3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 script to do a borrower enquiry/bring up borrower details etc
24 Displays all the details about a borrower
25 written 20/12/99 by chris@katipo.co.nz
26 last modified 21/1/2000 by chris@katipo.co.nz
27 modified 31/1/2001 by chris@katipo.co.nz
28 to not allow items on request to be renewed
30 needs html removed and to use the C4::Output more, but its tricky
35 #use warnings; FIXME - Bug 2505
41 use C4::Members::Attributes;
42 use C4::Members::AttributeTypes;
50 use C4::Branch; # GetBranchName
51 use C4::Form::MessagingPreferences;
59 $debug = $ENV{DEBUG} || 0;
62 my $dbh = C4::Context->dbh;
65 $debug or $debug = $input->param('debug') || 0;
66 my $print = $input->param('print');
67 my $override_limit = $input->param("override_limit") || 0;
68 my @failedrenews = $input->param('failedrenew');
69 my @failedreturns = $input->param('failedreturn');
70 my $error = $input->param('error');
72 for my $renew (@failedrenews) { $renew_failed{$renew} = 1; }
74 for my $failedret (@failedreturns) { $return_failed{$failedret} = 1; }
79 if ($print eq "page") { $template_name = "members/moremember-print.tmpl"; }
80 elsif ($print eq "slip") { $template_name = "members/moremember-receipt.tmpl"; }
81 elsif ($print eq "qslip") { $template_name = "members/moremember-receipt.tmpl"; $quickslip = 1; }
82 else { $template_name = "members/moremember.tmpl"; }
84 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
86 template_name => $template_name,
90 flagsrequired => { borrowers => 1 },
94 my $borrowernumber = $input->param('borrowernumber');
96 #start the page and read in includes
97 my $data = GetMember( 'borrowernumber' => $borrowernumber );
98 my $reregistration = $input->param('reregistration');
100 if ( not defined $data ) {
101 $template->param (unknowuser => 1);
102 output_html_with_http_headers $input, $cookie, $template->output;
106 # re-reregistration function to automatic calcul of date expiry
107 if ( $reregistration eq 'y' ) {
108 $data->{'dateexpiry'} = ExtendMemberSubscriptionTo( $borrowernumber );
111 my $category_type = $data->{'category_type'};
115 # in template <TMPL_IF name="I"> => instutitional (A for Adult& C for children)
116 $template->param( $data->{'categorycode'} => 1 );
118 $debug and printf STDERR "dates (enrolled,expiry,birthdate) raw: (%s, %s, %s)\n", map {$data->{$_}} qw(dateenrolled dateexpiry dateofbirth);
119 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
120 my $userdate = $data->{$_};
122 $debug and warn sprintf "Empty \$data{%12s}", $_;
126 $userdate = C4::Dates->new($userdate,'iso')->output('syspref');
127 $data->{$_} = $userdate || '';
128 $template->param( $_ => $userdate );
130 $data->{'IS_ADULT'} = ( $data->{'categorycode'} ne 'I' );
132 for (qw(debarred gonenoaddress lost borrowernotes)) {
133 $data->{$_} and $template->param(flagged => 1) and last;
136 $data->{'ethnicity'} = fixEthnicity( $data->{'ethnicity'} );
137 $data->{ "sex_".$data->{'sex'}."_p" } = 1;
140 if ( $category_type eq 'C') {
141 if ($data->{'guarantorid'} ne '0' ) {
142 my $data2 = GetMember( 'borrowernumber' => $data->{'guarantorid'} );
143 foreach (qw(address city B_address B_city phone mobile zipcode country B_country)) {
144 $data->{$_} = $data2->{$_};
147 my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
148 my $cnt = scalar(@$catcodes);
150 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
151 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
155 if ( $data->{'ethnicity'} || $data->{'ethnotes'} ) {
156 $template->param( printethnicityline => 1 );
158 if ( $category_type eq 'A' ) {
159 $template->param( isguarantee => 1 );
162 # It looks like the $i is only being returned to handle walking through
163 # the array, which is probably better done as a foreach loop.
165 my ( $count, $guarantees ) = GetGuarantees( $data->{'borrowernumber'} );
167 for ( my $i = 0 ; $i < $count ; $i++ ) {
170 borrowernumber => $guarantees->[$i]->{'borrowernumber'},
171 cardnumber => $guarantees->[$i]->{'cardnumber'},
172 name => $guarantees->[$i]->{'firstname'} . " "
173 . $guarantees->[$i]->{'surname'}
177 $template->param( guaranteeloop => \@guaranteedata );
178 ( $template->param( adultborrower => 1 ) ) if ( $category_type eq 'A' );
181 if ($data->{'guarantorid'}){
182 my ($guarantor) = GetMember( 'borrowernumber' =>$data->{'guarantorid'});
183 $template->param(guarantor => 1);
184 foreach (qw(borrowernumber cardnumber firstname surname)) {
185 $template->param("guarantor$_" => $guarantor->{$_});
188 if ($category_type eq 'C'){
189 $template->param('C' => 1);
194 $bor{'borrowernumber'} = $borrowernumber;
196 # Converts the branchcode to the branch name
198 if ( C4::Context->preference("IndependantBranches") ) {
199 my $userenv = C4::Context->userenv;
200 unless ( $userenv->{flags} % 2 == 1 ) {
201 $samebranch = ( $data->{'branchcode'} eq $userenv->{branch} );
203 $samebranch = 1 if ( $userenv->{flags} % 2 == 1 );
207 my $branchdetail = GetBranchDetail( $data->{'branchcode'});
208 $data->{'branchname'} = $branchdetail->{branchname};
211 my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
212 my $lib1 = &GetSortDetails( "Bsort1", $data->{'sort1'} );
213 my $lib2 = &GetSortDetails( "Bsort2", $data->{'sort2'} );
214 $template->param( lib1 => $lib1 ) if ($lib1);
215 $template->param( lib2 => $lib2 ) if ($lib2);
219 my $issue = GetPendingIssues($borrowernumber);
220 my $issuecount = scalar(@$issue);
221 my $roaddetails = &GetRoadTypeDetails( $data->{'streettype'} );
222 my $today = POSIX::strftime("%Y-%m-%d", localtime); # iso format
224 my $overdues_exist = 0;
226 for ( my $i = 0 ; $i < $issuecount ; $i++ ) {
227 my $datedue = $issue->[$i]{'date_due'};
228 my $issuedate = $issue->[$i]{'issuedate'};
229 $issue->[$i]{'date_due'} = C4::Dates->new($issue->[$i]{'date_due'}, 'iso')->output('syspref');
230 $issue->[$i]{'issuedate'} = C4::Dates->new($issue->[$i]{'issuedate'},'iso')->output('syspref');
231 my $biblionumber = $issue->[$i]{'biblionumber'};
232 my %row = %{ $issue->[$i] };
233 $totalprice += $issue->[$i]{'replacementprice'};
234 $row{'replacementprice'} = $issue->[$i]{'replacementprice'};
235 # item lost, damaged loops
236 if ($row{'itemlost'}) {
237 my $fw = GetFrameworkCode($issue->[$i]{'biblionumber'});
238 my $category = GetAuthValCode('items.itemlost',$fw);
239 my $lostdbh = C4::Context->dbh;
240 my $sth = $lostdbh->prepare("select lib from authorised_values where category=? and authorised_value =? ");
241 $sth->execute($category, $row{'itemlost'});
242 my $loststat = $sth->fetchrow;
244 $row{'itemlost'} = $loststat;
247 if ($row{'damaged'}) {
248 my $fw = GetFrameworkCode($issue->[$i]{'biblionumber'});
249 my $category = GetAuthValCode('items.damaged',$fw);
250 my $damageddbh = C4::Context->dbh;
251 my $sth = $damageddbh->prepare("select lib from authorised_values where category=? and authorised_value =? ");
252 $sth->execute($category, $row{'damaged'});
253 my $damagedstat = $sth->fetchrow;
255 $row{'itemdamaged'} = $damagedstat;
259 if ( $datedue lt $today ) {
263 if ( $issuedate eq $today ) {
267 #find the charge for an item
268 my ( $charge, $itemtype ) =
269 GetIssuingCharges( $issue->[$i]{'itemnumber'}, $borrowernumber );
271 my $itemtypeinfo = getitemtypeinfo($itemtype);
272 $row{'itemtype_description'} = $itemtypeinfo->{description};
273 $row{'itemtype_image'} = $itemtypeinfo->{imageurl};
275 $row{'charge'} = sprintf( "%.2f", $charge );
277 my ( $renewokay,$renewerror ) = CanBookBeRenewed( $borrowernumber, $issue->[$i]{'itemnumber'}, $override_limit );
278 $row{'norenew'} = !$renewokay;
279 $row{'can_confirm'} = ( !$renewokay && $renewerror ne 'on_reserve' );
280 $row{"norenew_reason_$renewerror"} = 1 if $renewerror;
281 $row{'renew_failed'} = $renew_failed{ $issue->[$i]{'itemnumber'} };
282 $row{'return_failed'} = $return_failed{$issue->[$i]{'barcode'}};
283 push( @issuedata, \%row );
286 ### ###############################################################################
288 # show all reserves of this borrower, and the position of the reservation ....
289 if ($borrowernumber) {
292 # now we show the status of the borrower's reservations
293 my @borrowerreserv = GetReservesFromBorrowernumber($borrowernumber );
295 foreach my $num_res (@borrowerreserv) {
297 my $getiteminfo = GetBiblioFromItemNumber( $num_res->{'itemnumber'} );
298 my $itemtypeinfo = getitemtypeinfo( $getiteminfo->{'itemtype'} );
299 my ( $transfertwhen, $transfertfrom, $transfertto ) =
300 GetTransfers( $num_res->{'itemnumber'} );
302 foreach (qw(waiting transfered nottransfered)) {
305 $getreserv{reservedate} = C4::Dates->new($num_res->{'reservedate'},'iso')->output('syspref');
306 foreach (qw(biblionumber title author itemcallnumber )) {
307 $getreserv{$_} = $getiteminfo->{$_};
309 $getreserv{barcodereserv} = $getiteminfo->{'barcode'};
310 $getreserv{itemtype} = $itemtypeinfo->{'description'};
312 # check if we have a waitin status for reservations
313 if ( $num_res->{'found'} eq 'W' ) {
314 $getreserv{color} = 'reserved';
315 $getreserv{waiting} = 1;
318 # check transfers with the itemnumber foud in th reservation loop
319 if ($transfertwhen) {
320 $getreserv{color} = 'transfered';
321 $getreserv{transfered} = 1;
322 $getreserv{datesent} = C4::Dates->new($transfertwhen, 'iso')->output('syspref') or die "Cannot get new($transfertwhen, 'iso') from C4::Dates";
323 $getreserv{frombranch} = GetBranchName($transfertfrom);
326 if ( ( $getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} )
327 and not $transfertwhen )
329 $getreserv{nottransfered} = 1;
330 $getreserv{nottransferedby} =
331 GetBranchName( $getiteminfo->{'holdingbranch'} );
334 # if we don't have a reserv on item, we put the biblio infos and the waiting position
335 if ( $getiteminfo->{'title'} eq '' ) {
336 my $getbibinfo = GetBiblioData( $num_res->{'biblionumber'} );
337 my $getbibtype = getitemtypeinfo( $getbibinfo->{'itemtype'} );
338 $getreserv{color} = 'inwait';
339 $getreserv{title} = $getbibinfo->{'title'};
340 $getreserv{nottransfered} = 0;
341 $getreserv{itemtype} = $getbibtype->{'description'};
342 $getreserv{author} = $getbibinfo->{'author'};
343 $getreserv{biblionumber} = $num_res->{'biblionumber'};
345 $getreserv{waitingposition} = $num_res->{'priority'};
347 push( @reservloop, \%getreserv );
350 # return result to the template
351 $template->param( reservloop => \@reservloop,
352 countreserv => scalar @reservloop,
356 # current alert subscriptions
357 my $alerts = getalert($borrowernumber);
359 $_->{ $_->{type} } = 1;
360 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
364 my $userenv = C4::Context->userenv;
365 if($userenv->{flags} % 2 == 1){
367 }elsif ( C4::Context->preference("IndependantBranches") ) {
368 $candeleteuser = ( $data->{'branchcode'} eq $userenv->{branch} );
370 if( C4::Auth::getuserflags( $userenv->{flags},$userenv->{number})->{borrowers} ) {
377 # check to see if patron's image exists in the database
378 # basically this gives us a template var to condition the display of
379 # patronimage related interface on
380 my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
381 $template->param( picture => 1 ) if $picture;
383 my $branch=C4::Context->userenv->{'branch'};
385 $template->param($data);
387 if (C4::Context->preference('ExtendedPatronAttributes')) {
388 $template->param(ExtendedPatronAttributes => 1);
389 $template->param(patron_attributes => C4::Members::Attributes::GetBorrowerAttributes($borrowernumber));
390 my @types = C4::Members::AttributeTypes::GetAttributeTypes();
391 if (scalar(@types) == 0) {
392 $template->param(no_patron_attribute_types => 1);
396 if (C4::Context->preference('EnhancedMessagingPreferences')) {
397 C4::Form::MessagingPreferences::set_form_values({ borrowernumber => $borrowernumber }, $template);
398 $template->param(messaging_form_inactive => 1);
399 $template->param(SMSSendDriver => C4::Context->preference("SMSSendDriver"));
400 $template->param(SMSnumber => defined $data->{'smsalertnumber'} ? $data->{'smsalertnumber'} : $data->{'mobile'});
405 AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"),
406 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
407 CANDELETEUSER => $candeleteuser,
408 roaddetails => $roaddetails,
409 borrowernumber => $borrowernumber,
410 categoryname => $data->{'description'},
411 reregistration => $reregistration,
413 totalprice => sprintf("%.2f", $totalprice),
414 totaldue => sprintf("%.2f", $total),
415 totaldue_raw => $total,
416 issueloop => \@issuedata,
417 issuecount => $issuecount,
418 overdues_exist => $overdues_exist,
421 StaffMember => ($category_type eq 'S'),
422 is_child => ($category_type eq 'C'),
423 # reserveloop => \@reservedata,
424 dateformat => C4::Context->preference("dateformat"),
425 "dateformat_" . (C4::Context->preference("dateformat") || '') => 1,
426 samebranch => $samebranch,
427 quickslip => $quickslip,
430 output_html_with_http_headers $input, $cookie, $template->output;