'; } /** * Get one term html select. */ function format_one_specific_field_select($prefix, $sf_term_array, $op, $extra_select_attr = 'size="7" class="sf-select-multiple"') { global $charset; $multiple_select = ''; return $multiple_select; } /** * Get terms html selects. */ function format_specific_fields_selects($sf_terms, $op, $prefilter_prefix = '') { // Process each prefix type term $i = 0; $max = count($sf_terms); $multiple_selects = ''; foreach ($sf_terms as $prefix => $sf_term_array) { if ($prefix == $prefilter_prefix) { continue; } $multiple_select = ''; if ($i > 0) { //print "+" image $multiple_select .= 'plus-sign-decoration'; } //sorting the array of terms $temp = []; if (!empty($sf_term_array)) { foreach ($sf_term_array as $key => $value) { $temp[trim(stripslashes($value['name']))] = $key; } } $temp = array_flip($temp); unset($sf_term_array); natcasesort($temp); $sf_term_array = $temp; $sf_copy = $sf_term_array; // get specific field name $sf_value = get_specific_field_list(['code' => "'$prefix'"]); $sf_value = array_shift($sf_value); $multiple_select .= '
'; $multiple_select .= format_one_specific_field_select($prefix, $sf_term_array, $op, 'multiple="multiple" size="7" class="sf-select-multiple"'); $multiple_select .= ''; $multiple_selects .= $multiple_select; $i++; } return $multiple_selects; } /** * Build the normal form. * * First, natural way. */ function search_widget_normal_form($action, $show_thesaurus, $sf_terms, $op) { $thesaurus_icon = Display::return_icon('thesaurus.gif', get_lang('SearchAdvancedOptions'), ['id' => 'thesaurus-icon']); $advanced_options = ''.get_lang('SearchAdvancedOptions').''; $display_thesaurus = ($show_thesaurus == true ? 'block' : 'none'); $help = '

'.get_lang('SearchKeywordsHelpTitle').'

'.get_lang('SearchKeywordsHelpComment'); $mode = (!empty($_REQUEST['mode']) ? htmlentities($_REQUEST['mode']) : 'gallery'); $type = (!empty($_REQUEST['type']) ? htmlentities($_REQUEST['type']) : 'normal'); /** * POST avoid long urls, but we are using GET because * SortableTableFromArray pagination is done with simple links, so now we * could not send a form in pagination. */ if (isset($_GET['action']) && strcmp(trim($_GET['action']), 'search') === 0) { $action = 'index.php'; } $navigator_info = api_get_navigator(); if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') { $submit_button1 = ''; $submit_button2 = ''; $reset_button = ''; } else { $submit_button1 = ''; $submit_button2 = ''; $reset_button = ' '; } $query = isset($_REQUEST['query']) ? Security::remove_XSS($_REQUEST['query']) : null; $form = '
'; return $form; } /** * Build the prefilter form. * * This type allow filter all other multiple select terms by one term in a dinamic way */ function search_widget_prefilter_form( $action, $show_thesaurus, $sf_terms, $op, $prefilter_prefix = null ) { $thesaurus_icon = Display::return_icon('thesaurus.gif', get_lang('SearchAdvancedOptions'), ['id' => 'thesaurus-icon']); $advanced_options = ''.get_lang('SearchAdvancedOptions').''; $display_thesaurus = ($show_thesaurus == true ? 'block' : 'none'); $help = '

'.get_lang('SearchKeywordsHelpTitle').'

'.get_lang('SearchKeywordsHelpComment'); $mode = (!empty($_REQUEST['mode']) ? htmlentities($_REQUEST['mode']) : 'gallery'); $type = (!empty($_REQUEST['type']) ? htmlentities($_REQUEST['type']) : 'normal'); /** * POST avoid long urls, but we are using GET because * SortableTableFromArray pagination is done with simple links, so now we * could not send a form in pagination. */ if (isset($_GET['action']) && strcmp(trim($_GET['action']), 'search') === 0) { $action = 'index.php'; } $form = '
'; return $form; } /** * Show search form. */ function display_search_form($action, $show_thesaurus, $sf_terms, $op) { $type = (!empty($_REQUEST['type']) ? htmlentities($_REQUEST['type']) : 'normal'); switch ($type) { case 'prefilter': $prefilter_prefix = api_get_setting('search_prefilter_prefix'); $form = search_widget_prefilter_form( $action, $show_thesaurus, $sf_terms, $op, $prefilter_prefix ); break; case 'normal': default: $form = search_widget_normal_form( $action, $show_thesaurus, $sf_terms, $op ); break; } // show built form echo $form; } /** * Show the search widget. * * The form will post to index.php by default, you can pass a value to * $action to use a custom action. * IMPORTANT: you have to call search_widget_prepare() before calling this * function or otherwise the form will not behave correctly. * * @param string $action Just in case your action is not * index.php */ function search_widget_show($action = 'index.php') { require_once api_get_path(LIBRARY_PATH).'search/ChamiloQuery.php'; // TODO: load images dinamically when they're avalaible from specific field ui to add $groupId = api_get_group_id(); $sf_terms = []; $specific_fields = get_specific_field_list(); $url_params = []; if (($cid = api_get_course_id()) != -1) { // with cid // get search engine terms $course_filter = chamilo_get_boolean_query(XAPIAN_PREFIX_COURSEID.$cid); $dkterms = chamilo_query_simple_query('', 0, 1000, [$course_filter]); //prepare specific fields names (and also get possible URL param names) foreach ($specific_fields as $specific_field) { $temp = []; if (is_array($dkterms) && count($dkterms) > 0) { foreach ($dkterms[1] as $obj) { $temp = array_merge($obj['sf-'.$specific_field['code']], $temp); } } $sf_terms[$specific_field['code']] = $temp; $url_params[] = 'sf_'.$specific_field['code']; unset($temp); } } else { // without cid // prepare specific fields names (and also get possible URL param names) foreach ($specific_fields as $specific_field) { //get Xapian terms for a specific term prefix, in ISO, apparently $sf_terms[$specific_field['code']] = xapian_get_all_terms(1000, $specific_field['code']); $url_params[] = 'sf_'.$specific_field['code']; } } echo '

'.get_lang('Search').'

'; // Tool introduction // TODO: Settings for the online editor to be checked (insert an image for example). Probably this is a special case here. if (api_get_course_id() !== -1) { if (!empty($groupId)) { Display::display_introduction_section(TOOL_SEARCH.$groupId); } else { Display::display_introduction_section(TOOL_SEARCH); } } $op = 'or'; if (!empty($_REQUEST['operator']) && in_array($op, ['or', 'and'])) { $op = $_REQUEST['operator']; } //check if URL params are defined (to see if we show the thesaurus or not) $show_thesaurus = false; foreach ($url_params as $param) { if (isset($_REQUEST[$param]) && is_array($_REQUEST[$param])) { $thesaurus_decided = false; foreach ($_REQUEST[$param] as $term) { if (!empty($term)) { $show_thesaurus = true; $thesaurus_decided = true; break; } } if ($thesaurus_decided) { break; } } } // create the form // TODO: use FormValidator display_search_form($action, $show_thesaurus, $sf_terms, $op); }