view.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. <?php
  2. /* Copyright (C) 2013-2016 Jean-François FERRY <hello@librethic.io>
  3. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  4. * Copyright (C) 2023 Benjamin Falière <benjamin.faliere@altairis.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/public/ticket/view.php
  21. * \ingroup ticket
  22. * \brief Public file to show one ticket
  23. */
  24. if (!defined('NOREQUIREMENU')) {
  25. define('NOREQUIREMENU', '1');
  26. }
  27. // If there is no need to load and show top and left menu
  28. if (!defined("NOLOGIN")) {
  29. define("NOLOGIN", '1');
  30. }
  31. if (!defined('NOIPCHECK')) {
  32. define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
  33. }
  34. if (!defined('NOBROWSERNOTIF')) {
  35. define('NOBROWSERNOTIF', '1');
  36. }
  37. // If this page is public (can be called outside logged session)
  38. // For MultiCompany module.
  39. // Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
  40. $entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
  41. if (is_numeric($entity)) {
  42. define("DOLENTITY", $entity);
  43. }
  44. // Load Dolibarr environment
  45. require '../../main.inc.php';
  46. require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
  47. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticket.class.php';
  48. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  49. require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
  50. require_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
  51. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  52. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  53. // Load translation files required by the page
  54. $langs->loadLangs(array("companies", "other", "ticket"));
  55. // Get parameters
  56. $action = GETPOST('action', 'aZ09');
  57. $cancel = GETPOST('cancel', 'aZ09');
  58. $track_id = GETPOST('track_id', 'alpha');
  59. $email = GETPOST('email', 'email');
  60. $suffix = "";
  61. if (GETPOST('btn_view_ticket')) {
  62. unset($_SESSION['email_customer']);
  63. }
  64. if (isset($_SESSION['email_customer'])) {
  65. $email = $_SESSION['email_customer'];
  66. }
  67. $object = new ActionsTicket($db);
  68. if (!isModEnabled('ticket')) {
  69. httponly_accessforbidden('Module Ticket not enabled');
  70. }
  71. /*
  72. * Actions
  73. */
  74. if ($cancel) {
  75. $backtopage = getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE', DOL_URL_ROOT.'/public/ticket/');
  76. if (!empty($backtopage)) {
  77. header("Location: ".$backtopage);
  78. exit;
  79. }
  80. $action = 'view_ticket';
  81. }
  82. if ($action == "view_ticket" || $action == "presend" || $action == "close" || $action == "confirm_public_close" || $action == "add_message" || $action == "add_contact") {
  83. $error = 0;
  84. $display_ticket = false;
  85. if (!strlen($track_id)) {
  86. $error++;
  87. array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("TicketTrackId")));
  88. $action = '';
  89. }
  90. if (!strlen($email)) {
  91. $error++;
  92. array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Email")));
  93. $action = '';
  94. } else {
  95. if (!isValidEmail($email)) {
  96. $error++;
  97. array_push($object->errors, $langs->trans("ErrorEmailInvalid"));
  98. $action = '';
  99. }
  100. }
  101. if (!$error) {
  102. $ret = $object->fetch('', '', $track_id);
  103. if ($ret && $object->dao->id > 0) {
  104. // Check if emails provided is the one of author
  105. $emailofticket = CMailFile::getValidAddress($object->dao->origin_email, 2);
  106. if (strtolower($emailofticket) == strtolower($email)) {
  107. $display_ticket = true;
  108. $_SESSION['email_customer'] = $email;
  109. } else {
  110. // Check if emails provided is inside list of contacts
  111. $contacts = $object->dao->liste_contact(-1, 'external');
  112. foreach ($contacts as $contact) {
  113. if (strtolower($contact['email']) == strtolower($email)) {
  114. $display_ticket = true;
  115. $_SESSION['email_customer'] = $email;
  116. break;
  117. } else {
  118. $display_ticket = false;
  119. }
  120. }
  121. }
  122. // Check email of thirdparty of ticket
  123. if ($object->dao->fk_soc > 0 || $object->dao->socid > 0) {
  124. $object->dao->fetch_thirdparty();
  125. if ($email == $object->dao->thirdparty->email) {
  126. $display_ticket = true;
  127. $_SESSION['email_customer'] = $email;
  128. }
  129. }
  130. // Check if email is email of creator
  131. if ($object->dao->fk_user_create > 0) {
  132. $tmpuser = new User($db);
  133. $tmpuser->fetch($object->dao->fk_user_create);
  134. if (strtolower($email) == strtolower($tmpuser->email)) {
  135. $display_ticket = true;
  136. $_SESSION['email_customer'] = $email;
  137. }
  138. }
  139. // Check if email is email of creator
  140. if ($object->dao->fk_user_assign > 0 && $object->dao->fk_user_assign != $object->dao->fk_user_create) {
  141. $tmpuser = new User($db);
  142. $tmpuser->fetch($object->dao->fk_user_assign);
  143. if (strtolower($email) == strtolower($tmpuser->email)) {
  144. $display_ticket = true;
  145. $_SESSION['email_customer'] = $email;
  146. }
  147. }
  148. } else {
  149. $error++;
  150. array_push($object->errors, $langs->trans("ErrorTicketNotFound", $track_id));
  151. $action = '';
  152. }
  153. }
  154. if (!$error && $action == 'confirm_public_close' && $display_ticket) {
  155. if ($object->dao->close($user)) {
  156. setEventMessages($langs->trans('TicketMarkedAsClosed'), null, 'mesgs');
  157. $url = 'view.php?action=view_ticket&track_id='.GETPOST('track_id', 'alpha').(!empty($entity) && isModEnabled('multicompany') ? '&entity='.$entity : '').'&token='.newToken();
  158. header("Location: ".$url);
  159. exit;
  160. } else {
  161. $action = '';
  162. setEventMessages($object->error, $object->errors, 'errors');
  163. }
  164. }
  165. if (!$error && $action == "add_message" && $display_ticket && GETPOSTISSET('btn_add_message')) {
  166. $ret = $object->dao->newMessage($user, $action, 0, 1);
  167. if (!$error) {
  168. $action = 'view_ticket';
  169. }
  170. }
  171. // Add a new external contributor to a ticket
  172. if (!$error && $action == "add_contact" && $display_ticket && GETPOSTISSET('btn_add_contact')) {
  173. $ret = $object->dao->add_contact(GETPOSTINT('contactid'), 'CONTRIBUTOR');
  174. if (!$error) {
  175. $action = 'view_ticket';
  176. }
  177. }
  178. if ($error || !empty($object->errors)) {
  179. setEventMessages($object->error, $object->errors, 'errors');
  180. if ($action == "add_message") {
  181. $action = 'presend';
  182. } else {
  183. $action = '';
  184. }
  185. }
  186. }
  187. // Actions to send emails (for ticket, we need to manage the addfile and removefile only)
  188. $triggersendname = 'TICKET_SENTBYMAIL';
  189. $paramname = 'id';
  190. $autocopy = 'MAIN_MAIL_AUTOCOPY_TICKET_TO'; // used to know the automatic BCC to add
  191. if (!empty($object->dao->id)) {
  192. $trackid = 'tic'.$object->dao->id;
  193. }
  194. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  195. /*
  196. * View
  197. */
  198. $form = new Form($db);
  199. $formticket = new FormTicket($db);
  200. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  201. $hookmanager->initHooks(array('ticketpublicview', 'globalcard'));
  202. if (!getDolGlobalString('TICKET_ENABLE_PUBLIC_INTERFACE')) {
  203. print '<div class="error">'.$langs->trans('TicketPublicInterfaceForbidden').'</div>';
  204. $db->close();
  205. exit();
  206. }
  207. $arrayofjs = array();
  208. $arrayofcss = array(getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE', '/ticket/').'css/styles.css.php');
  209. llxHeaderTicket($langs->trans("Tickets"), "", 0, 0, $arrayofjs, $arrayofcss);
  210. if ($action == "view_ticket" || $action == "presend" || $action == "close" || $action == "confirm_public_close") {
  211. if ($display_ticket) {
  212. print '<!-- public view ticket -->';
  213. print '<div class="ticketpublicarea ticketlargemargin centpercent">';
  214. // Confirmation close
  215. if ($action == 'close') {
  216. print $form->formconfirm($_SERVER["PHP_SELF"]."?track_id=".$track_id.(!empty($entity) && isModEnabled('multicompany') ? '&entity='.$entity : ''), $langs->trans("CloseATicket"), $langs->trans("ConfirmCloseAticket"), "confirm_public_close", '', '', 1);
  217. }
  218. print '<div id="form_view_ticket" class="margintoponly">';
  219. print '<table class="ticketpublictable centpercent tableforfield">';
  220. // Ref
  221. print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>';
  222. print img_picto('', 'ticket', 'class="pictofixedwidth"');
  223. print dol_escape_htmltag($object->dao->ref);
  224. print '</td></tr>';
  225. // Tracking ID
  226. print '<tr><td>'.$langs->trans("TicketTrackId").'</td><td>';
  227. print dol_escape_htmltag($object->dao->track_id);
  228. print '</td></tr>';
  229. // Subject
  230. print '<tr><td>'.$langs->trans("Subject").'</td><td>';
  231. print '<span class="bold">';
  232. print dol_escape_htmltag($object->dao->subject);
  233. print '</span>';
  234. print '</td></tr>';
  235. // Statut
  236. print '<tr><td>'.$langs->trans("Status").'</td><td>';
  237. print $object->dao->getLibStatut(2);
  238. print '</td></tr>';
  239. // Type
  240. print '<tr><td>'.$langs->trans("Type").'</td><td>';
  241. print dol_escape_htmltag($object->dao->type_label);
  242. print '</td></tr>';
  243. // Category
  244. print '<tr><td>'.$langs->trans("Category").'</td><td>';
  245. if ($object->dao->category_label) {
  246. print img_picto('', 'category', 'class="pictofixedwidth"');
  247. print dol_escape_htmltag($object->dao->category_label);
  248. }
  249. print '</td></tr>';
  250. // Severity
  251. print '<tr><td>'.$langs->trans("Severity").'</td><td>';
  252. print dol_escape_htmltag($object->dao->severity_label);
  253. print '</td></tr>';
  254. // Creation date
  255. print '<tr><td>'.$langs->trans("DateCreation").'</td><td>';
  256. print dol_print_date($object->dao->datec, 'dayhour');
  257. print '</td></tr>';
  258. // Author
  259. print '<tr><td>'.$langs->trans("Author").'</td><td>';
  260. if ($object->dao->fk_user_create > 0) {
  261. $langs->load("users");
  262. $fuser = new User($db);
  263. $fuser->fetch($object->dao->fk_user_create);
  264. print img_picto('', 'user', 'class="pictofixedwidth"');
  265. print $fuser->getFullName($langs);
  266. } else {
  267. print img_picto('', 'email', 'class="pictofixedwidth"');
  268. print dol_escape_htmltag($object->dao->origin_email);
  269. }
  270. print '</td></tr>';
  271. // Read date
  272. if (!empty($object->dao->date_read)) {
  273. print '<tr><td>'.$langs->trans("TicketReadOn").'</td><td>';
  274. print dol_print_date($object->dao->date_read, 'dayhour');
  275. print '</td></tr>';
  276. }
  277. // Close date
  278. if (!empty($object->dao->date_close)) {
  279. print '<tr><td>'.$langs->trans("TicketCloseOn").'</td><td>';
  280. print dol_print_date($object->dao->date_close, 'dayhour');
  281. print '</td></tr>';
  282. }
  283. // User assigned
  284. print '<tr><td>'.$langs->trans("AssignedTo").'</td><td>';
  285. if ($object->dao->fk_user_assign > 0) {
  286. $fuser = new User($db);
  287. $fuser->fetch($object->dao->fk_user_assign);
  288. print img_picto('', 'user', 'class="pictofixedwidth"');
  289. print $fuser->getFullName($langs, 0);
  290. }
  291. print '</td></tr>';
  292. // External contributors
  293. if (getDolGlobalInt('TICKET_PUBLIC_DISPLAY_EXTERNAL_CONTRIBUTORS')) {
  294. print '<tr><td>'.$langs->trans("ExternalContributors").'</td><td>';
  295. if ($object->dao->id > 0) {
  296. $contactlist = $object->dao->liste_contact(-1, 'external');
  297. foreach ($contactlist as $externalContributor) {
  298. print img_picto('', 'contact', 'class="pictofixedwidth"');
  299. print $externalContributor["lastname"]." ".$externalContributor["firstname"]."<br>";
  300. }
  301. }
  302. print '</td></tr>';
  303. }
  304. // Add new external contributor
  305. if (getDolGlobalInt('TICKET_PUBLIC_SELECT_EXTERNAL_CONTRIBUTORS') && !empty($object->dao->fk_soc)) {
  306. print '<form method="post" id="form_view_add_contact" name="form_view_add_contact" action="'.$_SERVER['PHP_SELF'].'?track_id='.$object->dao->track_id.'">';
  307. print '<input type="hidden" name="token" value="'.newToken().'">';
  308. print '<input type="hidden" name="action" value="add_contact">';
  309. print '<input type="hidden" name="email" value="'.$_SESSION['email_customer'].'">';
  310. print '<tr><td>'.$langs->trans("AddContributor").'</td><td>';
  311. print $form->selectcontacts($object->dao->fk_soc, '', 'contactid', 3, '', '', 1, 'minwidth100imp widthcentpercentminusxx maxwidth400');
  312. print '<input type="submit" class="button smallpaddingimp reposition" name="btn_add_contact" value="'.$langs->trans('Add').'" />';
  313. print '</td></tr></form>';
  314. }
  315. // Progression
  316. if (getDolGlobalString('TICKET_SHOW_PROGRESSION')) {
  317. print '<tr><td>'.$langs->trans("Progression").'</td><td>';
  318. print($object->dao->progress > 0 ? dol_escape_htmltag($object->dao->progress) : '0').'%';
  319. print '</td></tr>';
  320. }
  321. // Other attributes
  322. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  323. print '</table>';
  324. print '</div>';
  325. print '<div style="clear: both; margin-top: 1.5em;"></div>';
  326. if ($action == 'presend') {
  327. print '<br>';
  328. print load_fiche_titre($langs->trans('TicketAddMessage'), '', 'conversation');
  329. $formticket = new FormTicket($db);
  330. $formticket->action = "add_message";
  331. $formticket->track_id = $object->dao->track_id;
  332. $formticket->trackid = 'tic'.$object->dao->id;
  333. $baseurl = getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE', DOL_URL_ROOT.'/public/ticket/');
  334. $formticket->param = array('track_id' => $object->dao->track_id, 'fk_user_create' => '-1',
  335. 'returnurl' => $baseurl.'view.php'.(!empty($entity) && isModEnabled('multicompany')?'?entity='.$entity:''));
  336. $formticket->withfile = 2;
  337. $formticket->withcancel = 1;
  338. $formticket->showMessageForm('100%');
  339. }
  340. if ($action != 'presend') {
  341. $baseurl = getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE', DOL_URL_ROOT.'/public/ticket/');
  342. print '<form method="post" id="form_view_ticket_list" name="form_view_ticket_list" action="'.$baseurl.'list.php'.(!empty($entity) && isModEnabled('multicompany')?'?entity='.$entity:'').'">';
  343. print '<input type="hidden" name="token" value="'.newToken().'">';
  344. print '<input type="hidden" name="action" value="view_ticketlist">';
  345. print '<input type="hidden" name="track_id" value="'.$object->dao->track_id.'">';
  346. print '<input type="hidden" name="email" value="'.$_SESSION['email_customer'].'">';
  347. //print '<input type="hidden" name="search_fk_status" value="non_closed">';
  348. print "</form>\n";
  349. print '<div class="tabsAction">';
  350. // List ticket
  351. print '<div class="inline-block divButAction"><a class="left" style="padding-right: 50px" href="javascript:$(\'#form_view_ticket_list\').submit();">'.$langs->trans('ViewMyTicketList').'</a></div>';
  352. if ($object->dao->fk_statut < Ticket::STATUS_CLOSED) {
  353. // New message
  354. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=presend&mode=init&track_id='.$object->dao->track_id.(!empty($entity) && isModEnabled('multicompany') ? '&entity='.$entity : '').'&token='.newToken().'">'.$langs->trans('TicketAddMessage').'</a></div>';
  355. // Close ticket
  356. if ($object->dao->fk_statut >= Ticket::STATUS_NOT_READ && $object->dao->fk_statut < Ticket::STATUS_CLOSED) {
  357. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=close&track_id='.$object->dao->track_id.(!empty($entity) && isModEnabled('multicompany') ? '&entity='.$entity : '').'&token='.newToken().'">'.$langs->trans('CloseTicket').'</a></div>';
  358. }
  359. }
  360. print '</div>';
  361. }
  362. print '</div>';
  363. // Message list
  364. print '<div class="ticketpublicarea ticketlargemargin centpercent">';
  365. print load_fiche_titre($langs->trans('TicketMessagesList'), '', 'conversation');
  366. print '</div>';
  367. $object->viewTicketMessages(false, true, $object->dao);
  368. } else {
  369. print '<!-- public view ticket -->';
  370. print '<div class="ticketpublicarea ticketlargemargin centpercent">';
  371. print '<div class="error">Not Allowed<br><a href="'.$_SERVER['PHP_SELF'].'?track_id='.$object->dao->track_id.(!empty($entity) && isModEnabled('multicompany') ? '?entity='.$entity : '').'" rel="nofollow noopener">'.$langs->trans('Back').'</a></div>';
  372. print '</div>';
  373. }
  374. } else {
  375. print '<!-- public view ticket -->';
  376. print '<div class="ticketpublicarea ticketlargemargin centpercent">';
  377. print '<div class="center opacitymedium margintoponly marginbottomonly ticketlargemargin">'.$langs->trans("TicketPublicMsgViewLogIn").'</div>';
  378. print '<div id="form_view_ticket">';
  379. print '<form method="post" name="form_view_ticket" action="'.$_SERVER['PHP_SELF'].(!empty($entity) && isModEnabled('multicompany') ? '?entity='.$entity : '').'">';
  380. print '<input type="hidden" name="token" value="'.newToken().'">';
  381. print '<input type="hidden" name="action" value="view_ticket">';
  382. print '<p><label for="track_id" style="display: inline-block; width: 30%; "><span class="fieldrequired">'.$langs->trans("TicketTrackId").'</span></label>';
  383. print '<input size="30" id="track_id" name="track_id" value="'.(GETPOST('track_id', 'alpha') ? GETPOST('track_id', 'alpha') : '').'" />';
  384. print '</p>';
  385. print '<p><label for="email" style="display: inline-block; width: 30%; "><span class="fieldrequired">'.$langs->trans('Email').'</span></label>';
  386. print '<input size="30" id="email" name="email" value="'.(GETPOST('email', 'alpha') ? GETPOST('email', 'alpha') : (!empty($_SESSION['customer_email']) ? $_SESSION['customer_email'] : "")).'" />';
  387. print '</p>';
  388. print '<p style="text-align: center; margin-top: 1.5em;">';
  389. print '<input type="submit" class="button" name="btn_view_ticket" value="'.$langs->trans('ViewTicket').'" />';
  390. print ' &nbsp; ';
  391. print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  392. print "</p>\n";
  393. print "</form>\n";
  394. print "</div>\n";
  395. print '</div>';
  396. }
  397. if (getDolGlobalInt('TICKET_SHOW_COMPANY_FOOTER')) {
  398. // End of page
  399. htmlPrintOnlineFooter($mysoc, $langs, 0, $suffix, $object);
  400. }
  401. llxFooter('', 'public');
  402. $db->close();