+ $this->t->set_file(array('ppi_sched_t' => 'ppi_sched.tpl'));
+ $this->t->set_block('ppi_sched_t','individual_list','indivlist');
+ $this->t->set_block('ppi_sched_t','appt_list','apptlist');
+ $action = get_var('action',array('GET','POST'));
+
+ $this->t->set_var('lang_save','Save Appt / Pri / Notes');
+ $this->t->set_var('lang_reset','Clear Changes');
+
+ $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
+ $this->t->set_var('ppi_link_title',$this->ppi_frequency_label . ' 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 ' . $this->ppi_frequency_label . ' PPIs');
+
+ $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched&action=save'));
+ $this->t->set_var('title',$this->ppi_frequency_label . ' PPI Scheduler');
+
+ $header_row = "<th ><font size=-2>Individual Name</th>";
+ $header_row.= "<th><font size=-2>Phone</th>";
+ $header_row.= "<th><font size=-2>Priority</th>";
+ $header_row.= "<th><font size=-2>Last PPI</th>";
+ $header_row.= "<th><font size=-2>Scheduling Notes</th>";
+ $table_data=""; $completed_data=""; $totals_data="";
+
+ $year = date('Y');
+ $month = date('m');
+ $period = intval(($month-1)/$this->ppi_frequency) + 1;
+ $start_of_period = ($period-1)*$this->ppi_frequency + 1;
+ $end_of_period = $period * $this->ppi_frequency;
+
+ if($action == 'save') {
+ // Save any changes made to the appointment table
+ $new_data = get_var('appt_notes',array('POST'));
+ if($new_data != "") {
+ foreach ($new_data as $entry) {
+ $indiv = $entry['individual'];
+ $appointment = $entry['appointment'];
+ $location = $entry['location'];
+ $presidency_location = $entry['presidency_location'];
+ if($location == "") { $location = $presidency_location; }
+ if($indiv == 0) { $location = ""; }
+
+ //Only perform a database update if we have made a change to this appointment
+ $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and individual='$indiv' and location='$location'";
+ $this->db->query($sql,__LINE__,__FILE__);
+ if(!$this->db->next_record()) {
+ // Perform database save actions here
+ $this->db->query("UPDATE tc_appointment set " .
+ " individual='" . $indiv . "'" .
+ ",location='" . $location . "'" .
+ " WHERE appointment=" . $appointment,__LINE__,__FILE__);
+ // Email the appointment
+ $this->email_appt($appointment);
+ }
+ }
+ }
+
+ // Save any changes made to the ppi notes table
+ $new_data = get_var('notes',array('POST'));
+ foreach ($new_data as $entry) {
+ $notes = $entry['notes'];
+ $individual = $entry['individual'];
+ $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->logToFile("ppi_sched", "UPDATE tc_scheduling_priority SET priority='$priority', notes=\"$notes\" WHERE scheduling_priority='$scheduling_priority'");
+ $this->db2->query("UPDATE tc_scheduling_priority SET priority='$priority', notes=\"$notes\" WHERE scheduling_priority='$scheduling_priority'", __LINE__, __FILE__);
+ }
+ }
+
+ $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched');
+ //Header('Location: ' . $take_me_to_url);
+ }
+
+ // create the individual id -> individual name mapping
+ $sql = "SELECT * FROM tc_individual where valid=1 and steward='$this->default_stewardship' ORDER BY name ASC";
+ $this->db->query($sql,__LINE__,__FILE__);
+ $i=0;
+ $individual = NULL;
+ $indiv_name = NULL;
+ while ($this->db->next_record()) {
+ $indiv_name[$i] = $this->db->f('name');
+ $individual[$i] = $this->db->f('individual');
+ $i++;
+ }
+ array_multisort($indiv_name, $individual);
+
+ // APPOINTMENT TABLE
+ $appt_header_row = "<th><font size=-2>Date</th>";
+ $appt_header_row.= "<th><font size=-2>Time</th>";
+ $appt_header_row.= "<th><font size=-2>Individual</th>";
+ $appt_header_row.= "<th><font size=-2>Location</th>";
+ $appt_table_data = "";
+ $table_data="";
+
+ $total_indivs=0; $indivs_with_yearly_ppi=0;
+
+ // Get the President
+ $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti where tp.individual=ti.individual AND tp.valid=1 AND ";
+ if($this->yearly_ppi_interviewer == 1) { $sql .= " (tp.president=1)"; }
+ if($this->yearly_ppi_interviewer == 2) { $sql .= " (tp.president=1 OR tp.counselor=1)"; }
+ if($this->yearly_ppi_interviewer == 3) { $sql .= " (tp.president=1 OR tp.counselor=1 OR tp.secretary=1)"; }
+ $this->db->query($sql,__LINE__,__FILE__);
+ while ($this->db->next_record()) {
+ $presidency_name = $this->db->f('name');
+ $presidency_name_array = explode(",",$presidency_name);
+ $presidency_last_name = $presidency_name_array[0];
+ $presidency_id = $this->db->f('presidency');
+ $presidency_address = $this->db->f('address');
+ $presidency_location = "$presidency_last_name"." home ($presidency_address)";
+ $appt_table_data = "";
+
+ // Display a scheduling table for this presidency member
+ $not_completed_table_title = "All individuals with " . $this->ppi_frequency_label . " PPI Not Completed";
+ $appt_table_title = $presidency_name . ": " . $this->ppi_frequency_label." PPI Appointment Slots";
+ $this->t->set_var('not_completed_table_title',$not_completed_table_title);
+ $this->t->set_var('appt_table_title',$appt_table_title);
+
+ // query the database for all the appointments
+ $sql = "SELECT * FROM tc_appointment where presidency=".$presidency_id." and date>=CURDATE() ORDER BY date ASC, time ASC";
+ $this->db2->query($sql,__LINE__,__FILE__);
+
+ while ($this->db2->next_record()) {
+ $appointment = $this->db2->f('appointment');
+ $indiv = $this->db2->f('individual');
+ $location = $this->db2->f('location');
+ if(($location == "") && ($indiv > 0)) { $location = $presidency_location; }
+
+ $date = $this->db2->f('date');
+ $date_array = explode("-",$date);
+ $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
+ $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
+
+ $time = $this->db2->f('time');
+ $time_array = explode(":",$time);
+ $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
+
+ $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
+ $appt_table_data.= "<td align=center>$day_string</td>";
+ $appt_table_data.= "<td align=center>$time_string</td>";
+
+ $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][individual]>';
+ $appt_table_data.= '<option value=0></option>';
+ for ($i=0; $i < count($individual); $i++) {
+ $id = $individual[$i];
+ $name = $indiv_name[$i];
+ if($individual[$i] == $indiv) {
+ $selected[$id] = 'selected="selected"';
+ } else {
+ $selected[$id] = '';
+ }
+ $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
+ }
+ $appt_table_data.='</select></td>';
+
+ $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
+ $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
+
+ $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
+
+ $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
+ $this->t->set_var('tr_color',$tr_color);
+ }
+ $this->t->set_var('appt_table_data',$appt_table_data);
+ $this->t->set_var('appt_header_row',$appt_header_row);
+ $this->t->set_var('lang_save','Save Appts for ' . $presidency_name);
+
+ $this->t->fp('apptlist','appt_list',True);
+ }
+
+ // PPI SCHEDULING TABLE
+ $sql = "SELECT * FROM tc_individual AS ti JOIN tc_scheduling_priority AS tsp WHERE ti.scheduling_priority=tsp.scheduling_priority AND steward='$this->default_stewardship' AND valid=1 ORDER BY tsp.priority ASC, ti.name ASC";
+ $this->db->query($sql,__LINE__,__FILE__);
+
+ $i=0;
+ $individual = NULL;
+ 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_priority[$individual[$i]] = $this->db->f('priority');
+ $indiv_notes[$individual[$i]] = $this->db->f('notes');
+ $i++;
+ $total_indivs++;
+ }
+
+ $max = count($individual);
+
+ for($i=0; $i < $max; $i++) {
+ $id = $individual[$i];
+ $name = $indiv_name[$i];
+ $phone = $indiv_phone[$id];
+ $priority = $indiv_priority[$id];
+ $notes = $indiv_notes[$id];
+
+ // If this individual has had a PPI this period, don't show him on the schedule list
+ $year_start = $year . "-" . $start_of_period . "-01";
+ $year_end = $year . "-" . $end_of_period . "-31";
+ $sql = "SELECT * FROM tc_interview WHERE date >= '$year_start' AND date <= '$year_end' ".
+ "AND individual=" . $id . " AND interview_type='ppi' ORDER BY date DESC";
+ $this->db2->query($sql,__LINE__,__FILE__);
+
+ if(!$this->db2->next_record()) {
+ $sql = "SELECT * FROM tc_interview WHERE individual=" . $id . " AND interview_type='ppi' 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.ppi_update';
+ $link_data['individual'] = $id;
+ $link_data['name'] = $name;
+ $link_data['interview'] = '';
+ $link_data['interview_type'] = 1;
+ $link_data['action'] = 'add';
+ $link_data['interviewer'] = $interviewer;
+ $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
+ $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
+ $this->t->set_var('tr_color',$tr_color);
+ $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
+ $table_data.= "<td align=center>$phone</td>";
+ //$table_data.= "<td align=center>$priority</td>";
+ $table_data.= "<td align=center>";
+ $table_data.= '<select name=notes['.$i.'][pri]>';
+ foreach(range(0,6) as $num) {
+ if($num == 0) { $num = 1; } else {$num = $num*5; }
+ if($priority == $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="notes['.$i.'][notes]" value="'.$notes.'">';
+ $table_data.= '<input type=hidden name="notes['.$i.'][individual]" value="'.$id.'">';
+ $table_data.= '<input type=hidden name="notes['.$i.'][indiv_name]" value="'.$name.'">';
+ $table_data.= '</td>';
+ $table_data.= '</tr>';
+ } else {
+ $link_data['menuaction'] = 'tc.tc.ppi_update';
+ $link_data['interviewer'] = $this->db2->f('interviewer');
+ $link_data['individual'] = $this->db2->f('individual');
+ $link_data['name'] = $name;
+ $link_data['interview'] = $this->db2->f('interview');
+ $link_data['interview_type'] = $this->db2->f('interview_type');
+ $link_data['action'] = 'view';
+ $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
+ $indivs_with_yearly_ppi++;
+ $date = $this->db2->f('date');
+ $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.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</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>$notes</td>";
+ $completed_data.= '</tr>';
+ }
+ } // End for individuals Loop
+
+ $completed_table_title = "All individuals with " . $this->ppi_frequency_label . " PPI Completed";
+ $completed_header_row = "<th><font size=-2>Individual</th>";
+ $completed_header_row.= "<th><font size=-2>Phone</th>";
+ $completed_header_row.= "<th><font size=-2>Date</th>";
+ $completed_header_row.= "<th><font size=-2>PPI Notes</th>";
+
+ $this->t->set_var('completed_table_title',$completed_table_title);
+ $this->t->set_var('header_row',$header_row);
+ $this->t->set_var('table_data',$table_data);
+ $this->t->set_var('completed_header_row',$completed_header_row);
+ $this->t->set_var('completed',$completed_data);
+ $this->t->set_var('lang_save','Save Pri / Notes');
+ $this->t->fp('indivlist','individual_list',True);
+
+ $totals_header_row = "<th><font size=-2>Individuals</th>";
+ $totals_header_row.= "<th><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 Individuals with " . $this->ppi_frequency_label . " PPIs completed:</b></font></td>";
+ $totals_data.= "<td align=center><font size=-2><b>$indivs_with_yearly_ppi / $total_indivs</b></font></td>";
+ $percent = ceil(($indivs_with_yearly_ppi / $total_indivs)*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('totals',$totals_data);
+ $this->t->set_var('totals_header_row',$totals_header_row);
+ $this->t->set_var('ppi_frequency_label',$this->ppi_frequency_label);
+
+ $this->t->pfp('out','ppi_sched_t');
+ $this->save_sessiondata();