-
Notifications
You must be signed in to change notification settings - Fork 3
/
hook.php
196 lines (176 loc) · 7.27 KB
/
hook.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
/**
* Notifications plugins
*
* Copyright (C) 2017-2021 by the Notification plugin Development Team.
*
* https://github.com/ddurieux/glpi_notifications
*
* ------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Notifications plugin project.
*
* Notifications plugin is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Notifications plugin 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Notifications plugin. If not, see <http://www.gnu.org/licenses/>.
*
* ------------------------------------------------------------------------
*
* This file is used to manage hooks
*
* ------------------------------------------------------------------------
*
* @package Notifications plugin
* @author David Durieux
* @copyright Copyright (c) 2017-2021 Notifications plugin team
* @license AGPL License 3.0 or (at your option) any later version
* http://www.gnu.org/licenses/agpl-3.0-standalone.html
* @link https://github.com/ddurieux/glpi_notifications
*
*/
/**
* Manage the installation process
*
* @return boolean
*/
function plugin_notifications_install() {
global $DB;
if (!$DB->tableExists('glpi_plugin_notifications_notifications')) {
$query = "CREATE TABLE `glpi_plugin_notifications_notifications` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`entities_id` int(11) NOT NULL DEFAULT '0',
`is_recursive` tinyint(1) NOT NULL DEFAULT '1',
`last_generation` datetime DEFAULT NULL,
`options` text DEFAULT NULL,
`itemtype` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`event` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`comment` text COLLATE utf8_unicode_ci,
`date_mod` datetime DEFAULT NULL,
`date_creation` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->query($query);
}
// add option followup_task_display (9.3+2.0)
$iterator = $DB->request([
'FROM' => 'glpi_plugin_notifications_notifications'
]);
while ($data = $iterator->next()) {
if (!strstr($data['options'], 'followup_task_display')) {
// add it
$options = str_replace("}", ',"opt_followup_task_display":"separate"}', $data['options']);
$DB->update(
'glpi_plugin_notifications_notifications',
['options' => $options],
['WHERE' => ['id' => $data['id']]]);
}
if (!strstr($data['options'], 'subject')) {
$options = str_replace("}", ',"opt_subject":"##ticket.shortentity## - ##ticket.action## : ##ticket.title##"}', $data['options']);
$DB->update(
'glpi_plugin_notifications_notifications',
['options' => $options],
['WHERE' => ['id' => $data['id']]]);
}
if (!strstr($data['options'], 'logo')) {
$options = str_replace("}", ',"opt_logo":"default"}', $data['options']);
$DB->update(
'glpi_plugin_notifications_notifications',
['options' => $options],
['WHERE' => ['id' => $data['id']]]);
}
}
return true;
}
/**
* Manage the uninstallation of the plugin
*
* @return boolean
*/
function plugin_notifications_uninstall() {
global $DB;
$query = "DROP TABLE `glpi_plugin_notifications_notifications`";
$DB->query($query);
return true;
}
/**
* Fill tags with data from database
*/
function plugin_notifications_item_get_datas(NotificationTarget $item) {
$item->data['activitymessages'] = [];
$restrict = [
'items_id' => $item->obj->getField('id'),
'itemtype' => 'Ticket'
];
$restrict_noprivate = $restrict;
$restrict_noprivate['is_private'] = 0;
// for followup and tasks, we compare followups / tasks got by the core and compare total with get here (only public and all)
// for that we use $item->data['followups'] and $item->data['tasks']
$followups_in_data = count($item->data['followups']);
$tasks_in_data = count($item->data['tasks']);
// Get followups
$dbu = new DbUtils();
$followups = $dbu->getAllDataFromTable('glpi_itilfollowups', $restrict, false);
$followups_noprivate = $dbu->getAllDataFromTable('glpi_itilfollowups', $restrict_noprivate, false);
$allfollowups = [];
if (count($followups_noprivate) == $followups_in_data) {
$allfollowups = $followups_noprivate;
} else if (count($followups) == $followups_in_data) {
$allfollowups = $followups;
} else {
$allfollowups = $followups_noprivate;
}
foreach ($allfollowups as $followup) {
$tmp = [
'##activitymessage.type##' => 'followup',
'##activitymessage.isprivate##' => Dropdown::getYesNo($followup['is_private']),
'##activitymessage.author##' => Html::clean(getUserName($followup['users_id'])),
'##activitymessage.requesttype##' => Dropdown::getDropdownName('glpi_requesttypes', $followup['requesttypes_id']),
'##activitymessage.date##' => Html::convDateTime($followup['date']),
'##activitymessage.description##' => Html::clean($followup['content']),
'##activitymessage.category##' => '',
'##task.time##' => ''
];
$item->data['activitymessages'][strtotime($followup['date'])] = $tmp;
}
// get tasks
$restrict = ['tickets_id' => $item->obj->getField('id')];
$restrict_noprivate = $restrict;
$restrict_noprivate['is_private'] = 0;
$tasks = $dbu->getAllDataFromTable('glpi_tickettasks', $restrict, false);
$tasks_noprivate = $dbu->getAllDataFromTable('glpi_tickettasks', $restrict_noprivate, false);
$alltasks = [];
if (count($tasks_noprivate) == $tasks_in_data) {
$alltasks = $tasks_noprivate;
} else if (count($tasks) == $tasks_in_data) {
$alltasks = $tasks;
} else {
$alltasks = $tasks_noprivate;
}
foreach ($alltasks as $task) {
$tmp = [
'##activitymessage.type##' => 'task',
'##activitymessage.isprivate##' => Dropdown::getYesNo($task['is_private']),
'##activitymessage.author##' => Html::clean(getUserName($task['users_id'])),
'##activitymessage.requesttype##' => '',
'##activitymessage.date##' => Html::convDateTime($task['date']),
'##activitymessage.description##' => Html::clean($task['content']),
'##activitymessage.category##' => Dropdown::getDropdownName('glpi_taskcategories', $task['taskcategories_id']),
'##task.time##' => Html::timestampToString($task['actiontime'], false)
];
$item->data['activitymessages'][strtotime($task['date'])] = $tmp;
}
krsort($item->data['activitymessages']);
$item->data['##ticket.numberofactivitymessages##'] = count($item->data['activitymessages']);
}