index.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <?php
  2. /* Copyright (C) - 2013-2016 Jean-François FERRY <hello@librethic.io>
  3. * Copyright (C) - 2019 Nicolas ZABOURI <info@inovea-conseil.com>
  4. * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/ticket/agenda.php
  21. * \ingroup ticket
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticketstats.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  29. $hookmanager = new HookManager($db);
  30. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  31. $hookmanager->initHooks(array('ticketsindex'));
  32. // Load translation files required by the page
  33. $langs->loadLangs(array('companies', 'other', 'ticket'));
  34. $WIDTH = DolGraph::getDefaultGraphSizeForStats('width');
  35. $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
  36. // Get parameters
  37. $id = GETPOST('id', 'int');
  38. $msg_id = GETPOST('msg_id', 'int');
  39. $action = GETPOST('action', 'aZ09');
  40. $socid = 0;
  41. if ($user->socid) {
  42. $socid = $user->socid;
  43. }
  44. // Security check
  45. $result = restrictedArea($user, 'ticket', 0, '', '', '', '');
  46. $nowyear = strftime("%Y", dol_now());
  47. $year = GETPOST('year') > 0 ? GETPOST('year') : $nowyear;
  48. $startyear = $year - (empty($conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS) ? 2 : max(1, min(10, $conf->global->MAIN_STATS_GRAPHS_SHOW_N_YEARS)));
  49. $endyear = $year;
  50. $object = new Ticket($db);
  51. /*
  52. * Actions
  53. */
  54. // None
  55. /*
  56. * View
  57. */
  58. $resultboxes = FormOther::getBoxesArea($user, "11"); // Load $resultboxes (selectboxlist + boxactivated + boxlista + boxlistb)
  59. $form = new Form($db);
  60. $tickesupstatic = new Ticket($db);
  61. llxHeader('', $langs->trans('TicketsIndex'), '');
  62. $linkback = '';
  63. print load_fiche_titre($langs->trans('TicketsIndex'), $resultboxes['selectboxlist'], 'ticket');
  64. $dir = '';
  65. $filenamenb = $dir."/".$prefix."ticketinyear-".$endyear.".png";
  66. $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=ticket&amp;file=ticketinyear-'.$endyear.'.png';
  67. $stats = new TicketStats($db, $socid, $userid);
  68. $param_year = 'DOLUSERCOOKIE_ticket_by_status_year';
  69. $param_shownb = 'DOLUSERCOOKIE_ticket_by_status_shownb';
  70. $param_showtot = 'DOLUSERCOOKIE_ticket_by_status_showtot';
  71. $autosetarray = preg_split("/[,;:]+/", GETPOST('DOL_AUTOSET_COOKIE'));
  72. if (in_array('DOLUSERCOOKIE_ticket_by_status', $autosetarray)) {
  73. $endyear = GETPOST($param_year, 'int');
  74. $shownb = GETPOST($param_shownb, 'alpha');
  75. $showtot = GETPOST($param_showtot, 'alpha');
  76. } else {
  77. $tmparray = json_decode($_COOKIE['DOLUSERCOOKIE_ticket_by_status'], true);
  78. $endyear = $tmparray['year'];
  79. $shownb = $tmparray['shownb'];
  80. $showtot = $tmparray['showtot'];
  81. }
  82. if (empty($shownb) && empty($showtot)) {
  83. $showtot = 1;
  84. }
  85. $nowarray = dol_getdate(dol_now(), true);
  86. if (empty($endyear)) {
  87. $endyear = $nowarray['year'];
  88. }
  89. $startyear = $endyear - 1;
  90. // Change default WIDHT and HEIGHT (we need a smaller than default for both desktop and smartphone)
  91. $WIDTH = (($shownb && $showtot) || !empty($conf->dol_optimize_smallscreen)) ? '100%' : '80%';
  92. if (empty($conf->dol_optimize_smallscreen)) {
  93. $HEIGHT = '200';
  94. } else {
  95. $HEIGHT = '160';
  96. }
  97. print '<div class="clearboth"></div>';
  98. print '<div class="fichecenter fichecenterbis">';
  99. print '<div class="twocolumns">';
  100. print '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
  101. /*
  102. * Statistics area
  103. */
  104. $tick = array(
  105. 'unread' => 0,
  106. 'read' => 0,
  107. 'needmoreinfo' => 0,
  108. 'answered' => 0,
  109. 'assigned' => 0,
  110. 'inprogress' => 0,
  111. 'waiting' => 0,
  112. 'closed' => 0,
  113. 'canceled' => 0,
  114. 'deleted' => 0,
  115. );
  116. $sql = "SELECT t.fk_statut, COUNT(t.fk_statut) as nb";
  117. $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
  118. if (!$user->rights->societe->client->voir && !$socid) {
  119. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  120. }
  121. $sql .= ' WHERE t.entity IN ('.getEntity('ticket').')';
  122. $sql .= dolSqlDateFilter('datec', 0, 0, $endyear);
  123. if (!$user->rights->societe->client->voir && !$socid) {
  124. $sql .= " AND t.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  125. }
  126. // External users restriction
  127. if ($user->socid > 0) {
  128. $sql .= " AND t.fk_soc= ".((int) $user->socid);
  129. } else {
  130. // For internals users,
  131. if (!empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY) && !$user->rights->ticket->manage) {
  132. $sql .= " AND t.fk_user_assign = ".((int) $user->id);
  133. }
  134. }
  135. $sql .= " GROUP BY t.fk_statut";
  136. $result = $db->query($sql);
  137. if ($result) {
  138. while ($objp = $db->fetch_object($result)) {
  139. $found = 0;
  140. if ($objp->fk_statut == Ticket::STATUS_NOT_READ) {
  141. $tick['unread'] = $objp->nb;
  142. }
  143. if ($objp->fk_statut == Ticket::STATUS_READ) {
  144. $tick['read'] = $objp->nb;
  145. }
  146. if ($objp->fk_statut == Ticket::STATUS_NEED_MORE_INFO) {
  147. $tick['needmoreinfo'] = $objp->nb;
  148. }
  149. if ($objp->fk_statut == Ticket::STATUS_ASSIGNED) {
  150. $tick['assigned'] = $objp->nb;
  151. }
  152. if ($objp->fk_statut == Ticket::STATUS_IN_PROGRESS) {
  153. $tick['inprogress'] = $objp->nb;
  154. }
  155. if ($objp->fk_statut == Ticket::STATUS_WAITING) {
  156. $tick['waiting'] = $objp->nb;
  157. }
  158. if ($objp->fk_statut == Ticket::STATUS_CLOSED) {
  159. $tick['closed'] = $objp->nb;
  160. }
  161. if ($objp->fk_statut == Ticket::STATUS_CANCELED) {
  162. $tick['canceled'] = $objp->nb;
  163. }
  164. }
  165. include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
  166. $dataseries = array();
  167. $colorseries = array();
  168. $dataseries[] = array('label' => $langs->transnoentitiesnoconv($tickesupstatic->statuts_short[Ticket::STATUS_NOT_READ]), 'data' => round($tick['unread']));
  169. $colorseries[Ticket::STATUS_NOT_READ] = '-'.$badgeStatus0;
  170. $dataseries[] = array('label' => $langs->transnoentitiesnoconv($tickesupstatic->statuts_short[Ticket::STATUS_READ]), 'data' => round($tick['read']));
  171. $colorseries[Ticket::STATUS_READ] = $badgeStatus1;
  172. $dataseries[] = array('label' => $langs->transnoentitiesnoconv($tickesupstatic->statuts_short[Ticket::STATUS_ASSIGNED]), 'data' => round($tick['assigned']));
  173. $colorseries[Ticket::STATUS_ASSIGNED] = $badgeStatus3;
  174. $dataseries[] = array('label' => $langs->transnoentitiesnoconv($tickesupstatic->statuts_short[Ticket::STATUS_IN_PROGRESS]), 'data' => round($tick['inprogress']));
  175. $colorseries[Ticket::STATUS_IN_PROGRESS] = $badgeStatus4;
  176. $dataseries[] = array('label' => $langs->transnoentitiesnoconv($tickesupstatic->statuts_short[Ticket::STATUS_WAITING]), 'data' => round($tick['waiting']));
  177. $colorseries[Ticket::STATUS_WAITING] = '-'.$badgeStatus4;
  178. $dataseries[] = array('label' => $langs->transnoentitiesnoconv($tickesupstatic->statuts_short[Ticket::STATUS_NEED_MORE_INFO]), 'data' => round($tick['needmoreinfo']));
  179. $colorseries[Ticket::STATUS_NEED_MORE_INFO] = '-'.$badgeStatus3;
  180. $dataseries[] = array('label' => $langs->transnoentitiesnoconv($tickesupstatic->statuts_short[Ticket::STATUS_CANCELED]), 'data' => round($tick['canceled']));
  181. $colorseries[Ticket::STATUS_CANCELED] = $badgeStatus9;
  182. $dataseries[] = array('label' => $langs->transnoentitiesnoconv($tickesupstatic->statuts_short[Ticket::STATUS_CLOSED]), 'data' => round($tick['closed']));
  183. $colorseries[Ticket::STATUS_CLOSED] = $badgeStatus6;
  184. } else {
  185. dol_print_error($db);
  186. }
  187. $stringtoshow = '<script type="text/javascript" language="javascript">
  188. jQuery(document).ready(function() {
  189. jQuery("#idsubimgDOLUSERCOOKIE_ticket_by_status").click(function() {
  190. jQuery("#idfilterDOLUSERCOOKIE_ticket_by_status").toggle();
  191. });
  192. });
  193. </script>';
  194. $stringtoshow .= '<div class="center hideobject" id="idfilterDOLUSERCOOKIE_ticket_by_status">'; // hideobject is to start hidden
  195. $stringtoshow .= '<form class="flat formboxfilter" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  196. $stringtoshow .= '<input type="hidden" name="token" value="'.newToken().'">';
  197. $stringtoshow .= '<input type="hidden" name="action" value="refresh">';
  198. $stringtoshow .= '<input type="hidden" name="DOL_AUTOSET_COOKIE" value="DOLUSERCOOKIE_ticket_by_status:year,shownb,showtot">';
  199. $stringtoshow .= $langs->trans("Year").' <input class="flat" size="4" type="text" name="'.$param_year.'" value="'.$endyear.'">';
  200. $stringtoshow .= '<input type="image" alt="'.$langs->trans("Refresh").'" src="'.img_picto($langs->trans("Refresh"), 'refresh.png', '', '', 1).'">';
  201. $stringtoshow .= '</form>';
  202. $stringtoshow .= '</div>';
  203. print '<div class="div-table-responsive-no-min">';
  204. print '<table class="noborder centpercent">';
  205. print '<tr class="liste_titre"><th >'.$langs->trans("Statistics").' '.$endyear.' '.img_picto('', 'filter.png', 'id="idsubimgDOLUSERCOOKIE_ticket_by_status" class="linkobject"').'</th></tr>';
  206. print '<tr><td class="center">';
  207. print $stringtoshow;
  208. // don't display graph if no series
  209. if (!empty($dataseries) && count($dataseries) > 1) {
  210. $totalnb = 0;
  211. foreach ($dataseries as $key => $value) {
  212. $totalnb += $value['data'];
  213. }
  214. $data = array();
  215. foreach ($dataseries as $key => $value) {
  216. $data[] = array($value['label'], $value['data']);
  217. }
  218. $px1 = new DolGraph();
  219. $mesg = $px1->isGraphKo();
  220. if (!$mesg) {
  221. $px1->SetData($data);
  222. $px1->SetDataColor(array_values($colorseries));
  223. unset($data1);
  224. $i = $startyear;
  225. $legend = array();
  226. while ($i <= $endyear) {
  227. $legend[] = $i;
  228. $i++;
  229. }
  230. $px1->setShowLegend(2);
  231. $px1->SetType(array('pie'));
  232. $px1->SetLegend($legend);
  233. $px1->SetMaxValue($px1->GetCeilMaxValue());
  234. //$px1->SetWidth($WIDTH);
  235. $px1->SetHeight($HEIGHT);
  236. $px1->SetYLabel($langs->trans("TicketStatByStatus"));
  237. $px1->SetShading(3);
  238. $px1->SetHorizTickIncrement(1);
  239. $px1->SetCssPrefix("cssboxes");
  240. $px1->mode = 'depth';
  241. //$px1->SetTitle($langs->trans("TicketStatByStatus"));
  242. $px1->draw($filenamenb, $fileurlnb);
  243. print $px1->show($totalnb ? 0 : 1);
  244. }
  245. }
  246. print '</td></tr>';
  247. print '</table>';
  248. print '</div>';
  249. // Build graphic number of object
  250. $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
  251. print '<br>'."\n";
  252. print $resultboxes['boxlista'];
  253. print '</div>'."\n";
  254. print '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
  255. /*
  256. * Latest unread tickets
  257. */
  258. $max = 10;
  259. $sql = "SELECT t.rowid, t.ref, t.track_id, t.datec, t.subject, t.type_code, t.category_code, t.severity_code, t.fk_statut, t.progress,";
  260. $sql .= " type.code as type_code, type.label as type_label,";
  261. $sql .= " category.code as category_code, category.label as category_label,";
  262. $sql .= " severity.code as severity_code, severity.label as severity_label";
  263. $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
  264. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code=t.type_code";
  265. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code=t.category_code";
  266. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code=t.severity_code";
  267. if (!$user->rights->societe->client->voir && !$socid) {
  268. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  269. }
  270. $sql .= ' WHERE t.entity IN ('.getEntity('ticket').')';
  271. $sql .= " AND t.fk_statut=0";
  272. if (!$user->rights->societe->client->voir && !$socid) {
  273. $sql .= " AND t.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  274. }
  275. if ($user->socid > 0) {
  276. $sql .= " AND t.fk_soc= ".((int) $user->socid);
  277. } else {
  278. // Restricted to assigned user only
  279. if (!empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY) && !$user->rights->ticket->manage) {
  280. $sql .= " AND t.fk_user_assign = ".((int) $user->id);
  281. }
  282. }
  283. $sql .= $db->order("t.datec", "DESC");
  284. $sql .= $db->plimit($max, 0);
  285. //print $sql;
  286. $result = $db->query($sql);
  287. if ($result) {
  288. $num = $db->num_rows($result);
  289. $i = 0;
  290. $transRecordedType = $langs->trans("LatestNewTickets", $max);
  291. print '<div class="div-table-responsive-no-min">';
  292. print '<table class="noborder centpercent">';
  293. print '<tr class="liste_titre"><th colspan="5">'.$transRecordedType.'</th>';
  294. print '<th class="right" colspan="2"><a href="'.DOL_URL_ROOT.'/ticket/list.php?search_fk_statut[]='.Ticket::STATUS_NOT_READ.'">'.$langs->trans("FullList").'</th>';
  295. print '</tr>';
  296. if ($num > 0) {
  297. while ($i < $num) {
  298. $objp = $db->fetch_object($result);
  299. $tickesupstatic->id = $objp->rowid;
  300. $tickesupstatic->ref = $objp->ref;
  301. $tickesupstatic->track_id = $objp->track_id;
  302. $tickesupstatic->fk_statut = $objp->fk_statut;
  303. $tickesupstatic->progress = $objp->progress;
  304. $tickesupstatic->subject = $objp->subject;
  305. print '<tr class="oddeven">';
  306. // Ref
  307. print '<td class="nowraponall">';
  308. print $tickesupstatic->getNomUrl(1);
  309. print "</td>\n";
  310. // Creation date
  311. print '<td class="left">';
  312. print dol_print_date($db->jdate($objp->datec), 'dayhour');
  313. print "</td>";
  314. // Subject
  315. print '<td class="nowrap">';
  316. print '<a href="card.php?track_id='.$objp->track_id.'">'.dol_trunc($objp->subject, 30).'</a>';
  317. print "</td>\n";
  318. // Type
  319. print '<td class="nowrap tdoverflowmax100">';
  320. $s = $langs->getLabelFromKey($db, 'TicketTypeShort'.$objp->type_code, 'c_ticket_type', 'code', 'label', $objp->type_code);
  321. print '<span title="'.dol_escape_htmltag($s).'">'.$s.'</span>';
  322. print '</td>';
  323. // Category
  324. print '<td class="nowrap">';
  325. $s = $langs->getLabelFromKey($db, 'TicketCategoryShort'.$objp->category_code, 'c_ticket_category', 'code', 'label', $objp->category_code);
  326. print '<span title="'.dol_escape_htmltag($s).'">'.$s.'</span>';
  327. //print $objp->category_label;
  328. print "</td>";
  329. // Severity
  330. print '<td class="nowrap">';
  331. $s = $langs->getLabelFromKey($db, 'TicketSeverityShort'.$objp->severity_code, 'c_ticket_severity', 'code', 'label', $objp->severity_code);
  332. print '<span title="'.dol_escape_htmltag($s).'">'.$s.'</span>';
  333. //print $objp->severity_label;
  334. print "</td>";
  335. print '<td class="nowraponall right">';
  336. print $tickesupstatic->getLibStatut(5);
  337. print "</td>";
  338. print "</tr>\n";
  339. $i++;
  340. }
  341. $db->free($result);
  342. } else {
  343. print '<tr><td colspan="6"><span class="opacitymedium">'.$langs->trans('NoUnreadTicketsFound').'</span></td></tr>';
  344. }
  345. print "</table>";
  346. print '</div>';
  347. print '<br>';
  348. } else {
  349. dol_print_error($db);
  350. }
  351. print $resultboxes['boxlistb'];
  352. print '</div>';
  353. print '</div>';
  354. print '</div>';
  355. print '<div style="clear:both"></div>';
  356. $parameters = array('user' => $user);
  357. $reshook = $hookmanager->executeHooks('dashboardTickets', $parameters, $object); // Note that $action and $object may have been modified by hook
  358. // End of page
  359. llxFooter('');
  360. $db->close();