Bug 11081: (followup) Add license information
[koha.git] / acqui / neworderbiblio.pl
blob4269fe6d918bbba6e6c469e8112ea0b9bfb82e74
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 strict;
59 #use warnings; FIXME - Bug 2505
61 use C4::Search;
62 use CGI qw ( -utf8 );
63 use C4::Biblio;
64 use C4::Auth;
65 use C4::Output;
66 use C4::Koha;
67 use C4::Members qw/ GetMember /;
68 use C4::Budgets qw/ GetBudgetHierarchy /;
70 use Koha::Acquisition::Bookseller;
72 my $input = new CGI;
74 #getting all CGI params into a hash.
75 my $params = $input->Vars;
77 my $page = $params->{'page'} || 1;
78 my $query = $params->{'q'};
79 my $results_per_page = $params->{'num'} || 20;
80 my $booksellerid = $params->{'booksellerid'};
81 my $basketno = $params->{'basketno'};
82 my $sub = $params->{'sub'};
83 my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
85 # getting the template
86 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
88 template_name => "acqui/neworderbiblio.tt",
89 query => $input,
90 type => "intranet",
91 authnotrequired => 0,
92 flagsrequired => { acquisition => 'order_manage' },
96 # Searching the catalog.
98 my @operands = $query;
99 my $QParser;
100 $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
101 my $builtquery;
102 if ($QParser) {
103 $builtquery = $query;
104 } else {
105 my ( $builterror,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type);
106 ( $builterror,$builtquery,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) = buildQuery(undef,\@operands);
108 my ( $error, $marcresults, $total_hits ) = SimpleSearch( $builtquery, $results_per_page * ( $page - 1 ), $results_per_page );
110 if (defined $error) {
111 $template->param(
112 query_error => $error,
113 basketno => $basketno,
114 booksellerid => $bookseller->{'id'},
115 name => $bookseller->{'name'},
117 output_html_with_http_headers $input, $cookie, $template->output;
118 exit;
121 my @results;
123 foreach my $result ( @{$marcresults} ) {
124 my $marcrecord = C4::Search::new_record_from_zebra( 'biblioserver', $result );
125 my $biblio = TransformMarcToKoha( C4::Context->dbh, $marcrecord, '' );
127 $biblio->{booksellerid} = $booksellerid;
128 push @results, $biblio;
132 my $borrower= GetMember('borrowernumber' => $loggedinuser);
133 my $budgets = GetBudgetHierarchy(q{},$borrower->{branchcode},$borrower->{borrowernumber});
134 my $has_budgets = 0;
135 foreach my $r (@{$budgets}) {
136 if (!defined $r->{budget_amount} || $r->{budget_amount} == 0) {
137 next;
139 $has_budgets = 1;
140 last;
143 $template->param(
144 has_budgets => $has_budgets,
145 basketno => $basketno,
146 booksellerid => $bookseller->{'id'},
147 name => $bookseller->{'name'},
148 resultsloop => \@results,
149 total => $total_hits,
150 query => $query,
151 pagination_bar => pagination_bar( "/cgi-bin/koha/acqui/neworderbiblio.pl?q=$query&booksellerid=$booksellerid&basketno=$basketno&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
154 # BUILD THE TEMPLATE
155 output_html_with_http_headers $input, $cookie, $template->output;