card.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  1. <?php
  2. /* Copyright (C) 2013-2016 Jean-François FERRY <hello@librethic.io>
  3. * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
  4. * Copyright (C) 2018 Laurent Destailleur <eldy@users.sourceforge.net>
  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 <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/ticket/card.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 . '/core/class/html.formticket.class.php';
  26. require_once DOL_DOCUMENT_ROOT . '/core/lib/ticket.lib.php';
  27. require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
  28. require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
  29. require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
  30. require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
  31. if (!empty($conf->projet->enabled)) {
  32. include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
  33. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
  34. include_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php';
  35. }
  36. if (!empty($conf->contrat->enabled)) {
  37. include_once DOL_DOCUMENT_ROOT . '/core/lib/contract.lib.php';
  38. include_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php';
  39. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formcontract.class.php';
  40. }
  41. // Load translation files required by the page
  42. $langs->loadLangs(array("companies","other","ticket"));
  43. // Get parameters
  44. $id = GETPOST('id', 'int');
  45. $track_id = GETPOST('track_id', 'alpha', 3);
  46. $ref = GETPOST('ref', 'alpha');
  47. $projectid = GETPOST('projectid', 'int');
  48. $action = GETPOST('action', 'aZ09');
  49. // Initialize technical object to manage hooks of ticket. Note that conf->hooks_modules contains array array
  50. $hookmanager->initHooks(array('ticketcard','globalcard'));
  51. $object = new Ticket($db);
  52. $extrafields = new ExtraFields($db);
  53. // Fetch optionals attributes and labels
  54. $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
  55. $search_array_options=$extrafields->getOptionalsFromPost($object->table_element,'','search_');
  56. // Initialize array of search criterias
  57. $search_all=trim(GETPOST("search_all",'alpha'));
  58. $search=array();
  59. foreach($object->fields as $key => $val)
  60. {
  61. if (GETPOST('search_'.$key,'alpha')) $search[$key]=GETPOST('search_'.$key,'alpha');
  62. }
  63. if (empty($action) && empty($id) && empty($ref)) $action='view';
  64. //Select mail models is same action as add_message
  65. if (GETPOST('modelselected','alpha')) {
  66. $action = 'add_message';
  67. }
  68. // Load object
  69. //include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
  70. if ($id || $track_id || $ref) {
  71. $res = $object->fetch($id, $ref, $track_id);
  72. if ($res >= 0)
  73. {
  74. $id = $object->id;
  75. $track_id = $object->track_id;
  76. }
  77. }
  78. // Store current page url
  79. $url_page_current = DOL_URL_ROOT.'/ticket/card.php';
  80. // Security check - Protection if external user
  81. //if ($user->societe_id > 0) access_forbidden();
  82. //if ($user->societe_id > 0) $socid = $user->societe_id;
  83. $result = restrictedArea($user, 'ticket', $object->id);
  84. $triggermodname = 'TICKETSUP_MODIFY';
  85. $permissiontoadd = $user->rights->ticket->write;
  86. $actionobject = new ActionsTicket($db);
  87. $now = dol_now();
  88. /*
  89. * Actions
  90. */
  91. $parameters=array();
  92. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  93. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  94. if ($cancel)
  95. {
  96. if (! empty($backtopage))
  97. {
  98. header("Location: ".$backtopage);
  99. exit;
  100. }
  101. $action='view';
  102. }
  103. // Do action
  104. $actionobject->doActions($action, $object);
  105. // Action to update one extrafield
  106. if ($action == "update_extras" && ! empty($permissiontoadd))
  107. {
  108. $object->fetch(GETPOST('id','int'), '', GETPOST('track_id','alpha'));
  109. $attributekey = GETPOST('attribute','alpha');
  110. $attributekeylong = 'options_'.$attributekey;
  111. $object->array_options['options_'.$attributekey] = GETPOST($attributekeylong,' alpha');
  112. $result = $object->insertExtraFields(empty($triggermodname)?'':$triggermodname, $user);
  113. if ($result > 0)
  114. {
  115. setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
  116. $action = 'view';
  117. }
  118. else
  119. {
  120. setEventMessages($object->error, $object->errors, 'errors');
  121. $action = 'edit_extras';
  122. }
  123. }
  124. if ($action == "change_property" && GETPOST('btn_update_ticket_prop','alpha') && $user->rights->ticket->write)
  125. {
  126. $object->fetch(GETPOST('id','int'), '', GETPOST('track_id','alpha'));
  127. $object->type_code = GETPOST('update_value_type','az09');
  128. $object->category_code = GETPOST('update_value_category','az09');
  129. $object->severity_code = GETPOST('update_value_severity','az09');
  130. $ret = $object->update($user);
  131. if ($ret > 0) {
  132. $log_action = $langs->trans('TicketLogPropertyChanged', $oldvalue_label, $newvalue_label);
  133. $ret = $object->createTicketLog($user, $log_action);
  134. if ($ret > 0) {
  135. setEventMessages($langs->trans('TicketUpdated'), null, 'mesgs');
  136. }
  137. }
  138. $action = 'view';
  139. }
  140. $permissiondellink = $user->rights->ticket->write;
  141. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
  142. /*
  143. * View
  144. */
  145. $userstat = new User($db);
  146. $form = new Form($db);
  147. $formticket = new FormTicket($db);
  148. if (! empty($conf->projet->enabled)) $formproject = new FormProjets($db);
  149. $help_url = 'FR:DocumentationModuleTicket';
  150. $page_title = $actionobject->getTitle($action);
  151. llxHeader('', $page_title, $help_url);
  152. if (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'dellink' || $action == 'add_message' || $action == 'close' || $action == 'delete' || $action == 'editcustomer' || $action == 'progression' || $action == 'reopen'
  153. || $action == 'editsubject' || $action == 'edit_extras' || $action == 'update_extras' || $action == 'edit_extrafields' || $action == 'set_extrafields' || $action == 'classify' || $action == 'sel_contract' || $action == 'edit_message_init' || $action == 'set_status' || $action == 'dellink')
  154. {
  155. if ($res > 0)
  156. {
  157. // or for unauthorized internals users
  158. if (!$user->societe_id && ($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY && $object->fk_user_assign != $user->id) && !$user->rights->ticket->manage) {
  159. accessforbidden('', 0);
  160. }
  161. // Confirmation close
  162. if ($action == 'close') {
  163. print $form->formconfirm($url_page_current . "?track_id=" . $object->track_id, $langs->trans("CloseATicket"), $langs->trans("ConfirmCloseAticket"), "confirm_close", '', '', 1);
  164. if ($ret == 'html') {
  165. print '<br>';
  166. }
  167. }
  168. // Confirmation delete
  169. if ($action == 'delete') {
  170. print $form->formconfirm($url_page_current . "?track_id=" . $object->track_id, $langs->trans("Delete"), $langs->trans("ConfirmDeleteTicket"), "confirm_delete_ticket", '', '', 1);
  171. }
  172. // Confirm reopen
  173. if ($action == 'reopen') {
  174. print $form->formconfirm($url_page_current . '?track_id=' . $object->track_id, $langs->trans('ReOpen'), $langs->trans('ConfirmReOpenTicket'), 'confirm_reopen', '', '', 1);
  175. }
  176. // Confirmation status change
  177. if ($action == 'set_status') {
  178. $new_status = GETPOST('new_status');
  179. //var_dump($url_page_current . "?track_id=" . $object->track_id);
  180. print $form->formconfirm($url_page_current . "?track_id=" . $object->track_id . "&new_status=" . GETPOST('new_status'), $langs->trans("TicketChangeStatus"), $langs->trans("TicketConfirmChangeStatus", $langs->transnoentities($object->statuts_short[$new_status])), "confirm_set_status", '', '', 1);
  181. }
  182. // project info
  183. if ($projectid) {
  184. $projectstat = new Project($db);
  185. if ($projectstat->fetch($projectid) > 0) {
  186. $projectstat->fetch_thirdparty();
  187. // To verify role of users
  188. //$userAccess = $object->restrictedProjectArea($user,'read');
  189. $userWrite = $projectstat->restrictedProjectArea($user, 'write');
  190. //$userDelete = $object->restrictedProjectArea($user,'delete');
  191. //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
  192. $head = project_prepare_head($projectstat);
  193. dol_fiche_head($head, 'ticket', $langs->trans("Project"), 0, ($projectstat->public ? 'projectpub' : 'project'));
  194. /*
  195. * Projet synthese pour rappel
  196. */
  197. print '<table class="border" width="100%">';
  198. $linkback = '<a href="' . DOL_URL_ROOT . '/projet/list.php">' . $langs->trans("BackToList") . '</a>';
  199. // Ref
  200. print '<tr><td width="30%">' . $langs->trans('Ref') . '</td><td colspan="3">';
  201. // Define a complementary filter for search of next/prev ref.
  202. if (!$user->rights->projet->all->lire) {
  203. $objectsListId = $projectstat->getProjectsAuthorizedForUser($user, $mine, 0);
  204. $projectstat->next_prev_filter = " rowid in (" . (count($objectsListId) ? join(',', array_keys($objectsListId)) : '0') . ")";
  205. }
  206. print $form->showrefnav($projectstat, 'ref', $linkback, 1, 'ref', 'ref', '');
  207. print '</td></tr>';
  208. // Label
  209. print '<tr><td>' . $langs->trans("Label") . '</td><td>' . $projectstat->title . '</td></tr>';
  210. // Customer
  211. print "<tr><td>" . $langs->trans("ThirdParty") . "</td>";
  212. print '<td colspan="3">';
  213. if ($projectstat->thirdparty->id > 0) {
  214. print $projectstat->thirdparty->getNomUrl(1);
  215. } else {
  216. print '&nbsp;';
  217. }
  218. print '</td></tr>';
  219. // Visibility
  220. print '<tr><td>' . $langs->trans("Visibility") . '</td><td>';
  221. if ($projectstat->public) {
  222. print $langs->trans('SharedProject');
  223. } else {
  224. print $langs->trans('PrivateProject');
  225. }
  226. print '</td></tr>';
  227. // Statut
  228. print '<tr><td>' . $langs->trans("Status") . '</td><td>' . $projectstat->getLibStatut(4) . '</td></tr>';
  229. print "</table>";
  230. print '</div>';
  231. } else {
  232. print "ErrorRecordNotFound";
  233. }
  234. } elseif ($socid > 0) {
  235. $object->fetch_thirdparty();
  236. $head = societe_prepare_head($object->thirdparty);
  237. dol_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
  238. dol_banner_tab($object->thirdparty, 'socid', '', ($user->societe_id ? 0 : 1), 'rowid', 'nom');
  239. dol_fiche_end();
  240. }
  241. if (!$user->societe_id && $conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY) {
  242. $object->next_prev_filter = "te.fk_user_assign = '" . $user->id . "'";
  243. } elseif ($user->societe_id > 0) {
  244. $object->next_prev_filter = "te.fk_soc = '" . $user->societe_id . "'";
  245. }
  246. $head = ticket_prepare_head($object);
  247. dol_fiche_head($head, 'tabTicket', $langs->trans("Ticket"), -1, 'ticket');
  248. $morehtmlref ='<div class="refidno">';
  249. $morehtmlref.= $object->subject;
  250. // Author
  251. if ($object->fk_user_create > 0) {
  252. $morehtmlref .= '<br>' . $langs->trans("CreatedBy") . ' : ';
  253. $langs->load("users");
  254. $fuser = new User($db);
  255. $fuser->fetch($object->fk_user_create);
  256. $morehtmlref .= $fuser->getNomUrl(0);
  257. }
  258. if (!empty($object->origin_email)) {
  259. $morehtmlref .= '<br>' . $langs->trans("CreatedBy") . ' : ';
  260. $morehtmlref .= $object->origin_email . ' <small>(' . $langs->trans("TicketEmailOriginIssuer") . ')</small>';
  261. }
  262. // Thirdparty
  263. if (! empty($conf->societe->enabled))
  264. {
  265. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' ';
  266. if ($action != 'editcustomer' && $object->fk_statut < 8 && !$user->societe_id && $user->rights->ticket->write) {
  267. $morehtmlref.='<a href="' . $url_page_current . '?action=editcustomer&amp;track_id=' . $object->track_id . '">' . img_edit($langs->transnoentitiesnoconv('Edit'), 1) . '</a> : ';
  268. }
  269. if ($action == 'editcustomer') {
  270. $morehtmlref.=$form->form_thirdparty($url_page_current . '?track_id=' . $object->track_id, $object->socid, 'editcustomer', '', 1, 0, 0, array(), 1);
  271. } else {
  272. $morehtmlref.=$form->form_thirdparty($url_page_current . '?track_id=' . $object->track_id, $object->socid, 'none', '', 1, 0, 0, array(), 1);
  273. }
  274. }
  275. // Project
  276. if (! empty($conf->projet->enabled))
  277. {
  278. $langs->load("projects");
  279. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  280. if ($user->rights->ticket->write)
  281. {
  282. if ($action != 'classify')
  283. $morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  284. if ($action == 'classify') {
  285. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  286. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  287. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  288. $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  289. $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1);
  290. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  291. $morehtmlref.='</form>';
  292. } else {
  293. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  294. }
  295. } else {
  296. if (! empty($object->fk_project)) {
  297. $proj = new Project($db);
  298. $proj->fetch($object->fk_project);
  299. $morehtmlref.=$proj->getNomUrl(1);
  300. } else {
  301. $morehtmlref.='';
  302. }
  303. }
  304. }
  305. $morehtmlref.='</div>';
  306. $linkback = '<a href="' . dol_buildpath('/ticket/list.php', 1) . '"><strong>' . $langs->trans("BackToList") . '</strong></a> ';
  307. dol_banner_tab($object, 'ref', $linkback, ($user->societe_id ? 0 : 1), 'ref', 'ref', $morehtmlref);
  308. print '<div class="fichecenter"><div class="fichehalfleft">';
  309. print '<div class="underbanner clearboth"></div>';
  310. print '<table class="border centpercent">';
  311. // Track ID
  312. print '<tr><td class="titlefield">' . $langs->trans("TicketTrackId") . '</td><td>';
  313. if (!empty($object->track_id)) {
  314. if (empty($object->ref)) {
  315. $object->ref = $object->id;
  316. print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'track_id');
  317. } else {
  318. print $object->track_id;
  319. }
  320. } else {
  321. print $langs->trans('None');
  322. }
  323. print '</td></tr>';
  324. // Subject
  325. print '<tr><td>';
  326. print $form->editfieldkey("Subject", 'subject', $object->subject, $object, $user->rights->ticket->write && !$user->societe_id, 'string');
  327. print '</td><td>';
  328. print $form->editfieldval("Subject", 'subject', $object->subject, $object, $user->rights->ticket->write && !$user->societe_id, 'string');
  329. print '</td></tr>';
  330. // Creation date
  331. print '<tr><td>' . $langs->trans("DateCreation") . '</td><td>';
  332. print dol_print_date($object->datec, 'dayhour');
  333. print ' - '.$langs->trans("TimeElapsedSince").': '.'<i>'.convertSecondToTime(roundUpToNextMultiple($now - $object->datec, 60)).'</i>';
  334. print '</td></tr>';
  335. // Read date
  336. print '<tr><td>' . $langs->trans("TicketReadOn") . '</td><td>';
  337. if (!empty($object->date_read)) {
  338. print dol_print_date($object->date_read, 'dayhour');
  339. print ' - '.$langs->trans("TicketTimeToRead").': <i>'.convertSecondToTime(roundUpToNextMultiple($object->date_read - $object->datec, 60)).'</i>';
  340. print ' - '.$langs->trans("TimeElapsedSince").': '.'<i>'.convertSecondToTime(roundUpToNextMultiple($now - $object->date_read, 60)).'</i>';
  341. }
  342. print '</td></tr>';
  343. // Close date
  344. print '<tr><td>' . $langs->trans("TicketCloseOn") . '</td><td>';
  345. if (!empty($object->date_close)) {
  346. print dol_print_date($object->date_close, 'dayhour');
  347. }
  348. print '</td></tr>';
  349. // User assigned
  350. print '<tr><td>' . $langs->trans("AssignedTo") . '</td><td>';
  351. if ($object->fk_user_assign > 0) {
  352. $userstat->fetch($object->fk_user_assign);
  353. print $userstat->getNomUrl(1);
  354. } else {
  355. print $langs->trans('None');
  356. }
  357. // Show user list to assignate one if status is "read"
  358. if (GETPOST('set','alpha') == "assign_ticket" && $object->fk_statut < 8 && !$user->societe_id && $user->rights->ticket->write) {
  359. print '<form method="post" name="ticket" enctype="multipart/form-data" action="' . $url_page_current . '">';
  360. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  361. print '<input type="hidden" name="action" value="assign_user">';
  362. print '<input type="hidden" name="track_id" value="' . $object->track_id . '">';
  363. print '<label for="fk_user_assign">' . $langs->trans("AssignUser") . '</label> ';
  364. print $form->select_dolusers($user->id, 'fk_user_assign', 1);
  365. print ' <input class="button" type="submit" name="btn_assign_user" value="' . $langs->trans("Validate") . '" />';
  366. print '</form>';
  367. }
  368. if ($object->fk_statut < 8 && GETPOST('set','alpha') != "assign_ticket" && $user->rights->ticket->manage) {
  369. print '<a href="' . $url_page_current . '?track_id=' . $object->track_id . '&action=view&set=assign_ticket">' . img_picto('', 'edit') . ' ' . $langs->trans('Modify') . '</a>';
  370. }
  371. print '</td></tr>';
  372. // Progression
  373. print '<tr><td>';
  374. print '<table class="nobordernopadding" width="100%"><tr><td class="nowrap">';
  375. print $langs->trans('Progression') . '</td><td align="left">';
  376. print '</td>';
  377. if ($action != 'progression' && $object->fk_statut < 8 && !$user->societe_id) {
  378. print '<td align="right"><a href="' . $url_page_current . '?action=progression&amp;track_id=' . $object->track_id . '">' . img_edit($langs->trans('Modify')) . '</a></td>';
  379. }
  380. print '</tr></table>';
  381. print '</td><td colspan="5">';
  382. if ($user->rights->ticket->write && $action == 'progression') {
  383. print '<form action="' . $url_page_current . '" method="post">';
  384. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  385. print '<input type="hidden" name="track_id" value="' . $track_id . '">';
  386. print '<input type="hidden" name="action" value="set_progression">';
  387. print '<input type="text" class="flat" size="20" name="progress" value="' . $object->progress . '">';
  388. print ' <input type="submit" class="button" value="' . $langs->trans('Modify') . '">';
  389. print '</form>';
  390. } else {
  391. print($object->progress > 0 ? $object->progress : '0') . '%';
  392. }
  393. print '</td>';
  394. print '</tr>';
  395. // Timing (Duration sum of linked fichinter)
  396. if ($conf->fichinter->enabled)
  397. {
  398. $object->fetchObjectLinked();
  399. $num = count($object->linkedObjects);
  400. $timing = 0;
  401. if ($num) {
  402. foreach ($object->linkedObjects as $objecttype => $objects) {
  403. if ($objecttype = "fichinter") {
  404. foreach ($objects as $fichinter) {
  405. $timing += $fichinter->duration;
  406. }
  407. }
  408. }
  409. }
  410. print '<tr><td valign="top">';
  411. print $form->textwithpicto($langs->trans("TicketDurationAuto"), $langs->trans("TicketDurationAutoInfos"), 1);
  412. print '</td><td>';
  413. print convertSecondToTime($timing, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
  414. print '</td></tr>';
  415. }
  416. // Other attributes
  417. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  418. print '</table>';
  419. // Fin colonne gauche et début colonne droite
  420. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  421. // View Original message
  422. $actionobject->viewTicketOriginalMessage($user, $action, $object);
  423. /***************************************************
  424. *
  425. * Classification and actions on ticket
  426. *
  427. ***************************************************/
  428. print '<form method="post" name="formticketproperties" action="' . $url_page_current . '">';
  429. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  430. print '<input type="hidden" name="action" value="change_property">';
  431. print '<input type="hidden" name="property" value="' . $property['dict'] . '">';
  432. print '<input type="hidden" name="track_id" value="' . $track_id . '">';
  433. print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  434. print '<table class="border centpercent margintable">';
  435. print '<tr class="liste_titre">';
  436. print '<td>';
  437. print $langs->trans('Properties');
  438. print '</td>';
  439. print '<td>';
  440. if (GETPOST('set','alpha') == 'properties' && $user->rights->ticket->write) {
  441. print '<input class="button" type="submit" name="btn_update_ticket_prop" value="' . $langs->trans("Modify") . '" />';
  442. }
  443. else {
  444. // Button to edit Properties
  445. if ($object->fk_statut < 5 && $user->rights->ticket->write) {
  446. print '<a href="card.php?track_id=' . $object->track_id . '&action=view&set=properties">' . img_edit($langs->trans('Modify')) . '</a>';
  447. }
  448. }
  449. print '</td>';
  450. print '</tr>';
  451. if (GETPOST('set','alpha') == 'properties' && $user->rights->ticket->write) {
  452. print '<tr>';
  453. print '<td class="titlefield">';
  454. print $langs->trans('TicketChangeType');
  455. print '</td><td>';
  456. print $formticket->selectTypesTickets($object->type_code, 'update_value_type', '', 2);
  457. print '</td>';
  458. print '</tr>';
  459. print '<tr>';
  460. print '<td>';
  461. print $langs->trans('TicketChangeCategory');
  462. print '</td><td>';
  463. print $formticket->selectCategoriesTickets($object->category_code, 'update_value_category', '', 2);
  464. print '</td>';
  465. print '</tr>';
  466. print '<tr>';
  467. print '<td>';
  468. print $langs->trans('TicketChangeSeverity');
  469. print '</td><td>';
  470. print $formticket->selectSeveritiesTickets($object->severity_code, 'update_value_severity', '', 2);
  471. print '</td>';
  472. print '</tr>';
  473. } else {
  474. // Type
  475. print '<tr><td class="titlefield">' . $langs->trans("Type") . '</td><td>';
  476. print $langs->getLabelFromKey($db, $object->type_code, 'c_ticket_type', 'code', 'label');
  477. /*if ($user->admin && !$noadmininfo) {
  478. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  479. }*/
  480. print '</td></tr>';
  481. // Category
  482. print '<tr><td>' . $langs->trans("Category") . '</td><td>';
  483. print $langs->getLabelFromKey($db, $object->category_code, 'c_ticket_category', 'code', 'label');
  484. /*if ($user->admin && !$noadmininfo) {
  485. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  486. }*/
  487. print '</td></tr>';
  488. // Severity
  489. print '<tr><td>' . $langs->trans("TicketSeverity") . '</td><td>';
  490. print $langs->getLabelFromKey($db, $object->severity_code, 'c_ticket_severity', 'code', 'label');
  491. /*if ($user->admin && !$noadmininfo) {
  492. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  493. }*/
  494. print '</td></tr>';
  495. }
  496. print '</table>'; // End table actions
  497. print '</form>';
  498. print '</div>';
  499. // Display navbar with links to change ticket status
  500. print '<!-- navbar with status -->';
  501. if (!$user->societe_id && $user->rights->ticket->write && $object->fk_status < 8 && GETPOST('set') !== 'properties') {
  502. $actionobject->viewStatusActions($object);
  503. }
  504. if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
  505. {
  506. print load_fiche_titre($langs->trans('Contacts'), '', 'title_companies.png');
  507. print '<div class="div-table-responsive-no-min">';
  508. print '<div class="tagtable centpercent noborder allwidth">';
  509. print '<div class="tagtr liste_titre">';
  510. print '<div class="tagtd">' . $langs->trans("Source") . '</div>
  511. <div class="tagtd">' . $langs->trans("Company") . '</div>
  512. <div class="tagtd">' . $langs->trans("Contacts") . '</div>
  513. <div class="tagtd">' . $langs->trans("ContactType") . '</div>
  514. <div class="tagtd">' . $langs->trans("Phone") . '</div>
  515. <div class="tagtd" align="center">' . $langs->trans("Status") . '</div>';
  516. print '</div><!-- tagtr -->';
  517. // Contact list
  518. $companystatic = new Societe($db);
  519. $contactstatic = new Contact($db);
  520. $userstatic = new User($db);
  521. foreach (array('internal', 'external') as $source) {
  522. $tmpobject = $object;
  523. $tab = $tmpobject->listeContact(-1, $source);
  524. $num = count($tab);
  525. $i = 0;
  526. while ($i < $num) {
  527. $var = !$var;
  528. print '<div class="tagtr ' . ($var ? 'pair' : 'impair') . '">';
  529. print '<div class="tagtd" align="left">';
  530. if ($tab[$i]['source'] == 'internal') {
  531. echo $langs->trans("User");
  532. }
  533. if ($tab[$i]['source'] == 'external') {
  534. echo $langs->trans("ThirdPartyContact");
  535. }
  536. print '</div>';
  537. print '<div class="tagtd" align="left">';
  538. if ($tab[$i]['socid'] > 0) {
  539. $companystatic->fetch($tab[$i]['socid']);
  540. echo $companystatic->getNomUrl(1);
  541. }
  542. if ($tab[$i]['socid'] < 0) {
  543. echo $conf->global->MAIN_INFO_SOCIETE_NOM;
  544. }
  545. if (!$tab[$i]['socid']) {
  546. echo '&nbsp;';
  547. }
  548. print '</div>';
  549. print '<div class="tagtd">';
  550. if ($tab[$i]['source'] == 'internal') {
  551. if ($userstatic->fetch($tab[$i]['id'])) {
  552. print $userstatic->getNomUrl(1);
  553. }
  554. }
  555. if ($tab[$i]['source'] == 'external') {
  556. if ($contactstatic->fetch($tab[$i]['id'])) {
  557. print $contactstatic->getNomUrl(1);
  558. }
  559. }
  560. print ' </div>
  561. <div class="tagtd">' . $tab[$i]['libelle'] . '</div>';
  562. print '<div class="tagtd">';
  563. print dol_print_phone($tab[$i]['phone'], '', '', '', 'AC_TEL').'<br>';
  564. if (! empty($tab[$i]['phone_perso'])) {
  565. //print img_picto($langs->trans('PhonePerso'),'object_phoning.png','',0,0,0).' ';
  566. print '<br>'.dol_print_phone($tab[$i]['phone_perso'], '', '', '', 'AC_TEL').'<br>';
  567. }
  568. if (! empty($tab[$i]['phone_mobile'])) {
  569. //print img_picto($langs->trans('PhoneMobile'),'object_phoning.png','',0,0,0).' ';
  570. print dol_print_phone($tab[$i]['phone_mobile'], '', '', '', 'AC_TEL').'<br>';
  571. }
  572. print '</div>';
  573. print '<div class="tagtd" align="center">';
  574. if ($object->statut >= 0) {
  575. echo '<a href="contact.php?track_id=' . $object->track_id . '&amp;action=swapstatut&amp;ligne=' . $tab[$i]['rowid'] . '">';
  576. }
  577. if ($tab[$i]['source'] == 'internal') {
  578. $userstatic->id = $tab[$i]['id'];
  579. $userstatic->lastname = $tab[$i]['lastname'];
  580. $userstatic->firstname = $tab[$i]['firstname'];
  581. echo $userstatic->LibStatut($tab[$i]['statuscontact'], 3);
  582. }
  583. if ($tab[$i]['source'] == 'external') {
  584. $contactstatic->id = $tab[$i]['id'];
  585. $contactstatic->lastname = $tab[$i]['lastname'];
  586. $contactstatic->firstname = $tab[$i]['firstname'];
  587. echo $contactstatic->LibStatut($tab[$i]['statuscontact'], 3);
  588. }
  589. if ($object->statut >= 0) {
  590. echo '</a>';
  591. }
  592. print '</div>';
  593. print '</div><!-- tagtr -->';
  594. $i++;
  595. }
  596. }
  597. print '</div><!-- contact list -->';
  598. print '</div>';
  599. }
  600. print '</div></div></div>';
  601. print '<div style="clear:both"></div>';
  602. dol_fiche_end();
  603. // Buttons for actions
  604. if ($action != 'presend' && $action != 'editline') {
  605. print '<div class="tabsAction">'."\n";
  606. $parameters=array();
  607. $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  608. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  609. if (empty($reshook))
  610. {
  611. // Show link to add a message (if read and not closed)
  612. if ($object->fk_statut < 8 && $action != "add_message") {
  613. print '<div class="inline-block divButAction"><a class="butAction" href="card.php?track_id=' . $object->track_id . '&action=add_message">' . $langs->trans('TicketAddMessage') . '</a></div>';
  614. }
  615. // Link to create an intervention
  616. // socid is needed otherwise fichinter ask it and forgot origin after form submit :\
  617. if (!$object->fk_soc && $user->rights->ficheinter->creer) {
  618. print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="' . $langs->trans('UnableToCreateInterIfNoSocid') . '">' . $langs->trans('TicketAddIntervention') . '</a></div>';
  619. }
  620. if ($object->fk_soc > 0 && $object->fk_statut < 8 && $user->rights->ficheinter->creer) {
  621. print '<div class="inline-block divButAction"><a class="butAction" href="' . dol_buildpath('/fichinter/card.php', 1) . '?action=create&socid=' . $object->fk_soc . '&origin=ticket_ticket&originid=' . $object->id . '">' . $langs->trans('TicketAddIntervention') . '</a></div>';
  622. }
  623. // Close ticket if statut is read
  624. if ($object->fk_statut > 0 && $object->fk_statut < 8 && $user->rights->ticket->write) {
  625. print '<div class="inline-block divButAction"><a class="butAction" href="card.php?track_id=' . $object->track_id . '&action=close">' . $langs->trans('CloseTicket') . '</a></div>';
  626. }
  627. // Re-open ticket
  628. if (!$user->socid && $object->fk_statut == 8 && !$user->societe_id) {
  629. print '<div class="inline-block divButAction"><a class="butAction" href="card.php?track_id=' . $object->track_id . '&action=reopen">' . $langs->trans('ReOpen') . '</a></div>';
  630. }
  631. // Delete ticket
  632. if ($user->rights->ticket->delete && !$user->societe_id) {
  633. print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?track_id=' . $object->track_id . '&action=delete">' . $langs->trans('Delete') . '</a></div>';
  634. }
  635. }
  636. print '</div>'."\n";
  637. }
  638. // Select mail models is same action as presend
  639. if (GETPOST('modelselected')) {
  640. $action = 'presend';
  641. }
  642. if (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'dellink' || $action == 'edit_message_init')
  643. {
  644. print '<div class="fichecenter"><div class="fichehalfleft">';
  645. print '<a name="builddoc"></a>'; // ancre
  646. // Show links to link elements
  647. $linktoelem = $form->showLinkToObjectBlock($object, null, array('ticket'));
  648. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  649. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  650. // Message list
  651. print load_fiche_titre($langs->trans('TicketMessagesList'), '', 'messages@ticket');
  652. $show_private_message = ($user->societe_id ? 0 : 1);
  653. $actionobject->viewTicketTimelineMessages($show_private_message, true, $object);
  654. print '</div></div>';
  655. print '</div><!-- fichecenter -->';
  656. print '<br style="clear: both">';
  657. }
  658. elseif ($action == 'add_message')
  659. {
  660. $action='new_message';
  661. $modelmail='ticket_send';
  662. print '<div>';
  663. print load_fiche_titre($langs->trans('TicketAddMessage'), '', 'messages@ticket');
  664. // Define output language
  665. $outputlangs = $langs;
  666. $newlang = '';
  667. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) {
  668. $newlang = $_REQUEST['lang_id'];
  669. }
  670. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
  671. $newlang = $object->default_lang;
  672. }
  673. $formticket = new FormTicket($db);
  674. $formticket->action = $action;
  675. $formticket->track_id = $object->track_id;
  676. $formticket->id = $object->id;
  677. $formticket->withfile = 2;
  678. $formticket->param = array('fk_user_create' => $user->id);
  679. $formticket->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang);
  680. // Tableau des parametres complementaires du post
  681. $formticket->param['models']=$modelmail;
  682. $formticket->param['models_id']=GETPOST('modelmailselected', 'int');
  683. //$formticket->param['socid']=$object->fk_soc;
  684. $formticket->param['returnurl']=$_SERVER["PHP_SELF"].'?track_id='.$object->track_id;
  685. $formticket->withsubstit = 1;
  686. if ($object->fk_soc > 0) {
  687. $object->fetch_thirdparty();
  688. $formticket->substit['__THIRDPARTY_NAME__'] = $object->thirdparty->name;
  689. }
  690. $formticket->substit['__SIGNATURE__'] = $user->signature;
  691. $formticket->substit['__TICKETSUP_TRACKID__'] = $object->track_id;
  692. $formticket->substit['__TICKETSUP_REF__'] = $object->ref;
  693. $formticket->substit['__TICKETSUP_SUBJECT__'] = $object->subject;
  694. $formticket->substit['__TICKETSUP_TYPE__'] = $object->type_code;
  695. $formticket->substit['__TICKETSUP_CATEGORY__'] = $object->category_code;
  696. $formticket->substit['__TICKETSUP_SEVERITY__'] = $object->severity_code;
  697. $formticket->substit['__TICKETSUP_MESSAGE__'] = $object->message;
  698. $formticket->substit['__TICKETSUP_PROGRESSION__'] = $object->progress;
  699. if ($object->fk_user_assign > 0) {
  700. $userstat->fetch($object->fk_user_assign);
  701. $formticket->substit['__TICKETSUP_USER_ASSIGN__'] = dolGetFirstLastname($userstat->firstname, $userstat->lastname);
  702. }
  703. if ($object->fk_user_create > 0) {
  704. $userstat->fetch($object->fk_user_create);
  705. $formticket->substit['__TICKETSUP_USER_CREATE__'] = dolGetFirstLastname($userstat->firstname, $userstat->lastname);
  706. }
  707. $formticket->showMessageForm('100%');
  708. print '</div>';
  709. }
  710. }
  711. }
  712. // End of page
  713. llxFooter();
  714. $db->close();