diff --git a/htdocs/admin/menus/edit.php b/htdocs/admin/menus/edit.php new file mode 100644 index 00000000000..c4d5026ed4a --- /dev/null +++ b/htdocs/admin/menus/edit.php @@ -0,0 +1,521 @@ + + * + * 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. + * + * $Id$ + * $Source$ + */ + +/** + \file htdocs/admin/menus/edit.php + \ingroup admin + \brief Edition des menus + \version $Revision$ +*/ + + + require("./pre.inc.php"); + + + + if (!$user->admin) + accessforbidden(); + + + + +if (isset($_GET["action"]) && $_GET["action"] == 'update') +{ + + + if(!$_POST['cancel']) + { + + $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m SET m.titre = '".$_POST['titre']."', m.leftmenu = '".$_POST['leftmenu']."', m.url = '".$_POST['url']."', m.langs = '".$_POST['langs']."', m.right = '".$_POST['right']."',m.target = '".$_POST['target']."', m.user = ".$_POST['user']." WHERE m.rowid = ".$_POST['menuId']; + $db->query($sql); + } + + if($_GET['return']) + { + header("location: index.php"); + } + else + { + header("location: edit.php?action=edit&menuId=".$_POST['menuId']); + } + + +} + +if (isset($_GET["action"]) && $_GET["action"] == 'add') +{ + + if($_POST['cancel']) + { + header("location:index.php"); + } + else + { + + if($_POST['level'] == -1) + { + $sql = "SELECT max(m.rowid) as maxId FROM ".MAIN_DB_PREFIX."menu as m WHERE m.level = ".$_POST['level']; + $result = $db->query($sql); + $lastMenu = $db->fetch_object($result); + $rowid = $lastMenu->maxId + 1; + + $sql = "SELECT max(m.order) as maxOrder FROM ".MAIN_DB_PREFIX."menu as m WHERE m.level = ".$_POST['level']; + $result = $db->query($sql); + $lastMenu = $db->fetch_object($result); + $order = $lastMenu->maxOrder + 1; + + } + elseif($_POST['level'] == 0) + { + + $sql = "SELECT max(m.rowid) as maxId FROM ".MAIN_DB_PREFIX."menu as m WHERE m.level = ".$_POST['level']; + $result = $db->query($sql); + $lastMenu = $db->fetch_object($result); + + $rowid = $lastMenu->maxId + 100 ; + + $sql = "SELECT max(m.order) as maxOrder FROM ".MAIN_DB_PREFIX."menu as m WHERE m.fk_menu = ".$_GET['menuId']; + $result = $db->query($sql); + $lastMenu = $db->fetch_object($result); + if(isset($lastMenu->maxOrder)) + { + $order = ($lastMenu->maxOrder) + 1; + } + else + { + $order = 0; + } + + } + elseif($_POST['level'] > 0) + { + + $parentId = round($_GET['menuId'] / 100); + + $sql = "SELECT max(m.rowid) as maxId FROM ".MAIN_DB_PREFIX."menu as m WHERE m.rowid LIKE '".$parentId."__' AND m.rowid <> '".$parentId."00'"; + $result = $db->query($sql); + $lastMenu = $db->fetch_object($result); + + if(isset($lastMenu->maxId)) + { + $rowid = ($lastMenu->maxId) + 1; + } + else + { + $rowid = ($parentId * 100) + 1; + } + + $sql = "SELECT max(m.order) as maxOrder FROM ".MAIN_DB_PREFIX."menu as m WHERE m.fk_menu = ".$_GET['menuId']; + $result = $db->query($sql); + $lastMenu = $db->fetch_object($result); + if(isset($lastMenu->maxOrder)) + { + $order = ($lastMenu->maxOrder) + 1; + } + else + { + $order = 0; + } + + } + + + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu VALUES($rowid, '".$_POST['mainmenu']."','".$_POST['leftmenu']."',".$_GET['menuId'].",'".$_POST['url']."','".$_POST['titre']."',".$_POST['level'].",'".$_POST['langs']."','".$_POST['right']."','',".$_POST['user'].",".$order.")"; + $db->query($sql); + + header("location: edit.php?action=edit&menuId=".$rowid); + } +} + + +if (isset($_GET["action"]) && $_GET["action"] == 'add_const') +{ + + if($_POST['type'] == 'prede') + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu_const(fk_menu, fk_constraint, user) VALUES(".$_POST['menuId'].",".$_POST['constraint'].",".$_POST['user'].")"; + } + 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, user) VALUES(".$_POST['menuId'].",".$constraint.",".$_POST['user'].")"; + } + + $db->query($sql); + + header("location:edit.php?action=edit&menuId=".$_POST['menuId']); + +} + +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) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu_constraint WHERE rowid = ".$_GET['constId']; + $db->query($sql); + } + + header("location:edit.php?action=edit&menuId=".$_GET['menuId']); +} + + + +if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') +{ + + + $sql = "SELECT c.rowid, c.fk_constraint FROM ".MAIN_DB_PREFIX."menu_const as c WHERE c.fk_menu = ".$_GET['menuId']; + $res = $db->query($sql); + if ($res) + { + + while ($obj = $db->fetch_object ($res)) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu_const WHERE rowid = ".$obj->rowid; + $db->query($sql); + + $sql = "SELECT count(rowid) as countId FROM ".MAIN_DB_PREFIX."menu_const WHERE fk_constraint = ".$obj->fk_constraint; + $result = $db->query($sql); + $objc = $db->fetch_object($result); + + if($objc->countId == 0) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu_constraint WHERE rowid = ".$obj->fk_constraint; + $db->query($sql); + } + } + + + + } +; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu WHERE rowid = ".$_GET['menuId']; + $db->query($sql); + + if ($result == 0) + { + llxHeader(); + print '
'.$langs->trans("MenuDeleted").'
'; + llxFooter(); + exit ; + } + else + { + $reload = 0; + $_GET["action"]=''; + } +} + + + +/* + * Affichage page + */ + +llxHeader(); + + + +if (isset($_GET["action"]) && $_GET["action"] == 'create') +{ + print_titre($langs->trans("NewMenu"),'','setup'); + + print '
'; + + print ''; + + if($_GET['menuId'] == 0) + { + $parent_rowid = $_GET['menuId']; + $parent_level = -2; + } + else + { + $sql = "SELECT m.rowid, m.mainmenu, m.level, m.langs FROM ".MAIN_DB_PREFIX."menu as m WHERE m.rowid = ".$_GET['menuId']; + $res = $db->query($sql); + + if ($res) + { + + while ($menu = $db->fetch_array ($res)) + { + $parent_rowid = $menu['rowid']; + $parent_mainmenu = $menu['mainmenu']; + $parent_langs = $menu['langs']; + $parent_level = $menu['level']; + } + } + } + //Titre + print ''; + //Mainmenu + print ''; + //Level + print ''; + //URL + print ''; + //Leftmenu + print ''; + //Langs + print ''; + //Right + print ''; + //User + print ''; + print ''; + print ''; + // target + print ''; + print ''; + + print '
'.$langs->trans('Titre').''.$langs->trans('DetailTitre').'
'.$langs->trans('Mainmenu').''.$langs->trans('DetailMainmenu').'
'.$langs->trans('URL').''.$langs->trans('DetailUrl').'
'.$langs->trans('Leftmenu').''.$langs->trans('DetailLeftmenu').'
'.$langs->trans('Langs').''.$langs->trans('DetailLangs').'
'.$langs->trans('Right').''.$langs->trans('DetailRight').'
'.$langs->trans('User').''.$langs->trans('DetailUser').'
'.$langs->trans('Target').''.$langs->trans('DetailTarget').'
'; + print ' '; + print '
'; + + + + + + + + + print '
'; + + +} + +elseif (isset($_GET["action"]) && $_GET["action"] == 'edit') +{ + print_titre($langs->trans("ModifMenu"),'','setup'); + + print '
'; + + print ''; + + + $sql = "SELECT m.rowid, m.titre, m.mainmenu, m.leftmenu, m.fk_menu, m.url, m.langs, m.level, m.right, m.target, m.user, m.order FROM ".MAIN_DB_PREFIX."menu as m WHERE m.rowid = ".$_GET['menuId']; + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows(); + $i = 0; + + while($i < $num) + { + $menu = $db->fetch_object($result); + + + // rowid + print ''; + print ''; + // titre + print ''; + // mainmenu + print ''; + // Niveau + print ''; + // url + print ''; + // Leftmenu + print ''; + // langs + print ''; + // right + print ''; + // user + print ''; + // target + print ''; + + // Bouton + print ''; + + $i++; + } + } + + print ''; + + /* + * Lignes de contraintes + */ + $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 c.rowid = mc.fk_constraint '; + $sql.= 'AND mc.fk_menu = '.$_GET['menuId']; + + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + + print '
'.$langs->trans('rowid').''.$menu->rowid.''.$langs->trans('DetailId').'
'.$langs->trans('Titre').''.$langs->trans('DetailTitre').'
'.$langs->trans('Mainmenu').''.$langs->trans('DetailMainmenu').'
'.$langs->trans('Level').''.$menu->level.''.$langs->trans('DetailLevel').'
'.$langs->trans('URL').''.$langs->trans('DetailUrl').'
'.$langs->trans('Leftmenu').''.$langs->trans('DetailLeftmenu').'
'.$langs->trans('Langs').''.$langs->trans('DetailLangs').'
'.$langs->trans('Right').''.$langs->trans('DetailRight').'
'.$langs->trans('User').''.$langs->trans('DetailUser').'
'.$langs->trans('Target').''.$langs->trans('DetailTarget').'
'; + print ' '; + print '
'; + if ($num) + { + print ''; + print ''; + print ''; + print ''; + print "\n"; + } + $var=true; + + $var = true; + while ($i < $num) + { + $objc = $db->fetch_object($resql); + + $var = !$var; + print ''; + print ''; + print ''; + print ''; + + $i++; + } + + print ''; + print ''; + print ''; + print ''; + print "\n"; + + + // Ajout de contraintes personalisés + print ''; + print ''; + print ''; + + $var=true; + print ''; + print ' '; + print ''; + print ''; + print ''; + print ''; + + + // Ajout de contraintes prédéfinis + print ''; + print ''; + print ''; + + $var=!$var; + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + + print '
'.$langs->trans('Constraint').''.$langs->trans('User').' 
'.$objc->action.''; + + switch ($objc->user) + { + case 0: print 'Interne'; + break; + case 1: print 'Externe'; + break; + case 2: print 'Tous'; + break; + } + print ''.img_delete().'
'.$langs->trans('Constraint').''.$langs->trans('User').' 
'; + print '
'; + print ''; + print ''; + print '
'; + $db->free($resql); + } + + + print ''; + + + + print '
'; + + print ''.$langs->trans('Valid').''; + print ''.$langs->trans('Supprimer').''; + print '
'; + + +} + + + + + +?> diff --git a/htdocs/admin/menus/images/arbre-deplier.png b/htdocs/admin/menus/images/arbre-deplier.png new file mode 100644 index 00000000000..31fcf9beee6 Binary files /dev/null and b/htdocs/admin/menus/images/arbre-deplier.png differ diff --git a/htdocs/admin/menus/images/arbre-plier.png b/htdocs/admin/menus/images/arbre-plier.png new file mode 100644 index 00000000000..88836226b9c Binary files /dev/null and b/htdocs/admin/menus/images/arbre-plier.png differ diff --git a/htdocs/admin/menus/images/arbre-puce.png b/htdocs/admin/menus/images/arbre-puce.png new file mode 100644 index 00000000000..90b2120f9e8 Binary files /dev/null and b/htdocs/admin/menus/images/arbre-puce.png differ diff --git a/htdocs/admin/menus/images/arbre-trait.png b/htdocs/admin/menus/images/arbre-trait.png new file mode 100644 index 00000000000..8bca16b5b9b Binary files /dev/null and b/htdocs/admin/menus/images/arbre-trait.png differ diff --git a/htdocs/admin/menus/index.php b/htdocs/admin/menus/index.php new file mode 100644 index 00000000000..f1a5a7920c6 --- /dev/null +++ b/htdocs/admin/menus/index.php @@ -0,0 +1,375 @@ + + * + * 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. + * + * $Id$ + * $Source$ + */ + +/** + \file htdocs/admin/menus/index.php + \ingroup admin + \brief Gestion des menus + \version $Revision$ +*/ + + + require("./pre.inc.php"); + + + + if (!$user->rights->menudb->creer) + accessforbidden(); + + +if (isset($_GET["action"]) && $_GET["action"] == 'up') +{ + + $sql = "SELECT m.rowid, m.order FROM ".MAIN_DB_PREFIX."menu as m WHERE m.rowid = ".$_GET["menuId"]; + $result = $db->query($sql); + + $num = $db->num_rows(); + $i = 0; + + while($i < $num) + { + $obj = $db->fetch_object($result); + $precedent['rowid'] = $obj->rowid; + $precedent['order'] = $obj->order; + $i++; + } + + $sql = "SELECT m.rowid, m.order FROM ".MAIN_DB_PREFIX."menu as m WHERE m.order = ".($precedent['order'] - 1)." AND m.level = -1"; + $result = $db->query($sql); + + $num = $db->num_rows(); + $i = 0; + + while($i < $num) + { + $obj = $db->fetch_object($result); + $suivant['rowid'] = $obj->rowid; + $suivant['order'] = $obj->order; + $i++; + } + + $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m SET m.order = ".$suivant['order']." WHERE m.rowid = ".$precedent['rowid'].""; // Monte celui select + $db->query($sql); + $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m SET m.order = ".$precedent['order']." WHERE m.rowid = ".$suivant['rowid'].""; // Descend celui du dessus + $db->query($sql); +} + +if (isset($_GET["action"]) && $_GET["action"] == 'down') +{ + + $sql = "SELECT m.rowid, m.order FROM ".MAIN_DB_PREFIX."menu as m WHERE m.rowid = ".$_GET["menuId"]; + $result = $db->query($sql); + + $num = $db->num_rows(); + $i = 0; + + while($i < $num) + { + $obj = $db->fetch_object($result); + $precedent['rowid'] = $obj->rowid; + $precedent['order'] = $obj->order; + $i++; + } + + $sql = "SELECT m.rowid, m.order FROM ".MAIN_DB_PREFIX."menu as m WHERE m.order = ".($precedent['order'] + 1)." AND m.level = -1"; + $result = $db->query($sql); + + $num = $db->num_rows(); + $i = 0; + + while($i < $num) + { + $obj = $db->fetch_object($result); + $suivant['rowid'] = $obj->rowid; + $suivant['order'] = $obj->order; + $i++; + } + + $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m SET m.order = ".$suivant['order']." WHERE m.rowid = ".$precedent['rowid'].""; // Monte celui select + $db->query($sql); + $sql = "UPDATE ".MAIN_DB_PREFIX."menu as m SET m.order = ".$precedent['order']." WHERE m.rowid = ".$suivant['rowid'].""; // Descend celui du dessus + $db->query($sql); +} + + + +/* + * Affichage page + */ + +llxHeader(); + + + +print_fiche_titre($langs->trans("Admin Menu"),'','setup'); + +print '
'; + +if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') +{ + + + $sql = "SELECT c.rowid, c.fk_constraint FROM ".MAIN_DB_PREFIX."menu_const as c WHERE c.fk_menu = ".$_GET['menuId']; + $res = $db->query($sql); + if ($res) + { + + while ($obj = $db->fetch_object ($res)) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu_const WHERE rowid = ".$obj->rowid; + $db->query($sql); + + $sql = "SELECT count(rowid) as countId FROM ".MAIN_DB_PREFIX."menu_const WHERE fk_constraint = ".$obj->fk_constraint; + $result = $db->query($sql); + $objc = $db->fetch_object($result); + + if($objc->countId == 0) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu_constraint WHERE rowid = ".$obj->fk_constraint; + $db->query($sql); + } + } + + + + } +; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu WHERE rowid = ".$_GET['menuId']; + $db->query($sql); + + if ($result == 0) + { + llxHeader(); + print '
'.$langs->trans("MenuDeleted").'
'; + llxFooter(); + exit ; + } + else + { + $reload = 0; + $_GET["action"]=''; + } +} + +// Confirmation de la suppression de la facture +if ($_GET["action"] == 'delete') +{ + + $sql = "SELECT m.titre FROM ".MAIN_DB_PREFIX."menu as m WHERE m.rowid = ".$_GET['menuId']; + $result = $db->query($sql); + $obj = $db->fetch_object($result); + + $html = new Form($db); + $html->form_confirm("index.php?menuId=".$_GET['menuId'],$langs->trans("DeleteMenu"),$langs->trans("ConfirmDeleteMenu")." ".$obj->titre,"confirm_delete"); + print "
\n"; +} + + + + + +print ''; +print ''; +print ''; + +print ''; +print ''; +print ''; + + print ''; + + print '
'.$langs->trans("TreeMenu").'
'; + + +/************************* + * ARBORESCENCE * + *************************/ + + +/* cette fonction gère le décallage des éléments + suivant leur position dans l'arborescence +*/ + + + +$rangLast = 0; +$idLast = -1; +if ($conf->use_javascript) +{ + print ''; +} + +function affiche($tab,$rang) +{ + global $rangLast, $idLast; + + if ($conf->use_javascript) + { + if($rang == $rangLast) + { + print ''; + } + elseif($rang > $rangLast) + { + + print '
    • '; + + } + elseif($rang < $rangLast) + { + print ''; + + for($i=$rang; $i < $rangLast; $i++) + { + print '
  • '; + echo "\n"; + } + + } + } + else + { + if($rang > $rangLast) + { + + print '
    • '; + + } + elseif($rang < $rangLast) + { + + for($i=$rang; $i < $rangLast; $i++) + { + print '
  • '; + echo "\n"; + } + + } + } + + print '
  • '; + print ''.$tab[2].''; + print ''; + print ''; + print ''; + print ''; + print '
  • '; + echo "\n"; + + $rangLast = $rang; + $idLast = $tab[0]; + + + + + +} + +/*fonction récursive d'affichage de l'arbre + $tab :tableau des éléments + $pere :index de l'élément courrant + $rang :décallage de l'élément +*/ +function recur($tab,$pere,$rang) { + + //ballayage du tableau + for ($x=0;$xquery($sql); + +if ($res) +{ + $num = $db->num_rows(); + + $i = 1; + while ($menu = $db->fetch_array ($res)) + { + $langs->load($menu['langs']); + $titre = $langs->trans($menu['titre']); + $data[] = array($menu['rowid'],$menu['fk_menu'],$titre); + $i++; + } +} + + //appelle de la fonction récursive (ammorce) + //avec recherche depuis la racine. + print '
      '; + recur($data,0,0); + print ''; + print '
    '; + + + + + print '
    '; + print '
    '; + + + + +print ''; + +print '
    '; +print ''.$langs->trans("NewMenu").''; +print '
    '; + + + + + + + +?> diff --git a/htdocs/admin/menus/menu.js b/htdocs/admin/menus/menu.js new file mode 100644 index 00000000000..19e0ee82462 --- /dev/null +++ b/htdocs/admin/menus/menu.js @@ -0,0 +1,171 @@ +/* ----------------------------------------------------- + +-------------------------------------------------------- */ +// Tests pour navigateurs +var OPE = (window.opera) ? true : false; +var IE = (document.all && !OPE) ? true : false; +var MOZ = (!IE && !OPE) ? true : false; +// ----------------------------------------------------- +// Fonction d'initialisation de l'arbre +function arbre() { + // Choix de la balise contenant le texte. par defaut. + balise = "STRONG"; + // Presentation de l'arbre au depart : deployee ('yes') ou fermee ('no') + extend = "yes"; + // Textes du lien plier / deplier + plier_text = 'Replier tout'; + plier_title = 'Replier tous les noeuds de l\'arbre' + deplier_text = 'Deplier tout'; + deplier_title = 'Deplier tous les noeuds de l\'arbre' + // Recuperation de tous les arbres de la page + uls = getElBy('ul','class','arbre'); + for (uli=0;uli + * + * 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' + \version $Revision$ +*/ + +class menuDb { + var $newmenu; + var $mainmenu; + var $leftmenu; + + function menuDb($db) { + $this->db = $db; + } + + 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.level FROM " . MAIN_DB_PREFIX . "menu as m WHERE m.mainmenu = '" . $this->mainmenu . "'"; + $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 FROM " . MAIN_DB_PREFIX . "menu as m "; + if($type_user == 0)$sql.= "WHERE m.user <> 1 "; + else $sql.= "WHERE 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++; + + } + + } + + $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 FROM " . MAIN_DB_PREFIX . "menu_constraint as c, " . MAIN_DB_PREFIX . "menu_const as mc 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++; + } + } + + 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 FROM " . MAIN_DB_PREFIX . "menu as m"; + $res = $this->db->query($sql); + + if ($res) { + $i = 0; + while ($menu = $this->db->fetch_array($res)) { + $overwritemenufor[$i] = $menu['mainmenu']; + $i++; + } + } + + 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 FROM ".MAIN_DB_PREFIX."menu as m WHERE m.level = -1 "; + 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++; + } + } + + return $tabMenu; + + } +} +?> diff --git a/htdocs/admin/menus/pre.inc.php b/htdocs/admin/menus/pre.inc.php new file mode 100644 index 00000000000..3ab20ed9509 --- /dev/null +++ b/htdocs/admin/menus/pre.inc.php @@ -0,0 +1,191 @@ + + * + * 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. + * + * $Id$ + * $Source$ + */ + + +/** + \file htdocs/admin/menus/pre.inc.php + \brief Fichier gestionnaire du menu de gauche de l'accueil + \version $Revision$ +*/ + +require ("../../main.inc.php"); +$user->getrights(); + +function llxHeader($head = "") +{ + global $user, $conf, $langs; + + top_menu($head); + + $menu = new Menu(); + + if ($conf->societe->enabled && $user->rights->societe->lire) + { + $langs->load("companies"); + $menu->add(DOL_URL_ROOT."/societe.php", $langs->trans("Companies")); + + if ($user->rights->societe->creer) + { + $menu->add_submenu(DOL_URL_ROOT."/soc.php?action=create", $langs->trans("MenuNewCompany")); + } + + if(is_dir("societe/groupe")) + { + $menu->add_submenu(DOL_URL_ROOT."/societe/groupe/index.php", $langs->trans("MenuSocGroup")); + } + $menu->add_submenu(DOL_URL_ROOT."/contact/index.php",$langs->trans("Contacts")); + } + + if ($conf->commercial->enabled && $user->rights->commercial->lire) + { + $langs->load("commercial"); + $menu->add(DOL_URL_ROOT."/comm/index.php",$langs->trans("Commercial")); + + $menu->add_submenu(DOL_URL_ROOT."/comm/clients.php",$langs->trans("Customers")); + $menu->add_submenu(DOL_URL_ROOT."/comm/prospect/prospects.php",$langs->trans("Prospects")); + + if ($user->rights->propale->lire) + { + $langs->load("propal"); + $menu->add_submenu(DOL_URL_ROOT."/comm/propal.php", $langs->trans("Prop")); + } + } + + if ($conf->compta->enabled || $conf->comptaexpert->enabled) + { + $langs->load("compta"); + $menu->add(DOL_URL_ROOT."/compta/index.php", $langs->trans("MenuFinancial")); + + if ($user->rights->facture->lire) { + $langs->load("bills"); + $menu->add_submenu(DOL_URL_ROOT."/compta/facture.php", $langs->trans("Bills")); + } + } + + if ($conf->fichinter->enabled && $user->rights->ficheinter->lire) + { + $langs->trans("interventions"); + $menu->add(DOL_URL_ROOT."/fichinter/index.php", $langs->trans("Interventions")); + } + + if (($conf->produit->enabled || $conf->service->enabled) && $user->rights->produit->lire) + { + $langs->load("products"); + $chaine=""; + if ($conf->produit->enabled) { $chaine.= $langs->trans("Products"); } + if ($conf->produit->enabled && $conf->service->enabled) { $chaine.="/"; } + if ($conf->service->enabled) { $chaine.= $langs->trans("Services"); } + $menu->add(DOL_URL_ROOT."/product/index.php", "$chaine"); + +/* + if ($conf->boutique->enabled) + { + if ($conf->boutique->livre->enabled) + { + $menu->add_submenu(DOL_URL_ROOT."/boutique/livre/index.php", "Livres"); + } + + if ($conf->boutique->album->enabled) + { + $menu->add_submenu(DOL_URL_ROOT."/product/album/index.php", "Albums"); + } + } +*/ + } + + + if ($conf->commande->enabled && $user->rights->commande->lire) + { + $langs->load("orders"); + $menu->add(DOL_URL_ROOT."/commande/index.php", $langs->trans("Orders")); + } + + if ($conf->expedition->enabled && $user->rights->expedition->lire) + { + $langs->load("sendings"); + $menu->add(DOL_URL_ROOT."/expedition/index.php", $langs->trans("Sendings")); + } + + if ($conf->mailing->enabled && $user->rights->mailing->lire) + { + $langs->load("mails"); + $menu->add(DOL_URL_ROOT."/comm/mailing/index.php",$langs->trans("EMailings")); + } + + if ($conf->telephonie->enabled) + { + $menu->add(DOL_URL_ROOT."/telephonie/index.php", "Téléphonie"); + } + + if ($conf->don->enabled) + { + $menu->add(DOL_URL_ROOT."/compta/dons/index.php", $langs->trans("Donations")); + } + + if ($conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire) + { + $langs->load("suppliers"); + $menu->add(DOL_URL_ROOT."/fourn/index.php", $langs->trans("Suppliers")); + } + + if ($conf->voyage->enabled && $user->societe_id == 0) + { + $menu->add(DOL_URL_ROOT."/compta/voyage/index.php","Voyages"); + $menu->add_submenu(DOL_URL_ROOT."/compta/voyage/index.php","Voyages"); + $menu->add_submenu(DOL_URL_ROOT."/compta/voyage/reduc.php","Reduc"); + } + + if ($conf->domaine->enabled) + { + $menu->add(DOL_URL_ROOT."/domain/index.php", "Domaines"); + } + + if ($conf->postnuke->enabled) + { + $menu->add(DOL_URL_ROOT."/postnuke/articles/index.php", "Editorial"); + } + + if ($conf->bookmark->enabled && $user->rights->bookmark->lire) + { + $menu->add(DOL_URL_ROOT."/bookmarks/liste.php", $langs->trans("Bookmarks")); + } + + if ($conf->export->enabled) + { + $langs->load("exports"); + $menu->add(DOL_URL_ROOT."/exports/index.php", $langs->trans("Exports")); + } + + if ($user->rights->user->user->lire || $user->admin) + { + $langs->load("users"); + $menu->add(DOL_URL_ROOT."/user/home.php", $langs->trans("MenuUsersAndGroups")); + } + + if ($user->admin) + { + $menu->add(DOL_URL_ROOT."/admin/index.php", $langs->trans("Setup")); + } + + + left_menu($menu->liste); +} +?> diff --git a/htdocs/includes/menus/barre_left/auguria_backoffice.php b/htdocs/includes/menus/barre_left/auguria_backoffice.php new file mode 100644 index 00000000000..8c8c01b53b2 --- /dev/null +++ b/htdocs/includes/menus/barre_left/auguria_backoffice.php @@ -0,0 +1,229 @@ + + * + * 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. + * + * $Id$ + * $Source$ + */ + +/** + \file htdocs/includes/menus/barre_left/auguria_backoffice.php + \brief Gestionnaire du menu du gauche Auguria + \version $Revision$ + + \remarks La construction d'un gestionnaire pour le menu de gauche est simple: + \remarks A l'aide d'un objet $newmenu=new Menu() et des méthode add et add_submenu, + \remarks définir la liste des entrées menu à faire apparaitre. + \remarks En fin de code, mettre la ligne $menu=$newmenu->liste. + \remarks Ce qui est défini dans un tel gestionnaire sera alors prioritaire sur + \remarks les définitions de menu des fichiers pre.inc.php +*/ + + +/** + \class MenuLeft + \brief Classe permettant la gestion du menu du gauche Auguria +*/ + +class MenuLeft { + + var $require_top=array("auguria_backoffice"); // Si doit etre en phase avec un gestionnaire de menu du haut particulier + var $newmenu; + var $menuArbo; + + var $overwritemenufor = array(); + var $leftmenu; + + + /** + * \brief Constructeur + * \param db Handler d'accès base de donnée + * \param menu_array Tableau des entrée de menu défini dans les fichier pre.inc.php + */ + function MenuLeft($db,&$menu_array) + { + + require_once(DOL_DOCUMENT_ROOT."/admin/menus/module_menudb.php"); + + $this->db=$db; + $this->menu_array=$menu_array; + $this->newmenu = new Menu(); + + $this->menuArbo = new menudb($this->db); + $this->overwritemenufor = $this->menuArbo->listeMainmenu(); + + } + + + /** + * \brief Affiche le menu + */ + function showmenu() + { + global $user,$conf,$langs,$dolibarr_main_db_name; + + + + + if (! session_id()) { + session_name("DOLSESSID_".$dolibarr_main_db_name); + session_start(); // En mode authentification PEAR, la session a déjà été ouverte + } + + $user->getrights(""); + + // On récupère mainmenu et leftmenu qui définissent le menu à afficher + if (isset($_GET["mainmenu"])) { + // On sauve en session le menu principal choisi + $mainmenu=$_GET["mainmenu"]; + $_SESSION["mainmenu"]=$mainmenu; + $_SESSION["leftmenuopened"]=""; + } else { + // On va le chercher en session si non défini par le lien + $mainmenu=$_SESSION["mainmenu"]; + } + + if (isset($_GET["leftmenu"])) { + // On sauve en session le menu principal choisi + $this->leftmenu=$_GET["leftmenu"]; + $_SESSION["leftmenu"]=$this->leftmenu; + if ($_SESSION["leftmenuopened"]==$this->leftmenu) { + //$leftmenu=""; + $_SESSION["leftmenuopened"]=""; + } + else { + $_SESSION["leftmenuopened"]=$this->leftmenu; + } + } else { + // On va le chercher en session si non défini par le lien + $this->leftmenu=isset($_SESSION["leftmenu"])?$_SESSION["leftmenu"]:''; + } + + + + /** + * On definit newmenu en fonction de mainmenu et leftmenu + * ------------------------------------------------------ + */ + if ($mainmenu) + { + + + $this->newmenu = $this->menuArbo->menuCharger($mainmenu, $this->newmenu,0,$this->leftmenu); + + + /* + * Menu AUTRES (Pour les menus du haut qui ne serait pas gérés) + */ + + if ($mainmenu && ! in_array($mainmenu,$this->overwritemenufor)) { $mainmenu=""; } + + } + + + + /** + * Si on est sur un cas géré de surcharge du menu, on ecrase celui par defaut + */ + if ($mainmenu) { + $this->menu_array=$this->newmenu->liste; + } + + + + + // Affichage du menu + $alt=0; + if (! sizeof($this->menu_array)) + { + print '
    '."\n"; + print $langs->trans("NoPermission"); + print '
    '; + } + else + { + $contenu = 0; + for ($i = 0 ; $i < sizeof($this->menu_array) ; $i++) + { + $alt++; + if ($this->menu_array[$i]['level']==0) { + if (($alt%2==0)) + { + print '