30require
'../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/class/menubase.class.php';
43$langs->loadLangs(array(
"other",
"admin"));
45$cancel =
GETPOST(
'cancel',
'alphanohtml');
52$dirstandard = array();
53$dirsmartphone = array();
54$dirmenus = array_merge(array(
"/core/menus/"), (array)
$conf->modules_parts[
'menus']);
55foreach ($dirmenus as $dirmenu) {
56 $dirstandard[] = $dirmenu.
'standard';
57 $dirsmartphone[] = $dirmenu.
'smartphone';
60$action =
GETPOST(
'action',
'aZ09');
65$menu_handler_top = preg_replace(
'/_backoffice.php/i',
'', $menu_handler_top);
66$menu_handler_top = preg_replace(
'/_frontoffice.php/i',
'', $menu_handler_top);
67$menu_handler_smartphone = preg_replace(
'/_backoffice.php/i',
'', $menu_handler_smartphone);
68$menu_handler_smartphone = preg_replace(
'/_frontoffice.php/i',
'', $menu_handler_smartphone);
70$menu_handler = $menu_handler_top;
72if (
GETPOST(
"handler_origine")) {
73 $menu_handler =
GETPOST(
"handler_origine");
76 $menu_handler =
GETPOST(
"menu_handler");
85if ($action ==
'add') {
87 header(
"Location: ".DOL_URL_ROOT.
"/admin/menus/index.php?menu_handler=".$menu_handler);
93 if (
GETPOST(
'menuIdParent',
'alphanohtml') && !is_numeric(
GETPOST(
'menuIdParent',
'alphanohtml'))) {
94 $tmp = explode(
'&',
GETPOST(
'menuIdParent',
'alphanohtml'));
95 foreach ($tmp as $s) {
96 if (preg_match(
'/fk_mainmenu=/', $s)) {
97 $mainmenu = preg_replace(
'/fk_mainmenu=/',
'', $s);
99 if (preg_match(
'/fk_leftmenu=/', $s)) {
100 $leftmenu = preg_replace(
'/fk_leftmenu=/',
'', $s);
105 $langs->load(
"errors");
108 if (!$error && !
GETPOST(
'menu_handler')) {
109 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MenuHandler")),
null,
'errors');
113 if (!$error && !
GETPOST(
'type')) {
114 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Position")),
null,
'errors');
118 if (!$error && !
GETPOST(
'url')) {
119 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"URL")),
null,
'errors');
123 if (!$error && !
GETPOST(
'titre')) {
124 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Title")),
null,
'errors');
128 if (!$error &&
GETPOST(
'menuIdParent',
'alphanohtml') &&
GETPOST(
'type') ==
'top') {
129 setEventMessages($langs->trans(
"ErrorTopMenuMustHaveAParentWithId0"),
null,
'errors');
133 if (!$error && !
GETPOST(
'menuIdParent',
'alphanohtml') &&
GETPOST(
'type') ==
'left') {
134 setEventMessages($langs->trans(
"ErrorLeftMenuMustHaveAParentId"),
null,
'errors');
141 $menu->menu_handler = preg_replace(
'/_menu$/',
'',
GETPOST(
'menu_handler',
'aZ09'));
142 $menu->type = (string)
GETPOST(
'type',
'alphanohtml');
143 $menu->title = (string)
GETPOST(
'titre',
'alphanohtml');
144 $menu->prefix = (string)
GETPOST(
'picto',
'restricthtmlallowclass');
145 $menu->url = (string)
GETPOST(
'url',
'alphanohtml');
146 $menu->langs = (string)
GETPOST(
'langs',
'alphanohtml');
148 $menu->enabled = (string)
GETPOST(
'enabled',
'alphanohtml');
149 $menu->perms = (string)
GETPOST(
'perms',
'alphanohtml');
150 $menu->target = (string)
GETPOST(
'target',
'alphanohtml');
152 $menu->mainmenu = (string)
GETPOST(
'propertymainmenu',
'alphanohtml');
153 if (is_numeric(
GETPOST(
'menuIdParent',
'alphanohtml'))) {
154 $menu->fk_menu = (int)
GETPOST(
'menuIdParent',
'alphanohtml');
156 if (
GETPOST(
'type',
'alphanohtml') ==
'top') {
161 $menu->fk_mainmenu = $mainmenu;
162 $menu->fk_leftmenu = $leftmenu;
165 $result = $menu->create($user);
167 header(
"Location: ".DOL_URL_ROOT.
"/admin/menus/index.php?menu_handler=".
GETPOST(
'menu_handler',
'aZ09'));
176if ($action ==
'update') {
180 if (
GETPOST(
'menuIdParent',
'alphanohtml') && !is_numeric(
GETPOST(
'menuIdParent',
'alphanohtml'))) {
181 $tmp = explode(
'&',
GETPOST(
'menuIdParent',
'alphanohtml'));
182 foreach ($tmp as $s) {
183 if (preg_match(
'/fk_mainmenu=/', $s)) {
184 $mainmenu = preg_replace(
'/fk_mainmenu=/',
'', $s);
186 if (preg_match(
'/fk_leftmenu=/', $s)) {
187 $leftmenu = preg_replace(
'/fk_leftmenu=/',
'', $s);
193 if (!$error && !
GETPOST(
'url')) {
194 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"URL")),
null,
'errors');
203 $menu->title = (string)
GETPOST(
'titre',
'alphanohtml');
204 $menu->prefix = (string)
GETPOST(
'picto',
'restricthtmlallowclass');
205 $menu->leftmenu = (string)
GETPOST(
'leftmenu',
'aZ09');
206 $menu->url = (string)
GETPOST(
'url',
'alphanohtml');
207 $menu->langs = (string)
GETPOST(
'langs',
'alphanohtml');
209 $menu->enabled = (string)
GETPOST(
'enabled',
'alphanohtml');
210 $menu->perms = (string)
GETPOST(
'perms',
'alphanohtml');
211 $menu->target = (string)
GETPOST(
'target',
'alphanohtml');
213 $menu->mainmenu = (string)
GETPOST(
'propertymainmenu',
'alphanohtml');
214 if (is_numeric(
GETPOST(
'menuIdParent',
'alphanohtml'))) {
215 $menu->fk_menu = (int)
GETPOST(
'menuIdParent',
'alphanohtml');
217 if (
GETPOST(
'type',
'alphanohtml') ==
'top') {
222 $menu->fk_mainmenu = $mainmenu;
223 $menu->fk_leftmenu = $leftmenu;
226 $result = $menu->update($user);
228 setEventMessages($langs->trans(
"RecordModifiedSuccessfully"),
null,
'mesgs');
238 header(
"Location: ".DOL_URL_ROOT.
"/admin/menus/index.php?menu_handler=".$menu_handler);
244 header(
"Location: ".DOL_URL_ROOT.
"/admin/menus/index.php?menu_handler=".$menu_handler);
255$form =
new Form($db);
258llxHeader(
'', $langs->trans(
'Menu'),
'',
'', 0, 0,
'',
'',
'',
'mod-admin page-menus_edit');
261if ($action ==
'create') {
262 print
'<script type="text/javascript">
263 jQuery(document).ready(function() {
264 function init_topleft()
266 if (jQuery("#topleft").val() == \'top\')
268 jQuery("#menuIdParent").prop("disabled", true);
269 jQuery("#menuIdParent").val(\'\');
270 jQuery("#propertymainmenu").removeAttr("disabled");
271 jQuery("#propertymainmenu").val(\'\');
273 if (jQuery("#topleft").val() == \'left\')
275 jQuery("#menuIdParent").removeAttr("disabled");
276 jQuery("#propertymainmenu").prop("disabled", true);
280 jQuery("#topleft").click(function() {
288 print
'<form action="'.DOL_URL_ROOT.
'/admin/menus/edit.php?menuId='.
GETPOSTINT(
'menuId').
'" method="POST" name="formmenucreate">';
289 print
'<input type="hidden" name="action" value="add">';
290 print
'<input type="hidden" name="token" value="'.newToken().
'">';
294 print
'<div class="div-table-responsive">';
295 print
'<table class="border centpercent">';
299 $parent_mainmenu =
'';
300 $parent_leftmenu =
'';
305 $sql =
"SELECT m.rowid, m.mainmenu, m.leftmenu, m.level, m.langs";
306 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu as m";
307 $sql .=
" WHERE m.rowid = ".(GETPOSTINT(
'menuId'));
308 $res = $db->query($sql);
310 while ($menu = $db->fetch_array($res)) {
311 $parent_rowid = $menu[
'rowid'];
312 $parent_mainmenu = $menu[
'mainmenu'];
313 $parent_leftmenu = $menu[
'leftmenu'];
314 $parent_langs = $menu[
'langs'];
315 $parent_level = $menu[
'level'];
321 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MenuHandler').
'</td>';
323 $formadmin->select_menu_families($menu_handler.(preg_match(
'/_menu/', $menu_handler) ?
'' :
'_menu'),
'menu_handler', array_merge($dirstandard, $dirsmartphone));
325 print
'<td>'.$langs->trans(
'DetailMenuHandler').
'</td></tr>';
328 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'MenuForUsers').
'</td>';
329 print
'<td><select class="flat" name="user" id="menuuser">';
330 print
'<option value="2" selected>'.$langs->trans(
"AllMenus").
'</option>';
331 print
'<option value="0">'.$langs->trans(
'Internal').
'</option>';
332 print
'<option value="1">'.$langs->trans(
'External').
'</option>';
336 print
'<td>'.$langs->trans(
'DetailUser').
'</td></tr>';
339 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Position').
'</td><td>';
341 print $langs->trans(
'Left');
342 print
'<input type="hidden" name="type" value="left">';
344 print
'<select name="type" class="flat" id="topleft">';
345 print
'<option value=""> </option>';
346 print
'<option value="top"'.(GETPOST(
"type") ==
'top' ?
' selected' :
'').
'>'.$langs->trans(
'Top').
'</option>';
347 print
'<option value="left"'.(GETPOST(
"type") ==
'left' ?
' selected' :
'').
'>'.$langs->trans(
'Left').
'</option>';
351 print
'</td><td>'.$langs->trans(
'DetailType').
'</td></tr>';
354 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MainMenuCode').
'</td>';
355 print
'<td><input type="text" class="minwidth300" id="propertymainmenu" name="propertymainmenu" value="'.(GETPOSTISSET(
"propertymainmenu") ?
GETPOST(
"propertymainmenu",
'alphanohtml') :
'').
'"></td>';
357 print $langs->trans(
"Example").
': mytopmenukey';
361 print
'<tr><td>'.$langs->trans(
'MenuIdParent').
'</td>';
363 print
'<td>'.$parent_rowid.
'<input type="hidden" name="menuIdParent" value="'.$parent_rowid.
'"></td>';
365 print
'<td><input type="text" class="minwidth300" id="menuIdParent" name="menuIdParent" value="'.(GETPOSTISSET(
"menuIdParent") ?
GETPOST(
"menuIdParent",
'alphanohtml') :
'').
'"></td>';
367 print
'<td>'.$langs->trans(
'DetailMenuIdParent');
368 print
', '.$langs->trans(
"Example").
': fk_mainmenu=abc&fk_leftmenu=def';
372 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Title').
'</td>';
373 print
'<td><input type="text" class="minwidth300" name="titre" value="'.dol_escape_htmltag(
GETPOST(
"titre",
'alphanohtml')).
'"></td><td>'.$langs->trans(
'DetailTitre').
'</td></tr>';
376 print
'<tr><td class="fieldrequired">'.$langs->trans(
'URL').
'</td>';
377 print
'<td><input type="text" class="minwidth500" name="url" value="'.dol_escape_htmltag(
GETPOST(
"url",
'alphanohtml')).
'"></td><td>'.$langs->trans(
'DetailUrl').
'</td></tr>';
380 print
'<tr><td>'.$langs->trans(
'Image').
'</td>';
381 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>';
384 print
'<tr><td>'.$langs->trans(
'LangFile').
'</td>';
385 print
'<td><input type="text" class="minwidth300" name="langs" value="'.dol_escape_htmltag($parent_langs).
'"></td><td>'.$langs->trans(
'DetailLangs').
'</td></tr>';
388 print
'<tr><td>'.$langs->trans(
'Position').
'</td>';
389 print
'<td><input type="text" class="width100" name="position" value="'.((int) (GETPOSTISSET(
"position") ?
GETPOSTINT(
"position") : 100)).
'"></td><td>'.$langs->trans(
'DetailPosition').
'</td></tr>';
392 print
'<tr><td>'.$langs->trans(
'Enabled').
'</td>';
393 print
'<td><input type="text" class="minwidth500" name="enabled" value="'.(GETPOSTISSET(
'enabled') ?
GETPOST(
"enabled",
'alphanohtml') :
'1').
'"></td><td>'.$langs->trans(
'DetailEnabled').
'</td></tr>';
396 print
'<tr><td>'.$langs->trans(
'Rights').
'</td>';
397 print
'<td><input type="text" class="minwidth500" name="perms" value="'.(GETPOSTISSET(
'perms') ?
GETPOST(
'perms',
'alphanohtml') :
'1').
'"></td><td>'.$langs->trans(
'DetailRight').
'</td></tr>';
400 print
'<tr><td>'.$langs->trans(
'Target').
'</td><td><select class="flat" name="target" id="target">';
402 print
'<option value=""'.(isset($menu->target) && $menu->target ==
"" ?
' selected' :
'').
'> </option>';
403 print
'<option value="_blank"'.(isset($menu->target) && $menu->target ==
"_blank" ?
' selected' :
'').
'>'.$langs->trans(
'_blank').
'</option>';
407 print
'</td></td><td>'.$langs->trans(
'DetailTarget').
'</td></tr>';
414 print $form->buttonsSaveCancel();
417} elseif ($action ==
'edit') {
421 print
'<form action="./edit.php" method="POST" name="formmenuedit">';
422 print
'<input type="hidden" name="action" value="update">';
423 print
'<input type="hidden" name="token" value="'.newToken().
'">';
424 print
'<input type="hidden" name="handler_origine" value="'.$menu_handler.
'">';
425 print
'<input type="hidden" name="menuId" value="'.GETPOSTINT(
'menuId').
'">';
429 print
'<div class="div-table-responsive">';
430 print
'<table class="border centpercent">';
437 print
'<tr><td>'.$langs->trans(
'Id').
'</td><td>'.$menu->id.
'</td><td>'.$langs->trans(
'DetailId').
'</td></tr>';
440 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>';
443 if ($menu->menu_handler ==
'all') {
444 $handler = $langs->trans(
'AllMenus');
446 $handler = $menu->menu_handler;
448 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MenuHandler').
'</td><td>'.$handler.
'</td><td>'.$langs->trans(
'DetailMenuHandler').
'</td></tr>';
451 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'MenuForUsers').
'</td><td>';
452 print
'<select class="flat" name="user" id="menuuser">';
453 print
'<option value="2"'.($menu->user == 2 ?
' selected' :
'').
'>'.$langs->trans(
"AllMenus").
'</option>';
454 print
'<option value="0"'.($menu->user == 0 ?
' selected' :
'').
'>'.$langs->trans(
'Internal').
'</option>';
455 print
'<option value="1"'.($menu->user == 1 ?
' selected' :
'').
'>'.$langs->trans(
'External').
'</option>';
458 print
'</td><td>'.$langs->trans(
'DetailUser').
'</td></tr>';
461 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Position').
'</td>';
462 print
'<td>'.$langs->trans(ucfirst($menu->type)).
'</td><td>'.$langs->trans(
'DetailType').
'</td></tr>';
465 if ($menu->type ==
'top') {
466 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MainMenuCode').
'</td>';
473 print
'<td><input type="text" class="minwidth300" id="propertymainmenu" name="propertymainmenu" value="'.(GETPOST(
"propertymainmenu",
'alphanohtml') ?
GETPOST(
"propertymainmenu",
'alphanohtml') : $menu->mainmenu).
'"></td>';
476 print $langs->trans(
"Example").
': mytopmenukey';
481 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MenuIdParent');
483 $valtouse = $menu->fk_menu;
484 if ($menu->fk_mainmenu) {
485 $valtouse =
'fk_mainmenu='.$menu->fk_mainmenu;
487 if ($menu->fk_leftmenu) {
488 $valtouse .=
'&fk_leftmenu='.$menu->fk_leftmenu;
490 print
'<td><input type="text" name="menuIdParent" value="'.dol_escape_htmltag(GETPOSTISSET(
'menuIdParent') ?
GETPOST(
'menuIdParent') : $valtouse).
'" class="minwidth300"></td>';
491 print
'<td>'.$langs->trans(
'DetailMenuIdParent');
492 print
', <span class="opacitymedium">'.$langs->trans(
"Example").
': fk_mainmenu=abc&fk_leftmenu=def</span>';
499 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Title').
'</td>';
500 print
'<td><input type="text" class="minwidth300" name="titre" value="'.dol_escape_htmltag($menu->title).
'"></td><td>'.$langs->trans(
'DetailTitre').
'</td></tr>';
503 print
'<tr><td class="fieldrequired">'.$langs->trans(
'URL').
'</td>';
504 print
'<td><input type="text" class="quatrevingtpercent" name="url" value="'.dol_escape_htmltag($menu->url).
'"></td><td>'.$langs->trans(
'DetailUrl').
'</td></tr>';
507 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Image').
'</td>';
508 print
'<td><input type="text" class="minwidth300" name="picto" value="'.dol_escape_htmltag($menu->prefix).
'"></td><td>'.$langs->trans(
'Example').
': fa-global</td></tr>';
511 print
'<tr><td>'.$langs->trans(
'LangFile').
'</td>';
512 print
'<td><input type="text" class="minwidth300" name="langs" value="'.dol_escape_htmltag($menu->langs).
'"></td><td>'.$langs->trans(
'DetailLangs').
'</td></tr>';
515 print
'<tr><td>'.$langs->trans(
'Position').
'</td>';
516 print
'<td><input type="text" class="minwidth100" name="position" value="'.((int) $menu->position).
'"></td><td>'.$langs->trans(
'DetailPosition').
'</td></tr>';
519 print
'<tr><td>'.$langs->trans(
'Enabled').
'</td>';
520 print
'<td><input type="text" class="minwidth500" name="enabled" value="'.dol_escape_htmltag($menu->enabled).
'"></td><td>'.$langs->trans(
'DetailEnabled');
521 if (!empty($menu->enabled)) {
522 print
' <span class="opacitymedium">('.$langs->trans(
"ConditionIsCurrently").
':</span> '.
yn((
int)
dol_eval($menu->enabled, 1, 1,
'1') <= 0 ? 0 : 1).
')';
527 print
'<tr><td>'.$langs->trans(
'Rights').
'</td>';
528 print
'<td><input type="text" class="minwidth500" name="perms" value="'.dol_escape_htmltag($menu->perms).
'"></td><td>'.$langs->trans(
'DetailRight');
529 if (!empty($menu->perms)) {
530 print
' <span class="opacitymedium">('.$langs->trans(
"ConditionIsCurrently").
':</span> '.
yn((
int)
dol_eval($menu->perms, 1, 1,
'1') <= 0 ? 0 : 1).
')';
535 print
'<tr><td>'.$langs->trans(
'Target').
'</td><td>';
536 print
'<select class="flat" id="target" name="target">';
537 print
'<option value=""'.($menu->target ==
"" ?
' selected' :
'').
'> </option>';
538 print
'<option value="_blank"'.($menu->target ==
"_blank" ?
' selected' :
'').
'>'.$langs->trans(
'_blank').
'</option>';
541 print
'</td><td>'.$langs->trans(
'DetailTarget').
'</td></tr>';
548 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.