dolibarr  16.0.5
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) {
36 }
37 
38 $dirstandard = array();
39 $dirsmartphone = array();
40 $dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
41 foreach ($dirmenus as $dirmenu) {
42  $dirstandard[] = $dirmenu.'standard';
43  $dirsmartphone[] = $dirmenu.'smartphone';
44 }
45 
46 $action = GETPOST('action', 'aZ09');
47 $confirm = GETPOST('confirm', 'alpha');
48 
49 $menu_handler_top = $conf->global->MAIN_MENU_STANDARD;
50 $menu_handler_smartphone = $conf->global->MAIN_MENU_SMARTPHONE;
51 $menu_handler_top = preg_replace('/(_backoffice\.php|_menu\.php)/i', '', $menu_handler_top);
52 $menu_handler_top = preg_replace('/(_frontoffice\.php|_menu\.php)/i', '', $menu_handler_top);
53 $menu_handler_smartphone = preg_replace('/(_backoffice\.php|_menu\.php)/i', '', $menu_handler_smartphone);
54 $menu_handler_smartphone = preg_replace('/(_frontoffice\.php|_menu\.php)/i', '', $menu_handler_smartphone);
55 
56 $menu_handler = $menu_handler_top;
57 
58 if (GETPOST("handler_origine")) {
59  $menu_handler = GETPOST("handler_origine");
60 }
61 if (GETPOST("menu_handler")) {
62  $menu_handler = GETPOST("menu_handler");
63 }
64 
65 $menu_handler_to_search = preg_replace('/(_backoffice|_frontoffice|_menu)?(\.php)?/i', '', $menu_handler);
66 
67 
68 /*
69  * Actions
70  */
71 
72 if ($action == 'up') {
73  $current = array();
74  $previous = array();
75 
76  // Get current position
77  $sql = "SELECT m.rowid, m.position, m.type, m.fk_menu";
78  $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
79  $sql .= " WHERE m.rowid = ".GETPOST("menuId", "int");
80  dol_syslog("admin/menus/index.php ".$sql);
81  $result = $db->query($sql);
82  $num = $db->num_rows($result);
83  $i = 0;
84  while ($i < $num) {
85  $obj = $db->fetch_object($result);
86  $current['rowid'] = $obj->rowid;
87  $current['order'] = $obj->position;
88  $current['type'] = $obj->type;
89  $current['fk_menu'] = $obj->fk_menu;
90  $i++;
91  }
92 
93  // Menu before
94  $sql = "SELECT m.rowid, m.position";
95  $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
96  $sql .= " WHERE (m.position < ".($current['order'])." OR (m.position = ".($current['order'])." AND rowid < ".GETPOST("menuId", "int")."))";
97  $sql .= " AND m.menu_handler='".$db->escape($menu_handler_to_search)."'";
98  $sql .= " AND m.entity = ".$conf->entity;
99  $sql .= " AND m.type = '".$db->escape($current['type'])."'";
100  $sql .= " AND m.fk_menu = '".$db->escape($current['fk_menu'])."'";
101  $sql .= " ORDER BY m.position, m.rowid";
102  dol_syslog("admin/menus/index.php ".$sql);
103  $result = $db->query($sql);
104  $num = $db->num_rows($result);
105  $i = 0;
106  while ($i < $num) {
107  $obj = $db->fetch_object($result);
108  $previous['rowid'] = $obj->rowid;
109  $previous['order'] = $obj->position;
110  $i++;
111  }
112 
113  $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
114  $sql .= " SET m.position = ".((int) $previous['order']);
115  $sql .= " WHERE m.rowid = ".((int) $current['rowid']); // Up the selected entry
116  dol_syslog("admin/menus/index.php ".$sql);
117  $db->query($sql);
118  $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
119  $sql .= " SET m.position = ".((int) ($current['order'] != $previous['order'] ? $current['order'] : $current['order'] + 1));
120  $sql .= " WHERE m.rowid = ".((int) $previous['rowid']); // Descend celui du dessus
121  dol_syslog("admin/menus/index.php ".$sql);
122  $db->query($sql);
123 } elseif ($action == 'down') {
124  $current = array();
125  $next = array();
126 
127  // Get current position
128  $sql = "SELECT m.rowid, m.position, m.type, m.fk_menu";
129  $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
130  $sql .= " WHERE m.rowid = ".GETPOST("menuId", "int");
131  dol_syslog("admin/menus/index.php ".$sql);
132  $result = $db->query($sql);
133  $num = $db->num_rows($result);
134  $i = 0;
135  while ($i < $num) {
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  $obj = $db->fetch_object($result);
159  $next['rowid'] = $obj->rowid;
160  $next['order'] = $obj->position;
161  $i++;
162  }
163 
164  $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
165  $sql .= " SET m.position = ".((int) ($current['order'] != $next['order'] ? $next['order'] : $current['order'] + 1)); // Down the selected entry
166  $sql .= " WHERE m.rowid = ".((int) $current['rowid']);
167  dol_syslog("admin/menus/index.php ".$sql);
168  $db->query($sql);
169  $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m"; // Up the next entry
170  $sql .= " SET m.position = ".((int) $current['order']);
171  $sql .= " WHERE m.rowid = ".((int) $next['rowid']);
172  dol_syslog("admin/menus/index.php ".$sql);
173  $db->query($sql);
174 } elseif ($action == 'confirm_delete' && $confirm == 'yes') {
175  $db->begin();
176 
177  $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu";
178  $sql .= " WHERE rowid = ".GETPOST('menuId', 'int');
179  $resql = $db->query($sql);
180  if ($resql) {
181  $db->commit();
182 
183  setEventMessages($langs->trans("MenuDeleted"), null, 'mesgs');
184 
185  header("Location: ".DOL_URL_ROOT.'/admin/menus/index.php?menu_handler='.$menu_handler);
186  exit;
187  } else {
188  $db->rollback();
189 
190  $reload = 0;
191  $action = '';
192  }
193 }
194 
195 
196 /*
197  * View
198  */
199 
200 $form = new Form($db);
201 $formadmin = new FormAdmin($db);
202 
203 $arrayofjs = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
204 $arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
205 
206 llxHeader('', $langs->trans("Menus"), '', '', 0, 0, $arrayofjs, $arrayofcss);
207 
208 
209 print load_fiche_titre($langs->trans("Menus"), '', 'title_setup');
210 
211 
212 $h = 0;
213 
214 $head[$h][0] = DOL_URL_ROOT."/admin/menus.php";
215 $head[$h][1] = $langs->trans("MenuHandlers");
216 $head[$h][2] = 'handler';
217 $h++;
218 
219 $head[$h][0] = DOL_URL_ROOT."/admin/menus/index.php";
220 $head[$h][1] = $langs->trans("MenuAdmin");
221 $head[$h][2] = 'editor';
222 $h++;
223 
224 print dol_get_fiche_head($head, 'editor', '', -1);
225 
226 print '<span class="opacitymedium">'.$langs->trans("MenusEditorDesc")."</span><br>\n";
227 print "<br>\n";
228 
229 
230 // Confirmation for remove menu entry
231 if ($action == 'delete') {
232  $sql = "SELECT m.titre as title";
233  $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
234  $sql .= " WHERE m.rowid = ".GETPOST('menuId', 'int');
235  $result = $db->query($sql);
236  $obj = $db->fetch_object($result);
237 
238  print $form->formconfirm("index.php?menu_handler=".$menu_handler."&menuId=".GETPOST('menuId', 'int'), $langs->trans("DeleteMenu"), $langs->trans("ConfirmDeleteMenu", $obj->title), "confirm_delete");
239 }
240 
241 $newcardbutton = '';
242 if ($user->admin) {
243  $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']));
244 }
245 
246 print '<form name="newmenu" class="nocellnopadd" action="'.$_SERVER["PHP_SELF"].'">';
247 print '<input type="hidden" action="change_menu_handler">';
248 print $langs->trans("MenuHandler").': ';
249 $formadmin->select_menu_families($menu_handler.(preg_match('/_menu/', $menu_handler) ? '' : '_menu'), 'menu_handler', array_merge($dirstandard, $dirsmartphone));
250 print ' &nbsp; <input type="submit" class="button" value="'.$langs->trans("Refresh").'">';
251 
252 print '<div class="floatright">';
253 print $newcardbutton;
254 print '</div>';
255 
256 print '</form>';
257 
258 print '<br>';
259 
260 print '<table class="noborder centpercent">';
261 
262 print '<tr class="liste_titre">';
263 print '<td>'.$langs->trans("TreeMenuPersonalized").'</td>';
264 print '<td class="right"><div id="iddivjstreecontrol"><a href="#">'.img_picto('', 'folder', 'class="paddingright"').$langs->trans("UndoExpandAll").'</a>';
265 print ' | <a href="#">'.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ExpandAll").'</a></div></td>';
266 print '</tr>';
267 
268 print '<tr>';
269 print '<td colspan="2">';
270 
271 // ARBORESCENCE
272 
273 $rangLast = 0;
274 $idLast = -1;
275 if ($conf->use_javascript_ajax) {
276  /*-------------------- MAIN -----------------------
277  tableau des elements de l'arbre:
278  c'est un tableau a 2 dimensions.
279  Une ligne represente un element : data[$x]
280  chaque ligne est decomposee en 3 donnees:
281  - l'index de l'élément
282  - l'index de l'élément parent
283  - la chaine a afficher
284  ie: data[]= array (index, index parent, chaine )
285  */
286 
287  //il faut d'abord declarer un element racine de l'arbre
288 
289  $data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
290 
291  //puis tous les elements enfants
292 
293  $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";
294  $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
295  $sql .= " WHERE menu_handler = '".$db->escape($menu_handler_to_search)."'";
296  $sql .= " AND entity = ".$conf->entity;
297  //$sql.= " AND fk_menu >= 0";
298  $sql .= " ORDER BY m.position, m.rowid"; // Order is position then rowid (because we need a sort criteria when position is same)
299 
300  $res = $db->query($sql);
301  if ($res) {
302  $num = $db->num_rows($res);
303 
304  $i = 1;
305  while ($menu = $db->fetch_array($res)) {
306  if (!empty($menu['langs'])) {
307  $langs->load($menu['langs']);
308  }
309  $titre = $langs->trans($menu['titre']);
310 
311  $entry = '<table class="nobordernopadding centpercent"><tr><td>';
312  $entry .= '<strong> &nbsp; <a href="edit.php?menu_handler='.$menu_handler_to_search.'&action=edit&token='.newToken().'&menuId='.$menu['rowid'].'">'.$titre.'</a></strong>';
313  $entry .= '</td><td class="right">';
314  $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> ';
315  $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> ';
316  $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> ';
317  $entry .= '&nbsp; ';
318  $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>';
319  $entry .= '</td></tr></table>';
320 
321  $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> ';
322  $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> ';
323  $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> ';
324  $buttons .= '&nbsp; ';
325  $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>';
326 
327  $data[] = array(
328  'rowid'=>$menu['rowid'],
329  'module'=>$menu['module'],
330  'fk_menu'=>$menu['fk_menu'],
331  'title'=>$titre,
332  'mainmenu'=>$menu['mainmenu'],
333  'leftmenu'=>$menu['leftmenu'],
334  'fk_mainmenu'=>$menu['fk_mainmenu'],
335  'fk_leftmenu'=>$menu['fk_leftmenu'],
336  'position'=>$menu['position'],
337  'entry'=>$entry,
338  'buttons'=>$buttons
339  );
340  $i++;
341  }
342  }
343 
344  global $tree_recur_alreadyadded; // This var was def into tree_recur
345 
346  //var_dump($data);
347 
348  // Appelle de la fonction recursive (ammorce) avec recherche depuis la racine.
349  //tree_recur($data, $data[0], 0, 'iddivjstree', 0, 1); // use this to get info on name and foreign keys of menu entry
350  tree_recur($data, $data[0], 0, 'iddivjstree', 0, 0); // $data[0] is virtual record 'racine'
351 
352 
353  print '</td>';
354 
355  print '</tr>';
356 
357  print '</table>';
358 
359 
360  // Process remaining records (records that are not linked to root by any path)
361  $remainingdata = array();
362  foreach ($data as $datar) {
363  if (empty($datar['rowid']) || !empty($tree_recur_alreadyadded[$datar['rowid']])) {
364  continue;
365  }
366  $remainingdata[] = $datar;
367  }
368 
369  if (count($remainingdata)) {
370  print '<table class="noborder centpercent">';
371 
372  print '<tr class="liste_titre">';
373  print '<td>'.$langs->trans("NotTopTreeMenuPersonalized").'</td>';
374  print '<td class="right"></td>';
375  print '</tr>';
376 
377  print '<tr>';
378  print '<td colspan="2">';
379  foreach ($remainingdata as $datar) {
380  $father = array('rowid'=>$datar['rowid'], 'title'=>"???", 'mainmenu'=>$datar['fk_mainmenu'], 'leftmenu'=>$datar['fk_leftmenu'], 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
381  //print 'Start with rowid='.$datar['rowid'].' mainmenu='.$father ['mainmenu'].' leftmenu='.$father ['leftmenu'].'<br>'."\n";
382  tree_recur($data, $father, 0, 'iddivjstree'.$datar['rowid'], 1, 1);
383  }
384 
385  print '</td>';
386 
387  print '</tr>';
388 
389  print '</table>';
390  }
391 
392  print '</div>';
393 } else {
394  $langs->load("errors");
395  setEventMessages($langs->trans("ErrorFeatureNeedJavascript"), null, 'errors');
396 }
397 
398 print '<br>';
399 
400 // End of page
401 llxFooter();
402 $db->close();
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
FormAdmin
Class to generate html code for admin pages.
Definition: html.formadmin.class.php:30
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4389
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
img_delete
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
Definition: functions.lib.php:4429
dolGetButtonTitle
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.
Definition: functions.lib.php:10605
img_edit_add
img_edit_add($titlealt='default', $other='')
Show logo +.
Definition: functions.lib.php:4353
tree_recur
tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree', $donoresetalreadyloaded=0, $showfk=0, $moreparam='')
Recursive function to output a tree.
Definition: treeview.lib.php:114
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
llxHeader
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
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 ...
Definition: security.lib.php:933