dolibarr 21.0.3
menus.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
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/lib/admin.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
32
33$action = GETPOST('action', 'aZ09');
34$cancel = GETPOST('cancel', 'alpha');
35
44// Load translation files required by the page
45$langs->loadLangs(array("companies", "products", "admin", "users", "other"));
46
47// Security check
48if (!$user->admin) {
50}
51
52$dirstandard = array();
53$dirsmartphone = array();
54$dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
55foreach ($dirmenus as $dirmenu) {
56 $dirstandard[] = $dirmenu.'standard';
57 $dirsmartphone[] = $dirmenu.'smartphone';
58}
59
60$error = 0;
61
62// This can be a big page. The execution time limit is increased.
63// This setting can only be changed when the 'safe_mode' is inactive.
64$err = error_reporting();
65error_reporting(0); // Disable all errors
66//error_reporting(E_ALL);
67@set_time_limit(300); // Need more than 240 on Windows 7/64
68error_reporting($err);
69
70
71/*
72 * Actions
73 */
74
75if ($action == 'update' && !$cancel) {
76 $_SESSION["mainmenu"] = "home"; // The menu manager may have changed
77
78 dolibarr_set_const($db, "MAIN_MENU_STANDARD", GETPOST('MAIN_MENU_STANDARD', 'alpha'), 'chaine', 0, '', $conf->entity);
79 dolibarr_set_const($db, "MAIN_MENU_SMARTPHONE", GETPOST('MAIN_MENU_SMARTPHONE', 'alpha'), 'chaine', 0, '', $conf->entity);
80
81 dolibarr_set_const($db, "MAIN_MENUFRONT_STANDARD", GETPOST('MAIN_MENUFRONT_STANDARD', 'alpha'), 'chaine', 0, '', $conf->entity);
82 dolibarr_set_const($db, "MAIN_MENUFRONT_SMARTPHONE", GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha'), 'chaine', 0, '', $conf->entity);
83
84 // Define list of menu handlers to initialize
85 $listofmenuhandler = array();
86 $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENU_STANDARD', 'alpha'))] = 1;
87 $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENUFRONT_STANDARD', 'alpha'))] = 1;
88 if (GETPOST('MAIN_MENU_SMARTPHONE', 'alpha')) {
89 $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENU_SMARTPHONE', 'alpha'))] = 1;
90 }
91 if (GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha')) {
92 $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha'))] = 1;
93 }
94
95 // Initialize menu handlers
96 foreach ($listofmenuhandler as $key => $val) {
97 // Load sql init_menu_handler.sql file
98 $dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
99 foreach ($dirmenus as $dirmenu) {
100 $file = 'init_menu_'.$key.'.sql';
101 $fullpath = dol_buildpath($dirmenu.$file);
102 //print 'action='.$action.' Search menu into fullpath='.$fullpath.'<br>';exit;
103
104 if (file_exists($fullpath)) {
105 $db->begin();
106
107 $result = run_sql($fullpath, 1, 0, 1, $key, 'none');
108 if ($result > 0) {
109 $db->commit();
110 } else {
111 $error++;
112 setEventMessages($langs->trans("FailedToInitializeMenu").' '.$key, null, 'errors');
113 $db->rollback();
114 }
115 }
116 }
117 }
118
119 if (!$error) {
120 setEventMessage($langs->trans("RecordSaved"));
121 $db->close();
122
123 // We make a header redirect because we need to change menu NOW.
124 header("Location: ".$_SERVER["PHP_SELF"]);
125 exit;
126 }
127}
128
129
130/*
131 * View
132 */
133
134$form = new Form($db);
135$formadmin = new FormAdmin($db);
136
137$wikihelp = 'EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
138llxHeader('', $langs->trans("Setup"), $wikihelp, '', 0, 0, '', '', '', 'mod-admin page-menus');
139
140print load_fiche_titre($langs->trans("Menus"), '', 'title_setup');
141
142
143$h = 0;
144
145$head = array();
146$head[$h][0] = DOL_URL_ROOT."/admin/menus.php";
147$head[$h][1] = $langs->trans("MenuHandlers");
148$head[$h][2] = 'handler';
149$h++;
150
151$head[$h][0] = DOL_URL_ROOT."/admin/menus/index.php";
152$head[$h][1] = $langs->trans("MenuAdmin");
153$head[$h][2] = 'editor';
154$h++;
155
156print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
157print '<input type="hidden" name="token" value="'.newToken().'">';
158print '<input type="hidden" name="action" value="update">';
159
160print dol_get_fiche_head($head, 'handler', '', -1);
161
162print '<div class="opacitymedium justify hideonsmartphone">'.$langs->trans("MenusDesc")."</div>\n";
163print '<br class="hideonsmartphone">';
164print "<br>\n";
165
166
167clearstatcache();
168
169// Menu manager choice
170
171print "\n";
172print '<div class="div-table-responsive-no-min">';
173
174print '<table class="noborder centpercent">';
175print '<tr class="liste_titre"><td>'.$langs->trans("Menu").'</td>';
176print '<td>';
177print $form->textwithpicto($langs->trans("InternalUsers"), $langs->trans("InternalExternalDesc"));
178print '</td>';
179print '<td>';
180print $form->textwithpicto($langs->trans("ExternalUsers"), $langs->trans("InternalExternalDesc"));
181print '</td>';
182print '</tr>';
183
184// Menu top
185print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuManager").'</td>';
186print '<td>';
187$formadmin->select_menu(getDolGlobalString('MAIN_MENU_STANDARD_FORCED', getDolGlobalString('MAIN_MENU_STANDARD')), 'MAIN_MENU_STANDARD', $dirstandard, !getDolGlobalString('MAIN_MENU_STANDARD_FORCED') ? '' : ' disabled');
188print '</td>';
189print '<td>';
190$formadmin->select_menu(getDolGlobalString('MAIN_MENUFRONT_STANDARD_FORCED', getDolGlobalString('MAIN_MENUFRONT_STANDARD')), 'MAIN_MENUFRONT_STANDARD', $dirstandard, !getDolGlobalString('MAIN_MENUFRONT_STANDARD_FORCED') ? '' : ' disabled');
191print '</td>';
192print '</tr>';
193
194// Menu smartphone
195print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuSmartphoneManager").'</td>';
196print '<td>';
197$formadmin->select_menu(getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED', getDolGlobalString('MAIN_MENU_SMARTPHONE')), 'MAIN_MENU_SMARTPHONE', array_merge($dirstandard, $dirsmartphone), !getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') ? '' : ' disabled');
198
199if (getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') && preg_match('/smartphone/', $conf->global->MAIN_MENU_SMARTPHONE_FORCED)
200 || (!getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') && getDolGlobalString('MAIN_MENU_SMARTPHONE') && preg_match('/smartphone/', getDolGlobalString('MAIN_MENU_SMARTPHONE')))) {
201 print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
202}
203
204print '</td>';
205print '<td>';
206$formadmin->select_menu(getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE_FORCED', getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE')), 'MAIN_MENUFRONT_SMARTPHONE', array_merge($dirstandard, $dirsmartphone), !getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE_FORCED') ? '' : ' disabled');
207
208if (getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') && preg_match('/smartphone/', $conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)
209 || (!getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE_FORCED') && getDolGlobalString('MAIN_MENU_SMARTPHONE') && preg_match('/smartphone/', getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE')))) {
210 print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
211}
212
213print '</td>';
214print '</tr>';
215
216print '</table>';
217print '</div>';
218
219print dol_get_fiche_end();
220
221print '<div class="center">';
222print '<input class="button button-save" type="submit" name="save" value="'.$langs->trans("Save").'">';
223print '</div>';
224
225print '</form>';
226
227// End of page
228llxFooter();
229$db->close();
run_sql($sqlfile, $silent=1, $entity=0, $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0, $colspan=0, $onlysqltoimportwebsite=0, $database='')
Launch a sql file.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
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.
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.
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.