28 require
'../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
30 require_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']);
45 foreach ($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;
61 if (
GETPOST(
"handler_origine")) {
62 $menu_handler =
GETPOST(
"handler_origine");
65 $menu_handler =
GETPOST(
"menu_handler");
74 if ($action ==
'update') {
76 $leftmenu =
''; $mainmenu =
'';
77 if (
GETPOST(
'menuIdParent',
'alphanohtml') && !is_numeric(
GETPOST(
'menuIdParent',
'alphanohtml'))) {
78 $tmp = explode(
'&',
GETPOST(
'menuIdParent',
'alphanohtml'));
79 foreach ($tmp as $s) {
80 if (preg_match(
'/fk_mainmenu=/', $s)) {
81 $mainmenu = preg_replace(
'/fk_mainmenu=/',
'', $s);
83 if (preg_match(
'/fk_leftmenu=/', $s)) {
84 $leftmenu = preg_replace(
'/fk_leftmenu=/',
'', $s);
90 $result = $menu->fetch(
GETPOST(
'menuId',
'int'));
92 $menu->title = (string)
GETPOST(
'titre',
'alphanohtml');
93 $menu->leftmenu = (string)
GETPOST(
'leftmenu',
'aZ09');
94 $menu->url = (string)
GETPOST(
'url',
'alphanohtml');
95 $menu->langs = (string)
GETPOST(
'langs',
'alphanohtml');
96 $menu->position = (int)
GETPOST(
'position',
'int');
97 $menu->enabled = (string)
GETPOST(
'enabled',
'alphanohtml');
98 $menu->perms = (string)
GETPOST(
'perms',
'alphanohtml');
99 $menu->target = (string)
GETPOST(
'target',
'alphanohtml');
100 $menu->user = (string)
GETPOST(
'user',
'alphanohtml');
101 $menu->mainmenu = (string)
GETPOST(
'propertymainmenu',
'alphanohtml');
102 if (is_numeric(
GETPOST(
'menuIdParent',
'alphanohtml'))) {
103 $menu->fk_menu = (int)
GETPOST(
'menuIdParent',
'alphanohtml');
105 if (
GETPOST(
'type',
'alphanohtml') ==
'top') {
110 $menu->fk_mainmenu = $mainmenu;
111 $menu->fk_leftmenu = $leftmenu;
114 $result = $menu->update($user);
116 setEventMessages($langs->trans(
"RecordModifiedSuccessfully"),
null,
'mesgs');
125 header(
"Location: ".DOL_URL_ROOT.
"/admin/menus/index.php?menu_handler=".$menu_handler);
128 header(
"Location: ".DOL_URL_ROOT.
"/admin/menus/index.php?menu_handler=".$menu_handler);
133 if ($action ==
'add') {
135 header(
"Location: ".DOL_URL_ROOT.
"/admin/menus/index.php?menu_handler=".$menu_handler);
141 if (
GETPOST(
'menuId',
'alphanohtml', 3) && !is_numeric(
GETPOST(
'menuId',
'alphanohtml', 3))) {
142 $tmp = explode(
'&',
GETPOST(
'menuId',
'alphanohtml', 3));
143 foreach ($tmp as $s) {
144 if (preg_match(
'/fk_mainmenu=/', $s)) {
145 $mainmenu = preg_replace(
'/fk_mainmenu=/',
'', $s);
147 if (preg_match(
'/fk_leftmenu=/', $s)) {
148 $leftmenu = preg_replace(
'/fk_leftmenu=/',
'', $s);
153 $langs->load(
"errors");
156 if (!$error && !
GETPOST(
'menu_handler')) {
157 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"MenuHandler")),
null,
'errors');
161 if (!$error && !
GETPOST(
'type')) {
162 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Type")),
null,
'errors');
166 if (!$error && !
GETPOST(
'url')) {
167 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"URL")),
null,
'errors');
171 if (!$error && !
GETPOST(
'titre')) {
172 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Title")),
null,
'errors');
176 if (!$error &&
GETPOST(
'menuId',
'alphanohtml', 3) &&
GETPOST(
'type') ==
'top') {
177 setEventMessages($langs->trans(
"ErrorTopMenuMustHaveAParentWithId0"),
null,
'errors');
181 if (!$error && !
GETPOST(
'menuId',
'alphanohtml', 3) &&
GETPOST(
'type') ==
'left') {
182 setEventMessages($langs->trans(
"ErrorLeftMenuMustHaveAParentId"),
null,
'errors');
189 $menu->menu_handler = preg_replace(
'/_menu$/',
'',
GETPOST(
'menu_handler',
'aZ09'));
190 $menu->type = (string)
GETPOST(
'type',
'alphanohtml');
191 $menu->title = (string)
GETPOST(
'titre',
'alphanohtml');
192 $menu->url = (string)
GETPOST(
'url',
'alphanohtml');
193 $menu->langs = (string)
GETPOST(
'langs',
'alphanohtml');
194 $menu->position = (int)
GETPOST(
'position',
'int');
195 $menu->enabled = (string)
GETPOST(
'enabled',
'alphanohtml');
196 $menu->perms = (string)
GETPOST(
'perms',
'alphanohtml');
197 $menu->target = (string)
GETPOST(
'target',
'alphanohtml');
198 $menu->user = (string)
GETPOST(
'user',
'alphanohtml');
199 $menu->mainmenu = (string)
GETPOST(
'propertymainmenu',
'alphanohtml');
200 if (is_numeric(
GETPOST(
'menuId',
'alphanohtml', 3))) {
201 $menu->fk_menu = (int)
GETPOST(
'menuId',
'alphanohtml', 3);
203 if (
GETPOST(
'type',
'alphanohtml') ==
'top') {
208 $menu->fk_mainmenu = $mainmenu;
209 $menu->fk_leftmenu = $leftmenu;
212 $result = $menu->create($user);
214 header(
"Location: ".DOL_URL_ROOT.
"/admin/menus/index.php?menu_handler=".
GETPOST(
'menu_handler',
'aZ09'));
235 if ($action ==
'create') {
236 print
'<script type="text/javascript">
237 jQuery(document).ready(function() {
238 function init_topleft()
240 if (jQuery("#topleft").val() == \'top\')
242 jQuery("#menuId").prop("disabled", true);
243 jQuery("#menuId").val(\'\');
244 jQuery("#propertymainmenu").removeAttr("disabled");
245 jQuery("#propertymainmenu").val(\'\');
247 if (jQuery("#topleft").val() == \'left\')
249 jQuery("#menuId").removeAttr("disabled");
250 jQuery("#propertymainmenu").prop("disabled", true);
254 jQuery("#topleft").click(function() {
262 print
'<form action="'.DOL_URL_ROOT.
'/admin/menus/edit.php?action=add&token='.
newToken().
'&menuId='.
GETPOST(
'menuId',
'int').
'" method="post" name="formmenucreate">';
263 print
'<input type="hidden" name="token" value="'.newToken().
'">';
267 print
'<table class="border centpercent">';
270 $parent_rowid =
GETPOST(
'menuId',
'int');
271 $parent_mainmenu =
'';
272 $parent_leftmenu =
'';
276 if (
GETPOST(
'menuId',
'int')) {
277 $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');
278 $res = $db->query($sql);
280 while ($menu = $db->fetch_array($res)) {
281 $parent_rowid = $menu[
'rowid'];
282 $parent_mainmenu = $menu[
'mainmenu'];
283 $parent_leftmenu = $menu[
'leftmenu'];
284 $parent_langs = $menu[
'langs'];
285 $parent_level = $menu[
'level'];
291 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MenuHandler').
'</td>';
293 $formadmin->select_menu_families($menu_handler.(preg_match(
'/_menu/', $menu_handler) ?
'' :
'_menu'),
'menu_handler', array_merge($dirstandard, $dirsmartphone));
295 print
'<td>'.$langs->trans(
'DetailMenuHandler').
'</td></tr>';
298 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'MenuForUsers').
'</td>';
299 print
'<td><select class="flat" name="user" id="menuuser">';
300 print
'<option value="2" selected>'.$langs->trans(
"AllMenus").
'</option>';
301 print
'<option value="0">'.$langs->trans(
'Internal').
'</option>';
302 print
'<option value="1">'.$langs->trans(
'External').
'</option>';
306 print
'<td>'.$langs->trans(
'DetailUser').
'</td></tr>';
309 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Position').
'</td><td>';
311 print $langs->trans(
'Left');
312 print
'<input type="hidden" name="type" value="left">';
314 print
'<select name="type" class="flat" id="topleft">';
315 print
'<option value=""> </option>';
316 print
'<option value="top"'.(GETPOST(
"type") ==
'top' ?
' selected' :
'').
'>'.$langs->trans(
'Top').
'</option>';
317 print
'<option value="left"'.(GETPOST(
"type") ==
'left' ?
' selected' :
'').
'>'.$langs->trans(
'Left').
'</option>';
321 print
'</td><td>'.$langs->trans(
'DetailType').
'</td></tr>';
324 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MainMenuCode').
'</td>';
325 print
'<td><input type="text" class="minwidth300" id="propertymainmenu" name="propertymainmenu" value="'.(GETPOSTISSET(
"propertymainmenu") ?
GETPOST(
"propertymainmenu",
'alphanohtml') :
'').
'"></td>';
327 print $langs->trans(
"Example").
': mytopmenukey';
331 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MenuIdParent').
'</td>';
333 print
'<td>'.$parent_rowid.
'<input type="hidden" name="menuId" value="'.$parent_rowid.
'"></td>';
335 print
'<td><input type="text" class="minwidth300" id="menuId" name="menuId" value="'.(GETPOSTISSET(
"menuId") ?
GETPOST(
"menuId",
'int') :
'').
'"></td>';
337 print
'<td>'.$langs->trans(
'DetailMenuIdParent');
338 print
', '.$langs->trans(
"Example").
': fk_mainmenu=abc&fk_leftmenu=def';
342 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Title').
'</td>';
343 print
'<td><input type="text" class="minwidth300" name="titre" value="'.dol_escape_htmltag(
GETPOST(
"titre",
'alphanohtml')).
'"></td><td>'.$langs->trans(
'DetailTitre').
'</td></tr>';
346 print
'<tr><td class="fieldrequired">'.$langs->trans(
'URL').
'</td>';
347 print
'<td><input type="text" class="minwidth500" name="url" value="'.GETPOST(
"url",
'alphanohtml').
'"></td><td>'.$langs->trans(
'DetailUrl').
'</td></tr>';
350 print
'<tr><td>'.$langs->trans(
'LangFile').
'</td>';
351 print
'<td><input type="text" class="minwidth300" name="langs" value="'.$parent_langs.
'"></td><td>'.$langs->trans(
'DetailLangs').
'</td></tr>';
354 print
'<tr><td>'.$langs->trans(
'Position').
'</td>';
355 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>';
358 print
'<tr><td>'.$langs->trans(
'Enabled').
'</td>';
359 print
'<td><input type="text" class="minwidth500" name="enabled" value="'.(GETPOSTISSET(
'enabled') ?
GETPOST(
"enabled",
'alphanohtml') :
'1').
'"></td><td>'.$langs->trans(
'DetailEnabled').
'</td></tr>';
362 print
'<tr><td>'.$langs->trans(
'Rights').
'</td>';
363 print
'<td><input type="text" class="minwidth500" name="perms" value="'.(GETPOSTISSET(
'perms') ?
GETPOST(
'perms',
'alphanohtml') :
'1').
'"></td><td>'.$langs->trans(
'DetailRight').
'</td></tr>';
366 print
'<tr><td>'.$langs->trans(
'Target').
'</td><td><select class="flat" name="target" id="target">';
367 print
'<option value=""'.(isset($menu->target) && $menu->target ==
"" ?
' selected' :
'').
'> </option>';
368 print
'<option value="_blank"'.(isset($menu->target) && $menu->target ==
"_blank" ?
' selected' :
'').
'>'.$langs->trans(
'_blank').
'</option>';
371 print
'</td></td><td>'.$langs->trans(
'DetailTarget').
'</td></tr>';
377 print
$form->buttonsSaveCancel();
380 } elseif ($action ==
'edit') {
384 print
'<form action="./edit.php?action=update" method="POST" name="formmenuedit">';
385 print
'<input type="hidden" name="token" value="'.newToken().
'">';
386 print
'<input type="hidden" name="handler_origine" value="'.$menu_handler.
'">';
387 print
'<input type="hidden" name="menuId" value="'.GETPOST(
'menuId',
'int').
'">';
391 print
'<table class="border centpercent">';
394 $result = $menu->fetch(
GETPOST(
'menuId',
'int'));
398 print
'<tr><td>'.$langs->trans(
'Id').
'</td><td>'.$menu->id.
'</td><td>'.$langs->trans(
'DetailId').
'</td></tr>';
401 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>';
404 if ($menu->menu_handler ==
'all') {
405 $handler = $langs->trans(
'AllMenus');
407 $handler = $menu->menu_handler;
409 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MenuHandler').
'</td><td>'.$handler.
'</td><td>'.$langs->trans(
'DetailMenuHandler').
'</td></tr>';
412 print
'<tr><td class="nowrap fieldrequired">'.$langs->trans(
'MenuForUsers').
'</td><td>';
413 print
'<select class="flat" name="user" id="menuuser">';
414 print
'<option value="2"'.($menu->user == 2 ?
' selected' :
'').
'>'.$langs->trans(
"AllMenus").
'</option>';
415 print
'<option value="0"'.($menu->user == 0 ?
' selected' :
'').
'>'.$langs->trans(
'Internal').
'</option>';
416 print
'<option value="1"'.($menu->user == 1 ?
' selected' :
'').
'>'.$langs->trans(
'External').
'</option>';
419 print
'</td><td>'.$langs->trans(
'DetailUser').
'</td></tr>';
422 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Position').
'</td>';
423 print
'<td>'.$langs->trans(ucfirst($menu->type)).
'</td><td>'.$langs->trans(
'DetailType').
'</td></tr>';
426 if ($menu->type ==
'top') {
427 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MainMenuCode').
'</td>';
434 print
'<td><input type="text" class="minwidth300" id="propertymainmenu" name="propertymainmenu" value="'.(GETPOST(
"propertymainmenu",
'alphanohtml') ?
GETPOST(
"propertymainmenu",
'alphanohtml') : $menu->mainmenu).
'"></td>';
437 print $langs->trans(
"Example").
': mytopmenukey';
442 print
'<tr><td class="fieldrequired">'.$langs->trans(
'MenuIdParent');
444 $valtouse = $menu->fk_menu;
445 if ($menu->fk_mainmenu) {
446 $valtouse =
'fk_mainmenu='.$menu->fk_mainmenu;
448 if ($menu->fk_leftmenu) {
449 $valtouse .=
'&fk_leftmenu='.$menu->fk_leftmenu;
451 print
'<td><input type="text" name="menuIdParent" value="'.$valtouse.
'" class="minwidth300"></td>';
452 print
'<td>'.$langs->trans(
'DetailMenuIdParent');
453 print
', <span class="opacitymedium">'.$langs->trans(
"Example").
': fk_mainmenu=abc&fk_leftmenu=def</span>';
460 print
'<tr><td class="fieldrequired">'.$langs->trans(
'Title').
'</td>';
461 print
'<td><input type="text" class="minwidth300" name="titre" value="'.dol_escape_htmltag($menu->title).
'"></td><td>'.$langs->trans(
'DetailTitre').
'</td></tr>';
464 print
'<tr><td class="fieldrequired">'.$langs->trans(
'URL').
'</td>';
465 print
'<td><input type="text" class="quatrevingtpercent" name="url" value="'.$menu->url.
'"></td><td>'.$langs->trans(
'DetailUrl').
'</td></tr>';
468 print
'<tr><td>'.$langs->trans(
'LangFile').
'</td>';
469 print
'<td><input type="text" class="minwidth300" name="langs" value="'.dol_escape_htmltag($menu->langs).
'"></td><td>'.$langs->trans(
'DetailLangs').
'</td></tr>';
472 print
'<tr><td>'.$langs->trans(
'Position').
'</td>';
473 print
'<td><input type="text" class="minwidth100" name="position" value="'.$menu->position.
'"></td><td>'.$langs->trans(
'DetailPosition').
'</td></tr>';
476 print
'<tr><td>'.$langs->trans(
'Enabled').
'</td>';
477 print
'<td><input type="text" class="minwidth500" name="enabled" value="'.dol_escape_htmltag($menu->enabled).
'"></td><td>'.$langs->trans(
'DetailEnabled');
478 if (!empty($menu->enabled)) {
479 print
' <span class="opacitymedium">('.$langs->trans(
"ConditionIsCurrently").
':</span> '.
yn(
dol_eval($menu->enabled, 1, 1,
'1')).
')';
484 print
'<tr><td>'.$langs->trans(
'Rights').
'</td>';
485 print
'<td><input type="text" class="minwidth500" name="perms" value="'.dol_escape_htmltag($menu->perms).
'"></td><td>'.$langs->trans(
'DetailRight');
486 if (!empty($menu->perms)) {
487 print
' <span class="opacitymedium">('.$langs->trans(
"ConditionIsCurrently").
':</span> '.
yn(
dol_eval($menu->perms, 1, 1,
'1')).
')';
492 print
'<tr><td>'.$langs->trans(
'Target').
'</td><td><select class="flat" id="target" name="target">';
493 print
'<option value=""'.($menu->target ==
"" ?
' selected' :
'').
'> </option>';
494 print
'<option value="_blank"'.($menu->target ==
"_blank" ?
' selected' :
'').
'>'.$langs->trans(
'_blank').
'</option>';
497 print
'</td><td>'.$langs->trans(
'DetailTarget').
'</td></tr>';
503 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.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.