Bug 16621: Translatability: Issues in opac-user.tt (sentence splitting)
[koha.git] / opac / opac-user.pl
blobec06d1d45d182f2f8f042ea370da595484d271b0
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
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
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::Patron::Debarments qw(IsDebarred);
39 use Koha::Holds;
40 use Koha::Database;
41 use Koha::Patron::Messages;
43 use constant ATTRIBUTE_SHOW_BARCODE => 'SHOW_BCODE';
45 use Scalar::Util qw(looks_like_number);
46 use Date::Calc qw(
47 Today
48 Add_Delta_Days
49 Date_to_Days
52 my $query = new CGI;
54 BEGIN {
55 if (C4::Context->preference('BakerTaylorEnabled')) {
56 require C4::External::BakerTaylor;
57 import C4::External::BakerTaylor qw(&image_url &link_url);
61 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
63 template_name => "opac-user.tt",
64 query => $query,
65 type => "opac",
66 authnotrequired => 0,
67 debug => 1,
71 my %renewed = map { $_ => 1 } split( ':', $query->param('renewed') );
73 my $show_priority;
74 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
75 m/priority/ and $show_priority = 1;
78 my $patronupdate = $query->param('patronupdate');
79 my $canrenew = 1;
81 $template->param( shibbolethAuthentication => C4::Context->config('useshibboleth') );
83 if (!$borrowernumber) {
84 $template->param( adminWarning => 1 );
87 # get borrower information ....
88 my ( $borr ) = GetMemberDetails( $borrowernumber );
90 my ( $today_year, $today_month, $today_day) = Today();
91 my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'};
93 my $debar = IsDebarred($borrowernumber);
94 my $userdebarred;
96 if ($debar) {
97 $userdebarred = 1;
98 $template->param( 'userdebarred' => $userdebarred );
99 if ( $debar ne "9999-12-31" ) {
100 $borr->{'userdebarreddate'} = $debar;
104 if ( $userdebarred || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
105 $borr->{'flagged'} = 1;
106 $canrenew = 0;
109 if ( $borr->{'amountoutstanding'} > 5 ) {
110 $borr->{'amountoverfive'} = 1;
112 if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
113 $borr->{'amountoverzero'} = 1;
115 my $no_renewal_amt = C4::Context->preference( 'OPACFineNoRenewals' );
116 $no_renewal_amt = undef unless looks_like_number( $no_renewal_amt );
118 if ( C4::Context->preference('OpacRenewalAllowed')
119 && defined($no_renewal_amt)
120 && $borr->{amountoutstanding} > $no_renewal_amt )
122 $borr->{'flagged'} = 1;
123 $canrenew = 0;
124 $template->param(
125 renewal_blocked_fines => $no_renewal_amt,
126 renewal_blocked_fines_amountoutstanding => $borr->{amountoutstanding},
130 if ( $borr->{'amountoutstanding'} < 0 ) {
131 $borr->{'amountlessthanzero'} = 1;
132 $borr->{'amountoutstanding'} = -1 * ( $borr->{'amountoutstanding'} );
135 # Warningdate is the date that the warning starts appearing
136 if ( $borr->{'dateexpiry'} && C4::Context->preference('NotifyBorrowerDeparture') ) {
137 my $days_to_expiry = Date_to_Days( $warning_year, $warning_month, $warning_day ) - Date_to_Days( $today_year, $today_month, $today_day );
138 if ( $days_to_expiry < 0 ) {
139 #borrower card has expired, warn the borrower
140 $borr->{'warnexpired'} = $borr->{'dateexpiry'};
141 } elsif ( $days_to_expiry < C4::Context->preference('NotifyBorrowerDeparture') ) {
142 # borrower card soon to expire, warn the borrower
143 $borr->{'warndeparture'} = $borr->{dateexpiry};
144 if (C4::Context->preference('ReturnBeforeExpiry')){
145 $borr->{'returnbeforeexpiry'} = 1;
150 # pass on any renew errors to the template for displaying
151 my $renew_error = $query->param('renew_error');
153 $template->param( BORROWER_INFO => $borr,
154 borrowernumber => $borrowernumber,
155 patron_flagged => $borr->{flagged},
156 OPACMySummaryHTML => (C4::Context->preference("OPACMySummaryHTML")) ? 1 : 0,
157 surname => $borr->{surname},
158 RENEW_ERROR => $renew_error,
159 borrower => $borr,
162 #get issued items ....
164 my $count = 0;
165 my $overdues_count = 0;
166 my @overdues;
167 my @issuedat;
168 my $itemtypes = GetItemTypes();
169 my $issues = GetPendingIssues($borrowernumber);
170 if ($issues){
171 foreach my $issue ( sort { $b->{date_due}->datetime() cmp $a->{date_due}->datetime() } @{$issues} ) {
172 # check for reserves
173 my $restype = GetReserveStatus( $issue->{'itemnumber'} );
174 if ( $restype ) {
175 $issue->{'reserved'} = 1;
178 my ( $total , $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
179 my $charges = 0;
180 foreach my $ac (@$accts) {
181 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
182 $charges += $ac->{'amountoutstanding'}
183 if $ac->{'accounttype'} eq 'F';
184 $charges += $ac->{'amountoutstanding'}
185 if $ac->{'accounttype'} eq 'FU';
186 $charges += $ac->{'amountoutstanding'}
187 if $ac->{'accounttype'} eq 'L';
190 $issue->{'charges'} = $charges;
191 my $marcrecord = GetMarcBiblio( $issue->{'biblionumber'} );
192 $issue->{'subtitle'} = GetRecordValue('subtitle', $marcrecord, GetFrameworkCode($issue->{'biblionumber'}));
193 # check if item is renewable
194 my ($status,$renewerror) = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} );
195 ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount($borrowernumber, $issue->{'itemnumber'});
196 if($status && C4::Context->preference("OpacRenewalAllowed")){
197 $issue->{'status'} = $status;
200 $issue->{'renewed'} = $renewed{ $issue->{'itemnumber'} };
202 if ($renewerror) {
203 $issue->{'too_many'} = 1 if $renewerror eq 'too_many';
204 $issue->{'on_reserve'} = 1 if $renewerror eq 'on_reserve';
205 $issue->{'norenew_overdue'} = 1 if $renewerror eq 'overdue';
206 $issue->{'auto_renew'} = 1 if $renewerror eq 'auto_renew';
207 $issue->{'auto_too_soon'} = 1 if $renewerror eq 'auto_too_soon';
209 if ( $renewerror eq 'too_soon' ) {
210 $issue->{'too_soon'} = 1;
211 $issue->{'soonestrenewdate'} = output_pref(
212 C4::Circulation::GetSoonestRenewDate(
213 $issue->{borrowernumber},
214 $issue->{itemnumber}
220 if ( $issue->{'overdue'} ) {
221 push @overdues, $issue;
222 $overdues_count++;
223 $issue->{'overdue'} = 1;
225 else {
226 $issue->{'issued'} = 1;
228 # imageurl:
229 my $itemtype = $issue->{'itemtype'};
230 if ( $itemtype ) {
231 $issue->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
232 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
234 push @issuedat, $issue;
235 $count++;
237 my $isbn = GetNormalizedISBN($issue->{'isbn'});
238 $issue->{normalized_isbn} = $isbn;
239 $issue->{normalized_upc} = GetNormalizedUPC( $marcrecord, C4::Context->preference('marcflavour') );
241 # My Summary HTML
242 if (my $my_summary_html = C4::Context->preference('OPACMySummaryHTML')){
243 $issue->{author} ? $my_summary_html =~ s/{AUTHOR}/$issue->{author}/g : $my_summary_html =~ s/{AUTHOR}//g;
244 $issue->{title} =~ s/\/+$//; # remove trailing slash
245 $issue->{title} =~ s/\s+$//; # remove trailing space
246 $issue->{title} ? $my_summary_html =~ s/{TITLE}/$issue->{title}/g : $my_summary_html =~ s/{TITLE}//g;
247 $issue->{isbn} ? $my_summary_html =~ s/{ISBN}/$isbn/g : $my_summary_html =~ s/{ISBN}//g;
248 $issue->{biblionumber} ? $my_summary_html =~ s/{BIBLIONUMBER}/$issue->{biblionumber}/g : $my_summary_html =~ s/{BIBLIONUMBER}//g;
249 $issue->{MySummaryHTML} = $my_summary_html;
253 my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
254 $canrenew = 0 if ($overduesblockrenewing ne 'allow' and $overdues_count == $count);
255 $template->param( ISSUES => \@issuedat );
256 $template->param( issues_count => $count );
257 $template->param( canrenew => $canrenew );
258 $template->param( OVERDUES => \@overdues );
259 $template->param( overdues_count => $overdues_count );
261 my $show_barcode = C4::Members::AttributeTypes::AttributeTypeExists( ATTRIBUTE_SHOW_BARCODE );
262 if ($show_barcode) {
263 my $patron_show_barcode = GetBorrowerAttributeValue($borrowernumber, ATTRIBUTE_SHOW_BARCODE);
264 undef $show_barcode if defined($patron_show_barcode) && !$patron_show_barcode;
266 $template->param( show_barcode => 1 ) if $show_barcode;
268 # load the branches
269 my $branches = GetBranches();
270 my @branch_loop;
271 for my $branch_hash ( sort keys %{$branches} ) {
272 my $selected;
273 if ( C4::Context->preference('SearchMyLibraryFirst') ) {
274 $selected =
275 ( C4::Context->userenv
276 && ( $branch_hash eq C4::Context->userenv->{branch} ) );
278 push @branch_loop,
279 { value => "branch: $branch_hash",
280 branchname => $branches->{$branch_hash}->{'branchname'},
281 selected => $selected,
284 $template->param( branchloop => \@branch_loop );
286 # now the reserved items....
287 my $reserves = Koha::Holds->search( { borrowernumber => $borrowernumber } );
289 $template->param(
290 RESERVES => $reserves,
291 showpriority => $show_priority,
294 # current alert subscriptions
295 my $alerts = getalert($borrowernumber);
296 foreach ( @$alerts ) {
297 $_->{ $_->{type} } = 1;
298 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
301 if (C4::Context->preference('BakerTaylorEnabled')) {
302 $template->param(
303 BakerTaylorEnabled => 1,
304 BakerTaylorImageURL => &image_url(),
305 BakerTaylorLinkURL => &link_url(),
306 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
310 if (C4::Context->preference("OPACAmazonCoverImages") or
311 C4::Context->preference("GoogleJackets") or
312 C4::Context->preference("BakerTaylorEnabled") or
313 C4::Context->preference("SyndeticsCoverImages")) {
314 $template->param(JacketImages=>1);
317 my $patron_messages = Koha::Patron::Messages->search(
319 borrowernumber => $borrowernumber,
320 message_type => 'B',
323 if ( $patron_messages->count ) {
324 $template->param( bor_messages => 1 );
327 if ( $borr->{'opacnote'} ) {
328 $template->param(
329 bor_messages => 1,
330 opacnote => $borr->{'opacnote'},
334 if ( C4::Context->preference('AllowPatronToSetCheckoutsVisibilityForGuarantor')
335 || C4::Context->preference('AllowStaffToSetCheckoutsVisibilityForGuarantor') )
337 my @relatives =
338 Koha::Database->new()->schema()->resultset("Borrower")->search(
340 privacy_guarantor_checkouts => 1,
341 'me.guarantorid' => $borrowernumber
343 { prefetch => [ { 'issues' => { 'item' => 'biblio' } } ] }
345 $template->param( relatives => \@relatives );
348 $template->param(
349 borrower => $borr,
350 patron_messages => $patron_messages,
351 patronupdate => $patronupdate,
352 OpacRenewalAllowed => C4::Context->preference("OpacRenewalAllowed"),
353 userview => 1,
354 SuspendHoldsOpac => C4::Context->preference('SuspendHoldsOpac'),
355 AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
356 OpacHoldNotes => C4::Context->preference('OpacHoldNotes'),
357 failed_holds => scalar $query->param('failed_holds'),
360 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };