moving localfiles to tmp
[koha.git] / cataloguing / addbooks.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 =head1 cataloguing:addbooks.pl
22
23         TODO
24
25 =cut
26
27 use strict;
28 use CGI;
29 use C4::Auth;
30 use C4::Biblio;
31 use C4::Breeding;
32 use C4::Output;
33 use C4::Koha;
34 use C4::Search;
35
36 my $input = new CGI;
37
38 my $success = $input->param('biblioitem');
39 my $query   = $input->param('q');
40 my @value   = $input->param('value');
41 my $page    = $input->param('page') || 1;
42 my $results_per_page = 20;
43
44
45 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
46     {
47         template_name   => "cataloguing/addbooks.tmpl",
48         query           => $input,
49         type            => "intranet",
50         authnotrequired => 0,
51         flagsrequired   => { editcatalogue => 1 },
52         debug           => 1,
53     }
54 );
55
56 # get framework list
57 my $frameworks = getframeworks;
58 my @frameworkcodeloop;
59 foreach my $thisframeworkcode ( keys %$frameworks ) {
60     my %row = (
61         value         => $thisframeworkcode,
62         frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
63     );
64     push @frameworkcodeloop, \%row;
65 }
66
67 # Searching the catalog.
68 if ($query) {
69
70     # find results
71     my ( $error, $marcresults ) = SimpleSearch($query);
72
73     if ( defined $error ) {
74         $template->param( error => $error );
75         warn "error: " . $error;
76         output_html_with_http_headers $input, $cookie, $template->output;
77         exit;
78     }
79     
80         if(not defined $marcresults){
81                 $template->param(query => $query);
82                 warn "no result found";
83                 output_html_with_http_headers $input, $cookie, $template->output;
84         exit;
85         }
86
87     # format output
88     my $total = scalar @$marcresults;
89     my @newresults = searchResults( $query, $total, $results_per_page, $page-1, @$marcresults );
90     $template->param(
91         total       => $total,
92         query       => $query,
93         resultsloop => \@newresults,
94         pagination_bar => pagination_bar(
95                                 "/cgi-bin/koha/cataloguing/addbooks.pl?q=$query&",
96                                  getnbpages( $total, $results_per_page ),
97                 $page,
98                         'page'
99                 ),
100     );
101 }
102
103 # fill with books in breeding farm
104 my $toggle = 0;
105 my ( $title, $isbn );
106
107 # fill isbn or title, depending on what has been entered
108 #u must do check on isbn because u can find number in beginning of title
109 #check is on isbn legnth 13 for new isbn and 10 for old isbn
110 my $querylength = length($query);
111 if ( $query =~ /\d/ and ( $querylength eq 13 or $querylength eq 10 ) ) {
112     $isbn = $query;
113 }
114 $title = $query unless $isbn;
115 my ( $countbr, @resultsbr ) = BreedingSearch( $title, $isbn ) if $query;
116 my @breeding_loop = ();
117 for ( my $i = 0 ; $i <= $#resultsbr ; $i++ ) {
118     my %row_data;
119     if ( $i % 2 ) {
120         $toggle = 0;
121     }
122     else {
123         $toggle = 1;
124     }
125     $row_data{toggle} = $toggle;
126     $row_data{id}     = $resultsbr[$i]->{'id'};
127     $row_data{isbn}   = $resultsbr[$i]->{'isbn'};
128     $row_data{file}   = $resultsbr[$i]->{'file'};
129     $row_data{title}  = $resultsbr[$i]->{'title'};
130     $row_data{author} = $resultsbr[$i]->{'author'};
131     push( @breeding_loop, \%row_data );
132 }
133
134 $template->param(
135     frameworkcodeloop => \@frameworkcodeloop,
136     breeding_loop     => \@breeding_loop,
137 );
138
139 output_html_with_http_headers $input, $cookie, $template->output;