1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* You may not change or alter any portion of this comment or credits |
5
|
|
|
* of supporting developers from this source code or any supporting source code |
6
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
7
|
|
|
* |
8
|
|
|
* This program is distributed in the hope that it will be useful, |
9
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
15
|
|
|
* @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later} |
16
|
|
|
* @author Brian Wahoff <[email protected]> |
17
|
|
|
* @author Eric Juden <[email protected]> |
18
|
|
|
* @author XOOPS Development Team |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use Xmf\Request; |
22
|
|
|
use XoopsModules\Xhelp; |
23
|
|
|
use XoopsModules\Xhelp\Validation; |
24
|
|
|
use XoopsModules\Xhelp\Ticket; |
25
|
|
|
|
26
|
|
|
require_once __DIR__ . '/header.php'; |
27
|
|
|
require_once XHELP_INCLUDE_PATH . '/events.php'; |
28
|
|
|
// require_once XHELP_CLASS_PATH . '/validator.php'; |
29
|
|
|
|
30
|
|
|
global $xoopsTpl, $session, $xoopsUser, $xoopsConfig, $xoopsModule, $xhelp_module_header, $xhelp_isStaff, $staff, $xoopsRequestUri; |
31
|
|
|
|
32
|
|
|
$helper = Xhelp\Helper::getInstance(); |
33
|
|
|
$eventService = Xhelp\EventService::getInstance(); |
34
|
|
|
$op = 'user'; |
35
|
|
|
$xhelp_id = 0; |
36
|
|
|
|
37
|
|
|
// Get the id of the ticket |
38
|
|
|
if (Request::hasVar('id', 'REQUEST')) { |
39
|
|
|
$xhelp_id = Request::getInt('id', 0, 'REQUEST'); |
40
|
|
|
} else { |
41
|
|
|
$helper->redirect('index.php', 3, _XHELP_ERROR_INV_TICKET); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if (Request::hasVar('op', 'GET')) { |
45
|
|
|
$op = $_GET['op']; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if (!$xoopsUser) { |
49
|
|
|
redirect_header(XOOPS_URL . '/user.php?xoops_redirect=' . htmlspecialchars($xoopsRequestUri, ENT_QUOTES | ENT_HTML5), 3); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
//$xoopsVersion = mb_substr(XOOPS_VERSION, 6); |
53
|
|
|
//(int)$xoopsVersion; |
54
|
|
|
|
55
|
|
|
global $ticketInfo; |
56
|
|
|
/** @var \XoopsModules\Xhelp\StaffHandler $staffHandler */ |
57
|
|
|
$staffHandler = $helper->getHandler('Staff'); |
58
|
|
|
/** @var \XoopsMemberHandler $memberHandler */ |
59
|
|
|
$memberHandler = xoops_getHandler('member'); |
60
|
|
|
/** @var \XoopsModules\Xhelp\TicketHandler $ticketHandler */ |
61
|
|
|
$ticketHandler = $helper->getHandler('Ticket'); |
62
|
|
|
if (!$ticketInfo = $ticketHandler->get($xhelp_id)) { |
63
|
|
|
$helper->redirect('index.php', 3, _XHELP_ERROR_INV_TICKET); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$displayName = $helper->getConfig('xhelp_displayName'); // Determines if username or real name is displayed |
67
|
|
|
|
68
|
|
|
/** @var \XoopsModules\Xhelp\DepartmentHandler $departmentHandler */ |
69
|
|
|
$departmentHandler = $helper->getHandler('Department'); |
70
|
|
|
$departments = &$departmentHandler->getObjects(null, true); |
71
|
|
|
$user = $memberHandler->getUser($ticketInfo->getVar('uid')); |
72
|
|
|
/** @var \XoopsModules\Xhelp\StaffReviewHandler $staffReviewHandler */ |
73
|
|
|
$staffReviewHandler = $helper->getHandler('StaffReview'); |
74
|
|
|
/** @var \XoopsModules\Xhelp\ResponseHandler $responseHandler */ |
75
|
|
|
$responseHandler = $helper->getHandler('Response'); |
76
|
|
|
/** @var \XoopsModules\Xhelp\MembershipHandler $membershipHandler */ |
77
|
|
|
$membershipHandler = $helper->getHandler('Membership'); |
78
|
|
|
$aResponses = []; |
79
|
|
|
$all_users = []; |
80
|
|
|
|
81
|
|
|
if (isset($departments[$ticketInfo->getVar('department')])) { |
82
|
|
|
$department = $departments[$ticketInfo->getVar('department')]; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
//Security Checkpoints to ensure no funny stuff |
86
|
|
|
if (!$xoopsUser) { |
87
|
|
|
$helper->redirect('index.php', 3, _NOPERM); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$op = ($xhelp_isStaff ? 'staff' : $op); |
91
|
|
|
|
92
|
|
|
$has_ticketFiles = false; |
93
|
|
|
$files = $ticketInfo->getFiles(); |
94
|
|
|
$aFiles = []; |
95
|
|
|
foreach ($files as $file) { |
96
|
|
|
if (0 == $file->getVar('responseid')) { |
97
|
|
|
$has_ticketFiles = true; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$filename_full = $file->getVar('filename'); |
101
|
|
|
if (0 != $file->getVar('responseid')) { |
102
|
|
|
$removeText = $file->getVar('ticketid') . '_' . $file->getVar('responseid') . '_'; |
103
|
|
|
} else { |
104
|
|
|
$removeText = $file->getVar('ticketid') . '_'; |
105
|
|
|
} |
106
|
|
|
$filename = str_replace($removeText, '', $filename_full); |
107
|
|
|
$filesize = round(filesize(XHELP_UPLOAD_PATH . '/' . $filename_full) / 1024, 2); |
|
|
|
|
108
|
|
|
|
109
|
|
|
$aFiles[] = [ |
110
|
|
|
'id' => $file->getVar('id'), |
111
|
|
|
'filename' => $filename, |
112
|
|
|
'filename_full' => $filename_full, |
113
|
|
|
'ticketid' => $file->getVar('ticketid'), |
114
|
|
|
'responseid' => $file->getVar('responseid'), |
115
|
|
|
'path' => 'viewFile.php?id=' . $file->getVar('id'), |
116
|
|
|
'size' => $filesize . ' ' . _XHELP_SIZE_KB, |
117
|
|
|
]; |
118
|
|
|
} |
119
|
|
|
$has_files = count($files) > 0; |
120
|
|
|
unset($files); |
121
|
|
|
$message = ''; |
122
|
|
|
|
123
|
|
|
if ($xhelp_isStaff) { |
124
|
|
|
//** BTW - What does $giveOwnership do here? |
125
|
|
|
$giveOwnership = false; |
126
|
|
|
if (Request::hasVar('op', 'GET')) { |
127
|
|
|
$op = $_GET['op']; |
128
|
|
|
} else { |
129
|
|
|
$op = 'staff'; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
//Retrieve all responses to current ticket |
133
|
|
|
$responses = $ticketInfo->getResponses(); |
134
|
|
|
foreach ($responses as $response) { |
135
|
|
|
if ($has_files) { |
136
|
|
|
$hasFiles = false; |
137
|
|
|
foreach ($aFiles as $file) { |
138
|
|
|
if ($file['responseid'] == $response->getVar('id')) { |
139
|
|
|
$hasFiles = true; |
140
|
|
|
break; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
} else { |
144
|
|
|
$hasFiles = false; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
$aResponses[] = [ |
148
|
|
|
'id' => $response->getVar('id'), |
149
|
|
|
'uid' => $response->getVar('uid'), |
150
|
|
|
'uname' => '', |
151
|
|
|
'ticketid' => $response->getVar('ticketid'), |
152
|
|
|
'message' => $response->getVar('message'), |
153
|
|
|
'timeSpent' => $response->getVar('timeSpent'), |
154
|
|
|
'updateTime' => $response->posted('m'), |
155
|
|
|
'userIP' => $response->getVar('userIP'), |
156
|
|
|
'user_sig' => '', |
157
|
|
|
'user_avatar' => '', |
158
|
|
|
'attachSig' => '', |
159
|
|
|
'staffRating' => '', |
160
|
|
|
'private' => $response->getVar('private'), |
161
|
|
|
'hasFiles' => $hasFiles, |
162
|
|
|
]; |
163
|
|
|
$all_users[$response->getVar('uid')] = ''; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
$all_users[$ticketInfo->getVar('uid')] = ''; |
167
|
|
|
$all_users[$ticketInfo->getVar('ownership')] = ''; |
168
|
|
|
$all_users[$ticketInfo->getVar('closedBy')] = ''; |
169
|
|
|
|
170
|
|
|
$has_responses = count($responses) > 0; |
171
|
|
|
unset($responses); |
172
|
|
|
|
173
|
|
|
$owner = $memberHandler->getUser($ticketInfo->getVar('ownership')); |
174
|
|
|
if ($owner) { |
|
|
|
|
175
|
|
|
$giveOwnership = true; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
//Retrieve all log messages from the database |
179
|
|
|
$logMessage = $ticketInfo->getLogs(); |
180
|
|
|
|
181
|
|
|
$patterns = []; |
182
|
|
|
$patterns[] = '/pri:([1-5])/'; |
183
|
|
|
$replacements = []; |
184
|
|
|
$replacements[] = '<img src="assets/images/priority$1.png" alt="Priority: $1">'; |
185
|
|
|
|
186
|
|
|
foreach ($logMessage as $msg) { |
187
|
|
|
$aMessages[] = [ |
188
|
|
|
'id' => $msg->getVar('id'), |
189
|
|
|
'uid' => $msg->getVar('uid'), |
190
|
|
|
'uname' => '', |
191
|
|
|
//'uname'=>(($msgLoggedBy)? $msgLoggedBy->getVar('uname'):$xoopsConfig['anonymous']), |
192
|
|
|
'ticketid' => $msg->getVar('ticketid'), |
193
|
|
|
'lastUpdated' => $msg->lastUpdated('m'), |
194
|
|
|
'action' => preg_replace($patterns, $replacements, $msg->getVar('action')), |
195
|
|
|
]; |
196
|
|
|
$all_users[$msg->getVar('uid')] = ''; |
197
|
|
|
} |
198
|
|
|
unset($logMessage); |
199
|
|
|
|
200
|
|
|
//For assign to ownership box |
201
|
|
|
/** @var \XoopsModules\Xhelp\MembershipHandler $membershipHandler */ |
202
|
|
|
$membershipHandler = $helper->getHandler('Membership'); |
203
|
|
|
|
204
|
|
|
global $staffArray; |
205
|
|
|
$staffArray = $staffHandler->getStaffByTask(XHELP_SEC_TICKET_TAKE_OWNERSHIP, $ticketInfo->getVar('department')); |
206
|
|
|
|
207
|
|
|
$aOwnership = []; |
208
|
|
|
// Only run if actions are set to inline style |
209
|
|
|
|
210
|
|
|
if (1 == $helper->getConfig('xhelp_staffTicketActions')) { |
211
|
|
|
$aOwnership[] = [ |
212
|
|
|
'uid' => 0, |
213
|
|
|
'uname' => _XHELP_NO_OWNER, |
214
|
|
|
]; |
215
|
|
|
foreach ($staffArray as $stf) { |
216
|
|
|
$aOwnership[] = [ |
217
|
|
|
'uid' => $stf->getVar('uid'), |
218
|
|
|
'uname' => '', |
219
|
|
|
]; |
220
|
|
|
$all_users[$stf->getVar('uid')] = ''; |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
// Get list of user's last submitted tickets |
225
|
|
|
$criteria = new \CriteriaCompo(new \Criteria('uid', $ticketInfo->getVar('uid'))); |
226
|
|
|
$criteria->setSort('posted'); |
227
|
|
|
$criteria->setOrder('DESC'); |
228
|
|
|
$criteria->setLimit(10); |
229
|
|
|
$lastTickets = $ticketHandler->getObjects($criteria); |
230
|
|
|
foreach ($lastTickets as $ticket) { |
231
|
|
|
$dept = $ticket->getVar('department'); |
232
|
|
|
if (isset($departments[$dept])) { |
233
|
|
|
$dept = $departments[$dept]->getVar('department'); |
234
|
|
|
$hasUrl = true; |
235
|
|
|
} else { |
236
|
|
|
$dept = _XHELP_TEXT_NO_DEPT; |
237
|
|
|
$hasUrl = false; |
238
|
|
|
} |
239
|
|
|
$aLastTickets[] = [ |
240
|
|
|
'id' => $ticket->getVar('id'), |
241
|
|
|
'subject' => $ticket->getVar('subject'), |
242
|
|
|
'status' => Xhelp\Utility::getStatus($ticket->getVar('status')), |
243
|
|
|
'department' => $dept, |
244
|
|
|
'dept_url' => $hasUrl ? XOOPS_URL . '/modules/xhelp/index.php?op=staffViewAll&dept=' . $ticket->getVar('department') : '', |
245
|
|
|
'url' => XOOPS_URL . '/modules/xhelp/ticket.php?id=' . $ticket->getVar('id'), |
246
|
|
|
]; |
247
|
|
|
} |
248
|
|
|
$has_lastTickets = count($lastTickets); |
249
|
|
|
unset($lastTickets); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
switch ($op) { |
253
|
|
|
case 'addEmail': |
254
|
|
|
|
255
|
|
|
if ('' === \Xmf\Request::getString('newEmail', '', 'POST')) { |
256
|
|
|
$message = _XHELP_MESSAGE_NO_EMAIL; |
257
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id", 3, $message); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
//Check if email is valid |
261
|
|
|
$validator = new Validation\ValidateEmail(Request::getString('newEmail', '', 'POST')); |
262
|
|
|
if (!$validator->isValid()) { |
263
|
|
|
redirect_header(Xhelp\Utility::createURI('ticket.php', ['id' => $xhelp_id], false), 3, _XHELP_MESSAGE_NO_EMAIL); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** @var \XoopsUser $newUser */ |
267
|
|
|
if ($newUser = Xhelp\Utility::emailIsXoopsUser(Request::getString('newEmail', '', 'POST'))) { |
268
|
|
|
$user_id = $newUser->getVar('uid'); |
269
|
|
|
} else { // If a user doesn't exist with this email |
270
|
|
|
$user_id = 0; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
// Check that the email doesn't already exist for this ticket |
274
|
|
|
/** @var \XoopsModules\Xhelp\TicketEmailsHandler $ticketEmailsHandler */ |
275
|
|
|
$ticketEmailsHandler = $helper->getHandler('TicketEmails'); |
276
|
|
|
$criteria = new \CriteriaCompo(new \Criteria('ticketid', $xhelp_id)); |
277
|
|
|
$criteria->add(new \Criteria('email', \Xmf\Request::getString('newEmail', '', 'POST'))); |
278
|
|
|
$existingUsers = $ticketEmailsHandler->getObjects($criteria); |
279
|
|
|
if (count($existingUsers) > 0) { |
280
|
|
|
$message = _XHELP_MESSAGE_EMAIL_USED; |
281
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id", 3, $message); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
// Create new ticket email object |
285
|
|
|
/** @var \XoopsModules\Xhelp\TicketEmails $newSubmitter */ |
286
|
|
|
$newSubmitter = $ticketEmailsHandler->create(); |
287
|
|
|
$newSubmitter->setVar('email', \Xmf\Request::getString('newEmail', '', 'POST')); |
288
|
|
|
$newSubmitter->setVar('uid', $user_id); |
289
|
|
|
$newSubmitter->setVar('ticketid', $xhelp_id); |
290
|
|
|
$newSubmitter->setVar('suppress', 0); |
291
|
|
|
if ($ticketEmailsHandler->insert($newSubmitter)) { |
292
|
|
|
$message = _XHELP_MESSAGE_ADDED_EMAIL; |
293
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id#emailNotification"); |
294
|
|
|
} else { |
295
|
|
|
$message = _XHELP_MESSAGE_ADDED_EMAIL_ERROR; |
296
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id#emailNotification", 3, $message); |
297
|
|
|
} |
298
|
|
|
break; |
299
|
|
|
case 'changeSuppress': |
300
|
|
|
if (!$xhelp_isStaff) { |
301
|
|
|
$message = _XHELP_MESSAGE_NO_MERGE_TICKET; |
302
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id", 3, $message); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** @var \XoopsModules\Xhelp\TicketEmailsHandler $ticketEmailsHandler */ |
306
|
|
|
$ticketEmailsHandler = $helper->getHandler('TicketEmails'); |
307
|
|
|
$criteria = new \CriteriaCompo(new \Criteria('ticketid', $_GET['id'])); |
308
|
|
|
$criteria->add(new \Criteria('email', $_GET['email'])); |
309
|
|
|
$suppressUser = $ticketEmailsHandler->getObjects($criteria); |
310
|
|
|
|
311
|
|
|
foreach ($suppressUser as $sUser) { |
312
|
|
|
if (0 == $sUser->getVar('suppress')) { |
313
|
|
|
$sUser->setVar('suppress', 1); |
314
|
|
|
} else { |
315
|
|
|
$sUser->setVar('suppress', 0); |
316
|
|
|
} |
317
|
|
|
if (!$ticketEmailsHandler->insert($sUser, true)) { |
318
|
|
|
$message = _XHELP_MESSAGE_ADD_EMAIL_ERROR; |
319
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id#emailNotification", 3, $message); |
320
|
|
|
} |
321
|
|
|
} |
322
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id#emailNotification"); |
323
|
|
|
break; |
324
|
|
|
case 'delete': |
325
|
|
|
if (!$hasRights = $staff->checkRoleRights(XHELP_SEC_TICKET_DELETE, $ticketInfo->getVar('department'))) { |
326
|
|
|
$message = _XHELP_MESSAGE_NO_DELETE_TICKET; |
327
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id", 3, $message); |
328
|
|
|
} |
329
|
|
|
if (Request::hasVar('delete_ticket', 'POST')) { |
330
|
|
|
if ($ticketHandler->delete($ticketInfo)) { |
331
|
|
|
$message = _XHELP_MESSAGE_DELETE_TICKET; |
332
|
|
|
$eventService->trigger('delete_ticket', [&$ticketInfo]); |
333
|
|
|
} else { |
334
|
|
|
$message = _XHELP_MESSAGE_DELETE_TICKET_ERROR; |
335
|
|
|
} |
336
|
|
|
} else { |
337
|
|
|
$message = _XHELP_MESSAGE_DELETE_TICKET_ERROR; |
338
|
|
|
} |
339
|
|
|
$helper->redirect('index.php', 3, $message); |
340
|
|
|
break; |
341
|
|
|
case 'edit': |
342
|
|
|
if (!$hasRights = $staff->checkRoleRights(XHELP_SEC_TICKET_EDIT, $ticketInfo->getVar('department'))) { |
343
|
|
|
$message = _XHELP_MESSAGE_NO_EDIT_TICKET; |
344
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id", 3, $message); |
345
|
|
|
} |
346
|
|
|
/** @var \XoopsModules\Xhelp\DepartmentHandler $departmentHandler */ |
347
|
|
|
$departmentHandler = $helper->getHandler('Department'); // Department handler |
348
|
|
|
|
349
|
|
|
if (isset($_POST['editTicket'])) { |
350
|
|
|
// require_once XHELP_CLASS_PATH . '/validator.php'; |
351
|
|
|
|
352
|
|
|
$v = []; |
353
|
|
|
$v['subject'][] = new Validation\ValidateLength(Request::getString('subject', '', 'POST'), 2, 100); |
354
|
|
|
$v['description'][] = new Validation\ValidateLength(Request::getString('description', '', 'POST'), 2, 50000); |
355
|
|
|
|
356
|
|
|
$aFields = []; |
357
|
|
|
|
358
|
|
|
//Temp Ticket object for _getTicketFields |
359
|
|
|
$_ticket = $ticketInfo; |
360
|
|
|
$_ticket->setVar('department', Request::getString('departments', '', 'POST')); |
361
|
|
|
$custFields = getTicketFields($_ticket); |
362
|
|
|
unset($_ticket); |
363
|
|
|
if (!empty($custFields)) { |
364
|
|
|
foreach ($custFields as $field) { |
365
|
|
|
$fieldname = $field['fieldname']; |
366
|
|
|
$value = \Xmf\Request::getString($fieldname, '', 'POST'); |
367
|
|
|
|
368
|
|
|
$fileid = ''; |
369
|
|
|
$filename = ''; |
370
|
|
|
$file = ''; |
371
|
|
|
if (XHELP_CONTROL_FILE == $field['controltype']) { |
372
|
|
|
$file = explode('_', $value); |
373
|
|
|
$fileid = ((isset($file[0]) && '' != $file[0]) ? $file[0] : ''); |
374
|
|
|
$filename = ((isset($file[1]) && '' != $file[1]) ? $file[1] : ''); |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
if ('' != $field['validation']) { |
378
|
|
|
$v[$fieldname][] = new Validation\ValidateRegex(Request::getString('$fieldname', '', 'POST'), $field['validation'], $field['required']); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
$aFields[$field['fieldname']] = [ |
382
|
|
|
'id' => $field['id'], |
383
|
|
|
'name' => $field['name'], |
384
|
|
|
'description' => $field['desc'], |
385
|
|
|
'fieldname' => $field['fieldname'], |
386
|
|
|
'controltype' => $field['controltype'], |
387
|
|
|
'datatype' => $field['datatype'], |
388
|
|
|
'required' => $field['required'], |
389
|
|
|
'fieldlength' => $field['fieldlength'], |
390
|
|
|
'weight' => $field['weight'], |
391
|
|
|
'fieldvalues' => $field['fieldvalues'], |
392
|
|
|
'defaultvalue' => $field['defaultvalue'], |
393
|
|
|
'validation' => $field['validation'], |
394
|
|
|
'value' => $value, |
395
|
|
|
'fileid' => $fileid, |
396
|
|
|
'filename' => $filename, |
397
|
|
|
]; |
398
|
|
|
} |
399
|
|
|
} |
400
|
|
|
unset($custFields); |
401
|
|
|
|
402
|
|
|
$session->set('xhelp_custFields', $aFields); |
403
|
|
|
$session->set('xhelp_ticket', [ |
404
|
|
|
'subject' => \Xmf\Request::getString('subject', '', 'POST'), |
405
|
|
|
'description' => htmlspecialchars(\Xmf\Request::getString('description', '', 'POST'), ENT_QUOTES), |
406
|
|
|
'department' => $_POST['departments'], |
407
|
|
|
'priority' => $_POST['priority'], |
408
|
|
|
]); |
409
|
|
|
|
410
|
|
|
// Perform each validation |
411
|
|
|
$fields = []; |
412
|
|
|
$errors = []; |
413
|
|
|
foreach ($v as $fieldname => $validator) { |
414
|
|
|
if (Xhelp\Utility::checkRules($validator, $errors)) { |
415
|
|
|
$fields[$fieldname]['haserrors'] = false; |
416
|
|
|
} else { |
417
|
|
|
//Mark field with error |
418
|
|
|
$fields[$fieldname]['haserrors'] = true; |
419
|
|
|
$fields[$fieldname]['errors'] = $errors; |
420
|
|
|
} |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
if (!empty($errors)) { |
424
|
|
|
$session->set('xhelp_validateError', $fields); |
425
|
|
|
$message = _XHELP_MESSAGE_VALIDATE_ERROR; |
426
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id&op=edit"); |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
$oldTicket = [ |
430
|
|
|
'id' => $ticketInfo->getVar('id'), |
431
|
|
|
'subject' => $ticketInfo->getVar('subject', 'n'), |
432
|
|
|
'description' => $ticketInfo->getVar('description', 'n'), |
433
|
|
|
'priority' => $ticketInfo->getVar('priority'), |
434
|
|
|
'status' => Xhelp\Utility::getStatus($ticketInfo->getVar('status')), |
435
|
|
|
'department' => $department->getVar('department'), |
436
|
|
|
'department_id' => $department->getVar('id'), |
437
|
|
|
]; |
438
|
|
|
|
439
|
|
|
// Change ticket info to new info |
440
|
|
|
$ticketInfo->setVar('subject', Request::getString('subject', '', 'POST')); //$_POST['subject']); |
441
|
|
|
$ticketInfo->setVar('description', Request::getString('description', '', 'POST'));//$_POST['description']); |
442
|
|
|
$ticketInfo->setVar('department', $_POST['departments']); |
443
|
|
|
$ticketInfo->setVar('priority', $_POST['priority']); |
444
|
|
|
$ticketInfo->setVar('posted', time()); |
445
|
|
|
|
446
|
|
|
if ($ticketHandler->insert($ticketInfo)) { |
447
|
|
|
$message = _XHELP_MESSAGE_EDITTICKET; // Successfully updated ticket |
448
|
|
|
|
449
|
|
|
// Update custom fields |
450
|
|
|
/** @var \XoopsModules\Xhelp\TicketValuesHandler $ticketValuesHandler */ |
451
|
|
|
$ticketValuesHandler = $helper->getHandler('TicketValues'); |
452
|
|
|
$ticketValues = $ticketValuesHandler->get($xhelp_id); |
453
|
|
|
|
454
|
|
|
if (is_object($ticketValues)) { |
455
|
|
|
foreach ($aFields as $field) { |
456
|
|
|
$ticketValues->setVar($field['fieldname'], $_POST[$field['fieldname']]); |
457
|
|
|
} |
458
|
|
|
if (!$ticketValuesHandler->insert($ticketValues)) { |
459
|
|
|
$message = _XHELP_MESSAGE_NO_CUSTFLD_ADDED . $ticketValues->getHtmlErrors(); |
460
|
|
|
} |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
$eventService->trigger('edit_ticket', [&$oldTicket, &$ticketInfo]); |
464
|
|
|
|
465
|
|
|
$session->del('xhelp_ticket'); |
466
|
|
|
$session->del('xhelp_validateError'); |
467
|
|
|
$session->del('xhelp_custFields'); |
468
|
|
|
} else { |
469
|
|
|
$message = _XHELP_MESSAGE_EDITTICKET_ERROR . $ticketInfo->getHtmlErrors(); // Unsuccessfully updated ticket |
470
|
|
|
} |
471
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id", 3, $message); |
472
|
|
|
} else { |
473
|
|
|
$GLOBALS['xoopsOption']['template_main'] = 'xhelp_editTicket.tpl'; // Always set main template before including the header |
474
|
|
|
require_once XOOPS_ROOT_PATH . '/header.php'; |
475
|
|
|
|
476
|
|
|
$criteria = new \Criteria('', ''); |
477
|
|
|
$criteria->setSort('department'); |
478
|
|
|
$departments = $departmentHandler->getObjects($criteria); |
479
|
|
|
/** @var \XoopsModules\Xhelp\StaffHandler $staffHandler */ |
480
|
|
|
$staffHandler = $helper->getHandler('Staff'); |
481
|
|
|
|
482
|
|
|
foreach ($departments as $dept) { |
483
|
|
|
$aDept[] = [ |
484
|
|
|
'id' => $dept->getVar('id'), |
485
|
|
|
'department' => $dept->getVar('department'), |
486
|
|
|
]; |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
// Form validation stuff |
490
|
|
|
$errors = []; |
491
|
|
|
$aElements = []; |
492
|
|
|
$validateErrors = $session->get('xhelp_validateError'); |
493
|
|
|
if ($validateErrors) { |
494
|
|
|
foreach ($validateErrors as $fieldname => $error) { |
495
|
|
|
if (!empty($error['errors'])) { |
496
|
|
|
$aElements[] = $fieldname; |
497
|
|
|
foreach ($error['errors'] as $err) { |
498
|
|
|
$errors[$fieldname] = $err; |
499
|
|
|
} |
500
|
|
|
} |
501
|
|
|
} |
502
|
|
|
$xoopsTpl->assign('xhelp_errors', $errors); |
503
|
|
|
} else { |
504
|
|
|
$xoopsTpl->assign('xhelp_errors', null); |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
$elements = ['subject', 'description']; |
508
|
|
|
foreach ($elements as $element) { // Foreach element in the predefined list |
509
|
|
|
$xoopsTpl->assign("xhelp_element_$element", 'formButton'); |
510
|
|
|
foreach ($aElements as $aElement) { // Foreach that has an error |
511
|
|
|
if ($aElement == $element) { // If the names are equal |
512
|
|
|
$xoopsTpl->assign("xhelp_element_$element", 'validateError'); |
513
|
|
|
break; |
514
|
|
|
} |
515
|
|
|
} |
516
|
|
|
} |
517
|
|
|
// end form validation stuff |
518
|
|
|
|
519
|
|
|
$javascript = '<script type="text/javascript" src="' . XHELP_BASE_URL . "/include/functions.js\"></script> |
520
|
|
|
<script type=\"text/javascript\" src='" . XHELP_SCRIPT_URL . "/addTicketDeptChange.php?client'></script> |
521
|
|
|
<script type=\"text/javascript\"> |
522
|
|
|
<!-- |
523
|
|
|
function departments_onchange() |
524
|
|
|
{ |
525
|
|
|
dept = xoopsGetElementById('departments'); |
526
|
|
|
var wl = new Xhelp\WebLib(fieldHandler); |
527
|
|
|
wl.editticketcustfields(dept.value, $xhelp_id); |
528
|
|
|
} |
529
|
|
|
|
530
|
|
|
var fieldHandler = { |
531
|
|
|
editticketcustfields: function(result){ |
532
|
|
|
|
533
|
|
|
var tbl = gE('tblEditTicket'); |
534
|
|
|
var staffCol = gE('staff');"; |
535
|
|
|
$javascript .= "var beforeele = gE('editButtons');\n"; |
536
|
|
|
$javascript .= "tbody = tbl.tBodies[0];\n"; |
537
|
|
|
$javascript .= "xhelpFillCustomFlds(tbody, result, beforeele);\n |
538
|
|
|
} |
539
|
|
|
} |
540
|
|
|
|
541
|
|
|
function window_onload() |
542
|
|
|
{ |
543
|
|
|
xhelpDOMAddEvent(xoopsGetElementById('departments'), 'change', departments_onchange, true); |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
xhelpDOMAddEvent(window, 'load', window_onload, true); |
547
|
|
|
//--> |
548
|
|
|
</script>"; |
549
|
|
|
$ticket = $session->get('xhelp_ticket'); |
550
|
|
|
if ($ticket) { |
551
|
|
|
$xoopsTpl->assign('xhelp_ticketID', $xhelp_id); |
552
|
|
|
$xoopsTpl->assign('xhelp_ticket_subject', $ticket['subject']); |
553
|
|
|
$xoopsTpl->assign('xhelp_ticket_description', $ticket['description']); |
554
|
|
|
$xoopsTpl->assign('xhelp_ticket_department', $ticket['department']); |
555
|
|
|
$xoopsTpl->assign('xhelp_departmenturl', 'index.php?op=staffViewAll&dept=' . $ticket['department']); |
556
|
|
|
$xoopsTpl->assign('xhelp_ticket_priority', $ticket['priority']); |
557
|
|
|
} else { |
558
|
|
|
$xoopsTpl->assign('xhelp_ticketID', $xhelp_id); |
559
|
|
|
$xoopsTpl->assign('xhelp_ticket_subject', $ticketInfo->getVar('subject')); |
560
|
|
|
$xoopsTpl->assign('xhelp_ticket_description', $ticketInfo->getVar('description', 'e')); |
561
|
|
|
$xoopsTpl->assign('xhelp_ticket_department', $ticketInfo->getVar('department')); |
562
|
|
|
$xoopsTpl->assign('xhelp_departmenturl', 'index.php?op=staffViewAll&dept=' . $ticketInfo->getVar('department')); |
563
|
|
|
$xoopsTpl->assign('xhelp_ticket_priority', $ticketInfo->getVar('priority')); |
564
|
|
|
} |
565
|
|
|
|
566
|
|
|
//** BTW - why do we need xhelp_allowUpload in the template if it will be always set to 0? |
567
|
|
|
//$xoopsTpl->assign('xhelp_allowUpload', $helper->getConfig('xhelp_allowUpload')); |
568
|
|
|
$xoopsTpl->assign('xhelp_allowUpload', 0); |
569
|
|
|
$xoopsTpl->assign('xhelp_imagePath', XOOPS_URL . '/modules/xhelp/assets/images/'); |
570
|
|
|
$xoopsTpl->assign('xhelp_departments', $aDept); |
571
|
|
|
$xoopsTpl->assign('xhelp_priorities', [5, 4, 3, 2, 1]); |
572
|
|
|
$xoopsTpl->assign('xhelp_priorities_desc', [ |
573
|
|
|
5 => _XHELP_PRIORITY5, |
574
|
|
|
4 => _XHELP_PRIORITY4, |
575
|
|
|
3 => _XHELP_PRIORITY3, |
576
|
|
|
2 => _XHELP_PRIORITY2, |
577
|
|
|
1 => _XHELP_PRIORITY1, |
578
|
|
|
]); |
579
|
|
|
|
580
|
|
|
if (Request::hasVar('logFor', 'POST')) { |
581
|
|
|
$uid = $_POST['logFor']; |
582
|
|
|
$username = Xhelp\Utility::getUsername($uid, $displayName); |
|
|
|
|
583
|
|
|
$xoopsTpl->assign('xhelp_username', $username); |
584
|
|
|
$xoopsTpl->assign('xhelp_user_id', $uid); |
585
|
|
|
} else { |
586
|
|
|
$xoopsTpl->assign('xhelp_username', Xhelp\Utility::getUsername($xoopsUser->getVar('uid'), $displayName)); |
587
|
|
|
$xoopsTpl->assign('xhelp_user_id', $xoopsUser->getVar('uid')); |
588
|
|
|
} |
589
|
|
|
// Used for displaying transparent-background images in IE |
590
|
|
|
$xoopsTpl->assign('xoops_module_header', $javascript . $xhelp_module_header); |
591
|
|
|
$xoopsTpl->assign('xhelp_isStaff', $xhelp_isStaff); |
592
|
|
|
|
593
|
|
|
$savedFields = $session->get('xhelp_custFields'); |
594
|
|
|
if ($savedFields) { |
595
|
|
|
$custFields = $savedFields; |
596
|
|
|
} else { |
597
|
|
|
$custFields = getTicketFields($ticketInfo); |
598
|
|
|
} |
599
|
|
|
$xoopsTpl->assign('xhelp_hasCustFields', !empty($custFields)); |
600
|
|
|
$xoopsTpl->assign('xhelp_custFields', $custFields); |
601
|
|
|
$xoopsTpl->assign('xhelp_uploadPath', XHELP_UPLOAD_PATH); |
602
|
|
|
$xoopsTpl->assign('xhelp_baseURL', XHELP_BASE_URL); |
603
|
|
|
|
604
|
|
|
require_once XOOPS_ROOT_PATH . '/footer.php'; |
605
|
|
|
} |
606
|
|
|
break; |
607
|
|
|
case 'merge': |
608
|
|
|
if (!$hasRights = $staff->checkRoleRights(XHELP_SEC_TICKET_MERGE, $ticketInfo->getVar('department'))) { |
609
|
|
|
$message = _XHELP_MESSAGE_NO_MERGE; |
610
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id", 3, $message); |
611
|
|
|
} |
612
|
|
|
if ('' === $_POST['ticket2']) { |
613
|
|
|
$message = _XHELP_MESSAGE_NO_TICKET2; |
614
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id", 3, $message); |
615
|
|
|
} |
616
|
|
|
|
617
|
|
|
$ticket2_id = Request::getInt('ticket2', 0, 'POST'); |
618
|
|
|
$newTicket = $ticketInfo->merge($ticket2_id); |
619
|
|
|
if ($newTicket) { |
620
|
|
|
$returnTicket = $newTicket; |
621
|
|
|
$message = _XHELP_MESSAGE_MERGE; |
622
|
|
|
$eventService->trigger('merge_tickets', [$xhelp_id, $ticket2_id, $returnTicket]); |
623
|
|
|
} else { |
624
|
|
|
$returnTicket = $xhelp_id; |
625
|
|
|
$message = _XHELP_MESSAGE_MERGE_ERROR; |
626
|
|
|
} |
627
|
|
|
$helper->redirect("ticket.php?id=$returnTicket", 3, $message); |
628
|
|
|
|
629
|
|
|
break; |
630
|
|
|
case 'ownership': |
631
|
|
|
if (!$hasRights = $staff->checkRoleRights(XHELP_SEC_TICKET_OWNERSHIP, $ticketInfo->getVar('department'))) { |
632
|
|
|
$message = _XHELP_MESSAGE_NO_CHANGE_OWNER; |
633
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id", 3, $message); |
634
|
|
|
} |
635
|
|
|
|
636
|
|
|
if (Request::hasVar('uid', 'POST')) { |
637
|
|
|
$uid = Request::getInt('uid', 0, 'POST'); |
638
|
|
|
} else { |
639
|
|
|
$message = _XHELP_MESSAGE_NO_UID; |
640
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id", 3, $message); |
641
|
|
|
} |
642
|
|
|
if (0 != $ticketInfo->getVar('ownership')) { |
643
|
|
|
$oldOwner = (int)$ticketInfo->getVar('ownership'); |
644
|
|
|
} else { |
645
|
|
|
$oldOwner = 0; //_XHELP_NO_OWNER; |
646
|
|
|
} |
647
|
|
|
|
648
|
|
|
$ticketInfo->setVar('ownership', $uid); |
649
|
|
|
$ticketInfo->setVar('lastUpdated', time()); |
650
|
|
|
if ($ticketHandler->insert($ticketInfo)) { |
651
|
|
|
$eventService->trigger('update_owner', [&$ticketInfo, $oldOwner, $xoopsUser->getVar('uid')]); |
652
|
|
|
$message = _XHELP_MESSAGE_UPDATE_OWNER; |
653
|
|
|
} |
654
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id", 3, $message); |
655
|
|
|
|
656
|
|
|
break; |
657
|
|
|
case 'print': |
658
|
|
|
/** @var \XoopsConfigHandler $configHandler */ |
659
|
|
|
$configHandler = xoops_getHandler('config'); |
660
|
|
|
$xoopsConfigMetaFooter = $configHandler->getConfigsByCat(XOOPS_CONF_METAFOOTER); |
661
|
|
|
|
662
|
|
|
$patterns = []; |
663
|
|
|
$patterns[] = '/pri:([1-5])/'; |
664
|
|
|
$replacements = []; |
665
|
|
|
$replacements = '<img src="assets/images/priority$1print.png">'; |
666
|
|
|
|
667
|
|
|
foreach ($logMessage as $msg) { |
668
|
|
|
$msgLoggedBy = $memberHandler->getUser($msg->getVar('uid')); |
669
|
|
|
$aPrintMessages[] = [ |
670
|
|
|
'id' => $msg->getVar('id'), |
671
|
|
|
'uid' => $msg->getVar('uid'), |
672
|
|
|
'uname' => Xhelp\Utility::getUsername($msgLoggedBy->getVar('uid'), $displayName), |
673
|
|
|
'ticketid' => $msg->getVar('ticketid'), |
674
|
|
|
'lastUpdated' => $msg->lastUpdated('m'), |
675
|
|
|
'action' => preg_replace($patterns, $replacements, $msg->getVar('action')), |
676
|
|
|
]; |
677
|
|
|
$all_users[$msg->getVar('uid')] = ''; |
678
|
|
|
} |
679
|
|
|
unset($logMessage); |
680
|
|
|
|
681
|
|
|
require_once XOOPS_ROOT_PATH . '/class/template.php'; |
682
|
|
|
$xoopsTpl = new \XoopsTpl(); |
683
|
|
|
$xoopsTpl->assign('xhelp_imagePath', XOOPS_URL . '/modules/xhelp/assets/images/'); |
684
|
|
|
$xoopsTpl->assign('xhelp_lang_userlookup', 'User Lookup'); |
685
|
|
|
$xoopsTpl->assign('sitename', $xoopsConfig['sitename']); |
686
|
|
|
$xoopsTpl->assign('xoops_themecss', xoops_getcss()); |
687
|
|
|
$xoopsTpl->assign('xoops_url', XOOPS_URL); |
688
|
|
|
$xoopsTpl->assign('xhelp_print_logMessages', $aPrintMessages); |
689
|
|
|
$xoopsTpl->assign('xhelp_ticket_subject', $ticketInfo->getVar('subject')); |
690
|
|
|
$xoopsTpl->assign('xhelp_ticket_description', $ticketInfo->getVar('description')); |
691
|
|
|
$xoopsTpl->assign('xhelp_ticket_department', $department->getVar('department')); |
692
|
|
|
$xoopsTpl->assign('xhelp_ticket_priority', $ticketInfo->getVar('priority')); |
693
|
|
|
$xoopsTpl->assign('xhelp_ticket_status', Xhelp\Utility::getStatus($ticketInfo->getVar('status'))); |
694
|
|
|
$xoopsTpl->assign('xhelp_ticket_lastUpdated', $ticketInfo->lastUpdated('m')); |
695
|
|
|
$xoopsTpl->assign('xhelp_ticket_posted', $ticketInfo->posted('m')); |
696
|
|
|
if ($giveOwnership) { |
697
|
|
|
$xoopsTpl->assign('xhelp_ticket_ownerUid', $owner->getVar('uid')); |
698
|
|
|
$xoopsTpl->assign('xhelp_ticket_ownership', Xhelp\Utility::getUsername($owner, $displayName)); |
699
|
|
|
$xoopsTpl->assign('xhelp_ownerinfo', XOOPS_URL . '/userinfo.php?uid=' . $owner->getVar('uid')); |
700
|
|
|
} |
701
|
|
|
$xoopsTpl->assign('xhelp_ticket_closedBy', $ticketInfo->getVar('closedBy')); |
702
|
|
|
$xoopsTpl->assign('xhelp_ticket_totalTimeSpent', $ticketInfo->getVar('totalTimeSpent')); |
703
|
|
|
$xoopsTpl->assign('xhelp_userinfo', XOOPS_URL . '/userinfo.php?uid=' . $ticketInfo->getVar('uid')); |
704
|
|
|
$xoopsTpl->assign('xhelp_username', Xhelp\Utility::getUsername($user, $displayName)); |
705
|
|
|
$xoopsTpl->assign('xhelp_ticket_details', sprintf(_XHELP_TEXT_TICKETDETAILS, $xhelp_id)); |
706
|
|
|
|
707
|
|
|
$custFields = $ticketInfo->getCustFieldValues(); |
708
|
|
|
$xoopsTpl->assign('xhelp_hasCustFields', !empty($custFields)); |
709
|
|
|
$xoopsTpl->assign('xhelp_custFields', $custFields); |
710
|
|
|
|
711
|
|
|
if (isset($aMessages)) { |
712
|
|
|
$xoopsTpl->assign('xhelp_logMessages', $aMessages); |
713
|
|
|
} else { |
714
|
|
|
$xoopsTpl->assign('xhelp_logMessages', 0); |
715
|
|
|
} |
716
|
|
|
$xoopsTpl->assign('xhelp_text_claimOwner', _XHELP_TEXT_CLAIM_OWNER); |
717
|
|
|
$xoopsTpl->assign('xhelp_aOwnership', $aOwnership); |
718
|
|
|
|
719
|
|
|
if ($has_responses) { |
720
|
|
|
$users = []; |
721
|
|
|
$_users = $memberHandler->getUsers(new \Criteria('uid', '(' . implode(',', array_keys($all_users)) . ')', 'IN'), true); |
722
|
|
|
foreach ($_users as $key => $_user) { |
723
|
|
|
if ((2 == $displayName) && ('' != $_user->getVar('name'))) { |
724
|
|
|
$users[$_user->getVar('uid')] = ['uname' => $_user->getVar('name')]; |
725
|
|
|
} else { |
726
|
|
|
$users[$_user->getVar('uid')] = ['uname' => $_user->getVar('uname')]; |
727
|
|
|
} |
728
|
|
|
} |
729
|
|
|
unset($_users); |
730
|
|
|
|
731
|
|
|
$myTs = \MyTextSanitizer::getInstance(); |
732
|
|
|
//Update arrays with user information |
733
|
|
|
if (count($aResponses) > 0) { |
734
|
|
|
for ($i = 0, $iMax = count($aResponses); $i < $iMax; ++$i) { |
735
|
|
|
if (isset($users[$aResponses[$i]['uid']])) { // Add uname to array |
736
|
|
|
$aResponses[$i]['uname'] = $users[$aResponses[$i]['uid']]['uname']; |
737
|
|
|
} else { |
738
|
|
|
$aResponses[$i]['uname'] = $xoopsConfig['anonymous']; |
739
|
|
|
} |
740
|
|
|
} |
741
|
|
|
} |
742
|
|
|
$xoopsTpl->assign('xhelp_aResponses', $aResponses); |
743
|
|
|
} else { |
744
|
|
|
$xoopsTpl->assign('xhelp_aResponses', 0); |
745
|
|
|
} |
746
|
|
|
$xoopsTpl->assign('xhelp_claimOwner', $xoopsUser->getVar('uid')); |
747
|
|
|
$xoopsTpl->assign('xhelp_hasResponses', $has_responses); |
748
|
|
|
$xoopsTpl->assign('xoops_meta_robots', $xoopsConfigMetaFooter['meta_robots']); |
749
|
|
|
$xoopsTpl->assign('xoops_meta_keywords', $xoopsConfigMetaFooter['meta_keywords']); |
750
|
|
|
$xoopsTpl->assign('xoops_meta_description', $xoopsConfigMetaFooter['meta_description']); |
751
|
|
|
$xoopsTpl->assign('xoops_meta_rating', $xoopsConfigMetaFooter['meta_rating']); |
752
|
|
|
$xoopsTpl->assign('xoops_meta_author', $xoopsConfigMetaFooter['meta_author']); |
753
|
|
|
$xoopsTpl->assign('xoops_meta_copyright', $xoopsConfigMetaFooter['meta_copyright']); |
754
|
|
|
|
755
|
|
|
$module_dir = $xoopsModule->getVar('mid'); |
756
|
|
|
$xoopsTpl->display('db:xhelp_print.tpl'); |
757
|
|
|
exit(); |
758
|
|
|
case 'updatePriority': |
759
|
|
|
if (!$hasRights = $staff->checkRoleRights(XHELP_SEC_TICKET_ADD)) { |
760
|
|
|
$message = _XHELP_MESSAGE_NO_ADD_TICKET; |
761
|
|
|
$helper->redirect('index.php', 3, $message); |
762
|
|
|
} |
763
|
|
|
|
764
|
|
|
if (Request::hasVar('priority', 'POST')) { |
765
|
|
|
$priority = $_POST['priority']; |
766
|
|
|
} else { |
767
|
|
|
$message = _XHELP_MESSAGE_NO_PRIORITY; |
768
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id", 3, $message); |
769
|
|
|
} |
770
|
|
|
$oldPriority = $ticketInfo->getVar('priority'); |
771
|
|
|
$ticketInfo->setVar('priority', $priority); |
772
|
|
|
$ticketInfo->setVar('lastUpdated', time()); |
773
|
|
|
if ($ticketHandler->insert($ticketInfo)) { |
774
|
|
|
$eventService->trigger('update_priority', [&$ticketInfo, $oldPriority]); |
775
|
|
|
$message = _XHELP_MESSAGE_UPDATE_PRIORITY; |
776
|
|
|
} else { |
777
|
|
|
$message = _XHELP_MESSAGE_UPDATE_PRIORITY_ERROR . '. '; |
778
|
|
|
} |
779
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id", 3, $message); |
780
|
|
|
break; |
781
|
|
|
case 'updateStatus': |
782
|
|
|
$addResponse = $changeStatus = false; |
783
|
|
|
$statusClosed = $statusReopened = false; |
784
|
|
|
$responseError = $ticketError = false; |
785
|
|
|
|
786
|
|
|
//1. Check if either a response was added or status was changed |
787
|
|
|
$addResponse = ('' != \Xmf\Request::getString('response', '', 'POST')); |
788
|
|
|
$changeStatus = ($_POST['status'] != $ticketInfo->getVar('status')); |
789
|
|
|
|
790
|
|
|
if ($addResponse || $changeStatus) { |
791
|
|
|
//2. Update Ticket LastUpdated time |
792
|
|
|
$ticketInfo->setVar('lastUpdated', time()); |
793
|
|
|
|
794
|
|
|
//3. Add Response (if necessary) |
795
|
|
|
if (true === $addResponse) { |
796
|
|
|
if ($ticketInfo->canAddResponse($xoopsUser)) { |
797
|
|
|
$userIP = xoops_getenv('REMOTE_ADDR'); |
798
|
|
|
$newResponse = $ticketInfo->addResponse($xoopsUser->getVar('uid'), $xhelp_id, $_POST['response'], $ticketInfo->getVar('lastUpdated'), $userIP, 0, 0, true); |
799
|
|
|
$responseError = !is_object($newResponse); |
800
|
|
|
} |
801
|
|
|
} |
802
|
|
|
|
803
|
|
|
//4. Update Status (if necessary) |
804
|
|
|
if (true === $changeStatus) { |
805
|
|
|
//Check if the current staff member can change status |
806
|
|
|
if ($staff->checkRoleRights(XHELP_SEC_TICKET_STATUS, $ticketInfo->getVar('department'))) { |
807
|
|
|
/** @var \XoopsModules\Xhelp\StatusHandler $statusHandler */ |
808
|
|
|
$statusHandler = $helper->getHandler('Status'); |
809
|
|
|
/** @var \XoopsModules\Xhelp\StaffHandler $staffHandler */ |
810
|
|
|
$staffHandler = $helper->getHandler('Staff'); |
811
|
|
|
|
812
|
|
|
$oldStatus = $statusHandler->get($ticketInfo->getVar('status')); |
813
|
|
|
$newStatus = $statusHandler->get(Request::getInt('status', 0, 'POST')); |
814
|
|
|
$ticketInfo->setVar('status', $_POST['status']); |
815
|
|
|
|
816
|
|
|
if (XHELP_STATE_RESOLVED == $newStatus->getVar('state') |
817
|
|
|
&& XHELP_STATE_UNRESOLVED == $oldStatus->getVar('state')) { |
818
|
|
|
//Closing the ticket |
819
|
|
|
$ticketInfo->setVar('closedBy', $xoopsUser->getVar('uid')); |
820
|
|
|
$statusClosed = true; |
821
|
|
|
} elseif (XHELP_STATE_RESOLVED == $oldStatus->getVar('state') |
822
|
|
|
&& XHELP_STATE_UNRESOLVED == $newStatus->getVar('state')) { |
823
|
|
|
//Re-opening the ticket |
824
|
|
|
$ticketInfo->setVar('overdueTime', $ticketInfo->getVar('posted') + ($helper->getConfig('xhelp_overdueTime') * 60 * 60)); |
825
|
|
|
$statusReopened = true; |
826
|
|
|
} |
827
|
|
|
} |
828
|
|
|
} |
829
|
|
|
|
830
|
|
|
//5. Save Ticket |
831
|
|
|
$ticketError = !$ticketHandler->insert($ticketInfo); |
832
|
|
|
|
833
|
|
|
//6. Fire Necessary Events, set response messages |
834
|
|
|
if (true === $addResponse && false === $responseError) { |
835
|
|
|
$eventService->trigger('new_response', [&$ticketInfo, &$newResponse]); |
836
|
|
|
$message .= _XHELP_MESSAGE_ADDRESPONSE; |
837
|
|
|
} elseif (true === $addResponse && true === $responseError) { |
838
|
|
|
$message .= _XHELP_MESSAGE_ADDRESPONSE_ERROR; |
839
|
|
|
} |
840
|
|
|
|
841
|
|
|
if (true === $changeStatus && false === $ticketError) { |
842
|
|
|
if ($statusClosed) { |
843
|
|
|
$eventService->trigger('close_ticket', [&$ticketInfo]); |
844
|
|
|
} elseif ($statusReopened) { |
845
|
|
|
$eventService->trigger('reopen_ticket', [&$ticketInfo]); |
846
|
|
|
} else { |
847
|
|
|
$eventService->trigger('update_status', [&$ticketInfo, &$oldStatus, &$newStatus]); |
848
|
|
|
} |
849
|
|
|
|
850
|
|
|
$message .= _XHELP_MESSAGE_UPDATE_STATUS; |
851
|
|
|
} elseif (true === $changeStatus && true === $ticketError) { |
852
|
|
|
$message .= _XHELP_MESSAGE_UPDATE_STATUS_ERROR . '. '; |
853
|
|
|
} |
854
|
|
|
} else { |
855
|
|
|
//No Changes Made |
856
|
|
|
//todo: Add new language constant for this |
857
|
|
|
$message = _XHELP_MESSAGE_NO_CHANGE_STATUS; |
858
|
|
|
} |
859
|
|
|
|
860
|
|
|
//Notify user of changes |
861
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id", 3, $message); |
862
|
|
|
|
863
|
|
|
break; |
864
|
|
|
case 'staff': |
865
|
|
|
/** @var \XoopsModules\Xhelp\StatusHandler $statusHandler */ |
866
|
|
|
$statusHandler = $helper->getHandler('Status'); |
867
|
|
|
$eventService->trigger('view_ticket', [&$ticketInfo]); |
868
|
|
|
$GLOBALS['xoopsOption']['template_main'] = 'xhelp_staff_ticketDetails.tpl'; // Set template |
869
|
|
|
require_once XOOPS_ROOT_PATH . '/header.php'; // Include |
870
|
|
|
|
871
|
|
|
$users = []; |
872
|
|
|
$_users = $memberHandler->getUsers(new \Criteria('uid', '(' . implode(',', array_keys($all_users)) . ')', 'IN'), true); |
873
|
|
|
foreach ($_users as $key => $_user) { |
874
|
|
|
if ((2 == $displayName) && ('' != $_user->getVar('name'))) { |
875
|
|
|
$users[$key] = [ |
876
|
|
|
'uname' => $_user->getVar('name'), |
877
|
|
|
'user_sig' => $_user->getVar('user_sig'), |
878
|
|
|
'user_avatar' => $_user->getVar('user_avatar'), |
879
|
|
|
]; |
880
|
|
|
} else { |
881
|
|
|
$users[$key] = [ |
882
|
|
|
'uname' => $_user->getVar('uname'), |
883
|
|
|
'user_sig' => $_user->getVar('user_sig'), |
884
|
|
|
'user_avatar' => $_user->getVar('user_avatar'), |
885
|
|
|
]; |
886
|
|
|
} |
887
|
|
|
} |
888
|
|
|
|
889
|
|
|
$criteria = new \Criteria('', ''); |
890
|
|
|
$criteria->setSort('department'); |
891
|
|
|
$alldepts = $departmentHandler->getObjects($criteria); |
892
|
|
|
foreach ($alldepts as $dept) { |
893
|
|
|
$aDept[$dept->getVar('id')] = $dept->getVar('department'); |
894
|
|
|
} |
895
|
|
|
unset($_users); |
896
|
|
|
$staffArray = []; |
897
|
|
|
$_staff = $staffHandler->getObjects(new \Criteria('uid', '(' . implode(',', array_keys($all_users)) . ')', 'IN'), true); |
898
|
|
|
foreach ($_staff as $key => $_user) { |
899
|
|
|
$staffArray[$key] = $_user->getVar('attachSig'); |
900
|
|
|
} |
901
|
|
|
unset($_staff); |
902
|
|
|
$staffReviews = $ticketInfo->getReviews(); |
903
|
|
|
|
904
|
|
|
$myTs = \MyTextSanitizer::getInstance(); |
905
|
|
|
//Update arrays with user information |
906
|
|
|
if (count($aResponses) > 0) { |
907
|
|
|
for ($i = 0, $iMax = count($aResponses); $i < $iMax; ++$i) { |
908
|
|
|
if (isset($users[$aResponses[$i]['uid']])) { // Add uname to array |
909
|
|
|
$aResponses[$i]['uname'] = $users[$aResponses[$i]['uid']]['uname']; |
910
|
|
|
$aResponses[$i]['user_sig'] = $myTs->displayTarea($users[$aResponses[$i]['uid']]['user_sig'], true); |
911
|
|
|
$aResponses[$i]['user_avatar'] = XOOPS_URL . '/uploads/' . ($users[$aResponses[$i]['uid']]['user_avatar'] ?: 'blank.gif'); |
912
|
|
|
} else { |
913
|
|
|
$aResponses[$i]['uname'] = $xoopsConfig['anonymous']; |
914
|
|
|
} |
915
|
|
|
$aResponses[$i]['staffRating'] = _XHELP_RATING0; |
916
|
|
|
|
917
|
|
|
if (isset($staffArray[$aResponses[$i]['uid']])) { // Add attachSig to array |
918
|
|
|
$aResponses[$i]['attachSig'] = $staffArray[$aResponses[$i]['uid']]; |
919
|
|
|
} |
920
|
|
|
|
921
|
|
|
if (count($staffReviews) > 0) { // Add staffRating to array |
922
|
|
|
foreach ($staffReviews as $review) { |
923
|
|
|
if ($aResponses[$i]['id'] == $review->getVar('responseid')) { |
924
|
|
|
$aResponses[$i]['staffRating'] = Xhelp\Utility::getRating($review->getVar('rating')); |
925
|
|
|
} |
926
|
|
|
} |
927
|
|
|
} |
928
|
|
|
} |
929
|
|
|
} |
930
|
|
|
if (isset($aMessages)) { |
931
|
|
|
for ($i = 0, $iMax = count($aMessages); $i < $iMax; ++$i) { // Fill other values for log messages |
932
|
|
|
if (isset($users[$aMessages[$i]['uid']])) { |
933
|
|
|
$aMessages[$i]['uname'] = $users[$aMessages[$i]['uid']]['uname']; |
934
|
|
|
} else { |
935
|
|
|
$aMessages[$i]['uname'] = $xoopsConfig['anonymous']; |
936
|
|
|
} |
937
|
|
|
} |
938
|
|
|
} |
939
|
|
|
if (1 == $helper->getConfig('xhelp_staffTicketActions')) { |
940
|
|
|
for ($i = 0, $iMax = count($aOwnership); $i < $iMax; ++$i) { |
941
|
|
|
if (isset($users[$aOwnership[$i]['uid']])) { |
942
|
|
|
$aOwnership[$i]['uname'] = $users[$aOwnership[$i]['uid']]['uname']; |
943
|
|
|
} |
944
|
|
|
} |
945
|
|
|
} |
946
|
|
|
unset($users); |
947
|
|
|
|
948
|
|
|
// Get list of users notified of changes to ticket |
949
|
|
|
/** @var \XoopsModules\Xhelp\TicketEmailsHandler $ticketEmailsHandler */ |
950
|
|
|
$ticketEmailsHandler = $helper->getHandler('TicketEmails'); |
951
|
|
|
$criteria = new \Criteria('ticketid', $xhelp_id); |
952
|
|
|
$criteria->setOrder('ASC'); |
953
|
|
|
$criteria->setSort('email'); |
954
|
|
|
$notifiedUsers = $ticketEmailsHandler->getObjects($criteria); |
955
|
|
|
$aNotified = []; |
956
|
|
|
foreach ($notifiedUsers as $nUser) { |
957
|
|
|
$aNotified[] = [ |
958
|
|
|
'email' => $nUser->getVar('email'), |
959
|
|
|
'suppress' => $nUser->getVar('suppress'), |
960
|
|
|
'suppressUrl' => XOOPS_URL . "/modules/xhelp/ticket.php?id=$xhelp_id&op=changeSuppress&email=" . $nUser->getVar('email'), |
961
|
|
|
]; |
962
|
|
|
} |
963
|
|
|
unset($notifiedUsers); |
964
|
|
|
|
965
|
|
|
$uid = $xoopsUser->getVar('uid'); |
966
|
|
|
$xoopsTpl->assign('xhelp_uid', $uid); |
967
|
|
|
|
968
|
|
|
// Smarty variables |
969
|
|
|
$xoopsTpl->assign('xhelp_baseURL', XHELP_BASE_URL); |
970
|
|
|
$xoopsTpl->assign('xhelp_allowUpload', $helper->getConfig('xhelp_allowUpload')); |
971
|
|
|
$xoopsTpl->assign('xhelp_imagePath', XOOPS_URL . '/modules/xhelp/assets/images/'); |
972
|
|
|
$xoopsTpl->assign('xoops_module_header', $xhelp_module_header); |
973
|
|
|
$xoopsTpl->assign('xhelp_ticketID', $xhelp_id); |
974
|
|
|
$xoopsTpl->assign('xhelp_ticket_uid', $ticketInfo->getVar('uid')); |
975
|
|
|
$submitUser = $memberHandler->getUser($ticketInfo->getVar('uid')); |
976
|
|
|
$xoopsTpl->assign( |
977
|
|
|
'xhelp_user_avatar', |
978
|
|
|
XOOPS_URL . '/uploads/' . (($submitUser |
979
|
|
|
&& '' != $submitUser->getVar('user_avatar')) ? $submitUser->getVar('user_avatar') : 'blank.gif') |
980
|
|
|
); |
981
|
|
|
$xoopsTpl->assign('xhelp_ticket_subject', $ticketInfo->getVar('subject', 's')); |
982
|
|
|
$xoopsTpl->assign('xhelp_ticket_description', $ticketInfo->getVar('description')); |
983
|
|
|
$xoopsTpl->assign('xhelp_ticket_department', (isset($departments[$ticketInfo->getVar('department')]) ? $departments[$ticketInfo->getVar('department')]->getVar('department') : _XHELP_TEXT_NO_DEPT)); |
984
|
|
|
$xoopsTpl->assign('xhelp_departmenturl', 'index.php?op=staffViewAll&dept=' . $ticketInfo->getVar('department')); |
985
|
|
|
$xoopsTpl->assign('xhelp_departmentid', $ticketInfo->getVar('department')); |
986
|
|
|
$xoopsTpl->assign('xhelp_departments', $aDept); |
987
|
|
|
$xoopsTpl->assign('xhelp_ticket_priority', $ticketInfo->getVar('priority')); |
988
|
|
|
$xoopsTpl->assign('xhelp_ticket_status', $ticketInfo->getVar('status')); |
989
|
|
|
$xoopsTpl->assign('xhelp_text_status', Xhelp\Utility::getStatus($ticketInfo->getVar('status'))); |
990
|
|
|
$xoopsTpl->assign('xhelp_ticket_userIP', $ticketInfo->getVar('userIP')); |
991
|
|
|
$xoopsTpl->assign('xhelp_ticket_lastUpdated', $ticketInfo->lastUpdated('m')); |
992
|
|
|
$xoopsTpl->assign('xhelp_priorities', [5, 4, 3, 2, 1]); |
993
|
|
|
$xoopsTpl->assign('xhelp_priorities_desc', [ |
994
|
|
|
5 => _XHELP_PRIORITY5, |
995
|
|
|
4 => _XHELP_PRIORITY4, |
996
|
|
|
3 => _XHELP_PRIORITY3, |
997
|
|
|
2 => _XHELP_PRIORITY2, |
998
|
|
|
1 => _XHELP_PRIORITY1, |
999
|
|
|
]); |
1000
|
|
|
$xoopsTpl->assign('xhelp_ticket_posted', $ticketInfo->posted('m')); |
1001
|
|
|
if ($giveOwnership) { |
1002
|
|
|
$xoopsTpl->assign('xhelp_ticket_ownerUid', $owner->getVar('uid')); |
1003
|
|
|
$xoopsTpl->assign('xhelp_ticket_ownership', Xhelp\Utility::getUsername($owner, $displayName)); |
1004
|
|
|
$xoopsTpl->assign('xhelp_ownerinfo', XOOPS_URL . '/userinfo.php?uid=' . $owner->getVar('uid')); |
1005
|
|
|
} |
1006
|
|
|
$xoopsTpl->assign('xhelp_ticket_closedBy', $ticketInfo->getVar('closedBy')); |
1007
|
|
|
$xoopsTpl->assign('xhelp_ticket_totalTimeSpent', $ticketInfo->getVar('totalTimeSpent')); |
1008
|
|
|
$xoopsTpl->assign('xhelp_userinfo', XOOPS_URL . '/userinfo.php?uid=' . $ticketInfo->getVar('uid')); |
1009
|
|
|
$xoopsTpl->assign('xhelp_username', ($user ? Xhelp\Utility::getUsername($user, $displayName) : $xoopsConfig['anonymous'])); |
|
|
|
|
1010
|
|
|
$xoopsTpl->assign('xhelp_userlevel', ($user ? $user->getVar('level') : 0)); |
|
|
|
|
1011
|
|
|
$xoopsTpl->assign('xhelp_email', ($user ? $user->getVar('email') : '')); |
|
|
|
|
1012
|
|
|
$xoopsTpl->assign('xhelp_ticket_details', sprintf(_XHELP_TEXT_TICKETDETAILS, $xhelp_id)); |
1013
|
|
|
$xoopsTpl->assign('xhelp_notifiedUsers', $aNotified); |
1014
|
|
|
$xoopsTpl->assign('xhelp_savedSearches', $aSavedSearches); |
1015
|
|
|
|
1016
|
|
|
if (isset($aMessages)) { |
1017
|
|
|
$xoopsTpl->assign('xhelp_logMessages', $aMessages); |
1018
|
|
|
} else { |
1019
|
|
|
$xoopsTpl->assign('xhelp_logMessages', 0); |
1020
|
|
|
} |
1021
|
|
|
$xoopsTpl->assign('xhelp_aOwnership', $aOwnership); |
1022
|
|
|
if ($has_responses) { |
1023
|
|
|
$xoopsTpl->assign('xhelp_aResponses', $aResponses); |
1024
|
|
|
} |
1025
|
|
|
unset($aResponses); |
1026
|
|
|
if ($has_files) { |
1027
|
|
|
$xoopsTpl->assign('xhelp_aFiles', $aFiles); |
1028
|
|
|
$xoopsTpl->assign('xhelp_hasTicketFiles', $has_ticketFiles); |
1029
|
|
|
} else { |
1030
|
|
|
$xoopsTpl->assign('xhelp_aFiles', false); |
1031
|
|
|
$xoopsTpl->assign('xhelp_hasTicketFiles', false); |
1032
|
|
|
} |
1033
|
|
|
$xoopsTpl->assign('xhelp_claimOwner', $xoopsUser->getVar('uid')); |
1034
|
|
|
$xoopsTpl->assign('xhelp_hasResponses', $has_responses); |
1035
|
|
|
$xoopsTpl->assign('xhelp_hasFiles', $has_files); |
1036
|
|
|
$xoopsTpl->assign('xhelp_hasTicketFiles', $has_ticketFiles); |
1037
|
|
|
$xoopsTpl->assign('xhelp_filePath', XOOPS_URL . '/uploads/xhelp/'); |
1038
|
|
|
$module_dir = $xoopsModule->getVar('mid'); |
1039
|
|
|
$xoopsTpl->assign('xhelp_admin', $xoopsUser->isAdmin($module_dir)); |
1040
|
|
|
$xoopsTpl->assign('xhelp_has_lastSubmitted', $has_lastTickets); |
1041
|
|
|
$xoopsTpl->assign('xhelp_lastSubmitted', $aLastTickets); |
1042
|
|
|
$xoopsTpl->assign('xoops_pagetitle', $xoopsModule->getVar('name') . ' - ' . $ticketInfo->getVar('subject')); |
1043
|
|
|
$xoopsTpl->assign('xhelp_showActions', $helper->getConfig('xhelp_staffTicketActions')); |
1044
|
|
|
|
1045
|
|
|
$xoopsTpl->assign('xhelp_has_changeOwner', false); |
1046
|
|
|
if ($ticketInfo->getVar('uid') == $xoopsUser->getVar('uid')) { |
1047
|
|
|
$xoopsTpl->assign('xhelp_has_addResponse', true); |
1048
|
|
|
} else { |
1049
|
|
|
$xoopsTpl->assign('xhelp_has_addResponse', false); |
1050
|
|
|
} |
1051
|
|
|
$xoopsTpl->assign('xhelp_has_editTicket', false); |
1052
|
|
|
$xoopsTpl->assign('xhelp_has_deleteTicket', false); |
1053
|
|
|
$xoopsTpl->assign('xhelp_has_changePriority', false); |
1054
|
|
|
$xoopsTpl->assign('xhelp_has_changeStatus', false); |
1055
|
|
|
$xoopsTpl->assign('xhelp_has_editResponse', false); |
1056
|
|
|
$xoopsTpl->assign('xhelp_has_mergeTicket', false); |
1057
|
|
|
$xoopsTpl->assign('xhelp_has_faqAdd', false); |
1058
|
|
|
$colspan = 5; |
1059
|
|
|
|
1060
|
|
|
$checkRights = [ |
1061
|
|
|
XHELP_SEC_TICKET_OWNERSHIP => ['xhelp_has_changeOwner', false], |
1062
|
|
|
XHELP_SEC_RESPONSE_ADD => ['xhelp_has_addResponse', true], |
1063
|
|
|
XHELP_SEC_TICKET_EDIT => ['xhelp_has_editTicket', true], |
1064
|
|
|
XHELP_SEC_TICKET_DELETE => ['xhelp_has_deleteTicket', true], |
1065
|
|
|
XHELP_SEC_TICKET_MERGE => ['xhelp_has_mergeTicket', true], |
1066
|
|
|
XHELP_SEC_TICKET_PRIORITY => ['xhelp_has_changePriority', true], |
1067
|
|
|
XHELP_SEC_TICKET_STATUS => ['xhelp_has_changeStatus', false], |
1068
|
|
|
XHELP_SEC_RESPONSE_EDIT => ['xhelp_has_editResponse', false], |
1069
|
|
|
XHELP_SEC_FILE_DELETE => ['xhelp_has_deleteFile', false], |
1070
|
|
|
XHELP_SEC_FAQ_ADD => ['xhelp_has_faqAdd', false], |
1071
|
|
|
XHELP_SEC_TICKET_TAKE_OWNERSHIP => ['xhelp_has_takeOwnership', false], |
1072
|
|
|
]; |
1073
|
|
|
|
1074
|
|
|
// See if this user is accepted for this ticket |
1075
|
|
|
/** @var \XoopsModules\Xhelp\TicketEmailsHandler $ticketEmailsHandler */ |
1076
|
|
|
$ticketEmailsHandler = $helper->getHandler('TicketEmails'); |
1077
|
|
|
$criteria = new \CriteriaCompo(new \Criteria('ticketid', $xhelp_id)); |
1078
|
|
|
$criteria->add(new \Criteria('uid', $xoopsUser->getVar('uid'))); |
1079
|
|
|
$ticketEmails = $ticketEmailsHandler->getObjects($criteria); |
1080
|
|
|
|
1081
|
|
|
foreach ($checkRights as $right => $desc) { |
1082
|
|
|
if ((XHELP_SEC_RESPONSE_ADD == $right) && (count($ticketEmails) > 0)) { |
1083
|
|
|
//Is this user in the ticket emails list (should be treated as a user) |
1084
|
|
|
$xoopsTpl->assign($desc[0], true); |
1085
|
|
|
++$colspan; |
1086
|
|
|
continue; |
1087
|
|
|
} |
1088
|
|
|
if ((XHELP_SEC_TICKET_STATUS == $right) && count($ticketEmails) > 0) { |
1089
|
|
|
//Is this user in the ticket emails list (should be treated as a user) |
1090
|
|
|
$xoopsTpl->assign($desc[0], true); |
1091
|
|
|
++$colspan; |
1092
|
|
|
continue; |
1093
|
|
|
} |
1094
|
|
|
$hasRights = $staff->checkRoleRights($right, $ticketInfo->getVar('department')); |
1095
|
|
|
if ($hasRights) { |
1096
|
|
|
$xoopsTpl->assign($desc[0], true); |
1097
|
|
|
} else { |
1098
|
|
|
if ($desc[1]) { |
1099
|
|
|
$colspan--; |
1100
|
|
|
} |
1101
|
|
|
} |
1102
|
|
|
} |
1103
|
|
|
$xoopsTpl->assign('xhelp_actions_colspan', $colspan); |
1104
|
|
|
|
1105
|
|
|
$criteria = new \Criteria('', ''); |
1106
|
|
|
$criteria->setSort('description'); |
1107
|
|
|
$criteria->setOrder('ASC'); |
1108
|
|
|
$statuses = $statusHandler->getObjects($criteria); |
1109
|
|
|
$aStatuses = []; |
1110
|
|
|
foreach ($statuses as $status) { |
1111
|
|
|
$aStatuses[$status->getVar('id')] = [ |
1112
|
|
|
'id' => $status->getVar('id'), |
1113
|
|
|
'desc' => $status->getVar('description'), |
1114
|
|
|
'state' => $status->getVar('state'), |
1115
|
|
|
]; |
1116
|
|
|
} |
1117
|
|
|
unset($statuses); |
1118
|
|
|
|
1119
|
|
|
$xoopsTpl->assign('xhelp_statuses', $aStatuses); |
1120
|
|
|
|
1121
|
|
|
$custFields = $ticketInfo->getCustFieldValues(); |
1122
|
|
|
$xoopsTpl->assign('xhelp_hasCustFields', !empty($custFields)); |
1123
|
|
|
$xoopsTpl->assign('xhelp_custFields', $custFields); |
1124
|
|
|
unset($custFields); |
1125
|
|
|
$xoopsTpl->assign('xhelp_uploadPath', XHELP_UPLOAD_PATH); |
1126
|
|
|
|
1127
|
|
|
require_once XOOPS_ROOT_PATH . '/footer.php'; |
1128
|
|
|
break; |
1129
|
|
|
case 'user': |
1130
|
|
|
// Check if user has permission to view ticket |
1131
|
|
|
/** @var \XoopsModules\Xhelp\TicketEmailsHandler $ticketEmailsHandler */ |
1132
|
|
|
$ticketEmailsHandler = $helper->getHandler('TicketEmails'); |
1133
|
|
|
$criteria = new \CriteriaCompo(new \Criteria('ticketid', $xhelp_id)); |
1134
|
|
|
$criteria->add(new \Criteria('uid', $xoopsUser->getVar('uid'))); |
1135
|
|
|
$ticketEmails = $ticketEmailsHandler->getObjects($criteria); |
1136
|
|
|
if (0 == count($ticketEmails)) { |
1137
|
|
|
$helper->redirect('index.php', 3, _XHELP_ERROR_INV_USER); |
1138
|
|
|
} |
1139
|
|
|
|
1140
|
|
|
$GLOBALS['xoopsOption']['template_main'] = 'xhelp_user_ticketDetails.tpl'; // Set template |
1141
|
|
|
require_once XOOPS_ROOT_PATH . '/header.php'; // Include |
1142
|
|
|
$responses = $ticketInfo->getResponses(); |
1143
|
|
|
foreach ($responses as $response) { |
1144
|
|
|
$hasFiles = false; |
1145
|
|
|
foreach ($aFiles as $file) { |
1146
|
|
|
if ($file['responseid'] == $response->getVar('id')) { |
1147
|
|
|
$hasFiles = true; |
1148
|
|
|
break; |
1149
|
|
|
} |
1150
|
|
|
} |
1151
|
|
|
|
1152
|
|
|
$staffReview = $staffReviewHandler->getReview($xhelp_id, $response->getVar('id'), $xoopsUser->getVar('uid')); |
1153
|
|
|
if (is_iterable($staffReview) && count($staffReview) > 0) { |
|
|
|
|
1154
|
|
|
$review = $staffReview[0]; |
1155
|
|
|
} |
1156
|
|
|
//$responseOwner = $memberHandler->getUser($response->getVar('uid')); |
1157
|
|
|
|
1158
|
|
|
$aResponses[] = [ |
1159
|
|
|
'id' => $response->getVar('id'), |
1160
|
|
|
'uid' => $response->getVar('uid'), |
1161
|
|
|
'uname' => '', |
1162
|
|
|
'ticketid' => $response->getVar('ticketid'), |
1163
|
|
|
'message' => $response->getVar('message'), |
1164
|
|
|
'timeSpent' => $response->getVar('timeSpent'), |
1165
|
|
|
'updateTime' => $response->posted('m'), |
1166
|
|
|
'userIP' => $response->getVar('userIP'), |
1167
|
|
|
'rating' => isset($review) ? Xhelp\Utility::getRating($review->getVar('rating')) : 0, |
1168
|
|
|
'user_sig' => '', |
1169
|
|
|
'private' => $response->getVar('private'), |
1170
|
|
|
'hasFiles' => $hasFiles, |
1171
|
|
|
'user_avatar' => XOOPS_URL . '/uploads/blank.gif', |
1172
|
|
|
]; |
1173
|
|
|
//XOOPS_URL .'/uploads/' .(($responseOwner)?$responseOwner->getVar('user_avatar') : 'blank.gif')); |
1174
|
|
|
|
1175
|
|
|
$all_users[$response->getVar('uid')] = ''; |
1176
|
|
|
} |
1177
|
|
|
|
1178
|
|
|
if (isset($review)) { |
1179
|
|
|
unset($review); |
1180
|
|
|
} |
1181
|
|
|
$staffArray = []; |
1182
|
|
|
$_staff = $staffHandler->getObjects(new \Criteria('uid', '(' . implode(',', array_keys($all_users)) . ')', 'IN'), true); |
1183
|
|
|
foreach ($_staff as $key => $_user) { |
1184
|
|
|
$staffArray[$key] = $_user->getVar('attachSig'); |
1185
|
|
|
} |
1186
|
|
|
unset($_staff); |
1187
|
|
|
|
1188
|
|
|
$users = []; |
1189
|
|
|
$_users = $memberHandler->getUsers(new \Criteria('uid', '(' . implode(',', array_keys($all_users)) . ')', 'IN'), true); |
1190
|
|
|
foreach ($_users as $key => $_user) { |
1191
|
|
|
$users[$key] = [ |
1192
|
|
|
'uname' => Xhelp\Utility::getUsername($_user, $helper->getConfig('xhelp_displayName')), |
1193
|
|
|
//Display signature if user is a staff member + has set signature to display |
1194
|
|
|
//or user with signature set to display |
1195
|
|
|
'user_sig' => (isset($staffArray[$key]) && $staffArray[$key]) |
1196
|
|
|
|| (!isset($staffArray[$key]) |
1197
|
|
|
&& $user->getVar('attachsig')) ? $_user->getVar('user_sig') : '', |
1198
|
|
|
'user_avatar' => mb_strlen($_user->getVar('user_avatar')) ? $_user->getVar('user_avatar') : 'blank.gif', |
1199
|
|
|
]; |
1200
|
|
|
} |
1201
|
|
|
unset($_users); |
1202
|
|
|
unset($_user); |
1203
|
|
|
unset($all_users); |
1204
|
|
|
|
1205
|
|
|
for ($i = 0, $iMax = count($aResponses); $i < $iMax; ++$i) { |
1206
|
|
|
$_response = $aResponses[$i]; |
1207
|
|
|
$_uid = $_response['uid']; |
1208
|
|
|
if (isset($users[$_uid])) { |
1209
|
|
|
$aResponses[$i]['user_sig'] = $users[$_uid]['user_sig']; |
1210
|
|
|
$aResponses[$i]['user_avatar'] = XOOPS_URL . '/uploads/' . $users[$_uid]['user_avatar']; |
1211
|
|
|
$aResponses[$i]['uname'] = $users[$_uid]['uname']; |
1212
|
|
|
} |
1213
|
|
|
} |
1214
|
|
|
unset($users); |
1215
|
|
|
|
1216
|
|
|
$has_responses = count($responses) > 0; |
1217
|
|
|
unset($responses); |
1218
|
|
|
|
1219
|
|
|
/** @var \XoopsModules\Xhelp\StatusHandler $statusHandler */ |
1220
|
|
|
$statusHandler = $helper->getHandler('Status'); |
1221
|
|
|
$myStatus = $statusHandler->get($ticketInfo->getVar('status')); |
1222
|
|
|
|
1223
|
|
|
// Smarty variables |
1224
|
|
|
$xoopsTpl->assign('xhelp_baseURL', XHELP_BASE_URL); |
1225
|
|
|
$reopenTicket = $helper->getConfig('xhelp_allowReopen') && 2 === $myStatus->getVar('state'); |
1226
|
|
|
$xoopsTpl->assign('xhelp_reopenTicket', $reopenTicket); |
1227
|
|
|
$xoopsTpl->assign('xhelp_allowResponse', (2 != $myStatus->getVar('state')) || $reopenTicket); |
1228
|
|
|
$xoopsTpl->assign('xhelp_imagePath', XHELP_IMAGE_URL . '/'); |
1229
|
|
|
$xoopsTpl->assign('xoops_module_header', $xhelp_module_header); |
1230
|
|
|
$xoopsTpl->assign('xhelp_ticketID', $xhelp_id); |
1231
|
|
|
$xoopsTpl->assign('xhelp_ticket_uid', $ticketInfo->getVar('uid')); |
1232
|
|
|
$xoopsTpl->assign('xhelp_ticket_subject', $ticketInfo->getVar('subject')); |
1233
|
|
|
$xoopsTpl->assign('xhelp_ticket_description', $ticketInfo->getVar('description')); |
1234
|
|
|
$xoopsTpl->assign('xhelp_ticket_department', $department->getVar('department')); |
1235
|
|
|
$xoopsTpl->assign('xhelp_ticket_priority', $ticketInfo->getVar('priority')); |
1236
|
|
|
$xoopsTpl->assign('xhelp_ticket_status', $myStatus->getVar('description')); // Xhelp\Utility::getStatus($ticketInfo->getVar('status'))); |
1237
|
|
|
$xoopsTpl->assign('xhelp_ticket_posted', $ticketInfo->posted('m')); |
1238
|
|
|
$xoopsTpl->assign('xhelp_ticket_lastUpdated', $ticketInfo->posted('m')); |
1239
|
|
|
$xoopsTpl->assign('xhelp_userinfo', XOOPS_URL . '/userinfo.php?uid=' . $ticketInfo->getVar('uid')); |
1240
|
|
|
$xoopsTpl->assign('xhelp_username', $user->getVar('uname')); |
1241
|
|
|
$xoopsTpl->assign('xhelp_email', $user->getVar('email')); |
1242
|
|
|
$xoopsTpl->assign('xhelp_priorities', [5, 4, 3, 2, 1]); |
1243
|
|
|
$xoopsTpl->assign('xhelp_priorities_desc', [ |
1244
|
|
|
5 => _XHELP_PRIORITY5, |
1245
|
|
|
4 => _XHELP_PRIORITY4, |
1246
|
|
|
3 => _XHELP_PRIORITY3, |
1247
|
|
|
2 => _XHELP_PRIORITY2, |
1248
|
|
|
1 => _XHELP_PRIORITY1, |
1249
|
|
|
]); |
1250
|
|
|
$xoopsTpl->assign('xhelp_uid', $xoopsUser->getVar('uid')); |
1251
|
|
|
if ($has_responses) { |
1252
|
|
|
$xoopsTpl->assign('xhelp_aResponses', $aResponses); |
1253
|
|
|
} |
1254
|
|
|
if ($has_files) { |
1255
|
|
|
$xoopsTpl->assign('xhelp_aFiles', $aFiles); |
1256
|
|
|
$xoopsTpl->assign('xhelp_hasTicketFiles', $has_ticketFiles); |
1257
|
|
|
} else { |
1258
|
|
|
$xoopsTpl->assign('xhelp_aFiles', false); |
1259
|
|
|
$xoopsTpl->assign('xhelp_hasTicketFiles', false); |
1260
|
|
|
} |
1261
|
|
|
$xoopsTpl->assign('xhelp_claimOwner', $xoopsUser->getVar('uid')); |
1262
|
|
|
$xoopsTpl->assign('xhelp_hasResponses', $has_responses); |
1263
|
|
|
$xoopsTpl->assign('xhelp_hasFiles', $has_files); |
1264
|
|
|
$xoopsTpl->assign('xhelp_filePath', XOOPS_URL . '/uploads/xhelp/'); |
1265
|
|
|
$xoopsTpl->assign('xoops_pagetitle', $xoopsModule->getVar('name') . ' - ' . $ticketInfo->getVar('subject')); |
1266
|
|
|
$xoopsTpl->assign('xhelp_ticket_details', sprintf(_XHELP_TEXT_TICKETDETAILS, $xhelp_id)); |
1267
|
|
|
|
1268
|
|
|
$custFields = $ticketInfo->getCustFieldValues(); |
1269
|
|
|
$xoopsTpl->assign('xhelp_hasCustFields', !empty($custFields)); |
1270
|
|
|
$xoopsTpl->assign('xhelp_custFields', $custFields); |
1271
|
|
|
$xoopsTpl->assign('xhelp_uploadPath', XHELP_UPLOAD_PATH); |
1272
|
|
|
$xoopsTpl->assign('xhelp_allowUpload', $helper->getConfig('xhelp_allowUpload')); |
1273
|
|
|
|
1274
|
|
|
require_once XOOPS_ROOT_PATH . '/footer.php'; |
1275
|
|
|
break; |
1276
|
|
|
case 'userResponse': |
1277
|
|
|
if (Request::hasVar('newResponse', 'POST')) { |
1278
|
|
|
// Check if user has permission to view ticket |
1279
|
|
|
/** @var \XoopsModules\Xhelp\TicketEmailsHandler $ticketEmailsHandler */ |
1280
|
|
|
$ticketEmailsHandler = $helper->getHandler('TicketEmails'); |
1281
|
|
|
$criteria = new \Criteria('ticketid', $xhelp_id); |
1282
|
|
|
$ticketEmails = $ticketEmailsHandler->getObjects($criteria); |
1283
|
|
|
$canChange = false; |
1284
|
|
|
foreach ($ticketEmails as $ticketEmail) { |
1285
|
|
|
if ($xoopsUser->getVar('uid') == $ticketEmail->getVar('uid')) { |
1286
|
|
|
$canChange = true; |
1287
|
|
|
break; |
1288
|
|
|
} |
1289
|
|
|
} |
1290
|
|
|
$errors = []; |
1291
|
|
|
/** @var \XoopsModules\Xhelp\StatusHandler $statusHandler */ |
1292
|
|
|
$statusHandler = $helper->getHandler('Status'); |
1293
|
|
|
if ($canChange) { |
1294
|
|
|
$oldStatus = $statusHandler->get($ticketInfo->getVar('status')); |
1295
|
|
|
if (2 == $oldStatus->getVar('state')) { //If the ticket is resolved |
1296
|
|
|
$ticketInfo->setVar('closedBy', 0); |
1297
|
|
|
$ticketInfo->setVar('status', 1); |
1298
|
|
|
$ticketInfo->setVar('overdueTime', $ticketInfo->getVar('posted') + ($helper->getConfig('xhelp_overdueTime') * 60 * 60)); |
1299
|
|
|
} elseif (Request::hasVar('closeTicket', 'POST') && 1 === (int)$_POST['closeTicket']) { // If the user closes the ticket |
1300
|
|
|
$ticketInfo->setVar('closedBy', $ticketInfo->getVar('uid')); |
1301
|
|
|
$ticketInfo->setVar('status', 2); // Todo: make moduleConfig for default resolved status? |
1302
|
|
|
} |
1303
|
|
|
$ticketInfo->setVar('lastUpdated', $ticketInfo->lastUpdated('m')); |
1304
|
|
|
|
1305
|
|
|
if ($ticketHandler->insert($ticketInfo, true)) { // Insert the ticket |
1306
|
|
|
$newStatus = $statusHandler->get($ticketInfo->getVar('status')); |
1307
|
|
|
|
1308
|
|
|
if (2 == $newStatus->getVar('state')) { |
1309
|
|
|
$eventService->trigger('close_ticket', [&$ticketInfo]); |
1310
|
|
|
} elseif ($oldStatus->getVar('id') != $newStatus->getVar('id') |
1311
|
|
|
&& 2 != $newStatus->getVar('state')) { |
1312
|
|
|
$eventService->trigger('update_status', [&$ticketInfo, &$oldStatus, &$newStatus]); |
1313
|
|
|
} |
1314
|
|
|
} |
1315
|
|
|
if ('' != \Xmf\Request::getString('userResponse', '', 'POST')) { // If the user does not add any text in the response |
1316
|
|
|
/** @var \XoopsModules\Xhelp\Response $newResponse */ |
1317
|
|
|
$newResponse = $responseHandler->create(); |
1318
|
|
|
$newResponse->setVar('uid', $xoopsUser->getVar('uid')); |
1319
|
|
|
$newResponse->setVar('ticketid', $xhelp_id); |
1320
|
|
|
$newResponse->setVar('message', \Xmf\Request::getString('userResponse', '', 'POST')); |
1321
|
|
|
// $newResponse->setVar('updateTime', $newResponse->posted('m')); |
1322
|
|
|
$newResponse->setVar('updateTime', time()); |
1323
|
|
|
$newResponse->setVar('userIP', getenv('REMOTE_ADDR')); |
1324
|
|
|
|
1325
|
|
|
if ($responseHandler->insert($newResponse)) { |
1326
|
|
|
$eventService->trigger('new_response', [&$ticketInfo, &$newResponse]); |
1327
|
|
|
$message = _XHELP_MESSAGE_USER_MOREINFO; |
1328
|
|
|
|
1329
|
|
|
if ($helper->getConfig('xhelp_allowUpload')) { // If uploading is allowed |
1330
|
|
|
if (is_uploaded_file(($_FILES['userfile']['tmp_name'])??'')) { |
1331
|
|
|
if (!$ret = $ticketInfo->checkUpload('userfile', $allowed_mimetypes, $errors)) { |
1332
|
|
|
$errorstxt = implode('<br>', $errors); |
1333
|
|
|
|
1334
|
|
|
$message = sprintf(_XHELP_MESSAGE_FILE_ERROR, $errorstxt); |
1335
|
|
|
$helper->redirect('addTicket.php', 5, $message); |
1336
|
|
|
} |
1337
|
|
|
$file = $ticketInfo->storeUpload('userfile', $newResponse->getVar('id'), $allowed_mimetypes); |
1338
|
|
|
} |
1339
|
|
|
} |
1340
|
|
|
} else { |
1341
|
|
|
$message = _XHELP_MESSAGE_USER_MOREINFO_ERROR; |
1342
|
|
|
} |
1343
|
|
|
} elseif (2 != $newStatus->getVar('state')) { |
1344
|
|
|
$message = _XHELP_MESSAGE_USER_NO_INFO; |
1345
|
|
|
} else { |
1346
|
|
|
$message = _XHELP_MESSAGE_UPDATE_STATUS; |
1347
|
|
|
} |
1348
|
|
|
} else { |
1349
|
|
|
$message = _XHELP_MESSAGE_NOT_USER; |
1350
|
|
|
} |
1351
|
|
|
redirect_header("ticket.php?id=$xhelp_id", 3, $message); |
1352
|
|
|
} |
1353
|
|
|
break; |
1354
|
|
|
case 'deleteFile': |
1355
|
|
|
if (!$hasRights = $staff->checkRoleRights(XHELP_SEC_FILE_DELETE, $ticketInfo->getVar('department'))) { |
1356
|
|
|
$message = _AM_XHELP_MESSAGE_NO_DELETE_FILE; |
1357
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id", 3, $message); |
1358
|
|
|
} |
1359
|
|
|
|
1360
|
|
|
if (!isset($_GET['fileid'])) { |
1361
|
|
|
$message = ''; |
1362
|
|
|
$helper->redirect("ticket.phpid=$xhelp_id", 3, $message); |
1363
|
|
|
} |
1364
|
|
|
|
1365
|
|
|
if (Request::hasVar('field', 'GET')) { // Remove filename from custom field |
1366
|
|
|
$field = $_GET['field']; |
1367
|
|
|
/** @var \XoopsModules\Xhelp\TicketValuesHandler $ticketValuesHandler */ |
1368
|
|
|
$ticketValuesHandler = $helper->getHandler('TicketValues'); |
1369
|
|
|
$ticketValues = $ticketValuesHandler->get($xhelp_id); |
1370
|
|
|
|
1371
|
|
|
$ticketValues->setVar($field, ''); |
1372
|
|
|
$ticketValuesHandler->insert($ticketValues, true); |
1373
|
|
|
} |
1374
|
|
|
|
1375
|
|
|
/** @var \XoopsModules\Xhelp\FileHandler $fileHandler */ |
1376
|
|
|
$fileHandler = $helper->getHandler('File'); |
1377
|
|
|
$fileid = Request::getInt('fileid', 0, 'GET'); |
1378
|
|
|
$file = $fileHandler->get($fileid); |
1379
|
|
|
|
1380
|
|
|
if (!$fileHandler->delete($file, true)) { |
1381
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id", 3, _XHELP_MESSAGE_DELETE_FILE_ERR); |
1382
|
|
|
} |
1383
|
|
|
$eventService->trigger('delete_file', [&$file]); |
1384
|
|
|
$helper->redirect("ticket.php?id=$xhelp_id"); |
1385
|
|
|
|
1386
|
|
|
break; |
1387
|
|
|
default: |
1388
|
|
|
$helper->redirect('index.php', 3); |
1389
|
|
|
break; |
1390
|
|
|
} |
1391
|
|
|
|
1392
|
|
|
/** |
1393
|
|
|
* @param Ticket $ticket |
1394
|
|
|
* @return array |
1395
|
|
|
*/ |
1396
|
|
|
function &getTicketFields(Ticket $ticket): array |
1397
|
|
|
{ |
1398
|
|
|
$helper = Xhelp\Helper::getInstance(); |
1399
|
|
|
$ret = []; |
1400
|
|
|
/** @var \XoopsModules\Xhelp\TicketFieldDepartmentHandler $ticketFieldDepartmentHandler */ |
1401
|
|
|
$ticketFieldDepartmentHandler = $helper->getHandler('TicketFieldDepartment'); |
1402
|
|
|
$fields = $ticketFieldDepartmentHandler->fieldsByDepartment($ticket->getVar('department')); |
1403
|
|
|
$values = $ticket->getCustFieldValues(true); |
1404
|
|
|
if (!empty($fields)) { |
1405
|
|
|
foreach ($fields as $field) { |
1406
|
|
|
$_arr = $field->toArray(); |
1407
|
|
|
$fieldname = $_arr['fieldname']; |
1408
|
|
|
$_arr['value'] = $values[$fieldname]['value']; |
1409
|
|
|
$_arr['fileid'] = $values[$fieldname]['fileid']; |
1410
|
|
|
$_arr['filename'] = $values[$fieldname]['filename']; |
1411
|
|
|
$ret[] = $_arr; |
1412
|
|
|
} |
1413
|
|
|
} |
1414
|
|
|
return $ret; |
1415
|
|
|
} |
1416
|
|
|
|