dolibarr  20.0.0-alpha
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 <https://www.gnu.org/licenses/>.
16  */
17 
24 // Load Dolibarr environment
25 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticket.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
29 require_once DOL_DOCUMENT_ROOT."/core/lib/company.lib.php";
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
33 if (isModEnabled('project')) {
34  include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
35  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
36  include_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
37 }
38 
39 // Load translation files required by the page
40 $langs->loadLangs(array('companies', 'other', 'ticket'));
41 
42 // Get parameters
43 $id = GETPOSTINT('id');
44 $ref = GETPOST('ref', 'alpha');
45 $track_id = GETPOST('track_id', 'alpha', 3);
46 $socid = GETPOSTINT('socid');
47 $action = GETPOST('action', 'aZ09');
48 
49 // Store current page url
50 $url_page_current = DOL_URL_ROOT.'/ticket/messaging.php';
51 
52 $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
53 $sortfield = GETPOST("sortfield", "aZ09comma");
54 $sortorder = GETPOST("sortorder", 'aZ09comma');
55 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
56 $page = is_numeric($page) ? $page : 0;
57 $page = $page == -1 ? 0 : $page;
58 if (!$sortfield) {
59  $sortfield = "a.datep,a.id";
60 }
61 if (!$sortorder) {
62  $sortorder = "DESC";
63 }
64 $offset = $limit * $page;
65 $pageprev = $page - 1;
66 $pagenext = $page + 1;
67 
68 if (GETPOST('actioncode', 'array')) {
69  $actioncode = GETPOST('actioncode', 'array', 3);
70  if (!count($actioncode)) {
71  $actioncode = '0';
72  }
73 } else {
74  $actioncode = GETPOST("actioncode", "alpha", 3) ? GETPOST("actioncode", "alpha", 3) : (GETPOST("actioncode") == '0' ? '0' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE_FOR_OBJECT'));
75 }
76 $search_rowid = GETPOST('search_rowid');
77 $search_agenda_label = GETPOST('search_agenda_label');
78 
79 $object = new Ticket($db);
80 $object->fetch($id, $ref, $track_id);
81 
82 $extrafields = new ExtraFields($db);
83 $extrafields->fetch_name_optionals_label($object->table_element);
84 
85 if (!$action) {
86  $action = 'view';
87 }
88 
89 // Security check
90 $id = GETPOSTINT("id");
91 if ($user->socid > 0) {
92  $socid = $user->socid;
93 }
94 $result = restrictedArea($user, 'ticket', $object->id, '');
95 
96 // restrict access for externals users
97 if ($user->socid > 0 && ($object->fk_soc != $user->socid)) {
99 }
100 // or for unauthorized internals users
101 if (!$user->socid && (getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY') && $object->fk_user_assign != $user->id) && !$user->hasRight('ticket', 'manage')) {
102  accessforbidden();
103 }
104 
105 $permissiontoadd = $user->hasRight('ticket', 'write');
106 
107 
108 /*
109  * Actions
110  */
111 
112 $parameters = array('id'=>$socid);
113 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
114 if ($reshook < 0) {
115  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
116 }
117 
118 if (empty($reshook)) {
119  // Set view style
120  $_SESSION['ticket-view-type'] = "messaging";
121 }
122 
123 // Purge search criteria
124 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
125  $actioncode = '';
126  $search_agenda_label = '';
127 }
128 
129 // Set parent company
130 if ($action == 'set_thirdparty' && $user->hasRight('ticket', 'write')) {
131  if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
132  $result = $object->setCustomer(GETPOSTINT('editcustomer'));
133  $url = $_SERVER["PHP_SELF"].'?track_id='.GETPOST('track_id', 'alpha');
134  header("Location: ".$url);
135  exit();
136  }
137 }
138 
139 
140 /*
141  * View
142  */
143 
144 $form = new Form($db);
145 $userstat = new User($db);
146 $formticket = new FormTicket($db);
147 
148 $title = $langs->trans("Ticket").' - '.$object->ref.' '.$object->name;
149 if (getDolGlobalString('MAIN_HTML_TITLE') && preg_match('/ticketnameonly/', getDolGlobalString('MAIN_HTML_TITLE')) && $object->name) {
150  $title = $object->ref.' '.$object->name.' - '.$langs->trans("Info");
151 }
152 $help_url = 'FR:DocumentationModuleTicket';
153 llxHeader('', $title, $help_url);
154 
155 if ($socid > 0) {
156  $object->fetch_thirdparty();
157  $head = societe_prepare_head($object->thirdparty);
158 
159  print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
160 
161  dol_banner_tab($object->thirdparty, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
162 
163  print dol_get_fiche_end();
164 }
165 
166 if (!$user->socid && getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY')) {
167  $object->next_prev_filter = "te.fk_user_assign = ".((int) $user->id);
168 } elseif ($user->socid > 0) {
169  $object->next_prev_filter = "te.fk_soc = ".((int) $user->socid);
170 }
172 
173 print dol_get_fiche_head($head, 'tabTicketLogs', $langs->trans("Ticket"), 0, 'ticket');
174 
175 $morehtmlref = '<div class="refidno">';
176 $morehtmlref .= $object->subject;
177 // Author
178 if ($object->fk_user_create > 0) {
179  $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
180 
181  $fuser = new User($db);
182  $fuser->fetch($object->fk_user_create);
183  $morehtmlref .= $fuser->getNomUrl(-1);
184 } elseif (!empty($object->email_msgid)) {
185  $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
186  $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
187  $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$form->textwithpicto($langs->trans("CreatedByEmailCollector"), $langs->trans("EmailMsgID").': '.$object->email_msgid).')</small>';
188 } elseif (!empty($object->origin_email)) {
189  $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
190  $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
191  $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$langs->trans("CreatedByPublicPortal").')</small>';
192 }
193 
194 // Thirdparty
195 if (isModEnabled("societe")) {
196  if (isModEnabled("societe")) {
197  $morehtmlref .= '<br>';
198  $morehtmlref .= img_picto($langs->trans("ThirdParty"), 'company', 'class="pictofixedwidth"');
199  if ($action != 'editcustomer' && $permissiontoadd) {
200  $morehtmlref .= '<a class="editfielda" href="'.$url_page_current.'?action=editcustomer&token='.newToken().'&track_id='.$object->track_id.'">'.img_edit($langs->transnoentitiesnoconv('SetThirdParty'), 0).'</a> ';
201  }
202  $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, $action == 'editcustomer' ? 'editcustomer' : 'none', '', 1, 0, 0, array(), 1);
203  }
204 }
205 
206 // Project
207 if (isModEnabled('project')) {
208  $langs->load("projects");
209  $morehtmlref .= '<br>';
210  if (0) {
211  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
212  if ($action != 'classify') {
213  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
214  }
215  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
216  } else {
217  if (!empty($object->fk_project)) {
218  $proj = new Project($db);
219  $proj->fetch($object->fk_project);
220  $morehtmlref .= $proj->getNomUrl(1);
221  if ($proj->title) {
222  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
223  }
224  }
225  }
226 }
227 
228 $morehtmlref .= '</div>';
229 
230 $linkback = '<a href="'.DOL_URL_ROOT.'/ticket/list.php"><strong>'.$langs->trans("BackToList").'</strong></a> ';
231 
232 dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
233 
234 print dol_get_fiche_end();
235 
236 print '<br>';
237 
238 
239 if (!empty($object->id)) {
240  $param = '&id='.$object->id;
241  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
242  $param .= '&contextpage='.$contextpage;
243  }
244  if ($limit > 0 && $limit != $conf->liste_limit) {
245  $param .= '&limit='.$limit;
246  }
247 
248  $morehtmlright = '';
249 
250  $messagingUrl = DOL_URL_ROOT.'/ticket/messaging.php?track_id='.$object->track_id;
251  $morehtmlright .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 1, array('morecss'=>'btnTitleSelected'));
252  $messagingUrl = DOL_URL_ROOT.'/ticket/agenda.php?track_id='.$object->track_id;
253  $morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 1);
254 
255  // Show link to send an email (if read and not closed)
256  $btnstatus = $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage";
257  $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';
258  $morehtmlright .= dolGetButtonTitle($langs->trans('SendMail'), '', 'fa fa-paper-plane', $url, 'email-title-button', $btnstatus);
259 
260  // Show link to add a private message (if read and not closed)
261  $btnstatus = $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage";
262  $url = 'card.php?track_id='.$object->track_id.'&action=presend_addmessage&mode=init&backtopage='.urlencode($_SERVER["PHP_SELF"].'?track_id='.$object->track_id).'#formmailbeforetitle';
263  $morehtmlright .= dolGetButtonTitle($langs->trans('TicketAddMessage'), '', 'fa fa-comment-dots', $url, 'add-new-ticket-title-button', $btnstatus);
264 
265  // Show link to add event (if read and not closed)
266  $btnstatus = $object->status < Ticket::STATUS_CLOSED && $action != "presend" && $action != "presend_addmessage";
267  $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);
268  $morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', $url, 'add-new-ticket-even-button', $btnstatus);
269 
270  require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
271  $cachekey = 'count_events_ticket_'.$object->id;
272  $nbEvent = dol_getcache($cachekey);
273 
274  $titlelist = $langs->trans("ActionsOnTicket").(is_numeric($nbEvent) ? '<span class="opacitymedium colorblack paddingleft">('.$nbEvent.')</span>' : '');
275 
276  print_barre_liste($titlelist, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 0);
277 
278  // List of all actions
279  $filters = array();
280  $filters['search_agenda_label'] = $search_agenda_label;
281  $filters['search_rowid'] = $search_rowid;
282 
283  show_actions_messaging($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
284 }
285 
286 // End of page
287 llxFooter();
288 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
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:118
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
Class to manage Dolibarr users.
Definition: user.class.php:50
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
Definition: company.lib.php:43
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
show_actions_messaging($conf, $langs, $db, $filterobj, $objcon=null, $noprint=0, $actioncode='', $donetodo='done', $filters=array(), $sortfield='a.datep, a.id', $sortorder='DESC')
Show html area with actions in messaging format.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
dol_getcache($memoryid)
Read a memory area shared by all users, all sessions on server.
Definition: memory.lib.php:141
Class to generate the form for creating a new ticket.
restrictedArea(User $user, $features, $object=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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
ticket_prepare_head($object)
Build tabs for a Ticket object.
Definition: ticket.lib.php:84