diff --git a/main/admin/settings.lib.php b/main/admin/settings.lib.php index 74f9568bb0..90dc8245a3 100755 --- a/main/admin/settings.lib.php +++ b/main/admin/settings.lib.php @@ -564,11 +564,10 @@ function handle_search() { } $group = array(); $url = Display::div(Display::url(get_lang('AddSpecificSearchField'), 'specific_fields.php'), array('class'=>'sectioncomment')); - if (empty($sf_values)) { + if (empty($sf_values)) { $form->addElement('html', get_lang('SearchPrefilterPrefix')); } else { - $form->addElement('select', 'search_prefilter_prefix', get_lang('SearchPrefilterPrefix'), $sf_values, ''); - + $form->addElement('select', 'search_prefilter_prefix', get_lang('SearchPrefilterPrefix'), $sf_values, ''); $default_values['search_prefilter_prefix'] = api_get_setting('search_prefilter_prefix'); } $form->addElement('html', $url); @@ -617,29 +616,56 @@ function handle_search() { $dir_is_writable = Display::return_icon('bullet_green.gif', get_lang('Ok')); $specific_fields_exists = Display::return_icon('bullet_green.gif', get_lang('Ok')); + //Testing specific fields if (empty($specific_fields)) { $specific_fields_exists = Display::return_icon('bullet_red.gif', get_lang('AddSpecificSearchField')); } - + //Testing xapian extension if (!extension_loaded('xapian')) { $xapian_loaded = Display::return_icon('bullet_red.gif', get_lang('Error')); } + //Testing xapian searchdb path if (!is_dir($xapian_path)) { $dir_exists = Display::return_icon('bullet_red.gif', get_lang('Error')); } + //Testing xapian searchdb path is writable if (!is_writable($xapian_path)) { $dir_is_writable = Display::return_icon('bullet_red.gif', get_lang('Error')); } - + $data[] = array(get_lang('XapianModuleInstalled'),$xapian_loaded); $data[] = array(get_lang('DirectoryExists').' - '.$xapian_path,$dir_exists); $data[] = array(get_lang('IsWritable').' - '.$xapian_path,$dir_is_writable); - $data[] = array(get_lang('SpecificSearchFieldsAvailable') ,$specific_fields_exists); - + $data[] = array(get_lang('SpecificSearchFieldsAvailable') ,$specific_fields_exists); + + echo Display::tag('h3', get_lang('Settings')); $table = new SortableTableFromArray($data); - $table->set_header(0,get_lang('Setting'), false); - $table->set_header(1,get_lang('Value'), false); - echo $table->display(); + $table->set_header(0, get_lang('Setting'), false); + $table->set_header(1, get_lang('Status'), false); + echo $table->display(); + + //@todo windows support + if (api_is_windows_os() == false) { + $list_of_programs = array('pdftotext','ps2pdf', 'catdoc','html2text','unrtf', 'catppt', 'xls2csv'); + + foreach($list_of_programs as $program) { + $output = null; + exec("which $program", $output, $ret_val); + $icon = Display::return_icon('bullet_red.gif', get_lang('NotInstalled')); + if (!empty($output[0])) { + $icon = Display::return_icon('bullet_green.gif', get_lang('Installed')); + } + $data2[]= array($program, $output[0], $icon); + } + echo Display::tag('h3', get_lang('ProgramsNeededToConvertFiles')); + $table = new SortableTableFromArray($data2); + $table->set_header(0, get_lang('Program'), false); + $table->set_header(1, get_lang('Path'), false); + $table->set_header(2, get_lang('Status'), false); + echo $table->display(); + } else { + Display::display_warning_message(get_lang('YouAreUsingChamiloInAWindowsPlatformSadlyYouCantConvertDocumentsInOrderToSearchTheContentUsingThisTool')); + } } } diff --git a/main/document/upload.php b/main/document/upload.php index eeaa41b862..8083d7e2db 100755 --- a/main/document/upload.php +++ b/main/document/upload.php @@ -191,60 +191,6 @@ if (!empty($_FILES)) { DocumentManager::upload_document($_FILES, $_POST['curdirpath'], $_POST['title'], $_POST['comment'], $_POST['unzip'], $_POST['if_exists'], $_POST['index_document'], true); } -// @todo remove this submit_image ??? -/* -// Missing images are submitted -if (isset($_POST['submit_image'])) { - $number_of_uploaded_images = count($_FILES['img_file']['name']); - //if images are uploaded - if ($number_of_uploaded_images > 0) { - // We could also create a function for this, I'm not sure... - // Create a directory for the missing files - $img_directory = str_replace('.', '_', $_POST['related_file'].'_files'); - $missing_files_dir = create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $img_directory); - // Put the uploaded files in the new directory and get the paths - $paths_to_replace_in_file = move_uploaded_file_collection_into_directory($_course, $_FILES['img_file'], $base_work_dir, $missing_files_dir, $_user['user_id'], $to_group_id, $to_user_id, $max_filled_space); - // Open the html file and replace the paths - replace_img_path_in_html_file($_POST['img_file_path'], $paths_to_replace_in_file, $base_work_dir.$_POST['related_file']); - // Update parent folders - item_property_update_on_folder($_course, $_POST['curdirpath'], $_user['user_id']); - } -} -*/ -//@todo keep it simple this page should only upload files! -/* -// They want to create a directory -if (isset($_POST['create_dir']) && $_POST['dirname'] != '') { - $added_slash = ($path=='/') ? '' : '/'; - $dir_name = $path.$added_slash.replace_dangerous_char($_POST['dirname']); - $created_dir = create_unexisting_directory($_course, $_user['user_id'], $to_group_id, $to_user_id, $base_work_dir, $dir_name, $_POST['dirname']); - if ($created_dir) { - Display::display_confirmation_message(get_lang('DirCr'), false); - $path = $created_dir; - } else { - display_error(get_lang('CannotCreateDir')); - } -}*/ - -// Tracking not needed here? -//event_access_tool(TOOL_DOCUMENT); - -/* They want to create a new directory */ -/* -if (isset($_GET['createdir'])) { - // create the form that asks for the directory name - $new_folder_text = '
'; - $new_folder_text .= ''; - $new_folder_text .= get_lang('NewDir') .' '; - $new_folder_text .= ''; - $new_folder_text .= ''; - $new_folder_text .= '
'; - // Show the form - //Display::display_normal_message($new_folder_text, false); - - echo create_dir_form(); -}*/ - // Actions echo '
'; @@ -290,17 +236,17 @@ $form->addElement('checkbox', 'unzip', get_lang('Options'), get_lang('Uncompress if (api_get_setting('search_enabled') == 'true') { //TODO: include language file - $supported_formats = 'Supported formats for index: Text plain, PDF, Postscript, MS Word, HTML, RTF, MS Power Point'; - $form -> addElement('checkbox', 'index_document', '', get_lang('SearchFeatureDoIndexDocument').'
'.$supported_formats.'
'); - $form -> addElement('html', '
'); - $form -> addElement('html', '
'.get_lang('SearchFeatureDocumentLanguage').'
'); - $form -> addElement('html', '
'.api_get_languages_combo().'
'); - $form -> addElement('html', '
'); + $supported_formats = get_lang('SupportedFormatsForIndex').': HTML, PDF, TXT, PDF, Postscript, MS Word, RTF, MS Power Point'; + $form->addElement('checkbox', 'index_document', '', get_lang('SearchFeatureDoIndexDocument').'
'.$supported_formats.'
'); + $form->addElement('html', '
'); + $form->addElement('html', '
'.get_lang('SearchFeatureDocumentLanguage').'
'); + $form->addElement('html', '
'.api_get_languages_combo().'
'); + $form->addElement('html', '
'); $specific_fields = get_specific_field_list(); foreach ($specific_fields as $specific_field) { - $form -> addElement('text', $specific_field['code'], $specific_field['name'].' : '); + $form->addElement('text', $specific_field['code'], $specific_field['name'].' : '); } - $form -> addElement('html', '
'); + $form->addElement('html', '
'); } $form->addElement('radio', 'if_exists', get_lang('UplWhatIfFileExists'), get_lang('UplDoNothing'), 'nothing'); @@ -320,9 +266,7 @@ $form->setDefaults($defaults); $simple_form = $form->return_form(); -echo ' - -'; +'; $url = api_get_path(WEB_AJAX_PATH).'document.ajax.php'; $multiple_form = get_lang('ClickToSelectOrDragAndDropMultipleFilesOnTheUploadField').'
'; $multiple_form .= '
diff --git a/main/inc/lib/database.lib.php b/main/inc/lib/database.lib.php index fafa45f3d7..f962b94809 100755 --- a/main/inc/lib/database.lib.php +++ b/main/inc/lib/database.lib.php @@ -441,17 +441,19 @@ class Database { * * @param string $course_code * @param string $table the name of the table + * @todo this function should be deprecated use api_get_course_info() and then get_course_table() */ public static function get_course_table_from_code($course_code, $table) { $course_table = self::get_main_table(TABLE_MAIN_COURSE); $course_cat_table = self::get_main_table(TABLE_MAIN_CATEGORY); - $result = self::fetch_array(self::query( - "SELECT $course_table.db_name, $course_cat_table.code + $sql = "SELECT $course_table.db_name, $course_cat_table.code FROM $course_table LEFT JOIN $course_cat_table ON $course_table.category_code = $course_cat_table.code WHERE $course_table.code = '$course_code' - LIMIT 1")); + LIMIT 1"; + + $result = self::fetch_array(self::query($sql)); return sprintf("%s.%s", $result[0], $table); } diff --git a/main/inc/lib/search/DokeosIndexer.class.php b/main/inc/lib/search/DokeosIndexer.class.php index 65a8db72bb..a7046ce315 100755 --- a/main/inc/lib/search/DokeosIndexer.class.php +++ b/main/inc/lib/search/DokeosIndexer.class.php @@ -1,4 +1,6 @@ '.$submit_button1.' -

- '. $thesaurus_icon . $advanced_options .'  +

'; + $list = get_specific_field_list(); + if(!empty($list)) { + $form = ''. $advanced_options .' 
'. $help .'
- - '; - $form .= format_specific_fields_selects($sf_terms, $op); - $or_checked = ''; - $and_checked = ''; - if ($op == 'or') { - $or_checked = 'checked="checked"'; - } else if ($op == 'and') { - $and_checked = 'checked="checked"'; + '; + $form .= format_specific_fields_selects($sf_terms, $op); + $or_checked = ''; + $and_checked = ''; + if ($op == 'or') { + $or_checked = 'checked="checked"'; + } else if ($op == 'and') { + $and_checked = 'checked="checked"'; + } + $form .= ' + + + + + + +
+ '. get_lang('SearchCombineSearchWith') .':
+ '. api_strtoupper(get_lang('Or')) .' + '. api_strtoupper(get_lang('And')) .' +
+
+ '.$reset_button.' + '. $submit_button2.' +
+
'; } - $form .= ' - - - - '. get_lang('SearchCombineSearchWith') .':
- '. api_strtoupper(get_lang('Or')) .' - '. api_strtoupper(get_lang('And')) .' - - - -
- '.$reset_button.' - '. $submit_button2.' - - - -
- + $form .='
'; return $form; @@ -198,6 +200,7 @@ function search_widget_prefilter_form($action, $show_thesaurus, $sf_terms, $op, if (isset($_GET['action']) && strcmp(trim($_GET['action']),'search')===0) { $action='index.php'; } + $form = ' -
- '; +
'; + return $form; } diff --git a/main/inc/lib/search/tool_processors/document_processor.class.php b/main/inc/lib/search/tool_processors/document_processor.class.php old mode 100644 new mode 100755 index c4aa0403e6..ece47942b4 --- a/main/inc/lib/search/tool_processors/document_processor.class.php +++ b/main/inc/lib/search/tool_processors/document_processor.class.php @@ -58,42 +58,46 @@ class document_processor extends search_processor { * Get document information */ private function get_information($course_id, $doc_id) { - $doc_table = Database::get_course_table_from_code($course_id, TABLE_DOCUMENT); - $item_property_table = Database::get_course_table_from_code($course_id, TABLE_ITEM_PROPERTY); - $doc_id = Database::escape_string($doc_id); - $sql = "SELECT * - FROM $doc_table - WHERE $doc_table.id = $doc_id - LIMIT 1"; - $dk_result = Database::query ($sql); - - $sql = "SELECT insert_user_id - FROM $item_property_table - WHERE ref = $doc_id - AND tool = '". TOOL_DOCUMENT ."' - LIMIT 1"; - - $name = ''; - if ($row = Database::fetch_array ($dk_result)) { - $name = $row['title']; - $url = api_get_path(WEB_PATH) . 'courses/%s/document%s'; - $url = sprintf($url, api_get_course_path($course_id), $row['path']); - // Get the image path - include_once api_get_path(LIBRARY_PATH). 'fileDisplay.lib.php'; - $icon = choose_image(basename($row['path'])); - $thumbnail = api_get_path(WEB_CODE_PATH) .'img/'. $icon; - $image = $thumbnail; - //FIXME: use big images - // get author - $author = ''; - $item_result = Database::query ($sql); - if ($row = Database::fetch_array ($item_result)) { - $user_data = api_get_user_info($row['insert_user_id']); - $author = api_get_person_name($user_data['firstName'], $user_data['lastName']); - } + $course_information = api_get_course_info($course_id); + if (!empty($course_information)) { + $item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_information['db_name']); + $doc_table = Database::get_course_table(TABLE_DOCUMENT, $course_information['db_name']); + + $doc_id = Database::escape_string($doc_id); + $sql = "SELECT * + FROM $doc_table + WHERE $doc_table.id = $doc_id + LIMIT 1"; + $dk_result = Database::query ($sql); + + $sql = "SELECT insert_user_id + FROM $item_property_table + WHERE ref = $doc_id + AND tool = '". TOOL_DOCUMENT ."' + LIMIT 1"; + + $name = ''; + if ($row = Database::fetch_array ($dk_result)) { + $name = $row['title']; + $url = api_get_path(WEB_PATH) . 'courses/%s/document%s'; + $url = sprintf($url, api_get_course_path($course_id), $row['path']); + // Get the image path + include_once api_get_path(LIBRARY_PATH). 'fileDisplay.lib.php'; + $icon = choose_image(basename($row['path'])); + $thumbnail = api_get_path(WEB_CODE_PATH) .'img/'. $icon; + $image = $thumbnail; + //FIXME: use big images + // get author + $author = ''; + $item_result = Database::query ($sql); + if ($row = Database::fetch_array ($item_result)) { + $user_data = api_get_user_info($row['insert_user_id']); + $author = api_get_person_name($user_data['firstName'], $user_data['lastName']); + } + } + return array($thumbnail, $image, $name, $author, $url); // FIXME: is it posible to get an author here? + } else { + return array(); } - - return array($thumbnail, $image, $name, $author, $url); // FIXME: is it posible to get an author here? } -} -?> +} \ No newline at end of file diff --git a/main/inc/lib/search/tool_processors/learnpath_processor.class.php b/main/inc/lib/search/tool_processors/learnpath_processor.class.php old mode 100644 new mode 100755 index a8b59aac07..9524d75ad6 --- a/main/inc/lib/search/tool_processors/learnpath_processor.class.php +++ b/main/inc/lib/search/tool_processors/learnpath_processor.class.php @@ -78,50 +78,55 @@ class learnpath_processor extends search_processor { * Get learning path information */ private function get_information($course_id, $lp_id, $has_document_id=TRUE) { - $lpi_table = Database::get_course_table_from_code($course_id, TABLE_LP_ITEM); - $lp_table = Database::get_course_table_from_code($course_id, TABLE_LP_MAIN); - $doc_table = Database::get_course_table_from_code($course_id, TABLE_DOCUMENT); - $lp_id = Database::escape_string($lp_id); + + $course_information = api_get_course_info($course_id); + if (!empty($course_information)) { + $lpi_table = Database::get_course_table(TABLE_LP_ITEM, $course_information['db_name']); + $lp_table = Database::get_course_table_from_code(TABLE_LP_MAIN, $course_information['db_name']); + $doc_table = Database::get_course_table_from_code(TABLE_DOCUMENT, $course_information['db_name']); + + $lp_id = Database::escape_string($lp_id); - if ($has_document_id) { - $sql = "SELECT $lpi_table.id, $lp_table.name, $lp_table.author, $doc_table.path - FROM $lp_table, $lpi_table - INNER JOIN $doc_table ON $lpi_table.path = $doc_table.id - WHERE $lpi_table.lp_id = $lp_id - AND $lpi_table.display_order = 1 - AND $lp_table.id = $lpi_table.lp_id - LIMIT 1"; - } - else { - $sql = "SELECT $lpi_table.id, $lp_table.name, $lp_table.author - FROM $lp_table, $lpi_table - WHERE $lpi_table.lp_id = $lp_id - AND $lpi_table.display_order = 1 - AND $lp_table.id = $lpi_table.lp_id - LIMIT 1"; - } - - $dk_result = Database::query ($sql); - - $path = ''; - $name = ''; - if ($row = Database::fetch_array ($dk_result)) { - // Get the image path - $img_location = api_get_path(WEB_COURSE_PATH).api_get_course_path($course_id)."/document/"; - $thumbnail_path = str_replace ('.png.html', '_thumb.png', $row['path']); - $big_img_path = str_replace ('.png.html', '.png', $row['path']); - $thumbnail = ''; - if (!empty($thumbnail_path)) { - $thumbnail = $img_location . $thumbnail_path; + if ($has_document_id) { + $sql = "SELECT $lpi_table.id, $lp_table.name, $lp_table.author, $doc_table.path + FROM $lp_table, $lpi_table + INNER JOIN $doc_table ON $lpi_table.path = $doc_table.id + WHERE $lpi_table.lp_id = $lp_id + AND $lpi_table.display_order = 1 + AND $lp_table.id = $lpi_table.lp_id + LIMIT 1"; } - $image = ''; - if (!empty($big_img_path)) { - $image = $img_location . $big_img_path; + else { + $sql = "SELECT $lpi_table.id, $lp_table.name, $lp_table.author + FROM $lp_table, $lpi_table + WHERE $lpi_table.lp_id = $lp_id + AND $lpi_table.display_order = 1 + AND $lp_table.id = $lpi_table.lp_id + LIMIT 1"; } - $name = $row['name']; + + $dk_result = Database::query ($sql); + + $path = ''; + $name = ''; + if ($row = Database::fetch_array ($dk_result)) { + // Get the image path + $img_location = api_get_path(WEB_COURSE_PATH).api_get_course_path($course_id)."/document/"; + $thumbnail_path = str_replace ('.png.html', '_thumb.png', $row['path']); + $big_img_path = str_replace ('.png.html', '.png', $row['path']); + $thumbnail = ''; + if (!empty($thumbnail_path)) { + $thumbnail = $img_location . $thumbnail_path; + } + $image = ''; + if (!empty($big_img_path)) { + $image = $img_location . $big_img_path; + } + $name = $row['name']; + } + return array($thumbnail, $image, $name, $row['author']); + } else { + return array(); } - - return array($thumbnail, $image, $name, $row['author']); } -} -?> +} \ No newline at end of file diff --git a/main/inc/lib/search/xapian/XapianIndexer.class.php b/main/inc/lib/search/xapian/XapianIndexer.class.php index 9c59993c3f..7744cec63b 100755 --- a/main/inc/lib/search/xapian/XapianIndexer.class.php +++ b/main/inc/lib/search/xapian/XapianIndexer.class.php @@ -1,4 +1,6 @@ db = new XapianWritableDatabase($path, $dbMode); - $this->indexer = new XapianTermGenerator(); - - if (!in_array($lang, $this->xapian_languages())) { - $lang = 'english'; - } + $this->db = new XapianWritableDatabase($path, $dbMode); + $this->indexer = new XapianTermGenerator(); - $this->stemmer = new XapianStem($lang); - $this->indexer->set_stemmer($this->stemmer); - - return $this->db; - } - catch (Exception $e) { - Display::display_error_message($e->getMessage()); - return 1; + if (!in_array($lang, $this->xapian_languages())) { + $lang = 'english'; + } + $this->stemmer = new XapianStem($lang); + $this->indexer->set_stemmer($this->stemmer); + + return $this->db; + } catch (Exception $e) { + Display::display_error_message($e->getMessage()); + return 1; } } @@ -100,39 +100,37 @@ abstract class XapianIndexer { * @return integer New Xapian document ID or NULL upon failure */ function index() { - try { - if (!empty($this->chunks)) { - foreach ($this->chunks as $chunk) { - $doc = new XapianDocument(); - $this->indexer->set_document($doc); - if (!empty($chunk->terms)) { - foreach ($chunk->terms as $term) { - /* FIXME: think of getting weight */ - $doc->add_term($term['flag'] . $term['name'], 1); + try { + if (!empty($this->chunks)) { + foreach ($this->chunks as $chunk) { + $doc = new XapianDocument(); + $this->indexer->set_document($doc); + if (!empty($chunk->terms)) { + foreach ($chunk->terms as $term) { + /* FIXME: think of getting weight */ + $doc->add_term($term['flag'] . $term['name'], 1); + } } + + // free-form index all data array (title, content, etc) + if (!empty($chunk->data)) { + foreach ($chunk->data as $key => $value) { + $this->indexer->index_text($value, 1); + } + } + $doc->set_data($chunk->xapian_data, 1); + $did = $this->db->add_document($doc); + + //write to disk + $this->db->flush(); + + return $did; } - - // free-form index all data array (title, content, etc) - if (!empty($chunk->data)) { - foreach ($chunk->data as $key => $value) { - $this->indexer->index_text($value, 1); - } - } - $doc->set_data($chunk->xapian_data, 1); - $did = $this->db->add_document($doc); - - //write to disk - $this->db->flush(); - - return $did; } + } catch (Exception $e) { + Display::display_error_message($e->getMessage()); + exit(1); } - } - catch (Exception $e) { - Display::display_error_message($e->getMessage()); - exit(1); - } - } /** @@ -204,16 +202,16 @@ abstract class XapianIndexer { * @param int did Xapian::docid */ function remove_document($did) { - if ($this->db == NULL) { - $this->connectDb(); - } - if (is_numeric($did) && $did>0) { - $doc = $this->get_document($did); - if ($doc !== FALSE) { - $this->db->delete_document($did); - $this->db->flush(); - } - } + if ($this->db == NULL) { + $this->connectDb(); + } + if (is_numeric($did) && $did>0) { + $doc = $this->get_document($did); + if ($doc !== FALSE) { + $this->db->delete_document($did); + $this->db->flush(); + } + } } /** @@ -294,5 +292,4 @@ abstract class XapianIndexer { unset($this->db); unset($this->stemmer); } -} -?> +} \ No newline at end of file diff --git a/main/inc/lib/search/xapian/XapianQuery.php b/main/inc/lib/search/xapian/XapianQuery.php index dcf3255c3b..1419e0eba5 100755 --- a/main/inc/lib/search/xapian/XapianQuery.php +++ b/main/inc/lib/search/xapian/XapianQuery.php @@ -27,16 +27,17 @@ function xapian_query($query_string, $db = NULL, $start = 0, $length = 10, $extr try { if (!is_object($db)) { - $db = new XapianDatabase(XAPIAN_DB); + $db = new XapianDatabase(XAPIAN_DB); } // Build subqueries from $extra array. Now only used by tags search filter on search widget $subqueries = array(); foreach ($extra as $subquery) { - if (!empty($subquery)) { - $subqueries[] = new XapianQuery($subquery); - } + if (!empty($subquery)) { + $subqueries[] = new XapianQuery($subquery); + } } + $query = NULL; $enquire = new XapianEnquire($db); @@ -49,42 +50,52 @@ function xapian_query($query_string, $db = NULL, $start = 0, $length = 10, $extr $query_parser->set_database($db); $query_parser->set_stemming_strategy(XapianQueryParser::STEM_SOME); $query_parser->add_boolean_prefix('courseid', XAPIAN_PREFIX_COURSEID); - $query_parser->add_boolean_prefix('toolid', XAPIAN_PREFIX_TOOLID); + $query_parser->add_boolean_prefix('toolid', XAPIAN_PREFIX_TOOLID); $query = $query_parser->parse_query($query_string); - $query = new XapianQuery(XapianQuery::OP_AND, array_merge($subqueries, array($query))); - } - else { - $query = new XapianQuery(XapianQuery::OP_OR, $subqueries); + $final_array = array_merge($subqueries, array($query)); + $query = new XapianQuery(XapianQuery::OP_AND, $final_array); + } else { + $query = new XapianQuery(XapianQuery::OP_OR, $subqueries); } $enquire->set_query($query); + $matches = $enquire->get_mset((int)$start, (int)$length); + + $specific_fields = get_specific_field_list(); $results = array(); $i = $matches->begin(); + + // Display the results. + //echo $matches->get_matches_estimated().'results found'; + + $count = 0; - while (!$i->equals($matches->end())) { - $count++; - $document = $i->get_document(); - if (is_object($document)) { - // process one item terms - $courseid_terms = xapian_get_doc_terms($document, XAPIAN_PREFIX_COURSEID); - $results[$count]['courseid'] = substr($courseid_terms[0]['name'], 1); - $toolid_terms = xapian_get_doc_terms($document, XAPIAN_PREFIX_TOOLID); - $results[$count]['toolid'] = substr($toolid_terms[0]['name'], 1); - - // process each specific field prefix - foreach ($specific_fields as $specific_field) { - $results[$count]['sf-'.$specific_field['code']] = xapian_get_doc_terms($document, $specific_field['code']); - } - - // rest of data - $results[$count]['xapian_data'] = unserialize($document->get_data()); - $results[$count]['score'] = ($i->get_percent()); - } - $i->next(); + + while (!$i->equals($matches->end())) { + $count++; + $document = $i->get_document(); + + if (is_object($document)) { + // process one item terms + $courseid_terms = xapian_get_doc_terms($document, XAPIAN_PREFIX_COURSEID); + $results[$count]['courseid'] = substr($courseid_terms[0]['name'], 1); + $toolid_terms = xapian_get_doc_terms($document, XAPIAN_PREFIX_TOOLID); + $results[$count]['toolid'] = substr($toolid_terms[0]['name'], 1); + + // process each specific field prefix + foreach ($specific_fields as $specific_field) { + $results[$count]['sf-'.$specific_field['code']] = xapian_get_doc_terms($document, $specific_field['code']); + } + + // rest of data + $results[$count]['xapian_data'] = unserialize($document->get_data()); + $results[$count]['score'] = ($i->get_percent()); + } + $i->next(); } switch ($count_type) { @@ -101,7 +112,6 @@ function xapian_query($query_string, $db = NULL, $start = 0, $length = 10, $extr $count = $matches->get_matches_estimated(); break; } - return array($count, $results); } catch (Exception $e) { display_xapian_error($e->getMessage()); diff --git a/main/inc/lib/sortabletable.class.php b/main/inc/lib/sortabletable.class.php index 0845304d6b..a2d4344521 100755 --- a/main/inc/lib/sortabletable.class.php +++ b/main/inc/lib/sortabletable.class.php @@ -158,9 +158,9 @@ class SortableTable extends HTML_Table { $this->total_number_of_items = -1; $this->get_total_number_function = $get_total_number_function; $this->get_data_function = $get_data_function; - $this->column_filters = array (); - $this->form_actions = array (); - $this->checkbox_name = null; + $this->column_filters = array(); + $this->form_actions = array(); + $this->checkbox_name = null; $this->td_attributes = array (); $this->th_attributes = array (); $this->other_tables = array(); @@ -838,7 +838,7 @@ class SortableTableFromArray extends SortableTable { * @param int $default_column * @param int $default_items_per_page */ - public function __construct ($table_data, $default_column = 1, $default_items_per_page = 20, $tablename = 'tablename') { + public function __construct($table_data, $default_column = 1, $default_items_per_page = 20, $tablename = 'tablename') { parent :: __construct ($tablename, null, null, $default_column, $default_items_per_page); $this->table_data = $table_data; } @@ -847,7 +847,7 @@ class SortableTableFromArray extends SortableTable { * Get table data to show on current page * @see SortableTable#get_table_data */ - public function get_table_data ($from = 1, $sort = true) { + public function get_table_data($from = 1, $sort = true) { if ($sort) { $content = TableSort :: sort_table($this->table_data, $this->column, $this->direction == 'ASC' ? SORT_ASC : SORT_DESC); } else { diff --git a/main/newscorm/lp_list_search.css b/main/newscorm/lp_list_search.css index 1d06bc8cd5..f65c2286c5 100755 --- a/main/newscorm/lp_list_search.css +++ b/main/newscorm/lp_list_search.css @@ -1,43 +1 @@ -.doc_table { - width: 30%; - text-align: left; -} -.doc_img { - border: 1px solid black; - padding: 1px solid white; - background: white; -} -.doc_img, -.doc_img img { - width: 120px; -} -.doc_text, -.doc_title { - padding-left: 10px; - vertical-align: top; -} -.doc_title { - font-size: large; - font-weight: bold; - height: 2em; -} -.data_table { - text-align:center; -} -.cls { - clear:both -} -#search-results-container { - width: 940px; - border: 1px solid #979797; - position: relative; - background-image: url(\'../img/search_background_bar.jpg\'); - background-repeat: repeat-x -} -#mode-selector { - width: 100px; - padding: 4px; - position: absolute; - top: 0px; - z-index: 9; -} +/* css styles moved to search_widget.css */ \ No newline at end of file diff --git a/main/newscorm/lp_list_search.php b/main/newscorm/lp_list_search.php index e66beec0ec..e428b043f5 100755 --- a/main/newscorm/lp_list_search.php +++ b/main/newscorm/lp_list_search.php @@ -76,31 +76,43 @@ foreach ($specific_fields as $specific_field) { } } } + } else { + $sf_terms_for_code = xapian_get_all_terms(1000, $specific_field['code']); + foreach ($sf_terms_for_code as $term) { + if (!empty($term)) { + $term_array[] = dokeos_get_boolean_query($term['name']); // Here name includes prefix. + } + } } } // Get right group of terms to show on multiple select. $fixed_queries = array(); $course_filter = NULL; -if ( ($cid=api_get_course_id()) != -1 ) { +if ( ($cid=api_get_course_id()) != -1 ) { // Results only from actual course. $course_filter = dokeos_get_boolean_query(XAPIAN_PREFIX_COURSEID . $cid); } -if (count($term_array)) { + +if (count($term_array)) { $fixed_queries = dokeos_join_queries($term_array, null, $op); + if ($course_filter != NULL) { $fixed_queries = dokeos_join_queries($fixed_queries, $course_filter, 'and'); } } else { - if (!empty($query)) { + if (!empty($query)) { $fixed_queries = array($course_filter); } } +//var_dump($fixed_queries); + list($count, $results) = dokeos_query_query(api_convert_encoding($query, 'UTF-8', $charset), 0, 1000, $fixed_queries); // Prepare blocks to show. $blocks = array(); + if ($count > 0) { foreach ($results as $result) { // Fill the result array. @@ -122,10 +134,8 @@ if ($count > 0) { $a_prefix .''. $a_sufix .'
'.$title.'
'.$result['author'], ); } else { - $title = '
'. $a_prefix . $result['title']. $a_sufix .(!empty($result['author']) ? $result['author'] : '').'
'; - $blocks[] = array( - $title, - ); + $title = '
'. $a_prefix . $result['title']. $a_sufix .(!empty($result['author']) ? ' '.$result['author'] : '').'
'; + $blocks[] = array($title); } } } @@ -158,7 +168,7 @@ if (count($blocks) > 0) { $s->additional_parameters = $additional_parameters; if ($mode == 'default') { - $s->set_header(0, get_lang(ucfirst(TOOL_SEARCH))); + $s->set_header(0, get_lang(ucfirst(TOOL_SEARCH)), false); } $search_link = ''; diff --git a/searchdb/readme.txt b/searchdb/readme.txt deleted file mode 100755 index 3e15e1a615..0000000000 --- a/searchdb/readme.txt +++ /dev/null @@ -1,2 +0,0 @@ -This directory is a placeholder for the search plugin, which allows the -indexation of Chamilo contents through the use of the Xapian search engine.