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 },
68 my $OPACDisplayRequestPriority = (C4::Context->preference("OPACDisplayRequestPriority")) ? 1 : 0;
69 my $patronupdate = $query->param('patronupdate');
72 # get borrower information ....
73 my ( $borr ) = GetMemberDetails( $borrowernumber );
75 my ( $today_year, $today_month, $today_day) = Today();
76 my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
78 $borr->{'ethnicity'} = fixEthnicity( $borr->{'ethnicity'} );
80 my $debar = CheckBorrowerDebarred($borrowernumber);
85 $template->param( 'userdebarred' => $userdebarred );
86 if ( $debar ne "9999-12-31" ) {
87 $borr->{'userdebarreddate'} = $debar;
91 if ( $userdebarred || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
92 $borr->{'flagged'} = 1;
96 if ( $borr->{'amountoutstanding'} > 5 ) {
97 $borr->{'amountoverfive'} = 1;
99 if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
100 $borr->{'amountoverzero'} = 1;
102 my $no_renewal_amt = C4::Context->preference( 'OPACFineNoRenewals' );
103 $no_renewal_amt ||= 0;
105 if ( $borr->{amountoutstanding} > $no_renewal_amt ) {
106 $borr->{'flagged'} = 1;
109 renewal_blocked_fines => sprintf( '%.02f', $no_renewal_amt ),
113 if ( $borr->{'amountoutstanding'} < 0 ) {
114 $borr->{'amountlessthanzero'} = 1;
115 $borr->{'amountoutstanding'} = -1 * ( $borr->{'amountoutstanding'} );
118 $borr->{'amountoutstanding'} = sprintf "%.02f", $borr->{'amountoutstanding'};
123 # Warningdate is the date that the warning starts appearing
124 if ( $borr->{dateexpiry} && Date_to_Days( $today_year, $today_month, $today_day ) > Date_to_Days( $warning_year, $warning_month, $warning_day ) ) {
125 $borr->{'warnexpired'} = 1;
127 elsif ( $borr->{dateexpiry} && C4::Context->preference('NotifyBorrowerDeparture') &&
128 Date_to_Days(Add_Delta_Days($warning_year, $warning_month, $warning_day,- C4::Context->preference('NotifyBorrowerDeparture'))) <
129 Date_to_Days( $today_year, $today_month, $today_day ) ) {
130 # borrower card soon to expire, warn the borrower
131 $borr->{'warndeparture'} = $borr->{dateexpiry};
132 if (C4::Context->preference('ReturnBeforeExpiry')){
133 $borr->{'returnbeforeexpiry'} = 1;
138 $template->param( BORROWER_INFO => \@bordat,
139 borrowernumber => $borrowernumber,
140 patron_flagged => $borr->{flagged},
141 OPACMySummaryHTML => (C4::Context->preference("OPACMySummaryHTML")) ? 1 : 0,
142 surname => $borr->{surname},
143 showname => $borr->{showname},
147 #get issued items ....
150 my $overdues_count = 0;
153 my $itemtypes = GetItemTypes();
154 my $issues = GetPendingIssues($borrowernumber);
156 foreach my $issue ( sort { $b->{date_due}->datetime() cmp $a->{date_due}->datetime() } @{$issues} ) {
158 my ( $restype, $res, undef ) = CheckReserves( $issue->{'itemnumber'} );
160 $issue->{'reserved'} = 1;
163 my ( $total , $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
165 foreach my $ac (@$accts) {
166 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
167 $charges += $ac->{'amountoutstanding'}
168 if $ac->{'accounttype'} eq 'F';
169 $charges += $ac->{'amountoutstanding'}
170 if $ac->{'accounttype'} eq 'FU';
171 $charges += $ac->{'amountoutstanding'}
172 if $ac->{'accounttype'} eq 'L';
175 $issue->{'charges'} = $charges;
177 # check if item is renewable
178 my ($status,$renewerror) = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} );
179 ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount($borrowernumber, $issue->{'itemnumber'});
180 if($status && C4::Context->preference("OpacRenewalAllowed")){
181 $issue->{'status'} = $status;
183 $issue->{'too_many'} = 1 if $renewerror and $renewerror eq 'too_many';
184 $issue->{'on_reserve'} = 1 if $renewerror and $renewerror eq 'on_reserve';
186 if ( $issue->{'overdue'} ) {
187 push @overdues, $issue;
189 $issue->{'overdue'} = 1;
192 $issue->{'issued'} = 1;
195 my $itemtype = $issue->{'itemtype'};
197 $issue->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
198 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
200 push @issuedat, $issue;
203 my $isbn = GetNormalizedISBN($issue->{'isbn'});
204 $issue->{normalized_isbn} = $isbn;
207 if (my $my_summary_html = C4::Context->preference('OPACMySummaryHTML')){
208 $issue->{author} ? $my_summary_html =~ s/{AUTHOR}/$issue->{author}/g : $my_summary_html =~ s/{AUTHOR}//g;
209 $issue->{title} =~ s/\/+$//; # remove trailing slash
210 $issue->{title} =~ s/\s+$//; # remove trailing space
211 $issue->{title} ? $my_summary_html =~ s/{TITLE}/$issue->{title}/g : $my_summary_html =~ s/{TITLE}//g;
212 $issue->{isbn} ? $my_summary_html =~ s/{ISBN}/$isbn/g : $my_summary_html =~ s/{ISBN}//g;
213 $issue->{biblionumber} ? $my_summary_html =~ s/{BIBLIONUMBER}/$issue->{biblionumber}/g : $my_summary_html =~ s/{BIBLIONUMBER}//g;
214 $issue->{MySummaryHTML} = $my_summary_html;
218 $template->param( ISSUES => \@issuedat );
219 $template->param( issues_count => $count );
220 $template->param( canrenew => $canrenew );
221 $template->param( OVERDUES => \@overdues );
222 $template->param( overdues_count => $overdues_count );
224 my $show_barcode = C4::Members::AttributeTypes::AttributeTypeExists( ATTRIBUTE_SHOW_BARCODE );
226 my $patron_show_barcode = GetBorrowerAttributeValue($borrowernumber, ATTRIBUTE_SHOW_BARCODE);
227 undef $show_barcode if defined($patron_show_barcode) && !$patron_show_barcode;
229 $template->param( show_barcode => 1 ) if $show_barcode;
232 my $branches = GetBranches();
234 for my $branch_hash ( sort keys %{$branches} ) {
236 if ( C4::Context->preference('SearchMyLibraryFirst') ) {
238 ( C4::Context->userenv
239 && ( $branch_hash eq C4::Context->userenv->{branch} ) );
242 { value => "branch: $branch_hash",
243 branchname => $branches->{$branch_hash}->{'branchname'},
244 selected => $selected,
247 $template->param( branchloop => \@branch_loop );
249 # now the reserved items....
250 my @reserves = GetReservesFromBorrowernumber( $borrowernumber );
251 foreach my $res (@reserves) {
253 if ( $res->{'expirationdate'} eq '0000-00-00' ) {
254 $res->{'expirationdate'} = '';
257 $res->{'waiting'} = 1 if $res->{'found'} eq 'W';
258 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
259 my $biblioData = GetBiblioData($res->{'biblionumber'});
260 $res->{'reserves_title'} = $biblioData->{'title'};
261 if ($OPACDisplayRequestPriority) {
262 $res->{'priority'} = '' if $res->{'priority'} eq '0';
264 $res->{'suspend_until'} = C4::Dates->new( $res->{'suspend_until'}, "iso")->output("syspref") if ( $res->{'suspend_until'} );
268 # warn Dumper(@reserves);
270 $template->param( RESERVES => \@reserves );
271 $template->param( reserves_count => $#reserves+1 );
272 $template->param( showpriority=>1 ) if $OPACDisplayRequestPriority;
276 foreach my $res (@reserves) {
277 if ( $res->{'itemnumber'} ) {
278 my $item = GetItem( $res->{'itemnumber'});
279 $res->{'holdingbranch'} =
280 $branches->{ $item->{'holdingbranch'} }->{'branchname'};
281 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
282 # get document reserve status
283 my $biblioData = GetBiblioData($res->{'biblionumber'});
284 $res->{'waiting_title'} = $biblioData->{'title'};
285 if ( ( $res->{'found'} eq 'W' ) ) {
286 my $item = $res->{'itemnumber'};
287 $item = GetBiblioFromItemNumber($item,undef);
289 $res->{'holdingbranch'}=$item->{'holdingbranch'};
290 $res->{'biblionumber'}=$item->{'biblionumber'};
291 $res->{'barcode'} = $item->{'barcode'};
292 $res->{'wbrcode'} = $res->{'branchcode'};
293 $res->{'itemnumber'} = $res->{'itemnumber'};
294 $res->{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
295 if($res->{'holdingbranch'} eq $res->{'wbrcode'}){
296 $res->{'atdestination'} = 1;
298 # set found to 1 if reserve is waiting for patron pickup
299 $res->{'found'} = 1 if $res->{'found'} eq 'W';
301 my ($transfertwhen, $transfertfrom, $transfertto) = GetTransfers( $res->{'itemnumber'} );
302 if ($transfertwhen) {
303 $res->{intransit} = 1;
304 $res->{datesent} = $transfertwhen;
305 $res->{frombranch} = GetBranchName($transfertfrom);
312 #$res->{'cancelable'} = 1 if ($res->{'wait'} && $res->{'atdestination'} && $res->{'found'} ne "1");
313 $res->{'cancelable'} = 1 if ($res->{wait} and not $res->{found}) or (not $res->{wait} and not $res->{intransit});
317 $template->param( WAITING => \@waiting );
319 # current alert subscriptions
320 my $alerts = getalert($borrowernumber);
321 foreach ( @$alerts ) {
322 $_->{ $_->{type} } = 1;
323 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
326 if (C4::Context->preference('BakerTaylorEnabled')) {
328 BakerTaylorEnabled => 1,
329 BakerTaylorImageURL => &image_url(),
330 BakerTaylorLinkURL => &link_url(),
331 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
335 if (C4::Context->preference("OPACAmazonCoverImages") or
336 C4::Context->preference("GoogleJackets") or
337 C4::Context->preference("BakerTaylorEnabled") or
338 C4::Context->preference("SyndeticsCoverImages")) {
339 $template->param(JacketImages=>1);
342 if ( GetMessagesCount( $borrowernumber, 'B' ) ) {
343 $template->param( bor_messages => 1 );
346 if ( $borr->{'opacnote'} ) {
349 opacnote => $borr->{'opacnote'},
354 bor_messages_loop => GetMessages( $borrowernumber, 'B', 'NONE' ),
355 waiting_count => $wcount,
356 patronupdate => $patronupdate,
357 OpacRenewalAllowed => C4::Context->preference("OpacRenewalAllowed"),
359 dateformat => C4::Context->preference("dateformat"),
362 $template->param( DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar() );
364 SuspendHoldsOpac => C4::Context->preference('SuspendHoldsOpac'),
365 AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds') ,
368 output_html_with_http_headers $query, $cookie, $template->output;