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);
85 my $overdues_count = 0;
88 my $imgdir = getitemtypeimagesrc();
89 my $itemtypes = GetItemTypes();
90 foreach my $issue ( @$issues ) {
91 if($count%2 eq 0){ $issue->{'toggle'} = 1; } else { $issue->{'toggle'} = 0; }
93 my ( $restype, $res ) = CheckReserves( $issue->{'itemnumber'} );
95 $issue->{'reserved'} = 1;
98 my ( $total , $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
100 foreach my $ac (@$accts) {
101 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
102 $charges += $ac->{'amountoutstanding'}
103 if $ac->{'accounttype'} eq 'F';
104 $charges += $ac->{'amountoutstanding'}
105 if $ac->{'accounttype'} eq 'L';
108 $issue->{'charges'} = $charges;
110 # get publictype for icon
112 my $publictype = $issue->{'publictype'};
113 $issue->{$publictype} = 1;
115 # check if item is renewable
116 my $status = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} );
117 ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount($borrowernumber, $issue->{'itemnumber'});
119 $issue->{'status'} = $status;
121 if ( $issue->{'overdue'} ) {
122 push @overdues, $issue;
124 $issue->{'overdue'} = 1;
127 $issue->{'issued'} = 1;
130 my $itemtype = $issue->{'itemtype'};
132 $issue->{'imageurl'} = $imgdir."/".$itemtypes->{$itemtype}->{'imageurl'};
133 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
135 push @issuedat, $issue;
139 $template->param( ISSUES => \@issuedat );
140 $template->param( issues_count => $count );
142 $template->param( OVERDUES => \@overdues );
143 $template->param( overdues_count => $overdues_count );
146 my $branches = GetBranches();
148 for my $branch_hash (sort keys %$branches ) {
149 my $selected=(C4::Context->userenv && ($branch_hash eq C4::Context->userenv->{branch})) if (C4::Context->preference('SearchMyLibraryFirst'));
152 value => "branch: $branch_hash",
153 branchname => $branches->{$branch_hash}->{'branchname'},
154 selected => $selected
157 $template->param( branchloop => \@branch_loop, "mylibraryfirst"=>C4::Context->preference("SearchMyLibraryFirst"));
159 # now the reserved items....
160 my @reserves = GetReservesFromBorrowernumber( $borrowernumber );
161 foreach my $res (@reserves) {
162 $res->{'reservedate'} = format_date( $res->{'reservedate'} );
163 my $publictype = $res->{'publictype'};
164 $res->{$publictype} = 1;
165 $res->{'waiting'} = 1 if $res->{'found'} eq 'W';
166 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
167 my $biblioData = GetBiblioData($res->{'biblionumber'});
168 $res->{'reserves_title'} = $biblioData->{'title'};
172 # warn Dumper(@reserves);
174 $template->param( RESERVES => \@reserves );
175 $template->param( reserves_count => $#reserves+1 );
179 foreach my $res (@reserves) {
180 if ( $res->{'itemnumber'} ) {
181 my $item = GetItem( $res->{'itemnumber'});
182 $res->{'holdingbranch'} =
183 $branches->{ $item->{'holdingbranch'} }->{'branchname'};
184 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
185 # get document reserve status
186 my $biblioData = GetBiblioData($res->{'biblionumber'});
187 $res->{'waiting_title'} = $biblioData->{'title'};
188 if ( ( $res->{'found'} eq 'W' ) or ( $res->{'priority'} eq '0' ) ) {
189 my $item = $res->{'itemnumber'};
190 $item = GetBiblioFromItemNumber($item,undef);
192 $res->{'holdingbranch'}=$item->{'holdingbranch'};
193 $res->{'biblionumber'}=$item->{'biblionumber'};
194 $res->{'barcodenumber'} = $item->{'barcode'};
195 $res->{'wbrcode'} = $res->{'branchcode'};
196 $res->{'itemnumber'} = $res->{'itemnumber'};
197 $res->{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
198 if($res->{'holdingbranch'} eq $res->{'wbrcode'}){
199 $res->{'atdestination'} = 1;
201 # set found to 1 if reserve is waiting for patron pickup
202 $res->{'found'} = 1 if $res->{'found'} eq 'W';
209 $template->param( WAITING => \@waiting );
211 # current alert subscriptions
212 my $alerts = getalert($borrowernumber);
213 foreach ( @$alerts ) {
214 $_->{ $_->{type} } = 1;
215 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
219 waiting_count => $wcount,
220 textmessaging => $borr->{textmessaging},
223 output_html_with_http_headers $query, $cookie, $template->output;