Merge pull request #18 in KWA/mobile-device-management from bugfix/KMP-55-adding-single-shared-folder-in-manage-share-folder-is-not-working to master
* commit 'e45ea00b83165e9e9f84034b5b3fc499b9387bc7': Adding single shared folder in manage share folder is not working
This commit is contained in:
		| @@ -8,13 +8,6 @@ Ext.namespace('Zarafa.plugins.mdm.data'); | ||||
|  */ | ||||
| Zarafa.plugins.mdm.data.MDMDeviceFolderStore = Ext.extend(Zarafa.core.data.MAPISubStore, { | ||||
|  | ||||
| 	/** | ||||
| 	 * @cfg {Zarafa.core.data.RecordCustomObjectType} customObjectType The custom object type | ||||
| 	 * which represents the {@link Ext.data.Record records} which should be created using | ||||
| 	 * {@link Zarafa.core.data.RecordFactory#createRecordObjectByCustomType}. | ||||
| 	 */ | ||||
| 	customObjectType: Zarafa.core.data.RecordCustomObjectType.MDM_Device_Folder, | ||||
|  | ||||
| 	/** | ||||
| 	 * @constructor | ||||
| 	 * @param config Configuration object | ||||
| @@ -27,7 +20,7 @@ Zarafa.plugins.mdm.data.MDMDeviceFolderStore = Ext.extend(Zarafa.core.data.MAPIS | ||||
| 			autoLoad: true, | ||||
| 			remoteSort: false, | ||||
| 			reader: new Zarafa.plugins.mdm.data.JsonDeviceFolderReader({ | ||||
| 				customObjectType: this.customObjectType | ||||
| 				customObjectType: Zarafa.core.data.RecordCustomObjectType.MDM_Device_Folder | ||||
| 			}), | ||||
| 			writer: new Zarafa.plugins.mdm.data.MDMDeviceFolderWriter(), | ||||
| 			proxy: new Zarafa.core.data.IPMProxy({ | ||||
|   | ||||
| @@ -453,19 +453,37 @@ class PluginMDMModule extends Module | ||||
| 	{ | ||||
| 		$storeList = $GLOBALS["mapisession"]->getAllMessageStores(); | ||||
| 		$properties = $GLOBALS["properties"]->getFolderListProperties(); | ||||
| 		$otherUsers = $GLOBALS["mapisession"]->retrieveOtherUsersFromSettings(); | ||||
| 		$properties["source_key"] = PR_SOURCE_KEY; | ||||
| 		$openWholeStore = true; | ||||
| 		$storeData = array(); | ||||
|  | ||||
| 		foreach ($storeList as $store) { | ||||
|             $msgstore_props = mapi_getprops($store, array(PR_ENTRYID, PR_DISPLAY_NAME, PR_IPM_SUBTREE_ENTRYID, PR_IPM_OUTBOX_ENTRYID, PR_IPM_SENTMAIL_ENTRYID, PR_IPM_WASTEBASKET_ENTRYID, PR_MDB_PROVIDER, PR_IPM_PUBLIC_FOLDERS_ENTRYID, PR_IPM_FAVORITES_ENTRYID, PR_OBJECT_TYPE, PR_STORE_SUPPORT_MASK, PR_MAILBOX_OWNER_ENTRYID, PR_MAILBOX_OWNER_NAME, PR_USER_ENTRYID, PR_USER_NAME, PR_QUOTA_WARNING_THRESHOLD, PR_QUOTA_SEND_THRESHOLD, PR_QUOTA_RECEIVE_THRESHOLD, PR_MESSAGE_SIZE_EXTENDED, PR_MAPPING_SIGNATURE, PR_COMMON_VIEWS_ENTRYID, PR_FINDER_ENTRYID)); | ||||
| 			$msgstore_props = mapi_getprops($store, array(PR_MDB_PROVIDER, PR_ENTRYID, PR_IPM_SUBTREE_ENTRYID, PR_USER_NAME)); | ||||
| 			$storeType = $msgstore_props[PR_MDB_PROVIDER]; | ||||
|  | ||||
|             if ($storeType == ZARAFA_STORE_DELEGATE_GUID) { | ||||
| 			if ($storeType == ZARAFA_SERVICE_GUID) { | ||||
| 				continue; | ||||
| 			} else if ($storeType == ZARAFA_STORE_DELEGATE_GUID) { | ||||
| 				$storeUserName = $GLOBALS["mapisession"]->getUserNameOfStore($msgstore_props[PR_ENTRYID]); | ||||
| 			} else if ($storeType == ZARAFA_STORE_PUBLIC_GUID) { | ||||
| 				$storeUserName = "SYSTEM"; | ||||
| 			} else { | ||||
| 				$storeUserName = $msgstore_props[PR_USER_NAME]; | ||||
| 			} | ||||
|  | ||||
| 			if (is_array($otherUsers)) { | ||||
| 				if (isset($otherUsers[$storeUserName])) { | ||||
| 					$sharedFolders = $otherUsers[$storeUserName]; | ||||
| 					if (!isset($otherUsers[$storeUserName]['all'])) { | ||||
| 						$openWholeStore = false; | ||||
| 						$a = $this->getSharedFolderList($store, $sharedFolders, $properties, $storeUserName); | ||||
| 						$storeData = array_merge($storeData, $a); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 			if ($openWholeStore) { | ||||
| 				if (isset($msgstore_props[PR_IPM_SUBTREE_ENTRYID])) { | ||||
| 					$subtreeFolderEntryID = $msgstore_props[PR_IPM_SUBTREE_ENTRYID]; | ||||
| 					try { | ||||
| @@ -474,10 +492,144 @@ class PluginMDMModule extends Module | ||||
| 						// We've handled the event | ||||
| 						$e->setHandled(); | ||||
| 					} | ||||
|                 try { | ||||
| 					$this->getSubFolders($subtreeFolder, $store, $properties, $storeData, $storeUserName); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
|                      // remove hidden folders, folders with PR_ATTR_HIDDEN property set | ||||
|                      // should not be shown to the client | ||||
| 		return $storeData; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Helper function to get the shared folder list. | ||||
| 	 * @param object $store Message Store Object. | ||||
| 	 * @param object $sharedFolders Mapi Folder Object. | ||||
| 	 * @param array $properties MAPI property mappings for folders. | ||||
| 	 * @param string $storeUserName owner name of store. | ||||
| 	 * @return array shared folders list. | ||||
| 	 */ | ||||
| 	function getSharedFolderList($store, $sharedFolders, $properties, $storeUserName) | ||||
| 	{ | ||||
| 		$msgstore_props = mapi_getprops($store, array(PR_ENTRYID, PR_DISPLAY_NAME, PR_IPM_SUBTREE_ENTRYID, PR_IPM_OUTBOX_ENTRYID, PR_IPM_SENTMAIL_ENTRYID, PR_IPM_WASTEBASKET_ENTRYID, PR_MDB_PROVIDER, PR_IPM_PUBLIC_FOLDERS_ENTRYID, PR_IPM_FAVORITES_ENTRYID, PR_OBJECT_TYPE, PR_STORE_SUPPORT_MASK, PR_MAILBOX_OWNER_ENTRYID, PR_MAILBOX_OWNER_NAME, PR_USER_ENTRYID, PR_USER_NAME, PR_QUOTA_WARNING_THRESHOLD, PR_QUOTA_SEND_THRESHOLD, PR_QUOTA_RECEIVE_THRESHOLD, PR_MESSAGE_SIZE_EXTENDED, PR_MAPPING_SIGNATURE, PR_COMMON_VIEWS_ENTRYID, PR_FINDER_ENTRYID)); | ||||
| 		$storeData = array(); | ||||
| 		$folders = array(); | ||||
| 		try { | ||||
| 			$inbox = mapi_msgstore_getreceivefolder($store); | ||||
| 			$inboxProps = mapi_getprops($inbox, array(PR_ENTRYID)); | ||||
| 		} catch (MAPIException $e) { | ||||
| 			// don't propogate this error to parent handlers, if store doesn't support it | ||||
| 			if ($e->getCode() === MAPI_E_NO_SUPPORT) { | ||||
| 				$e->setHandled(); | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		$root = mapi_msgstore_openentry($store, null); | ||||
| 		$rootProps = mapi_getprops($root, array(PR_IPM_APPOINTMENT_ENTRYID, PR_IPM_CONTACT_ENTRYID, PR_IPM_DRAFTS_ENTRYID, PR_IPM_JOURNAL_ENTRYID, PR_IPM_NOTE_ENTRYID, PR_IPM_TASK_ENTRYID, PR_ADDITIONAL_REN_ENTRYIDS)); | ||||
|  | ||||
| 		$additional_ren_entryids = array(); | ||||
| 		if (isset($rootProps[PR_ADDITIONAL_REN_ENTRYIDS])) { | ||||
| 			$additional_ren_entryids = $rootProps[PR_ADDITIONAL_REN_ENTRYIDS]; | ||||
| 		} | ||||
|  | ||||
| 		$defaultfolders = array( | ||||
| 			"default_folder_inbox" => array("inbox" => PR_ENTRYID), | ||||
| 			"default_folder_outbox" => array("store" => PR_IPM_OUTBOX_ENTRYID), | ||||
| 			"default_folder_sent" => array("store" => PR_IPM_SENTMAIL_ENTRYID), | ||||
| 			"default_folder_wastebasket" => array("store" => PR_IPM_WASTEBASKET_ENTRYID), | ||||
| 			"default_folder_favorites" => array("store" => PR_IPM_FAVORITES_ENTRYID), | ||||
| 			"default_folder_publicfolders" => array("store" => PR_IPM_PUBLIC_FOLDERS_ENTRYID), | ||||
| 			"default_folder_calendar" => array("root" => PR_IPM_APPOINTMENT_ENTRYID), | ||||
| 			"default_folder_contact" => array("root" => PR_IPM_CONTACT_ENTRYID), | ||||
| 			"default_folder_drafts" => array("root" => PR_IPM_DRAFTS_ENTRYID), | ||||
| 			"default_folder_journal" => array("root" => PR_IPM_JOURNAL_ENTRYID), | ||||
| 			"default_folder_note" => array("root" => PR_IPM_NOTE_ENTRYID), | ||||
| 			"default_folder_task" => array("root" => PR_IPM_TASK_ENTRYID), | ||||
| 			"default_folder_junk" => array("additional" => 4), | ||||
| 			"default_folder_syncissues" => array("additional" => 1), | ||||
| 			"default_folder_conflicts" => array("additional" => 0), | ||||
| 			"default_folder_localfailures" => array("additional" => 2), | ||||
| 			"default_folder_serverfailures" => array("additional" => 3), | ||||
| 		); | ||||
|  | ||||
| 		foreach ($defaultfolders as $key => $prop) { | ||||
| 			$tag = reset($prop); | ||||
| 			$from = key($prop); | ||||
| 			switch ($from) { | ||||
| 				case "inbox": | ||||
| 					if (isset($inboxProps[$tag])) { | ||||
| 						$storeData["props"][$key] = bin2hex($inboxProps[$tag]); | ||||
| 					} | ||||
| 					break; | ||||
| 				case "store": | ||||
| 					if (isset($msgstore_props[$tag])) { | ||||
| 						$storeData["props"][$key] = bin2hex($msgstore_props[$tag]); | ||||
| 					} | ||||
| 					break; | ||||
| 				case "root": | ||||
| 					if (isset($rootProps[$tag])) { | ||||
| 						$storeData["props"][$key] = bin2hex($rootProps[$tag]); | ||||
| 					} | ||||
| 					break; | ||||
| 				case "additional": | ||||
| 					if (isset($additional_ren_entryids[$tag])) { | ||||
| 						$storeData["props"][$key] = bin2hex($additional_ren_entryids[$tag]); | ||||
| 					} | ||||
| 					break; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		$store_access = true; | ||||
| 		$openSubFolders = false; | ||||
| 		foreach ($sharedFolders as $type => $sharedFolder) { | ||||
| 			$openSubFolders = ($sharedFolder["show_subfolders"] == true); | ||||
| 			$folderEntryID = hex2bin($storeData["props"]["default_folder_" . $sharedFolder["folder_type"]]); | ||||
| 			try { | ||||
| 				// load folder props | ||||
| 				$folder = mapi_msgstore_openentry($store, $folderEntryID); | ||||
| 			} catch (MAPIException $e) { | ||||
| 				// Indicate that we don't have access to the store, | ||||
| 				// so no more attempts to read properties or open entries. | ||||
| 				$store_access = false; | ||||
|  | ||||
| 				// We've handled the event | ||||
| 				$e->setHandled(); | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		if ($store_access === true) { | ||||
| 			$folderProps = mapi_getprops($folder, $properties); | ||||
| 			$folderProps["user"] = $storeUserName; | ||||
| 			array_push($folders, $folderProps); | ||||
|  | ||||
| 			//If folder has sub folders then add its. | ||||
| 			if ($openSubFolders === true) { | ||||
| 				if ($folderProps[PR_SUBFOLDERS] != false) { | ||||
| 					$subFoldersData = array(); | ||||
| 					$this->getSubFolders($folder, $store, $properties, $subFoldersData, $storeUserName); | ||||
| 					$folders =array_merge($folders, $subFoldersData); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		return $folders; | ||||
| 	} | ||||
|  | ||||
|  | ||||
| 	/** | ||||
| 	 * Helper function to get the sub folders of a given folder. | ||||
| 	 * | ||||
| 	 * @access private | ||||
| 	 * @param object $folder Mapi Folder Object. | ||||
| 	 * @param object $store Message Store Object | ||||
| 	 * @param array $properties MAPI property mappings for folders | ||||
| 	 * @param array $storeData Reference to an array. The folder properties are added to this array. | ||||
| 	 * @param string $storeUserName owner name of store. | ||||
| 	 */ | ||||
| 	function getSubFolders($folder, $store, $properties, &$storeData, $storeUserName) | ||||
| 	{ | ||||
| 		/** | ||||
| 		 * remove hidden folders, folders with PR_ATTR_HIDDEN property set | ||||
| 		 * should not be shown to the client | ||||
| 		 */ | ||||
| 		$restriction = Array(RES_OR, Array( | ||||
| 			Array(RES_PROPERTY, | ||||
| 				Array( | ||||
| @@ -497,10 +649,11 @@ class PluginMDMModule extends Module | ||||
| 			) | ||||
| 		)); | ||||
|  | ||||
|  | ||||
| 		$expand = Array( | ||||
| 			Array( | ||||
|                             'folder' => $subtreeFolder, | ||||
|                             'props' => mapi_getprops($subtreeFolder, Array(PR_ENTRYID, PR_SUBFOLDERS)) | ||||
| 				'folder' => $folder, | ||||
| 				'props' => mapi_getprops($folder, Array(PR_ENTRYID, PR_SUBFOLDERS)) | ||||
| 			) | ||||
| 		); | ||||
|  | ||||
| @@ -510,16 +663,18 @@ class PluginMDMModule extends Module | ||||
| 		// it will be expanded later. | ||||
| 		while (!empty($expand)) { | ||||
| 			$item = array_shift($expand); | ||||
| 			$columns = $properties; | ||||
|  | ||||
| 			$hierarchyTable = mapi_folder_gethierarchytable($item['folder'], MAPI_DEFERRED_ERRORS); | ||||
| 			mapi_table_restrict($hierarchyTable, $restriction, TBL_BATCH); | ||||
|  | ||||
|                         mapi_table_setcolumns($hierarchyTable, $properties); | ||||
| 			mapi_table_setcolumns($hierarchyTable, $columns); | ||||
| 			$columns = null; | ||||
|  | ||||
| 			// Load the hierarchy in small batches | ||||
| 			$batchcount = 100; | ||||
| 			do { | ||||
|                             $rows = mapi_table_queryrows($hierarchyTable, null, 0, $batchcount); | ||||
| 				$rows = mapi_table_queryrows($hierarchyTable, $columns, 0, $batchcount); | ||||
|  | ||||
| 				foreach ($rows as $subfolder) { | ||||
|  | ||||
| @@ -537,17 +692,9 @@ class PluginMDMModule extends Module | ||||
| 				// When the server returned a different number of rows then was requested, | ||||
| 				// we have reached the end of the table and we should exit the loop. | ||||
| 			} while (count($rows) === $batchcount); | ||||
|                     } | ||||
|  | ||||
|                 } catch (MAPIException $e) { | ||||
|  | ||||
|                     // We've handled the event | ||||
|                     $e->setHandled(); | ||||
| 		} | ||||
| 	} | ||||
|         } | ||||
|         return $storeData; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| 	 * Function which is use get folder types from the container class | ||||
|   | ||||
		Reference in New Issue
	
	Block a user