From 62971614d09d48ad1342142f262559cbee54f181 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 20 Apr 2009 21:10:00 +0000 Subject: [PATCH] Cancel new feature add to get back a stable version for 2.6 --- dev/skeletons/modMyModule.class.php | 3 +- htdocs/admin/menus/edit.php | 43 ++++++----- htdocs/core/menubase.class.php | 109 ---------------------------- 3 files changed, 27 insertions(+), 128 deletions(-) diff --git a/dev/skeletons/modMyModule.class.php b/dev/skeletons/modMyModule.class.php index 2438b6aaa21..29bfb516dd4 100644 --- a/dev/skeletons/modMyModule.class.php +++ b/dev/skeletons/modMyModule.class.php @@ -146,8 +146,7 @@ class modMyModule extends DolibarrModules // 'position'=>100, // 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules // 'target'=>'', - // 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both - // 'constraint'=>'$conf->mymodule->enabled'); // Add constraint + // 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both // $r++; // // Example to declare a Left Menu entry: diff --git a/htdocs/admin/menus/edit.php b/htdocs/admin/menus/edit.php index 0a2b3d783c1..d1938afa857 100644 --- a/htdocs/admin/menus/edit.php +++ b/htdocs/admin/menus/edit.php @@ -182,35 +182,44 @@ if (isset($_GET["action"]) && $_GET["action"] == 'add') if (isset($_GET["action"]) && $_GET["action"] == 'add_const') { - $langs->load("errors"); - $menu = new Menubase($db); - $result=$menu->addConstraint($_POST['menuId'], $_POST['constraint'], $_POST['type']); - if ($result > 0) + + if($_POST['type'] == 'prede') { - $mesg='
'.$langs->trans("RecordModifiedSuccessfully").'
'; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu_const(fk_menu, fk_constraint) VALUES(".$_POST['menuId'].",".$_POST['constraint'].")"; } else { - $mesg='
'.$menu->error.'
'; + + $sql = "SELECT max(rowid) as maxId FROM ".MAIN_DB_PREFIX."menu_constraint"; + $result = $db->query($sql); + $objc = $db->fetch_object($result); + $constraint = ($objc->maxId) + 1; + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu_constraint(rowid,action) VALUES(".$constraint.",'".$_POST['constraint']."')"; + $db->query($sql); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu_const(fk_menu, fk_constraint) VALUES(".$_POST['menuId'].",".$constraint.")"; } + $db->query($sql); + header("location:edit.php?action=edit&menuId=".$_POST['menuId']); exit; } if (isset($_GET["action"]) && $_GET["action"] == 'del_const') { - $langs->load("errors"); - $menu = new Menubase($db); - $result=$menu->delConstraint($_GET['menuId'], $_GET['constId']); - if ($result > 0) + $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu_const WHERE fk_menu = ".$_GET['menuId']." AND fk_constraint = ".$_GET['constId']; + $db->query($sql); + + $sql = "SELECT count(rowid) as countId FROM ".MAIN_DB_PREFIX."menu_const WHERE fk_constraint = ".$_GET['constId']; + $result = $db->query($sql); + $objc = $db->fetch_object($result); + if($objc->countId == 0) { - $mesg='
'.$langs->trans("RecordModifiedSuccessfully").'
'; - } - else - { - $mesg='
'.$menu->error.'
'; - } + $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu_constraint WHERE rowid = ".$_GET['constId']; + $db->query($sql); + } header("location:edit.php?action=edit&menuId=".$_GET['menuId']); exit; @@ -520,7 +529,7 @@ elseif (isset($_GET["action"]) && $_GET["action"] == 'edit') // Ajout de contraintes predefinis print '
'; print ''; - print ''; + print ''; $var=!$var; print ''; diff --git a/htdocs/core/menubase.class.php b/htdocs/core/menubase.class.php index 81dd62a8bf4..ef7fdfa8693 100644 --- a/htdocs/core/menubase.class.php +++ b/htdocs/core/menubase.class.php @@ -1,6 +1,5 @@ - * Copyright (C) 2009 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -661,114 +660,6 @@ class Menubase return $tabMenu; } - - /** - * \brief Add constraint menu - * \param menuId Menu id - * \param constraint Value or id for constraint - * \param type type of constraint - * \return int <0 if KO, >0 if OK - */ - function addConstraint($menuId, $constraint, $type='') - { - if($type == 'predefined') - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu_const(fk_menu, fk_constraint) VALUES(".$menuId.",".$constraint.")"; - } - else - { - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."menu_constraint"; - $sql.= " WHERE action = '".$constraint."'"; - $resSql = $this->db->query($sql); - if (! $resSql) - { - $this->error="Error ".$this->db->lasterror(); - dol_syslog("Menubase::addConstraint::4 ".$this->error, LOG_ERR); - return -4; - } - $num = $this->db->num_rows($resSql); - if ($num) - { - $obj = $this->db->fetch_object($resSql); - $constraintId = $obj->rowid; - } - else - { - $sql = "SELECT max(rowid) as maxId FROM ".MAIN_DB_PREFIX."menu_constraint"; - $resultId = $this->db->query($sql); - if (! $resultId) - { - $this->error="Error ".$this->db->lasterror(); - dol_syslog("Menubase::addConstraint::3 ".$this->error, LOG_ERR); - return -3; - } - - $objc = $this->db->fetch_object($resultId); - $constraintId = ($objc->maxId) + 1; - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu_constraint(rowid,action) VALUES(".$constraintId.",'".$constraint."')"; - $result = $this->db->query($sql); - if (! $result) - { - $this->error="Error ".$this->db->lasterror(); - dol_syslog("Menubase::addConstraint::2 sql = ".$sql." ".$this->error, LOG_ERR); - return -2; - } - } - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu_const(fk_menu, fk_constraint) VALUES(".$menuId.",".$constraintId.")"; - } - - $result = $this->db->query($sql); - if (! $result) - { - $this->error="Error ".$this->db->lasterror(); - dol_syslog("Menubase::addConstraint::1 sql = ".$sql." ".$this->error, LOG_ERR); - return -1; - } - return 1; - } - - /** - * \brief Delete constraint menu - * \param menuId Menu id - * \param constId Constraint id - * \return int <0 if KO, >0 if OK - */ - function delConstraint($menuId, $constId) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu_const WHERE fk_menu = ".$menuId." AND fk_constraint = ".$constId; - $result = $this->db->query($sql); - if (! $result) - { - $this->error="Error ".$this->db->lasterror(); - dol_syslog("Menubase::delConstraint::3 ".$this->error, LOG_ERR); - return -3; - } - - $sql = "SELECT count(rowid) as countId FROM ".MAIN_DB_PREFIX."menu_const WHERE fk_constraint = ".$constId; - $result = $this->db->query($sql); - if (! $result) - { - $this->error="Error ".$this->db->lasterror(); - dol_syslog("Menubase::delConstraint::2 ".$this->error, LOG_ERR); - return -2; - } - - $objc = $this->db->fetch_object($result); - if($objc->countId == 0) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu_constraint WHERE rowid = ".$constId; - $result = $this->db->query($sql); - if (! $result) - { - $this->error="Error ".$this->db->lasterror(); - dol_syslog("Menubase::delConstraint::1 ".$this->error, LOG_ERR); - return -1; - } - } - return 1; - } }