Merge remote-tracking branch 'origin/new/bug_6720'
[koha.git] / opac / opac-authorities-home.pl
blob4e9f9ab4fbe4f5e759561720ceedd39a536c8bb1
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 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
11 # version.
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.
21 use strict;
22 use warnings;
24 use CGI;
25 use C4::Auth;
27 use C4::Context;
28 use C4::Auth;
29 use C4::Output;
30 use C4::AuthoritiesMarc;
31 use C4::Koha; # XXX subfield_is_koha_internal_p
33 my $query = new CGI;
34 my $op = $query->param('op') || '';
35 my $authtypecode = $query->param('authtypecode') || '';
36 my $dbh = C4::Context->dbh;
38 my $startfrom = $query->param('startfrom');
39 my $authid = $query->param('authid');
40 $startfrom = 0 if ( !defined $startfrom );
41 my ( $template, $loggedinuser, $cookie );
42 my $resultsperpage;
44 my $authtypes = getauthtypes();
45 my @authtypesloop = ();
46 foreach my $thisauthtype (
47 sort {
48 $authtypes->{$a}->{'authtypetext'}
49 cmp $authtypes->{$b}->{'authtypetext'}
51 keys %{$authtypes}
52 ) {
53 push @authtypesloop,
54 { value => $thisauthtype,
55 selected => $thisauthtype eq $authtypecode,
56 authtypetext => $authtypes->{$thisauthtype}->{'authtypetext'},
60 if ( $op eq "do_search" ) {
61 my @marclist = ($query->param('marclista'),$query->param('marclistb'),$query->param('marclistc'));
62 my @and_or = ($query->param('and_ora'),$query->param('and_orb'),$query->param('and_orc'));
63 my @excluding = ($query->param('excludinga'),$query->param('excludingb'),$query->param('excludingc'),);
64 my @operator = ($query->param('operatora'),$query->param('operatorb'),$query->param('operatorc'));
65 my $orderby = $query->param('orderby');
66 my @value = ($query->param('valuea') || "",$query->param('valueb') || "",$query->param('valuec') || "",);
68 $resultsperpage = $query->param('resultsperpage');
69 $resultsperpage = 20 if ( !defined $resultsperpage );
70 my @tags;
71 my ( $results, $total, @fields ) =
72 SearchAuthorities( \@marclist, \@and_or, \@excluding, \@operator,
73 \@value, $startfrom * $resultsperpage,
74 $resultsperpage, $authtypecode, $orderby );
75 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
77 template_name => "opac-authoritiessearchresultlist.tmpl",
78 query => $query,
79 type => 'opac',
80 authnotrequired => 1,
81 debug => 1,
85 # multi page display gestion
86 my $displaynext = 0;
87 my $displayprev = $startfrom;
88 $total ||= 0;
89 if ( ( $total - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
90 $displaynext = 1;
93 my @field_data = ();
95 foreach my $letter (qw/a b c/){
96 push @field_data, { term => "marclist$letter" , val => $query->param("marclist$letter") || ''};
97 push @field_data, { term => "and_or$letter" , val => $query->param("and_or$letter") || ''};
98 push @field_data, { term => "excluding$letter" , val => $query->param("excluding$letter") || ''};
99 push @field_data, { term => "operator$letter" , val => $query->param("operator$letter") || ''};
100 push @field_data, { term => "value$letter" , val => $query->param("value$letter") || ''};
103 my @numbers = ();
105 if ( $total > $resultsperpage ) {
106 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
107 if ( $i < 16 ) {
108 my $highlight = 0;
109 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
110 push @numbers,
112 number => $i,
113 highlight => $highlight,
114 searchdata => \@field_data,
115 startfrom => ( $i - 1 )
121 my $from = $startfrom * $resultsperpage + 1;
122 my $to;
124 if ( $total < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
125 $to = $total;
127 else {
128 $to = ( ( $startfrom + 1 ) * $resultsperpage );
130 unless (C4::Context->preference('OPACShowUnusedAuthorities')) {
131 my @usedauths = grep { $_->{used} > 0 } @$results;
132 $results = \@usedauths;
134 $template->param( result => $results ) if $results;
135 $template->param( FIELDS => \@fields );
136 $template->param( orderby => $orderby );
137 $template->param(
138 startfrom => $startfrom,
139 displaynext => $displaynext,
140 displayprev => $displayprev,
141 resultsperpage => $resultsperpage,
142 startfromnext => $startfrom + 1,
143 startfromprev => $startfrom - 1,
144 searchdata => \@field_data,
145 countfuzzy => !(C4::Context->preference('OPACShowUnusedAuthorities')),
146 total => $total,
147 from => $from,
148 to => $to,
149 resultcount => scalar @$results,
150 numbers => \@numbers,
151 authtypecode => $authtypecode,
152 authtypetext => $authtypes->{$authtypecode}{'authtypetext'},
153 isEDITORS => $authtypecode eq 'EDITORS',
157 else {
158 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
160 template_name => "opac-authorities-home.tmpl",
161 query => $query,
162 type => 'opac',
163 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
164 debug => 1,
170 $template->param( authtypesloop => \@authtypesloop );
172 # Print the page
173 output_html_with_http_headers $query, $cookie, $template->output;
175 # Local Variables:
176 # tab-width: 4
177 # End: