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

index 6bbfe5657c72c750d25b1dd097ec60d8b06c8a03..a11906b99977bef3d8201971d9be73fd9c5f0f1b 100755 (executable)
@@ -232,37 +232,6 @@ sub update_tc_calling_table()
        }
 }
 
-# TC_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_tc_district_table
-{
-    # Districts should be created by hand. This subroutine only
-    # updates the supervisor's ID in each district.
-    print "\n-> Updating tc_district table\n";
-    $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();
-    }
-    $sth->finish();
-}
-
 # TC_COMPANIONSHIP
 #+----------------------+------------------+------+-----+---------+-------+
 #| Field                | Type             | Null | Key | Default | Extra |
@@ -694,7 +663,6 @@ if($opt_s) { $dbh->disconnect(); exit; }
 # Now update the various eq DB tables
 &update_tc_calling_table();
 &update_tc_individual_table();
-&update_tc_district_table();
 &update_tc_companionship_table();
 &update_tc_family_table();
 &update_tc_visit_table();
index 06a11e10bbca0918c68625279147f63f6ff01400..f766b1287d26f183f6ae17132a6a74b3669bac0a 100644 (file)
@@ -203,7 +203,7 @@ class tc
                $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
                $this->t->set_var('title','Hometeaching'); 
 
-               $sql = "SELECT * FROM tc_district where valid=1 ORDER BY district ASC";
+               $sql = "SELECT * FROM tc_district AS td JOIN tc_individual AS ti WHERE td.supervisor=ti.individual AND td.valid=1 ORDER BY td.district ASC";
                $this->db->query($sql,__LINE__,__FILE__);
                $i=0;
                while ($this->db->next_record()) {
@@ -1775,7 +1775,7 @@ class tc
                }
 
                // Get the Districts
-               $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";
+               $sql = "SELECT * FROM tc_district AS td JOIN (tc_presidency AS tp, tc_individual AS ti) WHERE td.district=tp.district AND td.supervisor=ti.individual AND td.valid=1 ORDER BY td.district ASC";
                $this->db->query($sql,__LINE__,__FILE__);
                $i=0;
                while ($this->db->next_record()) {
@@ -1889,7 +1889,7 @@ class tc
                        $i=0;
                        for ($j=0; $j < count($unique_companionships); $j++) {
                                // Select all the companions from each companionship
-                               $sql = "SELECT * FROM tc_companionship AS tc JOIN (tc_scheduling_priority AS tsp, tc_individual as ti) WHERE tc.scheduling_priority=tsp.scheduling_priority AND tc.individual=ti.individual AND tc.valid=1 AND tc.companionship=". $unique_companionships[$j]['companionship'];
+                               $sql = "SELECT * FROM tc_companionship AS tc JOIN (tc_scheduling_priority AS tsp, tc_individual AS ti) WHERE tc.scheduling_priority=tsp.scheduling_priority AND tc.individual=ti.individual AND tc.valid=1 AND tc.companionship=". $unique_companionships[$j]['companionship'];
                                $this->db->query($sql,__LINE__,__FILE__);
                                $k=0; $int_completed=0;
                                $comp = $unique_companionships[$j]['companionship'];
@@ -2601,7 +2601,7 @@ class tc
                else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
                else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
 
-               $sql = "SELECT * FROM tc_district where valid=1 ORDER BY district ASC";
+               $sql = "SELECT * FROM tc_district AS td JOIN tc_individual AS ti WHERE td.supervisor=ti.individual AND td.valid=1 ORDER BY td.district ASC";
                $this->db->query($sql,__LINE__,__FILE__);
                $i=0;
                while ($this->db->next_record()) {
@@ -4073,8 +4073,8 @@ class tc
                        $name = "High Priests";
                        $indiv = 0;
                        $valid = 0;
-                       $this->db2->query("INSERT INTO tc_district (district,name,supervisor,valid) " .
-                                         "VALUES ('" . $district . "','" . $name . "','" .
+                       $this->db2->query("INSERT INTO tc_district (district,supervisor,valid) " .
+                                         "VALUES ('" . $district . "','" . 
                                          $indiv . "','" . $valid . "'" .
                                          ")",__LINE__,__FILE__);
 
@@ -4091,8 +4091,8 @@ class tc
 
                                // If we have a valid district, add it to the district table
                                if($district > 0) {
-                                       $this->db2->query("INSERT INTO tc_district (district,name,supervisor,valid) " .
-                                                         "VALUES ('" . $district . "','" . $name . "','" .
+                                       $this->db2->query("INSERT INTO tc_district (district,supervisor,valid) " .
+                                                         "VALUES ('" . $district . "','" . 
                                                          $indiv . "','" . $valid . "'" .
                                                          ")",__LINE__,__FILE__);
                                }
index b5d91fa23ca65badf8787ec5dc7a23017df2535f..2a88bf6072a955f82ac12042a9eb313b59de2526 100644 (file)
@@ -27,7 +27,7 @@ digraph schema {
     shape = "record"
   ];
   district      [
-    label = "district||<d> district|<n> name|<s> supervisor|<v> valid"
+    label = "district||<d> district|<s> supervisor|<v> valid"
     shape = "record"
   ];
   individual   [
index 6b3279d20073e36bb6438ed7bb592edecae7af66..b1ca53c901989c8a42fa289dbeaaa3e13e924455 100644 (file)
Binary files a/sql/tc.jpg and b/sql/tc.jpg differ
index 6090cddb2208b01f5a0f607a592f26f4083a4708..ecea939e05aee03e176f801840b360bb8bc55264 100644 (file)
@@ -95,7 +95,6 @@ CREATE TABLE `tc_companionship` (
 --
 CREATE TABLE `tc_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`)