dolibarr 21.0.0-beta
menu.tpl.php
1<!-- file menu.tpl.php -->
2<?php
3/* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 * or see https://www.gnu.org/
19 */
20
21// Protection to avoid direct call of template
22if (empty($context) || !is_object($context)) {
23 print "Error, template page can't be called as URL";
24 exit(1);
25}
26'@phan-var-force Context $context';
27
28global $conf, $hookmanager, $langs;
29
30$navMenu = $navGroupMenu = $navUserMenu = array();
31
32$maxTopMenu = 0;
33
34if ($context->userIsLog()) {
35 // menu propal
36 if (isModEnabled('propal') && getDolGlobalInt('WEBPORTAL_PROPAL_LIST_ACCESS')) {
37 $navMenu['propal_list'] = array(
38 'id' => 'propal_list',
39 'rank' => 10,
40 'url' => $context->getControllerUrl('propallist'),
41 'name' => $langs->trans('WebPortalPropalListMenu'),
42 'group' => 'administrative' // group identifier for the group if necessary
43 );
44 }
45
46 // menu orders
47 if (isModEnabled('order') && getDolGlobalInt('WEBPORTAL_ORDER_LIST_ACCESS')) {
48 $navMenu['order_list'] = array(
49 'id' => 'order_list',
50 'rank' => 20,
51 'url' => $context->getControllerUrl('orderlist'),
52 'name' => $langs->trans('WebPortalOrderListMenu'),
53 'group' => 'administrative' // group identifier for the group if necessary
54 );
55 }
56
57 // menu invoices
58 if (isModEnabled('invoice') && getDolGlobalInt('WEBPORTAL_INVOICE_LIST_ACCESS')) {
59 $navMenu['invoice_list'] = array(
60 'id' => 'invoice_list',
61 'rank' => 30,
62 'url' => $context->getControllerUrl('invoicelist'),
63 'name' => $langs->trans('WebPortalInvoiceListMenu'),
64 'group' => 'administrative' // group identifier for the group if necessary
65 );
66 }
67
68 // menu member
69 $cardAccess = getDolGlobalString('WEBPORTAL_MEMBER_CARD_ACCESS');
70 if (isModEnabled('member')
71 && in_array($cardAccess, array('visible', 'edit'))
72 && $context->logged_member
73 && $context->logged_member->id > 0
74 ) {
75 $navMenu['member_card'] = array(
76 'id' => 'member_card',
77 'rank' => 110,
78 'url' => $context->getControllerUrl('membercard'),
79 'name' => $langs->trans('WebPortalMemberCardMenu'),
80 'group' => 'administrative' // group identifier for the group if necessary
81 );
82 }
83
84 // menu partnership
85 $cardAccess = getDolGlobalString('WEBPORTAL_PARTNERSHIP_CARD_ACCESS');
86 if (isModEnabled('partnership')
87 && in_array($cardAccess, array('visible', 'edit'))
88 && $context->logged_partnership
89 && $context->logged_partnership->id > 0
90 ) {
91 $navMenu['partnership_card'] = array(
92 'id' => 'partnership_card',
93 'rank' => 120,
94 'url' => $context->getControllerUrl('partnershipcard'),
95 'name' => $langs->trans('WebPortalPartnershipCardMenu'),
96 'group' => 'administrative' // group identifier for the group if necessary
97 );
98 }
99
100 // menu user with logout
101 $navUserMenu['user_logout'] = array(
102 'id' => 'user_logout',
103 'rank' => 99999,
104 'url' => $context->getControllerUrl() . 'logout.php',
105 'name' => img_picto($langs->trans('Logout'), 'logout', 'class="pictofixedwidth"'),
106 );
107}
108
109// GROUP MENU
110$navGroupMenu = array(
111 'administrative' => array(
112 'id' => 'administrative',
113 'rank' => -1, // negative value for undefined, it will be set by the min item rank for this group
114 'url' => '',
115 'name' => $langs->trans('WebPortalGroupMenuAdmin'),
116 'children' => array()
117 ),
118 'technical' => array(
119 'id' => 'technical',
120 'rank' => -1, // negative value for undefined, it will be set by the min item rank for this group
121 'url' => '',
122 'name' => $langs->trans('WebPortalGroupMenuTechnical'),
123 'children' => array()
124 ),
125);
126
127$parameters = array(
128 'controller' => $context->controller,
129 'Tmenu' => & $navMenu,
130 'TGroupMenu' => & $navGroupMenu,
131 'maxTopMenu' => & $maxTopMenu
132);
133
134$reshook = $hookmanager->executeHooks('PrintTopMenu', $parameters, $context, $context->action); // Note that $action and $object may have been modified by hook
135if ($reshook < 0) {
136 $context->setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
137}
138
139if (empty($reshook)) {
140 if (!empty($hookmanager->resArray)) {
141 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
142 $navMenu = array_replace($navMenu, $hookmanager->resArray);
143 }
144
145 if (!empty($navMenu)) {
146 // Sorting
147 uasort($navMenu, 'menuSortInv');
148
149 if (!empty($maxTopMenu) && $maxTopMenu < count($navMenu)) {
150 // AFFECT MENU ITEMS TO GROUPS
151 foreach ($navMenu as $menuId => $menuItem) {
152 // assign items to group menu
153 if (!empty($menuItem['group']) && !empty($navGroupMenu[$menuItem['group']])) {
154 $goupId = $menuItem['group'];
155
156 // set item to group
157 $navGroupMenu[$goupId]['children'][$menuId] = $menuItem;
158
159 // apply rank
160 if (!empty($navGroupMenu[$goupId]['rank']) && $navGroupMenu[$goupId]['rank'] > 0) {
161 // minimum rank of group determine rank of group
162 $navGroupMenu[$goupId]['rank'] = min(abs($navGroupMenu[$goupId]['rank']), abs($menuItem['rank'])); // @phpstan-ignore-line
163 }
164 }
165 }
166
167 // add grouped items to this menu
168 foreach ($navGroupMenu as $groupId => $groupItem) {
169 // If group have more than 1 item, group is valid
170 if (!empty($groupItem['children']) && count($groupItem['children']) > 1) {
171 // ajout du group au menu
172 $navMenu[$groupId] = $groupItem;
173
174 // suppression des items enfant du group du menu
175 foreach ($groupItem['children'] as $menuId => $menuItem) {
176 if (isset($navMenu[$menuId])) {
177 unset($navMenu[$menuId]);
178 }
179 }
180 }
181 }
182
183 // final sorting
184 uasort($navMenu, 'menuSortInv');
185 }
186 }
187}
188?>
189<nav class="primary-top-nav container-fluid">
190 <ul class="brand">
191 <li class="brand">
192 <?php
193 $brandTitle = getDolGlobalString('WEBPORTAL_TITLE') ? getDolGlobalString('WEBPORTAL_TITLE') : getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
194 print '<a class="brand__logo-link" href="'.$context->getControllerUrl().'" >';
195 if (!empty($context->theme->menuLogoUrl)) {
196 print '<img class="brand__logo-img" src="' . dol_escape_htmltag($context->theme->menuLogoUrl) . '" alt="' . dol_escape_htmltag($brandTitle) . '">';
197 } else {
198 print '<span class="brand__name">' . $brandTitle . '</span>';
199 }
200 print '</a>';
201 ?>
202 </li>
203 </ul>
204 <ul class="menu-entries">
205 <?php
206 if (empty($context->doNotDisplayMenu) && empty($reshook) && !empty($navMenu)) {
207 // show menu
208 print getNav($navMenu);
209 }
210 ?>
211 </ul>
212 <ul class="menu-entries-alt">
213 <?php
214 // show menu
215 print '<li data-deep="0" class="--item-propal-list nav-item "><a href="'.$context->getControllerUrl().'">'.$langs->trans("Menu").'...</a></li>';
216 ?>
217 </ul>
218 <ul class="logout">
219 <?php
220 if (empty($context->doNotDisplayMenu) && empty($reshook) && !empty($navUserMenu)) {
221 // show menu
222 uasort($navUserMenu, 'menuSortInv');
223 print getNav($navUserMenu);
224 }
225 ?>
226 </ul>
227</nav>
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
getNav($Tmenu)
Get nav menu.
$context
@method int call_trigger(string $triggerName, User $user)
Definition logout.php:42