Bug 31272: Use TT plugins for pickup library and due date in opac-reserve.pl
[koha.git] / cataloguing / addbooks.pl
1 #!/usr/bin/perl
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
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.
12 #
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.
17 #
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>.
20
21 =head1 cataloguing:addbooks.pl
22
23         TODO
24
25 =cut
26
27 use Modern::Perl;
28
29 use CGI qw ( -utf8 );
30 use C4::Auth qw( get_template_and_user );
31 use C4::Breeding qw( BreedingSearch );
32 use C4::Output qw( output_html_with_http_headers pagination_bar );
33 use C4::Koha qw( getnbpages );
34 use C4::Languages;
35 use C4::Search qw( searchResults z3950_search_args );
36
37 use Koha::BiblioFrameworks;
38 use Koha::SearchEngine::Search;
39 use Koha::SearchEngine::QueryBuilder;
40 use Koha::Z3950Servers;
41
42 my $input = CGI->new;
43
44 my $success = $input->param('biblioitem');
45 my $query   = $input->param('q');
46 my @value   = $input->multi_param('value');
47 my $page    = $input->param('page') || 1;
48 my $results_per_page = 20;
49 my $lang = C4::Languages::getlanguage($input);
50
51
52 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
53     {
54         template_name   => "cataloguing/addbooks.tt",
55         query           => $input,
56         type            => "intranet",
57         flagsrequired   => { editcatalogue => '*' },
58     }
59 );
60
61 # Searching the catalog.
62 if ($query) {
63
64     # build query
65     my @operands = $query;
66
67     my $builtquery;
68     my $query_cgi;
69     my $builder = Koha::SearchEngine::QueryBuilder->new(
70         { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
71     my $searcher = Koha::SearchEngine::Search->new(
72         { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
73     ( undef, $builtquery, undef, $query_cgi, undef, undef, undef, undef, undef, undef ) =
74       $builder->build_query_compat( undef, \@operands, undef, undef, undef, 0, $lang, { weighted_fields => 1 });
75
76     $template->param( search_query => $builtquery ) if C4::Context->preference('DumpSearchQueryTemplate');
77
78     # find results
79     my ( $error, $marcresults, $total_hits ) = $searcher->simple_search_compat($builtquery, $results_per_page * ($page - 1), $results_per_page);
80
81     if ( defined $error ) {
82         $template->param( error => $error );
83         warn "error: " . $error;
84         output_html_with_http_headers $input, $cookie, $template->output;
85         exit;
86     }
87
88     # format output
89     # SimpleSearch() give the results per page we want, so 0 offet here
90     my $total = @{$marcresults};
91     my @newresults = searchResults( {'interface' => 'intranet'}, $query, $total, $results_per_page, 0, 0, $marcresults );
92     foreach my $line (@newresults) {
93         if ( not exists $line->{'size'} ) { $line->{'size'} = "" }
94     }
95     $template->param(
96         total          => $total_hits,
97         query          => $query,
98         resultsloop    => \@newresults,
99         pagination_bar => pagination_bar( "/cgi-bin/koha/cataloguing/addbooks.pl?$query_cgi&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
100     );
101 }
102
103 # fill with books in breeding farm
104
105 my $countbr = 0;
106 my @resultsbr;
107 if ($query) {
108     ( $countbr, @resultsbr ) = BreedingSearch( $query );
109 }
110 my $breeding_loop = [];
111 for my $resultsbr (@resultsbr) {
112     push @{$breeding_loop}, {
113         id               => $resultsbr->{import_record_id},
114         isbn             => $resultsbr->{isbn},
115         file             => $resultsbr->{file_name},
116         title            => $resultsbr->{title},
117         author           => $resultsbr->{author},
118         upload_timestamp => $resultsbr->{upload_timestamp}
119     };
120 }
121
122 my $servers = Koha::Z3950Servers->search(
123     {
124         recordtype => 'biblio',
125         servertype => ['zed','sru'],
126     }
127 );
128
129 my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
130 $template->param(
131     servers           => $servers,
132     frameworks        => $frameworks,
133     breeding_count    => $countbr,
134     breeding_loop     => $breeding_loop,
135     z3950_search_params => C4::Search::z3950_search_args($query),
136 );
137
138 output_html_with_http_headers $input, $cookie, $template->output;
139