-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathnotificationtargetprocessmaker.class.php
More file actions
252 lines (214 loc) · 9.99 KB
/
notificationtargetprocessmaker.class.php
File metadata and controls
252 lines (214 loc) · 9.99 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<?php
/*
-------------------------------------------------------------------------
ProcessMaker plugin for GLPI
Copyright (C) 2014-2024 by Raynet SAS a company of A.Raymond Network.
https://www.araymond.com/
-------------------------------------------------------------------------
LICENSE
This file is part of ProcessMaker plugin for GLPI.
This file 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.
This 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this plugin. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/**
* PluginProcessmakerNotificationTargetProcessmaker short summary.
*
* PluginProcessmakerNotificationTargetProcessmaker description.
*
* Common notificationtarget class for cases and tasks
*
* @version 1.0
* @author MoronO
*/
class PluginProcessmakerNotificationTargetProcessmaker extends NotificationTargetCommonITILObject {
const PM_USER_TYPE = 1000;
const OLD_TASK_TECH_IN_CHARGE = 1;
/**
* Summary of saveNotificationState
* @param mixed $donotif
* @return mixed
*/
static function saveNotificationState($donotif) {
global $CFG_GLPI;
$savenotif = $CFG_GLPI["use_notifications"];
if (!$donotif) {
$CFG_GLPI["use_notifications"] = false;
}
return $savenotif;
}
/**
* Summary of restoreNotificationState
* @param mixed $savenotif
*/
static function restoreNotificationState($savenotif) {
global $CFG_GLPI;
$CFG_GLPI["use_notifications"] = $savenotif;
}
/**
* Summary of getSubjectPrefix
* @param mixed $event
* @return string
*/
function getSubjectPrefix($event = '') {
return '';
}
/**
* Summary of getTags
*/
public function getTags() {
$tags = ['process.category' => __('Process category', 'processmaker'),
'process.categoryid' => __('Process category id', 'processmaker'),
'process.categorycomment' => __('Process category comment', 'processmaker'),
'case.id' => __('Case id', 'processmaker'),
'case.title' => __('Case title', 'processmaker'),
'case.description' => __('Case description', 'processmaker'),
'case.url' => __('Case URL'),
'var.XXX' => __('Case variable \'XXX\'', 'processmaker'),
'array.YYY' => __('List of values in \'YYY\' array', 'processmaker'),
'array.numberofYYY' => __('Number of rows in \'YYY\' array', 'processmaker'),
'array.YYY.colname' => __('Value for colname in \'YYY\' array', 'processmaker'),
'1darray.ZZZ.key' => __('Value for key in \'ZZZ\' assoc array (1-dimension array)', 'processmaker'),
'item.type' => __('Item type', 'processmaker'),
'item.id' => __('Item id', 'processmaker'),
'item.url' => __('Item URL', 'processmaker'),
'item.title' => __('Item title', 'processmaker')
];
foreach ($tags as $tag => $label) {
$elt= ['tag' => $tag,
'label' => $label,
'value' => true];
if ($tag == 'var.XXX') {
$elt['allowed_values'] = [__('XXX is to be replaced by any case variable names', 'processmaker')];
}
if ($tag == 'array.YYY') {
$elt['allowed_values'] = [__('YYY is to be replaced by any array variables', 'processmaker')];
$elt['foreach'] = true;
}
if ($tag == '1darray.ZZZ.key') {
$elt['allowed_values'] = [__('ZZZ is to be replaced by any assoc array variables (1-dimension array with key/value pairs)', 'processmaker')];
}
$this->addTagToList($elt);
}
asort($this->tag_descriptions);
}
/**
* Get all data needed for template processing
**/
public function addDataForTemplate($event, $options = []) {
global $CFG_GLPI, $PM_DB;
$excluded = ['_VAR_CHANGED_',
'PIN',
'APPLICATION',
'PROCESS',
'TASK',
'INDEX',
'USER_LOGGED',
'USR_USERNAME',
'APP_NUMBER',
'GLPI_.*',
'SYS_.*'
];
$process = new PluginProcessmakerProcess;
$process->getFromDB($options['case']->fields['plugin_processmaker_processes_id']);
$taskcat_id = $process->fields['taskcategories_id'];
// get case variable values
$res = $PM_DB->query("SELECT APP_DATA, APP_TITLE, APP_DESCRIPTION FROM APPLICATION WHERE APP_NUMBER = ".$options['case']->fields['id']);
if ($res && $PM_DB->numrows($res) == 1) {
// get all the case variables from $PM_DB
$caserow = $PM_DB->fetchAssoc($res);
$case_variables = unserialize($caserow['APP_DATA']);
$excluded_re = '/^(' . implode('|', $excluded) . ')$/u';
foreach ($case_variables as $key => $val) {
if (!preg_match($excluded_re, $key)) {
if (is_array($val)) {
// add numberof for count of rows
$this->data["##array.numberof$key##"] = count($val);
// get the keys/vals of the sub-array
foreach ($val as $attribute => $row) {
if (is_array($row)) {
$index = isset($this->data["array.$key"]) ? count($this->data["array.$key"]) : 0;
foreach ($row as $col_name => $col_val) {
$this->data["array.$key"][$index]["##array.$key.$col_name##"] = $col_val;
$this->data["##lang.array.$key.$col_name##"] = $col_name;
}
} else {
$this->data["1darray.$key"]["##array.$key.$attribute##"] = $row;
$this->data["##lang.1darray.$key.$attribute##"] = $attribute;
}
}
} else {
$this->data["##var.$key##"] = $val;
$this->data["##lang.var.$key##"] = $key;
}
}
}
$this->data['##case.title##'] = $caserow['APP_TITLE'];
$this->data['##case.description##'] = $caserow['APP_DESCRIPTION'];
}
// case id
$this->data['##case.id##'] = $options['case']->fields['id'];
// case URL
$this->data['##case.url##'] = $this->formatURL($options['additionnaloption']['usertype'],
urlencode(urlencode($CFG_GLPI["url_base"] .
PluginProcessmakerCase::getFormURLWithID($options['case']->fields['id'], false))));
// parent task information: meta data on process
// will get parent of task which is the process task category
$tmp_taskcatinfo['name'] = DropdownTranslation::getTranslatedValue($taskcat_id, 'TaskCategory', 'name');
$tmp_taskcatinfo['comment'] = DropdownTranslation::getTranslatedValue($taskcat_id, 'TaskCategory', 'comment');
// process title
$this->data['##process.categoryid##'] = $taskcat_id;
$this->data['##process.category##'] = $tmp_taskcatinfo['name'];
$this->data['##process.categorycomment##'] = $tmp_taskcatinfo['comment'];
// add information about item that hosts the case
$item = new $options['case']->fields['itemtype'];
$item->getFromDB($options['case']->fields['items_id']);
$this->data['##item.type##'] = $item->getTypeName(1);
$this->data['##item.id##'] = sprintf("%07d", $options['case']->fields['items_id']); // to have items_id with 7 digits with leading 0
$this->data['##item.url##'] = $this->formatURL($options['additionnaloption']['usertype'],
urlencode(urlencode($CFG_GLPI["url_base"] .
$item::getFormURLWithID($options['case']->fields['items_id'], false))));
$this->data['##item.title##'] = HTML::entities_deep($item->fields['name']);
// add labels to tags that are not set
$this->getTags();
foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) {
if (!isset($this->data[$tag])) {
$this->data[$tag] = $values['label'];
}
}
}
/**
* Get header to add to content
**/
function getContentHeader() {
if ($this->getMode() == \Notification_NotificationTemplate::MODE_MAIL
&& MailCollector::countActiveCollectors()
&& $this->allowResponse()
) {
return NotificationTargetTicket::HEADERTAG.' '.__('To answer by email, write above this line').' '.
NotificationTargetTicket::HEADERTAG;
}
return '';
}
/**
* Get footer to add to content
**/
function getContentFooter() {
if ($this->getMode() == \Notification_NotificationTemplate::MODE_MAIL
&& MailCollector::countActiveCollectors()
&& $this->allowResponse()
) {
return NotificationTargetTicket::FOOTERTAG.' '.__('To answer by email, write under this line').' '.
NotificationTargetTicket::FOOTERTAG;
}
return '';
}
}