Fixing warning php messages, adding cidreset, adding comments, updating documentation for the Search funcionality

skala
Julio Montoya 14 years ago
parent 53713f47bb
commit 0951d23247
  1. 6
      main/admin/index.php
  2. 85
      main/admin/settings.lib.php
  3. 11
      main/admin/settings.php
  4. 4
      main/admin/specific_fields.php
  5. 10
      main/admin/specific_fields_add.php
  6. 14
      main/inc/lib/search/xapian/XapianQuery.php
  7. 27
      main/inc/lib/specific_fields_manager.lib.php
  8. 2
      main/link/link.php
  9. 15
      main/newscorm/learnpath.class.php
  10. 15
      main/newscorm/lp_list_search.php
  11. 37
      main/search/INSTALL
  12. 20
      main/search/index.php
  13. 2
      searchdb/readme.txt

@ -64,8 +64,7 @@ if (api_is_platform_admin()) {
<button class="search" type="submit"> <?php echo get_lang('Search'); ?></button>
</form>
</div>
<ul>
<!-- <li><a href="user_list.php?search=advanced"><?php echo api_ucfirst(get_lang('AdvancedSearch')); ?></a></li> -->
<ul>
<li><a href="user_list.php"><?php echo get_lang('UserList'); ?></a></li>
<li><a href="user_add.php"><?php echo get_lang('AddUsers'); ?></a></li>
<li><a href="user_export.php"><?php echo get_lang('ExportUserListXMLCSV'); ?></a></li>
@ -179,8 +178,7 @@ if (api_get_setting('use_session_mode') == 'true') { ?>
<button class="search" type="submit"><?php echo get_lang('Search'); ?></button>
</form>
</div>
<ul>
<!-- <li><a href="session_list.php?search=advanced"><?php echo api_ucfirst(get_lang('AdvancedSearch')); ?></a></li> -->
<ul>
<li><a href="session_list.php"><?php echo get_lang('ListSession'); ?></a></li>
<li><a href="session_category_list.php"><?php echo get_lang('ListSessionCategory'); ?></a></li>
<li><a href="session_add.php"><?php echo get_lang('AddSession'); ?></a></li>

@ -502,63 +502,82 @@ function is_style($style) {
function handle_search() {
global $SettingsStored, $_configuration;
require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
$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');
$values = get_settings_options('search_enabled');
$form->addElement('header', null, get_lang('SearchEnabledTitle'));
$group = array ();
foreach ($values as $key => $value) {
$element = & $form->createElement('radio', 'search_show_unlinked_results', '', get_lang($value['display_text']), $value['value']);
$group[] = $element;
if (is_array($values)) {
foreach ($values as $key => $value) {
$element = & $form->createElement('radio', 'search_enabled', '', get_lang($value['display_text']), $value['value']);
if ($hide_element) {
$element->freeze();
}
$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'];
$form->addGroup($group, 'search_enabled', get_lang('SearchEnabledComment'), '<br />', false);
$default_values['search_enabled'] = $search_enabled;
$search_enabled = api_get_setting('search_enabled');
if ($search_enabled == 'true') {
// 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');
}
$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('style_submit_button', 'search-options-save', get_lang('Ok'));
$form->addElement('style_submit_button', 'submit', get_lang('Save'),'class="save"');
$form->setDefaults($default_values);
if ($form->validate()) {
$formvalues = $form->exportValues();
var_dump($formvalues);
$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_confirmation_message($SettingsStored);
Display::display_confirmation_message($SettingsStored);
} else {
echo '<div id="search-options-form">';
$form->display();
echo '</div>';
}
}
/**

@ -147,7 +147,7 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', '
$default_values = array();
foreach ($settings as $row) {
// Settings to avoid
$rows_to_avoid = array('search_enabled', 'gradebook_enable');
$rows_to_avoid = array('gradebook_enable');
if (in_array($row['variable'], $rows_to_avoid)) { continue; }
$anchor_name = $row['variable'].(!empty($row['subkey']) ? '_'.$row['subkey'] : '');
@ -259,7 +259,7 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', '
$result = Database::query($sql);
$group = array ();
while ($rowkeys = Database::fetch_array($result)) {
if ($rowkeys['variable'] == 'course_create_active_tools' && $rowkeys['subkey'] == 'enable_search') { continue; }
//if ($rowkeys['variable'] == 'course_create_active_tools' && $rowkeys['subkey'] == 'enable_search') { continue; }
// Profile tab option should be hidden when the social tool is enabled.
if (api_get_setting('allow_social_tool') == 'true') {
@ -575,10 +575,8 @@ echo "\n</div>";
if (!empty($_GET['category'])) {
switch ($_GET['category']) {
case 'Plugins':
// Displaying the extensions: Plugins.
// This will be available to all the sites (access_urls).
if (isset($_POST['submit_dashboard_plugins'])) {
$affected_rows = DashboardManager::store_dashboard_plugins($_POST);
if ($affected_rows) {
@ -590,13 +588,11 @@ if (!empty($_GET['category'])) {
Display :: display_confirmation_message(get_lang('DashboardPluginsHaveBeenUpdatedSucesslly'));
}
}
handle_plugins();
DashboardManager::handle_dashboard_plugins();
break;
case 'stylesheets':
// Displaying the extensions: Stylesheets.
handle_stylesheets();
break;
@ -613,5 +609,4 @@ if (!empty($_GET['category'])) {
}
/* FOOTER */
Display :: display_footer();
Display :: display_footer();

@ -6,6 +6,9 @@
* @package chamilo.admin
*/
$language_file[] = 'admin';
// Resetting the course id.
$cidReset = true;
// Including some necessary chamilo files
require_once '../inc/global.inc.php';
@ -17,6 +20,7 @@ $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAd
$interbreadcrumb[] = array ('url' => 'specific_fields.php', 'name' => get_lang('SpecificSearchFields'));
$libpath = api_get_path(LIBRARY_PATH);
require_once $libpath.'sortabletable.class.php';
include_once $libpath.'specific_fields_manager.lib.php';
require_once $libpath.'formvalidator/FormValidator.class.php';

@ -6,6 +6,10 @@
*/
$language_file[] = 'admin';
// Resetting the course id.
$cidReset = true;
// including necessary libraries
require_once '../inc/global.inc.php';
$libpath = api_get_path(LIBRARY_PATH);
@ -40,8 +44,8 @@ $form->addElement('text','field_name',get_lang('FieldName'));
$form->applyFilter('field_name','html_filter');
$form->applyFilter('field_name','trim');
$form->addRule('field_name', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('fieldname', get_lang('OnlyLettersAndNumbersAllowed'), 'username');
$form->addRule('fieldname', '', 'maxlength',20);
$form->addRule('field_name', get_lang('OnlyLettersAndNumbersAllowed'), 'username');
$form->addRule('field_name', '', 'maxlength',20);
// Set default values (only not empty when editing)
$defaults = array();
@ -51,7 +55,7 @@ if (is_numeric($_REQUEST['field_id'])) {
}
$form->setDefaults($defaults);
// Submit button
$form->addElement('submit', 'submit', get_lang('Add'));
$form->addElement('style_submit_button', 'submit', get_lang('Add'),'class="add"');
// Validate form
if ($form->validate()) {

@ -26,8 +26,8 @@ define('XAPIAN_DB', api_get_path(SYS_PATH).'searchdb/');
function xapian_query($query_string, $db = NULL, $start = 0, $length = 10, $extra = array(), $count_type = 0) {
try {
if (!is_object($db)) {
$db = new XapianDatabase(XAPIAN_DB);
if (!is_object($db)) {
$db = new XapianDatabase(XAPIAN_DB);
}
// Build subqueries from $extra array. Now only used by tags search filter on search widget
@ -103,10 +103,9 @@ function xapian_query($query_string, $db = NULL, $start = 0, $length = 10, $extr
}
return array($count, $results);
}
catch (Exception $e) {
display_xapian_error($e->getMessage());
return NULL;
} catch (Exception $e) {
display_xapian_error($e->getMessage());
return NULL;
}
}
@ -245,5 +244,4 @@ function xapian_join_queries($query1, $query2=NULL, $op='or') {
}
$display_message=get_lang('Error').' : '. $message_error;
Display::display_error_message($display_message);
}
?>
}

@ -149,20 +149,19 @@ function get_specific_field_values_list_by_prefix($prefix, $course_code, $tool_i
* @param string $value specific field value
*/
function add_specific_field_value($id_specific_field, $course_id, $tool_id, $ref_id, $value) {
$table_sf_values = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD_VALUES);
$value = trim($value);
if (empty($value)) {
return FALSE;
}
$sql = 'INSERT INTO %s(id, course_code, tool_id, ref_id, field_id, value) VALUES(NULL, \'%s\', \'%s\', %s, %s, \'%s\')';
$sql = sprintf($sql, $table_sf_values, $course_id, $tool_id, $ref_id, $id_specific_field, Database::escape_string($value));
$result = Database::query($sql);
if ($result) {
return Database::insert_id();
}
else {
return FALSE;
}
$table_sf_values = Database :: get_main_table(TABLE_MAIN_SPECIFIC_FIELD_VALUES);
$value = trim($value);
if (empty($value)) {
return false;
}
$sql = 'INSERT INTO %s(id, course_code, tool_id, ref_id, field_id, value) VALUES(NULL, \'%s\', \'%s\', %s, %s, \'%s\')';
$sql = sprintf($sql, $table_sf_values, $course_id, $tool_id, $ref_id, $id_specific_field, Database::escape_string($value));
$result = Database::query($sql);
if ($result) {
return Database::insert_id();
} else {
return false;
}
}
/**

@ -165,7 +165,7 @@ if (api_is_allowed_to_edit(null, true) && isset($_GET['action'])) {
echo '</div>';
if (api_get_setting('search_enabled') == 'true') {
if (!extension_loaded('xapian')) {
Display::display_error_message(get_lang('SearchXapianModuleNotInstaled'));
Display::display_error_message(get_lang('SearchXapianModuleNotInstalled'));
}
}
// Displaying the correct title and the form for adding a category or link. This is only shown when nothing

@ -1397,8 +1397,10 @@ class learnpath {
require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
$terms = get_specific_field_values_list_by_prefix($prefix, $this->cc, TOOL_LEARNPATH, $this->lp_id);
$prefix_terms = array();
foreach ($terms as $term) {
$prefix_terms[] = $term['value'];
if (!empty($terms)) {
foreach ($terms as $term) {
$prefix_terms[] = $term['value'];
}
}
return $prefix_terms;
}
@ -3882,7 +3884,7 @@ class learnpath {
$items_table = Database :: get_course_table(TABLE_LP_ITEM);
// TODO: Make query secure agains XSS : use member attr instead of post var.
$lp_id = intval($_POST['lp_id']);
$sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
$sql = "SELECT * FROM $items_table WHERE lp_id = $lp_id";
$result = Database::query($sql);
$di = new DokeosIndexer();
@ -3892,6 +3894,7 @@ class learnpath {
$sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1';
$sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
//echo $sql; echo '<br>';
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
@ -3901,7 +3904,7 @@ class learnpath {
$doc = $di->get_document($se_ref['search_did']);
$xapian_terms = xapian_get_doc_terms($doc, $prefix);
//var_dump($xapian_terms);
$xterms = array ();
foreach ($xapian_terms as $xapian_term) {
$xterms[] = substr($xapian_term['name'], 1);
@ -3921,8 +3924,10 @@ class learnpath {
}
$di->getDb()->replace_document((int) $se_ref['search_did'], $doc);
$di->getDb()->flush();
} else {
//@todo What we should do here?
}
}
}
return true;
}

@ -3,11 +3,12 @@
/**
* Script to draw the results from a query
* @package: chamilo.learnpath
* @author: Diego Escalante Urrelo <diegoe@gmail.com>
* @author: Marco Antonio Villegas Vega <marvil07@gmail.com>
* @package chamilo.learnpath
* @author Diego Escalante Urrelo <diegoe@gmail.com>
* @author Marco Antonio Villegas Vega <marvil07@gmail.com>
* @author Julio Montoya <gugli100@gmail.com> Lots of bug fixing
*
*/
require_once api_get_path(LIBRARY_PATH).'sortabletable.class.php';
require api_get_path(LIBRARY_PATH).'search/search_widget.php';
require api_get_path(LIBRARY_PATH).'search/DokeosQuery.php';
@ -138,13 +139,14 @@ if (count($blocks) > 0) {
$additional_parameters = array (
'mode' => $mode,
'action' => 'search',
'query' => $_REQUEST['query'],
'query' => Security::remove_XSS($_REQUEST['query']),
);
$get_params = '';
foreach ($specific_fields as $specific_field) {
if (isset($_REQUEST[ 'sf_'. $specific_field['code'] ])) {
$values = $_REQUEST[ 'sf_'. $specific_field['code'] ];
$additional_parameters[ 'sf_'. $specific_field['code'] ] = $values;
//Sortable additional_parameters doesn't accept multi dimensional arrays
//$additional_parameters[ 'sf_'. $specific_field['code'] ] = $values;
foreach ( $values as $value ) {
$get_params .= '&sf_' . $specific_field['code'] .'[]='. $value;
}
@ -152,6 +154,7 @@ if (count($blocks) > 0) {
}
}
$additional_parameters['operator'] = $op;
$s->additional_parameters = $additional_parameters;
if ($mode == 'default') {

@ -1,4 +1,4 @@
INSTALL
INSTALLATION
On Debian Lenny
Base install
@ -17,24 +17,23 @@ On Debian Lenny
On Ubuntu 8.10
DOKEOS 1.8.5 + XAPIAN in Ubuntu 8.10
Chamilo 1.8.8 + XAPIAN in Ubuntu 10.10
1. Execute dokeos_main_corp.sql
2. Go to main/admin/settings.php?category=Tools and add the search params
Full-text search feature
3. Add specific fields in main/admin/specific_fields.php
4. Add specific search field i.e. Author, Body part, Technology, Topic
5. Install php5 + xapian
apt-get install php5-xapian
6. Install
1. Activate the search module setting in main/admin/settings.php?category=Search
2. Go to main/admin/specific_fields.php and Specific fields (Those are text fields that will be add in documents, exercises, links in order to index data)
i.e i.e. Author, Body part, Technology, Topic
3. Go to main/admin/settings.php?category=Search and set a Specific field by default
4. Install the Xapian module for PHP5
sudo apt-get install php5-xapian
5. Install the imagemagick modules
sudo apt-get install imagemagick
sudo apt-get install php5-imagick
7. On Dokeos root
mkdir searchdb
chmod 777 searchdb
8. Useful xapian development tools
apt-get install xapian-doc xapian-tools
9. Restart Apache
10. Create a course and 2 LP for testing
11. Edit the LPs created and add/edit the specific fields (i.e. Author, Body part, Technology, Topic)
6. In Chamilo root
mkdir searchdb
sudo chmod 777 searchdb
7. Useful Xapian development tools
sudo apt-get install xapian-doc xapian-tools
8. Restart Apache
9. Create a course and 2 *new* Learning paths for testing
10.Edit the LPs created and add/edit the specific fields (i.e. Author, Body part, Technology, Topic)
11.Go to the

@ -1,26 +1,24 @@
<?php
/* For licensing terms, see /dokeos_license.txt */
/* For licensing terms, see /license.txt */
/**
* This file includes lp_list_search to avoid duplication of code, it
* bootstraps dokeos api enough to make lp_list_search work.
* bootstraps chamilo api enough to make lp_list_search work.
*/
$language_file = array('admin');
require_once ('../inc/global.inc.php');
require_once '../inc/global.inc.php';
$this_section = SECTION_COURSES;
if (extension_loaded('xapian')) {
include_once (api_get_path(LIBRARY_PATH).'course.lib.php');
include_once (api_get_path(LIBRARY_PATH).'system_announcements.lib.php');
include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
include_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
require_once api_get_path(LIBRARY_PATH).'course.lib.php';
require_once api_get_path(LIBRARY_PATH).'system_announcements.lib.php';
require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
//api_block_anonymous_users(); // only users who are logged in can proceed
require '../newscorm/lp_list_search.php';
} else {
Display::display_header(get_lang('Search'));
Display::display_error_message(get_lang('SearchXapianModuleNotInstaled'));
Display::display_error_message(get_lang('SearchXapianModuleNotInstalled'));
Display::display_footer();
exit;
}
?>
}

@ -1,2 +1,2 @@
This directory is a placeholder for the search plugin, which allows the
indexation of Dokeos contents through the use of the Xapian search engine.
indexation of Chamilo contents through the use of the Xapian search engine.

Loading…
Cancel
Save