diff --git a/lib/permissions/permissiondynamiccondition.inc.php b/lib/permissions/permissiondynamiccondition.inc.php index 0329612..a26be4c 100644 --- a/lib/permissions/permissiondynamiccondition.inc.php +++ b/lib/permissions/permissiondynamiccondition.inc.php @@ -80,6 +80,12 @@ class KTPermissionDynamicCondition extends KTEntity { return KTEntityUtil::getList2('KTPermissionDynamicCondition', $sWhereClause); } + function getPermissionObjectIdList($sWhereClause, $aParams) { + $query = 'SELECT DISTINCT(permission_object_id) FROM permission_dynamic_conditions WHERE '.$sWhereClause; + $aQuery = array($query, $aParams); + return DBUtil::getResultArray($aQuery); + } + function &getByPermissionObject($oPermissionObject) { $iPermissionObjectId = KTUtil::getId($oPermissionObject); return KTEntityUtil::getByDict('KTPermissionDynamicCondition', array( diff --git a/plugins/ktcore/admin/conditions.php b/plugins/ktcore/admin/conditions.php index 44d4d7d..39418c2 100755 --- a/plugins/ktcore/admin/conditions.php +++ b/plugins/ktcore/admin/conditions.php @@ -5,32 +5,32 @@ * KnowledgeTree Open Source Edition * Document Management Made Simple * Copyright (C) 2004 - 2008 The Jam Warehouse Software (Pty) Limited - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, * Blake Street, Observatory, 7925 South Africa. 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 + * 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. + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. * Contributor( s): ______________________________________ * */ @@ -39,6 +39,7 @@ require_once(KT_LIB_DIR . "/templating/templating.inc.php"); require_once(KT_LIB_DIR . "/dispatcher.inc.php"); require_once(KT_LIB_DIR . "/browse/Criteria.inc"); require_once(KT_LIB_DIR . "/search/savedsearch.inc.php"); +require_once(KT_LIB_DIR .'/permissions/permissiondynamiccondition.inc.php'); class KTConditionDispatcher extends KTAdminDispatcher { var $bAutomaticTransaction = true; @@ -72,6 +73,12 @@ class KTConditionDispatcher extends KTAdminDispatcher { function do_delete_confirmed() { $id = KTUtil::arrayGet($_REQUEST, 'fSavedSearchId'); + + // Get associated permission objects before deleting the condition + $sWhere = 'condition_id = ?'; + $aParams = array($id); + $aPermissionObjects = KTPermissionDynamicCondition::getPermissionObjectIdList($sWhere, $aParams); + $oSearch = KTSavedSearch::get($id); KTPermissionDynamicCondition::deleteByCondition($oSearch); $res = $oSearch->delete(); @@ -79,19 +86,29 @@ class KTConditionDispatcher extends KTAdminDispatcher { 'redirect_to' => 'main', 'message' => _kt('Search not deleted'), )); + + // Update permission objects if they exist + if(!PEAR::isError($aPermissionObjects) && !empty($aPermissionObjects)){ + // update permission objects + foreach($aPermissionObjects as $iPermObjectId){ + $oPO = KTPermissionObject::get($iPermObjectId['permission_object_id']); + KTPermissionUtil::updatePermissionLookupForPO($oPO); + } + } + $this->successRedirectToMain(_kt('Dynamic condition deleted')); } function do_new() { $this->oPage->setBreadcrumbDetails(_kt('Create a new condition')); $this->oPage->setTitle(_kt('Create a new condition')); - + $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate("ktcore/boolean_search"); - + $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton(); $aCriteria =& $oCriteriaRegistry->getCriteria(); - + $aTemplateData = array( "title" => _kt("Create a new condition"), "sNameTitle" => _kt("Name of condition"), @@ -105,24 +122,24 @@ class KTConditionDispatcher extends KTAdminDispatcher { function do_view() { } - + function do_edit() { $id = KTUtil::arrayGet($_REQUEST, 'fSavedSearchId'); $oSearch = KTSavedSearch::get($id); - + if (PEAR::isError($oSearch) || ($oSearch == false)) { $this->errorRedirectToMain('No such dynamic condition'); } - + $aSearch = $oSearch->getSearch(); - - + + $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate("ktcore/boolean_search_edit"); - + $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton(); $aCriteria =& $oCriteriaRegistry->getCriteria(); - + // we need to help out here, since it gets unpleasant inside the template. foreach ($aSearch['subgroup'] as $isg => $as) { $aSubgroup =& $aSearch['subgroup'][$isg]; @@ -139,8 +156,8 @@ class KTConditionDispatcher extends KTAdminDispatcher { } } } - - + + $aTemplateData = array( "title" => _kt("Edit an existing condition"), "aCriteria" => $aCriteria, @@ -151,26 +168,26 @@ class KTConditionDispatcher extends KTAdminDispatcher { 'old_name' => $oSearch->getName(), 'sNameTitle' => _kt('Edit Dynamic Condition'), ); - return $oTemplate->render($aTemplateData); + return $oTemplate->render($aTemplateData); } - + // XXX: Rename to do_save function do_updateSearch() { $id = KTUtil::arrayGet($_REQUEST, 'fSavedSearchId'); $sName = KTUtil::arrayGet($_REQUEST, 'name'); $oSearch = KTSavedSearch::get($id); - + if (PEAR::isError($oSearch) || ($oSearch == false)) { $this->errorRedirectToMain('No such dynamic condition'); } - - + + $datavars = KTUtil::arrayGet($_REQUEST, 'boolean_search'); if (!is_array($datavars)) { $datavars = unserialize($datavars); } - + if (empty($datavars)) { $this->errorRedirectToMain(_kt('You need to have at least 1 condition.')); } @@ -179,16 +196,30 @@ class KTConditionDispatcher extends KTAdminDispatcher { if (!empty($sName)) { $oSearch->setName($sName); } - + $oSearch->setSearch($datavars); $res = $oSearch->update(); - + $this->oValidator->notError($res, array( 'redirect_to' => 'main', 'message' => _kt('Search not saved'), )); + + // Update permission object if exists + $sWhere = 'condition_id = ?'; + $aParams = array($id); + $aPermissionObjects = KTPermissionDynamicCondition::getPermissionObjectIdList($sWhere, $aParams); + + if(!PEAR::isError($aPermissionObjects) && !empty($aPermissionObjects)){ + // update permission objects + foreach($aPermissionObjects as $iPermObjectId){ + $oPO = KTPermissionObject::get($iPermObjectId['permission_object_id']); + KTPermissionUtil::updatePermissionLookupForPO($oPO); + } + } + $this->successRedirectToMain(_kt('Dynamic condition saved')); - } + } // XXX: Rename to do_save function do_performSearch() { @@ -196,17 +227,17 @@ class KTConditionDispatcher extends KTAdminDispatcher { if (!is_array($datavars)) { $datavars = unserialize($datavars); } - + if (empty($datavars)) { $this->errorRedirectToMain(_kt('You need to have at least 1 condition.')); } $sName = $this->oValidator->validateEntityName( - 'KTSavedSearch', - KTUtil::arrayGet($_REQUEST, 'name'), + 'KTSavedSearch', + KTUtil::arrayGet($_REQUEST, 'name'), array('extra_condition' => 'is_condition', 'redirect_to' => array('new')) ); - + $sNamespace = KTUtil::nameToLocalNamespace('Saved searches', $sName); $oSearch = KTSavedSearch::createFromArray(array(