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);
40 use constant ATTRIBUTE_SHOW_BARCODE
=> 'SHOW_BCODE';
51 if (C4
::Context
->preference('BakerTaylorEnabled')) {
52 require C4
::External
::BakerTaylor
;
53 import C4
::External
::BakerTaylor
qw(&image_url &link_url);
57 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
59 template_name
=> "opac-user.tt",
67 my %renewed = map { $_ => 1 } split( ':', $query->param('renewed') );
70 for ( C4
::Context
->preference("OPACShowHoldQueueDetails") ) {
71 m/priority/ and $show_priority = 1;
74 my $patronupdate = $query->param('patronupdate');
77 $template->param( shibbolethAuthentication
=> C4
::Context
->config('useshibboleth') );
79 # get borrower information ....
80 my ( $borr ) = GetMemberDetails
( $borrowernumber );
82 my ( $today_year, $today_month, $today_day) = Today
();
83 my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
85 $borr->{'ethnicity'} = fixEthnicity
( $borr->{'ethnicity'} );
87 my $debar = IsDebarred
($borrowernumber);
92 $template->param( 'userdebarred' => $userdebarred );
93 if ( $debar ne "9999-12-31" ) {
94 $borr->{'userdebarreddate'} = $debar;
98 if ( $userdebarred || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
99 $borr->{'flagged'} = 1;
103 if ( $borr->{'amountoutstanding'} > 5 ) {
104 $borr->{'amountoverfive'} = 1;
106 if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
107 $borr->{'amountoverzero'} = 1;
109 my $no_renewal_amt = C4
::Context
->preference( 'OPACFineNoRenewals' );
110 $no_renewal_amt ||= 0;
112 if ( C4
::Context
->preference( 'OpacRenewalAllowed' ) && $borr->{amountoutstanding
} > $no_renewal_amt ) {
113 $borr->{'flagged'} = 1;
116 renewal_blocked_fines
=> sprintf( '%.02f', $no_renewal_amt ),
117 renewal_blocked_fines_amountoutstanding
=> sprintf( '%.02f', $borr->{amountoutstanding
} ),
121 if ( $borr->{'amountoutstanding'} < 0 ) {
122 $borr->{'amountlessthanzero'} = 1;
123 $borr->{'amountoutstanding'} = -1 * ( $borr->{'amountoutstanding'} );
126 $borr->{'amountoutstanding'} = sprintf "%.02f", $borr->{'amountoutstanding'};
131 # Warningdate is the date that the warning starts appearing
132 if ( $borr->{'dateexpiry'} && C4
::Context
->preference('NotifyBorrowerDeparture') ) {
133 my $days_to_expiry = Date_to_Days
( $warning_year, $warning_month, $warning_day ) - Date_to_Days
( $today_year, $today_month, $today_day );
134 if ( $days_to_expiry < 0 ) {
135 #borrower card has expired, warn the borrower
136 $borr->{'warnexpired'} = $borr->{'dateexpiry'};
137 } elsif ( $days_to_expiry < C4
::Context
->preference('NotifyBorrowerDeparture') ) {
138 # borrower card soon to expire, warn the borrower
139 $borr->{'warndeparture'} = $borr->{dateexpiry
};
140 if (C4
::Context
->preference('ReturnBeforeExpiry')){
141 $borr->{'returnbeforeexpiry'} = 1;
146 # pass on any renew errors to the template for displaying
147 my $renew_error = $query->param('renew_error');
149 $template->param( BORROWER_INFO
=> \
@bordat,
150 borrowernumber
=> $borrowernumber,
151 patron_flagged
=> $borr->{flagged
},
152 OPACMySummaryHTML
=> (C4
::Context
->preference("OPACMySummaryHTML")) ?
1 : 0,
153 surname
=> $borr->{surname
},
154 showname
=> $borr->{showname
},
155 RENEW_ERROR
=> $renew_error,
159 #get issued items ....
162 my $overdues_count = 0;
165 my $itemtypes = GetItemTypes
();
166 my $issues = GetPendingIssues
($borrowernumber);
168 foreach my $issue ( sort { $b->{date_due
}->datetime() cmp $a->{date_due
}->datetime() } @
{$issues} ) {
170 my $restype = GetReserveStatus
( $issue->{'itemnumber'} );
172 $issue->{'reserved'} = 1;
175 my ( $total , $accts, $numaccts) = GetMemberAccountRecords
( $borrowernumber );
177 foreach my $ac (@
$accts) {
178 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
179 $charges += $ac->{'amountoutstanding'}
180 if $ac->{'accounttype'} eq 'F';
181 $charges += $ac->{'amountoutstanding'}
182 if $ac->{'accounttype'} eq 'FU';
183 $charges += $ac->{'amountoutstanding'}
184 if $ac->{'accounttype'} eq 'L';
187 $issue->{'charges'} = $charges;
188 $issue->{'subtitle'} = GetRecordValue
('subtitle', GetMarcBiblio
($issue->{'biblionumber'}), GetFrameworkCode
($issue->{'biblionumber'}));
189 # check if item is renewable
190 my ($status,$renewerror) = CanBookBeRenewed
( $borrowernumber, $issue->{'itemnumber'} );
191 ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount
($borrowernumber, $issue->{'itemnumber'});
192 if($status && C4
::Context
->preference("OpacRenewalAllowed")){
193 $issue->{'status'} = $status;
196 $issue->{'renewed'} = $renewed{ $issue->{'itemnumber'} };
199 $issue->{'too_many'} = 1 if $renewerror eq 'too_many';
200 $issue->{'on_reserve'} = 1 if $renewerror eq 'on_reserve';
201 $issue->{'auto_renew'} = 1 if $renewerror eq 'auto_renew';
202 $issue->{'auto_too_soon'} = 1 if $renewerror eq 'auto_too_soon';
204 if ( $renewerror eq 'too_soon' ) {
205 $issue->{'too_soon'} = 1;
206 $issue->{'soonestrenewdate'} = output_pref
(
207 C4
::Circulation
::GetSoonestRenewDate
(
208 $issue->{borrowernumber
},
215 if ( $issue->{'overdue'} ) {
216 push @overdues, $issue;
218 $issue->{'overdue'} = 1;
221 $issue->{'issued'} = 1;
224 my $itemtype = $issue->{'itemtype'};
226 $issue->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
227 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
229 push @issuedat, $issue;
232 my $isbn = GetNormalizedISBN
($issue->{'isbn'});
233 $issue->{normalized_isbn
} = $isbn;
236 if (my $my_summary_html = C4
::Context
->preference('OPACMySummaryHTML')){
237 $issue->{author
} ?
$my_summary_html =~ s/{AUTHOR}/$issue->{author}/g : $my_summary_html =~ s/{AUTHOR}//g;
238 $issue->{title
} =~ s/\/+$//; # remove trailing slash
239 $issue->{title
} =~ s/\s+$//; # remove trailing space
240 $issue->{title
} ?
$my_summary_html =~ s/{TITLE}/$issue->{title}/g : $my_summary_html =~ s/{TITLE}//g;
241 $issue->{isbn
} ?
$my_summary_html =~ s/{ISBN}/$isbn/g : $my_summary_html =~ s/{ISBN}//g;
242 $issue->{biblionumber
} ?
$my_summary_html =~ s/{BIBLIONUMBER}/$issue->{biblionumber}/g : $my_summary_html =~ s/{BIBLIONUMBER}//g;
243 $issue->{MySummaryHTML
} = $my_summary_html;
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 = GetReservesFromBorrowernumber
( $borrowernumber );
280 foreach my $res (@reserves) {
282 if ( $res->{'expirationdate'} eq '0000-00-00' ) {
283 $res->{'expirationdate'} = '';
285 $res->{'subtitle'} = GetRecordValue
('subtitle', GetMarcBiblio
($res->{'biblionumber'}), GetFrameworkCode
($res->{'biblionumber'}));
286 $res->{'waiting'} = 1 if $res->{'found'} eq 'W';
287 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
288 my $biblioData = GetBiblioData
($res->{'biblionumber'});
289 $res->{'reserves_title'} = $biblioData->{'title'};
290 $res->{'author'} = $biblioData->{'author'};
292 if ($show_priority) {
293 $res->{'priority'} ||= '';
295 $res->{'suspend_until'} = C4
::Dates
->new( $res->{'suspend_until'}, "iso")->output("syspref") if ( $res->{'suspend_until'} );
299 # warn Dumper(@reserves);
301 $template->param( RESERVES
=> \
@reserves );
302 $template->param( reserves_count
=> $#reserves+1 );
303 $template->param( showpriority
=>$show_priority );
307 foreach my $res (@reserves) {
308 if ( $res->{'itemnumber'} ) {
309 my $item = GetItem
( $res->{'itemnumber'});
310 $res->{'holdingbranch'} =
311 $branches->{ $item->{'holdingbranch'} }->{'branchname'};
312 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
313 $res->{'enumchron'} = $item->{'enumchron'} if $item->{'enumchron'};
314 # get document reserve status
315 my $biblioData = GetBiblioData
($res->{'biblionumber'});
316 $res->{'waiting_title'} = $biblioData->{'title'};
317 if ( ( $res->{'found'} eq 'W' ) ) {
318 my $item = $res->{'itemnumber'};
319 $item = GetBiblioFromItemNumber
($item,undef);
321 $res->{'holdingbranch'}=$item->{'holdingbranch'};
322 $res->{'biblionumber'}=$item->{'biblionumber'};
323 $res->{'barcode'} = $item->{'barcode'};
324 $res->{'wbrcode'} = $res->{'branchcode'};
325 $res->{'itemnumber'} = $res->{'itemnumber'};
326 $res->{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
327 if($res->{'holdingbranch'} eq $res->{'wbrcode'}){
328 $res->{'atdestination'} = 1;
330 # set found to 1 if reserve is waiting for patron pickup
331 $res->{'found'} = 1 if $res->{'found'} eq 'W';
333 my ($transfertwhen, $transfertfrom, $transfertto) = GetTransfers
( $res->{'itemnumber'} );
334 if ($transfertwhen) {
335 $res->{intransit
} = 1;
336 $res->{datesent
} = $transfertwhen;
337 $res->{frombranch
} = GetBranchName
($transfertfrom);
344 #$res->{'cancelable'} = 1 if ($res->{'wait'} && $res->{'atdestination'} && $res->{'found'} ne "1");
345 $res->{'cancelable'} = 1 if ($res->{wait} and not $res->{found
}) or (not $res->{wait} and not $res->{intransit
});
349 $template->param( WAITING
=> \
@waiting );
351 # current alert subscriptions
352 my $alerts = getalert
($borrowernumber);
353 foreach ( @
$alerts ) {
354 $_->{ $_->{type
} } = 1;
355 $_->{relatedto
} = findrelatedto
( $_->{type
}, $_->{externalid
} );
358 if (C4
::Context
->preference('BakerTaylorEnabled')) {
360 BakerTaylorEnabled
=> 1,
361 BakerTaylorImageURL
=> &image_url
(),
362 BakerTaylorLinkURL
=> &link_url
(),
363 BakerTaylorBookstoreURL
=> C4
::Context
->preference('BakerTaylorBookstoreURL'),
367 if (C4
::Context
->preference("OPACAmazonCoverImages") or
368 C4
::Context
->preference("GoogleJackets") or
369 C4
::Context
->preference("BakerTaylorEnabled") or
370 C4
::Context
->preference("SyndeticsCoverImages")) {
371 $template->param(JacketImages
=>1);
374 if ( GetMessagesCount
( $borrowernumber, 'B' ) ) {
375 $template->param( bor_messages
=> 1 );
378 if ( $borr->{'opacnote'} ) {
381 opacnote
=> $borr->{'opacnote'},
386 bor_messages_loop
=> GetMessages
( $borrowernumber, 'B', 'NONE' ),
387 waiting_count
=> $wcount,
388 patronupdate
=> $patronupdate,
389 OpacRenewalAllowed
=> C4
::Context
->preference("OpacRenewalAllowed"),
394 SuspendHoldsOpac
=> C4
::Context
->preference('SuspendHoldsOpac'),
395 AutoResumeSuspendedHolds
=> C4
::Context
->preference('AutoResumeSuspendedHolds'),
396 OpacHoldNotes
=> C4
::Context
->preference('OpacHoldNotes'),
399 output_html_with_http_headers
$query, $cookie, $template->output;