From: Alan Jack Pippin Date: Sun, 6 Jan 2008 00:03:23 +0000 (-0700) Subject: Minor restructuring of program locations. X-Git-Tag: release_0_1_0~11 X-Git-Url: http://git.pippins.net/embedvideo/.git/%7Bupdate_month%7D?a=commitdiff_plain;h=82963f2191eff35b295440782e4309ea3632cf55;p=eq%2F.git Minor restructuring of program locations. Added new sql create script. Updated docs/ folder with proper install instructions. Added new "EQ Presidency Table Update" tool under Admin. --- diff --git a/bin/backup_phpgw_db b/bin/backup_phpgw_db new file mode 100755 index 0000000..b00afda --- /dev/null +++ b/bin/backup_phpgw_db @@ -0,0 +1,13 @@ +#!/bin/bash + +MNTPNT="/backup" +DSTDIR="/backup/mysql/" +DBNAME=phpgroupware +DBUSER=phpgroupware +DBPASS=phpgroupware + +mount -w -o remount $MNTPNT +/usr/bin/mysqldump --databases $DBNAME -u $DBUSER --password=$DBPASS -c > $DSTDIR/mysql_phpgw_backup.sql +ls -l $DSTDIR/mysql_phpgw_backup.sql +mount -r -o remount $MNTPNT + diff --git a/bin/import_ward_data b/bin/import_ward_data new file mode 100755 index 0000000..bd707b4 --- /dev/null +++ b/bin/import_ward_data @@ -0,0 +1,745 @@ +#!/usr/bin/perl + +use DBI; +use Getopt::Std; +################################################### +# GLOBALS +$dbname = "phpgroupware"; +$dbhost = "192.168.0.2"; +$dbport = 3306; +$dbuser = "phpgroupware"; +$dbpass = "phpgroupware"; +%hometeaching_data = (); +%membership_data = (); +getopts('vsn:o:'); + +$monthname2num{'Jan'} = '01'; +$monthname2num{'Feb'} = '02'; +$monthname2num{'Mar'} = '03'; +$monthname2num{'Apr'} = '04'; +$monthname2num{'May'} = '05'; +$monthname2num{'Jun'} = '06'; +$monthname2num{'Jul'} = '07'; +$monthname2num{'Aug'} = '08'; +$monthname2num{'Sep'} = '09'; +$monthname2num{'Oct'} = '10'; +$monthname2num{'Nov'} = '11'; +$monthname2num{'Dec'} = '12'; + +###################################################################### +# SUBROUTINES +###################################################################### +sub csv_to_hash +{ + my ($filename, $hashref) = @_; + + open(FILE,$filename) || die "-E- Could not open $filename for reading\n"; + + my $found_header = 0; my $index = 0; + while() + { + $line = $_; + @data = split /\",/, $line; + if(!$found_header) { @header = @data; $found_header = 1; } + else { + foreach $i (0..$#data-1) { + $data[$i] =~ s/\"//g; + $header[$i] =~ s/\"//g; + $hashref->{$index}{$header[$i]} = $data[$i]; + #print "$index: $i: $header[$i]: $data[$i]\n"; + } + $index++; + } + } + + close(FILE); +} + +###################################################################### +sub print_hash +{ + my ($hashref) = @_; + + foreach $key (sort {$a <=> $b} keys %$hashref) { + print "Index: $key\n"; + foreach $field (keys %{$hashref->{$key}}) { + print "$field: $hashref->{$key}{$field}\n"; + } + print "\n"; + } +} + +###################################################################### + +# EQ_AARONIC +#+-------+--------------------+------+-----+---------+-------+ +#| Field | Type | Null | Key | Default | Extra | +#+-------+--------------------+------+-----+---------+-------+ +#| aaronic | int(16) unsigned | | PRI | 0 | A | +#| name | varchar(60) | YES | | NULL | | +#| phone | varchar(12) | YES | | NULL | | +#| valid | tinyint(1) | YES | | NULL | | +#+-------+--------------------+------+-----+---------+-------+ +sub update_eq_aaronic_table +{ + print "\n-> Updating eq_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 eq_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}{'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_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 eq_aaronic values (NULL,'$aaronic_name','$phone',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 eq_aaronic set phone='$phone' where name='$aaronic_name'"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + $sth = $dbh->prepare("update eq_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(); +} + +# EQ_ELDER +#+-------------+------------------+------+-----+---------+----------------+ +#| Field | Type | Null | Key | Default | Extra | +#+-------------+------------------+------+-----+---------+----------------+ +#| elder | int(16) unsigned | | PRI | NULL | auto_increment | +#| name | varchar(60) | YES | | NULL | | +#| phone | varchar(12) | YES | | NULL | | +#| ppi_pri | int(10) unsigned | YES | | 1 | | +#| ppi_notes | varchar(128) | YES | | NULL | | +#| int_pri | int(10) unsigned | YES | | 1 | | +#| int_notes | varchar(128) | YES | | NULL | | +#| attending | tinyint(1) | YES | | 0 | | +#| valid | tinyint(1) | YES | | NULL | | +#+-------------+------------------+------+-----+---------+----------------+ +sub update_eq_elder_table +{ + print "\n-> Updating eq_elder table\n"; + + # Set all records to be invalid. Only mark them as valid if they appear on the new list. + $sth = $dbh->prepare("update eq_elder 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} =~ /Elder/i) { + $id = $membership_data{$index}{'Indiv ID'}; + $elder_name = $membership_data{$index}{'Preferred Name'}; + $phone = $membership_data{$index}{'Phone 1'}; + $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 = "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 = (); + while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); } + my $rows = scalar @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','$phone','1','','1','',$attending,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"; + $sth = $dbh->prepare("update eq_elder set attending='$attending' 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"; + } + } + } + } + $sth->finish(); +} + +# EQ_CALLING +#+--------------+------------------+------+-----+---------+-------+ +#| Field | Type | Null | Key | Default | Extra | +#+--------------+------------------+------+-----+---------+-------+ +#| indiv_id | int(16) unsigned | YES | | NULL | | +#| name | varchar(30) | YES | | NULL | | +#| organization | varchar(30) | YES | | NULL | | +#| position | varchar(30) | YES | | NULL | | +#| sequence | int(16) unsigned | YES | | NULL | | +#| sustained | date | YES | | NULL | | +#+--------------+------------------+------+-----+---------+-------+ +sub update_eq_calling_table() +{ + print "\n-> Updating eq_calling table\n"; + + #print "-> Organization Data Dump\n\n"; + #&print_hash(\%organization_data); + + # Delete all records from the calling table. We have no history to + # save here. Just re-populate with the latest calling information. + $sth = $dbh->prepare("delete from eq_calling "); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + + foreach $index (keys %organization_data) + { + $indiv_id = $organization_data{$index}{'Indiv ID'}; + $name = $organization_data{$index}{'Indiv Name'}; + $name =~ s/\'/\\'/g; #' + $organization = $organization_data{$index}{'Organization'}; + $organization_by_name{$name} = $organization; + $organization_by_id{$indiv_id} = $organization; + $position = $organization_data{$index}{'Position'}; + $sequence = $organization_data{$index}{'Org Seq'}; + $sustained = $organization_data{$index}{'Sustained'}; + $sustained =~ /(\S+) (\d+)/; $month=$1; $year=$2; + if($name eq "") { next; } + print " Adding new Calling: $name -> $position\n"; + $sth = $dbh->prepare("insert into eq_calling values ('$indiv_id','$name','$organization','$position','$sequence','$month $year')"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + } +} + +# EQ_DISTRICT +#+------------+------------------+------+-----+---------+-------+ +#| Field | Type | Null | Key | Default | Extra | +#+------------+------------------+------+-----+---------+-------+ +#| district | int(16) unsigned | | PRI | 0 | | +#| name | varchar(30) | YES | | NULL | | +#| supervisor | int(16) unsigned | YES | | NULL | | +#| valid | tinyint(1) | YES | | NULL | | +#+------------+------------------+------+-----+---------+-------+ +sub update_eq_district_table +{ + # Districts should be created by hand. This subroutine only + # updates the supervisor's ID in each district. + print "\n-> Updating eq_district table\n"; + $sth = $dbh->prepare("select * from eq_district"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + while($sqlhashref = $sth->fetchrow_hashref) { + $supervisor_name = $sqlhashref->{name}; + $district = $sqlhashref->{district}; + $sth2 = $dbh->prepare("select * from eq_elder where name='$supervisor_name'"); + $sth2->execute or die "-E- DB error: $DBI::errstr\n"; + $sqlhashref2 = $sth2->fetchrow_hashref; + $supervisor_id = $sqlhashref2->{elder}; + $sth2->finish(); + $sth2 = $dbh->prepare("update eq_district set supervisor='$supervisor_id' where district='$district'"); + $sth2->execute or die "-E- DB error: $DBI::errstr\n"; + $sth2->finish(); + } + $sth->finish(); +} + +# EQ_COMPANIONSHIP +#+---------------+------------------+------+-----+---------+-------+ +#| Field | Type | Null | Key | Default | Extra | +#+---------------+------------------+------+-----+---------+-------+ +#| companionship | int(16) unsigned | | | 0 | | +#| elder | int(16) unsigned | YES | | NULL | | +#| aaronic | int(16) unsigned | YES | | NULL | | +#| district | int(16) unsigned | YES | | NULL | | +#| valid | tinyint(1) | YES | | NULL | | +#+---------------+------------------+------+-----+---------+-------+ +sub update_eq_companionship_table +{ + print "\n-> Updating eq_companionship table\n"; + + # First, mark all existing companionships as invalid in case they have been dissolved + $sth = $dbh->prepare("update eq_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 eq_aaronic set valid=0"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + + foreach $index (keys %hometeaching_data) + { + $hashref = $hometeaching_data{$index}; + foreach $key (keys %$hashref) { + if($key =~ /Quorum/i && $hometeaching_data{$index}{$key} =~ /Elders/i) { + foreach $field ("Home Teacher 1","Home Teacher 2") { + $elder_name = $hometeaching_data{$index}{$field}; + if($elder_name eq "") { next; } + $sth2 = $dbh->prepare("select * from eq_elder where name='$elder_name'"); + $sth2->execute or die "-E- DB error: $DBI::errstr\n"; + $sqlhashref2 = $sth2->fetchrow_hashref; + $elder = $sqlhashref2->{elder}; + $aaronic = "NULL"; + if($elder eq "") { + $sth2 = $dbh->prepare("select * from eq_aaronic where name='$elder_name'"); + $sth2->execute or die "-E- DB error: $DBI::errstr\n"; + $sqlhashref2 = $sth2->fetchrow_hashref; + $aaronic = $sqlhashref2->{aaronic}; + $elder = "NULL"; + if($aaronic eq "") { print "-W- Unable to find $elder_name in eq_elder or eq_aaronic tables\n"; next; } + } + $id = $hometeaching_data{$index}{'Comp ID'}; + $district = $hometeaching_data{$index}{'HT District'}; + $sth = $dbh->prepare("select * from eq_companionship where elder='$elder' and aaronic='$aaronic' and companionship='$id'"); + $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 companionship, make a new entry + print " Adding Companion to companionship: $elder_name -> $id\n"; + $sth = $dbh->prepare("insert into eq_companionship values ($id,'$elder','$aaronic','$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 eq_companionship where district='$district' and companionship='$id'"); + $sth2->execute or die "-E- DB error: $DBI::errstr\n"; + if($elder ne "NULL") { + print " Updating Companionship with Elder: $elder_name ($elder) -> $id\n"; + $sth = $dbh->prepare("update eq_companionship set district='$district' where elder='$elder' and companionship='$id'"); + $sth->execute or die "-E- DB error 'district': $DBI::errstr\n"; + $sth = $dbh->prepare("update eq_companionship set elder='$elder' where elder='$elder' and companionship='$id'"); + $sth->execute or die "-E- DB error 'elder': $DBI::errstr\n"; + $sth = $dbh->prepare("update eq_companionship set valid=1 where elder='$elder' and companionship='$id'"); + $sth->execute or die "-E- DB error 'valid': $DBI::errstr\n"; + } else { + print " Updating Companionship with Aaronic: $elder_name ($aaronic) -> $id\n"; + $sth = $dbh->prepare("update eq_companionship set district='$district' where aaronic='$aaronic' and companionship='$id'"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + $sth = $dbh->prepare("update eq_companionship set aaronic='$aaronic' where aaronic='$aaronic' and companionship='$id'"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + $sth = $dbh->prepare("update eq_companionship set valid=1 where aaronic='$aaronic' and companionship='$id'"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + $sth = $dbh->prepare("update eq_aaronic set valid=1 where aaronic='$aaronic'"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + } + } + $sth->finish(); + $sth2->finish(); + } + } + } + } +} + +# EQ_FAMILY +#+---------------+------------------+------+-----+---------+-------+ +#| Field | Type | Null | Key | Default | Extra | +#+---------------+------------------+------+-----+---------+-------+ +#| family | int(16) unsigned | | PRI | 0 | A | +#| hofh_id | int(16) unsigned | YES | | NULL | | +#| name | varchar(30) | YES | | NULL | | +#| name_id | varchar(30) | YES | | NULL | | +#| elder_id | int(16) unsigned | YES | | NULL | | +#| companionship | int(16) unsigned | YES | | NULL | | +#| visit_pri | int(10) unsigned | YES | | 1 | | +#| visit_notes | varchar(128) | YES | | NULL | | +#| valid | tinyint(1) | YES | | NULL | | +#+---------------+------------------+------+-----+---------+-------+ +sub update_eq_family_table +{ + print "\n-> Updating eq_family table\n"; + + # Set all records to be invalid. Only mark them as valid if they appear on the new list. + $sth = $dbh->prepare("update eq_family set valid=0"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + $sth = $dbh->prepare("update eq_family set companionship=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) { + $family_name = $membership_data{$index}{'Preferred Name'}; + $family_name =~ s/\'/\\'/g; #' + $id = $membership_data{$index}{'HofH ID'}; + $name_id = uc($family_name); + + # Find out how many families match this family's name + $sth = $dbh->prepare("select * from eq_family where name_id='$name_id'"); + $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 family, make a new entry + print " Adding new Family: $family_name\n"; + $sth = $dbh->prepare("insert into eq_family values (NULL,$id,'$family_name','$name_id','0','0','1','',1)"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + } elsif($rows == 1) { + # An existing record was found for this family, update it + print " Updating existing family: $family_name\n"; + $sth = $dbh->prepare("update eq_family set hofh_id=$id where name_id='$name_id'"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + $sth = $dbh->prepare("update eq_family set valid=1 where name_id='$name_id'"); + $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 family name: $family_name\n"; + } + + # Now update the elder_id field for this family + $sth = $dbh->prepare("select * from eq_elder WHERE name='$family_name'"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + while($sqlhashref = $sth->fetchrow_hashref) { + $elder_id = $sqlhashref->{elder}; + print " Updating family elder_id: $family_name -> $elder_id\n"; + $sth = $dbh->prepare("update eq_family set elder_id=$elder_id where name_id='$name_id'"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + } + + # Now update the hometeaching field for this family + foreach $index (keys %hometeaching_data) + { + $hashref = $hometeaching_data{$index}; + foreach $key (keys %$hashref) { + if($hometeaching_data{$index}{'Household'} =~ /(\S+)\s+(\S+),\s+(\S+)\s+(.*)/) { + $a = $1; $b = $2; $c = $3; $d = $4; + if($family_name =~ /$a/ && $hometeaching_data{$index}{'Household'} !~ /$family_name/i) { + print "I: Adjusting hometeaching match from: $hometeaching_data{$index}{'Household'} to $a, $c $d\n"; + $hometeaching_data{$index}{'Household'} = "$a, $c $d"; + } + } + if($key =~ /Quorum/i && + $hometeaching_data{$index}{$key} =~ /Elders/i && + $hometeaching_data{$index}{'Household'} =~ /$family_name/i && + $data[0]->{companionship} != $hometeaching_data{$index}{'Comp ID'} + ) + { + print " Updating hometeaching assignment for $family_name family\n"; + $companionship = $hometeaching_data{$index}{'Comp ID'}; + $sth = $dbh->prepare("update eq_family set companionship='$companionship' where name_id='$name_id'"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + } + } + } + $sth->finish(); + } + } + } +} + +# EQ_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_eq_parent_table +{ + print "\n-> Updating eq_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 eq_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}{'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"; } + $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 eq_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 eq_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 eq_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 eq_parent set family='$family_id' where name='$parent_name'"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + $sth = $dbh->prepare("update eq_parent set birthday='$year-$month-$day' where name='$parent_name'"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + $sth = $dbh->prepare("update eq_parent set phone='$phone' where name='$parent_name'"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + $sth = $dbh->prepare("update eq_parent set address='$address' where name='$parent_name'"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + $sth = $dbh->prepare("update eq_parent set valid=1 where name='$parent_name'"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + $sth = $dbh->prepare("update eq_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(); + } + } + } +} + +# EQ_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_eq_child_table +{ + print "\n-> Updating eq_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 eq_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 eq_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 eq_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 eq_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 eq_child set family='$family_id' where name='$child_name'"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + $sth = $dbh->prepare("update eq_child set birthday='$year-$month-$day' where name='$child_name'"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + $sth = $dbh->prepare("update eq_child set valid=1 where name='$child_name'"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + $sth = $dbh->prepare("update eq_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(); + } + } + } +} + +###################################################################### +sub check_for_changed_ids +{ + # If the Indiv ID & HofH ID has changed between data sets, we could have problems + my ($oldhashref, $newhashref) = @_; + my $found_problem = 0; + + foreach $oldindex (keys %$oldhashref) + { + $indiv_id = $oldhashref->{$oldindex}{'Indiv ID'}; + $hofh_id = $oldhashref->{$oldindex}{'HofH ID'}; + $full_name = $oldhashref->{$oldindex}{'Full Name'}; + $hh_position = $oldhashref->{$oldindex}{'HH Position'}; + if($hh_position =~ /Other/i) { next; } + + foreach $newindex (keys %$newhashref) + { + if($newhashref->{$newindex}{'Full Name'} eq $full_name && + $indiv_id != $newhashref->{$newindex}{'Indiv ID'}) + { + print "-W- Indiv ID for $full_name changed from $indiv_id to $newhashref->{$newindex}{'Indiv ID'}\n"; + $found_problem = 1; + } + + if($newhashref->{$newindex}{'Full Name'} eq $full_name && + $hofh_id != $newhashref->{$newindex}{'HofH ID'}) + { + print "-W- HofH ID for $full_name changed from $hofh_id to $newhashref->{$newindex}{'HofH ID'}\n"; + $found_problem = 1; + } + } + } + + return $found_problem; +} + +###################################################################### +# MAIN +###################################################################### + +################################################### +# Open a connection to the database +$dbh=DBI->connect("dbi:mysql:dbname=$dbname;host=$dbhost port=$dbport",$dbuser,$dbpass,{ + AutoCommit=>0, + PrintError=>0}) or print "Connect Failure:".$DBI::errstr."\n" and exit 2; + +################################################### +# Check old directory against new directory to ensure +# that the Indiv ID & HofH ID have not changed between updates +if(defined $opt_o) { + print "-> Comparing old data files to new ones: $opt_o => $opt_n\n"; + my %old_membership_data = (); + my %new_membership_data = (); + &csv_to_hash("$opt_o/Membership.csv",\%old_membership_data); + &csv_to_hash("$opt_n/Membership.csv",\%new_membership_data); + + $changed_ids=&check_for_changed_ids(\%old_membership_data, \%new_membership_data); + + if($changed_ids) { + print "\n"; + print "-E- Some Indiv IDs and HofH IDs have changed for Head of Households between \n"; + print " $opt_o and $opt_n data sets.\n"; + print " This script is not currently setup to handle this properly.\n"; + print "\n"; + print " Exiting without updating...\n\n"; + exit; + } +} + +################################################### +# Process command line options +if(defined $opt_n) { $datadir = $opt_n; } +else { $datadir = shift(@ARGV); } +print "\n-> Processing all ward data files in $datadir\n"; + +################################################### +# Parse Ward Data Files +&csv_to_hash("$datadir/Membership.csv",\%membership_data); +&csv_to_hash("$datadir/HomeTeaching.csv",\%hometeaching_data); +&csv_to_hash("$datadir/Organization.csv",\%organization_data); +%organization_by_name = (); +%organization_by_id = (); + +if($opt_v) { + print "-> Membership Data Dump\n\n"; + &print_hash(\%membership_data); + print "-> HomeTeaching Data Dump\n\n"; + &print_hash(\%hometeaching_data); + print "-> Organization Data Dump\n\n"; + &print_hash(\%organization_data); +} + +if($opt_s) { $dbh->disconnect(); exit; } + +# Now update the various eq DB tables +&update_eq_calling_table(); +&update_eq_elder_table(); +&update_eq_aaronic_table(); +&update_eq_district_table(); +&update_eq_companionship_table(); +&update_eq_family_table(); +&update_eq_parent_table(); +&update_eq_child_table(); + +################################################### +# Disconnect from the database +$dbh->disconnect(); + +###################################################################### + + + + + + + + + + + + diff --git a/bin/parse_ward_data b/bin/parse_ward_data new file mode 100755 index 0000000..82a1730 --- /dev/null +++ b/bin/parse_ward_data @@ -0,0 +1,136 @@ +#!/usr/bin/perl + +use DBI; +use Getopt::Std; +################################################### +# GLOBALS +$dbname = "phpgroupware"; +$dbhost = "192.168.0.2"; +$dbport = 3306; +$dbuser = "phpgroupware"; +$dbpass = "phpgroupware"; +%hometeaching_data = (); +%membership_data = (); +getopts('vsn:o:b'); + +$monthname2num{'Jan'} = '01'; +$monthname2num{'Feb'} = '02'; +$monthname2num{'Mar'} = '03'; +$monthname2num{'Apr'} = '04'; +$monthname2num{'May'} = '05'; +$monthname2num{'Jun'} = '06'; +$monthname2num{'Jul'} = '07'; +$monthname2num{'Aug'} = '08'; +$monthname2num{'Sep'} = '09'; +$monthname2num{'Oct'} = '10'; +$monthname2num{'Nov'} = '11'; +$monthname2num{'Dec'} = '12'; + +###################################################################### +# SUBROUTINES +###################################################################### +sub csv_to_hash +{ + my ($filename, $hashref) = @_; + + open(FILE,$filename) || die "-E- Could not open $filename for reading\n"; + + my $found_header = 0; my $index = 0; + while() + { + $line = $_; + @data = split /\",/, $line; + if(!$found_header) { @header = @data; $found_header = 1; } + else { + foreach $i (0..$#data-1) { + $data[$i] =~ s/\"//g; + $header[$i] =~ s/\"//g; + $hashref->{$index}{$header[$i]} = $data[$i]; + #print "$index: $i: $header[$i]: $data[$i]\n"; + } + $index++; + } + } + + close(FILE); +} + +###################################################################### +sub print_hash +{ + my ($hashref) = @_; + + foreach $key (sort {$a <=> $b} keys %$hashref) { + print "Index: $key\n"; + foreach $field (keys %{$hashref->{$key}}) { + print "$field: $hashref->{$key}{$field}\n"; + } + print "\n"; + } +} + +###################################################################### +sub print_birthdays +{ + my ($hashref) = @_; + + foreach $key (sort {$a <=> $b} keys %$hashref) { + $name = ""; + $birthday = ""; + foreach $field (keys %{$hashref->{$key}}) { + if($field =~ /Full Name/) { $name = $hashref->{$key}{$field}; } + if($field =~ /Birth/) { $birthday = $hashref->{$key}{$field}; } + } + if($name ne "" && $birthday ne "") { printf "%-30s %-10s\n",$name,$birthday; } + } +} + +###################################################################### +# MAIN +###################################################################### + +################################################### +# Open a connection to the database +$dbh=DBI->connect("dbi:mysql:dbname=$dbname;host=$dbhost port=$dbport",$dbuser,$dbpass,{ + AutoCommit=>0, + PrintError=>0}) or print "Connect Failure:".$DBI::errstr."\n" and exit 2; + +################################################### +# Process command line options +if(defined $opt_n) { $datadir = $opt_n; } +else { $datadir = shift(@ARGV); } +print "-> Processing all ward data files in $datadir\n"; + +################################################### +# Parse Ward Data Files +&csv_to_hash("$datadir/Membership.csv",\%membership_data); +&csv_to_hash("$datadir/HomeTeaching.csv",\%hometeaching_data); + +if($opt_v) { + print "-> Membership Data Dump\n\n"; + &print_hash(\%membership_data); + print "-> HomeTeaching Data Dump\n\n"; + &print_hash(\%hometeaching_data); +} + +if($opt_b) { &print_birthdays(\%membership_data); } + +if($opt_s) { $dbh->disconnect(); exit; } + +################################################### +# Disconnect from the database +$dbh->disconnect(); + +###################################################################### + + + + + + + + + + + + diff --git a/checkmark.gif b/checkmark.gif deleted file mode 100644 index ae70f59..0000000 Binary files a/checkmark.gif and /dev/null differ diff --git a/doc b/doc deleted file mode 120000 index 01b66f7..0000000 --- a/doc +++ /dev/null @@ -1 +0,0 @@ -../../doc/phpgroupware-skel \ No newline at end of file diff --git a/eq.jpg b/eq.jpg deleted file mode 100644 index 5f1886d..0000000 Binary files a/eq.jpg and /dev/null differ diff --git a/eq.spec b/eq.spec index 40621d6..a86bfbb 100644 --- a/eq.spec +++ b/eq.spec @@ -12,7 +12,7 @@ %define httpdroot /home/httpd/html/phpgroupware %define packaging 1 -Summary: Skeleton App for phpGroupWare. +Summary: Tools for Managing an Elders Quorum app for phpGroupWare. Name: %{packagename} Version: %{version} Release: %{packaging} @@ -27,7 +27,7 @@ requires: phpgroupware >= 0.9.10 AutoReq: 0 %description -This is an Elder's Quorum Presidency Application. +This is an Elders Quorum Presidency Application. %prep %setup -n %{phpgwdirname} diff --git a/images/checkmark.gif b/images/checkmark.gif new file mode 100644 index 0000000..ae70f59 Binary files /dev/null and b/images/checkmark.gif differ diff --git a/images/x.gif b/images/x.gif new file mode 100755 index 0000000..12ed1d5 Binary files /dev/null and b/images/x.gif differ diff --git a/images/x.psd b/images/x.psd new file mode 100755 index 0000000..8353958 Binary files /dev/null and b/images/x.psd differ diff --git a/import_ward_data b/import_ward_data deleted file mode 100755 index bd707b4..0000000 --- a/import_ward_data +++ /dev/null @@ -1,745 +0,0 @@ -#!/usr/bin/perl - -use DBI; -use Getopt::Std; -################################################### -# GLOBALS -$dbname = "phpgroupware"; -$dbhost = "192.168.0.2"; -$dbport = 3306; -$dbuser = "phpgroupware"; -$dbpass = "phpgroupware"; -%hometeaching_data = (); -%membership_data = (); -getopts('vsn:o:'); - -$monthname2num{'Jan'} = '01'; -$monthname2num{'Feb'} = '02'; -$monthname2num{'Mar'} = '03'; -$monthname2num{'Apr'} = '04'; -$monthname2num{'May'} = '05'; -$monthname2num{'Jun'} = '06'; -$monthname2num{'Jul'} = '07'; -$monthname2num{'Aug'} = '08'; -$monthname2num{'Sep'} = '09'; -$monthname2num{'Oct'} = '10'; -$monthname2num{'Nov'} = '11'; -$monthname2num{'Dec'} = '12'; - -###################################################################### -# SUBROUTINES -###################################################################### -sub csv_to_hash -{ - my ($filename, $hashref) = @_; - - open(FILE,$filename) || die "-E- Could not open $filename for reading\n"; - - my $found_header = 0; my $index = 0; - while() - { - $line = $_; - @data = split /\",/, $line; - if(!$found_header) { @header = @data; $found_header = 1; } - else { - foreach $i (0..$#data-1) { - $data[$i] =~ s/\"//g; - $header[$i] =~ s/\"//g; - $hashref->{$index}{$header[$i]} = $data[$i]; - #print "$index: $i: $header[$i]: $data[$i]\n"; - } - $index++; - } - } - - close(FILE); -} - -###################################################################### -sub print_hash -{ - my ($hashref) = @_; - - foreach $key (sort {$a <=> $b} keys %$hashref) { - print "Index: $key\n"; - foreach $field (keys %{$hashref->{$key}}) { - print "$field: $hashref->{$key}{$field}\n"; - } - print "\n"; - } -} - -###################################################################### - -# EQ_AARONIC -#+-------+--------------------+------+-----+---------+-------+ -#| Field | Type | Null | Key | Default | Extra | -#+-------+--------------------+------+-----+---------+-------+ -#| aaronic | int(16) unsigned | | PRI | 0 | A | -#| name | varchar(60) | YES | | NULL | | -#| phone | varchar(12) | YES | | NULL | | -#| valid | tinyint(1) | YES | | NULL | | -#+-------+--------------------+------+-----+---------+-------+ -sub update_eq_aaronic_table -{ - print "\n-> Updating eq_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 eq_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}{'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_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 eq_aaronic values (NULL,'$aaronic_name','$phone',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 eq_aaronic set phone='$phone' where name='$aaronic_name'"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - $sth = $dbh->prepare("update eq_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(); -} - -# EQ_ELDER -#+-------------+------------------+------+-----+---------+----------------+ -#| Field | Type | Null | Key | Default | Extra | -#+-------------+------------------+------+-----+---------+----------------+ -#| elder | int(16) unsigned | | PRI | NULL | auto_increment | -#| name | varchar(60) | YES | | NULL | | -#| phone | varchar(12) | YES | | NULL | | -#| ppi_pri | int(10) unsigned | YES | | 1 | | -#| ppi_notes | varchar(128) | YES | | NULL | | -#| int_pri | int(10) unsigned | YES | | 1 | | -#| int_notes | varchar(128) | YES | | NULL | | -#| attending | tinyint(1) | YES | | 0 | | -#| valid | tinyint(1) | YES | | NULL | | -#+-------------+------------------+------+-----+---------+----------------+ -sub update_eq_elder_table -{ - print "\n-> Updating eq_elder table\n"; - - # Set all records to be invalid. Only mark them as valid if they appear on the new list. - $sth = $dbh->prepare("update eq_elder 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} =~ /Elder/i) { - $id = $membership_data{$index}{'Indiv ID'}; - $elder_name = $membership_data{$index}{'Preferred Name'}; - $phone = $membership_data{$index}{'Phone 1'}; - $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 = "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 = (); - while($sqlhashref = $sth->fetchrow_hashref) { push(@data, $sqlhashref); } - my $rows = scalar @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','$phone','1','','1','',$attending,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"; - $sth = $dbh->prepare("update eq_elder set attending='$attending' 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"; - } - } - } - } - $sth->finish(); -} - -# EQ_CALLING -#+--------------+------------------+------+-----+---------+-------+ -#| Field | Type | Null | Key | Default | Extra | -#+--------------+------------------+------+-----+---------+-------+ -#| indiv_id | int(16) unsigned | YES | | NULL | | -#| name | varchar(30) | YES | | NULL | | -#| organization | varchar(30) | YES | | NULL | | -#| position | varchar(30) | YES | | NULL | | -#| sequence | int(16) unsigned | YES | | NULL | | -#| sustained | date | YES | | NULL | | -#+--------------+------------------+------+-----+---------+-------+ -sub update_eq_calling_table() -{ - print "\n-> Updating eq_calling table\n"; - - #print "-> Organization Data Dump\n\n"; - #&print_hash(\%organization_data); - - # Delete all records from the calling table. We have no history to - # save here. Just re-populate with the latest calling information. - $sth = $dbh->prepare("delete from eq_calling "); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - - foreach $index (keys %organization_data) - { - $indiv_id = $organization_data{$index}{'Indiv ID'}; - $name = $organization_data{$index}{'Indiv Name'}; - $name =~ s/\'/\\'/g; #' - $organization = $organization_data{$index}{'Organization'}; - $organization_by_name{$name} = $organization; - $organization_by_id{$indiv_id} = $organization; - $position = $organization_data{$index}{'Position'}; - $sequence = $organization_data{$index}{'Org Seq'}; - $sustained = $organization_data{$index}{'Sustained'}; - $sustained =~ /(\S+) (\d+)/; $month=$1; $year=$2; - if($name eq "") { next; } - print " Adding new Calling: $name -> $position\n"; - $sth = $dbh->prepare("insert into eq_calling values ('$indiv_id','$name','$organization','$position','$sequence','$month $year')"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - } -} - -# EQ_DISTRICT -#+------------+------------------+------+-----+---------+-------+ -#| Field | Type | Null | Key | Default | Extra | -#+------------+------------------+------+-----+---------+-------+ -#| district | int(16) unsigned | | PRI | 0 | | -#| name | varchar(30) | YES | | NULL | | -#| supervisor | int(16) unsigned | YES | | NULL | | -#| valid | tinyint(1) | YES | | NULL | | -#+------------+------------------+------+-----+---------+-------+ -sub update_eq_district_table -{ - # Districts should be created by hand. This subroutine only - # updates the supervisor's ID in each district. - print "\n-> Updating eq_district table\n"; - $sth = $dbh->prepare("select * from eq_district"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - while($sqlhashref = $sth->fetchrow_hashref) { - $supervisor_name = $sqlhashref->{name}; - $district = $sqlhashref->{district}; - $sth2 = $dbh->prepare("select * from eq_elder where name='$supervisor_name'"); - $sth2->execute or die "-E- DB error: $DBI::errstr\n"; - $sqlhashref2 = $sth2->fetchrow_hashref; - $supervisor_id = $sqlhashref2->{elder}; - $sth2->finish(); - $sth2 = $dbh->prepare("update eq_district set supervisor='$supervisor_id' where district='$district'"); - $sth2->execute or die "-E- DB error: $DBI::errstr\n"; - $sth2->finish(); - } - $sth->finish(); -} - -# EQ_COMPANIONSHIP -#+---------------+------------------+------+-----+---------+-------+ -#| Field | Type | Null | Key | Default | Extra | -#+---------------+------------------+------+-----+---------+-------+ -#| companionship | int(16) unsigned | | | 0 | | -#| elder | int(16) unsigned | YES | | NULL | | -#| aaronic | int(16) unsigned | YES | | NULL | | -#| district | int(16) unsigned | YES | | NULL | | -#| valid | tinyint(1) | YES | | NULL | | -#+---------------+------------------+------+-----+---------+-------+ -sub update_eq_companionship_table -{ - print "\n-> Updating eq_companionship table\n"; - - # First, mark all existing companionships as invalid in case they have been dissolved - $sth = $dbh->prepare("update eq_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 eq_aaronic set valid=0"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - - foreach $index (keys %hometeaching_data) - { - $hashref = $hometeaching_data{$index}; - foreach $key (keys %$hashref) { - if($key =~ /Quorum/i && $hometeaching_data{$index}{$key} =~ /Elders/i) { - foreach $field ("Home Teacher 1","Home Teacher 2") { - $elder_name = $hometeaching_data{$index}{$field}; - if($elder_name eq "") { next; } - $sth2 = $dbh->prepare("select * from eq_elder where name='$elder_name'"); - $sth2->execute or die "-E- DB error: $DBI::errstr\n"; - $sqlhashref2 = $sth2->fetchrow_hashref; - $elder = $sqlhashref2->{elder}; - $aaronic = "NULL"; - if($elder eq "") { - $sth2 = $dbh->prepare("select * from eq_aaronic where name='$elder_name'"); - $sth2->execute or die "-E- DB error: $DBI::errstr\n"; - $sqlhashref2 = $sth2->fetchrow_hashref; - $aaronic = $sqlhashref2->{aaronic}; - $elder = "NULL"; - if($aaronic eq "") { print "-W- Unable to find $elder_name in eq_elder or eq_aaronic tables\n"; next; } - } - $id = $hometeaching_data{$index}{'Comp ID'}; - $district = $hometeaching_data{$index}{'HT District'}; - $sth = $dbh->prepare("select * from eq_companionship where elder='$elder' and aaronic='$aaronic' and companionship='$id'"); - $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 companionship, make a new entry - print " Adding Companion to companionship: $elder_name -> $id\n"; - $sth = $dbh->prepare("insert into eq_companionship values ($id,'$elder','$aaronic','$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 eq_companionship where district='$district' and companionship='$id'"); - $sth2->execute or die "-E- DB error: $DBI::errstr\n"; - if($elder ne "NULL") { - print " Updating Companionship with Elder: $elder_name ($elder) -> $id\n"; - $sth = $dbh->prepare("update eq_companionship set district='$district' where elder='$elder' and companionship='$id'"); - $sth->execute or die "-E- DB error 'district': $DBI::errstr\n"; - $sth = $dbh->prepare("update eq_companionship set elder='$elder' where elder='$elder' and companionship='$id'"); - $sth->execute or die "-E- DB error 'elder': $DBI::errstr\n"; - $sth = $dbh->prepare("update eq_companionship set valid=1 where elder='$elder' and companionship='$id'"); - $sth->execute or die "-E- DB error 'valid': $DBI::errstr\n"; - } else { - print " Updating Companionship with Aaronic: $elder_name ($aaronic) -> $id\n"; - $sth = $dbh->prepare("update eq_companionship set district='$district' where aaronic='$aaronic' and companionship='$id'"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - $sth = $dbh->prepare("update eq_companionship set aaronic='$aaronic' where aaronic='$aaronic' and companionship='$id'"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - $sth = $dbh->prepare("update eq_companionship set valid=1 where aaronic='$aaronic' and companionship='$id'"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - $sth = $dbh->prepare("update eq_aaronic set valid=1 where aaronic='$aaronic'"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - } - } - $sth->finish(); - $sth2->finish(); - } - } - } - } -} - -# EQ_FAMILY -#+---------------+------------------+------+-----+---------+-------+ -#| Field | Type | Null | Key | Default | Extra | -#+---------------+------------------+------+-----+---------+-------+ -#| family | int(16) unsigned | | PRI | 0 | A | -#| hofh_id | int(16) unsigned | YES | | NULL | | -#| name | varchar(30) | YES | | NULL | | -#| name_id | varchar(30) | YES | | NULL | | -#| elder_id | int(16) unsigned | YES | | NULL | | -#| companionship | int(16) unsigned | YES | | NULL | | -#| visit_pri | int(10) unsigned | YES | | 1 | | -#| visit_notes | varchar(128) | YES | | NULL | | -#| valid | tinyint(1) | YES | | NULL | | -#+---------------+------------------+------+-----+---------+-------+ -sub update_eq_family_table -{ - print "\n-> Updating eq_family table\n"; - - # Set all records to be invalid. Only mark them as valid if they appear on the new list. - $sth = $dbh->prepare("update eq_family set valid=0"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - $sth = $dbh->prepare("update eq_family set companionship=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) { - $family_name = $membership_data{$index}{'Preferred Name'}; - $family_name =~ s/\'/\\'/g; #' - $id = $membership_data{$index}{'HofH ID'}; - $name_id = uc($family_name); - - # Find out how many families match this family's name - $sth = $dbh->prepare("select * from eq_family where name_id='$name_id'"); - $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 family, make a new entry - print " Adding new Family: $family_name\n"; - $sth = $dbh->prepare("insert into eq_family values (NULL,$id,'$family_name','$name_id','0','0','1','',1)"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - } elsif($rows == 1) { - # An existing record was found for this family, update it - print " Updating existing family: $family_name\n"; - $sth = $dbh->prepare("update eq_family set hofh_id=$id where name_id='$name_id'"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - $sth = $dbh->prepare("update eq_family set valid=1 where name_id='$name_id'"); - $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 family name: $family_name\n"; - } - - # Now update the elder_id field for this family - $sth = $dbh->prepare("select * from eq_elder WHERE name='$family_name'"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - while($sqlhashref = $sth->fetchrow_hashref) { - $elder_id = $sqlhashref->{elder}; - print " Updating family elder_id: $family_name -> $elder_id\n"; - $sth = $dbh->prepare("update eq_family set elder_id=$elder_id where name_id='$name_id'"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - } - - # Now update the hometeaching field for this family - foreach $index (keys %hometeaching_data) - { - $hashref = $hometeaching_data{$index}; - foreach $key (keys %$hashref) { - if($hometeaching_data{$index}{'Household'} =~ /(\S+)\s+(\S+),\s+(\S+)\s+(.*)/) { - $a = $1; $b = $2; $c = $3; $d = $4; - if($family_name =~ /$a/ && $hometeaching_data{$index}{'Household'} !~ /$family_name/i) { - print "I: Adjusting hometeaching match from: $hometeaching_data{$index}{'Household'} to $a, $c $d\n"; - $hometeaching_data{$index}{'Household'} = "$a, $c $d"; - } - } - if($key =~ /Quorum/i && - $hometeaching_data{$index}{$key} =~ /Elders/i && - $hometeaching_data{$index}{'Household'} =~ /$family_name/i && - $data[0]->{companionship} != $hometeaching_data{$index}{'Comp ID'} - ) - { - print " Updating hometeaching assignment for $family_name family\n"; - $companionship = $hometeaching_data{$index}{'Comp ID'}; - $sth = $dbh->prepare("update eq_family set companionship='$companionship' where name_id='$name_id'"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - } - } - } - $sth->finish(); - } - } - } -} - -# EQ_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_eq_parent_table -{ - print "\n-> Updating eq_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 eq_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}{'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"; } - $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 eq_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 eq_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 eq_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 eq_parent set family='$family_id' where name='$parent_name'"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - $sth = $dbh->prepare("update eq_parent set birthday='$year-$month-$day' where name='$parent_name'"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - $sth = $dbh->prepare("update eq_parent set phone='$phone' where name='$parent_name'"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - $sth = $dbh->prepare("update eq_parent set address='$address' where name='$parent_name'"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - $sth = $dbh->prepare("update eq_parent set valid=1 where name='$parent_name'"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - $sth = $dbh->prepare("update eq_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(); - } - } - } -} - -# EQ_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_eq_child_table -{ - print "\n-> Updating eq_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 eq_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 eq_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 eq_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 eq_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 eq_child set family='$family_id' where name='$child_name'"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - $sth = $dbh->prepare("update eq_child set birthday='$year-$month-$day' where name='$child_name'"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - $sth = $dbh->prepare("update eq_child set valid=1 where name='$child_name'"); - $sth->execute or die "-E- DB error: $DBI::errstr\n"; - $sth = $dbh->prepare("update eq_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(); - } - } - } -} - -###################################################################### -sub check_for_changed_ids -{ - # If the Indiv ID & HofH ID has changed between data sets, we could have problems - my ($oldhashref, $newhashref) = @_; - my $found_problem = 0; - - foreach $oldindex (keys %$oldhashref) - { - $indiv_id = $oldhashref->{$oldindex}{'Indiv ID'}; - $hofh_id = $oldhashref->{$oldindex}{'HofH ID'}; - $full_name = $oldhashref->{$oldindex}{'Full Name'}; - $hh_position = $oldhashref->{$oldindex}{'HH Position'}; - if($hh_position =~ /Other/i) { next; } - - foreach $newindex (keys %$newhashref) - { - if($newhashref->{$newindex}{'Full Name'} eq $full_name && - $indiv_id != $newhashref->{$newindex}{'Indiv ID'}) - { - print "-W- Indiv ID for $full_name changed from $indiv_id to $newhashref->{$newindex}{'Indiv ID'}\n"; - $found_problem = 1; - } - - if($newhashref->{$newindex}{'Full Name'} eq $full_name && - $hofh_id != $newhashref->{$newindex}{'HofH ID'}) - { - print "-W- HofH ID for $full_name changed from $hofh_id to $newhashref->{$newindex}{'HofH ID'}\n"; - $found_problem = 1; - } - } - } - - return $found_problem; -} - -###################################################################### -# MAIN -###################################################################### - -################################################### -# Open a connection to the database -$dbh=DBI->connect("dbi:mysql:dbname=$dbname;host=$dbhost port=$dbport",$dbuser,$dbpass,{ - AutoCommit=>0, - PrintError=>0}) or print "Connect Failure:".$DBI::errstr."\n" and exit 2; - -################################################### -# Check old directory against new directory to ensure -# that the Indiv ID & HofH ID have not changed between updates -if(defined $opt_o) { - print "-> Comparing old data files to new ones: $opt_o => $opt_n\n"; - my %old_membership_data = (); - my %new_membership_data = (); - &csv_to_hash("$opt_o/Membership.csv",\%old_membership_data); - &csv_to_hash("$opt_n/Membership.csv",\%new_membership_data); - - $changed_ids=&check_for_changed_ids(\%old_membership_data, \%new_membership_data); - - if($changed_ids) { - print "\n"; - print "-E- Some Indiv IDs and HofH IDs have changed for Head of Households between \n"; - print " $opt_o and $opt_n data sets.\n"; - print " This script is not currently setup to handle this properly.\n"; - print "\n"; - print " Exiting without updating...\n\n"; - exit; - } -} - -################################################### -# Process command line options -if(defined $opt_n) { $datadir = $opt_n; } -else { $datadir = shift(@ARGV); } -print "\n-> Processing all ward data files in $datadir\n"; - -################################################### -# Parse Ward Data Files -&csv_to_hash("$datadir/Membership.csv",\%membership_data); -&csv_to_hash("$datadir/HomeTeaching.csv",\%hometeaching_data); -&csv_to_hash("$datadir/Organization.csv",\%organization_data); -%organization_by_name = (); -%organization_by_id = (); - -if($opt_v) { - print "-> Membership Data Dump\n\n"; - &print_hash(\%membership_data); - print "-> HomeTeaching Data Dump\n\n"; - &print_hash(\%hometeaching_data); - print "-> Organization Data Dump\n\n"; - &print_hash(\%organization_data); -} - -if($opt_s) { $dbh->disconnect(); exit; } - -# Now update the various eq DB tables -&update_eq_calling_table(); -&update_eq_elder_table(); -&update_eq_aaronic_table(); -&update_eq_district_table(); -&update_eq_companionship_table(); -&update_eq_family_table(); -&update_eq_parent_table(); -&update_eq_child_table(); - -################################################### -# Disconnect from the database -$dbh->disconnect(); - -###################################################################### - - - - - - - - - - - - diff --git a/inc/class.eq.inc.php b/inc/class.eq.inc.php index 9bc77a0..4198742 100644 --- a/inc/class.eq.inc.php +++ b/inc/class.eq.inc.php @@ -8,7 +8,7 @@ * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * \**************************************************************************/ - /* $Id: class.eq.inc.php,v 1.1.1.1 2001/05/20 07:40:32 seek3r Exp $ */ + /* $Id: class.eq.inc.php,v 1.1.1.1 2005/07/20 07:40:32 ajp Exp $ */ class eq { @@ -26,11 +26,13 @@ class eq var $default_int_num_years; var $default_vis_num_years; var $default_att_num_quarters; + var $max_num_districts; var $current_year; var $current_month; var $upload_target_path; var $script_path; var $max_appointments; + var $max_presidency_members; var $public_functions = array ( @@ -65,6 +67,9 @@ class eq function eq() { + // LOCAL CONFIGURATION. PLEASE UPDATE AS APPROPRIATE. + $this->upload_target_path = "/home/users/eqpres/eq_data/"; + $this->script_path = "/usr/share/phpgroupware/eq/bin/"; $this->default_ht_num_months = 3; $this->default_ppi_num_months = 3; $this->default_ppi_num_years = 0; @@ -72,9 +77,10 @@ class eq $this->default_int_num_years = 0; $this->default_att_num_quarters = 1; $this->default_vis_num_years = 1; + $this->max_num_districts = 4; + $this->max_presidency_members = 99; $this->max_appointments = 32768; - $this->upload_target_path = "/home/users/eqpres/eq_data/"; - $this->script_path = "/usr/share/phpgroupware/eq/"; + // END LOCAL CONFIGURATION $this->db = $GLOBALS['phpgw']->db; $this->db2 = $this->db; @@ -91,7 +97,7 @@ class eq mondayFirst : false, weekNumbers : false'; - $GLOBALS['phpgw_info']['flags']['app_header'] = 'Elders Quorum Tools'; + $GLOBALS['phpgw_info']['flags']['app_header'] = 'Elders Quorum Tools - The 3rd Counselor'; $GLOBALS['phpgw']->common->phpgw_header(); $this->current_day = `date '+%d'`; @@ -313,10 +319,10 @@ class eq if($this->db2->next_record()) { if($this->db2->f('visited') == 'y') { $visits[$m]++; $total_visits[$m]++; - $table_data .= ''; + $table_data .= ''; } else if($this->db2->f('visited') == 'n') { - $table_data .= ''; + $table_data .= ''; } else { $visits[$m]++; $total_visits[$m]++; @@ -1070,14 +1076,14 @@ class eq } } if($checkmark) { - $part_table .= ''; + $part_table .= ''; $part_table .= ''.$num_matches.'
'; $part_table .= ''.$date.''; } else { $part_table .= ' '; } } - if($participated) { $part_table .= ''.$participated.''; } + if($participated) { $part_table .= ''.$participated.''; } else { $part_table .= ' '; } $this->t->set_var('part_table',$part_table); $this->t->fp('list2','elder_list',True); @@ -1194,10 +1200,10 @@ class eq if($this->db->f('willing') == 'y') { $total_willing[$j]++; $elder_willing=1; - $willing_table .= '
'.$date_part.''; + $willing_table .= '
'.$date_part.''; } else if($this->db->f('willing') == 'n') { - $willing_table .= ''; + $willing_table .= ''; } else { $elder_willing=1; @@ -2079,7 +2085,7 @@ class eq $appt_table_data = ""; // Find out what the EQ Presidency ID is - $sql = "SELECT * FROM eq_presidency where president=0 and counselor=0 and secretary=0 and valid=1"; + $sql = "SELECT * FROM eq_presidency where eqpres=1 and valid=1"; $this->db->query($sql,__LINE__,__FILE__); if($this->db->next_record()) { $presidency_name = $this->db->f('name'); @@ -2387,7 +2393,7 @@ class eq $month = $date_array[1]; $day = $date_array[2]; $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data); - $table_data .= ' '.$month.'-'.$day.''; + $table_data .= ' '.$month.'-'.$day.''; } else { $table_data .= " "; } } @@ -2684,7 +2690,7 @@ class eq $month = $date_array[1]; $day = $date_array[2]; $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data); - $table_data .= ' '.$month.'-'.$day.''; + $table_data .= ' '.$month.'-'.$day.''; } else { $table_data .= " "; } } @@ -3191,7 +3197,7 @@ class eq $attended[$i][$cur_month]=1; $attendance[$monthnum[$cur_month]]++; } - $att_table .= ''; + $att_table .= ''; } else { $att_table .= ' '; } @@ -3805,13 +3811,27 @@ class eq $this->t->set_block('admin_t','upload','uploadhandle'); $this->t->set_block('admin_t','admin','adminhandle'); $this->t->set_block('admin_t','cmd','cmdhandle'); + $this->t->set_block('admin_t','presidency','presidencyhandle'); $this->t->set_var('upload_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.admin&action=upload')); + $this->t->set_var('presidency_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.admin&action=presidency')); $action = get_var('action',array('GET','POST')); $this->t->pfp('out','admin_t'); - + + $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC"; + $this->db->query($sql,__LINE__,__FILE__); + $i=0; + while ($this->db->next_record()) + { + $elder_id[$i] = $this->db->f('elder'); + $elder_name[$i] = $this->db->f('name'); + $elder2name[$elder_id[$i]] = $elder_name[$i]; + $i++; + } + array_multisort($elder_name, $elder_id); + if($action == 'upload') { $target_path = $this->upload_target_path . basename( $_FILES['uploadedfile']['name']); @@ -3915,12 +3935,238 @@ class eq $this->t->pfp('uploadhandle','upload',True); } } + else if($action == "presidency") + { + $new_data = get_var('eqpres',array('POST')); + foreach ($new_data as $entry) + { + $id = $entry['id']; + $email = $entry['email']; + $elder = $entry['elder']; + $name = $entry['name']; + $district = $entry['district']; + $president = $entry['president']; + $counselor = $entry['counselor']; + $secretary = $entry['secretary']; + $eqpresidency = $entry['eqpresidency']; + // Set the elder id to 0 for EQ Presidency tagged entry + if($eqpresidency == 1) { $elder="0"; } + // Re-look up the elder name for the ID if we aren't an EQ Presidency tagged entry + else { $name = $elder2name[$elder]; } + //print "id=$id elder=$elder name=$name email=$email district=$district president=$president "; + //print "counselor=$counselor secretary=$secretary eqpres=$eqpresidency
"; + + if(($elder > 0) || ($name != "")) { + if($id < $this->max_presidency_members) { + //print "Updating Existing Entry
"; + $this->db2->query("UPDATE eq_presidency set" . + " elder=" . $elder . + " ,district=" . $district . + " ,name='" . $name . "'" . + " ,email='" . $email . "'" . + " ,president='" . $president . "'" . + " ,counselor='" . $counselor . "'" . + " ,secretary='" . $secretary . "'" . + " ,eqpres='" . $eqpresidency . "'" . + " WHERE presidency=" . $id,__LINE__,__FILE__); + + } else { + //print "Adding New Entry
"; + $this->db2->query("INSERT INTO eq_presidency (presidency,elder,district,name," + . "email,president,counselor,secretary,eqpres,valid) " + . "VALUES (NULL,'" . $elder . "','" . $district . "','" + . $name . "','" . $email . "','" . $president . "','" + . $counselor . "','" . $secretary . "','" . $eqpres . "','1'" + .")",__LINE__,__FILE__); + } + } else { + //print "Ignoring Blank Entry
"; + } + } + + // Now update the eq_district table appropriately + + // Delete all the previous district entries from the table + $this->db->query("DELETE from eq_district where valid=1",__LINE__,__FILE__); + $this->db->query("DELETE from eq_district where valid=0",__LINE__,__FILE__); + + // Always add a "District 0" assigned to the High Priests Group + $district = 0; + $name = "High Priests"; + $elder = 0; + $valid = 0; + $this->db2->query("INSERT INTO eq_district (district,name,supervisor,valid) " + . "VALUES ('" . $district . "','" . $name . "','" + . $elder . "','" . $valid . "'" + .")",__LINE__,__FILE__); + + + // Requery the eq_presidency table + $sql = "SELECT * FROM eq_presidency where valid=1"; + $this->db->query($sql,__LINE__,__FILE__); + while ($this->db->next_record()) + { + // Extract the data for each presidency record + $id = $this->db->f('presidency'); + $elder = $this->db->f('elder'); + $name = $this->db->f('name'); + $district = $this->db->f('district'); + $name = $this->db->f('name'); + $valid = 1; + + // If we have a valid district, add it to the district table + if($district > 0) { + $this->db2->query("INSERT INTO eq_district (district,name,supervisor,valid) " + . "VALUES ('" . $district . "','" . $name . "','" + . $elder . "','" . $valid . "'" + .")",__LINE__,__FILE__); + } + + } + + $this->t->set_var('adminhandle',''); + $this->t->pfp('adminhandle','admin'); + } else { $this->t->set_var('adminhandle',''); $this->t->pfp('adminhandle','admin'); } + + // Now save off the data needed for an EQ Presidency Table Update + $sql = "SELECT * FROM eq_presidency where valid=1"; + $this->db->query($sql,__LINE__,__FILE__); + $table_data = ""; + $header_row = "ElderEmailDistrictPresidentCounselorSecretaryEQ Presidency"; + while ($this->db->next_record()) + { + // Extract the data for each presidency record + $id = $this->db->f('presidency'); + $elder = $this->db->f('elder'); + $district = $this->db->f('district'); + $name = $this->db->f('name'); + $email = $this->db->f('email'); + $president = $this->db->f('president'); + $counselor = $this->db->f('counselor'); + $secretary = $this->db->f('secretary'); + $eqpresidency = $this->db->f('eqpres'); + + // Create the forms needed in the table + $table_data .= ""; + + // Presidency ID + $table_data .= ''; + + // Elder + if($eqpresidency == 0) { + $table_data.= ''; + $table_data.=''; + } else { + $table_data.= ''; + $table_data.= ''; + } + + // Email Address + $table_data .= ''; + + // District + $table_data.= ''; + + // President + $table_data.= ''; + + // Counselor + $table_data.= ''; + + // Secretary + $table_data.= ''; + + // EQ Presidency + $table_data.= ''; + + // End of ROW + $table_data .= "\n"; + $tr_color = $this->nextmatchs->alternate_row_color($tr_color); + $this->t->set_var('tr_color',$tr_color); + } + + // Now create 1 blank row to always have a line available to add a new elder with + $id = $this->max_presidency_members; + $table_data .= ""; + // Presidency ID + $table_data .= ''; + // Elder + $table_data.= ''; + $table_data.=''; + // Email Address + $table_data.=''; + // District + $table_data.= ''; + // President + $table_data.= ''; + // Counselor + $table_data.= ''; + // Secretary + $table_data.= ''; + // EQ Presidency + $table_data.= ''; + // End of ROW + $table_data .= "\n"; + $tr_color = $this->nextmatchs->alternate_row_color($tr_color); + $this->t->set_var('tr_color',$tr_color); + + $this->t->set_var('header_row',$header_row); + $this->t->set_var('table_data',$table_data); + $this->t->pfp('presidencyhandle','presidency',True); + $this->save_sessiondata(); } diff --git a/parse_ward_data b/parse_ward_data deleted file mode 100755 index 82a1730..0000000 --- a/parse_ward_data +++ /dev/null @@ -1,136 +0,0 @@ -#!/usr/bin/perl - -use DBI; -use Getopt::Std; -################################################### -# GLOBALS -$dbname = "phpgroupware"; -$dbhost = "192.168.0.2"; -$dbport = 3306; -$dbuser = "phpgroupware"; -$dbpass = "phpgroupware"; -%hometeaching_data = (); -%membership_data = (); -getopts('vsn:o:b'); - -$monthname2num{'Jan'} = '01'; -$monthname2num{'Feb'} = '02'; -$monthname2num{'Mar'} = '03'; -$monthname2num{'Apr'} = '04'; -$monthname2num{'May'} = '05'; -$monthname2num{'Jun'} = '06'; -$monthname2num{'Jul'} = '07'; -$monthname2num{'Aug'} = '08'; -$monthname2num{'Sep'} = '09'; -$monthname2num{'Oct'} = '10'; -$monthname2num{'Nov'} = '11'; -$monthname2num{'Dec'} = '12'; - -###################################################################### -# SUBROUTINES -###################################################################### -sub csv_to_hash -{ - my ($filename, $hashref) = @_; - - open(FILE,$filename) || die "-E- Could not open $filename for reading\n"; - - my $found_header = 0; my $index = 0; - while() - { - $line = $_; - @data = split /\",/, $line; - if(!$found_header) { @header = @data; $found_header = 1; } - else { - foreach $i (0..$#data-1) { - $data[$i] =~ s/\"//g; - $header[$i] =~ s/\"//g; - $hashref->{$index}{$header[$i]} = $data[$i]; - #print "$index: $i: $header[$i]: $data[$i]\n"; - } - $index++; - } - } - - close(FILE); -} - -###################################################################### -sub print_hash -{ - my ($hashref) = @_; - - foreach $key (sort {$a <=> $b} keys %$hashref) { - print "Index: $key\n"; - foreach $field (keys %{$hashref->{$key}}) { - print "$field: $hashref->{$key}{$field}\n"; - } - print "\n"; - } -} - -###################################################################### -sub print_birthdays -{ - my ($hashref) = @_; - - foreach $key (sort {$a <=> $b} keys %$hashref) { - $name = ""; - $birthday = ""; - foreach $field (keys %{$hashref->{$key}}) { - if($field =~ /Full Name/) { $name = $hashref->{$key}{$field}; } - if($field =~ /Birth/) { $birthday = $hashref->{$key}{$field}; } - } - if($name ne "" && $birthday ne "") { printf "%-30s %-10s\n",$name,$birthday; } - } -} - -###################################################################### -# MAIN -###################################################################### - -################################################### -# Open a connection to the database -$dbh=DBI->connect("dbi:mysql:dbname=$dbname;host=$dbhost port=$dbport",$dbuser,$dbpass,{ - AutoCommit=>0, - PrintError=>0}) or print "Connect Failure:".$DBI::errstr."\n" and exit 2; - -################################################### -# Process command line options -if(defined $opt_n) { $datadir = $opt_n; } -else { $datadir = shift(@ARGV); } -print "-> Processing all ward data files in $datadir\n"; - -################################################### -# Parse Ward Data Files -&csv_to_hash("$datadir/Membership.csv",\%membership_data); -&csv_to_hash("$datadir/HomeTeaching.csv",\%hometeaching_data); - -if($opt_v) { - print "-> Membership Data Dump\n\n"; - &print_hash(\%membership_data); - print "-> HomeTeaching Data Dump\n\n"; - &print_hash(\%hometeaching_data); -} - -if($opt_b) { &print_birthdays(\%membership_data); } - -if($opt_s) { $dbh->disconnect(); exit; } - -################################################### -# Disconnect from the database -$dbh->disconnect(); - -###################################################################### - - - - - - - - - - - - diff --git a/setup/setup.inc.php b/setup/setup.inc.php index a144ba4..74e5dc1 100644 --- a/setup/setup.inc.php +++ b/setup/setup.inc.php @@ -29,7 +29,24 @@ $setup_info['eq']['maintainer_email'] = 'apippin@pippins.net'; /* The tables this app creates */ - /* $setup_info['eq']['tables'] = Array('eq'); */ + $setup_info['eq']['tables'][] = 'eq_aaronic'; + $setup_info['eq']['tables'][] = 'eq_activity'; + $setup_info['eq']['tables'][] = 'eq_appointment'; + $setup_info['eq']['tables'][] = 'eq_assignment'; + $setup_info['eq']['tables'][] = 'eq_attendance'; + $setup_info['eq']['tables'][] = 'eq_calling'; + $setup_info['eq']['tables'][] = 'eq_child'; + $setup_info['eq']['tables'][] = 'eq_companionship'; + $setup_info['eq']['tables'][] = 'eq_district'; + $setup_info['eq']['tables'][] = 'eq_elder'; + $setup_info['eq']['tables'][] = 'eq_family'; + $setup_info['eq']['tables'][] = 'eq_interview'; + $setup_info['eq']['tables'][] = 'eq_parent'; + $setup_info['eq']['tables'][] = 'eq_participation'; + $setup_info['eq']['tables'][] = 'eq_ppi'; + $setup_info['eq']['tables'][] = 'eq_presidency'; + $setup_info['eq']['tables'][] = 'eq_visit'; + $setup_info['eq']['tables'][] = 'eq_willingness'; /* The hooks this app includes, needed for hooks registration */ $setup_info['eq']['hooks'] = Array( diff --git a/sql/dot.cmd b/sql/dot.cmd new file mode 100755 index 0000000..9bd21b9 --- /dev/null +++ b/sql/dot.cmd @@ -0,0 +1 @@ +dot -Tjpg -o eq.jpg schema.dot diff --git a/sql/eq.jpg b/sql/eq.jpg new file mode 100644 index 0000000..7c1ff2d Binary files /dev/null and b/sql/eq.jpg differ diff --git a/sql/eq.sql b/sql/eq.sql new file mode 100644 index 0000000..3649953 --- /dev/null +++ b/sql/eq.sql @@ -0,0 +1,256 @@ +-- MySQL dump 10.11 +-- +-- Host: localhost Database: phpgroupware +-- ------------------------------------------------------ + +-- +-- Current Database: `phpgroupware` +-- + +CREATE DATABASE /*!32312 IF NOT EXISTS*/ `phpgroupware` /*!40100 DEFAULT CHARACTER SET latin1 */; + +USE `phpgroupware`; + +-- +-- Table structure for table `eq_aaronic` +-- +CREATE TABLE `eq_aaronic` ( + `aaronic` int(16) unsigned NOT NULL auto_increment, + `name` varchar(60) default NULL, + `phone` varchar(12) default NULL, + `valid` tinyint(1) default NULL, + PRIMARY KEY (`aaronic`) +) ENGINE=MyISAM AUTO_INCREMENT=92 DEFAULT CHARSET=latin1; + + +-- +-- Table structure for table `eq_activity` +-- +CREATE TABLE `eq_activity` ( + `activity` int(16) unsigned NOT NULL auto_increment, + `assignment` int(16) unsigned NOT NULL, + `date` date default NULL, + `notes` text, + PRIMARY KEY (`activity`), + KEY `assignment` (`assignment`) +) ENGINE=MyISAM AUTO_INCREMENT=33 DEFAULT CHARSET=latin1; + +-- +-- Table structure for table `eq_appointment` +-- +CREATE TABLE `eq_appointment` ( + `appointment` int(16) unsigned NOT NULL auto_increment, + `presidency` int(16) unsigned NOT NULL default '0', + `family` int(16) unsigned default '0', + `elder` int(16) unsigned default '0', + `date` date NOT NULL default '0000-00-00', + `time` time NOT NULL default '00:00:00', + `uid` bigint(64) unsigned NOT NULL default '0', + PRIMARY KEY (`appointment`) +) ENGINE=MyISAM AUTO_INCREMENT=132 DEFAULT CHARSET=latin1; + +-- +-- Table structure for table `eq_assignment` +-- +CREATE TABLE `eq_assignment` ( + `assignment` int(12) unsigned NOT NULL auto_increment, + `name` varchar(60) NOT NULL, + `code` varchar(12) default NULL, + PRIMARY KEY (`assignment`) +) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=latin1; + +-- +-- Dumping data for table `eq_assignment` +-- +LOCK TABLES `eq_assignment` WRITE; +/*!40000 ALTER TABLE `eq_assignment` DISABLE KEYS */; +INSERT INTO `eq_assignment` (`assignment`, `name`, `code`) VALUES (1,'Enrichment Night Babysitting','RS'),(2,'Building Lockup','LU'),(3,'Building Cleaning Coordinator','CC'),(4,'Missionary Splits','MS'),(5,'Stake Farm','SF'),(6,'Loveland Kitchen','LK'),(7,'Moves','MV'),(8,'Temple Kitchen & Laundary','TKL'),(9,'Temple Sealings','TS'),(10,'Temple Initatories','TI'); +/*!40000 ALTER TABLE `eq_assignment` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `eq_attendance` +-- +CREATE TABLE `eq_attendance` ( + `elder` int(16) unsigned NOT NULL default '0', + `date` date default NULL, + KEY `elder` (`elder`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +-- +-- Table structure for table `eq_calling` +-- +CREATE TABLE `eq_calling` ( + `indiv_id` int(16) unsigned default NULL, + `name` varchar(30) default NULL, + `organization` varchar(30) default NULL, + `position` varchar(30) default NULL, + `sequence` int(16) unsigned default NULL, + `sustained` varchar(30) default NULL, + KEY `indiv_id` (`indiv_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +-- +-- Table structure for table `eq_child` +-- +CREATE TABLE `eq_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 `eq_companionship` +-- + +CREATE TABLE `eq_companionship` ( + `companionship` int(16) unsigned NOT NULL default '0', + `elder` 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`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +-- +-- Table structure for table `eq_district` +-- +CREATE TABLE `eq_district` ( + `district` int(16) unsigned NOT NULL default '0', + `name` varchar(30) default NULL, + `supervisor` int(16) unsigned default NULL, + `valid` tinyint(1) default NULL, + PRIMARY KEY (`district`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; +LOCK TABLES `eq_district` WRITE; +/*!40000 ALTER TABLE `eq_district` DISABLE KEYS */; +INSERT INTO `eq_district` (`district`, `name`, `supervisor`, `valid`) VALUES (0,'High Priests',0,0); +/*!40000 ALTER TABLE `eq_district` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `eq_elder` +-- +CREATE TABLE `eq_elder` ( + `elder` int(16) unsigned NOT NULL auto_increment, + `name` varchar(60) default NULL, + `phone` varchar(12) default NULL, + `ppi_pri` int(10) unsigned NOT NULL default '1', + `ppi_notes` varchar(128) default NULL, + `int_pri` int(10) unsigned default '1', + `int_notes` varchar(128) default NULL, + `attending` tinyint(1) default '0', + `valid` tinyint(1) default NULL, + PRIMARY KEY (`elder`) +) ENGINE=MyISAM AUTO_INCREMENT=105 DEFAULT CHARSET=latin1; + +-- +-- Table structure for table `eq_family` +-- +CREATE TABLE `eq_family` ( + `family` int(16) unsigned NOT NULL auto_increment, + `hofh_id` int(16) unsigned NOT NULL default '0', + `name` varchar(30) NOT NULL default '', + `name_id` varchar(30) NOT NULL default '', + `elder_id` int(16) unsigned default '0', + `companionship` int(16) unsigned default NULL, + `visit_pri` int(10) unsigned default '1', + `visit_notes` varchar(128) default NULL, + `valid` tinyint(1) default NULL, + PRIMARY KEY (`family`) +) ENGINE=MyISAM AUTO_INCREMENT=277 DEFAULT CHARSET=latin1; + +-- +-- Table structure for table `eq_interview` +-- +CREATE TABLE `eq_interview` ( + `interview` int(16) unsigned NOT NULL auto_increment, + `interviewer` int(16) unsigned default NULL, + `elder` int(16) unsigned default NULL, + `aaronic` int(16) unsigned NOT NULL default '0', + `date` date default NULL, + `notes` text, + PRIMARY KEY (`interview`) +) ENGINE=MyISAM AUTO_INCREMENT=65 DEFAULT CHARSET=latin1; + +-- +-- Table structure for table `eq_parent` +-- +CREATE TABLE `eq_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 `eq_participation` +-- +CREATE TABLE `eq_participation` ( + `elder` int(16) unsigned NOT NULL default '0', + `activity` int(16) unsigned default NULL, + UNIQUE KEY `activity_ndx` (`elder`,`activity`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +-- +-- Table structure for table `eq_ppi` +-- +CREATE TABLE `eq_ppi` ( + `ppi` int(16) unsigned NOT NULL auto_increment, + `interviewer` int(16) unsigned default NULL, + `elder` int(16) unsigned default NULL, + `date` date default NULL, + `notes` text, + `eqpresppi` tinyint(1) default '0', + PRIMARY KEY (`ppi`) +) ENGINE=MyISAM AUTO_INCREMENT=248 DEFAULT CHARSET=latin1; + + +-- +-- Table structure for table `eq_presidency` +-- +CREATE TABLE `eq_presidency` ( + `presidency` int(16) unsigned NOT NULL auto_increment, + `elder` int(16) unsigned NOT NULL default '0', + `district` int(16) unsigned default '0', + `name` varchar(60) NOT NULL, + `email` varchar(60) NOT NULL, + `president` tinyint(1) default '0', + `counselor` tinyint(1) default '0', + `secretary` tinyint(1) default '0', + `valid` tinyint(1) default '1', + KEY `presidency` (`presidency`), + KEY `elder` (`elder`) +) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; + +-- +-- Table structure for table `eq_visit` +-- +CREATE TABLE `eq_visit` ( + `visit` int(16) unsigned NOT NULL auto_increment, + `family` int(16) unsigned default NULL, + `companionship` int(16) unsigned default NULL, + `date` date default NULL, + `notes` text, + `visited` enum('y','n','') default NULL, + PRIMARY KEY (`visit`) +) ENGINE=MyISAM AUTO_INCREMENT=9513 DEFAULT CHARSET=latin1; + +-- +-- Table structure for table `eq_willingness` +-- +CREATE TABLE `eq_willingness` ( + `elder` int(16) unsigned NOT NULL, + `assignment` int(16) unsigned NOT NULL, + `willing` enum('y','n','') NOT NULL, + KEY `elder` (`elder`,`assignment`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; diff --git a/sql/schema.dot b/sql/schema.dot new file mode 100644 index 0000000..99fb6c4 --- /dev/null +++ b/sql/schema.dot @@ -0,0 +1,110 @@ +digraph schema { + graph [ + rankdir = "LR" + ]; + family [ + label = " family|| companionship| name_id| hofh_id| elder_id| visit_pri| visit_notes| valid" + shape = "record" + ]; + elder [ + label = " elder|| name|

phone| ppi_pri| ppi_notes| int_pri| int_notes| attending| valid" + shape = "record" + ]; + companionship [ + label = " companionship|| elder| aaronic| district| valid" + shape = "record" + ]; + visit [ + label = " visit|| family| companionship| date| notes| visited" + shape = "record" + ]; + ppi [ + label = "

ppi|| interviewer| elder| date| notes|

eqpresppi" + shape = "record" + ]; + activity [ + label = " activity|| assignment| date| notes" + shape = "record" + ]; + participation [ + label = "participation|| elder| activity" + shape = "record" + ]; + attendance [ + label = "attendance|| elder| date" + shape = "record" + ]; + child [ + label = " child|| family| indiv_id| name| birthday| valid" + shape = "record" + ]; + parent [ + label = "

parent|| family| name| birthday|

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

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

presidency| family| elder | date| time| uid" + shape = "record" + ]; + assignment [ + label = " assignment|| name| code" + shape = "record" + ]; + calling [ + label = "calling|| indiv_id| name| organization|

position| sequence| sustained" + shape = "record" + ]; + district [ + label = " district|| name| supervisor| valid" + shape = "record" + ]; + interview [ + label = " interview|| interviewer| elder| aaronic| date| notes" + shape = "record" + ]; + presidency [ + label = "

presidency|| elder| district| name| email| president| counselor| secreatary| valid" + shape = "record" + ]; + willingness [ + label = " elder|| assignment| willing" + shape = "record" + ]; + + family:c -> companionship:c + companionship:e -> elder:e + companionship:a -> aaronic:a + + appointment:e -> elder:e + appointment:f -> family:f + + interview:e -> elder:e + interview:in -> elder:e + interview:a -> aaronic:a + + presidency:e -> elder:e + presidency:d -> district:d + + willingness:e -> elder:e + willingness:a -> assignment:a + + activity:s -> assignment:a + + visit:c -> companionship:c + visit:f -> family:f + + ppi:i -> elder:e + ppi:e -> elder:e + + participation:e -> elder:e + participation:a -> activity:a + + attendance:e -> elder:e + + child:f -> family:f + parent:f -> family:f +} diff --git a/templates/default/admin.tpl b/templates/default/admin.tpl index d2a87ba..9285312 100644 --- a/templates/default/admin.tpl +++ b/templates/default/admin.tpl @@ -19,10 +19,10 @@

Choose the MLS data file to upload (.zip):
-
+ It must contain the following files from MLS: Membership.csv, Hometeaching.csv, Organization.csv +

  (Import can take up to 30 seconds) -
@@ -41,6 +41,33 @@ + +
+ + + + +
+
+ Update the EQ Presidency Table +

+
+ + {header_row} + {table_data} +
+ Notes: +
Make sure you have at least 1 EQ Presidency member that is marked with "EQ Presidency=1". +
This entry is used to email the entire presidency, and its email address should cause that to happen. +
If a member of the presidency is not a District Leader, make sure to set their "District=0". +
The President, Counselor, Secretary, and EQ Presidency fields are boolean value (true|false) flags. +

+ + +
+
+ + diff --git a/x.gif b/x.gif deleted file mode 100755 index 12ed1d5..0000000 Binary files a/x.gif and /dev/null differ diff --git a/x.psd b/x.psd deleted file mode 100755 index 8353958..0000000 Binary files a/x.psd and /dev/null differ