adding a XMLgetbiblio in Biblio.pm (1st draft, to use with zebra)
[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 C4::Breeding;
31 use HTML::Template;
32 use MARC::File::USMARC;
33
34 use vars qw( $tagslib );
35 use vars qw( $is_a_modif );
36
37
38 my $input = new CGI;
39 my $dbh = C4::Context->dbh;
40 my $error = $input->param('error');
41 my $bibid=$input->param('bibid');
42 my $title = $input->param('title');
43 my $author = $input->param('author');
44 my $isbn = $input->param('isbn');
45 my $issn = $input->param('issn');
46 my $random = $input->param('random');
47 my @results;
48 my $count;
49 my $toggle;
50
51 my $record;
52 my $oldbiblio;
53 if ($bibid > 0) {
54         $record = MARCgetbiblio($dbh,$bibid);
55         $oldbiblio = MARCmarc2koha($dbh,$record);
56 }
57 my $errmsg;
58 unless ($random) { # if random is a parameter => we're just waiting for the search to end, it's a refresh.
59         if ($isbn) {
60                 $random =rand(1000000000);
61                 $errmsg = addz3950queue($isbn, "isbn", $random, 'CHECKED');
62         } elsif ($author) {
63                 $random =rand(1000000000);
64                 $errmsg = addz3950queue($author, "author", $random, 'CHECKED');
65         } elsif ($title) {
66                 $random =rand(1000000000);
67                 $errmsg = addz3950queue($title, "title", $random, 'CHECKED');
68         }
69 }
70 my ($template, $loggedinuser, $cookie)
71 = get_template_and_user({template_name => "z3950/searchresult.tmpl",
72                                 query => $input,
73                                 type => "intranet",
74                                 authnotrequired => 0,
75                                 flagsrequired => {catalogue => 1},
76                                 debug => 1,
77                                 });
78
79 # fill with books in breeding farm
80 ($count, @results) = BreedingSearch($title,$isbn,$random);
81 my $numberpending= &checkz3950searchdone($random);
82 my @breeding_loop = ();
83 for (my $i=0; $i <= $#results; $i++) {
84         my %row_data;
85         if ($i % 2) {
86                 $toggle="#ffffcc";
87         } else {
88                 $toggle="white";
89         }
90         $row_data{toggle} = $toggle;
91         $row_data{id} = $results[$i]->{'id'};
92         $row_data{isbn} = $results[$i]->{'isbn'};
93         $row_data{file} = $results[$i]->{'file'};
94         $row_data{title} = $results[$i]->{'title'};
95         $row_data{author} = $results[$i]->{'author'};
96         push (@breeding_loop, \%row_data);
97 }
98
99 $template->param(isbn => $isbn,
100                                                 title => $title,
101                                                 author => $author,
102                                                 breeding_loop => \@breeding_loop,
103                                                 refresh => ($numberpending eq 0 ? 0 : "search.pl?bibid=$bibid&random=$random"),
104                                                 numberpending => $numberpending,
105                                                 oldbiblionumber => $oldbiblio->{'biblionumber'},
106                                                 );
107
108 print $input->header(
109 -type => guesstype($template->output),
110 -cookie => $cookie
111 ),$template->output;