New: possibility to declare constraint menu in module
This commit is contained in:
parent
1f7f5d1478
commit
2ad54c2100
@ -146,7 +146,8 @@ class modMyModule extends DolibarrModules
|
|||||||
// 'position'=>100,
|
// 'position'=>100,
|
||||||
// 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
|
// 'perms'=>'1', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules
|
||||||
// 'target'=>'',
|
// '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++;
|
// $r++;
|
||||||
//
|
//
|
||||||
// Example to declare a Left Menu entry:
|
// Example to declare a Left Menu entry:
|
||||||
|
|||||||
@ -182,44 +182,35 @@ if (isset($_GET["action"]) && $_GET["action"] == 'add')
|
|||||||
|
|
||||||
if (isset($_GET["action"]) && $_GET["action"] == 'add_const')
|
if (isset($_GET["action"]) && $_GET["action"] == 'add_const')
|
||||||
{
|
{
|
||||||
|
$langs->load("errors");
|
||||||
if($_POST['type'] == 'prede')
|
$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='<div class="ok">'.$langs->trans("RecordModifiedSuccessfully").'</div>';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
$mesg='<div class="error">'.$menu->error.'</div>';
|
||||||
$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']);
|
header("location:edit.php?action=edit&menuId=".$_POST['menuId']);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_GET["action"]) && $_GET["action"] == 'del_const')
|
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'];
|
$langs->load("errors");
|
||||||
$db->query($sql);
|
$menu = new Menubase($db);
|
||||||
|
$result=$menu->delConstraint($_GET['menuId'], $_GET['constId']);
|
||||||
$sql = "SELECT count(rowid) as countId FROM ".MAIN_DB_PREFIX."menu_const WHERE fk_constraint = ".$_GET['constId'];
|
if ($result > 0)
|
||||||
$result = $db->query($sql);
|
|
||||||
$objc = $db->fetch_object($result);
|
|
||||||
if($objc->countId == 0)
|
|
||||||
{
|
{
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."menu_constraint WHERE rowid = ".$_GET['constId'];
|
$mesg='<div class="ok">'.$langs->trans("RecordModifiedSuccessfully").'</div>';
|
||||||
$db->query($sql);
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
$mesg='<div class="error">'.$menu->error.'</div>';
|
||||||
|
}
|
||||||
|
|
||||||
header("location:edit.php?action=edit&menuId=".$_GET['menuId']);
|
header("location:edit.php?action=edit&menuId=".$_GET['menuId']);
|
||||||
exit;
|
exit;
|
||||||
@ -529,7 +520,7 @@ elseif (isset($_GET["action"]) && $_GET["action"] == 'edit')
|
|||||||
// Ajout de contraintes predefinis
|
// Ajout de contraintes predefinis
|
||||||
print '<form action="edit.php?action=add_const" method="post">';
|
print '<form action="edit.php?action=add_const" method="post">';
|
||||||
print '<input type="hidden" name="menuId" value="'.$_GET['menuId'].'">';
|
print '<input type="hidden" name="menuId" value="'.$_GET['menuId'].'">';
|
||||||
print '<input type="hidden" name="type" value="prede">';
|
print '<input type="hidden" name="type" value="predefined">';
|
||||||
|
|
||||||
$var=!$var;
|
$var=!$var;
|
||||||
print '<tr '.$bc[$var].'>';
|
print '<tr '.$bc[$var].'>';
|
||||||
|
|||||||
@ -660,6 +660,114 @@ class Menubase
|
|||||||
|
|
||||||
return $tabMenu;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -873,11 +873,23 @@ class DolibarrModules
|
|||||||
$menu->perms=$this->menu[$key]['perms'];
|
$menu->perms=$this->menu[$key]['perms'];
|
||||||
$menu->target=$this->menu[$key]['target'];
|
$menu->target=$this->menu[$key]['target'];
|
||||||
$menu->user=$this->menu[$key]['user'];
|
$menu->user=$this->menu[$key]['user'];
|
||||||
|
$menu->constraint=$this->menu[$key]['constraint'];
|
||||||
if (! $err)
|
if (! $err)
|
||||||
{
|
{
|
||||||
$result=$menu->create($user);
|
$result=$menu->create($user);
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
|
if ($menu->constraint)
|
||||||
|
{
|
||||||
|
$resultConstraint=$menu->addConstraint($result,$menu->constraint);
|
||||||
|
if ($resultConstraint < 0)
|
||||||
|
{
|
||||||
|
$this->error=$menu->error;
|
||||||
|
dol_syslog('DolibarrModules::addConstraint result='.$resultConstraint." ".$this->error, LOG_ERR);
|
||||||
|
$err++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
$this->menu[$key]['rowid']=$result;
|
$this->menu[$key]['rowid']=$result;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@ -140,7 +140,18 @@ class modAgenda extends DolibarrModules
|
|||||||
//------
|
//------
|
||||||
$r=0;
|
$r=0;
|
||||||
|
|
||||||
$this->menu[$r]=array('fk_menu'=>0,'type'=>'top','titre'=>'Agenda','mainmenu'=>'agenda','leftmenu'=>'0','url'=>'/comm/action/index.php','langs'=>'commercial','position'=>100,'perms'=>'$user->rights->agenda->myactions->read','target'=>'','user'=>0);
|
$this->menu[$r]=array('fk_menu'=>0,
|
||||||
|
'type'=>'top',
|
||||||
|
'titre'=>'Agenda',
|
||||||
|
'mainmenu'=>'agenda',
|
||||||
|
'leftmenu'=>'0',
|
||||||
|
'url'=>'/comm/action/index.php',
|
||||||
|
'langs'=>'commercial',
|
||||||
|
'position'=>100,
|
||||||
|
'perms'=>'$user->rights->agenda->myactions->read',
|
||||||
|
'target'=>'',
|
||||||
|
'user'=>0,
|
||||||
|
'constraint'=>'$conf->agenda->enabled');
|
||||||
$r++;
|
$r++;
|
||||||
|
|
||||||
// Exports
|
// Exports
|
||||||
|
|||||||
@ -103,7 +103,8 @@ class modCashDesk extends DolibarrModules
|
|||||||
'position'=>100,
|
'position'=>100,
|
||||||
'perms'=>1, // Use 'perms'=>'1' if you want your menu with no permission rules
|
'perms'=>1, // Use 'perms'=>'1' if you want your menu with no permission rules
|
||||||
'target'=>'',
|
'target'=>'',
|
||||||
'user'=>0); // 0=Menu for internal users, 1=external users, 2=both
|
'user'=>0, // 0=Menu for internal users, 1=external users, 2=both
|
||||||
|
'constraint'=>'$conf->cashdesk->enabled'); //Constraint
|
||||||
$r++;
|
$r++;
|
||||||
|
|
||||||
// This is to declare a Left Menu entry:
|
// This is to declare a Left Menu entry:
|
||||||
|
|||||||
@ -132,7 +132,8 @@ class modECM extends DolibarrModules
|
|||||||
'position'=>100,
|
'position'=>100,
|
||||||
'perms'=>'$user->rights->ecm->download || $user->rights->ecm->upload || $user->rights->ecm->setup',
|
'perms'=>'$user->rights->ecm->download || $user->rights->ecm->upload || $user->rights->ecm->setup',
|
||||||
'target'=>'',
|
'target'=>'',
|
||||||
'user'=>0);
|
'user'=>0,
|
||||||
|
'constraint'=>'$conf->ecm->enabled');
|
||||||
$r++;
|
$r++;
|
||||||
|
|
||||||
// Left menu linked to top menu
|
// Left menu linked to top menu
|
||||||
|
|||||||
@ -98,7 +98,18 @@ class modPhenix extends DolibarrModules
|
|||||||
//------
|
//------
|
||||||
$r=0;
|
$r=0;
|
||||||
|
|
||||||
$this->menu[$r]=array('fk_menu'=>0,'type'=>'top','titre'=>'Calendar','mainmenu'=>'phenix','leftmenu'=>'1','url'=>'/phenix/phenix.php','langs'=>'other','position'=>100,'perms'=>'','target'=>'','user'=>0);
|
$this->menu[$r]=array('fk_menu'=>0,
|
||||||
|
'type'=>'top',
|
||||||
|
'titre'=>'Calendar',
|
||||||
|
'mainmenu'=>'phenix',
|
||||||
|
'leftmenu'=>'1',
|
||||||
|
'url'=>'/phenix/phenix.php',
|
||||||
|
'langs'=>'other',
|
||||||
|
'position'=>100,
|
||||||
|
'perms'=>'',
|
||||||
|
'target'=>'',
|
||||||
|
'user'=>0,
|
||||||
|
'constraint'=>'$conf->phenix->enabled');
|
||||||
$r++;
|
$r++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user