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 with
16 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
17 # Suite 330, Boston, MA 02111-1307 USA
21 #use warnings; FIXME - Bug 2505
30 use C4
::Members
::AttributeTypes
;
31 use C4
::Members
::Attributes qw
/GetBorrowerAttributeValue/;
35 use C4
::Dates qw
/format_date/;
37 use C4
::Branch
; # GetBranches
39 use constant ATTRIBUTE_SHOW_BARCODE
=> 'SHOW_BCODE';
44 if (C4
::Context
->preference('BakerTaylorEnabled')) {
45 require C4
::External
::BakerTaylor
;
46 import C4
::External
::BakerTaylor
qw(&image_url &link_url);
50 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
52 template_name
=> "opac-user.tmpl",
56 flagsrequired
=> { borrow
=> 1 },
61 my $OPACDisplayRequestPriority = (C4
::Context
->preference("OPACDisplayRequestPriority")) ?
1 : 0;
62 my $patronupdate = $query->param('patronupdate');
64 # get borrower information ....
65 my ( $borr ) = GetMemberDetails
( $borrowernumber );
67 for (qw(dateenrolled dateexpiry dateofbirth)) {
68 ($borr->{$_}) and $borr->{$_} = format_date
($borr->{$_});
70 $borr->{'ethnicity'} = fixEthnicity
( $borr->{'ethnicity'} );
72 if ( $borr->{'debarred'} || $borr->{'gonenoaddress'} || $borr->{'lost'} ) {
73 $borr->{'flagged'} = 1;
76 if ( $borr->{'amountoutstanding'} > 5 ) {
77 $borr->{'amountoverfive'} = 1;
79 if ( 5 >= $borr->{'amountoutstanding'} && $borr->{'amountoutstanding'} > 0 ) {
80 $borr->{'amountoverzero'} = 1;
83 if ( $borr->{'amountoutstanding'} > C4
::Context
->preference( 'OPACFineNoRenewals' ) ) {
84 $borr->{'flagged'} = 1;
86 renewal_blocked_fines
=> sprintf( "%.02f", C4
::Context
->preference( 'OPACFineNoRenewals' ) ),
90 if ( $borr->{'amountoutstanding'} < 0 ) {
91 $borr->{'amountlessthanzero'} = 1;
92 $borr->{'amountoutstanding'} = -1 * ( $borr->{'amountoutstanding'} );
95 $borr->{'amountoutstanding'} = sprintf "%.02f", $borr->{'amountoutstanding'};
100 $template->param( BORROWER_INFO
=> \
@bordat,
101 borrowernumber
=> $borrowernumber,
102 patron_flagged
=> $borr->{flagged
},
103 OPACMySummaryHTML
=> (C4
::Context
->preference("OPACMySummaryHTML")) ?
1 : 0,
106 #get issued items ....
110 my $overdues_count = 0;
113 my $itemtypes = GetItemTypes
();
114 my ($issues) = GetPendingIssues
($borrowernumber);
116 foreach my $issue ( sort { $b->{'date_due'} cmp $a->{'date_due'} } @
$issues ) {
118 my ( $restype, $res ) = CheckReserves
( $issue->{'itemnumber'} );
120 $issue->{'reserved'} = 1;
123 my ( $total , $accts, $numaccts) = GetMemberAccountRecords
( $borrowernumber );
125 foreach my $ac (@
$accts) {
126 if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
127 $charges += $ac->{'amountoutstanding'}
128 if $ac->{'accounttype'} eq 'F';
129 $charges += $ac->{'amountoutstanding'}
130 if $ac->{'accounttype'} eq 'L';
133 $issue->{'charges'} = $charges;
135 # get publictype for icon
137 my $publictype = $issue->{'publictype'};
138 $issue->{$publictype} = 1;
140 # check if item is renewable
141 my ($status,$renewerror) = CanBookBeRenewed
( $borrowernumber, $issue->{'itemnumber'} );
142 ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount
($borrowernumber, $issue->{'itemnumber'});
143 $issue->{'status'} = $status && C4
::Context
->preference("OpacRenewalAllowed");
144 $issue->{'too_many'} = 1 if $renewerror and $renewerror eq 'too_many';
145 $issue->{'on_reserve'} = 1 if $renewerror and $renewerror eq 'on_reserve';
147 if ( $issue->{'overdue'} ) {
148 push @overdues, $issue;
150 $issue->{'overdue'} = 1;
153 $issue->{'issued'} = 1;
156 my $itemtype = $issue->{'itemtype'};
158 $issue->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
159 $issue->{'description'} = $itemtypes->{$itemtype}->{'description'};
161 $issue->{date_due
} = format_date
($issue->{date_due
});
162 push @issuedat, $issue;
165 my $isbn = GetNormalizedISBN
($issue->{'isbn'});
166 $issue->{normalized_isbn
} = $isbn;
169 if (my $my_summary_html = C4
::Context
->preference('OPACMySummaryHTML')){
170 $issue->{author
} ?
$my_summary_html =~ s/{AUTHOR}/$issue->{author}/g : $my_summary_html =~ s/{AUTHOR}//g;
171 $issue->{title
} =~ s/\/+$//; # remove trailing slash
172 $issue->{title
} =~ s/\s+$//; # remove trailing space
173 $issue->{title
} ?
$my_summary_html =~ s/{TITLE}/$issue->{title}/g : $my_summary_html =~ s/{TITLE}//g;
174 $issue->{isbn
} ?
$my_summary_html =~ s/{ISBN}/$isbn/g : $my_summary_html =~ s/{ISBN}//g;
175 $issue->{biblionumber
} ?
$my_summary_html =~ s/{BIBLIONUMBER}/$issue->{biblionumber}/g : $my_summary_html =~ s/{BIBLIONUMBER}//g;
176 $issue->{MySummaryHTML
} = $my_summary_html;
180 $template->param( ISSUES
=> \
@issuedat );
181 $template->param( issues_count
=> $count );
183 $template->param( OVERDUES
=> \
@overdues );
184 $template->param( overdues_count
=> $overdues_count );
186 my $show_barcode = C4
::Members
::AttributeTypes
::AttributeTypeExists
( ATTRIBUTE_SHOW_BARCODE
);
188 my $patron_show_barcode = GetBorrowerAttributeValue
($borrowernumber, ATTRIBUTE_SHOW_BARCODE
);
189 undef $show_barcode if defined($patron_show_barcode) && !$patron_show_barcode;
191 $template->param( show_barcode
=> 1 ) if $show_barcode;
194 my $branches = GetBranches
();
196 for my $branch_hash (sort keys %$branches ) {
197 my $selected=(C4
::Context
->userenv && ($branch_hash eq C4
::Context
->userenv->{branch
})) if (C4
::Context
->preference('SearchMyLibraryFirst'));
200 value
=> "branch: $branch_hash",
201 branchname
=> $branches->{$branch_hash}->{'branchname'},
202 selected
=> $selected
205 $template->param( branchloop
=> \
@branch_loop );
207 # now the reserved items....
208 my @reserves = GetReservesFromBorrowernumber
( $borrowernumber );
209 foreach my $res (@reserves) {
210 $res->{'reservedate'} = format_date
( $res->{'reservedate'} );
212 if ( $res->{'expirationdate'} ne '0000-00-00' ) {
213 $res->{'expirationdate'} = format_date
( $res->{'expirationdate'} )
215 $res->{'expirationdate'} = '';
218 my $publictype = $res->{'publictype'};
219 $res->{$publictype} = 1;
220 $res->{'waiting'} = 1 if $res->{'found'} eq 'W';
221 $res->{'formattedwaitingdate'} = format_date
($res->{'waitingdate'});
222 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
223 my $biblioData = GetBiblioData
($res->{'biblionumber'});
224 $res->{'reserves_title'} = $biblioData->{'title'};
225 if ($OPACDisplayRequestPriority) {
226 $res->{'priority'} = '' if $res->{'priority'} eq '0';
231 # warn Dumper(@reserves);
233 $template->param( RESERVES
=> \
@reserves );
234 $template->param( reserves_count
=> $#reserves+1 );
235 $template->param( showpriority
=>1 ) if $OPACDisplayRequestPriority;
239 foreach my $res (@reserves) {
240 if ( $res->{'itemnumber'} ) {
241 my $item = GetItem
( $res->{'itemnumber'});
242 $res->{'holdingbranch'} =
243 $branches->{ $item->{'holdingbranch'} }->{'branchname'};
244 $res->{'branch'} = $branches->{ $res->{'branchcode'} }->{'branchname'};
245 # get document reserve status
246 my $biblioData = GetBiblioData
($res->{'biblionumber'});
247 $res->{'waiting_title'} = $biblioData->{'title'};
248 if ( ( $res->{'found'} eq 'W' ) ) {
249 my $item = $res->{'itemnumber'};
250 $item = GetBiblioFromItemNumber
($item,undef);
252 $res->{'holdingbranch'}=$item->{'holdingbranch'};
253 $res->{'biblionumber'}=$item->{'biblionumber'};
254 $res->{'barcode'} = $item->{'barcode'};
255 $res->{'wbrcode'} = $res->{'branchcode'};
256 $res->{'itemnumber'} = $res->{'itemnumber'};
257 $res->{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
258 if($res->{'holdingbranch'} eq $res->{'wbrcode'}){
259 $res->{'atdestination'} = 1;
261 # set found to 1 if reserve is waiting for patron pickup
262 $res->{'found'} = 1 if $res->{'found'} eq 'W';
264 my ($transfertwhen, $transfertfrom, $transfertto) = GetTransfers
( $res->{'itemnumber'} );
265 if ($transfertwhen) {
266 $res->{intransit
} = 1;
267 $res->{datesent
} = format_date
($transfertwhen);
268 $res->{frombranch
} = GetBranchName
($transfertfrom);
275 #$res->{'cancelable'} = 1 if ($res->{'wait'} && $res->{'atdestination'} && $res->{'found'} ne "1");
276 $res->{'cancelable'} = 1 if ($res->{wait} and not $res->{found
}) or (not $res->{wait} and not $res->{intransit
});
280 $template->param( WAITING
=> \
@waiting );
282 # current alert subscriptions
283 my $alerts = getalert
($borrowernumber);
284 foreach ( @
$alerts ) {
285 $_->{ $_->{type
} } = 1;
286 $_->{relatedto
} = findrelatedto
( $_->{type
}, $_->{externalid
} );
289 if (C4
::Context
->preference('BakerTaylorEnabled')) {
291 BakerTaylorEnabled
=> 1,
292 BakerTaylorImageURL
=> &image_url
(),
293 BakerTaylorLinkURL
=> &link_url
(),
294 BakerTaylorBookstoreURL
=> C4
::Context
->preference('BakerTaylorBookstoreURL'),
298 if (C4
::Context
->preference("OPACAmazonCoverImages") or
299 C4
::Context
->preference("GoogleJackets") or
300 C4
::Context
->preference("BakerTaylorEnabled") or
301 C4
::Context
->preference("SyndeticsCoverImages")) {
302 $template->param(JacketImages
=>1);
305 if ( GetMessagesCount
( $borrowernumber, 'B' ) ) {
306 $template->param( bor_messages
=> 1 );
309 if ( $borr->{'opacnote'} ) {
312 opacnote
=> $borr->{'opacnote'},
317 bor_messages_loop
=> GetMessages
( $borrowernumber, 'B', 'NONE' ),
318 waiting_count
=> $wcount,
319 textmessaging
=> $borr->{textmessaging
},
320 patronupdate
=> $patronupdate,
321 OpacRenewalAllowed
=> C4
::Context
->preference("OpacRenewalAllowed"),
323 dateformat
=> C4
::Context
->preference("dateformat"),
326 output_html_with_http_headers
$query, $cookie, $template->output;