[svn r17968] search widget prefilter: avoid hardcode specific field prefix

- added admin configuration catergory Search
  - change search_show_unlinked_results variable to this category
  - added search_prefilter_prefix variable to choose which specific field use to build the prefilter type on search widget
    - also initialize search_prefilter_prefix on db
- also some minor changes
  - fix search button background image
  - use T prefix for new specific fields, since there is no more XAPIAN_PREFIX_TAG
skala
Marco Villegas 16 years ago
parent 0589a0ac18
commit 0204d33334
  1. 80
      main/admin/settings.php
  2. 2
      main/inc/lib/search/search_widget.css
  3. 2
      main/inc/lib/search/search_widget.php
  4. 4
      main/inc/lib/specific_fields_manager.lib.php
  5. 3
      main/install/dokeos_main_corp.sql

@ -1,4 +1,4 @@
<?php // $Id: settings.php 17865 2009-01-20 16:33:17Z juliomontoya $
<?php // $Id: settings.php 17968 2009-01-23 17:13:50Z marvil07 $
/*
==============================================================================
Dokeos - elearning and course management software
@ -75,7 +75,7 @@ $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAd
$tool_name = get_lang('DokeosConfigSettings');
// Build the form
if (!empty($_GET['category']) and $_GET['category'] <> "Plugins" and $_GET['category'] <> "stylesheets" )
if (!empty($_GET['category']) and !in_array($_GET['category'], array('Plugins', 'stylesheets', 'Search')))
{
$form = new FormValidator('settings', 'post', 'settings.php?category='.$_GET['category']);
$renderer = & $form->defaultRenderer();
@ -291,12 +291,13 @@ $action_images['tuning'] = 'tuning.gif';
$action_images['plugins'] = 'plugin.gif';
$action_images['stylesheets'] = 'theme.gif';
$action_images['templates'] = 'template.gif';
$action_images['search'] = 'search.gif';
// grabbing the categories
//$selectcategories = "SELECT DISTINCT category FROM ".$table_settings_current." WHERE category NOT IN ('stylesheets','Plugins')";
//$resultcategories = api_sql_query($selectcategories, __FILE__, __LINE__);
$resultcategories = api_get_settings_categories(array('stylesheets','Plugins', 'Templates'));
$resultcategories = api_get_settings_categories(array('stylesheets','Plugins', 'Templates', 'Search'));
echo "\n<div class=\"actions\">";
//while ($row = mysql_fetch_array($resultcategories))
foreach($resultcategories as $row)
@ -306,6 +307,7 @@ foreach($resultcategories as $row)
echo "\n\t<a href=\"".api_get_self()."?category=Plugins\">".Display::return_icon($action_images['plugins'], ucfirst(get_lang('Plugins'))).ucfirst(get_lang('Plugins'))."</a>";
echo "\n\t<a href=\"".api_get_self()."?category=stylesheets\">".Display::return_icon($action_images['stylesheets'], ucfirst(get_lang('Stylesheets'))).ucfirst(get_lang('Stylesheets'))."</a>";
echo "\n\t<a href=\"".api_get_self()."?category=Templates\">".Display::return_icon($action_images['templates'], ucfirst(get_lang('Templates'))).ucfirst(get_lang('Templates'))."</a>";
echo "\n\t<a href=\"".api_get_self()."?category=Search\">".Display::return_icon($action_images['search'], ucfirst(get_lang('Search'))).ucfirst(get_lang('Search'))."</a>";
echo "\n</div>";
if (isset ($_GET['category']))
@ -321,6 +323,9 @@ if (isset ($_GET['category']))
case 'stylesheets' :
handle_stylesheets();
break;
case 'Search' :
handle_search();
break;
default :
$form->display();
}
@ -757,4 +762,73 @@ function is_style($style)
}
return false;
}
/**
* Search options
* TODO: support for multiple site. aka $_configuration['access_url'] == 1
* @author Marco Villegas <marvil07@gmail.com>
*/
function handle_search() {
global $SettingsStored, $_configuration;
$search_enabled = api_get_setting('search_enabled');
$settings = api_get_settings('Search');
if ($search_enabled !== 'true' || count($settings) < 1) {
Display::display_error_message(get_lang('SearchFeatureNotEnabledComment'));
return;
}
require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';
$form = new FormValidator('search-options', 'post', api_get_self().'?category=Search');
$renderer = & $form->defaultRenderer();
$renderer->setHeaderTemplate('<div class="sectiontitle">{header}</div>'."\n");
$renderer->setElementTemplate('<div class="sectioncomment">{label}</div>'."\n".'<div class="sectionvalue">{element}</div>'."\n");
//search_show_unlinked_results
$form->addElement('header', null, get_lang('SearchShowUnlinkedResultsTitle'));
$form->addElement('label', null, get_lang('SearchShowUnlinkedResultsComment'));
$values = get_settings_options('search_show_unlinked_results');
$group = array ();
foreach ($values as $key => $value) {
$element = & $form->createElement('radio', 'search_show_unlinked_results', '', get_lang($value['display_text']), $value['value']);
$group[] = $element;
}
$form->addGroup($group, 'search_show_unlinked_results', get_lang('SearchShowUnlinkedResultsComment'), '<br />', false);
$default_values['search_show_unlinked_results'] = api_get_setting('search_show_unlinked_results');
//search_prefilter_prefix
$form->addElement('header', null, get_lang('SearchPrefilterPrefix'));
$form->addElement('label', null, get_lang('SearchPrefilterPrefixComment'));
$specific_fields = get_specific_field_list();
$sf_values = array();
foreach ($specific_fields as $sf) {
$sf_values[$sf['code']] = $sf['name'];
}
$group = array ();
$form->addElement('select', 'search_prefilter_prefix', get_lang('SearchPrefilterPrefix'), $sf_values, '');
$default_values['search_prefilter_prefix'] = api_get_setting('search_prefilter_prefix');
//$form->addRule('search_show_unlinked_results', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('submit', 'search-options-save', get_lang('Ok'));
$form->setDefaults($default_values);
if( $form->validate()) {
$formvalues = $form->exportValues();
$r = api_set_settings_category('Search','false',$_configuration['access_url']);
// Save the settings
foreach ($formvalues as $key => $value)
{
$result = api_set_setting($key,$value,null,null);
}
Display :: display_normal_message($SettingsStored);
} else {
echo '<div id="search-options-form">';
$form->display();
echo '</div>';
}
}
?>

@ -13,7 +13,7 @@
font-size: 130%;
}
#submit {
background-image: url(\'../img/search-lense.gif\');
background-image: url('/main/img/search-lense.gif');
background-repeat: no-repeat;
background-position: 0px -1px;
padding-left:18px;

@ -251,7 +251,7 @@ function display_search_form($action, $show_thesaurus, $sf_terms, $op) {
$type = (!empty($_REQUEST['type'])? htmlentities($_REQUEST['type']): 'normal');
switch ($type) {
case 'prefilter':
$prefilter_prefix = 'E'; //TODO: should be api_get_setting('search_prefilter_prefix')
$prefilter_prefix = api_get_setting('search_prefilter_prefix');
$form = search_widget_prefilter_form($action, $show_thesaurus, $sf_terms, $op, $prefilter_prefix);
break;
case 'normal':

@ -201,7 +201,9 @@ function delete_all_values_for_item($course_id, $tool_id, $ref_id) {
* @return string One-letter code, upper-case
*/
function get_specific_field_code_from_name($name) {
$list = array('A','B','D','E','F','G','H','I','J','K','L','M','N','P','Q','R','S','U','V','W','X','Y'); //Z is used internally by Xapian and we already use C,T & O for tool_id, course_id and normal tags
// Z is used internally by Xapian
// O & C already used by tool_id and course_id
$list = array('A','B','D','E','F','G','H','I','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y');
$table_sf = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD);
$sql = "SELECT code FROM $table_sf ORDER BY code";
$res = api_sql_query($sql,__FILE__,__LINE__);

@ -2,7 +2,8 @@ INSERT INTO settings_current
(variable, subkey, type, category, selected_value, title, comment, scope, subkeytext)
VALUES
('search_enabled',NULL,'radio','Tools','false','EnableSearchTitle','EnableSearchComment',NULL,NULL),
('search_show_unlinked_results',NULL,'radio','Tools','true','SearchShowUnlinkedResultsTitle','SearchShowUnlinkedResultsComment',NULL,NULL);
('search_prefilter_prefix',NULL, NULL,'Search','','SearchPrefilterPrefix','SearchPrefilterPrefixComment',NULL,NULL),
('search_show_unlinked_results',NULL,'radio','Search','true','SearchShowUnlinkedResultsTitle','SearchShowUnlinkedResultsComment',NULL,NULL);
INSERT INTO settings_options
(variable, value, display_text)

Loading…
Cancel
Save