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
} && C4
::Context
->preference('NotifyBorrowerDeparture') &&
129 Date_to_Days
(Add_Delta_Days
($warning_year,$warning_month,$warning_day,- C4
::Context
->preference('NotifyBorrowerDeparture'))) <
130 Date_to_Days
( $today_year, $today_month, $today_day ) )
132 # borrower card soon to expire, warn the borrower
133 $borr->{'warndeparture'} = $borr->{dateexpiry
};
134 if (C4
::Context
->preference('ReturnBeforeExpiry')){
135 $borr->{'returnbeforeexpiry'} = 1;
139 $template->param( BORROWER_INFO
=> \
@bordat,
140 borrowernumber
=> $borrowernumber,
141 patron_flagged
=> $borr->{flagged
},
142 OPACMySummaryHTML
=> (C4
::Context
->preference("OPACMySummaryHTML")) ?
1 : 0,
143 surname
=> $borr->{surname
},
144 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;
176 # get publictype for icon
178 my $publictype = $issue->{'publictype'};
179 $issue->{$publictype} = 1;
181 # check if item is renewable
182 my ($status,$renewerror) = CanBookBeRenewed
( $borrowernumber, $issue->{'itemnumber'} );
183 ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount
($borrowernumber, $issue->{'itemnumber'});
184 if($status && C4
::Context
->preference("OpacRenewalAllowed")){
185 $issue->{'status'} = $status;
187 $issue->{'too_many'} = 1 if $renewerror and $renewerror eq 'too_many';
188 $issue->{'on_reserve'} = 1 if $renewerror and $renewerror eq 'on_reserve';
190 if ( $issue->{'overdue'} ) {
191 push @overdues, $issue;
193 $issue->{'overdue'} = 1;
196 $issue->{'issued'} = 1;
199 my $itemtype = $issue->{'itemtype'};
201 $issue->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
202 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
204 push @issuedat, $issue;
207 my $isbn = GetNormalizedISBN
($issue->{'isbn'});
208 $issue->{normalized_isbn
} = $isbn;
211 if (my $my_summary_html = C4
::Context
->preference('OPACMySummaryHTML')){
212 $issue->{author
} ?
$my_summary_html =~ s/{AUTHOR}/$issue->{author}/g : $my_summary_html =~ s/{AUTHOR}//g;
213 $issue->{title
} =~ s/\/+$//; # remove trailing slash
214 $issue->{title
} =~ s/\s+$//; # remove trailing space
215 $issue->{title
} ?
$my_summary_html =~ s/{TITLE}/$issue->{title}/g : $my_summary_html =~ s/{TITLE}//g;
216 $issue->{isbn
} ?
$my_summary_html =~ s/{ISBN}/$isbn/g : $my_summary_html =~ s/{ISBN}//g;
217 $issue->{biblionumber
} ?
$my_summary_html =~ s/{BIBLIONUMBER}/$issue->{biblionumber}/g : $my_summary_html =~ s/{BIBLIONUMBER}//g;
218 $issue->{MySummaryHTML
} = $my_summary_html;
222 $template->param( ISSUES
=> \
@issuedat );
223 $template->param( issues_count
=> $count );
224 $template->param( canrenew
=> $canrenew );
225 $template->param( OVERDUES
=> \
@overdues );
226 $template->param( overdues_count
=> $overdues_count );
228 my $show_barcode = C4
::Members
::AttributeTypes
::AttributeTypeExists
( ATTRIBUTE_SHOW_BARCODE
);
230 my $patron_show_barcode = GetBorrowerAttributeValue
($borrowernumber, ATTRIBUTE_SHOW_BARCODE
);
231 undef $show_barcode if defined($patron_show_barcode) && !$patron_show_barcode;
233 $template->param( show_barcode
=> 1 ) if $show_barcode;
236 my $branches = GetBranches
();
238 for my $branch_hash ( sort keys %{$branches} ) {
240 if ( C4
::Context
->preference('SearchMyLibraryFirst') ) {
242 ( C4
::Context
->userenv
243 && ( $branch_hash eq C4
::Context
->userenv->{branch
} ) );
246 { value
=> "branch: $branch_hash",
247 branchname
=> $branches->{$branch_hash}->{'branchname'},
248 selected
=> $selected,
251 $template->param( branchloop
=> \
@branch_loop );
253 # now the reserved items....
254 my @reserves = GetReservesFromBorrowernumber
( $borrowernumber );
255 foreach my $res (@reserves) {
257 if ( $res->{'expirationdate'} eq '0000-00-00' ) {
258 $res->{'expirationdate'} = '';
261 my $publictype = $res->{'publictype'};
262 $res->{$publictype} = 1;
263 $res->{'waiting'} = 1 if $res->{'found'} eq 'W';
264 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
265 my $biblioData = GetBiblioData
($res->{'biblionumber'});
266 $res->{'reserves_title'} = $biblioData->{'title'};
267 if ($show_priority) {
268 $res->{'priority'} ||= '';
270 $res->{'suspend_until'} = C4
::Dates
->new( $res->{'suspend_until'}, "iso")->output("syspref") if ( $res->{'suspend_until'} );
274 # warn Dumper(@reserves);
276 $template->param( RESERVES
=> \
@reserves );
277 $template->param( reserves_count
=> $#reserves+1 );
278 $template->param( showpriority
=>$show_priority );
282 foreach my $res (@reserves) {
283 if ( $res->{'itemnumber'} ) {
284 my $item = GetItem
( $res->{'itemnumber'});
285 $res->{'holdingbranch'} =
286 $branches->{ $item->{'holdingbranch'} }->{'branchname'};
287 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
288 # get document reserve status
289 my $biblioData = GetBiblioData
($res->{'biblionumber'});
290 $res->{'waiting_title'} = $biblioData->{'title'};
291 if ( ( $res->{'found'} eq 'W' ) ) {
292 my $item = $res->{'itemnumber'};
293 $item = GetBiblioFromItemNumber
($item,undef);
295 $res->{'holdingbranch'}=$item->{'holdingbranch'};
296 $res->{'biblionumber'}=$item->{'biblionumber'};
297 $res->{'barcode'} = $item->{'barcode'};
298 $res->{'wbrcode'} = $res->{'branchcode'};
299 $res->{'itemnumber'} = $res->{'itemnumber'};
300 $res->{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
301 if($res->{'holdingbranch'} eq $res->{'wbrcode'}){
302 $res->{'atdestination'} = 1;
304 # set found to 1 if reserve is waiting for patron pickup
305 $res->{'found'} = 1 if $res->{'found'} eq 'W';
307 my ($transfertwhen, $transfertfrom, $transfertto) = GetTransfers
( $res->{'itemnumber'} );
308 if ($transfertwhen) {
309 $res->{intransit
} = 1;
310 $res->{datesent
} = $transfertwhen;
311 $res->{frombranch
} = GetBranchName
($transfertfrom);
318 #$res->{'cancelable'} = 1 if ($res->{'wait'} && $res->{'atdestination'} && $res->{'found'} ne "1");
319 $res->{'cancelable'} = 1 if ($res->{wait} and not $res->{found
}) or (not $res->{wait} and not $res->{intransit
});
323 $template->param( WAITING
=> \
@waiting );
325 # current alert subscriptions
326 my $alerts = getalert
($borrowernumber);
327 foreach ( @
$alerts ) {
328 $_->{ $_->{type
} } = 1;
329 $_->{relatedto
} = findrelatedto
( $_->{type
}, $_->{externalid
} );
332 if (C4
::Context
->preference('BakerTaylorEnabled')) {
334 BakerTaylorEnabled
=> 1,
335 BakerTaylorImageURL
=> &image_url
(),
336 BakerTaylorLinkURL
=> &link_url
(),
337 BakerTaylorBookstoreURL
=> C4
::Context
->preference('BakerTaylorBookstoreURL'),
341 if (C4
::Context
->preference("OPACAmazonCoverImages") or
342 C4
::Context
->preference("GoogleJackets") or
343 C4
::Context
->preference("BakerTaylorEnabled") or
344 C4
::Context
->preference("SyndeticsCoverImages")) {
345 $template->param(JacketImages
=>1);
348 if ( GetMessagesCount
( $borrowernumber, 'B' ) ) {
349 $template->param( bor_messages
=> 1 );
352 if ( $borr->{'opacnote'} ) {
355 opacnote
=> $borr->{'opacnote'},
360 bor_messages_loop
=> GetMessages
( $borrowernumber, 'B', 'NONE' ),
361 waiting_count
=> $wcount,
362 patronupdate
=> $patronupdate,
363 OpacRenewalAllowed
=> C4
::Context
->preference("OpacRenewalAllowed"),
365 dateformat
=> C4
::Context
->preference("dateformat"),
368 $template->param( DHTMLcalendar_dateformat
=> C4
::Dates
->DHTMLcalendar() );
370 SuspendHoldsOpac
=> C4
::Context
->preference('SuspendHoldsOpac'),
371 AutoResumeSuspendedHolds
=> C4
::Context
->preference('AutoResumeSuspendedHolds') ,
374 output_html_with_http_headers
$query, $cookie, $template->output;