removed tc_parent, tc_child, and tc_aaronic tables, moved required info into tc_indiv...
authorOwen Leonard <owen@balawis.leonard.fam>
Sun, 12 Sep 2010 07:13:07 +0000 (01:13 -0600)
committerOwen Leonard <owen@balawis.leonard.fam>
Sun, 12 Sep 2010 07:13:07 +0000 (01:13 -0600)
bin/import_ward_data
bin/upgrade_4_0_to_5_0
inc/class.tc.inc.php
sql/schema.dot
sql/tc.jpg
sql/tc.sql
templates/default/int_update.tpl
templates/default/ppi_update.tpl

index 21a5a368006ee6f4da26be483e292de634e8e74f..97823c43a4fbe7cac26982707491f360b6c7a2ef 100755 (executable)
@@ -102,67 +102,6 @@ sub print_hash
 
 ######################################################################
 
-# 3RD_AARONIC
-#+-------+--------------------+------+-----+---------+-------+
-#| Field | Type               | Null | Key | Default | Extra |
-#+-------+--------------------+------+-----+---------+-------+
-#| aaronic | int(16) unsigned |      | PRI | 0       |   A   |
-#| name    | varchar(60)      | YES  |     | NULL    |       |
-#| phone   | varchar(12)      | YES  |     | NULL    |       |
-#| email   | varchar(120)     | YES  |     | NULL    |       |
-#| valid   | tinyint(1)       | YES  |     | NULL    |       |
-#+-------+--------------------+------+-----+---------+-------+
-sub update_tc_aaronic_table
-{
-    print "\n-> Updating tc_aaronic table\n";
-
-    # Set all records to be invalid. Only mark them as valid if they appear on the new list.
-    $sth = $dbh->prepare("update tc_aaronic set valid=0");
-    $sth->execute or die "-E- DB error: $DBI::errstr\n";
-    
-    foreach $index (keys %membership_data)
-    {
-       $hashref = $membership_data{$index};
-       foreach $key (keys %$hashref) {
-           if($key =~ /Priesthood/i &&
-              ($membership_data{$index}{$key} =~ /^Deacon\s*$/i ||
-               $membership_data{$index}{$key} =~ /^Teacher\s*$/i ||
-               $membership_data{$index}{$key} =~ /^Priest\s*$/i)) {
-               $aaronic_name = $membership_data{$index}{'Preferred Name'};
-               $phone = $membership_data{$index}{'Household Phone'};
-               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}{'Individual E-mail'};
-               if ($email eq "") { $email = $membership_data{$index}{'Household E-mail'}; }
-               $sth = $dbh->prepare("select * from tc_aaronic where name='$aaronic_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 aaronic, make a new entry
-                   print "   Adding new Aaronic: $aaronic_name\n";
-                   $sth = $dbh->prepare("insert into tc_aaronic values (NULL,'$aaronic_name','$phone','$email',1)");
-                   $sth->execute or die "-E- DB error: $DBI::errstr\n";
-               } elsif($rows == 1) {
-                   # An existing record was found for this aaronic, update it, mark it valid!
-                   print "   Updating existing aaronic: $aaronic_name\n";
-                   $sth = $dbh->prepare("update tc_aaronic set phone='$phone' where name='$aaronic_name'");
-                   $sth->execute or die "-E- DB error: $DBI::errstr\n";
-                   $sth = $dbh->prepare("update tc_aaronic set email='$email' where name='$aaronic_name'");
-                   $sth->execute or die "-E- DB error: $DBI::errstr\n";
-                   $sth = $dbh->prepare("update tc_aaronic set valid=1 where name='$aaronic_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 aaronic name: $aaronic_name\n";
-               }
-           }
-       }
-    }
-    $sth->finish();
-}
-
 # 3RD_INDIV
 #+-------------+------------------+------+-----+---------+----------------+
 #| Field       | Type             | Null | Key | Default | Extra          |
@@ -191,77 +130,74 @@ sub update_tc_indiv_table
     foreach $index (keys %membership_data)
     {
        $hashref = $membership_data{$index};
-       foreach $key (keys %$hashref) {
-           if($key =~ /Priesthood/i && 
-              ($membership_data{$index}{$key} =~ /Deacon/i ||
-               $membership_data{$index}{$key} =~ /Teacher/i ||
-               $membership_data{$index}{$key} =~ /Priest/i ||
-               $membership_data{$index}{$key} =~ /Elder/i ||
-               $membership_data{$index}{$key} =~ /Unordained/i)) {
-               
-               # check if this is a prospective elder under the stewardship of the EQ
-               if($membership_data{$index}{$key} !~ /Elder/i) {
-                       $found = 0;
-                       foreach $i (keys %prospective_elder_data) {
-                               #print "$membership_data{$index}{'Full Name'}\n";
-                               #print "$prospective_elder_data{$i}{'Full Name'}\n";
-                               if($membership_data{$index}{'Full Name'} eq $prospective_elder_data{$i}{'Full Name'}) {
-                                       $found = 1;
-                                       last;
-                               }
-                       }
-                       if($found == 0) { next;}
-               }
-               
-               $id = $membership_data{$index}{'Indiv ID'};
-               $indiv_name = $membership_data{$index}{'Preferred Name'};
-               $phone = $membership_data{$index}{'Household Phone'};
-               $priesthood = $membership_data{$index}{'Priesthood'};
-               $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','$phone','$email','$priesthood','n','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";
-                   $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";
-               } 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";
-               }
+       $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\"");
            }
+           $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";
        }
     }
     $sth->finish();
@@ -346,7 +282,6 @@ sub update_tc_district_table
 #+---------------+------------------+------+-----+---------+-------+
 #| companionship | int(16) unsigned |      |     | 0       |       |
 #| indiv         | int(16) unsigned | YES  |     | NULL    |       |
-#| aaronic       | int(16) unsigned | YES  |     | NULL    |       |
 #| district      | int(16) unsigned | YES  |     | NULL    |       |
 #| valid         | tinyint(1)       | YES  |     | NULL    |       |
 #+---------------+------------------+------+-----+---------+-------+
@@ -357,9 +292,6 @@ sub update_tc_companionship_table
     # First, mark all existing companionships as invalid in case they have been dissolved
     $sth = $dbh->prepare("update tc_companionship set valid=0");
     $sth->execute or die "-E- DB error: $DBI::errstr\n";
-    # Second, mark all the aaronic invalid. We'll only mark the ones as valid that are assigned to hometeach
-    $sth = $dbh->prepare("update tc_aaronic set valid=0");
-    $sth->execute or die "-E- DB error: $DBI::errstr\n";
     
     foreach $index (keys %hometeaching_data)
     {
@@ -373,18 +305,9 @@ sub update_tc_companionship_table
                    $sth2->execute or die "-E- DB error: $DBI::errstr\n";
                    $sqlhashref2 = $sth2->fetchrow_hashref;
                    $indiv = $sqlhashref2->{indiv};
-                   $aaronic = "NULL";
-                   if($indiv eq "") {
-                       $sth2 = $dbh->prepare("select * from tc_aaronic where name='$indiv_name'");
-                       $sth2->execute or die "-E- DB error: $DBI::errstr\n";
-                       $sqlhashref2 = $sth2->fetchrow_hashref;
-                       $aaronic = $sqlhashref2->{aaronic};
-                       $indiv = "NULL";
-                       if($aaronic eq "") { print "-W- Unable to find $indiv_name in tc_indiv or tc_aaronic tables\n"; next; }
-                   } 
                    $id = $hometeaching_data{$index}{'Comp ID'};
                    $district = $hometeaching_data{$index}{'HT District'};
-                   $sth = $dbh->prepare("select * from tc_companionship where indiv='$indiv' and aaronic='$aaronic' and companionship='$id'");
+                   $sth = $dbh->prepare("select * from tc_companionship where indiv='$indiv' and companionship='$id'");
                    $sth->execute or die "-E- DB error: $DBI::errstr\n";
                    my @data = ();
                    while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); }
@@ -392,31 +315,19 @@ sub update_tc_companionship_table
                    if($rows == 0) {
                        # No existing records found for this companionship, make a new entry
                        print "   Adding Companion to companionship: $indiv_name -> $id\n";
-                       $sth = $dbh->prepare("insert into tc_companionship values ($id,'$indiv','$aaronic','$district',1)");
+                       $sth = $dbh->prepare("insert into tc_companionship values ($id,'$indiv','$district',1)");
                        $sth->execute or die "-E- DB error: $DBI::errstr\n";
                    } else {
                        # An existing companionship was found for this companionship, update it
                        $sth2 = $dbh->prepare("select * from tc_companionship where district='$district' and companionship='$id'");
                        $sth2->execute or die "-E- DB error: $DBI::errstr\n";
-                       if($indiv ne "NULL") {
-                           print "   Updating Companionship with indiv: $indiv_name ($indiv) -> $id\n";
-                           $sth = $dbh->prepare("update tc_companionship set district='$district' where indiv='$indiv' and companionship='$id'");
-                           $sth->execute or die "-E- DB error 'district': $DBI::errstr\n";
-                           $sth = $dbh->prepare("update tc_companionship set indiv='$indiv' where indiv='$indiv' and companionship='$id'");
-                           $sth->execute or die "-E- DB error 'indiv': $DBI::errstr\n";
-                           $sth = $dbh->prepare("update tc_companionship set valid=1 where indiv='$indiv' and companionship='$id'");
-                           $sth->execute or die "-E- DB error 'valid': $DBI::errstr\n";
-                       } else {
-                           print "   Updating Companionship with Aaronic: $indiv_name ($aaronic) -> $id\n";
-                           $sth = $dbh->prepare("update tc_companionship set district='$district' where aaronic='$aaronic' and companionship='$id'");
-                           $sth->execute or die "-E- DB error: $DBI::errstr\n";
-                           $sth = $dbh->prepare("update tc_companionship set aaronic='$aaronic' where aaronic='$aaronic' and companionship='$id'");
-                           $sth->execute or die "-E- DB error: $DBI::errstr\n";
-                           $sth = $dbh->prepare("update tc_companionship set valid=1 where aaronic='$aaronic' and companionship='$id'");
-                           $sth->execute or die "-E- DB error: $DBI::errstr\n";                            
-                           $sth = $dbh->prepare("update tc_aaronic set valid=1 where aaronic='$aaronic'");
-                           $sth->execute or die "-E- DB error: $DBI::errstr\n";
-                       }
+                       print "   Updating Companionship with indiv: $indiv_name ($indiv) -> $id\n";
+                       $sth = $dbh->prepare("update tc_companionship set district='$district' where indiv='$indiv' and companionship='$id'");
+                       $sth->execute or die "-E- DB error 'district': $DBI::errstr\n";
+                       $sth = $dbh->prepare("update tc_companionship set indiv='$indiv' where indiv='$indiv' and companionship='$id'");
+                       $sth->execute or die "-E- DB error 'indiv': $DBI::errstr\n";
+                       $sth = $dbh->prepare("update tc_companionship set valid=1 where indiv='$indiv' and companionship='$id'");
+                       $sth->execute or die "-E- DB error 'valid': $DBI::errstr\n";
                    }
                    $sth->finish();
                    $sth2->finish();                
@@ -525,171 +436,6 @@ sub update_tc_family_table
     }
 }
 
-# 3RD_PARENT
-#+----------+------------------+------+-----+---------+-------+
-#| Field    | Type             | Null | Key | Default | Extra |
-#+----------+------------------+------+-----+---------+-------+
-#| parent   | int(16) unsigned |      | PRI | 0       |   A   |
-#| family   | int(16) unsigned | YES  |     | NULL    |       |
-#| name     | varchar(30)      | YES  |     | NULL    |       |
-#| birthday | date             | YES  |     | NULL    |       |
-#| phone    | varchar(12)      | YES  |     | NULL    |       |
-#| address  | varchar(255)     | YES  |     | NULL    |       |
-#| indiv_id | int(16) unsigned | YES  | UNI | NULL    |       |
-#| valid    | tinyint(1)       | YES  |     | NULL    |       |
-#+----------+------------------+------+-----+---------+-------+
-sub update_tc_parent_table
-{
-    print "\n-> Updating tc_parent table\n";
-
-    # Set all records to be invalid. Only mark them as valid if they appear on the new list.
-    $sth = $dbh->prepare("update tc_parent set valid=0");
-    $sth->execute or die "-E- DB error: $DBI::errstr\n";
-    
-    foreach $index (keys %membership_data)
-    {
-       $hashref = $membership_data{$index};
-       foreach $key (keys %$hashref) {
-           if($key =~ /HH Position/i &&
-              $membership_data{$index}{$key} =~ /Head of Household/i ||
-              $membership_data{$index}{$key} =~ /Spouse/i
-              ) {
-               # Get some information from the hash about this parent
-               $parent_name = $membership_data{$index}{'Preferred Name'};
-               $parent_name =~ s/\'/\\'/g; #'
-               $birthday = $membership_data{$index}{'Birth'};
-               $birthday =~ /(\d+) (\S+) (\d+)/; $day=$1; $month=$monthname2num{$2}; $year=$3;
-               $hofh_id = $membership_data{$index}{'HofH ID'};
-               $id = $membership_data{$index}{'Indiv ID'};
-               $phone = $membership_data{$index}{'Household Phone'};
-               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"; }
-               $address = $membership_data{$index}{'Street 1'};
-               if($membership_data{$index}{'Street 2'} ne "") { 
-                   $address .= " " . $membership_data{$index}{'Street 2'};
-               }
-
-               # Find the family id for this parent's HofH_ID.
-               $sth = $dbh->prepare("select * from tc_family where hofh_id='$hofh_id' and valid=1");
-               $sth->execute or die "-E- DB error: $DBI::errstr\n";
-               my @family_data = ();
-               while($sqlhashref = $sth->fetchrow_hashref) { push(@family_data, $sqlhashref); }
-               my $family_rows = scalar @family_data;
-               if($family_rows > 0) { $family_id = $family_data[0]->{'family'}; }
-               else { $family_id = 0; }
-               
-               # Find out how many parents match this parent's name
-               $sth = $dbh->prepare("select * from tc_parent where name='$parent_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 && $family_rows > 0) {
-                   # No existing records found for this parent, make a new entry
-                   print "   Adding new Parent: $parent_name\n";
-                   $sth = $dbh->prepare("insert into tc_parent values (NULL,$family_id,'$parent_name','$year-$month-$day','$phone','$address','$id',1)");
-                   $sth->execute or die "-E- DB error: $DBI::errstr\n";
-               } elsif($rows == 1 && $family_rows > 0) {
-                   # An existing record was found for this parent, update it
-                   print "   Updating existing parent: $parent_name\n";
-                   $sth = $dbh->prepare("update tc_parent set family='$family_id' where name='$parent_name'");
-                   $sth->execute or die "-E- DB error: $DBI::errstr\n";
-                   $sth = $dbh->prepare("update tc_parent set birthday='$year-$month-$day' where name='$parent_name'");
-                   $sth->execute or die "-E- DB error: $DBI::errstr\n";
-                   $sth = $dbh->prepare("update tc_parent set phone='$phone' where name='$parent_name'");
-                   $sth->execute or die "-E- DB error: $DBI::errstr\n";
-                   $sth = $dbh->prepare("update tc_parent set address='$address' where name='$parent_name'");
-                   $sth->execute or die "-E- DB error: $DBI::errstr\n";
-                   $sth = $dbh->prepare("update tc_parent set valid=1 where name='$parent_name'");
-                   $sth->execute or die "-E- DB error: $DBI::errstr\n";
-                   $sth = $dbh->prepare("update tc_parent set indiv_id='$id' where name='$parent_name'");
-                   $sth->execute or die "-E- DB error: $DBI::errstr\n";
-               } elsif($rows > 1) {
-                   # More than one record was found. Error! This shouldn't happen.
-                   print "   -E- More than one record found with same parent name: $parent_name with hofh_id: $hofh_id\n";
-               } else {
-                   print "   -E- Unable to find a family to attach this parent to: $parent_name with hofh_id: $hofh_id\n";
-               }
-               $sth->finish();
-           }
-       }
-    }
-}
-
-# 3RD_CHILD
-#+----------+------------------+------+-----+---------+-------+
-#| Field    | Type             | Null | Key | Default | Extra |
-#+----------+------------------+------+-----+---------+-------+
-#| child    | int(16) unsigned |      | PRI | 0       |   A   |
-#| family   | int(16) unsigned | YES  |     | NULL    |       |
-#| name     | varchar(30)      | YES  |     | NULL    |       |
-#| birthday | date             | YES  |     | NULL    |       |
-#| indiv_id | int(16) unsigned | YES  | UNI | NULL    |       |
-#| valid    | tinyint(1)       | YES  |     | NULL    |       |
-#+----------+------------------+------+-----+---------+-------+
-sub update_tc_child_table
-{
-    print "\n-> Updating tc_child table\n";
-
-    # Set all records to be invalid. Only mark them as valid if they appear on the new list.
-    $sth = $dbh->prepare("update tc_child set valid=0");
-    $sth->execute or die "-E- DB error: $DBI::errstr\n";
-    
-    foreach $index (keys %membership_data)
-    {
-       $hashref = $membership_data{$index};
-       foreach $key (keys %$hashref) {
-           if($key =~ /HH Position/i && $membership_data{$index}{$key} =~ /Other/i ) {
-               $child_name = $membership_data{$index}{'Full Name'};
-               $child_name =~ s/\'/\\'/g; #'
-               $birthday = $membership_data{$index}{'Birth'};
-               $birthday =~ /(\d+) (\S+) (\d+)/; $day=$1; $month=$monthname2num{$2}; $year=$3;
-               $id = $membership_data{$index}{'Indiv ID'};
-               $hofh_id = $membership_data{$index}{'HofH ID'};
-
-               # Find the family id for this child's HofH_ID.
-               $sth = $dbh->prepare("select * from tc_family where hofh_id='$hofh_id' and valid=1");
-               $sth->execute or die "-E- DB error: $DBI::errstr\n";
-               my @family_data = ();
-               while($sqlhashref = $sth->fetchrow_hashref) { push(@family_data, $sqlhashref); }
-               my $family_rows = scalar @family_data;
-               if($family_rows > 0) { $family_id = $family_data[0]->{'family'}; }
-               else { $family_id = 0; }
-               
-               # Find out how many children have the same name for the same family
-               $sth = $dbh->prepare("select * from tc_child where name='$child_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 && $family_rows > 0) {
-                   # No existing records found for this child, make a new entry
-                   print "   Adding new Child: $child_name\n";
-                   $sth = $dbh->prepare("insert into tc_child values (NULL,$family_id,'$child_name','$year-$month-$day','$id',1)");
-                   $sth->execute or die "-E- DB error: $DBI::errstr\n";
-               } elsif($rows == 1 && $family_rows > 0) {
-                   # An existing record was found for this child, update it
-                   print "   Updating existing child: $child_name\n";
-                   $sth = $dbh->prepare("update tc_child set family='$family_id' where name='$child_name'");
-                   $sth->execute or die "-E- DB error: $DBI::errstr\n";
-                   $sth = $dbh->prepare("update tc_child set birthday='$year-$month-$day' where name='$child_name'");
-                   $sth->execute or die "-E- DB error: $DBI::errstr\n";
-                   $sth = $dbh->prepare("update tc_child set valid=1 where name='$child_name'");
-                   $sth->execute or die "-E- DB error: $DBI::errstr\n";
-                   $sth = $dbh->prepare("update tc_child set indiv_id='$id' where name='$child_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) with same child name: $child_name\n";
-               }
-               $sth->finish();
-           }
-       }
-    }
-}
-
 # 3RD_VISIT
 #+----------------+------------------+------+-----+---------+-------+
 #| Field          | Type             | Null | Key | Default | Extra |
@@ -833,6 +579,36 @@ sub check_for_changed_ids
     return $found_problem;
 }
 
+sub update_family_in_tc_indiv_table
+{
+    print "\n-> Updating family info in tc_indiv table\n";
+
+    foreach $index (keys %membership_data)
+    {
+       $hashref = $membership_data{$index};
+       
+       # get some information from hash about this individual
+       $name = $membership_data{$index}{'Preferred Name'};
+       $hofh_id = $membership_data{$index}{'HofH ID'};
+       
+       # Find the family id for this individual's HofH_id
+       $sth = $dbh->prepare("select * from tc_family where hofh_id=$hofh_id and valid=1");
+       $sth->execute or die "-E- DB error: $DBI::errstr\n";
+       my @family_data = ();
+       while($sqlhashref = $sth->fetchrow_hashref) { push(@family_data, $sqlhashref); }
+       my $family_rows = scalar @family_data;
+       if($family_rows > 0) { 
+               $family_id = $family_data[0]->{'family'};
+               
+               print "   Updating family data for: $name\n";
+               
+               # write the family id to the individual's data in tc_indiv
+               $sth = $dbh->prepare("update tc_indiv set family='$family_id' where name=\"$name\""); 
+               $sth->execute or die "-E- DB error: $DBI::errstr\n";
+       } else { $family_id = 0; }
+    }
+}
+
 ######################################################################
 # MAIN
 ######################################################################
@@ -898,13 +674,11 @@ if($opt_s) { $dbh->disconnect(); exit; }
 # Now update the various eq DB tables
 &update_tc_calling_table();
 &update_tc_indiv_table();
-&update_tc_aaronic_table();
 &update_tc_district_table();
 &update_tc_companionship_table();
 &update_tc_family_table();
-&update_tc_parent_table();
-&update_tc_child_table();
 &update_tc_visit_table();
+&update_family_in_tc_indiv_table();
 
 print "\n-> Import Successful! DONE...\n";
 
index 731c51226fb64377f711f1549ed25f49540c4d55..7401ea4310af265a3e47fc659892754c59492637 100755 (executable)
@@ -15,8 +15,8 @@ $dbh=DBI->connect("dbi:mysql:dbname=$dbname:host=$dbhost:port=$dbport",$dbuser,$
     PrintError=>0}) or print "Connect Failure:".$DBI::errstr."\n" and exit 2;
 ###################################################
 
-# Rename eq_aaronic table to tc_aaronic
-$sth = $dbh->prepare("RENAME TABLE `eq_aaronic` TO `tc_aaronic`");
+# Remove eq_aaronic table
+$sth = $dbh->prepare("DROP TABLE `eq_aaronic` IF EXISTS");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
 # Rename eq_activity table to tc_activity
@@ -47,14 +47,18 @@ $sth->execute or die "-E- DB error: $DBI::errstr\n";
 $sth = $dbh->prepare("RENAME TABLE `eq_calling` TO `tc_calling`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Rename eq_child table to tc_child
-$sth = $dbh->prepare("RENAME TABLE `eq_child` TO `tc_child`");
+# Remove eq_child table
+$sth = $dbh->prepare("DROP TABLE `eq_child` IF EXISTS");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
 # Rename eq_companionship table to tc_companionship
 $sth = $dbh->prepare("RENAME TABLE `eq_companionship` TO `tc_companionship`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
+# Remove aaronic field from tc_companionship
+$sth = $dbh->prepare("ALTER TABLE 'tc_companionship' DROP 'aaronic'");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+
 # Change elder field in tc_companionship table to indiv
 $sth = $dbh->prepare("ALTER TABLE `tc_companionship` CHANGE `elder` `indiv` INT(16)");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
@@ -67,14 +71,26 @@ $sth->execute or die "-E- DB error: $DBI::errstr\n";
 $sth = $dbh->prepare("RENAME TABLE `eq_elder` TO `tc_indiv`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Add a new 'propective' field to the tc_indiv table
-$sth = $dbh->prepare("ALTER TABLE `tc_indiv` ADD `prospective` enum('y','n') NULL AFTER `priesthood`");
-$sth->execute or die "-E- DB error: $DBI::errstr\n";
-
 # Change elder field in tc_indiv table to indiv
 $sth = $dbh->prepare("ALTER TABLE `tc_indiv` CHANGE `elder` `indiv` INT(16)");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
+# Add a new 'birthday' column to the tc_indiv table
+$sth = $dbh->prepare("ALTER TABLE `tc_indiv` ADD `birthday` DATE NULL DEFAULT NULL AFTER `name` ");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+
+# Add a new 'address' column to the tc_indiv table
+$sth = $dbh->prepare("ALTER TABLE `tc_indiv` ADD `address` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `birthday`");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+
+# Add a new 'family' column to the tc_indiv table
+$sth = $dbh->prepare("ALTER TABLE `tc_indiv` ADD `family` INT(16) UNSIGNED NULL DEFAULT NULL AFTER `email`");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+
+# Add a new 'family' column to the tc_indiv table
+$sth = $dbh->prepare("ALTER TABLE `tc_indiv` ADD `hh_position` ENUM( 'Head of Household', 'Spouse', 'Other' ) NOT NULL DEFAULT 'Other' AFTER `family`");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+
 # Rename eq_family table to tc_family
 $sth = $dbh->prepare("RENAME TABLE `eq_family` TO `tc_family`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
@@ -83,8 +99,8 @@ $sth->execute or die "-E- DB error: $DBI::errstr\n";
 $sth = $dbh->prepare("ALTER TABLE `tc_family` CHANGE `elder_id` `indiv_id` INT(16)");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
-# Rename eq_parent table to tc_parent
-$sth = $dbh->prepare("RENAME TABLE `eq_parent` TO `tc_parent`");
+# Remove eq_parent table
+$sth = $dbh->prepare("DROP TABLE `eq_parent` IF EXISTS");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
 # Rename eq_participation table to tc_participation
@@ -103,6 +119,10 @@ $sth->execute or die "-E- DB error: $DBI::errstr\n";
 $sth = $dbh->prepare("ALTER TABLE `tc_interview` CHANGE `elder` `indiv` INT(16)");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
+# Remove aaronic field from tc_interview
+$sth = $dbh->prepare("ALTER TABLE 'tc_interview' DROP 'aaronic'");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+
 # Change ppi field in tc_interview table to interview
 $sth = $dbh->prepare("ALTER TABLE `tc_interview` CHANGE `ppi` `interview` INT(16)");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
index c6a32d3b7cf997e837a95453376defe550050f37..543aed895317a4f44ff95ab615e15dceb31fa644 100644 (file)
@@ -220,15 +220,6 @@ class tc
           $indivs[$id] = $indiv_name[$i];
       }      
 
-      $sql = "SELECT * FROM tc_aaronic where valid=1 ORDER BY aaronic ASC";
-      $this->db->query($sql,__LINE__,__FILE__);
-      while ($this->db->next_record())
-       {
-         $aaronic_id = $this->db->f('aaronic');
-         $aaronic[$aaronic_id]['name'] = $this->db->f('name');
-         $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
-       }
-
       $this->nextmatchs->template_alternate_row_color(&$this->t);
       for($m=$num_months; $m >= 0; $m--) { $total_families[$m]=0; }
       for ($i=0; $i < count($districts); $i++) {
@@ -262,15 +253,8 @@ class tc
              if($companion_table_entry != "") { $companion_table_entry .= "<td>&nbsp;/&nbsp;</td>"; }
              $companionship = $this->db->f('companionship');
              $indiv_id = $this->db->f('indiv');
-             $aaronic_id = $this->db->f('aaronic');
-             if($indiv_id) {
-               $name = $indivs[$indiv_id];
-               $phone = $indiv_phone[$indiv_id];
-             }
-             else if($aaronic_id) {
-               $name = $aaronic[$aaronic_id]['name'];
-               $phone = $aaronic[$aaronic_id]['phone'];                
-             }
+             $name = $indivs[$indiv_id];
+             $phone = $indiv_phone[$indiv_id];
              $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
            }
          $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
@@ -472,15 +456,6 @@ class tc
           $indivs[$id] = $indiv_name[$i];
       }      
 
-      $sql = "SELECT * FROM tc_aaronic where valid=1 ORDER BY aaronic ASC";
-      $this->db->query($sql,__LINE__,__FILE__);
-      while ($this->db->next_record())
-       {
-         $aaronic_id = $this->db->f('aaronic');
-         $aaronic[$aaronic_id]['name'] = $this->db->f('name');
-         $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
-       }
-      
       // Select all the unique companionship numbers for this district
       $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $district;
       $this->db->query($sql,__LINE__,__FILE__);
@@ -506,15 +481,8 @@ class tc
            if($companion_table_entry != "") { $companion_table_entry .= "<td>&nbsp;/&nbsp;</td>"; }
            $companionship = $this->db->f('companionship');
            $indiv_id = $this->db->f('indiv');
-           $aaronic_id = $this->db->f('aaronic');
-           if($indiv_id) {
-             $name = $indivs[$indiv_id];
-             $phone = $indiv_phone[$indiv_id];
-           }
-           else if($aaronic_id) {
-             $name = $aaronic[$aaronic_id]['name'];
-             $phone = $aaronic[$aaronic_id]['phone'];
-           }
+           $name = $indivs[$indiv_id];
+           $phone = $indiv_phone[$indiv_id];
            $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
          }
        $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
@@ -1429,7 +1397,7 @@ class tc
        if($this->db2->next_record()) {
          $indiv_id = $this->db2->f('indiv_id');
        }
-       $sql = "SELECT * FROM tc_parent where indiv_id='$indiv_id'";
+       $sql = "SELECT * FROM tc_indiv where indiv_id='$indiv_id'";
        $this->db2->query($sql,__LINE__,__FILE__);
        if($this->db2->next_record()) {
          $president_address = $this->db2->f('address');
@@ -1763,7 +1731,7 @@ class tc
                  if($this->db2->next_record()) {
                    $indiv_id = $this->db2->f('indiv_id');
                  }
-                 $sql = "SELECT * FROM tc_parent where indiv_id='$indiv_id'";
+                 $sql = "SELECT * FROM tc_indiv where indiv_id='$indiv_id'";
                  $this->db2->query($sql,__LINE__,__FILE__);
                  if($this->db2->next_record()) {
                    $supervisor_address = $this->db2->f('address');
@@ -1797,15 +1765,12 @@ class tc
             $indiv_id = $entry['indiv_id'];
             $indiv_name = $entry['indiv_name'];
             $int_pri = $entry['pri'];
-            $aaronic = $entry['aaronic'];
-            //print "int_notes: $int_notes indiv_name: $indiv_name aaronic: $aaronic <Br>";
-            if($aaronic == 0) { 
-              // Perform database save actions here
-              $this->db->query("UPDATE tc_indiv set " .
-                               " int_notes='" . $int_notes . "'" .
-                               ",int_pri='" . $int_pri . "'" .
-                               " WHERE indiv=" . $indiv_id,__LINE__,__FILE__);
-            } 
+            //print "int_notes: $int_notes indiv_name: $indiv_name <Br>";
+            // Perform database save actions here
+            $this->db->query("UPDATE tc_indiv set " .
+                             " int_notes='" . $int_notes . "'" .
+                             ",int_pri='" . $int_pri . "'" .
+                             " WHERE indiv=" . $indiv_id,__LINE__,__FILE__);
             
           }
 
@@ -1856,7 +1821,7 @@ class tc
       if($this->db2->next_record()) {
        $indiv_id = $this->db2->f('indiv_id');
       }
-      $sql = "SELECT * FROM tc_parent where indiv_id='$indiv_id'";
+      $sql = "SELECT * FROM tc_indiv where indiv_id='$indiv_id'";
       $this->db2->query($sql,__LINE__,__FILE__);
       if($this->db2->next_record()) {
        $supervisor_address = $this->db2->f('address');
@@ -1942,37 +1907,20 @@ class tc
            {         
              // Get this companions information
              $indiv_id = $this->db->f('indiv');
-             $aaronic_id = $this->db->f('aaronic');
             
              $sql = "SELECT * FROM tc_indiv where indiv=$indiv_id";
              $this->db2->query($sql,__LINE__,__FILE__);        
-             if($this->db2->next_record())
-               {
-                 $indiv_id = $this->db2->f('indiv');
-                 $indiv_name = $this->db2->f('name');
-                 $indiv_phone[$indiv_id] = $this->db2->f('phone');
-                 $indiv_int_pri[$indiv_id] = $this->db2->f('int_pri');
-                 $indiv_int_notes[$indiv_id] = $this->db2->f('int_notes');
-                 $indiv_aaronic = 0;
-               }
-             else {
-               $sql = "SELECT * FROM tc_aaronic where aaronic=$aaronic_id";
-               $this->db2->query($sql,__LINE__,__FILE__);
-               if($this->db2->next_record())
-                 {
-                   $indiv_id = $this->db2->f('aaronic');
-                   $indiv_name = $this->db2->f('name');
-                   $indiv_phone[$indiv_id] = $this->db2->f('phone');
-                   $indiv_aaronic = 1;
-                 }
-             }
+             $indiv_id = $this->db2->f('indiv');
+             $indiv_name = $this->db2->f('name');
+             $indiv_phone[$indiv_id] = $this->db2->f('phone');
+             $indiv_int_pri[$indiv_id] = $this->db2->f('int_pri');
+             $indiv_int_notes[$indiv_id] = $this->db2->f('int_notes');
 
              $id = $indiv_id;
              $name = $indiv_name;
              $phone = $indiv_phone[$id];
              $int_pri = $indiv_int_pri[$id];
              $int_notes = $indiv_int_notes[$id];
-             $aaronic = $indiv_aaronic;
              
              // If the companionship has already had its quarterly interview,
              // Skip the other companion in the companionship.
@@ -2000,7 +1948,6 @@ class tc
                if($this->db3->next_record()) { $date = $this->db3->f('date'); } else { $date = ""; }
                $link_data['menuaction'] = 'tc.tc.int_update';
                $link_data['indiv'] = $id;
-               $link_data['aaronic'] = 0;
                $link_data['name'] = $name;
                $link_data['interview'] = '';
                $link_data['action'] = 'add';
@@ -2009,22 +1956,17 @@ class tc
                $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
                $table_data.= "<td align=center>$phone</td>";
                $table_data.= "<td align=center>";
-               if($aaronic == 0) { 
-                 $table_data.= '<select name=int_notes['.$i.'][pri]>';
-                 foreach(range(0,6) as $num) {
-                   if($num == 0) { $num = 1; } else {$num = $num*5; }
-                   if($int_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
-                   $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
-                 }
-                 $table_data.= '</select></td>';
+               $table_data.= '<select name=int_notes['.$i.'][pri]>';
+               foreach(range(0,6) as $num) {
+                 if($num == 0) { $num = 1; } else {$num = $num*5; }
+                 if($int_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
+                 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
                }
+                 $table_data.= '</select></td>';
                $table_data.= "<td align=center>$date</td>";
-               if($aaronic == 0) { 
-                 $table_data.= '<td><input type=text size="50" maxlength="128" name="int_notes['.$i.'][notes]" value="'.$int_notes.'">';
-               }
+               $table_data.= '<td><input type=text size="50" maxlength="128" name="int_notes['.$i.'][notes]" value="'.$int_notes.'">';
                $table_data.= '<input type=hidden name="int_notes['.$i.'][indiv_id]" value="'.$id.'">';
                $table_data.= '<input type=hidden name="int_notes['.$i.'][indiv_name]" value="'.$name.'">';
-               $table_data.= '<input type=hidden name="int_notes['.$i.'][aaronic]" value="'.$aaronic.'">';
                $table_data.= '</td>';
                $table_data.= '</tr>'."\n";
                $i++;
@@ -2032,7 +1974,6 @@ class tc
                $link_data['menuaction'] = 'tc.tc.int_update';
                $link_data['interviewer'] = $this->db2->f('interviewer');
                $link_data['indiv'] = $this->db2->f('indiv');
-               $link_data['aaronic'] = $this->db2->f('aaronic');
                $link_data['name'] = $name;
                $link_data['interview'] = $this->db2->f('interview');
                $link_data['action'] = 'view';
@@ -2133,7 +2074,7 @@ class tc
          $family_id[$i] = $this->db->f('family');
          $family_name[$i] = $this->db->f('name');
          $familyid2name[$family_id[$i]] = $family_name[$i];
-         $sql = "SELECT * FROM tc_parent where family='$family_id[$i]'";
+         $sql = "SELECT * FROM tc_indiv where family='$family_id[$i]'";
          $this->db2->query($sql,__LINE__,__FILE__);
          if($this->db2->next_record()) {
            $familyid2address[$family_id[$i]] = $this->db2->f('address');
@@ -2290,7 +2231,7 @@ class tc
          $total_families++;
        }
 
-      $sql = "SELECT * FROM tc_parent where valid=1";
+      $sql = "SELECT * FROM tc_indiv where valid=1";
       $this->db->query($sql,__LINE__,__FILE__);
       while ($this->db->next_record())
        {
@@ -2549,7 +2490,6 @@ class tc
       $name = get_var('name',array('GET','POST'));
       $interview = get_var('interview',array('GET','POST'));
       $indiv = get_var('indiv',array('GET','POST'));
-      $aaronic = get_var('aaronic',array('GET','POST'));
       $date = get_var('date',array('GET','POST'));
       $notes = get_var('notes',array('GET','POST'));
       $interview_type = get_var('interview_type',array('GET','POST'));
@@ -2577,7 +2517,6 @@ class tc
                     "   interview='" . $interview . "'" .
                    ", interviewer='" . $interviewer . "'" .
                          ", indiv='" . $indiv . "'" .
-                       ", aaronic='" . $aaronic . "'" .
                           ", date='" . $date . "'" .
                          ", notes='" . $notes . "'" .
                 ", interview_type='" . $interview_type . "'" .
@@ -2589,8 +2528,8 @@ class tc
       if($action == 'insert')
        {
          $notes = get_var('notes',array('POST'));
-         $this->db->query("INSERT INTO tc_interview (interviewer,indiv,aaronic,date,notes,interview_type) "
-                          . "VALUES ('" . $interviewer . "','" . $indiv . "','" . $aaronic . "','"
+         $this->db->query("INSERT INTO tc_interview (interviewer,indiv,date,notes,interview_type) "
+                          . "VALUES ('" . $interviewer . "','" . $indiv . "','"
                           . $date . "','" . $notes . "','" . $interview_type  ."')",__LINE__,__FILE__);
          $this->ppi_view();
          return false;
@@ -2719,15 +2658,6 @@ class tc
           $indivs[$id] = $indiv_name[$i];
       }      
 
-      $sql = "SELECT * FROM tc_aaronic where valid=1 ORDER BY aaronic ASC";
-      $this->db->query($sql,__LINE__,__FILE__);
-      while ($this->db->next_record())
-       {
-         $aaronic_id = $this->db->f('aaronic');
-         $aaronic[$aaronic_id]['name'] = $this->db->f('name');
-         $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
-       }
-      
       $total_companionships = 0;
       $this->nextmatchs->template_alternate_row_color(&$this->t);
       for ($i=0; $i < count($districts); $i++) {
@@ -2762,20 +2692,12 @@ class tc
              $num_indivs++;
              $companionship = $this->db->f('companionship');
              $indiv_id = $this->db->f('indiv');
-             $aaronic_id = $this->db->f('aaronic');
-             if($indiv_id) {
-               $name = $indivs[$indiv_id];
-               $phone = $indiv_phone[$indiv_id];
-             }
-             else if($aaronic_id) {
-               $name = $aaronic[$aaronic_id]['name'];
-               $phone = $aaronic[$aaronic_id]['phone'];
-             }
+             $name = $indivs[$indiv_id];
+             $phone = $indiv_phone[$indiv_id];
              $link_data['menuaction'] = 'tc.tc.int_update';
              $link_data['companionship'] = $companionship;
              $link_data['interviewer'] = $supervisor;
              $link_data['indiv'] = $indiv_id;
-             $link_data['aaronic'] = $aaronic_id;
              $link_data['name'] = $name;
              $link_data['interview'] = '';
              $link_data['action'] = 'add';
@@ -2793,7 +2715,7 @@ class tc
                $month_end = "$year"."-"."$month"."-"."31";
                $month = "$month"."/"."$year";
                $sql = "SELECT * FROM tc_interview WHERE date >= '$month_start' AND date <= '$month_end' ".
-                  "AND indiv=" . $indiv_id . " AND aaronic=" . $aaronic_id;
+                  "AND indiv=" . $indiv_id;
                $this->db2->query($sql,__LINE__,__FILE__);
                $header_row .= "<th width=$int_width><font size=-2>$month</th>";
              
@@ -2806,7 +2728,6 @@ class tc
                  $link_data['companionship'] = $companionship;
                  $link_data['interviewer'] = $this->db2->f('interviewer');
                  $link_data['indiv'] = $indiv_id;
-                 $link_data['aaronic'] = $aaronic_id;
                  $link_data['name'] = $name;
                  $link_data['interview'] = $this->db2->f('interview');
                  $link_data['action'] = 'view';
@@ -2886,7 +2807,6 @@ class tc
       $name = get_var('name',array('GET','POST'));
       $interview = get_var('interview',array('GET','POST'));
       $indiv = get_var('indiv',array('GET','POST'));
-      $aaronic = get_var('aaronic',array('GET','POST'));
       $date = get_var('date',array('GET','POST'));
       $notes = get_var('notes',array('GET','POST'));
       $interview_type = get_var('interview_type',array('GET','POST'));
@@ -2913,7 +2833,6 @@ class tc
                     "   interview='" . $interview . "'" .
                    ", interviewer='" . $interviewer . "'" .
                          ", indiv='" . $indiv . "'" .
-                       ", aaronic='" . $aaronic . "'" .
                           ", date='" . $date . "'" .
                          ", notes='" . $notes . "'" .
                 ", interview_type='" . $interview_type . "'" .
@@ -2925,8 +2844,8 @@ class tc
       if($action == 'insert')
        {
          $notes = get_var('notes',array('POST'));
-         $this->db->query("INSERT INTO tc_interview (interviewer,indiv,aaronic,date,notes,interview_type) "
-                          . "VALUES ('" . $interviewer . "','" . $indiv . "','" . $aaronic . "','"
+         $this->db->query("INSERT INTO tc_interview (interviewer,indiv,date,notes,interview_type) "
+                          . "VALUES ('" . $interviewer . "','" . $indiv . "','"
                           . $date . "','" . $notes ."','" . $interview_type . "')",__LINE__,__FILE__);
          $this->int_view();
          return false;
@@ -2939,7 +2858,6 @@ class tc
          $this->t->set_var('interviewer', $interviewer);
          $this->t->set_var('name',$name);
          $this->t->set_var('indiv',$indiv);
-         $this->t->set_var('aaronic',$aaronic);
          $this->t->set_var('date','');
          $this->t->set_var('notes','');
          $this->t->set_var('lang_done','Cancel');
@@ -2957,7 +2875,6 @@ class tc
          $this->t->set_var('name',$name);
          $this->t->set_var('interviewer', $this->db->f('interviewer'));
          $this->t->set_var('indiv',$this->db->f('indiv'));
-         $this->t->set_var('aaronic',$this->db->f('aaronic'));
          $this->t->set_var('date',$this->db->f('date'));
          $this->t->set_var('notes',$this->db->f('notes'));
          if($this->db->f('interview_type') == 1) { $this->t->set_var('interview_type_checked','checked'); }
@@ -3534,12 +3451,12 @@ class tc
       $this->t->set_file(array('dir_view_t' => 'dir_view.tpl'));
       $this->t->set_block('dir_view_t','dir_list','list');
       
-      $sql = "SELECT * FROM tc_parent where valid=1 ORDER BY name ASC";
+      $sql = "SELECT * FROM tc_indiv where valid=1 and hh_position='Head of Household' ORDER BY name ASC";
       $this->db->query($sql,__LINE__,__FILE__);
       $i=0;
       while ($this->db->next_record())
        {
-         $parent[$i]['id'] = $this->db->f('parent');
+         $parent[$i]['id'] = $this->db->f('indiv');
          $parent[$i]['name'] = $this->db->f('name');
          $parent[$i]['phone'] = $this->db->f('phone');
          $parent[$i]['address'] = $this->db->f('address');
@@ -3681,7 +3598,7 @@ class tc
          $family_id[$i] = $this->db->f('family');
          $family_name[$i] = $this->db->f('name');
          $familyid2name[$family_id[$i]] = $family_name[$i];
-         $sql = "SELECT * FROM tc_parent where family='$family_id[$i]'";
+         $sql = "SELECT * FROM tc_indiv where family='$family_id[$i]' and hh_position='Head of Household'";
          $this->db2->query($sql,__LINE__,__FILE__);
          if($this->db2->next_record()) {
            $familyid2address[$family_id[$i]] = $this->db2->f('address');
@@ -3727,7 +3644,7 @@ class tc
                     if($this->db2->next_record()) {
                       $indiv_id = $this->db2->f('indiv_id');
                     }
-                    $sql = "SELECT * FROM tc_parent where indiv_id='$indiv_id'";
+                    $sql = "SELECT * FROM tc_indiv where indiv_id='$indiv_id'";
                     $this->db2->query($sql,__LINE__,__FILE__);
                     if($this->db2->next_record()) {
                       $supervisor_address = $this->db2->f('address');
@@ -3854,7 +3771,7 @@ class tc
                if($this->db2->next_record()) {
                  $indiv_id = $this->db2->f('indiv_id');
                }
-               $sql = "SELECT * FROM tc_parent where indiv_id='$indiv_id'";
+               $sql = "SELECT * FROM tc_indiv where indiv_id='$indiv_id'";
                $this->db2->query($sql,__LINE__,__FILE__);
                if($this->db2->next_record()) {
                  $supervisor_address = $this->db2->f('address');
index 8435656f5f7042ad06d6fdc4b7f645272192e714..e6059e5252bb6b01294d3d6164128d9f4f9a0f62 100644 (file)
@@ -7,11 +7,11 @@ digraph schema {
     shape = "record"
   ];
   indiv   [
-    label = "<i> indiv||<id> indiv_id|<n> name|<p> phone|<em> email|<po> priesthood|<pr> prospective|<pp> ppi_pri|<t> ppi_notes|<ip> int_pri|<in> int_notes|<a> attending|<v> valid"
+    label = "<i> indiv||<id> indiv_id|<n> name|<b> birthday|<a> address|<p> phone|<em> email|<f> family|<hh> hh position|<po> priesthood|<pr> prospective|<pp> ppi_pri|<t> ppi_notes|<ip> int_pri|<in> int_notes|<a> attending|<v> valid"
     shape = "record"
   ];
   companionship   [
-    label = "<c> companionship||<i> indiv|<a> aaronic|<d> district|<v> valid"
+    label = "<c> companionship||<i> indiv|<d> district|<v> valid"
     shape = "record"
   ];
   visit   [
@@ -19,7 +19,7 @@ digraph schema {
     shape = "record"
   ];
   interview   [
-    label = "<in> interview||<i> interviewer|<il> indiv|<a> aaronic|<t> date|<n> notes|<it> interview_type"
+    label = "<in> interview||<i> interviewer|<il> indiv|<t> date|<n> notes|<it> interview_type"
     shape = "record"
   ];
   activity   [
@@ -34,18 +34,6 @@ digraph schema {
     label = "attendance||<i> indiv|<d> date"
     shape = "record"
   ];
-  child        [
-    label = "<c> child||<f> family|<n> name|<b> birthday|<i> indiv_id|<v> valid"
-    shape = "record"
-  ]; 
-  parent       [
-    label = "<p> parent||<f> family|<n> name|<b> birthday|<p> phone|<a> address|<i>indiv_id|<v> valid"
-    shape = "record"
-  ]; 
-  aaronic       [
-    label = "<a> aaronic||<n> name|<p> phone|<em> email|<v> valid"
-    shape = "record"
-  ];
   appointment   [
     label = "<a> appointment||<p> presidency|<f> family|<i> indiv |<d> date|<t> time|<l> location|<u> uid"
     shape = "record"
@@ -73,14 +61,12 @@ digraph schema {
 
   family:c        -> companionship:c
   companionship:i -> indiv:i
-  companionship:a -> aaronic:a
 
   appointment:i   -> indiv:i
   appointment:f   -> family:f
 
   interview:il    -> indiv:i
   interview:i     -> indiv:i
-  interview:a     -> aaronic:a
 
   presidency:i    -> indiv:i
   presidency:d    -> district:d
@@ -100,6 +86,5 @@ digraph schema {
 
   attendance:i    -> indiv:i
 
-  child:f         -> family:f
-  parent:f        -> family:f
+  indiv:f        -> family:f
 }
index 4a398e5f45dce3ff1407476994ab4843efbaffbb..8244f5e181814ff29b946dea00dceaa26cdaf8d9 100644 (file)
Binary files a/sql/tc.jpg and b/sql/tc.jpg differ
index 8cbfdb2ea954cf0eedcb6b7c3d04730dbc5a0ab5..ab47ccedc66bd29f8dae0908a65db2d29276e647 100644 (file)
@@ -11,19 +11,6 @@ CREATE DATABASE /*!32312 IF NOT EXISTS*/ `phpgroupware` /*!40100 DEFAULT CHARACT
 
 USE `phpgroupware`;
 
---
--- Table structure for table `tc_aaronic`
---
-CREATE TABLE `tc_aaronic` (
-  `aaronic` int(16) unsigned NOT NULL auto_increment,
-  `name` varchar(60) default NULL,
-  `phone` varchar(12) default NULL,
-  `email` varchar(120) default NULL,
-  `valid` tinyint(1) default NULL,
-  PRIMARY KEY  (`aaronic`)
-) ENGINE=MyISAM AUTO_INCREMENT=92 DEFAULT CHARSET=latin1;
-
-
 --
 -- Table structure for table `tc_activity`
 --
@@ -92,19 +79,6 @@ CREATE TABLE `tc_calling` (
   KEY `indiv_id` (`indiv_id`)
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
 
---
--- Table structure for table `tc_child`
---
-CREATE TABLE `tc_child` (
-  `child` int(16) unsigned NOT NULL auto_increment,
-  `family` int(16) unsigned default NULL,
-  `name` varchar(30) default NULL,
-  `birthday` date default NULL,
-  `indiv_id` int(16) unsigned default NULL,
-  `valid` tinyint(1) default NULL,
-  PRIMARY KEY  (`child`)
-) ENGINE=MyISAM AUTO_INCREMENT=260 DEFAULT CHARSET=latin1;
-
 --
 -- Table structure for table `tc_companionship`
 --
@@ -112,7 +86,6 @@ CREATE TABLE `tc_child` (
 CREATE TABLE `tc_companionship` (
   `companionship` int(16) unsigned NOT NULL default '0',
   `indiv` int(16) unsigned NOT NULL default '0',
-  `aaronic` int(16) unsigned NOT NULL default '0',
   `district` int(16) unsigned default NULL,
   `valid` tinyint(1) default NULL,
   KEY `companionship` (`companionship`)
@@ -136,10 +109,13 @@ CREATE TABLE `tc_indiv` (
   `indiv` int(16) unsigned NOT NULL auto_increment,
   `indiv_id` int(16) unsigned NOT NULL,
   `name` varchar(60) default NULL,
+  `birthday` date default NULL,
+  `address` varchar(255) default NULL,
   `phone` varchar(12) default NULL,
   `email` varchar(120) default NULL,
+  `family` int(16) unsigned default NULL,
+  `hh_position` enum('Head of Household','Spouse','Other') DEFAULT 'Other',
   `priesthood` enum('High Priest','Elder','Priest','Teacher','Deacon','Unordained') DEFAULT NULL,
-  `prospective` enum('y','n') DEFAULT 'n',
   `ppi_pri` int(10) unsigned NOT NULL default '1',
   `ppi_notes` varchar(128) default NULL,
   `int_pri` int(10) unsigned default '1',
@@ -165,21 +141,6 @@ CREATE TABLE `tc_family` (
   PRIMARY KEY  (`family`)
 ) ENGINE=MyISAM AUTO_INCREMENT=277 DEFAULT CHARSET=latin1;
 
---
--- Table structure for table `tc_parent`
---
-CREATE TABLE `tc_parent` (
-  `parent` int(16) unsigned NOT NULL auto_increment,
-  `family` int(16) unsigned default NULL,
-  `name` varchar(30) default NULL,
-  `birthday` date default NULL,
-  `phone` varchar(12) default NULL,
-  `address` varchar(255) default NULL,
-  `indiv_id` int(16) unsigned default NULL,
-  `valid` tinyint(1) default NULL,
-  PRIMARY KEY  (`parent`)
-) ENGINE=MyISAM AUTO_INCREMENT=396 DEFAULT CHARSET=latin1;
-
 --
 -- Table structure for table `tc_participation`
 --
@@ -196,7 +157,6 @@ CREATE TABLE `tc_interview` (
   `interview` int(16) unsigned NOT NULL auto_increment,
   `interviewer` int(16) unsigned default NULL,
   `indiv` int(16) unsigned default NULL,
-  `aaronic` int(16) unsigned NOT NULL default '0',
   `date` date default NULL,
   `notes` text,
   `interview_type` enum('hti','ppi') NOT NULL DEFAULT 'hti',
index 1613f7516e96a6305ad3b2c11a038931372bbb2b..2f846fad90f6369c130bf38f06d599bf8dda6bf0 100644 (file)
@@ -4,7 +4,6 @@
        <form action="{actionurl}" method="POST">
        <input type=hidden name=interviewer value={interviewer}>
        <input type=hidden name=indiv value={indiv}>
-       <input type=hidden name=aaronic value={aaronic}>
        <input type=hidden name=companionship value={companionship}>
        <table border="0" width="60%" cellspacing="2" cellpadding="2">
                <tr>
index e83394f6d6e756e43e2fc84c339e31ee9aea79cf..70469b85b55cf8ee1ddbc2496a304b149886f705 100644 (file)
@@ -4,7 +4,6 @@
        <form action="{actionurl}" method="POST">
        <input type=hidden name=interviewer value={interviewer}>
        <input type=hidden name=indiv value={indiv}>
-       <input type=hidden name=aaronic value={aaronic}>
        <input type=hidden name=companionship value={companionship}>
        <table border="0" width="60%" cellspacing="2" cellpadding="2">
                <tr>