really proud of this commit :-)
[koha.git] / z3950 / search.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
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 2 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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20 use strict;
21 use CGI;
22 use C4::Auth;
23 use C4::Output;
24 use C4::Interface::CGI::Output;
25 use C4::Biblio;
26 use C4::Context;
27 use C4::Koha; # XXX subfield_is_koha_internal_p
28 use C4::Z3950;
29 use C4::Search;
30 use HTML::Template;
31 use MARC::File::USMARC;
32
33 use vars qw( $tagslib );
34 use vars qw( $is_a_modif );
35
36
37 my $input = new CGI;
38 my $dbh = C4::Context->dbh;
39 my $error = $input->param('error');
40 my $bibid=$input->param('bibid');
41 my $title = $input->param('title');
42 my $isbn = $input->param('isbn');
43 my $issn = $input->param('issn');
44 my $random = $input->param('random');
45 my @results;
46 my $count;
47 my $toggle;
48
49 my $record;
50 my $oldbiblio;
51 if ($bibid) {
52         $record = MARCgetbiblio($dbh,$bibid);
53         $oldbiblio = MARCmarc2koha($dbh,$record);
54 }
55 $isbn = $oldbiblio->{'isbn'};
56 $issn = $oldbiblio->{'issn'};
57 $title = $oldbiblio->{'title'};
58 my $errmsg;
59 unless ($random) { # if random is a parameter => we're just waiting for the search to end, it's a refresh.
60         if ($isbn) {
61                 $random =rand(1000000000);
62                 $errmsg = addz3950queue($isbn, "isbn", $random, 'CHECKED');
63         }
64 }
65 my ($template, $loggedinuser, $cookie)
66 = get_template_and_user({template_name => "z3950/searchresult.tmpl",
67                                 query => $input,
68                                 type => "intranet",
69                                 authnotrequired => 0,
70                                 flagsrequired => {catalogue => 1},
71                                 debug => 1,
72                                 });
73
74 # fill with books in breeding farm
75 ($count, @results) = breedingsearch($title,$isbn,$random);
76 my $numberpending= &checkz3950searchdone($random);
77 my @breeding_loop = ();
78 for (my $i=0; $i <= $#results; $i++) {
79         my %row_data;
80         if ($i % 2) {
81                 $toggle="#ffffcc";
82         } else {
83                 $toggle="white";
84         }
85         $row_data{toggle} = $toggle;
86         $row_data{id} = $results[$i]->{'id'};
87         $row_data{isbn} = $results[$i]->{'isbn'};
88         $row_data{file} = $results[$i]->{'file'};
89         $row_data{title} = $results[$i]->{'title'};
90         $row_data{author} = $results[$i]->{'author'};
91         push (@breeding_loop, \%row_data);
92 }
93
94 $template->param(isbn => $isbn,
95                                                 title => $title,
96                                                 breeding_loop => \@breeding_loop,
97                                                 refresh => ($numberpending eq 0 ? 0 : "search.pl?bibid=$bibid&random=$random"),
98                                                 numberpending => $numberpending,
99                                                 oldbiblionumber => $oldbiblio->{'biblionumber'},
100                                                 );
101
102 print $input->header(
103 -type => guesstype($template->output),
104 -cookie => $cookie
105 ),$template->output;