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;
43 use constant ATTRIBUTE_SHOW_BARCODE => 'SHOW_BCODE';
45 use Scalar::Util qw(looks_like_number);
55 if (C4::Context->preference('BakerTaylorEnabled')) {
56 require C4::External::BakerTaylor;
57 import C4::External::BakerTaylor qw(&image_url &link_url);
61 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
63 template_name => "opac-user.tt",
71 my %renewed = map { $_ => 1 } split( ':', $query->param('renewed') );
74 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
75 m/priority/ and $show_priority = 1;
78 my $patronupdate = $query->param('patronupdate');
81 $template->param( shibbolethAuthentication => C4::Context->config('useshibboleth') );
83 if (!$borrowernumber) {
84 $template->param( adminWarning => 1 );
87 # get borrower information ....
88 my ( $borr ) = GetMemberDetails( $borrowernumber );
90 my ( $today_year, $today_month, $today_day) = Today();
91 my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
93 my $debar = IsDebarred($borrowernumber);
98 $template->param( 'userdebarred' => $userdebarred );
99 if ( $debar ne "9999-12-31" ) {
100 $borr->{'userdebarreddate'} = $debar;
104 if ( $userdebarred || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
105 $borr->{'flagged'} = 1;
109 if ( $borr->{'amountoutstanding'} > 5 ) {
110 $borr->{'amountoverfive'} = 1;
112 if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
113 $borr->{'amountoverzero'} = 1;
115 my $no_renewal_amt = C4::Context->preference( 'OPACFineNoRenewals' );
116 $no_renewal_amt = undef unless looks_like_number( $no_renewal_amt );
118 if ( C4::Context->preference('OpacRenewalAllowed')
119 && defined($no_renewal_amt)
120 && $borr->{amountoutstanding} > $no_renewal_amt )
122 $borr->{'flagged'} = 1;
125 renewal_blocked_fines => sprintf( '%.02f', $no_renewal_amt ),
126 renewal_blocked_fines_amountoutstanding =>
127 sprintf( '%.02f', $borr->{amountoutstanding} ),
131 if ( $borr->{'amountoutstanding'} < 0 ) {
132 $borr->{'amountlessthanzero'} = 1;
133 $borr->{'amountoutstanding'} = -1 * ( $borr->{'amountoutstanding'} );
136 $borr->{'amountoutstanding'} = sprintf "%.02f", $borr->{'amountoutstanding'};
138 # Warningdate is the date that the warning starts appearing
139 if ( $borr->{'dateexpiry'} && C4::Context->preference('NotifyBorrowerDeparture') ) {
140 my $days_to_expiry = Date_to_Days( $warning_year, $warning_month, $warning_day ) - Date_to_Days( $today_year, $today_month, $today_day );
141 if ( $days_to_expiry < 0 ) {
142 #borrower card has expired, warn the borrower
143 $borr->{'warnexpired'} = $borr->{'dateexpiry'};
144 } elsif ( $days_to_expiry < C4::Context->preference('NotifyBorrowerDeparture') ) {
145 # borrower card soon to expire, warn the borrower
146 $borr->{'warndeparture'} = $borr->{dateexpiry};
147 if (C4::Context->preference('ReturnBeforeExpiry')){
148 $borr->{'returnbeforeexpiry'} = 1;
153 # pass on any renew errors to the template for displaying
154 my $renew_error = $query->param('renew_error');
156 $template->param( BORROWER_INFO => $borr,
157 borrowernumber => $borrowernumber,
158 patron_flagged => $borr->{flagged},
159 OPACMySummaryHTML => (C4::Context->preference("OPACMySummaryHTML")) ? 1 : 0,
160 surname => $borr->{surname},
161 RENEW_ERROR => $renew_error,
165 #get issued items ....
168 my $overdues_count = 0;
171 my $itemtypes = GetItemTypes();
172 my $issues = GetPendingIssues($borrowernumber);
174 foreach my $issue ( sort { $b->{date_due}->datetime() cmp $a->{date_due}->datetime() } @{$issues} ) {
176 my $restype = GetReserveStatus( $issue->{'itemnumber'} );
178 $issue->{'reserved'} = 1;
181 my ( $total , $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
183 foreach my $ac (@$accts) {
184 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
185 $charges += $ac->{'amountoutstanding'}
186 if $ac->{'accounttype'} eq 'F';
187 $charges += $ac->{'amountoutstanding'}
188 if $ac->{'accounttype'} eq 'FU';
189 $charges += $ac->{'amountoutstanding'}
190 if $ac->{'accounttype'} eq 'L';
193 $issue->{'charges'} = $charges;
194 my $marcrecord = GetMarcBiblio( $issue->{'biblionumber'} );
195 $issue->{'subtitle'} = GetRecordValue('subtitle', $marcrecord, GetFrameworkCode($issue->{'biblionumber'}));
196 # check if item is renewable
197 my ($status,$renewerror) = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} );
198 ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount($borrowernumber, $issue->{'itemnumber'});
199 if($status && C4::Context->preference("OpacRenewalAllowed")){
200 $issue->{'status'} = $status;
203 $issue->{'renewed'} = $renewed{ $issue->{'itemnumber'} };
206 $issue->{'too_many'} = 1 if $renewerror eq 'too_many';
207 $issue->{'on_reserve'} = 1 if $renewerror eq 'on_reserve';
208 $issue->{'norenew_overdue'} = 1 if $renewerror eq 'overdue';
209 $issue->{'auto_renew'} = 1 if $renewerror eq 'auto_renew';
210 $issue->{'auto_too_soon'} = 1 if $renewerror eq 'auto_too_soon';
212 if ( $renewerror eq 'too_soon' ) {
213 $issue->{'too_soon'} = 1;
214 $issue->{'soonestrenewdate'} = output_pref(
215 C4::Circulation::GetSoonestRenewDate(
216 $issue->{borrowernumber},
223 if ( $issue->{'overdue'} ) {
224 push @overdues, $issue;
226 $issue->{'overdue'} = 1;
229 $issue->{'issued'} = 1;
232 my $itemtype = $issue->{'itemtype'};
234 $issue->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
235 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
237 push @issuedat, $issue;
240 my $isbn = GetNormalizedISBN($issue->{'isbn'});
241 $issue->{normalized_isbn} = $isbn;
242 $issue->{normalized_upc} = GetNormalizedUPC( $marcrecord, C4::Context->preference('marcflavour') );
245 if (my $my_summary_html = C4::Context->preference('OPACMySummaryHTML')){
246 $issue->{author} ? $my_summary_html =~ s/{AUTHOR}/$issue->{author}/g : $my_summary_html =~ s/{AUTHOR}//g;
247 $issue->{title} =~ s/\/+$//; # remove trailing slash
248 $issue->{title} =~ s/\s+$//; # remove trailing space
249 $issue->{title} ? $my_summary_html =~ s/{TITLE}/$issue->{title}/g : $my_summary_html =~ s/{TITLE}//g;
250 $issue->{isbn} ? $my_summary_html =~ s/{ISBN}/$isbn/g : $my_summary_html =~ s/{ISBN}//g;
251 $issue->{biblionumber} ? $my_summary_html =~ s/{BIBLIONUMBER}/$issue->{biblionumber}/g : $my_summary_html =~ s/{BIBLIONUMBER}//g;
252 $issue->{MySummaryHTML} = $my_summary_html;
256 my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
257 $canrenew = 0 if ($overduesblockrenewing ne 'allow' and $overdues_count == $count);
258 $template->param( ISSUES => \@issuedat );
259 $template->param( issues_count => $count );
260 $template->param( canrenew => $canrenew );
261 $template->param( OVERDUES => \@overdues );
262 $template->param( overdues_count => $overdues_count );
264 my $show_barcode = C4::Members::AttributeTypes::AttributeTypeExists( ATTRIBUTE_SHOW_BARCODE );
266 my $patron_show_barcode = GetBorrowerAttributeValue($borrowernumber, ATTRIBUTE_SHOW_BARCODE);
267 undef $show_barcode if defined($patron_show_barcode) && !$patron_show_barcode;
269 $template->param( show_barcode => 1 ) if $show_barcode;
272 my $branches = GetBranches();
274 for my $branch_hash ( sort keys %{$branches} ) {
276 if ( C4::Context->preference('SearchMyLibraryFirst') ) {
278 ( C4::Context->userenv
279 && ( $branch_hash eq C4::Context->userenv->{branch} ) );
282 { value => "branch: $branch_hash",
283 branchname => $branches->{$branch_hash}->{'branchname'},
284 selected => $selected,
287 $template->param( branchloop => \@branch_loop );
289 # now the reserved items....
290 my $reserves = Koha::Holds->search( { borrowernumber => $borrowernumber } );
293 RESERVES => $reserves,
294 showpriority => $show_priority,
297 # current alert subscriptions
298 my $alerts = getalert($borrowernumber);
299 foreach ( @$alerts ) {
300 $_->{ $_->{type} } = 1;
301 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
304 if (C4::Context->preference('BakerTaylorEnabled')) {
306 BakerTaylorEnabled => 1,
307 BakerTaylorImageURL => &image_url(),
308 BakerTaylorLinkURL => &link_url(),
309 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
313 if (C4::Context->preference("OPACAmazonCoverImages") or
314 C4::Context->preference("GoogleJackets") or
315 C4::Context->preference("BakerTaylorEnabled") or
316 C4::Context->preference("SyndeticsCoverImages")) {
317 $template->param(JacketImages=>1);
320 my $patron_messages = Koha::Patron::Messages->search(
322 borrowernumber => $borrowernumber,
326 if ( $patron_messages->count ) {
327 $template->param( bor_messages => 1 );
330 if ( $borr->{'opacnote'} ) {
333 opacnote => $borr->{'opacnote'},
337 if ( C4::Context->preference('AllowPatronToSetCheckoutsVisibilityForGuarantor')
338 || C4::Context->preference('AllowStaffToSetCheckoutsVisibilityForGuarantor') )
341 Koha::Database->new()->schema()->resultset("Borrower")->search(
343 privacy_guarantor_checkouts => 1,
344 'me.guarantorid' => $borrowernumber
346 { prefetch => [ { 'issues' => { 'item' => 'biblio' } } ] }
348 $template->param( relatives => \@relatives );
353 patron_messages => $patron_messages,
354 patronupdate => $patronupdate,
355 OpacRenewalAllowed => C4::Context->preference("OpacRenewalAllowed"),
357 SuspendHoldsOpac => C4::Context->preference('SuspendHoldsOpac'),
358 AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
359 OpacHoldNotes => C4::Context->preference('OpacHoldNotes'),
360 failed_holds => scalar $query->param('failed_holds'),
363 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };