card.php 60 KB

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