dolibarr  20.0.0-alpha
ticket.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013-2018 Jean-François FERRY <hello@librethic.io>
3  * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
4  * Copyright (C) 2019-2024 Frédéric France <frederic.france@netlogic.fr>
5  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
33 {
34  global $langs, $conf, $db;
35 
36  $extrafields = new ExtraFields($db);
37  $extrafields->fetch_name_optionals_label('ticket');
38 
39  $langs->load("ticket");
40 
41  $h = 0;
42  $head = array();
43 
44  $head[$h][0] = DOL_URL_ROOT.'/admin/ticket.php';
45  $head[$h][1] = $langs->trans("TicketSettings");
46  $head[$h][2] = 'settings';
47  $h++;
48 
49  $head[$h][0] = DOL_URL_ROOT.'/admin/ticket_extrafields.php';
50  $head[$h][1] = $langs->trans("ExtraFieldsTicket");
51  $nbExtrafields = $extrafields->attributes['ticket']['count'];
52  if ($nbExtrafields > 0) {
53  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
54  }
55  $head[$h][2] = 'attributes';
56  $h++;
57 
58  $head[$h][0] = DOL_URL_ROOT.'/admin/ticket_public.php';
59  $head[$h][1] = $langs->trans("PublicInterface");
60  $head[$h][2] = 'public';
61  $h++;
62 
63  // Show more tabs from modules
64  // Entries must be declared in modules descriptor with line
65  //$this->tabs = array(
66  // 'entity:+tabname:Title:@ticket:/ticket/mypage.php?id=__ID__'
67  //); // to add new tab
68  //$this->tabs = array(
69  // 'entity:-tabname:Title:@ticket:/ticket/mypage.php?id=__ID__'
70  //); // to remove a tab
71  complete_head_from_modules($conf, $langs, null, $head, $h, 'ticketadmin');
72 
73  complete_head_from_modules($conf, $langs, null, $head, $h, 'ticketadmin', 'remove');
74 
75  return $head;
76 }
77 
85 {
86  global $langs, $conf, $user, $db;
87 
88  $h = 0;
89  $head = array();
90  $head[$h][0] = DOL_URL_ROOT.'/ticket/card.php?track_id='.$object->track_id;
91  $head[$h][1] = $langs->trans("Ticket");
92  $head[$h][2] = 'tabTicket';
93  $h++;
94 
95  if (!getDolGlobalInt('MAIN_DISABLE_CONTACTS_TAB') && empty($user->socid) && isModEnabled("societe")) {
96  $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
97  $head[$h][0] = DOL_URL_ROOT.'/ticket/contact.php?track_id='.$object->track_id;
98  $head[$h][1] = $langs->trans('ContactsAddresses');
99  if ($nbContact > 0) {
100  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
101  }
102  $head[$h][2] = 'contact';
103  $h++;
104  }
105 
106  complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket', 'add', 'core');
107 
108  // Attached files
109  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
110  $upload_dir = $conf->ticket->dir_output."/".$object->ref;
111  $nbFiles = count(dol_dir_list($upload_dir, 'files'));
112  $sql = 'SELECT id FROM '.MAIN_DB_PREFIX.'actioncomm';
113  $sql .= " WHERE fk_element = ".(int) $object->id." AND elementtype = 'ticket'";
114  $resql = $db->query($sql);
115  if ($resql) {
116  $numrows = $db->num_rows($resql);
117  for ($i=0; $i < $numrows; $i++) {
118  $upload_msg_dir = $conf->agenda->dir_output.'/'.$db->fetch_row($resql)[0];
119  $nbFiles += count(dol_dir_list($upload_msg_dir, "files"));
120  }
121  }
122  $head[$h][0] = DOL_URL_ROOT.'/ticket/document.php?id='.$object->id;
123  $head[$h][1] = $langs->trans("Documents");
124  if ($nbFiles > 0) {
125  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbFiles.'</span>';
126  }
127 
128  $head[$h][2] = 'tabTicketDocument';
129  $h++;
130 
131 
132  // History
133  $ticketViewType = "messaging";
134  if (empty($_SESSION['ticket-view-type'])) {
135  $_SESSION['ticket-view-type'] = $ticketViewType;
136  } else {
137  $ticketViewType = $_SESSION['ticket-view-type'];
138  }
139 
140  if ($ticketViewType == "messaging") {
141  $head[$h][0] = DOL_URL_ROOT.'/ticket/messaging.php?track_id='.$object->track_id;
142  } else {
143  // $ticketViewType == "list"
144  $head[$h][0] = DOL_URL_ROOT.'/ticket/agenda.php?track_id='.$object->track_id;
145  }
146  $head[$h][1] = $langs->trans('Events');
147  if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
148  $head[$h][1] .= '/';
149  $head[$h][1] .= $langs->trans("Agenda");
150  }
151  $head[$h][2] = 'tabTicketLogs';
152  $h++;
153 
154 
155  complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket', 'add', 'external');
156 
157  complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket', 'remove');
158 
159  return $head;
160 }
161 
169 {
170  global $conf, $langs;
171 
172  require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
173  $email = CMailFile::getValidAddress($object->origin_email, 2);
174  $url = '';
175  if ($email) {
176  $url = getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE', dol_buildpath('/public/ticket/', 3)).'view.php?track_id='.$object->track_id.'&email='.$email;
177  }
178 
179  $out = '';
180  if (!getDolGlobalInt('TICKET_ENABLE_PUBLIC_INTERFACE')) {
181  $langs->load('errors');
182  $out .= '<span class="opacitymedium">'.$langs->trans("ErrorPublicInterfaceNotEnabled").'</span>';
183  } else {
184  $out .= img_picto('', 'object_globe.png').' <span class="opacitymedium">'.$langs->trans("TicketPublicAccess").'</span><br>';
185  if ($url) {
186  $out .= '<div class="urllink">';
187  $out .= '<input type="text" id="directpubliclink" class="quatrevingtpercentminusx" value="'.$url.'">';
188  $out .= '<a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.img_picto('', 'object_globe.png', 'class="paddingleft"').'</a>';
189  $out .= '</div>';
190  $out .= ajax_autoselect("directpubliclink", 0);
191  } else {
192  $out .= '<span class="opacitymedium">'.$langs->trans("TicketNotCreatedFromPublicInterface").'</span>';
193  }
194  }
195 
196  return $out;
197 }
198 
205 function generate_random_id($car = 16)
206 {
207  $string = "";
208  $chaine = "abcdefghijklmnopqrstuvwxyz123456789";
209  mt_srand((int) ((float) microtime() * 1000000));
210  for ($i = 0; $i < $car; $i++) {
211  $string .= $chaine[mt_rand() % strlen($chaine)];
212  }
213  return $string;
214 }
215 
227 function llxHeaderTicket($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = [])
228 {
229  global $user, $conf, $langs, $mysoc;
230 
231  $urllogo = "";
232  top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss, 0, 1); // Show html headers
233 
234  print '<body id="mainbody" class="publicnewticketform">';
235  print '<div class="publicnewticketform2 flexcontainer centpercent" style="min-height: 100%;">';
236 
237  print '<header class="center centpercent">';
238 
239  // Define urllogo
240  if (getDolGlobalInt('TICKET_SHOW_COMPANY_LOGO') || getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC')) {
241  // Print logo
242  if (getDolGlobalInt('TICKET_SHOW_COMPANY_LOGO')) {
243  $urllogo = DOL_URL_ROOT.'/theme/common/login_logo.png';
244 
245  if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) {
246  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_small);
247  } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) {
248  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$mysoc->logo);
249  } elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.svg')) {
250  $urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg';
251  }
252  }
253  }
254 
255  // Output html code for logo
256  if ($urllogo || getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC')) {
257  print '<div class="backgreypublicpayment">';
258  print '<div class="logopublicpayment">';
259  if ($urllogo) {
260  print '<a href="'.(getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE') ? getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE') : dol_buildpath('/public/ticket/index.php?entity='.$conf->entity, 1)).'">';
261  print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
262  print '>';
263  print '</a>';
264  }
265  if (getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC')) {
266  print '<div class="clearboth"></div><strong>'.(getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC') ? getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC') : $langs->trans("TicketSystem")).'</strong>';
267  }
268  print '</div>';
269  if (!getDolGlobalInt('MAIN_HIDE_POWERED_BY')) {
270  print '<div class="poweredbypublicpayment opacitymedium right hideonsmartphone"><a class="poweredbyhref" href="https://www.dolibarr.org?utm_medium=website&utm_source=poweredby" target="dolibarr" rel="noopener">'.$langs->trans("PoweredBy").'<br><img src="'.DOL_URL_ROOT.'/theme/dolibarr_logo.svg" width="80px"></a></div>';
271  }
272  print '</div>';
273  }
274 
275  if (getDolGlobalInt('TICKET_IMAGE_PUBLIC_INTERFACE')) {
276  print '<div class="backimagepublicticket">';
277  print '<img id="idTICKET_IMAGE_PUBLIC_INTERFACE" src="'.getDolGlobalString('TICKET_IMAGE_PUBLIC_INTERFACE').'">';
278  print '</div>';
279  }
280 
281  print '</header>';
282 
283  //print '<div class="ticketlargemargin">';
284 }
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
Class to manage standard extra fields.
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
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)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
Definition: main.inc.php:1749
generate_random_id($car=16)
Generate a random id.
Definition: ticket.lib.php:205
llxHeaderTicket($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs=[], $arrayofcss=[])
Show http header, open body tag and show HTML header banner for public pages for tickets.
Definition: ticket.lib.php:227
ticketAdminPrepareHead()
Build tabs for admin page.
Definition: ticket.lib.php:32
showDirectPublicLink($object)
Return string with full Url.
Definition: ticket.lib.php:168
ticket_prepare_head($object)
Build tabs for a Ticket object.
Definition: ticket.lib.php:84