card.php 62 KB

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