dolibarr  13.0.2
agenda.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 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 
69 $extrafields->fetch_name_optionals_label($object->table_element);
70 
71 if (!$action) {
72  $action = 'view';
73 }
74 
75 
76 // Security check
77 $id = GETPOST("id", 'int');
78 $socid = 0;
79 //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.
80 $result = restrictedArea($user, 'ticket', $id, '');
81 
82 if (!$user->rights->ticket->read) {
84 }
85 // restrict access for externals users
86 if ($user->socid > 0 && ($object->fk_soc != $user->socid))
87 {
89 }
90 // or for unauthorized internals users
91 if (!$user->socid && ($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY && $object->fk_user_assign != $user->id) && !$user->rights->ticket->manage) {
93 }
94 
95 
96 
97 /*
98  * Actions
99  */
100 
101 $parameters = array('id'=>$socid);
102 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
103 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
104 
105 if (empty($reshook))
106 {
107  // Set view style
108  $_SESSION['ticket-view-type'] = "list";
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 {
114  $actioncode = '';
115  $search_agenda_label = '';
116 }
117 
118 
119 
120 /*
121  * View
122  */
123 
124 $form = new Form($db);
125 $userstat = new User($db);
126 $formticket = new FormTicket($db);
127 
128 $title = $langs->trans("Ticket").' - '.$object->ref.' '.$object->name;
129 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");
130 $help_url = 'FR:DocumentationModuleTicket';
131 llxHeader('', $title, $help_url);
132 
133 if ($socid > 0) {
134  $object->fetch_thirdparty();
135  $head = societe_prepare_head($object->thirdparty);
136 
137  print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
138 
139  dol_banner_tab($object->thirdparty, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
140 
142 }
143 
144 if (!$user->socid && $conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY) {
145  $object->next_prev_filter = "te.fk_user_assign = '".$user->id."'";
146 } elseif ($user->socid > 0) {
147  $object->next_prev_filter = "te.fk_soc = '".$user->socid."'";
148 }
149 $head = ticket_prepare_head($object);
150 
151 print dol_get_fiche_head($head, 'tabTicketLogs', $langs->trans("Ticket"), 0, 'ticket');
152 
153 $morehtmlref = '<div class="refidno">';
154 $morehtmlref .= $object->subject;
155 // Author
156 if ($object->fk_user_create > 0) {
157  $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
158 
159  $langs->load("users");
160  $fuser = new User($db);
161  $fuser->fetch($object->fk_user_create);
162  $morehtmlref .= $fuser->getNomUrl(0);
163 }
164 if (!empty($object->origin_email)) {
165  $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
166  $morehtmlref .= $object->origin_email.' <small>('.$langs->trans("TicketEmailOriginIssuer").')</small>';
167 }
168 
169 // Thirdparty
170 if (!empty($conf->societe->enabled))
171 {
172  $morehtmlref .= '<br>'.$langs->trans('ThirdParty');
173  /*if ($action != 'editcustomer' && $object->fk_statut < 8 && !$user->socid && $user->rights->ticket->write) {
174  $morehtmlref.='<a class="editfielda" href="' . $url_page_current . '?action=editcustomer&amp;track_id=' . $object->track_id . '">' . img_edit($langs->transnoentitiesnoconv('Edit'), 1) . '</a>';
175  }*/
176  $morehtmlref .= ' : ';
177  if ($action == 'editcustomer') {
178  $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'editcustomer', '', 1, 0, 0, array(), 1);
179  } else {
180  $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'none', '', 1, 0, 0, array(), 1);
181  }
182 }
183 
184 // Project
185 if (!empty($conf->projet->enabled))
186 {
187  $langs->load("projects");
188  $morehtmlref .= '<br>'.$langs->trans('Project');
189  if ($user->rights->ticket->write)
190  {
191  if ($action != 'classify') {
192  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>';
193  $morehtmlref .= ' : ';
194  }
195  if ($action == 'classify') {
196  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
197  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
198  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
199  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
200  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1);
201  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
202  $morehtmlref .= '</form>';
203  } else {
204  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
205  }
206  } else {
207  if (!empty($object->fk_project)) {
208  $proj = new Project($db);
209  $proj->fetch($object->fk_project);
210  $morehtmlref .= $proj->getNomUrl(1);
211  } else {
212  $morehtmlref .= '';
213  }
214  }
215 }
216 
217 $morehtmlref .= '</div>';
218 
219 $linkback = '<a href="'.dol_buildpath('/ticket/list.php', 1).'"><strong>'.$langs->trans("BackToList").'</strong></a> ';
220 
221 dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
222 
224 
225 print '<br>';
226 
227 
228 if (!empty($object->id))
229 {
230  $param = '&id='.$object->id;
231  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage;
232  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit;
233 
234  $morehtmlright = '';
235 
236  $messagingUrl = DOL_URL_ROOT.'/ticket/messaging.php?track_id='.$object->track_id;
237  $morehtmlright .= dolGetButtonTitle($langs->trans('ShowAsConversation'), '', 'fa fa-comments imgforviewmode', $messagingUrl, '', 1);
238  $messagingUrl = DOL_URL_ROOT.'/ticket/agenda.php?track_id='.$object->track_id;
239  $morehtmlright .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-list-alt imgforviewmode', $messagingUrl, '', 1, array('morecss'=>'btnTitleSelected'));
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"]);
249  $morehtmlright .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', $url, 'add-new-ticket-even-button', $btnstatus);
250 
251  print_barre_liste($langs->trans("ActionsOnTicket"), 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', 0, -1, '', 0, $morehtmlright, '', 0, 1, 1);
252 
253  // List of all actions
254  $filters = array();
255  $filters['search_agenda_label'] = $search_agenda_label;
256  show_actions_done($conf, $langs, $db, $object, null, 0, $actioncode, '', $filters, $sortfield, $sortorder);
257 }
258 
259 // End of page
260 llxFooter();
261 $db->close();
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
show_actions_done($conf, $langs, $db, $filterobj, $objcon= '', $noprint=0, $actioncode= '', $donetodo= 'done', $filters=array(), $sortfield= 'a.datep, a.id', $sortorder= 'DESC', $module= '')
Show html area with actions (done or not, ignore the name of function).
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