-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathhistory.class.php
More file actions
316 lines (271 loc) · 11.1 KB
/
history.class.php
File metadata and controls
316 lines (271 loc) · 11.1 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
<?php
/**
* -------------------------------------------------------------------------
* Escalade plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Escalade.
*
* Escalade 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 2 of the License, or
* (at your option) any later version.
*
* Escalade 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 Escalade. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2015-2023 by Escalade plugin team.
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/escalade
* -------------------------------------------------------------------------
*/
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file");
}
class PluginEscaladeHistory extends CommonDBTM {
const HISTORY_LIMIT = 4;
static function getFirstLineForTicket($tickets_id) {
$found = self::getFullHistory($tickets_id);
if (count($found) == 0) {
return false;
} else {
return array_pop($found);
}
}
static function getlastLineForTicket($tickets_id) {
$found = self::getFullHistory($tickets_id);
if (count($found) == 0) {
return false;
} else {
return array_shift($found);
}
}
static function getLastHistoryForTicketAndGroup($tickets_id, $groups_id, $previous_groups_id) {
$history = new self();
$history->getFromDBByRequest(['ORDER' => 'date_mod DESC',
'LIMIT' => 1,
'WHERE' =>
[
'tickets_id' => $tickets_id,
'groups_id' => [$groups_id, $previous_groups_id],
'groups_id_previous' => [$groups_id, $previous_groups_id]
]
]);
return $history;
}
static function getFullHistory($tickets_id) {
$history = new self();
return $history->find(['tickets_id' => $tickets_id], "date_mod DESC");
}
static function getHistory($tickets_id, $full_history = false) {
global $CFG_GLPI;
$filter_groups_id = [];
if ($_SESSION['plugins']['escalade']['config']['use_filter_assign_group']) {
$groups_groups = new PluginEscaladeGroup_Group();
$filter_groups_id = $groups_groups->getGroups($tickets_id);
$use_filter_assign_group = true;
} else {
$use_filter_assign_group = false;
}
$plugin_dir = ($full_history) ? ".." : Plugin::getWebDir('escalade');
//get all line for this ticket
$group = new Group();
$history = new self();
$found = $history->find(['tickets_id' => $tickets_id], "date_mod DESC");
$nb_histories = count($found);
//remove first line (current assign)
$first_group = array_shift($found);
if ($full_history) {
//show 1st group
echo "<div class='escalade_active'>";
echo " <i class='fas fa-users></i>' ";
if ($group->getFromDB($first_group['groups_id'])) {
echo $group->getLink(true);
}
echo "</div>";
}
echo "<div class='escalade'>";
//parse all lines
$i = 0;
foreach ($found as $key => $hline) {
echo "<div class='escalade_history'>";
if (! $use_filter_assign_group || isset($filter_groups_id[$hline['groups_id']])) {
//up link and image
echo "<a href='$plugin_dir/front/climb_group.php?tickets_id="
.$tickets_id."&groups_id=".$hline['groups_id'];
if ($full_history) {
echo "&full_history=true";
}
echo "' title='".__("Reassign the ticket to group", "escalade")."' class='btn btn-icon btn-sm btn-ghost-secondary'><i class='ti ti-arrow-up'></i></a>";
} else {
echo " ";
}
//group link
echo " <i class='ti ti-users'></i> ";
if ($group->getFromDB($hline['groups_id'])) {
echo self::showGroupLink($group, $full_history);
}
echo "</div>";
$i++;
if ($i == self::HISTORY_LIMIT && !$full_history) {
break;
}
}
//In case there are more than 10 group changes, a popup can display historical
if ($nb_histories-1 > self::HISTORY_LIMIT && ! $full_history) {
echo "<a href='#' onclick='var w=window.open(\""
.$plugin_dir."/front/popup_histories.php?tickets_id=".$tickets_id
."\" ,\"\", \"height=500, width=250, top=100, left=100, scrollbars=yes\" ); "
."w.focus();' title='".__("View full history", "escalade")."'>...</a>";
}
echo "</div>";
}
static function showGroupLink($group, $full_history = false) {
if (!$group->can($group->fields['id'], READ)) {
return $group->getNameID(true);
}
$link_item = $group->getFormURL();
$link = $link_item;
$link .= (strpos($link, '?') ? '&':'?').'id=' . $group->fields['id'];
$link .= ($group->isTemplate() ? "&withtemplate=1" : "");
echo "<a href='$link'";
if ($full_history) {
echo " onclick='self.opener.location.href=\"$link\"; self.close();'";
}
echo ">" . $group->getNameID(true) . "</a>";
}
static function showCentralList() {
self::showCentralSpecificList("solved");
self::showCentralSpecificList("notold");
}
static function showCentralSpecificList($type) {
global $CFG_GLPI, $DB;
if (! Session::haveRight("ticket", Ticket::READALL)
&& ! Session::haveRight("ticket", Ticket::READASSIGN)
&& ! Session::haveRight("ticket", CREATE)
&& ! Session::haveRight("ticketvalidation", TicketValidation::VALIDATEREQUEST
& TicketValidation::VALIDATEINCIDENT)) {
return false;
}
$criteria = [
'SELECT' => ['glpi_tickets.id'],
'DISTINCT' => true,
'FROM' => 'glpi_tickets',
'LEFT JOIN' => [
'glpi_tickets_users' => [
'ON' => [
'glpi_tickets' => 'id',
'glpi_tickets_users' => 'tickets_id'
]
]
],
'WHERE' => [
'glpi_tickets.is_deleted' => 0,
],
'ORDER' => ['glpi_tickets.date_mod DESC']
];
if ($type == "notold") {
$title = __("Tickets to follow (escalated)", "escalade");
$status = CommonITILObject::INCOMING.", ".CommonITILObject::PLANNED.", ".
CommonITILObject::ASSIGNED.", ".CommonITILObject::WAITING;
$criteria['WHERE']['glpi_plugin_escalade_histories.groups_id'] = $_SESSION['glpigroups'];
$criteria['WHERE'][] = [
'OR' => [
'NOT' => ['glpi_groups_tickets.groups_id' => $_SESSION['glpigroups']],
'glpi_groups_tickets.groups_id' => null
]
];
$criteria['LEFT JOIN']['glpi_plugin_escalade_histories'] = [
'ON' => [
'glpi_tickets' => 'id',
'glpi_plugin_escalade_histories' => 'tickets_id'
]
];
} else {
$title = __("Tickets to close (escalated)", "escalade");
$status = CommonITILObject::SOLVED;
$criteria['WHERE']['glpi_groups_tickets.groups_id'] = $_SESSION['glpigroups'];
}
$criteria['LEFT JOIN']['glpi_groups_tickets'] = [
'ON' => [
'glpi_tickets' => 'id',
'glpi_groups_tickets' => 'tickets_id',
[
'AND' => ['glpi_groups_tickets.type' => 2]
]
]
];
$criteria['WHERE']['status'] = $status;
$criteria['WHERE'][] = getEntitiesRestrictCriteria('glpi_tickets');
$result = $DB->request($criteria);
$numrows = count($result);
if (!$numrows) {
return;
}
$criteria['START'] = 0;
$criteria['LIMIT'] = 5;
$result = $DB->request($criteria);
$number = count($result);
//show central list
if ($numrows > 0) {
//construct link to ticket list
$options['reset'] = 'reset';
$options['criteria'][0]['field'] = 12; // status
$options['criteria'][0]['searchtype'] = 'equals';
if ($type == 'notold') {
$options['criteria'][0]['value'] = 'notold';
} else if ($type == 'solved') {
$options['criteria'][0]['value'] = 5;
}
$options['criteria'][0]['link'] = 'AND';
if ($type == 'notold') {
$options['criteria'][1]['field'] = 1881; // groups_id_assign for escalade history
$options['criteria'][1]['searchtype'] = 'equals';
$options['criteria'][1]['value'] = 'mygroups';
$options['criteria'][1]['link'] = 'AND';
}
$options['criteria'][2]['field'] = 8; // groups_id_assign
if ($type == 'notold') {
$options['criteria'][2]['searchtype'] = 'notequals';
} else {
$options['criteria'][2]['searchtype'] = 'equals';
}
$options['criteria'][2]['value'] = 'mygroups';
$options['criteria'][2]['link'] = 'AND';
echo "<div class='grid-item col-xl-6 escalade-appended'><div class='card'>";
echo "<div class='card-body p-0'>";
echo "<div class='lazy-widget' data-itemtype='Ticket' data-widget='central_list'>";
echo "<div class='table-responsive card-table'>";
echo "<table class='table table-borderless table-striped table-hover card-table'>";
echo "<thead>";
echo "<tr><th colspan='4'>";
echo "<a href=\"".$CFG_GLPI["root_doc"]."/front/ticket.php?".
Toolbox::append_params($options, '&')."\">".
Html::makeTitle($title, $number, $numrows)."</a>";
echo "</th></tr>";
if ($number) {
echo "<tr>";
echo "<th></th>";
echo "<th>".__('Requester')."</th>";
echo "<th>".__('Associated element')."</th>";
echo "<th>".__('Description')."</th></tr></thead>";
foreach ($result as $data) {
Ticket::showVeryShort($data['id'], 'Ticket$2');
}
}
echo "</table>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
}
}
}