Bug 28230: Regression tests
[koha.git] / cataloguing / z3950_auth_search.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Copyright 2013 Prosentient Systems
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, see <http://www.gnu.org/licenses>.
18
19 use Modern::Perl;
20
21 use CGI qw / -utf8 /;
22
23 use C4::Auth;
24 use C4::Output;
25 use C4::Context;
26 use C4::Breeding;
27 use C4::Koha;
28
29 my $input        = CGI->new;
30 my $dbh          = C4::Context->dbh;
31 my $error         = $input->param('error');
32 my $authid  = $input->param('authid') || 0;
33 my $nameany     = $input->param('nameany');
34 my $authorany     = $input->param('authorany');
35 my $authorcorp     = $input->param('authorcorp');
36 my $authorpersonal     = $input->param('authorpersonal');
37 my $authormeetingcon     = $input->param('authormeetingcon');
38 my $title         = $input->param('title');
39 my $uniformtitle         = $input->param('uniformtitle');
40 my $subject       = $input->param('subject');
41 my $subjectsubdiv       = $input->param('subjectsubdiv');
42 my $srchany       = $input->param('srchany');
43 my $op            = $input->param('op')||'';
44 my $page            = $input->param('current_page') || 1;
45 my $index =$input->param('index');
46 $page = $input->param('goto_page') if $input->param('changepage_goto');
47 my $controlnumber    = $input->param('controlnumber');
48
49 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
50         template_name   => "cataloguing/z3950_auth_search.tt",
51         query           => $input,
52         type            => "intranet",
53         flagsrequired   => { catalogue => 1 },
54 });
55
56 $template->param(
57     nameany    => $nameany,
58     authorany    => $authorany,
59     authorcorp    => $authorcorp,
60     authorpersonal    => $authorpersonal,
61     authormeetingcon    => $authormeetingcon,
62     title        => $title,
63     uniformtitle      => $uniformtitle,
64     subject      => $subject,
65     subjectsubdiv   => $subjectsubdiv,
66     srchany      => $srchany,
67     authid => $authid,
68     controlnumber => $controlnumber,
69     index => $index,
70 );
71
72 if ( $op ne "do_search" ) {
73     my $sth = $dbh->prepare("SELECT id,host,servername,checked FROM z3950servers WHERE recordtype = 'authority' ORDER BY `rank`, servername");
74     $sth->execute();
75     my $serverloop = $sth->fetchall_arrayref( {} );
76     $template->param(
77         serverloop   => $serverloop,
78         opsearch     => "search",
79         index        => $index,
80     );
81     output_html_with_http_headers $input, $cookie, $template->output;
82     exit;
83 }
84
85 my @id = $input->multi_param('id');
86 if ( @id==0 ) {
87         # empty server list -> report and exit
88         $template->param( emptyserverlist => 1 );
89         output_html_with_http_headers $input, $cookie, $template->output;
90         exit;
91 }
92
93 my $pars= {
94         page => $page,
95         id => \@id,
96         nameany => $nameany,
97         authorany => $authorany,
98         authorcorp => $authorcorp,
99         authorpersonal => $authorpersonal,
100         authormeetingcon => $authormeetingcon,
101         title => $title,
102         uniformtitle => $uniformtitle,
103         subject => $subject,
104         subjectsubdiv => $subjectsubdiv,
105         srchany => $srchany,
106         authid => $authid,
107         controlnumber => $controlnumber,
108 };
109 Z3950SearchAuth($pars, $template);
110 output_html_with_http_headers $input, $cookie, $template->output;