dolibarr  19.0.0-dev
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 $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  return 1;
176  }
177 
178 
185  public function create($user = null)
186  {
187  global $conf, $langs;
188 
189  // Clean parameters
190  if (!isset($this->enabled)) {
191  $this->enabled = '1';
192  }
193  $this->entity = (isset($this->entity) && (int) $this->entity >= 0 ? (int) $this->entity : $conf->entity);
194  $this->menu_handler = trim((string) $this->menu_handler);
195  $this->module = trim((string) $this->module);
196  $this->type = trim((string) $this->type);
197  $this->mainmenu = trim((string) $this->mainmenu);
198  $this->leftmenu = trim((string) $this->leftmenu);
199  $this->fk_menu = (int) $this->fk_menu; // If -1, fk_mainmenu and fk_leftmenu must be defined
200  $this->fk_mainmenu = trim((string) $this->fk_mainmenu);
201  $this->fk_leftmenu = trim((string) $this->fk_leftmenu);
202  $this->position = (int) $this->position;
203  $this->url = trim((string) $this->url);
204  $this->target = trim((string) $this->target);
205  $this->title = trim((string) $this->title);
206  $this->langs = trim((string) $this->langs);
207  $this->perms = trim((string) $this->perms);
208  $this->enabled = trim((string) $this->enabled);
209  $this->user = (int) $this->user;
210  if (empty($this->position)) {
211  $this->position = 0;
212  }
213  if (!$this->level) {
214  $this->level = 0;
215  }
216 
217  // Check parameters
218  if (empty($this->menu_handler)) {
219  return -1;
220  }
221 
222  // For PGSQL, we must first found the max rowid and use it as rowid in insert because postgresql
223  // may use an already used value because its internal cursor does not increase when we do
224  // an insert with a forced id.
225  if (in_array($this->db->type, array('pgsql'))) {
226  $sql = "SELECT MAX(rowid) as maxrowid FROM ".$this->db->prefix()."menu";
227  $resqlrowid = $this->db->query($sql);
228  if ($resqlrowid) {
229  $obj = $this->db->fetch_object($resqlrowid);
230  $maxrowid = $obj->maxrowid;
231 
232  // Max rowid can be empty if there is no record yet
233  if (empty($maxrowid)) {
234  $maxrowid = 1;
235  }
236 
237  $sql = "SELECT setval('".$this->db->prefix()."menu_rowid_seq', ".($maxrowid).")";
238  //print $sql; exit;
239  $resqlrowidset = $this->db->query($sql);
240  if (!$resqlrowidset) {
241  dol_print_error($this->db);
242  }
243  } else {
244  dol_print_error($this->db);
245  }
246  }
247 
248  // Check that entry does not exists yet on key menu_handler-fk_menu-position-url-entity, to avoid errors with postgresql
249  $sql = "SELECT count(*)";
250  $sql .= " FROM ".$this->db->prefix()."menu";
251  $sql .= " WHERE menu_handler = '".$this->db->escape($this->menu_handler)."'";
252  $sql .= " AND fk_menu = ".((int) $this->fk_menu);
253  $sql .= " AND position = ".((int) $this->position);
254  $sql .= " AND url = '".$this->db->escape($this->url)."'";
255  $sql .= " AND entity IN (0, ".$conf->entity.")";
256 
257  $result = $this->db->query($sql);
258  if ($result) {
259  $row = $this->db->fetch_row($result);
260 
261  if ($row[0] == 0) { // If not found
262  // Insert request
263  $sql = "INSERT INTO ".$this->db->prefix()."menu(";
264  $sql .= "menu_handler,";
265  $sql .= "entity,";
266  $sql .= "module,";
267  $sql .= "type,";
268  $sql .= "mainmenu,";
269  $sql .= "leftmenu,";
270  $sql .= "fk_menu,";
271  $sql .= "fk_mainmenu,";
272  $sql .= "fk_leftmenu,";
273  $sql .= "position,";
274  $sql .= "url,";
275  $sql .= "target,";
276  $sql .= "titre,";
277  $sql .= "prefix,";
278  $sql .= "langs,";
279  $sql .= "perms,";
280  $sql .= "enabled,";
281  $sql .= "usertype";
282  $sql .= ") VALUES (";
283  $sql .= " '".$this->db->escape($this->menu_handler)."',";
284  $sql .= " '".$this->db->escape($this->entity)."',";
285  $sql .= " '".$this->db->escape($this->module)."',";
286  $sql .= " '".$this->db->escape($this->type)."',";
287  $sql .= " ".($this->mainmenu ? "'".$this->db->escape($this->mainmenu)."'" : "''").","; // Can't be null
288  $sql .= " ".($this->leftmenu ? "'".$this->db->escape($this->leftmenu)."'" : "null").",";
289  $sql .= " ".((int) $this->fk_menu).",";
290  $sql .= " ".($this->fk_mainmenu ? "'".$this->db->escape($this->fk_mainmenu)."'" : "null").",";
291  $sql .= " ".($this->fk_leftmenu ? "'".$this->db->escape($this->fk_leftmenu)."'" : "null").",";
292  $sql .= " ".((int) $this->position).",";
293  $sql .= " '".$this->db->escape($this->url)."',";
294  $sql .= " '".$this->db->escape($this->target)."',";
295  $sql .= " '".$this->db->escape($this->title)."',";
296  $sql .= " '".$this->db->escape($this->prefix)."',";
297  $sql .= " '".$this->db->escape($this->langs)."',";
298  $sql .= " '".$this->db->escape($this->perms)."',";
299  $sql .= " '".$this->db->escape($this->enabled)."',";
300  $sql .= " '".$this->db->escape($this->user)."'";
301  $sql .= ")";
302 
303  dol_syslog(get_class($this)."::create", LOG_DEBUG);
304  $resql = $this->db->query($sql);
305  if ($resql) {
306  $this->id = $this->db->last_insert_id($this->db->prefix()."menu");
307  dol_syslog(get_class($this)."::create record added has rowid=".((int) $this->id), LOG_DEBUG);
308 
309  return $this->id;
310  } else {
311  $this->error = "Error ".$this->db->lasterror();
312  return -1;
313  }
314  } else {
315  dol_syslog(get_class($this)."::create menu entry already exists", LOG_WARNING);
316  $this->error = 'Error Menu entry ('.$this->menu_handler.','.$this->position.','.$this->url.') already exists';
317  return 0;
318  }
319  } else {
320  return -1;
321  }
322  }
323 
331  public function update($user = null, $notrigger = 0)
332  {
333  //global $conf, $langs;
334 
335  // Clean parameters
336  $this->rowid = trim($this->rowid);
337  $this->menu_handler = trim($this->menu_handler);
338  $this->module = trim($this->module);
339  $this->type = trim($this->type);
340  $this->mainmenu = trim($this->mainmenu);
341  $this->leftmenu = trim($this->leftmenu);
342  $this->fk_menu = (int) $this->fk_menu;
343  $this->fk_mainmenu = trim($this->fk_mainmenu);
344  $this->fk_leftmenu = trim($this->fk_leftmenu);
345  $this->position = (int) $this->position;
346  $this->url = trim($this->url);
347  $this->target = trim($this->target);
348  $this->title = trim($this->title);
349  $this->prefix = trim($this->prefix);
350  $this->langs = trim($this->langs);
351  $this->perms = trim($this->perms);
352  $this->enabled = trim($this->enabled);
353  $this->user = (int) $this->user;
354 
355  // Check parameters
356  // Put here code to add control on parameters values
357 
358  // Update request
359  $sql = "UPDATE ".$this->db->prefix()."menu SET";
360  $sql .= " menu_handler='".$this->db->escape($this->menu_handler)."',";
361  $sql .= " module='".$this->db->escape($this->module)."',";
362  $sql .= " type='".$this->db->escape($this->type)."',";
363  $sql .= " mainmenu='".$this->db->escape($this->mainmenu)."',";
364  $sql .= " leftmenu='".$this->db->escape($this->leftmenu)."',";
365  $sql .= " fk_menu=".((int) $this->fk_menu).",";
366  $sql .= " fk_mainmenu=".($this->fk_mainmenu ? "'".$this->db->escape($this->fk_mainmenu)."'" : "null").",";
367  $sql .= " fk_leftmenu=".($this->fk_leftmenu ? "'".$this->db->escape($this->fk_leftmenu)."'" : "null").",";
368  $sql .= " position=".($this->position > 0 ? ((int) $this->position) : 0).",";
369  $sql .= " url='".$this->db->escape($this->url)."',";
370  $sql .= " target='".$this->db->escape($this->target)."',";
371  $sql .= " titre='".$this->db->escape($this->title)."',";
372  $sql .= " prefix='".$this->db->escape($this->prefix)."',";
373  $sql .= " langs='".$this->db->escape($this->langs)."',";
374  $sql .= " perms='".$this->db->escape($this->perms)."',";
375  $sql .= " enabled='".$this->db->escape($this->enabled)."',";
376  $sql .= " usertype='".$this->db->escape($this->user)."'";
377  $sql .= " WHERE rowid=".((int) $this->id);
378 
379  dol_syslog(get_class($this)."::update", LOG_DEBUG);
380  $resql = $this->db->query($sql);
381  if (!$resql) {
382  $this->error = "Error ".$this->db->lasterror();
383  return -1;
384  }
385 
386  return 1;
387  }
388 
389 
397  public function fetch($id, $user = null)
398  {
399  //global $langs;
400 
401  $sql = "SELECT";
402  $sql .= " t.rowid,";
403  $sql .= " t.menu_handler,";
404  $sql .= " t.entity,";
405  $sql .= " t.module,";
406  $sql .= " t.type,";
407  $sql .= " t.mainmenu,";
408  $sql .= " t.leftmenu,";
409  $sql .= " t.fk_menu,";
410  $sql .= " t.fk_mainmenu,";
411  $sql .= " t.fk_leftmenu,";
412  $sql .= " t.position,";
413  $sql .= " t.url,";
414  $sql .= " t.target,";
415  $sql .= " t.titre as title,";
416  $sql .= " t.prefix,";
417  $sql .= " t.langs,";
418  $sql .= " t.perms,";
419  $sql .= " t.enabled,";
420  $sql .= " t.usertype as user,";
421  $sql .= " t.tms";
422  $sql .= " FROM ".$this->db->prefix()."menu as t";
423  $sql .= " WHERE t.rowid = ".((int) $id);
424 
425  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
426  $resql = $this->db->query($sql);
427  if ($resql) {
428  if ($this->db->num_rows($resql)) {
429  $obj = $this->db->fetch_object($resql);
430 
431  $this->id = $obj->rowid;
432 
433  $this->menu_handler = $obj->menu_handler;
434  $this->entity = $obj->entity;
435  $this->module = $obj->module;
436  $this->type = $obj->type;
437  $this->mainmenu = $obj->mainmenu;
438  $this->leftmenu = $obj->leftmenu;
439  $this->fk_menu = $obj->fk_menu;
440  $this->fk_mainmenu = $obj->fk_mainmenu;
441  $this->fk_leftmenu = $obj->fk_leftmenu;
442  $this->position = $obj->position;
443  $this->url = $obj->url;
444  $this->target = $obj->target;
445  $this->title = $obj->title;
446  $this->prefix = $obj->prefix;
447  $this->langs = $obj->langs;
448  $this->perms = $obj->perms;
449  $this->enabled = str_replace("\"", "'", $obj->enabled);
450  $this->user = $obj->user;
451  $this->tms = $this->db->jdate($obj->tms);
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 = '';
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 = '';
512  $this->tms = '';
513  }
514 
515 
526  public function menuTopCharger($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
527  {
528  global $langs, $user, $conf; // To export to dol_eval function
529  global $mainmenu, $leftmenu; // To export to dol_eval function
530 
531  $mainmenu = $mymainmenu; // To export to dol_eval function
532  $leftmenu = $myleftmenu; // To export to dol_eval function
533 
534  $newTabMenu = array();
535  foreach ($tabMenu as $val) {
536  if ($val['type'] == 'top') {
537  $newTabMenu[] = $val;
538  }
539  }
540 
541  return $newTabMenu;
542  }
543 
556  public function menuLeftCharger($newmenu, $mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
557  {
558  global $langs, $user, $conf; // To export to dol_eval function
559  global $mainmenu, $leftmenu; // To export to dol_eval function
560 
561  $mainmenu = $mymainmenu; // To export to dol_eval function
562  $leftmenu = $myleftmenu; // To export to dol_eval function
563 
564  // Detect what is top mainmenu id
565  $menutopid = '';
566  foreach ($tabMenu as $key => $val) {
567  // Define menutopid of mainmenu
568  if (empty($menutopid) && $val['type'] == 'top' && $val['mainmenu'] == $mainmenu) {
569  $menutopid = $val['rowid'];
570  break;
571  }
572  }
573 
574  // We initialize newmenu with first already found menu entries
575  $this->newmenu = $newmenu;
576 
577  // 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)
578  $this->recur($tabMenu, $menutopid, 1);
579 
580  // Now complete $this->newmenu->list when fk_menu value is -1 (left menu added by modules with no top menu)
581  foreach ($tabMenu as $key => $val) {
582  if ($val['fk_menu'] == -1 && $val['fk_mainmenu'] == $mainmenu) { // We found a menu entry not linked to parent with good mainmenu
583  //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>';
584  //var_dump($this->newmenu->liste);exit;
585 
586  if (empty($val['fk_leftmenu'])) {
587  $this->newmenu->add($val['url'], $val['titre'], 0, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position'], '', '', '', $val['prefix']);
588  //var_dump($this->newmenu->liste);
589  } else {
590  // Search first menu with this couple (mainmenu,leftmenu)=(fk_mainmenu,fk_leftmenu)
591  $searchlastsub = 0;
592  $lastid = 0;
593  $nextid = 0;
594  $found = 0;
595  foreach ($this->newmenu->liste as $keyparent => $valparent) {
596  //var_dump($valparent);
597  if ($searchlastsub) { // If we started to search for last submenu
598  if ($valparent['level'] >= $searchlastsub) {
599  $lastid = $keyparent;
600  }
601  if ($valparent['level'] < $searchlastsub) {
602  $nextid = $keyparent;
603  break;
604  }
605  }
606  if ($valparent['mainmenu'] == $val['fk_mainmenu'] && $valparent['leftmenu'] == $val['fk_leftmenu']) {
607  //print "We found parent: keyparent='.$keyparent.' - level=".$valparent['level'].' - '.join(',',$valparent).'<br>';
608  // Now we look to find last subelement of this parent (we add at end)
609  $searchlastsub = ($valparent['level'] + 1);
610  $lastid = $keyparent;
611  $found = 1;
612  }
613  }
614  //print 'We must insert menu entry between entry '.$lastid.' and '.$nextid.'<br>';
615  if ($found) {
616  $this->newmenu->insert($lastid, $val['url'], $val['titre'], $searchlastsub, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position'], '', '', '', $val['prefix']);
617  } else {
618  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);
619  //print "Parent menu not found !!<br>";
620  }
621  }
622  }
623  }
624 
625  return $this->newmenu;
626  }
627 
628 
639  public function menuLoad($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
640  {
641  global $langs, $user, $conf; // To export to dol_eval function
642  global $mainmenu, $leftmenu; // To export to dol_eval function
643 
644  $mainmenu = $mymainmenu; // To export to dol_eval function
645  $leftmenu = $myleftmenu; // To export to dol_eval function
646 
647  $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";
648  $sql .= " FROM ".$this->db->prefix()."menu as m";
649  $sql .= " WHERE m.entity IN (0,".$conf->entity.")";
650  $sql .= " AND m.menu_handler IN ('".$this->db->escape($menu_handler)."','all')";
651  if ($type_user == 0) {
652  $sql .= " AND m.usertype IN (0,2)";
653  }
654  if ($type_user == 1) {
655  $sql .= " AND m.usertype IN (1,2)";
656  }
657  $sql .= " ORDER BY m.position, m.rowid";
658  //print $sql;
659 
660  //dol_syslog(get_class($this)."::menuLoad mymainmenu=".$mymainmenu." myleftmenu=".$myleftmenu." type_user=".$type_user." menu_handler=".$menu_handler." tabMenu size=".count($tabMenu), LOG_DEBUG);
661  $resql = $this->db->query($sql);
662  if ($resql) {
663  $numa = $this->db->num_rows($resql);
664 
665  $a = 0;
666  $b = 0;
667  while ($a < $numa) {
668  //$objm = $this->db->fetch_object($resql);
669  $menu = $this->db->fetch_array($resql);
670 
671  // Define $right
672  $perms = true;
673  if (isset($menu['perms'])) {
674  $tmpcond = $menu['perms'];
675  if ($leftmenu == 'all') {
676  $tmpcond = preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/', '1==1', $tmpcond); // Force part of condition to true
677  }
678  $perms = verifCond($tmpcond);
679  //print "verifCond rowid=".$menu['rowid']." ".$tmpcond.":".$perms."<br>\n";
680  }
681 
682  // Define $enabled
683  $enabled = true;
684  if (isset($menu['enabled'])) {
685  $tmpcond = $menu['enabled'];
686  if ($leftmenu == 'all') {
687  $tmpcond = preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/', '1==1', $tmpcond); // Force part of condition to true
688  }
689  $enabled = verifCond($tmpcond);
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.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
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
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:120
$conf db user
Definition: repair.php:124