# error message to display
# FIXME - What is the correct value of "flagsrequired"?
-# FIXME - untranslatable strings here
# Copyright 2000-2002 Katipo Communications
#
use strict;
use C4::Auth;
use C4::Input;
-use C4::Charset;
+use C4::Interface::CGI::Output;
use CGI;
use Date::Manip;
use HTML::Template;
-
+use C4::Date;
my %env;
my $input = new CGI;
flagsrequired => {parameters => 1},
});
+#Get the database handle
+my $dbh = C4::Context->dbh;
+
# Check that all compulsary fields are entered
# If everything is ok, set $ok = 0
# Otherwise set $ok = 1 and $string to the error message to display.
my $ok=0;
my $string = "The following compulsary fields have been left blank. "
. "Please push the back button and try again<p>";
-
+my @errors;
if ($data{'cardnumber'} eq ''){
- $string.=" Cardnumber<br>";
+ push @errors,"cardnumber";
$ok=1;
} else {
#check cardnumber is valid
- my $valid=checkdigit(\%env,$data{'cardnumber'});
+ my $nounique;
+ if ( $data{'type'} eq "Add" ) {
+ $nounique = 0;
+ } else {
+ $nounique = 1;
+ }
+ my $valid=checkdigit(\%env,$data{'cardnumber'}, $nounique);
if ($valid != 1){
$ok=1;
- $string.=" Invalid Cardnumber<br>";
+ push @errors, "invalid_cardnumber";
}
}
if ($data{'sex'} eq ''){
- $string.=" Gender <br>";
+ push @errors, "gender";
$ok=1;
}
if ($data{'firstname'} eq ''){
- $string.=" Given Names<br>";
+ push @errors,"firstname";
$ok=1;
}
if ($data{'surname'} eq ''){
- $string.=" Surname<br>";
+ push @errors,"surname";
$ok=1;
}
if ($data{'address'} eq ''){
- $string.=" Postal Street Address<br>";
+ push @errors, "address";
$ok=1;
}
if ($data{'city'} eq ''){
- $string.=" Postal City<br>";
- $ok=1;
-}
-if ($data{'contactname'} eq ''){
- $string.=" Alternate Contact<br>";
+ push @errors, "city";
$ok=1;
}
# Pass the ok/not ok status and the error message to the template
-$template->param( OK=> ($ok==0),
- string=> $string);
+$template->param( OK=> ($ok==0));
+foreach my $error (@errors) {
+ $template->param( $error => 1);
+}
# If things are ok, display the confirmation page
if ($ok == 0) {
$name.="$data{'surname'} ( $data{'firstname'}, $data{'initials'})";
my $sex;
if ($data{'sex'} eq 'M'){
- $sex="Male";
+ $sex=1;
} else {
- $sex="Female";
+ $sex=0;
}
if ($data{'joining'} eq ''){
$data{'joining'}=ParseDate('today');
- $data{'joining'}=&UnixDate($data{'joining'},'%Y-%m-%d');
+ $data{'joining'}=format_date($data{'joining'});
}
if ($data{'expiry'} eq ''){
- $data{'expiry'}=ParseDate('in 1 year');
- $data{'expiry'}=&UnixDate($data{'expiry'},'%Y-%m-%d');
+ my $get_enrolmentperiod = $dbh->prepare(q{SELECT enrolmentperiod FROM categories WHERE categorycode = ?});
+ $get_enrolmentperiod->execute($data{'categorycode'});
+ my ( $period ) = $get_enrolmentperiod->fetchrow;
+ if ( ($period) && ($period != 1))
+ {
+ $data{'expiry'}=ParseDate("in $period years");
+ $data{'expiry'}=format_date($data{'expiry'});
+ }
+ else
+ {
+ $data{'expiry'}=ParseDate('in 1 year');
+ $data{'expiry'}=format_date($data{'expiry'});
+ }
}
my $ethnic=$data{'ethnicity'}." ".$data{'ethnicnotes'};
my $postal=$data{'address'}."<br>".$data{'city'};
push(@inputsloop, \%line);
}
+ #Get the fee
+ my $sth = $dbh->prepare("SELECT enrolmentfee FROM categories WHERE categorycode = ?");
+ $sth->execute($data{'categorycode'});
+ my ($fee) = $sth->fetchrow;
+ $sth->finish;
+
$template->param(name => $name,
bornum => $data{'borrowernumber'},
cardnum => $data{'cardnumber'},
memcat => $data{'categorycode'},
- area => $data{'area'},
- fee => $data{'fee'},
- joindate => $data{'joining'},
- expdate => $data{'expiry'},
- joinbranch => $data{'joinbranch'},
+ fee => $fee,
+ joindate => format_date($data{'joining'}),
+ expdate => format_date($data{'expiry'}),
+ branchcode => $data{'branchcode'},
ethnic => $ethnic,
- dob => $data{'dateofbirth'},
+ dob => format_date($data{'dateofbirth'}),
sex => $sex,
postal => $postal,
home => $home,
+ zipcode => $data{'zipcode'},
+ homezipcode => $data{'homezipcode'},
phone => $data{'phone'},
phoneday => $data{'phoneday'},
faxnumber => $data{'faxnumber'},
emailaddress => $data{'emailaddress'},
+ textmessaging => $data{'textmessaging'},
contactname => $data{'contactname'},
altphone => $data{'altphone'},
altrelationship => $data{'altrelationship'},
;
}
-print $input->header(
- -type => guesstype($template->output),
- -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $input, $cookie, $template->output;