[followup](bug #4062) marc21 item support
[koha.git] / opac / opac-authorities-home.pl
1 #!/usr/bin/perl
2 # WARNING: 4-character tab stops here
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
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.
12 #
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.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA  02111-1307 USA
20
21 use strict;
22 use warnings;
23
24 use CGI;
25 use C4::Auth;
26
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
32
33 my $query        = new CGI;
34 my $op           = $query->param('op') || '';
35 my $authtypecode = $query->param('authtypecode') || '';
36 my $dbh          = C4::Context->dbh;
37
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;
43
44 my $authtypes = getauthtypes;
45 my @authtypesloop;
46 foreach my $thisauthtype ( sort { $authtypes->{$a}{'authtypetext'} cmp $authtypes->{$b}{'authtypetext'} }
47     keys %$authtypes )
48 {
49     my $selected = 1 if $thisauthtype eq $authtypecode;
50     my %row = (
51         value        => $thisauthtype,
52         selected     => $selected,
53         authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
54     );
55     push @authtypesloop, \%row;
56 }
57
58 if ( $op eq "do_search" ) {
59     my @marclist = ($query->param('marclista'),$query->param('marclistb'),$query->param('marclistc'));
60     my @and_or = ($query->param('and_ora'),$query->param('and_orb'),$query->param('and_orc'));
61     my @excluding = ($query->param('excludinga'),$query->param('excludingb'),$query->param('excludingc'),);
62     my @operator = ($query->param('operatora'),$query->param('operatorb'),$query->param('operatorc'));
63     my $orderby = $query->param('orderby');
64     my @value = ($query->param('valuea') || "",$query->param('valueb') || "",$query->param('valuec') || "",);
65
66     $resultsperpage = $query->param('resultsperpage');
67     $resultsperpage = 20 if ( !defined $resultsperpage );
68     my @tags;
69     my ( $results, $total, @fields ) =
70       SearchAuthorities( \@marclist, \@and_or, \@excluding, \@operator,
71         \@value, $startfrom * $resultsperpage,
72         $resultsperpage, $authtypecode, $orderby );
73     ( $template, $loggedinuser, $cookie ) = get_template_and_user(
74         {
75             template_name   => "opac-authoritiessearchresultlist.tmpl",
76             query           => $query,
77             type            => 'opac',
78             authnotrequired => 1,
79             debug           => 1,
80         }
81     );
82
83     # multi page display gestion
84     my $displaynext = 0;
85     my $displayprev = $startfrom;
86     if ( ( $total - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
87         $displaynext = 1;
88     }
89
90     my @field_data = ();
91
92     foreach my $letter (qw/a b c/){
93         push @field_data, { term => "marclist$letter" , val => $query->param("marclist$letter") || ''};
94         push @field_data, { term => "and_or$letter" , val => $query->param("and_or$letter") || ''};
95         push @field_data, { term => "excluding$letter" , val => $query->param("excluding$letter") || ''};
96         push @field_data, { term => "operator$letter" , val => $query->param("operator$letter") || ''};
97         push @field_data, { term => "value$letter" , val => $query->param("value$letter") || ''};
98     }
99
100     my @numbers = ();
101
102     if ( $total > $resultsperpage ) {
103         for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
104             if ( $i < 16 ) {
105                 my $highlight = 0;
106                 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
107                 push @numbers,
108                   {
109                     number     => $i,
110                     highlight  => $highlight,
111                     searchdata => \@field_data,
112                     startfrom  => ( $i - 1 )
113                   };
114             }
115         }
116     }
117
118     my $from = $startfrom * $resultsperpage + 1;
119     my $to;
120
121     if ( $total < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
122         $to = $total;
123     }
124     else {
125         $to = ( ( $startfrom + 1 ) * $resultsperpage );
126     }
127     $template->param( result => $results ) if $results;
128     $template->param( FIELDS => \@fields );
129     $template->param( orderby => $orderby );
130     $template->param(
131         startfrom      => $startfrom,
132         displaynext    => $displaynext,
133         displayprev    => $displayprev,
134         resultsperpage => $resultsperpage,
135         startfromnext  => $startfrom + 1,
136         startfromprev  => $startfrom - 1,
137         searchdata     => \@field_data,
138         total          => $total,
139         from           => $from,
140         to             => $to,
141         numbers        => \@numbers,
142         authtypecode   => $authtypecode,
143         isEDITORS      => $authtypecode eq 'EDITORS',
144     );
145
146 }
147 else {
148     ( $template, $loggedinuser, $cookie ) = get_template_and_user(
149         {
150             template_name   => "opac-authorities-home.tmpl",
151             query           => $query,
152             type            => 'opac',
153             authnotrequired => 1,
154             debug           => 1,
155         }
156     );
157
158 }
159
160 $template->param( authtypesloop => \@authtypesloop );
161
162 # Print the page
163 output_html_with_http_headers $query, $cookie, $template->output;
164
165 # Local Variables:
166 # tab-width: 4
167 # End: