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