moving boraccount.pl to members directory
[koha.git] / bull / receipt.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI;
5 use C4::Auth;
6 use C4::Output;
7 use C4::Interface::CGI::Output;
8 use C4::Context;
9 use HTML::Template;
10
11 my $query = new CGI;
12
13 my $op = $query->param('op');
14 my $search = $query->param('titleorissn');
15 my $startfrom=$query->param('startfrom');
16
17 if ($op eq 'search')
18
19     my $total;
20     my $results;
21     my $dbh = C4::Context->dbh;
22         my @marclist = $query->param('marclist');
23         my @and_or = $query->param('and_or');
24         my @excluding = $query->param('excluding');
25         my @operator = $query->param('operator');
26         my @value = $query->param('value');
27
28         my $resultsperpage= $query->param('resultsperpage');
29         $resultsperpage = 19 if(!defined $resultsperpage);
30
31     
32
33     my $sth = $dbh->prepare("select subscriptionid, biblionumber from subscription");
34     $sth->execute();
35     my @finalsolution;
36     while (my $first_step = $sth->fetchrow_hashref)
37     {
38         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 ?)");
39         $sth2->execute($first_step->{'biblionumber'},$search, "%$search%");
40         my @answear;
41         @answear = $sth2->fetchrow_array;
42         $total = scalar @answear;
43         if ($total >= 1)
44         {
45             $first_step->{'serial'} = $answear[0];
46             push @finalsolution ,$first_step;
47         }
48     }
49 my ($template, $loggedinuser, $cookie)
50 = get_template_and_user({template_name => "bull/receipt-search-result.tmpl",
51                                 query => $query,
52                                 type => "intranet",
53                                 authnotrequired => 0,
54                                 flagsrequired => {catalogue => 1},
55                                 debug => 1,
56                                 });
57     $template->param(subtable => \@finalsolution, total => $total
58                 ,);
59
60         my $displaynext=0;
61         my $displayprev=$startfrom;
62         if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){
63                 $displaynext = 1;
64         }
65
66         my @field_data = ();
67
68
69         for(my $i = 0 ; $i <= $#marclist ; $i++)
70         {
71                 push @field_data, { term => "marclist", val=>$marclist[$i] };
72                 push @field_data, { term => "and_or", val=>$and_or[$i] };
73                 push @field_data, { term => "excluding", val=>$excluding[$i] };
74                 push @field_data, { term => "operator", val=>$operator[$i] };
75                 push @field_data, { term => "value", val=>$value[$i] };
76         }
77
78         my @numbers = ();
79
80         if ($total>$resultsperpage)
81         {
82                 for (my $i=1; $i<$total/$resultsperpage+1; $i++)
83                 {
84                         if ($i<16)
85                         {
86                         my $highlight=0;
87                         ($startfrom==($i-1)) && ($highlight=1);
88                         push @numbers, { number => $i,
89                                         highlight => $highlight ,
90                                         searchdata=> \@field_data,
91                                         startfrom => ($i-1)};
92                         }
93         }
94         }
95
96         my $from = $startfrom*$resultsperpage+1;
97         my $to;
98
99         if($total < (($startfrom+1)*$resultsperpage))
100         {
101                 $to = $total;
102         } else {
103                 $to = (($startfrom+1)*$resultsperpage);
104         }
105     $results = \@finalsolution;
106         $template->param(result => $results) if $results;
107         $template->param(
108                                                         startfrom=> $startfrom,
109                                                         displaynext=> $displaynext,
110                                                         displayprev=> $displayprev,
111                                                         resultsperpage => $resultsperpage,
112                                                         startfromnext => $startfrom+1,
113                                                         startfromprev => $startfrom-1,
114                                                         searchdata=>\@field_data,
115                                                         total=>$total,
116                                                         from=>$from,
117                                                         to=>$to,
118                                                         numbers=>\@numbers,
119                                                         );
120 output_html_with_http_headers $query, $cookie, $template->output;
121
122 }
123 else{
124 my ($template, $loggedinuser, $cookie)
125 = get_template_and_user({template_name => "bull/receipt.tmpl",
126                                 query => $query,
127                                 type => "intranet",
128                                 authnotrequired => 0,
129                                 flagsrequired => {catalogue => 1},
130                                 debug => 1,
131                                 });
132 output_html_with_http_headers $query, $cookie, $template->output;
133 }