bug 10292: improve fallback logic for picking XSLT
[koha.git] / cataloguing / addbooks.pl
blobf64359963551a7350612747641e5114fbd969442
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 => '*' },
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 unless ($QParser) {
77 my ( $builterror,$builtquery,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = buildQuery(undef,\@operands);
78 $query = $builtquery;
81 # find results
82 my ( $error, $marcresults, $total_hits ) = SimpleSearch($query, $results_per_page * ($page - 1), $results_per_page);
84 if ( defined $error ) {
85 $template->param( error => $error );
86 warn "error: " . $error;
87 output_html_with_http_headers $input, $cookie, $template->output;
88 exit;
91 # format output
92 # SimpleSearch() give the results per page we want, so 0 offet here
93 my $total = @{$marcresults};
94 my @newresults = searchResults( 'intranet', $query, $total, $results_per_page, 0, 0, $marcresults );
95 foreach my $line (@newresults) {
96 if ( not exists $line->{'size'} ) { $line->{'size'} = "" }
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 $querylength = length $query;
117 if ( $querylength == 13 || $querylength == 10 ) {
118 $isbn = $query;
121 if (!$isbn) {
122 $title = $query;
124 ( $countbr, @resultsbr ) = BreedingSearch( $title, $isbn );
126 my $breeding_loop = [];
127 for my $resultsbr (@resultsbr) {
128 push @{$breeding_loop}, {
129 id => $resultsbr->{import_record_id},
130 isbn => $resultsbr->{isbn},
131 copyrightdate => $resultsbr->{copyrightdate},
132 editionstatement => $resultsbr->{editionstatement},
133 file => $resultsbr->{file_name},
134 title => $resultsbr->{title},
135 author => $resultsbr->{author},
139 $template->param(
140 frameworkcodeloop => \@frameworkcodeloop,
141 breeding_count => $countbr,
142 breeding_loop => $breeding_loop,
143 z3950_search_params => C4::Search::z3950_search_args($query),
146 output_html_with_http_headers $input, $cookie, $template->output;