-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathdropdownReplaceFindDevice.php
More file actions
181 lines (153 loc) · 5.87 KB
/
dropdownReplaceFindDevice.php
File metadata and controls
181 lines (153 loc) · 5.87 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
<?php
/**
* -------------------------------------------------------------------------
* Uninstall plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Uninstall.
*
* Uninstall 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.
*
* Uninstall 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 Uninstall. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2015-2023 by Teclib'.
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/uninstall
* -------------------------------------------------------------------------
*/
use Glpi\Exception\Http\AccessDeniedHttpException;
use Glpi\Exception\Http\BadRequestHttpException;
use function Safe\json_encode;
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkRightsOr('uninstall:profile', [READ, PluginUninstallProfile::RIGHT_REPLACE]);
/**
* @var array $UNINSTALL_TYPES
* @var array $UNINSTALL_DIRECT_CONNECTIONS_TYPE
* @var array $CFG_GLPI
* @var DBmysql $DB
*/
global $UNINSTALL_TYPES, $UNINSTALL_DIRECT_CONNECTIONS_TYPE, $CFG_GLPI, $DB;
if (!in_array($_REQUEST['itemtype'], array_merge($UNINSTALL_TYPES, $UNINSTALL_DIRECT_CONNECTIONS_TYPE))) {
throw new AccessDeniedHttpException(__s("You don't have permission to perform this action."));
}
if (class_exists($_REQUEST['itemtype']) && is_a($_REQUEST['itemtype'], CommonDBTM::class, true)) {
$itemtypeisplugin = isPluginItemType($_REQUEST['itemtype']);
$item = new $_REQUEST['itemtype']();
$table = getTableForItemType($_REQUEST['itemtype']);
$options = [];
$count = 0;
$datastoadd = [];
$displaywith = false;
if (isset($_REQUEST['displaywith']) && (is_array($_REQUEST['displaywith']) && count($_REQUEST['displaywith']))) {
$displaywith = true;
}
$criteria = [
'FROM' => $table,
'WHERE' => [],
];
if ($item->isEntityAssign()) {
// allow opening ticket on recursive object (printer, software, ...)
$criteria['WHERE'] = getEntitiesRestrictCriteria($table, '', $_SESSION['glpiactiveentities'], $item->maybeRecursive());
}
if ($item->maybeDeleted()) {
$criteria['WHERE']['is_deleted'] = 0;
}
if ($item->maybeTemplate()) {
$criteria['WHERE']['is_template'] = 0;
}
if (
isset($_REQUEST['searchText'])
&& (string) $_REQUEST['searchText'] !== ''
&& $_REQUEST['searchText'] != $CFG_GLPI["ajax_wildcard"]
) {
// isset already makes sure the search value isn't null
$search_val = Search::makeTextSearchValue($_REQUEST['searchText']);
$criteria['WHERE'][] = [
'OR' => [
'name' => ['LIKE', $search_val],
'id' => ['LIKE', $search_val],
'serial' => ['LIKE', $search_val],
'otherserial' => ['LIKE', $search_val],
],
];
}
//If software or plugins : filter to display only the objects that are allowed to be visible in Helpdesk
if (in_array($_REQUEST['itemtype'], $CFG_GLPI["helpdesk_visible_types"])) {
$criteria['WHERE']['is_helpdesk_visible'] = 1;
}
if (isset($_REQUEST['used'])) {
$used = $_REQUEST['used'];
if (count($used) > 0) {
$criteria['WHERE'][] = [
'NOT' => [$table . '.id' => $used],
];
}
}
if (isset($_REQUEST['current_item']) && ($_REQUEST['current_item'] > 0)) {
$criteria['WHERE']['id'] = ['!=', $_REQUEST['current_item']];
}
$criteria['START'] = 0;
$criteria['LIMIT'] = $CFG_GLPI["dropdown_max"];
$criteria['ORDER'] = ['name'];
if (
isset($_REQUEST['searchText'])
&& $_REQUEST['searchText'] == $CFG_GLPI["ajax_wildcard"]
) {
unset($criteria['LIMIT']);
}
$it = $DB->request($criteria);
foreach ($it as $data) {
$outputval = $data["name"];
if ($displaywith) {
foreach ($_REQUEST['displaywith'] as $key) {
if (isset($data[$key])) {
$withoutput = $data[$key];
if (isForeignKeyField($key)) {
$withoutput = Dropdown::getDropdownName(
getTableNameForForeignKeyField($key),
$data[$key],
);
}
if (((string) $withoutput !== '') && ($withoutput != ' ')) {
$outputval = sprintf(__s('%1$s - %2$s'), $outputval, $withoutput);
}
}
}
}
$ID = $data['id'];
$addcomment = "";
$title = $outputval;
if (isset($data["comment"])) {
$addcomment .= $data["comment"];
$title = sprintf(__s('%1$s - %2$s'), $title, $addcomment);
}
if (
$_SESSION["glpiis_ids_visible"]
|| ((string) $outputval === '')
) {
$outputval = sprintf(__s('%1$s (%2$s)'), $outputval, $ID);
}
$options[] = ['id' => $ID,
'text' => $outputval,
'title' => $title,
];
$count++;
}
echo json_encode(['results' => $options,
'count' => $count,
]);
} else {
throw new BadRequestHttpException();
}