From: Owen Leonard Date: Sat, 18 Sep 2010 03:40:05 +0000 (-0600) Subject: added tc_scheduling_priority table, removed pri and notes fields from tc_individual... X-Git-Tag: release_1_0_0~33 X-Git-Url: http://git.pippins.net/embedvideo/.git/images/%27%20%20%20%20.%20%24GLOBALS%5B%27phpgw%27%5D-%3Elink%28%27inc/jquery/static/x.gif?a=commitdiff_plain;h=868fb3cf0a52bd6d4f613c30e40f75ad35fde4b3;p=eq%2F.git added tc_scheduling_priority table, removed pri and notes fields from tc_individual tc_family and tc_companionship --- diff --git a/bin/import_ward_data b/bin/import_ward_data index 560650a..b88cba8 100755 --- a/bin/import_ward_data +++ b/bin/import_ward_data @@ -105,22 +105,19 @@ sub print_hash ###################################################################### # 3RD_INDIV -#+-------------+------------------+------+-----+---------+----------------+ -#| Field | Type | Null | Key | Default | Extra | -#+-------------+------------------+------+-----+---------+----------------+ -#| individual | int(16) unsigned | | PRI | NULL | auto_increment | -#| mls_id | int(16) unsigned | | | NULL | | -#| name | varchar(60) | YES | | NULL | | -#| phone | varchar(12) | YES | | NULL | | -#| email | varchar(120) | YES | | NULL | | -#| priesthood | enum | YES | | NULL | | -#| ppi_pri | int(10) unsigned | YES | | 1 | | -#| ppi_notes | varchar(128) | YES | | NULL | | -#| hti_pri | int(10) unsigned | YES | | 1 | | -#| hti_notes | varchar(128) | YES | | NULL | | -#| attending | tinyint(1) | YES | | 0 | | -#| valid | tinyint(1) | YES | | NULL | | -#+-------------+------------------+------+-----+---------+----------------+ +#+----------------------+------------------+------+-----+---------+----------------+ +#| Field | Type | Null | Key | Default | Extra | +#+----------------------+------------------+------+-----+---------+----------------+ +#| individual | int(16) unsigned | | PRI | NULL | auto_increment | +#| mls_id | int(16) unsigned | | | NULL | | +#| name | varchar(60) | YES | | NULL | | +#| phone | varchar(12) | YES | | NULL | | +#| email | varchar(120) | YES | | NULL | | +#| priesthood | enum | YES | | NULL | | +#| scheduling_priority | int(10) unsigned | YES | | 30 | | +#| attending | tinyint(1) | YES | | 0 | | +#| valid | tinyint(1) | YES | | NULL | | +#+----------------------+------------------+------+-----+---------+----------------+ sub update_tc_individual_table { print "\n-> Updating tc_individual table\n"; @@ -160,7 +157,7 @@ sub update_tc_individual_table if($rows == 0) { # No existing records found for this individual, make a new entry print " Adding new individual: $individual_name\n"; - $sth = $dbh->prepare("insert into tc_individual values (NULL,'$id',\"$individual_name\",'$address','$phone','$email','','$hhposition','$priesthood','','$default_interview_pri','','$default_interview_pri','',$attending,1)"); + $sth = $dbh->prepare("insert into tc_individual values (NULL,'$id',\"$individual_name\",'$address','$phone','$email','','$hhposition','$priesthood',NULL,$attending,1)"); $sth->execute or die "-E- DB error: $DBI::errstr\n"; } elsif($rows == 1) { # An existing record was found for this individual, update it @@ -271,14 +268,15 @@ sub update_tc_district_table } # 3RD_COMPANIONSHIP -#+---------------+------------------+------+-----+---------+-------+ -#| Field | Type | Null | Key | Default | Extra | -#+---------------+------------------+------+-----+---------+-------+ -#| companionship | int(16) unsigned | | | 0 | | -#| individual | int(16) unsigned | YES | | NULL | | -#| district | int(16) unsigned | YES | | NULL | | -#| valid | tinyint(1) | YES | | NULL | | -#+---------------+------------------+------+-----+---------+-------+ +#+----------------------+------------------+------+-----+---------+-------+ +#| Field | Type | Null | Key | Default | Extra | +#+----------------------+------------------+------+-----+---------+-------+ +#| companionship | int(16) unsigned | | | 0 | | +#| individual | int(16) unsigned | YES | | NULL | | +#| district | int(16) unsigned | YES | | NULL | | +#| scheduling_priority | int(10) unsigned | YES | | 30 | | +#| valid | tinyint(1) | YES | | NULL | | +#+----------------------+------------------+------+-----+---------+-------+ sub update_tc_companionship_table { print "\n-> Updating tc_companionship table\n"; @@ -309,7 +307,7 @@ sub update_tc_companionship_table if($rows == 0) { # No existing records found for this companionship, make a new entry print " Adding Companion to companionship: $individual_name -> $id\n"; - $sth = $dbh->prepare("insert into tc_companionship values ($id,'$individual','$district',1)"); + $sth = $dbh->prepare("insert into tc_companionship values ($id,'$individual','$district',NULL,1)"); $sth->execute or die "-E- DB error: $DBI::errstr\n"; } else { # An existing companionship was found for this companionship, update it @@ -332,19 +330,18 @@ sub update_tc_companionship_table } # 3RD_FAMILY -#+---------------+------------------+------+-----+---------+-------+ -#| Field | Type | Null | Key | Default | Extra | -#+---------------+------------------+------+-----+---------+-------+ -#| family | int(16) unsigned | | PRI | 0 | A | -#| hofh_id | int(16) unsigned | YES | | NULL | | -#| name | varchar(30) | YES | | NULL | | -#| name_id | varchar(30) | YES | | NULL | | -#| individual | int(16) unsigned | YES | | NULL | | -#| companionship | int(16) unsigned | YES | | NULL | | -#| visit_pri | int(10) unsigned | YES | | 1 | | -#| visit_notes | varchar(128) | YES | | NULL | | -#| valid | tinyint(1) | YES | | NULL | | -#+---------------+------------------+------+-----+---------+-------+ +#+----------------------+------------------+------+-----+---------+-------+ +#| Field | Type | Null | Key | Default | Extra | +#+----------------------+------------------+------+-----+---------+-------+ +#| family | int(16) unsigned | | PRI | 0 | A | +#| hofh_id | int(16) unsigned | YES | | NULL | | +#| name | varchar(30) | YES | | NULL | | +#| name_id | varchar(30) | YES | | NULL | | +#| individual | int(16) unsigned | YES | | NULL | | +#| companionship | int(16) unsigned | YES | | NULL | | +#| scheduling_priority | int(10) unsigned | YES | | 30 | | +#| valid | tinyint(1) | YES | | NULL | | +#+----------------------+------------------+------+-----+---------+-------+ sub update_tc_family_table { print "\n-> Updating tc_family table\n"; @@ -375,7 +372,7 @@ sub update_tc_family_table if($rows == 0) { # No existing records found for this family, make a new entry print " Adding new Family: $family_name\n"; - $sth = $dbh->prepare("insert into tc_family values (NULL,$id,'$family_name','$name_id','0','0','$default_visit_pri','',1)"); + $sth = $dbh->prepare("insert into tc_family values (NULL,$id,'$family_name','$name_id','0','0',NULL,1)"); $sth->execute or die "-E- DB error: $DBI::errstr\n"; } elsif($rows == 1) { # An existing record was found for this family, update it @@ -628,6 +625,65 @@ sub update_organization_class_data } } +sub update_tc_scheduling_priority_table +{ + print "\n-> Updating scheduling priority table\n"; + + # individuals + # TODO: make steward flexible with a setting in the config file + $sth = $dbh->prepare("select * from tc_individual where steward='Elder' and valid=1"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + while($sqlhashref = $sth->fetchrow_hashref) { + $individual = $sqlhashref->{individual}; + $scheduling_priority = $sqlhashref->{scheduling_priority}; + if ($scheduling_priority == 'NULL') + { + $sth2 = $dbh->prepare("insert into tc_scheduling_priority values (NULL, 30, '')"); + $sth2->execute or die "-E- DB error: $DBI::errstr\n"; + $scheduling_priority = $dbh->last_insert_id(NULL,NULL,'tc_scheduling_priority',NULL); + $sth2 = $dbh->prepare("update tc_individual set scheduling_priority=$scheduling_priority where individual=$individual"); + $sth2->execute or die "-E- DB error: $DBI::errstr\n"; + } + } + + # families + # TODO: make steward flexible with a setting in the config file + $sth = $dbh->prepare("select tf.scheduling_priority, tf.family from tc_family AS tf JOIN tc_individual AS ti ON tf.individual=ti.individual and ti.steward='Elder' and tf.valid=1"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + while($sqlhashref = $sth->fetchrow_hashref) { + $family = $sqlhashref->{family}; + $scheduling_priority = $sqlhashref->{scheduling_priority}; + #print "$family $scheduling_priority\n"; + if ($scheduling_priority == 'NULL') + { + $sth2 = $dbh->prepare("insert into tc_scheduling_priority values (NULL, 30, '')"); + $sth2->execute or die "-E- DB error: $DBI::errstr\n"; + $scheduling_priority = $dbh->last_insert_id(NULL,NULL,'tc_scheduling_priority',NULL); + $sth2 = $dbh->prepare("update tc_family set scheduling_priority=$scheduling_priority where family=$family"); + $sth2->execute or die "-E- DB error: $DBI::errstr\n"; + } + } + + # companionships + # TODO: make steward flexible with a setting in the config file + $sth = $dbh->prepare("select tc.individual, tc.scheduling_priority from tc_companionship AS tc JOIN tc_individual AS ti ON tc.individual=ti.individual and (ti.steward='Elder' or ti.steward='') and tc.valid=1"); + $sth->execute or die "-E- DB error: $DBI::errstr\n"; + while($sqlhashref = $sth->fetchrow_hashref) { + $individual = $sqlhashref->{individual}; + $scheduling_priority = $sqlhashref->{scheduling_priority}; + #print "$individual $scheduling_priority\n"; + if ($scheduling_priority == 'NULL') + { + $sth2 = $dbh->prepare("insert into tc_scheduling_priority values (NULL, 30, '')"); + $sth2->execute or die "-E- DB error: $DBI::errstr\n"; + $scheduling_priority = $dbh->last_insert_id(NULL,NULL,'tc_scheduling_priority',NULL); + $sth2 = $dbh->prepare("update tc_companionship set scheduling_priority=$scheduling_priority where individual=$individual"); + $sth2->execute or die "-E- DB error: $DBI::errstr\n"; + } + } + +} + ###################################################################### # MAIN ###################################################################### @@ -699,6 +755,7 @@ if($opt_s) { $dbh->disconnect(); exit; } &update_tc_visit_table(); &update_family_in_tc_individual_table(); &update_organization_class_data(); +&update_tc_scheduling_priority_table(); print "\n-> Import Successful! DONE...\n"; diff --git a/inc/class.tc.inc.php b/inc/class.tc.inc.php index 976709f..07c0b0e 100644 --- a/inc/class.tc.inc.php +++ b/inc/class.tc.inc.php @@ -1406,17 +1406,27 @@ class tc } // Save any changes made to the ppi notes table - $new_data = get_var('ppi_notes',array('POST')); + $new_data = get_var('notes',array('POST')); foreach ($new_data as $entry) { - $ppi_notes = $entry['notes']; + $notes = $entry['notes']; $individual = $entry['individual']; - $ppi_pri = $entry['pri']; + $priority = $entry['pri']; // Perform database save actions here + $sql = "SELECT * FROM tc_individual WHERE individual='$individual'"; + $this->db->query($sql,__LINE__,__FILE__); + if ($this->db->next_record()) { + $scheduling_priority = $this->db->f('scheduling_priority'); + $this->db2->query("UPDATE tc_scheduling_priority SET priority='$priority' AND notes=\"$notes\" WHERE scheduling_priority='$scheduling_priority'", __LINE__, __FILE__); + } + +/* $this->db->query("UPDATE tc_individual set " . - " ppi_notes='" . $ppi_notes . "'" . - ",ppi_pri='" . $ppi_pri . "'" . + " notes='" . $notes . "'" . + ",priority='" . $priority . "'" . " WHERE individual=" . $individual,__LINE__,__FILE__); +*/ + } @@ -1508,7 +1518,7 @@ class tc // PPI SCHEDULING TABLE // TODO: changed this so it picks the quorum dynamically - $sql = "SELECT * FROM tc_individual where valid=1 and steward='Elder' ORDER BY ppi_pri ASC, name ASC"; + $sql = "SELECT * FROM tc_individual as ti JOIN tc_scheduling_priority as tsp where ti.scheduling_priority=tsp.scheduling_priority and steward='Elder' and valid=1 ORDER by tsp.priority ASC, ti.name ASC"; $this->db->query($sql,__LINE__,__FILE__); $i=0; @@ -1517,8 +1527,8 @@ class tc $individual[$i] = $this->db->f('individual'); $indiv_name[$i] = $this->db->f('name'); $indiv_phone[$individual[$i]] = $this->db->f('phone'); - $indiv_ppi_pri[$individual[$i]] = $this->db->f('ppi_pri'); - $indiv_ppi_notes[$individual[$i]] = $this->db->f('ppi_notes'); + $indiv_priority[$individual[$i]] = $this->db->f('priority'); + $indiv_notes[$individual[$i]] = $this->db->f('notes'); $i++; $total_indivs++; } @@ -1529,8 +1539,8 @@ class tc $id = $individual[$i]; $name = $indiv_name[$i]; $phone = $indiv_phone[$id]; - $ppi_pri = $indiv_ppi_pri[$id]; - $ppi_notes = $indiv_ppi_notes[$id]; + $priority = $indiv_priority[$id]; + $notes = $indiv_notes[$id]; // If this individual has had a yearly PPI this year, don't show him on the schedule list $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01"; @@ -1558,12 +1568,12 @@ class tc $this->t->set_var('tr_color',$tr_color); $table_data.= "$name"; $table_data.= "$phone"; - //$table_data.= "$ppi_pri"; + //$table_data.= "$priority"; $table_data.= ""; - $table_data.= ''; foreach(range(0,6) as $num) { if($num == 0) { $num = 1; } else {$num = $num*5; } - if($ppi_pri == $num) { + if($priority == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; @@ -1572,9 +1582,9 @@ class tc } $table_data.= ''; $table_data.= "$date"; - $table_data.= ''; - $table_data.= ''; - $table_data.= ''; + $table_data.= ''; + $table_data.= ''; + $table_data.= ''; $table_data.= ''; $table_data.= ''; } else { @@ -1588,14 +1598,14 @@ class tc $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data); $indivs_with_yearly_ppi++; $date = $this->db2->f('date'); - $ppi_notes = $this->db2->f('notes'); - if(strlen($ppi_notes) > 40) { $ppi_notes = substr($ppi_notes,0,40) . "..."; } + $notes = $this->db2->f('notes'); + if(strlen($notes) > 40) { $notes = substr($notes,0,40) . "..."; } $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2); $this->t->set_var('tr_color2',$tr_color2); $completed_data.= "$name"; $completed_data.= "$phone"; $completed_data.= "$date"; - $completed_data.= "$ppi_notes"; + $completed_data.= "$notes"; $completed_data.= ''; } } // End for individuals Loop @@ -1756,10 +1766,17 @@ class tc $hti_pri = $entry['pri']; //print "hti_notes: $hti_notes indiv_name: $indiv_name
"; // Perform database save actions here + $this->db->query("SELECT * FROM tc_companionship WHERE individual=$individual and valid=1",__LINE__,__FILE__); + if ($this->db->next_record()) { + $scheduling_priority = $this->db->f('scheduling_priority'); + $this->db2->query("UPDATE tc_scheduling_priority SET priority='$hti_pri' and notes=\"hti_notes\" where scheduling_priority=$scheduling_priority",__LINE__,__FILE__); + } +/* $this->db->query("UPDATE tc_individual set " . " hti_notes='" . $hti_notes . "'" . ",hti_pri='" . $hti_pri . "'" . " WHERE individual=" . $individual,__LINE__,__FILE__); +*/ } $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'); @@ -1885,7 +1902,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 where valid=1 and 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']; @@ -1896,20 +1913,11 @@ class tc // Get this companions information $individual = $this->db->f('individual'); - $sql = "SELECT * FROM tc_individual where individual='$individual'"; - $this->db2->query($sql,__LINE__,__FILE__); - if($this->db2->next_record()) { - $individual = $this->db2->f('individual'); - $indiv_name = $this->db2->f('name'); - $indiv_phone[$individual] = $this->db2->f('phone'); - $indiv_hti_pri[$individual] = $this->db2->f('hti_pri'); - $indiv_hti_notes[$individual] = $this->db2->f('hti_notes'); - } - $id = $individual; - $name = $indiv_name; - $phone = $indiv_phone[$id]; - $hti_pri = $indiv_hti_pri[$id]; - $hti_notes = $indiv_hti_notes[$id]; + $id = $this->db->f('individual'); + $name = $this->db->f('name'); + $phone = $this->db->f('phone'); + $hti_pri = $this->db->f('priority'); + $hti_notes = $this->db->f('notes'); // If the companionship has already had its quarterly interview, // Skip the other companion in the companionship. @@ -2118,10 +2126,17 @@ class tc $visit_pri = $entry['pri']; // Perform database save actions here + $this->db->query("SELECT * FROM tc_family WHERE family='$family'",__LINE__,__FILE__); + if ($this->db->next_record()) { + $scheduling_priority = $this->db->f('scheduling_priority'); + $this->db2->query("UPDATE tc_scheduling_priority SET priority='$visit_pri' AND notes=\"$visit_notes\" WHERE scheduling_priority='$scheduling_priority'",__LINE__,__FILE__); + } +/* $this->db->query("UPDATE tc_family set " . " visit_notes='" . $visit_notes . "'" . ",visit_pri='" . $visit_pri . "'" . " WHERE family=" . $family,__LINE__,__FILE__); +*/ } $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'); @@ -2203,7 +2218,7 @@ class tc // VISIT SCHEDULING TABLE - $sql = "SELECT * FROM tc_family where valid=1 and individual != 0 and companionship != 0 ORDER BY visit_pri ASC, name ASC"; + $sql = "SELECT * FROM tc_family AS tf JOIN tc_scheduling_priority AS tsp WHERE tf.scheduling_priority=tsp.scheduling_priority AND tf.valid=1 AND tf.individual != 0 AND tf.companionship != 0 ORDER BY tsp.priority ASC, tf.name ASC"; $this->db->query($sql,__LINE__,__FILE__); $total_families=0; $families_with_yearly_visit=0; @@ -2390,15 +2405,15 @@ class tc $this->t->set_var('district_name',$president_name); // TODO: changed this so it picks the quorum dynamically - $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1 ORDER BY individual ASC"; + $sql = "SELECT * FROM tc_individual AS ti JOIN tc_scheduling_priority as tsp where ti.scheduling_priority=tsp.scheduling_priority and ti.steward='Elder' and ti.valid=1 ORDER BY ti.individual ASC"; $this->db->query($sql,__LINE__,__FILE__); $i=0; while ($this->db->next_record()) { $individual[$i] = $this->db->f('individual'); $indiv_name[$i] = $this->db->f('name'); $indiv_phone[$individual[$i]] = $this->db->f('phone'); - $indiv_ppi_pri[$individual[$i]] = $this->db->f('ppi_pri'); - $indiv_ppi_notes[$individual[$i]] = $this->db->f('ppi_notes'); + $indiv_priority[$individual[$i]] = $this->db->f('priority'); + $indiv_notes[$individual[$i]] = $this->db->f('notes'); $i++; } $total_indivs=$i; diff --git a/sql/tc.sql b/sql/tc.sql index 531b98e..71902b6 100644 --- a/sql/tc.sql +++ b/sql/tc.sql @@ -87,6 +87,7 @@ CREATE TABLE `tc_companionship` ( `companionship` int(16) unsigned NOT NULL default '0', `individual` int(16) unsigned NOT NULL default '0', `district` int(16) unsigned default NULL, + `scheduling_priority` int(16) unsigned default NULL, `valid` tinyint(1) default NULL, KEY `companionship` (`companionship`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; @@ -116,10 +117,7 @@ CREATE TABLE `tc_individual` ( `hh_position` enum('Head of Household','Spouse','Other') DEFAULT 'Other', `priesthood` enum('High Priest','Elder','Priest','Teacher','Deacon','Unordained') DEFAULT NULL, `steward` enum('High Priest','Elder') DEFAULT NULL, - `ppi_pri` int(10) unsigned NOT NULL default '1', - `ppi_notes` varchar(128) default NULL, - `hti_pri` int(10) unsigned default '1', - `hti_notes` varchar(128) default NULL, + `scheduling_priority` int(16) unsigned default NULL, `attending` tinyint(1) default '0', `valid` tinyint(1) default NULL, PRIMARY KEY (`individual`) @@ -135,8 +133,7 @@ CREATE TABLE `tc_family` ( `name_id` varchar(30) NOT NULL default '', `individual` int(16) unsigned default '0', `companionship` int(16) unsigned default NULL, - `visit_pri` int(10) unsigned default '1', - `visit_notes` varchar(128) default NULL, + `scheduling_priority` int(16) unsigned default NULL, `valid` tinyint(1) default NULL, PRIMARY KEY (`family`) ) ENGINE=MyISAM AUTO_INCREMENT=277 DEFAULT CHARSET=latin1; @@ -206,3 +203,12 @@ CREATE TABLE `tc_willingness` ( `willing` enum('y','n','') NOT NULL, KEY `individual` (`individual`,`assignment`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +-- +-- Table structure for table `tc_scheduling_priority` +-- +CREATE TABLE `phpgroupware`.`tc_scheduling_priority` ( +`scheduling_priority` INT( 16 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , +`priority` INT( 10 ) UNSIGNED NOT NULL DEFAULT '30', +`notes` VARCHAR( 128 ) NOT NULL DEFAULT '' +) ENGINE = MYISAM ;