+ $this->t->set_file(array('int_sched_t' => 'int_sched.tpl'));
+ $this->t->set_block('int_sched_t','individual_list','indivlist');
+ $this->t->set_block('int_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('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
+ $this->t->set_var('int_link_title','Hometeaching Interviews');
+
+ $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
+ $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
+
+ $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched&action=save'));
+ $this->t->set_var('title','Hometeaching Interviews Scheduler');
+
+ $indiv_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $int_date_width=20;
+ $table_width=$indiv_width + $phone_width + $pri_width + $notes_width + $int_date_width;
+ $header_row = "<th width=$indiv_width><font size=-2>Individual</th>";
+ $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
+ $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
+ $header_row.= "<th width=$int_date_width><font size=-2>Last Interview</th>";
+ $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
+ $table_data=""; $completed_data=""; $totals_data="";
+
+ $year = date('Y');
+ $month = date('m');
+ $nextyear = $year + 1;
+ if($month >= 1 && $month <= 3) { $quarter_start=$year."-01-01"; $quarter_end=$year."-04-01"; }
+ if($month >= 4 && $month <= 6) { $quarter_start=$year."-04-01"; $quarter_end=$year."-07-01"; }
+ if($month >= 7 && $month <= 9) { $quarter_start=$year."-07-01"; $quarter_end=$year."-10-01"; }
+ if($month >= 10 && $month <= 12) { $quarter_start=$year."-10-01"; $quarter_end=$nextyear."-01-01"; }
+ //print "year: $year month: $month quarter_start: $quarter_start quarter_end: $quarter_end<br>";
+
+ // create the individual id -> individual name mapping
+ $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY name ASC";
+ $this->db->query($sql,__LINE__,__FILE__);
+ $i=0;
+ $individual_data = NULL;
+ $indiv_name_data = NULL;
+ while ($this->db->next_record()) {
+ $indiv_name_data[$i] = $this->db->f('name');
+ $individual_data[$i] = $this->db->f('individual');
+ $individ2name[$individual_data[$i]] = $indiv_name_data[$i];
+ $i++;
+ }
+ // add any YM that are home teachers
+ $sql = "SELECT * FROM tc_companionship where valid=1";
+ $this->db->query($sql,__LINE__,__FILE__);
+ while ($this->db->next_record()) {
+ $tmp_individual = $this->db->f('individual');
+ $sql = "Select * FROM tc_individual where individual='$tmp_individual' and steward='' and valid=1";
+ $this->db2->query($sql,__LINE__,__FILE__);
+ while ($this->db2->next_record()) {
+ $indiv_name_data[$i] = $this->db2->f('name');
+ $individual_data[$i] = $this->db2->f('individual');
+ $individ2name[$individual_data[$i]] = $indiv_name_data[$i];
+ $i++;
+ }
+ }
+ array_multisort($indiv_name_data, $individual_data);
+
+ 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'];
+ if($location == "") {
+ $supervisor = $entry['supervisor'];
+ $supervisor_array = explode(",", $individ2name[$supervisor]);
+ $supervisor_last_name = $supervisor_array[0];
+ $sql = "SELECT * FROM tc_individual where individual='$supervisor'";
+ $this->db2->query($sql,__LINE__,__FILE__);
+ if($this->db2->next_record()) {
+ $supervisor_address = $this->db2->f('address');
+ }
+ $location = "$supervisor_last_name"." home ($supervisor_address)";
+ }
+ if($indiv == 0) { $location = ""; }
+
+ //print "indiv: $indiv appointment: $appointment <br>";
+ //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 int notes table
+ $new_data = get_var('hti_notes',array('POST'));
+ foreach ($new_data as $entry) {
+ $hti_notes = $entry['notes'];
+ $individual = $entry['individual'];
+ $indiv_name = $entry['indiv_name'];
+ $hti_pri = $entry['pri'];
+ //print "hti_notes: $hti_notes indiv_name: $indiv_name <Br>";
+ // Perform database save actions here
+ $this->db->query("SELECT * FROM tc_companion WHERE individual=$individual and valid=1",__LINE__,__FILE__);
+ if ($this->db->next_record()) {
+ $scheduling_priority = $this->db->f('scheduling_priority');
+ //$this->logToFile("int_sched", "UPDATE tc_scheduling_priority SET priority='$hti_pri', notes=\"$hti_notes\" WHERE scheduling_priority='$scheduling_priority'");
+ $this->db2->query("UPDATE tc_scheduling_priority SET priority='$hti_pri', notes=\"$hti_notes\" WHERE scheduling_priority='$scheduling_priority'",__LINE__,__FILE__);
+ }
+ }
+
+ $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched');
+ //Header('Location: ' . $take_me_to_url);
+ }
+
+ // Get the Districts
+ $sql = "SELECT * FROM tc_district AS td JOIN (tc_presidency AS tp, tc_individual AS ti) WHERE td.district=tp.district AND td.supervisor=ti.individual AND td.valid=1 ORDER BY td.district ASC";
+ $this->db->query($sql,__LINE__,__FILE__);
+ $i=0;
+ while ($this->db->next_record()) {
+ $district = $this->db->f('district');
+ $districts[$i]['district'] = $this->db->f('district');
+ $districts[$i]['name'] = $this->db->f('name');
+ $districts[$i]['supervisor'] = $this->db->f('supervisor');
+ $districts[$i]['presidency'] = $this->db->f('presidency');
+ $i++;
+ }
+
+ // APPOINTMENT TABLE
+ $district = 1;
+ $date_width=250; $time_width=100; $indiv_width=200; $location_width=100;
+ $appt_table_width=$date_width + $time_width + $indiv_width + $location_width;
+ $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
+ $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
+ $appt_header_row.= "<th width=$indiv_width><font size=-2>Individual</th>";
+ $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
+ $appt_table_data = "";
+
+ $total_comps=0; $comps_with_quarterly_int=0;
+
+ // Display a scheduling table for each district
+ for ($d=0; $d < count($districts); $d++) {
+ $table_data=""; $appt_table_data="";
+ $this->t->set_var('district_number',$districts[$d]['district']);
+ $this->t->set_var('district_name',$districts[$d]['name']);
+ $supervisor = $districts[$d]['supervisor'];
+ $supervisor_array = explode(",", $supervisor);
+ $supervisor_last_name = $supervisor_array[0];
+ $sql = "SELECT * FROM tc_individual where individual='$supervisor'";
+ $this->db2->query($sql,__LINE__,__FILE__);
+ if($this->db2->next_record()) {
+ $supervisor_address = $this->db2->f('address');
+ }
+ $location = "$supervisor_last_name"." home ($supervisor_address)";
+ $table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": All Individuals with Interviews Not Completed";
+ $appt_table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": Interview Appointment Slots";
+ $this->t->set_var('table_title',$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=".$districts[$d]['presidency']." and date>=CURDATE() ORDER BY date ASC, time ASC";
+ $this->db->query($sql,__LINE__,__FILE__);
+
+ while ($this->db->next_record()) {
+ $appointment = $this->db->f('appointment');
+ $indiv = $this->db->f('individual');
+ $location = $this->db->f('location');
+ if(($location == "") && ($indiv > 0)) { $location = "$supervisor_last_name"." home ($supervisor_address)"; }
+
+ $date = $this->db->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->db->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_data); $i++) {
+ $id = $individual_data[$i];
+ $name = $indiv_name_data[$i];
+ if($individual_data[$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.'">';
+ $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][supervisor]" value="'.$supervisor.'">';
+
+ $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('appt_table_width',$appt_table_width);
+
+ // INTERVIEW SCHEDULING TABLE
+
+ // Select all the unique companionship numbers for this district
+ $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$d]['district'];
+ $this->db->query($sql,__LINE__,__FILE__);
+ $j=0; $unique_companionships = '';
+ while ($this->db->next_record())
+ {
+ $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
+ $j++;
+ }
+
+ $i=0;
+ for ($j=0; $j < count($unique_companionships); $j++) {
+ // Select all the companions from each companionship
+ $sql = "SELECT * FROM tc_companion 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'];
+ $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
+ $this->t->set_var('tr_color',$tr_color);
+ $total_comps++;
+ while ($this->db->next_record()) {
+ // Get this companions information
+ $individual = $this->db->f('individual');
+
+ $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.
+ if($int_completed == 1) {
+ $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>$hti_notes</td>";
+ $completed_data.= '</tr>';
+ $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
+ $this->t->set_var('tr_color2',$tr_color2);
+ $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
+ $this->t->set_var('tr_color',$tr_color);
+ continue;
+ }
+
+ // If this companionship has had a hometeaching interview this quarter, don't show them on the schedule list
+ $sql = "SELECT * FROM tc_interview WHERE date >= '$quarter_start' AND date < '$quarter_end' AND individual='$id' AND interview_type='hti'";
+ $this->db2->query($sql,__LINE__,__FILE__);
+
+ if(!$this->db2->next_record()) {
+ $sql = "SELECT * FROM tc_interview WHERE individual='$id' AND interview_type='hti' ORDER BY date DESC";
+ $this->db3->query($sql,__LINE__,__FILE__);
+ if($this->db3->next_record()) {
+ $date = $this->db3->f('date');
+ } else {
+ $date = "";
+ }
+ $link_data['menuaction'] = 'tc.tc.int_update';
+ $link_data['individual'] = $id;
+ $link_data['name'] = $name;
+ $link_data['interview'] = '';
+ $link_data['action'] = 'add';
+ $link_data['interview_type'] = 'hti';
+ $link_data['interviewer'] = $districts[$d]['supervisor'];
+ $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</a></td>";
+ $table_data.= "<td align=center>$phone</td>";
+ $table_data.= "<td align=center>";
+ $table_data.= '<select name=hti_notes['.$i.'][pri]>';
+ foreach(range(0,6) as $num) {
+ if($num == 0) { $num = 1; } else {$num = $num*5; }
+ if($hti_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="hti_notes['.$i.'][notes]" value="'.$hti_notes.'">';
+ $table_data.= '<input type=hidden name="hti_notes['.$i.'][individual]" value="'.$id.'">';
+ $table_data.= '<input type=hidden name="hti_notes['.$i.'][indiv_name]" value="'.$name.'">';
+ $table_data.= '</td>';
+ $table_data.= '</tr>'."\n";
+ $i++;
+ } else {
+ $link_data['menuaction'] = 'tc.tc.int_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'] = 'hti';
+ $link_data['action'] = 'view';
+ $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
+ $comps_with_quarterly_int++;
+ $int_completed=1;
+ $date = $this->db2->f('date');
+ $hti_notes = $this->db2->f('notes');
+ if(strlen($hti_notes) > 40) { $hti_notes = substr($hti_notes,0,40) . "..."; }
+ $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>$hti_notes</td>";
+ $completed_data.= '</tr>';
+ }
+ }
+ }
+
+ $name_width=175; $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>Individual</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>Interview Notes</th>";
+
+ $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('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->fp('indivlist','individual_list',True);
+
+ } // End for each district loop
+
+
+ $indivs_width=300; $totals_width=100;
+ $totals_table_width=$indivs_width + $totals_width;
+ $totals_header_row = "<th width=$indivs_width><font size=-2>Individuals</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 Companionships with interviews completed:</b></font></td>";
+ $totals_data.= "<td align=center><font size=-2><b>$comps_with_quarterly_int / $total_comps</b></font></td>";
+ $percent = ceil(($comps_with_quarterly_int / $total_comps)*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('totals_table_width',$totals_table_width);
+
+ $this->t->pfp('out','int_sched_t');
+ $this->save_sessiondata();
+