#+------------+------------------+------+-----+---------+-------+
#| elder | int(16) unsigned | | PRI | 0 | A |
#| name | varchar(60) | YES | | NULL | |
+#| phone | varchar(12) | YES | | NULL | |
#| valid | tinyint(1) | YES | | NULL | |
#+------------+------------------+------+-----+---------+-------+
sub update_eq_elder_table
foreach $key (keys %$hashref) {
if($key =~ /Priesthood/i && $membership_data{$index}{$key} =~ /Elder/i) {
$elder_name = $membership_data{$index}{'Preferred Name'};
+ $phone = $membership_data{$index}{'Phone 1'};
+ if($phone =~ /(\d\d\d-\d\d\d\d)/) { $phone = "970-$1"; }
+ if($phone =~ /^\(\d\d\d\) (\d\d\d-\d\d\d\d)/) { $phone = "$1-$2"; }
$sth = $dbh->prepare("select * from eq_elder where name='$elder_name'");
$sth->execute or die "-E- DB error: $DBI::errstr\n";
my @data = ();
if($rows == 0) {
# No existing records found for this elder, make a new entry
print " Adding new Elder: $elder_name\n";
- $sth = $dbh->prepare("insert into eq_elder values (NULL,'$elder_name',1)");
+ $sth = $dbh->prepare("insert into eq_elder values (NULL,'$elder_name','$phone',1)");
$sth->execute or die "-E- DB error: $DBI::errstr\n";
} elsif($rows == 1) {
# An existing record was found for this elder, update it
print " Updating existing Elder: $elder_name\n";
$sth = $dbh->prepare("update eq_elder set valid=1 where name='$elder_name'");
$sth->execute or die "-E- DB error: $DBI::errstr\n";
+ if($phone ne "") {
+ $sth = $dbh->prepare("update eq_elder set phone='$phone' where name='$elder_name'");
+ } else {
+ $sth = $dbh->prepare("update eq_elder set phone=NULL where name='$elder_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 Elder: $elder_name\n";
{
$elder_id[$i] = $this->db->f('elder');
$elder_name[$i] = $this->db->f('name');
+ $elder_phone[$elder_id[$i]] = $this->db->f('phone');
$i++;
}
array_multisort($elder_name, $elder_id);
while ($this->db->next_record())
{
// Get this companions information
- if($companion_table_entry != "") { $companion_table_entry .= " / "; }
+ if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
$companionship = $this->db->f('companionship');
$elder_id = $this->db->f('elder');
$aaronic_id = $this->db->f('aaronic');
+ $phone = $elder_phone[$elder_id];
if($elder_id) { $name = $elders[$elder_id]; }
else if($aaronic_id) { $name = $aaronic[$aaronic_id]['name']; }
- $companion_table_entry .= "$name";
+ $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
}
- $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><b>$companion_table_entry<hr></td></tr>";
+ $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
// Get the names of the families assigned this home teaching companionship
$sql = "SELECT * from eq_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];