Fixes for basket closing:
[koha.git] / acqui / neworderbiblio.pl
1 #!/usr/bin/perl
2
3 #origninally script to provide intranet (librarian) advanced search facility
4 #now script to do searching for acquisitions
5
6 # Copyright 2000-2002 Katipo Communications
7 # Copyright 2008-2009 BibLibre SARL
8 #
9 # This file is part of Koha.
10 #
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.
15 #
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.
19 #
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA  02111-1307 USA
23
24 =head1 NAME
25
26 neworderbiblio.pl
27
28 =head1 DESCRIPTION
29
30 this script allows to perform a new order from an existing record.
31
32 =head1 CGI PARAMETERS
33
34 =over 4
35
36 =item search
37 the title the librarian has typed to search an existing record.
38
39 =item q
40 the keyword the librarian has typed to search an existing record.
41
42 =item author
43 the author of the new record.
44
45 =item num
46 the number of result per page to display
47
48 =item booksellerid
49 the id of the bookseller this script has to add an order.
50
51 =item basketno
52 the basket number to know on which basket this script have to add a new order.
53
54 =back
55
56 =cut
57
58 use strict;
59
60 use C4::Search;
61 use CGI;
62 use C4::Bookseller;
63 use C4::Biblio;
64 use C4::Auth;
65 use C4::Output;
66 use C4::Koha;
67
68 my $input = new CGI;
69
70 #getting all CGI params into a hash.
71 my $params = $input->Vars;
72
73 my $page             = $params->{'page'} || 1;
74 my $query            = $params->{'q'};
75 my $results_per_page = $params->{'num'} || 20;
76 my $booksellerid     = $params->{'booksellerid'};
77 my $basketno         = $params->{'basketno'};
78 my $sub              = $params->{'sub'};
79
80 # getting the template
81 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
82     {
83         template_name   => "acqui/neworderbiblio.tmpl",
84         query           => $input,
85         type            => "intranet",
86         authnotrequired => 0,
87         flagsrequired   => { acquisition => 'order_manage' },
88     }
89 );
90
91 # Searching the catalog.
92 my ($error, $marcresults, $total_hits) = SimpleSearch($query, $results_per_page * ($page - 1), $results_per_page);
93
94 if (defined $error) {
95     warn "error: ".$error;
96     $template->param(
97         query_error => $error,
98         basketno             => $basketno,
99         booksellerid     => $bookseller->{'id'},
100         name             => $bookseller->{'name'},
101     );
102     output_html_with_http_headers $input, $cookie, $template->output;
103     exit;
104 }
105
106 my @results;
107
108 if ($marcresults) {
109     foreach my $i ( 0 .. scalar @$marcresults ) {
110         my %resultsloop;
111         my $marcrecord = MARC::File::USMARC::decode( $marcresults->[$i] );
112         my $biblio = TransformMarcToKoha( C4::Context->dbh, $marcrecord, '' );
113
114         #build the hash for the template.
115         %resultsloop = %$biblio;
116         $resultsloop{highlight} = ( $i % 2 ) ? (1) : (0);
117         $resultsloop{booksellerid} = $booksellerid;
118         push @results, \%resultsloop;
119     }
120 }
121
122 $template->param(
123     basketno             => $basketno,
124     booksellerid     => $bookseller->{'id'},
125     name             => $bookseller->{'name'},
126     resultsloop          => \@results,
127     total                => $total_hits,
128     query                => $query,
129     pagination_bar       => pagination_bar( "$ENV{'SCRIPT_NAME'}?q=$query&booksellerid=$booksellerid&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
130 );
131
132 # BUILD THE TEMPLATE
133 output_html_with_http_headers $input, $cookie, $template->output;