From: Owen Leonard <owen@balawis.leonard.fam>
Date: Sun, 31 Oct 2010 21:56:23 +0000 (-0600)
Subject: converged president,counselor,secretary fields in tc_leader into one type field
X-Git-Url: http://git.pippins.net/images/%7Bdelete%7D?a=commitdiff_plain;h=b5c74cd3f678ed412df81cda7f8f77344d374d7a;p=eq%2F.git

converged president,counselor,secretary fields in tc_leader into one type field
---

diff --git a/bin/upgrade_1_1_0_to_1_1_1 b/bin/upgrade_1_1_0_to_1_1_1
index 3098d49..5c934cb 100755
--- a/bin/upgrade_1_1_0_to_1_1_1
+++ b/bin/upgrade_1_1_0_to_1_1_1
@@ -60,6 +60,21 @@ $sth->execute or die "-E- DB error: $DBI::errstr\n";
 $sth = $dbh->prepare("RENAME TABLE `tc_presidency` TO `tc_leader`");
 $sth->execute or die "-E- DB error: $DBI::errstr\n";
 
+# add type field to tc_leader in place of president, counselor, secretary fields
+$sth = $dbh->prepare("ALTER TABLE `tc_leader` ADD `type` ENUM( 'P', 'C', 'S', 'D' ) NOT NULL AFTER `email`");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+$sth = $dbh->prepare("UPDATE tc_leader SET type='P' WHERE president=1");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+$sth = $dbh->prepare("UPDATE tc_leader SET type='C' WHERE counselor=1");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+$sth = $dbh->prepare("UPDATE tc_leader SET type='S' WHERE secretary=1");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+$sth = $dbh->prepare("UPDATE tc_leader SET type='D' WHERE president=0 AND counselor=0 AND secretary=0");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+$sth = $dbh->prepare("ALTER TABLE `tc_leader` DROP `president`, DROP `counselor`, DROP `secretary`");
+$sth->execute or die "-E- DB error: $DBI::errstr\n";
+
+
 print "-> Done!\n";
 
 ###################################################
diff --git a/inc/class.tc.inc.php b/inc/class.tc.inc.php
index 6a6a6e7..59aa4c0 100644
--- a/inc/class.tc.inc.php
+++ b/inc/class.tc.inc.php
@@ -874,7 +874,7 @@ class tc
 		$email_contents .= "\r\n";
 		
 		// email changes to leader
-		$sql = "SELECT DISTINCT tp.email AS email1, ti.email AS email2 FROM tc_leader AS tl JOIN tc_individual AS ti WHERE tl.individual=ti.individual AND (tl.president=1 OR tl.counselor=1 OR tl.secretary=1) AND tl.valid=1";
+		$sql = "SELECT DISTINCT tp.email AS email1, ti.email AS email2 FROM tc_leader AS tl JOIN tc_individual AS ti WHERE tl.individual=ti.individual AND (tl.type='P' OR tl.type='C' OR tl.type='S') AND tl.valid=1";
 		$this->db->query($sql,__LINE__,__FILE__);
 		while ($this->db->next_record()) {
 			$email = "";
@@ -889,7 +889,7 @@ class tc
 				$to .= ", $email";
 			}
 		}
-		$sql = "SELECT DISTINCT tp.email AS email1, ti.email AS email2 FROM tc_leader AS tl JOIN tc_individual AS ti WHERE tl.individual=ti.individual AND tl.president=1 AND tl.valid=1";
+		$sql = "SELECT DISTINCT tp.email AS email1, ti.email AS email2 FROM tc_leader AS tl JOIN tc_individual AS ti WHERE tl.individual=ti.individual AND tl.type='P' AND tl.valid=1";
 		$this->db->query($sql,__LINE__,__FILE__);
 		if ($this->db->next_record()) {
 			if ($this->db->f('email1') != "") {
@@ -1965,9 +1965,9 @@ class tc
 
 		// Get the President
 		$sql = "SELECT * FROM tc_leader AS tl JOIN tc_individual AS ti where tl.individual=ti.individual AND tl.valid=1 AND ";
-		if($this->yearly_ppi_interviewer == 1) { $sql .= " (tl.president=1)"; }
-		if($this->yearly_ppi_interviewer == 2) { $sql .= " (tl.president=1 OR tl.counselor=1)"; }
-		if($this->yearly_ppi_interviewer == 3) { $sql .= " (tl.president=1 OR tl.counselor=1 OR tl.secretary=1)"; }
+		if($this->yearly_ppi_interviewer == 1) { $sql .= " (tl.type='P')"; }
+		if($this->yearly_ppi_interviewer == 2) { $sql .= " (tl.type='P' OR tl.type='C')"; }
+		if($this->yearly_ppi_interviewer == 3) { $sql .= " (tl.type='P' OR tl.type='C' OR tl.type='S')"; }
 		$this->db->query($sql,__LINE__,__FILE__);
 		while ($this->db->next_record()) {
 		  $leader_name = $this->db->f('name');
@@ -2625,7 +2625,7 @@ class tc
 		$appt_table_data = ""; 
 
 		// Find out what the President ID is
-		$sql = "SELECT * FROM tc_leader AS tl JOIN tc_individual AS ti WHERE tl.individual=ti.individual AND tl.president=1 AND tl.valid=1";
+		$sql = "SELECT * FROM tc_leader AS tl JOIN tc_individual AS ti WHERE tl.individual=ti.individual AND tl.type='P' AND tl.valid=1";
 		$this->db->query($sql,__LINE__,__FILE__);
 		if($this->db->next_record()) {
 			$leader_name = $this->db->f('name');
@@ -2832,7 +2832,7 @@ class tc
 			$this->t->set_var('lang_num_months','Years of History');
 		}
 
-		$sql = "SELECT * FROM tc_leader AS tl JOIN tc_individual AS ti WHERE tl.individual=ti.individual AND tl.president=1 AND tl.valid=1";
+		$sql = "SELECT * FROM tc_leader AS tl JOIN tc_individual AS ti WHERE tl.individual=ti.individual AND tl.type='P' AND tl.valid=1";
 		$this->db->query($sql,__LINE__,__FILE__);
 		if($this->db->next_record()) {
 			$president_name = $this->db->f('name');
@@ -2955,9 +2955,9 @@ class tc
 		$type = get_var('type',array('GET','POST'));
 
 	    $sql = "SELECT * FROM tc_leader AS tl JOIN tc_individual AS ti WHERE tl.individual=ti.individual AND tl.valid=1 AND ";
-	    if($this->yearly_ppi_interviewer == 1) { $sql .= " (tl.president=1)"; }
-		if($this->yearly_ppi_interviewer == 2) { $sql .= " (tl.president=1 OR tl.counselor=1)"; }
-		if($this->yearly_ppi_interviewer == 3) { $sql .= " (tl.president=1 OR tl.counselor=1 OR tl.secretary=1)"; }
+	    if($this->yearly_ppi_interviewer == 1) { $sql .= " (tl.type='P')"; }
+		if($this->yearly_ppi_interviewer == 2) { $sql .= " (tl.type='P' OR tl.type='C')"; }
+		if($this->yearly_ppi_interviewer == 3) { $sql .= " (tl.type='P' OR tl.type='C' OR tl.type='S')"; }
 		$this->db2->query($sql,__LINE__,__FILE__);
 		while ($this->db2->next_record()) {
 			$indiv = $this->db2->f('individual');
@@ -3283,7 +3283,7 @@ class tc
 		$notes = get_var('notes',array('GET','POST'));
 		$type = get_var('type',array('GET','POST'));
 
-		$sql = "SELECT * FROM tc_leader AS tl JOIN tc_individual AS ti WHERE tl.individual=ti.individual AND tl.valid=1 AND (tl.president=1 OR tl.counselor=1 OR tl.secretary=1 OR tl.district!=0)";
+		$sql = "SELECT * FROM tc_leader AS tl JOIN tc_individual AS ti WHERE tl.individual=ti.individual AND tl.valid=1 AND (tl.type='P' OR tl.type='C' OR tl.type='D' OR tl.district!=0)";
 		$this->db2->query($sql,__LINE__,__FILE__);
 		while ($this->db2->next_record()) {
 			$indiv = $this->db2->f('individual');
@@ -4527,23 +4527,24 @@ class tc
 				//print "counselor=$counselor secretary=$secretary<br>";
 
 				if(($indiv > 0) || ($name != "")) {
+                    $leader_type = 'D';
+                    if ($secretary == 1) {$leader_type = 'S';}
+                    if ($counselor == 1) {$leader_type = 'C';}
+                    if ($president == 1) {$leader_type = 'P';}
 					if($id < $this->max_leader_members) {
 						//print "Updating Existing Entry<br>";
 						$this->db2->query("UPDATE tc_leader set" .
 						                  " individual=" . $indiv . 
 						                  " ,district=" . $district . 
 						                  " ,email='" . $email . "'" .
-						                  " ,president='" . $president . "'" .
-						                  " ,counselor='" . $counselor . "'" .
-						                  " ,secretary='" . $secretary . "'" .
+						                  " ,type='" . $leader_type . "'" .
 						                  " WHERE leader=" . $id,__LINE__,__FILE__);
 					} else {
 						//print "Adding New Entry<br>";
 						$this->db2->query("INSERT INTO tc_leader (leader,individual,district," .
-						                  "email,president,counselor,secretary,valid) " .
+						                  "email,type,valid) " .
 						                  "VALUES (NULL,'" . $indiv . "','" . $district . "','" .
-						                  $email . "','" . $president  . "','" .
-						                  $counselor . "','" . $secretary . "','1'" .
+						                  $email . "','" . $leader_type . "','1'" .
 						                  ")",__LINE__,__FILE__);
 					}
 				} else {
@@ -4609,9 +4610,10 @@ class tc
 			$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');
+            $leader_type = $this->db->f('type');
+			if ($leader_type == 'P') {$president = 1;} else {$president = 0;}
+			if ($leader_type == 'C') {$counselor = 1;} else {$counselor = 0;}
+			if ($leader_type == 'S') {$secretary = 1;} else {$secretary = 0;}
 
 			// Create the forms needed in the table
 			$table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
diff --git a/sql/schema.dot b/sql/schema.dot
index c554f04..37c0463 100644
--- a/sql/schema.dot
+++ b/sql/schema.dot
@@ -51,7 +51,7 @@ digraph schema {
     shape = "record"
   ];
   leader    [
-    label = "leader||<l> leader|<i> individual|<d> district|<em> email|<pr> president|<cn> counselor|<sec> secreatary|<v> valid"
+    label = "leader||<l> leader|<i> individual|<d> district|<em> email|<t> type|<v> valid"
     shape = "record"
   ];
   visit   [
diff --git a/sql/tc.jpg b/sql/tc.jpg
index 4a35aa2..85a642b 100644
Binary files a/sql/tc.jpg and b/sql/tc.jpg differ
diff --git a/sql/tc.sql b/sql/tc.sql
index ce19e36..2d1c631 100644
--- a/sql/tc.sql
+++ b/sql/tc.sql
@@ -163,9 +163,7 @@ CREATE TABLE /*!42501 IF NOT EXISTS*/ `tc_leader` (
   `individual` int(16) unsigned NOT NULL default '0',
   `district` int(16) unsigned default '0',
   `email` varchar(60) NOT NULL,
-  `president` tinyint(1) default '0',
-  `counselor` tinyint(1) default '0',
-  `secretary` tinyint(1) default '0',
+  `type` enum( 'P', 'C', 'S', 'D' ) NOT NULL,
   `valid` tinyint(1) default '1',
   KEY `leader` (`leader`),
   KEY `individual` (`individual`)