dolibarr 22.0.5
box_dolibarr_state_board.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2015-2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024 Charlene Benke <charlene@patas-monkey.com>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29include_once DOL_DOCUMENT_ROOT . '/core/boxes/modules_boxes.php';
30
31
36{
37 public $boxcode = "dolibarrstatebox";
38 public $boximg = "generic";
39 public $boxlabel = "BoxDolibarrStateBoard";
40 public $depends = array("user");
41
42 public $enabled = 1;
43
50 public function __construct($db, $param = '')
51 {
52 $this->db = $db;
53 }
54
61 public function loadBox($max = 5)
62 {
63 global $user, $langs;
64 $langs->load("boxes");
65
66 $this->max = $max;
67 $this->info_box_head = array('text' => $langs->trans("DolibarrStateBoard"));
68
69 if (empty($user->socid) && !getDolGlobalString('MAIN_DISABLE_GLOBAL_BOXSTATS')) {
70 $hookmanager = new HookManager($this->db);
71 $hookmanager->initHooks(array('index'));
72 $object = new stdClass();
73 $action = '';
74 $parameters = array();
75 $hookmanager->executeHooks('addStatisticLine', $parameters, $object, $action);
76 $boxstatItems = array();
77 $boxstatFromHook = '';
78 $boxstatFromHook = $hookmanager->resPrint;
79 $boxstat = '';
80
81 $keys = array(
82 'users',
83 'members',
84 'expensereports',
85 'holidays',
86 'customers',
87 'prospects',
88 'suppliers',
89 'contacts',
90 'products',
91 'services',
92 'projects',
93 'proposals',
94 'orders',
95 'invoices',
96 'donations',
97 'supplier_proposals',
98 'supplier_orders',
99 'supplier_invoices',
100 'contracts',
101 'interventions',
102 'ticket',
103 'knowledgebase',
104 'dolresource'
105 );
106 $conditions = array(
107 'users' => $user->hasRight('user', 'user', 'lire'),
108 'members' => isModEnabled('member') && $user->hasRight('adherent', 'lire'),
109 'customers' => isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS_STATS'),
110 'prospects' => isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS_STATS'),
111 'suppliers' => (
112 (isModEnabled("fournisseur") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight('fournisseur', 'lire'))
113 || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire'))
114 || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))
115 )
116 && !getDolGlobalString('SOCIETE_DISABLE_SUPPLIERS_STATS'),
117 'contacts' => isModEnabled('societe') && $user->hasRight('societe', 'contact', 'lire'),
118 'products' => isModEnabled('product') && $user->hasRight('product', 'read'),
119 'services' => isModEnabled('service') && $user->hasRight('service', 'read'),
120 'proposals' => isModEnabled('propal') && $user->hasRight('propal', 'read'),
121 'orders' => isModEnabled('order') && $user->hasRight('commande', 'lire'),
122 'invoices' => isModEnabled('invoice') && $user->hasRight('facture', 'lire'),
123 'donations' => isModEnabled('don') && $user->hasRight('don', 'lire'),
124 'contracts' => isModEnabled('contract') && $user->hasRight('contrat', 'lire'),
125 'interventions' => isModEnabled('intervention') && $user->hasRight('ficheinter', 'lire'),
126 'supplier_orders' => isModEnabled('supplier_order') && $user->hasRight('fournisseur', 'commande', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_SUPPLIERS_ORDERS_STATS'),
127 'supplier_invoices' => isModEnabled('supplier_invoice') && $user->hasRight('fournisseur', 'facture', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_SUPPLIERS_INVOICES_STATS'),
128 'supplier_proposals' => isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_SUPPLIERS_PROPOSAL_STATS'),
129 'projects' => isModEnabled('project') && $user->hasRight('projet', 'lire'),
130 'expensereports' => isModEnabled('expensereport') && $user->hasRight('expensereport', 'lire'),
131 'holidays' => isModEnabled('holiday') && $user->hasRight('holiday', 'read'),
132 'ticket' => isModEnabled('ticket') && $user->hasRight('ticket', 'read'),
133 'knowledgebase' => isModEnabled('knowledgemanagement') && $user->hasRight('knowledgemanagement', 'knowledgerecord', 'read'),
134 'dolresource' => isModEnabled('resource') && $user->hasRight('resource', 'read')
135 );
136 $classes = array(
137 'users' => 'User',
138 'members' => 'Adherent',
139 'customers' => 'Client',
140 'prospects' => 'Client',
141 'suppliers' => 'Fournisseur',
142 'contacts' => 'Contact',
143 'products' => 'Product',
144 'services' => 'ProductService',
145 'proposals' => 'Propal',
146 'orders' => 'Commande',
147 'invoices' => 'Facture',
148 'donations' => 'Don',
149 'contracts' => 'Contrat',
150 'interventions' => 'Fichinter',
151 'supplier_orders' => 'CommandeFournisseur',
152 'supplier_invoices' => 'FactureFournisseur',
153 'supplier_proposals' => 'SupplierProposal',
154 'projects' => 'Project',
155 'expensereports' => 'ExpenseReport',
156 'holidays' => 'Holiday',
157 'ticket' => 'Ticket',
158 'knowledgebase' => 'KnowledgeRecord',
159 'dolresource' => 'Dolresource'
160 );
161 $includes = array(
162 'users' => DOL_DOCUMENT_ROOT . "/user/class/user.class.php",
163 'members' => DOL_DOCUMENT_ROOT . "/adherents/class/adherent.class.php",
164 'customers' => DOL_DOCUMENT_ROOT . "/societe/class/client.class.php",
165 'prospects' => DOL_DOCUMENT_ROOT . "/societe/class/client.class.php",
166 'suppliers' => DOL_DOCUMENT_ROOT . "/fourn/class/fournisseur.class.php",
167 'contacts' => DOL_DOCUMENT_ROOT . "/contact/class/contact.class.php",
168 'products' => DOL_DOCUMENT_ROOT . "/product/class/product.class.php",
169 'services' => DOL_DOCUMENT_ROOT . "/product/class/product.class.php",
170 'proposals' => DOL_DOCUMENT_ROOT . "/comm/propal/class/propal.class.php",
171 'orders' => DOL_DOCUMENT_ROOT . "/commande/class/commande.class.php",
172 'invoices' => DOL_DOCUMENT_ROOT . "/compta/facture/class/facture.class.php",
173 'donations' => DOL_DOCUMENT_ROOT . "/don/class/don.class.php",
174 'contracts' => DOL_DOCUMENT_ROOT . "/contrat/class/contrat.class.php",
175 'interventions' => DOL_DOCUMENT_ROOT . "/fichinter/class/fichinter.class.php",
176 'supplier_orders' => DOL_DOCUMENT_ROOT . "/fourn/class/fournisseur.commande.class.php",
177 'supplier_invoices' => DOL_DOCUMENT_ROOT . "/fourn/class/fournisseur.facture.class.php",
178 'supplier_proposals' => DOL_DOCUMENT_ROOT . "/supplier_proposal/class/supplier_proposal.class.php",
179 'projects' => DOL_DOCUMENT_ROOT . "/projet/class/project.class.php",
180 'expensereports' => DOL_DOCUMENT_ROOT . "/expensereport/class/expensereport.class.php",
181 'holidays' => DOL_DOCUMENT_ROOT . "/holiday/class/holiday.class.php",
182 'ticket' => DOL_DOCUMENT_ROOT . "/ticket/class/ticket.class.php",
183 'knowledgebase' => DOL_DOCUMENT_ROOT . "/knowledgemanagement/class/knowledgerecord.class.php",
184 'dolresource' => DOL_DOCUMENT_ROOT . "/resource/class/dolresource.class.php"
185 );
186 $links = array(
187 'users' => DOL_URL_ROOT . '/user/list.php',
188 'members' => DOL_URL_ROOT . '/adherents/list.php?statut=1&mainmenu=members',
189 'customers' => DOL_URL_ROOT . '/societe/list.php?type=c&mainmenu=companies',
190 'prospects' => DOL_URL_ROOT . '/societe/list.php?type=p&mainmenu=companies',
191 'suppliers' => DOL_URL_ROOT . '/societe/list.php?type=f&mainmenu=companies',
192 'contacts' => DOL_URL_ROOT . '/contact/list.php?mainmenu=companies',
193 'products' => DOL_URL_ROOT . '/product/list.php?type=0&mainmenu=products',
194 'services' => DOL_URL_ROOT . '/product/list.php?type=1&mainmenu=products',
195 'proposals' => DOL_URL_ROOT . '/comm/propal/list.php?mainmenu=commercial&leftmenu=propals',
196 'orders' => DOL_URL_ROOT . '/commande/list.php?mainmenu=commercial&leftmenu=orders',
197 'invoices' => DOL_URL_ROOT . '/compta/facture/list.php?mainmenu=billing&leftmenu=customers_bills',
198 'donations' => DOL_URL_ROOT . '/don/list.php?leftmenu=donations',
199 'contracts' => DOL_URL_ROOT . '/contrat/list.php?mainmenu=commercial&leftmenu=contracts',
200 'interventions' => DOL_URL_ROOT . '/fichinter/list.php?mainmenu=commercial&leftmenu=ficheinter',
201 'supplier_orders' => DOL_URL_ROOT . '/fourn/commande/list.php?mainmenu=commercial&leftmenu=orders_suppliers',
202 'supplier_invoices' => DOL_URL_ROOT . '/fourn/facture/list.php?mainmenu=billing&leftmenu=suppliers_bills',
203 'supplier_proposals' => DOL_URL_ROOT . '/supplier_proposal/list.php?mainmenu=commercial&leftmenu=',
204 'projects' => DOL_URL_ROOT . '/projet/list.php?mainmenu=project',
205 'expensereports' => DOL_URL_ROOT . '/expensereport/list.php?mainmenu=hrm&leftmenu=expensereport',
206 'holidays' => DOL_URL_ROOT . '/holiday/list.php?mainmenu=hrm&leftmenu=holiday',
207 'ticket' => DOL_URL_ROOT . '/ticket/list.php?leftmenu=ticket',
208 'knowledgebase' => DOL_URL_ROOT . '/knowledgemanagement/knowledgerecord_list.php?leftmenu=knowledgebase',
209 'dolresource' => DOL_URL_ROOT . '/resource/list.php?mainmenu=agenda',
210 );
211 $titres = array(
212 'users' => "Users",
213 'members' => "Members",
214 'customers' => "ThirdPartyCustomersStats",
215 'prospects' => "ThirdPartyProspectsStats",
216 'suppliers' => "Suppliers",
217 'contacts' => "Contacts",
218 'products' => "Products",
219 'services' => "Services",
220 'proposals' => "CommercialProposalsShort",
221 'orders' => "CustomersOrders",
222 'invoices' => "BillsCustomers",
223 'donations' => "Donations",
224 'contracts' => "Contracts",
225 'interventions' => "Interventions",
226 'supplier_orders' => "SuppliersOrders",
227 'supplier_invoices' => "SuppliersInvoices",
228 'supplier_proposals' => "SupplierProposalShort",
229 'projects' => "Projects",
230 'expensereports' => "ExpenseReports",
231 'holidays' => "Holidays",
232 'ticket' => "Ticket",
233 'knowledgebase' => "KnowledgeRecord",
234 'dolresource' => "Resources",
235 );
236 $langfile = array(
237 'customers' => "companies",
238 'contacts' => "companies",
239 'services' => "products",
240 'proposals' => "propal",
241 'invoices' => "bills",
242 'supplier_orders' => "orders",
243 'supplier_invoices' => "bills",
244 'supplier_proposals' => 'supplier_proposal',
245 'expensereports' => "trips",
246 'holidays' => "holiday",
247 );
248 $boardloaded = array();
249
250 foreach ($keys as $val) {
251 if ($conditions[$val]) {
252 $boxstatItem = '';
253 $class = $classes[$val];
254 // Search in cache if load_state_board is already realized
255 $classkeyforcache = $class;
256 if ($classkeyforcache == 'ProductService') {
257 $classkeyforcache = 'Product'; // ProductService use same load_state_board than Product
258 }
259
260 if (!isset($boardloaded[$classkeyforcache]) || !is_object($boardloaded[$classkeyforcache])) {
261 include_once $includes[$val]; // Loading a class cost around 1Mb
262
263 $board = new $class($this->db);
264 if (method_exists($board, 'load_state_board')) {
265 // @phan-suppress-next-line PhanUndeclaredMethod (Legacy, not present in core).
266 $board->load_state_board();
267 } elseif (method_exists($board, 'loadStateBoard')) { // @phpstan-ignore-line
268 $board->loadStateBoard();
269 } else {
270 $board = -1;
271 }
272 $boardloaded[$class] = $board;
273 } else {
274 $board = $boardloaded[$classkeyforcache];
275 }
276
277 $langs->load(empty($langfile[$val]) ? $val : $langfile[$val]);
278
279 $text = $langs->trans($titres[$val]);
280 $boxstatItem .= '<a href="' . $links[$val] . '" class="boxstatsindicator thumbstat nobold nounderline">';
281 $boxstatItem .= '<div class="boxstats">';
282 $boxstatItem .= '<span class="boxstatstext" title="' . dol_escape_htmltag($text) . '">' . $text . '</span><br>';
283 $boxstatItem .= '<span class="boxstatsindicator">' . img_object("", $board->picto, 'class="inline-block"') . ' ' . (!empty($board->nb[$val]) ? $board->nb[$val] : 0) . '</span>';
284 $boxstatItem .= '</div>';
285 $boxstatItem .= '</a>';
286
287 $boxstatItems[$val] = $boxstatItem;
288 }
289 }
290
291 if (!empty($boxstatFromHook) || !empty($boxstatItems)) {
292 $boxstat .= $boxstatFromHook;
293
294 if (!empty($boxstatItems)) {
295 $boxstat .= implode('', $boxstatItems);
296 }
297
298 $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>';
299 $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>';
300 $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>';
301 $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>';
302 $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>';
303 $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>';
304 $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>';
305 $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>';
306
307 $this->info_box_contents[0][0] = array(
308 'tr' => 'class="nohover"',
309 'td' => 'class="tdwidgetstate center"',
310 'textnoformat' => $boxstat
311 );
312 }
313 } else {
314 $this->info_box_contents[0][0] = array(
315 'td' => '',
316 'text' => $langs->trans("ReadPermissionNotAllowed")
317 );
318 }
319 }
320
321
322
323
332 public function showBox($head = null, $contents = null, $nooutput = 0)
333 {
334 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
335 }
336}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
Class to manage hooks.
Class ModeleBoxes.
Class to manage the box to show last thirdparties.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
loadBox($max=5)
Load data for box to show them later.
__construct($db, $param='')
Constructor.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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...