dolibarr 24.0.0-beta
menu.tpl.php
1<?php
2/* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024 sebastien schaffhauser <sebastien@webmaster67.fr>
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 // menu orders
46 if (isModEnabled('order') && getDolGlobalInt('WEBPORTAL_ORDER_LIST_ACCESS')) {
47 $navMenu['order_list'] = array(
48 'id' => 'order_list',
49 'rank' => 20,
50 'url' => $context->getControllerUrl('orderlist'),
51 'name' => $langs->trans('WebPortalOrderListMenu'),
52 'group' => 'administrative' // group identifier for the group if necessary
53 );
54 }
55 // menu invoices
56 if (isModEnabled('invoice') && getDolGlobalInt('WEBPORTAL_INVOICE_LIST_ACCESS')) {
57 $navMenu['invoice_list'] = array(
58 'id' => 'invoice_list',
59 'rank' => 30,
60 'url' => $context->getControllerUrl('invoicelist'),
61 'name' => $langs->trans('WebPortalInvoiceListMenu'),
62 'group' => 'administrative' // group identifier for the group if necessary
63 );
64 }
65 // menu interventions
66 if (isModEnabled('intervention') && getDolGlobalInt('WEBPORTAL_FICHEINTER_LIST_ACCESS')) {
67 $navMenu['ficheinter_list'] = array(
68 'id' => 'ficheinter_list',
69 'rank' => 35,
70 'url' => $context->getControllerUrl('ficheinterlist'),
71 'name' => $langs->trans('WebPortalFicheinterListMenu'),
72 'group' => 'administrative'
73 );
74 }
75 // menu tickets
76 if (isModEnabled('ticket') && getDolGlobalInt('WEBPORTAL_TICKET_LIST_ACCESS')) {
77 $navMenu['ticket_list'] = array(
78 'id' => 'ticket_list',
79 'rank' => 36,
80 'url' => $context->getControllerUrl('ticketlist'),
81 'name' => $langs->trans('WebPortalTicketListMenu'),
82 'group' => 'administrative'
83 );
84 }
85 // menu documents (GED)
86 if (getDolGlobalInt('WEBPORTAL_DOCUMENT_LIST_ACCESS')) {
87 $navMenu['document_list'] = array(
88 'id' => 'document_list',
89 'rank' => 40,
90 'url' => $context->getControllerUrl('documentlist'),
91 'name' => $langs->trans('MyDocuments'), // CORRIGÉ : Clé de traduction correcte
92 'group' => 'administrative' // group identifier for the group if necessary
93 );
94 }
95 // Shared documents menu
96 if (getDolGlobalInt('WEBPORTAL_SHARED_DOCUMENT_ACCESS')) {
97 $navMenu['shared_documents'] = array(
98 'id' => 'shared_documents',
99 'rank' => 50,
100 'url' => $context->getControllerUrl('shareddocuments'),
101 'name' => $langs->trans('SharedDocuments'),
102 'group' => 'administrative'
103 );
104 }
105 // menu member
106 $cardAccess = getDolGlobalString('WEBPORTAL_MEMBER_CARD_ACCESS');
107 if (isModEnabled('member')
108 && in_array($cardAccess, array('visible', 'edit'))
109 && $context->logged_member
110 && $context->logged_member->id > 0
111 ) {
112 $navMenu['member_card'] = array(
113 'id' => 'member_card',
114 'rank' => 110,
115 'url' => $context->getControllerUrl('membercard'),
116 'name' => $langs->trans('WebPortalMemberCardMenu'),
117 'group' => 'administrative' // group identifier for the group if necessary
118 );
119 }
120 // menu partnership
121 $cardAccess = getDolGlobalString('WEBPORTAL_PARTNERSHIP_CARD_ACCESS');
122 if (isModEnabled('partnership')
123 && in_array($cardAccess, array('visible', 'edit'))
124 && $context->logged_partnership
125 && $context->logged_partnership->id > 0
126 ) {
127 $navMenu['partnership_card'] = array(
128 'id' => 'partnership_card',
129 'rank' => 120,
130 'url' => $context->getControllerUrl('partnershipcard'),
131 'name' => $langs->trans('WebPortalPartnershipCardMenu'),
132 'group' => 'administrative' // group identifier for the group if necessary
133 );
134 }
135
136 // menu user
137 if ($context->logged_thirdparty) {
138 $navUserMenu['user'] = array(
139 'id' => 'user_account',
140 'rank' => 99998,
141 'url' => false,
142 'name' => '<img class="top-nav-icon user-account" src="' . WebPortalTheme::getIconImagesUrl() . 'user.svg" aria-hidden="true" /> <span class="user-account-name">'.$context->logged_thirdparty->getFullName($langs).'</span>',
143 );
144 }
145
146
147 // menu user with logout
148 $navUserMenu['user_logout'] = array(
149 'id' => 'user_logout',
150 'rank' => 99999,
151 'url' => $context->getControllerUrl() . 'logout.php',
152 'name' => '<img class="top-nav-icon log-out-img" src="'.WebPortalTheme::getIconImagesUrl() . 'logout.svg" title="'.dol_escape_htmltag($langs->trans('Logout')).'" />',
153 );
154}
155// GROUP MENU
156$navGroupMenu = array(
157 'administrative' => array(
158 'id' => 'administrative',
159 'rank' => -1, // negative value for undefined, it will be set by the min item rank for this group
160 'url' => '',
161 'name' => $langs->trans('WebPortalGroupMenuAdmin'),
162 'children' => array()
163 ),
164 'technical' => array(
165 'id' => 'technical',
166 'rank' => -1, // negative value for undefined, it will be set by the min item rank for this group
167 'url' => '',
168 'name' => $langs->trans('WebPortalGroupMenuTechnical'),
169 'children' => array()
170 ),
171);
172
173$parameters = array(
174 'controller' => $context->controller,
175 'Tmenu' => & $navMenu,
176 'TUserMenu' => & $navUserMenu,
177 'TGroupMenu' => & $navGroupMenu,
178 'maxTopMenu' => & $maxTopMenu
179);
180
181$reshook = $hookmanager->executeHooks('PrintTopMenu', $parameters, $context, $context->action); // Note that $action and $object may have been modified by hook
182if ($reshook < 0) {
183 $context->setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
184}
185
186if (empty($reshook)) {
187 if (!empty($hookmanager->resArray)) {
188 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
189 $navMenu = array_replace($navMenu, $hookmanager->resArray);
190 }
191
192 if (!empty($navMenu)) {
193 // Sorting
194 uasort($navMenu, 'menuSortInv');
195
196 if (!empty($maxTopMenu) && $maxTopMenu < count($navMenu)) {
197 // AFFECT MENU ITEMS TO GROUPS
198 foreach ($navMenu as $menuId => $menuItem) {
199 // assign items to group menu
200 if (!empty($menuItem['group']) && !empty($navGroupMenu[$menuItem['group']])) {
201 $goupId = $menuItem['group'];
202
203 // set item to group
204 $navGroupMenu[$goupId]['children'][$menuId] = $menuItem;
205
206 // apply rank
207 if (!empty($navGroupMenu[$goupId]['rank']) && $navGroupMenu[$goupId]['rank'] > 0) {
208 // minimum rank of group determine rank of group
209 $navGroupMenu[$goupId]['rank'] = min(abs($navGroupMenu[$goupId]['rank']), abs($menuItem['rank'])); // @phpstan-ignore-line
210 }
211 }
212 }
213 // add grouped items to this menu
214 foreach ($navGroupMenu as $groupId => $groupItem) {
215 // If group have more than 1 item, group is valid
216 if (!empty($groupItem['children']) && count($groupItem['children']) > 1) {
217 // ajout du group au menu
218 $navMenu[$groupId] = $groupItem;
219
220 // remove child item of the group of the menu
221 foreach ($groupItem['children'] as $menuId => $menuItem) {
222 if (isset($navMenu[$menuId])) {
223 unset($navMenu[$menuId]);
224 }
225 }
226 }
227 }
228
229 // final sorting
230 uasort($navMenu, 'menuSortInv');
231 }
232 }
233}
234?>
235<nav class="primary-top-nav container-fluid">
236 <ul class="menu-entries-alt">
237 <?php
238 // show menu
239 print '<li data-deep="0" class="nav-item">';
240 print ' <details class="main-nav-dropdown dropdown">';
241 print ' <summary><img class="top-nav-icon menu-icon-dropdown" src="' . WebPortalTheme::getIconImagesUrl() . 'menu.svg" alt="'.dol_escape_htmltag($langs->trans("Menu")).'" /></summary>';
242 print ' <ul >';
243 print getNav($navMenu);
244 print ' </ul>';
245 print ' </details>';
246 print '</li>';
247 ?>
248 </ul>
249
250 <ul class="brand">
251 <li class="brand">
252 <?php
253 $brandTitle = getDolGlobalString('WEBPORTAL_TITLE') ? getDolGlobalString('WEBPORTAL_TITLE') : getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
254 print '<a class="brand__logo-link" href="'.$context->getControllerUrl().'" >';
255 if (!empty($context->theme->menuLogoUrl)) {
256 print '<img class="brand__logo-img" src="' . dol_escape_htmltag($context->theme->menuLogoUrl) . '" alt="' . dol_escape_htmltag($brandTitle) . '">';
257 } else {
258 print '<span class="brand__name">' . $brandTitle . '</span>';
259 }
260 print '</a>';
261 ?>
262 </li>
263 </ul>
264 <ul class="menu-entries">
265 <?php
266 if (empty($context->doNotDisplayMenu) && empty($reshook) && !empty($navMenu)) {
267 // show menu
268 print getNav($navMenu);
269 }
270 ?>
271 </ul>
272
273 <ul class="logout">
274 <?php
275 if (empty($context->doNotDisplayMenu) && empty($reshook) && !empty($navUserMenu)) {
276 // show menu
277 uasort($navUserMenu, 'menuSortInv');
278 print getNav($navUserMenu);
279 }
280 ?>
281 </ul>
282</nav>
static getIconImagesUrl()
return current icons folder url
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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...
getNav($Tmenu)
Get nav menu.
$context
@method int call_trigger(string $triggerName, ?User $user)
Definition logout.php:42