dolibarr 21.0.0-beta
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 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 $target;
107
113 public $titre;
114
118 public $title;
119
123 public $prefix;
124
128 public $langs;
129
133 public $leftmenu;
134
138 public $perms;
139
143 public $enabled;
144
148 public $user;
149
153 public $tms;
154
158 public $newmenu;
159
166 public function __construct($db, $menu_handler = '')
167 {
168 $this->db = $db;
169 $this->menu_handler = $menu_handler;
170 }
171
172
179 public function create($user = null)
180 {
181 global $conf;
182
183 // Clean parameters
184 if (!isset($this->enabled)) {
185 $this->enabled = '1';
186 }
187 $this->entity = (isset($this->entity) && (int) $this->entity >= 0 ? (int) $this->entity : $conf->entity);
188 $this->menu_handler = trim((string) $this->menu_handler);
189 $this->module = trim((string) $this->module);
190 $this->type = trim((string) $this->type);
191 $this->mainmenu = trim((string) $this->mainmenu);
192 $this->leftmenu = trim((string) $this->leftmenu);
193 $this->fk_menu = (int) $this->fk_menu; // If -1, fk_mainmenu and fk_leftmenu must be defined
194 $this->fk_mainmenu = trim((string) $this->fk_mainmenu);
195 $this->fk_leftmenu = trim((string) $this->fk_leftmenu);
196 $this->position = (int) $this->position;
197 $this->url = trim((string) $this->url);
198 $this->target = trim((string) $this->target);
199 $this->title = trim((string) $this->title);
200 $this->langs = trim((string) $this->langs);
201 $this->perms = trim((string) $this->perms);
202 $this->enabled = trim((string) $this->enabled);
203 $this->user = (int) $this->user;
204 if (empty($this->position)) {
205 $this->position = 0;
206 }
207
208 // Check parameters
209 if (empty($this->menu_handler)) {
210 return -1;
211 }
212
213 // For PGSQL, we must first found the max rowid and use it as rowid in insert because postgresql
214 // may use an already used value because its internal cursor does not increase when we do
215 // an insert with a forced id.
216 if (in_array($this->db->type, array('pgsql'))) {
217 $sql = "SELECT MAX(rowid) as maxrowid FROM ".$this->db->prefix()."menu";
218 $resqlrowid = $this->db->query($sql);
219 if ($resqlrowid) {
220 $obj = $this->db->fetch_object($resqlrowid);
221 $maxrowid = $obj->maxrowid;
222
223 // Max rowid can be empty if there is no record yet
224 if (empty($maxrowid)) {
225 $maxrowid = 1;
226 }
227
228 $sql = "SELECT setval('".$this->db->prefix()."menu_rowid_seq', ".($maxrowid).")";
229 //print $sql; exit;
230 $resqlrowidset = $this->db->query($sql);
231 if (!$resqlrowidset) {
232 dol_print_error($this->db);
233 }
234 } else {
235 dol_print_error($this->db);
236 }
237 }
238
239 // Check that entry does not exists yet on key menu_handler-fk_menu-position-url-entity, to avoid errors with postgresql
240 $sql = "SELECT count(*)";
241 $sql .= " FROM ".$this->db->prefix()."menu";
242 $sql .= " WHERE menu_handler = '".$this->db->escape($this->menu_handler)."'";
243 $sql .= " AND fk_menu = ".((int) $this->fk_menu);
244 $sql .= " AND position = ".((int) $this->position);
245 $sql .= " AND url = '".$this->db->escape($this->url)."'";
246 $sql .= " AND entity IN (0, ".$conf->entity.")";
247
248 $result = $this->db->query($sql);
249 if ($result) {
250 $row = $this->db->fetch_row($result);
251
252 if ($row[0] == 0) { // If not found
253 // Insert request
254 $sql = "INSERT INTO ".$this->db->prefix()."menu(";
255 $sql .= "menu_handler,";
256 $sql .= "entity,";
257 $sql .= "module,";
258 $sql .= "type,";
259 $sql .= "mainmenu,";
260 $sql .= "leftmenu,";
261 $sql .= "fk_menu,";
262 $sql .= "fk_mainmenu,";
263 $sql .= "fk_leftmenu,";
264 $sql .= "position,";
265 $sql .= "url,";
266 $sql .= "target,";
267 $sql .= "titre,";
268 $sql .= "prefix,";
269 $sql .= "langs,";
270 $sql .= "perms,";
271 $sql .= "enabled,";
272 $sql .= "usertype";
273 $sql .= ") VALUES (";
274 $sql .= " '".$this->db->escape($this->menu_handler)."',";
275 $sql .= " '".$this->db->escape($this->entity)."',";
276 $sql .= " '".$this->db->escape($this->module)."',";
277 $sql .= " '".$this->db->escape($this->type)."',";
278 $sql .= " ".($this->mainmenu ? "'".$this->db->escape($this->mainmenu)."'" : "''").","; // Can't be null
279 $sql .= " ".($this->leftmenu ? "'".$this->db->escape($this->leftmenu)."'" : "null").",";
280 $sql .= " ".((int) $this->fk_menu).",";
281 $sql .= " ".($this->fk_mainmenu ? "'".$this->db->escape($this->fk_mainmenu)."'" : "null").",";
282 $sql .= " ".($this->fk_leftmenu ? "'".$this->db->escape($this->fk_leftmenu)."'" : "null").",";
283 $sql .= " ".((int) $this->position).",";
284 $sql .= " '".$this->db->escape($this->url)."',";
285 $sql .= " '".$this->db->escape($this->target)."',";
286 $sql .= " '".$this->db->escape($this->title)."',";
287 $sql .= " '".$this->db->escape($this->prefix)."',";
288 $sql .= " '".$this->db->escape($this->langs)."',";
289 $sql .= " '".$this->db->escape($this->perms)."',";
290 $sql .= " '".$this->db->escape($this->enabled)."',";
291 $sql .= " '".$this->db->escape($this->user)."'";
292 $sql .= ")";
293
294 dol_syslog(get_class($this)."::create", LOG_DEBUG);
295 $resql = $this->db->query($sql);
296 if ($resql) {
297 $this->id = $this->db->last_insert_id($this->db->prefix()."menu");
298 dol_syslog(get_class($this)."::create record added has rowid=".((int) $this->id), LOG_DEBUG);
299
300 return $this->id;
301 } else {
302 $this->error = "Error ".$this->db->lasterror();
303 return -1;
304 }
305 } else {
306 dol_syslog(get_class($this)."::create menu entry already exists", LOG_WARNING);
307 $this->error = 'Error Menu entry ('.$this->menu_handler.','.$this->position.','.$this->url.') already exists';
308 return 0;
309 }
310 } else {
311 return -1;
312 }
313 }
314
322 public function update($user = null, $notrigger = 0)
323 {
324 //global $conf, $langs;
325
326 // Clean parameters
327 $this->menu_handler = trim($this->menu_handler);
328 $this->module = trim($this->module);
329 $this->type = trim($this->type);
330 $this->mainmenu = trim($this->mainmenu);
331 $this->leftmenu = trim($this->leftmenu);
332 $this->fk_menu = (int) $this->fk_menu;
333 $this->fk_mainmenu = trim($this->fk_mainmenu);
334 $this->fk_leftmenu = trim($this->fk_leftmenu);
335 $this->position = (int) $this->position;
336 $this->url = trim($this->url);
337 $this->target = trim($this->target);
338 $this->title = trim($this->title);
339 $this->prefix = trim($this->prefix);
340 $this->langs = trim($this->langs);
341 $this->perms = trim($this->perms);
342 $this->enabled = trim($this->enabled);
343 $this->user = (int) $this->user;
344
345 // Check parameters
346 // Put here code to add control on parameters values
347
348 // Update request
349 $sql = "UPDATE ".$this->db->prefix()."menu SET";
350 $sql .= " menu_handler='".$this->db->escape($this->menu_handler)."',";
351 $sql .= " module='".$this->db->escape($this->module)."',";
352 $sql .= " type='".$this->db->escape($this->type)."',";
353 $sql .= " mainmenu='".$this->db->escape($this->mainmenu)."',";
354 $sql .= " leftmenu='".$this->db->escape($this->leftmenu)."',";
355 $sql .= " fk_menu=".((int) $this->fk_menu).",";
356 $sql .= " fk_mainmenu=".($this->fk_mainmenu ? "'".$this->db->escape($this->fk_mainmenu)."'" : "null").",";
357 $sql .= " fk_leftmenu=".($this->fk_leftmenu ? "'".$this->db->escape($this->fk_leftmenu)."'" : "null").",";
358 $sql .= " position=".($this->position > 0 ? ((int) $this->position) : 0).",";
359 $sql .= " url='".$this->db->escape($this->url)."',";
360 $sql .= " target='".$this->db->escape($this->target)."',";
361 $sql .= " titre='".$this->db->escape($this->title)."',";
362 $sql .= " prefix='".$this->db->escape($this->prefix)."',";
363 $sql .= " langs='".$this->db->escape($this->langs)."',";
364 $sql .= " perms='".$this->db->escape($this->perms)."',";
365 $sql .= " enabled='".$this->db->escape($this->enabled)."',";
366 $sql .= " usertype='".$this->db->escape($this->user)."'";
367 $sql .= " WHERE rowid=".((int) $this->id);
368
369 dol_syslog(get_class($this)."::update", LOG_DEBUG);
370 $resql = $this->db->query($sql);
371 if (!$resql) {
372 $this->error = "Error ".$this->db->lasterror();
373 return -1;
374 }
375
376 return 1;
377 }
378
379
387 public function fetch($id, $user = null)
388 {
389 //global $langs;
390
391 $sql = "SELECT";
392 $sql .= " t.rowid,";
393 $sql .= " t.menu_handler,";
394 $sql .= " t.entity,";
395 $sql .= " t.module,";
396 $sql .= " t.type,";
397 $sql .= " t.mainmenu,";
398 $sql .= " t.leftmenu,";
399 $sql .= " t.fk_menu,";
400 $sql .= " t.fk_mainmenu,";
401 $sql .= " t.fk_leftmenu,";
402 $sql .= " t.position,";
403 $sql .= " t.url,";
404 $sql .= " t.target,";
405 $sql .= " t.titre as title,";
406 $sql .= " t.prefix,";
407 $sql .= " t.langs,";
408 $sql .= " t.perms,";
409 $sql .= " t.enabled,";
410 $sql .= " t.usertype as user,";
411 $sql .= " t.tms";
412 $sql .= " FROM ".$this->db->prefix()."menu as t";
413 $sql .= " WHERE t.rowid = ".((int) $id);
414
415 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
416 $resql = $this->db->query($sql);
417 if ($resql) {
418 if ($this->db->num_rows($resql)) {
419 $obj = $this->db->fetch_object($resql);
420
421 $this->id = $obj->rowid;
422
423 $this->menu_handler = $obj->menu_handler;
424 $this->entity = $obj->entity;
425 $this->module = $obj->module;
426 $this->type = $obj->type;
427 $this->mainmenu = $obj->mainmenu;
428 $this->leftmenu = $obj->leftmenu;
429 $this->fk_menu = $obj->fk_menu;
430 $this->fk_mainmenu = $obj->fk_mainmenu;
431 $this->fk_leftmenu = $obj->fk_leftmenu;
432 $this->position = $obj->position;
433 $this->url = $obj->url;
434 $this->target = $obj->target;
435 $this->title = $obj->title;
436 $this->prefix = $obj->prefix;
437 $this->langs = $obj->langs;
438 $this->perms = str_replace("\"", "'", $obj->perms);
439 $this->enabled = str_replace("\"", "'", $obj->enabled);
440 $this->user = $obj->user;
441 $this->tms = $this->db->jdate($obj->tms);
442 }
443 $this->db->free($resql);
444
445 return 1;
446 } else {
447 $this->error = "Error ".$this->db->lasterror();
448 return -1;
449 }
450 }
451
452
459 public function delete($user)
460 {
461 //global $conf, $langs;
462
463 $sql = "DELETE FROM ".$this->db->prefix()."menu";
464 $sql .= " WHERE rowid=".((int) $this->id);
465
466 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
467 $resql = $this->db->query($sql);
468 if (!$resql) {
469 $this->error = "Error ".$this->db->lasterror();
470 return -1;
471 }
472
473 return 1;
474 }
475
476
484 public function initAsSpecimen()
485 {
486 $this->id = 0;
487
488 $this->menu_handler = 'all';
489 $this->module = 'specimen';
490 $this->type = 'top';
491 $this->mainmenu = '';
492 $this->fk_menu = 0;
493 $this->position = 0;
494 $this->url = 'http://dummy';
495 $this->target = '';
496 $this->title = 'Specimen menu';
497 $this->langs = '';
498 $this->leftmenu = '';
499 $this->perms = '';
500 $this->enabled = '';
501 $this->user = 0;
502 $this->tms = dol_now();
503
504 return 1;
505 }
506
507
518 public function menuTopCharger($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
519 {
520 global $langs, $user, $conf; // To export to dol_eval function
521 global $mainmenu, $leftmenu; // To export to dol_eval function
522
523 $mainmenu = $mymainmenu; // To export to dol_eval function
524 $leftmenu = $myleftmenu; // To export to dol_eval function
525
526 $newTabMenu = array();
527 foreach ($tabMenu as $val) {
528 if ($val['type'] == 'top') {
529 $newTabMenu[] = $val;
530 }
531 }
532
533 return $newTabMenu;
534 }
535
548 public function menuLeftCharger($newmenu, $mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
549 {
550 global $langs, $user, $conf; // To export to dol_eval function
551 global $mainmenu, $leftmenu; // To export to dol_eval function
552
553 $mainmenu = $mymainmenu; // To export to dol_eval function
554 $leftmenu = $myleftmenu; // To export to dol_eval function
555
556 // Detect what is top mainmenu id
557 $menutopid = '';
558 foreach ($tabMenu as $key => $val) {
559 // Define menutopid of mainmenu
560 if (empty($menutopid) && $val['type'] == 'top' && $val['mainmenu'] == $mainmenu) {
561 $menutopid = $val['rowid'];
562 break;
563 }
564 }
565
566 // We initialize newmenu with first already found menu entries
567 $this->newmenu = $newmenu;
568
569 // 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)
570 $this->recur($tabMenu, $menutopid, 1);
571
572 // Now complete $this->newmenu->list when fk_menu value is -1 (left menu added by modules with no top menu)
573 foreach ($tabMenu as $key => $val) {
574 if ($val['fk_menu'] == -1 && $val['fk_mainmenu'] == $mainmenu) { // We found a menu entry not linked to parent with good mainmenu
575 //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>';
576 //var_dump($this->newmenu->liste);exit;
577 if (empty($val['fk_leftmenu'])) {
578 $this->newmenu->add($val['url'], $val['titre'], 0, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position'], '', '', '', $val['prefix']);
579 //var_dump($this->newmenu->liste);
580 } else {
581 // Search first menu with this couple (mainmenu,leftmenu)=(fk_mainmenu,fk_leftmenu)
582 $searchlastsub = 0;
583 $lastid = 0;
584 $nextid = 0;
585 $found = 0;
586 foreach ($this->newmenu->liste as $keyparent => $valparent) {
587 //var_dump($valparent);
588 if ($searchlastsub) { // If we started to search for last submenu
589 if ($valparent['level'] >= $searchlastsub) {
590 $lastid = $keyparent;
591 }
592 if ($valparent['level'] < $searchlastsub) {
593 $nextid = $keyparent;
594 break;
595 }
596 }
597 if ($valparent['mainmenu'] == $val['fk_mainmenu'] && $valparent['leftmenu'] == $val['fk_leftmenu']) {
598 //print "We found parent: keyparent='.$keyparent.' - level=".$valparent['level'].' - '.join(',',$valparent).'<br>';
599 // Now we look to find last subelement of this parent (we add at end)
600 $searchlastsub = ($valparent['level'] + 1);
601 $lastid = $keyparent;
602 $found = 1;
603 }
604 }
605 //print 'We must insert menu entry between entry '.$lastid.' and '.$nextid.'<br>';
606 if ($found) {
607 $this->newmenu->insert($lastid, $val['url'], $val['titre'], $searchlastsub, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position'], '', '', '', $val['prefix']);
608 } else {
609 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);
610 //print "Parent menu not found !!<br>";
611 }
612 }
613 }
614 }
615
616 return $this->newmenu;
617 }
618
619
630 public function menuLoad($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
631 {
632 global $langs, $user, $conf; // To export to dol_eval function
633 global $mainmenu, $leftmenu; // To export to dol_eval function
634
635 $mainmenu = $mymainmenu; // To export to dol_eval function
636 $leftmenu = $myleftmenu; // To export to dol_eval function
637
638 $sql = "SELECT m.rowid, m.type, m.module, m.fk_menu, m.fk_mainmenu, m.fk_leftmenu, m.url, m.titre,";
639 $sql .= " m.prefix, m.langs, m.perms, m.enabled, m.target, m.mainmenu, m.leftmenu, m.position";
640 $sql .= " FROM ".$this->db->prefix()."menu as m";
641 $sql .= " WHERE m.entity IN (0,".$conf->entity.")";
642 $sql .= " AND m.menu_handler IN ('".$this->db->escape($menu_handler)."','all')";
643 if ($type_user == 0) {
644 $sql .= " AND m.usertype IN (0,2)";
645 }
646 if ($type_user == 1) {
647 $sql .= " AND m.usertype IN (1,2)";
648 }
649 $sql .= " ORDER BY m.type DESC, m.position, m.rowid";
650 //print $sql;
651
652 //dol_syslog(get_class($this)."::menuLoad mymainmenu=".$mymainmenu." myleftmenu=".$myleftmenu." type_user=".$type_user." menu_handler=".$menu_handler." tabMenu size=".count($tabMenu), LOG_DEBUG);
653 $resql = $this->db->query($sql);
654 if ($resql) {
655 $numa = $this->db->num_rows($resql);
656
657 $a = 0;
658 $b = 0;
659 while ($a < $numa) {
660 //$objm = $this->db->fetch_object($resql);
661 $menu = $this->db->fetch_array($resql);
662
663 // Define $right
664 $perms = true;
665 if (isset($menu['perms'])) {
666 $tmpcond = $menu['perms'];
667 if ($leftmenu == 'all') {
668 $tmpcond = preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/', '1==1', $tmpcond); // Force the part of condition on leftmenu to true
669 }
670 $perms = verifCond($tmpcond);
671 //print "verifCond rowid=".$menu['rowid']." ".$tmpcond.":".$perms."<br>\n";
672 }
673
674 // Define $enabled
675 $enabled = true;
676 if (isset($menu['enabled'])) {
677 $tmpcond = $menu['enabled'];
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 $enabled = verifCond($tmpcond);
682 //var_dump($menu['type'].' - '.$menu['titre'].' - '.$menu['enabled'].' => '.$enabled);
683 }
684
685 // Define $title
686 if ($enabled && isset($menu)) {
687 $title = $langs->trans($menu['titre']); // If $menu['titre'] start with $, a dol_eval is done.
688 //var_dump($title.'-'.$menu['titre']);
689 if ($title == $menu['titre']) { // Translation not found
690 if (!empty($menu['langs'])) { // If there is a dedicated translation file
691 //print 'Load file '.$menu['langs'].'<br>';
692 $langs->load($menu['langs']);
693 }
694
695 $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
696 $menu['titre'] = make_substitutions($menu['titre'], $substitarray);
697
698 if (preg_match("/\//", $menu['titre'])) { // To manage translation when title is string1/string2
699 $tab_titre = explode("/", $menu['titre']);
700 $title = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]);
701 } elseif (preg_match('/\|\|/', $menu['titre'])) {
702 // To manage different translation (Title||AltTitle@ConditionForAltTitle)
703 $tab_title = explode("||", $menu['titre']);
704 $alt_title = explode("@", $tab_title[1]);
705 $title_enabled = verifCond($alt_title[1]);
706 $title = ($title_enabled ? $langs->trans($alt_title[0]) : $langs->trans($tab_title[0]));
707 } else {
708 $title = $langs->trans($menu['titre']);
709 }
710 }
711
712 // We complete tabMenu
713 $tabMenu[$b]['rowid'] = $menu['rowid'];
714 $tabMenu[$b]['module'] = $menu['module'];
715 $tabMenu[$b]['fk_menu'] = $menu['fk_menu'];
716 $tabMenu[$b]['url'] = $menu['url'];
717 if (!preg_match("/^(http:\/\/|https:\/\/)/i", $tabMenu[$b]['url'])) {
718 if (preg_match('/\?/', $tabMenu[$b]['url'])) {
719 $tabMenu[$b]['url'] .= '&amp;idmenu='.$menu['rowid'];
720 } else {
721 $tabMenu[$b]['url'] .= '?idmenu='.$menu['rowid'];
722 }
723 }
724 $tabMenu[$b]['titre'] = $title;
725 $tabMenu[$b]['prefix'] = $menu['prefix'];
726 $tabMenu[$b]['target'] = $menu['target'];
727 $tabMenu[$b]['mainmenu'] = $menu['mainmenu'];
728 $tabMenu[$b]['leftmenu'] = $menu['leftmenu'];
729 $tabMenu[$b]['perms'] = $perms;
730 $tabMenu[$b]['langs'] = $menu['langs']; // Note that this should not be used, lang file should be already loaded.
731 $tabMenu[$b]['enabled'] = $enabled;
732 $tabMenu[$b]['type'] = $menu['type'];
733 $tabMenu[$b]['fk_mainmenu'] = $menu['fk_mainmenu'];
734 $tabMenu[$b]['fk_leftmenu'] = $menu['fk_leftmenu'];
735 $tabMenu[$b]['position'] = (int) $menu['position'];
736
737 $b++;
738 }
739
740 $a++;
741 }
742 $this->db->free($resql);
743
744 // Currently $tabMenu is sorted on position.
745 // 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
746 // into the leftMenuCharger later to avoid useless operations.
747
748 return 1;
749 } else {
750 dol_print_error($this->db);
751 return -1;
752 }
753 }
754
763 private function recur($tab, $pere, $level)
764 {
765 // Loop on tab array
766 $num = count($tab);
767 for ($x = 0; $x < $num; $x++) {
768 //si un element a pour pere : $pere
769 if ((($tab[$x]['fk_menu'] >= 0 && $tab[$x]['fk_menu'] == $pere)) && $tab[$x]['enabled']) {
770 $this->newmenu->add($tab[$x]['url'], $tab[$x]['titre'], ($level - 1), $tab[$x]['perms'], $tab[$x]['target'], $tab[$x]['mainmenu'], $tab[$x]['leftmenu'], 0, '', '', '', $tab[$x]['prefix']);
771 $this->recur($tab, $tab[$x]['rowid'], ($level + 1));
772 }
773 }
774 }
775}
print $object position
Definition edit.php:204
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.
verifCond($strToEvaluate, $onlysimplestring='1')
Verify if condition in string is ok or not.
dol_now($mode='auto')
Return date for now.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
$conf db user
Active Directory does not allow anonymous connections.
Definition repair.php:153
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:149