dolibarr 24.0.0-beta
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-2026 Frédéric France <frederic.france@free.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, $extrafields;
36
37 $extrafields->fetch_name_optionals_label('ticket');
38
39 $langs->load("ticket");
40
41 $h = 0;
42 $head = array();
43
44 $head[$h][0] = dolBuildUrl(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] = dolBuildUrl(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] = dolBuildUrl(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] = dolBuildUrl(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] = dolBuildUrl(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 // Notes
107 if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
108 $nbNote = 0;
109 if (!empty($object->note_private)) {
110 $nbNote++;
111 }
112 if (!empty($object->note_public)) {
113 $nbNote++;
114 }
115 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/ticket/note.php', ['id' => $object->id]);
116 $head[$h][1] = $langs->trans('Notes');
117 if ($nbNote > 0) {
118 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
119 }
120 $head[$h][2] = 'note';
121 $h++;
122 }
123
124 complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket', 'add', 'core');
125
126 // Attached files
127 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
128 $upload_dir = $conf->ticket->dir_output."/".$object->ref;
129 $nbFiles = count(dol_dir_list($upload_dir, 'files'));
130 /* 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.
131 $sql = 'SELECT id FROM '.MAIN_DB_PREFIX.'actioncomm';
132 $sql .= " WHERE fk_element = ".(int) $object->id." AND elementtype = 'ticket'";
133 $resql = $db->query($sql);
134 if ($resql) {
135 $numrows = $db->num_rows($resql);
136 for ($i=0; $i < $numrows; $i++) {
137 $upload_msg_dir = $conf->agenda->dir_output.'/'.$db->fetch_row($resql)[0];
138 $nbFiles += count(dol_dir_list($upload_msg_dir, "files"));
139 }
140 }
141 */
142 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/ticket/document.php', ['id' => $object->id]);
143 $head[$h][1] = $langs->trans("Documents");
144 if ($nbFiles > 0) {
145 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbFiles.'</span>';
146 }
147
148 $head[$h][2] = 'tabTicketDocument';
149 $h++;
150
151
152 // History
153 $ticketViewType = "messaging";
154 if (empty($_SESSION['ticket-view-type'])) {
155 $_SESSION['ticket-view-type'] = $ticketViewType;
156 } else {
157 $ticketViewType = $_SESSION['ticket-view-type'];
158 }
159
160 if ($ticketViewType == "messaging") {
161 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/ticket/messaging.php', ['track_id' => $object->track_id]);
162 } else {
163 // $ticketViewType == "list"
164 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/ticket/agenda.php', ['track_id' => $object->track_id]);
165 }
166 $head[$h][1] = $langs->trans('Events');
167 if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
168 $nbEvent = 0;
169 // Enable caching of ticket count actioncomm
170 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
171 $cachekey = 'count_events_ticket_'.$object->id;
172 $dataretrieved = dol_getcache($cachekey);
173 if (!is_null($dataretrieved)) {
174 $nbEvent = $dataretrieved;
175 } else {
176 $sql = "SELECT COUNT(id) as nb";
177 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
178 $sql .= " WHERE fk_element = ".((int) $object->id);
179 $sql .= " AND elementtype = 'ticket'";
180 $resql = $db->query($sql);
181 if ($resql) {
182 $obj = $db->fetch_object($resql);
183 $nbEvent = $obj->nb;
184 } else {
185 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
186 }
187 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
188 }
189
190 $head[$h][1] .= '/';
191 $head[$h][1] .= $langs->trans("Agenda");
192 if ($nbEvent > 0) {
193 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
194 }
195 }
196 $head[$h][2] = 'tabTicketLogs';
197 $h++;
198
199
200 complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket', 'add', 'external');
201
202 complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket', 'remove');
203
204 return $head;
205}
206
214{
215 global $langs;
216
217 require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
218 $email = CMailFile::getValidAddress($object->origin_email, 2);
219 $url = '';
220 if ($email) {
221 $url = getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE', dol_buildpath('/public/ticket/', 3)).'view.php?track_id='.$object->track_id.'&email='.$email;
222 }
223
224 $out = '';
225 if (!getDolGlobalInt('TICKET_ENABLE_PUBLIC_INTERFACE')) {
226 $langs->load('errors');
227 $out .= '<span class="opacitymedium">'.$langs->trans("ErrorPublicInterfaceNotEnabled").'</span>';
228 } else {
229 $out .= img_picto('', 'object_globe.png');
230 if ($url) {
231 $out .= ' <span class="opacitymedium">'.$langs->trans("TicketPublicAccess").'</span>';
232 $out .= '<br><div class="urllink">';
233 $out .= '<input type="text" id="directpubliclink" class="quatrevingtpercentminusx" spellcheck="false" value="'.$url.'">';
234 $out .= '<a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.img_picto('', 'object_globe.png', 'class="paddingleft"').'</a>';
235 $out .= '</div>';
236 $out .= ajax_autoselect("directpubliclink", '');
237 } else {
238 $out .= ' <span class="opacitymedium">'.$langs->trans("TicketNotCreatedFromPublicInterface").'</span>';
239 }
240 }
241
242 return $out;
243}
244
251function generate_random_id($car = 16)
252{
253 $string = "";
254 $chaine = "abcdefghijklmnopqrstuvwxyz123456789";
255 $max = strlen($chaine) - 1;
256
257 for ($i = 0; $i < $car; $i++) {
258 try {
259 $key = random_int(0, $max);
260 } catch (Exception $e) {
261 // Fallback. We let PHP makes the seed automatically (no manual mt_srand)
262 $key = mt_rand(0, $max);
263 }
264 $string .= $chaine[$key];
265 }
266 return $string;
267}
268
280function llxHeaderTicket($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = [], $arrayofcss = [])
281{
282 global $conf, $langs, $mysoc;
283
284 top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss, 0, 1); // Show html headers
285
286 print '<body id="mainbody" class="publicnewticketform">';
287 print '<div class="publicnewticketform2 centpercent" style="min-height: 100%;">';
288
289
290 htmlPrintOnlineHeader($mysoc, $langs, (getDolGlobalInt('TICKET_SHOW_COMPANY_LOGO') ? getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE', dol_buildpath('/public/ticket/index.php?entity='.$conf->entity, 1)) : '0'), getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC', $langs->trans("TicketSystem")), 'TICKET_IMAGE_PUBLIC_INTERFACE');
291}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
htmlPrintOnlineHeader($mysoc, $langs, $showlogo=1, $alttext='', $subimageconst='', $altlogo1='', $altlogo2='')
Show the header of a company in HTML public pages.
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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:64
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)
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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 a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
dol_setcache($memoryid, $data, $expire=0, $filecache=0, $replace=0)
Save data into a memory area shared by all users, all sessions on server.
dol_getcache($memoryid, $filecache=0)
Read a memory area shared by all users, all sessions on server.
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.