<?php
// +-------------------------------------------------+
// 2002-2004 PMB Services / www.sigb.net pmb@sigb.net et contributeurs (voir www.sigb.net)
// +-------------------------------------------------+
// $Id: searcher_authorities_titres_uniformes_query.class.php,v 1.8.4.1 2026/01/23 13:39:40 dgoron Exp $
if (stristr($_SERVER['REQUEST_URI'], ".class.php"))
    die("no access");

global $class_path;
require_once ($class_path . '/searcher/searcher_autorities.class.php');

class searcher_authorities_titres_uniformes_query extends searcher_authorities_titres_uniformes
{

    protected $searcher_mode = 'query';

    protected function _analyse()
    {}

    public function _get_search_type()
    {
        return parent::_get_search_type() . "_query";
    }

    protected function _get_search_query()
    {
        $user_query = $this->_get_user_query();
        if ($user_query !== "*") {
            $query = str_replace('!!p!!', pmb_mysql_escape_string($user_query), $this->query);

            $filters = $this->_get_authorities_filters();
            if (count($filters)) {
                if (stripos($query, "where") === false) {
                    $query .= ' where ' . implode(' and ', $filters);
                } else {
                    $query .= ' and ' . implode(' and ', $filters);
                }
            }

            foreach ($this->filters as $filterid => $restrict) {
                $filter_field_name = "filter_field_tab_$filterid";
                global ${$filter_field_name};
                if (! empty(${$filter_field_name})) {
                    if (is_array(${$filter_field_name})) {
                        if (${$filter_field_name}[0] != "") {
                            $query .= str_replace('!!filter!!', '"' . implode('","', ${$filter_field_name}) . '"', $restrict);
                        }
                    } else {
                        $query .= str_replace('!!filter!!', '"' . pmb_mysql_escape_string(${$filter_field_name}) . '"', $restrict);
                    }
                }
            }
            return $query;
        }
        return "select 0 as $this->object_table_key";
    }
}