1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* Copyright (C) 2013-2018 Jean-François FERRY <[email protected]> |
4
|
|
|
* Copyright (C) 2016 Christophe Battarel <[email protected]> |
5
|
|
|
* Copyright (C) 2019-2024 Frédéric France <[email protected]> |
6
|
|
|
* Copyright (C) 2024 MDW <[email protected]> |
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
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* \file core/lib/ticket.lib.php |
24
|
|
|
* \ingroup ticket |
25
|
|
|
* \brief This file is a library for Ticket module |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
use Dolibarr\Lib\Images; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Build tabs for admin page |
32
|
|
|
* |
33
|
|
|
* @return array |
34
|
|
|
*/ |
35
|
|
|
function ticketAdminPrepareHead() |
36
|
|
|
{ |
37
|
|
|
global $langs, $conf, $db; |
38
|
|
|
|
39
|
|
|
$extrafields = new ExtraFields($db); |
40
|
|
|
$extrafields->fetch_name_optionals_label('ticket'); |
41
|
|
|
|
42
|
|
|
$langs->load("ticket"); |
43
|
|
|
|
44
|
|
|
$h = 0; |
45
|
|
|
$head = array(); |
46
|
|
|
|
47
|
|
|
$head[$h][0] = constant('BASE_URL') . '/admin/ticket.php'; |
48
|
|
|
$head[$h][1] = $langs->trans("TicketSettings"); |
49
|
|
|
$head[$h][2] = 'settings'; |
50
|
|
|
$h++; |
51
|
|
|
|
52
|
|
|
$head[$h][0] = constant('BASE_URL') . '/admin/ticket_extrafields.php'; |
53
|
|
|
$head[$h][1] = $langs->trans("ExtraFieldsTicket"); |
54
|
|
|
$nbExtrafields = $extrafields->attributes['ticket']['count']; |
55
|
|
|
if ($nbExtrafields > 0) { |
56
|
|
|
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>'; |
57
|
|
|
} |
58
|
|
|
$head[$h][2] = 'attributes'; |
59
|
|
|
$h++; |
60
|
|
|
|
61
|
|
|
$head[$h][0] = constant('BASE_URL') . '/admin/ticket_public.php'; |
62
|
|
|
$head[$h][1] = $langs->trans("PublicInterface"); |
63
|
|
|
$head[$h][2] = 'public'; |
64
|
|
|
$h++; |
65
|
|
|
|
66
|
|
|
// Show more tabs from modules |
67
|
|
|
// Entries must be declared in modules descriptor with line |
68
|
|
|
//$this->tabs = array( |
69
|
|
|
// 'entity:+tabname:Title:@ticket:/ticket/mypage.php?id=__ID__' |
70
|
|
|
//); // to add new tab |
71
|
|
|
//$this->tabs = array( |
72
|
|
|
// 'entity:-tabname:Title:@ticket:/ticket/mypage.php?id=__ID__' |
73
|
|
|
//); // to remove a tab |
74
|
|
|
complete_head_from_modules($conf, $langs, null, $head, $h, 'ticketadmin'); |
75
|
|
|
|
76
|
|
|
complete_head_from_modules($conf, $langs, null, $head, $h, 'ticketadmin', 'remove'); |
77
|
|
|
|
78
|
|
|
return $head; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Build tabs for a Ticket object |
83
|
|
|
* |
84
|
|
|
* @param Ticket $object Object Ticket |
85
|
|
|
* @return array Array of tabs |
86
|
|
|
*/ |
87
|
|
|
function ticket_prepare_head($object) |
88
|
|
|
{ |
89
|
|
|
global $langs, $conf, $user, $db; |
90
|
|
|
|
91
|
|
|
$h = 0; |
92
|
|
|
$head = array(); |
93
|
|
|
$head[$h][0] = constant('BASE_URL') . '/ticket/card.php?track_id=' . $object->track_id; |
94
|
|
|
$head[$h][1] = $langs->trans("Ticket"); |
95
|
|
|
$head[$h][2] = 'tabTicket'; |
96
|
|
|
$h++; |
97
|
|
|
|
98
|
|
|
if (!getDolGlobalInt('MAIN_DISABLE_CONTACTS_TAB') && empty($user->socid) && isModEnabled("societe")) { |
99
|
|
|
$nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external')); |
100
|
|
|
$head[$h][0] = constant('BASE_URL') . '/ticket/contact.php?track_id=' . $object->track_id; |
101
|
|
|
$head[$h][1] = $langs->trans('ContactsAddresses'); |
102
|
|
|
if ($nbContact > 0) { |
103
|
|
|
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbContact . '</span>'; |
104
|
|
|
} |
105
|
|
|
$head[$h][2] = 'contact'; |
106
|
|
|
$h++; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket', 'add', 'core'); |
110
|
|
|
|
111
|
|
|
// Attached files |
112
|
|
|
include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; |
113
|
|
|
$upload_dir = $conf->ticket->dir_output . "/" . $object->ref; |
114
|
|
|
$nbFiles = count(dol_dir_list($upload_dir, 'files')); |
115
|
|
|
$sql = 'SELECT id FROM ' . MAIN_DB_PREFIX . 'actioncomm'; |
116
|
|
|
$sql .= " WHERE fk_element = " . (int) $object->id . " AND elementtype = 'ticket'"; |
117
|
|
|
$resql = $db->query($sql); |
118
|
|
|
if ($resql) { |
119
|
|
|
$numrows = $db->num_rows($resql); |
120
|
|
|
for ($i = 0; $i < $numrows; $i++) { |
121
|
|
|
$upload_msg_dir = $conf->agenda->dir_output . '/' . $db->fetch_row($resql)[0]; |
122
|
|
|
$nbFiles += count(dol_dir_list($upload_msg_dir, "files")); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
$head[$h][0] = constant('BASE_URL') . '/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] = constant('BASE_URL') . '/ticket/messaging.php?track_id=' . $object->track_id; |
145
|
|
|
} else { |
146
|
|
|
// $ticketViewType == "list" |
147
|
|
|
$head[$h][0] = constant('BASE_URL') . '/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
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Return string with full Url. The file qualified is the one defined by relative path in $object->last_main_doc |
167
|
|
|
* |
168
|
|
|
* @param Object $object Object |
169
|
|
|
* @return string Url string |
170
|
|
|
*/ |
171
|
|
|
function showDirectPublicLink($object) |
172
|
|
|
{ |
173
|
|
|
global $conf, $langs; |
174
|
|
|
|
175
|
|
|
require_once constant('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
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Generate a random id |
204
|
|
|
* |
205
|
|
|
* @param int $car Length of string to generate key |
206
|
|
|
* @return string |
207
|
|
|
*/ |
208
|
|
|
function 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
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Show http header, open body tag and show HTML header banner for public pages for tickets |
221
|
|
|
* |
222
|
|
|
* @param string $title Title |
223
|
|
|
* @param string $head Head array |
224
|
|
|
* @param int $disablejs More content into html header |
225
|
|
|
* @param int $disablehead More content into html header |
226
|
|
|
* @param array $arrayofjs Array of complementary js files |
227
|
|
|
* @param array $arrayofcss Array of complementary css files |
228
|
|
|
* @return void |
229
|
|
|
*/ |
230
|
|
|
function 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
|
|
|
$width = 0; |
247
|
|
|
$urllogo = Images::getLogo($conf->theme, $width, $mysoc->logo_small, $mysoc->logo); |
248
|
|
|
} |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
// Output html code for logo |
252
|
|
|
if ($urllogo || getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC')) { |
253
|
|
|
print '<div class="backgreypublicpayment">'; |
254
|
|
|
print '<div class="logopublicpayment">'; |
255
|
|
|
if ($urllogo) { |
256
|
|
|
print '<a href="' . (getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE') ? getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE') : dol_buildpath('/public/ticket/index.php?entity=' . $conf->entity, 1)) . '">'; |
257
|
|
|
print '<img id="dolpaymentlogo" src="' . $urllogo . '"'; |
258
|
|
|
print '>'; |
259
|
|
|
print '</a>'; |
260
|
|
|
} |
261
|
|
|
if (getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC')) { |
262
|
|
|
print '<div class="clearboth"></div><strong>' . (getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC') ? getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC') : $langs->trans("TicketSystem")) . '</strong>'; |
263
|
|
|
} |
264
|
|
|
print '</div>'; |
265
|
|
|
if (!getDolGlobalInt('MAIN_HIDE_POWERED_BY')) { |
266
|
|
|
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="' . constant('DOL_URL_ROOT') . '/theme/dolibarr_logo.svg" width="80px"></a></div>'; |
267
|
|
|
} |
268
|
|
|
print '</div>'; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
if (getDolGlobalInt('TICKET_IMAGE_PUBLIC_INTERFACE')) { |
272
|
|
|
print '<div class="backimagepublicticket">'; |
273
|
|
|
print '<img id="idTICKET_IMAGE_PUBLIC_INTERFACE" src="' . getDolGlobalString('TICKET_IMAGE_PUBLIC_INTERFACE') . '">'; |
274
|
|
|
print '</div>'; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
print '</header>'; |
278
|
|
|
|
279
|
|
|
//print '<div class="ticketlargemargin">'; |
280
|
|
|
} |
281
|
|
|
|