diff --git a/htdocs/admin/menus/edit.php b/htdocs/admin/menus/edit.php index 288cba1c5b9..0bbdc36f548 100644 --- a/htdocs/admin/menus/edit.php +++ b/htdocs/admin/menus/edit.php @@ -71,65 +71,6 @@ if (GETPOST("menu_handler")) { * Actions */ -if ($action == 'update') { - if (!$cancel) { - $leftmenu = ''; $mainmenu = ''; - if (GETPOST('menuIdParent', 'alphanohtml') && !is_numeric(GETPOST('menuIdParent', 'alphanohtml'))) { - $tmp = explode('&', GETPOST('menuIdParent', 'alphanohtml')); - 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->title = (string) GETPOST('titre', 'alphanohtml'); - $menu->leftmenu = (string) GETPOST('leftmenu', 'aZ09'); - $menu->url = (string) GETPOST('url', 'alphanohtml'); - $menu->langs = (string) GETPOST('langs', 'alphanohtml'); - $menu->position = (int) GETPOST('position', 'int'); - $menu->enabled = (string) GETPOST('enabled', 'alphanohtml'); - $menu->perms = (string) GETPOST('perms', 'alphanohtml'); - $menu->target = (string) GETPOST('target', 'alphanohtml'); - $menu->user = (string) GETPOST('user', 'alphanohtml'); - $menu->mainmenu = (string) GETPOST('propertymainmenu', 'alphanohtml'); - if (is_numeric(GETPOST('menuIdParent', 'alphanohtml'))) { - $menu->fk_menu = (int) GETPOST('menuIdParent', 'alphanohtml'); - } else { - if (GETPOST('type', 'alphanohtml') == '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); @@ -138,8 +79,8 @@ if ($action == 'add') { $leftmenu = ''; $mainmenu = ''; - if (GETPOST('menuId', 'alphanohtml', 3) && !is_numeric(GETPOST('menuId', 'alphanohtml', 3))) { - $tmp = explode('&', GETPOST('menuId', 'alphanohtml', 3)); + if (GETPOST('menuIdParent', 'alphanohtml') && !is_numeric(GETPOST('menuIdParent', 'alphanohtml'))) { + $tmp = explode('&', GETPOST('menuIdParent', 'alphanohtml')); foreach ($tmp as $s) { if (preg_match('/fk_mainmenu=/', $s)) { $mainmenu = preg_replace('/fk_mainmenu=/', '', $s); @@ -173,12 +114,12 @@ if ($action == 'add') { $action = 'create'; $error++; } - if (!$error && GETPOST('menuId', 'alphanohtml', 3) && GETPOST('type') == 'top') { + if (!$error && GETPOST('menuIdParent', 'alphanohtml') && GETPOST('type') == 'top') { setEventMessages($langs->trans("ErrorTopMenuMustHaveAParentWithId0"), null, 'errors'); $action = 'create'; $error++; } - if (!$error && !GETPOST('menuId', 'alphanohtml', 3) && GETPOST('type') == 'left') { + if (!$error && !GETPOST('menuIdParent', 'alphanohtml') && GETPOST('type') == 'left') { setEventMessages($langs->trans("ErrorLeftMenuMustHaveAParentId"), null, 'errors'); $action = 'create'; $error++; @@ -189,6 +130,7 @@ if ($action == 'add') { $menu->menu_handler = preg_replace('/_menu$/', '', GETPOST('menu_handler', 'aZ09')); $menu->type = (string) GETPOST('type', 'alphanohtml'); $menu->title = (string) GETPOST('titre', 'alphanohtml'); + $menu->prefix = (string) GETPOST('picto', 'restricthtmlallowclass'); $menu->url = (string) GETPOST('url', 'alphanohtml'); $menu->langs = (string) GETPOST('langs', 'alphanohtml'); $menu->position = (int) GETPOST('position', 'int'); @@ -197,8 +139,8 @@ if ($action == 'add') { $menu->target = (string) GETPOST('target', 'alphanohtml'); $menu->user = (string) GETPOST('user', 'alphanohtml'); $menu->mainmenu = (string) GETPOST('propertymainmenu', 'alphanohtml'); - if (is_numeric(GETPOST('menuId', 'alphanohtml', 3))) { - $menu->fk_menu = (int) GETPOST('menuId', 'alphanohtml', 3); + if (is_numeric(GETPOST('menuIdParent', 'alphanohtml'))) { + $menu->fk_menu = (int) GETPOST('menuIdParent', 'alphanohtml'); } else { if (GETPOST('type', 'alphanohtml') == 'top') { $menu->fk_menu = 0; @@ -220,6 +162,78 @@ if ($action == 'add') { } } +if ($action == 'update') { + if (!$cancel) { + $leftmenu = ''; $mainmenu = ''; + if (GETPOST('menuIdParent', 'alphanohtml') && !is_numeric(GETPOST('menuIdParent', 'alphanohtml'))) { + $tmp = explode('&', GETPOST('menuIdParent', 'alphanohtml')); + 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); + } + } + } + + $error = 0; + if (!$error && !GETPOST('url')) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("URL")), null, 'errors'); + $action = 'create'; + $error++; + } + + if (!$error) { + $menu = new Menubase($db); + $result = $menu->fetch(GETPOST('menuId', 'int')); + if ($result > 0) { + $menu->title = (string) GETPOST('titre', 'alphanohtml'); + $menu->prefix = (string) GETPOST('picto', 'restricthtmlallowclass'); + $menu->leftmenu = (string) GETPOST('leftmenu', 'aZ09'); + $menu->url = (string) GETPOST('url', 'alphanohtml'); + $menu->langs = (string) GETPOST('langs', 'alphanohtml'); + $menu->position = (int) GETPOST('position', 'int'); + $menu->enabled = (string) GETPOST('enabled', 'alphanohtml'); + $menu->perms = (string) GETPOST('perms', 'alphanohtml'); + $menu->target = (string) GETPOST('target', 'alphanohtml'); + $menu->user = (string) GETPOST('user', 'alphanohtml'); + $menu->mainmenu = (string) GETPOST('propertymainmenu', 'alphanohtml'); + if (is_numeric(GETPOST('menuIdParent', 'alphanohtml'))) { + $menu->fk_menu = (int) GETPOST('menuIdParent', 'alphanohtml'); + } else { + if (GETPOST('type', 'alphanohtml') == '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 { + $action = 'edit'; + } + } else { + header("Location: ".DOL_URL_ROOT."/admin/menus/index.php?menu_handler=".$menu_handler); + exit; + } +} + /* @@ -239,14 +253,14 @@ if ($action == 'create') { { if (jQuery("#topleft").val() == \'top\') { - jQuery("#menuId").prop("disabled", true); - jQuery("#menuId").val(\'\'); + jQuery("#menuIdParent").prop("disabled", true); + jQuery("#menuIdParent").val(\'\'); jQuery("#propertymainmenu").removeAttr("disabled"); jQuery("#propertymainmenu").val(\'\'); } if (jQuery("#topleft").val() == \'left\') { - jQuery("#menuId").removeAttr("disabled"); + jQuery("#menuIdParent").removeAttr("disabled"); jQuery("#propertymainmenu").prop("disabled", true); } } @@ -264,6 +278,7 @@ if ($action == 'create') { print dol_get_fiche_head(); + print '
| '.$langs->trans('MenuIdParent').' | '; if ($parent_rowid) { - print ''.$parent_rowid.' | '; + print ''.$parent_rowid.' | '; } else { - print ''; + print ' | '; } print ' | '.$langs->trans('DetailMenuIdParent'); print ', '.$langs->trans("Example").': fk_mainmenu=abc&fk_leftmenu=def'; @@ -342,17 +359,21 @@ if ($action == 'create') { print ' |
| '.$langs->trans('Title').' | '; print ''.$langs->trans('DetailTitre').' | ||||
| '.$langs->trans('Image').' | '; + print ''.$langs->trans('Example').': fa-global | ||||
| '.$langs->trans('URL').' | '; - print ''.$langs->trans('DetailUrl').' | '.$langs->trans('DetailUrl').' | '; // Langs print '|||
| '.$langs->trans('LangFile').' | '; - print ''.$langs->trans('DetailLangs').' | '.$langs->trans('DetailLangs').' | '; // Position print '|||
| '.$langs->trans('Position').' | '; - print ''.$langs->trans('DetailPosition').' | '.$langs->trans('DetailPosition').' | '; // Enabled print '|||
| '.$langs->trans('Enabled').' | '; @@ -371,6 +392,7 @@ if ($action == 'create') { print ''.$langs->trans('DetailTarget').' |