예제 #1
0
 /**
  * GET method helper
  *
  * @param  array  parameter passing array
  * @param  int  Document ID
  * @return bool   true on success
  */
 function _GETDocument(&$options, $iDocumentID)
 {
     global $default;
     $oDocument =& Document::get($iDocumentID);
     // get a temp file, and read.  NOTE: NEVER WRITE TO THIS
     $oStorage =& KTStorageManagerUtil::getSingleton();
     $fspath = $oStorage->temporaryFile($oDocument);
     $this->ktwebdavLog("Filesystem Path is " . $fspath, 'info', true);
     // detect resource type
     $mimetype = KTMime::getMimeTypeName($oDocument->getMimeTypeID());
     $options['mimetype'] = KTMime::getFriendlyNameForString($mimetype);
     // detect modification time
     // see rfc2518, section 13.7
     // some clients seem to treat this as a reverse rule
     // requiering a Last-Modified header if the getlastmodified header was set
     $options['mtime'] = $oDocument->getVersionCreated();
     // detect resource size
     $options['size'] = $oDocument->getFileSize();
     // no need to check result here, it is handled by the base class
     $options['stream'] = fopen($fspath, "r");
     $this->ktwebdavLog("Method is " . $this->currentMethod, 'info', true);
     if ($this->currentMethod == "get") {
         // create the document transaction record
         include_once KT_LIB_DIR . '/documentmanagement/DocumentTransaction.inc';
         $oDocumentTransaction =& new DocumentTransaction($oDocument, "Document viewed via KTWebDAV", 'ktcore.transactions.view');
         $oDocumentTransaction->iUserID = $this->userID;
         $oDocumentTransaction->create();
     }
     return true;
 }
예제 #2
0
 /**
  * This returns detailed information on the document.
  *
  * @author KnowledgeTree Team
  * @access public
  * @return array The document information
  */
 function get_detail()
 {
     global $default;
     // make sure we ge tthe latest
     $this->clearCache();
     $config = KTConfig::getSingleton();
     $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION);
     $detail = array();
     $document = $this->document;
     // get the document id
     $detail['document_id'] = (int) $document->getId();
     $oem_document_no = null;
     if ($wsversion >= 2) {
         $oem_document_no = $document->getOemNo();
     }
     if (empty($oem_document_no)) {
         $oem_document_no = 'n/a';
     }
     $detail['custom_document_no'] = 'n/a';
     $detail['oem_document_no'] = $oem_document_no;
     // get the title
     $detail['title'] = $document->getName();
     // get the document type
     $documenttypeid = $document->getDocumentTypeID();
     $documenttype = '* unknown *';
     if (is_numeric($documenttypeid)) {
         $dt = DocumentType::get($documenttypeid);
         if (!is_null($dt) && !PEAR::isError($dt)) {
             $documenttype = $dt->getName();
         }
     }
     $detail['document_type'] = $documenttype;
     // get the filename
     $detail['filename'] = $document->getFilename();
     // get the filesize
     $detail['filesize'] = (int) $document->getFileSize();
     // get the folder id
     $detail['folder_id'] = (int) $document->getFolderID();
     // get the creator
     $userid = $document->getCreatorID();
     $username = '******';
     if (is_numeric($userid)) {
         $username = '******';
         $user = User::get($userid);
         if (!is_null($user) && !PEAR::isError($user)) {
             $username = $user->getName();
         }
     }
     $detail['created_by'] = $username;
     // get the creation date
     $detail['created_date'] = $document->getCreatedDateTime();
     // get the checked out user
     $userid = $document->getCheckedOutUserID();
     $username = '******';
     if (is_numeric($userid)) {
         $username = '******';
         $user = User::get($userid);
         if (!is_null($user) && !PEAR::isError($user)) {
             $username = $user->getName();
         }
     }
     $detail['checked_out_by'] = $username;
     // get the checked out date
     list($major, $minor, $fix) = explode('.', $default->systemVersion);
     if ($major == 3 && $minor >= 5) {
         $detail['checked_out_date'] = $document->getCheckedOutDate();
     } else {
         $detail['checked_out_date'] = $detail['modified_date'];
     }
     if (is_null($detail['checked_out_date'])) {
         $detail['checked_out_date'] = 'n/a';
     }
     // get the modified user
     $userid = $document->getModifiedUserId();
     $username = '******';
     if (is_numeric($userid)) {
         $username = '******';
         $user = User::get($userid);
         if (!is_null($user) && !PEAR::isError($user)) {
             $username = $user->getName();
         }
     }
     $detail['modified_by'] = $detail['updated_by'] = $username;
     // get the modified date
     $detail['updated_date'] = $detail['modified_date'] = $document->getLastModifiedDate();
     // get the owner
     $userid = $document->getOwnerID();
     $username = '******';
     if (is_numeric($userid)) {
         $username = '******';
         $user = User::get($userid);
         if (!is_null($user) && !PEAR::isError($user)) {
             $username = $user->getName();
         }
     }
     $detail['owned_by'] = $username;
     // get the version
     $detail['version'] = $document->getVersion();
     if ($wsversion >= 2) {
         $detail['version'] = (double) $detail['version'];
     }
     //might be unset at the bottom in case of old webservice version
     //make sure we're using the real document for this one
     $this->document->switchToRealCore();
     $detail['linked_document_id'] = $document->getLinkedDocumentId();
     $this->document->switchToLinkedCore();
     // check immutability
     $detail['is_immutable'] = (bool) $document->getImmutable();
     // check permissions
     $detail['permissions'] = KTAPI_Document::get_permission_string($document);
     // get workflow name
     $workflowid = $document->getWorkflowId();
     $workflowname = 'n/a';
     if (is_numeric($workflowid)) {
         $workflow = KTWorkflow::get($workflowid);
         if (!is_null($workflow) && !PEAR::isError($workflow)) {
             $workflowname = $workflow->getName();
         }
     }
     $detail['workflow'] = $workflowname;
     // get the workflow state
     $stateid = $document->getWorkflowStateId();
     $workflowstate = 'n/a';
     if (is_numeric($stateid)) {
         $state = KTWorkflowState::get($stateid);
         if (!is_null($state) && !PEAR::isError($state)) {
             $workflowstate = $state->getName();
         }
     }
     $detail['workflow_state'] = $workflowstate;
     // get the full path
     $detail['full_path'] = '/' . $this->document->getFullPath();
     // get mime info
     $mimetypeid = $document->getMimeTypeID();
     $detail['mime_type'] = KTMime::getMimeTypeName($mimetypeid);
     $detail['mime_icon_path'] = KTMime::getIconPath($mimetypeid);
     $detail['mime_display'] = KTMime::getFriendlyNameForString($detail['mime_type']);
     // get the storage path
     $detail['storage_path'] = $document->getStoragePath();
     if ($wsversion >= 2) {
         unset($detail['updated_by']);
         unset($detail['updated_date']);
     }
     if ($wsversion < 3) {
         unset($detail['linked_document_id']);
     }
     return $detail;
 }
예제 #3
0
 function getMimeTypeInfo($iUserId, $iDocumentId)
 {
     global $default;
     $mimeinfo['typeId'] = KTrss::getDocumentMimeTypeId($iUserId, $iDocumentId);
     // mime type id
     $mimeinfo['typeName'] = KTMime::getMimeTypeName($mimeinfo['typeId']);
     // mime type name
     $mimeinfo['typeFName'] = KTMime::getFriendlyNameForString($mimeinfo['typeName']);
     // mime type friendly name
     $mimeinfo['typeIcon'] = "http" . ($default->sslEnabled ? "s" : "") . "://" . $_SERVER['HTTP_HOST'] . "/" . $GLOBALS['KTRootUrl'] . "/resources/mimetypes/" . KTMime::getIconPath($mimeinfo['typeId']) . ".png";
     //icon path
     return $mimeinfo;
 }
예제 #4
0
 /**
  * Create a table of the document metadata.
  * Hard coded for the moment
  *
  * @return unknown
  */
 function getMetadata()
 {
     /* Get document info */
     // Filename
     $sFilenameLb = _kt('Document Filename: ');
     $sFilename = $this->_oDocument->getFileName();
     // Mime type
     $sMimeTypeLb = _kt('File is a: ');
     $iMimeId = $this->_oDocument->getMimeTypeID();
     $sMimeType = KTMime::getMimeTypeName($iMimeId);
     $sMimeType = KTMime::getFriendlyNameForString($sMimeType);
     // Version
     $sVersionLb = _kt('Document Version: ');
     $iVersion = $this->_oDocument->getVersion();
     // Created by
     $sCreatedByLb = _kt('Created by: ');
     $iCreatorId = $this->_oDocument->getCreatorID();
     $sCreated = $this->_oDocument->getCreatedDateTime();
     $oCreator = User::get($iCreatorId);
     $sCreatedBy = $oCreator->getName() . ' (' . $sCreated . ')';
     // Owned by
     $sOwnedByLb = _kt('Owned by: ');
     $iOwnedId = $this->_oDocument->getOwnerID();
     $oOwner = User::get($iOwnedId);
     $sOwnedBy = $oOwner->getName();
     // Last update by
     $iModifiedId = $this->_oDocument->getModifiedUserId();
     $sLastUpdatedByLb = '';
     $sLastUpdatedBy = '';
     if (!empty($iModifiedId)) {
         $sLastUpdatedByLb = _kt('Last updated by: ');
         $sModified = $this->_oDocument->getLastModifiedDate();
         $oModifier = User::get($iModifiedId);
         $sLastUpdatedBy = $oModifier->getName() . ' (' . $sModified . ')';
     }
     // Document type
     $sDocTypeLb = _kt('Document Type: ');
     $iDocTypeId = $this->_oDocument->getDocumentTypeID();
     $oDocType = DocumentType::get($iDocTypeId);
     $sDocType = $oDocType->getName();
     // Workflow
     $iWFId = $this->_oDocument->getWorkflowId();
     $sWF = '';
     $sWFLb = '';
     if (!empty($iWFId)) {
         $sWFLb = _kt('Workflow: ');
         $iWFStateId = $this->_oDocument->getWorkflowStateId();
         $oWF = KTWorkflow::get($iWFId);
         $sWF = $oWF->getHumanName();
         $oWFState = KTWorkflowState::get($iWFStateId);
         $sWF .= ' (' . $oWFState->getHumanName() . ')';
     }
     // Checked out by
     $sCheckedLb = '';
     $sCheckedOutBy = '';
     if ($this->_oDocument->getIsCheckedOut()) {
         $sCheckedLb = _kt('Checked out by: ');
         $iCheckedID = $this->_oDocument->getCheckedOutUserID();
         $oCheckedUser = User::get($iCheckedID);
         $sCheckedOutBy = $oCheckedUser->getName();
     }
     // Id
     $sIdLb = _kt('Document ID: ');
     $sId = $this->_IDocId;
     /* Create table */
     $sInfo = "<div style='float:left; width:405px;'>\n            <table cellspacing='3px' cellpadding='3px' width='405px'>\n            <tr><td>{$sFilenameLb}</td><td><b>{$sFilename}</b></td></tr>\n            <tr><td>{$sMimeTypeLb}</td><td><b>{$sMimeType}</b></td></tr>\n            <tr><td>{$sVersionLb}</td><td><b>{$iVersion}</b></td></tr>\n            <tr><td>{$sCreatedByLb}</td><td><b>{$sCreatedBy}</b></td></tr>\n            <tr><td>{$sOwnedByLb}</td><td><b>{$sOwnedBy}</b></td></tr>";
     if (!empty($sLastUpdatedBy)) {
         $sInfo .= "<tr><td>{$sLastUpdatedByLb}</td><td><b>{$sLastUpdatedBy}</b></td></tr>";
     }
     $sInfo .= "<tr><td>{$sDocTypeLb}</td><td><b>{$sDocType}</b></td></tr>";
     if (!empty($sWF)) {
         $sInfo .= "<tr><td>{$sWFLb}</td><td><b>{$sWF}</b></td></tr>";
     }
     if (!empty($sCheckedOutBy)) {
         $sInfo .= "<tr><td>{$sCheckedLb}</td><td><b>{$sCheckedOutBy}</b></td></tr>";
     }
     $sInfo .= "<tr><td>{$sIdLb}</td><td><b>{$sId}</b></td></tr>";
     $sInfo .= " </table></div>";
     return $sInfo;
 }
예제 #5
0
 function is_active($oUser)
 {
     if (!Permission::userIsSystemAdministrator($oUser)) {
         return false;
     }
     require_once KT_LIB_DIR . '/triggers/triggerregistry.inc.php';
     $noTransforms = false;
     $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
     $aTriggers = $oKTTriggerRegistry->getTriggers('content', 'transform');
     $aTriggerSet = array();
     if (empty($aTriggers)) {
         $noTransforms = true;
     } else {
         foreach ($aTriggers as $aTrigger) {
             $sTrigger = $aTrigger[0];
             if ($aTrigger[1]) {
                 require_once $aTrigger[1];
             }
             $oTrigger = new $sTrigger();
             $sDiagnostic = $oTrigger->getDiagnostic();
             // empty is OK.
             if (is_null($sDiagnostic) || $sDiagnostic == false) {
                 continue;
             }
             $aTypes = (array) $oTrigger->mimetypes;
             $aTypesStr = array();
             foreach ($aTypes as $sTypeName => $v) {
                 //if ($sTypeName != 'application/octet-stream') { // never use application/octet-stream
                 $aTypesStr[KTMime::getFriendlyNameForString($sTypeName)] = 1;
                 //}
             }
             $aTriggerSet[] = array('types' => $aTypesStr, 'diagnostic' => $sDiagnostic);
         }
     }
     $this->aTriggerSet = $aTriggerSet;
     $this->noTransforms = $noTransforms;
     return $noTransforms || !empty($aTriggerSet);
     // no diags and have some transforms.
 }
예제 #6
0
 /**
  * Get's a folder listing, recursing to the maximum depth.
  * Derived from the get_listing function.
  *
  * <code>
  * $root = $this->ktapi->get_root_folder();
  * $listing = $root->get_full_listing();
  * foreach($listing as $val) {
  * 	if($val['item_type'] == 'F') {
  *   // It's a folder
  *   echo $val['title'];
  *  }
  * }
  * </code>
  *
  * @author KnowledgeTree Team
  * @access public
  * @param string $what
  * @return array
  */
 function get_full_listing($what = 'DFS')
 {
     $what = strtoupper($what);
     $read_permission =& KTPermission::getByName(KTAPI_PERMISSION_READ);
     $folder_permission =& KTPermission::getByName(KTAPI_PERMISSION_VIEW_FOLDER);
     $config = KTConfig::getSingleton();
     $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION);
     $user = $this->ktapi->get_user();
     $contents = array();
     if (strpos($what, 'F') !== false) {
         $folder_children = Folder::getList(array('parent_id = ?', $this->folderid));
         foreach ($folder_children as $folder) {
             if (KTPermissionUtil::userHasPermissionOnItem($user, $folder_permission, $folder) || KTPermissionUtil::userHasPermissionOnItem($user, $read_permission, $folder)) {
                 $sub_folder =& $this->ktapi->get_folder_by_id($folder->getId());
                 if (!PEAR::isError($sub_folder)) {
                     $items = $sub_folder->get_full_listing($what);
                 } else {
                     $items = array();
                 }
                 $creator = $this->_resolve_user($folder->getCreatorID());
                 if ($wsversion >= 2) {
                     $array = array('id' => (int) $folder->getId(), 'item_type' => 'F', 'custom_document_no' => 'n/a', 'oem_document_no' => 'n/a', 'title' => $folder->getName(), 'document_type' => 'n/a', 'filename' => $folder->getName(), 'filesize' => 'n/a', 'created_by' => is_null($creator) ? 'n/a' : $creator->getName(), 'created_date' => 'n/a', 'checked_out_by' => 'n/a', 'checked_out_date' => 'n/a', 'modified_by' => 'n/a', 'modified_date' => 'n/a', 'owned_by' => 'n/a', 'version' => 'n/a', 'is_immutable' => 'n/a', 'permissions' => KTAPI_Folder::get_permission_string($folder), 'workflow' => 'n/a', 'workflow_state' => 'n/a', 'mime_type' => 'folder', 'mime_icon_path' => 'folder', 'mime_display' => 'Folder', 'storage_path' => 'n/a');
                     if ($wsversion >= 3) {
                         $array['linked_folder_id'] = $folder->getLinkedFolderId();
                         if ($folder->isSymbolicLink()) {
                             $array['item_type'] = "S";
                         }
                     }
                     $array['items'] = $items;
                     if ($wsversion < 3 || strpos($what, 'F') !== false && !$folder->isSymbolicLink() || $folder->isSymbolicLink() && strpos($what, 'S') !== false) {
                         $contents[] = $array;
                     }
                 } else {
                     $contents[] = array('id' => (int) $folder->getId(), 'item_type' => 'F', 'title' => $folder->getName(), 'creator' => is_null($creator) ? 'n/a' : $creator->getName(), 'checkedoutby' => 'n/a', 'modifiedby' => 'n/a', 'filename' => $folder->getName(), 'size' => 'n/a', 'major_version' => 'n/a', 'minor_version' => 'n/a', 'storage_path' => 'n/a', 'mime_type' => 'folder', 'mime_icon_path' => 'folder', 'mime_display' => 'Folder', 'items' => $items, 'workflow' => 'n/a', 'workflow_state' => 'n/a');
                 }
             }
         }
     }
     if (strpos($what, 'D') !== false) {
         $document_children = Document::getList(array('folder_id = ? AND status_id = 1', $this->folderid));
         // I hate that KT doesn't cache things nicely...
         $mime_cache = array();
         foreach ($document_children as $document) {
             if (KTPermissionUtil::userHasPermissionOnItem($user, $read_permission, $document)) {
                 $created_by = $this->_resolve_user($document->getCreatorID());
                 $created_date = $document->getCreatedDateTime();
                 if (empty($created_date)) {
                     $created_date = 'n/a';
                 }
                 $checked_out_by = $this->_resolve_user($document->getCheckedOutUserID());
                 $checked_out_date = $document->getCheckedOutDate();
                 if (empty($checked_out_date)) {
                     $checked_out_date = 'n/a';
                 }
                 $modified_by = $this->_resolve_user($document->getCreatorID());
                 $modified_date = $document->getLastModifiedDate();
                 if (empty($modified_date)) {
                     $modified_date = 'n/a';
                 }
                 $owned_by = $this->_resolve_user($document->getOwnerID());
                 $mimetypeid = $document->getMimeTypeID();
                 if (!array_key_exists($mimetypeid, $mime_cache)) {
                     $type = KTMime::getMimeTypeName($mimetypeid);
                     $icon = KTMime::getIconPath($mimetypeid);
                     $display = KTMime::getFriendlyNameForString($type);
                     $mime_cache[$mimetypeid] = array('type' => $type, 'icon' => $icon, 'display' => $display);
                 }
                 $mimeinfo = $mime_cache[$mimetypeid];
                 $workflow = 'n/a';
                 $state = 'n/a';
                 $wf = KTWorkflowUtil::getWorkflowForDocument($document);
                 if (!is_null($wf) && !PEAR::isError($wf)) {
                     $workflow = $wf->getHumanName();
                     $ws = KTWorkflowUtil::getWorkflowStateForDocument($document);
                     if (!is_null($ws) && !PEAR::isError($ws)) {
                         $state = $ws->getHumanName();
                     }
                 }
                 if ($wsversion >= 2) {
                     $docTypeId = $document->getDocumentTypeID();
                     $documentType = DocumentType::get($docTypeId);
                     $oemDocumentNo = $document->getOemNo();
                     if (empty($oemDocumentNo)) {
                         $oemDocumentNo = 'n/a';
                     }
                     $array = array('id' => (int) $document->getId(), 'item_type' => 'D', 'custom_document_no' => 'n/a', 'oem_document_no' => $oemDocumentNo, 'title' => $document->getName(), 'document_type' => $documentType->getName(), 'filename' => $document->getFileName(), 'filesize' => $document->getFileSize(), 'created_by' => is_null($created_by) ? 'n/a' : $created_by->getName(), 'created_date' => $created_date, 'checked_out_by' => is_null($checked_out_by) ? 'n/a' : $checked_out_by->getName(), 'checked_out_date' => $checked_out_date, 'modified_by' => is_null($modified_by) ? 'n/a' : $modified_by->getName(), 'modified_date' => $modified_date, 'owned_by' => is_null($owned_by) ? 'n/a' : $owned_by->getName(), 'version' => $document->getMajorVersionNumber() . '.' . $document->getMinorVersionNumber(), 'content_id' => $document->getContentVersionId(), 'is_immutable' => $document->getImmutable() ? 'true' : 'false', 'permissions' => KTAPI_Document::get_permission_string($document), 'workflow' => $workflow, 'workflow_state' => $state, 'mime_type' => $mime_cache[$mimetypeid]['type'], 'mime_icon_path' => $mime_cache[$mimetypeid]['icon'], 'mime_display' => $mime_cache[$mimetypeid]['display'], 'storage_path' => $document->getStoragePath());
                     if ($wsversion >= 3) {
                         $document->switchToRealCore();
                         $array['linked_document_id'] = $document->getLinkedDocumentId();
                         $document->switchToLinkedCore();
                         if ($document->isSymbolicLink()) {
                             $array['item_type'] = "S";
                         }
                     }
                     $array['items'] = array();
                     if ($wsversion < 3 || strpos($what, 'D') !== false && !$document->isSymbolicLink() || $document->isSymbolicLink() && strpos($what, 'S') !== false) {
                         $contents[] = $array;
                     }
                 } else {
                     $contents[] = array('id' => (int) $document->getId(), 'item_type' => 'D', 'title' => $document->getName(), 'creator' => is_null($created_by) ? 'n/a' : $created_by->getName(), 'checkedoutby' => is_null($checked_out_by) ? 'n/a' : $checked_out_by->getName(), 'modifiedby' => is_null($modified_by) ? 'n/a' : $modified_by->getName(), 'filename' => $document->getFileName(), 'size' => $document->getFileSize(), 'major_version' => $document->getMajorVersionNumber(), 'minor_version' => $document->getMinorVersionNumber(), 'storage_path' => $document->getStoragePath(), 'mime_type' => $mime_cache[$mimetypeid]['type'], 'mime_icon_path' => $mime_cache[$mimetypeid]['icon'], 'mime_display' => $mime_cache[$mimetypeid]['display'], 'items' => array(), 'workflow' => $workflow, 'workflow_state' => $state);
                 }
             }
         }
     }
     return $contents;
 }