messaging.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <?php
  2. /* Copyright (C) - 2013-2016 Jean-François FERRY <hello@librethic.io>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/ticket/messaging.php
  19. * \ingroup ticket
  20. * \brief Page with events on ticket
  21. */
  22. // Load Dolibarr environment
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticket.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
  27. require_once DOL_DOCUMENT_ROOT."/core/lib/company.lib.php";
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  31. if (isModEnabled('project')) {
  32. include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  33. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  34. include_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  35. }
  36. // Load translation files required by the page
  37. $langs->loadLangs(array('companies', 'other', 'ticket'));
  38. // Get parameters
  39. $id = GETPOST('id', 'int');
  40. $ref = GETPOST('ref', 'alpha');
  41. $track_id = GETPOST('track_id', 'alpha', 3);
  42. $socid = GETPOST('socid', 'int');
  43. $action = GETPOST('action', 'aZ09');
  44. // Store current page url
  45. $url_page_current = DOL_URL_ROOT.'/ticket/messaging.php';
  46. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  47. $sortfield = GETPOST("sortfield", "aZ09comma");
  48. $sortorder = GETPOST("sortorder", 'aZ09comma');
  49. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  50. $page = is_numeric($page) ? $page : 0;
  51. $page = $page == -1 ? 0 : $page;
  52. if (!$sortfield) {
  53. $sortfield = "a.datep,a.id";
  54. }
  55. if (!$sortorder) {
  56. $sortorder = "DESC";
  57. }
  58. $offset = $limit * $page;
  59. $pageprev = $page - 1;
  60. $pagenext = $page + 1;
  61. if (GETPOST('actioncode', 'array')) {
  62. $actioncode = GETPOST('actioncode', 'array', 3);
  63. if (!count($actioncode)) {
  64. $actioncode = '0';
  65. }
  66. } else {
  67. $actioncode = GETPOST("actioncode", "alpha", 3) ?GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT'));
  68. }
  69. $search_rowid = GETPOST('search_rowid');
  70. $search_agenda_label = GETPOST('search_agenda_label');
  71. $object = new Ticket($db);
  72. $object->fetch($id, $ref, $track_id);
  73. $extrafields = new ExtraFields($db);
  74. $extrafields->fetch_name_optionals_label($object->table_element);
  75. if (!$action) {
  76. $action = 'view';
  77. }
  78. // Security check
  79. $id = GETPOST("id", 'int');
  80. if ($user->socid > 0) $socid = $user->socid;
  81. $result = restrictedArea($user, 'ticket', $object->id, '');
  82. // restrict access for externals users
  83. if ($user->socid > 0 && ($object->fk_soc != $user->socid)) {
  84. accessforbidden();
  85. }
  86. // or for unauthorized internals users
  87. if (!$user->socid && (!empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY) && $object->fk_user_assign != $user->id) && !$user->hasRight('ticket', 'manage')) {
  88. accessforbidden();
  89. }
  90. $permissiontoadd = $user->rights->ticket->write;
  91. /*
  92. * Actions
  93. */
  94. $parameters = array('id'=>$socid);
  95. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  96. if ($reshook < 0) {
  97. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  98. }
  99. if (empty($reshook)) {
  100. // Set view style
  101. $_SESSION['ticket-view-type'] = "messaging";
  102. }
  103. // Purge search criteria
  104. 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
  105. $actioncode = '';
  106. $search_agenda_label = '';
  107. }
  108. // Set parent company
  109. if ($action == 'set_thirdparty' && $user->hasRight('ticket', 'write')) {
  110. if ($object->fetch(GETPOST('id', 'int'), '', GETPOST('track_id', 'alpha')) >= 0) {
  111. $result = $object->setCustomer(GETPOST('editcustomer', 'int'));
  112. $url = $_SERVER["PHP_SELF"].'?track_id='.GETPOST('track_id', 'alpha');
  113. header("Location: ".$url);
  114. exit();
  115. }
  116. }
  117. /*
  118. * View
  119. */
  120. $form = new Form($db);
  121. $userstat = new User($db);
  122. $formticket = new FormTicket($db);
  123. $title = $langs->trans("Ticket").' - '.$object->ref.' '.$object->name;
  124. if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/ticketnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
  125. $title = $object->ref.' '.$object->name.' - '.$langs->trans("Info");
  126. }
  127. $help_url = 'FR:DocumentationModuleTicket';
  128. llxHeader('', $title, $help_url);
  129. if ($socid > 0) {
  130. $object->fetch_thirdparty();
  131. $head = societe_prepare_head($object->thirdparty);
  132. print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
  133. dol_banner_tab($object->thirdparty, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
  134. print dol_get_fiche_end();
  135. }
  136. if (!$user->socid && !empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY)) {
  137. $object->next_prev_filter = "te.fk_user_assign = ".((int) $user->id);
  138. } elseif ($user->socid > 0) {
  139. $object->next_prev_filter = "te.fk_soc = ".((int) $user->socid);
  140. }
  141. $head = ticket_prepare_head($object);
  142. print dol_get_fiche_head($head, 'tabTicketLogs', $langs->trans("Ticket"), 0, 'ticket');
  143. $morehtmlref = '<div class="refidno">';
  144. $morehtmlref .= $object->subject;
  145. // Author
  146. if ($object->fk_user_create > 0) {
  147. $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
  148. $fuser = new User($db);
  149. $fuser->fetch($object->fk_user_create);
  150. $morehtmlref .= $fuser->getNomUrl(-1);
  151. } elseif (!empty($object->email_msgid)) {
  152. $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
  153. $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
  154. $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$form->textwithpicto($langs->trans("CreatedByEmailCollector"), $langs->trans("EmailMsgID").': '.$object->email_msgid).')</small>';
  155. } elseif (!empty($object->origin_email)) {
  156. $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
  157. $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
  158. $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$langs->trans("CreatedByPublicPortal").')</small>';
  159. }
  160. // Thirdparty
  161. if (isModEnabled("societe")) {
  162. if (isModEnabled("societe")) {
  163. $morehtmlref .= '<br>';
  164. $morehtmlref .= img_picto($langs->trans("ThirdParty"), 'company', 'class="pictofixedwidth"');
  165. if ($action != 'editcustomer' && $permissiontoadd) {
  166. $morehtmlref .= '<a class="editfielda" href="'.$url_page_current.'?action=editcustomer&token='.newToken().'&track_id='.$object->track_id.'">'.img_edit($langs->transnoentitiesnoconv('SetThirdParty'), 0).'</a> ';
  167. }
  168. $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, $action == 'editcustomer' ? 'editcustomer' : 'none', '', 1, 0, 0, array(), 1);
  169. }
  170. }
  171. // Project
  172. if (isModEnabled('project')) {
  173. $langs->load("projects");
  174. $morehtmlref .= '<br>';
  175. if (0) {
  176. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  177. if ($action != 'classify') {
  178. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  179. }
  180. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  181. } else {
  182. if (!empty($object->fk_project)) {
  183. $proj = new Project($db);
  184. $proj->fetch($object->fk_project);
  185. $morehtmlref .= $proj->getNomUrl(1);
  186. if ($proj->title) {
  187. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  188. }
  189. }
  190. }
  191. }
  192. $morehtmlref .= '</div>';
  193. $linkback = '<a href="'.DOL_URL_ROOT.'/ticket/list.php"><strong>'.$langs->trans("BackToList").'</strong></a> ';
  194. dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  195. print dol_get_fiche_end();
  196. print '<br>';
  197. if (!empty($object->id)) {
  198. $param = '&id='.$object->id;
  199. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  200. $param .= '&contextpage='.$contextpage;
  201. }
  202. if ($limit > 0 && $limit != $conf->liste_limit) {
  203. $param .= '&limit='.$limit;
  204. }
  205. $morehtmlright = '';
  206. $messagingUrl = DOL_URL_ROOT.'/ticket/messaging.php?track_id='.$object->track_id;
  207. $morehtmlright .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 1, array('morecss'=>'btnTitleSelected'));
  208. $messagingUrl = DOL_URL_ROOT.'/ticket/agenda.php?track_id='.$object->track_id;
  209. $morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 1);
  210. // Show link to send an email (if read and not closed)
  211. $btnstatus = $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage";
  212. $url = 'card.php?track_id='.$object->track_id.'&action=presend_addmessage&mode=init&private_message=0&send_email=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?track_id='.$object->track_id).'#formmailbeforetitle';
  213. $morehtmlright .= dolGetButtonTitle($langs->trans('SendMail'), '', 'fa fa-paper-plane', $url, 'email-title-button', $btnstatus);
  214. // Show link to add a private message (if read and not closed)
  215. $btnstatus = $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage";
  216. $url = 'card.php?track_id='.$object->track_id.'&action=presend_addmessage&mode=init&backtopage='.urlencode($_SERVER["PHP_SELF"].'?track_id='.$object->track_id).'#formmailbeforetitle';
  217. $morehtmlright .= dolGetButtonTitle($langs->trans('TicketAddMessage'), '', 'fa fa-comment-dots', $url, 'add-new-ticket-title-button', $btnstatus);
  218. // Show link to add event (if read and not closed)
  219. $btnstatus = $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage";
  220. $url = DOL_URL_ROOT.'/comm/action/card.php?action=create&datep=now&origin=ticket&originid='.$object->id.'&projectid='.$object->fk_project.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?track_id='.$object->track_id);
  221. $morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', $url, 'add-new-ticket-even-button', $btnstatus);
  222. require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
  223. $cachekey = 'count_events_ticket_'.$object->id;
  224. $nbEvent = dol_getcache($cachekey);
  225. $titlelist = $langs->trans("ActionsOnTicket").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>': '');
  226. print_barre_liste($titlelist, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 0);
  227. // List of all actions
  228. $filters = array();
  229. $filters['search_agenda_label'] = $search_agenda_label;
  230. $filters['search_rowid'] = $search_rowid;
  231. show_actions_messaging($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
  232. }
  233. // End of page
  234. llxFooter();
  235. $db->close();