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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 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
40 use C4::Members::Attributes;
41 use C4::Members::AttributeTypes;
49 use C4::Branch; # GetBranchName
57 $debug = $ENV{DEBUG} || 0;
60 my $dbh = C4::Context->dbh;
63 $debug or $debug = $input->param('debug') || 0;
64 my $print = $input->param('print');
65 my @failedrenews = $input->param('failedrenew');
66 my @failedreturns = $input->param('failedreturn');
67 my $error = $input->param('error');
69 for my $renew (@failedrenews) { $renew_failed{$renew} = 1; }
71 for my $failedret (@failedreturns) { $return_failed{$failedret} = 1; }
75 if ($print eq "page") { $template_name = "members/moremember-print.tmpl"; }
76 elsif ($print eq "slip") { $template_name = "members/moremember-receipt.tmpl"; }
77 else { $template_name = "members/moremember.tmpl"; }
79 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
81 template_name => $template_name,
85 flagsrequired => { borrowers => 1 },
89 my $borrowernumber = $input->param('borrowernumber');
91 #start the page and read in includes
92 my $data = GetMember( $borrowernumber ,'borrowernumber');
93 my $reregistration = $input->param('reregistration');
95 if ( not defined $data ) {
96 $template->param (unknowuser => 1);
97 output_html_with_http_headers $input, $cookie, $template->output;
101 # re-reregistration function to automatic calcul of date expiry
102 if ( $reregistration eq 'y' ) {
103 $data->{'dateexpiry'} = ExtendMemberSubscriptionTo( $borrowernumber );
106 my $category_type = $data->{'category_type'};
110 # in template <TMPL_IF name="I"> => instutitional (A for Adult& C for children)
111 $template->param( $data->{'categorycode'} => 1 );
113 $debug and printf STDERR "dates (enrolled,expiry,birthdate) raw: (%s, %s, %s)\n", map {$data->{$_}} qw(dateenrolled dateexpiry dateofbirth);
114 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
115 my $userdate = $data->{$_};
117 $debug and warn sprintf "Empty \$data{%12s}", $_;
121 $userdate = C4::Dates->new($userdate,'iso')->output('syspref');
122 $data->{$_} = $userdate || '';
123 $template->param( $_ => $userdate );
125 $data->{'IS_ADULT'} = ( $data->{'categorycode'} ne 'I' );
127 for (qw(debarred gonenoaddress lost borrowernotes)) {
128 $data->{$_} and $template->param(flagged => 1) and last;
131 $data->{'ethnicity'} = fixEthnicity( $data->{'ethnicity'} );
132 $data->{ "sex_".$data->{'sex'}."_p" } = 1;
135 if ( $category_type eq 'C') {
136 if ($data->{'guarantorid'} ne '0' ) {
137 my $data2 = GetMember( $data->{'guarantorid'} ,'borrowernumber');
138 foreach (qw(address city B_address B_city phone mobile zipcode)) {
139 $data->{$_} = $data2->{$_};
142 my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
143 my $cnt = scalar(@$catcodes);
145 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
146 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
150 if ( $data->{'ethnicity'} || $data->{'ethnotes'} ) {
151 $template->param( printethnicityline => 1 );
153 if ( $category_type eq 'A' ) {
154 $template->param( isguarantee => 1 );
157 # It looks like the $i is only being returned to handle walking through
158 # the array, which is probably better done as a foreach loop.
160 my ( $count, $guarantees ) = GetGuarantees( $data->{'borrowernumber'} );
162 for ( my $i = 0 ; $i < $count ; $i++ ) {
165 borrowernumber => $guarantees->[$i]->{'borrowernumber'},
166 cardnumber => $guarantees->[$i]->{'cardnumber'},
167 name => $guarantees->[$i]->{'firstname'} . " "
168 . $guarantees->[$i]->{'surname'}
172 $template->param( guaranteeloop => \@guaranteedata );
173 ( $template->param( adultborrower => 1 ) ) if ( $category_type eq 'A' );
176 if ($data->{'guarantorid'}){
177 my ($guarantor) = GetMember( $data->{'guarantorid'},'biblionumber');
178 $template->param(guarantor => 1);
179 foreach (qw(borrowernumber cardnumber firstname surname)) {
180 $template->param("guarantor$_" => $guarantor->{$_});
183 if ($category_type eq 'C'){
184 $template->param('C' => 1);
188 #Independant branches management
189 my $unvalidlibrarian =
190 ( ( C4::Context->preference("IndependantBranches") )
191 && ( C4::Context->userenv->{flags} != 1 )
192 && ( $data->{'branchcode'} ne C4::Context->userenv->{branch} ) );
195 $bor{'borrowernumber'} = $borrowernumber;
197 # Converts the branchcode to the branch name
199 if ( C4::Context->preference("IndependantBranches") ) {
200 my $userenv = C4::Context->userenv;
201 unless ( $userenv->{flags} == 1 ) {
202 $samebranch = ( $data->{'branchcode'} eq $userenv->{branch} );
204 $samebranch = 1 if ( $userenv->{flags} == 1 );
206 my $branchdetail = GetBranchDetail( $data->{'branchcode'});
207 $data->{'branchname'} = $branchdetail->{branchname};
210 my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
211 my $lib1 = &GetSortDetails( "Bsort1", $data->{'sort1'} );
212 my $lib2 = &GetSortDetails( "Bsort2", $data->{'sort2'} );
213 ( $template->param( lib1 => $lib1 ) ) if ($lib1);
214 ( $template->param( lib2 => $lib2 ) ) if ($lib2);
218 my ( $count, $issue ) = GetPendingIssues($borrowernumber);
219 my $roaddetails = &GetRoadTypeDetails( $data->{'streettype'} );
220 my $today = POSIX::strftime("%Y-%m-%d", localtime); # iso format
222 my $overdues_exist = 0;
225 for ( my $i = 0 ; $i < $count ; $i++ ) {
226 my $datedue = $issue->[$i]{'date_due'};
227 $issue->[$i]{'date_due'} = C4::Dates->new($issue->[$i]{'date_due'},'iso')->output('syspref');
228 $issue->[$i]{'issuedate'} = C4::Dates->new($issue->[$i]{'issuedate'},'iso')->output('syspref');
229 my %row = %{ $issue->[$i] };
230 $totalprice += $issue->[$i]{'replacementprice'};
231 $row{'replacementprice'} = $issue->[$i]{'replacementprice'};
232 if ( $datedue lt $today ) {
234 $row{'red'} = 1; #print "<font color=red>";
236 $row{toggle} = $toggle++ % 2;
238 #find the charge for an item
239 my ( $charge, $itemtype ) =
240 GetIssuingCharges( $issue->[$i]{'itemnumber'}, $borrowernumber );
242 my $itemtypeinfo = getitemtypeinfo($itemtype);
243 $row{'itemtype_description'} = $itemtypeinfo->{description};
244 $row{'itemtype_image'} = $itemtypeinfo->{imageurl};
246 $row{'charge'} = sprintf( "%.2f", $charge );
248 my ( $renewokay,$renewerror ) = CanBookBeRenewed( $borrowernumber, $issue->[$i]{'itemnumber'});
249 $row{'norenew'} = !$renewokay;
250 $row{"norenew_reason_$renewerror"} = 1 if $renewerror;
251 $row{'renew_failed'} = $renew_failed{ $issue->[$i]{'itemnumber'} };
252 $row{'return_failed'} = $return_failed{$issue->[$i]{'barcode'}};
253 push( @issuedata, \%row );
256 ### ###############################################################################
258 # show all reserves of this borrower, and the position of the reservation ....
259 if ($borrowernumber) {
262 # now we show the status of the borrower's reservations
263 my @borrowerreserv = GetReservesFromBorrowernumber($borrowernumber );
265 foreach my $num_res (@borrowerreserv) {
267 my $getiteminfo = GetBiblioFromItemNumber( $num_res->{'itemnumber'} );
268 my $itemtypeinfo = getitemtypeinfo( $getiteminfo->{'itemtype'} );
269 my ( $transfertwhen, $transfertfrom, $transfertto ) =
270 GetTransfers( $num_res->{'itemnumber'} );
272 foreach (qw(waiting transfered nottransfered)) {
275 $getreserv{reservedate} = C4::Dates->new($num_res->{'reservedate'},'iso')->output('syspref');
276 foreach (qw(biblionumber title author itemcallnumber )) {
277 $getreserv{$_} = $getiteminfo->{$_};
279 $getreserv{barcodereserv} = $getiteminfo->{'barcode'};
280 $getreserv{itemtype} = $itemtypeinfo->{'description'};
282 # check if we have a waitin status for reservations
283 if ( $num_res->{'found'} eq 'W' ) {
284 $getreserv{color} = 'reserved';
285 $getreserv{waiting} = 1;
288 # check transfers with the itemnumber foud in th reservation loop
289 if ($transfertwhen) {
290 $getreserv{color} = 'transfered';
291 $getreserv{transfered} = 1;
292 $getreserv{datesent} = C4::Dates->new($transfertwhen, 'iso')->output('syspref') or die "Cannot get new($transfertwhen, 'iso') from C4::Dates";
293 $getreserv{frombranch} = GetBranchName($transfertfrom);
296 if ( ( $getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} )
297 and not $transfertwhen )
299 $getreserv{nottransfered} = 1;
300 $getreserv{nottransferedby} =
301 GetBranchName( $getiteminfo->{'holdingbranch'} );
304 # if we don't have a reserv on item, we put the biblio infos and the waiting position
305 if ( $getiteminfo->{'title'} eq '' ) {
306 my $getbibinfo = GetBiblioData( $num_res->{'biblionumber'} );
307 my $getbibtype = getitemtypeinfo( $getbibinfo->{'itemtype'} );
308 $getreserv{color} = 'inwait';
309 $getreserv{title} = $getbibinfo->{'title'};
310 $getreserv{nottransfered} = 0;
311 $getreserv{itemtype} = $getbibtype->{'description'};
312 $getreserv{author} = $getbibinfo->{'author'};
313 $getreserv{biblionumber} = $num_res->{'biblionumber'};
315 $getreserv{waitingposition} = $num_res->{'priority'};
317 push( @reservloop, \%getreserv );
320 # return result to the template
321 $template->param( reservloop => \@reservloop );
324 # current alert subscriptions
325 my $alerts = getalert($borrowernumber);
327 $_->{ $_->{type} } = 1;
328 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
331 # check to see if patron's image exists in the database
332 # basically this gives us a template var to condition the display of
333 # patronimage related interface on
334 my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
335 $template->param( picture => 1 ) if $picture;
337 my $branch=C4::Context->userenv->{'branch'};
339 $template->param($data);
341 if (C4::Context->preference('ExtendedPatronAttributes')) {
342 $template->param(ExtendedPatronAttributes => 1);
343 $template->param(patron_attributes => C4::Members::Attributes::GetBorrowerAttributes($borrowernumber));
344 my @types = C4::Members::AttributeTypes::GetAttributeTypes();
345 if (scalar(@types) == 0) {
346 $template->param(no_patron_attribute_types => 1);
352 DHTMLcalendar_dateformat=>C4::Dates->DHTMLcalendar(),
353 roaddetails => $roaddetails,
354 borrowernumber => $borrowernumber,
355 categoryname => $data->{'description'},
356 reregistration => $reregistration,
358 totalprice => sprintf( "%.2f", $totalprice ),
359 totaldue => sprintf( "%.2f", $total ),
360 issueloop => \@issuedata,
361 overdues_exist => $overdues_exist,
362 unvalidlibrarian => $unvalidlibrarian,
365 StaffMember => ($category_type eq 'S'),
366 is_child => ($category_type eq 'C'),
367 # reserveloop => \@reservedata,
368 dateformat => C4::Context->preference("dateformat"),
371 output_html_with_http_headers $input, $cookie, $template->output;