Bug 13748: Acquisition wizard: some strings not translatable
[koha.git] / opac / opac-user.pl
blob995db7b0111b510bce0588afb9f753f6fa16cfce
1 #!/usr/bin/perl
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
9 # version.
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.
20 use strict;
21 #use warnings; FIXME - Bug 2505
23 use CGI qw ( -utf8 );
25 use C4::Auth;
26 use C4::Koha;
27 use C4::Circulation;
28 use C4::Reserves;
29 use C4::Members;
30 use C4::Members::AttributeTypes;
31 use C4::Members::Attributes qw/GetBorrowerAttributeValue/;
32 use C4::Output;
33 use C4::Biblio;
34 use C4::Items;
35 use C4::Letters;
36 use C4::Branch; # GetBranches
37 use Koha::DateUtils;
38 use Koha::Borrower::Debarments qw(IsDebarred);
40 use constant ATTRIBUTE_SHOW_BARCODE => 'SHOW_BCODE';
42 use Date::Calc qw(
43 Today
44 Add_Delta_Days
45 Date_to_Days
48 my $query = new CGI;
50 BEGIN {
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.tt",
60 query => $query,
61 type => "opac",
62 authnotrequired => 0,
63 flagsrequired => { borrow => 1 },
64 debug => 1,
68 my %renewed = map { $_ => 1 } split( ':', $query->param('renewed') );
70 my $show_priority;
71 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
72 m/priority/ and $show_priority = 1;
75 my $patronupdate = $query->param('patronupdate');
76 my $canrenew = 1;
78 $template->param( shibbolethAuthentication => C4::Context->config('useshibboleth') );
80 # get borrower information ....
81 my ( $borr ) = GetMemberDetails( $borrowernumber );
83 my ( $today_year, $today_month, $today_day) = Today();
84 my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
86 $borr->{'ethnicity'} = fixEthnicity( $borr->{'ethnicity'} );
88 my $debar = IsDebarred($borrowernumber);
89 my $userdebarred;
91 if ($debar) {
92 $userdebarred = 1;
93 $template->param( 'userdebarred' => $userdebarred );
94 if ( $debar ne "9999-12-31" ) {
95 $borr->{'userdebarreddate'} = $debar;
99 if ( $userdebarred || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
100 $borr->{'flagged'} = 1;
101 $canrenew = 0;
104 if ( $borr->{'amountoutstanding'} > 5 ) {
105 $borr->{'amountoverfive'} = 1;
107 if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
108 $borr->{'amountoverzero'} = 1;
110 my $no_renewal_amt = C4::Context->preference( 'OPACFineNoRenewals' );
111 $no_renewal_amt ||= 0;
113 if ( C4::Context->preference( 'OpacRenewalAllowed' ) && $borr->{amountoutstanding} > $no_renewal_amt ) {
114 $borr->{'flagged'} = 1;
115 $canrenew = 0;
116 $template->param(
117 renewal_blocked_fines => sprintf( '%.02f', $no_renewal_amt ),
118 renewal_blocked_fines_amountoutstanding => sprintf( '%.02f', $borr->{amountoutstanding} ),
122 if ( $borr->{'amountoutstanding'} < 0 ) {
123 $borr->{'amountlessthanzero'} = 1;
124 $borr->{'amountoutstanding'} = -1 * ( $borr->{'amountoutstanding'} );
127 $borr->{'amountoutstanding'} = sprintf "%.02f", $borr->{'amountoutstanding'};
129 my @bordat;
130 $bordat[0] = $borr;
132 # Warningdate is the date that the warning starts appearing
133 if ( $borr->{'dateexpiry'} && C4::Context->preference('NotifyBorrowerDeparture') ) {
134 my $days_to_expiry = Date_to_Days( $warning_year, $warning_month, $warning_day ) - Date_to_Days( $today_year, $today_month, $today_day );
135 if ( $days_to_expiry < 0 ) {
136 #borrower card has expired, warn the borrower
137 $borr->{'warnexpired'} = $borr->{'dateexpiry'};
138 } elsif ( $days_to_expiry < C4::Context->preference('NotifyBorrowerDeparture') ) {
139 # borrower card soon to expire, warn the borrower
140 $borr->{'warndeparture'} = $borr->{dateexpiry};
141 if (C4::Context->preference('ReturnBeforeExpiry')){
142 $borr->{'returnbeforeexpiry'} = 1;
147 # pass on any renew errors to the template for displaying
148 my $renew_error = $query->param('renew_error');
150 $template->param( BORROWER_INFO => \@bordat,
151 borrowernumber => $borrowernumber,
152 patron_flagged => $borr->{flagged},
153 OPACMySummaryHTML => (C4::Context->preference("OPACMySummaryHTML")) ? 1 : 0,
154 surname => $borr->{surname},
155 showname => $borr->{showname},
156 RENEW_ERROR => $renew_error,
157 borrower => $borr,
160 #get issued items ....
162 my $count = 0;
163 my $overdues_count = 0;
164 my @overdues;
165 my @issuedat;
166 my $itemtypes = GetItemTypes();
167 my $issues = GetPendingIssues($borrowernumber);
168 if ($issues){
169 foreach my $issue ( sort { $b->{date_due}->datetime() cmp $a->{date_due}->datetime() } @{$issues} ) {
170 # check for reserves
171 my $restype = GetReserveStatus( $issue->{'itemnumber'} );
172 if ( $restype ) {
173 $issue->{'reserved'} = 1;
176 my ( $total , $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
177 my $charges = 0;
178 foreach my $ac (@$accts) {
179 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
180 $charges += $ac->{'amountoutstanding'}
181 if $ac->{'accounttype'} eq 'F';
182 $charges += $ac->{'amountoutstanding'}
183 if $ac->{'accounttype'} eq 'FU';
184 $charges += $ac->{'amountoutstanding'}
185 if $ac->{'accounttype'} eq 'L';
188 $issue->{'charges'} = $charges;
189 $issue->{'subtitle'} = GetRecordValue('subtitle', GetMarcBiblio($issue->{'biblionumber'}), GetFrameworkCode($issue->{'biblionumber'}));
190 # check if item is renewable
191 my ($status,$renewerror) = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} );
192 ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount($borrowernumber, $issue->{'itemnumber'});
193 if($status && C4::Context->preference("OpacRenewalAllowed")){
194 $issue->{'status'} = $status;
197 $issue->{'renewed'} = $renewed{ $issue->{'itemnumber'} };
199 if ($renewerror) {
200 $issue->{'too_many'} = 1 if $renewerror eq 'too_many';
201 $issue->{'on_reserve'} = 1 if $renewerror eq 'on_reserve';
202 $issue->{'auto_renew'} = 1 if $renewerror eq 'auto_renew';
203 $issue->{'auto_too_soon'} = 1 if $renewerror eq 'auto_too_soon';
205 if ( $renewerror eq 'too_soon' ) {
206 $issue->{'too_soon'} = 1;
207 $issue->{'soonestrenewdate'} = output_pref(
208 C4::Circulation::GetSoonestRenewDate(
209 $issue->{borrowernumber},
210 $issue->{itemnumber}
216 if ( $issue->{'overdue'} ) {
217 push @overdues, $issue;
218 $overdues_count++;
219 $issue->{'overdue'} = 1;
221 else {
222 $issue->{'issued'} = 1;
224 # imageurl:
225 my $itemtype = $issue->{'itemtype'};
226 if ( $itemtype ) {
227 $issue->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
228 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
230 push @issuedat, $issue;
231 $count++;
233 my $isbn = GetNormalizedISBN($issue->{'isbn'});
234 $issue->{normalized_isbn} = $isbn;
236 # My Summary HTML
237 if (my $my_summary_html = C4::Context->preference('OPACMySummaryHTML')){
238 $issue->{author} ? $my_summary_html =~ s/{AUTHOR}/$issue->{author}/g : $my_summary_html =~ s/{AUTHOR}//g;
239 $issue->{title} =~ s/\/+$//; # remove trailing slash
240 $issue->{title} =~ s/\s+$//; # remove trailing space
241 $issue->{title} ? $my_summary_html =~ s/{TITLE}/$issue->{title}/g : $my_summary_html =~ s/{TITLE}//g;
242 $issue->{isbn} ? $my_summary_html =~ s/{ISBN}/$isbn/g : $my_summary_html =~ s/{ISBN}//g;
243 $issue->{biblionumber} ? $my_summary_html =~ s/{BIBLIONUMBER}/$issue->{biblionumber}/g : $my_summary_html =~ s/{BIBLIONUMBER}//g;
244 $issue->{MySummaryHTML} = $my_summary_html;
248 $template->param( ISSUES => \@issuedat );
249 $template->param( issues_count => $count );
250 $template->param( canrenew => $canrenew );
251 $template->param( OVERDUES => \@overdues );
252 $template->param( overdues_count => $overdues_count );
254 my $show_barcode = C4::Members::AttributeTypes::AttributeTypeExists( ATTRIBUTE_SHOW_BARCODE );
255 if ($show_barcode) {
256 my $patron_show_barcode = GetBorrowerAttributeValue($borrowernumber, ATTRIBUTE_SHOW_BARCODE);
257 undef $show_barcode if defined($patron_show_barcode) && !$patron_show_barcode;
259 $template->param( show_barcode => 1 ) if $show_barcode;
261 # load the branches
262 my $branches = GetBranches();
263 my @branch_loop;
264 for my $branch_hash ( sort keys %{$branches} ) {
265 my $selected;
266 if ( C4::Context->preference('SearchMyLibraryFirst') ) {
267 $selected =
268 ( C4::Context->userenv
269 && ( $branch_hash eq C4::Context->userenv->{branch} ) );
271 push @branch_loop,
272 { value => "branch: $branch_hash",
273 branchname => $branches->{$branch_hash}->{'branchname'},
274 selected => $selected,
277 $template->param( branchloop => \@branch_loop );
279 # now the reserved items....
280 my @reserves = GetReservesFromBorrowernumber( $borrowernumber );
281 foreach my $res (@reserves) {
283 if ( $res->{'expirationdate'} eq '0000-00-00' ) {
284 $res->{'expirationdate'} = '';
286 $res->{'subtitle'} = GetRecordValue('subtitle', GetMarcBiblio($res->{'biblionumber'}), GetFrameworkCode($res->{'biblionumber'}));
287 $res->{'waiting'} = 1 if $res->{'found'} eq 'W';
288 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
289 my $biblioData = GetBiblioData($res->{'biblionumber'});
290 $res->{'reserves_title'} = $biblioData->{'title'};
291 $res->{'author'} = $biblioData->{'author'};
293 if ($show_priority) {
294 $res->{'priority'} ||= '';
296 $res->{'suspend_until'} = C4::Dates->new( $res->{'suspend_until'}, "iso")->output("syspref") if ( $res->{'suspend_until'} );
299 # use Data::Dumper;
300 # warn Dumper(@reserves);
302 $template->param( RESERVES => \@reserves );
303 $template->param( reserves_count => $#reserves+1 );
304 $template->param( showpriority=>$show_priority );
306 my @waiting;
307 my $wcount = 0;
308 foreach my $res (@reserves) {
309 if ( $res->{'itemnumber'} ) {
310 my $item = GetItem( $res->{'itemnumber'});
311 $res->{'holdingbranch'} =
312 $branches->{ $item->{'holdingbranch'} }->{'branchname'};
313 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
314 # get document reserve status
315 my $biblioData = GetBiblioData($res->{'biblionumber'});
316 $res->{'waiting_title'} = $biblioData->{'title'};
317 if ( ( $res->{'found'} eq 'W' ) ) {
318 my $item = $res->{'itemnumber'};
319 $item = GetBiblioFromItemNumber($item,undef);
320 $res->{'wait'}= 1;
321 $res->{'holdingbranch'}=$item->{'holdingbranch'};
322 $res->{'biblionumber'}=$item->{'biblionumber'};
323 $res->{'barcode'} = $item->{'barcode'};
324 $res->{'wbrcode'} = $res->{'branchcode'};
325 $res->{'itemnumber'} = $res->{'itemnumber'};
326 $res->{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
327 if($res->{'holdingbranch'} eq $res->{'wbrcode'}){
328 $res->{'atdestination'} = 1;
330 # set found to 1 if reserve is waiting for patron pickup
331 $res->{'found'} = 1 if $res->{'found'} eq 'W';
332 } else {
333 my ($transfertwhen, $transfertfrom, $transfertto) = GetTransfers( $res->{'itemnumber'} );
334 if ($transfertwhen) {
335 $res->{intransit} = 1;
336 $res->{datesent} = $transfertwhen;
337 $res->{frombranch} = GetBranchName($transfertfrom);
340 push @waiting, $res;
341 $wcount++;
343 # can be cancelled
344 #$res->{'cancelable'} = 1 if ($res->{'wait'} && $res->{'atdestination'} && $res->{'found'} ne "1");
345 $res->{'cancelable'} = 1 if ($res->{wait} and not $res->{found}) or (not $res->{wait} and not $res->{intransit});
349 $template->param( WAITING => \@waiting );
351 # current alert subscriptions
352 my $alerts = getalert($borrowernumber);
353 foreach ( @$alerts ) {
354 $_->{ $_->{type} } = 1;
355 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
358 if (C4::Context->preference('BakerTaylorEnabled')) {
359 $template->param(
360 BakerTaylorEnabled => 1,
361 BakerTaylorImageURL => &image_url(),
362 BakerTaylorLinkURL => &link_url(),
363 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
367 if (C4::Context->preference("OPACAmazonCoverImages") or
368 C4::Context->preference("GoogleJackets") or
369 C4::Context->preference("BakerTaylorEnabled") or
370 C4::Context->preference("SyndeticsCoverImages")) {
371 $template->param(JacketImages=>1);
374 if ( GetMessagesCount( $borrowernumber, 'B' ) ) {
375 $template->param( bor_messages => 1 );
378 if ( $borr->{'opacnote'} ) {
379 $template->param(
380 bor_messages => 1,
381 opacnote => $borr->{'opacnote'},
385 $template->param(
386 bor_messages_loop => GetMessages( $borrowernumber, 'B', 'NONE' ),
387 waiting_count => $wcount,
388 patronupdate => $patronupdate,
389 OpacRenewalAllowed => C4::Context->preference("OpacRenewalAllowed"),
390 userview => 1,
393 $template->param(
394 SuspendHoldsOpac => C4::Context->preference('SuspendHoldsOpac'),
395 AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
396 OpacHoldNotes => C4::Context->preference('OpacHoldNotes'),
399 output_html_with_http_headers $query, $cookie, $template->output;