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;
31 use C4::Koha; # XXX subfield_is_koha_internal_p
32 use C4::Search::History;
34 use Koha::Authority::Types;
37 my $op = $query->param('op') || '';
38 my $authtypecode = $query->param('authtypecode') || '';
39 my $dbh = C4::Context->dbh;
41 my $startfrom = $query->param('startfrom');
42 my $authid = $query->param('authid');
43 $startfrom = 0 if ( !defined $startfrom );
44 my ( $template, $loggedinuser, $cookie );
47 my $authority_types = Koha::Authority::Types->search({}, { order_by => ['authtypetext']});
49 if ( $op eq "do_search" ) {
50 my @marclist = ($query->param('marclist'));
51 my @and_or = ($query->param('and_or'));
52 my @excluding = ($query->param('excluding'),);
53 my @operator = ($query->param('operator'));
54 my $orderby = $query->param('orderby');
55 my @value = ($query->param('value') || "",);
57 $resultsperpage = $query->param('resultsperpage');
58 $resultsperpage = 20 if ( !defined $resultsperpage );
60 my ( $results, $total, @fields ) =
61 SearchAuthorities( \@marclist, \@and_or, \@excluding, \@operator,
62 \@value, $startfrom * $resultsperpage,
63 $resultsperpage, $authtypecode, $orderby );
64 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
66 template_name => "opac-authoritiessearchresultlist.tt",
74 # multi page display gestion
76 my $displayprev = $startfrom;
78 if ( ( $total - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
83 { term => "marclist", val => $marclist[0] },
84 { term => "and_or", val => $and_or[0] },
85 { term => "excluding", val => $excluding[0] },
86 { term => "operator", val => $operator[0] },
87 { term => "value", val => $value[0] },
92 if ( $total > $resultsperpage ) {
93 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
96 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
100 highlight => $highlight,
101 searchdata => \@field_data,
102 startfrom => ( $i - 1 )
108 my $from = $startfrom * $resultsperpage + 1;
111 if ( $total < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
115 $to = ( ( $startfrom + 1 ) * $resultsperpage );
117 unless (C4::Context->preference('OPACShowUnusedAuthorities')) {
118 my @usedauths = grep { $_->{used} > 0 } @$results;
119 $results = \@usedauths;
122 # Opac search history
123 if (C4::Context->preference('EnableOpacSearchHistory')) {
124 unless ( $startfrom ) {
125 my $path_info = $query->url(-path_info=>1);
126 my $query_cgi_history = $query->url(-query=>1);
127 $query_cgi_history =~ s/^$path_info\?//;
128 $query_cgi_history =~ s/;/&/g;
130 unless ( $loggedinuser ) {
131 my $new_search = C4::Search::History::add_to_session({
133 query_desc => $value[0],
134 query_cgi => $query_cgi_history,
139 # To the session (the user is logged in)
140 C4::Search::History::add({
141 userid => $loggedinuser,
142 sessionid => $query->cookie("CGISESSID"),
143 query_desc => $value[0],
144 query_cgi => $query_cgi_history,
152 $template->param( result => $results ) if $results;
153 $template->param( FIELDS => \@fields );
154 $template->param( orderby => $orderby );
156 startfrom => $startfrom,
157 displaynext => $displaynext,
158 displayprev => $displayprev,
159 resultsperpage => $resultsperpage,
160 startfromnext => $startfrom + 1,
161 startfromprev => $startfrom - 1,
162 searchdata => \@field_data,
163 countfuzzy => !(C4::Context->preference('OPACShowUnusedAuthorities')),
167 resultcount => scalar @$results,
168 numbers => \@numbers,
169 authtypecode => $authtypecode,
170 authtypetext => $authority_types->find($authtypecode)->authtypetext,
171 isEDITORS => $authtypecode eq 'EDITORS',
176 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
178 template_name => "opac-authorities-home.tt",
181 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
189 authority_types => $authority_types,
190 authtypecode => $authtypecode,
194 output_html_with_http_headers $query, $cookie, $template->output;