diff --git a/htdocs/admin/menus/index.php b/htdocs/admin/menus/index.php index 69696d8a892..256103ca13e 100644 --- a/htdocs/admin/menus/index.php +++ b/htdocs/admin/menus/index.php @@ -65,27 +65,6 @@ if (isset($_GET["action"]) && ($_GET["action"] == 'up')) $current=array(); $previous=array(); - // Redefine order - /*$sql = "SELECT m.rowid, m.position"; - $sql.= " FROM ".MAIN_DB_PREFIX."menu as m"; - $sql.= " WHERE m.menu_handler='".$menu_handler."'"; - $sql.= " AND m.entity = ".$conf->entity; - $sql.= " ORDER BY m.position, m.rowid"; - dol_syslog("admin/menus/index.php ".$sql); - $resql = $db->query($sql); - $num = $db->num_rows($resql); - $i = 0; - while($i < $num) - { - $obj = $db->fetch_object($resql); - $sqlupdate ="UPDATE ".MAIN_DB_PREFIX."menu as m SET position=".($i+1); - $sqlupdate.=" WHERE m.menu_handler='".$menu_handler."'"; - $sqlupdate.=" AND m.entity = ".$conf->entity; - $sqlupdate.=" AND rowid=".$obj->rowid; - $resql2 = $db->query($sqlupdate); - $i++; - }*/ - // Get current position $sql = "SELECT m.rowid, m.position, m.type, m.fk_menu"; $sql.= " FROM ".MAIN_DB_PREFIX."menu as m"; @@ -223,8 +202,9 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') $html=new Form($db); $htmladmin=new FormAdmin($db); +$arrayofjs=array('/admin/menus/menu.js.php?lang='.$langs->defaultlang); -llxHeader(); +llxHeader('',$langs->trans("Menus"),'','',0,0,$arrayofjs); print_fiche_titre($langs->trans("Menus"),'','setup'); @@ -292,8 +272,6 @@ $rangLast = 0; $idLast = -1; if ($conf->use_javascript_ajax) { - tree_addjs(); - /*-------------------- MAIN ----------------------- tableau des elements de l'arbre: c'est un tableau a 2 dimensions. @@ -315,6 +293,7 @@ if ($conf->use_javascript_ajax) $sql.= " FROM ".MAIN_DB_PREFIX."menu as m"; $sql.= " WHERE menu_handler = '".$menu_handler."'"; $sql.= " AND entity = ".$conf->entity; + $sql.= " AND fk_menu >= 0"; $sql.= " ORDER BY m.position, m.rowid"; // Order is position then rowid (because we need a sort criteria when position is same) $res = $db->query($sql); diff --git a/htdocs/core/class/menubase.class.php b/htdocs/core/class/menubase.class.php index 20ea6ec8518..c29c08ce151 100644 --- a/htdocs/core/class/menubase.class.php +++ b/htdocs/core/class/menubase.class.php @@ -72,9 +72,9 @@ class Menubase /** - * \brief Create menu entry into database - * \param user User that create - * \return int <0 si ko, >0 si ok + * Create menu entry into database + * @param user User that create + * @return int <0 if KO, Id of record if OK */ function create($user) { @@ -85,14 +85,15 @@ class Menubase $this->module=trim($this->module); $this->type=trim($this->type); $this->mainmenu=trim($this->mainmenu); + $this->leftmenu=trim($this->leftmenu); $this->fk_menu=trim($this->fk_menu); + $this->fk_mainmenu=trim($this->fk_mainmenu); + $this->fk_leftmenu=trim($this->fk_leftmenu); $this->position=trim($this->position); $this->url=trim($this->url); $this->target=trim($this->target); $this->titre=trim($this->titre); $this->langs=trim($this->langs); - $this->level=trim($this->level); - $this->leftmenu=trim($this->leftmenu); $this->perms=trim($this->perms); $this->enabled=trim($this->enabled); $this->user=trim($this->user); @@ -115,14 +116,15 @@ class Menubase $sql.= "module,"; $sql.= "type,"; $sql.= "mainmenu,"; + $sql.= "leftmenu,"; $sql.= "fk_menu,"; + $sql.= "fk_mainmenu,"; + $sql.= "fk_leftmenu,"; $sql.= "position,"; $sql.= "url,"; $sql.= "target,"; $sql.= "titre,"; $sql.= "langs,"; - $sql.= "level,"; - $sql.= "leftmenu,"; $sql.= "perms,"; $sql.= "enabled,"; $sql.= "usertype"; @@ -132,14 +134,15 @@ class Menubase $sql.= " '".$this->module."',"; $sql.= " '".$this->type."',"; $sql.= " '".$this->mainmenu."',"; + $sql.= " '".$this->leftmenu."',"; $sql.= " '".$this->fk_menu."',"; + $sql.= " ".($this->fk_mainmenu?"'".$this->fk_mainmenu."'":"null").","; + $sql.= " ".($this->fk_leftmenu?"'".$this->fk_leftmenu."'":"null").","; $sql.= " '".$this->position."',"; $sql.= " '".$this->url."',"; $sql.= " '".$this->target."',"; $sql.= " '".$this->titre."',"; $sql.= " '".$this->langs."',"; - $sql.= " '".$this->level."',"; - $sql.= " '".$this->leftmenu."',"; $sql.= " '".$this->perms."',"; $sql.= " '".$this->enabled."',"; $sql.= " '".$this->user."'"; @@ -162,11 +165,11 @@ class Menubase } } - /* - * \brief Update database - * \param user User that modify - * \param notrigger 0=no, 1=yes (no update trigger) - * \return int <0 if KO, >0 if OK + /** + * Update menu entry into database + * @param user User that modify + * @param notrigger 0=no, 1=yes (no update trigger) + * @return int <0 if KO, >0 if OK */ function update($user=0, $notrigger=0) { @@ -178,14 +181,15 @@ class Menubase $this->module=trim($this->module); $this->type=trim($this->type); $this->mainmenu=trim($this->mainmenu); + $this->leftmenu=trim($this->leftmenu); $this->fk_menu=trim($this->fk_menu); + $this->fk_mainmenu=trim($this->fk_mainmenu); + $this->fk_leftmenu=trim($this->fk_leftmenu); $this->position=trim($this->position); $this->url=trim($this->url); $this->target=trim($this->target); $this->titre=trim($this->titre); $this->langs=trim($this->langs); - $this->level=trim($this->level); - $this->leftmenu=trim($this->leftmenu); $this->perms=trim($this->perms); $this->enabled=trim($this->enabled); $this->user=trim($this->user); @@ -199,14 +203,15 @@ class Menubase $sql.= " module='".$this->db->escape($this->module)."',"; $sql.= " type='".$this->type."',"; $sql.= " mainmenu='".$this->db->escape($this->mainmenu)."',"; + $sql.= " leftmenu='".$this->db->escape($this->leftmenu)."',"; $sql.= " fk_menu='".$this->fk_menu."',"; + $sql.= " fk_mainmenu=".($this->fk_mainmenu?"'".$this->fk_mainmenu."'":"null").","; + $sql.= " fk_leftmenu=".($this->fk_leftmenu?"'".$this->fk_leftmenu."'":"null").","; $sql.= " position='".$this->position."',"; $sql.= " url='".$this->db->escape($this->url)."',"; $sql.= " target='".$this->db->escape($this->target)."',"; $sql.= " titre='".$this->db->escape($this->titre)."',"; $sql.= " langs='".$this->db->escape($this->langs)."',"; - $sql.= " level='".$this->level."',"; - $sql.= " leftmenu='".$this->db->escape($this->leftmenu)."',"; $sql.= " perms='".$this->db->escape($this->perms)."',"; $sql.= " enabled='".$this->db->escape($this->enabled)."',"; $sql.= " usertype='".$this->user."'"; @@ -242,14 +247,13 @@ class Menubase $sql.= " t.module,"; $sql.= " t.type,"; $sql.= " t.mainmenu,"; + $sql.= " t.leftmenu,"; $sql.= " t.fk_menu,"; $sql.= " t.position,"; $sql.= " t.url,"; $sql.= " t.target,"; $sql.= " t.titre,"; $sql.= " t.langs,"; - $sql.= " t.level,"; - $sql.= " t.leftmenu,"; $sql.= " t.perms,"; $sql.= " t.enabled,"; $sql.= " t.usertype as user,"; @@ -272,14 +276,13 @@ class Menubase $this->module = $obj->module; $this->type = $obj->type; $this->mainmenu = $obj->mainmenu; + $this->leftmenu = $obj->leftmenu; $this->fk_menu = $obj->fk_menu; $this->position = $obj->position; $this->url = $obj->url; $this->target = $obj->target; $this->titre = $obj->titre; $this->langs = $obj->langs; - $this->level = $obj->level; - $this->leftmenu = $obj->leftmenu; $this->perms = $obj->perms; $this->enabled = str_replace("\"","'",$obj->enabled); $this->user = $obj->user; @@ -324,8 +327,8 @@ class Menubase /** - * \brief Initialise object with example values - * \remarks id must be 0 if object instance is a specimen. + * Initialise object with example values + * Id must be 0 if object instance is a specimen. */ function initAsSpecimen() { @@ -391,41 +394,6 @@ class Menubase } } - /** - * Return all values of mainmenu where leftmenu defined - * in pre.inc.php must be overwritten completely by dynamic menu. - * - * @return array - */ - function listeMainmenu() - { - global $conf; - - $overwritemenufor=array(); - - $sql = "SELECT DISTINCT m.mainmenu"; - $sql.= " FROM " . MAIN_DB_PREFIX . "menu as m"; - $sql.= " WHERE m.menu_handler in ('".$this->menu_handler."','all')"; - $sql.= " AND m.entity = ".$conf->entity; - $sql.= " AND m.leftmenu != '0'"; // leftmenu exists in database so pre.inc.php must be overwritten - - //print $sql; - $res = $this->db->query($sql); - if ($res) - { - while ($menu = $this->db->fetch_array($res)) - { - if ($menu['mainmenu']) $overwritemenufor[] = $menu['mainmenu']; - } - } - else - { - dol_print_error($this->db); - } - - return $overwritemenufor; - } - /** * Load tabMenu array * @param type_user 0=Internal,1=External,2=All diff --git a/htdocs/includes/modules/DolibarrModules.class.php b/htdocs/includes/modules/DolibarrModules.class.php index 70f3c0ea51a..a453b6b0ba1 100644 --- a/htdocs/includes/modules/DolibarrModules.class.php +++ b/htdocs/includes/modules/DolibarrModules.class.php @@ -1036,8 +1036,8 @@ class DolibarrModules /** - * \brief Insert menus entries into llx_menu* - * \return int Nb of errors (0 if OK) + * Insert menus entries found into $this->menu into llx_menu* + * @return int Nb of errors (0 if OK) */ function insert_menus() { @@ -1063,15 +1063,27 @@ class DolibarrModules else { //print 'xxx'.$this->menu[$key]['fk_menu'];exit; - $numparent=$this->menu[$key]['fk_menu']; - $numparent=str_replace('r=','',$numparent); - if (isset($this->menu[$numparent]['rowid'])) + $foundparent=0; + $fk_parent=$this->menu[$key]['fk_menu']; + if (preg_match('/r=/',$fk_parent)) { - $menu->fk_menu=$this->menu[$numparent]['rowid']; + $fk_parent=str_replace('r=','',$fk_parent); + if (isset($this->menu[$fk_parent]['rowid'])) + { + $menu->fk_menu=$this->menu[$fk_parent]['rowid']; + $foundparent=1; + } } - else + elseif (preg_match('/mainmenu=(.*),leftmenu=(.*)/',$fk_parent,$reg)) { - $this->error="BadDefinitionOfMenuArrayInModuleDescriptor"; + $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("DolibarrModules::insert_menus ".$this->error." ".$this->menu[$key]['fk_menu'], LOG_ERR); $err++; } diff --git a/htdocs/install/mysql/migration/3.0.0-3.1.0.sql b/htdocs/install/mysql/migration/3.0.0-3.1.0.sql index 6cd9ab70e0f..fa8f4e83ba5 100755 --- a/htdocs/install/mysql/migration/3.0.0-3.1.0.sql +++ b/htdocs/install/mysql/migration/3.0.0-3.1.0.sql @@ -43,7 +43,12 @@ ALTER TABLE llx_societe ADD COLUMN fk_currency integer DEFAULT 0 AFTER fk_forme_ ALTER TABLE llx_societe_remise MODIFY remise_client double(6,3) DEFAULT 0 NOT NULL; -create table llx_c_availability +ALTER TABLE llx_menu ADD COLUMN fk_mainmenu varchar(16) after fk_menu; +ALTER TABLE llx_menu ADD COLUMN fk_leftmenu varchar(16) after fk_menu; +ALTER TABLE llx_menu MODIFY leftmenu varchar(100) NULL; + + +CREATE TABLE llx_c_availability ( rowid integer AUTO_INCREMENT PRIMARY KEY, code varchar(30) NOT NULL, @@ -55,7 +60,9 @@ create table llx_c_availability ALTER TABLE llx_propal ADD COLUMN fk_availability integer DEFAULT 0 AFTER fk_adresse_livraison; ALTER TABLE llx_propal CHANGE COLUMN delivery fk_availability integer DEFAULT 0; ALTER TABLE llx_availability CHANGE COLUMN libelle label varchar(60) NOT NULL; -INSERT INTO llx_c_availability (rowid,code,label,active) VALUES (1, 'DSP', 'Disponible', 1); -INSERT INTO llx_c_availability (rowid,code,label,active) VALUES (2, 'USM', 'Une semaine', 1); -INSERT INTO llx_c_availability (rowid,code,label,active) VALUES (3, 'DSM', 'Deux semaines', 1); -INSERT INTO llx_c_availability (rowid,code,label,active) VALUES (4, 'TSM', 'Trois semaines', 1); + +INSERT INTO llx_c_availability (rowid,code,label,active) VALUES (1, 'AV_NOW', 'Immediate', 1); +INSERT INTO llx_c_availability (rowid,code,label,active) VALUES (2, 'AV_1W', 'One week', 1); +INSERT INTO llx_c_availability (rowid,code,label,active) VALUES (3, 'AV_2W', 'Two weeks', 1); +INSERT INTO llx_c_availability (rowid,code,label,active) VALUES (4, 'AV_3W', 'Three weeks', 1); + diff --git a/htdocs/install/mysql/tables/llx_menu.sql b/htdocs/install/mysql/tables/llx_menu.sql index 0bbc733895f..663adaffe60 100644 --- a/htdocs/install/mysql/tables/llx_menu.sql +++ b/htdocs/install/mysql/tables/llx_menu.sql @@ -29,14 +29,16 @@ CREATE TABLE llx_menu module varchar(64), -- Module name if record is added by a module type varchar(4) NOT NULL, -- Menu top or left mainmenu varchar(100) NOT NULL, -- Name family/module (home, companies, ...) - fk_menu integer NOT NULL, -- 0 or Id of mother menu line + leftmenu varchar(100) NULL, -- Name family/module for left menu (setup, info, ...) + fk_menu integer NOT NULL, -- 0 or Id of mother menu line, or -1 if we use fk_mainmenu and fk_leftmenu + fk_mainmenu varchar(16), -- + fk_leftmenu varchar(16), -- position integer NOT NULL, -- Sort order of entry url varchar(255) NOT NULL, -- Relative (or absolute) url to go target varchar(100) NULL, -- Target of Url link titre varchar(255) NOT NULL, -- Key for menu translation langs varchar(100), -- Lang file to load for translation - level smallint, -- Used by auguria menu only. Do not use. - leftmenu varchar(1) NULL default '1', -- Say if left menu defined in pre.inc.php and used by top menu must be overwritten by dynamic databse menu (1=yes by default) + level smallint, -- Deprecated. Not used. perms varchar(255), -- Condition to show enabled or disabled enabled varchar(255) NULL default '1', -- Condition to show or hide usertype integer NOT NULL default '0', -- 0 if menu for all users, 1 for external only, 2 for internal only diff --git a/htdocs/lib/treeview.lib.php b/htdocs/lib/treeview.lib.php index bbfab1a99ec..f8e5fc09f09 100644 --- a/htdocs/lib/treeview.lib.php +++ b/htdocs/lib/treeview.lib.php @@ -139,20 +139,12 @@ function tree_showpad(&$fulltree,$key,$selected=0) -// ------------------------------- Used by enu editor ----------------- +// ------------------------------- Used by menu editor ----------------- /** - * \brief Ad javascript tree functions - */ -function tree_addjs() -{ - global $langs; - print ''; -} - - -/* cette fonction gere le decallage des elements - suivant leur position dans l'arborescence + * Show an element with correct offset + * @param $tab Array of all elements + * @param $rang Level of offset */ function tree_showline($tab,$rang) { @@ -220,10 +212,11 @@ function tree_showline($tab,$rang) } -/*fonction r�cursive d'affichage de l'arbre - $tab :tableau des �l�ments - $pere :index de l'�l�ment courant - $rang :d�callage de l'�l�ment +/** + * Recursive function to output menu tree + * @param $tab Array of elements + * @param $pere Id of parent + * @param $rang Level of element */ function tree_recur($tab,$pere,$rang) { @@ -232,17 +225,16 @@ function tree_recur($tab,$pere,$rang) if ($rang > 10) return; // Protection contre boucle infinie //ballayage du tableau - for ($x=0;$x