29require
'../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/menubase.class.php';
34$langs->loadLangs(array(
"other",
"admin"));
36$cancel =
GETPOST(
'cancel',
'alphanohtml');
43$dirstandard = array();
44$dirsmartphone = array();
45$dirmenus = array_merge(array(
"/core/menus/"), (array) $conf->modules_parts[
'menus']);
46foreach ($dirmenus as $dirmenu) {
47 $dirstandard[] = $dirmenu.
'standard';
48 $dirsmartphone[] = $dirmenu.
'smartphone';
51$action =
GETPOST(
'action',
'aZ09');
56$menu_handler_top = preg_replace(
'/_backoffice.php/i',
'', $menu_handler_top);
57$menu_handler_top = preg_replace(
'/_frontoffice.php/i',
'', $menu_handler_top);
58$menu_handler_smartphone = preg_replace(
'/_backoffice.php/i',
'', $menu_handler_smartphone);
59$menu_handler_smartphone = preg_replace(
'/_frontoffice.php/i',
'', $menu_handler_smartphone);
61$menu_handler = $menu_handler_top;
63if (
GETPOST(
"handler_origine")) {
64 $menu_handler =
GETPOST(
"handler_origine");
67 $menu_handler =
GETPOST(
"menu_handler");
76if ($action ==
'add') {
78 header(
"Location: ".DOL_URL_ROOT.
"/admin/menus/index.php?menu_handler=".$menu_handler);
84 if (
GETPOST(
'menuIdParent',
'alphanohtml') && !is_numeric(
GETPOST(
'menuIdParent',
'alphanohtml'))) {
85 $tmp = explode(
'&',
GETPOST(
'menuIdParent',
'alphanohtml'));
86 foreach ($tmp as $s) {
87 if (preg_match(
'/fk_mainmenu=/', $s)) {
88 $mainmenu = preg_replace(
'/fk_mainmenu=/',
'', $s);
90 if (preg_match(
'/fk_leftmenu=/', $s)) {
91 $leftmenu = preg_replace(
'/fk_leftmenu=/',
'', $s);
96 $langs->load(
"errors");
99 if (!$error && !
GETPOST(
'menu_handler')) {
100 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MenuHandler")),
null,
'errors');
104 if (!$error && !
GETPOST(
'type')) {
105 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Position")),
null,
'errors');
109 if (!$error && !
GETPOST(
'url')) {
110 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"URL")),
null,
'errors');
114 if (!$error && !
GETPOST(
'titre')) {
115 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Title")),
null,
'errors');
119 if (!$error &&
GETPOST(
'menuIdParent',
'alphanohtml') &&
GETPOST(
'type') ==
'top') {
120 setEventMessages($langs->trans(
"ErrorTopMenuMustHaveAParentWithId0"),
null,
'errors');
124 if (!$error && !
GETPOST(
'menuIdParent',
'alphanohtml') &&
GETPOST(
'type') ==
'left') {
125 setEventMessages($langs->trans(
"ErrorLeftMenuMustHaveAParentId"),
null,
'errors');
132 $menu->menu_handler = preg_replace(
'/_menu$/',
'',
GETPOST(
'menu_handler',
'aZ09'));
133 $menu->type = (string)
GETPOST(
'type',
'alphanohtml');
134 $menu->title = (string)
GETPOST(
'titre',
'alphanohtml');
135 $menu->prefix = (string)
GETPOST(
'picto',
'restricthtmlallowclass');
136 $menu->url = (string)
GETPOST(
'url',
'alphanohtml');
137 $menu->langs = (string)
GETPOST(
'langs',
'alphanohtml');
139 $menu->enabled = (string)
GETPOST(
'enabled',
'alphanohtml');
140 $menu->perms = (string)
GETPOST(
'perms',
'alphanohtml');
141 $menu->target = (string)
GETPOST(
'target',
'alphanohtml');
143 $menu->mainmenu = (string)
GETPOST(
'propertymainmenu',
'alphanohtml');
144 if (is_numeric(
GETPOST(
'menuIdParent',
'alphanohtml'))) {
145 $menu->fk_menu = (int)
GETPOST(
'menuIdParent',
'alphanohtml');
147 if (
GETPOST(
'type',
'alphanohtml') ==
'top') {
152 $menu->fk_mainmenu = $mainmenu;
153 $menu->fk_leftmenu = $leftmenu;
156 $result = $menu->create($user);
158 header(
"Location: ".DOL_URL_ROOT.
"/admin/menus/index.php?menu_handler=".
GETPOST(
'menu_handler',
'aZ09'));
167if ($action ==
'update') {
171 if (
GETPOST(
'menuIdParent',
'alphanohtml') && !is_numeric(
GETPOST(
'menuIdParent',
'alphanohtml'))) {
172 $tmp = explode(
'&',
GETPOST(
'menuIdParent',
'alphanohtml'));
173 foreach ($tmp as $s) {
174 if (preg_match(
'/fk_mainmenu=/', $s)) {
175 $mainmenu = preg_replace(
'/fk_mainmenu=/',
'', $s);
177 if (preg_match(
'/fk_leftmenu=/', $s)) {
178 $leftmenu = preg_replace(
'/fk_leftmenu=/',
'', $s);
184 if (!$error && !
GETPOST(
'url')) {
185 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"URL")),
null,
'errors');
194 $menu->title = (string)
GETPOST(
'titre',
'alphanohtml');
195 $menu->prefix = (string)
GETPOST(
'picto',
'restricthtmlallowclass');
196 $menu->leftmenu = (string)
GETPOST(
'leftmenu',
'aZ09');
197 $menu->url = (string)
GETPOST(
'url',
'alphanohtml');
198 $menu->langs = (string)
GETPOST(
'langs',
'alphanohtml');
200 $menu->enabled = (string)
GETPOST(
'enabled',
'alphanohtml');
201 $menu->perms = (string)
GETPOST(
'perms',
'alphanohtml');
202 $menu->target = (string)
GETPOST(
'target',
'alphanohtml');
204 $menu->mainmenu = (string)
GETPOST(
'propertymainmenu',
'alphanohtml');
205 if (is_numeric(
GETPOST(
'menuIdParent',
'alphanohtml'))) {
206 $menu->fk_menu = (int)
GETPOST(
'menuIdParent',
'alphanohtml');
208 if (
GETPOST(
'type',
'alphanohtml') ==
'top') {
213 $menu->fk_mainmenu = $mainmenu;
214 $menu->fk_leftmenu = $leftmenu;
217 $result = $menu->update($user);
219 setEventMessages($langs->trans(
"RecordModifiedSuccessfully"),
null,
'mesgs');
229 header(
"Location: ".DOL_URL_ROOT.
"/admin/menus/index.php?menu_handler=".$menu_handler);
235 header(
"Location: ".DOL_URL_ROOT.
"/admin/menus/index.php?menu_handler=".$menu_handler);
246$form =
new Form($db);
249llxHeader(
'', $langs->trans(
'Menu'),
'',
'', 0, 0,
'',
'',
'',
'mod-admin page-menus_edit');
252if ($action ==
'create') {
253 print
'<script type="text/javascript">
254 jQuery(document).ready(function() {
255 function init_topleft()
257 if (jQuery("#topleft").val() == \'top\')
259 jQuery("#menuIdParent").prop("disabled", true);
260 jQuery("#menuIdParent").val(\'\');
261 jQuery("#propertymainmenu").removeAttr("disabled");
262 jQuery("#propertymainmenu").val(\'\');
264 if (jQuery("#topleft").val() == \'left\')
266 jQuery("#menuIdParent").removeAttr("disabled");
267 jQuery("#propertymainmenu").prop("disabled", true);
271 jQuery("#topleft").click(function() {
279 print
'<form action="'.DOL_URL_ROOT.
'/admin/menus/edit.php?menuId='.
GETPOSTINT(
'menuId').
'" method="POST" name="formmenucreate">';
280 print
'<input type="hidden" name="action" value="add">';
281 print
'<input type="hidden" name="token" value="'.newToken().
'">';
285 print
'<div class="div-table-responsive">';
286 print
'<table class="border centpercent">';
290 $parent_mainmenu =
'';
291 $parent_leftmenu =
'';
296 $sql =
"SELECT m.rowid, m.mainmenu, m.leftmenu, m.level, m.langs";
297 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu as m";
298 $sql .=
" WHERE m.rowid = ".(GETPOSTINT(
'menuId'));
299 $res = $db->query($sql);
301 while ($menu = $db->fetch_array($res)) {
302 $parent_rowid = $menu[
'rowid'];
303 $parent_mainmenu = $menu[
'mainmenu'];
304 $parent_leftmenu = $menu[
'leftmenu'];
305 $parent_langs = $menu[
'langs'];
306 $parent_level = $menu[
'level'];
312 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MenuHandler').
'</td>';
314 $formadmin->select_menu_families($menu_handler.(preg_match(
'/_menu/', $menu_handler) ?
'' :
'_menu'),
'menu_handler', array_merge($dirstandard, $dirsmartphone));
316 print
'<td>'.$langs->trans(
'DetailMenuHandler').
'</td></tr>';
319 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'MenuForUsers').
'</td>';
320 print
'<td><select class="flat" name="user" id="menuuser">';
321 print
'<option value="2" selected>'.$langs->trans(
"AllMenus").
'</option>';
322 print
'<option value="0">'.$langs->trans(
'Internal').
'</option>';
323 print
'<option value="1">'.$langs->trans(
'External').
'</option>';
327 print
'<td>'.$langs->trans(
'DetailUser').
'</td></tr>';
330 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Position').
'</td><td>';
332 print $langs->trans(
'Left');
333 print
'<input type="hidden" name="type" value="left">';
335 print
'<select name="type" class="flat" id="topleft">';
336 print
'<option value=""> </option>';
337 print
'<option value="top"'.(GETPOST(
"type") ==
'top' ?
' selected' :
'').
'>'.$langs->trans(
'Top').
'</option>';
338 print
'<option value="left"'.(GETPOST(
"type") ==
'left' ?
' selected' :
'').
'>'.$langs->trans(
'Left').
'</option>';
342 print
'</td><td>'.$langs->trans(
'DetailType').
'</td></tr>';
345 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MainMenuCode').
'</td>';
346 print
'<td><input type="text" class="minwidth300" id="propertymainmenu" name="propertymainmenu" value="'.(GETPOSTISSET(
"propertymainmenu") ?
GETPOST(
"propertymainmenu",
'alphanohtml') :
'').
'"></td>';
348 print $langs->trans(
"Example").
': mytopmenukey';
352 print
'<tr><td>'.$langs->trans(
'MenuIdParent').
'</td>';
354 print
'<td>'.$parent_rowid.
'<input type="hidden" name="menuIdParent" value="'.$parent_rowid.
'"></td>';
356 print
'<td><input type="text" class="minwidth300" id="menuIdParent" name="menuIdParent" value="'.(GETPOSTISSET(
"menuIdParent") ?
GETPOST(
"menuIdParent",
'alphanohtml') :
'').
'"></td>';
358 print
'<td>'.$langs->trans(
'DetailMenuIdParent');
359 print
', '.$langs->trans(
"Example").
': fk_mainmenu=abc&fk_leftmenu=def';
363 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Title').
'</td>';
364 print
'<td><input type="text" class="minwidth300" name="titre" value="'.dol_escape_htmltag(
GETPOST(
"titre",
'alphanohtml')).
'"></td><td>'.$langs->trans(
'DetailTitre').
'</td></tr>';
367 print
'<tr><td class="fieldrequired">'.$langs->trans(
'URL').
'</td>';
368 print
'<td><input type="text" class="minwidth500" name="url" value="'.dol_escape_htmltag(
GETPOST(
"url",
'alphanohtml')).
'"></td><td>'.$langs->trans(
'DetailUrl').
'</td></tr>';
371 print
'<tr><td>'.$langs->trans(
'Image').
'</td>';
372 print
'<td><input type="text" class="minwidth300" name="picto" value="'.dol_escape_htmltag(
GETPOST(
"picto",
'alphanohtml')).
'"></td><td>'.$langs->trans(
'Example').
': fa-global</td></tr>';
375 print
'<tr><td>'.$langs->trans(
'LangFile').
'</td>';
376 print
'<td><input type="text" class="minwidth300" name="langs" value="'.dol_escape_htmltag($parent_langs).
'"></td><td>'.$langs->trans(
'DetailLangs').
'</td></tr>';
379 print
'<tr><td>'.$langs->trans(
'Position').
'</td>';
380 print
'<td><input type="text" class="width100" name="position" value="'.((int) (GETPOSTISSET(
"position") ?
GETPOSTINT(
"position") : 100)).
'"></td><td>'.$langs->trans(
'DetailPosition').
'</td></tr>';
383 print
'<tr><td>'.$langs->trans(
'Enabled').
'</td>';
384 print
'<td><input type="text" class="minwidth500" name="enabled" value="'.(GETPOSTISSET(
'enabled') ?
GETPOST(
"enabled",
'alphanohtml') :
'1').
'"></td><td>'.$langs->trans(
'DetailEnabled').
'</td></tr>';
387 print
'<tr><td>'.$langs->trans(
'Rights').
'</td>';
388 print
'<td><input type="text" class="minwidth500" name="perms" value="'.(GETPOSTISSET(
'perms') ?
GETPOST(
'perms',
'alphanohtml') :
'1').
'"></td><td>'.$langs->trans(
'DetailRight').
'</td></tr>';
391 print
'<tr><td>'.$langs->trans(
'Target').
'</td><td><select class="flat" name="target" id="target">';
393 print
'<option value=""'.(isset($menu->target) && $menu->target ==
"" ?
' selected' :
'').
'> </option>';
394 print
'<option value="_blank"'.(isset($menu->target) && $menu->target ==
"_blank" ?
' selected' :
'').
'>'.$langs->trans(
'_blank').
'</option>';
398 print
'</td></td><td>'.$langs->trans(
'DetailTarget').
'</td></tr>';
405 print $form->buttonsSaveCancel();
408} elseif ($action ==
'edit') {
412 print
'<form action="./edit.php" method="POST" name="formmenuedit">';
413 print
'<input type="hidden" name="action" value="update">';
414 print
'<input type="hidden" name="token" value="'.newToken().
'">';
415 print
'<input type="hidden" name="handler_origine" value="'.$menu_handler.
'">';
416 print
'<input type="hidden" name="menuId" value="'.GETPOSTINT(
'menuId').
'">';
420 print
'<div class="div-table-responsive">';
421 print
'<table class="border centpercent">';
428 print
'<tr><td>'.$langs->trans(
'Id').
'</td><td>'.$menu->id.
'</td><td>'.$langs->trans(
'DetailId').
'</td></tr>';
431 print
'<tr><td>'.$langs->trans(
'MenuModule').
'</td><td>'.(empty($menu->module) ?
'Core' : $menu->module).
'</td><td><span class="opacitymedium">'.$langs->trans(
'DetailMenuModule').
'</span></td></tr>';
434 if ($menu->menu_handler ==
'all') {
435 $handler = $langs->trans(
'AllMenus');
437 $handler = $menu->menu_handler;
439 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MenuHandler').
'</td><td>'.$handler.
'</td><td>'.$langs->trans(
'DetailMenuHandler').
'</td></tr>';
442 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'MenuForUsers').
'</td><td>';
443 print
'<select class="flat" name="user" id="menuuser">';
444 print
'<option value="2"'.($menu->user == 2 ?
' selected' :
'').
'>'.$langs->trans(
"AllMenus").
'</option>';
445 print
'<option value="0"'.($menu->user == 0 ?
' selected' :
'').
'>'.$langs->trans(
'Internal').
'</option>';
446 print
'<option value="1"'.($menu->user == 1 ?
' selected' :
'').
'>'.$langs->trans(
'External').
'</option>';
449 print
'</td><td>'.$langs->trans(
'DetailUser').
'</td></tr>';
452 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Position').
'</td>';
453 print
'<td>'.$langs->trans(ucfirst($menu->type)).
'</td><td>'.$langs->trans(
'DetailType').
'</td></tr>';
456 if ($menu->type ==
'top') {
457 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MainMenuCode').
'</td>';
464 print
'<td><input type="text" class="minwidth300" id="propertymainmenu" name="propertymainmenu" value="'.(GETPOST(
"propertymainmenu",
'alphanohtml') ?
GETPOST(
"propertymainmenu",
'alphanohtml') : $menu->mainmenu).
'"></td>';
467 print $langs->trans(
"Example").
': mytopmenukey';
472 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MenuIdParent');
474 $valtouse = $menu->fk_menu;
475 if ($menu->fk_mainmenu) {
476 $valtouse =
'fk_mainmenu='.$menu->fk_mainmenu;
478 if ($menu->fk_leftmenu) {
479 $valtouse .=
'&fk_leftmenu='.$menu->fk_leftmenu;
481 print
'<td><input type="text" name="menuIdParent" value="'.dol_escape_htmltag(GETPOSTISSET(
'menuIdParent') ?
GETPOST(
'menuIdParent') : $valtouse).
'" class="minwidth300"></td>';
482 print
'<td>'.$langs->trans(
'DetailMenuIdParent');
483 print
', <span class="opacitymedium">'.$langs->trans(
"Example").
': fk_mainmenu=abc&fk_leftmenu=def</span>';
490 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Title').
'</td>';
491 print
'<td><input type="text" class="minwidth300" name="titre" value="'.dol_escape_htmltag($menu->title).
'"></td><td>'.$langs->trans(
'DetailTitre').
'</td></tr>';
494 print
'<tr><td class="fieldrequired">'.$langs->trans(
'URL').
'</td>';
495 print
'<td><input type="text" class="quatrevingtpercent" name="url" value="'.dol_escape_htmltag($menu->url).
'"></td><td>'.$langs->trans(
'DetailUrl').
'</td></tr>';
498 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Image').
'</td>';
499 print
'<td><input type="text" class="minwidth300" name="picto" value="'.dol_escape_htmltag($menu->prefix).
'"></td><td>'.$langs->trans(
'Example').
': fa-global</td></tr>';
502 print
'<tr><td>'.$langs->trans(
'LangFile').
'</td>';
503 print
'<td><input type="text" class="minwidth300" name="langs" value="'.dol_escape_htmltag($menu->langs).
'"></td><td>'.$langs->trans(
'DetailLangs').
'</td></tr>';
506 print
'<tr><td>'.$langs->trans(
'Position').
'</td>';
507 print
'<td><input type="text" class="minwidth100" name="position" value="'.((int) $menu->position).
'"></td><td>'.$langs->trans(
'DetailPosition').
'</td></tr>';
510 print
'<tr><td>'.$langs->trans(
'Enabled').
'</td>';
511 print
'<td><input type="text" class="minwidth500" name="enabled" value="'.dol_escape_htmltag($menu->enabled).
'"></td><td>'.$langs->trans(
'DetailEnabled');
512 if (!empty($menu->enabled)) {
513 print
' <span class="opacitymedium">('.$langs->trans(
"ConditionIsCurrently").
':</span> '.
yn((
int)
dol_eval($menu->enabled, 1, 1,
'1') <= 0 ? 0 : 1).
')';
518 print
'<tr><td>'.$langs->trans(
'Rights').
'</td>';
519 print
'<td><input type="text" class="minwidth500" name="perms" value="'.dol_escape_htmltag($menu->perms).
'"></td><td>'.$langs->trans(
'DetailRight');
520 if (!empty($menu->perms)) {
521 print
' <span class="opacitymedium">('.$langs->trans(
"ConditionIsCurrently").
':</span> '.
yn((
int)
dol_eval($menu->perms, 1, 1,
'1') <= 0 ? 0 : 1).
')';
526 print
'<tr><td>'.$langs->trans(
'Target').
'</td><td>';
527 print
'<select class="flat" id="target" name="target">';
528 print
'<option value=""'.($menu->target ==
"" ?
' selected' :
'').
'> </option>';
529 print
'<option value="_blank"'.($menu->target ==
"_blank" ?
' selected' :
'').
'>'.$langs->trans(
'_blank').
'</option>';
532 print
'</td><td>'.$langs->trans(
'DetailTarget').
'</td></tr>';
539 print $form->buttonsSaveCancel();
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.