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 },
67 my $OPACDisplayRequestPriority = (C4::Context->preference("OPACDisplayRequestPriority")) ? 1 : 0;
68 my $patronupdate = $query->param('patronupdate');
71 # get borrower information ....
72 my ( $borr ) = GetMemberDetails( $borrowernumber );
74 my ( $today_year, $today_month, $today_day) = Today();
75 my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
77 $borr->{'ethnicity'} = fixEthnicity( $borr->{'ethnicity'} );
79 my $debar = $borr->{'debarred'};
84 $template->param( 'userdebarred' => $userdebarred );
85 if ( $debar ne "9999-12-31" ) {
86 $borr->{'userdebarreddate'} = $debar;
90 if ( $userdebarred || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
91 $borr->{'flagged'} = 1;
95 if ( $borr->{'amountoutstanding'} > 5 ) {
96 $borr->{'amountoverfive'} = 1;
98 if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
99 $borr->{'amountoverzero'} = 1;
101 my $no_renewal_amt = C4::Context->preference( 'OPACFineNoRenewals' );
102 $no_renewal_amt ||= 0;
104 if ( C4::Context->preference( 'OpacRenewalAllowed' ) && $borr->{amountoutstanding} > $no_renewal_amt ) {
105 $borr->{'flagged'} = 1;
108 renewal_blocked_fines => sprintf( '%.02f', $no_renewal_amt ),
112 if ( $borr->{'amountoutstanding'} < 0 ) {
113 $borr->{'amountlessthanzero'} = 1;
114 $borr->{'amountoutstanding'} = -1 * ( $borr->{'amountoutstanding'} );
117 $borr->{'amountoutstanding'} = sprintf "%.02f", $borr->{'amountoutstanding'};
122 # Warningdate is the date that the warning starts appearing
123 if ( $borr->{'dateexpiry'} && C4::Context->preference('NotifyBorrowerDeparture') ) {
124 my $days_to_expiry = Date_to_Days( $warning_year, $warning_month, $warning_day ) - Date_to_Days( $today_year, $today_month, $today_day );
125 if ( $days_to_expiry < 0 ) {
126 #borrower card has expired, warn the borrower
127 $borr->{'warnexpired'} = $borr->{'dateexpiry'};
128 } elsif ( $days_to_expiry < C4::Context->preference('NotifyBorrowerDeparture') ) {
129 # borrower card soon to expire, warn the borrower
130 $borr->{'warndeparture'} = $borr->{dateexpiry};
131 if (C4::Context->preference('ReturnBeforeExpiry')){
132 $borr->{'returnbeforeexpiry'} = 1;
137 # pass on any renew errors to the template for displaying
138 $template->param( RENEW_ERROR => $query->param('renew_error') ) if $query->param('renew_error');
140 $template->param( BORROWER_INFO => \@bordat,
141 borrowernumber => $borrowernumber,
142 patron_flagged => $borr->{flagged},
143 OPACMySummaryHTML => (C4::Context->preference("OPACMySummaryHTML")) ? 1 : 0,
144 surname => $borr->{surname},
145 showname => $borr->{showname},
148 #get issued items ....
151 my $overdues_count = 0;
154 my $itemtypes = GetItemTypes();
155 my $issues = GetPendingIssues($borrowernumber);
157 foreach my $issue ( sort { $b->{date_due}->datetime() cmp $a->{date_due}->datetime() } @{$issues} ) {
159 my ( $restype, $res, undef ) = CheckReserves( $issue->{'itemnumber'} );
161 $issue->{'reserved'} = 1;
164 my ( $total , $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
166 foreach my $ac (@$accts) {
167 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
168 $charges += $ac->{'amountoutstanding'}
169 if $ac->{'accounttype'} eq 'F';
170 $charges += $ac->{'amountoutstanding'}
171 if $ac->{'accounttype'} eq 'L';
174 $issue->{'charges'} = $charges;
175 $issue->{'subtitle'} = GetRecordValue('subtitle', GetMarcBiblio($issue->{'biblionumber'}), GetFrameworkCode($issue->{'biblionumber'}));
176 # check if item is renewable
177 my ($status,$renewerror) = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} );
178 ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount($borrowernumber, $issue->{'itemnumber'});
179 if($status && C4::Context->preference("OpacRenewalAllowed")){
180 $issue->{'status'} = $status;
184 $issue->{'too_many'} = 1 if $renewerror eq 'too_many';
185 $issue->{'on_reserve'} = 1 if $renewerror eq 'on_reserve';
187 if ( $renewerror eq 'too_soon' ) {
188 $issue->{'too_soon'} = 1;
189 $issue->{'soonestrenewdate'} = output_pref(
190 C4::Circulation::GetSoonestRenewDate(
191 $issue->{borrowernumber},
198 if ( $issue->{'overdue'} ) {
199 push @overdues, $issue;
201 $issue->{'overdue'} = 1;
204 $issue->{'issued'} = 1;
207 my $itemtype = $issue->{'itemtype'};
209 $issue->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
210 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
212 push @issuedat, $issue;
215 my $isbn = GetNormalizedISBN($issue->{'isbn'});
216 $issue->{normalized_isbn} = $isbn;
219 if (my $my_summary_html = C4::Context->preference('OPACMySummaryHTML')){
220 $issue->{author} ? $my_summary_html =~ s/{AUTHOR}/$issue->{author}/g : $my_summary_html =~ s/{AUTHOR}//g;
221 $issue->{title} =~ s/\/+$//; # remove trailing slash
222 $issue->{title} =~ s/\s+$//; # remove trailing space
223 $issue->{title} ? $my_summary_html =~ s/{TITLE}/$issue->{title}/g : $my_summary_html =~ s/{TITLE}//g;
224 $issue->{isbn} ? $my_summary_html =~ s/{ISBN}/$isbn/g : $my_summary_html =~ s/{ISBN}//g;
225 $issue->{biblionumber} ? $my_summary_html =~ s/{BIBLIONUMBER}/$issue->{biblionumber}/g : $my_summary_html =~ s/{BIBLIONUMBER}//g;
226 $issue->{MySummaryHTML} = $my_summary_html;
230 $template->param( ISSUES => \@issuedat );
231 $template->param( issues_count => $count );
232 $template->param( canrenew => $canrenew );
233 $template->param( OVERDUES => \@overdues );
234 $template->param( overdues_count => $overdues_count );
236 my $show_barcode = C4::Members::AttributeTypes::AttributeTypeExists( ATTRIBUTE_SHOW_BARCODE );
238 my $patron_show_barcode = GetBorrowerAttributeValue($borrowernumber, ATTRIBUTE_SHOW_BARCODE);
239 undef $show_barcode if defined($patron_show_barcode) && !$patron_show_barcode;
241 $template->param( show_barcode => 1 ) if $show_barcode;
244 my $branches = GetBranches();
246 for my $branch_hash ( sort keys %{$branches} ) {
248 if ( C4::Context->preference('SearchMyLibraryFirst') ) {
250 ( C4::Context->userenv
251 && ( $branch_hash eq C4::Context->userenv->{branch} ) );
254 { value => "branch: $branch_hash",
255 branchname => $branches->{$branch_hash}->{'branchname'},
256 selected => $selected,
259 $template->param( branchloop => \@branch_loop );
261 # now the reserved items....
262 my @reserves = GetReservesFromBorrowernumber( $borrowernumber );
263 foreach my $res (@reserves) {
265 if ( $res->{'expirationdate'} eq '0000-00-00' ) {
266 $res->{'expirationdate'} = '';
268 $res->{'subtitle'} = GetRecordValue('subtitle', GetMarcBiblio($res->{'biblionumber'}), GetFrameworkCode($res->{'biblionumber'}));
269 $res->{'waiting'} = 1 if $res->{'found'} eq 'W';
270 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
271 my $biblioData = GetBiblioData($res->{'biblionumber'});
272 $res->{'reserves_title'} = $biblioData->{'title'};
273 if ($OPACDisplayRequestPriority) {
274 $res->{'priority'} = '' if $res->{'priority'} eq '0';
276 $res->{'suspend_until'} = C4::Dates->new( $res->{'suspend_until'}, "iso")->output("syspref") if ( $res->{'suspend_until'} );
280 # warn Dumper(@reserves);
282 $template->param( RESERVES => \@reserves );
283 $template->param( reserves_count => $#reserves+1 );
284 $template->param( showpriority=>1 ) if $OPACDisplayRequestPriority;
288 foreach my $res (@reserves) {
289 if ( $res->{'itemnumber'} ) {
290 my $item = GetItem( $res->{'itemnumber'});
291 $res->{'holdingbranch'} =
292 $branches->{ $item->{'holdingbranch'} }->{'branchname'};
293 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
294 # get document reserve status
295 my $biblioData = GetBiblioData($res->{'biblionumber'});
296 $res->{'waiting_title'} = $biblioData->{'title'};
297 if ( ( $res->{'found'} eq 'W' ) ) {
298 my $item = $res->{'itemnumber'};
299 $item = GetBiblioFromItemNumber($item,undef);
301 $res->{'holdingbranch'}=$item->{'holdingbranch'};
302 $res->{'biblionumber'}=$item->{'biblionumber'};
303 $res->{'barcode'} = $item->{'barcode'};
304 $res->{'wbrcode'} = $res->{'branchcode'};
305 $res->{'itemnumber'} = $res->{'itemnumber'};
306 $res->{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
307 if($res->{'holdingbranch'} eq $res->{'wbrcode'}){
308 $res->{'atdestination'} = 1;
310 # set found to 1 if reserve is waiting for patron pickup
311 $res->{'found'} = 1 if $res->{'found'} eq 'W';
313 my ($transfertwhen, $transfertfrom, $transfertto) = GetTransfers( $res->{'itemnumber'} );
314 if ($transfertwhen) {
315 $res->{intransit} = 1;
316 $res->{datesent} = $transfertwhen;
317 $res->{frombranch} = GetBranchName($transfertfrom);
324 #$res->{'cancelable'} = 1 if ($res->{'wait'} && $res->{'atdestination'} && $res->{'found'} ne "1");
325 $res->{'cancelable'} = 1 if ($res->{wait} and not $res->{found}) or (not $res->{wait} and not $res->{intransit});
329 $template->param( WAITING => \@waiting );
331 # current alert subscriptions
332 my $alerts = getalert($borrowernumber);
333 foreach ( @$alerts ) {
334 $_->{ $_->{type} } = 1;
335 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
338 if (C4::Context->preference('BakerTaylorEnabled')) {
340 BakerTaylorEnabled => 1,
341 BakerTaylorImageURL => &image_url(),
342 BakerTaylorLinkURL => &link_url(),
343 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
347 if (C4::Context->preference("OPACAmazonCoverImages") or
348 C4::Context->preference("GoogleJackets") or
349 C4::Context->preference("BakerTaylorEnabled") or
350 C4::Context->preference("SyndeticsCoverImages")) {
351 $template->param(JacketImages=>1);
354 if ( GetMessagesCount( $borrowernumber, 'B' ) ) {
355 $template->param( bor_messages => 1 );
358 if ( $borr->{'opacnote'} ) {
361 opacnote => $borr->{'opacnote'},
366 bor_messages_loop => GetMessages( $borrowernumber, 'B', 'NONE' ),
367 waiting_count => $wcount,
368 patronupdate => $patronupdate,
369 OpacRenewalAllowed => C4::Context->preference("OpacRenewalAllowed"),
371 dateformat => C4::Context->preference("dateformat"),
375 SuspendHoldsOpac => C4::Context->preference('SuspendHoldsOpac'),
376 AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
377 OpacHoldNotes => C4::Context->preference('OpacHoldNotes'),
380 output_html_with_http_headers $query, $cookie, $template->output;