dolibarr 20.0.0
menu.tpl.php
1<!-- file menu.tpl.php -->
2<?php
3// Protection to avoid direct call of template
4if (empty($context) || !is_object($context)) {
5 print "Error, template page can't be called as URL";
6 exit(1);
7}
8
9global $conf, $hookmanager, $langs;
10
11$navMenu = $navGroupMenu = $navUserMenu = array();
12
13$maxTopMenu = 0;
14
15if ($context->userIsLog()) {
16 // menu propal
17 if (isModEnabled('propal') && getDolGlobalInt('WEBPORTAL_PROPAL_LIST_ACCESS')) {
18 $navMenu['propal_list'] = array(
19 'id' => 'propal_list',
20 'rank' => 10,
21 'url' => $context->getControllerUrl('propallist'),
22 'name' => $langs->trans('WebPortalPropalListMenu'),
23 'group' => 'administrative' // group identifier for the group if necessary
24 );
25 }
26
27 // menu orders
28 if (isModEnabled('order') && getDolGlobalInt('WEBPORTAL_ORDER_LIST_ACCESS')) {
29 $navMenu['order_list'] = array(
30 'id' => 'order_list',
31 'rank' => 20,
32 'url' => $context->getControllerUrl('orderlist'),
33 'name' => $langs->trans('WebPortalOrderListMenu'),
34 'group' => 'administrative' // group identifier for the group if necessary
35 );
36 }
37
38 // menu invoices
39 if (isModEnabled('invoice') && getDolGlobalInt('WEBPORTAL_INVOICE_LIST_ACCESS')) {
40 $navMenu['invoice_list'] = array(
41 'id' => 'invoice_list',
42 'rank' => 30,
43 'url' => $context->getControllerUrl('invoicelist'),
44 'name' => $langs->trans('WebPortalInvoiceListMenu'),
45 'group' => 'administrative' // group identifier for the group if necessary
46 );
47 }
48
49 // menu member
50 $cardAccess = getDolGlobalString('WEBPORTAL_MEMBER_CARD_ACCESS');
51 if (isModEnabled('member')
52 && in_array($cardAccess, array('visible', 'edit'))
53 && $context->logged_member
54 && $context->logged_member->id > 0
55 ) {
56 $navMenu['member_card'] = array(
57 'id' => 'member_card',
58 'rank' => 110,
59 'url' => $context->getControllerUrl('membercard'),
60 'name' => $langs->trans('WebPortalMemberCardMenu'),
61 'group' => 'administrative' // group identifier for the group if necessary
62 );
63 }
64
65 // menu partnership
66 $cardAccess = getDolGlobalString('WEBPORTAL_PARTNERSHIP_CARD_ACCESS');
67 if (isModEnabled('partnership')
68 && in_array($cardAccess, array('visible', 'edit'))
69 && $context->logged_partnership
70 && $context->logged_partnership->id > 0
71 ) {
72 $navMenu['partnership_card'] = array(
73 'id' => 'partnership_card',
74 'rank' => 120,
75 'url' => $context->getControllerUrl('partnershipcard'),
76 'name' => $langs->trans('WebPortalPartnershipCardMenu'),
77 'group' => 'administrative' // group identifier for the group if necessary
78 );
79 }
80
81 // menu user with logout
82 $navUserMenu['user_logout'] = array(
83 'id' => 'user_logout',
84 'rank' => 99999,
85 'url' => $context->getControllerUrl() . 'logout.php',
86 'name' => img_picto($langs->trans('Logout'), 'logout', 'class="pictofixedwidth"'),
87 );
88}
89
90// GROUP MENU
91$navGroupMenu = array(
92 'administrative' => array(
93 'id' => 'administrative',
94 'rank' => -1, // negative value for undefined, it will be set by the min item rank for this group
95 'url' => '',
96 'name' => $langs->trans('WebPortalGroupMenuAdmin'),
97 'children' => array()
98 ),
99 'technical' => array(
100 'id' => 'technical',
101 'rank' => -1, // negative value for undefined, it will be set by the min item rank for this group
102 'url' => '',
103 'name' => $langs->trans('WebPortalGroupMenuTechnical'),
104 'children' => array()
105 ),
106);
107
108$parameters = array(
109 'controller' => $context->controller,
110 'Tmenu' => & $navMenu,
111 'TGroupMenu' => & $navGroupMenu,
112 'maxTopMenu' => & $maxTopMenu
113);
114
115$reshook = $hookmanager->executeHooks('PrintTopMenu', $parameters, $context, $context->action); // Note that $action and $object may have been modified by hook
116if ($reshook < 0) {
117 $context->setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
118}
119
120if (empty($reshook)) {
121 if (!empty($hookmanager->resArray)) {
122 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
123 $navMenu = array_replace($navMenu, $hookmanager->resArray);
124 }
125
126 if (!empty($navMenu)) {
127 // Sorting
128 uasort($navMenu, 'menuSortInv');
129
130 if (!empty($maxTopMenu) && $maxTopMenu < count($navMenu)) {
131 // AFFECT MENU ITEMS TO GROUPS
132 foreach ($navMenu as $menuId => $menuItem) {
133 // assign items to group menu
134 if (!empty($menuItem['group']) && !empty($navGroupMenu[$menuItem['group']])) {
135 $goupId = $menuItem['group'];
136
137 // set item to group
138 $navGroupMenu[$goupId]['children'][$menuId] = $menuItem;
139
140 // apply rank
141 if (!empty($navGroupMenu[$goupId]['rank']) && $navGroupMenu[$goupId]['rank'] > 0) {
142 // minimum rank of group determine rank of group
143 $navGroupMenu[$goupId]['rank'] = min(abs($navGroupMenu[$goupId]['rank']), abs($menuItem['rank']));
144 }
145 }
146 }
147
148 // add grouped items to this menu
149 foreach ($navGroupMenu as $groupId => $groupItem) {
150 // If group have more than 1 item, group is valid
151 if (!empty($groupItem['children']) && count($groupItem['children']) > 1) {
152 // ajout du group au menu
153 $navMenu[$groupId] = $groupItem;
154
155 // suppression des items enfant du group du menu
156 foreach ($groupItem['children'] as $menuId => $menuItem) {
157 if (isset($navMenu[$menuId])) {
158 unset($navMenu[$menuId]);
159 }
160 }
161 }
162 }
163
164 // final sorting
165 uasort($navMenu, 'menuSortInv');
166 }
167 }
168}
169?>
170<nav class="primary-top-nav container-fluid">
171 <ul class="brand">
172 <li class="brand">
173 <?php
174 $brandTitle = getDolGlobalString('WEBPORTAL_TITLE') ? getDolGlobalString('WEBPORTAL_TITLE') : getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
175 print '<a class="brand__logo-link" href="'.$context->getControllerUrl().'" >';
176 if (!empty($context->theme->menuLogoUrl)) {
177 print '<img class="brand__logo-img" src="' . dol_escape_htmltag($context->theme->menuLogoUrl) . '" alt="' . dol_escape_htmltag($brandTitle) . '">';
178 } else {
179 print '<span class="brand__name">' . $brandTitle . '</span>';
180 }
181 print '</a>';
182 ?>
183 </li>
184 </ul>
185 <ul class="menu-entries">
186 <?php
187 if (empty($context->doNotDisplayMenu) && empty($reshook) && !empty($navMenu)) {
188 // show menu
189 print getNav($navMenu);
190 }
191 ?>
192 </ul>
193 <ul class="menu-entries-alt">
194 <?php
195 // show menu
196 print '<li data-deep="0" class="--item-propal-list nav-item "><a href="'.$context->getControllerUrl().'">'.$langs->trans("Menu").'...</a></li>';
197 ?>
198 </ul>
199 <ul class="logout">
200 <?php
201 if (empty($context->doNotDisplayMenu) && empty($reshook) && !empty($navUserMenu)) {
202 // show menu
203 uasort($navUserMenu, 'menuSortInv');
204 print getNav($navUserMenu);
205 }
206 ?>
207 </ul>
208</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 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.