optimisation + encoding set.
[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     # format output
82     my $total = scalar @$marcresults;
83     my @newresults = searchResults( $query, $total, $results_per_page, $page, @$marcresults );
84     
85     $template->param(
86         total       => $total,
87         query       => $query,
88         resultsloop => \@newresults,
89         pagination_bar => pagination_bar(
90                                 "/cgi-bin/koha/cataloguing/addbooks.pl?q=$query&",
91                                  getnbpages( $total, $results_per_page ),
92                 $page,
93                         'page'
94                 ),
95     );
96 }
97
98 # fill with books in breeding farm
99 my $toggle = 0;
100 my ( $title, $isbn );
101
102 # fill isbn or title, depending on what has been entered
103 #u must do check on isbn because u can find number in beginning of title
104 #check is on isbn legnth 13 for new isbn and 10 for old isbn
105 my $querylength = length($query);
106 if ( $query =~ /\d/ and ( $querylength eq 13 or $querylength eq 10 ) ) {
107     $isbn = $query;
108 }
109 $title = $query unless $isbn;
110 my ( $countbr, @resultsbr ) = BreedingSearch( $title, $isbn ) if $query;
111 my @breeding_loop = ();
112 for ( my $i = 0 ; $i <= $#resultsbr ; $i++ ) {
113     my %row_data;
114     if ( $i % 2 ) {
115         $toggle = 0;
116     }
117     else {
118         $toggle = 1;
119     }
120     $row_data{toggle} = $toggle;
121     $row_data{id}     = $resultsbr[$i]->{'id'};
122     $row_data{isbn}   = $resultsbr[$i]->{'isbn'};
123     $row_data{file}   = $resultsbr[$i]->{'file'};
124     $row_data{title}  = $resultsbr[$i]->{'title'};
125     $row_data{author} = $resultsbr[$i]->{'author'};
126     push( @breeding_loop, \%row_data );
127 }
128
129 $template->param(
130     frameworkcodeloop => \@frameworkcodeloop,
131     breeding_loop     => \@breeding_loop,
132 );
133
134 output_html_with_http_headers $input, $cookie, $template->output;