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