Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
[koha.git] / acqui.simple / isbnsearch.pl
1 #!/usr/bin/perl
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA  02111-1307 USA
20
21 use strict;
22 use CGI;
23 use C4::Auth;
24 use C4::Catalogue;
25 use C4::Biblio;
26 use C4::Search;
27 use C4::Output;
28 use C4::Interface::CGI::Output;
29 use HTML::Template;
30
31 my $input      = new CGI;
32 my $isbn       = $input->param('isbn');
33 my $title               = $input->param('title');
34 my $offset     = $input->param('offset');
35 my $num        = $input->param('num');
36 my $showoffset = $offset + 1;
37 my $total;
38 my $count;
39 my @results;
40 my ($template, $loggedinuser, $cookie)
41     = get_template_and_user({template_name => "acqui.simple/isbnsearch.tmpl",
42                              query => $input,
43                              type => "intranet",
44                              authnotrequired => 0,
45                              flagsrequired => {catalogue => 1},
46                              debug => 1,
47                              });
48 if (! $isbn && !$title) {
49         print $input->redirect('addbooks.pl');
50 } else {
51         # fill with books in ACTIVE DB (biblio)
52         if (! $offset) {
53                 $offset     = 0;
54                 $showoffset = 1;
55         };
56         if (! $num) { $num = 10 };
57         ($count, @results) = isbnsearch($isbn,$title);
58
59         if ($count < ($offset + $num)) {
60                 $total = $count;
61         } else {
62                 $total = $offset + $num;
63         } # else
64
65         my @loop_data = ();
66         my $toggle;
67         for (my $i = $offset; $i < $total; $i++) {
68                 if ($i % 2) {
69                         $toggle="#ffffcc";
70                 } else {
71                         $toggle="white";
72                 }
73                 my %row_data;  # get a fresh hash for the row data
74                 $row_data{toggle} = $toggle;
75                 $row_data{biblionumber} =$results[$i]->{'biblionumber'};
76                 $row_data{title} = $results[$i]->{'title'};
77                 $row_data{author} = $results[$i]->{'author'};
78                 $row_data{copyrightdate} = $results[$i]->{'copyrightdate'};
79                 push(@loop_data, \%row_data);
80         }
81         my @loop_links = ();
82         for (my $i = 0; ($i * $num) < $count; $i++) {
83                 my %row_data;
84                 $row_data{newoffset} = $i * $num;
85                 $row_data{shownumber} = $i + 1;
86                 $row_data{num} = $num;
87                 push (@loop_links,\%row_data);
88         } # for
89         # fill with books in breeding farm
90         ($count, @results) = breedingsearch($title,$isbn);
91         my @breeding_loop = ();
92         for (my $i=0; $i <= $#results; $i++) {
93                 my %row_data;
94                 $row_data{id} = $results[$i]->{'id'};
95                 $row_data{isbn} = $results[$i]->{'isbn'};
96                 $row_data{file} = $results[$i]->{'file'};
97                 $row_data{title} = $results[$i]->{'title'};
98                 $row_data{author} = $results[$i]->{'author'};
99                 push (@breeding_loop, \%row_data);
100         }
101         $template->param(isbn => $isbn,
102                                                         showoffset => $showoffset,
103                                                         total => $total,
104                                                         offset => $offset,
105                                                         loop => \@loop_data,
106                                                         breeding_loop => \@breeding_loop,
107                                                         loop_links => \@loop_links);
108
109         print $input->header(
110             -type => guesstype($template->output),
111             -cookie => $cookie
112         ),$template->output;
113 } # else