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