-
Notifications
You must be signed in to change notification settings - Fork 3
/
hook.php
299 lines (262 loc) · 11.3 KB
/
hook.php
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
<?php
/*
* @version $Id: HEADER 15930 2011-10-30 15:47:55Z tsmr $
-------------------------------------------------------------------------
vip plugin for GLPI
Copyright (C) 2016-2022 by the vip Development Team.
https://github.com/InfotelGLPI/vip
-------------------------------------------------------------------------
LICENSE
This file is part of vip.
vip 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.
vip 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 vip. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
function plugin_vip_install() {
global $DB;
// Création de la table uniquement lors de la première installation
if (!$DB->tableExists("glpi_plugin_vip_groups")) {
$DB->runFile(PLUGIN_VIP_DIR. "/install/sql/empty-1.8.0.sql");
}
if ($DB->tableExists('glpi_plugin_vip_tickets')) {
$tables = ["glpi_plugin_vip_tickets"];
foreach ($tables as $table) {
$DB->dropTable($table);
}
}
if (!$DB->fieldExists("glpi_plugin_vip_groups","vip_color")) {
$DB->runFile(PLUGIN_VIP_DIR. "/install/sql/update-1.7.3.sql");
}
if (!$DB->fieldExists("glpi_plugin_vip_groups","vip_icon")) {
$DB->runFile(PLUGIN_VIP_DIR. "/install/sql/update-1.8.0.sql");
}
include_once(PLUGIN_VIP_DIR."/inc/profile.class.php");
PluginVipProfile::initProfile();
PluginVipProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
return true;
}
function plugin_vip_uninstall() {
global $DB;
$tables = ["glpi_plugin_vip_profiles",
"glpi_plugin_vip_groups",
"glpi_plugin_vip_tickets"];
foreach ($tables as $table)
$DB->dropTable($table);
$tables_glpi = ["glpi_displaypreferences",
"glpi_documents_items",
"glpi_savedsearches",
"glpi_logs",
"glpi_items_tickets",
"glpi_contracts_items",
"glpi_notepads",
"glpi_dropdowntranslations"];
foreach ($tables_glpi as $table_glpi) {
$DB->delete($table_glpi, ['itemtype' => ['LIKE' => 'PluginVip%']]);
}
//drop rules
$Rule = new Rule();
$a_rules = $Rule->find(['sub_type' => 'PluginVipRuleVip']);
foreach ($a_rules as $data) {
$Rule->delete($data);
}
//Delete rights associated with the plugin
$profileRight = new ProfileRight();
foreach (PluginVipProfile::getAllRights() as $right) {
$profileRight->deleteByCriteria(['name' => $right['field']]);
}
PluginVipProfile::removeRightsFromSession();
return true;
}
function plugin_vip_getPluginsDatabaseRelations() {
if (Plugin::isPluginActive("vip"))
return [
"glpi_groups" => ["glpi_plugin_vip_groups" => "id"]
];
else
return [];
}
function plugin_vip_getAddSearchOptions($itemtype) {
$sopt = [];
if (Session::getCurrentInterface() == 'central'
&& Session::haveRight('plugin_vip', READ)) {
switch ($itemtype) {
case 'Ticket':
case 'Computer':
case 'Printer':
$rng1 = 10100;
$sopt[$rng1]['table'] = 'glpi_plugin_vip_groups';
$sopt[$rng1]['field'] = 'isvip';
$sopt[$rng1]['name'] = 'Vip';
$sopt[$rng1]['datatype'] = 'bool';
$sopt[$rng1]['massiveaction'] = false;
break;
case 'Group':
$rng1 = 10150;
$sopt[$rng1]['table'] = 'glpi_plugin_vip_groups';
$sopt[$rng1]['field'] = 'isvip';
$sopt[$rng1]['linkfield'] = 'id';
$sopt[$rng1]['name'] = 'Vip';
$sopt[$rng1]['datatype'] = 'bool';
$sopt[$rng1]['massiveaction'] = false;
break;
}
}
return $sopt;
}
function plugin_vip_MassiveActions($type) {
if ($type == 'Group') {
$vip = new PluginVipGroup();
return $vip->massiveActions();
}
return [];
}
function plugin_vip_addLeftJoin($type, $ref_table, $new_table, $linkfield, &$already_link_tables) {
if ($ref_table == 'glpi_tickets') {
switch ($new_table) {
case "glpi_plugin_vip_groups" :
$out = " LEFT JOIN `glpi_tickets_users` ON (`glpi_tickets`.`id` = `glpi_tickets_users`.`tickets_id` AND `glpi_tickets_users`.`type` = " . CommonITILActor::REQUESTER . ") ";
$out .= " LEFT JOIN `glpi_groups_users` ON (`glpi_tickets_users`.`users_id` = `glpi_groups_users`.`users_id`)";
$out .= " LEFT JOIN `glpi_plugin_vip_groups` ON (`glpi_groups_users`.`groups_id` = `glpi_plugin_vip_groups`.`id`)";
return $out;
}
} else if ($ref_table == 'glpi_printers') {
switch ($new_table) {
case "glpi_plugin_vip_groups" :
// $out = " LEFT JOIN `glpi_users` `glpi_users_VIP` ON (`glpi_printers`.`users_id` = `glpi_users_VIP`.`id`) ";
$out = " LEFT JOIN `glpi_groups_users` ON (`glpi_printers`.`users_id` = `glpi_groups_users`.`users_id`)";
$out .= " LEFT JOIN `glpi_plugin_vip_groups` ON (`glpi_groups_users`.`groups_id` = `glpi_plugin_vip_groups`.`id`)";
return $out;
}
} else if ($ref_table == 'glpi_computers') {
switch ($new_table) {
case "glpi_plugin_vip_groups" :
// $out = " LEFT JOIN `glpi_users` `glpi_users_VIP` ON (`glpi_printers`.`users_id` = `glpi_users_VIP`.`id`) ";
$out = " LEFT JOIN `glpi_groups_users` ON (`glpi_computers`.`users_id` = `glpi_groups_users`.`users_id`)";
$out .= " LEFT JOIN `glpi_plugin_vip_groups` ON (`glpi_groups_users`.`groups_id` = `glpi_plugin_vip_groups`.`id`)";
return $out;
}
}
return "";
}
function plugin_vip_giveItem($type, $ID, $data, $num) {
global $CFG_GLPI, $DB;
$searchopt = &Search::getOptions($type);
$table = $searchopt[$ID]["table"];
$field = $searchopt[$ID]["field"];
switch ($type) {
case 'Ticket':
switch ($table . '.' . $field) {
case "glpi_plugin_vip_groups.isvip" :
if ($id = PluginVipTicket::isTicketVip($data["id"])) {
$name = PluginVipGroup::getVipName($id);
$color = PluginVipGroup::getVipColor($id);
$icon = PluginVipGroup::getVipIcon($id);
return "<i class='fas $icon fa-2x' title=\"$name\" style='font-family:\"Font Awesome 5 Free\", \"Font Awesome 5 Brands\";color:$color'></i><p style='display:none'>1</p>";
}
break;
}
break;
case 'Printer':
switch ($table . '.' . $field) {
case "glpi_plugin_vip_groups.isvip" :
if ($id = PluginVipTicket::isPrinterVip($data["id"])) {
$name = PluginVipGroup::getVipName($id);
$color = PluginVipGroup::getVipColor($id);
$icon = PluginVipGroup::getVipIcon($id);
return "<i class='fas $icon fa-2x' title=\"$name\" style='font-family:\"Font Awesome 5 Free\", \"Font Awesome 5 Brands\";color:$color'></i><p style='display:none'>1</p>";
}
break;
}
break;
case 'Computer':
switch ($table . '.' . $field) {
case "glpi_plugin_vip_groups.isvip" :
if ($id = PluginVipTicket::isComputerVip($data["id"])) {
$name = PluginVipGroup::getVipName($id);
$color = PluginVipGroup::getVipColor($id);
$icon = PluginVipGroup::getVipIcon($id);
return "<i class='fas $icon fa-2x' title=\"$name\" style='font-family:\"Font Awesome 5 Free\", \"Font Awesome 5 Brands\";color:$color'></i><p style='display:none'>1</p>";
}
break;
}
break;
case 'Group':
switch ($table . '.' . $field) {
case "glpi_plugin_vip_groups.isvip" :
if ($data[$num][0]['name']) {
$name = PluginVipGroup::getVipName($data["id"]);
$color = PluginVipGroup::getVipColor($data["id"]);
$icon = PluginVipGroup::getVipIcon($data["id"]);
return "<i class='fas $icon fa-2x' title=\"$name\" style='font-family:\"Font Awesome 5 Free\", \"Font Awesome 5 Brands\";color:$color'></i><p style='display:none'>1</p>";
}
break;
}
break;
}
return " ";
}
function plugin_vip_executeActions($options) {
$vip = new PluginVipRuleVip();
return $vip->executeActions($options['action'], $options['output'], $options['params']);
}
function plugin_vip_redefine_api_schemas(array $data): array {
if (!Session::haveRight('plugin_vip', READ)) {
return $data;
}
foreach ($data['schemas'] as &$schema) {
if (!isset($schema['x-itemtype'])) {
continue;
}
switch ($schema['x-itemtype']) {
case 'User':
$schema['properties']['vip_groups'] = [
'type' => \Glpi\Api\HL\Doc\Schema::TYPE_ARRAY,
'items' => [
'type' => \Glpi\Api\HL\Doc\Schema::TYPE_OBJECT,
'x-join' => [
// This is the join with the desired data
'table' => 'glpi_plugin_vip_groups',
'fkey' => 'groups_id',
'field' => 'id', // This table uses the group ID as the primary key "id"
'ref-join' => [
// This is the linking join between the main item and the data needed
'table' => 'glpi_groups_users',
'fkey' => 'id',
'field' => 'users_id',
]
],
'properties' => [
'id' => [
'type' => \Glpi\Api\HL\Doc\Schema::TYPE_INTEGER,
'x-readonly' => true,
],
'name' => [
'type' => \Glpi\Api\HL\Doc\Schema::TYPE_STRING,
'x-readonly' => true,
],
'color' => [
'type' => \Glpi\Api\HL\Doc\Schema::TYPE_STRING,
'x-readonly' => true,
'x-field' => 'vip_color'
],
'icon' => [
'type' => \Glpi\Api\HL\Doc\Schema::TYPE_STRING,
'x-readonly' => true,
'x-field' => 'vip_icon'
],
]
]
];
break;
}
}
return $data;
}