$template->param( "checked" => 1) if ($nodouble eq 1);
-
+my $borrower_data=borrdata('',$borrowernumber);
# if a add or modify is requested => check validity of data.
+if ($step eq 0){
+ foreach my $column (keys %$borrower_data){
+ $data{$column}=$borrower_data->{$column};
+ }
+ $data{'borrowerid'}=$borrowernumber;
+ if (!$borrowerid){
+ $borrowerid=$borrowernumber;
+ }
+}
+
if ($op eq 'add' or $op eq 'modify') {
my @names=$input->param;
foreach my $key (@names){
$data{$key}=~ s/\"/\\\"/g;
}
+ # WARN : some tests must be done whatever the step, because the librarian can click on any tab.
#############test for member being unique #############
- if ($op eq 'add' && $step eq 2){
+ if ($op eq 'add'){
(my $category_type_send=$category_type ) if ($category_type eq 'I');
my $check_category; # recover the category code of the doublon suspect borrowers
($check_member,$check_category)= checkuniquemember($category_type_send,$data{'surname'},$data{'firstname'},format_date_in_iso($data{'dateofbirth'}));
-# recover the category type if the borrowers is a duplicate
+
+# recover the category type if the borrowers is a doublon
($check_categorytype,undef)=getcategorytype($check_category);
}
-
-# CHECKS step by step
+ # CHECKS step by step
# STEP 1
if ($step eq 1) {
###############test to take the right zipcode and city name ##############
my $sth=$dbh->prepare($query);
$sth->execute($categorycode);
my $category_info = $sth->fetchrow_hashref;
-
my $age = get_age(format_date_in_iso($data{dateofbirth}));
-
if ($age > $category_info->{upperagelimit}
or $age < $category_info->{dateofbirthrequired}
) {
}
# STEP 2
if ($step eq 2) {
- if ( ($data{'login'} eq '')){
+ if ( ($data{'userid'} eq '')){
my $onefirstnameletter=substr($data{'firstname'},0,1);
my $fivesurnameletter=substr($data{'surname'},0,5);
- $data{'login'}=lc($onefirstnameletter.$fivesurnameletter);
+ $data{'userid'}=lc($onefirstnameletter.$fivesurnameletter);
}
if ($op eq 'add' and $data{'dateenrolled'} eq ''){
- my $today=today();
+ my $today= sprintf('%04d-%02d-%02d', Today());
#insert ,in field "dateenrolled" , the current date
$data{'dateenrolled'}=$today;
#if date expiry is null u must calculate the value only in this case
$data{'dateexpiry'} = calcexpirydate($data{'categorycode'},$today);
}
if ($op eq 'modify' ){
- my $today=today();
+ my $today= sprintf('%04d-%02d-%02d', Today());
# if date expiry is null u must calculate the value only in this case
if ($data{'dateexpiry'} eq ''){
$data{'dateexpiry'} = calcexpirydate($data{'categorycode'},$today);
# STEP 3
if ($step eq 3) {
# this value show if the login and password are been used
- my $loginexist=checkuserpassword($borrowerid,$data{'login'},$data{'password'});
+ my $loginexist=checkuserpassword($borrowernumber,$data{'userid'},$data{'password'});
# test to know if u must save or create the borrowers
if ($op eq 'modify'){
# test to know if another user have the same password and same login
if ($loginexist eq 0) {
&modmember(%data);
- logaction($loggedinuser,"MEMBERS","modify member", $borrowerid, "");
+ logaction($loggedinuser,"MEMBERS","modify member", $borrowernumber, "");
}
else {
push @errors, "ERROR_login_exist";
push @errors, "ERROR_login_exist";
$nok=1;
} else {
- $borrowerid = &newmember(%data);
- if ($data{'organisations'}){
+ $borrowernumber = &newmember(%data);
+ if ($data{'organisations'}){
# need to add the members organisations
- add_member_orgs($borrowerid,$data{'organisations'});
+ my @orgs=split(/\|/,$data{'organisations'});
+ add_member_orgs($borrowerid,\@orgs);
}
- logaction($loggedinuser,"MEMBERS","add member", $borrowerid, "");
+ logaction($loggedinuser,"MEMBERS","add member", $borrowernumber, "");
}
}
print $input->redirect("/cgi-bin/koha/circ/circulation.pl?findborrower=$data{'cardnumber'}");
} else {
if ($loginexist == 0) {
- print $input->redirect("/cgi-bin/koha/members/moremember.pl?bornum=$borrowerid");
+ print $input->redirect("/cgi-bin/koha/members/moremember.pl?bornum=$borrowernumber");
}
}
}
}
if ($delete){
- print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$borrowerid");
print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$borrowernumber");
} else { # this else goes down the whole script
# retrieve previous values : either in DB or in CGI, in case of errors in values
my $data;
# test to now if u add or modify a borrower (modify =>to take all carateristic of the borrowers)
if (!$op and !$data{'surname'}) {
- $data=borrdata('',$borrowerid);
+ $data=borrdata('',$borrowernumber);
%data=%$data;
}
if (C4::Context->preference("IndependantBranches")) {
$step++;
}
- warn "CITY".$data{city};
+
$template->param(
BorrowerMandatoryField => C4::Context->preference("BorrowerMandatoryField"),#field to test with javascript
category_type => $category_type,#to know the category type of the borrower
"op$op" => 1,
# op => $op,
nodouble => $nodouble,
- borrowerid => $borrowerid,#register number
+ borrowernumber => $borrowernumber,#register number
cardnumber => $data{'cardnumber'},
surname => uc($data{'surname'}),
firstname => ucfirst($data{'firstname'}),
guarantorid => $guarantorid,
ethcatpopup => $ethcatpopup,
sex => $data{'sex'},
- login => $data{'login'},
+ userid => $data{'userid'},
password => $data{'password'},
- opacnotes => $data{'opacnotes'},
+ opacnote => $data{'opacnote'},
contactnotes => $data{'contactnotes'},
borrowernotes => $data{'borrowernotes'},
relshiploop => \@relshipdata,
contacttype => $data{'contacttype'},
organisations => $data{'organisations'},
flagloop => \@flagdata,
-# "contacttype_".$data{'contacttype'} =>" SELECTED ",
+# "contacttype_".$data{'contacttype'} =>" SELECTED ",
dateformat => display_date_format(),
check_categorytype =>$check_categorytype,#to recover the category type with checkcategorytype function
- modify => $modify,
-# city_choice => $city_choice ,#check if the city was selected
+ modify => $modify,
+# city_choice => $city_choice ,#check if the city was selected
nok => $nok,#flag to konw if an error
CGIbranch => $CGIbranch,
memberofinstution => $member_of_institution,
output_html_with_http_headers $input, $cookie, $template->output;
}
-sub get_age {
- my ($date, $date_ref) = @_;
-
- if (not defined $date_ref) {
- $date_ref = sprintf('%04d-%02d-%02d', Today());
- }
-
- my ($year1, $month1, $day1) = split /-/, $date;
- my ($year2, $month2, $day2) = split /-/, $date_ref;
-
- my $age = $year2 - $year1;
- if ($month1.$day1 > $month2.$day2) {
- $age--;
- }
-
- return $age;
-}
-
# Local Variables:
# tab-width: 8
# End: