dolibarr 23.0.3
menubase.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2009 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
32{
36 public $db;
37
41 public $error;
42
46 public $errors = array();
47
51 public $id;
52
56 public $entity;
57
61 public $menu_handler;
62
66 public $module;
67
71 public $type;
72
76 public $mainmenu;
77
81 public $fk_menu;
82
86 public $fk_mainmenu;
87
91 public $fk_leftmenu;
92
96 public $position;
97
101 public $url;
102
106 public $showtopmenuinframe;
107
111 public $target;
112
118 public $titre;
119
123 public $title;
124
128 public $prefix;
129
133 public $langs;
134
138 public $leftmenu;
139
143 public $perms;
144
148 public $enabled;
149
153 public $user;
154
158 public $tms;
159
163 public $newmenu;
164
171 public function __construct($db, $menu_handler = '')
172 {
173 $this->db = $db;
174 $this->menu_handler = $menu_handler;
175 }
176
177
184 public function create($user = null)
185 {
186 global $conf;
187
188 // Clean parameters
189 if (!isset($this->enabled)) {
190 $this->enabled = '1';
191 }
192 $this->entity = (isset($this->entity) && (int) $this->entity >= 0 ? (int) $this->entity : $conf->entity);
193 $this->menu_handler = trim((string) $this->menu_handler);
194 $this->module = trim((string) $this->module);
195 $this->type = trim((string) $this->type);
196 $this->mainmenu = trim((string) $this->mainmenu);
197 $this->leftmenu = trim((string) $this->leftmenu);
198 $this->fk_menu = (int) $this->fk_menu; // If -1, fk_mainmenu and fk_leftmenu must be defined
199 $this->fk_mainmenu = trim((string) $this->fk_mainmenu);
200 $this->fk_leftmenu = trim((string) $this->fk_leftmenu);
201 $this->position = (int) $this->position;
202 $this->url = trim((string) $this->url);
203 $this->target = trim((string) $this->target);
204 $this->title = trim((string) $this->title);
205 $this->langs = trim((string) $this->langs);
206 $this->perms = trim((string) $this->perms);
207 $this->enabled = trim((string) $this->enabled);
208 $this->user = (int) $this->user;
209 if (empty($this->position)) {
210 $this->position = 0;
211 }
212
213 // Check parameters
214 if (empty($this->menu_handler)) {
215 return -1;
216 }
217
218 // For PGSQL, we must first found the max rowid and use it as rowid in insert because postgresql
219 // may use an already used value because its internal cursor does not increase when we do
220 // an insert with a forced id.
221 if (in_array($this->db->type, array('pgsql'))) {
222 $sql = "SELECT MAX(rowid) as maxrowid FROM ".$this->db->prefix()."menu";
223 $resqlrowid = $this->db->query($sql);
224 if ($resqlrowid) {
225 $obj = $this->db->fetch_object($resqlrowid);
226 $maxrowid = $obj->maxrowid;
227
228 // Max rowid can be empty if there is no record yet
229 if (empty($maxrowid)) {
230 $maxrowid = 1;
231 }
232
233 $sql = "SELECT setval('".$this->db->prefix()."menu_rowid_seq', ".($maxrowid).")";
234 //print $sql; exit;
235 $resqlrowidset = $this->db->query($sql);
236 if (!$resqlrowidset) {
237 dol_print_error($this->db);
238 }
239 } else {
240 dol_print_error($this->db);
241 }
242 }
243
244 // Check that entry does not exists yet on key menu_handler-fk_menu-position-url-entity, to avoid errors with postgresql
245 $sql = "SELECT count(*)";
246 $sql .= " FROM ".$this->db->prefix()."menu";
247 $sql .= " WHERE menu_handler = '".$this->db->escape($this->menu_handler)."'";
248 $sql .= " AND fk_menu = ".((int) $this->fk_menu);
249 $sql .= " AND position = ".((int) $this->position);
250 $sql .= " AND url = '".$this->db->escape($this->url)."'";
251 $sql .= " AND entity IN (0, ".$conf->entity.")";
252
253 $result = $this->db->query($sql);
254 if ($result) {
255 $row = $this->db->fetch_row($result);
256
257 if ($row[0] == 0) { // If not found
258 // Insert request
259 $sql = "INSERT INTO ".$this->db->prefix()."menu(";
260 $sql .= "menu_handler,";
261 $sql .= "entity,";
262 $sql .= "module,";
263 $sql .= "type,";
264 $sql .= "mainmenu,";
265 $sql .= "leftmenu,";
266 $sql .= "fk_menu,";
267 $sql .= "fk_mainmenu,";
268 $sql .= "fk_leftmenu,";
269 $sql .= "position,";
270 $sql .= "url,";
271 $sql .= "target,";
272 $sql .= "titre,";
273 $sql .= "prefix,";
274 $sql .= "langs,";
275 $sql .= "perms,";
276 $sql .= "enabled,";
277 $sql .= "usertype,";
278 $sql .= "showtopmenuinframe";
279 $sql .= ") VALUES (";
280 $sql .= " '".$this->db->escape($this->menu_handler)."',";
281 $sql .= " '".$this->db->escape((string) $this->entity)."',";
282 $sql .= " '".$this->db->escape($this->module)."',";
283 $sql .= " '".$this->db->escape($this->type)."',";
284 $sql .= " ".($this->mainmenu ? "'".$this->db->escape($this->mainmenu)."'" : "''").","; // Can't be null
285 $sql .= " ".($this->leftmenu ? "'".$this->db->escape($this->leftmenu)."'" : "null").",";
286 $sql .= " ".((int) $this->fk_menu).",";
287 $sql .= " ".($this->fk_mainmenu ? "'".$this->db->escape($this->fk_mainmenu)."'" : "null").",";
288 $sql .= " ".($this->fk_leftmenu ? "'".$this->db->escape($this->fk_leftmenu)."'" : "null").",";
289 $sql .= " ".((int) $this->position).",";
290 $sql .= " '".$this->db->escape($this->url)."',";
291 $sql .= " '".$this->db->escape($this->target)."',";
292 $sql .= " '".$this->db->escape($this->title)."',";
293 $sql .= " '".$this->db->escape($this->prefix)."',";
294 $sql .= " '".$this->db->escape($this->langs)."',";
295 $sql .= " '".$this->db->escape($this->perms)."',";
296 $sql .= " '".$this->db->escape($this->enabled)."',";
297 $sql .= " '".$this->db->escape((string) $this->user)."',";
298 $sql .= " ".((int) $this->showtopmenuinframe);
299 $sql .= ")";
300
301 dol_syslog(get_class($this)."::create", LOG_DEBUG);
302 $resql = $this->db->query($sql);
303 if ($resql) {
304 $this->id = $this->db->last_insert_id($this->db->prefix()."menu");
305 dol_syslog(get_class($this)."::create record added has rowid=".((int) $this->id), LOG_DEBUG);
306
307 return $this->id;
308 } else {
309 $this->error = "Error ".$this->db->lasterror();
310 return -1;
311 }
312 } else {
313 dol_syslog(get_class($this)."::create menu entry already exists", LOG_WARNING);
314 $this->error = 'Error Menu entry ('.$this->menu_handler.','.$this->position.','.$this->url.') already exists';
315 return 0;
316 }
317 } else {
318 return -1;
319 }
320 }
321
329 public function update($user = null, $notrigger = 0)
330 {
331 //global $conf, $langs;
332
333 // Clean parameters
334 $this->menu_handler = trim($this->menu_handler);
335 $this->module = trim($this->module);
336 $this->type = trim($this->type);
337 $this->mainmenu = trim($this->mainmenu);
338 $this->leftmenu = trim($this->leftmenu);
339 $this->fk_menu = (int) $this->fk_menu;
340 $this->fk_mainmenu = trim($this->fk_mainmenu);
341 $this->fk_leftmenu = trim($this->fk_leftmenu);
342 $this->position = (int) $this->position;
343 $this->url = trim($this->url);
344 $this->target = trim($this->target);
345 $this->title = trim($this->title);
346 $this->prefix = trim($this->prefix);
347 $this->langs = trim($this->langs);
348 $this->perms = trim($this->perms);
349 $this->enabled = trim($this->enabled);
350 $this->user = (int) $this->user;
351
352 // Check parameters
353 // Put here code to add control on parameters values
354
355 // Update request
356 $sql = "UPDATE ".$this->db->prefix()."menu SET";
357 $sql .= " menu_handler = '".$this->db->escape($this->menu_handler)."',";
358 $sql .= " module = '".$this->db->escape($this->module)."',";
359 $sql .= " type = '".$this->db->escape($this->type)."',";
360 $sql .= " mainmenu = '".$this->db->escape($this->mainmenu)."',";
361 $sql .= " leftmenu = '".$this->db->escape($this->leftmenu)."',";
362 $sql .= " fk_menu = ".((int) $this->fk_menu).",";
363 $sql .= " fk_mainmenu = ".($this->fk_mainmenu ? "'".$this->db->escape($this->fk_mainmenu)."'" : "null").",";
364 $sql .= " fk_leftmenu = ".($this->fk_leftmenu ? "'".$this->db->escape($this->fk_leftmenu)."'" : "null").",";
365 $sql .= " position = ".($this->position > 0 ? ((int) $this->position) : 0).",";
366 $sql .= " url = '".$this->db->escape($this->url)."',";
367 $sql .= " target = '".$this->db->escape($this->target)."',";
368 $sql .= " titre = '".$this->db->escape($this->title)."',";
369 $sql .= " prefix = '".$this->db->escape($this->prefix)."',";
370 $sql .= " langs = '".$this->db->escape($this->langs)."',";
371 $sql .= " perms = '".$this->db->escape($this->perms)."',";
372 $sql .= " enabled = '".$this->db->escape($this->enabled)."',";
373 $sql .= " usertype = '".$this->db->escape((string) $this->user)."',";
374 $sql .= " showtopmenuinframe = ".((int) $this->showtopmenuinframe);
375 $sql .= " WHERE rowid = ".((int) $this->id);
376
377 dol_syslog(get_class($this)."::update", LOG_DEBUG);
378 $resql = $this->db->query($sql);
379 if (!$resql) {
380 $this->error = "Error ".$this->db->lasterror();
381 return -1;
382 }
383
384 return 1;
385 }
386
387
395 public function fetch($id, $user = null)
396 {
397 //global $langs;
398
399 $sql = "SELECT";
400 $sql .= " t.rowid,";
401 $sql .= " t.menu_handler,";
402 $sql .= " t.entity,";
403 $sql .= " t.module,";
404 $sql .= " t.type,";
405 $sql .= " t.mainmenu,";
406 $sql .= " t.leftmenu,";
407 $sql .= " t.fk_menu,";
408 $sql .= " t.fk_mainmenu,";
409 $sql .= " t.fk_leftmenu,";
410 $sql .= " t.position,";
411 $sql .= " t.url,";
412 $sql .= " t.target,";
413 $sql .= " t.titre as title,";
414 $sql .= " t.prefix,";
415 $sql .= " t.langs,";
416 $sql .= " t.perms,";
417 $sql .= " t.enabled,";
418 $sql .= " t.usertype as user,";
419 $sql .= " t.tms,";
420 $sql .= " t.showtopmenuinframe";
421 $sql .= " FROM ".$this->db->prefix()."menu as t";
422 $sql .= " WHERE t.rowid = ".((int) $id);
423
424 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
425 $resql = $this->db->query($sql);
426 if ($resql) {
427 if ($this->db->num_rows($resql)) {
428 $obj = $this->db->fetch_object($resql);
429
430 $this->id = $obj->rowid;
431
432 $this->menu_handler = $obj->menu_handler;
433 $this->entity = $obj->entity;
434 $this->module = $obj->module;
435 $this->type = $obj->type;
436 $this->mainmenu = $obj->mainmenu;
437 $this->leftmenu = $obj->leftmenu;
438 $this->fk_menu = $obj->fk_menu;
439 $this->fk_mainmenu = $obj->fk_mainmenu;
440 $this->fk_leftmenu = $obj->fk_leftmenu;
441 $this->position = $obj->position;
442 $this->url = $obj->url;
443 $this->target = $obj->target;
444 $this->title = $obj->title;
445 $this->prefix = $obj->prefix;
446 $this->langs = $obj->langs;
447 $this->perms = str_replace("\"", "'", $obj->perms);
448 $this->enabled = str_replace("\"", "'", $obj->enabled);
449 $this->user = $obj->user;
450 $this->tms = $this->db->jdate($obj->tms);
451 $this->showtopmenuinframe = $obj->showtopmenuinframe;
452 }
453 $this->db->free($resql);
454
455 return 1;
456 } else {
457 $this->error = "Error ".$this->db->lasterror();
458 return -1;
459 }
460 }
461
462
469 public function delete($user)
470 {
471 //global $conf, $langs;
472
473 $sql = "DELETE FROM ".$this->db->prefix()."menu";
474 $sql .= " WHERE rowid=".((int) $this->id);
475
476 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
477 $resql = $this->db->query($sql);
478 if (!$resql) {
479 $this->error = "Error ".$this->db->lasterror();
480 return -1;
481 }
482
483 return 1;
484 }
485
486
494 public function initAsSpecimen()
495 {
496 $this->id = 0;
497
498 $this->menu_handler = 'all';
499 $this->module = 'specimen';
500 $this->type = 'top';
501 $this->mainmenu = '';
502 $this->fk_menu = 0;
503 $this->position = 0;
504 $this->url = 'http://dummy';
505 $this->target = '';
506 $this->title = 'Specimen menu';
507 $this->langs = '';
508 $this->leftmenu = '';
509 $this->perms = '';
510 $this->enabled = '';
511 $this->user = 0;
512 $this->tms = dol_now();
513
514 return 1;
515 }
516
517
528 public function menuTopCharger($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
529 {
530 global $langs, $user, $conf; // To export to dol_eval function
531 global $mainmenu, $leftmenu; // To export to dol_eval function
532
533 $mainmenu = $mymainmenu; // To export to dol_eval function
534 $leftmenu = $myleftmenu; // To export to dol_eval function
535
536 $newTabMenu = array();
537 foreach ($tabMenu as $val) {
538 if ($val['type'] == 'top') {
539 $newTabMenu[] = $val;
540 }
541 }
542
543 return $newTabMenu;
544 }
545
546
559 public function menuLeftCharger($newmenu, $mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
560 {
561 global $langs, $user, $conf; // To export to dol_eval function
562 global $mainmenu, $leftmenu; // To export to dol_eval function
563
564 $mainmenu = $mymainmenu; // To export to dol_eval function
565 $leftmenu = $myleftmenu; // To export to dol_eval function
566
567 // Detect what is top mainmenu id
568 $menutopid = '';
569 foreach ($tabMenu as $key => $val) {
570 // Define menutopid of mainmenu
571 if (empty($menutopid) && $val['type'] == 'top' && $val['mainmenu'] == $mainmenu) {
572 $menutopid = $val['rowid'];
573 break;
574 }
575 }
576
577 // We initialize newmenu with first already found menu entries
578 $this->newmenu = $newmenu;
579
580 // Now complete $this->newmenu->list to add entries found into $tabMenu that are children of mainmenu=$menutopid, using the fk_menu link that is int (old method)
581 $this->recur($tabMenu, $menutopid, 1);
582
583 // Now complete $this->newmenu->list when fk_menu value is -1 (left menu added by modules with no top menu)
584 foreach ($tabMenu as $key => $val) {
585 if ($val['fk_menu'] == -1 && $val['fk_mainmenu'] == $mainmenu) { // We found a menu entry not linked to parent with good mainmenu
586 //print 'Try to add menu (current is mainmenu='.$mainmenu.' leftmenu='.$leftmenu.') for '.join(',',$val).' fk_mainmenu='.$val['fk_mainmenu'].' fk_leftmenu='.$val['fk_leftmenu'].'<br>';
587 //var_dump($this->newmenu->liste);exit;
588 if (empty($val['fk_leftmenu'])) {
589 $this->newmenu->add($val['url'], $val['titre'], 0, (int) $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position'], '', '', '', $val['prefix']);
590 //var_dump($this->newmenu->liste);
591 } else {
592 // Search first menu with this couple (mainmenu,leftmenu)=(fk_mainmenu,fk_leftmenu)
593 $searchlastsub = 0;
594 $lastid = 0;
595 $nextid = 0;
596 $found = 0;
597 foreach ($this->newmenu->liste as $keyparent => $valparent) {
598 //var_dump($valparent);
599 if ($searchlastsub) { // If we started to search for last submenu
600 if ($valparent['level'] >= $searchlastsub) {
601 $lastid = $keyparent;
602 }
603 if ($valparent['level'] < $searchlastsub) {
604 $nextid = $keyparent;
605 break;
606 }
607 }
608 if ($valparent['mainmenu'] == $val['fk_mainmenu'] && $valparent['leftmenu'] == $val['fk_leftmenu']) {
609 //print "We found parent: keyparent='.$keyparent.' - level=".$valparent['level'].' - '.join(',',$valparent).'<br>';
610 // Now we look to find last subelement of this parent (we add at end)
611 $searchlastsub = ($valparent['level'] + 1);
612 $lastid = $keyparent;
613 $found = 1;
614 }
615 }
616 //print 'We must insert menu entry between entry '.$lastid.' and '.$nextid.'<br>';
617 if ($found) {
618 $this->newmenu->insert($lastid, $val['url'], $val['titre'], $searchlastsub, (int) $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position'], '', '', '', $val['prefix']);
619 } else {
620 dol_syslog("Error. Modules ".$val['module']." has defined a menu entry with a parent='fk_mainmenu=".$val['fk_leftmenu'].",fk_leftmenu=".$val['fk_leftmenu']."' and position=".$val['position'].'. The parent was not found. May be you forget it into your definition of menu, or may be the parent has a "position" that is after the child (fix field "position" of parent or child in this case).', LOG_WARNING);
621 //print "Parent menu not found !!<br>";
622 }
623 }
624 }
625 }
626
627 return $this->newmenu;
628 }
629
630
641 public function menuLoad($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
642 {
643 global $langs, $user, $conf; // To export to dol_eval function
644 global $mainmenu, $leftmenu; // To export to dol_eval function
645
646 $mainmenu = $mymainmenu; // To export to dol_eval function
647 $leftmenu = $myleftmenu; // To export to dol_eval function
648
649 $sql = "SELECT m.rowid, m.type, m.module, m.fk_menu, m.fk_mainmenu, m.fk_leftmenu, m.url, m.titre,";
650 $sql .= " m.prefix, m.langs, m.perms, m.enabled, m.target, m.mainmenu, m.leftmenu, m.position, m.showtopmenuinframe";
651 $sql .= " FROM ".$this->db->prefix()."menu as m";
652 $sql .= " WHERE m.entity IN (0,".$conf->entity.")";
653 $sql .= " AND m.menu_handler IN ('".$this->db->escape($menu_handler)."','all')";
654 if ($type_user == 0) {
655 $sql .= " AND m.usertype IN (0,2)";
656 }
657 if ($type_user == 1) {
658 $sql .= " AND m.usertype IN (1,2)";
659 }
660 $sql .= " ORDER BY m.type DESC, m.position, m.rowid";
661 //print $sql;
662
663 //dol_syslog(get_class($this)."::menuLoad mymainmenu=".$mymainmenu." myleftmenu=".$myleftmenu." type_user=".$type_user." menu_handler=".$menu_handler." tabMenu size=".count($tabMenu), LOG_DEBUG);
664 $resql = $this->db->query($sql);
665 if ($resql) {
666 $numa = $this->db->num_rows($resql);
667
668 $a = 0;
669 $b = 0;
670 while ($a < $numa) {
671 //$objm = $this->db->fetch_object($resql);
672 $menu = $this->db->fetch_array($resql);
673
674 // Define $right
675 $perms = true;
676 if (isset($menu['perms'])) {
677 $tmpcond = $menu['perms'];
678 if ($leftmenu == 'all') {
679 $tmpcond = preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/', '1==1', $tmpcond); // Force the part of condition on leftmenu to true
680 }
681 $perms = verifCond($tmpcond);
682 //print "verifCond rowid=".$menu['rowid']." ".$tmpcond.":".$perms."<br>\n";
683 }
684
685 // Define $enabled
686 $enabled = true;
687 if (isset($menu['enabled'])) {
688 $tmpcond = $menu['enabled'];
689 if ($leftmenu == 'all') {
690 $tmpcond = preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/', '1==1', $tmpcond); // Force the part of condition on leftmenu to true
691 }
692 $enabled = verifCond($tmpcond);
693 //var_dump($menu['type'].' - '.$menu['titre'].' - '.$menu['enabled'].' => '.$enabled);
694 }
695
696 // Define $title
697 if ($enabled && isset($menu)) {
698 $title = $langs->trans($menu['titre']); // If $menu['titre'] start with $, a dol_eval is done.
699 //var_dump($title.'-'.$menu['titre']);
700 if ($title == $menu['titre']) { // Translation not found
701 if (!empty($menu['langs'])) { // If there is a dedicated translation file
702 //print 'Load file '.$menu['langs'].'<br>';
703 $langs->load($menu['langs']);
704 }
705
706 $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
707 $menu['titre'] = make_substitutions($menu['titre'], $substitarray);
708
709 if (preg_match("/\//", $menu['titre'])) { // To manage translation when title is string1/string2
710 $tab_titre = explode("/", $menu['titre']);
711 $title = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]);
712 } elseif (preg_match('/\|\|/', $menu['titre'])) {
713 // To manage different translation (Title||AltTitle@ConditionForAltTitle)
714 $tab_title = explode("||", $menu['titre']);
715 $alt_title = explode("@", $tab_title[1]);
716 $title_enabled = verifCond($alt_title[1]);
717 $title = ($title_enabled ? $langs->trans($alt_title[0]) : $langs->trans($tab_title[0]));
718 } else {
719 $title = $langs->trans($menu['titre']);
720 }
721 }
722
723 // We complete tabMenu
724 $tabMenu[$b]['rowid'] = $menu['rowid'];
725 $tabMenu[$b]['module'] = $menu['module'];
726 $tabMenu[$b]['fk_menu'] = $menu['fk_menu'];
727 $tabMenu[$b]['url'] = $menu['url'];
728 if (!preg_match("/^(http:\/\/|https:\/\/)/i", $tabMenu[$b]['url'])) {
729 if (preg_match('/\?/', $tabMenu[$b]['url'])) {
730 $tabMenu[$b]['url'] .= '&amp;idmenu='.$menu['rowid'];
731 } else {
732 $tabMenu[$b]['url'] .= '?idmenu='.$menu['rowid'];
733 }
734 }
735 $tabMenu[$b]['titre'] = $title;
736 $tabMenu[$b]['prefix'] = $menu['prefix'];
737 $tabMenu[$b]['target'] = $menu['target'];
738 $tabMenu[$b]['mainmenu'] = $menu['mainmenu'];
739 $tabMenu[$b]['leftmenu'] = $menu['leftmenu'];
740 $tabMenu[$b]['perms'] = $perms;
741 $tabMenu[$b]['langs'] = $menu['langs']; // Note that this should not be used, lang file should be already loaded.
742 $tabMenu[$b]['enabled'] = $enabled;
743 $tabMenu[$b]['type'] = $menu['type'];
744 $tabMenu[$b]['fk_mainmenu'] = $menu['fk_mainmenu'];
745 $tabMenu[$b]['fk_leftmenu'] = $menu['fk_leftmenu'];
746 $tabMenu[$b]['position'] = (int) $menu['position'];
747 $tabMenu[$b]['showtopmenuinframe'] = (int) $menu['showtopmenuinframe'];
748
749 $b++;
750 }
751
752 $a++;
753 }
754 $this->db->free($resql);
755
756 // Currently $tabMenu is sorted on position.
757 // If a child have a position lower that its parent, we can make a loop to fix this here, but we prefer to show a warning
758 // into the leftMenuCharger later to avoid useless operations.
759
760 return 1;
761 } else {
762 dol_print_error($this->db);
763 return -1;
764 }
765 }
766
775 private function recur($tab, $pere, $level)
776 {
777 // Loop on tab array
778 $num = count($tab);
779 for ($x = 0; $x < $num; $x++) {
780 //si un element a pour pere : $pere
781 if ((($tab[$x]['fk_menu'] >= 0 && $tab[$x]['fk_menu'] == $pere)) && $tab[$x]['enabled']) {
782 $this->newmenu->add($tab[$x]['url'], $tab[$x]['titre'], ($level - 1), (int) $tab[$x]['perms'], $tab[$x]['target'], $tab[$x]['mainmenu'], $tab[$x]['leftmenu'], 0, '', '', '', $tab[$x]['prefix']);
783 $this->recur($tab, (int) $tab[$x]['rowid'], ($level + 1));
784 }
785 }
786 }
787}
print $object position
Definition edit.php:207
Class to manage menu entries.
recur($tab, $pere, $level)
Complete this->newmenu with menu entry found in $tab.
menuLoad($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
Load entries found in database into variable $tabMenu.
update($user=null, $notrigger=0)
Update menu entry into database.
fetch($id, $user=null)
Load object in memory from database.
__construct($db, $menu_handler='')
Constructor.
initAsSpecimen()
Initialise an instance with random values.
menuLeftCharger($newmenu, $mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
Load entries found from database (and stored into $tabMenu) in $this->newmenu array.
create($user=null)
Create menu entry into database.
menuTopCharger($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
Load tabMenu array with top menu entries found into database.
dol_now($mode='gmt')
Return date for now.
verifCond($strToEvaluate, $onlysimplestring='1')
Verify if condition in string is ok or not.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db user
Active Directory does not allow anonymous connections.
Definition repair.php:129
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:125