28require
'../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/class/menubase.class.php';
33$langs->loadLangs(array(
"other",
"admin"));
35$cancel =
GETPOST(
'cancel',
'alphanohtml');
42$dirstandard = array();
43$dirsmartphone = array();
44$dirmenus = array_merge(array(
"/core/menus/"), (array) $conf->modules_parts[
'menus']);
45foreach ($dirmenus as $dirmenu) {
46 $dirstandard[] = $dirmenu.
'standard';
47 $dirsmartphone[] = $dirmenu.
'smartphone';
50$action =
GETPOST(
'action',
'aZ09');
52$menu_handler_top = $conf->global->MAIN_MENU_STANDARD;
53$menu_handler_smartphone = $conf->global->MAIN_MENU_SMARTPHONE;
54$menu_handler_top = preg_replace(
'/_backoffice.php/i',
'', $menu_handler_top);
55$menu_handler_top = preg_replace(
'/_frontoffice.php/i',
'', $menu_handler_top);
56$menu_handler_smartphone = preg_replace(
'/_backoffice.php/i',
'', $menu_handler_smartphone);
57$menu_handler_smartphone = preg_replace(
'/_frontoffice.php/i',
'', $menu_handler_smartphone);
59$menu_handler = $menu_handler_top;
61if (
GETPOST(
"handler_origine")) {
62 $menu_handler =
GETPOST(
"handler_origine");
65 $menu_handler =
GETPOST(
"menu_handler");
74if ($action ==
'add') {
76 header(
"Location: ".DOL_URL_ROOT.
"/admin/menus/index.php?menu_handler=".$menu_handler);
82 if (
GETPOST(
'menuIdParent',
'alphanohtml') && !is_numeric(
GETPOST(
'menuIdParent',
'alphanohtml'))) {
83 $tmp = explode(
'&',
GETPOST(
'menuIdParent',
'alphanohtml'));
84 foreach ($tmp as $s) {
85 if (preg_match(
'/fk_mainmenu=/', $s)) {
86 $mainmenu = preg_replace(
'/fk_mainmenu=/',
'', $s);
88 if (preg_match(
'/fk_leftmenu=/', $s)) {
89 $leftmenu = preg_replace(
'/fk_leftmenu=/',
'', $s);
94 $langs->load(
"errors");
97 if (!$error && !
GETPOST(
'menu_handler')) {
98 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MenuHandler")),
null,
'errors');
102 if (!$error && !
GETPOST(
'type')) {
103 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Type")),
null,
'errors');
107 if (!$error && !
GETPOST(
'url')) {
108 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"URL")),
null,
'errors');
112 if (!$error && !
GETPOST(
'titre')) {
113 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Title")),
null,
'errors');
117 if (!$error &&
GETPOST(
'menuIdParent',
'alphanohtml') &&
GETPOST(
'type') ==
'top') {
118 setEventMessages($langs->trans(
"ErrorTopMenuMustHaveAParentWithId0"),
null,
'errors');
122 if (!$error && !
GETPOST(
'menuIdParent',
'alphanohtml') &&
GETPOST(
'type') ==
'left') {
123 setEventMessages($langs->trans(
"ErrorLeftMenuMustHaveAParentId"),
null,
'errors');
130 $menu->menu_handler = preg_replace(
'/_menu$/',
'',
GETPOST(
'menu_handler',
'aZ09'));
131 $menu->type = (string)
GETPOST(
'type',
'alphanohtml');
132 $menu->title = (string)
GETPOST(
'titre',
'alphanohtml');
133 $menu->prefix = (string)
GETPOST(
'picto',
'restricthtmlallowclass');
134 $menu->url = (string)
GETPOST(
'url',
'alphanohtml');
135 $menu->langs = (string)
GETPOST(
'langs',
'alphanohtml');
136 $menu->position = (int)
GETPOST(
'position',
'int');
137 $menu->enabled = (string)
GETPOST(
'enabled',
'alphanohtml');
138 $menu->perms = (string)
GETPOST(
'perms',
'alphanohtml');
139 $menu->target = (string)
GETPOST(
'target',
'alphanohtml');
140 $menu->user = (string)
GETPOST(
'user',
'alphanohtml');
141 $menu->mainmenu = (string)
GETPOST(
'propertymainmenu',
'alphanohtml');
142 if (is_numeric(
GETPOST(
'menuIdParent',
'alphanohtml'))) {
143 $menu->fk_menu = (int)
GETPOST(
'menuIdParent',
'alphanohtml');
145 if (
GETPOST(
'type',
'alphanohtml') ==
'top') {
150 $menu->fk_mainmenu = $mainmenu;
151 $menu->fk_leftmenu = $leftmenu;
154 $result = $menu->create($user);
156 header(
"Location: ".DOL_URL_ROOT.
"/admin/menus/index.php?menu_handler=".
GETPOST(
'menu_handler',
'aZ09'));
165if ($action ==
'update') {
167 $leftmenu =
''; $mainmenu =
'';
168 if (
GETPOST(
'menuIdParent',
'alphanohtml') && !is_numeric(
GETPOST(
'menuIdParent',
'alphanohtml'))) {
169 $tmp = explode(
'&',
GETPOST(
'menuIdParent',
'alphanohtml'));
170 foreach ($tmp as $s) {
171 if (preg_match(
'/fk_mainmenu=/', $s)) {
172 $mainmenu = preg_replace(
'/fk_mainmenu=/',
'', $s);
174 if (preg_match(
'/fk_leftmenu=/', $s)) {
175 $leftmenu = preg_replace(
'/fk_leftmenu=/',
'', $s);
181 if (!$error && !
GETPOST(
'url')) {
182 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"URL")),
null,
'errors');
189 $result = $menu->fetch(
GETPOST(
'menuId',
'int'));
191 $menu->title = (string)
GETPOST(
'titre',
'alphanohtml');
192 $menu->prefix = (string)
GETPOST(
'picto',
'restricthtmlallowclass');
193 $menu->leftmenu = (string)
GETPOST(
'leftmenu',
'aZ09');
194 $menu->url = (string)
GETPOST(
'url',
'alphanohtml');
195 $menu->langs = (string)
GETPOST(
'langs',
'alphanohtml');
196 $menu->position = (int)
GETPOST(
'position',
'int');
197 $menu->enabled = (string)
GETPOST(
'enabled',
'alphanohtml');
198 $menu->perms = (string)
GETPOST(
'perms',
'alphanohtml');
199 $menu->target = (string)
GETPOST(
'target',
'alphanohtml');
200 $menu->user = (string)
GETPOST(
'user',
'alphanohtml');
201 $menu->mainmenu = (string)
GETPOST(
'propertymainmenu',
'alphanohtml');
202 if (is_numeric(
GETPOST(
'menuIdParent',
'alphanohtml'))) {
203 $menu->fk_menu = (int)
GETPOST(
'menuIdParent',
'alphanohtml');
205 if (
GETPOST(
'type',
'alphanohtml') ==
'top') {
210 $menu->fk_mainmenu = $mainmenu;
211 $menu->fk_leftmenu = $leftmenu;
214 $result = $menu->update($user);
216 setEventMessages($langs->trans(
"RecordModifiedSuccessfully"),
null,
'mesgs');
226 header(
"Location: ".DOL_URL_ROOT.
"/admin/menus/index.php?menu_handler=".$menu_handler);
232 header(
"Location: ".DOL_URL_ROOT.
"/admin/menus/index.php?menu_handler=".$menu_handler);
243$form =
new Form($db);
249if ($action ==
'create') {
250 print
'<script type="text/javascript">
251 jQuery(document).ready(function() {
252 function init_topleft()
254 if (jQuery("#topleft").val() == \'top\')
256 jQuery("#menuIdParent").prop("disabled", true);
257 jQuery("#menuIdParent").val(\'\');
258 jQuery("#propertymainmenu").removeAttr("disabled");
259 jQuery("#propertymainmenu").val(\'\');
261 if (jQuery("#topleft").val() == \'left\')
263 jQuery("#menuIdParent").removeAttr("disabled");
264 jQuery("#propertymainmenu").prop("disabled", true);
268 jQuery("#topleft").click(function() {
276 print
'<form action="'.DOL_URL_ROOT.
'/admin/menus/edit.php?action=add&token='.newToken().
'&menuId='.
GETPOST(
'menuId',
'int').
'" method="post" name="formmenucreate">';
277 print
'<input type="hidden" name="token" value="'.newToken().
'">';
281 print
'<div class="div-table-responsive">';
282 print
'<table class="border centpercent">';
285 $parent_rowid =
GETPOST(
'menuId',
'int');
286 $parent_mainmenu =
'';
287 $parent_leftmenu =
'';
291 if (
GETPOST(
'menuId',
'int')) {
292 $sql =
"SELECT m.rowid, m.mainmenu, m.leftmenu, m.level, m.langs";
293 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu as m";
294 $sql .=
" WHERE m.rowid = ".((int)
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" id="menuuser">';
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>';
323 print
'<td>'.$langs->trans(
'DetailUser').
'</td></tr>';
326 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Position').
'</td><td>';
328 print $langs->trans(
'Left');
329 print
'<input type="hidden" name="type" value="left">';
331 print
'<select name="type" class="flat" id="topleft">';
332 print
'<option value=""> </option>';
333 print
'<option value="top"'.(GETPOST(
"type") ==
'top' ?
' selected' :
'').
'>'.$langs->trans(
'Top').
'</option>';
334 print
'<option value="left"'.(GETPOST(
"type") ==
'left' ?
' selected' :
'').
'>'.$langs->trans(
'Left').
'</option>';
338 print
'</td><td>'.$langs->trans(
'DetailType').
'</td></tr>';
341 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MainMenuCode').
'</td>';
342 print
'<td><input type="text" class="minwidth300" id="propertymainmenu" name="propertymainmenu" value="'.(GETPOSTISSET(
"propertymainmenu") ?
GETPOST(
"propertymainmenu",
'alphanohtml') :
'').
'"></td>';
344 print $langs->trans(
"Example").
': mytopmenukey';
348 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MenuIdParent').
'</td>';
350 print
'<td>'.$parent_rowid.
'<input type="hidden" name="menuIdParent" value="'.$parent_rowid.
'"></td>';
352 print
'<td><input type="text" class="minwidth300" id="menuIdParent" name="menuIdParent" value="'.(GETPOSTISSET(
"menuIdParent") ?
GETPOST(
"menuIdParent",
'alphanohtml') :
'').
'"></td>';
354 print
'<td>'.$langs->trans(
'DetailMenuIdParent');
355 print
', '.$langs->trans(
"Example").
': fk_mainmenu=abc&fk_leftmenu=def';
359 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Title').
'</td>';
360 print
'<td><input type="text" class="minwidth300" name="titre" value="'.dol_escape_htmltag(
GETPOST(
"titre",
'alphanohtml')).
'"></td><td>'.$langs->trans(
'DetailTitre').
'</td></tr>';
363 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Image').
'</td>';
364 print
'<td><input type="text" class="minwidth300" name="picto" value="'.dol_escape_htmltag(
GETPOST(
"picto",
'alphanohtmlallowclass')).
'"></td><td>'.$langs->trans(
'Example').
': fa-global</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(
'LangFile').
'</td>';
372 print
'<td><input type="text" class="minwidth300" name="langs" value="'.dol_escape_htmltag($parent_langs).
'"></td><td>'.$langs->trans(
'DetailLangs').
'</td></tr>';
375 print
'<tr><td>'.$langs->trans(
'Position').
'</td>';
376 print
'<td><input type="text" class="width100" name="position" value="'.((int) (GETPOSTISSET(
"position") ?
GETPOSTINT(
"position") : 100)).
'"></td><td>'.$langs->trans(
'DetailPosition').
'</td></tr>';
379 print
'<tr><td>'.$langs->trans(
'Enabled').
'</td>';
380 print
'<td><input type="text" class="minwidth500" name="enabled" value="'.(GETPOSTISSET(
'enabled') ?
GETPOST(
"enabled",
'alphanohtml') :
'1').
'"></td><td>'.$langs->trans(
'DetailEnabled').
'</td></tr>';
383 print
'<tr><td>'.$langs->trans(
'Rights').
'</td>';
384 print
'<td><input type="text" class="minwidth500" name="perms" value="'.(GETPOSTISSET(
'perms') ?
GETPOST(
'perms',
'alphanohtml') :
'1').
'"></td><td>'.$langs->trans(
'DetailRight').
'</td></tr>';
387 print
'<tr><td>'.$langs->trans(
'Target').
'</td><td><select class="flat" name="target" id="target">';
388 print
'<option value=""'.(isset($menu->target) && $menu->target ==
"" ?
' selected' :
'').
'> </option>';
389 print
'<option value="_blank"'.(isset($menu->target) && $menu->target ==
"_blank" ?
' selected' :
'').
'>'.$langs->trans(
'_blank').
'</option>';
392 print
'</td></td><td>'.$langs->trans(
'DetailTarget').
'</td></tr>';
399 print $form->buttonsSaveCancel();
402} elseif ($action ==
'edit') {
406 print
'<form action="./edit.php" method="POST" name="formmenuedit">';
407 print
'<input type="hidden" name="action" value="update">';
408 print
'<input type="hidden" name="token" value="'.newToken().
'">';
409 print
'<input type="hidden" name="handler_origine" value="'.$menu_handler.
'">';
410 print
'<input type="hidden" name="menuId" value="'.GETPOST(
'menuId',
'int').
'">';
414 print
'<div class="div-table-responsive">';
415 print
'<table class="border centpercent">';
418 $result = $menu->fetch(
GETPOST(
'menuId',
'int'));
422 print
'<tr><td>'.$langs->trans(
'Id').
'</td><td>'.$menu->id.
'</td><td>'.$langs->trans(
'DetailId').
'</td></tr>';
425 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>';
428 if ($menu->menu_handler ==
'all') {
429 $handler = $langs->trans(
'AllMenus');
431 $handler = $menu->menu_handler;
433 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MenuHandler').
'</td><td>'.$handler.
'</td><td>'.$langs->trans(
'DetailMenuHandler').
'</td></tr>';
436 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'MenuForUsers').
'</td><td>';
437 print
'<select class="flat" name="user" id="menuuser">';
438 print
'<option value="2"'.($menu->user == 2 ?
' selected' :
'').
'>'.$langs->trans(
"AllMenus").
'</option>';
439 print
'<option value="0"'.($menu->user == 0 ?
' selected' :
'').
'>'.$langs->trans(
'Internal').
'</option>';
440 print
'<option value="1"'.($menu->user == 1 ?
' selected' :
'').
'>'.$langs->trans(
'External').
'</option>';
443 print
'</td><td>'.$langs->trans(
'DetailUser').
'</td></tr>';
446 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Position').
'</td>';
447 print
'<td>'.$langs->trans(ucfirst($menu->type)).
'</td><td>'.$langs->trans(
'DetailType').
'</td></tr>';
450 if ($menu->type ==
'top') {
451 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MainMenuCode').
'</td>';
458 print
'<td><input type="text" class="minwidth300" id="propertymainmenu" name="propertymainmenu" value="'.(GETPOST(
"propertymainmenu",
'alphanohtml') ?
GETPOST(
"propertymainmenu",
'alphanohtml') : $menu->mainmenu).
'"></td>';
461 print $langs->trans(
"Example").
': mytopmenukey';
466 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MenuIdParent');
468 $valtouse = $menu->fk_menu;
469 if ($menu->fk_mainmenu) {
470 $valtouse =
'fk_mainmenu='.$menu->fk_mainmenu;
472 if ($menu->fk_leftmenu) {
473 $valtouse .=
'&fk_leftmenu='.$menu->fk_leftmenu;
475 print
'<td><input type="text" name="menuIdParent" value="'.dol_escape_htmltag(GETPOSTISSET(
'menuIdParent') ?
GETPOST(
'menuIdParent') : $valtouse).
'" class="minwidth300"></td>';
476 print
'<td>'.$langs->trans(
'DetailMenuIdParent');
477 print
', <span class="opacitymedium">'.$langs->trans(
"Example").
': fk_mainmenu=abc&fk_leftmenu=def</span>';
484 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Title').
'</td>';
485 print
'<td><input type="text" class="minwidth300" name="titre" value="'.dol_escape_htmltag($menu->title).
'"></td><td>'.$langs->trans(
'DetailTitre').
'</td></tr>';
488 print
'<tr><td class="fieldrequired">'.$langs->trans(
'URL').
'</td>';
489 print
'<td><input type="text" class="quatrevingtpercent" name="url" value="'.dol_escape_htmltag($menu->url).
'"></td><td>'.$langs->trans(
'DetailUrl').
'</td></tr>';
492 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Image').
'</td>';
493 print
'<td><input type="text" class="minwidth300" name="picto" value="'.dol_escape_htmltag($menu->prefix).
'"></td><td>'.$langs->trans(
'Example').
': fa-global</td></tr>';
496 print
'<tr><td>'.$langs->trans(
'LangFile').
'</td>';
497 print
'<td><input type="text" class="minwidth300" name="langs" value="'.dol_escape_htmltag($menu->langs).
'"></td><td>'.$langs->trans(
'DetailLangs').
'</td></tr>';
500 print
'<tr><td>'.$langs->trans(
'Position').
'</td>';
501 print
'<td><input type="text" class="minwidth100" name="position" value="'.((int) $menu->position).
'"></td><td>'.$langs->trans(
'DetailPosition').
'</td></tr>';
504 print
'<tr><td>'.$langs->trans(
'Enabled').
'</td>';
505 print
'<td><input type="text" class="minwidth500" name="enabled" value="'.dol_escape_htmltag($menu->enabled).
'"></td><td>'.$langs->trans(
'DetailEnabled');
506 if (!empty($menu->enabled)) {
507 print
' <span class="opacitymedium">('.$langs->trans(
"ConditionIsCurrently").
':</span> '.
yn(
dol_eval($menu->enabled, 1, 1,
'1')).
')';
512 print
'<tr><td>'.$langs->trans(
'Rights').
'</td>';
513 print
'<td><input type="text" class="minwidth500" name="perms" value="'.dol_escape_htmltag($menu->perms).
'"></td><td>'.$langs->trans(
'DetailRight');
514 if (!empty($menu->perms)) {
515 print
' <span class="opacitymedium">('.$langs->trans(
"ConditionIsCurrently").
':</span> '.
yn(
dol_eval($menu->perms, 1, 1,
'1')).
')';
520 print
'<tr><td>'.$langs->trans(
'Target').
'</td><td>';
521 print
'<select class="flat" id="target" name="target">';
522 print
'<option value=""'.($menu->target ==
"" ?
' selected' :
'').
'> </option>';
523 print
'<option value="_blank"'.($menu->target ==
"_blank" ?
' selected' :
'').
'>'.$langs->trans(
'_blank').
'</option>';
526 print
'</td><td>'.$langs->trans(
'DetailTarget').
'</td></tr>';
533 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()
Empty header.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOSTINT($paramname, $method=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_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=0, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.