Bug 21613: Turn strict SQL modes on for tests
[koha.git] / cataloguing / addbooks.pl
blobe374cd33ac76395e1cf12f662ced45732c847240
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 Modern::Perl;
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::Languages qw(getlanguage);
36 use C4::Search;
38 use Koha::BiblioFrameworks;
39 use Koha::SearchEngine::Search;
40 use Koha::SearchEngine::QueryBuilder;
41 use Koha::Z3950Servers;
43 my $input = new CGI;
45 my $success = $input->param('biblioitem');
46 my $query = $input->param('q');
47 my @value = $input->multi_param('value');
48 my $page = $input->param('page') || 1;
49 my $results_per_page = 20;
50 my $lang = C4::Languages::getlanguage($input);
53 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
55 template_name => "cataloguing/addbooks.tt",
56 query => $input,
57 type => "intranet",
58 authnotrequired => 0,
59 flagsrequired => { editcatalogue => '*' },
60 debug => 1,
64 # Searching the catalog.
65 if ($query) {
67 # build query
68 my @operands = $query;
70 my $QParser;
71 $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
72 my $builtquery;
73 my $builder = Koha::SearchEngine::QueryBuilder->new(
74 { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
75 my $searcher = Koha::SearchEngine::Search->new(
76 { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
77 if ($QParser) {
78 $builtquery = $query;
79 } else {
80 ( undef, $builtquery, undef, undef, undef, undef, undef, undef, undef, undef ) =
81 $builder->build_query_compat( undef, \@operands, undef, undef, undef, 0, $lang );
83 # find results
84 my ( $error, $marcresults, $total_hits ) = $searcher->simple_search_compat($builtquery, $results_per_page * ($page - 1), $results_per_page);
86 if ( defined $error ) {
87 $template->param( error => $error );
88 warn "error: " . $error;
89 output_html_with_http_headers $input, $cookie, $template->output;
90 exit;
93 # format output
94 # SimpleSearch() give the results per page we want, so 0 offet here
95 my $total = @{$marcresults};
96 my @newresults = searchResults( 'intranet', $query, $total, $results_per_page, 0, 0, $marcresults );
97 $template->param(
98 total => $total_hits,
99 query => $query,
100 resultsloop => \@newresults,
101 pagination_bar => pagination_bar( "/cgi-bin/koha/cataloguing/addbooks.pl?q=$query&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
105 # fill with books in breeding farm
107 my $countbr = 0;
108 my @resultsbr;
109 if ($query) {
110 # fill isbn or title, depending on what has been entered
111 #u must do check on isbn because u can find number in beginning of title
112 #check is on isbn legnth 13 for new isbn and 10 for old isbn
113 my ( $title, $isbn );
114 if ($query=~/\d/) {
115 my $clean_query = $query;
116 $clean_query =~ s/-//g; # remove hyphens
117 my $querylength = length $clean_query;
118 if ( $querylength == 13 || $querylength == 10 ) {
119 $isbn = $query;
122 if (!$isbn) {
123 $title = $query;
125 ( $countbr, @resultsbr ) = BreedingSearch( $title, $isbn );
127 my $breeding_loop = [];
128 for my $resultsbr (@resultsbr) {
129 push @{$breeding_loop}, {
130 id => $resultsbr->{import_record_id},
131 isbn => $resultsbr->{isbn},
132 copyrightdate => $resultsbr->{copyrightdate},
133 editionstatement => $resultsbr->{editionstatement},
134 file => $resultsbr->{file_name},
135 title => $resultsbr->{title},
136 author => $resultsbr->{author},
140 my $servers = Koha::Z3950Servers->search(
142 recordtype => 'biblio',
143 servertype => ['zed','sru'],
147 my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
148 $template->param(
149 servers => $servers,
150 frameworks => $frameworks,
151 breeding_count => $countbr,
152 breeding_loop => $breeding_loop,
153 z3950_search_params => C4::Search::z3950_search_args($query),
156 output_html_with_http_headers $input, $cookie, $template->output;