dolibarr  x.y.z
bookmarks.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
31 {
32  global $conf, $user, $db, $langs, $sortfield, $sortorder;
33 
34  require_once DOL_DOCUMENT_ROOT.'/bookmarks/class/bookmark.class.php';
35  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
36 
37  $langs->load("bookmarks");
38 
39  $authorized_var=array('limit','optioncss','contextpage');
40  $url = $_SERVER["PHP_SELF"];
41  $url_param=array();
42  if (!empty($_SERVER["QUERY_STRING"])) {
43  if (is_array($_GET)) {
44  foreach ($_GET as $key => $val) {
45  if (is_array($val)) {
46  foreach ($val as $tmpsubval) {
47  $url_param[] = http_build_query(array(dol_escape_htmltag($key).'[]' => dol_escape_htmltag($tmpsubval)));
48  }
49  } elseif ($val != '') {
50  $url_param[$key] = http_build_query(array(dol_escape_htmltag($key) => dol_escape_htmltag($val)));
51  }
52  }
53  }
54  }
55  $tmpurl = '';
56  // No urlencode, all param $url will be urlencoded later
57  if ($sortfield) {
58  $tmpurl .= ($tmpurl ? '&' : '').'sortfield='.urlencode($sortfield);
59  }
60  if ($sortorder) {
61  $tmpurl .= ($tmpurl ? '&' : '').'sortorder='.urlencode($sortorder);
62  }
63  if (!empty($_POST) && is_array($_POST)) {
64  foreach ($_POST as $key => $val) {
65  if ((preg_match('/^search_/', $key) || in_array($key, $authorized_var))
66  && $val != ''
67  && !array_key_exists($key, $url_param)) {
68  $url_param[$key] = http_build_query(array(dol_escape_htmltag($key) => dol_escape_htmltag($val)));
69  }
70  }
71  }
72 
73  $url .= ($tmpurl ? '?'.$tmpurl : '');
74  if (!empty($url_param)) {
75  $url .= '&'.implode('&', $url_param);
76  }
77 
78  $searchForm = '<!-- form with POST method by default, will be replaced with GET for external link by js -->'."\n";
79  $searchForm .= '<form id="top-menu-action-bookmark" name="actionbookmark" method="POST" action=""'.(empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? ' onsubmit="return false"' : '').'>';
80  $searchForm .= '<input type="hidden" name="token" value="'.newToken().'">';
81 
82  // Url to go on create new bookmark page
83  $newbtn = '';
84  if (!empty($user->rights->bookmark->creer)) {
85  if (!preg_match('/bookmarks\/card.php/', $_SERVER['PHP_SELF'])) {
86  //$urltoadd=DOL_URL_ROOT.'/bookmarks/card.php?action=create&amp;urlsource='.urlencode($url).'&amp;url='.urlencode($url);
87  $urltoadd = DOL_URL_ROOT.'/bookmarks/card.php?action=create&amp;url='.urlencode($url);
88  $newbtn .= '<a class="top-menu-dropdown-link" title="'.$langs->trans('AddThisPageToBookmarks').'" href="'.dol_escape_htmltag($urltoadd).'" >';
89  $newbtn .= img_picto('', 'add', '', false, 0, 0, '', 'paddingright').dol_escape_htmltag($langs->trans('AddThisPageToBookmarks')).'</a>';
90  }
91  }
92 
93  // Url to list/edit bookmark
94  $listbtn = '<a class="top-menu-dropdown-link" title="'.dol_escape_htmltag($langs->trans('Bookmarks')).'" href="'.DOL_URL_ROOT.'/bookmarks/list.php">';
95  $listbtn .= img_picto('', 'edit', 'class="paddingright opacitymedium"').$langs->trans('EditBookmarks').'</a>';
96 
97  $bookmarkList = '';
98  // Menu with list of bookmarks
99  $sql = "SELECT rowid, title, url, target FROM ".MAIN_DB_PREFIX."bookmark";
100  $sql .= " WHERE (fk_user = ".((int) $user->id)." OR fk_user is NULL OR fk_user = 0)";
101  $sql .= " AND entity IN (".getEntity('bookmarks').")";
102  $sql .= " ORDER BY position";
103  if ($resql = $db->query($sql)) {
104  if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
105  $bookmarkList = '<div id="dropdown-bookmarks-list" >';
106  $i = 0;
107  while ((empty($conf->global->BOOKMARKS_SHOW_IN_MENU) || $i < $conf->global->BOOKMARKS_SHOW_IN_MENU) && $obj = $db->fetch_object($resql)) {
108  $bookmarkList .= '<a class="dropdown-item bookmark-item'.(strpos($obj->url, 'http') === 0 ? ' bookmark-item-external' : '').'" id="bookmark-item-'.$obj->rowid.'" data-id="'.$obj->rowid.'" '.($obj->target == 1 ? ' target="_blank" rel="noopener noreferrer"' : '').' href="'.dol_escape_htmltag($obj->url).'" >';
109  $bookmarkList .= dol_escape_htmltag($obj->title);
110  $bookmarkList .= '</a>';
111  $i++;
112  }
113  $bookmarkList .= '</div>';
114 
115  $searchForm .= '<input name="bookmark" id="top-bookmark-search-input" class="dropdown-search-input" placeholder="'.$langs->trans('Bookmarks').'" autocomplete="off" >';
116  } else {
117  $searchForm .= '<select name"=bookmark" id="boxbookmark" class="topmenu-bookmark-dropdown .dropdown-toggle">';
118  //$searchForm .= '<option>--'.$langs->trans("Bookmarks").'--</option>';
119  $searchForm .= '<option hidden value="listbookmarks" class="optiongrey" selected rel="'.DOL_URL_ROOT.'/bookmarks/list.php">'.$langs->trans('Bookmarks').'</option>';
120  $searchForm .= '<option value="listbookmark" class="optionblue" rel="'.dol_escape_htmltag(DOL_URL_ROOT.'/bookmarks/list.php').'" ';
121  $searchForm .= ' data-html="'.dol_escape_htmltag(img_picto('', 'bookmark').' '.($user->rights->bookmark->creer ? $langs->trans('EditBookmarks') : $langs->trans('ListOfBookmarks')).'...').'">';
122  $searchForm .= dol_escape_htmltag($user->rights->bookmark->creer ? $langs->trans('EditBookmarks') : $langs->trans('ListOfBookmarks')).'...</option>';
123  // Url to go on create new bookmark page
124  if (!empty($user->rights->bookmark->creer)) {
125  if (!preg_match('/bookmarks\/card.php/', $_SERVER['PHP_SELF'])) {
126  $urltoadd = DOL_URL_ROOT.'/bookmarks/card.php?action=create&amp;url='.urlencode($url);
127  $searchForm .= '<option value="newbookmark" class="optionblue" rel="'.dol_escape_htmltag($urltoadd).'"';
128  $searchForm .= ' data-html="'.dol_escape_htmltag(img_picto('', 'bookmark').' '.$langs->trans('AddThisPageToBookmarks').'...').'">'.dol_escape_htmltag($langs->trans('AddThisPageToBookmarks').'...').'</option>';
129  }
130  }
131  $i = 0;
132  while ((empty($conf->global->BOOKMARKS_SHOW_IN_MENU) || $i < $conf->global->BOOKMARKS_SHOW_IN_MENU) && $obj = $db->fetch_object($resql)) {
133  $searchForm .= '<option name="bookmark'.$obj->rowid.'" value="'.$obj->rowid.'" '.($obj->target == 1 ? ' target="_blank" rel="noopener noreferrer"' : '').' rel="'.dol_escape_htmltag($obj->url).'" >';
134  $searchForm .= dol_escape_htmltag($obj->title);
135  $searchForm .= '</option>';
136  $i++;
137  }
138  $searchForm .= '</select>';
139  }
140  } else {
141  dol_print_error($db);
142  }
143 
144  $searchForm .= '</form>';
145 
146  // Generate the return string
147  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
148  $html = $searchForm;
149 
150  $html .= '<!-- script to open selected choice -->
151  <script>
152  $(document).ready(function () {
153  jQuery("#boxbookmark").change(function() {
154  var urlselected = jQuery("#boxbookmark option:selected").attr("rel");
155  if (! urlselected) console.log("Error, failed to get the URL to jump to from the rel attribute");
156  var urltarget = jQuery("#boxbookmark option:selected").attr("target");
157  if (! urltarget) { urltarget=""; }
158  jQuery("form#top-menu-action-bookmark").attr("target",urltarget);
159  jQuery("form#top-menu-action-bookmark").attr("action",urlselected);
160 
161  console.log("We change select bookmark. We choose urlselected="+urlselected+" with target="+urltarget);
162 
163  // Method is POST for internal link, GET for external
164  if (urlselected.startsWith(\'http\'))
165  {
166  var newmethod=\'GET\';
167  jQuery("form#top-menu-action-bookmark").attr("method", newmethod);
168  console.log("We change method to newmethod="+newmethod);
169  jQuery("form#top-menu-action-bookmark").submit();
170  console.log("We restore method to POST");
171  jQuery("form#top-menu-action-bookmark").attr("method", \'POST\');
172  }
173  else
174  {
175  jQuery("form#top-menu-action-bookmark").submit();
176  }
177  });
178  })
179  </script>';
180  } else {
181  $html = '
182  <!-- search input -->
183  <div class="dropdown-header bookmark-header">
184  ' . $searchForm.'
185  </div>
186  ';
187 
188  $html .= '
189  <!-- Menu bookmark tools-->
190  <div class="bookmark-footer">
191  '.$newbtn.$listbtn.'
192  <div style="clear:both;"></div>
193  </div>
194  ';
195 
196  $html .= '
197  <!-- Menu Body -->
198  <div class="bookmark-body dropdown-body">
199  '.$bookmarkList.'
200  <span id="top-bookmark-search-nothing-found" class="hidden-search-result opacitymedium">'.dol_escape_htmltag($langs->trans("NoBookmarkFound")).'</span>
201  </div>
202  ';
203 
204  $html .= '<!-- script to open/close the popup -->
205  <script>
206  jQuery(document).on("keyup", "#top-bookmark-search-input", function () {
207  console.log("keyup in bookmark search input");
208 
209  var filter = $(this).val(), count = 0;
210  jQuery("#dropdown-bookmarks-list .bookmark-item").each(function () {
211  if ($(this).text().search(new RegExp(filter, "i")) < 0) {
212  $(this).addClass("hidden-search-result");
213  } else {
214  $(this).removeClass("hidden-search-result");
215  count++;
216  }
217  });
218  jQuery("#top-bookmark-search-filter-count").text(count);
219  if (count == 0) {
220  jQuery("#top-bookmark-search-nothing-found").removeClass("hidden-search-result");
221  } else {
222  jQuery("#top-bookmark-search-nothing-found").addClass("hidden-search-result");
223  }
224  });
225  </script>';
226  }
227 
228  return $html;
229 }
printDropdownBookmarksList()
Add area with bookmarks in top menu.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)