+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";
+ }
+ }
+
+}
+