/** * Adds menu entries * * @return int Error count (0 if OK) */ function insert_menus() { global $user; require_once DOL_DOCUMENT_ROOT . '/core/class/menubase.class.php'; $err = 0; $this->db->begin(); foreach ($this->menu as $key => $value) { $menu = new Menubase($this->db); $menu->menu_handler = 'all'; $menu->module = $this->rights_class; if (!$this->menu[$key]['fk_menu']) { $menu->fk_menu = 0; } else { $foundparent = 0; $fk_parent = $this->menu[$key]['fk_menu']; if (preg_match('/^r=/', $fk_parent)) { $fk_parent = str_replace('r=', '', $fk_parent); if (isset($this->menu[$fk_parent]['rowid'])) { $menu->fk_menu = $this->menu[$fk_parent]['rowid']; $foundparent = 1; } } elseif (preg_match('/^fk_mainmenu=([a-zA-Z0-9_]+),fk_leftmenu=([a-zA-Z0-9_]+)$/', $fk_parent, $reg)) { $menu->fk_menu = -1; $menu->fk_mainmenu = $reg[1]; $menu->fk_leftmenu = $reg[2]; $foundparent = 1; } elseif (preg_match('/^fk_mainmenu=([a-zA-Z0-9_]+)$/', $fk_parent, $reg)) { $menu->fk_menu = -1; $menu->fk_mainmenu = $reg[1]; $menu->fk_leftmenu = ''; $foundparent = 1; } if (!$foundparent) { $this->error = "ErrorBadDefinitionOfMenuArrayInModuleDescriptor"; dol_syslog(get_class($this) . "::insert_menus " . $this->error . " " . $this->menu[$key]['fk_menu'], LOG_ERR); $err++; } } $menu->type = $this->menu[$key]['type']; $menu->mainmenu = isset($this->menu[$key]['mainmenu']) ? $this->menu[$key]['mainmenu'] : (isset($menu->fk_mainmenu) ? $menu->fk_mainmenu : ''); $menu->leftmenu = isset($this->menu[$key]['leftmenu']) ? $this->menu[$key]['leftmenu'] : ''; $menu->titre = $this->menu[$key]['titre']; $menu->url = $this->menu[$key]['url']; $menu->langs = $this->menu[$key]['langs']; $menu->position = $this->menu[$key]['position']; $menu->perms = $this->menu[$key]['perms']; $menu->target = $this->menu[$key]['target']; $menu->user = $this->menu[$key]['user']; $menu->enabled = isset($this->menu[$key]['enabled']) ? $this->menu[$key]['enabled'] : 0; $menu->position = $this->menu[$key]['position']; if (!$err) { $result = $menu->create($user); // Save menu entry into table llx_menu if ($result > 0) { $this->menu[$key]['rowid'] = $result; } else { $this->error = $menu->error; dol_syslog(get_class($this) . '::insert_menus result=' . $result . " " . $this->error, LOG_ERR); $err++; break; } } } if (!$err) { $this->db->commit(); } else { dol_syslog(get_class($this) . "::insert_menus " . $this->error, LOG_ERR); $this->db->rollback(); } return $err; }
$menu->enabled = $_POST['enabled']; $menu->perms = $_POST['perms']; $menu->target = $_POST['target']; $menu->user = $_POST['user']; if (is_numeric($_POST['menuId'])) { $menu->fk_menu = $_POST['menuId']; } else { if ($_POST['type'] == 'top') { $menu->fk_menu = 0; } else { $menu->fk_menu = -1; } $menu->fk_mainmenu = $mainmenu; $menu->fk_leftmenu = $leftmenu; } $result = $menu->create($user); if ($result > 0) { header("Location: " . DOL_URL_ROOT . "/admin/menus/index.php?menu_handler=" . $_POST['menu_handler']); exit; } else { $action = 'create'; setEventMessage($menu->error, 'errors'); } } } // delete if ($action == 'confirm_delete' && $_POST["confirm"] == 'yes') { $this->db->begin(); $sql = "DELETE FROM " . MAIN_DB_PREFIX . "menu WHERE rowid = " . $_GET['menuId']; $db->query($sql); if ($result == 0) {
private function setMenu() { global $db, $langs, $conf, $user; if ($this->fk_menu <= 0) { $menu = new Menubase($db, 'all'); $menu->module = 'query'; $menu->type = 'left'; $menu->mainmenu = $menu->fk_mainmenu = $this->mainmenu; $menu->fk_leftmenu = $this->leftmenu; $menu->leftmenu = 'querymenu' . $this->getId(); $menu->fk_menu = -1; $menu->position = 500 + $this->getId(); $menu->url = $this->getUrl(); $menu->target = ''; $menu->titre = $this->title; $menu->langs = 'query.lang'; $menu->perms = $this->perms; $menu->enabled = 0; $menu->user = 2; $menu->level = 0; $res = $menu->create($user); if ($res <= 0) { var_dump($menu); exit('Erreur lors de la création du menu'); } $this->fk_menu = $menu->id; } else { $menu = new Menubase($db, 'all'); if ($menu->fetch($this->fk_menu) > 0) { $menu->mainmenu = $menu->fk_mainmenu = $this->mainmenu; $menu->fk_leftmenu = $this->leftmenu; $menu->url = $this->getUrl(); $menu->leftmenu = 'querymenu' . $this->getId(); $menu->position = 500 + $this->getId(); $menu->titre = $this->title; $menu->enabled = 0; $menu->level = 0; $menu->user = 2; $menu->update($user); } } }
/** * Insert menus entries found into $this->menu into llx_menu* * @return int Nb of errors (0 if OK) */ function insert_menus() { require_once(DOL_DOCUMENT_ROOT."/core/class/menubase.class.php"); $err=0; $this->db->begin(); //var_dump($this->menu); exit; foreach ($this->menu as $key => $value) { $menu = new Menubase($this->db); $menu->menu_handler='all'; $menu->module=$this->rights_class; if (! $this->menu[$key]['fk_menu']) { $menu->fk_menu=0; //print 'aaa'.$this->menu[$key]['fk_menu']; } else { //print 'xxx'.$this->menu[$key]['fk_menu'];exit; $foundparent=0; $fk_parent=$this->menu[$key]['fk_menu']; if (preg_match('/r=/',$fk_parent)) { $fk_parent=str_replace('r=','',$fk_parent); if (isset($this->menu[$fk_parent]['rowid'])) { $menu->fk_menu=$this->menu[$fk_parent]['rowid']; $foundparent=1; } } elseif (preg_match('/mainmenu=(.*),leftmenu=(.*)/',$fk_parent,$reg)) { $menu->fk_menu=-1; $menu->fk_mainmenu=$reg[1]; $menu->fk_leftmenu=$reg[2]; $foundparent=1; } if (! $foundparent) { $this->error="ErrorBadDefinitionOfMenuArrayInModuleDescriptor (bad value for key fk_menu)"; dol_syslog(get_class($this)."::insert_menus ".$this->error." ".$this->menu[$key]['fk_menu'], LOG_ERR); $err++; } } $menu->type=$this->menu[$key]['type']; $menu->mainmenu=$this->menu[$key]['mainmenu']; $menu->titre=$this->menu[$key]['titre']; $menu->leftmenu=isset($this->menu[$key]['leftmenu'])?$this->menu[$key]['leftmenu']:0; $menu->url=$this->menu[$key]['url']; $menu->langs=$this->menu[$key]['langs']; $menu->position=$this->menu[$key]['position']; $menu->perms=$this->menu[$key]['perms']; $menu->target=$this->menu[$key]['target']; $menu->user=$this->menu[$key]['user']; //$menu->constraint=$this->menu[$key]['constraint']; $menu->enabled=isset($this->menu[$key]['enabled'])?$this->menu[$key]['enabled']:0; if (! $err) { $result=$menu->create(); if ($result > 0) { $this->menu[$key]['rowid']=$result; } else { $this->error=$menu->error; dol_syslog('DolibarrModules::insert_menus result='.$result." ".$this->error, LOG_ERR); $err++; break; } } } if (! $err) { $this->db->commit(); } else { dol_syslog(get_class($this)."::insert_menus ".$this->error, LOG_ERR); $this->db->rollback(); } return $err; }