index.php 15 KB

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