Bug 10468: (followup) fix indentation
[koha.git] / cataloguing / addbooks.pl
blob37ac83a6324363a9bcc5ceda94887866184e5434
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
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 =head1 cataloguing:addbooks.pl
23 TODO
25 =cut
27 use strict;
28 use warnings;
29 use CGI qw ( -utf8 );
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.tt",
49 query => $input,
50 type => "intranet",
51 authnotrequired => 0,
52 flagsrequired => { editcatalogue => '*' },
53 debug => 1,
57 # get framework list
58 my $frameworks = getframeworks;
59 my @frameworkcodeloop;
60 foreach my $thisframeworkcode ( sort { uc($frameworks->{$a}->{'frameworktext'}) cmp uc($frameworks->{$b}->{'frameworktext'}) } 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;
74 my $QParser;
75 $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
76 my $builtquery;
77 if ($QParser) {
78 $builtquery = $query;
79 } else {
80 my ( $builterror,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type);
81 ( $builterror,$builtquery,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) = buildQuery(undef,\@operands);
84 # find results
85 my ( $error, $marcresults, $total_hits ) = SimpleSearch($builtquery, $results_per_page * ($page - 1), $results_per_page);
87 if ( defined $error ) {
88 $template->param( error => $error );
89 warn "error: " . $error;
90 output_html_with_http_headers $input, $cookie, $template->output;
91 exit;
94 # format output
95 # SimpleSearch() give the results per page we want, so 0 offet here
96 my $total = @{$marcresults};
97 my @newresults = searchResults( 'intranet', $query, $total, $results_per_page, 0, 0, $marcresults );
98 $template->param(
99 total => $total_hits,
100 query => $query,
101 resultsloop => \@newresults,
102 pagination_bar => pagination_bar( "/cgi-bin/koha/cataloguing/addbooks.pl?q=$query&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
106 # fill with books in breeding farm
108 my $countbr = 0;
109 my @resultsbr;
110 if ($query) {
111 # fill isbn or title, depending on what has been entered
112 #u must do check on isbn because u can find number in beginning of title
113 #check is on isbn legnth 13 for new isbn and 10 for old isbn
114 my ( $title, $isbn );
115 if ($query=~/\d/) {
116 my $clean_query = $query;
117 $clean_query =~ s/-//g; # remove hyphens
118 my $querylength = length $clean_query;
119 if ( $querylength == 13 || $querylength == 10 ) {
120 $isbn = $query;
123 if (!$isbn) {
124 $title = $query;
126 ( $countbr, @resultsbr ) = BreedingSearch( $title, $isbn );
128 my $breeding_loop = [];
129 for my $resultsbr (@resultsbr) {
130 push @{$breeding_loop}, {
131 id => $resultsbr->{import_record_id},
132 isbn => $resultsbr->{isbn},
133 copyrightdate => $resultsbr->{copyrightdate},
134 editionstatement => $resultsbr->{editionstatement},
135 file => $resultsbr->{file_name},
136 title => $resultsbr->{title},
137 author => $resultsbr->{author},
141 $template->param(
142 frameworkcodeloop => \@frameworkcodeloop,
143 breeding_count => $countbr,
144 breeding_loop => $breeding_loop,
145 z3950_search_params => C4::Search::z3950_search_args($query),
148 output_html_with_http_headers $input, $cookie, $template->output;