dolibarr 19.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-2023 Frédéric France <frederic.france@netlogic.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
31{
35 public $db;
36
40 public $error;
41
45 public $errors = array();
46
50 public $id;
51
55 public $entity;
56
60 public $menu_handler;
61
65 public $module;
66
70 public $type;
71
75 public $mainmenu;
76
80 public $fk_menu;
81
85 public $fk_mainmenu;
86
90 public $fk_leftmenu;
91
95 public $position;
96
100 public $url;
101
105 public $target;
106
112 public $titre;
113
117 public $title;
118
122 public $prefix;
123
127 public $langs;
128
133 public $level;
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, $langs;
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 if (!$this->level) {
213 $this->level = 0;
214 }
215
216 // Check parameters
217 if (empty($this->menu_handler)) {
218 return -1;
219 }
220
221 // For PGSQL, we must first found the max rowid and use it as rowid in insert because postgresql
222 // may use an already used value because its internal cursor does not increase when we do
223 // an insert with a forced id.
224 if (in_array($this->db->type, array('pgsql'))) {
225 $sql = "SELECT MAX(rowid) as maxrowid FROM ".$this->db->prefix()."menu";
226 $resqlrowid = $this->db->query($sql);
227 if ($resqlrowid) {
228 $obj = $this->db->fetch_object($resqlrowid);
229 $maxrowid = $obj->maxrowid;
230
231 // Max rowid can be empty if there is no record yet
232 if (empty($maxrowid)) {
233 $maxrowid = 1;
234 }
235
236 $sql = "SELECT setval('".$this->db->prefix()."menu_rowid_seq', ".($maxrowid).")";
237 //print $sql; exit;
238 $resqlrowidset = $this->db->query($sql);
239 if (!$resqlrowidset) {
240 dol_print_error($this->db);
241 }
242 } else {
243 dol_print_error($this->db);
244 }
245 }
246
247 // Check that entry does not exists yet on key menu_handler-fk_menu-position-url-entity, to avoid errors with postgresql
248 $sql = "SELECT count(*)";
249 $sql .= " FROM ".$this->db->prefix()."menu";
250 $sql .= " WHERE menu_handler = '".$this->db->escape($this->menu_handler)."'";
251 $sql .= " AND fk_menu = ".((int) $this->fk_menu);
252 $sql .= " AND position = ".((int) $this->position);
253 $sql .= " AND url = '".$this->db->escape($this->url)."'";
254 $sql .= " AND entity IN (0, ".$conf->entity.")";
255
256 $result = $this->db->query($sql);
257 if ($result) {
258 $row = $this->db->fetch_row($result);
259
260 if ($row[0] == 0) { // If not found
261 // Insert request
262 $sql = "INSERT INTO ".$this->db->prefix()."menu(";
263 $sql .= "menu_handler,";
264 $sql .= "entity,";
265 $sql .= "module,";
266 $sql .= "type,";
267 $sql .= "mainmenu,";
268 $sql .= "leftmenu,";
269 $sql .= "fk_menu,";
270 $sql .= "fk_mainmenu,";
271 $sql .= "fk_leftmenu,";
272 $sql .= "position,";
273 $sql .= "url,";
274 $sql .= "target,";
275 $sql .= "titre,";
276 $sql .= "prefix,";
277 $sql .= "langs,";
278 $sql .= "perms,";
279 $sql .= "enabled,";
280 $sql .= "usertype";
281 $sql .= ") VALUES (";
282 $sql .= " '".$this->db->escape($this->menu_handler)."',";
283 $sql .= " '".$this->db->escape($this->entity)."',";
284 $sql .= " '".$this->db->escape($this->module)."',";
285 $sql .= " '".$this->db->escape($this->type)."',";
286 $sql .= " ".($this->mainmenu ? "'".$this->db->escape($this->mainmenu)."'" : "''").","; // Can't be null
287 $sql .= " ".($this->leftmenu ? "'".$this->db->escape($this->leftmenu)."'" : "null").",";
288 $sql .= " ".((int) $this->fk_menu).",";
289 $sql .= " ".($this->fk_mainmenu ? "'".$this->db->escape($this->fk_mainmenu)."'" : "null").",";
290 $sql .= " ".($this->fk_leftmenu ? "'".$this->db->escape($this->fk_leftmenu)."'" : "null").",";
291 $sql .= " ".((int) $this->position).",";
292 $sql .= " '".$this->db->escape($this->url)."',";
293 $sql .= " '".$this->db->escape($this->target)."',";
294 $sql .= " '".$this->db->escape($this->title)."',";
295 $sql .= " '".$this->db->escape($this->prefix)."',";
296 $sql .= " '".$this->db->escape($this->langs)."',";
297 $sql .= " '".$this->db->escape($this->perms)."',";
298 $sql .= " '".$this->db->escape($this->enabled)."',";
299 $sql .= " '".$this->db->escape($this->user)."'";
300 $sql .= ")";
301
302 dol_syslog(get_class($this)."::create", LOG_DEBUG);
303 $resql = $this->db->query($sql);
304 if ($resql) {
305 $this->id = $this->db->last_insert_id($this->db->prefix()."menu");
306 dol_syslog(get_class($this)."::create record added has rowid=".((int) $this->id), LOG_DEBUG);
307
308 return $this->id;
309 } else {
310 $this->error = "Error ".$this->db->lasterror();
311 return -1;
312 }
313 } else {
314 dol_syslog(get_class($this)."::create menu entry already exists", LOG_WARNING);
315 $this->error = 'Error Menu entry ('.$this->menu_handler.','.$this->position.','.$this->url.') already exists';
316 return 0;
317 }
318 } else {
319 return -1;
320 }
321 }
322
330 public function update($user = null, $notrigger = 0)
331 {
332 //global $conf, $langs;
333
334 // Clean parameters
335 $this->menu_handler = trim($this->menu_handler);
336 $this->module = trim($this->module);
337 $this->type = trim($this->type);
338 $this->mainmenu = trim($this->mainmenu);
339 $this->leftmenu = trim($this->leftmenu);
340 $this->fk_menu = (int) $this->fk_menu;
341 $this->fk_mainmenu = trim($this->fk_mainmenu);
342 $this->fk_leftmenu = trim($this->fk_leftmenu);
343 $this->position = (int) $this->position;
344 $this->url = trim($this->url);
345 $this->target = trim($this->target);
346 $this->title = trim($this->title);
347 $this->prefix = trim($this->prefix);
348 $this->langs = trim($this->langs);
349 $this->perms = trim($this->perms);
350 $this->enabled = trim($this->enabled);
351 $this->user = (int) $this->user;
352
353 // Check parameters
354 // Put here code to add control on parameters values
355
356 // Update request
357 $sql = "UPDATE ".$this->db->prefix()."menu SET";
358 $sql .= " menu_handler='".$this->db->escape($this->menu_handler)."',";
359 $sql .= " module='".$this->db->escape($this->module)."',";
360 $sql .= " type='".$this->db->escape($this->type)."',";
361 $sql .= " mainmenu='".$this->db->escape($this->mainmenu)."',";
362 $sql .= " leftmenu='".$this->db->escape($this->leftmenu)."',";
363 $sql .= " fk_menu=".((int) $this->fk_menu).",";
364 $sql .= " fk_mainmenu=".($this->fk_mainmenu ? "'".$this->db->escape($this->fk_mainmenu)."'" : "null").",";
365 $sql .= " fk_leftmenu=".($this->fk_leftmenu ? "'".$this->db->escape($this->fk_leftmenu)."'" : "null").",";
366 $sql .= " position=".($this->position > 0 ? ((int) $this->position) : 0).",";
367 $sql .= " url='".$this->db->escape($this->url)."',";
368 $sql .= " target='".$this->db->escape($this->target)."',";
369 $sql .= " titre='".$this->db->escape($this->title)."',";
370 $sql .= " prefix='".$this->db->escape($this->prefix)."',";
371 $sql .= " langs='".$this->db->escape($this->langs)."',";
372 $sql .= " perms='".$this->db->escape($this->perms)."',";
373 $sql .= " enabled='".$this->db->escape($this->enabled)."',";
374 $sql .= " usertype='".$this->db->escape($this->user)."'";
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 .= " FROM ".$this->db->prefix()."menu as t";
421 $sql .= " WHERE t.rowid = ".((int) $id);
422
423 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
424 $resql = $this->db->query($sql);
425 if ($resql) {
426 if ($this->db->num_rows($resql)) {
427 $obj = $this->db->fetch_object($resql);
428
429 $this->id = $obj->rowid;
430
431 $this->menu_handler = $obj->menu_handler;
432 $this->entity = $obj->entity;
433 $this->module = $obj->module;
434 $this->type = $obj->type;
435 $this->mainmenu = $obj->mainmenu;
436 $this->leftmenu = $obj->leftmenu;
437 $this->fk_menu = $obj->fk_menu;
438 $this->fk_mainmenu = $obj->fk_mainmenu;
439 $this->fk_leftmenu = $obj->fk_leftmenu;
440 $this->position = $obj->position;
441 $this->url = $obj->url;
442 $this->target = $obj->target;
443 $this->title = $obj->title;
444 $this->prefix = $obj->prefix;
445 $this->langs = $obj->langs;
446 $this->perms = $obj->perms;
447 $this->enabled = str_replace("\"", "'", $obj->enabled);
448 $this->user = $obj->user;
449 $this->tms = $this->db->jdate($obj->tms);
450 }
451 $this->db->free($resql);
452
453 return 1;
454 } else {
455 $this->error = "Error ".$this->db->lasterror();
456 return -1;
457 }
458 }
459
460
467 public function delete($user)
468 {
469 //global $conf, $langs;
470
471 $sql = "DELETE FROM ".$this->db->prefix()."menu";
472 $sql .= " WHERE rowid=".((int) $this->id);
473
474 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
475 $resql = $this->db->query($sql);
476 if (!$resql) {
477 $this->error = "Error ".$this->db->lasterror();
478 return -1;
479 }
480
481 return 1;
482 }
483
484
492 public function initAsSpecimen()
493 {
494 $this->id = 0;
495
496 $this->menu_handler = 'all';
497 $this->module = 'specimen';
498 $this->type = 'top';
499 $this->mainmenu = '';
500 $this->fk_menu = '0';
501 $this->position = '';
502 $this->url = 'http://dummy';
503 $this->target = '';
504 $this->title = 'Specimen menu';
505 $this->langs = '';
506 $this->leftmenu = '';
507 $this->perms = '';
508 $this->enabled = '';
509 $this->user = '';
510 $this->tms = '';
511 }
512
513
524 public function menuTopCharger($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
525 {
526 global $langs, $user, $conf; // To export to dol_eval function
527 global $mainmenu, $leftmenu; // To export to dol_eval function
528
529 $mainmenu = $mymainmenu; // To export to dol_eval function
530 $leftmenu = $myleftmenu; // To export to dol_eval function
531
532 $newTabMenu = array();
533 foreach ($tabMenu as $val) {
534 if ($val['type'] == 'top') {
535 $newTabMenu[] = $val;
536 }
537 }
538
539 return $newTabMenu;
540 }
541
554 public function menuLeftCharger($newmenu, $mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
555 {
556 global $langs, $user, $conf; // To export to dol_eval function
557 global $mainmenu, $leftmenu; // To export to dol_eval function
558
559 $mainmenu = $mymainmenu; // To export to dol_eval function
560 $leftmenu = $myleftmenu; // To export to dol_eval function
561
562 // Detect what is top mainmenu id
563 $menutopid = '';
564 foreach ($tabMenu as $key => $val) {
565 // Define menutopid of mainmenu
566 if (empty($menutopid) && $val['type'] == 'top' && $val['mainmenu'] == $mainmenu) {
567 $menutopid = $val['rowid'];
568 break;
569 }
570 }
571
572 // We initialize newmenu with first already found menu entries
573 $this->newmenu = $newmenu;
574
575 // Now complete $this->newmenu->list to add entries found into $tabMenu that are childs of mainmenu=$menutopid, using the fk_menu link that is int (old method)
576 $this->recur($tabMenu, $menutopid, 1);
577
578 // Now complete $this->newmenu->list when fk_menu value is -1 (left menu added by modules with no top menu)
579 foreach ($tabMenu as $key => $val) {
580 if ($val['fk_menu'] == -1 && $val['fk_mainmenu'] == $mainmenu) { // We found a menu entry not linked to parent with good mainmenu
581 //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>';
582 //var_dump($this->newmenu->liste);exit;
583
584 if (empty($val['fk_leftmenu'])) {
585 $this->newmenu->add($val['url'], $val['titre'], 0, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position'], '', '', '', $val['prefix']);
586 //var_dump($this->newmenu->liste);
587 } else {
588 // Search first menu with this couple (mainmenu,leftmenu)=(fk_mainmenu,fk_leftmenu)
589 $searchlastsub = 0;
590 $lastid = 0;
591 $nextid = 0;
592 $found = 0;
593 foreach ($this->newmenu->liste as $keyparent => $valparent) {
594 //var_dump($valparent);
595 if ($searchlastsub) { // If we started to search for last submenu
596 if ($valparent['level'] >= $searchlastsub) {
597 $lastid = $keyparent;
598 }
599 if ($valparent['level'] < $searchlastsub) {
600 $nextid = $keyparent;
601 break;
602 }
603 }
604 if ($valparent['mainmenu'] == $val['fk_mainmenu'] && $valparent['leftmenu'] == $val['fk_leftmenu']) {
605 //print "We found parent: keyparent='.$keyparent.' - level=".$valparent['level'].' - '.join(',',$valparent).'<br>';
606 // Now we look to find last subelement of this parent (we add at end)
607 $searchlastsub = ($valparent['level'] + 1);
608 $lastid = $keyparent;
609 $found = 1;
610 }
611 }
612 //print 'We must insert menu entry between entry '.$lastid.' and '.$nextid.'<br>';
613 if ($found) {
614 $this->newmenu->insert($lastid, $val['url'], $val['titre'], $searchlastsub, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position'], '', '', '', $val['prefix']);
615 } else {
616 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);
617 //print "Parent menu not found !!<br>";
618 }
619 }
620 }
621 }
622
623 return $this->newmenu;
624 }
625
626
637 public function menuLoad($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
638 {
639 global $langs, $user, $conf; // To export to dol_eval function
640 global $mainmenu, $leftmenu; // To export to dol_eval function
641
642 $mainmenu = $mymainmenu; // To export to dol_eval function
643 $leftmenu = $myleftmenu; // To export to dol_eval function
644
645 $sql = "SELECT m.rowid, m.type, m.module, m.fk_menu, m.fk_mainmenu, m.fk_leftmenu, m.url, m.titre,";
646 $sql .= " m.prefix, m.langs, m.perms, m.enabled, m.target, m.mainmenu, m.leftmenu, m.position";
647 $sql .= " FROM ".$this->db->prefix()."menu as m";
648 $sql .= " WHERE m.entity IN (0,".$conf->entity.")";
649 $sql .= " AND m.menu_handler IN ('".$this->db->escape($menu_handler)."','all')";
650 if ($type_user == 0) {
651 $sql .= " AND m.usertype IN (0,2)";
652 }
653 if ($type_user == 1) {
654 $sql .= " AND m.usertype IN (1,2)";
655 }
656 $sql .= " ORDER BY m.type DESC, m.position, m.rowid";
657 //print $sql;
658
659 //dol_syslog(get_class($this)."::menuLoad mymainmenu=".$mymainmenu." myleftmenu=".$myleftmenu." type_user=".$type_user." menu_handler=".$menu_handler." tabMenu size=".count($tabMenu), LOG_DEBUG);
660 $resql = $this->db->query($sql);
661 if ($resql) {
662 $numa = $this->db->num_rows($resql);
663
664 $a = 0;
665 $b = 0;
666 while ($a < $numa) {
667 //$objm = $this->db->fetch_object($resql);
668 $menu = $this->db->fetch_array($resql);
669
670 // Define $right
671 $perms = true;
672 if (isset($menu['perms'])) {
673 $tmpcond = $menu['perms'];
674 if ($leftmenu == 'all') {
675 $tmpcond = preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/', '1==1', $tmpcond); // Force part of condition to true
676 }
677 $perms = verifCond($tmpcond);
678 //print "verifCond rowid=".$menu['rowid']." ".$tmpcond.":".$perms."<br>\n";
679 }
680
681 // Define $enabled
682 $enabled = true;
683 if (isset($menu['enabled'])) {
684 $tmpcond = $menu['enabled'];
685 if ($leftmenu == 'all') {
686 $tmpcond = preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/', '1==1', $tmpcond); // Force part of condition to true
687 }
688 $enabled = verifCond($tmpcond);
689 //var_dump($menu['type'].' - '.$menu['titre'].' - '.$menu['enabled'].' => '.$enabled);
690 }
691
692 // Define $title
693 if ($enabled) {
694 $title = $langs->trans($menu['titre']); // If $menu['titre'] start with $, a dol_eval is done.
695 //var_dump($title.'-'.$menu['titre']);
696 if ($title == $menu['titre']) { // Translation not found
697 if (!empty($menu['langs'])) { // If there is a dedicated translation file
698 //print 'Load file '.$menu['langs'].'<br>';
699 $langs->load($menu['langs']);
700 }
701
702 $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
703 $menu['titre'] = make_substitutions($menu['titre'], $substitarray);
704
705 if (preg_match("/\//", $menu['titre'])) { // To manage translation when title is string1/string2
706 $tab_titre = explode("/", $menu['titre']);
707 $title = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]);
708 } elseif (preg_match('/\|\|/', $menu['titre'])) {
709 // To manage different translation (Title||AltTitle@ConditionForAltTitle)
710 $tab_title = explode("||", $menu['titre']);
711 $alt_title = explode("@", $tab_title[1]);
712 $title_enabled = verifCond($alt_title[1]);
713 $title = ($title_enabled ? $langs->trans($alt_title[0]) : $langs->trans($tab_title[0]));
714 } else {
715 $title = $langs->trans($menu['titre']);
716 }
717 }
718 //$tmp4=microtime(true);
719 //print '>>> 3 '.($tmp4 - $tmp3).'<br>';
720
721 // We complete tabMenu
722 $tabMenu[$b]['rowid'] = $menu['rowid'];
723 $tabMenu[$b]['module'] = $menu['module'];
724 $tabMenu[$b]['fk_menu'] = $menu['fk_menu'];
725 $tabMenu[$b]['url'] = $menu['url'];
726 if (!preg_match("/^(http:\/\/|https:\/\/)/i", $tabMenu[$b]['url'])) {
727 if (preg_match('/\?/', $tabMenu[$b]['url'])) {
728 $tabMenu[$b]['url'] .= '&amp;idmenu='.$menu['rowid'];
729 } else {
730 $tabMenu[$b]['url'] .= '?idmenu='.$menu['rowid'];
731 }
732 }
733 $tabMenu[$b]['titre'] = $title;
734 $tabMenu[$b]['prefix'] = $menu['prefix'];
735 $tabMenu[$b]['target'] = $menu['target'];
736 $tabMenu[$b]['mainmenu'] = $menu['mainmenu'];
737 $tabMenu[$b]['leftmenu'] = $menu['leftmenu'];
738 $tabMenu[$b]['perms'] = $perms;
739 $tabMenu[$b]['langs'] = $menu['langs']; // Note that this should not be used, lang file should be already loaded.
740 $tabMenu[$b]['enabled'] = $enabled;
741 $tabMenu[$b]['type'] = $menu['type'];
742 $tabMenu[$b]['fk_mainmenu'] = $menu['fk_mainmenu'];
743 $tabMenu[$b]['fk_leftmenu'] = $menu['fk_leftmenu'];
744 $tabMenu[$b]['position'] = (int) $menu['position'];
745
746 $b++;
747 }
748
749 $a++;
750 }
751 $this->db->free($resql);
752
753 // Currently $tabMenu is sorted on position.
754 // 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
755 // into the leftMenuCharger later to avoid useless operations.
756
757 return 1;
758 } else {
759 dol_print_error($this->db);
760 return -1;
761 }
762 }
763
772 private function recur($tab, $pere, $level)
773 {
774 // Loop on tab array
775 $num = count($tab);
776 for ($x = 0; $x < $num; $x++) {
777 //si un element a pour pere : $pere
778 if ((($tab[$x]['fk_menu'] >= 0 && $tab[$x]['fk_menu'] == $pere)) && $tab[$x]['enabled']) {
779 $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']);
780 $this->recur($tab, $tab[$x]['rowid'], ($level + 1));
781 }
782 }
783 }
784}
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
verifCond($strToEvaluate)
Verify if condition in string is ok or not.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
rtl background position
$conf db user
Definition repair.php:125
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:121