Bug 16554: Fix fr-FR sample files
[koha.git] / cataloguing / addbooks.pl
blob672a070ef02a0ba01ef6fd9f6dcc2086cd908c11
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 use Koha::SearchEngine::Search;
38 use Koha::SearchEngine::QueryBuilder;
40 my $input = new CGI;
42 my $success = $input->param('biblioitem');
43 my $query = $input->param('q');
44 my @value = $input->multi_param('value');
45 my $page = $input->param('page') || 1;
46 my $results_per_page = 20;
49 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
51 template_name => "cataloguing/addbooks.tt",
52 query => $input,
53 type => "intranet",
54 authnotrequired => 0,
55 flagsrequired => { editcatalogue => '*' },
56 debug => 1,
60 # get framework list
61 my $frameworks = getframeworks;
62 my @frameworkcodeloop;
63 foreach my $thisframeworkcode ( sort { uc($frameworks->{$a}->{'frameworktext'}) cmp uc($frameworks->{$b}->{'frameworktext'}) } keys %{$frameworks} ) {
64 push @frameworkcodeloop, {
65 value => $thisframeworkcode,
66 frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'},
71 # Searching the catalog.
72 if ($query) {
74 # build query
75 my @operands = $query;
77 my $QParser;
78 $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
79 my $builtquery;
80 my $builder = Koha::SearchEngine::QueryBuilder->new(
81 { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
82 my $searcher = Koha::SearchEngine::Search->new(
83 { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
84 if ($QParser) {
85 $builtquery = $query;
86 } else {
87 ( undef,$builtquery,undef,undef,undef,undef,undef,undef,undef,undef) = $builder->build_query_compat(undef,\@operands);
89 # find results
90 my ( $error, $marcresults, $total_hits ) = $searcher->simple_search_compat($builtquery, $results_per_page * ($page - 1), $results_per_page);
92 if ( defined $error ) {
93 $template->param( error => $error );
94 warn "error: " . $error;
95 output_html_with_http_headers $input, $cookie, $template->output;
96 exit;
99 # format output
100 # SimpleSearch() give the results per page we want, so 0 offet here
101 my $total = @{$marcresults};
102 my @newresults = searchResults( 'intranet', $query, $total, $results_per_page, 0, 0, $marcresults );
103 $template->param(
104 total => $total_hits,
105 query => $query,
106 resultsloop => \@newresults,
107 pagination_bar => pagination_bar( "/cgi-bin/koha/cataloguing/addbooks.pl?q=$query&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
111 # fill with books in breeding farm
113 my $countbr = 0;
114 my @resultsbr;
115 if ($query) {
116 # fill isbn or title, depending on what has been entered
117 #u must do check on isbn because u can find number in beginning of title
118 #check is on isbn legnth 13 for new isbn and 10 for old isbn
119 my ( $title, $isbn );
120 if ($query=~/\d/) {
121 my $clean_query = $query;
122 $clean_query =~ s/-//g; # remove hyphens
123 my $querylength = length $clean_query;
124 if ( $querylength == 13 || $querylength == 10 ) {
125 $isbn = $query;
128 if (!$isbn) {
129 $title = $query;
131 ( $countbr, @resultsbr ) = BreedingSearch( $title, $isbn );
133 my $breeding_loop = [];
134 for my $resultsbr (@resultsbr) {
135 push @{$breeding_loop}, {
136 id => $resultsbr->{import_record_id},
137 isbn => $resultsbr->{isbn},
138 copyrightdate => $resultsbr->{copyrightdate},
139 editionstatement => $resultsbr->{editionstatement},
140 file => $resultsbr->{file_name},
141 title => $resultsbr->{title},
142 author => $resultsbr->{author},
146 $template->param(
147 frameworkcodeloop => \@frameworkcodeloop,
148 breeding_count => $countbr,
149 breeding_loop => $breeding_loop,
150 z3950_search_params => C4::Search::z3950_search_args($query),
153 output_html_with_http_headers $input, $cookie, $template->output;