3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
31 use C4::Dates qw/format_date/;
33 use C4::Branch; # GetBranches
38 if (C4::Context->preference('BakerTaylorEnabled')) {
39 require C4::External::BakerTaylor;
40 import C4::External::BakerTaylor qw(&image_url &link_url);
44 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
46 template_name => "opac-user.tmpl",
50 flagsrequired => { borrow => 1 },
55 my $OPACDisplayRequestPriority = (C4::Context->preference("OPACDisplayRequestPriority")) ? 1 : 0;
56 my $patronupdate = $query->param('patronupdate');
58 # get borrower information ....
59 my ( $borr ) = GetMemberDetails( $borrowernumber );
61 $borr->{'dateenrolled'} = format_date( $borr->{'dateenrolled'} );
62 $borr->{'expiry'} = format_date( $borr->{'expiry'} );
63 $borr->{'dateofbirth'} = format_date( $borr->{'dateofbirth'} );
64 $borr->{'ethnicity'} = fixEthnicity( $borr->{'ethnicity'} );
66 if ( $borr->{'debarred'} || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
67 $borr->{'flagged'} = 1;
69 # $make flagged available everywhere in the template
70 my $patron_flagged = $borr->{'flagged'};
71 if ( $borr->{'amountoutstanding'} > 5 ) {
72 $borr->{'amountoverfive'} = 1;
74 if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
75 $borr->{'amountoverzero'} = 1;
77 if ( $borr->{'amountoutstanding'} < 0 ) {
78 $borr->{'amountlessthanzero'} = 1;
79 $borr->{'amountoutstanding'} = -1 * ( $borr->{'amountoutstanding'} );
82 $borr->{'amountoutstanding'} = sprintf "%.02f", $borr->{'amountoutstanding'};
87 $template->param( BORROWER_INFO => \@bordat,
88 borrowernumber => $borrowernumber,
89 patron_flagged => $patron_flagged,
92 #get issued items ....
93 my ($issues) = GetPendingIssues($borrowernumber);
94 my @issue_list = sort { $b->{'date_due'} cmp $a->{'date_due'} } @$issues;
98 my $overdues_count = 0;
101 my $itemtypes = GetItemTypes();
102 foreach my $issue ( @issue_list ) {
103 if($count%2 eq 0){ $issue->{'toggle'} = 1; } else { $issue->{'toggle'} = 0; }
105 my ( $restype, $res ) = CheckReserves( $issue->{'itemnumber'} );
107 $issue->{'reserved'} = 1;
110 my ( $total , $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
112 foreach my $ac (@$accts) {
113 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
114 $charges += $ac->{'amountoutstanding'}
115 if $ac->{'accounttype'} eq 'F';
116 $charges += $ac->{'amountoutstanding'}
117 if $ac->{'accounttype'} eq 'L';
120 $issue->{'charges'} = $charges;
122 # get publictype for icon
124 my $publictype = $issue->{'publictype'};
125 $issue->{$publictype} = 1;
127 # check if item is renewable
128 my ($status,$renewerror) = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} );
129 ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount($borrowernumber, $issue->{'itemnumber'});
131 $issue->{'status'} = $status || C4::Context->preference("OpacRenewalAllowed");
133 if ( $issue->{'overdue'} ) {
134 push @overdues, $issue;
136 $issue->{'overdue'} = 1;
139 $issue->{'issued'} = 1;
142 my $itemtype = $issue->{'itemtype'};
144 $issue->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
145 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
147 $issue->{date_due} = format_date($issue->{date_due});
148 push @issuedat, $issue;
152 my $xisbn=$issue->{'isbn'};
153 $xisbn =~ /(\d*[X]*)/;
154 $issue->{amazonisbn} = $1; # FIXME: so it is OK if the ISBN = 'XXXXX' ?
155 my ($clean, $amazonisbn);
157 # these might be overkill, but they are better than the regexp above.
159 $amazonisbn =~ /\b(\d{13})\b/ or
160 $amazonisbn =~ /\b(\d{10})\b/ or
161 $amazonisbn =~ /\b(\d{9}X)\b/i
164 $issue->{clean_isbn} = $1;
169 $template->param( ISSUES => \@issuedat );
170 $template->param( issues_count => $count );
172 $template->param( OVERDUES => \@overdues );
173 $template->param( overdues_count => $overdues_count );
176 my $branches = GetBranches();
178 for my $branch_hash (sort keys %$branches ) {
179 my $selected=(C4::Context->userenv && ($branch_hash eq C4::Context->userenv->{branch})) if (C4::Context->preference('SearchMyLibraryFirst'));
182 value => "branch: $branch_hash",
183 branchname => $branches->{$branch_hash}->{'branchname'},
184 selected => $selected
187 $template->param( branchloop => \@branch_loop, "mylibraryfirst"=>C4::Context->preference("SearchMyLibraryFirst"));
189 # now the reserved items....
190 my @reserves = GetReservesFromBorrowernumber( $borrowernumber );
191 foreach my $res (@reserves) {
192 $res->{'reservedate'} = format_date( $res->{'reservedate'} );
193 my $publictype = $res->{'publictype'};
194 $res->{$publictype} = 1;
195 $res->{'waiting'} = 1 if $res->{'found'} eq 'W';
196 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
197 my $biblioData = GetBiblioData($res->{'biblionumber'});
198 $res->{'reserves_title'} = $biblioData->{'title'};
199 if ($OPACDisplayRequestPriority) {
200 $res->{'priority'} = '' if $res->{'priority'} eq '0';
205 # warn Dumper(@reserves);
207 $template->param( RESERVES => \@reserves );
208 $template->param( reserves_count => $#reserves+1 );
209 $template->param( showpriority=>1 ) if $OPACDisplayRequestPriority;
213 foreach my $res (@reserves) {
214 if ( $res->{'itemnumber'} ) {
215 my $item = GetItem( $res->{'itemnumber'});
216 $res->{'holdingbranch'} =
217 $branches->{ $item->{'holdingbranch'} }->{'branchname'};
218 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
219 # get document reserve status
220 my $biblioData = GetBiblioData($res->{'biblionumber'});
221 $res->{'waiting_title'} = $biblioData->{'title'};
222 if ( ( $res->{'found'} eq 'W' ) ) {
223 my $item = $res->{'itemnumber'};
224 $item = GetBiblioFromItemNumber($item,undef);
226 $res->{'holdingbranch'}=$item->{'holdingbranch'};
227 $res->{'biblionumber'}=$item->{'biblionumber'};
228 $res->{'barcodenumber'} = $item->{'barcode'};
229 $res->{'wbrcode'} = $res->{'branchcode'};
230 $res->{'itemnumber'} = $res->{'itemnumber'};
231 $res->{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
232 if($res->{'holdingbranch'} eq $res->{'wbrcode'}){
233 $res->{'atdestination'} = 1;
235 # set found to 1 if reserve is waiting for patron pickup
236 $res->{'found'} = 1 if $res->{'found'} eq 'W';
238 my ($transfertwhen, $transfertfrom, $transfertto) = GetTransfers( $res->{'itemnumber'} );
239 if ($transfertwhen) {
240 $res->{intransit} = 1;
241 $res->{datesent} = format_date($transfertwhen);
242 $res->{frombranch} = GetBranchName($transfertfrom);
250 $template->param( WAITING => \@waiting );
252 # current alert subscriptions
253 my $alerts = getalert($borrowernumber);
254 foreach ( @$alerts ) {
255 $_->{ $_->{type} } = 1;
256 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
259 if (C4::Context->preference('BakerTaylorEnabled')) {
261 BakerTaylorEnabled => 1,
262 BakerTaylorImageURL => &image_url(),
263 BakerTaylorLinkURL => &link_url(),
264 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
268 if (C4::Context->preference("AmazonContent" ) or
269 C4::Context->preference("GoogleJackets" ) or
270 C4::Context->preference("BakerTaylorEnabled") ) {
271 $template->param(JacketImages=>1);
275 waiting_count => $wcount,
276 textmessaging => $borr->{textmessaging},
277 patronupdate => $patronupdate,
278 OpacRenewalAllowed => C4::Context->preference("OpacRenewalAllowed"),
280 dateformat => C4::Context->preference("dateformat"),
283 output_html_with_http_headers $query, $cookie, $template->output;