- 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','','$default_interview_pri','','$default_interview_pri','',$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\"");
- }
- $sth->execute or die "-E- DB error: $DBI::errstr\n";
- $sth = $dbh->prepare("update tc_indiv set attending='$attending' where name=\"$indiv_name\"");
- $sth->execute or die "-E- DB error: $DBI::errstr\n";
- $sth = $dbh->prepare("update tc_indiv set indiv_id='$id' where name=\"$indiv_name\"");
- $sth->execute or die "-E- DB error: $DBI::errstr\n";
- $sth = $dbh->prepare("update tc_indiv set priesthood='$priesthood' where name=\"$indiv_name\"");
- $sth->execute or die "-E- DB error: $DBI::errstr\n";
- $sth = $dbh->prepare("update tc_indiv set email='$email' where name=\"$indiv_name\"");
- $sth->execute or die "-E- DB error: $DBI::errstr\n";
- $sth = $dbh->prepare("update tc_indiv set hh_position='$hhposition' where name=\"$indiv_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 indiv: $indiv_name\n";
+
+ foreach $index (keys %membership_data)
+ {
+ $hashref = $membership_data{$index};
+ $id = $membership_data{$index}{'Indiv ID'};
+ $indiv_name = $membership_data{$index}{'Preferred Name'};
+ $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\",'$address','$phone','$email','','$hhposition','$priesthood','','$default_interview_pri','','$default_interview_pri','',$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($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\"");
+ }
+ $sth->execute or die "-E- DB error: $DBI::errstr\n";
+ $sth = $dbh->prepare("update tc_indiv set attending='$attending' where name=\"$indiv_name\"");
+ $sth->execute or die "-E- DB error: $DBI::errstr\n";
+ $sth = $dbh->prepare("update tc_indiv set indiv_id='$id' where name=\"$indiv_name\"");
+ $sth->execute or die "-E- DB error: $DBI::errstr\n";
+ $sth = $dbh->prepare("update tc_indiv set priesthood='$priesthood' where name=\"$indiv_name\"");
+ $sth->execute or die "-E- DB error: $DBI::errstr\n";
+ $sth = $dbh->prepare("update tc_indiv set email='$email' where name=\"$indiv_name\"");
+ $sth->execute or die "-E- DB error: $DBI::errstr\n";
+ $sth = $dbh->prepare("update tc_indiv set hh_position='$hhposition' where name=\"$indiv_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 indiv: $indiv_name\n";
+ }