Bug 5979: follow to fix spelling
[koha.git] / opac / opac-authorities-home.pl
blobd37df857e1e8bb13338cc12ab0c0ed575e6281b6
1 #!/usr/bin/perl
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>.
21 use strict;
22 use warnings;
24 use CGI qw ( -utf8 );
25 use C4::Auth;
27 use C4::Context;
28 use C4::Auth;
29 use C4::Output;
30 use C4::AuthoritiesMarc;
31 use C4::Koha;
32 use C4::Search::History;
34 use Koha::Authority::Types;
36 my $query = new CGI;
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 );
45 my $resultsperpage;
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');
56 $value[0] ||= q||;
58 $resultsperpage = $query->param('resultsperpage');
59 $resultsperpage = 20 if ( !defined $resultsperpage );
60 my @tags;
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",
68 query => $query,
69 type => 'opac',
70 authnotrequired => 1,
71 debug => 1,
75 # multi page display gestion
76 my $displaynext = 0;
77 my $displayprev = $startfrom;
78 $total ||= 0;
79 if ( ( $total - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
80 $displaynext = 1;
83 my @field_data = (
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] },
91 my @numbers = ();
93 if ( $total > $resultsperpage ) {
94 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
95 if ( $i < 16 ) {
96 my $highlight = 0;
97 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
98 push @numbers,
100 number => $i,
101 highlight => $highlight,
102 searchdata => \@field_data,
103 startfrom => ( $i - 1 )
109 my $from = $startfrom * $resultsperpage + 1;
110 my $to;
112 if ( $total < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
113 $to = $total;
115 else {
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({
133 cgi => $query,
134 query_desc => $value[0],
135 query_cgi => $query_cgi_history,
136 total => $total,
137 type => "authority",
139 } else {
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,
146 total => $total,
147 type => "authority",
153 $template->param( result => $results ) if $results;
154 $template->param( FIELDS => \@fields );
155 $template->param( orderby => $orderby );
156 $template->param(
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')),
165 total => $total,
166 from => $from,
167 to => $to,
168 resultcount => scalar @$results,
169 numbers => \@numbers,
170 authtypecode => $authtypecode,
171 authtypetext => $authority_types->find($authtypecode)->authtypetext,
172 isEDITORS => $authtypecode eq 'EDITORS',
176 else {
177 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
179 template_name => "opac-authorities-home.tt",
180 query => $query,
181 type => 'opac',
182 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
183 debug => 1,
189 $template->param(
190 authority_types => $authority_types,
191 authtypecode => $authtypecode,
194 # Print the page
195 output_html_with_http_headers $query, $cookie, $template->output;
197 # Local Variables:
198 # tab-width: 4
199 # End: