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
;
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->multi_param('marclist');
51 my @and_or = $query->multi_param('and_or');
52 my @excluding = $query->multi_param('excluding');
53 my @operator = $query->multi_param('operator');
54 my $orderby = $query->param('orderby');
55 my @value = $query->multi_param('value');
58 $resultsperpage = $query->param('resultsperpage');
59 $resultsperpage = 20 if ( !defined $resultsperpage );
61 my ( $results, $total, @fields ) =
62 SearchAuthorities
( \
@marclist, \
@and_or, \
@excluding, \
@operator,
63 \
@value, $startfrom * $resultsperpage,
64 $resultsperpage, $authtypecode, $orderby );
65 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
67 template_name
=> "opac-authoritiessearchresultlist.tt",
75 # multi page display gestion
77 my $displayprev = $startfrom;
79 if ( ( $total - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
84 { term
=> "marclist", val
=> $marclist[0] },
85 { term
=> "and_or", val
=> $and_or[0] },
86 { term
=> "excluding", val
=> $excluding[0] },
87 { term
=> "operator", val
=> $operator[0] },
88 { term
=> "value", val
=> $value[0] },
93 if ( $total > $resultsperpage ) {
94 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
97 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
101 highlight
=> $highlight,
102 searchdata
=> \
@field_data,
103 startfrom
=> ( $i - 1 )
109 my $from = $startfrom * $resultsperpage + 1;
112 if ( $total < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
116 $to = ( ( $startfrom + 1 ) * $resultsperpage );
118 unless (C4
::Context
->preference('OPACShowUnusedAuthorities')) {
119 my @usedauths = grep { $_->{used
} > 0 } @
$results;
120 $results = \
@usedauths;
123 # Opac search history
124 if (C4
::Context
->preference('EnableOpacSearchHistory')) {
125 unless ( $startfrom ) {
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( result
=> $results ) if $results;
154 $template->param( FIELDS
=> \
@fields );
155 $template->param( orderby
=> $orderby );
157 startfrom
=> $startfrom,
158 displaynext
=> $displaynext,
159 displayprev
=> $displayprev,
160 resultsperpage
=> $resultsperpage,
161 startfromnext
=> $startfrom + 1,
162 startfromprev
=> $startfrom - 1,
163 searchdata
=> \
@field_data,
164 countfuzzy
=> !(C4
::Context
->preference('OPACShowUnusedAuthorities')),
168 resultcount
=> scalar @
$results,
169 numbers
=> \
@numbers,
170 authtypecode
=> $authtypecode,
171 authtypetext
=> $authority_types->find($authtypecode)->authtypetext,
172 isEDITORS
=> $authtypecode eq 'EDITORS',
177 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
179 template_name
=> "opac-authorities-home.tt",
182 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
190 authority_types
=> $authority_types,
191 authtypecode
=> $authtypecode,
195 output_html_with_http_headers
$query, $cookie, $template->output;