dolibarr 21.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-2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
32
41// Load translation files required by the page
42$langs->loadLangs(array("other", "admin"));
43
44$dirstandard = array();
45$dirsmartphone = array();
46$dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
47foreach ($dirmenus as $dirmenu) {
48 $dirstandard[] = $dirmenu.'standard';
49 $dirsmartphone[] = $dirmenu.'smartphone';
50}
51
52$action = GETPOST('action', 'aZ09');
53$confirm = GETPOST('confirm', 'alpha');
54
55//$menu_handler_top = getDolGlobalString('MAIN_MENU_STANDARD');
56$menu_handler_top = 'all';
57$menu_handler_top = preg_replace('/(_backoffice\.php|_menu\.php)/i', '', $menu_handler_top);
58$menu_handler_top = preg_replace('/(_frontoffice\.php|_menu\.php)/i', '', $menu_handler_top);
59
60$menu_handler = $menu_handler_top;
61
62if (GETPOST("handler_origine")) {
63 $menu_handler = GETPOST("handler_origine");
64}
65if (GETPOST("menu_handler")) {
66 $menu_handler = GETPOST("menu_handler");
67}
68
69$menu_handler_to_search = preg_replace('/(_backoffice|_frontoffice|_menu)?(\.php)?/i', '', $menu_handler);
70
71if (empty($user->admin)) {
73}
74
75
76/*
77 * Actions
78 */
79
80if ($action == 'up') {
81 $current = array();
82 $previous = array();
83
84 // Get current position
85 $sql = "SELECT m.rowid, m.position, m.type, m.fk_menu";
86 $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
87 $sql .= " WHERE m.rowid = ".GETPOSTINT("menuId");
88 dol_syslog("admin/menus/index.php ".$sql);
89 $result = $db->query($sql);
90 $num = $db->num_rows($result);
91 $i = 0;
92 while ($i < $num) {
93 $obj = $db->fetch_object($result);
94 $current['rowid'] = (int) $obj->rowid;
95 $current['order'] = (int) $obj->position;
96 $current['type'] = (string) $obj->type;
97 $current['fk_menu'] = (int) $obj->fk_menu;
98 $i++;
99 }
100
101 // Menu before
102 $sql = "SELECT m.rowid, m.position";
103 $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
104 $sql .= " WHERE (m.position < ".($current['order'])." OR (m.position = ".($current['order'])." AND rowid < ".GETPOSTINT("menuId")."))";
105 $sql .= " AND m.menu_handler='".$db->escape($menu_handler_to_search)."'";
106 $sql .= " AND m.entity = ".$conf->entity;
107 $sql .= " AND m.type = '".$db->escape($current['type'])."'";
108 $sql .= " AND m.fk_menu = '".$db->escape($current['fk_menu'])."'";
109 $sql .= " ORDER BY m.position, m.rowid";
110 dol_syslog("admin/menus/index.php ".$sql);
111 $result = $db->query($sql);
112 $num = $db->num_rows($result);
113 $i = 0;
114 while ($i < $num) {
115 $obj = $db->fetch_object($result);
116 $previous['rowid'] = (int) $obj->rowid;
117 $previous['order'] = (int) $obj->position;
118 $i++;
119 }
120
121 $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
122 $sql .= " SET m.position = ".((int) $previous['order']);
123 $sql .= " WHERE m.rowid = ".((int) $current['rowid']); // Up the selected entry
124 dol_syslog("admin/menus/index.php ".$sql);
125 $db->query($sql);
126 $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
127 $sql .= " SET m.position = ".((int) ($current['order'] != $previous['order'] ? $current['order'] : $current['order'] + 1));
128 $sql .= " WHERE m.rowid = ".((int) $previous['rowid']); // Descend celui du dessus
129 dol_syslog("admin/menus/index.php ".$sql);
130 $db->query($sql);
131} elseif ($action == 'down') {
132 $current = array();
133 $next = array();
134
135 // Get current position
136 $sql = "SELECT m.rowid, m.position, m.type, m.fk_menu";
137 $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
138 $sql .= " WHERE m.rowid = ".GETPOSTINT("menuId");
139 dol_syslog("admin/menus/index.php ".$sql);
140 $result = $db->query($sql);
141 $num = $db->num_rows($result);
142 $i = 0;
143 while ($i < $num) {
144 $obj = $db->fetch_object($result);
145 $current['rowid'] = (int) $obj->rowid;
146 $current['order'] = (int) $obj->position;
147 $current['type'] = (string) $obj->type;
148 $current['fk_menu'] = (int) $obj->fk_menu;
149 $i++;
150 }
151
152 // Menu after
153 $sql = "SELECT m.rowid, m.position";
154 $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
155 $sql .= " WHERE (m.position > ".($current['order'])." OR (m.position = ".($current['order'])." AND rowid > ".GETPOSTINT("menuId")."))";
156 $sql .= " AND m.menu_handler='".$db->escape($menu_handler_to_search)."'";
157 $sql .= " AND m.entity = ".$conf->entity;
158 $sql .= " AND m.type = '".$db->escape($current['type'])."'";
159 $sql .= " AND m.fk_menu = '".$db->escape($current['fk_menu'])."'";
160 $sql .= " ORDER BY m.position, m.rowid";
161 dol_syslog("admin/menus/index.php ".$sql);
162 $result = $db->query($sql);
163 $num = $db->num_rows($result);
164 $i = 0;
165 while ($i < $num) {
166 $obj = $db->fetch_object($result);
167 $next['rowid'] = (int) $obj->rowid;
168 $next['order'] = (int) $obj->position;
169 $i++;
170 }
171
172 $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
173 $sql .= " SET m.position = ".((int) ($current['order'] != $next['order'] ? $next['order'] : $current['order'] + 1)); // Down the selected entry
174 $sql .= " WHERE m.rowid = ".((int) $current['rowid']);
175 dol_syslog("admin/menus/index.php ".$sql);
176 $db->query($sql);
177 $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m"; // Up the next entry
178 $sql .= " SET m.position = ".((int) $current['order']);
179 $sql .= " WHERE m.rowid = ".((int) $next['rowid']);
180 dol_syslog("admin/menus/index.php ".$sql);
181 $db->query($sql);
182} elseif ($action == 'confirm_delete' && $confirm == 'yes') {
183 $db->begin();
184
185 $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu";
186 $sql .= " WHERE rowid = ".GETPOSTINT('menuId');
187 $resql = $db->query($sql);
188 if ($resql) {
189 $db->commit();
190
191 setEventMessages($langs->trans("MenuDeleted"), null, 'mesgs');
192
193 header("Location: ".DOL_URL_ROOT.'/admin/menus/index.php?menu_handler='.$menu_handler);
194 exit;
195 } else {
196 $db->rollback();
197
198 $reload = 0;
199 $action = '';
200 }
201}
202
203
204/*
205 * View
206 */
207
208$form = new Form($db);
209$formadmin = new FormAdmin($db);
210
211$arrayofjs = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
212$arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
213
214llxHeader('', $langs->trans("Menus"), '', '', 0, 0, $arrayofjs, $arrayofcss, '', 'mod-admin page-menus_index');
215
216
217print load_fiche_titre($langs->trans("Menus"), '', 'title_setup');
218
219
220$h = 0;
221$head = array();
222
223$head[$h][0] = DOL_URL_ROOT."/admin/menus.php";
224$head[$h][1] = $langs->trans("MenuHandlers");
225$head[$h][2] = 'handler';
226$h++;
227
228$head[$h][0] = DOL_URL_ROOT."/admin/menus/index.php";
229$head[$h][1] = $langs->trans("MenuAdmin");
230$head[$h][2] = 'editor';
231$h++;
232
233print dol_get_fiche_head($head, 'editor', '', -1);
234
235print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("MenusEditorDesc")."</span>";
236print '<br class="hideonsmartphone">'."\n";
237print "<br>\n";
238
239
240// Confirmation for remove menu entry
241if ($action == 'delete') {
242 $sql = "SELECT m.titre as title";
243 $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
244 $sql .= " WHERE m.rowid = ".GETPOSTINT('menuId');
245 $result = $db->query($sql);
246 $obj = $db->fetch_object($result);
247
248 print $form->formconfirm("index.php?menu_handler=".$menu_handler."&menuId=".GETPOSTINT('menuId'), $langs->trans("DeleteMenu"), $langs->trans("ConfirmDeleteMenu", $obj->title), "confirm_delete");
249}
250
251$newcardbutton = '';
252if ($user->admin) {
253 $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']));
254}
255
256print '<form name="newmenu" class="nocellnopadd" action="'.$_SERVER["PHP_SELF"].'">';
257print '<input type="hidden" action="change_menu_handler">';
258print $langs->trans("MenuHandler").': ';
259$formadmin->select_menu_families($menu_handler.(preg_match('/_menu/', $menu_handler) ? '' : '_menu'), 'menu_handler', array_merge($dirstandard, $dirsmartphone));
260print ' &nbsp; <input type="submit" class="button small" value="'.$langs->trans("Refresh").'">';
261
262print '<div class="floatright">';
263print $newcardbutton;
264print '</div>';
265
266print '</form>';
267
268print '<br>';
269
270
271// MENU TREE
272
273
274/*-------------------- MAIN -----------------------
275Array of the menu tree:
276- Is an array in with 2 dimensions.
277- A single line represents an item : data[$x]
278- Each line has 3 data items:
279 - The index of the item;
280 - The index of the item's parent;
281 - The string to show
282i.e.: data[]= array (index, parent index, string )
283*/
284
285// First the root item of the tree must be declared:
286
287$data = array();
288$data[] = array('rowid' => 0, 'fk_menu' => -1, 'title' => 'racine', 'mainmenu' => '', 'leftmenu' => '', 'fk_mainmenu' => '', 'fk_leftmenu' => '');
289
290// Then all child items must be declared
291
292$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";
293$sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
294$sql .= " WHERE menu_handler = '".$db->escape($menu_handler_to_search)."'";
295$sql .= " AND entity = ".$conf->entity;
296//$sql.= " AND fk_menu >= 0";
297$sql .= " ORDER BY m.position, m.rowid"; // Order is position then rowid (because we need a sort criteria when position is same)
298
299$res = $db->query($sql);
300if ($res) {
301 $num = $db->num_rows($res);
302
303 $i = 1;
304 while ($menu = $db->fetch_array($res)) {
305 if (!empty($menu['langs'])) {
306 $langs->load($menu['langs']);
307 }
308 $titre = $langs->trans($menu['titre']);
309
310 $entry = '<table class="nobordernopadding centpercent"><tr><td class="tdoverflowmax200">';
311 $entry .= '<strong class="paddingleft"><a href="edit.php?menu_handler='.$menu_handler_to_search.'&action=edit&token='.newToken().'&menuId='.$menu['rowid'].'">'.$titre.'</a></strong>';
312 $entry .= '</td>';
313 $entry .= '<td class="right nowraponall">';
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' => (int) $menu['rowid'],
329 'module' => (string) $menu['module'],
330 'fk_menu' => (int) $menu['fk_menu'],
331 'title' => (string) $titre,
332 'mainmenu' => (string) $menu['mainmenu'],
333 'leftmenu' => (string) $menu['leftmenu'],
334 'fk_mainmenu' => (string) $menu['fk_mainmenu'],
335 'fk_leftmenu' => (string) $menu['fk_leftmenu'],
336 'position' => (int) $menu['position'],
337 'entry' => $entry,
338 'buttons' => $buttons
339 );
340 $i++;
341 }
342}
343
344global $tree_recur_alreadyadded; // This var was def into tree_recur
345
346//var_dump($data);
347
348print '<div class="div-table-responsive">';
349print '<table class="noborder centpercent">';
350
351print '<tr class="liste_titre">';
352print '<td>'.$langs->trans("TreeMenuPersonalized").'</td>';
353print '<td class="right"><div id="iddivjstreecontrol"><a href="#">'.img_picto($langs->trans("UndoExpandAll"), 'folder', 'class="paddingright"').'</a>';
354print ' | <a href="#">'.img_picto($langs->trans("ExpandAll"), 'folder-open', 'class="paddingright"').'</a></div></td>';
355print '</tr>';
356
357print '<tr>';
358print '<td colspan="2">';
359
360
361//tree_recur($data, $data[0], 0, 'iddivjstree', 0, 1); // use this to get info on name and foreign keys of menu entry
362tree_recur($data, $data[0], 0, 'iddivjstree', 0, 0); // $data[0] is virtual record 'racine'
363
364
365print '</td>';
366print '</tr>';
367
368print '</table>';
369print '</div>';
370
371// Process remaining records (records that are not linked to root by any path)
372$remainingdata = array();
373foreach ($data as $datar) {
374 if (empty($datar['rowid']) || !empty($tree_recur_alreadyadded[$datar['rowid']])) {
375 continue;
376 }
377 $remainingdata[] = $datar;
378}
379
380if (count($remainingdata)) {
381 print '<div class="div-table-responsive">';
382 print '<table class="noborder centpercent">';
383
384 print '<tr class="liste_titre">';
385 print '<td>'.$langs->trans("NotTopTreeMenuPersonalized").'</td>';
386 print '<td class="right"></td>';
387 print '</tr>';
388
389 print '<tr>';
390 print '<td colspan="2">';
391 foreach ($remainingdata as $datar) {
392 $father = array('rowid' => $datar['rowid'], 'title' => "???", 'mainmenu' => $datar['fk_mainmenu'], 'leftmenu' => $datar['fk_leftmenu'], 'fk_mainmenu' => '', 'fk_leftmenu' => '');
393 //print 'Start with rowid='.$datar['rowid'].' mainmenu='.$father ['mainmenu'].' leftmenu='.$father ['leftmenu'].'<br>'."\n";
394 tree_recur($data, $father, 0, 'iddivjstree'.$datar['rowid'], 1, 1);
395 }
396
397 print '</td>';
398
399 print '</tr>';
400
401 print '</table>';
402 print '</div>';
403}
404
405print '<br>';
406
407// End of page
408llxFooter();
409$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to generate html code for admin pages.
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.