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 },
68 for ( C4
::Context
->preference("OPACShowHoldQueueDetails") ) {
69 m/priority/ and $show_priority = 1;
71 my $patronupdate = $query->param('patronupdate');
74 # get borrower information ....
75 my ( $borr ) = GetMemberDetails
( $borrowernumber );
77 my ( $today_year, $today_month, $today_day) = Today
();
78 my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
80 $borr->{'ethnicity'} = fixEthnicity
( $borr->{'ethnicity'} );
82 my $debar = $borr->{'debarred'};
87 $template->param( 'userdebarred' => $userdebarred );
88 if ( $debar ne "9999-12-31" ) {
89 $borr->{'userdebarreddate'} = $debar;
93 if ( $userdebarred || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
94 $borr->{'flagged'} = 1;
98 if ( $borr->{'amountoutstanding'} > 5 ) {
99 $borr->{'amountoverfive'} = 1;
101 if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
102 $borr->{'amountoverzero'} = 1;
104 my $no_renewal_amt = C4
::Context
->preference( 'OPACFineNoRenewals' );
105 $no_renewal_amt ||= 0;
107 if ( C4
::Context
->preference( 'OpacRenewalAllowed' ) && $borr->{amountoutstanding
} > $no_renewal_amt ) {
108 $borr->{'flagged'} = 1;
111 renewal_blocked_fines
=> sprintf( '%.02f', $no_renewal_amt ),
112 renewal_blocked_fines_amountoutstanding
=> sprintf( '%.02f', $borr->{amountoutstanding
} ),
116 if ( $borr->{'amountoutstanding'} < 0 ) {
117 $borr->{'amountlessthanzero'} = 1;
118 $borr->{'amountoutstanding'} = -1 * ( $borr->{'amountoutstanding'} );
121 $borr->{'amountoutstanding'} = sprintf "%.02f", $borr->{'amountoutstanding'};
126 # Warningdate is the date that the warning starts appearing
127 if ( $borr->{dateexpiry
} && Date_to_Days
( $today_year, $today_month, $today_day ) > Date_to_Days
( $warning_year, $warning_month, $warning_day ) ) {
128 $borr->{'warnexpired'} = 1;
130 elsif ( $borr->{dateexpiry
} && C4
::Context
->preference('NotifyBorrowerDeparture') &&
131 Date_to_Days
(Add_Delta_Days
($warning_year, $warning_month, $warning_day,- C4
::Context
->preference('NotifyBorrowerDeparture'))) <
132 Date_to_Days
( $today_year, $today_month, $today_day ) ) {
133 # borrower card soon to expire, warn the borrower
134 $borr->{'warndeparture'} = $borr->{dateexpiry
};
135 if (C4
::Context
->preference('ReturnBeforeExpiry')){
136 $borr->{'returnbeforeexpiry'} = 1;
141 $template->param( BORROWER_INFO
=> \
@bordat,
142 borrowernumber
=> $borrowernumber,
143 patron_flagged
=> $borr->{flagged
},
144 OPACMySummaryHTML
=> (C4
::Context
->preference("OPACMySummaryHTML")) ?
1 : 0,
145 surname
=> $borr->{surname
},
146 showname
=> $borr->{showname
},
149 #get issued items ....
152 my $overdues_count = 0;
155 my $itemtypes = GetItemTypes
();
156 my $issues = GetPendingIssues
($borrowernumber);
158 foreach my $issue ( sort { $b->{date_due
}->datetime() cmp $a->{date_due
}->datetime() } @
{$issues} ) {
160 my $restype = GetReserveStatus
( $issue->{'itemnumber'} );
162 $issue->{'reserved'} = 1;
165 my ( $total , $accts, $numaccts) = GetMemberAccountRecords
( $borrowernumber );
167 foreach my $ac (@
$accts) {
168 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
169 $charges += $ac->{'amountoutstanding'}
170 if $ac->{'accounttype'} eq 'F';
171 $charges += $ac->{'amountoutstanding'}
172 if $ac->{'accounttype'} eq 'FU';
173 $charges += $ac->{'amountoutstanding'}
174 if $ac->{'accounttype'} eq 'L';
177 $issue->{'charges'} = $charges;
178 $issue->{'subtitle'} = GetRecordValue
('subtitle', GetMarcBiblio
($issue->{'biblionumber'}), GetFrameworkCode
($issue->{'biblionumber'}));
179 # check if item is renewable
180 my ($status,$renewerror) = CanBookBeRenewed
( $borrowernumber, $issue->{'itemnumber'} );
181 ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount
($borrowernumber, $issue->{'itemnumber'});
182 if($status && C4
::Context
->preference("OpacRenewalAllowed")){
183 $issue->{'status'} = $status;
185 $issue->{'too_many'} = 1 if $renewerror and $renewerror eq 'too_many';
186 $issue->{'on_reserve'} = 1 if $renewerror and $renewerror eq 'on_reserve';
188 if ( $issue->{'overdue'} ) {
189 push @overdues, $issue;
191 $issue->{'overdue'} = 1;
194 $issue->{'issued'} = 1;
197 my $itemtype = $issue->{'itemtype'};
199 $issue->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
200 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
202 push @issuedat, $issue;
205 my $isbn = GetNormalizedISBN
($issue->{'isbn'});
206 $issue->{normalized_isbn
} = $isbn;
209 if (my $my_summary_html = C4
::Context
->preference('OPACMySummaryHTML')){
210 $issue->{author
} ?
$my_summary_html =~ s/{AUTHOR}/$issue->{author}/g : $my_summary_html =~ s/{AUTHOR}//g;
211 $issue->{title
} =~ s/\/+$//; # remove trailing slash
212 $issue->{title
} =~ s/\s+$//; # remove trailing space
213 $issue->{title
} ?
$my_summary_html =~ s/{TITLE}/$issue->{title}/g : $my_summary_html =~ s/{TITLE}//g;
214 $issue->{isbn
} ?
$my_summary_html =~ s/{ISBN}/$isbn/g : $my_summary_html =~ s/{ISBN}//g;
215 $issue->{biblionumber
} ?
$my_summary_html =~ s/{BIBLIONUMBER}/$issue->{biblionumber}/g : $my_summary_html =~ s/{BIBLIONUMBER}//g;
216 $issue->{MySummaryHTML
} = $my_summary_html;
220 $template->param( ISSUES
=> \
@issuedat );
221 $template->param( issues_count
=> $count );
222 $template->param( canrenew
=> $canrenew );
223 $template->param( OVERDUES
=> \
@overdues );
224 $template->param( overdues_count
=> $overdues_count );
226 my $show_barcode = C4
::Members
::AttributeTypes
::AttributeTypeExists
( ATTRIBUTE_SHOW_BARCODE
);
228 my $patron_show_barcode = GetBorrowerAttributeValue
($borrowernumber, ATTRIBUTE_SHOW_BARCODE
);
229 undef $show_barcode if defined($patron_show_barcode) && !$patron_show_barcode;
231 $template->param( show_barcode
=> 1 ) if $show_barcode;
234 my $branches = GetBranches
();
236 for my $branch_hash ( sort keys %{$branches} ) {
238 if ( C4
::Context
->preference('SearchMyLibraryFirst') ) {
240 ( C4
::Context
->userenv
241 && ( $branch_hash eq C4
::Context
->userenv->{branch
} ) );
244 { value
=> "branch: $branch_hash",
245 branchname
=> $branches->{$branch_hash}->{'branchname'},
246 selected
=> $selected,
249 $template->param( branchloop
=> \
@branch_loop );
251 # now the reserved items....
252 my @reserves = GetReservesFromBorrowernumber
( $borrowernumber );
253 foreach my $res (@reserves) {
255 if ( $res->{'expirationdate'} eq '0000-00-00' ) {
256 $res->{'expirationdate'} = '';
258 $res->{'subtitle'} = GetRecordValue
('subtitle', GetMarcBiblio
($res->{'biblionumber'}), GetFrameworkCode
($res->{'biblionumber'}));
259 $res->{'waiting'} = 1 if $res->{'found'} eq 'W';
260 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
261 my $biblioData = GetBiblioData
($res->{'biblionumber'});
262 $res->{'reserves_title'} = $biblioData->{'title'};
263 if ($show_priority) {
264 $res->{'priority'} ||= '';
266 $res->{'suspend_until'} = C4
::Dates
->new( $res->{'suspend_until'}, "iso")->output("syspref") if ( $res->{'suspend_until'} );
270 # warn Dumper(@reserves);
272 $template->param( RESERVES
=> \
@reserves );
273 $template->param( reserves_count
=> $#reserves+1 );
274 $template->param( showpriority
=>$show_priority );
278 foreach my $res (@reserves) {
279 if ( $res->{'itemnumber'} ) {
280 my $item = GetItem
( $res->{'itemnumber'});
281 $res->{'holdingbranch'} =
282 $branches->{ $item->{'holdingbranch'} }->{'branchname'};
283 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
284 # get document reserve status
285 my $biblioData = GetBiblioData
($res->{'biblionumber'});
286 $res->{'waiting_title'} = $biblioData->{'title'};
287 if ( ( $res->{'found'} eq 'W' ) ) {
288 my $item = $res->{'itemnumber'};
289 $item = GetBiblioFromItemNumber
($item,undef);
291 $res->{'holdingbranch'}=$item->{'holdingbranch'};
292 $res->{'biblionumber'}=$item->{'biblionumber'};
293 $res->{'barcode'} = $item->{'barcode'};
294 $res->{'wbrcode'} = $res->{'branchcode'};
295 $res->{'itemnumber'} = $res->{'itemnumber'};
296 $res->{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
297 if($res->{'holdingbranch'} eq $res->{'wbrcode'}){
298 $res->{'atdestination'} = 1;
300 # set found to 1 if reserve is waiting for patron pickup
301 $res->{'found'} = 1 if $res->{'found'} eq 'W';
303 my ($transfertwhen, $transfertfrom, $transfertto) = GetTransfers
( $res->{'itemnumber'} );
304 if ($transfertwhen) {
305 $res->{intransit
} = 1;
306 $res->{datesent
} = $transfertwhen;
307 $res->{frombranch
} = GetBranchName
($transfertfrom);
314 #$res->{'cancelable'} = 1 if ($res->{'wait'} && $res->{'atdestination'} && $res->{'found'} ne "1");
315 $res->{'cancelable'} = 1 if ($res->{wait} and not $res->{found
}) or (not $res->{wait} and not $res->{intransit
});
319 $template->param( WAITING
=> \
@waiting );
321 # current alert subscriptions
322 my $alerts = getalert
($borrowernumber);
323 foreach ( @
$alerts ) {
324 $_->{ $_->{type
} } = 1;
325 $_->{relatedto
} = findrelatedto
( $_->{type
}, $_->{externalid
} );
328 if (C4
::Context
->preference('BakerTaylorEnabled')) {
330 BakerTaylorEnabled
=> 1,
331 BakerTaylorImageURL
=> &image_url
(),
332 BakerTaylorLinkURL
=> &link_url
(),
333 BakerTaylorBookstoreURL
=> C4
::Context
->preference('BakerTaylorBookstoreURL'),
337 if (C4
::Context
->preference("OPACAmazonCoverImages") or
338 C4
::Context
->preference("GoogleJackets") or
339 C4
::Context
->preference("BakerTaylorEnabled") or
340 C4
::Context
->preference("SyndeticsCoverImages")) {
341 $template->param(JacketImages
=>1);
344 if ( GetMessagesCount
( $borrowernumber, 'B' ) ) {
345 $template->param( bor_messages
=> 1 );
348 if ( $borr->{'opacnote'} ) {
351 opacnote
=> $borr->{'opacnote'},
356 bor_messages_loop
=> GetMessages
( $borrowernumber, 'B', 'NONE' ),
357 waiting_count
=> $wcount,
358 patronupdate
=> $patronupdate,
359 OpacRenewalAllowed
=> C4
::Context
->preference("OpacRenewalAllowed"),
364 SuspendHoldsOpac
=> C4
::Context
->preference('SuspendHoldsOpac'),
365 AutoResumeSuspendedHolds
=> C4
::Context
->preference('AutoResumeSuspendedHolds'),
366 OpacHoldNotes
=> C4
::Context
->preference('OpacHoldNotes'),
369 output_html_with_http_headers
$query, $cookie, $template->output;