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