Several changes: - add check in link to circulation checkouts listing
[koha.git] / opac / opac-user.pl
blob36395259f80951ffd6d5edec30d232919316b7bb
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
18 # $Id$
20 use strict;
21 require Exporter;
22 use CGI;
24 use C4::Auth;
25 use C4::Koha;
26 use C4::Circulation;
27 use C4::Reserves;
28 use C4::Members;
29 use C4::Output;
30 use C4::Biblio;
31 use C4::Date;
32 use C4::Letters;
33 use C4::Branch; # GetBranches
35 my $query = new CGI;
36 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
38 template_name => "opac-user.tmpl",
39 query => $query,
40 type => "opac",
41 authnotrequired => 0,
42 flagsrequired => { borrow => 1 },
43 debug => 1,
47 # get borrower information ....
48 my ( $borr, $flags ) = GetMemberDetails( $borrowernumber );
50 $borr->{'dateenrolled'} = format_date( $borr->{'dateenrolled'} );
51 $borr->{'expiry'} = format_date( $borr->{'expiry'} );
52 $borr->{'dateofbirth'} = format_date( $borr->{'dateofbirth'} );
53 $borr->{'ethnicity'} = fixEthnicity( $borr->{'ethnicity'} );
55 if ( $borr->{'debarred'} || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
56 $borr->{'flagged'} = 1;
59 if ( $borr->{'amountoutstanding'} > 5 ) {
60 $borr->{'amountoverfive'} = 1;
62 if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
63 $borr->{'amountoverzero'} = 1;
65 if ( $borr->{'amountoutstanding'} < 0 ) {
66 $borr->{'amountlessthanzero'} = 1;
67 $borr->{'amountoutstanding'} = -1 * ( $borr->{'amountoutstanding'} );
70 $borr->{'amountoutstanding'} = sprintf "%.02f", $borr->{'amountoutstanding'};
72 my @bordat;
73 $bordat[0] = $borr;
75 $template->param( BORROWER_INFO => \@bordat );
76 $template->param( borrowernumber => $borrowernumber );
78 #get issued items ....
79 my ($countissues,$issues) = GetPendingIssues($borrowernumber);
81 my $count = 0;
82 my $overdues_count = 0;
83 my @overdues;
84 my @issuedat;
85 my $imgdir = getitemtypeimagesrc();
86 my $itemtypes = GetItemTypes();
87 foreach my $issue ( @$issues ) {
89 # check for reserves
90 my ( $restype, $res ) = CheckReserves( $issue->{'itemnumber'} );
91 if ( $restype ) {
92 $issue->{'reserved'} = 1;
95 my ( $total , $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
96 my $charges = 0;
97 foreach my $ac (@$accts) {
98 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
99 $charges += $ac->{'amountoutstanding'}
100 if $ac->{'accounttype'} eq 'F';
101 $charges += $ac->{'amountoutstanding'}
102 if $ac->{'accounttype'} eq 'L';
105 $issue->{'charges'} = $charges;
107 # get publictype for icon
109 my $publictype = $issue->{'publictype'};
110 $issue->{$publictype} = 1;
112 # check if item is renewable
113 my $status = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} );
115 $issue->{'status'} = $status;
117 if ( $issue->{'overdue'} ) {
118 push @overdues, $issue;
119 $overdues_count++;
120 $issue->{'overdue'} = 1;
122 else {
123 $issue->{'issued'} = 1;
125 # imageurl:
126 my $itemtype = $issue->{'itemtype'};
127 if ( $itemtype ) {
128 $issue->{'imageurl'} = $imgdir."/".$itemtypes->{$itemtype}->{'imageurl'};
129 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
131 push @issuedat, $issue;
132 $count++;
135 $template->param( ISSUES => \@issuedat );
136 $template->param( issues_count => $count );
138 $template->param( OVERDUES => \@overdues );
139 $template->param( overdues_count => $overdues_count );
141 # load the branches
142 my $branches = GetBranches();
143 my @branch_loop;
144 for my $branch_hash ( keys %$branches ) {
145 my $selected=(C4::Context->userenv && ($branch_hash eq C4::Context->userenv->{branch})) if (C4::Context->preference('SearchMyLibraryFirst'));
146 push @branch_loop,
148 value => "branch: $branch_hash",
149 branchname => $branches->{$branch_hash}->{'branchname'},
150 selected => $selected
153 $template->param( branchloop => \@branch_loop, "mylibraryfirst"=>C4::Context->preference("SearchMyLibraryFirst"));
155 # now the reserved items....
156 my @reserves = GetReservesFromBorrowernumber( $borrowernumber );
157 foreach my $res (@reserves) {
158 $res->{'reservedate'} = format_date( $res->{'reservedate'} );
159 my $publictype = $res->{'publictype'};
160 $res->{$publictype} = 1;
161 $res->{'waiting'} = 1 if $res->{'found'} eq 'W';
162 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
163 my $biblioData = GetBiblioData($res->{'biblionumber'});
164 $res->{'reserves_title'} = $biblioData->{'title'};
167 # use Data::Dumper;
168 # warn Dumper(@reserves);
170 $template->param( RESERVES => \@reserves );
171 $template->param( reserves_count => $#reserves+1 );
173 my @waiting;
174 my $wcount = 0;
175 foreach my $res (@reserves) {
176 if ( $res->{'itemnumber'} ) {
177 my $item = GetItem( $res->{'itemnumber'});
178 $res->{'holdingbranch'} =
179 $branches->{ $item->{'holdingbranch'} }->{'branchname'};
180 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
181 # get document reserve status
182 my $biblioData = GetBiblioData($res->{'biblionumber'});
183 $res->{'waiting_title'} = $biblioData->{'title'};
184 if ( ( $res->{'found'} eq 'W' ) or ( $res->{'priority'} eq '0' ) ) {
185 my $item = $res->{'itemnumber'};
186 $item = GetBiblioFromItemNumber($item,undef);
187 $res->{'wait'}= 1;
188 $res->{'holdingbranch'}=$item->{'holdingbranch'};
189 $res->{'biblionumber'}=$item->{'biblionumber'};
190 $res->{'barcodenumber'} = $item->{'barcode'};
191 $res->{'wbrcode'} = $res->{'branchcode'};
192 $res->{'itemnumber'} = $res->{'itemnumber'};
193 $res->{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
194 if($res->{'holdingbranch'} eq $res->{'wbrcode'}){
195 $res->{'atdestination'} = 1;
197 # set found to 1 if reserve is waiting for patron pickup
198 $res->{'found'} = 1 if $res->{'found'} eq 'W';
200 push @waiting, $res;
201 $wcount++;
205 $template->param( WAITING => \@waiting );
207 # current alert subscriptions
208 my $alerts = getalert($borrowernumber);
209 foreach ( @$alerts ) {
210 $_->{ $_->{type} } = 1;
211 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
214 $template->param(
215 waiting_count => $wcount,
216 textmessaging => $borr->{textmessaging},
219 output_html_with_http_headers $query, $cookie, $template->output;