1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Reminder ItemModule |
||
5 | * Module which saves an item and it |
||
6 | * extends the CreateMailItemModule class. |
||
7 | */ |
||
8 | class ReminderItemModule extends ItemModule { |
||
9 | /** |
||
10 | * Constructor. |
||
11 | * |
||
12 | * @param int $id unique id |
||
13 | * @param array $data list of all actions |
||
14 | */ |
||
15 | public function __construct($id, $data) { |
||
16 | parent::__construct($id, $data); |
||
17 | } |
||
18 | |||
19 | /** |
||
20 | * Function is use to set message flags for flagged mail item. |
||
21 | * |
||
22 | * @param object $store MAPI Message Store Object |
||
23 | * @param string $parententryid parent entryid of the message |
||
24 | * @param string $entryid entryid of the message |
||
25 | * @param array $action the action data, sent by the client |
||
26 | */ |
||
27 | #[Override] |
||
28 | public function save($store, $parententryid, $entryid, $action) { |
||
29 | $this->properties = $GLOBALS['properties']->getMailProperties(); |
||
30 | $result = false; |
||
31 | |||
32 | if (!$store) { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
33 | $store = $GLOBALS['mapisession']->getDefaultMessageStore(); |
||
34 | } |
||
35 | |||
36 | if ($store) { |
||
0 ignored issues
–
show
|
|||
37 | // Reference to an array which will be filled with PR_ENTRYID, PR_STORE_ENTRYID and PR_PARENT_ENTRYID of the message |
||
38 | $messageProps = []; |
||
39 | |||
40 | // Set message flags |
||
41 | if (isset($action['props'], $action['props']['message_flags']) && $entryid) { |
||
42 | $msg_action = $action['message_action'] ?? false; |
||
43 | $result = $GLOBALS['operations']->setMessageFlag($store, $entryid, $action['props']['message_flags'], $msg_action, $messageProps); |
||
44 | } |
||
45 | |||
46 | // Feedback for successful save |
||
47 | if ($result) { |
||
48 | $GLOBALS['bus']->notify(bin2hex($messageProps[PR_PARENT_ENTRYID]), TABLE_SAVE, $messageProps); |
||
49 | } |
||
50 | |||
51 | $this->sendFeedback($result ? true : false, [], true); |
||
52 | } |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Function which is use to dismiss or snooze the reminder item. |
||
57 | * |
||
58 | * @param object $store MAPI Message Store Object |
||
59 | * @param string $parententryid parent entryid of the message |
||
60 | * @param string $entryid entryid of the message |
||
61 | * @param array $action the action data, sent by the client |
||
62 | */ |
||
63 | #[Override] |
||
64 | public function delete($store, $parententryid, $entryid, $action) { |
||
65 | $this->properties = $GLOBALS["properties"]->getReminderProperties(); |
||
66 | |||
67 | if (!$store) { |
||
0 ignored issues
–
show
|
|||
68 | $store = $GLOBALS["mapisession"]->getDefaultMessageStore(); |
||
69 | } |
||
70 | |||
71 | $subActionType = false; |
||
72 | if (isset($action["message_action"], $action["message_action"]["action_type"])) { |
||
73 | $subActionType = $action["message_action"]["action_type"]; |
||
74 | } |
||
75 | |||
76 | switch ($subActionType) { |
||
77 | case "snooze": |
||
78 | $entryid = $this->getActionEntryID($action); |
||
79 | $this->snoozeItem($store, $entryid, $action); |
||
80 | break; |
||
81 | |||
82 | case "dismiss": |
||
83 | $entryid = $this->getActionEntryID($action); |
||
84 | $this->dismissItem($store, $entryid); |
||
85 | break; |
||
86 | |||
87 | default: |
||
88 | $this->handleUnknownActionType($subActionType); |
||
89 | } |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Function which is use to snooze the reminder for given time. |
||
94 | * |
||
95 | * @param object $store MAPI Message Store Object |
||
96 | * @param string $entryid entryid of the message |
||
97 | * @param array $action the action data, sent by the client |
||
98 | */ |
||
99 | public function snoozeItem($store, $entryid, $action) { |
||
100 | $result = false; |
||
101 | $message = mapi_msgstore_openentry($store, $entryid); |
||
102 | if ($message) { |
||
103 | $newProps = [PR_ENTRYID => $entryid]; |
||
104 | $props = mapi_getprops($message, $this->properties); |
||
105 | |||
106 | $snoozeTime = $GLOBALS["settings"]->get('zarafa/v1/main/reminder/default_snooze_time', 5); |
||
107 | if (isset($action["message_action"]["snoozeTime"]) && is_numeric($action["message_action"]["snoozeTime"])) { |
||
108 | $snoozeTime = $action["message_action"]["snoozeTime"]; |
||
109 | } |
||
110 | |||
111 | $reminderTime = time() + ($snoozeTime * 60); |
||
112 | if (stripos((string) $props[$this->properties["message_class"]], "IPM.Appointment") === 0) { |
||
113 | if (isset($props[$this->properties["appointment_recurring"]]) && $props[$this->properties["appointment_recurring"]]) { |
||
114 | $recurrence = new Recurrence($store, $message); |
||
0 ignored issues
–
show
The type
Recurrence was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
115 | $nextReminder = $recurrence->getNextReminderTime(time()); |
||
116 | |||
117 | // flagdueby must be the snooze time or the time of the next instance, whichever is earlier |
||
118 | if ($reminderTime < $nextReminder) { |
||
119 | $newProps[$this->properties["flagdueby"]] = $reminderTime; |
||
120 | } |
||
121 | else { |
||
122 | $newProps[$this->properties["flagdueby"]] = $nextReminder; |
||
123 | } |
||
124 | } |
||
125 | else { |
||
126 | $newProps[$this->properties["flagdueby"]] = $reminderTime; |
||
127 | } |
||
128 | } |
||
129 | else { |
||
130 | $newProps[$this->properties["flagdueby"]] = $reminderTime; |
||
131 | } |
||
132 | |||
133 | // save props |
||
134 | mapi_setprops($message, $newProps); |
||
135 | mapi_savechanges($message); |
||
136 | |||
137 | $result = true; |
||
138 | } |
||
139 | |||
140 | if ($result) { |
||
141 | /* |
||
142 | * @FIXME: Fix notifications for reminders. |
||
143 | * Notifications are currently disabled, because deleting multiple items will notify |
||
144 | * hierarchy multiple time but no data is changed with folder item in hierarchy. |
||
145 | * so it will push same data again which will lead to an error. |
||
146 | */ |
||
147 | // $props = mapi_getprops($message, array(PR_ENTRYID, PR_PARENT_ENTRYID, PR_STORE_ENTRYID)); |
||
148 | // $GLOBALS["bus"]->notify(bin2hex($props[PR_PARENT_ENTRYID]), TABLE_SAVE, $props); |
||
149 | } |
||
150 | $this->sendFeedback($result); |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * Function which is use to dismiss the reminder. |
||
155 | * |
||
156 | * @param object $store MAPI Message Store Object |
||
157 | * @param string $entryid entryid of the message |
||
158 | */ |
||
159 | public function dismissItem($store, $entryid) { |
||
160 | $result = false; |
||
161 | $message = mapi_msgstore_openentry($store, $entryid); |
||
162 | if ($message) { |
||
163 | $newProps = []; |
||
164 | $props = mapi_getprops($message, $this->properties); |
||
165 | |||
166 | if (stripos((string) $props[$this->properties["message_class"]], "IPM.Appointment") === 0) { |
||
167 | if (isset($props[$this->properties["appointment_recurring"]]) && $props[$this->properties["appointment_recurring"]]) { |
||
168 | $recurrence = new Recurrence($store, $message); |
||
169 | // check for next reminder after "now" for the next instance |
||
170 | $nextReminder = $recurrence->getNextReminderTime(time()); |
||
171 | if ($nextReminder) { |
||
172 | $newProps[$this->properties["flagdueby"]] = $nextReminder; |
||
173 | } |
||
174 | else { |
||
175 | $newProps[$this->properties["reminder"]] = false; |
||
176 | } |
||
177 | } |
||
178 | else { |
||
179 | $newProps[$this->properties["reminder"]] = false; |
||
180 | } |
||
181 | } |
||
182 | elseif (stripos((string) $props[$this->properties["message_class"]], "IPM.Task") === 0) { |
||
183 | $newProps[$this->properties["reminder"]] = false; |
||
184 | |||
185 | if (isset($props[$this->properties['task_recurring']]) && $props[$this->properties['task_recurring']] == 1) { |
||
186 | $newProps[$this->properties['task_resetreminder']] = true; |
||
187 | } |
||
188 | } |
||
189 | else { |
||
190 | $newProps[$this->properties["reminder"]] = false; |
||
191 | } |
||
192 | |||
193 | // save props |
||
194 | mapi_setprops($message, $newProps); |
||
195 | mapi_savechanges($message); |
||
196 | |||
197 | $result = true; |
||
198 | } |
||
199 | |||
200 | if ($result) { |
||
201 | /* |
||
202 | * @FIXME: Fix notifications for reminders. |
||
203 | * Notifications are currently disabled, because deleting multiple items will notify |
||
204 | * hierarchy multiple time but no data is changed with folder item in hierarchy. |
||
205 | * so it will push same data again which will lead to an error. |
||
206 | */ |
||
207 | // $props = mapi_getprops($message, array(PR_ENTRYID, PR_PARENT_ENTRYID, PR_STORE_ENTRYID)); |
||
208 | // $GLOBALS["bus"]->notify(bin2hex($props[PR_PARENT_ENTRYID]), TABLE_SAVE, $props); |
||
209 | } |
||
210 | $this->sendFeedback($result); |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * Function does customization of exception based on module data. |
||
215 | * like, here it will generate display message based on actionType |
||
216 | * for particular exception. |
||
217 | * |
||
218 | * @param object $e Exception object |
||
219 | * @param string $actionType the action type, sent by the client |
||
220 | * @param MAPIobject $store store object of message |
||
0 ignored issues
–
show
The type
MAPIobject was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
221 | * @param string $parententryid parent entryid of the message |
||
222 | * @param string $entryid entryid of the message |
||
223 | * @param array $action the action data, sent by the client |
||
224 | */ |
||
225 | #[Override] |
||
226 | public function handleException(&$e, $actionType = null, $store = null, $parententryid = null, $entryid = null, $action = null) { |
||
227 | if (is_null($e->displayMessage)) { |
||
228 | switch ($actionType) { |
||
229 | case 'delete': |
||
230 | if (!empty($action['message_action']['action_type'])) { |
||
231 | switch ($action['message_action']['action_type']) { |
||
232 | case 'snooze': |
||
233 | if ($e->getCode() == MAPI_E_STORE_FULL) { |
||
234 | $e->setDisplayMessage(_('Cannot snooze the reminder. You may be reminded again.') . '<br />' . $this->getOverQuotaMessage($store)); |
||
235 | } |
||
236 | else { |
||
237 | $e->setDisplayMessage(_('Cannot snooze the reminder. You may be reminded again.')); |
||
238 | } |
||
239 | break; |
||
240 | |||
241 | case 'dismiss': |
||
242 | if ($e->getCode() == MAPI_E_STORE_FULL) { |
||
243 | $e->setDisplayMessage(_('Cannot dismiss the reminder. You may be reminded again.') . '<br />' . $this->getOverQuotaMessage($store)); |
||
244 | } |
||
245 | else { |
||
246 | $e->setDisplayMessage(_('Cannot dismiss the reminder. You may be reminded again.')); |
||
247 | } |
||
248 | break; |
||
249 | } |
||
250 | } |
||
251 | break; |
||
252 | } |
||
253 | } |
||
254 | |||
255 | parent::handleException($e, $actionType, $store, $parententryid, $entryid, $action); |
||
256 | } |
||
257 | } |
||
258 |