dolibarr 24.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-2025 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2025 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';
37require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
39
40// Load translation files required by the page
41$langs->loadLangs(array("other", "admin"));
42
43$dirstandard = array();
44$dirsmartphone = array();
45$dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
46foreach ($dirmenus as $dirmenu) {
47 $dirstandard[] = $dirmenu.'standard';
48 $dirsmartphone[] = $dirmenu.'smartphone';
49}
50
51$action = GETPOST('action', 'aZ09');
52$confirm = GETPOST('confirm', 'alpha');
53
54//$menu_handler_top = getDolGlobalString('MAIN_MENU_STANDARD');
55$menu_handler_top = 'all';
56$menu_handler_top = preg_replace('/(_backoffice\.php|_menu\.php)/i', '', $menu_handler_top);
57$menu_handler_top = preg_replace('/(_frontoffice\.php|_menu\.php)/i', '', $menu_handler_top);
58
59$menu_handler = $menu_handler_top;
60
61if (GETPOST("handler_origine")) {
62 $menu_handler = GETPOST("handler_origine");
63}
64if (GETPOST("menu_handler")) {
65 $menu_handler = GETPOST("menu_handler");
66}
67
68$menu_handler_to_search = preg_replace('/(_backoffice|_frontoffice|_menu)?(\.php)?/i', '', $menu_handler);
69
70if (empty($user->admin)) {
72}
73
74
75/*
76 * Actions
77 */
78
79if ($action == 'up') {
80 $current = array();
81 $previous = array();
82
83 // Get current position
84 $sql = "SELECT m.rowid, m.position, m.type, m.fk_menu";
85 $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
86 $sql .= " WHERE m.rowid = ".GETPOSTINT("menuId");
87 dol_syslog("admin/menus/index.php ".$sql);
88 $result = $db->query($sql);
89 $num = $db->num_rows($result);
90 $i = 0;
91 while ($i < $num) {
92 $obj = $db->fetch_object($result);
93 $current['rowid'] = (int) $obj->rowid;
94 $current['order'] = (int) $obj->position;
95 $current['type'] = (string) $obj->type;
96 $current['fk_menu'] = (int) $obj->fk_menu;
97 $i++;
98 }
99
100 // Menu before
101 $sql = "SELECT m.rowid, m.position";
102 $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
103 $sql .= " WHERE (m.position < ".($current['order'])." OR (m.position = ".($current['order'])." AND rowid < ".GETPOSTINT("menuId")."))";
104 $sql .= " AND m.menu_handler='".$db->escape($menu_handler_to_search)."'";
105 $sql .= " AND m.entity = ".$conf->entity;
106 $sql .= " AND m.type = '".$db->escape($current['type'])."'";
107 $sql .= " AND m.fk_menu = '".$db->escape((string) $current['fk_menu'])."'";
108 $sql .= " ORDER BY m.position, m.rowid";
109 dol_syslog("admin/menus/index.php ".$sql);
110 $result = $db->query($sql);
111 $num = $db->num_rows($result);
112 $i = 0;
113 while ($i < $num) {
114 $obj = $db->fetch_object($result);
115 $previous['rowid'] = (int) $obj->rowid;
116 $previous['order'] = (int) $obj->position;
117 $i++;
118 }
119
120 $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
121 $sql .= " SET m.position = ".((int) $previous['order']);
122 $sql .= " WHERE m.rowid = ".((int) $current['rowid']); // Up the selected entry
123 dol_syslog("admin/menus/index.php ".$sql);
124 $db->query($sql);
125 $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
126 $sql .= " SET m.position = ".((int) ($current['order'] != $previous['order'] ? $current['order'] : $current['order'] + 1));
127 $sql .= " WHERE m.rowid = ".((int) $previous['rowid']); // Descend celui du dessus
128 dol_syslog("admin/menus/index.php ".$sql);
129 $db->query($sql);
130} elseif ($action == 'down') {
131 $current = array();
132 $next = array();
133
134 // Get current position
135 $sql = "SELECT m.rowid, m.position, m.type, m.fk_menu";
136 $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
137 $sql .= " WHERE m.rowid = ".GETPOSTINT("menuId");
138 dol_syslog("admin/menus/index.php ".$sql);
139 $result = $db->query($sql);
140 $num = $db->num_rows($result);
141 $i = 0;
142 while ($i < $num) {
143 $obj = $db->fetch_object($result);
144 $current['rowid'] = (int) $obj->rowid;
145 $current['order'] = (int) $obj->position;
146 $current['type'] = (string) $obj->type;
147 $current['fk_menu'] = (int) $obj->fk_menu;
148 $i++;
149 }
150
151 // Menu after
152 $sql = "SELECT m.rowid, m.position";
153 $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
154 $sql .= " WHERE (m.position > ".($current['order'])." OR (m.position = ".($current['order'])." AND rowid > ".GETPOSTINT("menuId")."))";
155 $sql .= " AND m.menu_handler='".$db->escape($menu_handler_to_search)."'";
156 $sql .= " AND m.entity = ".$conf->entity;
157 $sql .= " AND m.type = '".$db->escape($current['type'])."'";
158 $sql .= " AND m.fk_menu = '".$db->escape((string) $current['fk_menu'])."'";
159 $sql .= " ORDER BY m.position, m.rowid";
160 dol_syslog("admin/menus/index.php ".$sql);
161 $result = $db->query($sql);
162 $num = $db->num_rows($result);
163 $i = 0;
164 while ($i < $num) {
165 $obj = $db->fetch_object($result);
166 $next['rowid'] = (int) $obj->rowid;
167 $next['order'] = (int) $obj->position;
168 $i++;
169 }
170
171 $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
172 $sql .= " SET m.position = ".((int) ($current['order'] != $next['order'] ? $next['order'] : $current['order'] + 1)); // Down the selected entry
173 $sql .= " WHERE m.rowid = ".((int) $current['rowid']);
174 dol_syslog("admin/menus/index.php ".$sql);
175 $db->query($sql);
176 $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m"; // Up the next entry
177 $sql .= " SET m.position = ".((int) $current['order']);
178 $sql .= " WHERE m.rowid = ".((int) $next['rowid']);
179 dol_syslog("admin/menus/index.php ".$sql);
180 $db->query($sql);
181} elseif ($action == 'confirm_delete' && $confirm == 'yes') {
182 $db->begin();
183
184 $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu";
185 $sql .= " WHERE rowid = ".GETPOSTINT('menuId');
186 $resql = $db->query($sql);
187 if ($resql) {
188 $db->commit();
189
190 setEventMessages($langs->trans("MenuDeleted"), null, 'mesgs');
191
192 header("Location: ".DOL_URL_ROOT.'/admin/menus/index.php?menu_handler='.$menu_handler);
193 exit;
194 } else {
195 $db->rollback();
196
197 $reload = 0;
198 $action = '';
199 }
200}
201
202
203/*
204 * View
205 */
206
207$form = new Form($db);
208$formadmin = new FormAdmin($db);
209
210$arrayofjs = array('/public/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/public/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
211$arrayofcss = array('/public/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
212
213llxHeader('', $langs->trans("Menus"), '', '', 0, 0, $arrayofjs, $arrayofcss, '', 'mod-admin page-menus_index');
214
215
216print load_fiche_titre($langs->trans("Menus"), '', 'title_setup');
217
218
219$h = 0;
220$head = array();
221
222$head[$h][0] = DOL_URL_ROOT."/admin/menus.php";
223$head[$h][1] = $langs->trans("MenuHandlers");
224$head[$h][2] = 'handler';
225$h++;
226
227$head[$h][0] = DOL_URL_ROOT."/admin/menus/index.php";
228$head[$h][1] = $langs->trans("MenuAdmin");
229$head[$h][2] = 'editor';
230$h++;
231
232print dol_get_fiche_head($head, 'editor', '', -1);
233
234print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("MenusEditorDesc")."</span>";
235print '<br class="hideonsmartphone">'."\n";
236print "<br>\n";
237
238
239// Confirmation for remove menu entry
240if ($action == 'delete') {
241 $sql = "SELECT m.titre as title";
242 $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
243 $sql .= " WHERE m.rowid = ".GETPOSTINT('menuId');
244 $result = $db->query($sql);
245 $obj = $db->fetch_object($result);
246
247 print $form->formconfirm("index.php?menu_handler=".$menu_handler."&menuId=".GETPOSTINT('menuId'), $langs->transnoentitiesnoconv("DeleteMenu"), $langs->transnoentitiesnoconv("ConfirmDeleteMenu", $obj->title), "confirm_delete");
248}
249
250$newcardbutton = '';
251if ($user->admin) {
252 $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']));
253}
254
255print '<form name="newmenu" class="nocellnopadd" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
256print '<input type="hidden" action="change_menu_handler">';
257print $langs->trans("MenuHandler").': ';
258$formadmin->select_menu_families($menu_handler.(preg_match('/_menu/', $menu_handler) ? '' : '_menu'), 'menu_handler', array_merge($dirstandard, $dirsmartphone));
259print ' &nbsp; <input type="submit" class="button small" value="'.$langs->trans("Refresh").'">';
260
261print '<div class="floatright">';
262print $newcardbutton;
263print '</div>';
264
265print '</form>';
266
267print '<br>';
268
269
270// MENU TREE
271
272
273/*-------------------- MAIN -----------------------
274Array of the menu tree:
275- Is an array in with 2 dimensions.
276- A single line represents an item : data[$x]
277- Each line has 3 data items:
278 - The index of the item;
279 - The index of the item's parent;
280 - The string to show
281i.e.: data[]= array (index, parent index, string )
282*/
283
284// First the root item of the tree must be declared:
285
286$data = array();
287$data[] = array('rowid' => 0, 'fk_menu' => -1, 'title' => 'racine', 'mainmenu' => '', 'leftmenu' => '', 'fk_mainmenu' => '', 'fk_leftmenu' => '');
288
289// Then all child items must be declared
290
291$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";
292$sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
293$sql .= " WHERE menu_handler = '".$db->escape($menu_handler_to_search)."'";
294$sql .= " AND entity = ".$conf->entity;
295//$sql.= " AND fk_menu >= 0";
296$sql .= " ORDER BY m.position, m.rowid"; // Order is position then rowid (because we need a sort criteria when position is same)
297
298$res = $db->query($sql);
299if ($res) {
300 $num = $db->num_rows($res);
301
302 $i = 1;
303 while ($menu = $db->fetch_array($res)) {
304 if (!empty($menu['langs'])) {
305 $langs->load($menu['langs']);
306 }
307 $titre = $langs->trans($menu['titre']);
308
309 $entry = '<table class="nobordernopadding centpercent"><tr><td class="tdoverflowmax200">';
310 $entry .= '<strong class="paddingleft"><a href="edit.php?menu_handler='.$menu_handler_to_search.'&action=edit&token='.newToken().'&menuId='.$menu['rowid'].'">'.$titre.'</a></strong>';
311 $entry .= '</td>';
312 $entry .= '<td class="right nowraponall">';
313 $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> ';
314 $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> ';
315 $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> ';
316 $entry .= '&nbsp; ';
317 $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>';
318 $entry .= '</td></tr></table>';
319
320 $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> ';
321 $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> ';
322 $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> ';
323 $buttons .= '&nbsp; ';
324 $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>';
325
326 $data[] = array(
327 'rowid' => (int) $menu['rowid'],
328 'module' => (string) $menu['module'],
329 'fk_menu' => (int) $menu['fk_menu'],
330 'title' => (string) $titre,
331 'mainmenu' => (string) $menu['mainmenu'],
332 'leftmenu' => (string) $menu['leftmenu'],
333 'fk_mainmenu' => (string) $menu['fk_mainmenu'],
334 'fk_leftmenu' => (string) $menu['fk_leftmenu'],
335 'position' => (int) $menu['position'],
336 'entry' => $entry,
337 'buttons' => $buttons
338 );
339 $i++;
340 }
341}
342
343global $tree_recur_alreadyadded; // This var was def into tree_recur
344
345//var_dump($data);
346
347print '<div class="div-table-responsive">';
348print '<table class="noborder centpercent">';
349
350print '<tr class="liste_titre">';
351print '<td>'.$langs->trans("TreeMenuPersonalized").'</td>';
352print '<td class="right"><div id="iddivjstreecontrol"><a href="#">'.img_picto($langs->trans("UndoExpandAll"), 'folder', 'class="paddingright"').'</a>';
353print ' | <a href="#">'.img_picto($langs->trans("ExpandAll"), 'folder-open', 'class="paddingright"').'</a></div></td>';
354print '</tr>';
355
356print '<tr>';
357print '<td colspan="2">';
358
359
360//tree_recur($data, $data[0], 0, 'iddivjstree', 0, 1); // use this to get info on name and foreign keys of menu entry
361tree_recur($data, $data[0], 0, 'iddivjstree', 0, 0); // $data[0] is virtual record 'racine'
362
363
364print '</td>';
365print '</tr>';
366
367print '</table>';
368print '</div>';
369
370// Process remaining records (records that are not linked to root by any path)
371$remainingdata = array();
372foreach ($data as $datar) {
373 if (empty($datar['rowid']) || !empty($tree_recur_alreadyadded[$datar['rowid']])) {
374 continue;
375 }
376 $remainingdata[] = $datar;
377}
378
379if (count($remainingdata)) {
380 print '<div class="div-table-responsive">';
381 print '<table class="noborder centpercent">';
382
383 print '<tr class="liste_titre">';
384 print '<td>'.$langs->trans("NotTopTreeMenuPersonalized").'</td>';
385 print '<td class="right"></td>';
386 print '</tr>';
387
388 print '<tr>';
389 print '<td colspan="2">';
390 foreach ($remainingdata as $datar) {
391 $father = array('rowid' => $datar['rowid'], 'title' => "???", 'mainmenu' => $datar['fk_mainmenu'], 'leftmenu' => $datar['fk_leftmenu'], 'fk_mainmenu' => '', 'fk_leftmenu' => '');
392 //print 'Start with rowid='.$datar['rowid'].' mainmenu='.$father ['mainmenu'].' leftmenu='.$father ['leftmenu'].'<br>'."\n";
393 tree_recur($data, $father, 0, 'iddivjstree'.$datar['rowid'], 1, 1);
394 }
395
396 print '</td>';
397
398 print '</tr>';
399
400 print '</table>';
401 print '</div>';
402}
403
404print '<br>';
405
406// End of page
407llxFooter();
408$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class to generate html code for admin pages.
Class to manage generation of HTML components Only common components must be here.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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, $morecssdiv='')
Show tabs of a record.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
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.