dolibarr  16.0.5
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 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
29 
30 $action = GETPOST('action', 'aZ09');
31 $cancel = GETPOST('cancel', 'alpha');
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array("companies", "products", "admin", "users", "other"));
35 
36 // Security check
37 if (!$user->admin) {
39 }
40 
41 $dirstandard = array();
42 $dirsmartphone = array();
43 $dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
44 foreach ($dirmenus as $dirmenu) {
45  $dirstandard[] = $dirmenu.'standard';
46  $dirsmartphone[] = $dirmenu.'smartphone';
47 }
48 
49 $error = 0;
50 
51 // Cette page peut etre longue. On augmente le delai autorise.
52 // Ne fonctionne que si on est pas en safe_mode.
53 $err = error_reporting();
54 error_reporting(0); // Disable all errors
55 //error_reporting(E_ALL);
56 @set_time_limit(300); // Need more than 240 on Windows 7/64
57 error_reporting($err);
58 
59 
60 /*
61  * Actions
62  */
63 
64 if ($action == 'update' && !$cancel) {
65  $_SESSION["mainmenu"] = "home"; // Le gestionnaire de menu a pu changer
66 
67  dolibarr_set_const($db, "MAIN_MENU_STANDARD", GETPOST('MAIN_MENU_STANDARD', 'alpha'), 'chaine', 0, '', $conf->entity);
68  dolibarr_set_const($db, "MAIN_MENU_SMARTPHONE", GETPOST('MAIN_MENU_SMARTPHONE', 'alpha'), 'chaine', 0, '', $conf->entity);
69 
70  dolibarr_set_const($db, "MAIN_MENUFRONT_STANDARD", GETPOST('MAIN_MENUFRONT_STANDARD', 'alpha'), 'chaine', 0, '', $conf->entity);
71  dolibarr_set_const($db, "MAIN_MENUFRONT_SMARTPHONE", GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha'), 'chaine', 0, '', $conf->entity);
72 
73  // Define list of menu handlers to initialize
74  $listofmenuhandler = array();
75  $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENU_STANDARD', 'alpha'))] = 1;
76  $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENUFRONT_STANDARD', 'alpha'))] = 1;
77  if (GETPOST('MAIN_MENU_SMARTPHONE', 'alpha')) {
78  $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENU_SMARTPHONE', 'alpha'))] = 1;
79  }
80  if (GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha')) {
81  $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha'))] = 1;
82  }
83 
84  // Initialize menu handlers
85  foreach ($listofmenuhandler as $key => $val) {
86  // Load sql init_menu_handler.sql file
87  $dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
88  foreach ($dirmenus as $dirmenu) {
89  $file = 'init_menu_'.$key.'.sql';
90  $fullpath = dol_buildpath($dirmenu.$file);
91  //print 'action='.$action.' Search menu into fullpath='.$fullpath.'<br>';exit;
92 
93  if (file_exists($fullpath)) {
94  $db->begin();
95 
96  $result = run_sql($fullpath, 1, '', 1, $key, 'none');
97  if ($result > 0) {
98  $db->commit();
99  } else {
100  $error++;
101  setEventMessages($langs->trans("FailedToInitializeMenu").' '.$key, null, 'errors');
102  $db->rollback();
103  }
104  }
105  }
106  }
107 
108  if (!$error) {
109  $db->close();
110 
111  // We make a header redirect because we need to change menu NOW.
112  header("Location: ".$_SERVER["PHP_SELF"]);
113  exit;
114  }
115 }
116 
117 
118 /*
119  * View
120  */
121 
122 $form = new Form($db);
123 $formadmin = new FormAdmin($db);
124 
125 $wikihelp = 'EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
126 llxHeader('', $langs->trans("Setup"), $wikihelp);
127 
128 print load_fiche_titre($langs->trans("Menus"), '', 'title_setup');
129 
130 
131 $h = 0;
132 
133 $head[$h][0] = DOL_URL_ROOT."/admin/menus.php";
134 $head[$h][1] = $langs->trans("MenuHandlers");
135 $head[$h][2] = 'handler';
136 $h++;
137 
138 $head[$h][0] = DOL_URL_ROOT."/admin/menus/index.php";
139 $head[$h][1] = $langs->trans("MenuAdmin");
140 $head[$h][2] = 'editor';
141 $h++;
142 
143 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
144 print '<input type="hidden" name="token" value="'.newToken().'">';
145 print '<input type="hidden" name="action" value="update">';
146 
147 print dol_get_fiche_head($head, 'handler', '', -1);
148 
149 print '<span class="opacitymedium">'.$langs->trans("MenusDesc")."</span><br>\n";
150 print "<br>\n";
151 
152 
153 clearstatcache();
154 
155 // Gestionnaires de menu
156 print '<table class="noborder centpercent">';
157 print '<tr class="liste_titre"><td width="35%">'.$langs->trans("Menu").'</td>';
158 print '<td>';
159 print $form->textwithpicto($langs->trans("InternalUsers"), $langs->trans("InternalExternalDesc"));
160 print '</td>';
161 print '<td>';
162 print $form->textwithpicto($langs->trans("ExternalUsers"), $langs->trans("InternalExternalDesc"));
163 print '</td>';
164 print '</tr>';
165 
166 // Menu top
167 print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuManager").'</td>';
168 print '<td>';
169 $formadmin->select_menu(empty($conf->global->MAIN_MENU_STANDARD_FORCED) ? $conf->global->MAIN_MENU_STANDARD : $conf->global->MAIN_MENU_STANDARD_FORCED, 'MAIN_MENU_STANDARD', $dirstandard, empty($conf->global->MAIN_MENU_STANDARD_FORCED) ? '' : ' disabled');
170 print '</td>';
171 print '<td>';
172 $formadmin->select_menu(empty($conf->global->MAIN_MENUFRONT_STANDARD_FORCED) ? $conf->global->MAIN_MENUFRONT_STANDARD : $conf->global->MAIN_MENUFRONT_STANDARD_FORCED, 'MAIN_MENUFRONT_STANDARD', $dirstandard, empty($conf->global->MAIN_MENUFRONT_STANDARD_FORCED) ? '' : ' disabled');
173 print '</td>';
174 print '</tr>';
175 
176 // Menu smartphone
177 print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuSmartphoneManager").'</td>';
178 print '<td>';
179 $formadmin->select_menu(empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) ? $conf->global->MAIN_MENU_SMARTPHONE : $conf->global->MAIN_MENU_SMARTPHONE_FORCED, 'MAIN_MENU_SMARTPHONE', array_merge($dirstandard, $dirsmartphone), empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) ? '' : ' disabled');
180 
181 if (!empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && preg_match('/smartphone/', $conf->global->MAIN_MENU_SMARTPHONE_FORCED)
182  || (empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && !empty($conf->global->MAIN_MENU_SMARTPHONE) && preg_match('/smartphone/', $conf->global->MAIN_MENU_SMARTPHONE))) {
183  print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
184 }
185 
186 print '</td>';
187 print '<td>';
188 $formadmin->select_menu(empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED) ? $conf->global->MAIN_MENUFRONT_SMARTPHONE : $conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED, 'MAIN_MENUFRONT_SMARTPHONE', array_merge($dirstandard, $dirsmartphone), empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED) ? '' : ' disabled');
189 
190 if (!empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && preg_match('/smartphone/', $conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)
191  || (empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED) && !empty($conf->global->MAIN_MENU_SMARTPHONE) && preg_match('/smartphone/', $conf->global->MAIN_MENUFRONT_SMARTPHONE))) {
192  print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
193 }
194 
195 print '</td>';
196 print '</tr>';
197 
198 print '</table>';
199 
200 print dol_get_fiche_end();
201 
202 print '<div class="center">';
203 print '<input class="button button-save" type="submit" name="save" value="'.$langs->trans("Save").'">';
204 print '</div>';
205 
206 print '</form>';
207 
208 // End of page
209 llxFooter();
210 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
FormAdmin
Class to generate html code for admin pages.
Definition: html.formadmin.class.php:30
$wikihelp
if($actionsave) if(!isset($conf->global->MAIN_AGENDA_EXPORT_PAST_DELAY)) $wikihelp
View.
Definition: agenda_xcal.php:72
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
dolibarr_set_const
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).
Definition: admin.lib.php:627
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
run_sql
run_sql($sqlfile, $silent=1, $entity='', $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0, $colspan=0, $onlysqltoimportwebsite=0)
Launch a sql file.
Definition: admin.lib.php:167
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59