-
Notifications
You must be signed in to change notification settings - Fork 45
/
setup.php
227 lines (196 loc) · 7.46 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
<?php
/**
* -------------------------------------------------------------------------
* Order plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Order.
*
* Order 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 3 of the License, or
* (at your option) any later version.
*
* Order 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 Order. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2009-2023 by Order plugin team.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/pluginsGLPI/order
* -------------------------------------------------------------------------
*/
define('PLUGIN_ORDER_VERSION', '2.10.6');
// Minimal GLPI version, inclusive
define("PLUGIN_ORDER_MIN_GLPI", "10.0.0");
// Maximum GLPI version, exclusive
define("PLUGIN_ORDER_MAX_GLPI", "10.0.99");
if (!defined('PLUGIN_ORDER_DIR')) {
define("PLUGIN_ORDER_DIR", Plugin::getPhpDir('order'));
}
if (!defined('PLUGIN_ORDER_TEMPLATE_DIR')) {
define("PLUGIN_ORDER_TEMPLATE_DIR", GLPI_PLUGIN_DOC_DIR . "/order/templates/");
}
if (!defined('PLUGIN_ORDER_SIGNATURE_DIR')) {
define("PLUGIN_ORDER_SIGNATURE_DIR", GLPI_PLUGIN_DOC_DIR . "/order/signatures/");
}
if (!defined('PLUGIN_ORDER_TEMPLATE_CUSTOM_DIR')) {
define("PLUGIN_ORDER_TEMPLATE_CUSTOM_DIR", GLPI_PLUGIN_DOC_DIR . "/order/generate/");
}
if (!defined('PLUGIN_ORDER_TEMPLATE_LOGO_DIR')) {
define("PLUGIN_ORDER_TEMPLATE_LOGO_DIR", GLPI_PLUGIN_DOC_DIR . "/order/logo/");
}
if (!defined('PLUGIN_ORDER_TEMPLATE_EXTENSION')) {
define("PLUGIN_ORDER_TEMPLATE_EXTENSION", "odt");
}
if (!defined('PLUGIN_ORDER_SIGNATURE_EXTENSION')) {
define("PLUGIN_ORDER_SIGNATURE_EXTENSION", "png");
}
/** @var array $CFG_GLPI */
global $CFG_GLPI;
if (!defined('PLUGIN_ORDER_NUMBER_STEP')) {
define("PLUGIN_ORDER_NUMBER_STEP", 1 / pow(10, $CFG_GLPI["decimal_number"]));
}
// Autoload
if (!defined('PCLZIP_TEMPORARY_DIR')) {
define('PCLZIP_TEMPORARY_DIR', GLPI_DOC_DIR . '/_tmp/pclzip');
}
include_once PLUGIN_ORDER_DIR . "/vendor/autoload.php";
/**
* Init hooks of the plugin.
* REQUIRED
*
* @return void
*/
function plugin_init_order()
{
/**
* @var object $PLUGIN_HOOKS
* @var array $CFG_GLPI
* @var array $ORDER_TYPES
*/
global $PLUGIN_HOOKS, $CFG_GLPI, $ORDER_TYPES;
Plugin::registerClass('PluginOrderProfile');
$PLUGIN_HOOKS['csrf_compliant']['order'] = true;
/* Init current profile */
$PLUGIN_HOOKS['change_profile']['order'] = ['PluginOrderProfile', 'initProfile'];
$plugin = new Plugin();
if ($plugin->isActivated('order')) {
$PLUGIN_HOOKS['migratetypes']['order'] = 'plugin_order_migratetypes';
$PLUGIN_HOOKS['assign_to_ticket']['order'] = true;
//Itemtypes in use for an order
$ORDER_TYPES = [
'Computer',
'Monitor',
'NetworkEquipment',
'Peripheral',
'Printer',
'Phone',
'ConsumableItem',
'CartridgeItem',
'Contract',
'PluginOrderOther',
'SoftwareLicense',
'Certificate',
'Rack',
'Enclosure',
'Pdu',
];
$CFG_GLPI['plugin_order_types'] = $ORDER_TYPES;
$PLUGIN_HOOKS['pre_item_purge']['order'] = [
'Profile' => ['PluginOrderProfile', 'purgeProfiles'],
'DocumentCategory' => ['PluginOrderDocumentCategory', 'purgeItem'],
];
$PLUGIN_HOOKS['pre_item_update']['order'] = [
'Infocom' => ['PluginOrderOrder_Item', 'updateItem'],
'Contract' => ['PluginOrderOrder_Item', 'updateItem'],
];
$PLUGIN_HOOKS['item_add']['order'] = [
'Document' => ['PluginOrderOrder', 'addDocumentCategory']
];
include_once(PLUGIN_ORDER_DIR . "/inc/order_item.class.php");
foreach (PluginOrderOrder_Item::getClasses(true) as $type) {
$PLUGIN_HOOKS['item_purge']['order'][$type] = 'plugin_item_purge_order';
}
Plugin::registerClass('PluginOrderOrder', [
'document_types' => true,
'unicity_types' => true,
'notificationtemplates_types' => true,
'helpdesk_visible_types' => true,
'ticket_types' => true,
'contract_types' => true,
'linkuser_types' => true,
'addtabon' => ['Budget']
]);
Plugin::registerClass('PluginOrderReference', ['document_types' => true]);
Plugin::registerClass('PluginOrderProfile', ['addtabon' => ['Profile']]);
$values['notificationtemplates_types'] = true;
$PLUGIN_HOOKS['infocom']['order'] = ['PluginOrderOrder_Item', 'showForInfocom'];
Plugin::registerClass('PluginOrderOrder_Item', $values);
if (PluginOrderOrder::canView()) {
Plugin::registerClass('PluginOrderDocumentCategory', ['addtabon' => ['DocumentCategory']]);
Plugin::registerClass('PluginOrderOrder_Supplier', ['addtabon' => ['Supplier']]);
Plugin::registerClass('PluginOrderPreference', ['addtabon' => ['Preference']]);
}
/*if glpi is loaded */
if (Session::getLoginUserID()) {
$PLUGIN_HOOKS['add_css']['order'][] = 'order.css';
/* link to the config page in plugins menu */
if (Session::haveRight("config", UPDATE)) {
$PLUGIN_HOOKS['config_page']['order'] = 'front/config.form.php';
}
if (
PluginOrderOrder::canView()
|| PluginOrderReference::canView()
|| PluginOrderBill::canView()
) {
$PLUGIN_HOOKS['menu_toadd']['order']['management'] = 'PluginOrderMenu';
}
$PLUGIN_HOOKS['assign_to_ticket']['order'] = true;
$PLUGIN_HOOKS['use_massive_action']['order'] = 1;
$PLUGIN_HOOKS['plugin_datainjection_populate']['order'] = "plugin_datainjection_populate_order";
}
}
}
/**
* Get the name and the version of the plugin
* REQUIRED
*
* @return array
*/
function plugin_version_order()
{
return [
'name' => __("Orders management", "order"),
'version' => PLUGIN_ORDER_VERSION,
'author' => 'The plugin order team',
'homepage' => 'https://github.com/pluginsGLPI/order',
'license' => 'GPLv2+',
'requirements' => [
'glpi' => [
'min' => PLUGIN_ORDER_MIN_GLPI,
'max' => PLUGIN_ORDER_MAX_GLPI,
]
]
];
}
/**
* Check pre-requisites before install
* OPTIONNAL, but recommanded
*
* @return boolean
*/
function plugin_order_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;
}