+
+ return $found_problem;
+}
+
+sub update_family_in_tc_individual_table
+{
+ print "\n-> Updating family info in tc_individual 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_individual
+ $sth = $dbh->prepare("update tc_individual set family='$family_id' where name=\"$name\"");
+ $sth->execute or die "-E- DB error: $DBI::errstr\n";
+ } else {
+ $family_id = 0;
+ }
+ }
+}
+
+sub update_organization_class_data
+{
+ print "\n-> Updating organization class info in tc_individual table\n";
+
+ foreach $index (keys %organization_class_data)
+ {
+ # get name and organization info for each individual
+ $name = $organization_class_data{$index}{'Preferred Name'};
+ $org_class = $organization_class_data{$index}{'Organization Class'};
+
+ if ($org_class =~ m/Elder/i) {
+ #print " $name: Elder\n";
+ $sth = $dbh->prepare("update tc_individual set steward='Elder' where name=\"$name\"");
+ $sth->execute or die "-E- DB error: $DBI::errstr\n";
+ }
+ if ($org_class =~ m/High Priest/i) {
+ #print " $name: High Priest\n";
+ $sth = $dbh->prepare("update tc_individual set steward='High Priest' where name=\"$name\"");
+ $sth->execute or die "-E- DB error: $DBI::errstr\n";
+ }
+ }
+}
+
+sub update_tc_scheduling_priority_table
+{
+ print "\n-> Updating scheduling priority table\n";
+
+ # individuals
+ # TODO: make steward flexible with a setting in the config file
+ $sth = $dbh->prepare("select * from tc_individual where steward='Elder' and valid=1");
+ $sth->execute or die "-E- DB error: $DBI::errstr\n";
+ while($sqlhashref = $sth->fetchrow_hashref) {
+ $individual = $sqlhashref->{individual};
+ $scheduling_priority = $sqlhashref->{scheduling_priority};
+ if ($scheduling_priority == 'NULL')
+ {
+ $sth2 = $dbh->prepare("insert into tc_scheduling_priority values (NULL, 30, '')");
+ $sth2->execute or die "-E- DB error: $DBI::errstr\n";
+ $scheduling_priority = $dbh->last_insert_id(NULL,NULL,'tc_scheduling_priority',NULL);
+ $sth2 = $dbh->prepare("update tc_individual set scheduling_priority=$scheduling_priority where individual=$individual");
+ $sth2->execute or die "-E- DB error: $DBI::errstr\n";
+ }
+ }
+
+ # families
+ # TODO: make steward flexible with a setting in the config file
+ $sth = $dbh->prepare("select tf.scheduling_priority, tf.family from tc_family AS tf JOIN tc_individual AS ti ON tf.individual=ti.individual and ti.steward='Elder' and tf.valid=1");
+ $sth->execute or die "-E- DB error: $DBI::errstr\n";
+ while($sqlhashref = $sth->fetchrow_hashref) {
+ $family = $sqlhashref->{family};
+ $scheduling_priority = $sqlhashref->{scheduling_priority};
+ #print "$family $scheduling_priority\n";
+ if ($scheduling_priority == 'NULL')
+ {
+ $sth2 = $dbh->prepare("insert into tc_scheduling_priority values (NULL, 30, '')");
+ $sth2->execute or die "-E- DB error: $DBI::errstr\n";
+ $scheduling_priority = $dbh->last_insert_id(NULL,NULL,'tc_scheduling_priority',NULL);
+ $sth2 = $dbh->prepare("update tc_family set scheduling_priority=$scheduling_priority where family=$family");
+ $sth2->execute or die "-E- DB error: $DBI::errstr\n";
+ }
+ }
+
+ # companionships
+ # TODO: make steward flexible with a setting in the config file
+ $sth = $dbh->prepare("select tc.individual, tc.scheduling_priority from tc_companionship AS tc JOIN tc_individual AS ti ON tc.individual=ti.individual and (ti.steward='Elder' or ti.steward='') and tc.valid=1");
+ $sth->execute or die "-E- DB error: $DBI::errstr\n";
+ while($sqlhashref = $sth->fetchrow_hashref) {
+ $individual = $sqlhashref->{individual};
+ $scheduling_priority = $sqlhashref->{scheduling_priority};
+ #print "$individual $scheduling_priority\n";
+ if ($scheduling_priority == 'NULL')
+ {
+ $sth2 = $dbh->prepare("insert into tc_scheduling_priority values (NULL, 30, '')");
+ $sth2->execute or die "-E- DB error: $DBI::errstr\n";
+ $scheduling_priority = $dbh->last_insert_id(NULL,NULL,'tc_scheduling_priority',NULL);
+ $sth2 = $dbh->prepare("update tc_companionship set scheduling_priority=$scheduling_priority where individual=$individual");
+ $sth2->execute or die "-E- DB error: $DBI::errstr\n";
+ }
+ }
+