adding isbn/author/title support (forgot to commit those...)
[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 $author = $input->param('author');
43 my $isbn = $input->param('isbn');
44 my $issn = $input->param('issn');
45 my $random = $input->param('random');
46 my @results;
47 my $count;
48 my $toggle;
49
50 my $record;
51 my $oldbiblio;
52 warn "search.pl : $bibid / $title / $author / $isbn";
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 warn "NO RANDOM";
60         if ($isbn) {
61         warn "ADD ISBN $isbn";
62                 $random =rand(1000000000);
63                 $errmsg = addz3950queue($isbn, "isbn", $random, 'CHECKED');
64         } elsif ($author) {
65         warn "ADD AUTHOR $author";
66                 $random =rand(1000000000);
67                 $errmsg = addz3950queue($author, "author", $random, 'CHECKED');
68         } elsif ($title) {
69         warn "ADD TITLE : $title";
70                 $random =rand(1000000000);
71                 $errmsg = addz3950queue($title, "title", $random, 'CHECKED');
72         }
73 }
74 my ($template, $loggedinuser, $cookie)
75 = get_template_and_user({template_name => "z3950/searchresult.tmpl",
76                                 query => $input,
77                                 type => "intranet",
78                                 authnotrequired => 0,
79                                 flagsrequired => {catalogue => 1},
80                                 debug => 1,
81                                 });
82
83 # fill with books in breeding farm
84 ($count, @results) = breedingsearch($title,$isbn,$random);
85 my $numberpending= &checkz3950searchdone($random);
86 my @breeding_loop = ();
87 for (my $i=0; $i <= $#results; $i++) {
88         my %row_data;
89         if ($i % 2) {
90                 $toggle="#ffffcc";
91         } else {
92                 $toggle="white";
93         }
94         $row_data{toggle} = $toggle;
95         $row_data{id} = $results[$i]->{'id'};
96         $row_data{isbn} = $results[$i]->{'isbn'};
97         $row_data{file} = $results[$i]->{'file'};
98         $row_data{title} = $results[$i]->{'title'};
99         $row_data{author} = $results[$i]->{'author'};
100         push (@breeding_loop, \%row_data);
101 }
102
103 $template->param(isbn => $isbn,
104                                                 title => $title,
105                                                 author => $author,
106                                                 breeding_loop => \@breeding_loop,
107                                                 refresh => ($numberpending eq 0 ? 0 : "search.pl?bibid=$bibid&random=$random"),
108                                                 numberpending => $numberpending,
109                                                 oldbiblionumber => $oldbiblio->{'biblionumber'},
110                                                 );
111
112 print $input->header(
113 -type => guesstype($template->output),
114 -cookie => $cookie
115 ),$template->output;