diff --git a/dev/skeletons/modMyModule.class.php b/dev/skeletons/modMyModule.class.php
index 29bfb516dd4..2438b6aaa21 100644
--- a/dev/skeletons/modMyModule.class.php
+++ b/dev/skeletons/modMyModule.class.php
@@ -146,7 +146,8 @@ 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
+ // 'user'=>2, // 0=Menu for internal users, 1=external users, 2=both
+ // 'constraint'=>'$conf->mymodule->enabled'); // Add constraint
// $r++;
//
// Example to declare a Left Menu entry:
diff --git a/htdocs/admin/menus/edit.php b/htdocs/admin/menus/edit.php
index d1938afa857..0a2b3d783c1 100644
--- a/htdocs/admin/menus/edit.php
+++ b/htdocs/admin/menus/edit.php
@@ -182,44 +182,35 @@ if (isset($_GET["action"]) && $_GET["action"] == 'add')
if (isset($_GET["action"]) && $_GET["action"] == 'add_const')
{
-
- if($_POST['type'] == 'prede')
+ $langs->load("errors");
+ $menu = new Menubase($db);
+ $result=$menu->addConstraint($_POST['menuId'], $_POST['constraint'], $_POST['type']);
+ if ($result > 0)
{
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu_const(fk_menu, fk_constraint) VALUES(".$_POST['menuId'].",".$_POST['constraint'].")";
+ $mesg='
'.$langs->trans("RecordModifiedSuccessfully").'
';
}
else
{
-
- $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.")";
+ $mesg=''.$menu->error.'
';
}
- $db->query($sql);
-
header("location:edit.php?action=edit&menuId=".$_POST['menuId']);
exit;
}
if (isset($_GET["action"]) && $_GET["action"] == 'del_const')
{
- $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)
+ $langs->load("errors");
+ $menu = new Menubase($db);
+ $result=$menu->delConstraint($_GET['menuId'], $_GET['constId']);
+ if ($result > 0)
{
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu_constraint WHERE rowid = ".$_GET['constId'];
- $db->query($sql);
- }
+ $mesg=''.$langs->trans("RecordModifiedSuccessfully").'
';
+ }
+ else
+ {
+ $mesg=''.$menu->error.'
';
+ }
header("location:edit.php?action=edit&menuId=".$_GET['menuId']);
exit;
@@ -529,7 +520,7 @@ elseif (isset($_GET["action"]) && $_GET["action"] == 'edit')
// Ajout de contraintes predefinis
print '