records appear in message body instead of in attached file
[koha.git] / acqui.simple / isbnsearch.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::Catalogue;
24 use C4::Biblio;
25 use C4::Search;
26 use C4::Output;
27 use C4::Interface::CGI::Output;
28 use HTML::Template;
29
30 my $input      = new CGI;
31 my $isbn       = $input->param('isbn');
32 my $title      = $input->param('title');
33 my $offset     = $input->param('offset');
34 my $num        = $input->param('num');
35 my $showoffset = $offset + 1;
36 my $total;
37 my $count;
38 my @results;
39 my $marc_p = C4::Context->boolean_preference("marc");
40
41 if ( !$isbn && !$title ) {
42     print $input->redirect('addbooks.pl');
43 }
44 else {
45     my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
46         {
47             template_name   => "acqui.simple/isbnsearch.tmpl",
48             query           => $input,
49             type            => "intranet",
50             authnotrequired => 0,
51             flagsrequired   => { catalogue => 1 },
52             debug           => 1,
53         }
54     );
55
56     # fill with books in ACTIVE DB (biblio)
57     if ( !$offset ) {
58         $offset     = 0;
59         $showoffset = 1;
60     }
61     if ( !$num ) { $num = 10 }
62     ( $count, @results ) = isbnsearch( $isbn, $title );
63
64     if ( $count < ( $offset + $num ) ) {
65         $total = $count;
66     }
67     else {
68         $total = $offset + $num;
69     }    # else
70
71     my @loop_data = ();
72     my $toggle;
73     for ( my $i = $offset ; $i < $total ; $i++ ) {
74         if ( $i % 2 ) {
75             $toggle = "#ffffcc";
76         }
77         else {
78             $toggle = "white";
79         }
80         my %row_data;    # get a fresh hash for the row data
81         $row_data{toggle}        = $toggle;
82         $row_data{biblionumber}  = $results[$i]->{'biblionumber'};
83         $row_data{title}         = $results[$i]->{'title'};
84         $row_data{author}        = $results[$i]->{'author'};
85         $row_data{copyrightdate} = $results[$i]->{'copyrightdate'};
86         $row_data{NOTMARC}       = !$marc_p;    
87         push ( @loop_data, \%row_data );
88     }
89     $template->param( startfrom => $offset + 1 );
90     ( $offset + $num <= $count )
91       ? ( $template->param( endat => $offset + $num ) )
92       : ( $template->param( endat => $count ) );
93     $template->param( numrecords => $count );
94     my $nextstartfrom = ( $offset + $num < $count ) ? ( $offset + $num ) : (-1);
95     my $prevstartfrom = ( $offset - $num >= 0 ) ? ( $offset - $num ) : (-1);
96     $template->param( nextstartfrom => $nextstartfrom );
97     my $displaynext = 1;
98     my $displayprev = 0;
99     ( $nextstartfrom == -1 ) ? ( $displaynext = 0 ) : ( $displaynext = 1 );
100     ( $prevstartfrom == -1 ) ? ( $displayprev = 0 ) : ( $displayprev = 1 );
101     $template->param( displaynext => $displaynext );
102     $template->param( displayprev => $displayprev );
103     my @numbers = ();
104     my $term;
105     my $value;
106
107     if ($isbn) {
108         $term  = "isbn";
109         $value = $isbn;
110     }
111     else {
112         $term  = "title";
113         $value = $title;
114     }
115     if ( $count > 10 ) {
116         for ( my $i = 1 ; $i < $count / 10 + 1 ; $i++ ) {
117             if ( $i < 16 ) {
118                 my $highlight = 0;
119                 ( $offset == ( $i - 1 ) * 10 ) && ( $highlight = 1 );
120                 push @numbers,
121                   {
122                     number    => $i,
123                     highlight => $highlight,
124                     term      => $term,
125                     value     => $value,
126                     startfrom => ( $i - 1 ) * 10
127                 };
128             }
129         }
130     }
131
132     # fill with books in breeding farm
133     ( $count, @results ) = breedingsearch( $title, $isbn );
134     my @breeding_loop = ();
135     for ( my $i = 0 ; $i <= $#results ; $i++ ) {
136         my %row_data;
137         if ( $i % 2 ) {
138             $toggle = "#ffffcc";
139         }
140         else {
141             $toggle = "white";
142         }
143         $row_data{toggle} = $toggle;
144         $row_data{id}     = $results[$i]->{'id'};
145         $row_data{isbn}   = $results[$i]->{'isbn'};
146         $row_data{file}   = $results[$i]->{'file'};
147         $row_data{title}  = $results[$i]->{'title'};
148         $row_data{author} = $results[$i]->{'author'};
149         $row_data{NOTMARC}= !$marc_p;   
150         push ( @breeding_loop, \%row_data );
151     }
152
153
154     $template->param(
155         isbn          => $isbn,
156         title         => $title,
157         showoffset    => $showoffset,
158         total         => $total,
159         offset        => $offset,
160         loop          => \@loop_data,
161         breeding_loop => \@breeding_loop,
162         numbers       => \@numbers,
163         term          => $term,
164         value         => $value,
165         NOTMARC       => !$marc_p
166     );
167
168     print $input->header(
169         -type   => guesstype( $template->output ),
170         -cookie => $cookie
171       ),
172       $template->output;
173 }    # else