Passed
Push — master ( 0f9140...c4489d )
by Alxarafe
22:27
created

dolibarr/htdocs/admin/menus.php (2 issues)

Severity
1
<?php
2
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <[email protected]>
3
 * Copyright (C) 2004-2012 Laurent Destailleur  <[email protected]>
4
 * Copyright (C) 2005-2010 Regis Houssin        <[email protected]>
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
20
/**
21
 *      \file       htdocs/admin/menus.php
22
 *      \ingroup    core
23
 *      \brief      Page to setup menu manager to use
24
 */
25
26
27
// Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
28
defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
29
require DOL_BASE_PATH . '/main.inc.php';
30
31
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
32
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
33
34
$action=GETPOST('action','aZ09');
35
$cancel=GETPOST('cancel','alpha');
36
37
// Load translation files required by the page
38
$langs->loadLangs(array("companies","products","admin","users","other"));
39
40
// Security check
41
if (! $user->admin) accessforbidden();
42
43
$dirstandard = array();
44
$dirsmartphone = array();
45
$dirmenus=array_merge(array("/core/menus/"),(array) $conf->modules_parts['menus']);
46
foreach($dirmenus as $dirmenu)
47
{
48
    $dirstandard[]=$dirmenu.'standard';
49
    $dirsmartphone[]=$dirmenu.'smartphone';
50
}
51
52
$error=0;
53
54
// Cette page peut etre longue. On augmente le delai autorise.
55
// Ne fonctionne que si on est pas en safe_mode.
56
$err=error_reporting();
57
error_reporting(0);     // Disable all errors
58
//error_reporting(E_ALL);
59
@set_time_limit(300);   // Need more than 240 on Windows 7/64
60
error_reporting($err);
61
62
63
/*
64
 * Actions
65
 */
66
67
if ($action == 'update' && ! $cancel)
68
{
69
	$_SESSION["mainmenu"]="home";   // Le gestionnaire de menu a pu changer
70
71
	dolibarr_set_const($db, "MAIN_MENU_STANDARD", GETPOST('MAIN_MENU_STANDARD','alpha'),'chaine',0,'',$conf->entity);
72
	dolibarr_set_const($db, "MAIN_MENU_SMARTPHONE", GETPOST('MAIN_MENU_SMARTPHONE','alpha'),'chaine',0,'',$conf->entity);
73
74
	dolibarr_set_const($db, "MAIN_MENUFRONT_STANDARD", GETPOST('MAIN_MENUFRONT_STANDARD','alpha'),'chaine',0,'',$conf->entity);
75
	dolibarr_set_const($db, "MAIN_MENUFRONT_SMARTPHONE", GETPOST('MAIN_MENUFRONT_SMARTPHONE','alpha'),'chaine',0,'',$conf->entity);
76
77
	// Define list of menu handlers to initialize
78
	$listofmenuhandler=array();
79
	$listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i','',GETPOST('MAIN_MENU_STANDARD','alpha'))]=1;
80
	$listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i','',GETPOST('MAIN_MENUFRONT_STANDARD','alpha'))]=1;
81
	if (GETPOST('MAIN_MENU_SMARTPHONE','alpha'))      $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i','',GETPOST('MAIN_MENU_SMARTPHONE','alpha'))]=1;
82
	if (GETPOST('MAIN_MENUFRONT_SMARTPHONE','alpha')) $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i','',GETPOST('MAIN_MENUFRONT_SMARTPHONE','alpha'))]=1;
83
84
	// Initialize menu handlers
85
	foreach ($listofmenuhandler as $key => $val)
86
	{
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
		{
91
			$file='init_menu_'.$key.'.sql';
92
		    $fullpath=dol_buildpath($dirmenu.$file);
93
		    //print 'action='.$action.' Search menu into fullpath='.$fullpath.'<br>';exit;
94
95
			if (file_exists($fullpath))
96
			{
97
				$db->begin();
98
99
				$result=run_sql($fullpath,1,'',1,$key,'none');
100
				if ($result > 0)
101
				{
102
					$db->commit();
103
				}
104
				else
105
				{
106
					$error++;
107
					setEventMessages($langs->trans("FailedToInitializeMenu").' '.$key, null, 'errors');
108
					$db->rollback();
109
				}
110
			}
111
		}
112
	}
113
114
	if (! $error)
115
	{
116
		$db->close();
117
118
		// We make a header redirect because we need to change menu NOW.
119
		header("Location: ".$_SERVER["PHP_SELF"]);
120
		exit;
121
	}
122
}
123
124
125
/*
126
 * View
127
 */
128
129
$form=new Form($db);
130
$formadmin=new FormAdmin($db);
131
132
$wikihelp='EN:First_setup|FR:Premiers_paramétrages|ES:Primeras_configuraciones';
133
llxHeader('',$langs->trans("Setup"),$wikihelp);
134
135
print load_fiche_titre($langs->trans("Menus"),'','title_setup');
136
137
138
$h = 0;
139
140
$head[$h][0] = DOL_URL_ROOT."/admin/menus.php";
141
$head[$h][1] = $langs->trans("MenuHandlers");
142
$head[$h][2] = 'handler';
143
$h++;
144
145
$head[$h][0] = DOL_URL_ROOT."/admin/menus/index.php";
146
$head[$h][1] = $langs->trans("MenuAdmin");
147
$head[$h][2] = 'editor';
148
$h++;
149
150
$head[$h][0] = DOL_URL_ROOT."/admin/menus/other.php";
151
$head[$h][1] = $langs->trans("Miscellaneous");
152
$head[$h][2] = 'misc';
153
$h++;
154
155
156
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
157
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
158
print '<input type="hidden" name="action" value="update">';
159
160
dol_fiche_head($head, 'handler', $langs->trans("Menus"), -1);
161
162
print $langs->trans("MenusDesc")."<br>\n";
163
print "<br>\n";
164
165
166
if ($action == 'edit')
167
{
168
	clearstatcache();
169
170
	// Gestionnaires de menu
171
	print '<table class="noborder" width="100%">';
172
	print '<tr class="liste_titre"><td width="35%">'.$langs->trans("Menu").'</td>';
173
	print '<td>';
174
	print $form->textwithpicto($langs->trans("InternalUsers"),$langs->trans("InternalExternalDesc"));
175
	print '</td>';
176
	print '<td>';
177
	print $form->textwithpicto($langs->trans("ExternalUsers"),$langs->trans("InternalExternalDesc"));
178
	print '</td>';
179
	print '</tr>';
180
181
	// Menu top
182
	print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuManager").'</td>';
183
	print '<td>';
184
	$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');
185
	print '</td>';
186
	print '<td>';
187
	$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');
188
	print '</td>';
189
	print '</tr>';
190
191
	// Menu smartphone
192
	print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuSmartphoneManager").'</td>';
193
	print '<td>';
194
	$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');
195
	print '</td>';
196
	print '<td>';
197
	$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');
198
	print '</td>';
199
	print '</tr>';
200
201
	print '</table>';
202
}
203
else
204
{
205
	// Gestionnaires de menu
206
	print '<table class="noborder" width="100%">';
207
	print '<tr class="liste_titre"><td width="35%">'.$langs->trans("Menu").'</td>';
208
	print '<td>';
209
	print $form->textwithpicto($langs->trans("InternalUsers"),$langs->trans("InternalExternalDesc"));
210
	print '</td>';
211
	print '<td>';
212
	print $form->textwithpicto($langs->trans("ExternalUsers"),$langs->trans("InternalExternalDesc"));
213
	print '</td>';
214
	print '</tr>';
215
216
217
	print '<tr class="oddeven"><td>'.$langs->trans("DefaultMenuManager").'</td>';
218
	print '<td>';
219
	$filelib=preg_replace('/.php$/i','',(empty($conf->global->MAIN_MENU_STANDARD_FORCED)?$conf->global->MAIN_MENU_STANDARD:$conf->global->MAIN_MENU_STANDARD_FORCED));
220
	print $filelib;
221
	print '</td>';
222
	print '<td>';
223
	$filelib=preg_replace('/.php$/i','',(empty($conf->global->MAIN_MENUFRONT_STANDARD_FORCED)?$conf->global->MAIN_MENUFRONT_STANDARD:$conf->global->MAIN_MENUFRONT_STANDARD_FORCED));
224
	print $filelib;
225
	print '</td>';
226
	print '</tr>';
227
228
229
	print '<tr class="oddeven">';
230
	print '<td>'.$langs->trans("DefaultMenuSmartphoneManager").'</td>';
231
	print '<td>';
232
	$filelib=preg_replace('/.php$/i','',(empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED)?$conf->global->MAIN_MENU_SMARTPHONE:$conf->global->MAIN_MENU_SMARTPHONE_FORCED));
233
	print $filelib;
234
	if (! empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && preg_match('/smartphone/', $conf->global->MAIN_MENU_SMARTPHONE_FORCED)
0 ignored issues
show
Consider adding parentheses for clarity. Current Interpretation: (! empty($conf->global->...->MAIN_MENU_SMARTPHONE), Probably Intended Meaning: ! empty($conf->global->M...>MAIN_MENU_SMARTPHONE))
Loading history...
235
	|| (empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && ! empty($conf->global->MAIN_MENU_SMARTPHONE) && preg_match('/smartphone/',$conf->global->MAIN_MENU_SMARTPHONE)))
236
	{
237
		print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
238
	}
239
	print '</td>';
240
	print '<td>';
241
	$filelib=preg_replace('/.php$/i','',(empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)?$conf->global->MAIN_MENUFRONT_SMARTPHONE:$conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED));
242
	print $filelib;
243
	if (! empty($conf->global->MAIN_MENU_SMARTPHONE_FORCED) && preg_match('/smartphone/',$conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED)
0 ignored issues
show
Consider adding parentheses for clarity. Current Interpretation: (! empty($conf->global->...N_MENUFRONT_SMARTPHONE), Probably Intended Meaning: ! empty($conf->global->M..._MENUFRONT_SMARTPHONE))
Loading history...
244
	|| (empty($conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED) && ! empty($conf->global->MAIN_MENU_SMARTPHONE) && preg_match('/smartphone/',$conf->global->MAIN_MENUFRONT_SMARTPHONE)))
245
	{
246
		print ' '.img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme"));
247
	}
248
	print '</td>';
249
	print '</tr>';
250
251
	print '</table>';
252
}
253
254
dol_fiche_end();
255
256
257
if ($action == 'edit')
258
{
259
	print '<div class="center">';
260
	print '<input class="button" type="submit" name="save" value="'.$langs->trans("Save").'">';
261
	print ' &nbsp; &nbsp; &nbsp; ';
262
	print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'">';
263
	print '</div>';
264
}
265
266
print '</form>';
267
268
269
if ($action != 'edit')
270
{
271
	print '<div class="tabsAction">';
272
	print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit">'.$langs->trans("Modify").'</a>';
273
	print '</div>';
274
}
275
276
// End of page
277
llxFooter();
278
$db->close();
279