dolibarr 23.0.3
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 documents (GED)
66 if (getDolGlobalInt('WEBPORTAL_DOCUMENT_LIST_ACCESS')) {
67 $navMenu['document_list'] = array(
68 'id' => 'document_list',
69 'rank' => 40,
70 'url' => $context->getControllerUrl('documentlist'),
71 'name' => $langs->trans('MyDocuments'), // CORRIGÉ : Clé de traduction correcte
72 'group' => 'administrative' // group identifier for the group if necessary
73 );
74 }
75 // Shared documents menu
76 if (getDolGlobalInt('WEBPORTAL_SHARED_DOCUMENT_ACCESS')) {
77 $navMenu['shared_documents'] = array(
78 'id' => 'shared_documents',
79 'rank' => 50,
80 'url' => $context->getControllerUrl('shareddocuments'),
81 'name' => $langs->trans('SharedDocuments'),
82 'group' => 'administrative'
83 );
84 }
85 // menu member
86 $cardAccess = getDolGlobalString('WEBPORTAL_MEMBER_CARD_ACCESS');
87 if (isModEnabled('member')
88 && in_array($cardAccess, array('visible', 'edit'))
89 && $context->logged_member
90 && $context->logged_member->id > 0
91 ) {
92 $navMenu['member_card'] = array(
93 'id' => 'member_card',
94 'rank' => 110,
95 'url' => $context->getControllerUrl('membercard'),
96 'name' => $langs->trans('WebPortalMemberCardMenu'),
97 'group' => 'administrative' // group identifier for the group if necessary
98 );
99 }
100 // menu partnership
101 $cardAccess = getDolGlobalString('WEBPORTAL_PARTNERSHIP_CARD_ACCESS');
102 if (isModEnabled('partnership')
103 && in_array($cardAccess, array('visible', 'edit'))
104 && $context->logged_partnership
105 && $context->logged_partnership->id > 0
106 ) {
107 $navMenu['partnership_card'] = array(
108 'id' => 'partnership_card',
109 'rank' => 120,
110 'url' => $context->getControllerUrl('partnershipcard'),
111 'name' => $langs->trans('WebPortalPartnershipCardMenu'),
112 'group' => 'administrative' // group identifier for the group if necessary
113 );
114 }
115
116 // menu user
117 if ($context->logged_thirdparty) {
118 $navUserMenu['user'] = array(
119 'id' => 'user_account',
120 'rank' => 99998,
121 'url' => false,
122 'name' => '<img class="top-nav-icon user-account" src="' . WebPortalTheme::getIconImagesUrl() . 'user.svg" aria-hidden="true" /> '.$context->logged_thirdparty->getFullName($langs),
123 );
124 }
125
126
127 // menu user with logout
128 $navUserMenu['user_logout'] = array(
129 'id' => 'user_logout',
130 'rank' => 99999,
131 'url' => $context->getControllerUrl() . 'logout.php',
132 'name' => '<img class="top-nav-icon log-out-img" src="'.WebPortalTheme::getIconImagesUrl() . 'logout.svg" title="'.dol_escape_htmltag($langs->trans('Logout')).'" />',
133 );
134}
135// GROUP MENU
136$navGroupMenu = array(
137 'administrative' => array(
138 'id' => 'administrative',
139 'rank' => -1, // negative value for undefined, it will be set by the min item rank for this group
140 'url' => '',
141 'name' => $langs->trans('WebPortalGroupMenuAdmin'),
142 'children' => array()
143 ),
144 'technical' => array(
145 'id' => 'technical',
146 'rank' => -1, // negative value for undefined, it will be set by the min item rank for this group
147 'url' => '',
148 'name' => $langs->trans('WebPortalGroupMenuTechnical'),
149 'children' => array()
150 ),
151);
152
153$parameters = array(
154 'controller' => $context->controller,
155 'Tmenu' => & $navMenu,
156 'TUserMenu' => & $navUserMenu,
157 'TGroupMenu' => & $navGroupMenu,
158 'maxTopMenu' => & $maxTopMenu
159);
160
161$reshook = $hookmanager->executeHooks('PrintTopMenu', $parameters, $context, $context->action); // Note that $action and $object may have been modified by hook
162if ($reshook < 0) {
163 $context->setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
164}
165
166if (empty($reshook)) {
167 if (!empty($hookmanager->resArray)) {
168 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
169 $navMenu = array_replace($navMenu, $hookmanager->resArray);
170 }
171
172 if (!empty($navMenu)) {
173 // Sorting
174 uasort($navMenu, 'menuSortInv');
175
176 if (!empty($maxTopMenu) && $maxTopMenu < count($navMenu)) {
177 // AFFECT MENU ITEMS TO GROUPS
178 foreach ($navMenu as $menuId => $menuItem) {
179 // assign items to group menu
180 if (!empty($menuItem['group']) && !empty($navGroupMenu[$menuItem['group']])) {
181 $goupId = $menuItem['group'];
182
183 // set item to group
184 $navGroupMenu[$goupId]['children'][$menuId] = $menuItem;
185
186 // apply rank
187 if (!empty($navGroupMenu[$goupId]['rank']) && $navGroupMenu[$goupId]['rank'] > 0) {
188 // minimum rank of group determine rank of group
189 $navGroupMenu[$goupId]['rank'] = min(abs($navGroupMenu[$goupId]['rank']), abs($menuItem['rank'])); // @phpstan-ignore-line
190 }
191 }
192 }
193 // add grouped items to this menu
194 foreach ($navGroupMenu as $groupId => $groupItem) {
195 // If group have more than 1 item, group is valid
196 if (!empty($groupItem['children']) && count($groupItem['children']) > 1) {
197 // ajout du group au menu
198 $navMenu[$groupId] = $groupItem;
199
200 // suppression des items enfant du group du menu
201 foreach ($groupItem['children'] as $menuId => $menuItem) {
202 if (isset($navMenu[$menuId])) {
203 unset($navMenu[$menuId]);
204 }
205 }
206 }
207 }
208
209 // final sorting
210 uasort($navMenu, 'menuSortInv');
211 }
212 }
213}
214?>
215<nav class="primary-top-nav container-fluid">
216 <ul class="brand">
217 <li class="brand">
218 <?php
219 $brandTitle = getDolGlobalString('WEBPORTAL_TITLE') ? getDolGlobalString('WEBPORTAL_TITLE') : getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
220 print '<a class="brand__logo-link" href="'.$context->getControllerUrl().'" >';
221 if (!empty($context->theme->menuLogoUrl)) {
222 print '<img class="brand__logo-img" src="' . dol_escape_htmltag($context->theme->menuLogoUrl) . '" alt="' . dol_escape_htmltag($brandTitle) . '">';
223 } else {
224 print '<span class="brand__name">' . $brandTitle . '</span>';
225 }
226 print '</a>';
227 ?>
228 </li>
229 </ul>
230 <ul class="menu-entries">
231 <?php
232 if (empty($context->doNotDisplayMenu) && empty($reshook) && !empty($navMenu)) {
233 // show menu
234 print getNav($navMenu);
235 }
236 ?>
237 </ul>
238 <ul class="menu-entries-alt">
239 <?php
240 // show menu
241 print '<li data-deep="0" class="--item-propal-list nav-item "><a href="'.$context->getControllerUrl().'">'.$langs->trans("Menu").'...</a></li>';
242 ?>
243 </ul>
244 <ul class="logout">
245 <?php
246 if (empty($context->doNotDisplayMenu) && empty($reshook) && !empty($navUserMenu)) {
247 // show menu
248 uasort($navUserMenu, 'menuSortInv');
249 print getNav($navUserMenu);
250 }
251 ?>
252 </ul>
253</nav>
static getIconImagesUrl()
return current icons folder url
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