dolibarr  16.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-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 
27 include_once DOL_DOCUMENT_ROOT . '/core/boxes/modules_boxes.php';
28 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
29 
30 
35 {
36  public $boxcode = "dolibarrstatebox";
37  public $boximg = "generic";
38  public $boxlabel = "BoxDolibarrStateBoard";
39  public $depends = array("user");
40 
44  public $db;
45 
46  public $enabled = 1;
47 
48  public $info_box_head = array();
49  public $info_box_contents = array();
50 
51 
58  public function __construct($db, $param = '')
59  {
60  global $conf, $user;
61 
62  $this->db = $db;
63  }
64 
71  public function loadBox($max = 5)
72  {
73  global $user, $langs, $conf;
74  $langs->load("boxes");
75 
76  $this->max = $max;
77  $this->info_box_head = array('text' => $langs->trans("DolibarrStateBoard"));
78 
79  if (empty($user->socid) && empty($conf->global->MAIN_DISABLE_GLOBAL_BOXSTATS)) {
80  $hookmanager = new HookManager($this->db);
81  $hookmanager->initHooks(array('index'));
82  $object = new stdClass;
83  $action = '';
84  $hookmanager->executeHooks('addStatisticLine', array(), $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->rights->adherent->lire,
117  'customers' => isModEnabled('societe') && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS),
118  'prospects' => isModEnabled('societe') && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS),
119  'suppliers' => ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->lire)
120  || (!empty($conf->supplier_order->enabled) && $user->rights->supplier_order->lire)
121  || (!empty($conf->supplier_invoice->enabled) && $user->rights->supplier_invoice->lire)
122  )
123  && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS),
124  'contacts' => isModEnabled('societe') && $user->hasRight('societe', 'contact', 'lire'),
125  'products' => isModEnabled('product') && $user->hasRight('produit', 'lire'),
126  'services' => isModEnabled('service') && $user->hasRight('service', 'lire'),
127  'proposals' => isModEnabled('propal') && $user->hasRight('propal', 'lire'),
128  'orders' => isModEnabled('commande') && $user->hasRight('commande', 'lire'),
129  'invoices' => isModEnabled('facture') && $user->hasRight('facture', 'lire'),
130  'donations' => isModEnabled('don') && $user->hasRight('don', 'lire'),
131  'contracts' => isModEnabled('contrat') && $user->hasRight('contrat', 'lire'),
132  'interventions' => isModEnabled('ficheinter') && $user->hasRight('ficheinter', 'lire'),
133  'supplier_orders' => isModEnabled('supplier_order') && $user->rights->fournisseur->commande->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_ORDERS_STATS),
134  'supplier_invoices' => isModEnabled('supplier_invoice') && $user->rights->fournisseur->facture->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_INVOICES_STATS),
135  'supplier_proposals' => isModEnabled('supplier_proposal') && $user->rights->supplier_proposal->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_PROPOSAL_STATS),
136  'projects' => isModEnabled('project') && $user->hasRight('projet', 'lire'),
137  'expensereports' => isModEnabled('expensereport') && $user->hasRight('expensereport', 'lire'),
138  'holidays' => isModEnabled('holiday') && $user->hasRight('holiday', 'read'),
139  'ticket' => isModEnabled('ticket') && $user->hasRight('ticket', 'read'),
140  'dolresource' => isModEnabled('resource') && $user->hasRight('resource', 'read')
141  );
142  $classes = array(
143  'users' => 'User',
144  'members' => 'Adherent',
145  'customers' => 'Client',
146  'prospects' => 'Client',
147  'suppliers' => 'Fournisseur',
148  'contacts' => 'Contact',
149  'products' => 'Product',
150  'services' => 'ProductService',
151  'proposals' => 'Propal',
152  'orders' => 'Commande',
153  'invoices' => 'Facture',
154  'donations' => 'Don',
155  'contracts' => 'Contrat',
156  'interventions' => 'Fichinter',
157  'supplier_orders' => 'CommandeFournisseur',
158  'supplier_invoices' => 'FactureFournisseur',
159  'supplier_proposals' => 'SupplierProposal',
160  'projects' => 'Project',
161  'expensereports' => 'ExpenseReport',
162  'holidays' => 'Holiday',
163  'ticket' => 'Ticket',
164  'dolresource' => 'Dolresource'
165  );
166  $includes = array(
167  'users' => DOL_DOCUMENT_ROOT . "/user/class/user.class.php",
168  'members' => DOL_DOCUMENT_ROOT . "/adherents/class/adherent.class.php",
169  'customers' => DOL_DOCUMENT_ROOT . "/societe/class/client.class.php",
170  'prospects' => DOL_DOCUMENT_ROOT . "/societe/class/client.class.php",
171  'suppliers' => DOL_DOCUMENT_ROOT . "/fourn/class/fournisseur.class.php",
172  'contacts' => DOL_DOCUMENT_ROOT . "/contact/class/contact.class.php",
173  'products' => DOL_DOCUMENT_ROOT . "/product/class/product.class.php",
174  'services' => DOL_DOCUMENT_ROOT . "/product/class/product.class.php",
175  'proposals' => DOL_DOCUMENT_ROOT . "/comm/propal/class/propal.class.php",
176  'orders' => DOL_DOCUMENT_ROOT . "/commande/class/commande.class.php",
177  'invoices' => DOL_DOCUMENT_ROOT . "/compta/facture/class/facture.class.php",
178  'donations' => DOL_DOCUMENT_ROOT . "/don/class/don.class.php",
179  'contracts' => DOL_DOCUMENT_ROOT . "/contrat/class/contrat.class.php",
180  'interventions' => DOL_DOCUMENT_ROOT . "/fichinter/class/fichinter.class.php",
181  'supplier_orders' => DOL_DOCUMENT_ROOT . "/fourn/class/fournisseur.commande.class.php",
182  'supplier_invoices' => DOL_DOCUMENT_ROOT . "/fourn/class/fournisseur.facture.class.php",
183  'supplier_proposals' => DOL_DOCUMENT_ROOT . "/supplier_proposal/class/supplier_proposal.class.php",
184  'projects' => DOL_DOCUMENT_ROOT . "/projet/class/project.class.php",
185  'expensereports' => DOL_DOCUMENT_ROOT . "/expensereport/class/expensereport.class.php",
186  'holidays' => DOL_DOCUMENT_ROOT . "/holiday/class/holiday.class.php",
187  'ticket' => DOL_DOCUMENT_ROOT . "/ticket/class/ticket.class.php",
188  'dolresource' => DOL_DOCUMENT_ROOT . "/resource/class/dolresource.class.php"
189  );
190  $links = array(
191  'users' => DOL_URL_ROOT . '/user/list.php',
192  'members' => DOL_URL_ROOT . '/adherents/list.php?statut=1&mainmenu=members',
193  'customers' => DOL_URL_ROOT . '/societe/list.php?type=c&mainmenu=companies',
194  'prospects' => DOL_URL_ROOT . '/societe/list.php?type=p&mainmenu=companies',
195  'suppliers' => DOL_URL_ROOT . '/societe/list.php?type=f&mainmenu=companies',
196  'contacts' => DOL_URL_ROOT . '/contact/list.php?mainmenu=companies',
197  'products' => DOL_URL_ROOT . '/product/list.php?type=0&mainmenu=products',
198  'services' => DOL_URL_ROOT . '/product/list.php?type=1&mainmenu=products',
199  'proposals' => DOL_URL_ROOT . '/comm/propal/list.php?mainmenu=commercial&leftmenu=propals',
200  'orders' => DOL_URL_ROOT . '/commande/list.php?mainmenu=commercial&leftmenu=orders',
201  'invoices' => DOL_URL_ROOT . '/compta/facture/list.php?mainmenu=billing&leftmenu=customers_bills',
202  'donations' => DOL_URL_ROOT . '/don/list.php?leftmenu=donations',
203  'contracts' => DOL_URL_ROOT . '/contrat/list.php?mainmenu=commercial&leftmenu=contracts',
204  'interventions' => DOL_URL_ROOT . '/fichinter/list.php?mainmenu=commercial&leftmenu=ficheinter',
205  'supplier_orders' => DOL_URL_ROOT . '/fourn/commande/list.php?mainmenu=commercial&leftmenu=orders_suppliers',
206  'supplier_invoices' => DOL_URL_ROOT . '/fourn/facture/list.php?mainmenu=billing&leftmenu=suppliers_bills',
207  'supplier_proposals' => DOL_URL_ROOT . '/supplier_proposal/list.php?mainmenu=commercial&leftmenu=',
208  'projects' => DOL_URL_ROOT . '/projet/list.php?mainmenu=project',
209  'expensereports' => DOL_URL_ROOT . '/expensereport/list.php?mainmenu=hrm&leftmenu=expensereport',
210  'holidays' => DOL_URL_ROOT . '/holiday/list.php?mainmenu=hrm&leftmenu=holiday',
211  'ticket' => DOL_URL_ROOT . '/ticket/list.php?leftmenu=ticket',
212  'dolresource' => DOL_URL_ROOT . '/resource/list.php?mainmenu=agenda',
213  );
214  $titres = array(
215  'users' => "Users",
216  'members' => "Members",
217  'customers' => "ThirdPartyCustomersStats",
218  'prospects' => "ThirdPartyProspectsStats",
219  'suppliers' => "Suppliers",
220  'contacts' => "Contacts",
221  'products' => "Products",
222  'services' => "Services",
223  'proposals' => "CommercialProposalsShort",
224  'orders' => "CustomersOrders",
225  'invoices' => "BillsCustomers",
226  'donations' => "Donations",
227  'contracts' => "Contracts",
228  'interventions' => "Interventions",
229  'supplier_orders' => "SuppliersOrders",
230  'supplier_invoices' => "SuppliersInvoices",
231  'supplier_proposals' => "SupplierProposalShort",
232  'projects' => "Projects",
233  'expensereports' => "ExpenseReports",
234  'holidays' => "Holidays",
235  'ticket' => "Ticket",
236  'dolresource' => "Resources",
237  );
238  $langfile = array(
239  'customers' => "companies",
240  'contacts' => "companies",
241  'services' => "products",
242  'proposals' => "propal",
243  'invoices' => "bills",
244  'supplier_orders' => "orders",
245  'supplier_invoices' => "bills",
246  'supplier_proposals' => 'supplier_proposal',
247  'expensereports' => "trips",
248  'holidays' => "holiday",
249  );
250  $boardloaded = array();
251 
252  foreach ($keys as $val) {
253  if ($conditions[$val]) {
254  $boxstatItem = '';
255  $class = $classes[$val];
256  // Search in cache if load_state_board is already realized
257  $classkeyforcache = $class;
258  if ($classkeyforcache == 'ProductService') {
259  $classkeyforcache = 'Product'; // ProductService use same load_state_board than Product
260  }
261 
262  if (!isset($boardloaded[$classkeyforcache]) || !is_object($boardloaded[$classkeyforcache])) {
263  include_once $includes[$val]; // Loading a class cost around 1Mb
264 
265  $board = new $class($this->db);
266  $board->load_state_board();
267  $boardloaded[$class] = $board;
268  } else {
269  $board = $boardloaded[$classkeyforcache];
270  }
271 
272  $langs->load(empty($langfile[$val]) ? $val : $langfile[$val]);
273 
274  $text = $langs->trans($titres[$val]);
275  $boxstatItem .= '<a href="' . $links[$val] . '" class="boxstatsindicator thumbstat nobold nounderline">';
276  $boxstatItem .= '<div class="boxstats">';
277  $boxstatItem .= '<span class="boxstatstext" title="' . dol_escape_htmltag($text) . '">' . $text . '</span><br>';
278  $boxstatItem .= '<span class="boxstatsindicator">' . img_object("", $board->picto, 'class="inline-block"') . ' ' . (!empty($board->nb[$val]) ? $board->nb[$val] : 0) . '</span>';
279  $boxstatItem .= '</div>';
280  $boxstatItem .= '</a>';
281 
282  $boxstatItems[$val] = $boxstatItem;
283  }
284  }
285 
286  if (!empty($boxstatFromHook) || !empty($boxstatItems)) {
287  $boxstat .= $boxstatFromHook;
288 
289  if (is_array($boxstatItems) && count($boxstatItems) > 0) {
290  $boxstat .= implode('', $boxstatItems);
291  }
292 
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  $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 
302  $this->info_box_contents[0][0] = array(
303  'tr' => 'class="nohover"',
304  'td' => '',
305  'textnoformat' => $boxstat
306  );
307  }
308  } else {
309  $this->info_box_contents[0][0] = array(
310  'td' => '',
311  'text' => $langs->trans("ReadPermissionNotAllowed")
312  );
313  }
314  }
315 
316 
325  public function showBox($head = null, $contents = null, $nooutput = 0)
326  {
327  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
328  }
329 }
db
$conf db
API class for accounts.
Definition: inc.php:41
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
box_dolibarr_state_board\showBox
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition: box_dolibarr_state_board.php:325
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
HookManager
Class to manage hooks.
Definition: hookmanager.class.php:30
ModeleBoxes
Class ModeleBoxes.
Definition: modules_boxes.php:34
box_dolibarr_state_board\__construct
__construct($db, $param='')
Constructor.
Definition: box_dolibarr_state_board.php:58
box_dolibarr_state_board
Class to manage the box to show last thirdparties.
Definition: box_dolibarr_state_board.php:34
box_dolibarr_state_board\loadBox
loadBox($max=5)
Load data for box to show them later.
Definition: box_dolibarr_state_board.php:71