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/;
33 use C4
::Overdues qw
/CheckBorrowerDebarred/;
37 use C4
::Branch
; # GetBranches
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.tmpl",
63 flagsrequired
=> { borrow
=> 1 },
69 for ( C4
::Context
->preference("OPACShowHoldQueueDetails") ) {
70 m/priority/ and $show_priority = 1;
72 my $patronupdate = $query->param('patronupdate');
75 # get borrower information ....
76 my ( $borr ) = GetMemberDetails
( $borrowernumber );
78 my ( $today_year, $today_month, $today_day) = Today
();
79 my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
81 $borr->{'ethnicity'} = fixEthnicity
( $borr->{'ethnicity'} );
83 my $debar = CheckBorrowerDebarred
($borrowernumber);
88 $template->param( 'userdebarred' => $userdebarred );
89 if ( $debar ne "9999-12-31" ) {
90 $borr->{'userdebarreddate'} = $debar;
94 if ( $userdebarred || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
95 $borr->{'flagged'} = 1;
99 if ( $borr->{'amountoutstanding'} > 5 ) {
100 $borr->{'amountoverfive'} = 1;
102 if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
103 $borr->{'amountoverzero'} = 1;
105 my $no_renewal_amt = C4
::Context
->preference( 'OPACFineNoRenewals' );
106 $no_renewal_amt ||= 0;
108 if ( $borr->{amountoutstanding
} > $no_renewal_amt ) {
109 $borr->{'flagged'} = 1;
112 renewal_blocked_fines
=> sprintf( '%.02f', $no_renewal_amt ),
113 renewal_blocked_fines_amountoutstanding
=> sprintf( '%.02f', $borr->{amountoutstanding
} ),
117 if ( $borr->{'amountoutstanding'} < 0 ) {
118 $borr->{'amountlessthanzero'} = 1;
119 $borr->{'amountoutstanding'} = -1 * ( $borr->{'amountoutstanding'} );
122 $borr->{'amountoutstanding'} = sprintf "%.02f", $borr->{'amountoutstanding'};
127 # Warningdate is the date that the warning starts appearing
128 if ( $borr->{dateexpiry
} && Date_to_Days
( $today_year, $today_month, $today_day ) > Date_to_Days
( $warning_year, $warning_month, $warning_day ) ) {
129 $borr->{'warnexpired'} = 1;
131 elsif ( $borr->{dateexpiry
} && C4
::Context
->preference('NotifyBorrowerDeparture') &&
132 Date_to_Days
(Add_Delta_Days
($warning_year, $warning_month, $warning_day,- C4
::Context
->preference('NotifyBorrowerDeparture'))) <
133 Date_to_Days
( $today_year, $today_month, $today_day ) ) {
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 $template->param( BORROWER_INFO
=> \
@bordat,
143 borrowernumber
=> $borrowernumber,
144 patron_flagged
=> $borr->{flagged
},
145 OPACMySummaryHTML
=> (C4
::Context
->preference("OPACMySummaryHTML")) ?
1 : 0,
146 surname
=> $borr->{surname
},
147 showname
=> $borr->{showname
},
150 #get issued items ....
153 my $overdues_count = 0;
156 my $itemtypes = GetItemTypes
();
157 my $issues = GetPendingIssues
($borrowernumber);
159 foreach my $issue ( sort { $b->{date_due
}->datetime() cmp $a->{date_due
}->datetime() } @
{$issues} ) {
161 my ( $restype, $res, undef ) = CheckReserves
( $issue->{'itemnumber'} );
163 $issue->{'reserved'} = 1;
166 my ( $total , $accts, $numaccts) = GetMemberAccountRecords
( $borrowernumber );
168 foreach my $ac (@
$accts) {
169 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
170 $charges += $ac->{'amountoutstanding'}
171 if $ac->{'accounttype'} eq 'F';
172 $charges += $ac->{'amountoutstanding'}
173 if $ac->{'accounttype'} eq 'FU';
174 $charges += $ac->{'amountoutstanding'}
175 if $ac->{'accounttype'} eq 'L';
178 $issue->{'charges'} = $charges;
180 # check if item is renewable
181 my ($status,$renewerror) = CanBookBeRenewed
( $borrowernumber, $issue->{'itemnumber'} );
182 ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount
($borrowernumber, $issue->{'itemnumber'});
183 if($status && C4
::Context
->preference("OpacRenewalAllowed")){
184 $issue->{'status'} = $status;
186 $issue->{'too_many'} = 1 if $renewerror and $renewerror eq 'too_many';
187 $issue->{'on_reserve'} = 1 if $renewerror and $renewerror eq 'on_reserve';
189 if ( $issue->{'overdue'} ) {
190 push @overdues, $issue;
192 $issue->{'overdue'} = 1;
195 $issue->{'issued'} = 1;
198 my $itemtype = $issue->{'itemtype'};
200 $issue->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
201 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
203 push @issuedat, $issue;
206 my $isbn = GetNormalizedISBN
($issue->{'isbn'});
207 $issue->{normalized_isbn
} = $isbn;
210 if (my $my_summary_html = C4
::Context
->preference('OPACMySummaryHTML')){
211 $issue->{author
} ?
$my_summary_html =~ s/{AUTHOR}/$issue->{author}/g : $my_summary_html =~ s/{AUTHOR}//g;
212 $issue->{title
} =~ s/\/+$//; # remove trailing slash
213 $issue->{title
} =~ s/\s+$//; # remove trailing space
214 $issue->{title
} ?
$my_summary_html =~ s/{TITLE}/$issue->{title}/g : $my_summary_html =~ s/{TITLE}//g;
215 $issue->{isbn
} ?
$my_summary_html =~ s/{ISBN}/$isbn/g : $my_summary_html =~ s/{ISBN}//g;
216 $issue->{biblionumber
} ?
$my_summary_html =~ s/{BIBLIONUMBER}/$issue->{biblionumber}/g : $my_summary_html =~ s/{BIBLIONUMBER}//g;
217 $issue->{MySummaryHTML
} = $my_summary_html;
221 $template->param( ISSUES
=> \
@issuedat );
222 $template->param( issues_count
=> $count );
223 $template->param( canrenew
=> $canrenew );
224 $template->param( OVERDUES
=> \
@overdues );
225 $template->param( overdues_count
=> $overdues_count );
227 my $show_barcode = C4
::Members
::AttributeTypes
::AttributeTypeExists
( ATTRIBUTE_SHOW_BARCODE
);
229 my $patron_show_barcode = GetBorrowerAttributeValue
($borrowernumber, ATTRIBUTE_SHOW_BARCODE
);
230 undef $show_barcode if defined($patron_show_barcode) && !$patron_show_barcode;
232 $template->param( show_barcode
=> 1 ) if $show_barcode;
235 my $branches = GetBranches
();
237 for my $branch_hash ( sort keys %{$branches} ) {
239 if ( C4
::Context
->preference('SearchMyLibraryFirst') ) {
241 ( C4
::Context
->userenv
242 && ( $branch_hash eq C4
::Context
->userenv->{branch
} ) );
245 { value
=> "branch: $branch_hash",
246 branchname
=> $branches->{$branch_hash}->{'branchname'},
247 selected
=> $selected,
250 $template->param( branchloop
=> \
@branch_loop );
252 # now the reserved items....
253 my @reserves = GetReservesFromBorrowernumber
( $borrowernumber );
254 foreach my $res (@reserves) {
256 if ( $res->{'expirationdate'} eq '0000-00-00' ) {
257 $res->{'expirationdate'} = '';
260 $res->{'waiting'} = 1 if $res->{'found'} eq 'W';
261 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
262 my $biblioData = GetBiblioData
($res->{'biblionumber'});
263 $res->{'reserves_title'} = $biblioData->{'title'};
264 if ($show_priority) {
265 $res->{'priority'} ||= '';
267 $res->{'suspend_until'} = C4
::Dates
->new( $res->{'suspend_until'}, "iso")->output("syspref") if ( $res->{'suspend_until'} );
271 # warn Dumper(@reserves);
273 $template->param( RESERVES
=> \
@reserves );
274 $template->param( reserves_count
=> $#reserves+1 );
275 $template->param( showpriority
=>$show_priority );
279 foreach my $res (@reserves) {
280 if ( $res->{'itemnumber'} ) {
281 my $item = GetItem
( $res->{'itemnumber'});
282 $res->{'holdingbranch'} =
283 $branches->{ $item->{'holdingbranch'} }->{'branchname'};
284 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
285 # get document reserve status
286 my $biblioData = GetBiblioData
($res->{'biblionumber'});
287 $res->{'waiting_title'} = $biblioData->{'title'};
288 if ( ( $res->{'found'} eq 'W' ) ) {
289 my $item = $res->{'itemnumber'};
290 $item = GetBiblioFromItemNumber
($item,undef);
292 $res->{'holdingbranch'}=$item->{'holdingbranch'};
293 $res->{'biblionumber'}=$item->{'biblionumber'};
294 $res->{'barcode'} = $item->{'barcode'};
295 $res->{'wbrcode'} = $res->{'branchcode'};
296 $res->{'itemnumber'} = $res->{'itemnumber'};
297 $res->{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
298 if($res->{'holdingbranch'} eq $res->{'wbrcode'}){
299 $res->{'atdestination'} = 1;
301 # set found to 1 if reserve is waiting for patron pickup
302 $res->{'found'} = 1 if $res->{'found'} eq 'W';
304 my ($transfertwhen, $transfertfrom, $transfertto) = GetTransfers
( $res->{'itemnumber'} );
305 if ($transfertwhen) {
306 $res->{intransit
} = 1;
307 $res->{datesent
} = $transfertwhen;
308 $res->{frombranch
} = GetBranchName
($transfertfrom);
315 #$res->{'cancelable'} = 1 if ($res->{'wait'} && $res->{'atdestination'} && $res->{'found'} ne "1");
316 $res->{'cancelable'} = 1 if ($res->{wait} and not $res->{found
}) or (not $res->{wait} and not $res->{intransit
});
320 $template->param( WAITING
=> \
@waiting );
322 # current alert subscriptions
323 my $alerts = getalert
($borrowernumber);
324 foreach ( @
$alerts ) {
325 $_->{ $_->{type
} } = 1;
326 $_->{relatedto
} = findrelatedto
( $_->{type
}, $_->{externalid
} );
329 if (C4
::Context
->preference('BakerTaylorEnabled')) {
331 BakerTaylorEnabled
=> 1,
332 BakerTaylorImageURL
=> &image_url
(),
333 BakerTaylorLinkURL
=> &link_url
(),
334 BakerTaylorBookstoreURL
=> C4
::Context
->preference('BakerTaylorBookstoreURL'),
338 if (C4
::Context
->preference("OPACAmazonCoverImages") or
339 C4
::Context
->preference("GoogleJackets") or
340 C4
::Context
->preference("BakerTaylorEnabled") or
341 C4
::Context
->preference("SyndeticsCoverImages")) {
342 $template->param(JacketImages
=>1);
345 if ( GetMessagesCount
( $borrowernumber, 'B' ) ) {
346 $template->param( bor_messages
=> 1 );
349 if ( $borr->{'opacnote'} ) {
352 opacnote
=> $borr->{'opacnote'},
357 bor_messages_loop
=> GetMessages
( $borrowernumber, 'B', 'NONE' ),
358 waiting_count
=> $wcount,
359 patronupdate
=> $patronupdate,
360 OpacRenewalAllowed
=> C4
::Context
->preference("OpacRenewalAllowed"),
365 SuspendHoldsOpac
=> C4
::Context
->preference('SuspendHoldsOpac'),
366 AutoResumeSuspendedHolds
=> C4
::Context
->preference('AutoResumeSuspendedHolds'),
369 output_html_with_http_headers
$query, $cookie, $template->output;