예제 #1
0
 function do_rename()
 {
     $aErrorOptions = array('redirect_to' => array('', sprintf('fFolderId=%d', $this->oFolder->getId())));
     $sFolderName = KTUtil::arrayGet($_REQUEST, 'foldername');
     $aErrorOptions['defaultmessage'] = _kt("No folder name given");
     $sFolderName = $this->oValidator->validateString($sFolderName, $aErrorOptions);
     $sFolderName = $this->oValidator->validateIllegalCharacters($sFolderName, $aErrorOptions);
     $sOldFolderName = $this->oFolder->getName();
     if ($this->oFolder->getId() != 1) {
         $oParentFolder =& Folder::get($this->oFolder->getParentID());
         if (PEAR::isError($oParentFolder)) {
             $this->errorRedirectToMain(_kt('Unable to retrieve parent folder.'), $aErrorOptions['redirect_to'][1]);
             exit(0);
         }
         if (KTFolderUtil::exists($oParentFolder, $sFolderName)) {
             $this->errorRedirectToMain(_kt('A folder with that name already exists.'), $aErrorOptions['redirect_to'][1]);
             exit(0);
         }
     }
     $res = KTFolderUtil::rename($this->oFolder, $sFolderName, $this->oUser);
     if (PEAR::isError($res)) {
         $_SESSION['KTErrorMessage'][] = $res->getMessage();
         redirect(KTBrowseUtil::getUrlForFolder($this->oFolder));
         exit(0);
     } else {
         $_SESSION['KTInfoMessage'][] = sprintf(_kt('Folder "%s" renamed to "%s".'), $sOldFolderName, $sFolderName);
     }
     $this->commitTransaction();
     redirect(KTBrowseUtil::getUrlForFolder($this->oFolder));
     exit(0);
 }
예제 #2
0
 /**
  * MOVE method helper for Folders
  *
  * @param  array   parameter passing array
  * @param  int     Folder ID
  * @return string  HTTP status code or false
  */
 function _MOVEFolder($options, $iFolderID)
 {
     /* ** Ensure that the destination path exists ** */
     if ($options['dest'] == '') {
         $options["dest"] = substr($options["dest_url"], strlen($_SERVER["SCRIPT_NAME"]));
     }
     $options['dest'] = $this->_slashify($options['dest']);
     $this->ktwebdavLog("Entering _MOVEFolder. options are " . print_r($options, true), 'info', true);
     /* ** RFC 2518 Section 8.9.2. A folder move must have a depth of 'infinity'.
        Check the requested depth. If depth is set to '0' or '1' return a 400 error. ** */
     if ($options["depth"] != "infinity") {
         $this->ktwebdavLog("400 Bad request", 'info', true);
         return "400 Bad request - depth must be 'inifinity'.";
     }
     // Fix for Mac Goliath - and for Novell Netdrive
     // Modified - 30/10/07 - remove ktwebdav from folder 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;
     /* ** Get the relevant paths.
        Check whether the destination path refers to a folder / document. ** */
     $source_path = $options["path"];
     $dest_path = urldecode($options["dest"]);
     list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path);
     /* ** Get the source 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, check overwrite.
        If overwrite is true, then check permissions and delete the document, continue.
        If the destination document is false, then continue. ** */
     $oSrcFolder = Folder::get($iFolderID);
     $oDestFolder = Folder::get($iDestFolder);
     $new = true;
     if (is_null($iDestDoc)) {
         // Folder exists
         $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 replaced so we need to get the parent folder object
         list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path);
         $oDestFolder = Folder::get($iDestFolder);
         $new = false;
     } else {
         if ($iDestDoc !== false) {
             // Destination is a document
             $this->ktwebdavLog("Destination is a document.", 'info', true);
             $oReplaceDoc = Document::get($iDestDoc);
             if ($options['overwrite'] != 'T') {
                 $this->ktwebdavLog("Overwrite needs to be TRUE.", 'info', true);
                 return "412 Precondition Failed - Destination Folder is a document. 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 an existing folder.
        Then action is probably a rename.
        Check if user has permission to write to the folder.
        Rename the document. ** */
     if (dirname($source_path) == dirname($dest_path) && !is_null($iDestDoc)) {
         // This is a rename
         $this->ktwebdavLog("Rename collection.", 'info', true);
         $this->ktwebdavLog("Got an oSrcFolder of " . print_r($oSrcFolder, true), 'info', true);
         $this->ktwebdavLog("Got an new name of " . basename($dest_path), 'info', true);
         include_once KT_LIB_DIR . '/foldermanagement/folderutil.inc.php';
         // Check if the user has permissions to write this folder
         $oPerm =& KTPermission::getByName('ktcore.permissions.folder_rename');
         $oUser =& User::get($this->userID);
         if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oSrcFolder)) {
             return "403 Forbidden - User does not have sufficient permissions";
         }
         $res = KTFolderUtil::rename($oSrcFolder, 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";
             }
         }
     }
     include_once KT_LIB_DIR . '/foldermanagement/folderutil.inc.php';
     /* ** Get the destination folder object and the source document object.
        Check if user has permission to write to the folder.
        Move the folder. ** */
     $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";
     }
     $res = KTFolderUtil::move($oSrcFolder, $oDestFolder, $oUser);
     if (PEAR::isError($res)) {
         $this->ktwebdavLog("Move on folder failed: " . $res->getMessage(), 'info', true);
         return "500 Internal Server Error - Move 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
<?php

require_once "../../config/dmsDefaults.php";
require_once KT_LIB_DIR . '/foldermanagement/folderutil.inc.php';
require_once KT_LIB_DIR . '/users/User.inc';
require_once KT_LIB_DIR . '/database/dbutil.inc';
error_reporting(E_ALL);
$iFolderId = 43;
$oUser = User::get(1);
$j = 'll';
$oFolder = Folder::get($iFolderId);
var_dump(KTFolderUtil::rename($oFolder, $j . '1', $oUser));
$oFolder = Folder::get($iFolderId);
var_dump(KTFolderUtil::rename($oFolder, $j . '2', $oUser));
$oFolder = Folder::get($iFolderId);
var_dump(KTFolderUtil::rename($oFolder, $j . '3', $oUser));
$oFolder = Folder::get($iFolderId);
var_dump(KTFolderUtil::rename($oFolder, $j . '4', $oUser));
예제 #4
0
 function do_saveUnit()
 {
     $oUnit =& $this->oValidator->validateUnit($_REQUEST['unit_id']);
     $aOptions = array('redirect_to' => array('editUnit', sprintf('unit_id=%d', $oUnit->getId())), 'message' => _kt('No name given'));
     $sName = $this->oValidator->validateString($_REQUEST['unit_name'], $aOptions);
     $aOptions['message'] = _kt('A unit with that name already exists.');
     $aOptions['rename'] = $oUnit->getId();
     $sName = $this->oValidator->validateDuplicateName('Unit', $sName, $aOptions);
     $oUnit->setName($sName);
     $res = $oUnit->update();
     if ($res == false || PEAR::isError($res)) {
         return $this->errorRedirectToMain(_kt('Failed to set unit details.'));
     }
     $iFolderId = $oUnit->getFolderId();
     $oFolder = Folder::get($iFolderId);
     if (!PEAR::isError($oFolder) && $oFolder !== false) {
         KTFolderUtil::rename($oFolder, $sName, $this->oUser);
     }
     $this->successRedirectToMain(_kt("Unit details updated"));
 }
예제 #5
0
 /**
  * This renames the folder
  *
  * @author KnowledgeTree Team
  * @access public
  * @param string $newname
  */
 function rename($newname)
 {
     $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_RENAME_FOLDER);
     if (PEAR::isError($user)) {
         return $user;
     }
     $newname = KTUtil::replaceInvalidCharacters($newname);
     DBUtil::startTransaction();
     $result = KTFolderUtil::rename($this->folder, $newname, $user);
     if (PEAR::isError($result)) {
         DBUtil::rollback();
         return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $result);
     }
     DBUtil::commit();
 }