29require
'../../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/lib/treeview.lib.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/class/menubase.class.php';
42$langs->loadLangs(array(
"other",
"admin"));
44$dirstandard = array();
45$dirmenus = array_merge(array(
"/core/menus/"), (array)
$conf->modules_parts[
'menus']);
46foreach ($dirmenus as $dirmenu) {
47 $dirstandard[] = $dirmenu.
'standard';
50$action =
GETPOST(
'action',
'aZ09');
51$confirm =
GETPOST(
'confirm',
'alpha');
54$menu_handler_top =
'all';
55$menu_handler_top = preg_replace(
'/(_backoffice\.php|_menu\.php)/i',
'', $menu_handler_top);
56$menu_handler_top = preg_replace(
'/(_frontoffice\.php|_menu\.php)/i',
'', $menu_handler_top);
58$menu_handler = $menu_handler_top;
60if (
GETPOST(
"handler_origine")) {
61 $menu_handler =
GETPOST(
"handler_origine");
64 $menu_handler =
GETPOST(
"menu_handler");
67$menu_handler_to_search = preg_replace(
'/(_backoffice|_frontoffice|_menu)?(\.php)?/i',
'', $menu_handler);
69if (empty($user->admin)) {
80if ($action ==
'up' || $action ==
'down') {
81 $sql =
"SELECT m.fk_menu, m.fk_mainmenu, m.fk_leftmenu, p.mainmenu as parent_mainmenu, p.leftmenu as parent_leftmenu, p.type as parent_type";
82 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu as m";
83 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"menu as p ON p.rowid = m.fk_menu";
84 $sql .=
" WHERE m.rowid = ".GETPOSTINT(
"menuId");
85 $sql .=
" AND m.entity = ".((int)
$conf->entity);
86 $resql = $db->query($sql);
87 $obj = ($resql ? $db->fetch_object($resql) :
null);
89 if ((
int) $obj->fk_menu == -1) {
91 $parentmainmenu = (string) $obj->fk_mainmenu;
92 $parentleftmenu = (string) $obj->fk_leftmenu;
93 $sqlsiblings =
"m.fk_menu IN (SELECT p.rowid FROM ".MAIN_DB_PREFIX.
"menu as p";
94 $sqlsiblings .=
" WHERE p.menu_handler = '".$db->escape($menu_handler_to_search).
"' AND p.entity = ".((int)
$conf->entity);
95 $sqlsiblings .=
" AND p.mainmenu = '".$db->escape($parentmainmenu).
"'";
96 $sqlsiblings .=
" AND ".($parentleftmenu ==
'' ?
"p.type = 'top' AND (p.leftmenu IS NULL OR p.leftmenu = '')" :
"p.leftmenu = '".$db->escape($parentleftmenu).
"'").
")";
99 $parentmainmenu = (string) $obj->parent_mainmenu;
100 $parentleftmenu = (string) $obj->parent_leftmenu;
101 $sqlsiblings =
"m.fk_menu = ".((int) $obj->fk_menu);
104 if ((
int) $obj->fk_menu != 0 && $parentmainmenu !=
'' && ((int) $obj->fk_menu == -1 || $parentleftmenu !=
'' || $obj->parent_type ==
'top')) {
105 $sqlsiblings .=
" OR (m.fk_menu = -1 AND m.fk_mainmenu = '".$db->escape($parentmainmenu).
"'";
106 $sqlsiblings .=
" AND ".($parentleftmenu ==
'' ?
"(m.fk_leftmenu IS NULL OR m.fk_leftmenu = '')" :
"m.fk_leftmenu = '".$db->escape($parentleftmenu).
"'").
")";
111if ($action ==
'up') {
116 $sql =
"SELECT m.rowid, m.position, m.type, m.fk_menu";
117 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu as m";
118 $sql .=
" WHERE m.rowid = ".GETPOSTINT(
"menuId");
119 $sql .=
" AND m.entity = ".((int)
$conf->entity);
121 $result = $db->query($sql);
122 $num = $db->num_rows($result);
125 $obj = $db->fetch_object($result);
126 $current[
'rowid'] = (int) $obj->rowid;
127 $current[
'order'] = (int) $obj->position;
128 $current[
'type'] = (string) $obj->type;
129 $current[
'fk_menu'] = (int) $obj->fk_menu;
134 if (!empty($current) && $sqlsiblings) {
135 $sql =
"SELECT m.rowid, m.position";
136 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu as m";
137 $sql .=
" WHERE (m.position < ".((int) $current[
'order']).
" OR (m.position = ".((int) $current[
'order']).
" AND rowid < ".((int) $current[
'rowid']).
"))";
138 $sql .=
" AND m.menu_handler='".$db->escape($menu_handler_to_search).
"'";
139 $sql .=
" AND m.entity = ".((int)
$conf->entity);
140 $sql .=
" AND m.type = '".$db->escape($current[
'type']).
"'";
141 $sql .=
" AND (".$sqlsiblings.
")";
142 $sql .=
" ORDER BY m.position DESC, m.rowid DESC";
143 $sql .= $db->plimit(1);
145 $result = $db->query($sql);
146 $num = $db->num_rows($result);
149 $obj = $db->fetch_object($result);
150 $previous[
'rowid'] = (int) $obj->rowid;
151 $previous[
'order'] = (int) $obj->position;
157 if (!empty($current) && !empty($previous)) {
161 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"menu as m";
162 $sql .=
" SET m.position = ".((int) $previous[
'order']);
163 $sql .=
" WHERE m.rowid = ".((int) $current[
'rowid']);
165 if (!$db->query($sql)) {
168 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"menu as m";
169 $sql .=
" SET m.position = ".((int) ($current[
'order'] != $previous[
'order'] ? $current[
'order'] : $current[
'order'] + 1));
170 $sql .=
" WHERE m.rowid = ".((int) $previous[
'rowid']);
172 if (!$error && !$db->query($sql)) {
178 setEventMessages($db->lasterror(),
null,
'errors');
183} elseif ($action ==
'down') {
188 $sql =
"SELECT m.rowid, m.position, m.type, m.fk_menu";
189 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu as m";
190 $sql .=
" WHERE m.rowid = ".GETPOSTINT(
"menuId");
191 $sql .=
" AND m.entity = ".((int)
$conf->entity);
193 $result = $db->query($sql);
194 $num = $db->num_rows($result);
197 $obj = $db->fetch_object($result);
198 $current[
'rowid'] = (int) $obj->rowid;
199 $current[
'order'] = (int) $obj->position;
200 $current[
'type'] = (string) $obj->type;
201 $current[
'fk_menu'] = (int) $obj->fk_menu;
206 if (!empty($current) && $sqlsiblings) {
207 $sql =
"SELECT m.rowid, m.position";
208 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu as m";
209 $sql .=
" WHERE (m.position > ".((int) $current[
'order']).
" OR (m.position = ".((int) $current[
'order']).
" AND rowid > ".((int) $current[
'rowid']).
"))";
210 $sql .=
" AND m.menu_handler='".$db->escape($menu_handler_to_search).
"'";
211 $sql .=
" AND m.entity = ".((int)
$conf->entity);
212 $sql .=
" AND m.type = '".$db->escape($current[
'type']).
"'";
213 $sql .=
" AND (".$sqlsiblings.
")";
214 $sql .=
" ORDER BY m.position, m.rowid";
215 $sql .= $db->plimit(1);
217 $result = $db->query($sql);
218 $num = $db->num_rows($result);
221 $obj = $db->fetch_object($result);
222 $next[
'rowid'] = (int) $obj->rowid;
223 $next[
'order'] = (int) $obj->position;
229 if (!empty($current) && !empty($next)) {
233 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"menu as m";
234 $sql .=
" SET m.position = ".((int) ($current[
'order'] != $next[
'order'] ? $next[
'order'] : $current[
'order'] + 1));
235 $sql .=
" WHERE m.rowid = ".((int) $current[
'rowid']);
237 if (!$db->query($sql)) {
240 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"menu as m";
241 $sql .=
" SET m.position = ".((int) $current[
'order']);
242 $sql .=
" WHERE m.rowid = ".((int) $next[
'rowid']);
244 if (!$error && !$db->query($sql)) {
250 setEventMessages($db->lasterror(),
null,
'errors');
255} elseif ($action ==
'confirm_delete' && $confirm ==
'yes') {
259 if (empty($menutodelete->id) || (
int) $menutodelete->entity != (
int)
$conf->entity) {
260 $langs->load(
"errors");
261 setEventMessages($langs->trans(
"ErrorRecordNotFound"),
null,
'errors');
265 $sql =
"SELECT COUNT(m.rowid) as nb";
266 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu as m";
267 $sql .=
" WHERE m.entity = ".((int)
$conf->entity);
268 $sql .=
" AND m.menu_handler = '".$db->escape($menutodelete->menu_handler).
"'";
269 $sql .=
" AND (m.fk_menu = ".((int) $menutodelete->id);
270 if (!empty($menutodelete->mainmenu) && ($menutodelete->type ==
'top' || !empty($menutodelete->leftmenu))) {
271 $sql .=
" OR (m.fk_menu = -1 AND m.fk_mainmenu = '".$db->escape($menutodelete->mainmenu).
"'";
272 if ($menutodelete->type ==
'top') {
273 $sql .=
" AND (m.fk_leftmenu IS NULL OR m.fk_leftmenu = '')";
275 $sql .=
" AND m.fk_leftmenu = '".$db->escape($menutodelete->leftmenu).
"'";
281 $resql = $db->query($sql);
283 $obj = $db->fetch_object($resql);
284 $nbchildren = (int) $obj->nb;
287 if ($nbchildren < 0) {
288 setEventMessages($db->lasterror(),
null,
'errors');
290 } elseif ($nbchildren > 0) {
291 $langs->load(
"errors");
292 setEventMessages($langs->trans(
"ErrorRecordHasChildren"),
null,
'errors');
297 $result = $menutodelete->delete($user);
301 setEventMessages($langs->trans(
"MenuDeleted"),
null,
'mesgs');
303 header(
"Location: ".DOL_URL_ROOT.
'/admin/menus/index.php?menu_handler='.urlencode($menu_handler));
307 setEventMessages($menutodelete->error, $menutodelete->errors,
'errors');
321$form =
new Form($db);
324$arrayofjs = array(
'/public/includes/jquery/plugins/jquerytreeview/jquery.treeview.js',
'/public/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
325$arrayofcss = array(
'/public/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
327llxHeader(
'', $langs->trans(
"Menus"),
'',
'', 0, 0, $arrayofjs, $arrayofcss,
'',
'mod-admin page-menus_index');
336$head[$h][0] = DOL_URL_ROOT.
"/admin/menus.php";
337$head[$h][1] = $langs->trans(
"MenuHandlers");
338$head[$h][2] =
'handler';
341$head[$h][0] = DOL_URL_ROOT.
"/admin/menus/index.php";
342$head[$h][1] = $langs->trans(
"MenuAdmin");
343$head[$h][2] =
'editor';
348print
'<div class="info hideonsmartphone">'.$langs->trans(
"MenusEditorDesc").
"</div>\n";
353if ($action ==
'delete') {
354 $sql =
"SELECT m.titre as title";
355 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu as m";
356 $sql .=
" WHERE m.rowid = ".GETPOSTINT(
'menuId');
357 $sql .=
" AND m.entity = ".((int)
$conf->entity);
358 $result = $db->query($sql);
359 $obj = ($result ? $db->fetch_object($result) :
null);
362 print $form->formconfirm(
"index.php?menu_handler=".urlencode($menu_handler).
"&menuId=".
GETPOSTINT(
'menuId'), $langs->transnoentitiesnoconv(
"DeleteMenu"), $langs->transnoentitiesnoconv(
"ConfirmDeleteMenu", $obj->title),
"confirm_delete");
364 $langs->load(
"errors");
365 setEventMessages($langs->trans(
"ErrorRecordNotFound"),
null,
'errors');
371 $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']));
374print
'<form name="newmenu" class="nocellnopadd" action="'.dolBuildUrl($_SERVER[
"PHP_SELF"]).
'" spellcheck="false">';
375print
'<input type="hidden" action="change_menu_handler">';
376print $langs->trans(
"MenuHandler").
': ';
377$formadmin->select_menu_families($menu_handler.(preg_match(
'/_menu/', $menu_handler) ?
'' :
'_menu'),
'menu_handler', $dirstandard);
378print
' <input type="submit" class="button small" value="'.$langs->trans(
"Refresh").
'">';
380print
'<div class="floatright">';
406$data[] = array(
'rowid' => 0,
'fk_menu' => -1,
'title' =>
'racine',
'mainmenu' =>
'',
'leftmenu' =>
'',
'fk_mainmenu' =>
'',
'fk_leftmenu' =>
'');
410$sql =
"SELECT m.rowid, m.titre, m.langs, m.type, m.mainmenu, m.leftmenu, m.fk_menu, m.fk_mainmenu, m.fk_leftmenu, m.position, m.module";
411$sql .=
" FROM ".MAIN_DB_PREFIX.
"menu as m";
412$sql .=
" WHERE menu_handler = '".$db->escape($menu_handler_to_search).
"'";
413$sql .=
" AND entity = ".((int)
$conf->entity);
415$sql .=
" ORDER BY m.position, m.rowid";
417$res = $db->query($sql);
419 $num = $db->num_rows($res);
422 while ($menu = $db->fetch_array($res)) {
423 if (!empty($menu[
'langs'])) {
424 $langs->load($menu[
'langs']);
426 $titre = $langs->transnoentitiesnoconv($menu[
'titre']);
428 $entry =
'<table class="nobordernopadding centpercent"><tr><td class="tdoverflowmax200">';
429 $entry .=
'<strong class="paddingleft"><a href="edit.php?menu_handler='.urlencode($menu_handler_to_search).
'&action=edit&token='.
newToken().
'&menuId='.$menu[
'rowid'].
'">'.dolPrintHTML($titre).
'</a></strong>';
431 $entry .=
'<td class="right nowraponall">';
432 $entry .=
'<a class="editfielda marginleftonly marginrightonly" href="edit.php?menu_handler='.urlencode($menu_handler_to_search).
'&action=edit&token='.
newToken().
'&menuId='.$menu[
'rowid'].
'">'.img_edit(
'default', 0,
'class="menuEdit" id="edit'.$menu[
'rowid'].
'"').
'</a> ';
433 $entry .=
'<a class="marginleftonly marginrightonly" href="edit.php?menu_handler='.urlencode($menu_handler_to_search).
'&action=create&token='.
newToken().
'&menuId='.$menu[
'rowid'].
'">'.img_edit_add(
'default').
'</a> ';
434 $entry .=
'<a class="marginleftonly marginrightonly" href="index.php?menu_handler='.urlencode($menu_handler_to_search).
'&action=delete&token='.
newToken().
'&menuId='.$menu[
'rowid'].
'">'.img_delete(
'default').
'</a> ';
436 $entry .=
'<a class="marginleftonly marginrightonly reposition" href="index.php?menu_handler='.urlencode($menu_handler_to_search).
'&action=up&token='.
newToken().
'&menuId='.$menu[
'rowid'].
'">'.img_picto(
"Up",
"1uparrow").
'</a><a class="reposition" href="index.php?menu_handler='.urlencode($menu_handler_to_search).
'&action=down&token='.
newToken().
'&menuId='.$menu[
'rowid'].
'">'.img_picto(
"Down",
"1downarrow").
'</a>';
437 $entry .=
'</td></tr></table>';
439 $buttons =
'<a class="editfielda marginleftonly marginrightonly" href="edit.php?menu_handler='.urlencode($menu_handler_to_search).
'&action=edit&token='.
newToken().
'&menuId='.$menu[
'rowid'].
'">'.img_edit(
'default', 0,
'class="menuEdit" id="edit'.$menu[
'rowid'].
'"').
'</a> ';
440 $buttons .=
'<a class="marginleftonly marginrightonly" href="edit.php?menu_handler='.urlencode($menu_handler_to_search).
'&action=create&token='.
newToken().
'&menuId='.$menu[
'rowid'].
'">'.img_edit_add(
'default').
'</a> ';
441 $buttons .=
'<a class="marginleftonly marginrightonly" href="index.php?menu_handler='.urlencode($menu_handler_to_search).
'&action=delete&token='.
newToken().
'&menuId='.$menu[
'rowid'].
'">'.img_delete(
'default').
'</a> ';
442 $buttons .=
' ';
443 $buttons .=
'<a class="marginleftonly marginrightonly reposition" href="index.php?menu_handler='.urlencode($menu_handler_to_search).
'&action=up&token='.
newToken().
'&menuId='.$menu[
'rowid'].
'">'.img_picto(
"Up",
"1uparrow").
'</a><a class="reposition" href="index.php?menu_handler='.urlencode($menu_handler_to_search).
'&action=down&token='.
newToken().
'&menuId='.$menu[
'rowid'].
'">'.img_picto(
"Down",
"1downarrow").
'</a>';
446 'rowid' => (
int) $menu[
'rowid'],
447 'module' => (
string) $menu[
'module'],
448 'fk_menu' => (
int) $menu[
'fk_menu'],
449 'title' => (
string) $titre,
450 'mainmenu' => (
string) $menu[
'mainmenu'],
451 'leftmenu' => (
string) $menu[
'leftmenu'],
452 'fk_mainmenu' => (
string) $menu[
'fk_mainmenu'],
453 'fk_leftmenu' => (
string) $menu[
'fk_leftmenu'],
454 'type' => (
string) $menu[
'type'],
455 'position' => (
int) $menu[
'position'],
457 'buttons' => $buttons
463global $tree_recur_alreadyadded;
467print
'<div class="div-table-responsive">';
468print
'<table class="noborder centpercent">';
470print
'<tr class="liste_titre">';
471print
'<td>'.$langs->trans(
"TreeMenuPersonalized").
'</td>';
472print
'<td class="right"><div id="iddivjstreecontrol"><a href="#">'.img_picto($langs->trans(
"UndoExpandAll"),
'folder',
'class="paddingright"').
'</a>';
473print
' | <a href="#">'.img_picto($langs->trans(
"ExpandAll"),
'folder-open',
'class="paddingright"').
'</a></div></td>';
477print
'<td colspan="2">';
481tree_recur($data, $data[0], 0,
'iddivjstree', 0, 0);
491$remainingdata = array();
492foreach ($data as $datar) {
493 if (empty($datar[
'rowid']) || !empty($tree_recur_alreadyadded[$datar[
'rowid']])) {
496 $remainingdata[] = $datar;
499if (count($remainingdata)) {
500 print
'<div class="div-table-responsive">';
501 print
'<table class="noborder centpercent">';
503 print
'<tr class="liste_titre">';
504 print
'<td>'.$langs->trans(
"NotTopTreeMenuPersonalized").
'</td>';
505 print
'<td class="right"></td>';
509 print
'<td colspan="2">';
511 $recordsbyid = array();
512 $recordsbycode = array();
513 foreach ($data as $datar) {
514 if (!empty($datar[
'rowid'])) {
515 $recordsbyid[$datar[
'rowid']] = 1;
516 if ($datar[
'leftmenu'] !=
'') {
517 $recordsbycode[$datar[
'mainmenu'].
'|'.$datar[
'leftmenu']] = 1;
524 for ($pass = 1; $pass <= 2; $pass++) {
525 foreach ($remainingdata as $datar) {
526 if (!empty($tree_recur_alreadyadded[$datar[
'rowid']])) {
529 if ($pass == 1 && (($datar[
'fk_menu'] > 0 && !empty($recordsbyid[$datar[
'fk_menu']])) || ($datar[
'fk_menu'] == -1 && !empty($recordsbycode[$datar[
'fk_mainmenu'].
'|'.$datar[
'fk_leftmenu']])))) {
532 $father = array(
'rowid' => $datar[
'rowid'],
'title' =>
"???",
'mainmenu' => $datar[
'fk_mainmenu'],
'leftmenu' => $datar[
'fk_leftmenu'],
'fk_mainmenu' =>
'',
'fk_leftmenu' =>
'');
534 tree_recur($data, $father, 0,
'iddivjstree'.$datar[
'rowid'], 1, 1);
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree', $donoresetalreadyloaded=0, $showfk=0, $moreparam='')
Recursive function to output a tree.