Exemplo n.º 1
0
 /**
  * MOVE method helper for Documents
  *
  * @param  array  parameter passing array
  * @param  int    Folder ID
  * @param  int    Document ID
  * @return string  HTTP status code or false
  */
 function _MOVEDocument($options, $iFolderID, $iDocumentID)
 {
     /* ** Ensure that the destination path exists ** */
     if ($options['dest'] == '') {
         $options["dest"] = substr($options["dest_url"], strlen($_SERVER["SCRIPT_NAME"]));
     }
     $this->ktwebdavLog("Entering _MOVEDocument. options are " . print_r($options, true), 'info', true);
     // Fix for Mac Goliath
     // Modified - 25/10/07 - remove ktwebdav from document path
     if ($this->dav_client == 'MG' || $this->dav_client == 'MS') {
         $this->ktwebdavLog("Remove ktwebdav from destination path: " . $options['dest'], 'info', true);
         if (!(strpos($options['dest'], 'ktwebdav/ktwebdav.php/') === FALSE)) {
             $options['dest'] = substr($options['dest'], 22);
         }
         if ($options['dest'][0] != '/') {
             $options['dest'] = '/' . $options['dest'];
         }
     }
     global $default;
     $new = true;
     /* ** Get the relevant paths. Get the basename of the destination path as the destination filename.
        Check whether the destination path refers to a folder / document. ** */
     $oDocument = Document::get($iDocumentID);
     $oSrcFolder = Folder::get($iFolderID);
     $oUser =& User::get($this->userID);
     $source_path = $options["path"];
     $dest_path = urldecode($options["dest"]);
     /* ** Get the source folder object.
        If the destination document is null, then the destination is a folder, continue.
        If the destination document returns an id, then the document exists. Check overwrite.
        If overwrite is true, then check permissions and delete the document, continue.
        If the destination document is false, then continue. ** */
     list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path);
     if (is_null($iDestDoc)) {
         // the dest is a folder
         $this->ktwebdavLog("Destination is a folder.", 'info', true);
     } else {
         if ($iDestDoc !== false) {
             // Document exists
             $this->ktwebdavLog("Destination Document exists.", 'info', true);
             $oReplaceDoc = Document::get($iDestDoc);
             if ($options['overwrite'] != 'T') {
                 $this->ktwebdavLog("Overwrite needs to be TRUE.", 'info', true);
                 return "412 Precondition Failed - Destination Document exists. Overwrite needs to be TRUE.";
             }
             $this->ktwebdavLog("Overwrite is TRUE, deleting Destination Document.", 'info', true);
             // Check if the user has permissions to delete this document
             $oPerm =& KTPermission::getByName('ktcore.permissions.delete');
             $oUser =& User::get($this->userID);
             if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oReplaceDoc)) {
                 return "403 Forbidden - User does not have sufficient permissions";
             }
             KTDocumentUtil::delete($oReplaceDoc, 'KTWebDAV move overwrites target.');
             $new = false;
         }
     }
     /* ** Check if the source and destination directories are the same and the destination is not a folder.
        Then action is probably a rename.
        Check if user has permission to write to the document and folder.
        Rename the document. ** */
     if (dirname($source_path) == dirname($dest_path) && !is_null($iDestDoc)) {
         // This is a rename
         $this->ktwebdavLog("This is a rename.", 'info', true);
         $this->ktwebdavLog("Got an oDocument of " . print_r($oDocument, true), 'info', true);
         $this->ktwebdavLog("Got a new name of " . basename($dest_path), 'info', true);
         // Check if the user has permissions to write this document
         $oPerm =& KTPermission::getByName('ktcore.permissions.write');
         $oUser =& User::get($this->userID);
         if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oDocument)) {
             return "403 Forbidden - User does not have sufficient permissions";
         }
         // Perform rename
         $res = KTDocumentUtil::rename($oDocument, basename($dest_path), $oUser);
         if (PEAR::isError($res) || is_null($res) || $res === false) {
             return "404 Not Found - " . $res->getMessage();
         } else {
             if ($new) {
                 $this->ktwebdavLog("201 Created", 'info', true);
                 return "201 Created";
             } else {
                 $this->ktwebdavLog("204 No Content", 'info', true);
                 return "204 No Content";
             }
         }
     }
     /* ** Get the destination folder object and the source document object.
        Check if user has permission to write to the document and folder.
        Move the document. ** */
     $oDestFolder = Folder::get($iDestFolder);
     $this->ktwebdavLog("Got a destination folder of " . print_r($oDestFolder, 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 Move.";
     $res = KTDocumentUtil::move($oDocument, $oDestFolder, $oUser, $reason);
     if (PEAR::isError($res)) {
         $this->ktwebdavLog("Move on document failed: " . $res->getMessage(), 'info', true);
         return "500 Internal Server Error - Move on document failed.";
     }
     if ($new) {
         $this->ktwebdavLog("201 Created", 'info', true);
         return "201 Created";
     } else {
         $this->ktwebdavLog("204 No Content", 'info', true);
         return "204 No Content";
     }
 }
Exemplo n.º 2
0
 /**
  * Changes the filename of the document.
  * If the filename contains any invalid characters they are replaced with a dash (-). For example: ?, *, %, \, /
  *
  * @author KnowledgeTree Team
  * @access public
  * @param string $newname The new filename
  * @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure
  */
 function renameFile($newname)
 {
     $user = $this->can_user_access_object_requiring_permission($this->document, KTAPI_PERMISSION_WRITE);
     if (PEAR::isError($user)) {
         return $user;
     }
     $newname = KTUtil::replaceInvalidCharacters($newname);
     DBUtil::startTransaction();
     $res = KTDocumentUtil::rename($this->document, $newname, $user);
     if (PEAR::isError($res)) {
         DBUtil::rollback();
         return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $res);
     }
     DBUtil::commit();
 }
Exemplo n.º 3
0
 function do_rename()
 {
     global $default;
     $sFilename = KTUtil::arrayGet($_REQUEST, 'filename');
     $aOptions = array('redirect_to' => array('', sprintf('fDocumentId=%d', $this->oDocument->getId())), 'message' => _kt("No filename given"), 'max_str_len' => 255);
     $this->oValidator->validateString($sFilename, $aOptions);
     $this->oValidator->validateIllegalCharacters($sFilename, $aOptions);
     $res = KTDocumentUtil::rename($this->oDocument, $sFilename, $this->oUser);
     if (PEAR::isError($res)) {
         $_SESSION['KTErrorMessage'][] = $res->getMessage();
         controllerRedirect('viewDocument', sprintf('fDocumentId=%d', $this->oDocument->getId()));
     } else {
         $_SESSION['KTInfoMessage'][] = sprintf(_kt('Document "%s" renamed.'), $this->oDocument->getName());
     }
     controllerRedirect('viewDocument', sprintf('fDocumentId=%d', $this->oDocument->getId()));
     exit(0);
 }
Exemplo n.º 4
0
<?php

require_once "../../config/dmsDefaults.php";
require_once KT_LIB_DIR . '/documentmanagement/documentutil.inc.php';
require_once KT_LIB_DIR . '/users/User.inc';
require_once KT_LIB_DIR . '/database/dbutil.inc';
error_reporting(E_ALL);
$oDocument = Document::get(28);
$oUser = User::get(1);
var_dump(KTDocumentUtil::rename($oDocument, 'bob1', $oUser));
var_dump(KTDocumentUtil::rename($oDocument, 'bob2', $oUser));
var_dump(KTDocumentUtil::rename($oDocument, 'bob3', $oUser));
var_dump(KTDocumentUtil::rename($oDocument, 'bob4', $oUser));