function do_main() { $this->oPage->setBreadcrumbDetails(_kt("transactions")); $this->oPage->setTitle(_kt('Folder transactions')); $folder_data = array(); $folder_data["folder_id"] = $this->oFolder->getId(); $this->oPage->setSecondaryTitle($this->oFolder->getName()); $aTransactions = array(); // FIXME do we really need to use a raw db-access here? probably... $sQuery = "SELECT DTT.name AS transaction_name, FT.transaction_namespace, U.name AS user_name, FT.comment AS comment, FT.datetime AS datetime " . "FROM " . KTUtil::getTableName("folder_transactions") . " AS FT LEFT JOIN " . KTUtil::getTableName("users") . " AS U ON FT.user_id = U.id " . "LEFT JOIN " . KTUtil::getTableName("transaction_types") . " AS DTT ON DTT.namespace = FT.transaction_namespace " . "WHERE FT.folder_id = ? ORDER BY FT.datetime DESC"; $aParams = array($this->oFolder->getId()); $res = DBUtil::getResultArray(array($sQuery, $aParams)); if (PEAR::isError($res)) { var_dump($res); // FIXME be graceful on failure. exit(0); } // FIXME roll up view transactions $aTransactions = $res; // Set the namespaces where not in the transactions lookup foreach ($aTransactions as $key => $transaction) { if (empty($transaction['transaction_name'])) { $aTransactions[$key]['transaction_name'] = $this->_getActionNameForNamespace($transaction['transaction_namespace']); } } // render pass. $this->oPage->title = _kt("Folder History"); $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate("kt3/view_folder_history"); $aTemplateData = array("context" => $this, "folder_id" => $folder_id, "folder" => $this->oFolder, "transactions" => $aTransactions); return $oTemplate->render($aTemplateData); }
function transform() { global $default; $iMimeTypeId = $this->oDocument->getMimeTypeId(); $sMimeType = KTMime::getMimeTypeName($iMimeTypeId); $sFileName = $this->oDocument->getFileName(); $aTestTypes = array('application/octet-stream', 'application/zip', 'application/x-zip'); if (in_array($sMimeType, $aTestTypes)) { $sExtension = KTMime::stripAllButExtension($sFileName); $sTable = KTUtil::getTableName('mimetypes'); $sQuery = "SELECT id, mimetypes FROM {$sTable} WHERE LOWER(filetypes) = ?"; $aParams = array($sExtension); $aRow = DBUtil::getOneResult(array($sQuery, $aParams)); if (PEAR::isError($aRow)) { $default->log->debug("ODI: error in query: " . print_r($aRow, true)); return; } if (empty($aRow)) { $default->log->debug("ODI: query returned entry"); return; } $id = $aRow['id']; $mimetype = $aRow['mimetypes']; $default->log->debug("ODI: query returned: " . print_r($aRow, true)); if (in_array($mimetype, $aTestTypes)) { // Haven't changed, really not an OpenDocument file... return; } if ($id) { $this->oDocument->setMimeTypeId($id); $this->oDocument->update(); } } parent::transform(); }
function do_main() { $this->oPage->setSecondaryTitle($this->oDocument->getName()); $this->oPage->setBreadcrumbDetails(_kt('history')); $aTransactions = array(); // FIXME create a sane "view user information" page somewhere. // FIXME do we really need to use a raw db-access here? probably... $sQuery = 'SELECT DTT.name AS transaction_name, DT.transaction_namespace, U.name AS user_name, DT.version AS version, DT.comment AS comment, DT.datetime AS datetime ' . 'FROM ' . KTUtil::getTableName('document_transactions') . ' AS DT INNER JOIN ' . KTUtil::getTableName('users') . ' AS U ON DT.user_id = U.id ' . 'LEFT JOIN ' . KTUtil::getTableName('transaction_types') . ' AS DTT ON DTT.namespace = DT.transaction_namespace ' . 'WHERE DT.document_id = ? ORDER BY DT.datetime DESC'; $aParams = array($this->oDocument->getId()); $res = DBUtil::getResultArray(array($sQuery, $aParams)); if (PEAR::isError($res)) { var_dump($res); // FIXME be graceful on failure. exit(0); } $aTransactions = $res; // Set the namespaces where not in the transactions lookup foreach ($aTransactions as $key => $transaction) { if (empty($transaction['transaction_name'])) { $aTransactions[$key]['transaction_name'] = $this->_getActionNameForNamespace($transaction['transaction_namespace']); } } // render pass. $this->oPage->setTitle(_kt('Document History')); $oTemplate = $this->oValidator->validateTemplate('ktcore/document/transaction_history'); $aTemplateData = array('context' => $this, 'document_id' => $this->oDocument->getId(), 'document' => $this->oDocument, 'transactions' => $aTransactions); return $oTemplate->render($aTemplateData); }
function do_update() { $sTable = KTUtil::getTableName('plugins'); $aIds = (array) KTUtil::arrayGet($_REQUEST, 'pluginids'); // Update disabled plugins $sIds = implode(',', $aIds); $sQuery = "UPDATE {$sTable} SET disabled = 1 WHERE id NOT IN ({$sIds})"; DBUtil::runQuery(array($sQuery)); // Select disabled plugins that have been enabled $sQuery = "SELECT * FROM {$sTable} WHERE disabled = 1 AND id IN ({$sIds})"; $res = DBUtil::getResultArray($sQuery); if (!PEAR::isError($res)) { // Enable the disabled plugins $sQuery = "UPDATE {$sTable} SET disabled = 0 WHERE id IN ({$sIds})"; DBUtil::runQuery(array($sQuery)); // run setup for each plugin $aEnabled = array(); if (!empty($res)) { foreach ($res as $item) { $aEnabled[] = $item['id']; } $sEnabled = implode(',', $aEnabled); $sQuery = "SELECT h.classname, h.pathname FROM {$sTable} p\n INNER JOIN plugin_helper h ON (p.namespace = h.plugin)\n WHERE classtype = 'plugin' AND p.id IN ({$sEnabled})"; $res = DBUtil::getResultArray($sQuery); if (!PEAR::isError($res)) { foreach ($res as $item) { $classname = $item['classname']; $path = $item['pathname']; if (!empty($path)) { require_once $path; } $oPlugin = new $classname($path); $oPlugin->setup(); } } } } KTPluginEntity::clearAllCaches(); // FIXME!!! Plugin manager needs to be updated to deal with this situation. This code should be in the plugin. //enabling or disabling Tag fieldset depending on whether tag cloud plugin is enabled or disabled. //Get tag cloud object $oTagClouPlugin = KTPluginEntity::getByNamespace('ktcore.tagcloud.plugin'); if (!PEAR::isError($oTagClouPlugin) && !is_a($oTagClouPlugin, 'KTEntityNoObjects') && !is_null($oTagClouPlugin)) { if ($oTagClouPlugin->getDisabled() == '1') { //disable tag fieldset $aFV = array('disabled' => true); $aWFV = array('namespace' => 'tagcloud'); $res = DBUtil::whereUpdate('fieldsets', $aFV, $aWFV); } else { //enable tag fieldset $aFV = array('disabled' => false); $aWFV = array('namespace' => 'tagcloud'); $res = DBUtil::whereUpdate('fieldsets', $aFV, $aWFV); } } // we reregister the plugins to ensure they are in the correct order KTPluginUtil::registerPlugins(); $this->successRedirectToMain(_kt('Plugins updated')); }
function outputHelpImage($sSubPath) { // FIXME there are error cases here ... $aPathInfo = KTHelp::_getLocationInfo($sSubPath); if (PEAR::isError($aPathInfo)) { return $aPathInfo; } // gets caught further up the stack $pi = pathinfo($aPathInfo['external']); $mime_type = ""; $sExtension = KTUtil::arrayGet($pi, 'extension'); if (!empty($sExtension)) { $mime_type = DBUtil::getOneResultKey(array("SELECT mimetypes FROM " . KTUtil::getTableName('mimetypes') . " WHERE LOWER(filetypes) = ?", $sExtension), "mimetypes"); } header("Content-Type: {$mime_type}"); header("Content-Length: " . filesize($fspath)); readfile($fspath); // does this output it?! 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 _table() { return KTUtil::getTableName('workflow_trigger_instances'); }
function _table() { return KTUtil::getTableName('dashlet_disable'); }
function _table() { return KTUtil::getTableName('field_behaviours'); }
if (PEAR::isError($dbSupport)) { print '<p><font color="red">Database support is not currently working. Error is: ' . htmlentities($dbSupport->toString()) . '</font></p>'; } else { ?> <p>Database connectivity successful.</p> <h3>Privileges</h3> <?php $selectPriv = DBUtil::runQuery('SELECT COUNT(id) FROM ' . $default->documents_table); if (PEAR::isError($selectPriv)) { print '<p><font color="red">Unable to do a basic database query. Error is: ' . htmlentities($selectPriv->toString()) . '</font></p>'; } else { print '<p>Basic database query successful.</p>'; } $sTable = KTUtil::getTableName('system_settings'); DBUtil::startTransaction(); $res = DBUtil::autoInsert($sTable, array('name' => 'transactionTest', 'value' => 1)); DBUtil::rollback(); $res = DBUtil::getOneResultKey("SELECT id FROM {$sTable} WHERE name = 'transactionTest'", 'id'); if (!empty($res)) { print '<p><font color="red">Transaction support not available in database</font></p>'; } else { print '<p>Database has transaction support.</p>'; } DBUtil::whereDelete($sTable, array('name' => 'transactionTest')); ?> <?php } ?>
function replaceState($oState, $oReplacement) { $state_id = KTUtil::getId($oState); $replacement_id = KTUtil::getId($oReplacement); // we need to convert: // - documents // - transitions // before we do a delete. $doc = KTUtil::getTableName('document_metadata_version'); $aDocQuery = array("UPDATE {$doc} SET workflow_state_id = ? WHERE workflow_state_id = ?", array($replacement_id, $state_id)); $res = DBUtil::runQuery($aDocQuery); if (PEAR::isError($res)) { return $res; } $wf = KTUtil::getTableName('workflow_transitions'); $aTransitionQuery = array("UPDATE {$wf} SET target_state_id = ? WHERE target_state_id = ?", array($replacement_id, $state_id)); $res = DBUtil::runQuery($aTransitionQuery); if (PEAR::isError($res)) { return $res; } $wf = KTUtil::getTableName('workflow_state_transitions'); $aTransitionQuery = array("DELETE FROM {$wf} WHERE state_id = ?", array($state_id)); $res = DBUtil::runQuery($aTransitionQuery); if (PEAR::isError($res)) { return $res; } Document::clearAllCaches(); }
function _table() { return KTUtil::getTableName('documents'); }
function _table() { return KTUtil::getTableName('column_entries'); }
/** * This returns the transaction history for the document. * * @author KnowledgeTree Team * @access public * @return array The list of transactions | a PEAR_Error on failure */ function get_transaction_history() { $sQuery = 'SELECT DTT.name AS transaction_name, U.name AS username, DT.version AS version, DT.comment AS comment, DT.datetime AS datetime ' . 'FROM ' . KTUtil::getTableName('document_transactions') . ' AS DT INNER JOIN ' . KTUtil::getTableName('users') . ' AS U ON DT.user_id = U.id ' . 'INNER JOIN ' . KTUtil::getTableName('transaction_types') . ' AS DTT ON DTT.namespace = DT.transaction_namespace ' . 'WHERE DT.document_id = ? ORDER BY DT.datetime DESC'; $aParams = array($this->documentid); $transactions = DBUtil::getResultArray(array($sQuery, $aParams)); if (is_null($transactions) || PEAR::isError($transactions)) { return new KTAPI_Error(KTAPI_ERROR_INTERNAL_ERROR, $transactions); } $config = KTConfig::getSingleton(); $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION); foreach ($transactions as $key => $transaction) { $transactions[$key]['version'] = (double) $transaction['version']; } return $transactions; }
function _table() { return KTUtil::getTableName('scheduler_tasks'); }
function _getDocumentQuery($aOptions = null) { $oUser = User::get($_SESSION['userID']); $res = KTSearchUtil::permissionToSQL($oUser, $this->sPermissionName); if (PEAR::isError($res)) { return $res; } list($sPermissionString, $aPermissionParams, $sPermissionJoin) = $res; $aPotentialWhere = array($sPermissionString, 'D.folder_id = ?', 'D.status_id = ' . ARCHIVED); $aWhere = array(); foreach ($aPotentialWhere as $sWhere) { if (empty($sWhere)) { continue; } if ($sWhere == '()') { continue; } $aWhere[] = $sWhere; } $sWhere = ''; if ($aWhere) { $sWhere = "\tWHERE " . join(' AND ', $aWhere); } $sSelect = KTUtil::arrayGet($aOptions, 'select', 'D.id'); $sQuery = sprintf('SELECT %s FROM %s AS D LEFT JOIN %s AS DM ON D.metadata_version_id = DM.id LEFT JOIN %s AS DC ON DM.content_version_id = DC.id %s %s', $sSelect, KTUtil::getTableName('documents'), KTUtil::getTableName('document_metadata_version'), KTUtil::getTableName('document_content_version'), $sPermissionJoin, $sWhere); $aParams = array(); $aParams = kt_array_merge($aParams, $aPermissionParams); $aParams[] = $this->folder_id; return array($sQuery, $aParams); }
function delete($oStartFolder, $oUser, $sReason, $aOptions = null, $bulk_action = false) { require_once KT_LIB_DIR . '/unitmanagement/Unit.inc'; $oPerm = KTPermission::getByName('ktcore.permissions.delete'); $bIgnorePermissions = KTUtil::arrayGet($aOptions, 'ignore_permissions'); $aFolderIds = array(); // of oFolder $aDocuments = array(); // of oDocument $aFailedDocuments = array(); // of String $aFailedFolders = array(); // of String $aRemainingFolders = array($oStartFolder->getId()); DBUtil::startTransaction(); while (!empty($aRemainingFolders)) { $iFolderId = array_pop($aRemainingFolders); $oFolder = Folder::get($iFolderId); if (PEAR::isError($oFolder) || $oFolder == false) { DBUtil::rollback(); return PEAR::raiseError(sprintf(_kt('Failure resolving child folder with id = %d.'), $iFolderId)); } $oUnit = Unit::getByFolder($oFolder); if (!empty($oUnit)) { DBUtil::rollback(); return PEAR::raiseError(sprintf(_kt('Cannot remove unit folder: %s.'), $oFolder->getName())); } // don't just stop ... plough on. if (!$bIgnorePermissions && !KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oFolder)) { $aFailedFolders[] = $oFolder->getName(); } else { $aFolderIds[] = $iFolderId; } // child documents $aChildDocs = Document::getList(array('folder_id = ?', array($iFolderId))); foreach ($aChildDocs as $oDoc) { if (!$bIgnorePermissions && $oDoc->getImmutable()) { if (!KTBrowseUtil::inAdminMode($oUser, $oStartFolder)) { $aFailedDocuments[] = $oDoc->getName(); continue; } } if ($bIgnorePermissions || KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oDoc) && $oDoc->getIsCheckedOut() == false) { $aDocuments[] = $oDoc; } else { $aFailedDocuments[] = $oDoc->getName(); } } // child folders. $aCFIds = Folder::getList(array('parent_id = ?', array($iFolderId)), array('ids' => true)); $aRemainingFolders = kt_array_merge($aRemainingFolders, $aCFIds); } // FIXME we could subdivide this to provide a per-item display (viz. bulk upload, etc.) if (!empty($aFailedDocuments) || !empty($aFailedFolders)) { $sFD = ''; $sFF = ''; if (!empty($aFailedDocuments)) { $sFD = _kt('Documents: ') . implode(', ', $aFailedDocuments) . '. '; } if (!empty($aFailedFolders)) { $sFF = _kt('Folders: ') . implode(', ', $aFailedFolders) . '.'; } return PEAR::raiseError(_kt('You do not have permission to delete these items. ') . $sFD . $sFF); } // now we can go ahead. foreach ($aDocuments as $oDocument) { $res = KTDocumentUtil::delete($oDocument, $sReason); if (PEAR::isError($res)) { DBUtil::rollback(); return PEAR::raiseError(_kt('Delete Aborted. Unexpected failure to delete document: ') . $oDocument->getName() . $res->getMessage()); } } $oStorage =& KTStorageManagerUtil::getSingleton(); $oStorage->removeFolderTree($oStartFolder); // Check for symbolic links to the folder and its sub folders $aSymlinks = array(); foreach ($aFolderIds as $iFolder) { $oFolder = Folder::get($iFolder); $aLinks = $oFolder->getSymbolicLinks(); $aSymlinks = array_merge($aSymlinks, $aLinks); } // documents all cleared. $sQuery = 'DELETE FROM ' . KTUtil::getTableName('folders') . ' WHERE id IN (' . DBUtil::paramArray($aFolderIds) . ')'; $aParams = $aFolderIds; $res = DBUtil::runQuery(array($sQuery, $aParams)); if (PEAR::isError($res)) { DBUtil::rollback(); return PEAR::raiseError(_kt('Failure deleting folders.')); } // now that the folder has been deleted we delete all the shortcuts if (!empty($aSymlinks)) { $links = array(); foreach ($aSymlinks as $link) { $links[] = $link['id']; } $linkIds = implode(',', $links); $query = "DELETE FROM folders WHERE id IN ({$linkIds})"; DBUtil::runQuery($query); } /* foreach($aSymlinks as $aSymlink){ KTFolderUtil::deleteSymbolicLink($aSymlink['id']); } */ // purge caches KTEntityUtil::clearAllCaches('Folder'); // and store DBUtil::commit(); return true; }
function rebuildPermissionLookups($bEmptyOnly = true) { if ($bEmptyOnly) { $sTable = KTUtil::getTableName('folders'); $sQuery = sprintf("SELECT id FROM %s WHERE permission_lookup_id IS NULL AND permission_object_id IS NOT NULL", $sTable); } else { $sTable = KTUtil::getTableName('folders'); $sQuery = sprintf("SELECT id FROM %s WHERE permission_object_id IS NOT NULL", $sTable); } $aIds = DBUtil::getResultArrayKey($sQuery, 'id'); foreach ($aIds as $iId) { $oFolder =& Folder::get($iId); KTPermissionUtil::updatePermissionLookup($oFolder); } if ($bEmptyOnly) { $sTable = KTUtil::getTableName('documents'); $sQuery = sprintf("SELECT id FROM %s WHERE permission_lookup_id IS NULL", $sTable); } else { $sTable = KTUtil::getTableName('documents'); $sQuery = sprintf("SELECT id FROM %s", $sTable); } $aIds = DBUtil::getResultArrayKey($sQuery, 'id'); foreach ($aIds as $iId) { $oDocument =& Document::get($iId); KTPermissionUtil::updatePermissionLookup($oDocument); } }
function transform() { $iMimeTypeId = $this->oDocument->getMimeTypeId(); $sMimeType = KTMime::getMimeTypeName($iMimeTypeId); if (!array_key_exists($sMimeType, $this->mimetypes)) { return; } $oStorage = KTStorageManagerUtil::getSingleton(); $sFile = $oStorage->temporaryFile($this->oDocument); $tempstub = 'transform'; if ($this->command != null) { $tempstub = $this->command; } $oKTConfig =& KTConfig::getSingleton(); $sBasedir = $oKTConfig->get("urls/tmpDirectory"); $myfilename = tempnam($sBasedir, 'kt.' . $tempstub); if (OS_WINDOWS) { $intermediate = tempnam($sBasedir, 'kt.' . $tempstub); if (!@copy($sFile, $intermediate)) { return; } } else { $intermediate = $sFile; } $contents = $this->extract_contents($intermediate, $myfilename); @unlink($myfilename); if (OS_WINDOWS) { @unlink($intermediate); } if (empty($contents)) { return; } $aInsertValues = array('document_id' => $this->oDocument->getId(), 'document_text' => $contents); $sTable = KTUtil::getTableName('document_text'); // clean up the document query "stuff". // FIXME this suggests that we should move the _old_ document_searchable_text across to the old-document's id if its a checkin. DBUtil::runQuery(array('DELETE FROM ' . $sTable . ' WHERE document_id = ?', array($this->oDocument->getId()))); DBUtil::autoInsert($sTable, $aInsertValues, array('noid' => true)); }
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; }
/** * Checks whether a conditional fieldset has the necessary * relationships set up to be usable - this means that for each * field, no matter how it is reached, there is at least one option * available to choose. */ function checkConditionalFieldsetCompleteness($oFieldset) { $oFieldset =& KTUtil::getObject('KTFieldset', $oFieldset); if ($oFieldset->getIsConditional() == false) { // If we're not conditional, we are fine. return true; } /* * First, ensure at least one master field item has a behaviour * assigned to it. That allows at least one item in the master * field to be chosen. */ $iMasterFieldId = $oFieldset->getMasterFieldId(); $sTable = KTUtil::getTableName('field_value_instances'); $sLookupTable = KTUtil::getTableName('metadata_lookup'); $aQuery = array("SELECT COUNT(FVI.id) AS cnt FROM {$sTable} AS FVI LEFT JOIN {$sLookupTable} AS ML ON (FVI.field_value_id = ML.id) WHERE FVI.field_id = ? AND ML.disabled = 0", array($iMasterFieldId)); $iCount = DBUtil::getOneResultKey($aQuery, 'cnt'); if (PEAR::isError($iCount)) { return $iCount; } $GLOBALS['default']->log->debug("Number of value instances for master field: {$iCount}"); if ($iCount == 0) { $GLOBALS['default']->log->debug("Number of value instances for master field is zero, failing"); return PEAR::raiseError(_kt("Master field has no values which are assigned to behaviours.")); } $GLOBALS['default']->log->debug("Number of value instances for master field is positive, continuing"); // fix for KTS-1023 // check that each master-field value has a valueinstance assigned. $sTable = KTUtil::getTableName('metadata_lookup'); $aQuery = array("SELECT COUNT(id) AS cnt FROM {$sTable} WHERE document_field_id = ? AND disabled = 0 ", array($iMasterFieldId)); $iValCount = DBUtil::getOneResultKey($aQuery, 'cnt'); // assumes that there cannot be more than 1 value instance for each master-field-value. if ($iValCount != $iCount) { return PEAR::raiseError(sprintf(_kt('%d values for the Master Field are not assigned to behaviours.'), $iValCount - $iCount)); } /* * Plan: For each behaviour that is assigned on the system, * ensure that it allows at least one value instance in each of * the fields that it needs to affect. */ $sTable = KTUtil::getTableName('field_value_instances'); $sFieldTable = KTUtil::getTableName('document_fields'); $aQuery = array("SELECT DISTINCT FV.behaviour_id AS behaviour_id FROM {$sTable} AS FV INNER JOIN {$sFieldTable} AS F ON FV.field_id = F.id WHERE F.parent_fieldset = ? AND FV.behaviour_id IS NOT NULL", array($oFieldset->getId())); $aBehaviourIds = DBUtil::getResultArrayKey($aQuery, 'behaviour_id'); if (PEAR::isError($aBehaviourIds)) { return $aBehaviourIds; } foreach ($aBehaviourIds as $iBehaviourId) { $GLOBALS['default']->log->debug("Checking behaviour id: " . $iBehaviourId); $oBehaviour =& KTFieldBehaviour::get($iBehaviourId); $sBehaviourName = $oBehaviour->getName(); $sBehaviourHumanName = $oBehaviour->getHumanName(); $iParentFieldId = $oBehaviour->getFieldId(); $GLOBALS['default']->log->debug(" field is " . $iParentFieldId); $aNextFields = KTMetadataUtil::getChildFieldIds($iParentFieldId); $oParentField =& DocumentField::get($iParentFieldId); $sParentFieldName = $oParentField->getName(); $GLOBALS['default']->log->debug(" next fields must include " . print_r($aNextFields, true)); $sTable = KTUtil::getTableName('field_behaviour_options'); $aQuery = array("SELECT DISTINCT field_id FROM {$sTable} WHERE behaviour_id = ?", array($iBehaviourId)); $aFields = DBUtil::getResultArrayKey($aQuery, 'field_id'); $GLOBALS['default']->log->debug(" actual fields are " . print_r($aNextFields, true)); /* foreach ($aNextFields as $iFieldId) { if (!in_array($iFieldId, $aFields)) { $GLOBALS['default']->log->debug(" field $iFieldId is not included, failing"); $oChildField =& DocumentField::get($iFieldId); $sChildFieldName = $oChildField->getName(); return PEAR::raiseError("Child field $sChildFieldName of parent field $sParentFieldName has no selectable values in behaviour $sBehaviourHumanName ($sBehaviourName)"); } */ } $GLOBALS['default']->log->debug("Got through: passed!"); return true; }
/** * postValidate method for trigger * * @return unknown */ function postValidate() { global $default; $oDocument =& $this->aInfo['document']; $aMeta =& $this->aInfo['aOptions']; // get document id $iDocId = $oDocument->getID(); // get all tags that are linked to the document $sQuery = 'SELECT tw.id FROM tag_words AS tw, document_tags AS dt, documents AS d ' . 'WHERE dt.tag_id = tw.id ' . 'AND dt.document_id = d.id ' . 'AND d.id = ?'; $aParams = array($iDocId); $aTagId = DBUtil::getResultArray(array($sQuery, $aParams)); if (PEAR::isError($aTagId)) { // XXX: log error return false; } // if there are any related tags proceed if ($aTagId) { // delete all entries from document_tags table for the document $sQuery = 'DELETE FROM document_tags ' . 'WHERE document_id = ?'; $aParams = array($iDocId); $removed = DBUtil::runQuery(array($sQuery, $aParams)); if (PEAR::isError($removed)) { // XXX: log error return false; } } // proceed to add the tags as per normal $sQuery = 'SELECT df.id AS id FROM document_fields AS df ' . 'WHERE df.name = \'Tag\''; $sTags = DBUtil::getOneResultKey(array($sQuery), 'id'); if (PEAR::isError($sTags)) { // XXX: log error return false; } $tagString = ''; if ($sTags) { // it is actually correct using $aMeta. It is different to the add trigger above... if (count($aMeta) > 0) { foreach ($aMeta as $aMetaData) { $oProxy = $aMetaData[0]; if ($oProxy->iId == $sTags) { $tagString = $aMetaData[1]; break; } } } if ($tagString != '') { $words_table = KTUtil::getTableName('tag_words'); $tagString = str_replace(' ', ' ', $tagString); $tags = explode(',', $tagString); $aTagIds = array(); foreach ($tags as $sTag) { $sTag = trim($sTag); if (mb_detect_encoding($sTag) == 'ASCII') { $sTag = strtolower($sTag); } $res = DBUtil::getOneResult(array("SELECT id FROM {$words_table} WHERE tag = ?", array($sTag))); if (PEAR::isError($res)) { return $res; } if (is_null($res)) { $id =& DBUtil::autoInsert($words_table, array('tag' => $sTag)); $aTagIds[$sTag] = $id; } else { $aTagIds[$sTag] = $res['id']; } } $doc_tags = KTUtil::getTableName('document_tags'); foreach ($aTagIds as $sTag => $tagid) { DBUtil::autoInsert($doc_tags, array('document_id' => $iDocId, 'tag_id' => $tagid), array('noid' => true)); } } } }
function _table() { return KTUtil::getTableName('plugins'); }
function _table() { return KTUtil::getTableName('role_allocations'); }
function &getByLookupAndParentBehaviour($oLookup, $oBehaviour, $aOptions = null) { $iLookupId = KTUtil::getId($oLookup); $iBehaviourId = KTUtil::getId($oBehaviour); $GLOBALS['default']->log->debug('KTValueInstance::getByLookupAndParentBehaviour: lookup id is ' . print_r($iLookupId, true)); $GLOBALS['default']->log->debug('KTValueInstance::getByLookupAndParentBehaviour: behaviour id is ' . $iBehaviourId); $sInstanceTable = KTUtil::getTableName('field_value_instances'); $sBehaviourOptionsTable = KTUtil::getTableName('field_behaviour_options'); $aQuery = array("SELECT instance_id FROM {$sBehaviourOptionsTable} AS BO INNER JOIN\n {$sInstanceTable} AS I ON BO.instance_id = I.id WHERE\n BO.behaviour_id = ? AND I.field_value_id = ?", array($iBehaviourId, $iLookupId)); $iId = DBUtil::getOneResultKey($aQuery, 'instance_id'); if (PEAR::isError($iId)) { $GLOBALS['default']->log->error('KTValueInstance::getByLookupAndParentBehaviour: error from db is: ' . print_r($iId, true)); return $iId; } if (is_null($iId)) { return null; } $GLOBALS['default']->log->debug('KTValueInstance::getByLookupAndParentBehaviour: id of instance is ' . $iId); if (KTUtil::arrayGet($aOptions, 'ids')) { return $iId; } return KTValueInstance::get($iId); }
* 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): ______________________________________ * */ $checkup = true; require_once '../../config/dmsDefaults.php'; $s = array("sql*2.99.5*0*2.99.5/dashlet_disabling.sql", "sql*2.99.5*0*2.99.5/role_allocations.sql", "sql*2.99.5*0*2.99.5/transaction_namespaces.sql", "sql*2.99.5*0*2.99.5/fieldset_field_descriptions.sql", "sql*2.99.5*0*2.99.5/role_changes.sql"); $sTable = KTUtil::getTableName('upgrades'); foreach ($s as $u) { var_dump($u); $f = array('descriptor' => $u, 'result' => true); $res = DBUtil::autoInsert($sTable, $f); var_dump($res); }
function createFolderDetailsPermission() { $sPermissionsTable = KTUtil::getTableName('permissions'); $bExists = DBUtil::getOneResultKey("SELECT COUNT(id) AS cnt FROM {$sPermissionsTable} WHERE name = 'ktcore.permissions.folder_details'", 'cnt'); if ($bExists) { return; } DBUtil::startTransaction(); $aPermissionInfo = array('human_name' => 'Core: Folder Details', 'name' => 'ktcore.permissions.folder_details', 'built_in' => true); $res = DBUtil::autoInsert($sPermissionsTable, $aPermissionInfo); if (PEAR::isError($res)) { return $res; } $iFolderDetailsPermissionId = $res; $sQuery = "SELECT id FROM {$sPermissionsTable} WHERE name = ?"; $aParams = array("ktcore.permissions.read"); $iReadPermissionId = DBUtil::getOneResultKey(array($sQuery, $aParams), "id"); $sPermissionAssignmentsTable = KTUtil::getTableName('permission_assignments'); $sQuery = "SELECT permission_object_id, permission_descriptor_id FROM {$sPermissionAssignmentsTable} WHERE permission_id = ?"; $aParams = array($iReadPermissionId); $aRows = DBUtil::getResultArray(array($sQuery, $aParams)); foreach ($aRows as $aRow) { $aRow['permission_id'] = $iFolderDetailsPermissionId; DBUtil::autoInsert($sPermissionAssignmentsTable, $aRow); } $sDocumentTable = KTUtil::getTableName('documents'); $sFolderTable = KTUtil::getTableName('folders'); DBUtil::runQuery("UPDATE {$sDocumentTable} SET permission_lookup_id = NULL"); DBUtil::runQuery("UPDATE {$sFolderTable} SET permission_lookup_id = NULL"); DBUtil::commit(); }
function getTransactionsMatchingQuery($oUser, $sJoinClause, $aExternalWhereClauses, $aExternalWhereParams, $aOptions = null) { $sSelectItems = 'DTT.name AS transaction_name, U.name AS user_name, DT.version AS version, DT.comment AS comment, DT.datetime AS datetime, D.id as document_id, DT.transaction_namespace as namespace'; $sBaseJoin = "FROM " . KTUtil::getTableName("document_transactions") . " AS DT " . "INNER JOIN " . KTUtil::getTableName("users") . " AS U ON DT.user_id = U.id " . "INNER JOIN " . KTUtil::getTableName("transaction_types") . " AS DTT ON DTT.namespace = DT.transaction_namespace " . "INNER JOIN " . KTUtil::getTableName("documents") . " AS D ON D.id = DT.document_id "; // now we're almost at partialquery like status. $perm_res = KTSearchUtil::permissionToSQL($oUser, 'ktcore.permissions.read'); if (PEAR::isError($perm_res)) { return $perm_res; } list($sPermissionString, $aPermissionParams, $sPermissionJoin) = $perm_res; // compile the final list $aFinalWhere = kt_array_merge(array($sPermissionString, 'D.creator_id IS NOT NULL'), $aExternalWhereClauses, array('D.status_id = ?')); $aFinalWhereParams = kt_array_merge($aPermissionParams, $aExternalWhereParams, array(LIVE)); if (!is_array($aOptions)) { $aOptions = (array) $aOptions; } $sOrderBy = KTUtil::arrayGet($aOptions, 'orderby', 'DT.datetime DESC'); // compile these. // NBM: do we need to wrap these in ()? $sWhereClause = implode(' AND ', $aFinalWhere); if (!empty($sWhereClause)) { $sWhereClause = 'WHERE ' . $sWhereClause; } $sQuery = sprintf("SELECT %s %s %s %s %s ORDER BY %s", $sSelectItems, $sBaseJoin, $sPermissionJoin, $sJoinClause, $sWhereClause, $sOrderBy); //var_dump(array($sQuery, $aFinalWhereParams)); $res = DBUtil::getResultArray(array($sQuery, $aFinalWhereParams)); //var_dump($res); exit(0); return $res; }
/** * Converts a criteria set into a SQL query that (by default) * returns the ids of documents that fulfil the criteria. * * $aOptions is a dictionary that can contain: * - select - a string that contains the list of columns * selected in the query * - join - a string that contains join conditions to satisfy * the select string passed or limit the documents included * * A list with the following elements is returned: * - String containing the parameterised SQL query * - Array containing the parameters for the SQL query */ function criteriaToQuery($aCriteriaSet, $oUser, $sPermissionName, $aOptions = null) { global $default; $sSelect = KTUtil::arrayGet($aOptions, 'select', 'D.id AS document_id'); $sInitialJoin = KTUtil::arrayGet($aOptions, 'join', ''); if (is_array($sInitialJoin)) { $aInitialJoinParams = $sInitialJoin[1]; $sInitialJoin = $sInitialJoin[0]; } $res = KTSearchUtil::criteriaSetToSQL($aCriteriaSet); if (PEAR::isError($res)) { return $res; } list($sSQLSearchString, $aCritParams, $sCritJoinSQL) = $res; $sToSearch = KTUtil::arrayGet($aOrigReq, 'fToSearch', 'Live'); // actually never present in this version. $res = KTSearchUtil::permissionToSQL($oUser, $sPermissionName); if (PEAR::isError($res)) { // only occurs if the group has no permissions. return $res; } else { list($sPermissionString, $aPermissionParams, $sPermissionJoin) = $res; } /* * This is to overcome the problem where $sPermissionString (or * even $sSQLSearchString) is empty, leading to leading or * trailing ANDs. */ $aPotentialWhere = array($sPermissionString, 'SL.name = ?', "({$sSQLSearchString})"); $aWhere = array(); foreach ($aPotentialWhere as $sWhere) { if (empty($sWhere)) { continue; } if ($sWhere == "()") { continue; } $aWhere[] = $sWhere; } $sWhere = ""; if ($aWhere) { $sWhere = "\tWHERE " . join(" AND ", $aWhere); } //$sQuery = DBUtil::compactQuery(" $sQuery = sprintf("\n SELECT\n %s\n FROM\n %s AS D\n LEFT JOIN %s AS DM ON D.metadata_version_id = DM.id\n LEFT JOIN %s AS DC ON DM.content_version_id = DC.id\n INNER JOIN {$default->status_table} AS SL on D.status_id=SL.id\n %s\n %s\n %s\n %s", $sSelect, KTUtil::getTableName('documents'), KTUtil::getTableName('document_metadata_version'), KTUtil::getTableName('document_content_version'), $sInitialJoin, $sCritJoinSQL, $sPermissionJoin, $sWhere); // GROUP BY D.id $aParams = array(); $aParams = kt_array_merge($aParams, $aInitialJoinParams); $aParams = kt_array_merge($aParams, $aPermissionParams); $aParams[] = $sToSearch; $aParams = kt_array_merge($aParams, $aCritParams); return array($sQuery, $aParams); }
/** * Finds folders that aren't reachable by the user but to which the * user has read permissions. * * Returns an array of Folder objects. */ function getBrowseableFolders($oUser) { $aPermissionDescriptors = KTPermissionUtil::getPermissionDescriptorsForUser($oUser); if (empty($aPermissionDescriptors)) { return array(); } $sPermissionDescriptors = DBUtil::paramArray($aPermissionDescriptors); $oPermission = KTPermission::getByName('ktcore.permissions.read'); $oPermission2 = KTPermission::getByName('ktcore.permissions.folder_details'); $aPermissionIds = array($oPermission->getId(), $oPermission->getId(), $oPermission2->getId(), $oPermission2->getId()); $sFoldersTable = KTUtil::getTableName('folders'); $sPLTable = KTUtil::getTableName('permission_lookups'); $sPLATable = KTUtil::getTableName('permission_lookup_assignments'); $sQuery = "SELECT DISTINCT F.id AS id FROM\n {$sFoldersTable} AS F\n LEFT JOIN {$sPLTable} AS PL ON F.permission_lookup_id = PL.id\n LEFT JOIN {$sPLATable} AS PLA ON PLA.permission_lookup_id = PL.id AND (PLA.permission_id = ? || PLA.permission_id = ?)\n\n LEFT JOIN {$sFoldersTable} AS F2 ON F.parent_id = F2.id\n LEFT JOIN {$sPLTable} AS PL2 ON F2.permission_lookup_id = PL2.id\n LEFT JOIN {$sPLATable} AS PLA2 ON PLA2.permission_lookup_id = PL2.id AND (PLA2.permission_id = ? || PLA.permission_id = ?)\n WHERE\n PLA.permission_descriptor_id IN ({$sPermissionDescriptors})\n AND F2.id <> 1\n AND NOT (PLA2.permission_descriptor_id IN ({$sPermissionDescriptors}))"; $aParams = kt_array_merge($aPermissionIds, $aPermissionDescriptors, $aPermissionDescriptors); $res = DBUtil::getResultArrayKey(array($sQuery, $aParams), 'id'); if (PEAR::isError($res)) { return $res; } $aFolders = array(); foreach ($res as $iFolderId) { $aFolders[] = Folder::get($iFolderId); } return $aFolders; }