partial 1481: adding to templates, fixing non-display of data
[koha.git] / cataloguing / addbooks.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 # Copyright 2000-2002 Katipo Communications
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA  02111-1307 USA
21
22 =head1 cataloguing:addbooks.pl
23
24         TODO
25
26 =cut
27
28 use strict;
29 use CGI;
30 use C4::Auth;
31 use C4::Biblio;
32 use C4::Breeding;
33 use C4::Output;
34 use C4::Koha;
35 use C4::Search;
36
37 my $input = new CGI;
38
39 my $success = $input->param('biblioitem');
40 my $query   = $input->param('q');
41 my @value   = $input->param('value');
42 my $page    = $input->param('page') || 1;
43 my $results_per_page = 20;
44
45
46 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
47     {
48         template_name   => "cataloguing/addbooks.tmpl",
49         query           => $input,
50         type            => "intranet",
51         authnotrequired => 0,
52         flagsrequired   => { editcatalogue => 1 },
53         debug           => 1,
54     }
55 );
56
57 # get framework list
58 my $frameworks = getframeworks;
59 my @frameworkcodeloop;
60 foreach my $thisframeworkcode ( keys %$frameworks ) {
61     my %row = (
62         value         => $thisframeworkcode,
63         frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
64     );
65     push @frameworkcodeloop, \%row;
66 }
67
68 # Searching the catalog.
69 if ($query) {
70
71     # find results
72     my ( $error, $marcresults ) = SimpleSearch($query);
73
74     if ( defined $error ) {
75         $template->param( error => $error );
76         warn "error: " . $error;
77         output_html_with_http_headers $input, $cookie, $template->output;
78         exit;
79     }
80     
81         if(not defined $marcresults){
82                 $template->param(query => $query);
83                 warn "no result found";
84                 output_html_with_http_headers $input, $cookie, $template->output;
85         exit;
86         }
87
88     # format output
89     my $total = scalar @$marcresults;
90     my @newresults = searchResults( $query, $total, $results_per_page, $page-1, @$marcresults );
91     $template->param(
92         total       => $total,
93         query       => $query,
94         resultsloop => \@newresults,
95         pagination_bar => pagination_bar(
96                                 "/cgi-bin/koha/cataloguing/addbooks.pl?q=$query&",
97                                  getnbpages( $total, $results_per_page ),
98                 $page,
99                         'page'
100                 ),
101     );
102 }
103
104 # fill with books in breeding farm
105 my $toggle = 0;
106 my ( $title, $isbn );
107
108 # fill isbn or title, depending on what has been entered
109 #u must do check on isbn because u can find number in beginning of title
110 #check is on isbn legnth 13 for new isbn and 10 for old isbn
111 my $querylength = length($query);
112 if ( $query =~ /\d/ and ( $querylength eq 13 or $querylength eq 10 ) ) {
113     $isbn = $query;
114 }
115 $title = $query unless $isbn;
116 my ( $countbr, @resultsbr ) = BreedingSearch( $title, $isbn ) if $query;
117 my @breeding_loop = ();
118 for ( my $i = 0 ; $i <= $#resultsbr ; $i++ ) {
119     my %row_data;
120     if ( $i % 2 ) {
121         $toggle = 0;
122     }
123     else {
124         $toggle = 1;
125     }
126     $row_data{toggle} = $toggle;
127     $row_data{id}     = $resultsbr[$i]->{'id'};
128     $row_data{isbn}   = $resultsbr[$i]->{'isbn'};
129     $row_data{file}   = $resultsbr[$i]->{'file'};
130     $row_data{title}  = $resultsbr[$i]->{'title'};
131     $row_data{author} = $resultsbr[$i]->{'author'};
132     push( @breeding_loop, \%row_data );
133 }
134
135 $template->param(
136     frameworkcodeloop => \@frameworkcodeloop,
137     breeding_loop     => \@breeding_loop,
138 );
139
140 output_html_with_http_headers $input, $cookie, $template->output;