dolibarr  13.0.2
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) $sortfield = "a.datep,a.id";
50 if (!$sortorder) $sortorder = "desc";
51 $offset = $limit * $page;
52 $pageprev = $page - 1;
53 $pagenext = $page + 1;
54 
55 if (GETPOST('actioncode', 'array'))
56 {
57  $actioncode = GETPOST('actioncode', 'array', 3);
58  if (!count($actioncode)) $actioncode = '0';
59 } else {
60  $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));
61 }
62 $search_agenda_label = GETPOST('search_agenda_label');
63 
64 $object = new Ticket($db);
65 $object->fetch($id, $ref, $track_id);
66 
67 $extrafields = new ExtraFields($db);
68 $extrafields->fetch_name_optionals_label($object->table_element);
69 
70 if (!$action) {
71  $action = 'view';
72 }
73 
74 
75 // Security check
76 $id = GETPOST("id", 'int');
77 $socid = 0;
78 //if ($user->socid > 0) $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignement.
79 $result = restrictedArea($user, 'ticket', $id, '');
80 
81 if (!$user->rights->ticket->read) {
83 }
84 // restrict access for externals users
85 if ($user->socid > 0 && ($object->fk_soc != $user->socid))
86 {
88 }
89 // or for unauthorized internals users
90 if (!$user->socid && ($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY && $object->fk_user_assign != $user->id) && !$user->rights->ticket->manage) {
92 }
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) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
103 
104 if (empty($reshook))
105 {
106  // Set view style
107  $_SESSION['ticket-view-type'] = "messaging";
108 }
109 
110 // Purge search criteria
111 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
112 {
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) $title = $object->ref.' '.$object->name.' - '.$langs->trans("Info");
129 $help_url = 'FR:DocumentationModuleTicket';
130 llxHeader('', $title, $help_url);
131 
132 if ($socid > 0) {
133  $object->fetch_thirdparty();
134  $head = societe_prepare_head($object->thirdparty);
135 
136  print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
137 
138  dol_banner_tab($object->thirdparty, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
139 
141 }
142 
143 if (!$user->socid && $conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY) {
144  $object->next_prev_filter = "te.fk_user_assign = '".$user->id."'";
145 } elseif ($user->socid > 0) {
146  $object->next_prev_filter = "te.fk_soc = '".$user->socid."'";
147 }
148 $head = ticket_prepare_head($object);
149 
150 print dol_get_fiche_head($head, 'tabTicketLogs', $langs->trans("Ticket"), 0, 'ticket');
151 
152 $morehtmlref = '<div class="refidno">';
153 $morehtmlref .= $object->subject;
154 // Author
155 if ($object->fk_user_create > 0) {
156  $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
157 
158  $langs->load("users");
159  $fuser = new User($db);
160  $fuser->fetch($object->fk_user_create);
161  $morehtmlref .= $fuser->getNomUrl(0);
162 }
163 if (!empty($object->origin_email)) {
164  $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
165  $morehtmlref .= $object->origin_email.' <small>('.$langs->trans("TicketEmailOriginIssuer").')</small>';
166 }
167 
168 // Thirdparty
169 if (!empty($conf->societe->enabled))
170 {
171  $morehtmlref .= '<br>'.$langs->trans('ThirdParty');
172  /*if ($action != 'editcustomer' && $object->fk_statut < 8 && !$user->socid && $user->rights->ticket->write) {
173  $morehtmlref.='<a class="editfielda" href="' . $url_page_current . '?action=editcustomer&amp;track_id=' . $object->track_id . '">' . img_edit($langs->transnoentitiesnoconv('Edit'), 1) . '</a>';
174  }*/
175  $morehtmlref .= ' : ';
176  if ($action == 'editcustomer') {
177  $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'editcustomer', '', 1, 0, 0, array(), 1);
178  } else {
179  $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'none', '', 1, 0, 0, array(), 1);
180  }
181 }
182 
183 // Project
184 if (!empty($conf->projet->enabled))
185 {
186  $langs->load("projects");
187  $morehtmlref .= '<br>'.$langs->trans('Project');
188  if ($user->rights->ticket->write)
189  {
190  if ($action != 'classify') {
191  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>';
192  $morehtmlref .= ' : ';
193  }
194  if ($action == 'classify') {
195  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
196  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
197  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
198  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
199  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1);
200  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
201  $morehtmlref .= '</form>';
202  } else {
203  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
204  }
205  } else {
206  if (!empty($object->fk_project)) {
207  $proj = new Project($db);
208  $proj->fetch($object->fk_project);
209  $morehtmlref .= $proj->getNomUrl(1);
210  } else {
211  $morehtmlref .= '';
212  }
213  }
214 }
215 
216 $morehtmlref .= '</div>';
217 
218 $linkback = '<a href="'.dol_buildpath('/ticket/list.php', 1).'"><strong>'.$langs->trans("BackToList").'</strong></a> ';
219 
220 dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
221 
223 
224 print '<br>';
225 
226 
227 if (!empty($object->id))
228 {
229  $param = '&id='.$object->id;
230  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage;
231  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit;
232 
233  $morehtmlright = '';
234 
235  $messagingUrl = DOL_URL_ROOT.'/ticket/messaging.php?track_id='.$object->track_id;
236  $morehtmlright .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 1, array('morecss'=>'btnTitleSelected'));
237  $messagingUrl = DOL_URL_ROOT.'/ticket/agenda.php?track_id='.$object->track_id;
238  $morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-list-alt imgforviewmode', $messagingUrl, '', 1);
239 
240 
241  // Show link to add a message (if read and not closed)
242  $btnstatus = $object->fk_statut < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage";
243  $url = 'card.php?track_id='.$object->track_id.'&action=presend_addmessage&mode=init';
244  $morehtmlright .= dolGetButtonTitle($langs->trans('TicketAddMessage'), '', 'fa fa-comment-dots', $url, 'add-new-ticket-title-button', $btnstatus);
245 
246  // Show link to add event (if read and not closed)
247  $btnstatus = $object->fk_statut < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage";
248  $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);
249  $morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', $url, 'add-new-ticket-even-button', $btnstatus);
250 
251 
252  print_barre_liste($langs->trans("ActionsOnTicket"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 1);
253 
254  // List of all actions
255  $filters = array();
256  $filters['search_agenda_label'] = $search_agenda_label;
257  show_ticket_messaging($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
258 }
259 
260 // End of page
261 llxFooter();
262 $db->close();
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:271
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
ticket_prepare_head($object)
Build tabs for a Ticket object.
Definition: ticket.lib.php:76
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.
Class to manage Dolibarr users.
Definition: user.class.php:44
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Class to manage ticket.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
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.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage projects.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
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 ...
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:42
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59