1 | <?php |
||||
2 | |||||
3 | /** |
||||
4 | * This class is just static class and will not be instantiate and |
||||
5 | * It contains the functionality to get freebusy message and folder. |
||||
6 | */ |
||||
7 | class FreeBusy { |
||||
8 | /** |
||||
9 | * PR_FREEBUSY_ENTRYIDS contains 4 entryids |
||||
10 | * PR_FREEBUSY_ENTRYIDS[0] gives associated freebusy folder in calendar |
||||
11 | * PR_FREEBUSY_ENTRYIDS[1] Localfreebusy (used for delegate properties) |
||||
12 | * PR_FREEBUSY_ENTRYIDS[2] global Freebusydata in public store |
||||
13 | * PR_FREEBUSY_ENTRYIDS[3] Freebusydata in IPM_SUBTREE. |
||||
14 | */ |
||||
15 | public const ASSOCIATED_FREEBUSY_FOLDER = 0; |
||||
16 | public const DELEGATE_PROPERTIES = 1; |
||||
17 | public const GLOBAL_FREEBUSYDATA = 2; |
||||
18 | public const FREEBUSYDATA_IPM_SUBTREE = 3; |
||||
19 | |||||
20 | /** |
||||
21 | * Function will return resource of the local freebusy message of the user's store. |
||||
22 | * |
||||
23 | * @param mixed $store (optional) user's store |
||||
24 | * |
||||
25 | * @return bool|resource local freebusy message, otherwise false if message not found |
||||
26 | */ |
||||
27 | public static function getLocalFreeBusyMessage($store = false) { |
||||
28 | if (!$store) { |
||||
29 | error_log("getLocalFreeBusyMessage: store not available"); |
||||
30 | |||||
31 | return false; |
||||
32 | } |
||||
33 | |||||
34 | // Check for mapi_freebusy_openmsg function, |
||||
35 | // If yes then use mapi function to get freebusy message. |
||||
36 | if (function_exists('mapi_freebusy_openmsg')) { |
||||
37 | return mapi_freebusy_openmsg($store); |
||||
38 | } |
||||
39 | |||||
40 | // Get 'LocalFreeBusy' message from FreeBusy Store |
||||
41 | $root = mapi_msgstore_openentry($store, null); |
||||
42 | $storeProps = mapi_getprops($root, [PR_FREEBUSY_ENTRYIDS]); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
43 | $localFreeBusyEntryids = $storeProps[PR_FREEBUSY_ENTRYIDS]; |
||||
44 | |||||
45 | try { |
||||
46 | return mapi_msgstore_openentry($store, $localFreeBusyEntryids[self::DELEGATE_PROPERTIES]); |
||||
0 ignored issues
–
show
|
|||||
47 | } |
||||
48 | catch (MAPIException $e) { |
||||
49 | // Either user store have malformed entryid in PR_FREEBUSY_ENTRYIDS or |
||||
50 | // No message found of given entryid in 'Freebusy Data' folder. |
||||
51 | if ($e->getCode() == MAPI_E_NOT_FOUND || $e->getCode() == MAPI_E_INVALID_ENTRYID) { |
||||
52 | $freeBusyFolder = mapi_msgstore_openentry($store, $localFreeBusyEntryids[self::FREEBUSYDATA_IPM_SUBTREE]); |
||||
53 | $table = mapi_folder_getcontentstable($freeBusyFolder); |
||||
0 ignored issues
–
show
It seems like
$freeBusyFolder can also be of type false ; however, parameter $fld of mapi_folder_getcontentstable() does only seem to accept resource , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
54 | mapi_table_restrict( |
||||
55 | $table, |
||||
0 ignored issues
–
show
It seems like
$table can also be of type false ; however, parameter $table of mapi_table_restrict() does only seem to accept resource , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
56 | [ |
||||
57 | RES_CONTENT, |
||||
58 | [ |
||||
59 | FUZZYLEVEL => FL_PREFIX, |
||||
60 | ULPROPTAG => PR_MESSAGE_CLASS, |
||||
61 | VALUE => [PR_MESSAGE_CLASS => "IPM.Microsoft.ScheduleData.FreeBusy"], |
||||
62 | ], |
||||
63 | ] |
||||
64 | ); |
||||
65 | |||||
66 | $items = mapi_table_queryallrows($table, [PR_ENTRYID]); |
||||
0 ignored issues
–
show
It seems like
$table can also be of type false ; however, parameter $table of mapi_table_queryallrows() does only seem to accept resource , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
67 | if (empty($items)) { |
||||
68 | // FIXME recreate local freebusy message in 'Freebusy Data' folder. |
||||
69 | error_log("Unable to find local free busy message in 'Freebusy Data' folder"); |
||||
70 | |||||
71 | return false; |
||||
72 | } |
||||
73 | |||||
74 | $localFreeBusyEntryids[1] = $items[0][PR_ENTRYID]; |
||||
75 | |||||
76 | // Updating the entryid in the PR_FREEBUSY_ENTRYIDS property of user store. |
||||
77 | mapi_setprops($root, [PR_FREEBUSY_ENTRYIDS => $localFreeBusyEntryids]); |
||||
0 ignored issues
–
show
It seems like
$root can also be of type false ; however, parameter $any of mapi_setprops() does only seem to accept resource , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
78 | mapi_savechanges($root); |
||||
0 ignored issues
–
show
It seems like
$root can also be of type false ; however, parameter $any of mapi_savechanges() does only seem to accept resource , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
79 | |||||
80 | return mapi_msgstore_openentry($store, $localFreeBusyEntryids[self::DELEGATE_PROPERTIES]); |
||||
0 ignored issues
–
show
|
|||||
81 | } |
||||
82 | |||||
83 | // Ensure to return false if an exception occurs |
||||
84 | error_log("getLocalFreeBusyMessage: unhandled MAPIException " . $e->getMessage()); |
||||
85 | return false; |
||||
86 | |||||
87 | } |
||||
88 | |||||
89 | // Fallback, should not typically reach here. |
||||
90 | error_log("getLocalFreeBusyMessage: reached unexpected code path"); |
||||
91 | return false; |
||||
92 | |||||
93 | } |
||||
94 | |||||
95 | /** |
||||
96 | * Function will return resource of the freebusy folder of the user's store. |
||||
97 | * |
||||
98 | * @param mixed $store (optional) user's store |
||||
99 | * |
||||
100 | * @return bool|resource freebusy folder |
||||
101 | */ |
||||
102 | public static function getLocalFreeBusyFolder($store = false) { |
||||
103 | if (!$store) { |
||||
104 | error_log("getLocalFreeBusyFolder: store not available"); |
||||
105 | |||||
106 | return false; |
||||
107 | } |
||||
108 | // Get 'LocalFreeBusy' message from FreeBusy Store |
||||
109 | $root = mapi_msgstore_openentry($store, null); |
||||
110 | $storeProps = mapi_getprops($root, [PR_FREEBUSY_ENTRYIDS]); |
||||
0 ignored issues
–
show
It seems like
$root can also be of type false ; however, parameter $any of mapi_getprops() does only seem to accept resource , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
111 | |||||
112 | return mapi_msgstore_openentry($store, $storeProps[PR_FREEBUSY_ENTRYIDS][self::FREEBUSYDATA_IPM_SUBTREE]); |
||||
0 ignored issues
–
show
|
|||||
113 | } |
||||
114 | } |
||||
115 |