dolibarr 21.0.0-alpha
auguria_menu.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
3 * Copyright (C) 2009 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2008-2013 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
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
34{
38 public $db;
39
43 public $type_user;
44
48 public $atarget = "";
49
53 public $name = "auguria";
54
58 public $menu;
59
63 public $menu_array;
67 public $menu_array_after;
68
72 public $tabMenu;
73
74
81 public function __construct($db, $type_user)
82 {
83 $this->type_user = $type_user;
84 $this->db = $db;
85 }
86
87
95 public function loadMenu($forcemainmenu = '', $forceleftmenu = '')
96 {
97 global $conf, $user, $langs;
98
99 // We save into session the main menu selected
100 if (GETPOSTISSET("mainmenu")) {
101 $_SESSION["mainmenu"] = GETPOST("mainmenu", 'aZ09');
102 }
103 if (GETPOSTISSET("idmenu")) {
104 $_SESSION["idmenu"] = GETPOSTINT("idmenu");
105 }
106
107 // Read now mainmenu and leftmenu that define which menu to show
108 if (GETPOSTISSET("mainmenu")) {
109 // On sauve en session le menu principal choisi
110 $mainmenu = GETPOST("mainmenu", 'aZ09');
111 $_SESSION["mainmenu"] = $mainmenu;
112 $_SESSION["leftmenuopened"] = "";
113 } else {
114 // Look for the menu in the session if not set by the link
115 $mainmenu = isset($_SESSION["mainmenu"]) ? $_SESSION["mainmenu"] : '';
116 }
117 if (!empty($forcemainmenu)) {
118 $mainmenu = $forcemainmenu;
119 }
120
121 if (GETPOSTISSET("leftmenu")) {
122 // On sauve en session le menu principal choisi
123 $leftmenu = GETPOST("leftmenu", 'aZ09');
124 $_SESSION["leftmenu"] = $leftmenu;
125
126 if ($_SESSION["leftmenuopened"] == $leftmenu) { // To collapse
127 //$leftmenu="";
128 $_SESSION["leftmenuopened"] = "";
129 } else {
130 $_SESSION["leftmenuopened"] = $leftmenu;
131 }
132 } else {
133 // Look for the menu in the session if not set by the link
134 $leftmenu = isset($_SESSION["leftmenu"]) ? $_SESSION["leftmenu"] : '';
135 }
136 if (!empty($forceleftmenu)) {
137 $leftmenu = $forceleftmenu;
138 }
139
140 require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
141 $tabMenu = array();
142 $menuArbo = new Menubase($this->db, 'auguria');
143 $menuArbo->menuLoad($mainmenu, $leftmenu, $this->type_user, 'auguria', $tabMenu);
144 $this->tabMenu = $tabMenu;
145 //var_dump($tabMenu);
146
147 //if ($forcemainmenu == 'all') { var_dump($this->tabMenu); exit; }
148 }
149
150
159 public function showmenu($mode, $moredata = null)
160 {
161 global $conf, $langs, $user;
162
163 require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/auguria.lib.php';
164
165 if ($this->type_user == 1) {
166 $conf->global->MAIN_SEARCHFORM_SOCIETE_DISABLED = 1;
167 $conf->global->MAIN_SEARCHFORM_CONTACT_DISABLED = 1;
168 }
169
170 require_once DOL_DOCUMENT_ROOT.'/core/class/menu.class.php';
171 $this->menu = new Menu();
172
173 if (!getDolGlobalString('MAIN_MENU_INVERT')) {
174 if ($mode == 'top') {
175 print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
176 }
177 if ($mode == 'left') {
178 print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0, '', '', $moredata);
179 }
180 } else {
181 $conf->global->MAIN_SHOW_LOGO = 0;
182 if ($mode == 'top') {
183 print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0);
184 }
185 if ($mode == 'left') {
186 print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
187 }
188 }
189
190 if ($mode == 'topnb') {
191 print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode);
192 return $this->menu->getNbOfVisibleMenuEntries();
193 }
194
195 if ($mode == 'jmobile') { // Used to get menu in xml ul/li
196 print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode);
197
198 // $this->menu->liste is top menu
199 //var_dump($this->menu->liste);exit;
200 $lastlevel = array();
201 $showmenu = true; // Is current menu shown - define here to keep static code checker happy
202 print '<!-- Generate menu list from menu handler '.$this->name.' -->'."\n";
203 foreach ($this->menu->liste as $key => $val) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
204 print '<ul class="ulmenu" data-inset="true">';
205 print '<li class="lilevel0">';
206 if ($val['enabled'] == 1) {
207 $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
208 $substitarray['__USERID__'] = $user->id; // For backward compatibility
209 $val['url'] = make_substitutions($val['url'], $substitarray);
210
211 $relurl = dol_buildpath($val['url'], 1);
212 $canonurl = preg_replace('/\?.*$/', '', $val['url']);
213
214 print '<a class="alilevel0" href="#">';
215
216 // Add font-awesome
217 if ($val['level'] == 0 && !empty($val['prefix'])) {
218 print str_replace('<span class="', '<span class="paddingright pictofixedwidth ', $val['prefix']);
219 }
220
221 print $val['titre'];
222 print '</a>'."\n";
223
224 // Search submenu for this mainmenu entry
225 $tmpmainmenu = $val['mainmenu'];
226 $tmpleftmenu = 'all';
227 $submenu = new Menu();
228 print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $submenu, 1, $tmpmainmenu, $tmpleftmenu);
229 if (!empty($submenu->liste[0]['url'])) {
230 $nexturl = dol_buildpath($submenu->liste[0]['url'], 1);
231 } else {
232 $nexturl = '';
233 }
234
235 $canonrelurl = preg_replace('/\?.*$/', '', $relurl);
236 $canonnexturl = preg_replace('/\?.*$/', '', $nexturl);
237 //var_dump($canonrelurl);
238 //var_dump($canonnexturl);
239 print '<ul>'."\n";
240 if (($canonrelurl != $canonnexturl && !in_array($val['mainmenu'], array('tools')))
241 || (strpos($canonrelurl, '/product/index.php') !== false || strpos($canonrelurl, '/compta/bank/list.php') !== false)) {
242 // We add sub entry
243 print str_pad('', 1).'<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic
244 print '<a href="'.$relurl.'">';
245
246 if ($val['level'] == 0) {
247 print '<span class="fas fa-home fa-fw paddingright pictofixedwidth" aria-hidden="true"></span>';
248 }
249
250 if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") { // No translation
251 if (in_array($val['mainmenu'], array('cashdesk', 'externalsite', 'website', 'collab', 'takepos'))) {
252 print $langs->trans("Access");
253 } else {
254 print $langs->trans("Dashboard");
255 }
256 } else {
257 print $langs->trans(ucfirst($val['mainmenu'])."Dashboard");
258 }
259 print '</a>';
260 print '</li>'."\n";
261 }
262
263 if ($val['level'] == 0) {
264 if ($val['enabled']) {
265 $lastlevel[0] = 'enabled';
266 } elseif ($showmenu) { // Not enabled but visible (so greyed)
267 $lastlevel[0] = 'greyed';
268 } else {
269 $lastlevel[0] = 'hidden';
270 }
271 }
272
273 $lastlevel2 = array();
274 foreach ($submenu->liste as $key2 => $val2) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
275 $showmenu = true;
276 if (getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED') && empty($val2['enabled'])) {
277 $showmenu = false;
278 }
279
280 // If at least one parent is not enabled, we do not show any menu of all children
281 if ($val2['level'] > 0) {
282 $levelcursor = $val2['level'] - 1;
283 while ($levelcursor >= 0) {
284 // @phan-suppress-next-line PhanTypeInvalidDimOffset
285 if ($lastlevel2[$levelcursor] != 'enabled') {
286 $showmenu = false;
287 }
288 $levelcursor--;
289 }
290 }
291
292 if ($showmenu) { // Visible (option to hide when not allowed is off or allowed)
293 $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
294 $substitarray['__USERID__'] = $user->id; // For backward compatibility
295 $val2['url'] = make_substitutions($val2['url'], $substitarray); // Make also substitution of __(XXX)__ and __[XXX]__
296
297 if (!preg_match("/^(http:\/\/|https:\/\/)/i", $val2['url'])) {
298 $relurl2 = dol_buildpath($val2['url'], 1);
299 } else {
300 $relurl2 = $val2['url'];
301 }
302 $canonurl2 = preg_replace('/\?.*$/', '', $val2['url']);
303 //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
304 if (in_array($canonurl2, array('/admin/index.php', '/admin/tools/index.php', '/core/tools.php'))) {
305 $relurl2 = '';
306 }
307
308 $disabled = '';
309 if (!$val2['enabled']) {
310 $disabled = " vsmenudisabled";
311 }
312
313 // @phan-suppress-next-line PhanParamSuspiciousOrder
314 print str_pad('', $val2['level'] + 1);
315 print '<li class="lilevel'.($val2['level'] + 1);
316 if ($val2['level'] == 0) {
317 print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic
318 }
319 print $disabled.'">'; // ui-btn to highlight on clic
320 if ($relurl2) {
321 if ($val2['enabled']) { // Allowed
322 print '<a href="'.$relurl2.'"';
323 //print ' data-ajax="false"';
324 print '>';
325 $lastlevel2[$val2['level']] = 'enabled';
326 } else { // Not allowed but visible (greyed)
327 print '<a href="#" class="vsmenudisabled">';
328 $lastlevel2[$val2['level']] = 'greyed';
329 }
330 } else {
331 if ($val2['enabled']) { // Allowed
332 $lastlevel2[$val2['level']] = 'enabled';
333 } else {
334 $lastlevel2[$val2['level']] = 'greyed';
335 }
336 }
337
338 if ($val2['level'] == 0 && !empty($val2['prefix'])) {
339 print $val2['prefix'];
340 } else {
341 print '<i class="fa fa-does-not-exists fa-fw paddingright pictofixedwidth"></i>';
342 }
343
344 print $val2['titre'];
345 if ($relurl2) {
346 print '</a>';
347 }
348 print '</li>'."\n";
349 }
350 }
351 //var_dump($submenu);
352 print '</ul>';
353 }
354 if ($val['enabled'] == 2) {
355 print '<span class="spanlilevel0 vsmenudisabled">';
356
357 // Add font-awesome
358 if ($val['level'] == 0 && !empty($val['prefix'])) {
359 print $val['prefix'];
360 }
361
362 print $val['titre'];
363 print '</span>';
364 }
365 print '</li>';
366 print '</ul>'."\n";
367 }
368 }
369
370 unset($this->menu);
371
372 //print 'xx'.$mode;
373 return 0;
374 }
375}
print_left_auguria_menu($db, $menu_array_before, $menu_array_after, &$tabMenu, &$menu, $noout=0, $forcemainmenu='', $forceleftmenu='', $moredata=null, $type_user=0)
Core function to output left menu auguria Fill &$menu (example with $forcemainmenu='home' $forceleftm...
print_auguria_menu($db, $atarget, $type_user, &$tabMenu, &$menu, $noout=0, $mode='')
Core function to output top menu auguria.
Class to manage left menus.
Class to manage menu Auguria.
__construct($db, $type_user)
Constructor.
loadMenu($forcemainmenu='', $forceleftmenu='')
Load this->tabMenu.
showmenu($mode, $moredata=null)
Show menu.
Class to manage menu entries.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.