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 under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 use C4
::AuthoritiesMarc
;
32 use C4
::Koha
; # XXX subfield_is_koha_internal_p
33 use C4
::Search
::History
;
36 my $op = $query->param('op') || '';
37 my $authtypecode = $query->param('authtypecode') || '';
38 my $dbh = C4
::Context
->dbh;
40 my $startfrom = $query->param('startfrom');
41 my $authid = $query->param('authid');
42 $startfrom = 0 if ( !defined $startfrom );
43 my ( $template, $loggedinuser, $cookie );
46 my $authtypes = getauthtypes
();
47 my @authtypesloop = ();
48 foreach my $thisauthtype (
50 $authtypes->{$a}->{'authtypetext'}
51 cmp $authtypes->{$b}->{'authtypetext'}
56 { value
=> $thisauthtype,
57 selected
=> $thisauthtype eq $authtypecode,
58 authtypetext
=> $authtypes->{$thisauthtype}->{'authtypetext'},
62 if ( $op eq "do_search" ) {
63 my @marclist = ($query->param('marclist'));
64 my @and_or = ($query->param('and_or'));
65 my @excluding = ($query->param('excluding'),);
66 my @operator = ($query->param('operator'));
67 my $orderby = $query->param('orderby');
68 my @value = ($query->param('value') || "",);
70 $resultsperpage = $query->param('resultsperpage');
71 $resultsperpage = 20 if ( !defined $resultsperpage );
73 my ( $results, $total, @fields ) =
74 SearchAuthorities
( \
@marclist, \
@and_or, \
@excluding, \
@operator,
75 \
@value, $startfrom * $resultsperpage,
76 $resultsperpage, $authtypecode, $orderby );
77 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
79 template_name
=> "opac-authoritiessearchresultlist.tt",
87 # multi page display gestion
89 my $displayprev = $startfrom;
91 if ( ( $total - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
96 { term
=> "marclist", val
=> $marclist[0] },
97 { term
=> "and_or", val
=> $and_or[0] },
98 { term
=> "excluding", val
=> $excluding[0] },
99 { term
=> "operator", val
=> $operator[0] },
100 { term
=> "value", val
=> $value[0] },
105 if ( $total > $resultsperpage ) {
106 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
109 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
113 highlight
=> $highlight,
114 searchdata
=> \
@field_data,
115 startfrom
=> ( $i - 1 )
121 my $from = $startfrom * $resultsperpage + 1;
124 if ( $total < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
128 $to = ( ( $startfrom + 1 ) * $resultsperpage );
130 unless (C4
::Context
->preference('OPACShowUnusedAuthorities')) {
131 my @usedauths = grep { $_->{used
} > 0 } @
$results;
132 $results = \
@usedauths;
135 # Opac search history
136 if (C4
::Context
->preference('EnableOpacSearchHistory')) {
137 unless ( $startfrom ) {
138 my $path_info = $query->url(-path_info
=>1);
139 my $query_cgi_history = $query->url(-query
=>1);
140 $query_cgi_history =~ s/^$path_info\?//;
141 $query_cgi_history =~ s/;/&/g;
143 unless ( $loggedinuser ) {
144 my $new_search = C4
::Search
::History
::add_to_session
({
146 query_desc
=> $value[0],
147 query_cgi
=> $query_cgi_history,
152 # To the session (the user is logged in)
153 C4
::Search
::History
::add
({
154 userid
=> $loggedinuser,
155 sessionid
=> $query->cookie("CGISESSID"),
156 query_desc
=> $value[0],
157 query_cgi
=> $query_cgi_history,
165 $template->param( result
=> $results ) if $results;
166 $template->param( FIELDS
=> \
@fields );
167 $template->param( orderby
=> $orderby );
169 startfrom
=> $startfrom,
170 displaynext
=> $displaynext,
171 displayprev
=> $displayprev,
172 resultsperpage
=> $resultsperpage,
173 startfromnext
=> $startfrom + 1,
174 startfromprev
=> $startfrom - 1,
175 searchdata
=> \
@field_data,
176 countfuzzy
=> !(C4
::Context
->preference('OPACShowUnusedAuthorities')),
180 resultcount
=> scalar @
$results,
181 numbers
=> \
@numbers,
182 authtypecode
=> $authtypecode,
183 authtypetext
=> $authtypes->{$authtypecode}{'authtypetext'},
184 isEDITORS
=> $authtypecode eq 'EDITORS',
189 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
191 template_name
=> "opac-authorities-home.tt",
194 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
201 $template->param( authtypesloop
=> \
@authtypesloop );
204 output_html_with_http_headers
$query, $cookie, $template->output;