dolibarr  7.0.0-beta
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 <http://www.gnu.org/licenses/>.
16  */
17 
31 function printBookmarksList($aDb, $aLangs)
32 {
33  global $conf, $user;
34 
35  $db = $aDb;
36  $langs = $aLangs;
37 
38  $ret = '<div class="menu_top"></div>'."\n";
39 
40  if (! empty($conf->use_javascript_ajax)) { // Bookmark autosubmit can't work when javascript is off.
41 
42  require_once DOL_DOCUMENT_ROOT.'/bookmarks/class/bookmark.class.php';
43  if (! isset($conf->global->BOOKMARKS_SHOW_IN_MENU)) $conf->global->BOOKMARKS_SHOW_IN_MENU=5;
44 
45  $langs->load("bookmarks");
46 
47  $url= $_SERVER["PHP_SELF"];
48 
49  if (! empty($_SERVER["QUERY_STRING"]))
50  {
51  $url.=(dol_escape_htmltag($_SERVER["QUERY_STRING"])?'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]):'');
52  }
53  else
54  {
55  global $sortfield,$sortorder;
56  $tmpurl='';
57  // No urlencode, all param $url will be urlencoded later
58  if ($sortfield) $tmpurl.=($tmpurl?'&':'').'sortfield='.$sortfield;
59  if ($sortorder) $tmpurl.=($tmpurl?'&':'').'sortorder='.$sortorder;
60  if (is_array($_POST))
61  {
62  foreach($_POST as $key => $val)
63  {
64  if (preg_match('/^search_/', $key) && $val != '') $tmpurl.=($tmpurl?'&':'').$key.'='.$val;
65  }
66  }
67  $url.=($tmpurl?'?'.$tmpurl:'');
68  }
69 
70  // Menu bookmark
71  $ret = '<div class="menu_top"></div>'."\n";
72 
73  $ret.= '<!-- form with POST method by default, will be replaced with GET for external link by js -->'."\n";
74  $ret.= '<form id="actionbookmark" name="actionbookmark" method="POST" action="">';
75  $ret.= '<select name="bookmark" id="boxbookmark" class="flat boxcombo vmenusearchselectcombo" alt="Bookmarks">';
76  $ret.= '<option hidden value="listbookmarks" class="optiongrey" selected rel="'.DOL_URL_ROOT.'/bookmarks/list.php">'.$langs->trans('Bookmarks').'</option>';
77  $ret.= '<option value="listbookmark" class="optionblue" rel="'.dol_escape_htmltag(DOL_URL_ROOT.'/bookmarks/list.php').'" ';
78  $ret.= ' data-html="'.dol_escape_htmltag('<span class="fa fa-star-o"></span> '.dol_escape_htmltag($user->rights->bookmark->creer ? $langs->trans('EditBookmarks') : $langs->trans('ListOfBookmarks')).'...').'">';
79  $ret.= dol_escape_htmltag($user->rights->bookmark->creer ? $langs->trans('EditBookmarks') : $langs->trans('ListOfBookmarks')).'...</option>';
80  // Url to go on create new bookmark page
81  if (! empty($user->rights->bookmark->creer))
82  {
83  //$urltoadd=DOL_URL_ROOT.'/bookmarks/card.php?action=create&amp;urlsource='.urlencode($url).'&amp;url='.urlencode($url);
84  $urltoadd=DOL_URL_ROOT.'/bookmarks/card.php?action=create&amp;url='.urlencode($url);
85  $ret.= '<option value="newbookmark" class="optionblue" rel="'.dol_escape_htmltag($urltoadd).'"';
86  $ret.= ' data-html="'.dol_escape_htmltag('<span class="fa fa-star-o"></span> '.$langs->trans('AddThisPageToBookmarks').'...').'">'.dol_escape_htmltag($langs->trans('AddThisPageToBookmarks').'...').'</option>';
87  }
88  // Menu with all bookmarks
89  if (! empty($conf->global->BOOKMARKS_SHOW_IN_MENU))
90  {
91  $sql = "SELECT rowid, title, url, target FROM ".MAIN_DB_PREFIX."bookmark";
92  $sql.= " WHERE (fk_user = ".$user->id." OR fk_user is NULL OR fk_user = 0)";
93  $sql.= " AND entity IN (".getEntity('bookmarks').")";
94  $sql.= " ORDER BY position";
95  if ($resql = $db->query($sql) )
96  {
97  $i=0;
98  while ($i < $conf->global->BOOKMARKS_SHOW_IN_MENU && $obj = $db->fetch_object($resql))
99  {
100  $ret.='<option name="bookmark'.$obj->rowid.'" value="'.$obj->rowid.'" '.($obj->target == 1?' target="_blank"':'').' rel="'.dol_escape_htmltag($obj->url).'"';
101  //$ret.=' data-html="'.dol_escape_htmltag('<span class="fa fa-print"></span> '.$obj->title).'"';
102  $ret.='>';
103  $ret.=dol_escape_htmltag($obj->title);
104  $ret.='</option>';
105  $i++;
106  }
107  }
108  else
109  {
110  dol_print_error($db);
111  }
112  }
113 
114  $ret.= '</select>';
115  $ret.= '</form>';
116 
117  $ret.=ajax_combobox('boxbookmark');
118 
119  $ret.='<script type="text/javascript">
120  $(document).ready(function () {';
121  $ret.=' jQuery("#boxbookmark").change(function() {
122  var urlselected = jQuery("#boxbookmark option:selected").attr("rel");
123  if (! urlselected) console.log("Error, failed to get the URL to jump to from the rel attribute");
124  var urltarget = jQuery("#boxbookmark option:selected").attr("target");
125  if (! urltarget) { urltarget=""; }
126  jQuery("form#actionbookmark").attr("target",urltarget);
127  jQuery("form#actionbookmark").attr("action",urlselected);
128 
129  console.log("We change select bookmark. We choose urlselected="+urlselected+" with target="+urltarget);
130 
131  // Method is POST for internal link, GET for external
132  if (urlselected.startsWith(\'http\'))
133  {
134  var newmethod=\'GET\';
135  jQuery("form#actionbookmark").attr("method", newmethod);
136  console.log("We change method to newmethod="+newmethod);
137  jQuery("#actionbookmark").submit();
138  console.log("We restore method to POST");
139  jQuery("form#actionbookmark").attr("method", \'POST\');
140  }
141  else
142  {
143  jQuery("#actionbookmark").submit();
144  }
145  });';
146  $ret.='})</script>';
147  }
148 
149  $ret.= '<div class="menu_end"></div>'."\n";
150 
151  return $ret;
152 }
153 
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:392
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
printBookmarksList($aDb, $aLangs)
Add area with bookmarks in menu.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013