dolibarr 22.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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require '../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
36require_once DOL_DOCUMENT_ROOT."/core/lib/company.lib.php";
37require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
38if (isModEnabled('project')) {
39 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
40 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
41 include_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
42}
43
52// Load translation files required by the page
53$langs->loadLangs(array("companies", "other", "ticket", "mails"));
54
55$id = GETPOSTINT('id');
56$socid = GETPOSTINT('socid');
57$ref = GETPOST('ref', 'alpha');
58$track_id = GETPOST('track_id', 'alpha');
59$action = GETPOST('action', 'alpha');
60$confirm = GETPOST('confirm', 'alpha');
61
62// Store current page url
63$url_page_current = DOL_URL_ROOT.'/ticket/document.php';
64
65// Get parameters
66$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
67$sortfield = GETPOST('sortfield', 'aZ09comma');
68$sortorder = GETPOST('sortorder', 'aZ09comma');
69$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
70if (empty($page) || $page == -1) {
71 $page = 0;
72} // If $page is not defined, or '' or -1
73$offset = $limit * $page;
74$pageprev = $page - 1;
75$pagenext = $page + 1;
76if (!$sortorder) {
77 $sortorder = "ASC";
78}
79if (!$sortfield) {
80 $sortfield = "position_name";
81}
82
83$hookmanager->initHooks(array('documentticketcard', 'globalcard'));
84$object = new Ticket($db);
85$result = $object->fetch($id, $ref, $track_id);
86
87if ($result < 0) {
88 setEventMessages($object->error, $object->errors, 'errors');
89} else {
90 $upload_dir = $conf->ticket->dir_output."/".dol_sanitizeFileName($object->ref);
91}
92
93// Security check - Protection if external user
94$result = restrictedArea($user, 'ticket', $object->id);
95
96// restrict access for externals users
97if ($user->socid > 0 && ($object->fk_soc != $user->socid)) {
99}
100// or for unauthorized internals users
101if (!$user->socid && getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY') && $object->fk_user_assign != $user->id && !$user->hasRight('ticket', 'manage')) {
103}
104
105$permissiontoadd = $user->hasRight('ticket', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles
106
107
108/*
109 * Actions
110 */
111
112include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
113
114$parameters = array();
115$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
116if ($reshook < 0) {
117 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
118}
119
120// Set parent company
121if ($action == 'set_thirdparty' && $user->hasRight('ticket', 'write')) {
122 if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
123 $result = $object->setCustomer(GETPOSTINT('editcustomer'));
124 $url = $_SERVER["PHP_SELF"].'?track_id='.GETPOST('track_id', 'alpha');
125 header("Location: ".$url);
126 exit();
127 }
128}
129
130
131/*
132 * View
133 */
134
135$form = new Form($db);
136
137$help_url = '';
138llxHeader('', $langs->trans("TicketDocumentsLinked").' - '.$langs->trans("Files"), $help_url, '', 0, 0, '', '', '', 'mod-ticket page-card_documents');
139
140if ($object->id) {
141 /*
142 * Show tabs
143 */
144 if ($socid > 0) {
145 $object->fetch_thirdparty();
146 $head = societe_prepare_head($object->thirdparty);
147 print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
148 dol_banner_tab($object->thirdparty, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
149 print dol_get_fiche_end();
150 }
151
152 if (!$user->socid && getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY')) {
153 $object->next_prev_filter = "te.fk_user_assign:=:".((int) $user->id); // usf filter
154 } elseif ($user->socid > 0) {
155 $object->next_prev_filter = "te.fk_soc:=:".((int) $user->socid); // usf filter
156 }
157
158 $head = ticket_prepare_head($object);
159
160 print dol_get_fiche_head($head, 'tabTicketDocument', $langs->trans("Ticket"), 0, 'ticket');
161
162 $morehtmlref = '<div class="refidno">';
163 $morehtmlref .= $object->subject;
164 // Author
165 if ($object->fk_user_create > 0) {
166 $morehtmlref .= '<br>';
167 //$morehtmlref .= '<span class="opacitymedium">'.$langs->trans("CreatedBy").'</span> ';
168
169 $fuser = new User($db);
170 $fuser->fetch($object->fk_user_create);
171 $morehtmlref .= $fuser->getNomUrl(-1);
172 } elseif (!empty($object->email_msgid)) {
173 $morehtmlref .= '<br>';
174 //$morehtmlref .= '<span class="opacitymedium">'.$langs->trans("CreatedBy").'</span> ';
175 $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
176 $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$form->textwithpicto($langs->trans("CreatedByEmailCollector"), $langs->trans("EmailMsgID").': '.$object->email_msgid).')</small>';
177 } elseif (!empty($object->origin_email)) {
178 $morehtmlref .= '<br>';
179 //$morehtmlref .= '<span class="opacitymedium">'.$langs->trans("CreatedBy").'</span> ';
180 $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
181 $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$langs->trans("CreatedByPublicPortal").')</small>';
182 }
183
184 // Thirdparty
185 if (isModEnabled("societe")) {
186 $morehtmlref .= '<br>';
187 $morehtmlref .= img_picto($langs->trans("ThirdParty"), 'company', 'class="pictofixedwidth"');
188 if ($action != 'editcustomer' && $permissiontoadd) {
189 $morehtmlref .= '<a class="editfielda" href="'.$url_page_current.'?action=editcustomer&token='.newToken().'&track_id='.$object->track_id.'">'.img_edit($langs->transnoentitiesnoconv('SetThirdParty'), 0).'</a> ';
190 }
191 $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, (string) $object->socid, $action == 'editcustomer' ? 'editcustomer' : 'none', '', 1, 0, 0, array(), 1);
192 }
193
194 // Project
195 if (isModEnabled('project')) {
196 $langs->load("projects");
197 if (0) {
198 $morehtmlref .= '<br>';
199 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
200 if ($action != 'classify') {
201 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
202 }
203 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
204 } else {
205 if (!empty($object->fk_project)) {
206 $morehtmlref .= '<br>';
207 $proj = new Project($db);
208 $proj->fetch($object->fk_project);
209 $morehtmlref .= $proj->getNomUrl(1);
210 if ($proj->title) {
211 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
212 }
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
223 print dol_get_fiche_end();
224
225 // Build file list
226 $filearray = dol_dir_list($upload_dir, "files", 0, '', '\.meta$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
227
228 // same as above for every messages
229 /* disabled. Too many bugs. All file of a ticket must be stored into ticket. File must be linked to an event by column agenda_id into llx_ecmfiles.
230 $sql = 'SELECT id FROM '.MAIN_DB_PREFIX.'actioncomm';
231 $sql .= " WHERE fk_element = ".(int) $object->id." AND elementtype = 'ticket'";
232 $resql = $db->query($sql);
233 if ($resql) {
234 $file_msg_array = array();
235 $numrows = $db->num_rows($resql);
236 for ($i=0; $i < $numrows; $i++) {
237 $upload_msg_dir = $conf->agenda->dir_output.'/'.$db->fetch_row($resql)[0];
238 $file_msg = dol_dir_list($upload_msg_dir, "files", 0, '', '\.meta$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
239 if (count($file_msg)) {
240 // add specific module part and user rights for delete
241 foreach ($file_msg as $key => $file) {
242 $file_msg[$key]['modulepart'] = 'actions';
243 $file_msg[$key]['relativepath'] = $file['level1name'].'/'; // directory without file name
244 $file_msg[$key]['permtoedit'] = 0;
245 $file_msg[$key]['permonobject'] = 0;
246 }
247 $file_msg_array = array_merge($file_msg, $file_msg_array);
248 }
249 }
250 if (count($file_msg_array)) {
251 $filearray = array_merge($filearray, $file_msg_array);
252 }
253 }
254 */
255
256 $totalsize = 0;
257 foreach ($filearray as $key => $file) {
258 $totalsize += $file['size'];
259 }
260
261 //$object->ref = $object->track_id; // For compatibility we use track ID for directory
262 $modulepart = 'ticket';
263 $permissiontoadd = $user->hasRight('ticket', 'write');
264 $permtoedit = $user->hasRight('ticket', 'write');
265 $param = '&id='.$object->id;
266
267 include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
268} else {
269 accessforbidden('', 0, 1);
270}
271
272// End of page
273llxFooter();
274$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
Class to manage Dolibarr users.
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:63
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
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, $morecssdiv='')
Show tabs of a record.
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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.