dolibarr  16.0.5
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-2019 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 
30 class Menubase
31 {
35  public $db;
36 
40  public $error;
41 
45  public $errors = array();
46 
50  public $id;
51 
55  public $menu_handler;
56 
60  public $module;
61 
65  public $type;
66 
70  public $mainmenu;
71 
75  public $fk_menu;
76 
80  public $fk_mainmenu;
81 
85  public $fk_leftmenu;
86 
90  public $position;
91 
95  public $url;
96 
100  public $target;
101 
107  public $titre;
108 
112  public $title;
113 
117  public $prefix;
118 
122  public $langs;
123 
128  public $level;
129 
133  public $leftmenu;
134 
138  public $perms;
139 
143  public $enabled;
144 
148  public $user;
149 
153  public $tms;
154 
155 
162  public function __construct($db, $menu_handler = '')
163  {
164  $this->db = $db;
165  $this->menu_handler = $menu_handler;
166  return 1;
167  }
168 
169 
176  public function create($user = null)
177  {
178  global $conf, $langs;
179 
180  // Clean parameters
181  if (!isset($this->enabled)) {
182  $this->enabled = '1';
183  }
184  $this->menu_handler = trim((string) $this->menu_handler);
185  $this->module = trim((string) $this->module);
186  $this->type = trim((string) $this->type);
187  $this->mainmenu = trim((string) $this->mainmenu);
188  $this->leftmenu = trim((string) $this->leftmenu);
189  $this->fk_menu = (int) $this->fk_menu; // If -1, fk_mainmenu and fk_leftmenu must be defined
190  $this->fk_mainmenu = trim((string) $this->fk_mainmenu);
191  $this->fk_leftmenu = trim((string) $this->fk_leftmenu);
192  $this->position = (int) $this->position;
193  $this->url = trim((string) $this->url);
194  $this->target = trim((string) $this->target);
195  $this->title = trim((string) $this->title);
196  $this->langs = trim((string) $this->langs);
197  $this->perms = trim((string) $this->perms);
198  $this->enabled = trim((string) $this->enabled);
199  $this->user = (int) $this->user;
200  if (empty($this->position)) {
201  $this->position = 0;
202  }
203  if (!$this->level) {
204  $this->level = 0;
205  }
206 
207  // Check parameters
208  if (empty($this->menu_handler)) {
209  return -1;
210  }
211 
212  // For PGSQL, we must first found the max rowid and use it as rowid in insert because postgresql
213  // may use an already used value because its internal cursor does not increase when we do
214  // an insert with a forced id.
215  if (in_array($this->db->type, array('pgsql'))) {
216  $sql = "SELECT MAX(rowid) as maxrowid FROM ".$this->db->prefix()."menu";
217  $resqlrowid = $this->db->query($sql);
218  if ($resqlrowid) {
219  $obj = $this->db->fetch_object($resqlrowid);
220  $maxrowid = $obj->maxrowid;
221 
222  // Max rowid can be empty if there is no record yet
223  if (empty($maxrowid)) {
224  $maxrowid = 1;
225  }
226 
227  $sql = "SELECT setval('".$this->db->prefix()."menu_rowid_seq', ".($maxrowid).")";
228  //print $sql; exit;
229  $resqlrowidset = $this->db->query($sql);
230  if (!$resqlrowidset) {
231  dol_print_error($this->db);
232  }
233  } else {
234  dol_print_error($this->db);
235  }
236  }
237 
238  // Check that entry does not exists yet on key menu_handler-fk_menu-position-url-entity, to avoid errors with postgresql
239  $sql = "SELECT count(*)";
240  $sql .= " FROM ".$this->db->prefix()."menu";
241  $sql .= " WHERE menu_handler = '".$this->db->escape($this->menu_handler)."'";
242  $sql .= " AND fk_menu = ".((int) $this->fk_menu);
243  $sql .= " AND position = ".((int) $this->position);
244  $sql .= " AND url = '".$this->db->escape($this->url)."'";
245  $sql .= " AND entity = ".$conf->entity;
246 
247  $result = $this->db->query($sql);
248  if ($result) {
249  $row = $this->db->fetch_row($result);
250 
251  if ($row[0] == 0) { // If not found
252  // Insert request
253  $sql = "INSERT INTO ".$this->db->prefix()."menu(";
254  $sql .= "menu_handler,";
255  $sql .= "entity,";
256  $sql .= "module,";
257  $sql .= "type,";
258  $sql .= "mainmenu,";
259  $sql .= "leftmenu,";
260  $sql .= "fk_menu,";
261  $sql .= "fk_mainmenu,";
262  $sql .= "fk_leftmenu,";
263  $sql .= "position,";
264  $sql .= "url,";
265  $sql .= "target,";
266  $sql .= "titre,";
267  $sql .= "prefix,";
268  $sql .= "langs,";
269  $sql .= "perms,";
270  $sql .= "enabled,";
271  $sql .= "usertype";
272  $sql .= ") VALUES (";
273  $sql .= " '".$this->db->escape($this->menu_handler)."',";
274  $sql .= " '".$this->db->escape($conf->entity)."',";
275  $sql .= " '".$this->db->escape($this->module)."',";
276  $sql .= " '".$this->db->escape($this->type)."',";
277  $sql .= " ".($this->mainmenu ? "'".$this->db->escape($this->mainmenu)."'" : "''").","; // Can't be null
278  $sql .= " ".($this->leftmenu ? "'".$this->db->escape($this->leftmenu)."'" : "null").",";
279  $sql .= " ".((int) $this->fk_menu).",";
280  $sql .= " ".($this->fk_mainmenu ? "'".$this->db->escape($this->fk_mainmenu)."'" : "null").",";
281  $sql .= " ".($this->fk_leftmenu ? "'".$this->db->escape($this->fk_leftmenu)."'" : "null").",";
282  $sql .= " ".((int) $this->position).",";
283  $sql .= " '".$this->db->escape($this->url)."',";
284  $sql .= " '".$this->db->escape($this->target)."',";
285  $sql .= " '".$this->db->escape($this->title)."',";
286  $sql .= " '".$this->db->escape($this->prefix)."',";
287  $sql .= " '".$this->db->escape($this->langs)."',";
288  $sql .= " '".$this->db->escape($this->perms)."',";
289  $sql .= " '".$this->db->escape($this->enabled)."',";
290  $sql .= " '".$this->db->escape($this->user)."'";
291  $sql .= ")";
292 
293  dol_syslog(get_class($this)."::create", LOG_DEBUG);
294  $resql = $this->db->query($sql);
295  if ($resql) {
296  $this->id = $this->db->last_insert_id($this->db->prefix()."menu");
297  dol_syslog(get_class($this)."::create record added has rowid=".((int) $this->id), LOG_DEBUG);
298 
299  return $this->id;
300  } else {
301  $this->error = "Error ".$this->db->lasterror();
302  return -1;
303  }
304  } else {
305  dol_syslog(get_class($this)."::create menu entry already exists", LOG_WARNING);
306  $this->error = 'Error Menu entry already exists';
307  return 0;
308  }
309  } else {
310  return -1;
311  }
312  }
313 
321  public function update($user = null, $notrigger = 0)
322  {
323  //global $conf, $langs;
324 
325  // Clean parameters
326  $this->rowid = trim($this->rowid);
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 = $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 = '';
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 = '';
502  $this->tms = '';
503  }
504 
505 
516  public function menuTopCharger($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
517  {
518  global $langs, $user, $conf; // To export to dol_eval function
519  global $mainmenu, $leftmenu; // To export to dol_eval function
520 
521  $mainmenu = $mymainmenu; // To export to dol_eval function
522  $leftmenu = $myleftmenu; // To export to dol_eval function
523 
524  $newTabMenu = array();
525  foreach ($tabMenu as $val) {
526  if ($val['type'] == 'top') {
527  $newTabMenu[] = $val;
528  }
529  }
530 
531  return $newTabMenu;
532  }
533 
546  public function menuLeftCharger($newmenu, $mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
547  {
548  global $langs, $user, $conf; // To export to dol_eval function
549  global $mainmenu, $leftmenu; // To export to dol_eval function
550 
551  $mainmenu = $mymainmenu; // To export to dol_eval function
552  $leftmenu = $myleftmenu; // To export to dol_eval function
553 
554  // Detect what is top mainmenu id
555  $menutopid = '';
556  foreach ($tabMenu as $key => $val) {
557  // Define menutopid of mainmenu
558  if (empty($menutopid) && $val['type'] == 'top' && $val['mainmenu'] == $mainmenu) {
559  $menutopid = $val['rowid'];
560  break;
561  }
562  }
563 
564  // We initialize newmenu with first already found menu entries
565  $this->newmenu = $newmenu;
566 
567  // 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)
568  $this->recur($tabMenu, $menutopid, 1);
569 
570  // Now complete $this->newmenu->list when fk_menu value is -1 (left menu added by modules with no top menu)
571  foreach ($tabMenu as $key => $val) {
572  if ($val['fk_menu'] == -1 && $val['fk_mainmenu'] == $mainmenu) { // We found a menu entry not linked to parent with good mainmenu
573  //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>';
574  //var_dump($this->newmenu->liste);exit;
575 
576  if (empty($val['fk_leftmenu'])) {
577  $this->newmenu->add($val['url'], $val['titre'], 0, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position'], '', '', '', $val['prefix']);
578  //var_dump($this->newmenu->liste);
579  } else {
580  // Search first menu with this couple (mainmenu,leftmenu)=(fk_mainmenu,fk_leftmenu)
581  $searchlastsub = 0;
582  $lastid = 0;
583  $nextid = 0;
584  $found = 0;
585  foreach ($this->newmenu->liste as $keyparent => $valparent) {
586  //var_dump($valparent);
587  if ($searchlastsub) { // If we started to search for last submenu
588  if ($valparent['level'] >= $searchlastsub) {
589  $lastid = $keyparent;
590  }
591  if ($valparent['level'] < $searchlastsub) {
592  $nextid = $keyparent;
593  break;
594  }
595  }
596  if ($valparent['mainmenu'] == $val['fk_mainmenu'] && $valparent['leftmenu'] == $val['fk_leftmenu']) {
597  //print "We found parent: keyparent='.$keyparent.' - level=".$valparent['level'].' - '.join(',',$valparent).'<br>';
598  // Now we look to find last subelement of this parent (we add at end)
599  $searchlastsub = ($valparent['level'] + 1);
600  $lastid = $keyparent;
601  $found = 1;
602  }
603  }
604  //print 'We must insert menu entry between entry '.$lastid.' and '.$nextid.'<br>';
605  if ($found) {
606  $this->newmenu->insert($lastid, $val['url'], $val['titre'], $searchlastsub, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position'], '', '', '', $val['prefix']);
607  } else {
608  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);
609  //print "Parent menu not found !!<br>";
610  }
611  }
612  }
613  }
614 
615  return $this->newmenu;
616  }
617 
618 
629  public function menuLoad($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
630  {
631  global $langs, $user, $conf; // To export to dol_eval function
632  global $mainmenu, $leftmenu; // To export to dol_eval function
633 
634  $mainmenu = $mymainmenu; // To export to dol_eval function
635  $leftmenu = $myleftmenu; // To export to dol_eval function
636 
637  $sql = "SELECT m.rowid, m.type, m.module, m.fk_menu, m.fk_mainmenu, m.fk_leftmenu, m.url, m.titre, m.prefix, m.langs, m.perms, m.enabled, m.target, m.mainmenu, m.leftmenu, m.position";
638  $sql .= " FROM ".$this->db->prefix()."menu as m";
639  $sql .= " WHERE m.entity IN (0,".$conf->entity.")";
640  $sql .= " AND m.menu_handler IN ('".$this->db->escape($menu_handler)."','all')";
641  if ($type_user == 0) {
642  $sql .= " AND m.usertype IN (0,2)";
643  }
644  if ($type_user == 1) {
645  $sql .= " AND m.usertype IN (1,2)";
646  }
647  $sql .= " ORDER BY m.position, m.rowid";
648  //print $sql;
649 
650  //dol_syslog(get_class($this)."::menuLoad mymainmenu=".$mymainmenu." myleftmenu=".$myleftmenu." type_user=".$type_user." menu_handler=".$menu_handler." tabMenu size=".count($tabMenu)."", LOG_DEBUG);
651  $resql = $this->db->query($sql);
652  if ($resql) {
653  $numa = $this->db->num_rows($resql);
654 
655  $a = 0;
656  $b = 0;
657  while ($a < $numa) {
658  //$objm = $this->db->fetch_object($resql);
659  $menu = $this->db->fetch_array($resql);
660 
661  // Define $right
662  $perms = true;
663  if (isset($menu['perms'])) {
664  $tmpcond = $menu['perms'];
665  if ($leftmenu == 'all') {
666  $tmpcond = preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/', '1==1', $tmpcond); // Force part of condition to true
667  }
668  $perms = verifCond($tmpcond);
669  //print "verifCond rowid=".$menu['rowid']." ".$tmpcond.":".$perms."<br>\n";
670  }
671 
672  // Define $enabled
673  $enabled = true;
674  if (isset($menu['enabled'])) {
675  $tmpcond = $menu['enabled'];
676  if ($leftmenu == 'all') {
677  $tmpcond = preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/', '1==1', $tmpcond); // Force part of condition to true
678  }
679  $enabled = verifCond($tmpcond);
680  }
681 
682  // Define $title
683  if ($enabled) {
684  $title = $langs->trans($menu['titre']); // If $menu['titre'] start with $, a dol_eval is done.
685  //var_dump($title.'-'.$menu['titre']);
686  if ($title == $menu['titre']) { // Translation not found
687  if (!empty($menu['langs'])) { // If there is a dedicated translation file
688  //print 'Load file '.$menu['langs'].'<br>';
689  $langs->load($menu['langs']);
690  }
691 
692  $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
693  $menu['titre'] = make_substitutions($menu['titre'], $substitarray);
694 
695  if (preg_match("/\//", $menu['titre'])) { // To manage translation when title is string1/string2
696  $tab_titre = explode("/", $menu['titre']);
697  $title = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]);
698  } elseif (preg_match('/\|\|/', $menu['titre'])) {
699  // To manage different translation (Title||AltTitle@ConditionForAltTitle)
700  $tab_title = explode("||", $menu['titre']);
701  $alt_title = explode("@", $tab_title[1]);
702  $title_enabled = verifCond($alt_title[1]);
703  $title = ($title_enabled ? $langs->trans($alt_title[0]) : $langs->trans($tab_title[0]));
704  } else {
705  $title = $langs->trans($menu['titre']);
706  }
707  }
708  //$tmp4=microtime(true);
709  //print '>>> 3 '.($tmp4 - $tmp3).'<br>';
710 
711  // We complete tabMenu
712  $tabMenu[$b]['rowid'] = $menu['rowid'];
713  $tabMenu[$b]['module'] = $menu['module'];
714  $tabMenu[$b]['fk_menu'] = $menu['fk_menu'];
715  $tabMenu[$b]['url'] = $menu['url'];
716  if (!preg_match("/^(http:\/\/|https:\/\/)/i", $tabMenu[$b]['url'])) {
717  if (preg_match('/\?/', $tabMenu[$b]['url'])) {
718  $tabMenu[$b]['url'] .= '&amp;idmenu='.$menu['rowid'];
719  } else {
720  $tabMenu[$b]['url'] .= '?idmenu='.$menu['rowid'];
721  }
722  }
723  $tabMenu[$b]['titre'] = $title;
724  $tabMenu[$b]['prefix'] = $menu['prefix'];
725  $tabMenu[$b]['target'] = $menu['target'];
726  $tabMenu[$b]['mainmenu'] = $menu['mainmenu'];
727  $tabMenu[$b]['leftmenu'] = $menu['leftmenu'];
728  $tabMenu[$b]['perms'] = $perms;
729  $tabMenu[$b]['langs'] = $menu['langs']; // Note that this should not be used, lang file should be already loaded.
730  $tabMenu[$b]['enabled'] = $enabled;
731  $tabMenu[$b]['type'] = $menu['type'];
732  $tabMenu[$b]['fk_mainmenu'] = $menu['fk_mainmenu'];
733  $tabMenu[$b]['fk_leftmenu'] = $menu['fk_leftmenu'];
734  $tabMenu[$b]['position'] = (int) $menu['position'];
735 
736  $b++;
737  }
738 
739  $a++;
740  }
741  $this->db->free($resql);
742 
743  // Currently $tabMenu is sorted on position.
744  // 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
745  // into the leftMenuCharger later to avoid useless operations.
746 
747  return 1;
748  } else {
749  dol_print_error($this->db);
750  return -1;
751  }
752  }
753 
762  private function recur($tab, $pere, $level)
763  {
764  // Loop on tab array
765  $num = count($tab);
766  for ($x = 0; $x < $num; $x++) {
767  //si un element a pour pere : $pere
768  if ((($tab[$x]['fk_menu'] >= 0 && $tab[$x]['fk_menu'] == $pere)) && $tab[$x]['enabled']) {
769  $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']);
770  $this->recur($tab, $tab[$x]['rowid'], ($level + 1));
771  }
772  }
773  }
774 }
make_substitutions
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
Definition: functions.lib.php:7839
db
$conf db
API class for accounts.
Definition: inc.php:41
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
Menubase\fetch
fetch($id, $user=null)
Load object in memory from database.
Definition: menubase.class.php:387
Menubase\update
update($user=null, $notrigger=0)
Update menu entry into database.
Definition: menubase.class.php:321
verifCond
verifCond($strToEvaluate)
Verify if condition in string is ok or not.
Definition: functions.lib.php:8582
rowid
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
Definition: email_expire_services_to_representatives.php:79
Menubase
Class to manage menu entries.
Definition: menubase.class.php:30
Menubase\__construct
__construct($db, $menu_handler='')
Constructor.
Definition: menubase.class.php:162
Menubase\menuLoad
menuLoad($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
Load entries found in database into variable $tabMenu.
Definition: menubase.class.php:629
Menubase\recur
recur($tab, $pere, $level)
Complete this->newmenu with menu entry found in $tab.
Definition: menubase.class.php:762
Menubase\menuLeftCharger
menuLeftCharger($newmenu, $mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
Load entries found from database (and stored into $tabMenu) in $this->newmenu array.
Definition: menubase.class.php:546
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
Menubase\initAsSpecimen
initAsSpecimen()
Initialise an instance with random values.
Definition: menubase.class.php:484
Menubase\create
create($user=null)
Create menu entry into database.
Definition: menubase.class.php:176
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
Menubase\menuTopCharger
menuTopCharger($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
Load tabMenu array with top menu entries found into database.
Definition: menubase.class.php:516
user
$conf db user
Definition: repair.php:123
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119