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
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
32 use C4::Branch; # GetBranches
35 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
37 template_name => "opac-user.tmpl",
41 flagsrequired => { borrow => 1 },
46 # get borrower information ....
47 my ( $borr, $flags ) = GetMemberDetails( $borrowernumber );
49 $borr->{'dateenrolled'} = format_date( $borr->{'dateenrolled'} );
50 $borr->{'expiry'} = format_date( $borr->{'expiry'} );
51 $borr->{'dateofbirth'} = format_date( $borr->{'dateofbirth'} );
52 $borr->{'ethnicity'} = fixEthnicity( $borr->{'ethnicity'} );
54 if ( $borr->{'debarred'} || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
55 $borr->{'flagged'} = 1;
57 # $make flagged available everywhere in the template
58 my $patron_flagged = $borr->{'flagged'};
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'};
75 $template->param( BORROWER_INFO => \@bordat,
76 borrowernumber => $borrowernumber,
77 patron_flagged => $patron_flagged,
80 #get issued items ....
81 my ($countissues,$issues) = GetPendingIssues($borrowernumber);
84 my $overdues_count = 0;
87 my $imgdir = getitemtypeimagesrc();
88 my $itemtypes = GetItemTypes();
89 foreach my $issue ( @$issues ) {
92 my ( $restype, $res ) = CheckReserves( $issue->{'itemnumber'} );
94 $issue->{'reserved'} = 1;
97 my ( $total , $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
99 foreach my $ac (@$accts) {
100 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
101 $charges += $ac->{'amountoutstanding'}
102 if $ac->{'accounttype'} eq 'F';
103 $charges += $ac->{'amountoutstanding'}
104 if $ac->{'accounttype'} eq 'L';
107 $issue->{'charges'} = $charges;
109 # get publictype for icon
111 my $publictype = $issue->{'publictype'};
112 $issue->{$publictype} = 1;
114 # check if item is renewable
115 my $status = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} );
117 $issue->{'status'} = $status;
119 if ( $issue->{'overdue'} ) {
120 push @overdues, $issue;
122 $issue->{'overdue'} = 1;
125 $issue->{'issued'} = 1;
128 my $itemtype = $issue->{'itemtype'};
130 $issue->{'imageurl'} = $imgdir."/".$itemtypes->{$itemtype}->{'imageurl'};
131 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
133 push @issuedat, $issue;
137 $template->param( ISSUES => \@issuedat );
138 $template->param( issues_count => $count );
140 $template->param( OVERDUES => \@overdues );
141 $template->param( overdues_count => $overdues_count );
144 my $branches = GetBranches();
146 for my $branch_hash (sort keys %$branches ) {
147 my $selected=(C4::Context->userenv && ($branch_hash eq C4::Context->userenv->{branch})) if (C4::Context->preference('SearchMyLibraryFirst'));
150 value => "branch: $branch_hash",
151 branchname => $branches->{$branch_hash}->{'branchname'},
152 selected => $selected
155 $template->param( branchloop => \@branch_loop, "mylibraryfirst"=>C4::Context->preference("SearchMyLibraryFirst"));
157 # now the reserved items....
158 my @reserves = GetReservesFromBorrowernumber( $borrowernumber );
159 foreach my $res (@reserves) {
160 $res->{'reservedate'} = format_date( $res->{'reservedate'} );
161 my $publictype = $res->{'publictype'};
162 $res->{$publictype} = 1;
163 $res->{'waiting'} = 1 if $res->{'found'} eq 'W';
164 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
165 my $biblioData = GetBiblioData($res->{'biblionumber'});
166 $res->{'reserves_title'} = $biblioData->{'title'};
170 # warn Dumper(@reserves);
172 $template->param( RESERVES => \@reserves );
173 $template->param( reserves_count => $#reserves+1 );
177 foreach my $res (@reserves) {
178 if ( $res->{'itemnumber'} ) {
179 my $item = GetItem( $res->{'itemnumber'});
180 $res->{'holdingbranch'} =
181 $branches->{ $item->{'holdingbranch'} }->{'branchname'};
182 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
183 # get document reserve status
184 my $biblioData = GetBiblioData($res->{'biblionumber'});
185 $res->{'waiting_title'} = $biblioData->{'title'};
186 if ( ( $res->{'found'} eq 'W' ) or ( $res->{'priority'} eq '0' ) ) {
187 my $item = $res->{'itemnumber'};
188 $item = GetBiblioFromItemNumber($item,undef);
190 $res->{'holdingbranch'}=$item->{'holdingbranch'};
191 $res->{'biblionumber'}=$item->{'biblionumber'};
192 $res->{'barcodenumber'} = $item->{'barcode'};
193 $res->{'wbrcode'} = $res->{'branchcode'};
194 $res->{'itemnumber'} = $res->{'itemnumber'};
195 $res->{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
196 if($res->{'holdingbranch'} eq $res->{'wbrcode'}){
197 $res->{'atdestination'} = 1;
199 # set found to 1 if reserve is waiting for patron pickup
200 $res->{'found'} = 1 if $res->{'found'} eq 'W';
207 $template->param( WAITING => \@waiting );
209 # current alert subscriptions
210 my $alerts = getalert($borrowernumber);
211 foreach ( @$alerts ) {
212 $_->{ $_->{type} } = 1;
213 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
217 waiting_count => $wcount,
218 textmessaging => $borr->{textmessaging},
221 output_html_with_http_headers $query, $cookie, $template->output;