+ if ($_POST['add']) {
+ #$this->t->set_var('debug_list',$_POST['add']);
+ $companionship = get_var('companionship',array('POST'));
+ $district = get_var('district',array('POST'));
+ $assignedHT_list = get_var('assignedHT',array('POST'));
+ $unassignedHT_list = get_var('unassignedHT',array('POST'));
+ $assigned_family_list = get_var('assignedFamiles',array('POST'));
+ $unassigned_family_list = get_var('unassignedFamilies',array('POST'));
+
+ if ($assignedHT_list || $unassignedHT_list) {
+ $sql = "INSERT INTO tc_companionship_sandbox (district) VALUES (\"$district\")";
+ $this->db2->query($sql,__LINE__,__FILE__);
+ $companionship_sandbox = mysql_insert_id();
+
+ foreach ($assignedHT_list as $individual) {
+ $sql = "INSERT INTO tc_companion_sandbox (individual,companionship) VALUES (\"$individual\",\"$companionship_sandbox\")";
+ $this->db->query($sql,__LINE__,__FILE__);
+ }
+ foreach ($unassignedHT_list as $individual) {
+ $sql = "INSERT INTO tc_companion_sandbox (individual,companionship) VALUES (\"$individual\",\"$companionship_sandbox\")";
+ $this->db->query($sql,__LINE__,__FILE__);
+ }
+ foreach ($assigned_family_list as $family) {
+ $sql = "UPDATE tc_family_sandbox SET companionship=$companionship_sandbox WHERE family=$family";
+ $this->db->query($sql,__LINE__,__FILE__);
+ }
+ foreach ($unassigned_family_list as $family) {
+ $sql = "UPDATE tc_family_sandbox SET companionship=$companionship_sandbox WHERE family=$family";
+ $this->db->query($sql,__LINE__,__FILE__);
+ }
+ } else {
+ $this->t->set_var('debug_list','You must select at least one companion!');
+ }
+ } else if ($_POST['delete']) {
+ #$this->t->set_var('debug_list',$_POST['delete']);
+ $companionship = get_var('companionship',array('POST'));
+ #$this->t->set_var('debug_list',$companionship);
+
+ if ($companionship > 0) {
+ # unassign families
+ $sql = "UPDATE tc_family_sandbox SET companionship=NULL WHERE companionship=$companionship";
+ $this->db->query($sql,__LINE__,__FILE__);
+
+ # remove companions
+ $sql = "DELETE FROM tc_companion_sandbox WHERE companionship=$companionship";
+ $this->db->query($sql,__LINE__,__FILE__);
+
+ # remove companionship
+ $sql = "DELETE FROM tc_companionship_sandbox WHERE companionship=$companionship";
+ $this->db->query($sql,__LINE__,__FILE__);
+ } else {
+ $this->t->set_var('debug_list','You must select a companionship to delete!');
+ }
+ } else if ($_POST['update']) {
+ #$this->t->set_var('debug_list',$_POST['update']);
+ $companionship = get_var('companionship',array('POST'));
+ $district = get_var('district',array('POST'));
+ $assignedHT_list = get_var('assignedHT',array('POST'));
+ $unassignedHT_list = get_var('unassignedHT',array('POST'));
+ $assigned_family_list = get_var('assignedFamiles',array('POST'));
+ $unassigned_family_list = get_var('unassignedFamilies',array('POST'));
+ #$this->t->set_var('debug_list',$district);
+
+ if ($companionship > 0) {
+ if ($assignedHT_list || $unassignedHT_list) {
+ # clear out existing info about companionship
+ $sql = "UPDATE tc_family_sandbox SET companionship=NULL WHERE companionship=$companionship";
+ $this->db->query($sql,__LINE__,__FILE__);
+ $sql = "DELETE FROM tc_companion_sandbox WHERE companionship=$companionship";
+ $this->db->query($sql,__LINE__,__FILE__);
+
+ # set new info about companionship
+ $sql = "UPDATE tc_companionship_sandbox SET district=$district WHERE companionship=$companionship";
+ $this->db->query($sql,__LINE__,__FILE__);
+ foreach ($assignedHT_list as $individual) {
+ $sql = "INSERT INTO tc_companion_sandbox (individual,companionship) VALUES (\"$individual\",\"$companionship\")";
+ $this->db->query($sql,__LINE__,__FILE__);
+ }
+ foreach ($unassignedHT_list as $individual) {
+ $sql = "INSERT INTO tc_companion_sandbox (individual,companionship) VALUES (\"$individual\",\"$companionship\")";
+ $this->db->query($sql,__LINE__,__FILE__);
+ }
+ foreach ($assigned_family_list as $family) {
+ $sql = "UPDATE tc_family_sandbox SET companionship=$companionship WHERE family=$family";
+ $this->db->query($sql,__LINE__,__FILE__);
+ }
+ foreach ($unassigned_family_list as $family) {
+ $sql = "UPDATE tc_family_sandbox SET companionship=$companionship WHERE family=$family";
+ $this->db->query($sql,__LINE__,__FILE__);
+ }
+ } else {
+ $this->t->set_var('debug_list','You must select at least one companion!');
+ }
+ } else {
+ $this->t->set_var('debug_list','You must select a companionship to update!');
+ }
+ } else if ($_POST['reset']) {
+ #$this->t->set_var('debug_list',$_POST['reset']);
+
+ $sql = "TRUNCATE TABLE tc_district_sandbox";
+ $this->db->query($sql,__LINE__,__FILE__);
+ $sql = "TRUNCATE TABLE tc_family_sandbox";
+ $this->db->query($sql,__LINE__,__FILE__);
+ $sql = "TRUNCATE TABLE tc_companion_sandbox";
+ $this->db->query($sql,__LINE__,__FILE__);
+ $sql = "TRUNCATE TABLE tc_companionship_sandbox";
+ $this->db->query($sql,__LINE__,__FILE__);
+
+ # populate tc_district_sandbox
+ $sql = "SELECT * FROM tc_district WHERE valid=1";
+ $this->db->query($sql,__LINE__,__FILE__);
+ while ($this->db->next_record()) {
+ $district = $this->db->f('district');
+ $supervisor = $this->db->f('supervisor');
+ $sql = "INSERT INTO tc_district_sandbox (district,supervisor) VALUES (\"$district\",\"$supervisor\")";
+ $this->db2->query($sql,__LINE__,__FILE__);
+ }
+
+ # populate family, companion, and companionship tables
+ $sql = "SELECT * FROM tc_companionship WHERE valid=1";
+ $this->db->query($sql,__LINE__,__FILE__);
+ while ($this->db->next_record()) {
+ $companionship = $this->db->f('companionship');
+ $district = $this->db->f('district');
+ $sql = "INSERT INTO tc_companionship_sandbox (district) VALUES (\"$district\")";
+ $this->db2->query($sql,__LINE__,__FILE__);
+ $companionship_sandbox = mysql_insert_id();
+
+ $sql = "SELECT * FROM tc_companion WHERE companionship=$companionship AND valid=1";
+ $this->db2->query($sql,__LINE__,__FILE__);
+ while ($this->db2->next_record()) {
+ $individual = $this->db2->f('individual');
+ $sql = "INSERT INTO tc_companion_sandbox (individual,companionship) VALUES (\"$individual\",\"$companionship_sandbox\")";
+ $this->db3->query($sql,__LINE__,__FILE__);
+ }
+
+ $sql = "SELECT * FROM tc_family WHERE companionship=$companionship AND valid=1";
+ $this->db2->query($sql,__LINE__,__FILE__);
+ while ($this->db2->next_record()) {
+ $individual = $this->db2->f('individual');
+ $family = $this->db2->f('family');
+ $sql = "INSERT INTO tc_family_sandbox (tc_family,individual,companionship) VALUES (\"$family\",\"$individual\",\"$companionship_sandbox\")";
+ $this->db3->query($sql,__LINE__,__FILE__);
+ }
+ }
+ }
+