27 require
'../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/class/menubase.class.php';
32 $langs->loadLangs(array(
"other",
"admin"));
34 $cancel =
GETPOST(
'cancel',
'alphanohtml');
41 $dirstandard = array();
42 $dirsmartphone = array();
43 $dirmenus = array_merge(array(
"/core/menus/"), (array) $conf->modules_parts[
'menus']);
44 foreach ($dirmenus as $dirmenu) {
45 $dirstandard[] = $dirmenu.
'standard';
46 $dirsmartphone[] = $dirmenu.
'smartphone';
49 $action =
GETPOST(
'action',
'aZ09');
51 $menu_handler_top = $conf->global->MAIN_MENU_STANDARD;
52 $menu_handler_smartphone = $conf->global->MAIN_MENU_SMARTPHONE;
53 $menu_handler_top = preg_replace(
'/_backoffice.php/i',
'', $menu_handler_top);
54 $menu_handler_top = preg_replace(
'/_frontoffice.php/i',
'', $menu_handler_top);
55 $menu_handler_smartphone = preg_replace(
'/_backoffice.php/i',
'', $menu_handler_smartphone);
56 $menu_handler_smartphone = preg_replace(
'/_frontoffice.php/i',
'', $menu_handler_smartphone);
58 $menu_handler = $menu_handler_top;
60 if (
GETPOST(
"handler_origine")) {
61 $menu_handler =
GETPOST(
"handler_origine");
64 $menu_handler =
GETPOST(
"menu_handler");
73 if ($action ==
'update') {
75 $leftmenu =
''; $mainmenu =
'';
76 if (
GETPOST(
'menuIdParent',
'alphanohtml') && !is_numeric(
GETPOST(
'menuIdParent',
'alphanohtml'))) {
77 $tmp = explode(
'&',
GETPOST(
'menuIdParent',
'alphanohtml'));
78 foreach ($tmp as $s) {
79 if (preg_match(
'/fk_mainmenu=/', $s)) {
80 $mainmenu = preg_replace(
'/fk_mainmenu=/',
'', $s);
82 if (preg_match(
'/fk_leftmenu=/', $s)) {
83 $leftmenu = preg_replace(
'/fk_leftmenu=/',
'', $s);
89 $result = $menu->fetch(
GETPOST(
'menuId',
'int'));
91 $menu->title = (string)
GETPOST(
'titre',
'alphanohtml');
92 $menu->leftmenu = (string)
GETPOST(
'leftmenu',
'aZ09');
93 $menu->url = (string)
GETPOST(
'url',
'alphanohtml');
94 $menu->langs = (string)
GETPOST(
'langs',
'alphanohtml');
95 $menu->position = (int)
GETPOST(
'position',
'int');
96 $menu->enabled = (string)
GETPOST(
'enabled',
'alphanohtml');
97 $menu->perms = (string)
GETPOST(
'perms',
'alphanohtml');
98 $menu->target = (string)
GETPOST(
'target',
'alphanohtml');
99 $menu->user = (string)
GETPOST(
'user',
'alphanohtml');
100 $menu->mainmenu = (string)
GETPOST(
'propertymainmenu',
'alphanohtml');
101 if (is_numeric(
GETPOST(
'menuIdParent',
'alphanohtml'))) {
102 $menu->fk_menu = (int)
GETPOST(
'menuIdParent',
'alphanohtml');
104 if (
GETPOST(
'type',
'alphanohtml') ==
'top') {
109 $menu->fk_mainmenu = $mainmenu;
110 $menu->fk_leftmenu = $leftmenu;
113 $result = $menu->update($user);
115 setEventMessages($langs->trans(
"RecordModifiedSuccessfully"), null,
'mesgs');
124 header(
"Location: ".DOL_URL_ROOT.
"/admin/menus/index.php?menu_handler=".$menu_handler);
127 header(
"Location: ".DOL_URL_ROOT.
"/admin/menus/index.php?menu_handler=".$menu_handler);
132 if ($action ==
'add') {
134 header(
"Location: ".DOL_URL_ROOT.
"/admin/menus/index.php?menu_handler=".$menu_handler);
140 if (
GETPOST(
'menuId',
'alphanohtml', 3) && !is_numeric(
GETPOST(
'menuId',
'alphanohtml', 3))) {
141 $tmp = explode(
'&',
GETPOST(
'menuId',
'alphanohtml', 3));
142 foreach ($tmp as $s) {
143 if (preg_match(
'/fk_mainmenu=/', $s)) {
144 $mainmenu = preg_replace(
'/fk_mainmenu=/',
'', $s);
146 if (preg_match(
'/fk_leftmenu=/', $s)) {
147 $leftmenu = preg_replace(
'/fk_leftmenu=/',
'', $s);
152 $langs->load(
"errors");
155 if (!$error && !$_POST[
'menu_handler']) {
156 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MenuHandler")), null,
'errors');
160 if (!$error && !$_POST[
'type']) {
161 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Type")), null,
'errors');
165 if (!$error && !$_POST[
'url']) {
166 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"URL")), null,
'errors');
170 if (!$error && !$_POST[
'titre']) {
171 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Title")), null,
'errors');
175 if (!$error && $_POST[
'menuId'] && $_POST[
'type'] ==
'top') {
176 setEventMessages($langs->trans(
"ErrorTopMenuMustHaveAParentWithId0"), null,
'errors');
180 if (!$error && !$_POST[
'menuId'] && $_POST[
'type'] ==
'left') {
181 setEventMessages($langs->trans(
"ErrorLeftMenuMustHaveAParentId"), null,
'errors');
188 $menu->menu_handler = preg_replace(
'/_menu$/',
'',
GETPOST(
'menu_handler',
'aZ09'));
189 $menu->type = (string)
GETPOST(
'type',
'alphanohtml');
190 $menu->title = (string)
GETPOST(
'titre',
'alphanohtml');
191 $menu->url = (string)
GETPOST(
'url',
'alphanohtml');
192 $menu->langs = (string)
GETPOST(
'langs',
'alphanohtml');
193 $menu->position = (int)
GETPOST(
'position',
'int');
194 $menu->enabled = (string)
GETPOST(
'enabled',
'alphanohtml');
195 $menu->perms = (string)
GETPOST(
'perms',
'alphanohtml');
196 $menu->target = (string)
GETPOST(
'target',
'alphanohtml');
197 $menu->user = (string)
GETPOST(
'user',
'alphanohtml');
198 $menu->mainmenu = (string)
GETPOST(
'propertymainmenu',
'alphanohtml');
199 if (is_numeric(
GETPOST(
'menuId',
'alphanohtml', 3))) {
200 $menu->fk_menu = (int)
GETPOST(
'menuId',
'alphanohtml', 3);
202 if (
GETPOST(
'type',
'alphanohtml') ==
'top') {
207 $menu->fk_mainmenu = $mainmenu;
208 $menu->fk_leftmenu = $leftmenu;
211 $result = $menu->create($user);
213 header(
"Location: ".DOL_URL_ROOT.
"/admin/menus/index.php?menu_handler=".
GETPOST(
'menu_handler',
'aZ09'));
223 if ($action ==
'confirm_delete' && $confirm ==
'yes') {
226 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"menu WHERE rowid = ".
GETPOST(
'menuId',
'int');
227 $result = $db->query($sql);
240 $_GET[
"action"] =
'';
251 $form =
new Form($db);
257 if ($action ==
'create') {
258 print '<script type="text/javascript" language="javascript">
259 jQuery(document).ready(function() {
260 function init_topleft()
262 if (jQuery("#topleft").val() == \'top\')
264 jQuery("#menuId").prop("disabled", true);
265 jQuery("#menuId").val(\'\');
266 jQuery("#propertymainmenu").removeAttr("disabled");
267 jQuery("#propertymainmenu").val(\'\');
269 if (jQuery("#topleft").val() == \'left\')
271 jQuery("#menuId").removeAttr("disabled");
272 jQuery("#propertymainmenu").prop("disabled", true);
276 jQuery("#topleft").click(function() {
284 print '<form action="./edit.php?action=add&menuId='.GETPOST(
'menuId',
'int').
'" method="post" name="formmenucreate">';
285 print '<input type="hidden" name="token" value="'.newToken().
'">';
289 print '<table class="border centpercent">';
292 $parent_rowid =
GETPOST(
'menuId',
'int');
293 if (
GETPOST(
'menuId',
'int')) {
294 $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');
295 $res = $db->query($sql);
297 while ($menu = $db->fetch_array($res)) {
298 $parent_rowid = $menu[
'rowid'];
299 $parent_mainmenu = $menu[
'mainmenu'];
300 $parent_leftmenu = $menu[
'leftmenu'];
301 $parent_langs = $menu[
'langs'];
302 $parent_level = $menu[
'level'];
308 print '<tr><td class="fieldrequired">'.$langs->trans(
'MenuHandler').
'</td>';
310 $formadmin->select_menu_families($menu_handler.(preg_match(
'/_menu/', $menu_handler) ?
'' :
'_menu'),
'menu_handler', array_merge($dirstandard, $dirsmartphone));
312 print '<td>'.$langs->trans(
'DetailMenuHandler').
'</td></tr>';
315 print '<tr><td class="nowrap fieldrequired">'.$langs->trans(
'MenuForUsers').
'</td>';
316 print '<td><select class="flat" name="user">';
317 print '<option value="2" selected>'.$langs->trans(
"AllMenus").
'</option>';
318 print '<option value="0">'.$langs->trans(
'Internal').
'</option>';
319 print '<option value="1">'.$langs->trans(
'External').
'</option>';
320 print '</select></td>';
321 print '<td>'.$langs->trans(
'DetailUser').
'</td></tr>';
324 print '<tr><td class="fieldrequired">'.$langs->trans(
'Type').
'</td><td>';
326 print $langs->trans(
'Left');
327 print '<input type="hidden" name="type" value="left">';
329 print '<select name="type" class="flat" id="topleft">';
330 print '<option value=""> </option>';
331 print '<option value="top"'.($_POST[
"type"] && $_POST[
"type"] ==
'top' ?
' selected' :
'').
'>'.$langs->trans(
'Top').
'</option>';
332 print '<option value="left"'.($_POST[
"type"] && $_POST[
"type"] ==
'left' ?
' selected' :
'').
'>'.$langs->trans(
'Left').
'</option>';
335 print '</td><td>'.$langs->trans(
'DetailType').
'</td></tr>';
338 print '<tr><td class="fieldrequired">'.$langs->trans(
'MainMenuCode').
'</td>';
339 print '<td><input type="text" class="minwidth300" id="propertymainmenu" name="propertymainmenu" value="'.(GETPOSTISSET(
"propertymainmenu") ?
GETPOST(
"propertymainmenu",
'alphanohtml') :
'').
'"></td>';
341 print $langs->trans(
"Example").
': mytopmenukey';
345 print '<tr><td class="fieldrequired">'.$langs->trans(
'MenuIdParent').
'</td>';
347 print '<td>'.$parent_rowid.
'<input type="hidden" name="menuId" value="'.$parent_rowid.
'"></td>';
349 print '<td><input type="text" class="minwidth300" id="menuId" name="menuId" value="'.(GETPOSTISSET(
"menuId") ?
GETPOST(
"menuId",
'int') :
'').
'"></td>';
351 print '<td>'.$langs->trans(
'DetailMenuIdParent');
352 print ', '.$langs->trans(
"Example").
': fk_mainmenu=abc&fk_leftmenu=def';
356 print '<tr><td class="fieldrequired">'.$langs->trans(
'Title').
'</td>';
357 print '<td><input type="text" class="minwidth300" name="titre" value="'.dol_escape_htmltag(
GETPOST(
"titre",
'alphanohtml')).
'"></td><td>'.$langs->trans(
'DetailTitre').
'</td></tr>';
360 print '<tr><td class="fieldrequired">'.$langs->trans(
'URL').
'</td>';
361 print '<td><input type="text" class="minwidth500" name="url" value="'.GETPOST(
"url",
'alphanohtml').
'"></td><td>'.$langs->trans(
'DetailUrl').
'</td></tr>';
364 print '<tr><td>'.$langs->trans(
'LangFile').
'</td>';
365 print '<td><input type="text" class="minwidth300" name="langs" value="'.$parent_langs.
'"></td><td>'.$langs->trans(
'DetailLangs').
'</td></tr>';
368 print '<tr><td>'.$langs->trans(
'Position').
'</td>';
369 print '<td><input type="text" class="width100" name="position" value="'.dol_escape_htmltag(
GETPOSTISSET(
"position") ?
GETPOST(
"position",
'int') : 100).
'"></td><td>'.$langs->trans(
'DetailPosition').
'</td></tr>';
372 print '<tr><td>'.$langs->trans(
'Target').
'</td><td><select class="flat" name="target">';
373 print '<option value=""'.($menu->target ==
"" ?
' selected' :
'').
'> </option>';
374 print '<option value="_blank"'.($menu->target ==
"_blank" ?
' selected' :
'').
'>'.$langs->trans(
'_blank').
'</option>';
375 print '</select></td></td><td>'.$langs->trans(
'DetailTarget').
'</td></tr>';
378 print '<tr><td>'.$langs->trans(
'Enabled').
'</td>';
379 print '<td><input type="text" class="minwidth500" name="enabled" value="'.(GETPOSTISSET(
'enabled') ?
GETPOST(
"enabled",
'alphanohtml') :
'1').
'"></td><td>'.$langs->trans(
'DetailEnabled').
'</td></tr>';
382 print '<tr><td>'.$langs->trans(
'Rights').
'</td>';
383 print '<td><input type="text" class="minwidth500" name="perms" value="'.(GETPOSTISSET(
'perms') ?
GETPOST(
'perms',
'alphanohtml') :
'1').
'"></td><td>'.$langs->trans(
'DetailRight').
'</td></tr>';
389 print '<div class="center">';
390 print '<input type="submit" class="button button-save" name="save" value="'.$langs->trans(
"Save").
'">';
391 print ' ';
392 print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
396 } elseif ($action ==
'edit') {
400 print
'<form action="./edit.php?action=update" method="POST" name="formmenuedit">';
401 print
'<input type="hidden" name="token" value="'.newToken().
'">';
402 print
'<input type="hidden" name="handler_origine" value="'.$menu_handler.
'">';
403 print
'<input type="hidden" name="menuId" value="'.GETPOST(
'menuId',
'int').
'">';
407 print
'<table class="border centpercent">';
410 $result = $menu->fetch(
GETPOST(
'menuId',
'int'));
414 print
'<tr><td>'.$langs->trans(
'Id').
'</td><td>'.$menu->id.
'</td><td>'.$langs->trans(
'DetailId').
'</td></tr>';
417 print
'<tr><td>'.$langs->trans(
'MenuModule').
'</td><td>'.$menu->module.
'</td><td>'.$langs->trans(
'DetailMenuModule').
'</td></tr>';
420 if ($menu->menu_handler ==
'all') {
421 $handler = $langs->trans(
'AllMenus');
423 $handler = $menu->menu_handler;
425 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MenuHandler').
'</td><td>'.$handler.
'</td><td>'.$langs->trans(
'DetailMenuHandler').
'</td></tr>';
428 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'MenuForUsers').
'</td><td><select class="flat" name="user">';
429 print
'<option value="2"'.($menu->user == 2 ?
' selected' :
'').
'>'.$langs->trans(
"AllMenus").
'</option>';
430 print
'<option value="0"'.($menu->user == 0 ?
' selected' :
'').
'>'.$langs->trans(
'Internal').
'</option>';
431 print
'<option value="1"'.($menu->user == 1 ?
' selected' :
'').
'>'.$langs->trans(
'External').
'</option>';
432 print
'</select></td><td>'.$langs->trans(
'DetailUser').
'</td></tr>';
435 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Type').
'</td>';
436 print
'<td>'.$langs->trans(ucfirst($menu->type)).
'</td><td>'.$langs->trans(
'DetailType').
'</td></tr>';
439 if ($menu->type ==
'top') {
440 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MainMenuCode').
'</td>';
447 print
'<td><input type="text" class="minwidth300" id="propertymainmenu" name="propertymainmenu" value="'.(GETPOST(
"propertymainmenu",
'alphanohtml') ?
GETPOST(
"propertymainmenu",
'alphanohtml') : $menu->mainmenu).
'"></td>';
450 print $langs->trans(
"Example").
': mytopmenukey';
455 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MenuIdParent');
457 $valtouse = $menu->fk_menu;
458 if ($menu->fk_mainmenu) {
459 $valtouse =
'fk_mainmenu='.$menu->fk_mainmenu;
461 if ($menu->fk_leftmenu) {
462 $valtouse .=
'&fk_leftmenu='.$menu->fk_leftmenu;
464 print
'<td><input type="text" name="menuIdParent" value="'.$valtouse.
'" class="minwidth300"></td>';
465 print
'<td>'.$langs->trans(
'DetailMenuIdParent');
466 print
', '.$langs->trans(
"Example").
': fk_mainmenu=abc&fk_leftmenu=def';
473 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Title').
'</td>';
474 print
'<td><input type="text" class="minwidth300" name="titre" value="'.dol_escape_htmltag($menu->title).
'"></td><td>'.$langs->trans(
'DetailTitre').
'</td></tr>';
477 print
'<tr><td class="fieldrequired">'.$langs->trans(
'URL').
'</td>';
478 print
'<td><input type="text" class="quatrevingtpercent" name="url" value="'.$menu->url.
'"></td><td>'.$langs->trans(
'DetailUrl').
'</td></tr>';
481 print
'<tr><td>'.$langs->trans(
'LangFile').
'</td>';
482 print
'<td><input type="text" class="minwidth300" name="langs" value="'.dol_escape_htmltag($menu->langs).
'"></td><td>'.$langs->trans(
'DetailLangs').
'</td></tr>';
485 print
'<tr><td>'.$langs->trans(
'Position').
'</td>';
486 print
'<td><input type="text" class="minwidth100" name="position" value="'.$menu->position.
'"></td><td>'.$langs->trans(
'DetailPosition').
'</td></tr>';
489 print
'<tr><td>'.$langs->trans(
'Target').
'</td><td><select class="flat" name="target">';
490 print
'<option value=""'.($menu->target ==
"" ?
' selected' :
'').
'> </option>';
491 print
'<option value="_blank"'.($menu->target ==
"_blank" ?
' selected' :
'').
'>'.$langs->trans(
'_blank').
'</option>';
492 print
'</select></td><td>'.$langs->trans(
'DetailTarget').
'</td></tr>';
495 print
'<tr><td>'.$langs->trans(
'Enabled').
'</td>';
496 print
'<td><input type="text" class="minwidth500" name="enabled" value="'.dol_escape_htmltag($menu->enabled).
'"></td><td>'.$langs->trans(
'DetailEnabled');
497 if (!empty($menu->enabled)) {
498 print
' ('.$langs->trans(
"ConditionIsCurrently").
': '.
yn(
dol_eval($menu->enabled, 1)).
')';
503 print
'<tr><td>'.$langs->trans(
'Rights').
'</td>';
504 print
'<td><input type="text" class="minwidth500" name="perms" value="'.dol_escape_htmltag($menu->perms).
'"></td><td>'.$langs->trans(
'DetailRight');
505 if (!empty($menu->perms)) {
506 print
' ('.$langs->trans(
"ConditionIsCurrently").
': '.
yn(
dol_eval($menu->perms, 1)).
')';
515 print
'<div class="center">';
516 print
'<input type="submit" class="button button-save" name="save" value="'.$langs->trans(
"Save").
'">';
517 print
' ';
518 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_eval($s, $returnvalue=0, $hideerrors=1)
Replace eval function to add more security.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
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 Calling this function terminate execution ...
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
dol_get_fiche_end($notab=0)
Return tab footer of a card.