Skip to content
Snippets Groups Projects
Commit d4c98d59 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Qual: Simplify code for menu handlers

parent 26268896
No related branches found
No related tags found
No related merge requests found
......@@ -409,8 +409,10 @@ class Menubase
//on affiche le menu
if ($this->verifConstraint($tab[$x][0], $tab[$x][6], $tab[$x][7]) != 0) {
if ($this->verifConstraint($tab[$x][0], $tab[$x][6], $tab[$x][7]) != 0)
{
$leftmenuConstraint = true;
if ($tab[$x][6])
{
$leftmenuConstraint = false;
......@@ -418,26 +420,28 @@ class Menubase
//print $str."<br>\n";
//eval ($str);
dol_eval($str);
if ($leftmenuConstraint == true)
{
$this->newmenu->add_submenu(DOL_URL_ROOT . $tab[$x][2], $tab[$x][3], $rang -1, $tab[$x][4], $tab[$x][5]);
$this->recur($tab, $tab[$x][0], $rang +1);
}
}
else
if ($leftmenuConstraint == true)
{
$this->newmenu->add_submenu(DOL_URL_ROOT . $tab[$x][2], $tab[$x][3], $rang -1, $tab[$x][4], $tab[$x][5]);
$this->recur($tab, $tab[$x][0], $rang +1);
}
}
}
}
}
// \TODO Avoid call for each
/**
* Check if constraint defined by rowid is ok or not
* \TODO Avoid call for each
*
* @param unknown_type $rowid
* @param unknown_type $mainmenu
* @param unknown_type $leftmenu
* @return unknown
*/
function verifConstraint($rowid, $mainmenu = "", $leftmenu = "")
{
global $user, $conf, $lang;
......@@ -446,9 +450,9 @@ class Menubase
include_once(DOL_DOCUMENT_ROOT.'/lib/admin.lib.php'); // Because later some eval try to run dynamic call to dolibarr_get_const
$constraint = true;
$sql = "SELECT c.rowid, c.action, mc.user";
$sql = "SELECT c.rowid, c.action";
$sql.= " FROM " . MAIN_DB_PREFIX . "menu_constraint as c, " . MAIN_DB_PREFIX . "menu_const as mc";
$sql.= " WHERE mc.fk_constraint = c.rowid AND (mc.user = 0 OR mc.user = 2) AND mc.fk_menu = '" . $rowid . "'";
$sql.= " WHERE mc.fk_constraint = c.rowid AND mc.fk_menu = '" . $rowid . "'";
dolibarr_syslog("Menubase::verifConstraint sql=".$sql);
$result = $this->db->query($sql);
......@@ -525,14 +529,19 @@ class Menubase
* \param type_user 0=Internal,1=External,2=All
* \param mainmenu Value for mainmenu that defined top menu
* \param menu_handler Name of menu_handler used (auguria, eldy...)
* \return array Return array with menu entries for top menu
*/
function menutopCharger($type_user, $mainmenu, $menu_handler)
function menuTopCharger($type_user, $mainmenu, $menu_handler)
{
global $langs, $user, $conf;
global $rights; // To export to dol_eval function
$tabMenu=array();
$sql = "SELECT m.rowid, m.mainmenu, m.titre, m.url, m.langs, m.perms";
$sql.= " FROM ".MAIN_DB_PREFIX."menu as m";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."menu_const as mc ON m.rowid = mc.fk_menu";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."menu_constraint as mo ON mc.fk_constraint = mo.rowid";
$sql.= " WHERE m.type = 'top'";
$sql.= " AND m.menu_handler in('".$menu_handler."','all')";
if ($type_user == 0) $sql.= " AND m.user in (0,2)";
......@@ -547,63 +556,76 @@ class Menubase
$a = 0;
$b = 0;
$oldrowid=0;
while ($a < $numa)
{
// Init tabMenu array
$objm = $this->db->fetch_object($resql);
//print "x".$objm->rowid;
if ($this->verifConstraint($objm->rowid))
{
// Define class
$class="";
if ($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == $objm->mainmenu)
{
$class='id="sel"';
}
$chaine="";
// Define $right
$rights = true;
if ($objm->perms)
{
$str = 'if(!('.$objm->perms.')) { $rights = false; }';
dol_eval($str);
}
// Define $chaine
$title=$objm->titre;
if (! eregi('\(dotnoloadlang\)$',$title))
{
if (! empty($objm->langs)) $langs->load($objm->langs);
}
else
{
$title=eregi_replace('\(dotnoloadlang\)$','',$title);
}
// Define class
$class="";
if ($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == $objm->mainmenu)
{
$class='id="sel"';
}
$chaine="";
// Define $chaine
$title=$objm->titre;
if (! eregi('\(dotnoloadlang\)$',$title))
{
if (! empty($objm->langs)) $langs->load($objm->langs);
}
else
{
$title=eregi_replace('\(dotnoloadlang\)$','',$title);
}
if (eregi("/",$title))
{
$tab_titre = explode("/",$title);
$chaine = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]);
}
else
{
$chaine = $langs->trans($title);
}
$tabMenu[$b]['rowid'] = $objm->rowid;
$tabMenu[$b]['mainmenu'] = $objm->mainmenu;
$tabMenu[$b]['titre'] = $chaine; // Title
$tabMenu[$b]['url'] = $objm->url;
$tabMenu[$b]['atarget'] = $this->atarget;
$tabMenu[$b]['class'] = $class;
$tabMenu[$b]['right'] = $rights;
$b++;
}
if (eregi("/",$title))
{
$tab_titre = explode("/",$title);
$chaine = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]);
}
else
{
$chaine = $langs->trans($title);
}
// Define $right
$rights = true;
if ($objm->perms)
{
$rights = false;
$str = 'if ('.$objm->perms.') { $rights = true; }';
dol_eval($str);
//print "Check permission for ".$objm->perms.": rights=".$rights."<br>\n";
}
// Define $constraint
$constraint = true;
if ($objm->action)
{
$constraint = false;
$strconstraint = 'if (' . $objm->action . ') { $constraint = true; }';
dol_eval($strconstraint);
//print "Check permission for ".$objm->perms.": rights=".$rights."<br>\n";
}
if ($objm->rowid != $oldrowid && $oldrowid) $b++; // Break on new entry
$oldrowid=$objm->rowid;
$tabMenu[$b]['rowid'] = $objm->rowid;
$tabMenu[$b]['mainmenu'] = $objm->mainmenu;
$tabMenu[$b]['titre'] = $chaine; // Title
$tabMenu[$b]['url'] = $objm->url;
$tabMenu[$b]['atarget'] = $this->atarget;
$tabMenu[$b]['class'] = $class;
if (! isset($tabMenu[$b]['right'])) $tabMenu[$b]['right'] = $rights;
else $tabMenu[$b]['right'] = ($tabMenu[$b]['right'] && $rights);
if (! isset($tabMenu[$b]['enabled'])) $tabMenu[$b]['enabled'] = $constraint;
else $tabMenu[$b]['enabled'] = ($tabMenu[$b]['enabled'] && $constraint);
//var_dump($tabMenu);
$a++;
}
}
......
......@@ -77,30 +77,32 @@ class MenuTop {
$menuArbo = new Menubase($this->db,'auguria','top');
$tabMenu = $menuArbo->menutopCharger(0,$_SESSION['mainmenu'], 'auguria');
$tabMenu = $menuArbo->menuTopCharger(0,$_SESSION['mainmenu'], 'auguria');
print '<ul>';
for($i=0; $i<count($tabMenu); $i++)
{
if ($tabMenu[$i]['right'] == true)
if ($tabMenu[$i]['enabled'] == true)
{
// Define url
$url=DOL_URL_ROOT.$tabMenu[$i]['url'];
if (! eregi('\?',DOL_URL_ROOT.$tabMenu[$i]['url'])) $url.='?';
else $url.='&';
$url.='mainmenu='.$tabMenu[$i]['mainmenu'].'&leftmenu=';
$url.="&idmenu=".$tabMenu[$i]['rowid'];
// Define idsel
if (! empty($_GET["idmenu"]) && $tabMenu[$i]['rowid'] == $_GET["idmenu"]) $idsel='id="sel" ';
else $idsel='';
print '<li><a '.$tabMenu[$i]['class'].' '.$idsel.'href="'.$url.'"'.($this->atarget?" target=$this->atarget":"").'>'.$tabMenu[$i]['titre'].'</a></li>';
}
else
{
print '<li><div class="tmenudisabled">'.$tabMenu[$i]['titre'].'</div></li>';
}
if ($tabMenu[$i]['right'] == true)
{
// Define url
$url=DOL_URL_ROOT.$tabMenu[$i]['url'];
if (! eregi('\?',DOL_URL_ROOT.$tabMenu[$i]['url'])) $url.='?';
else $url.='&';
$url.='mainmenu='.$tabMenu[$i]['mainmenu'].'&leftmenu=';
$url.="&idmenu=".$tabMenu[$i]['rowid'];
// Define idsel
if (! empty($_GET["idmenu"]) && $tabMenu[$i]['rowid'] == $_GET["idmenu"]) $idsel='id="sel" ';
else $idsel='';
print '<li><a '.$tabMenu[$i]['class'].' '.$idsel.'href="'.$url.'"'.($this->atarget?" target=$this->atarget":"").'>'.$tabMenu[$i]['titre'].'</a></li>';
}
else
{
print '<li><div class="tmenudisabled">'.$tabMenu[$i]['titre'].'</div></li>';
}
}
}
print '</ul>';
......
......@@ -77,30 +77,32 @@ class MenuTop {
$menuArbo = new Menubase($this->db,'auguria','top');
$tabMenu = $menuArbo->menutopCharger(1,$_SESSION['mainmenu'], 'auguria');
$tabMenu = $menuArbo->menuTopCharger(1,$_SESSION['mainmenu'], 'auguria');
print '<ul>';
for($i=0; $i<count($tabMenu); $i++)
{
if ($tabMenu[$i]['right'] == true)
if ($tabMenu[$i]['enabled'] == true)
{
// Define url
$url=DOL_URL_ROOT.$tabMenu[$i]['url'];
if (! eregi('\?',DOL_URL_ROOT.$tabMenu[$i]['url'])) $url.='?';
else $url.='&';
$url.='mainmenu='.$tabMenu[$i]['mainmenu'].'&leftmenu=';
$url.="&idmenu=".$tabMenu[$i]['rowid'];
// Define idsel
if (! empty($_GET["idmenu"]) && $tabMenu[$i]['rowid'] == $_GET["idmenu"]) $idsel='id="sel" ';
else $idsel='';
print '<li><a '.$tabMenu[$i]['class'].' '.$idsel.'href="'.$url.'"'.($this->atarget?" target=$tabMenu[$i]['atarget']":"").'>'.$tabMenu[$i]['titre'].'</a></li>';
if ($tabMenu[$i]['right'] == true)
{
// Define url
$url=DOL_URL_ROOT.$tabMenu[$i]['url'];
if (! eregi('\?',DOL_URL_ROOT.$tabMenu[$i]['url'])) $url.='?';
else $url.='&';
$url.='mainmenu='.$tabMenu[$i]['mainmenu'].'&leftmenu=';
$url.="&idmenu=".$tabMenu[$i]['rowid'];
// Define idsel
if (! empty($_GET["idmenu"]) && $tabMenu[$i]['rowid'] == $_GET["idmenu"]) $idsel='id="sel" ';
else $idsel='';
print '<li><a '.$tabMenu[$i]['class'].' '.$idsel.'href="'.$url.'"'.($this->atarget?" target=$tabMenu[$i]['atarget']":"").'>'.$tabMenu[$i]['titre'].'</a></li>';
}
else
{
print '<li><div class="tmenudisabled">'.$tabMenu[$i]['titre'].'</div></li>';
}
}
else
{
print '<li><div class="tmenudisabled">'.$tabMenu[$i]['titre'].'</div></li>';
}
}
print '</ul>';
......
......@@ -346,26 +346,30 @@ class MenuTop {
require_once(DOL_DOCUMENT_ROOT."/core/menubase.class.php");
$menuArbo = new Menubase($this->db,'eldy','top');
$tabMenu = $menuArbo->menutopCharger(0,$_SESSION['mainmenu'],'eldy');
for($i=0; $i<count($tabMenu); $i++)
$tabMenu = $menuArbo->menuTopCharger(0,$_SESSION['mainmenu'],'eldy');
for($i=0; $i<count($tabMenu); $i++)
{
if ($tabMenu[$i]['right'] == true)
{
$url=DOL_URL_ROOT.$tabMenu[$i]['url'];
if (! eregi('\?',DOL_URL_ROOT.$tabMenu[$i]['url'])) $url.='?';
else $url.='&';
$url.='mainmenu='.$tabMenu[$i]['mainmenu'].'&leftmenu=';
$url.="&idmenu=".$tabMenu[$i]['rowid'];
// Define idsel
if (! empty($_SESSION['idmenu']) && $tabMenu[$i]['rowid'] == $_SESSION['idmenu']) $idsel='id="sel" ';
else $idsel='';
print '<td class="tmenu"><a class="tmenu" '.$idsel.'href="'.$url.'"'.($this->atarget?" target=$this->atarget":"").'>';
print $tabMenu[$i]['titre'];
print '</a></td>';
}
else
if ($tabMenu[$i]['enabled'] == true)
{
print '<td class="tmenu"><font class="tmenudisabled">'.$tabMenu[$i]['titre'].'</font></td>';
if ($tabMenu[$i]['right'] == true)
{
$url=DOL_URL_ROOT.$tabMenu[$i]['url'];
if (! eregi('\?',DOL_URL_ROOT.$tabMenu[$i]['url'])) $url.='?';
else $url.='&';
$url.='mainmenu='.$tabMenu[$i]['mainmenu'].'&leftmenu=';
$url.="&idmenu=".$tabMenu[$i]['rowid'];
// Define idsel
if (! empty($_SESSION['idmenu']) && $tabMenu[$i]['rowid'] == $_SESSION['idmenu']) $idsel='id="sel" ';
else $idsel='';
print '<td class="tmenu"><a class="tmenu" '.$idsel.'href="'.$url.'"'.($this->atarget?" target=$this->atarget":"").'>';
print $tabMenu[$i]['titre'];
print '</a></td>';
}
else
{
print '<td class="tmenu"><font class="tmenudisabled">'.$tabMenu[$i]['titre'].'</font></td>';
}
}
}
......
......@@ -311,26 +311,28 @@ class MenuTop {
require_once(DOL_DOCUMENT_ROOT."/core/menubase.class.php");
$menuArbo = new Menubase($this->db,'eldy','top');
$tabMenu = $menuArbo->menutopCharger(1,$_SESSION['mainmenu'],'eldy');
$tabMenu = $menuArbo->menuTopCharger(1,$_SESSION['mainmenu'],'eldy');
for($i=0; $i<count($tabMenu); $i++)
{
if ($tabMenu[$i]['right'] == true)
if ($tabMenu[$i]['enabled'] == true)
{
$url=DOL_URL_ROOT.$tabMenu[$i]['url'];
if (! eregi('\?',DOL_URL_ROOT.$tabMenu[$i]['url'])) $url.='?';
else $url.='&';
$url.='mainmenu='.$tabMenu[$i]['mainmenu'].'&leftmenu=';
$url.="&idmenu=".$tabMenu[$i]['rowid'];
// Define idsel
if (! empty($_GET["idmenu"]) && $tabMenu[$i]['rowid'] == $_GET["idmenu"]) $idsel='id="sel" ';
else $idsel='';
print '<td class="tmenu"><a class="tmenu" '.$idsel.'href="'.$url.'"'.($this->atarget?" target=$this->atarget":"").'>'.$tabMenu[$i]['titre'].'</a></td>';
}
else
{
print '<td class="tmenu"><font class="tmenudisabled">'.$tabMenu[$i]['titre'].'</font></td>';
}
if ($tabMenu[$i]['right'] == true)
{
$url=DOL_URL_ROOT.$tabMenu[$i]['url'];
if (! eregi('\?',DOL_URL_ROOT.$tabMenu[$i]['url'])) $url.='?';
else $url.='&';
$url.='mainmenu='.$tabMenu[$i]['mainmenu'].'&leftmenu=';
$url.="&idmenu=".$tabMenu[$i]['rowid'];
// Define idsel
if (! empty($_GET["idmenu"]) && $tabMenu[$i]['rowid'] == $_GET["idmenu"]) $idsel='id="sel" ';
else $idsel='';
print '<td class="tmenu"><a class="tmenu" '.$idsel.'href="'.$url.'"'.($this->atarget?" target=$this->atarget":"").'>'.$tabMenu[$i]['titre'].'</a></td>';
}
else
{
print '<td class="tmenu"><font class="tmenudisabled">'.$tabMenu[$i]['titre'].'</font></td>';
}
}
}
print '</tr></table>';
......
......@@ -71,26 +71,28 @@ class MenuTop {
require_once(DOL_DOCUMENT_ROOT."/core/menubase.class.php");
$menuArbo = new Menubase($this->db,'eldy','top');
$tabMenu = $menuArbo->menutopCharger(2,$_SESSION['mainmenu'],'');
$tabMenu = $menuArbo->menuTopCharger(2,$_SESSION['mainmenu'],'');
for($i=0;$i<count($tabMenu);$i++)
{
if ($tabMenu[$i]['right'] == true)
if ($tabMenu[$i]['enabled'] == true)
{
$url=DOL_URL_ROOT.$tabMenu[$i]['url'];
if (! eregi('\?',DOL_URL_ROOT.$tabMenu[$i]['url'])) $url.='?';
else $url.='&';
$url.='mainmenu='.$tabMenu[$i]['mainmenu'].'&leftmenu=';
$url.="&idmenu=".$tabMenu[$i]['rowid'];
// Define idsel
if (! empty($_GET["idmenu"]) && $tabMenu[$i]['rowid'] == $_GET["idmenu"]) $idsel='id="sel" ';
else $idsel='';
print '<td class="tmenu"><a class="tmenu" '.$idsel.'href="'.$url.'"'.($this->atarget?" target=$this->atarget":"").'>'.$tabMenu[$i]['titre'].'</a></td>';
}
else
{
print '<td class="tmenu"><font class="tmenudisabled">'.$tabMenu[$i]['titre'].'</font></td>';
}
if ($tabMenu[$i]['right'] == true)
{
$url=DOL_URL_ROOT.$tabMenu[$i]['url'];
if (! eregi('\?',DOL_URL_ROOT.$tabMenu[$i]['url'])) $url.='?';
else $url.='&';
$url.='mainmenu='.$tabMenu[$i]['mainmenu'].'&leftmenu=';
$url.="&idmenu=".$tabMenu[$i]['rowid'];
// Define idsel
if (! empty($_GET["idmenu"]) && $tabMenu[$i]['rowid'] == $_GET["idmenu"]) $idsel='id="sel" ';
else $idsel='';
print '<td class="tmenu"><a class="tmenu" '.$idsel.'href="'.$url.'"'.($this->atarget?" target=$this->atarget":"").'>'.$tabMenu[$i]['titre'].'</a></td>';
}
else
{
print '<td class="tmenu"><font class="tmenudisabled">'.$tabMenu[$i]['titre'].'</font></td>';
}
}
}
*/
......
......@@ -310,27 +310,30 @@ class MenuTop {
require_once(DOL_DOCUMENT_ROOT."/core/menubase.class.php");
$menuArbo = new Menubase($this->db,'rodolphe','top');
$tabMenu = $menuArbo->menutopCharger(2,$_SESSION['mainmenu'],'rodolphe');
for($i=0;$i<count($tabMenu);$i++)
$tabMenu = $menuArbo->menuTopCharger(2,$_SESSION['mainmenu'],'rodolphe');
for($i=0;$i<count($tabMenu);$i++)
{
if ($tabMenu[$i]['right'] == true)
{
$url=DOL_URL_ROOT.$tabMenu[$i]['url'];
if (! eregi('\?',DOL_URL_ROOT.$tabMenu[$i]['url'])) $url.='?';
else $url.='&';
$url.='mainmenu='.$tabMenu[$i]['mainmenu'].'&leftmenu=';
$url.="&idmenu=".$tabMenu[$i]['rowid'];
// Define idsel
if (! empty($_GET["idmenu"]) && $tabMenu[$i]['rowid'] == $_GET["idmenu"]) $idsel='id="sel" ';
elseif (! empty($_GET["mainmenu"]) && $_GET["mainmenu"] == $tabMenu[$i]['mainmenu']) $idsel='id="sel" ';
else $idsel='';
print '<td class="tmenu"><a class="tmenu" '.$idsel.'href="'.$url.'"'.($this->atarget?" target=$this->atarget":"").'>'.$tabMenu[$i]['titre'].'</a></td>';
}
else
if ($tabMenu[$i]['enabled'] == true)
{
print '<td class="tmenu"><font class="tmenudisabled">'.$tabMenu[$i]['titre'].'</font></td>';
if ($tabMenu[$i]['right'] == true)
{
$url=DOL_URL_ROOT.$tabMenu[$i]['url'];
if (! eregi('\?',DOL_URL_ROOT.$tabMenu[$i]['url'])) $url.='?';
else $url.='&';
$url.='mainmenu='.$tabMenu[$i]['mainmenu'].'&leftmenu=';
$url.="&idmenu=".$tabMenu[$i]['rowid'];
// Define idsel
if (! empty($_GET["idmenu"]) && $tabMenu[$i]['rowid'] == $_GET["idmenu"]) $idsel='id="sel" ';
elseif (! empty($_GET["mainmenu"]) && $_GET["mainmenu"] == $tabMenu[$i]['mainmenu']) $idsel='id="sel" ';
else $idsel='';
print '<td class="tmenu"><a class="tmenu" '.$idsel.'href="'.$url.'"'.($this->atarget?" target=$this->atarget":"").'>'.$tabMenu[$i]['titre'].'</a></td>';
}
else
{
print '<td class="tmenu"><font class="tmenudisabled">'.$tabMenu[$i]['titre'].'</font></td>';
}
}
}
......
......@@ -252,6 +252,8 @@ alter table llx_tva modify fk_bank integer;
delete from llx_const where name='MAIN_USE_PREVIEW_TABS';
alter table llx_menu_const drop column user;
create table llx_ecm_directories
(
rowid integer AUTO_INCREMENT PRIMARY KEY,
......
......@@ -23,9 +23,6 @@ CREATE TABLE `llx_menu_const` (
`rowid` int(11) NOT NULL auto_increment,
`fk_menu` int(11) NOT NULL,
`fk_constraint` int(11) NOT NULL,
`user` tinyint(4) NOT NULL default '2',
PRIMARY KEY (`rowid`),
KEY `fk_menu` (`fk_menu`),
KEY `fk_constraint` (`fk_constraint`)
PRIMARY KEY (`rowid`)
) type=innodb;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment