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::Borrower::Debarments qw(IsDebarred);
41 use constant ATTRIBUTE_SHOW_BARCODE => 'SHOW_BCODE';
52 if (C4::Context->preference('BakerTaylorEnabled')) {
53 require C4::External::BakerTaylor;
54 import C4::External::BakerTaylor qw(&image_url &link_url);
58 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
60 template_name => "opac-user.tt",
68 my %renewed = map { $_ => 1 } split( ':', $query->param('renewed') );
71 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
72 m/priority/ and $show_priority = 1;
75 my $patronupdate = $query->param('patronupdate');
78 $template->param( shibbolethAuthentication => C4::Context->config('useshibboleth') );
80 # get borrower information ....
81 my ( $borr ) = GetMemberDetails( $borrowernumber );
83 my ( $today_year, $today_month, $today_day) = Today();
84 my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
86 my $debar = IsDebarred($borrowernumber);
91 $template->param( 'userdebarred' => $userdebarred );
92 if ( $debar ne "9999-12-31" ) {
93 $borr->{'userdebarreddate'} = $debar;
97 if ( $userdebarred || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
98 $borr->{'flagged'} = 1;
102 if ( $borr->{'amountoutstanding'} > 5 ) {
103 $borr->{'amountoverfive'} = 1;
105 if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
106 $borr->{'amountoverzero'} = 1;
108 my $no_renewal_amt = C4::Context->preference( 'OPACFineNoRenewals' );
109 $no_renewal_amt ||= 0;
111 if ( C4::Context->preference( 'OpacRenewalAllowed' ) && $borr->{amountoutstanding} > $no_renewal_amt ) {
112 $borr->{'flagged'} = 1;
115 renewal_blocked_fines => sprintf( '%.02f', $no_renewal_amt ),
116 renewal_blocked_fines_amountoutstanding => sprintf( '%.02f', $borr->{amountoutstanding} ),
120 if ( $borr->{'amountoutstanding'} < 0 ) {
121 $borr->{'amountlessthanzero'} = 1;
122 $borr->{'amountoutstanding'} = -1 * ( $borr->{'amountoutstanding'} );
125 $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 => $borr,
146 borrowernumber => $borrowernumber,
147 patron_flagged => $borr->{flagged},
148 OPACMySummaryHTML => (C4::Context->preference("OPACMySummaryHTML")) ? 1 : 0,
149 surname => $borr->{surname},
150 RENEW_ERROR => $renew_error,
154 #get issued items ....
157 my $overdues_count = 0;
160 my $itemtypes = GetItemTypes();
161 my $issues = GetPendingIssues($borrowernumber);
163 foreach my $issue ( sort { $b->{date_due}->datetime() cmp $a->{date_due}->datetime() } @{$issues} ) {
165 my $restype = GetReserveStatus( $issue->{'itemnumber'} );
167 $issue->{'reserved'} = 1;
170 my ( $total , $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
172 foreach my $ac (@$accts) {
173 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
174 $charges += $ac->{'amountoutstanding'}
175 if $ac->{'accounttype'} eq 'F';
176 $charges += $ac->{'amountoutstanding'}
177 if $ac->{'accounttype'} eq 'FU';
178 $charges += $ac->{'amountoutstanding'}
179 if $ac->{'accounttype'} eq 'L';
182 $issue->{'charges'} = $charges;
183 my $marcrecord = GetMarcBiblio( $issue->{'biblionumber'} );
184 $issue->{'subtitle'} = GetRecordValue('subtitle', $marcrecord, 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;
192 $issue->{'renewed'} = $renewed{ $issue->{'itemnumber'} };
195 $issue->{'too_many'} = 1 if $renewerror eq 'too_many';
196 $issue->{'on_reserve'} = 1 if $renewerror eq 'on_reserve';
197 $issue->{'norenew_overdue'} = 1 if $renewerror eq 'overdue';
198 $issue->{'auto_renew'} = 1 if $renewerror eq 'auto_renew';
199 $issue->{'auto_too_soon'} = 1 if $renewerror eq 'auto_too_soon';
201 if ( $renewerror eq 'too_soon' ) {
202 $issue->{'too_soon'} = 1;
203 $issue->{'soonestrenewdate'} = output_pref(
204 C4::Circulation::GetSoonestRenewDate(
205 $issue->{borrowernumber},
212 if ( $issue->{'overdue'} ) {
213 push @overdues, $issue;
215 $issue->{'overdue'} = 1;
218 $issue->{'issued'} = 1;
221 my $itemtype = $issue->{'itemtype'};
223 $issue->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
224 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
226 push @issuedat, $issue;
229 my $isbn = GetNormalizedISBN($issue->{'isbn'});
230 $issue->{normalized_isbn} = $isbn;
231 $issue->{normalized_upc} = GetNormalizedUPC( $marcrecord, C4::Context->preference('marcflavour') );
234 if (my $my_summary_html = C4::Context->preference('OPACMySummaryHTML')){
235 $issue->{author} ? $my_summary_html =~ s/{AUTHOR}/$issue->{author}/g : $my_summary_html =~ s/{AUTHOR}//g;
236 $issue->{title} =~ s/\/+$//; # remove trailing slash
237 $issue->{title} =~ s/\s+$//; # remove trailing space
238 $issue->{title} ? $my_summary_html =~ s/{TITLE}/$issue->{title}/g : $my_summary_html =~ s/{TITLE}//g;
239 $issue->{isbn} ? $my_summary_html =~ s/{ISBN}/$isbn/g : $my_summary_html =~ s/{ISBN}//g;
240 $issue->{biblionumber} ? $my_summary_html =~ s/{BIBLIONUMBER}/$issue->{biblionumber}/g : $my_summary_html =~ s/{BIBLIONUMBER}//g;
241 $issue->{MySummaryHTML} = $my_summary_html;
245 my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
246 $canrenew = 0 if ($overduesblockrenewing ne 'allow' and $overdues_count == $count);
247 $template->param( ISSUES => \@issuedat );
248 $template->param( issues_count => $count );
249 $template->param( canrenew => $canrenew );
250 $template->param( OVERDUES => \@overdues );
251 $template->param( overdues_count => $overdues_count );
253 my $show_barcode = C4::Members::AttributeTypes::AttributeTypeExists( ATTRIBUTE_SHOW_BARCODE );
255 my $patron_show_barcode = GetBorrowerAttributeValue($borrowernumber, ATTRIBUTE_SHOW_BARCODE);
256 undef $show_barcode if defined($patron_show_barcode) && !$patron_show_barcode;
258 $template->param( show_barcode => 1 ) if $show_barcode;
261 my $branches = GetBranches();
263 for my $branch_hash ( sort keys %{$branches} ) {
265 if ( C4::Context->preference('SearchMyLibraryFirst') ) {
267 ( C4::Context->userenv
268 && ( $branch_hash eq C4::Context->userenv->{branch} ) );
271 { value => "branch: $branch_hash",
272 branchname => $branches->{$branch_hash}->{'branchname'},
273 selected => $selected,
276 $template->param( branchloop => \@branch_loop );
278 # now the reserved items....
279 my $reserves = Koha::Holds->search( { borrowernumber => $borrowernumber } );
282 RESERVES => $reserves,
283 showpriority => $show_priority,
286 # current alert subscriptions
287 my $alerts = getalert($borrowernumber);
288 foreach ( @$alerts ) {
289 $_->{ $_->{type} } = 1;
290 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
293 if (C4::Context->preference('BakerTaylorEnabled')) {
295 BakerTaylorEnabled => 1,
296 BakerTaylorImageURL => &image_url(),
297 BakerTaylorLinkURL => &link_url(),
298 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
302 if (C4::Context->preference("OPACAmazonCoverImages") or
303 C4::Context->preference("GoogleJackets") or
304 C4::Context->preference("BakerTaylorEnabled") or
305 C4::Context->preference("SyndeticsCoverImages")) {
306 $template->param(JacketImages=>1);
309 if ( GetMessagesCount( $borrowernumber, 'B' ) ) {
310 $template->param( bor_messages => 1 );
313 if ( $borr->{'opacnote'} ) {
316 opacnote => $borr->{'opacnote'},
321 bor_messages_loop => GetMessages( $borrowernumber, 'B', 'NONE' ),
322 waiting_count => $wcount,
323 patronupdate => $patronupdate,
324 OpacRenewalAllowed => C4::Context->preference("OpacRenewalAllowed"),
326 SuspendHoldsOpac => C4::Context->preference('SuspendHoldsOpac'),
327 AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
328 OpacHoldNotes => C4::Context->preference('OpacHoldNotes'),
329 failed_holds => $query->param('failed_holds'),
332 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };