1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only |
4
|
|
|
* SPDX-FileCopyrightText: Copyright 2005-2016 Zarafa Deutschland GmbH |
5
|
|
|
* SPDX-FileCopyrightText: Copyright 2020-2022 grommunio GmbH |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
/* |
9
|
|
|
* In general |
10
|
|
|
* |
11
|
|
|
* This class never actually modifies a task item unless we receive a task request update. This means |
12
|
|
|
* that setting all the properties to make the task item itself behave like a task request is up to the |
13
|
|
|
* caller. |
14
|
|
|
* |
15
|
|
|
* The only exception to this is the generation of the TaskGlobalObjId, the unique identifier identifying |
16
|
|
|
* this task request to both the organizer and the assignee. The globalobjectid is generated when the |
17
|
|
|
* task request is sent via sendTaskRequest. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
/* The TaskMode value is only used for the IPM.TaskRequest items. |
21
|
|
|
* It must 0 (tdmtNothing) on IPM.Task items. |
22
|
|
|
* |
23
|
|
|
* It is used to indicate the type of change that is being |
24
|
|
|
* carried in the IPM.TaskRequest item (although this information seems |
25
|
|
|
* redundant due to that information already being available in PR_MESSAGE_CLASS). |
26
|
|
|
*/ |
27
|
|
|
define('tdmtNothing', 0); // Value in IPM.Task items |
28
|
|
|
define('tdmtTaskReq', 1); // Assigner -> Assignee |
29
|
|
|
define('tdmtTaskAcc', 2); // Assignee -> Assigner |
30
|
|
|
define('tdmtTaskDec', 3); // Assignee -> Assigner |
31
|
|
|
define('tdmtTaskUpd', 4); // Assignee -> Assigner |
32
|
|
|
define('tdmtTaskSELF', 5); // Assigner -> Assigner (?) |
33
|
|
|
|
34
|
|
|
/* The TaskHistory is used to show the last action on the task |
35
|
|
|
* on both the assigner and the assignee's side. |
36
|
|
|
* |
37
|
|
|
* It is used in combination with 'task_assigned_time' and 'tasklastdelegate' |
38
|
|
|
* or 'tasklastuser' to show the information at the top of the task request in |
39
|
|
|
* the format 'Accepted by <user> on 01-01-2010 11:00'. |
40
|
|
|
*/ |
41
|
|
|
define('thNone', 0); |
42
|
|
|
define('thAccepted', 1); // Set by assignee |
43
|
|
|
define('thDeclined', 2); // Set by assignee |
44
|
|
|
define('thUpdated', 3); // Set by assignee |
45
|
|
|
define('thDueDateChanged', 4); |
46
|
|
|
define('thAssigned', 5); // Set by assigner |
47
|
|
|
|
48
|
|
|
/* The TaskState value is used to differentiate the version of a task |
49
|
|
|
* in the assigner's folder and the version in the |
50
|
|
|
* assignee's folder. The buttons shown depend on this and |
51
|
|
|
* the 'taskaccepted' boolean (for the assignee) |
52
|
|
|
*/ |
53
|
|
|
define('tdsNOM', 0); // Got a response to a deleted task, and re-created the task for the assigner |
54
|
|
|
define('tdsOWNNEW', 1); // Not assigned |
55
|
|
|
define('tdsOWN', 2); // Assignee version |
56
|
|
|
define('tdsACC', 3); // Assigner version |
57
|
|
|
define('tdsDEC', 4); // Assigner version, but assignee declined |
58
|
|
|
|
59
|
|
|
/* The TaskAcceptanceState is used for the assigner to indicate state */ |
60
|
|
|
define('olTaskNotDelegated', 0); |
61
|
|
|
define('olTaskDelegationUnknown', 1); // After sending req |
62
|
|
|
define('olTaskDelegationAccepted', 2); // After receiving accept |
63
|
|
|
define('olTaskDelegationDeclined', 3); // After receiving decline |
64
|
|
|
|
65
|
|
|
/* The task ownership indicates the role of the current user relative to the task. */ |
66
|
|
|
define('olNewTask', 0); |
67
|
|
|
define('olDelegatedTask', 1); // Task has been assigned |
68
|
|
|
define('olOwnTask', 2); // Task owned |
69
|
|
|
|
70
|
|
|
/* taskmultrecips indicates whether the task request sent or received has multiple assignees or not. */ |
71
|
|
|
define('tmrNone', 0); |
72
|
|
|
define('tmrSent', 1); // Task has been sent to multiple assignee |
73
|
|
|
define('tmrReceived', 2); // Task Request received has multiple assignee |
74
|
|
|
|
75
|
|
|
// Task icon index. |
76
|
|
|
define('ICON_TASK_ASSIGNEE', 0x00000502); |
77
|
|
|
define('ICON_TASK_DECLINE', 0x00000506); |
78
|
|
|
define('ICON_TASK_ASSIGNER', 0x00000503); |
79
|
|
|
|
80
|
|
|
class TaskRequest { |
81
|
|
|
private $props; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @var resource |
85
|
|
|
*/ |
86
|
|
|
private $store; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @var resource |
90
|
|
|
*/ |
91
|
|
|
private $message; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @var resource |
95
|
|
|
*/ |
96
|
|
|
private $session; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @var string |
100
|
|
|
*/ |
101
|
|
|
private $taskCommentsInfo; |
102
|
|
|
|
103
|
|
|
// All recipient properties |
104
|
|
|
public $recipProps = [ |
105
|
|
|
PR_ENTRYID, |
106
|
|
|
PR_DISPLAY_NAME, |
|
|
|
|
107
|
|
|
PR_EMAIL_ADDRESS, |
|
|
|
|
108
|
|
|
PR_RECIPIENT_ENTRYID, |
|
|
|
|
109
|
|
|
PR_RECIPIENT_TYPE, |
|
|
|
|
110
|
|
|
PR_SEND_INTERNET_ENCODING, |
|
|
|
|
111
|
|
|
PR_SEND_RICH_INFO, |
|
|
|
|
112
|
|
|
PR_RECIPIENT_DISPLAY_NAME, |
|
|
|
|
113
|
|
|
PR_ADDRTYPE, |
|
|
|
|
114
|
|
|
PR_DISPLAY_TYPE, |
|
|
|
|
115
|
|
|
PR_RECIPIENT_TRACKSTATUS, |
|
|
|
|
116
|
|
|
PR_RECIPIENT_TRACKSTATUS_TIME, |
|
|
|
|
117
|
|
|
PR_RECIPIENT_FLAGS, |
|
|
|
|
118
|
|
|
PR_ROWID, |
|
|
|
|
119
|
|
|
PR_SEARCH_KEY, |
|
|
|
|
120
|
|
|
]; |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Constructor. |
124
|
|
|
* |
125
|
|
|
* Constructs a TaskRequest object for the specified message. This can be either the task request |
126
|
|
|
* message itself (in the inbox) or the task in the tasks folder, depending on the action to be performed. |
127
|
|
|
* |
128
|
|
|
* As a general rule, the object message passed is the object 'in view' when the user performs one of the |
129
|
|
|
* actions in this class. |
130
|
|
|
* |
131
|
|
|
* @param resource $store MAPI Store in which $message resides. This is also the store where the tasks folder is assumed to be in |
132
|
|
|
* @param resource $message MAPI Message to which the task request refers (can be an email or a task) |
133
|
|
|
* @param resource $session MAPI Session which is used to open tasks folders for delegated task requests or responses |
134
|
|
|
*/ |
135
|
|
|
public function __construct($store, $message, $session) { |
136
|
|
|
$this->store = $store; |
137
|
|
|
$this->message = $message; |
138
|
|
|
$this->session = $session; |
139
|
|
|
$this->taskCommentsInfo = ''; |
140
|
|
|
|
141
|
|
|
$properties = []; |
142
|
|
|
$properties["owner"] = "PT_STRING8:PSETID_Task:0x811f"; |
143
|
|
|
$properties["updatecount"] = "PT_LONG:PSETID_Task:0x8112"; |
144
|
|
|
$properties["taskstate"] = "PT_LONG:PSETID_Task:0x8113"; |
145
|
|
|
$properties["taskmultrecips"] = "PT_LONG:PSETID_Task:0x8120"; |
146
|
|
|
$properties["taskupdates"] = "PT_BOOLEAN:PSETID_Task:0x811b"; |
147
|
|
|
$properties["tasksoc"] = "PT_BOOLEAN:PSETID_Task:0x8119"; |
148
|
|
|
$properties["taskhistory"] = "PT_LONG:PSETID_Task:0x811a"; |
149
|
|
|
$properties["taskmode"] = "PT_LONG:PSETID_Common:0x8518"; |
150
|
|
|
$properties["task_goid"] = "PT_BINARY:PSETID_Common:0x8519"; |
151
|
|
|
$properties["complete"] = "PT_BOOLEAN:PSETID_Common:" . PidLidTaskComplete; |
|
|
|
|
152
|
|
|
$properties["task_assigned_time"] = "PT_SYSTIME:PSETID_Task:0x8115"; |
153
|
|
|
$properties["taskfcreator"] = "PT_BOOLEAN:PSETID_Task:0x0x811e"; |
154
|
|
|
$properties["tasklastuser"] = "PT_STRING8:PSETID_Task:0x8122"; |
155
|
|
|
$properties["tasklastdelegate"] = "PT_STRING8:PSETID_Task:0x8125"; |
156
|
|
|
$properties["taskaccepted"] = "PT_BOOLEAN:PSETID_Task:0x8108"; |
157
|
|
|
$properties["task_acceptance_state"] = "PT_LONG:PSETID_Task:0x812a"; |
158
|
|
|
$properties["ownership"] = "PT_LONG:PSETID_Task:0x8129"; |
159
|
|
|
|
160
|
|
|
$properties["complete"] = "PT_BOOLEAN:PSETID_Task:" . PidLidTaskComplete; |
161
|
|
|
$properties["datecompleted"] = "PT_SYSTIME:PSETID_Task:" . PidLidTaskDateCompleted; |
|
|
|
|
162
|
|
|
$properties["recurring"] = "PT_BOOLEAN:PSETID_Task:0x8126"; |
163
|
|
|
$properties["startdate"] = "PT_SYSTIME:PSETID_Task:" . PidLidTaskStartDate; |
|
|
|
|
164
|
|
|
$properties["duedate"] = "PT_SYSTIME:PSETID_Task:" . PidLidTaskDueDate; |
|
|
|
|
165
|
|
|
$properties["status"] = "PT_LONG:PSETID_Task:" . PidLidTaskStatus; |
|
|
|
|
166
|
|
|
$properties["percent_complete"] = "PT_DOUBLE:PSETID_Task:" . PidLidPercentComplete; |
|
|
|
|
167
|
|
|
$properties["totalwork"] = "PT_LONG:PSETID_Task:0x8111"; |
168
|
|
|
$properties["actualwork"] = "PT_LONG:PSETID_Task:0x8110"; |
169
|
|
|
$properties["categories"] = "PT_MV_STRING8:PS_PUBLIC_STRINGS:Keywords"; |
170
|
|
|
$properties["companies"] = "PT_MV_STRING8:PSETID_Common:0x8539"; |
171
|
|
|
$properties["mileage"] = "PT_STRING8:PSETID_Common:0x8534"; |
172
|
|
|
$properties["billinginformation"] = "PT_STRING8:PSETID_Common:0x8535"; |
173
|
|
|
|
174
|
|
|
$this->props = getPropIdsFromStrings($store, $properties); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
// General functions |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Returns TRUE if the message pointed to is an incoming task request and should |
181
|
|
|
* therefore be replied to with doAccept or doDecline(). |
182
|
|
|
* |
183
|
|
|
* @param mixed $messageClass message class to use for checking |
184
|
|
|
* |
185
|
|
|
* @return bool true if this is a task request else false |
186
|
|
|
*/ |
187
|
|
|
public function isTaskRequest($messageClass = false) { |
188
|
|
|
if ($messageClass === false) { |
189
|
|
|
$props = mapi_getprops($this->message, [PR_MESSAGE_CLASS]); |
|
|
|
|
190
|
|
|
$messageClass = isset($props[PR_MESSAGE_CLASS]) ? $props[PR_MESSAGE_CLASS] : false; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
if ($messageClass !== false && $messageClass === "IPM.TaskRequest") { |
194
|
|
|
return true; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
return false; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Returns TRUE if the message pointed to is a returning task request response. |
202
|
|
|
* |
203
|
|
|
* @param mixed $messageClass message class to use for checking |
204
|
|
|
* |
205
|
|
|
* @return bool true if this is a task request else false |
206
|
|
|
*/ |
207
|
|
|
public function isTaskRequestResponse($messageClass = false) { |
208
|
|
|
if ($messageClass === false) { |
209
|
|
|
$props = mapi_getprops($this->message, [PR_MESSAGE_CLASS]); |
|
|
|
|
210
|
|
|
$messageClass = isset($props[PR_MESSAGE_CLASS]) ? $props[PR_MESSAGE_CLASS] : false; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
if ($messageClass !== false && strpos($messageClass, "IPM.TaskRequest.") === 0) { |
214
|
|
|
return true; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
return false; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Returns TRUE if the message pointed to is an incoming task request/response. |
222
|
|
|
* |
223
|
|
|
* @param array $props The MAPI properties to check message is an incoming task request/response |
224
|
|
|
* |
225
|
|
|
* @return bool true if this is an incoming task request/response else false |
226
|
|
|
*/ |
227
|
|
|
public function isReceivedItem($props) { |
228
|
|
|
return isset($props[PR_MESSAGE_TO_ME]) ? $props[PR_MESSAGE_TO_ME] : false; |
|
|
|
|
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Gets the task associated with an IPM.TaskRequest message. |
233
|
|
|
* |
234
|
|
|
* If the task does not exist yet, it is created, using the attachment object in the |
235
|
|
|
* task request item. |
236
|
|
|
* |
237
|
|
|
* @param bool $create true - try create task in user's task folder if task does not exist |
238
|
|
|
* false - find the associated task in user's task folder |
239
|
|
|
* |
240
|
|
|
* @return bool|resource associated task of task request else false |
241
|
|
|
*/ |
242
|
|
|
public function getAssociatedTask($create) { |
243
|
|
|
$props = mapi_getprops($this->message, [PR_MESSAGE_CLASS, $this->props['task_goid']]); |
|
|
|
|
244
|
|
|
|
245
|
|
|
if ($props[PR_MESSAGE_CLASS] == "IPM.Task") { |
246
|
|
|
// Message itself is task, so return that |
247
|
|
|
return $this->message; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
$taskFolder = $this->getDefaultTasksFolder(); |
251
|
|
|
$goid = $props[$this->props['task_goid']]; |
252
|
|
|
|
253
|
|
|
// Find the task by looking for the task_goid |
254
|
|
|
$restriction = [ |
255
|
|
|
RES_PROPERTY, |
256
|
|
|
[ |
257
|
|
|
RELOP => RELOP_EQ, |
258
|
|
|
ULPROPTAG => $this->props['task_goid'], |
259
|
|
|
VALUE => $goid, |
260
|
|
|
], |
261
|
|
|
]; |
262
|
|
|
|
263
|
|
|
$contents = mapi_folder_getcontentstable($taskFolder); |
|
|
|
|
264
|
|
|
|
265
|
|
|
$rows = mapi_table_queryallrows($contents, [PR_ENTRYID], $restriction); |
|
|
|
|
266
|
|
|
|
267
|
|
|
if (empty($rows)) { |
268
|
|
|
// None found, create one if possible |
269
|
|
|
if (!$create) { |
270
|
|
|
return false; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
$task = mapi_folder_createmessage($taskFolder); |
|
|
|
|
274
|
|
|
|
275
|
|
|
$sub = $this->getEmbeddedTask(); |
276
|
|
|
mapi_copyto($sub, [], [$this->props['categories']], $task); |
|
|
|
|
277
|
|
|
|
278
|
|
|
$senderProps = [ |
279
|
|
|
PR_SENT_REPRESENTING_NAME, |
|
|
|
|
280
|
|
|
PR_SENT_REPRESENTING_EMAIL_ADDRESS, |
|
|
|
|
281
|
|
|
PR_SENT_REPRESENTING_ENTRYID, |
|
|
|
|
282
|
|
|
PR_SENT_REPRESENTING_ADDRTYPE, |
|
|
|
|
283
|
|
|
PR_SENT_REPRESENTING_SEARCH_KEY, |
|
|
|
|
284
|
|
|
PR_SENDER_NAME, |
|
|
|
|
285
|
|
|
PR_SENDER_EMAIL_ADDRESS, |
|
|
|
|
286
|
|
|
PR_SENDER_ENTRYID, |
|
|
|
|
287
|
|
|
PR_SENDER_ADDRTYPE, |
|
|
|
|
288
|
|
|
PR_SENDER_SEARCH_KEY, ]; |
|
|
|
|
289
|
|
|
|
290
|
|
|
// Copy sender information from the e-mail |
291
|
|
|
$props = mapi_getprops($this->message, $senderProps); |
292
|
|
|
$props[PR_MESSAGE_CLASS] = 'IPM.Task'; |
293
|
|
|
mapi_setprops($task, $props); |
|
|
|
|
294
|
|
|
} |
295
|
|
|
else { |
296
|
|
|
// If there are multiple, just use the first |
297
|
|
|
$entryid = $rows[0][PR_ENTRYID]; |
298
|
|
|
|
299
|
|
|
$store = $this->getTaskFolderStore(); |
300
|
|
|
$task = mapi_msgstore_openentry($store, $entryid); |
|
|
|
|
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
return $task; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Function which checks that if we have received a task request/response |
308
|
|
|
* for an already updated task in task folder. |
309
|
|
|
* |
310
|
|
|
* @return bool true if task request is updated later |
311
|
|
|
*/ |
312
|
|
|
public function isTaskRequestUpdated() { |
313
|
|
|
$props = mapi_getprops($this->message, [PR_MESSAGE_CLASS, $this->props['task_goid'], $this->props['updatecount']]); |
|
|
|
|
314
|
|
|
$result = false; |
315
|
|
|
$associatedTask = $this->getAssociatedTask(false); |
316
|
|
|
if ($this->isTaskRequest($props[PR_MESSAGE_CLASS])) { |
317
|
|
|
if ($associatedTask) { |
318
|
|
|
return true; |
319
|
|
|
} |
320
|
|
|
$folder = $this->getDefaultTasksFolder(); |
321
|
|
|
$goid = $props[$this->props['task_goid']]; |
322
|
|
|
|
323
|
|
|
// Find the task by looking for the task_goid |
324
|
|
|
$restriction = [ |
325
|
|
|
RES_PROPERTY, |
326
|
|
|
[ |
327
|
|
|
RELOP => RELOP_EQ, |
328
|
|
|
ULPROPTAG => $this->props['task_goid'], |
329
|
|
|
VALUE => $goid, |
330
|
|
|
], |
331
|
|
|
]; |
332
|
|
|
|
333
|
|
|
$table = mapi_folder_getcontentstable($folder, MAPI_DEFERRED_ERRORS | SHOW_SOFT_DELETES); |
|
|
|
|
334
|
|
|
$softDeletedItems = mapi_table_queryallrows($table, [PR_ENTRYID], $restriction); |
|
|
|
|
335
|
|
|
if (!empty($softDeletedItems)) { |
336
|
|
|
return true; |
337
|
|
|
} |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
if ($associatedTask !== false) { |
341
|
|
|
$taskItemProps = mapi_getprops($associatedTask, [$this->props['updatecount']]); |
342
|
|
|
/* |
343
|
|
|
* if(message_counter < task_counter) task object is newer then task response (task is updated) |
344
|
|
|
* if(message_counter >= task_counter) task is not updated, do normal processing |
345
|
|
|
*/ |
346
|
|
|
if (isset($taskItemProps[$this->props['updatecount']], $props[$this->props['updatecount']])) { |
347
|
|
|
if ($props[$this->props['updatecount']] < $taskItemProps[$this->props['updatecount']]) { |
348
|
|
|
$result = true; |
349
|
|
|
} |
350
|
|
|
} |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
return $result; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
// Organizer functions (called by the organizer) |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* Processes a task request response, which can be any of the following: |
360
|
|
|
* - Task accept (task history is marked as accepted) |
361
|
|
|
* - Task decline (task history is marked as declined) |
362
|
|
|
* - Task update (updates completion %, etc). |
363
|
|
|
* |
364
|
|
|
* @return true |
365
|
|
|
*/ |
366
|
|
|
public function processTaskResponse(): bool { |
367
|
|
|
$messageProps = mapi_getprops($this->message, [PR_PROCESSED, $this->props["taskupdates"], PR_MESSAGE_TO_ME]); |
|
|
|
|
368
|
|
|
if (isset($messageProps[PR_PROCESSED]) && $messageProps[PR_PROCESSED]) { |
369
|
|
|
return true; |
370
|
|
|
} |
371
|
|
|
mapi_setprops($this->message, [PR_PROCESSED => true]); |
|
|
|
|
372
|
|
|
mapi_savechanges($this->message); |
|
|
|
|
373
|
|
|
|
374
|
|
|
// Get the embedded task information. |
375
|
|
|
$sub = $this->getEmbeddedTask(); |
376
|
|
|
// OL saves the task related properties in the embedded message |
377
|
|
|
$subProps = mapi_getprops($sub, [$this->props["taskupdates"]]); |
378
|
|
|
|
379
|
|
|
// If task is updated in task folder then we don't need to process |
380
|
|
|
// old response |
381
|
|
|
if ($this->isTaskRequestUpdated()) { |
382
|
|
|
return true; |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
$isReceivedItem = $this->isReceivedItem($messageProps); |
386
|
|
|
|
387
|
|
|
$isCreateAssociatedTask = false; |
388
|
|
|
$isAllowUpdateAssociatedTask = $subProps[$this->props["taskupdates"]]; |
389
|
|
|
$props = mapi_getprops($this->message, [PR_MESSAGE_CLASS]); |
|
|
|
|
390
|
|
|
// Set correct taskmode and taskhistory depending on response type |
391
|
|
|
switch ($props[PR_MESSAGE_CLASS]) { |
392
|
|
|
case 'IPM.TaskRequest.Accept': |
393
|
|
|
$taskHistory = thAccepted; |
394
|
|
|
$taskState = $isReceivedItem ? tdsACC : tdsOWN; |
395
|
|
|
$taskOwner = $isReceivedItem ? olDelegatedTask : olOwnTask; |
396
|
|
|
$taskAcceptanceState = $isReceivedItem ? olTaskDelegationAccepted : olTaskNotDelegated; |
397
|
|
|
break; |
398
|
|
|
|
399
|
|
|
case 'IPM.TaskRequest.Decline': |
400
|
|
|
$isCreateAssociatedTask = $isReceivedItem; |
401
|
|
|
$isAllowUpdateAssociatedTask = $isReceivedItem; |
402
|
|
|
$taskHistory = thDeclined; |
403
|
|
|
$taskState = $isReceivedItem ? tdsDEC : tdsACC; |
404
|
|
|
$taskOwner = $isReceivedItem ? olOwnTask : olDelegatedTask; |
405
|
|
|
$taskAcceptanceState = $isReceivedItem ? olTaskDelegationDeclined : olTaskDelegationUnknown; |
406
|
|
|
break; |
407
|
|
|
|
408
|
|
|
case 'IPM.TaskRequest.Update': |
409
|
|
|
case 'IPM.TaskRequest.Complete': |
410
|
|
|
$taskHistory = thUpdated; |
411
|
|
|
$taskState = $isReceivedItem ? tdsACC : tdsOWN; |
412
|
|
|
$taskAcceptanceState = olTaskNotDelegated; |
413
|
|
|
$taskOwner = $isReceivedItem ? olDelegatedTask : olOwnTask; |
414
|
|
|
break; |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
$props = [ |
418
|
|
|
$this->props['taskhistory'] => $taskHistory, |
|
|
|
|
419
|
|
|
$this->props['taskstate'] => $taskState, |
|
|
|
|
420
|
|
|
$this->props['task_acceptance_state'] => $taskAcceptanceState, |
|
|
|
|
421
|
|
|
$this->props['ownership'] => $taskOwner, |
|
|
|
|
422
|
|
|
]; |
423
|
|
|
|
424
|
|
|
// Get the task for this response |
425
|
|
|
$task = $this->getAssociatedTask($isCreateAssociatedTask); |
426
|
|
|
if ($task && $isAllowUpdateAssociatedTask) { |
427
|
|
|
// To avoid duplication of attachments in associated task. we simple remove the |
428
|
|
|
// all attachments from associated task. |
429
|
|
|
$taskAttachTable = mapi_message_getattachmenttable($task); |
|
|
|
|
430
|
|
|
$taskAttachments = mapi_table_queryallrows($taskAttachTable, [PR_ATTACH_NUM]); |
|
|
|
|
431
|
|
|
foreach ($taskAttachments as $taskAttach) { |
432
|
|
|
mapi_message_deleteattach($task, $taskAttach[PR_ATTACH_NUM]); |
|
|
|
|
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
$ignoreProps = [ |
436
|
|
|
$this->props['taskstate'], |
437
|
|
|
$this->props['taskhistory'], |
438
|
|
|
$this->props['taskmode'], |
439
|
|
|
$this->props['taskfcreator'], |
440
|
|
|
]; |
441
|
|
|
// Ignore PR_ICON_INDEX when task request response |
442
|
|
|
// is not received item. |
443
|
|
|
if ($isReceivedItem === false) { |
444
|
|
|
$ignoreProps[] = PR_ICON_INDEX; |
|
|
|
|
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
// We copy all properties except taskstate, taskhistory, taskmode and taskfcreator properties |
448
|
|
|
// from $sub message to $task even also we copy all attachments from $sub to $task message. |
449
|
|
|
mapi_copyto($sub, [], $ignoreProps, $task); |
|
|
|
|
450
|
|
|
$senderProps = mapi_getprops($this->message, [ |
451
|
|
|
PR_SENDER_NAME, |
|
|
|
|
452
|
|
|
PR_SENDER_EMAIL_ADDRESS, |
|
|
|
|
453
|
|
|
PR_SENDER_ENTRYID, |
|
|
|
|
454
|
|
|
PR_SENDER_ADDRTYPE, |
|
|
|
|
455
|
|
|
PR_SENDER_SEARCH_KEY, |
|
|
|
|
456
|
|
|
PR_MESSAGE_DELIVERY_TIME, |
|
|
|
|
457
|
|
|
PR_SENT_REPRESENTING_NAME, |
|
|
|
|
458
|
|
|
PR_SENT_REPRESENTING_EMAIL_ADDRESS, |
|
|
|
|
459
|
|
|
PR_SENT_REPRESENTING_ADDRTYPE, |
|
|
|
|
460
|
|
|
PR_SENT_REPRESENTING_ENTRYID, |
|
|
|
|
461
|
|
|
PR_SENT_REPRESENTING_SEARCH_KEY, ]); |
|
|
|
|
462
|
|
|
|
463
|
|
|
mapi_setprops($task, $senderProps); |
464
|
|
|
|
465
|
|
|
// Update taskstate and task history (last action done by the assignee) |
466
|
|
|
mapi_setprops($task, $props); |
467
|
|
|
|
468
|
|
|
// Copy missing properties from embedded task |
469
|
|
|
$subProperties = $this->getSubProperties(); |
470
|
|
|
$subprops = mapi_getprops($sub, $subProperties); |
471
|
|
|
mapi_setprops($task, $subprops); |
472
|
|
|
|
473
|
|
|
mapi_savechanges($task); |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
mapi_setprops($this->message, $props); |
477
|
|
|
mapi_savechanges($this->message); |
478
|
|
|
|
479
|
|
|
if ($isReceivedItem) { |
480
|
|
|
$this->updateSentTaskRequest(); |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
return true; |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
/** |
487
|
|
|
* Update the sent task request in sent items folder. |
488
|
|
|
* |
489
|
|
|
* @return bool |
490
|
|
|
*/ |
491
|
|
|
public function updateSentTaskRequest() { |
492
|
|
|
$props = mapi_getprops($this->message, [ |
|
|
|
|
493
|
|
|
$this->props['taskhistory'], |
494
|
|
|
$this->props["taskstate"], |
495
|
|
|
$this->props["ownership"], |
496
|
|
|
$this->props['task_goid'], |
497
|
|
|
$this->props['task_acceptance_state'], |
498
|
|
|
$this->props["tasklastuser"], |
499
|
|
|
$this->props["tasklastdelegate"], ]); |
500
|
|
|
|
501
|
|
|
$store = $this->getDefaultStore(); |
502
|
|
|
$storeProps = mapi_getprops($store, [PR_IPM_SENTMAIL_ENTRYID]); |
|
|
|
|
503
|
|
|
|
504
|
|
|
$sentFolder = mapi_msgstore_openentry($store, $storeProps[PR_IPM_SENTMAIL_ENTRYID]); |
|
|
|
|
505
|
|
|
if (!$sentFolder) { |
506
|
|
|
return false; |
507
|
|
|
} |
508
|
|
|
|
509
|
|
|
// Find the task by looking for the task_goid |
510
|
|
|
$restriction = [ |
511
|
|
|
RES_PROPERTY, |
512
|
|
|
[ |
513
|
|
|
RELOP => RELOP_EQ, |
514
|
|
|
ULPROPTAG => $this->props['task_goid'], |
515
|
|
|
VALUE => $props[$this->props['task_goid']], |
516
|
|
|
], |
517
|
|
|
]; |
518
|
|
|
|
519
|
|
|
$contentsTable = mapi_folder_getcontentstable($sentFolder); |
|
|
|
|
520
|
|
|
|
521
|
|
|
$rows = mapi_table_queryallrows($contentsTable, [PR_ENTRYID], $restriction); |
|
|
|
|
522
|
|
|
|
523
|
|
|
if (!empty($rows)) { |
524
|
|
|
foreach ($rows as $row) { |
525
|
|
|
$sentTaskRequest = mapi_msgstore_openentry($store, $row[PR_ENTRYID]); |
526
|
|
|
mapi_setprops($sentTaskRequest, $props); |
|
|
|
|
527
|
|
|
mapi_setprops($sentTaskRequest, [PR_PROCESSED => true]); |
|
|
|
|
528
|
|
|
mapi_savechanges($sentTaskRequest); |
|
|
|
|
529
|
|
|
} |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
return true; |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
/** |
536
|
|
|
* Creates a new message in the current user's outbox and submits it. |
537
|
|
|
* |
538
|
|
|
* Takes the task passed in the constructor as the task to be sent; recipient should |
539
|
|
|
* be pre-existing. The task request will be sent to all recipients. |
540
|
|
|
* |
541
|
|
|
* @param string $prefix |
542
|
|
|
* |
543
|
|
|
* @return true |
544
|
|
|
*/ |
545
|
|
|
public function sendTaskRequest($prefix): bool { |
546
|
|
|
// Generate a TaskGlobalObjectId |
547
|
|
|
$taskid = $this->createTGOID(); |
548
|
|
|
$messageprops = mapi_getprops($this->message, [PR_SUBJECT]); |
|
|
|
|
549
|
|
|
|
550
|
|
|
// Set properties on Task Request |
551
|
|
|
mapi_setprops($this->message, [ |
|
|
|
|
552
|
|
|
$this->props['task_goid'] => $taskid, // our new task_goid |
553
|
|
|
$this->props['taskstate'] => tdsACC, // state for our outgoing request |
554
|
|
|
$this->props['taskmode'] => tdmtNothing, // we're not sending a change |
555
|
|
|
$this->props['updatecount'] => 2, // version 2 (no idea) |
556
|
|
|
$this->props['task_acceptance_state'] => olTaskDelegationUnknown, // no reply yet |
557
|
|
|
$this->props['ownership'] => olDelegatedTask, // Task has been assigned |
558
|
|
|
$this->props['taskhistory'] => thAssigned, // Task has been assigned |
559
|
|
|
PR_CONVERSATION_TOPIC => $messageprops[PR_SUBJECT], |
|
|
|
|
560
|
|
|
PR_ICON_INDEX => ICON_TASK_ASSIGNER, |
|
|
|
|
561
|
|
|
]); |
562
|
|
|
$this->setLastUser(); |
563
|
|
|
$this->setOwnerForAssignor(); |
564
|
|
|
mapi_savechanges($this->message); |
|
|
|
|
565
|
|
|
|
566
|
|
|
// Create outgoing task request message |
567
|
|
|
$outgoing = $this->createOutgoingMessage(); |
568
|
|
|
|
569
|
|
|
// No need to copy PR_ICON_INDEX and PR_SENT_* information in to outgoing message. |
570
|
|
|
$ignoreProps = [PR_ICON_INDEX, PR_SENT_REPRESENTING_NAME, PR_SENT_REPRESENTING_EMAIL_ADDRESS, PR_SENT_REPRESENTING_ADDRTYPE, PR_SENT_REPRESENTING_ENTRYID, PR_SENT_REPRESENTING_SEARCH_KEY]; |
|
|
|
|
571
|
|
|
mapi_copyto($this->message, [], $ignoreProps, $outgoing); |
|
|
|
|
572
|
|
|
|
573
|
|
|
// Make it a task request, and put it in sent items after it is sent |
574
|
|
|
mapi_setprops($outgoing, [ |
575
|
|
|
PR_MESSAGE_CLASS => "IPM.TaskRequest", // class is task request |
|
|
|
|
576
|
|
|
$this->props['taskstate'] => tdsOWN, // for the recipient he is the task owner |
577
|
|
|
$this->props['taskmode'] => tdmtTaskReq, // for the recipient it's a request |
578
|
|
|
$this->props['updatecount'] => 1, // version 2 is in the attachment |
579
|
|
|
PR_SUBJECT_PREFIX => $prefix, |
|
|
|
|
580
|
|
|
PR_SUBJECT => $prefix . $messageprops[PR_SUBJECT], |
581
|
|
|
]); |
582
|
|
|
|
583
|
|
|
$attach = mapi_message_createattach($outgoing); |
|
|
|
|
584
|
|
|
mapi_setprops($attach, [ |
585
|
|
|
PR_ATTACH_METHOD => ATTACH_EMBEDDED_MSG, |
|
|
|
|
586
|
|
|
PR_ATTACHMENT_HIDDEN => true, |
|
|
|
|
587
|
|
|
PR_DISPLAY_NAME => $messageprops[PR_SUBJECT], ]); |
|
|
|
|
588
|
|
|
|
589
|
|
|
$sub = mapi_attach_openproperty($attach, PR_ATTACH_DATA_OBJ, IID_IMessage, 0, MAPI_MODIFY | MAPI_CREATE); |
|
|
|
|
590
|
|
|
|
591
|
|
|
mapi_copyto($this->message, [], [], $sub); |
592
|
|
|
mapi_setprops($sub, [PR_MESSAGE_CLASS => 'IPM.Task']); |
593
|
|
|
|
594
|
|
|
mapi_savechanges($sub); |
595
|
|
|
|
596
|
|
|
mapi_savechanges($attach); |
597
|
|
|
|
598
|
|
|
mapi_savechanges($outgoing); |
599
|
|
|
mapi_message_submitmessage($outgoing); |
|
|
|
|
600
|
|
|
|
601
|
|
|
return true; |
602
|
|
|
} |
603
|
|
|
|
604
|
|
|
// Assignee functions (called by the assignee) |
605
|
|
|
|
606
|
|
|
/** |
607
|
|
|
* Updates task version counter. |
608
|
|
|
* |
609
|
|
|
* Must be called before each update to increase counter. |
610
|
|
|
*/ |
611
|
|
|
public function updateTaskRequest(): void { |
612
|
|
|
$messageprops = mapi_getprops($this->message, [$this->props['updatecount']]); |
|
|
|
|
613
|
|
|
|
614
|
|
|
if (isset($messageprops)) { |
615
|
|
|
++$messageprops[$this->props['updatecount']]; |
616
|
|
|
} |
617
|
|
|
else { |
618
|
|
|
$messageprops[$this->props['updatecount']] = 1; |
619
|
|
|
} |
620
|
|
|
|
621
|
|
|
mapi_setprops($this->message, $messageprops); |
|
|
|
|
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
/** |
625
|
|
|
* Processes a task request. |
626
|
|
|
* |
627
|
|
|
* Message passed should be an IPM.TaskRequest message. The task request is then processed to create |
628
|
|
|
* the task in the tasks folder if needed. |
629
|
|
|
* |
630
|
|
|
* @return bool |
631
|
|
|
*/ |
632
|
|
|
public function processTaskRequest() { |
633
|
|
|
if (!$this->isTaskRequest()) { |
634
|
|
|
return false; |
635
|
|
|
} |
636
|
|
|
$messageProps = mapi_getprops($this->message, [PR_PROCESSED, $this->props["taskupdates"], PR_MESSAGE_TO_ME]); |
|
|
|
|
637
|
|
|
if (isset($messageProps[PR_PROCESSED]) && $messageProps[PR_PROCESSED]) { |
638
|
|
|
return true; |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
// if task is updated in task folder then we don't need to process |
642
|
|
|
// old request. |
643
|
|
|
if ($this->isTaskRequestUpdated()) { |
644
|
|
|
return true; |
645
|
|
|
} |
646
|
|
|
|
647
|
|
|
$isReceivedItem = $this->isReceivedItem($messageProps); |
648
|
|
|
|
649
|
|
|
$props = []; |
650
|
|
|
$props[PR_PROCESSED] = true; |
651
|
|
|
$props[$this->props["taskstate"]] = $isReceivedItem ? tdsOWN : tdsACC; |
652
|
|
|
$props[$this->props["ownership"]] = $isReceivedItem ? olOwnTask : olDelegatedTask; |
653
|
|
|
|
654
|
|
|
mapi_setprops($this->message, $props); |
|
|
|
|
655
|
|
|
mapi_savechanges($this->message); |
|
|
|
|
656
|
|
|
|
657
|
|
|
// Don't create associated task in task folder if "taskupdates" is not true. |
658
|
|
|
if (!$isReceivedItem && !$messageProps[$this->props["taskupdates"]]) { |
659
|
|
|
return true; |
660
|
|
|
} |
661
|
|
|
// create an associated task in task folder while |
662
|
|
|
// reading/loading task request on client side. |
663
|
|
|
$task = $this->getAssociatedTask(true); |
664
|
|
|
|
665
|
|
|
$taskProps = mapi_getprops($task, [$this->props['taskmultrecips']]); |
666
|
|
|
$taskProps[$this->props["taskstate"]] = $isReceivedItem ? tdsOWN : tdsACC; |
667
|
|
|
$taskProps[$this->props["taskhistory"]] = thAssigned; |
668
|
|
|
$taskProps[$this->props["taskmode"]] = tdmtNothing; |
669
|
|
|
$taskProps[$this->props["taskaccepted"]] = false; |
670
|
|
|
$taskProps[$this->props["taskfcreator"]] = false; |
671
|
|
|
$taskProps[$this->props["ownership"]] = $isReceivedItem ? olOwnTask : olDelegatedTask; |
672
|
|
|
$taskProps[$this->props["task_acceptance_state"]] = olTaskNotDelegated; |
673
|
|
|
$taskProps[PR_ICON_INDEX] = ICON_TASK_ASSIGNEE; |
|
|
|
|
674
|
|
|
|
675
|
|
|
mapi_setprops($task, $taskProps); |
676
|
|
|
$this->setAssignorInRecipients($task); |
677
|
|
|
|
678
|
|
|
mapi_savechanges($task); |
679
|
|
|
|
680
|
|
|
return true; |
681
|
|
|
} |
682
|
|
|
|
683
|
|
|
/** |
684
|
|
|
* Accepts a task request and sends the response. |
685
|
|
|
* |
686
|
|
|
* Message passed should be an IPM.Task (eg the task from getAssociatedTask()) |
687
|
|
|
* |
688
|
|
|
* Copies the task to the user's task folder, sets it to accepted, and sends the acceptation |
689
|
|
|
* message back to the organizer. The caller is responsible for removing the message. |
690
|
|
|
* |
691
|
|
|
* @return array|false PR_ENTRYID, PR_STORE_ENTRYID and PR_PARENT_ENTRYID of the task |
692
|
|
|
*/ |
693
|
|
|
public function doAccept() { |
694
|
|
|
$prefix = _("Task Accepted:") . " "; |
695
|
|
|
$messageProps = mapi_getprops($this->message, [PR_MESSAGE_CLASS, $this->props['taskstate']]); |
|
|
|
|
696
|
|
|
|
697
|
|
|
if (!isset($messageProps[$this->props['taskstate']]) || $messageProps[$this->props['taskstate']] != tdsOWN) { |
698
|
|
|
// Can only accept assignee task |
699
|
|
|
return false; |
700
|
|
|
} |
701
|
|
|
|
702
|
|
|
$this->setLastUser(); |
703
|
|
|
$this->updateTaskRequest(); |
704
|
|
|
|
705
|
|
|
$props = [ |
706
|
|
|
$this->props['taskhistory'] => thAccepted, |
707
|
|
|
$this->props['task_assigned_time'] => time(), |
708
|
|
|
$this->props['taskaccepted'] => true, |
709
|
|
|
$this->props['task_acceptance_state'] => olTaskNotDelegated, ]; |
710
|
|
|
|
711
|
|
|
// Message is TaskRequest then update the associated task as well. |
712
|
|
|
if ($this->isTaskRequest($messageProps[PR_MESSAGE_CLASS])) { |
713
|
|
|
$task = $this->getAssociatedTask(false); |
714
|
|
|
if ($task) { |
715
|
|
|
mapi_setprops($task, $props); |
|
|
|
|
716
|
|
|
mapi_savechanges($task); |
|
|
|
|
717
|
|
|
} |
718
|
|
|
} |
719
|
|
|
|
720
|
|
|
// Set as accepted |
721
|
|
|
mapi_setprops($this->message, $props); |
722
|
|
|
|
723
|
|
|
// As we copy the all properties from received message we need to remove following |
724
|
|
|
// properties from accept response. |
725
|
|
|
mapi_deleteprops($this->message, [PR_MESSAGE_RECIP_ME, PR_MESSAGE_TO_ME, PR_MESSAGE_CC_ME, PR_PROCESSED]); |
|
|
|
|
726
|
|
|
|
727
|
|
|
mapi_savechanges($this->message); |
728
|
|
|
|
729
|
|
|
$this->sendResponse(tdmtTaskAcc, $prefix); |
730
|
|
|
|
731
|
|
|
return $this->deleteReceivedTR(); |
732
|
|
|
} |
733
|
|
|
|
734
|
|
|
/** |
735
|
|
|
* Declines a task request and sends the response. |
736
|
|
|
* |
737
|
|
|
* Passed message must be a task request message, ie isTaskRequest() must return TRUE. |
738
|
|
|
* |
739
|
|
|
* Sends the decline message back to the organizer. The caller is responsible for removing the message. |
740
|
|
|
* |
741
|
|
|
* @return array|false TRUE on success, FALSE on failure |
742
|
|
|
*/ |
743
|
|
|
public function doDecline() { |
744
|
|
|
$prefix = _("Task Declined:") . " "; |
745
|
|
|
$messageProps = mapi_getprops($this->message, [$this->props['taskstate']]); |
|
|
|
|
746
|
|
|
|
747
|
|
|
if (!isset($messageProps[$this->props['taskstate']]) || $messageProps[$this->props['taskstate']] != tdsOWN) { |
748
|
|
|
return false; // Can only decline assignee task |
749
|
|
|
} |
750
|
|
|
|
751
|
|
|
$this->setLastUser(); |
752
|
|
|
$this->updateTaskRequest(); |
753
|
|
|
|
754
|
|
|
// Set as declined |
755
|
|
|
mapi_setprops($this->message, [ |
|
|
|
|
756
|
|
|
$this->props['taskhistory'] => thDeclined, |
757
|
|
|
$this->props['task_acceptance_state'] => olTaskDelegationDeclined, |
758
|
|
|
]); |
759
|
|
|
mapi_deleteprops($this->message, [PR_MESSAGE_RECIP_ME, PR_MESSAGE_TO_ME, PR_MESSAGE_CC_ME, PR_PROCESSED]); |
|
|
|
|
760
|
|
|
mapi_savechanges($this->message); |
|
|
|
|
761
|
|
|
|
762
|
|
|
$this->sendResponse(tdmtTaskDec, $prefix); |
763
|
|
|
|
764
|
|
|
// Delete the associated task when task request is declined by the assignee. |
765
|
|
|
$task = $this->getAssociatedTask(false); |
766
|
|
|
if ($task) { |
767
|
|
|
$taskFolder = $this->getDefaultTasksFolder(); |
768
|
|
|
$props = mapi_getprops($task, [PR_ENTRYID]); |
769
|
|
|
mapi_folder_deletemessages($taskFolder, [$props[PR_ENTRYID]]); |
|
|
|
|
770
|
|
|
} |
771
|
|
|
|
772
|
|
|
return $this->deleteReceivedTR(); |
773
|
|
|
} |
774
|
|
|
|
775
|
|
|
/** |
776
|
|
|
* Sends an update of the task if requested, and sends the Status-On-Completion report if complete and requested. |
777
|
|
|
* |
778
|
|
|
* If no updates were requested from the organizer, this function does nothing. |
779
|
|
|
* |
780
|
|
|
* @return bool TRUE if the update succeeded, FALSE otherwise |
781
|
|
|
*/ |
782
|
|
|
public function doUpdate() { |
783
|
|
|
$messageProps = mapi_getprops($this->message, [$this->props['taskstate'], PR_SUBJECT]); |
|
|
|
|
784
|
|
|
|
785
|
|
|
if (!isset($messageProps[$this->props['taskstate']]) || $messageProps[$this->props['taskstate']] != tdsOWN) { |
786
|
|
|
return false; // Can only update assignee task |
787
|
|
|
} |
788
|
|
|
|
789
|
|
|
$this->setLastUser(); |
790
|
|
|
$this->updateTaskRequest(); |
791
|
|
|
|
792
|
|
|
// Set as updated |
793
|
|
|
mapi_setprops($this->message, [$this->props['taskhistory'] => thUpdated]); |
|
|
|
|
794
|
|
|
|
795
|
|
|
mapi_savechanges($this->message); |
|
|
|
|
796
|
|
|
|
797
|
|
|
$props = mapi_getprops($this->message, [$this->props['taskupdates'], $this->props['tasksoc'], $this->props['recurring'], $this->props['complete']]); |
798
|
|
|
if (!$props[$this->props['complete']] && $props[$this->props['taskupdates']] && !(isset($props[$this->props['recurring']]) && $props[$this->props['recurring']])) { |
799
|
|
|
$this->sendResponse(tdmtTaskUpd, _("Task Updated:") . " "); |
800
|
|
|
} |
801
|
|
|
elseif ($props[$this->props['complete']]) { |
802
|
|
|
$this->sendResponse(tdmtTaskUpd, _("Task Completed:") . " "); |
803
|
|
|
} |
804
|
|
|
|
805
|
|
|
return true; |
806
|
|
|
} |
807
|
|
|
|
808
|
|
|
/** |
809
|
|
|
* Gets the store associated with the task. |
810
|
|
|
* |
811
|
|
|
* Normally this will just open the store that the processed message is in. However, if the message is opened |
812
|
|
|
* by a delegate, this function opens the store that the message was delegated from. |
813
|
|
|
*/ |
814
|
|
|
public function getTaskFolderStore() { |
815
|
|
|
$ownerentryid = false; |
816
|
|
|
|
817
|
|
|
$rcvdprops = mapi_getprops($this->message, [PR_RCVD_REPRESENTING_ENTRYID]); |
|
|
|
|
818
|
|
|
if (isset($rcvdprops[PR_RCVD_REPRESENTING_ENTRYID])) { |
819
|
|
|
$ownerentryid = $rcvdprops[PR_RCVD_REPRESENTING_ENTRYID]; |
820
|
|
|
} |
821
|
|
|
|
822
|
|
|
if (!$ownerentryid) { |
823
|
|
|
$store = $this->store; |
824
|
|
|
} |
825
|
|
|
else { |
826
|
|
|
$ab = mapi_openaddressbook($this->session); |
|
|
|
|
827
|
|
|
if (!$ab) { |
828
|
|
|
return false; |
829
|
|
|
} |
830
|
|
|
|
831
|
|
|
$mailuser = mapi_ab_openentry($ab, $ownerentryid); |
|
|
|
|
832
|
|
|
if (!$mailuser) { |
833
|
|
|
return false; |
834
|
|
|
} |
835
|
|
|
|
836
|
|
|
$mailuserprops = mapi_getprops($mailuser, [PR_EMAIL_ADDRESS]); |
|
|
|
|
837
|
|
|
if (!isset($mailuserprops[PR_EMAIL_ADDRESS])) { |
838
|
|
|
return false; |
839
|
|
|
} |
840
|
|
|
|
841
|
|
|
$storeid = mapi_msgstore_createentryid($this->store, $mailuserprops[PR_EMAIL_ADDRESS]); |
|
|
|
|
842
|
|
|
|
843
|
|
|
$store = mapi_openmsgstore($this->session, $storeid); |
|
|
|
|
844
|
|
|
} |
845
|
|
|
|
846
|
|
|
return $store; |
847
|
|
|
} |
848
|
|
|
|
849
|
|
|
/** |
850
|
|
|
* Opens the default task folder for the current user, or the specified user if passed. |
851
|
|
|
*/ |
852
|
|
|
public function getDefaultTasksFolder() { |
853
|
|
|
$store = $this->getTaskFolderStore(); |
854
|
|
|
|
855
|
|
|
$inbox = mapi_msgstore_getreceivefolder($store); |
|
|
|
|
856
|
|
|
$inboxprops = mapi_getprops($inbox, [PR_IPM_TASK_ENTRYID]); |
|
|
|
|
857
|
|
|
if (!isset($inboxprops[PR_IPM_TASK_ENTRYID])) { |
858
|
|
|
return false; |
859
|
|
|
} |
860
|
|
|
|
861
|
|
|
return mapi_msgstore_openentry($store, $inboxprops[PR_IPM_TASK_ENTRYID]); |
|
|
|
|
862
|
|
|
} |
863
|
|
|
|
864
|
|
|
/** |
865
|
|
|
* Prepares the sent representing properties from given MAPI store. |
866
|
|
|
* |
867
|
|
|
* @param mixed $store MAPI store object |
868
|
|
|
* |
869
|
|
|
* @return array[][][][][]|false if store is not mail box owner entryid then return false else prepare the sent representing props and return it |
870
|
|
|
* |
871
|
|
|
* @psalm-return array<array<array<array<array<array<never, never>>>>>>|false |
872
|
|
|
*/ |
873
|
|
|
public function getSentReprProps($store) { |
874
|
|
|
$storeprops = mapi_getprops($store, [PR_MAILBOX_OWNER_ENTRYID]); |
|
|
|
|
875
|
|
|
if (!isset($storeprops[PR_MAILBOX_OWNER_ENTRYID])) { |
876
|
|
|
return false; |
877
|
|
|
} |
878
|
|
|
|
879
|
|
|
$ab = mapi_openaddressbook($this->session); |
|
|
|
|
880
|
|
|
$mailuser = mapi_ab_openentry($ab, $storeprops[PR_MAILBOX_OWNER_ENTRYID]); |
|
|
|
|
881
|
|
|
$mailuserprops = mapi_getprops($mailuser, [PR_ADDRTYPE, PR_EMAIL_ADDRESS, PR_DISPLAY_NAME, PR_SEARCH_KEY, PR_ENTRYID]); |
|
|
|
|
882
|
|
|
|
883
|
|
|
$props = []; |
884
|
|
|
$props[PR_SENT_REPRESENTING_ADDRTYPE] = $mailuserprops[PR_ADDRTYPE]; |
|
|
|
|
885
|
|
|
$props[PR_SENT_REPRESENTING_EMAIL_ADDRESS] = $mailuserprops[PR_EMAIL_ADDRESS]; |
|
|
|
|
886
|
|
|
$props[PR_SENT_REPRESENTING_NAME] = $mailuserprops[PR_DISPLAY_NAME]; |
|
|
|
|
887
|
|
|
$props[PR_SENT_REPRESENTING_SEARCH_KEY] = $mailuserprops[PR_SEARCH_KEY]; |
|
|
|
|
888
|
|
|
$props[PR_SENT_REPRESENTING_ENTRYID] = $mailuserprops[PR_ENTRYID]; |
|
|
|
|
889
|
|
|
|
890
|
|
|
return $props; |
891
|
|
|
} |
892
|
|
|
|
893
|
|
|
/** |
894
|
|
|
* Creates an outgoing message based on the passed message - will set delegate information |
895
|
|
|
* and sent mail folder. |
896
|
|
|
*/ |
897
|
|
|
public function createOutgoingMessage() { |
898
|
|
|
// Open our default store for this user (that's the only store we can submit in) |
899
|
|
|
$store = $this->getDefaultStore(); |
900
|
|
|
$storeprops = mapi_getprops($store, [PR_IPM_OUTBOX_ENTRYID, PR_IPM_SENTMAIL_ENTRYID]); |
|
|
|
|
901
|
|
|
|
902
|
|
|
$outbox = mapi_msgstore_openentry($store, $storeprops[PR_IPM_OUTBOX_ENTRYID]); |
|
|
|
|
903
|
|
|
if (!$outbox) { |
904
|
|
|
return false; |
905
|
|
|
} |
906
|
|
|
|
907
|
|
|
$outgoing = mapi_folder_createmessage($outbox); |
|
|
|
|
908
|
|
|
if (!$outgoing) { |
909
|
|
|
return false; |
910
|
|
|
} |
911
|
|
|
|
912
|
|
|
// Set SENT_REPRESENTING in case we're sending as a delegate |
913
|
|
|
$ownerstore = $this->getTaskFolderStore(); |
914
|
|
|
$sentreprprops = $this->getSentReprProps($ownerstore); |
915
|
|
|
mapi_setprops($outgoing, $sentreprprops); |
|
|
|
|
916
|
|
|
|
917
|
|
|
mapi_setprops($outgoing, [PR_SENTMAIL_ENTRYID => $storeprops[PR_IPM_SENTMAIL_ENTRYID]]); |
|
|
|
|
918
|
|
|
|
919
|
|
|
return $outgoing; |
920
|
|
|
} |
921
|
|
|
|
922
|
|
|
/** |
923
|
|
|
* Sends a response message (from assignee back to organizer). |
924
|
|
|
* |
925
|
|
|
* @param int $type Type of response (tdmtTaskAcc, tdmtTaskDec, tdmtTaskUpd) |
926
|
|
|
* @param mixed $prefix |
927
|
|
|
* |
928
|
|
|
* @return bool TRUE on success |
929
|
|
|
*/ |
930
|
|
|
public function sendResponse($type, $prefix) { |
931
|
|
|
// Create a message in our outbox |
932
|
|
|
$outgoing = $this->createOutgoingMessage(); |
933
|
|
|
$messageprops = mapi_getprops($this->message, [PR_CONVERSATION_TOPIC, PR_MESSAGE_CLASS, $this->props['complete']]); |
|
|
|
|
934
|
|
|
|
935
|
|
|
$attach = mapi_message_createattach($outgoing); |
|
|
|
|
936
|
|
|
mapi_setprops($attach, [PR_ATTACH_METHOD => ATTACH_EMBEDDED_MSG, PR_DISPLAY_NAME => $messageprops[PR_CONVERSATION_TOPIC], PR_ATTACHMENT_HIDDEN => true]); |
|
|
|
|
937
|
|
|
$sub = mapi_attach_openproperty($attach, PR_ATTACH_DATA_OBJ, IID_IMessage, 0, MAPI_CREATE | MAPI_MODIFY); |
|
|
|
|
938
|
|
|
|
939
|
|
|
$message = !$this->isTaskRequest() ? $this->message : $this->getAssociatedTask(false); |
940
|
|
|
|
941
|
|
|
$ignoreProps = [PR_ICON_INDEX, $this->props["categories"], PR_SENT_REPRESENTING_NAME, PR_SENT_REPRESENTING_EMAIL_ADDRESS, PR_SENT_REPRESENTING_ADDRTYPE, PR_SENT_REPRESENTING_ENTRYID, PR_SENT_REPRESENTING_SEARCH_KEY]; |
|
|
|
|
942
|
|
|
|
943
|
|
|
mapi_copyto($message, [], $ignoreProps, $outgoing); |
|
|
|
|
944
|
|
|
mapi_copyto($message, [], [], $sub); |
945
|
|
|
|
946
|
|
|
if (!$this->setRecipientsForResponse($outgoing, $type)) { |
947
|
|
|
return false; |
948
|
|
|
} |
949
|
|
|
|
950
|
|
|
$props = []; |
951
|
|
|
|
952
|
|
|
switch ($type) { |
953
|
|
|
case tdmtTaskAcc: |
954
|
|
|
$props[PR_MESSAGE_CLASS] = "IPM.TaskRequest.Accept"; |
955
|
|
|
mapi_setprops($sub, [PR_ICON_INDEX => ICON_TASK_ASSIGNER]); |
956
|
|
|
break; |
957
|
|
|
|
958
|
|
|
case tdmtTaskDec: |
959
|
|
|
$props[PR_MESSAGE_CLASS] = "IPM.TaskRequest.Decline"; |
960
|
|
|
mapi_setprops($sub, [PR_ICON_INDEX => ICON_TASK_DECLINE]); |
961
|
|
|
break; |
962
|
|
|
|
963
|
|
|
case tdmtTaskUpd: |
964
|
|
|
mapi_setprops($sub, [PR_ICON_INDEX => ICON_TASK_ASSIGNER]); |
965
|
|
|
if ($messageprops[$this->props['complete']]) { |
966
|
|
|
$props[PR_MESSAGE_CLASS] = "IPM.TaskRequest.Complete"; |
967
|
|
|
} |
968
|
|
|
else { |
969
|
|
|
$props[PR_MESSAGE_CLASS] = "IPM.TaskRequest.Update"; |
970
|
|
|
} |
971
|
|
|
|
972
|
|
|
break; |
973
|
|
|
} |
974
|
|
|
|
975
|
|
|
mapi_savechanges($sub); |
|
|
|
|
976
|
|
|
mapi_savechanges($attach); |
977
|
|
|
|
978
|
|
|
$props[PR_SUBJECT] = $prefix . $messageprops[PR_CONVERSATION_TOPIC]; |
|
|
|
|
979
|
|
|
$props[$this->props['taskmode']] = $type; |
980
|
|
|
$props[$this->props['task_assigned_time']] = time(); |
981
|
|
|
|
982
|
|
|
mapi_setprops($outgoing, $props); |
983
|
|
|
|
984
|
|
|
// taskCommentsInfo contains some comments which added by assignee while |
985
|
|
|
// edit response before sending task response. |
986
|
|
|
if ($this->taskCommentsInfo != '') { |
987
|
|
|
$comments = $this->getTaskCommentsInfo(); |
988
|
|
|
$stream = mapi_openproperty($outgoing, PR_BODY, IID_IStream, STGM_TRANSACTED, MAPI_CREATE | MAPI_MODIFY); |
|
|
|
|
989
|
|
|
mapi_stream_setsize($stream, strlen($comments)); |
|
|
|
|
990
|
|
|
mapi_stream_write($stream, $comments); |
|
|
|
|
991
|
|
|
mapi_stream_commit($stream); |
|
|
|
|
992
|
|
|
} |
993
|
|
|
|
994
|
|
|
mapi_savechanges($outgoing); |
995
|
|
|
mapi_message_submitmessage($outgoing); |
|
|
|
|
996
|
|
|
|
997
|
|
|
return true; |
998
|
|
|
} |
999
|
|
|
|
1000
|
|
|
public function getDefaultStore() { |
1001
|
|
|
$table = mapi_getmsgstorestable($this->session); |
|
|
|
|
1002
|
|
|
$rows = mapi_table_queryallrows($table, [PR_DEFAULT_STORE, PR_ENTRYID]); |
|
|
|
|
1003
|
|
|
|
1004
|
|
|
foreach ($rows as $row) { |
1005
|
|
|
if ($row[PR_DEFAULT_STORE]) { |
1006
|
|
|
return mapi_openmsgstore($this->session, $row[PR_ENTRYID]); |
|
|
|
|
1007
|
|
|
} |
1008
|
|
|
} |
1009
|
|
|
|
1010
|
|
|
return false; |
1011
|
|
|
} |
1012
|
|
|
|
1013
|
|
|
/** |
1014
|
|
|
* Creates a new TaskGlobalObjId. |
1015
|
|
|
* |
1016
|
|
|
* Just 16 bytes of random data |
1017
|
|
|
*/ |
1018
|
|
|
public function createTGOID(): string { |
1019
|
|
|
$goid = ""; |
1020
|
|
|
for ($i = 0; $i < 16; ++$i) { |
1021
|
|
|
$goid .= chr(rand(0, 255)); |
1022
|
|
|
} |
1023
|
|
|
|
1024
|
|
|
return $goid; |
1025
|
|
|
} |
1026
|
|
|
|
1027
|
|
|
/** |
1028
|
|
|
* Gets the embedded task of task request. Further used to |
1029
|
|
|
* create/update associated task of assigner/assignee. |
1030
|
|
|
* |
1031
|
|
|
* @return bool|resource embedded task if found else false |
1032
|
|
|
*/ |
1033
|
|
|
public function getEmbeddedTask() { |
1034
|
|
|
$task = false; |
1035
|
|
|
$goid = mapi_getprops($this->message, [$this->props["task_goid"]]); |
|
|
|
|
1036
|
|
|
$attachmentTable = mapi_message_getattachmenttable($this->message); |
|
|
|
|
1037
|
|
|
$restriction = [RES_PROPERTY, |
1038
|
|
|
[RELOP => RELOP_EQ, |
1039
|
|
|
ULPROPTAG => PR_ATTACH_METHOD, |
|
|
|
|
1040
|
|
|
VALUE => ATTACH_EMBEDDED_MSG, ], |
1041
|
|
|
]; |
1042
|
|
|
$rows = mapi_table_queryallrows($attachmentTable, [PR_ATTACH_NUM], $restriction); |
|
|
|
|
1043
|
|
|
|
1044
|
|
|
if (empty($rows)) { |
1045
|
|
|
return $task; |
1046
|
|
|
} |
1047
|
|
|
|
1048
|
|
|
foreach ($rows as $row) { |
1049
|
|
|
try { |
1050
|
|
|
$attach = mapi_message_openattach($this->message, $row[PR_ATTACH_NUM]); |
|
|
|
|
1051
|
|
|
$task = mapi_attach_openobj($attach); |
|
|
|
|
1052
|
|
|
} |
1053
|
|
|
catch (MAPIException $e) { |
1054
|
|
|
continue; |
1055
|
|
|
} |
1056
|
|
|
|
1057
|
|
|
$taskGoid = mapi_getprops($task, [$this->props["task_goid"]]); |
1058
|
|
|
if ($goid[$this->props["task_goid"]] === $taskGoid[$this->props["task_goid"]]) { |
1059
|
|
|
mapi_setprops($attach, [PR_ATTACHMENT_HIDDEN => true]); |
|
|
|
|
1060
|
|
|
mapi_savechanges($attach); |
|
|
|
|
1061
|
|
|
mapi_savechanges($this->message); |
1062
|
|
|
break; |
1063
|
|
|
} |
1064
|
|
|
} |
1065
|
|
|
|
1066
|
|
|
return $task; |
1067
|
|
|
} |
1068
|
|
|
|
1069
|
|
|
/** |
1070
|
|
|
* Sets the user name who has last used this task. Update the |
1071
|
|
|
* tasklastdelegate and task_assigned_time. |
1072
|
|
|
*/ |
1073
|
|
|
public function setLastUser(): void { |
1074
|
|
|
$delegatestore = $this->getDefaultStore(); |
1075
|
|
|
$taskstore = $this->getTaskFolderStore(); |
1076
|
|
|
|
1077
|
|
|
$delegateprops = mapi_getprops($delegatestore, [PR_MAILBOX_OWNER_NAME]); |
|
|
|
|
1078
|
|
|
$taskprops = mapi_getprops($taskstore, [PR_MAILBOX_OWNER_NAME]); |
1079
|
|
|
|
1080
|
|
|
// The owner of the task |
1081
|
|
|
$username = $delegateprops[PR_MAILBOX_OWNER_NAME]; |
1082
|
|
|
// This is me (the one calling the script) |
1083
|
|
|
$delegate = $taskprops[PR_MAILBOX_OWNER_NAME]; |
1084
|
|
|
|
1085
|
|
|
if ($this->isTaskRequest()) { |
1086
|
|
|
$task = $this->getAssociatedTask(false); |
1087
|
|
|
mapi_setprops($task, [ |
|
|
|
|
1088
|
|
|
$this->props["tasklastuser"] => $username, |
1089
|
|
|
$this->props["tasklastdelegate"] => $delegate, |
1090
|
|
|
$this->props['task_assigned_time'] => time(), |
1091
|
|
|
]); |
1092
|
|
|
mapi_savechanges($task); |
|
|
|
|
1093
|
|
|
} |
1094
|
|
|
mapi_setprops($this->message, [ |
1095
|
|
|
$this->props["tasklastuser"] => $username, |
1096
|
|
|
$this->props["tasklastdelegate"] => $delegate, |
1097
|
|
|
$this->props['task_assigned_time'] => time(), |
1098
|
|
|
]); |
1099
|
|
|
} |
1100
|
|
|
|
1101
|
|
|
/** |
1102
|
|
|
* Sets assignee as owner in the assignor's copy of task. |
1103
|
|
|
* Assignee becomes the owner when a user/assignor assigns any task to someone. |
1104
|
|
|
* There can be more than one assignee. |
1105
|
|
|
*/ |
1106
|
|
|
public function setOwnerForAssignor(): void { |
1107
|
|
|
$recipTable = mapi_message_getrecipienttable($this->message); |
|
|
|
|
1108
|
|
|
$recips = mapi_table_queryallrows($recipTable, [PR_DISPLAY_NAME]); |
|
|
|
|
1109
|
|
|
|
1110
|
|
|
if (!empty($recips)) { |
1111
|
|
|
$owner = []; |
1112
|
|
|
foreach ($recips as $value) { |
1113
|
|
|
$owner[] = $value[PR_DISPLAY_NAME]; |
1114
|
|
|
} |
1115
|
|
|
|
1116
|
|
|
$props = [$this->props['owner'] => implode("; ", $owner)]; |
1117
|
|
|
mapi_setprops($this->message, $props); |
|
|
|
|
1118
|
|
|
} |
1119
|
|
|
} |
1120
|
|
|
|
1121
|
|
|
/** |
1122
|
|
|
* Sets assignor as recipients in assignee's copy of task. |
1123
|
|
|
* |
1124
|
|
|
* If assignor has requested task updates then the assignor is added as recipient type MAPI_CC. |
1125
|
|
|
* |
1126
|
|
|
* Also if assignor has request SOC then the assignor is also add as recipient type MAPI_BCC |
1127
|
|
|
* |
1128
|
|
|
* @param mixed $task assignee's copy of task |
1129
|
|
|
*/ |
1130
|
|
|
public function setAssignorInRecipients($task): void { |
1131
|
|
|
$recipTable = mapi_message_getrecipienttable($task); |
|
|
|
|
1132
|
|
|
|
1133
|
|
|
// Delete all MAPI_TO recipients |
1134
|
|
|
$recips = mapi_table_queryallrows($recipTable, [PR_ROWID], [ |
|
|
|
|
1135
|
|
|
RES_PROPERTY, |
1136
|
|
|
[ |
1137
|
|
|
RELOP => RELOP_EQ, |
1138
|
|
|
ULPROPTAG => PR_RECIPIENT_TYPE, |
|
|
|
|
1139
|
|
|
VALUE => MAPI_TO, |
1140
|
|
|
], |
1141
|
|
|
]); |
1142
|
|
|
foreach ($recips as $recip) { |
1143
|
|
|
mapi_message_modifyrecipients($task, MODRECIP_REMOVE, [$recip]); |
|
|
|
|
1144
|
|
|
} |
1145
|
|
|
|
1146
|
|
|
$recips = []; |
1147
|
|
|
$taskReqProps = mapi_getprops($this->message, [ |
|
|
|
|
1148
|
|
|
PR_SENT_REPRESENTING_NAME, |
|
|
|
|
1149
|
|
|
PR_SENT_REPRESENTING_EMAIL_ADDRESS, |
|
|
|
|
1150
|
|
|
PR_SENT_REPRESENTING_ENTRYID, |
|
|
|
|
1151
|
|
|
PR_SENT_REPRESENTING_ADDRTYPE, |
|
|
|
|
1152
|
|
|
PR_SENT_REPRESENTING_SEARCH_KEY, |
|
|
|
|
1153
|
|
|
]); |
1154
|
|
|
$associatedTaskProps = mapi_getprops($task, [ |
1155
|
|
|
$this->props['taskupdates'], |
1156
|
|
|
$this->props['tasksoc'], |
1157
|
|
|
$this->props['taskmultrecips'], |
1158
|
|
|
]); |
1159
|
|
|
|
1160
|
|
|
// Build assignor info |
1161
|
|
|
$assignor = [ |
1162
|
|
|
PR_ENTRYID => $taskReqProps[PR_SENT_REPRESENTING_ENTRYID], |
1163
|
|
|
PR_DISPLAY_NAME => $taskReqProps[PR_SENT_REPRESENTING_NAME], |
|
|
|
|
1164
|
|
|
PR_EMAIL_ADDRESS => $taskReqProps[PR_SENT_REPRESENTING_EMAIL_ADDRESS], |
|
|
|
|
1165
|
|
|
PR_RECIPIENT_DISPLAY_NAME => $taskReqProps[PR_SENT_REPRESENTING_NAME], |
|
|
|
|
1166
|
|
|
PR_ADDRTYPE => empty($taskReqProps[PR_SENT_REPRESENTING_ADDRTYPE]) ? 'SMTP' : $taskReqProps[PR_SENT_REPRESENTING_ADDRTYPE], |
|
|
|
|
1167
|
|
|
PR_RECIPIENT_FLAGS => recipSendable, |
|
|
|
|
1168
|
|
|
PR_SEARCH_KEY => $taskReqProps[PR_SENT_REPRESENTING_SEARCH_KEY], |
|
|
|
|
1169
|
|
|
]; |
1170
|
|
|
|
1171
|
|
|
// Assignor has requested task updates, so set him/her as MAPI_CC in recipienttable. |
1172
|
|
|
if ((isset($associatedTaskProps[$this->props['taskupdates']]) && $associatedTaskProps[$this->props['taskupdates']]) && |
1173
|
|
|
!(isset($associatedTaskProps[$this->props['taskmultrecips']]) && $associatedTaskProps[$this->props['taskmultrecips']] == tmrReceived)) { |
1174
|
|
|
$assignor[PR_RECIPIENT_TYPE] = MAPI_CC; |
1175
|
|
|
$recips[] = $assignor; |
1176
|
|
|
} |
1177
|
|
|
|
1178
|
|
|
// Assignor wants to receive an email report when task is mark as 'Complete', so in recipients as MAPI_BCC |
1179
|
|
|
if ($associatedTaskProps[$this->props['tasksoc']]) { |
1180
|
|
|
$assignor[PR_RECIPIENT_TYPE] = MAPI_BCC; |
1181
|
|
|
$recips[] = $assignor; |
1182
|
|
|
} |
1183
|
|
|
|
1184
|
|
|
if (!empty($recips)) { |
1185
|
|
|
mapi_message_modifyrecipients($task, MODRECIP_ADD, $recips); |
1186
|
|
|
} |
1187
|
|
|
} |
1188
|
|
|
|
1189
|
|
|
/** |
1190
|
|
|
* Deletes incoming task request from Inbox. |
1191
|
|
|
* |
1192
|
|
|
* @returns array|bool PR_ENTRYID, PR_STORE_ENTRYID and PR_PARENT_ENTRYID of the deleted task request |
1193
|
|
|
* |
1194
|
|
|
* @return array|false |
1195
|
|
|
*/ |
1196
|
|
|
public function deleteReceivedTR() { |
1197
|
|
|
$store = $this->getTaskFolderStore(); |
1198
|
|
|
$storeType = mapi_getprops($store, [PR_MDB_PROVIDER]); |
|
|
|
|
1199
|
|
|
if ($storeType[PR_MDB_PROVIDER] === ZARAFA_STORE_PUBLIC_GUID) { |
1200
|
|
|
$store = $this->getDefaultStore(); |
1201
|
|
|
} |
1202
|
|
|
$inbox = mapi_msgstore_getreceivefolder($store); |
|
|
|
|
1203
|
|
|
|
1204
|
|
|
$storeProps = mapi_getprops($store, [PR_IPM_WASTEBASKET_ENTRYID]); |
|
|
|
|
1205
|
|
|
$props = mapi_getprops($this->message, [$this->props['task_goid']]); |
1206
|
|
|
$goid = $props[$this->props['task_goid']]; |
1207
|
|
|
|
1208
|
|
|
// Find the task by looking for the task_goid |
1209
|
|
|
$restriction = [ |
1210
|
|
|
RES_PROPERTY, |
1211
|
|
|
[ |
1212
|
|
|
RELOP => RELOP_EQ, |
1213
|
|
|
ULPROPTAG => $this->props['task_goid'], |
1214
|
|
|
VALUE => $goid, |
1215
|
|
|
], |
1216
|
|
|
]; |
1217
|
|
|
|
1218
|
|
|
$contents = mapi_folder_getcontentstable($inbox); |
|
|
|
|
1219
|
|
|
|
1220
|
|
|
$rows = mapi_table_queryallrows($contents, [PR_ENTRYID, PR_PARENT_ENTRYID, PR_STORE_ENTRYID], $restriction); |
|
|
|
|
1221
|
|
|
|
1222
|
|
|
if (!empty($rows)) { |
1223
|
|
|
// If there are multiple, just use the first |
1224
|
|
|
$entryid = $rows[0][PR_ENTRYID]; |
1225
|
|
|
$wastebasket = mapi_msgstore_openentry($store, $storeProps[PR_IPM_WASTEBASKET_ENTRYID]); |
|
|
|
|
1226
|
|
|
mapi_folder_copymessages($inbox, [$entryid], $wastebasket, MESSAGE_MOVE); |
|
|
|
|
1227
|
|
|
|
1228
|
|
|
return [PR_ENTRYID => $entryid, PR_PARENT_ENTRYID => $rows[0][PR_PARENT_ENTRYID], PR_STORE_ENTRYID => $rows[0][PR_STORE_ENTRYID]]; |
1229
|
|
|
} |
1230
|
|
|
|
1231
|
|
|
return false; |
1232
|
|
|
} |
1233
|
|
|
|
1234
|
|
|
/** |
1235
|
|
|
* Sets recipients for the outgoing message according to type of the response. |
1236
|
|
|
* |
1237
|
|
|
* If it is a task update, then only recipient type MAPI_CC are taken from the task message. |
1238
|
|
|
* |
1239
|
|
|
* If it is accept/decline response, then PR_SENT_REPRESENTATING_XXXX are taken as recipient. |
1240
|
|
|
* |
1241
|
|
|
* @param mixed $outgoing outgoing mapi message |
1242
|
|
|
* @param int $responseType response type (tdmtTaskAcc, tdmtTaskDec, tdmtTaskUpd) |
1243
|
|
|
*/ |
1244
|
|
|
public function setRecipientsForResponse($outgoing, $responseType): bool { |
1245
|
|
|
// Clear recipients from outgoing msg |
1246
|
|
|
$this->deleteAllRecipients($outgoing); |
1247
|
|
|
|
1248
|
|
|
// If it is a task update then get MAPI_CC recipients which are assignors who has asked for task update. |
1249
|
|
|
if ($responseType == tdmtTaskUpd) { |
1250
|
|
|
$props = mapi_getprops($this->message, [$this->props['complete']]); |
|
|
|
|
1251
|
|
|
$isComplete = $props[$this->props['complete']]; |
1252
|
|
|
|
1253
|
|
|
$recipTable = mapi_message_getrecipienttable($this->message); |
|
|
|
|
1254
|
|
|
$recips = mapi_table_queryallrows($recipTable, $this->recipProps, [ |
|
|
|
|
1255
|
|
|
RES_PROPERTY, |
1256
|
|
|
[ |
1257
|
|
|
RELOP => RELOP_EQ, |
1258
|
|
|
ULPROPTAG => PR_RECIPIENT_TYPE, |
|
|
|
|
1259
|
|
|
VALUE => ($isComplete ? MAPI_BCC : MAPI_CC), |
1260
|
|
|
], |
1261
|
|
|
]); |
1262
|
|
|
|
1263
|
|
|
// No recipients found, return error |
1264
|
|
|
if (empty($recips)) { |
1265
|
|
|
return false; |
1266
|
|
|
} |
1267
|
|
|
|
1268
|
|
|
foreach ($recips as $recip) { |
1269
|
|
|
$recip[PR_RECIPIENT_TYPE] = MAPI_TO; // Change recipient type to MAPI_TO |
1270
|
|
|
mapi_message_modifyrecipients($outgoing, MODRECIP_ADD, [$recip]); |
|
|
|
|
1271
|
|
|
} |
1272
|
|
|
|
1273
|
|
|
return true; |
1274
|
|
|
} |
1275
|
|
|
|
1276
|
|
|
$orgprops = mapi_getprops($this->message, [ |
1277
|
|
|
PR_SENT_REPRESENTING_NAME, |
|
|
|
|
1278
|
|
|
PR_SENT_REPRESENTING_EMAIL_ADDRESS, |
|
|
|
|
1279
|
|
|
PR_SENT_REPRESENTING_ADDRTYPE, |
|
|
|
|
1280
|
|
|
PR_SENT_REPRESENTING_ENTRYID, |
|
|
|
|
1281
|
|
|
PR_SUBJECT, |
|
|
|
|
1282
|
|
|
]); |
1283
|
|
|
|
1284
|
|
|
$recip = [ |
1285
|
|
|
PR_DISPLAY_NAME => $orgprops[PR_SENT_REPRESENTING_NAME], |
|
|
|
|
1286
|
|
|
PR_EMAIL_ADDRESS => $orgprops[PR_SENT_REPRESENTING_EMAIL_ADDRESS], |
|
|
|
|
1287
|
|
|
PR_ADDRTYPE => $orgprops[PR_SENT_REPRESENTING_ADDRTYPE], |
|
|
|
|
1288
|
|
|
PR_ENTRYID => $orgprops[PR_SENT_REPRESENTING_ENTRYID], |
1289
|
|
|
PR_RECIPIENT_TYPE => MAPI_TO, ]; |
1290
|
|
|
|
1291
|
|
|
mapi_message_modifyrecipients($outgoing, MODRECIP_ADD, [$recip]); |
1292
|
|
|
|
1293
|
|
|
return true; |
1294
|
|
|
} |
1295
|
|
|
|
1296
|
|
|
/** |
1297
|
|
|
* Deletes all recipients from given message object. |
1298
|
|
|
* |
1299
|
|
|
* @param mixed $message MAPI message from which recipients are to be removed |
1300
|
|
|
*/ |
1301
|
|
|
public function deleteAllRecipients($message): void { |
1302
|
|
|
$recipTable = mapi_message_getrecipienttable($message); |
|
|
|
|
1303
|
|
|
$recipRows = mapi_table_queryallrows($recipTable, [PR_ROWID]); |
|
|
|
|
1304
|
|
|
|
1305
|
|
|
foreach ($recipRows as $recipient) { |
1306
|
|
|
mapi_message_modifyrecipients($message, MODRECIP_REMOVE, [$recipient]); |
|
|
|
|
1307
|
|
|
} |
1308
|
|
|
} |
1309
|
|
|
|
1310
|
|
|
/** |
1311
|
|
|
* Marks the record to complete and send complete update |
1312
|
|
|
* notification to assigner. |
1313
|
|
|
* |
1314
|
|
|
* @return bool TRUE if the update succeeded, FALSE otherwise |
1315
|
|
|
*/ |
1316
|
|
|
public function sendCompleteUpdate() { |
1317
|
|
|
$messageprops = mapi_getprops($this->message, [$this->props['taskstate']]); |
|
|
|
|
1318
|
|
|
|
1319
|
|
|
if (!isset($messageprops[$this->props['taskstate']]) || $messageprops[$this->props['taskstate']] != tdsOWN) { |
1320
|
|
|
return false; // Can only decline assignee task |
1321
|
|
|
} |
1322
|
|
|
|
1323
|
|
|
mapi_setprops($this->message, [ |
|
|
|
|
1324
|
|
|
$this->props['complete'] => true, |
1325
|
|
|
$this->props['datecompleted'] => time(), |
1326
|
|
|
$this->props['status'] => 2, |
1327
|
|
|
$this->props['percent_complete'] => 1, |
1328
|
|
|
]); |
1329
|
|
|
|
1330
|
|
|
return $this->doUpdate(); |
1331
|
|
|
} |
1332
|
|
|
|
1333
|
|
|
/** |
1334
|
|
|
* Returns extra info about task request comments along with message body |
1335
|
|
|
* which will be included in body while sending task request/response. |
1336
|
|
|
* |
1337
|
|
|
* @return string info about task request comments along with message body |
1338
|
|
|
*/ |
1339
|
|
|
public function getTaskCommentsInfo() { |
1340
|
|
|
return $this->taskCommentsInfo; |
1341
|
|
|
} |
1342
|
|
|
|
1343
|
|
|
/** |
1344
|
|
|
* Sets an extra info about task request comments along with message body |
1345
|
|
|
* which will be included in body while sending task request/response. |
1346
|
|
|
* |
1347
|
|
|
* @param string $taskCommentsInfo info about task request comments along with message body |
1348
|
|
|
*/ |
1349
|
|
|
public function setTaskCommentsInfo($taskCommentsInfo): void { |
1350
|
|
|
$this->taskCommentsInfo = $taskCommentsInfo; |
1351
|
|
|
} |
1352
|
|
|
|
1353
|
|
|
public function getSubProperties() { |
1354
|
|
|
$subProperties = []; |
1355
|
|
|
$subProperties["subject"] = PR_SUBJECT; |
|
|
|
|
1356
|
|
|
$subProperties["convtopic"] = PR_CONVERSATION_TOPIC; |
|
|
|
|
1357
|
|
|
$subProperties["complete"] = "PT_BOOLEAN:PSETID_Task:" . PidLidTaskComplete; |
|
|
|
|
1358
|
|
|
$subProperties["datecompleted"] = "PT_SYSTIME:PSETID_Task:" . PidLidTaskDateCompleted; |
|
|
|
|
1359
|
|
|
$subProperties["recurring"] = "PT_BOOLEAN:PSETID_Task:0x8126"; |
1360
|
|
|
$subProperties["startdate"] = "PT_SYSTIME:PSETID_Task:" . PidLidTaskStartDate; |
|
|
|
|
1361
|
|
|
$subProperties["duedate"] = "PT_SYSTIME:PSETID_Task:" . PidLidTaskDueDate; |
|
|
|
|
1362
|
|
|
$subProperties["status"] = "PT_LONG:PSETID_Task:" . PidLidTaskStatus; |
|
|
|
|
1363
|
|
|
$subProperties["percent_complete"] = "PT_DOUBLE:PSETID_Task:" . PidLidPercentComplete; |
|
|
|
|
1364
|
|
|
$subProperties["totalwork"] = "PT_LONG:PSETID_Task:0x8111"; |
1365
|
|
|
$subProperties["actualwork"] = "PT_LONG:PSETID_Task:0x8110"; |
1366
|
|
|
$subProperties["categories"] = "PT_MV_STRING8:PS_PUBLIC_STRINGS:Keywords"; |
1367
|
|
|
$subProperties["companies"] = "PT_MV_STRING8:PSETID_Common:0x8539"; |
1368
|
|
|
$subProperties["mileage"] = "PT_STRING8:PSETID_Common:0x8534"; |
1369
|
|
|
$subProperties["billinginformation"] = "PT_STRING8:PSETID_Common:0x8535"; |
1370
|
|
|
|
1371
|
|
|
return getPropIdsFromStrings($this->store, $subProperties); |
1372
|
|
|
} |
1373
|
|
|
} |
1374
|
|
|
|