예제 #1
0
 function tearDown()
 {
     $aOptions = array('ignore_permissions' => true);
     KTFolderUtil::delete($this->oFolder, $this->oUser, 'test case', $aOptions);
 }
예제 #2
0
 /**
  * COPY method helper for Folders
  *
  * @param  array   parameter passing array
  * @param  int     Parent Folder ID
  * @return string  HTTP status code or false
  */
 function _COPYFolder($options, $iFolderID)
 {
     /* ** Ensure that the destination path exists ** */
     if ($options['dest'] == '') {
         $options["dest"] = substr($options["dest_url"], strlen($_SERVER["SCRIPT_NAME"]));
     }
     $this->ktwebdavLog("Entering _COPYFolder. options are " . print_r($options, true), 'info', true);
     /* ** RFC 2518 Section 8.8.3. DAV compliant servers must support depth headers of '0' and 'infinity'.
        Check the requested depth. If depth is set to '0', set copyall to false. A depth of 0 indicates
        that the folder is copied without any children. If depth is set to '1', return a 400 error. ** */
     $copyAll = true;
     if ($options["depth"] != "infinity") {
         if ($options['depth'] == '0') {
             $copyAll = false;
             $this->ktwebdavLog("Depth is 0. Copy only the base folder.", 'info', true);
         } else {
             $this->ktwebdavLog("400 Bad request. Depth must be infinity or 0.", 'info', true);
             return "400 Bad request - Depth must be 'infinity' or '0'.";
         }
     }
     global $default;
     $new = true;
     /* ** Get the relevant paths. Get the basename of the destination path as the destination path name.
        Check whether the destination path refers to a folder / document. ** */
     $source_path = $options["path"];
     $dest_path = urldecode($options["dest"]);
     $sDestPathName = basename($dest_path);
     list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path);
     /* ** Get the source and destination folder objects.
        If the destination document is null, then the destination is an existing folder. Check overwrite.
        If overwrite is true, then check permissions and delete the folder, continue.
        If the destination document returns an id, then the destination is a document, return 409 error.
        If the destination document is false, then continue. ** */
     $oSrcFolder = Folder::get($iFolderID);
     $oDestFolder = Folder::get($iDestFolder);
     include_once KT_LIB_DIR . '/foldermanagement/folderutil.inc.php';
     if (is_null($iDestDoc)) {
         // Destination is a folder and exists
         //$sDestPathName = '';
         $this->ktwebdavLog("Destination Folder exists.", 'info', true);
         $oReplaceFolder = $oDestFolder;
         if ($options['overwrite'] != 'T') {
             $this->ktwebdavLog("Overwrite needs to be TRUE.", 'info', true);
             return "412 Precondition Failed - Destination Folder exists. Overwrite needs to be TRUE.";
         }
         $this->ktwebdavLog("Overwrite is TRUE, deleting Destination Folder.", 'info', true);
         // Check if the user has permissions to delete this folder
         $oPerm =& KTPermission::getByName('ktcore.permissions.delete');
         $oUser =& User::get($this->userID);
         if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oReplaceFolder)) {
             return "403 Forbidden - User does not have sufficient permissions";
         }
         KTFolderUtil::delete($oReplaceFolder, $oUser, 'KTWebDAV move overwrites target.');
         // Destination folder has been deleted - get new object of destination parent folder
         list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path);
         $oDestFolder = Folder::get($iDestFolder);
         $new = false;
     } else {
         if ($iDestDoc !== false) {
             // Destination is a document
             return "409 Conflict - Can't write a collection to a document";
         }
     }
     /* ** Get the destination folder object and the source document object.
        Check if user has permission to write to the folder.
        Copy the document. Pass parameters for the destination folder name and the depth of copy. ** */
     $oUser =& User::get($this->userID);
     $this->ktwebdavLog("Got an oSrcFolder of " . print_r($oSrcFolder, true), 'info', true);
     $this->ktwebdavLog("Got an oDestFolder of " . print_r($oDestFolder, true), 'info', true);
     $this->ktwebdavLog("Got an oUser of " . print_r($oUser, true), 'info', true);
     // Check if the user has permissions to write in this folder
     $oPerm =& KTPermission::getByName('ktcore.permissions.write');
     $oUser =& User::get($this->userID);
     if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oDestFolder)) {
         return "403 Forbidden - User does not have sufficient permissions";
     }
     $reason = isset($_SERVER['HTTP_REASON']) && !empty($_SERVER['HTTP_REASON']) ? $_SERVER['HTTP_REASON'] : "KTWebDAV Copy.";
     $res = KTFolderUtil::copy($oSrcFolder, $oDestFolder, $oUser, $reason, $sDestPathName, $copyAll);
     if (PEAR::isError($res)) {
         $this->ktwebdavLog("Copy on folder failed: " . $res->getMessage(), 'info', true);
         return "500 Internal Server Error - Copy on folder failed.";
     }
     if ($new) {
         $this->ktwebdavLog("201 Created", 'info', true);
         return "201 Created";
     } else {
         $this->ktwebdavLog("204 No Content", 'info', true);
         return "204 No Content";
     }
 }
예제 #3
0
 function do_removeUnit()
 {
     $oUnit =& $this->oValidator->validateUnit($_REQUEST['unit_id']);
     $bDeleteFolder = KTUtil::arrayGet($_REQUEST, 'delete_folder', false);
     $res = $oUnit->delete();
     $aOptions = array('redirect_to' => array('main'), 'message' => _kt("Could not delete this unit because it has groups assigned to it"), 'no_exception' => true);
     $this->oValidator->notError($res, $aOptions);
     if ($bDeleteFolder) {
         $iFolderId = $oUnit->getFolderId();
         $oFolder = Folder::get($iFolderId);
         if (!PEAR::isError($oFolder) && $oFolder !== false) {
             $aOptions = array('ignore_permissions' => true);
             KTFolderUtil::delete($oFolder, $this->oUser, "Unit deleted", $aOptions);
         }
     }
     $this->successRedirectToMain(_kt("Unit removed"));
 }
예제 #4
0
 function perform_action($oEntity)
 {
     $sReason = $this->res['reason'];
     if (is_a($oEntity, 'Document')) {
         $res = KTDocumentUtil::delete($oEntity, $sReason);
     } else {
         if (is_a($oEntity, 'Folder')) {
             $res = KTFolderUtil::delete($oEntity, $this->oUser, $sReason);
         }
     }
     return $res;
 }
예제 #5
0
 /**
  * This deletes the current folder.
  *
  * <code>
  * $kt = new KTAPI();
  * $kt->start_session("admin", "admin");
  * $folder = $kt->get_folder_by_name("My New folder");
  * $folder->delete("It was getting old!");
  * </code>
  *
  * @author KnowledgeTree Team
  * @access public
  * @param string $reason
  */
 function delete($reason)
 {
     $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_DELETE);
     if (PEAR::isError($user)) {
         return $user;
     }
     if ($this->folderid == 1) {
         return new PEAR_Error('Cannot delete root folder!');
     }
     DBUtil::startTransaction();
     $result = KTFolderUtil::delete($this->folder, $user, $reason);
     if (PEAR::isError($result)) {
         DBUtil::rollback();
         return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $result);
     }
     DBUtil::commit();
 }
예제 #6
0
 function perform_action($oEntity)
 {
     $sReason = $this->res['reason'];
     if (is_a($oEntity, 'Document')) {
         $res = KTDocumentUtil::delete($oEntity, $sReason, null, true);
         if (PEAR::isError($res)) {
             return $res;
         }
         return "RemoveChildDocument";
     } else {
         if (is_a($oEntity, 'Folder')) {
             $res = KTFolderUtil::delete($oEntity, $this->oUser, $sReason, null, true);
             if (PEAR::isError($res)) {
                 return $res;
             }
             return "RemoveChildFolder";
         }
     }
 }