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