- foreach $key (keys %$hashref) {
- if($key =~ /Priesthood/i && $membership_data{$index}{$key} =~ /Elder/i) {
- $id = $membership_data{$index}{'Indiv ID'};
- $elder_name = $membership_data{$index}{'Preferred Name'};
- $phone = $membership_data{$index}{'Phone 1'};
- $organization = $organization_by_id{$id};
- $attending = 0;
- if(($organization =~ /Elders/) ||
- ($organization =~ /Young Men/) ||
- ($organization =~ /Sunday School/) ||
- ($organization =~ /Primary/)
- ) { $attending = 1; }
- if($phone =~ /(\d\d\d-\d\d\d\d)/) { $phone = "970-$1"; }
- if($phone =~ /^\(\d\d\d\) (\d\d\d-\d\d\d\d)/) { $phone = "$1-$2"; }
- $sth = $dbh->prepare("select * from eq_elder where name='$elder_name'");
- $sth->execute or die "-E- DB error: $DBI::errstr\n";
- my @data = ();
- while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
- my $rows = scalar @data;
- if($rows == 0) {
- # No existing records found for this elder, make a new entry
- print " Adding new Elder: $elder_name\n";
- $sth = $dbh->prepare("insert into eq_elder values (NULL,'$elder_name','$phone','1','','1','',$attending,1)");
- $sth->execute or die "-E- DB error: $DBI::errstr\n";
- } elsif($rows == 1) {
- # An existing record was found for this elder, update it
- print " Updating existing Elder: $elder_name\n";
- $sth = $dbh->prepare("update eq_elder set valid=1 where name='$elder_name'");
- $sth->execute or die "-E- DB error: $DBI::errstr\n";
- if($phone ne "") {
- $sth = $dbh->prepare("update eq_elder set phone='$phone' where name='$elder_name'");
- } else {
- $sth = $dbh->prepare("update eq_elder set phone=NULL where name='$elder_name'");
- }
- $sth->execute or die "-E- DB error: $DBI::errstr\n";
- $sth = $dbh->prepare("update eq_elder set attending='$attending' where name='$elder_name'");
- $sth->execute or die "-E- DB error: $DBI::errstr\n";
- } else {
- # More than one record was found. Error! This shouldn't happen.
- print " -E- More than one record found ($rows) for Elder: $elder_name\n";
- }
+ $id = $membership_data{$index}{'Indiv ID'};
+ $indiv_name = $membership_data{$index}{'Preferred Name'};
+ $birthday = $membership_data{$index}{'Birth'};
+ $birthday =~ /(\d+) (\S+) (\d+)/; $day=$1; $month=$monthname2num{$2}; $year=$3;
+ $address = $membership_data{$index}{'Street 1'};
+ if($membership_data{$index}{'Street 2'} ne "") {
+ $address .= " " . $membership_data{$index}{'Street 2'};
+ }
+ $phone = $membership_data{$index}{'Household Phone'};
+ $priesthood = $membership_data{$index}{'Priesthood'};
+ $hhposition = $membership_data{$index}{'HH Position'};
+ $organization = $organization_by_id{$id};
+ $attending = 0;
+ if(($organization =~ /Elders/) ||
+ ($organization =~ /Young Men/) ||
+ ($organization =~ /Sunday School/) ||
+ ($organization =~ /Primary/)
+ ) { $attending = 1; }
+ if($phone =~ /(\d\d\d-\d\d\d\d)/) { $phone = "$areacode-$1"; }
+ if($phone =~ /^\(\d\d\d\) (\d\d\d-\d\d\d\d)/) { $phone = "$1-$2"; }
+ $email = $membership_data{$index}{'indiv E-mail'};
+ if ($email eq "") { $email = $membership_data{$index}{'Household E-mail'}; }
+ $sth = $dbh->prepare("select * from tc_indiv where name=\"$indiv_name\"");
+ $sth->execute or die "-E- DB error: $DBI::errstr\n";
+ my @data = ();
+ while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
+ my $rows = scalar @data;
+ if($rows == 0) {
+ # No existing records found for this indiv, make a new entry
+ print " Adding new indiv: $indiv_name\n";
+ $sth = $dbh->prepare("insert into tc_indiv values (NULL,'$id',\"$indiv_name\",'$year-$month-$day','$address','$phone','$email','','$hhposition','$priesthood','','1','','1','',$attending,1)");
+ $sth->execute or die "-E- DB error: $DBI::errstr\n";
+ } elsif($rows == 1) {
+ # An existing record was found for this indiv, update it
+ print " Updating existing indiv: $indiv_name\n";
+ $sth = $dbh->prepare("update tc_indiv set valid=1 where name=\"$indiv_name\"");
+ $sth->execute or die "-E- DB error: $DBI::errstr\n";
+ if($phone ne "") {
+ $sth = $dbh->prepare("update tc_indiv set phone='$phone' where name=\"$indiv_name\"");
+ } else {
+ $sth = $dbh->prepare("update tc_indiv set phone=NULL where name=\"$indiv_name\"");
+ }
+ $sth->execute or die "-E- DB error: $DBI::errstr\n";
+ if($birthday ne "") {
+ $sth = $dbh->prepare("update tc_indiv set birthday='$year-$month-$day' where name=\"$indiv_name\"");
+ } else {
+ $sth = $dbh->prepare("update tc_indiv set birthday=NULL where name=\"$indiv_name\"");
+ }
+ $sth->execute or die "-E- DB error: $DBI::errstr\n";
+ if($address ne "") {
+ $sth = $dbh->prepare("update tc_indiv set address='$address' where name=\"$indiv_name\"");
+ } else {
+ $sth = $dbh->prepare("update tc_indiv set address=NULL where name=\"$indiv_name\"");