dolibarr 20.0.0
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 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
30
31$action = GETPOST('action', 'aZ09');
32$cancel = GETPOST('cancel', 'alpha');
33
34// Load translation files required by the page
35$langs->loadLangs(array("companies", "products", "admin", "users", "other"));
36
37// Security check
38if (!$user->admin) {
40}
41
42$dirstandard = array();
43$dirsmartphone = array();
44$dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
45foreach ($dirmenus as $dirmenu) {
46 $dirstandard[] = $dirmenu.'standard';
47 $dirsmartphone[] = $dirmenu.'smartphone';
48}
49
50$error = 0;
51
52// This can be a big page. The execution time limit is increased.
53// This setting can only be changed when the 'safe_mode' is inactive.
54$err = error_reporting();
55error_reporting(0); // Disable all errors
56//error_reporting(E_ALL);
57@set_time_limit(300); // Need more than 240 on Windows 7/64
58error_reporting($err);
59
60
61/*
62 * Actions
63 */
64
65if ($action == 'update' && !$cancel) {
66 $_SESSION["mainmenu"] = "home"; // The menu manager may have changed
67
68 dolibarr_set_const($db, "MAIN_MENU_STANDARD", GETPOST('MAIN_MENU_STANDARD', 'alpha'), 'chaine', 0, '', $conf->entity);
69 dolibarr_set_const($db, "MAIN_MENU_SMARTPHONE", GETPOST('MAIN_MENU_SMARTPHONE', 'alpha'), 'chaine', 0, '', $conf->entity);
70
71 dolibarr_set_const($db, "MAIN_MENUFRONT_STANDARD", GETPOST('MAIN_MENUFRONT_STANDARD', 'alpha'), 'chaine', 0, '', $conf->entity);
72 dolibarr_set_const($db, "MAIN_MENUFRONT_SMARTPHONE", GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha'), 'chaine', 0, '', $conf->entity);
73
74 // Define list of menu handlers to initialize
75 $listofmenuhandler = array();
76 $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENU_STANDARD', 'alpha'))] = 1;
77 $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENUFRONT_STANDARD', 'alpha'))] = 1;
78 if (GETPOST('MAIN_MENU_SMARTPHONE', 'alpha')) {
79 $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENU_SMARTPHONE', 'alpha'))] = 1;
80 }
81 if (GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha')) {
82 $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha'))] = 1;
83 }
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, '', 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 $db->close();
111
112 // We make a header redirect because we need to change menu NOW.
113 header("Location: ".$_SERVER["PHP_SELF"]);
114 exit;
115 }
116}
117
118
119/*
120 * View
121 */
122
123$form = new Form($db);
124$formadmin = new FormAdmin($db);
125
126$wikihelp = 'EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
127llxHeader('', $langs->trans("Setup"), $wikihelp, '', 0, 0, '', '', '', 'mod-admin page-menus');
128
129print load_fiche_titre($langs->trans("Menus"), '', 'title_setup');
130
131
132$h = 0;
133
134$head = array();
135$head[$h][0] = DOL_URL_ROOT."/admin/menus.php";
136$head[$h][1] = $langs->trans("MenuHandlers");
137$head[$h][2] = 'handler';
138$h++;
139
140$head[$h][0] = DOL_URL_ROOT."/admin/menus/index.php";
141$head[$h][1] = $langs->trans("MenuAdmin");
142$head[$h][2] = 'editor';
143$h++;
144
145print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
146print '<input type="hidden" name="token" value="'.newToken().'">';
147print '<input type="hidden" name="action" value="update">';
148
149print dol_get_fiche_head($head, 'handler', '', -1);
150
151print '<span class="opacitymedium">'.$langs->trans("MenusDesc")."</span><br>\n";
152print "<br>\n";
153
154
155clearstatcache();
156
157// Gestionnaires de menu
158print '<table class="noborder centpercent">';
159print '<tr class="liste_titre"><td width="35%">'.$langs->trans("Menu").'</td>';
160print '<td>';
161print $form->textwithpicto($langs->trans("InternalUsers"), $langs->trans("InternalExternalDesc"));
162print '</td>';
163print '<td>';
164print $form->textwithpicto($langs->trans("ExternalUsers"), $langs->trans("InternalExternalDesc"));
165print '</td>';
166print '</tr>';
167
168// Menu top
169print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuManager").'</td>';
170print '<td>';
171$formadmin->select_menu(getDolGlobalString('MAIN_MENU_STANDARD_FORCED', getDolGlobalString('MAIN_MENU_STANDARD')), 'MAIN_MENU_STANDARD', $dirstandard, !getDolGlobalString('MAIN_MENU_STANDARD_FORCED') ? '' : ' disabled');
172print '</td>';
173print '<td>';
174$formadmin->select_menu(getDolGlobalString('MAIN_MENUFRONT_STANDARD_FORCED', getDolGlobalString('MAIN_MENUFRONT_STANDARD')), 'MAIN_MENUFRONT_STANDARD', $dirstandard, !getDolGlobalString('MAIN_MENUFRONT_STANDARD_FORCED') ? '' : ' disabled');
175print '</td>';
176print '</tr>';
177
178// Menu smartphone
179print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuSmartphoneManager").'</td>';
180print '<td>';
181$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');
182
183if (getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') && preg_match('/smartphone/', $conf->global->MAIN_MENU_SMARTPHONE_FORCED)
184 || (!getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') && getDolGlobalString('MAIN_MENU_SMARTPHONE') && preg_match('/smartphone/', $conf->global->MAIN_MENU_SMARTPHONE))) {
185 print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
186}
187
188print '</td>';
189print '<td>';
190$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');
191
192if (getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') && preg_match('/smartphone/', $conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)
193 || (!getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE_FORCED') && getDolGlobalString('MAIN_MENU_SMARTPHONE') && preg_match('/smartphone/', $conf->global->MAIN_MENUFRONT_SMARTPHONE))) {
194 print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
195}
196
197print '</td>';
198print '</tr>';
199
200print '</table>';
201
202print dol_get_fiche_end();
203
204print '<div class="center">';
205print '<input class="button button-save" type="submit" name="save" value="'.$langs->trans("Save").'">';
206print '</div>';
207
208print '</form>';
209
210// End of page
211llxFooter();
212$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()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return 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.