Bug 12868: Improving t/db_dependent/Member.t
[koha.git] / acqui / neworderbiblio.pl
blob8d13915668a8bce1991895e3e405586a8f2d58ae
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 under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along
21 # with Koha; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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;
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 # find results
99 my ( $error, $marcresults, $total_hits ) = SimpleSearch( $query, $results_per_page * ( $page - 1 ), $results_per_page );
101 if (defined $error) {
102 $template->param(
103 query_error => $error,
104 basketno => $basketno,
105 booksellerid => $bookseller->{'id'},
106 name => $bookseller->{'name'},
108 output_html_with_http_headers $input, $cookie, $template->output;
109 exit;
112 my @results;
114 foreach my $result ( @{$marcresults} ) {
115 my $marcrecord = C4::Search::new_record_from_zebra( 'biblioserver', $result );
116 my $biblio = TransformMarcToKoha( C4::Context->dbh, $marcrecord, '' );
118 $biblio->{booksellerid} = $booksellerid;
119 push @results, $biblio;
123 my $borrower= GetMember('borrowernumber' => $loggedinuser);
124 my $budgets = GetBudgetHierarchy(q{},$borrower->{branchcode},$borrower->{borrowernumber});
125 my $has_budgets = 0;
126 foreach my $r (@{$budgets}) {
127 if (!defined $r->{budget_amount} || $r->{budget_amount} == 0) {
128 next;
130 $has_budgets = 1;
131 last;
134 $template->param(
135 has_budgets => $has_budgets,
136 basketno => $basketno,
137 booksellerid => $bookseller->{'id'},
138 name => $bookseller->{'name'},
139 resultsloop => \@results,
140 total => $total_hits,
141 query => $query,
142 pagination_bar => pagination_bar( "$ENV{'SCRIPT_NAME'}?q=$query&booksellerid=$booksellerid&basketno=$basketno&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
145 # BUILD THE TEMPLATE
146 output_html_with_http_headers $input, $cookie, $template->output;