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;
39 var $public_functions = array
64 'willing_view' => True,
65 'willing_update' => True,
66 'send_ical_appt' => True,
67 'assign_view' => True,
68 'assign_update' => True,
69 'get_time_selection_form' => True,
74 if(file_exists("setup/tc_config.local")) {
75 include("setup/tc_config.local");
77 include("setup/tc_config");
80 $this->script_path = "$this->application_path"."/bin";
81 $this->max_presidency_members = 99;
82 $this->max_appointments = 32768;
84 $this->db = $GLOBALS['phpgw']->db;
85 $this->db2 = $this->db;
86 $this->db3 = $this->db;
87 $this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
88 $this->t = $GLOBALS['phpgw']->template;
89 $this->account = $GLOBALS['phpgw_info']['user']['account_id'];
90 $this->grants = $GLOBALS['phpgw']->acl->get_grants('tc');
91 $this->grants[$this->account] = PHPGW_ACL_READ + PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE;
93 $this->jscal = CreateObject('tc.jscalendar'); // before phpgw_header() !!!
94 $this->cal_options = 'daFormat : "%Y-%m-%d",
95 ifFormat : "%Y-%m-%d",
99 $GLOBALS['phpgw_info']['flags']['app_header'] = 'The 3rd Counselor';
100 $GLOBALS['phpgw']->common->phpgw_header();
102 $this->current_day = `date '+%d'`;
103 $this->current_day = $this->current_day-0; // Make it numeric
104 $this->current_month = `date '+%m'`;
105 $this->current_month = $this->current_month-0; // Make it numeric
106 $this->current_year = `date '+%Y'`;
107 $this->current_year = $this->current_year-0; // Make it numeric
110 $this->display_app_header();
113 function logToFile($func, $msg)
116 $fd = fopen($this->upload_target_path . "/tc_trace.log", "a");
117 // append date/time to message
118 $str = "[" . date("Y/m/d h:i:s", mktime()) . "] [" . $func . "] " . $msg;
120 fwrite($fd, $str . "\n");
125 function save_sessiondata()
129 function display_app_header()
131 $this->t->set_file(array('tc_header' => 'header.tpl'));
133 if (isset($phpgw_info['user']['preferences']['tc']['tc_font']))
135 $font = $phpgw_info['user']['preferences']['tc']['tc_font'];
142 $this->t->set_var('bg_color',$phpgw_info['theme']['th_bg']);
143 $this->t->set_var('font',$font);
144 $link_data['menuaction'] = 'tc.tc.ht_view';
145 $this->t->set_var('link_hometeaching',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
146 $this->t->set_var('lang_hometeaching','HomeTeaching');
147 $link_data['menuaction'] = 'tc.tc.act_list';
148 $this->t->set_var('link_activity',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
149 $this->t->set_var('lang_activity','Activities');
150 $link_data['menuaction'] = 'tc.tc.willing_view';
151 $this->t->set_var('link_willing',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
152 $this->t->set_var('lang_willing','Willingness');
153 $link_data['menuaction'] = 'tc.tc.assign_view';
154 $this->t->set_var('link_assignment',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
155 $this->t->set_var('lang_assignment','Assignments');
156 $link_data['menuaction'] = 'tc.tc.par_view';
157 $this->t->set_var('link_participation',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
158 $this->t->set_var('lang_participation','Participation');
159 $link_data['menuaction'] = 'tc.tc.ppi_view';
160 $this->t->set_var('link_ppi',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
161 $this->t->set_var('lang_ppi','PPIs');
162 $link_data['menuaction'] = 'tc.tc.int_view';
163 $this->t->set_var('link_int',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
164 $this->t->set_var('lang_int','Interviews');
165 $link_data['menuaction'] = 'tc.tc.vis_view';
166 $this->t->set_var('link_visit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
167 $this->t->set_var('lang_visit','Visits');
168 $link_data['menuaction'] = 'tc.tc.att_view';
169 $this->t->set_var('link_attendance',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
170 $this->t->set_var('lang_attendance','Attendance');
171 $link_data['menuaction'] = 'tc.tc.dir_view';
172 $this->t->set_var('link_dir',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
173 $this->t->set_var('lang_dir','Directory');
174 $link_data['menuaction'] = 'tc.tc.org_view';
175 $this->t->set_var('link_org',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
176 $this->t->set_var('lang_org','Callings');
177 $link_data['menuaction'] = 'tc.tc.admin';
178 $this->t->set_var('link_admin',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
179 $this->t->set_var('lang_admin','Admin');
180 $link_data['menuaction'] = 'tc.tc.schedule';
181 $this->t->set_var('link_schedule',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
182 $this->t->set_var('lang_schedule','Scheduling');
183 $link_data['menuaction'] = 'tc.tc.email';
184 $this->t->set_var('link_email',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
185 $this->t->set_var('lang_email','Email');
187 $this->t->pparse('out','tc_header');
192 $this->t->set_file(array('ht_view_t' => 'ht_view.tpl'));
193 $this->t->set_block('ht_view_t','district_list','list');
195 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
196 $num_months = get_var('num_months',array('GET','POST'));
197 if($num_months == '') { $num_months = $this->default_ht_num_months; }
198 $this->t->set_var('num_months',$num_months);
199 $this->t->set_var('lang_filter','Filter');
200 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
201 else { $this->t->set_var('lang_num_months','Months of History'); }
203 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
204 $this->t->set_var('title','Hometeaching');
206 $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";
207 $this->db->query($sql,__LINE__,__FILE__);
209 while ($this->db->next_record()) {
210 $districts[$i]['district'] = $this->db->f('district');
211 $districts[$i]['name'] = $this->db->f('name');
212 $districts[$i]['supervisor'] = $this->db->f('supervisor');
216 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
217 $this->db->query($sql,__LINE__,__FILE__);
219 while ($this->db->next_record()) {
220 $individual[$i] = $this->db->f('individual');
221 $indiv_name[$i] = $this->db->f('name');
222 $indiv_phone[$individual[$i]] = $this->db->f('phone');
225 array_multisort($indiv_name, $individual);
227 // Make an array mapping individuals to indiv_names
228 for($i=0; $i < count($individual); $i++) {
229 $id = $individual[$i];
230 $indivs[$id] = $indiv_name[$i];
233 $this->nextmatchs->template_alternate_row_color(&$this->t);
234 for($m=$num_months; $m >= 0; $m--) { $total_families[$m]=0; }
235 for ($i=0; $i < count($districts); $i++) {
236 $this->t->set_var('district_number',$districts[$i]['district']);
237 $this->t->set_var('district_name',$districts[$i]['name']);
238 $supervisor = $districts[$i]['supervisor'];
240 // Select all the unique companionship numbers for this district
241 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$i]['district'];
242 $this->db->query($sql,__LINE__,__FILE__);
243 $j=0; $unique_companionships = '';
244 while ($this->db->next_record()) {
245 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
249 $comp_width=450; $visit_width=25; $table_width=$comp_width + $num_months*$visit_width;
250 $table_data=""; $num_companionships = 0;
251 for($m=$num_months; $m >= 0; $m--) {
255 for ($j=0; $j < count($unique_companionships); $j++) {
256 $companion_table_entry = "";
257 // Select all the companions in each companionship
258 $sql = "SELECT * FROM tc_companion where valid=1 and ".
259 "companionship=". $unique_companionships[$j]['companionship'];
260 $this->db->query($sql,__LINE__,__FILE__);
262 while ($this->db->next_record()) {
263 // Get this companions information
264 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
265 $companionship = $this->db->f('companionship');
266 $individual = $this->db->f('individual');
267 $name = $indivs[$individual];
268 $phone = $indiv_phone[$individual];
269 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
271 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
273 // Get the names of the families assigned this home teaching companionship
274 $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'];
275 $sql = $sql . " ORDER BY name ASC";
276 $this->db->query($sql,__LINE__,__FILE__);
278 while ($this->db->next_record()) {
279 $family_name = $this->db->f('name');
280 $family_id = $this->db->f('family');
281 $this->nextmatchs->template_alternate_row_color(&$this->t);
282 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
283 // Find out how many times Visits were performed by this companionship
284 // in the past $num_months for this Family
285 $header_row="<th width=$comp_width><font size=-2>Families</th>";
286 for($m=$num_months; $m >= 0; $m--) {
287 $month = $this->current_month - $m;
288 $year = $this->current_year;
289 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
290 if($month < 10) { $month = "0"."$month"; }
291 $month_start = "$year"."-"."$month"."-"."01";
292 $month_end = "$year"."-"."$month"."-"."31";
293 $month = "$month"."/"."$year";
295 //print "m: $m month: $month year: $year month_start: $month_start month_end: $month_end<br>";
296 // Add this to the query to filter on only visits made by this companionship:
297 // " AND companionship=" . $unique_companionships[$j]['companionship'].
299 // First check to see if the currently assigned companionship has visited them
300 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
301 " AND companionship=".$unique_companionships[$j]['companionship'].
302 " AND family=". $family_id;
303 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
304 if($this->db2->num_rows($query_id) == 0) {
305 // We did not find any visits made by the currently assigned companionship,
306 // look for visits made by any other companionship other than 0. (0 == Presidency Visit)
307 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
308 " AND companionship!=0".
309 " AND family=". $family_id;
310 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
312 $this->db2->query($sql,__LINE__,__FILE__);
313 $link_data['menuaction'] = 'tc.tc.ht_update';
314 $link_data['date'] = $month_start;
315 $link_data['month_start'] = $month_start;
316 $link_data['month_end'] = $month_end;
317 $link_data['month'] = $month;
318 $link_data['district'] = $districts[$i]['district'];
319 $link_data['district_name'] = $districts[$i]['name'];
320 $link_data['action'] = 'view';
321 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
322 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
323 if(!$total_visits[$m]) { $total_visits[$m] = 0; }
324 if($this->db2->next_record()) {
325 if($this->db2->f('visited') == 'y') {
326 $visits[$m]++; $total_visits[$m]++;
327 $num_families[$m]++; $total_families[$m]++;
328 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/checkmark.gif"></a></td>';
329 } else if($this->db2->f('visited') == 'n') {
330 $num_families[$m]++; $total_families[$m]++;
331 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/x.gif"></a></td>';
333 //$visits[$m]++; $total_visits[$m]++;
334 $table_data .= "<td> </td>";
337 //$visits[$m]++; $total_visits[$m]++;
338 $table_data .= "<td> </td>";
341 $table_data .= "</tr>";
344 $table_data .= "<tr><td colspan=20></td></tr>";
346 $table_data .= "<tr><td colspan=20><hr></td></tr>";
347 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
349 for($m=$num_months; $m >=0; $m--) {
350 if($num_families[$m] > 0) {
351 $percent = ceil(($visits[$m] / $num_families[$m])*100);
355 $stat_data .= "<td align=center><font size=-2><b>$visits[$m] / $num_families[$m]<br>$percent%</font></b></td>";
357 $stat_data .= "</tr>";
359 $this->t->set_var('table_width',$table_width);
360 $this->t->set_var('header_row',$header_row);
361 $this->t->set_var('table_data',$table_data);
362 $this->t->set_var('stat_data',$stat_data);
363 $this->t->fp('list','district_list',True);
366 $totals = "<tr><td><b><font size=-2>Total Families Hometaught:<br>Total Hometeaching Percentage:</font></b></td>";
367 for($m=$num_months; $m >=0; $m--) {
368 if($total_families[$m] > 0) {
369 $percent = ceil(($total_visits[$m] / $total_families[$m])*100);
373 $totals .= "<td align=center><font size=-2><b>$total_visits[$m] / $total_families[$m]<br>$percent%</font></b></td>";
377 $this->t->set_var('totals',$totals);
379 $this->t->pfp('out','ht_view_t');
380 $this->save_sessiondata();
386 $this->t->set_file(array('ht_update_t' => 'ht_update.tpl'));
387 $this->t->set_block('ht_update_t','district_list','list');
388 $this->t->set_block('ht_update_t','save','savehandle');
390 $district = get_var('district',array('GET','POST'));
391 $district_name = get_var('district_name',array('GET','POST'));
392 $date = get_var('date',array('GET','POST'));
393 $month = get_var('month',array('GET','POST'));
394 $month_start = get_var('month_start',array('GET','POST'));
395 $month_end = get_var('month_end',array('GET','POST'));
396 $action = get_var('action',array('GET','POST'));
398 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
399 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_update&action=save'));
400 $this->t->set_var('lang_done','Cancel');
401 $this->t->set_var('district_name',$district_name);
402 $this->t->set_var('district_number',$district);
403 $this->t->set_var('title','Hometeaching Update ' . $month);
404 $this->t->set_var('date',$date);
406 if($action == 'save') {
407 // Get a list of all the companionships in this district
408 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $district;
409 $this->db->query($sql,__LINE__,__FILE__);
410 $j=0; $unique_companionships = '';
411 while ($this->db->next_record()) {
412 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
415 for ($j=0; $j < count($unique_companionships); $j++) {
416 //$comp=$unique_companionships[$j]['companionship'];
417 //print "deleting from tc_visit where companionship=$comp and date=$date and district=$district<br>";
418 // Delete all the visits that have taken place for all families for this companionsthip for this month
419 $this->db->query("DELETE from tc_visit where companionship=" . $unique_companionships[$j]['companionship'] .
420 " AND " . "date='" . $date . "'",__LINE__,__FILE__);
423 // Now, add the visits that are checked for this month
424 $new_data = get_var('family_visited',array('POST'));
425 foreach ($new_data as $family) {
426 foreach ($family as $data) {
427 //print "family_visited: $data <br>";
428 $data_array = explode("/",$data);
429 $family_id = $data_array[0];
430 $companionship = $data_array[1];
431 $date = $data_array[2];
432 $visited = $data_array[3];
433 if($visited == "") { $visited = $data_array[4]; }
434 //print "family_id: $family_id companionship: $companionship date: $date visited: $visited<br>";
435 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes,visited) " .
436 "VALUES (" . $family_id .",". $companionship .",'". $date ."','','". $visited ."')",__LINE__,__FILE__);
443 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
444 $this->db->query($sql,__LINE__,__FILE__);
446 while ($this->db->next_record()) {
447 $individual[$i] = $this->db->f('individual');
448 $indiv_name[$i] = $this->db->f('name');
449 $indiv_phone[$individual[$i]] = $this->db->f('phone');
452 array_multisort($indiv_name, $individual);
454 // Make an array mapping individuals to indiv_names
455 for($i=0; $i < count($individual); $i++) {
456 $id = $individual[$i];
457 $indivs[$id] = $indiv_name[$i];
460 // Select all the unique companionship numbers for this district
461 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $district;
462 $this->db->query($sql,__LINE__,__FILE__);
463 $j=0; $unique_companionships = '';
464 while ($this->db->next_record()) {
465 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
469 $comp_width=300; $visit_width=25; $table_width=$comp_width + $visit_width;
470 $table_data=""; $num_companionships = 0; $num_families = 0; $visits=0;
471 for ($j=0; $j < count($unique_companionships); $j++) {
472 $companion_table_entry = "";
473 // Select all the companions in each companionship
474 $sql = "SELECT * FROM tc_companionship where valid=1 and ".
475 "companionship=". $unique_companionships[$j]['companionship'];
476 $this->db->query($sql,__LINE__,__FILE__);
478 while ($this->db->next_record()) {
479 // Get this companions information
480 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
481 $companionship = $this->db->f('companionship');
482 $individual = $this->db->f('individual');
483 $name = $indivs[$individual];
484 $phone = $indiv_phone[$individual];
485 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
487 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
489 // Get the names of the families assigned this home teaching companionship
490 $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'];
491 $sql = $sql . " ORDER BY ti.name ASC";
492 $this->db->query($sql,__LINE__,__FILE__);
493 while ($this->db->next_record()) {
494 $family_name = $this->db->f('name');
495 $family_id = $this->db->f('family');
496 $this->nextmatchs->template_alternate_row_color(&$this->t);
497 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
499 $header_row="<th width=$comp_width><font size=-2>Families</th>";
501 // First check to see if the currently assigned companionship has visited them
502 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
503 " AND companionship=".$unique_companionships[$j]['companionship'].
504 " AND family=". $family_id;
505 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
506 if($this->db2->num_rows($query_id) == 0) {
507 // We did not find any visits made by the currently assigned companionship,
508 // look for visits made by any other companionship other than 0. (0 == Presidency Visit)
509 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
510 " AND companionship!=0".
511 " AND family=". $family_id;
512 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
515 $value = $family_id . "/" . $unique_companionships[$j]['companionship'] . "/" . $date;
516 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
517 if(!$total_visits) { $total_visits = 0; }
518 if($this->db2->next_record()) {
519 if($this->db2->f('visited') == 'y') {
520 $visits++; $total_visits++; $num_families++;
521 $table_data .= '<td width=100 align=center>';
522 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y" checked>Y';
523 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
524 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/"> ';
525 $table_data .= '</td>';
526 } else if($this->db2->f('visited') == 'n') {
528 $table_data .= '<td width=100 align=center>';
529 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
530 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n" checked>N';
531 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/">';
532 $table_data .= '</td>';
534 $table_data .= '<td width=100 align=center>';
535 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
536 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
537 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
538 $table_data .= '</td>';
543 $table_data .= '<td width=100 align=center>';
544 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
545 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
546 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
547 $table_data .= '</td>';
550 $table_data .= "</tr>";
551 $table_data .= "<tr><td colspan=20></td></tr>";
553 $table_data .= "<tr><td colspan=20><hr></td></tr>";
554 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
556 $percent = ceil(($visits / $num_families)*100);
557 $stat_data .= "<td align=center><font size=-2><b>$visits / $num_families<br>$percent%</font></b></td>";
558 $stat_data .= "</tr>";
560 $this->t->set_var('table_width',$table_width);
561 $this->t->set_var('header_row',$header_row);
562 $this->t->set_var('table_data',$table_data);
563 $this->t->set_var('stat_data',$stat_data);
564 $this->t->fp('list','district_list',True);
566 $this->t->set_var('lang_reset','Clear Form');
567 $this->t->set_var('lang_save','Save Changes');
568 $this->t->set_var('savehandle','');
570 $this->t->pfp('out','ht_update_t');
571 $this->t->pfp('addhandle','save');
573 $this->save_sessiondata();
578 $this->t->set_file(array('act_list_t' => 'act_list.tpl'));
579 $this->t->set_block('act_list_t','act_list','list');
581 $this->t->set_var('lang_name','Assignment');
582 $this->t->set_var('lang_date','Date');
583 $this->t->set_var('lang_notes','Description');
585 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
586 $this->db->query($sql,__LINE__,__FILE__);
587 $total_records = $this->db->num_rows();
590 while ($this->db->next_record()) {
591 $activity_list[$i]['activity'] = $this->db->f('activity');
592 $activity_list[$i]['assignment'] = $this->db->f('assignment');
593 $activity_list[$i]['date'] = $this->db->f('date');
594 $activity_list[$i]['notes'] = $this->db->f('notes');
596 $sql = "SELECT * FROM tc_assignment WHERE assignment='" . $activity_list[$i]['assignment'] . "'";
597 $this->db2->query($sql,__LINE__,__FILE__);
598 if($this->db2->next_record()) {
599 $activity_list[$i]['name'] = $this->db2->f('name');
600 $activity_list[$i]['abbreviation'] = $this->db2->f('abbreviation');
605 for ($i=0; $i < count($activity_list); $i++) {
606 $this->nextmatchs->template_alternate_row_color(&$this->t);
607 $this->t->set_var('name',$activity_list[$i]['name']);
608 $this->t->set_var('date',$activity_list[$i]['date']);
609 $activity_notes = $activity_list[$i]['notes'];
610 if(strlen($activity_notes) > 40) { $activity_notes = substr($activity_notes,0,40) . "..."; }
611 $this->t->set_var('notes',$activity_notes);
613 $link_data['menuaction'] = 'tc.tc.act_view';
614 $link_data['activity'] = $activity_list[$i]['activity'];
615 $link_data['action'] = 'view';
616 $this->t->set_var('view',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
617 $this->t->set_var('lang_view','View');
619 $link_data['menuaction'] = 'tc.tc.act_update';
620 $link_data['activity'] = $activity_list[$i]['activity'];
621 $link_data['action'] = 'edit';
622 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
623 $this->t->set_var('lang_edit','Edit');
625 $this->t->fp('list','act_list',True);
628 $link_data['menuaction'] = 'tc.tc.act_update';
629 $link_data['activity'] = '0';
630 $link_data['action'] = 'add';
631 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/tc/index.php',$link_data) .
632 '"><input type="submit" name="Add" value="' . 'Add Activity' .'"></font></form>');
634 $this->t->pfp('out','act_list_t');
635 $this->save_sessiondata();
640 $this->t->set_file(array('act_view_t' => 'act_view.tpl'));
641 $this->t->set_block('act_view_t','part_list','list');
643 $sql = "SELECT * FROM tc_activity WHERE activity=" . intval(get_var('activity',array('GET','POST')));
644 $this->db->query($sql,__LINE__,__FILE__);
645 $this->db->next_record();
646 $this->t->set_var('assignment', $this->db->f('assignment'));
647 $this->t->set_var('date', $this->db->f('date'));
648 $this->t->set_var('notes', $this->db->f('notes'));
650 $sql = "SELECT * FROM tc_assignment WHERE assignment='" . $this->db->f('assignment') . "'";
651 $this->db2->query($sql,__LINE__,__FILE__);
652 if($this->db2->next_record()) {
653 $this->t->set_var('name', $this->db2->f('name'));
654 $this->t->set_var('abbreviation', $this->db2->f('abbreviation'));
656 $this->t->set_var('lang_name','Assignment');
657 $this->t->set_var('lang_date','Date');
658 $this->t->set_var('lang_notes','Description');
659 $this->t->set_var('lang_done','Done');
660 $this->t->set_var('lang_action','View');
662 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
663 $this->t->set_var('tr_color',$tr_color);
665 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_list'));
667 $link_data['menuaction'] = 'tc.tc.act_update';
668 $link_data['activity'] = get_var('activity',array('GET','POST'));
669 $link_data['action'] = 'edit';
670 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
671 $this->t->set_var('lang_edit','Edit');
672 $this->t->set_var('cal_date',$this->db->f('date'));
674 // Now find out which indivs participated in this activity
675 $sql = "SELECT * FROM tc_participation WHERE activity=" . intval(get_var('activity',array('GET','POST')));
676 $this->db->query($sql,__LINE__,__FILE__);
677 $total_records = $this->db->num_rows();
680 while ($this->db->next_record()) {
681 $part_list[$i]['individual'] = $this->db->f('individual');
685 for ($i=0; $i < count($part_list); $i++) {
686 $sql = "SELECT * FROM tc_individual WHERE individual=" . $part_list[$i]['individual'];
687 $this->db->query($sql,__LINE__,__FILE__);
688 $this->db->next_record();
689 $names[$i] = $this->db->f('name');
693 for ($i=0; $i < count($names); $i++) {
694 //$this->nextmatchs->template_alternate_row_color(&$this->t);
695 $this->t->set_var('individual_name',$names[$i]);
696 if(($i+1) % 3 == 0) {
697 $this->t->set_var('table_sep',"</td></tr><tr>");
699 $this->t->set_var('table_sep',"</td>");
701 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
702 $this->t->fp('list','part_list',True);
705 $this->t->pfp('out','act_view_t');
706 $this->save_sessiondata();
709 function act_update()
711 $this->t->set_file(array('form' => 'act_update.tpl'));
712 $this->t->set_block('form','individual_list','list');
713 $this->t->set_block('form','add','addhandle');
714 $this->t->set_block('form','edit','edithandle');
715 $this->t->set_var('lang_done','Done');
717 $action = get_var('action',array('GET','POST'));
718 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_list'));
719 $activity['activity'] = intval(get_var('activity',array('GET','POST')));
721 if($action == 'save') {
722 $activity['assignment'] = get_var('assignment',array('POST'));
723 $activity['date'] = get_var('date',array('POST'));
724 $activity['notes']= get_var('notes',array('POST'));
725 $this->db->query("UPDATE tc_activity set " .
726 " assignment='" . $activity['assignment'] .
727 "', date='" . $activity['date'] . "'" .
728 ", notes='" . $activity['notes'] . "'" .
729 " WHERE activity=" . $activity['activity'],__LINE__,__FILE__);
731 // Delete all the individuals who have particiapted in this activity
732 $this->db->query("DELETE from tc_participation where activity=".$activity['activity'],__LINE__,__FILE__);
734 // Re-add the individuals who are checked as having participated in this activity
735 $indivs = get_var('individual_name',array('POST'));
736 if(is_array($indivs)) { // Only do the foreach loop if we have a valid array of indivs to work with
737 foreach ($indivs as $individual) {
738 $this->db->query("INSERT INTO tc_participation (individual,activity) " .
739 "VALUES (" . $individual . ",". $activity['activity'] . ")",__LINE__,__FILE__);
747 if($action == 'insert') {
748 $activity['assignment'] = get_var('assignment',array('POST'));
749 $activity['date'] = get_var('date',array('POST'));
750 $activity['notes']= get_var('notes',array('POST'));
751 $this->db->query("INSERT INTO tc_activity (assignment,date,notes) " .
752 "VALUES ('" . $activity['assignment'] . "','" .
753 $activity['date'] . "','" . $activity['notes'] . "')",__LINE__,__FILE__);
755 $sql = "SELECT * FROM tc_activity WHERE assignment='".$activity['assignment']."' " .
756 " AND date='".$activity['date']."' AND notes='".$activity['notes']."'";
757 $this->db->query($sql,__LINE__,__FILE__);
758 if($this->db->next_record()) {
759 //print "activity: " . $this->db->f('activity') . "<br>";
760 $activity['activity'] = $this->db->f('activity');
763 $indivs = get_var('individual_name',array('POST'));
764 foreach ($indivs as $individual)
766 $this->db->query("INSERT INTO tc_participation (individual,activity) " .
767 "VALUES (" . $individual . ",". $activity['activity'] . ")",__LINE__,__FILE__);
774 if($action == 'add') {
775 $activity['activity'] = 0;
776 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
777 $this->t->set_var('assignment','');
778 $this->t->set_var('date','');
779 $this->t->set_var('notes','');
780 $this->t->set_var('lang_done','Cancel');
781 $this->t->set_var('lang_action','Adding New Activity');
782 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_update&activity=' .
783 $activity['activity'] . '&action=' . 'insert'));
786 if($action == 'edit') {
787 $sql = "SELECT * FROM tc_activity WHERE activity=" . $activity['activity'];
788 $this->db->query($sql,__LINE__,__FILE__);
789 $this->db->next_record();
790 $this->t->set_var('cal_date',$this->jscal->input('date',$this->db->f('date'),'','','','','',$this->cal_options));
791 $this->t->set_var('assignment', $this->db->f('assignment'));
792 $assignment = $this->db->f('assignment');
793 $this->t->set_var('date', $this->db->f('date'));
794 $this->t->set_var('notes', $this->db->f('notes'));
795 $this->t->set_var('lang_done','Cancel');
796 $this->t->set_var('lang_action','Editing Activity');
797 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_update&activity=' .
798 $activity['activity'] . '&action=' . 'save'));
801 // Create the assignments drop-down list
802 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
803 $this->db->query($sql,__LINE__,__FILE__);
805 while ($this->db->next_record()) {
806 $assignments[$i]['assignment'] = $this->db->f('assignment');
807 $assignments[$i]['name'] = $this->db->f('name');
808 $assignments[$i]['abbreviation'] = $this->db->f('abbreviation');
812 $assignment_data.= '<select name=assignment>';
813 $assignment_data.= '<option value=0></option>';
814 for ($j=0; $j < count($assignments); $j++) {
815 $id = $assignments[$j]['assignment'];
816 $name = $assignments[$j]['name'];
817 if($assignments[$j]['assignment'] == $assignment) {
818 $selected[$id] = 'selected="selected"';
822 $assignment_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
824 $assignment_data.='</select>';
825 $this->t->set_var('assignment_data',$assignment_data);
827 // Create individual selection boxes
828 $sql = "SELECT * FROM tc_individual WHERE steward='$this->default_stewardship'";
829 $this->db->query($sql,__LINE__,__FILE__);
831 while ($this->db->next_record()) {
832 if($this->db->f('valid') == 1 || $action != 'add') {
833 $indiv_name[$i] = $this->db->f('name');
834 $individual[$i] = $this->db->f('individual');
835 $indiv_valid[$i] = $this->db->f('valid');
839 array_multisort($indiv_name, $individual, $indiv_valid);
842 for ($i=0; $i < count($individual); $i++) {
843 //$this->nextmatchs->template_alternate_row_color(&$this->t);
844 $sql = "SELECT * FROM tc_participation where activity=". $activity['activity'] . " AND individual=" . $individual[$i];
845 $this->db->query($sql,__LINE__,__FILE__);
846 if($this->db->next_record()) {
847 $this->t->set_var('checked','checked');
850 $this->t->set_var('checked','');
853 if($checked || $indiv_valid[$i] == 1) {
854 $this->t->set_var('individual_name',$indiv_name[$i]);
855 $this->t->set_var('individual',$individual[$i]);
856 if(($j+1) % 3 == 0) {
857 $this->t->set_var('table_sep',"</td></tr><tr>");
859 $this->t->set_var('table_sep',"</td>");
861 if(($j) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
862 $this->t->fp('list','individual_list',True);
867 $this->t->set_var('lang_reset','Clear Form');
868 $this->t->set_var('lang_add','Add Activity');
869 $this->t->set_var('lang_save','Save Changes');
870 $this->t->set_var('edithandle','');
871 $this->t->set_var('addhandle','');
873 $this->t->pfp('out','form');
874 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
875 if($action == 'add') { $this->t->pfp('addhandle','add'); }
877 $this->save_sessiondata();
880 function assign_view()
882 $this->t->set_file(array('assign_view_t' => 'assign_view.tpl'));
883 $this->t->set_block('assign_view_t','assign_view','list');
885 $this->t->set_var('lang_name','Assignment Name');
886 $this->t->set_var('lang_code','Abbreviation');
888 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
889 $this->db->query($sql,__LINE__,__FILE__);
890 $total_records = $this->db->num_rows();
893 while ($this->db->next_record()) {
894 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
895 $assignment_list[$i]['name'] = $this->db->f('name');
896 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
900 for ($i=0; $i < count($assignment_list); $i++) {
901 $this->nextmatchs->template_alternate_row_color(&$this->t);
902 $this->t->set_var('name',$assignment_list[$i]['name']);
903 $this->t->set_var('abbreviation',$assignment_list[$i]['abbreviation']);
905 $link_data['menuaction'] = 'tc.tc.assign_update';
906 $link_data['assignment'] = $assignment_list[$i]['assignment'];
907 $link_data['action'] = 'edit';
908 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
909 $this->t->set_var('lang_edit','Edit');
911 $link_data['menuaction'] = 'tc.tc.assign_update';
912 $link_data['assignment'] = '0';
913 $link_data['action'] = 'add';
914 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/tc/index.php',$link_data) .
915 '"><input type="submit" name="Add" value="' . 'Add Assignment' .'"></font></form>');
917 $this->t->fp('list','assign_view',True);
920 $this->t->pfp('out','assign_view_t');
921 $this->save_sessiondata();
924 function assign_update()
926 $this->t->set_file(array('form' => 'assign_update.tpl'));
927 $this->t->set_block('form','add','addhandle');
928 $this->t->set_block('form','edit','edithandle');
929 $this->t->set_var('lang_done','Done');
931 $action = get_var('action',array('GET','POST'));
932 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_view'));
933 $assignment['assignment'] = intval(get_var('assignment',array('GET','POST')));
935 if($action == 'save') {
936 $assignment['name'] = get_var('name',array('POST'));
937 $assignment['abbreviation'] = get_var('abbreviation',array('POST'));
938 $this->db->query("UPDATE tc_assignment set " .
939 " name='" . $assignment['name'] . "'" .
940 ", abbreviation='" . $assignment['abbreviation'] . "'" .
941 " WHERE assignment=" . $assignment['assignment'],__LINE__,__FILE__);
943 $this->assign_view();
947 if($action == 'insert') {
948 $assignment['name'] = get_var('name',array('POST'));
949 $assignment['abbreviation'] = get_var('abbreviation',array('POST'));
950 $this->db->query("INSERT INTO tc_assignment (name,abbreviation) " .
951 "VALUES ('" . $assignment['name'] . "','" .
952 $assignment['abbreviation'] . "')",__LINE__,__FILE__);
953 $this->assign_view();
957 if($action == 'add') {
958 $assignment['assignment'] = 0;
959 $this->t->set_var('name','');
960 $this->t->set_var('abbreviation','');
961 $this->t->set_var('lang_done','Cancel');
962 $this->t->set_var('lang_action','Adding New Assignment');
963 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_update&assignment=' .
964 $assignment['assignment'] . '&action=' . 'insert'));
967 if($action == 'edit')
969 $sql = "SELECT * FROM tc_assignment WHERE assignment=" . $assignment['assignment'];
970 $this->db->query($sql,__LINE__,__FILE__);
971 $this->db->next_record();
972 $this->t->set_var('name', $this->db->f('name'));
973 $this->t->set_var('abbreviation', $this->db->f('abbreviation'));
974 $this->t->set_var('lang_done','Cancel');
975 $this->t->set_var('lang_action','Editing Assignment');
976 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_update&assignment=' .
977 $assignment['assignment'] . '&action=' . 'save'));
980 $this->t->set_var('lang_reset','Clear Form');
981 $this->t->set_var('lang_add','Add Assignment');
982 $this->t->set_var('lang_save','Save Changes');
983 $this->t->set_var('edithandle','');
984 $this->t->set_var('addhandle','');
986 $this->t->pfp('out','form');
987 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
988 if($action == 'add') { $this->t->pfp('addhandle','add'); }
990 $this->save_sessiondata();
995 $this->t->set_file(array('par_view_t' => 'par_view.tpl'));
996 $this->t->set_block('par_view_t','header_list','list1');
997 $this->t->set_block('par_view_t','individual_list','list2');
999 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
1000 $this->db->query($sql,__LINE__,__FILE__);
1002 while ($this->db->next_record()) {
1003 $individual_name[$i] = $this->db->f('name');
1004 $individual[$i] = $this->db->f('individual');
1007 array_multisort($individual_name, $individual);
1009 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
1010 $this->db->query($sql,__LINE__,__FILE__);
1011 $total_records = $this->db->num_rows();
1014 while ($this->db->next_record()) {
1015 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1016 $activity_list[$i]['date'] = $this->db->f('date');
1017 $activity_list[$i]['activity'] = $this->db->f('activity');
1021 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1022 $this->db->query($sql,__LINE__,__FILE__);
1024 while($this->db->next_record()) {
1025 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1026 $assignment_list[$i]['name'] = $this->db->f('name');
1027 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1031 $individual_width=300; $part_width=25; $assignment_width=50;
1032 $total_width=$individual_width+$part_width;
1033 for ($i=0; $i < count($assignment_list); $i++) {
1034 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1035 $this->t->set_var('assignment_abbreviation',$assignment_list[$i]['abbreviation']);
1036 $this->t->fp('list1','header_list',True);
1037 $total_width += $assignment_width;
1040 for ($i=0; $i < count($individual); $i++) {
1041 $participated=0; $part_table = '';
1042 $this->nextmatchs->template_alternate_row_color(&$this->t);
1043 $this->t->set_var('individual_name',$individual_name[$i]);
1044 for ($j=0; $j < count($assignment_list); $j++) {
1045 $date = "0000-00-00"; $checkmark=0; $num_matches=0;
1046 for ($k=0; $k < count($activity_list); $k++) {
1047 if($assignment_list[$j]['assignment'] == $activity_list[$k]['assignment']) {
1048 $sql = "SELECT * FROM tc_participation where " .
1049 " activity=" . $activity_list[$k]['activity'] .
1050 " AND individual=" . $individual[$i];
1051 $this->db->query($sql,__LINE__,__FILE__);
1052 while($this->db->next_record()) {
1053 if($activity_list[$k]['date'] > $date) {
1054 $date = $activity_list[$k]['date'];
1063 $part_table .= '<td align=center><img src="images/checkmark.gif">';
1064 $part_table .= '<font size=-2>'.$num_matches.'</font><br>';
1065 $part_table .= '<font size=-2>'.$date.'</font></td>';
1067 $part_table .= '<td> </td>';
1071 $part_table .= '<td align=center><img src="images/checkmark.gif">'.$participated.'</td>';
1073 $part_table .= '<td> </td>';
1075 $this->t->set_var('part_table',$part_table);
1076 $this->t->fp('list2','individual_list',True);
1078 $this->t->set_var('total_width',$total_width);
1079 $this->t->set_var('individual_width',$individual_width);
1080 $this->t->set_var('part_width',$part_width);
1081 $this->t->set_var('act_width',$act_width);
1082 $this->t->pfp('out','par_view_t');
1083 $this->save_sessiondata();
1086 function willing_view()
1088 $this->t->set_file(array('willing_view_t' => 'willing_view.tpl'));
1089 $this->t->set_block('willing_view_t','header_list','list1');
1090 $this->t->set_block('willing_view_t','individual_list','list2');
1092 $this->t->set_var('lang_filter','Filter');
1093 $this->t->set_var('lang_filter_unwilling','Filter out unwilling individuals:');
1095 $filter_unwilling = get_var('filter_unwilling',array('POST'));
1096 $this->t->set_var('filter_unwilling',$filter_unwilling);
1098 if($filter_unwilling == 'y' || $filter_unwilling == '') {
1099 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\" checked>Y";
1100 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\">N";
1101 $filter_input.= " ";
1103 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\">Y";
1104 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\" checked>N";
1105 $filter_input.= " ";
1107 $this->t->set_var('filter_input',$filter_input);
1109 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
1110 $this->db->query($sql,__LINE__,__FILE__);
1112 while ($this->db->next_record()) {
1113 $indiv_name[$i] = $this->db->f('name');
1114 $individual[$i] = $this->db->f('individual');
1115 $indiv_phone[$individual[$i]] = $this->db->f('phone');
1118 array_multisort($indiv_name, $individual);
1120 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1121 $this->db->query($sql,__LINE__,__FILE__);
1123 while($this->db->next_record()) {
1124 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1125 $assignment_list[$i]['name'] = $this->db->f('name');
1126 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1130 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
1131 $this->db->query($sql,__LINE__,__FILE__);
1132 $total_records = $this->db->num_rows();
1135 while ($this->db->next_record()) {
1136 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1137 $activity_list[$i]['date'] = $this->db->f('date');
1138 $activity_list[$i]['activity'] = $this->db->f('activity');
1142 $indiv_width=275; $willing_width=40; $assignment_width=50;
1143 $total_width=$indiv_width+$willing_width;
1145 for ($i=0; $i < count($assignment_list); $i++) {
1146 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1147 $this->t->set_var('assignment_abbreviation',$assignment_list[$i]['abbreviation']);
1148 $this->t->fp('list1','header_list',True);
1149 $total_width += $assignment_width;
1150 $total_willing[$i] = 0;
1153 for ($i=0; $i < count($individual); $i++) {
1154 $willing_table = ''; $indiv_willing=0;
1155 $this->t->set_var('individual_name',$indiv_name[$i]);
1156 $this->t->set_var('individual_phone',$indiv_phone[$individual[$i]]);
1157 $this->t->set_var('editurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_update&individual=' .
1158 $individual[$i] . '&action=' . 'edit'));
1159 for ($j=0; $j < count($assignment_list); $j++) {
1160 $found_willingness=0;
1161 $sql = "SELECT * FROM tc_willingness where " .
1162 " assignment=" . $assignment_list[$j]['assignment'] .
1163 " AND individual=" . $individual[$i];
1164 $this->db->query($sql,__LINE__,__FILE__);
1165 while($this->db->next_record()) {
1166 $found_willingness=1;
1168 $sql = "SELECT * FROM tc_activity where " .
1169 " assignment=". $assignment_list[$j]['assignment'] .
1170 " ORDER by date DESC";
1171 $this->db2->query($sql,__LINE__,__FILE__);
1172 if($this->db2->next_record()) {
1173 $activity = $this->db2->f('activity');
1174 $date = $this->db2->f('date');
1175 $sql = "SELECT * FROM tc_participation where " .
1176 " activity=" . $activity .
1177 " AND individual=". $individual[$i];
1178 $this->db3->query($sql,__LINE__,__FILE__);
1179 if($this->db3->next_record()) {
1184 if($this->db->f('willing') == 'y') {
1185 $total_willing[$j]++;
1187 $willing_table .= '<td align=center><img src="images/checkmark.gif"><br><font size=-2>'.$date_part.'</font></td></td>';
1188 } else if($this->db->f('willing') == 'n') {
1189 $willing_table .= '<td align=center><img src="images/x.gif"></td>';
1192 $willing_table .= "<td> </td>";
1195 if(!$found_willingness) {
1197 $willing_table .= "<td> </td>";
1200 if(($indiv_willing == 1) || ($filter_unwilling == 'n')) {
1201 $this->t->set_var('willing_table',$willing_table);
1202 $this->t->fp('list2','individual_list',True);
1203 $this->nextmatchs->template_alternate_row_color(&$this->t);
1207 $stat_table = '<td><b>Total Willing to Serve</b></td>';
1208 for ($j=0; $j < count($assignment_list); $j++) {
1209 $stat_table .= "<td align=center><b>".$total_willing[$j]."</b></td>";
1211 $this->t->set_var('stat_table',$stat_table);
1213 $this->t->set_var('total_width',$total_width);
1214 $this->t->set_var('individual_width',$indiv_width);
1215 $this->t->set_var('willing_width',$willing_width);
1216 $this->t->pfp('out','willing_view_t');
1217 $this->save_sessiondata();
1220 function willing_update()
1222 //print "<font color=red>Willingness Update Under Constrcution</font>";
1223 //$this->willing_view();
1226 $this->t->set_file(array('willing_update_t' => 'willing_update.tpl'));
1227 $this->t->set_block('willing_update_t','assignment_list','list');
1228 $this->t->set_block('willing_update_t','save','savehandle');
1230 $individual = get_var('individual',array('GET','POST'));
1231 $this->t->set_var('individual',$individual);
1232 $action = get_var('action',array('GET','POST'));
1234 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_view'));
1235 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_update&action=save'));
1236 $this->t->set_var('lang_done','Cancel');
1237 $this->t->set_var('title','Willingness Update ');
1239 if($action == 'save') {
1240 // Delete all the previous willingness entries for this individual
1241 $this->db->query("DELETE from tc_willingness where individual=" . $individual ,__LINE__,__FILE__);
1243 // Now, add the assignment willingness that is checked for this individual
1244 $new_data = get_var('willingness',array('POST'));
1245 foreach ($new_data as $data) {
1246 $data_array = explode("/",$data);
1247 $assignment = $data_array[0];
1248 $willing = $data_array[1];
1249 //print "individual: $individual assignment: $assignment willing: $willing<br>";
1250 $this->db->query("INSERT INTO tc_willingness (individual,assignment,willing) " .
1251 "VALUES (" . $individual .",". $assignment .",'". $willing . "')",__LINE__,__FILE__);
1253 $this->willing_view();
1257 $assignment_width=300; $willing_width=25; $table_width=$assignment_width + $willing_width;
1260 // Find out the individual's name
1261 $sql = "SELECT * FROM tc_individual WHERE individual=".$individual." AND valid=1";
1262 $this->db->query($sql,__LINE__,__FILE__);
1263 if($this->db->next_record()) {
1264 $indiv_name = $this->db->f('name');
1265 $this->t->set_var('individual_name',$indiv_name);
1268 // Select all the assignments
1269 $sql = "SELECT * FROM tc_assignment ORDER by name ASC";
1270 $this->db->query($sql,__LINE__,__FILE__);
1272 while ($this->db->next_record()) {
1273 $assignment = $this->db->f('assignment');
1274 $assignment_name = $this->db->f('name');
1275 $assignment_abbreviation = $this->db->f('abbreviation');
1277 $this->nextmatchs->template_alternate_row_color(&$this->t);
1278 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$assignment_name</td>";
1280 $header_row="<th width=$comp_width><font size=-2>Assignments</th><th>Willingness</th>";
1281 $sql = "SELECT * FROM tc_willingness WHERE individual=".$individual." AND assignment=".$assignment;
1282 $this->db2->query($sql,__LINE__,__FILE__);
1283 $value = $assignment;
1285 if($this->db2->next_record()) {
1286 if($this->db2->f('willing') == 'y') {
1287 $table_data .= '<td width=100 align=center>';
1288 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y" checked>Y';
1289 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1290 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/"> ';
1291 $table_data .= '</td>';
1292 } else if($this->db2->f('willing') == 'n') {
1293 $table_data .= '<td width=100 align=center>';
1294 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1295 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n" checked>N';
1296 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/">';
1297 $table_data .= '</td>';
1299 $table_data .= '<td width=100 align=center>';
1300 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1301 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1302 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1303 $table_data .= '</td>';
1306 $table_data .= '<td width=100 align=center>';
1307 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1308 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1309 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1310 $table_data .= '</td>';
1313 $table_data .= "\n";
1314 $table_data .= "</tr>";
1315 $table_data .= "<tr><td colspan=20></td></tr>";
1318 $table_data .= "<tr><td colspan=20><hr></td></tr>";
1320 $this->t->set_var('table_width',$table_width);
1321 $this->t->set_var('header_row',$header_row);
1322 $this->t->set_var('table_data',$table_data);
1323 $this->t->fp('list','assignment_list',True);
1325 $this->t->set_var('lang_reset','Clear Form');
1326 $this->t->set_var('lang_save','Save Changes');
1327 $this->t->set_var('savehandle','');
1329 $this->t->pfp('out','willing_update_t');
1330 $this->t->pfp('addhandle','save');
1332 $this->save_sessiondata();
1336 function ppi_sched()
1338 $this->t->set_file(array('ppi_sched_t' => 'ppi_sched.tpl'));
1339 $this->t->set_block('ppi_sched_t','individual_list','indivlist');
1340 $this->t->set_block('ppi_sched_t','appt_list','apptlist');
1341 $action = get_var('action',array('GET','POST'));
1343 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1344 $this->t->set_var('lang_reset','Clear Changes');
1346 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
1347 $this->t->set_var('ppi_link_title','Yearly PPIs');
1349 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
1350 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
1352 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched&action=save'));
1353 $this->t->set_var('title','Yearly PPI Scheduler');
1355 $indiv_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $ppi_date_width=20;
1356 $table_width=$indiv_width + $phone_width + $pri_width + $notes_width + $ppi_date_width;
1357 $header_row = "<th width=$indiv_width><font size=-2>individual Name</th>";
1358 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1359 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1360 $header_row.= "<th width=$ppi_date_width><font size=-2>Last PPI</th>";
1361 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1362 $table_data=""; $completed_data=""; $totals_data="";
1366 // Get the President
1367 $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";
1368 $this->db->query($sql,__LINE__,__FILE__);
1369 if($this->db->next_record()) {
1370 $president_name = $this->db->f('name');
1371 $president_name_array = explode(",",$president_name);
1372 $president_last_name = $president_name_array[0];
1373 $president_id = $this->db->f('individual');
1374 $presidency_id = $this->db->f('presidency');
1375 $interviewer = $this->db->f('individual');
1376 $district_number = '*';
1377 $district_name = $president_name;
1378 $president_address = $this->db->f('address');
1380 print "<hr><font color=red><h3>-E- Unable to locate President in tc_presidency table</h3></font></hr>";
1384 if($action == 'save') {
1385 // Save any changes made to the appointment table
1386 $new_data = get_var('appt_notes',array('POST'));
1387 if($new_data != "") {
1388 foreach ($new_data as $entry) {
1389 $indiv = $entry['individual'];
1390 $appointment = $entry['appointment'];
1391 $location = $entry['location'];
1392 if($location == "") { $location = "$president_last_name"." home ($president_address)"; }
1393 if($indiv == 0) { $location = ""; }
1395 //Only perform a database update if we have made a change to this appointment
1396 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and individual='$indiv' and location='$location'";
1397 $this->db->query($sql,__LINE__,__FILE__);
1398 if(!$this->db->next_record()) {
1399 // Perform database save actions here
1400 $this->db->query("UPDATE tc_appointment set " .
1401 " individual='" . $indiv . "'" .
1402 ",location='" . $location . "'" .
1403 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1404 // Email the appointment
1405 $this->email_appt($appointment);
1410 // Save any changes made to the ppi notes table
1411 $new_data = get_var('notes',array('POST'));
1412 foreach ($new_data as $entry) {
1413 $notes = $entry['notes'];
1414 $individual = $entry['individual'];
1415 $priority = $entry['pri'];
1417 // Perform database save actions here
1418 $sql = "SELECT * FROM tc_individual WHERE individual='$individual'";
1419 $this->db->query($sql,__LINE__,__FILE__);
1420 if ($this->db->next_record()) {
1421 $scheduling_priority = $this->db->f('scheduling_priority');
1422 //$this->logToFile("ppi_sched", "UPDATE tc_scheduling_priority SET priority='$priority', notes=\"$notes\" WHERE scheduling_priority='$scheduling_priority'");
1423 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$priority', notes=\"$notes\" WHERE scheduling_priority='$scheduling_priority'", __LINE__, __FILE__);
1427 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched');
1428 //Header('Location: ' . $take_me_to_url);
1431 // create the individual id -> individual name mapping
1432 $sql = "SELECT * FROM tc_individual where valid=1 and steward='$this->default_stewardship' ORDER BY name ASC";
1433 $this->db->query($sql,__LINE__,__FILE__);
1437 while ($this->db->next_record()) {
1438 $indiv_name[$i] = $this->db->f('name');
1439 $individual[$i] = $this->db->f('individual');
1442 array_multisort($indiv_name, $individual);
1444 // APPOINTMENT TABLE
1445 $date_width=250; $time_width=100; $indiv_width=200; $location_width=100;
1446 $appt_table_width=$date_width + $time_width + $indiv_width + $location_width;
1447 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1448 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1449 $appt_header_row.= "<th width=$indiv_width><font size=-2>indiv</th>";
1450 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
1451 $appt_table_data = "";
1453 $total_indivs=0; $indivs_with_yearly_ppi=0;
1455 // Display a scheduling table for the President
1456 $table_data=""; $appt_table_data="";
1457 $table_title = "District ".$district_number.": ".$district_name.": All indivs with Yearly PPI Not Completed";
1458 $appt_table_title = "District ".$district_number.": ".$district_name.": Yearly PPI Appointment Slots";
1459 $this->t->set_var('table_title',$table_title);
1460 $this->t->set_var('appt_table_title',$appt_table_title);
1462 // query the database for all the appointments
1463 $sql = "SELECT * FROM tc_appointment where presidency=".$presidency_id." and date>=CURDATE() ORDER BY date ASC, time ASC";
1464 $this->db->query($sql,__LINE__,__FILE__);
1466 while ($this->db->next_record()) {
1467 $appointment = $this->db->f('appointment');
1468 $indiv = $this->db->f('individual');
1469 $location = $this->db->f('location');
1470 if(($location == "") && ($indiv > 0)) { $location = "$president_last_name"." home ($president_address)"; }
1472 $date = $this->db->f('date');
1473 $date_array = explode("-",$date);
1474 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1475 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1477 $time = $this->db->f('time');
1478 $time_array = explode(":",$time);
1479 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1481 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1482 $appt_table_data.= "<td align=center>$day_string</td>";
1483 $appt_table_data.= "<td align=center>$time_string</td>";
1485 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][individual]>';
1486 $appt_table_data.= '<option value=0></option>';
1487 for ($i=0; $i < count($individual); $i++) {
1488 $id = $individual[$i];
1489 $name = $indiv_name[$i];
1490 if($individual[$i] == $indiv) {
1491 $selected[$id] = 'selected="selected"';
1493 $selected[$id] = '';
1495 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1497 $appt_table_data.='</select></td>';
1499 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
1500 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
1502 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1504 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1505 $this->t->set_var('tr_color',$tr_color);
1508 $this->t->set_var('appt_table_data',$appt_table_data);
1509 $this->t->set_var('appt_header_row',$appt_header_row);
1510 $this->t->set_var('appt_table_width',$appt_table_width);
1512 // PPI SCHEDULING TABLE
1513 $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";
1514 $this->db->query($sql,__LINE__,__FILE__);
1518 while ($this->db->next_record()) {
1519 $individual[$i] = $this->db->f('individual');
1520 $indiv_name[$i] = $this->db->f('name');
1521 $indiv_phone[$individual[$i]] = $this->db->f('phone');
1522 $indiv_priority[$individual[$i]] = $this->db->f('priority');
1523 $indiv_notes[$individual[$i]] = $this->db->f('notes');
1528 $max = count($individual);
1530 for($i=0; $i < $max; $i++) {
1531 $id = $individual[$i];
1532 $name = $indiv_name[$i];
1533 $phone = $indiv_phone[$id];
1534 $priority = $indiv_priority[$id];
1535 $notes = $indiv_notes[$id];
1537 // If this individual has had a yearly PPI this year, don't show him on the schedule list
1538 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
1539 $sql = "SELECT * FROM tc_interview WHERE date > '$year_start' AND date < '$year_end' ".
1540 "AND individual=" . $id . " AND interview_type='ppi'";
1541 $this->db2->query($sql,__LINE__,__FILE__);
1543 if(!$this->db2->next_record()) {
1544 $sql = "SELECT * FROM tc_interview WHERE individual=" . $id . " AND interview_type='ppi' ORDER BY date DESC";
1545 $this->db->query($sql,__LINE__,__FILE__);
1546 if($this->db->next_record()) {
1547 $date = $this->db->f('date');
1551 $link_data['menuaction'] = 'tc.tc.ppi_update';
1552 $link_data['individual'] = $id;
1553 $link_data['name'] = $name;
1554 $link_data['interview'] = '';
1555 $link_data['interview_type'] = 1;
1556 $link_data['action'] = 'add';
1557 $link_data['interviewer'] = $interviewer;
1558 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1559 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1560 $this->t->set_var('tr_color',$tr_color);
1561 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1562 $table_data.= "<td align=center>$phone</td>";
1563 //$table_data.= "<td align=center>$priority</td>";
1564 $table_data.= "<td align=center>";
1565 $table_data.= '<select name=notes['.$i.'][pri]>';
1566 foreach(range(0,6) as $num) {
1567 if($num == 0) { $num = 1; } else {$num = $num*5; }
1568 if($priority == $num) {
1569 $selected[$num] = 'selected="selected"';
1571 $selected[$num] = '';
1573 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1575 $table_data.= '</select></td>';
1576 $table_data.= "<td align=center>$date</td>";
1577 $table_data.= '<td><input type=text size="50" maxlength="128" name="notes['.$i.'][notes]" value="'.$notes.'">';
1578 $table_data.= '<input type=hidden name="notes['.$i.'][individual]" value="'.$id.'">';
1579 $table_data.= '<input type=hidden name="notes['.$i.'][indiv_name]" value="'.$name.'">';
1580 $table_data.= '</td>';
1581 $table_data.= '</tr>';
1583 $link_data['menuaction'] = 'tc.tc.ppi_update';
1584 $link_data['interviewer'] = $this->db2->f('interviewer');
1585 $link_data['individual'] = $this->db2->f('individual');
1586 $link_data['name'] = $name;
1587 $link_data['interview'] = $this->db2->f('interview');
1588 $link_data['interview_type'] = $this->db2->f('interview_type');
1589 $link_data['action'] = 'view';
1590 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1591 $indivs_with_yearly_ppi++;
1592 $date = $this->db2->f('date');
1593 $notes = $this->db2->f('notes');
1594 if(strlen($notes) > 40) { $notes = substr($notes,0,40) . "..."; }
1595 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1596 $this->t->set_var('tr_color2',$tr_color2);
1597 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1598 $completed_data.= "<td align=center>$phone</td>";
1599 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1600 $completed_data.= "<td align=left>$notes</td>";
1601 $completed_data.= '</tr>';
1603 } // End for individuals Loop
1605 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1606 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1607 $completed_header_row = "<th width=$name_width><font size=-2>Individual Name</th>";
1608 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1609 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1610 $completed_header_row.= "<th width=$notes_width><font size=-2>PPI Notes</th>";
1612 $this->t->set_var('table_width',$table_width);
1613 $this->t->set_var('header_row',$header_row);
1614 $this->t->set_var('table_data',$table_data);
1615 $this->t->set_var('completed_header_row',$completed_header_row);
1616 $this->t->set_var('completed_table_width',$completed_table_width);
1617 $this->t->set_var('completed',$completed_data);
1618 $this->t->fp('indivlist','individual_list',True);
1620 $indivs_width=300; $totals_width=100;
1621 $totals_table_width=$indivs_width + $totals_width;
1622 $totals_header_row = "<th width=$indivs_width><font size=-2>Individuals</th>";
1623 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
1624 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1625 $totals_data.= "<td align=left><font size=-2><b>Total Individuals with yearly PPIs completed:</b></font></td>";
1626 $totals_data.= "<td align=center><font size=-2><b>$indivs_with_yearly_ppi / $total_indivs</b></font></td>";
1627 $percent = ceil(($indivs_with_yearly_ppi / $total_indivs)*100);
1628 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1629 $this->t->set_var('tr_color',$tr_color);
1630 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1631 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
1632 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
1633 $totals_data.= "</tr>";
1635 $this->t->set_var('totals',$totals_data);
1636 $this->t->set_var('totals_header_row',$totals_header_row);
1637 $this->t->set_var('totals_table_width',$totals_table_width);
1639 $this->t->pfp('out','ppi_sched_t');
1640 $this->save_sessiondata();
1644 function int_sched()
1646 $this->t->set_file(array('int_sched_t' => 'int_sched.tpl'));
1647 $this->t->set_block('int_sched_t','individual_list','indivlist');
1648 $this->t->set_block('int_sched_t','appt_list','apptlist');
1649 $action = get_var('action',array('GET','POST'));
1651 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1652 $this->t->set_var('lang_reset','Clear Changes');
1654 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
1655 $this->t->set_var('int_link_title','Hometeaching Interviews');
1657 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
1658 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
1660 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched&action=save'));
1661 $this->t->set_var('title','Hometeaching Interviews Scheduler');
1663 $indiv_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $int_date_width=20;
1664 $table_width=$indiv_width + $phone_width + $pri_width + $notes_width + $int_date_width;
1665 $header_row = "<th width=$indiv_width><font size=-2>individual Name</th>";
1666 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1667 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1668 $header_row.= "<th width=$int_date_width><font size=-2>Last Interview</th>";
1669 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1670 $table_data=""; $completed_data=""; $totals_data="";
1674 $nextyear = $year + 1;
1675 if($month >= 1 && $month <= 3) { $quarter_start=$year."-01-01"; $quarter_end=$year."-04-01"; }
1676 if($month >= 4 && $month <= 6) { $quarter_start=$year."-04-01"; $quarter_end=$year."-07-01"; }
1677 if($month >= 7 && $month <= 9) { $quarter_start=$year."-07-01"; $quarter_end=$year."-10-01"; }
1678 if($month >= 10 && $month <= 12) { $quarter_start=$year."-10-01"; $quarter_end=$nextyear."-01-01"; }
1679 //print "year: $year month: $month quarter_start: $quarter_start quarter_end: $quarter_end<br>";
1681 // create the individual id -> individual name mapping
1682 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY name ASC";
1683 $this->db->query($sql,__LINE__,__FILE__);
1685 $individual_data = NULL;
1686 $indiv_name_data = NULL;
1687 while ($this->db->next_record()) {
1688 $indiv_name_data[$i] = $this->db->f('name');
1689 $individual_data[$i] = $this->db->f('individual');
1690 $individ2name[$individual_data[$i]] = $indiv_name_data[$i];
1693 // add any YM that are home teachers
1694 $sql = "SELECT * FROM tc_companionship where valid=1";
1695 $this->db->query($sql,__LINE__,__FILE__);
1696 while ($this->db->next_record()) {
1697 $tmp_individual = $this->db->f('individual');
1698 $sql = "Select * FROM tc_individual where individual='$tmp_individual' and steward='' and valid=1";
1699 $this->db2->query($sql,__LINE__,__FILE__);
1700 while ($this->db2->next_record()) {
1701 $indiv_name_data[$i] = $this->db2->f('name');
1702 $individual_data[$i] = $this->db2->f('individual');
1703 $individ2name[$individual_data[$i]] = $indiv_name_data[$i];
1707 array_multisort($indiv_name_data, $individual_data);
1709 if($action == 'save') {
1710 // Save any changes made to the appointment table
1711 $new_data = get_var('appt_notes',array('POST'));
1712 if($new_data != "") {
1713 foreach ($new_data as $entry) {
1714 $indiv = $entry['individual'];
1715 $appointment = $entry['appointment'];
1716 $location = $entry['location'];
1717 if($location == "") {
1718 $supervisor = $entry['supervisor'];
1719 $supervisor_array = explode(",", $individ2name[$supervisor]);
1720 $supervisor_last_name = $supervisor_array[0];
1721 $sql = "SELECT * FROM tc_individual where individual='$supervisor'";
1722 $this->db2->query($sql,__LINE__,__FILE__);
1723 if($this->db2->next_record()) {
1724 $mls_id = $this->db2->f('mls_id');
1726 $sql = "SELECT * FROM tc_individual where mls_id='$mls_id'";
1727 $this->db2->query($sql,__LINE__,__FILE__);
1728 if($this->db2->next_record()) {
1729 $supervisor_address = $this->db2->f('address');
1731 $location = "$supervisor_last_name"." home ($supervisor_address)";
1733 if($indiv == 0) { $location = ""; }
1735 //print "indiv: $indiv appointment: $appointment <br>";
1736 //Only perform a database update if we have made a change to this appointment
1737 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and individual='$indiv' and location='$location'";
1738 $this->db->query($sql,__LINE__,__FILE__);
1739 if(!$this->db->next_record()) {
1740 // Perform database save actions here
1741 $this->db->query("UPDATE tc_appointment set " .
1742 " individual='" . $indiv . "'" .
1743 ",location='" . $location . "'" .
1744 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1745 // Email the appointment
1746 $this->email_appt($appointment);
1751 // Save any changes made to the int notes table
1752 $new_data = get_var('hti_notes',array('POST'));
1753 foreach ($new_data as $entry) {
1754 $hti_notes = $entry['notes'];
1755 $individual = $entry['individual'];
1756 $indiv_name = $entry['indiv_name'];
1757 $hti_pri = $entry['pri'];
1758 //print "hti_notes: $hti_notes indiv_name: $indiv_name <Br>";
1759 // Perform database save actions here
1760 $this->db->query("SELECT * FROM tc_companion WHERE individual=$individual and valid=1",__LINE__,__FILE__);
1761 if ($this->db->next_record()) {
1762 $scheduling_priority = $this->db->f('scheduling_priority');
1763 //$this->logToFile("int_sched", "UPDATE tc_scheduling_priority SET priority='$hti_pri', notes=\"$hti_notes\" WHERE scheduling_priority='$scheduling_priority'");
1764 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$hti_pri', notes=\"$hti_notes\" WHERE scheduling_priority='$scheduling_priority'",__LINE__,__FILE__);
1768 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched');
1769 //Header('Location: ' . $take_me_to_url);
1772 // Get the Districts
1773 $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";
1774 $this->db->query($sql,__LINE__,__FILE__);
1776 while ($this->db->next_record()) {
1777 $district = $this->db->f('district');
1778 $districts[$i]['district'] = $this->db->f('district');
1779 $districts[$i]['name'] = $this->db->f('name');
1780 $districts[$i]['supervisor'] = $this->db->f('supervisor');
1781 $districts[$i]['presidency'] = $this->db->f('presidency');
1785 // APPOINTMENT TABLE
1787 $date_width=250; $time_width=100; $indiv_width=200; $location_width=100;
1788 $appt_table_width=$date_width + $time_width + $indiv_width + $location_width;
1789 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1790 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1791 $appt_header_row.= "<th width=$indiv_width><font size=-2>Individual</th>";
1792 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
1793 $appt_table_data = "";
1795 $total_comps=0; $comps_with_quarterly_int=0;
1797 // Display a scheduling table for each district
1798 for ($d=0; $d < count($districts); $d++) {
1799 $table_data=""; $appt_table_data="";
1800 $this->t->set_var('district_number',$districts[$d]['district']);
1801 $this->t->set_var('district_name',$districts[$d]['name']);
1802 $supervisor = $districts[$d]['supervisor'];
1803 $supervisor_array = explode(",", $supervisor);
1804 $supervisor_last_name = $supervisor_array[0];
1805 $sql = "SELECT * FROM tc_individual where individual='$supervisor'";
1806 $this->db2->query($sql,__LINE__,__FILE__);
1807 if($this->db2->next_record()) {
1808 $mls_id = $this->db2->f('mls_id');
1810 $sql = "SELECT * FROM tc_individual where mls_id='$mls_id'";
1811 $this->db2->query($sql,__LINE__,__FILE__);
1812 if($this->db2->next_record()) {
1813 $supervisor_address = $this->db2->f('address');
1815 $location = "$supervisor_last_name"." home ($supervisor_address)";
1816 $table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": All Individuals with Interviews Not Completed";
1817 $appt_table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": Interview Appointment Slots";
1818 $this->t->set_var('table_title',$table_title);
1819 $this->t->set_var('appt_table_title',$appt_table_title);
1821 // query the database for all the appointments
1822 $sql = "SELECT * FROM tc_appointment where presidency=".$districts[$d]['presidency']." and date>=CURDATE() ORDER BY date ASC, time ASC";
1823 $this->db->query($sql,__LINE__,__FILE__);
1825 while ($this->db->next_record()) {
1826 $appointment = $this->db->f('appointment');
1827 $indiv = $this->db->f('individual');
1828 $location = $this->db->f('location');
1829 if(($location == "") && ($indiv > 0)) { $location = "$supervisor_last_name"." home ($supervisor_address)"; }
1831 $date = $this->db->f('date');
1832 $date_array = explode("-",$date);
1833 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1834 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1836 $time = $this->db->f('time');
1837 $time_array = explode(":",$time);
1838 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1840 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1841 $appt_table_data.= "<td align=center>$day_string</td>";
1842 $appt_table_data.= "<td align=center>$time_string</td>";
1844 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][individual]>';
1845 $appt_table_data.= '<option value=0></option>';
1846 for ($i=0; $i < count($individual_data); $i++) {
1847 $id = $individual_data[$i];
1848 $name = $indiv_name_data[$i];
1849 if($individual_data[$i] == $indiv) {
1850 $selected[$id] = 'selected="selected"';
1852 $selected[$id] = '';
1854 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1856 $appt_table_data.='</select></td>';
1858 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
1859 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
1861 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1862 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][supervisor]" value="'.$supervisor.'">';
1864 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1865 $this->t->set_var('tr_color',$tr_color);
1868 $this->t->set_var('appt_table_data',$appt_table_data);
1869 $this->t->set_var('appt_header_row',$appt_header_row);
1870 $this->t->set_var('appt_table_width',$appt_table_width);
1872 // INTERVIEW SCHEDULING TABLE
1874 // Select all the unique companionship numbers for this district
1875 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$d]['district'];
1876 $this->db->query($sql,__LINE__,__FILE__);
1877 $j=0; $unique_companionships = '';
1878 while ($this->db->next_record())
1880 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
1885 for ($j=0; $j < count($unique_companionships); $j++) {
1886 // Select all the companions from each companionship
1887 $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'];
1888 $this->db->query($sql,__LINE__,__FILE__);
1889 $k=0; $int_completed=0;
1890 $comp = $unique_companionships[$j]['companionship'];
1891 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1892 $this->t->set_var('tr_color',$tr_color);
1894 while ($this->db->next_record()) {
1895 // Get this companions information
1896 $individual = $this->db->f('individual');
1898 $id = $this->db->f('individual');
1899 $name = $this->db->f('name');
1900 $phone = $this->db->f('phone');
1901 $hti_pri = $this->db->f('priority');
1902 $hti_notes = $this->db->f('notes');
1904 // If the companionship has already had its quarterly interview,
1905 // Skip the other companion in the companionship.
1906 if($int_completed == 1) {
1907 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1908 $completed_data.= "<td align=center>$phone</td>";
1909 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1910 $completed_data.= "<td align=left>$hti_notes</td>";
1911 $completed_data.= '</tr>';
1912 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1913 $this->t->set_var('tr_color2',$tr_color2);
1914 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1915 $this->t->set_var('tr_color',$tr_color);
1919 // If this companionship has had a hometeaching interview this quarter, don't show them on the schedule list
1920 $sql = "SELECT * FROM tc_interview WHERE date >= '$quarter_start' AND date < '$quarter_end' AND individual='$id'";
1921 $this->db2->query($sql,__LINE__,__FILE__);
1923 if(!$this->db2->next_record()) {
1924 $sql = "SELECT * FROM tc_interview WHERE individual='$id' ORDER BY date DESC";
1925 $this->db3->query($sql,__LINE__,__FILE__);
1926 if($this->db3->next_record()) {
1927 $date = $this->db3->f('date');
1931 $link_data['menuaction'] = 'tc.tc.int_update';
1932 $link_data['individual'] = $id;
1933 $link_data['name'] = $name;
1934 $link_data['interview'] = '';
1935 $link_data['action'] = 'add';
1936 $link_data['interview_type'] = 'hti';
1937 $link_data['interviewer'] = $districts[$d]['supervisor'];
1938 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1939 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1940 $table_data.= "<td align=center>$phone</td>";
1941 $table_data.= "<td align=center>";
1942 $table_data.= '<select name=hti_notes['.$i.'][pri]>';
1943 foreach(range(0,6) as $num) {
1944 if($num == 0) { $num = 1; } else {$num = $num*5; }
1945 if($hti_pri == $num) {
1946 $selected[$num] = 'selected="selected"';
1948 $selected[$num] = '';
1950 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1952 $table_data.= '</select></td>';
1953 $table_data.= "<td align=center>$date</td>";
1954 $table_data.= '<td><input type=text size="50" maxlength="128" name="hti_notes['.$i.'][notes]" value="'.$hti_notes.'">';
1955 $table_data.= '<input type=hidden name="hti_notes['.$i.'][individual]" value="'.$id.'">';
1956 $table_data.= '<input type=hidden name="hti_notes['.$i.'][indiv_name]" value="'.$name.'">';
1957 $table_data.= '</td>';
1958 $table_data.= '</tr>'."\n";
1961 $link_data['menuaction'] = 'tc.tc.int_update';
1962 $link_data['interviewer'] = $this->db2->f('interviewer');
1963 $link_data['individual'] = $this->db2->f('individual');
1964 $link_data['name'] = $name;
1965 $link_data['interview'] = $this->db2->f('interview');
1966 $link_data['interview_type'] = 'hti';
1967 $link_data['action'] = 'view';
1968 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1969 $comps_with_quarterly_int++;
1971 $date = $this->db2->f('date');
1972 $hti_notes = $this->db2->f('notes');
1973 if(strlen($hti_notes) > 40) { $hti_notes = substr($hti_notes,0,40) . "..."; }
1974 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1975 $completed_data.= "<td align=center>$phone</td>";
1976 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1977 $completed_data.= "<td align=left>$hti_notes</td>";
1978 $completed_data.= '</tr>';
1983 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1984 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1985 $completed_header_row = "<th width=$name_width><font size=-2>Individual Name</th>";
1986 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1987 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1988 $completed_header_row.= "<th width=$notes_width><font size=-2>Interview Notes</th>";
1990 $this->t->set_var('table_width',$table_width);
1991 $this->t->set_var('header_row',$header_row);
1992 $this->t->set_var('table_data',$table_data);
1993 $this->t->set_var('completed_header_row',$completed_header_row);
1994 $this->t->set_var('completed_table_width',$completed_table_width);
1995 $this->t->set_var('completed',$completed_data);
1996 $this->t->fp('indivlist','individual_list',True);
1998 } // End for each district loop
2001 $indivs_width=300; $totals_width=100;
2002 $totals_table_width=$indivs_width + $totals_width;
2003 $totals_header_row = "<th width=$indivs_width><font size=-2>Individuals</th>";
2004 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2005 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2006 $totals_data.= "<td align=left><font size=-2><b>Total Companionships with interviews completed:</b></font></td>";
2007 $totals_data.= "<td align=center><font size=-2><b>$comps_with_quarterly_int / $total_comps</b></font></td>";
2008 $percent = ceil(($comps_with_quarterly_int / $total_comps)*100);
2009 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2010 $this->t->set_var('tr_color',$tr_color);
2011 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2012 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2013 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2014 $totals_data.= "</tr>";
2016 $this->t->set_var('totals',$totals_data);
2017 $this->t->set_var('totals_header_row',$totals_header_row);
2018 $this->t->set_var('totals_table_width',$totals_table_width);
2020 $this->t->pfp('out','int_sched_t');
2021 $this->save_sessiondata();
2025 function vis_sched()
2027 $this->t->set_file(array('vis_sched_t' => 'vis_sched.tpl'));
2028 $this->t->set_block('vis_sched_t','family_list','familylist');
2029 $this->t->set_block('vis_sched_t','appt_list','apptlist');
2030 $action = get_var('action',array('GET','POST'));
2032 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
2033 $this->t->set_var('lang_reset','Clear Changes');
2035 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2036 $this->t->set_var('vis_link_title','View Yearly Visits');
2038 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
2039 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2041 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched&action=save'));
2042 $this->t->set_var('title','Presidency Yearly Visit Scheduler');
2044 $family_width=500; $phone_width=40; $pri_width=10; $notes_width=128; $visit_date_width=20;
2045 $table_width=$family_width + $phone_width + $pri_width + $notes_width + $visit_date_width;
2046 $header_row = "<th width=$family_width><font size=-2>Family Name</th>";
2047 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2048 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
2049 $header_row.= "<th width=$visit_date_width><font size=-2>Last Visit</th>";
2050 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
2051 $table_data=""; $completed_data=""; $totals_data="";
2055 // create the family id -> family name mapping
2056 $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";
2057 $this->db->query($sql,__LINE__,__FILE__);
2060 while ($this->db->next_record()) {
2061 $family_id[$i] = $this->db->f('family');
2062 $family_name[$i] = $this->db->f('name');
2063 $familyid2name[$family_id[$i]] = $family_name[$i];
2064 $familyid2address[$family_id[$i]] = $this->db->f('address');
2067 array_multisort($family_name, $family_id);
2069 if($action == 'save') {
2070 // Save any changes made to the appointment table
2071 $new_data = get_var('appt_notes',array('POST'));
2072 if($new_data != "") {
2073 foreach ($new_data as $entry) {
2074 $family = $entry['family'];
2075 $appointment = $entry['appointment'];
2076 $location = $entry['location'];
2077 if($location == "") {
2078 $family_name_array = explode(",", $familyid2name[$family]);
2079 $family_last_name = $family_name_array[0];
2080 $family_address = $familyid2address[$family];
2081 $location = "$family_last_name"." home ($family_address)";
2083 if($family == 0) { $location = ""; }
2085 //Only perform a database update if we have made a change to this appointment
2086 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and family='$family' and location='$location'";
2087 $this->db->query($sql,__LINE__,__FILE__);
2088 if(!$this->db->next_record()) {
2089 // Perform database save actions here
2090 $this->db->query("UPDATE tc_appointment set " .
2091 " family='" . $family . "'" .
2092 ",location='" . $location . "'" .
2093 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
2095 // Email the appointment
2096 $this->email_appt($appointment);
2101 // Save any changes made to the visit notes table
2102 $new_data = get_var('vis_notes',array('POST'));
2103 foreach ($new_data as $entry) {
2104 $visit_notes = $entry['notes'];
2105 $family = $entry['family_id'];
2106 $visit_pri = $entry['pri'];
2107 // Perform database save actions here
2108 $this->db->query("SELECT * FROM tc_family WHERE family='$family'",__LINE__,__FILE__);
2109 if ($this->db->next_record()) {
2110 $scheduling_priority = $this->db->f('scheduling_priority');
2111 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$visit_pri', notes=\"$visit_notes\" WHERE scheduling_priority='$scheduling_priority'", __LINE__, __FILE__);
2115 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched');
2116 //Header('Location: ' . $take_me_to_url);
2119 // APPOINTMENT TABLE
2120 $date_width=250; $time_width=100; $family_width=250; $location_width=100;
2121 $appt_table_width=$date_width + $time_width + $family_width + $location_width;
2122 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
2123 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
2124 $appt_header_row.= "<th width=$family_width><font size=-2>Family</th>";
2125 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
2126 $appt_table_data = "";
2128 // Find out what the President ID is
2129 $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";
2130 $this->db->query($sql,__LINE__,__FILE__);
2131 if($this->db->next_record()) {
2132 $presidency_name = $this->db->f('name');
2133 $presidency_id = $this->db->f('presidency');
2135 print "<hr><font color=red><h3>-E- Unable to locate Presidency in tc_presidency table</h3></font></hr>";
2139 // query the database for all the appointments
2140 $sql = "SELECT * FROM tc_appointment where presidency=$presidency_id and date>=CURDATE() ORDER BY date ASC, time ASC";
2141 $this->db->query($sql,__LINE__,__FILE__);
2143 while ($this->db->next_record()) {
2144 $appointment = $this->db->f('appointment');
2145 $family = $this->db->f('family');
2146 $location = $this->db->f('location');
2147 $family_name_array = explode(",", $familyid2name[$family]);
2148 $family_last_name = $family_name_array[0];
2149 $family_address = $familyid2address[$family];
2150 if(($location == "") && ($family > 0)) { $location = "$family_last_name"." home ($family_address)"; }
2152 $date = $this->db->f('date');
2153 $date_array = explode("-",$date);
2154 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
2155 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
2157 $time = $this->db->f('time');
2158 $time_array = explode(":",$time);
2159 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
2161 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2162 $appt_table_data.= "<td align=center>$day_string</td>";
2163 $appt_table_data.= "<td align=center>$time_string</td>";
2165 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][family]>';
2166 $appt_table_data.= '<option value=0></option>';
2167 for ($i=0; $i < count($family_id); $i++) {
2168 $id = $family_id[$i];
2169 $name = $family_name[$i];
2170 if($family_id[$i] == $family) {
2171 $selected[$id] = 'selected="selected"';
2173 $selected[$id] = '';
2175 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
2177 $appt_table_data.='</select></td>';
2179 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
2180 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
2182 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
2184 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2185 $this->t->set_var('tr_color',$tr_color);
2188 $this->t->set_var('appt_table_data',$appt_table_data);
2189 $this->t->set_var('appt_header_row',$appt_header_row);
2190 $this->t->set_var('appt_table_width',$appt_table_width);
2193 // VISIT SCHEDULING TABLE
2194 $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";
2195 $this->db->query($sql,__LINE__,__FILE__);
2197 $total_families=0; $families_with_yearly_visit=0;
2199 while ( $this->db->next_record()) {
2201 $id = $this->db->f('family');
2202 $name = $this->db->f('name');
2203 $phone = $this->db->f('phone');
2204 $vis_pri = $this->db->f('priority');
2205 $vis_notes = $this->db->f('notes');
2207 // If this family has had a yearly visit this year, don't show them on the schedule list
2208 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2209 $sql = "SELECT * FROM tc_visit WHERE date > '$year_start' AND date < '$year_end' ".
2210 "AND family=" . $id . " AND companionship=0";
2211 $this->db2->query($sql,__LINE__,__FILE__);
2213 if(!$this->db2->next_record()) {
2214 $sql = "SELECT * FROM tc_visit WHERE family=" . $id . " AND companionship=0 ORDER BY date DESC";
2215 $this->db3->query($sql,__LINE__,__FILE__);
2216 if($this->db3->next_record()) {
2217 $date = $this->db3->f('date');
2221 $link_data['menuaction'] = 'tc.tc.vis_update';
2222 $link_data['visit'] = '';
2223 $link_data['family'] = $id;
2224 $link_data['name'] = $name;
2225 $link_data['action'] = 'add';
2226 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2227 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2228 $table_data.= "<td align=center>$phone</td>";
2229 $table_data.= "<td align=center>";
2230 $table_data.= '<select name=vis_notes['.$id.'][pri]>';
2231 foreach(range(0,6) as $num) {
2232 if($num == 0) { $num = 1; } else {$num = $num*5; }
2233 if($vis_pri == $num) {
2234 $selected[$num] = 'selected="selected"';
2236 $selected[$num] = '';
2238 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2240 $table_data.= '</select></td>';
2241 $table_data.= "<td align=center>$date</td>";
2242 $table_data.= '<td><input type=text size="50" maxlength="128" name="vis_notes['.$id.'][notes]" value="'.$vis_notes.'">';
2243 $table_data.= '<input type=hidden name="vis_notes['.$id.'][family_id]" value="'.$id.'">';
2244 $table_data.= '<input type=hidden name="vis_notes['.$id.'][family_name]" value="'.$name.'">';
2245 $table_data.= '</td>';
2246 $table_data.= '</tr>';
2247 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2248 $this->t->set_var('tr_color',$tr_color);
2250 $link_data['menuaction'] = 'tc.tc.vis_update';
2251 $link_data['visit'] = $this->db2->f('visit');
2252 $link_data['family'] = $this->db2->f('family');
2253 $link_data['name'] = $name;
2254 $link_data['date'] = $this->db2->f('date');
2255 $link_data['action'] = 'view';
2256 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2257 $families_with_yearly_visit++;
2258 $date = $this->db2->f('date');
2259 $vis_notes = $this->db2->f('notes');
2260 if(strlen($vis_notes) > 40) { $vis_notes = stripslashes(substr($vis_notes,0,40) . "..."); }
2261 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2262 $completed_data.= "<td align=center>$phone</td>";
2263 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2264 $completed_data.= "<td align=left>$vis_notes</td>";
2265 $completed_data.= '</tr>';
2266 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
2267 $this->t->set_var('tr_color2',$tr_color2);
2271 $name_width=190; $phone_width=100; $date_width=100; $notes_width=300;
2272 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
2273 $completed_header_row = "<th width=$name_width><font size=-2>Family Name</th>";
2274 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2275 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
2276 $completed_header_row.= "<th width=$notes_width><font size=-2>Visit Notes</th>";
2278 $family_width=300; $totals_width=100;
2279 $totals_table_width=$family_width + $totals_width;
2280 $totals_header_row = "<th width=$family_width><font size=-2>Families</th>";
2281 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2282 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2283 $totals_data.= "<td align=left><font size=-2><b>Total Families with yearly Visits completed:</b></font></td>";
2284 $totals_data.= "<td align=center><font size=-2><b>$families_with_yearly_visit / $total_families</b></font></td>";
2285 $percent = ceil(($families_with_yearly_visit / $total_families)*100);
2286 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2287 $this->t->set_var('tr_color',$tr_color);
2288 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2289 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2290 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2291 $totals_data.= "</tr>";
2293 $this->t->set_var('table_width',$table_width);
2294 $this->t->set_var('header_row',$header_row);
2295 $this->t->set_var('table_data',$table_data);
2296 $this->t->set_var('totals_header_row',$totals_header_row);
2297 $this->t->set_var('totals_table_width',$totals_table_width);
2298 $this->t->set_var('completed_header_row',$completed_header_row);
2299 $this->t->set_var('completed_table_width',$completed_table_width);
2300 $this->t->set_var('completed',$completed_data);
2301 $this->t->set_var('totals',$totals_data);
2302 $this->t->fp('familylist','family_list',True);
2303 $this->t->fp('apptlist','appt_list',True);
2305 $this->t->pfp('out','vis_sched_t');
2306 $this->save_sessiondata();
2311 $this->t->set_file(array('ppi_view_t' => 'ppi_view.tpl'));
2312 $this->t->set_block('ppi_view_t','district_list','list');
2314 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2315 $num_months = get_var('num_months',array('GET','POST'));
2316 if($num_months == '') { $num_months = $this->default_ppi_num_months; }
2317 $this->t->set_var('num_months',$num_months);
2318 if($num_months == 1) {
2319 $this->t->set_var('lang_num_months','Month of History');
2321 $this->t->set_var('lang_num_months','Months of History');
2323 $this->t->set_var('lang_filter','Filter');
2324 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2326 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2327 $this->t->set_var('ppi_link_title','Yearly PPIs');
2329 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
2330 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
2332 $this->t->set_var('title','Yearly PPIs');
2333 $num_months = get_var('num_months',array('GET','POST'));
2334 if($num_months == '') { $num_months = $this->default_ppi_num_years; }
2335 $this->t->set_var('num_months',$num_months);
2336 if($num_months == 1) {
2337 $this->t->set_var('lang_num_months','Year of History');
2339 $this->t->set_var('lang_num_months','Years of History');
2342 $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";
2343 $this->db->query($sql,__LINE__,__FILE__);
2344 if($this->db->next_record()) {
2345 $president_name = $this->db->f('name');
2346 $interviewer = $this->db->f('individual');
2348 print "<hr><font color=red><h3>-E- Unable to locate President in tc_presidency table</h3></font></hr>";
2351 $this->t->set_var('district_number','*');
2352 $this->t->set_var('district_name',$president_name);
2354 $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";
2355 $this->db->query($sql,__LINE__,__FILE__);
2357 while ($this->db->next_record()) {
2358 $individual[$i] = $this->db->f('individual');
2359 $indiv_name[$i] = $this->db->f('name');
2360 $indiv_phone[$individual[$i]] = $this->db->f('phone');
2361 $indiv_priority[$individual[$i]] = $this->db->f('priority');
2362 $indiv_notes[$individual[$i]] = $this->db->f('notes');
2366 array_multisort($indiv_name, $individual);
2367 //var_dump($indiv_name); print "<br><br>"; var_dump($individual);
2369 $header_row="<th width=$comp_width><font size=-2>Individual Name</th>";
2371 $indiv_width=400; $ppi_width=75; $table_width=$indiv_width + $num_months*$ppi_width;
2373 for($m=$num_months; $m >= 0; $m--) {
2374 $year = date('Y') - $m;
2375 $header_row .= "<th width=150><font size=-2>$year</th>";
2379 for ($j=0; $j < count($individual); $j++) {
2380 $id = $individual[$j];
2381 $name = $indiv_name[$j];
2382 $phone = $indiv_phone[$id];
2384 $link_data['menuaction'] = 'tc.tc.ppi_update';
2385 $link_data['interviewer'] = $interviewer;
2386 $link_data['individual'] = $id;
2387 $link_data['name'] = $name;
2388 $link_data['interview'] = '';
2389 $link_data['interview_type'] = 'ppi';
2390 $link_data['action'] = 'add';
2391 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2392 $this->nextmatchs->template_alternate_row_color(&$this->t);
2393 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2395 // Find out how many times PPIs were performed in the past $num_months for this individual
2396 for($m=$num_months; $m >= 0; $m--) {
2397 $year = date('Y') - $m;
2398 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2399 $sql = "SELECT * FROM tc_interview WHERE date > '$year_start' AND date < '$year_end' ".
2400 "AND individual=" . $id . " AND interview_type='ppi'";
2401 $this->db2->query($sql,__LINE__,__FILE__);
2403 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
2404 if($this->db2->next_record()) {
2405 $ppis[$m]++; $total_ppis[$m]++; $ppi_recorded[$companionship][$m]=1;
2406 $link_data['menuaction'] = 'tc.tc.ppi_update';
2407 $link_data['companionship'] = $companionship;
2408 $link_data['interviewer'] = $this->db2->f('interviewer');
2409 $link_data['indiv'] = $id;
2410 $link_data['name'] = $name;
2411 $link_data['interview'] = $this->db2->f('interview');
2412 $link_data['interview_type'] = 'ppi';
2413 $link_data['action'] = 'view';
2414 $date = $this->db2->f('date');
2415 $date_array = explode("-",$date);
2416 $month = $date_array[1];
2417 $day = $date_array[2];
2418 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2419 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2421 $table_data .= "<td> </td>";
2424 $table_data .= "</tr>\n";
2426 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2428 $stat_data = "<tr><td><b><font size=-2>$total_indivs Individuals<br>PPI Totals:</font></b></td>";
2429 for($m=$num_months; $m >=0; $m--) {
2430 $percent = ceil(($ppis[$m] / $total_indivs)*100);
2431 $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
2433 $stat_data .= "</tr>";
2435 $this->t->set_var('table_width',$table_width);
2436 $this->t->set_var('header_row',$header_row);
2437 $this->t->set_var('table_data',$table_data);
2438 $this->t->set_var('stat_data',$stat_data);
2439 $this->t->pfp('out','ppi_view_t');
2440 $this->save_sessiondata();
2443 function ppi_update()
2445 $this->t->set_file(array('form' => 'ppi_update.tpl'));
2446 $this->t->set_block('form','interviewer_list','int_list');
2447 $this->t->set_block('form','add','addhandle');
2448 $this->t->set_block('form','edit','edithandle');
2450 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2451 $this->t->set_var('readonly','');
2452 $this->t->set_var('disabled','');
2454 $action = get_var('action',array('GET','POST'));
2455 $companionship = get_var('companionship',array('GET','POST'));
2456 $interviewer = get_var('interviewer',array('GET','POST'));
2457 $name = get_var('name',array('GET','POST'));
2458 $interview = get_var('interview',array('GET','POST'));
2459 $individual = get_var('individual',array('GET','POST'));
2460 $date = get_var('date',array('GET','POST'));
2461 $notes = get_var('notes',array('GET','POST'));
2462 $interview_type = get_var('interview_type',array('GET','POST'));
2464 $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)";
2465 $this->db2->query($sql,__LINE__,__FILE__);
2466 while ($this->db2->next_record()) {
2467 $indiv = $this->db2->f('individual');
2468 $interviewer_name = $this->db2->f('name');
2469 if($indiv == $interviewer) {
2470 $this->t->set_var('interviewer',$interviewer . ' selected');
2472 $this->t->set_var('interviewer',$interviewer);
2474 $this->t->set_var('interviewer_name',$interviewer_name);
2475 $this->t->set_var('eqpresppi_checked','checked');
2476 $this->t->fp('int_list','interviewer_list',True);
2479 if($action == 'save') {
2480 $notes = get_var('notes',array('POST'));
2481 $this->db->query("UPDATE tc_interview set " .
2482 " interview='" . $interview . "'" .
2483 ", interviewer='" . $interviewer . "'" .
2484 ", individual='" . $individual . "'" .
2485 ", date='" . $date . "'" .
2486 ", notes='" . $notes . "'" .
2487 ", interview_type='" . $interview_type . "'" .
2488 " WHERE interview=" . $interview,__LINE__,__FILE__);
2493 if($action == 'insert') {
2494 $notes = get_var('notes',array('POST'));
2495 $this->db->query("INSERT INTO tc_interview (interviewer,individual,date,notes,interview_type) " .
2496 "VALUES ('" . $interviewer . "','" . $individual . "','" .
2497 $date . "','" . $notes . "','" . $interview_type ."')",__LINE__,__FILE__);
2502 if($action == 'add') {
2503 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2504 $this->t->set_var('interview', '');
2505 $this->t->set_var('interviewer', $interviewer);
2506 $this->t->set_var('name',$name);
2507 $this->t->set_var('individual',$individual);
2508 $this->t->set_var('date','');
2509 $this->t->set_var('notes','');
2510 $this->t->set_var('interview_type',$interview_type);
2511 $this->t->set_var('eqpresppi_checked','checked');
2512 $this->t->set_var('lang_done','Cancel');
2513 $this->t->set_var('lang_action','Adding New PPI');
2514 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview=' .
2515 $interview . '&action=' . 'insert'));
2518 if($action == 'edit' || $action == 'view') {
2519 $sql = "SELECT * FROM tc_interview WHERE interview=".$interview;
2520 $this->db->query($sql,__LINE__,__FILE__);
2521 $this->db->next_record();
2522 $this->t->set_var('interview',$interview);
2523 $this->t->set_var('name',$name);
2524 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2525 $this->t->set_var('individual',$this->db->f('individual'));
2526 $this->t->set_var('date',$this->db->f('date'));
2527 $this->t->set_var('notes',$this->db->f('notes'));
2528 $this->t->set_var('interview_type',$this->db->f('interview_type'));
2529 if($this->db->f('interview_type') == 'ppi') { $this->t->set_var('eqpresppi_checked','checked'); }
2532 if($action == 'edit') {
2533 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2534 $this->t->set_var('lang_done','Cancel');
2535 $this->t->set_var('lang_action','Editing PPI');
2536 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview='.
2537 $interview . '&action=' . 'save'));
2540 if($action == 'view') {
2541 $date = $this->db->f('date');
2542 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2543 $this->t->set_var('readonly','READONLY');
2544 $this->t->set_var('disabled','DISABLED');
2545 $this->t->set_var('lang_done','Done');
2546 $this->t->set_var('lang_action','Viewing PPI');
2547 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview=' .
2548 $interview . '&action=' . 'edit'));
2551 $this->t->set_var('lang_reset','Clear Form');
2552 $this->t->set_var('lang_add','Add PPI');
2553 $this->t->set_var('lang_save','Save Changes');
2554 $this->t->set_var('edithandle','');
2555 $this->t->set_var('addhandle','');
2557 $this->t->pfp('out','form');
2559 if($action == 'view') { $this->t->set_var('lang_save','Edit PPI'); }
2560 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2561 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2563 $this->save_sessiondata();
2568 $this->t->set_file(array('int_view_t' => 'int_view.tpl'));
2569 $this->t->set_block('int_view_t','district_list','list');
2571 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2572 $num_quarters = get_var('num_quarters',array('GET','POST'));
2573 if($num_quarters == '') { $num_quarters = $this->default_int_num_quarters; }
2574 $this->t->set_var('num_quarters',$num_quarters);
2575 if($num_quarters == 1) {
2576 $this->t->set_var('lang_num_quarters','Quarter of History');
2578 $this->t->set_var('lang_num_quarters','Quarters of History');
2580 $this->t->set_var('lang_filter','Filter');
2582 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2583 $this->t->set_var('int_link_title','Hometeaching Interviews');
2585 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
2586 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
2588 $this->t->set_var('title','Hometeaching Interviews');
2590 $num_months = $num_quarters * 3 - 1;
2591 $current_month = $this->current_month;
2592 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
2593 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
2594 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
2595 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
2597 $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";
2598 $this->db->query($sql,__LINE__,__FILE__);
2600 while ($this->db->next_record()) {
2601 $districts[$i]['district'] = $this->db->f('district');
2602 $districts[$i]['name'] = $this->db->f('name');
2603 $districts[$i]['supervisor'] = $this->db->f('supervisor');
2607 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
2608 $this->db->query($sql,__LINE__,__FILE__);
2610 while ($this->db->next_record()) {
2611 $individual[$i] = $this->db->f('individual');
2612 $indiv_name[$i] = $this->db->f('name');
2613 $indiv_phone[$individual[$i]] = $this->db->f('phone');
2616 array_multisort($indiv_name, $individual);
2617 for($i=0; $i < count($individual); $i++) {
2618 $id = $individual[$i];
2619 $indivs[$id] = $indiv_name[$i];
2622 $total_companionships = 0;
2623 $this->nextmatchs->template_alternate_row_color(&$this->t);
2624 for ($i=0; $i < count($districts); $i++) {
2625 $this->t->set_var('district_number',$districts[$i]['district']);
2626 $this->t->set_var('district_name',$districts[$i]['name']);
2627 $supervisor = $districts[$i]['supervisor'];
2629 // Select all the unique companionship numbers for this district
2630 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$i]['district'];
2631 $this->db->query($sql,__LINE__,__FILE__);
2632 $j=0; $unique_companionships = '';
2633 while ($this->db->next_record()) {
2634 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
2638 $comp_width=250; $int_width=75; $table_width=$comp_width + $num_months*$int_width;
2639 $table_data=""; $num_companionships = $j; $num_indivs = 0;
2640 for($m=$num_months; $m >= 0; $m--) { $ints[$m] = 0; }
2641 for ($j=0; $j < count($unique_companionships); $j++) {
2642 // Select all the companions in each companionship
2643 $sql = "SELECT * FROM tc_companion where valid=1 and ".
2644 "companionship=". $unique_companionships[$j]['companionship'];
2645 $this->db->query($sql,__LINE__,__FILE__);
2647 $comp = $unique_companionships[$j]['companionship'];
2648 for($m=$num_months; $m >= 0; $m--) { $int_recorded[$comp][$m] = 0; }
2649 while ($this->db->next_record()) {
2650 // Get this companions information
2652 $companionship = $this->db->f('companionship');
2653 $individual = $this->db->f('individual');
2654 $name = $indivs[$individual];
2655 $phone = $indiv_phone[$individual];
2656 $link_data['menuaction'] = 'tc.tc.int_update';
2657 $link_data['companionship'] = $companionship;
2658 $link_data['interviewer'] = $supervisor;
2659 $link_data['individual'] = $individual;
2660 $link_data['name'] = $name;
2661 $link_data['interview'] = '';
2662 $link_data['interview_type'] = 'hti';
2663 $link_data['action'] = 'add';
2664 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2665 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2667 // Find out how many times Interviews were performed in the past $num_months for this individual
2668 $header_row="<th width=$comp_width><font size=-2>Companionship</th>";
2669 for($m=$num_months; $m >= 0; $m--) {
2670 $month = $current_month - $m;
2671 $year = $this->current_year;
2673 $remainder = $month;
2674 $month = 12 + $remainder;
2677 if($month < 10) { $month = "0"."$month"; }
2678 $month_start = "$year"."-"."$month"."-"."01";
2679 $month_end = "$year"."-"."$month"."-"."31";
2680 $month = "$month"."/"."$year";
2681 $sql = "SELECT * FROM tc_interview WHERE date >= '$month_start' AND date <= '$month_end' ".
2682 "AND individual=" . $individual;
2683 $this->db2->query($sql,__LINE__,__FILE__);
2684 $header_row .= "<th width=$int_width><font size=-2>$month</th>";
2686 if(!$total_ints[$m]) { $total_ints[$m] = 0; }
2687 if($this->db2->next_record()) {
2688 if(!$int_recorded[$companionship][$m]) {
2691 $int_recorded[$companionship][$m]=1;
2693 $link_data['menuaction'] = 'tc.tc.int_update';
2694 $link_data['companionship'] = $companionship;
2695 $link_data['interviewer'] = $this->db2->f('interviewer');
2696 $link_data['individual'] = $individual;
2697 $link_data['name'] = $name;
2698 $link_data['interview'] = $this->db2->f('interview');
2699 $link_data['action'] = 'view';
2700 $link_data['interview_type'] = 'hti';
2701 $date = $this->db2->f('date');
2702 $date_array = explode("-",$date);
2703 $month = $date_array[1];
2704 $day = $date_array[2];
2705 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2706 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2709 $table_data .= "<td> </td>";
2712 $table_data .= "</tr>";
2715 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2717 $total_companionships += $num_companionships;
2718 $stat_data = "<tr><td><b><font size=-2>$num_companionships Companionships<br>Interview Totals:</font></b></td>";
2720 // Print the hometeaching interview stats
2721 for($m=$num_months; $m >=0; $m--) {
2722 $month = $current_month - $m;
2723 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
2724 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
2725 //print "$month % $this->monthly_hometeaching_interview_stats = $month_begins <br>";
2726 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
2727 if(($month_begins) == 1) {
2730 $total += $ints[$m];
2732 $percent = ceil(($total / $num_companionships)*100);
2733 $stat_data .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
2735 $stat_data .= "</tr>";
2737 $this->t->set_var('table_width',$table_width);
2738 $this->t->set_var('header_row',$header_row);
2739 $this->t->set_var('table_data',$table_data);
2740 $this->t->set_var('stat_data',$stat_data);
2741 $this->t->fp('list','district_list',True);
2744 // Display the totals
2746 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>Interview Totals:</font></b></td>";
2747 for($m=$num_months; $m >=0; $m--) {
2748 $month = $current_month - $m;
2749 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
2750 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
2751 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
2752 if(($month_begins) == 1) {
2753 $total = $total_ints[$m];
2755 $total += $total_ints[$m];
2757 $percent = ceil(($total / $total_companionships)*100);
2758 $totals .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
2762 $this->t->set_var('totals',$totals);
2763 $this->t->pfp('out','int_view_t');
2764 $this->save_sessiondata();
2767 function int_update()
2769 $this->t->set_file(array('form' => 'int_update.tpl'));
2770 $this->t->set_block('form','interviewer_list','int_list');
2771 $this->t->set_block('form','add','addhandle');
2772 $this->t->set_block('form','edit','edithandle');
2774 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2775 $this->t->set_var('readonly','');
2776 $this->t->set_var('disabled','');
2777 $this->t->set_var('eqpresppi','');
2779 $action = get_var('action',array('GET','POST'));
2780 $companionship = get_var('companionship',array('GET','POST'));
2781 $interviewer = get_var('interviewer',array('GET','POST'));
2782 $name = get_var('name',array('GET','POST'));
2783 $interview = get_var('interview',array('GET','POST'));
2784 $individual = get_var('individual',array('GET','POST'));
2785 $date = get_var('date',array('GET','POST'));
2786 $notes = get_var('notes',array('GET','POST'));
2787 $interview_type = get_var('interview_type',array('GET','POST'));
2789 $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)";
2790 $this->db2->query($sql,__LINE__,__FILE__);
2791 while ($this->db2->next_record()) {
2792 $indiv = $this->db2->f('individual');
2793 $interviewer_name = $this->db2->f('name');
2794 if($indiv == $interviewer) {
2795 $this->t->set_var('interviewer',$interviewer . ' selected');
2797 $this->t->set_var('interviewer',$interviewer);
2799 $this->t->set_var('interviewer_name',$interviewer_name);
2800 $this->t->fp('int_list','interviewer_list',True);
2803 if($action == 'save') {
2804 $notes = get_var('notes',array('POST'));
2805 $this->db->query("UPDATE tc_interview set " .
2806 " interview='" . $interview . "'" .
2807 ", interviewer='" . $interviewer . "'" .
2808 ", individual='" . $individual . "'" .
2809 ", date='" . $date . "'" .
2810 ", notes='" . $notes . "'" .
2811 ", interview_type='" . $interview_type . "'" .
2812 " WHERE interview=" . $interview,__LINE__,__FILE__);
2817 if($action == 'insert') {
2818 $notes = get_var('notes',array('POST'));
2819 $this->db->query("INSERT INTO tc_interview (interviewer,individual,date,notes,interview_type) " .
2820 "VALUES ('" . $interviewer . "','" . $individual . "','" .
2821 $date . "','" . $notes ."','" . $interview_type . "')",__LINE__,__FILE__);
2826 if($action == 'add') {
2827 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2828 $this->t->set_var('interview', '');
2829 $this->t->set_var('interviewer', $interviewer);
2830 $this->t->set_var('name',$name);
2831 $this->t->set_var('individual',$individual);
2832 $this->t->set_var('date','');
2833 $this->t->set_var('notes','');
2834 $this->t->set_var('interview_type',$interview_type);
2835 $this->t->set_var('lang_done','Cancel');
2836 $this->t->set_var('lang_action','Adding New Interview');
2837 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
2838 $interview . '&action=' . 'insert'));
2841 if($action == 'edit' || $action == 'view') {
2842 $sql = "SELECT * FROM tc_interview WHERE interview=".$interview;
2843 $this->db->query($sql,__LINE__,__FILE__);
2844 $this->db->next_record();
2845 $this->t->set_var('interview',$interview);
2846 $this->t->set_var('name',$name);
2847 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2848 $this->t->set_var('individual',$this->db->f('individual'));
2849 $this->t->set_var('date',$this->db->f('date'));
2850 $this->t->set_var('notes',$this->db->f('notes'));
2851 $this->t->set_var('interview_type',$this->db->f('interview_type'));
2852 if($this->db->f('interview_type') == 'ppi') { $this->t->set_var('eqpresppi_checked','checked'); }
2855 if($action == 'edit') {
2856 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2857 $this->t->set_var('lang_done','Cancel');
2858 $this->t->set_var('lang_action','Editing Interview');
2859 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
2860 $interview . '&action=' . 'save'));
2863 if($action == 'view') {
2864 $date = $this->db->f('date');
2865 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2866 $this->t->set_var('readonly','READONLY');
2867 $this->t->set_var('disabled','DISABLED');
2868 $this->t->set_var('lang_done','Done');
2869 $this->t->set_var('lang_action','Viewing Interview');
2870 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
2871 $interview . '&action=' . 'edit'));
2874 $this->t->set_var('lang_reset','Clear Form');
2875 $this->t->set_var('lang_add','Add Interview');
2876 $this->t->set_var('lang_save','Save Changes');
2877 $this->t->set_var('edithandle','');
2878 $this->t->set_var('addhandle','');
2880 $this->t->pfp('out','form');
2882 if($action == 'view') { $this->t->set_var('lang_save','Edit Interview'); }
2883 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2884 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2886 $this->save_sessiondata();
2891 $this->t->set_file(array('vis_view_t' => 'vis_view.tpl'));
2892 $this->t->set_block('vis_view_t','visit_list','list1');
2893 $this->t->set_block('vis_view_t','family_list','list2');
2895 $this->t->set_var('lang_name','Family Name');
2896 $this->t->set_var('lang_date','Date');
2898 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2899 $this->t->set_var('vis_link_title','View Yearly Visits');
2901 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
2902 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2904 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2905 $num_years = get_var('num_years',array('GET','POST'));
2906 if($num_years == '') { $num_years = $this->default_vis_num_years; }
2907 $this->t->set_var('num_years',$num_years);
2908 if($num_years == 1) {
2909 $this->t->set_var('lang_num_years','Year of History');
2911 $this->t->set_var('lang_num_years','Years of History');
2913 $this->t->set_var('lang_filter','Filter');
2915 $year = date('Y') - $num_years + 1;
2916 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2918 $sql = "SELECT * FROM tc_visit WHERE companionship=0 and date > '$year_start' ORDER BY date DESC";
2919 $this->db->query($sql,__LINE__,__FILE__);
2920 $total_records = $this->db->num_rows();
2923 while ($this->db->next_record()) {
2924 $visit_list[$i]['visit'] = $this->db->f('visit');
2925 $visit_list[$i]['family'] = $this->db->f('family');
2926 $visit_list[$i]['date'] = $this->db->f('date');
2930 for ($i=0; $i < count($visit_list); $i++) {
2931 $this->nextmatchs->template_alternate_row_color(&$this->t);
2933 $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'";
2934 $this->db->query($sql,__LINE__,__FILE__);
2935 $this->db->next_record();
2937 $this->t->set_var('family',$visit_list[$i]['family']);
2938 $this->t->set_var('family_name',$this->db->f('name'));
2939 $this->t->set_var('date',$visit_list[$i]['date']);
2941 $link_data['menuaction'] = 'tc.tc.vis_update';
2942 $link_data['visit'] = $visit_list[$i]['visit'];
2943 $link_data['name'] = $this->db->f('name');
2944 $link_data['date'] = $visit_list[$i]['date'];
2945 $link_data['action'] = 'view';
2946 $this->t->set_var('view',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
2947 $this->t->set_var('lang_view','View');
2949 $link_data['menuaction'] = 'tc.tc.vis_update';
2950 $link_data['visit'] = $visit_list[$i]['visit'];
2951 $link_data['name'] = $this->db->f('name');
2952 $link_data['date'] = $visit_list[$i]['date'];
2953 $link_data['action'] = 'edit';
2954 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
2955 $this->t->set_var('lang_edit','Edit');
2957 $this->t->fp('list1','visit_list',True);
2960 // List the families that are available to record a visit against
2961 $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'";
2962 $this->db->query($sql,__LINE__,__FILE__);
2963 $total_records = $this->db->num_rows();
2966 while ($this->db->next_record()) {
2967 $family_names[$i] = $this->db->f('name');
2968 $family_ids[$i] = $this->db->f('family');
2970 } array_multisort($family_names, $family_ids);
2972 for ($i=0; $i < count($family_names); $i++) {
2973 $link_data['menuaction'] = 'tc.tc.vis_update';
2974 $link_data['visit'] = '';
2975 $link_data['family'] = $family_ids[$i];
2976 $link_data['action'] = 'add';
2977 $link_data['name'] = $family_names[$i];
2978 $this->t->set_var('add',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
2980 $this->t->set_var('name',$family_names[$i]);
2981 if(($i+1) % 3 == 0) {
2982 $this->t->set_var('table_sep',"</td></tr><tr>");
2984 $this->t->set_var('table_sep',"</td>");
2986 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
2988 $this->t->fp('list2','family_list',True);
2991 $this->t->pfp('out','vis_view_t');
2992 $this->save_sessiondata();
2995 function vis_update()
2997 $this->t->set_file(array('form' => 'vis_update.tpl'));
2998 $this->t->set_block('form','add','addhandle');
2999 $this->t->set_block('form','edit','edithandle');
3001 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
3002 $this->t->set_var('readonly','');
3003 $this->t->set_var('disabled','');
3005 $action = get_var('action',array('GET','POST'));
3006 $visit = get_var('visit',array('GET','POST'));
3007 $family = get_var('family',array('GET','POST'));
3008 $name = get_var('name',array('GET','POST'));
3009 $date = get_var('date',array('GET','POST'));
3010 $notes = get_var('notes',array('GET','POST'));
3013 if($action == 'save') {
3014 $notes = get_var('notes',array('POST'));
3015 $this->db->query("UPDATE tc_visit set " .
3016 " date='" . $date . "'" .
3017 ", notes='" . $notes . "'" .
3018 " WHERE visit=" . $visit,__LINE__,__FILE__);
3023 if($action == 'insert') {
3024 $notes = get_var('notes',array('POST'));
3025 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes) " .
3026 "VALUES ('" . $family . "','" . $companionship . "','" .
3027 $date . "','" . $notes . "')",__LINE__,__FILE__);
3032 if($action == 'add') {
3033 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
3034 $this->t->set_var('family', $family);
3035 $this->t->set_var('visit', '');
3036 $this->t->set_var('name', $name);
3037 $this->t->set_var('date','');
3038 $this->t->set_var('notes','');
3039 $this->t->set_var('lang_done','Cancel');
3040 $this->t->set_var('lang_action','Adding New Visit');
3041 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&family=' .
3042 $family . '&action=' . 'insert'));
3045 if($action == 'edit' || $action == 'view') {
3046 $sql = "SELECT * FROM tc_visit WHERE visit=".$visit;
3047 $this->db->query($sql,__LINE__,__FILE__);
3048 $this->db->next_record();
3049 $this->t->set_var('visit',$visit);
3050 $this->t->set_var('name',$name);
3051 $this->t->set_var('family', $family);
3052 $this->t->set_var('date',$this->db->f('date'));
3053 $this->t->set_var('notes',$this->db->f('notes'));
3056 if($action == 'edit') {
3057 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
3058 $this->t->set_var('lang_done','Cancel');
3059 $this->t->set_var('lang_action','Editing Visit');
3060 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit=' .
3061 $visit . '&action=' . 'save'));
3064 if($action == 'view') {
3065 $date = $this->db->f('date');
3066 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
3067 $this->t->set_var('readonly','READONLY');
3068 $this->t->set_var('disabled','DISABLED');
3069 $this->t->set_var('lang_done','Done');
3070 $this->t->set_var('lang_action','Viewing Visit');
3071 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit=' .
3072 $visit . '&action=' . 'edit'));
3075 $this->t->set_var('lang_reset','Clear Form');
3076 $this->t->set_var('lang_add','Add Visit');
3077 $this->t->set_var('lang_save','Save Changes');
3078 $this->t->set_var('edithandle','');
3079 $this->t->set_var('addhandle','');
3081 $this->t->pfp('out','form');
3083 if($action == 'view') { $this->t->set_var('lang_save','Edit Visit'); }
3084 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
3085 if($action == 'add') { $this->t->pfp('addhandle','add'); }
3087 $this->save_sessiondata();
3092 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3093 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3094 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3096 $this->t->set_file(array('att_view_t' => 'att_view.tpl'));
3097 $this->t->set_block('att_view_t','act_list','list');
3099 $this->t->set_block('att_view_t','month_list','list1');
3100 $this->t->set_block('att_view_t','header_list','list2');
3101 $this->t->set_block('att_view_t','individual_list','list3');
3103 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3104 $num_quarters = get_var('num_quarters',array('GET','POST'));
3105 if($num_quarters == '') { $num_quarters = $this->default_att_num_quarters; }
3106 $this->t->set_var('num_quarters',$num_quarters);
3107 $this->t->set_var('lang_filter','Filter');
3108 if($num_quarters == 1) {
3109 $this->t->set_var('lang_num_quarters','Quarter of History');
3111 $this->t->set_var('lang_num_quarters','Quarters of History');
3114 $num_months = $num_quarters * 3;
3115 $current_month = $this->current_month;
3116 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
3117 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
3118 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
3119 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
3121 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
3122 $this->db->query($sql,__LINE__,__FILE__);
3124 while ($this->db->next_record()) {
3125 $individual_name[$i] = $this->db->f('name');
3126 $individual[$i] = $this->db->f('individual');
3129 array_multisort($individual_name, $individual);
3131 // Create a list of sunday dates for a window of 3 months back and current month
3135 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, ($current_month-$num_months)+1, 1, date("y")));
3136 $last_date = explode("-",$sunday_list[0]['date']);
3137 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3138 $time_limit = mktime(0, 0, 0, $current_month, 31, date("y"));
3139 while($last_time < $time_limit) {
3140 $day = date("w",$last_time);
3141 if(date("w",$last_time) == 0) {
3142 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3143 $last_date = explode("-",$sunday_list[$i]['date']);
3144 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3145 $sunday_list[$i]['day'] = $last_date[2];
3146 $sunday_list[$i]['month'] = date("M",$last_time);
3147 $sunday_list[$i]['year'] = $last_date[0];
3149 $last_date = $sunday_list[$i]['date'];
3151 $last_time += 90000;
3152 if($found_sunday) { $i++; $found_sunday=0; }
3155 $total_individuals = count($individual);
3156 $old_month=$sunday_list[0]['month']; $span=0;
3157 for ($i=0; $i < count($sunday_list); $i++) {
3158 $date = $sunday_list[$i]['date'];
3159 $this->t->set_var('date',$sunday_list[$i]['date']);
3160 $this->t->set_var('day',$sunday_list[$i]['day']);
3161 if(($old_month != $sunday_list[$i]['month']) || $i == count($sunday_list)-1) {
3162 if($i == count($sunday_list)-1) { $span++; }
3163 $cur_month = $sunday_list[$i]['month'];
3164 $old_month = $sunday_list[$i]['month'];
3165 $link_data['menuaction'] = 'tc.tc.att_update';
3166 $link_data['month'] = $sunday_list[$i-1]['month'];
3167 $link_data['year'] = $sunday_list[$i-1]['year'];
3168 $link_data['action'] = 'update_month';
3169 $cur_month = $sunday_list[$i-1]['month'];
3170 $cur_year = $sunday_list[$i-1]['year'];
3171 $header_row .= "<th><font size=-3>$cur_month $cur_year</font></th>";
3172 $this->t->set_var('update_month',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3173 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3174 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3175 $this->t->set_var('span',$span); $span=0;
3176 $this->t->fp('list1','month_list',True);
3180 $this->t->set_var('total_individuals',$total_individuals);
3181 $this->t->set_var('header_row',$header_row);
3183 $individual_width=200; $att_width=25; $total_width=$individual_width;
3184 for ($i=0; $i < count($sunday_list); $i++) {
3185 $link_data['menuaction'] = 'tc.tc.att_update';
3186 $link_data['month'] = $sunday_list[$i]['month'];
3187 $link_data['year'] = $sunday_list[$i]['year'];
3188 $link_data['day'] = $sunday_list[$i]['day'];
3189 $link_data['date'] = $sunday_list[$i]['date'];
3190 $link_data['action'] = 'update_day';
3191 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3192 $this->t->set_var('date',$sunday_list[$i]['date']);
3193 $this->t->set_var('day',$sunday_list[$i]['day']);
3194 $this->t->set_var('month',$sunday_list[$i]['month']);
3195 $this->t->set_var('year',$sunday_list[$i]['year']);
3196 $this->t->fp('list2','header_list',True);
3197 $total_width += $att_width;
3198 $attendance[$monthnum[$sunday_list[$i]['month']]]=0;
3201 for ($i=0; $i < count($individual); $i++) {
3203 $this->nextmatchs->template_alternate_row_color(&$this->t);
3204 $this->t->set_var('individual_name',$individual_name[$i]);
3205 #print "checking for individual: " . $individual[$i] . "<br>";
3206 for ($j=0; $j < count($sunday_list); $j++) {
3207 #print "checking for date: " . $sunday_list[$j]['date'] . "<br>";
3208 #print "SELECT * FROM tc_attendance WHERE date='"
3209 # . $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i] . "<br>";
3210 $sql = "SELECT * FROM tc_attendance WHERE date='" .
3211 $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i];
3212 $this->db->query($sql,__LINE__,__FILE__);
3213 if($this->db->next_record()) {
3214 $cur_month = $sunday_list[$j]['month'];
3215 if($attended[$i][$cur_month] != 1) {
3216 $attended[$i][$cur_month]=1;
3217 $attendance[$monthnum[$cur_month]]++;
3219 $att_table .= '<td align=center><img src="images/checkmark.gif"></td>';
3221 $att_table .= '<td> </td>';
3224 $this->t->set_var('att_table',$att_table);
3225 $this->t->fp('list3','individual_list',True);
3227 $this->t->set_var('total_width',$total_width);
3228 $this->t->set_var('individual_width',$individual_width);
3229 $this->t->set_var('att_width',$att_width);
3231 # Now calculate attendance for these months
3232 $attendance_str = "";
3233 $nonattendance_str = "";
3234 $aveattendance_str = "";
3235 $avenonattendance_str = "";
3237 $ave_total_attended=0;
3239 foreach($attendance as $att => $value) {
3240 $total_attended = $attendance[$att];
3241 $ave_total_attended += $attendance[$att]; $num_months++;
3242 $percent = ceil(($total_attended / $total_individuals)*100);
3243 $attendance_str.="<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3244 $total_nonattended = $total_individuals - $total_attended;
3245 $percent = ceil(($total_nonattended / $total_individuals)*100);
3246 $nonattendance_str.="<td align=center><font size=-2><b>$total_nonattended ($percent%)</b></font></td>";
3248 $total_attended = ceil(($ave_total_attended / $num_months));
3249 $percent = ceil(($total_attended / $total_individuals)*100);
3250 $aveattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3251 $total_attended = $total_individuals - ceil(($ave_total_attended / $num_months));
3252 $percent = ceil(($total_attended / $total_individuals)*100);
3253 $avenonattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3256 $this->t->set_var('attendance',$attendance_str);
3257 $this->t->set_var('aveattendance',$aveattendance_str);
3258 $this->t->set_var('nonattendance',$nonattendance_str);
3259 $this->t->set_var('avenonattendance',$avenonattendance_str);
3261 $this->t->pfp('out','att_view_t');
3262 $this->save_sessiondata();
3265 function att_update()
3267 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3268 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3269 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3271 $this->t->set_file(array('form' => 'att_update.tpl'));
3272 $this->t->set_block('form','edit','edithandle');
3274 $this->t->set_block('form','month_list','list1');
3275 $this->t->set_block('form','header_list','list2');
3276 $this->t->set_block('form','individual_list','list3');
3278 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3280 $action = get_var('action',array('GET','POST'));
3281 $month = get_var('month',array('GET','POST'));
3282 $year = get_var('year',array('GET','POST'));
3283 $day = get_var('day',array('GET','POST'));
3284 $date = get_var('date',array('GET','POST'));
3286 if($action == 'save_month' || $action == 'save_day') {
3287 $new_data = get_var('individuals_attended',array('POST'));
3288 $month = $monthnum[$month]; if($month < 10) { $month = "0" . $month; }
3290 if($action == 'save_month') {
3291 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-%'",__LINE__,__FILE__);
3294 if($action == 'save_day') {
3295 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-".$day."'",__LINE__,__FILE__);
3298 foreach ($new_data as $data) {
3299 $data_array = explode("-",$data);
3300 $indiv = $data_array[0];
3301 $date = "$data_array[1]-$data_array[2]-$data_array[3]";
3302 $this->db->query("INSERT INTO tc_attendance (individual,date) " .
3303 "VALUES (" . $indiv . ",'". $date . "')",__LINE__,__FILE__);
3310 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
3311 $this->db->query($sql,__LINE__,__FILE__);
3313 while ($this->db->next_record()) {
3314 $indiv_name[$i] = $this->db->f('name');
3315 $individual[$i] = $this->db->f('individual');
3316 $indiv_attending[$individual[$i]] = $this->db->f('attending');
3319 array_multisort($indiv_name, $individual);
3321 if($action == 'update_month') {
3322 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_month'));
3326 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], 1, $year));
3327 $last_date = explode("-",$sunday_list[0]['date']);
3328 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3329 $time_limit = mktime(0, 0, 0, $monthnum[$month], 31, $year);
3330 while($last_time <= $time_limit) {
3331 $day = date("w",$last_time);
3332 if(date("w",$last_time) == 0) {
3333 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3334 $last_date = explode("-",$sunday_list[$i]['date']);
3335 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3336 $sunday_list[$i]['day'] = $last_date[2];
3337 $sunday_list[$i]['month'] = date("M",$last_time);
3338 $sunday_list[$i]['year'] = $last_date[0];
3341 $last_time += 90000;
3342 if($found_sunday) { $i++; $found_sunday=0; }
3345 $this->t->set_var('span', $i);
3346 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3347 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3348 $this->t->fp('list1','month_list',True);
3349 $indiv_width=200; $att_width=25; $total_width=$indiv_width;
3350 for ($i=0; $i < count($sunday_list); $i++) {
3351 $link_data['menuaction'] = 'tc.tc.att_update';
3352 $link_data['month'] = $sunday_list[$i]['month'];
3353 $link_data['year'] = $sunday_list[$i]['year'];
3354 $link_data['day'] = $sunday_list[$i]['day'];
3355 $link_data['date'] = $sunday_list[$i]['date'];
3356 $link_data['action'] = 'update_day';
3357 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3358 $this->t->set_var('date',$sunday_list[$i]['date']);
3359 $this->t->set_var('day',$sunday_list[$i]['day']);
3360 $this->t->set_var('month',$sunday_list[$i]['month']);
3361 $this->t->set_var('year',$sunday_list[$i]['year']);
3362 $this->t->fp('list2','header_list',True);
3363 $total_width += $att_width;
3367 if($action == 'update_day') {
3368 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_day'));
3369 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], $day, $year));
3370 $this->t->set_var('month',$month);
3371 $this->t->set_var('year',$year);
3372 $this->t->fp('list1','month_list',True);
3373 $this->t->set_var('date',$date);
3374 $this->t->set_var('day',$day);
3375 $this->t->set_var('month',$month);
3376 $this->t->set_var('year',$year);
3377 $this->t->fp('list2','header_list',True);
3380 for ($i=0; $i < count($individual); $i++) {
3382 $this->nextmatchs->template_alternate_row_color(&$this->t);
3383 $this->t->set_var('individual_name',$indiv_name[$i]);
3384 for ($j=0; $j < count($sunday_list); $j++) {
3385 $sql = "SELECT * FROM tc_attendance WHERE date='" .
3386 $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i];
3387 $this->db->query($sql,__LINE__,__FILE__);
3388 $value = $individual[$i] . "-" . $sunday_list[$j]['date'];
3389 if($this->db->next_record()) {
3390 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'" checked></td>';
3391 } else if($indiv_attending[$individual[$i]] == 1) {
3392 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'" checked></td>';
3394 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'"></td>';
3397 $this->t->set_var('att_table',$att_table);
3398 $this->t->fp('list3','individual_list',True);
3401 $this->t->set_var('lang_done', 'Cancel');
3402 $this->t->set_var('lang_reset','Clear Form');
3403 $this->t->set_var('lang_save','Save Changes');
3405 $this->t->pfp('out','form');
3406 $this->t->pfp('addhandle','edit');
3408 $this->save_sessiondata();
3413 $this->t->set_file(array('dir_view_t' => 'dir_view.tpl'));
3414 $this->t->set_block('dir_view_t','dir_list','list');
3416 $sql = "SELECT * FROM tc_individual where valid=1 and hh_position='Head of Household' ORDER BY name ASC";
3417 $this->db->query($sql,__LINE__,__FILE__);
3419 while ($this->db->next_record()) {
3420 $parent[$i]['id'] = $this->db->f('individual');
3421 $parent[$i]['name'] = $this->db->f('name');
3422 $parent[$i]['phone'] = $this->db->f('phone');
3423 $parent[$i]['address'] = $this->db->f('address');
3427 for ($i=0; $i < count($parent); $i++) {
3428 $name = $parent[$i]['name'];
3429 $phone = $parent[$i]['phone'];
3430 $address = $parent[$i]['address'];
3431 $this->t->set_var('name', $name);
3432 $this->t->set_var('address', $address);
3433 $this->t->set_var('phone', $phone);
3434 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3435 $this->t->set_var('tr_color',$tr_color);
3436 $this->t->fp('list','dir_list',True);
3437 //print "$phone $name $address<br>";
3439 $this->t->pfp('out','dir_view_t');
3440 $this->save_sessiondata();
3445 $this->t->set_file(array('org_view_t' => 'org_view.tpl'));
3446 $this->t->set_block('org_view_t','calling_list','list1');
3447 $this->t->set_block('org_view_t','org_list','list2');
3449 # Display a list ordered alphabetically
3450 $sql = "SELECT * FROM tc_calling AS tc JOIN tc_individual AS ti WHERE tc.individual=ti.individual ORDER BY name ASC";
3451 $this->db->query($sql,__LINE__,__FILE__);
3453 while ($this->db->next_record()) {
3454 $calling[$i]['name'] = $this->db->f('name');
3455 $calling[$i]['position'] = $this->db->f('position');
3456 $calling[$i]['sustained'] = $this->db->f('sustained');
3457 $calling[$i]['organization'] = $this->db->f('organization');
3460 for ($i=0; $i < count($calling); $i++) {
3461 $name = $calling[$i]['name'];
3462 $position = $calling[$i]['position'];
3463 $sustained = $calling[$i]['sustained'];
3464 $organization = $calling[$i]['organization'];
3465 $this->t->set_var('name', $name);
3466 $this->t->set_var('position', $position);
3467 $this->t->set_var('sustained', $sustained);
3468 $this->t->set_var('organization', $organization);
3469 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3470 $this->t->set_var('tr_color',$tr_color);
3471 $this->t->fp('list1','calling_list',True);
3474 # Display a list ordered by organization
3475 $sql = "SELECT * FROM tc_calling AS tc JOIN tc_individual AS ti where tc.individual=ti.individual ORDER BY organization ASC";
3476 $this->db->query($sql,__LINE__,__FILE__);
3478 while ($this->db->next_record()) {
3479 $calling[$i]['name'] = $this->db->f('name');
3480 $calling[$i]['position'] = $this->db->f('position');
3481 $calling[$i]['sustained'] = $this->db->f('sustained');
3482 $calling[$i]['organization'] = $this->db->f('organization');
3485 for ($i=0; $i < count($calling); $i++) {
3486 $name = $calling[$i]['name'];
3487 $position = $calling[$i]['position'];
3488 $sustained = $calling[$i]['sustained'];
3489 $organization = $calling[$i]['organization'];
3490 $this->t->set_var('name', $name);
3491 $this->t->set_var('position', $position);
3492 $this->t->set_var('sustained', $sustained);
3493 $this->t->set_var('organization', $organization);
3494 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3495 $this->t->set_var('tr_color',$tr_color);
3496 $this->t->fp('list2','org_list',True);
3499 $this->t->pfp('out','org_view_t');
3500 $this->save_sessiondata();
3505 $this->t->set_file(array('sched_t' => 'schedule.tpl'));
3506 $this->t->set_block('sched_t','presidency_list','list');
3508 $action = get_var('action',array('GET','POST'));
3510 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule&action=save'));
3511 $this->t->set_var('title','Scheduling Tool');
3513 $this->t->set_var('lang_save','Save Schedule');
3514 $this->t->set_var('lang_reset','Cancel');
3516 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
3517 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
3519 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
3520 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
3522 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
3523 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
3525 $date_width=160; $time_width=220; $indiv_width=170; $family_width=180; $location_width=100;
3526 $table_width=$date_width + $time_width + $indiv_width + $family_width + $location_width;
3527 $header_row = "<th width=$date_width><font size=-2>Date</th>";
3528 $header_row.= "<th width=$time_width><font size=-2>Time</th>";
3529 $header_row.= "<th width=$indiv_width><font size=-2>individual</th>";
3530 $header_row.= "<th width=$family_width><font size=-2>Family</th>";
3531 $header_row.= "<th width=$location_width><font size=-2>Location</th>";
3534 $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";
3535 $this->db->query($sql,__LINE__,__FILE__);
3537 while ($this->db->next_record()) {
3538 $presidency_data[$i]['id'] = $this->db->f('presidency');
3539 $presidency_data[$i]['name'] = $this->db->f('name');
3540 $presidency_data[$i]['indiv'] = $this->db->f('individual');
3541 $presidency2name[$presidency_data[$i]['id']] = $presidency_data[$i]['name'];
3542 $presidency2indiv[$presidency_data[$i]['id']] = $presidency_data[$i]['individual'];
3546 $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";
3547 $this->db->query($sql,__LINE__,__FILE__);
3549 while ($this->db->next_record()) {
3550 $family_id[$i] = $this->db->f('family');
3551 $family_name[$i] = $this->db->f('name');
3552 $familyid2name[$family_id[$i]] = $family_name[$i];
3553 $familyid2address[$family_id[$i]] = $this->db->f('address');
3556 array_multisort($family_name, $family_id);
3558 if($action == 'save') {
3559 $new_data = get_var('sched',array('POST'));
3560 foreach ($new_data as $presidency_array) {
3561 foreach ($presidency_array as $entry) {
3562 $presidency = $entry['presidency'];
3563 $appointment = $entry['appointment'];
3564 $location = $entry['location'];
3565 $date = $entry['date'];
3566 $hour = $entry['hour'];
3567 $minute = $entry['minute'];
3569 $indiv = $entry['individual'];
3570 $family = $entry['family'];
3571 $location = $entry['location'];
3572 if($pm) { $hour = $hour + 12; }
3573 $time = $hour.':'.$minute.':'.'00';
3576 // Zero out family or individual if they are invalid
3577 if($indiv == "") { $indiv=0; }
3578 if($family == "") { $family=0; }
3580 // Update our location
3581 if($location == "") {
3583 $family_name_array = explode(",", $familyid2name[$family]);
3584 $family_last_name = $family_name_array[0];
3585 $family_address = $familyid2address[$family];
3586 $location = "$family_last_name"." home ($family_address)";
3587 } else if($indiv > 0) {
3588 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
3589 $supervisor_last_name = $supervisor_name_array[0];
3590 $sql = "SELECT * FROM tc_individual where individual='$presidency2indiv[$presidency]'";
3591 $this->db2->query($sql,__LINE__,__FILE__);
3592 if($this->db2->next_record()) {
3593 $mls_id = $this->db2->f('mls_id');
3595 $sql = "SELECT * FROM tc_individual where mls_id='$mls_id'";
3596 $this->db2->query($sql,__LINE__,__FILE__);
3597 if($this->db2->next_record()) {
3598 $supervisor_address = $this->db2->f('address');
3600 $location = "$supervisor_last_name"." home ($supervisor_address)";
3604 // Zero out the family or individual if date = NULL
3611 if(($indiv == 0) && ($family == 0)) { $location = ""; }
3613 // Update an existing appointment
3614 if($appointment < $this->max_appointments)
3616 //Only perform a database update if we have made a change to this appointment
3617 $sql = "SELECT * FROM tc_appointment where " .
3618 "appointment='$appointment'" .
3619 " and presidency='$presidency'" .
3620 " and individual='$indiv'" .
3621 " and family='$family'" .
3622 " and date='$date'" .
3623 " and time='$time'" .
3624 " and location='$location'";
3625 $this->db->query($sql,__LINE__,__FILE__);
3626 if(!$this->db->next_record()) {
3627 $old_date = $this->db->f('date');
3628 $old_time = $this->db->f('time');
3629 $this->db2->query("UPDATE tc_appointment set" .
3630 " family=" . $family .
3631 " ,individual=" . $indiv .
3632 " ,date='" . $date . "'" .
3633 " ,time='" . $time . "'" .
3634 " ,location='" . $location . "'" .
3635 " ,presidency='" . $presidency . "'" .
3636 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
3638 // Email the appointment
3639 $this->email_appt($appointment);
3643 // Add a new appointment
3644 else if(($appointment >= $this->max_appointments) && ($date != "") && ($time != ""))
3646 //print "adding entry: appt=$appointment date: $date time: $time individual: $indiv family: $family<br>";
3647 $this->db2->query("INSERT INTO tc_appointment (appointment,presidency,family,individual,date,time,location,uid) " .
3648 "VALUES (NULL,'" . $presidency . "','" . $family . "','" . $indiv . "','" .
3649 $date . "','" . $time . "','" . $location . "','" . $uid ."')",__LINE__,__FILE__);
3651 // Now reselect this entry from the database to see if we need
3652 // to send an appointment out for it.
3653 $sql = "SELECT * FROM tc_appointment where " .
3654 "individual='$indiv'" .
3655 " and family='$family'" .
3656 " and presidency='$presidency'" .
3657 " and date='$date'" .
3658 " and time='$time'" .
3660 " and location='$location'";
3661 $this->db3->query($sql,__LINE__,__FILE__);
3662 if($this->db3->next_record()) {
3663 // Email the appointment if warranted
3664 if(($date != "") && ($time != "") && (($indiv > 0) || $family > 0)) {
3665 $this->email_appt($this->db3->f('appointment'));
3672 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule');
3673 //Header('Location: ' . $take_me_to_url);
3676 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY individual ASC";
3677 $this->db->query($sql,__LINE__,__FILE__);
3679 while ($this->db->next_record()) {
3680 $individual[$i] = $this->db->f('individual');
3681 $indiv_name[$i] = $this->db->f('name');
3682 $indiv_phone[$individual[$i]] = $this->db->f('phone');
3685 array_multisort($indiv_name, $individual);
3687 for ($i=0; $i < count($presidency_data); $i++) {
3688 $presidency = $presidency_data[$i]['id'];
3689 $interviewer = $presidency_data[$i]['individual'];
3690 $name = $presidency_data[$i]['name'];
3691 $this->t->set_var('presidency_name',$name);
3694 // query the database for all the appointments
3695 $sql = "SELECT * FROM tc_appointment where presidency=$presidency and date>=CURDATE() ORDER BY date ASC, time ASC";
3696 $this->db->query($sql,__LINE__,__FILE__);
3698 // Prefill any existing appointment slots
3699 while ($this->db->next_record()) {
3700 $appointment = $this->db->f('appointment');
3701 $indiv = $this->db->f('individual');
3702 $family = $this->db->f('family');
3703 $location = $this->db->f('location');
3705 if($location == "") {
3707 $family_name_array = explode(",", $familyid2name[$family]);
3708 $family_last_name = $family_name_array[0];
3709 $family_address = $familyid2address[$family];
3710 $location = "$family_last_name"." home ($family_address)";
3711 } else if($indiv > 0) {
3712 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
3713 $supervisor_last_name = $supervisor_name_array[0];
3714 $sql = "SELECT * FROM tc_individual where individual='$presidency2indiv[$presidency]'";
3715 $this->db2->query($sql,__LINE__,__FILE__);
3716 if($this->db2->next_record()) {
3717 $mls_id = $this->db2->f('mls_id');
3719 $sql = "SELECT * FROM tc_individual where mls_id='$mls_id'";
3720 $this->db2->query($sql,__LINE__,__FILE__);
3721 if($this->db2->next_record()) {
3722 $supervisor_address = $this->db2->f('address');
3724 $location = "$supervisor_last_name"." home ($supervisor_address)";
3728 $date = $this->db->f('date');
3729 $date_array = explode("-",$date);
3730 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
3731 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
3733 $time = $this->db->f('time');
3734 $time_array = explode(":",$time);
3735 $hour = $time_array[0];
3736 $minute = $time_array[1];
3738 if($hour > 12) { $pm=1; $hour = $hour - 12; }
3739 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
3741 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3744 $table_data.= '<td align=left>';
3745 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]',$date,'','','','','',$this->cal_options);
3746 $table_data.= '</td>';
3748 // Hour & Minutes selection
3749 $table_data.= "<td align=center>";
3750 $table_data .= $this->get_time_selection_form($hour, $minute, $pm, $presidency, $appointment);
3751 $table_data.= "</td>";
3753 // individual drop down list (for PPIs)
3754 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][indiv] STYLE="font-size : 8pt">';
3755 $table_data.= '<option value=0></option>';
3756 for ($j=0; $j < count($individual); $j++) {
3757 $id = $individual[$j];
3758 $name = $indiv_name[$j];
3759 if($individual[$j] == $indiv) {
3760 $selected[$id] = 'selected="selected"';
3762 $selected[$id] = '';
3764 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
3766 $table_data.='</select></td>';
3768 // Family drop down list (for Visits)
3769 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family] STYLE="font-size : 8pt">';
3770 $table_data.= '<option value=0></option>';
3771 for ($j=0; $j < count($individual); $j++) {
3772 $id = $family_id[$j];
3773 $name = $family_name[$j];
3774 if($family_id[$j] == $family) {
3775 $selected[$id] = 'selected="selected"';
3777 $selected[$id] = '';
3779 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
3781 $table_data.='</select></td>';
3783 // Location text box
3784 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
3785 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="'.$location.'" STYLE="font-size : 8pt">';
3787 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3788 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3790 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3791 $this->t->set_var('tr_color',$tr_color);
3794 // Create blank appointment slot
3795 for ($b=0; $b < 4; $b++) {
3796 $appointment = $this->max_appointments + $b;
3797 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3800 $table_data.= '<td align=left>';
3801 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]','','','','','','',$this->cal_options);
3802 $table_data.= '</td>';
3805 $table_data.= "<td align=center>";
3806 $table_data .= $this->get_time_selection_form(0, 0, 0, $presidency, $appointment);
3807 $table_data.= "</td>";
3809 // individual drop down list
3810 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][indiv] STYLE="font-size : 8pt">';
3811 $table_data.= '<option value=0></option>';
3812 for ($j=0; $j < count($individual); $j++) {
3813 $id = $individual[$j];
3814 $name = $indiv_name[$j];
3815 $table_data.= '<option value='.$id.'>'.$name.'</option>';
3817 $table_data.='</select></td>';
3819 // Family drop down list
3820 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family] STYLE="font-size : 8pt">';
3821 $table_data.= '<option value=0></option>';
3822 for ($j=0; $j < count($individual); $j++) {
3823 $id = $family_id[$j];
3824 $name = $family_name[$j];
3825 $table_data.= '<option value='.$id.'>'.$name.' Family</option>';
3827 $table_data.='</select></td>';
3829 // Location text box
3830 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
3831 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="" STYLE="font-size : 8pt">';
3833 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3834 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3836 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3837 $this->t->set_var('tr_color',$tr_color);
3840 $this->t->set_var('table_data',$table_data);
3841 $this->t->set_var('header_row',$header_row);
3842 $this->t->set_var('table_width',$table_width);
3843 $this->t->fp('list','presidency_list',True);
3846 $this->t->pfp('out','sched_t');
3847 $this->save_sessiondata();
3852 $this->t->set_file(array('email_t' => 'email.tpl'));
3853 $this->t->set_block('email_t','individual_list','list');
3855 $action = get_var('action',array('GET','POST'));
3857 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email'));
3858 $this->t->set_var('title','Email Tool');
3860 $this->t->set_var('lang_email','Send Email');
3861 $this->t->set_var('lang_reset','Cancel');
3863 $this->t->set_var('email_member_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=member'));
3864 $this->t->set_var('email_member_link_title','Email Quorum Member');
3866 $this->t->set_var('email_quorum_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=quorum'));
3867 $this->t->set_var('email_quorum_link_title','Email Quorum');
3869 $this->t->set_var('email_reminder_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=reminder'));
3870 $this->t->set_var('email_reminder_link_title','Email Reminders');
3872 $this->t->set_var('email_edit_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=edit'));
3873 $this->t->set_var('email_edit_link_title','Edit Email Addresses');
3876 $this->t->set_var('table_width',$table_width);
3878 $this->t->pfp('out','email_t');
3879 $this->save_sessiondata();
3884 $this->t->set_file(array('admin_t' => 'admin.tpl'));
3885 $this->t->set_block('admin_t','upload','uploadhandle');
3886 $this->t->set_block('admin_t','admin','adminhandle');
3887 $this->t->set_block('admin_t','cmd','cmdhandle');
3888 $this->t->set_block('admin_t','presidency','presidencyhandle');
3890 $this->t->set_var('upload_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=upload'));
3891 $this->t->set_var('presidency_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=presidency'));
3893 $action = get_var('action',array('GET','POST'));
3895 $this->t->pfp('out','admin_t');
3897 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY individual ASC";
3898 $this->db->query($sql,__LINE__,__FILE__);
3900 while ($this->db->next_record()) {
3901 $individual[$i] = $this->db->f('individual');
3902 $indiv_name[$i] = $this->db->f('name');
3903 $indiv2name[$individual[$i]] = $indiv_name[$i];
3906 array_multisort($indiv_name, $individual);
3908 if($action == 'upload') {
3909 $target_path = $this->upload_target_path . '/' . basename( $_FILES['uploadedfile']['name']);
3911 if(($_FILES['uploadedfile']['type'] == "application/zip") ||
3912 ($_FILES['uploadedfile']['type'] == "application/x-zip-compressed") ||
3913 ($_FILES['uploadedfile']['type'] == "application/x-zip") ||
3914 ($_FILES['uploadedfile']['type'] == "application/octet-stream")) {
3916 if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
3917 $uploadstatus = "<b><font color=red> -E- Unable to move the uploaded file to ";
3918 $uploadstatus.= "the target path (check the path and permissions) of: $target_path</font></b>";
3919 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
3920 $uploadstatus.= "Tmp Filename : " . $_FILES['uploadedfile']['tmp_name'] . "<br>";
3921 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
3922 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
3923 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
3924 $uploadstatus.= "Error : " . $_FILES['uploadedfile']['error'] . "<br>";
3925 $this->t->set_var('uploadstatus',$uploadstatus);
3926 $this->t->pfp('uploadhandle','upload',True);
3930 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
3931 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
3932 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
3933 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
3934 $this->t->set_var('uploadstatus',$uploadstatus);
3935 $this->t->pfp('uploadhandle','upload');
3936 $this->t->set_var('uploadhandle','');
3937 print "<table border=1 width=80%><tr><td>\n<pre>";
3939 # make a directory for this data to be stored in
3940 $date="data_" . date("Y_m_d");
3941 $data_dir = $this->upload_target_path . '/' . $date;
3942 print "-> Making the data directory: $date<br>\n";
3943 exec('mkdir -p ' . $data_dir . ' 2>&1', $result, $return_code);
3944 if($return_code != 0) {
3945 print implode('\n',$result) . "<br>";
3946 print "<b><font color=red>";
3947 print "-E- Unable to create the data directory. Aborting import.";
3948 print "</font></b>";
3952 # move the file uploaded into this directory
3953 print "-> Moving the uploaded file into the data dir<br>\n";
3954 exec('mv ' . $target_path . ' ' . $data_dir . '/' . ' 2>&1', $result, $return_code);
3955 if($return_code != 0) {
3956 print implode('\n',$result) . "<br>";
3957 print "<b><font color=red>";
3958 print "-E- Unable to move the uploaded file into the data dir. Aborting import.";
3959 print "</font></b>";
3963 # unzip the data into this directory
3964 print "-> Unzipping the data<br>\n";
3965 exec($this->unzip_path .' -u '. $data_dir . '/*.zip -d ' . $data_dir . ' 2>&1', $result, $return_code);
3966 if($return_code != 0) {
3967 print implode('\n',$result) . "<br>";
3968 print "<b><font color=red>";
3969 print "-E- Unable to unzip the uploaded file into the data dir: $data_dir. Aborting import.";
3970 print "</font></b>";
3973 exec('mv ' . $data_dir . '/*/* '. $data_dir . ' 2>&1', $result, $return_code);
3975 # update the data_latest link to point to this new directory
3976 print "-> Updating the latest data dir link<br>\n";
3977 $data_latest = $this->upload_target_path . '/data_latest';
3978 exec('rm ' . $data_latest. '; ln -s ' . $data_dir .' '. $data_latest .' 2>&1', $result, $return_code);
3979 if($return_code != 0) {
3980 print implode('\n',$result) . "<br>";
3981 print "<b><font color=red>";
3982 print "-E- Unable to update the data latest link. Aborting import.";
3983 print "</font></b>";
3987 # run the import perl script to encorporate it into the DB
3988 ob_start('ob_logstdout', 2);
3989 print "-> Importing the data into the database<br>\n";
3990 ob_flush(); flush(); sleep(1);
3991 $import_log = $this->upload_target_path . '/import.log';
3992 $data_log = $this->upload_target_path . '/data.log';
3993 $import_cmd = $this->script_path . '/import_ward_data ' . $data_latest . ' 2>&1 | tee ' . $import_log;
3994 $parse_cmd = $this->script_path . '/parse_ward_data -v ' . $data_latest . ' > ' . $data_log . '2>&1';
3995 #print "import_cmd: $import_cmd<br>";
3996 #print "parse_cmd: $parse_cmd<br>";
3997 ob_start('ob_logstdout', 2);
3998 passthru($import_cmd);
3999 passthru($parse_cmd);
4000 ob_flush(); flush(); sleep(1);
4002 # fix the permissions of the data dir
4003 exec('chmod -R o-rwx ' . $data_dir, $result, $return_code);
4005 $this->t->pfp('cmdhandle','cmd');
4006 print "</pre></td></tr></table>";
4007 } else if(($_FILES['uploadedfile']['type'] != "application/zip") &&
4008 ($_FILES['uploadedfile']['type'] != "application/x-zip-compressed") &&
4009 ($_FILES['uploadedfile']['type'] != "application/x-zip") &&
4010 ($_FILES['uploadedfile']['type'] != "application/octet-stream")) {
4011 $uploadstatus = "<b><font color=red>The file format must be a .zip file, please try again! </font></b>";
4012 $uploadstatus.= "<br><br><b>Detected file format: " . $_FILES['uploadedfile']['type'] . "</b>";
4013 $this->t->set_var('uploadstatus',$uploadstatus);
4014 $this->t->pfp('uploadhandle','upload',True);
4016 $uploadstatus = "<b><font color=red> There was an error (" . $_FILES['uploadedfile']['error'];
4017 $uploadstatus.= ") uploading the file, please try again! </font></b>";
4018 $this->t->set_var('uploadstatus',$uploadstatus);
4019 $this->t->pfp('uploadhandle','upload',True);
4021 } else if($action == "presidency") {
4022 $new_data = get_var('eqpres',array('POST'));
4023 foreach ($new_data as $entry) {
4025 $email = $entry['email'];
4026 $indiv = $entry['indiv'];
4027 $name = $entry['name'];
4028 $district = $entry['district'];
4029 $president = $entry['president'];
4030 $counselor = $entry['counselor'];
4031 $secretary = $entry['secretary'];
4032 // look up the individual name for the ID
4033 $name = $indiv2name[$indiv];
4034 //print "id=$id indiv=$indiv name=$name email=$email district=$district president=$president ";
4035 //print "counselor=$counselor secretary=$secretary<br>";
4037 if(($indiv > 0) || ($name != "")) {
4038 if($id < $this->max_presidency_members) {
4039 //print "Updating Existing Entry<br>";
4040 $this->db2->query("UPDATE tc_presidency set" .
4041 " individual=" . $indiv .
4042 " ,district=" . $district .
4043 " ,email='" . $email . "'" .
4044 " ,president='" . $president . "'" .
4045 " ,counselor='" . $counselor . "'" .
4046 " ,secretary='" . $secretary . "'" .
4047 " WHERE presidency=" . $id,__LINE__,__FILE__);
4049 //print "Adding New Entry<br>";
4050 $this->db2->query("INSERT INTO tc_presidency (presidency,individual,district," .
4051 "email,president,counselor,secretary,valid) " .
4052 "VALUES (NULL,'" . $indiv . "','" . $district . "','" .
4053 $email . "','" . $president . "','" .
4054 $counselor . "','" . $secretary . "','1'" .
4055 ")",__LINE__,__FILE__);
4058 //print "Ignoring Blank Entry<br>";
4062 // Now update the tc_district table appropriately
4064 // Delete all the previous district entries from the table
4065 $this->db->query("DELETE from tc_district where valid=1",__LINE__,__FILE__);
4066 $this->db->query("DELETE from tc_district where valid=0",__LINE__,__FILE__);
4068 // Always add a "District 0" assigned to the High Priests Group
4070 $name = "High Priests";
4073 $this->db2->query("INSERT INTO tc_district (district,supervisor,valid) " .
4074 "VALUES ('" . $district . "','" .
4075 $indiv . "','" . $valid . "'" .
4076 ")",__LINE__,__FILE__);
4078 // Requery the tc_presidency table
4079 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1";
4080 $this->db->query($sql,__LINE__,__FILE__);
4081 while ($this->db->next_record()) {
4082 // Extract the data for each presidency record
4083 $id = $this->db->f('presidency');
4084 $indiv = $this->db->f('individual');
4085 $name = $this->db->f('name');
4086 $district = $this->db->f('district');
4089 // If we have a valid district, add it to the district table
4091 $this->db2->query("INSERT INTO tc_district (district,supervisor,valid) " .
4092 "VALUES ('" . $district . "','" .
4093 $indiv . "','" . $valid . "'" .
4094 ")",__LINE__,__FILE__);
4098 $this->t->set_var('adminhandle','');
4099 $this->t->pfp('adminhandle','admin');
4103 $this->t->set_var('adminhandle','');
4104 $this->t->pfp('adminhandle','admin');
4107 // Now save off the data needed for a Presidency Table Update
4109 $sql = "SELECT tp.*, ti.name FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1";
4110 $this->db->query($sql,__LINE__,__FILE__);
4112 $header_row = "<th>Individual</th><th>Email</th><th>District</th><th>President</th><th>Counselor</th><th>Secretary</th>";
4113 while ($this->db->next_record()) {
4114 // Extract the data for each presidency record
4115 $id = $this->db->f('presidency');
4116 $indiv = $this->db->f('individual');
4117 $district = $this->db->f('district');
4118 $name = $this->db->f('name');
4119 $email = $this->db->f('email');
4120 $president = $this->db->f('president');
4121 $counselor = $this->db->f('counselor');
4122 $secretary = $this->db->f('secretary');
4124 // Create the forms needed in the table
4125 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4128 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4131 if($eqpresidency == 0) {
4132 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4133 $table_data.= '<option value=0></option>';
4134 for ($j=0; $j < count($individual); $j++) {
4135 $tmp_id = $individual[$j];
4136 $name = $indiv_name[$j];
4137 if($individual[$j] == $indiv) {
4139 $selected = 'selected="selected"';
4143 $table_data.= '<option value='.$tmp_id.' '.$selected.'>'.$name.'</option>';
4145 $table_data.='</select></td>';
4146 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="'.$indivname.'">';
4148 $table_data.= '<td align=left><input type=text size="20" name="eqpresname" value="Presidency"></td>';
4149 $table_data.= '<input type=hidden name="eqpres['.$id.'][name]" value="Presidency">';
4153 $table_data .= '<td><input type="text" size="50" name="eqpres['.$id.'][email]" value="'.$email.'"></td>';
4156 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4157 $table_data.= '<option value=0></option>';
4158 for ($j=0; $j <= $this->max_num_districts; $j++) {
4159 if($district == $j) {
4160 $selected = 'selected="selected"';
4164 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4166 $table_data.='</select></td>';
4169 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4170 if($president == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4171 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4172 $table_data.='</select></td>';
4175 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4176 if($counselor == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4177 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4178 $table_data.='</select></td>';
4181 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4182 if($secretary == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4183 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4184 $table_data.='</select></td>';
4187 $table_data .= "</tr>\n";
4188 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4189 $this->t->set_var('tr_color',$tr_color);
4192 // Now create 1 blank row to always have a line available to add a new individual with
4193 $id = $this->max_presidency_members;
4194 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4196 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4198 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4199 $table_data.= '<option value=0></option>';
4200 for ($j=0; $j < count($individual); $j++) {
4201 $tmp_id = $individual[$j];
4202 $name = $indiv_name[$j];
4203 $table_data.= '<option value='.$tmp_id.'>'.$name.'</option>';
4205 $table_data.='</select></td>';
4206 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="">';
4208 $table_data.='<td><input type="text" size="50" name="eqpres['.$id.'][email]" value=""></td>';
4210 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4211 $table_data.= '<option value=0></option>';
4212 for ($j=0; $j <= $this->max_num_districts; $j++) {
4214 $selected = 'selected="selected"';
4218 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4220 $table_data.='</select></td>';
4222 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4223 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4224 $table_data.='</select></td>';
4226 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4227 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4228 $table_data.='</select></td>';
4230 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4231 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4232 $table_data.='</select></td>';
4234 $table_data .= "</tr>\n";
4235 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4236 $this->t->set_var('tr_color',$tr_color);
4238 $this->t->set_var('header_row',$header_row);
4239 $this->t->set_var('table_data',$table_data);
4240 $this->t->pfp('presidencyhandle','presidency',True);
4242 $this->save_sessiondata();
4245 function email_appt($appointment)
4247 //print "Emailing notification of appointment: $appointment <br>";
4249 $sql = "SELECT * FROM tc_appointment where appointment='$appointment'";
4250 $this->db->query($sql,__LINE__,__FILE__);
4252 while ($this->db->next_record()) {
4253 $appointment = $this->db->f('appointment');
4254 $presidency = $this->db->f('presidency');
4255 $location = $this->db->f('location');
4258 $indiv = $this->db->f('individual');
4260 $family = $this->db->f('family');
4264 $uid = $this->db->f('uid');
4266 // Extract the year, month, day, hours, minutes, seconds from the appointment time
4267 $appt_date = $this->db->f('date');
4268 $date_array = explode("-",$appt_date);
4269 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
4270 $appt_time = $this->db->f('time');
4271 $time_array = explode(":",$appt_time);
4272 $hour = $time_array[0]; $minute = $time_array[1]; $seconds = $time_array[2];
4274 // Format the appointment time into an iCal UTC equivalent
4275 $dtstamp = gmdate("Ymd"."\T"."His"."\Z");
4276 $dtstart = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds,$month,$day,$year));
4277 $dtstartstr = date("l, F d, o g:i A", mktime($hour,$minute,$seconds,$month,$day,$year));
4279 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.presidency='$presidency'";
4280 $this->db2->query($sql,__LINE__,__FILE__);
4281 if($this->db2->next_record()) {
4282 $email = $this->db2->f('email');
4283 $interviewer = $this->db2->f('name');
4286 // Set the email address of the interviewer
4290 $sql = "SELECT * FROM tc_individual where individual='$indiv'";
4291 $this->db2->query($sql,__LINE__,__FILE__);
4292 if($this->db2->next_record()) {
4293 $indiv_name = $this->db2->f('name');
4294 $phone = $this->db2->f('phone');
4295 $appt_name = $indiv_name . " Interview";
4296 $duration = $this->default_ppi_appt_duration * 60;
4301 $sql = "SELECT * FROM tc_family WHERE family='$family'";
4302 $this->db2->query($sql,__LINE__,__FILE__);
4303 if($this->db2->next_record()) {
4304 $individual = $this->db2->f('individual');
4305 $sql = "SELECT * FROM tc_individual where individual='$individual'";
4306 $this->db3->query($sql,__LINE__,__FILE__);
4307 if($this->db3->next_record()) {
4308 $phone = $this->db3->f('phone');
4309 $family_name = $this->db3->f('name');
4310 $phone = $this->db3->f('phone');
4312 $appt_name = $family_name . " Family Visit";
4313 $duration = $this->default_visit_appt_duration * 60;
4317 $dtend = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4318 $dtendstr = date("g:i A", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4319 $date = $dtstartstr . "-" . $dtendstr;
4320 $description = "$appt_name : $phone";
4322 if(($uid == 0) && ($appt_name != "")) {
4323 // Create a new calendar item for this appointment, since this must be the first time we
4324 // are sending it out.
4325 print "Sent new appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4326 $uid = rand() . rand(); // Generate a random identifier for this appointment
4327 $subject = "Created: $appt_name";
4329 $this->db->query("UPDATE tc_appointment set" .
4331 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4333 $action = "PUBLISH";
4334 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4335 $dtend, $date, $location, $appt_name, $description, $uid);
4336 } else if(($uid != 0) && ($appt_name == "")) {
4337 // Remove the calendar item for this appointment since it has already been sent
4338 // and there is no name we have changed it to.
4339 print "Sent deleted appointment to " . $interviewer . " at " . $email . " for " . $appt_date . " " . $appt_time . "<br>";
4340 $subject = "Canceled: $appt_date $appt_time";
4342 $this->db->query("UPDATE tc_appointment set" .
4344 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4347 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4348 $dtend, $date, $location, $subject, $subject, $uid);
4349 } else if($uid != 0) {
4350 // Update the existing appointment since we have changed it
4351 print "Sent updated appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4353 $subject = "Canceled: $appt_date $appt_time";
4355 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4356 $dtend, $date, $location, $subject, $subject, $uid);
4358 $uid = rand() . rand(); // Generate a random identifier for this appointment
4359 $this->db->query("UPDATE tc_appointment set" .
4361 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4363 $subject = "Updated: $appt_name";
4364 $action = "PUBLISH";
4365 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4366 $dtend, $date, $location, $appt_name, $description, $uid);
4372 function send_ical_appt($action, $to, $from, $subject, $dtstamp, $dtstart, $dtend, $date, $location, $summary, $description, $uid)
4374 // Initialize our local variables
4375 $boundary = "=MIME_APPOINTMENT_BOUNDARY";
4379 // Form the headers for the email message
4380 $headers.="X-Mailer: PHP/" . phpversion() . "\n";
4381 $headers.="Mime-Version: 1.0\n";
4382 $headers.="Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
4383 $headers.="Content-Disposition: inline\n";
4384 $headers.="Reply-To: $from\n";
4385 $headers.="From: $from\n";
4387 // Print the plaintext version of the appointment
4388 $message.="--$boundary\n";
4389 $message.="Content-Type: text/plain; charset=us-ascii\n";
4390 $message.="Content-Disposition: inline\n";
4392 $message.="What: $description\n";
4393 $message.="When: $date\n";
4394 $message.="Where: $location\n";
4397 // Print the .ics attachment version of the appointment
4398 $message.="--$boundary\n";
4399 $message.="Content-Type: text/calendar; charset=us-ascii\n";
4400 $message.="Content-Disposition: attachment; filename=\"appointment.ics\"\n";
4402 $message.="BEGIN:VCALENDAR" . "\n";
4403 $message.="VERSION:2.0" . "\n";
4404 $message.="PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN" . "\n";
4405 $message.="METHOD:$action" . "\n";
4406 $message.="BEGIN:VEVENT" . "\n";
4407 $message.="ORGANIZER:MAILTO:$from". "\n";
4408 $message.="DTSTAMP:$dtstamp" . "\n";
4409 $message.="DTSTART:$dtstart" . "\n";
4410 $message.="DTEND:$dtend" . "\n";
4411 $message.="SUMMARY:$summary" . "\n";
4412 $message.="DESCRIPTION:$description" . "\n";
4413 $message.="LOCATION:$location" . "\n";
4414 $message.="UID:$uid" ."\n";
4415 $message.="TRANSP:OPAQUE" . "\n";
4416 $message.="SEQUENCE:0" . "\n";
4417 $message.="CLASS:PUBLIC" . "\n";
4418 $message.="END:VEVENT" . "\n";
4419 $message.="END:VCALENDAR" . "\n";
4421 // Complete the message
4422 $message.="--$boundary\n";
4425 mail($to, $subject, $message, $headers);
4428 function get_time_selection_form($hour, $minute, $pm, $presidency, $appointment)
4433 if($hour == 0) { $blank = 1; }
4435 if($this->time_drop_down_lists == 1) {
4436 // Create drop down lists to get the time
4437 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][hour]>';
4438 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4439 foreach(range(1,12) as $num) {
4441 $selected = 'selected="selected"';
4445 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4447 $form_data.= '</select>';
4448 $form_data.= ' : ';
4449 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][minute]>';
4450 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4453 if($num < 10) { $num = "0" . "$num"; }
4454 if($minute == $num) {
4455 $selected = 'selected="selected"';
4459 if($blank == 1) { $selected = ""; }
4460 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4461 $num = $num + $this->time_drop_down_list_inc;
4463 $form_data.= '</select>';
4465 // Use free form text fields to get the time
4471 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][hour] value='.$hour.'>';
4473 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][minute] value='.$minute.'>';
4474 $form_data.= ' ';
4476 // Always use a drop-down select form for am/pm
4477 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][pm]>';
4480 $form_data.= '<option value=0 selected>am</option>';
4481 $form_data.= '<option value=1>pm</option>';
4484 $form_data.= '<option value=0>am</option>';
4485 $form_data.= '<option value=1 selected>pm</option>';
4488 $form_data.= '<option value=""></option>';
4489 $form_data.= '<option value=0>am</option>';
4490 $form_data.= '<option value=1>pm</option>';
4492 $form_data.= '</select>';