wr-70205 Rental discount not being respected
[koha.git] / cataloguing / addbooks.pl
blob4ee71416631b0c04820f6f106795fbbeac317b22
1 #!/usr/bin/perl
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
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.
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.
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.
21 =head1 cataloguing:addbooks.pl
23 TODO
25 =cut
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;
37 my $input = new CGI;
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;
46 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
48 template_name => "cataloguing/addbooks.tmpl",
49 query => $input,
50 type => "intranet",
51 authnotrequired => 0,
52 flagsrequired => { editcatalogue => 'edit_catalogue' },
53 debug => 1,
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'},
68 # Searching the catalog.
69 if ($query) {
71 # build query
72 my @operands = $query;
73 my (@operators, @indexes, @sort_by, @limits) = ();
74 my ( $builterror,$builtquery,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = buildQuery(\@operators,\@operands,\@indexes,@limits,\@sort_by,undef,undef);
76 # find results
77 my ( $error, $marcresults, $total_hits ) = SimpleSearch($builtquery, $results_per_page * ($page - 1), $results_per_page);
79 if ( defined $error ) {
80 $template->param( error => $error );
81 warn "error: " . $error;
82 output_html_with_http_headers $input, $cookie, $template->output;
83 exit;
86 # format output
87 # SimpleSearch() give the results per page we want, so 0 offet here
88 my $total = scalar @$marcresults;
89 my @newresults = searchResults( $query, $total, $results_per_page, 0, 0, @$marcresults );
90 $template->param(
91 total => $total_hits,
92 query => $query,
93 resultsloop => \@newresults,
94 pagination_bar => pagination_bar( "/cgi-bin/koha/cataloguing/addbooks.pl?q=$query&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
98 # fill with books in breeding farm
100 my $countbr = 0;
101 my @resultsbr;
102 if ($query) {
103 # fill isbn or title, depending on what has been entered
104 #u must do check on isbn because u can find number in beginning of title
105 #check is on isbn legnth 13 for new isbn and 10 for old isbn
106 my ( $title, $isbn );
107 if ($query=~/\d/) {
108 my $querylength = length $query;
109 if ( $querylength == 13 || $querylength == 10 ) {
110 $isbn = $query;
113 if (!$isbn) {
114 $title = $query;
116 ( $countbr, @resultsbr ) = BreedingSearch( $title, $isbn );
118 my $breeding_loop = [];
119 for my $resultsbr (@resultsbr) {
120 push @{$breeding_loop}, {
121 id => $resultsbr->{import_record_id},
122 isbn => $resultsbr->{isbn},
123 copyrightdate => $resultsbr->{copyrightdate},
124 editionstatement => $resultsbr->{editionstatement},
125 file => $resultsbr->{file_name},
126 title => $resultsbr->{title},
127 author => $resultsbr->{author},
131 $template->param(
132 frameworkcodeloop => \@frameworkcodeloop,
133 breeding_count => $countbr,
134 breeding_loop => $breeding_loop,
135 z3950_search_params => C4::Search::z3950_search_args($query),
138 output_html_with_http_headers $input, $cookie, $template->output;