Bug 21637: Fixed upercase letter in EasyAnalyticalRecords syspref
[koha.git] / acqui / neworderbiblio.pl
blobb48737d79f81cbd8d789a7bf9457e2e41a1d2415
1 #!/usr/bin/perl
3 #origninally script to provide intranet (librarian) advanced search facility
4 #now script to do searching for acquisitions
6 # Copyright 2000-2002 Katipo Communications
7 # Copyright 2008-2009 BibLibre SARL
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
16 # Koha is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 =head1 NAME
26 neworderbiblio.pl
28 =head1 DESCRIPTION
30 this script allows to perform a new order from an existing record.
32 =head1 CGI PARAMETERS
34 =over 4
36 =item search
37 the title the librarian has typed to search an existing record.
39 =item q
40 the keyword the librarian has typed to search an existing record.
42 =item author
43 the author of the new record.
45 =item num
46 the number of result per page to display
48 =item booksellerid
49 the id of the bookseller this script has to add an order.
51 =item basketno
52 the basket number to know on which basket this script have to add a new order.
54 =back
56 =cut
58 use Modern::Perl;
60 use C4::Search;
61 use CGI qw ( -utf8 );
62 use C4::Biblio;
63 use C4::Auth;
64 use C4::Output;
65 use C4::Koha;
66 use C4::Budgets qw/ GetBudgetHierarchy /;
67 use C4::Languages qw(getlanguage);
69 use Koha::Acquisition::Booksellers;
70 use Koha::SearchEngine;
71 use Koha::SearchEngine::Search;
72 use Koha::SearchEngine::QueryBuilder;
73 use Koha::Patrons;
75 my $input = new CGI;
77 #getting all CGI params into a hash.
78 my $params = $input->Vars;
80 my $page = $params->{'page'} || 1;
81 my $query = $params->{'q'};
82 my $results_per_page = $params->{'num'} || 20;
83 my $booksellerid = $params->{'booksellerid'};
84 my $basketno = $params->{'basketno'};
85 my $sub = $params->{'sub'};
86 my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
87 my $lang = C4::Languages::getlanguage($input);
89 # getting the template
90 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
92 template_name => "acqui/neworderbiblio.tt",
93 query => $input,
94 type => "intranet",
95 authnotrequired => 0,
96 flagsrequired => { acquisition => 'order_manage' },
100 # Searching the catalog.
102 my @operands = $query;
103 my $QParser;
104 $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
105 my $builtquery;
106 my $builder = Koha::SearchEngine::QueryBuilder->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
107 my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
108 if ($QParser) {
109 $builtquery = $query;
110 } else {
111 ( undef, $builtquery, undef, undef, undef, undef, undef, undef, undef, undef ) =
112 $builder->build_query_compat( undef, \@operands, undef, undef, undef, 0, $lang );
114 my ( $error, $marcresults, $total_hits ) = $searcher->simple_search_compat($builtquery, $results_per_page * ($page - 1), $results_per_page);
116 if (defined $error) {
117 $template->param(
118 query_error => $error,
119 basketno => $basketno,
120 booksellerid => $bookseller->id,
121 name => $bookseller->name,
123 output_html_with_http_headers $input, $cookie, $template->output;
124 exit;
127 my @results;
129 foreach my $result ( @{$marcresults} ) {
130 my $marcrecord = C4::Search::new_record_from_zebra( 'biblioserver', $result );
131 my $biblio = TransformMarcToKoha( $marcrecord, '' );
132 $biblio->{subtitles} = GetRecordValue( 'subtitle', GetMarcBiblio({ biblionumber => $biblio->{biblionumber} }), GetFrameworkCode( $biblio->{biblionumber} ) );
134 $biblio->{booksellerid} = $booksellerid;
135 push @results, $biblio;
139 my $patron = Koha::Patrons->find( $loggedinuser );
140 my $budgets = GetBudgetHierarchy(q{},$patron->branchcode,$patron->borrowernumber);
141 my $has_budgets = 0;
142 foreach my $r (@{$budgets}) {
143 if (!defined $r->{budget_amount} || $r->{budget_amount} == 0) {
144 next;
146 $has_budgets = 1;
147 last;
150 $template->param(
151 has_budgets => $has_budgets,
152 basketno => $basketno,
153 booksellerid => $bookseller->id,
154 name => $bookseller->name,
155 resultsloop => \@results,
156 total => $total_hits,
157 query => $query,
158 pagination_bar => pagination_bar( "/cgi-bin/koha/acqui/neworderbiblio.pl?q=$query&booksellerid=$booksellerid&basketno=$basketno&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
161 # BUILD THE TEMPLATE
162 output_html_with_http_headers $input, $cookie, $template->output;