3 # This file is part of Koha.
4 # parts copyright 2010 BibLibre
6 # Koha is free software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any later
11 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along with
16 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
17 # Suite 330, Boston, MA 02111-1307 USA
21 #use warnings; FIXME - Bug 2505
33 use C4
::Dates qw
/format_date/;
35 use C4
::Branch
; # GetBranches
40 if (C4
::Context
->preference('BakerTaylorEnabled')) {
41 require C4
::External
::BakerTaylor
;
42 import C4
::External
::BakerTaylor
qw(&image_url &link_url);
46 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
48 template_name
=> "opac-user.tmpl",
52 flagsrequired
=> { borrow
=> 1 },
57 my $OPACDisplayRequestPriority = (C4
::Context
->preference("OPACDisplayRequestPriority")) ?
1 : 0;
58 my $patronupdate = $query->param('patronupdate');
60 # get borrower information ....
61 my ( $borr ) = GetMemberDetails
( $borrowernumber );
63 for (qw(dateenrolled dateexpiry dateofbirth)) {
64 ($borr->{$_}) and $borr->{$_} = format_date
($borr->{$_});
66 $borr->{'ethnicity'} = fixEthnicity
( $borr->{'ethnicity'} );
68 if ( $borr->{'debarred'} || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
69 $borr->{'flagged'} = 1;
72 if ( $borr->{'amountoutstanding'} > 5 ) {
73 $borr->{'amountoverfive'} = 1;
75 if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
76 $borr->{'amountoverzero'} = 1;
79 if ( $borr->{'amountoutstanding'} > C4
::Context
->preference( 'OPACFineNoRenewals' ) ) {
80 $borr->{'flagged'} = 1;
82 renewal_blocked_fines
=> sprintf( "%.02f", C4
::Context
->preference( 'OPACFineNoRenewals' ) ),
86 if ( $borr->{'amountoutstanding'} < 0 ) {
87 $borr->{'amountlessthanzero'} = 1;
88 $borr->{'amountoutstanding'} = -1 * ( $borr->{'amountoutstanding'} );
91 $borr->{'amountoutstanding'} = sprintf "%.02f", $borr->{'amountoutstanding'};
96 $template->param( BORROWER_INFO
=> \
@bordat,
97 borrowernumber
=> $borrowernumber,
98 patron_flagged
=> $borr->{flagged
},
101 #get issued items ....
105 my $overdues_count = 0;
108 my $itemtypes = GetItemTypes
();
109 my ($issues) = GetPendingIssues
($borrowernumber);
111 foreach my $issue ( sort sort { $b->{'date_due'} cmp $a->{'date_due'} } @
$issues ) {
113 my ( $restype, $res ) = CheckReserves
( $issue->{'itemnumber'} );
115 $issue->{'reserved'} = 1;
118 my ( $total , $accts, $numaccts) = GetMemberAccountRecords
( $borrowernumber );
120 foreach my $ac (@
$accts) {
121 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
122 $charges += $ac->{'amountoutstanding'}
123 if $ac->{'accounttype'} eq 'F';
124 $charges += $ac->{'amountoutstanding'}
125 if $ac->{'accounttype'} eq 'L';
128 $issue->{'charges'} = $charges;
130 # get publictype for icon
132 my $publictype = $issue->{'publictype'};
133 $issue->{$publictype} = 1;
135 # check if item is renewable
136 my ($status,$renewerror) = CanBookBeRenewed
( $borrowernumber, $issue->{'itemnumber'} );
137 ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount
($borrowernumber, $issue->{'itemnumber'});
138 $issue->{'status'} = $status && C4
::Context
->preference("OpacRenewalAllowed");
139 $issue->{'too_many'} = 1 if $renewerror and $renewerror eq 'too_many';
140 $issue->{'on_reserve'} = 1 if $renewerror and $renewerror eq 'on_reserve';
142 if ( $issue->{'overdue'} ) {
143 push @overdues, $issue;
145 $issue->{'overdue'} = 1;
148 $issue->{'issued'} = 1;
151 my $itemtype = $issue->{'itemtype'};
153 $issue->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
154 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
156 $issue->{date_due
} = format_date
($issue->{date_due
});
157 push @issuedat, $issue;
160 my $isbn = GetNormalizedISBN
($issue->{'isbn'});
161 $issue->{normalized_isbn
} = $isbn;
164 $template->param( ISSUES
=> \
@issuedat );
165 $template->param( issues_count
=> $count );
167 $template->param( OVERDUES
=> \
@overdues );
168 $template->param( overdues_count
=> $overdues_count );
171 my $branches = GetBranches
();
173 for my $branch_hash (sort keys %$branches ) {
174 my $selected=(C4
::Context
->userenv && ($branch_hash eq C4
::Context
->userenv->{branch
})) if (C4
::Context
->preference('SearchMyLibraryFirst'));
177 value
=> "branch: $branch_hash",
178 branchname
=> $branches->{$branch_hash}->{'branchname'},
179 selected
=> $selected
182 $template->param( branchloop
=> \
@branch_loop );
184 # now the reserved items....
185 my @reserves = GetReservesFromBorrowernumber
( $borrowernumber );
186 foreach my $res (@reserves) {
187 $res->{'reservedate'} = format_date
( $res->{'reservedate'} );
189 if ( $res->{'expirationdate'} ne '0000-00-00' ) {
190 $res->{'expirationdate'} = format_date
( $res->{'expirationdate'} )
192 $res->{'expirationdate'} = '';
195 my $publictype = $res->{'publictype'};
196 $res->{$publictype} = 1;
197 $res->{'waiting'} = 1 if $res->{'found'} eq 'W';
198 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
199 my $biblioData = GetBiblioData
($res->{'biblionumber'});
200 $res->{'reserves_title'} = $biblioData->{'title'};
201 if ($OPACDisplayRequestPriority) {
202 $res->{'priority'} = '' if $res->{'priority'} eq '0';
207 # warn Dumper(@reserves);
209 $template->param( RESERVES
=> \
@reserves );
210 $template->param( reserves_count
=> $#reserves+1 );
211 $template->param( showpriority
=>1 ) if $OPACDisplayRequestPriority;
215 foreach my $res (@reserves) {
216 if ( $res->{'itemnumber'} ) {
217 my $item = GetItem
( $res->{'itemnumber'});
218 $res->{'holdingbranch'} =
219 $branches->{ $item->{'holdingbranch'} }->{'branchname'};
220 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
221 # get document reserve status
222 my $biblioData = GetBiblioData
($res->{'biblionumber'});
223 $res->{'waiting_title'} = $biblioData->{'title'};
224 if ( ( $res->{'found'} eq 'W' ) ) {
225 my $item = $res->{'itemnumber'};
226 $item = GetBiblioFromItemNumber
($item,undef);
228 $res->{'holdingbranch'}=$item->{'holdingbranch'};
229 $res->{'biblionumber'}=$item->{'biblionumber'};
230 $res->{'barcodenumber'} = $item->{'barcode'};
231 $res->{'wbrcode'} = $res->{'branchcode'};
232 $res->{'itemnumber'} = $res->{'itemnumber'};
233 $res->{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
234 if($res->{'holdingbranch'} eq $res->{'wbrcode'}){
235 $res->{'atdestination'} = 1;
237 # set found to 1 if reserve is waiting for patron pickup
238 $res->{'found'} = 1 if $res->{'found'} eq 'W';
240 my ($transfertwhen, $transfertfrom, $transfertto) = GetTransfers
( $res->{'itemnumber'} );
241 if ($transfertwhen) {
242 $res->{intransit
} = 1;
243 $res->{datesent
} = format_date
($transfertwhen);
244 $res->{frombranch
} = GetBranchName
($transfertfrom);
251 #$res->{'cancelable'} = 1 if ($res->{'wait'} && $res->{'atdestination'} && $res->{'found'} ne "1");
252 $res->{'cancelable'} = 1 if ($res->{wait} and not $res->{found
}) or (not $res->{wait} and not $res->{intransit
});
256 $template->param( WAITING
=> \
@waiting );
258 # current alert subscriptions
259 my $alerts = getalert
($borrowernumber);
260 foreach ( @
$alerts ) {
261 $_->{ $_->{type
} } = 1;
262 $_->{relatedto
} = findrelatedto
( $_->{type
}, $_->{externalid
} );
265 if (C4
::Context
->preference('BakerTaylorEnabled')) {
267 BakerTaylorEnabled
=> 1,
268 BakerTaylorImageURL
=> &image_url
(),
269 BakerTaylorLinkURL
=> &link_url
(),
270 BakerTaylorBookstoreURL
=> C4
::Context
->preference('BakerTaylorBookstoreURL'),
274 if (C4
::Context
->preference("OPACAmazonCoverImages") or
275 C4
::Context
->preference("GoogleJackets") or
276 C4
::Context
->preference("BakerTaylorEnabled") or
277 C4
::Context
->preference("SyndeticsCoverImages")) {
278 $template->param(JacketImages
=>1);
281 if ( GetMessagesCount
( $borrowernumber, 'B' ) ) {
282 $template->param( bor_messages
=> 1 );
285 if ( $borr->{'opacnote'} ) {
288 opacnote
=> $borr->{'opacnote'},
293 bor_messages_loop
=> GetMessages
( $borrowernumber, 'B', 'NONE' ),
294 waiting_count
=> $wcount,
295 textmessaging
=> $borr->{textmessaging
},
296 patronupdate
=> $patronupdate,
297 OpacRenewalAllowed
=> C4
::Context
->preference("OpacRenewalAllowed"),
299 dateformat
=> C4
::Context
->preference("dateformat"),
302 output_html_with_http_headers
$query, $cookie, $template->output;