-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathsetup.php
More file actions
293 lines (242 loc) · 10.4 KB
/
setup.php
File metadata and controls
293 lines (242 loc) · 10.4 KB
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
<?php
/*
* @version $Id: HEADER 15930 2011-10-30 15:47:55Z tsmr $
-------------------------------------------------------------------------
resources plugin for GLPI
Copyright (C) 2009-2022 by the resources Development Team.
https://github.com/InfotelGLPI/resources
-------------------------------------------------------------------------
LICENSE
This file is part of resources.
resources 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.
resources 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 resources. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
use Glpi\Plugin\Hooks;
use GlpiPlugin\Behaviors\Common;
use GlpiPlugin\Behaviors\Rule;
use GlpiPlugin\Mydashboard\Menu as DashboardMenu;
use GlpiPlugin\Positions\Position;
use GlpiPlugin\Resources\Dashboard;
use GlpiPlugin\Resources\Directory;
use GlpiPlugin\Resources\Employment;
use GlpiPlugin\Resources\LinkAd;
use GlpiPlugin\Resources\Menu;
use GlpiPlugin\Resources\Metademand;
use GlpiPlugin\Resources\Notification;
use GlpiPlugin\Resources\Profile;
use GlpiPlugin\Resources\Recap;
use GlpiPlugin\Resources\Resource;
use GlpiPlugin\Resources\Resource_Item;
use GlpiPlugin\Resources\ResourcePDF;
use GlpiPlugin\Resources\RuleChecklist;
use GlpiPlugin\Resources\RuleChecklistCollection;
use GlpiPlugin\Resources\RuleContracttype;
use GlpiPlugin\Resources\RuleContracttypeCollection;
use GlpiPlugin\Resources\RuleContracttypeHidden;
use GlpiPlugin\Resources\RuleContracttypeHiddenCollection;
use GlpiPlugin\Resources\RuleContracttypeReadonly;
use GlpiPlugin\Resources\RuleContracttypeReadonlyCollection;
use GlpiPlugin\Resources\Servicecatalog;
use GlpiPlugin\Resources\TaskPlanning;
define('PLUGIN_RESOURCES_VERSION', '4.0.13');
global $CFG_GLPI;
if (!defined("PLUGIN_RESOURCES_DIR")) {
define("PLUGIN_RESOURCES_DIR", Plugin::getPhpDir("resources"));
$root = $CFG_GLPI['root_doc'] . '/plugins/resources';
define("PLUGIN_RESOURCES_WEBDIR", $root);
}
// Init the hooks of the plugins -Needed
function plugin_init_resources()
{
global $PLUGIN_HOOKS;
// add autoload for vendor
include_once(PLUGIN_RESOURCES_DIR . "/vendor/autoload.php");
$PLUGIN_HOOKS['csrf_compliant']['resources'] = true;
$PLUGIN_HOOKS['change_profile']['resources'] = [Profile::class, 'initProfile'];
$PLUGIN_HOOKS['assign_to_ticket']['resources'] = true;
if (Session::getLoginUserID()) {
$PLUGIN_HOOKS['pre_item_form']['resources'] = [LinkAd::class, 'messageSolution'];
$PLUGIN_HOOKS['post_item_form']['resources'] = [LinkAd::class, 'deleteButtton'];
$noupdate = false;
if (Session::getCurrentInterface() != 'central') {
$noupdate = true;
}
Plugin::registerClass(Resource::class, [
// 'linkuser_types' => true,
'document_types' => true,
'ticket_types' => true,
'helpdesk_visible_types' => true,
'notificationtemplates_types' => true,
'unicity_types' => true,
// 'massiveaction_nodelete_types' => $noupdate,
// 'massiveaction_noupdate_types' => $noupdate
]);
Plugin::registerClass(Directory::class, [
// 'massiveaction_nodelete_types' => true,
// 'massiveaction_noupdate_types' => true
]);
Plugin::registerClass(Recap::class, [
// 'massiveaction_nodelete_types' => true,
// 'massiveaction_noupdate_types' => true
]);
Plugin::registerClass(TaskPlanning::class, [
'planning_types' => true,
]);
Plugin::registerClass(RuleChecklistCollection::class, [
'rulecollections_types' => true,
]);
Plugin::registerClass(RuleContracttypeCollection::class, [
'rulecollections_types' => true,
]);
Plugin::registerClass(RuleContracttypeHiddenCollection::class, [
'rulecollections_types' => true,
]);
Plugin::registerClass(RuleContracttypeReadonlyCollection::class, [
'rulecollections_types' => true
]);
Plugin::registerClass(
Profile::class,
['addtabon' => 'Profile']
);
Plugin::registerClass(Employment::class, [
// 'massiveaction_nodelete_types' => true
]);
if (Session::haveRight("plugin_servicecatalog", READ)
|| Session::haveright("plugin_servicecatalog_setup", UPDATE)) {
$PLUGIN_HOOKS['servicecatalog']['resources'] = [Servicecatalog::class];
}
if ((Session::haveRight("plugin_resources", READ)
|| Session::haveright("plugin_resources_employee", UPDATE))) {
$PLUGIN_HOOKS['helpdesk_menu_entry']['resources'] = PLUGIN_RESOURCES_WEBDIR . '/front/menu.php';
$PLUGIN_HOOKS['helpdesk_menu_entry_icon']['resources'] = Resource::getIcon();
}
if (Session::haveright("plugin_resources_checklist", READ)
&& class_exists(DashboardMenu::class)
) {
$PLUGIN_HOOKS['mydashboard']['resources'] = [Dashboard::class];
}
if (class_exists(Position::class)) {
Position::registerType(Resource::class);
}
if (class_exists(Common::class)) {
Common::addCloneType(RuleChecklist::class, Rule::class);
Common::addCloneType(RuleContracttype::class, Rule::class);
Common::addCloneType(RuleContracttypeHidden::class, Rule::class); // TODO Confirm usefull
Common::addCloneType(RuleContracttypeReadonly::class, Rule::class);
}
if (class_exists('PluginTreeviewConfig')) {
PluginTreeviewConfig::registerType(Resource::class);
$PLUGIN_HOOKS['treeview'][Resource::class] = '../resources/pics/miniresources.png';
$PLUGIN_HOOKS['treeview_params']['resources'] = [Resource::class, 'showResourceTreeview'];
}
if ((Session::haveRight("plugin_resources", READ)
|| Session::haveright("plugin_resources_employee", UPDATE))) {
$PLUGIN_HOOKS['menu_toadd']['resources'] = ['admin' => Menu::class];
}
Plugin::registerClass(LinkAd::class, ['addtabon' => 'Ticket']);
// Resource menu
if (Session::haveRight("plugin_resources", READ)
|| Session::haveright("plugin_resources_employee", UPDATE)) {
$PLUGIN_HOOKS['redirect_page']['resources'] = PLUGIN_RESOURCES_WEBDIR . "/front/resource.form.php";
}
//
$PLUGIN_HOOKS['use_massive_action']['resources'] = true;
// }
// Config
if (Session::haveRight("config", UPDATE)) {
$PLUGIN_HOOKS['config_page']['resources'] = 'front/config.form.php';
}
// Add specific files to add to the header : javascript or css
if (Session::haveRight("plugin_resources", READ)) {
$PLUGIN_HOOKS[Hooks::ADD_CSS]['resources'] = ["css/resources.css"];
$PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT]['resources'] = [
"resources.js",
"lib/plugins/jquery.address.js",
"lib/plugins/jquery.mousewheel.js",
"lib/plugins/jquery.scroll.js",
];
// if (strpos($_SERVER['REQUEST_URI'], "resource.card.form.php") !== false) {
// $PLUGIN_HOOKS[Hooks::ADD_JAVASCRIPT]['resources'][] = "lib/resources_card.js";
// $PLUGIN_HOOKS[Hooks::ADD_CSS]['resources'][] = "css/resourcecard.css";
// }
}
//TODO : Check
$PLUGIN_HOOKS['plugin_pdf'][Resource::class] = ResourcePDF::class;
$PLUGIN_HOOKS['item_add']['resources'] =
[
'Item_Ticket' => [new Resource(), 'afterInsert'],
];
//Clean Plugin on Profile delete
if (class_exists(Resource_Item::class)) { // only if plugin activated
$PLUGIN_HOOKS['pre_item_purge']['resources'] = [
Resource::class => [
Notification::class,
'purgeNotification',
],
];
$PLUGIN_HOOKS['plugin_datainjection_populate']['resources'] = 'plugin_datainjection_populate_resources';
}
//planning action
$PLUGIN_HOOKS['planning_populate']['resources'] = [TaskPlanning::class, 'populatePlanning'];
$PLUGIN_HOOKS['display_planning']['resources'] = [TaskPlanning::class, 'displayPlanningItem'];
$PLUGIN_HOOKS['migratetypes']['resources'] = 'plugin_datainjection_migratetypes_resources';
$PLUGIN_HOOKS['metademands']['resources'] = [Metademand::class];
}
// End init, when all types are registered
$PLUGIN_HOOKS['post_init']['resources'] = 'plugin_resources_postinit';
}
// Get the name and the version of the plugin - Needed
/**
* @return array
*/
function plugin_version_resources()
{
return [
'name' => _n('Human Resource', 'Human Resources', 2, 'resources'),
'version' => PLUGIN_RESOURCES_VERSION,
'license' => 'GPLv2+',
'author' => "<a href='https://blogglpi.infotel.com'>Infotel</a>, Xavier CAILLAUD",
'homepage' => 'https://github.com/InfotelGLPI/resources',
'requirements' => [
'glpi' => [
'min' => '11.0',
'max' => '12.0',
'dev' => false,
],
],
];
}
// Optional : check prerequisites before install : may print errors or add to message after redirect
/**
* @return bool
*/
/**
* @return bool
*/
function plugin_resources_check_prerequisites()
{
if (!is_readable(__DIR__ . '/vendor/autoload.php') || !is_file(__DIR__ . '/vendor/autoload.php')) {
echo "Run composer install --no-dev in the plugin directory<br>";
return false;
}
return true;
}
/**
* @param $types
*
* @return mixed
*/
function plugin_datainjection_migratetypes_resources($types)
{
$types[4300] = Resource::class;
return $types;
}