dolibarr  9.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 <http://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) accessforbidden();
38 
39 $dirstandard = array();
40 $dirsmartphone = array();
41 $dirmenus=array_merge(array("/core/menus/"),(array) $conf->modules_parts['menus']);
42 foreach($dirmenus as $dirmenu)
43 {
44  $dirstandard[]=$dirmenu.'standard';
45  $dirsmartphone[]=$dirmenu.'smartphone';
46 }
47 
48 $error=0;
49 
50 // Cette page peut etre longue. On augmente le delai autorise.
51 // Ne fonctionne que si on est pas en safe_mode.
52 $err=error_reporting();
53 error_reporting(0); // Disable all errors
54 //error_reporting(E_ALL);
55 @set_time_limit(300); // Need more than 240 on Windows 7/64
56 error_reporting($err);
57 
58 
59 /*
60  * Actions
61  */
62 
63 if ($action == 'update' && ! $cancel)
64 {
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')) $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i','',GETPOST('MAIN_MENU_SMARTPHONE','alpha'))]=1;
78  if (GETPOST('MAIN_MENUFRONT_SMARTPHONE','alpha')) $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i','',GETPOST('MAIN_MENUFRONT_SMARTPHONE','alpha'))]=1;
79 
80  // Initialize menu handlers
81  foreach ($listofmenuhandler as $key => $val)
82  {
83  // Load sql init_menu_handler.sql file
84  $dirmenus=array_merge(array("/core/menus/"),(array) $conf->modules_parts['menus']);
85  foreach($dirmenus as $dirmenu)
86  {
87  $file='init_menu_'.$key.'.sql';
88  $fullpath=dol_buildpath($dirmenu.$file);
89  //print 'action='.$action.' Search menu into fullpath='.$fullpath.'<br>';exit;
90 
91  if (file_exists($fullpath))
92  {
93  $db->begin();
94 
95  $result=run_sql($fullpath,1,'',1,$key,'none');
96  if ($result > 0)
97  {
98  $db->commit();
99  }
100  else
101  {
102  $error++;
103  setEventMessages($langs->trans("FailedToInitializeMenu").' '.$key, null, 'errors');
104  $db->rollback();
105  }
106  }
107  }
108  }
109 
110  if (! $error)
111  {
112  $db->close();
113 
114  // We make a header redirect because we need to change menu NOW.
115  header("Location: ".$_SERVER["PHP_SELF"]);
116  exit;
117  }
118 }
119 
120 
121 /*
122  * View
123  */
124 
125 $form=new Form($db);
126 $formadmin=new FormAdmin($db);
127 
128 $wikihelp='EN:First_setup|FR:Premiers_param├ętrages|ES:Primeras_configuraciones';
129 llxHeader('',$langs->trans("Setup"),$wikihelp);
130 
131 print load_fiche_titre($langs->trans("Menus"),'','title_setup');
132 
133 
134 $h = 0;
135 
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 
146 $head[$h][0] = DOL_URL_ROOT."/admin/menus/other.php";
147 $head[$h][1] = $langs->trans("Miscellaneous");
148 $head[$h][2] = 'misc';
149 $h++;
150 
151 
152 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
153 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
154 print '<input type="hidden" name="action" value="update">';
155 
156 dol_fiche_head($head, 'handler', $langs->trans("Menus"), -1);
157 
158 print $langs->trans("MenusDesc")."<br>\n";
159 print "<br>\n";
160 
161 
162 if ($action == 'edit')
163 {
164  clearstatcache();
165 
166  // Gestionnaires de menu
167  print '<table class="noborder" width="100%">';
168  print '<tr class="liste_titre"><td width="35%">'.$langs->trans("Menu").'</td>';
169  print '<td>';
170  print $form->textwithpicto($langs->trans("InternalUsers"),$langs->trans("InternalExternalDesc"));
171  print '</td>';
172  print '<td>';
173  print $form->textwithpicto($langs->trans("ExternalUsers"),$langs->trans("InternalExternalDesc"));
174  print '</td>';
175  print '</tr>';
176 
177  // Menu top
178  print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuManager").'</td>';
179  print '<td>';
180  $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');
181  print '</td>';
182  print '<td>';
183  $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');
184  print '</td>';
185  print '</tr>';
186 
187  // Menu smartphone
188  print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuSmartphoneManager").'</td>';
189  print '<td>';
190  $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');
191  print '</td>';
192  print '<td>';
193  $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');
194  print '</td>';
195  print '</tr>';
196 
197  print '</table>';
198 }
199 else
200 {
201  // Gestionnaires de menu
202  print '<table class="noborder" width="100%">';
203  print '<tr class="liste_titre"><td width="35%">'.$langs->trans("Menu").'</td>';
204  print '<td>';
205  print $form->textwithpicto($langs->trans("InternalUsers"),$langs->trans("InternalExternalDesc"));
206  print '</td>';
207  print '<td>';
208  print $form->textwithpicto($langs->trans("ExternalUsers"),$langs->trans("InternalExternalDesc"));
209  print '</td>';
210  print '</tr>';
211 
212 
213  print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuManager").'</td>';
214  print '<td>';
215  $filelib=preg_replace('/.php$/i','',(empty($conf->global->MAIN_MENU_STANDARD_FORCED)?$conf->global->MAIN_MENU_STANDARD:$conf->global->MAIN_MENU_STANDARD_FORCED));
216  print $filelib;
217  print '</td>';
218  print '<td>';
219  $filelib=preg_replace('/.php$/i','',(empty($conf->global->MAIN_MENUFRONT_STANDARD_FORCED)?$conf->global->MAIN_MENUFRONT_STANDARD:$conf->global->MAIN_MENUFRONT_STANDARD_FORCED));
220  print $filelib;
221  print '</td>';
222  print '</tr>';
223 
224 
225  print '<tr class="oddeven">';
226  print '<td>'.$langs->trans("DefaultMenuSmartphoneManager").'</td>';
227  print '<td>';
228  $filelib=preg_replace('/.php$/i','',(empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED)?$conf->global->MAIN_MENU_SMARTPHONE:$conf->global->MAIN_MENU_SMARTPHONE_FORCED));
229  print $filelib;
230  if (! empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && preg_match('/smartphone/', $conf->global->MAIN_MENU_SMARTPHONE_FORCED)
231  || (empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && ! empty($conf->global->MAIN_MENU_SMARTPHONE) && preg_match('/smartphone/',$conf->global->MAIN_MENU_SMARTPHONE)))
232  {
233  print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
234  }
235  print '</td>';
236  print '<td>';
237  $filelib=preg_replace('/.php$/i','',(empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)?$conf->global->MAIN_MENUFRONT_SMARTPHONE:$conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED));
238  print $filelib;
239  if (! empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && preg_match('/smartphone/',$conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)
240  || (empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED) && ! empty($conf->global->MAIN_MENU_SMARTPHONE) && preg_match('/smartphone/',$conf->global->MAIN_MENUFRONT_SMARTPHONE)))
241  {
242  print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
243  }
244  print '</td>';
245  print '</tr>';
246 
247  print '</table>';
248 }
249 
250 dol_fiche_end();
251 
252 
253 if ($action == 'edit')
254 {
255  print '<div class="center">';
256  print '<input class="button" type="submit" name="save" value="'.$langs->trans("Save").'">';
257  print ' &nbsp; &nbsp; &nbsp; ';
258  print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
259  print '</div>';
260 }
261 
262 print '</form>';
263 
264 
265 if ($action != 'edit')
266 {
267  print '<div class="tabsAction">';
268  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
269  print '</div>';
270 }
271 
272 // End of page
273 llxFooter();
274 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
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:510
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Class to generate html code for admin pages.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
run_sql($sqlfile, $silent=1, $entity='', $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0)
Launch a sql file.
Definition: admin.lib.php:130
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $wikihelp
View.
Definition: agenda.php:120