*** empty log message ***
[koha.git] / opac / opac-user.pl
1 #!/usr/bin/perl
2 use strict;
3 require Exporter;
4 use CGI;
5
6 use C4::Auth;
7 use C4::Koha;
8 use C4::Circulation::Circ2;
9 use C4::Circulation::Renewals2;
10 use C4::Reserves2;
11 use C4::Search;
12 use C4::Interface::CGI::Output;
13 use HTML::Template;
14 use C4::Date;
15
16 my $query = new CGI;
17 my ($template, $borrowernumber, $cookie) 
18     = get_template_and_user({template_name => "opac-user.tmpl",
19                              query => $query,
20                              type => "opac",
21                              authnotrequired => 0,
22                              flagsrequired => {borrow => 1},
23                              debug => 1,
24                              });
25
26 # get borrower information ....
27 my ($borr, $flags) = getpatroninformation(undef, $borrowernumber);
28
29 $borr->{'dateenrolled'} = format_date($borr->{'dateenrolled'});
30 $borr->{'expiry'}       = format_date($borr->{'expiry'});
31 $borr->{'dateofbirth'}  = format_date($borr->{'dateofbirth'});
32 $borr->{'ethnicity'}    = fixEthnicity($borr->{'ethnicity'});
33
34 if ($borr->{'amountoutstanding'} > 5) {
35     $borr->{'amountoverfive'} = 1;
36 }
37 if (5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
38     $borr->{'amountoverzero'} = 1;
39 }
40 if ($borr->{'amountoutstanding'} < 0) {
41     $borr->{'amountlessthanzero'} = 1;
42     $borr->{'amountoutstanding'} = -1*($borr->{'amountoutstanding'});
43 }
44
45 $borr->{'amountoutstanding'} = sprintf "\$%.02f", $borr->{'amountoutstanding'};
46
47 my @bordat;
48 $bordat[0] = $borr;
49
50 $template->param(BORROWER_INFO => \@bordat);
51 $template->param(borrowernumber => $borrowernumber);
52
53 #get issued items ....
54 my $issues = getissues($borr);
55
56 my $count = 0;
57 my $overdues_count = 0;
58 my @overdues;
59 my @issuedat;
60 foreach my $key (keys %$issues) {
61     my $issue = $issues->{$key};
62     $issue->{'date_due'}  = format_date($issue->{'date_due'});
63
64     # check for reserves
65     my ($restype, $res) = CheckReserves($issue->{'itemnumber'});
66     if ($restype) {
67         $issue->{'reserved'} = 1;
68     }
69
70     my ($numaccts,$accts,$total) = getboracctrecord(undef,$borr);
71     my $charges = 0;
72     foreach my $ac (@$accts) {
73         if ($ac->{'itemnumber'} == $issue->{'itemnumber'}) {
74             $charges += $ac->{'amountoutstanding'} if $ac->{'accounttype'} eq 'F'; 
75             $charges += $ac->{'amountoutstanding'} if $ac->{'accounttype'} eq 'L';
76         } 
77     }
78     $issue->{'charges'} = $charges;
79
80     # get publictype for icon
81     
82     my $publictype = $issue->{'publictype'};
83     $issue->{$publictype} = 1;
84
85     # check if item is renewable
86     my %env;
87     my $status = renewstatus(\%env,$borrowernumber, $issue->{'itemnumber'});
88
89     $issue->{'status'} = $status;
90
91     if ($issue->{'overdue'}) {
92         push @overdues, $issue;
93         $overdues_count++;
94         $issue->{'overdue'} = 1;
95     } else {
96         $issue->{'issued'} = 1;
97     }
98     push @issuedat, $issue;
99     $count++;
100 }
101
102 $template->param(ISSUES => \@issuedat);
103 $template->param(issues_count => $count);
104
105 $template->param(OVERDUES => \@overdues);
106 $template->param(overdues_count => $overdues_count);
107
108 my $branches = getbranches();
109
110 # now the reserved items....
111 my ($rcount, $reserves) = FindReserves(undef, $borrowernumber);
112 foreach my $res (@$reserves) {
113     $res->{'reservedate'}  = format_date($res->{'reservedate'});
114     my $publictype = $res->{'publictype'};
115     $res->{$publictype} = 1;
116     $res->{'waiting'} = 1 if $res->{'found'} eq 'W';
117     $res->{'branch'} = $branches->{$res->{'branchcode'}}->{'branchname'};
118 }
119
120 $template->param(RESERVES => $reserves);
121 $template->param(reserves_count => $rcount);
122
123 my @waiting;
124 my $wcount = 0;
125 foreach my $res (@$reserves) {
126     if ($res->{'itemnumber'}) {
127         $res->{'branch'} = $branches->{$res->{'branchcode'}}->{'branchname'};
128         push @waiting, $res;
129         $wcount++;
130     }
131 }
132
133 # $template->param(WAITING => \@waiting);
134 $template->param(waiting_count => $wcount);
135
136 output_html_with_http_headers $query, $cookie, $template->output;
137