1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Contact ItemModule |
5
|
|
|
* Module which opens, creates, saves and deletes an item. It |
6
|
|
|
* extends the Module class. |
7
|
|
|
*/ |
8
|
|
|
class ContactItemModule 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
|
|
|
$this->properties = $GLOBALS['properties']->getContactProperties(); |
17
|
|
|
|
18
|
|
|
parent::__construct($id, $data); |
19
|
|
|
|
20
|
|
|
$this->plaintext = false; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Function which opens an item. |
25
|
|
|
* |
26
|
|
|
* @param object $store MAPI Message Store Object |
27
|
|
|
* @param string $entryid entryid of the message |
28
|
|
|
* @param array $action the action data, sent by the client |
29
|
|
|
*/ |
30
|
|
|
#[Override] |
31
|
|
|
public function open($store, $entryid, $action) { |
32
|
|
|
$data = []; |
33
|
|
|
$orEntryid = $entryid; |
34
|
|
|
|
35
|
|
|
if ($entryid) { |
36
|
|
|
// Check if OneOff entryid is a local contact |
37
|
|
|
if ($GLOBALS['entryid']->hasAddressBookOneOff(bin2hex($entryid))) { |
38
|
|
|
try { |
39
|
|
|
$oneoff = mapi_parseoneoff($entryid); |
40
|
|
|
$ab = $GLOBALS['mapisession']->getAddressbook(); |
41
|
|
|
$ab_dir = mapi_ab_openentry($ab); |
42
|
|
|
$res = $this->searchContactsFolders($ab, $ab_dir, $oneoff['address']); |
43
|
|
|
if (count($res) > 0) { |
44
|
|
|
$entryid = $res[0][PR_ENTRYID]; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
catch (MAPIException $ex) { |
48
|
|
|
error_log(sprintf( |
49
|
|
|
"Unable to open contact because mapi_parseoneoff failed: %s - %s", |
50
|
|
|
get_mapi_error_name($ex->getCode()), |
51
|
|
|
$ex->getDisplayMessage() |
52
|
|
|
)); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
/* Check if given entryid is shared folder distlist then |
56
|
|
|
* get the store of distlist for fetching it's members. |
57
|
|
|
*/ |
58
|
|
|
$storeData = $this->getStoreParentEntryIdFromEntryId($entryid); |
59
|
|
|
$store = $storeData["store"]; |
60
|
|
|
$message = $storeData["message"]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
if (empty($message)) { |
64
|
|
|
return; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
// Open embedded message if requested |
68
|
|
|
$attachNum = !empty($action['attach_num']) ? $action['attach_num'] : false; |
69
|
|
|
if ($attachNum) { |
70
|
|
|
// get message props of sub message |
71
|
|
|
$parentMessage = $message; |
|
|
|
|
72
|
|
|
$message = $GLOBALS['operations']->openMessage($store, $entryid, $attachNum); |
73
|
|
|
|
74
|
|
|
if (empty($message)) { |
75
|
|
|
return; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
// Check if message is distlist then we need to use different set of properties |
79
|
|
|
$props = mapi_getprops($message, [PR_MESSAGE_CLASS]); |
80
|
|
|
|
81
|
|
|
if (stripos((string) $props[PR_MESSAGE_CLASS], 'IPM.Distlist') !== false) { |
82
|
|
|
// for distlist we need to use different set of properties |
83
|
|
|
$this->properties = $GLOBALS['properties']->getDistListProperties(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$data['item'] = $GLOBALS['operations']->getEmbeddedMessageProps($store, $message, $this->properties, $parentMessage, $attachNum); |
87
|
|
|
} |
88
|
|
|
else { |
89
|
|
|
// Check if message is distlist then we need to use different set of properties |
90
|
|
|
$props = mapi_getprops($message, [PR_MESSAGE_CLASS]); |
91
|
|
|
|
92
|
|
|
if (stripos((string) $props[PR_MESSAGE_CLASS], 'IPM.Distlist') !== false) { |
93
|
|
|
// for distlist we need to use different set of properties |
94
|
|
|
$this->properties = $GLOBALS['properties']->getDistListProperties(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
// get message props of the message |
98
|
|
|
$data['item'] = $GLOBALS['operations']->getMessageProps($store, $message, $this->properties, $this->plaintext); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
// By openentry from address book, the entryid will differ, make it same as the origin |
102
|
|
|
$data['item']['entryid'] = bin2hex($orEntryid); |
103
|
|
|
|
104
|
|
|
// Allowing to hook in just before the data sent away to be sent to the client |
105
|
|
|
$GLOBALS['PluginManager']->triggerHook('server.module.contactitemmodule.open.after', [ |
106
|
|
|
'moduleObject' => &$this, |
107
|
|
|
'store' => $store, |
108
|
|
|
'entryid' => $entryid, |
109
|
|
|
'action' => $action, |
110
|
|
|
'message' => &$message, |
111
|
|
|
'data' => &$data, |
112
|
|
|
]); |
113
|
|
|
|
114
|
|
|
$this->addActionData('item', $data); |
115
|
|
|
$GLOBALS['bus']->addData($this->getResponseData()); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Function which saves an item. It sets the right properties for a contact |
120
|
|
|
* item (address book properties). |
121
|
|
|
* |
122
|
|
|
* @param object $store MAPI Message Store Object |
123
|
|
|
* @param string $parententryid parent entryid of the message |
124
|
|
|
* @param string $entryid entryid of the message |
125
|
|
|
* @param array $action the action data, sent by the client |
126
|
|
|
*/ |
127
|
|
|
#[Override] |
128
|
|
|
public function save($store, $parententryid, $entryid, $action) { |
129
|
|
|
$properiesToDelete = []; // create an array of properties which should be deleted |
130
|
|
|
// this array is passed to $GLOBALS['operations']->saveMessage() function |
131
|
|
|
|
132
|
|
|
if (!$store && !$parententryid) { |
|
|
|
|
133
|
|
|
if (isset($action['props']['message_class'])) { |
134
|
|
|
$store = $GLOBALS['mapisession']->getDefaultMessageStore(); |
135
|
|
|
$parententryid = $this->getDefaultFolderEntryID($store, $action['props']['message_class']); |
136
|
|
|
} |
137
|
|
|
elseif ($entryid) { |
138
|
|
|
$data = $this->getStoreParentEntryIdFromEntryId($entryid); |
139
|
|
|
$store = $data["store"]; |
140
|
|
|
$parententryid = $data["parent_entryid"]; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
elseif (!$parententryid) { |
144
|
|
|
if (isset($action['props']['message_class'])) { |
145
|
|
|
$parententryid = $this->getDefaultFolderEntryID($store, $action['props']['message_class']); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
if ($store && $parententryid && isset($action['props'])) { |
150
|
|
|
if (isset($action['members'])) { |
151
|
|
|
// DistList |
152
|
|
|
|
153
|
|
|
// for distlist we need to use different set of properties |
154
|
|
|
$this->properties = $GLOBALS['properties']->getDistListProperties(); |
155
|
|
|
|
156
|
|
|
// do conversion of client data |
157
|
|
|
$props = Conversion::mapXML2MAPI($this->properties, $action['props']); |
158
|
|
|
|
159
|
|
|
// collect members |
160
|
|
|
$members = []; |
161
|
|
|
$oneoff_members = []; |
162
|
|
|
|
163
|
|
|
$items = $action['members']; |
164
|
|
|
|
165
|
|
|
foreach ($items as $item) { |
166
|
|
|
if (empty($item['email_address'])) { |
167
|
|
|
// if no email address is given then mapi_parseoneoff fails, so always give |
168
|
|
|
// email address, OL07 uses Unknown as email address so we do same here |
169
|
|
|
$item['email_address'] = 'Unknown'; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
$oneoff = mapi_createoneoff($item['display_name'], $item['address_type'], $item['email_address']); |
173
|
|
|
|
174
|
|
|
if ($item['distlist_type'] == DL_EXTERNAL_MEMBER) { |
175
|
|
|
$member = $oneoff; |
176
|
|
|
} |
177
|
|
|
else { |
178
|
|
|
$parts = []; |
179
|
|
|
$parts['distlist_guid'] = WAB_GUID; |
180
|
|
|
$parts['distlist_type'] = $item['distlist_type']; |
181
|
|
|
$parts['entryid'] = hex2bin((string) $item['entryid']); |
182
|
|
|
$member = pack('VA16CA*', 0, $parts['distlist_guid'], $parts['distlist_type'], $parts['entryid']); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
$oneoff_members[] = $oneoff; |
186
|
|
|
$members[] = $member; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
if (!empty($members) && !empty($oneoff_members)) { |
190
|
|
|
$props[$this->properties['members']] = $members; |
191
|
|
|
$props[$this->properties['oneoff_members']] = $oneoff_members; |
192
|
|
|
} |
193
|
|
|
else { |
194
|
|
|
$properiesToDelete[] = $this->properties['members']; |
195
|
|
|
$properiesToDelete[] = $this->properties['oneoff_members']; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
unset($action['members']); |
199
|
|
|
} |
200
|
|
|
else { |
201
|
|
|
// Contact |
202
|
|
|
|
203
|
|
|
$isCopyGABToContact = isset($action["message_action"], $action["message_action"]["action_type"]) && |
204
|
|
|
|
205
|
|
|
$action["message_action"]["action_type"] === "copyToContact"; |
206
|
|
|
|
207
|
|
|
if ($isCopyGABToContact) { |
208
|
|
|
$this->copyGABRecordProps($action); |
209
|
|
|
} |
210
|
|
|
// generate one-off entryids for email addresses |
211
|
|
|
for ($index = 1; $index < 4; ++$index) { |
212
|
|
|
if (!empty($action['props']['email_address_' . $index]) && !empty($action['props']['email_address_display_name_' . $index])) { |
213
|
|
|
$action['props']['email_address_entryid_' . $index] = bin2hex(mapi_createoneoff($action['props']['email_address_display_name_' . $index], $action['props']['email_address_type_' . $index], $action['props']['email_address_' . $index])); |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
// set properties for primary fax number |
218
|
|
|
if (isset($action['props']['fax_1_email_address']) && !empty($action['props']['fax_1_email_address'])) { |
219
|
|
|
$action['props']['fax_1_original_entryid'] = bin2hex(mapi_createoneoff($action['props']['fax_1_original_display_name'], $action['props']['fax_1_address_type'], $action['props']['fax_1_email_address'], MAPI_UNICODE)); |
220
|
|
|
} |
221
|
|
|
else { |
222
|
|
|
// delete properties to remove previous values |
223
|
|
|
$properiesToDelete[] = $this->properties['fax_1_address_type']; |
224
|
|
|
$properiesToDelete[] = $this->properties['fax_1_original_display_name']; |
225
|
|
|
$properiesToDelete[] = $this->properties['fax_1_email_address']; |
226
|
|
|
$properiesToDelete[] = $this->properties['fax_1_original_entryid']; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
// set properties for business fax number |
230
|
|
|
if (isset($action['props']['fax_2_email_address']) && !empty($action['props']['fax_2_email_address'])) { |
231
|
|
|
$action['props']['fax_2_original_entryid'] = bin2hex(mapi_createoneoff($action['props']['fax_2_original_display_name'], $action['props']['fax_2_address_type'], $action['props']['fax_2_email_address'], MAPI_UNICODE)); |
232
|
|
|
} |
233
|
|
|
else { |
234
|
|
|
$properiesToDelete[] = $this->properties['fax_2_address_type']; |
235
|
|
|
$properiesToDelete[] = $this->properties['fax_2_original_display_name']; |
236
|
|
|
$properiesToDelete[] = $this->properties['fax_2_email_address']; |
237
|
|
|
$properiesToDelete[] = $this->properties['fax_2_original_entryid']; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
// set properties for home fax number |
241
|
|
|
if (isset($action['props']['fax_3_email_address']) && !empty($action['props']['fax_3_email_address'])) { |
242
|
|
|
$action['props']['fax_3_original_entryid'] = bin2hex(mapi_createoneoff($action['props']['fax_3_original_display_name'], $action['props']['fax_3_address_type'], $action['props']['fax_3_email_address'], MAPI_UNICODE)); |
243
|
|
|
} |
244
|
|
|
else { |
245
|
|
|
$properiesToDelete[] = $this->properties['fax_3_address_type']; |
246
|
|
|
$properiesToDelete[] = $this->properties['fax_3_original_display_name']; |
247
|
|
|
$properiesToDelete[] = $this->properties['fax_3_email_address']; |
248
|
|
|
$properiesToDelete[] = $this->properties['fax_3_original_entryid']; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
// check for properties which should be deleted |
252
|
|
|
if (isset($action['entryid']) && !empty($action['entryid'])) { |
253
|
|
|
// check for empty email address properties |
254
|
|
|
for ($i = 1; $i < 4; ++$i) { |
255
|
|
|
if (isset($action['props']['email_address_' . $i]) && empty($action['props']['email_address_' . $i])) { |
256
|
|
|
array_push($properiesToDelete, $this->properties['email_address_entryid_' . $i]); |
257
|
|
|
array_push($properiesToDelete, $this->properties['email_address_' . $i]); |
258
|
|
|
array_push($properiesToDelete, $this->properties['email_address_display_name_' . $i]); |
259
|
|
|
array_push($properiesToDelete, $this->properties['email_address_display_name_email_' . $i]); |
260
|
|
|
array_push($properiesToDelete, $this->properties['email_address_type_' . $i]); |
261
|
|
|
} |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
// check for empty address_book_mv and address_book_long properties |
265
|
|
|
if (isset($action['props']['address_book_long']) && $action['props']['address_book_long'] === 0) { |
266
|
|
|
$properiesToDelete[] = $this->properties['address_book_mv']; |
267
|
|
|
$properiesToDelete[] = $this->properties['address_book_long']; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
// Check if the birthday and anniversary properties are empty. If so delete them. |
271
|
|
|
if (array_key_exists('birthday', $action['props']) && empty($action['props']['birthday'])) { |
272
|
|
|
array_push($properiesToDelete, $this->properties['birthday']); |
273
|
|
|
array_push($properiesToDelete, $this->properties['birthday_eventid']); |
274
|
|
|
if (!empty($action['props']['birthday_eventid'])) { |
275
|
|
|
$this->deleteSpecialDateAppointment($store, $action['props']['birthday_eventid']); |
276
|
|
|
} |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
if (array_key_exists('wedding_anniversary', $action['props']) && empty($action['props']['wedding_anniversary'])) { |
280
|
|
|
array_push($properiesToDelete, $this->properties['wedding_anniversary']); |
281
|
|
|
array_push($properiesToDelete, $this->properties['anniversary_eventid']); |
282
|
|
|
if (!empty($action['props']['anniversary_eventid'])) { |
283
|
|
|
$this->deleteSpecialDateAppointment($store, $action['props']['anniversary_eventid']); |
284
|
|
|
} |
285
|
|
|
} |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/* |
289
|
|
|
* convert all line endings(LF) into CRLF |
290
|
|
|
* XML parser will normalize all CR, LF and CRLF into LF |
291
|
|
|
* but outlook(windows) uses CRLF as line ending |
292
|
|
|
*/ |
293
|
|
|
if (isset($action['props']['business_address'])) { |
294
|
|
|
$action['props']['business_address'] = str_replace('\n', '\r\n', $action['props']['business_address']); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
if (isset($action['props']['home_address'])) { |
298
|
|
|
$action['props']['home_address'] = str_replace('\n', '\r\n', $action['props']['home_address']); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
if (isset($action['props']['other_address'])) { |
302
|
|
|
$action['props']['other_address'] = str_replace('\n', '\r\n', $action['props']['other_address']); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
// check birthday props to make an appointment |
306
|
|
|
if (!empty($action['props']['birthday'])) { |
307
|
|
|
$action['props']['birthday_eventid'] = $this->updateAppointments($store, $action, 'birthday'); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
// check anniversary props to make an appointment |
311
|
|
|
if (!empty($action['props']['wedding_anniversary'])) { |
312
|
|
|
$action['props']['anniversary_eventid'] = $this->updateAppointments($store, $action, 'wedding_anniversary'); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
// do the conversion when all processing has been finished |
316
|
|
|
$props = Conversion::mapXML2MAPI($this->properties, $action['props']); |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
$messageProps = []; |
320
|
|
|
|
321
|
|
|
$result = $GLOBALS['operations']->saveMessage($store, $entryid, $parententryid, $props, $messageProps, [], $action['attachments'] ?? [], $properiesToDelete); |
322
|
|
|
|
323
|
|
|
if ($result) { |
324
|
|
|
$GLOBALS['bus']->notify(bin2hex($parententryid), TABLE_SAVE, $messageProps); |
325
|
|
|
|
326
|
|
|
if ($isCopyGABToContact) { |
|
|
|
|
327
|
|
|
$message = mapi_msgstore_openentry($store, $messageProps[PR_ENTRYID]); |
328
|
|
|
$messageProps = mapi_getprops($message, $this->properties); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
$this->addActionData('update', ['item' => Conversion::mapMAPI2XML($this->properties, $messageProps)]); |
332
|
|
|
$GLOBALS['bus']->addData($this->getResponseData()); |
333
|
|
|
} |
334
|
|
|
} |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
* Function copy the some property from address book record to contact props. |
339
|
|
|
* |
340
|
|
|
* @param array $action the action data, sent by the client |
341
|
|
|
*/ |
342
|
|
|
public function copyGABRecordProps(&$action) { |
343
|
|
|
$addrbook = $GLOBALS["mapisession"]->getAddressbook(); |
344
|
|
|
$abitem = mapi_ab_openentry($addrbook, hex2bin((string) $action["message_action"]["source_entryid"])); |
345
|
|
|
$abItemProps = mapi_getprops($abitem, [ |
346
|
|
|
PR_COMPANY_NAME, |
347
|
|
|
PR_ASSISTANT, |
348
|
|
|
PR_BUSINESS_TELEPHONE_NUMBER, |
349
|
|
|
PR_BUSINESS2_TELEPHONE_NUMBER, |
350
|
|
|
PR_HOME2_TELEPHONE_NUMBER, |
351
|
|
|
PR_STREET_ADDRESS, |
352
|
|
|
PR_LOCALITY, |
353
|
|
|
PR_STATE_OR_PROVINCE, |
354
|
|
|
PR_POSTAL_CODE, |
355
|
|
|
PR_COUNTRY, |
356
|
|
|
PR_MOBILE_TELEPHONE_NUMBER, |
357
|
|
|
]); |
358
|
|
|
$action["props"]["company_name"] = $abItemProps[PR_COMPANY_NAME] ?? ''; |
359
|
|
|
$action["props"]["assistant"] = $abItemProps[PR_ASSISTANT] ?? ''; |
360
|
|
|
$action["props"]["business_telephone_number"] = $abItemProps[PR_BUSINESS_TELEPHONE_NUMBER] ?? ''; |
361
|
|
|
$action["props"]["business2_telephone_number"] = $abItemProps[PR_BUSINESS2_TELEPHONE_NUMBER] ?? ''; |
362
|
|
|
$action["props"]["home2_telephone_number"] = $abItemProps[PR_HOME2_TELEPHONE_NUMBER] ?? ''; |
363
|
|
|
$action["props"]["home_address_street"] = $abItemProps[PR_STREET_ADDRESS] ?? ''; |
364
|
|
|
$action["props"]["home_address_city"] = $abItemProps[PR_LOCALITY] ?? ''; |
365
|
|
|
$action["props"]["home_address_state"] = $abItemProps[PR_STATE_OR_PROVINCE] ?? ''; |
366
|
|
|
$action["props"]["home_address_postal_code"] = $abItemProps[PR_POSTAL_CODE] ?? ''; |
367
|
|
|
$action["props"]["home_address_country"] = $abItemProps[PR_COUNTRY] ?? ''; |
368
|
|
|
|
369
|
|
|
$action["props"]["cellular_telephone_number"] = $abItemProps[PR_MOBILE_TELEPHONE_NUMBER] ?? ''; |
370
|
|
|
|
371
|
|
|
// Set the home_address property value |
372
|
|
|
$props = ["street", "city", "state", "postal_code", "country"]; |
373
|
|
|
$homeAddress = ""; |
374
|
|
|
foreach ($props as $index => $prop) { |
375
|
|
|
if (isset($action["props"]["home_address_" . $prop]) && !empty($action["props"]["home_address_" . $prop])) { |
376
|
|
|
$homeAddress .= $action["props"]["home_address_" . $prop] . " "; |
377
|
|
|
if ($prop == "street" || $prop == "postal_code") { |
378
|
|
|
$homeAddress .= PHP_EOL; |
379
|
|
|
} |
380
|
|
|
} |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
$action["props"]["home_address"] = $homeAddress; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* Function which deletes an item. Extended here to also delete corresponding birthday/anniversary |
388
|
|
|
* appointments from calendar. |
389
|
|
|
* |
390
|
|
|
* @param object $store MAPI Message Store Object |
391
|
|
|
* @param string $parententryid parent entryid of the message |
392
|
|
|
* @param string $entryid entryid of the message |
393
|
|
|
* @param array $action the action data, sent by the client |
394
|
|
|
*/ |
395
|
|
|
#[Override] |
396
|
|
|
public function delete($store, $parententryid, $entryid, $action) { |
397
|
|
|
$message = false; |
398
|
|
|
if (!$store && !$parententryid && $entryid) { |
|
|
|
|
399
|
|
|
$data = $this->getStoreParentEntryIdFromEntryId($entryid); |
400
|
|
|
$store = $data["store"]; |
401
|
|
|
$message = $data["message"]; |
402
|
|
|
$parententryid = $data["parent_entryid"]; |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
if ($store && $entryid) { |
406
|
|
|
try { |
407
|
|
|
if ($message === false) { |
|
|
|
|
408
|
|
|
$message = $GLOBALS["operations"]->openMessage($store, $entryid); |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
$props = mapi_getprops($message, [$this->properties['anniversary_eventid'], $this->properties['birthday_eventid']]); |
412
|
|
|
|
413
|
|
|
// if any of the appointment entryid exists then delete it |
414
|
|
|
if (!empty($props[$this->properties['birthday_eventid']])) { |
415
|
|
|
$this->deleteSpecialDateAppointment($store, bin2hex((string) $props[$this->properties['birthday_eventid']])); |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
if (!empty($props[$this->properties['anniversary_eventid']])) { |
419
|
|
|
$this->deleteSpecialDateAppointment($store, bin2hex((string) $props[$this->properties['anniversary_eventid']])); |
420
|
|
|
} |
421
|
|
|
} |
422
|
|
|
catch (MAPIException $e) { |
423
|
|
|
// if any error occurs in deleting appointments then we shouldn't block deletion of contact item |
424
|
|
|
// so ignore errors now |
425
|
|
|
$e->setHandled(); |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
parent::delete($store, $parententryid, $entryid, $action); |
429
|
|
|
} |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* Function which retrieve the store, parent_entryid from record entryid. |
434
|
|
|
* |
435
|
|
|
* @param $entryid entryid of the message |
436
|
|
|
* |
437
|
|
|
* @return array which contains store and message object and parent entryid of that message |
438
|
|
|
*/ |
439
|
|
|
public function getStoreParentEntryIdFromEntryId($entryid) { |
440
|
|
|
$message = $GLOBALS['mapisession']->openMessage($entryid); |
441
|
|
|
$messageStoreInfo = mapi_getprops($message, [PR_STORE_ENTRYID, PR_PARENT_ENTRYID]); |
442
|
|
|
$store = $GLOBALS['mapisession']->openMessageStore($messageStoreInfo[PR_STORE_ENTRYID]); |
443
|
|
|
$parentEntryid = $messageStoreInfo[PR_PARENT_ENTRYID]; |
444
|
|
|
|
445
|
|
|
return ["message" => $message, "store" => $store, "parent_entryid" => $parentEntryid]; |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
/** |
449
|
|
|
* Function will create/update a yearly recurring appointment on the respective date of birthday or anniversary in user's calendar. |
450
|
|
|
* |
451
|
|
|
* @param object $store MAPI Message Store Object |
452
|
|
|
* @param array $action the action data, sent by the client |
453
|
|
|
* @param string $type type of appointment that should be created/updated, valid values are 'birthday' and 'wedding_anniversary' |
454
|
|
|
* |
455
|
|
|
* @return HexString entryid of the newly created appointment in hex format |
|
|
|
|
456
|
|
|
*/ |
457
|
|
|
public function updateAppointments($store, $action, $type) { |
458
|
|
|
$result = false; |
459
|
|
|
|
460
|
|
|
$root = mapi_msgstore_openentry($store); |
461
|
|
|
$rootProps = mapi_getprops($root, [PR_IPM_APPOINTMENT_ENTRYID, PR_STORE_ENTRYID]); |
462
|
|
|
$parentEntryId = bin2hex((string) $rootProps[PR_IPM_APPOINTMENT_ENTRYID]); |
463
|
|
|
$storeEntryId = bin2hex((string) $rootProps[PR_STORE_ENTRYID]); |
464
|
|
|
|
465
|
|
|
$actionProps = $action['props']; |
466
|
|
|
$subject = !empty($actionProps['subject']) ? $actionProps['subject'] : _('Untitled'); |
467
|
|
|
$subject = ($type === 'birthday' ? sprintf(_('%s\'s Birthday'), $subject) : sprintf(_('%s\'s Anniversary'), $subject)); |
468
|
|
|
|
469
|
|
|
// UTC time |
470
|
|
|
$startDateUTC = $actionProps[$type]; |
471
|
|
|
$dueDateUTC = $actionProps[$type] + (24 * 60 * 60); // ONE DAY is added to set duedate of item. |
472
|
|
|
|
473
|
|
|
// get local time from UTC time |
474
|
|
|
$recur = new Recurrence($store, []); |
|
|
|
|
475
|
|
|
$startDate = $recur->fromGMT($actionProps, $startDateUTC); |
476
|
|
|
$dueDate = $recur->fromGMT($actionProps, $dueDateUTC); |
477
|
|
|
|
478
|
|
|
// Find the number of minutes since the start of the year to the given month, |
479
|
|
|
// taking leap years into account. |
480
|
|
|
$month = date('m', $startDate); |
481
|
|
|
$year = date('y', $startDate); |
482
|
|
|
|
483
|
|
|
$d1 = new DateTime(); |
484
|
|
|
$d1->setDate($year, 1, 1); |
|
|
|
|
485
|
|
|
$d2 = new DateTime(); |
486
|
|
|
$d2->setDate($year, $month, 1); |
|
|
|
|
487
|
|
|
|
488
|
|
|
$diff = $d2->diff($d1); |
489
|
|
|
$month = $diff->days * 24 * 60; |
490
|
|
|
|
491
|
|
|
$props = [ |
492
|
|
|
'message_class' => 'IPM.Appointment', |
493
|
|
|
'icon_index' => 1025, |
494
|
|
|
'busystatus' => fbFree, |
495
|
|
|
'meeting' => olNonMeeting, |
496
|
|
|
'object_type' => MAPI_MESSAGE, |
497
|
|
|
'message_flags' => MSGFLAG_READ | MSGFLAG_UNSENT, |
498
|
|
|
'subject' => $subject, |
499
|
|
|
|
500
|
|
|
'startdate' => $startDateUTC, |
501
|
|
|
'duedate' => $dueDateUTC, |
502
|
|
|
'commonstart' => $startDateUTC, |
503
|
|
|
'commonend' => $dueDateUTC, |
504
|
|
|
'alldayevent' => true, |
505
|
|
|
'duration' => 1440, |
506
|
|
|
'reminder' => true, |
507
|
|
|
'reminder_minutes' => 1080, |
508
|
|
|
'reminder_time' => $startDateUTC, |
509
|
|
|
'flagdueby' => $startDateUTC - (1080 * 60), |
510
|
|
|
|
511
|
|
|
'recurring' => true, |
512
|
|
|
'recurring_reset' => true, |
513
|
|
|
'startocc' => 0, |
514
|
|
|
'endocc' => 1440, |
515
|
|
|
'start' => $startDate, |
516
|
|
|
'end' => $dueDate, |
517
|
|
|
'term' => 35, |
518
|
|
|
'everyn' => 12, |
519
|
|
|
'subtype' => 2, |
520
|
|
|
'type' => 13, |
521
|
|
|
'regen' => 0, |
522
|
|
|
'month' => $month, |
523
|
|
|
'monthday' => date('j', $startDate), |
524
|
|
|
'timezone' => $actionProps['timezone'], |
525
|
|
|
'timezonedst' => $actionProps['timezonedst'], |
526
|
|
|
'dststartmonth' => $actionProps['dststartmonth'], |
527
|
|
|
'dststartweek' => $actionProps['dststartweek'], |
528
|
|
|
'dststartday' => $actionProps['dststartday'], |
529
|
|
|
'dststarthour' => $actionProps['dststarthour'], |
530
|
|
|
'dstendmonth' => $actionProps['dstendmonth'], |
531
|
|
|
'dstendweek' => $actionProps['dstendweek'], |
532
|
|
|
'dstendday' => $actionProps['dstendday'], |
533
|
|
|
'dstendhour' => $actionProps['dstendhour'], |
534
|
|
|
]; |
535
|
|
|
|
536
|
|
|
$data = []; |
537
|
|
|
$data['store'] = $storeEntryId; |
538
|
|
|
$data['parententryid'] = $parentEntryId; |
539
|
|
|
|
540
|
|
|
$entryid = false; |
541
|
|
|
// if entryid is provided then update existing appointment, else create new one |
542
|
|
|
if ($type === 'birthday' && !empty($actionProps['birthday_eventid'])) { |
543
|
|
|
$entryid = $actionProps['birthday_eventid']; |
544
|
|
|
} |
545
|
|
|
elseif ($type === 'wedding_anniversary' && !empty($actionProps['anniversary_eventid'])) { |
546
|
|
|
$entryid = $actionProps['anniversary_eventid']; |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
if ($entryid !== false) { |
550
|
|
|
$data['entryid'] = $entryid; |
551
|
|
|
} |
552
|
|
|
|
553
|
|
|
if (isset($action['timezone_iana'])) { |
554
|
|
|
$props['timezone_iana'] = $action['timezone_iana']; |
555
|
|
|
} |
556
|
|
|
|
557
|
|
|
$data['props'] = $props; |
558
|
|
|
|
559
|
|
|
// Save appointment (saveAppointment takes care of creating/modifying exceptions to recurring |
560
|
|
|
// items if necessary) |
561
|
|
|
try { |
562
|
|
|
$messageProps = $GLOBALS['operations']->saveAppointment($store, hex2bin((string) $entryid), hex2bin($parentEntryId), $data); |
563
|
|
|
} |
564
|
|
|
catch (MAPIException $e) { |
565
|
|
|
// if the appointment is deleted then create a new one |
566
|
|
|
if ($e->getCode() == MAPI_E_NOT_FOUND) { |
567
|
|
|
$e->setHandled(); |
568
|
|
|
$messageProps = $GLOBALS['operations']->saveAppointment($store, false, hex2bin($parentEntryId), $data); |
569
|
|
|
} |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
// Notify the bus if the save was OK |
573
|
|
|
if ($messageProps && !(is_array($messageProps) && isset($messageProps['error']))) { |
574
|
|
|
$GLOBALS['bus']->notify($parentEntryId, TABLE_SAVE, $messageProps); |
575
|
|
|
$result = bin2hex((string) $messageProps[PR_ENTRYID]); |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
return $result; |
|
|
|
|
579
|
|
|
} |
580
|
|
|
|
581
|
|
|
/** |
582
|
|
|
* Function will delete the appointment on the respective date of birthday or anniversary in user's calendar. |
583
|
|
|
* |
584
|
|
|
* @param object $store MAPI Message Store Object |
585
|
|
|
* @param $entryid of the message with will be deleted,sent by the client |
|
|
|
|
586
|
|
|
*/ |
587
|
|
|
public function deleteSpecialDateAppointment($store, $entryid) { |
588
|
|
|
$root = mapi_msgstore_openentry($store); |
589
|
|
|
$rootProps = mapi_getprops($root, [PR_IPM_APPOINTMENT_ENTRYID, PR_STORE_ENTRYID]); |
590
|
|
|
$parentEntryId = $rootProps[PR_IPM_APPOINTMENT_ENTRYID]; |
591
|
|
|
$storeEntryId = $rootProps[PR_STORE_ENTRYID]; |
592
|
|
|
|
593
|
|
|
$props = []; |
594
|
|
|
$props[PR_PARENT_ENTRYID] = $parentEntryId; |
595
|
|
|
$props[PR_ENTRYID] = hex2bin((string) $entryid); |
596
|
|
|
$props[PR_STORE_ENTRYID] = $storeEntryId; |
597
|
|
|
|
598
|
|
|
$result = $GLOBALS['operations']->deleteMessages($store, $parentEntryId, $props[PR_ENTRYID]); |
599
|
|
|
|
600
|
|
|
if ($result) { |
601
|
|
|
$GLOBALS['bus']->notify(bin2hex((string) $parentEntryId), TABLE_DELETE, $props); |
602
|
|
|
} |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
/** |
606
|
|
|
* This function searches the private contact folders for users and returns an array with data. |
607
|
|
|
* Please note that the returning array must be UTF8. |
608
|
|
|
* |
609
|
|
|
* @param resource $ab The addressbook |
610
|
|
|
* @param resource $ab_dir The addressbook container |
611
|
|
|
* @param string $searchstr The search query, case is ignored |
612
|
|
|
*/ |
613
|
|
|
public function searchContactsFolders($ab, $ab_dir, $searchstr) { |
614
|
|
|
$r = []; |
615
|
|
|
$abhtable = mapi_folder_gethierarchytable($ab_dir, MAPI_DEFERRED_ERRORS | CONVENIENT_DEPTH); |
616
|
|
|
$abcntfolders = mapi_table_queryallrows($abhtable, [PR_ENTRYID, PR_AB_PROVIDER_ID, PR_DISPLAY_NAME]); |
617
|
|
|
$restriction = [ |
618
|
|
|
RES_CONTENT, |
619
|
|
|
[ |
620
|
|
|
FUZZYLEVEL => FL_SUBSTRING | FL_IGNORECASE, |
621
|
|
|
ULPROPTAG => PR_SMTP_ADDRESS, |
622
|
|
|
VALUE => [PR_SMTP_ADDRESS => $searchstr], |
623
|
|
|
], |
624
|
|
|
]; |
625
|
|
|
// restriction on hierarchy table for PR_AB_PROVIDER_ID |
626
|
|
|
// seems not to work, just loop through |
627
|
|
|
foreach ($abcntfolders as $abcntfolder) { |
628
|
|
|
if ($abcntfolder[PR_AB_PROVIDER_ID] == ZARAFA_CONTACTS_GUID) { |
629
|
|
|
$abfldentry = mapi_ab_openentry($ab, $abcntfolder[PR_ENTRYID]); |
630
|
|
|
$abfldcontents = mapi_folder_getcontentstable($abfldentry); |
631
|
|
|
mapi_table_restrict($abfldcontents, $restriction); |
632
|
|
|
$r = mapi_table_queryallrows($abfldcontents, [PR_ENTRYID]); |
633
|
|
|
if (is_array($r) && !empty($r)) { |
634
|
|
|
return $r; |
635
|
|
|
} |
636
|
|
|
} |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
return $r; |
640
|
|
|
} |
641
|
|
|
} |
642
|
|
|
|