forked from pluginsGLPI/order
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook.php
373 lines (323 loc) · 14.4 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
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
<?php
/*
LICENSE
This file is part of the order plugin.
Order 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.
Order 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 GLPI; along with Order. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
@package order
@author the order plugin team
@copyright Copyright (c) 2010-2015 Order plugin team
@license GPLv2+
http://www.gnu.org/licenses/gpl.txt
@link https://forge.indepnet.net/projects/order
@link http://www.glpi-project.org/
@since 2009
---------------------------------------------------------------------- */
function plugin_order_install() {
foreach (glob(GLPI_ROOT . '/plugins/order/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", "order")."<th></tr>";
echo "<tr class='tab_bg_1'>";
echo "<td align='center'>";
$migration = new Migration("1.5.2");
$classes = array('PluginOrderConfig', 'PluginOrderBillState', 'PluginOrderBillType',
'PluginOrderOrderState', 'PluginOrderOrder','PluginOrderOrder_Item',
'PluginOrderReference', 'PluginOrderDeliveryState',
'PluginOrderNotificationTargetOrder',
'PluginOrderOrder_Supplier', 'PluginOrderBill', 'PluginOrderOrderPayment',
'PluginOrderOrderType', 'PluginOrderOther', 'PluginOrderOtherType',
'PluginOrderPreference', 'PluginOrderProfile', 'PluginOrderReference_Supplier',
'PluginOrderSurveySupplier', 'PluginOrderOrderTax', 'PluginOrderDocumentCategory');
foreach ($classes as $class) {
if ($plug=isPluginItemType($class)) {
$plugname=strtolower($plug['plugin']);
$dir=GLPI_ROOT . "/plugins/$plugname/inc/";
$item=strtolower($plug['class']);
if (file_exists("$dir$item.class.php")) {
include_once ("$dir$item.class.php");
call_user_func(array($class,'install'),$migration);
}
}
}
echo "</td>";
echo "</tr>";
echo "</table></center>";
return true;
}
function plugin_order_uninstall() {
foreach (glob(GLPI_ROOT . '/plugins/order/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 = array('PluginOrderConfig', 'PluginOrderBill', 'PluginOrderBillState',
'PluginOrderBillType', 'PluginOrderOrderState', 'PluginOrderOrder',
'PluginOrderOrder_Item', 'PluginOrderReference', 'PluginOrderDeliveryState',
'PluginOrderNotificationTargetOrder',
'PluginOrderOrder_Supplier', 'PluginOrderOrderPayment','PluginOrderOrderTax',
'PluginOrderOrderType', 'PluginOrderOther', 'PluginOrderOtherType',
'PluginOrderPreference', 'PluginOrderProfile', 'PluginOrderReference_Supplier',
'PluginOrderSurveySupplier', 'PluginOrderDocumentCategory');
foreach ($classes as $class) {
call_user_func(array($class,'uninstall'));
}
return true;
}
/* define dropdown tables to be manage in GLPI : */
function plugin_order_getDropdown() {
/* table => name */
$plugin = new Plugin();
if ($plugin->isActivated("order")) {
return array ('PluginOrderOrderTax' => __("VAT", "order"),
'PluginOrderOrderPayment' => __("Payment conditions", "order"),
'PluginOrderOrderType' => __("Type"),
'PluginOrderOrderState' => __("Order status", "order"),
'PluginOrderOtherType' => __("Other type of item", "order"),
'PluginOrderDeliveryState' => __("Delivery status", "order"),
'PluginOrderBillState' => __("Bill status", "order"),
'PluginOrderBillType' => __("Bill type", "order"),
'PluginOrderDocumentCategory' => __("Orders", "order"));
} else {
return array ();
}
}
/* define dropdown relations */
function plugin_order_getDatabaseRelations() {
$plugin = new Plugin();
if ($plugin->isActivated("order")) {
return array (
"glpi_plugin_order_orderpayments" => array (
"glpi_plugin_order_orders" => "plugin_order_orderpayments_id"),
"glpi_plugin_order_ordertaxes" => array (
"glpi_plugin_order_orders" => "plugin_order_ordertaxes_id"),
"glpi_plugin_order_ordertypes" => array (
"glpi_plugin_order_orders" => "plugin_order_ordertypes_id"),
"glpi_plugin_order_orderstates" => array (
"glpi_plugin_order_orders" => "plugin_order_orderstates_id"),
"glpi_plugin_order_deliverystates" => array (
"glpi_plugin_order_orders_items" => "plugin_order_deliverystates_id"),
"glpi_plugin_order_orders" => array (
"glpi_plugin_order_orders_items" => "plugin_order_orders_id",
"glpi_plugin_order_orders_suppliers" => "plugin_order_orders_id"),
"glpi_plugin_order_references" => array (
"glpi_plugin_order_orders_items" => "plugin_order_references_id",
"glpi_plugin_order_references_suppliers" => "plugin_order_references_id"),
"glpi_entities" => array ("glpi_plugin_order_orders" => "entities_id",
"glpi_plugin_order_references" => "entities_id",
"glpi_plugin_order_others" => "entities_id",
"glpi_plugin_order_bills" => "entities_id"),
"glpi_budgets" => array ("glpi_plugin_order_orders" => "budgets_id"),
"glpi_plugin_order_othertypes" => array ("glpi_plugin_order_others" => "othertypes_id"),
"glpi_suppliers" => array ("glpi_plugin_order_orders" => "suppliers_id",
"glpi_plugin_order_orders_suppliers" => "suppliers_id",
"glpi_plugin_order_references_suppliers" => "suppliers_id"),
"glpi_manufacturers" => array ("glpi_plugin_order_references" => "manufacturers_id"),
"glpi_contacts" => array ("glpi_plugin_order_orders" => "contacts_id"),
"glpi_locations" => array ("glpi_plugin_order_orders" => "locations_id"),
"glpi_profiles" => array ("glpi_plugin_order_profiles" => "profiles_id"));
} else {
return array ();
}
}
////// SEARCH FUNCTIONS ///////(){
// Define search option for types of the plugins
function plugin_order_getAddSearchOptions($itemtype) {
$plugin = new Plugin();
$sopt = array();
if ($plugin->isInstalled('order')
&& $plugin->isActivated('order')
&& Session::haveRight("plugin_order_order", READ)) {
if (in_array($itemtype, PluginOrderOrder_Item::getClasses(true))) {
$sopt[3160]['table'] = 'glpi_plugin_order_orders';
$sopt[3160]['field'] = 'name';
$sopt[3160]['linkfield'] = '';
$sopt[3160]['name'] = __("Order name", "order");
$sopt[3160]['forcegroupby'] = true;
$sopt[3160]['datatype'] = 'itemlink';
$sopt[3160]['itemlink_type'] = 'PluginOrderOrder';
$sopt[3161]['table'] = 'glpi_plugin_order_orders';
$sopt[3161]['field'] = 'num_order';
$sopt[3161]['linkfield'] = '';
$sopt[3161]['name'] = __("Order number", "order");
$sopt[3161]['forcegroupby'] = true;
$sopt[3161]['datatype'] = 'itemlink';
$sopt[3161]['itemlink_type'] = 'PluginOrderOrder';
}
}
return $sopt;
}
function plugin_order_addSelect($type, $ID, $num) {
$searchopt = &Search::getOptions($type);
$table = $searchopt[$ID]["table"];
$field = $searchopt[$ID]["field"];
if ($table == "glpi_plugin_order_references" && $num != 0) {
return "`$table`.`itemtype`, `$table`.`$field` AS `ITEM_$num`, ";
} else {
return "";
}
}
function plugin_order_addLeftJoin($type,$ref_table,$new_table,$linkfield,
&$already_link_tables) {
switch ($new_table){
case "glpi_plugin_order_orders" : // From items
$out = " LEFT JOIN `glpi_plugin_order_orders_items` " .
"ON (`$ref_table`.`id` = `glpi_plugin_order_orders_items`.`items_id` " .
"AND `glpi_plugin_order_orders_items`.`itemtype` = '$type') ";
$out.= " LEFT JOIN `glpi_plugin_order_orders` " .
"ON (`glpi_plugin_order_orders`.`id` = `glpi_plugin_order_orders_items`.`plugin_order_orders_id`) ";
return $out;
break;
case "glpi_budgets" : // From order list
$out = " LEFT JOIN `glpi_budgets` " .
"ON (`glpi_plugin_order_orders`.`budgets_id` = `glpi_budgets`.`id`) ";
return $out;
break;
case "glpi_contacts" : // From order list
$out = " LEFT JOIN `glpi_contacts` " .
"ON (`glpi_plugin_order_orders`.`contacts_id` = `glpi_contacts`.`id`) ";
return $out;
break;
}
return "";
}
function plugin_order_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) {
global $ORDER_TYPES;
$out = "";
if ($ID == 6) {
Toolbox::logDebug($link, $nott, $itemtype, $ID, $val, $searchtype, $out);
switch ($searchtype) {
case 'contains':
$comparison = "`name` " . Search::makeTextSearch($val, $nott);
}
$assetTypesType = array();
foreach ($ORDER_TYPES as $assetType) {
if ($itemtype == 'PluginOrderReference') {
$table = strtolower("glpi_" . $assetType::getType()."types");
if (TableExists($table)) {
$assetTypestype[] = "SELECT `id`
FROM `$table`
WHERE `itemtype`='$assetType'
AND `types_id`=`$table`.`id`
AND $comparison";
}
}
}
if (count($assetTypestype)) {
$out = "$link `types_id` IN (" . implode(" UNION ", $assetTypestype) . ")";
}
}
if ($ID == 3) {
$table = $itemtype::getTable();
if ($nott) {
$out = "$link `itemtype`<>'$val'";
} else {
$out = "$link `$table`.`itemtype`='$val'";
}
}
return $out;
}
/* display custom fields in the search */
function plugin_order_giveItem($type, $ID, $data, $num) {
global $CFG_GLPI;
$searchopt = &Search::getOptions($type);
$table = $searchopt[$ID]["table"];
$field = $searchopt[$ID]["field"];
$reference = new PluginOrderReference();
switch ($table . '.' . $field) {
/* display associated items with order */
case "glpi_plugin_order_references.types_id" :
if ($data['raw']["itemtype"] == 'PluginOrderOther') {
$file = GLPI_ROOT."/plugins/order/inc/othertype.class.php";
} else {
$file = GLPI_ROOT."/inc/".strtolower($data['raw']["itemtype"])."type.class.php";
}
if (file_exists($file)) {
return Dropdown::getDropdownName(getTableForItemType($data["itemtype"]."Type"),
$data['raw']["ITEM_" . $num]);
} else {
return " ";
}
break;
case "glpi_plugin_order_references.models_id" :
if (file_exists(GLPI_ROOT."/inc/".strtolower($data["itemtype"])."model.class.php")) {
return Dropdown::getDropdownName(getTableForItemType($data['raw']["itemtype"]."Model"),
$data['raw']["ITEM_" . $num]);
} else {
return " ";
}
break;
case "glpi_plugin_order_references.templates_id" :
if (!$data['raw']["ITEM_" . $num]) {
return " ";
} else {
return $reference->getTemplateName($data['raw']["itemtype"], $data['raw']["ITEM_" . $num]);
}
break;
}
return "";
}
function plugin_order_displayConfigItem($type, $ID, $data, $num) {
global $CFG_GLPI;
$searchopt = &Search::getOptions($type);
$table = $searchopt[$ID]["table"];
$field = $searchopt[$ID]["field"];
switch ($table . '.' . $field) {
case "glpi_plugin_order_orders.is_late":
$message = "";
if ($data['raw']["ITEM_" . $num]) {
$config = PluginOrderConfig::getConfig();
if ($config->getShouldBeDevileredColor() != '') {
$message.= " style=\"background-color:".$config->getShouldBeDevileredColor().";\" ";
}
}
return $message;
}
}
/* hook done on purge item case */
function plugin_item_purge_order($item) {
global $DB;
$query = "UPDATE `glpi_plugin_order_orders_items`
SET `items_id`='0'
WHERE `itemtype`='".$item->getType()."'
AND `items_id`='".$item->getField('id')."'";
$DB->query($query);
return true;
}
/**
* Get itemtypes to migration from GLPI 0.72 to GLPI 0.78+
*/
function plugin_order_migratetypes($types) {
$types[3150] = 'PluginOrderOrder';
$types[3151] = 'PluginOrderReference';
$types[3152] = 'PluginOrderReference_Supplier';
$types[3153] = 'PluginOrderBudget';
$types[3154] = 'PluginOrderReception';
return $types;
}
function plugin_datainjection_populate_order() {
global $INJECTABLE_TYPES;
$INJECTABLE_TYPES['PluginOrderOrderInjection'] = 'order';
$INJECTABLE_TYPES['PluginOrderReferenceInjection'] = 'order';
}
function plugin_order_AssignToTicket($types) {
if (Session::haveRight("plugin_order_order", PluginOrderOrder::RIGHT_OPENTICKET)) {
$types['PluginOrderOrder'] = __("Order", "order");
}
return $types;
}