dolibarr 25.0.0-alpha
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-2025 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$dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
54foreach ($dirmenus as $dirmenu) {
55 $dirstandard[] = $dirmenu.'standard';
56}
57
58$error = 0;
59
60// This can be a big page. The execution time limit is increased.
61// This setting can only be changed when the 'safe_mode' is inactive.
62$err = error_reporting();
63error_reporting(0); // Disable all errors
64//error_reporting(E_ALL);
65@set_time_limit(300); // Need more than 240 on Windows 7/64
66error_reporting($err);
67
68
69/*
70 * Actions
71 */
72
73if ($action == 'update' && !$cancel) {
74 $_SESSION["mainmenu"] = "home"; // The menu manager may have changed
75
76 dolibarr_set_const($db, "MAIN_MENU_STANDARD", GETPOST('MAIN_MENU_STANDARD', 'alpha'), 'chaine', 0, '', $conf->entity);
77
78 dolibarr_set_const($db, "MAIN_MENUFRONT_STANDARD", GETPOST('MAIN_MENUFRONT_STANDARD', 'alpha'), 'chaine', 0, '', $conf->entity);
79
80 // Define list of menu handlers to initialize
81 $listofmenuhandler = array();
82 $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENU_STANDARD', 'alpha'))] = 1;
83 $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENUFRONT_STANDARD', 'alpha'))] = 1;
84
85 // Initialize menu handlers
86 foreach ($listofmenuhandler as $key => $val) {
87 // Load sql init_menu_handler.sql file
88 $dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
89 foreach ($dirmenus as $dirmenu) {
90 $file = 'init_menu_'.$key.'.sql';
91 $fullpath = dol_buildpath($dirmenu.$file);
92 //print 'action='.$action.' Search menu into fullpath='.$fullpath.'<br>';exit;
93
94 if (file_exists($fullpath)) {
95 $db->begin();
96
97 $result = run_sql($fullpath, 1, 0, 1, $key, 'none');
98 if ($result > 0) {
99 $db->commit();
100 } else {
101 $error++;
102 setEventMessages($langs->trans("FailedToInitializeMenu").' '.$key, null, 'errors');
103 $db->rollback();
104 }
105 }
106 }
107 }
108
109 if (!$error) {
110 setEventMessage($langs->trans("RecordSaved"));
111 $db->close();
112
113 // We make a header redirect because we need to change menu NOW.
114 header("Location: ".dolBuildUrl($_SERVER["PHP_SELF"]));
115 exit;
116 }
117}
118
119
120/*
121 * View
122 */
123
124$form = new Form($db);
125$formadmin = new FormAdmin($db);
126
127$wikihelp = 'EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
128llxHeader('', $langs->trans("Setup"), $wikihelp, '', 0, 0, '', '', '', 'mod-admin page-menus');
129
130print load_fiche_titre($langs->trans("Menus"), '', 'title_setup');
131
132
133$h = 0;
134
135$head = array();
136$head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/admin/menus.php");
137$head[$h][1] = $langs->trans("MenuHandlers");
138$head[$h][2] = 'handler';
139$h++;
140
141$head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/admin/menus/index.php");
142$head[$h][1] = $langs->trans("MenuAdmin");
143$head[$h][2] = 'editor';
144$h++;
145
146print '<form method="post" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'" spellcheck="false">';
147print '<input type="hidden" name="token" value="'.newToken().'">';
148print '<input type="hidden" name="action" value="update">';
149
150print dol_get_fiche_head($head, 'handler', '', -1);
151
152print '<div class="info justify hideonsmartphone">'.$langs->trans("MenusDesc")."</div>\n";
153print "<br>\n";
154
155
156clearstatcache();
157
158// Menu manager choice
159
160print "\n";
161print '<div class="div-table-responsive-no-min">';
162
163print '<table class="noborder centpercent">';
164print '<tr class="liste_titre"><td>'.$langs->trans("Menu").'</td>';
165print '<td>';
166print $form->textwithpicto($langs->trans("InternalUsers"), $langs->trans("InternalExternalDesc"));
167print '</td>';
168print '<td>';
169print $form->textwithpicto($langs->trans("ExternalUsers"), $langs->trans("InternalExternalDesc"));
170print '</td>';
171print '</tr>';
172
173// Menu manager
174print '<tr class="oddeven"><td>'.$langs->trans("MenuManager").'</td>';
175print '<td>';
176$formadmin->select_menu(getDolGlobalString('MAIN_MENU_STANDARD_FORCED', getDolGlobalString('MAIN_MENU_STANDARD')), 'MAIN_MENU_STANDARD', $dirstandard, !getDolGlobalString('MAIN_MENU_STANDARD_FORCED') ? '' : ' disabled');
177print '</td>';
178print '<td>';
179$formadmin->select_menu(getDolGlobalString('MAIN_MENUFRONT_STANDARD_FORCED', getDolGlobalString('MAIN_MENUFRONT_STANDARD')), 'MAIN_MENUFRONT_STANDARD', $dirstandard, !getDolGlobalString('MAIN_MENUFRONT_STANDARD_FORCED') ? '' : ' disabled');
180print '</td>';
181print '</tr>';
182
183print '</table>';
184print '</div>';
185
186print '<div class="center">';
187print '<input class="button button-save" type="submit" name="save" value="'.$langs->trans("Save").'">';
188print '</div>';
189
190print dol_get_fiche_end();
191
192print '</form>';
193
194// End of page
195llxFooter();
196$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: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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to generate html code for admin pages.
Class to manage generation of HTML components Only common components must be here.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=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.
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.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.