Conforming to AWS new terms of service
[koha.git] / labels / label-item-search.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20 use strict;
21 use warnings;
22
23 use CGI;
24 use C4::Auth;
25 use HTML::Template::Pro;
26 use C4::Context;
27 use C4::Search;
28 use C4::Auth;
29 use C4::Output;
30 use C4::Biblio;
31 use C4::Items;
32 use C4::Acquisition;
33 use C4::Search;
34 use C4::Dates;
35 use C4::Koha;    # XXX subfield_is_koha_internal_p
36 use C4::Debug;
37 use List::Util qw( max min );
38 use POSIX;
39
40 #use Smart::Comments;
41 #use Data::Dumper;
42
43 BEGIN {
44     $debug = $debug || $cgi_debug;
45     if ($debug) {
46         require Data::Dumper;
47         import Data::Dumper qw(Dumper);
48     }
49 }
50
51 # Creates a scrolling list with the associated default value.
52 # Using more than one scrolling list in a CGI assigns the same default value to all the
53 # scrolling lists on the page !?!? That's why this function was written.
54
55 my $query = new CGI;
56
57 my $type      = $query->param('type');
58 my $op        = $query->param('op') || '';
59 my $batch_id  = $query->param('batch_id');
60 my $ccl_query = $query->param('ccl_query');
61
62 my $dbh = C4::Context->dbh;
63
64 my $startfrom = $query->param('startfrom') || 1;
65 my ( $template, $loggedinuser, $cookie );
66 my (
67     $total_hits,  $orderby, $results,  $total,  $error,
68     $marcresults, $idx,     $datefrom, $dateto, $ccl_textbox
69 );
70
71 my $resultsperpage = C4::Context->preference('numSearchResults') || '20';
72
73 my $show_results = 0;
74
75 if ( $op eq "do_search" ) {
76     $idx         = $query->param('idx');
77     $ccl_textbox = $query->param('ccl_textbox');
78     if ( $ccl_textbox && $idx ) {
79         $ccl_query = "$idx=$ccl_textbox";
80     }
81
82     $datefrom = $query->param('datefrom');
83     $dateto   = $query->param('dateto');
84
85     ( $template, $loggedinuser, $cookie ) = get_template_and_user(
86         {
87             template_name   => "labels/search.tmpl",
88             query           => $query,
89             type            => "intranet",
90             authnotrequired => 0,
91             flagsrequired   => { catalogue => 1 },
92             debug           => 1,
93         }
94     );
95
96     if ($datefrom) {
97         $datefrom = C4::Dates->new($datefrom);
98         $ccl_query .= ' and ' if $ccl_textbox;
99         $ccl_query .=
100           "acqdate,st-date-normalized,ge=" . $datefrom->output("iso");
101     }
102
103     if ($dateto) {
104         $dateto = C4::Dates->new($dateto);
105         $ccl_query .= ' and ' if ( $ccl_textbox || $datefrom );
106         $ccl_query .= "acqdate,st-date-normalized,le=" . $dateto->output("iso");
107     }
108
109     my $offset = $startfrom > 1 ? $startfrom - 1 : 0;
110     ( $error, $marcresults, $total_hits ) =
111       SimpleSearch( $ccl_query, $offset, $resultsperpage );
112
113     if ($marcresults) {
114         $show_results = scalar @$marcresults;
115     }
116     else {
117         $debug and warn "ERROR label-item-search: no results from SimpleSearch";
118
119         # leave $show_results undef
120     }
121 }
122
123 # Print the page
124 $template->param( DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), );
125 output_html_with_http_headers $query, $cookie, $template->output;