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 with
16 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
17 # Suite 330, Boston, MA 02111-1307 USA
21 #use warnings; FIXME - Bug 2505
30 use C4::Members::AttributeTypes;
31 use C4::Members::Attributes qw/GetBorrowerAttributeValue/;
35 use C4::Dates qw/format_date/;
37 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');
70 # get borrower information ....
71 my ( $borr ) = GetMemberDetails( $borrowernumber );
73 my ( $today_year, $today_month, $today_day) = Today();
74 my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
76 for (qw(dateenrolled dateexpiry dateofbirth)) {
77 ($borr->{$_}) and $borr->{$_} = format_date($borr->{$_});
79 $borr->{'ethnicity'} = fixEthnicity( $borr->{'ethnicity'} );
81 if ( $borr->{'debarred'} || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
82 $borr->{'flagged'} = 1;
85 if ( $borr->{'amountoutstanding'} > 5 ) {
86 $borr->{'amountoverfive'} = 1;
88 if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
89 $borr->{'amountoverzero'} = 1;
91 my $no_renewal_amt = C4::Context->preference( 'OPACFineNoRenewals' );
92 $no_renewal_amt ||= 0;
94 if ( $borr->{amountoutstanding} > $no_renewal_amt ) {
95 $borr->{'flagged'} = 1;
97 renewal_blocked_fines => sprintf( '%.02f', $no_renewal_amt ),
101 if ( $borr->{'amountoutstanding'} < 0 ) {
102 $borr->{'amountlessthanzero'} = 1;
103 $borr->{'amountoutstanding'} = -1 * ( $borr->{'amountoutstanding'} );
106 $borr->{'amountoutstanding'} = sprintf "%.02f", $borr->{'amountoutstanding'};
111 # Warningdate is the date that the warning starts appearing
112 if ( C4::Context->preference('NotifyBorrowerDeparture') &&
113 Date_to_Days(Add_Delta_Days($warning_year,$warning_month,$warning_day,- C4::Context->preference('NotifyBorrowerDeparture'))) <
114 Date_to_Days( $today_year, $today_month, $today_day ) )
116 # borrower card soon to expire, warn the borrower
117 $borr->{'warndeparture'} = $borr->{dateexpiry};
118 if (C4::Context->preference('ReturnBeforeExpiry')){
119 $borr->{'returnbeforeexpiry'} = 1;
123 $template->param( BORROWER_INFO => \@bordat,
124 borrowernumber => $borrowernumber,
125 patron_flagged => $borr->{flagged},
126 OPACMySummaryHTML => (C4::Context->preference("OPACMySummaryHTML")) ? 1 : 0,
127 surname => $borr->{surname},
128 showname => $borr->{showname},
131 #get issued items ....
135 my $overdues_count = 0;
138 my $itemtypes = GetItemTypes();
139 my ($issues) = GetPendingIssues($borrowernumber);
142 foreach my $issue ( sort { $b->{'date_due'} cmp $a->{'date_due'} } @$issues ) {
144 my ( $restype, $res ) = CheckReserves( $issue->{'itemnumber'} );
146 $issue->{'reserved'} = 1;
149 my ( $total , $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
151 foreach my $ac (@$accts) {
152 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
153 $charges += $ac->{'amountoutstanding'}
154 if $ac->{'accounttype'} eq 'F';
155 $charges += $ac->{'amountoutstanding'}
156 if $ac->{'accounttype'} eq 'L';
159 $issue->{'charges'} = $charges;
161 # get publictype for icon
163 my $publictype = $issue->{'publictype'};
164 $issue->{$publictype} = 1;
166 # check if item is renewable
167 my ($status,$renewerror) = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} );
168 ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount($borrowernumber, $issue->{'itemnumber'});
169 if($status && C4::Context->preference("OpacRenewalAllowed")){
170 $issue->{'status'} = $status;
173 $issue->{'too_many'} = 1 if $renewerror and $renewerror eq 'too_many';
174 $issue->{'on_reserve'} = 1 if $renewerror and $renewerror eq 'on_reserve';
176 if ( $issue->{'overdue'} ) {
177 push @overdues, $issue;
179 $issue->{'overdue'} = 1;
182 $issue->{'issued'} = 1;
185 my $itemtype = $issue->{'itemtype'};
187 $issue->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
188 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
190 $issue->{date_due} = format_date($issue->{date_due});
191 push @issuedat, $issue;
194 my $isbn = GetNormalizedISBN($issue->{'isbn'});
195 $issue->{normalized_isbn} = $isbn;
198 if (my $my_summary_html = C4::Context->preference('OPACMySummaryHTML')){
199 $issue->{author} ? $my_summary_html =~ s/{AUTHOR}/$issue->{author}/g : $my_summary_html =~ s/{AUTHOR}//g;
200 $issue->{title} =~ s/\/+$//; # remove trailing slash
201 $issue->{title} =~ s/\s+$//; # remove trailing space
202 $issue->{title} ? $my_summary_html =~ s/{TITLE}/$issue->{title}/g : $my_summary_html =~ s/{TITLE}//g;
203 $issue->{isbn} ? $my_summary_html =~ s/{ISBN}/$isbn/g : $my_summary_html =~ s/{ISBN}//g;
204 $issue->{biblionumber} ? $my_summary_html =~ s/{BIBLIONUMBER}/$issue->{biblionumber}/g : $my_summary_html =~ s/{BIBLIONUMBER}//g;
205 $issue->{MySummaryHTML} = $my_summary_html;
209 $template->param( ISSUES => \@issuedat );
210 $template->param( issues_count => $count );
211 $template->param( canrenew => $canrenew );
212 $template->param( OVERDUES => \@overdues );
213 $template->param( overdues_count => $overdues_count );
215 my $show_barcode = C4::Members::AttributeTypes::AttributeTypeExists( ATTRIBUTE_SHOW_BARCODE );
217 my $patron_show_barcode = GetBorrowerAttributeValue($borrowernumber, ATTRIBUTE_SHOW_BARCODE);
218 undef $show_barcode if defined($patron_show_barcode) && !$patron_show_barcode;
220 $template->param( show_barcode => 1 ) if $show_barcode;
223 my $branches = GetBranches();
225 for my $branch_hash ( sort keys %{$branches} ) {
227 if ( C4::Context->preference('SearchMyLibraryFirst') ) {
229 ( C4::Context->userenv
230 && ( $branch_hash eq C4::Context->userenv->{branch} ) );
233 { value => "branch: $branch_hash",
234 branchname => $branches->{$branch_hash}->{'branchname'},
235 selected => $selected,
238 $template->param( branchloop => \@branch_loop );
240 # now the reserved items....
241 my @reserves = GetReservesFromBorrowernumber( $borrowernumber );
242 foreach my $res (@reserves) {
243 $res->{'reservedate'} = format_date( $res->{'reservedate'} );
245 if ( $res->{'expirationdate'} ne '0000-00-00' ) {
246 $res->{'expirationdate'} = format_date( $res->{'expirationdate'} )
248 $res->{'expirationdate'} = '';
251 my $publictype = $res->{'publictype'};
252 $res->{$publictype} = 1;
253 $res->{'waiting'} = 1 if $res->{'found'} eq 'W';
254 $res->{'formattedwaitingdate'} = format_date($res->{'waitingdate'});
255 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
256 my $biblioData = GetBiblioData($res->{'biblionumber'});
257 $res->{'reserves_title'} = $biblioData->{'title'};
258 if ($OPACDisplayRequestPriority) {
259 $res->{'priority'} = '' if $res->{'priority'} eq '0';
264 # warn Dumper(@reserves);
266 $template->param( RESERVES => \@reserves );
267 $template->param( reserves_count => $#reserves+1 );
268 $template->param( showpriority=>1 ) if $OPACDisplayRequestPriority;
272 foreach my $res (@reserves) {
273 if ( $res->{'itemnumber'} ) {
274 my $item = GetItem( $res->{'itemnumber'});
275 $res->{'holdingbranch'} =
276 $branches->{ $item->{'holdingbranch'} }->{'branchname'};
277 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
278 # get document reserve status
279 my $biblioData = GetBiblioData($res->{'biblionumber'});
280 $res->{'waiting_title'} = $biblioData->{'title'};
281 if ( ( $res->{'found'} eq 'W' ) ) {
282 my $item = $res->{'itemnumber'};
283 $item = GetBiblioFromItemNumber($item,undef);
285 $res->{'holdingbranch'}=$item->{'holdingbranch'};
286 $res->{'biblionumber'}=$item->{'biblionumber'};
287 $res->{'barcode'} = $item->{'barcode'};
288 $res->{'wbrcode'} = $res->{'branchcode'};
289 $res->{'itemnumber'} = $res->{'itemnumber'};
290 $res->{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
291 if($res->{'holdingbranch'} eq $res->{'wbrcode'}){
292 $res->{'atdestination'} = 1;
294 # set found to 1 if reserve is waiting for patron pickup
295 $res->{'found'} = 1 if $res->{'found'} eq 'W';
297 my ($transfertwhen, $transfertfrom, $transfertto) = GetTransfers( $res->{'itemnumber'} );
298 if ($transfertwhen) {
299 $res->{intransit} = 1;
300 $res->{datesent} = format_date($transfertwhen);
301 $res->{frombranch} = GetBranchName($transfertfrom);
308 #$res->{'cancelable'} = 1 if ($res->{'wait'} && $res->{'atdestination'} && $res->{'found'} ne "1");
309 $res->{'cancelable'} = 1 if ($res->{wait} and not $res->{found}) or (not $res->{wait} and not $res->{intransit});
313 $template->param( WAITING => \@waiting );
315 # current alert subscriptions
316 my $alerts = getalert($borrowernumber);
317 foreach ( @$alerts ) {
318 $_->{ $_->{type} } = 1;
319 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
322 if (C4::Context->preference('BakerTaylorEnabled')) {
324 BakerTaylorEnabled => 1,
325 BakerTaylorImageURL => &image_url(),
326 BakerTaylorLinkURL => &link_url(),
327 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
331 if (C4::Context->preference("OPACAmazonCoverImages") or
332 C4::Context->preference("GoogleJackets") or
333 C4::Context->preference("BakerTaylorEnabled") or
334 C4::Context->preference("SyndeticsCoverImages")) {
335 $template->param(JacketImages=>1);
338 if ( GetMessagesCount( $borrowernumber, 'B' ) ) {
339 $template->param( bor_messages => 1 );
342 if ( $borr->{'opacnote'} ) {
345 opacnote => $borr->{'opacnote'},
350 bor_messages_loop => GetMessages( $borrowernumber, 'B', 'NONE' ),
351 waiting_count => $wcount,
352 textmessaging => $borr->{textmessaging},
353 patronupdate => $patronupdate,
354 OpacRenewalAllowed => C4::Context->preference("OpacRenewalAllowed"),
356 dateformat => C4::Context->preference("dateformat"),
359 output_html_with_http_headers $query, $cookie, $template->output;