card.php 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646
  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. * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
  6. * Copyright (C) 2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  7. * Copyright (C) 2022-2023 Charlene Benke <charlene@patas-monkey.com>
  8. * Copyright (C) 2023 Benjamin Falière <benjamin.faliere@altairis.fr>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/ticket/card.php
  25. * \ingroup ticket
  26. * \brief Page to create/edit/view Tickets
  27. */
  28. // Load Dolibarr environment
  29. require '../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticket.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  38. if (isModEnabled('project')) {
  39. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  40. include_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  41. include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  42. }
  43. if (isModEnabled('contrat')) {
  44. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formcontract.class.php';
  45. include_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php';
  46. include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  47. }
  48. // Load translation files required by the page
  49. $langs->loadLangs(array("companies", "other", "ticket"));
  50. // Get parameters
  51. $id = GETPOST('id', 'int');
  52. $ref = GETPOST('ref', 'alpha');
  53. $track_id = GETPOST('track_id', 'alpha', 3);
  54. $socid = GETPOST('socid', 'int');
  55. $contactid = GETPOST('contactid', 'int');
  56. $projectid = GETPOST('projectid', 'int');
  57. $notifyTiers = GETPOST("notify_tiers_at_create", 'alpha');
  58. $action = GETPOST('action', 'aZ09');
  59. $cancel = GETPOST('cancel', 'alpha');
  60. $backtopage = GETPOST('backtopage', 'alpha');
  61. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  62. $sortfield = GETPOST('sortfield', 'aZ09comma') ? GETPOST('sortfield', 'aZ09comma') : "a.datep";
  63. $sortorder = GETPOST('sortorder', 'aZ09comma') ? GETPOST('sortorder', 'aZ09comma') : "desc";
  64. $search_rowid = GETPOST('search_rowid');
  65. $search_agenda_label = GETPOST('search_agenda_label');
  66. if (GETPOST('actioncode', 'array')) {
  67. $actioncode = GETPOST('actioncode', 'array', 3);
  68. if (!count($actioncode)) {
  69. $actioncode = '0';
  70. }
  71. } else {
  72. $actioncode = GETPOST("actioncode", "alpha", 3) ? GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT'));
  73. }
  74. // Initialize technical object to manage hooks of ticket. Note that conf->hooks_modules contains array array
  75. $hookmanager->initHooks(array('ticketcard', 'globalcard'));
  76. $object = new Ticket($db);
  77. $extrafields = new ExtraFields($db);
  78. // Fetch optionals attributes and labels
  79. $extrafields->fetch_name_optionals_label($object->table_element);
  80. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  81. // Initialize array of search criterias
  82. $search_all = GETPOST("search_all", 'alpha');
  83. $search = array();
  84. foreach ($object->fields as $key => $val) {
  85. if (GETPOST('search_'.$key, 'alpha')) {
  86. $search[$key] = GETPOST('search_'.$key, 'alpha');
  87. }
  88. }
  89. if (empty($action) && empty($id) && empty($ref)) {
  90. $action = 'view';
  91. }
  92. // Select mail models is same action as add_message
  93. if (GETPOST('modelselected', 'alpha')) {
  94. $action = 'presend';
  95. }
  96. // Load object
  97. //include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
  98. if ($id || $track_id || $ref) {
  99. $res = $object->fetch($id, $ref, $track_id);
  100. if ($res >= 0) {
  101. $id = $object->id;
  102. $track_id = $object->track_id;
  103. }
  104. }
  105. $now = dol_now();
  106. $actionobject = new ActionsTicket($db);
  107. // Store current page url
  108. $url_page_current = DOL_URL_ROOT.'/ticket/card.php';
  109. // Security check - Protection if external user
  110. if ($user->socid > 0) {
  111. $socid = $user->socid;
  112. }
  113. $result = restrictedArea($user, 'ticket', $object->id);
  114. $triggermodname = 'TICKET_MODIFY';
  115. // Permissions
  116. $permissiontoread = $user->hasRight('ticket', 'read');
  117. $permissiontoadd = $user->hasRight('ticket', 'write');
  118. $permissiontodelete = $user->hasRight('ticket', 'delete');
  119. $upload_dir = $conf->ticket->dir_output;
  120. /*
  121. * Actions
  122. */
  123. $parameters = array();
  124. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  125. if ($reshook < 0) {
  126. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  127. }
  128. $error = 0;
  129. if (empty($reshook)) {
  130. // Purge search criteria
  131. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers{
  132. $actioncode = '';
  133. $search_agenda_label = '';
  134. }
  135. $backurlforlist = DOL_URL_ROOT.'/ticket/list.php';
  136. if (empty($backtopage) || ($cancel && empty($id))) {
  137. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  138. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  139. $backtopage = $backurlforlist;
  140. } else {
  141. $backtopage = DOL_URL_ROOT.'/ticket/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
  142. }
  143. }
  144. }
  145. if ($cancel) {
  146. if (!empty($backtopageforcancel)) {
  147. header("Location: ".$backtopageforcancel);
  148. exit;
  149. } elseif (!empty($backtopage)) {
  150. header("Location: ".$backtopage);
  151. exit;
  152. }
  153. $action = 'view';
  154. }
  155. // Action to add an action (not a message)
  156. if (GETPOST('save', 'alpha') && $permissiontoadd) {
  157. $error = 0;
  158. if (!GETPOST("type_code", 'alpha')) {
  159. $error++;
  160. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("TicketTypeRequest")), null, 'errors');
  161. $action = 'create';
  162. } elseif (!GETPOST("category_code", 'alpha')) {
  163. $error++;
  164. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("TicketCategory")), null, 'errors');
  165. $action = 'create';
  166. } elseif (!GETPOST("severity_code", 'alpha')) {
  167. $error++;
  168. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("TicketSeverity")), null, 'errors');
  169. $action = 'create';
  170. } elseif (!GETPOST("subject", 'alphanohtml')) {
  171. $error++;
  172. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Subject")), null, 'errors');
  173. $action = 'create';
  174. } elseif (!GETPOST("message", 'restricthtml')) {
  175. $error++;
  176. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Message")), null, 'errors');
  177. $action = 'create';
  178. }
  179. $ret = $extrafields->setOptionalsFromPost(null, $object);
  180. if ($ret < 0) {
  181. $error++;
  182. }
  183. if (!$error) {
  184. $db->begin();
  185. $getRef = GETPOST("ref", 'alphanohtml');
  186. $test = new Ticket($db);
  187. if ($test->fetch('', $getRef) > 0) {
  188. $object->ref = $object->getDefaultRef();
  189. $object->track_id = null;
  190. setEventMessage($langs->trans('TicketRefAlreadyUsed', $getRef, $object->ref));
  191. } else {
  192. $object->ref = $getRef;
  193. }
  194. $object->fk_soc = $object->socid = GETPOST("socid", 'int') > 0 ? GETPOST("socid", 'int') : 0;
  195. $object->subject = GETPOST("subject", 'alphanohtml');
  196. $object->message = GETPOST("message", 'restricthtml');
  197. $object->type_code = GETPOST("type_code", 'alpha');
  198. $object->type_label = $langs->trans($langs->getLabelFromKey($db, $object->type_code, 'c_ticket_type', 'code', 'label'));
  199. $object->category_code = GETPOST("category_code", 'alpha');
  200. $object->category_label = $langs->trans($langs->getLabelFromKey($db, $object->category_code, 'c_ticket_category', 'code', 'label'));
  201. $object->severity_code = GETPOST("severity_code", 'alpha');
  202. $object->severity_label = $langs->trans($langs->getLabelFromKey($db, $object->severity_code, 'c_ticket_severity', 'code', 'label'));
  203. $object->fk_user_create = $user->id;
  204. $object->email_from = $user->email;
  205. $object->origin_email = null;
  206. $notifyTiers = GETPOST("notify_tiers_at_create", 'alpha');
  207. $object->notify_tiers_at_create = empty($notifyTiers) ? 0 : 1;
  208. $fk_user_assign = GETPOST("fk_user_assign", 'int');
  209. if ($fk_user_assign > 0) {
  210. $object->fk_user_assign = $fk_user_assign;
  211. $object->status = $object::STATUS_ASSIGNED;
  212. }
  213. $object->fk_project = $projectid;
  214. $object->fk_contract = GETPOST('fk_contract', 'int');
  215. $id = $object->create($user);
  216. if ($id <= 0) {
  217. $error++;
  218. setEventMessages($object->error, $object->errors, 'errors');
  219. $action = 'create';
  220. }
  221. if (!$error) {
  222. // Add contact
  223. $contactid = GETPOST('contactid', 'int');
  224. $type_contact = GETPOST("type", 'alpha');
  225. // Category association
  226. $categories = GETPOST('categories', 'array');
  227. $object->setCategories($categories);
  228. if ($contactid > 0 && $type_contact) {
  229. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  230. $result = $object->add_contact($contactid, $typeid, 'external');
  231. }
  232. // Link ticket to project
  233. if (GETPOST('origin', 'alpha') == 'projet') {
  234. $projectid = GETPOST('originid', 'int');
  235. } else {
  236. $projectid = GETPOST('projectid', 'int');
  237. }
  238. if ($projectid > 0) {
  239. $object->setProject($projectid);
  240. }
  241. // Auto mark as read if created from backend
  242. if (getDolGlobalString('TICKET_AUTO_READ_WHEN_CREATED_FROM_BACKEND') && $user->hasRight('ticket', 'write')) {
  243. if (! $object->markAsRead($user) > 0) {
  244. setEventMessages($object->error, $object->errors, 'errors');
  245. }
  246. }
  247. // Auto assign user
  248. if (getDolGlobalString('TICKET_AUTO_ASSIGN_USER_CREATE')) {
  249. $result = $object->assignUser($user, $user->id, 1);
  250. $object->add_contact($user->id, "SUPPORTTEC", 'internal');
  251. }
  252. }
  253. if (!$error) {
  254. // File transfer
  255. $object->copyFilesForTicket(''); // trackid is forced to '' because files were uploaded when no id for ticket exists yet and trackid was ''
  256. }
  257. if (!$error) {
  258. $db->commit();
  259. if (!empty($backtopage)) {
  260. if (empty($id)) {
  261. $url = $backtopage;
  262. } else {
  263. $url = 'card.php?track_id='.urlencode($object->track_id);
  264. }
  265. } else {
  266. $url = 'card.php?track_id='.urlencode($object->track_id);
  267. }
  268. header("Location: ".$url);
  269. exit;
  270. } else {
  271. $db->rollback();
  272. setEventMessages($object->error, $object->errors, 'errors');
  273. }
  274. } else {
  275. setEventMessages($object->error, $object->errors, 'errors');
  276. $action = 'create';
  277. }
  278. }
  279. if ($action == 'update' && $permissiontoadd && $object->status < Ticket::STATUS_CLOSED) {
  280. $error = 0;
  281. $ret = $object->fetch(GETPOST('id', 'int'), GETPOST('ref', 'alpha'), GETPOST('track_id', 'alpha'));
  282. if ($ret < 0) {
  283. $error++;
  284. array_push($object->errors, $langs->trans('ErrorTicketIsNotValid'));
  285. }
  286. // check fields
  287. if (!$error) {
  288. if (!GETPOST('subject', 'alpha')) {
  289. $error++;
  290. array_push($object->errors, $langs->trans('ErrorFieldRequired', $langs->transnoentities('Subject')));
  291. }
  292. $ret = $extrafields->setOptionalsFromPost(null, $object);
  293. if ($ret < 0) {
  294. $error++;
  295. }
  296. }
  297. if (!$error) {
  298. $db->begin();
  299. $object->subject = GETPOST('subject', 'alpha');
  300. $object->type_code = GETPOST('type_code', 'alpha');
  301. $object->category_code = GETPOST('category_code', 'alpha');
  302. $object->severity_code = GETPOST('severity_code', 'alpha');
  303. $ret = $object->update($user);
  304. if ($ret > 0) {
  305. // Category association
  306. $categories = GETPOST('categories', 'array');
  307. $object->setCategories($categories);
  308. } else {
  309. $error++;
  310. }
  311. if ($error) {
  312. $db->rollback();
  313. } else {
  314. $db->commit();
  315. }
  316. }
  317. if ($error) {
  318. setEventMessages($object->error, $object->errors, 'errors');
  319. $action = 'edit';
  320. } else {
  321. if (!empty($backtopage)) {
  322. if (empty($id)) {
  323. $url = $backtopage;
  324. } else {
  325. $url = 'card.php?track_id='.urlencode($object->track_id);
  326. }
  327. } else {
  328. $url = 'card.php?track_id='.urlencode($object->track_id);
  329. }
  330. header('Location: '.$url);
  331. exit();
  332. }
  333. }
  334. // Mark as Read
  335. if ($action == "set_read" && $permissiontoadd) {
  336. $object->fetch('', '', GETPOST("track_id", 'alpha'));
  337. if ($object->markAsRead($user) > 0) {
  338. setEventMessages($langs->trans('TicketMarkedAsRead'), null, 'mesgs');
  339. header("Location: card.php?track_id=".$object->track_id);
  340. exit;
  341. } else {
  342. setEventMessages($object->error, $object->errors, 'errors');
  343. }
  344. $action = 'view';
  345. }
  346. // Assign to someone
  347. if ($action == "assign_user" && GETPOST('btn_assign_user', 'alpha') && $permissiontoadd) {
  348. $object->fetch('', '', GETPOST("track_id", 'alpha'));
  349. $useroriginassign = $object->fk_user_assign;
  350. $usertoassign = GETPOST('fk_user_assign', 'int');
  351. /*if (! ($usertoassign > 0)) {
  352. $error++;
  353. array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("AssignedTo")));
  354. $action = 'view';
  355. }*/
  356. if (!$error) {
  357. $ret = $object->assignUser($user, $usertoassign);
  358. if ($ret < 0) {
  359. $error++;
  360. }
  361. }
  362. if (!$error) { // Update list of contacts
  363. // If a user has already been assigned, we delete him from the contacts.
  364. if ($useroriginassign > 0) {
  365. $internal_contacts = $object->listeContact(-1, 'internal', 0, 'SUPPORTTEC');
  366. foreach ($internal_contacts as $key => $contact) {
  367. if ($contact['id'] !== $usertoassign) {
  368. $result = $object->delete_contact($contact['rowid']);
  369. if ($result<0) {
  370. $error++;
  371. setEventMessages($object->error, $object->errors, 'errors');
  372. }
  373. }
  374. }
  375. }
  376. if ($usertoassign > 0 && $usertoassign!==$useroriginassign) {
  377. $result = $object->add_contact($usertoassign, "SUPPORTTEC", 'internal', $notrigger = 0);
  378. if ($result<0) {
  379. $error++;
  380. setEventMessages($object->error, $object->errors, 'errors');
  381. }
  382. }
  383. }
  384. if (!$error) {
  385. // Log action in ticket logs table
  386. $object->fetch_user($usertoassign);
  387. setEventMessages($langs->trans('TicketAssigned'), null, 'mesgs');
  388. header("Location: card.php?track_id=".$object->track_id);
  389. exit;
  390. } else {
  391. array_push($object->errors, $object->error);
  392. }
  393. $action = 'view';
  394. }
  395. // Action to add a message (private or not, with email or not).
  396. // This may also send an email (concatenated with email_intro and email footer if checkbox was selected)
  397. if ($action == 'add_message' && GETPOSTISSET('btn_add_message') && $permissiontoread) {
  398. $ret = $object->newMessage($user, $action, (GETPOST('private_message', 'alpha') == "on" ? 1 : 0), 0);
  399. if ($ret > 0) {
  400. if (!empty($backtopage)) {
  401. $url = $backtopage;
  402. } else {
  403. $url = 'card.php?track_id='.urlencode($object->track_id);
  404. }
  405. header("Location: ".$url);
  406. exit;
  407. } else {
  408. setEventMessages($object->error, $object->errors, 'errors');
  409. $action = 'presend';
  410. }
  411. }
  412. if (($action == "confirm_close" || $action == "confirm_abandon") && GETPOST('confirm', 'alpha') == 'yes' && $permissiontoadd) {
  413. $object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha'));
  414. if ($object->close($user, ($action == "confirm_abandon" ? 1 : 0))) {
  415. setEventMessages($langs->trans('TicketMarkedAsClosed'), null, 'mesgs');
  416. $url = 'card.php?track_id='.GETPOST('track_id', 'alpha');
  417. header("Location: ".$url);
  418. } else {
  419. $action = '';
  420. setEventMessages($object->error, $object->errors, 'errors');
  421. }
  422. }
  423. if ($action == "confirm_public_close" && GETPOST('confirm', 'alpha') == 'yes' && $permissiontoadd) {
  424. $object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha'));
  425. if ($_SESSION['email_customer'] == $object->origin_email || $_SESSION['email_customer'] == $object->thirdparty->email) {
  426. $object->close($user);
  427. setEventMessages('<div class="confirm">'.$langs->trans('TicketMarkedAsClosed').'</div>', null, 'mesgs');
  428. $url = 'card.php?track_id='.GETPOST('track_id', 'alpha');
  429. header("Location: ".$url);
  430. } else {
  431. setEventMessages($object->error, $object->errors, 'errors');
  432. $action = '';
  433. }
  434. }
  435. if ($action == 'confirm_delete_ticket' && GETPOST('confirm', 'alpha') == "yes" && $permissiontodelete) {
  436. if ($object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) {
  437. if ($object->delete($user) > 0) {
  438. setEventMessages('<div class="confirm">'.$langs->trans('TicketDeletedSuccess').'</div>', null, 'mesgs');
  439. Header("Location: ".DOL_URL_ROOT."/ticket/list.php");
  440. exit;
  441. } else {
  442. $langs->load("errors");
  443. $mesg = '<div class="error">'.$langs->trans($object->error).'</div>';
  444. $action = '';
  445. }
  446. }
  447. }
  448. // Set parent company
  449. if ($action == 'set_thirdparty' && $user->hasRight('ticket', 'write')) {
  450. if ($object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) {
  451. $result = $object->setCustomer(GETPOST('editcustomer', 'int'));
  452. $url = $_SERVER["PHP_SELF"].'?track_id='.GETPOST('track_id', 'alpha');
  453. header("Location: ".$url);
  454. exit();
  455. }
  456. }
  457. // Set progress status
  458. if ($action == 'set_progression' && $user->hasRight('ticket', 'write')) {
  459. if ($object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) {
  460. $result = $object->setProgression(GETPOST('progress', 'alpha'));
  461. $url = 'card.php?track_id='.$object->track_id;
  462. header("Location: ".$url);
  463. exit();
  464. }
  465. }
  466. // Set categories
  467. if ($action == 'set_categories' && $user->hasRight('ticket', 'write')) {
  468. if ($object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) {
  469. $result = $object->setCategories(GETPOST('categories', 'array'));
  470. $url = 'card.php?track_id='.$object->track_id;
  471. header("Location: ".$url);
  472. exit();
  473. }
  474. }
  475. // Set Subject
  476. if ($action == 'setsubject' && $user->hasRight('ticket', 'write')) {
  477. if ($object->fetch(GETPOST('id', 'int'))) {
  478. if ($action == 'setsubject') {
  479. $object->subject = GETPOST('subject', 'alphanohtml');
  480. }
  481. if ($action == 'setsubject' && empty($object->subject)) {
  482. $error++;
  483. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Subject")), null, 'errors');
  484. }
  485. if (!$error) {
  486. if ($object->update($user) >= 0) {
  487. header("Location: ".$_SERVER['PHP_SELF']."?track_id=".$object->track_id);
  488. exit;
  489. } else {
  490. $error++;
  491. setEventMessages($object->error, $object->errors, 'errors');
  492. }
  493. }
  494. }
  495. }
  496. if ($action == 'confirm_reopen' && $user->hasRight('ticket', 'manage') && !GETPOST('cancel')) {
  497. if ($object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) {
  498. // prevent browser refresh from reopening ticket several times
  499. if ($object->status == Ticket::STATUS_CLOSED || $object->status == Ticket::STATUS_CANCELED) {
  500. $res = $object->setStatut(Ticket::STATUS_ASSIGNED);
  501. if ($res) {
  502. $url = 'card.php?track_id='.$object->track_id;
  503. header("Location: ".$url);
  504. exit();
  505. } else {
  506. $error++;
  507. setEventMessages($object->error, $object->errors, 'errors');
  508. }
  509. }
  510. }
  511. } elseif ($action == 'classin' && $permissiontoadd) {
  512. // Categorisation dans projet
  513. if ($object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) {
  514. $object->setProject($projectid);
  515. $url = 'card.php?track_id='.$object->track_id;
  516. header("Location: ".$url);
  517. exit();
  518. }
  519. } elseif ($action == 'setcontract' && $permissiontoadd) {
  520. // Categorisation dans contrat
  521. if ($object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) {
  522. $object->setContract(GETPOST('contractid', 'int'));
  523. $url = 'card.php?track_id='.$object->track_id;
  524. header("Location: ".$url);
  525. exit();
  526. }
  527. } elseif ($action == "set_message" && $user->hasRight('ticket', 'manage')) {
  528. if (!GETPOST('cancel')) {
  529. $object->fetch('', '', GETPOST('track_id', 'alpha'));
  530. //$oldvalue_message = $object->message;
  531. $fieldtomodify = GETPOST('message_initial', 'restricthtml');
  532. $object->message = $fieldtomodify;
  533. $ret = $object->update($user);
  534. if ($ret > 0) {
  535. //include_once DOL_DOCUMENT_ROOT.'/core/class/utils_diff.class.php';
  536. // output the result of comparing two files as plain text
  537. //$log_action .= Diff::toString(Diff::compare(strip_tags($oldvalue_message), strip_tags($object->message)));
  538. setEventMessages($langs->trans('TicketMessageSuccesfullyUpdated'), null, 'mesgs');
  539. } else {
  540. $error++;
  541. setEventMessages($object->error, $object->errors, 'errors');
  542. }
  543. }
  544. $action = 'view';
  545. } elseif ($action == 'confirm_set_status' && $permissiontoadd && !GETPOST('cancel')) {
  546. // Reopen ticket
  547. if ($object->fetch(GETPOST('id', 'int'), GETPOST('track_id', 'alpha')) >= 0) {
  548. $new_status = GETPOST('new_status', 'int');
  549. //$old_status = $object->status;
  550. $res = $object->setStatut($new_status);
  551. if ($res) {
  552. $url = 'card.php?track_id='.$object->track_id;
  553. header("Location: ".$url);
  554. exit();
  555. } else {
  556. $error++;
  557. setEventMessages($object->error, $object->errors, 'errors');
  558. }
  559. }
  560. }
  561. // Action to update an extrafield
  562. if ($action == "update_extras" && $permissiontoadd) {
  563. $object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha'));
  564. $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
  565. if ($ret < 0) {
  566. $error++;
  567. }
  568. if (!$error) {
  569. $result = $object->insertExtraFields(empty($triggermodname) ? '' : $triggermodname, $user);
  570. if ($result < 0) {
  571. $error++;
  572. }
  573. }
  574. if ($error) {
  575. setEventMessages($object->error, $object->errors, 'errors');
  576. $action = 'edit_extras';
  577. } else {
  578. setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
  579. $action = 'view';
  580. }
  581. }
  582. if ($action == "change_property" && GETPOST('btn_update_ticket_prop', 'alpha') && $permissiontoadd) {
  583. $object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha'));
  584. $object->type_code = GETPOST('update_value_type', 'aZ09');
  585. $object->severity_code = GETPOST('update_value_severity', 'aZ09');
  586. $object->category_code = GETPOST('update_value_category', 'aZ09');
  587. $ret = $object->update($user);
  588. if ($ret > 0) {
  589. setEventMessages($langs->trans('TicketUpdated'), null, 'mesgs');
  590. } else {
  591. $error++;
  592. setEventMessages($object->error, $object->errors, 'errors');
  593. }
  594. $action = 'view';
  595. }
  596. $permissiondellink = $user->hasRight('ticket', 'write');
  597. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
  598. // Actions to build doc
  599. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  600. //var_dump($action);exit;
  601. // Actions to send emails
  602. $triggersendname = 'TICKET_SENTBYMAIL';
  603. $paramname = 'id';
  604. $autocopy = 'MAIN_MAIL_AUTOCOPY_TICKET_TO'; // used to know the automatic BCC to add
  605. $trackid = 'tic'.$object->id;
  606. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  607. // Set $action to correct value for the case we used presend action to add a message
  608. if (GETPOSTISSET('actionbis') && $action == 'presend') {
  609. $action = 'presend_addmessage';
  610. }
  611. }
  612. /*
  613. * View
  614. */
  615. $userstat = new User($db);
  616. $form = new Form($db);
  617. $formticket = new FormTicket($db);
  618. if (isModEnabled('project')) {
  619. $formproject = new FormProjets($db);
  620. }
  621. $help_url = 'EN:Module_Ticket|FR:DocumentationModuleTicket';
  622. $title = $actionobject->getTitle($action);
  623. llxHeader('', $title, $help_url);
  624. if ($action == 'create' || $action == 'presend') {
  625. $formticket = new FormTicket($db);
  626. print load_fiche_titre($langs->trans('NewTicket'), '', 'ticket');
  627. $formticket->trackid = ''; // TODO Use a unique key 'tic' to avoid conflict in upload file feature
  628. $formticket->withfromsocid = $socid ? $socid : $user->socid;
  629. $formticket->withfromcontactid = $contactid ? $contactid : '';
  630. $formticket->withtitletopic = 1;
  631. $formticket->withnotifytiersatcreate = ($notifyTiers ? 1 : (!getDolGlobalString('TICKET_CHECK_NOTIFY_THIRDPARTY_AT_CREATION') ? 0 : 1));
  632. $formticket->withusercreate = 0;
  633. $formticket->withref = 1;
  634. $formticket->fk_user_create = $user->id;
  635. $formticket->withfile = 2;
  636. $formticket->withextrafields = 1;
  637. $formticket->param = array('origin' => GETPOST('origin'), 'originid' => GETPOST('originid'));
  638. $formticket->withcancel = 1;
  639. $formticket->showForm(1, 'create', 0, null, $action);
  640. /*} elseif ($action == 'edit' && $user->rights->ticket->write && $object->status < Ticket::STATUS_CLOSED) {
  641. $formticket = new FormTicket($db);
  642. $head = ticket_prepare_head($object);
  643. print '<form method="POST" name="form_ticket" id="form_edit_ticket" action="'.$_SERVER['PHP_SELF'].'?track_id='.$object->track_id.'">';
  644. print '<input type="hidden" name="token" value="'.newToken().'">';
  645. print '<input type="hidden" name="action" value="update">';
  646. print '<input type="hidden" name="tack_id" value="'.$object->track_id.'">';
  647. print dol_get_fiche_head($head, 'card', $langs->trans('Ticket'), 0, 'ticket');
  648. print '<div class="fichecenter2">';
  649. print '<table class="border" width="100%">';
  650. // Type
  651. print '<tr><td class="titlefield"><span class="fieldrequired"><label for="selecttype_code">'.$langs->trans("TicketTypeRequest").'</span></label></td><td>';
  652. $formticket->selectTypesTickets((GETPOSTISSET('type_code') ? GETPOST('type_code') : $object->type_code), 'type_code', '', '2');
  653. print '</td></tr>';
  654. // Severity
  655. print '<tr><td><span class="fieldrequired"><label for="selectseverity_code">'.$langs->trans("TicketSeverity").'</span></label></td><td>';
  656. $formticket->selectSeveritiesTickets((GETPOSTISSET('severity_code') ? GETPOST('severity_code') : $object->severity_code), 'severity_code', '', '2');
  657. print '</td></tr>';
  658. // Group
  659. print '<tr><td><span class="fieldrequired"><label for="selectcategory_code">'.$langs->trans("TicketCategory").'</span></label></td><td>';
  660. $formticket->selectGroupTickets((GETPOSTISSET('category_code') ? GETPOST('category_code') : $object->category_code), 'category_code', '', '2');
  661. print '</td></tr>';
  662. // Subject
  663. print '<tr><td><label for="subject"><span class="fieldrequired">'.$langs->trans("Subject").'</span></label></td><td>';
  664. print '<input class="text minwidth200" id="subject" name="subject" value="'.dol_escape_htmltag(GETPOSTISSET('subject') ? GETPOST('subject', 'alpha') : $object->subject).'" />';
  665. print '</td></tr>';
  666. // Other attributes
  667. $parameters = array('colspan' => ' colspan="3"', 'colspanvalue' => '3');
  668. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  669. print $hookmanager->resPrint;
  670. if (empty($reshook)) {
  671. print $object->showOptionals($extrafields, 'edit');
  672. }
  673. print '</table>';
  674. print '</div>';
  675. print dol_get_fiche_end();
  676. print $form->buttonsSaveCancel();
  677. print '</form>'; */
  678. } elseif (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'dellink' || $action == 'presend' || $action == 'presend_addmessage' || $action == 'close' || $action == 'abandon' || $action == 'delete' || $action == 'editcustomer' || $action == 'progression' || $action == 'categories' || $action == 'reopen'
  679. || $action== 'edit_contrat' || $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') {
  680. if ($res > 0) {
  681. // or for unauthorized internals users
  682. if (!$user->socid && (getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY') && $object->fk_user_assign != $user->id) && !$user->hasRight('ticket', 'manage')) {
  683. accessforbidden('', 0, 1);
  684. }
  685. // Confirmation close
  686. if ($action == 'close') {
  687. $thirdparty_contacts = $object->getInfosTicketExternalContact(1);
  688. $contacts_select = array(
  689. '-2' => $langs->trans('TicketNotifyAllTiersAtClose'),
  690. '-3' => $langs->trans('TicketNotNotifyTiersAtClose')
  691. );
  692. foreach ($thirdparty_contacts as $thirdparty_contact) {
  693. $contacts_select[$thirdparty_contact['id']] = $thirdparty_contact['civility'] . ' ' . $thirdparty_contact['lastname'] . ' ' . $thirdparty_contact['firstname'];
  694. }
  695. // Default select all or no contact
  696. $default = (getDolGlobalString('TICKET_NOTIFY_AT_CLOSING')) ? -2 : -3;
  697. $formquestion = array(
  698. array(
  699. 'name' => 'contactid',
  700. 'type' => 'select',
  701. 'label' => $langs->trans('NotifyThirdpartyOnTicketClosing'),
  702. 'values' => $contacts_select,
  703. 'default' => $default
  704. ),
  705. );
  706. print $form->formconfirm($url_page_current."?track_id=".$object->track_id, $langs->trans("CloseATicket"), $langs->trans("ConfirmCloseAticket"), "confirm_close", $formquestion, '', 1);
  707. }
  708. // Confirmation abandon
  709. if ($action == 'abandon') {
  710. print $form->formconfirm($url_page_current."?track_id=".$object->track_id, $langs->trans("AbandonTicket"), $langs->trans("ConfirmAbandonTicket"), "confirm_abandon", '', '', 1);
  711. }
  712. // Confirmation delete
  713. if ($action == 'delete') {
  714. print $form->formconfirm($url_page_current."?track_id=".$object->track_id, $langs->trans("Delete"), $langs->trans("ConfirmDeleteTicket"), "confirm_delete_ticket", '', '', 1);
  715. }
  716. // Confirm reopen
  717. if ($action == 'reopen') {
  718. print $form->formconfirm($url_page_current.'?track_id='.$object->track_id, $langs->trans('ReOpen'), $langs->trans('ConfirmReOpenTicket'), 'confirm_reopen', '', '', 1);
  719. }
  720. // Confirmation status change
  721. if ($action == 'set_status') {
  722. $new_status = GETPOST('new_status');
  723. //var_dump($url_page_current . "?track_id=" . $object->track_id);
  724. 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->labelStatusShort[$new_status])), "confirm_set_status", '', '', 1);
  725. }
  726. // project info
  727. if ($projectid > 0) {
  728. $projectstat = new Project($db);
  729. if ($projectstat->fetch($projectid) > 0) {
  730. $projectstat->fetch_thirdparty();
  731. // To verify role of users
  732. //$userAccess = $object->restrictedProjectArea($user,'read');
  733. $userWrite = $projectstat->restrictedProjectArea($user, 'write');
  734. //$userDelete = $object->restrictedProjectArea($user,'delete');
  735. //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
  736. $head = project_prepare_head($projectstat);
  737. print dol_get_fiche_head($head, 'ticket', $langs->trans("Project"), 0, ($projectstat->public ? 'projectpub' : 'project'));
  738. print '<table class="border centpercent">';
  739. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  740. // Ref
  741. print '<tr><td width="30%">'.$langs->trans('Ref').'</td><td colspan="3">';
  742. // Define a complementary filter for search of next/prev ref.
  743. if (!$user->hasRight('projet', 'all', 'lire')) {
  744. $objectsListId = $projectstat->getProjectsAuthorizedForUser($user, $mine, 0);
  745. $projectstat->next_prev_filter = "rowid IN (".$db->sanitize(count($objectsListId) ? join(',', array_keys($objectsListId)) : '0').")";
  746. }
  747. print $form->showrefnav($projectstat, 'ref', $linkback, 1, 'ref', 'ref', '');
  748. print '</td></tr>';
  749. // Label
  750. print '<tr><td>'.$langs->trans("Label").'</td><td>'.$projectstat->title.'</td></tr>';
  751. // Customer
  752. print "<tr><td>".$langs->trans("ThirdParty")."</td>";
  753. print '<td colspan="3">';
  754. if ($projectstat->thirdparty->id > 0) {
  755. print $projectstat->thirdparty->getNomUrl(1);
  756. } else {
  757. print '&nbsp;';
  758. }
  759. print '</td></tr>';
  760. // Visibility
  761. print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
  762. if ($projectstat->public) {
  763. print $langs->trans('SharedProject');
  764. } else {
  765. print $langs->trans('PrivateProject');
  766. }
  767. print '</td></tr>';
  768. // Status
  769. print '<tr><td>'.$langs->trans("Status").'</td><td>'.$projectstat->getLibStatut(4).'</td></tr>';
  770. print "</table>";
  771. print dol_get_fiche_end();
  772. } else {
  773. print "ErrorRecordNotFound";
  774. }
  775. } elseif ($socid > 0) {
  776. $object->fetch_thirdparty();
  777. $head = societe_prepare_head($object->thirdparty);
  778. print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
  779. dol_banner_tab($object->thirdparty, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
  780. print dol_get_fiche_end();
  781. }
  782. if (!$user->socid && getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY')) {
  783. $object->next_prev_filter = "te.fk_user_assign = ".((int) $user->id);
  784. } elseif ($user->socid > 0) {
  785. $object->next_prev_filter = "te.fk_soc = ".((int) $user->socid);
  786. }
  787. $head = ticket_prepare_head($object);
  788. print dol_get_fiche_head($head, 'tabTicket', $langs->trans("Ticket"), -1, 'ticket');
  789. $morehtmlref = '<div class="refidno">';
  790. $morehtmlref .= $object->subject;
  791. // Author
  792. if ($object->fk_user_create > 0) {
  793. $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
  794. $fuser = new User($db);
  795. $fuser->fetch($object->fk_user_create);
  796. $morehtmlref .= $fuser->getNomUrl(-1);
  797. } elseif (!empty($object->email_msgid)) {
  798. $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
  799. $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
  800. $htmltooltip = $langs->trans("EmailMsgID").': '.$object->email_msgid;
  801. $htmltooltip .= '<br>'.$langs->trans("EmailDate").': '.dol_print_date($object->email_date, 'dayhour');
  802. $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">- '.$form->textwithpicto($langs->trans("CreatedByEmailCollector"), $htmltooltip, 1, 'help', '', 0, 3, 'tooltip').'</small>';
  803. } elseif (!empty($object->origin_email)) {
  804. $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
  805. $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
  806. $htmltooptip = $langs->trans("IP").': '.$object->ip;
  807. $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">- '.$form->textwithpicto($langs->trans("CreatedByPublicPortal"), $htmltooptip, 1, 'help', '', 0, 3, 'tooltip').'</small>';
  808. }
  809. $permissiontoedit = $object->status < 8 && !$user->socid && $user->rights->ticket->write;
  810. //$permissiontoedit = 0;
  811. // Thirdparty
  812. if (isModEnabled("societe")) {
  813. $morehtmlref .= '<br>';
  814. $morehtmlref .= img_picto($langs->trans("ThirdParty"), 'company', 'class="pictofixedwidth"');
  815. if ($action != 'editcustomer' && $permissiontoedit) {
  816. $morehtmlref .= '<a class="editfielda" href="'.$url_page_current.'?action=editcustomer&token='.newToken().'&track_id='.$object->track_id.'">'.img_edit($langs->transnoentitiesnoconv('SetThirdParty'), 0).'</a> ';
  817. }
  818. $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, $action == 'editcustomer' ? 'editcustomer' : 'none', '', 1, 0, 0, array(), 1);
  819. if (!empty($object->socid)) {
  820. $morehtmlref .= ' - <a href="'.DOL_URL_ROOT.'/ticket/list.php?socid='.$object->socid.'&sortfield=t.datec&sortorder=desc">'.img_picto($langs->trans("Tickets"), 'ticket', 'class="pictofixedwidth"').' '.$langs->trans("TicketHistory").'</a>';
  821. }
  822. }
  823. // Project
  824. if (isModEnabled('project')) {
  825. $langs->load("projects");
  826. $morehtmlref .= '<br>';
  827. if ($permissiontoedit) {
  828. $object->fetch_project();
  829. $morehtmlref .= img_picto($langs->trans("Project"), 'project'.((is_object($object->project) && $object->project->public) ? 'pub' : ''), 'class="pictofixedwidth"');
  830. if ($action != 'classify') {
  831. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  832. }
  833. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  834. } else {
  835. if (!empty($object->fk_project)) {
  836. $object->fetch_project();
  837. $morehtmlref .= $object->project->getNomUrl(1);
  838. if ($object->project->title) {
  839. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($object->project->title).'</span>';
  840. }
  841. }
  842. }
  843. }
  844. // Contract
  845. if (getDolGlobalString('TICKET_LINK_TO_CONTRACT_WITH_HARDLINK')) {
  846. // Deprecated. Duplicate feature. Ticket can already be linked to contract with the generic "Link to" feature.
  847. if (isModEnabled('contrat')) {
  848. $langs->load('contracts');
  849. $morehtmlref .= '<br>';
  850. if ($permissiontoedit) {
  851. $morehtmlref .= img_picto($langs->trans("Contract"), 'contract', 'class="pictofixedwidth"');
  852. if ($action == 'edit_contrat') {
  853. $formcontract = new FormContract($db);
  854. $morehtmlref .= $formcontract->formSelectContract($_SERVER["PHP_SELF"].'?id='.$object->id, $object->socid, $object->fk_contract, 'contratid', 0, 1, 1, 1);
  855. } else {
  856. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=edit_contrat&token='.newToken().'&id='.$object->id.'">';
  857. $morehtmlref .= img_edit($langs->trans('SetContract'));
  858. $morehtmlref .= '</a>';
  859. }
  860. } else {
  861. if (!empty($object->fk_contract)) {
  862. $contratstatic = new Contrat($db);
  863. $contratstatic->fetch($object->fk_contract);
  864. //print '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$selected.'">'.$projet->title.'</a>';
  865. $morehtmlref .= $contratstatic->getNomUrl(0, '', 1);
  866. }
  867. }
  868. }
  869. }
  870. $morehtmlref .= '</div>';
  871. $linkback = '<a href="'.DOL_URL_ROOT.'/ticket/list.php?restore_lastsearch_values=1"><strong>'.$langs->trans("BackToList").'</strong></a> ';
  872. dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', 'ref', $morehtmlref);
  873. print '<div class="fichecenter">';
  874. print '<div class="fichehalfleft">';
  875. print '<div class="underbanner clearboth"></div>';
  876. print '<table class="border tableforfield centpercent">';
  877. // Track ID
  878. print '<tr><td class="titlefield">'.$langs->trans("TicketTrackId").'</td><td>';
  879. if (!empty($object->track_id)) {
  880. if (empty($object->ref)) {
  881. $object->ref = $object->id;
  882. print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'track_id');
  883. } else {
  884. print $object->track_id;
  885. }
  886. } else {
  887. print $langs->trans('None');
  888. }
  889. print '</td></tr>';
  890. // Subject
  891. print '<tr><td>';
  892. print $form->editfieldkey("Subject", 'subject', $object->subject, $object, $user->hasRight('ticket', 'write') && !$user->socid, 'string');
  893. print '</td><td>';
  894. print $form->editfieldval("Subject", 'subject', $object->subject, $object, $user->hasRight('ticket', 'write') && !$user->socid, 'string');
  895. print '</td></tr>';
  896. // Creation date
  897. print '<tr><td>'.$langs->trans("DateCreation").'</td><td>';
  898. print dol_print_date($object->datec, 'dayhour', 'tzuser');
  899. print '<span class="opacitymedium"> - '.$langs->trans("TimeElapsedSince").': <i>'.convertSecondToTime(roundUpToNextMultiple($now - $object->datec, 60)).'</i></span>';
  900. print '</td></tr>';
  901. // Origin
  902. /*
  903. if ($object->email_msgid) {
  904. $texttoshow = $langs->trans("CreatedByEmailCollector");
  905. } elseif ($object->origin_email) {
  906. $texttoshow = $langs->trans("FromPublicEmail");
  907. }
  908. if ($texttoshow) {
  909. print '<tr><td class="titlefield fieldname_email_origin">';
  910. print $langs->trans("Origin");
  911. print '</td>';
  912. print '<td class="valuefield fieldname_email_origin">';
  913. print $texttoshow;
  914. print '</td></tr>';
  915. }
  916. */
  917. // Read date
  918. print '<tr><td>'.$langs->trans("TicketReadOn").'</td><td>';
  919. if (!empty($object->date_read)) {
  920. print dol_print_date($object->date_read, 'dayhour', 'tzuser');
  921. print '<span class="opacitymedium"> - '.$langs->trans("TicketTimeElapsedBeforeSince").': <i>'.convertSecondToTime(roundUpToNextMultiple($object->date_read - $object->datec, 60)).'</i>';
  922. print ' / <i>'.convertSecondToTime(roundUpToNextMultiple($now - $object->date_read, 60)).'</i></span>';
  923. }
  924. print '</td></tr>';
  925. // Close date
  926. print '<tr><td>'.$langs->trans("TicketCloseOn").'</td><td>';
  927. if (!empty($object->date_close)) {
  928. print dol_print_date($object->date_close, 'dayhour', 'tzuser');
  929. }
  930. print '</td></tr>';
  931. // User assigned
  932. print '<tr><td>';
  933. print '<table class="nobordernopadding" width="100%"><tr><td class="nowrap">';
  934. print $langs->trans("AssignedTo");
  935. if (isset($object->status) && $object->status < $object::STATUS_CLOSED && GETPOST('set', 'alpha') != "assign_ticket" && $user->hasRight('ticket', 'manage')) {
  936. print '</td><td class="right"><a class="editfielda" href="'.$url_page_current.'?track_id='.urlencode($object->track_id).'&set=assign_ticket">'.img_edit($langs->trans('Modify'), '').'</a>';
  937. }
  938. print '</td></tr></table>';
  939. print '</td><td>';
  940. if (GETPOST('set', 'alpha') != "assign_ticket" && $object->fk_user_assign > 0) {
  941. $userstat->fetch($object->fk_user_assign);
  942. print $userstat->getNomUrl(-1);
  943. }
  944. // Show user list to assignate one if status is "read"
  945. if (GETPOST('set', 'alpha') == "assign_ticket" && $object->status < 8 && !$user->socid && $user->hasRight('ticket', 'write')) {
  946. print '<form method="post" name="ticket" enctype="multipart/form-data" action="'.$url_page_current.'">';
  947. print '<input type="hidden" name="token" value="'.newToken().'">';
  948. print '<input type="hidden" name="action" value="assign_user">';
  949. print '<input type="hidden" name="track_id" value="'.$object->track_id.'">';
  950. //print '<label for="fk_user_assign">'.$langs->trans("AssignUser").'</label> ';
  951. print $form->select_dolusers(empty($object->fk_user_assign) ? $user->id : $object->fk_user_assign, 'fk_user_assign', 1);
  952. print ' <input type="submit" class="button small" name="btn_assign_user" value="'.$langs->trans("Validate").'" />';
  953. print '</form>';
  954. }
  955. print '</td></tr>';
  956. // Progression
  957. print '<tr><td>';
  958. print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
  959. print $langs->trans('Progression').'</td><td class="left">';
  960. print '</td>';
  961. if ($action != 'progression' && isset($object->status) && $object->status < $object::STATUS_CLOSED && !$user->socid) {
  962. print '<td class="right"><a class="editfielda" href="'.$url_page_current.'?action=progression&token='.newToken().'&track_id='.urlencode($object->track_id).'">'.img_edit($langs->trans('Modify')).'</a></td>';
  963. }
  964. print '</tr></table>';
  965. print '</td><td>';
  966. if ($user->hasRight('ticket', 'write') && $action == 'progression') {
  967. print '<form action="'.$url_page_current.'" method="post">';
  968. print '<input type="hidden" name="token" value="'.newToken().'">';
  969. print '<input type="hidden" name="track_id" value="'.$track_id.'">';
  970. print '<input type="hidden" name="action" value="set_progression">';
  971. print '<input type="text" class="flat width75" name="progress" value="'.$object->progress.'">';
  972. print ' <input type="submit" class="button button-edit small" value="'.$langs->trans('Modify').'">';
  973. print '</form>';
  974. } else {
  975. print($object->progress > 0 ? $object->progress : '0').'%';
  976. }
  977. print '</td>';
  978. print '</tr>';
  979. // Timing (Duration sum of linked fichinter)
  980. if (isModEnabled('ficheinter')) {
  981. $object->fetchObjectLinked();
  982. $num = count($object->linkedObjects);
  983. $timing = 0;
  984. $foundinter = 0;
  985. if ($num) {
  986. foreach ($object->linkedObjects as $objecttype => $objects) {
  987. if ($objecttype == "fichinter") {
  988. foreach ($objects as $fichinter) {
  989. $foundinter++;
  990. $timing += $fichinter->duration;
  991. }
  992. }
  993. }
  994. }
  995. print '<tr><td>';
  996. print $form->textwithpicto($langs->trans("TicketDurationAuto"), $langs->trans("TicketDurationAutoInfos"), 1);
  997. print '</td><td>';
  998. print $foundinter ? convertSecondToTime($timing, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY) : '';
  999. print '</td></tr>';
  1000. }
  1001. // Other attributes
  1002. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  1003. print '</table>';
  1004. // End of left column and beginning of right column
  1005. print '</div><div class="fichehalfright">';
  1006. print '<form method="post" name="formticketproperties" action="'.$url_page_current.'">';
  1007. print '<input type="hidden" name="token" value="'.newToken().'">';
  1008. print '<input type="hidden" name="action" value="change_property">';
  1009. print '<input type="hidden" name="track_id" value="'.$track_id.'">';
  1010. print '<input type="hidden" name="trackid" value="'.$trackid.'">';
  1011. // Categories
  1012. if (isModEnabled('categorie')) {
  1013. print '<div class="underbanner clearboth"></div>';
  1014. print '<table class="border centpercent tableforfield">';
  1015. print '<tr>';
  1016. print '<td class="valignmiddle titlefield">';
  1017. print '<table class="nobordernopadding centpercent"><tr><td class="titlefield">';
  1018. print $langs->trans("Categories");
  1019. if ($action != 'categories' && !$user->socid) {
  1020. print '<td class="right"><a class="editfielda" href="'.$url_page_current.'?action=categories&amp;track_id='.$object->track_id.'">'.img_edit($langs->trans('Modify')).'</a></td>';
  1021. }
  1022. print '</table>';
  1023. print '</td>';
  1024. if ($user->hasRight('ticket', 'write') && $action == 'categories') {
  1025. $cate_arbo = $form->select_all_categories(Categorie::TYPE_TICKET, '', 'parent', 64, 0, 1);
  1026. if (is_array($cate_arbo)) {
  1027. // Categories
  1028. print '<td colspan="3">';
  1029. print '<form action="'.$url_page_current.'" method="post">';
  1030. print '<input type="hidden" name="token" value="'.newToken().'">';
  1031. print '<input type="hidden" name="track_id" value="'.$track_id.'">';
  1032. print '<input type="hidden" name="action" value="set_categories">';
  1033. $category = new Categorie($db);
  1034. $cats = $category->containing($object->id, 'ticket');
  1035. $arrayselected = array();
  1036. foreach ($cats as $cat) {
  1037. $arrayselected[] = $cat->id;
  1038. }
  1039. print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, 'quatrevingtpercent widthcentpercentminusx', 0, 0);
  1040. print '<input type="submit" class="button button-edit small" value="'.$langs->trans('Save').'">';
  1041. print '</form>';
  1042. print "</td>";
  1043. }
  1044. } else {
  1045. print '<td colspan="3">';
  1046. print $form->showCategories($object->id, Categorie::TYPE_TICKET, 1);
  1047. print "</td></tr>";
  1048. }
  1049. print '</table>';
  1050. }
  1051. // View Original message
  1052. $actionobject->viewTicketOriginalMessage($user, $action, $object);
  1053. // Classification of ticket
  1054. 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
  1055. print '<table class="noborder tableforfield centpercent margintable">';
  1056. print '<tr class="liste_titre">';
  1057. print '<td>';
  1058. print $langs->trans('TicketProperties');
  1059. print '</td>';
  1060. print '<td>';
  1061. if (GETPOST('set', 'alpha') == 'properties' && $user->hasRight('ticket', 'write')) {
  1062. print '<input type="submit" class="button small" name="btn_update_ticket_prop" value="'.$langs->trans("Modify").'" />';
  1063. } else {
  1064. // Button to edit Properties
  1065. if (isset($object->status) && ($object->status < $object::STATUS_NEED_MORE_INFO || getDolGlobalString('TICKET_ALLOW_CLASSIFICATION_MODIFICATION_EVEN_IF_CLOSED')) && $user->hasRight('ticket', 'write')) {
  1066. print ' <a class="editfielda" href="card.php?track_id='.$object->track_id.'&set=properties">'.img_edit($langs->trans('Modify')).'</a>';
  1067. }
  1068. }
  1069. print '</td>';
  1070. print '</tr>';
  1071. if (GETPOST('set', 'alpha') == 'properties' && $user->hasRight('ticket', 'write')) {
  1072. print '<tr>';
  1073. // Type
  1074. print '<td class="titlefield">';
  1075. print $langs->trans('Type');
  1076. print '</td><td>';
  1077. $formticket->selectTypesTickets($object->type_code, 'update_value_type', '', 2);
  1078. print '</td>';
  1079. print '</tr>';
  1080. // Group
  1081. print '<tr>';
  1082. print '<td>';
  1083. print $langs->trans('TicketCategory');
  1084. print '</td><td>';
  1085. $formticket->selectGroupTickets($object->category_code, 'update_value_category', '', 2, 0, 0, 0, 'maxwidth500 widthcentpercentminusxx');
  1086. print '</td>';
  1087. print '</tr>';
  1088. // Severity
  1089. print '<tr>';
  1090. print '<td>';
  1091. print $langs->trans('TicketSeverity');
  1092. print '</td><td>';
  1093. $formticket->selectSeveritiesTickets($object->severity_code, 'update_value_severity', '', 2);
  1094. print '</td>';
  1095. print '</tr>';
  1096. } else {
  1097. // Type
  1098. print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td>';
  1099. if (!empty($object->type_code)) {
  1100. print $langs->getLabelFromKey($db, 'TicketTypeShort'.$object->type_code, 'c_ticket_type', 'code', 'label', $object->type_code);
  1101. }
  1102. print '</td></tr>';
  1103. // Group
  1104. $s = '';
  1105. if (!empty($object->category_code)) {
  1106. $s = $langs->getLabelFromKey($db, 'TicketCategoryShort'.$object->category_code, 'c_ticket_category', 'code', 'label', $object->category_code);
  1107. }
  1108. print '<tr><td>'.$langs->trans("TicketCategory").'</td><td class="tdoverflowmax200" title="'.dol_escape_htmltag($s).'">';
  1109. print dol_escape_htmltag($s);
  1110. print '</td></tr>';
  1111. // Severity
  1112. print '<tr><td>'.$langs->trans("TicketSeverity").'</td><td>';
  1113. if (!empty($object->severity_code)) {
  1114. print $langs->getLabelFromKey($db, 'TicketSeverityShort'.$object->severity_code, 'c_ticket_severity', 'code', 'label', $object->severity_code);
  1115. }
  1116. print '</td></tr>';
  1117. }
  1118. print '</table>'; // End table actions
  1119. print '</div>';
  1120. print '</form>';
  1121. // Display navbar with links to change ticket status
  1122. print '<!-- navbar with status -->';
  1123. if (!$user->socid && $user->hasRight('ticket', 'write') && isset($object->status) && $object->status < $object::STATUS_CLOSED && GETPOST('set') !== 'properties') {
  1124. $actionobject->viewStatusActions($object);
  1125. }
  1126. if (getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
  1127. print load_fiche_titre($langs->trans('Contacts'), '', 'title_companies.png');
  1128. print '<div class="div-table-responsive-no-min">';
  1129. print '<div class="tagtable centpercent noborder allwidth">';
  1130. print '<div class="tagtr liste_titre">';
  1131. print '<div class="tagtd">'.$langs->trans("Source").'</div>
  1132. <div class="tagtd">' . $langs->trans("Company").'</div>
  1133. <div class="tagtd">' . $langs->trans("Contacts").'</div>
  1134. <div class="tagtd">' . $langs->trans("ContactType").'</div>
  1135. <div class="tagtd">' . $langs->trans("Phone").'</div>
  1136. <div class="tagtd center">' . $langs->trans("Status").'</div>';
  1137. print '</div><!-- tagtr -->';
  1138. // Contact list
  1139. $companystatic = new Societe($db);
  1140. $contactstatic = new Contact($db);
  1141. $userstatic = new User($db);
  1142. $var = false;
  1143. foreach (array('internal', 'external') as $source) {
  1144. $tmpobject = $object;
  1145. $tab = $tmpobject->listeContact(-1, $source);
  1146. $num = count($tab);
  1147. $i = 0;
  1148. while ($i < $num) {
  1149. $var = !$var;
  1150. print '<div class="tagtr '.($var ? 'pair' : 'impair').'">';
  1151. print '<div class="tagtd left">';
  1152. if ($tab[$i]['source'] == 'internal') {
  1153. echo $langs->trans("User");
  1154. }
  1155. if ($tab[$i]['source'] == 'external') {
  1156. echo $langs->trans("ThirdPartyContact");
  1157. }
  1158. print '</div>';
  1159. print '<div class="tagtd left">';
  1160. if ($tab[$i]['socid'] > 0) {
  1161. $companystatic->fetch($tab[$i]['socid']);
  1162. echo $companystatic->getNomUrl(-1);
  1163. }
  1164. if ($tab[$i]['socid'] < 0) {
  1165. echo $conf->global->MAIN_INFO_SOCIETE_NOM;
  1166. }
  1167. if (!$tab[$i]['socid']) {
  1168. echo '&nbsp;';
  1169. }
  1170. print '</div>';
  1171. print '<div class="tagtd">';
  1172. if ($tab[$i]['source'] == 'internal') {
  1173. if ($userstatic->fetch($tab[$i]['id'])) {
  1174. print $userstatic->getNomUrl(-1);
  1175. }
  1176. }
  1177. if ($tab[$i]['source'] == 'external') {
  1178. if ($contactstatic->fetch($tab[$i]['id'])) {
  1179. print $contactstatic->getNomUrl(-1);
  1180. }
  1181. }
  1182. print ' </div>
  1183. <div class="tagtd">' . $tab[$i]['libelle'].'</div>';
  1184. print '<div class="tagtd">';
  1185. print dol_print_phone($tab[$i]['phone'], '', '', '', 'AC_TEL').'<br>';
  1186. if (!empty($tab[$i]['phone_perso'])) {
  1187. //print img_picto($langs->trans('PhonePerso'),'object_phoning.png','',0,0,0).' ';
  1188. print '<br>'.dol_print_phone($tab[$i]['phone_perso'], '', '', '', 'AC_TEL').'<br>';
  1189. }
  1190. if (!empty($tab[$i]['phone_mobile'])) {
  1191. //print img_picto($langs->trans('PhoneMobile'),'object_phoning.png','',0,0,0).' ';
  1192. print dol_print_phone($tab[$i]['phone_mobile'], '', '', '', 'AC_TEL').'<br>';
  1193. }
  1194. print '</div>';
  1195. print '<div class="tagtd center">';
  1196. if ($object->status >= 0) {
  1197. echo '<a href="contact.php?track_id='.$object->track_id.'&amp;action=swapstatut&amp;ligne='.$tab[$i]['rowid'].'">';
  1198. }
  1199. if ($tab[$i]['source'] == 'internal') {
  1200. $userstatic->id = $tab[$i]['id'];
  1201. $userstatic->lastname = $tab[$i]['lastname'];
  1202. $userstatic->firstname = $tab[$i]['firstname'];
  1203. echo $userstatic->LibStatut($tab[$i]['statuscontact'], 3);
  1204. }
  1205. if ($tab[$i]['source'] == 'external') {
  1206. $contactstatic->id = $tab[$i]['id'];
  1207. $contactstatic->lastname = $tab[$i]['lastname'];
  1208. $contactstatic->firstname = $tab[$i]['firstname'];
  1209. echo $contactstatic->LibStatut($tab[$i]['statuscontact'], 3);
  1210. }
  1211. if ($object->status >= 0) {
  1212. echo '</a>';
  1213. }
  1214. print '</div>';
  1215. print '</div><!-- tagtr -->';
  1216. $i++;
  1217. }
  1218. }
  1219. print '</div><!-- contact list -->';
  1220. print '</div>';
  1221. }
  1222. print '</div></div>';
  1223. print '<div class="clearboth"></div>';
  1224. print dol_get_fiche_end();
  1225. // Buttons for actions
  1226. if ($action != 'presend' && $action != 'presend_addmessage' && $action != 'editline') {
  1227. print '<div class="tabsAction">'."\n";
  1228. $parameters = array();
  1229. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1230. if ($reshook < 0) {
  1231. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  1232. }
  1233. if (empty($reshook)) {
  1234. // Email
  1235. if (isset($object->status) && $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage") {
  1236. print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"].'?action=presend_addmessage&send_email=1&private_message=0&mode=init&token='.newToken().'&track_id='.$object->track_id.'#formmailbeforetitle', '');
  1237. }
  1238. // Show link to add a message (if read and not closed)
  1239. if (isset($object->status) && $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage") {
  1240. print dolGetButtonAction('', $langs->trans('TicketAddPrivateMessage'), 'default', $_SERVER["PHP_SELF"].'?action=presend_addmessage&mode=init&token='.newToken().'&track_id='.$object->track_id.'#formmailbeforetitle', '');
  1241. }
  1242. // Link to create an intervention
  1243. // socid is needed otherwise fichinter ask it and forgot origin after form submit :\
  1244. if (!$object->fk_soc && $user->hasRight("ficheinter", "creer")) {
  1245. print dolGetButtonAction($langs->trans('UnableToCreateInterIfNoSocid'), $langs->trans('TicketAddIntervention'), 'default', $_SERVER['PHP_SELF']. '#', '', false);
  1246. }
  1247. if ($object->fk_soc > 0 && isset($object->status) && $object->status < Ticket::STATUS_CLOSED && $user->hasRight('ficheinter', 'creer')) {
  1248. print dolGetButtonAction('', $langs->trans('TicketAddIntervention'), 'default', DOL_URL_ROOT.'/fichinter/card.php?action=create&token='.newToken().'&socid='. $object->fk_soc.'&origin=ticket_ticket&originid='. $object->id, '');
  1249. }
  1250. // Close ticket if status is read
  1251. if (isset($object->status) && $object->status > 0 && $object->status < Ticket::STATUS_CLOSED && $user->hasRight('ticket', 'write')) {
  1252. print dolGetButtonAction('', $langs->trans('CloseTicket'), 'default', $_SERVER["PHP_SELF"].'?action=close&token='.newToken().'&track_id='.$object->track_id, '');
  1253. }
  1254. // Abandon ticket if status is read
  1255. if (isset($object->status) && $object->status > 0 && $object->status < Ticket::STATUS_CLOSED && $user->hasRight('ticket', 'write')) {
  1256. print dolGetButtonAction('', $langs->trans('AbandonTicket'), 'default', $_SERVER["PHP_SELF"].'?action=abandon&token='.newToken().'&track_id='.$object->track_id, '');
  1257. }
  1258. // Re-open ticket
  1259. if (!$user->socid && (isset($object->status) && ($object->status == Ticket::STATUS_CLOSED || $object->status == Ticket::STATUS_CANCELED)) && !$user->socid) {
  1260. print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&track_id='.$object->track_id, '');
  1261. }
  1262. // Delete ticket
  1263. if ($user->hasRight('ticket', 'delete') && !$user->socid) {
  1264. print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&track_id='.$object->track_id, '');
  1265. }
  1266. }
  1267. print '</div>'."\n";
  1268. } else {
  1269. //print '<br>';
  1270. }
  1271. // Select mail models is same action as presend
  1272. if (GETPOST('modelselected')) {
  1273. $action = 'presend';
  1274. }
  1275. // Set $action to correct value for the case we used presend action to add a message
  1276. if (GETPOSTISSET('actionbis') && $action == 'presend') {
  1277. $action = 'presend_addmessage';
  1278. }
  1279. // add a message
  1280. if ($action == 'presend' || $action == 'presend_addmessage') {
  1281. if ($object->fk_soc > 0) {
  1282. $object->fetch_thirdparty();
  1283. }
  1284. $outputlangs = $langs;
  1285. $newlang = '';
  1286. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  1287. $newlang = GETPOST('lang_id', 'aZ09');
  1288. } elseif (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && is_object($object->thirdparty)) {
  1289. $newlang = $object->thirdparty->default_lang;
  1290. }
  1291. if (!empty($newlang)) {
  1292. $outputlangs = new Translate("", $conf);
  1293. $outputlangs->setDefaultLang($newlang);
  1294. }
  1295. $arrayoffamiliestoexclude = array('objectamount');
  1296. $action = 'add_message'; // action to use to post the message
  1297. $modelmail = 'ticket_send';
  1298. // Substitution array
  1299. $morehtmlright = '';
  1300. $help = "";
  1301. $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, $arrayoffamiliestoexclude, $object);
  1302. $morehtmlright .= $form->textwithpicto('<span class="opacitymedium">'.$langs->trans("TicketMessageSubstitutionReplacedByGenericValues").'</span>', $help, 1, 'helpclickable', '', 0, 3, 'helpsubstitution');
  1303. print '<div>';
  1304. print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
  1305. print load_fiche_titre($langs->trans('TicketAddMessage'), $morehtmlright, 'messages@ticket');
  1306. print '<hr>';
  1307. $formticket = new FormTicket($db);
  1308. $formticket->action = $action;
  1309. $formticket->track_id = $object->track_id;
  1310. $formticket->ref = $object->ref;
  1311. $formticket->id = $object->id;
  1312. $formticket->trackid = 'tic'.$object->id;
  1313. $formticket->withfile = 2;
  1314. $formticket->withcancel = 1;
  1315. $formticket->param = array('fk_user_create' => $user->id);
  1316. $formticket->param['langsmodels'] = (empty($newlang) ? $langs->defaultlang : $newlang);
  1317. // Table of additional post parameters
  1318. $formticket->param['models'] = $modelmail;
  1319. $formticket->param['models_id'] = GETPOST('modelmailselected', 'int');
  1320. //$formticket->param['socid']=$object->fk_soc;
  1321. $formticket->param['returnurl'] = $_SERVER["PHP_SELF"].'?track_id='.$object->track_id;
  1322. $formticket->withsubstit = 1;
  1323. $formticket->substit = $substitutionarray;
  1324. $formticket->backtopage = $backtopage;
  1325. $formticket->showMessageForm('100%');
  1326. print '</div>';
  1327. }
  1328. // Show messages on card (Note: this is a duplicate of the view Events/Agenda but on the main tab)
  1329. if (getDolGlobalString('TICKET_SHOW_MESSAGES_ON_CARD')) {
  1330. $param = '&id='.$object->id;
  1331. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  1332. $param .= '&contextpage='.$contextpage;
  1333. }
  1334. if ($limit > 0 && $limit != $conf->liste_limit) {
  1335. $param .= '&limit='.$limit;
  1336. }
  1337. if ($actioncode) {
  1338. $param .= '&actioncode='.urlencode($actioncode);
  1339. }
  1340. if ($search_agenda_label) {
  1341. $param .= '&search_agenda_label='.urlencode($search_agenda_label);
  1342. }
  1343. $morehtmlright = '';
  1344. $messagingUrl = DOL_URL_ROOT.'/ticket/agenda.php?track_id='.$object->track_id;
  1345. $morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 1);
  1346. // Show link to add a message (if read and not closed)
  1347. $btnstatus = $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage" && $action != "add_message";
  1348. $url = 'card.php?track_id='.$object->track_id.'&action=presend_addmessage&mode=init';
  1349. $morehtmlright .= dolGetButtonTitle($langs->trans('TicketAddMessage'), '', 'fa fa-comment-dots', $url, 'add-new-ticket-title-button', $btnstatus);
  1350. // Show link to add event (if read and not closed)
  1351. $btnstatus = $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage" && $action != "add_message";
  1352. $url = dol_buildpath('/comm/action/card.php', 1).'?action=create&datep='.date('YmdHi').'&origin=ticket&originid='.$object->id.'&projectid='.$object->fk_project.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?track_id='.$object->track_id);
  1353. $morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', $url, 'add-new-ticket-even-button', $btnstatus);
  1354. print_barre_liste($langs->trans("ActionsOnTicket"), 0, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 1);
  1355. // List of all actions
  1356. $filters = array();
  1357. $filters['search_agenda_label'] = $search_agenda_label;
  1358. $filters['search_rowid'] = $search_rowid;
  1359. show_actions_messaging($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
  1360. }
  1361. if ($action != 'presend' && $action != 'presend_addmessage' && $action != 'add_message') {
  1362. print '<div class="fichecenter"><div class="fichehalfleft">';
  1363. print '<a name="builddoc"></a>'; // ancre
  1364. // Show links to link elements
  1365. $linktoelem = $form->showLinkToObjectBlock($object, null, array('ticket'));
  1366. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  1367. // Show direct link to public interface
  1368. print '<br><!-- Link to public interface -->'."\n";
  1369. print showDirectPublicLink($object).'<br>';
  1370. print '</div>';
  1371. if (!getDolGlobalString('TICKET_SHOW_MESSAGES_ON_CARD')) {
  1372. print '<div class="fichehalfright">';
  1373. $MAXEVENT = 10;
  1374. $morehtmlcenter = '<div class="nowraponall">';
  1375. $morehtmlcenter .= dolGetButtonTitle($langs->trans('FullConversation'), '', 'fa fa-comments imgforviewmode', DOL_URL_ROOT.'/ticket/messaging.php?id='.$object->id);
  1376. $morehtmlcenter .= dolGetButtonTitle($langs->trans('FullList'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/ticket/agenda.php?id='.$object->id);
  1377. $morehtmlcenter .= '</div>';
  1378. // List of actions on element
  1379. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  1380. $formactions = new FormActions($db);
  1381. $somethingshown = $formactions->showactions($object, 'ticket', $socid, 1, 'listactions', $MAXEVENT, '', $morehtmlcenter);
  1382. print '</div>';
  1383. }
  1384. print '</div>';
  1385. }
  1386. }
  1387. }
  1388. // End of page
  1389. llxFooter();
  1390. $db->close();