forked from pluginsGLPI/fields
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.php
executable file
·151 lines (124 loc) · 5.76 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
<?php
// Init the hooks of the plugins -Needed
function plugin_init_fields() {
global $PLUGIN_HOOKS;
$PLUGIN_HOOKS['csrf_compliant']['fields'] = true;
$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
$PLUGIN_HOOKS['add_css']['fields'][] = 'fields.css';
$PLUGIN_HOOKS['add_javascript']['fields'][] = 'fields.js.php';
// 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'][] = "scripts/redips-drag-min.js";
$PLUGIN_HOOKS['add_javascript']['fields'][] = "scripts/drag-field-row.js";
}
// Add Fields to Datainjection
if ($plugin->isInstalled('datainjection') && $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] = array("PluginFieldsContainer",
"preItemUpdate");
$PLUGIN_HOOKS['pre_item_purge'] ['fields'][$itemtype] = array("PluginFieldsContainer",
"preItemPurge");
$PLUGIN_HOOKS['item_add']['fields'][$itemtype] = array("PluginFieldsContainer",
"preItemUpdate");
}
}
}
}
// Get the name and the version of the plugin - Needed
function plugin_version_fields() {
return array ('name' => __("Additionnal fields", "fields"),
'version' => '0.90-1.1',
'author' => 'Teclib\', Olivier Moron',
'homepage' => 'teclib.com',
'license' => 'GPLv2+',
'minGlpiVersion' => '0.85');
}
// Optional : check prerequisites before install : may print errors or add to message after redirect
function plugin_fields_check_prerequisites() {
if (version_compare(GLPI_VERSION,'0.85','lt')) {
echo "This plugin requires GLPI 0.85";
return false;
}
if (version_compare(PHP_VERSION, '5.3.0', 'lt')) {
echo "PHP 5.3.0 or higher is required";
return false;
}
// Check class and front files for existing containers and dropdown fields
plugin_fields_checkFiles();
return true;
}
function plugin_fields_checkFiles() {
$plugin = new Plugin();
if (isset($_SESSION['glpiactiveentities'])
&& $plugin->isInstalled('fields')
&& $plugin->isActivated('fields')) {
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) {
$classname = "PluginFields".ucfirst($container['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 for plugin : need to return true if succeeded
// Can display a message only if failure and $verbose is true
function plugin_fields_check_config($verbose = false) {
if (true) { // Your configuration check
return true;
}
if ($verbose) {
echo __("Installed / not configured");
}
return false;
}