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 | use Dolibarr\Code\Core\Classes\Form; |
||
23 | use Dolibarr\Code\Core\Classes\FormAdmin; |
||
24 | use Dolibarr\Lib\ViewMain; |
||
25 | |||
26 | /** |
||
27 | * \file htdocs/admin/menus.php |
||
28 | * \ingroup core |
||
29 | * \brief Page to setup menu manager to use |
||
30 | */ |
||
31 | |||
32 | // Load Dolibarr environment |
||
33 | require constant('DOL_DOCUMENT_ROOT') . '/main.inc.php'; |
||
34 | require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/admin.lib.php'; |
||
35 | |||
36 | $action = GETPOST('action', 'aZ09'); |
||
37 | $cancel = GETPOST('cancel', 'alpha'); |
||
38 | |||
39 | // Load translation files required by the page |
||
40 | $langs->loadLangs(array("companies", "products", "admin", "users", "other")); |
||
41 | |||
42 | // Security check |
||
43 | if (!$user->admin) { |
||
44 | accessforbidden(); |
||
45 | } |
||
46 | |||
47 | $dirstandard = array(); |
||
48 | $dirsmartphone = array(); |
||
49 | $dirmenus = array_merge(array("/core/menus/"), (array)$conf->modules_parts['menus']); |
||
50 | foreach ($dirmenus as $dirmenu) { |
||
51 | $dirstandard[] = $dirmenu . 'standard'; |
||
52 | $dirsmartphone[] = $dirmenu . 'smartphone'; |
||
53 | } |
||
54 | |||
55 | $error = 0; |
||
56 | |||
57 | // This can be a big page. The execution time limit is increased. |
||
58 | // This setting can only be changed when the 'safe_mode' is inactive. |
||
59 | $err = error_reporting(); |
||
60 | error_reporting(0); // Disable all errors |
||
61 | //error_reporting(E_ALL); |
||
62 | @set_time_limit(300); // Need more than 240 on Windows 7/64 |
||
63 | error_reporting($err); |
||
64 | |||
65 | |||
66 | /* |
||
67 | * Actions |
||
68 | */ |
||
69 | |||
70 | if ($action == 'update' && !$cancel) { |
||
71 | $_SESSION["mainmenu"] = "home"; // The menu manager may have changed |
||
72 | |||
73 | dolibarr_set_const($db, "MAIN_MENU_STANDARD", GETPOST('MAIN_MENU_STANDARD', 'alpha'), 'chaine', 0, '', $conf->entity); |
||
74 | dolibarr_set_const($db, "MAIN_MENU_SMARTPHONE", GETPOST('MAIN_MENU_SMARTPHONE', 'alpha'), 'chaine', 0, '', $conf->entity); |
||
75 | |||
76 | dolibarr_set_const($db, "MAIN_MENUFRONT_STANDARD", GETPOST('MAIN_MENUFRONT_STANDARD', 'alpha'), 'chaine', 0, '', $conf->entity); |
||
77 | dolibarr_set_const($db, "MAIN_MENUFRONT_SMARTPHONE", GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha'), 'chaine', 0, '', $conf->entity); |
||
78 | |||
79 | // Define list of menu handlers to initialize |
||
80 | $listofmenuhandler = array(); |
||
81 | $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENU_STANDARD', 'alpha'))] = 1; |
||
82 | $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENUFRONT_STANDARD', 'alpha'))] = 1; |
||
83 | if (GETPOST('MAIN_MENU_SMARTPHONE', 'alpha')) { |
||
84 | $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENU_SMARTPHONE', 'alpha'))] = 1; |
||
85 | } |
||
86 | if (GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha')) { |
||
87 | $listofmenuhandler[preg_replace('/(_backoffice|_frontoffice|_menu)?\.php/i', '', GETPOST('MAIN_MENUFRONT_SMARTPHONE', 'alpha'))] = 1; |
||
88 | } |
||
89 | |||
90 | // Initialize menu handlers |
||
91 | foreach ($listofmenuhandler as $key => $val) { |
||
92 | // Load sql init_menu_handler.sql file |
||
93 | $dirmenus = array_merge(array("/core/menus/"), (array)$conf->modules_parts['menus']); |
||
94 | foreach ($dirmenus as $dirmenu) { |
||
95 | $file = 'init_menu_' . $key . '.sql'; |
||
96 | $fullpath = dol_buildpath($dirmenu . $file); |
||
97 | //print 'action='.$action.' Search menu into fullpath='.$fullpath.'<br>';exit; |
||
98 | |||
99 | if (file_exists($fullpath)) { |
||
100 | $db->begin(); |
||
101 | |||
102 | $result = run_sql($fullpath, 1, '', 1, $key, 'none'); |
||
103 | if ($result > 0) { |
||
104 | $db->commit(); |
||
105 | } else { |
||
106 | $error++; |
||
107 | setEventMessages($langs->trans("FailedToInitializeMenu") . ' ' . $key, null, 'errors'); |
||
108 | $db->rollback(); |
||
109 | } |
||
110 | } |
||
111 | } |
||
112 | } |
||
113 | |||
114 | if (!$error) { |
||
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 | ViewMain::llxHeader('', $langs->trans("Setup"), $wikihelp, '', 0, 0, '', '', '', 'mod-admin page-menus'); |
||
133 | |||
134 | print load_fiche_titre($langs->trans("Menus"), '', 'title_setup'); |
||
135 | |||
136 | |||
137 | $h = 0; |
||
138 | |||
139 | $head = array(); |
||
140 | $head[$h][0] = constant('BASE_URL') . "/admin/menus.php"; |
||
141 | $head[$h][1] = $langs->trans("MenuHandlers"); |
||
142 | $head[$h][2] = 'handler'; |
||
143 | $h++; |
||
144 | |||
145 | $head[$h][0] = constant('BASE_URL') . "/admin/menus/index.php"; |
||
146 | $head[$h][1] = $langs->trans("MenuAdmin"); |
||
147 | $head[$h][2] = 'editor'; |
||
148 | $h++; |
||
149 | |||
150 | print '<form method="post" action="' . $_SERVER["PHP_SELF"] . '">'; |
||
151 | print '<input type="hidden" name="token" value="' . newToken() . '">'; |
||
152 | print '<input type="hidden" name="action" value="update">'; |
||
153 | |||
154 | print dol_get_fiche_head($head, 'handler', '', -1); |
||
155 | |||
156 | print '<span class="opacitymedium">' . $langs->trans("MenusDesc") . "</span><br>\n"; |
||
157 | print "<br>\n"; |
||
158 | |||
159 | |||
160 | clearstatcache(); |
||
161 | |||
162 | // Gestionnaires de menu |
||
163 | print '<table class="noborder centpercent">'; |
||
164 | print '<tr class="liste_titre"><td width="35%">' . $langs->trans("Menu") . '</td>'; |
||
165 | print '<td>'; |
||
166 | print $form->textwithpicto($langs->trans("InternalUsers"), $langs->trans("InternalExternalDesc")); |
||
167 | print '</td>'; |
||
168 | print '<td>'; |
||
169 | print $form->textwithpicto($langs->trans("ExternalUsers"), $langs->trans("InternalExternalDesc")); |
||
170 | print '</td>'; |
||
171 | print '</tr>'; |
||
172 | |||
173 | // Menu top |
||
174 | print '<tr class="oddeven"><td>' . $langs->trans("DefaultMenuManager") . '</td>'; |
||
175 | print '<td>'; |
||
176 | $formadmin->select_menu(getDolGlobalString('MAIN_MENU_STANDARD_FORCED', getDolGlobalString('MAIN_MENU_STANDARD')), 'MAIN_MENU_STANDARD', $dirstandard, !getDolGlobalString('MAIN_MENU_STANDARD_FORCED') ? '' : ' disabled'); |
||
177 | print '</td>'; |
||
178 | print '<td>'; |
||
179 | $formadmin->select_menu(getDolGlobalString('MAIN_MENUFRONT_STANDARD_FORCED', getDolGlobalString('MAIN_MENUFRONT_STANDARD')), 'MAIN_MENUFRONT_STANDARD', $dirstandard, !getDolGlobalString('MAIN_MENUFRONT_STANDARD_FORCED') ? '' : ' disabled'); |
||
180 | print '</td>'; |
||
181 | print '</tr>'; |
||
182 | |||
183 | // Menu smartphone |
||
184 | print '<tr class="oddeven"><td>' . $langs->trans("DefaultMenuSmartphoneManager") . '</td>'; |
||
185 | print '<td>'; |
||
186 | $formadmin->select_menu(getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED', getDolGlobalString('MAIN_MENU_SMARTPHONE')), 'MAIN_MENU_SMARTPHONE', array_merge($dirstandard, $dirsmartphone), !getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') ? '' : ' disabled'); |
||
187 | |||
188 | if ( |
||
189 | getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') && preg_match('/smartphone/', $conf->global->MAIN_MENU_SMARTPHONE_FORCED) |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
190 | || (!getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') && getDolGlobalString('MAIN_MENU_SMARTPHONE') && preg_match('/smartphone/', $conf->global->MAIN_MENU_SMARTPHONE)) |
||
191 | ) { |
||
192 | print ' ' . img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme")); |
||
193 | } |
||
194 | |||
195 | print '</td>'; |
||
196 | print '<td>'; |
||
197 | $formadmin->select_menu(getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE_FORCED', getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE')), 'MAIN_MENUFRONT_SMARTPHONE', array_merge($dirstandard, $dirsmartphone), !getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE_FORCED') ? '' : ' disabled'); |
||
198 | |||
199 | if ( |
||
200 | getDolGlobalString('MAIN_MENU_SMARTPHONE_FORCED') && preg_match('/smartphone/', $conf->global->MAIN_MENUFRONT_SMARTPHONE_FORCED) |
||
0 ignored issues
–
show
|
|||
201 | || (!getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE_FORCED') && getDolGlobalString('MAIN_MENU_SMARTPHONE') && preg_match('/smartphone/', $conf->global->MAIN_MENUFRONT_SMARTPHONE)) |
||
202 | ) { |
||
203 | print ' ' . img_warning($langs->transnoentitiesnoconv("ThisForceAlsoTheme")); |
||
204 | } |
||
205 | |||
206 | print '</td>'; |
||
207 | print '</tr>'; |
||
208 | |||
209 | print '</table>'; |
||
210 | |||
211 | print dol_get_fiche_end(); |
||
212 | |||
213 | print '<div class="center">'; |
||
214 | print '<input class="button button-save" type="submit" name="save" value="' . $langs->trans("Save") . '">'; |
||
215 | print '</div>'; |
||
216 | |||
217 | print '</form>'; |
||
218 | |||
219 | // End of page |
||
220 | ViewMain::llxFooter(); |
||
221 | $db->close(); |
||
222 |