dolibarr  16.0.5
messaging.php
Go to the documentation of this file.
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 <http://www.gnu.org/licenses/>.
16  */
17 
24 require '../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticket.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
28 require_once DOL_DOCUMENT_ROOT."/core/lib/company.lib.php";
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array('companies', 'other', 'ticket'));
35 
36 // Get parameters
37 $id = GETPOST('id', 'int');
38 $ref = GETPOST('ref', 'alpha');
39 $track_id = GETPOST('track_id', 'alpha', 3);
40 $socid = GETPOST('socid', 'int');
41 $action = GETPOST('action', 'aZ09');
42 
43 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
44 $sortfield = GETPOST("sortfield", "aZ09comma");
45 $sortorder = GETPOST("sortorder", 'aZ09comma');
46 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
47 $page = is_numeric($page) ? $page : 0;
48 $page = $page == -1 ? 0 : $page;
49 if (!$sortfield) {
50  $sortfield = "a.datep,a.id";
51 }
52 if (!$sortorder) {
53  $sortorder = "DESC";
54 }
55 $offset = $limit * $page;
56 $pageprev = $page - 1;
57 $pagenext = $page + 1;
58 
59 if (GETPOST('actioncode', 'array')) {
60  $actioncode = GETPOST('actioncode', 'array', 3);
61  if (!count($actioncode)) {
62  $actioncode = '0';
63  }
64 } else {
65  $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));
66 }
67 $search_agenda_label = GETPOST('search_agenda_label');
68 
69 $object = new Ticket($db);
70 $object->fetch($id, $ref, $track_id);
71 
72 $extrafields = new ExtraFields($db);
73 $extrafields->fetch_name_optionals_label($object->table_element);
74 
75 if (!$action) {
76  $action = 'view';
77 }
78 
79 $permissiontoadd = $user->rights->ticket->write;
80 
81 // Security check
82 $id = GETPOST("id", 'int');
83 if ($user->socid > 0) $socid = $user->socid;
84 $result = restrictedArea($user, 'ticket', $object->id, '');
85 
86 // restrict access for externals users
87 if ($user->socid > 0 && ($object->fk_soc != $user->socid)) {
89 }
90 // or for unauthorized internals users
91 if (!$user->socid && (!empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY) && $object->fk_user_assign != $user->id) && !$user->rights->ticket->manage) {
93 }
94 
95 
96 /*
97  * Actions
98  */
99 
100 $parameters = array('id'=>$socid);
101 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
102 if ($reshook < 0) {
103  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
104 }
105 
106 if (empty($reshook)) {
107  // Set view style
108  $_SESSION['ticket-view-type'] = "messaging";
109 }
110 
111 // Purge search criteria
112 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
113  $actioncode = '';
114  $search_agenda_label = '';
115 }
116 
117 
118 
119 /*
120  * View
121  */
122 
123 $form = new Form($db);
124 $userstat = new User($db);
125 $formticket = new FormTicket($db);
126 
127 $title = $langs->trans("Ticket").' - '.$object->ref.' '.$object->name;
128 if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/ticketnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
129  $title = $object->ref.' '.$object->name.' - '.$langs->trans("Info");
130 }
131 $help_url = 'FR:DocumentationModuleTicket';
132 llxHeader('', $title, $help_url);
133 
134 if ($socid > 0) {
135  $object->fetch_thirdparty();
136  $head = societe_prepare_head($object->thirdparty);
137 
138  print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
139 
140  dol_banner_tab($object->thirdparty, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
141 
142  print dol_get_fiche_end();
143 }
144 
145 if (!$user->socid && !empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY)) {
146  $object->next_prev_filter = "te.fk_user_assign = '".$user->id."'";
147 } elseif ($user->socid > 0) {
148  $object->next_prev_filter = "te.fk_soc = '".$user->socid."'";
149 }
150 $head = ticket_prepare_head($object);
151 
152 print dol_get_fiche_head($head, 'tabTicketLogs', $langs->trans("Ticket"), 0, 'ticket');
153 
154 $morehtmlref = '<div class="refidno">';
155 $morehtmlref .= $object->subject;
156 // Author
157 if ($object->fk_user_create > 0) {
158  $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
159 
160  $fuser = new User($db);
161  $fuser->fetch($object->fk_user_create);
162  $morehtmlref .= $fuser->getNomUrl(-1);
163 } elseif (!empty($object->email_msgid)) {
164  $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
165  $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
166  $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$form->textwithpicto($langs->trans("CreatedByEmailCollector"), $langs->trans("EmailMsgID").': '.$object->email_msgid).')</small>';
167 } elseif (!empty($object->origin_email)) {
168  $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
169  $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
170  $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$langs->trans("CreatedByPublicPortal").')</small>';
171 }
172 
173 // Thirdparty
174 if (isModEnabled('societe')) {
175  $morehtmlref .= '<br>'.$langs->trans('ThirdParty');
176  /*if ($action != 'editcustomer' && $object->fk_statut < 8 && !$user->socid && $user->rights->ticket->write) {
177  $morehtmlref.='<a class="editfielda" href="' . $url_page_current . '?action=editcustomer&token='.newToken().'&track_id=' . $object->track_id . '">' . img_edit($langs->transnoentitiesnoconv('Edit'), 1) . '</a>';
178  }*/
179  $morehtmlref .= ' : ';
180  if ($action == 'editcustomer') {
181  $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'editcustomer', '', 1, 0, 0, array(), 1);
182  } else {
183  $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'none', '', 1, 0, 0, array(), 1);
184  }
185 }
186 
187 // Project
188 if (isModEnabled('project')) {
189  $langs->load("projects");
190  $morehtmlref .= '<br>'.$langs->trans('Project');
191  if ($user->rights->ticket->write) {
192  if ($action != 'classify') {
193  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>';
194  $morehtmlref .= ' : ';
195  }
196  if ($action == 'classify') {
197  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
198  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
199  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
200  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
201  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1);
202  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
203  $morehtmlref .= '</form>';
204  } else {
205  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
206  }
207  } else {
208  if (!empty($object->fk_project)) {
209  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
210  $proj = new Project($db);
211  $proj->fetch($object->fk_project);
212  $morehtmlref .= $proj->getNomUrl(1);
213  } else {
214  $morehtmlref .= '';
215  }
216  }
217 }
218 
219 $morehtmlref .= '</div>';
220 
221 $linkback = '<a href="'.DOL_URL_ROOT.'/ticket/list.php"><strong>'.$langs->trans("BackToList").'</strong></a> ';
222 
223 dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
224 
225 print dol_get_fiche_end();
226 
227 print '<br>';
228 
229 
230 if (!empty($object->id)) {
231  $param = '&id='.$object->id;
232  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
233  $param .= '&contextpage='.$contextpage;
234  }
235  if ($limit > 0 && $limit != $conf->liste_limit) {
236  $param .= '&limit='.$limit;
237  }
238 
239  $morehtmlright = '';
240 
241  $messagingUrl = DOL_URL_ROOT.'/ticket/messaging.php?track_id='.$object->track_id;
242  $morehtmlright .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 1, array('morecss'=>'btnTitleSelected'));
243  $messagingUrl = DOL_URL_ROOT.'/ticket/agenda.php?track_id='.$object->track_id;
244  $morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 1);
245 
246 
247  // Show link to add a message (if read and not closed)
248  $btnstatus = $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage";
249  $url = 'card.php?track_id='.$object->track_id.'&action=presend_addmessage&mode=init&backtopage='.urlencode($_SERVER["PHP_SELF"].'?track_id='.$object->track_id);
250  $morehtmlright .= dolGetButtonTitle($langs->trans('TicketAddMessage'), '', 'fa fa-comment-dots', $url, 'add-new-ticket-title-button', $btnstatus);
251 
252  // Show link to add event (if read and not closed)
253  $btnstatus = $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage";
254  $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"].'?track_id='.$object->track_id);
255  $morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', $url, 'add-new-ticket-even-button', $btnstatus);
256 
257 
258  print_barre_liste($langs->trans("ActionsOnTicket"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 1);
259 
260  // List of all actions
261  $filters = array();
262  $filters['search_agenda_label'] = $search_agenda_label;
263  show_ticket_messaging($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
264 }
265 
266 // End of page
267 llxFooter();
268 $db->close();
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
Project
Class to manage projects.
Definition: project.class.php:35
ticket_prepare_head
ticket_prepare_head($object)
Build tabs for a Ticket object.
Definition: ticket.lib.php:76
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
dolGetButtonTitle
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
Definition: functions.lib.php:10605
print_barre_liste
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
Definition: functions.lib.php:5257
FormTicket
Definition: html.formticket.class.php:43
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
societe_prepare_head
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:42
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
show_ticket_messaging
show_ticket_messaging($conf, $langs, $db, $filterobj, $objcon='', $noprint=0, $actioncode='', $donetodo='done', $filters=array(), $sortfield='a.datep, a.id', $sortorder='DESC')
Show html area with actions for ticket messaging.
Definition: ticket.lib.php:281
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
Ticket
Class to generate the form for creating a new ticket.
Definition: html.formticket.class.php:31
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59