forked from InfotelGLPI/manufacturersimports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook.php
298 lines (262 loc) · 12.5 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
<?php
/**
* -------------------------------------------------------------------------
* Manufacturersimports plugin for GLPI
* Copyright (C) 2009-2022 by the Manufacturersimports Development Team.
*
* https://github.com/InfotelGLPI/manufacturersimports
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Manufacturersimports.
*
* Manufacturersimports 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.
*
* Manufacturersimports 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 Manufacturersimports. If not, see <http://www.gnu.org/licenses/>.
* --------------------------------------------------------------------------
*
* -------------------------------------------------------------------------
* Manufacturersimports plugin for GLPI
* Copyright (C) 2023 by the TICgal Team.
* https://www.tic.gal/
* -------------------------------------------------------------------------
* LICENSE
* This file is part of the Manufacturersimports plugin.
* Manufacturersimports 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 3 of the License, or
* (at your option) any later version.
* Manufacturersimports 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 Manufacturersimports. If not, see <http://www.gnu.org/licenses/>.
* --------------------------------------------------------------------------
* @package Manufacturersimports
* @author the TICgal team
* @copyright Copyright (c) 2023 TICgal team
* @license AGPL License 3.0 or (at your option) any later version
* http://www.gnu.org/licenses/agpl-3.0-standalone.html
* @link https://www.tic.gal/
* @since 2023
* ----------------------------------------------------------------------
*/
function plugin_manufacturersimports_install()
{
global $DB;
include_once(PLUGIN_MANUFACTURERSIMPORTS_DIR . "/inc/profile.class.php");
include_once(PLUGIN_MANUFACTURERSIMPORTS_DIR . "/inc/config.class.php");
$migration = new Migration("3.0.5");
$update = false;
//Root of SQL files for DB installation or upgrade
$sql_root = PLUGIN_MANUFACTURERSIMPORTS_DIR . "/sql/";
if (!$DB->tableExists("glpi_plugin_manufacturersimports_configs")) {
$DB->runFile($sql_root . "/empty-3.0.0.sql");
} elseif ($DB->tableExists("glpi_plugin_suppliertag_config")
&& !$DB->fieldExists("glpi_plugin_suppliertag_config", "FK_entities")) {
$update = true;
$DB->runFile($sql_root . "/update-1.1.sql");
$DB->runFile($sql_root . "/update-1.2.0.sql");
$DB->runFile($sql_root . "/update-1.3.0.sql");
$DB->runFile($sql_root . "/update-1.4.1.sql");
$DB->runFile($sql_root . "/update-1.5.0.sql");
$DB->runFile($sql_root . "/update-1.7.0.sql");
} elseif ($DB->tableExists("glpi_plugin_suppliertag_profiles")
&& $DB->fieldExists("glpi_plugin_suppliertag_profiles", "interface")) {
$update = true;
$DB->runFile($sql_root . "/update-1.2.0.sql");
$DB->runFile($sql_root . "/update-1.3.0.sql");
$DB->runFile($sql_root . "/update-1.4.1.sql");
$DB->runFile($sql_root . "/update-1.5.0.sql");
$DB->runFile($sql_root . "/update-1.7.0.sql");
} elseif (!$DB->tableExists("glpi_plugin_manufacturersimports_profiles")
&& !$DB->fieldExists("glpi_plugin_manufacturersimports_configs", "supplier_key")) {
$update = true;
$DB->runFile($sql_root . "/update-1.3.0.sql");
$DB->runFile($sql_root . "/update-1.4.1.sql");
$DB->runFile($sql_root . "/update-1.5.0.sql");
$DB->runFile($sql_root . "/update-1.7.0.sql");
} elseif (!$DB->fieldExists("glpi_plugin_manufacturersimports_configs", "supplier_key")) {
$DB->runFile($sql_root . "/update-1.7.0.sql");
} elseif (!$DB->fieldExists("glpi_plugin_manufacturersimports_configs", "supplier_secret")) {
$DB->runFile($sql_root . "/update-2.1.0.sql");
}
if (!$DB->fieldExists("glpi_plugin_manufacturersimports_configs", "warranty_url")) {
$DB->runFile($sql_root . "/update-2.1.3.sql");
}
$query = "UPDATE `glpi_plugin_manufacturersimports_configs`
SET `Supplier_url` = 'https://www.dell.com/support/home/product-support/servicetag/',
`warranty_url` ='https://apigtwb2c.us.dell.com/PROD/sbil/eapi/v5/asset-entitlements?servicetags=',
`token_url` = 'https://apigtwb2c.us.dell.com/auth/oauth/v2/token'
WHERE `name` ='" . PluginManufacturersimportsConfig::DELL . "'";
$DB->query($query);
$query = "UPDATE `glpi_plugin_manufacturersimports_configs`
SET `Supplier_url` = 'https://www.lenovo.com/us/en/warrantyApos?serialNumber='
WHERE `name` ='" . PluginManufacturersimportsConfig::LENOVO . "'";
$DB->query($query);
$query = "UPDATE `glpi_plugin_manufacturersimports_configs`
SET `Supplier_url` = 'http://support.ts.fujitsu.com/Warranty/WarrantyStatus.asp?lng=com&IDNR'
WHERE `name` ='" . PluginManufacturersimportsConfig::FUJITSU . "'";
$DB->query($query);
$query = "UPDATE `glpi_plugin_manufacturersimports_configs`
SET `Supplier_url` = 'https://www.wortmann.de/fr-fr/profile/snsearch.aspx?SN='
WHERE `name` ='" . PluginManufacturersimportsConfig::WORTMANN_AG . "'";
$DB->query($query);
$query = "UPDATE `glpi_plugin_manufacturersimports_configs`
SET `Supplier_url` = 'https://warrantyapiproxy.azurewebsites.net/api/HP?serial='
WHERE `name` ='" . PluginManufacturersimportsConfig::HP . "'";
$DB->query($query);
$cron = new CronTask;
if ($cron->getFromDBbyName('PluginManufacturersimportsDell', 'DataRecoveryDELL')) {
CronTask::Unregister('ManufacturersimportsDell');
}
$cron = new CronTask();
if (!$cron->getFromDBbyName('PluginManufacturersimportsImport', 'DataWarrantyImport')) {
CronTask::Register('PluginManufacturersimportsImport', 'DataWarrantyImport', WEEK_TIMESTAMP, ['state' => CronTask::STATE_DISABLE]);
}
if ($update) {
foreach ($DB->request('glpi_plugin_manufacturersimports_profiles') as $data) {
$query = "UPDATE `glpi_plugin_manufacturersimports_profiles`
SET `profiles_id` = '" . $data["id"] . "'
WHERE `id` = '" . $data["id"] . "';";
$DB->query($query);
}
$migration->dropField('glpi_plugin_manufacturersimports_profiles', 'name');
Plugin::migrateItemType(
[2150 => 'PluginManufacturersimportsModel',
2151 => 'PluginManufacturersimportsConfig'],
["glpi_savedsearches", "glpi_savedsearches_users", "glpi_displaypreferences",
"glpi_documents_items", "glpi_infocoms", "glpi_logs", "glpi_items_tickets"],
["glpi_plugin_manufacturersimports_models", "glpi_plugin_manufacturersimports_logs"]
);
}
//Migrate profiles to the system introduced in 0.85
PluginManufacturersimportsProfile::initProfile();
PluginManufacturersimportsProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);
//Drop old profile table : not used anymore
$migration->dropTable('glpi_plugin_manufacturersimports_profiles');
return true;
}
function plugin_manufacturersimports_uninstall()
{
include_once(PLUGIN_MANUFACTURERSIMPORTS_DIR . "/inc/profile.class.php");
include_once(PLUGIN_MANUFACTURERSIMPORTS_DIR . "/inc/menu.class.php");
$migration = new Migration("1.9.1");
$tables = ["glpi_plugin_manufacturersimports_configs",
"glpi_plugin_manufacturersimports_models",
"glpi_plugin_manufacturersimports_logs"];
foreach ($tables as $table) {
$migration->dropTable($table);
}
//old versions
$tables = ["glpi_plugin_suppliertag_config",
"glpi_plugin_suppliertag_profiles",
"glpi_plugin_suppliertag_models",
"glpi_plugin_suppliertag_imported"];
foreach ($tables as $table) {
$migration->dropTable($table);
}
$cron = new CronTask;
if ($cron->getFromDBbyName('PluginManufacturersimportsDell', 'DataRecoveryDELL')) {
CronTask::Unregister('ManufacturersimportsDell');
}
if ($cron->getFromDBbyName('PluginManufacturersimportsImport', 'DataWarrantyImport')) {
CronTask::Unregister('ManufacturersimportsImport');
}
$profileRight = new ProfileRight();
foreach (PluginManufacturersimportsProfile::getAllRights() as $right) {
$profileRight->deleteByCriteria(['name' => $right['field']]);
}
//Remove rigth from $_SESSION['glpiactiveprofile'] if exists
PluginManufacturersimportsProfile::removeRightsFromSession();
//Remove entries in GLPI's menu and breadcrumb
PluginManufacturersimportsMenu::removeRightsFromSession();
return true;
}
function plugin_manufacturersimports_postinit()
{
foreach (PluginManufacturersimportsConfig::getTypes(true) as $type) {
CommonGLPI::registerStandardTab($type, 'PluginManufacturersimportsConfig');
}
}
// Define dropdown relations
function plugin_manufacturersimports_getDatabaseRelations()
{
if (Plugin::isPluginActive("manufacturersimports")) {
return ["glpi_entities"
=> ["glpi_plugin_manufacturersimports_configs"
=> "entities_id"],
"glpi_manufacturers"
=> ["glpi_plugin_manufacturersimports_configs"
=> "manufacturers_id"],
"glpi_suppliers"
=> ["glpi_plugin_manufacturersimports_configs"
=> "suppliers_id"],
"glpi_documentcategories"
=> ["glpi_plugin_manufacturersimports_configs"
=> "documentcategories_id"],
"glpi_documents"
=> ["glpi_plugin_manufacturersimports_logs"
=> "documents_id"]
];
} else {
return [];
}
}
////// SEARCH FUNCTIONS ///////() {
function plugin_manufacturersimports_getAddSearchOptions($itemtype)
{
$sopt = [];
if (in_array($itemtype, PluginManufacturersimportsConfig::getTypes())) {
//TODO change right manufacturersimports READ
if (Session::haveRight('config', READ)) {
$sopt[2150]['table'] = 'glpi_plugin_manufacturersimports_models';
$sopt[2150]['field'] = 'model_name';
$sopt[2150]['linkfield'] = '';
$sopt[2150]['name'] = _n(
'Suppliers import',
'Suppliers imports',
2,
'manufacturersimports'
)
. " - " . __('Model number', 'manufacturersimports');
$sopt[2150]['forcegroupby'] = true;
$sopt[2150]['joinparams'] = ['jointype' => 'itemtype_item'];
$sopt[2150]['massiveaction'] = false;
}
}
return $sopt;
}
//force groupby for multible links to items
function plugin_manufacturersimports_forceGroupBy($type)
{
return true;
switch ($type) {
case 'PluginManufacturersimportsModel':
return true;
break;
}
return false;
}
////// SPECIFIC MODIF MASSIVE FUNCTIONS ///////
function plugin_manufacturersimports_MassiveActions($type)
{
if (Plugin::isPluginActive('manufacturersimports')) {
if (in_array($type, PluginManufacturersimportsConfig::getTypes(true))) {
return ['PluginManufacturersimportsModel' . MassiveAction::CLASS_ACTION_SEPARATOR . "add_model"
=> __('Add new material brand number', 'manufacturersimports')];
}
}
return [];
}