dolibarr  20.0.0-alpha
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 // Load Dolibarr environment
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
34 require_once DOL_DOCUMENT_ROOT."/core/lib/company.lib.php";
35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
36 if (isModEnabled('project')) {
37  include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
38  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
39  include_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
40 }
41 
42 // Load translation files required by the page
43 $langs->loadLangs(array("companies", "other", "ticket", "mails"));
44 
45 $id = GETPOSTINT('id');
46 $socid = GETPOSTINT('socid');
47 $ref = GETPOST('ref', 'alpha');
48 $track_id = GETPOST('track_id', 'alpha');
49 $action = GETPOST('action', 'alpha');
50 $confirm = GETPOST('confirm', 'alpha');
51 
52 // Store current page url
53 $url_page_current = DOL_URL_ROOT.'/ticket/document.php';
54 
55 // Get parameters
56 $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
57 $sortfield = GETPOST('sortfield', 'aZ09comma');
58 $sortorder = GETPOST('sortorder', 'aZ09comma');
59 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
60 if (empty($page) || $page == -1) {
61  $page = 0;
62 } // If $page is not defined, or '' or -1
63 $offset = $limit * $page;
64 $pageprev = $page - 1;
65 $pagenext = $page + 1;
66 if (!$sortorder) {
67  $sortorder = "ASC";
68 }
69 if (!$sortfield) {
70  $sortfield = "position_name";
71 }
72 
73 $object = new Ticket($db);
74 $result = $object->fetch($id, $ref, $track_id);
75 
76 if ($result < 0) {
77  setEventMessages($object->error, $object->errors, 'errors');
78 } else {
79  $upload_dir = $conf->ticket->dir_output."/".dol_sanitizeFileName($object->ref);
80 }
81 
82 // Security check - Protection if external user
83 $result = restrictedArea($user, 'ticket', $object->id);
84 
85 // restrict access for externals users
86 if ($user->socid > 0 && ($object->fk_soc != $user->socid)) {
88 }
89 // or for unauthorized internals users
90 if (!$user->socid && getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY') && $object->fk_user_assign != $user->id && !$user->hasRight('ticket', 'manage')) {
92 }
93 
94 $permissiontoadd = $user->hasRight('ticket', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles
95 
96 
97 /*
98  * Actions
99  */
100 
101 include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
102 
103 // Set parent company
104 if ($action == 'set_thirdparty' && $user->hasRight('ticket', 'write')) {
105  if ($object->fetch(GETPOSTINT('id'), '', GETPOST('track_id', 'alpha')) >= 0) {
106  $result = $object->setCustomer(GETPOSTINT('editcustomer'));
107  $url = $_SERVER["PHP_SELF"].'?track_id='.GETPOST('track_id', 'alpha');
108  header("Location: ".$url);
109  exit();
110  }
111 }
112 
113 
114 /*
115  * View
116  */
117 
118 $form = new Form($db);
119 
120 $help_url = '';
121 llxHeader('', $langs->trans("TicketDocumentsLinked").' - '.$langs->trans("Files"), $help_url);
122 
123 if ($object->id) {
124  /*
125  * Show tabs
126  */
127  if ($socid > 0) {
128  $object->fetch_thirdparty();
129  $head = societe_prepare_head($object->thirdparty);
130  print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company');
131  dol_banner_tab($object->thirdparty, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
132  print dol_get_fiche_end();
133  }
134 
135  if (!$user->socid && getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY')) {
136  $object->next_prev_filter = "te.fk_user_assign = ".((int) $user->id);
137  } elseif ($user->socid > 0) {
138  $object->next_prev_filter = "te.fk_soc = ".((int) $user->socid);
139  }
140 
141  $head = ticket_prepare_head($object);
142 
143  print dol_get_fiche_head($head, 'tabTicketDocument', $langs->trans("Ticket"), 0, 'ticket');
144 
145  $morehtmlref = '<div class="refidno">';
146  $morehtmlref .= $object->subject;
147  // Author
148  if ($object->fk_user_create > 0) {
149  $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
150 
151  $fuser = new User($db);
152  $fuser->fetch($object->fk_user_create);
153  $morehtmlref .= $fuser->getNomUrl(-1);
154  } elseif (!empty($object->email_msgid)) {
155  $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
156  $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
157  $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$form->textwithpicto($langs->trans("CreatedByEmailCollector"), $langs->trans("EmailMsgID").': '.$object->email_msgid).')</small>';
158  } elseif (!empty($object->origin_email)) {
159  $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : ';
160  $morehtmlref .= img_picto('', 'email', 'class="paddingrightonly"');
161  $morehtmlref .= dol_escape_htmltag($object->origin_email).' <small class="hideonsmartphone opacitymedium">('.$langs->trans("CreatedByPublicPortal").')</small>';
162  }
163 
164  // Thirdparty
165  if (isModEnabled("societe")) {
166  $morehtmlref .= '<br>';
167  $morehtmlref .= img_picto($langs->trans("ThirdParty"), 'company', 'class="pictofixedwidth"');
168  if ($action != 'editcustomer' && $permissiontoadd) {
169  $morehtmlref .= '<a class="editfielda" href="'.$url_page_current.'?action=editcustomer&token='.newToken().'&track_id='.$object->track_id.'">'.img_edit($langs->transnoentitiesnoconv('SetThirdParty'), 0).'</a> ';
170  }
171  $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, $action == 'editcustomer' ? 'editcustomer' : 'none', '', 1, 0, 0, array(), 1);
172  }
173 
174  // Project
175  if (isModEnabled('project')) {
176  $langs->load("projects");
177  if (0) {
178  $morehtmlref .= '<br>';
179  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
180  if ($action != 'classify') {
181  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
182  }
183  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
184  } else {
185  if (!empty($object->fk_project)) {
186  $morehtmlref .= '<br>';
187  $proj = new Project($db);
188  $proj->fetch($object->fk_project);
189  $morehtmlref .= $proj->getNomUrl(1);
190  if ($proj->title) {
191  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
192  }
193  }
194  }
195  }
196 
197  $morehtmlref .= '</div>';
198 
199  $linkback = '<a href="'.dol_buildpath('/ticket/list.php', 1).'"><strong>'.$langs->trans("BackToList").'</strong></a> ';
200 
201  dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
202 
203  print dol_get_fiche_end();
204 
205  // Build file list
206  $filearray = dol_dir_list($upload_dir, "files", 0, '', '\.meta$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
207  // same as above for every messages
208  $sql = 'SELECT id FROM '.MAIN_DB_PREFIX.'actioncomm';
209  $sql .= " WHERE fk_element = ".(int) $object->id." AND elementtype = 'ticket'";
210  $resql = $db->query($sql);
211  if ($resql) {
212  $file_msg_array = array();
213  $numrows = $db->num_rows($resql);
214  for ($i=0; $i < $numrows; $i++) {
215  $upload_msg_dir = $conf->agenda->dir_output.'/'.$db->fetch_row($resql)[0];
216  $file_msg = dol_dir_list($upload_msg_dir, "files", 0, '', '\.meta$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
217  if (count($file_msg)) {
218  $file_msg_array = array_merge($file_msg, $file_msg_array);
219  }
220  }
221  if (count($file_msg_array)) {
222  $filearray = array_merge($filearray, $file_msg_array);
223  }
224  }
225 
226  $totalsize = 0;
227  foreach ($filearray as $key => $file) {
228  $totalsize += $file['size'];
229  }
230 
231  //$object->ref = $object->track_id; // For compatibility we use track ID for directory
232  $modulepart = 'ticket';
233  $permissiontoadd = $user->hasRight('ticket', 'write');
234  $permtoedit = $user->hasRight('ticket', 'write');
235  $param = '&id='.$object->id;
236 
237  include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
238 } else {
239  accessforbidden('', 0, 1);
240 }
241 
242 // End of page
243 llxFooter();
244 $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
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(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:744
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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:83
llxFooter()
Footer empty.
Definition: document.php:92
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
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.
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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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...
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