예제 #1
0
 function do_copy()
 {
     $oForm = $this->form_copyselection();
     $res = $oForm->validate();
     $errors = $res['errors'];
     $data = $res['results'];
     $sReason = $data['reason'];
     $extra_errors = array();
     if (!is_null($data['browse'])) {
         $bNameClash = KTDocumentUtil::nameExists($data['browse'], $this->oDocument->getName());
         if ($bNameClash && isset($data['name'])) {
             $name = $data['name'];
             $bNameClash = KTDocumentUtil::nameExists($data['browse'], $name);
         } else {
             $name = $this->oDocument->getName();
         }
         if ($bNameClash) {
             $extra_errors['name'] = _kt('A document with this title already exists in your chosen folder.  Please choose a different folder, or specify a new title for the copied document.');
         }
         $bFileClash = KTDocumentUtil::fileExists($data['browse'], $this->oDocument->getFilename());
         if ($bFileClash && isset($data['filename'])) {
             $filename = $data['filename'];
             $bFileClash = KTDocumentUtil::fileExists($data['browse'], $filename);
         } else {
             $filename = $this->oDocument->getFilename();
         }
         if ($bFileClash) {
             $extra_errors['filename'] = _kt('A document with this filename already exists in your chosen folder.  Please choose a different folder, or specify a new filename for the copied document.');
         }
         if (!Permission::userHasFolderWritePermission($data['browse'])) {
             $extra_errors['browse'] = _kt('You do not have permission to create new documents in that folder.');
         }
     }
     if (!empty($errors) || !empty($extra_errors)) {
         return $oForm->handleError(null, $extra_errors);
     }
     // FIXME agree on document-duplication rules re: naming, etc.
     $this->startTransaction();
     // now try update it.
     $oNewDoc = KTDocumentUtil::copy($this->oDocument, $data['browse'], $sReason);
     if (PEAR::isError($oNewDoc)) {
         $this->errorRedirectTo('main', _kt('Failed to copy document: ') . $oNewDoc->getMessage(), sprintf('fDocumentId=%d&fFolderId=%d', $this->oDocument->getId(), $this->oFolder->getId()));
         exit(0);
     }
     $oNewDoc->setName($name);
     $oNewDoc->setFilename($filename);
     $res = $oNewDoc->update();
     if (PEAR::isError($res)) {
         return $this->errorRedirectTo('main', _kt('Failed to copy document: ') . $res->getMessage(), sprintf('fDocumentId=%d&fFolderId=%d', $this->oDocument->getId(), $this->oFolder->getId()));
     }
     $this->commitTransaction();
     $_SESSION['KTInfoMessage'][] = _kt('Document copied.');
     controllerRedirect('viewDocument', 'fDocumentId=' . $oNewDoc->getId());
     exit(0);
 }
예제 #2
0
 /**
  * Get's a permission string for a folder eg: 'RW' or 'RWA'
  *
  * @author KnowledgeTree Team
  * @access public
  * @param Folder $folder
  * @return string
  */
 function get_permission_string($folder)
 {
     $perms = '';
     if (Permission::userHasFolderReadPermission($folder)) {
         $perms .= 'R';
     }
     if (Permission::userHasFolderWritePermission($folder)) {
         $perms .= 'W';
     }
     if (Permission::userHasAddFolderPermission($folder)) {
         $perms .= 'A';
     }
     // root folder cannot be renamed or deleted.
     if ($folder->iId != 1) {
         if (Permission::userHasRenameFolderPermission($folder)) {
             $perms .= 'N';
         }
         if (Permission::userHasDeleteFolderPermission($folder)) {
             $perms .= 'D';
         }
     }
     return $perms;
 }
예제 #3
0
 function do_performaction()
 {
     $this->store_lists();
     $this->get_lists();
     $oForm = $this->form_collectinfo();
     $res = $oForm->validate();
     if (!empty($res['errors'])) {
         $oForm->handleError();
     }
     $this->sReason = $_REQUEST['data']['reason'];
     $this->iTargetFolderId = $_REQUEST['data']['fFolderId'];
     $this->oTargetFolder = Folder::get($this->iTargetFolderId);
     $_REQUEST['fReturnData'] = '';
     $_REQUEST['fFolderId'] = $this->iTargetFolderId;
     // does it exists
     if (PEAR::isError($this->oTargetFolder)) {
         return PEAR::raiseError(_kt('Invalid target folder selected'));
     }
     // does the user have write permission
     if (!Permission::userHasFolderWritePermission($this->oTargetFolder)) {
         $this->errorRedirectTo('collectinfo', _kt('You do not have permission to move items to this location'));
     }
     return parent::do_performaction();
 }
예제 #4
0
 /**
  * Get's a permission string for a folder eg: 'RW' or 'RWA'
  *
  * @author KnowledgeTree Team
  * @access public
  * @param Folder $folder
  * @return string
  */
 function get_permission_string($folder)
 {
     $perms = '';
     if (Permission::userHasFolderReadPermission($folder)) {
         $perms .= 'R';
     }
     if (Permission::userHasFolderWritePermission($folder)) {
         $perms .= 'W';
     }
     if (Permission::userHasAddFolderPermission($folder)) {
         $perms .= 'A';
     }
     return $perms;
 }