dolibarr  16.0.5
document.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2013-2016 Jean-François Ferry <hello@librethic.io>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
33 require_once DOL_DOCUMENT_ROOT."/core/lib/company.lib.php";
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
35 
36 // Load translation files required by the page
37 $langs->loadLangs(array("companies", "other", "ticket", "mails"));
38 
39 $id = GETPOST('id', 'int');
40 $socid = GETPOST('socid', 'int');
41 $ref = GETPOST('ref', 'alpha');
42 $track_id = GETPOST('track_id', 'alpha');
43 $action = GETPOST('action', 'alpha');
44 $confirm = GETPOST('confirm', 'alpha');
45 
46 // Get parameters
47 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
48 $sortfield = GETPOST('sortfield', 'aZ09comma');
49 $sortorder = GETPOST('sortorder', 'aZ09comma');
50 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
51 if (empty($page) || $page == -1) {
52  $page = 0;
53 } // If $page is not defined, or '' or -1
54 $offset = $limit * $page;
55 $pageprev = $page - 1;
56 $pagenext = $page + 1;
57 if (!$sortorder) {
58  $sortorder = "ASC";
59 }
60 if (!$sortfield) {
61  $sortfield = "position_name";
62 }
63 
64 $object = new Ticket($db);
65 $result = $object->fetch($id, $ref, $track_id);
66 
67 if ($result < 0) {
68  setEventMessages($object->error, $object->errors, 'errors');
69 } else {
70  $upload_dir = $conf->ticket->dir_output."/".dol_sanitizeFileName($object->ref);
71 }
72 
73 $permissiontoadd = $user->rights->ticket->write; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles
74 
75 // Security check - Protection if external user
76 $result = restrictedArea($user, 'ticket', $object->id);
77 
78 // restrict access for externals users
79 if ($user->socid > 0 && ($object->fk_soc != $user->socid)) {
81 }
82 // or for unauthorized internals users
83 if (!$user->socid && !empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY) && $object->fk_user_assign != $user->id && empty($user->rights->ticket->manage)) {
85 }
86 
87 
88 
89 /*
90  * Actions
91  */
92 
93 include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
94 
95 
96 
97 /*
98  * View
99  */
100 
101 $form = new Form($db);
102 
103 $help_url = '';
104 llxHeader('', $langs->trans("TicketDocumentsLinked").' - '.$langs->trans("Files"), $help_url);
105 
106 if ($object->id) {
107  /*
108  * Show tabs
109  */
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 
118  if (!$user->socid && !empty($conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY)) {
119  $object->next_prev_filter = "te.fk_user_assign = '".$user->id."'";
120  } elseif ($user->socid > 0) {
121  $object->next_prev_filter = "te.fk_soc = '".$user->socid."'";
122  }
123 
124  $head = ticket_prepare_head($object);
125 
126  print dol_get_fiche_head($head, 'tabTicketDocument', $langs->trans("Ticket"), 0, 'ticket');
127 
128  $morehtmlref = '<div class="refidno">';
129  $morehtmlref .= $object->subject;
130  // Author
131  if ($object->fk_user_create > 0) {
132  $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
133 
134  $fuser = new User($db);
135  $fuser->fetch($object->fk_user_create);
136  $morehtmlref .= $fuser->getNomUrl(-1);
137  } elseif (!empty($object->email_msgid)) {
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">('.$form->textwithpicto($langs->trans("CreatedByEmailCollector"), $langs->trans("EmailMsgID").': '.$object->email_msgid).')</small>';
141  } elseif (!empty($object->origin_email)) {
142  $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
143  $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
144  $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$langs->trans("CreatedByPublicPortal").')</small>';
145  }
146 
147  // Thirdparty
148  if (isModEnabled('societe')) {
149  $morehtmlref .= '<br>'.$langs->trans('ThirdParty');
150  /*if ($action != 'editcustomer' && $object->fk_statut < 8 && !$user->socid && $user->rights->ticket->write) {
151  $morehtmlref.='<a class="editfielda" href="' . $url_page_current . '?action=editcustomer&token='.newToken().'&track_id=' . $object->track_id . '">' . img_edit($langs->transnoentitiesnoconv('Edit'), 1) . '</a>';
152  }*/
153  $morehtmlref .= ' : ';
154  if ($action == 'editcustomer') {
155  $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'editcustomer', '', 1, 0, 0, array(), 1);
156  } else {
157  $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'none', '', 1, 0, 0, array(), 1);
158  }
159  }
160 
161  // Project
162  if (isModEnabled('project')) {
163  $langs->load("projects");
164  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
165  if ($user->rights->ticket->write) {
166  if ($action != 'classify') {
167  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>';
168  $morehtmlref .= ' : ';
169  }
170  if ($action == 'classify') {
171  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
172  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
173  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
174  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
175  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1);
176  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
177  $morehtmlref .= '</form>';
178  } else {
179  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
180  }
181  } else {
182  if (!empty($object->fk_project)) {
183  $proj = new Project($db);
184  $proj->fetch($object->fk_project);
185  $morehtmlref .= $proj->getNomUrl(1);
186  } else {
187  $morehtmlref .= '';
188  }
189  }
190  }
191 
192  $morehtmlref .= '</div>';
193 
194  $linkback = '<a href="'.dol_buildpath('/ticket/list.php', 1).'"><strong>'.$langs->trans("BackToList").'</strong></a> ';
195 
196  dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
197 
198  print dol_get_fiche_end();
199 
200  // Build file list
201  $filearray = dol_dir_list($upload_dir, "files", 0, '', '\.meta$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
202  $totalsize = 0;
203  foreach ($filearray as $key => $file) {
204  $totalsize += $file['size'];
205  }
206 
207  //$object->ref = $object->track_id; // For compatibility we use track ID for directory
208  $modulepart = 'ticket';
209  $permissiontoadd = $user->rights->ticket->write;
210  $permtoedit = $user->rights->ticket->write;
211  $param = '&id='.$object->id;
212 
213  include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
214 } else {
215  accessforbidden('', 0, 1);
216 }
217 
218 // End of page
219 llxFooter();
220 $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
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
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
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
llxFooter
llxFooter()
Footer empty.
Definition: document.php:89
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
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
llxHeader
if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(isset($_GET["hashp"]) &&!defined("NOLOGIN")) if((isset($_GET["modulepart"]) && $_GET["modulepart"]=='medias')) llxHeader()
Header empty.
Definition: document.php:80
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
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
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