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 '