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