dolibarr 22.0.5
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 // We save into session the main menu selected
98 if (GETPOSTISSET("mainmenu")) {
99 $_SESSION["mainmenu"] = GETPOST("mainmenu", 'aZ09');
100 }
101 if (GETPOSTISSET("idmenu")) {
102 $_SESSION["idmenu"] = GETPOSTINT("idmenu");
103 }
104
105 // Read now mainmenu and leftmenu that define which menu to show
106 if (GETPOSTISSET("mainmenu")) {
107 // On sauve en session le menu principal choisi
108 $mainmenu = GETPOST("mainmenu", 'aZ09');
109 $_SESSION["mainmenu"] = $mainmenu;
110 $_SESSION["leftmenuopened"] = "";
111 } else {
112 // Look for the menu in the session if not set by the link
113 $mainmenu = isset($_SESSION["mainmenu"]) ? $_SESSION["mainmenu"] : '';
114 }
115 if (!empty($forcemainmenu)) {
116 $mainmenu = $forcemainmenu;
117 }
118
119 if (GETPOSTISSET("leftmenu")) {
120 // On sauve en session le menu principal choisi
121 $leftmenu = GETPOST("leftmenu", 'aZ09');
122 $_SESSION["leftmenu"] = $leftmenu;
123
124 if ($_SESSION["leftmenuopened"] == $leftmenu) { // To collapse
125 //$leftmenu="";
126 $_SESSION["leftmenuopened"] = "";
127 } else {
128 $_SESSION["leftmenuopened"] = $leftmenu;
129 }
130 } else {
131 // Look for the menu in the session if not set by the link
132 $leftmenu = isset($_SESSION["leftmenu"]) ? $_SESSION["leftmenu"] : '';
133 }
134 if (!empty($forceleftmenu)) {
135 $leftmenu = $forceleftmenu;
136 }
137
138 require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php';
139 $tabMenu = array();
140 $menuArbo = new Menubase($this->db, 'auguria');
141 $menuArbo->menuLoad($mainmenu, $leftmenu, $this->type_user, 'auguria', $tabMenu);
142 $this->tabMenu = $tabMenu;
143 //var_dump($tabMenu);
144
145 //if ($forcemainmenu == 'all') { var_dump($this->tabMenu); exit; }
146 }
147
148
157 public function showmenu($mode, $moredata = null)
158 {
159 global $conf, $langs, $user;
160
161 require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/auguria.lib.php';
162
163 if ($this->type_user == 1) {
164 $conf->global->MAIN_SEARCHFORM_SOCIETE_DISABLED = 1;
165 $conf->global->MAIN_SEARCHFORM_CONTACT_DISABLED = 1;
166 }
167
168 require_once DOL_DOCUMENT_ROOT.'/core/class/menu.class.php';
169 $this->menu = new Menu();
170
171 if (!getDolGlobalString('MAIN_MENU_INVERT')) {
172 if ($mode == 'top') {
173 print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
174 }
175 if ($mode == 'left') {
176 print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0, '', '', $moredata);
177 }
178 } else {
179 $conf->global->MAIN_SHOW_LOGO = 0;
180 if ($mode == 'top') {
181 print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0);
182 }
183 if ($mode == 'left') {
184 print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
185 }
186 }
187
188 if ($mode == 'topnb') {
189 print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode);
190 return $this->menu->getNbOfVisibleMenuEntries();
191 }
192
193 if ($mode == 'jmobile') { // Used to get menu in xml ul/li
194 print_auguria_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode);
195
196 // $this->menu->liste is top menu
197 //var_dump($this->menu->liste);exit;
198 $lastlevel = array();
199 $showmenu = true; // Is current menu shown - define here to keep static code checker happy
200 print '<!-- Generate menu list from menu handler '.$this->name.' -->'."\n";
201 foreach ($this->menu->liste as $key => $val) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
202 print '<ul class="ulmenu" data-inset="true">';
203 print '<li class="lilevel0">';
204 if ($val['enabled'] == 1) {
205 $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
206 $substitarray['__USERID__'] = $user->id; // For backward compatibility
207 $val['url'] = make_substitutions($val['url'], $substitarray);
208
209 $relurl = dol_buildpath($val['url'], 1);
210 $canonurl = preg_replace('/\?.*$/', '', $val['url']);
211
212 print '<a class="alilevel0" href="#">';
213
214 // Add font-awesome
215 if ($val['level'] == 0 && !empty($val['prefix'])) {
216 print str_replace('<span class="', '<span class="paddingright pictofixedwidth ', $val['prefix']);
217 }
218
219 print $val['titre'];
220 print '</a>'."\n";
221
222 // Search submenu for this mainmenu entry
223 $tmpmainmenu = $val['mainmenu'];
224 $tmpleftmenu = 'all';
225 $submenu = new Menu();
226 print_left_auguria_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $submenu, 1, $tmpmainmenu, $tmpleftmenu);
227 if (!empty($submenu->liste[0]['url'])) {
228 $nexturl = dol_buildpath($submenu->liste[0]['url'], 1);
229 } else {
230 $nexturl = '';
231 }
232
233 $canonrelurl = preg_replace('/\?.*$/', '', $relurl);
234 $canonnexturl = preg_replace('/\?.*$/', '', $nexturl);
235 //var_dump($canonrelurl);
236 //var_dump($canonnexturl);
237 print '<ul>'."\n";
238 if (($canonrelurl != $canonnexturl && !in_array($val['mainmenu'], array('tools')))
239 || (strpos($canonrelurl, '/product/index.php') !== false || strpos($canonrelurl, '/compta/bank/list.php') !== false)) {
240 // We add sub entry
241 print str_pad('', 1).'<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic
242 print '<a href="'.$relurl.'">';
243
244 if ($val['level'] == 0) {
245 print '<span class="fas fa-home fa-fw paddingright pictofixedwidth" aria-hidden="true"></span>';
246 }
247
248 if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") { // No translation
249 if (in_array($val['mainmenu'], array('cashdesk', 'externalsite', 'website', 'collab', 'takepos'))) {
250 print $langs->trans("Access");
251 } else {
252 print $langs->trans("Dashboard");
253 }
254 } else {
255 print $langs->trans(ucfirst($val['mainmenu'])."Dashboard");
256 }
257 print '</a>';
258 print '</li>'."\n";
259 }
260
261 if ($val['level'] == 0) {
262 if ($val['enabled']) {
263 $lastlevel[0] = 'enabled';
264 } elseif ($showmenu) { // Not enabled but visible (so greyed)
265 $lastlevel[0] = 'greyed';
266 } else {
267 $lastlevel[0] = 'hidden';
268 }
269 }
270
271 $lastlevel2 = array();
272 foreach ($submenu->liste as $key2 => $val2) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
273 $showmenu = true;
274 if (getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED') && empty($val2['enabled'])) {
275 $showmenu = false;
276 }
277
278 // If at least one parent is not enabled, we do not show any menu of all children
279 if ($val2['level'] > 0) {
280 $levelcursor = $val2['level'] - 1;
281 while ($levelcursor >= 0) {
282 // @phan-suppress-next-line PhanTypeInvalidDimOffset
283 if ($lastlevel2[$levelcursor] != 'enabled') {
284 $showmenu = false;
285 }
286 $levelcursor--;
287 }
288 }
289
290 if ($showmenu) { // Visible (option to hide when not allowed is off or allowed)
291 $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
292 $substitarray['__USERID__'] = $user->id; // For backward compatibility
293 $val2['url'] = make_substitutions($val2['url'], $substitarray); // Make also substitution of __(XXX)__ and __[XXX]__
294
295 if (!preg_match("/^(http:\/\/|https:\/\/)/i", $val2['url'])) {
296 $relurl2 = dol_buildpath($val2['url'], 1);
297 } else {
298 $relurl2 = $val2['url'];
299 }
300 $canonurl2 = preg_replace('/\?.*$/', '', $val2['url']);
301 //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']);
302 if (in_array($canonurl2, array('/admin/index.php', '/admin/tools/index.php', '/core/tools.php'))) {
303 $relurl2 = '';
304 }
305
306 $disabled = '';
307 if (!$val2['enabled']) {
308 $disabled = " vsmenudisabled";
309 }
310
311 // @phan-suppress-next-line PhanParamSuspiciousOrder
312 print str_pad('', $val2['level'] + 1);
313 print '<li class="lilevel'.($val2['level'] + 1);
314 if ($val2['level'] == 0) {
315 print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic
316 }
317 print $disabled.'">'; // ui-btn to highlight on clic
318 if ($relurl2) {
319 if ($val2['enabled']) { // Allowed
320 print '<a href="'.$relurl2.'"';
321 //print ' data-ajax="false"';
322 print '>';
323 $lastlevel2[$val2['level']] = 'enabled';
324 } else { // Not allowed but visible (greyed)
325 print '<a href="#" class="vsmenudisabled">';
326 $lastlevel2[$val2['level']] = 'greyed';
327 }
328 } else {
329 if ($val2['enabled']) { // Allowed
330 $lastlevel2[$val2['level']] = 'enabled';
331 } else {
332 $lastlevel2[$val2['level']] = 'greyed';
333 }
334 }
335
336 // Add font-awesome for level 0 and 1 (if $val2['level'] == 1, we are on level2, if $val2['level'] == 2, we are on level 3...)
337 if ($val2['level'] == 0 && !empty($val2['prefix'])) {
338 print $val2['prefix'];
339 } else {
340 print '<i class="fa fa-does-not-exists fa-fw paddingright pictofixedwidth"></i>';
341 }
342
343 print $val2['titre'];
344 if ($relurl2) {
345 print '</a>';
346 }
347 print '</li>'."\n";
348 }
349 }
350 //var_dump($submenu);
351 print '</ul>';
352 }
353 if ($val['enabled'] == 2) {
354 print '<span class="spanlilevel0 vsmenudisabled">';
355
356 // Add font-awesome
357 if ($val['level'] == 0 && !empty($val['prefix'])) {
358 print $val['prefix'];
359 }
360
361 print $val['titre'];
362 print '</span>';
363 }
364 print '</li>';
365 print '</ul>'."\n";
366 }
367 }
368
369 unset($this->menu);
370
371 //print 'xx'.$mode;
372 return 0;
373 }
374}
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='')
@phan-file-suppress PhanTypeInvalidDimOffset
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)
Output menu on screen.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79