2 # WARNING: 4-character tab stops here
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
30 use C4::AuthoritiesMarc;
32 use C4::Search::History;
34 use Koha::Authority::Types;
35 use Koha::SearchEngine::Search;
36 use Koha::SearchEngine::QueryBuilder;
39 my $op = $query->param('op') || '';
40 my $authtypecode = $query->param('authtypecode') || '';
41 my $dbh = C4::Context->dbh;
43 my $startfrom = $query->param('startfrom') || 1;
44 my $resultsperpage = $query->param('resultsperpage') || 20;
45 my $authid = $query->param('authid');
46 my ( $template, $loggedinuser, $cookie );
48 my $authority_types = Koha::Authority::Types->search({}, { order_by => ['authtypetext']});
50 if ( $op eq "do_search" ) {
51 my @marclist = $query->multi_param('marclist');
52 my @and_or = $query->multi_param('and_or');
53 my @excluding = $query->multi_param('excluding');
54 my @operator = $query->multi_param('operator');
55 my $orderby = $query->param('orderby');
56 my @value = $query->multi_param('value');
59 my $builder = Koha::SearchEngine::QueryBuilder->new(
60 { index => $Koha::SearchEngine::AUTHORITIES_INDEX } );
61 my $searcher = Koha::SearchEngine::Search->new(
62 { index => $Koha::SearchEngine::AUTHORITIES_INDEX } );
63 my $search_query = $builder->build_authorities_query_compat( \@marclist, \@and_or,
64 \@excluding, \@operator, \@value, $authtypecode, $orderby );
65 my $offset = ( $startfrom - 1 ) * $resultsperpage + 1;
66 my ( $results, $total ) =
67 $searcher->search_auth_compat( $search_query, $offset, $resultsperpage );
68 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
70 template_name => "opac-authoritiessearchresultlist.tt",
76 $template->param( search_query => $search_query ) if C4::Context->preference('DumpSearchQueryTemplate');
78 # multi page display gestion
79 my $value_url = uri_escape_utf8($value[0]);
80 my $base_url = "opac-authorities-home.pl?"
81 ."marclist=$marclist[0]"
82 ."&and_or=$and_or[0]"
83 ."&excluding=$excluding[0]"
84 ."&operator=$operator[0]"
85 ."&value=$value_url"
86 ."&resultsperpage=$resultsperpage"
89 ."&authtypecode=$authtypecode"
90 ."&orderby=$orderby";
92 my $from = ( $startfrom - 1 ) * $resultsperpage + 1;
94 if ( !defined $total ) {
98 if ( $total < $startfrom * $resultsperpage ) {
102 $to = $startfrom * $resultsperpage;
105 $template->param( result => $results ) if $results;
108 pagination_bar => pagination_bar(
109 $base_url, int( $total / $resultsperpage ) + 1,
110 $startfrom, 'startfrom'
117 unless (C4::Context->preference('OPACShowUnusedAuthorities')) {
118 # TODO implement usage counts
119 # my @usedauths = grep { $_->{used} > 0 } @$results;
120 # $results = \@usedauths;
123 # Opac search history
124 if (C4::Context->preference('EnableOpacSearchHistory')) {
125 if ( $startfrom == 1) {
126 my $path_info = $query->url(-path_info=>1);
127 my $query_cgi_history = $query->url(-query=>1);
128 $query_cgi_history =~ s/^$path_info\?//;
129 $query_cgi_history =~ s/;/&/g;
131 unless ( $loggedinuser ) {
132 my $new_search = C4::Search::History::add_to_session({
134 query_desc => $value[0],
135 query_cgi => $query_cgi_history,
140 # To the session (the user is logged in)
141 C4::Search::History::add({
142 userid => $loggedinuser,
143 sessionid => $query->cookie("CGISESSID"),
144 query_desc => $value[0],
145 query_cgi => $query_cgi_history,
153 $template->param( orderby => $orderby );
155 startfrom => $startfrom,
156 resultsperpage => $resultsperpage,
157 countfuzzy => !(C4::Context->preference('OPACShowUnusedAuthorities')),
158 resultcount => scalar @$results,
159 authtypecode => $authtypecode,
160 authtypetext => $authority_types->find($authtypecode)->authtypetext,
161 isEDITORS => $authtypecode eq 'EDITORS',
166 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
168 template_name => "opac-authorities-home.tt",
171 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
178 authority_types => $authority_types,
179 authtypecode => $authtypecode,
183 output_html_with_http_headers $query, $cookie, $template->output;