- $sql = "SELECT * FROM tc_indiv where valid=1";
- $this->db->query($sql,__LINE__,__FILE__);
- while ($this->db->next_record())
- {
- $family = $this->db->f('family');
- $phone = $this->db->f('phone');
- $family_phone[$family] = $phone;
- }
-
- $max = count($family_id);
-
- for($i=0; $i < $max; $i++) {
- $id = $family_id[$i];
- $name = $family_name[$i];
- $phone = $family_phone[$id];
- $vis_pri = $family_visit_pri[$id];
- $vis_notes = $family_visit_notes[$id];
-
- // If this family has had a yearly visit this year, don't show them on the schedule list
- $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
- $sql = "SELECT * FROM tc_visit WHERE date > '$year_start' AND date < '$year_end' ".
- "AND family=" . $id . " AND companionship=0";
- $this->db2->query($sql,__LINE__,__FILE__);
-
- if(!$this->db2->next_record()) {
- $sql = "SELECT * FROM tc_visit WHERE family=" . $id . " AND companionship=0 ORDER BY date DESC";
- $this->db->query($sql,__LINE__,__FILE__);
- if($this->db->next_record()) { $date = $this->db->f('date'); } else { $date = ""; }
- $link_data['menuaction'] = 'tc.tc.vis_update';
- $link_data['visit'] = '';
- $link_data['family'] = $id;
- $link_data['name'] = $name;
- $link_data['action'] = 'add';
- $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
- $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
- $table_data.= "<td align=center>$phone</td>";
- $table_data.= "<td align=center>";
- $table_data.= '<select name=vis_notes['.$i.'][pri]>';
- foreach(range(0,6) as $num) {
- if($num == 0) { $num = 1; } else {$num = $num*5; }
- if($vis_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
- $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
- }
- $table_data.= '</select></td>';
- $table_data.= "<td align=center>$date</td>";
- $table_data.= '<td><input type=text size="50" maxlength="128" name="vis_notes['.$i.'][notes]" value="'.$vis_notes.'">';
- $table_data.= '<input type=hidden name="vis_notes['.$i.'][family_id]" value="'.$id.'">';
- $table_data.= '<input type=hidden name="vis_notes['.$i.'][family_name]" value="'.$name.'">';
- $table_data.= '</td>';
- $table_data.= '</tr>';
- $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
- $this->t->set_var('tr_color',$tr_color);
- } else {
- $link_data['menuaction'] = 'tc.tc.vis_update';
- $link_data['visit'] = $this->db2->f('visit');
- $link_data['family'] = $this->db2->f('family');
- $link_data['name'] = $name;
- $link_data['date'] = $this->db2->f('date');
- $link_data['action'] = 'view';
- $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
- $families_with_yearly_visit++;
- $date = $this->db2->f('date');
- $vis_notes = $this->db2->f('notes');
- if(strlen($vis_notes) > 40) { $vis_notes = stripslashes(substr($vis_notes,0,40) . "..."); }
- $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
- $completed_data.= "<td align=center>$phone</td>";
- $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
- $completed_data.= "<td align=left>$vis_notes</td>";
- $completed_data.= '</tr>';
- $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
- $this->t->set_var('tr_color2',$tr_color2);
- }
- }
-
- $name_width=190; $phone_width=100; $date_width=100; $notes_width=300;
- $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
- $completed_header_row = "<th width=$name_width><font size=-2>Family Name</th>";
- $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
- $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
- $completed_header_row.= "<th width=$notes_width><font size=-2>Visit Notes</th>";
-
- $family_width=300; $totals_width=100;
- $totals_table_width=$family_width + $totals_width;
- $totals_header_row = "<th width=$family_width><font size=-2>Families</th>";
- $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
- $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
- $totals_data.= "<td align=left><font size=-2><b>Total Families with yearly Visits completed:</b></font></td>";
- $totals_data.= "<td align=center><font size=-2><b>$families_with_yearly_visit / $total_families</b></font></td>";
- $percent = ceil(($families_with_yearly_visit / $total_families)*100);
- $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
- $this->t->set_var('tr_color',$tr_color);
- $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
- $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
- $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
- $totals_data.= "</tr>";
-
- $this->t->set_var('table_width',$table_width);
- $this->t->set_var('header_row',$header_row);
- $this->t->set_var('table_data',$table_data);
- $this->t->set_var('totals_header_row',$totals_header_row);
- $this->t->set_var('totals_table_width',$totals_table_width);
- $this->t->set_var('completed_header_row',$completed_header_row);
- $this->t->set_var('completed_table_width',$completed_table_width);
- $this->t->set_var('completed',$completed_data);
- $this->t->set_var('totals',$totals_data);
- $this->t->fp('familylist','family_list',True);
- $this->t->fp('apptlist','appt_list',True);
-
- $this->t->pfp('out','vis_sched_t');
- $this->save_sessiondata();
-
- }
-
- function ppi_view()
- {
- $this->t->set_file(array('ppi_view_t' => 'ppi_view.tpl'));
- $this->t->set_block('ppi_view_t','district_list','list');
-
- $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
- $num_months = get_var('num_months',array('GET','POST'));
- if($num_months == '') { $num_months = $this->default_ppi_num_months; }
- $this->t->set_var('num_months',$num_months);
- if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
- else { $this->t->set_var('lang_num_months','Months of History'); }
- $this->t->set_var('lang_filter','Filter');
- $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
-
- $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
- $this->t->set_var('ppi_link_title','Yearly PPIs');
-
- $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
- $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
-
- $this->t->set_var('title','Yearly PPIs');
- $num_months = get_var('num_months',array('GET','POST'));
- if($num_months == '') { $num_months = $this->default_ppi_num_years; }
- $this->t->set_var('num_months',$num_months);
- if($num_months == 1) { $this->t->set_var('lang_num_months','Year of History'); }
- else { $this->t->set_var('lang_num_months','Years of History'); }
-
- $sql = "SELECT * FROM tc_presidency where president=1 and valid=1";
- $this->db->query($sql,__LINE__,__FILE__);
- if($this->db->next_record()) {
- $president_name = $this->db->f('name');
- $interviewer = $this->db->f('indiv');
- $interview_type = 'ppi';
- } else {
- print "<hr><font color=red><h3>-E- Unable to locate President in tc_presidency table</h3></font></hr>";
- return;
- }
- $this->t->set_var('district_number','*');
- $this->t->set_var('district_name',$president_name);
-
- // TODO: changed this so it picks the quorum dynamically
- $sql = "SELECT * FROM tc_indiv where steward='Elder' and valid=1 ORDER BY indiv ASC";
- $this->db->query($sql,__LINE__,__FILE__);
- $i=0;
- while ($this->db->next_record())
- {
- $indiv_id[$i] = $this->db->f('indiv');
- $indiv_name[$i] = $this->db->f('name');
- $indiv_phone[$indiv_id[$i]] = $this->db->f('phone');
- $indiv_ppi_pri[$indiv_id[$i]] = $this->db->f('ppi_pri');
- $indiv_ppi_notes[$indiv_id[$i]] = $this->db->f('ppi_notes');
- $i++;
- }
- $total_indivs=$i;
- array_multisort($indiv_name, $indiv_id);
- //var_dump($indiv_name); print "<br><br>"; var_dump($indiv_id);
-
- $header_row="<th width=$comp_width><font size=-2>Individual Name</th>";
-
- $indiv_width=400; $ppi_width=75; $table_width=$indiv_width + $num_months*$ppi_width;
- $table_data="";
- for($m=$num_months; $m >= 0; $m--) {
- $year = date('Y') - $m;
- $header_row .= "<th width=150><font size=-2>$year</th>";
- $ppis[$m] = 0;
- }
-
- for ($j=0; $j < count($indiv_id); $j++) {
- $id = $indiv_id[$j];
- $name = $indiv_name[$j];
- $phone = $indiv_phone[$id];
-
- $link_data['menuaction'] = 'tc.tc.ppi_update';
- $link_data['interviewer'] = $interviewer;
- $link_data['indiv'] = $id;
- $link_data['name'] = $name;
- $link_data['interview'] = '';
- $link_data['interview_type'] = $interview_type;
- $link_data['action'] = 'add';
- $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
- $this->nextmatchs->template_alternate_row_color(&$this->t);
- $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
-
- // Find out how many times PPIs were performed in the past $num_months for this individual
- for($m=$num_months; $m >= 0; $m--) {
- $year = date('Y') - $m;
- $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
- $sql = "SELECT * FROM tc_interview WHERE date > '$year_start' AND date < '$year_end' ".
- "AND indiv=" . $id . " AND interview_type='ppi'";
- $this->db2->query($sql,__LINE__,__FILE__);
-
- if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
- if($this->db2->next_record()) {
- $ppis[$m]++; $total_ppis[$m]++; $ppi_recorded[$companionship][$m]=1;
- $link_data['menuaction'] = 'tc.tc.ppi_update';
- $link_data['companionship'] = $companionship;
- $link_data['interviewer'] = $this->db2->f('interviewer');
- $link_data['indiv'] = $id;
- $link_data['name'] = $name;
- $link_data['interview'] = $this->db2->f('interview');
- $link_data['interview_type'] = $interview_type;
- $link_data['action'] = 'view';
- $date = $this->db2->f('date');
- $date_array = explode("-",$date);
- $month = $date_array[1];
- $day = $date_array[2];
- $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
- $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
- }
- else { $table_data .= "<td> </td>"; }
- }
- $table_data .= "</tr>\n";
- }
- $table_data .= "<tr><td colspan=20><hr></td></tr>";
-
- $stat_data = "<tr><td><b><font size=-2>$total_indivs Individuals<br>PPI Totals:</font></b></td>";
- for($m=$num_months; $m >=0; $m--) {
- $percent = ceil(($ppis[$m] / $total_indivs)*100);
- $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
- }
- $stat_data .= "</tr>";
-
- $this->t->set_var('table_width',$table_width);
- $this->t->set_var('header_row',$header_row);
- $this->t->set_var('table_data',$table_data);
- $this->t->set_var('stat_data',$stat_data);
- $this->t->pfp('out','ppi_view_t');
- $this->save_sessiondata();
- }
-
- function ppi_update()
- {
- $this->t->set_file(array('form' => 'ppi_update.tpl'));
- $this->t->set_block('form','interviewer_list','int_list');
- $this->t->set_block('form','add','addhandle');
- $this->t->set_block('form','edit','edithandle');
-
- $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
- $this->t->set_var('readonly','');
- $this->t->set_var('disabled','');
-
- $action = get_var('action',array('GET','POST'));
- $companionship = get_var('companionship',array('GET','POST'));
- $interviewer = get_var('interviewer',array('GET','POST'));
- $name = get_var('name',array('GET','POST'));
- $interview = get_var('interview',array('GET','POST'));
- $indiv = get_var('indiv',array('GET','POST'));
- $date = get_var('date',array('GET','POST'));
- $notes = get_var('notes',array('GET','POST'));
- $interview_type = get_var('interview_type',array('GET','POST'));
-
- $sql = "SELECT * FROM tc_presidency where valid=1 and (president=1 or counselor=1 or secretary=1)";
- $this->db2->query($sql,__LINE__,__FILE__);
- while ($this->db2->next_record())
- {
- $indiv = $this->db2->f('indiv');
- $interviewer_name = $this->db2->f('name');
- if($indiv == $interviewer) {
- $this->t->set_var('interviewer',$interviewer . ' selected');
- } else {
- $this->t->set_var('interviewer',$interviewer);
- }
- $this->t->set_var('interviewer_name',$interviewer_name);
- $this->t->set_var('interview_type_checked','');
- $this->t->fp('int_list','interviewer_list',True);
- }
-
- if($action == 'save')
- {
- $notes = get_var('notes',array('POST'));
- $this->db->query("UPDATE tc_interview set " .
- " interview='" . $interview . "'" .
- ", interviewer='" . $interviewer . "'" .
- ", indiv='" . $indiv . "'" .
- ", date='" . $date . "'" .
- ", notes='" . $notes . "'" .
- ", interview_type='" . $interview_type . "'" .
- " WHERE interview=" . $interview,__LINE__,__FILE__);
- $this->ppi_view();
- return false;