dolibarr 21.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 *
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/lib/admin.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
31
32$action = GETPOST('action', 'aZ09');
33$cancel = GETPOST('cancel', 'alpha');
34
35// Load translation files required by the page
36$langs->loadLangs(array("companies", "products", "admin", "users", "other"));
37
38// Security check
39if (!$user->admin) {
41}
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$error = 0;
52
53// This can be a big page. The execution time limit is increased.
54// This setting can only be changed when the 'safe_mode' is inactive.
55$err = error_reporting();
56error_reporting(0); // Disable all errors
57//error_reporting(E_ALL);
58@set_time_limit(300); // Need more than 240 on Windows 7/64
59error_reporting($err);
60
61
62/*
63 * Actions
64 */
65
66if ($action == 'update' && !$cancel) {
67 $_SESSION["mainmenu"] = "home"; // The menu manager may have changed
68
69 dolibarr_set_const($db, "MAIN_MENU_STANDARD", GETPOST('MAIN_MENU_STANDARD', 'alpha'), 'chaine', 0, '', $conf->entity);
70 dolibarr_set_const($db, "MAIN_MENU_SMARTPHONE", GETPOST('MAIN_MENU_SMARTPHONE', 'alpha'), 'chaine', 0, '', $conf->entity);
71
72 dolibarr_set_const($db, "MAIN_MENUFRONT_STANDARD", GETPOST('MAIN_MENUFRONT_STANDARD', 'alpha'), 'chaine', 0, '', $conf->entity);
73 dolibarr_set_const($db, "MAIN_MENUFRONT_SMARTPHONE", GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha'), 'chaine', 0, '', $conf->entity);
74
75 // Define list of menu handlers to initialize
76 $listofmenuhandler = array();
77 $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENU_STANDARD', 'alpha'))] = 1;
78 $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENUFRONT_STANDARD', 'alpha'))] = 1;
79 if (GETPOST('MAIN_MENU_SMARTPHONE', 'alpha')) {
80 $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENU_SMARTPHONE', 'alpha'))] = 1;
81 }
82 if (GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha')) {
83 $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha'))] = 1;
84 }
85
86 // Initialize menu handlers
87 foreach ($listofmenuhandler as $key => $val) {
88 // Load sql init_menu_handler.sql file
89 $dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
90 foreach ($dirmenus as $dirmenu) {
91 $file = 'init_menu_'.$key.'.sql';
92 $fullpath = dol_buildpath($dirmenu.$file);
93 //print 'action='.$action.' Search menu into fullpath='.$fullpath.'<br>';exit;
94
95 if (file_exists($fullpath)) {
96 $db->begin();
97
98 $result = run_sql($fullpath, 1, 0, 1, $key, 'none');
99 if ($result > 0) {
100 $db->commit();
101 } else {
102 $error++;
103 setEventMessages($langs->trans("FailedToInitializeMenu").' '.$key, null, 'errors');
104 $db->rollback();
105 }
106 }
107 }
108 }
109
110 if (!$error) {
111 $db->close();
112
113 // We make a header redirect because we need to change menu NOW.
114 header("Location: ".$_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] = 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] = 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="'.$_SERVER["PHP_SELF"].'">';
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="opacitymedium justify hideonsmartphone">'.$langs->trans("MenusDesc")."</div>\n";
153print '<br class="hideonsmartphone">';
154print "<br>\n";
155
156
157clearstatcache();
158
159// Menu manager choice
160
161print "\n";
162print '<div class="div-table-responsive-no-min">';
163
164print '<table class="noborder centpercent">';
165print '<tr class="liste_titre"><td>'.$langs->trans("Menu").'</td>';
166print '<td>';
167print $form->textwithpicto($langs->trans("InternalUsers"), $langs->trans("InternalExternalDesc"));
168print '</td>';
169print '<td>';
170print $form->textwithpicto($langs->trans("ExternalUsers"), $langs->trans("InternalExternalDesc"));
171print '</td>';
172print '</tr>';
173
174// Menu top
175print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuManager").'</td>';
176print '<td>';
177$formadmin->select_menu(getDolGlobalString('MAIN_MENU_STANDARD_FORCED', getDolGlobalString('MAIN_MENU_STANDARD')), 'MAIN_MENU_STANDARD', $dirstandard, !getDolGlobalString('MAIN_MENU_STANDARD_FORCED') ? '' : ' disabled');
178print '</td>';
179print '<td>';
180$formadmin->select_menu(getDolGlobalString('MAIN_MENUFRONT_STANDARD_FORCED', getDolGlobalString('MAIN_MENUFRONT_STANDARD')), 'MAIN_MENUFRONT_STANDARD', $dirstandard, !getDolGlobalString('MAIN_MENUFRONT_STANDARD_FORCED') ? '' : ' disabled');
181print '</td>';
182print '</tr>';
183
184// Menu smartphone
185print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuSmartphoneManager").'</td>';
186print '<td>';
187$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');
188
189if (getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') && preg_match('/smartphone/', $conf->global->MAIN_MENU_SMARTPHONE_FORCED)
190 || (!getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') && getDolGlobalString('MAIN_MENU_SMARTPHONE') && preg_match('/smartphone/', getDolGlobalString('MAIN_MENU_SMARTPHONE')))) {
191 print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
192}
193
194print '</td>';
195print '<td>';
196$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');
197
198if (getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') && preg_match('/smartphone/', $conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)
199 || (!getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE_FORCED') && getDolGlobalString('MAIN_MENU_SMARTPHONE') && preg_match('/smartphone/', getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE')))) {
200 print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
201}
202
203print '</td>';
204print '</tr>';
205
206print '</table>';
207print '</div>';
208
209print dol_get_fiche_end();
210
211print '<div class="center">';
212print '<input class="button button-save" type="submit" name="save" value="'.$langs->trans("Save").'">';
213print '</div>';
214
215print '</form>';
216
217// End of page
218llxFooter();
219$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).
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:70
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.
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.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.