index.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  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 (isModEnabled('agenda') && empty($conf->global->MAIN_DISABLE_BLOCK_AGENDA) && $user->hasRight('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 (isModEnabled('project') && empty($conf->global->MAIN_DISABLE_BLOCK_PROJECT) && $user->hasRight('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 (isModEnabled('project') && empty($conf->global->MAIN_DISABLE_BLOCK_PROJECT) && empty($conf->global->PROJECT_HIDE_TASKS) && $user->hasRight('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 customer proposals open (expired)
  143. if (isModEnabled('propal') && empty($conf->global->MAIN_DISABLE_BLOCK_CUSTOMER) && $user->hasRight('propal', '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 supplier proposals open (expired)
  151. if (isModEnabled('supplier_proposal') && empty($conf->global->MAIN_DISABLE_BLOCK_SUPPLIER) && $user->hasRight('supplier_proposal', 'lire')) {
  152. $langs->load("supplier_proposal");
  153. include_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
  154. $board = new SupplierProposal($db);
  155. $dashboardlines[$board->element.'_opened'] = $board->load_board($user, "opened");
  156. // Number of commercial proposals CLOSED signed (billed)
  157. $dashboardlines[$board->element.'_signed'] = $board->load_board($user, "signed");
  158. }
  159. // Number of customer orders a deal
  160. if (isModEnabled('commande') && empty($conf->global->MAIN_DISABLE_BLOCK_CUSTOMER) && $user->hasRight('commande', 'lire')) {
  161. include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  162. $board = new Commande($db);
  163. $dashboardlines[$board->element] = $board->load_board($user);
  164. }
  165. // Number of suppliers orders a deal
  166. if (isModEnabled('supplier_order') && empty($conf->global->MAIN_DISABLE_BLOCK_SUPPLIER) && $user->hasRight('fournisseur', 'commande', 'lire')) {
  167. include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  168. $board = new CommandeFournisseur($db);
  169. $dashboardlines[$board->element.'_opened'] = $board->load_board($user, "opened");
  170. $dashboardlines[$board->element.'_awaiting'] = $board->load_board($user, 'awaiting');
  171. }
  172. // Number of contract / services enabled (delayed)
  173. if (isModEnabled('contrat') && empty($conf->global->MAIN_DISABLE_BLOCK_CONTRACT) && $user->hasRight('contrat', 'lire')) {
  174. include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  175. $board = new Contrat($db);
  176. $dashboardlines[$board->element.'_inactive'] = $board->load_board($user, "inactive");
  177. // Number of active services (expired)
  178. $dashboardlines[$board->element.'_active'] = $board->load_board($user, "active");
  179. }
  180. // Number of tickets open
  181. if (isModEnabled('ticket') && empty($conf->global->MAIN_DISABLE_BLOCK_TICKET) && $user->hasRight('ticket', 'read')) {
  182. include_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
  183. $board = new Ticket($db);
  184. $dashboardlines[$board->element.'_opened'] = $board->load_board($user, "opened");
  185. // Number of active services (expired)
  186. //$dashboardlines[$board->element.'_active'] = $board->load_board($user, "active");
  187. }
  188. // Number of invoices customers (paid)
  189. if (isModEnabled('facture') && empty($conf->global->MAIN_DISABLE_BLOCK_CUSTOMER) && $user->hasRight('facture', 'lire')) {
  190. include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  191. $board = new Facture($db);
  192. $dashboardlines[$board->element] = $board->load_board($user);
  193. }
  194. // Number of supplier invoices (paid)
  195. if (isModEnabled('supplier_invoice') && empty($conf->global->MAIN_DISABLE_BLOCK_SUPPLIER) && $user->hasRight('fournisseur', 'facture', 'lire')) {
  196. include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  197. $board = new FactureFournisseur($db);
  198. $dashboardlines[$board->element] = $board->load_board($user);
  199. }
  200. // Number of transactions to conciliate
  201. if (isModEnabled('banque') && empty($conf->global->MAIN_DISABLE_BLOCK_BANK) && $user->hasRight('banque', 'lire') && !$user->socid) {
  202. include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  203. $board = new Account($db);
  204. $nb = $board->countAccountToReconcile(); // Get nb of account to reconciliate
  205. if ($nb > 0) {
  206. $dashboardlines[$board->element] = $board->load_board($user);
  207. }
  208. }
  209. // Number of cheque to send
  210. if (isModEnabled('banque') && empty($conf->global->MAIN_DISABLE_BLOCK_BANK) && $user->hasRight('banque', 'lire') && !$user->socid) {
  211. if (empty($conf->global->BANK_DISABLE_CHECK_DEPOSIT)) {
  212. include_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
  213. $board = new RemiseCheque($db);
  214. $dashboardlines[$board->element] = $board->load_board($user);
  215. }
  216. if (!empty($conf->prelevement->enabled)) {
  217. include_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
  218. $board = new BonPrelevement($db);
  219. $dashboardlines[$board->element.'_direct_debit'] = $board->load_board($user, 'direct_debit');
  220. }
  221. if (!empty($conf->paymentbybanktransfer->enabled)) {
  222. include_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
  223. $board = new BonPrelevement($db);
  224. $dashboardlines[$board->element.'_credit_transfer'] = $board->load_board($user, 'credit_transfer');
  225. }
  226. }
  227. // Number of foundation members
  228. if (isModEnabled('adherent') && empty($conf->global->MAIN_DISABLE_BLOCK_ADHERENT) && $user->hasRight('adherent', 'lire') && !$user->socid) {
  229. include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  230. $board = new Adherent($db);
  231. $dashboardlines[$board->element.'_shift'] = $board->load_board($user, 'shift');
  232. $dashboardlines[$board->element.'_expired'] = $board->load_board($user, 'expired');
  233. }
  234. // Number of expense reports to approve
  235. if (isModEnabled('expensereport') && empty($conf->global->MAIN_DISABLE_BLOCK_EXPENSEREPORT) && $user->hasRight('expensereport', 'approve')) {
  236. include_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  237. $board = new ExpenseReport($db);
  238. $dashboardlines[$board->element.'_toapprove'] = $board->load_board($user, 'toapprove');
  239. }
  240. // Number of expense reports to pay
  241. if (isModEnabled('expensereport') && empty($conf->global->MAIN_DISABLE_BLOCK_EXPENSEREPORT) && $user->hasRight('expensereport', 'to_paid')) {
  242. include_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  243. $board = new ExpenseReport($db);
  244. $dashboardlines[$board->element.'_topay'] = $board->load_board($user, 'topay');
  245. }
  246. // Number of holidays to approve
  247. if (isModEnabled('holiday') && empty($conf->global->MAIN_DISABLE_BLOCK_HOLIDAY) && $user->hasRight('holiday', 'approve')) {
  248. include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
  249. $board = new Holiday($db);
  250. $dashboardlines[$board->element] = $board->load_board($user);
  251. }
  252. $object = new stdClass();
  253. $parameters = array();
  254. $action = '';
  255. $reshook = $hookmanager->executeHooks(
  256. 'addOpenElementsDashboardLine',
  257. $parameters,
  258. $object,
  259. $action
  260. ); // Note that $action and $object may have been modified by some hooks
  261. if ($reshook == 0) {
  262. $dashboardlines = array_merge($dashboardlines, $hookmanager->resArray);
  263. }
  264. /* Open object dashboard */
  265. $dashboardgroup = array(
  266. 'action' =>
  267. array(
  268. 'groupName' => 'Agenda',
  269. 'stats' => array('action'),
  270. ),
  271. 'project' =>
  272. array(
  273. 'groupName' => 'Projects',
  274. 'globalStatsKey' => 'projects',
  275. 'stats' => array('project', 'project_task'),
  276. ),
  277. 'propal' =>
  278. array(
  279. 'groupName' => 'Proposals',
  280. 'globalStatsKey' => 'proposals',
  281. 'stats' =>
  282. array('propal_opened', 'propal_signed'),
  283. ),
  284. 'commande' =>
  285. array(
  286. 'groupName' => 'Orders',
  287. 'globalStatsKey' => 'orders',
  288. 'stats' =>
  289. array('commande'),
  290. ),
  291. 'facture' =>
  292. array(
  293. 'groupName' => 'Invoices',
  294. 'globalStatsKey' => 'invoices',
  295. 'stats' =>
  296. array('facture'),
  297. ),
  298. 'supplier_proposal' =>
  299. array(
  300. 'lang' => 'supplier_proposal',
  301. 'groupName' => 'SupplierProposals',
  302. 'globalStatsKey' => 'askprice',
  303. 'stats' =>
  304. array('supplier_proposal_opened', 'supplier_proposal_signed'),
  305. ),
  306. 'order_supplier' =>
  307. array(
  308. 'groupName' => 'SuppliersOrders',
  309. 'globalStatsKey' => 'supplier_orders',
  310. 'stats' =>
  311. array('order_supplier_opened', 'order_supplier_awaiting'),
  312. ),
  313. 'invoice_supplier' =>
  314. array(
  315. 'groupName' => 'BillsSuppliers',
  316. 'globalStatsKey' => 'supplier_invoices',
  317. 'stats' =>
  318. array('invoice_supplier'),
  319. ),
  320. 'contrat' =>
  321. array(
  322. 'groupName' => 'Contracts',
  323. 'globalStatsKey' => 'Contracts',
  324. 'stats' =>
  325. array('contrat_inactive', 'contrat_active'),
  326. ),
  327. 'ticket' =>
  328. array(
  329. 'groupName' => 'Tickets',
  330. 'globalStatsKey' => 'ticket',
  331. 'stats' =>
  332. array('ticket_opened'),
  333. ),
  334. 'bank_account' =>
  335. array(
  336. 'groupName' => 'BankAccount',
  337. 'stats' =>
  338. array('bank_account', 'chequereceipt', 'widthdraw_direct_debit', 'widthdraw_credit_transfer'),
  339. ),
  340. 'member' =>
  341. array(
  342. 'groupName' => 'Members',
  343. 'globalStatsKey' => 'members',
  344. 'stats' =>
  345. array('member_shift', 'member_expired'),
  346. ),
  347. 'expensereport' =>
  348. array(
  349. 'groupName' => 'ExpenseReport',
  350. 'globalStatsKey' => 'expensereports',
  351. 'stats' =>
  352. array('expensereport_toapprove', 'expensereport_topay'),
  353. ),
  354. 'holiday' =>
  355. array(
  356. 'groupName' => 'Holidays',
  357. 'globalStatsKey' => 'holidays',
  358. 'stats' =>
  359. array('holiday'),
  360. ),
  361. );
  362. $object = new stdClass();
  363. $parameters = array(
  364. 'dashboardgroup' => $dashboardgroup
  365. );
  366. $reshook = $hookmanager->executeHooks('addOpenElementsDashboardGroup', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  367. if ($reshook == 0) {
  368. $dashboardgroup = array_merge($dashboardgroup, $hookmanager->resArray);
  369. }
  370. // Calculate total nb of late
  371. $totallate = $totaltodo = 0;
  372. //Remove any invalid response
  373. //load_board can return an integer if failed, or WorkboardResponse if OK
  374. $valid_dashboardlines = array();
  375. foreach ($dashboardlines as $workboardid => $tmp) {
  376. if ($tmp instanceof WorkboardResponse) {
  377. $tmp->id = $workboardid; // Complete the object to add its id into its name
  378. $valid_dashboardlines[$workboardid] = $tmp;
  379. }
  380. }
  381. // We calculate $totallate. Must be defined before start of next loop because it is show in first fetch on next loop
  382. foreach ($valid_dashboardlines as $board) {
  383. if ($board->nbtodolate > 0) {
  384. $totaltodo += $board->nbtodo;
  385. $totallate += $board->nbtodolate;
  386. }
  387. }
  388. $openedDashBoardSize = 'info-box-sm'; // use sm by default
  389. foreach ($dashboardgroup as $dashbordelement) {
  390. if (is_array($dashbordelement['stats']) && count($dashbordelement['stats']) > 2) {
  391. $openedDashBoardSize = ''; // use default info box size : big
  392. break;
  393. }
  394. }
  395. $totalLateNumber = $totallate;
  396. $totallatePercentage = ((!empty($totaltodo)) ? round($totallate / $totaltodo * 100, 2) : 0);
  397. if (!empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE)) {
  398. $totallate = $totallatePercentage;
  399. }
  400. $boxwork = '';
  401. $boxwork .= '<div class="box">';
  402. $boxwork .= '<table summary="'.dol_escape_htmltag($langs->trans("WorkingBoard")).'" class="noborder boxtable boxtablenobottom boxworkingboard centpercent">'."\n";
  403. $boxwork .= '<tr class="liste_titre">';
  404. $boxwork .= '<th class="liste_titre"><div class="inline-block valignmiddle">'.$langs->trans("DolibarrWorkBoard").'</div>';
  405. if ($showweather) {
  406. if ($totallate > 0) {
  407. $text = $langs->transnoentitiesnoconv("WarningYouHaveAtLeastOneTaskLate").' ('.$langs->transnoentitiesnoconv(
  408. "NActionsLate",
  409. $totallate.(!empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE) ? '%' : '')
  410. ).')';
  411. } else {
  412. $text = $langs->transnoentitiesnoconv("NoItemLate");
  413. }
  414. $text .= '. '.$langs->transnoentitiesnoconv("LateDesc");
  415. //$text.=$form->textwithpicto('',$langs->trans("LateDesc"));
  416. $options = 'height="24px" style="float: right"';
  417. $boxwork .= showWeather($totallate, $text, $options, 'inline-block valignmiddle');
  418. }
  419. $boxwork .= '</th>';
  420. $boxwork .= '</tr>'."\n";
  421. // Show dashboard
  422. $nbworkboardempty = 0;
  423. $isIntopOpenedDashBoard = $globalStatInTopOpenedDashBoard = array();
  424. if (!empty($valid_dashboardlines)) {
  425. $openedDashBoard = '';
  426. $boxwork .= '<tr class="nobottom nohover"><td class="tdboxstats nohover flexcontainer centpercent"><div style="display: flex: flex-wrap: wrap">';
  427. foreach ($dashboardgroup as $groupKey => $groupElement) {
  428. $boards = array();
  429. // Scan $groupElement and save the one with 'stats' that lust be used for Open object dashboard
  430. if (empty($conf->global->MAIN_DISABLE_NEW_OPENED_DASH_BOARD)) {
  431. foreach ($groupElement['stats'] as $infoKey) {
  432. if (!empty($valid_dashboardlines[$infoKey])) {
  433. $boards[] = $valid_dashboardlines[$infoKey];
  434. $isIntopOpenedDashBoard[] = $infoKey;
  435. }
  436. }
  437. }
  438. if (!empty($boards)) {
  439. if (!empty($groupElement['lang'])) {
  440. $langs->load($groupElement['lang']);
  441. }
  442. $groupName = $langs->trans($groupElement['groupName']);
  443. $groupKeyLowerCase = strtolower($groupKey);
  444. // global stats
  445. $globalStatsKey = false;
  446. if (!empty($groupElement['globalStatsKey']) && empty($groupElement['globalStats'])) { // can be filled by hook
  447. $globalStatsKey = $groupElement['globalStatsKey'];
  448. $groupElement['globalStats'] = array();
  449. if (isset($keys) && is_array($keys) && in_array($globalStatsKey, $keys)) {
  450. // get key index of stats used in $includes, $classes, $keys, $icons, $titres, $links
  451. $keyIndex = array_search($globalStatsKey, $keys);
  452. $classe = (!empty($classes[$keyIndex]) ? $classes[$keyIndex] : '');
  453. if (isset($boardloaded[$classe]) && is_object($boardloaded[$classe])) {
  454. $groupElement['globalStats']['total'] = $boardloaded[$classe]->nb[$globalStatsKey] ? $boardloaded[$classe]->nb[$globalStatsKey] : 0;
  455. $nbTotal = floatval($groupElement['globalStats']['total']);
  456. if ($nbTotal >= 10000) {
  457. $nbTotal = round($nbTotal / 1000, 2).'k';
  458. }
  459. $groupElement['globalStats']['text'] = $langs->trans('Total').' : '.$langs->trans($titres[$keyIndex]).' ('.$groupElement['globalStats']['total'].')';
  460. $groupElement['globalStats']['total'] = $nbTotal;
  461. //$groupElement['globalStats']['link'] = $links[$keyIndex];
  462. }
  463. }
  464. }
  465. $openedDashBoard .= '<div class="box-flex-item"><div class="box-flex-item-with-margin">'."\n";
  466. $openedDashBoard .= ' <div class="info-box '.$openedDashBoardSize.'">'."\n";
  467. $openedDashBoard .= ' <span class="info-box-icon bg-infobox-'.$groupKeyLowerCase.'">'."\n";
  468. $openedDashBoard .= ' <i class="fa fa-dol-'.$groupKeyLowerCase.'"></i>'."\n";
  469. // Show the span for the total of record
  470. if (!empty($groupElement['globalStats'])) {
  471. $globalStatInTopOpenedDashBoard[] = $globalStatsKey;
  472. $openedDashBoard .= '<span class="info-box-icon-text" title="'.$groupElement['globalStats']['text'].'">'.$nbTotal.'</span>';
  473. }
  474. $openedDashBoard .= '</span>'."\n";
  475. $openedDashBoard .= '<div class="info-box-content">'."\n";
  476. $openedDashBoard .= '<div class="info-box-title" title="'.strip_tags($groupName).'">'.$groupName.'</div>'."\n";
  477. $openedDashBoard .= '<div class="info-box-lines">'."\n";
  478. foreach ($boards as $board) {
  479. $openedDashBoard .= '<div class="info-box-line">';
  480. if (!empty($board->labelShort)) {
  481. $infoName = '<span class="marginrightonly" title="'.$board->label.'">'.$board->labelShort.'</span>';
  482. } else {
  483. $infoName = '<span class="marginrightonly">'.$board->label.'</span>';
  484. }
  485. $textLateTitle = $langs->trans("NActionsLate", $board->nbtodolate);
  486. $textLateTitle .= ' ('.$langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($board->warning_delay) >= 0 ? '+' : '').ceil($board->warning_delay).' '.$langs->trans("days").')';
  487. if ($board->id == 'bank_account') {
  488. $textLateTitle .= '<br><span class="opacitymedium">'.$langs->trans("IfYouDontReconcileDisableProperty", $langs->transnoentitiesnoconv("Conciliable")).'</span>';
  489. }
  490. $textLate = '';
  491. if ($board->nbtodolate > 0) {
  492. $textLate .= '<span title="'.dol_escape_htmltag($textLateTitle).'" class="classfortooltip badge badge-warning">';
  493. $textLate .= '<i class="fa fa-exclamation-triangle"></i> '.$board->nbtodolate;
  494. $textLate .= '</span>';
  495. }
  496. $nbtodClass = '';
  497. if ($board->nbtodo > 0) {
  498. $nbtodClass = 'badge badge-info';
  499. } else {
  500. $nbtodClass = 'opacitymedium';
  501. }
  502. // Forge the line to show into the open object box
  503. $labeltoshow = $board->label.' ('.$board->nbtodo.')';
  504. if ($board->total > 0) {
  505. $labeltoshow .= ' - '.price($board->total, 0, $langs, 1, -1, -1, $conf->currency);
  506. }
  507. $openedDashBoard .= '<a href="'.$board->url.'" class="info-box-text info-box-text-a">'.$infoName.'<span class="classfortooltip'.($nbtodClass ? ' '.$nbtodClass : '').'" title="'.$labeltoshow.'" >';
  508. $openedDashBoard .= $board->nbtodo;
  509. if ($board->total > 0 && !empty($conf->global->MAIN_WORKBOARD_SHOW_TOTAL_WO_TAX)) {
  510. $openedDashBoard .= ' : '.price($board->total, 0, $langs, 1, -1, -1, $conf->currency);
  511. }
  512. $openedDashBoard .= '</span>';
  513. if ($textLate) {
  514. if ($board->url_late) {
  515. $openedDashBoard .= '</a>';
  516. $openedDashBoard .= ' <a href="'.$board->url_late.'" class="info-box-text info-box-text-a paddingleft">';
  517. } else {
  518. $openedDashBoard .= ' ';
  519. }
  520. $openedDashBoard .= $textLate;
  521. }
  522. $openedDashBoard .= '</a>'."\n";
  523. $openedDashBoard .= '</div>'."\n";
  524. }
  525. // TODO Add hook here to add more "info-box-line"
  526. $openedDashBoard .= ' </div><!-- /.info-box-lines --></div><!-- /.info-box-content -->'."\n";
  527. $openedDashBoard .= ' </div><!-- /.info-box -->'."\n";
  528. $openedDashBoard .= '</div><!-- /.box-flex-item-with-margin -->'."\n";
  529. $openedDashBoard .= '</div><!-- /.box-flex-item -->'."\n";
  530. $openedDashBoard .= "\n";
  531. }
  532. }
  533. if ($showweather && !empty($isIntopOpenedDashBoard)) {
  534. $appendClass = (!empty($conf->global->MAIN_DISABLE_METEO) && $conf->global->MAIN_DISABLE_METEO == 2 ? ' hideonsmartphone' : '');
  535. $weather = getWeatherStatus($totallate);
  536. $text = '';
  537. if ($totallate > 0) {
  538. $text = $langs->transnoentitiesnoconv("WarningYouHaveAtLeastOneTaskLate").' ('.$langs->transnoentitiesnoconv(
  539. "NActionsLate",
  540. $totallate.(!empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE) ? '%' : '')
  541. ).')';
  542. } else {
  543. $text = $langs->transnoentitiesnoconv("NoItemLate");
  544. }
  545. $text .= '. '.$langs->transnoentitiesnoconv("LateDesc");
  546. $weatherDashBoard = '<div class="box-flex-item '.$appendClass.'"><div class="box-flex-item-with-margin">'."\n";
  547. $weatherDashBoard .= ' <div class="info-box '.$openedDashBoardSize.' info-box-weather info-box-weather-level'.$weather->level.'">'."\n";
  548. $weatherDashBoard .= ' <span class="info-box-icon">';
  549. $weatherDashBoard .= img_weather('', $weather->level, '', 0, 'valignmiddle width50');
  550. $weatherDashBoard .= ' </span>'."\n";
  551. $weatherDashBoard .= ' <div class="info-box-content">'."\n";
  552. $weatherDashBoard .= ' <div class="info-box-title">'.$langs->trans('GlobalOpenedElemView').'</div>'."\n";
  553. if ($totallatePercentage > 0 && !empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE)) {
  554. $weatherDashBoard .= ' <span class="info-box-number">'.$langs->transnoentitiesnoconv(
  555. "NActionsLate",
  556. price($totallatePercentage).'%'
  557. ).'</span>'."\n";
  558. $weatherDashBoard .= ' <span class="progress-description">'.$langs->trans(
  559. 'NActionsLate',
  560. $totalLateNumber
  561. ).'</span>'."\n";
  562. } else {
  563. $weatherDashBoard .= ' <span class="info-box-number">'.$langs->transnoentitiesnoconv(
  564. "NActionsLate",
  565. $totalLateNumber
  566. ).'</span>'."\n";
  567. if ($totallatePercentage > 0) {
  568. $weatherDashBoard .= ' <span class="progress-description">'.$langs->trans(
  569. 'NActionsLate',
  570. price($totallatePercentage).'%'
  571. ).'</span>'."\n";
  572. }
  573. }
  574. $weatherDashBoard .= ' </div><!-- /.info-box-content -->'."\n";
  575. $weatherDashBoard .= ' </div><!-- /.info-box -->'."\n";
  576. $weatherDashBoard .= '</div><!-- /.box-flex-item-with-margin -->'."\n";
  577. $weatherDashBoard .= '</div><!-- /.box-flex-item -->'."\n";
  578. $weatherDashBoard .= "\n";
  579. $openedDashBoard = $weatherDashBoard.$openedDashBoard;
  580. }
  581. if (!empty($isIntopOpenedDashBoard)) {
  582. for ($i = 1; $i <= 10; $i++) {
  583. $openedDashBoard .= '<div class="box-flex-item filler"></div>';
  584. }
  585. }
  586. $nbworkboardcount = 0;
  587. foreach ($valid_dashboardlines as $infoKey => $board) {
  588. if (in_array($infoKey, $isIntopOpenedDashBoard)) {
  589. // skip if info is present on top
  590. continue;
  591. }
  592. if (empty($board->nbtodo)) {
  593. $nbworkboardempty++;
  594. }
  595. $nbworkboardcount++;
  596. $textlate = $langs->trans("NActionsLate", $board->nbtodolate);
  597. $textlate .= ' ('.$langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($board->warning_delay) >= 0 ? '+' : '').ceil($board->warning_delay).' '.$langs->trans("days").')';
  598. $boxwork .= '<div class="boxstatsindicator thumbstat150 nobold nounderline"><div class="boxstats130 boxstatsborder">';
  599. $boxwork .= '<div class="boxstatscontent">';
  600. $boxwork .= '<span class="boxstatstext" title="'.dol_escape_htmltag($board->label).'">'.$board->img.' <span>'.$board->label.'</span></span><br>';
  601. $boxwork .= '<a class="valignmiddle dashboardlineindicator" href="'.$board->url.'"><span class="dashboardlineindicator'.(($board->nbtodo == 0) ? ' dashboardlineok' : '').'">'.$board->nbtodo.'</span></a>';
  602. if ($board->total > 0 && !empty($conf->global->MAIN_WORKBOARD_SHOW_TOTAL_WO_TAX)) {
  603. $boxwork .= '&nbsp;/&nbsp;<a class="valignmiddle dashboardlineindicator" href="'.$board->url.'"><span class="dashboardlineindicator'.(($board->nbtodo == 0) ? ' dashboardlineok' : '').'">'.price($board->total).'</span></a>';
  604. }
  605. $boxwork .= '</div>';
  606. if ($board->nbtodolate > 0) {
  607. $boxwork .= '<div class="dashboardlinelatecoin nowrap">';
  608. $boxwork .= '<a title="'.dol_escape_htmltag($textlate).'" class="valignmiddle dashboardlineindicatorlate'.($board->nbtodolate > 0 ? ' dashboardlineko' : ' dashboardlineok').'" href="'.((!$board->url_late) ? $board->url : $board->url_late).'">';
  609. //$boxwork .= img_picto($textlate, "warning_white", 'class="valigntextbottom"').'';
  610. $boxwork .= img_picto(
  611. $textlate,
  612. "warning_white",
  613. 'class="inline-block hideonsmartphone valigntextbottom"'
  614. ).'';
  615. $boxwork .= '<span class="dashboardlineindicatorlate'.($board->nbtodolate > 0 ? ' dashboardlineko' : ' dashboardlineok').'">';
  616. $boxwork .= $board->nbtodolate;
  617. $boxwork .= '</span>';
  618. $boxwork .= '</a>';
  619. $boxwork .= '</div>';
  620. }
  621. $boxwork .= '</div></div>';
  622. $boxwork .= "\n";
  623. }
  624. $boxwork .= '<div class="boxstatsindicator thumbstat150 nobold nounderline"><div class="boxstats150empty"></div></div>';
  625. $boxwork .= '<div class="boxstatsindicator thumbstat150 nobold nounderline"><div class="boxstats150empty"></div></div>';
  626. $boxwork .= '<div class="boxstatsindicator thumbstat150 nobold nounderline"><div class="boxstats150empty"></div></div>';
  627. $boxwork .= '<div class="boxstatsindicator thumbstat150 nobold nounderline"><div class="boxstats150empty"></div></div>';
  628. $boxwork .= '</div>';
  629. $boxwork .= '</td></tr>';
  630. } else {
  631. $boxwork .= '<tr class="nohover">';
  632. $boxwork .= '<td class="nohover valignmiddle opacitymedium">';
  633. $boxwork .= $langs->trans("NoOpenedElementToProcess");
  634. $boxwork .= '</td>';
  635. $boxwork .= '</tr>';
  636. }
  637. $boxwork .= '</td></tr>';
  638. $boxwork .= '</table>'; // End table array of working board
  639. $boxwork .= '</div>';
  640. if (!empty($isIntopOpenedDashBoard)) {
  641. print '<div class="fichecenter">';
  642. print '<div class="opened-dash-board-wrap"><div class="box-flex-container">'.$openedDashBoard.'</div></div>';
  643. print '</div>';
  644. }
  645. }
  646. print '<div class="clearboth"></div>';
  647. print '<div class="fichecenter fichecenterbis">';
  648. /*
  649. * Show widgets (boxes)
  650. */
  651. $boxlist = '<div class="twocolumns">';
  652. $boxlist .= '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
  653. if (!empty($nbworkboardcount)) {
  654. $boxlist .= $boxwork;
  655. }
  656. $boxlist .= $resultboxes['boxlista'];
  657. $boxlist .= '</div>';
  658. $boxlist .= '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
  659. $boxlist .= $resultboxes['boxlistb'];
  660. $boxlist .= '</div>';
  661. $boxlist .= "\n";
  662. $boxlist .= '</div>';
  663. print $boxlist;
  664. print '</div>';
  665. //print 'mem='.memory_get_usage().' - '.memory_get_peak_usage();
  666. // End of page
  667. llxFooter();
  668. $db->close();
  669. /**
  670. * Show weather logo. Logo to show depends on $totallate and values for
  671. * $conf->global->MAIN_METEO_LEVELx
  672. *
  673. * @param int $totallate Nb of element late
  674. * @param string $text Text to show on logo
  675. * @param string $options More parameters on img tag
  676. * @param string $morecss More CSS
  677. * @return string Return img tag of weather
  678. */
  679. function showWeather($totallate, $text, $options, $morecss = '')
  680. {
  681. global $conf;
  682. $weather = getWeatherStatus($totallate);
  683. return img_weather($text, $weather->picto, $options, 0, $morecss);
  684. }
  685. /**
  686. * get weather level
  687. * $conf->global->MAIN_METEO_LEVELx
  688. *
  689. * @param int $totallate Nb of element late
  690. * @return stdClass Return img tag of weather
  691. */
  692. function getWeatherStatus($totallate)
  693. {
  694. global $conf;
  695. $weather = new stdClass();
  696. $weather->picto = '';
  697. $offset = 0;
  698. $factor = 10; // By default
  699. $used_conf = empty($conf->global->MAIN_USE_METEO_WITH_PERCENTAGE) ? 'MAIN_METEO_LEVEL' : 'MAIN_METEO_PERCENTAGE_LEVEL';
  700. $level0 = $offset;
  701. $weather->level = 0;
  702. if (!empty($conf->global->{$used_conf.'0'})) {
  703. $level0 = $conf->global->{$used_conf.'0'};
  704. }
  705. $level1 = $offset + 1 * $factor;
  706. if (!empty($conf->global->{$used_conf.'1'})) {
  707. $level1 = $conf->global->{$used_conf.'1'};
  708. }
  709. $level2 = $offset + 2 * $factor;
  710. if (!empty($conf->global->{$used_conf.'2'})) {
  711. $level2 = $conf->global->{$used_conf.'2'};
  712. }
  713. $level3 = $offset + 3 * $factor;
  714. if (!empty($conf->global->{$used_conf.'3'})) {
  715. $level3 = $conf->global->{$used_conf.'3'};
  716. }
  717. if ($totallate <= $level0) {
  718. $weather->picto = 'weather-clear.png';
  719. $weather->level = 0;
  720. } elseif ($totallate <= $level1) {
  721. $weather->picto = 'weather-few-clouds.png';
  722. $weather->level = 1;
  723. } elseif ($totallate <= $level2) {
  724. $weather->picto = 'weather-clouds.png';
  725. $weather->level = 2;
  726. } elseif ($totallate <= $level3) {
  727. $weather->picto = 'weather-many-clouds.png';
  728. $weather->level = 3;
  729. } else {
  730. $weather->picto = 'weather-storm.png';
  731. $weather->level = 4;
  732. }
  733. return $weather;
  734. }