From: Owen Leonard <owen@balawis.leonard.fam>
Date: Sat, 18 Sep 2010 19:42:22 +0000 (-0600)
Subject: removed name field from tc_district
X-Git-Tag: release_1_0_0~25
X-Git-Url: http://git.pippins.net/%27%20.%20%24this-%3Ephpgw_js_url%20.%20%27/jscalendar/static/%7Bediturl%7D?a=commitdiff_plain;h=c0138a3e56518fd73dfe4d93c30d8e36ce062d87;p=eq%2F.git

removed name field from tc_district
---

diff --git a/bin/import_ward_data b/bin/import_ward_data
index 6bbfe56..a11906b 100755
--- a/bin/import_ward_data
+++ b/bin/import_ward_data
@@ -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();
diff --git a/inc/class.tc.inc.php b/inc/class.tc.inc.php
index 06a11e1..f766b12 100644
--- a/inc/class.tc.inc.php
+++ b/inc/class.tc.inc.php
@@ -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__);
 				}
diff --git a/sql/schema.dot b/sql/schema.dot
index b5d91fa..2a88bf6 100644
--- a/sql/schema.dot
+++ b/sql/schema.dot
@@ -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   [
diff --git a/sql/tc.jpg b/sql/tc.jpg
index 6b3279d..b1ca53c 100644
Binary files a/sql/tc.jpg and b/sql/tc.jpg differ
diff --git a/sql/tc.sql b/sql/tc.sql
index 6090cdd..ecea939 100644
--- a/sql/tc.sql
+++ b/sql/tc.sql
@@ -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`)