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 '