📄 ktapidocument.inc.php.tmp
字号:
<?php/** * $Id$ * * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008 KnowledgeTree Inc. * Portions copyright The Jam Warehouse Software (Pty) Limited * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, * California 94120-7775, or email info@knowledgetree.com. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices * must display the words "Powered by KnowledgeTree" and retain the original * copyright notice. * Contributor( s): ______________________________________ * *///require_once(KT_DIR . '/ktwebservice/KTUploadManager.inc.php');class KTAPI_Document extends KTAPI_FolderItem{ /** * This is a reference to the internal document object. * * @var Document */ var $document; /** * This is the id of the document. * * @var int */ var $documentid; /** * This is a reference to the parent folder. * * @var KTAPI_Folder */ var $ktapi_folder; function get_documentid() { return $this->documentid; } /** * This is used to get a document based on document id. * * @static * @access public * @param KTAPI $ktapi * @param int $documentid * @return KTAPI_Document */ function &get(&$ktapi, $documentid) { assert(!is_null($ktapi)); assert(is_a($ktapi, 'KTAPI')); assert(is_numeric($documentid)); $documentid += 0; $document = &Document::get($documentid); if (is_null($document) || PEAR::isError($document)) { return new KTAPI_Error(KTAPI_ERROR_DOCUMENT_INVALID,$document ); } $user = $ktapi->can_user_access_object_requiring_permission($document, KTAPI_PERMISSION_READ); if (is_null($user) || PEAR::isError($user)) { return $user; } $folderid = $document->getParentID(); if (!is_null($folderid)) { $ktapi_folder = &KTAPI_Folder::get($ktapi, $folderid); } else { $ktapi_folder = null; } // We don't do any checks on this folder as it could possibly be deleted, and is not required right now. return new KTAPI_Document($ktapi, $ktapi_folder, $document); } function is_deleted() { return ($this->document->getStatusID() == 3); } /** * Checks if the document is a shortcut * * @return boolean */ function is_shortcut() { return $this->document->isSymbolicLink(); } /** * Retrieves the shortcuts linking to this document * */ function get_shortcuts() { return $this->document->getSymbolicLinks(); } /** * This is the constructor for the KTAPI_Folder. * * @access private * @param KTAPI $ktapi * @param Document $document * @return KTAPI_Document */ function KTAPI_Document(&$ktapi, &$ktapi_folder, &$document) { assert(is_a($ktapi,'KTAPI')); assert(is_null($ktapi_folder) || is_a($ktapi_folder,'KTAPI_Folder')); $this->ktapi = &$ktapi; $this->ktapi_folder = &$ktapi_folder; $this->document = &$document; $this->documentid = $document->getId(); } /** * This checks a document into the repository * * @param string $filename * @param string $reason * @param string $tempfilename * @param bool $major_update */ function checkin($filename, $reason, $tempfilename, $major_update=false) { if (!is_file($tempfilename)) { return new PEAR_Error('File does not exist.'); } $user = $this->can_user_access_object_requiring_permission($this->document, KTAPI_PERMISSION_WRITE); if (PEAR::isError($user)) { return $user; } if (!$this->document->getIsCheckedOut()) { return new PEAR_Error(KTAPI_ERROR_DOCUMENT_NOT_CHECKED_OUT); } $filename = KTUtil::replaceInvalidCharacters($filename); $options = array('major_update'=>$major_update); $currentfilename = $this->document->getFileName(); if ($filename != $currentfilename) { $options['newfilename'] = $filename; } DBUtil::startTransaction(); $result = KTDocumentUtil::checkin($this->document, $tempfilename, $reason, $user, $options); if (PEAR::isError($result)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$result); } DBUtil::commit(); KTUploadManager::temporary_file_imported($tempfilename); } function removeUpdateNotification() { $sql = "DELETE FROM notifications WHERE data_int_1=$this->documentid AND data_str_1='ModifyDocument'"; DBUtil::runQuery($sql); } /** * Link a document to another * * @param KTAPI_Document $document */ function link_document($document, $type) { $typeid = $this->ktapi->get_link_type_id($type); if (PEAR::isError($typeid)) { return $result; } $link = new DocumentLink($this->get_documentid(), $document->get_documentid(), $typeid ); $created = $link->create(); if ($created === false || PEAR::isError($created)) { return new PEAR_Error(_kt('Could not create link')); } } /** * Unlink a document to another * * @param KTAPI_Document $document */ function unlink_document($document) { $sql = "DELETE FROM document_link WHERE parent_document_id=$this->documentid AND child_document_id=$document->documentid"; $result = DBUtil::runQuery($sql); if (empty($result) || PEAR::isError($created)) { return new PEAR_Error(_kt('Could not remove link')); } } /** * * @return boolean */ function is_checked_out() { return ($this->document->getIsCheckedOut()); } /** * This reverses the checkout process. * * @param string $reason */ function undo_checkout($reason) { $user = $this->can_user_access_object_requiring_permission($this->document, KTAPI_PERMISSION_WRITE); if (PEAR::isError($user)) { return $user; } if (!$this->document->getIsCheckedOut()) { return new PEAR_Error(KTAPI_ERROR_DOCUMENT_NOT_CHECKED_OUT); } DBUtil::startTransaction(); $this->document->setIsCheckedOut(0); $this->document->setCheckedOutUserID(-1); $res = $this->document->update(); if (($res === false) || PEAR::isError($res)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res); } $oDocumentTransaction = new DocumentTransaction($this->document, $reason, 'ktcore.transactions.force_checkin'); $res = $oDocumentTransaction->create(); if (($res === false) || PEAR::isError($res)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR,$res); } DBUtil::commit(); } function get_linked_documents() { $sql = " SELECT dl.child_document_id as document_id, dmv.name as title, dcv.size, w.name as workflow, ws.name as workflow_state, dlt.name as link_type, dtl.name as document_type, dcv.major_version, dcv.minor_version, d.oem_no FROM document_link dl INNER JOIN document_link_types dlt ON dl.link_type_id=dlt.id INNER JOIN documents d ON dl.child_document_id=d.id INNER JOIN document_metadata_version dmv ON d.metadata_version_id=dmv.id INNER JOIN document_content_version dcv ON dmv.content_version_id=dcv.id INNER JOIN document_types_lookup dtl ON dtl.id=dmv.document_type_id LEFT OUTER JOIN workflow_documents wd ON d.id=wd.document_id LEFT OUTER JOIN workflows w ON w.id=wd.workflow_id LEFT OUTER JOIN workflow_states ws ON wd.state_id=ws.id WHERE dl.parent_document_id=$this->documentid "; $rows = DBUtil::getResultArray($sql); if (PEAR::isError($rows)) { return $rows; } $result=array(); $read_permission = &KTPermission::getByName(KTAPI_PERMISSION_READ); $user = $this->ktapi->get_user(); foreach($rows as $row) { $document = Document::get($row['document_id']); if (PEAR::isError($document) || is_null($document)) { continue; } if(!KTPermissionUtil::userHasPermissionOnItem($user, $read_permission, $document)) { continue; } $oem_no = $row['oem_no']; if (empty($oem_no)) $oem_no = 'n/a'; $result[] = array( 'document_id'=>(int)$row['document_id'], 'custom_document_no'=>'n/a', 'oem_document_no'=>$oem_no, 'title'=> $row['title'], 'document_type'=> $row['document_type'], 'version'=> (float) ($row['major_version'] . '.' . $row['minor_version']), 'filesize'=>(int)$row['size'], 'workflow'=>empty($row['workflow'])?'n/a':$row['workflow'], 'workflow_state'=>empty($row['workflow_state'])?'n/a':$row['workflow_state'], 'link_type'=>empty($row['link_type'])?'unknown':$row['link_type'], ); } return $result; } /** * This returns a URL to the file that can be downloaded. * * @param string $reason */ function checkout($reason) { $user = $this->can_user_access_object_requiring_permission($this->document, KTAPI_PERMISSION_WRITE); if (PEAR::isError($user)) { return $user; } if ($this->document->getIsCheckedOut()) { return new PEAR_Error(KTAPI_ERROR_DOCUMENT_CHECKED_OUT); } DBUtil::startTransaction(); $res = KTDocumentUtil::checkout($this->document, $reason, $user); if (PEAR::isError($res)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $res); } DBUtil::commit(); } /** * This deletes a document from the folder. * * @param string $reason */ function delete($reason) { $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_DELETE); if (PEAR::isError($user)) { return $user; } if ($this->document->getIsCheckedOut()) { return new PEAR_Error(KTAPI_ERROR_DOCUMENT_CHECKED_OUT); } DBUtil::startTransaction(); $res = KTDocumentUtil::delete($this->document, $reason); if (PEAR::isError($res)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $res); } DBUtil::commit(); } /** * This changes the owner of the file. * * @param string $ktapi_newuser */ function change_owner($newusername, $reason='Changing of owner.') { $user = $this->can_user_access_object_requiring_permission( $this->document, KTAPI_PERMISSION_CHANGE_OWNERSHIP); if (PEAR::isError($user)) { return $user; } DBUtil::startTransaction(); $user = &User::getByUserName($newusername); if (is_null($user) || PEAR::isError($user)) { return new KTAPI_Error('User could not be found',$user); } $newuserid = $user->getId(); $this->document->setOwnerID($newuserid); $res = $this->document->update(); if (PEAR::isError($res)) { DBUtil::rollback(); return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR ,$res ); } $res = KTPermissionUtil::updatePermissionLookup($this->document); if (PEAR::isError($res)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -