-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathhook.php
More file actions
444 lines (394 loc) · 18.6 KB
/
Copy pathhook.php
File metadata and controls
444 lines (394 loc) · 18.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
<?php
/**
* -------------------------------------------------------------------------
* moreticket plugin for GLPI
* Copyright (C) 2015-2026 by the moreticket Development Team.
*
* https://github.com/InfotelGLPI/moreticket
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of moreticket.
*
* moreticket is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* moreticket is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with moreticket. If not, see <http://www.gnu.org/licenses/>.
* --------------------------------------------------------------------------
*/
use GlpiPlugin\Moreticket\CloseTicket;
use GlpiPlugin\Moreticket\Config;
use GlpiPlugin\Moreticket\NotificationTicket;
use GlpiPlugin\Moreticket\Profile;
use GlpiPlugin\Moreticket\Solution;
use GlpiPlugin\Moreticket\UrgencyTicket;
use GlpiPlugin\Moreticket\WaitingTicket;
use GlpiPlugin\Moreticket\WaitingType;
/**
* @return bool
*/
function plugin_moreticket_install()
{
global $DB;
$update = true;
if (!$DB->tableExists("glpi_plugin_moreticket_configs")) {
// table sql creation
$DB->runFile(PLUGIN_MORETICKET_DIR . "/sql/empty-1.7.5.sql");
$update = false;
}
if (!$DB->fieldExists("glpi_plugin_moreticket_configs", "solution_status")) {
$DB->runFile(PLUGIN_MORETICKET_DIR . "/sql/update-1.1.1.sql");
}
if ($DB->fieldExists("glpi_plugin_moreticket_waitingtypes", "is_helpdeskvisible")) {
$DB->runFile(PLUGIN_MORETICKET_DIR . "/sql/update-1.1.2.sql");
}
if (!$DB->fieldExists("glpi_plugin_moreticket_closetickets", "documents_id")) {
$DB->runFile(PLUGIN_MORETICKET_DIR . "/sql/update-1.1.3.sql");
}
if (!$DB->fieldExists("glpi_plugin_moreticket_configs", "date_report_mandatory")) {
$DB->runFile(PLUGIN_MORETICKET_DIR . "/sql/update-1.2.0.sql");
}
if (!$DB->fieldExists("glpi_plugin_moreticket_configs", "close_followup")) {
$DB->runFile(PLUGIN_MORETICKET_DIR . "/sql/update-1.2.2.sql");
}
//version 1.2.3
if (!$DB->fieldExists("glpi_plugin_moreticket_configs", "waitingreason_mandatory")) {
$DB->runFile(PLUGIN_MORETICKET_DIR . "/sql/update-1.2.3.sql");
}
//version 1.2.4
if (!$DB->fieldExists("glpi_plugin_moreticket_configs", "urgency_justification")) {
$DB->runFile(PLUGIN_MORETICKET_DIR . "/sql/update-1.2.4.sql");
}
//version 1.2.5
if (!$DB->fieldExists("glpi_plugin_moreticket_waitingtickets", "status")) {
$DB->runFile(PLUGIN_MORETICKET_DIR . "/sql/update-1.2.5.sql");
}
//version 1.3.2
if (!$DB->fieldExists("glpi_plugin_moreticket_configs", "use_duration_solution")) {
$DB->runFile(PLUGIN_MORETICKET_DIR . "/sql/update-1.3.2.sql");
}
//version 1.3.4
if (!$DB->fieldExists("glpi_plugin_moreticket_configs", "is_mandatory_solution")) {
$DB->runFile(PLUGIN_MORETICKET_DIR . "/sql/update-1.3.4.sql");
}
if (!$DB->fieldExists("glpi_plugin_moreticket_configs", "use_question")) {
$DB->runFile(PLUGIN_MORETICKET_DIR . "/sql/update-1.5.1.sql");
}
if (!$DB->fieldExists("glpi_plugin_moreticket_configs", "add_save_button")) {
$DB->runFile(PLUGIN_MORETICKET_DIR . "/sql/update-1.6.2.sql");
}
if (!$DB->tableExists("glpi_plugin_moreticket_notificationtickets")) {
$DB->runFile(PLUGIN_MORETICKET_DIR . "/sql/update-1.6.3.sql");
}
if (!$DB->fieldExists("glpi_plugin_moreticket_configs", 'update_after_tech_add_task')) {
WaitingTicket::deleteDuplicates();
$DB->runFile(PLUGIN_MORETICKET_DIR . "/sql/update-1.7.5.sql");
}
if ($update) {
$DB->runFile(PLUGIN_MORETICKET_DIR . "/sql/update-1.7.0.sql");
}
$DB->runFile(PLUGIN_MORETICKET_DIR . "/sql/update-1.8.1.sql");
CronTask::Register('GlpiPlugin\Moreticket\WaitingTicket', 'MoreticketWaitingTicket', DAY_TIMESTAMP, ['state' => 1]);
Profile::initProfile();
Profile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
$migration = new Migration(PLUGIN_MORETICKET_VERSION);
$migration->dropTable('glpi_plugin_moreticket_profiles');
return true;
}
// Uninstall process for plugin : need to return true if succeeded
/**
* @return bool
*/
function plugin_moreticket_uninstall()
{
global $DB;
// Plugin tables deletion
$tables = [
"glpi_plugin_moreticket_configs",
"glpi_plugin_moreticket_waitingtickets",
"glpi_plugin_moreticket_waitingtypes",
"glpi_plugin_moreticket_closetickets",
"glpi_plugin_moreticket_urgencytickets",
"glpi_plugin_moreticket_notificationtickets",
];
//Delete rights associated with the plugin
$profileRight = new ProfileRight();
foreach (Profile::getAllRights() as $right) {
$profileRight->deleteByCriteria(['name' => $right['field']]);
}
// Search options and dropdown translations outlive the tables they describe, and
// dropTable() says nothing about either. A display preference keeps a now-unknown column
// in the ticket list of every user who added it, and a translation keeps naming a
// dropdown that no longer exists. Both are rows of core tables: only the plugin knows
// they belong to it, so only the plugin can remove them.
$displaypreference = new DisplayPreference();
$displaypreference->deleteByCriteria([
'itemtype' => Ticket::class,
// The ids the plugin declares in plugin_moreticket_getAddSearchOptions(), including
// the two it used to declare before they were commented out.
'num' => [3450, 3451, 3452, 3453, 3454, 3455, 3486, 3487],
]);
$dropdowntranslation = new DropdownTranslation();
$dropdowntranslation->deleteByCriteria(['itemtype' => WaitingType::class]);
// Documents attached to a closing record are deliberately left alone. They are attached
// to the ticket itself (front/closeticket.form.php pins itemtype to Ticket), the ticket
// outlives the plugin, and its owner still sees them in its Documents tab: removing them
// here would be destroying a user's attachment, not cleaning up after ourselves. Purging
// the ticket still takes them down, see plugin_pre_item_purge_moreticket().
foreach ($tables as $table) {
$DB->dropTable($table, true);
}
CronTask::Unregister('Moreticket');
return true;
}
// Hook done on purge item case
/**
* @param $item
*/
function plugin_pre_item_purge_moreticket($item)
{
switch (get_class($item)) {
case 'Ticket':
$tickets_id = (int) $item->getField('id');
// A closing record owns a document of its own. Dropping the row alone would leave
// that document behind in Management > Documents, still readable, with nothing
// left to say what it was attached to.
$closeTicket = new CloseTicket();
foreach ($closeTicket->find(['tickets_id' => $tickets_id]) as $closure) {
$documents_id = (int) $closure['documents_id'];
if ($documents_id <= 0) {
continue;
}
// Purge only what this closure brought in: the same document may have been
// attached to another item, and that other owner still needs it.
$document_item = new Document_Item();
$other_owners = $document_item->find([
'documents_id' => $documents_id,
'NOT' => [
'itemtype' => Ticket::class,
'items_id' => $tickets_id,
],
]);
$document = new Document();
if (count($other_owners) === 0 && $document->getFromDB($documents_id)) {
$document->delete(['id' => $documents_id], true);
}
}
// None of these tables carries is_deleted, so delete() really removes the row.
foreach ([$closeTicket, new WaitingTicket(), new UrgencyTicket(), new NotificationTicket()] as $child) {
$child->deleteByCriteria(['tickets_id' => $tickets_id]);
}
break;
}
}
////// SEARCH FUNCTIONS ///////() {
// Define search option for types of the plugins
/**
* @param $itemtype
*
* @return array
*/
function plugin_moreticket_getAddSearchOptions($itemtype)
{
$sopt = [];
if ($itemtype == "Ticket") {
if (Session::haveRight("plugin_moreticket", READ)) {
$config = new Config();
// $sopt[3450]['table'] = 'glpi_plugin_moreticket_waitingtickets';
// $sopt[3450]['field'] = 'reason';
// $sopt[3450]['name'] = __('Reason', 'moreticket');
// $sopt[3450]['datatype'] = "text";
// $sopt[3450]['joinparams'] = ['jointype' => 'child',
// 'condition' => "AND `NEWTABLE`.`date_end_suspension` IS NULL"];
// $sopt[3450]['massiveaction'] = false;
//
// $sopt[3451]['table'] = 'glpi_plugin_moreticket_waitingtickets';
// $sopt[3451]['field'] = 'date_report';
// $sopt[3451]['name'] = __('Postponement date', 'moreticket');
// $sopt[3451]['datatype'] = "datetime";
// $sopt[3451]['joinparams'] = ['jointype' => 'child',
// 'condition' => "AND `NEWTABLE`.`date_end_suspension` IS NULL"];
// $sopt[3451]['massiveaction'] = false;
//
//Used by Mydashboard
$sopt[3452]['table'] = 'glpi_plugin_moreticket_waitingtypes';
$sopt[3452]['field'] = 'name';
$sopt[3452]['name'] = WaitingType::getTypeName(1);
$sopt[3452]['datatype'] = "dropdown";
$condition = "AND (`NEWTABLE`.`date_end_suspension` IS NULL)";
$sopt[3452]['joinparams'] = ['beforejoin'
=> ['table' => 'glpi_plugin_moreticket_waitingtickets',
'joinparams' => ['jointype' => 'child',
'condition' => $condition]]];
// $sopt[3452]['massiveaction'] = false;
if ($config->closeInformations()) {
$sopt[3453]['table'] = 'glpi_plugin_moreticket_closetickets';
$sopt[3453]['field'] = 'date';
$sopt[3453]['name'] = __('Close ticket informations', 'moreticket') . " : " . __('Date');
$sopt[3453]['datatype'] = "datetime";
$sopt[3453]['joinparams'] = ['jointype' => 'child'];
$sopt[3453]['massiveaction'] = false;
$sopt[3454]['table'] = 'glpi_plugin_moreticket_closetickets';
$sopt[3454]['field'] = 'comment';
$sopt[3454]['name'] = __('Close ticket informations', 'moreticket') . " : " . __('Comments');
$sopt[3454]['datatype'] = "text";
$sopt[3454]['joinparams'] = ['jointype' => 'child'];
$sopt[3454]['massiveaction'] = false;
$sopt[3455]['table'] = 'glpi_plugin_moreticket_closetickets';
$sopt[3455]['field'] = 'requesters_id';
$sopt[3455]['name'] = __('Close ticket informations', 'moreticket') . " : " . __('Writer');
$sopt[3455]['datatype'] = "dropdown";
$sopt[3455]['joinparams'] = ['jointype' => 'child'];
$sopt[3455]['massiveaction'] = false;
$sopt[3486]['table'] = 'glpi_documents';
$sopt[3486]['field'] = 'name';
$sopt[3486]['name'] = __('Close ticket informations', 'moreticket') . " : " . _n(
'Document',
'Documents',
Session::getPluralNumber(),
);
$sopt[3486]['forcegroupby'] = true;
$sopt[3486]['usehaving'] = true;
$sopt[3486]['datatype'] = 'dropdown';
$sopt[3486]['massiveaction'] = false;
$sopt[3486]['joinparams'] = [
'beforejoin' => [
'table' => 'glpi_documents_items',
'joinparams' => [
'jointype' => 'itemtype_item',
'specific_itemtype' => CloseTicket::class,
'beforejoin' => [
'table' => 'glpi_plugin_moreticket_closetickets',
'joinparams' => [],
],
],
],
];
}
$sopt[3487]['table'] = 'glpi_plugin_moreticket_notificationtickets';
$sopt[3487]['field'] = 'users_id_lastupdater';
$sopt[3487]['name'] = __('Updated by a user', 'moreticket');
$sopt[3487]['massiveaction'] = false;
$sopt[3487]['datatype'] = 'specific';
$sopt[3487]['joinparams'] = ['jointype' => 'child'];
$sopt[3487]['additionalfields'] = ['tickets_id'];
}
}
return $sopt;
}
function plugin_moreticket_pre_item_form($params)
{
$item = $params['item'] ?? null;
if ($item === null) {
return;
}
$config = new Config();
switch ($item->getType()) {
case 'ITILSolution':
if ($config->isMandatorysolution() == true) {
\Glpi\Application\View\TemplateRenderer::getInstance()->display(
'@moreticket/solution_mandatory_warning.html.twig',
);
}
break;
}
}
function plugin_moreticket_post_item_form($params)
{
global $DB;
$item = $params['item'];
$config = new Config();
$waitingTicket = new WaitingTicket();
switch ($item->getType()) {
case 'ITILSolution':
if ($config->useDurationSolution() == true) {
Solution::showFormSolution($params);
if ($config->isMandatorysolution()) {
if (isset($params['item'])) {
$item = $params['item'];
if ($item->getType() == 'ITILSolution') {
echo Html::scriptBlock(
"$(document).ready(function(){
$('.itilsolution').children().find(':submit').hide();
});",
);
}
}
}
}
break;
case 'TicketTask':
// block with plugin's waiting reason + postponement date
if ($config->useWaiting() && WaitingTicket::canView()) {
$waitingTicket->addFormWaitingBlock($item->fields['tickets_id'], $item->getType());
}
// automatically click task's set ticket to waiting status switch
if (($config->fields['waiting_by_default_task'] ?? 0) && Session::haveRight('ticket', \Ticket::OWN)) {
// current() returns null on an empty result set, and the chained offset on
// that null read a warning instead of a layout. Keep the row, then the value.
$user_row = $DB->request([
'SELECT' => 'timeline_action_btn_layout',
'FROM' => 'glpi_users',
'WHERE' => [
'id' => Session::getLoginUserID(),
],
])->current();
$actionButtonLayout = $user_row['timeline_action_btn_layout'] ?? null;
if ($actionButtonLayout === null) {
$config_row = $DB->request([
'SELECT' => 'value',
'FROM' => 'glpi_configs',
'WHERE' => [
'name' => 'timeline_action_btn_layout',
],
])->current();
$actionButtonLayout = $config_row['value'] ?? 0;
}
$element = 'a';
if ($actionButtonLayout == 1) {
$element = 'button';
}
echo Html::scriptBlock(
"$(document).ready(function() {
let buttonTask = document.getElementById('itil-footer').querySelector('" . $element . "[data-bs-target=\"#new-TicketTask-block\"]');
buttonTask.addEventListener('click', (e) => {
let inputs = document.getElementById('new-itilobject-form').querySelectorAll('[id^=\"enable-pending-reasons\"]');
if (!inputs[1].checked) inputs[1].click();
})
})",
);
}
break;
case 'ITILFollowup':
if ($item->fields['itemtype'] == 'Ticket') {
// block with plugin's waiting reason + postponement date
if ($config->useWaiting() && WaitingTicket::canView()) {
$waitingTicket->addFormWaitingBlock($item->fields['items_id'], $item->getType());
}
// automatically click follow up set ticket to waiting status switch
if (strpos($_SERVER['REQUEST_URI'] ?? '', "ticket.form.php") !== false) {
if (($config->fields['waiting_by_default_followup'] ?? 0) && Session::haveRight('ticket', \Ticket::OWN)) {
echo Html::scriptBlock(
"$(document).ready(function() {
let buttonFollowup = document.getElementById('itil-footer').querySelector(\"button[data-bs-target='#new-ITILFollowup-block']\");
buttonFollowup.addEventListener('click', e => {
let input = document.getElementById('new-itilobject-form').querySelector('[id^=\"enable-pending-reasons\"]');
if (!input.checked) input.click();
})
});",
);
}
}
}
break;
}
}