dolibarr 25.0.0-alpha
home.tpl.php
1<!-- file home.tpl.php -->
2<?php
3/* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2025 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2026 charlene Benke <charlene@patas-monkey.com>
6 */
7// Protection to avoid direct call of template
8if (empty($context) || !is_object($context)) {
9 print "Error, template page can't be called as URL";
10 exit(1);
11}
12'@phan-var-force Context $context';
20$navMenu = array();
22$navGroupMenu = array();
23'@phan-var-force array<string,array<string,mixed>> $navGroupMenu';
25$navUserMenu = array();
27$maxTopMenu = 0;
28
29if ($context->userIsLog()) {
30 // menu propal
31 if (isModEnabled('propal') && getDolGlobalInt('WEBPORTAL_PROPAL_LIST_ACCESS')) {
32 $navMenu['propal_list'] = array(
33 'id' => 'propal_list',
34 'rank' => 10,
35 'url' => $context->getControllerUrl('propallist'),
36 'name' => $langs->trans('WebPortalPropalListMenu'),
37 'group' => 'administrative' // group identifier for the group if necessary
38 );
39 }
40 // menu orders
41 if (isModEnabled('order') && getDolGlobalInt('WEBPORTAL_ORDER_LIST_ACCESS')) {
42 $navMenu['order_list'] = array(
43 'id' => 'order_list',
44 'rank' => 20,
45 'url' => $context->getControllerUrl('orderlist'),
46 'name' => $langs->trans('WebPortalOrderListMenu'),
47 'group' => 'administrative' // group identifier for the group if necessary
48 );
49 }
50 // menu invoices
51 if (isModEnabled('invoice') && getDolGlobalInt('WEBPORTAL_INVOICE_LIST_ACCESS')) {
52 $navMenu['invoice_list'] = array(
53 'id' => 'invoice_list',
54 'rank' => 30,
55 'url' => $context->getControllerUrl('invoicelist'),
56 'name' => $langs->trans('WebPortalInvoiceListMenu'),
57 'group' => 'administrative' // group identifier for the group if necessary
58 );
59 }
60
61 // menu documents (GED)
62 if (getDolGlobalInt('WEBPORTAL_DOCUMENT_LIST_ACCESS')) {
63 $navMenu['document_list'] = array(
64 'id' => 'document_list',
65 'rank' => 40,
66 'url' => $context->getControllerUrl('documentlist'),
67 'name' => $langs->trans('MyDocuments'),
68 'group' => 'administrative' // group identifier for the group if necessary
69 );
70 }
71 // Shared documents menu
72 if (getDolGlobalInt('WEBPORTAL_SHARED_DOCUMENT_ACCESS')) {
73 $navMenu['shared_documents'] = array(
74 'id' => 'shared_documents',
75 'rank' => 50,
76 'url' => $context->getControllerUrl('shareddocuments'),
77 'name' => $langs->trans('SharedDocuments'),
78 'group' => 'administrative'
79 );
80 }
81 // menu member
82 $cardAccess = getDolGlobalString('WEBPORTAL_MEMBER_CARD_ACCESS');
83 if (isModEnabled('member')
84 && in_array($cardAccess, array('visible', 'edit'))
85 && $context->logged_member
86 && $context->logged_member->id > 0
87 ) {
88 $navMenu['member_card'] = array(
89 'id' => 'member_card',
90 'rank' => 110,
91 'url' => $context->getControllerUrl('membercard'),
92 'name' => $langs->trans('WebPortalMemberCardMenu'),
93 'group' => 'administrative' // group identifier for the group if necessary
94 );
95 }
96 // menu partnership
97 $cardAccess = getDolGlobalString('WEBPORTAL_PARTNERSHIP_CARD_ACCESS');
98 if (isModEnabled('partnership')
99 && in_array($cardAccess, array('visible', 'edit'))
100 && $context->logged_partnership
101 && $context->logged_partnership->id > 0
102 ) {
103 $navMenu['partnership_card'] = array(
104 'id' => 'partnership_card',
105 'rank' => 120,
106 'url' => $context->getControllerUrl('partnershipcard'),
107 'name' => $langs->trans('WebPortalPartnershipCardMenu'),
108 'group' => 'administrative' // group identifier for the group if necessary
109 );
110 }
111}
112
113$parameters = array(
114 'controller' => $context->controller,
115 'Tmenu' => & $navMenu,
116 'TUserMenu' => & $navUserMenu,
117 'TGroupMenu' => & $navGroupMenu,
118 'maxTopMenu' => & $maxTopMenu
119);
120
121$reshook = $hookmanager->executeHooks('PrintTopMenu', $parameters, $context, $context->action); // Note that $action and $object may have been modified by hook
122if ($reshook < 0) {
123 $context->setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
124}
125if (empty($reshook)) {
126 if (!empty($hookmanager->resArray)) {
127 // @phan-suppress-next-line PhanPluginSuspiciousParamOrderInternal
128 $navMenu = array_replace($navMenu, $hookmanager->resArray);
129 }
130
131 if (!empty($navMenu)) {
132 // Sorting
133 uasort($navMenu, 'menuSortInv');
134
135 if (!empty($maxTopMenu) && $maxTopMenu < count($navMenu)) {
136 // AFFECT MENU ITEMS TO GROUPS
137 foreach ($navMenu as $menuId => $menuItem) {
138 // assign items to group menu
139 if (!empty($menuItem['group']) && !empty($navGroupMenu[$menuItem['group']])) {
140 $goupId = $menuItem['group'];
141
142 // set item to group
143 $navGroupMenu[$goupId]['children'][$menuId] = $menuItem;
144
145 // apply rank
146 if (!empty($navGroupMenu[$goupId]['rank']) && $navGroupMenu[$goupId]['rank'] > 0) {
147 // minimum rank of group determine rank of group
148 $navGroupMenu[$goupId]['rank'] = min(abs($navGroupMenu[$goupId]['rank']), abs($menuItem['rank'])); // @phpstan-ignore-line
149 }
150 }
151 }
152 // add grouped items to this menu
153 foreach ($navGroupMenu as $groupId => $groupItem) {
154 // If group have more than 1 item, group is valid
155 if (!empty($groupItem['children']) && count($groupItem['children']) > 1) {
156 // add the group to the menu
157 $navMenu[$groupId] = $groupItem;
158
159 // suppress items children of the group from the menu
160 foreach ($groupItem['children'] as $menuId => $menuItem) {
161 if (isset($navMenu[$menuId])) {
162 unset($navMenu[$menuId]);
163 }
164 }
165 }
166 }
167
168 // final sorting
169 uasort($navMenu, 'menuSortInv');
170 }
171 }
172}
173print '<main class="container">';
174print '<div class="home-links-grid grid">';
175foreach ($navMenu as $menuId => $menuItem) {
176 print '<article class="home-links-card --' . $menuId . '">';
177 print '<div class="home-links-card__icon" ></div>';
178 print '<a class="home-links-card__link" href="' . $menuItem['url'] . '" title="' . $menuItem['name'] . '">' . $menuItem['name'] . '</a>';
179 print '</article>';
180}
181print '</div></main>';
$context
@method int call_trigger(string $triggerName, ?User $user)
Definition command.php:209
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.