* Copyright (C) 2007-2012 Laurent Destailleur * Copyright (C) 2009-2011 Regis Houssin * Copyright (C) 2016 Meziane Sof * * 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 3 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, see . */ /** * \file htdocs/admin/menus/edit.php * \ingroup core * \brief Tool to edit menus */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php'; // Load translation files required by the page $langs->loadLangs(array("other", "admin")); $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button if (!$user->admin) accessforbidden(); $dirstandard = array(); $dirsmartphone = array(); $dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']); foreach ($dirmenus as $dirmenu) { $dirstandard[] = $dirmenu.'standard'; $dirsmartphone[] = $dirmenu.'smartphone'; } $action = GETPOST('action', 'aZ09'); $menu_handler_top = $conf->global->MAIN_MENU_STANDARD; $menu_handler_smartphone = $conf->global->MAIN_MENU_SMARTPHONE; $menu_handler_top = preg_replace('/_backoffice.php/i', '', $menu_handler_top); $menu_handler_top = preg_replace('/_frontoffice.php/i', '', $menu_handler_top); $menu_handler_smartphone = preg_replace('/_backoffice.php/i', '', $menu_handler_smartphone); $menu_handler_smartphone = preg_replace('/_frontoffice.php/i', '', $menu_handler_smartphone); $menu_handler = $menu_handler_top; if (GETPOST("handler_origine")) $menu_handler = GETPOST("handler_origine"); if (GETPOST("menu_handler")) $menu_handler = GETPOST("menu_handler"); /* * Actions */ if ($action == 'update') { if (!$cancel) { $leftmenu = ''; $mainmenu = ''; if (GETPOST('menuIdParent', 'alpha') && !is_numeric(GETPOST('menuIdParent', 'alpha'))) { $tmp = explode('&', GETPOST('menuIdParent', 'alpha')); foreach ($tmp as $s) { if (preg_match('/fk_mainmenu=/', $s)) { $mainmenu = preg_replace('/fk_mainmenu=/', '', $s); } if (preg_match('/fk_leftmenu=/', $s)) { $leftmenu = preg_replace('/fk_leftmenu=/', '', $s); } } } $menu = new Menubase($db); $result = $menu->fetch(GETPOST('menuId', 'int')); if ($result > 0) { $menu->titre = GETPOST('titre', 'alpha'); // deprecated $menu->title = GETPOST('titre', 'alpha'); $menu->leftmenu = GETPOST('leftmenu', 'aZ09'); $menu->url = GETPOST('url', 'alpha'); $menu->langs = GETPOST('langs', 'alpha'); $menu->position = GETPOST('position', 'int'); $menu->enabled = GETPOST('enabled', 'alpha'); $menu->perms = GETPOST('perms', 'alpha'); $menu->target = GETPOST('target', 'alpha'); $menu->user = GETPOST('user', 'alpha'); $menu->mainmenu = GETPOST('propertymainmenu', 'alpha'); if (is_numeric(GETPOST('menuIdParent', 'alpha'))) { $menu->fk_menu = GETPOST('menuIdParent', 'alpha'); } else { if (GETPOST('type', 'alpha') == 'top') $menu->fk_menu = 0; else $menu->fk_menu = -1; $menu->fk_mainmenu = $mainmenu; $menu->fk_leftmenu = $leftmenu; } $result = $menu->update($user); if ($result > 0) { setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs'); } else { setEventMessages($menu->error, $menu->errors, 'errors'); } } else { setEventMessages($menu->error, $menu->errors, 'errors'); } $action = "edit"; header("Location: ".DOL_URL_ROOT."/admin/menus/index.php?menu_handler=".$menu_handler); exit; } else { header("Location: ".DOL_URL_ROOT."/admin/menus/index.php?menu_handler=".$menu_handler); exit; } } if ($action == 'add') { if ($cancel) { header("Location: ".DOL_URL_ROOT."/admin/menus/index.php?menu_handler=".$menu_handler); exit; } $leftmenu = ''; $mainmenu = ''; if (GETPOST('menuId', 'alpha', 3) && !is_numeric(GETPOST('menuId', 'alpha', 3))) { $tmp = explode('&', GETPOST('menuId', 'alpha', 3)); foreach ($tmp as $s) { if (preg_match('/fk_mainmenu=/', $s)) { $mainmenu = preg_replace('/fk_mainmenu=/', '', $s); } if (preg_match('/fk_leftmenu=/', $s)) { $leftmenu = preg_replace('/fk_leftmenu=/', '', $s); } } } $langs->load("errors"); $error = 0; if (!$error && !$_POST['menu_handler']) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("MenuHandler")), null, 'errors'); $action = 'create'; $error++; } if (!$error && !$_POST['type']) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors'); $action = 'create'; $error++; } if (!$error && !$_POST['url']) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("URL")), null, 'errors'); $action = 'create'; $error++; } if (!$error && !$_POST['titre']) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Title")), null, 'errors'); $action = 'create'; $error++; } if (!$error && $_POST['menuId'] && $_POST['type'] == 'top') { setEventMessages($langs->trans("ErrorTopMenuMustHaveAParentWithId0"), null, 'errors'); $action = 'create'; $error++; } if (!$error && !$_POST['menuId'] && $_POST['type'] == 'left') { setEventMessages($langs->trans("ErrorLeftMenuMustHaveAParentId"), null, 'errors'); $action = 'create'; $error++; } if (!$error) { $menu = new Menubase($db); $menu->menu_handler = preg_replace('/_menu$/', '', GETPOST('menu_handler', 'aZ09')); $menu->type = GETPOST('type', 'alpha'); $menu->titre = GETPOST('titre', 'alpha'); // deprecated $menu->title = GETPOST('titre', 'alpha'); $menu->url = GETPOST('url', 'alpha'); $menu->langs = GETPOST('langs', 'alpha'); $menu->position = GETPOST('position', 'int'); $menu->enabled = GETPOST('enabled', 'alpha'); $menu->perms = GETPOST('perms', 'alpha'); $menu->target = GETPOST('target', 'alpha'); $menu->user = GETPOST('user', 'alpha'); $menu->mainmenu = GETPOST('propertymainmenu', 'alpha'); if (is_numeric(GETPOST('menuId', 'alpha', 3))) { $menu->fk_menu = GETPOST('menuId', 'alpha', 3); } else { if (GETPOST('type', 'alpha') == 'top') $menu->fk_menu = 0; else $menu->fk_menu = -1; $menu->fk_mainmenu = $mainmenu; $menu->fk_leftmenu = $leftmenu; } $result = $menu->create($user); if ($result > 0) { header("Location: ".DOL_URL_ROOT."/admin/menus/index.php?menu_handler=".GETPOST('menu_handler', 'aZ09')); exit; } else { $action = 'create'; setEventMessages($menu->error, $menu->errors, 'errors'); } } } // delete if ($action == 'confirm_delete' && $_POST["confirm"] == 'yes') { $this->db->begin(); $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu WHERE rowid = ".GETPOST('menuId', 'int'); $result = $db->query($sql); if ($result == 0) { $this->db->commit(); llxHeader(); setEventMessages($langs->trans("MenuDeleted"), null, 'mesgs'); llxFooter(); exit; } else { $this->db->rollback(); $reload = 0; $_GET["action"] = ''; } } /* * View */ $form = new Form($db); $formadmin = new FormAdmin($db); llxHeader('', $langs->trans("Menu")); if ($action == 'create') { print ''; print load_fiche_titre($langs->trans("NewMenu"), '', 'title_setup'); print '
'; print ''; dol_fiche_head(); print ''; // Id $parent_rowid = GETPOST('menuId', 'int'); if (GETPOST('menuId', 'int')) { $sql = "SELECT m.rowid, m.mainmenu, m.leftmenu, m.level, m.langs FROM ".MAIN_DB_PREFIX."menu as m WHERE m.rowid = ".GETPOST('menuId', 'int'); $res = $db->query($sql); if ($res) { while ($menu = $db->fetch_array($res)) { $parent_rowid = $menu['rowid']; $parent_mainmenu = $menu['mainmenu']; $parent_leftmenu = $menu['leftmenu']; $parent_langs = $menu['langs']; $parent_level = $menu['level']; } } } // Handler print ''; print ''; print ''; // User print ''; print ''; print ''; // Type print ''; // Mainmenu code print ''; print ''; print ''; // MenuId Parent print ''; if ($parent_rowid) { print ''; } else { print ''; } print ''; // Title print ''; // URL print ''; // Langs print ''; // Position print ''; // Target print ''; // Enabled print ''; // Perms print ''; print '
'.$langs->trans('MenuHandler').''; $formadmin->select_menu_families($menu_handler.(preg_match('/_menu/', $menu_handler) ? '' : '_menu'), 'menu_handler', array_merge($dirstandard, $dirsmartphone)); print ''.$langs->trans('DetailMenuHandler').'
'.$langs->trans('MenuForUsers').''.$langs->trans('DetailUser').'
'.$langs->trans('Type').''; if ($parent_rowid) { print $langs->trans('Left'); print ''; } else { print ''; } print ''.$langs->trans('DetailType').'
'.$langs->trans('MainMenuCode').''; print $langs->trans("Example").': mytopmenukey'; print '
'.$langs->trans('MenuIdParent').''.$parent_rowid.''.$langs->trans('DetailMenuIdParent'); print ', '.$langs->trans("Example").': fk_mainmenu=abc&fk_leftmenu=def'; print '
'.$langs->trans('Title').''.$langs->trans('DetailTitre').'
'.$langs->trans('URL').''.$langs->trans('DetailUrl').'
'.$langs->trans('LangFile').''.$langs->trans('DetailLangs').'
'.$langs->trans('Position').''.$langs->trans('DetailPosition').'
'.$langs->trans('Target').''.$langs->trans('DetailTarget').'
'.$langs->trans('Enabled').''.$langs->trans('DetailEnabled').'
'.$langs->trans('Rights').''.$langs->trans('DetailRight').'
'; dol_fiche_end(); print '
'; print ''; print '     '; print ''; print '
'; print '
'; } elseif ($action == 'edit') { print load_fiche_titre($langs->trans("ModifMenu"), '', 'title_setup'); print '
'; print '
'; print ''; print ''; print ''; dol_fiche_head(); print ''; $menu = new Menubase($db); $result = $menu->fetch(GETPOST('menuId', 'int')); //var_dump($menu); // Id print ''; // Module print ''; // Handler if ($menu->menu_handler == 'all') $handler = $langs->trans('AllMenus'); else $handler = $menu->menu_handler; print ''; // User print ''; // Type print ''; // Mainmenu code if ($menu->type == 'top') { print ''; /*if ($parent_rowid) { print ''; } else {*/ print ''; //} print ''; } // MenuId Parent print ''; $valtouse = $menu->fk_menu; if ($menu->fk_mainmenu) $valtouse = 'fk_mainmenu='.$menu->fk_mainmenu; if ($menu->fk_leftmenu) $valtouse .= '&fk_leftmenu='.$menu->fk_leftmenu; print ''; print ''; // Niveau //print ''; // Title print ''; // Url print ''; // Langs print ''; // Position print ''; // Target print ''; // Enabled print ''; // Perms print ''; print '
'.$langs->trans('Id').''.$menu->id.''.$langs->trans('DetailId').'
'.$langs->trans('MenuModule').''.$menu->module.''.$langs->trans('DetailMenuModule').'
'.$langs->trans('MenuHandler').''.$handler.''.$langs->trans('DetailMenuHandler').'
'.$langs->trans('MenuForUsers').''.$langs->trans('DetailUser').'
'.$langs->trans('Type').''.$langs->trans(ucfirst($menu->type)).''.$langs->trans('DetailType').'
'.$langs->trans('MainMenuCode').''.$parent_rowid.'mainmenu).'">'; print $langs->trans("Example").': mytopmenukey'; print '
'.$langs->trans('MenuIdParent'); print ''.$langs->trans('DetailMenuIdParent'); print ', '.$langs->trans("Example").': fk_mainmenu=abc&fk_leftmenu=def'; print '
'.$langs->trans('Level').''.$menu->level.''.$langs->trans('DetailLevel').'
'.$langs->trans('Title').''.$langs->trans('DetailTitre').'
'.$langs->trans('URL').''.$langs->trans('DetailUrl').'
'.$langs->trans('LangFile').''.$langs->trans('DetailLangs').'
'.$langs->trans('Position').''.$langs->trans('DetailPosition').'
'.$langs->trans('Target').''.$langs->trans('DetailTarget').'
'.$langs->trans('Enabled').''.$langs->trans('DetailEnabled'); if (!empty($menu->enabled)) print ' ('.$langs->trans("ConditionIsCurrently").': '.yn(dol_eval($menu->enabled, 1)).')'; print '
'.$langs->trans('Rights').''.$langs->trans('DetailRight'); if (!empty($menu->perms)) print ' ('.$langs->trans("ConditionIsCurrently").': '.yn(dol_eval($menu->perms, 1)).')'; print '
'; dol_fiche_end(); // Bouton print '
'; print ''; print '     '; print ''; print '
'; print '
'; print '
'; } // End of page llxFooter(); $db->close();