Test Failed
Push — master ( 647c72...cd42b5 )
by
unknown
10:25
created

modules/class.outofofficesettingsmodule.php (2 issues)

1
<?php
2
	/**
3
	 * OutOfOfficeSettingsModule Module
4
	 */
5
	class OutOfOfficeSettingsModule extends Module
6
	{
7
		/**
8
		 * Constructor
9
		 * @param int $id unique id.
10
		 * @param array $data list of all actions.
11
		 */
12
		function __construct($id, $data)
13
		{
14
			parent::__construct($id, $data);
15
		
16
			$this->properties = $GLOBALS["properties"]->getOutOfOfficeProperties();
17
		}
18
19
		/**
20
		 * Executes all the actions in the $data variable.
21
		 */
22
		function execute()
23
		{
24
			foreach ($this->data as $actionType => $action) {
25
				if (isset($actionType)) {
26
					try {
27
						switch ($actionType) {
28
							case "list" :
29
								$this->getOofSettings();
30
								break;
31
							case "save" :
32
								$this->saveOofSettings($action);
33
								break;
34
							default:
35
								$this->handleUnknownActionType($actionType);
36
						}
37
					} catch (SettingsException $e) {
38
						$this->processException($e, $actionType);
39
					} catch (MAPIException $e) {
40
						$this->processException($e, $actionType);
41
					}
42
				 }
43
			}
44
		}
45
46
		/**
47
		 * Read 'out of office' settings from PR_EC_OUTOFOFFICE_*
48
		 *
49
		 * Internal function to retrieve the 'out of office' settings from the store, these settings are normal properties on the store
50
		 * @access private
51
		 */
52
		function getOofSettings()
53
		{
54
			$otherStores = $this->getOwnerPermissionStores();
55
			array_unshift($otherStores, $GLOBALS['mapisession']->getDefaultMessageStore());
56
57
			$oofSettings = Array();
58
			foreach ($otherStores as $storeEntryId => $storeObj) {
59
				$props = mapi_getprops($storeObj, $this->properties);
60
				if (!isset($props[PR_EC_OUTOFOFFICE_STATE])) {
61
					$props[PR_EC_OUTOFOFFICE_STATE] = false;
62
				}
63
				if (!isset($props[PR_EC_OUTOFOFFICE_INTERNALREPLY])) {
64
					$props[PR_EC_OUTOFOFFICE_INTERNALREPLY] = '';
65
				}
66
				if (!isset($props[PR_EC_OUTOFOFFICE_INTERNALSUBJECT])) {
67
					$props[PR_EC_OUTOFOFFICE_INTERNALSUBJECT] = '';
68
				}
69
				if (!isset($props[PR_EC_OUTOFOFFICE_BEGIN])) {
70
					$props[PR_EC_OUTOFOFFICE_BEGIN] = 0;
71
				}
72
				if (!isset($props[PR_EC_OUTOFOFFICE_END]) || $props[PR_EC_OUTOFOFFICE_END] === FUTURE_ENDDATE) {
73
					$props[PR_EC_OUTOFOFFICE_END] = 0;
74
				}
75
				if (!isset($props[PR_EC_OUTOFOFFICE_ALLOWEXTERNAL])) {
76
					$props[PR_EC_OUTOFOFFICE_ALLOWEXTERNAL] = 0;
77
				}
78
				if (!isset($props[PR_EC_OUTOFOFFICE_EXTERNALAUDIENCE])) {
79
					$props[PR_EC_OUTOFOFFICE_EXTERNALAUDIENCE] = 0;
80
				}
81
				if (!isset($props[PR_EC_OUTOFOFFICE_EXTERNALREPLY])) {
82
					$props[PR_EC_OUTOFOFFICE_EXTERNALREPLY] = '';
83
				}
84
				if (!isset($props[PR_EC_OUTOFOFFICE_EXTERNALSUBJECT])) {
85
					$props[PR_EC_OUTOFOFFICE_EXTERNALSUBJECT] = '';
86
				}
87
88
				$externalProps['props']['entryid'] = bin2hex($props[PR_MAILBOX_OWNER_ENTRYID]);
89
				$externalProps['props']['store_entryid'] = bin2hex($props[PR_ENTRYID]);
90
				$externalProps['props']['set'] = $props[PR_EC_OUTOFOFFICE_STATE];
91
				$externalProps['props']['internal_reply'] = trim($props[PR_EC_OUTOFOFFICE_INTERNALREPLY]);
92
				$externalProps['props']['internal_subject'] = trim($props[PR_EC_OUTOFOFFICE_INTERNALSUBJECT]);
93
				$externalProps['props']['from'] = $props[PR_EC_OUTOFOFFICE_BEGIN];
94
				$externalProps['props']['until'] = $props[PR_EC_OUTOFOFFICE_END];
95
				$externalProps['props']['allow_external'] = $props[PR_EC_OUTOFOFFICE_ALLOWEXTERNAL];
96
				$externalProps['props']['external_audience'] = $props[PR_EC_OUTOFOFFICE_EXTERNALAUDIENCE];
97
				$externalProps['props']['external_reply'] = trim($props[PR_EC_OUTOFOFFICE_EXTERNALREPLY]);
98
				$externalProps['props']['external_subject'] = trim($props[PR_EC_OUTOFOFFICE_EXTERNALSUBJECT]);
99
100
				array_push($oofSettings, $externalProps);
101
			}
102
103
			// Send success message to client
104
			$this->addActionData('list', Array('item' => $oofSettings));
105
106
			$GLOBALS["bus"]->addData($this->getResponseData());
107
		}
108
109
		/**
110
		 * Function returns array of user stores who has given 'Owner' permission to logged in user.
111
		 * Internal function to retrieve the shared stores with 'owner' permission.
112
		 * @access private
113
		 * @return {Array} array of user stores who has given 'owner' permission.
114
		 */
115
		function getOwnerPermissionStores()
116
		{
117
			$stores = $GLOBALS['mapisession']->getOtherUserStore();
118
119
			// $sharedOwnerStores array will contains store of users who has given 'owner' permission.
120
			// Or store of users which can be fully accessible by default user in case of 'Admin User'.
121
			$sharedOwnerStores = array();
122
123
			foreach ($stores as $storeEntryId => $storeObj) {
124
				$subTree = mapi_getprops($storeObj, array(PR_IPM_SUBTREE_ENTRYID));
125
				try {
126
					$subtreeObj = mapi_msgstore_openentry($storeObj, $subTree[PR_IPM_SUBTREE_ENTRYID]);
127
				} catch (MAPIException $e) {
128
					// we don't have rights to open folder, so don't include User's store.
129
					if ($e->getCode() === MAPI_E_NO_ACCESS) {
130
						continue;
131
					}
132
					// rethrow other errors
133
					throw $e;
134
				}
135
136
				$permission = mapi_getprops($subtreeObj, array(PR_RIGHTS));
137
				$hasSufficientPermission = $permission[PR_RIGHTS]&ecRightsSecretary === ecRightsSecretary;
138
139
				// If User store's IPM subtree has rights higher than 'secretary' then include that User's store.
140
				if ($hasSufficientPermission) {
141
					$sharedOwnerStores[$storeEntryId] = $storeObj;
142
				}
143
			}
144
145
			return $sharedOwnerStores;
146
		}
147
148
		/**
149
		 * Internal function to save the 'out of office' settings to the correct properties on the store.
150
		 * On success function will send 'success' feedback to user.
151
		 *
152
		 * Writes some properties to the PR_EC_OUTOFOFFICE_* properties
153
		 *
154
		 * @param array $action the action data, sent by the client
155
		 * @access private
156
		 */
157
		function saveOofSettings($action)
158
		{
159
			$storeEntryId = $action['store_entryid'];
160
			$oofSettings = $action['props'];
161
			$store = $GLOBALS['mapisession']->openMessageStore(hex2bin($storeEntryId));
162
			$props = Conversion::mapXML2MAPI($this->properties, $oofSettings);
163
164
			// If client sent until value as 0 or User set OOF to true but don't set until
165
			// then save FUTURE_ENDDATE as until date. Also when OOF is already ON and User
166
			// don't change 'until' field then check if 'until' value is available in User's store
167
			// and if not then set until date to FUTURE_ENDDATE.
168
			// Note: If we remove PR_EC_OUTOFOFFICE_END property from User's store,
169
			// then gromox is setting past value "1970-01-01 00:00:00" as until date.
170
			// To avoid this issue and for OOF to work as expected, we are setting until date as FUTURE_ENDDATE.
171
			if (isset($oofSettings['until']) && $oofSettings['until'] === 0 ||
0 ignored issues
show
Consider adding parentheses for clarity. Current Interpretation: (IssetNode && $oofSettin... IssetNode && IssetNode, Probably Intended Meaning: IssetNode && ($oofSettin...IssetNode && IssetNode)
Loading history...
172
				!isset($oofSettings['until']) && isset($oofSettings['set'])) {
173
				$props[$this->properties['until']] = FUTURE_ENDDATE;
174
			} else if (!isset($oofSettings['until'], $oofSettings['set'])) {
175
				$untilProp = mapi_getprops($store, array(PR_EC_OUTOFOFFICE_END));
176
				if (!isset($untilProp[PR_EC_OUTOFOFFICE_END]) || $untilProp[PR_EC_OUTOFOFFICE_END] === 0) {
177
					$props[$this->properties['until']] = FUTURE_ENDDATE;
178
				}
179
			}
180
181
			if (!empty($props))	{
182
				mapi_setprops($store, $props);
183
				mapi_savechanges($store);
184
			}
185
			$this->sendFeedback(true);
186
		}
187
	}
188
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

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.

Loading history...
189