diff --git a/lib/browse/Criteria.inc b/lib/browse/Criteria.inc index 01ffd68..23c9cbb 100644 --- a/lib/browse/Criteria.inc +++ b/lib/browse/Criteria.inc @@ -157,8 +157,16 @@ class BrowseCriterion { return "" . $this->headerDisplay() . ": " . $this->searchWidget($aRequest) . "\n"; } - function searchWidget ($aRequest) { - return "getWidgetBase() . "\" />"; + function searchWidget ($aRequest, $aPreValue = null) { + if ($aPreValue != null) { + // !#@&)*( (*&!@# *(&@!(*&!@# + $k = array_keys($aPreValue); + $k = $k[0]; + $preval = $aPreValue[$k]; + return "getWidgetBase() . "\" value=\"" . $preval . "\"/>"; + } else { + return "getWidgetBase() . "\" />"; + } } function getWidgetBase () { @@ -255,12 +263,21 @@ class CreatorCriterion extends BrowseCriterion { function folderDisplay($oFolder) { return $this->documentDisplay($oFolder); } - function searchWidget ($aRequest) { + function searchWidget ($aRequest, $aPreValue = null) { + $preval = null; + if ($aPreValue != null) { + // !#@&)*( (*&!@# *(&@!(*&!@# + $k = array_keys($aPreValue); + $k = $k[0]; + $preval = $aPreValue[$k]; + } $sRet = "\n"; return $sRet; @@ -274,15 +291,10 @@ class DateCreatedCriterion extends BrowseCriterion { function getName() { return "created"; } - function searchWidget ($aRequest) { + function searchWidget ($aRequest, $aPreValue = null) { global $default; - // this is not ideal, but we don't actually have access to the - // dispatcher's oPage object. - - // even worse, we may _not_ have the items we want. - - global $main; + // IMPORTANT: this requires the presence of kt3-calendar.js $sStartWidget = $this->getWidgetBase() . "_start"; $sEndWidget = $this->getWidgetBase() . "_end"; @@ -292,8 +304,8 @@ class DateCreatedCriterion extends BrowseCriterion { $sToRender .= "   Before date: "; $sToRender .= "  graphicsUrl/calendar/calendar.gif\" name=\"imgCalendar\" width=\"34\" height=\"21\" border=\"0\" alt=\"\">"; */ - $sToRender = 'After Date: No Date Selected — '; - $sToRender .= 'Before Date: No Date Selected
'; + $sToRender = 'After Date: ' . $aPreValue[$sStartWidget] . ' — '; + $sToRender .= 'Before Date: ' . $aPreValue[$sStartWidget] . '
'; return $sToRender; } function searchSQL ($aRequest) { @@ -338,12 +350,21 @@ class DocumentTypeCriterion extends BrowseCriterion { } return " "; } - function searchWidget ($aRequest) { + function searchWidget ($aRequest, $aPreValue = null) { + $preval = null; + if ($aPreValue != null) { + // !#@&)*( (*&!@# *(&@!(*&!@# + $k = array_keys($aPreValue); + $k = $k[0]; + $preval = $aPreValue[$k]; + } $sRet = "\n"; return $sRet; @@ -392,10 +413,17 @@ class GenericMetadataCriterion extends BrowseCriterion { return $this->aLookup['field']; } - function searchWidget ($aRequest) { + function searchWidget ($aRequest, $aPreValue = null) { + $preval = null; + if ($aPreValue != null) { + // !#@&)*( (*&!@# *(&@!(*&!@# + $k = array_keys($aPreValue); + $k = $k[0]; + $preval = $aPreValue[$k]; + } // If there's no lookup, just use the standard text input if ($this->oField->getHasLookup() == false) { - return parent::searchWidget($aRequest); + return parent::searchWidget($aRequest, $aPreValue); } $sRet = "\n"; return $sRet; @@ -498,13 +528,23 @@ class WorkflowStateCriterion extends BrowseCriterion { return "INNER JOIN $default->workflow_documents_table AS WD ON D.id = WD.document_id"; } - function searchWidget ($aRequest) { + function searchWidget ($aRequest, $aPreValue = null) { + $preval = null; + if ($aPreValue != null) { + // !#@&)*( (*&!@# *(&@!(*&!@# + $k = array_keys($aPreValue); + $k = $k[0]; + $preval = $aPreValue[$k]; + } + $sRet = "\n"; return $sRet; diff --git a/plugins/ktcore/KTCorePlugin.php b/plugins/ktcore/KTCorePlugin.php index 28f8c0e..f1672a8 100644 --- a/plugins/ktcore/KTCorePlugin.php +++ b/plugins/ktcore/KTCorePlugin.php @@ -120,7 +120,7 @@ class KTCorePlugin extends KTPlugin { $this->registerAdminPage("savedsearch", 'KTSavedSearchDispatcher', 'misc', _('Saved searches'), _('Manage saved searches - searches available by default to all users.'), - 'admin/manageHelp.php', null); + 'admin/savedSearch.php', null); // plugins $this->registerAdminPage("plugins", 'KTPluginDispatcher', 'plugins', diff --git a/plugins/ktcore/admin/savedSearch.php b/plugins/ktcore/admin/savedSearch.php index 1946d03..7ff6d8c 100755 --- a/plugins/ktcore/admin/savedSearch.php +++ b/plugins/ktcore/admin/savedSearch.php @@ -9,10 +9,16 @@ require_once(KT_LIB_DIR . "/search/savedsearch.inc.php"); class KTSavedSearchDispatcher extends KTStandardDispatcher { var $bAutomaticTransaction = true; + function check() { + $this->oPage->setTitle(_('Manage Saved Searches')); + return true; + } + function do_main() { $oTemplate =& $this->oValidator->validateTemplate('ktcore/search/administration/savedsearches'); $oTemplate->setData(array( 'saved_searches' => KTSavedSearch::getList(), + 'context' => $this, )); return $oTemplate->render(); } @@ -27,6 +33,8 @@ class KTSavedSearchDispatcher extends KTStandardDispatcher { "title" => _("Create a new condition"), "aCriteria" => $aCriteria, "searchButton" => _("Save"), + 'context' => $this, + "sNameTitle" => _('New Stored Search'), ); return $oTemplate->render($aTemplateData); } @@ -34,10 +42,92 @@ class KTSavedSearchDispatcher extends KTStandardDispatcher { 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 search'); + } + + $aSearch = $oSearch->getSearch(); + + + $oTemplating = new KTTemplating; + $oTemplate = $oTemplating->loadTemplate("ktcore/boolean_search_edit"); + + $aCriteria = Criteria::getAllCriteria(); + + // we need to help out here, since it gets unpleasant inside the template. + foreach ($aSearch['subgroup'] as $isg => $as) { + $aSubgroup =& $aSearch['subgroup'][$isg]; + foreach ($aSubgroup['values'] as $iv => $t) { + $datavars =& $aSubgroup['values'][$iv]; + $datavars['typename'] = $aCriteria[$datavars['type']]->sDisplay; + $datavars['widgetval'] = $aCriteria[$datavars['type']]->searchWidget(null, $datavars['data']); + } + } + + //$s = '
';
+        //$s .= print_r($aSearch, true);
+        //$s .= '
'; + //print $s; + + $aTemplateData = array( + "title" => _("Edit an existing condition"), + "aCriteria" => $aCriteria, + "searchButton" => _("Update Saved Search"), + 'aSearch' => $aSearch, + 'context' => $this, + 'iSearchId' => $oSearch->getId(), + 'old_name' => $oSearch->getName(), + 'sNameTitle' => _('Edit Search'), + ); + return $oTemplate->render($aTemplateData); + + //return $s; + } + + // 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 search'); + } + + + $datavars = KTUtil::arrayGet($_REQUEST, 'boolean_search'); + if (!is_array($datavars)) { + $datavars = unserialize($datavars); + } + + if (empty($datavars)) { + $this->errorRedirectToMain(_('You need to have at least 1 condition.')); + } + + //$sName = "Neil's saved search"; + if (!empty($sName)) { + $oSearch->setName($sName); + } + + $oSearch->setSearch($datavars); + $res = $oSearch->update(); + + $this->oValidator->notError($res, array( + 'redirect_to' => 'main', + 'message' => _('Search not saved'), + )); + $this->successRedirectToMain(_('Search saved')); + } // XXX: Rename to do_save function do_performSearch() { $datavars = KTUtil::arrayGet($_REQUEST, 'boolean_search'); + $sName = KTUtil::arrayGet($_REQUEST, 'name'); if (!is_array($datavars)) { $datavars = unserialize($datavars); } @@ -46,7 +136,6 @@ class KTSavedSearchDispatcher extends KTStandardDispatcher { $this->errorRedirectToMain(_('You need to have at least 1 condition.')); } - $sName = "Neil's saved search"; $sNamespace = KTUtil::nameToLocalNamespace('Saved searches', $sName); $oSearch = KTSavedSearch::createFromArray(array( @@ -66,7 +155,7 @@ class KTSavedSearchDispatcher extends KTStandardDispatcher { } } -$oDispatcher = new KTSavedSearchDispatcher(); -$oDispatcher->dispatch(); +//$oDispatcher = new KTSavedSearchDispatcher(); +//$oDispatcher->dispatch(); ?> diff --git a/resources/js/constructed_search_postprocess.js b/resources/js/constructed_search_postprocess.js new file mode 100644 index 0000000..831ad51 --- /dev/null +++ b/resources/js/constructed_search_postprocess.js @@ -0,0 +1,62 @@ +/* Constructed Search Postprocessing. + * + * In order to make everything as seamless as possible, we do a + * JS based postprocess on the boolean_search pages. + * + * This needs to do two things: + * - adjust all the input.name elements. + * - push the autoIncrement vars so we don't have modification conflicts. + */ + + +// expects a table row in canonical format, ready for var-modification. +function processRow(tablerow, parent_table) { + var inputs = tablerow.getElementsByTagName('INPUT'); + + // unfortunate note: if we have > 1 items, we are dealing with a "real" row. + // (1 since select != input, and . + // (not == 2 since we can have arbitrary other items... + + if (inputs.length > 1) { // is a "predefined" row. + autoIndexCriteria.push(0); + var crit_id = autoIndexCriteria.length; + var table_id = getBooleanGroupId(parent_table); + + // we also need "SELECT" items. + + var selects = tablerow.getElementsByTagName('SELECT'); + + if (inputs[0].name != '') { + alert('invalid output.'); + return null; + } else { + inputs[0].name = 'boolean_search[subgroup]['+table_id+'][values]['+crit_id+'][type]'; + } + + // different from constructed_search: remove the _initial_ INPUT type="hidden, and the button. + for (var i=1; ioPage->requireJSResource("thirdpartyjs/MochiKit/Base.js")} +{$context->oPage->requireJSResource("thirdpartyjs/MochiKit/DateTime.js")} +{$context->oPage->requireJSResource("thirdpartyjs/MochiKit/Iter.js")} +{$context->oPage->requireJSResource("thirdpartyjs/MochiKit/DOM.js")} +{$context->oPage->requireJSResource("thirdpartyjs/MochiKit/Async.js")} +{$context->oPage->requireJSResource("resources/js/taillog.js")} +{$context->oPage->requireJSResource("resources/js/constructed_search.js")} +{$context->oPage->requireJSResource("resources/js/constructed_search_postprocess.js")} + +{$context->oPage->requireJSResource("resources/js/kt3calendar.js")} +{$context->oPage->requireJSResource("thirdpartyjs/jscalendar-1.0/calendar.js")} +{$context->oPage->requireJSResource("thirdpartyjs/jscalendar-1.0/lang/calendar-en.js")} +{$context->oPage->requireJSResource("thirdpartyjs/jscalendar-1.0/calendar-setup.js")} + +{$context->oPage->requireCSSResource("thirdpartyjs/jscalendar-1.0/calendar-system.css")} + +{capture assign=sJS} +{literal} +function testStartup() { + simpleLog('INFO','Log initialised.'); +} + +addLoadEvent(testStartup); +{/literal} +{/capture} +{$context->oPage->requireJSStandalone($sJS)} + +{capture assign=sCSS} +{literal} +fieldset { border: 1px dotted #999; } +legend { border: 1px dotted #999;} + +.helpText { color: #666; } + +/* logging support */ +#brad-log thead th { border-bottom: 1px solid black; } +#brad-log {font-size: smaller; } +#brad-log .severity-INFO { color: blue; font-weight: bold; } +#brad-log .severity-DEBUG { color: green; font-weight: bold; } +#brad-log .severity-ERROR { color: red; font-weight: bold; } +#brad-log .explanation { font-family: monospace; white-space: pre; } +{/literal} +{/capture} +{$context->oPage->requireCSSStandalone($sCSS)} + + + + +{capture assign=defaulttitle} +{i18n}Boolean Search{/i18n} +{/capture} +

{$title|default:$defaulttitle}

+ +
+ + +{if $sNameTitle} + {$sNameTitle}:
+{/if} + +{capture assign=options} + +{/capture} + +

{i18n arg_options=$options}Return items which match  #options# of the criteria groups specified.{/i18n}

+ + {foreach item=aSubgroup from=$aSearch.subgroup} + +
+ {i18n}Criteria Group{/i18n} + + {capture assign=options} + + {/capture} + +

{i18n arg_options=$options}Return items which match  #options# of the criteria specified.{/i18n}

+ + + + + + + + + + + + + {foreach item=oSearchCriteria from=$aSubgroup.values} + + + + + + {/foreach} + + + + + + + +
{i18n}Criteria{/i18n}{i18n}Values{/i18n} 
+ {$oSearchCriteria.typename} + + {$oSearchCriteria.widgetval} + + +
+

{i18n}first select a type of query{/i18n}

+ +
+ + {/foreach} + +
+ + + + +{capture assign=defaultsubmit} +{i18n}Search{/i18n} +{/capture} + +
+
+ + +