Bug 32817: Fix cataloguing/value_builder/dateaccessioned.pl
[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 qw( get_template_and_user );
24 use C4::Output qw( output_html_with_http_headers );
25 use C4::Context;
26 use C4::Breeding qw( Z3950Search Z3950SearchAuth );
27 use MARC::Record;
28 use Koha::Authorities;
29 use Koha::Authority::Types;
30 use C4::AuthoritiesMarc qw( GetAuthority );
31
32 my $input        = CGI->new;
33 my $dbh          = C4::Context->dbh;
34 my $error         = $input->param('error');
35 my $authid  = $input->param('authid') || 0;
36
37 my $record         = GetAuthority($authid);
38 my $marc_flavour = C4::Context->preference('marcflavour');
39 my $authfields_mapping = {
40     'authorpersonal'   => $marc_flavour eq 'MARC21' ? '100' : '200',
41     'authorcorp'       => $marc_flavour eq 'MARC21' ? '110' : '210',
42     'authormeetingcon' => $marc_flavour eq 'MARC21' ? '111' : '210',
43     'uniformtitle'     => $marc_flavour eq 'MARC21' ? '130' : '230',
44     'subject'          => $marc_flavour eq 'MARC21' ? '150' : '250',
45 };
46
47 my $nameany     = $input->param('nameany');
48 my $authorany     = $input->param('authorany');
49 my $authorcorp =
50     $record
51   ? $record->subfield( $authfields_mapping->{'authorcorp'}, 'a' )
52   : $input->param('authorcorp');
53 my $authorpersonal =
54     $record
55   ? $record->subfield( $authfields_mapping->{'authorpersonal'}, 'a' )
56   : $input->param('authorpersonal');
57 my $authormeetingcon =
58     $record
59   ? $record->subfield( $authfields_mapping->{'authormeetingcon'}, 'a' )
60   : $input->param('authormeetingcon');
61
62 my $title         = $input->param('title');
63 my $uniformtitle =
64     $record
65   ? $record->subfield( $authfields_mapping->{'uniformtitle'}, 'a' )
66   : $input->param('uniformtitle');
67 my $subject =
68     $record
69   ? $record->subfield( $authfields_mapping->{'subject'}, 'a' )
70   : $input->param('subject');
71
72 my $subjectsubdiv       = $input->param('subjectsubdiv');
73 my $srchany       = $input->param('srchany');
74 my $op            = $input->param('op')||'';
75 my $page            = $input->param('current_page') || 1;
76 my $index =$input->param('index');
77 $page = $input->param('goto_page') if $input->param('changepage_goto');
78 my $controlnumber    = $input->param('controlnumber');
79
80 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
81         template_name   => "cataloguing/z3950_auth_search.tt",
82         query           => $input,
83         type            => "intranet",
84         flagsrequired   => { catalogue => 1 },
85 });
86
87 $template->param(
88     nameany    => $nameany,
89     authorany    => $authorany,
90     authorcorp    => $authorcorp,
91     authorpersonal    => $authorpersonal,
92     authormeetingcon    => $authormeetingcon,
93     title        => $title,
94     uniformtitle      => $uniformtitle,
95     subject      => $subject,
96     subjectsubdiv   => $subjectsubdiv,
97     srchany      => $srchany,
98     authid => $authid,
99     controlnumber => $controlnumber,
100     index => $index,
101 );
102
103 if ( $op ne "do_search" ) {
104     my $sth = $dbh->prepare("SELECT id,host,servername,checked FROM z3950servers WHERE recordtype = 'authority' ORDER BY `rank`, servername");
105     $sth->execute();
106     my $serverloop = $sth->fetchall_arrayref( {} );
107     $template->param(
108         serverloop   => $serverloop,
109         opsearch     => "search",
110         index        => $index,
111     );
112     output_html_with_http_headers $input, $cookie, $template->output;
113     exit;
114 }
115
116 my @id = $input->multi_param('id');
117 if ( @id==0 ) {
118         # empty server list -> report and exit
119         $template->param( emptyserverlist => 1 );
120         output_html_with_http_headers $input, $cookie, $template->output;
121         exit;
122 }
123
124 my $pars= {
125         page => $page,
126         id => \@id,
127         nameany => $nameany,
128         authorany => $authorany,
129         authorcorp => $authorcorp,
130         authorpersonal => $authorpersonal,
131         authormeetingcon => $authormeetingcon,
132         title => $title,
133         uniformtitle => $uniformtitle,
134         subject => $subject,
135         subjectsubdiv => $subjectsubdiv,
136         srchany => $srchany,
137         authid => $authid,
138         controlnumber => $controlnumber,
139 };
140 Z3950SearchAuth($pars, $template);
141 output_html_with_http_headers $input, $cookie, $template->output;