forked from pluginsGLPI/fields
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.php
252 lines (209 loc) · 8.71 KB
/
setup.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
<?php
/*
-------------------------------------------------------------------------
Fields plugin for GLPI
Copyright (C) 2016 by the Fields Development Team.
https://github.com/pluginsGLPI/fields
-------------------------------------------------------------------------
LICENSE
This file is part of Fields.
Fields 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.
Fields 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 Fields. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
define ('PLUGIN_FIELDS_VERSION', '1.6.1');
if (!defined("PLUGINFIELDS_DIR")) {
define("PLUGINFIELDS_DIR", GLPI_ROOT . "/plugins/fields");
}
if (!defined("PLUGINFIELDS_DOC_DIR")) {
define("PLUGINFIELDS_DOC_DIR", GLPI_PLUGIN_DOC_DIR . "/fields");
if (!file_exists(PLUGINFIELDS_DOC_DIR)) {
mkdir(PLUGINFIELDS_DOC_DIR);
}
}
if (!defined("PLUGINFIELDS_CLASS_PATH")) {
define("PLUGINFIELDS_CLASS_PATH", PLUGINFIELDS_DOC_DIR . "/inc");
if (!file_exists(PLUGINFIELDS_CLASS_PATH)) {
mkdir(PLUGINFIELDS_CLASS_PATH);
}
}
if (!defined("PLUGINFIELDS_FRONT_PATH")) {
define("PLUGINFIELDS_FRONT_PATH", PLUGINFIELDS_DOC_DIR."/front");
if (!file_exists(PLUGINFIELDS_FRONT_PATH)) {
mkdir(PLUGINFIELDS_FRONT_PATH);
}
}
/**
* Init hooks of the plugin.
* REQUIRED
*
* @return void
*/
function plugin_init_fields() {
global $PLUGIN_HOOKS;
$PLUGIN_HOOKS['csrf_compliant']['fields'] = true;
include_once(PLUGINFIELDS_DIR . "/vendor/autoload.php");
include_once(PLUGINFIELDS_DIR . "/inc/autoload.php");
$options = array(
PLUGINFIELDS_CLASS_PATH
);
$pluginfields_autoloader = new PluginFieldsAutoloader($options);
$pluginfields_autoloader->register();
$plugin = new Plugin();
if ($plugin->isInstalled('fields')
&& $plugin->isActivated('fields')
&& Session::getLoginUserID() ) {
// Init hook about itemtype(s) for plugin fields
$PLUGIN_HOOKS['plugin_fields'] = array();
// When a Category is changed during ticket creation
if (isset($_POST) && !empty($_POST) && isset($_POST['_plugin_fields_type'])) {
if ($_SERVER['REQUEST_URI'] == Ticket::getFormURL()) {
//$_SESSION['plugin_fields']['Ticket'] = $_POST;
foreach ($_POST as $key => $value) {
if (! is_array($value)) {
$_SESSION['plugin']['fields']['values_sent'][$key] = stripcslashes($value);
}
}
}
}
// complete rule engine
$PLUGIN_HOOKS['use_rules']['fields'] = array('PluginFusioninventoryTaskpostactionRule');
$PLUGIN_HOOKS['rule_matched']['fields'] = 'plugin_fields_rule_matched';
if (isset($_SESSION['glpiactiveentities'])) {
$PLUGIN_HOOKS['config_page']['fields'] = 'front/container.php';
// add entry to configuration menu
$PLUGIN_HOOKS["menu_toadd"]['fields'] = array('config' => 'PluginFieldsMenu');
// add tabs to itemtypes
Plugin::registerClass('PluginFieldsContainer',
array('addtabon' => array_unique(PluginFieldsContainer::getEntries())));
//include js and css
$debug = (isset($_SESSION['glpi_use_mode']) && $_SESSION['glpi_use_mode'] == Session::DEBUG_MODE ? true : false);
if (!$debug && file_exists(__DIR__ . '/css/fields.min.css')) {
$PLUGIN_HOOKS['add_css']['fields'][] = 'css/fields.min.css';
} else {
$PLUGIN_HOOKS['add_css']['fields'][] = 'css/fields.css';
}
// Add/delete profiles to automaticaly to container
$PLUGIN_HOOKS['item_add']['fields']['Profile'] = array("PluginFieldsProfile",
"addNewProfile");
$PLUGIN_HOOKS['pre_item_purge']['fields']['Profile'] = array("PluginFieldsProfile",
"deleteProfile");
//load drag and drop javascript library on Package Interface
$PLUGIN_HOOKS['add_javascript']['fields'][] = "js/redips-drag-min.js";
if (!$debug && file_exists(__DIR__ . '/js/drag-field-row.min.js')) {
$PLUGIN_HOOKS['add_javascript']['fields'][] = 'js/drag-field-row.min.js';
} else {
$PLUGIN_HOOKS['add_javascript']['fields'][] = 'js/drag-field-row.js';
}
}
// Add Fields to Datainjection
if ($plugin->isActivated('datainjection')) {
$PLUGIN_HOOKS['plugin_datainjection_populate']['fields'] = "plugin_datainjection_populate_fields";
}
//Retrieve dom container
$itemtypes = PluginFieldsContainer::getUsedItemtypes();
if ($itemtypes !== false) {
foreach ($itemtypes as $itemtype) {
$PLUGIN_HOOKS['pre_item_update']['fields'][$itemtype] = ["PluginFieldsContainer",
"preItemUpdate"];
$PLUGIN_HOOKS['pre_item_add']['fields'][$itemtype] = ["PluginFieldsContainer",
"preItem"];
$PLUGIN_HOOKS['item_add']['fields'][$itemtype] = ["PluginFieldsContainer",
"postItemAdd"];
$PLUGIN_HOOKS['pre_item_purge'] ['fields'][$itemtype] = ["PluginFieldsContainer",
"preItemPurge"];
}
}
$PLUGIN_HOOKS['post_item_form']['fields'] = ['PluginFieldsField',
'showForTab'];
// Check class and front files for existing containers and dropdown fields
plugin_fields_checkFiles();
}
}
/**
* Get the name and the version of the plugin
* REQUIRED
*
* @return array
*/
function plugin_version_fields() {
return array ('name' => __("Additionnal fields", "fields"),
'version' => PLUGIN_FIELDS_VERSION,
'author' => 'Teclib\', Olivier Moron',
'homepage' => 'teclib.com',
'license' => 'GPLv2+',
'minGlpiVersion' => '9.1.2');
}
/**
* Check pre-requisites before install
* OPTIONNAL, but recommanded
*
* @return boolean
*/
function plugin_fields_check_prerequisites() {
if (version_compare(GLPI_VERSION, '9.1.2', 'lt')) {
if (method_exists('Plugin', 'messageIncompatible')) {
echo Plugin::messageIncompatible('core', '9.1.2');
} else {
echo "This plugin requires GLPI 9.1.2";
}
return false;
}
return true;
}
function plugin_fields_checkFiles() {
$plugin = new Plugin();
if (isset($_SESSION['glpiactiveentities'])
&& $plugin->isInstalled('fields')
&& $plugin->isActivated('fields')
&& Session::getLoginUserID()) {
Plugin::registerClass('PluginFieldsContainer');
Plugin::registerClass('PluginFieldsDropdown');
Plugin::registerClass('PluginFieldsField');
if (TableExists("glpi_plugin_fields_containers")) {
$container_obj = new PluginFieldsContainer();
$containers = $container_obj->find();
foreach ($containers as $container) {
$itemtypes = (count($container['itemtypes']) > 0) ? json_decode($container['itemtypes'], TRUE) : array();
foreach ($itemtypes as $itemtype) {
$classname = "PluginFields".ucfirst($itemtype.
preg_replace('/s$/', '', $container['name']));
if (!class_exists($classname)) {
PluginFieldsContainer::generateTemplate($container);
}
}
}
}
if (TableExists("glpi_plugin_fields_fields")) {
$fields_obj = new PluginFieldsField();
$fields = $fields_obj->find("`type` = 'dropdown'");
foreach ($fields as $field) {
PluginFieldsDropdown::create($field);
}
}
}
}
/**
* Check configuration process
*
* @param boolean $verbose Whether to display message on failure. Defaults to false
*
* @return boolean
*/
function plugin_fields_check_config($verbose = false) {
if (true) { // Your configuration check
return true;
}
if ($verbose) {
echo __("Installed / not configured");
}
return false;
}