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