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
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 #use warnings; FIXME - Bug 2505
30 use C4::Members::AttributeTypes;
31 use C4::Members::Attributes qw/GetBorrowerAttributeValue/;
36 use C4::Branch; # GetBranches
38 use Koha::Patron::Debarments qw(IsDebarred);
41 use Koha::Patron::Messages;
42 use Koha::Patron::Discharge;
44 use constant ATTRIBUTE_SHOW_BARCODE => 'SHOW_BCODE';
46 use Scalar::Util qw(looks_like_number);
56 if (C4::Context->preference('BakerTaylorEnabled')) {
57 require C4::External::BakerTaylor;
58 import C4::External::BakerTaylor qw(&image_url &link_url);
62 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
64 template_name => "opac-user.tt",
72 my %renewed = map { $_ => 1 } split( ':', $query->param('renewed') );
75 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
76 m/priority/ and $show_priority = 1;
79 my $patronupdate = $query->param('patronupdate');
82 $template->param( shibbolethAuthentication => C4::Context->config('useshibboleth') );
84 if (!$borrowernumber) {
85 $template->param( adminWarning => 1 );
88 # get borrower information ....
89 my ( $borr ) = GetMemberDetails( $borrowernumber );
91 my ( $today_year, $today_month, $today_day) = Today();
92 my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
94 my $debar = IsDebarred($borrowernumber);
99 $template->param( 'userdebarred' => $userdebarred );
100 if ( $debar ne "9999-12-31" ) {
101 $borr->{'userdebarreddate'} = $debar;
103 # FIXME looks like $available is not needed
104 # If a patron is discharged he has a validated discharge available
105 my $available = Koha::Patron::Discharge::count({
106 borrowernumber => $borrowernumber,
109 $template->param( 'discharge_available' => $available && Koha::Patron::Discharge::is_discharged({borrowernumber => $borrowernumber}) );
112 if ( $userdebarred || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
113 $borr->{'flagged'} = 1;
117 if ( $borr->{'amountoutstanding'} > 5 ) {
118 $borr->{'amountoverfive'} = 1;
120 if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
121 $borr->{'amountoverzero'} = 1;
123 my $no_renewal_amt = C4::Context->preference( 'OPACFineNoRenewals' );
124 $no_renewal_amt = undef unless looks_like_number( $no_renewal_amt );
126 if ( C4::Context->preference('OpacRenewalAllowed')
127 && defined($no_renewal_amt)
128 && $borr->{amountoutstanding} > $no_renewal_amt )
130 $borr->{'flagged'} = 1;
133 renewal_blocked_fines => $no_renewal_amt,
134 renewal_blocked_fines_amountoutstanding => $borr->{amountoutstanding},
138 if ( $borr->{'amountoutstanding'} < 0 ) {
139 $borr->{'amountlessthanzero'} = 1;
140 $borr->{'amountoutstanding'} = -1 * ( $borr->{'amountoutstanding'} );
143 # Warningdate is the date that the warning starts appearing
144 if ( $borr->{'dateexpiry'} && C4::Context->preference('NotifyBorrowerDeparture') ) {
145 my $days_to_expiry = Date_to_Days( $warning_year, $warning_month, $warning_day ) - Date_to_Days( $today_year, $today_month, $today_day );
146 if ( $days_to_expiry < 0 ) {
147 #borrower card has expired, warn the borrower
148 $borr->{'warnexpired'} = $borr->{'dateexpiry'};
149 } elsif ( $days_to_expiry < C4::Context->preference('NotifyBorrowerDeparture') ) {
150 # borrower card soon to expire, warn the borrower
151 $borr->{'warndeparture'} = $borr->{dateexpiry};
152 if (C4::Context->preference('ReturnBeforeExpiry')){
153 $borr->{'returnbeforeexpiry'} = 1;
158 # pass on any renew errors to the template for displaying
159 my $renew_error = $query->param('renew_error');
161 $template->param( BORROWER_INFO => $borr,
162 borrowernumber => $borrowernumber,
163 patron_flagged => $borr->{flagged},
164 OPACMySummaryHTML => (C4::Context->preference("OPACMySummaryHTML")) ? 1 : 0,
165 surname => $borr->{surname},
166 RENEW_ERROR => $renew_error,
170 #get issued items ....
173 my $overdues_count = 0;
176 my $itemtypes = GetItemTypes();
177 my $issues = GetPendingIssues($borrowernumber);
179 foreach my $issue ( sort { $b->{date_due}->datetime() cmp $a->{date_due}->datetime() } @{$issues} ) {
181 my $restype = GetReserveStatus( $issue->{'itemnumber'} );
183 $issue->{'reserved'} = 1;
186 my ( $total , $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
188 foreach my $ac (@$accts) {
189 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
190 $charges += $ac->{'amountoutstanding'}
191 if $ac->{'accounttype'} eq 'F';
192 $charges += $ac->{'amountoutstanding'}
193 if $ac->{'accounttype'} eq 'FU';
194 $charges += $ac->{'amountoutstanding'}
195 if $ac->{'accounttype'} eq 'L';
198 $issue->{'charges'} = $charges;
199 my $marcrecord = GetMarcBiblio( $issue->{'biblionumber'} );
200 $issue->{'subtitle'} = GetRecordValue('subtitle', $marcrecord, GetFrameworkCode($issue->{'biblionumber'}));
201 # check if item is renewable
202 my ($status,$renewerror) = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} );
203 ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount($borrowernumber, $issue->{'itemnumber'});
204 if($status && C4::Context->preference("OpacRenewalAllowed")){
205 $issue->{'status'} = $status;
208 $issue->{'renewed'} = $renewed{ $issue->{'itemnumber'} };
211 $issue->{'too_many'} = 1 if $renewerror eq 'too_many';
212 $issue->{'on_reserve'} = 1 if $renewerror eq 'on_reserve';
213 $issue->{'norenew_overdue'} = 1 if $renewerror eq 'overdue';
214 $issue->{'auto_renew'} = 1 if $renewerror eq 'auto_renew';
215 $issue->{'auto_too_soon'} = 1 if $renewerror eq 'auto_too_soon';
217 if ( $renewerror eq 'too_soon' ) {
218 $issue->{'too_soon'} = 1;
219 $issue->{'soonestrenewdate'} = output_pref(
220 C4::Circulation::GetSoonestRenewDate(
221 $issue->{borrowernumber},
228 if ( $issue->{'overdue'} ) {
229 push @overdues, $issue;
231 $issue->{'overdue'} = 1;
234 $issue->{'issued'} = 1;
237 my $itemtype = $issue->{'itemtype'};
239 $issue->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
240 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
242 push @issuedat, $issue;
245 my $isbn = GetNormalizedISBN($issue->{'isbn'});
246 $issue->{normalized_isbn} = $isbn;
247 $issue->{normalized_upc} = GetNormalizedUPC( $marcrecord, C4::Context->preference('marcflavour') );
250 if (my $my_summary_html = C4::Context->preference('OPACMySummaryHTML')){
251 $issue->{author} ? $my_summary_html =~ s/{AUTHOR}/$issue->{author}/g : $my_summary_html =~ s/{AUTHOR}//g;
252 $issue->{title} =~ s/\/+$//; # remove trailing slash
253 $issue->{title} =~ s/\s+$//; # remove trailing space
254 $issue->{title} ? $my_summary_html =~ s/{TITLE}/$issue->{title}/g : $my_summary_html =~ s/{TITLE}//g;
255 $issue->{isbn} ? $my_summary_html =~ s/{ISBN}/$isbn/g : $my_summary_html =~ s/{ISBN}//g;
256 $issue->{biblionumber} ? $my_summary_html =~ s/{BIBLIONUMBER}/$issue->{biblionumber}/g : $my_summary_html =~ s/{BIBLIONUMBER}//g;
257 $issue->{MySummaryHTML} = $my_summary_html;
261 my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
262 $canrenew = 0 if ($overduesblockrenewing ne 'allow' and $overdues_count == $count);
263 $template->param( ISSUES => \@issuedat );
264 $template->param( issues_count => $count );
265 $template->param( canrenew => $canrenew );
266 $template->param( OVERDUES => \@overdues );
267 $template->param( overdues_count => $overdues_count );
269 my $show_barcode = C4::Members::AttributeTypes::AttributeTypeExists( ATTRIBUTE_SHOW_BARCODE );
271 my $patron_show_barcode = GetBorrowerAttributeValue($borrowernumber, ATTRIBUTE_SHOW_BARCODE);
272 undef $show_barcode if defined($patron_show_barcode) && !$patron_show_barcode;
274 $template->param( show_barcode => 1 ) if $show_barcode;
277 my $branches = GetBranches();
279 for my $branch_hash ( sort keys %{$branches} ) {
281 if ( C4::Context->preference('SearchMyLibraryFirst') ) {
283 ( C4::Context->userenv
284 && ( $branch_hash eq C4::Context->userenv->{branch} ) );
287 { value => "branch: $branch_hash",
288 branchname => $branches->{$branch_hash}->{'branchname'},
289 selected => $selected,
292 $template->param( branchloop => \@branch_loop );
294 # now the reserved items....
295 my $reserves = Koha::Holds->search( { borrowernumber => $borrowernumber } );
298 RESERVES => $reserves,
299 showpriority => $show_priority,
302 # current alert subscriptions
303 my $alerts = getalert($borrowernumber);
304 foreach ( @$alerts ) {
305 $_->{ $_->{type} } = 1;
306 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
309 if (C4::Context->preference('BakerTaylorEnabled')) {
311 BakerTaylorEnabled => 1,
312 BakerTaylorImageURL => &image_url(),
313 BakerTaylorLinkURL => &link_url(),
314 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
318 if (C4::Context->preference("OPACAmazonCoverImages") or
319 C4::Context->preference("GoogleJackets") or
320 C4::Context->preference("BakerTaylorEnabled") or
321 C4::Context->preference("SyndeticsCoverImages")) {
322 $template->param(JacketImages=>1);
325 my $patron_messages = Koha::Patron::Messages->search(
327 borrowernumber => $borrowernumber,
331 if ( $patron_messages->count ) {
332 $template->param( bor_messages => 1 );
335 if ( $borr->{'opacnote'} ) {
338 opacnote => $borr->{'opacnote'},
342 if ( C4::Context->preference('AllowPatronToSetCheckoutsVisibilityForGuarantor')
343 || C4::Context->preference('AllowStaffToSetCheckoutsVisibilityForGuarantor') )
346 Koha::Database->new()->schema()->resultset("Borrower")->search(
348 privacy_guarantor_checkouts => 1,
349 'me.guarantorid' => $borrowernumber
351 { prefetch => [ { 'issues' => { 'item' => 'biblio' } } ] }
353 $template->param( relatives => \@relatives );
358 patron_messages => $patron_messages,
359 patronupdate => $patronupdate,
360 OpacRenewalAllowed => C4::Context->preference("OpacRenewalAllowed"),
362 SuspendHoldsOpac => C4::Context->preference('SuspendHoldsOpac'),
363 AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
364 OpacHoldNotes => C4::Context->preference('OpacHoldNotes'),
365 failed_holds => scalar $query->param('failed_holds'),
368 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };