示例#1
0
 /**
  * Recursively generates forward slash deliminated string giving full path of document
  * from file system root url
  */
 function _generateFullFolderPath($iFolderId)
 {
     //if the folder is not the root folder
     if (empty($iFolderId)) {
         return;
     }
     $sTable = KTUtil::getTableName('folders');
     $sQuery = sprintf("SELECT name, parent_id FROM %s WHERE Id = ?", $sTable);
     $aParams = array($iFolderId);
     $aRow = DBUtil::getOneResult(array($sQuery, $aParams));
     return KTDocumentCore::_generateFullFolderPath($aRow["parent_id"]) . "/" . $aRow["name"];
 }
 function getAllowed()
 {
     if (!is_null($this->iPermissionDescriptorId)) {
         $oDescriptor = KTPermissionDescriptor::get($this->iPermissionDescriptorId);
         // fully done, etc.
         $aAllowed = $oDescriptor->getAllowed();
     } else {
         $aAllowed = array();
     }
     // special case "document owner".
     if ($this->iRoleId == -2) {
         $oDoc = KTDocumentCore::get($this->iDocumentId);
         /* ! NBM Please Review
          *
          * This should never be an error - we were called by PermissionUtil 
          * to get the details for a document, but it _is_ be a DocumentCore
          * object during _add.
          *
          * When we try to grab the Document, it blows up on the MetadataVersion,
          * so we have to use a DocumentCore to avoid a fail-out on the initial 
          * on-add permission check.
          *
          * Is this bad/evil/not appropriate in some way?  I can't see a major
          * issue with it...
          *
          */
         if (PEAR::isError($oDoc)) {
             return $aAllowed;
         }
         // ! NBM Please review
         // we cascade "owner" from the folder (if, for some _bizarre_ reason the
         // owner role is allocated to users/groups/etc.  this can be disabled
         // with the CRACK_IS_BAD flag, or removed entirely.  I am undecided.
         //
         // There is some argument to be made for the consistency, but it may not be
         // that big.  I think it _may_ lead to easily misconfigured setups, but I
         // really don't know.
         $CRACK_IS_BAD = false;
         if (!$CRACK_IS_BAD && is_null($this->iPermissionDescriptorId)) {
             $oDerivedAlloc = RoleAllocation::getAllocationsForFolderAndRole($oDoc->getFolderID(), $this->iRoleId);
             if (!(PEAR::isError($oDerivedAlloc) || is_null($oDerivedAlloc))) {
                 $aAllowed = $oDerivedAlloc->getAllowed();
             }
         }
         $owner_id = $oDoc->getOwnerId();
         if (is_null($aAllowed['user'])) {
             $aAllowed['user'] = array($owner_id);
         } else {
             if (array_search($owner_id, $aAllowed['user']) === false) {
                 $aAllowed['user'][] = $owner_id;
             }
         }
     }
     return $aAllowed;
 }
 /**
  * Restore a document from the Deleted/ folder to the specified folder
  *
  * return boolean true on successful move, false otherwhise
  */
 function restore($oDocument)
 {
     $oConfig =& KTConfig::getSingleton();
     $sCurrentPath = $this->getPath($oDocument);
     // check if the deleted folder exists and create it if not
     $sDeletedPrefix = sprintf("%s/Deleted", $oConfig->get('urls/documentRoot'));
     $sDocumentRoot = $oConfig->get('urls/documentRoot');
     $oNewFolder = Folder::get($oDocument->getFolderID());
     $aVersions = KTDocumentContentVersion::getByDocument($oDocument);
     foreach ($aVersions as $oVersion) {
         $sNewPath = sprintf("%s/%s-%s", KTDocumentCore::_generateFolderPath($oNewFolder->getID()), $oVersion->getId(), $oVersion->getFileName());
         $oVersion->setStoragePath($sNewPath);
         $sOldPath = sprintf("Deleted/%s-%s", $oVersion->getId(), $oVersion->getFileName());
         $sFullNewPath = sprintf("%s/%s", $sDocumentRoot, $sNewPath);
         $sFullOldPath = sprintf("%s/%s", $sDocumentRoot, $sOldPath);
         KTUtil::moveFile($sFullOldPath, $sFullNewPath);
         $oVersion->update();
     }
     return true;
 }
 /**
  * Create a symbolic link in the target folder
  *
  * @param Document $sourceDocument the document to create a link to
  * @param Folder $targetFolder the folder to place the link in
  * @param User $user current user
  */
 static function createSymbolicLink($sourceDocument, $targetFolder, $user = null)
 {
     //validate input
     if (is_numeric($sourceDocument)) {
         $sourceDocument = Document::get($sourceDocument);
     }
     if (!$sourceDocument instanceof Document) {
         return PEAR::raiseError(_kt('Source document not specified'));
     }
     if (is_numeric($targetFolder)) {
         $targetFolder = Folder::get($targetFolder);
     }
     if (!$targetFolder instanceof Folder) {
         return PEAR::raiseError(_kt('Target folder not specified'));
     }
     if (is_null($user)) {
         $user = $_SESSION['userID'];
     }
     if (is_numeric($user)) {
         $user = User::get($user);
     }
     //check for permissions
     $oPermission =& KTPermission::getByName("ktcore.permissions.write");
     $oReadPermission =& KTPermission::getByName("ktcore.permissions.read");
     if (KTBrowseUtil::inAdminMode($user, $targetFolder)) {
         if (!KTPermissionUtil::userHasPermissionOnItem($user, $oPermission, $targetFolder)) {
             return PEAR::raiseError(_kt('You\'re not authorized to create shortcuts'));
         }
     }
     if (!KTBrowseUtil::inAdminMode($user, $sourceDocument->getParentID())) {
         if (!KTPermissionUtil::userHasPermissionOnItem($user, $oReadPermission, $sourceDocument)) {
             return PEAR::raiseError(_kt('You\'re not authorized to create a shortcut to this document'));
         }
     }
     //check if the shortcut doesn't already exists in the target folder
     $aSymlinks = $sourceDocument->getSymbolicLinks();
     foreach ($aSymlinks as $iSymlink) {
         $oSymlink = Document::get($iSymlink['id']);
         $oSymlink->switchToRealCore();
         if ($oSymlink->getFolderID() == $targetFolder->getID()) {
             return PEAR::raiseError(_kt('There already is a shortcut to this document in the target folder.'));
         }
     }
     //create the actual shortcut
     $oCore = KTDocumentCore::createFromArray(array('iCreatorId' => $user->getId(), 'iFolderId' => $targetFolder->getId(), 'iLinkedDocumentId' => $sourceDocument->getId(), 'sFullPath' => $targetFolder->getFullPath() . '/' . $sourceDocument->getName(), 'iPermissionObjectId' => $targetFolder->getPermissionObjectID(), 'iPermissionLookupId' => $targetFolder->getPermissionLookupID(), 'iStatusId' => 1, 'iMetadataVersionId' => $sourceDocument->getMetadataVersionId()));
     $document = Document::get($oCore->getId());
     return $document;
 }