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 $patronupdate = $query->param('patronupdate');
57 # get borrower information ....
58 my ( $borr ) = GetMemberDetails( $borrowernumber );
60 $borr->{'dateenrolled'} = format_date( $borr->{'dateenrolled'} );
61 $borr->{'expiry'} = format_date( $borr->{'expiry'} );
62 $borr->{'dateofbirth'} = format_date( $borr->{'dateofbirth'} );
63 $borr->{'ethnicity'} = fixEthnicity( $borr->{'ethnicity'} );
65 if ( $borr->{'debarred'} || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
66 $borr->{'flagged'} = 1;
68 # $make flagged available everywhere in the template
69 my $patron_flagged = $borr->{'flagged'};
70 if ( $borr->{'amountoutstanding'} > 5 ) {
71 $borr->{'amountoverfive'} = 1;
73 if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
74 $borr->{'amountoverzero'} = 1;
76 if ( $borr->{'amountoutstanding'} < 0 ) {
77 $borr->{'amountlessthanzero'} = 1;
78 $borr->{'amountoutstanding'} = -1 * ( $borr->{'amountoutstanding'} );
81 $borr->{'amountoutstanding'} = sprintf "%.02f", $borr->{'amountoutstanding'};
86 $template->param( BORROWER_INFO => \@bordat,
87 borrowernumber => $borrowernumber,
88 patron_flagged => $patron_flagged,
91 #get issued items ....
92 my ($countissues,$issues) = GetPendingIssues($borrowernumber);
93 my @issue_list = sort { $b->{'date_due'} cmp $a->{'date_due'} } @$issues;
97 my $overdues_count = 0;
100 my $itemtypes = GetItemTypes();
101 foreach my $issue ( @issue_list ) {
102 if($count%2 eq 0){ $issue->{'toggle'} = 1; } else { $issue->{'toggle'} = 0; }
104 my ( $restype, $res ) = CheckReserves( $issue->{'itemnumber'} );
106 $issue->{'reserved'} = 1;
109 my ( $total , $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
111 foreach my $ac (@$accts) {
112 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
113 $charges += $ac->{'amountoutstanding'}
114 if $ac->{'accounttype'} eq 'F';
115 $charges += $ac->{'amountoutstanding'}
116 if $ac->{'accounttype'} eq 'L';
119 $issue->{'charges'} = $charges;
121 # get publictype for icon
123 my $publictype = $issue->{'publictype'};
124 $issue->{$publictype} = 1;
126 # check if item is renewable
127 my ($status,$renewerror) = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} );
128 ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount($borrowernumber, $issue->{'itemnumber'});
130 $issue->{'status'} = $status;
132 if ( $issue->{'overdue'} ) {
133 push @overdues, $issue;
135 $issue->{'overdue'} = 1;
138 $issue->{'issued'} = 1;
141 my $itemtype = $issue->{'itemtype'};
143 $issue->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
144 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
146 $issue->{date_due} = format_date($issue->{date_due});
147 push @issuedat, $issue;
151 my $xisbn=$issue->{'isbn'};
152 $xisbn =~ /(\d*[X]*)/;
153 $issue->{amazonisbn} = $1; # FIXME: so it is OK if the ISBN = 'XXXXX' ?
154 my ($clean, $amazonisbn);
156 # these might be overkill, but they are better than the regexp above.
158 $amazonisbn =~ /\b(\d{13})\b/ or
159 $amazonisbn =~ /\b(\d{10})\b/ or
160 $amazonisbn =~ /\b(\d{9}X)\b/i
163 $issue->{clean_isbn} = $1;
168 $template->param( ISSUES => \@issuedat );
169 $template->param( issues_count => $count );
171 $template->param( OVERDUES => \@overdues );
172 $template->param( overdues_count => $overdues_count );
175 my $branches = GetBranches();
177 for my $branch_hash (sort keys %$branches ) {
178 my $selected=(C4::Context->userenv && ($branch_hash eq C4::Context->userenv->{branch})) if (C4::Context->preference('SearchMyLibraryFirst'));
181 value => "branch: $branch_hash",
182 branchname => $branches->{$branch_hash}->{'branchname'},
183 selected => $selected
186 $template->param( branchloop => \@branch_loop, "mylibraryfirst"=>C4::Context->preference("SearchMyLibraryFirst"));
188 # now the reserved items....
189 my @reserves = GetReservesFromBorrowernumber( $borrowernumber );
190 foreach my $res (@reserves) {
191 $res->{'reservedate'} = format_date( $res->{'reservedate'} );
192 my $publictype = $res->{'publictype'};
193 $res->{$publictype} = 1;
194 $res->{'waiting'} = 1 if $res->{'found'} eq 'W';
195 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
196 my $biblioData = GetBiblioData($res->{'biblionumber'});
197 $res->{'reserves_title'} = $biblioData->{'title'};
201 # warn Dumper(@reserves);
203 $template->param( RESERVES => \@reserves );
204 $template->param( reserves_count => $#reserves+1 );
208 foreach my $res (@reserves) {
209 if ( $res->{'itemnumber'} ) {
210 my $item = GetItem( $res->{'itemnumber'});
211 $res->{'holdingbranch'} =
212 $branches->{ $item->{'holdingbranch'} }->{'branchname'};
213 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
214 # get document reserve status
215 my $biblioData = GetBiblioData($res->{'biblionumber'});
216 $res->{'waiting_title'} = $biblioData->{'title'};
217 if ( ( $res->{'found'} eq 'W' ) ) {
218 my $item = $res->{'itemnumber'};
219 $item = GetBiblioFromItemNumber($item,undef);
221 $res->{'holdingbranch'}=$item->{'holdingbranch'};
222 $res->{'biblionumber'}=$item->{'biblionumber'};
223 $res->{'barcodenumber'} = $item->{'barcode'};
224 $res->{'wbrcode'} = $res->{'branchcode'};
225 $res->{'itemnumber'} = $res->{'itemnumber'};
226 $res->{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
227 if($res->{'holdingbranch'} eq $res->{'wbrcode'}){
228 $res->{'atdestination'} = 1;
230 # set found to 1 if reserve is waiting for patron pickup
231 $res->{'found'} = 1 if $res->{'found'} eq 'W';
233 my ($transfertwhen, $transfertfrom, $transfertto) = GetTransfers( $res->{'itemnumber'} );
234 if ($transfertwhen) {
235 $res->{intransit} = 1;
236 $res->{datesent} = format_date($transfertwhen);
237 $res->{frombranch} = GetBranchName($transfertfrom);
245 $template->param( WAITING => \@waiting );
247 # current alert subscriptions
248 my $alerts = getalert($borrowernumber);
249 foreach ( @$alerts ) {
250 $_->{ $_->{type} } = 1;
251 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
254 if (C4::Context->preference('BakerTaylorEnabled')) {
256 BakerTaylorEnabled => 1,
257 BakerTaylorImageURL => &image_url(),
258 BakerTaylorLinkURL => &link_url(),
259 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
263 if (C4::Context->preference("AmazonContent" ) or
264 C4::Context->preference("GoogleJackets" ) or
265 C4::Context->preference("BakerTaylorEnabled") ) {
266 $template->param(JacketImages=>1);
270 waiting_count => $wcount,
271 textmessaging => $borr->{textmessaging},
272 patronupdate => $patronupdate,
273 OpacRenewalAllowed => C4::Context->preference("OpacRenewalAllowed"),
275 dateformat => C4::Context->preference("dateformat"),
278 output_html_with_http_headers $query, $cookie, $template->output;