Merge remote-tracking branch 'origin/new/bug_6448'
[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
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 =head1 cataloguing:addbooks.pl
22
23         TODO
24
25 =cut
26
27 use strict;
28 use warnings;
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 => '*' },
53         debug           => 1,
54     }
55 );
56
57 # get framework list
58 my $frameworks = getframeworks;
59 my @frameworkcodeloop;
60 foreach my $thisframeworkcode ( sort {$frameworks->{$a} cmp $frameworks->{$b}}keys %{$frameworks} ) {
61     push @frameworkcodeloop, {
62         value         => $thisframeworkcode,
63         frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
64     };
65 }
66
67
68 # Searching the catalog.
69 if ($query) {
70
71     # build query
72     my @operands = $query;
73     my ( $builterror,$builtquery,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = buildQuery(undef,\@operands);
74
75     # find results
76     my ( $error, $marcresults, $total_hits ) = SimpleSearch($builtquery, $results_per_page * ($page - 1), $results_per_page);
77
78     if ( defined $error ) {
79         $template->param( error => $error );
80         warn "error: " . $error;
81         output_html_with_http_headers $input, $cookie, $template->output;
82         exit;
83     }
84
85     # format output
86     # SimpleSearch() give the results per page we want, so 0 offet here
87     my $total = @{$marcresults};
88     my @newresults = searchResults( 'intranet', $query, $total, $results_per_page, 0, 0, $marcresults );
89     foreach my $line (@newresults) {
90         if ( not exists $line->{'size'} ) { $line->{'size'} = "" }
91     }
92     $template->param(
93         total          => $total_hits,
94         query          => $query,
95         resultsloop    => \@newresults,
96         pagination_bar => pagination_bar( "/cgi-bin/koha/cataloguing/addbooks.pl?q=$query&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
97     );
98 }
99
100 # fill with books in breeding farm
101
102 my $countbr = 0;
103 my @resultsbr;
104 if ($query) {
105 # fill isbn or title, depending on what has been entered
106 #u must do check on isbn because u can find number in beginning of title
107 #check is on isbn legnth 13 for new isbn and 10 for old isbn
108     my ( $title, $isbn );
109     if ($query=~/\d/) {
110         my $querylength = length $query;
111         if ( $querylength == 13 || $querylength == 10 ) {
112             $isbn = $query;
113         }
114     }
115     if (!$isbn) {
116         $title = $query;
117     }
118     ( $countbr, @resultsbr ) = BreedingSearch( $title, $isbn );
119 }
120 my $breeding_loop = [];
121 for my $resultsbr (@resultsbr) {
122     push @{$breeding_loop}, {
123         id               => $resultsbr->{import_record_id},
124         isbn             => $resultsbr->{isbn},
125         copyrightdate    => $resultsbr->{copyrightdate},
126         editionstatement => $resultsbr->{editionstatement},
127         file             => $resultsbr->{file_name},
128         title            => $resultsbr->{title},
129         author           => $resultsbr->{author},
130     };
131 }
132
133 $template->param(
134     frameworkcodeloop => \@frameworkcodeloop,
135     breeding_count    => $countbr,
136     breeding_loop     => $breeding_loop,
137     z3950_search_params => C4::Search::z3950_search_args($query),
138 );
139
140 output_html_with_http_headers $input, $cookie, $template->output;
141