Don't extract purely-numeric strings like "1" either
[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 if ($bibid > 0) {
53         $record = MARCgetbiblio($dbh,$bibid);
54         $oldbiblio = MARCmarc2koha($dbh,$record);
55 }
56 my $errmsg;
57 unless ($random) { # if random is a parameter => we're just waiting for the search to end, it's a refresh.
58         if ($isbn) {
59                 $random =rand(1000000000);
60                 $errmsg = addz3950queue($isbn, "isbn", $random, 'CHECKED');
61         } elsif ($author) {
62                 $random =rand(1000000000);
63                 $errmsg = addz3950queue($author, "author", $random, 'CHECKED');
64         } elsif ($title) {
65                 $random =rand(1000000000);
66                 $errmsg = addz3950queue($title, "title", $random, 'CHECKED');
67         }
68 }
69 my ($template, $loggedinuser, $cookie)
70 = get_template_and_user({template_name => "z3950/searchresult.tmpl",
71                                 query => $input,
72                                 type => "intranet",
73                                 authnotrequired => 0,
74                                 flagsrequired => {catalogue => 1},
75                                 debug => 1,
76                                 });
77
78 # fill with books in breeding farm
79 ($count, @results) = breedingsearch($title,$isbn,$random);
80 my $numberpending= &checkz3950searchdone($random);
81 my @breeding_loop = ();
82 for (my $i=0; $i <= $#results; $i++) {
83         my %row_data;
84         if ($i % 2) {
85                 $toggle="#ffffcc";
86         } else {
87                 $toggle="white";
88         }
89         $row_data{toggle} = $toggle;
90         $row_data{id} = $results[$i]->{'id'};
91         $row_data{isbn} = $results[$i]->{'isbn'};
92         $row_data{file} = $results[$i]->{'file'};
93         $row_data{title} = $results[$i]->{'title'};
94         $row_data{author} = $results[$i]->{'author'};
95         push (@breeding_loop, \%row_data);
96 }
97
98 $template->param(isbn => $isbn,
99                                                 title => $title,
100                                                 author => $author,
101                                                 breeding_loop => \@breeding_loop,
102                                                 refresh => ($numberpending eq 0 ? 0 : "search.pl?bibid=$bibid&random=$random"),
103                                                 numberpending => $numberpending,
104                                                 oldbiblionumber => $oldbiblio->{'biblionumber'},
105                                                 );
106
107 print $input->header(
108 -type => guesstype($template->output),
109 -cookie => $cookie
110 ),$template->output;