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