index.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  7. * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
  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. /**
  23. * \file htdocs/index.php
  24. * \brief Dolibarr home page
  25. */
  26. define('CSRFCHECK_WITH_TOKEN', 1); // We force need to use a token to login when making a POST
  27. require 'main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  29. // If not defined, we select menu "home"
  30. $_GET['mainmenu'] = GETPOST('mainmenu', 'aZ09') ? GETPOST('mainmenu', 'aZ09') : 'home';
  31. $action = GETPOST('action', 'aZ09');
  32. $hookmanager->initHooks(array('index'));
  33. /*
  34. * Actions
  35. */
  36. // Check if company name is defined (first install)
  37. if (!isset($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_INFO_SOCIETE_NOM)) {
  38. header("Location: ".DOL_URL_ROOT."/admin/index.php?mainmenu=home&leftmenu=setup&mesg=setupnotcomplete");
  39. exit;
  40. }
  41. if (count($conf->modules) <= (empty($conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING) ? 1 : $conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING)) { // If only user module enabled
  42. header("Location: ".DOL_URL_ROOT."/admin/index.php?mainmenu=home&leftmenu=setup&mesg=setupnotcomplete");
  43. exit;
  44. }
  45. if (GETPOST('addbox')) { // Add box (when submit is done from a form when ajax disabled)
  46. require_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
  47. $zone = GETPOST('areacode', 'int');
  48. $userid = GETPOST('userid', 'int');
  49. $boxorder = GETPOST('boxorder', 'aZ09');
  50. $boxorder .= GETPOST('boxcombo', 'aZ09');
  51. $result = InfoBox::saveboxorder($db, $zone, $boxorder, $userid);
  52. if ($result > 0) {
  53. setEventMessages($langs->trans("BoxAdded"), null);
  54. }
  55. }
  56. /*
  57. * View
  58. */
  59. if (!isset($form) || !is_object($form)) {
  60. $form = new Form($db);
  61. }
  62. // Title
  63. $title = $langs->trans("HomeArea").' - Dolibarr '.DOL_VERSION;
  64. if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
  65. $title = $langs->trans("HomeArea").' - '.$conf->global->MAIN_APPLICATION_TITLE;
  66. }
  67. llxHeader('', $title);
  68. $resultboxes = FormOther::getBoxesArea($user, "0"); // Load $resultboxes (selectboxlist + boxactivated + boxlista + boxlistb)
  69. print load_fiche_titre('&nbsp;', $resultboxes['selectboxlist'], '', 0, '', 'titleforhome');
  70. if (!empty($conf->global->MAIN_MOTD)) {
  71. $conf->global->MAIN_MOTD = preg_replace('/<br(\s[\sa-zA-Z_="]*)?\/?>/i', '<br>', $conf->global->MAIN_MOTD);
  72. if (!empty($conf->global->MAIN_MOTD)) {
  73. $substitutionarray = getCommonSubstitutionArray($langs);
  74. complete_substitutions_array($substitutionarray, $langs);
  75. $texttoshow = make_substitutions($conf->global->MAIN_MOTD, $substitutionarray, $langs);
  76. print "\n<!-- Start of welcome text -->\n";
  77. print '<table width="100%" class="notopnoleftnoright"><tr><td>';
  78. print dol_htmlentitiesbr($texttoshow);
  79. print '</td></tr></table><br>';
  80. print "\n<!-- End of welcome text -->\n";
  81. }
  82. }
  83. /*
  84. * Show security warnings
  85. */
  86. // Security warning repertoire install existe (si utilisateur admin)
  87. if ($user->admin && empty($conf->global->MAIN_REMOVE_INSTALL_WARNING)) {
  88. $message = '';
  89. // Check if install lock file is present
  90. $lockfile = DOL_DATA_ROOT.'/install.lock';
  91. if (!empty($lockfile) && !file_exists($lockfile) && is_dir(DOL_DOCUMENT_ROOT."/install")) {
  92. $langs->load("errors");
  93. //if (! empty($message)) $message.='<br>';
  94. $message .= info_admin($langs->trans("WarningLockFileDoesNotExists", DOL_DATA_ROOT).' '.$langs->trans("WarningUntilDirRemoved", DOL_DOCUMENT_ROOT."/install"), 0, 0, '1', 'clearboth');
  95. }
  96. // Conf files must be in read only mode
  97. if (is_writable($conffile)) {
  98. $langs->load("errors");
  99. //$langs->load("other");
  100. //if (! empty($message)) $message.='<br>';
  101. $message .= info_admin($langs->transnoentities("WarningConfFileMustBeReadOnly").' '.$langs->trans("WarningUntilDirRemoved", DOL_DOCUMENT_ROOT."/install"), 0, 0, '1', 'clearboth');
  102. }
  103. if ($message) {
  104. print $message;
  105. //$message.='<br>';
  106. //print info_admin($langs->trans("WarningUntilDirRemoved",DOL_DOCUMENT_ROOT."/install"));
  107. }
  108. }
  109. /*
  110. * Dashboard Dolibarr states (statistics)
  111. * Hidden for external users
  112. */
  113. $boxstatItems = array();
  114. $boxstatFromHook = '';
  115. // Load translation files required by page
  116. $langs->loadLangs(array('commercial', 'bills', 'orders', 'contracts'));
  117. // Dolibarr Working Board with weather
  118. if (empty($conf->global->MAIN_DISABLE_GLOBAL_WORKBOARD)) {
  119. $showweather = (empty($conf->global->MAIN_DISABLE_METEO) || $conf->global->MAIN_DISABLE_METEO == 2) ? 1 : 0;
  120. //Array that contains all WorkboardResponse classes to process them
  121. $dashboardlines = array();
  122. // Do not include sections without management permission
  123. require_once DOL_DOCUMENT_ROOT.'/core/class/workboardresponse.class.php';
  124. // Number of actions to do (late)
  125. if (!empty($conf->agenda->enabled) && $user->rights->agenda->myactions->read) {
  126. include_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  127. $board = new ActionComm($db);
  128. $dashboardlines[$board->element] = $board->load_board($user);
  129. }
  130. // Number of project opened
  131. if (!empty($conf->projet->enabled) && $user->rights->projet->lire) {
  132. include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  133. $board = new Project($db);
  134. $dashboardlines[$board->element] = $board->load_board($user);
  135. }
  136. // Number of tasks to do (late)
  137. if (!empty($conf->projet->enabled) && empty($conf->global->PROJECT_HIDE_TASKS) && $user->rights->projet->lire) {
  138. include_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  139. $board = new Task($db);
  140. $dashboardlines[$board->element] = $board->load_board($user);
  141. }
  142. // Number of commercial proposals open (expired)
  143. if (!empty($conf->propal->enabled) && $user->rights->propale->lire) {
  144. include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  145. $board = new Propal($db);
  146. $dashboardlines[$board->element.'_opened'] = $board->load_board($user, "opened");
  147. // Number of commercial proposals CLOSED signed (billed)
  148. $dashboardlines[$board->element.'_signed'] = $board->load_board($user, "signed");
  149. }
  150. // Number of commercial proposals open (expired)
  151. if (!empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->lire) {
  152. include_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
  153. $board = new SupplierProposal($db);
  154. $dashboardlines[$board->element.'_opened'] = $board->load_board($user, "opened");
  155. // Number of commercial proposals CLOSED signed (billed)
  156. $dashboardlines[$board->element.'_signed'] = $board->load_board($user, "signed");
  157. }
  158. // Number of customer orders a deal
  159. if (!empty($conf->commande->enabled) && $user->rights->commande->lire) {
  160. include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  161. $board = new Commande($db);
  162. $dashboardlines[$board->element] = $board->load_board($user);
  163. }
  164. // Number of suppliers orders a deal
  165. if (!empty($conf->supplier_order->enabled) && $user->rights->fournisseur->commande->lire) {
  166. include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  167. $board = new CommandeFournisseur($db);
  168. $dashboardlines[$board->element.'_opened'] = $board->load_board($user, "opened");
  169. $dashboardlines[$board->element.'_awaiting'] = $board->load_board($user, 'awaiting');
  170. }
  171. // Number of contract / services enabled (delayed)
  172. if (!empty($conf->contrat->enabled) && $user->rights->contrat->lire) {
  173. include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  174. $board = new Contrat($db);
  175. $dashboardlines[$board->element.'_inactive'] = $board->load_board($user, "inactive");
  176. // Number of active services (expired)
  177. $dashboardlines[$board->element.'_active'] = $board->load_board($user, "active");
  178. }
  179. // Number of tickets open
  180. if (!empty($conf->ticket->enabled) && $user->rights->ticket->read) {
  181. include_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
  182. $board = new Ticket($db);
  183. $dashboardlines[$board->element.'_opened'] = $board->load_board($user, "opened");
  184. // Number of active services (expired)
  185. //$dashboardlines[$board->element.'_active'] = $board->load_board($user, "active");
  186. }
  187. // Number of invoices customers (paid)
  188. if (!empty($conf->facture->enabled) && $user->rights->facture->lire) {
  189. include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  190. $board = new Facture($db);
  191. $dashboardlines[$board->element] = $board->load_board($user);
  192. }
  193. // Number of supplier invoices (paid)
  194. if (!empty($conf->supplier_invoice->enabled) && !empty($user->rights->fournisseur->facture->lire)) {
  195. include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  196. $board = new FactureFournisseur($db);
  197. $dashboardlines[$board->element] = $board->load_board($user);
  198. }
  199. // Number of transactions to conciliate
  200. if (!empty($conf->banque->enabled) && $user->rights->banque->lire && !$user->socid) {
  201. include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  202. $board = new Account($db);
  203. $nb = $board->countAccountToReconcile(); // Get nb of account to reconciliate
  204. if ($nb > 0) {
  205. $dashboardlines[$board->element] = $board->load_board($user);
  206. }
  207. }
  208. // Number of cheque to send
  209. if (!empty($conf->banque->enabled) && $user->rights->banque->lire && !$user->socid && empty($conf->global->BANK_DISABLE_CHECK_DEPOSIT)) {
  210. include_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
  211. $board = new RemiseCheque($db);
  212. $dashboardlines[$board->element] = $board->load_board($user);
  213. }
  214. // Number of foundation members
  215. if (!empty($conf->adherent->enabled) && $user->rights->adherent->lire && !$user->socid) {
  216. include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  217. $board = new Adherent($db);
  218. $dashboardlines[$board->element.'_shift'] = $board->load_board($user, 'shift');
  219. $dashboardlines[$board->element.'_expired'] = $board->load_board($user, 'expired');
  220. }
  221. // Number of expense reports to approve
  222. if (!empty($conf->expensereport->enabled) && $user->rights->expensereport->approve) {
  223. include_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  224. $board = new ExpenseReport($db);
  225. $dashboardlines[$board->element.'_toapprove'] = $board->load_board($user, 'toapprove');
  226. }
  227. // Number of expense reports to pay
  228. if (!empty($conf->expensereport->enabled) && $user->rights->expensereport->to_paid) {
  229. include_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  230. $board = new ExpenseReport($db);
  231. $dashboardlines[$board->element.'_topay'] = $board->load_board($user, 'topay');
  232. }
  233. // Number of holidays to approve
  234. if (!empty($conf->holiday->enabled) && $user->rights->holiday->approve) {
  235. include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
  236. $board = new Holiday($db);
  237. $dashboardlines[$board->element] = $board->load_board($user);
  238. }
  239. $object = new stdClass();
  240. $parameters = array();
  241. $action = '';
  242. $reshook = $hookmanager->executeHooks(
  243. 'addOpenElementsDashboardLine',
  244. $parameters,
  245. $object,
  246. $action
  247. ); // Note that $action and $object may have been modified by some hooks
  248. if ($reshook == 0) {
  249. $dashboardlines = array_merge($dashboardlines, $hookmanager->resArray);
  250. }
  251. /* Open object dashboard */
  252. $dashboardgroup = array(
  253. 'action' =>
  254. array(
  255. 'groupName' => 'Agenda',
  256. 'stats' => array('action'),
  257. ),
  258. 'project' =>
  259. array(
  260. 'groupName' => 'Projects',
  261. 'globalStatsKey' => 'projects',
  262. 'stats' => array('project', 'project_task'),
  263. ),
  264. 'propal' =>
  265. array(
  266. 'groupName' => 'Proposals',
  267. 'globalStatsKey' => 'proposals',
  268. 'stats' =>
  269. array('propal_opened', 'propal_signed'),
  270. ),
  271. 'commande' =>
  272. array(
  273. 'groupName' => 'Orders',
  274. 'globalStatsKey' => 'orders',
  275. 'stats' =>
  276. array('commande'),
  277. ),
  278. 'facture' =>
  279. array(
  280. 'groupName' => 'Invoices',
  281. 'globalStatsKey' => 'invoices',
  282. 'stats' =>
  283. array('facture'),
  284. ),
  285. 'supplier_proposal' =>
  286. array(
  287. 'lang' => 'supplier_proposal',
  288. 'groupName' => 'SupplierProposals',
  289. 'globalStatsKey' => 'askprice',
  290. 'stats' =>
  291. array('supplier_proposal_opened', 'supplier_proposal_signed'),
  292. ),
  293. 'order_supplier' =>
  294. array(
  295. 'groupName' => 'SuppliersOrders',
  296. 'globalStatsKey' => 'supplier_orders',
  297. 'stats' =>
  298. array('order_supplier_opened', 'order_supplier_awaiting'),
  299. ),
  300. 'invoice_supplier' =>
  301. array(
  302. 'groupName' => 'BillsSuppliers',
  303. 'globalStatsKey' => 'supplier_invoices',
  304. 'stats' =>
  305. array('invoice_supplier'),
  306. ),
  307. 'contrat' =>
  308. array(
  309. 'groupName' => 'Contracts',
  310. 'globalStatsKey' => 'Contracts',
  311. 'stats' =>
  312. array('contrat_inactive', 'contrat_active'),
  313. ),
  314. 'ticket' =>
  315. array(
  316. 'groupName' => 'Tickets',
  317. 'globalStatsKey' => 'ticket',
  318. 'stats' =>
  319. array('ticket_opened'),
  320. ),
  321. 'bank_account' =>
  322. array(
  323. 'groupName' => 'BankAccount',
  324. 'stats' =>
  325. array('bank_account', 'chequereceipt'),
  326. ),
  327. 'member' =>
  328. array(
  329. 'groupName' => 'Members',
  330. 'globalStatsKey' => 'members',
  331. 'stats' =>
  332. array('member_shift', 'member_expired'),
  333. ),
  334. 'expensereport' =>
  335. array(
  336. 'groupName' => 'ExpenseReport',
  337. 'globalStatsKey' => 'expensereports',
  338. 'stats' =>
  339. array('expensereport_toapprove', 'expensereport_topay'),
  340. ),
  341. 'holiday' =>
  342. array(
  343. 'groupName' => 'Holidays',
  344. 'globalStatsKey' => 'holidays',
  345. 'stats' =>
  346. array('holiday'),
  347. ),
  348. );
  349. $object = new stdClass();
  350. $parameters = array(
  351. 'dashboardgroup' => $dashboardgroup
  352. );
  353. $reshook = $hookmanager->executeHooks('addOpenElementsDashboardGroup', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  354. if ($reshook == 0) {
  355. $dashboardgroup = array_merge($dashboardgroup, $hookmanager->resArray);
  356. }
  357. // Calculate total nb of late
  358. $totallate = $totaltodo = 0;
  359. //Remove any invalid response
  360. //load_board can return an integer if failed or WorkboardResponse if OK
  361. $valid_dashboardlines = array();
  362. foreach ($dashboardlines as $workboardid => $tmp) {
  363. if ($tmp instanceof WorkboardResponse) {
  364. $tmp->id = $workboardid; // Complete the object to add its id into its name
  365. $valid_dashboardlines[$workboardid] = $tmp;
  366. }
  367. }
  368. // We calculate $totallate. Must be defined before start of next loop because it is show in first fetch on next loop
  369. foreach ($valid_dashboardlines as $board) {
  370. if ($board->nbtodolate > 0) {
  371. $totaltodo += $board->nbtodo;
  372. $totallate += $board->nbtodolate;
  373. }
  374. }
  375. $openedDashBoardSize = 'info-box-sm'; // use sm by default
  376. foreach ($dashboardgroup as $dashbordelement) {
  377. if (is_array($dashbordelement['stats']) && count($dashbordelement['stats']) > 2) {
  378. $openedDashBoardSize = ''; // use default info box size : big
  379. break;
  380. }
  381. }
  382. $totalLateNumber = $totallate;
  383. $totallatePercentage = ((!empty($totaltodo)) ? round($totallate / $totaltodo * 100, 2) : 0);
  384. if (!empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE)) {
  385. $totallate = $totallatePercentage;
  386. }
  387. $boxwork = '';
  388. $boxwork .= '<div class="box">';
  389. $boxwork .= '<table summary="'.dol_escape_htmltag($langs->trans("WorkingBoard")).'" class="noborder boxtable boxtablenobottom boxworkingboard centpercent">'."\n";
  390. $boxwork .= '<tr class="liste_titre">';
  391. $boxwork .= '<th class="liste_titre"><div class="inline-block valignmiddle">'.$langs->trans("DolibarrWorkBoard").'</div>';
  392. if ($showweather) {
  393. if ($totallate > 0) {
  394. $text = $langs->transnoentitiesnoconv("WarningYouHaveAtLeastOneTaskLate").' ('.$langs->transnoentitiesnoconv(
  395. "NActionsLate",
  396. $totallate.(!empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE) ? '%' : '')
  397. ).')';
  398. } else {
  399. $text = $langs->transnoentitiesnoconv("NoItemLate");
  400. }
  401. $text .= '. '.$langs->transnoentitiesnoconv("LateDesc");
  402. //$text.=$form->textwithpicto('',$langs->trans("LateDesc"));
  403. $options = 'height="24px" style="float: right"';
  404. $boxwork .= showWeather($totallate, $text, $options, 'inline-block valignmiddle');
  405. }
  406. $boxwork .= '</th>';
  407. $boxwork .= '</tr>'."\n";
  408. // Show dashboard
  409. $nbworkboardempty = 0;
  410. $isIntopOpenedDashBoard = $globalStatInTopOpenedDashBoard = array();
  411. if (!empty($valid_dashboardlines)) {
  412. $openedDashBoard = '';
  413. $boxwork .= '<tr class="nobottom nohover"><td class="tdboxstats nohover flexcontainer centpercent"><div style="display: flex: flex-wrap: wrap">';
  414. foreach ($dashboardgroup as $groupKey => $groupElement) {
  415. $boards = array();
  416. if (empty($conf->global->MAIN_DISABLE_NEW_OPENED_DASH_BOARD)) {
  417. foreach ($groupElement['stats'] as $infoKey) {
  418. if (!empty($valid_dashboardlines[$infoKey])) {
  419. $boards[] = $valid_dashboardlines[$infoKey];
  420. $isIntopOpenedDashBoard[] = $infoKey;
  421. }
  422. }
  423. }
  424. if (!empty($boards)) {
  425. if (!empty($groupElement['lang'])) {
  426. $langs->load($groupElement['lang']);
  427. }
  428. $groupName = $langs->trans($groupElement['groupName']);
  429. $groupKeyLowerCase = strtolower($groupKey);
  430. $nbTotalForGroup = 0;
  431. // global stats
  432. $globalStatsKey = false;
  433. if (!empty($groupElement['globalStatsKey']) && empty($groupElement['globalStats'])) { // can be filled by hook
  434. $globalStatsKey = $groupElement['globalStatsKey'];
  435. $groupElement['globalStats'] = array();
  436. if (isset($keys) && is_array($keys) && in_array($globalStatsKey, $keys)) {
  437. // get key index of stats used in $includes, $classes, $keys, $icons, $titres, $links
  438. $keyIndex = array_search($globalStatsKey, $keys);
  439. $classe = (!empty($classes[$keyIndex]) ? $classes[$keyIndex] : '');
  440. if (isset($boardloaded[$classe]) && is_object($boardloaded[$classe])) {
  441. $groupElement['globalStats']['total'] = $boardloaded[$classe]->nb[$globalStatsKey] ? $boardloaded[$classe]->nb[$globalStatsKey] : 0;
  442. $nbTotal = floatval($groupElement['globalStats']['total']);
  443. if ($nbTotal >= 10000) {
  444. $nbTotal = round($nbTotal / 1000, 2).'k';
  445. }
  446. $groupElement['globalStats']['text'] = $langs->trans('Total').' : '.$langs->trans($titres[$keyIndex]).' ('.$groupElement['globalStats']['total'].')';
  447. $groupElement['globalStats']['total'] = $nbTotal;
  448. $groupElement['globalStats']['link'] = $links[$keyIndex];
  449. }
  450. }
  451. }
  452. $openedDashBoard .= '<div class="box-flex-item"><div class="box-flex-item-with-margin">'."\n";
  453. $openedDashBoard .= ' <div class="info-box '.$openedDashBoardSize.'">'."\n";
  454. $openedDashBoard .= ' <span class="info-box-icon bg-infobox-'.$groupKeyLowerCase.'">'."\n";
  455. $openedDashBoard .= ' <i class="fa fa-dol-'.$groupKeyLowerCase.'"></i>'."\n";
  456. // Show the span for the total of record
  457. if (!empty($groupElement['globalStats'])) {
  458. $globalStatInTopOpenedDashBoard[] = $globalStatsKey;
  459. $openedDashBoard .= '<span class="info-box-icon-text" title="'.$groupElement['globalStats']['text'].'">'.$nbTotal.'</span>';
  460. }
  461. $openedDashBoard .= '</span>'."\n";
  462. $openedDashBoard .= '<div class="info-box-content">'."\n";
  463. $openedDashBoard .= '<div class="info-box-title" title="'.strip_tags($groupName).'">'.$groupName.'</div>'."\n";
  464. $openedDashBoard .= '<div class="info-box-lines">'."\n";
  465. foreach ($boards as $board) {
  466. $openedDashBoard .= '<div class="info-box-line">';
  467. if (!empty($board->labelShort)) {
  468. $infoName = '<span title="'.$board->label.'">'.$board->labelShort.'</span>';
  469. } else {
  470. $infoName = $board->label;
  471. }
  472. $textLateTitle = $langs->trans("NActionsLate", $board->nbtodolate);
  473. $textLateTitle .= ' ('.$langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($board->warning_delay) >= 0 ? '+' : '').ceil($board->warning_delay).' '.$langs->trans("days").')';
  474. if ($board->id == 'bank_account') {
  475. $textLateTitle .= '<br><span class="opacitymedium">'.$langs->trans("IfYouDontReconcileDisableProperty", $langs->transnoentitiesnoconv("Conciliable")).'</span>';
  476. }
  477. $textLate = '';
  478. if ($board->nbtodolate > 0) {
  479. $textLate .= '<span title="'.dol_escape_htmltag($textLateTitle).'" class="classfortooltip badge badge-warning">';
  480. $textLate .= '<i class="fa fa-exclamation-triangle"></i> '.$board->nbtodolate;
  481. $textLate .= '</span>';
  482. }
  483. $nbtodClass = '';
  484. if ($board->nbtodo > 0) {
  485. $nbtodClass = 'badge badge-info';
  486. }
  487. $openedDashBoard .= ' <a href="'.$board->url.'" class="info-box-text info-box-text-a">'.$infoName.' : <span class="'.$nbtodClass.' classfortooltip" title="'.$board->label.'" >'.$board->nbtodo.'</span>';
  488. if ($textLate) {
  489. if ($board->url_late) {
  490. $openedDashBoard .= '</a>';
  491. $openedDashBoard .= ' <a href="'.$board->url_late.'" class="info-box-text info-box-text-a paddingleft">';
  492. } else {
  493. $openedDashBoard .= ' ';
  494. }
  495. $openedDashBoard .= $textLate;
  496. }
  497. $openedDashBoard .= '</a>'."\n";
  498. if ($board->total > 0 && !empty($conf->global->MAIN_WORKBOARD_SHOW_TOTAL_WO_TAX)) {
  499. $openedDashBoard .= '<a href="'.$board->url.'" class="info-box-text">'.$langs->trans('Total').' : '.price($board->total).'</a>';
  500. }
  501. $openedDashBoard .= '</div>'."\n";
  502. }
  503. // TODO Add hook here to add more "info-box-line"
  504. $openedDashBoard .= ' </div><!-- /.info-box-lines --></div><!-- /.info-box-content -->'."\n";
  505. $openedDashBoard .= ' </div><!-- /.info-box -->'."\n";
  506. $openedDashBoard .= '</div><!-- /.box-flex-item-with-margin -->'."\n";
  507. $openedDashBoard .= '</div><!-- /.box-flex-item -->'."\n";
  508. $openedDashBoard .= "\n";
  509. }
  510. }
  511. if ($showweather && !empty($isIntopOpenedDashBoard)) {
  512. $appendClass = (!empty($conf->global->MAIN_DISABLE_METEO) && $conf->global->MAIN_DISABLE_METEO == 2 ? ' hideonsmartphone' : '');
  513. $weather = getWeatherStatus($totallate);
  514. $text = '';
  515. if ($totallate > 0) {
  516. $text = $langs->transnoentitiesnoconv("WarningYouHaveAtLeastOneTaskLate").' ('.$langs->transnoentitiesnoconv(
  517. "NActionsLate",
  518. $totallate.(!empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE) ? '%' : '')
  519. ).')';
  520. } else {
  521. $text = $langs->transnoentitiesnoconv("NoItemLate");
  522. }
  523. $text .= '. '.$langs->transnoentitiesnoconv("LateDesc");
  524. $weatherDashBoard = '<div class="box-flex-item '.$appendClass.'"><div class="box-flex-item-with-margin">'."\n";
  525. $weatherDashBoard .= ' <div class="info-box '.$openedDashBoardSize.' info-box-weather info-box-weather-level'.$weather->level.'">'."\n";
  526. $weatherDashBoard .= ' <span class="info-box-icon">';
  527. $weatherDashBoard .= img_weather('', $weather->level, '', 0, 'valignmiddle width50');
  528. $weatherDashBoard .= ' </span>'."\n";
  529. $weatherDashBoard .= ' <div class="info-box-content">'."\n";
  530. $weatherDashBoard .= ' <div class="info-box-title">'.$langs->trans('GlobalOpenedElemView').'</div>'."\n";
  531. if ($totallatePercentage > 0 && !empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE)) {
  532. $weatherDashBoard .= ' <span class="info-box-number">'.$langs->transnoentitiesnoconv(
  533. "NActionsLate",
  534. price($totallatePercentage).'%'
  535. ).'</span>'."\n";
  536. $weatherDashBoard .= ' <span class="progress-description">'.$langs->trans(
  537. 'NActionsLate',
  538. $totalLateNumber
  539. ).'</span>'."\n";
  540. } else {
  541. $weatherDashBoard .= ' <span class="info-box-number">'.$langs->transnoentitiesnoconv(
  542. "NActionsLate",
  543. $totalLateNumber
  544. ).'</span>'."\n";
  545. if ($totallatePercentage > 0) {
  546. $weatherDashBoard .= ' <span class="progress-description">'.$langs->trans(
  547. 'NActionsLate',
  548. price($totallatePercentage).'%'
  549. ).'</span>'."\n";
  550. }
  551. }
  552. $weatherDashBoard .= ' </div><!-- /.info-box-content -->'."\n";
  553. $weatherDashBoard .= ' </div><!-- /.info-box -->'."\n";
  554. $weatherDashBoard .= '</div><!-- /.box-flex-item-with-margin -->'."\n";
  555. $weatherDashBoard .= '</div><!-- /.box-flex-item -->'."\n";
  556. $weatherDashBoard .= "\n";
  557. $openedDashBoard = $weatherDashBoard.$openedDashBoard;
  558. }
  559. if (!empty($isIntopOpenedDashBoard)) {
  560. for ($i = 1; $i <= 10; $i++) {
  561. $openedDashBoard .= '<div class="box-flex-item filler"></div>';
  562. }
  563. }
  564. $nbworkboardcount = 0;
  565. foreach ($valid_dashboardlines as $infoKey => $board) {
  566. if (in_array($infoKey, $isIntopOpenedDashBoard)) {
  567. // skip if info is present on top
  568. continue;
  569. }
  570. if (empty($board->nbtodo)) {
  571. $nbworkboardempty++;
  572. }
  573. $nbworkboardcount++;
  574. $textlate = $langs->trans("NActionsLate", $board->nbtodolate);
  575. $textlate .= ' ('.$langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($board->warning_delay) >= 0 ? '+' : '').ceil($board->warning_delay).' '.$langs->trans("days").')';
  576. $boxwork .= '<div class="boxstatsindicator thumbstat150 nobold nounderline"><div class="boxstats130 boxstatsborder">';
  577. $boxwork .= '<div class="boxstatscontent">';
  578. $boxwork .= '<span class="boxstatstext" title="'.dol_escape_htmltag($board->label).'">'.$board->img.' <span>'.$board->label.'</span></span><br>';
  579. $boxwork .= '<a class="valignmiddle dashboardlineindicator" href="'.$board->url.'"><span class="dashboardlineindicator'.(($board->nbtodo == 0) ? ' dashboardlineok' : '').'">'.$board->nbtodo.'</span></a>';
  580. if ($board->total > 0 && !empty($conf->global->MAIN_WORKBOARD_SHOW_TOTAL_WO_TAX)) {
  581. $boxwork .= '&nbsp;/&nbsp;<a class="valignmiddle dashboardlineindicator" href="'.$board->url.'"><span class="dashboardlineindicator'.(($board->nbtodo == 0) ? ' dashboardlineok' : '').'">'.price($board->total).'</span></a>';
  582. }
  583. $boxwork .= '</div>';
  584. if ($board->nbtodolate > 0) {
  585. $boxwork .= '<div class="dashboardlinelatecoin nowrap">';
  586. $boxwork .= '<a title="'.dol_escape_htmltag($textlate).'" class="valignmiddle dashboardlineindicatorlate'.($board->nbtodolate > 0 ? ' dashboardlineko' : ' dashboardlineok').'" href="'.((!$board->url_late) ? $board->url : $board->url_late).'">';
  587. //$boxwork .= img_picto($textlate, "warning_white", 'class="valigntextbottom"').'';
  588. $boxwork .= img_picto(
  589. $textlate,
  590. "warning_white",
  591. 'class="inline-block hideonsmartphone valigntextbottom"'
  592. ).'';
  593. $boxwork .= '<span class="dashboardlineindicatorlate'.($board->nbtodolate > 0 ? ' dashboardlineko' : ' dashboardlineok').'">';
  594. $boxwork .= $board->nbtodolate;
  595. $boxwork .= '</span>';
  596. $boxwork .= '</a>';
  597. $boxwork .= '</div>';
  598. }
  599. $boxwork .= '</div></div>';
  600. $boxwork .= "\n";
  601. }
  602. $boxwork .= '<div class="boxstatsindicator thumbstat150 nobold nounderline"><div class="boxstats150empty"></div></div>';
  603. $boxwork .= '<div class="boxstatsindicator thumbstat150 nobold nounderline"><div class="boxstats150empty"></div></div>';
  604. $boxwork .= '<div class="boxstatsindicator thumbstat150 nobold nounderline"><div class="boxstats150empty"></div></div>';
  605. $boxwork .= '<div class="boxstatsindicator thumbstat150 nobold nounderline"><div class="boxstats150empty"></div></div>';
  606. $boxwork .= '</div>';
  607. $boxwork .= '</td></tr>';
  608. } else {
  609. $boxwork .= '<tr class="nohover">';
  610. $boxwork .= '<td class="nohover valignmiddle opacitymedium">';
  611. $boxwork .= $langs->trans("NoOpenedElementToProcess");
  612. $boxwork .= '</td>';
  613. $boxwork .= '</tr>';
  614. }
  615. $boxwork .= '</td></tr>';
  616. $boxwork .= '</table>'; // End table array of working board
  617. $boxwork .= '</div>';
  618. if (!empty($isIntopOpenedDashBoard)) {
  619. print '<div class="fichecenter">';
  620. print '<div class="opened-dash-board-wrap"><div class="box-flex-container">'.$openedDashBoard.'</div></div>';
  621. print '</div>';
  622. }
  623. }
  624. print '<div class="clearboth"></div>';
  625. print '<div class="fichecenter fichecenterbis">';
  626. /*
  627. * Show widgets (boxes)
  628. */
  629. $boxlist = '<div class="twocolumns">';
  630. $boxlist .= '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
  631. if (!empty($nbworkboardcount)) {
  632. $boxlist .= $boxwork;
  633. }
  634. $boxlist .= $resultboxes['boxlista'];
  635. $boxlist .= '</div>';
  636. $boxlist .= '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
  637. $boxlist .= $resultboxes['boxlistb'];
  638. $boxlist .= '</div>';
  639. $boxlist .= "\n";
  640. $boxlist .= '</div>';
  641. print $boxlist;
  642. print '</div>';
  643. //print 'mem='.memory_get_usage().' - '.memory_get_peak_usage();
  644. // End of page
  645. llxFooter();
  646. $db->close();
  647. /**
  648. * Show weather logo. Logo to show depends on $totallate and values for
  649. * $conf->global->MAIN_METEO_LEVELx
  650. *
  651. * @param int $totallate Nb of element late
  652. * @param string $text Text to show on logo
  653. * @param string $options More parameters on img tag
  654. * @param string $morecss More CSS
  655. * @return string Return img tag of weather
  656. */
  657. function showWeather($totallate, $text, $options, $morecss = '')
  658. {
  659. global $conf;
  660. $weather = getWeatherStatus($totallate);
  661. return img_weather($text, $weather->picto, $options, 0, $morecss);
  662. }
  663. /**
  664. * get weather level
  665. * $conf->global->MAIN_METEO_LEVELx
  666. *
  667. * @param int $totallate Nb of element late
  668. * @return stdClass Return img tag of weather
  669. */
  670. function getWeatherStatus($totallate)
  671. {
  672. global $conf;
  673. $weather = new stdClass();
  674. $weather->picto = '';
  675. $offset = 0;
  676. $factor = 10; // By default
  677. $used_conf = empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE) ? 'MAIN_METEO_LEVEL' : 'MAIN_METEO_PERCENTAGE_LEVEL';
  678. $level0 = $offset;
  679. $weather->level = 0;
  680. if (!empty($conf->global->{$used_conf.'0'})) {
  681. $level0 = $conf->global->{$used_conf.'0'};
  682. }
  683. $level1 = $offset + 1 * $factor;
  684. if (!empty($conf->global->{$used_conf.'1'})) {
  685. $level1 = $conf->global->{$used_conf.'1'};
  686. }
  687. $level2 = $offset + 2 * $factor;
  688. if (!empty($conf->global->{$used_conf.'2'})) {
  689. $level2 = $conf->global->{$used_conf.'2'};
  690. }
  691. $level3 = $offset + 3 * $factor;
  692. if (!empty($conf->global->{$used_conf.'3'})) {
  693. $level3 = $conf->global->{$used_conf.'3'};
  694. }
  695. if ($totallate <= $level0) {
  696. $weather->picto = 'weather-clear.png';
  697. $weather->level = 0;
  698. } elseif ($totallate <= $level1) {
  699. $weather->picto = 'weather-few-clouds.png';
  700. $weather->level = 1;
  701. } elseif ($totallate <= $level2) {
  702. $weather->picto = 'weather-clouds.png';
  703. $weather->level = 2;
  704. } elseif ($totallate <= $level3) {
  705. $weather->picto = 'weather-many-clouds.png';
  706. $weather->level = 3;
  707. } else {
  708. $weather->picto = 'weather-storm.png';
  709. $weather->level = 4;
  710. }
  711. return $weather;
  712. }