agenda.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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/agenda.php
  19. * \ingroup ticket
  20. * \brief Page with events on ticket
  21. */
  22. require '../main.inc.php';
  23. require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticket.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
  26. require_once DOL_DOCUMENT_ROOT."/core/lib/company.lib.php";
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array('companies', 'other', 'ticket'));
  32. // Get parameters
  33. $id = GETPOST('id', 'int');
  34. $ref = GETPOST('ref', 'alpha');
  35. $track_id = GETPOST('track_id', 'alpha', 3);
  36. $socid = GETPOST('socid', 'int');
  37. $action = GETPOST('action', 'aZ09');
  38. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  39. $sortfield = GETPOST('sortfield', 'aZ09comma');
  40. $sortorder = GETPOST('sortorder', 'aZ09comma');
  41. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  42. $page = is_numeric($page) ? $page : 0;
  43. $page = $page == -1 ? 0 : $page;
  44. if (!$sortfield) {
  45. $sortfield = "a.datep,a.id";
  46. }
  47. if (!$sortorder) {
  48. $sortorder = "DESC";
  49. }
  50. $offset = $limit * $page;
  51. $pageprev = $page - 1;
  52. $pagenext = $page + 1;
  53. if (GETPOST('actioncode', 'array')) {
  54. $actioncode = GETPOST('actioncode', 'array', 3);
  55. if (!count($actioncode)) {
  56. $actioncode = '0';
  57. }
  58. } else {
  59. $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));
  60. }
  61. $search_agenda_label = GETPOST('search_agenda_label');
  62. $object = new Ticket($db);
  63. $object->fetch($id, $ref, $track_id);
  64. $extrafields = new ExtraFields($db);
  65. $extrafields->fetch_name_optionals_label($object->table_element);
  66. if (!$action) {
  67. $action = 'view';
  68. }
  69. // Security check
  70. $id = GETPOST("id", 'int');
  71. if ($user->socid > 0) $socid = $user->socid;
  72. $result = restrictedArea($user, 'ticket', $object->id, '');
  73. // restrict access for externals users
  74. if ($user->socid > 0 && ($object->fk_soc != $user->socid)) {
  75. accessforbidden();
  76. }
  77. // or for unauthorized internals users
  78. if (!$user->socid && (!empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY) && $object->fk_user_assign != $user->id) && !$user->rights->ticket->manage) {
  79. accessforbidden();
  80. }
  81. /*
  82. * Actions
  83. */
  84. $parameters = array('id'=>$socid);
  85. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  86. if ($reshook < 0) {
  87. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  88. }
  89. if (empty($reshook)) {
  90. // Set view style
  91. $_SESSION['ticket-view-type'] = "list";
  92. }
  93. // Purge search criteria
  94. 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
  95. $actioncode = '';
  96. $search_agenda_label = '';
  97. }
  98. /*
  99. * View
  100. */
  101. $form = new Form($db);
  102. $userstat = new User($db);
  103. $formticket = new FormTicket($db);
  104. $title = $langs->trans("Ticket").' - '.$object->ref.' '.$object->name;
  105. if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/ticketnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
  106. $title = $object->ref.' '.$object->name.' - '.$langs->trans("Info");
  107. }
  108. $help_url = 'EN:Module_Agenda_En|FR:Module_Agenda';
  109. llxHeader('', $title, $help_url);
  110. if ($socid > 0) {
  111. $object->fetch_thirdparty();
  112. $head = societe_prepare_head($object->thirdparty);
  113. print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
  114. dol_banner_tab($object->thirdparty, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
  115. print dol_get_fiche_end();
  116. }
  117. if (!$user->socid && !empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY)) {
  118. $object->next_prev_filter = "te.fk_user_assign = '".$user->id."'";
  119. } elseif ($user->socid > 0) {
  120. $object->next_prev_filter = "te.fk_soc = '".$user->socid."'";
  121. }
  122. $head = ticket_prepare_head($object);
  123. print dol_get_fiche_head($head, 'tabTicketLogs', $langs->trans("Ticket"), 0, 'ticket');
  124. $morehtmlref = '<div class="refidno">';
  125. $morehtmlref .= $object->subject;
  126. // Author
  127. if ($object->fk_user_create > 0) {
  128. $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
  129. $langs->load("users");
  130. $fuser = new User($db);
  131. $fuser->fetch($object->fk_user_create);
  132. $morehtmlref .= $fuser->getNomUrl(-1);
  133. } elseif (!empty($object->email_msgid)) {
  134. $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
  135. $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
  136. $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$form->textwithpicto($langs->trans("CreatedByEmailCollector"), $langs->trans("EmailMsgID").': '.$object->email_msgid).')</small>';
  137. } elseif (!empty($object->origin_email)) {
  138. $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
  139. $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
  140. $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$langs->trans("CreatedByPublicPortal").')</small>';
  141. }
  142. // Thirdparty
  143. if (isModEnabled('societe')) {
  144. $morehtmlref .= '<br>'.$langs->trans('ThirdParty');
  145. /*if ($action != 'editcustomer' && $object->fk_statut < 8 && !$user->socid && $user->rights->ticket->write) {
  146. $morehtmlref.='<a class="editfielda" href="' . $url_page_current . '?action=editcustomer&token='.newToken().'&track_id=' . $object->track_id . '">' . img_edit($langs->transnoentitiesnoconv('Edit'), 1) . '</a>';
  147. }*/
  148. $morehtmlref .= ' : ';
  149. if ($action == 'editcustomer') {
  150. $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'editcustomer', '', 1, 0, 0, array(), 1);
  151. } else {
  152. $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'none', '', 1, 0, 0, array(), 1);
  153. }
  154. }
  155. // Project
  156. if (isModEnabled('project')) {
  157. $langs->load("projects");
  158. $morehtmlref .= '<br>'.$langs->trans('Project');
  159. if ($user->rights->ticket->write) {
  160. if ($action != 'classify') {
  161. //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>';
  162. $morehtmlref .= ' : ';
  163. }
  164. if ($action == 'classify') {
  165. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  166. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  167. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  168. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  169. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1);
  170. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  171. $morehtmlref .= '</form>';
  172. } else {
  173. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  174. }
  175. } else {
  176. if (!empty($object->fk_project)) {
  177. $proj = new Project($db);
  178. $proj->fetch($object->fk_project);
  179. $morehtmlref .= $proj->getNomUrl(1);
  180. } else {
  181. $morehtmlref .= '';
  182. }
  183. }
  184. }
  185. $morehtmlref .= '</div>';
  186. $linkback = '<a href="'.DOL_URL_ROOT.'/ticket/list.php"><strong>'.$langs->trans("BackToList").'</strong></a> ';
  187. dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
  188. print dol_get_fiche_end();
  189. print '<br>';
  190. if (!empty($object->id)) {
  191. $param = '&id='.$object->id;
  192. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  193. $param .= '&contextpage='.$contextpage;
  194. }
  195. if ($limit > 0 && $limit != $conf->liste_limit) {
  196. $param .= '&limit='.$limit;
  197. }
  198. $morehtmlright = '';
  199. $messagingUrl = DOL_URL_ROOT.'/ticket/messaging.php?track_id='.$object->track_id;
  200. $morehtmlright .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 1);
  201. $messagingUrl = DOL_URL_ROOT.'/ticket/agenda.php?track_id='.$object->track_id;
  202. $morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 1, array('morecss'=>'btnTitleSelected'));
  203. // Show link to add a message (if read and not closed)
  204. $btnstatus = $object->fk_statut < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage";
  205. $url = 'card.php?track_id='.$object->track_id.'&action=presend_addmessage&mode=init';
  206. $morehtmlright .= dolGetButtonTitle($langs->trans('TicketAddMessage'), '', 'fa fa-comment-dots', $url, 'add-new-ticket-title-button', $btnstatus);
  207. // Show link to add event (if read and not closed)
  208. $btnstatus = $object->fk_statut < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage";
  209. $url = DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.date('YmdHi').'&origin=ticket&originid='.$object->id.'&projectid='.$object->fk_project.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id);
  210. $morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', $url, 'add-new-ticket-even-button', $btnstatus);
  211. print_barre_liste($langs->trans("ActionsOnTicket"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 1);
  212. // List of all actions
  213. $filters = array();
  214. $filters['search_agenda_label'] = $search_agenda_label;
  215. show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
  216. }
  217. // End of page
  218. llxFooter();
  219. $db->close();