-
Notifications
You must be signed in to change notification settings - Fork 31
/
setup.php
196 lines (172 loc) · 7.66 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
<?php
/**
* -------------------------------------------------------------------------
* Escalade plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Escalade.
*
* Escalade 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.
*
* Escalade 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 Escalade. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2015-2023 by Escalade plugin team.
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/escalade
* -------------------------------------------------------------------------
*/
use Glpi\Plugin\Hooks;
define('PLUGIN_ESCALADE_VERSION', '2.9.9');
// Minimal GLPI version, inclusive
define("PLUGIN_ESCALADE_MIN_GLPI", "10.0.11");
// Maximum GLPI version, exclusive
define("PLUGIN_ESCALADE_MAX_GLPI", "10.0.99");
if (!defined("PLUGIN_ESCALADE_DIR")) {
define("PLUGIN_ESCALADE_DIR", Plugin::getPhpDir("escalade"));
define("PLUGIN_ESCALADE_WEBDIR", Plugin::getWebDir("escalade"));
}
/**
* Init hooks of the plugin.
* REQUIRED
*
* @return void
*/
function plugin_init_escalade()
{
/** @var DBmysql $DB */
/** @var array $PLUGIN_HOOKS */
global $PLUGIN_HOOKS, $DB;
$PLUGIN_HOOKS['csrf_compliant']['escalade'] = true;
if ((isset($_SESSION['glpiID']) || isCommandLine()) && Plugin::isPluginActive('escalade')) {
//load config in session
if ($DB->tableExists("glpi_plugin_escalade_configs")) {
PluginEscaladeConfig::loadInSession();
// == Load js scripts ==
if (isset($_SESSION['plugins']['escalade']['config'])) {
$escalade_config = $_SESSION['plugins']['escalade']['config'];
$PLUGIN_HOOKS['add_javascript']['escalade'][] = 'js/function.js';
// on central page
if (strpos($_SERVER['REQUEST_URI'] ?? '', "central.php") !== false) {
//history and climb feature
if ($escalade_config['show_history']) {
$PLUGIN_HOOKS['add_javascript']['escalade'][] = 'js/central.js.php';
}
}
// on ticket page (in edition)
if (
(strpos($_SERVER['REQUEST_URI'] ?? '', "ticket.form.php") !== false
|| strpos($_SERVER['REQUEST_URI'] ?? '', "problem.form.php") !== false
|| strpos($_SERVER['REQUEST_URI'] ?? '', "change.form.php") !== false) && isset($_GET['id'])
) {
if (
!$escalade_config['remove_delete_requester_user_btn']
|| !$escalade_config['remove_delete_watcher_user_btn']
|| !$escalade_config['remove_delete_assign_user_btn']
|| !$escalade_config['remove_delete_requester_group_btn']
|| !$escalade_config['remove_delete_watcher_group_btn']
|| !$escalade_config['remove_delete_assign_group_btn']
|| !$escalade_config['remove_delete_assign_supplier_btn']
) {
//remove btn feature
$PLUGIN_HOOKS['add_javascript']['escalade'][] = 'js/remove_btn.js.php';
}
}
// on ticket page (in edition)
if (
strpos($_SERVER['REQUEST_URI'] ?? '', "ticket.form.php") !== false
&& isset($_GET['id'])
) {
//history and climb feature
if ($escalade_config['show_history']) {
$PLUGIN_HOOKS['add_javascript']['escalade'][] = 'js/escalade.js.php';
}
//clone ticket feature
if ($escalade_config['cloneandlink_ticket']) {
$PLUGIN_HOOKS['add_javascript']['escalade'][] = 'js/cloneandlink_ticket.js.php';
}
}
Plugin::registerClass('PluginEscaladeGroup_Group', ['addtabon' => 'Group']);
Plugin::registerClass('PluginEscaladeUser', ['addtabon' => ['User']]);
}
}
$PLUGIN_HOOKS['add_css']['escalade'][] = 'css/escalade.css';
// == Ticket modifications
$PLUGIN_HOOKS['pre_item_update']['escalade'] = [
'Ticket' => 'plugin_escalade_pre_item_update',
];
$PLUGIN_HOOKS['item_update']['escalade'] = [
'Ticket' => 'plugin_escalade_item_update',
];
$PLUGIN_HOOKS['item_add']['escalade'] = [
'Group_Ticket' => 'plugin_escalade_item_add_group_ticket',
'Ticket_User' => 'plugin_escalade_item_add_user',
'Ticket' => 'plugin_escalade_item_add_ticket',
];
$PLUGIN_HOOKS['pre_item_add']['escalade'] = [
'Group_Ticket' => 'plugin_escalade_pre_item_add_group_ticket',
'Ticket' => 'plugin_escalade_pre_item_add_ticket',
];
$PLUGIN_HOOKS['post_prepareadd']['escalade'] = [
'Ticket' => 'plugin_escalade_post_prepareadd_ticket',
];
$PLUGIN_HOOKS['item_purge']['escalade'] = [
'User' => 'plugin_escalade_item_purge',
'Ticket' => 'plugin_escalade_item_purge',
];
$PLUGIN_HOOKS['item_add']['escalade']['User'] = 'plugin_escalade_item_add_user';
//filter group feature
if ($escalade_config['use_filter_assign_group']) {
$PLUGIN_HOOKS[Hooks::FILTER_ACTORS]['escalade'] = [
'PluginEscaladeTicket', 'filter_actors',
];
}
// == Interface links ==
if (Session::haveRight('config', UPDATE)) {
$PLUGIN_HOOKS['config_page']['escalade'] = 'front/config.form.php';
}
$PLUGIN_HOOKS['use_massive_action']['escalade'] = 1;
// add more target to some notifications
$PLUGIN_HOOKS['item_add_targets']['escalade']['NotificationTargetPlanningRecall']
= ['PluginEscaladeNotification', 'addTargets'];
$PLUGIN_HOOKS['item_action_targets']['escalade']['NotificationTargetPlanningRecall']
= ['PluginEscaladeNotification', 'getActionTargets'];
// Add additional events for Ticket notifications
$PLUGIN_HOOKS['item_get_events']['escalade'] = [
'NotificationTargetTicket' => ['PluginEscaladeNotification', 'getEvents']
];
$PLUGIN_HOOKS['timeline_answer_actions']['escalade'] = ['PluginEscaladeTicket', 'addToTimeline'];
}
}
/**
* Get the name and the version of the plugin
* REQUIRED
*
* @return array
*/
function plugin_version_escalade()
{
return [
'name' => __("Escalation", "escalade"),
'version' => PLUGIN_ESCALADE_VERSION,
'author' => "<a href='http://www.teclib.com'>Teclib'</a>",
'homepage' => "https://github.com/pluginsGLPI/escalade",
'license' => 'GPLv2+',
'requirements' => [
'glpi' => [
'min' => PLUGIN_ESCALADE_MIN_GLPI,
'max' => PLUGIN_ESCALADE_MAX_GLPI,
]
]
];
}