index.php 33 KB

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