dolibarr  13.0.2
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
3  * Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array("other", "admin"));
33 
34 if (!$user->admin) accessforbidden();
35 
36 $dirstandard = array();
37 $dirsmartphone = array();
38 $dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
39 foreach ($dirmenus as $dirmenu)
40 {
41  $dirstandard[] = $dirmenu.'standard';
42  $dirsmartphone[] = $dirmenu.'smartphone';
43 }
44 
45 $action = GETPOST('action', 'aZ09');
46 $confirm = GETPOST('confirm', 'alpha');
47 
48 $menu_handler_top = $conf->global->MAIN_MENU_STANDARD;
49 $menu_handler_smartphone = $conf->global->MAIN_MENU_SMARTPHONE;
50 $menu_handler_top = preg_replace('/(_backoffice\.php|_menu\.php)/i', '', $menu_handler_top);
51 $menu_handler_top = preg_replace('/(_frontoffice\.php|_menu\.php)/i', '', $menu_handler_top);
52 $menu_handler_smartphone = preg_replace('/(_backoffice\.php|_menu\.php)/i', '', $menu_handler_smartphone);
53 $menu_handler_smartphone = preg_replace('/(_frontoffice\.php|_menu\.php)/i', '', $menu_handler_smartphone);
54 
55 $menu_handler = $menu_handler_top;
56 
57 if (GETPOST("handler_origine")) $menu_handler = GETPOST("handler_origine");
58 if (GETPOST("menu_handler")) $menu_handler = GETPOST("menu_handler");
59 
60 $menu_handler_to_search = preg_replace('/(_backoffice|_frontoffice|_menu)?(\.php)?/i', '', $menu_handler);
61 
62 
63 /*
64  * Actions
65  */
66 
67 if ($action == 'up')
68 {
69  $current = array();
70  $previous = array();
71 
72  // Get current position
73  $sql = "SELECT m.rowid, m.position, m.type, m.fk_menu";
74  $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
75  $sql .= " WHERE m.rowid = ".GETPOST("menuId", "int");
76  dol_syslog("admin/menus/index.php ".$sql);
77  $result = $db->query($sql);
78  $num = $db->num_rows($result);
79  $i = 0;
80  while ($i < $num)
81  {
82  $obj = $db->fetch_object($result);
83  $current['rowid'] = $obj->rowid;
84  $current['order'] = $obj->position;
85  $current['type'] = $obj->type;
86  $current['fk_menu'] = $obj->fk_menu;
87  $i++;
88  }
89 
90  // Menu before
91  $sql = "SELECT m.rowid, m.position";
92  $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
93  $sql .= " WHERE (m.position < ".($current['order'])." OR (m.position = ".($current['order'])." AND rowid < ".GETPOST("menuId", "int")."))";
94  $sql .= " AND m.menu_handler='".$db->escape($menu_handler_to_search)."'";
95  $sql .= " AND m.entity = ".$conf->entity;
96  $sql .= " AND m.type = '".$db->escape($current['type'])."'";
97  $sql .= " AND m.fk_menu = '".$db->escape($current['fk_menu'])."'";
98  $sql .= " ORDER BY m.position, m.rowid";
99  dol_syslog("admin/menus/index.php ".$sql);
100  $result = $db->query($sql);
101  $num = $db->num_rows($result);
102  $i = 0;
103  while ($i < $num)
104  {
105  $obj = $db->fetch_object($result);
106  $previous['rowid'] = $obj->rowid;
107  $previous['order'] = $obj->position;
108  $i++;
109  }
110 
111  $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
112  $sql .= " SET m.position = ".$previous['order'];
113  $sql .= " WHERE m.rowid = ".$current['rowid']; // Up the selected entry
114  dol_syslog("admin/menus/index.php ".$sql);
115  $db->query($sql);
116  $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
117  $sql .= " SET m.position = ".($current['order'] != $previous['order'] ? $current['order'] : $current['order'] + 1);
118  $sql .= " WHERE m.rowid = ".$previous['rowid']; // Descend celui du dessus
119  dol_syslog("admin/menus/index.php ".$sql);
120  $db->query($sql);
121 } elseif ($action == 'down')
122 {
123  $current = array();
124  $next = array();
125 
126  // Get current position
127  $sql = "SELECT m.rowid, m.position, m.type, m.fk_menu";
128  $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
129  $sql .= " WHERE m.rowid = ".GETPOST("menuId", "int");
130  dol_syslog("admin/menus/index.php ".$sql);
131  $result = $db->query($sql);
132  $num = $db->num_rows($result);
133  $i = 0;
134  while ($i < $num)
135  {
136  $obj = $db->fetch_object($result);
137  $current['rowid'] = $obj->rowid;
138  $current['order'] = $obj->position;
139  $current['type'] = $obj->type;
140  $current['fk_menu'] = $obj->fk_menu;
141  $i++;
142  }
143 
144  // Menu after
145  $sql = "SELECT m.rowid, m.position";
146  $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
147  $sql .= " WHERE (m.position > ".($current['order'])." OR (m.position = ".($current['order'])." AND rowid > ".GETPOST("menuId", "int")."))";
148  $sql .= " AND m.menu_handler='".$db->escape($menu_handler_to_search)."'";
149  $sql .= " AND m.entity = ".$conf->entity;
150  $sql .= " AND m.type = '".$db->escape($current['type'])."'";
151  $sql .= " AND m.fk_menu = '".$db->escape($current['fk_menu'])."'";
152  $sql .= " ORDER BY m.position, m.rowid";
153  dol_syslog("admin/menus/index.php ".$sql);
154  $result = $db->query($sql);
155  $num = $db->num_rows($result);
156  $i = 0;
157  while ($i < $num)
158  {
159  $obj = $db->fetch_object($result);
160  $next['rowid'] = $obj->rowid;
161  $next['order'] = $obj->position;
162  $i++;
163  }
164 
165  $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
166  $sql .= " SET m.position = ".($current['order'] != $next['order'] ? $next['order'] : $current['order'] + 1); // Down the selected entry
167  $sql .= " WHERE m.rowid = ".$current['rowid'];
168  dol_syslog("admin/menus/index.php ".$sql);
169  $db->query($sql);
170  $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m"; // Up the next entry
171  $sql .= " SET m.position = ".$current['order'];
172  $sql .= " WHERE m.rowid = ".$next['rowid'];
173  dol_syslog("admin/menus/index.php ".$sql);
174  $db->query($sql);
175 } elseif ($action == 'confirm_delete' && $confirm == 'yes')
176 {
177  $db->begin();
178 
179  $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu";
180  $sql .= " WHERE rowid = ".GETPOST('menuId', 'int');
181  $resql = $db->query($sql);
182  if ($resql)
183  {
184  $db->commit();
185 
186  setEventMessages($langs->trans("MenuDeleted"), null, 'mesgs');
187 
188  header("Location: ".DOL_URL_ROOT.'/admin/menus/index.php?menu_handler='.$menu_handler);
189  exit;
190  } else {
191  $db->rollback();
192 
193  $reload = 0;
194  $action = '';
195  }
196 }
197 
198 
199 /*
200  * View
201  */
202 
203 $form = new Form($db);
204 $formadmin = new FormAdmin($db);
205 
206 $arrayofjs = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
207 $arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
208 
209 llxHeader('', $langs->trans("Menus"), '', '', 0, 0, $arrayofjs, $arrayofcss);
210 
211 
212 print load_fiche_titre($langs->trans("Menus"), '', 'title_setup');
213 
214 
215 $h = 0;
216 
217 $head[$h][0] = DOL_URL_ROOT."/admin/menus.php";
218 $head[$h][1] = $langs->trans("MenuHandlers");
219 $head[$h][2] = 'handler';
220 $h++;
221 
222 $head[$h][0] = DOL_URL_ROOT."/admin/menus/index.php";
223 $head[$h][1] = $langs->trans("MenuAdmin");
224 $head[$h][2] = 'editor';
225 $h++;
226 
227 print dol_get_fiche_head($head, 'editor', '', -1);
228 
229 print '<span class="opacitymedium">'.$langs->trans("MenusEditorDesc")."</span><br>\n";
230 print "<br>\n";
231 
232 
233 // Confirmation for remove menu entry
234 if ($action == 'delete')
235 {
236  $sql = "SELECT m.titre as title";
237  $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
238  $sql .= " WHERE m.rowid = ".GETPOST('menuId', 'int');
239  $result = $db->query($sql);
240  $obj = $db->fetch_object($result);
241 
242  print $form->formconfirm("index.php?menu_handler=".$menu_handler."&menuId=".GETPOST('menuId', 'int'), $langs->trans("DeleteMenu"), $langs->trans("ConfirmDeleteMenu", $obj->title), "confirm_delete");
243 }
244 
245 $newcardbutton = '';
246 if ($user->admin)
247 {
248  $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/admin/menus/edit.php?menuId=0&action=create&menu_handler='.urlencode($menu_handler).'&backtopage='.urlencode($_SERVER['PHP_SELF']));
249 }
250 
251 print '<form name="newmenu" class="nocellnopadd" action="'.$_SERVER["PHP_SELF"].'">';
252 print '<input type="hidden" action="change_menu_handler">';
253 print $langs->trans("MenuHandler").': ';
254 $formadmin->select_menu_families($menu_handler.(preg_match('/_menu/', $menu_handler) ? '' : '_menu'), 'menu_handler', array_merge($dirstandard, $dirsmartphone));
255 print ' &nbsp; <input type="submit" class="button" value="'.$langs->trans("Refresh").'">';
256 
257 print '<div class="floatright">';
258 print $newcardbutton;
259 print '</div>';
260 
261 print '</form>';
262 
263 print '<br>';
264 
265 print '<table class="noborder centpercent">';
266 
267 print '<tr class="liste_titre">';
268 print '<td>'.$langs->trans("TreeMenuPersonalized").'</td>';
269 print '<td class="right"><div id="iddivjstreecontrol"><a href="#">'.img_picto('', 'folder', 'class="paddingright"').$langs->trans("UndoExpandAll").'</a>';
270 print ' | <a href="#">'.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ExpandAll").'</a></div></td>';
271 print '</tr>';
272 
273 print '<tr>';
274 print '<td colspan="2">';
275 
276 // ARBORESCENCE
277 
278 $rangLast = 0;
279 $idLast = -1;
280 if ($conf->use_javascript_ajax)
281 {
282  /*-------------------- MAIN -----------------------
283  tableau des elements de l'arbre:
284  c'est un tableau a 2 dimensions.
285  Une ligne represente un element : data[$x]
286  chaque ligne est decomposee en 3 donnees:
287  - l'index de l'élément
288  - l'index de l'élément parent
289  - la chaine a afficher
290  ie: data[]= array (index, index parent, chaine )
291  */
292 
293  //il faut d'abord declarer un element racine de l'arbre
294 
295  $data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
296 
297  //puis tous les elements enfants
298 
299  $sql = "SELECT m.rowid, m.titre, m.langs, m.mainmenu, m.leftmenu, m.fk_menu, m.fk_mainmenu, m.fk_leftmenu, m.position, m.module";
300  $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
301  $sql .= " WHERE menu_handler = '".$db->escape($menu_handler_to_search)."'";
302  $sql .= " AND entity = ".$conf->entity;
303  //$sql.= " AND fk_menu >= 0";
304  $sql .= " ORDER BY m.position, m.rowid"; // Order is position then rowid (because we need a sort criteria when position is same)
305 
306  $res = $db->query($sql);
307  if ($res)
308  {
309  $num = $db->num_rows($res);
310 
311  $i = 1;
312  while ($menu = $db->fetch_array($res))
313  {
314  if (!empty($menu['langs'])) $langs->load($menu['langs']);
315  $titre = $langs->trans($menu['titre']);
316 
317  $entry = '<table class="nobordernopadding centpercent"><tr><td>';
318  $entry .= '<strong> &nbsp; <a href="edit.php?menu_handler='.$menu_handler_to_search.'&action=edit&token='.newToken().'&menuId='.$menu['rowid'].'">'.$titre.'</a></strong>';
319  $entry .= '</td><td class="right">';
320  $entry .= '<a class="editfielda marginleftonly marginrightonly" href="edit.php?menu_handler='.$menu_handler_to_search.'&action=edit&token='.newToken().'&menuId='.$menu['rowid'].'">'.img_edit('default', 0, 'class="menuEdit" id="edit'.$menu['rowid'].'"').'</a> ';
321  $entry .= '<a class="marginleftonly marginrightonly" href="edit.php?menu_handler='.$menu_handler_to_search.'&action=create&token='.newToken().'&menuId='.$menu['rowid'].'">'.img_edit_add('default').'</a> ';
322  $entry .= '<a class="marginleftonly marginrightonly" href="index.php?menu_handler='.$menu_handler_to_search.'&action=delete&token='.newToken().'&menuId='.$menu['rowid'].'">'.img_delete('default').'</a> ';
323  $entry .= '&nbsp; &nbsp; &nbsp;';
324  $entry .= '<a class="marginleftonly marginrightonly" href="index.php?menu_handler='.$menu_handler_to_search.'&action=up&token='.newToken().'&menuId='.$menu['rowid'].'">'.img_picto("Up", "1uparrow").'</a><a href="index.php?menu_handler='.$menu_handler_to_search.'&action=down&menuId='.$menu['rowid'].'">'.img_picto("Down", "1downarrow").'</a>';
325  $entry .= '</td></tr></table>';
326 
327  $buttons = '<a class="editfielda marginleftonly marginrightonly" href="edit.php?menu_handler='.$menu_handler_to_search.'&action=edit&token='.newToken().'&menuId='.$menu['rowid'].'">'.img_edit('default', 0, 'class="menuEdit" id="edit'.$menu['rowid'].'"').'</a> ';
328  $buttons .= '<a class="marginleftonly marginrightonly" href="edit.php?menu_handler='.$menu_handler_to_search.'&action=create&token='.newToken().'&menuId='.$menu['rowid'].'">'.img_edit_add('default').'</a> ';
329  $buttons .= '<a class="marginleftonly marginrightonly" href="index.php?menu_handler='.$menu_handler_to_search.'&action=delete&token='.newToken().'&menuId='.$menu['rowid'].'">'.img_delete('default').'</a> ';
330  $buttons .= '&nbsp; &nbsp; &nbsp;';
331  $buttons .= '<a class="marginleftonly marginrightonly" href="index.php?menu_handler='.$menu_handler_to_search.'&action=up&token='.newToken().'&menuId='.$menu['rowid'].'">'.img_picto("Up", "1uparrow").'</a><a href="index.php?menu_handler='.$menu_handler_to_search.'&action=down&menuId='.$menu['rowid'].'">'.img_picto("Down", "1downarrow").'</a>';
332 
333  $data[] = array(
334  'rowid'=>$menu['rowid'],
335  'module'=>$menu['module'],
336  'fk_menu'=>$menu['fk_menu'],
337  'title'=>$titre,
338  'mainmenu'=>$menu['mainmenu'],
339  'leftmenu'=>$menu['leftmenu'],
340  'fk_mainmenu'=>$menu['fk_mainmenu'],
341  'fk_leftmenu'=>$menu['fk_leftmenu'],
342  'position'=>$menu['position'],
343  'entry'=>$entry,
344  'buttons'=>$buttons
345  );
346  $i++;
347  }
348  }
349 
350  global $tree_recur_alreadyadded; // This var was def into tree_recur
351 
352  //var_dump($data);
353 
354  // Appelle de la fonction recursive (ammorce) avec recherche depuis la racine.
355  //tree_recur($data, $data[0], 0, 'iddivjstree', 0, 1); // use this to get info on name and foreign keys of menu entry
356  tree_recur($data, $data[0], 0, 'iddivjstree', 0, 0); // $data[0] is virtual record 'racine'
357 
358 
359  print '</td>';
360 
361  print '</tr>';
362 
363  print '</table>';
364 
365 
366  // Process remaining records (records that are not linked to root by any path)
367  $remainingdata = array();
368  foreach ($data as $datar)
369  {
370  if (empty($datar['rowid']) || $tree_recur_alreadyadded[$datar['rowid']]) continue;
371  $remainingdata[] = $datar;
372  }
373 
374  if (count($remainingdata))
375  {
376  print '<table class="noborder centpercent">';
377 
378  print '<tr class="liste_titre">';
379  print '<td>'.$langs->trans("NotTopTreeMenuPersonalized").'</td>';
380  print '<td class="right"></td>';
381  print '</tr>';
382 
383  print '<tr>';
384  print '<td colspan="2">';
385  foreach ($remainingdata as $datar)
386  {
387  $father = array('rowid'=>$datar['rowid'], 'title'=>"???", 'mainmenu'=>$datar['fk_mainmenu'], 'leftmenu'=>$datar['fk_leftmenu'], 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
388  //print 'Start with rowid='.$datar['rowid'].' mainmenu='.$father ['mainmenu'].' leftmenu='.$father ['leftmenu'].'<br>'."\n";
389  tree_recur($data, $father, 0, 'iddivjstree'.$datar['rowid'], 1, 1);
390  }
391 
392  print '</td>';
393 
394  print '</tr>';
395 
396  print '</table>';
397  }
398 
399  print '</div>';
400 } else {
401  $langs->load("errors");
402  setEventMessages($langs->trans("ErrorFeatureNeedJavascript"), null, 'errors');
403 }
404 
405 print '<br>';
406 
407 // End of page
408 llxFooter();
409 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
dolGetButtonTitle($label, $helpText= '', $iconClass= 'fa fa-file', $url= '', $id= '', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
Class to generate html code for admin pages.
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
print $_SERVER["PHP_SELF"]
Edit parameters.
img_edit_add($titlealt= 'default', $other= '')
Show logo +.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
llxFooter()
Empty footer.
Definition: wrapper.php:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
tree_recur($tab, $pere, $rang, $iddivjstree= 'iddivjstree', $donoresetalreadyloaded=0, $showfk=0, $moreparam= '')
Recursive function to output a tree.