Exemple #1
0
 /**
  * Returns an array of SyncFolder types with the entire folder hierarchy
  * on the server (the array itself is flat, but refers to parents via the 'parent' property
  *
  * provides AS 1.0 compatibility
  *
  * @access public
  * @return array SYNC_FOLDER
  */
 public function GetHierarchy()
 {
     $folders = array();
     $mapiprovider = new MAPIProvider($this->session, $this->store);
     $storeProps = $mapiprovider->GetStoreProps();
     // for SYSTEM user open the public folders
     if (strtoupper($this->storeName) == "SYSTEM") {
         $rootfolder = mapi_msgstore_openentry($this->store, $storeProps[PR_IPM_PUBLIC_FOLDERS_ENTRYID]);
     } else {
         $rootfolder = mapi_msgstore_openentry($this->store);
     }
     $rootfolderprops = mapi_getprops($rootfolder, array(PR_SOURCE_KEY));
     $hierarchy = mapi_folder_gethierarchytable($rootfolder, CONVENIENT_DEPTH);
     $rows = mapi_table_queryallrows($hierarchy, array(PR_DISPLAY_NAME, PR_PARENT_ENTRYID, PR_ENTRYID, PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY, PR_CONTAINER_CLASS, PR_ATTR_HIDDEN, PR_EXTENDED_FOLDER_FLAGS, PR_FOLDER_TYPE));
     foreach ($rows as $row) {
         // do not display hidden and search folders
         if (isset($row[PR_ATTR_HIDDEN]) && $row[PR_ATTR_HIDDEN] || isset($row[PR_FOLDER_TYPE]) && $row[PR_FOLDER_TYPE] == FOLDER_SEARCH || isset($row[PR_PARENT_SOURCE_KEY]) && $row[PR_PARENT_SOURCE_KEY] == $rootfolderprops[PR_SOURCE_KEY] && strtoupper($this->storeName) != "SYSTEM") {
             continue;
         }
         $folder = $mapiprovider->GetFolder($row);
         if ($folder) {
             $folders[] = $folder;
         }
     }
     // reloop the folders to make sure all parentids are mapped correctly
     $dm = ZPush::GetDeviceManager();
     foreach ($folders as $folder) {
         if ($folder->parentid !== "0") {
             // SYSTEM user's parentid points to $rootfolderprops[PR_SOURCE_KEY], but they need to be on the top level
             $folder->parentid = strtoupper($this->storeName) == "SYSTEM" && $folder->parentid == bin2hex($rootfolderprops[PR_SOURCE_KEY]) ? '0' : $dm->GetFolderIdForBackendId($folder->parentid);
         }
     }
     return $folders;
 }