function do_assign_handler() { $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); $aTriggers = $oKTTriggerRegistry->getTriggers('workflow', 'objectModification'); $selection_ns = KTUtil::arrayGet($_REQUEST, 'selection_ns'); if (empty($selection_ns)) { $sQuery = 'DELETE FROM ' . KTUtil::getTableName('trigger_selection'); $sQuery .= ' WHERE event_ns = ?'; $aParams = array('ktstandard.workflowassociation.handler'); DBUtil::runQuery(array($sQuery, $aParams)); $this->successRedirectToMain(_kt('Handler removed.')); } else { if (!array_key_exists($selection_ns, $aTriggers)) { $this->errorRedirectToMain(_kt('Invalid assignment')); } // clear $sQuery = 'DELETE FROM ' . KTUtil::getTableName('trigger_selection'); $sQuery .= ' WHERE event_ns = ?'; $aParams = array('ktstandard.workflowassociation.handler'); DBUtil::runQuery(array($sQuery, $aParams)); // set $sQuery = 'INSERT INTO ' . KTUtil::getTableName('trigger_selection'); $sQuery .= ' (event_ns, selection_ns)'; $sQuery .= ' VALUES ("ktstandard.workflowassociation.handler",?)'; $aParams = array($selection_ns); DBUtil::runQuery(array($sQuery, $aParams)); $this->successRedirectToMain(_kt('Handler set.')); } }
function do_main() { global $default; // Check for any triggers on logout $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); $aTriggers = $oKTTriggerRegistry->getTriggers('logout', 'postValidate'); foreach ($aTriggers as $aTrigger) { $sTrigger = $aTrigger[0]; $oTrigger = new $sTrigger(); $ret = $oTrigger->postValidate(); } /*$oAuthenticator =& KTAuthenticationUtil::getAuthenticatorForUser($this->oUser); $oAuthenticator->logout($this->oUser);*/ Session::destroy(); redirect(!empty($default->rootUrl) ? $default->rootUrl : '/'); exit(0); }
function KTWorkflowAssociationDelegator() { $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); $aTriggers = $oKTTriggerRegistry->getTriggers('workflow', 'objectModification'); // if we have _some_ triggers. if (!empty($aTriggers)) { $sQuery = 'SELECT selection_ns FROM ' . KTUtil::getTableName('trigger_selection'); $sQuery .= ' WHERE event_ns = ?'; $aParams = array('ktstandard.workflowassociation.handler'); $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'selection_ns'); if (PEAR::isError($res)) { $this->_handler = new KTWorkflowAssociationHandler(); } if (array_key_exists($res, $aTriggers)) { $this->_handler = new $aTriggers[$res][0](); } else { $this->_handler = new KTWorkflowAssociationHandler(); } } else { $this->_handler = new KTWorkflowAssociationHandler(); } }
function do_checkout_final() { $sReason = KTUtil::arrayGet($_REQUEST, 'reason'); $this->oValidator->notEmpty($sReason); $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); $aTriggers = $oKTTriggerRegistry->getTriggers('checkoutDownload', 'postValidate'); foreach ($aTriggers as $aTrigger) { $sTrigger = $aTrigger[0]; $oTrigger = new $sTrigger(); $aInfo = array('document' => $this->oDocument); $oTrigger->setInfo($aInfo); $ret = $oTrigger->postValidate(); if (PEAR::isError($ret)) { return $ret; } } $oStorage =& KTStorageManagerUtil::getSingleton(); $oStorage->download($this->oDocument, true); exit(0); }
function do_trytype() { $oForm = $this->form_changetype(); $res = $oForm->validate(); $data = $res['results']; $errors = $res['errors']; if (!empty($errors)) { $oForm->handleError(); } $document_type = $data['type']; $doctypeid = $document_type->getId(); // Get the current document type, fieldsets and metadata $iOldDocTypeID = $this->oDocument->getDocumentTypeID(); $fieldsets = KTMetadataUtil::fieldsetsForDocument($this->oDocument, $iOldDocTypeID); $mdlist = DocumentFieldLink::getByDocument($this->oDocument); $field_values = array(); foreach ($mdlist as $oFieldLink) { $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue(); } DBUtil::startTransaction(); // Update the document with the new document type id $this->oDocument->startNewMetadataVersion($this->oUser); $this->oDocument->setDocumentTypeId($doctypeid); $res = $this->oDocument->update(); if (PEAR::isError($res)) { DBUtil::rollback(); return $res; } // Ensure all values for fieldsets common to both document types are retained $fs_ids = array(); $doctype_fieldsets = KTFieldSet::getForDocumentType($doctypeid); foreach ($doctype_fieldsets as $fieldset) { $fs_ids[] = $fieldset->getId(); } $MDPack = array(); foreach ($fieldsets as $oFieldset) { if ($oFieldset->getIsGeneric() || in_array($oFieldset->getId(), $fs_ids)) { $fields = $oFieldset->getFields(); foreach ($fields as $oField) { $val = isset($field_values[$oField->getId()]) ? $field_values[$oField->getId()] : ''; if (!empty($val)) { $MDPack[] = array($oField, $val); } } } } $core_res = KTDocumentUtil::saveMetadata($this->oDocument, $MDPack, array('novalidate' => true)); if (PEAR::isError($core_res)) { DBUtil::rollback(); return $core_res; } DBUtil::commit(); $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); $aTriggers = $oKTTriggerRegistry->getTriggers('edit', 'postValidate'); foreach ($aTriggers as $aTrigger) { $sTrigger = $aTrigger[0]; $oTrigger = new $sTrigger(); $aInfo = array("document" => $this->oDocument, "aOptions" => $MDPack); $oTrigger->setInfo($aInfo); $ret = $oTrigger->postValidate(); } // Check if there are any dynamic conditions / permissions that need to be updated on the document // If there are dynamic conditions then update the permissions on the document // The dynamic condition test fails unless the changes exists in the DB therefore update permissions after committing the transaction. $iPermissionObjectId = $this->oDocument->getPermissionObjectID(); $dynamicCondition = KTPermissionDynamicCondition::getByPermissionObjectId($iPermissionObjectId); if (!PEAR::isError($dynamicCondition) && !empty($dynamicCondition)) { $res = KTPermissionUtil::updatePermissionLookup($this->oDocument); } $this->successRedirectToMain(sprintf(_kt("You have selected a new document type: %s. "), $data['type']->getName())); }
function do_finish_expunge() { $selected_docs = KTUtil::arrayGet($_REQUEST, 'selected_docs', array()); $aDocuments = array(); foreach ($selected_docs as $doc_id) { $oDoc =& Document::get($doc_id); if (PEAR::isError($oDoc) || $oDoc === false) { $this->errorRedirectToMain(_kt('Invalid document id specified. Aborting expunge')); } else { if ($oDoc->getStatusId() != DELETED) { $this->errorRedirectToMain(sprintf(_kt('%s is not a deleted document. Aborting expunge'), $oDoc->getName())); } } $aDocuments[] = $oDoc; } $this->startTransaction(); $aErrorDocuments = array(); $aSuccessDocuments = array(); $oStorage =& KTStorageManagerUtil::getSingleton(); foreach ($aDocuments as $oDoc) { // first evaluate the folder for inconsistencies. $oFolder = Folder::get($oDoc->getFolderID()); if (PEAR::isError($oFolder)) { $oDoc->setFolderId(1); $oDoc->update(); } if (!$oStorage->expunge($oDoc)) { $aErrorDocuments[] = $oDoc->getDisplayPath(); } else { $oDocumentTransaction =& new DocumentTransaction($oDoc, _kt('Document expunged'), 'ktcore.transactions.expunge'); $oDocumentTransaction->create(); // delete this from the db now if (!$oDoc->delete()) { $aErrorDocuments[] = $oDoc->getId(); } else { // removed succesfully $aSuccessDocuments[] = $oDoc->getDisplayPath(); // remove any document data $oDoc->cleanupDocumentData($oDoc->getId()); // silly - why the redundancy? $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); $aTriggers = $oKTTriggerRegistry->getTriggers('expunge', 'finalised'); foreach ($aTriggers as $aTrigger) { $sTrigger = $aTrigger[0]; $oTrigger = new $sTrigger(); $aInfo = array('document' => $oDoc); $oTrigger->setInfo($aInfo); $ret = $oTrigger->finalised(); } } } } $this->commitTransaction(); $msg = sprintf(_kt('%d documents expunged.'), count($aSuccessDocuments)); if (count($aErrorDocuments) != 0) { $msg .= _kt('Failed to expunge') . ': ' . join(', ', $aErrorDocuments); } $this->successRedirectToMain($msg); }
/** * This updates the metadata on the document. This includes the 'title'. * * <code> * $ktapi = new KTAPI(); * $session = $ktapi->start_system_session(); * $document = $ktapi->get_document_by_id($documentid); * $metadata = $document->get_metadata(); * foreach($metadata as $key => $fieldset){ * if($fieldset['fieldset'] == 'XYZ'){ * * foreach($fieldset['fields'] as $k => $field){ * if($field['name'] == 'ABC'){ * $metadata[$key][fields][$k]['value'] = 'new value'; * } * } * } * } * * $res = $document->update_metadata($metadata); * </code> * * @author KnowledgeTree Team * @access public * @param array This is an array containing the metadata to be associated with the document. * @return void|PEAR_Error Returns nothing on success | a PEAR_Error on failure */ function update_metadata($metadata) { global $default; if (empty($metadata)) { return; } $packed = $this->get_packed_metadata($metadata); DBUtil::startTransaction(); $user = $this->ktapi->get_user(); $this->document->setLastModifiedDate(getCurrentDateTime()); $this->document->setModifiedUserId($user->getId()); // Update the content version / document version if ($default->updateContentVersion) { $this->document->startNewContentVersion($user); $this->document->setMinorVersionNumber($this->document->getMinorVersionNumber() + 1); } else { $this->document->startNewMetadataVersion($user); } $res = $this->document->update(); if (PEAR::isError($res)) { DBUtil::rollback(); return new KTAPI_Error('Unexpected failure updating document', $res); } $result = KTDocumentUtil::saveMetadata($this->document, $packed, array('novalidate' => true)); if (is_null($result)) { DBUtil::rollback(); return new PEAR_Error(KTAPI_ERROR_INTERNAL_ERROR . ': Null result returned but not expected.'); } if (PEAR::isError($result)) { DBUtil::rollback(); return new KTAPI_Error('Unexpected validation failure', $result); } DBUtil::commit(); $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); $aTriggers = $oKTTriggerRegistry->getTriggers('edit', 'postValidate'); foreach ($aTriggers as $aTrigger) { $sTrigger = $aTrigger[0]; $oTrigger = new $sTrigger(); $aInfo = array("document" => $this->document, "aOptions" => $packed); $oTrigger->setInfo($aInfo); $ret = $oTrigger->postValidate(); } }
/** * Original load function for the plugins * @deprecated */ function load2() { if (!$this->isRegistered()) { return; } $this->setup(); require_once KT_LIB_DIR . '/actions/actionregistry.inc.php'; require_once KT_LIB_DIR . '/actions/portletregistry.inc.php'; require_once KT_LIB_DIR . '/triggers/triggerregistry.inc.php'; require_once KT_LIB_DIR . '/plugins/pageregistry.inc.php'; require_once KT_LIB_DIR . '/authentication/authenticationproviderregistry.inc.php'; require_once KT_LIB_DIR . "/plugins/KTAdminNavigation.php"; require_once KT_LIB_DIR . "/dashboard/dashletregistry.inc.php"; require_once KT_LIB_DIR . "/i18n/i18nregistry.inc.php"; require_once KT_LIB_DIR . "/help/help.inc.php"; require_once KT_LIB_DIR . "/workflow/workflowutil.inc.php"; require_once KT_LIB_DIR . "/widgets/widgetfactory.inc.php"; require_once KT_LIB_DIR . "/validation/validatorfactory.inc.php"; require_once KT_LIB_DIR . "/browse/columnregistry.inc.php"; require_once KT_LIB_DIR . "/browse/criteriaregistry.php"; require_once KT_LIB_DIR . "/authentication/interceptorregistry.inc.php"; $oPRegistry =& KTPortletRegistry::getSingleton(); $oTRegistry =& KTTriggerRegistry::getSingleton(); $oARegistry =& KTActionRegistry::getSingleton(); $oPageRegistry =& KTPageRegistry::getSingleton(); $oAPRegistry =& KTAuthenticationProviderRegistry::getSingleton(); $oAdminRegistry =& KTAdminNavigationRegistry::getSingleton(); $oDashletRegistry =& KTDashletRegistry::getSingleton(); $oi18nRegistry =& KTi18nRegistry::getSingleton(); $oKTHelpRegistry =& KTHelpRegistry::getSingleton(); $oWFTriggerRegistry =& KTWorkflowTriggerRegistry::getSingleton(); $oColumnRegistry =& KTColumnRegistry::getSingleton(); $oNotificationHandlerRegistry =& KTNotificationRegistry::getSingleton(); $oTemplating =& KTTemplating::getSingleton(); $oWidgetFactory =& KTWidgetFactory::getSingleton(); $oValidatorFactory =& KTValidatorFactory::getSingleton(); $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton(); $oInterceptorRegistry =& KTInterceptorRegistry::getSingleton(); foreach ($this->_aPortlets as $k => $v) { call_user_func_array(array(&$oPRegistry, 'registerPortlet'), $v); } foreach ($this->_aTriggers as $k => $v) { call_user_func_array(array(&$oTRegistry, 'registerTrigger'), $v); } foreach ($this->_aActions as $k => $v) { call_user_func_array(array(&$oARegistry, 'registerAction'), $v); } foreach ($this->_aPages as $k => $v) { call_user_func_array(array(&$oPageRegistry, 'registerPage'), $v); } foreach ($this->_aAuthenticationProviders as $k => $v) { call_user_func_array(array(&$oAPRegistry, 'registerAuthenticationProvider'), $v); } foreach ($this->_aAdminCategories as $k => $v) { call_user_func_array(array(&$oAdminRegistry, 'registerCategory'), $v); } foreach ($this->_aAdminPages as $k => $v) { call_user_func_array(array(&$oAdminRegistry, 'registerLocation'), $v); } foreach ($this->_aDashlets as $k => $v) { call_user_func_array(array(&$oDashletRegistry, 'registerDashlet'), $v); } foreach ($this->_ai18n as $k => $v) { call_user_func_array(array(&$oi18nRegistry, 'registeri18n'), $v); } foreach ($this->_ai18nLang as $k => $v) { call_user_func_array(array(&$oi18nRegistry, 'registeri18nLang'), $v); } foreach ($this->_aLanguage as $k => $v) { call_user_func_array(array(&$oi18nRegistry, 'registerLanguage'), $v); } foreach ($this->_aHelpLanguage as $k => $v) { call_user_func_array(array(&$oKTHelpRegistry, 'registerHelp'), $v); } foreach ($this->_aWFTriggers as $k => $v) { call_user_func_array(array(&$oWFTriggerRegistry, 'registerWorkflowTrigger'), $v); } foreach ($this->_aColumns as $k => $v) { call_user_func_array(array(&$oColumnRegistry, 'registerColumn'), $v); } foreach ($this->_aViews as $k => $v) { call_user_func_array(array(&$oColumnRegistry, 'registerView'), $v); } foreach ($this->_aNotificationHandlers as $k => $v) { call_user_func_array(array(&$oNotificationHandlerRegistry, 'registerNotificationHandler'), $v); } foreach ($this->_aTemplateLocations as $k => $v) { call_user_func_array(array(&$oTemplating, 'addLocation'), $v); } foreach ($this->_aCriteria as $k => $v) { call_user_func_array(array(&$oCriteriaRegistry, 'registerCriterion'), $v); } foreach ($this->_aWidgets as $k => $v) { call_user_func_array(array(&$oWidgetFactory, 'registerWidget'), $v); } foreach ($this->_aValidators as $k => $v) { call_user_func_array(array(&$oValidatorFactory, 'registerValidator'), $v); } foreach ($this->_aInterceptors as $k => $v) { call_user_func_array(array(&$oInterceptorRegistry, 'registerInterceptor'), $v); } }
/** * Load the plugins into the global space * * @param array $aPlugins */ function load($aPlugins) { require_once KT_LIB_DIR . '/actions/actionregistry.inc.php'; require_once KT_LIB_DIR . '/actions/portletregistry.inc.php'; require_once KT_LIB_DIR . '/triggers/triggerregistry.inc.php'; require_once KT_LIB_DIR . '/plugins/pageregistry.inc.php'; require_once KT_LIB_DIR . '/authentication/authenticationproviderregistry.inc.php'; require_once KT_LIB_DIR . "/plugins/KTAdminNavigation.php"; require_once KT_LIB_DIR . "/dashboard/dashletregistry.inc.php"; require_once KT_LIB_DIR . "/i18n/i18nregistry.inc.php"; require_once KT_LIB_DIR . "/help/help.inc.php"; require_once KT_LIB_DIR . "/workflow/workflowutil.inc.php"; require_once KT_LIB_DIR . "/widgets/widgetfactory.inc.php"; require_once KT_LIB_DIR . "/validation/validatorfactory.inc.php"; require_once KT_LIB_DIR . "/browse/columnregistry.inc.php"; require_once KT_LIB_DIR . "/browse/criteriaregistry.php"; require_once KT_LIB_DIR . "/authentication/interceptorregistry.inc.php"; $oPRegistry =& KTPortletRegistry::getSingleton(); $oTRegistry =& KTTriggerRegistry::getSingleton(); $oARegistry =& KTActionRegistry::getSingleton(); $oPageRegistry =& KTPageRegistry::getSingleton(); $oAPRegistry =& KTAuthenticationProviderRegistry::getSingleton(); $oAdminRegistry =& KTAdminNavigationRegistry::getSingleton(); $oDashletRegistry =& KTDashletRegistry::getSingleton(); $oi18nRegistry =& KTi18nRegistry::getSingleton(); $oKTHelpRegistry =& KTHelpRegistry::getSingleton(); $oWFTriggerRegistry =& KTWorkflowTriggerRegistry::getSingleton(); $oColumnRegistry =& KTColumnRegistry::getSingleton(); $oNotificationHandlerRegistry =& KTNotificationRegistry::getSingleton(); $oTemplating =& KTTemplating::getSingleton(); $oWidgetFactory =& KTWidgetFactory::getSingleton(); $oValidatorFactory =& KTValidatorFactory::getSingleton(); $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton(); $oInterceptorRegistry =& KTInterceptorRegistry::getSingleton(); $oKTPluginRegistry =& KTPluginRegistry::getSingleton(); // Loop through the loaded plugins and register them for access foreach ($aPlugins as $plugin) { $sName = $plugin['namespace']; $sParams = $plugin['object']; $aParams = explode('|', $sParams); $sClassType = $plugin['classtype']; switch ($sClassType) { case 'portlet': $aLocation = unserialize($aParams[0]); if ($aLocation != false) { $aParams[0] = $aLocation; } if (isset($aParams[3])) { $aParams[3] = KTPluginUtil::getFullPath($aParams[3]); } call_user_func_array(array(&$oPRegistry, 'registerPortlet'), $aParams); break; case 'trigger': if (isset($aParams[4])) { $aParams[4] = KTPluginUtil::getFullPath($aParams[4]); } call_user_func_array(array(&$oTRegistry, 'registerTrigger'), $aParams); break; case 'action': if (isset($aParams[3])) { $aParams[3] = KTPluginUtil::getFullPath($aParams[3]); } call_user_func_array(array(&$oARegistry, 'registerAction'), $aParams); break; case 'page': if (isset($aParams[2])) { $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } call_user_func_array(array(&$oPageRegistry, 'registerPage'), $aParams); break; case 'authentication_provider': if (isset($aParams[3])) { $aParams[3] = KTPluginUtil::getFullPath($aParams[3]); } $aParams[0] = _kt($aParams[0]); call_user_func_array(array(&$oAPRegistry, 'registerAuthenticationProvider'), $aParams); break; case 'admin_category': $aParams[1] = _kt($aParams[1]); $aParams[2] = _kt($aParams[2]); call_user_func_array(array(&$oAdminRegistry, 'registerCategory'), $aParams); break; case 'admin_page': if (isset($aParams[5])) { $aParams[5] = KTPluginUtil::getFullPath($aParams[5]); } $aParams[3] = _kt($aParams[3]); $aParams[4] = _kt($aParams[4]); call_user_func_array(array(&$oAdminRegistry, 'registerLocation'), $aParams); break; case 'dashlet': if (isset($aParams[2])) { $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } call_user_func_array(array(&$oDashletRegistry, 'registerDashlet'), $aParams); break; case 'i18nlang': if (isset($aParams[2]) && $aParams[2] != 'default') { $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } call_user_func_array(array(&$oi18nRegistry, 'registeri18nLang'), $aParams); case 'i18n': if (isset($aParams[2])) { $aParams[1] = $aParams[2]; unset($aParams[2]); } else { $aParams[1] = KTPluginUtil::getFullPath($aParams[1]); } call_user_func_array(array(&$oi18nRegistry, 'registeri18n'), $aParams); break; case 'language': call_user_func_array(array(&$oi18nRegistry, 'registerLanguage'), $aParams); break; case 'help_language': if (isset($aParams[2])) { $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } call_user_func_array(array(&$oKTHelpRegistry, 'registerHelp'), $aParams); break; case 'workflow_trigger': if (isset($aParams[2])) { $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } call_user_func_array(array(&$oWFTriggerRegistry, 'registerWorkflowTrigger'), $aParams); break; case 'column': if (isset($aParams[3])) { $aParams[3] = KTPluginUtil::getFullPath($aParams[3]); } $aParams[0] = _kt($aParams[0]); call_user_func_array(array(&$oColumnRegistry, 'registerColumn'), $aParams); break; case 'view': $aParams[0] = _kt($aParams[0]); call_user_func_array(array(&$oColumnRegistry, 'registerView'), $aParams); break; case 'notification_handler': if (isset($aParams[2])) { $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } call_user_func_array(array(&$oNotificationHandlerRegistry, 'registerNotificationHandler'), $aParams); break; case 'template_location': if (isset($aParams[1])) { $aParams[1] = KTPluginUtil::getFullPath($aParams[1]); } call_user_func_array(array(&$oTemplating, 'addLocation2'), $aParams); break; case 'criterion': $aInit = unserialize($aParams[3]); if ($aInit != false) { $aParams[3] = $aInit; } if (isset($aParams[2])) { $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } call_user_func_array(array(&$oCriteriaRegistry, 'registerCriterion'), $aParams); break; case 'widget': if (isset($aParams[2])) { $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } call_user_func_array(array(&$oWidgetFactory, 'registerWidget'), $aParams); break; case 'validator': if (isset($aParams[2])) { $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } call_user_func_array(array(&$oValidatorFactory, 'registerValidator'), $aParams); break; case 'interceptor': if (isset($aParams[2])) { $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } call_user_func_array(array(&$oInterceptorRegistry, 'registerInterceptor'), $aParams); break; case 'plugin': if (isset($aParams[2])) { $aParams[2] = KTPluginUtil::getFullPath($aParams[2]); } $oKTPluginRegistry->_aPluginDetails[$sName] = $aParams; break; } } }
function perform_action($oEntity) { // checkout document $sReason = $this->sReason; if (is_a($oEntity, 'Document')) { if ($oEntity->getImmutable()) { return PEAR::raiseError($oEntity->getName() . ': ' . _kt('Document cannot be checked out as it is immutable')); } if ($oEntity->getIsCheckedOut()) { $checkedOutUser = $oEntity->getCheckedOutUserID(); $sUserId = $_SESSION['userID']; if ($checkedOutUser != $sUserId) { $oCheckedOutUser = User::get($checkedOutUser); return PEAR::raiseError($oEntity->getName() . ': ' . _kt('Document has already been checked out by ') . $oCheckedOutUser->getName()); } } else { $res = KTDocumentUtil::checkout($oEntity, $sReason, $this->oUser); if (PEAR::isError($res)) { return PEAR::raiseError($oEntity->getName() . ': ' . $res->getMessage()); } } if ($this->bDownload) { if ($this->bNoisy) { $oDocumentTransaction = new DocumentTransaction($oEntity, "Document part of bulk checkout", 'ktstandard.transactions.check_out', array()); $oDocumentTransaction->create(); } $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); $aTriggers = $oKTTriggerRegistry->getTriggers('checkoutDownload', 'postValidate'); foreach ($aTriggers as $aTrigger) { $sTrigger = $aTrigger[0]; $oTrigger = new $sTrigger(); $aInfo = array('document' => $oEntity); $oTrigger->setInfo($aInfo); $ret = $oTrigger->postValidate(); if (PEAR::isError($ret)) { return $ret; } } $this->oZip->addDocumentToZip($oEntity); } } else { if (is_a($oEntity, 'Folder')) { // get documents and subfolders $aDocuments = array(); $oFolder = $oEntity; if ($oFolder->isSymbolicLink()) { $oFolder = $oFolder->getLinkedFolder(); } $sFolderId = $oFolder->getId(); $sFolderDocs = $oFolder->getDocumentIDs($sFolderId); // get documents directly in the folder if (!empty($sFolderDocs)) { $aDocuments = explode(',', $sFolderDocs); } // Get all the folders within the current folder $sWhereClause = "parent_folder_ids = '{$sFolderId}' OR\n parent_folder_ids LIKE '{$sFolderId},%' OR\n parent_folder_ids LIKE '%,{$sFolderId},%' OR\n parent_folder_ids LIKE '%,{$sFolderId}'"; $aFolderList = $this->oFolder->getList($sWhereClause); $aLinkingFolders = $this->getLinkingEntities($aFolderList); $aFolderList = array_merge($aFolderList, $aLinkingFolders); $aFolderObjects = array(); $aFolderObjects[$sFolderId] = $oFolder; // Get the documents within the folder if (!empty($aFolderList)) { foreach ($aFolderList as $k => $oFolderItem) { if (Permission::userHasFolderReadPermission($oFolderItem)) { // Get documents for each folder if ($oFolderItem->isSymbolicLink()) { $oFolderItem = $oFolderItem->getLinkedFolder(); } $sFolderItemId = $oFolderItem->getID(); $sFolderItemDocs = $oFolderItem->getDocumentIDs($sFolderItemId); if (!empty($sFolderItemDocs)) { $aFolderDocs = explode(',', $sFolderItemDocs); $aDocuments = array_merge($aDocuments, $aFolderDocs); } // Add the folder to the zip file if ($this->bDownload) { $this->oZip->addFolderToZip($oFolderItem); $aFolderObjects[$oFolderItem->getId()] = $oFolderItem; } } } } // Checkout each document within the folder structure if (!empty($aDocuments)) { foreach ($aDocuments as $sDocId) { $oDocument = Document::get($sDocId); if (PEAR::isError($oDocument)) { // add message, skip document and continue $this->addErrorMessage($oDocument->getName() . ': ' . $oDocument->getMessage()); continue; } if ($oDocument->isSymbolicLink()) { $oDocument->switchToLinkedCore(); } if ($oDocument->getImmutable()) { $this->addErrorMessage($oDocument->getName() . ': ' . _kt('Document cannot be checked out as it is immutable')); continue; } // Check if the action is restricted by workflow on the document if (!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.checkout')) { $this->addErrorMessage($oDocument->getName() . ': ' . _kt('Checkout is restricted by the workflow state.')); continue; } // Check if document is already checked out, check the owner. // If the current user is the owner, then include to the download, otherwise ignore. if ($oDocument->getIsCheckedOut()) { $checkedOutUser = $oDocument->getCheckedOutUserID(); $sUserId = $_SESSION['userID']; if ($checkedOutUser != $sUserId) { $oCheckedOutUser = User::get($checkedOutUser); $this->addErrorMessage($oDocument->getName() . ': ' . _kt('Document has already been checked out by ') . $oCheckedOutUser->getName()); continue; } } else { // Check out document $res = KTDocumentUtil::checkout($oDocument, $sReason, $this->oUser); if (PEAR::isError($res)) { $this->addErrorMessage($oDocument->getName() . ': ' . _kt('Document could not be checked out. ') . $res->getMessage()); continue; } } // Add document to the zip file if ($this->bDownload) { if ($this->bNoisy) { $oDocumentTransaction = new DocumentTransaction($oDocument, 'Document part of bulk checkout', 'ktstandard.transactions.check_out', array()); $oDocumentTransaction->create(); } $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); $aTriggers = $oKTTriggerRegistry->getTriggers('checkoutDownload', 'postValidate'); foreach ($aTriggers as $aTrigger) { $sTrigger = $aTrigger[0]; $oTrigger = new $sTrigger(); $aInfo = array('document' => $oDocument); $oTrigger->setInfo($aInfo); $ret = $oTrigger->postValidate(); if (PEAR::isError($ret)) { return $ret; } } $sDocFolderId = $oDocument->getFolderID(); $oFolder = isset($aFolderObjects[$sDocFolderId]) ? $aFolderObjects[$sDocFolderId] : Folder::get($sDocFolderId); $this->oZip->addDocumentToZip($oDocument, $oFolder); } } } } } return true; }
function do_postreply() { $aErrorOptions = array('redirect_to' => array('main', sprintf('fDocumentId=%d', $this->oDocument->getId()))); $iThreadId = KTUtil::arrayGet($_REQUEST, 'fThreadId'); $oThread = DiscussionThread::get($iThreadId); $this->oValidator->notError($oThread, $aErrorOptions); $aErrorOptions = array('redirect_to' => array('viewthread', sprintf('fDocumentId=%d&fThreadId=%d', $this->oDocument->getId(), $oThread->getId()))); $aErrorOptions['message'] = _kt("No subject provided"); $sSubject = KTUtil::arrayGet($_REQUEST, 'subject'); $sSubject = $this->oValidator->validateString($sSubject, $aErrorOptions); $aErrorOptions['message'] = _kt("No body provided"); $sBody = KTUtil::arrayGet($_REQUEST, 'body'); $sBody = $this->oValidator->validateString($sBody, $aErrorOptions); // Start the transaction comment creation $this->startTransaction(); // Create comment $oComment = DiscussionComment::createFromArray(array('threadid' => $oThread->getId(), 'userid' => $this->oUser->getId(), 'subject' => $sSubject, 'body' => KTUtil::formatPlainText($sBody))); $aErrorOptions['message'] = _kt("There was an error adding the comment to the thread"); $this->oValidator->notError($oComment, $aErrorOptions); // Update thread $oThread->setLastCommentId($oComment->getId()); $oThread->incrementNumberOfReplies(); $res = $oThread->update(); // add to searchable_text. $sTable = KTUtil::getTableName('comment_searchable_text'); $aSearch = array('comment_id' => $oComment->getId(), 'document_id' => $this->oDocument->getId(), 'body' => sprintf("%s %s", KTUtil::formatPlainText($sBody), $sSubject)); DBUtil::autoInsert($sTable, $aSearch, array('noid' => true)); $aErrorOptions['message'] = _kt("There was an error updating the thread with the new comment"); $this->oValidator->notError($res, $aErrorOptions); $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); $aTriggers = $oKTTriggerRegistry->getTriggers('discussion', 'postValidate'); foreach ($aTriggers as $aTrigger) { $sTrigger = $aTrigger[0]; $oTrigger = new $sTrigger(); $aInfo = array("document" => $this->oDocument, "comment" => $oComment); $oTrigger->setInfo($aInfo); $ret = $oTrigger->postValidate(); if (PEAR::isError($ret)) { $this->oValidator->notError($res, $aErrorOptions); } } // Thread and comment created correctly, commit to database $this->commitTransaction(); $this->successRedirectTo('viewThread', _kt("Reply posted"), sprintf('fDocumentId=%d&fThreadId=%d', $this->oDocument->getId(), $oThread->getId())); exit(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. }
function move($oDocument, $oToFolder, $oUser = null, $sReason = null) { //make sure we move the symlink, and the document it's linking to if ($oDocument->isSymbolicLink()) { $oDocument->switchToRealCore(); } else { $oDocument->switchToLinkedCore(); } $oFolder = $oToFolder; // alias. $oOriginalFolder = Folder::get($oDocument->getFolderId()); $iOriginalFolderPermissionObjectId = $oOriginalFolder->getPermissionObjectId(); $iDocumentPermissionObjectId = $oDocument->getPermissionObjectId(); if ($iDocumentPermissionObjectId === $iOriginalFolderPermissionObjectId) { $oDocument->setPermissionObjectId($oFolder->getPermissionObjectId()); } //put the document in the new folder $oDocument->setFolderID($oFolder->getId()); $sName = $oDocument->getName(); $sFilename = $oDocument->getFileName(); $oDocument->setFileName(KTDocumentUtil::getUniqueFilename($oToFolder, $sFilename)); $oDocument->setName(KTDocumentUtil::getUniqueDocumentName($oToFolder, $sName)); $res = $oDocument->update(); if (PEAR::isError($res)) { return $res; } //move the document on the file system(not if it's a symlink) if (!$oDocument->isSymbolicLink()) { $oStorage =& KTStorageManagerUtil::getSingleton(); $res = $oStorage->moveDocument($oDocument, $oFolder, $oOriginalFolder); if (PEAR::isError($res) || $res === false) { $oDocument->setFolderID($oOriginalFolder->getId()); $res = $oDocument->update(); if (PEAR::isError($res)) { return $res; } return $res; // we failed, bail. } } $sMoveMessage = sprintf(_kt("Moved from %s/%s to %s/%s. %s"), $oOriginalFolder->getFullPath(), $oOriginalFolder->getName(), $oFolder->getFullPath(), $oFolder->getName(), $sReason); // create the document transaction record $oDocumentTransaction = new DocumentTransaction($oDocument, $sMoveMessage, 'ktcore.transactions.move'); $oDocumentTransaction->create(); $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); $aTriggers = $oKTTriggerRegistry->getTriggers('moveDocument', 'postValidate'); foreach ($aTriggers as $aTrigger) { $sTrigger = $aTrigger[0]; $oTrigger = new $sTrigger(); $aInfo = array('document' => $oDocument, 'old_folder' => $oOriginalFolder, 'new_folder' => $oFolder); $oTrigger->setInfo($aInfo); $ret = $oTrigger->postValidate(); if (PEAR::isError($ret)) { return $ret; } } // fire subscription alerts for the moved document $oSubscriptionEvent = new SubscriptionEvent(); $oSubscriptionEvent->MoveDocument($oDocument, $oFolder, $oOriginalFolder); return KTPermissionUtil::updatePermissionLookup($oDocument); }