dolibarr 21.0.0-beta
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 $db->close();
121
122 // We make a header redirect because we need to change menu NOW.
123 header("Location: ".$_SERVER["PHP_SELF"]);
124 exit;
125 }
126}
127
128
129/*
130 * View
131 */
132
133$form = new Form($db);
134$formadmin = new FormAdmin($db);
135
136$wikihelp = 'EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
137llxHeader('', $langs->trans("Setup"), $wikihelp, '', 0, 0, '', '', '', 'mod-admin page-menus');
138
139print load_fiche_titre($langs->trans("Menus"), '', 'title_setup');
140
141
142$h = 0;
143
144$head = array();
145$head[$h][0] = DOL_URL_ROOT."/admin/menus.php";
146$head[$h][1] = $langs->trans("MenuHandlers");
147$head[$h][2] = 'handler';
148$h++;
149
150$head[$h][0] = DOL_URL_ROOT."/admin/menus/index.php";
151$head[$h][1] = $langs->trans("MenuAdmin");
152$head[$h][2] = 'editor';
153$h++;
154
155print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
156print '<input type="hidden" name="token" value="'.newToken().'">';
157print '<input type="hidden" name="action" value="update">';
158
159print dol_get_fiche_head($head, 'handler', '', -1);
160
161print '<div class="opacitymedium justify hideonsmartphone">'.$langs->trans("MenusDesc")."</div>\n";
162print '<br class="hideonsmartphone">';
163print "<br>\n";
164
165
166clearstatcache();
167
168// Menu manager choice
169
170print "\n";
171print '<div class="div-table-responsive-no-min">';
172
173print '<table class="noborder centpercent">';
174print '<tr class="liste_titre"><td>'.$langs->trans("Menu").'</td>';
175print '<td>';
176print $form->textwithpicto($langs->trans("InternalUsers"), $langs->trans("InternalExternalDesc"));
177print '</td>';
178print '<td>';
179print $form->textwithpicto($langs->trans("ExternalUsers"), $langs->trans("InternalExternalDesc"));
180print '</td>';
181print '</tr>';
182
183// Menu top
184print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuManager").'</td>';
185print '<td>';
186$formadmin->select_menu(getDolGlobalString('MAIN_MENU_STANDARD_FORCED', getDolGlobalString('MAIN_MENU_STANDARD')), 'MAIN_MENU_STANDARD', $dirstandard, !getDolGlobalString('MAIN_MENU_STANDARD_FORCED') ? '' : ' disabled');
187print '</td>';
188print '<td>';
189$formadmin->select_menu(getDolGlobalString('MAIN_MENUFRONT_STANDARD_FORCED', getDolGlobalString('MAIN_MENUFRONT_STANDARD')), 'MAIN_MENUFRONT_STANDARD', $dirstandard, !getDolGlobalString('MAIN_MENUFRONT_STANDARD_FORCED') ? '' : ' disabled');
190print '</td>';
191print '</tr>';
192
193// Menu smartphone
194print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuSmartphoneManager").'</td>';
195print '<td>';
196$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');
197
198if (getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') && preg_match('/smartphone/', $conf->global->MAIN_MENU_SMARTPHONE_FORCED)
199 || (!getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') && getDolGlobalString('MAIN_MENU_SMARTPHONE') && preg_match('/smartphone/', getDolGlobalString('MAIN_MENU_SMARTPHONE')))) {
200 print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
201}
202
203print '</td>';
204print '<td>';
205$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');
206
207if (getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') && preg_match('/smartphone/', $conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)
208 || (!getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE_FORCED') && getDolGlobalString('MAIN_MENU_SMARTPHONE') && preg_match('/smartphone/', getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE')))) {
209 print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
210}
211
212print '</td>';
213print '</tr>';
214
215print '</table>';
216print '</div>';
217
218print dol_get_fiche_end();
219
220print '<div class="center">';
221print '<input class="button button-save" type="submit" name="save" value="'.$langs->trans("Save").'">';
222print '</div>';
223
224print '</form>';
225
226// End of page
227llxFooter();
228$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:71
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.
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.