box_dolibarr_state_board.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. /**
  21. * \file htdocs/core/boxes/box_dolibarr_state_board.php
  22. * \ingroup
  23. * \brief Module Dolibarr state base
  24. */
  25. include_once DOL_DOCUMENT_ROOT . '/core/boxes/modules_boxes.php';
  26. include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
  27. /**
  28. * Class to manage the box to show last thirdparties
  29. */
  30. class box_dolibarr_state_board extends ModeleBoxes
  31. {
  32. public $boxcode = "dolibarrstatebox";
  33. public $boximg = "generic";
  34. public $boxlabel = "BoxDolibarrStateBoard";
  35. public $depends = array("user");
  36. /**
  37. * @var DoliDB Database handler.
  38. */
  39. public $db;
  40. public $enabled = 1;
  41. public $info_box_head = array();
  42. public $info_box_contents = array();
  43. /**
  44. * Constructor
  45. *
  46. * @param DoliDB $db Database handler
  47. * @param string $param More parameters
  48. */
  49. public function __construct($db, $param = '')
  50. {
  51. global $conf, $user;
  52. $this->db = $db;
  53. }
  54. /**
  55. * Load data for box to show them later
  56. *
  57. * @param int $max Maximum number of records to load
  58. * @return void
  59. */
  60. public function loadBox($max = 5)
  61. {
  62. global $user, $langs, $conf;
  63. $langs->load("boxes");
  64. $this->max = $max;
  65. $this->info_box_head = array('text' => $langs->trans("DolibarrStateBoard"));
  66. if (empty($user->socid) && empty($conf->global->MAIN_DISABLE_GLOBAL_BOXSTATS)) {
  67. $hookmanager = new HookManager($this->db);
  68. $hookmanager->initHooks(array('index'));
  69. $object = new stdClass;
  70. $action = '';
  71. $hookmanager->executeHooks('addStatisticLine', array(), $object, $action);
  72. $boxstatItems = array();
  73. $boxstatFromHook = '';
  74. $boxstatFromHook = $hookmanager->resPrint;
  75. $boxstat = '';
  76. $keys = array(
  77. 'users',
  78. 'members',
  79. 'expensereports',
  80. 'holidays',
  81. 'customers',
  82. 'prospects',
  83. 'suppliers',
  84. 'contacts',
  85. 'products',
  86. 'services',
  87. 'projects',
  88. 'proposals',
  89. 'orders',
  90. 'invoices',
  91. 'donations',
  92. 'supplier_proposals',
  93. 'supplier_orders',
  94. 'supplier_invoices',
  95. 'contracts',
  96. 'interventions',
  97. 'ticket',
  98. 'dolresource'
  99. );
  100. $conditions = array(
  101. 'users' => $user->hasRight('user', 'user', 'lire'),
  102. 'members' => isModEnabled('adherent') && $user->rights->adherent->lire,
  103. 'customers' => isModEnabled('societe') && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS),
  104. 'prospects' => isModEnabled('societe') && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS),
  105. 'suppliers' => ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->lire)
  106. || (!empty($conf->supplier_order->enabled) && $user->rights->supplier_order->lire)
  107. || (!empty($conf->supplier_invoice->enabled) && $user->rights->supplier_invoice->lire)
  108. )
  109. && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS),
  110. 'contacts' => isModEnabled('societe') && $user->hasRight('societe', 'contact', 'lire'),
  111. 'products' => isModEnabled('product') && $user->hasRight('produit', 'lire'),
  112. 'services' => isModEnabled('service') && $user->hasRight('service', 'lire'),
  113. 'proposals' => isModEnabled('propal') && $user->hasRight('propal', 'lire'),
  114. 'orders' => isModEnabled('commande') && $user->hasRight('commande', 'lire'),
  115. 'invoices' => isModEnabled('facture') && $user->hasRight('facture', 'lire'),
  116. 'donations' => isModEnabled('don') && $user->hasRight('don', 'lire'),
  117. 'contracts' => isModEnabled('contrat') && $user->hasRight('contrat', 'lire'),
  118. 'interventions' => isModEnabled('ficheinter') && $user->hasRight('ficheinter', 'lire'),
  119. 'supplier_orders' => isModEnabled('supplier_order') && $user->rights->fournisseur->commande->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_ORDERS_STATS),
  120. 'supplier_invoices' => isModEnabled('supplier_invoice') && $user->rights->fournisseur->facture->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_INVOICES_STATS),
  121. 'supplier_proposals' => isModEnabled('supplier_proposal') && $user->rights->supplier_proposal->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_PROPOSAL_STATS),
  122. 'projects' => isModEnabled('project') && $user->hasRight('projet', 'lire'),
  123. 'expensereports' => isModEnabled('expensereport') && $user->hasRight('expensereport', 'lire'),
  124. 'holidays' => isModEnabled('holiday') && $user->hasRight('holiday', 'read'),
  125. 'ticket' => isModEnabled('ticket') && $user->hasRight('ticket', 'read'),
  126. 'dolresource' => isModEnabled('resource') && $user->hasRight('resource', 'read')
  127. );
  128. $classes = array(
  129. 'users' => 'User',
  130. 'members' => 'Adherent',
  131. 'customers' => 'Client',
  132. 'prospects' => 'Client',
  133. 'suppliers' => 'Fournisseur',
  134. 'contacts' => 'Contact',
  135. 'products' => 'Product',
  136. 'services' => 'ProductService',
  137. 'proposals' => 'Propal',
  138. 'orders' => 'Commande',
  139. 'invoices' => 'Facture',
  140. 'donations' => 'Don',
  141. 'contracts' => 'Contrat',
  142. 'interventions' => 'Fichinter',
  143. 'supplier_orders' => 'CommandeFournisseur',
  144. 'supplier_invoices' => 'FactureFournisseur',
  145. 'supplier_proposals' => 'SupplierProposal',
  146. 'projects' => 'Project',
  147. 'expensereports' => 'ExpenseReport',
  148. 'holidays' => 'Holiday',
  149. 'ticket' => 'Ticket',
  150. 'dolresource' => 'Dolresource'
  151. );
  152. $includes = array(
  153. 'users' => DOL_DOCUMENT_ROOT . "/user/class/user.class.php",
  154. 'members' => DOL_DOCUMENT_ROOT . "/adherents/class/adherent.class.php",
  155. 'customers' => DOL_DOCUMENT_ROOT . "/societe/class/client.class.php",
  156. 'prospects' => DOL_DOCUMENT_ROOT . "/societe/class/client.class.php",
  157. 'suppliers' => DOL_DOCUMENT_ROOT . "/fourn/class/fournisseur.class.php",
  158. 'contacts' => DOL_DOCUMENT_ROOT . "/contact/class/contact.class.php",
  159. 'products' => DOL_DOCUMENT_ROOT . "/product/class/product.class.php",
  160. 'services' => DOL_DOCUMENT_ROOT . "/product/class/product.class.php",
  161. 'proposals' => DOL_DOCUMENT_ROOT . "/comm/propal/class/propal.class.php",
  162. 'orders' => DOL_DOCUMENT_ROOT . "/commande/class/commande.class.php",
  163. 'invoices' => DOL_DOCUMENT_ROOT . "/compta/facture/class/facture.class.php",
  164. 'donations' => DOL_DOCUMENT_ROOT . "/don/class/don.class.php",
  165. 'contracts' => DOL_DOCUMENT_ROOT . "/contrat/class/contrat.class.php",
  166. 'interventions' => DOL_DOCUMENT_ROOT . "/fichinter/class/fichinter.class.php",
  167. 'supplier_orders' => DOL_DOCUMENT_ROOT . "/fourn/class/fournisseur.commande.class.php",
  168. 'supplier_invoices' => DOL_DOCUMENT_ROOT . "/fourn/class/fournisseur.facture.class.php",
  169. 'supplier_proposals' => DOL_DOCUMENT_ROOT . "/supplier_proposal/class/supplier_proposal.class.php",
  170. 'projects' => DOL_DOCUMENT_ROOT . "/projet/class/project.class.php",
  171. 'expensereports' => DOL_DOCUMENT_ROOT . "/expensereport/class/expensereport.class.php",
  172. 'holidays' => DOL_DOCUMENT_ROOT . "/holiday/class/holiday.class.php",
  173. 'ticket' => DOL_DOCUMENT_ROOT . "/ticket/class/ticket.class.php",
  174. 'dolresource' => DOL_DOCUMENT_ROOT . "/resource/class/dolresource.class.php"
  175. );
  176. $links = array(
  177. 'users' => DOL_URL_ROOT . '/user/list.php',
  178. 'members' => DOL_URL_ROOT . '/adherents/list.php?statut=1&mainmenu=members',
  179. 'customers' => DOL_URL_ROOT . '/societe/list.php?type=c&mainmenu=companies',
  180. 'prospects' => DOL_URL_ROOT . '/societe/list.php?type=p&mainmenu=companies',
  181. 'suppliers' => DOL_URL_ROOT . '/societe/list.php?type=f&mainmenu=companies',
  182. 'contacts' => DOL_URL_ROOT . '/contact/list.php?mainmenu=companies',
  183. 'products' => DOL_URL_ROOT . '/product/list.php?type=0&mainmenu=products',
  184. 'services' => DOL_URL_ROOT . '/product/list.php?type=1&mainmenu=products',
  185. 'proposals' => DOL_URL_ROOT . '/comm/propal/list.php?mainmenu=commercial&leftmenu=propals',
  186. 'orders' => DOL_URL_ROOT . '/commande/list.php?mainmenu=commercial&leftmenu=orders',
  187. 'invoices' => DOL_URL_ROOT . '/compta/facture/list.php?mainmenu=billing&leftmenu=customers_bills',
  188. 'donations' => DOL_URL_ROOT . '/don/list.php?leftmenu=donations',
  189. 'contracts' => DOL_URL_ROOT . '/contrat/list.php?mainmenu=commercial&leftmenu=contracts',
  190. 'interventions' => DOL_URL_ROOT . '/fichinter/list.php?mainmenu=commercial&leftmenu=ficheinter',
  191. 'supplier_orders' => DOL_URL_ROOT . '/fourn/commande/list.php?mainmenu=commercial&leftmenu=orders_suppliers',
  192. 'supplier_invoices' => DOL_URL_ROOT . '/fourn/facture/list.php?mainmenu=billing&leftmenu=suppliers_bills',
  193. 'supplier_proposals' => DOL_URL_ROOT . '/supplier_proposal/list.php?mainmenu=commercial&leftmenu=',
  194. 'projects' => DOL_URL_ROOT . '/projet/list.php?mainmenu=project',
  195. 'expensereports' => DOL_URL_ROOT . '/expensereport/list.php?mainmenu=hrm&leftmenu=expensereport',
  196. 'holidays' => DOL_URL_ROOT . '/holiday/list.php?mainmenu=hrm&leftmenu=holiday',
  197. 'ticket' => DOL_URL_ROOT . '/ticket/list.php?leftmenu=ticket',
  198. 'dolresource' => DOL_URL_ROOT . '/resource/list.php?mainmenu=agenda',
  199. );
  200. $titres = array(
  201. 'users' => "Users",
  202. 'members' => "Members",
  203. 'customers' => "ThirdPartyCustomersStats",
  204. 'prospects' => "ThirdPartyProspectsStats",
  205. 'suppliers' => "Suppliers",
  206. 'contacts' => "Contacts",
  207. 'products' => "Products",
  208. 'services' => "Services",
  209. 'proposals' => "CommercialProposalsShort",
  210. 'orders' => "CustomersOrders",
  211. 'invoices' => "BillsCustomers",
  212. 'donations' => "Donations",
  213. 'contracts' => "Contracts",
  214. 'interventions' => "Interventions",
  215. 'supplier_orders' => "SuppliersOrders",
  216. 'supplier_invoices' => "SuppliersInvoices",
  217. 'supplier_proposals' => "SupplierProposalShort",
  218. 'projects' => "Projects",
  219. 'expensereports' => "ExpenseReports",
  220. 'holidays' => "Holidays",
  221. 'ticket' => "Ticket",
  222. 'dolresource' => "Resources",
  223. );
  224. $langfile = array(
  225. 'customers' => "companies",
  226. 'contacts' => "companies",
  227. 'services' => "products",
  228. 'proposals' => "propal",
  229. 'invoices' => "bills",
  230. 'supplier_orders' => "orders",
  231. 'supplier_invoices' => "bills",
  232. 'supplier_proposals' => 'supplier_proposal',
  233. 'expensereports' => "trips",
  234. 'holidays' => "holiday",
  235. );
  236. $boardloaded = array();
  237. foreach ($keys as $val) {
  238. if ($conditions[$val]) {
  239. $boxstatItem = '';
  240. $class = $classes[$val];
  241. // Search in cache if load_state_board is already realized
  242. $classkeyforcache = $class;
  243. if ($classkeyforcache == 'ProductService') {
  244. $classkeyforcache = 'Product'; // ProductService use same load_state_board than Product
  245. }
  246. if (!isset($boardloaded[$classkeyforcache]) || !is_object($boardloaded[$classkeyforcache])) {
  247. include_once $includes[$val]; // Loading a class cost around 1Mb
  248. $board = new $class($this->db);
  249. $board->load_state_board();
  250. $boardloaded[$class] = $board;
  251. } else {
  252. $board = $boardloaded[$classkeyforcache];
  253. }
  254. $langs->load(empty($langfile[$val]) ? $val : $langfile[$val]);
  255. $text = $langs->trans($titres[$val]);
  256. $boxstatItem .= '<a href="' . $links[$val] . '" class="boxstatsindicator thumbstat nobold nounderline">';
  257. $boxstatItem .= '<div class="boxstats">';
  258. $boxstatItem .= '<span class="boxstatstext" title="' . dol_escape_htmltag($text) . '">' . $text . '</span><br>';
  259. $boxstatItem .= '<span class="boxstatsindicator">' . img_object("", $board->picto, 'class="inline-block"') . ' ' . (!empty($board->nb[$val]) ? $board->nb[$val] : 0) . '</span>';
  260. $boxstatItem .= '</div>';
  261. $boxstatItem .= '</a>';
  262. $boxstatItems[$val] = $boxstatItem;
  263. }
  264. }
  265. if (!empty($boxstatFromHook) || !empty($boxstatItems)) {
  266. $boxstat .= $boxstatFromHook;
  267. if (is_array($boxstatItems) && count($boxstatItems) > 0) {
  268. $boxstat .= implode('', $boxstatItems);
  269. }
  270. $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>';
  271. $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>';
  272. $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>';
  273. $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>';
  274. $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>';
  275. $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>';
  276. $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>';
  277. $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>';
  278. $this->info_box_contents[0][0] = array(
  279. 'tr' => 'class="nohover"',
  280. 'td' => '',
  281. 'textnoformat' => $boxstat
  282. );
  283. }
  284. } else {
  285. $this->info_box_contents[0][0] = array(
  286. 'td' => '',
  287. 'text' => $langs->trans("ReadPermissionNotAllowed")
  288. );
  289. }
  290. }
  291. /**
  292. * Method to show box
  293. *
  294. * @param array $head Array with properties of box title
  295. * @param array $contents Array with properties of box lines
  296. * @param int $nooutput No print, only return string
  297. * @return string
  298. */
  299. public function showBox($head = null, $contents = null, $nooutput = 0)
  300. {
  301. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  302. }
  303. }