This commit is contained in:
Frédéric FRANCE 2020-11-26 23:49:42 +01:00
parent 19339bb0ea
commit f03930e55e
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1

View File

@ -34,13 +34,14 @@ $langs->loadLangs(array("other", "admin"));
$cancel = GETPOST('cancel', 'alphanohtml'); // We click on a Cancel button
$confirm = GETPOST('confirm');
if (!$user->admin) accessforbidden();
if (!$user->admin) {
accessforbidden();
}
$dirstandard = array();
$dirsmartphone = array();
$dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
foreach ($dirmenus as $dirmenu)
{
foreach ($dirmenus as $dirmenu) {
$dirstandard[] = $dirmenu.'standard';
$dirsmartphone[] = $dirmenu.'smartphone';
}
@ -56,8 +57,12 @@ $menu_handler_smartphone = preg_replace('/_frontoffice.php/i', '', $menu_handler
$menu_handler = $menu_handler_top;
if (GETPOST("handler_origine")) $menu_handler = GETPOST("handler_origine");
if (GETPOST("menu_handler")) $menu_handler = GETPOST("menu_handler");
if (GETPOST("handler_origine")) {
$menu_handler = GETPOST("handler_origine");
}
if (GETPOST("menu_handler")) {
$menu_handler = GETPOST("menu_handler");
}
@ -65,22 +70,16 @@ if (GETPOST("menu_handler")) $menu_handler = GETPOST("menu_handler");
* Actions
*/
if ($action == 'update')
{
if (!$cancel)
{
if ($action == 'update') {
if (!$cancel) {
$leftmenu = ''; $mainmenu = '';
if (GETPOST('menuIdParent', 'alphanohtml') && !is_numeric(GETPOST('menuIdParent', 'alphanohtml')))
{
if (GETPOST('menuIdParent', 'alphanohtml') && !is_numeric(GETPOST('menuIdParent', 'alphanohtml'))) {
$tmp = explode('&', GETPOST('menuIdParent', 'alphanohtml'));
foreach ($tmp as $s)
{
if (preg_match('/fk_mainmenu=/', $s))
{
foreach ($tmp as $s) {
if (preg_match('/fk_mainmenu=/', $s)) {
$mainmenu = preg_replace('/fk_mainmenu=/', '', $s);
}
if (preg_match('/fk_leftmenu=/', $s))
{
if (preg_match('/fk_leftmenu=/', $s)) {
$leftmenu = preg_replace('/fk_leftmenu=/', '', $s);
}
}
@ -88,31 +87,31 @@ if ($action == 'update')
$menu = new Menubase($db);
$result = $menu->fetch(GETPOST('menuId', 'int'));
if ($result > 0)
{
$menu->title = GETPOST('titre', 'alphanohtml');
$menu->leftmenu = GETPOST('leftmenu', 'aZ09');
$menu->url = GETPOST('url', 'alphanohtml');
$menu->langs = GETPOST('langs', 'alphanohtml');
$menu->position = GETPOST('position', 'int');
$menu->enabled = GETPOST('enabled', 'alphanohtml');
$menu->perms = GETPOST('perms', 'alphanohtml');
$menu->target = GETPOST('target', 'alphanohtml');
$menu->user = GETPOST('user', 'alphanohtml');
$menu->mainmenu = GETPOST('propertymainmenu', 'alphanohtml');
if (is_numeric(GETPOST('menuIdParent', 'alphanohtml')))
{
$menu->fk_menu = GETPOST('menuIdParent', 'alphanohtml');
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;
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)
{
if ($result > 0) {
setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
} else {
setEventMessages($menu->error, $menu->errors, 'errors');
@ -130,26 +129,21 @@ if ($action == 'update')
}
}
if ($action == 'add')
{
if ($cancel)
{
if ($action == 'add') {
if ($cancel) {
header("Location: ".DOL_URL_ROOT."/admin/menus/index.php?menu_handler=".$menu_handler);
exit;
}
$leftmenu = ''; $mainmenu = '';
if (GETPOST('menuId', 'alphanohtml', 3) && !is_numeric(GETPOST('menuId', 'alphanohtml', 3)))
{
$leftmenu = '';
$mainmenu = '';
if (GETPOST('menuId', 'alphanohtml', 3) && !is_numeric(GETPOST('menuId', 'alphanohtml', 3))) {
$tmp = explode('&', GETPOST('menuId', 'alphanohtml', 3));
foreach ($tmp as $s)
{
if (preg_match('/fk_mainmenu=/', $s))
{
foreach ($tmp as $s) {
if (preg_match('/fk_mainmenu=/', $s)) {
$mainmenu = preg_replace('/fk_mainmenu=/', '', $s);
}
if (preg_match('/fk_leftmenu=/', $s))
{
if (preg_match('/fk_leftmenu=/', $s)) {
$leftmenu = preg_replace('/fk_leftmenu=/', '', $s);
}
}
@ -158,70 +152,64 @@ if ($action == 'add')
$langs->load("errors");
$error = 0;
if (!$error && !$_POST['menu_handler'])
{
if (!$error && !$_POST['menu_handler']) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("MenuHandler")), null, 'errors');
$action = 'create';
$error++;
}
if (!$error && !$_POST['type'])
{
if (!$error && !$_POST['type']) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors');
$action = 'create';
$error++;
}
if (!$error && !$_POST['url'])
{
if (!$error && !$_POST['url']) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("URL")), null, 'errors');
$action = 'create';
$error++;
}
if (!$error && !$_POST['titre'])
{
if (!$error && !$_POST['titre']) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Title")), null, 'errors');
$action = 'create';
$error++;
}
if (!$error && $_POST['menuId'] && $_POST['type'] == 'top')
{
if (!$error && $_POST['menuId'] && $_POST['type'] == 'top') {
setEventMessages($langs->trans("ErrorTopMenuMustHaveAParentWithId0"), null, 'errors');
$action = 'create';
$error++;
}
if (!$error && !$_POST['menuId'] && $_POST['type'] == 'left')
{
if (!$error && !$_POST['menuId'] && $_POST['type'] == 'left') {
setEventMessages($langs->trans("ErrorLeftMenuMustHaveAParentId"), null, 'errors');
$action = 'create';
$error++;
}
if (!$error)
{
if (!$error) {
$menu = new Menubase($db);
$menu->menu_handler = preg_replace('/_menu$/', '', GETPOST('menu_handler', 'aZ09'));
$menu->type = GETPOST('type', 'alphanohtml');
$menu->title = GETPOST('titre', 'alphanohtml');
$menu->url = GETPOST('url', 'alphanohtml');
$menu->langs = GETPOST('langs', 'alphanohtml');
$menu->position = GETPOST('position', 'int');
$menu->enabled = GETPOST('enabled', 'alphanohtml');
$menu->perms = GETPOST('perms', 'alphanohtml');
$menu->target = GETPOST('target', 'alphanohtml');
$menu->user = GETPOST('user', 'alphanohtml');
$menu->mainmenu = GETPOST('propertymainmenu', 'alphanohtml');
if (is_numeric(GETPOST('menuId', 'alphanohtml', 3)))
{
$menu->fk_menu = GETPOST('menuId', 'alphanohtml', 3);
$menu->type = (string) GETPOST('type', 'alphanohtml');
$menu->title = (string) GETPOST('titre', 'alphanohtml');
$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('menuId', 'alphanohtml', 3))) {
$menu->fk_menu = (int) GETPOST('menuId', 'alphanohtml', 3);
} else {
if (GETPOST('type', 'alphanohtml') == 'top') $menu->fk_menu = 0;
else $menu->fk_menu = -1;
if (GETPOST('type', 'alphanohtml') == '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)
{
if ($result > 0) {
header("Location: ".DOL_URL_ROOT."/admin/menus/index.php?menu_handler=".GETPOST('menu_handler', 'aZ09'));
exit;
} else {
@ -232,15 +220,13 @@ if ($action == 'add')
}
// delete
if ($action == 'confirm_delete' && $confirm == 'yes')
{
if ($action == 'confirm_delete' && $confirm == 'yes') {
$db->begin();
$sql = "DELETE FROM ".MAIN_DB_PREFIX."menu WHERE rowid = ".GETPOST('menuId', 'int');
$result = $db->query($sql);
if ($result == 0)
{
if ($result == 0) {
$db->commit();
llxHeader();
@ -268,8 +254,7 @@ $formadmin = new FormAdmin($db);
llxHeader('', $langs->trans("Menu"));
if ($action == 'create')
{
if ($action == 'create') {
print '<script type="text/javascript" language="javascript">
jQuery(document).ready(function() {
function init_topleft()
@ -305,14 +290,11 @@ if ($action == 'create')
// Id
$parent_rowid = GETPOST('menuId', 'int');
if (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))
{
if ($res) {
while ($menu = $db->fetch_array($res)) {
$parent_rowid = $menu['rowid'];
$parent_mainmenu = $menu['mainmenu'];
$parent_leftmenu = $menu['leftmenu'];
@ -340,8 +322,7 @@ if ($action == 'create')
// Type
print '<tr><td class="fieldrequired">'.$langs->trans('Type').'</td><td>';
if ($parent_rowid)
{
if ($parent_rowid) {
print $langs->trans('Left');
print '<input type="hidden" name="type" value="left">';
} else {
@ -355,15 +336,14 @@ if ($action == 'create')
// Mainmenu code
print '<tr><td class="fieldrequired">'.$langs->trans('MainMenuCode').'</td>';
print '<td><input type="text" class="minwidth300" id="propertymainmenu" name="propertymainmenu" value="'.(GETPOSTISSET("propertymainmenu") ? GETPOST("propertymainmenu", 'alphanohtml') : '').'"></td>';
print '<td><input type="text" class="minwidth300" id="propertymainmenu" name="propertymainmenu" value="'.(GETPOSTISSET("propertymainmenu") ? GETPOST("propertymainmenu", 'alphanohtml') : '').'"></td>';
print '<td>';
print $langs->trans("Example").': mytopmenukey';
print '</td></tr>';
// MenuId Parent
print '<tr><td class="fieldrequired">'.$langs->trans('MenuIdParent').'</td>';
if ($parent_rowid)
{
if ($parent_rowid) {
print '<td>'.$parent_rowid.'<input type="hidden" name="menuId" value="'.$parent_rowid.'"></td>';
} else {
print '<td><input type="text" class="minwidth300" id="menuId" name="menuId" value="'.(GETPOSTISSET("menuId") ? GETPOST("menuId", 'int') : '').'"></td>';
@ -407,8 +387,7 @@ if ($action == 'create')
print '</div>';
print '</form>';
} elseif ($action == 'edit')
{
} elseif ($action == 'edit') {
print load_fiche_titre($langs->trans("ModifMenu"), '', 'title_setup');
print '<br>';
@ -432,8 +411,11 @@ if ($action == 'create')
print '<tr><td>'.$langs->trans('MenuModule').'</td><td>'.$menu->module.'</td><td>'.$langs->trans('DetailMenuModule').'</td></tr>';
// Handler
if ($menu->menu_handler == 'all') $handler = $langs->trans('AllMenus');
else $handler = $menu->menu_handler;
if ($menu->menu_handler == 'all') {
$handler = $langs->trans('AllMenus');
} else {
$handler = $menu->menu_handler;
}
print '<tr><td class="fieldrequired">'.$langs->trans('MenuHandler').'</td><td>'.$handler.'</td><td>'.$langs->trans('DetailMenuHandler').'</td></tr>';
// User
@ -447,15 +429,14 @@ if ($action == 'create')
print '<tr><td class="fieldrequired">'.$langs->trans('Type').'</td><td>'.$langs->trans(ucfirst($menu->type)).'</td><td>'.$langs->trans('DetailType').'</td></tr>';
// Mainmenu code
if ($menu->type == 'top')
{
if ($menu->type == 'top') {
print '<tr><td class="fieldrequired">'.$langs->trans('MainMenuCode').'</td>';
/*if ($parent_rowid)
{
print '<td>'.$parent_rowid.'<input type="hidden" name="propertyleftmenu" value="'.$parent_rowid.'"></td>';
}
else
{*/
{
print '<td>'.$parent_rowid.'<input type="hidden" name="propertyleftmenu" value="'.$parent_rowid.'"></td>';
}
else
{*/
print '<td><input type="text" class="minwidth300" id="propertymainmenu" name="propertymainmenu" value="'.(GETPOST("propertymainmenu", 'alphanohtml') ?GETPOST("propertymainmenu", 'alphanohtml') : $menu->mainmenu).'"></td>';
//}
print '<td>';
@ -467,8 +448,12 @@ if ($action == 'create')
print '<tr><td class="fieldrequired">'.$langs->trans('MenuIdParent');
print '</td>';
$valtouse = $menu->fk_menu;
if ($menu->fk_mainmenu) $valtouse = 'fk_mainmenu='.$menu->fk_mainmenu;
if ($menu->fk_leftmenu) $valtouse .= '&fk_leftmenu='.$menu->fk_leftmenu;
if ($menu->fk_mainmenu) {
$valtouse = 'fk_mainmenu='.$menu->fk_mainmenu;
}
if ($menu->fk_leftmenu) {
$valtouse .= '&fk_leftmenu='.$menu->fk_leftmenu;
}
print '<td><input type="text" name="menuIdParent" value="'.$valtouse.'" class="minwidth300"></td>';
print '<td>'.$langs->trans('DetailMenuIdParent');
print ', '.$langs->trans("Example").': fk_mainmenu=abc&fk_leftmenu=def';
@ -497,12 +482,16 @@ if ($action == 'create')
// Enabled
print '<tr><td>'.$langs->trans('Enabled').'</td><td><input type="text" class="minwidth500" name="enabled" value="'.dol_escape_htmltag($menu->enabled).'"></td><td>'.$langs->trans('DetailEnabled');
if (!empty($menu->enabled)) print ' ('.$langs->trans("ConditionIsCurrently").': '.yn(dol_eval($menu->enabled, 1)).')';
if (!empty($menu->enabled)) {
print ' ('.$langs->trans("ConditionIsCurrently").': '.yn(dol_eval($menu->enabled, 1)).')';
}
print '</td></tr>';
// Perms
print '<tr><td>'.$langs->trans('Rights').'</td><td><input type="text" class="minwidth500" name="perms" value="'.dol_escape_htmltag($menu->perms).'"></td><td>'.$langs->trans('DetailRight');
if (!empty($menu->perms)) print ' ('.$langs->trans("ConditionIsCurrently").': '.yn(dol_eval($menu->perms, 1)).')';
if (!empty($menu->perms)) {
print ' ('.$langs->trans("ConditionIsCurrently").': '.yn(dol_eval($menu->perms, 1)).')';
}
print '</td></tr>';
print '</table>';