Ejemplo n.º 1
0
 function getUrlForDocument($oDocument)
 {
     $iDocumentId = KTUtil::getId($oDocument);
     $sExt = '.php';
     if (KTUtil::arrayGet($_SERVER, 'kt_no_extensions')) {
         $sExt = '';
     }
     return sprintf('%s/view%s?fDocumentId=%d', $GLOBALS['KTRootUrl'], $sExt, $iDocumentId);
 }
Ejemplo n.º 2
0
 function do_managetree()
 {
     global $default;
     // extract.
     $iFieldsetId = KTUtil::getId($this->oFieldset);
     $iFieldId = KTUtil::getId($this->oField);
     $oFieldset =& $this->oFieldset;
     $oField =& $this->oField;
     $this->oPage->setBreadcrumbDetails(_kt('edit lookup tree'));
     $field_id = $iFieldId;
     $current_node = KTUtil::arrayGet($_REQUEST, 'current_node', 0);
     $subaction = KTUtil::arrayGet($_REQUEST, 'subaction');
     // validate
     if (empty($field_id)) {
         return $this->errorRedirectToMain(_kt("Must select a field to edit."));
     }
     $oField =& DocumentField::get($field_id);
     if (PEAR::isError($oField)) {
         return $this->errorRedirectToMain(_kt("Invalid field."));
     }
     $aErrorOptions = array('redirect_to' => array('editTree', sprintf('field_id=%d', $field_id)));
     // under here we do the subaction rendering.
     // we do this so we don't have to do _very_ strange things with multiple actions.
     //$default->log->debug("Subaction: " . $subaction);
     $fieldTree =& new MDTree();
     $fieldTree->buildForField($oField->getId());
     if ($subaction !== null) {
         $target = 'managetree';
         $msg = _kt('Changes saved.');
         if ($subaction === "addCategory") {
             $new_category = KTUtil::arrayGet($_REQUEST, 'category_name');
             if (empty($new_category)) {
                 return $this->errorRedirectTo("managetree", _kt("Must enter a name for the new category."), array("field_id" => $field_id, "fFieldsetId" => $iFieldsetId));
             } else {
                 $this->subact_addCategory($field_id, $current_node, $new_category, $fieldTree);
             }
             $msg = _kt('Category added') . ': ' . $new_category;
         }
         if ($subaction === "deleteCategory") {
             $this->subact_deleteCategory($fieldTree, $current_node);
             $current_node = 0;
             // clear out, and don't try and render the newly deleted category.
             $msg = _kt('Category removed.');
         }
         if ($subaction === "linkKeywords") {
             $keywords = KTUtil::arrayGet($_REQUEST, 'keywordsToAdd');
             $aErrorOptions['message'] = _kt("No keywords selected");
             $this->oValidator->notEmpty($keywords, $aErrorOptions);
             $this->subact_linkKeywords($fieldTree, $current_node, $keywords);
             $current_node = 0;
             // clear out, and don't try and render the newly deleted category.
             $msg = _kt('Keywords added to category.');
         }
         if ($subaction === "unlinkKeyword") {
             $keyword = KTUtil::arrayGet($_REQUEST, 'keyword_id');
             $this->subact_unlinkKeyword($fieldTree, $keyword);
             $msg = _kt('Keyword moved to base of tree.');
         }
         // now redirect
         $query = sprintf('field_id=%d&fFieldsetId=%d', $field_id, $iFieldsetId);
         return $this->successRedirectTo($target, $msg, $query);
     }
     if ($fieldTree->root === null) {
         return $this->errorRedirectToMain(_kt("Error building tree. Is this a valid tree-lookup field?"));
     }
     // FIXME extract this from MDTree (helper method?)
     $free_metadata = MetaData::getList('document_field_id = ' . $oField->getId() . ' AND (treeorg_parent = 0 OR treeorg_parent IS NULL) AND (disabled = 0)');
     // render edit template.
     $oTemplate = $this->oValidator->validateTemplate("ktcore/metadata/admin/edit_lookuptree");
     $renderedTree = $this->_evilTreeRenderer($fieldTree);
     $this->oPage->setTitle(_kt('Edit Lookup Tree'));
     if ($current_node == 0) {
         $category_name = 'Root';
     } else {
         $oNode = MDTreeNode::get($current_node);
         $category_name = $oNode->getName();
     }
     $aTemplateData = array("context" => $this, "args" => $this->meldPersistQuery("", "managetree", true), "field" => $oField, "oFieldset" => $oFieldset, "tree" => $fieldTree, "renderedTree" => $renderedTree, "currentNode" => $current_node, 'category_name' => $category_name, "freechildren" => $free_metadata);
     return $oTemplate->render($aTemplateData);
 }
Ejemplo n.º 3
0
 function nameExists($sName, $oWorkflow)
 {
     $iWorkflowId = KTUtil::getId($oWorkflow);
     $res = KTEntityUtil::getByDict('KTWorkflowState', array('name' => $sName, 'workflow_id' => $iWorkflowId));
     // expect KTEntityNoObjects
     if (PEAR::isError($res)) {
         return false;
     }
     return true;
 }
Ejemplo n.º 4
0
 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);
 }
 function &getByUser($oFolder, $aOptions = null)
 {
     $aOptions = KTUtil::meldOptions(array('multi' => true), $aOptions);
     $iFolderId = KTUtil::getId($oFolder);
     return KTEntityUtil::getByDict('KTFolderTransaction', array('folder_id' => $iFolderId), $aOptions);
 }
Ejemplo n.º 6
0
 function testConditionOnFolder($oSearch, $oFolder)
 {
     $oSearch =& KTUtil::getObject('KTSavedSearch', $oSearch);
     $iFolderId = KTUtil::getId($oFolder);
     /*
      * Make a new criteria set, an AND of the existing criteria set
      * and the sql statement requiring that D.id be the document id
      * given to us.
      */
     $aCriteriaSet = array("join" => "AND", "subgroup" => array($oSearch->getSearch(), array("join" => "AND", "values" => array(array("sql" => array("F.id = ?", array($iFolderId)))))));
     $aOptions = array('select' => 'COUNT(DISTINCT(F.id)) AS cnt');
     $aQuery = KTSearchUtil::criteriaToFolderQuery($aCriteriaSet, null, null, $aOptions);
     if (PEAR::isError($aQuery)) {
         // caused by no permissions being set.
         return false;
     }
     $cnt = DBUtil::getOneResultKey($aQuery, 'cnt');
     if (PEAR::isError($cnt)) {
         return $cnt;
     }
     if (is_null($cnt)) {
         return false;
     }
     if (!is_numeric($cnt)) {
         return PEAR::raiseError(_kt("Non-integer returned when looking for count"));
     }
     return $cnt > 0;
 }
 function &getByTransition($oTransition, $aOptions = null)
 {
     $iTransitionId = KTUtil::getId($oTransition);
     $aOptions = KTUtil::meldOptions($aOptions, array('multi' => true));
     return KTEntityUtil::getByDict('KTWorkflowTriggerInstance', array('workflow_transition_id' => $iTransitionId), $aOptions);
 }
Ejemplo n.º 8
0
 function getFieldsetsForType($iTypeId)
 {
     $typeid = KTUtil::getId($iTypeId);
     $aGenericFieldsetIds = KTFieldset::getGenericFieldsets(array('ids' => false));
     $aSpecificFieldsetIds = KTFieldset::getForDocumentType($typeid, array('ids' => false));
     $fieldsets = kt_array_merge($aGenericFieldsetIds, $aSpecificFieldsetIds);
     return $fieldsets;
 }
 function &getByDocument($oDocument)
 {
     $iDocumentId = KTUtil::getId($oDocument);
     return KTEntityUtil::getByDict('KTDocumentMetadataVersion', array('document_id' => $iDocumentId), array('multi' => true, 'orderby' => 'version_created DESC'));
 }
 function &getByState($oState)
 {
     $iStateId = KTUtil::getId($oState);
     return KTEntityUtil::GetList2('KTWorkflowStatePermissionAssignment', 'workflow_state_id = ' . $iStateId);
 }
 function generateStoragePathForVersion($oContentVersion)
 {
     $iId = KTUtil::getId($oContentVersion);
     $str = (string) $iId;
     if (strlen($str) < 4) {
         $str = sprintf('%s%s', str_repeat('0', 4 - strlen($str)), $str);
     }
     if (strlen($str) % 2 == 1) {
         $str = sprintf('0%s', $str);
     }
     $str = substr($str, 0, -2);
     $dir = preg_replace('#(\\d\\d)(\\d\\d)#', '\\1/\\2', $str);
     // Now, create the directory (including intermediaries)
     $oConfig =& KTConfig::getSingleton();
     $sDocumentRoot = $oConfig->get('urls/documentRoot');
     $path = "";
     foreach (split('/', $dir) as $sDirPart) {
         $path = sprintf('%s/%s', $path, $sDirPart);
         $createPath = sprintf('%s%s', $sDocumentRoot, $path);
         if (!file_exists($createPath)) {
             $res = @mkdir($createPath, 0777, true);
             if ($res === false) {
                 return PEAR::raiseError(_kt("Could not create directory for storage" . ': ' . $createPath));
             }
         }
     }
     return sprintf("%s/%d", $dir, $iId);
 }
Ejemplo n.º 12
0
 function &_add($oFolder, $sFilename, $oUser, $aOptions)
 {
     global $default;
     //$oContents = KTUtil::arrayGet($aOptions, 'contents');
     $aMetadata = KTUtil::arrayGet($aOptions, 'metadata', null, false);
     $oDocumentType = KTUtil::arrayGet($aOptions, 'documenttype');
     $sDescription = KTUtil::arrayGet($aOptions, 'description', '');
     if (empty($sDescription)) {
         // If no document name is provided use the filename minus the extension
         $aFile = pathinfo($sFilename);
         $sDescription = isset($aFile['filename']) && !empty($aFile['filename']) ? $aFile['filename'] : $sFilename;
     }
     $oUploadChannel =& KTUploadChannel::getSingleton();
     if ($oDocumentType) {
         $iDocumentTypeId = KTUtil::getId($oDocumentType);
     } else {
         $iDocumentTypeId = 1;
     }
     $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Creating database entry')));
     $oDocument =& Document::createFromArray(array('name' => $sDescription, 'description' => $sDescription, 'filename' => $sFilename, 'folderid' => $oFolder->getID(), 'creatorid' => $oUser->getID(), 'documenttypeid' => $iDocumentTypeId));
     $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Storing contents')));
     $res = KTDocumentUtil::storeContents($oDocument, '', $aOptions);
     if (PEAR::isError($res)) {
         if (!PEAR::isError($oDocument)) {
             $oDocument->delete();
         }
         return $res;
     }
     if (is_null($aMetadata)) {
         $res = KTDocumentUtil::setIncomplete($oDocument, 'metadata');
         if (PEAR::isError($res)) {
             $oDocument->delete();
             return $res;
         }
     } else {
         $oUploadChannel->sendMessage(new KTUploadGenericMessage(_kt('Saving metadata')));
         $res = KTDocumentUtil::saveMetadata($oDocument, $aMetadata, $aOptions);
         if (PEAR::isError($res)) {
             $oDocument->delete();
             return $res;
         }
     }
     // setIncomplete and storeContents may change the document's status or
     // storage_path, so now is the time to update
     $oDocument->update();
     return $oDocument;
 }
 function &getByDocument($oDocument, $aOptions = null)
 {
     $aOptions = KTUtil::meldOptions(array('multi' => true), $aOptions);
     $iDocumentId = KTUtil::getId($oDocument);
     return KTEntityUtil::getByDict('KTDocumentContentVersion', array('document_id' => $iDocumentId), $aOptions);
 }
Ejemplo n.º 14
0
 function do_assistance()
 {
     $sSubject = $this->oValidator->validateString($_REQUEST['subject']);
     $sDetails = $this->oValidator->validateString($_REQUEST['details']);
     $aUsers = array();
     $aGroups = array();
     $aRoles = array();
     foreach (Group::getAdministratorGroups() as $oGroup) {
         $aGroups[$oGroup->getId()] =& $oGroup;
     }
     foreach (Unit::getUnitsForFolder($this->oDocument->getFolderId()) as $oUnit) {
         foreach (Group::getUnitAdministratorGroupsByUnit($oUnit) as $oGroup) {
             $aGroups[$oGroup->getId()] =& $oGroup;
         }
     }
     $aRoles[-2] = Role::get(-2);
     $oDocument =& $this->oDocument;
     foreach ($aRoles as $oRole) {
         // Ignore anonymous or Everyone roles
         $iRoleId = KTUtil::getId($oRole);
         if ($iRoleId == -3 || $iRoleId == -4) {
             continue;
         }
         // first try on the document, then the folder above it.
         $oRoleAllocation = DocumentRoleAllocation::getAllocationsForDocumentAndRole($oDocument->getId(), $iRoleId);
         if (is_null($oRoleAllocation)) {
             // if we don't get a document role, try folder role.
             $oRoleAllocation = RoleAllocation::getAllocationsForFolderAndRole($oDocument->getFolderID(), $oRole->getId());
         }
         if (is_null($oRoleAllocation) || PEAR::isError($oRoleAllocation)) {
             continue;
         }
         $aRoleUsers = $oRoleAllocation->getUsers();
         $aRoleGroups = $oRoleAllocation->getGroups();
         foreach ($aRoleUsers as $id => $oU) {
             $aUsers[$id] = $oU;
         }
         foreach ($aRoleGroups as $id => $oGroup) {
             $aGroups[$id] = $oGroup;
         }
     }
     $aGroupMembershipSet = GroupUtil::buildGroupArray();
     $aAllIds = array_keys($aGroups);
     foreach ($aGroups as $id => $oGroup) {
         $aAllIds = kt_array_merge($aGroupMembershipSet[$id], $aAllIds);
     }
     foreach ($aAllIds as $id) {
         if (!array_key_exists($id, $aGroups)) {
             $aGroups[$id] = Group::get($id);
         }
     }
     // now, merge this (again) into the user-set.
     foreach ($aGroups as $oGroup) {
         $aNewUsers = $oGroup->getMembers();
         foreach ($aNewUsers as $oU) {
             $id = $oU->getId();
             if (!array_key_exists($id, $aUsers)) {
                 $aUsers[$id] = $oU;
             }
         }
     }
     foreach ($aUsers as $oU) {
         if (!PEAR::isError($oU)) {
             KTAssistNotification::newNotificationForDocument($this->oDocument, $oU, $this->oUser, $sSubject, $sDetails);
         }
     }
     $this->commitTransaction();
     $params = 'fDocumentId=' . $oDocument->getId();
     $url = generateControllerLink('viewDocument', $params);
     exit(redirect($url));
 }
Ejemplo n.º 15
0
 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();
 }
Ejemplo n.º 16
0
 function getLastLogins($aOptions = null)
 {
     $oUser = KTUtil::arrayGet($aOptions, 'user');
     if ($oUser) {
         $iUserId = KTUtil::getId($oUser);
     } else {
         $iUserId = null;
     }
     $aOptions = KTUtil::meldOptions(array('limit' => 5, 'orderby' => 'datetime DESC'), $aOptions);
     $sTable = KTUserHistory::_table();
     if ($iUserId) {
         return KTEntityUtil::getByDict($sTable, array('user_id' => $iUserId), $aOptions);
     } else {
         return KTEntityUtil::getList2('KTUserHistory', null, $aOptions);
     }
 }
Ejemplo n.º 17
0
 function _importfolder($oFolder, $sPath)
 {
     $oPermission = KTPermission::getByName('ktcore.permissions.addFolder');
     $aDocPaths = $this->oStorage->listDocuments($sPath);
     if (PEAR::isError($aDocPaths)) {
         return $aDocPaths;
     }
     $oDocObjects = array();
     foreach ($aDocPaths as $sDocumentPath) {
         $res = $this->_importdocument($oFolder, $sDocumentPath);
         if (PEAR::isError($res)) {
             return $res;
         }
         // Store document object
         $this->uploadedDocs[] = $res;
     }
     $aFolderPaths = $this->oStorage->listFolders($sPath);
     if (PEAR::isError($aFolderPaths)) {
         return $aFolderPaths;
     }
     $oFolderObjects = array();
     foreach ($aFolderPaths as $sFolderPath) {
         $sFolderBasePath = basename($sFolderPath);
         $sFolderBasePath = $this->is_utf8($sFolderBasePath) ? $sFolderBasePath : utf8_encode($sFolderBasePath);
         if (Folder::folderExistsName($sFolderPath, KTUtil::getId($oFolder))) {
             $_SESSION['KTErrorMessage'][] = sprintf(_kt("The folder %s is already present in %s.  Adding files into pre-existing folder."), $sFolderBasePath, $oFolder->getName());
             $aOptions = Folder::getList("parent_id = " . KTUtil::getId($oFolder) . ' AND name = "' . DBUtil::escapeSimple($sFolderBasePath) . '"');
             if (PEAR::isError($aOptions)) {
                 return $aOptions;
             }
             if (count($aOptions) != 1) {
                 return PEAR::raiseError(sprintf(_kt("Two folders named %s present in %s. Unable to decide which to use..."), $sFolderName, $oFolder->getName()));
             } else {
                 $oThisFolder = $aOptions[0];
             }
         } else {
             if (KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $oFolder)) {
                 $oThisFolder = KTFolderUtil::add($oFolder, $sFolderBasePath, $this->oUser, true);
             } else {
                 $oThisFolder = $oFolder;
                 if (!in_array('Your documents have been added to this folder and not the folder structure within the upload file because you do not have permission to add any folders.', $_SESSION['KTErrorMessage'])) {
                     $_SESSION['KTErrorMessage'][] = sprintf(_kt('Your documents have been added to this folder and not the folder structure within the upload file because you do not have permission to add any folders.'));
                 }
             }
         }
         if (PEAR::isError($oThisFolder)) {
             return $oThisFolder;
         }
         $res = $this->_importfolder($oThisFolder, $sFolderPath);
         if (PEAR::isError($res)) {
             return $res;
         }
         // Store folder object
         $this->uploadedFolders[] = $res;
     }
 }
Ejemplo n.º 18
0
 function clearGroupCacheForUser($oUser)
 {
     $oCache =& KTCache::getSingleton();
     if (PEAR::isError($oUser)) {
         return $oUser;
     }
     $group = "groupidsforuser";
     $iUserId = KTUtil::getId($oUser);
     $oCache->remove($group, $iUserId);
 }
Ejemplo n.º 19
0
 function &getByField($oField)
 {
     $iFieldId = KTUtil::getId($oField);
     $aOptions = array('multi' => true);
     return KTEntityUtil::getBy('KTFieldBehaviour', 'field_id', $iFieldId, $aOptions);
 }
Ejemplo n.º 20
0
 function do_addactiontrigger()
 {
     $oForm = $this->form_addtransitionaction();
     $res = $oForm->validate();
     $data = $res['results'];
     $errors = $res['errors'];
     if (!empty($errors)) {
         return $oForm->handleError();
     }
     $KTWFTriggerReg =& KTWorkflowTriggerRegistry::getSingleton();
     $this->startTransaction();
     $oTrigger = $KTWFTriggerReg->getWorkflowTrigger(KTUtil::arrayGet($data, 'action_name'));
     if (PEAR::isError($oTrigger)) {
         return $oForm->handleError(_kt('Unable to add trigger.'));
     }
     $oTriggerConfig = KTWorkflowTriggerInstance::createFromArray(array('transitionid' => KTUtil::getId($this->oTransition), 'namespace' => KTUtil::arrayGet($data, 'action_name'), 'config' => array()));
     if (PEAR::isError($oTriggerConfig)) {
         return $oForm->handleError(_kt('Unable to add trigger.') . $oTriggerConfig->getMessage());
     }
     // now, if the trigger is editable...
     $oTrigger->loadConfig($oTriggerConfig);
     if ($oTrigger->bIsConfigurable) {
         $this->successRedirectTo('editactiontrigger', _kt("New action added. This action requires configuration:  please specify this below."), array('fTriggerInstanceId' => $oTriggerConfig->getId()));
     } else {
         $this->successRedirectTo('managetransitionactions', _kt("New restriction added."));
     }
     exit(0);
 }
Ejemplo n.º 21
0
 /**
  * This function takes a list of metadata values and synchronises
  * those values into the values that already exist for the field by
  * adding new values and disabling values that aren't in the new
  * list.
  *
  * XXX: Scalability: This function 
  */
 function synchroniseMetadata($oField, $aNewMetadata)
 {
     $iFieldId = KTUtil::getId($oField);
     $aCurrentAllValues = Metadata::getValuesByDocumentField($iFieldId);
     $aCurrentEnabledValues = Metadata::getEnabledValuesByDocumentField($iFieldId);
     $aCurrentDisabledValues = Metadata::getDisabledValuesByDocumentField($iFieldId);
     $aToBeAddedValues = array_diff($aNewMetadata, $aCurrentAllValues);
     $aToBeDisabledValues = array_diff($aCurrentEnabledValues, $aNewMetadata);
     $aToBeEnabledValues = array_intersect($aCurrentDisabledValues, $aNewMetadata);
     foreach ($aToBeAddedValues as $sValue) {
         $oMetadata =& Metadata::createFromArray(array('name' => $sValue, 'docfieldid' => $iFieldId));
     }
     foreach ($aToBeDisabledValues as $sValue) {
         $oMetadata =& Metadata::getByValueAndDocumentField($sValue, $iFieldId);
         if (PEAR::isError($oMetadata)) {
             var_dump($aToBeDisabledValues);
             var_dump($sValue);
             var_dump($iFieldId);
             var_dump($oMetadata);
             exit(0);
         }
         if (!$oMetadata->getIsStuck()) {
             $oMetadata->updateFromArray(array('disabled' => true));
         }
     }
     foreach ($aToBeEnabledValues as $sValue) {
         $oMetadata =& Metadata::getByValueAndDocumentField($sValue, $iFieldId);
         if (!$oMetadata->getIsStuck()) {
             $oMetadata->updateFromArray(array('disabled' => false));
         }
     }
 }
 function hasRoles($aRoles)
 {
     if (!is_array($aRoles)) {
         return false;
     }
     $sTable = KTUtil::getTableName('permission_descriptor_roles');
     if (count($aRoles) === 0) {
         return false;
     }
     $aRoleIDs = array();
     foreach ($aRoles as $oRole) {
         $aRoleIDs[] = KTUtil::getId($oRole);
     }
     $sRoleIDs = DBUtil::paramArray($aRoleIDs);
     $sQuery = "SELECT COUNT(role_id) AS num FROM {$sTable}\n            WHERE descriptor_id = ? AND role_id IN ({$sRoleIDs})";
     $aParams = array($this->getID());
     $aParams = kt_array_merge($aParams, $aRoleIDs);
     $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'num');
     if (PEAR::isError($res)) {
         return $res;
     }
     if ((int) $res === 0) {
         return false;
     }
     return true;
 }
Ejemplo n.º 23
0
 function generateWorkflowTriggers()
 {
     require_once KT_LIB_DIR . '/workflow/workflowutil.inc.php';
     // get all the transitions, and add a trigger to the util with the appropriate settings.
     $KTWFTriggerReg =& KTWorkflowTriggerRegistry::getSingleton();
     $aTransitions = KTWorkflowTransition::getList();
     foreach ($aTransitions as $oTransition) {
         // guard perm
         $iGuardPerm = $oTransition->getGuardPermissionId();
         if (!is_null($iGuardPerm)) {
             $sNamespace = 'ktcore.workflowtriggers.permissionguard';
             $oPerm = KTPermission::get($iGuardPerm);
             $oTrigger = $KTWFTriggerReg->getWorkflowTrigger($sNamespace);
             $oTriggerConfig = KTWorkflowTriggerInstance::createFromArray(array('transitionid' => KTUtil::getId($oTransition), 'namespace' => $sNamespace, 'config' => array('perms' => array($oPerm->getName()))));
         }
         // guard group
         $iGuardGroup = $oTransition->getGuardGroupId();
         if (!is_null($iGuardGroup)) {
             $sNamespace = 'ktcore.workflowtriggers.groupguard';
             $oTrigger = $KTWFTriggerReg->getWorkflowTrigger($sNamespace);
             $oTriggerConfig = KTWorkflowTriggerInstance::createFromArray(array('transitionid' => KTUtil::getId($oTransition), 'namespace' => $sNamespace, 'config' => array('group_id' => $iGuardGroup)));
         }
         // guard role
         $iGuardRole = $oTransition->getGuardRoleId();
         if (!is_null($iGuardRole)) {
             $sNamespace = 'ktcore.workflowtriggers.roleguard';
             $oTrigger = $KTWFTriggerReg->getWorkflowTrigger($sNamespace);
             $oTriggerConfig = KTWorkflowTriggerInstance::createFromArray(array('transitionid' => KTUtil::getId($oTransition), 'namespace' => $sNamespace, 'config' => array('role_id' => $iGuardRole)));
         }
         // guard condition
         $iGuardCondition = $oTransition->getGuardConditionId();
         if (!is_null($iGuardCondition)) {
             $sNamespace = 'ktcore.workflowtriggers.conditionguard';
             $oTrigger = $KTWFTriggerReg->getWorkflowTrigger($sNamespace);
             $oTriggerConfig = KTWorkflowTriggerInstance::createFromArray(array('transitionid' => KTUtil::getId($oTransition), 'namespace' => $sNamespace, 'config' => array('condition_id' => $iGuardCondition)));
         }
     }
 }
 function deleteByCondition($oCondition)
 {
     $iConditionId = KTUtil::getId($oCondition);
     $sTable = KTUtil::getTableName('permission_dynamic_conditions');
     $sAssignmentsTable = KTUtil::getTableName('permission_dynamic_assignments');
     $aQuery = array(sprintf('SELECT id FROM %s WHERE condition_id = ?', $sTable), array($iConditionId));
     $aIds = DBUtil::getResultArrayKey($aQuery, 'id');
     $sParam = DBUtil::paramArray($aIds);
     $aAssignmentQuery = array(sprintf('DELETE FROM %s WHERE dynamic_condition_id IN (%s)', $sAssignmentsTable, $sParam), $aIds);
     DBUtil::runQuery($aAssignmentQuery);
     $aConditionQuery = array(sprintf('DELETE FROM %s WHERE id IN (%s)', $sTable, $sParam), $aIds);
     DBUtil::runQuery($aAssignmentQuery);
     return;
 }