dolibarr 18.0.6
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
28require '../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
30require_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
35if (!$user->admin) {
37}
38
39$dirstandard = array();
40$dirsmartphone = array();
41$dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
42foreach ($dirmenus as $dirmenu) {
43 $dirstandard[] = $dirmenu.'standard';
44 $dirsmartphone[] = $dirmenu.'smartphone';
45}
46
47$action = GETPOST('action', 'aZ09');
48$confirm = GETPOST('confirm', 'alpha');
49
50$menu_handler_top = $conf->global->MAIN_MENU_STANDARD;
51$menu_handler_smartphone = $conf->global->MAIN_MENU_SMARTPHONE;
52$menu_handler_top = preg_replace('/(_backoffice\.php|_menu\.php)/i', '', $menu_handler_top);
53$menu_handler_top = preg_replace('/(_frontoffice\.php|_menu\.php)/i', '', $menu_handler_top);
54$menu_handler_smartphone = preg_replace('/(_backoffice\.php|_menu\.php)/i', '', $menu_handler_smartphone);
55$menu_handler_smartphone = preg_replace('/(_frontoffice\.php|_menu\.php)/i', '', $menu_handler_smartphone);
56
57$menu_handler = $menu_handler_top;
58
59if (GETPOST("handler_origine")) {
60 $menu_handler = GETPOST("handler_origine");
61}
62if (GETPOST("menu_handler")) {
63 $menu_handler = GETPOST("menu_handler");
64}
65
66$menu_handler_to_search = preg_replace('/(_backoffice|_frontoffice|_menu)?(\.php)?/i', '', $menu_handler);
67
68
69/*
70 * Actions
71 */
72
73if ($action == 'up') {
74 $current = array();
75 $previous = array();
76
77 // Get current position
78 $sql = "SELECT m.rowid, m.position, m.type, m.fk_menu";
79 $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
80 $sql .= " WHERE m.rowid = ".GETPOST("menuId", "int");
81 dol_syslog("admin/menus/index.php ".$sql);
82 $result = $db->query($sql);
83 $num = $db->num_rows($result);
84 $i = 0;
85 while ($i < $num) {
86 $obj = $db->fetch_object($result);
87 $current['rowid'] = $obj->rowid;
88 $current['order'] = $obj->position;
89 $current['type'] = $obj->type;
90 $current['fk_menu'] = $obj->fk_menu;
91 $i++;
92 }
93
94 // Menu before
95 $sql = "SELECT m.rowid, m.position";
96 $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
97 $sql .= " WHERE (m.position < ".($current['order'])." OR (m.position = ".($current['order'])." AND rowid < ".GETPOST("menuId", "int")."))";
98 $sql .= " AND m.menu_handler='".$db->escape($menu_handler_to_search)."'";
99 $sql .= " AND m.entity = ".$conf->entity;
100 $sql .= " AND m.type = '".$db->escape($current['type'])."'";
101 $sql .= " AND m.fk_menu = '".$db->escape($current['fk_menu'])."'";
102 $sql .= " ORDER BY m.position, m.rowid";
103 dol_syslog("admin/menus/index.php ".$sql);
104 $result = $db->query($sql);
105 $num = $db->num_rows($result);
106 $i = 0;
107 while ($i < $num) {
108 $obj = $db->fetch_object($result);
109 $previous['rowid'] = $obj->rowid;
110 $previous['order'] = $obj->position;
111 $i++;
112 }
113
114 $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
115 $sql .= " SET m.position = ".((int) $previous['order']);
116 $sql .= " WHERE m.rowid = ".((int) $current['rowid']); // Up the selected entry
117 dol_syslog("admin/menus/index.php ".$sql);
118 $db->query($sql);
119 $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
120 $sql .= " SET m.position = ".((int) ($current['order'] != $previous['order'] ? $current['order'] : $current['order'] + 1));
121 $sql .= " WHERE m.rowid = ".((int) $previous['rowid']); // Descend celui du dessus
122 dol_syslog("admin/menus/index.php ".$sql);
123 $db->query($sql);
124} elseif ($action == 'down') {
125 $current = array();
126 $next = array();
127
128 // Get current position
129 $sql = "SELECT m.rowid, m.position, m.type, m.fk_menu";
130 $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
131 $sql .= " WHERE m.rowid = ".GETPOST("menuId", "int");
132 dol_syslog("admin/menus/index.php ".$sql);
133 $result = $db->query($sql);
134 $num = $db->num_rows($result);
135 $i = 0;
136 while ($i < $num) {
137 $obj = $db->fetch_object($result);
138 $current['rowid'] = $obj->rowid;
139 $current['order'] = $obj->position;
140 $current['type'] = $obj->type;
141 $current['fk_menu'] = $obj->fk_menu;
142 $i++;
143 }
144
145 // Menu after
146 $sql = "SELECT m.rowid, m.position";
147 $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
148 $sql .= " WHERE (m.position > ".($current['order'])." OR (m.position = ".($current['order'])." AND rowid > ".GETPOST("menuId", "int")."))";
149 $sql .= " AND m.menu_handler='".$db->escape($menu_handler_to_search)."'";
150 $sql .= " AND m.entity = ".$conf->entity;
151 $sql .= " AND m.type = '".$db->escape($current['type'])."'";
152 $sql .= " AND m.fk_menu = '".$db->escape($current['fk_menu'])."'";
153 $sql .= " ORDER BY m.position, m.rowid";
154 dol_syslog("admin/menus/index.php ".$sql);
155 $result = $db->query($sql);
156 $num = $db->num_rows($result);
157 $i = 0;
158 while ($i < $num) {
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 = ".((int) ($current['order'] != $next['order'] ? $next['order'] : $current['order'] + 1)); // Down the selected entry
167 $sql .= " WHERE m.rowid = ".((int) $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 = ".((int) $current['order']);
172 $sql .= " WHERE m.rowid = ".((int) $next['rowid']);
173 dol_syslog("admin/menus/index.php ".$sql);
174 $db->query($sql);
175} elseif ($action == 'confirm_delete' && $confirm == 'yes') {
176 $db->begin();
177
178 $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu";
179 $sql .= " WHERE rowid = ".GETPOST('menuId', 'int');
180 $resql = $db->query($sql);
181 if ($resql) {
182 $db->commit();
183
184 setEventMessages($langs->trans("MenuDeleted"), null, 'mesgs');
185
186 header("Location: ".DOL_URL_ROOT.'/admin/menus/index.php?menu_handler='.$menu_handler);
187 exit;
188 } else {
189 $db->rollback();
190
191 $reload = 0;
192 $action = '';
193 }
194}
195
196
197/*
198 * View
199 */
200
201$form = new Form($db);
202$formadmin = new FormAdmin($db);
203
204$arrayofjs = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
205$arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
206
207llxHeader('', $langs->trans("Menus"), '', '', 0, 0, $arrayofjs, $arrayofcss);
208
209
210print load_fiche_titre($langs->trans("Menus"), '', 'title_setup');
211
212
213$h = 0;
214
215$head[$h][0] = DOL_URL_ROOT."/admin/menus.php";
216$head[$h][1] = $langs->trans("MenuHandlers");
217$head[$h][2] = 'handler';
218$h++;
219
220$head[$h][0] = DOL_URL_ROOT."/admin/menus/index.php";
221$head[$h][1] = $langs->trans("MenuAdmin");
222$head[$h][2] = 'editor';
223$h++;
224
225print dol_get_fiche_head($head, 'editor', '', -1);
226
227print '<span class="opacitymedium">'.$langs->trans("MenusEditorDesc")."</span><br>\n";
228print "<br>\n";
229
230
231// Confirmation for remove menu entry
232if ($action == 'delete') {
233 $sql = "SELECT m.titre as title";
234 $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
235 $sql .= " WHERE m.rowid = ".GETPOST('menuId', 'int');
236 $result = $db->query($sql);
237 $obj = $db->fetch_object($result);
238
239 print $form->formconfirm("index.php?menu_handler=".$menu_handler."&menuId=".GETPOST('menuId', 'int'), $langs->trans("DeleteMenu"), $langs->trans("ConfirmDeleteMenu", $obj->title), "confirm_delete");
240}
241
242$newcardbutton = '';
243if ($user->admin) {
244 $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']));
245}
246
247print '<form name="newmenu" class="nocellnopadd" action="'.$_SERVER["PHP_SELF"].'">';
248print '<input type="hidden" action="change_menu_handler">';
249print $langs->trans("MenuHandler").': ';
250$formadmin->select_menu_families($menu_handler.(preg_match('/_menu/', $menu_handler) ? '' : '_menu'), 'menu_handler', array_merge($dirstandard, $dirsmartphone));
251print ' &nbsp; <input type="submit" class="button" value="'.$langs->trans("Refresh").'">';
252
253print '<div class="floatright">';
254print $newcardbutton;
255print '</div>';
256
257print '</form>';
258
259print '<br>';
260
261print '<table class="noborder centpercent">';
262
263print '<tr class="liste_titre">';
264print '<td>'.$langs->trans("TreeMenuPersonalized").'</td>';
265print '<td class="right"><div id="iddivjstreecontrol"><a href="#">'.img_picto('', 'folder', 'class="paddingright"').$langs->trans("UndoExpandAll").'</a>';
266print ' | <a href="#">'.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ExpandAll").'</a></div></td>';
267print '</tr>';
268
269print '<tr>';
270print '<td colspan="2">';
271
272// ARBORESCENCE
273
274$rangLast = 0;
275$idLast = -1;
276if ($conf->use_javascript_ajax) {
277 /*-------------------- MAIN -----------------------
278 tableau des elements de l'arbre:
279 c'est un tableau a 2 dimensions.
280 Une ligne represente un element : data[$x]
281 chaque ligne est decomposee en 3 donnees:
282 - l'index de l'élément
283 - l'index de l'élément parent
284 - la chaine a afficher
285 ie: data[]= array (index, index parent, chaine )
286 */
287
288 //il faut d'abord declarer un element racine de l'arbre
289
290 $data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
291
292 //puis tous les elements enfants
293
294 $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";
295 $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
296 $sql .= " WHERE menu_handler = '".$db->escape($menu_handler_to_search)."'";
297 $sql .= " AND entity = ".$conf->entity;
298 //$sql.= " AND fk_menu >= 0";
299 $sql .= " ORDER BY m.position, m.rowid"; // Order is position then rowid (because we need a sort criteria when position is same)
300
301 $res = $db->query($sql);
302 if ($res) {
303 $num = $db->num_rows($res);
304
305 $i = 1;
306 while ($menu = $db->fetch_array($res)) {
307 if (!empty($menu['langs'])) {
308 $langs->load($menu['langs']);
309 }
310 $titre = $langs->trans($menu['titre']);
311
312 $entry = '<table class="nobordernopadding centpercent"><tr><td>';
313 $entry .= '<strong> &nbsp; <a href="edit.php?menu_handler='.$menu_handler_to_search.'&action=edit&token='.newToken().'&menuId='.$menu['rowid'].'">'.$titre.'</a></strong>';
314 $entry .= '</td><td class="right">';
315 $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> ';
316 $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> ';
317 $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> ';
318 $entry .= '&nbsp; ';
319 $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>';
320 $entry .= '</td></tr></table>';
321
322 $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> ';
323 $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> ';
324 $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> ';
325 $buttons .= '&nbsp; ';
326 $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>';
327
328 $data[] = array(
329 'rowid'=>$menu['rowid'],
330 'module'=>$menu['module'],
331 'fk_menu'=>$menu['fk_menu'],
332 'title'=>$titre,
333 'mainmenu'=>$menu['mainmenu'],
334 'leftmenu'=>$menu['leftmenu'],
335 'fk_mainmenu'=>$menu['fk_mainmenu'],
336 'fk_leftmenu'=>$menu['fk_leftmenu'],
337 'position'=>$menu['position'],
338 'entry'=>$entry,
339 'buttons'=>$buttons
340 );
341 $i++;
342 }
343 }
344
345 global $tree_recur_alreadyadded; // This var was def into tree_recur
346
347 //var_dump($data);
348
349 // Appelle de la fonction recursive (ammorce) avec recherche depuis la racine.
350 //tree_recur($data, $data[0], 0, 'iddivjstree', 0, 1); // use this to get info on name and foreign keys of menu entry
351 tree_recur($data, $data[0], 0, 'iddivjstree', 0, 0); // $data[0] is virtual record 'racine'
352
353
354 print '</td>';
355
356 print '</tr>';
357
358 print '</table>';
359
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 '<table class="noborder centpercent">';
372
373 print '<tr class="liste_titre">';
374 print '<td>'.$langs->trans("NotTopTreeMenuPersonalized").'</td>';
375 print '<td class="right"></td>';
376 print '</tr>';
377
378 print '<tr>';
379 print '<td colspan="2">';
380 foreach ($remainingdata as $datar) {
381 $father = array('rowid'=>$datar['rowid'], 'title'=>"???", 'mainmenu'=>$datar['fk_mainmenu'], 'leftmenu'=>$datar['fk_leftmenu'], 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
382 //print 'Start with rowid='.$datar['rowid'].' mainmenu='.$father ['mainmenu'].' leftmenu='.$father ['leftmenu'].'<br>'."\n";
383 tree_recur($data, $father, 0, 'iddivjstree'.$datar['rowid'], 1, 1);
384 }
385
386 print '</td>';
387
388 print '</tr>';
389
390 print '</table>';
391 }
392
393 print '</div>';
394} else {
395 $langs->load("errors");
396 setEventMessages($langs->trans("ErrorFeatureNeedJavascript"), null, 'errors');
397}
398
399print '<br>';
400
401// End of page
402llxFooter();
403$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
Class to generate html code for admin pages.
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_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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 editer/modifier fiche.
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.
tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree', $donoresetalreadyloaded=0, $showfk=0, $moreparam='')
Recursive function to output a tree.