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
16 # with Koha; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #use warnings; FIXME - Bug 2505
30 use C4
::Members
::AttributeTypes
;
31 use C4
::Members
::Attributes qw
/GetBorrowerAttributeValue/;
36 use C4
::Branch
; # GetBranches
39 use constant ATTRIBUTE_SHOW_BARCODE
=> 'SHOW_BCODE';
50 if (C4
::Context
->preference('BakerTaylorEnabled')) {
51 require C4
::External
::BakerTaylor
;
52 import C4
::External
::BakerTaylor
qw(&image_url &link_url);
56 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
58 template_name
=> "opac-user.tmpl",
62 flagsrequired
=> { borrow
=> 1 },
68 for ( C4
::Context
->preference("OPACShowHoldQueueDetails") ) {
69 m/priority/ and $show_priority = 1;
72 my $patronupdate = $query->param('patronupdate');
75 # get borrower information ....
76 my ( $borr ) = GetMemberDetails
( $borrowernumber );
78 my ( $today_year, $today_month, $today_day) = Today
();
79 my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
81 $borr->{'ethnicity'} = fixEthnicity
( $borr->{'ethnicity'} );
83 my $debar = $borr->{'debarred'};
88 $template->param( 'userdebarred' => $userdebarred );
89 if ( $debar ne "9999-12-31" ) {
90 $borr->{'userdebarreddate'} = $debar;
94 if ( $userdebarred || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
95 $borr->{'flagged'} = 1;
99 if ( $borr->{'amountoutstanding'} > 5 ) {
100 $borr->{'amountoverfive'} = 1;
102 if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
103 $borr->{'amountoverzero'} = 1;
105 my $no_renewal_amt = C4
::Context
->preference( 'OPACFineNoRenewals' );
106 $no_renewal_amt ||= 0;
108 if ( C4
::Context
->preference( 'OpacRenewalAllowed' ) && $borr->{amountoutstanding
} > $no_renewal_amt ) {
109 $borr->{'flagged'} = 1;
112 renewal_blocked_fines
=> sprintf( '%.02f', $no_renewal_amt ),
113 renewal_blocked_fines_amountoutstanding
=> sprintf( '%.02f', $borr->{amountoutstanding
} ),
117 if ( $borr->{'amountoutstanding'} < 0 ) {
118 $borr->{'amountlessthanzero'} = 1;
119 $borr->{'amountoutstanding'} = -1 * ( $borr->{'amountoutstanding'} );
122 $borr->{'amountoutstanding'} = sprintf "%.02f", $borr->{'amountoutstanding'};
127 # Warningdate is the date that the warning starts appearing
128 if ( $borr->{'dateexpiry'} && C4
::Context
->preference('NotifyBorrowerDeparture') ) {
129 my $days_to_expiry = Date_to_Days
( $warning_year, $warning_month, $warning_day ) - Date_to_Days
( $today_year, $today_month, $today_day );
130 if ( $days_to_expiry < 0 ) {
131 #borrower card has expired, warn the borrower
132 $borr->{'warnexpired'} = $borr->{'dateexpiry'};
133 } elsif ( $days_to_expiry < C4
::Context
->preference('NotifyBorrowerDeparture') ) {
134 # borrower card soon to expire, warn the borrower
135 $borr->{'warndeparture'} = $borr->{dateexpiry
};
136 if (C4
::Context
->preference('ReturnBeforeExpiry')){
137 $borr->{'returnbeforeexpiry'} = 1;
142 # pass on any renew errors to the template for displaying
143 my $renew_error = $query->param('renew_error');
145 $template->param( BORROWER_INFO
=> \
@bordat,
146 borrowernumber
=> $borrowernumber,
147 patron_flagged
=> $borr->{flagged
},
148 OPACMySummaryHTML
=> (C4
::Context
->preference("OPACMySummaryHTML")) ?
1 : 0,
149 surname
=> $borr->{surname
},
150 showname
=> $borr->{showname
},
151 RENEW_ERROR
=> $renew_error,
155 #get issued items ....
158 my $overdues_count = 0;
161 my $itemtypes = GetItemTypes
();
162 my $issues = GetPendingIssues
($borrowernumber);
164 foreach my $issue ( sort { $b->{date_due
}->datetime() cmp $a->{date_due
}->datetime() } @
{$issues} ) {
166 my $restype = GetReserveStatus
( $issue->{'itemnumber'} );
168 $issue->{'reserved'} = 1;
171 my ( $total , $accts, $numaccts) = GetMemberAccountRecords
( $borrowernumber );
173 foreach my $ac (@
$accts) {
174 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
175 $charges += $ac->{'amountoutstanding'}
176 if $ac->{'accounttype'} eq 'F';
177 $charges += $ac->{'amountoutstanding'}
178 if $ac->{'accounttype'} eq 'FU';
179 $charges += $ac->{'amountoutstanding'}
180 if $ac->{'accounttype'} eq 'L';
183 $issue->{'charges'} = $charges;
184 $issue->{'subtitle'} = GetRecordValue
('subtitle', GetMarcBiblio
($issue->{'biblionumber'}), GetFrameworkCode
($issue->{'biblionumber'}));
185 # check if item is renewable
186 my ($status,$renewerror) = CanBookBeRenewed
( $borrowernumber, $issue->{'itemnumber'} );
187 ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount
($borrowernumber, $issue->{'itemnumber'});
188 if($status && C4
::Context
->preference("OpacRenewalAllowed")){
189 $issue->{'status'} = $status;
193 $issue->{'too_many'} = 1 if $renewerror eq 'too_many';
194 $issue->{'on_reserve'} = 1 if $renewerror eq 'on_reserve';
196 if ( $renewerror eq 'too_soon' ) {
197 $issue->{'too_soon'} = 1;
198 $issue->{'soonestrenewdate'} = output_pref
(
199 C4
::Circulation
::GetSoonestRenewDate
(
200 $issue->{borrowernumber
},
207 if ( $issue->{'overdue'} ) {
208 push @overdues, $issue;
210 $issue->{'overdue'} = 1;
213 $issue->{'issued'} = 1;
216 my $itemtype = $issue->{'itemtype'};
218 $issue->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
219 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
221 push @issuedat, $issue;
224 my $isbn = GetNormalizedISBN
($issue->{'isbn'});
225 $issue->{normalized_isbn
} = $isbn;
228 if (my $my_summary_html = C4
::Context
->preference('OPACMySummaryHTML')){
229 $issue->{author
} ?
$my_summary_html =~ s/{AUTHOR}/$issue->{author}/g : $my_summary_html =~ s/{AUTHOR}//g;
230 $issue->{title
} =~ s/\/+$//; # remove trailing slash
231 $issue->{title
} =~ s/\s+$//; # remove trailing space
232 $issue->{title
} ?
$my_summary_html =~ s/{TITLE}/$issue->{title}/g : $my_summary_html =~ s/{TITLE}//g;
233 $issue->{isbn
} ?
$my_summary_html =~ s/{ISBN}/$isbn/g : $my_summary_html =~ s/{ISBN}//g;
234 $issue->{biblionumber
} ?
$my_summary_html =~ s/{BIBLIONUMBER}/$issue->{biblionumber}/g : $my_summary_html =~ s/{BIBLIONUMBER}//g;
235 $issue->{MySummaryHTML
} = $my_summary_html;
239 $template->param( ISSUES
=> \
@issuedat );
240 $template->param( issues_count
=> $count );
241 $template->param( canrenew
=> $canrenew );
242 $template->param( OVERDUES
=> \
@overdues );
243 $template->param( overdues_count
=> $overdues_count );
245 my $show_barcode = C4
::Members
::AttributeTypes
::AttributeTypeExists
( ATTRIBUTE_SHOW_BARCODE
);
247 my $patron_show_barcode = GetBorrowerAttributeValue
($borrowernumber, ATTRIBUTE_SHOW_BARCODE
);
248 undef $show_barcode if defined($patron_show_barcode) && !$patron_show_barcode;
250 $template->param( show_barcode
=> 1 ) if $show_barcode;
253 my $branches = GetBranches
();
255 for my $branch_hash ( sort keys %{$branches} ) {
257 if ( C4
::Context
->preference('SearchMyLibraryFirst') ) {
259 ( C4
::Context
->userenv
260 && ( $branch_hash eq C4
::Context
->userenv->{branch
} ) );
263 { value
=> "branch: $branch_hash",
264 branchname
=> $branches->{$branch_hash}->{'branchname'},
265 selected
=> $selected,
268 $template->param( branchloop
=> \
@branch_loop );
270 # now the reserved items....
271 my @reserves = GetReservesFromBorrowernumber
( $borrowernumber );
272 foreach my $res (@reserves) {
274 if ( $res->{'expirationdate'} eq '0000-00-00' ) {
275 $res->{'expirationdate'} = '';
277 $res->{'subtitle'} = GetRecordValue
('subtitle', GetMarcBiblio
($res->{'biblionumber'}), GetFrameworkCode
($res->{'biblionumber'}));
278 $res->{'waiting'} = 1 if $res->{'found'} eq 'W';
279 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
280 my $biblioData = GetBiblioData
($res->{'biblionumber'});
281 $res->{'reserves_title'} = $biblioData->{'title'};
282 $res->{'author'} = $biblioData->{'author'};
284 if ($show_priority) {
285 $res->{'priority'} ||= '';
287 $res->{'suspend_until'} = C4
::Dates
->new( $res->{'suspend_until'}, "iso")->output("syspref") if ( $res->{'suspend_until'} );
291 # warn Dumper(@reserves);
293 $template->param( RESERVES
=> \
@reserves );
294 $template->param( reserves_count
=> $#reserves+1 );
295 $template->param( showpriority
=>$show_priority );
299 foreach my $res (@reserves) {
300 if ( $res->{'itemnumber'} ) {
301 my $item = GetItem
( $res->{'itemnumber'});
302 $res->{'holdingbranch'} =
303 $branches->{ $item->{'holdingbranch'} }->{'branchname'};
304 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
305 # get document reserve status
306 my $biblioData = GetBiblioData
($res->{'biblionumber'});
307 $res->{'waiting_title'} = $biblioData->{'title'};
308 if ( ( $res->{'found'} eq 'W' ) ) {
309 my $item = $res->{'itemnumber'};
310 $item = GetBiblioFromItemNumber
($item,undef);
312 $res->{'holdingbranch'}=$item->{'holdingbranch'};
313 $res->{'biblionumber'}=$item->{'biblionumber'};
314 $res->{'barcode'} = $item->{'barcode'};
315 $res->{'wbrcode'} = $res->{'branchcode'};
316 $res->{'itemnumber'} = $res->{'itemnumber'};
317 $res->{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
318 if($res->{'holdingbranch'} eq $res->{'wbrcode'}){
319 $res->{'atdestination'} = 1;
321 # set found to 1 if reserve is waiting for patron pickup
322 $res->{'found'} = 1 if $res->{'found'} eq 'W';
324 my ($transfertwhen, $transfertfrom, $transfertto) = GetTransfers
( $res->{'itemnumber'} );
325 if ($transfertwhen) {
326 $res->{intransit
} = 1;
327 $res->{datesent
} = $transfertwhen;
328 $res->{frombranch
} = GetBranchName
($transfertfrom);
335 #$res->{'cancelable'} = 1 if ($res->{'wait'} && $res->{'atdestination'} && $res->{'found'} ne "1");
336 $res->{'cancelable'} = 1 if ($res->{wait} and not $res->{found
}) or (not $res->{wait} and not $res->{intransit
});
340 $template->param( WAITING
=> \
@waiting );
342 # current alert subscriptions
343 my $alerts = getalert
($borrowernumber);
344 foreach ( @
$alerts ) {
345 $_->{ $_->{type
} } = 1;
346 $_->{relatedto
} = findrelatedto
( $_->{type
}, $_->{externalid
} );
349 if (C4
::Context
->preference('BakerTaylorEnabled')) {
351 BakerTaylorEnabled
=> 1,
352 BakerTaylorImageURL
=> &image_url
(),
353 BakerTaylorLinkURL
=> &link_url
(),
354 BakerTaylorBookstoreURL
=> C4
::Context
->preference('BakerTaylorBookstoreURL'),
358 if (C4
::Context
->preference("OPACAmazonCoverImages") or
359 C4
::Context
->preference("GoogleJackets") or
360 C4
::Context
->preference("BakerTaylorEnabled") or
361 C4
::Context
->preference("SyndeticsCoverImages")) {
362 $template->param(JacketImages
=>1);
365 if ( GetMessagesCount
( $borrowernumber, 'B' ) ) {
366 $template->param( bor_messages
=> 1 );
369 if ( $borr->{'opacnote'} ) {
372 opacnote
=> $borr->{'opacnote'},
377 bor_messages_loop
=> GetMessages
( $borrowernumber, 'B', 'NONE' ),
378 waiting_count
=> $wcount,
379 patronupdate
=> $patronupdate,
380 OpacRenewalAllowed
=> C4
::Context
->preference("OpacRenewalAllowed"),
385 SuspendHoldsOpac
=> C4
::Context
->preference('SuspendHoldsOpac'),
386 AutoResumeSuspendedHolds
=> C4
::Context
->preference('AutoResumeSuspendedHolds'),
387 OpacHoldNotes
=> C4
::Context
->preference('OpacHoldNotes'),
390 output_html_with_http_headers
$query, $cookie, $template->output;