function check() { $this->browse_mode = KTUtil::arrayGet($_REQUEST, 'fBrowseMode', 'folder'); $action = KTUtil::arrayGet($_REQUEST, $this->event_var, 'main'); $this->editable = false; // catch the alternative actions. if ($action != 'main') { return true; } // if we're going to main ... // folder browse mode if ($this->browse_mode == 'folder') { $in_folder_id = KTUtil::arrayGet($_REQUEST, 'fFolderId'); if (empty($in_folder_id)) { $oConfig = KTConfig::getSingleton(); if ($oConfig->get('tweaks/browseToUnitFolder')) { $iHomeFolderId = $this->oUser->getHomeFolderId(); if ($iHomeFolderId) { $in_folder_id = $iHomeFolderId; } } } $folder_id = (int) $in_folder_id; // conveniently, will be 0 if not possible. if ($folder_id == 0) { $folder_id = 1; } $_REQUEST['fBrowseMode'] = 'folder'; // here we need the folder object to do the breadcrumbs. $oFolder =& Folder::get($folder_id); if (PEAR::isError($oFolder)) { return false; // just fail. } // check whether the user can edit this folder $oPerm = KTPermission::getByName('ktcore.permissions.write'); if (KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPerm, $oFolder)) { $this->editable = true; } else { $this->editable = false; } // set the title and breadcrumbs... $this->oPage->setTitle(_kt('Browse')); if (KTPermissionUtil::userHasPermissionOnItem($this->oUser, 'ktcore.permissions.folder_details', $oFolder)) { $this->oPage->setSecondaryTitle($oFolder->getName()); } else { if (KTBrowseUtil::inAdminMode($this->oUser, $oFolder)) { $this->oPage->setSecondaryTitle(sprintf('(%s)', $oFolder->getName())); } else { $this->oPage->setSecondaryTitle('...'); } } //Figure out if we came here by navigating trough a shortcut. //If we came here from a shortcut, the breadcrumbspath should be relative //to the shortcut folder. $iSymLinkFolderId = KTUtil::arrayGet($_REQUEST, 'fShortcutFolder', null); if (is_numeric($iSymLinkFolderId)) { $oBreadcrumbsFolder = Folder::get($iSymLinkFolderId); $this->aBreadcrumbs = kt_array_merge($this->aBreadcrumbs, KTBrowseUtil::breadcrumbsForFolder($oBreadcrumbsFolder, array('final' => false))); $this->aBreadcrumbs[] = array('name' => $oFolder->getName()); } else { $this->aBreadcrumbs = kt_array_merge($this->aBreadcrumbs, KTBrowseUtil::breadcrumbsForFolder($oFolder)); } $this->oFolder =& $oFolder; // we now have a folder, and need to create the query. $aOptions = array('ignorepermissions' => KTBrowseUtil::inAdminMode($this->oUser, $oFolder)); $this->oQuery = new BrowseQuery($oFolder->getId(), $this->oUser, $aOptions); $this->resultURL = KTUtil::addQueryString($_SERVER['PHP_SELF'], sprintf('fFolderId=%d', $oFolder->getId())); // and the portlets $portlet = new KTActionPortlet(sprintf(_kt('About this folder'))); $aActions = KTFolderActionUtil::getFolderInfoActionsForFolder($this->oFolder, $this->oUser); $portlet->setActions($aActions, $this->sName); $this->oPage->addPortlet($portlet); $portlet = new KTActionPortlet(sprintf(_kt('Actions on this folder'))); $aActions = KTFolderActionUtil::getFolderActionsForFolder($oFolder, $this->oUser); $portlet->setActions($aActions, null); $this->oPage->addPortlet($portlet); } else { if ($this->browse_mode == 'lookup_value') { // browsing by a lookup value $this->editable = false; // check the inputs $field = KTUtil::arrayGet($_REQUEST, 'fField', null); $oField = DocumentField::get($field); if (PEAR::isError($oField) || $oField == false) { $this->errorRedirectToMain('No Field selected.'); exit(0); } $value = KTUtil::arrayGet($_REQUEST, 'fValue', null); $oValue = MetaData::get($value); if (PEAR::isError($oValue) || $oValue == false) { $this->errorRedirectToMain('No Value selected.'); exit(0); } $this->oQuery = new ValueBrowseQuery($oField, $oValue); $this->resultURL = KTUtil::addQueryString($_SERVER['PHP_SELF'], sprintf('fBrowseMode=lookup_value&fField=%d&fValue=%d', $field, $value)); // setup breadcrumbs $this->aBreadcrumbs = array(array('name' => _kt('Lookup Values'), 'url' => KTUtil::addQueryString($_SERVER['PHP_SELF'], 'action=selectField')), array('name' => $oField->getName(), 'url' => KTUtil::addQueryString($_SERVER['PHP_SELF'], 'action=selectLookup&fField=' . $oField->getId())), array('name' => $oValue->getName(), 'url' => KTUtil::addQueryString($_SERVER['PHP_SELF'], sprintf('fBrowseMode=lookup_value&fField=%d&fValue=%d', $field, $value)))); } else { if ($this->browse_mode == 'document_type') { // browsing by document type $this->editable = false; $doctype = KTUtil::arrayGet($_REQUEST, 'fType', null); $oDocType = DocumentType::get($doctype); if (PEAR::isError($oDocType) || $oDocType == false) { $this->errorRedirectToMain('No Document Type selected.'); exit(0); } $this->oQuery = new TypeBrowseQuery($oDocType); // FIXME probably want to redirect to self + action=selectType $this->aBreadcrumbs[] = array('name' => _kt('Document Types'), 'url' => KTUtil::addQueryString($_SERVER['PHP_SELF'], 'action=selectType')); $this->aBreadcrumbs[] = array('name' => $oDocType->getName(), 'url' => KTUtil::addQueryString($_SERVER['PHP_SELF'], 'fBrowseMode=document_type&fType=' . $oDocType->getId())); $this->resultURL = KTUtil::addQueryString($_SERVER['PHP_SELF'], sprintf('fType=%s&fBrowseMode=document_type', $doctype)); } else { // FIXME what should we do if we can't initiate the browse? we "pretend" to have no perms. return false; } } } return true; }
function form_changetype() { $oForm = new KTForm(); $oForm->setOptions(array('label' => _kt("Change Document Type"), 'description' => _kt("Changing the document type will allow different metadata to be associated with it."), 'identifier' => 'ktcore.doc.edit.typechange', 'submit_label' => _kt("Update Document"), 'context' => $this, 'cancel_action' => 'main', 'action' => 'trytype')); $type = DocumentType::get($this->oDocument->getDocumentTypeId()); $current_type_name = $type->getName(); $oFolder = Folder::get($this->oDocument->getFolderID()); $oForm->setWidgets(array(array('ktcore.widgets.entityselection', array('label' => _kt("New Document Type"), 'description' => _kt("Please select the new type for this document."), 'important_description' => sprintf(_kt("The document is currently of type \"%s\"."), $current_type_name), 'value' => $type->getId(), 'label_method' => 'getName', 'vocab' => DocumentType::getListForUserAndFolder($this->oUser, $oFolder), 'simple_select' => false, 'required' => true, 'name' => 'type')))); $oForm->setValidators(array(array('ktcore.validators.entity', array('test' => 'type', 'output' => 'type', 'class' => 'DocumentType')))); return $oForm; }
function do_addfieldsets() { $oDocumentType =& DocumentType::get($_REQUEST['fDocumentTypeId']); $aFieldsetId = $_REQUEST['fieldsetid']; if (!count($aFieldsetId)) { $this->errorRedirectTo('edit', _kt('You must select at least one fieldset'), 'fDocumentTypeId=' . $oDocumentType->getId()); exit(0); } $res = KTMetadataUtil::addSetsToDocumentType($oDocumentType, $aFieldsetId); if (PEAR::isError($res)) { var_dump($res); $this->errorRedirectTo('edit', _kt('Changes not saved'), 'fDocumentTypeId=' . $oDocumentType->getId()); exit(0); } $this->successRedirectTo('edit', _kt('Fieldsets associated.'), 'fDocumentTypeId=' . $oDocumentType->getId()); exit(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; }
function do_viewComparison() { $document_data = array(); $document_id = KTUtil::arrayGet($_REQUEST, 'fDocumentId'); if ($document_id === null) { $this->oPage->addError(sprintf(_kt("No document was requested. Please <a href=\"%s\">browse</a> for one."), KTBrowseUtil::getBrowseBaseUrl())); return $this->do_error(); } $document_data['document_id'] = $document_id; $base_version = KTUtil::arrayGet($_REQUEST, 'fBaseVersion'); // try get the document. $oDocument =& Document::get($document_id, $base_version); if (PEAR::isError($oDocument)) { $this->oPage->addError(sprintf(_kt("The base document you attempted to retrieve is invalid. Please <a href=\"%s\">browse</a> for one."), KTBrowseUtil::getBrowseBaseUrl())); return $this->do_error(); } if (!Permission::userHasDocumentReadPermission($oDocument)) { // FIXME inconsistent. $this->oPage->addError(_kt('You are not allowed to view this document')); return $this->permissionDenied(); } $this->oDocument =& $oDocument; $this->oPage->setSecondaryTitle($oDocument->getName()); $aOptions = array('documentaction' => 'viewDocument', 'folderaction' => 'browse'); $this->aBreadcrumbs = kt_array_merge($this->aBreadcrumbs, KTBrowseUtil::breadcrumbsForDocument($oDocument, $aOptions)); $this->oPage->setBreadcrumbDetails(_kt('compare versions')); $comparison_version = KTUtil::arrayGet($_REQUEST, 'fComparisonVersion'); if ($comparison_version === null) { $this->oPage->addError(sprintf(_kt("No comparison version was requested. Please <a href=\"%s\">select a version</a>."), KTUtil::addQueryStringSelf('action=history&fDocumentId=' . $document_id))); return $this->do_error(); } $oComparison =& Document::get($oDocument->getId(), $comparison_version); if (PEAR::isError($oComparison)) { $this->errorRedirectToMain(_kt('Invalid document to compare against.')); } $comparison_data = array(); $comparison_data['document_id'] = $oComparison->getId(); $document_data['document'] = $oDocument; $comparison_data['document'] = $oComparison; $document_data['document_type'] =& DocumentType::get($oDocument->getDocumentTypeID()); $comparison_data['document_type'] =& DocumentType::get($oComparison->getDocumentTypeID()); // follow twice: once for normal, once for comparison. $is_valid_doctype = true; if (PEAR::isError($document_data['document_type'])) { $this->oPage->addError(_kt('The document you requested has an invalid <strong>document type</strong>. Unfortunately, this means that we cannot effectively display it.')); $is_valid_doctype = false; } // we want to grab all the md for this doc, since its faster that way. $mdlist =& DocumentFieldLink::getList(array('metadata_version_id = ?', array($base_version))); $field_values = array(); foreach ($mdlist as $oFieldLink) { $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue(); } $document_data['field_values'] = $field_values; $mdlist =& DocumentFieldLink::getList(array('metadata_version_id = ?', array($comparison_version))); $field_values = array(); foreach ($mdlist as $oFieldLink) { $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue(); } $comparison_data['field_values'] = $field_values; // Fieldset generation. // // we need to create a set of FieldsetDisplay objects // that adapt the Fieldsets associated with this lot // to the view (i.e. ZX3). Unfortunately, we don't have // any of the plumbing to do it, so we handle this here. $fieldsets = array(); // we always have a generic. array_push($fieldsets, new GenericFieldsetDisplay()); // FIXME can we key this on fieldset namespace? or can we have duplicates? // now we get the other fieldsets, IF there is a valid doctype. if ($is_valid_doctype) { // these are the _actual_ fieldsets. $fieldsetDisplayReg =& KTFieldsetDisplayRegistry::getSingleton(); // and the generics $activesets = KTFieldset::getGenericFieldsets(); foreach ($activesets as $oFieldset) { $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace()); array_push($fieldsets, new $displayClass($oFieldset)); } $activesets = KTFieldset::getForDocumentType($oDocument->getDocumentTypeID()); foreach ($activesets as $oFieldset) { $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace()); array_push($fieldsets, new $displayClass($oFieldset)); } } // FIXME handle ad-hoc fieldsets. $this->addPortlets(); $oTemplate = $this->oValidator->validateTemplate('ktcore/document/compare'); $aTemplateData = array('context' => $this, 'document_id' => $document_id, 'document' => $oDocument, 'document_data' => $document_data, 'comparison_data' => $comparison_data, 'comparison_document' => $oComparison, 'fieldsets' => $fieldsets); //var_dump($aTemplateData['comparison_data']); return $oTemplate->render($aTemplateData); }
function &getAssociatedTypes() { // NOTE: this returns null if we are generic (all is the wrong answer) if ($this->getIsGeneric()) { return array(); } $sTable = KTUtil::getTableName('document_type_fieldsets'); $aQuery = array("SELECT document_type_id FROM {$sTable} WHERE fieldset_id = ?", array($this->getId())); $aIds = DBUtil::getResultArrayKey($aQuery, 'document_type_id'); $aRet = array(); foreach ($aIds as $iID) { $oType = DocumentType::get($iID); if (!PEAR::isError($oType)) { $aRet[] = $oType; } } return $aRet; }
/** * 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; }
function do_finalise() { $this->persistParams(array('fFileKey')); $sess_key = $_REQUEST['fFileKey']; $oForm = $this->form_metadata($sess_key); $res = $oForm->validate(); if (!empty($res['errors'])) { return $oForm->handleError(); } $data = $res['results']; $extra_d = $_SESSION['_add_data'][$sess_key]; $doctypeid = $extra_d['document_type']; $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => false)); $aSpecificFieldsetIds = KTFieldset::getForDocumentType($doctypeid, array('ids' => false)); $fieldsets = kt_array_merge($aGenericFieldsetIds, $aSpecificFieldsetIds); $MDPack = array(); foreach ($fieldsets as $oFieldset) { $fields = $oFieldset->getFields(); $values = (array) KTUtil::arrayGet($data, 'fieldset_' . $oFieldset->getId()); foreach ($fields as $oField) { $val = KTUtil::arrayGet($values, 'metadata_' . $oField->getId()); if ($oFieldset->getIsConditional()) { if ($val == _kt('No selection.')) { $val = null; } } // ALT.METADATA.LAYER.DIE.DIE.DIE if (!is_null($val)) { $MDPack[] = array($oField, $val); } } } // older code $mpo =& new JavascriptObserver($this); $oUploadChannel =& KTUploadChannel::getSingleton(); $oUploadChannel->addObserver($mpo); require_once KT_LIB_DIR . '/storage/storagemanager.inc.php'; //require_once(KT_LIB_DIR . '/filelike/fsfilelike.inc.php'); require_once KT_LIB_DIR . '/documentmanagement/DocumentType.inc'; require_once KT_LIB_DIR . '/metadata/fieldset.inc.php'; require_once KT_LIB_DIR . '/documentmanagement/documentutil.inc.php'; $aErrorOptions = array('redirect_to' => array('main', sprintf('fFolderId=%d', $this->oFolder->getId())), 'max_str_len' => 200); $aFile = $this->oValidator->validateFile($extra_d['file'], $aErrorOptions); $sTitle = $extra_d['document_name']; $iFolderId = $this->oFolder->getId(); $aOptions = array('temp_file' => $aFile['tmp_name'], 'documenttype' => DocumentType::get($extra_d['document_type']), 'metadata' => $MDPack, 'description' => $sTitle, 'cleanup_initial_file' => true); $mpo->start(); //$this->startTransaction(); $oDocument =& KTDocumentUtil::add($this->oFolder, $aFile['name'], $this->oUser, $aOptions); if (PEAR::isError($oDocument)) { $message = $oDocument->getMessage(); $this->errorRedirectTo('main', sprintf(_kt("Unexpected failure to add document - %s"), $message), 'fFolderId=' . $this->oFolder->getId()); exit(0); } $this->addInfoMessage(_kt("Document added")); //$this->commitTransaction(); $mpo->redirectToDocument($oDocument->getId()); exit(0); }
function renderData($aDataRow) { // only show this for documents. if ($aDataRow['type'] === 'folder') { return ' '; } // Check if document is checked out $iDocTypeId = $aDataRow['document']->getDocumentTypeID(); if (!empty($iDocTypeId)) { $oDocumentType = DocumentType::get($iDocTypeId); $sType = $oDocumentType->getName(); return '<span class="descriptive">' . htmlentities($sType, ENT_NOQUOTES, 'UTF-8') . '</span>'; } return '—'; }
/** * This adds a document to the current folder. * * <code> * $kt = new KTAPI(); * $kt->start_session("admin", "admin"); * $folder = $kt->get_folder_by_name("My New folder"); * $res = $folder->add_document("Test Document", "test.txt", "Default", $tmpfname); * </code> * * @author KnowledgeTree Team * @access public * @param string $title This is the title for the file in the repository. * @param string $filename This is the filename in the system for the file. * @param string $documenttype This is the name or id of the document type. It first looks by name, then by id. * @param string $tempfilename This is a reference to the file that is accessible locally on the file system. * @return KTAPI_Document */ function add_document($title, $filename, $documenttype, $tempfilename) { if (!is_file($tempfilename)) { return new PEAR_Error('File does not exist.'); } $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_WRITE); if (PEAR::isError($user)) { return $user; } //KTS-4016: removed the replacing of special characters from the title as they should be allowed there //$title = KTUtil::replaceInvalidCharacters($title); $filename = basename($filename); $filename = KTUtil::replaceInvalidCharacters($filename); $documenttypeid = KTAPI::get_documenttypeid($documenttype); if (PEAR::isError($documenttypeid)) { $config = KTCache::getSingleton(); $defaultToDefaultDocType = $config->get('webservice/useDefaultDocumentTypeIfInvalid', true); if ($defaultToDefaultDocType) { $documenttypeid = KTAPI::get_documenttypeid('Default'); } else { return new KTAPI_DocumentTypeError('The document type could not be resolved or is disabled: ' . $documenttype); } } $options = array('contents' => new KTFSFileLike($tempfilename), 'temp_file' => $tempfilename, 'novalidate' => true, 'documenttype' => DocumentType::get($documenttypeid), 'description' => $title, 'metadata' => array(), 'cleanup_initial_file' => true); DBUtil::startTransaction(); $document =& KTDocumentUtil::add($this->folder, $filename, $user, $options); if (PEAR::isError($document)) { DBUtil::rollback(); return new PEAR_Error(KTAPI_ERROR_INTERNAL_ERROR . ' : ' . $document->getMessage()); } DBUtil::commit(); KTUploadManager::temporary_file_imported($tempfilename); return new KTAPI_Document($this->ktapi, $this, $document); }