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