From: Owen Leonard Date: Sun, 12 Sep 2010 07:13:07 +0000 (-0600) Subject: removed tc_parent, tc_child, and tc_aaronic tables, moved required info into tc_indiv... X-Git-Tag: release_1_0_0~55 X-Git-Url: http://git.pippins.net/embedvideo/.git/static/%22%22.%24thumbnail.%22/%7Bdone_action%7D?a=commitdiff_plain;h=80739f4c39deff0ff28e20be40871a30eb58664a;p=eq%2F.git removed tc_parent, tc_child, and tc_aaronic tables, moved required info into tc_indiv and linked tc_indiv to tc_family --- diff --git a/bin/import_ward_data b/bin/import_ward_data index 21a5a36..97823c4 100755 --- a/bin/import_ward_data +++ b/bin/import_ward_data @@ -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"; diff --git a/bin/upgrade_4_0_to_5_0 b/bin/upgrade_4_0_to_5_0 index 731c512..7401ea4 100755 --- a/bin/upgrade_4_0_to_5_0 +++ b/bin/upgrade_4_0_to_5_0 @@ -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"; diff --git a/inc/class.tc.inc.php b/inc/class.tc.inc.php index c6a32d3..543aed8 100644 --- a/inc/class.tc.inc.php +++ b/inc/class.tc.inc.php @@ -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 .= " / "; } $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 .= "$name"; } $table_data.= "$companion_table_entry

"; @@ -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 .= " / "; } $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 .= "$name"; } $table_data.= "$companion_table_entry

"; @@ -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
"; - 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
"; + // 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.= "$name"; $table_data.= "$phone"; $table_data.= ""; - if($aaronic == 0) { - $table_data.= ''; + $table_data.= ''; $table_data.= "$date"; - if($aaronic == 0) { - $table_data.= ''; - } + $table_data.= ''; $table_data.= ''; $table_data.= ''; - $table_data.= ''; $table_data.= ''; $table_data.= ''."\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 .= "$month"; @@ -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'); diff --git a/sql/schema.dot b/sql/schema.dot index 8435656..e6059e5 100644 --- a/sql/schema.dot +++ b/sql/schema.dot @@ -7,11 +7,11 @@ digraph schema { shape = "record" ]; indiv [ - label = " indiv|| indiv_id| name|

phone| email| priesthood| prospective| ppi_pri| ppi_notes| int_pri| int_notes| attending| valid" + label = " indiv|| indiv_id| name| birthday| address|

phone| email| family| hh position| priesthood| prospective| ppi_pri| ppi_notes| int_pri| int_notes| attending| valid" shape = "record" ]; companionship [ - label = " companionship|| indiv| aaronic| district| valid" + label = " companionship|| indiv| district| valid" shape = "record" ]; visit [ @@ -19,7 +19,7 @@ digraph schema { shape = "record" ]; interview [ - label = " interview|| interviewer| indiv| aaronic| date| notes| interview_type" + label = " interview|| interviewer| indiv| date| notes| interview_type" shape = "record" ]; activity [ @@ -34,18 +34,6 @@ digraph schema { label = "attendance|| indiv| date" shape = "record" ]; - child [ - label = " child|| family| name| birthday| indiv_id| valid" - shape = "record" - ]; - parent [ - label = "

parent|| family| name| birthday|

phone| address|indiv_id| valid" - shape = "record" - ]; - aaronic [ - label = " aaronic|| name|

phone| email| valid" - shape = "record" - ]; appointment [ label = " appointment||

presidency| family| indiv | date| time| location| 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 } diff --git a/sql/tc.jpg b/sql/tc.jpg index 4a398e5..8244f5e 100644 Binary files a/sql/tc.jpg and b/sql/tc.jpg differ diff --git a/sql/tc.sql b/sql/tc.sql index 8cbfdb2..ab47cce 100644 --- a/sql/tc.sql +++ b/sql/tc.sql @@ -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', diff --git a/templates/default/int_update.tpl b/templates/default/int_update.tpl index 1613f75..2f846fa 100644 --- a/templates/default/int_update.tpl +++ b/templates/default/int_update.tpl @@ -4,7 +4,6 @@

- diff --git a/templates/default/ppi_update.tpl b/templates/default/ppi_update.tpl index e83394f..70469b8 100644 --- a/templates/default/ppi_update.tpl +++ b/templates/default/ppi_update.tpl @@ -4,7 +4,6 @@ -