grommunio /
grommunio-web
| 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 | /** |
||
| 11 | * Constructor |
||
| 12 | * @param int $id unique id. |
||
| 13 | * @param array $data list of all actions. |
||
| 14 | */ |
||
| 15 | function __construct($id, $data) |
||
| 16 | { |
||
| 17 | parent::__construct($id, $data); |
||
| 18 | } |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Function is use to set message flags for flagged mail item. |
||
| 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 | * @return boolean true on success or false on failure |
||
| 27 | */ |
||
| 28 | function save($store, $parententryid, $entryid, $action) |
||
| 29 | { |
||
| 30 | $this->properties = $GLOBALS['properties']->getMailProperties(); |
||
| 31 | $result = false; |
||
| 32 | |||
| 33 | if (!$store) { |
||
| 34 | $store = $GLOBALS['mapisession']->getDefaultMessageStore(); |
||
| 35 | } |
||
| 36 | |||
| 37 | if ($store) { |
||
| 38 | // Reference to an array which will be filled with PR_ENTRYID, PR_STORE_ENTRYID and PR_PARENT_ENTRYID of the message |
||
| 39 | $messageProps = array(); |
||
| 40 | |||
| 41 | // Set message flags |
||
| 42 | if (isset($action['props']) && isset($action['props']['message_flags']) && $entryid) { |
||
| 43 | $msg_action = isset($action['message_action']) ? $action['message_action'] : false; |
||
| 44 | $result = $GLOBALS['operations']->setMessageFlag($store, $entryid, $action['props']['message_flags'], $msg_action, $messageProps); |
||
| 45 | } |
||
| 46 | |||
| 47 | // Feedback for successful save |
||
| 48 | if ($result) { |
||
| 49 | $GLOBALS['bus']->notify(bin2hex($messageProps[PR_PARENT_ENTRYID]), TABLE_SAVE, $messageProps); |
||
| 50 | } |
||
| 51 | |||
| 52 | $this->sendFeedback($result ? true : false, array(), true); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Function which is use to dismiss or snooze the reminder item. |
||
| 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 | * @return boolean true on success or false on failure |
||
| 63 | */ |
||
| 64 | function delete($store, $parententryid, $entryid, $action) |
||
| 65 | { |
||
| 66 | $this->properties = $GLOBALS["properties"]->getReminderProperties(); |
||
| 67 | |||
| 68 | if(!$store) { |
||
| 69 | $store = $GLOBALS["mapisession"]->getDefaultMessageStore(); |
||
| 70 | } |
||
| 71 | |||
| 72 | $subActionType = false; |
||
| 73 | if (isset($action["message_action"]) && isset($action["message_action"]["action_type"])) { |
||
| 74 | $subActionType = $action["message_action"]["action_type"]; |
||
| 75 | } |
||
| 76 | |||
| 77 | switch ($subActionType) { |
||
| 78 | case "snooze": |
||
| 79 | $entryid = $this->getActionEntryID($action); |
||
| 80 | $this->snoozeItem($store, $entryid, $action); |
||
| 81 | break; |
||
| 82 | case "dismiss": |
||
| 83 | $entryid = $this->getActionEntryID($action); |
||
| 84 | $this->dismissItem($store, $entryid); |
||
| 85 | break; |
||
| 86 | default: |
||
| 87 | $this->handleUnknownActionType($subActionType); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Function which is use to snooze the reminder for given time |
||
| 93 | * @param object $store MAPI Message Store Object |
||
| 94 | * @param string $entryid entryid of the message |
||
| 95 | * @param array $action the action data, sent by the client |
||
| 96 | */ |
||
| 97 | function snoozeItem($store, $entryid, $action) |
||
| 98 | { |
||
| 99 | $result = false; |
||
| 100 | $message = mapi_msgstore_openentry($store, $entryid); |
||
| 101 | if ($message) { |
||
| 102 | $newProps = array(PR_ENTRYID => $entryid); |
||
| 103 | $props = mapi_getprops($message, $this->properties); |
||
| 104 | |||
| 105 | $snoozeTime = $GLOBALS["settings"]->get('zarafa/v1/main/reminder/default_snooze_time', 5); |
||
| 106 | if (isset($action["message_action"]["snoozeTime"]) && is_numeric($action["message_action"]["snoozeTime"])) { |
||
| 107 | $snoozeTime = $action["message_action"]["snoozeTime"]; |
||
| 108 | } |
||
| 109 | |||
| 110 | $reminderTime = time() + ($snoozeTime * 60); |
||
| 111 | if (stripos($props[$this->properties["message_class"]], "IPM.Appointment") === 0) { |
||
| 112 | if (isset($props[$this->properties["appointment_recurring"]]) && $props[$this->properties["appointment_recurring"]]) { |
||
| 113 | |||
| 114 | $recurrence = new Recurrence($store, $message); |
||
| 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 | else |
||
| 121 | $newProps[$this->properties["flagdueby"]] = $nextReminder; |
||
| 122 | } else { |
||
| 123 | $newProps[$this->properties["flagdueby"]] = $reminderTime; |
||
| 124 | } |
||
| 125 | } else { |
||
| 126 | $newProps[$this->properties["flagdueby"]] = $reminderTime; |
||
| 127 | } |
||
| 128 | |||
| 129 | // save props |
||
| 130 | mapi_setprops($message, $newProps); |
||
| 131 | mapi_savechanges($message); |
||
| 132 | |||
| 133 | $result = true; |
||
| 134 | } |
||
| 135 | |||
| 136 | if ($result) { |
||
| 137 | /** |
||
| 138 | * @FIXME: Fix notifications for reminders. |
||
| 139 | * Notifications are currently disabled, because deleting multiple items will notify |
||
| 140 | * hierarchy multiple time but no data is changed with folder item in hierarchy. |
||
| 141 | * so it will push same data again which will lead to an error. |
||
| 142 | */ |
||
| 143 | //$props = mapi_getprops($message, array(PR_ENTRYID, PR_PARENT_ENTRYID, PR_STORE_ENTRYID)); |
||
| 144 | //$GLOBALS["bus"]->notify(bin2hex($props[PR_PARENT_ENTRYID]), TABLE_SAVE, $props); |
||
| 145 | } |
||
| 146 | $this->sendFeedback($result); |
||
| 147 | } |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Function which is use to dismiss the reminder |
||
| 151 | * @param object $store MAPI Message Store Object |
||
| 152 | * @param string $entryid entryid of the message |
||
| 153 | */ |
||
| 154 | function dismissItem($store, $entryid) |
||
| 155 | { |
||
| 156 | $result = false; |
||
| 157 | $message = mapi_msgstore_openentry($store, $entryid); |
||
| 158 | if ($message) { |
||
| 159 | $newProps = array(); |
||
| 160 | $props = mapi_getprops($message, $this->properties); |
||
| 161 | |||
| 162 | if (stripos($props[$this->properties["message_class"]], "IPM.Appointment") === 0) { |
||
| 163 | if (isset($props[$this->properties["appointment_recurring"]]) && $props[$this->properties["appointment_recurring"]]) { |
||
| 164 | |||
| 165 | $recurrence = new Recurrence($store, $message); |
||
| 166 | // check for next reminder after "now" for the next instance |
||
| 167 | $nextReminder = $recurrence->getNextReminderTime(time()); |
||
| 168 | if ($nextReminder) |
||
| 169 | $newProps[$this->properties["flagdueby"]] = $nextReminder; |
||
| 170 | else |
||
| 171 | $newProps[$this->properties["reminder"]] = false; |
||
| 172 | } else { |
||
| 173 | $newProps[$this->properties["reminder"]] = false; |
||
| 174 | } |
||
| 175 | } else if (stripos($props[$this->properties["message_class"]], "IPM.Task") === 0) { |
||
| 176 | $newProps[$this->properties["reminder"]] = false; |
||
| 177 | |||
| 178 | if (isset($props[$this->properties['task_recurring']]) && $props[$this->properties['task_recurring']] == 1) { |
||
| 179 | $newProps[$this->properties['task_resetreminder']] = true; |
||
| 180 | } |
||
| 181 | } else { |
||
| 182 | $newProps[$this->properties["reminder"]] = false; |
||
| 183 | } |
||
| 184 | |||
| 185 | // save props |
||
| 186 | mapi_setprops($message, $newProps); |
||
| 187 | mapi_savechanges($message); |
||
| 188 | |||
| 189 | $result = true; |
||
| 190 | } |
||
| 191 | |||
| 192 | if ($result) { |
||
| 193 | /** |
||
| 194 | * @FIXME: Fix notifications for reminders. |
||
| 195 | * Notifications are currently disabled, because deleting multiple items will notify |
||
| 196 | * hierarchy multiple time but no data is changed with folder item in hierarchy. |
||
| 197 | * so it will push same data again which will lead to an error. |
||
| 198 | */ |
||
| 199 | //$props = mapi_getprops($message, array(PR_ENTRYID, PR_PARENT_ENTRYID, PR_STORE_ENTRYID)); |
||
| 200 | //$GLOBALS["bus"]->notify(bin2hex($props[PR_PARENT_ENTRYID]), TABLE_SAVE, $props); |
||
| 201 | } |
||
| 202 | $this->sendFeedback($result); |
||
| 203 | } |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Function does customization of exception based on module data. |
||
| 207 | * like, here it will generate display message based on actionType |
||
| 208 | * for particular exception. |
||
| 209 | * |
||
| 210 | * @param object $e Exception object |
||
| 211 | * @param string $actionType the action type, sent by the client |
||
| 212 | * @param MAPIobject $store Store object of message. |
||
| 213 | * @param string $parententryid parent entryid of the message. |
||
| 214 | * @param string $entryid entryid of the message. |
||
| 215 | * @param array $action the action data, sent by the client |
||
| 216 | */ |
||
| 217 | function handleException(&$e, $actionType = null, $store = null, $parententryid = null, $entryid = null, $action = null) |
||
| 218 | { |
||
| 219 | if (is_null($e->displayMessage)) { |
||
| 220 | switch ($actionType) { |
||
| 221 | case 'delete': |
||
| 222 | if (!empty($action['message_action']['action_type'])) { |
||
| 223 | switch ($action['message_action']['action_type']) { |
||
| 224 | case 'snooze': |
||
| 225 | if ($e->getCode() == MAPI_E_STORE_FULL) { |
||
| 226 | $e->setDisplayMessage(_('Cannot snooze the reminder. You may be reminded again.') . '<br />' . $this->getOverQuotaMessage($store)); |
||
| 227 | } else { |
||
| 228 | $e->setDisplayMessage(_('Cannot snooze the reminder. You may be reminded again.')); |
||
| 229 | } |
||
| 230 | break; |
||
| 231 | case 'dismiss': |
||
| 232 | if ($e->getCode() == MAPI_E_STORE_FULL) { |
||
| 233 | $e->setDisplayMessage(_('Cannot dismiss the reminder. You may be reminded again.') . '<br />' . $this->getOverQuotaMessage($store)); |
||
| 234 | } else { |
||
| 235 | $e->setDisplayMessage(_('Cannot dismiss the reminder. You may be reminded again.')); |
||
| 236 | } |
||
| 237 | break; |
||
| 238 | } |
||
| 239 | } |
||
| 240 | break; |
||
| 241 | } |
||
| 242 | } |
||
| 243 | |||
| 244 | parent::handleException($e, $actionType, $store, $parententryid, $entryid, $action); |
||
| 245 | } |
||
| 246 | } |
||
| 247 | |||
| 248 | ?> |
||
|
0 ignored issues
–
show
|
|||
| 249 |
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.