removing all useless %env / $env
[koha.git] / serials / receipt.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 # $Id$
21
22 use strict;
23 use CGI;
24 use C4::Auth;
25 use C4::Output;
26 use C4::Interface::CGI::Output;
27 use C4::Context;
28
29
30 my $query = new CGI;
31
32 my $op = $query->param('op');
33 my $search = $query->param('titleorissn');
34 my $startfrom=$query->param('startfrom');
35
36 if ($op eq 'search')
37 {
38     my $total;
39     my $results;
40     my $dbh = C4::Context->dbh;
41     my @marclist = $query->param('marclist');
42         my @and_or = $query->param('and_or');
43         my @excluding = $query->param('excluding');
44         my @operator = $query->param('operator');
45         my @value = $query->param('value');
46
47         my $resultsperpage= $query->param('resultsperpage');
48         $resultsperpage = 19 unless $resultsperpage;
49
50
51     my $sth = $dbh->prepare("select subscriptionid, biblionumber from subscription");
52     $sth->execute();
53     my @finalsolution;
54     while (my $first_step = $sth->fetchrow_hashref)
55     {
56         my $sth2 = $dbh->prepare("select b3.title from biblioitems b2, biblio b3 where b3.biblionumber = ? and b2.biblionumber = b3.biblionumber and (b2.issn = ? or b3.title like ?)");
57         $sth2->execute($first_step->{'biblionumber'},$search, "%$search%");
58         my @answear;
59         @answear = $sth2->fetchrow_array;
60         $total = scalar @answear;
61         if ($total >= 1)
62         {
63             $first_step->{'serial'} = $answear[0];
64             push @finalsolution ,$first_step;
65         }
66     }
67 my ($template, $loggedinuser, $cookie)
68 = get_template_and_user({template_name => "serials/receipt-search-result.tmpl",
69                                 query => $query,
70                                 type => "intranet",
71                                 authnotrequired => 0,
72                                 flagsrequired => {serials => 1},
73                                 debug => 1,
74                                 });
75     $template->param(subtable => \@finalsolution, total => $total
76                 ,);
77
78         my $displaynext=0;
79         my $displayprev=$startfrom;
80         if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){
81                 $displaynext = 1;
82         }
83
84         my @field_data = ();
85
86
87         for(my $i = 0 ; $i <= $#marclist ; $i++)
88         {
89                 push @field_data, { term => "marclist", val=>$marclist[$i] };
90                 push @field_data, { term => "and_or", val=>$and_or[$i] };
91                 push @field_data, { term => "excluding", val=>$excluding[$i] };
92                 push @field_data, { term => "operator", val=>$operator[$i] };
93                 push @field_data, { term => "value", val=>$value[$i] };
94         }
95
96         my @numbers = ();
97
98         if ($total>$resultsperpage)
99         {
100                 for (my $i=1; $i<$total/$resultsperpage+1; $i++)
101                 {
102                         if ($i<16)
103                         {
104                         my $highlight=0;
105                         ($startfrom==($i-1)) && ($highlight=1);
106                         push @numbers, { number => $i,
107                                         highlight => $highlight ,
108                                         searchdata=> \@field_data,
109                                         startfrom => ($i-1)};
110                         }
111         }
112         }
113
114         my $from = $startfrom*$resultsperpage+1;
115         my $to;
116
117         if($total < (($startfrom+1)*$resultsperpage))
118         {
119                 $to = $total;
120         } else {
121                 $to = (($startfrom+1)*$resultsperpage);
122         }
123     $results = \@finalsolution;
124         $template->param(result => $results) if $results;
125         $template->param(
126                                                         startfrom=> $startfrom,
127                                                         displaynext=> $displaynext,
128                                                         displayprev=> $displayprev,
129                                                         resultsperpage => $resultsperpage,
130                                                         startfromnext => $startfrom+1,
131                                                         startfromprev => $startfrom-1,
132                                                         searchdata=>\@field_data,
133                                                         total=>$total,
134                                                         from=>$from,
135                                                         to=>$to,
136                                                         numbers=>\@numbers,
137                                                         intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
138                 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
139                 IntranetNav => C4::Context->preference("IntranetNav"),
140                                                         );
141 output_html_with_http_headers $query, $cookie, $template->output;
142
143 }
144 else{
145 my ($template, $loggedinuser, $cookie)
146 = get_template_and_user({template_name => "serials/receipt.tmpl",
147                                 query => $query,
148                                 type => "intranet",
149                                 authnotrequired => 0,
150                                 flagsrequired => {serials => 1},
151                                 debug => 1,
152                                 });
153 output_html_with_http_headers $query, $cookie, $template->output;
154 }