-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhook.php
230 lines (198 loc) · 8.37 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
<?php
/*
LICENSE
This file is part of the purchaserequest plugin.
Purchaserequest plugin 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.
Purchaserequest plugin 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 Purchaserequest. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
@package purchaserequest
@author the purchaserequest plugin team
@copyright Copyright (c) 2015-2022 Purchaserequest plugin team
@license GPLv2+
http://www.gnu.org/licenses/gpl.txt
@link https://github.com/InfotelGLPI/purchaserequest
@link http://www.glpi-project.org/
@since 2009
---------------------------------------------------------------------- */
/**
* Plugin install process
*
* @return boolean
*/
function plugin_purchaserequest_install() {
foreach (glob(PLUGIN_PURCHASEREQUEST_DIR . '/inc/*.php') as $file) {
//Do not load datainjection files (not needed and avoid missing class error message)
if (!preg_match('/injection.class.php/', $file)) {
include_once($file);
}
}
echo "<center>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr><th>" . __("Plugin installation or upgrade", "purchaserequest") . "<th></tr>";
echo "<tr class='tab_bg_1'>";
echo "<td align='center'>";
$migration = new Migration("3.0.2");
$classes = ['PluginPurchaserequestNotificationTargetPurchaseRequest',
'PluginPurchaserequestPurchaseRequest',
'PluginPurchaserequestConfig',
'PluginPurchaserequestThreshold',
'PluginPurchaserequestValidation',
'PluginPurchaserequestPurchaseRequestState'];
foreach ($classes as $class) {
if ($plug = isPluginItemType($class)) {
$plugname = strtolower($plug['plugin']);
$dir = PLUGIN_PURCHASEREQUEST_DIR . "/inc/";
$item = strtolower($plug['class']);
if (file_exists("$dir$item.class.php")) {
include_once("$dir$item.class.php");
call_user_func([$class, 'install'], $migration);
}
}
}
echo "</td>";
echo "</tr>";
echo "</table></center>";
PluginPurchaserequestProfile::initProfile();
PluginPurchaserequestProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
return true;
}
/**
* Plugin uninstall process
*
* @return boolean
*/
function plugin_purchaserequest_uninstall() {
foreach (glob(PLUGIN_PURCHASEREQUEST_DIR . '/inc/*.php') as $file) {
//Do not load datainjection files (not needed and avoid missing class error message)
if (!preg_match('/injection.class.php/', $file)) {
include_once($file);
}
}
$classes = ['PluginPurchaserequestNotificationTargetPurchaseRequest',
'PluginPurchaserequestPurchaseRequest',
'PluginPurchaserequestPurchaseRequestState',
'PluginPurchaserequestConfig',
'PluginPurchaserequestThreshold',
'PluginPurchaserequestValidation'];
foreach ($classes as $class) {
call_user_func([$class, 'uninstall']);
}
//Delete rights associated with the plugin
$profileRight = new ProfileRight();
foreach (PluginPurchaserequestProfile::getAllRights() as $right) {
$profileRight->deleteByCriteria(['name' => $right['field']]);
}
return true;
}
/* define dropdown tables to be manage in GLPI : */
function plugin_purchaserequest_getDropdown() {
/* table => name */
if (Plugin::isPluginActive("purchaserequest")) {
return ['PluginPurchaserequestPurchaseRequestState' => __("Purchase request status", "purchaserequest")];
} else {
return [];
}
}
/* define dropdown relations */
function plugin_purchaserequest_getDatabaseRelations() {
if (Plugin::isPluginActive("purchaserequest")) {
return ["glpi_entities" => ["glpi_plugin_purchaserequest_purchaserequests" => "entities_id"],
"glpi_profiles" => ["glpi_plugin_purchaserequest_profiles" => "profiles_id"],
"glpi_users" => ["glpi_plugin_purchaserequest_purchaserequests" => "users_id",
"glpi_plugin_purchaserequest_purchaserequests" => "users_id_validate",
"glpi_plugin_purchaserequest_purchaserequests" => "users_id_creator"],
"glpi_groups" => ["glpi_plugin_purchaserequest_purchaserequests" => "groups_id"],
"glpi_tickets" => ["glpi_plugin_purchaserequest_purchaserequests" => "tickets_id"],
"glpi_plugin_purchaserequest_purchaserequeststates" => [
"glpi_plugin_purchaserequest_purchaserequests" => "plugin_purchaserequest_purchaserequeststates_id"]];
} else {
return [];
}
}
function plugin_purchaserequest_addSelect($type, $ID, $num) {
$searchopt = &Search::getOptions($type);
$table = $searchopt[$ID]["table"];
$field = $searchopt[$ID]["field"];
if ($table == "glpi_plugin_purchaserequest_purchaserequests"
&& $field == "types_id") {
return "`$table`.`itemtype`, `$table`.`$field` AS `ITEM_$num`, ";
} else {
return "";
}
}
/* display custom fields in the search */
function plugin_purchaserequest_giveItem($type, $ID, $data, $num) {
$searchopt = &Search::getOptions($type);
$table = $searchopt[$ID]["table"];
$field = $searchopt[$ID]["field"];
$dbu = new DbUtils();
switch ($table . '.' . $field) {
/* display associated items with order */
case "glpi_plugin_purchaserequest_purchaserequests.types_id" :
$file = "";
if (isset($data['raw']["itemtype"]) && $data['raw']["itemtype"] == 'PluginOrderOther') {
$file = Plugin::getWebDir('order') . "/inc/othertype.class.php";
} elseif (isset($data['raw']["itemtype"])) {
$file = GLPI_ROOT . "/src/" . $data['raw']["itemtype"] . "Type.php";
}
if (file_exists($file)) {
return Dropdown::getDropdownName($dbu->getTableForItemType($data["itemtype"] . "Type"),
$data['raw']["ITEM_" . $num]);
} else {
return " ";
}
break;
case "glpi_plugin_purchaserequest_purchaserequests.plugin_order_orders_id" :
$order = new PluginOrderOrder();
if ($order->getFromDB($data['raw']["ITEM_" . $num])) {
return $order->getLink();
} else {
return " ";
}
break;
}
}
function plugin_purchaserequest_getAddSearchOptions($itemtype) {
$sopt = [];
if ($itemtype == 'Ticket') {
if (Session::haveRight('plugin_purchaserequest_purchaserequest', READ)) {
$sopt[22227]['table'] = 'glpi_plugin_purchaserequest_purchaserequests';
$sopt[22227]['field'] = 'id';
$sopt[22227]['name'] = _x('quantity', 'Number of purchase request', 'purchaserequest');
$sopt[22227]['forcegroupby'] = true;
$sopt[22227]['usehaving'] = true;
$sopt[22227]['datatype'] = 'count';
$sopt[22227]['massiveaction'] = false;
$sopt[22227]['joinparams'] = ['jointype' => 'child'];
}
}
return $sopt;
}
/**
* @param $type
* @param $ID
* @param $data
* @param $num
*
* @return string
*/
function plugin_purchaserequest_displayConfigItem($type, $ID, $data, $num) {
$searchopt =& Search::getOptions($type);
$table = $searchopt[$ID]["table"];
$field = $searchopt[$ID]["field"];
switch ($table . '.' . $field) {
case "glpi_plugin_purchaserequest_purchaserequests.status" :
$status_color = CommonITILValidation::getStatusColor($data[$num][0]['name']);
return " class=\"shadow-none\" style=\"background-color:" . $status_color . ";\" ";
break;
}
return "";
}