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,
76 if(file_exists("setup/tc_config.local")) {
77 include("setup/tc_config.local");
79 include("setup/tc_config");
82 $this->script_path = "$this->application_path"."/bin";
83 $this->max_presidency_members = 99;
84 $this->max_appointments = 32768;
86 $this->db = $GLOBALS['phpgw']->db;
87 $this->db2 = $this->db;
88 $this->db3 = $this->db;
89 $this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
90 $this->t = $GLOBALS['phpgw']->template;
91 $this->account = $GLOBALS['phpgw_info']['user']['account_id'];
92 $this->grants = $GLOBALS['phpgw']->acl->get_grants('tc');
93 $this->grants[$this->account] = PHPGW_ACL_READ + PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE;
95 $this->jscal = CreateObject('tc.jscalendar'); // before phpgw_header() !!!
96 $this->cal_options = 'daFormat : "%Y-%m-%d",
97 ifFormat : "%Y-%m-%d",
101 $GLOBALS['phpgw_info']['flags']['app_header'] = 'The 3rd Counselor';
102 $GLOBALS['phpgw']->common->phpgw_header();
104 $this->current_day = `date '+%d'`;
105 $this->current_day = $this->current_day-0; // Make it numeric
106 $this->current_month = `date '+%m'`;
107 $this->current_month = $this->current_month-0; // Make it numeric
108 $this->current_year = `date '+%Y'`;
109 $this->current_year = $this->current_year-0; // Make it numeric
111 if ($this->ppi_frequency == 12) {
112 $this->ppi_frequency_label = "Annual";
113 } else if ($this->ppi_frequency == 6) {
114 $this->ppi_frequency_label = "Semi-Annual";
115 } else if ($this->ppi_frequency == 3) {
116 $this->ppi_frequency_label = "Quarterly";
117 } else if ($this->ppi_frequency == 1) {
118 $this->ppi_frequency_label = "Monthly";
120 $this->ppi_frequency_label = "Periodic";
124 $this->display_app_header();
127 function logToFile($func, $msg)
130 $fd = fopen($this->upload_target_path . "/tc_trace.log", "a");
131 // append date/time to message
132 $str = "[" . date("Y/m/d h:i:s", mktime()) . "] [" . $func . "] " . $msg;
134 fwrite($fd, $str . "\n");
139 function save_sessiondata()
143 function display_app_header()
145 $this->t->set_file(array('tc_header' => 'header.tpl'));
147 if (isset($phpgw_info['user']['preferences']['tc']['tc_font']))
149 $font = $phpgw_info['user']['preferences']['tc']['tc_font'];
156 $this->t->set_var('bg_color',$phpgw_info['theme']['th_bg']);
157 $this->t->set_var('font',$font);
158 $link_data['menuaction'] = 'tc.tc.ht_view';
159 $this->t->set_var('link_hometeaching',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
160 $this->t->set_var('lang_hometeaching','HomeTeaching');
161 $link_data['menuaction'] = 'tc.tc.act_list';
162 $this->t->set_var('link_activity',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
163 $this->t->set_var('lang_activity','Activities');
164 $link_data['menuaction'] = 'tc.tc.willing_view';
165 $this->t->set_var('link_willing',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
166 $this->t->set_var('lang_willing','Willingness');
167 $link_data['menuaction'] = 'tc.tc.assign_view';
168 $this->t->set_var('link_assignment',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
169 $this->t->set_var('lang_assignment','Assignments');
170 $link_data['menuaction'] = 'tc.tc.par_view';
171 $this->t->set_var('link_participation',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
172 $this->t->set_var('lang_participation','Participation');
173 $link_data['menuaction'] = 'tc.tc.ppi_view';
174 $this->t->set_var('link_ppi',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
175 $this->t->set_var('lang_ppi','PPIs');
176 $link_data['menuaction'] = 'tc.tc.int_view';
177 $this->t->set_var('link_int',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
178 $this->t->set_var('lang_int','Interviews');
179 $link_data['menuaction'] = 'tc.tc.vis_view';
180 $this->t->set_var('link_visit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
181 $this->t->set_var('lang_visit','Visits');
182 $link_data['menuaction'] = 'tc.tc.att_view';
183 $this->t->set_var('link_attendance',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
184 $this->t->set_var('lang_attendance','Attendance');
185 $link_data['menuaction'] = 'tc.tc.dir_view';
186 $this->t->set_var('link_dir',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
187 $this->t->set_var('lang_dir','Directory');
188 $link_data['menuaction'] = 'tc.tc.org_view';
189 $this->t->set_var('link_org',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
190 $this->t->set_var('lang_org','Callings');
191 $link_data['menuaction'] = 'tc.tc.admin';
192 $this->t->set_var('link_admin',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
193 $this->t->set_var('lang_admin','Admin');
194 $link_data['menuaction'] = 'tc.tc.schedule';
195 $this->t->set_var('link_schedule',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
196 $this->t->set_var('lang_schedule','Scheduling');
197 $link_data['menuaction'] = 'tc.tc.email';
198 $this->t->set_var('link_email',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
199 $this->t->set_var('lang_email','Email');
201 $this->t->pparse('out','tc_header');
206 $this->t->set_file(array('ht_view_t' => 'ht_view.tpl'));
207 $this->t->set_block('ht_view_t','district_list','list');
209 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
210 $num_months = get_var('num_months',array('GET','POST'));
211 if($num_months == '') { $num_months = $this->default_ht_num_months; }
212 $this->t->set_var('num_months',$num_months);
213 $this->t->set_var('lang_filter','Filter');
214 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
215 else { $this->t->set_var('lang_num_months','Months of History'); }
217 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
218 $this->t->set_var('title','Hometeaching');
220 $this->t->set_var('ht_sandbox_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_sandbox'));
221 $this->t->set_var('ht_sandbox_link_title','Hometeaching Sandbox');
223 $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";
224 $this->db->query($sql,__LINE__,__FILE__);
226 while ($this->db->next_record()) {
227 $districts[$i]['district'] = $this->db->f('district');
228 $districts[$i]['name'] = $this->db->f('name');
229 $districts[$i]['supervisor'] = $this->db->f('supervisor');
233 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
234 $this->db->query($sql,__LINE__,__FILE__);
236 while ($this->db->next_record()) {
237 $individual[$i] = $this->db->f('individual');
238 $indiv_name[$i] = $this->db->f('name');
239 $indiv_phone[$individual[$i]] = $this->db->f('phone');
242 array_multisort($indiv_name, $individual);
244 // Make an array mapping individuals to indiv_names
245 for($i=0; $i < count($individual); $i++) {
246 $id = $individual[$i];
247 $indivs[$id] = $indiv_name[$i];
250 $this->nextmatchs->template_alternate_row_color(&$this->t);
251 for($m=$num_months; $m >= 0; $m--) { $total_families[$m]=0; }
252 for ($i=0; $i < count($districts); $i++) {
253 $this->t->set_var('district_number',$districts[$i]['district']);
254 $this->t->set_var('district_name',$districts[$i]['name']);
255 $supervisor = $districts[$i]['supervisor'];
257 // Select all the unique companionship numbers for this district
258 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$i]['district'];
259 $this->db->query($sql,__LINE__,__FILE__);
260 $j=0; $unique_companionships = '';
261 while ($this->db->next_record()) {
262 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
266 $comp_width=450; $visit_width=25; $table_width=$comp_width + $num_months*$visit_width;
267 $table_data=""; $num_companionships = 0;
268 for($m=$num_months; $m >= 0; $m--) {
272 for ($j=0; $j < count($unique_companionships); $j++) {
273 $companion_table_entry = "";
274 // Select all the companions in each companionship
275 $sql = "SELECT * FROM tc_companion where valid=1 and ".
276 "companionship=". $unique_companionships[$j]['companionship'];
277 $this->db->query($sql,__LINE__,__FILE__);
279 while ($this->db->next_record()) {
280 // Get this companions information
281 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
282 $companionship = $this->db->f('companionship');
283 $individual = $this->db->f('individual');
284 $name = $indivs[$individual];
285 $phone = $indiv_phone[$individual];
286 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
288 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
290 // Get the names of the families assigned this home teaching companionship
291 $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'];
292 $sql = $sql . " ORDER BY name ASC";
293 $this->db->query($sql,__LINE__,__FILE__);
295 while ($this->db->next_record()) {
296 $family_name = $this->db->f('name');
297 $family_id = $this->db->f('family');
298 $this->nextmatchs->template_alternate_row_color(&$this->t);
299 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
300 // Find out how many times Visits were performed by this companionship
301 // in the past $num_months for this Family
302 $header_row="<th width=$comp_width><font size=-2>Families</th>";
303 for($m=$num_months; $m >= 0; $m--) {
304 $month = $this->current_month - $m;
305 $year = $this->current_year;
306 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
307 if($month < 10) { $month = "0"."$month"; }
308 $month_start = "$year"."-"."$month"."-"."01";
309 $month_end = "$year"."-"."$month"."-"."31";
310 $month = "$month"."/"."$year";
312 //print "m: $m month: $month year: $year month_start: $month_start month_end: $month_end<br>";
313 // Add this to the query to filter on only visits made by this companionship:
314 // " AND companionship=" . $unique_companionships[$j]['companionship'].
316 // First check to see if the currently assigned companionship has visited them
317 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
318 " AND companionship=".$unique_companionships[$j]['companionship'].
319 " AND family=". $family_id;
320 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
321 if($this->db2->num_rows($query_id) == 0) {
322 // We did not find any visits made by the currently assigned companionship,
323 // look for visits made by any other companionship other than 0. (0 == Presidency Visit)
324 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
325 " AND companionship!=0".
326 " AND family=". $family_id;
327 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
329 $this->db2->query($sql,__LINE__,__FILE__);
330 $link_data['menuaction'] = 'tc.tc.ht_update';
331 $link_data['date'] = $month_start;
332 $link_data['month_start'] = $month_start;
333 $link_data['month_end'] = $month_end;
334 $link_data['month'] = $month;
335 $link_data['district'] = $districts[$i]['district'];
336 $link_data['district_name'] = $districts[$i]['name'];
337 $link_data['action'] = 'view';
338 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
339 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
340 if(!$total_visits[$m]) { $total_visits[$m] = 0; }
341 if($this->db2->next_record()) {
342 if($this->db2->f('visited') == 'y') {
343 $visits[$m]++; $total_visits[$m]++;
344 $num_families[$m]++; $total_families[$m]++;
345 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/checkmark.gif"></a></td>';
346 } else if($this->db2->f('visited') == 'n') {
347 $num_families[$m]++; $total_families[$m]++;
348 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/x.gif"></a></td>';
350 //$visits[$m]++; $total_visits[$m]++;
351 $table_data .= "<td> </td>";
354 //$visits[$m]++; $total_visits[$m]++;
355 $table_data .= "<td> </td>";
358 $table_data .= "</tr>";
361 $table_data .= "<tr><td colspan=20></td></tr>";
363 $table_data .= "<tr><td colspan=20><hr></td></tr>";
364 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
366 for($m=$num_months; $m >=0; $m--) {
367 if($num_families[$m] > 0) {
368 $percent = ceil(($visits[$m] / $num_families[$m])*100);
372 $stat_data .= "<td align=center><font size=-2><b>$visits[$m] / $num_families[$m]<br>$percent%</font></b></td>";
374 $stat_data .= "</tr>";
376 $this->t->set_var('table_width',$table_width);
377 $this->t->set_var('header_row',$header_row);
378 $this->t->set_var('table_data',$table_data);
379 $this->t->set_var('stat_data',$stat_data);
380 $this->t->fp('list','district_list',True);
383 $totals = "<tr><td><b><font size=-2>Total Families Hometaught:<br>Total Hometeaching Percentage:</font></b></td>";
384 for($m=$num_months; $m >=0; $m--) {
385 if($total_families[$m] > 0) {
386 $percent = ceil(($total_visits[$m] / $total_families[$m])*100);
390 $totals .= "<td align=center><font size=-2><b>$total_visits[$m] / $total_families[$m]<br>$percent%</font></b></td>";
394 $this->t->set_var('totals',$totals);
396 $this->t->pfp('out','ht_view_t');
397 $this->save_sessiondata();
401 function ht_sandbox()
403 $this->t->set_file(array('ht_sandbox_t' => 'ht_sandbox.tpl'));
404 $this->t->set_block('ht_sandbox_t','district_list','list');
406 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_sandbox'));
408 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_sandbox'));
409 $this->t->set_var('title','Hometeaching Sandbox');
413 $this->t->pfp('out','ht_sandbox_t');
414 $this->save_sessiondata();
420 $this->t->set_file(array('ht_update_t' => 'ht_update.tpl'));
421 $this->t->set_block('ht_update_t','district_list','list');
422 $this->t->set_block('ht_update_t','save','savehandle');
424 $district = get_var('district',array('GET','POST'));
425 $district_name = get_var('district_name',array('GET','POST'));
426 $date = get_var('date',array('GET','POST'));
427 $month = get_var('month',array('GET','POST'));
428 $month_start = get_var('month_start',array('GET','POST'));
429 $month_end = get_var('month_end',array('GET','POST'));
430 $action = get_var('action',array('GET','POST'));
432 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
433 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_update&action=save'));
434 $this->t->set_var('lang_done','Cancel');
435 $this->t->set_var('district_name',$district_name);
436 $this->t->set_var('district_number',$district);
437 $this->t->set_var('title','Hometeaching Update ' . $month);
438 $this->t->set_var('date',$date);
440 if($action == 'save') {
441 // Get a list of all the companionships in this district
442 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $district;
443 $this->db->query($sql,__LINE__,__FILE__);
444 $j=0; $unique_companionships = '';
445 while ($this->db->next_record()) {
446 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
449 for ($j=0; $j < count($unique_companionships); $j++) {
450 //$comp=$unique_companionships[$j]['companionship'];
451 //print "deleting from tc_visit where companionship=$comp and date=$date and district=$district<br>";
452 // Delete all the visits that have taken place for all families for this companionsthip for this month
453 $this->db->query("DELETE from tc_visit where companionship=" . $unique_companionships[$j]['companionship'] .
454 " AND " . "date='" . $date . "'",__LINE__,__FILE__);
457 // Now, add the visits that are checked for this month
458 $new_data = get_var('family_visited',array('POST'));
459 foreach ($new_data as $family) {
460 foreach ($family as $data) {
461 //print "family_visited: $data <br>";
462 $data_array = explode("/",$data);
463 $family_id = $data_array[0];
464 $companionship = $data_array[1];
465 $date = $data_array[2];
466 $visited = $data_array[3];
467 if($visited == "") { $visited = $data_array[4]; }
468 //print "family_id: $family_id companionship: $companionship date: $date visited: $visited<br>";
469 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes,visited) " .
470 "VALUES (" . $family_id .",". $companionship .",'". $date ."','','". $visited ."')",__LINE__,__FILE__);
477 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
478 $this->db->query($sql,__LINE__,__FILE__);
480 while ($this->db->next_record()) {
481 $individual[$i] = $this->db->f('individual');
482 $indiv_name[$i] = $this->db->f('name');
483 $indiv_phone[$individual[$i]] = $this->db->f('phone');
486 array_multisort($indiv_name, $individual);
488 // Make an array mapping individuals to indiv_names
489 for($i=0; $i < count($individual); $i++) {
490 $id = $individual[$i];
491 $indivs[$id] = $indiv_name[$i];
494 // Select all the unique companionship numbers for this district
495 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $district;
496 $this->db->query($sql,__LINE__,__FILE__);
497 $j=0; $unique_companionships = '';
498 while ($this->db->next_record()) {
499 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
503 $comp_width=300; $visit_width=25; $table_width=$comp_width + $visit_width;
504 $table_data=""; $num_companionships = 0; $num_families = 0; $visits=0;
505 for ($j=0; $j < count($unique_companionships); $j++) {
506 $companion_table_entry = "";
507 // Select all the companions in each companionship
508 $sql = "SELECT * FROM tc_companionship where valid=1 and ".
509 "companionship=". $unique_companionships[$j]['companionship'];
510 $this->db->query($sql,__LINE__,__FILE__);
512 while ($this->db->next_record()) {
513 // Get this companions information
514 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
515 $companionship = $this->db->f('companionship');
516 $individual = $this->db->f('individual');
517 $name = $indivs[$individual];
518 $phone = $indiv_phone[$individual];
519 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
521 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
523 // Get the names of the families assigned this home teaching companionship
524 $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'];
525 $sql = $sql . " ORDER BY ti.name ASC";
526 $this->db->query($sql,__LINE__,__FILE__);
527 while ($this->db->next_record()) {
528 $family_name = $this->db->f('name');
529 $family_id = $this->db->f('family');
530 $this->nextmatchs->template_alternate_row_color(&$this->t);
531 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
533 $header_row="<th width=$comp_width><font size=-2>Families</th>";
535 // First check to see if the currently assigned companionship has visited them
536 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
537 " AND companionship=".$unique_companionships[$j]['companionship'].
538 " AND family=". $family_id;
539 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
540 if($this->db2->num_rows($query_id) == 0) {
541 // We did not find any visits made by the currently assigned companionship,
542 // look for visits made by any other companionship other than 0. (0 == Presidency Visit)
543 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
544 " AND companionship!=0".
545 " AND family=". $family_id;
546 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
549 $value = $family_id . "/" . $unique_companionships[$j]['companionship'] . "/" . $date;
550 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
551 if(!$total_visits) { $total_visits = 0; }
552 if($this->db2->next_record()) {
553 if($this->db2->f('visited') == 'y') {
554 $visits++; $total_visits++; $num_families++;
555 $table_data .= '<td width=100 align=center>';
556 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y" checked>Y';
557 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
558 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/"> ';
559 $table_data .= '</td>';
560 } else if($this->db2->f('visited') == 'n') {
562 $table_data .= '<td width=100 align=center>';
563 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
564 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n" checked>N';
565 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/">';
566 $table_data .= '</td>';
568 $table_data .= '<td width=100 align=center>';
569 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
570 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
571 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
572 $table_data .= '</td>';
577 $table_data .= '<td width=100 align=center>';
578 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
579 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
580 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
581 $table_data .= '</td>';
584 $table_data .= "</tr>";
585 $table_data .= "<tr><td colspan=20></td></tr>";
587 $table_data .= "<tr><td colspan=20><hr></td></tr>";
588 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
590 $percent = ceil(($visits / $num_families)*100);
591 $stat_data .= "<td align=center><font size=-2><b>$visits / $num_families<br>$percent%</font></b></td>";
592 $stat_data .= "</tr>";
594 $this->t->set_var('table_width',$table_width);
595 $this->t->set_var('header_row',$header_row);
596 $this->t->set_var('table_data',$table_data);
597 $this->t->set_var('stat_data',$stat_data);
598 $this->t->fp('list','district_list',True);
600 $this->t->set_var('lang_reset','Clear Form');
601 $this->t->set_var('lang_save','Save Changes');
602 $this->t->set_var('savehandle','');
604 $this->t->pfp('out','ht_update_t');
605 $this->t->pfp('addhandle','save');
607 $this->save_sessiondata();
612 $this->t->set_file(array('act_list_t' => 'act_list.tpl'));
613 $this->t->set_block('act_list_t','act_list','list');
615 $this->t->set_var('lang_name','Assignment');
616 $this->t->set_var('lang_date','Date');
617 $this->t->set_var('lang_notes','Description');
619 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
620 $this->db->query($sql,__LINE__,__FILE__);
621 $total_records = $this->db->num_rows();
624 while ($this->db->next_record()) {
625 $activity_list[$i]['activity'] = $this->db->f('activity');
626 $activity_list[$i]['assignment'] = $this->db->f('assignment');
627 $activity_list[$i]['date'] = $this->db->f('date');
628 $activity_list[$i]['notes'] = $this->db->f('notes');
630 $sql = "SELECT * FROM tc_assignment WHERE assignment='" . $activity_list[$i]['assignment'] . "'";
631 $this->db2->query($sql,__LINE__,__FILE__);
632 if($this->db2->next_record()) {
633 $activity_list[$i]['name'] = $this->db2->f('name');
634 $activity_list[$i]['abbreviation'] = $this->db2->f('abbreviation');
639 for ($i=0; $i < count($activity_list); $i++) {
640 $this->nextmatchs->template_alternate_row_color(&$this->t);
641 $this->t->set_var('name',$activity_list[$i]['name']);
642 $this->t->set_var('date',$activity_list[$i]['date']);
643 $activity_notes = $activity_list[$i]['notes'];
644 if(strlen($activity_notes) > 40) { $activity_notes = substr($activity_notes,0,40) . "..."; }
645 $this->t->set_var('notes',$activity_notes);
647 $link_data['menuaction'] = 'tc.tc.act_view';
648 $link_data['activity'] = $activity_list[$i]['activity'];
649 $link_data['action'] = 'view';
650 $this->t->set_var('view',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
651 $this->t->set_var('lang_view','View');
653 $link_data['menuaction'] = 'tc.tc.act_update';
654 $link_data['activity'] = $activity_list[$i]['activity'];
655 $link_data['action'] = 'edit';
656 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
657 $this->t->set_var('lang_edit','Edit');
659 $this->t->fp('list','act_list',True);
662 $link_data['menuaction'] = 'tc.tc.act_update';
663 $link_data['activity'] = '0';
664 $link_data['action'] = 'add';
665 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/tc/index.php',$link_data) .
666 '"><input type="submit" name="Add" value="' . 'Add Activity' .'"></font></form>');
668 $this->t->pfp('out','act_list_t');
669 $this->save_sessiondata();
674 $this->t->set_file(array('act_view_t' => 'act_view.tpl'));
675 $this->t->set_block('act_view_t','part_list','list');
677 $sql = "SELECT * FROM tc_activity WHERE activity=" . intval(get_var('activity',array('GET','POST')));
678 $this->db->query($sql,__LINE__,__FILE__);
679 $this->db->next_record();
680 $this->t->set_var('assignment', $this->db->f('assignment'));
681 $this->t->set_var('date', $this->db->f('date'));
682 $this->t->set_var('notes', $this->db->f('notes'));
684 $sql = "SELECT * FROM tc_assignment WHERE assignment='" . $this->db->f('assignment') . "'";
685 $this->db2->query($sql,__LINE__,__FILE__);
686 if($this->db2->next_record()) {
687 $this->t->set_var('name', $this->db2->f('name'));
688 $this->t->set_var('abbreviation', $this->db2->f('abbreviation'));
690 $this->t->set_var('lang_name','Assignment');
691 $this->t->set_var('lang_date','Date');
692 $this->t->set_var('lang_notes','Description');
693 $this->t->set_var('lang_done','Done');
694 $this->t->set_var('lang_action','View');
696 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
697 $this->t->set_var('tr_color',$tr_color);
699 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_list'));
701 $link_data['menuaction'] = 'tc.tc.act_update';
702 $link_data['activity'] = get_var('activity',array('GET','POST'));
703 $link_data['action'] = 'edit';
704 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
705 $this->t->set_var('lang_edit','Edit');
706 $this->t->set_var('cal_date',$this->db->f('date'));
708 // Now find out which indivs participated in this activity
709 $sql = "SELECT * FROM tc_participation WHERE activity=" . intval(get_var('activity',array('GET','POST')));
710 $this->db->query($sql,__LINE__,__FILE__);
711 $total_records = $this->db->num_rows();
714 while ($this->db->next_record()) {
715 $part_list[$i]['individual'] = $this->db->f('individual');
719 for ($i=0; $i < count($part_list); $i++) {
720 $sql = "SELECT * FROM tc_individual WHERE individual=" . $part_list[$i]['individual'];
721 $this->db->query($sql,__LINE__,__FILE__);
722 $this->db->next_record();
723 $names[$i] = $this->db->f('name');
727 for ($i=0; $i < count($names); $i++) {
728 //$this->nextmatchs->template_alternate_row_color(&$this->t);
729 $this->t->set_var('individual_name',$names[$i]);
730 if(($i+1) % 3 == 0) {
731 $this->t->set_var('table_sep',"</td></tr><tr>");
733 $this->t->set_var('table_sep',"</td>");
735 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
736 $this->t->fp('list','part_list',True);
739 $this->t->pfp('out','act_view_t');
740 $this->save_sessiondata();
743 function act_update()
745 $this->t->set_file(array('form' => 'act_update.tpl'));
746 $this->t->set_block('form','individual_list','list');
747 $this->t->set_block('form','add','addhandle');
748 $this->t->set_block('form','edit','edithandle');
749 $this->t->set_var('lang_done','Done');
751 $action = get_var('action',array('GET','POST'));
752 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_list'));
753 $activity['activity'] = intval(get_var('activity',array('GET','POST')));
755 if($action == 'save') {
756 $activity['assignment'] = get_var('assignment',array('POST'));
757 $activity['date'] = get_var('date',array('POST'));
758 $activity['notes']= get_var('notes',array('POST'));
759 $this->db->query("UPDATE tc_activity set " .
760 " assignment='" . $activity['assignment'] .
761 "', date='" . $activity['date'] . "'" .
762 ", notes=\"" . $activity['notes'] . "\"" .
763 " WHERE activity=" . $activity['activity'],__LINE__,__FILE__);
765 // Delete all the individuals who have particiapted in this activity
766 $this->db->query("DELETE from tc_participation where activity=".$activity['activity'],__LINE__,__FILE__);
768 // Re-add the individuals who are checked as having participated in this activity
769 $indivs = get_var('individual_name',array('POST'));
770 if(is_array($indivs)) { // Only do the foreach loop if we have a valid array of indivs to work with
771 foreach ($indivs as $individual) {
772 $this->db->query("INSERT INTO tc_participation (individual,activity) " .
773 "VALUES (" . $individual . ",". $activity['activity'] . ")",__LINE__,__FILE__);
781 if($action == 'insert') {
782 $activity['assignment'] = get_var('assignment',array('POST'));
783 $activity['date'] = get_var('date',array('POST'));
784 $activity['notes']= get_var('notes',array('POST'));
785 $this->db->query("INSERT INTO tc_activity (assignment,date,notes) " .
786 "VALUES ('" . $activity['assignment'] . "','" .
787 $activity['date'] . "',\"" . $activity['notes'] . "\")",__LINE__,__FILE__);
789 $sql = "SELECT * FROM tc_activity WHERE assignment='".$activity['assignment']."' " .
790 " AND date='".$activity['date']."' AND notes=\"".$activity['notes']."\"";
791 $this->db->query($sql,__LINE__,__FILE__);
792 if($this->db->next_record()) {
793 //print "activity: " . $this->db->f('activity') . "<br>";
794 $activity['activity'] = $this->db->f('activity');
797 $indivs = get_var('individual_name',array('POST'));
798 foreach ($indivs as $individual)
800 $this->db->query("INSERT INTO tc_participation (individual,activity) " .
801 "VALUES (" . $individual . ",". $activity['activity'] . ")",__LINE__,__FILE__);
808 if($action == 'add') {
809 $activity['activity'] = 0;
810 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
811 $this->t->set_var('assignment','');
812 $this->t->set_var('date','');
813 $this->t->set_var('notes','');
814 $this->t->set_var('lang_done','Cancel');
815 $this->t->set_var('lang_action','Adding New Activity');
816 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_update&activity=' .
817 $activity['activity'] . '&action=' . 'insert'));
820 if($action == 'edit') {
821 $sql = "SELECT * FROM tc_activity WHERE activity=" . $activity['activity'];
822 $this->db->query($sql,__LINE__,__FILE__);
823 $this->db->next_record();
824 $this->t->set_var('cal_date',$this->jscal->input('date',$this->db->f('date'),'','','','','',$this->cal_options));
825 $this->t->set_var('assignment', $this->db->f('assignment'));
826 $assignment = $this->db->f('assignment');
827 $this->t->set_var('date', $this->db->f('date'));
828 $this->t->set_var('notes', $this->db->f('notes'));
829 $this->t->set_var('lang_done','Cancel');
830 $this->t->set_var('lang_action','Editing Activity');
831 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_update&activity=' .
832 $activity['activity'] . '&action=' . 'save'));
835 // Create the assignments drop-down list
836 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
837 $this->db->query($sql,__LINE__,__FILE__);
839 while ($this->db->next_record()) {
840 $assignments[$i]['assignment'] = $this->db->f('assignment');
841 $assignments[$i]['name'] = $this->db->f('name');
842 $assignments[$i]['abbreviation'] = $this->db->f('abbreviation');
846 $assignment_data.= '<select name=assignment>';
847 $assignment_data.= '<option value=0></option>';
848 for ($j=0; $j < count($assignments); $j++) {
849 $id = $assignments[$j]['assignment'];
850 $name = $assignments[$j]['name'];
851 if($assignments[$j]['assignment'] == $assignment) {
852 $selected[$id] = 'selected="selected"';
856 $assignment_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
858 $assignment_data.='</select>';
859 $this->t->set_var('assignment_data',$assignment_data);
861 // Create individual selection boxes
862 $sql = "SELECT * FROM tc_individual";
863 $this->db->query($sql,__LINE__,__FILE__);
865 while ($this->db->next_record()) {
866 if($this->db->f('valid') == 1 || $action != 'add') {
867 $indiv_name[$i] = $this->db->f('name');
868 $individual[$i] = $this->db->f('individual');
869 $indiv_valid[$i] = $this->db->f('valid');
873 array_multisort($indiv_name, $individual, $indiv_valid);
876 for ($i=0; $i < count($individual); $i++) {
877 //$this->nextmatchs->template_alternate_row_color(&$this->t);
878 $sql = "SELECT * FROM tc_participation where activity=". $activity['activity'] . " AND individual=" . $individual[$i];
879 $this->db->query($sql,__LINE__,__FILE__);
880 if($this->db->next_record()) {
881 $this->t->set_var('checked','checked');
884 $this->t->set_var('checked','');
887 if($checked || $indiv_valid[$i] == 1) {
888 $this->t->set_var('individual_name',$indiv_name[$i]);
889 $this->t->set_var('individual',$individual[$i]);
890 if(($j+1) % 3 == 0) {
891 $this->t->set_var('table_sep',"</td></tr><tr>");
893 $this->t->set_var('table_sep',"</td>");
895 if(($j) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
896 $this->t->fp('list','individual_list',True);
901 $this->t->set_var('lang_reset','Clear Form');
902 $this->t->set_var('lang_add','Add Activity');
903 $this->t->set_var('lang_save','Save Changes');
904 $this->t->set_var('edithandle','');
905 $this->t->set_var('addhandle','');
907 $this->t->pfp('out','form');
908 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
909 if($action == 'add') { $this->t->pfp('addhandle','add'); }
911 $this->save_sessiondata();
914 function assign_view()
916 $this->t->set_file(array('assign_view_t' => 'assign_view.tpl'));
917 $this->t->set_block('assign_view_t','assign_view','list');
919 $this->t->set_var('lang_name','Assignment Name');
920 $this->t->set_var('lang_code','Abbreviation');
922 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
923 $this->db->query($sql,__LINE__,__FILE__);
924 $total_records = $this->db->num_rows();
927 while ($this->db->next_record()) {
928 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
929 $assignment_list[$i]['name'] = $this->db->f('name');
930 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
934 for ($i=0; $i < count($assignment_list); $i++) {
935 $this->nextmatchs->template_alternate_row_color(&$this->t);
936 $this->t->set_var('name',$assignment_list[$i]['name']);
937 $this->t->set_var('abbreviation',$assignment_list[$i]['abbreviation']);
939 $link_data['menuaction'] = 'tc.tc.assign_update';
940 $link_data['assignment'] = $assignment_list[$i]['assignment'];
941 $link_data['action'] = 'edit';
942 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
943 $this->t->set_var('lang_edit','Edit');
945 $link_data['menuaction'] = 'tc.tc.assign_update';
946 $link_data['assignment'] = '0';
947 $link_data['action'] = 'add';
948 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/tc/index.php',$link_data) .
949 '"><input type="submit" name="Add" value="' . 'Add Assignment' .'"></font></form>');
951 $this->t->fp('list','assign_view',True);
954 $this->t->pfp('out','assign_view_t');
955 $this->save_sessiondata();
958 function assign_update()
960 $this->t->set_file(array('form' => 'assign_update.tpl'));
961 $this->t->set_block('form','add','addhandle');
962 $this->t->set_block('form','edit','edithandle');
963 $this->t->set_var('lang_done','Done');
965 $action = get_var('action',array('GET','POST'));
966 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_view'));
967 $assignment['assignment'] = intval(get_var('assignment',array('GET','POST')));
969 if($action == 'save') {
970 $assignment['name'] = get_var('name',array('POST'));
971 $assignment['abbreviation'] = get_var('abbreviation',array('POST'));
972 $this->db->query("UPDATE tc_assignment set " .
973 " name='" . $assignment['name'] . "'" .
974 ", abbreviation='" . $assignment['abbreviation'] . "'" .
975 " WHERE assignment=" . $assignment['assignment'],__LINE__,__FILE__);
977 $this->assign_view();
981 if($action == 'insert') {
982 $assignment['name'] = get_var('name',array('POST'));
983 $assignment['abbreviation'] = get_var('abbreviation',array('POST'));
984 $this->db->query("INSERT INTO tc_assignment (name,abbreviation) " .
985 "VALUES ('" . $assignment['name'] . "','" .
986 $assignment['abbreviation'] . "')",__LINE__,__FILE__);
987 $this->assign_view();
991 if($action == 'add') {
992 $assignment['assignment'] = 0;
993 $this->t->set_var('name','');
994 $this->t->set_var('abbreviation','');
995 $this->t->set_var('lang_done','Cancel');
996 $this->t->set_var('lang_action','Adding New Assignment');
997 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_update&assignment=' .
998 $assignment['assignment'] . '&action=' . 'insert'));
1001 if($action == 'edit')
1003 $sql = "SELECT * FROM tc_assignment WHERE assignment=" . $assignment['assignment'];
1004 $this->db->query($sql,__LINE__,__FILE__);
1005 $this->db->next_record();
1006 $this->t->set_var('name', $this->db->f('name'));
1007 $this->t->set_var('abbreviation', $this->db->f('abbreviation'));
1008 $this->t->set_var('lang_done','Cancel');
1009 $this->t->set_var('lang_action','Editing Assignment');
1010 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_update&assignment=' .
1011 $assignment['assignment'] . '&action=' . 'save'));
1014 $this->t->set_var('lang_reset','Clear Form');
1015 $this->t->set_var('lang_add','Add Assignment');
1016 $this->t->set_var('lang_save','Save Changes');
1017 $this->t->set_var('edithandle','');
1018 $this->t->set_var('addhandle','');
1020 $this->t->pfp('out','form');
1021 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
1022 if($action == 'add') { $this->t->pfp('addhandle','add'); }
1024 $this->save_sessiondata();
1029 $this->t->set_file(array('par_view_t' => 'par_view.tpl'));
1030 $this->t->set_block('par_view_t','header_list','list1');
1031 $this->t->set_block('par_view_t','individual_list','list2');
1033 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
1034 $this->db->query($sql,__LINE__,__FILE__);
1036 while ($this->db->next_record()) {
1037 $individual_name[$i] = $this->db->f('name');
1038 $individual[$i] = $this->db->f('individual');
1041 array_multisort($individual_name, $individual);
1043 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
1044 $this->db->query($sql,__LINE__,__FILE__);
1045 $total_records = $this->db->num_rows();
1048 while ($this->db->next_record()) {
1049 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1050 $activity_list[$i]['date'] = $this->db->f('date');
1051 $activity_list[$i]['activity'] = $this->db->f('activity');
1055 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1056 $this->db->query($sql,__LINE__,__FILE__);
1058 while($this->db->next_record()) {
1059 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1060 $assignment_list[$i]['name'] = $this->db->f('name');
1061 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1065 $individual_width=300; $part_width=25; $assignment_width=50;
1066 $total_width=$individual_width+$part_width;
1067 for ($i=0; $i < count($assignment_list); $i++) {
1068 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1069 $this->t->set_var('assignment_abbreviation',$assignment_list[$i]['abbreviation']);
1070 $this->t->fp('list1','header_list',True);
1071 $total_width += $assignment_width;
1074 for ($i=0; $i < count($individual); $i++) {
1075 $participated=0; $part_table = '';
1076 $this->nextmatchs->template_alternate_row_color(&$this->t);
1077 $this->t->set_var('individual_name',$individual_name[$i]);
1078 for ($j=0; $j < count($assignment_list); $j++) {
1079 $date = "0000-00-00"; $checkmark=0; $num_matches=0;
1080 for ($k=0; $k < count($activity_list); $k++) {
1081 if($assignment_list[$j]['assignment'] == $activity_list[$k]['assignment']) {
1082 $sql = "SELECT * FROM tc_participation where " .
1083 " activity=" . $activity_list[$k]['activity'] .
1084 " AND individual=" . $individual[$i];
1085 $this->db->query($sql,__LINE__,__FILE__);
1086 while($this->db->next_record()) {
1087 if($activity_list[$k]['date'] > $date) {
1088 $date = $activity_list[$k]['date'];
1097 $part_table .= '<td align=center><img src="images/checkmark.gif">';
1098 $part_table .= '<font size=-2>'.$num_matches.'</font><br>';
1099 $part_table .= '<font size=-2>'.$date.'</font></td>';
1101 $part_table .= '<td> </td>';
1105 $part_table .= '<td align=center><img src="images/checkmark.gif">'.$participated.'</td>';
1107 $part_table .= '<td> </td>';
1109 $this->t->set_var('part_table',$part_table);
1110 $this->t->fp('list2','individual_list',True);
1112 $this->t->set_var('total_width',$total_width);
1113 $this->t->set_var('individual_width',$individual_width);
1114 $this->t->set_var('part_width',$part_width);
1115 $this->t->set_var('act_width',$act_width);
1116 $this->t->pfp('out','par_view_t');
1117 $this->save_sessiondata();
1120 function willing_view()
1122 $this->t->set_file(array('willing_view_t' => 'willing_view.tpl'));
1123 $this->t->set_block('willing_view_t','header_list','list1');
1124 $this->t->set_block('willing_view_t','individual_list','list2');
1126 $this->t->set_var('lang_filter','Filter');
1127 $this->t->set_var('lang_filter_unwilling','Filter out unwilling individuals:');
1129 $filter_unwilling = get_var('filter_unwilling',array('POST'));
1130 $this->t->set_var('filter_unwilling',$filter_unwilling);
1132 if($filter_unwilling == 'y' || $filter_unwilling == '') {
1133 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\" checked>Y";
1134 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\">N";
1135 $filter_input.= " ";
1137 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\">Y";
1138 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\" checked>N";
1139 $filter_input.= " ";
1141 $this->t->set_var('filter_input',$filter_input);
1143 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
1144 $this->db->query($sql,__LINE__,__FILE__);
1146 while ($this->db->next_record()) {
1147 $indiv_name[$i] = $this->db->f('name');
1148 $individual[$i] = $this->db->f('individual');
1149 $indiv_phone[$individual[$i]] = $this->db->f('phone');
1152 array_multisort($indiv_name, $individual);
1154 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1155 $this->db->query($sql,__LINE__,__FILE__);
1157 while($this->db->next_record()) {
1158 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1159 $assignment_list[$i]['name'] = $this->db->f('name');
1160 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1164 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
1165 $this->db->query($sql,__LINE__,__FILE__);
1166 $total_records = $this->db->num_rows();
1169 while ($this->db->next_record()) {
1170 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1171 $activity_list[$i]['date'] = $this->db->f('date');
1172 $activity_list[$i]['activity'] = $this->db->f('activity');
1176 $indiv_width=275; $willing_width=40; $assignment_width=50;
1177 $total_width=$indiv_width+$willing_width;
1179 for ($i=0; $i < count($assignment_list); $i++) {
1180 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1181 $this->t->set_var('assignment_abbreviation',$assignment_list[$i]['abbreviation']);
1182 $this->t->fp('list1','header_list',True);
1183 $total_width += $assignment_width;
1184 $total_willing[$i] = 0;
1187 for ($i=0; $i < count($individual); $i++) {
1188 $willing_table = ''; $indiv_willing=0;
1189 $this->t->set_var('individual_name',$indiv_name[$i]);
1190 $this->t->set_var('individual_phone',$indiv_phone[$individual[$i]]);
1191 $this->t->set_var('editurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_update&individual=' .
1192 $individual[$i] . '&action=' . 'edit'));
1193 for ($j=0; $j < count($assignment_list); $j++) {
1194 $found_willingness=0;
1195 $sql = "SELECT * FROM tc_willingness where " .
1196 " assignment=" . $assignment_list[$j]['assignment'] .
1197 " AND individual=" . $individual[$i];
1198 $this->db->query($sql,__LINE__,__FILE__);
1199 while($this->db->next_record()) {
1200 $found_willingness=1;
1202 $sql = "SELECT * FROM tc_activity where " .
1203 " assignment=". $assignment_list[$j]['assignment'] .
1204 " ORDER by date DESC";
1205 $this->db2->query($sql,__LINE__,__FILE__);
1206 if($this->db2->next_record()) {
1207 $activity = $this->db2->f('activity');
1208 $date = $this->db2->f('date');
1209 $sql = "SELECT * FROM tc_participation where " .
1210 " activity=" . $activity .
1211 " AND individual=". $individual[$i];
1212 $this->db3->query($sql,__LINE__,__FILE__);
1213 if($this->db3->next_record()) {
1218 if($this->db->f('willing') == 'y') {
1219 $total_willing[$j]++;
1221 $willing_table .= '<td align=center><img src="images/checkmark.gif"><br><font size=-2>'.$date_part.'</font></td></td>';
1222 } else if($this->db->f('willing') == 'n') {
1223 $willing_table .= '<td align=center><img src="images/x.gif"></td>';
1226 $willing_table .= "<td> </td>";
1229 if(!$found_willingness) {
1231 $willing_table .= "<td> </td>";
1234 if(($indiv_willing == 1) || ($filter_unwilling == 'n')) {
1235 $this->t->set_var('willing_table',$willing_table);
1236 $this->t->fp('list2','individual_list',True);
1237 $this->nextmatchs->template_alternate_row_color(&$this->t);
1241 $stat_table = '<td><b>Total Willing to Serve</b></td>';
1242 for ($j=0; $j < count($assignment_list); $j++) {
1243 $stat_table .= "<td align=center><b>".$total_willing[$j]."</b></td>";
1245 $this->t->set_var('stat_table',$stat_table);
1247 $this->t->set_var('total_width',$total_width);
1248 $this->t->set_var('individual_width',$indiv_width);
1249 $this->t->set_var('willing_width',$willing_width);
1250 $this->t->pfp('out','willing_view_t');
1251 $this->save_sessiondata();
1254 function willing_update()
1256 //print "<font color=red>Willingness Update Under Constrcution</font>";
1257 //$this->willing_view();
1260 $this->t->set_file(array('willing_update_t' => 'willing_update.tpl'));
1261 $this->t->set_block('willing_update_t','assignment_list','list');
1262 $this->t->set_block('willing_update_t','save','savehandle');
1264 $individual = get_var('individual',array('GET','POST'));
1265 $this->t->set_var('individual',$individual);
1266 $action = get_var('action',array('GET','POST'));
1268 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_view'));
1269 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_update&action=save'));
1270 $this->t->set_var('lang_done','Cancel');
1271 $this->t->set_var('title','Willingness Update ');
1273 if($action == 'save') {
1274 // Delete all the previous willingness entries for this individual
1275 $this->db->query("DELETE from tc_willingness where individual=" . $individual ,__LINE__,__FILE__);
1277 // Now, add the assignment willingness that is checked for this individual
1278 $new_data = get_var('willingness',array('POST'));
1279 foreach ($new_data as $data) {
1280 $data_array = explode("/",$data);
1281 $assignment = $data_array[0];
1282 $willing = $data_array[1];
1283 //print "individual: $individual assignment: $assignment willing: $willing<br>";
1284 $this->db->query("INSERT INTO tc_willingness (individual,assignment,willing) " .
1285 "VALUES (" . $individual .",". $assignment .",'". $willing . "')",__LINE__,__FILE__);
1287 $this->willing_view();
1291 $assignment_width=300; $willing_width=25; $table_width=$assignment_width + $willing_width;
1294 // Find out the individual's name
1295 $sql = "SELECT * FROM tc_individual WHERE individual=".$individual." AND valid=1";
1296 $this->db->query($sql,__LINE__,__FILE__);
1297 if($this->db->next_record()) {
1298 $indiv_name = $this->db->f('name');
1299 $this->t->set_var('individual_name',$indiv_name);
1302 // Select all the assignments
1303 $sql = "SELECT * FROM tc_assignment ORDER by name ASC";
1304 $this->db->query($sql,__LINE__,__FILE__);
1306 while ($this->db->next_record()) {
1307 $assignment = $this->db->f('assignment');
1308 $assignment_name = $this->db->f('name');
1309 $assignment_abbreviation = $this->db->f('abbreviation');
1311 $this->nextmatchs->template_alternate_row_color(&$this->t);
1312 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$assignment_name</td>";
1314 $header_row="<th width=$comp_width><font size=-2>Assignments</th><th>Willingness</th>";
1315 $sql = "SELECT * FROM tc_willingness WHERE individual=".$individual." AND assignment=".$assignment;
1316 $this->db2->query($sql,__LINE__,__FILE__);
1317 $value = $assignment;
1319 if($this->db2->next_record()) {
1320 if($this->db2->f('willing') == 'y') {
1321 $table_data .= '<td width=100 align=center>';
1322 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y" checked>Y';
1323 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1324 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/"> ';
1325 $table_data .= '</td>';
1326 } else if($this->db2->f('willing') == 'n') {
1327 $table_data .= '<td width=100 align=center>';
1328 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1329 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n" checked>N';
1330 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/">';
1331 $table_data .= '</td>';
1333 $table_data .= '<td width=100 align=center>';
1334 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1335 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1336 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1337 $table_data .= '</td>';
1340 $table_data .= '<td width=100 align=center>';
1341 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1342 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1343 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1344 $table_data .= '</td>';
1347 $table_data .= "\n";
1348 $table_data .= "</tr>";
1349 $table_data .= "<tr><td colspan=20></td></tr>";
1352 $table_data .= "<tr><td colspan=20><hr></td></tr>";
1354 $this->t->set_var('table_width',$table_width);
1355 $this->t->set_var('header_row',$header_row);
1356 $this->t->set_var('table_data',$table_data);
1357 $this->t->fp('list','assignment_list',True);
1359 $this->t->set_var('lang_reset','Clear Form');
1360 $this->t->set_var('lang_save','Save Changes');
1361 $this->t->set_var('savehandle','');
1363 $this->t->pfp('out','willing_update_t');
1364 $this->t->pfp('addhandle','save');
1366 $this->save_sessiondata();
1370 function ppi_sched()
1372 $this->t->set_file(array('ppi_sched_t' => 'ppi_sched.tpl'));
1373 $this->t->set_block('ppi_sched_t','individual_list','indivlist');
1374 $this->t->set_block('ppi_sched_t','appt_list','apptlist');
1375 $action = get_var('action',array('GET','POST'));
1377 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1378 $this->t->set_var('lang_reset','Clear Changes');
1380 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
1381 $this->t->set_var('ppi_link_title',$this->ppi_frequency_label . ' PPIs');
1383 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
1384 $this->t->set_var('schedule_ppi_link_title','Schedule ' . $this->ppi_frequency_label . ' PPIs');
1386 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched&action=save'));
1387 $this->t->set_var('title',$this->ppi_frequency_label . ' PPI Scheduler');
1389 $indiv_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $ppi_date_width=20;
1390 $table_width=$indiv_width + $phone_width + $pri_width + $notes_width + $ppi_date_width;
1391 $header_row = "<th width=$indiv_width><font size=-2>individual Name</th>";
1392 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1393 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1394 $header_row.= "<th width=$ppi_date_width><font size=-2>Last PPI</th>";
1395 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1396 $table_data=""; $completed_data=""; $totals_data="";
1400 $period = intval(($month-1)/$this->ppi_frequency) + 1;
1401 $start_of_period = ($period-1)*$this->ppi_frequency + 1;
1402 $end_of_period = $period * $this->ppi_frequency;
1404 if($action == 'save') {
1405 // Save any changes made to the appointment table
1406 $new_data = get_var('appt_notes',array('POST'));
1407 if($new_data != "") {
1408 foreach ($new_data as $entry) {
1409 $indiv = $entry['individual'];
1410 $appointment = $entry['appointment'];
1411 $location = $entry['location'];
1412 $presidency_location = $entry['presidency_location'];
1413 if($location == "") { $location = $presidency_location; }
1414 if($indiv == 0) { $location = ""; }
1416 //Only perform a database update if we have made a change to this appointment
1417 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and individual='$indiv' and location='$location'";
1418 $this->db->query($sql,__LINE__,__FILE__);
1419 if(!$this->db->next_record()) {
1420 // Perform database save actions here
1421 $this->db->query("UPDATE tc_appointment set " .
1422 " individual='" . $indiv . "'" .
1423 ",location='" . $location . "'" .
1424 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1425 // Email the appointment
1426 $this->email_appt($appointment);
1431 // Save any changes made to the ppi notes table
1432 $new_data = get_var('notes',array('POST'));
1433 foreach ($new_data as $entry) {
1434 $notes = $entry['notes'];
1435 $individual = $entry['individual'];
1436 $priority = $entry['pri'];
1438 // Perform database save actions here
1439 $sql = "SELECT * FROM tc_individual WHERE individual='$individual'";
1440 $this->db->query($sql,__LINE__,__FILE__);
1441 if ($this->db->next_record()) {
1442 $scheduling_priority = $this->db->f('scheduling_priority');
1443 //$this->logToFile("ppi_sched", "UPDATE tc_scheduling_priority SET priority='$priority', notes=\"$notes\" WHERE scheduling_priority='$scheduling_priority'");
1444 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$priority', notes=\"$notes\" WHERE scheduling_priority='$scheduling_priority'", __LINE__, __FILE__);
1448 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched');
1449 //Header('Location: ' . $take_me_to_url);
1452 // create the individual id -> individual name mapping
1453 $sql = "SELECT * FROM tc_individual where valid=1 and steward='$this->default_stewardship' ORDER BY name ASC";
1454 $this->db->query($sql,__LINE__,__FILE__);
1458 while ($this->db->next_record()) {
1459 $indiv_name[$i] = $this->db->f('name');
1460 $individual[$i] = $this->db->f('individual');
1463 array_multisort($indiv_name, $individual);
1465 // APPOINTMENT TABLE
1466 $date_width=250; $time_width=100; $indiv_width=200; $location_width=100;
1467 $appt_table_width=$date_width + $time_width + $indiv_width + $location_width;
1468 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1469 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1470 $appt_header_row.= "<th width=$indiv_width><font size=-2>Individual</th>";
1471 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
1472 $appt_table_data = "";
1475 $total_indivs=0; $indivs_with_yearly_ppi=0;
1477 // Get the President
1478 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti where tp.individual=ti.individual AND tp.valid=1 AND ";
1479 if($this->yearly_ppi_interviewer == 1) { $sql .= " (tp.president=1)"; }
1480 if($this->yearly_ppi_interviewer == 2) { $sql .= " (tp.president=1 OR tp.counselor=1)"; }
1481 if($this->yearly_ppi_interviewer == 3) { $sql .= " (tp.president=1 OR tp.counselor=1 OR tp.secretary=1)"; }
1482 $this->db->query($sql,__LINE__,__FILE__);
1483 while ($this->db->next_record()) {
1484 $presidency_name = $this->db->f('name');
1485 $presidency_name_array = explode(",",$presidency_name);
1486 $presidency_last_name = $presidency_name_array[0];
1487 $presidency_id = $this->db->f('presidency');
1488 $presidency_address = $this->db->f('address');
1489 $presidency_location = "$presidency_last_name"." home ($presidency_address)";
1490 $appt_table_data = "";
1492 // Display a scheduling table for this presidency member
1493 $district_number = '*';
1494 $district_name = $presidency_name;
1495 $not_completed_table_title = "District ".$district_number.": ".$district_name.": All indivs with " . $this->ppi_frequency_label . " PPI Not Completed";
1496 $appt_table_title = "District ".$district_number.": ".$district_name.": ".$this->ppi_frequency_label." PPI Appointment Slots";
1497 $this->t->set_var('not_completed_table_title',$not_completed_table_title);
1498 $this->t->set_var('appt_table_title',$appt_table_title);
1500 // query the database for all the appointments
1501 $sql = "SELECT * FROM tc_appointment where presidency=".$presidency_id." and date>=CURDATE() ORDER BY date ASC, time ASC";
1502 $this->db2->query($sql,__LINE__,__FILE__);
1504 while ($this->db2->next_record()) {
1505 $appointment = $this->db2->f('appointment');
1506 $indiv = $this->db2->f('individual');
1507 $location = $this->db2->f('location');
1508 if(($location == "") && ($indiv > 0)) { $location = $presidency_location; }
1510 $date = $this->db2->f('date');
1511 $date_array = explode("-",$date);
1512 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1513 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1515 $time = $this->db2->f('time');
1516 $time_array = explode(":",$time);
1517 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1519 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1520 $appt_table_data.= "<td align=center>$day_string</td>";
1521 $appt_table_data.= "<td align=center>$time_string</td>";
1523 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][individual]>';
1524 $appt_table_data.= '<option value=0></option>';
1525 for ($i=0; $i < count($individual); $i++) {
1526 $id = $individual[$i];
1527 $name = $indiv_name[$i];
1528 if($individual[$i] == $indiv) {
1529 $selected[$id] = 'selected="selected"';
1531 $selected[$id] = '';
1533 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1535 $appt_table_data.='</select></td>';
1537 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
1538 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
1540 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1542 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1543 $this->t->set_var('tr_color',$tr_color);
1545 $this->t->set_var('appt_table_data',$appt_table_data);
1546 $this->t->set_var('appt_header_row',$appt_header_row);
1547 $this->t->set_var('appt_table_width',$appt_table_width);
1548 $this->t->fp('apptlist','appt_list',True);
1551 // PPI SCHEDULING TABLE
1552 $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";
1553 $this->db->query($sql,__LINE__,__FILE__);
1557 while ($this->db->next_record()) {
1558 $individual[$i] = $this->db->f('individual');
1559 $indiv_name[$i] = $this->db->f('name');
1560 $indiv_phone[$individual[$i]] = $this->db->f('phone');
1561 $indiv_priority[$individual[$i]] = $this->db->f('priority');
1562 $indiv_notes[$individual[$i]] = $this->db->f('notes');
1567 $max = count($individual);
1569 for($i=0; $i < $max; $i++) {
1570 $id = $individual[$i];
1571 $name = $indiv_name[$i];
1572 $phone = $indiv_phone[$id];
1573 $priority = $indiv_priority[$id];
1574 $notes = $indiv_notes[$id];
1576 // If this individual has had a PPI this period, don't show him on the schedule list
1577 $year_start = $year . "-" . $start_of_period . "-01";
1578 $year_end = $year . "-" . $end_of_period . "-31";
1579 $sql = "SELECT * FROM tc_interview WHERE date >= '$year_start' AND date <= '$year_end' ".
1580 "AND individual=" . $id . " AND interview_type='ppi' ORDER BY date DESC";
1581 $this->db2->query($sql,__LINE__,__FILE__);
1583 if(!$this->db2->next_record()) {
1584 $sql = "SELECT * FROM tc_interview WHERE individual=" . $id . " AND interview_type='ppi' ORDER BY date DESC";
1585 $this->db->query($sql,__LINE__,__FILE__);
1586 if($this->db->next_record()) {
1587 $date = $this->db->f('date');
1591 $link_data['menuaction'] = 'tc.tc.ppi_update';
1592 $link_data['individual'] = $id;
1593 $link_data['name'] = $name;
1594 $link_data['interview'] = '';
1595 $link_data['interview_type'] = 1;
1596 $link_data['action'] = 'add';
1597 $link_data['interviewer'] = $interviewer;
1598 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1599 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1600 $this->t->set_var('tr_color',$tr_color);
1601 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1602 $table_data.= "<td align=center>$phone</td>";
1603 //$table_data.= "<td align=center>$priority</td>";
1604 $table_data.= "<td align=center>";
1605 $table_data.= '<select name=notes['.$i.'][pri]>';
1606 foreach(range(0,6) as $num) {
1607 if($num == 0) { $num = 1; } else {$num = $num*5; }
1608 if($priority == $num) {
1609 $selected[$num] = 'selected="selected"';
1611 $selected[$num] = '';
1613 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1615 $table_data.= '</select></td>';
1616 $table_data.= "<td align=center>$date</td>";
1617 $table_data.= '<td><input type=text size="50" maxlength="128" name="notes['.$i.'][notes]" value="'.$notes.'">';
1618 $table_data.= '<input type=hidden name="notes['.$i.'][individual]" value="'.$id.'">';
1619 $table_data.= '<input type=hidden name="notes['.$i.'][indiv_name]" value="'.$name.'">';
1620 $table_data.= '</td>';
1621 $table_data.= '</tr>';
1623 $link_data['menuaction'] = 'tc.tc.ppi_update';
1624 $link_data['interviewer'] = $this->db2->f('interviewer');
1625 $link_data['individual'] = $this->db2->f('individual');
1626 $link_data['name'] = $name;
1627 $link_data['interview'] = $this->db2->f('interview');
1628 $link_data['interview_type'] = $this->db2->f('interview_type');
1629 $link_data['action'] = 'view';
1630 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1631 $indivs_with_yearly_ppi++;
1632 $date = $this->db2->f('date');
1633 $notes = $this->db2->f('notes');
1634 if(strlen($notes) > 40) { $notes = substr($notes,0,40) . "..."; }
1635 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1636 $this->t->set_var('tr_color2',$tr_color2);
1637 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1638 $completed_data.= "<td align=center>$phone</td>";
1639 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1640 $completed_data.= "<td align=left>$notes</td>";
1641 $completed_data.= '</tr>';
1643 } // End for individuals Loop
1645 $completed_table_title = "District ".$district_number.": ".$district_name.": All indivs with " . $this->ppi_frequency_label . " PPI Completed";
1646 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1647 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1648 $completed_header_row = "<th width=$name_width><font size=-2>Individual</th>";
1649 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1650 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1651 $completed_header_row.= "<th width=$notes_width><font size=-2>PPI Notes</th>";
1653 $this->t->set_var('completed_table_title',$completed_table_title);
1654 $this->t->set_var('table_width',$table_width);
1655 $this->t->set_var('header_row',$header_row);
1656 $this->t->set_var('table_data',$table_data);
1657 $this->t->set_var('completed_header_row',$completed_header_row);
1658 $this->t->set_var('completed_table_width',$completed_table_width);
1659 $this->t->set_var('completed',$completed_data);
1660 $this->t->fp('indivlist','individual_list',True);
1662 $indivs_width=300; $totals_width=100;
1663 $totals_table_width=$indivs_width + $totals_width;
1664 $totals_header_row = "<th width=$indivs_width><font size=-2>Individuals</th>";
1665 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
1666 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1667 $totals_data.= "<td align=left><font size=-2><b>Total Individuals with " . $this->ppi_frequency_label . " PPIs completed:</b></font></td>";
1668 $totals_data.= "<td align=center><font size=-2><b>$indivs_with_yearly_ppi / $total_indivs</b></font></td>";
1669 $percent = ceil(($indivs_with_yearly_ppi / $total_indivs)*100);
1670 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1671 $this->t->set_var('tr_color',$tr_color);
1672 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1673 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
1674 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
1675 $totals_data.= "</tr>";
1677 $this->t->set_var('totals',$totals_data);
1678 $this->t->set_var('totals_header_row',$totals_header_row);
1679 $this->t->set_var('totals_table_width',$totals_table_width);
1681 $this->t->pfp('out','ppi_sched_t');
1682 $this->save_sessiondata();
1686 function int_sched()
1688 $this->t->set_file(array('int_sched_t' => 'int_sched.tpl'));
1689 $this->t->set_block('int_sched_t','individual_list','indivlist');
1690 $this->t->set_block('int_sched_t','appt_list','apptlist');
1691 $action = get_var('action',array('GET','POST'));
1693 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1694 $this->t->set_var('lang_reset','Clear Changes');
1696 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
1697 $this->t->set_var('int_link_title','Hometeaching Interviews');
1699 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
1700 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
1702 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched&action=save'));
1703 $this->t->set_var('title','Hometeaching Interviews Scheduler');
1705 $indiv_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $int_date_width=20;
1706 $table_width=$indiv_width + $phone_width + $pri_width + $notes_width + $int_date_width;
1707 $header_row = "<th width=$indiv_width><font size=-2>Individual</th>";
1708 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1709 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1710 $header_row.= "<th width=$int_date_width><font size=-2>Last Interview</th>";
1711 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1712 $table_data=""; $completed_data=""; $totals_data="";
1716 $nextyear = $year + 1;
1717 if($month >= 1 && $month <= 3) { $quarter_start=$year."-01-01"; $quarter_end=$year."-04-01"; }
1718 if($month >= 4 && $month <= 6) { $quarter_start=$year."-04-01"; $quarter_end=$year."-07-01"; }
1719 if($month >= 7 && $month <= 9) { $quarter_start=$year."-07-01"; $quarter_end=$year."-10-01"; }
1720 if($month >= 10 && $month <= 12) { $quarter_start=$year."-10-01"; $quarter_end=$nextyear."-01-01"; }
1721 //print "year: $year month: $month quarter_start: $quarter_start quarter_end: $quarter_end<br>";
1723 // create the individual id -> individual name mapping
1724 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY name ASC";
1725 $this->db->query($sql,__LINE__,__FILE__);
1727 $individual_data = NULL;
1728 $indiv_name_data = NULL;
1729 while ($this->db->next_record()) {
1730 $indiv_name_data[$i] = $this->db->f('name');
1731 $individual_data[$i] = $this->db->f('individual');
1732 $individ2name[$individual_data[$i]] = $indiv_name_data[$i];
1735 // add any YM that are home teachers
1736 $sql = "SELECT * FROM tc_companionship where valid=1";
1737 $this->db->query($sql,__LINE__,__FILE__);
1738 while ($this->db->next_record()) {
1739 $tmp_individual = $this->db->f('individual');
1740 $sql = "Select * FROM tc_individual where individual='$tmp_individual' and steward='' and valid=1";
1741 $this->db2->query($sql,__LINE__,__FILE__);
1742 while ($this->db2->next_record()) {
1743 $indiv_name_data[$i] = $this->db2->f('name');
1744 $individual_data[$i] = $this->db2->f('individual');
1745 $individ2name[$individual_data[$i]] = $indiv_name_data[$i];
1749 array_multisort($indiv_name_data, $individual_data);
1751 if($action == 'save') {
1752 // Save any changes made to the appointment table
1753 $new_data = get_var('appt_notes',array('POST'));
1754 if($new_data != "") {
1755 foreach ($new_data as $entry) {
1756 $indiv = $entry['individual'];
1757 $appointment = $entry['appointment'];
1758 $location = $entry['location'];
1759 if($location == "") {
1760 $supervisor = $entry['supervisor'];
1761 $supervisor_array = explode(",", $individ2name[$supervisor]);
1762 $supervisor_last_name = $supervisor_array[0];
1763 $sql = "SELECT * FROM tc_individual where individual='$supervisor'";
1764 $this->db2->query($sql,__LINE__,__FILE__);
1765 if($this->db2->next_record()) {
1766 $supervisor_address = $this->db2->f('address');
1768 $location = "$supervisor_last_name"." home ($supervisor_address)";
1770 if($indiv == 0) { $location = ""; }
1772 //print "indiv: $indiv appointment: $appointment <br>";
1773 //Only perform a database update if we have made a change to this appointment
1774 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and individual='$indiv' and location='$location'";
1775 $this->db->query($sql,__LINE__,__FILE__);
1776 if(!$this->db->next_record()) {
1777 // Perform database save actions here
1778 $this->db->query("UPDATE tc_appointment set " .
1779 " individual='" . $indiv . "'" .
1780 ",location='" . $location . "'" .
1781 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1782 // Email the appointment
1783 $this->email_appt($appointment);
1788 // Save any changes made to the int notes table
1789 $new_data = get_var('hti_notes',array('POST'));
1790 foreach ($new_data as $entry) {
1791 $hti_notes = $entry['notes'];
1792 $individual = $entry['individual'];
1793 $indiv_name = $entry['indiv_name'];
1794 $hti_pri = $entry['pri'];
1795 //print "hti_notes: $hti_notes indiv_name: $indiv_name <Br>";
1796 // Perform database save actions here
1797 $this->db->query("SELECT * FROM tc_companion WHERE individual=$individual and valid=1",__LINE__,__FILE__);
1798 if ($this->db->next_record()) {
1799 $scheduling_priority = $this->db->f('scheduling_priority');
1800 //$this->logToFile("int_sched", "UPDATE tc_scheduling_priority SET priority='$hti_pri', notes=\"$hti_notes\" WHERE scheduling_priority='$scheduling_priority'");
1801 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$hti_pri', notes=\"$hti_notes\" WHERE scheduling_priority='$scheduling_priority'",__LINE__,__FILE__);
1805 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched');
1806 //Header('Location: ' . $take_me_to_url);
1809 // Get the Districts
1810 $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";
1811 $this->db->query($sql,__LINE__,__FILE__);
1813 while ($this->db->next_record()) {
1814 $district = $this->db->f('district');
1815 $districts[$i]['district'] = $this->db->f('district');
1816 $districts[$i]['name'] = $this->db->f('name');
1817 $districts[$i]['supervisor'] = $this->db->f('supervisor');
1818 $districts[$i]['presidency'] = $this->db->f('presidency');
1822 // APPOINTMENT TABLE
1824 $date_width=250; $time_width=100; $indiv_width=200; $location_width=100;
1825 $appt_table_width=$date_width + $time_width + $indiv_width + $location_width;
1826 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1827 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1828 $appt_header_row.= "<th width=$indiv_width><font size=-2>Individual</th>";
1829 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
1830 $appt_table_data = "";
1832 $total_comps=0; $comps_with_quarterly_int=0;
1834 // Display a scheduling table for each district
1835 for ($d=0; $d < count($districts); $d++) {
1836 $table_data=""; $appt_table_data="";
1837 $this->t->set_var('district_number',$districts[$d]['district']);
1838 $this->t->set_var('district_name',$districts[$d]['name']);
1839 $supervisor = $districts[$d]['supervisor'];
1840 $supervisor_array = explode(",", $supervisor);
1841 $supervisor_last_name = $supervisor_array[0];
1842 $sql = "SELECT * FROM tc_individual where individual='$supervisor'";
1843 $this->db2->query($sql,__LINE__,__FILE__);
1844 if($this->db2->next_record()) {
1845 $supervisor_address = $this->db2->f('address');
1847 $location = "$supervisor_last_name"." home ($supervisor_address)";
1848 $table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": All Individuals with Interviews Not Completed";
1849 $appt_table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": Interview Appointment Slots";
1850 $this->t->set_var('table_title',$table_title);
1851 $this->t->set_var('appt_table_title',$appt_table_title);
1853 // query the database for all the appointments
1854 $sql = "SELECT * FROM tc_appointment where presidency=".$districts[$d]['presidency']." and date>=CURDATE() ORDER BY date ASC, time ASC";
1855 $this->db->query($sql,__LINE__,__FILE__);
1857 while ($this->db->next_record()) {
1858 $appointment = $this->db->f('appointment');
1859 $indiv = $this->db->f('individual');
1860 $location = $this->db->f('location');
1861 if(($location == "") && ($indiv > 0)) { $location = "$supervisor_last_name"." home ($supervisor_address)"; }
1863 $date = $this->db->f('date');
1864 $date_array = explode("-",$date);
1865 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1866 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1868 $time = $this->db->f('time');
1869 $time_array = explode(":",$time);
1870 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1872 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1873 $appt_table_data.= "<td align=center>$day_string</td>";
1874 $appt_table_data.= "<td align=center>$time_string</td>";
1876 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][individual]>';
1877 $appt_table_data.= '<option value=0></option>';
1878 for ($i=0; $i < count($individual_data); $i++) {
1879 $id = $individual_data[$i];
1880 $name = $indiv_name_data[$i];
1881 if($individual_data[$i] == $indiv) {
1882 $selected[$id] = 'selected="selected"';
1884 $selected[$id] = '';
1886 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1888 $appt_table_data.='</select></td>';
1890 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
1891 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
1893 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1894 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][supervisor]" value="'.$supervisor.'">';
1896 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1897 $this->t->set_var('tr_color',$tr_color);
1900 $this->t->set_var('appt_table_data',$appt_table_data);
1901 $this->t->set_var('appt_header_row',$appt_header_row);
1902 $this->t->set_var('appt_table_width',$appt_table_width);
1904 // INTERVIEW SCHEDULING TABLE
1906 // Select all the unique companionship numbers for this district
1907 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$d]['district'];
1908 $this->db->query($sql,__LINE__,__FILE__);
1909 $j=0; $unique_companionships = '';
1910 while ($this->db->next_record())
1912 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
1917 for ($j=0; $j < count($unique_companionships); $j++) {
1918 // Select all the companions from each companionship
1919 $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'];
1920 $this->db->query($sql,__LINE__,__FILE__);
1921 $k=0; $int_completed=0;
1922 $comp = $unique_companionships[$j]['companionship'];
1923 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1924 $this->t->set_var('tr_color',$tr_color);
1926 while ($this->db->next_record()) {
1927 // Get this companions information
1928 $individual = $this->db->f('individual');
1930 $id = $this->db->f('individual');
1931 $name = $this->db->f('name');
1932 $phone = $this->db->f('phone');
1933 $hti_pri = $this->db->f('priority');
1934 $hti_notes = $this->db->f('notes');
1936 // If the companionship has already had its quarterly interview,
1937 // Skip the other companion in the companionship.
1938 if($int_completed == 1) {
1939 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1940 $completed_data.= "<td align=center>$phone</td>";
1941 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1942 $completed_data.= "<td align=left>$hti_notes</td>";
1943 $completed_data.= '</tr>';
1944 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1945 $this->t->set_var('tr_color2',$tr_color2);
1946 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1947 $this->t->set_var('tr_color',$tr_color);
1951 // If this companionship has had a hometeaching interview this quarter, don't show them on the schedule list
1952 $sql = "SELECT * FROM tc_interview WHERE date >= '$quarter_start' AND date < '$quarter_end' AND individual='$id' AND interview_type='hti'";
1953 $this->db2->query($sql,__LINE__,__FILE__);
1955 if(!$this->db2->next_record()) {
1956 $sql = "SELECT * FROM tc_interview WHERE individual='$id' AND interview_type='hti' ORDER BY date DESC";
1957 $this->db3->query($sql,__LINE__,__FILE__);
1958 if($this->db3->next_record()) {
1959 $date = $this->db3->f('date');
1963 $link_data['menuaction'] = 'tc.tc.int_update';
1964 $link_data['individual'] = $id;
1965 $link_data['name'] = $name;
1966 $link_data['interview'] = '';
1967 $link_data['action'] = 'add';
1968 $link_data['interview_type'] = 'hti';
1969 $link_data['interviewer'] = $districts[$d]['supervisor'];
1970 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1971 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1972 $table_data.= "<td align=center>$phone</td>";
1973 $table_data.= "<td align=center>";
1974 $table_data.= '<select name=hti_notes['.$i.'][pri]>';
1975 foreach(range(0,6) as $num) {
1976 if($num == 0) { $num = 1; } else {$num = $num*5; }
1977 if($hti_pri == $num) {
1978 $selected[$num] = 'selected="selected"';
1980 $selected[$num] = '';
1982 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1984 $table_data.= '</select></td>';
1985 $table_data.= "<td align=center>$date</td>";
1986 $table_data.= '<td><input type=text size="50" maxlength="128" name="hti_notes['.$i.'][notes]" value="'.$hti_notes.'">';
1987 $table_data.= '<input type=hidden name="hti_notes['.$i.'][individual]" value="'.$id.'">';
1988 $table_data.= '<input type=hidden name="hti_notes['.$i.'][indiv_name]" value="'.$name.'">';
1989 $table_data.= '</td>';
1990 $table_data.= '</tr>'."\n";
1993 $link_data['menuaction'] = 'tc.tc.int_update';
1994 $link_data['interviewer'] = $this->db2->f('interviewer');
1995 $link_data['individual'] = $this->db2->f('individual');
1996 $link_data['name'] = $name;
1997 $link_data['interview'] = $this->db2->f('interview');
1998 $link_data['interview_type'] = 'hti';
1999 $link_data['action'] = 'view';
2000 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2001 $comps_with_quarterly_int++;
2003 $date = $this->db2->f('date');
2004 $hti_notes = $this->db2->f('notes');
2005 if(strlen($hti_notes) > 40) { $hti_notes = substr($hti_notes,0,40) . "..."; }
2006 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2007 $completed_data.= "<td align=center>$phone</td>";
2008 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2009 $completed_data.= "<td align=left>$hti_notes</td>";
2010 $completed_data.= '</tr>';
2015 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
2016 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
2017 $completed_header_row = "<th width=$name_width><font size=-2>Individual</th>";
2018 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2019 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
2020 $completed_header_row.= "<th width=$notes_width><font size=-2>Interview Notes</th>";
2022 $this->t->set_var('table_width',$table_width);
2023 $this->t->set_var('header_row',$header_row);
2024 $this->t->set_var('table_data',$table_data);
2025 $this->t->set_var('completed_header_row',$completed_header_row);
2026 $this->t->set_var('completed_table_width',$completed_table_width);
2027 $this->t->set_var('completed',$completed_data);
2028 $this->t->fp('indivlist','individual_list',True);
2030 } // End for each district loop
2033 $indivs_width=300; $totals_width=100;
2034 $totals_table_width=$indivs_width + $totals_width;
2035 $totals_header_row = "<th width=$indivs_width><font size=-2>Individuals</th>";
2036 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2037 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2038 $totals_data.= "<td align=left><font size=-2><b>Total Companionships with interviews completed:</b></font></td>";
2039 $totals_data.= "<td align=center><font size=-2><b>$comps_with_quarterly_int / $total_comps</b></font></td>";
2040 $percent = ceil(($comps_with_quarterly_int / $total_comps)*100);
2041 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2042 $this->t->set_var('tr_color',$tr_color);
2043 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2044 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2045 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2046 $totals_data.= "</tr>";
2048 $this->t->set_var('totals',$totals_data);
2049 $this->t->set_var('totals_header_row',$totals_header_row);
2050 $this->t->set_var('totals_table_width',$totals_table_width);
2052 $this->t->pfp('out','int_sched_t');
2053 $this->save_sessiondata();
2057 function vis_sched()
2059 $this->t->set_file(array('vis_sched_t' => 'vis_sched.tpl'));
2060 $this->t->set_block('vis_sched_t','family_list','familylist');
2061 $this->t->set_block('vis_sched_t','appt_list','apptlist');
2062 $action = get_var('action',array('GET','POST'));
2064 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
2065 $this->t->set_var('lang_reset','Clear Changes');
2067 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2068 $this->t->set_var('vis_link_title','View Yearly Visits');
2070 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
2071 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2073 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched&action=save'));
2074 $this->t->set_var('title','Presidency Yearly Visit Scheduler');
2076 $family_width=500; $phone_width=40; $pri_width=10; $notes_width=128; $visit_date_width=20;
2077 $table_width=$family_width + $phone_width + $pri_width + $notes_width + $visit_date_width;
2078 $header_row = "<th width=$family_width><font size=-2>Family Name</th>";
2079 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2080 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
2081 $header_row.= "<th width=$visit_date_width><font size=-2>Last Visit</th>";
2082 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
2083 $table_data=""; $completed_data=""; $totals_data="";
2087 // create the family id -> family name mapping
2088 $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";
2089 $this->db->query($sql,__LINE__,__FILE__);
2092 while ($this->db->next_record()) {
2093 $family_id[$i] = $this->db->f('family');
2094 $family_name[$i] = $this->db->f('name');
2095 $familyid2name[$family_id[$i]] = $family_name[$i];
2096 $familyid2address[$family_id[$i]] = $this->db->f('address');
2099 array_multisort($family_name, $family_id);
2101 if($action == 'save') {
2102 // Save any changes made to the appointment table
2103 $new_data = get_var('appt_notes',array('POST'));
2104 if($new_data != "") {
2105 foreach ($new_data as $entry) {
2106 $family = $entry['family'];
2107 $appointment = $entry['appointment'];
2108 $location = $entry['location'];
2109 if($location == "") {
2110 $family_name_array = explode(",", $familyid2name[$family]);
2111 $family_last_name = $family_name_array[0];
2112 $family_address = $familyid2address[$family];
2113 $location = "$family_last_name"." home ($family_address)";
2115 if($family == 0) { $location = ""; }
2117 //Only perform a database update if we have made a change to this appointment
2118 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and family='$family' and location='$location'";
2119 $this->db->query($sql,__LINE__,__FILE__);
2120 if(!$this->db->next_record()) {
2121 // Perform database save actions here
2122 $this->db->query("UPDATE tc_appointment set " .
2123 " family='" . $family . "'" .
2124 ",location='" . $location . "'" .
2125 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
2127 // Email the appointment
2128 $this->email_appt($appointment);
2133 // Save any changes made to the visit notes table
2134 $new_data = get_var('vis_notes',array('POST'));
2135 foreach ($new_data as $entry) {
2136 $visit_notes = $entry['notes'];
2137 $family = $entry['family_id'];
2138 $visit_pri = $entry['pri'];
2139 // Perform database save actions here
2140 $this->db->query("SELECT * FROM tc_family WHERE family='$family'",__LINE__,__FILE__);
2141 if ($this->db->next_record()) {
2142 $scheduling_priority = $this->db->f('scheduling_priority');
2143 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$visit_pri', notes=\"$visit_notes\" WHERE scheduling_priority='$scheduling_priority'", __LINE__, __FILE__);
2147 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched');
2148 //Header('Location: ' . $take_me_to_url);
2151 // APPOINTMENT TABLE
2152 $date_width=250; $time_width=100; $family_width=250; $location_width=100;
2153 $appt_table_width=$date_width + $time_width + $family_width + $location_width;
2154 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
2155 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
2156 $appt_header_row.= "<th width=$family_width><font size=-2>Family</th>";
2157 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
2158 $appt_table_data = "";
2160 // Find out what the President ID is
2161 $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";
2162 $this->db->query($sql,__LINE__,__FILE__);
2163 if($this->db->next_record()) {
2164 $presidency_name = $this->db->f('name');
2165 $presidency_id = $this->db->f('presidency');
2167 print "<hr><font color=red><h3>-E- Unable to locate Presidency in tc_presidency table</h3></font></hr>";
2171 // query the database for all the appointments
2172 $sql = "SELECT * FROM tc_appointment where presidency=$presidency_id and date>=CURDATE() ORDER BY date ASC, time ASC";
2173 $this->db->query($sql,__LINE__,__FILE__);
2175 while ($this->db->next_record()) {
2176 $appointment = $this->db->f('appointment');
2177 $family = $this->db->f('family');
2178 $location = $this->db->f('location');
2179 $family_name_array = explode(",", $familyid2name[$family]);
2180 $family_last_name = $family_name_array[0];
2181 $family_address = $familyid2address[$family];
2182 if(($location == "") && ($family > 0)) { $location = "$family_last_name"." home ($family_address)"; }
2184 $date = $this->db->f('date');
2185 $date_array = explode("-",$date);
2186 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
2187 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
2189 $time = $this->db->f('time');
2190 $time_array = explode(":",$time);
2191 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
2193 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2194 $appt_table_data.= "<td align=center>$day_string</td>";
2195 $appt_table_data.= "<td align=center>$time_string</td>";
2197 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][family]>';
2198 $appt_table_data.= '<option value=0></option>';
2199 for ($i=0; $i < count($family_id); $i++) {
2200 $id = $family_id[$i];
2201 $name = $family_name[$i];
2202 if($family_id[$i] == $family) {
2203 $selected[$id] = 'selected="selected"';
2205 $selected[$id] = '';
2207 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
2209 $appt_table_data.='</select></td>';
2211 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
2212 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
2214 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
2216 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2217 $this->t->set_var('tr_color',$tr_color);
2220 $this->t->set_var('appt_table_data',$appt_table_data);
2221 $this->t->set_var('appt_header_row',$appt_header_row);
2222 $this->t->set_var('appt_table_width',$appt_table_width);
2225 // VISIT SCHEDULING TABLE
2226 $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";
2227 $this->db->query($sql,__LINE__,__FILE__);
2229 $total_families=0; $families_with_yearly_visit=0;
2231 while ( $this->db->next_record()) {
2233 $id = $this->db->f('family');
2234 $name = $this->db->f('name');
2235 $phone = $this->db->f('phone');
2236 $vis_pri = $this->db->f('priority');
2237 $vis_notes = $this->db->f('notes');
2239 // If this family has had a yearly visit this year, don't show them on the schedule list
2240 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2241 $sql = "SELECT * FROM tc_visit WHERE date > '$year_start' AND date < '$year_end' ".
2242 "AND family=" . $id . " AND companionship=0";
2243 $this->db2->query($sql,__LINE__,__FILE__);
2245 if(!$this->db2->next_record()) {
2246 $sql = "SELECT * FROM tc_visit WHERE family=" . $id . " AND companionship=0 ORDER BY date DESC";
2247 $this->db3->query($sql,__LINE__,__FILE__);
2248 if($this->db3->next_record()) {
2249 $date = $this->db3->f('date');
2253 $link_data['menuaction'] = 'tc.tc.vis_update';
2254 $link_data['visit'] = '';
2255 $link_data['family'] = $id;
2256 $link_data['name'] = $name;
2257 $link_data['action'] = 'add';
2258 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2259 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2260 $table_data.= "<td align=center>$phone</td>";
2261 $table_data.= "<td align=center>";
2262 $table_data.= '<select name=vis_notes['.$id.'][pri]>';
2263 foreach(range(0,6) as $num) {
2264 if($num == 0) { $num = 1; } else {$num = $num*5; }
2265 if($vis_pri == $num) {
2266 $selected[$num] = 'selected="selected"';
2268 $selected[$num] = '';
2270 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2272 $table_data.= '</select></td>';
2273 $table_data.= "<td align=center>$date</td>";
2274 $table_data.= '<td><input type=text size="50" maxlength="128" name="vis_notes['.$id.'][notes]" value="'.$vis_notes.'">';
2275 $table_data.= '<input type=hidden name="vis_notes['.$id.'][family_id]" value="'.$id.'">';
2276 $table_data.= '<input type=hidden name="vis_notes['.$id.'][family_name]" value="'.$name.'">';
2277 $table_data.= '</td>';
2278 $table_data.= '</tr>';
2279 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2280 $this->t->set_var('tr_color',$tr_color);
2282 $link_data['menuaction'] = 'tc.tc.vis_update';
2283 $link_data['visit'] = $this->db2->f('visit');
2284 $link_data['family'] = $this->db2->f('family');
2285 $link_data['name'] = $name;
2286 $link_data['date'] = $this->db2->f('date');
2287 $link_data['action'] = 'view';
2288 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2289 $families_with_yearly_visit++;
2290 $date = $this->db2->f('date');
2291 $vis_notes = $this->db2->f('notes');
2292 if(strlen($vis_notes) > 40) { $vis_notes = stripslashes(substr($vis_notes,0,40) . "..."); }
2293 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2294 $completed_data.= "<td align=center>$phone</td>";
2295 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2296 $completed_data.= "<td align=left>$vis_notes</td>";
2297 $completed_data.= '</tr>';
2298 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
2299 $this->t->set_var('tr_color2',$tr_color2);
2303 $name_width=190; $phone_width=100; $date_width=100; $notes_width=300;
2304 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
2305 $completed_header_row = "<th width=$name_width><font size=-2>Family Name</th>";
2306 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2307 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
2308 $completed_header_row.= "<th width=$notes_width><font size=-2>Visit Notes</th>";
2310 $family_width=300; $totals_width=100;
2311 $totals_table_width=$family_width + $totals_width;
2312 $totals_header_row = "<th width=$family_width><font size=-2>Families</th>";
2313 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2314 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2315 $totals_data.= "<td align=left><font size=-2><b>Total Families with yearly Visits completed:</b></font></td>";
2316 $totals_data.= "<td align=center><font size=-2><b>$families_with_yearly_visit / $total_families</b></font></td>";
2317 $percent = ceil(($families_with_yearly_visit / $total_families)*100);
2318 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2319 $this->t->set_var('tr_color',$tr_color);
2320 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2321 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2322 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2323 $totals_data.= "</tr>";
2325 $this->t->set_var('table_width',$table_width);
2326 $this->t->set_var('header_row',$header_row);
2327 $this->t->set_var('table_data',$table_data);
2328 $this->t->set_var('totals_header_row',$totals_header_row);
2329 $this->t->set_var('totals_table_width',$totals_table_width);
2330 $this->t->set_var('completed_header_row',$completed_header_row);
2331 $this->t->set_var('completed_table_width',$completed_table_width);
2332 $this->t->set_var('completed',$completed_data);
2333 $this->t->set_var('totals',$totals_data);
2334 $this->t->fp('familylist','family_list',True);
2335 $this->t->fp('apptlist','appt_list',True);
2337 $this->t->pfp('out','vis_sched_t');
2338 $this->save_sessiondata();
2343 $this->t->set_file(array('ppi_view_t' => 'ppi_view.tpl'));
2344 $this->t->set_block('ppi_view_t','district_list','list');
2346 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2347 $num_months = get_var('num_months',array('GET','POST'));
2348 if($num_months == '') { $num_months = $this->default_ppi_num_months; }
2349 $this->t->set_var('num_months',$num_months);
2350 if($num_months == 1) {
2351 $this->t->set_var('lang_num_months','Month of History');
2353 $this->t->set_var('lang_num_months','Months of History');
2355 $this->t->set_var('lang_filter','Filter');
2356 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2358 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2359 $this->t->set_var('ppi_link_title',$this->ppi_frequency_label . ' PPIs');
2361 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
2362 $this->t->set_var('schedule_ppi_link_title','Schedule ' . $this->ppi_frequency_label . ' PPIs');
2364 $this->t->set_var('title',$this->ppi_frequency_label . ' PPIs');
2365 $num_months = get_var('num_months',array('GET','POST'));
2366 if($num_months == '') { $num_months = $this->default_ppi_num_years; }
2367 $this->t->set_var('num_months',$num_months);
2368 if($num_months == 1) {
2369 $this->t->set_var('lang_num_months','Year of History');
2371 $this->t->set_var('lang_num_months','Years of History');
2374 $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";
2375 $this->db->query($sql,__LINE__,__FILE__);
2376 if($this->db->next_record()) {
2377 $president_name = $this->db->f('name');
2378 $interviewer = $this->db->f('individual');
2380 print "<hr><font color=red><h3>-E- Unable to locate President in tc_presidency table</h3></font></hr>";
2383 $this->t->set_var('district_number','*');
2384 $this->t->set_var('district_name',$president_name);
2386 $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";
2387 $this->db->query($sql,__LINE__,__FILE__);
2389 while ($this->db->next_record()) {
2390 $individual[$i] = $this->db->f('individual');
2391 $indiv_name[$i] = $this->db->f('name');
2392 $indiv_phone[$individual[$i]] = $this->db->f('phone');
2393 $indiv_priority[$individual[$i]] = $this->db->f('priority');
2394 $indiv_notes[$individual[$i]] = $this->db->f('notes');
2398 array_multisort($indiv_name, $individual);
2399 //var_dump($indiv_name); print "<br><br>"; var_dump($individual);
2401 $header_row="<th width=$comp_width><font size=-2>Individual</th>";
2403 $indiv_width=400; $ppi_width=75; $table_width=$indiv_width + $num_months*$ppi_width;
2405 for($m=$num_months; $m >= 0; $m--) {
2406 $year = date('Y') - $m;
2407 $header_row .= "<th width=150><font size=-2>$year</th>";
2411 for ($j=0; $j < count($individual); $j++) {
2412 $id = $individual[$j];
2413 $name = $indiv_name[$j];
2414 $phone = $indiv_phone[$id];
2416 $link_data['menuaction'] = 'tc.tc.ppi_update';
2417 $link_data['interviewer'] = $interviewer;
2418 $link_data['individual'] = $id;
2419 $link_data['name'] = $name;
2420 $link_data['interview'] = '';
2421 $link_data['interview_type'] = 'ppi';
2422 $link_data['action'] = 'add';
2423 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2424 $this->nextmatchs->template_alternate_row_color(&$this->t);
2425 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2427 // Find out how many times PPIs were performed in the past $num_months for this individual
2428 for($m=$num_months; $m >= 0; $m--) {
2429 $year = date('Y') - $m;
2430 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2431 $sql = "SELECT * FROM tc_interview WHERE date > '$year_start' AND date < '$year_end' ".
2432 "AND individual=" . $id . " AND interview_type='ppi' ORDER BY date DESC";
2433 $this->db2->query($sql,__LINE__,__FILE__);
2435 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
2436 if($this->db2->next_record()) {
2437 $ppis[$m]++; $total_ppis[$m]++; $ppi_recorded[$companionship][$m]=1;
2438 $link_data['menuaction'] = 'tc.tc.ppi_update';
2439 $link_data['companionship'] = $companionship;
2440 $link_data['interviewer'] = $this->db2->f('interviewer');
2441 $link_data['indiv'] = $id;
2442 $link_data['name'] = $name;
2443 $link_data['interview'] = $this->db2->f('interview');
2444 $link_data['interview_type'] = 'ppi';
2445 $link_data['action'] = 'view';
2446 $date = $this->db2->f('date');
2447 $date_array = explode("-",$date);
2448 $month = $date_array[1];
2449 $day = $date_array[2];
2450 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2451 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2453 $table_data .= "<td> </td>";
2456 $table_data .= "</tr>\n";
2458 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2460 $stat_data = "<tr><td><b><font size=-2>$total_indivs Individuals<br>PPI Totals:</font></b></td>";
2461 for($m=$num_months; $m >=0; $m--) {
2462 $percent = ceil(($ppis[$m] / $total_indivs)*100);
2463 $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
2465 $stat_data .= "</tr>";
2467 $this->t->set_var('table_width',$table_width);
2468 $this->t->set_var('header_row',$header_row);
2469 $this->t->set_var('table_data',$table_data);
2470 $this->t->set_var('stat_data',$stat_data);
2471 $this->t->pfp('out','ppi_view_t');
2472 $this->save_sessiondata();
2475 function ppi_update()
2477 $this->t->set_file(array('form' => 'ppi_update.tpl'));
2478 $this->t->set_block('form','interviewer_list','int_list');
2479 $this->t->set_block('form','add','addhandle');
2480 $this->t->set_block('form','edit','edithandle');
2482 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2483 $this->t->set_var('readonly','');
2484 $this->t->set_var('disabled','');
2486 $action = get_var('action',array('GET','POST'));
2487 $companionship = get_var('companionship',array('GET','POST'));
2488 $interviewer = get_var('interviewer',array('GET','POST'));
2489 $name = get_var('name',array('GET','POST'));
2490 $interview = get_var('interview',array('GET','POST'));
2491 $individual = get_var('individual',array('GET','POST'));
2492 $date = get_var('date',array('GET','POST'));
2493 $notes = get_var('notes',array('GET','POST'));
2494 $interview_type = get_var('interview_type',array('GET','POST'));
2496 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1 AND ";
2497 if($this->yearly_ppi_interviewer == 1) { $sql .= " (tp.president=1)"; }
2498 if($this->yearly_ppi_interviewer == 2) { $sql .= " (tp.president=1 OR tp.counselor=1)"; }
2499 if($this->yearly_ppi_interviewer == 3) { $sql .= " (tp.president=1 OR tp.counselor=1 OR tp.secretary=1)"; }
2500 $this->db2->query($sql,__LINE__,__FILE__);
2501 while ($this->db2->next_record()) {
2502 $indiv = $this->db2->f('individual');
2503 $interviewer_name = $this->db2->f('name');
2504 if($indiv == $interviewer) {
2505 $this->t->set_var('interviewer',$indiv . ' selected');
2507 $this->t->set_var('interviewer',$indiv);
2509 #print "indiv: $indiv interviewer: $interviewer<br>";
2510 $this->t->set_var('interviewer_name',$interviewer_name);
2511 $this->t->set_var('eqpresppi_checked','checked');
2512 $this->t->fp('int_list','interviewer_list',True);
2514 #print "selected interviewer: $interviewer<br>";
2515 if($action == 'save') {
2516 $notes = get_var('notes',array('POST'));
2517 $this->db->query("UPDATE tc_interview set " .
2518 " interview='" . $interview . "'" .
2519 ", interviewer='" . $interviewer . "'" .
2520 ", individual='" . $individual . "'" .
2521 ", date='" . $date . "'" .
2522 ", notes=\"" . $notes . "\"" .
2523 ", interview_type='" . $interview_type . "'" .
2524 " WHERE interview=" . $interview,__LINE__,__FILE__);
2529 if($action == 'insert') {
2530 $notes = get_var('notes',array('POST'));
2531 $this->db->query("INSERT INTO tc_interview (interviewer,individual,date,notes,interview_type) " .
2532 "VALUES ('" . $interviewer . "','" . $individual . "','" .
2533 $date . "',\"" . $notes . "\",'" . $interview_type ."')",__LINE__,__FILE__);
2538 if($action == 'add') {
2539 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2540 $this->t->set_var('interview', '');
2541 $this->t->set_var('interviewer', $interviewer);
2542 $this->t->set_var('name',$name);
2543 $this->t->set_var('individual',$individual);
2544 $this->t->set_var('date','');
2545 $this->t->set_var('notes','');
2546 $this->t->set_var('interview_type',$interview_type);
2547 $this->t->set_var('eqpresppi_checked','checked');
2548 $this->t->set_var('lang_done','Cancel');
2549 $this->t->set_var('lang_action','Adding New PPI');
2550 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview=' .
2551 $interview . '&action=' . 'insert'));
2554 if($action == 'edit' || $action == 'view') {
2555 $sql = "SELECT * FROM tc_interview WHERE interview=" . $interview . " AND interview_type='ppi'";
2556 $this->db->query($sql,__LINE__,__FILE__);
2557 $this->db->next_record();
2558 $this->t->set_var('interview',$interview);
2559 $this->t->set_var('name',$name);
2560 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2561 $this->t->set_var('individual',$this->db->f('individual'));
2562 $this->t->set_var('date',$this->db->f('date'));
2563 $this->t->set_var('notes',$this->db->f('notes'));
2564 $this->t->set_var('interview_type',$this->db->f('interview_type'));
2565 if($this->db->f('interview_type') == 'ppi') { $this->t->set_var('eqpresppi_checked','checked'); }
2568 if($action == 'edit') {
2569 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2570 $this->t->set_var('lang_done','Cancel');
2571 $this->t->set_var('lang_action','Editing PPI');
2572 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview='.
2573 $interview . '&action=' . 'save'));
2576 if($action == 'view') {
2577 $date = $this->db->f('date');
2578 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2579 $this->t->set_var('readonly','READONLY');
2580 $this->t->set_var('disabled','DISABLED');
2581 $this->t->set_var('lang_done','Done');
2582 $this->t->set_var('lang_action','Viewing PPI');
2583 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview=' .
2584 $interview . '&action=' . 'edit'));
2587 $this->t->set_var('lang_reset','Clear Form');
2588 $this->t->set_var('lang_add','Add PPI');
2589 $this->t->set_var('lang_save','Save Changes');
2590 $this->t->set_var('edithandle','');
2591 $this->t->set_var('addhandle','');
2593 $this->t->pfp('out','form');
2595 if($action == 'view') { $this->t->set_var('lang_save','Edit PPI'); }
2596 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2597 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2599 $this->save_sessiondata();
2604 $this->t->set_file(array('int_view_t' => 'int_view.tpl'));
2605 $this->t->set_block('int_view_t','district_list','list');
2607 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2608 $num_quarters = get_var('num_quarters',array('GET','POST'));
2609 if($num_quarters == '') { $num_quarters = $this->default_int_num_quarters; }
2610 $this->t->set_var('num_quarters',$num_quarters);
2611 if($num_quarters == 1) {
2612 $this->t->set_var('lang_num_quarters','Quarter of History');
2614 $this->t->set_var('lang_num_quarters','Quarters of History');
2616 $this->t->set_var('lang_filter','Filter');
2618 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2619 $this->t->set_var('int_link_title','Hometeaching Interviews');
2621 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
2622 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
2624 $this->t->set_var('title','Hometeaching Interviews');
2626 $num_months = $num_quarters * 3 - 1;
2627 $current_month = $this->current_month;
2628 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
2629 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
2630 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
2631 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
2633 $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";
2634 $this->db->query($sql,__LINE__,__FILE__);
2636 while ($this->db->next_record()) {
2637 $districts[$i]['district'] = $this->db->f('district');
2638 $districts[$i]['name'] = $this->db->f('name');
2639 $districts[$i]['supervisor'] = $this->db->f('supervisor');
2643 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
2644 $this->db->query($sql,__LINE__,__FILE__);
2646 while ($this->db->next_record()) {
2647 $individual[$i] = $this->db->f('individual');
2648 $indiv_name[$i] = $this->db->f('name');
2649 $indiv_phone[$individual[$i]] = $this->db->f('phone');
2652 array_multisort($indiv_name, $individual);
2653 for($i=0; $i < count($individual); $i++) {
2654 $id = $individual[$i];
2655 $indivs[$id] = $indiv_name[$i];
2658 $total_companionships = 0;
2659 $this->nextmatchs->template_alternate_row_color(&$this->t);
2660 for ($i=0; $i < count($districts); $i++) {
2661 $this->t->set_var('district_number',$districts[$i]['district']);
2662 $this->t->set_var('district_name',$districts[$i]['name']);
2663 $supervisor = $districts[$i]['supervisor'];
2665 // Select all the unique companionship numbers for this district
2666 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$i]['district'];
2667 $this->db->query($sql,__LINE__,__FILE__);
2668 $j=0; $unique_companionships = '';
2669 while ($this->db->next_record()) {
2670 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
2674 $comp_width=250; $int_width=75; $table_width=$comp_width + $num_months*$int_width;
2675 $table_data=""; $num_companionships = $j; $num_indivs = 0;
2676 for($m=$num_months; $m >= 0; $m--) { $ints[$m] = 0; }
2677 for ($j=0; $j < count($unique_companionships); $j++) {
2678 // Select all the companions in each companionship
2679 $sql = "SELECT * FROM tc_companion where valid=1 and ".
2680 "companionship=". $unique_companionships[$j]['companionship'];
2681 $this->db->query($sql,__LINE__,__FILE__);
2683 $comp = $unique_companionships[$j]['companionship'];
2684 for($m=$num_months; $m >= 0; $m--) { $int_recorded[$comp][$m] = 0; }
2685 while ($this->db->next_record()) {
2686 // Get this companions information
2688 $companionship = $this->db->f('companionship');
2689 $individual = $this->db->f('individual');
2690 $name = $indivs[$individual];
2691 $phone = $indiv_phone[$individual];
2692 $link_data['menuaction'] = 'tc.tc.int_update';
2693 $link_data['companionship'] = $companionship;
2694 $link_data['interviewer'] = $supervisor;
2695 $link_data['individual'] = $individual;
2696 $link_data['name'] = $name;
2697 $link_data['interview'] = '';
2698 $link_data['interview_type'] = 'hti';
2699 $link_data['action'] = 'add';
2700 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2701 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2703 // Find out how many times Interviews were performed in the past $num_months for this individual
2704 $header_row="<th width=$comp_width><font size=-2>Companionship</th>";
2705 for($m=$num_months; $m >= 0; $m--) {
2706 $month = $current_month - $m;
2707 $year = $this->current_year;
2709 $remainder = $month;
2710 $month = 12 + $remainder;
2713 if($month < 10) { $month = "0"."$month"; }
2714 $month_start = "$year"."-"."$month"."-"."01";
2715 $month_end = "$year"."-"."$month"."-"."31";
2716 $month = "$month"."/"."$year";
2717 $sql = "SELECT * FROM tc_interview WHERE date >= '$month_start' AND date <= '$month_end' ".
2718 "AND individual=" . $individual . " AND interview_type='hti' ORDER BY date DESC";
2719 $this->db2->query($sql,__LINE__,__FILE__);
2720 $header_row .= "<th width=$int_width><font size=-2>$month</th>";
2722 if(!$total_ints[$m]) { $total_ints[$m] = 0; }
2723 if($this->db2->next_record()) {
2724 if(!$int_recorded[$companionship][$m]) {
2727 $int_recorded[$companionship][$m]=1;
2729 $link_data['menuaction'] = 'tc.tc.int_update';
2730 $link_data['companionship'] = $companionship;
2731 $link_data['interviewer'] = $this->db2->f('interviewer');
2732 $link_data['individual'] = $individual;
2733 $link_data['name'] = $name;
2734 $link_data['interview'] = $this->db2->f('interview');
2735 $link_data['action'] = 'view';
2736 $link_data['interview_type'] = 'hti';
2737 $date = $this->db2->f('date');
2738 $date_array = explode("-",$date);
2739 $month = $date_array[1];
2740 $day = $date_array[2];
2741 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2742 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2745 $table_data .= "<td> </td>";
2748 $table_data .= "</tr>";
2751 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2753 $total_companionships += $num_companionships;
2754 $stat_data = "<tr><td><b><font size=-2>$num_companionships Companionships<br>Interview Totals:</font></b></td>";
2756 // Print the hometeaching interview stats
2757 for($m=$num_months; $m >=0; $m--) {
2758 $month = $current_month - $m;
2759 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
2760 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
2761 //print "$month % $this->monthly_hometeaching_interview_stats = $month_begins <br>";
2762 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
2763 if(($month_begins) == 1) {
2766 $total += $ints[$m];
2768 $percent = ceil(($total / $num_companionships)*100);
2769 $stat_data .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
2771 $stat_data .= "</tr>";
2773 $this->t->set_var('table_width',$table_width);
2774 $this->t->set_var('header_row',$header_row);
2775 $this->t->set_var('table_data',$table_data);
2776 $this->t->set_var('stat_data',$stat_data);
2777 $this->t->fp('list','district_list',True);
2780 // Display the totals
2782 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>Interview Totals:</font></b></td>";
2783 for($m=$num_months; $m >=0; $m--) {
2784 $month = $current_month - $m;
2785 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
2786 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
2787 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
2788 if(($month_begins) == 1) {
2789 $total = $total_ints[$m];
2791 $total += $total_ints[$m];
2793 $percent = ceil(($total / $total_companionships)*100);
2794 $totals .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
2798 $this->t->set_var('totals',$totals);
2799 $this->t->pfp('out','int_view_t');
2800 $this->save_sessiondata();
2803 function int_update()
2805 $this->t->set_file(array('form' => 'int_update.tpl'));
2806 $this->t->set_block('form','interviewer_list','int_list');
2807 $this->t->set_block('form','add','addhandle');
2808 $this->t->set_block('form','edit','edithandle');
2810 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2811 $this->t->set_var('readonly','');
2812 $this->t->set_var('disabled','');
2813 $this->t->set_var('eqpresppi','');
2815 $action = get_var('action',array('GET','POST'));
2816 $companionship = get_var('companionship',array('GET','POST'));
2817 $interviewer = get_var('interviewer',array('GET','POST'));
2818 $name = get_var('name',array('GET','POST'));
2819 $interview = get_var('interview',array('GET','POST'));
2820 $individual = get_var('individual',array('GET','POST'));
2821 $date = get_var('date',array('GET','POST'));
2822 $notes = get_var('notes',array('GET','POST'));
2823 $interview_type = get_var('interview_type',array('GET','POST'));
2825 $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)";
2826 $this->db2->query($sql,__LINE__,__FILE__);
2827 while ($this->db2->next_record()) {
2828 $indiv = $this->db2->f('individual');
2829 $interviewer_name = $this->db2->f('name');
2830 if($indiv == $interviewer) {
2831 $this->t->set_var('interviewer',$indiv . ' selected');
2833 $this->t->set_var('interviewer',$indiv);
2835 $this->t->set_var('interviewer_name',$interviewer_name);
2836 $this->t->fp('int_list','interviewer_list',True);
2839 if($action == 'save') {
2840 $notes = get_var('notes',array('POST'));
2841 $this->db->query("UPDATE tc_interview set " .
2842 " interview='" . $interview . "'" .
2843 ", interviewer='" . $interviewer . "'" .
2844 ", individual='" . $individual . "'" .
2845 ", date='" . $date . "'" .
2846 ", notes=\"" . $notes . "\"" .
2847 ", interview_type='" . $interview_type . "'" .
2848 " WHERE interview=" . $interview,__LINE__,__FILE__);
2853 if($action == 'insert') {
2854 $notes = get_var('notes',array('POST'));
2855 $this->db->query("INSERT INTO tc_interview (interviewer,individual,date,notes,interview_type) " .
2856 "VALUES ('" . $interviewer . "','" . $individual . "','" .
2857 $date . "',\"" . $notes ."\",'" . $interview_type . "')",__LINE__,__FILE__);
2862 if($action == 'add') {
2863 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2864 $this->t->set_var('interview', '');
2865 $this->t->set_var('interviewer', $interviewer);
2866 $this->t->set_var('name',$name);
2867 $this->t->set_var('individual',$individual);
2868 $this->t->set_var('date','');
2869 $this->t->set_var('notes','');
2870 $this->t->set_var('interview_type',$interview_type);
2871 $this->t->set_var('lang_done','Cancel');
2872 $this->t->set_var('lang_action','Adding New Interview');
2873 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
2874 $interview . '&action=' . 'insert'));
2877 if($action == 'edit' || $action == 'view') {
2878 $sql = "SELECT * FROM tc_interview WHERE interview=" . $interview . " AND interview_type='hti'";
2879 $this->db->query($sql,__LINE__,__FILE__);
2880 $this->db->next_record();
2881 $this->t->set_var('interview',$interview);
2882 $this->t->set_var('name',$name);
2883 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2884 $this->t->set_var('individual',$this->db->f('individual'));
2885 $this->t->set_var('date',$this->db->f('date'));
2886 $this->t->set_var('notes',$this->db->f('notes'));
2887 $this->t->set_var('interview_type',$this->db->f('interview_type'));
2888 if($this->db->f('interview_type') == 'ppi') { $this->t->set_var('eqpresppi_checked','checked'); }
2891 if($action == 'edit') {
2892 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2893 $this->t->set_var('lang_done','Cancel');
2894 $this->t->set_var('lang_action','Editing Interview');
2895 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
2896 $interview . '&action=' . 'save'));
2899 if($action == 'view') {
2900 $date = $this->db->f('date');
2901 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2902 $this->t->set_var('readonly','READONLY');
2903 $this->t->set_var('disabled','DISABLED');
2904 $this->t->set_var('lang_done','Done');
2905 $this->t->set_var('lang_action','Viewing Interview');
2906 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
2907 $interview . '&action=' . 'edit'));
2910 $this->t->set_var('lang_reset','Clear Form');
2911 $this->t->set_var('lang_add','Add Interview');
2912 $this->t->set_var('lang_save','Save Changes');
2913 $this->t->set_var('edithandle','');
2914 $this->t->set_var('addhandle','');
2916 $this->t->pfp('out','form');
2918 if($action == 'view') { $this->t->set_var('lang_save','Edit Interview'); }
2919 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2920 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2922 $this->save_sessiondata();
2927 $this->t->set_file(array('vis_view_t' => 'vis_view.tpl'));
2928 $this->t->set_block('vis_view_t','visit_list','list1');
2929 $this->t->set_block('vis_view_t','family_list','list2');
2931 $this->t->set_var('lang_name','Family Name');
2932 $this->t->set_var('lang_date','Date');
2934 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2935 $this->t->set_var('vis_link_title','View Yearly Visits');
2937 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
2938 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2940 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2941 $num_years = get_var('num_years',array('GET','POST'));
2942 if($num_years == '') { $num_years = $this->default_vis_num_years; }
2943 $this->t->set_var('num_years',$num_years);
2944 if($num_years == 1) {
2945 $this->t->set_var('lang_num_years','Year of History');
2947 $this->t->set_var('lang_num_years','Years of History');
2949 $this->t->set_var('lang_filter','Filter');
2951 $year = date('Y') - $num_years + 1;
2952 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2954 $sql = "SELECT * FROM tc_visit WHERE companionship=0 and date > '$year_start' ORDER BY date DESC";
2955 $this->db->query($sql,__LINE__,__FILE__);
2956 $total_records = $this->db->num_rows();
2959 while ($this->db->next_record()) {
2960 $visit_list[$i]['visit'] = $this->db->f('visit');
2961 $visit_list[$i]['family'] = $this->db->f('family');
2962 $visit_list[$i]['date'] = $this->db->f('date');
2966 for ($i=0; $i < count($visit_list); $i++) {
2967 $this->nextmatchs->template_alternate_row_color(&$this->t);
2969 $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'";
2970 $this->db->query($sql,__LINE__,__FILE__);
2971 $this->db->next_record();
2973 $this->t->set_var('family',$visit_list[$i]['family']);
2974 $this->t->set_var('family_name',$this->db->f('name'));
2975 $this->t->set_var('date',$visit_list[$i]['date']);
2977 $link_data['menuaction'] = 'tc.tc.vis_update';
2978 $link_data['visit'] = $visit_list[$i]['visit'];
2979 $link_data['name'] = $this->db->f('name');
2980 $link_data['date'] = $visit_list[$i]['date'];
2981 $link_data['action'] = 'view';
2982 $this->t->set_var('view',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
2983 $this->t->set_var('lang_view','View');
2985 $link_data['menuaction'] = 'tc.tc.vis_update';
2986 $link_data['visit'] = $visit_list[$i]['visit'];
2987 $link_data['name'] = $this->db->f('name');
2988 $link_data['date'] = $visit_list[$i]['date'];
2989 $link_data['action'] = 'edit';
2990 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
2991 $this->t->set_var('lang_edit','Edit');
2993 $this->t->fp('list1','visit_list',True);
2996 // List the families that are available to record a visit against
2997 $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'";
2998 $this->db->query($sql,__LINE__,__FILE__);
2999 $total_records = $this->db->num_rows();
3002 while ($this->db->next_record()) {
3003 $family_names[$i] = $this->db->f('name');
3004 $family_ids[$i] = $this->db->f('family');
3006 } array_multisort($family_names, $family_ids);
3008 for ($i=0; $i < count($family_names); $i++) {
3009 $link_data['menuaction'] = 'tc.tc.vis_update';
3010 $link_data['visit'] = '';
3011 $link_data['family'] = $family_ids[$i];
3012 $link_data['action'] = 'add';
3013 $link_data['name'] = $family_names[$i];
3014 $this->t->set_var('add',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3016 $this->t->set_var('name',$family_names[$i]);
3017 if(($i+1) % 3 == 0) {
3018 $this->t->set_var('table_sep',"</td></tr><tr>");
3020 $this->t->set_var('table_sep',"</td>");
3022 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
3024 $this->t->fp('list2','family_list',True);
3027 $this->t->pfp('out','vis_view_t');
3028 $this->save_sessiondata();
3031 function vis_update()
3033 $this->t->set_file(array('form' => 'vis_update.tpl'));
3034 $this->t->set_block('form','add','addhandle');
3035 $this->t->set_block('form','edit','edithandle');
3037 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
3038 $this->t->set_var('readonly','');
3039 $this->t->set_var('disabled','');
3041 $action = get_var('action',array('GET','POST'));
3042 $visit = get_var('visit',array('GET','POST'));
3043 $family = get_var('family',array('GET','POST'));
3044 $name = get_var('name',array('GET','POST'));
3045 $date = get_var('date',array('GET','POST'));
3046 $notes = get_var('notes',array('GET','POST'));
3049 if($action == 'save') {
3050 $notes = get_var('notes',array('POST'));
3051 $this->db->query("UPDATE tc_visit set " .
3052 " date='" . $date . "'" .
3053 ", notes=\"" . $notes . "\"" .
3054 " WHERE visit=" . $visit,__LINE__,__FILE__);
3059 if($action == 'insert') {
3060 $notes = get_var('notes',array('POST'));
3061 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes) " .
3062 "VALUES ('" . $family . "','" . $companionship . "','" .
3063 $date . "',\"" . $notes . "\")",__LINE__,__FILE__);
3068 if($action == 'add') {
3069 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
3070 $this->t->set_var('family', $family);
3071 $this->t->set_var('visit', '');
3072 $this->t->set_var('name', $name);
3073 $this->t->set_var('date','');
3074 $this->t->set_var('notes','');
3075 $this->t->set_var('lang_done','Cancel');
3076 $this->t->set_var('lang_action','Adding New Visit');
3077 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&family=' .
3078 $family . '&action=' . 'insert'));
3081 if($action == 'edit' || $action == 'view') {
3082 $sql = "SELECT * FROM tc_visit WHERE visit=".$visit;
3083 $this->db->query($sql,__LINE__,__FILE__);
3084 $this->db->next_record();
3085 $this->t->set_var('visit',$visit);
3086 $this->t->set_var('name',$name);
3087 $this->t->set_var('family', $family);
3088 $this->t->set_var('date',$this->db->f('date'));
3089 $this->t->set_var('notes',$this->db->f('notes'));
3092 if($action == 'edit') {
3093 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
3094 $this->t->set_var('lang_done','Cancel');
3095 $this->t->set_var('lang_action','Editing Visit');
3096 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit=' .
3097 $visit . '&action=' . 'save'));
3100 if($action == 'view') {
3101 $date = $this->db->f('date');
3102 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
3103 $this->t->set_var('readonly','READONLY');
3104 $this->t->set_var('disabled','DISABLED');
3105 $this->t->set_var('lang_done','Done');
3106 $this->t->set_var('lang_action','Viewing Visit');
3107 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit=' .
3108 $visit . '&action=' . 'edit'));
3111 $this->t->set_var('lang_reset','Clear Form');
3112 $this->t->set_var('lang_add','Add Visit');
3113 $this->t->set_var('lang_save','Save Changes');
3114 $this->t->set_var('edithandle','');
3115 $this->t->set_var('addhandle','');
3117 $this->t->pfp('out','form');
3119 if($action == 'view') { $this->t->set_var('lang_save','Edit Visit'); }
3120 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
3121 if($action == 'add') { $this->t->pfp('addhandle','add'); }
3123 $this->save_sessiondata();
3128 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3129 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3130 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3132 $this->t->set_file(array('att_view_t' => 'att_view.tpl'));
3133 $this->t->set_block('att_view_t','act_list','list');
3135 $this->t->set_block('att_view_t','month_list','list1');
3136 $this->t->set_block('att_view_t','header_list','list2');
3137 $this->t->set_block('att_view_t','individual_list','list3');
3139 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3140 $num_quarters = get_var('num_quarters',array('GET','POST'));
3141 if($num_quarters == '') { $num_quarters = $this->default_att_num_quarters; }
3142 $this->t->set_var('num_quarters',$num_quarters);
3143 $this->t->set_var('lang_filter','Filter');
3144 if($num_quarters == 1) {
3145 $this->t->set_var('lang_num_quarters','Quarter of History');
3147 $this->t->set_var('lang_num_quarters','Quarters of History');
3150 $num_months = $num_quarters * 3;
3151 $current_month = $this->current_month;
3152 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
3153 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
3154 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
3155 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
3157 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
3158 $this->db->query($sql,__LINE__,__FILE__);
3160 while ($this->db->next_record()) {
3161 $individual_name[$i] = $this->db->f('name');
3162 $individual[$i] = $this->db->f('individual');
3165 array_multisort($individual_name, $individual);
3167 // Create a list of sunday dates for a window of 3 months back and current month
3171 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, ($current_month-$num_months)+1, 1, date("y")));
3172 $last_date = explode("-",$sunday_list[0]['date']);
3173 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3174 $time_limit = mktime(0, 0, 0, $current_month, 31, date("y"));
3175 while($last_time < $time_limit) {
3176 $day = date("w",$last_time);
3177 if(date("w",$last_time) == 0) {
3178 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3179 $last_date = explode("-",$sunday_list[$i]['date']);
3180 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3181 $sunday_list[$i]['day'] = $last_date[2];
3182 $sunday_list[$i]['month'] = date("M",$last_time);
3183 $sunday_list[$i]['year'] = $last_date[0];
3185 $last_date = $sunday_list[$i]['date'];
3187 $last_time += 90000;
3188 if($found_sunday) { $i++; $found_sunday=0; }
3191 $total_individuals = count($individual);
3192 $old_month=$sunday_list[0]['month']; $span=0;
3193 for ($i=0; $i < count($sunday_list); $i++) {
3194 $date = $sunday_list[$i]['date'];
3195 $this->t->set_var('date',$sunday_list[$i]['date']);
3196 $this->t->set_var('day',$sunday_list[$i]['day']);
3197 if(($old_month != $sunday_list[$i]['month']) || $i == count($sunday_list)-1) {
3198 if($i == count($sunday_list)-1) { $span++; }
3199 $cur_month = $sunday_list[$i]['month'];
3200 $old_month = $sunday_list[$i]['month'];
3201 $link_data['menuaction'] = 'tc.tc.att_update';
3202 $link_data['month'] = $sunday_list[$i-1]['month'];
3203 $link_data['year'] = $sunday_list[$i-1]['year'];
3204 $link_data['action'] = 'update_month';
3205 $cur_month = $sunday_list[$i-1]['month'];
3206 $cur_year = $sunday_list[$i-1]['year'];
3207 $header_row .= "<th><font size=-3>$cur_month $cur_year</font></th>";
3208 $this->t->set_var('update_month',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3209 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3210 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3211 $this->t->set_var('span',$span); $span=0;
3212 $this->t->fp('list1','month_list',True);
3216 $this->t->set_var('total_individuals',$total_individuals);
3217 $this->t->set_var('header_row',$header_row);
3219 $individual_width=200; $att_width=25; $total_width=$individual_width;
3220 for ($i=0; $i < count($sunday_list); $i++) {
3221 $link_data['menuaction'] = 'tc.tc.att_update';
3222 $link_data['month'] = $sunday_list[$i]['month'];
3223 $link_data['year'] = $sunday_list[$i]['year'];
3224 $link_data['day'] = $sunday_list[$i]['day'];
3225 $link_data['date'] = $sunday_list[$i]['date'];
3226 $link_data['action'] = 'update_day';
3227 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3228 $this->t->set_var('date',$sunday_list[$i]['date']);
3229 $this->t->set_var('day',$sunday_list[$i]['day']);
3230 $this->t->set_var('month',$sunday_list[$i]['month']);
3231 $this->t->set_var('year',$sunday_list[$i]['year']);
3232 $this->t->fp('list2','header_list',True);
3233 $total_width += $att_width;
3234 $attendance[$monthnum[$sunday_list[$i]['month']]]=0;
3237 for ($i=0; $i < count($individual); $i++) {
3239 $this->nextmatchs->template_alternate_row_color(&$this->t);
3240 $this->t->set_var('individual_name',$individual_name[$i]);
3241 #print "checking for individual: " . $individual[$i] . "<br>";
3242 for ($j=0; $j < count($sunday_list); $j++) {
3243 #print "checking for date: " . $sunday_list[$j]['date'] . "<br>";
3244 #print "SELECT * FROM tc_attendance WHERE date='"
3245 # . $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i] . "<br>";
3246 $sql = "SELECT * FROM tc_attendance WHERE date='" .
3247 $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i];
3248 $this->db->query($sql,__LINE__,__FILE__);
3249 if($this->db->next_record()) {
3250 $cur_month = $sunday_list[$j]['month'];
3251 if($attended[$i][$cur_month] != 1) {
3252 $attended[$i][$cur_month]=1;
3253 $attendance[$monthnum[$cur_month]]++;
3255 $att_table .= '<td align=center><img src="images/checkmark.gif"></td>';
3257 $att_table .= '<td> </td>';
3260 $this->t->set_var('att_table',$att_table);
3261 $this->t->fp('list3','individual_list',True);
3263 $this->t->set_var('total_width',$total_width);
3264 $this->t->set_var('individual_width',$individual_width);
3265 $this->t->set_var('att_width',$att_width);
3267 # Now calculate attendance for these months
3268 $attendance_str = "";
3269 $nonattendance_str = "";
3270 $aveattendance_str = "";
3271 $avenonattendance_str = "";
3273 $ave_total_attended=0;
3275 foreach($attendance as $att => $value) {
3276 $total_attended = $attendance[$att];
3277 $ave_total_attended += $attendance[$att]; $num_months++;
3278 $percent = ceil(($total_attended / $total_individuals)*100);
3279 $attendance_str.="<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3280 $total_nonattended = $total_individuals - $total_attended;
3281 $percent = ceil(($total_nonattended / $total_individuals)*100);
3282 $nonattendance_str.="<td align=center><font size=-2><b>$total_nonattended ($percent%)</b></font></td>";
3284 $total_attended = ceil(($ave_total_attended / $num_months));
3285 $percent = ceil(($total_attended / $total_individuals)*100);
3286 $aveattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3287 $total_attended = $total_individuals - ceil(($ave_total_attended / $num_months));
3288 $percent = ceil(($total_attended / $total_individuals)*100);
3289 $avenonattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3292 $this->t->set_var('attendance',$attendance_str);
3293 $this->t->set_var('aveattendance',$aveattendance_str);
3294 $this->t->set_var('nonattendance',$nonattendance_str);
3295 $this->t->set_var('avenonattendance',$avenonattendance_str);
3297 $this->t->pfp('out','att_view_t');
3298 $this->save_sessiondata();
3301 function att_update()
3303 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3304 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3305 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3307 $this->t->set_file(array('form' => 'att_update.tpl'));
3308 $this->t->set_block('form','edit','edithandle');
3310 $this->t->set_block('form','month_list','list1');
3311 $this->t->set_block('form','header_list','list2');
3312 $this->t->set_block('form','individual_list','list3');
3314 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3316 $action = get_var('action',array('GET','POST'));
3317 $month = get_var('month',array('GET','POST'));
3318 $year = get_var('year',array('GET','POST'));
3319 $day = get_var('day',array('GET','POST'));
3320 $date = get_var('date',array('GET','POST'));
3322 if($action == 'save_month' || $action == 'save_day') {
3323 $new_data = get_var('individuals_attended',array('POST'));
3324 $month = $monthnum[$month]; if($month < 10) { $month = "0" . $month; }
3326 if($action == 'save_month') {
3327 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-%'",__LINE__,__FILE__);
3330 if($action == 'save_day') {
3331 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-".$day."'",__LINE__,__FILE__);
3334 foreach ($new_data as $data) {
3335 $data_array = explode("-",$data);
3336 $indiv = $data_array[0];
3337 $date = "$data_array[1]-$data_array[2]-$data_array[3]";
3338 $this->db->query("INSERT INTO tc_attendance (individual,date) " .
3339 "VALUES (" . $indiv . ",'". $date . "')",__LINE__,__FILE__);
3346 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
3347 $this->db->query($sql,__LINE__,__FILE__);
3349 while ($this->db->next_record()) {
3350 $indiv_name[$i] = $this->db->f('name');
3351 $individual[$i] = $this->db->f('individual');
3352 $indiv_attending[$individual[$i]] = $this->db->f('attending');
3355 array_multisort($indiv_name, $individual);
3357 if($action == 'update_month') {
3358 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_month'));
3362 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], 1, $year));
3363 $last_date = explode("-",$sunday_list[0]['date']);
3364 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3365 $time_limit = mktime(0, 0, 0, $monthnum[$month], 31, $year);
3366 while($last_time <= $time_limit) {
3367 $day = date("w",$last_time);
3368 if(date("w",$last_time) == 0) {
3369 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3370 $last_date = explode("-",$sunday_list[$i]['date']);
3371 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3372 $sunday_list[$i]['day'] = $last_date[2];
3373 $sunday_list[$i]['month'] = date("M",$last_time);
3374 $sunday_list[$i]['year'] = $last_date[0];
3377 $last_time += 90000;
3378 if($found_sunday) { $i++; $found_sunday=0; }
3381 $this->t->set_var('span', $i);
3382 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3383 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3384 $this->t->fp('list1','month_list',True);
3385 $indiv_width=200; $att_width=25; $total_width=$indiv_width;
3386 for ($i=0; $i < count($sunday_list); $i++) {
3387 $link_data['menuaction'] = 'tc.tc.att_update';
3388 $link_data['month'] = $sunday_list[$i]['month'];
3389 $link_data['year'] = $sunday_list[$i]['year'];
3390 $link_data['day'] = $sunday_list[$i]['day'];
3391 $link_data['date'] = $sunday_list[$i]['date'];
3392 $link_data['action'] = 'update_day';
3393 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3394 $this->t->set_var('date',$sunday_list[$i]['date']);
3395 $this->t->set_var('day',$sunday_list[$i]['day']);
3396 $this->t->set_var('month',$sunday_list[$i]['month']);
3397 $this->t->set_var('year',$sunday_list[$i]['year']);
3398 $this->t->fp('list2','header_list',True);
3399 $total_width += $att_width;
3403 if($action == 'update_day') {
3404 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_day'));
3405 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], $day, $year));
3406 $this->t->set_var('month',$month);
3407 $this->t->set_var('year',$year);
3408 $this->t->fp('list1','month_list',True);
3409 $this->t->set_var('date',$date);
3410 $this->t->set_var('day',$day);
3411 $this->t->set_var('month',$month);
3412 $this->t->set_var('year',$year);
3413 $this->t->fp('list2','header_list',True);
3416 for ($i=0; $i < count($individual); $i++) {
3418 $this->nextmatchs->template_alternate_row_color(&$this->t);
3419 $this->t->set_var('individual_name',$indiv_name[$i]);
3420 for ($j=0; $j < count($sunday_list); $j++) {
3421 $sql = "SELECT * FROM tc_attendance WHERE date='" .
3422 $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i];
3423 $this->db->query($sql,__LINE__,__FILE__);
3424 $value = $individual[$i] . "-" . $sunday_list[$j]['date'];
3425 if($this->db->next_record()) {
3426 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'" checked></td>';
3427 } else if($indiv_attending[$individual[$i]] == 1) {
3428 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'" checked></td>';
3430 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'"></td>';
3433 $this->t->set_var('att_table',$att_table);
3434 $this->t->fp('list3','individual_list',True);
3437 $this->t->set_var('lang_done', 'Cancel');
3438 $this->t->set_var('lang_reset','Clear Form');
3439 $this->t->set_var('lang_save','Save Changes');
3441 $this->t->pfp('out','form');
3442 $this->t->pfp('addhandle','edit');
3444 $this->save_sessiondata();
3449 $this->t->set_file(array('dir_view_t' => 'dir_view.tpl'));
3450 $this->t->set_block('dir_view_t','dir_list','list');
3452 $sql = "SELECT * FROM tc_individual where valid=1 and hh_position='Head of Household' ORDER BY name ASC";
3453 $this->db->query($sql,__LINE__,__FILE__);
3455 while ($this->db->next_record()) {
3456 $parent[$i]['id'] = $this->db->f('individual');
3457 $parent[$i]['name'] = $this->db->f('name');
3458 $parent[$i]['phone'] = $this->db->f('phone');
3459 $parent[$i]['address'] = $this->db->f('address');
3463 for ($i=0; $i < count($parent); $i++) {
3464 $name = $parent[$i]['name'];
3465 $phone = $parent[$i]['phone'];
3466 $address = $parent[$i]['address'];
3467 $this->t->set_var('name', $name);
3468 $this->t->set_var('address', $address);
3469 $this->t->set_var('phone', $phone);
3470 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3471 $this->t->set_var('tr_color',$tr_color);
3472 $this->t->fp('list','dir_list',True);
3473 //print "$phone $name $address<br>";
3475 $this->t->pfp('out','dir_view_t');
3476 $this->save_sessiondata();
3481 $this->t->set_file(array('org_view_t' => 'org_view.tpl'));
3482 $this->t->set_block('org_view_t','calling_list','list1');
3483 $this->t->set_block('org_view_t','org_list','list2');
3485 # Display a list ordered alphabetically
3486 $sql = "SELECT * FROM tc_calling AS tc JOIN tc_individual AS ti WHERE tc.individual=ti.individual ORDER BY name ASC";
3487 $this->db->query($sql,__LINE__,__FILE__);
3489 while ($this->db->next_record()) {
3490 $calling[$i]['name'] = $this->db->f('name');
3491 $calling[$i]['position'] = $this->db->f('position');
3492 $calling[$i]['sustained'] = $this->db->f('sustained');
3493 $calling[$i]['organization'] = $this->db->f('organization');
3496 for ($i=0; $i < count($calling); $i++) {
3497 $name = $calling[$i]['name'];
3498 $position = $calling[$i]['position'];
3499 $sustained = $calling[$i]['sustained'];
3500 $organization = $calling[$i]['organization'];
3501 $this->t->set_var('name', $name);
3502 $this->t->set_var('position', $position);
3503 $this->t->set_var('sustained', $sustained);
3504 $this->t->set_var('organization', $organization);
3505 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3506 $this->t->set_var('tr_color',$tr_color);
3507 $this->t->fp('list1','calling_list',True);
3510 # Display a list ordered by organization
3511 $sql = "SELECT * FROM tc_calling AS tc JOIN tc_individual AS ti where tc.individual=ti.individual ORDER BY organization ASC";
3512 $this->db->query($sql,__LINE__,__FILE__);
3514 while ($this->db->next_record()) {
3515 $calling[$i]['name'] = $this->db->f('name');
3516 $calling[$i]['position'] = $this->db->f('position');
3517 $calling[$i]['sustained'] = $this->db->f('sustained');
3518 $calling[$i]['organization'] = $this->db->f('organization');
3521 for ($i=0; $i < count($calling); $i++) {
3522 $name = $calling[$i]['name'];
3523 $position = $calling[$i]['position'];
3524 $sustained = $calling[$i]['sustained'];
3525 $organization = $calling[$i]['organization'];
3526 $this->t->set_var('name', $name);
3527 $this->t->set_var('position', $position);
3528 $this->t->set_var('sustained', $sustained);
3529 $this->t->set_var('organization', $organization);
3530 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3531 $this->t->set_var('tr_color',$tr_color);
3532 $this->t->fp('list2','org_list',True);
3535 $this->t->pfp('out','org_view_t');
3536 $this->save_sessiondata();
3541 $this->t->set_file(array('sched_t' => 'schedule.tpl'));
3542 $this->t->set_block('sched_t','presidency_list','list');
3544 $action = get_var('action',array('GET','POST'));
3546 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule&action=save'));
3547 $this->t->set_var('title','Scheduling Tool');
3549 $this->t->set_var('lang_save','Save Schedule');
3550 $this->t->set_var('lang_reset','Cancel');
3552 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
3553 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
3555 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
3556 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
3558 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
3559 $this->t->set_var('schedule_ppi_link_title','Schedule ' . $this->ppi_frequency_label . ' PPIs');
3561 $date_width=160; $time_width=220; $indiv_width=170; $family_width=180; $location_width=100;
3562 $table_width=$date_width + $time_width + $indiv_width + $family_width + $location_width;
3563 $header_row = "<th width=$date_width><font size=-2>Date</th>";
3564 $header_row.= "<th width=$time_width><font size=-2>Time</th>";
3565 $header_row.= "<th width=$indiv_width><font size=-2>Individual</th>";
3566 $header_row.= "<th width=$family_width><font size=-2>Family</th>";
3567 $header_row.= "<th width=$location_width><font size=-2>Location</th>";
3570 $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";
3571 $this->db->query($sql,__LINE__,__FILE__);
3573 while ($this->db->next_record()) {
3574 $presidency_data[$i]['id'] = $this->db->f('presidency');
3575 $presidency_data[$i]['name'] = $this->db->f('name');
3576 $presidency_data[$i]['indiv'] = $this->db->f('individual');
3577 $presidency2name[$presidency_data[$i]['id']] = $presidency_data[$i]['name'];
3578 $presidency2indiv[$presidency_data[$i]['id']] = $presidency_data[$i]['indiv'];
3582 $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";
3583 $this->db->query($sql,__LINE__,__FILE__);
3585 while ($this->db->next_record()) {
3586 $family_id[$i] = $this->db->f('family');
3587 $family_name[$i] = $this->db->f('name');
3588 $familyid2name[$family_id[$i]] = $family_name[$i];
3589 $familyid2address[$family_id[$i]] = $this->db->f('address');
3592 array_multisort($family_name, $family_id);
3594 if($action == 'save') {
3595 $new_data = get_var('sched',array('POST'));
3596 foreach ($new_data as $presidency_array) {
3597 foreach ($presidency_array as $entry) {
3598 $presidency = $entry['presidency'];
3599 $appointment = $entry['appointment'];
3600 $location = $entry['location'];
3601 $date = $entry['date'];
3602 $hour = $entry['hour'];
3603 $minute = $entry['minute'];
3605 $indiv = $entry['individual'];
3606 $family = $entry['family'];
3607 $location = $entry['location'];
3608 if($pm) { $hour = $hour + 12; }
3609 $time = $hour.':'.$minute.':'.'00';
3612 // Zero out family or individual if they are invalid
3613 if($indiv == "") { $indiv=0; }
3614 if($family == "") { $family=0; }
3616 // Update our location
3617 if($location == "") {
3619 $family_name_array = explode(",", $familyid2name[$family]);
3620 $family_last_name = $family_name_array[0];
3621 $family_address = $familyid2address[$family];
3622 $location = "$family_last_name"." home ($family_address)";
3623 } else if($indiv > 0) {
3624 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
3625 $supervisor_last_name = $supervisor_name_array[0];
3626 #print "presidency2indiv: $presidency $presidency2indiv[$presidency]<br>";
3627 $sql = "SELECT * FROM tc_individual where individual='$presidency2indiv[$presidency]'";
3628 $this->db2->query($sql,__LINE__,__FILE__);
3629 if($this->db2->next_record()) {
3630 $supervisor_address = $this->db2->f('address');
3632 $location = "$supervisor_last_name"." home ($supervisor_address)";
3636 // Zero out the family or individual if date = NULL
3643 if(($indiv == 0) && ($family == 0)) { $location = ""; }
3645 // Update an existing appointment
3646 if($appointment < $this->max_appointments)
3648 //Only perform a database update if we have made a change to this appointment
3649 $sql = "SELECT * FROM tc_appointment where " .
3650 "appointment='$appointment'" .
3651 " and presidency='$presidency'" .
3652 " and individual='$indiv'" .
3653 " and family='$family'" .
3654 " and date='$date'" .
3655 " and time='$time'" .
3656 " and location='$location'";
3657 $this->db->query($sql,__LINE__,__FILE__);
3658 if(!$this->db->next_record()) {
3659 $old_date = $this->db->f('date');
3660 $old_time = $this->db->f('time');
3661 $this->db2->query("UPDATE tc_appointment set" .
3662 " family=" . $family .
3663 " ,individual=" . $indiv .
3664 " ,date='" . $date . "'" .
3665 " ,time='" . $time . "'" .
3666 " ,location='" . $location . "'" .
3667 " ,presidency='" . $presidency . "'" .
3668 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
3670 // Email the appointment
3671 $this->email_appt($appointment);
3675 // Add a new appointment
3676 else if(($appointment >= $this->max_appointments) && ($date != "") && ($time != ""))
3678 //print "adding entry: appt=$appointment date: $date time: $time individual: $indiv family: $family<br>";
3679 $this->db2->query("INSERT INTO tc_appointment (appointment,presidency,family,individual,date,time,location,uid) " .
3680 "VALUES (NULL,'" . $presidency . "','" . $family . "','" . $indiv . "','" .
3681 $date . "','" . $time . "','" . $location . "','" . $uid ."')",__LINE__,__FILE__);
3683 // Now reselect this entry from the database to see if we need
3684 // to send an appointment out for it.
3685 $sql = "SELECT * FROM tc_appointment where " .
3686 "individual='$indiv'" .
3687 " and family='$family'" .
3688 " and presidency='$presidency'" .
3689 " and date='$date'" .
3690 " and time='$time'" .
3692 " and location='$location'";
3693 $this->db3->query($sql,__LINE__,__FILE__);
3694 if($this->db3->next_record()) {
3695 // Email the appointment if warranted
3696 if(($date != "") && ($time != "") && (($indiv > 0) || $family > 0)) {
3697 $this->email_appt($this->db3->f('appointment'));
3704 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule');
3705 //Header('Location: ' . $take_me_to_url);
3708 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY individual ASC";
3709 $this->db->query($sql,__LINE__,__FILE__);
3711 while ($this->db->next_record()) {
3712 $individual[$i] = $this->db->f('individual');
3713 $indiv_name[$i] = $this->db->f('name');
3714 $indiv_phone[$individual[$i]] = $this->db->f('phone');
3717 array_multisort($indiv_name, $individual);
3719 for ($i=0; $i < count($presidency_data); $i++) {
3720 $presidency = $presidency_data[$i]['id'];
3721 $interviewer = $presidency_data[$i]['individual'];
3722 $name = $presidency_data[$i]['name'];
3723 $this->t->set_var('presidency_name',$name);
3726 // query the database for all the appointments
3727 $sql = "SELECT * FROM tc_appointment where presidency=$presidency and date>=CURDATE() ORDER BY date ASC, time ASC";
3728 $this->db->query($sql,__LINE__,__FILE__);
3730 // Prefill any existing appointment slots
3731 while ($this->db->next_record()) {
3732 $appointment = $this->db->f('appointment');
3733 $indiv = $this->db->f('individual');
3734 $family = $this->db->f('family');
3735 $location = $this->db->f('location');
3737 if($location == "") {
3739 $family_name_array = explode(",", $familyid2name[$family]);
3740 $family_last_name = $family_name_array[0];
3741 $family_address = $familyid2address[$family];
3742 $location = "$family_last_name"." home ($family_address)";
3743 } else if($indiv > 0) {
3744 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
3745 $supervisor_last_name = $supervisor_name_array[0];
3746 $sql = "SELECT * FROM tc_individual where individual='$presidency2indiv[$presidency]'";
3747 $this->db2->query($sql,__LINE__,__FILE__);
3748 if($this->db2->next_record()) {
3749 $supervisor_address = $this->db2->f('address');
3751 $location = "$supervisor_last_name"." home ($supervisor_address)";
3755 $date = $this->db->f('date');
3756 $date_array = explode("-",$date);
3757 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
3758 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
3760 $time = $this->db->f('time');
3761 $time_array = explode(":",$time);
3762 $hour = $time_array[0];
3763 $minute = $time_array[1];
3765 if($hour > 12) { $pm=1; $hour = $hour - 12; }
3766 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
3768 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3771 $table_data.= '<td align=left>';
3772 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]',$date,'','','','','',$this->cal_options);
3773 $table_data.= '</td>';
3775 // Hour & Minutes selection
3776 $table_data.= "<td align=center>";
3777 $table_data .= $this->get_time_selection_form($hour, $minute, $pm, $presidency, $appointment);
3778 $table_data.= "</td>";
3780 // individual drop down list (for PPIs)
3781 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][individual] STYLE="font-size : 8pt">';
3782 $table_data.= '<option value=0></option>';
3783 for ($j=0; $j < count($individual); $j++) {
3784 $id = $individual[$j];
3785 $name = $indiv_name[$j];
3786 if($individual[$j] == $indiv) {
3787 $selected[$id] = 'selected="selected"';
3789 $selected[$id] = '';
3791 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
3793 $table_data.='</select></td>';
3795 // Family drop down list (for Visits)
3796 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family] STYLE="font-size : 8pt">';
3797 $table_data.= '<option value=0></option>';
3798 for ($j=0; $j < count($individual); $j++) {
3799 $id = $family_id[$j];
3800 $name = $family_name[$j];
3801 if($family_id[$j] == $family) {
3802 $selected[$id] = 'selected="selected"';
3804 $selected[$id] = '';
3806 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
3808 $table_data.='</select></td>';
3810 // Location text box
3811 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
3812 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="'.$location.'" STYLE="font-size : 8pt">';
3814 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3815 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3817 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3818 $this->t->set_var('tr_color',$tr_color);
3821 // Create blank appointment slot
3822 for ($b=0; $b < 4; $b++) {
3823 $appointment = $this->max_appointments + $b;
3824 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3827 $table_data.= '<td align=left>';
3828 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]','','','','','','',$this->cal_options);
3829 $table_data.= '</td>';
3832 $table_data.= "<td align=center>";
3833 $table_data .= $this->get_time_selection_form(0, 0, 0, $presidency, $appointment);
3834 $table_data.= "</td>";
3836 // individual drop down list
3837 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][individual] STYLE="font-size : 8pt">';
3838 $table_data.= '<option value=0></option>';
3839 for ($j=0; $j < count($individual); $j++) {
3840 $id = $individual[$j];
3841 $name = $indiv_name[$j];
3842 $table_data.= '<option value='.$id.'>'.$name.'</option>';
3844 $table_data.='</select></td>';
3846 // Family drop down list
3847 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family] STYLE="font-size : 8pt">';
3848 $table_data.= '<option value=0></option>';
3849 for ($j=0; $j < count($individual); $j++) {
3850 $id = $family_id[$j];
3851 $name = $family_name[$j];
3852 $table_data.= '<option value='.$id.'>'.$name.' Family</option>';
3854 $table_data.='</select></td>';
3856 // Location text box
3857 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
3858 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="" STYLE="font-size : 8pt">';
3860 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3861 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3863 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3864 $this->t->set_var('tr_color',$tr_color);
3867 $this->t->set_var('table_data',$table_data);
3868 $this->t->set_var('header_row',$header_row);
3869 $this->t->set_var('table_width',$table_width);
3870 $this->t->fp('list','presidency_list',True);
3873 $this->t->pfp('out','sched_t');
3874 $this->save_sessiondata();
3879 $this->t->set_file(array('email_t' => 'email.tpl'));
3880 $this->t->set_block('email_t','individual_list','list');
3882 $action = get_var('action',array('GET','POST'));
3884 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email'));
3885 $this->t->set_var('title','Email Tool');
3887 $this->t->set_var('lang_email','Send Email');
3888 $this->t->set_var('lang_reset','Cancel');
3890 $this->t->set_var('email_member_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=member'));
3891 $this->t->set_var('email_member_link_title','Email Quorum Member');
3893 $this->t->set_var('email_quorum_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=quorum'));
3894 $this->t->set_var('email_quorum_link_title','Email Quorum');
3896 $this->t->set_var('email_reminder_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=reminder'));
3897 $this->t->set_var('email_reminder_link_title','Email Reminders');
3899 $this->t->set_var('email_edit_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=edit'));
3900 $this->t->set_var('email_edit_link_title','Edit Email Addresses');
3903 $this->t->set_var('table_width',$table_width);
3905 $this->t->pfp('out','email_t');
3906 $this->save_sessiondata();
3911 $this->t->set_file(array('admin_t' => 'admin.tpl'));
3912 $this->t->set_block('admin_t','upload','uploadhandle');
3913 $this->t->set_block('admin_t','admin','adminhandle');
3914 $this->t->set_block('admin_t','cmd','cmdhandle');
3915 $this->t->set_block('admin_t','presidency','presidencyhandle');
3917 $this->t->set_var('upload_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=upload'));
3918 $this->t->set_var('presidency_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=presidency'));
3920 $action = get_var('action',array('GET','POST'));
3922 $this->t->pfp('out','admin_t');
3924 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY individual ASC";
3925 $this->db->query($sql,__LINE__,__FILE__);
3927 while ($this->db->next_record()) {
3928 $individual[$i] = $this->db->f('individual');
3929 $indiv_name[$i] = $this->db->f('name');
3930 $indiv2name[$individual[$i]] = $indiv_name[$i];
3933 array_multisort($indiv_name, $individual);
3935 if($action == 'upload') {
3936 $target_path = $this->upload_target_path . '/' . basename( $_FILES['uploadedfile']['name']);
3938 if(($_FILES['uploadedfile']['type'] == "application/zip") ||
3939 ($_FILES['uploadedfile']['type'] == "application/x-zip-compressed") ||
3940 ($_FILES['uploadedfile']['type'] == "application/x-zip") ||
3941 ($_FILES['uploadedfile']['type'] == "application/octet-stream")) {
3943 if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
3944 $uploadstatus = "<b><font color=red> -E- Unable to move the uploaded file to ";
3945 $uploadstatus.= "the target path (check the path and permissions) of: $target_path</font></b>";
3946 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
3947 $uploadstatus.= "Tmp Filename : " . $_FILES['uploadedfile']['tmp_name'] . "<br>";
3948 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
3949 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
3950 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
3951 $uploadstatus.= "Error : " . $_FILES['uploadedfile']['error'] . "<br>";
3952 $this->t->set_var('uploadstatus',$uploadstatus);
3953 $this->t->pfp('uploadhandle','upload',True);
3957 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
3958 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
3959 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
3960 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
3961 $this->t->set_var('uploadstatus',$uploadstatus);
3962 $this->t->pfp('uploadhandle','upload');
3963 $this->t->set_var('uploadhandle','');
3964 print "<table border=1 width=80%><tr><td>\n<pre>";
3966 # make a directory for this data to be stored in
3967 $date="data_" . date("Y_m_d");
3968 $data_dir = $this->upload_target_path . '/' . $date;
3969 print "-> Making the data directory: $date<br>\n";
3970 exec('mkdir -p ' . $data_dir . ' 2>&1', $result, $return_code);
3971 if($return_code != 0) {
3972 print implode('\n',$result) . "<br>";
3973 print "<b><font color=red>";
3974 print "-E- Unable to create the data directory. Aborting import.";
3975 print "</font></b>";
3979 # move the file uploaded into this directory
3980 print "-> Moving the uploaded file into the data dir<br>\n";
3981 exec('mv ' . $target_path . ' ' . $data_dir . '/' . ' 2>&1', $result, $return_code);
3982 if($return_code != 0) {
3983 print implode('\n',$result) . "<br>";
3984 print "<b><font color=red>";
3985 print "-E- Unable to move the uploaded file into the data dir. Aborting import.";
3986 print "</font></b>";
3990 # unzip the data into this directory
3991 print "-> Unzipping the data<br>\n";
3992 exec($this->unzip_path .' -u '. $data_dir . '/*.zip -d ' . $data_dir . ' 2>&1', $result, $return_code);
3993 if($return_code != 0) {
3994 print implode('\n',$result) . "<br>";
3995 print "<b><font color=red>";
3996 print "-E- Unable to unzip the uploaded file into the data dir: $data_dir. Aborting import.";
3997 print "</font></b>";
4000 exec('mv ' . $data_dir . '/*/* '. $data_dir . ' 2>&1', $result, $return_code);
4002 # update the data_latest link to point to this new directory
4003 print "-> Updating the latest data dir link<br>\n";
4004 $data_latest = $this->upload_target_path . '/data_latest';
4005 exec('rm ' . $data_latest. '; ln -s ' . $data_dir .' '. $data_latest .' 2>&1', $result, $return_code);
4006 if($return_code != 0) {
4007 print implode('\n',$result) . "<br>";
4008 print "<b><font color=red>";
4009 print "-E- Unable to update the data latest link. Aborting import.";
4010 print "</font></b>";
4014 # run the import perl script to encorporate it into the DB
4015 ob_start('ob_logstdout', 2);
4016 print "-> Importing the data into the database<br>\n";
4017 ob_flush(); flush(); sleep(1);
4018 $import_log = $this->upload_target_path . '/import.log';
4019 $data_log = $this->upload_target_path . '/data.log';
4020 $import_cmd = $this->script_path . '/import_ward_data ' . $data_latest . ' 2>&1 | tee ' . $import_log;
4021 $parse_cmd = $this->script_path . '/parse_ward_data -v ' . $data_latest . ' > ' . $data_log . '2>&1';
4022 #print "import_cmd: $import_cmd<br>";
4023 #print "parse_cmd: $parse_cmd<br>";
4024 ob_start('ob_logstdout', 2);
4025 passthru($import_cmd);
4026 passthru($parse_cmd);
4027 ob_flush(); flush(); sleep(1);
4029 # fix the permissions of the data dir
4030 exec('chmod -R o-rwx ' . $data_dir, $result, $return_code);
4032 $this->t->pfp('cmdhandle','cmd');
4033 print "</pre></td></tr></table>";
4034 } else if(($_FILES['uploadedfile']['type'] != "application/zip") &&
4035 ($_FILES['uploadedfile']['type'] != "application/x-zip-compressed") &&
4036 ($_FILES['uploadedfile']['type'] != "application/x-zip") &&
4037 ($_FILES['uploadedfile']['type'] != "application/octet-stream")) {
4038 $uploadstatus = "<b><font color=red>The file format must be a .zip file, please try again! </font></b>";
4039 $uploadstatus.= "<br><br><b>Detected file format: " . $_FILES['uploadedfile']['type'] . "</b>";
4040 $this->t->set_var('uploadstatus',$uploadstatus);
4041 $this->t->pfp('uploadhandle','upload',True);
4043 $uploadstatus = "<b><font color=red> There was an error (" . $_FILES['uploadedfile']['error'];
4044 $uploadstatus.= ") uploading the file, please try again! </font></b>";
4045 $this->t->set_var('uploadstatus',$uploadstatus);
4046 $this->t->pfp('uploadhandle','upload',True);
4048 } else if($action == "presidency") {
4049 $new_data = get_var('eqpres',array('POST'));
4050 foreach ($new_data as $entry) {
4052 $email = $entry['email'];
4053 $indiv = $entry['indiv'];
4054 $name = $entry['name'];
4055 $district = $entry['district'];
4056 $president = $entry['president'];
4057 $counselor = $entry['counselor'];
4058 $secretary = $entry['secretary'];
4059 // look up the individual name for the ID
4060 $name = $indiv2name[$indiv];
4061 //print "id=$id indiv=$indiv name=$name email=$email district=$district president=$president ";
4062 //print "counselor=$counselor secretary=$secretary<br>";
4064 if(($indiv > 0) || ($name != "")) {
4065 if($id < $this->max_presidency_members) {
4066 //print "Updating Existing Entry<br>";
4067 $this->db2->query("UPDATE tc_presidency set" .
4068 " individual=" . $indiv .
4069 " ,district=" . $district .
4070 " ,email='" . $email . "'" .
4071 " ,president='" . $president . "'" .
4072 " ,counselor='" . $counselor . "'" .
4073 " ,secretary='" . $secretary . "'" .
4074 " WHERE presidency=" . $id,__LINE__,__FILE__);
4076 //print "Adding New Entry<br>";
4077 $this->db2->query("INSERT INTO tc_presidency (presidency,individual,district," .
4078 "email,president,counselor,secretary,valid) " .
4079 "VALUES (NULL,'" . $indiv . "','" . $district . "','" .
4080 $email . "','" . $president . "','" .
4081 $counselor . "','" . $secretary . "','1'" .
4082 ")",__LINE__,__FILE__);
4085 //print "Ignoring Blank Entry<br>";
4089 // Now update the tc_district table appropriately
4091 // Delete all the previous district entries from the table
4092 $this->db->query("DELETE from tc_district where valid=1",__LINE__,__FILE__);
4093 $this->db->query("DELETE from tc_district where valid=0",__LINE__,__FILE__);
4095 // Always add a "District 0" assigned to the High Priests Group
4097 $name = "High Priests";
4100 $this->db2->query("INSERT INTO tc_district (district,supervisor,valid) " .
4101 "VALUES ('" . $district . "','" .
4102 $indiv . "','" . $valid . "'" .
4103 ")",__LINE__,__FILE__);
4105 // Requery the tc_presidency table
4106 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1";
4107 $this->db->query($sql,__LINE__,__FILE__);
4108 while ($this->db->next_record()) {
4109 // Extract the data for each presidency record
4110 $id = $this->db->f('presidency');
4111 $indiv = $this->db->f('individual');
4112 $name = $this->db->f('name');
4113 $district = $this->db->f('district');
4116 // If we have a valid district, add it to the district table
4118 $this->db2->query("INSERT INTO tc_district (district,supervisor,valid) " .
4119 "VALUES ('" . $district . "','" .
4120 $indiv . "','" . $valid . "'" .
4121 ")",__LINE__,__FILE__);
4125 $this->t->set_var('adminhandle','');
4126 $this->t->pfp('adminhandle','admin');
4130 $this->t->set_var('adminhandle','');
4131 $this->t->pfp('adminhandle','admin');
4134 // Now save off the data needed for a Presidency Table Update
4136 $sql = "SELECT tp.*, ti.name FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1";
4137 $this->db->query($sql,__LINE__,__FILE__);
4139 $header_row = "<th>Individual</th><th>Email</th><th>District</th><th>President</th><th>Counselor</th><th>Secretary</th>";
4140 while ($this->db->next_record()) {
4141 // Extract the data for each presidency record
4142 $id = $this->db->f('presidency');
4143 $indiv = $this->db->f('individual');
4144 $district = $this->db->f('district');
4145 $name = $this->db->f('name');
4146 $email = $this->db->f('email');
4147 $president = $this->db->f('president');
4148 $counselor = $this->db->f('counselor');
4149 $secretary = $this->db->f('secretary');
4151 // Create the forms needed in the table
4152 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4155 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4158 if($eqpresidency == 0) {
4159 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4160 $table_data.= '<option value=0></option>';
4161 for ($j=0; $j < count($individual); $j++) {
4162 $tmp_id = $individual[$j];
4163 $name = $indiv_name[$j];
4164 if($individual[$j] == $indiv) {
4166 $selected = 'selected="selected"';
4170 $table_data.= '<option value='.$tmp_id.' '.$selected.'>'.$name.'</option>';
4172 $table_data.='</select></td>';
4173 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="'.$indivname.'">';
4175 $table_data.= '<td align=left><input type=text size="20" name="eqpresname" value="Presidency"></td>';
4176 $table_data.= '<input type=hidden name="eqpres['.$id.'][name]" value="Presidency">';
4180 $table_data .= '<td><input type="text" size="50" name="eqpres['.$id.'][email]" value="'.$email.'"></td>';
4183 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4184 $table_data.= '<option value=0></option>';
4185 for ($j=0; $j <= $this->max_num_districts; $j++) {
4186 if($district == $j) {
4187 $selected = 'selected="selected"';
4191 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4193 $table_data.='</select></td>';
4196 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4197 if($president == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4198 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4199 $table_data.='</select></td>';
4202 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4203 if($counselor == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4204 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4205 $table_data.='</select></td>';
4208 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4209 if($secretary == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4210 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4211 $table_data.='</select></td>';
4214 $table_data .= "</tr>\n";
4215 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4216 $this->t->set_var('tr_color',$tr_color);
4219 // Now create 1 blank row to always have a line available to add a new individual with
4220 $id = $this->max_presidency_members;
4221 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4223 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4225 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4226 $table_data.= '<option value=0></option>';
4227 for ($j=0; $j < count($individual); $j++) {
4228 $tmp_id = $individual[$j];
4229 $name = $indiv_name[$j];
4230 $table_data.= '<option value='.$tmp_id.'>'.$name.'</option>';
4232 $table_data.='</select></td>';
4233 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="">';
4235 $table_data.='<td><input type="text" size="50" name="eqpres['.$id.'][email]" value=""></td>';
4237 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4238 $table_data.= '<option value=0></option>';
4239 for ($j=0; $j <= $this->max_num_districts; $j++) {
4241 $selected = 'selected="selected"';
4245 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4247 $table_data.='</select></td>';
4249 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4250 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4251 $table_data.='</select></td>';
4253 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4254 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4255 $table_data.='</select></td>';
4257 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4258 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4259 $table_data.='</select></td>';
4261 $table_data .= "</tr>\n";
4262 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4263 $this->t->set_var('tr_color',$tr_color);
4265 $this->t->set_var('header_row',$header_row);
4266 $this->t->set_var('table_data',$table_data);
4267 $this->t->pfp('presidencyhandle','presidency',True);
4269 $this->save_sessiondata();
4272 function email_appt($appointment)
4274 //print "Emailing notification of appointment: $appointment <br>";
4276 $sql = "SELECT * FROM tc_appointment where appointment='$appointment'";
4277 $this->db->query($sql,__LINE__,__FILE__);
4279 while ($this->db->next_record()) {
4280 $appointment = $this->db->f('appointment');
4281 $presidency = $this->db->f('presidency');
4282 $location = $this->db->f('location');
4285 $indiv = $this->db->f('individual');
4287 $family = $this->db->f('family');
4291 $uid = $this->db->f('uid');
4293 // Extract the year, month, day, hours, minutes, seconds from the appointment time
4294 $appt_date = $this->db->f('date');
4295 $date_array = explode("-",$appt_date);
4296 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
4297 $appt_time = $this->db->f('time');
4298 $time_array = explode(":",$appt_time);
4299 $hour = $time_array[0]; $minute = $time_array[1]; $seconds = $time_array[2];
4301 // Format the appointment time into an iCal UTC equivalent
4302 $dtstamp = gmdate("Ymd"."\T"."His"."\Z");
4303 $dtstart = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds,$month,$day,$year));
4304 $dtstartstr = date("l, F d, o g:i A", mktime($hour,$minute,$seconds,$month,$day,$year));
4306 $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'";
4307 $this->db2->query($sql,__LINE__,__FILE__);
4308 if($this->db2->next_record()) {
4309 if ($this->db2->f('email1') != "") {
4310 $email = $this->db2->f('email1');
4312 $email = $this->db2->f('email2');
4314 $interviewer = $this->db2->f('name');
4317 // Set the email address of the interviewer
4321 $sql = "SELECT * FROM tc_individual where individual='$indiv'";
4322 $this->db2->query($sql,__LINE__,__FILE__);
4323 if($this->db2->next_record()) {
4324 $indiv_name = $this->db2->f('name');
4325 $phone = $this->db2->f('phone');
4326 $appt_name = $indiv_name . " Interview";
4327 $duration = $this->default_ppi_appt_duration * 60;
4332 $sql = "SELECT * FROM tc_family WHERE family='$family'";
4333 $this->db2->query($sql,__LINE__,__FILE__);
4334 if($this->db2->next_record()) {
4335 $individual = $this->db2->f('individual');
4336 $sql = "SELECT * FROM tc_individual where individual='$individual'";
4337 $this->db3->query($sql,__LINE__,__FILE__);
4338 if($this->db3->next_record()) {
4339 $phone = $this->db3->f('phone');
4340 $family_name = $this->db3->f('name');
4341 $phone = $this->db3->f('phone');
4343 $appt_name = $family_name . " Family Visit";
4344 $duration = $this->default_visit_appt_duration * 60;
4348 $dtend = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4349 $dtendstr = date("g:i A", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4350 $date = $dtstartstr . "-" . $dtendstr;
4351 $description = "$appt_name : $phone";
4353 if(($uid == 0) && ($appt_name != "")) {
4354 // Create a new calendar item for this appointment, since this must be the first time we
4355 // are sending it out.
4356 print "Sent new appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4357 $uid = rand() . rand(); // Generate a random identifier for this appointment
4358 $subject = "Created: $appt_name";
4360 $this->db->query("UPDATE tc_appointment set" .
4362 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4364 $action = "PUBLISH";
4365 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4366 $dtend, $date, $location, $appt_name, $description, $uid);
4367 } else if(($uid != 0) && ($appt_name == "")) {
4368 // Remove the calendar item for this appointment since it has already been sent
4369 // and there is no name we have changed it to.
4370 print "Sent deleted appointment to " . $interviewer . " at " . $email . " for " . $appt_date . " " . $appt_time . "<br>";
4371 $subject = "Canceled: $appt_date $appt_time";
4373 $this->db->query("UPDATE tc_appointment set" .
4375 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4378 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4379 $dtend, $date, $location, $subject, $subject, $uid);
4380 } else if($uid != 0) {
4381 // Update the existing appointment since we have changed it
4382 print "Sent updated appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4384 $subject = "Canceled: $appt_date $appt_time";
4386 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4387 $dtend, $date, $location, $subject, $subject, $uid);
4389 $uid = rand() . rand(); // Generate a random identifier for this appointment
4390 $this->db->query("UPDATE tc_appointment set" .
4392 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4394 $subject = "Updated: $appt_name";
4395 $action = "PUBLISH";
4396 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4397 $dtend, $date, $location, $appt_name, $description, $uid);
4403 function send_ical_appt($action, $to, $from, $subject, $dtstamp, $dtstart, $dtend, $date, $location, $summary, $description, $uid)
4405 // Initialize our local variables
4406 $boundary = "=MIME_APPOINTMENT_BOUNDARY";
4410 // Form the headers for the email message
4411 $headers.="X-Mailer: PHP/" . phpversion() . "\n";
4412 $headers.="Mime-Version: 1.0\n";
4413 $headers.="Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
4414 $headers.="Content-Disposition: inline\n";
4415 $headers.="Reply-To: $from\n";
4416 $headers.="From: $from\n";
4418 // Print the plaintext version of the appointment
4419 $message.="--$boundary\n";
4420 $message.="Content-Type: text/plain; charset=us-ascii\n";
4421 $message.="Content-Disposition: inline\n";
4423 $message.="What: $description\n";
4424 $message.="When: $date\n";
4425 $message.="Where: $location\n";
4428 // Print the .ics attachment version of the appointment
4429 $message.="--$boundary\n";
4430 $message.="Content-Type: text/calendar; charset=us-ascii\n";
4431 $message.="Content-Disposition: attachment; filename=\"appointment.ics\"\n";
4433 $message.="BEGIN:VCALENDAR" . "\n";
4434 $message.="VERSION:2.0" . "\n";
4435 $message.="PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN" . "\n";
4436 $message.="METHOD:$action" . "\n";
4437 $message.="BEGIN:VEVENT" . "\n";
4438 $message.="ORGANIZER:MAILTO:$from". "\n";
4439 $message.="DTSTAMP:$dtstamp" . "\n";
4440 $message.="DTSTART:$dtstart" . "\n";
4441 $message.="DTEND:$dtend" . "\n";
4442 $message.="SUMMARY:$summary" . "\n";
4443 $message.="DESCRIPTION:$description" . "\n";
4444 $message.="LOCATION:$location" . "\n";
4445 $message.="UID:$uid" ."\n";
4446 $message.="TRANSP:OPAQUE" . "\n";
4447 $message.="SEQUENCE:0" . "\n";
4448 $message.="CLASS:PUBLIC" . "\n";
4449 $message.="END:VEVENT" . "\n";
4450 $message.="END:VCALENDAR" . "\n";
4452 // Complete the message
4453 $message.="--$boundary\n";
4456 mail($to, $subject, $message, $headers);
4459 function get_time_selection_form($hour, $minute, $pm, $presidency, $appointment)
4464 if($hour == 0) { $blank = 1; }
4466 if($this->time_drop_down_lists == 1) {
4467 // Create drop down lists to get the time
4468 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][hour]>';
4469 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4470 foreach(range(1,12) as $num) {
4472 $selected = 'selected="selected"';
4476 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4478 $form_data.= '</select>';
4479 $form_data.= ' : ';
4480 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][minute]>';
4481 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4484 if($num < 10) { $num = "0" . "$num"; }
4485 if($minute == $num) {
4486 $selected = 'selected="selected"';
4490 if($blank == 1) { $selected = ""; }
4491 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4492 $num = $num + $this->time_drop_down_list_inc;
4494 $form_data.= '</select>';
4496 // Use free form text fields to get the time
4502 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][hour] value='.$hour.'>';
4504 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][minute] value='.$minute.'>';
4505 $form_data.= ' ';
4507 // Always use a drop-down select form for am/pm
4508 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][pm]>';
4511 $form_data.= '<option value=0 selected>am</option>';
4512 $form_data.= '<option value=1>pm</option>';
4515 $form_data.= '<option value=0>am</option>';
4516 $form_data.= '<option value=1 selected>pm</option>';
4519 $form_data.= '<option value=""></option>';
4520 $form_data.= '<option value=0>am</option>';
4521 $form_data.= '<option value=1>pm</option>';
4523 $form_data.= '</select>';