removed name field from tc_presidency, updated tc.jpg
authorOwen Leonard <owen@balawis.leonard.fam>
Sat, 18 Sep 2010 19:25:36 +0000 (13:25 -0600)
committerOwen Leonard <owen@balawis.leonard.fam>
Sat, 18 Sep 2010 19:25:36 +0000 (13:25 -0600)
bin/import_ward_data
inc/class.tc.inc.php
sql/schema.dot
sql/tc.jpg
sql/tc.sql

index 670383662bcd0a0d9bef1649a5a5c0612dcf0852..6bbfe5657c72c750d25b1dd097ec60d8b06c8a03 100755 (executable)
@@ -249,16 +249,16 @@ sub update_tc_district_table
     $sth = $dbh->prepare("select * from tc_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 tc_individual where name='$supervisor_name'");
-       $sth2->execute or die "-E- DB error: $DBI::errstr\n";
-       $sqlhashref2 = $sth2->fetchrow_hashref;
-       $supervisor_id = $sqlhashref2->{individual};
-       $sth2->finish();
-       $sth2 = $dbh->prepare("update tc_district set supervisor='$supervisor_id' where district='$district'");
-       $sth2->execute or die "-E- DB error: $DBI::errstr\n";
-       $sth2->finish();
+               $supervisor_name = $sqlhashref->{name};
+               $district = $sqlhashref->{district};
+               $sth2 = $dbh->prepare("select * from tc_individual where name='$supervisor_name'");
+               $sth2->execute or die "-E- DB error: $DBI::errstr\n";
+               $sqlhashref2 = $sth2->fetchrow_hashref;
+               $supervisor_id = $sqlhashref2->{individual};
+               $sth2->finish();
+               $sth2 = $dbh->prepare("update tc_district set supervisor='$supervisor_id' where district='$district'");
+               $sth2->execute or die "-E- DB error: $DBI::errstr\n";
+               $sth2->finish();
     }
     $sth->finish();
 }
index c47ef9552c14ac35c527bc07dbc28b4cad865a95..06a11e10bbca0918c68625279147f63f6ff01400 100644 (file)
@@ -1366,7 +1366,7 @@ class tc
                $year = date('Y');
 
                // Get the President
-               $sql = "SELECT * FROM tc_presidency where president=1 and valid=1";
+               $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti where tp.individual=ti.individual AND tp.president=1 AND tp.valid=1";
                $this->db->query($sql,__LINE__,__FILE__);
                if($this->db->next_record()) {
                        $president_name = $this->db->f('name');
@@ -1377,16 +1377,7 @@ class tc
                        $interviewer = $this->db->f('individual');
                        $district_number = '*';
                        $district_name = $president_name;
-                       $sql = "SELECT * FROM tc_individual where individual='$president_id'";
-                       $this->db2->query($sql,__LINE__,__FILE__);
-                       if($this->db2->next_record()) {
-                               $mls_id = $this->db2->f('mls_id');
-                       }
-                       $sql = "SELECT * FROM tc_individual where mls_id='$mls_id'";
-                       $this->db2->query($sql,__LINE__,__FILE__);
-                       if($this->db2->next_record()) {
-                               $president_address = $this->db2->f('address');
-                       }
+                       $president_address = $this->db->f('address');
                } else {
                        print "<hr><font color=red><h3>-E- Unable to locate President in tc_presidency table</h3></font></hr>";
                        return;
@@ -1784,7 +1775,7 @@ class tc
                }
 
                // Get the Districts
-               $sql = "SELECT * FROM tc_district where valid=1 ORDER BY district ASC";
+               $sql = "SELECT * FROM tc_district AS td JOIN tc_presidency AS tp WHERE td.district=tp.district AND td.valid=1 ORDER BY td.district ASC";
                $this->db->query($sql,__LINE__,__FILE__);
                $i=0;
                while ($this->db->next_record()) {
@@ -1792,11 +1783,7 @@ class tc
                        $districts[$i]['district'] = $this->db->f('district');
                        $districts[$i]['name'] = $this->db->f('name');
                        $districts[$i]['supervisor'] = $this->db->f('supervisor');
-                       $sql = "SELECT * FROM tc_presidency where district=$district and valid=1";
-                       $this->db2->query($sql,__LINE__,__FILE__);
-                       if($this->db2->next_record()) {
-                               $districts[$i]['presidency'] = $this->db2->f('presidency');
-                       }
+                       $districts[$i]['presidency'] = $this->db->f('presidency');
                        $i++;
                }
 
@@ -2144,7 +2131,7 @@ class tc
                $appt_table_data = ""; 
 
                // Find out what the President ID is
-               $sql = "SELECT * FROM tc_presidency where president=1 and valid=1";
+               $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.president=1 AND tp.valid=1";
                $this->db->query($sql,__LINE__,__FILE__);
                if($this->db->next_record()) {
                        $presidency_name = $this->db->f('name');
@@ -2357,7 +2344,7 @@ class tc
                        $this->t->set_var('lang_num_months','Years of History');
                }
 
-               $sql = "SELECT * FROM tc_presidency where president=1 and valid=1";
+               $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.president=1 AND tp.valid=1";
                $this->db->query($sql,__LINE__,__FILE__);
                if($this->db->next_record()) {
                        $president_name = $this->db->f('name');
@@ -2481,7 +2468,7 @@ class tc
                $notes = get_var('notes',array('GET','POST'));
                $interview_type = get_var('interview_type',array('GET','POST'));
 
-               $sql = "SELECT * FROM tc_presidency where valid=1 and (president=1 or counselor=1 or secretary=1)";
+               $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1 AND (tp.president=1 OR tp.counselor=1 OR tp.secretary=1)";
                $this->db2->query($sql,__LINE__,__FILE__);
                while ($this->db2->next_record()) {
                        $indiv = $this->db2->f('individual');
@@ -2804,7 +2791,7 @@ class tc
                $notes = get_var('notes',array('GET','POST'));
                $interview_type = get_var('interview_type',array('GET','POST'));
 
-               $sql = "SELECT * FROM tc_presidency where valid=1 and (president=1 or counselor=1 or secretary=1 or district!=0)";
+               $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1 AND (tp.president=1 OR tp.counselor=1 OR tp.secretary=1 OR tp.district!=0)";
                $this->db2->query($sql,__LINE__,__FILE__);
                while ($this->db2->next_record()) {
                        $indiv = $this->db2->f('individual');
@@ -3549,7 +3536,7 @@ class tc
                $header_row.= "<th width=$location_width><font size=-2>Location</th>";
                $table_data = "";
 
-               $sql = "SELECT * FROM tc_presidency where valid=1 GROUP BY individual ORDER BY name ASC";
+               $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1 GROUP BY tp.individual ORDER BY ti.name ASC";
                $this->db->query($sql,__LINE__,__FILE__);
                $i=0;
                while ($this->db->next_record()) {
@@ -4056,7 +4043,6 @@ class tc
                                                $this->db2->query("UPDATE tc_presidency set" .
                                                                  " individual=" . $indiv . 
                                                                  " ,district=" . $district . 
-                                                                 " ,name='" . $name . "'" .
                                                                  " ,email='" . $email . "'" .
                                                                  " ,president='" . $president . "'" .
                                                                  " ,counselor='" . $counselor . "'" .
@@ -4064,10 +4050,10 @@ class tc
                                                                  " WHERE presidency=" . $id,__LINE__,__FILE__);
                                        } else {
                                                //print "Adding New Entry<br>";
-                                               $this->db2->query("INSERT INTO tc_presidency (presidency,individual,district,name," .
+                                               $this->db2->query("INSERT INTO tc_presidency (presidency,individual,district," .
                                                                  "email,president,counselor,secretary,valid) " .
                                                                  "VALUES (NULL,'" . $indiv . "','" . $district . "','" .
-                                                                 $name . "','" . $email . "','" . $president  . "','" .
+                                                                 $email . "','" . $president  . "','" .
                                                                  $counselor . "','" . $secretary . "','1'" .
                                                                  ")",__LINE__,__FILE__);
                                        }
@@ -4093,7 +4079,7 @@ class tc
                                          ")",__LINE__,__FILE__);
 
                        // Requery the tc_presidency table
-                       $sql = "SELECT * FROM tc_presidency where valid=1";
+                       $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1";
                        $this->db->query($sql,__LINE__,__FILE__);
                        while ($this->db->next_record()) {
                                // Extract the data for each presidency record
@@ -4101,7 +4087,6 @@ class tc
                                $indiv = $this->db->f('individual');
                                $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
@@ -4124,7 +4109,7 @@ class tc
 
                // Now save off the data needed for a Presidency Table Update
 
-               $sql = "SELECT * FROM tc_presidency where valid=1";
+               $sql = "SELECT tp.*, ti.name FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1";
                $this->db->query($sql,__LINE__,__FILE__);
                $table_data = "";
                $header_row = "<th>Individual</th><th>Email</th><th>District</th><th>President</th><th>Counselor</th><th>Secretary</th>";
@@ -4294,7 +4279,7 @@ class tc
                        $dtstart = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds,$month,$day,$year));
                        $dtstartstr = date("l, F d, o g:i A", mktime($hour,$minute,$seconds,$month,$day,$year));
 
-                       $sql = "SELECT * FROM tc_presidency where presidency='$presidency'";
+                       $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.presidency='$presidency'";
                        $this->db2->query($sql,__LINE__,__FILE__);
                        if($this->db2->next_record()) {
                                $email = $this->db2->f('email');
index b189159ac8281ee7932ea7383f655a29b783e703..b5d91fa23ca65badf8787ec5dc7a23017df2535f 100644 (file)
@@ -2,89 +2,124 @@ digraph schema {
   graph [
     rankdir = "LR"
   ];
-  family   [
-    label = "<f> family||<i> hofh_id|<n> name|<ni> name_id|<i> indiv_id|<c> companionship|<vp> visit_pri|<vn> visit_notes|<v> valid"
+  activity   [
+    label = "activity||<a> activity|<s> assignment|<t> date|<n> notes"
+    shape = "record"
+  ];
+  appointment   [
+    label = "appointment||<a> appointment|<p> presidency|<f> family|<i> individual |<d> date|<t> time|<l> location|<u> uid"
+    shape = "record"
+  ];
+  assignment    [
+    label = "assignment||<a> assignment|<n> name|<ab> abbreviation"
+    shape = "record"
+  ];
+  attendance   [
+    label = "attendance||<i> individual|<d> date"
     shape = "record"
   ];
-  indiv   [
-    label = "<i> indiv||<id> indiv_id|<n> name|<a> address|<p> phone|<em> email|<f> family|<hh> hh position|<po> priesthood|<st> steward|<pr> prospective|<pp> ppi_pri|<t> ppi_notes|<hp> hti_pri|<hn> hti_notes|<a> attending|<v> valid"
+  calling       [
+    label = "calling||<n> name|<o> organization|<p> position|<s> sustained"
     shape = "record"
   ];
   companionship   [
-    label = "<c> companionship||<i> indiv|<d> district|<v> valid"
+    label = "companionship||<c> companionship|<i> individual|<d> district|<sp> scheduling_priority|<v> valid"
     shape = "record"
   ];
-  visit   [
-    label = "<v> visit||<f> family|<c> companionship|<c1> companion1|<c2> companion2|<t> date|<n> notes|<v> visited|<vt> visit_type"
+  district      [
+    label = "district||<d> district|<n> name|<s> supervisor|<v> valid"
     shape = "record"
   ];
-  interview   [
-    label = "<in> interview||<i> interviewer|<il> indiv|<t> date|<n> notes|<it> interview_type"
+  individual   [
+    label = "individual||<i> individual|<id> mls_id|<n> name|<a> address|<p> phone|<em> email|<hh> hh position|<pr> priesthood|<st> steward|<sp> scheduling_priority|<a> attending|<v> valid"
     shape = "record"
   ];
-  activity   [
-    label = "<a> activity||<s> assignment|<t> date|<n> notes"
+  family   [
+    label = "family||<f> family|<i> individual|<c> companionship|<sp> scheduling_priority|<v> valid"
     shape = "record"
   ];
   participation   [
-    label = "participation||<i> indiv|<a> activity"
+    label = "participation||<i> individual|<a> activity"
     shape = "record"
   ];
-  attendance   [
-    label = "attendance||<i> indiv|<d> date"
+  interview   [
+    label = "interview||<in> interview|<i> interviewer|<il> individual|<t> date|<n> notes|<it> interview_type"
     shape = "record"
   ];
-  appointment   [
-    label = "<a> appointment||<p> presidency|<f> family|<i> indiv |<d> date|<t> time|<l> location|<u> uid"
+  presidency    [
+    label = "presidency||<p> presidency||<i> individual|<d> district|<em> email|<pr> president|<cn> counselor|<sec> secreatary|<v> valid"
     shape = "record"
   ];
-  assignment    [
-    label = "<a> assignment||<n> name|<c> code"
+  visit   [
+    label = "visit||<v> visit|<f> family|<c> companionship|<c1> companion1|<c2> companion2|<t> date|<n> notes|<v> visited|<vt> visit_type"
     shape = "record"
   ];
-  calling       [
-    label = "calling||<i> indiv_id|<n> name|<o> organization|<p> position|<s> sequence|<t> sustained"
+  willingness   [
+    label = "willingness||<i> individual|<a> assignment|<w> willing"
     shape = "record"
   ];
-  district      [
-    label = "<d> district||<n> name|<s> supervisor|<v> valid"
+  scheduling_priority   [
+    label = "scheduling_priority||<sp> scheduling_priority|<p> priority|<n> notes"
     shape = "record"
   ];
-  presidency    [
-    label = "<p> presidency||<i> indiv|<d> district|<n> name|<em> email|<pr> president|<cn> counselor|<sec> secreatary|<v> valid"
+  email_list   [
+    label = "email_list||<e> email_list|<n> name"
     shape = "record"
   ];
-  willingness   [
-    label = "<i> indiv||<a> assignment|<w> willing"
+  email_list_membership   [
+    label = "email_list_membership||<i> individual|<e> email_list"
+    shape = "record"
+  ];
+  accomplishment   [
+    label = "accomplishment||<a> accomplishment|<i> individual|<d> date|<t> task|<n> note"
+    shape = "record"
+  ];
+  task   [
+    label = "task||<t> task|<n> name|<d> description"
     shape = "record"
   ];
 
-  family:c        -> companionship:c
-  companionship:i -> indiv:i
+  activity:s      -> assignment:a
 
-  appointment:i   -> indiv:i
+  appointment:p   -> presidency:p
   appointment:f   -> family:f
+  appointment:i   -> individual:i
 
-  interview:il    -> indiv:i
-  interview:i     -> indiv:i
+  attendance:i    -> individual:i
 
-  presidency:i    -> indiv:i
-  presidency:d    -> district:d
+  companionship:i -> individual:i
+  companionship:d -> district:d
+  companionship:sp -> scheduling_priority:sp
+  
+  district:s      -> individual:i
+  
+  individual:sp   -> scheduling_priority:sp
+  
+  family:i        -> individual:i
+  family:c        -> companionship:c
+  family:sp       -> scheduling_priority:sp
 
-  willingness:i   -> indiv:i
-  willingness:a   -> assignment:a
+  participation:i -> individual:i
+  participation:a -> activity:a
 
-  activity:s      -> assignment:a
+  interview:il    -> individual:i
+  interview:i     -> individual:i
+
+  presidency:i    -> individual:i
+  presidency:d    -> district:d
 
   visit:c         -> companionship:c
   visit:f         -> family:f
   visit:c1        -> presidency:i
   visit:c2        -> presidency:i
 
-  participation:i -> indiv:i
-  participation:a -> activity:a
-
-  attendance:i    -> indiv:i
+  willingness:i   -> individual:i
+  willingness:a   -> assignment:a
 
-  indiv:f        -> family:f
+  email_list_membership:i  -> individual:i
+  email_list_membership:e  -> email_list:e
+  
+  accomplishment:i   -> individual:i
+  accomplishment:t   -> task:t
+  
 }
index 487cdfa8480359a4bcd83e8a58e8c0615fd0ac1e..6b3279d20073e36bb6438ed7bb592edecae7af66 100644 (file)
Binary files a/sql/tc.jpg and b/sql/tc.jpg differ
index fddc9242b8b483e967613a537a9ad6c9f1af7789..6090cddb2208b01f5a0f607a592f26f4083a4708 100644 (file)
@@ -162,7 +162,6 @@ CREATE TABLE `tc_presidency` (
   `presidency` int(16) unsigned NOT NULL auto_increment,
   `individual` 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',