dolibarr 20.0.5
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 * Copyright (C) 2025 Benjamin Falière <benjamin@faliere.com>
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
34{
35 global $langs, $conf, $db;
36
37 $extrafields = new ExtraFields($db);
38 $extrafields->fetch_name_optionals_label('ticket');
39
40 $langs->load("ticket");
41
42 $h = 0;
43 $head = array();
44
45 $head[$h][0] = DOL_URL_ROOT.'/admin/ticket.php';
46 $head[$h][1] = $langs->trans("TicketSettings");
47 $head[$h][2] = 'settings';
48 $h++;
49
50 $head[$h][0] = DOL_URL_ROOT.'/admin/ticket_extrafields.php';
51 $head[$h][1] = $langs->trans("ExtraFieldsTicket");
52 $nbExtrafields = $extrafields->attributes['ticket']['count'];
53 if ($nbExtrafields > 0) {
54 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
55 }
56 $head[$h][2] = 'attributes';
57 $h++;
58
59 $head[$h][0] = DOL_URL_ROOT.'/admin/ticket_public.php';
60 $head[$h][1] = $langs->trans("PublicInterface");
61 $head[$h][2] = 'public';
62 $h++;
63
64 // Show more tabs from modules
65 // Entries must be declared in modules descriptor with line
66 //$this->tabs = array(
67 // 'entity:+tabname:Title:@ticket:/ticket/mypage.php?id=__ID__'
68 //); // to add new tab
69 //$this->tabs = array(
70 // 'entity:-tabname:Title:@ticket:/ticket/mypage.php?id=__ID__'
71 //); // to remove a tab
72 complete_head_from_modules($conf, $langs, null, $head, $h, 'ticketadmin');
73
74 complete_head_from_modules($conf, $langs, null, $head, $h, 'ticketadmin', 'remove');
75
76 return $head;
77}
78
86{
87 global $langs, $conf, $user, $db;
88
89 $h = 0;
90 $head = array();
91 $head[$h][0] = DOL_URL_ROOT.'/ticket/card.php?track_id='.$object->track_id;
92 $head[$h][1] = $langs->trans("Ticket");
93 $head[$h][2] = 'tabTicket';
94 $h++;
95
96 if (!getDolGlobalInt('MAIN_DISABLE_CONTACTS_TAB') && empty($user->socid) && isModEnabled("societe")) {
97 $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
98 $head[$h][0] = DOL_URL_ROOT.'/ticket/contact.php?track_id='.$object->track_id;
99 $head[$h][1] = $langs->trans('ContactsAddresses');
100 if ($nbContact > 0) {
101 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
102 }
103 $head[$h][2] = 'contact';
104 $h++;
105 }
106
107 complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket', 'add', 'core');
108
109 // Attached files
110 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
111 $upload_dir = $conf->ticket->dir_output."/".$object->ref;
112 $nbFiles = count(dol_dir_list($upload_dir, 'files'));
113 /* 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.
114 $sql = 'SELECT id FROM '.MAIN_DB_PREFIX.'actioncomm';
115 $sql .= " WHERE fk_element = ".(int) $object->id." AND elementtype = 'ticket'";
116 $resql = $db->query($sql);
117 if ($resql) {
118 $numrows = $db->num_rows($resql);
119 for ($i=0; $i < $numrows; $i++) {
120 $upload_msg_dir = $conf->agenda->dir_output.'/'.$db->fetch_row($resql)[0];
121 $nbFiles += count(dol_dir_list($upload_msg_dir, "files"));
122 }
123 }
124 */
125 $head[$h][0] = DOL_URL_ROOT.'/ticket/document.php?id='.$object->id;
126 $head[$h][1] = $langs->trans("Documents");
127 if ($nbFiles > 0) {
128 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbFiles.'</span>';
129 }
130
131 $head[$h][2] = 'tabTicketDocument';
132 $h++;
133
134
135 // History
136 $ticketViewType = "messaging";
137 if (empty($_SESSION['ticket-view-type'])) {
138 $_SESSION['ticket-view-type'] = $ticketViewType;
139 } else {
140 $ticketViewType = $_SESSION['ticket-view-type'];
141 }
142
143 if ($ticketViewType == "messaging") {
144 $head[$h][0] = DOL_URL_ROOT.'/ticket/messaging.php?track_id='.$object->track_id;
145 } else {
146 // $ticketViewType == "list"
147 $head[$h][0] = DOL_URL_ROOT.'/ticket/agenda.php?track_id='.$object->track_id;
148 }
149 $head[$h][1] = $langs->trans('Events');
150 if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
151 $head[$h][1] .= '/';
152 $head[$h][1] .= $langs->trans("Agenda");
153 }
154 $head[$h][2] = 'tabTicketLogs';
155 $h++;
156
157
158 complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket', 'add', 'external');
159
160 complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket', 'remove');
161
162 return $head;
163}
164
172{
173 global $conf, $langs;
174
175 require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
176 $email = CMailFile::getValidAddress($object->origin_email, 2);
177 $url = '';
178 if ($email) {
179 $url = getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE', dol_buildpath('/public/ticket/', 3)).'view.php?track_id='.$object->track_id.'&email='.$email;
180 }
181
182 $out = '';
183 if (!getDolGlobalInt('TICKET_ENABLE_PUBLIC_INTERFACE')) {
184 $langs->load('errors');
185 $out .= '<span class="opacitymedium">'.$langs->trans("ErrorPublicInterfaceNotEnabled").'</span>';
186 } else {
187 $out .= img_picto('', 'object_globe.png').' <span class="opacitymedium">'.$langs->trans("TicketPublicAccess").'</span><br>';
188 if ($url) {
189 $out .= '<div class="urllink">';
190 $out .= '<input type="text" id="directpubliclink" class="quatrevingtpercentminusx" value="'.$url.'">';
191 $out .= '<a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.img_picto('', 'object_globe.png', 'class="paddingleft"').'</a>';
192 $out .= '</div>';
193 $out .= ajax_autoselect("directpubliclink", 0);
194 } else {
195 $out .= '<span class="opacitymedium">'.$langs->trans("TicketNotCreatedFromPublicInterface").'</span>';
196 }
197 }
198
199 return $out;
200}
201
208function generate_random_id($car = 16)
209{
210 $string = "";
211 $chaine = "abcdefghijklmnopqrstuvwxyz123456789";
212 mt_srand((int) ((float) microtime() * 1000000));
213 for ($i = 0; $i < $car; $i++) {
214 $string .= $chaine[mt_rand() % strlen($chaine)];
215 }
216 return $string;
217}
218
230function llxHeaderTicket($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = [])
231{
232 global $user, $conf, $langs, $mysoc;
233
234 $urllogo = "";
235 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss, 0, 1); // Show html headers
236
237 print '<body id="mainbody" class="publicnewticketform">';
238 print '<div class="publicnewticketform2 flexcontainer centpercent" style="min-height: 100%;">';
239
240 print '<header class="center centpercent">';
241
242 // Define urllogo
243 if (getDolGlobalInt('TICKET_SHOW_COMPANY_LOGO') || getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC')) {
244 // Print logo
245 if (getDolGlobalInt('TICKET_SHOW_COMPANY_LOGO')) {
246 $urllogo = DOL_URL_ROOT.'/theme/common/login_logo.png';
247
248 if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) {
249 $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_small);
250 } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) {
251 $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$mysoc->logo);
252 } elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.svg')) {
253 $urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg';
254 }
255 }
256 }
257
258 // Output html code for logo
259 if ($urllogo || getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC')) {
260 print '<div class="backgreypublicpayment">';
261 print '<div class="logopublicpayment">';
262 if ($urllogo) {
263 print '<a href="'.(getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE') ? getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE') : dol_buildpath('/public/ticket/index.php?entity='.$conf->entity, 1)).'">';
264 print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
265 print '>';
266 print '</a>';
267 }
268 if (getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC')) {
269 print '<div class="clearboth"></div><strong>'.(getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC') ? getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC') : $langs->trans("TicketSystem")).'</strong>';
270 }
271 print '</div>';
272 if (!getDolGlobalInt('MAIN_HIDE_POWERED_BY')) {
273 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>';
274 }
275 print '</div>';
276 }
277
278 if (getDolGlobalString('TICKET_IMAGE_PUBLIC_INTERFACE')) {
279 print '<div class="backimagepublicticket">';
280 print '<img id="idTICKET_IMAGE_PUBLIC_INTERFACE" src="'.getDolGlobalString('TICKET_IMAGE_PUBLIC_INTERFACE').'">';
281 print '</div>';
282 }
283
284 print '</header>';
285
286 //print '<div class="ticketlargemargin">';
287}
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.
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.
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
generate_random_id($car=16)
Generate a random id.
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.
ticketAdminPrepareHead()
Build tabs for admin page.
showDirectPublicLink($object)
Return string with full Url.
ticket_prepare_head($object)
Build tabs for a Ticket object.