Removed trailing whitespace.
[koha.git] / opac / opac-user.pl
1 #!/usr/bin/perl
2 use strict;
3 require Exporter;
4 use CGI;
5
6 use C4::Search;       # borrdata
7 use C4::Output;       # gettemplate
8 use C4::Auth;         # checkauth, getborrowernumber.
9 use C4::Koha;
10 use C4::Circulation::Circ2;
11 use C4::Reserves2;
12
13 my $query = new CGI;
14
15 my ($loggedinuser, $cookie, $sessionID) = checkauth($query);
16
17 my $template = gettemplate("opac-user.tmpl", "opac");
18
19 # get borrower information ....
20 my $borrowernumber = getborrowernumber($loggedinuser);
21 my ($borr, $flags) = getpatroninformation(undef, $borrowernumber);
22
23 $borr->{'dateenrolled'} = slashifyDate($borr->{'dateenrolled'});
24 $borr->{'expiry'}       = slashifyDate($borr->{'expiry'});
25 $borr->{'dateofbirth'}  = slashifyDate($borr->{'dateofbirth'});
26 $borr->{'ethnicity'}    = fixEthnicity($borr->{'ethnicity'});
27
28 if ($borr->{'amountoutstanding'} > 5) {
29     $borr->{'amountoverfive'} = 1;
30 } else {
31     $borr->{'amountoverfive'} = 0;
32 }
33
34 $borr->{'amountoutstanding'} = sprintf "\$%.02f", $borr->{'amountoutstanding'};
35
36 my @bordat;
37 $bordat[0] = $borr;
38
39 $template->param(BORROWER_INFO => \@bordat);
40
41 #get issued items ....
42 my $issues = getissues($borr);
43
44 my $count=0;
45 my @issuedat;
46 foreach my $key (keys %$issues) {
47     my $issue = $issues->{$key};
48     $issue->{'date_due'}  = slashifyDate($issue->{'date_due'});
49     if ($issue->{'overdue'}) {
50         $issue->{'status'} = "OVERDUE";
51     } else {
52         $issue->{'status'} = "Issued";
53     }
54 # check for reserves
55     my ($restype, $res) = CheckReserves($issue->{'itemnumber'});
56     if ($restype) {
57         $issue->{'status'} .= "Reserved";
58     }
59     my ($charges, $itemtype) = calc_charges(undef, undef, $issue->{'itemnumber'}, $borrowernumber);
60     $issue->{'charges'} = $charges;
61     push @issuedat, $issue;
62     $count++;
63 }
64
65 $template->param(ISSUES => \@issuedat);
66 $template->param(issues_count => $count);
67
68 # now the reserved items....
69 my ($rcount, $reserves) = FindReserves(undef, $borrowernumber);
70
71 $template->param(RESERVES => $reserves);
72 $template->param(reserves_count => $rcount);
73
74 my $branches = getbranches();
75 my @waiting;
76 my $wcount = 0;
77 foreach my $res (@$reserves) {
78     if ($res->{'itemnumber'}) {
79         $res->{'branch'} = $branches->{$res->{'branchcode'}}->{'branchname'};
80         push @waiting, $res;
81         $wcount++;
82     }
83 }
84
85 $template->param(WAITING => \@waiting);
86 $template->param(waiting_count => $wcount);
87
88 $template->param(loggedinuser => $loggedinuser);
89 print "Content-Type: text/html\n\n", $template->output;