index.php 15 KB

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