Bug 10462: Some optimizations in Z3950 search paving the way for enhancements
[koha.git] / acqui / z3950_search.pl
1 #!/usr/bin/perl
2
3 # This is a completely new Z3950 clients search using async ZOOM -TG 02/11/06
4 # Copyright 2000-2002 Katipo Communications
5 # Copyright 2010 Catalyst IT
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22 use warnings;
23 use strict;
24 use CGI qw/-utf8/;
25
26 use C4::Auth;
27 use C4::Output;
28 use C4::Context;
29 use C4::Breeding;
30 use C4::Koha;
31 use C4::Bookseller qw/ GetBookSellerFromId /;
32
33 my $input           = new CGI;
34 my $dbh             = C4::Context->dbh;
35 my $biblionumber    = $input->param('biblionumber')||0;
36 my $frameworkcode   = $input->param('frameworkcode')||'';
37 my $title           = $input->param('title');
38 my $author          = $input->param('author');
39 my $isbn            = $input->param('isbn');
40 my $issn            = $input->param('issn');
41 my $lccn            = $input->param('lccn');
42 my $lccall          = $input->param('lccall');
43 my $subject         = $input->param('subject');
44 my $dewey           = $input->param('dewey');
45 my $controlnumber   = $input->param('controlnumber');
46 my $op              = $input->param('op')||'';
47 my $booksellerid    = $input->param('booksellerid');
48 my $basketno        = $input->param('basketno');
49 my $page            = $input->param('current_page') || 1;
50 $page               = $input->param('goto_page') if $input->param('changepage_goto');
51
52 # get framework list
53 my $frameworks = getframeworks;
54 my @frameworkcodeloop;
55 foreach my $thisframeworkcode ( keys %$frameworks ) {
56     my %row = (
57         value         => $thisframeworkcode,
58         frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
59     );
60     if ( $row{'value'} eq $frameworkcode){
61         $row{'active'} = 'true';
62     }
63     push @frameworkcodeloop, \%row;
64 }
65
66 my $vendor = GetBookSellerFromId($booksellerid);
67
68 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
69     {
70         template_name   => "acqui/z3950_search.tmpl",
71         query           => $input,
72         type            => "intranet",
73         authnotrequired => 1,
74         flagsrequired   => { acquisition => 'order_manage' },
75     }
76 );
77 $template->param(
78         frameworkcode => $frameworkcode,
79         frameworkcodeloop => \@frameworkcodeloop,
80         booksellerid => $booksellerid,
81         basketno     => $basketno,
82         name         => $vendor->{'name'},
83         isbn         => $isbn,
84         issn         => $issn,
85         lccn         => $lccn,
86         lccall       => $lccall,
87         title        => $title,
88         author       => $author,
89         controlnumber=> $controlnumber,
90         biblionumber => $biblionumber,
91         dewey        => $dewey,
92         subject      => $subject,
93 );
94
95 if ( $op ne "do_search" ) {
96     my $sth = $dbh->prepare("select id,host,name,checked from z3950servers  order by host");
97     $sth->execute();
98     my $serverloop = $sth->fetchall_arrayref( {} );
99     $template->param(
100         serverloop   => $serverloop,
101         opsearch     => "search",
102     );
103     output_html_with_http_headers $input, $cookie, $template->output;
104     exit;
105 }
106
107 my @id = $input->param('id');
108 if (@id==0) {
109     $template->param( emptyserverlist => 1 );
110     output_html_with_http_headers $input, $cookie, $template->output;
111     exit;
112 }
113
114 my $pars= {
115         biblionumber => $biblionumber,
116         page => $page,
117         id => \@id,
118         isbn => $isbn,
119         issn => $issn,
120         title => $title,
121         author => $author,
122         dewey => $dewey,
123         subject => $subject,
124         lccall => $lccall,
125         controlnumber => $controlnumber,
126         stdid => 0,
127         srchany => 0,
128 };
129 Z3950Search($pars, $template);
130 output_html_with_http_headers $input, $cookie, $template->output;