Fix: Debuggage editeur de menu
This commit is contained in:
parent
e600bd2f2e
commit
4ff8d0a97c
@ -21,7 +21,7 @@
|
||||
|
||||
/**
|
||||
\file htdocs/admin/menus.php
|
||||
\ingroup core,menudb
|
||||
\ingroup core
|
||||
\brief Page de configuration des gestionnaires de menu
|
||||
*/
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
|
||||
/**
|
||||
\file htdocs/admin/menus/edit.php
|
||||
\ingroup core,menudb
|
||||
\ingroup core
|
||||
\brief Edition des menus
|
||||
*/
|
||||
|
||||
@ -100,13 +100,13 @@ if (isset($_GET["action"]) && $_GET["action"] == 'add')
|
||||
$error=0;
|
||||
if (! $error && ! $_POST['menu_handler'])
|
||||
{
|
||||
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiest("MenuHandler")).'</div>';
|
||||
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("MenuHandler")).'</div>';
|
||||
$_GET["action"] = 'create';
|
||||
$error++;
|
||||
}
|
||||
if (! $error && ! $_POST['type'])
|
||||
{
|
||||
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiest("Type")).'</div>';
|
||||
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Type")).'</div>';
|
||||
$_GET["action"] = 'create';
|
||||
$error++;
|
||||
}
|
||||
@ -128,6 +128,12 @@ if (isset($_GET["action"]) && $_GET["action"] == 'add')
|
||||
$_GET["action"] = 'create';
|
||||
$error++;
|
||||
}
|
||||
if (! $error && ! $_POST['menuId'] && $_POST['type'] == 'left')
|
||||
{
|
||||
$mesg='<div class="error">'.$langs->trans("ErrorLeftMenuMustHaveAParentId").'</div>';
|
||||
$_GET["action"] = 'create';
|
||||
$error++;
|
||||
}
|
||||
if (! $error)
|
||||
{
|
||||
$sql = "SELECT max(m.rowid) as maxId FROM ".MAIN_DB_PREFIX."menu as m";
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
|
||||
/**
|
||||
\file htdocs/admin/menus/index.php
|
||||
\ingroup core,menudb
|
||||
\ingroup core
|
||||
\brief Gestion des menus
|
||||
*/
|
||||
|
||||
@ -165,9 +165,8 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes')
|
||||
}
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."menu WHERE rowid = ".$_GET['menuId'];
|
||||
$db->query($sql);
|
||||
|
||||
if ($result == 0)
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$db->commit();
|
||||
|
||||
|
||||
@ -1,295 +0,0 @@
|
||||
<?php
|
||||
/* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
* or see http://www.gnu.org/
|
||||
*
|
||||
* $Id$
|
||||
* $Source$
|
||||
*/
|
||||
|
||||
/**
|
||||
\file htdocs/includes/modules/menudb/modules_menudb.php
|
||||
\ingroup menudb
|
||||
\brief Fichier contenant la classe mère d'affichage des menus DB
|
||||
\version $Revision$
|
||||
*/
|
||||
|
||||
/**
|
||||
\class MenuDb
|
||||
\brief Classe de gestion du menu DB
|
||||
*/
|
||||
class MenuDb
|
||||
{
|
||||
var $db;
|
||||
var $menu_handler;
|
||||
var $type;
|
||||
var $atarget;
|
||||
|
||||
var $newmenu;
|
||||
var $mainmenu;
|
||||
var $leftmenu;
|
||||
|
||||
function MenuDb($db,$menu_handler,$type)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->menu_handler = $menu_handler;
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
function menuCharger($mainmenu, $newmenu,$type_user, $leftmenu)
|
||||
{
|
||||
|
||||
global $langs,$user, $conf;
|
||||
|
||||
$this->mainmenu = $mainmenu;
|
||||
$this->newmenu = $newmenu;
|
||||
$this->leftmenu = $leftmenu;
|
||||
|
||||
$sql = "SELECT m.rowid, m.titre, m.type";
|
||||
$sql.= " FROM " . MAIN_DB_PREFIX . "menu as m";
|
||||
$sql.= " WHERE m.mainmenu = '".$this->mainmenu."'";
|
||||
$sql.= " AND m.menu_handler= '".$this->menu_handler."'";
|
||||
$result = $this->db->query($sql);
|
||||
$menuTop = $this->db->fetch_object($result);
|
||||
|
||||
$data[] = array ($menutop->rowid,-1,$this->mainmenu);
|
||||
|
||||
$sql = "SELECT m.rowid, m.fk_menu, m.url, m.titre, m.langs, m.right, m.target, m.mainmenu, m.leftmenu";
|
||||
$sql.= " FROM " . MAIN_DB_PREFIX . "menu as m";
|
||||
$sql.= " WHERE m.menu_handler= '".$this->menu_handler."'";
|
||||
if($type_user == 0) $sql.= " AND m.user <> 1";
|
||||
else $sql.= " AND m.user > 0";
|
||||
$sql.= " ORDER BY m.order, m.rowid";
|
||||
|
||||
$res = $this->db->query($sql);
|
||||
if ($res)
|
||||
{
|
||||
$num = $this->db->num_rows();
|
||||
|
||||
$i = 1;
|
||||
while ($menu = $this->db->fetch_array($res)) {
|
||||
$langs->load($menu['langs']);
|
||||
$titre = $langs->trans($menu['titre']);
|
||||
$rights = $this->verifRights($menu['right']);
|
||||
$data[] = array (
|
||||
$menu['rowid'],
|
||||
$menu['fk_menu'],
|
||||
$menu['url'],
|
||||
$titre,
|
||||
$rights,
|
||||
$menu['target'],
|
||||
$menu['leftmenu']
|
||||
);
|
||||
$i++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
}
|
||||
|
||||
$this->recur($data, $menuTop->rowid, 1);
|
||||
|
||||
return $this->newmenu;
|
||||
|
||||
}
|
||||
|
||||
function recur($tab, $pere, $rang) {
|
||||
$leftmenu = $this->leftmenu;
|
||||
//ballayage du tableau
|
||||
for ($x = 0; $x < count($tab); $x++) {
|
||||
|
||||
//si un élément a pour père : $pere
|
||||
if ($tab[$x][1] == $pere) {
|
||||
|
||||
//on affiche le menu
|
||||
|
||||
if ($this->verifConstraint($tab[$x][0], $tab[$x][6], $tab[$x][7]) != 0) {
|
||||
|
||||
if ($tab[$x][6]) {
|
||||
|
||||
$leftmenuConstraint = false;
|
||||
$str = "if(" . $tab[$x][6] . ") \$leftmenuConstraint = true;";
|
||||
|
||||
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 {
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function verifConstraint($rowid, $mainmenu = "", $leftmenu = "")
|
||||
{
|
||||
global $user, $conf, $user;
|
||||
|
||||
$constraint = true;
|
||||
|
||||
$sql = "SELECT c.rowid, c.action, mc.user";
|
||||
$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 . "'";
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
//echo $sql;
|
||||
$num = $this->db->num_rows();
|
||||
$i = 0;
|
||||
while (($i < $num) && $constraint == true)
|
||||
{
|
||||
$obj = $this->db->fetch_object($result);
|
||||
$strconstraint = "if(!(" . $obj->action . ")) { \$constraint = false;}";
|
||||
|
||||
eval ($strconstraint);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
}
|
||||
|
||||
return $constraint;
|
||||
}
|
||||
|
||||
function verifRights($strRights) {
|
||||
|
||||
global $user,$conf,$user;
|
||||
|
||||
if ($strRights != "") {
|
||||
$rights = true;
|
||||
|
||||
$tab_rights = explode(" || ", $strRights);
|
||||
$i = 0;
|
||||
while (($i < count($tab_rights)) && ($rights == true)) {
|
||||
$str = "if(!(" . $strRights . ")) { \$rights = false;}";
|
||||
eval ($str);
|
||||
$i++;
|
||||
}
|
||||
} else
|
||||
$rights = true;
|
||||
|
||||
return $rights;
|
||||
}
|
||||
|
||||
function listeMainmenu()
|
||||
{
|
||||
$sql = "SELECT DISTINCT m.mainmenu";
|
||||
$sql.= " FROM " . MAIN_DB_PREFIX . "menu as m";
|
||||
$sql.= " WHERE m.menu_handler= '".$this->menu_handler."'";
|
||||
|
||||
$res = $this->db->query($sql);
|
||||
if ($res) {
|
||||
$i = 0;
|
||||
while ($menu = $this->db->fetch_array($res)) {
|
||||
$overwritemenufor[$i] = $menu['mainmenu'];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
}
|
||||
|
||||
return $overwritemenufor;
|
||||
}
|
||||
|
||||
|
||||
function menutopCharger($type_user,$mainmenu)
|
||||
{
|
||||
global $langs, $user, $conf;
|
||||
|
||||
$sql = "SELECT m.rowid, m.mainmenu, m.titre, m.url, m.langs, m.right";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."menu as m";
|
||||
$sql.= " WHERE m.type = 'top'";
|
||||
$sql.= " AND m.menu_handler= '".$this->menu_handler."'";
|
||||
if($type_user == 0) $sql.= " AND m.user <> 1";
|
||||
else $sql.= " AND m.user > 0";
|
||||
$sql.= " ORDER BY m.order";
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$numa = $this->db->num_rows();
|
||||
|
||||
$a = 0;
|
||||
$b = 0;
|
||||
while ($a < $numa)
|
||||
{
|
||||
// Affichage entete menu
|
||||
$objm = $this->db->fetch_object($result);
|
||||
|
||||
if ($this->verifConstraint($objm->rowid))
|
||||
{
|
||||
$langs->load($objm->langs);
|
||||
|
||||
$class="";
|
||||
if ($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == $objm->mainmenu)
|
||||
{
|
||||
$class='id="sel"';
|
||||
}
|
||||
$chaine="";
|
||||
|
||||
$right = true;
|
||||
|
||||
if ($objm->right)
|
||||
{
|
||||
$str = "if(!(".$objm->right.")) \$right = false;";
|
||||
eval($str);
|
||||
}
|
||||
|
||||
if(eregi("/",$objm->titre))
|
||||
{
|
||||
$tab_titre = explode("/",$objm->titre);
|
||||
$chaine = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$chaine = $langs->trans($objm->titre);
|
||||
}
|
||||
|
||||
$tabMenu[$b]['titre'] = $chaine;
|
||||
$tabMenu[$b]['url'] = $objm->url;
|
||||
$tabMenu[$b]['atarget'] = $this->atarget;
|
||||
$tabMenu[$b]['class'] = $class;
|
||||
$tabMenu[$b]['right'] = $right;
|
||||
|
||||
$b++;
|
||||
|
||||
}
|
||||
|
||||
$a++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
}
|
||||
|
||||
return $tabMenu;
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -22,7 +22,7 @@
|
||||
|
||||
/**
|
||||
\file htdocs/admin/perms.php
|
||||
\ingroup core,menudb
|
||||
\ingroup core
|
||||
\brief Page d'administration/configuration des permissions par defaut
|
||||
\version $Revision$
|
||||
*/
|
||||
|
||||
@ -254,9 +254,6 @@ class Conf
|
||||
$this->droitpret->cat=defined('DROITPRET_MAIL')?DROITPRET_MAIL:'';
|
||||
$this->droitpret->dir_temp=DOL_DATA_ROOT."/droitpret/temp";
|
||||
|
||||
// Module menuDb
|
||||
$this->menudb->enabled=1;
|
||||
|
||||
// Module code barre
|
||||
$this->barcode->enabled=defined("MAIN_MODULE_BARCODE")?MAIN_MODULE_BARCODE:0;
|
||||
// Module categorie
|
||||
|
||||
@ -55,14 +55,13 @@ class MenuLeft {
|
||||
*/
|
||||
function MenuLeft($db,&$menu_array)
|
||||
{
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT."/admin/menus/module_menudb.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/menubase.class.php");
|
||||
|
||||
$this->db=$db;
|
||||
$this->menu_array=$menu_array;
|
||||
$this->newmenu = new Menu();
|
||||
|
||||
$this->menuArbo = new menudb($this->db,'auguria','left');
|
||||
$this->menuArbo = new Menubase($this->db,'auguria','left');
|
||||
$this->overwritemenufor = $this->menuArbo->listeMainmenu();
|
||||
|
||||
}
|
||||
|
||||
@ -54,14 +54,14 @@ class MenuLeft {
|
||||
*/
|
||||
function MenuLeft($db,&$menu_array)
|
||||
{
|
||||
require_once(DOL_DOCUMENT_ROOT."/admin/menus/module_menudb.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/menubase.class.php");
|
||||
|
||||
$this->db=$db;
|
||||
$this->menu_array=$menu_array;
|
||||
|
||||
$this->newmenu = new Menu();
|
||||
|
||||
$this->menuArbo = new menudb($this->db,'auguria','left');
|
||||
$this->menuArbo = new Menubase($this->db,'auguria','left');
|
||||
$this->overwritemenufor = $this->menuArbo->listeMainmenu();
|
||||
}
|
||||
|
||||
|
||||
@ -61,7 +61,7 @@ class MenuTop {
|
||||
*/
|
||||
function showmenu()
|
||||
{
|
||||
require_once(DOL_DOCUMENT_ROOT."/admin/menus/module_menudb.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/menubase.class.php");
|
||||
|
||||
global $user,$conf,$langs,$dolibarr_main_db_name;;
|
||||
|
||||
@ -85,7 +85,7 @@ class MenuTop {
|
||||
}
|
||||
|
||||
|
||||
$menuArbo = new MenuDb($this->db,'auguria','top');
|
||||
$menuArbo = new Menubase($this->db,'auguria','top');
|
||||
$tabMenu = $menuArbo->menutopCharger(0,$_SESSION['mainmenu']);
|
||||
|
||||
print '<ul>';
|
||||
|
||||
@ -61,7 +61,7 @@ class MenuTop {
|
||||
*/
|
||||
function showmenu()
|
||||
{
|
||||
require_once(DOL_DOCUMENT_ROOT."/admin/menus/module_menudb.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/menubase.class.php");
|
||||
|
||||
global $user,$conf,$langs,$dolibarr_main_db_name;;
|
||||
|
||||
@ -85,7 +85,7 @@ class MenuTop {
|
||||
}
|
||||
|
||||
|
||||
$menuArbo = new menudb($this->db,'auguria','top');
|
||||
$menuArbo = new Menubase($this->db,'auguria','top');
|
||||
$tabMenu = $menuArbo->menutopCharger(1,$_SESSION['mainmenu']);
|
||||
|
||||
print '<ul>';
|
||||
|
||||
@ -426,9 +426,9 @@ class MenuTop {
|
||||
|
||||
|
||||
// Affichage des menus personnalises
|
||||
require_once(DOL_DOCUMENT_ROOT."/admin/menus/module_menudb.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/menubase.class.php");
|
||||
|
||||
$menuArbo = new MenuDb($this->db,'eldy','top');
|
||||
$menuArbo = new Menubase($this->db,'eldy','top');
|
||||
$tabMenu = $menuArbo->menutopCharger(0,$_SESSION['mainmenu']);
|
||||
for($i=0;$i<count($tabMenu);$i++)
|
||||
{
|
||||
|
||||
@ -372,9 +372,9 @@ class MenuTop {
|
||||
|
||||
|
||||
// Affichage des menus personnalises
|
||||
require_once(DOL_DOCUMENT_ROOT."/admin/menus/module_menudb.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/menubase.class.php");
|
||||
|
||||
$menuArbo = new MenuDb($this->db,'eldy','top');
|
||||
$menuArbo = new Menubase($this->db,'eldy','top');
|
||||
$tabMenu = $menuArbo->menutopCharger(0,$_SESSION['mainmenu']);
|
||||
for($i=0;$i<count($tabMenu);$i++)
|
||||
{
|
||||
|
||||
@ -68,9 +68,9 @@ class MenuTop {
|
||||
|
||||
/*
|
||||
// Code to show personalized menus
|
||||
require_once(DOL_DOCUMENT_ROOT."/admin/menus/module_menudb.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/menubase.class.php");
|
||||
|
||||
$menuArbo = new MenuDb($this->db,'eldy','top');
|
||||
$menuArbo = new Menubase($this->db,'eldy','top');
|
||||
$tabMenu = $menuArbo->menutopCharger(0,$_SESSION['mainmenu']);
|
||||
for($i=0;$i<count($tabMenu);$i++)
|
||||
{
|
||||
|
||||
@ -374,9 +374,9 @@ class MenuTop {
|
||||
|
||||
|
||||
// Affichage des menus personnalises
|
||||
require_once(DOL_DOCUMENT_ROOT."/admin/menus/module_menudb.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/menubase.class.php");
|
||||
|
||||
$menuArbo = new MenuDb($this->db,'rodolphe','top');
|
||||
$menuArbo = new Menubase($this->db,'rodolphe','top');
|
||||
$tabMenu = $menuArbo->menutopCharger(0,$_SESSION['mainmenu']);
|
||||
for($i=0;$i<count($tabMenu);$i++)
|
||||
{
|
||||
|
||||
@ -18,4 +18,5 @@ ErrorFieldsRequired=Some required fields were not filled.
|
||||
ErrorFailedToCreateDir=Failed to create a directory. Check that Web server user has permissions to write into Dolibarr documents directory. If parameter <b>safe_mode</b> is enabled on this PHP, check that Dolibarr php files owns to web server user (or group).
|
||||
ErrorNoMailDefinedForThisUser=No mail defined for this user
|
||||
ErrorFeatureNeedJavascript=This feature need javascript to be activated to work. Change this in setup - display.
|
||||
ErrorTopMenuMustHaveAParentWithId0=A menu of type 'Top' can't have a parent menu. Put 0 in parent menu or choose a menu of type 'Left'.
|
||||
ErrorTopMenuMustHaveAParentWithId0=A menu of type 'Top' can't have a parent menu. Put 0 in parent menu or choose a menu of type 'Left'.
|
||||
ErrorLeftMenuMustHaveAParentId=A menu of type 'Left' must have a parent id.
|
||||
@ -18,4 +18,5 @@ ErrorFieldsRequired=Des champs obligatoires n'ont pas
|
||||
ErrorFailedToCreateDir=Echec a la creation d'un repertoire. Verifiez que le user du serveur Web a bien les droits d'ecriture dans les repertoires documents de Dolibarr. Si le parametre <b>safe_mode</b> a été activé sur ce PHP, vérifier que les fichiers php dolibarr appartiennent à l'utilisateur du serveur Web.
|
||||
ErrorNoMailDefinedForThisUser=EMail non defini pour cet utilisateur
|
||||
ErrorFeatureNeedJavascript=Cette fonctionnalité a besoin de javascript activé pour fonctionner. Modifier dans configuration - affichage.
|
||||
ErrorTopMenuMustHaveAParentWithId0=Un menu de type 'Top' ne peut avoir de menu père. Mettre 0 dans l'id père ou choisir un menu de type 'Left'.
|
||||
ErrorTopMenuMustHaveAParentWithId0=Un menu de type 'Top' ne peut avoir de menu père. Mettre 0 dans l'id père ou choisir un menu de type 'Left'.
|
||||
ErrorLeftMenuMustHaveAParentId=Un menu de type 'Left' doit avoir un id de père.
|
||||
@ -53,16 +53,16 @@ class Menubase
|
||||
var $user;
|
||||
var $tms;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Constructor
|
||||
* \param DB Database handler
|
||||
*/
|
||||
function Menubase($DB)
|
||||
function Menubase($DB,$menu_handler='',$type='')
|
||||
{
|
||||
$this->db = $DB;
|
||||
$this->menu_handler = $menu_handler;
|
||||
$this->type = $type;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -344,5 +344,249 @@ class Menubase
|
||||
$this->tms='';
|
||||
}
|
||||
|
||||
|
||||
function menuCharger($mainmenu, $newmenu, $type_user, $leftmenu)
|
||||
{
|
||||
|
||||
global $langs,$user, $conf;
|
||||
|
||||
$this->mainmenu = $mainmenu;
|
||||
$this->newmenu = $newmenu;
|
||||
$this->leftmenu = $leftmenu;
|
||||
|
||||
$sql = "SELECT m.rowid, m.titre, m.type";
|
||||
$sql.= " FROM " . MAIN_DB_PREFIX . "menu as m";
|
||||
$sql.= " WHERE m.mainmenu = '".$this->mainmenu."'";
|
||||
$sql.= " AND m.menu_handler= '".$this->menu_handler."'";
|
||||
$result = $this->db->query($sql);
|
||||
$menuTop = $this->db->fetch_object($result);
|
||||
|
||||
$data[] = array ($menutop->rowid,-1,$this->mainmenu);
|
||||
|
||||
$sql = "SELECT m.rowid, m.fk_menu, m.url, m.titre, m.langs, m.right, m.target, m.mainmenu, m.leftmenu";
|
||||
$sql.= " FROM " . MAIN_DB_PREFIX . "menu as m";
|
||||
$sql.= " WHERE m.menu_handler= '".$this->menu_handler."'";
|
||||
if($type_user == 0) $sql.= " AND m.user <> 1";
|
||||
else $sql.= " AND m.user > 0";
|
||||
$sql.= " ORDER BY m.order, m.rowid";
|
||||
|
||||
$res = $this->db->query($sql);
|
||||
if ($res)
|
||||
{
|
||||
$num = $this->db->num_rows();
|
||||
|
||||
$i = 1;
|
||||
while ($menu = $this->db->fetch_array($res)) {
|
||||
$langs->load($menu['langs']);
|
||||
$titre = $langs->trans($menu['titre']);
|
||||
$rights = $this->verifRights($menu['right']);
|
||||
$data[] = array (
|
||||
$menu['rowid'],
|
||||
$menu['fk_menu'],
|
||||
$menu['url'],
|
||||
$titre,
|
||||
$rights,
|
||||
$menu['target'],
|
||||
$menu['leftmenu']
|
||||
);
|
||||
$i++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
}
|
||||
|
||||
$this->recur($data, $menuTop->rowid, 1);
|
||||
|
||||
return $this->newmenu;
|
||||
|
||||
}
|
||||
|
||||
function recur($tab, $pere, $rang) {
|
||||
$leftmenu = $this->leftmenu;
|
||||
//ballayage du tableau
|
||||
for ($x = 0; $x < count($tab); $x++) {
|
||||
|
||||
//si un élément a pour père : $pere
|
||||
if ($tab[$x][1] == $pere) {
|
||||
|
||||
//on affiche le menu
|
||||
|
||||
if ($this->verifConstraint($tab[$x][0], $tab[$x][6], $tab[$x][7]) != 0) {
|
||||
|
||||
if ($tab[$x][6]) {
|
||||
|
||||
$leftmenuConstraint = false;
|
||||
$str = "if(" . $tab[$x][6] . ") \$leftmenuConstraint = true;";
|
||||
|
||||
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 {
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function verifConstraint($rowid, $mainmenu = "", $leftmenu = "")
|
||||
{
|
||||
global $user, $conf, $user;
|
||||
|
||||
$constraint = true;
|
||||
|
||||
$sql = "SELECT c.rowid, c.action, mc.user";
|
||||
$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 . "'";
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
//echo $sql;
|
||||
$num = $this->db->num_rows();
|
||||
$i = 0;
|
||||
while (($i < $num) && $constraint == true)
|
||||
{
|
||||
$obj = $this->db->fetch_object($result);
|
||||
$strconstraint = "if(!(" . $obj->action . ")) { \$constraint = false;}";
|
||||
|
||||
eval ($strconstraint);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
}
|
||||
|
||||
return $constraint;
|
||||
}
|
||||
|
||||
function verifRights($strRights) {
|
||||
|
||||
global $user,$conf,$user;
|
||||
|
||||
if ($strRights != "") {
|
||||
$rights = true;
|
||||
|
||||
$tab_rights = explode(" || ", $strRights);
|
||||
$i = 0;
|
||||
while (($i < count($tab_rights)) && ($rights == true)) {
|
||||
$str = "if(!(" . $strRights . ")) { \$rights = false;}";
|
||||
eval ($str);
|
||||
$i++;
|
||||
}
|
||||
} else
|
||||
$rights = true;
|
||||
|
||||
return $rights;
|
||||
}
|
||||
|
||||
function listeMainmenu()
|
||||
{
|
||||
$sql = "SELECT DISTINCT m.mainmenu";
|
||||
$sql.= " FROM " . MAIN_DB_PREFIX . "menu as m";
|
||||
$sql.= " WHERE m.menu_handler= '".$this->menu_handler."'";
|
||||
|
||||
$res = $this->db->query($sql);
|
||||
if ($res) {
|
||||
$i = 0;
|
||||
while ($menu = $this->db->fetch_array($res)) {
|
||||
$overwritemenufor[$i] = $menu['mainmenu'];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
}
|
||||
|
||||
return $overwritemenufor;
|
||||
}
|
||||
|
||||
|
||||
function menutopCharger($type_user,$mainmenu)
|
||||
{
|
||||
global $langs, $user, $conf;
|
||||
|
||||
$sql = "SELECT m.rowid, m.mainmenu, m.titre, m.url, m.langs, m.right";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."menu as m";
|
||||
$sql.= " WHERE m.type = 'top'";
|
||||
$sql.= " AND m.menu_handler= '".$this->menu_handler."'";
|
||||
if($type_user == 0) $sql.= " AND m.user <> 1";
|
||||
else $sql.= " AND m.user > 0";
|
||||
$sql.= " ORDER BY m.order";
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$numa = $this->db->num_rows();
|
||||
|
||||
$a = 0;
|
||||
$b = 0;
|
||||
while ($a < $numa)
|
||||
{
|
||||
// Affichage entete menu
|
||||
$objm = $this->db->fetch_object($result);
|
||||
|
||||
if ($this->verifConstraint($objm->rowid))
|
||||
{
|
||||
$langs->load($objm->langs);
|
||||
|
||||
$class="";
|
||||
if ($_SESSION["mainmenu"] && $_SESSION["mainmenu"] == $objm->mainmenu)
|
||||
{
|
||||
$class='id="sel"';
|
||||
}
|
||||
$chaine="";
|
||||
|
||||
$right = true;
|
||||
|
||||
if ($objm->right)
|
||||
{
|
||||
$str = "if(!(".$objm->right.")) \$right = false;";
|
||||
eval($str);
|
||||
}
|
||||
|
||||
if(eregi("/",$objm->titre))
|
||||
{
|
||||
$tab_titre = explode("/",$objm->titre);
|
||||
$chaine = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$chaine = $langs->trans($objm->titre);
|
||||
}
|
||||
|
||||
$tabMenu[$b]['titre'] = $chaine;
|
||||
$tabMenu[$b]['url'] = $objm->url;
|
||||
$tabMenu[$b]['atarget'] = $this->atarget;
|
||||
$tabMenu[$b]['class'] = $class;
|
||||
$tabMenu[$b]['right'] = $right;
|
||||
|
||||
$b++;
|
||||
|
||||
}
|
||||
|
||||
$a++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
}
|
||||
|
||||
return $tabMenu;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user