3 # This file is part of Koha.
5 # Copyright 2013 Prosentient Systems
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
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.
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>.
23 use C4::Auth qw( get_template_and_user );
24 use C4::Output qw( output_html_with_http_headers );
26 use C4::Breeding qw( Z3950Search Z3950SearchAuth );
28 use Koha::Authorities;
29 use Koha::Authority::Types;
30 use C4::AuthoritiesMarc qw( GetAuthority );
33 my $dbh = C4::Context->dbh;
34 my $error = $input->param('error');
35 my $authid = $input->param('authid') || 0;
36 my $op = $input->param('op')||'';
38 my $record = GetAuthority($authid);
39 my $marc_flavour = C4::Context->preference('marcflavour');
40 my $authfields_mapping = {
41 'authorpersonal' => $marc_flavour eq 'MARC21' ? '100' : '200',
42 'authorcorp' => $marc_flavour eq 'MARC21' ? '110' : '210',
43 'authormeetingcon' => $marc_flavour eq 'MARC21' ? '111' : '210',
44 'uniformtitle' => $marc_flavour eq 'MARC21' ? '130' : '230',
45 'subject' => $marc_flavour eq 'MARC21' ? '150' : '250',
48 my $nameany = $input->param('nameany');
49 my $authorany = $input->param('authorany');
50 my $title = $input->param('title');
51 my $authorpersonal = $input->param('authorpersonal');
52 my $authormeetingcon = $input->param('authormeetingcon');
53 my $uniformtitle = $input->param('uniformtitle');
54 my $subject = $input->param('subject');
55 my $authorcorp = $input->param('authorcorp');
56 my $subjectsubdiv = $input->param('subjectsubdiv');
57 my $srchany = $input->param('srchany');
59 # If replacing an existing record we want to initially populate the form with record info,
60 # however, we want to use entered inputs when searching
61 if ( $record && $op ne 'do_search' ) {
63 $record->subfield( $authfields_mapping->{'authorcorp'}, 'a' );
65 $record->subfield( $authfields_mapping->{'authorpersonal'}, 'a' );
67 $record->subfield( $authfields_mapping->{'authormeetingcon'}, 'a' );
69 $record->subfield( $authfields_mapping->{'uniformtitle'}, 'a' );
70 $subject ||= $record->subfield( $authfields_mapping->{'subject'}, 'a' );
73 my $page = $input->param('current_page') || 1;
74 my $index =$input->param('index');
75 $page = $input->param('goto_page') if $input->param('changepage_goto');
76 my $controlnumber = $input->param('controlnumber');
78 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
79 template_name => "cataloguing/z3950_auth_search.tt",
82 flagsrequired => { catalogue => 1 },
87 authorany => $authorany,
88 authorcorp => $authorcorp,
89 authorpersonal => $authorpersonal,
90 authormeetingcon => $authormeetingcon,
92 uniformtitle => $uniformtitle,
94 subjectsubdiv => $subjectsubdiv,
97 controlnumber => $controlnumber,
101 if ( $op ne "do_search" ) {
102 my $sth = $dbh->prepare("SELECT id,host,servername,checked FROM z3950servers WHERE recordtype = 'authority' ORDER BY `rank`, servername");
104 my $serverloop = $sth->fetchall_arrayref( {} );
106 serverloop => $serverloop,
107 opsearch => "search",
110 output_html_with_http_headers $input, $cookie, $template->output;
114 my @id = $input->multi_param('id');
116 # empty server list -> report and exit
117 $template->param( emptyserverlist => 1 );
118 output_html_with_http_headers $input, $cookie, $template->output;
126 authorany => $authorany,
127 authorcorp => $authorcorp,
128 authorpersonal => $authorpersonal,
129 authormeetingcon => $authormeetingcon,
131 uniformtitle => $uniformtitle,
133 subjectsubdiv => $subjectsubdiv,
136 controlnumber => $controlnumber,
138 Z3950SearchAuth($pars, $template);
139 output_html_with_http_headers $input, $cookie, $template->output;