diff --git a/htdocs/admin/menus/edit.php b/htdocs/admin/menus/edit.php index d7c5a3bf49b..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); } } @@ -275,7 +289,9 @@ if ($action == 'create') { $parent_level = ''; 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'); + $sql = "SELECT m.rowid, m.mainmenu, m.leftmenu, m.level, m.langs"; + $sql .= " FROM ".MAIN_DB_PREFIX."menu as m"; + $sql .= " WHERE m.rowid = ".((int) GETPOST('menuId', 'int')); $res = $db->query($sql); if ($res) { while ($menu = $db->fetch_array($res)) { @@ -331,9 +347,9 @@ if ($action == 'create') { // MenuId Parent 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'; @@ -343,17 +359,21 @@ if ($action == 'create') { print ''.$langs->trans('Title').''; print ''.$langs->trans('DetailTitre').''; + // Picto + print ''.$langs->trans('Image').''; + print ''.$langs->trans('Example').': fa-global'; + // URL print ''.$langs->trans('URL').''; - print ''.$langs->trans('DetailUrl').''; + print ''.$langs->trans('DetailUrl').''; // Langs print ''.$langs->trans('LangFile').''; - print ''.$langs->trans('DetailLangs').''; + print ''.$langs->trans('DetailLangs').''; // Position print ''.$langs->trans('Position').''; - print ''.$langs->trans('DetailPosition').''; + print ''.$langs->trans('DetailPosition').''; // Enabled print ''.$langs->trans('Enabled').''; @@ -383,7 +403,8 @@ if ($action == 'create') { print load_fiche_titre($langs->trans("ModifMenu"), '', 'title_setup'); print '
'; - print '
'; + print ''; + print ''; print ''; print ''; print ''; @@ -434,7 +455,7 @@ if ($action == 'create') { } else {*/ - print 'mainmenu).'">'; + print 'mainmenu).'">'; //} print ''; print $langs->trans("Example").': mytopmenukey'; @@ -451,7 +472,7 @@ if ($action == 'create') { if ($menu->fk_leftmenu) { $valtouse .= '&fk_leftmenu='.$menu->fk_leftmenu; } - print ''; + print ''; print ''.$langs->trans('DetailMenuIdParent'); print ', '.$langs->trans("Example").': fk_mainmenu=abc&fk_leftmenu=def'; print ''; @@ -463,9 +484,13 @@ if ($action == 'create') { print ''.$langs->trans('Title').''; print ''.$langs->trans('DetailTitre').''; - // Url + // URL print ''.$langs->trans('URL').''; - print ''.$langs->trans('DetailUrl').''; + print ''.$langs->trans('DetailUrl').''; + + // Picto + print ''.$langs->trans('Image').''; + print ''.$langs->trans('Example').': fa-global'; // Langs print ''.$langs->trans('LangFile').''; @@ -473,7 +498,7 @@ if ($action == 'create') { // Position print ''.$langs->trans('Position').''; - print ''.$langs->trans('DetailPosition').''; + print ''.$langs->trans('DetailPosition').''; // Enabled print ''.$langs->trans('Enabled').''; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 5b47c3d31b6..5e1af04dc5f 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -955,8 +955,6 @@ function checkVal($out = '', $check = 'alphanohtml', $filter = null, $options = */ function sanitizeVal($out = '', $check = 'alphanohtml', $filter = null, $options = null) { - global $conf; - // TODO : use class "Validate" to perform tests (and add missing tests) if needed for factorize // Check is done after replacement switch ($check) { @@ -1044,8 +1042,9 @@ function sanitizeVal($out = '', $check = 'alphanohtml', $filter = null, $options case 'nohtml': // No html $out = dol_string_nohtmltag($out, 0); break; - case 'restricthtml': // Recommended for most html textarea case 'restricthtmlnolink': + case 'restricthtml': // Recommended for most html textarea + case 'restricthtmlallowclass': case 'restricthtmlallowunvalid': $out = dol_htmlwithnojs($out, 1, $check); break; @@ -7356,7 +7355,7 @@ function dol_nl2br($stringtoencode, $nl2brmode = 0, $forxml = false) * * @param string $stringtoencode String to encode * @param int $nouseofiframesandbox Allow use of option MAIN_SECURITY_USE_SANDBOX_FOR_HTMLWITHNOJS for html sanitizing - * @param string $check 'restricthtmlnolink' or 'restricthtml' or 'restricthtmlallowunvalid' + * @param string $check 'restricthtmlnolink' or 'restricthtml' or 'restricthtmlallowclass' or 'restricthtmlallowunvalid' * @return string HTML sanitized */ function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check = 'restricthtml') @@ -7415,7 +7414,7 @@ function dol_htmlwithnojs($stringtoencode, $nouseofiframesandbox = 0, $check = ' $out = preg_replace('/&#x?[0-9]+/i', '', $out); // For example if we have javascript with an entities without the ; to hide the 'a' of 'javascript'. // Keep only some html tags and remove also some 'javascript:' strings - $out = dol_string_onlythesehtmltags($out, 0, 1, 1); + $out = dol_string_onlythesehtmltags($out, 0, ($check == 'restricthtmlallowclass' ? 0 : 1), 1); // We should also exclude non expected HTML attributes and clean content of some attributes (keep only alt=, title=...). if (!empty($conf->global->MAIN_RESTRICTHTML_REMOVE_ALSO_BAD_ATTRIBUTES)) { diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 5e586cecd99..0194c45b457 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -986,7 +986,14 @@ function print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabM } else { print ''; } - print ($menu_array[$i]['prefix'] ? $menu_array[$i]['prefix'] : '').$menu_array[$i]['titre']; + if (!empty($menu_array[$i]['prefix'])) { + if (preg_match('/^fa-[a-zA-Z0-9-_]+$/', $menu_array[$i]['prefix'])) { + print ''; + } else { + print $menu_array[$i]['prefix']; + } + } + print $menu_array[$i]['titre']; if ($shorturlwithoutparam) { print ''; } else { @@ -997,7 +1004,10 @@ function print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabM } elseif ($showmenu) { // Not enabled but visible (so greyed) print ''."\n"; $lastlevel0 = 'greyed';