2 /**************************************************************************\
3 * Application: phpGroupWare - 3rd Counselor *
4 * Framework: http://www.phpgroupware.org *
5 * Author: Alan J. Pippin (apippin@pippins.net) *
6 * ----------------------------------------------- *
7 * This program is free software; you can redistribute it and/or modify it *
8 * under the terms of the GNU General Public License as published by the *
9 * Free Software Foundation; either version 2 of the License, or (at your *
10 * option) any later version. *
11 \**************************************************************************/
12 /* $Id: class.tc.inc.php,v 1.1.1.1 2005/07/20 07:40:32 ajp Exp $ */
24 var $default_ht_num_months;
25 var $default_ppi_num_months;
26 var $default_ppi_num_years;
27 var $default_int_num_quarters;
28 var $default_int_num_years;
29 var $default_vis_num_years;
30 var $default_att_num_quarters;
31 var $max_num_districts;
34 var $upload_target_path;
36 var $max_appointments;
37 var $max_presidency_members;
38 var $ppi_frequency_label;
40 var $public_functions = array
65 'willing_view' => True,
66 'willing_update' => True,
67 'send_ical_appt' => True,
68 'assign_view' => True,
69 'assign_update' => True,
70 'get_time_selection_form' => True,
75 if(file_exists("setup/tc_config.local")) {
76 include("setup/tc_config.local");
78 include("setup/tc_config");
81 $this->script_path = "$this->application_path"."/bin";
82 $this->max_presidency_members = 99;
83 $this->max_appointments = 32768;
85 $this->db = $GLOBALS['phpgw']->db;
86 $this->db2 = $this->db;
87 $this->db3 = $this->db;
88 $this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
89 $this->t = $GLOBALS['phpgw']->template;
90 $this->account = $GLOBALS['phpgw_info']['user']['account_id'];
91 $this->grants = $GLOBALS['phpgw']->acl->get_grants('tc');
92 $this->grants[$this->account] = PHPGW_ACL_READ + PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE;
94 $this->jscal = CreateObject('tc.jscalendar'); // before phpgw_header() !!!
95 $this->cal_options = 'daFormat : "%Y-%m-%d",
96 ifFormat : "%Y-%m-%d",
100 $GLOBALS['phpgw_info']['flags']['app_header'] = 'The 3rd Counselor';
101 $GLOBALS['phpgw']->common->phpgw_header();
103 $this->current_day = `date '+%d'`;
104 $this->current_day = $this->current_day-0; // Make it numeric
105 $this->current_month = `date '+%m'`;
106 $this->current_month = $this->current_month-0; // Make it numeric
107 $this->current_year = `date '+%Y'`;
108 $this->current_year = $this->current_year-0; // Make it numeric
110 if ($this->ppi_frequency == 12) {
111 $this->ppi_frequency_label = "Annual";
112 } else if ($this->ppi_frequency == 6) {
113 $this->ppi_frequency_label = "Semi-Annual";
114 } else if ($this->ppi_frequency == 3) {
115 $this->ppi_frequency_label = "Quarterly";
116 } else if ($this->ppi_frequency == 1) {
117 $this->ppi_frequency_label = "Monthly";
119 $this->ppi_frequency_label = "Periodic";
123 $this->display_app_header();
126 function logToFile($func, $msg)
129 $fd = fopen($this->upload_target_path . "/tc_trace.log", "a");
130 // append date/time to message
131 $str = "[" . date("Y/m/d h:i:s", mktime()) . "] [" . $func . "] " . $msg;
133 fwrite($fd, $str . "\n");
138 function save_sessiondata()
142 function display_app_header()
144 $this->t->set_file(array('tc_header' => 'header.tpl'));
146 if (isset($phpgw_info['user']['preferences']['tc']['tc_font']))
148 $font = $phpgw_info['user']['preferences']['tc']['tc_font'];
155 $this->t->set_var('bg_color',$phpgw_info['theme']['th_bg']);
156 $this->t->set_var('font',$font);
157 $link_data['menuaction'] = 'tc.tc.ht_view';
158 $this->t->set_var('link_hometeaching',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
159 $this->t->set_var('lang_hometeaching','HomeTeaching');
160 $link_data['menuaction'] = 'tc.tc.act_list';
161 $this->t->set_var('link_activity',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
162 $this->t->set_var('lang_activity','Activities');
163 $link_data['menuaction'] = 'tc.tc.willing_view';
164 $this->t->set_var('link_willing',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
165 $this->t->set_var('lang_willing','Willingness');
166 $link_data['menuaction'] = 'tc.tc.assign_view';
167 $this->t->set_var('link_assignment',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
168 $this->t->set_var('lang_assignment','Assignments');
169 $link_data['menuaction'] = 'tc.tc.par_view';
170 $this->t->set_var('link_participation',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
171 $this->t->set_var('lang_participation','Participation');
172 $link_data['menuaction'] = 'tc.tc.ppi_view';
173 $this->t->set_var('link_ppi',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
174 $this->t->set_var('lang_ppi','PPIs');
175 $link_data['menuaction'] = 'tc.tc.int_view';
176 $this->t->set_var('link_int',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
177 $this->t->set_var('lang_int','Interviews');
178 $link_data['menuaction'] = 'tc.tc.vis_view';
179 $this->t->set_var('link_visit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
180 $this->t->set_var('lang_visit','Visits');
181 $link_data['menuaction'] = 'tc.tc.att_view';
182 $this->t->set_var('link_attendance',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
183 $this->t->set_var('lang_attendance','Attendance');
184 $link_data['menuaction'] = 'tc.tc.dir_view';
185 $this->t->set_var('link_dir',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
186 $this->t->set_var('lang_dir','Directory');
187 $link_data['menuaction'] = 'tc.tc.org_view';
188 $this->t->set_var('link_org',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
189 $this->t->set_var('lang_org','Callings');
190 $link_data['menuaction'] = 'tc.tc.admin';
191 $this->t->set_var('link_admin',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
192 $this->t->set_var('lang_admin','Admin');
193 $link_data['menuaction'] = 'tc.tc.schedule';
194 $this->t->set_var('link_schedule',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
195 $this->t->set_var('lang_schedule','Scheduling');
196 $link_data['menuaction'] = 'tc.tc.email';
197 $this->t->set_var('link_email',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
198 $this->t->set_var('lang_email','Email');
200 $this->t->pparse('out','tc_header');
205 $this->t->set_file(array('ht_view_t' => 'ht_view.tpl'));
206 $this->t->set_block('ht_view_t','district_list','list');
208 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
209 $num_months = get_var('num_months',array('GET','POST'));
210 if($num_months == '') { $num_months = $this->default_ht_num_months; }
211 $this->t->set_var('num_months',$num_months);
212 $this->t->set_var('lang_filter','Filter');
213 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
214 else { $this->t->set_var('lang_num_months','Months of History'); }
216 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
217 $this->t->set_var('title','Hometeaching');
219 $sql = "SELECT * FROM tc_district AS td JOIN tc_individual AS ti WHERE td.supervisor=ti.individual AND td.valid=1 ORDER BY td.district ASC";
220 $this->db->query($sql,__LINE__,__FILE__);
222 while ($this->db->next_record()) {
223 $districts[$i]['district'] = $this->db->f('district');
224 $districts[$i]['name'] = $this->db->f('name');
225 $districts[$i]['supervisor'] = $this->db->f('supervisor');
229 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
230 $this->db->query($sql,__LINE__,__FILE__);
232 while ($this->db->next_record()) {
233 $individual[$i] = $this->db->f('individual');
234 $indiv_name[$i] = $this->db->f('name');
235 $indiv_phone[$individual[$i]] = $this->db->f('phone');
238 array_multisort($indiv_name, $individual);
240 // Make an array mapping individuals to indiv_names
241 for($i=0; $i < count($individual); $i++) {
242 $id = $individual[$i];
243 $indivs[$id] = $indiv_name[$i];
246 $this->nextmatchs->template_alternate_row_color(&$this->t);
247 for($m=$num_months; $m >= 0; $m--) { $total_families[$m]=0; }
248 for ($i=0; $i < count($districts); $i++) {
249 $this->t->set_var('district_number',$districts[$i]['district']);
250 $this->t->set_var('district_name',$districts[$i]['name']);
251 $supervisor = $districts[$i]['supervisor'];
253 // Select all the unique companionship numbers for this district
254 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$i]['district'];
255 $this->db->query($sql,__LINE__,__FILE__);
256 $j=0; $unique_companionships = '';
257 while ($this->db->next_record()) {
258 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
262 $comp_width=450; $visit_width=25; $table_width=$comp_width + $num_months*$visit_width;
263 $table_data=""; $num_companionships = 0;
264 for($m=$num_months; $m >= 0; $m--) {
268 for ($j=0; $j < count($unique_companionships); $j++) {
269 $companion_table_entry = "";
270 // Select all the companions in each companionship
271 $sql = "SELECT * FROM tc_companion where valid=1 and ".
272 "companionship=". $unique_companionships[$j]['companionship'];
273 $this->db->query($sql,__LINE__,__FILE__);
275 while ($this->db->next_record()) {
276 // Get this companions information
277 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
278 $companionship = $this->db->f('companionship');
279 $individual = $this->db->f('individual');
280 $name = $indivs[$individual];
281 $phone = $indiv_phone[$individual];
282 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
284 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
286 // Get the names of the families assigned this home teaching companionship
287 $sql = "SELECT * FROM tc_family AS tf JOIN tc_individual AS ti WHERE tf.individual=ti.individual AND tf.valid=1 AND tf.companionship=".$unique_companionships[$j]['companionship'];
288 $sql = $sql . " ORDER BY name ASC";
289 $this->db->query($sql,__LINE__,__FILE__);
291 while ($this->db->next_record()) {
292 $family_name = $this->db->f('name');
293 $family_id = $this->db->f('family');
294 $this->nextmatchs->template_alternate_row_color(&$this->t);
295 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
296 // Find out how many times Visits were performed by this companionship
297 // in the past $num_months for this Family
298 $header_row="<th width=$comp_width><font size=-2>Families</th>";
299 for($m=$num_months; $m >= 0; $m--) {
300 $month = $this->current_month - $m;
301 $year = $this->current_year;
302 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
303 if($month < 10) { $month = "0"."$month"; }
304 $month_start = "$year"."-"."$month"."-"."01";
305 $month_end = "$year"."-"."$month"."-"."31";
306 $month = "$month"."/"."$year";
308 //print "m: $m month: $month year: $year month_start: $month_start month_end: $month_end<br>";
309 // Add this to the query to filter on only visits made by this companionship:
310 // " AND companionship=" . $unique_companionships[$j]['companionship'].
312 // First check to see if the currently assigned companionship has visited them
313 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
314 " AND companionship=".$unique_companionships[$j]['companionship'].
315 " AND family=". $family_id;
316 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
317 if($this->db2->num_rows($query_id) == 0) {
318 // We did not find any visits made by the currently assigned companionship,
319 // look for visits made by any other companionship other than 0. (0 == Presidency Visit)
320 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
321 " AND companionship!=0".
322 " AND family=". $family_id;
323 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
325 $this->db2->query($sql,__LINE__,__FILE__);
326 $link_data['menuaction'] = 'tc.tc.ht_update';
327 $link_data['date'] = $month_start;
328 $link_data['month_start'] = $month_start;
329 $link_data['month_end'] = $month_end;
330 $link_data['month'] = $month;
331 $link_data['district'] = $districts[$i]['district'];
332 $link_data['district_name'] = $districts[$i]['name'];
333 $link_data['action'] = 'view';
334 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
335 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
336 if(!$total_visits[$m]) { $total_visits[$m] = 0; }
337 if($this->db2->next_record()) {
338 if($this->db2->f('visited') == 'y') {
339 $visits[$m]++; $total_visits[$m]++;
340 $num_families[$m]++; $total_families[$m]++;
341 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/checkmark.gif"></a></td>';
342 } else if($this->db2->f('visited') == 'n') {
343 $num_families[$m]++; $total_families[$m]++;
344 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/x.gif"></a></td>';
346 //$visits[$m]++; $total_visits[$m]++;
347 $table_data .= "<td> </td>";
350 //$visits[$m]++; $total_visits[$m]++;
351 $table_data .= "<td> </td>";
354 $table_data .= "</tr>";
357 $table_data .= "<tr><td colspan=20></td></tr>";
359 $table_data .= "<tr><td colspan=20><hr></td></tr>";
360 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
362 for($m=$num_months; $m >=0; $m--) {
363 if($num_families[$m] > 0) {
364 $percent = ceil(($visits[$m] / $num_families[$m])*100);
368 $stat_data .= "<td align=center><font size=-2><b>$visits[$m] / $num_families[$m]<br>$percent%</font></b></td>";
370 $stat_data .= "</tr>";
372 $this->t->set_var('table_width',$table_width);
373 $this->t->set_var('header_row',$header_row);
374 $this->t->set_var('table_data',$table_data);
375 $this->t->set_var('stat_data',$stat_data);
376 $this->t->fp('list','district_list',True);
379 $totals = "<tr><td><b><font size=-2>Total Families Hometaught:<br>Total Hometeaching Percentage:</font></b></td>";
380 for($m=$num_months; $m >=0; $m--) {
381 if($total_families[$m] > 0) {
382 $percent = ceil(($total_visits[$m] / $total_families[$m])*100);
386 $totals .= "<td align=center><font size=-2><b>$total_visits[$m] / $total_families[$m]<br>$percent%</font></b></td>";
390 $this->t->set_var('totals',$totals);
392 $this->t->pfp('out','ht_view_t');
393 $this->save_sessiondata();
399 $this->t->set_file(array('ht_update_t' => 'ht_update.tpl'));
400 $this->t->set_block('ht_update_t','district_list','list');
401 $this->t->set_block('ht_update_t','save','savehandle');
403 $district = get_var('district',array('GET','POST'));
404 $district_name = get_var('district_name',array('GET','POST'));
405 $date = get_var('date',array('GET','POST'));
406 $month = get_var('month',array('GET','POST'));
407 $month_start = get_var('month_start',array('GET','POST'));
408 $month_end = get_var('month_end',array('GET','POST'));
409 $action = get_var('action',array('GET','POST'));
411 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
412 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_update&action=save'));
413 $this->t->set_var('lang_done','Cancel');
414 $this->t->set_var('district_name',$district_name);
415 $this->t->set_var('district_number',$district);
416 $this->t->set_var('title','Hometeaching Update ' . $month);
417 $this->t->set_var('date',$date);
419 if($action == 'save') {
420 // Get a list of all the companionships in this district
421 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $district;
422 $this->db->query($sql,__LINE__,__FILE__);
423 $j=0; $unique_companionships = '';
424 while ($this->db->next_record()) {
425 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
428 for ($j=0; $j < count($unique_companionships); $j++) {
429 //$comp=$unique_companionships[$j]['companionship'];
430 //print "deleting from tc_visit where companionship=$comp and date=$date and district=$district<br>";
431 // Delete all the visits that have taken place for all families for this companionsthip for this month
432 $this->db->query("DELETE from tc_visit where companionship=" . $unique_companionships[$j]['companionship'] .
433 " AND " . "date='" . $date . "'",__LINE__,__FILE__);
436 // Now, add the visits that are checked for this month
437 $new_data = get_var('family_visited',array('POST'));
438 foreach ($new_data as $family) {
439 foreach ($family as $data) {
440 //print "family_visited: $data <br>";
441 $data_array = explode("/",$data);
442 $family_id = $data_array[0];
443 $companionship = $data_array[1];
444 $date = $data_array[2];
445 $visited = $data_array[3];
446 if($visited == "") { $visited = $data_array[4]; }
447 //print "family_id: $family_id companionship: $companionship date: $date visited: $visited<br>";
448 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes,visited) " .
449 "VALUES (" . $family_id .",". $companionship .",'". $date ."','','". $visited ."')",__LINE__,__FILE__);
456 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
457 $this->db->query($sql,__LINE__,__FILE__);
459 while ($this->db->next_record()) {
460 $individual[$i] = $this->db->f('individual');
461 $indiv_name[$i] = $this->db->f('name');
462 $indiv_phone[$individual[$i]] = $this->db->f('phone');
465 array_multisort($indiv_name, $individual);
467 // Make an array mapping individuals to indiv_names
468 for($i=0; $i < count($individual); $i++) {
469 $id = $individual[$i];
470 $indivs[$id] = $indiv_name[$i];
473 // Select all the unique companionship numbers for this district
474 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $district;
475 $this->db->query($sql,__LINE__,__FILE__);
476 $j=0; $unique_companionships = '';
477 while ($this->db->next_record()) {
478 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
482 $comp_width=300; $visit_width=25; $table_width=$comp_width + $visit_width;
483 $table_data=""; $num_companionships = 0; $num_families = 0; $visits=0;
484 for ($j=0; $j < count($unique_companionships); $j++) {
485 $companion_table_entry = "";
486 // Select all the companions in each companionship
487 $sql = "SELECT * FROM tc_companionship where valid=1 and ".
488 "companionship=". $unique_companionships[$j]['companionship'];
489 $this->db->query($sql,__LINE__,__FILE__);
491 while ($this->db->next_record()) {
492 // Get this companions information
493 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
494 $companionship = $this->db->f('companionship');
495 $individual = $this->db->f('individual');
496 $name = $indivs[$individual];
497 $phone = $indiv_phone[$individual];
498 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
500 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
502 // Get the names of the families assigned this home teaching companionship
503 $sql = "SELECT * FROM tc_family AS tf JOIN tc_individual AS ti WHERE tf.individual=ti.individual AND tf.valid=1 AND tf.companionship=".$unique_companionships[$j]['companionship'];
504 $sql = $sql . " ORDER BY ti.name ASC";
505 $this->db->query($sql,__LINE__,__FILE__);
506 while ($this->db->next_record()) {
507 $family_name = $this->db->f('name');
508 $family_id = $this->db->f('family');
509 $this->nextmatchs->template_alternate_row_color(&$this->t);
510 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
512 $header_row="<th width=$comp_width><font size=-2>Families</th>";
514 // First check to see if the currently assigned companionship has visited them
515 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
516 " AND companionship=".$unique_companionships[$j]['companionship'].
517 " AND family=". $family_id;
518 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
519 if($this->db2->num_rows($query_id) == 0) {
520 // We did not find any visits made by the currently assigned companionship,
521 // look for visits made by any other companionship other than 0. (0 == Presidency Visit)
522 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
523 " AND companionship!=0".
524 " AND family=". $family_id;
525 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
528 $value = $family_id . "/" . $unique_companionships[$j]['companionship'] . "/" . $date;
529 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
530 if(!$total_visits) { $total_visits = 0; }
531 if($this->db2->next_record()) {
532 if($this->db2->f('visited') == 'y') {
533 $visits++; $total_visits++; $num_families++;
534 $table_data .= '<td width=100 align=center>';
535 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y" checked>Y';
536 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
537 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/"> ';
538 $table_data .= '</td>';
539 } else if($this->db2->f('visited') == 'n') {
541 $table_data .= '<td width=100 align=center>';
542 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
543 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n" checked>N';
544 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/">';
545 $table_data .= '</td>';
547 $table_data .= '<td width=100 align=center>';
548 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
549 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
550 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
551 $table_data .= '</td>';
556 $table_data .= '<td width=100 align=center>';
557 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
558 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
559 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
560 $table_data .= '</td>';
563 $table_data .= "</tr>";
564 $table_data .= "<tr><td colspan=20></td></tr>";
566 $table_data .= "<tr><td colspan=20><hr></td></tr>";
567 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
569 $percent = ceil(($visits / $num_families)*100);
570 $stat_data .= "<td align=center><font size=-2><b>$visits / $num_families<br>$percent%</font></b></td>";
571 $stat_data .= "</tr>";
573 $this->t->set_var('table_width',$table_width);
574 $this->t->set_var('header_row',$header_row);
575 $this->t->set_var('table_data',$table_data);
576 $this->t->set_var('stat_data',$stat_data);
577 $this->t->fp('list','district_list',True);
579 $this->t->set_var('lang_reset','Clear Form');
580 $this->t->set_var('lang_save','Save Changes');
581 $this->t->set_var('savehandle','');
583 $this->t->pfp('out','ht_update_t');
584 $this->t->pfp('addhandle','save');
586 $this->save_sessiondata();
591 $this->t->set_file(array('act_list_t' => 'act_list.tpl'));
592 $this->t->set_block('act_list_t','act_list','list');
594 $this->t->set_var('lang_name','Assignment');
595 $this->t->set_var('lang_date','Date');
596 $this->t->set_var('lang_notes','Description');
598 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
599 $this->db->query($sql,__LINE__,__FILE__);
600 $total_records = $this->db->num_rows();
603 while ($this->db->next_record()) {
604 $activity_list[$i]['activity'] = $this->db->f('activity');
605 $activity_list[$i]['assignment'] = $this->db->f('assignment');
606 $activity_list[$i]['date'] = $this->db->f('date');
607 $activity_list[$i]['notes'] = $this->db->f('notes');
609 $sql = "SELECT * FROM tc_assignment WHERE assignment='" . $activity_list[$i]['assignment'] . "'";
610 $this->db2->query($sql,__LINE__,__FILE__);
611 if($this->db2->next_record()) {
612 $activity_list[$i]['name'] = $this->db2->f('name');
613 $activity_list[$i]['abbreviation'] = $this->db2->f('abbreviation');
618 for ($i=0; $i < count($activity_list); $i++) {
619 $this->nextmatchs->template_alternate_row_color(&$this->t);
620 $this->t->set_var('name',$activity_list[$i]['name']);
621 $this->t->set_var('date',$activity_list[$i]['date']);
622 $activity_notes = $activity_list[$i]['notes'];
623 if(strlen($activity_notes) > 40) { $activity_notes = substr($activity_notes,0,40) . "..."; }
624 $this->t->set_var('notes',$activity_notes);
626 $link_data['menuaction'] = 'tc.tc.act_view';
627 $link_data['activity'] = $activity_list[$i]['activity'];
628 $link_data['action'] = 'view';
629 $this->t->set_var('view',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
630 $this->t->set_var('lang_view','View');
632 $link_data['menuaction'] = 'tc.tc.act_update';
633 $link_data['activity'] = $activity_list[$i]['activity'];
634 $link_data['action'] = 'edit';
635 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
636 $this->t->set_var('lang_edit','Edit');
638 $this->t->fp('list','act_list',True);
641 $link_data['menuaction'] = 'tc.tc.act_update';
642 $link_data['activity'] = '0';
643 $link_data['action'] = 'add';
644 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/tc/index.php',$link_data) .
645 '"><input type="submit" name="Add" value="' . 'Add Activity' .'"></font></form>');
647 $this->t->pfp('out','act_list_t');
648 $this->save_sessiondata();
653 $this->t->set_file(array('act_view_t' => 'act_view.tpl'));
654 $this->t->set_block('act_view_t','part_list','list');
656 $sql = "SELECT * FROM tc_activity WHERE activity=" . intval(get_var('activity',array('GET','POST')));
657 $this->db->query($sql,__LINE__,__FILE__);
658 $this->db->next_record();
659 $this->t->set_var('assignment', $this->db->f('assignment'));
660 $this->t->set_var('date', $this->db->f('date'));
661 $this->t->set_var('notes', $this->db->f('notes'));
663 $sql = "SELECT * FROM tc_assignment WHERE assignment='" . $this->db->f('assignment') . "'";
664 $this->db2->query($sql,__LINE__,__FILE__);
665 if($this->db2->next_record()) {
666 $this->t->set_var('name', $this->db2->f('name'));
667 $this->t->set_var('abbreviation', $this->db2->f('abbreviation'));
669 $this->t->set_var('lang_name','Assignment');
670 $this->t->set_var('lang_date','Date');
671 $this->t->set_var('lang_notes','Description');
672 $this->t->set_var('lang_done','Done');
673 $this->t->set_var('lang_action','View');
675 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
676 $this->t->set_var('tr_color',$tr_color);
678 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_list'));
680 $link_data['menuaction'] = 'tc.tc.act_update';
681 $link_data['activity'] = get_var('activity',array('GET','POST'));
682 $link_data['action'] = 'edit';
683 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
684 $this->t->set_var('lang_edit','Edit');
685 $this->t->set_var('cal_date',$this->db->f('date'));
687 // Now find out which indivs participated in this activity
688 $sql = "SELECT * FROM tc_participation WHERE activity=" . intval(get_var('activity',array('GET','POST')));
689 $this->db->query($sql,__LINE__,__FILE__);
690 $total_records = $this->db->num_rows();
693 while ($this->db->next_record()) {
694 $part_list[$i]['individual'] = $this->db->f('individual');
698 for ($i=0; $i < count($part_list); $i++) {
699 $sql = "SELECT * FROM tc_individual WHERE individual=" . $part_list[$i]['individual'];
700 $this->db->query($sql,__LINE__,__FILE__);
701 $this->db->next_record();
702 $names[$i] = $this->db->f('name');
706 for ($i=0; $i < count($names); $i++) {
707 //$this->nextmatchs->template_alternate_row_color(&$this->t);
708 $this->t->set_var('individual_name',$names[$i]);
709 if(($i+1) % 3 == 0) {
710 $this->t->set_var('table_sep',"</td></tr><tr>");
712 $this->t->set_var('table_sep',"</td>");
714 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
715 $this->t->fp('list','part_list',True);
718 $this->t->pfp('out','act_view_t');
719 $this->save_sessiondata();
722 function act_update()
724 $this->t->set_file(array('form' => 'act_update.tpl'));
725 $this->t->set_block('form','individual_list','list');
726 $this->t->set_block('form','add','addhandle');
727 $this->t->set_block('form','edit','edithandle');
728 $this->t->set_var('lang_done','Done');
730 $action = get_var('action',array('GET','POST'));
731 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_list'));
732 $activity['activity'] = intval(get_var('activity',array('GET','POST')));
734 if($action == 'save') {
735 $activity['assignment'] = get_var('assignment',array('POST'));
736 $activity['date'] = get_var('date',array('POST'));
737 $activity['notes']= get_var('notes',array('POST'));
738 $this->db->query("UPDATE tc_activity set " .
739 " assignment='" . $activity['assignment'] .
740 "', date='" . $activity['date'] . "'" .
741 ", notes=\"" . $activity['notes'] . "\"" .
742 " WHERE activity=" . $activity['activity'],__LINE__,__FILE__);
744 // Delete all the individuals who have particiapted in this activity
745 $this->db->query("DELETE from tc_participation where activity=".$activity['activity'],__LINE__,__FILE__);
747 // Re-add the individuals who are checked as having participated in this activity
748 $indivs = get_var('individual_name',array('POST'));
749 if(is_array($indivs)) { // Only do the foreach loop if we have a valid array of indivs to work with
750 foreach ($indivs as $individual) {
751 $this->db->query("INSERT INTO tc_participation (individual,activity) " .
752 "VALUES (" . $individual . ",". $activity['activity'] . ")",__LINE__,__FILE__);
760 if($action == 'insert') {
761 $activity['assignment'] = get_var('assignment',array('POST'));
762 $activity['date'] = get_var('date',array('POST'));
763 $activity['notes']= get_var('notes',array('POST'));
764 $this->db->query("INSERT INTO tc_activity (assignment,date,notes) " .
765 "VALUES ('" . $activity['assignment'] . "','" .
766 $activity['date'] . "',\"" . $activity['notes'] . "\")",__LINE__,__FILE__);
768 $sql = "SELECT * FROM tc_activity WHERE assignment='".$activity['assignment']."' " .
769 " AND date='".$activity['date']."' AND notes=\"".$activity['notes']."\"";
770 $this->db->query($sql,__LINE__,__FILE__);
771 if($this->db->next_record()) {
772 //print "activity: " . $this->db->f('activity') . "<br>";
773 $activity['activity'] = $this->db->f('activity');
776 $indivs = get_var('individual_name',array('POST'));
777 foreach ($indivs as $individual)
779 $this->db->query("INSERT INTO tc_participation (individual,activity) " .
780 "VALUES (" . $individual . ",". $activity['activity'] . ")",__LINE__,__FILE__);
787 if($action == 'add') {
788 $activity['activity'] = 0;
789 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
790 $this->t->set_var('assignment','');
791 $this->t->set_var('date','');
792 $this->t->set_var('notes','');
793 $this->t->set_var('lang_done','Cancel');
794 $this->t->set_var('lang_action','Adding New Activity');
795 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_update&activity=' .
796 $activity['activity'] . '&action=' . 'insert'));
799 if($action == 'edit') {
800 $sql = "SELECT * FROM tc_activity WHERE activity=" . $activity['activity'];
801 $this->db->query($sql,__LINE__,__FILE__);
802 $this->db->next_record();
803 $this->t->set_var('cal_date',$this->jscal->input('date',$this->db->f('date'),'','','','','',$this->cal_options));
804 $this->t->set_var('assignment', $this->db->f('assignment'));
805 $assignment = $this->db->f('assignment');
806 $this->t->set_var('date', $this->db->f('date'));
807 $this->t->set_var('notes', $this->db->f('notes'));
808 $this->t->set_var('lang_done','Cancel');
809 $this->t->set_var('lang_action','Editing Activity');
810 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_update&activity=' .
811 $activity['activity'] . '&action=' . 'save'));
814 // Create the assignments drop-down list
815 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
816 $this->db->query($sql,__LINE__,__FILE__);
818 while ($this->db->next_record()) {
819 $assignments[$i]['assignment'] = $this->db->f('assignment');
820 $assignments[$i]['name'] = $this->db->f('name');
821 $assignments[$i]['abbreviation'] = $this->db->f('abbreviation');
825 $assignment_data.= '<select name=assignment>';
826 $assignment_data.= '<option value=0></option>';
827 for ($j=0; $j < count($assignments); $j++) {
828 $id = $assignments[$j]['assignment'];
829 $name = $assignments[$j]['name'];
830 if($assignments[$j]['assignment'] == $assignment) {
831 $selected[$id] = 'selected="selected"';
835 $assignment_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
837 $assignment_data.='</select>';
838 $this->t->set_var('assignment_data',$assignment_data);
840 // Create individual selection boxes
841 $sql = "SELECT * FROM tc_individual";
842 $this->db->query($sql,__LINE__,__FILE__);
844 while ($this->db->next_record()) {
845 if($this->db->f('valid') == 1 || $action != 'add') {
846 $indiv_name[$i] = $this->db->f('name');
847 $individual[$i] = $this->db->f('individual');
848 $indiv_valid[$i] = $this->db->f('valid');
852 array_multisort($indiv_name, $individual, $indiv_valid);
855 for ($i=0; $i < count($individual); $i++) {
856 //$this->nextmatchs->template_alternate_row_color(&$this->t);
857 $sql = "SELECT * FROM tc_participation where activity=". $activity['activity'] . " AND individual=" . $individual[$i];
858 $this->db->query($sql,__LINE__,__FILE__);
859 if($this->db->next_record()) {
860 $this->t->set_var('checked','checked');
863 $this->t->set_var('checked','');
866 if($checked || $indiv_valid[$i] == 1) {
867 $this->t->set_var('individual_name',$indiv_name[$i]);
868 $this->t->set_var('individual',$individual[$i]);
869 if(($j+1) % 3 == 0) {
870 $this->t->set_var('table_sep',"</td></tr><tr>");
872 $this->t->set_var('table_sep',"</td>");
874 if(($j) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
875 $this->t->fp('list','individual_list',True);
880 $this->t->set_var('lang_reset','Clear Form');
881 $this->t->set_var('lang_add','Add Activity');
882 $this->t->set_var('lang_save','Save Changes');
883 $this->t->set_var('edithandle','');
884 $this->t->set_var('addhandle','');
886 $this->t->pfp('out','form');
887 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
888 if($action == 'add') { $this->t->pfp('addhandle','add'); }
890 $this->save_sessiondata();
893 function assign_view()
895 $this->t->set_file(array('assign_view_t' => 'assign_view.tpl'));
896 $this->t->set_block('assign_view_t','assign_view','list');
898 $this->t->set_var('lang_name','Assignment Name');
899 $this->t->set_var('lang_code','Abbreviation');
901 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
902 $this->db->query($sql,__LINE__,__FILE__);
903 $total_records = $this->db->num_rows();
906 while ($this->db->next_record()) {
907 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
908 $assignment_list[$i]['name'] = $this->db->f('name');
909 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
913 for ($i=0; $i < count($assignment_list); $i++) {
914 $this->nextmatchs->template_alternate_row_color(&$this->t);
915 $this->t->set_var('name',$assignment_list[$i]['name']);
916 $this->t->set_var('abbreviation',$assignment_list[$i]['abbreviation']);
918 $link_data['menuaction'] = 'tc.tc.assign_update';
919 $link_data['assignment'] = $assignment_list[$i]['assignment'];
920 $link_data['action'] = 'edit';
921 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
922 $this->t->set_var('lang_edit','Edit');
924 $link_data['menuaction'] = 'tc.tc.assign_update';
925 $link_data['assignment'] = '0';
926 $link_data['action'] = 'add';
927 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/tc/index.php',$link_data) .
928 '"><input type="submit" name="Add" value="' . 'Add Assignment' .'"></font></form>');
930 $this->t->fp('list','assign_view',True);
933 $this->t->pfp('out','assign_view_t');
934 $this->save_sessiondata();
937 function assign_update()
939 $this->t->set_file(array('form' => 'assign_update.tpl'));
940 $this->t->set_block('form','add','addhandle');
941 $this->t->set_block('form','edit','edithandle');
942 $this->t->set_var('lang_done','Done');
944 $action = get_var('action',array('GET','POST'));
945 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_view'));
946 $assignment['assignment'] = intval(get_var('assignment',array('GET','POST')));
948 if($action == 'save') {
949 $assignment['name'] = get_var('name',array('POST'));
950 $assignment['abbreviation'] = get_var('abbreviation',array('POST'));
951 $this->db->query("UPDATE tc_assignment set " .
952 " name='" . $assignment['name'] . "'" .
953 ", abbreviation='" . $assignment['abbreviation'] . "'" .
954 " WHERE assignment=" . $assignment['assignment'],__LINE__,__FILE__);
956 $this->assign_view();
960 if($action == 'insert') {
961 $assignment['name'] = get_var('name',array('POST'));
962 $assignment['abbreviation'] = get_var('abbreviation',array('POST'));
963 $this->db->query("INSERT INTO tc_assignment (name,abbreviation) " .
964 "VALUES ('" . $assignment['name'] . "','" .
965 $assignment['abbreviation'] . "')",__LINE__,__FILE__);
966 $this->assign_view();
970 if($action == 'add') {
971 $assignment['assignment'] = 0;
972 $this->t->set_var('name','');
973 $this->t->set_var('abbreviation','');
974 $this->t->set_var('lang_done','Cancel');
975 $this->t->set_var('lang_action','Adding New Assignment');
976 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_update&assignment=' .
977 $assignment['assignment'] . '&action=' . 'insert'));
980 if($action == 'edit')
982 $sql = "SELECT * FROM tc_assignment WHERE assignment=" . $assignment['assignment'];
983 $this->db->query($sql,__LINE__,__FILE__);
984 $this->db->next_record();
985 $this->t->set_var('name', $this->db->f('name'));
986 $this->t->set_var('abbreviation', $this->db->f('abbreviation'));
987 $this->t->set_var('lang_done','Cancel');
988 $this->t->set_var('lang_action','Editing Assignment');
989 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_update&assignment=' .
990 $assignment['assignment'] . '&action=' . 'save'));
993 $this->t->set_var('lang_reset','Clear Form');
994 $this->t->set_var('lang_add','Add Assignment');
995 $this->t->set_var('lang_save','Save Changes');
996 $this->t->set_var('edithandle','');
997 $this->t->set_var('addhandle','');
999 $this->t->pfp('out','form');
1000 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
1001 if($action == 'add') { $this->t->pfp('addhandle','add'); }
1003 $this->save_sessiondata();
1008 $this->t->set_file(array('par_view_t' => 'par_view.tpl'));
1009 $this->t->set_block('par_view_t','header_list','list1');
1010 $this->t->set_block('par_view_t','individual_list','list2');
1012 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
1013 $this->db->query($sql,__LINE__,__FILE__);
1015 while ($this->db->next_record()) {
1016 $individual_name[$i] = $this->db->f('name');
1017 $individual[$i] = $this->db->f('individual');
1020 array_multisort($individual_name, $individual);
1022 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
1023 $this->db->query($sql,__LINE__,__FILE__);
1024 $total_records = $this->db->num_rows();
1027 while ($this->db->next_record()) {
1028 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1029 $activity_list[$i]['date'] = $this->db->f('date');
1030 $activity_list[$i]['activity'] = $this->db->f('activity');
1034 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1035 $this->db->query($sql,__LINE__,__FILE__);
1037 while($this->db->next_record()) {
1038 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1039 $assignment_list[$i]['name'] = $this->db->f('name');
1040 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1044 $individual_width=300; $part_width=25; $assignment_width=50;
1045 $total_width=$individual_width+$part_width;
1046 for ($i=0; $i < count($assignment_list); $i++) {
1047 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1048 $this->t->set_var('assignment_abbreviation',$assignment_list[$i]['abbreviation']);
1049 $this->t->fp('list1','header_list',True);
1050 $total_width += $assignment_width;
1053 for ($i=0; $i < count($individual); $i++) {
1054 $participated=0; $part_table = '';
1055 $this->nextmatchs->template_alternate_row_color(&$this->t);
1056 $this->t->set_var('individual_name',$individual_name[$i]);
1057 for ($j=0; $j < count($assignment_list); $j++) {
1058 $date = "0000-00-00"; $checkmark=0; $num_matches=0;
1059 for ($k=0; $k < count($activity_list); $k++) {
1060 if($assignment_list[$j]['assignment'] == $activity_list[$k]['assignment']) {
1061 $sql = "SELECT * FROM tc_participation where " .
1062 " activity=" . $activity_list[$k]['activity'] .
1063 " AND individual=" . $individual[$i];
1064 $this->db->query($sql,__LINE__,__FILE__);
1065 while($this->db->next_record()) {
1066 if($activity_list[$k]['date'] > $date) {
1067 $date = $activity_list[$k]['date'];
1076 $part_table .= '<td align=center><img src="images/checkmark.gif">';
1077 $part_table .= '<font size=-2>'.$num_matches.'</font><br>';
1078 $part_table .= '<font size=-2>'.$date.'</font></td>';
1080 $part_table .= '<td> </td>';
1084 $part_table .= '<td align=center><img src="images/checkmark.gif">'.$participated.'</td>';
1086 $part_table .= '<td> </td>';
1088 $this->t->set_var('part_table',$part_table);
1089 $this->t->fp('list2','individual_list',True);
1091 $this->t->set_var('total_width',$total_width);
1092 $this->t->set_var('individual_width',$individual_width);
1093 $this->t->set_var('part_width',$part_width);
1094 $this->t->set_var('act_width',$act_width);
1095 $this->t->pfp('out','par_view_t');
1096 $this->save_sessiondata();
1099 function willing_view()
1101 $this->t->set_file(array('willing_view_t' => 'willing_view.tpl'));
1102 $this->t->set_block('willing_view_t','header_list','list1');
1103 $this->t->set_block('willing_view_t','individual_list','list2');
1105 $this->t->set_var('lang_filter','Filter');
1106 $this->t->set_var('lang_filter_unwilling','Filter out unwilling individuals:');
1108 $filter_unwilling = get_var('filter_unwilling',array('POST'));
1109 $this->t->set_var('filter_unwilling',$filter_unwilling);
1111 if($filter_unwilling == 'y' || $filter_unwilling == '') {
1112 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\" checked>Y";
1113 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\">N";
1114 $filter_input.= " ";
1116 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\">Y";
1117 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\" checked>N";
1118 $filter_input.= " ";
1120 $this->t->set_var('filter_input',$filter_input);
1122 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
1123 $this->db->query($sql,__LINE__,__FILE__);
1125 while ($this->db->next_record()) {
1126 $indiv_name[$i] = $this->db->f('name');
1127 $individual[$i] = $this->db->f('individual');
1128 $indiv_phone[$individual[$i]] = $this->db->f('phone');
1131 array_multisort($indiv_name, $individual);
1133 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1134 $this->db->query($sql,__LINE__,__FILE__);
1136 while($this->db->next_record()) {
1137 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1138 $assignment_list[$i]['name'] = $this->db->f('name');
1139 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1143 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
1144 $this->db->query($sql,__LINE__,__FILE__);
1145 $total_records = $this->db->num_rows();
1148 while ($this->db->next_record()) {
1149 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1150 $activity_list[$i]['date'] = $this->db->f('date');
1151 $activity_list[$i]['activity'] = $this->db->f('activity');
1155 $indiv_width=275; $willing_width=40; $assignment_width=50;
1156 $total_width=$indiv_width+$willing_width;
1158 for ($i=0; $i < count($assignment_list); $i++) {
1159 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1160 $this->t->set_var('assignment_abbreviation',$assignment_list[$i]['abbreviation']);
1161 $this->t->fp('list1','header_list',True);
1162 $total_width += $assignment_width;
1163 $total_willing[$i] = 0;
1166 for ($i=0; $i < count($individual); $i++) {
1167 $willing_table = ''; $indiv_willing=0;
1168 $this->t->set_var('individual_name',$indiv_name[$i]);
1169 $this->t->set_var('individual_phone',$indiv_phone[$individual[$i]]);
1170 $this->t->set_var('editurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_update&individual=' .
1171 $individual[$i] . '&action=' . 'edit'));
1172 for ($j=0; $j < count($assignment_list); $j++) {
1173 $found_willingness=0;
1174 $sql = "SELECT * FROM tc_willingness where " .
1175 " assignment=" . $assignment_list[$j]['assignment'] .
1176 " AND individual=" . $individual[$i];
1177 $this->db->query($sql,__LINE__,__FILE__);
1178 while($this->db->next_record()) {
1179 $found_willingness=1;
1181 $sql = "SELECT * FROM tc_activity where " .
1182 " assignment=". $assignment_list[$j]['assignment'] .
1183 " ORDER by date DESC";
1184 $this->db2->query($sql,__LINE__,__FILE__);
1185 if($this->db2->next_record()) {
1186 $activity = $this->db2->f('activity');
1187 $date = $this->db2->f('date');
1188 $sql = "SELECT * FROM tc_participation where " .
1189 " activity=" . $activity .
1190 " AND individual=". $individual[$i];
1191 $this->db3->query($sql,__LINE__,__FILE__);
1192 if($this->db3->next_record()) {
1197 if($this->db->f('willing') == 'y') {
1198 $total_willing[$j]++;
1200 $willing_table .= '<td align=center><img src="images/checkmark.gif"><br><font size=-2>'.$date_part.'</font></td></td>';
1201 } else if($this->db->f('willing') == 'n') {
1202 $willing_table .= '<td align=center><img src="images/x.gif"></td>';
1205 $willing_table .= "<td> </td>";
1208 if(!$found_willingness) {
1210 $willing_table .= "<td> </td>";
1213 if(($indiv_willing == 1) || ($filter_unwilling == 'n')) {
1214 $this->t->set_var('willing_table',$willing_table);
1215 $this->t->fp('list2','individual_list',True);
1216 $this->nextmatchs->template_alternate_row_color(&$this->t);
1220 $stat_table = '<td><b>Total Willing to Serve</b></td>';
1221 for ($j=0; $j < count($assignment_list); $j++) {
1222 $stat_table .= "<td align=center><b>".$total_willing[$j]."</b></td>";
1224 $this->t->set_var('stat_table',$stat_table);
1226 $this->t->set_var('total_width',$total_width);
1227 $this->t->set_var('individual_width',$indiv_width);
1228 $this->t->set_var('willing_width',$willing_width);
1229 $this->t->pfp('out','willing_view_t');
1230 $this->save_sessiondata();
1233 function willing_update()
1235 //print "<font color=red>Willingness Update Under Constrcution</font>";
1236 //$this->willing_view();
1239 $this->t->set_file(array('willing_update_t' => 'willing_update.tpl'));
1240 $this->t->set_block('willing_update_t','assignment_list','list');
1241 $this->t->set_block('willing_update_t','save','savehandle');
1243 $individual = get_var('individual',array('GET','POST'));
1244 $this->t->set_var('individual',$individual);
1245 $action = get_var('action',array('GET','POST'));
1247 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_view'));
1248 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_update&action=save'));
1249 $this->t->set_var('lang_done','Cancel');
1250 $this->t->set_var('title','Willingness Update ');
1252 if($action == 'save') {
1253 // Delete all the previous willingness entries for this individual
1254 $this->db->query("DELETE from tc_willingness where individual=" . $individual ,__LINE__,__FILE__);
1256 // Now, add the assignment willingness that is checked for this individual
1257 $new_data = get_var('willingness',array('POST'));
1258 foreach ($new_data as $data) {
1259 $data_array = explode("/",$data);
1260 $assignment = $data_array[0];
1261 $willing = $data_array[1];
1262 //print "individual: $individual assignment: $assignment willing: $willing<br>";
1263 $this->db->query("INSERT INTO tc_willingness (individual,assignment,willing) " .
1264 "VALUES (" . $individual .",". $assignment .",'". $willing . "')",__LINE__,__FILE__);
1266 $this->willing_view();
1270 $assignment_width=300; $willing_width=25; $table_width=$assignment_width + $willing_width;
1273 // Find out the individual's name
1274 $sql = "SELECT * FROM tc_individual WHERE individual=".$individual." AND valid=1";
1275 $this->db->query($sql,__LINE__,__FILE__);
1276 if($this->db->next_record()) {
1277 $indiv_name = $this->db->f('name');
1278 $this->t->set_var('individual_name',$indiv_name);
1281 // Select all the assignments
1282 $sql = "SELECT * FROM tc_assignment ORDER by name ASC";
1283 $this->db->query($sql,__LINE__,__FILE__);
1285 while ($this->db->next_record()) {
1286 $assignment = $this->db->f('assignment');
1287 $assignment_name = $this->db->f('name');
1288 $assignment_abbreviation = $this->db->f('abbreviation');
1290 $this->nextmatchs->template_alternate_row_color(&$this->t);
1291 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$assignment_name</td>";
1293 $header_row="<th width=$comp_width><font size=-2>Assignments</th><th>Willingness</th>";
1294 $sql = "SELECT * FROM tc_willingness WHERE individual=".$individual." AND assignment=".$assignment;
1295 $this->db2->query($sql,__LINE__,__FILE__);
1296 $value = $assignment;
1298 if($this->db2->next_record()) {
1299 if($this->db2->f('willing') == 'y') {
1300 $table_data .= '<td width=100 align=center>';
1301 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y" checked>Y';
1302 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1303 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/"> ';
1304 $table_data .= '</td>';
1305 } else if($this->db2->f('willing') == 'n') {
1306 $table_data .= '<td width=100 align=center>';
1307 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1308 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n" checked>N';
1309 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/">';
1310 $table_data .= '</td>';
1312 $table_data .= '<td width=100 align=center>';
1313 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1314 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1315 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1316 $table_data .= '</td>';
1319 $table_data .= '<td width=100 align=center>';
1320 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1321 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1322 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1323 $table_data .= '</td>';
1326 $table_data .= "\n";
1327 $table_data .= "</tr>";
1328 $table_data .= "<tr><td colspan=20></td></tr>";
1331 $table_data .= "<tr><td colspan=20><hr></td></tr>";
1333 $this->t->set_var('table_width',$table_width);
1334 $this->t->set_var('header_row',$header_row);
1335 $this->t->set_var('table_data',$table_data);
1336 $this->t->fp('list','assignment_list',True);
1338 $this->t->set_var('lang_reset','Clear Form');
1339 $this->t->set_var('lang_save','Save Changes');
1340 $this->t->set_var('savehandle','');
1342 $this->t->pfp('out','willing_update_t');
1343 $this->t->pfp('addhandle','save');
1345 $this->save_sessiondata();
1349 function ppi_sched()
1351 $this->t->set_file(array('ppi_sched_t' => 'ppi_sched.tpl'));
1352 $this->t->set_block('ppi_sched_t','individual_list','indivlist');
1353 $this->t->set_block('ppi_sched_t','appt_list','apptlist');
1354 $action = get_var('action',array('GET','POST'));
1356 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1357 $this->t->set_var('lang_reset','Clear Changes');
1359 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
1360 $this->t->set_var('ppi_link_title',$this->ppi_frequency_label . ' PPIs');
1362 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
1363 $this->t->set_var('schedule_ppi_link_title','Schedule ' . $this->ppi_frequency_label . ' PPIs');
1365 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched&action=save'));
1366 $this->t->set_var('title',$this->ppi_frequency_label . ' PPI Scheduler');
1368 $header_row = "<th ><font size=-2>Individual Name</th>";
1369 $header_row.= "<th><font size=-2>Phone</th>";
1370 $header_row.= "<th><font size=-2>Priority</th>";
1371 $header_row.= "<th><font size=-2>Last PPI</th>";
1372 $header_row.= "<th><font size=-2>Scheduling Notes</th>";
1373 $table_data=""; $completed_data=""; $totals_data="";
1377 $period = intval(($month-1)/$this->ppi_frequency) + 1;
1378 $start_of_period = ($period-1)*$this->ppi_frequency + 1;
1379 $end_of_period = $period * $this->ppi_frequency;
1381 if($action == 'save') {
1382 // Save any changes made to the appointment table
1383 $new_data = get_var('appt_notes',array('POST'));
1384 if($new_data != "") {
1385 foreach ($new_data as $entry) {
1386 $indiv = $entry['individual'];
1387 $appointment = $entry['appointment'];
1388 $location = $entry['location'];
1389 $presidency_location = $entry['presidency_location'];
1390 if($location == "") { $location = $presidency_location; }
1391 if($indiv == 0) { $location = ""; }
1393 //Only perform a database update if we have made a change to this appointment
1394 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and individual='$indiv' and location='$location'";
1395 $this->db->query($sql,__LINE__,__FILE__);
1396 if(!$this->db->next_record()) {
1397 // Perform database save actions here
1398 $this->db->query("UPDATE tc_appointment set " .
1399 " individual='" . $indiv . "'" .
1400 ",location='" . $location . "'" .
1401 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1402 // Email the appointment
1403 $this->email_appt($appointment);
1408 // Save any changes made to the ppi notes table
1409 $new_data = get_var('notes',array('POST'));
1410 foreach ($new_data as $entry) {
1411 $notes = $entry['notes'];
1412 $individual = $entry['individual'];
1413 $priority = $entry['pri'];
1415 // Perform database save actions here
1416 $sql = "SELECT * FROM tc_individual WHERE individual='$individual'";
1417 $this->db->query($sql,__LINE__,__FILE__);
1418 if ($this->db->next_record()) {
1419 $scheduling_priority = $this->db->f('scheduling_priority');
1420 //$this->logToFile("ppi_sched", "UPDATE tc_scheduling_priority SET priority='$priority', notes=\"$notes\" WHERE scheduling_priority='$scheduling_priority'");
1421 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$priority', notes=\"$notes\" WHERE scheduling_priority='$scheduling_priority'", __LINE__, __FILE__);
1425 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched');
1426 //Header('Location: ' . $take_me_to_url);
1429 // create the individual id -> individual name mapping
1430 $sql = "SELECT * FROM tc_individual where valid=1 and steward='$this->default_stewardship' ORDER BY name ASC";
1431 $this->db->query($sql,__LINE__,__FILE__);
1435 while ($this->db->next_record()) {
1436 $indiv_name[$i] = $this->db->f('name');
1437 $individual[$i] = $this->db->f('individual');
1440 array_multisort($indiv_name, $individual);
1442 // APPOINTMENT TABLE
1443 $appt_header_row = "<th><font size=-2>Date</th>";
1444 $appt_header_row.= "<th><font size=-2>Time</th>";
1445 $appt_header_row.= "<th><font size=-2>Individual</th>";
1446 $appt_header_row.= "<th><font size=-2>Location</th>";
1447 $appt_table_data = "";
1450 $total_indivs=0; $indivs_with_yearly_ppi=0;
1452 // Get the President
1453 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti where tp.individual=ti.individual AND tp.valid=1 AND ";
1454 if($this->yearly_ppi_interviewer == 1) { $sql .= " (tp.president=1)"; }
1455 if($this->yearly_ppi_interviewer == 2) { $sql .= " (tp.president=1 OR tp.counselor=1)"; }
1456 if($this->yearly_ppi_interviewer == 3) { $sql .= " (tp.president=1 OR tp.counselor=1 OR tp.secretary=1)"; }
1457 $this->db->query($sql,__LINE__,__FILE__);
1458 while ($this->db->next_record()) {
1459 $presidency_name = $this->db->f('name');
1460 $presidency_name_array = explode(",",$presidency_name);
1461 $presidency_last_name = $presidency_name_array[0];
1462 $presidency_id = $this->db->f('presidency');
1463 $presidency_address = $this->db->f('address');
1464 $presidency_location = "$presidency_last_name"." home ($presidency_address)";
1465 $appt_table_data = "";
1467 // Display a scheduling table for this presidency member
1468 $not_completed_table_title = "All individuals with " . $this->ppi_frequency_label . " PPI Not Completed";
1469 $appt_table_title = $presidency_name . ": " . $this->ppi_frequency_label." PPI Appointment Slots";
1470 $this->t->set_var('not_completed_table_title',$not_completed_table_title);
1471 $this->t->set_var('appt_table_title',$appt_table_title);
1473 // query the database for all the appointments
1474 $sql = "SELECT * FROM tc_appointment where presidency=".$presidency_id." and date>=CURDATE() ORDER BY date ASC, time ASC";
1475 $this->db2->query($sql,__LINE__,__FILE__);
1477 while ($this->db2->next_record()) {
1478 $appointment = $this->db2->f('appointment');
1479 $indiv = $this->db2->f('individual');
1480 $location = $this->db2->f('location');
1481 if(($location == "") && ($indiv > 0)) { $location = $presidency_location; }
1483 $date = $this->db2->f('date');
1484 $date_array = explode("-",$date);
1485 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1486 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1488 $time = $this->db2->f('time');
1489 $time_array = explode(":",$time);
1490 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1492 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1493 $appt_table_data.= "<td align=center>$day_string</td>";
1494 $appt_table_data.= "<td align=center>$time_string</td>";
1496 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][individual]>';
1497 $appt_table_data.= '<option value=0></option>';
1498 for ($i=0; $i < count($individual); $i++) {
1499 $id = $individual[$i];
1500 $name = $indiv_name[$i];
1501 if($individual[$i] == $indiv) {
1502 $selected[$id] = 'selected="selected"';
1504 $selected[$id] = '';
1506 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1508 $appt_table_data.='</select></td>';
1510 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
1511 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
1513 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1515 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1516 $this->t->set_var('tr_color',$tr_color);
1518 $this->t->set_var('appt_table_data',$appt_table_data);
1519 $this->t->set_var('appt_header_row',$appt_header_row);
1520 $this->t->set_var('lang_save','Save Appts for ' . $presidency_name);
1522 $this->t->fp('apptlist','appt_list',True);
1525 // PPI SCHEDULING TABLE
1526 $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";
1527 $this->db->query($sql,__LINE__,__FILE__);
1531 while ($this->db->next_record()) {
1532 $individual[$i] = $this->db->f('individual');
1533 $indiv_name[$i] = $this->db->f('name');
1534 $indiv_phone[$individual[$i]] = $this->db->f('phone');
1535 $indiv_priority[$individual[$i]] = $this->db->f('priority');
1536 $indiv_notes[$individual[$i]] = $this->db->f('notes');
1541 $max = count($individual);
1543 for($i=0; $i < $max; $i++) {
1544 $id = $individual[$i];
1545 $name = $indiv_name[$i];
1546 $phone = $indiv_phone[$id];
1547 $priority = $indiv_priority[$id];
1548 $notes = $indiv_notes[$id];
1550 // If this individual has had a PPI this period, don't show him on the schedule list
1551 $year_start = $year . "-" . $start_of_period . "-01";
1552 $year_end = $year . "-" . $end_of_period . "-31";
1553 $sql = "SELECT * FROM tc_interview WHERE date >= '$year_start' AND date <= '$year_end' ".
1554 "AND individual=" . $id . " AND interview_type='ppi' ORDER BY date DESC";
1555 $this->db2->query($sql,__LINE__,__FILE__);
1557 if(!$this->db2->next_record()) {
1558 $sql = "SELECT * FROM tc_interview WHERE individual=" . $id . " AND interview_type='ppi' ORDER BY date DESC";
1559 $this->db->query($sql,__LINE__,__FILE__);
1560 if($this->db->next_record()) {
1561 $date = $this->db->f('date');
1565 $link_data['menuaction'] = 'tc.tc.ppi_update';
1566 $link_data['individual'] = $id;
1567 $link_data['name'] = $name;
1568 $link_data['interview'] = '';
1569 $link_data['interview_type'] = 1;
1570 $link_data['action'] = 'add';
1571 $link_data['interviewer'] = $interviewer;
1572 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1573 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1574 $this->t->set_var('tr_color',$tr_color);
1575 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1576 $table_data.= "<td align=center>$phone</td>";
1577 //$table_data.= "<td align=center>$priority</td>";
1578 $table_data.= "<td align=center>";
1579 $table_data.= '<select name=notes['.$i.'][pri]>';
1580 foreach(range(0,6) as $num) {
1581 if($num == 0) { $num = 1; } else {$num = $num*5; }
1582 if($priority == $num) {
1583 $selected[$num] = 'selected="selected"';
1585 $selected[$num] = '';
1587 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1589 $table_data.= '</select></td>';
1590 $table_data.= "<td align=center>$date</td>";
1591 $table_data.= '<td><input type=text size="50" maxlength="128" name="notes['.$i.'][notes]" value="'.$notes.'">';
1592 $table_data.= '<input type=hidden name="notes['.$i.'][individual]" value="'.$id.'">';
1593 $table_data.= '<input type=hidden name="notes['.$i.'][indiv_name]" value="'.$name.'">';
1594 $table_data.= '</td>';
1595 $table_data.= '</tr>';
1597 $link_data['menuaction'] = 'tc.tc.ppi_update';
1598 $link_data['interviewer'] = $this->db2->f('interviewer');
1599 $link_data['individual'] = $this->db2->f('individual');
1600 $link_data['name'] = $name;
1601 $link_data['interview'] = $this->db2->f('interview');
1602 $link_data['interview_type'] = $this->db2->f('interview_type');
1603 $link_data['action'] = 'view';
1604 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1605 $indivs_with_yearly_ppi++;
1606 $date = $this->db2->f('date');
1607 $notes = $this->db2->f('notes');
1608 if(strlen($notes) > 40) { $notes = substr($notes,0,40) . "..."; }
1609 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1610 $this->t->set_var('tr_color2',$tr_color2);
1611 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1612 $completed_data.= "<td align=center>$phone</td>";
1613 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1614 $completed_data.= "<td align=left>$notes</td>";
1615 $completed_data.= '</tr>';
1617 } // End for individuals Loop
1619 $completed_table_title = "All individuals with " . $this->ppi_frequency_label . " PPI Completed";
1620 $completed_header_row = "<th><font size=-2>Individual</th>";
1621 $completed_header_row.= "<th><font size=-2>Phone</th>";
1622 $completed_header_row.= "<th><font size=-2>Date</th>";
1623 $completed_header_row.= "<th><font size=-2>PPI Notes</th>";
1625 $this->t->set_var('completed_table_title',$completed_table_title);
1626 $this->t->set_var('header_row',$header_row);
1627 $this->t->set_var('table_data',$table_data);
1628 $this->t->set_var('completed_header_row',$completed_header_row);
1629 $this->t->set_var('completed',$completed_data);
1630 $this->t->set_var('lang_save','Save Pri / Notes');
1631 $this->t->fp('indivlist','individual_list',True);
1633 $totals_header_row = "<th><font size=-2>Individuals</th>";
1634 $totals_header_row.= "<th><font size=-2>$year</th>";
1635 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1636 $totals_data.= "<td align=left><font size=-2><b>Total Individuals with " . $this->ppi_frequency_label . " PPIs completed:</b></font></td>";
1637 $totals_data.= "<td align=center><font size=-2><b>$indivs_with_yearly_ppi / $total_indivs</b></font></td>";
1638 $percent = ceil(($indivs_with_yearly_ppi / $total_indivs)*100);
1639 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1640 $this->t->set_var('tr_color',$tr_color);
1641 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1642 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
1643 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
1644 $totals_data.= "</tr>";
1646 $this->t->set_var('totals',$totals_data);
1647 $this->t->set_var('totals_header_row',$totals_header_row);
1648 $this->t->set_var('ppi_frequency_label',$this->ppi_frequency_label);
1650 $this->t->pfp('out','ppi_sched_t');
1651 $this->save_sessiondata();
1655 function int_sched()
1657 $this->t->set_file(array('int_sched_t' => 'int_sched.tpl'));
1658 $this->t->set_block('int_sched_t','individual_list','indivlist');
1659 $this->t->set_block('int_sched_t','appt_list','apptlist');
1660 $action = get_var('action',array('GET','POST'));
1662 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1663 $this->t->set_var('lang_reset','Clear Changes');
1665 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
1666 $this->t->set_var('int_link_title','Hometeaching Interviews');
1668 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
1669 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
1671 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched&action=save'));
1672 $this->t->set_var('title','Hometeaching Interviews Scheduler');
1674 $indiv_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $int_date_width=20;
1675 $table_width=$indiv_width + $phone_width + $pri_width + $notes_width + $int_date_width;
1676 $header_row = "<th width=$indiv_width><font size=-2>Individual</th>";
1677 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1678 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1679 $header_row.= "<th width=$int_date_width><font size=-2>Last Interview</th>";
1680 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1681 $table_data=""; $completed_data=""; $totals_data="";
1685 $nextyear = $year + 1;
1686 if($month >= 1 && $month <= 3) { $quarter_start=$year."-01-01"; $quarter_end=$year."-04-01"; }
1687 if($month >= 4 && $month <= 6) { $quarter_start=$year."-04-01"; $quarter_end=$year."-07-01"; }
1688 if($month >= 7 && $month <= 9) { $quarter_start=$year."-07-01"; $quarter_end=$year."-10-01"; }
1689 if($month >= 10 && $month <= 12) { $quarter_start=$year."-10-01"; $quarter_end=$nextyear."-01-01"; }
1690 //print "year: $year month: $month quarter_start: $quarter_start quarter_end: $quarter_end<br>";
1692 // create the individual id -> individual name mapping
1693 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY name ASC";
1694 $this->db->query($sql,__LINE__,__FILE__);
1696 $individual_data = NULL;
1697 $indiv_name_data = NULL;
1698 while ($this->db->next_record()) {
1699 $indiv_name_data[$i] = $this->db->f('name');
1700 $individual_data[$i] = $this->db->f('individual');
1701 $individ2name[$individual_data[$i]] = $indiv_name_data[$i];
1704 // add any YM that are home teachers
1705 $sql = "SELECT * FROM tc_companionship where valid=1";
1706 $this->db->query($sql,__LINE__,__FILE__);
1707 while ($this->db->next_record()) {
1708 $tmp_individual = $this->db->f('individual');
1709 $sql = "Select * FROM tc_individual where individual='$tmp_individual' and steward='' and valid=1";
1710 $this->db2->query($sql,__LINE__,__FILE__);
1711 while ($this->db2->next_record()) {
1712 $indiv_name_data[$i] = $this->db2->f('name');
1713 $individual_data[$i] = $this->db2->f('individual');
1714 $individ2name[$individual_data[$i]] = $indiv_name_data[$i];
1718 array_multisort($indiv_name_data, $individual_data);
1720 if($action == 'save') {
1721 // Save any changes made to the appointment table
1722 $new_data = get_var('appt_notes',array('POST'));
1723 if($new_data != "") {
1724 foreach ($new_data as $entry) {
1725 $indiv = $entry['individual'];
1726 $appointment = $entry['appointment'];
1727 $location = $entry['location'];
1728 if($location == "") {
1729 $supervisor = $entry['supervisor'];
1730 $supervisor_array = explode(",", $individ2name[$supervisor]);
1731 $supervisor_last_name = $supervisor_array[0];
1732 $sql = "SELECT * FROM tc_individual where individual='$supervisor'";
1733 $this->db2->query($sql,__LINE__,__FILE__);
1734 if($this->db2->next_record()) {
1735 $supervisor_address = $this->db2->f('address');
1737 $location = "$supervisor_last_name"." home ($supervisor_address)";
1739 if($indiv == 0) { $location = ""; }
1741 //print "indiv: $indiv appointment: $appointment <br>";
1742 //Only perform a database update if we have made a change to this appointment
1743 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and individual='$indiv' and location='$location'";
1744 $this->db->query($sql,__LINE__,__FILE__);
1745 if(!$this->db->next_record()) {
1746 // Perform database save actions here
1747 $this->db->query("UPDATE tc_appointment set " .
1748 " individual='" . $indiv . "'" .
1749 ",location='" . $location . "'" .
1750 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1751 // Email the appointment
1752 $this->email_appt($appointment);
1757 // Save any changes made to the int notes table
1758 $new_data = get_var('hti_notes',array('POST'));
1759 foreach ($new_data as $entry) {
1760 $hti_notes = $entry['notes'];
1761 $individual = $entry['individual'];
1762 $indiv_name = $entry['indiv_name'];
1763 $hti_pri = $entry['pri'];
1764 //print "hti_notes: $hti_notes indiv_name: $indiv_name <Br>";
1765 // Perform database save actions here
1766 $this->db->query("SELECT * FROM tc_companion WHERE individual=$individual and valid=1",__LINE__,__FILE__);
1767 if ($this->db->next_record()) {
1768 $scheduling_priority = $this->db->f('scheduling_priority');
1769 //$this->logToFile("int_sched", "UPDATE tc_scheduling_priority SET priority='$hti_pri', notes=\"$hti_notes\" WHERE scheduling_priority='$scheduling_priority'");
1770 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$hti_pri', notes=\"$hti_notes\" WHERE scheduling_priority='$scheduling_priority'",__LINE__,__FILE__);
1774 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched');
1775 //Header('Location: ' . $take_me_to_url);
1778 // Get the Districts
1779 $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";
1780 $this->db->query($sql,__LINE__,__FILE__);
1782 while ($this->db->next_record()) {
1783 $district = $this->db->f('district');
1784 $districts[$i]['district'] = $this->db->f('district');
1785 $districts[$i]['name'] = $this->db->f('name');
1786 $districts[$i]['supervisor'] = $this->db->f('supervisor');
1787 $districts[$i]['presidency'] = $this->db->f('presidency');
1791 // APPOINTMENT TABLE
1793 $date_width=250; $time_width=100; $indiv_width=200; $location_width=100;
1794 $appt_table_width=$date_width + $time_width + $indiv_width + $location_width;
1795 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1796 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1797 $appt_header_row.= "<th width=$indiv_width><font size=-2>Individual</th>";
1798 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
1799 $appt_table_data = "";
1801 $total_comps=0; $comps_with_quarterly_int=0;
1803 // Display a scheduling table for each district
1804 for ($d=0; $d < count($districts); $d++) {
1805 $table_data=""; $appt_table_data="";
1806 $this->t->set_var('district_number',$districts[$d]['district']);
1807 $this->t->set_var('district_name',$districts[$d]['name']);
1808 $supervisor = $districts[$d]['supervisor'];
1809 $supervisor_array = explode(",", $supervisor);
1810 $supervisor_last_name = $supervisor_array[0];
1811 $sql = "SELECT * FROM tc_individual where individual='$supervisor'";
1812 $this->db2->query($sql,__LINE__,__FILE__);
1813 if($this->db2->next_record()) {
1814 $supervisor_address = $this->db2->f('address');
1816 $location = "$supervisor_last_name"." home ($supervisor_address)";
1817 $table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": All Individuals with Interviews Not Completed";
1818 $appt_table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": Interview Appointment Slots";
1819 $this->t->set_var('table_title',$table_title);
1820 $this->t->set_var('appt_table_title',$appt_table_title);
1822 // query the database for all the appointments
1823 $sql = "SELECT * FROM tc_appointment where presidency=".$districts[$d]['presidency']." and date>=CURDATE() ORDER BY date ASC, time ASC";
1824 $this->db->query($sql,__LINE__,__FILE__);
1826 while ($this->db->next_record()) {
1827 $appointment = $this->db->f('appointment');
1828 $indiv = $this->db->f('individual');
1829 $location = $this->db->f('location');
1830 if(($location == "") && ($indiv > 0)) { $location = "$supervisor_last_name"." home ($supervisor_address)"; }
1832 $date = $this->db->f('date');
1833 $date_array = explode("-",$date);
1834 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1835 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1837 $time = $this->db->f('time');
1838 $time_array = explode(":",$time);
1839 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1841 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1842 $appt_table_data.= "<td align=center>$day_string</td>";
1843 $appt_table_data.= "<td align=center>$time_string</td>";
1845 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][individual]>';
1846 $appt_table_data.= '<option value=0></option>';
1847 for ($i=0; $i < count($individual_data); $i++) {
1848 $id = $individual_data[$i];
1849 $name = $indiv_name_data[$i];
1850 if($individual_data[$i] == $indiv) {
1851 $selected[$id] = 'selected="selected"';
1853 $selected[$id] = '';
1855 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1857 $appt_table_data.='</select></td>';
1859 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
1860 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
1862 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1863 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][supervisor]" value="'.$supervisor.'">';
1865 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1866 $this->t->set_var('tr_color',$tr_color);
1869 $this->t->set_var('appt_table_data',$appt_table_data);
1870 $this->t->set_var('appt_header_row',$appt_header_row);
1871 $this->t->set_var('appt_table_width',$appt_table_width);
1873 // INTERVIEW SCHEDULING TABLE
1875 // Select all the unique companionship numbers for this district
1876 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$d]['district'];
1877 $this->db->query($sql,__LINE__,__FILE__);
1878 $j=0; $unique_companionships = '';
1879 while ($this->db->next_record())
1881 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
1886 for ($j=0; $j < count($unique_companionships); $j++) {
1887 // Select all the companions from each companionship
1888 $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'];
1889 $this->db->query($sql,__LINE__,__FILE__);
1890 $k=0; $int_completed=0;
1891 $comp = $unique_companionships[$j]['companionship'];
1892 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1893 $this->t->set_var('tr_color',$tr_color);
1895 while ($this->db->next_record()) {
1896 // Get this companions information
1897 $individual = $this->db->f('individual');
1899 $id = $this->db->f('individual');
1900 $name = $this->db->f('name');
1901 $phone = $this->db->f('phone');
1902 $hti_pri = $this->db->f('priority');
1903 $hti_notes = $this->db->f('notes');
1905 // If the companionship has already had its quarterly interview,
1906 // Skip the other companion in the companionship.
1907 if($int_completed == 1) {
1908 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1909 $completed_data.= "<td align=center>$phone</td>";
1910 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1911 $completed_data.= "<td align=left>$hti_notes</td>";
1912 $completed_data.= '</tr>';
1913 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1914 $this->t->set_var('tr_color2',$tr_color2);
1915 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1916 $this->t->set_var('tr_color',$tr_color);
1920 // If this companionship has had a hometeaching interview this quarter, don't show them on the schedule list
1921 $sql = "SELECT * FROM tc_interview WHERE date >= '$quarter_start' AND date < '$quarter_end' AND individual='$id' AND interview_type='hti'";
1922 $this->db2->query($sql,__LINE__,__FILE__);
1924 if(!$this->db2->next_record()) {
1925 $sql = "SELECT * FROM tc_interview WHERE individual='$id' AND interview_type='hti' ORDER BY date DESC";
1926 $this->db3->query($sql,__LINE__,__FILE__);
1927 if($this->db3->next_record()) {
1928 $date = $this->db3->f('date');
1932 $link_data['menuaction'] = 'tc.tc.int_update';
1933 $link_data['individual'] = $id;
1934 $link_data['name'] = $name;
1935 $link_data['interview'] = '';
1936 $link_data['action'] = 'add';
1937 $link_data['interview_type'] = 'hti';
1938 $link_data['interviewer'] = $districts[$d]['supervisor'];
1939 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1940 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1941 $table_data.= "<td align=center>$phone</td>";
1942 $table_data.= "<td align=center>";
1943 $table_data.= '<select name=hti_notes['.$i.'][pri]>';
1944 foreach(range(0,6) as $num) {
1945 if($num == 0) { $num = 1; } else {$num = $num*5; }
1946 if($hti_pri == $num) {
1947 $selected[$num] = 'selected="selected"';
1949 $selected[$num] = '';
1951 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1953 $table_data.= '</select></td>';
1954 $table_data.= "<td align=center>$date</td>";
1955 $table_data.= '<td><input type=text size="50" maxlength="128" name="hti_notes['.$i.'][notes]" value="'.$hti_notes.'">';
1956 $table_data.= '<input type=hidden name="hti_notes['.$i.'][individual]" value="'.$id.'">';
1957 $table_data.= '<input type=hidden name="hti_notes['.$i.'][indiv_name]" value="'.$name.'">';
1958 $table_data.= '</td>';
1959 $table_data.= '</tr>'."\n";
1962 $link_data['menuaction'] = 'tc.tc.int_update';
1963 $link_data['interviewer'] = $this->db2->f('interviewer');
1964 $link_data['individual'] = $this->db2->f('individual');
1965 $link_data['name'] = $name;
1966 $link_data['interview'] = $this->db2->f('interview');
1967 $link_data['interview_type'] = 'hti';
1968 $link_data['action'] = 'view';
1969 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1970 $comps_with_quarterly_int++;
1972 $date = $this->db2->f('date');
1973 $hti_notes = $this->db2->f('notes');
1974 if(strlen($hti_notes) > 40) { $hti_notes = substr($hti_notes,0,40) . "..."; }
1975 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1976 $completed_data.= "<td align=center>$phone</td>";
1977 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1978 $completed_data.= "<td align=left>$hti_notes</td>";
1979 $completed_data.= '</tr>';
1984 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1985 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1986 $completed_header_row = "<th width=$name_width><font size=-2>Individual</th>";
1987 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1988 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1989 $completed_header_row.= "<th width=$notes_width><font size=-2>Interview Notes</th>";
1991 $this->t->set_var('table_width',$table_width);
1992 $this->t->set_var('header_row',$header_row);
1993 $this->t->set_var('table_data',$table_data);
1994 $this->t->set_var('completed_header_row',$completed_header_row);
1995 $this->t->set_var('completed_table_width',$completed_table_width);
1996 $this->t->set_var('completed',$completed_data);
1997 $this->t->fp('indivlist','individual_list',True);
1999 } // End for each district loop
2002 $indivs_width=300; $totals_width=100;
2003 $totals_table_width=$indivs_width + $totals_width;
2004 $totals_header_row = "<th width=$indivs_width><font size=-2>Individuals</th>";
2005 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2006 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2007 $totals_data.= "<td align=left><font size=-2><b>Total Companionships with interviews completed:</b></font></td>";
2008 $totals_data.= "<td align=center><font size=-2><b>$comps_with_quarterly_int / $total_comps</b></font></td>";
2009 $percent = ceil(($comps_with_quarterly_int / $total_comps)*100);
2010 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2011 $this->t->set_var('tr_color',$tr_color);
2012 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2013 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2014 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2015 $totals_data.= "</tr>";
2017 $this->t->set_var('totals',$totals_data);
2018 $this->t->set_var('totals_header_row',$totals_header_row);
2019 $this->t->set_var('totals_table_width',$totals_table_width);
2021 $this->t->pfp('out','int_sched_t');
2022 $this->save_sessiondata();
2026 function vis_sched()
2028 $this->t->set_file(array('vis_sched_t' => 'vis_sched.tpl'));
2029 $this->t->set_block('vis_sched_t','family_list','familylist');
2030 $this->t->set_block('vis_sched_t','appt_list','apptlist');
2031 $action = get_var('action',array('GET','POST'));
2033 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
2034 $this->t->set_var('lang_reset','Clear Changes');
2036 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2037 $this->t->set_var('vis_link_title','View Yearly Visits');
2039 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
2040 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2042 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched&action=save'));
2043 $this->t->set_var('title','Presidency Yearly Visit Scheduler');
2045 $family_width=500; $phone_width=40; $pri_width=10; $notes_width=128; $visit_date_width=20;
2046 $table_width=$family_width + $phone_width + $pri_width + $notes_width + $visit_date_width;
2047 $header_row = "<th width=$family_width><font size=-2>Family Name</th>";
2048 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2049 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
2050 $header_row.= "<th width=$visit_date_width><font size=-2>Last Visit</th>";
2051 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
2052 $table_data=""; $completed_data=""; $totals_data="";
2056 // create the family id -> family name mapping
2057 $sql = "SELECT * FROM tc_family AS tf JOIN tc_individual AS ti WHERE tf.individual=ti.individual AND tf.valid=1 AND tf.individual != 0 AND tf.companionship != 0 AND ti.steward='$this->default_stewardship' ORDER BY ti.name ASC";
2058 $this->db->query($sql,__LINE__,__FILE__);
2061 while ($this->db->next_record()) {
2062 $family_id[$i] = $this->db->f('family');
2063 $family_name[$i] = $this->db->f('name');
2064 $familyid2name[$family_id[$i]] = $family_name[$i];
2065 $familyid2address[$family_id[$i]] = $this->db->f('address');
2068 array_multisort($family_name, $family_id);
2070 if($action == 'save') {
2071 // Save any changes made to the appointment table
2072 $new_data = get_var('appt_notes',array('POST'));
2073 if($new_data != "") {
2074 foreach ($new_data as $entry) {
2075 $family = $entry['family'];
2076 $appointment = $entry['appointment'];
2077 $location = $entry['location'];
2078 if($location == "") {
2079 $family_name_array = explode(",", $familyid2name[$family]);
2080 $family_last_name = $family_name_array[0];
2081 $family_address = $familyid2address[$family];
2082 $location = "$family_last_name"." home ($family_address)";
2084 if($family == 0) { $location = ""; }
2086 //Only perform a database update if we have made a change to this appointment
2087 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and family='$family' and location='$location'";
2088 $this->db->query($sql,__LINE__,__FILE__);
2089 if(!$this->db->next_record()) {
2090 // Perform database save actions here
2091 $this->db->query("UPDATE tc_appointment set " .
2092 " family='" . $family . "'" .
2093 ",location='" . $location . "'" .
2094 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
2096 // Email the appointment
2097 $this->email_appt($appointment);
2102 // Save any changes made to the visit notes table
2103 $new_data = get_var('vis_notes',array('POST'));
2104 foreach ($new_data as $entry) {
2105 $visit_notes = $entry['notes'];
2106 $family = $entry['family_id'];
2107 $visit_pri = $entry['pri'];
2108 // Perform database save actions here
2109 $this->db->query("SELECT * FROM tc_family WHERE family='$family'",__LINE__,__FILE__);
2110 if ($this->db->next_record()) {
2111 $scheduling_priority = $this->db->f('scheduling_priority');
2112 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$visit_pri', notes=\"$visit_notes\" WHERE scheduling_priority='$scheduling_priority'", __LINE__, __FILE__);
2116 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched');
2117 //Header('Location: ' . $take_me_to_url);
2120 // APPOINTMENT TABLE
2121 $date_width=250; $time_width=100; $family_width=250; $location_width=100;
2122 $appt_table_width=$date_width + $time_width + $family_width + $location_width;
2123 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
2124 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
2125 $appt_header_row.= "<th width=$family_width><font size=-2>Family</th>";
2126 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
2127 $appt_table_data = "";
2129 // Find out what the President ID is
2130 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.president=1 AND tp.valid=1";
2131 $this->db->query($sql,__LINE__,__FILE__);
2132 if($this->db->next_record()) {
2133 $presidency_name = $this->db->f('name');
2134 $presidency_id = $this->db->f('presidency');
2136 print "<hr><font color=red><h3>-E- Unable to locate Presidency in tc_presidency table</h3></font></hr>";
2140 // query the database for all the appointments
2141 $sql = "SELECT * FROM tc_appointment where presidency=$presidency_id and date>=CURDATE() ORDER BY date ASC, time ASC";
2142 $this->db->query($sql,__LINE__,__FILE__);
2144 while ($this->db->next_record()) {
2145 $appointment = $this->db->f('appointment');
2146 $family = $this->db->f('family');
2147 $location = $this->db->f('location');
2148 $family_name_array = explode(",", $familyid2name[$family]);
2149 $family_last_name = $family_name_array[0];
2150 $family_address = $familyid2address[$family];
2151 if(($location == "") && ($family > 0)) { $location = "$family_last_name"." home ($family_address)"; }
2153 $date = $this->db->f('date');
2154 $date_array = explode("-",$date);
2155 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
2156 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
2158 $time = $this->db->f('time');
2159 $time_array = explode(":",$time);
2160 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
2162 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2163 $appt_table_data.= "<td align=center>$day_string</td>";
2164 $appt_table_data.= "<td align=center>$time_string</td>";
2166 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][family]>';
2167 $appt_table_data.= '<option value=0></option>';
2168 for ($i=0; $i < count($family_id); $i++) {
2169 $id = $family_id[$i];
2170 $name = $family_name[$i];
2171 if($family_id[$i] == $family) {
2172 $selected[$id] = 'selected="selected"';
2174 $selected[$id] = '';
2176 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
2178 $appt_table_data.='</select></td>';
2180 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
2181 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
2183 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
2185 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2186 $this->t->set_var('tr_color',$tr_color);
2189 $this->t->set_var('appt_table_data',$appt_table_data);
2190 $this->t->set_var('appt_header_row',$appt_header_row);
2191 $this->t->set_var('appt_table_width',$appt_table_width);
2194 // VISIT SCHEDULING TABLE
2195 $sql = "SELECT * FROM tc_family AS tf JOIN (tc_scheduling_priority AS tsp, tc_individual as ti) WHERE tf.scheduling_priority=tsp.scheduling_priority AND tf.individual=ti.individual AND tf.valid=1 AND tf.individual != 0 AND tf.companionship != 0 AND ti.steward='$this->default_stewardship' ORDER BY tsp.priority ASC, ti.name ASC";
2196 $this->db->query($sql,__LINE__,__FILE__);
2198 $total_families=0; $families_with_yearly_visit=0;
2200 while ( $this->db->next_record()) {
2202 $id = $this->db->f('family');
2203 $name = $this->db->f('name');
2204 $phone = $this->db->f('phone');
2205 $vis_pri = $this->db->f('priority');
2206 $vis_notes = $this->db->f('notes');
2208 // If this family has had a yearly visit this year, don't show them on the schedule list
2209 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2210 $sql = "SELECT * FROM tc_visit WHERE date > '$year_start' AND date < '$year_end' ".
2211 "AND family=" . $id . " AND companionship=0";
2212 $this->db2->query($sql,__LINE__,__FILE__);
2214 if(!$this->db2->next_record()) {
2215 $sql = "SELECT * FROM tc_visit WHERE family=" . $id . " AND companionship=0 ORDER BY date DESC";
2216 $this->db3->query($sql,__LINE__,__FILE__);
2217 if($this->db3->next_record()) {
2218 $date = $this->db3->f('date');
2222 $link_data['menuaction'] = 'tc.tc.vis_update';
2223 $link_data['visit'] = '';
2224 $link_data['family'] = $id;
2225 $link_data['name'] = $name;
2226 $link_data['action'] = 'add';
2227 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2228 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2229 $table_data.= "<td align=center>$phone</td>";
2230 $table_data.= "<td align=center>";
2231 $table_data.= '<select name=vis_notes['.$id.'][pri]>';
2232 foreach(range(0,6) as $num) {
2233 if($num == 0) { $num = 1; } else {$num = $num*5; }
2234 if($vis_pri == $num) {
2235 $selected[$num] = 'selected="selected"';
2237 $selected[$num] = '';
2239 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2241 $table_data.= '</select></td>';
2242 $table_data.= "<td align=center>$date</td>";
2243 $table_data.= '<td><input type=text size="50" maxlength="128" name="vis_notes['.$id.'][notes]" value="'.$vis_notes.'">';
2244 $table_data.= '<input type=hidden name="vis_notes['.$id.'][family_id]" value="'.$id.'">';
2245 $table_data.= '<input type=hidden name="vis_notes['.$id.'][family_name]" value="'.$name.'">';
2246 $table_data.= '</td>';
2247 $table_data.= '</tr>';
2248 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2249 $this->t->set_var('tr_color',$tr_color);
2251 $link_data['menuaction'] = 'tc.tc.vis_update';
2252 $link_data['visit'] = $this->db2->f('visit');
2253 $link_data['family'] = $this->db2->f('family');
2254 $link_data['name'] = $name;
2255 $link_data['date'] = $this->db2->f('date');
2256 $link_data['action'] = 'view';
2257 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2258 $families_with_yearly_visit++;
2259 $date = $this->db2->f('date');
2260 $vis_notes = $this->db2->f('notes');
2261 if(strlen($vis_notes) > 40) { $vis_notes = stripslashes(substr($vis_notes,0,40) . "..."); }
2262 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2263 $completed_data.= "<td align=center>$phone</td>";
2264 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2265 $completed_data.= "<td align=left>$vis_notes</td>";
2266 $completed_data.= '</tr>';
2267 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
2268 $this->t->set_var('tr_color2',$tr_color2);
2272 $name_width=190; $phone_width=100; $date_width=100; $notes_width=300;
2273 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
2274 $completed_header_row = "<th width=$name_width><font size=-2>Family Name</th>";
2275 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2276 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
2277 $completed_header_row.= "<th width=$notes_width><font size=-2>Visit Notes</th>";
2279 $family_width=300; $totals_width=100;
2280 $totals_table_width=$family_width + $totals_width;
2281 $totals_header_row = "<th width=$family_width><font size=-2>Families</th>";
2282 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2283 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2284 $totals_data.= "<td align=left><font size=-2><b>Total Families with yearly Visits completed:</b></font></td>";
2285 $totals_data.= "<td align=center><font size=-2><b>$families_with_yearly_visit / $total_families</b></font></td>";
2286 $percent = ceil(($families_with_yearly_visit / $total_families)*100);
2287 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2288 $this->t->set_var('tr_color',$tr_color);
2289 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2290 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2291 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2292 $totals_data.= "</tr>";
2294 $this->t->set_var('table_width',$table_width);
2295 $this->t->set_var('header_row',$header_row);
2296 $this->t->set_var('table_data',$table_data);
2297 $this->t->set_var('totals_header_row',$totals_header_row);
2298 $this->t->set_var('totals_table_width',$totals_table_width);
2299 $this->t->set_var('completed_header_row',$completed_header_row);
2300 $this->t->set_var('completed_table_width',$completed_table_width);
2301 $this->t->set_var('completed',$completed_data);
2302 $this->t->set_var('totals',$totals_data);
2303 $this->t->fp('familylist','family_list',True);
2304 $this->t->fp('apptlist','appt_list',True);
2306 $this->t->pfp('out','vis_sched_t');
2307 $this->save_sessiondata();
2312 $this->t->set_file(array('ppi_view_t' => 'ppi_view.tpl'));
2313 $this->t->set_block('ppi_view_t','district_list','list');
2315 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2316 $num_months = get_var('num_months',array('GET','POST'));
2317 if($num_months == '') { $num_months = $this->default_ppi_num_months; }
2318 $this->t->set_var('num_months',$num_months);
2319 if($num_months == 1) {
2320 $this->t->set_var('lang_num_months','Month of History');
2322 $this->t->set_var('lang_num_months','Months of History');
2324 $this->t->set_var('lang_filter','Filter');
2325 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2327 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2328 $this->t->set_var('ppi_link_title',$this->ppi_frequency_label . ' PPIs');
2330 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
2331 $this->t->set_var('schedule_ppi_link_title','Schedule ' . $this->ppi_frequency_label . ' PPIs');
2333 $this->t->set_var('title',$this->ppi_frequency_label . ' PPIs');
2334 $num_months = get_var('num_months',array('GET','POST'));
2335 if($num_months == '') { $num_months = $this->default_ppi_num_years; }
2336 $this->t->set_var('num_months',$num_months);
2337 if($num_months == 1) {
2338 $this->t->set_var('lang_num_months','Year of History');
2340 $this->t->set_var('lang_num_months','Years of History');
2343 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.president=1 AND tp.valid=1";
2344 $this->db->query($sql,__LINE__,__FILE__);
2345 if($this->db->next_record()) {
2346 $president_name = $this->db->f('name');
2347 $interviewer = $this->db->f('individual');
2349 print "<hr><font color=red><h3>-E- Unable to locate President in tc_presidency table</h3></font></hr>";
2352 $this->t->set_var('district_number','*');
2353 $this->t->set_var('district_name',$president_name);
2355 $sql = "SELECT * FROM tc_individual AS ti JOIN tc_scheduling_priority as tsp where ti.scheduling_priority=tsp.scheduling_priority and ti.steward='$this->default_stewardship' and ti.valid=1 ORDER BY ti.individual ASC";
2356 $this->db->query($sql,__LINE__,__FILE__);
2358 while ($this->db->next_record()) {
2359 $individual[$i] = $this->db->f('individual');
2360 $indiv_name[$i] = $this->db->f('name');
2361 $indiv_phone[$individual[$i]] = $this->db->f('phone');
2362 $indiv_priority[$individual[$i]] = $this->db->f('priority');
2363 $indiv_notes[$individual[$i]] = $this->db->f('notes');
2367 array_multisort($indiv_name, $individual);
2368 //var_dump($indiv_name); print "<br><br>"; var_dump($individual);
2370 $header_row="<th width=$comp_width><font size=-2>Individual</th>";
2372 $indiv_width=400; $ppi_width=75; $table_width=$indiv_width + $num_months*$ppi_width;
2374 for($m=$num_months; $m >= 0; $m--) {
2375 $year = date('Y') - $m;
2376 $header_row .= "<th width=150><font size=-2>$year</th>";
2380 for ($j=0; $j < count($individual); $j++) {
2381 $id = $individual[$j];
2382 $name = $indiv_name[$j];
2383 $phone = $indiv_phone[$id];
2385 $link_data['menuaction'] = 'tc.tc.ppi_update';
2386 $link_data['interviewer'] = $interviewer;
2387 $link_data['individual'] = $id;
2388 $link_data['name'] = $name;
2389 $link_data['interview'] = '';
2390 $link_data['interview_type'] = 'ppi';
2391 $link_data['action'] = 'add';
2392 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2393 $this->nextmatchs->template_alternate_row_color(&$this->t);
2394 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2396 // Find out how many times PPIs were performed in the past $num_months for this individual
2397 for($m=$num_months; $m >= 0; $m--) {
2398 $year = date('Y') - $m;
2399 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2400 $sql = "SELECT * FROM tc_interview WHERE date > '$year_start' AND date < '$year_end' ".
2401 "AND individual=" . $id . " AND interview_type='ppi' ORDER BY date DESC";
2402 $this->db2->query($sql,__LINE__,__FILE__);
2404 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
2405 if($this->db2->next_record()) {
2406 $ppis[$m]++; $total_ppis[$m]++; $ppi_recorded[$companionship][$m]=1;
2407 $link_data['menuaction'] = 'tc.tc.ppi_update';
2408 $link_data['companionship'] = $companionship;
2409 $link_data['interviewer'] = $this->db2->f('interviewer');
2410 $link_data['indiv'] = $id;
2411 $link_data['name'] = $name;
2412 $link_data['interview'] = $this->db2->f('interview');
2413 $link_data['interview_type'] = 'ppi';
2414 $link_data['action'] = 'view';
2415 $date = $this->db2->f('date');
2416 $date_array = explode("-",$date);
2417 $month = $date_array[1];
2418 $day = $date_array[2];
2419 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2420 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2422 $table_data .= "<td> </td>";
2425 $table_data .= "</tr>\n";
2427 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2429 $stat_data = "<tr><td><b><font size=-2>$total_indivs Individuals<br>PPI Totals:</font></b></td>";
2430 for($m=$num_months; $m >=0; $m--) {
2431 $percent = ceil(($ppis[$m] / $total_indivs)*100);
2432 $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
2434 $stat_data .= "</tr>";
2436 $this->t->set_var('table_width',$table_width);
2437 $this->t->set_var('header_row',$header_row);
2438 $this->t->set_var('table_data',$table_data);
2439 $this->t->set_var('stat_data',$stat_data);
2440 $this->t->pfp('out','ppi_view_t');
2441 $this->save_sessiondata();
2444 function ppi_update()
2446 $this->t->set_file(array('form' => 'ppi_update.tpl'));
2447 $this->t->set_block('form','interviewer_list','int_list');
2448 $this->t->set_block('form','add','addhandle');
2449 $this->t->set_block('form','edit','edithandle');
2451 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2452 $this->t->set_var('readonly','');
2453 $this->t->set_var('disabled','');
2455 $action = get_var('action',array('GET','POST'));
2456 $companionship = get_var('companionship',array('GET','POST'));
2457 $interviewer = get_var('interviewer',array('GET','POST'));
2458 $name = get_var('name',array('GET','POST'));
2459 $interview = get_var('interview',array('GET','POST'));
2460 $individual = get_var('individual',array('GET','POST'));
2461 $date = get_var('date',array('GET','POST'));
2462 $notes = get_var('notes',array('GET','POST'));
2463 $interview_type = get_var('interview_type',array('GET','POST'));
2465 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1 AND ";
2466 if($this->yearly_ppi_interviewer == 1) { $sql .= " (tp.president=1)"; }
2467 if($this->yearly_ppi_interviewer == 2) { $sql .= " (tp.president=1 OR tp.counselor=1)"; }
2468 if($this->yearly_ppi_interviewer == 3) { $sql .= " (tp.president=1 OR tp.counselor=1 OR tp.secretary=1)"; }
2469 $this->db2->query($sql,__LINE__,__FILE__);
2470 while ($this->db2->next_record()) {
2471 $indiv = $this->db2->f('individual');
2472 $interviewer_name = $this->db2->f('name');
2473 if($indiv == $interviewer) {
2474 $this->t->set_var('interviewer',$indiv . ' selected');
2476 $this->t->set_var('interviewer',$indiv);
2478 #print "indiv: $indiv interviewer: $interviewer<br>";
2479 $this->t->set_var('interviewer_name',$interviewer_name);
2480 $this->t->set_var('eqpresppi_checked','checked');
2481 $this->t->fp('int_list','interviewer_list',True);
2483 #print "selected interviewer: $interviewer<br>";
2484 if($action == 'save') {
2485 $notes = get_var('notes',array('POST'));
2486 $this->db->query("UPDATE tc_interview set " .
2487 " interview='" . $interview . "'" .
2488 ", interviewer='" . $interviewer . "'" .
2489 ", individual='" . $individual . "'" .
2490 ", date='" . $date . "'" .
2491 ", notes=\"" . $notes . "\"" .
2492 ", interview_type='" . $interview_type . "'" .
2493 " WHERE interview=" . $interview,__LINE__,__FILE__);
2498 if($action == 'insert') {
2499 $notes = get_var('notes',array('POST'));
2500 $this->db->query("INSERT INTO tc_interview (interviewer,individual,date,notes,interview_type) " .
2501 "VALUES ('" . $interviewer . "','" . $individual . "','" .
2502 $date . "',\"" . $notes . "\",'" . $interview_type ."')",__LINE__,__FILE__);
2507 if($action == 'add') {
2508 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2509 $this->t->set_var('interview', '');
2510 $this->t->set_var('interviewer', $interviewer);
2511 $this->t->set_var('name',$name);
2512 $this->t->set_var('individual',$individual);
2513 $this->t->set_var('date','');
2514 $this->t->set_var('notes','');
2515 $this->t->set_var('interview_type',$interview_type);
2516 $this->t->set_var('eqpresppi_checked','checked');
2517 $this->t->set_var('lang_done','Cancel');
2518 $this->t->set_var('lang_action','Adding New PPI');
2519 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview=' .
2520 $interview . '&action=' . 'insert'));
2523 if($action == 'edit' || $action == 'view') {
2524 $sql = "SELECT * FROM tc_interview WHERE interview=" . $interview . " AND interview_type='ppi'";
2525 $this->db->query($sql,__LINE__,__FILE__);
2526 $this->db->next_record();
2527 $this->t->set_var('interview',$interview);
2528 $this->t->set_var('name',$name);
2529 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2530 $this->t->set_var('individual',$this->db->f('individual'));
2531 $this->t->set_var('date',$this->db->f('date'));
2532 $this->t->set_var('notes',$this->db->f('notes'));
2533 $this->t->set_var('interview_type',$this->db->f('interview_type'));
2534 if($this->db->f('interview_type') == 'ppi') { $this->t->set_var('eqpresppi_checked','checked'); }
2537 if($action == 'edit') {
2538 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2539 $this->t->set_var('lang_done','Cancel');
2540 $this->t->set_var('lang_action','Editing PPI');
2541 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview='.
2542 $interview . '&action=' . 'save'));
2545 if($action == 'view') {
2546 $date = $this->db->f('date');
2547 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2548 $this->t->set_var('readonly','READONLY');
2549 $this->t->set_var('disabled','DISABLED');
2550 $this->t->set_var('lang_done','Done');
2551 $this->t->set_var('lang_action','Viewing PPI');
2552 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview=' .
2553 $interview . '&action=' . 'edit'));
2556 $this->t->set_var('lang_reset','Clear Form');
2557 $this->t->set_var('lang_add','Add PPI');
2558 $this->t->set_var('lang_save','Save Changes');
2559 $this->t->set_var('edithandle','');
2560 $this->t->set_var('addhandle','');
2562 $this->t->pfp('out','form');
2564 if($action == 'view') { $this->t->set_var('lang_save','Edit PPI'); }
2565 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2566 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2568 $this->save_sessiondata();
2573 $this->t->set_file(array('int_view_t' => 'int_view.tpl'));
2574 $this->t->set_block('int_view_t','district_list','list');
2576 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2577 $num_quarters = get_var('num_quarters',array('GET','POST'));
2578 if($num_quarters == '') { $num_quarters = $this->default_int_num_quarters; }
2579 $this->t->set_var('num_quarters',$num_quarters);
2580 if($num_quarters == 1) {
2581 $this->t->set_var('lang_num_quarters','Quarter of History');
2583 $this->t->set_var('lang_num_quarters','Quarters of History');
2585 $this->t->set_var('lang_filter','Filter');
2587 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2588 $this->t->set_var('int_link_title','Hometeaching Interviews');
2590 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
2591 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
2593 $this->t->set_var('title','Hometeaching Interviews');
2595 $num_months = $num_quarters * 3 - 1;
2596 $current_month = $this->current_month;
2597 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
2598 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
2599 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
2600 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
2602 $sql = "SELECT * FROM tc_district AS td JOIN tc_individual AS ti WHERE td.supervisor=ti.individual AND td.valid=1 ORDER BY td.district ASC";
2603 $this->db->query($sql,__LINE__,__FILE__);
2605 while ($this->db->next_record()) {
2606 $districts[$i]['district'] = $this->db->f('district');
2607 $districts[$i]['name'] = $this->db->f('name');
2608 $districts[$i]['supervisor'] = $this->db->f('supervisor');
2612 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
2613 $this->db->query($sql,__LINE__,__FILE__);
2615 while ($this->db->next_record()) {
2616 $individual[$i] = $this->db->f('individual');
2617 $indiv_name[$i] = $this->db->f('name');
2618 $indiv_phone[$individual[$i]] = $this->db->f('phone');
2621 array_multisort($indiv_name, $individual);
2622 for($i=0; $i < count($individual); $i++) {
2623 $id = $individual[$i];
2624 $indivs[$id] = $indiv_name[$i];
2627 $total_companionships = 0;
2628 $this->nextmatchs->template_alternate_row_color(&$this->t);
2629 for ($i=0; $i < count($districts); $i++) {
2630 $this->t->set_var('district_number',$districts[$i]['district']);
2631 $this->t->set_var('district_name',$districts[$i]['name']);
2632 $supervisor = $districts[$i]['supervisor'];
2634 // Select all the unique companionship numbers for this district
2635 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$i]['district'];
2636 $this->db->query($sql,__LINE__,__FILE__);
2637 $j=0; $unique_companionships = '';
2638 while ($this->db->next_record()) {
2639 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
2643 $comp_width=250; $int_width=75; $table_width=$comp_width + $num_months*$int_width;
2644 $table_data=""; $num_companionships = $j; $num_indivs = 0;
2645 for($m=$num_months; $m >= 0; $m--) { $ints[$m] = 0; }
2646 for ($j=0; $j < count($unique_companionships); $j++) {
2647 // Select all the companions in each companionship
2648 $sql = "SELECT * FROM tc_companion where valid=1 and ".
2649 "companionship=". $unique_companionships[$j]['companionship'];
2650 $this->db->query($sql,__LINE__,__FILE__);
2652 $comp = $unique_companionships[$j]['companionship'];
2653 for($m=$num_months; $m >= 0; $m--) { $int_recorded[$comp][$m] = 0; }
2654 while ($this->db->next_record()) {
2655 // Get this companions information
2657 $companionship = $this->db->f('companionship');
2658 $individual = $this->db->f('individual');
2659 $name = $indivs[$individual];
2660 $phone = $indiv_phone[$individual];
2661 $link_data['menuaction'] = 'tc.tc.int_update';
2662 $link_data['companionship'] = $companionship;
2663 $link_data['interviewer'] = $supervisor;
2664 $link_data['individual'] = $individual;
2665 $link_data['name'] = $name;
2666 $link_data['interview'] = '';
2667 $link_data['interview_type'] = 'hti';
2668 $link_data['action'] = 'add';
2669 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2670 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2672 // Find out how many times Interviews were performed in the past $num_months for this individual
2673 $header_row="<th width=$comp_width><font size=-2>Companionship</th>";
2674 for($m=$num_months; $m >= 0; $m--) {
2675 $month = $current_month - $m;
2676 $year = $this->current_year;
2678 $remainder = $month;
2679 $month = 12 + $remainder;
2682 if($month < 10) { $month = "0"."$month"; }
2683 $month_start = "$year"."-"."$month"."-"."01";
2684 $month_end = "$year"."-"."$month"."-"."31";
2685 $month = "$month"."/"."$year";
2686 $sql = "SELECT * FROM tc_interview WHERE date >= '$month_start' AND date <= '$month_end' ".
2687 "AND individual=" . $individual . " AND interview_type='hti' ORDER BY date DESC";
2688 $this->db2->query($sql,__LINE__,__FILE__);
2689 $header_row .= "<th width=$int_width><font size=-2>$month</th>";
2691 if(!$total_ints[$m]) { $total_ints[$m] = 0; }
2692 if($this->db2->next_record()) {
2693 if(!$int_recorded[$companionship][$m]) {
2696 $int_recorded[$companionship][$m]=1;
2698 $link_data['menuaction'] = 'tc.tc.int_update';
2699 $link_data['companionship'] = $companionship;
2700 $link_data['interviewer'] = $this->db2->f('interviewer');
2701 $link_data['individual'] = $individual;
2702 $link_data['name'] = $name;
2703 $link_data['interview'] = $this->db2->f('interview');
2704 $link_data['action'] = 'view';
2705 $link_data['interview_type'] = 'hti';
2706 $date = $this->db2->f('date');
2707 $date_array = explode("-",$date);
2708 $month = $date_array[1];
2709 $day = $date_array[2];
2710 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2711 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2714 $table_data .= "<td> </td>";
2717 $table_data .= "</tr>";
2720 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2722 $total_companionships += $num_companionships;
2723 $stat_data = "<tr><td><b><font size=-2>$num_companionships Companionships<br>Interview Totals:</font></b></td>";
2725 // Print the hometeaching interview stats
2726 for($m=$num_months; $m >=0; $m--) {
2727 $month = $current_month - $m;
2728 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
2729 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
2730 //print "$month % $this->monthly_hometeaching_interview_stats = $month_begins <br>";
2731 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
2732 if(($month_begins) == 1) {
2735 $total += $ints[$m];
2737 $percent = ceil(($total / $num_companionships)*100);
2738 $stat_data .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
2740 $stat_data .= "</tr>";
2742 $this->t->set_var('table_width',$table_width);
2743 $this->t->set_var('header_row',$header_row);
2744 $this->t->set_var('table_data',$table_data);
2745 $this->t->set_var('stat_data',$stat_data);
2746 $this->t->fp('list','district_list',True);
2749 // Display the totals
2751 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>Interview Totals:</font></b></td>";
2752 for($m=$num_months; $m >=0; $m--) {
2753 $month = $current_month - $m;
2754 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
2755 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
2756 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
2757 if(($month_begins) == 1) {
2758 $total = $total_ints[$m];
2760 $total += $total_ints[$m];
2762 $percent = ceil(($total / $total_companionships)*100);
2763 $totals .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
2767 $this->t->set_var('totals',$totals);
2768 $this->t->pfp('out','int_view_t');
2769 $this->save_sessiondata();
2772 function int_update()
2774 $this->t->set_file(array('form' => 'int_update.tpl'));
2775 $this->t->set_block('form','interviewer_list','int_list');
2776 $this->t->set_block('form','add','addhandle');
2777 $this->t->set_block('form','edit','edithandle');
2779 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2780 $this->t->set_var('readonly','');
2781 $this->t->set_var('disabled','');
2782 $this->t->set_var('eqpresppi','');
2784 $action = get_var('action',array('GET','POST'));
2785 $companionship = get_var('companionship',array('GET','POST'));
2786 $interviewer = get_var('interviewer',array('GET','POST'));
2787 $name = get_var('name',array('GET','POST'));
2788 $interview = get_var('interview',array('GET','POST'));
2789 $individual = get_var('individual',array('GET','POST'));
2790 $date = get_var('date',array('GET','POST'));
2791 $notes = get_var('notes',array('GET','POST'));
2792 $interview_type = get_var('interview_type',array('GET','POST'));
2794 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1 AND (tp.president=1 OR tp.counselor=1 OR tp.secretary=1 OR tp.district!=0)";
2795 $this->db2->query($sql,__LINE__,__FILE__);
2796 while ($this->db2->next_record()) {
2797 $indiv = $this->db2->f('individual');
2798 $interviewer_name = $this->db2->f('name');
2799 if($indiv == $interviewer) {
2800 $this->t->set_var('interviewer',$indiv . ' selected');
2802 $this->t->set_var('interviewer',$indiv);
2804 $this->t->set_var('interviewer_name',$interviewer_name);
2805 $this->t->fp('int_list','interviewer_list',True);
2808 if($action == 'save') {
2809 $notes = get_var('notes',array('POST'));
2810 $this->db->query("UPDATE tc_interview set " .
2811 " interview='" . $interview . "'" .
2812 ", interviewer='" . $interviewer . "'" .
2813 ", individual='" . $individual . "'" .
2814 ", date='" . $date . "'" .
2815 ", notes=\"" . $notes . "\"" .
2816 ", interview_type='" . $interview_type . "'" .
2817 " WHERE interview=" . $interview,__LINE__,__FILE__);
2822 if($action == 'insert') {
2823 $notes = get_var('notes',array('POST'));
2824 $this->db->query("INSERT INTO tc_interview (interviewer,individual,date,notes,interview_type) " .
2825 "VALUES ('" . $interviewer . "','" . $individual . "','" .
2826 $date . "',\"" . $notes ."\",'" . $interview_type . "')",__LINE__,__FILE__);
2831 if($action == 'add') {
2832 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2833 $this->t->set_var('interview', '');
2834 $this->t->set_var('interviewer', $interviewer);
2835 $this->t->set_var('name',$name);
2836 $this->t->set_var('individual',$individual);
2837 $this->t->set_var('date','');
2838 $this->t->set_var('notes','');
2839 $this->t->set_var('interview_type',$interview_type);
2840 $this->t->set_var('lang_done','Cancel');
2841 $this->t->set_var('lang_action','Adding New Interview');
2842 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
2843 $interview . '&action=' . 'insert'));
2846 if($action == 'edit' || $action == 'view') {
2847 $sql = "SELECT * FROM tc_interview WHERE interview=" . $interview . " AND interview_type='hti'";
2848 $this->db->query($sql,__LINE__,__FILE__);
2849 $this->db->next_record();
2850 $this->t->set_var('interview',$interview);
2851 $this->t->set_var('name',$name);
2852 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2853 $this->t->set_var('individual',$this->db->f('individual'));
2854 $this->t->set_var('date',$this->db->f('date'));
2855 $this->t->set_var('notes',$this->db->f('notes'));
2856 $this->t->set_var('interview_type',$this->db->f('interview_type'));
2857 if($this->db->f('interview_type') == 'ppi') { $this->t->set_var('eqpresppi_checked','checked'); }
2860 if($action == 'edit') {
2861 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2862 $this->t->set_var('lang_done','Cancel');
2863 $this->t->set_var('lang_action','Editing Interview');
2864 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
2865 $interview . '&action=' . 'save'));
2868 if($action == 'view') {
2869 $date = $this->db->f('date');
2870 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2871 $this->t->set_var('readonly','READONLY');
2872 $this->t->set_var('disabled','DISABLED');
2873 $this->t->set_var('lang_done','Done');
2874 $this->t->set_var('lang_action','Viewing Interview');
2875 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
2876 $interview . '&action=' . 'edit'));
2879 $this->t->set_var('lang_reset','Clear Form');
2880 $this->t->set_var('lang_add','Add Interview');
2881 $this->t->set_var('lang_save','Save Changes');
2882 $this->t->set_var('edithandle','');
2883 $this->t->set_var('addhandle','');
2885 $this->t->pfp('out','form');
2887 if($action == 'view') { $this->t->set_var('lang_save','Edit Interview'); }
2888 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2889 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2891 $this->save_sessiondata();
2896 $this->t->set_file(array('vis_view_t' => 'vis_view.tpl'));
2897 $this->t->set_block('vis_view_t','visit_list','list1');
2898 $this->t->set_block('vis_view_t','family_list','list2');
2900 $this->t->set_var('lang_name','Family Name');
2901 $this->t->set_var('lang_date','Date');
2903 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2904 $this->t->set_var('vis_link_title','View Yearly Visits');
2906 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
2907 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2909 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2910 $num_years = get_var('num_years',array('GET','POST'));
2911 if($num_years == '') { $num_years = $this->default_vis_num_years; }
2912 $this->t->set_var('num_years',$num_years);
2913 if($num_years == 1) {
2914 $this->t->set_var('lang_num_years','Year of History');
2916 $this->t->set_var('lang_num_years','Years of History');
2918 $this->t->set_var('lang_filter','Filter');
2920 $year = date('Y') - $num_years + 1;
2921 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2923 $sql = "SELECT * FROM tc_visit WHERE companionship=0 and date > '$year_start' ORDER BY date DESC";
2924 $this->db->query($sql,__LINE__,__FILE__);
2925 $total_records = $this->db->num_rows();
2928 while ($this->db->next_record()) {
2929 $visit_list[$i]['visit'] = $this->db->f('visit');
2930 $visit_list[$i]['family'] = $this->db->f('family');
2931 $visit_list[$i]['date'] = $this->db->f('date');
2935 for ($i=0; $i < count($visit_list); $i++) {
2936 $this->nextmatchs->template_alternate_row_color(&$this->t);
2938 $sql = "SELECT * FROM tc_family AS tf JOIN tc_individual AS ti WHERE tf.individual=ti.individual AND tf.family=".$visit_list[$i]['family']." AND ti.steward='$this->default_stewardship'";
2939 $this->db->query($sql,__LINE__,__FILE__);
2940 $this->db->next_record();
2942 $this->t->set_var('family',$visit_list[$i]['family']);
2943 $this->t->set_var('family_name',$this->db->f('name'));
2944 $this->t->set_var('date',$visit_list[$i]['date']);
2946 $link_data['menuaction'] = 'tc.tc.vis_update';
2947 $link_data['visit'] = $visit_list[$i]['visit'];
2948 $link_data['name'] = $this->db->f('name');
2949 $link_data['date'] = $visit_list[$i]['date'];
2950 $link_data['action'] = 'view';
2951 $this->t->set_var('view',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
2952 $this->t->set_var('lang_view','View');
2954 $link_data['menuaction'] = 'tc.tc.vis_update';
2955 $link_data['visit'] = $visit_list[$i]['visit'];
2956 $link_data['name'] = $this->db->f('name');
2957 $link_data['date'] = $visit_list[$i]['date'];
2958 $link_data['action'] = 'edit';
2959 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
2960 $this->t->set_var('lang_edit','Edit');
2962 $this->t->fp('list1','visit_list',True);
2965 // List the families that are available to record a visit against
2966 $sql = "SELECT * FROM tc_family AS tf JOIN tc_individual AS ti WHERE tf.individual=ti.individual AND tf.companionship != 0 AND tf.valid=1 AND ti.steward='$this->default_stewardship'";
2967 $this->db->query($sql,__LINE__,__FILE__);
2968 $total_records = $this->db->num_rows();
2971 while ($this->db->next_record()) {
2972 $family_names[$i] = $this->db->f('name');
2973 $family_ids[$i] = $this->db->f('family');
2975 } array_multisort($family_names, $family_ids);
2977 for ($i=0; $i < count($family_names); $i++) {
2978 $link_data['menuaction'] = 'tc.tc.vis_update';
2979 $link_data['visit'] = '';
2980 $link_data['family'] = $family_ids[$i];
2981 $link_data['action'] = 'add';
2982 $link_data['name'] = $family_names[$i];
2983 $this->t->set_var('add',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
2985 $this->t->set_var('name',$family_names[$i]);
2986 if(($i+1) % 3 == 0) {
2987 $this->t->set_var('table_sep',"</td></tr><tr>");
2989 $this->t->set_var('table_sep',"</td>");
2991 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
2993 $this->t->fp('list2','family_list',True);
2996 $this->t->pfp('out','vis_view_t');
2997 $this->save_sessiondata();
3000 function vis_update()
3002 $this->t->set_file(array('form' => 'vis_update.tpl'));
3003 $this->t->set_block('form','add','addhandle');
3004 $this->t->set_block('form','edit','edithandle');
3006 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
3007 $this->t->set_var('readonly','');
3008 $this->t->set_var('disabled','');
3010 $action = get_var('action',array('GET','POST'));
3011 $visit = get_var('visit',array('GET','POST'));
3012 $family = get_var('family',array('GET','POST'));
3013 $name = get_var('name',array('GET','POST'));
3014 $date = get_var('date',array('GET','POST'));
3015 $notes = get_var('notes',array('GET','POST'));
3018 if($action == 'save') {
3019 $notes = get_var('notes',array('POST'));
3020 $this->db->query("UPDATE tc_visit set " .
3021 " date='" . $date . "'" .
3022 ", notes=\"" . $notes . "\"" .
3023 " WHERE visit=" . $visit,__LINE__,__FILE__);
3028 if($action == 'insert') {
3029 $notes = get_var('notes',array('POST'));
3030 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes) " .
3031 "VALUES ('" . $family . "','" . $companionship . "','" .
3032 $date . "',\"" . $notes . "\")",__LINE__,__FILE__);
3037 if($action == 'add') {
3038 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
3039 $this->t->set_var('family', $family);
3040 $this->t->set_var('visit', '');
3041 $this->t->set_var('name', $name);
3042 $this->t->set_var('date','');
3043 $this->t->set_var('notes','');
3044 $this->t->set_var('lang_done','Cancel');
3045 $this->t->set_var('lang_action','Adding New Visit');
3046 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&family=' .
3047 $family . '&action=' . 'insert'));
3050 if($action == 'edit' || $action == 'view') {
3051 $sql = "SELECT * FROM tc_visit WHERE visit=".$visit;
3052 $this->db->query($sql,__LINE__,__FILE__);
3053 $this->db->next_record();
3054 $this->t->set_var('visit',$visit);
3055 $this->t->set_var('name',$name);
3056 $this->t->set_var('family', $family);
3057 $this->t->set_var('date',$this->db->f('date'));
3058 $this->t->set_var('notes',$this->db->f('notes'));
3061 if($action == 'edit') {
3062 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
3063 $this->t->set_var('lang_done','Cancel');
3064 $this->t->set_var('lang_action','Editing Visit');
3065 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit=' .
3066 $visit . '&action=' . 'save'));
3069 if($action == 'view') {
3070 $date = $this->db->f('date');
3071 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
3072 $this->t->set_var('readonly','READONLY');
3073 $this->t->set_var('disabled','DISABLED');
3074 $this->t->set_var('lang_done','Done');
3075 $this->t->set_var('lang_action','Viewing Visit');
3076 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit=' .
3077 $visit . '&action=' . 'edit'));
3080 $this->t->set_var('lang_reset','Clear Form');
3081 $this->t->set_var('lang_add','Add Visit');
3082 $this->t->set_var('lang_save','Save Changes');
3083 $this->t->set_var('edithandle','');
3084 $this->t->set_var('addhandle','');
3086 $this->t->pfp('out','form');
3088 if($action == 'view') { $this->t->set_var('lang_save','Edit Visit'); }
3089 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
3090 if($action == 'add') { $this->t->pfp('addhandle','add'); }
3092 $this->save_sessiondata();
3097 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3098 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3099 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3101 $this->t->set_file(array('att_view_t' => 'att_view.tpl'));
3102 $this->t->set_block('att_view_t','act_list','list');
3104 $this->t->set_block('att_view_t','month_list','list1');
3105 $this->t->set_block('att_view_t','header_list','list2');
3106 $this->t->set_block('att_view_t','individual_list','list3');
3108 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3109 $num_quarters = get_var('num_quarters',array('GET','POST'));
3110 if($num_quarters == '') { $num_quarters = $this->default_att_num_quarters; }
3111 $this->t->set_var('num_quarters',$num_quarters);
3112 $this->t->set_var('lang_filter','Filter');
3113 if($num_quarters == 1) {
3114 $this->t->set_var('lang_num_quarters','Quarter of History');
3116 $this->t->set_var('lang_num_quarters','Quarters of History');
3119 $num_months = $num_quarters * 3;
3120 $current_month = $this->current_month;
3121 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
3122 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
3123 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
3124 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
3126 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
3127 $this->db->query($sql,__LINE__,__FILE__);
3129 while ($this->db->next_record()) {
3130 $individual_name[$i] = $this->db->f('name');
3131 $individual[$i] = $this->db->f('individual');
3134 array_multisort($individual_name, $individual);
3136 // Create a list of sunday dates for a window of 3 months back and current month
3140 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, ($current_month-$num_months)+1, 1, date("y")));
3141 $last_date = explode("-",$sunday_list[0]['date']);
3142 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3143 $time_limit = mktime(0, 0, 0, $current_month, 31, date("y"));
3144 while($last_time < $time_limit) {
3145 $day = date("w",$last_time);
3146 if(date("w",$last_time) == 0) {
3147 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3148 $last_date = explode("-",$sunday_list[$i]['date']);
3149 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3150 $sunday_list[$i]['day'] = $last_date[2];
3151 $sunday_list[$i]['month'] = date("M",$last_time);
3152 $sunday_list[$i]['year'] = $last_date[0];
3154 $last_date = $sunday_list[$i]['date'];
3156 $last_time += 90000;
3157 if($found_sunday) { $i++; $found_sunday=0; }
3160 $total_individuals = count($individual);
3161 $old_month=$sunday_list[0]['month']; $span=0;
3162 for ($i=0; $i < count($sunday_list); $i++) {
3163 $date = $sunday_list[$i]['date'];
3164 $this->t->set_var('date',$sunday_list[$i]['date']);
3165 $this->t->set_var('day',$sunday_list[$i]['day']);
3166 if(($old_month != $sunday_list[$i]['month']) || $i == count($sunday_list)-1) {
3167 if($i == count($sunday_list)-1) { $span++; }
3168 $cur_month = $sunday_list[$i]['month'];
3169 $old_month = $sunday_list[$i]['month'];
3170 $link_data['menuaction'] = 'tc.tc.att_update';
3171 $link_data['month'] = $sunday_list[$i-1]['month'];
3172 $link_data['year'] = $sunday_list[$i-1]['year'];
3173 $link_data['action'] = 'update_month';
3174 $cur_month = $sunday_list[$i-1]['month'];
3175 $cur_year = $sunday_list[$i-1]['year'];
3176 $header_row .= "<th><font size=-3>$cur_month $cur_year</font></th>";
3177 $this->t->set_var('update_month',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3178 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3179 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3180 $this->t->set_var('span',$span); $span=0;
3181 $this->t->fp('list1','month_list',True);
3185 $this->t->set_var('total_individuals',$total_individuals);
3186 $this->t->set_var('header_row',$header_row);
3188 $individual_width=200; $att_width=25; $total_width=$individual_width;
3189 for ($i=0; $i < count($sunday_list); $i++) {
3190 $link_data['menuaction'] = 'tc.tc.att_update';
3191 $link_data['month'] = $sunday_list[$i]['month'];
3192 $link_data['year'] = $sunday_list[$i]['year'];
3193 $link_data['day'] = $sunday_list[$i]['day'];
3194 $link_data['date'] = $sunday_list[$i]['date'];
3195 $link_data['action'] = 'update_day';
3196 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3197 $this->t->set_var('date',$sunday_list[$i]['date']);
3198 $this->t->set_var('day',$sunday_list[$i]['day']);
3199 $this->t->set_var('month',$sunday_list[$i]['month']);
3200 $this->t->set_var('year',$sunday_list[$i]['year']);
3201 $this->t->fp('list2','header_list',True);
3202 $total_width += $att_width;
3203 $attendance[$monthnum[$sunday_list[$i]['month']]]=0;
3206 for ($i=0; $i < count($individual); $i++) {
3208 $this->nextmatchs->template_alternate_row_color(&$this->t);
3209 $this->t->set_var('individual_name',$individual_name[$i]);
3210 #print "checking for individual: " . $individual[$i] . "<br>";
3211 for ($j=0; $j < count($sunday_list); $j++) {
3212 #print "checking for date: " . $sunday_list[$j]['date'] . "<br>";
3213 #print "SELECT * FROM tc_attendance WHERE date='"
3214 # . $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i] . "<br>";
3215 $sql = "SELECT * FROM tc_attendance WHERE date='" .
3216 $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i];
3217 $this->db->query($sql,__LINE__,__FILE__);
3218 if($this->db->next_record()) {
3219 $cur_month = $sunday_list[$j]['month'];
3220 if($attended[$i][$cur_month] != 1) {
3221 $attended[$i][$cur_month]=1;
3222 $attendance[$monthnum[$cur_month]]++;
3224 $att_table .= '<td align=center><img src="images/checkmark.gif"></td>';
3226 $att_table .= '<td> </td>';
3229 $this->t->set_var('att_table',$att_table);
3230 $this->t->fp('list3','individual_list',True);
3232 $this->t->set_var('total_width',$total_width);
3233 $this->t->set_var('individual_width',$individual_width);
3234 $this->t->set_var('att_width',$att_width);
3236 # Now calculate attendance for these months
3237 $attendance_str = "";
3238 $nonattendance_str = "";
3239 $aveattendance_str = "";
3240 $avenonattendance_str = "";
3242 $ave_total_attended=0;
3244 foreach($attendance as $att => $value) {
3245 $total_attended = $attendance[$att];
3246 $ave_total_attended += $attendance[$att]; $num_months++;
3247 $percent = ceil(($total_attended / $total_individuals)*100);
3248 $attendance_str.="<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3249 $total_nonattended = $total_individuals - $total_attended;
3250 $percent = ceil(($total_nonattended / $total_individuals)*100);
3251 $nonattendance_str.="<td align=center><font size=-2><b>$total_nonattended ($percent%)</b></font></td>";
3253 $total_attended = ceil(($ave_total_attended / $num_months));
3254 $percent = ceil(($total_attended / $total_individuals)*100);
3255 $aveattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3256 $total_attended = $total_individuals - ceil(($ave_total_attended / $num_months));
3257 $percent = ceil(($total_attended / $total_individuals)*100);
3258 $avenonattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3261 $this->t->set_var('attendance',$attendance_str);
3262 $this->t->set_var('aveattendance',$aveattendance_str);
3263 $this->t->set_var('nonattendance',$nonattendance_str);
3264 $this->t->set_var('avenonattendance',$avenonattendance_str);
3266 $this->t->pfp('out','att_view_t');
3267 $this->save_sessiondata();
3270 function att_update()
3272 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3273 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3274 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3276 $this->t->set_file(array('form' => 'att_update.tpl'));
3277 $this->t->set_block('form','edit','edithandle');
3279 $this->t->set_block('form','month_list','list1');
3280 $this->t->set_block('form','header_list','list2');
3281 $this->t->set_block('form','individual_list','list3');
3283 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3285 $action = get_var('action',array('GET','POST'));
3286 $month = get_var('month',array('GET','POST'));
3287 $year = get_var('year',array('GET','POST'));
3288 $day = get_var('day',array('GET','POST'));
3289 $date = get_var('date',array('GET','POST'));
3291 if($action == 'save_month' || $action == 'save_day') {
3292 $new_data = get_var('individuals_attended',array('POST'));
3293 $month = $monthnum[$month]; if($month < 10) { $month = "0" . $month; }
3295 if($action == 'save_month') {
3296 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-%'",__LINE__,__FILE__);
3299 if($action == 'save_day') {
3300 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-".$day."'",__LINE__,__FILE__);
3303 foreach ($new_data as $data) {
3304 $data_array = explode("-",$data);
3305 $indiv = $data_array[0];
3306 $date = "$data_array[1]-$data_array[2]-$data_array[3]";
3307 $this->db->query("INSERT INTO tc_attendance (individual,date) " .
3308 "VALUES (" . $indiv . ",'". $date . "')",__LINE__,__FILE__);
3315 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
3316 $this->db->query($sql,__LINE__,__FILE__);
3318 while ($this->db->next_record()) {
3319 $indiv_name[$i] = $this->db->f('name');
3320 $individual[$i] = $this->db->f('individual');
3321 $indiv_attending[$individual[$i]] = $this->db->f('attending');
3324 array_multisort($indiv_name, $individual);
3326 if($action == 'update_month') {
3327 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_month'));
3331 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], 1, $year));
3332 $last_date = explode("-",$sunday_list[0]['date']);
3333 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3334 $time_limit = mktime(0, 0, 0, $monthnum[$month], 31, $year);
3335 while($last_time <= $time_limit) {
3336 $day = date("w",$last_time);
3337 if(date("w",$last_time) == 0) {
3338 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3339 $last_date = explode("-",$sunday_list[$i]['date']);
3340 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3341 $sunday_list[$i]['day'] = $last_date[2];
3342 $sunday_list[$i]['month'] = date("M",$last_time);
3343 $sunday_list[$i]['year'] = $last_date[0];
3346 $last_time += 90000;
3347 if($found_sunday) { $i++; $found_sunday=0; }
3350 $this->t->set_var('span', $i);
3351 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3352 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3353 $this->t->fp('list1','month_list',True);
3354 $indiv_width=200; $att_width=25; $total_width=$indiv_width;
3355 for ($i=0; $i < count($sunday_list); $i++) {
3356 $link_data['menuaction'] = 'tc.tc.att_update';
3357 $link_data['month'] = $sunday_list[$i]['month'];
3358 $link_data['year'] = $sunday_list[$i]['year'];
3359 $link_data['day'] = $sunday_list[$i]['day'];
3360 $link_data['date'] = $sunday_list[$i]['date'];
3361 $link_data['action'] = 'update_day';
3362 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3363 $this->t->set_var('date',$sunday_list[$i]['date']);
3364 $this->t->set_var('day',$sunday_list[$i]['day']);
3365 $this->t->set_var('month',$sunday_list[$i]['month']);
3366 $this->t->set_var('year',$sunday_list[$i]['year']);
3367 $this->t->fp('list2','header_list',True);
3368 $total_width += $att_width;
3372 if($action == 'update_day') {
3373 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_day'));
3374 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], $day, $year));
3375 $this->t->set_var('month',$month);
3376 $this->t->set_var('year',$year);
3377 $this->t->fp('list1','month_list',True);
3378 $this->t->set_var('date',$date);
3379 $this->t->set_var('day',$day);
3380 $this->t->set_var('month',$month);
3381 $this->t->set_var('year',$year);
3382 $this->t->fp('list2','header_list',True);
3385 for ($i=0; $i < count($individual); $i++) {
3387 $this->nextmatchs->template_alternate_row_color(&$this->t);
3388 $this->t->set_var('individual_name',$indiv_name[$i]);
3389 for ($j=0; $j < count($sunday_list); $j++) {
3390 $sql = "SELECT * FROM tc_attendance WHERE date='" .
3391 $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i];
3392 $this->db->query($sql,__LINE__,__FILE__);
3393 $value = $individual[$i] . "-" . $sunday_list[$j]['date'];
3394 if($this->db->next_record()) {
3395 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'" checked></td>';
3396 } else if($indiv_attending[$individual[$i]] == 1) {
3397 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'" checked></td>';
3399 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'"></td>';
3402 $this->t->set_var('att_table',$att_table);
3403 $this->t->fp('list3','individual_list',True);
3406 $this->t->set_var('lang_done', 'Cancel');
3407 $this->t->set_var('lang_reset','Clear Form');
3408 $this->t->set_var('lang_save','Save Changes');
3410 $this->t->pfp('out','form');
3411 $this->t->pfp('addhandle','edit');
3413 $this->save_sessiondata();
3418 $this->t->set_file(array('dir_view_t' => 'dir_view.tpl'));
3419 $this->t->set_block('dir_view_t','dir_list','list');
3421 $sql = "SELECT * FROM tc_individual where valid=1 and hh_position='Head of Household' ORDER BY name ASC";
3422 $this->db->query($sql,__LINE__,__FILE__);
3424 while ($this->db->next_record()) {
3425 $parent[$i]['id'] = $this->db->f('individual');
3426 $parent[$i]['name'] = $this->db->f('name');
3427 $parent[$i]['phone'] = $this->db->f('phone');
3428 $parent[$i]['address'] = $this->db->f('address');
3432 for ($i=0; $i < count($parent); $i++) {
3433 $name = $parent[$i]['name'];
3434 $phone = $parent[$i]['phone'];
3435 $address = $parent[$i]['address'];
3436 $this->t->set_var('name', $name);
3437 $this->t->set_var('address', $address);
3438 $this->t->set_var('phone', $phone);
3439 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3440 $this->t->set_var('tr_color',$tr_color);
3441 $this->t->fp('list','dir_list',True);
3442 //print "$phone $name $address<br>";
3444 $this->t->pfp('out','dir_view_t');
3445 $this->save_sessiondata();
3450 $this->t->set_file(array('org_view_t' => 'org_view.tpl'));
3451 $this->t->set_block('org_view_t','calling_list','list1');
3452 $this->t->set_block('org_view_t','org_list','list2');
3454 # Display a list ordered alphabetically
3455 $sql = "SELECT * FROM tc_calling AS tc JOIN tc_individual AS ti WHERE tc.individual=ti.individual ORDER BY name ASC";
3456 $this->db->query($sql,__LINE__,__FILE__);
3458 while ($this->db->next_record()) {
3459 $calling[$i]['name'] = $this->db->f('name');
3460 $calling[$i]['position'] = $this->db->f('position');
3461 $calling[$i]['sustained'] = $this->db->f('sustained');
3462 $calling[$i]['organization'] = $this->db->f('organization');
3465 for ($i=0; $i < count($calling); $i++) {
3466 $name = $calling[$i]['name'];
3467 $position = $calling[$i]['position'];
3468 $sustained = $calling[$i]['sustained'];
3469 $organization = $calling[$i]['organization'];
3470 $this->t->set_var('name', $name);
3471 $this->t->set_var('position', $position);
3472 $this->t->set_var('sustained', $sustained);
3473 $this->t->set_var('organization', $organization);
3474 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3475 $this->t->set_var('tr_color',$tr_color);
3476 $this->t->fp('list1','calling_list',True);
3479 # Display a list ordered by organization
3480 $sql = "SELECT * FROM tc_calling AS tc JOIN tc_individual AS ti where tc.individual=ti.individual ORDER BY organization ASC";
3481 $this->db->query($sql,__LINE__,__FILE__);
3483 while ($this->db->next_record()) {
3484 $calling[$i]['name'] = $this->db->f('name');
3485 $calling[$i]['position'] = $this->db->f('position');
3486 $calling[$i]['sustained'] = $this->db->f('sustained');
3487 $calling[$i]['organization'] = $this->db->f('organization');
3490 for ($i=0; $i < count($calling); $i++) {
3491 $name = $calling[$i]['name'];
3492 $position = $calling[$i]['position'];
3493 $sustained = $calling[$i]['sustained'];
3494 $organization = $calling[$i]['organization'];
3495 $this->t->set_var('name', $name);
3496 $this->t->set_var('position', $position);
3497 $this->t->set_var('sustained', $sustained);
3498 $this->t->set_var('organization', $organization);
3499 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3500 $this->t->set_var('tr_color',$tr_color);
3501 $this->t->fp('list2','org_list',True);
3504 $this->t->pfp('out','org_view_t');
3505 $this->save_sessiondata();
3510 $this->t->set_file(array('sched_t' => 'schedule.tpl'));
3511 $this->t->set_block('sched_t','presidency_list','list');
3513 $action = get_var('action',array('GET','POST'));
3515 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule&action=save'));
3516 $this->t->set_var('title','Scheduling Tool');
3518 $this->t->set_var('lang_save','Save Schedule');
3519 $this->t->set_var('lang_reset','Cancel');
3521 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
3522 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
3524 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
3525 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
3527 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
3528 $this->t->set_var('schedule_ppi_link_title','Schedule ' . $this->ppi_frequency_label . ' PPIs');
3530 $date_width=160; $time_width=220; $indiv_width=170; $family_width=180; $location_width=100;
3531 $table_width=$date_width + $time_width + $indiv_width + $family_width + $location_width;
3532 $header_row = "<th width=$date_width><font size=-2>Date</th>";
3533 $header_row.= "<th width=$time_width><font size=-2>Time</th>";
3534 $header_row.= "<th width=$indiv_width><font size=-2>Individual</th>";
3535 $header_row.= "<th width=$family_width><font size=-2>Family</th>";
3536 $header_row.= "<th width=$location_width><font size=-2>Location</th>";
3539 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1 GROUP BY tp.individual ORDER BY ti.name ASC";
3540 $this->db->query($sql,__LINE__,__FILE__);
3542 while ($this->db->next_record()) {
3543 $presidency_data[$i]['id'] = $this->db->f('presidency');
3544 $presidency_data[$i]['name'] = $this->db->f('name');
3545 $presidency_data[$i]['indiv'] = $this->db->f('individual');
3546 $presidency2name[$presidency_data[$i]['id']] = $presidency_data[$i]['name'];
3547 $presidency2indiv[$presidency_data[$i]['id']] = $presidency_data[$i]['indiv'];
3551 $sql = "SELECT * FROM tc_family AS tf JOIN tc_individual AS ti WHERE tf.individual=ti.individual AND ti.steward='$this->default_stewardship' AND tf.valid=1 AND tf.individual != 0 ORDER BY ti.name ASC";
3552 $this->db->query($sql,__LINE__,__FILE__);
3554 while ($this->db->next_record()) {
3555 $family_id[$i] = $this->db->f('family');
3556 $family_name[$i] = $this->db->f('name');
3557 $familyid2name[$family_id[$i]] = $family_name[$i];
3558 $familyid2address[$family_id[$i]] = $this->db->f('address');
3561 array_multisort($family_name, $family_id);
3563 if($action == 'save') {
3564 $new_data = get_var('sched',array('POST'));
3565 foreach ($new_data as $presidency_array) {
3566 foreach ($presidency_array as $entry) {
3567 $presidency = $entry['presidency'];
3568 $appointment = $entry['appointment'];
3569 $location = $entry['location'];
3570 $date = $entry['date'];
3571 $hour = $entry['hour'];
3572 $minute = $entry['minute'];
3574 $indiv = $entry['individual'];
3575 $family = $entry['family'];
3576 $location = $entry['location'];
3577 if($pm) { $hour = $hour + 12; }
3578 $time = $hour.':'.$minute.':'.'00';
3581 // Zero out family or individual if they are invalid
3582 if($indiv == "") { $indiv=0; }
3583 if($family == "") { $family=0; }
3585 // Update our location
3586 if($location == "") {
3588 $family_name_array = explode(",", $familyid2name[$family]);
3589 $family_last_name = $family_name_array[0];
3590 $family_address = $familyid2address[$family];
3591 $location = "$family_last_name"." home ($family_address)";
3592 } else if($indiv > 0) {
3593 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
3594 $supervisor_last_name = $supervisor_name_array[0];
3595 #print "presidency2indiv: $presidency $presidency2indiv[$presidency]<br>";
3596 $sql = "SELECT * FROM tc_individual where individual='$presidency2indiv[$presidency]'";
3597 $this->db2->query($sql,__LINE__,__FILE__);
3598 if($this->db2->next_record()) {
3599 $supervisor_address = $this->db2->f('address');
3601 $location = "$supervisor_last_name"." home ($supervisor_address)";
3605 // Zero out the family or individual if date = NULL
3612 if(($indiv == 0) && ($family == 0)) { $location = ""; }
3614 // Update an existing appointment
3615 if($appointment < $this->max_appointments)
3617 //Only perform a database update if we have made a change to this appointment
3618 $sql = "SELECT * FROM tc_appointment where " .
3619 "appointment='$appointment'" .
3620 " and presidency='$presidency'" .
3621 " and individual='$indiv'" .
3622 " and family='$family'" .
3623 " and date='$date'" .
3624 " and time='$time'" .
3625 " and location='$location'";
3626 $this->db->query($sql,__LINE__,__FILE__);
3627 if(!$this->db->next_record()) {
3628 $old_date = $this->db->f('date');
3629 $old_time = $this->db->f('time');
3630 $this->db2->query("UPDATE tc_appointment set" .
3631 " family=" . $family .
3632 " ,individual=" . $indiv .
3633 " ,date='" . $date . "'" .
3634 " ,time='" . $time . "'" .
3635 " ,location='" . $location . "'" .
3636 " ,presidency='" . $presidency . "'" .
3637 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
3639 // Email the appointment
3640 $this->email_appt($appointment);
3644 // Add a new appointment
3645 else if(($appointment >= $this->max_appointments) && ($date != "") && ($time != ""))
3647 //print "adding entry: appt=$appointment date: $date time: $time individual: $indiv family: $family<br>";
3648 $this->db2->query("INSERT INTO tc_appointment (appointment,presidency,family,individual,date,time,location,uid) " .
3649 "VALUES (NULL,'" . $presidency . "','" . $family . "','" . $indiv . "','" .
3650 $date . "','" . $time . "','" . $location . "','" . $uid ."')",__LINE__,__FILE__);
3652 // Now reselect this entry from the database to see if we need
3653 // to send an appointment out for it.
3654 $sql = "SELECT * FROM tc_appointment where " .
3655 "individual='$indiv'" .
3656 " and family='$family'" .
3657 " and presidency='$presidency'" .
3658 " and date='$date'" .
3659 " and time='$time'" .
3661 " and location='$location'";
3662 $this->db3->query($sql,__LINE__,__FILE__);
3663 if($this->db3->next_record()) {
3664 // Email the appointment if warranted
3665 if(($date != "") && ($time != "") && (($indiv > 0) || $family > 0)) {
3666 $this->email_appt($this->db3->f('appointment'));
3673 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule');
3674 //Header('Location: ' . $take_me_to_url);
3677 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY individual ASC";
3678 $this->db->query($sql,__LINE__,__FILE__);
3680 while ($this->db->next_record()) {
3681 $individual[$i] = $this->db->f('individual');
3682 $indiv_name[$i] = $this->db->f('name');
3683 $indiv_phone[$individual[$i]] = $this->db->f('phone');
3686 array_multisort($indiv_name, $individual);
3688 for ($i=0; $i < count($presidency_data); $i++) {
3689 $presidency = $presidency_data[$i]['id'];
3690 $interviewer = $presidency_data[$i]['individual'];
3691 $name = $presidency_data[$i]['name'];
3692 $this->t->set_var('presidency_name',$name);
3695 // query the database for all the appointments
3696 $sql = "SELECT * FROM tc_appointment where presidency=$presidency and date>=CURDATE() ORDER BY date ASC, time ASC";
3697 $this->db->query($sql,__LINE__,__FILE__);
3699 // Prefill any existing appointment slots
3700 while ($this->db->next_record()) {
3701 $appointment = $this->db->f('appointment');
3702 $indiv = $this->db->f('individual');
3703 $family = $this->db->f('family');
3704 $location = $this->db->f('location');
3706 if($location == "") {
3708 $family_name_array = explode(",", $familyid2name[$family]);
3709 $family_last_name = $family_name_array[0];
3710 $family_address = $familyid2address[$family];
3711 $location = "$family_last_name"." home ($family_address)";
3712 } else if($indiv > 0) {
3713 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
3714 $supervisor_last_name = $supervisor_name_array[0];
3715 $sql = "SELECT * FROM tc_individual where individual='$presidency2indiv[$presidency]'";
3716 $this->db2->query($sql,__LINE__,__FILE__);
3717 if($this->db2->next_record()) {
3718 $supervisor_address = $this->db2->f('address');
3720 $location = "$supervisor_last_name"." home ($supervisor_address)";
3724 $date = $this->db->f('date');
3725 $date_array = explode("-",$date);
3726 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
3727 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
3729 $time = $this->db->f('time');
3730 $time_array = explode(":",$time);
3731 $hour = $time_array[0];
3732 $minute = $time_array[1];
3734 if($hour > 12) { $pm=1; $hour = $hour - 12; }
3735 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
3737 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3740 $table_data.= '<td align=left>';
3741 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]',$date,'','','','','',$this->cal_options);
3742 $table_data.= '</td>';
3744 // Hour & Minutes selection
3745 $table_data.= "<td align=center>";
3746 $table_data .= $this->get_time_selection_form($hour, $minute, $pm, $presidency, $appointment);
3747 $table_data.= "</td>";
3749 // individual drop down list (for PPIs)
3750 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][individual] STYLE="font-size : 8pt">';
3751 $table_data.= '<option value=0></option>';
3752 for ($j=0; $j < count($individual); $j++) {
3753 $id = $individual[$j];
3754 $name = $indiv_name[$j];
3755 if($individual[$j] == $indiv) {
3756 $selected[$id] = 'selected="selected"';
3758 $selected[$id] = '';
3760 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
3762 $table_data.='</select></td>';
3764 // Family drop down list (for Visits)
3765 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family] STYLE="font-size : 8pt">';
3766 $table_data.= '<option value=0></option>';
3767 for ($j=0; $j < count($individual); $j++) {
3768 $id = $family_id[$j];
3769 $name = $family_name[$j];
3770 if($family_id[$j] == $family) {
3771 $selected[$id] = 'selected="selected"';
3773 $selected[$id] = '';
3775 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
3777 $table_data.='</select></td>';
3779 // Location text box
3780 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
3781 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="'.$location.'" STYLE="font-size : 8pt">';
3783 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3784 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3786 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3787 $this->t->set_var('tr_color',$tr_color);
3790 // Create blank appointment slot
3791 for ($b=0; $b < 4; $b++) {
3792 $appointment = $this->max_appointments + $b;
3793 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3796 $table_data.= '<td align=left>';
3797 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]','','','','','','',$this->cal_options);
3798 $table_data.= '</td>';
3801 $table_data.= "<td align=center>";
3802 $table_data .= $this->get_time_selection_form(0, 0, 0, $presidency, $appointment);
3803 $table_data.= "</td>";
3805 // individual drop down list
3806 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][individual] STYLE="font-size : 8pt">';
3807 $table_data.= '<option value=0></option>';
3808 for ($j=0; $j < count($individual); $j++) {
3809 $id = $individual[$j];
3810 $name = $indiv_name[$j];
3811 $table_data.= '<option value='.$id.'>'.$name.'</option>';
3813 $table_data.='</select></td>';
3815 // Family drop down list
3816 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family] STYLE="font-size : 8pt">';
3817 $table_data.= '<option value=0></option>';
3818 for ($j=0; $j < count($individual); $j++) {
3819 $id = $family_id[$j];
3820 $name = $family_name[$j];
3821 $table_data.= '<option value='.$id.'>'.$name.' Family</option>';
3823 $table_data.='</select></td>';
3825 // Location text box
3826 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
3827 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="" STYLE="font-size : 8pt">';
3829 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3830 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3832 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3833 $this->t->set_var('tr_color',$tr_color);
3836 $this->t->set_var('table_data',$table_data);
3837 $this->t->set_var('header_row',$header_row);
3838 $this->t->set_var('table_width',$table_width);
3839 $this->t->fp('list','presidency_list',True);
3842 $this->t->pfp('out','sched_t');
3843 $this->save_sessiondata();
3848 $this->t->set_file(array('email_t' => 'email.tpl'));
3849 $this->t->set_block('email_t','individual_list','list');
3851 $action = get_var('action',array('GET','POST'));
3853 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email'));
3854 $this->t->set_var('title','Email Tool');
3856 $this->t->set_var('lang_email','Send Email');
3857 $this->t->set_var('lang_reset','Cancel');
3859 $this->t->set_var('email_member_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=member'));
3860 $this->t->set_var('email_member_link_title','Email Quorum Member');
3862 $this->t->set_var('email_quorum_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=quorum'));
3863 $this->t->set_var('email_quorum_link_title','Email Quorum');
3865 $this->t->set_var('email_reminder_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=reminder'));
3866 $this->t->set_var('email_reminder_link_title','Email Reminders');
3868 $this->t->set_var('email_edit_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=edit'));
3869 $this->t->set_var('email_edit_link_title','Edit Email Addresses');
3872 $this->t->set_var('table_width',$table_width);
3874 $this->t->pfp('out','email_t');
3875 $this->save_sessiondata();
3880 $this->t->set_file(array('admin_t' => 'admin.tpl'));
3881 $this->t->set_block('admin_t','upload','uploadhandle');
3882 $this->t->set_block('admin_t','admin','adminhandle');
3883 $this->t->set_block('admin_t','cmd','cmdhandle');
3884 $this->t->set_block('admin_t','presidency','presidencyhandle');
3886 $this->t->set_var('upload_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=upload'));
3887 $this->t->set_var('presidency_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=presidency'));
3889 $action = get_var('action',array('GET','POST'));
3891 $this->t->pfp('out','admin_t');
3893 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY individual ASC";
3894 $this->db->query($sql,__LINE__,__FILE__);
3896 while ($this->db->next_record()) {
3897 $individual[$i] = $this->db->f('individual');
3898 $indiv_name[$i] = $this->db->f('name');
3899 $indiv2name[$individual[$i]] = $indiv_name[$i];
3902 array_multisort($indiv_name, $individual);
3904 if($action == 'upload') {
3905 $target_path = $this->upload_target_path . '/' . basename( $_FILES['uploadedfile']['name']);
3907 if(($_FILES['uploadedfile']['type'] == "application/zip") ||
3908 ($_FILES['uploadedfile']['type'] == "application/x-zip-compressed") ||
3909 ($_FILES['uploadedfile']['type'] == "application/x-zip") ||
3910 ($_FILES['uploadedfile']['type'] == "application/octet-stream")) {
3912 if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
3913 $uploadstatus = "<b><font color=red> -E- Unable to move the uploaded file to ";
3914 $uploadstatus.= "the target path (check the path and permissions) of: $target_path</font></b>";
3915 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
3916 $uploadstatus.= "Tmp Filename : " . $_FILES['uploadedfile']['tmp_name'] . "<br>";
3917 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
3918 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
3919 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
3920 $uploadstatus.= "Error : " . $_FILES['uploadedfile']['error'] . "<br>";
3921 $this->t->set_var('uploadstatus',$uploadstatus);
3922 $this->t->pfp('uploadhandle','upload',True);
3926 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
3927 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
3928 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
3929 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
3930 $this->t->set_var('uploadstatus',$uploadstatus);
3931 $this->t->pfp('uploadhandle','upload');
3932 $this->t->set_var('uploadhandle','');
3933 print "<table border=1 width=80%><tr><td>\n<pre>";
3935 # make a directory for this data to be stored in
3936 $date="data_" . date("Y_m_d");
3937 $data_dir = $this->upload_target_path . '/' . $date;
3938 print "-> Making the data directory: $date<br>\n";
3939 exec('mkdir -p ' . $data_dir . ' 2>&1', $result, $return_code);
3940 if($return_code != 0) {
3941 print implode('\n',$result) . "<br>";
3942 print "<b><font color=red>";
3943 print "-E- Unable to create the data directory. Aborting import.";
3944 print "</font></b>";
3948 # move the file uploaded into this directory
3949 print "-> Moving the uploaded file into the data dir<br>\n";
3950 exec('mv ' . $target_path . ' ' . $data_dir . '/' . ' 2>&1', $result, $return_code);
3951 if($return_code != 0) {
3952 print implode('\n',$result) . "<br>";
3953 print "<b><font color=red>";
3954 print "-E- Unable to move the uploaded file into the data dir. Aborting import.";
3955 print "</font></b>";
3959 # unzip the data into this directory
3960 print "-> Unzipping the data<br>\n";
3961 exec($this->unzip_path .' -u '. $data_dir . '/*.zip -d ' . $data_dir . ' 2>&1', $result, $return_code);
3962 if($return_code != 0) {
3963 print implode('\n',$result) . "<br>";
3964 print "<b><font color=red>";
3965 print "-E- Unable to unzip the uploaded file into the data dir: $data_dir. Aborting import.";
3966 print "</font></b>";
3969 exec('mv ' . $data_dir . '/*/* '. $data_dir . ' 2>&1', $result, $return_code);
3971 # update the data_latest link to point to this new directory
3972 print "-> Updating the latest data dir link<br>\n";
3973 $data_latest = $this->upload_target_path . '/data_latest';
3974 exec('rm ' . $data_latest. '; ln -s ' . $data_dir .' '. $data_latest .' 2>&1', $result, $return_code);
3975 if($return_code != 0) {
3976 print implode('\n',$result) . "<br>";
3977 print "<b><font color=red>";
3978 print "-E- Unable to update the data latest link. Aborting import.";
3979 print "</font></b>";
3983 # run the import perl script to encorporate it into the DB
3984 ob_start('ob_logstdout', 2);
3985 print "-> Importing the data into the database<br>\n";
3986 ob_flush(); flush(); sleep(1);
3987 $import_log = $this->upload_target_path . '/import.log';
3988 $data_log = $this->upload_target_path . '/data.log';
3989 $import_cmd = $this->script_path . '/import_ward_data ' . $data_latest . ' 2>&1 | tee ' . $import_log;
3990 $parse_cmd = $this->script_path . '/parse_ward_data -v ' . $data_latest . ' > ' . $data_log . '2>&1';
3991 #print "import_cmd: $import_cmd<br>";
3992 #print "parse_cmd: $parse_cmd<br>";
3993 ob_start('ob_logstdout', 2);
3994 passthru($import_cmd);
3995 passthru($parse_cmd);
3996 ob_flush(); flush(); sleep(1);
3998 # fix the permissions of the data dir
3999 exec('chmod -R o-rwx ' . $data_dir, $result, $return_code);
4001 $this->t->pfp('cmdhandle','cmd');
4002 print "</pre></td></tr></table>";
4003 } else if(($_FILES['uploadedfile']['type'] != "application/zip") &&
4004 ($_FILES['uploadedfile']['type'] != "application/x-zip-compressed") &&
4005 ($_FILES['uploadedfile']['type'] != "application/x-zip") &&
4006 ($_FILES['uploadedfile']['type'] != "application/octet-stream")) {
4007 $uploadstatus = "<b><font color=red>The file format must be a .zip file, please try again! </font></b>";
4008 $uploadstatus.= "<br><br><b>Detected file format: " . $_FILES['uploadedfile']['type'] . "</b>";
4009 $this->t->set_var('uploadstatus',$uploadstatus);
4010 $this->t->pfp('uploadhandle','upload',True);
4012 $uploadstatus = "<b><font color=red> There was an error (" . $_FILES['uploadedfile']['error'];
4013 $uploadstatus.= ") uploading the file, please try again! </font></b>";
4014 $this->t->set_var('uploadstatus',$uploadstatus);
4015 $this->t->pfp('uploadhandle','upload',True);
4017 } else if($action == "presidency") {
4018 $new_data = get_var('eqpres',array('POST'));
4019 foreach ($new_data as $entry) {
4021 $email = $entry['email'];
4022 $indiv = $entry['indiv'];
4023 $name = $entry['name'];
4024 $district = $entry['district'];
4025 $president = $entry['president'];
4026 $counselor = $entry['counselor'];
4027 $secretary = $entry['secretary'];
4028 // look up the individual name for the ID
4029 $name = $indiv2name[$indiv];
4030 //print "id=$id indiv=$indiv name=$name email=$email district=$district president=$president ";
4031 //print "counselor=$counselor secretary=$secretary<br>";
4033 if(($indiv > 0) || ($name != "")) {
4034 if($id < $this->max_presidency_members) {
4035 //print "Updating Existing Entry<br>";
4036 $this->db2->query("UPDATE tc_presidency set" .
4037 " individual=" . $indiv .
4038 " ,district=" . $district .
4039 " ,email='" . $email . "'" .
4040 " ,president='" . $president . "'" .
4041 " ,counselor='" . $counselor . "'" .
4042 " ,secretary='" . $secretary . "'" .
4043 " WHERE presidency=" . $id,__LINE__,__FILE__);
4045 //print "Adding New Entry<br>";
4046 $this->db2->query("INSERT INTO tc_presidency (presidency,individual,district," .
4047 "email,president,counselor,secretary,valid) " .
4048 "VALUES (NULL,'" . $indiv . "','" . $district . "','" .
4049 $email . "','" . $president . "','" .
4050 $counselor . "','" . $secretary . "','1'" .
4051 ")",__LINE__,__FILE__);
4054 //print "Ignoring Blank Entry<br>";
4058 // Now update the tc_district table appropriately
4060 // Delete all the previous district entries from the table
4061 $this->db->query("DELETE from tc_district where valid=1",__LINE__,__FILE__);
4062 $this->db->query("DELETE from tc_district where valid=0",__LINE__,__FILE__);
4064 // Always add a "District 0" assigned to the High Priests Group
4066 $name = "High Priests";
4069 $this->db2->query("INSERT INTO tc_district (district,supervisor,valid) " .
4070 "VALUES ('" . $district . "','" .
4071 $indiv . "','" . $valid . "'" .
4072 ")",__LINE__,__FILE__);
4074 // Requery the tc_presidency table
4075 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1";
4076 $this->db->query($sql,__LINE__,__FILE__);
4077 while ($this->db->next_record()) {
4078 // Extract the data for each presidency record
4079 $id = $this->db->f('presidency');
4080 $indiv = $this->db->f('individual');
4081 $name = $this->db->f('name');
4082 $district = $this->db->f('district');
4085 // If we have a valid district, add it to the district table
4087 $this->db2->query("INSERT INTO tc_district (district,supervisor,valid) " .
4088 "VALUES ('" . $district . "','" .
4089 $indiv . "','" . $valid . "'" .
4090 ")",__LINE__,__FILE__);
4094 $this->t->set_var('adminhandle','');
4095 $this->t->pfp('adminhandle','admin');
4099 $this->t->set_var('adminhandle','');
4100 $this->t->pfp('adminhandle','admin');
4103 // Now save off the data needed for a Presidency Table Update
4105 $sql = "SELECT tp.*, ti.name FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1";
4106 $this->db->query($sql,__LINE__,__FILE__);
4108 $header_row = "<th>Individual</th><th>Email</th><th>District</th><th>President</th><th>Counselor</th><th>Secretary</th>";
4109 while ($this->db->next_record()) {
4110 // Extract the data for each presidency record
4111 $id = $this->db->f('presidency');
4112 $indiv = $this->db->f('individual');
4113 $district = $this->db->f('district');
4114 $name = $this->db->f('name');
4115 $email = $this->db->f('email');
4116 $president = $this->db->f('president');
4117 $counselor = $this->db->f('counselor');
4118 $secretary = $this->db->f('secretary');
4120 // Create the forms needed in the table
4121 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4124 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4127 if($eqpresidency == 0) {
4128 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4129 $table_data.= '<option value=0></option>';
4130 for ($j=0; $j < count($individual); $j++) {
4131 $tmp_id = $individual[$j];
4132 $name = $indiv_name[$j];
4133 if($individual[$j] == $indiv) {
4135 $selected = 'selected="selected"';
4139 $table_data.= '<option value='.$tmp_id.' '.$selected.'>'.$name.'</option>';
4141 $table_data.='</select></td>';
4142 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="'.$indivname.'">';
4144 $table_data.= '<td align=left><input type=text size="20" name="eqpresname" value="Presidency"></td>';
4145 $table_data.= '<input type=hidden name="eqpres['.$id.'][name]" value="Presidency">';
4149 $table_data .= '<td><input type="text" size="50" name="eqpres['.$id.'][email]" value="'.$email.'"></td>';
4152 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4153 $table_data.= '<option value=0></option>';
4154 for ($j=0; $j <= $this->max_num_districts; $j++) {
4155 if($district == $j) {
4156 $selected = 'selected="selected"';
4160 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4162 $table_data.='</select></td>';
4165 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4166 if($president == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4167 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4168 $table_data.='</select></td>';
4171 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4172 if($counselor == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4173 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4174 $table_data.='</select></td>';
4177 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4178 if($secretary == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4179 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4180 $table_data.='</select></td>';
4183 $table_data .= "</tr>\n";
4184 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4185 $this->t->set_var('tr_color',$tr_color);
4188 // Now create 1 blank row to always have a line available to add a new individual with
4189 $id = $this->max_presidency_members;
4190 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4192 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4194 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4195 $table_data.= '<option value=0></option>';
4196 for ($j=0; $j < count($individual); $j++) {
4197 $tmp_id = $individual[$j];
4198 $name = $indiv_name[$j];
4199 $table_data.= '<option value='.$tmp_id.'>'.$name.'</option>';
4201 $table_data.='</select></td>';
4202 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="">';
4204 $table_data.='<td><input type="text" size="50" name="eqpres['.$id.'][email]" value=""></td>';
4206 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4207 $table_data.= '<option value=0></option>';
4208 for ($j=0; $j <= $this->max_num_districts; $j++) {
4210 $selected = 'selected="selected"';
4214 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4216 $table_data.='</select></td>';
4218 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4219 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4220 $table_data.='</select></td>';
4222 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4223 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4224 $table_data.='</select></td>';
4226 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4227 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4228 $table_data.='</select></td>';
4230 $table_data .= "</tr>\n";
4231 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4232 $this->t->set_var('tr_color',$tr_color);
4234 $this->t->set_var('header_row',$header_row);
4235 $this->t->set_var('table_data',$table_data);
4236 $this->t->pfp('presidencyhandle','presidency',True);
4238 $this->save_sessiondata();
4241 function email_appt($appointment)
4243 //print "Emailing notification of appointment: $appointment <br>";
4245 $sql = "SELECT * FROM tc_appointment where appointment='$appointment'";
4246 $this->db->query($sql,__LINE__,__FILE__);
4248 while ($this->db->next_record()) {
4249 $appointment = $this->db->f('appointment');
4250 $presidency = $this->db->f('presidency');
4251 $location = $this->db->f('location');
4254 $indiv = $this->db->f('individual');
4256 $family = $this->db->f('family');
4260 $uid = $this->db->f('uid');
4262 // Extract the year, month, day, hours, minutes, seconds from the appointment time
4263 $appt_date = $this->db->f('date');
4264 $date_array = explode("-",$appt_date);
4265 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
4266 $appt_time = $this->db->f('time');
4267 $time_array = explode(":",$appt_time);
4268 $hour = $time_array[0]; $minute = $time_array[1]; $seconds = $time_array[2];
4270 // Format the appointment time into an iCal UTC equivalent
4271 $dtstamp = gmdate("Ymd"."\T"."His"."\Z");
4272 $dtstart = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds,$month,$day,$year));
4273 $dtstartstr = date("l, F d, o g:i A", mktime($hour,$minute,$seconds,$month,$day,$year));
4275 $sql = "SELECT tp.email AS email1, ti.email AS email2, ti.name AS name FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.presidency='$presidency'";
4276 $this->db2->query($sql,__LINE__,__FILE__);
4277 if($this->db2->next_record()) {
4278 if ($this->db2->f('email1') != "") {
4279 $email = $this->db2->f('email1');
4281 $email = $this->db2->f('email2');
4283 $interviewer = $this->db2->f('name');
4286 // Set the email address of the interviewer
4290 $sql = "SELECT * FROM tc_individual where individual='$indiv'";
4291 $this->db2->query($sql,__LINE__,__FILE__);
4292 if($this->db2->next_record()) {
4293 $indiv_name = $this->db2->f('name');
4294 $phone = $this->db2->f('phone');
4295 $appt_name = $indiv_name . " Interview";
4296 $duration = $this->default_ppi_appt_duration * 60;
4301 $sql = "SELECT * FROM tc_family WHERE family='$family'";
4302 $this->db2->query($sql,__LINE__,__FILE__);
4303 if($this->db2->next_record()) {
4304 $individual = $this->db2->f('individual');
4305 $sql = "SELECT * FROM tc_individual where individual='$individual'";
4306 $this->db3->query($sql,__LINE__,__FILE__);
4307 if($this->db3->next_record()) {
4308 $phone = $this->db3->f('phone');
4309 $family_name = $this->db3->f('name');
4310 $phone = $this->db3->f('phone');
4312 $appt_name = $family_name . " Family Visit";
4313 $duration = $this->default_visit_appt_duration * 60;
4317 $dtend = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4318 $dtendstr = date("g:i A", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4319 $date = $dtstartstr . "-" . $dtendstr;
4320 $description = "$appt_name : $phone";
4322 if(($uid == 0) && ($appt_name != "")) {
4323 // Create a new calendar item for this appointment, since this must be the first time we
4324 // are sending it out.
4325 print "Sent new appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4326 $uid = rand() . rand(); // Generate a random identifier for this appointment
4327 $subject = "Created: $appt_name";
4329 $this->db->query("UPDATE tc_appointment set" .
4331 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4333 $action = "PUBLISH";
4334 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4335 $dtend, $date, $location, $appt_name, $description, $uid);
4336 } else if(($uid != 0) && ($appt_name == "")) {
4337 // Remove the calendar item for this appointment since it has already been sent
4338 // and there is no name we have changed it to.
4339 print "Sent deleted appointment to " . $interviewer . " at " . $email . " for " . $appt_date . " " . $appt_time . "<br>";
4340 $subject = "Canceled: $appt_date $appt_time";
4342 $this->db->query("UPDATE tc_appointment set" .
4344 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4347 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4348 $dtend, $date, $location, $subject, $subject, $uid);
4349 } else if($uid != 0) {
4350 // Update the existing appointment since we have changed it
4351 print "Sent updated appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4353 $subject = "Canceled: $appt_date $appt_time";
4355 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4356 $dtend, $date, $location, $subject, $subject, $uid);
4358 $uid = rand() . rand(); // Generate a random identifier for this appointment
4359 $this->db->query("UPDATE tc_appointment set" .
4361 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4363 $subject = "Updated: $appt_name";
4364 $action = "PUBLISH";
4365 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4366 $dtend, $date, $location, $appt_name, $description, $uid);
4372 function send_ical_appt($action, $to, $from, $subject, $dtstamp, $dtstart, $dtend, $date, $location, $summary, $description, $uid)
4374 // Initialize our local variables
4375 $boundary = "=MIME_APPOINTMENT_BOUNDARY";
4379 // Form the headers for the email message
4380 $headers.="X-Mailer: PHP/" . phpversion() . "\n";
4381 $headers.="Mime-Version: 1.0\n";
4382 $headers.="Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
4383 $headers.="Content-Disposition: inline\n";
4384 $headers.="Reply-To: $from\n";
4385 $headers.="From: $from\n";
4387 // Print the plaintext version of the appointment
4388 $message.="--$boundary\n";
4389 $message.="Content-Type: text/plain; charset=us-ascii\n";
4390 $message.="Content-Disposition: inline\n";
4392 $message.="What: $description\n";
4393 $message.="When: $date\n";
4394 $message.="Where: $location\n";
4397 // Print the .ics attachment version of the appointment
4398 $message.="--$boundary\n";
4399 $message.="Content-Type: text/calendar; charset=us-ascii\n";
4400 $message.="Content-Disposition: attachment; filename=\"appointment.ics\"\n";
4402 $message.="BEGIN:VCALENDAR" . "\n";
4403 $message.="VERSION:2.0" . "\n";
4404 $message.="PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN" . "\n";
4405 $message.="METHOD:$action" . "\n";
4406 $message.="BEGIN:VEVENT" . "\n";
4407 $message.="ORGANIZER:MAILTO:$from". "\n";
4408 $message.="DTSTAMP:$dtstamp" . "\n";
4409 $message.="DTSTART:$dtstart" . "\n";
4410 $message.="DTEND:$dtend" . "\n";
4411 $message.="SUMMARY:$summary" . "\n";
4412 $message.="DESCRIPTION:$description" . "\n";
4413 $message.="LOCATION:$location" . "\n";
4414 $message.="UID:$uid" ."\n";
4415 $message.="TRANSP:OPAQUE" . "\n";
4416 $message.="SEQUENCE:0" . "\n";
4417 $message.="CLASS:PUBLIC" . "\n";
4418 $message.="END:VEVENT" . "\n";
4419 $message.="END:VCALENDAR" . "\n";
4421 // Complete the message
4422 $message.="--$boundary\n";
4425 mail($to, $subject, $message, $headers);
4428 function get_time_selection_form($hour, $minute, $pm, $presidency, $appointment)
4433 if($hour == 0) { $blank = 1; }
4435 if($this->time_drop_down_lists == 1) {
4436 // Create drop down lists to get the time
4437 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][hour]>';
4438 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4439 foreach(range(1,12) as $num) {
4441 $selected = 'selected="selected"';
4445 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4447 $form_data.= '</select>';
4448 $form_data.= ' : ';
4449 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][minute]>';
4450 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4453 if($num < 10) { $num = "0" . "$num"; }
4454 if($minute == $num) {
4455 $selected = 'selected="selected"';
4459 if($blank == 1) { $selected = ""; }
4460 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4461 $num = $num + $this->time_drop_down_list_inc;
4463 $form_data.= '</select>';
4465 // Use free form text fields to get the time
4471 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][hour] value='.$hour.'>';
4473 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][minute] value='.$minute.'>';
4474 $form_data.= ' ';
4476 // Always use a drop-down select form for am/pm
4477 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][pm]>';
4480 $form_data.= '<option value=0 selected>am</option>';
4481 $form_data.= '<option value=1>pm</option>';
4484 $form_data.= '<option value=0>am</option>';
4485 $form_data.= '<option value=1 selected>pm</option>';
4488 $form_data.= '<option value=""></option>';
4489 $form_data.= '<option value=0>am</option>';
4490 $form_data.= '<option value=1>pm</option>';
4492 $form_data.= '</select>';