Ejemplo n.º 1
0
 function do_getNewCriteria()
 {
     $criteriaType = KTUtil::arrayGet($_REQUEST, 'type');
     if (empty($criteriaType)) {
         return 'AJAX Error:  no criteria type specified.';
     }
     $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton();
     $critObj = $oCriteriaRegistry->getCriterion($criteriaType);
     if (PEAR::isError($critObj)) {
         return 'AJAX Error:  failed to initialise critiria of type "' . $type . '".';
     }
     // NBM:  there appears to be no reason to take $aRequest into searchWidget...
     $noRequest = array();
     return $critObj->searchWidget($noRequest);
 }
Ejemplo n.º 2
0
 function handleCriteriaSet($aCriteriaSet, $iStartIndex, $sTitle = null, $bIsCondition = false)
 {
     if ($sTitle == null) {
         $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Advanced Search'));
         $sTitle = _kt('Search Results');
     } else {
         if ($bIsCondition) {
             $this->aBreadcrumbs[] = array('name' => _kt('Test Condition'));
             $this->oPage->setTitle(sprintf(_kt('Test Condition: %s'), $sTitle));
         } else {
             $this->aBreadcrumbs[] = array('name' => _kt('Saved Search'));
             $this->oPage->setTitle(sprintf(_kt('Saved Search: %s'), $sTitle));
         }
         $this->oPage->setBreadcrumbDetails($sTitle);
     }
     $this->browseType = "Folder";
     $searchable_text = KTUtil::arrayGet($_REQUEST, "fSearchableText");
     $sSearch = md5(serialize($aCriteriaSet));
     $_SESSION['boolean_search'][$sSearch] = $aCriteriaSet;
     $collection = new AdvancedCollection();
     $oColumnRegistry = KTColumnRegistry::getSingleton();
     $aColumns = $oColumnRegistry->getColumnsForView('ktcore.views.search');
     $collection->addColumns($aColumns);
     // get search parameters
     $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton();
     $aParams = array();
     $aJoins = array();
     $aJoins['main'] = $aCriteriaSet['join'] == 'AND' ? _kt('all') : _kt('any');
     foreach ($aCriteriaSet['subgroup'] as $k => $subgroup) {
         $aGroup = array();
         $aJoins[$k] = $subgroup['join'] == 'AND' ? _kt('all') : _kt('any');
         if (!empty($subgroup['values'])) {
             foreach ($subgroup['values'] as $value) {
                 $oCriterion =& $oCriteriaRegistry->getCriterion($value['type']);
                 if ($oCriterion == null || $oCriterion == "" || PEAR::isError($oCriterion)) {
                     $this->errorRedirectToMain('Criterion error');
                 }
                 $aGroup[] = $oCriterion->parameterDisplay($value['data']);
             }
         }
         $aParams[] = $aGroup;
     }
     // set a view option
     $aTitleOptions = array('documenturl' => $GLOBALS['KTRootUrl'] . '/view.php');
     $collection->setColumnOptions('ktcore.columns.title', $aTitleOptions);
     $collection->setColumnOptions('ktcore.columns.selection', array('rangename' => 'selection', 'show_folders' => true, 'show_documents' => true));
     $aOptions = $collection->getEnvironOptions();
     // extract data from the environment
     $aOptions['return_url'] = KTUtil::addQueryStringSelf("action=performSearch&boolean_search_id=" . urlencode($sSearch));
     $aOptions['empty_message'] = _kt("No documents or folders match this query.");
     $aOptions['is_browse'] = true;
     $collection->setOptions($aOptions);
     $collection->setQueryObject(new BooleanSearchQuery($aCriteriaSet));
     //$a = new BooleanSearchQuery($aCriteriaSet);
     //var_dump($a->getDocumentCount()); exit(0);
     // form fields for saving the search
     $save_fields = array();
     $save_fields[] = new KTStringWidget(_kt('New search'), _kt('The name to save this search as'), 'name', null, $this->oPage, true);
     $aUserSearches = KTSavedSearch::getUserSearches($this->oUser->getId(), true);
     if (count($aUserSearches)) {
         $aVocab = array('' => ' ---- ');
         foreach ($aUserSearches as $oSearch) {
             $aVocab[$oSearch->getId()] = $oSearch->getName();
         }
         $aSelectOptions = array('vocab' => $aVocab);
         $save_fields[] = new KTLookupWidget(_kt('Existing search'), _kt('To save over one of your existing searches, select it here.'), 'fSearchId', null, $this->oPage, true, null, null, $aSelectOptions);
     }
     $oTemplating =& KTTemplating::getSingleton();
     $oTemplate = $oTemplating->loadTemplate("kt3/browse");
     $aTemplateData = array("context" => $this, "collection" => $collection, "custom_title" => $sTitle, "save_fields" => $save_fields, "params" => $aParams, "joins" => $aJoins, 'isEditable' => true, "boolean_search" => $sSearch, 'bulkactions' => KTBulkActionUtil::getAllBulkActions(), 'browseutil' => new KTBrowseUtil(), 'returnaction' => 'booleanSearch', 'returndata' => $sSearch);
     return $oTemplate->render($aTemplateData);
 }
Ejemplo n.º 3
0
 /**
  * All for folders only
  * Handles leaf criteria set (ie, no subgroups), generating SQL for
  * the values in the criteria.
  *
  * (This would be the place to extend criteria to support contains,
  * starts with, ends with, greater than, and so forth.)
  */
 function _oneCriteriaFolderSetToSQL($aOneCriteriaSet)
 {
     $aSQL = array();
     $aJoinSQL = array();
     $criteria_set = array();
     /*
      * First phase: get criterion object for search or the direct
      * SQL to use.
      *
      * XXX: Why is there $order there? 
      */
     foreach ($aOneCriteriaSet as $order => $dataset) {
         $type = KTUtil::arrayGet($dataset, "type");
         $sql = KTUtil::arrayGet($dataset, "sql");
         if (!empty($type)) {
             $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton();
             $oCriterion = $oCriteriaRegistry->getCriterion($dataset['type']);
             if (PEAR::isError($oCriterion)) {
                 return PEAR::raiseError(_kt('Invalid criteria specified.'));
             }
             $criteria_set[] = array($oCriterion, $dataset["data"]);
         } else {
             if (!empty($sql)) {
                 $criteria_set[] = $sql;
             } else {
                 return PEAR::raiseError(_kt('Invalid criteria specified.'));
             }
         }
     }
     /*
      * Second phase: Create an individual SQL query per criteria.
      */
     foreach ($criteria_set as $oCriterionPair) {
         $oCriterion->aLookup[table] = 'folder_field_links';
         $oCriterion = $oCriterionPair[0];
         $aReq = $oCriterionPair[1];
         if (is_object($oCriterion)) {
             // changed by dp start // for multiselect search for folders
             if (is_array($aReq[$oCriterion->sNamespace]) && KTPluginUtil::pluginIsActive('inet.multiselect.lookupvalue.plugin')) {
                 $aNewSQL = array();
                 foreach ($aReq[$oCriterion->sNamespace] as $kkey => $vval) {
                     $newAReq = $aReq;
                     $newAReq[$oCriterion->sNamespace] = $vval;
                     $res = $oCriterion->searchSQL($newAReq);
                     if (!is_null($res)) {
                         $aNewSQL[] = $res;
                     }
                 }
                 $aNewSQL0 = array();
                 $aNewSQL1 = array();
                 foreach ($aNewSQL as $ind => $sQ) {
                     $aNewSQL0[] = $sQ[0];
                     $aNewSQL1 = array_merge($aNewSQL1, $sQ[1]);
                 }
                 $aSQL[] = array(" ( " . join(" ) " . $aReq[$oCriterion->sNamespace . "_join"] . " ( ", $aNewSQL0) . " ) ", $aNewSQL1);
                 $res = $oCriterion->searchJoinSQL();
                 if (!is_null($res)) {
                     if (strstr($res, 'D.metadata_version_id')) {
                         $res = str_replace('D.metadata_version_id', 'F.metadata_version_id', $res);
                     }
                     if (strstr($res, 'document_fields_link')) {
                         $res = str_replace('document_fields_link', 'folder_fields_link', $res);
                     }
                     $aJoinSQL[] = $res;
                 }
             } else {
                 $res = $oCriterion->searchSQL($aReq);
                 if (!is_null($res)) {
                     $aSQL[] = $res;
                 }
                 $res = $oCriterion->searchJoinSQL();
                 if (!is_null($res)) {
                     if (strstr($res, 'D.metadata_version_id')) {
                         $res = str_replace('D.metadata_version_id', 'F.metadata_version_id', $res);
                     }
                     if (strstr($res, 'document_fields_link')) {
                         $res = str_replace('document_fields_link', 'folder_fields_link', $res);
                     }
                     $aJoinSQL[] = $res;
                 }
             }
         } else {
             $aSQL[] = array($oCriterion, $aReq);
         }
     }
     /*
      * Third phase: build up $aCritQueries and $aCritParams, and put
      * parentheses around them.
      */
     $aCritParams = array();
     $aCritQueries = array();
     foreach ($aSQL as $sSQL) {
         if (is_array($sSQL)) {
             $aCritQueries[] = '(' . $sSQL[0] . ')';
             $aCritParams = kt_array_merge($aCritParams, $sSQL[1]);
         } else {
             $aCritQueries[] = '(' . $sSQL . ')';
         }
     }
     if (count($aCritQueries) == 0) {
         return PEAR::raiseError(_kt("No search criteria were specified"));
     }
     return array($aCritQueries, $aCritParams, $aJoinSQL);
 }
Ejemplo n.º 4
0
 /**
  * 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);
     }
 }
Ejemplo n.º 5
0
 /**
  * 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;
         }
     }
 }
Ejemplo n.º 6
0
 function do_edit()
 {
     $id = KTUtil::arrayGet($_REQUEST, 'fSavedSearchId');
     $oSearch = KTSavedSearch::get($id);
     if (PEAR::isError($oSearch) || $oSearch == false) {
         $this->errorRedirectToMain('No Such search');
     }
     $aSearch = $oSearch->getSearch();
     /*
     	print '<pre>';
     	print_r($aSearch);
     	exit(0);
     */
     $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];
         if (is_array($aSubgroup['values'])) {
             foreach ($aSubgroup['values'] as $iv => $t) {
                 $datavars =& $aSubgroup['values'][$iv];
                 $oCriterion = $oCriteriaRegistry->getCriterion($datavars['type']);
                 $datavars['typename'] = $oCriterion->sDisplay;
                 $datavars['widgetval'] = $oCriterion->searchWidget(null, $datavars['data']);
             }
         }
     }
     //$s = '<pre>';
     //$s .= print_r($aSearch, true);
     //$s .= '</pre>';
     //print $s;
     $aTemplateData = array("title" => _kt("Edit an existing condition"), "aCriteria" => $aCriteria, "searchButton" => _kt("Update Saved Search"), 'aSearch' => $aSearch, 'context' => $this, 'iSearchId' => $oSearch->getId(), 'old_name' => $oSearch->getName(), 'sNameTitle' => _kt('Edit Search'));
     return $oTemplate->render($aTemplateData);
     //return $s;
 }
Ejemplo n.º 7
0
 /**
  * Handles leaf criteria set (ie, no subgroups), generating SQL for
  * the values in the criteria.
  *
  * (This would be the place to extend criteria to support contains,
  * starts with, ends with, greater than, and so forth.)
  */
 function _oneCriteriaSetToSQL($aOneCriteriaSet)
 {
     $aSQL = array();
     $aJoinSQL = array();
     $criteria_set = array();
     /*
      * First phase: get criterion object for search or the direct
      * SQL to use.
      *
      * XXX: Why is there $order there? 
      */
     foreach ($aOneCriteriaSet as $order => $dataset) {
         $type = KTUtil::arrayGet($dataset, "type");
         $sql = KTUtil::arrayGet($dataset, "sql");
         if (!empty($type)) {
             $oCriteriaRegistry =& KTCriteriaRegistry::getSingleton();
             $oCriterion = $oCriteriaRegistry->getCriterion($dataset['type']);
             if (PEAR::isError($oCriterion)) {
                 return PEAR::raiseError(_kt('Invalid criteria specified.'));
             }
             $criteria_set[] = array($oCriterion, $dataset["data"]);
         } else {
             if (!empty($sql)) {
                 $criteria_set[] = $sql;
             } else {
                 return PEAR::raiseError(_kt('Invalid criteria specified.'));
             }
         }
     }
     /*
      * Second phase: Create an individual SQL query per criteria.
      */
     foreach ($criteria_set as $oCriterionPair) {
         $oCriterion = $oCriterionPair[0];
         $aReq = $oCriterionPair[1];
         if (is_object($oCriterion)) {
             $res = $oCriterion->searchSQL($aReq);
             if (!is_null($res)) {
                 $aSQL[] = $res;
             }
             $res = $oCriterion->searchJoinSQL();
             if (!is_null($res)) {
                 $aJoinSQL[] = $res;
             }
         } else {
             $aSQL[] = array($oCriterion, $aReq);
         }
     }
     /*
      * Third phase: build up $aCritQueries and $aCritParams, and put
      * parentheses around them.
      */
     $aCritParams = array();
     $aCritQueries = array();
     foreach ($aSQL as $sSQL) {
         if (is_array($sSQL)) {
             $aCritQueries[] = '(' . $sSQL[0] . ')';
             $aCritParams = kt_array_merge($aCritParams, $sSQL[1]);
         } else {
             $aCritQueries[] = '(' . $sSQL . ')';
         }
     }
     if (count($aCritQueries) == 0) {
         return PEAR::raiseError(_kt("No search criteria were specified"));
     }
     return array($aCritQueries, $aCritParams, $aJoinSQL);
 }