<?php
// +-------------------------------------------------+
// © 2002-2004 PMB Services / www.sigb.net pmb@sigb.net et contributeurs (voir www.sigb.net)
// +-------------------------------------------------+
// $Id: level2_search.class.php,v 1.13 2026/07/15 10:10:54 rtigero Exp $

if (stristr($_SERVER['REQUEST_URI'], ".class.php")) die("no access");

global $opac_search_other_function;
if ($opac_search_other_function) require_once($include_path."/".$opac_search_other_function);

/* Classe qui permet de faire la recherche de premier niveau */

class level2_search {
	public $user_query;
	public $type;

	protected $elements_ids;

	/* Instance du searcher utilise pour la recherche (sert a connaitre le plafonnement Sphinx) */
	protected $searcher_instance;

    public function __construct($user_query, $type) {
    	$this->user_query = $user_query;
    	$this->type = $type;
    }

    protected function get_title() {
    	global $msg;

    	return $msg[$this->type.'_found'];
    }

    protected function get_query() {
    	$query = '';
    	return $query;
    }

//     protected function get_display_element($element) {
//     	$display = '';
//     	switch($this->type) {
//     		case 'indexint':
//     			$display .= "<a href='".$this->get_permalink($element->indexint_id)."'><img src='".get_url_icon('folder.gif')."' style='border:0px'/> ".$element->indexint_name." ".$element->indexint_comment."</a>";
//     			break;
//     		default:
//     			$display .= "<li class='categ_colonne'><span class='notice_fort'><a href='".$this->get_permalink($element->id)."'>".$element->name."</a></span></li>";
// //     			$display .= elements_authorities_list_ui::generate_element($element->id);
//     			break;
//     	}
//     	return $display;
//     }

    /**
     * Enregistrement des stats
     */
    protected function search_log($count) {
    	global $nb_results_tab;

		$nb_results_tab[$this->type] = $count;
    }

	public function proceed() {
		global $msg, $charset;
		global $include_path;
		global $opac_allow_affiliate_search;
		global $search_result_affiliate_lvl2_head;
		global $search_result_affiliate_lvl2_footer;
		global $opac_search_other_function;
		global $catal_navbar;
		global $pmb_logs_activate;
		global $count;
		global $tab;

	    if($opac_allow_affiliate_search){
	        print str_replace('!!title!!', common::format_title($msg['resultat_recherche']), $search_result_affiliate_lvl2_head);
		}else {
			print "
            <div id=\"resultatrech\">".common::format_title($msg['resultat_recherche'])."
				<div id=\"resultatrech_container\">
				    <div id=\"resultatrech_see\">";
		}

		//le contenu du catalogue est calculé dans 2 cas  :
		// 1- la recherche affiliée n'est pas activée, c'est donc le seul résultat affichable
		// 2- la recherche affiliée est active et on demande l'onglet catalog...
		if(!$opac_allow_affiliate_search || ($opac_allow_affiliate_search && $tab == "catalog")){
		    $display = $this->get_display_elements_list();
		    print $this->get_search_title();
			print '<div id="resultatrech_liste">' . $display . '</div>';
			if($opac_allow_affiliate_search) {
			    print $catal_navbar . $search_result_affiliate_lvl2_footer;
			}
			else print "</div></div>";
			if ($this->type == 'extended') print "</div>"; // un div en +
		}else{
			$this->search_affiliate();
		}
		//Enregistrement des stats
		if($pmb_logs_activate){
			$this->search_log($count);
		}
    }

    public function get_elements_ids() {
    	if(!isset($this->elements_ids)) {
    		$this->elements_ids = array();
    	}
    	return $this->elements_ids;
    }

    public function get_search_title(){
    	global $charset, $count, $opac_search_other_function, $opac_allow_affiliate_search, $sphinx_active;

    	//Nombre affiche : par defaut le compte courant (plafonne, sert a la pagination).
    	//Si Sphinx a plafonne l'affichage, on montre le total reel et on signale la limite.
    	$display_count = $count;
    	$matches_restrict = "";
    	if($sphinx_active && is_object($this->searcher_instance) && method_exists($this->searcher_instance, 'is_results_limited') && $this->searcher_instance->is_results_limited()){
    		$display_count = $this->searcher_instance->get_full_nb_results();
    		$matches_restrict = $this->searcher_instance->get_matches_restrict_message();
    	}

    	$search_title = "<h3 class='searchResult-search' id='searchResult-search' >
				<span class='searchResult-equation'>
					<span class='searchResult-nbResults' id='searchResult-nbResults'><b>".$display_count."</b></span> ".$this->get_title()." <b>
					'".htmlentities($this->user_query,ENT_QUOTES,$charset)."'".$matches_restrict;

    	if ($opac_search_other_function) {
    		$search_title.= " ".search_other_function_human_query($_SESSION["last_query"]);
    	}
    	$search_title.= "</b></span>";
    	$search_title.= activation_surlignage();
    	$search_title.= "</h3>\n";

    	if(!$opac_allow_affiliate_search)
    		$search_title.= "
					</div>";

    	return $search_title;
    }
}
?>