-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsetup.php
More file actions
executable file
·230 lines (198 loc) · 8.94 KB
/
setup.php
File metadata and controls
executable file
·230 lines (198 loc) · 8.94 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
<?php
/*
-------------------------------------------------------------------------
Archisw plugin for GLPI
Copyright (C) 2009-2018 by Eric Feron.
-------------------------------------------------------------------------
LICENSE
This file is part of Archisw.
Archisw 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.
Archisw 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 Archisw. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
define('PLUGIN_ARCHISW_VERSION', '3.0.25');
// Minimal GLPI version, inclusive
define('PLUGIN_ARCHISW_MIN_GLPI', '10.0.0');
// Maximum GLPI version, exclusive
define('PLUGIN_ARCHISW_MAX_GLPI', '11.0.99');
// Init the hooks of the plugins -Needed
function plugin_init_archisw() {
global $PLUGIN_HOOKS, $CFG_GLPI, $DB;
$PLUGIN_HOOKS['csrf_compliant']['archisw'] = true;
$PLUGIN_HOOKS['change_profile']['archisw'] = ['PluginArchiswProfile', 'initProfile'];
$PLUGIN_HOOKS['assign_to_ticket']['archisw'] = true;
$PLUGIN_HOOKS['assign_to_ticket_dropdown']['archisw'] = true;
$PLUGIN_HOOKS['assign_to_ticket_itemtype']['archisw'] = ['PluginArchiswSwcomponent_Item'];
$CFG_GLPI['impact_asset_types']['PluginArchiswSwcomponent'] = Plugin::getWebDir("archisw", false)."/swcomponent.png";
Plugin::registerClass('PluginArchiswSwcomponent', [
'linkgroup_tech_types' => true,
'linkuser_tech_types' => true,
'document_types' => true,
'ticket_types' => true,
'helpdesk_visible_types' => true,
'addtabon' => 'Supplier'
]);
Plugin::registerClass('PluginArchiswProfile',
['addtabon' => 'Profile']);
//Plugin::registerClass('PluginDatabasesDatabase_Item',
// array('ticket_types' => true));
// Register generic objects from genericobject plugin
$plugin = new Plugin();
if ($plugin->isActivated('genericobject')) {
$query = "SELECT itemtype FROM `glpi_plugin_genericobject_types` WHERE `is_active` = TRUE";
$result = $DB->doQuery($query);
$rowcount = $DB->numrows($result);
if ($rowcount > 0) {
while ($data = $DB->fetchAssoc($result)) {
PluginArchiswSwcomponent::registerType($data['itemtype']);
}
}
}
// Add links to other plugins
$types = ['PluginArchimapGraph'];
$associatedtypes = ['PluginAccountsAccount',
'PluginArchiswSwcomponent'];
foreach ($types as $itemtype) {
if (class_exists($itemtype)) {
$itemtype::registerType('PluginArchiswSwcomponent');
PluginArchiswSwcomponent::registerType($itemtype);
}
}
// Add other plugin associations
if (class_exists('PluginArchiswSwcomponent'))
foreach ($associatedtypes as $itemtype) {
// if (class_exists($itemtype)) {
// $itemtype::registerType('PluginArchiswSwcomponent');
PluginArchiswSwcomponent::registerType($itemtype);
// }
}
if (Session::getLoginUserID()) {
// link to fields plugin
if ($plugin->isActivated('fields')
&& Session::haveRight("plugin_archisw", READ))
{
$PLUGIN_HOOKS['plugin_fields']['archisw'] = 'PluginArchiswSwcomponent';
}
if (Session::haveRight("plugin_archisw", READ)) {
$PLUGIN_HOOKS['menu_toadd']['archisw']['assets'] = 'PluginArchiswMenu';
}
if (Session::haveRight("plugin_archisw_configuration", READ)) {
$PLUGIN_HOOKS['menu_toadd']['archisw']["config"] = 'PluginArchiswConfigswMenu';
}
if (Session::haveRight("plugin_archisw", READ)
|| Session::haveRight("config", UPDATE)) {
$PLUGIN_HOOKS['config_page']['archisw'] = 'front/configsw.php';
}
if (Session::haveRight("plugin_archisw", UPDATE)) {
$PLUGIN_HOOKS['use_massive_action']['archisw']=1;
}
if (class_exists('PluginArchiswSwcomponent_Item')) { // only if plugin activated
$PLUGIN_HOOKS['plugin_datainjection_populate']['archisw'] = 'plugin_datainjection_populate_archisw';
}
// End init, when all types are registered
$PLUGIN_HOOKS['post_init']['archisw'] = 'plugin_archisw_postinit';
// Import from Data_Injection plugin
$PLUGIN_HOOKS['migratetypes']['archisw'] = 'plugin_datainjection_migratetypes_archisw';
$PLUGIN_HOOKS['pre_item_update']['archisw'] = ['PluginArchiswConfigsw' => 'hook_pre_item_update_archisw_configsw',
'PluginArchiswConfigswLink' => 'hook_pre_item_update_archisw_configswlink'];
$PLUGIN_HOOKS['pre_item_add']['archisw'] = ['PluginArchiswConfigsw' => 'hook_pre_item_add_archisw_configsw',
'PluginArchiswConfigswLink' => 'hook_pre_item_add_archisw_configswlink'];
$PLUGIN_HOOKS['pre_item_purge']['archisw'] = ['PluginArchiswConfigsw' => 'hook_pre_item_purge_archisw_configsw',
'PluginArchiswConfigswLink' => 'hook_pre_item_purge_archisw_configswlink'];
}
}
// Get the name and the version of the plugin - Needed
function plugin_version_archisw() {
return array (
'name' => _n('Apps structure', 'Apps structures', 2, 'archisw'),
'version' => PLUGIN_ARCHISW_VERSION,
'author' => "Eric Feron",
'license' => 'GPLv2+',
'homepage'=> 'https://github.com/ericferon/glpi-archisw',
'requirements' => [
'glpi' => [
'min' => PLUGIN_ARCHISW_MIN_GLPI,
'max' => PLUGIN_ARCHISW_MAX_GLPI,
// 'dev' => false
]
]
);
}
// Optional : check prerequisites before install : may print errors or add to message after redirect
function plugin_archisw_check_prerequisites() {
global $DB;
$query = "select * from glpi_plugins where directory = 'statecheck' and state = 1";
$result_query = $DB->doQuery($query);
if($DB->numRows($result_query) == 1) {
return true;
} else {
echo "the plugin 'statecheck' must be installed before using 'Apps structure (archisw)'";
return false;
}
}
// Uninstall process for plugin : need to return true if succeeded : may display messages or add to message after redirect
function plugin_archisw_check_config() {
return true;
}
/*function plugin_datainjection_migratetypes_archisw($types) {
$types[2400] = 'PluginArchiswSwcomponent';
return $types;
}
*/
// Uninstall process for plugin : need to return true if succeeded : may display messages or add to message after redirect
function hook_pre_item_add_archisw_configsw(CommonDBTM $item) {
global $DB;
$fieldname = $item->fields['name'];
$dbfield = new PluginArchiswConfigswDbfieldtype;
if ($dbfield->getFromDB($item->fields['plugin_archisw_configswdbfieldtypes_id'])) {
$fieldtype = $dbfield->fields['name'];
$query = "ALTER TABLE `glpi_plugin_archisw_swcomponents` ADD COLUMN IF NOT EXISTS $fieldname $fieldtype";
if($item->fields['plugin_archisw_configswdatatypes_id'] == 6) {// if dropdown, add key
$query .= ", ADD KEY IF NOT EXISTS $fieldname ($fieldname)";
}
$result = $DB->doQuery($query);
return true;
}
return false;
}
function hook_pre_item_update_archisw_configsw(CommonDBTM $item) {
global $DB;
$oldfieldname = $item->fields['name'];
$newfieldname = $item->input['name'];
$dbfield = new PluginArchiswConfigswDbfieldtype;
if ($dbfield->getFromDB($item->fields['plugin_archisw_configswdbfieldtypes_id'])) {
$fieldtype = $dbfield->fields['name'];
if ($oldfieldname != $newfieldname) {
$query = "ALTER TABLE `glpi_plugin_archisw_swcomponents` CHANGE COLUMN $oldfieldname $newfieldname $fieldtype";
} else {
$query = "ALTER TABLE `glpi_plugin_archisw_swcomponents` MODIFY $newfieldname $fieldtype";
}
if($item->input['plugin_archisw_configswdatatypes_id'] == 6) {// if dropdown, add key
$query .= ", ADD KEY IF NOT EXISTS $newfieldname ($newfieldname)";
}
$result = $DB->doQuery($query);
return true;
}
return false;
}
function hook_pre_item_purge_archisw_configsw(CommonDBTM $item) {
global $DB;
$oldid = $item->fields['id'];
$oldfieldname = $item->fields['name'];
// suppress in glpi_plugin_archisw_labeltranslations
$query = "DELETE FROM `glpi_plugin_archisw_labeltranslations` WHERE `items_id` = '".$oldid."'";
$result = $DB->doQuery($query);
// suppress column
$query = "ALTER TABLE `glpi_plugin_archisw_swcomponents` DROP COLUMN IF EXISTS $oldfieldname";
$result = $DB->doQuery($query);
return true;
}
?>