dolibarr  20.0.0-beta
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 // Load Dolibarr environment
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array("other", "admin"));
34 
35 $dirstandard = array();
36 $dirsmartphone = array();
37 $dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
38 foreach ($dirmenus as $dirmenu) {
39  $dirstandard[] = $dirmenu.'standard';
40  $dirsmartphone[] = $dirmenu.'smartphone';
41 }
42 
43 $action = GETPOST('action', 'aZ09');
44 $confirm = GETPOST('confirm', 'alpha');
45 
46 //$menu_handler_top = getDolGlobalString('MAIN_MENU_STANDARD');
47 $menu_handler_top = 'all';
48 $menu_handler_top = preg_replace('/(_backoffice\.php|_menu\.php)/i', '', $menu_handler_top);
49 $menu_handler_top = preg_replace('/(_frontoffice\.php|_menu\.php)/i', '', $menu_handler_top);
50 
51 $menu_handler = $menu_handler_top;
52 
53 if (GETPOST("handler_origine")) {
54  $menu_handler = GETPOST("handler_origine");
55 }
56 if (GETPOST("menu_handler")) {
57  $menu_handler = GETPOST("menu_handler");
58 }
59 
60 $menu_handler_to_search = preg_replace('/(_backoffice|_frontoffice|_menu)?(\.php)?/i', '', $menu_handler);
61 
62 if (empty($user->admin)) {
64 }
65 
66 
67 /*
68  * Actions
69  */
70 
71 if ($action == 'up') {
72  $current = array();
73  $previous = array();
74 
75  // Get current position
76  $sql = "SELECT m.rowid, m.position, m.type, m.fk_menu";
77  $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
78  $sql .= " WHERE m.rowid = ".GETPOSTINT("menuId");
79  dol_syslog("admin/menus/index.php ".$sql);
80  $result = $db->query($sql);
81  $num = $db->num_rows($result);
82  $i = 0;
83  while ($i < $num) {
84  $obj = $db->fetch_object($result);
85  $current['rowid'] = $obj->rowid;
86  $current['order'] = $obj->position;
87  $current['type'] = $obj->type;
88  $current['fk_menu'] = $obj->fk_menu;
89  $i++;
90  }
91 
92  // Menu before
93  $sql = "SELECT m.rowid, m.position";
94  $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
95  $sql .= " WHERE (m.position < ".($current['order'])." OR (m.position = ".($current['order'])." AND rowid < ".GETPOSTINT("menuId")."))";
96  $sql .= " AND m.menu_handler='".$db->escape($menu_handler_to_search)."'";
97  $sql .= " AND m.entity = ".$conf->entity;
98  $sql .= " AND m.type = '".$db->escape($current['type'])."'";
99  $sql .= " AND m.fk_menu = '".$db->escape($current['fk_menu'])."'";
100  $sql .= " ORDER BY m.position, m.rowid";
101  dol_syslog("admin/menus/index.php ".$sql);
102  $result = $db->query($sql);
103  $num = $db->num_rows($result);
104  $i = 0;
105  while ($i < $num) {
106  $obj = $db->fetch_object($result);
107  $previous['rowid'] = $obj->rowid;
108  $previous['order'] = $obj->position;
109  $i++;
110  }
111 
112  $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
113  $sql .= " SET m.position = ".((int) $previous['order']);
114  $sql .= " WHERE m.rowid = ".((int) $current['rowid']); // Up the selected entry
115  dol_syslog("admin/menus/index.php ".$sql);
116  $db->query($sql);
117  $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
118  $sql .= " SET m.position = ".((int) ($current['order'] != $previous['order'] ? $current['order'] : $current['order'] + 1));
119  $sql .= " WHERE m.rowid = ".((int) $previous['rowid']); // Descend celui du dessus
120  dol_syslog("admin/menus/index.php ".$sql);
121  $db->query($sql);
122 } elseif ($action == 'down') {
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 = ".GETPOSTINT("menuId");
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  $obj = $db->fetch_object($result);
136  $current['rowid'] = $obj->rowid;
137  $current['order'] = $obj->position;
138  $current['type'] = $obj->type;
139  $current['fk_menu'] = $obj->fk_menu;
140  $i++;
141  }
142 
143  // Menu after
144  $sql = "SELECT m.rowid, m.position";
145  $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
146  $sql .= " WHERE (m.position > ".($current['order'])." OR (m.position = ".($current['order'])." AND rowid > ".GETPOSTINT("menuId")."))";
147  $sql .= " AND m.menu_handler='".$db->escape($menu_handler_to_search)."'";
148  $sql .= " AND m.entity = ".$conf->entity;
149  $sql .= " AND m.type = '".$db->escape($current['type'])."'";
150  $sql .= " AND m.fk_menu = '".$db->escape($current['fk_menu'])."'";
151  $sql .= " ORDER BY m.position, m.rowid";
152  dol_syslog("admin/menus/index.php ".$sql);
153  $result = $db->query($sql);
154  $num = $db->num_rows($result);
155  $i = 0;
156  while ($i < $num) {
157  $obj = $db->fetch_object($result);
158  $next['rowid'] = $obj->rowid;
159  $next['order'] = $obj->position;
160  $i++;
161  }
162 
163  $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
164  $sql .= " SET m.position = ".((int) ($current['order'] != $next['order'] ? $next['order'] : $current['order'] + 1)); // Down the selected entry
165  $sql .= " WHERE m.rowid = ".((int) $current['rowid']);
166  dol_syslog("admin/menus/index.php ".$sql);
167  $db->query($sql);
168  $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m"; // Up the next entry
169  $sql .= " SET m.position = ".((int) $current['order']);
170  $sql .= " WHERE m.rowid = ".((int) $next['rowid']);
171  dol_syslog("admin/menus/index.php ".$sql);
172  $db->query($sql);
173 } elseif ($action == 'confirm_delete' && $confirm == 'yes') {
174  $db->begin();
175 
176  $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu";
177  $sql .= " WHERE rowid = ".GETPOSTINT('menuId');
178  $resql = $db->query($sql);
179  if ($resql) {
180  $db->commit();
181 
182  setEventMessages($langs->trans("MenuDeleted"), null, 'mesgs');
183 
184  header("Location: ".DOL_URL_ROOT.'/admin/menus/index.php?menu_handler='.$menu_handler);
185  exit;
186  } else {
187  $db->rollback();
188 
189  $reload = 0;
190  $action = '';
191  }
192 }
193 
194 
195 /*
196  * View
197  */
198 
199 $form = new Form($db);
200 $formadmin = new FormAdmin($db);
201 
202 $arrayofjs = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
203 $arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
204 
205 llxHeader('', $langs->trans("Menus"), '', '', 0, 0, $arrayofjs, $arrayofcss);
206 
207 
208 print load_fiche_titre($langs->trans("Menus"), '', 'title_setup');
209 
210 
211 $h = 0;
212 $head = array();
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 hideonsmartphone">'.$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 = ".GETPOSTINT('menuId');
235  $result = $db->query($sql);
236  $obj = $db->fetch_object($result);
237 
238  print $form->formconfirm("index.php?menu_handler=".$menu_handler."&menuId=".GETPOSTINT('menuId'), $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 small" 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 
261 // MENU TREE
262 
263 
264 /*-------------------- MAIN -----------------------
265 Array of the menu tree:
266 - Is an array in with 2 dimensions.
267 - A single line represents an item : data[$x]
268 - Each line has 3 data items:
269  - The index of the item;
270  - The index of the item's parent;
271  - The string to show
272 i.e.: data[]= array (index, parent index, string )
273 */
274 
275 // First the root item of the tree must be declared:
276 
277 $data = array();
278 $data[] = array('rowid' => 0, 'fk_menu' => -1, 'title' => "racine", 'mainmenu' => '', 'leftmenu' => '', 'fk_mainmenu' => '', 'fk_leftmenu' => '');
279 
280 // Then all child items must be declared
281 
282 $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";
283 $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
284 $sql .= " WHERE menu_handler = '".$db->escape($menu_handler_to_search)."'";
285 $sql .= " AND entity = ".$conf->entity;
286 //$sql.= " AND fk_menu >= 0";
287 $sql .= " ORDER BY m.position, m.rowid"; // Order is position then rowid (because we need a sort criteria when position is same)
288 
289 $res = $db->query($sql);
290 if ($res) {
291  $num = $db->num_rows($res);
292 
293  $i = 1;
294  while ($menu = $db->fetch_array($res)) {
295  if (!empty($menu['langs'])) {
296  $langs->load($menu['langs']);
297  }
298  $titre = $langs->trans($menu['titre']);
299 
300  $entry = '<table class="nobordernopadding centpercent"><tr><td class="tdoverflowmax200">';
301  $entry .= '<strong class="paddingleft"><a href="edit.php?menu_handler='.$menu_handler_to_search.'&action=edit&token='.newToken().'&menuId='.$menu['rowid'].'">'.$titre.'</a></strong>';
302  $entry .= '</td>';
303  $entry .= '<td class="right nowraponall">';
304  $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> ';
305  $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> ';
306  $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> ';
307  $entry .= '&nbsp; ';
308  $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>';
309  $entry .= '</td></tr></table>';
310 
311  $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> ';
312  $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> ';
313  $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> ';
314  $buttons .= '&nbsp; ';
315  $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>';
316 
317  $data[] = array(
318  'rowid' => $menu['rowid'],
319  'module' => $menu['module'],
320  'fk_menu' => $menu['fk_menu'],
321  'title' => $titre,
322  'mainmenu' => $menu['mainmenu'],
323  'leftmenu' => $menu['leftmenu'],
324  'fk_mainmenu' => $menu['fk_mainmenu'],
325  'fk_leftmenu' => $menu['fk_leftmenu'],
326  'position' => $menu['position'],
327  'entry' => $entry,
328  'buttons' => $buttons
329  );
330  $i++;
331  }
332 }
333 
334 global $tree_recur_alreadyadded; // This var was def into tree_recur
335 
336 //var_dump($data);
337 
338 print '<div class="div-table-responsive">';
339 print '<table class="noborder centpercent">';
340 
341 print '<tr class="liste_titre">';
342 print '<td>'.$langs->trans("TreeMenuPersonalized").'</td>';
343 print '<td class="right"><div id="iddivjstreecontrol"><a href="#">'.img_picto('', 'folder', 'class="paddingright"').$langs->trans("UndoExpandAll").'</a>';
344 print ' | <a href="#">'.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ExpandAll").'</a></div></td>';
345 print '</tr>';
346 
347 print '<tr>';
348 print '<td colspan="2">';
349 
350 
351 //tree_recur($data, $data[0], 0, 'iddivjstree', 0, 1); // use this to get info on name and foreign keys of menu entry
352 tree_recur($data, $data[0], 0, 'iddivjstree', 0, 0); // $data[0] is virtual record 'racine'
353 
354 
355 print '</td>';
356 print '</tr>';
357 
358 print '</table>';
359 print '</div>';
360 
361 // Process remaining records (records that are not linked to root by any path)
362 $remainingdata = array();
363 foreach ($data as $datar) {
364  if (empty($datar['rowid']) || !empty($tree_recur_alreadyadded[$datar['rowid']])) {
365  continue;
366  }
367  $remainingdata[] = $datar;
368 }
369 
370 if (count($remainingdata)) {
371  print '<div class="div-table-responsive">';
372  print '<table class="noborder centpercent">';
373 
374  print '<tr class="liste_titre">';
375  print '<td>'.$langs->trans("NotTopTreeMenuPersonalized").'</td>';
376  print '<td class="right"></td>';
377  print '</tr>';
378 
379  print '<tr>';
380  print '<td colspan="2">';
381  foreach ($remainingdata as $datar) {
382  $father = array('rowid' => $datar['rowid'], 'title' => "???", 'mainmenu' => $datar['fk_mainmenu'], 'leftmenu' => $datar['fk_leftmenu'], 'fk_mainmenu' => '', 'fk_leftmenu' => '');
383  //print 'Start with rowid='.$datar['rowid'].' mainmenu='.$father ['mainmenu'].' leftmenu='.$father ['leftmenu'].'<br>'."\n";
384  tree_recur($data, $father, 0, 'iddivjstree'.$datar['rowid'], 1, 1);
385  }
386 
387  print '</td>';
388 
389  print '</tr>';
390 
391  print '</table>';
392  print '</div>';
393 }
394 
395 print '<br>';
396 
397 // End of page
398 llxFooter();
399 $db->close();
Class to generate html code for admin pages.
Class to manage generation of HTML components Only common components must be here.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
img_edit_add($titlealt='default', $other='')
Show logo +.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
llxFooter()
Footer empty.
Definition: index.php:72
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:64
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree', $donoresetalreadyloaded=0, $showfk=0, $moreparam='')
Recursive function to output a tree.