|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <[email protected]> |
|
4
|
|
|
* Copyright (C) 2004-2012 Laurent Destailleur <[email protected]> |
|
5
|
|
|
* Copyright (C) 2005-2010 Regis Houssin <[email protected]> |
|
6
|
|
|
* Copyright (C) 2024 Rafael San José <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This program is free software; you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU General Public License as published by |
|
10
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
11
|
|
|
* (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU General Public License |
|
19
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace DoliModules\Admin\Controller; |
|
23
|
|
|
|
|
24
|
|
|
global $conf; |
|
25
|
|
|
global $db; |
|
26
|
|
|
global $user; |
|
27
|
|
|
global $hookmanager; |
|
28
|
|
|
global $user; |
|
29
|
|
|
global $menumanager; |
|
30
|
|
|
global $langs; |
|
31
|
|
|
global $mysoc; |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
// Load Dolibarr environment |
|
35
|
|
|
require BASE_PATH . '/main.inc.php'; |
|
36
|
|
|
|
|
37
|
|
|
use DoliCore\Base\DolibarrController; |
|
38
|
|
|
|
|
39
|
|
|
class AdminMenuController extends DolibarrController |
|
40
|
|
|
{ |
|
41
|
|
|
/** |
|
42
|
|
|
* \file htdocs/adherents/type.php |
|
43
|
|
|
* \ingroup member |
|
44
|
|
|
* \brief Member's type setup |
|
45
|
|
|
*/ |
|
46
|
|
|
public function index($executeActions = true): bool |
|
47
|
|
|
{ |
|
48
|
|
|
global $conf; |
|
49
|
|
|
global $db; |
|
50
|
|
|
global $user; |
|
51
|
|
|
global $hookmanager; |
|
52
|
|
|
global $user; |
|
53
|
|
|
global $menumanager; |
|
54
|
|
|
global $langs; |
|
55
|
|
|
global $mysoc; |
|
56
|
|
|
|
|
57
|
|
|
$action = GETPOST('action', 'aZ09'); |
|
58
|
|
|
$cancel = GETPOST('cancel', 'alpha'); |
|
59
|
|
|
|
|
60
|
|
|
// Load translation files required by the page |
|
61
|
|
|
$langs->loadLangs(["companies", "products", "admin", "users", "other"]); |
|
62
|
|
|
|
|
63
|
|
|
// Security check |
|
64
|
|
|
if (!$user->admin) { |
|
65
|
|
|
accessforbidden(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$dirstandard = []; |
|
69
|
|
|
$dirsmartphone = []; |
|
70
|
|
|
$dirmenus = array_merge(["/core/menus/"], (array) $conf->modules_parts['menus']); |
|
71
|
|
|
foreach ($dirmenus as $dirmenu) { |
|
72
|
|
|
$dirstandard[] = $dirmenu . 'standard'; |
|
73
|
|
|
$dirsmartphone[] = $dirmenu . 'smartphone'; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$error = 0; |
|
77
|
|
|
|
|
78
|
|
|
// This can be a big page. The execution time limit is increased. |
|
79
|
|
|
// This setting can only be changed when the 'safe_mode' is inactive. |
|
80
|
|
|
$err = error_reporting(); |
|
81
|
|
|
error_reporting(0); // Disable all errors |
|
82
|
|
|
//error_reporting(E_ALL); |
|
83
|
|
|
@set_time_limit(300); // Need more than 240 on Windows 7/64 |
|
|
|
|
|
|
84
|
|
|
error_reporting($err); |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
/* |
|
88
|
|
|
* Actions |
|
89
|
|
|
*/ |
|
90
|
|
|
|
|
91
|
|
|
if ($action == 'update' && !$cancel) { |
|
92
|
|
|
$_SESSION["mainmenu"] = "home"; // The menu manager may have changed |
|
93
|
|
|
|
|
94
|
|
|
dolibarr_set_const($db, "MAIN_MENU_STANDARD", GETPOST('MAIN_MENU_STANDARD', 'alpha'), 'chaine', 0, '', $conf->entity); |
|
95
|
|
|
dolibarr_set_const($db, "MAIN_MENU_SMARTPHONE", GETPOST('MAIN_MENU_SMARTPHONE', 'alpha'), 'chaine', 0, '', $conf->entity); |
|
96
|
|
|
|
|
97
|
|
|
dolibarr_set_const($db, "MAIN_MENUFRONT_STANDARD", GETPOST('MAIN_MENUFRONT_STANDARD', 'alpha'), 'chaine', 0, '', $conf->entity); |
|
98
|
|
|
dolibarr_set_const($db, "MAIN_MENUFRONT_SMARTPHONE", GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha'), 'chaine', 0, '', $conf->entity); |
|
99
|
|
|
|
|
100
|
|
|
// Define list of menu handlers to initialize |
|
101
|
|
|
$listofmenuhandler = []; |
|
102
|
|
|
$listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENU_STANDARD', 'alpha'))] = 1; |
|
103
|
|
|
$listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENUFRONT_STANDARD', 'alpha'))] = 1; |
|
104
|
|
|
if (GETPOST('MAIN_MENU_SMARTPHONE', 'alpha')) { |
|
105
|
|
|
$listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENU_SMARTPHONE', 'alpha'))] = 1; |
|
106
|
|
|
} |
|
107
|
|
|
if (GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha')) { |
|
108
|
|
|
$listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha'))] = 1; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
// Initialize menu handlers |
|
112
|
|
|
foreach ($listofmenuhandler as $key => $val) { |
|
113
|
|
|
// Load sql init_menu_handler.sql file |
|
114
|
|
|
$dirmenus = array_merge(["/core/menus/"], (array) $conf->modules_parts['menus']); |
|
115
|
|
|
foreach ($dirmenus as $dirmenu) { |
|
116
|
|
|
$file = 'init_menu_' . $key . '.sql'; |
|
117
|
|
|
$fullpath = dol_buildpath($dirmenu . $file); |
|
118
|
|
|
//print 'action='.$action.' Search menu into fullpath='.$fullpath.'<br>';exit; |
|
119
|
|
|
|
|
120
|
|
|
if (file_exists($fullpath)) { |
|
121
|
|
|
$db->begin(); |
|
122
|
|
|
|
|
123
|
|
|
$result = run_sql($fullpath, 1, '', 1, $key, 'none'); |
|
124
|
|
|
if ($result > 0) { |
|
125
|
|
|
$db->commit(); |
|
126
|
|
|
} else { |
|
127
|
|
|
$error++; |
|
128
|
|
|
setEventMessages($langs->trans("FailedToInitializeMenu") . ' ' . $key, null, 'errors'); |
|
129
|
|
|
$db->rollback(); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
if (!$error) { |
|
136
|
|
|
$db->close(); |
|
137
|
|
|
|
|
138
|
|
|
// We make a header redirect because we need to change menu NOW. |
|
139
|
|
|
header("Location: " . $_SERVER['PHP_SELF']); |
|
140
|
|
|
exit; |
|
|
|
|
|
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
|
|
145
|
|
|
/* |
|
146
|
|
|
* View |
|
147
|
|
|
*/ |
|
148
|
|
|
require_once realpath(BASE_PATH . '/../Dolibarr/Modules/Admin/Views/admin_menu.php'); |
|
149
|
|
|
|
|
150
|
|
|
$db->close(); |
|
151
|
|
|
|
|
152
|
|
|
return true; |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: