dolibarr/htdocs/admin/menus/index.php

403 lines
15 KiB
PHP
Raw Normal View History

<?php
/* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
2018-10-27 14:43:12 +02:00
* Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
2020-06-28 17:34:30 +02:00
* Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
*
* 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
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
2008-09-01 23:51:38 +02:00
* \file htdocs/admin/menus/index.php
* \ingroup core
* \brief Index page for menu editor
*/
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/treeview.lib.php';
2007-12-14 10:54:24 +01:00
2018-09-07 14:58:22 +02:00
// Load translation files required by the page
$langs->loadLangs(array("other", "admin"));
2007-12-14 10:54:24 +01:00
2021-02-26 22:04:03 +01:00
if (!$user->admin) {
accessforbidden();
}
2007-06-08 00:52:47 +02:00
$dirstandard = array();
$dirsmartphone = array();
$dirmenus = array_merge(array("/core/menus/"), (array) $conf->modules_parts['menus']);
2021-02-26 22:04:03 +01:00
foreach ($dirmenus as $dirmenu) {
$dirstandard[] = $dirmenu.'standard';
$dirsmartphone[] = $dirmenu.'smartphone';
}
2020-09-16 19:39:50 +02:00
$action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm', 'alpha');
$menu_handler_top = $conf->global->MAIN_MENU_STANDARD;
$menu_handler_smartphone = $conf->global->MAIN_MENU_SMARTPHONE;
$menu_handler_top = preg_replace('/(_backoffice\.php|_menu\.php)/i', '', $menu_handler_top);
$menu_handler_top = preg_replace('/(_frontoffice\.php|_menu\.php)/i', '', $menu_handler_top);
$menu_handler_smartphone = preg_replace('/(_backoffice\.php|_menu\.php)/i', '', $menu_handler_smartphone);
$menu_handler_smartphone = preg_replace('/(_frontoffice\.php|_menu\.php)/i', '', $menu_handler_smartphone);
$menu_handler = $menu_handler_top;
2021-02-26 22:04:03 +01:00
if (GETPOST("handler_origine")) {
$menu_handler = GETPOST("handler_origine");
}
if (GETPOST("menu_handler")) {
$menu_handler = GETPOST("menu_handler");
}
2007-06-08 00:52:47 +02:00
$menu_handler_to_search = preg_replace('/(_backoffice|_frontoffice|_menu)?(\.php)?/i', '', $menu_handler);
2013-02-19 15:23:25 +01:00
2007-06-08 00:52:47 +02:00
/*
2013-02-19 15:23:25 +01:00
* Actions
*/
2021-02-26 22:04:03 +01:00
if ($action == 'up') {
$current = array();
$previous = array();
2009-10-25 16:36:45 +01:00
// Get current position
$sql = "SELECT m.rowid, m.position, m.type, m.fk_menu";
$sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
$sql .= " WHERE m.rowid = ".GETPOST("menuId", "int");
2009-10-25 16:36:45 +01:00
dol_syslog("admin/menus/index.php ".$sql);
2009-02-11 21:19:47 +01:00
$result = $db->query($sql);
2008-01-12 17:14:14 +01:00
$num = $db->num_rows($result);
$i = 0;
2021-02-26 22:04:03 +01:00
while ($i < $num) {
$obj = $db->fetch_object($result);
2009-10-25 16:36:45 +01:00
$current['rowid'] = $obj->rowid;
$current['order'] = $obj->position;
$current['type'] = $obj->type;
$current['fk_menu'] = $obj->fk_menu;
$i++;
}
2009-02-11 21:19:47 +01:00
2009-10-25 16:36:45 +01:00
// Menu before
$sql = "SELECT m.rowid, m.position";
$sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
$sql .= " WHERE (m.position < ".($current['order'])." OR (m.position = ".($current['order'])." AND rowid < ".GETPOST("menuId", "int")."))";
$sql .= " AND m.menu_handler='".$db->escape($menu_handler_to_search)."'";
$sql .= " AND m.entity = ".$conf->entity;
$sql .= " AND m.type = '".$db->escape($current['type'])."'";
$sql .= " AND m.fk_menu = '".$db->escape($current['fk_menu'])."'";
$sql .= " ORDER BY m.position, m.rowid";
2009-10-25 16:36:45 +01:00
dol_syslog("admin/menus/index.php ".$sql);
2009-02-11 21:19:47 +01:00
$result = $db->query($sql);
2008-01-12 17:14:14 +01:00
$num = $db->num_rows($result);
$i = 0;
2021-02-26 22:04:03 +01:00
while ($i < $num) {
$obj = $db->fetch_object($result);
2009-10-25 16:36:45 +01:00
$previous['rowid'] = $obj->rowid;
$previous['order'] = $obj->position;
$i++;
}
2009-02-11 21:19:47 +01:00
$sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
2021-03-30 03:37:54 +02:00
$sql .= " SET m.position = ".((int) $previous['order']);
$sql .= " WHERE m.rowid = ".((int) $current['rowid']); // Up the selected entry
2009-10-25 16:36:45 +01:00
dol_syslog("admin/menus/index.php ".$sql);
2009-02-11 21:19:47 +01:00
$db->query($sql);
$sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
2021-03-30 03:37:54 +02:00
$sql .= " SET m.position = ".((int) ($current['order'] != $previous['order'] ? $current['order'] : $current['order'] + 1));
$sql .= " WHERE m.rowid = ".((int) $previous['rowid']); // Descend celui du dessus
2009-10-25 16:36:45 +01:00
dol_syslog("admin/menus/index.php ".$sql);
2009-02-11 21:19:47 +01:00
$db->query($sql);
2021-02-26 22:04:03 +01:00
} elseif ($action == 'down') {
$current = array();
$next = array();
2009-10-25 16:36:45 +01:00
// Get current position
$sql = "SELECT m.rowid, m.position, m.type, m.fk_menu";
$sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
$sql .= " WHERE m.rowid = ".GETPOST("menuId", "int");
2009-10-25 16:36:45 +01:00
dol_syslog("admin/menus/index.php ".$sql);
2009-02-11 21:19:47 +01:00
$result = $db->query($sql);
2008-01-12 17:14:14 +01:00
$num = $db->num_rows($result);
$i = 0;
2021-02-26 22:04:03 +01:00
while ($i < $num) {
$obj = $db->fetch_object($result);
2009-10-25 16:36:45 +01:00
$current['rowid'] = $obj->rowid;
$current['order'] = $obj->position;
$current['type'] = $obj->type;
$current['fk_menu'] = $obj->fk_menu;
$i++;
}
2009-02-11 21:19:47 +01:00
2009-10-25 16:36:45 +01:00
// Menu after
2008-01-12 17:14:14 +01:00
$sql = "SELECT m.rowid, m.position";
$sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
$sql .= " WHERE (m.position > ".($current['order'])." OR (m.position = ".($current['order'])." AND rowid > ".GETPOST("menuId", "int")."))";
$sql .= " AND m.menu_handler='".$db->escape($menu_handler_to_search)."'";
$sql .= " AND m.entity = ".$conf->entity;
$sql .= " AND m.type = '".$db->escape($current['type'])."'";
$sql .= " AND m.fk_menu = '".$db->escape($current['fk_menu'])."'";
$sql .= " ORDER BY m.position, m.rowid";
2009-10-25 16:36:45 +01:00
dol_syslog("admin/menus/index.php ".$sql);
2009-02-11 21:19:47 +01:00
$result = $db->query($sql);
2008-01-12 17:14:14 +01:00
$num = $db->num_rows($result);
$i = 0;
2021-02-26 22:04:03 +01:00
while ($i < $num) {
$obj = $db->fetch_object($result);
2009-10-25 16:36:45 +01:00
$next['rowid'] = $obj->rowid;
$next['order'] = $obj->position;
$i++;
}
2009-02-11 21:19:47 +01:00
$sql = "UPDATE ".MAIN_DB_PREFIX."menu as m";
$sql .= " SET m.position = ".((int) ($current['order'] != $next['order'] ? $next['order'] : $current['order'] + 1)); // Down the selected entry
$sql .= " WHERE m.rowid = ".((int) $current['rowid']);
2009-10-25 16:36:45 +01:00
dol_syslog("admin/menus/index.php ".$sql);
2009-02-11 21:19:47 +01:00
$db->query($sql);
$sql = "UPDATE ".MAIN_DB_PREFIX."menu as m"; // Up the next entry
$sql .= " SET m.position = ".((int) $current['order']);
$sql .= " WHERE m.rowid = ".((int) $next['rowid']);
2009-10-25 16:36:45 +01:00
dol_syslog("admin/menus/index.php ".$sql);
2009-02-11 21:19:47 +01:00
$db->query($sql);
2021-02-26 22:04:03 +01:00
} elseif ($action == 'confirm_delete' && $confirm == 'yes') {
$db->begin();
2009-02-11 21:19:47 +01:00
$sql = "DELETE FROM ".MAIN_DB_PREFIX."menu";
$sql .= " WHERE rowid = ".GETPOST('menuId', 'int');
$resql = $db->query($sql);
2021-02-26 22:04:03 +01:00
if ($resql) {
$db->commit();
2015-10-23 12:58:30 +02:00
setEventMessages($langs->trans("MenuDeleted"), null, 'mesgs');
header("Location: ".DOL_URL_ROOT.'/admin/menus/index.php?menu_handler='.$menu_handler);
exit;
2020-05-21 09:35:30 +02:00
} else {
$db->rollback();
$reload = 0;
$action = '';
}
}
2007-06-06 00:30:46 +02:00
/*
2009-05-27 16:32:19 +02:00
* View
2007-06-06 00:30:46 +02:00
*/
2009-05-27 16:32:19 +02:00
$form = new Form($db);
$formadmin = new FormAdmin($db);
2007-06-06 00:30:46 +02:00
$arrayofjs = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
$arrayofcss = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
llxHeader('', $langs->trans("Menus"), '', '', 0, 0, $arrayofjs, $arrayofcss);
2007-06-06 00:30:46 +02:00
print load_fiche_titre($langs->trans("Menus"), '', 'title_setup');
2007-06-06 00:30:46 +02:00
2011-12-08 22:48:28 +01:00
2007-06-06 00:30:46 +02:00
$h = 0;
$head[$h][0] = DOL_URL_ROOT."/admin/menus.php";
$head[$h][1] = $langs->trans("MenuHandlers");
$head[$h][2] = 'handler';
$h++;
$head[$h][0] = DOL_URL_ROOT."/admin/menus/index.php";
$head[$h][1] = $langs->trans("MenuAdmin");
$head[$h][2] = 'editor';
$h++;
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head($head, 'editor', '', -1);
2007-06-06 00:30:46 +02:00
2019-03-13 15:04:38 +01:00
print '<span class="opacitymedium">'.$langs->trans("MenusEditorDesc")."</span><br>\n";
print "<br>\n";
// Confirmation for remove menu entry
2021-02-26 22:04:03 +01:00
if ($action == 'delete') {
$sql = "SELECT m.titre as title";
$sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
$sql .= " WHERE m.rowid = ".GETPOST('menuId', 'int');
$result = $db->query($sql);
$obj = $db->fetch_object($result);
2009-02-11 21:19:47 +01:00
print $form->formconfirm("index.php?menu_handler=".$menu_handler."&menuId=".GETPOST('menuId', 'int'), $langs->trans("DeleteMenu"), $langs->trans("ConfirmDeleteMenu", $obj->title), "confirm_delete");
}
$newcardbutton = '';
2021-02-26 22:04:03 +01:00
if ($user->admin) {
$newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/admin/menus/edit.php?menuId=0&action=create&menu_handler='.urlencode($menu_handler).'&backtopage='.urlencode($_SERVER['PHP_SELF']));
2019-02-14 10:10:31 +01:00
}
2007-07-08 18:24:06 +02:00
2008-05-23 17:28:03 +02:00
print '<form name="newmenu" class="nocellnopadd" action="'.$_SERVER["PHP_SELF"].'">';
2007-06-08 00:52:47 +02:00
print '<input type="hidden" action="change_menu_handler">';
print $langs->trans("MenuHandler").': ';
$formadmin->select_menu_families($menu_handler.(preg_match('/_menu/', $menu_handler) ? '' : '_menu'), 'menu_handler', array_merge($dirstandard, $dirsmartphone));
2007-06-08 00:52:47 +02:00
print ' &nbsp; <input type="submit" class="button" value="'.$langs->trans("Refresh").'">';
2019-02-14 10:10:31 +01:00
print '<div class="floatright">';
print $newcardbutton;
print '</div>';
2007-06-08 00:52:47 +02:00
print '</form>';
2007-06-08 00:52:47 +02:00
print '<br>';
2016-04-23 21:34:10 +02:00
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
2007-06-06 00:30:46 +02:00
print '<td>'.$langs->trans("TreeMenuPersonalized").'</td>';
2020-05-06 05:10:42 +02:00
print '<td class="right"><div id="iddivjstreecontrol"><a href="#">'.img_picto('', 'folder', 'class="paddingright"').$langs->trans("UndoExpandAll").'</a>';
print ' | <a href="#">'.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ExpandAll").'</a></div></td>';
print '</tr>';
print '<tr>';
print '<td colspan="2">';
2007-06-06 00:30:46 +02:00
2009-02-11 21:19:47 +01:00
// ARBORESCENCE
$rangLast = 0;
$idLast = -1;
2021-02-26 22:04:03 +01:00
if ($conf->use_javascript_ajax) {
/*-------------------- MAIN -----------------------
2009-10-25 16:36:45 +01:00
tableau des elements de l'arbre:
c'est un tableau a 2 dimensions.
Une ligne represente un element : data[$x]
chaque ligne est decomposee en 3 donnees:
- l'index de l'élément
- l'index de l'élément parent
2009-10-25 16:36:45 +01:00
- la chaine a afficher
2009-02-11 21:19:47 +01:00
ie: data[]= array (index, index parent, chaine )
*/
2017-07-01 12:42:49 +02:00
2009-10-25 16:36:45 +01:00
//il faut d'abord declarer un element racine de l'arbre
$data[] = array('rowid'=>0, 'fk_menu'=>-1, 'title'=>"racine", 'mainmenu'=>'', 'leftmenu'=>'', 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
2017-07-01 12:42:49 +02:00
2009-10-25 16:36:45 +01:00
//puis tous les elements enfants
2017-07-30 19:38:12 +02:00
$sql = "SELECT m.rowid, m.titre, m.langs, m.mainmenu, m.leftmenu, m.fk_menu, m.fk_mainmenu, m.fk_leftmenu, m.position, m.module";
$sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
$sql .= " WHERE menu_handler = '".$db->escape($menu_handler_to_search)."'";
$sql .= " AND entity = ".$conf->entity;
//$sql.= " AND fk_menu >= 0";
$sql .= " ORDER BY m.position, m.rowid"; // Order is position then rowid (because we need a sort criteria when position is same)
2012-09-08 02:03:47 +02:00
$res = $db->query($sql);
2021-02-26 22:04:03 +01:00
if ($res) {
$num = $db->num_rows($res);
$i = 1;
2021-02-26 22:04:03 +01:00
while ($menu = $db->fetch_array($res)) {
if (!empty($menu['langs'])) {
$langs->load($menu['langs']);
}
$titre = $langs->trans($menu['titre']);
2017-07-01 12:42:49 +02:00
2020-04-27 00:02:31 +02:00
$entry = '<table class="nobordernopadding centpercent"><tr><td>';
$entry .= '<strong> &nbsp; <a href="edit.php?menu_handler='.$menu_handler_to_search.'&action=edit&token='.newToken().'&menuId='.$menu['rowid'].'">'.$titre.'</a></strong>';
2020-04-27 00:02:31 +02:00
$entry .= '</td><td class="right">';
$entry .= '<a class="editfielda marginleftonly marginrightonly" href="edit.php?menu_handler='.$menu_handler_to_search.'&action=edit&token='.newToken().'&menuId='.$menu['rowid'].'">'.img_edit('default', 0, 'class="menuEdit" id="edit'.$menu['rowid'].'"').'</a> ';
$entry .= '<a class="marginleftonly marginrightonly" href="edit.php?menu_handler='.$menu_handler_to_search.'&action=create&token='.newToken().'&menuId='.$menu['rowid'].'">'.img_edit_add('default').'</a> ';
$entry .= '<a class="marginleftonly marginrightonly" href="index.php?menu_handler='.$menu_handler_to_search.'&action=delete&token='.newToken().'&menuId='.$menu['rowid'].'">'.img_delete('default').'</a> ';
2021-06-15 01:18:17 +02:00
$entry .= '&nbsp; ';
$entry .= '<a class="marginleftonly marginrightonly" href="index.php?menu_handler='.$menu_handler_to_search.'&action=up&token='.newToken().'&menuId='.$menu['rowid'].'">'.img_picto("Up", "1uparrow").'</a><a href="index.php?menu_handler='.$menu_handler_to_search.'&action=down&menuId='.$menu['rowid'].'">'.img_picto("Down", "1downarrow").'</a>';
2020-04-27 00:02:31 +02:00
$entry .= '</td></tr></table>';
$buttons = '<a class="editfielda marginleftonly marginrightonly" href="edit.php?menu_handler='.$menu_handler_to_search.'&action=edit&token='.newToken().'&menuId='.$menu['rowid'].'">'.img_edit('default', 0, 'class="menuEdit" id="edit'.$menu['rowid'].'"').'</a> ';
$buttons .= '<a class="marginleftonly marginrightonly" href="edit.php?menu_handler='.$menu_handler_to_search.'&action=create&token='.newToken().'&menuId='.$menu['rowid'].'">'.img_edit_add('default').'</a> ';
$buttons .= '<a class="marginleftonly marginrightonly" href="index.php?menu_handler='.$menu_handler_to_search.'&action=delete&token='.newToken().'&menuId='.$menu['rowid'].'">'.img_delete('default').'</a> ';
2021-06-15 01:18:17 +02:00
$buttons .= '&nbsp; ';
$buttons .= '<a class="marginleftonly marginrightonly" href="index.php?menu_handler='.$menu_handler_to_search.'&action=up&token='.newToken().'&menuId='.$menu['rowid'].'">'.img_picto("Up", "1uparrow").'</a><a href="index.php?menu_handler='.$menu_handler_to_search.'&action=down&menuId='.$menu['rowid'].'">'.img_picto("Down", "1downarrow").'</a>';
2020-04-27 00:02:31 +02:00
$data[] = array(
'rowid'=>$menu['rowid'],
'module'=>$menu['module'],
'fk_menu'=>$menu['fk_menu'],
'title'=>$titre,
'mainmenu'=>$menu['mainmenu'],
'leftmenu'=>$menu['leftmenu'],
'fk_mainmenu'=>$menu['fk_mainmenu'],
'fk_leftmenu'=>$menu['fk_leftmenu'],
'position'=>$menu['position'],
2020-04-27 00:02:31 +02:00
'entry'=>$entry,
'buttons'=>$buttons
);
2009-02-11 21:19:47 +01:00
$i++;
}
}
global $tree_recur_alreadyadded; // This var was def into tree_recur
2017-07-01 12:42:49 +02:00
//var_dump($data);
2017-07-30 19:38:12 +02:00
// Appelle de la fonction recursive (ammorce) avec recherche depuis la racine.
//tree_recur($data, $data[0], 0, 'iddivjstree', 0, 1); // use this to get info on name and foreign keys of menu entry
tree_recur($data, $data[0], 0, 'iddivjstree', 0, 0); // $data[0] is virtual record 'racine'
2017-07-01 12:42:49 +02:00
print '</td>';
2017-07-01 12:42:49 +02:00
print '</tr>';
2017-07-01 12:42:49 +02:00
print '</table>';
2017-07-01 12:42:49 +02:00
// Process remaining records (records that are not linked to root by any path)
$remainingdata = array();
2021-02-26 22:04:03 +01:00
foreach ($data as $datar) {
if (empty($datar['rowid']) || !empty($tree_recur_alreadyadded[$datar['rowid']])) {
continue;
}
$remainingdata[] = $datar;
}
2017-07-01 12:42:49 +02:00
2021-02-26 22:04:03 +01:00
if (count($remainingdata)) {
print '<table class="noborder centpercent">';
2017-07-01 12:42:49 +02:00
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("NotTopTreeMenuPersonalized").'</td>';
print '<td class="right"></td>';
print '</tr>';
2017-07-01 12:42:49 +02:00
print '<tr>';
print '<td colspan="2">';
2021-02-26 22:04:03 +01:00
foreach ($remainingdata as $datar) {
$father = array('rowid'=>$datar['rowid'], 'title'=>"???", 'mainmenu'=>$datar['fk_mainmenu'], 'leftmenu'=>$datar['fk_leftmenu'], 'fk_mainmenu'=>'', 'fk_leftmenu'=>'');
//print 'Start with rowid='.$datar['rowid'].' mainmenu='.$father ['mainmenu'].' leftmenu='.$father ['leftmenu'].'<br>'."\n";
tree_recur($data, $father, 0, 'iddivjstree'.$datar['rowid'], 1, 1);
}
2017-07-01 12:42:49 +02:00
print '</td>';
2017-07-01 12:42:49 +02:00
print '</tr>';
2017-07-01 12:42:49 +02:00
print '</table>';
}
print '</div>';
2020-05-21 09:35:30 +02:00
} else {
$langs->load("errors");
2015-10-23 12:58:30 +02:00
setEventMessages($langs->trans("ErrorFeatureNeedJavascript"), null, 'errors');
}
print '<br>';
2018-07-28 14:29:28 +02:00
// End of page
2012-07-09 18:09:44 +02:00
llxFooter();
$db->close();