forked from pluginsGLPI/genericobject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.php
267 lines (225 loc) · 8.51 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<?php
/*
-------------------------------------------------------------------------
Genericobject plugin for GLPI
Copyright (C) 2016 by the Genericobject Development Team.
https://github.com/pluginsGLPI/genericobject
-------------------------------------------------------------------------
LICENSE
This file is part of Genericobject.
Genericobject 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.
Genericobject 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 Genericobject. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
@package genericobject
@author the genericobject plugin team
@copyright Copyright (c) 2010-2011 Order plugin team
@license GPLv2+
http://www.gnu.org/licenses/gpl.txt
@link https://forge.indepnet.net/projects/genericobject
@link http://www.glpi-project.org/
@since 2009
----------------------------------------------------------------------
*/
define ('PLUGIN_GENERICOBJECT_VERSION', '2.5.1');
if (!defined("GENERICOBJECT_DIR")) {
define("GENERICOBJECT_DIR", GLPI_ROOT . "/plugins/genericobject");
}
if (!defined("GENERICOBJECT_DOC_DIR")) {
define("GENERICOBJECT_DOC_DIR", GLPI_PLUGIN_DOC_DIR . "/genericobject");
if (!file_exists(GENERICOBJECT_DOC_DIR)) {
mkdir(GENERICOBJECT_DOC_DIR);
}
}
if (!defined("GENERICOBJECT_FRONT_PATH")) {
define("GENERICOBJECT_FRONT_PATH", GENERICOBJECT_DOC_DIR."/front");
if (!file_exists(GENERICOBJECT_FRONT_PATH)) {
mkdir(GENERICOBJECT_FRONT_PATH);
}
}
if (!defined("GENERICOBJECT_AJAX_PATH")) {
define("GENERICOBJECT_AJAX_PATH", GENERICOBJECT_DOC_DIR . "/ajax");
if (!file_exists(GENERICOBJECT_AJAX_PATH)) {
mkdir(GENERICOBJECT_AJAX_PATH);
}
}
if (!defined("GENERICOBJECT_CLASS_PATH")) {
define("GENERICOBJECT_CLASS_PATH", GENERICOBJECT_DOC_DIR . "/inc");
if (!file_exists(GENERICOBJECT_CLASS_PATH)) {
mkdir(GENERICOBJECT_CLASS_PATH);
}
}
if (!defined("GENERICOBJECT_LOCALES_PATH")) {
define("GENERICOBJECT_LOCALES_PATH", GENERICOBJECT_DOC_DIR . "/locales");
if (!file_exists(GENERICOBJECT_LOCALES_PATH)) {
mkdir(GENERICOBJECT_LOCALES_PATH);
}
}
if (!defined("GENERICOBJECT_FIELDS_PATH")) {
define("GENERICOBJECT_FIELDS_PATH", GENERICOBJECT_DOC_DIR . "/fields");
if (!file_exists(GENERICOBJECT_FIELDS_PATH)) {
mkdir(GENERICOBJECT_FIELDS_PATH);
}
}
if (!defined("GENERICOBJECT_PICS_PATH")) {
define("GENERICOBJECT_PICS_PATH", GENERICOBJECT_DOC_DIR . "/pics");
if (!file_exists(GENERICOBJECT_PICS_PATH)) {
mkdir(GENERICOBJECT_PICS_PATH);
}
}
// Autoload class generated in files/_plugins/genericobject/inc/
include_once( GENERICOBJECT_DIR . "/vendor/autoload.php");
include_once( GENERICOBJECT_DIR . "/inc/autoload.php");
include_once( GENERICOBJECT_DIR . "/inc/functions.php");
if (file_exists(GENERICOBJECT_DIR . "/log_filter.settings.php")) {
include_once(GENERICOBJECT_DIR . "/log_filter.settings.php");
}
$go_autoloader = new PluginGenericobjectAutoloader([
GENERICOBJECT_CLASS_PATH
]);
$go_autoloader->register();
/**
* Init hooks of the plugin.
* REQUIRED
*
* @return void
*/
function plugin_init_genericobject() {
global $PLUGIN_HOOKS, $CFG_GLPI, $GO_BLACKLIST_FIELDS, $GO_FIELDS,
$GENERICOBJECT_PDF_TYPES, $GO_LINKED_TYPES, $GO_READONLY_FIELDS, $LOADED_PLUGINS;
$GO_READONLY_FIELDS = array ("is_helpdesk_visible", "comment");
$GO_BLACKLIST_FIELDS = array ("itemtype", "table", "is_deleted", "id", "entities_id",
"is_recursive", "is_template", "notepad", "template_name",
"date_mod", "name", "is_helpdesk_visible", "comment",
"date_creation");
$GO_LINKED_TYPES = array ('Computer', 'Phone', 'Peripheral', 'Software', 'Monitor',
'Printer', 'NetworkEquipment');
$PLUGIN_HOOKS['csrf_compliant']['genericobject'] = true;
$GENERICOBJECT_PDF_TYPES = array ();
$plugin = new Plugin();
if ($plugin->isInstalled("genericobject")
&& $plugin->isActivated("genericobject")
&& isset($_SESSION['glpiactiveprofile'])) {
$PLUGIN_HOOKS['change_profile']['genericobject'] = [
'PluginGenericobjectProfile',
'changeProfile'
];
plugin_genericobject_includeCommonFields();
$PLUGIN_HOOKS['use_massive_action']['genericobject'] = 1;
// add css styles
$PLUGIN_HOOKS['add_css']['genericobject'] = [
"css/styles.css"
];
// Display a menu entry ?
$PLUGIN_HOOKS['menu_toadd']['genericobject'] = [
'config' => 'PluginGenericobjectType',
'assets' => 'PluginGenericobjectObject'
];
// Config page
if (Session::haveRight('config', READ)) {
$PLUGIN_HOOKS['config_page']['genericobject'] = 'front/type.php';
}
$PLUGIN_HOOKS['assign_to_ticket']['genericobject'] = true;
$PLUGIN_HOOKS['use_massive_action']['genericobject'] = 1;
$PLUGIN_HOOKS['post_init']['genericobject'] = 'plugin_post_init_genericobject';
$PLUGIN_HOOKS['plugin_datainjection_populate']['genericobject'] = "plugin_datainjection_populate_genericobject";
}
}
function plugin_post_init_genericobject() {
global $GO_FIELDS;
Plugin::registerClass(
'PluginGenericobjectProfile',
['addtabon' => ['Profile', 'PluginGenericobjectType']]
);
foreach (PluginGenericobjectType::getTypes() as $id => $objecttype) {
$itemtype = $objecttype['itemtype'];
if (class_exists($itemtype)) {
$itemtype::registerType();
}
}
}
/**
* Get the name and the version of the plugin
* REQUIRED
*
* @return array
*/
function plugin_version_genericobject() {
return array ('name' => __("Objects management", "genericobject"),
'version' => PLUGIN_GENERICOBJECT_VERSION,
'author' => "<a href=\"mailto:[email protected]\">Teclib'</a> & siprossii",
'homepage' => 'https://github.com/pluginsGLPI/genericobject',
'license' => 'GPLv2+',
'requirements' => [
'glpi' => [
'min' => '9.2',
'dev' => true
]
]
);
}
/**
* Check pre-requisites before install
* OPTIONNAL, but recommanded
*
* @return boolean
*/
function plugin_genericobject_check_prerequisites() {
$version = rtrim(GLPI_VERSION, '-dev');
if (version_compare($version, '9.2', 'lt')) {
echo "This plugin requires GLPI 9.2 or higher";
return false;
}
return true;
}
/**
* Check configuration process
*
* @param boolean $verbose Whether to display message on failure. Defaults to false
*
* @return boolean
*/
function plugin_genericobject_check_config($verbose = false) {
if (true) { // Your configuration check
return true;
}
if ($verbose) {
echo __('Installed / not configured');
}
return false;
}
function plugin_genericobject_haveTypeRight($itemtype, $right) {
switch ($itemtype) {
case 'PluginGenericobjectType' :
return Session::haveRight("config", $right);
default :
return Session::haveRight($itemtype, $right);
}
}
function plugin_genericobject_includeCommonFields($force = false) {
//Load genericobject default constants
if (!$force) {
include_once (GLPI_ROOT . "/plugins/genericobject/fields/field.constant.php");
} else {
include (GLPI_ROOT . "/plugins/genericobject/fields/field.constant.php");
}
//Include user constants, that must be accessible for all itemtypes
if (file_exists(GENERICOBJECT_FIELDS_PATH . "/field.constant.php")) {
if (!$force) {
include_once ( GENERICOBJECT_FIELDS_PATH . "/field.constant.php");
} else {
include ( GENERICOBJECT_FIELDS_PATH . "/field.constant.php");
}
}
}
function plugin_genericobject_haveRight($class,$right) {
$right_name = PluginGenericobjectProfile::getProfileNameForItemtype($class);
return Session::haveRight($right_name, $right);
}