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
47 use C4::Branch; # GetBranchName
52 $debug = $ENV{DEBUG} || 0;
55 my $dbh = C4::Context->dbh;
58 my $print = $input->param('print');
59 my @failedrenews = $input->param('failedrenew');
60 my $error = $input->param('error');
62 for (@failedrenews) { $renew_failed[$_] = 1; }
66 if ($print eq "page") { $template_name = "members/moremember-print.tmpl"; }
67 elsif ($print eq "slip") { $template_name = "members/moremember-receipt.tmpl"; }
68 else { $template_name = "members/moremember.tmpl"; }
70 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
72 template_name => $template_name,
76 flagsrequired => { borrowers => 1 },
80 my $borrowernumber = $input->param('borrowernumber');
82 #start the page and read in includes
83 my $data = GetMember( $borrowernumber ,'borrowernumber');
84 my $reregistration = $input->param('reregistration');
86 if ( not defined $data ) {
87 $template->param (unknowuser => 1);
91 # re-reregistration function to automatic calcul of date expiry
92 if ( $reregistration eq 'y' ) {
93 $data->{'dateexpiry'} = ExtendMemberSubscriptionTo( $borrowernumber );
96 my $borrowercategory = GetBorrowercategory( $data->{'categorycode'} );
97 my $category_type = $borrowercategory->{'category_type'};
99 # in template <TMPL_IF name="I"> => instutitional (A for Adult& C for children)
100 $template->param( $data->{'categorycode'} => 1 );
102 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
103 my $userdate = $data->{$_};
105 $debug and warn sprintf "Empty \$data{%12s}", $_;
109 my $tempdate = C4::Dates->new($userdate,'iso')->output('syspref')
110 or warn ("Invalid $_ = '$userdate'");
111 $data->{$_} = $tempdate || '';
113 $data->{'IS_ADULT'} = ( $data->{'categorycode'} ne 'I' );
115 for (qw(debarred gonenoaddress lost borrowernotes)) {
116 $data->{$_} and $template->param(flagged => 1) and last;
119 $data->{'ethnicity'} = fixEthnicity( $data->{'ethnicity'} );
121 $data->{ "sex_".$data->{'sex'}."_p" } = 1;
123 if ( $category_type eq 'C' and $data->{'guarantorid'} ne '0' ) {
124 my $data2 = GetMember( $data->{'guarantorid'} ,'borrowernumber');
125 foreach (qw(address city B_address B_city phone mobilezipcode)) {
126 $data->{$_} = $data2->{$_};
130 if ( $data->{'ethnicity'} || $data->{'ethnotes'} ) {
131 $template->param( printethnicityline => 1 );
133 if ( $category_type eq 'A' ) {
134 $template->param( isguarantee => 1 );
137 # It looks like the $i is only being returned to handle walking through
138 # the array, which is probably better done as a foreach loop.
140 my ( $count, $guarantees ) = GetGuarantees( $data->{'borrowernumber'} );
142 for ( my $i = 0 ; $i < $count ; $i++ ) {
145 borrowernumber => $guarantees->[$i]->{'borrowernumber'},
146 cardnumber => $guarantees->[$i]->{'cardnumber'},
147 name => $guarantees->[$i]->{'firstname'} . " "
148 . $guarantees->[$i]->{'surname'}
152 $template->param( guaranteeloop => \@guaranteedata );
153 ( $template->param( adultborrower => 1 ) ) if ( $category_type eq 'A' );
156 if ($data->{'guarantorid'}){
157 my ($guarantor) = GetMember( $data->{'guarantorid'},'biblionumber');
158 $template->param(guarantor => 1);
159 foreach (qw(borrowernumber cardnumber firstname surname)) {
160 $template->param("guarantor$_" => $guarantor->{$_});
165 #Independant branches management
166 my $unvalidlibrarian =
167 ( ( C4::Context->preference("IndependantBranches") )
168 && ( C4::Context->userenv->{flags} != 1 )
169 && ( $data->{'branchcode'} ne C4::Context->userenv->{branch} ) );
172 $bor{'borrowernumber'} = $borrowernumber;
174 # Converts the branchcode to the branch name
176 if ( C4::Context->preference("IndependantBranches") ) {
177 my $userenv = C4::Context->userenv;
178 unless ( $userenv->{flags} == 1 ) {
179 $samebranch = ( $data->{'branchcode'} eq $userenv->{branch} );
181 $samebranch = 1 if ( $userenv->{flags} == 1 );
183 my $branchdetail = GetBranchDetail( $data->{'branchcode'});
184 $data->{'branchname'} = $branchdetail->{branchname};
187 my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
188 my $lib1 = &GetSortDetails( "Bsort1", $data->{'sort1'} );
189 my $lib2 = &GetSortDetails( "Bsort2", $data->{'sort2'} );
190 ( $template->param( lib1 => $lib1 ) ) if ($lib1);
191 ( $template->param( lib2 => $lib2 ) ) if ($lib2);
195 my ( $count, $issue ) = GetPendingIssues($borrowernumber);
196 my $roaddetails = &GetRoadTypeDetails( $data->{'streettype'} );
197 my $today = POSIX::strftime("%Y%m%d", localtime); # iso format
201 for ( my $i = 0 ; $i < $count ; $i++ ) {
202 my $datedue = $issue->[$i]{'date_due'};
203 $issue->[$i]{'date_due'} = C4::Dates->new($issue->[$i]{'date_due'},'iso')->output('syspref');
204 my %row = %{ $issue->[$i] };
205 $totalprice += $issue->[$i]{'replacementprice'};
206 $row{'replacementprice'} = $issue->[$i]{'replacementprice'};
207 if ( $datedue < $today ) {
208 $row{'red'} = 1; #print "<font color=red>";
210 $row{toggle} = $toggle++ % 2;
212 #find the charge for an item
213 my ( $charge, $itemtype ) =
214 GetIssuingCharges( $issue->[$i]{'itemnumber'}, $borrowernumber );
216 my $itemtypeinfo = getitemtypeinfo($itemtype);
217 $row{'itemtype_description'} = $itemtypeinfo->{description};
218 $row{'itemtype_image'} = $itemtypeinfo->{imageurl};
220 $row{'charge'} = sprintf( "%.2f", $charge );
222 #check item is not reserved
223 my ( $restype, $reserves ) = CheckReserves( $issue->[$i]{'itemnumber'} );
224 $row{'norenew'} = ($restype) ? 1 : 0;
225 $row{'renew_failed'} = $renew_failed[$issue->[$i]{'itemnumber'}];
226 push( @issuedata, \%row );
229 ##################################################################################
231 # show all reserves of this borrower, and the position of the reservation ....
232 if ($borrowernumber) {
235 # now we show the status of the borrower's reservations
236 my @borrowerreserv = GetReservesFromBorrowernumber($borrowernumber );
238 foreach my $num_res (@borrowerreserv) {
240 my $getiteminfo = GetBiblioFromItemNumber( $num_res->{'itemnumber'} );
241 my $itemtypeinfo = getitemtypeinfo( $getiteminfo->{'itemtype'} );
242 my ( $transfertwhen, $transfertfrom, $transfertto ) =
243 GetTransfers( $num_res->{'itemnumber'} );
245 foreach (qw(waiting transfered nottransfered)) {
248 $getreserv{reservedate} = C4::Dates->new($num_res->{'reservedate'},'iso')->output('syspref');
249 foreach (qw(biblionumber title author barcodereserv itemcallnumber )) {
250 $getreserv{$_} = $getiteminfo->{$_};
252 $getreserv{itemtype} = $itemtypeinfo->{'description'};
254 # check if we have a waitin status for reservations
255 if ( $num_res->{'found'} eq 'W' ) {
256 $getreserv{color} = 'reserved';
257 $getreserv{waiting} = 1;
260 # check transfers with the itemnumber foud in th reservation loop
261 if ($transfertwhen) {
262 $getreserv{color} = 'transfered';
263 $getreserv{transfered} = 1;
264 $getreserv{datesent} = C4::Dates->new($transfertwhen, 'iso')->output('syspref') or die "Cannot get new($transfertwhen, 'iso') from C4::Dates";
265 $getreserv{frombranch} = GetBranchName($transfertfrom);
268 if ( ( $getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} )
269 and not $transfertwhen )
271 $getreserv{nottransfered} = 1;
272 $getreserv{nottransferedby} =
273 GetBranchName( $getiteminfo->{'holdingbranch'} );
276 # if we don't have a reserv on item, we put the biblio infos and the waiting position
277 if ( $getiteminfo->{'title'} eq '' ) {
278 my $getbibinfo = GetBiblioItemData( $num_res->{'biblionumber'} );
279 my $getbibtype = getitemtypeinfo( $getbibinfo->{'itemtype'} );
280 $getreserv{color} = 'inwait';
281 $getreserv{title} = $getbibinfo->{'title'};
282 $getreserv{waitingposition} = $num_res->{'priority'};
283 $getreserv{nottransfered} = 0;
284 $getreserv{itemtype} = $getbibtype->{'description'};
285 $getreserv{author} = $getbibinfo->{'author'};
286 $getreserv{itemcallnumber} = '----------';
287 $getreserv{biblionumber} = $num_res->{'biblionumber'};
290 push( @reservloop, \%getreserv );
293 # return result to the template
294 $template->param( reservloop => \@reservloop );
297 # current alert subscriptions
298 my $alerts = getalert($borrowernumber);
300 $_->{ $_->{type} } = 1;
301 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
304 my $htdocs = C4::Context->config('intrahtdocs');
305 $picture = "/borrowerimages/" . $borrowernumber . ".jpg";
306 if ( -e $htdocs . "$picture" ) {
307 $template->param( picture => $picture );
309 my $branch=C4::Context->userenv->{'branch'};
311 $template->param($data);
315 roaddetails => $roaddetails,
316 borrowernumber => $borrowernumber,
317 reregistration => $reregistration,
319 totalprice => sprintf( "%.2f", $totalprice ),
320 totaldue => sprintf( "%.2f", $total ),
321 issueloop => \@issuedata,
322 unvalidlibrarian => $unvalidlibrarian,
325 StaffMember => ($category_type eq 'S'),
326 # reserveloop => \@reservedata,
329 output_html_with_http_headers $input, $cookie, $template->output;