bug 1980: updateing calls to SimpleSearch to limit number of things returned
[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 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
14 #
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA  02111-1307 USA
22
23 =head1 NAME
24
25 neworderbiblio.pl
26
27 =head1 DESCRIPTION
28
29 this script allows to perform a new order from an existing record.
30
31 =head1 CGI PARAMETERS
32
33 =over 4
34
35 =item search
36 the title the librarian has typed to search an existing record.
37
38 =item q
39 the keyword the librarian has typed to search an existing record.
40
41 =item author
42 the author of the new record.
43
44 =item num
45 the number of result per page to display
46
47 =item booksellerid
48 the id of the bookseller this script has to add an order.
49
50 =item basketno
51 the basket number to know on which basket this script have to add a new order.
52
53 =back
54
55 =cut
56
57 use strict;
58 use C4::Search;
59 use CGI;
60 use C4::Bookseller;
61 use C4::Biblio;
62
63 use C4::Auth;
64 use C4::Output;
65 use C4::Koha;
66
67 my $input = new CGI;
68
69 #getting all CGI params into a hash.
70 my $params = $input->Vars;
71
72 my $page             = $params->{'page'} || 1;
73 my $query            = $params->{'q'};
74 my $results_per_page = $params->{'num'} || 20;
75
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 => 1 },
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     $template->param(query_error => $error);
96     warn "error: ".$error;
97     output_html_with_http_headers $input, $cookie, $template->output;
98     exit;
99 }
100
101 my @results;
102
103 foreach my $i ( 0 .. scalar @$marcresults ) {
104     my %resultsloop;
105     my $marcrecord = MARC::File::USMARC::decode($marcresults->[$i]);
106     my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
107
108     #build the hash for the template.
109     %resultsloop=%$biblio;
110     $resultsloop{highlight}       = ($i % 2)?(1):(0);
111     $resultsloop{booksellerid} = $booksellerid;
112     push @results, \%resultsloop;
113 }
114
115 $template->param(
116     basketno             => $basketno,
117     booksellerid         => $booksellerid,
118     resultsloop          => \@results,
119     total                => $total_hits,
120     query                => $query,
121     virtualshelves       => C4::Context->preference("virtualshelves"),
122     LibraryName          => C4::Context->preference("LibraryName"),
123     OpacNav              => C4::Context->preference("OpacNav"),
124     opaccredits          => C4::Context->preference("opaccredits"),
125     AmazonContent        => C4::Context->preference("AmazonContent"),
126     opacsmallimage       => C4::Context->preference("opacsmallimage"),
127     opaclayoutstylesheet => C4::Context->preference("opaclayoutstylesheet"),
128     opaccolorstylesheet  => C4::Context->preference("opaccolorstylesheet"),
129     "BiblioDefaultView".C4::Context->preference("IntranetBiblioDefaultView") => 1,
130     # FIXME: pagination_bar doesn't work right with only one pair of CGI params, so I put two in.
131     pagination_bar       => pagination_bar( "$ENV{'SCRIPT_NAME'}?bug=fix&q=$query&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
132 );
133
134 # BUILD THE TEMPLATE
135 output_html_with_http_headers $input, $cookie, $template->output;