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' ORDER BY date DESC";
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 $supervisor_address = $this->db2->f('address');
1726 $location = "$supervisor_last_name"." home ($supervisor_address)";
1728 if($indiv == 0) { $location = ""; }
1730 //print "indiv: $indiv appointment: $appointment <br>";
1731 //Only perform a database update if we have made a change to this appointment
1732 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and individual='$indiv' and location='$location'";
1733 $this->db->query($sql,__LINE__,__FILE__);
1734 if(!$this->db->next_record()) {
1735 // Perform database save actions here
1736 $this->db->query("UPDATE tc_appointment set " .
1737 " individual='" . $indiv . "'" .
1738 ",location='" . $location . "'" .
1739 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1740 // Email the appointment
1741 $this->email_appt($appointment);
1746 // Save any changes made to the int notes table
1747 $new_data = get_var('hti_notes',array('POST'));
1748 foreach ($new_data as $entry) {
1749 $hti_notes = $entry['notes'];
1750 $individual = $entry['individual'];
1751 $indiv_name = $entry['indiv_name'];
1752 $hti_pri = $entry['pri'];
1753 //print "hti_notes: $hti_notes indiv_name: $indiv_name <Br>";
1754 // Perform database save actions here
1755 $this->db->query("SELECT * FROM tc_companion WHERE individual=$individual and valid=1",__LINE__,__FILE__);
1756 if ($this->db->next_record()) {
1757 $scheduling_priority = $this->db->f('scheduling_priority');
1758 //$this->logToFile("int_sched", "UPDATE tc_scheduling_priority SET priority='$hti_pri', notes=\"$hti_notes\" WHERE scheduling_priority='$scheduling_priority'");
1759 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$hti_pri', notes=\"$hti_notes\" WHERE scheduling_priority='$scheduling_priority'",__LINE__,__FILE__);
1763 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched');
1764 //Header('Location: ' . $take_me_to_url);
1767 // Get the Districts
1768 $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";
1769 $this->db->query($sql,__LINE__,__FILE__);
1771 while ($this->db->next_record()) {
1772 $district = $this->db->f('district');
1773 $districts[$i]['district'] = $this->db->f('district');
1774 $districts[$i]['name'] = $this->db->f('name');
1775 $districts[$i]['supervisor'] = $this->db->f('supervisor');
1776 $districts[$i]['presidency'] = $this->db->f('presidency');
1780 // APPOINTMENT TABLE
1782 $date_width=250; $time_width=100; $indiv_width=200; $location_width=100;
1783 $appt_table_width=$date_width + $time_width + $indiv_width + $location_width;
1784 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1785 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1786 $appt_header_row.= "<th width=$indiv_width><font size=-2>Individual</th>";
1787 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
1788 $appt_table_data = "";
1790 $total_comps=0; $comps_with_quarterly_int=0;
1792 // Display a scheduling table for each district
1793 for ($d=0; $d < count($districts); $d++) {
1794 $table_data=""; $appt_table_data="";
1795 $this->t->set_var('district_number',$districts[$d]['district']);
1796 $this->t->set_var('district_name',$districts[$d]['name']);
1797 $supervisor = $districts[$d]['supervisor'];
1798 $supervisor_array = explode(",", $supervisor);
1799 $supervisor_last_name = $supervisor_array[0];
1800 $sql = "SELECT * FROM tc_individual where individual='$supervisor'";
1801 $this->db2->query($sql,__LINE__,__FILE__);
1802 if($this->db2->next_record()) {
1803 $supervisor_address = $this->db2->f('address');
1805 $location = "$supervisor_last_name"." home ($supervisor_address)";
1806 $table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": All Individuals with Interviews Not Completed";
1807 $appt_table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": Interview Appointment Slots";
1808 $this->t->set_var('table_title',$table_title);
1809 $this->t->set_var('appt_table_title',$appt_table_title);
1811 // query the database for all the appointments
1812 $sql = "SELECT * FROM tc_appointment where presidency=".$districts[$d]['presidency']." and date>=CURDATE() ORDER BY date ASC, time ASC";
1813 $this->db->query($sql,__LINE__,__FILE__);
1815 while ($this->db->next_record()) {
1816 $appointment = $this->db->f('appointment');
1817 $indiv = $this->db->f('individual');
1818 $location = $this->db->f('location');
1819 if(($location == "") && ($indiv > 0)) { $location = "$supervisor_last_name"." home ($supervisor_address)"; }
1821 $date = $this->db->f('date');
1822 $date_array = explode("-",$date);
1823 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1824 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1826 $time = $this->db->f('time');
1827 $time_array = explode(":",$time);
1828 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1830 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1831 $appt_table_data.= "<td align=center>$day_string</td>";
1832 $appt_table_data.= "<td align=center>$time_string</td>";
1834 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][individual]>';
1835 $appt_table_data.= '<option value=0></option>';
1836 for ($i=0; $i < count($individual_data); $i++) {
1837 $id = $individual_data[$i];
1838 $name = $indiv_name_data[$i];
1839 if($individual_data[$i] == $indiv) {
1840 $selected[$id] = 'selected="selected"';
1842 $selected[$id] = '';
1844 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1846 $appt_table_data.='</select></td>';
1848 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
1849 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
1851 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1852 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][supervisor]" value="'.$supervisor.'">';
1854 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1855 $this->t->set_var('tr_color',$tr_color);
1858 $this->t->set_var('appt_table_data',$appt_table_data);
1859 $this->t->set_var('appt_header_row',$appt_header_row);
1860 $this->t->set_var('appt_table_width',$appt_table_width);
1862 // INTERVIEW SCHEDULING TABLE
1864 // Select all the unique companionship numbers for this district
1865 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$d]['district'];
1866 $this->db->query($sql,__LINE__,__FILE__);
1867 $j=0; $unique_companionships = '';
1868 while ($this->db->next_record())
1870 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
1875 for ($j=0; $j < count($unique_companionships); $j++) {
1876 // Select all the companions from each companionship
1877 $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'];
1878 $this->db->query($sql,__LINE__,__FILE__);
1879 $k=0; $int_completed=0;
1880 $comp = $unique_companionships[$j]['companionship'];
1881 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1882 $this->t->set_var('tr_color',$tr_color);
1884 while ($this->db->next_record()) {
1885 // Get this companions information
1886 $individual = $this->db->f('individual');
1888 $id = $this->db->f('individual');
1889 $name = $this->db->f('name');
1890 $phone = $this->db->f('phone');
1891 $hti_pri = $this->db->f('priority');
1892 $hti_notes = $this->db->f('notes');
1894 // If the companionship has already had its quarterly interview,
1895 // Skip the other companion in the companionship.
1896 if($int_completed == 1) {
1897 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1898 $completed_data.= "<td align=center>$phone</td>";
1899 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1900 $completed_data.= "<td align=left>$hti_notes</td>";
1901 $completed_data.= '</tr>';
1902 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1903 $this->t->set_var('tr_color2',$tr_color2);
1904 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1905 $this->t->set_var('tr_color',$tr_color);
1909 // If this companionship has had a hometeaching interview this quarter, don't show them on the schedule list
1910 $sql = "SELECT * FROM tc_interview WHERE date >= '$quarter_start' AND date < '$quarter_end' AND individual='$id' AND interview_type='hti'";
1911 $this->db2->query($sql,__LINE__,__FILE__);
1913 if(!$this->db2->next_record()) {
1914 $sql = "SELECT * FROM tc_interview WHERE individual='$id' AND interview_type='hti' ORDER BY date DESC";
1915 $this->db3->query($sql,__LINE__,__FILE__);
1916 if($this->db3->next_record()) {
1917 $date = $this->db3->f('date');
1921 $link_data['menuaction'] = 'tc.tc.int_update';
1922 $link_data['individual'] = $id;
1923 $link_data['name'] = $name;
1924 $link_data['interview'] = '';
1925 $link_data['action'] = 'add';
1926 $link_data['interview_type'] = 'hti';
1927 $link_data['interviewer'] = $districts[$d]['supervisor'];
1928 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1929 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1930 $table_data.= "<td align=center>$phone</td>";
1931 $table_data.= "<td align=center>";
1932 $table_data.= '<select name=hti_notes['.$i.'][pri]>';
1933 foreach(range(0,6) as $num) {
1934 if($num == 0) { $num = 1; } else {$num = $num*5; }
1935 if($hti_pri == $num) {
1936 $selected[$num] = 'selected="selected"';
1938 $selected[$num] = '';
1940 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1942 $table_data.= '</select></td>';
1943 $table_data.= "<td align=center>$date</td>";
1944 $table_data.= '<td><input type=text size="50" maxlength="128" name="hti_notes['.$i.'][notes]" value="'.$hti_notes.'">';
1945 $table_data.= '<input type=hidden name="hti_notes['.$i.'][individual]" value="'.$id.'">';
1946 $table_data.= '<input type=hidden name="hti_notes['.$i.'][indiv_name]" value="'.$name.'">';
1947 $table_data.= '</td>';
1948 $table_data.= '</tr>'."\n";
1951 $link_data['menuaction'] = 'tc.tc.int_update';
1952 $link_data['interviewer'] = $this->db2->f('interviewer');
1953 $link_data['individual'] = $this->db2->f('individual');
1954 $link_data['name'] = $name;
1955 $link_data['interview'] = $this->db2->f('interview');
1956 $link_data['interview_type'] = 'hti';
1957 $link_data['action'] = 'view';
1958 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1959 $comps_with_quarterly_int++;
1961 $date = $this->db2->f('date');
1962 $hti_notes = $this->db2->f('notes');
1963 if(strlen($hti_notes) > 40) { $hti_notes = substr($hti_notes,0,40) . "..."; }
1964 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1965 $completed_data.= "<td align=center>$phone</td>";
1966 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1967 $completed_data.= "<td align=left>$hti_notes</td>";
1968 $completed_data.= '</tr>';
1973 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1974 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1975 $completed_header_row = "<th width=$name_width><font size=-2>Individual Name</th>";
1976 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1977 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1978 $completed_header_row.= "<th width=$notes_width><font size=-2>Interview Notes</th>";
1980 $this->t->set_var('table_width',$table_width);
1981 $this->t->set_var('header_row',$header_row);
1982 $this->t->set_var('table_data',$table_data);
1983 $this->t->set_var('completed_header_row',$completed_header_row);
1984 $this->t->set_var('completed_table_width',$completed_table_width);
1985 $this->t->set_var('completed',$completed_data);
1986 $this->t->fp('indivlist','individual_list',True);
1988 } // End for each district loop
1991 $indivs_width=300; $totals_width=100;
1992 $totals_table_width=$indivs_width + $totals_width;
1993 $totals_header_row = "<th width=$indivs_width><font size=-2>Individuals</th>";
1994 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
1995 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1996 $totals_data.= "<td align=left><font size=-2><b>Total Companionships with interviews completed:</b></font></td>";
1997 $totals_data.= "<td align=center><font size=-2><b>$comps_with_quarterly_int / $total_comps</b></font></td>";
1998 $percent = ceil(($comps_with_quarterly_int / $total_comps)*100);
1999 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2000 $this->t->set_var('tr_color',$tr_color);
2001 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2002 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2003 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2004 $totals_data.= "</tr>";
2006 $this->t->set_var('totals',$totals_data);
2007 $this->t->set_var('totals_header_row',$totals_header_row);
2008 $this->t->set_var('totals_table_width',$totals_table_width);
2010 $this->t->pfp('out','int_sched_t');
2011 $this->save_sessiondata();
2015 function vis_sched()
2017 $this->t->set_file(array('vis_sched_t' => 'vis_sched.tpl'));
2018 $this->t->set_block('vis_sched_t','family_list','familylist');
2019 $this->t->set_block('vis_sched_t','appt_list','apptlist');
2020 $action = get_var('action',array('GET','POST'));
2022 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
2023 $this->t->set_var('lang_reset','Clear Changes');
2025 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2026 $this->t->set_var('vis_link_title','View Yearly Visits');
2028 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
2029 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2031 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched&action=save'));
2032 $this->t->set_var('title','Presidency Yearly Visit Scheduler');
2034 $family_width=500; $phone_width=40; $pri_width=10; $notes_width=128; $visit_date_width=20;
2035 $table_width=$family_width + $phone_width + $pri_width + $notes_width + $visit_date_width;
2036 $header_row = "<th width=$family_width><font size=-2>Family Name</th>";
2037 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2038 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
2039 $header_row.= "<th width=$visit_date_width><font size=-2>Last Visit</th>";
2040 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
2041 $table_data=""; $completed_data=""; $totals_data="";
2045 // create the family id -> family name mapping
2046 $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";
2047 $this->db->query($sql,__LINE__,__FILE__);
2050 while ($this->db->next_record()) {
2051 $family_id[$i] = $this->db->f('family');
2052 $family_name[$i] = $this->db->f('name');
2053 $familyid2name[$family_id[$i]] = $family_name[$i];
2054 $familyid2address[$family_id[$i]] = $this->db->f('address');
2057 array_multisort($family_name, $family_id);
2059 if($action == 'save') {
2060 // Save any changes made to the appointment table
2061 $new_data = get_var('appt_notes',array('POST'));
2062 if($new_data != "") {
2063 foreach ($new_data as $entry) {
2064 $family = $entry['family'];
2065 $appointment = $entry['appointment'];
2066 $location = $entry['location'];
2067 if($location == "") {
2068 $family_name_array = explode(",", $familyid2name[$family]);
2069 $family_last_name = $family_name_array[0];
2070 $family_address = $familyid2address[$family];
2071 $location = "$family_last_name"." home ($family_address)";
2073 if($family == 0) { $location = ""; }
2075 //Only perform a database update if we have made a change to this appointment
2076 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and family='$family' and location='$location'";
2077 $this->db->query($sql,__LINE__,__FILE__);
2078 if(!$this->db->next_record()) {
2079 // Perform database save actions here
2080 $this->db->query("UPDATE tc_appointment set " .
2081 " family='" . $family . "'" .
2082 ",location='" . $location . "'" .
2083 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
2085 // Email the appointment
2086 $this->email_appt($appointment);
2091 // Save any changes made to the visit notes table
2092 $new_data = get_var('vis_notes',array('POST'));
2093 foreach ($new_data as $entry) {
2094 $visit_notes = $entry['notes'];
2095 $family = $entry['family_id'];
2096 $visit_pri = $entry['pri'];
2097 // Perform database save actions here
2098 $this->db->query("SELECT * FROM tc_family WHERE family='$family'",__LINE__,__FILE__);
2099 if ($this->db->next_record()) {
2100 $scheduling_priority = $this->db->f('scheduling_priority');
2101 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$visit_pri', notes=\"$visit_notes\" WHERE scheduling_priority='$scheduling_priority'", __LINE__, __FILE__);
2105 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched');
2106 //Header('Location: ' . $take_me_to_url);
2109 // APPOINTMENT TABLE
2110 $date_width=250; $time_width=100; $family_width=250; $location_width=100;
2111 $appt_table_width=$date_width + $time_width + $family_width + $location_width;
2112 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
2113 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
2114 $appt_header_row.= "<th width=$family_width><font size=-2>Family</th>";
2115 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
2116 $appt_table_data = "";
2118 // Find out what the President ID is
2119 $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";
2120 $this->db->query($sql,__LINE__,__FILE__);
2121 if($this->db->next_record()) {
2122 $presidency_name = $this->db->f('name');
2123 $presidency_id = $this->db->f('presidency');
2125 print "<hr><font color=red><h3>-E- Unable to locate Presidency in tc_presidency table</h3></font></hr>";
2129 // query the database for all the appointments
2130 $sql = "SELECT * FROM tc_appointment where presidency=$presidency_id and date>=CURDATE() ORDER BY date ASC, time ASC";
2131 $this->db->query($sql,__LINE__,__FILE__);
2133 while ($this->db->next_record()) {
2134 $appointment = $this->db->f('appointment');
2135 $family = $this->db->f('family');
2136 $location = $this->db->f('location');
2137 $family_name_array = explode(",", $familyid2name[$family]);
2138 $family_last_name = $family_name_array[0];
2139 $family_address = $familyid2address[$family];
2140 if(($location == "") && ($family > 0)) { $location = "$family_last_name"." home ($family_address)"; }
2142 $date = $this->db->f('date');
2143 $date_array = explode("-",$date);
2144 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
2145 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
2147 $time = $this->db->f('time');
2148 $time_array = explode(":",$time);
2149 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
2151 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2152 $appt_table_data.= "<td align=center>$day_string</td>";
2153 $appt_table_data.= "<td align=center>$time_string</td>";
2155 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][family]>';
2156 $appt_table_data.= '<option value=0></option>';
2157 for ($i=0; $i < count($family_id); $i++) {
2158 $id = $family_id[$i];
2159 $name = $family_name[$i];
2160 if($family_id[$i] == $family) {
2161 $selected[$id] = 'selected="selected"';
2163 $selected[$id] = '';
2165 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
2167 $appt_table_data.='</select></td>';
2169 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
2170 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
2172 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
2174 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2175 $this->t->set_var('tr_color',$tr_color);
2178 $this->t->set_var('appt_table_data',$appt_table_data);
2179 $this->t->set_var('appt_header_row',$appt_header_row);
2180 $this->t->set_var('appt_table_width',$appt_table_width);
2183 // VISIT SCHEDULING TABLE
2184 $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";
2185 $this->db->query($sql,__LINE__,__FILE__);
2187 $total_families=0; $families_with_yearly_visit=0;
2189 while ( $this->db->next_record()) {
2191 $id = $this->db->f('family');
2192 $name = $this->db->f('name');
2193 $phone = $this->db->f('phone');
2194 $vis_pri = $this->db->f('priority');
2195 $vis_notes = $this->db->f('notes');
2197 // If this family has had a yearly visit this year, don't show them on the schedule list
2198 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2199 $sql = "SELECT * FROM tc_visit WHERE date > '$year_start' AND date < '$year_end' ".
2200 "AND family=" . $id . " AND companionship=0";
2201 $this->db2->query($sql,__LINE__,__FILE__);
2203 if(!$this->db2->next_record()) {
2204 $sql = "SELECT * FROM tc_visit WHERE family=" . $id . " AND companionship=0 ORDER BY date DESC";
2205 $this->db3->query($sql,__LINE__,__FILE__);
2206 if($this->db3->next_record()) {
2207 $date = $this->db3->f('date');
2211 $link_data['menuaction'] = 'tc.tc.vis_update';
2212 $link_data['visit'] = '';
2213 $link_data['family'] = $id;
2214 $link_data['name'] = $name;
2215 $link_data['action'] = 'add';
2216 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2217 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2218 $table_data.= "<td align=center>$phone</td>";
2219 $table_data.= "<td align=center>";
2220 $table_data.= '<select name=vis_notes['.$id.'][pri]>';
2221 foreach(range(0,6) as $num) {
2222 if($num == 0) { $num = 1; } else {$num = $num*5; }
2223 if($vis_pri == $num) {
2224 $selected[$num] = 'selected="selected"';
2226 $selected[$num] = '';
2228 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2230 $table_data.= '</select></td>';
2231 $table_data.= "<td align=center>$date</td>";
2232 $table_data.= '<td><input type=text size="50" maxlength="128" name="vis_notes['.$id.'][notes]" value="'.$vis_notes.'">';
2233 $table_data.= '<input type=hidden name="vis_notes['.$id.'][family_id]" value="'.$id.'">';
2234 $table_data.= '<input type=hidden name="vis_notes['.$id.'][family_name]" value="'.$name.'">';
2235 $table_data.= '</td>';
2236 $table_data.= '</tr>';
2237 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2238 $this->t->set_var('tr_color',$tr_color);
2240 $link_data['menuaction'] = 'tc.tc.vis_update';
2241 $link_data['visit'] = $this->db2->f('visit');
2242 $link_data['family'] = $this->db2->f('family');
2243 $link_data['name'] = $name;
2244 $link_data['date'] = $this->db2->f('date');
2245 $link_data['action'] = 'view';
2246 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2247 $families_with_yearly_visit++;
2248 $date = $this->db2->f('date');
2249 $vis_notes = $this->db2->f('notes');
2250 if(strlen($vis_notes) > 40) { $vis_notes = stripslashes(substr($vis_notes,0,40) . "..."); }
2251 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2252 $completed_data.= "<td align=center>$phone</td>";
2253 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2254 $completed_data.= "<td align=left>$vis_notes</td>";
2255 $completed_data.= '</tr>';
2256 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
2257 $this->t->set_var('tr_color2',$tr_color2);
2261 $name_width=190; $phone_width=100; $date_width=100; $notes_width=300;
2262 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
2263 $completed_header_row = "<th width=$name_width><font size=-2>Family Name</th>";
2264 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2265 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
2266 $completed_header_row.= "<th width=$notes_width><font size=-2>Visit Notes</th>";
2268 $family_width=300; $totals_width=100;
2269 $totals_table_width=$family_width + $totals_width;
2270 $totals_header_row = "<th width=$family_width><font size=-2>Families</th>";
2271 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2272 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2273 $totals_data.= "<td align=left><font size=-2><b>Total Families with yearly Visits completed:</b></font></td>";
2274 $totals_data.= "<td align=center><font size=-2><b>$families_with_yearly_visit / $total_families</b></font></td>";
2275 $percent = ceil(($families_with_yearly_visit / $total_families)*100);
2276 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2277 $this->t->set_var('tr_color',$tr_color);
2278 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2279 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2280 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2281 $totals_data.= "</tr>";
2283 $this->t->set_var('table_width',$table_width);
2284 $this->t->set_var('header_row',$header_row);
2285 $this->t->set_var('table_data',$table_data);
2286 $this->t->set_var('totals_header_row',$totals_header_row);
2287 $this->t->set_var('totals_table_width',$totals_table_width);
2288 $this->t->set_var('completed_header_row',$completed_header_row);
2289 $this->t->set_var('completed_table_width',$completed_table_width);
2290 $this->t->set_var('completed',$completed_data);
2291 $this->t->set_var('totals',$totals_data);
2292 $this->t->fp('familylist','family_list',True);
2293 $this->t->fp('apptlist','appt_list',True);
2295 $this->t->pfp('out','vis_sched_t');
2296 $this->save_sessiondata();
2301 $this->t->set_file(array('ppi_view_t' => 'ppi_view.tpl'));
2302 $this->t->set_block('ppi_view_t','district_list','list');
2304 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2305 $num_months = get_var('num_months',array('GET','POST'));
2306 if($num_months == '') { $num_months = $this->default_ppi_num_months; }
2307 $this->t->set_var('num_months',$num_months);
2308 if($num_months == 1) {
2309 $this->t->set_var('lang_num_months','Month of History');
2311 $this->t->set_var('lang_num_months','Months of History');
2313 $this->t->set_var('lang_filter','Filter');
2314 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2316 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2317 $this->t->set_var('ppi_link_title','Yearly PPIs');
2319 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
2320 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
2322 $this->t->set_var('title','Yearly PPIs');
2323 $num_months = get_var('num_months',array('GET','POST'));
2324 if($num_months == '') { $num_months = $this->default_ppi_num_years; }
2325 $this->t->set_var('num_months',$num_months);
2326 if($num_months == 1) {
2327 $this->t->set_var('lang_num_months','Year of History');
2329 $this->t->set_var('lang_num_months','Years of History');
2332 $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";
2333 $this->db->query($sql,__LINE__,__FILE__);
2334 if($this->db->next_record()) {
2335 $president_name = $this->db->f('name');
2336 $interviewer = $this->db->f('individual');
2338 print "<hr><font color=red><h3>-E- Unable to locate President in tc_presidency table</h3></font></hr>";
2341 $this->t->set_var('district_number','*');
2342 $this->t->set_var('district_name',$president_name);
2344 $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";
2345 $this->db->query($sql,__LINE__,__FILE__);
2347 while ($this->db->next_record()) {
2348 $individual[$i] = $this->db->f('individual');
2349 $indiv_name[$i] = $this->db->f('name');
2350 $indiv_phone[$individual[$i]] = $this->db->f('phone');
2351 $indiv_priority[$individual[$i]] = $this->db->f('priority');
2352 $indiv_notes[$individual[$i]] = $this->db->f('notes');
2356 array_multisort($indiv_name, $individual);
2357 //var_dump($indiv_name); print "<br><br>"; var_dump($individual);
2359 $header_row="<th width=$comp_width><font size=-2>Individual Name</th>";
2361 $indiv_width=400; $ppi_width=75; $table_width=$indiv_width + $num_months*$ppi_width;
2363 for($m=$num_months; $m >= 0; $m--) {
2364 $year = date('Y') - $m;
2365 $header_row .= "<th width=150><font size=-2>$year</th>";
2369 for ($j=0; $j < count($individual); $j++) {
2370 $id = $individual[$j];
2371 $name = $indiv_name[$j];
2372 $phone = $indiv_phone[$id];
2374 $link_data['menuaction'] = 'tc.tc.ppi_update';
2375 $link_data['interviewer'] = $interviewer;
2376 $link_data['individual'] = $id;
2377 $link_data['name'] = $name;
2378 $link_data['interview'] = '';
2379 $link_data['interview_type'] = 'ppi';
2380 $link_data['action'] = 'add';
2381 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2382 $this->nextmatchs->template_alternate_row_color(&$this->t);
2383 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2385 // Find out how many times PPIs were performed in the past $num_months for this individual
2386 for($m=$num_months; $m >= 0; $m--) {
2387 $year = date('Y') - $m;
2388 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2389 $sql = "SELECT * FROM tc_interview WHERE date > '$year_start' AND date < '$year_end' ".
2390 "AND individual=" . $id . " AND interview_type='ppi' ORDER BY date DESC";
2391 $this->db2->query($sql,__LINE__,__FILE__);
2393 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
2394 if($this->db2->next_record()) {
2395 $ppis[$m]++; $total_ppis[$m]++; $ppi_recorded[$companionship][$m]=1;
2396 $link_data['menuaction'] = 'tc.tc.ppi_update';
2397 $link_data['companionship'] = $companionship;
2398 $link_data['interviewer'] = $this->db2->f('interviewer');
2399 $link_data['indiv'] = $id;
2400 $link_data['name'] = $name;
2401 $link_data['interview'] = $this->db2->f('interview');
2402 $link_data['interview_type'] = 'ppi';
2403 $link_data['action'] = 'view';
2404 $date = $this->db2->f('date');
2405 $date_array = explode("-",$date);
2406 $month = $date_array[1];
2407 $day = $date_array[2];
2408 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2409 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2411 $table_data .= "<td> </td>";
2414 $table_data .= "</tr>\n";
2416 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2418 $stat_data = "<tr><td><b><font size=-2>$total_indivs Individuals<br>PPI Totals:</font></b></td>";
2419 for($m=$num_months; $m >=0; $m--) {
2420 $percent = ceil(($ppis[$m] / $total_indivs)*100);
2421 $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
2423 $stat_data .= "</tr>";
2425 $this->t->set_var('table_width',$table_width);
2426 $this->t->set_var('header_row',$header_row);
2427 $this->t->set_var('table_data',$table_data);
2428 $this->t->set_var('stat_data',$stat_data);
2429 $this->t->pfp('out','ppi_view_t');
2430 $this->save_sessiondata();
2433 function ppi_update()
2435 $this->t->set_file(array('form' => 'ppi_update.tpl'));
2436 $this->t->set_block('form','interviewer_list','int_list');
2437 $this->t->set_block('form','add','addhandle');
2438 $this->t->set_block('form','edit','edithandle');
2440 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2441 $this->t->set_var('readonly','');
2442 $this->t->set_var('disabled','');
2444 $action = get_var('action',array('GET','POST'));
2445 $companionship = get_var('companionship',array('GET','POST'));
2446 $interviewer = get_var('interviewer',array('GET','POST'));
2447 $name = get_var('name',array('GET','POST'));
2448 $interview = get_var('interview',array('GET','POST'));
2449 $individual = get_var('individual',array('GET','POST'));
2450 $date = get_var('date',array('GET','POST'));
2451 $notes = get_var('notes',array('GET','POST'));
2452 $interview_type = get_var('interview_type',array('GET','POST'));
2454 $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)";
2455 $this->db2->query($sql,__LINE__,__FILE__);
2456 while ($this->db2->next_record()) {
2457 $indiv = $this->db2->f('individual');
2458 $interviewer_name = $this->db2->f('name');
2459 if($indiv == $interviewer) {
2460 $this->t->set_var('interviewer',$indiv . ' selected');
2462 $this->t->set_var('interviewer',$indiv);
2464 #print "indiv: $indiv interviewer: $interviewer<br>";
2465 $this->t->set_var('interviewer_name',$interviewer_name);
2466 $this->t->set_var('eqpresppi_checked','checked');
2467 $this->t->fp('int_list','interviewer_list',True);
2469 #print "selected interviewer: $interviewer<br>";
2470 if($action == 'save') {
2471 $notes = get_var('notes',array('POST'));
2472 $this->db->query("UPDATE tc_interview set " .
2473 " interview='" . $interview . "'" .
2474 ", interviewer='" . $interviewer . "'" .
2475 ", individual='" . $individual . "'" .
2476 ", date='" . $date . "'" .
2477 ", notes=\"" . $notes . "\"" .
2478 ", interview_type='" . $interview_type . "'" .
2479 " WHERE interview=" . $interview,__LINE__,__FILE__);
2484 if($action == 'insert') {
2485 $notes = get_var('notes',array('POST'));
2486 $this->db->query("INSERT INTO tc_interview (interviewer,individual,date,notes,interview_type) " .
2487 "VALUES ('" . $interviewer . "','" . $individual . "','" .
2488 $date . "',\"" . $notes . "\",'" . $interview_type ."')",__LINE__,__FILE__);
2493 if($action == 'add') {
2494 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2495 $this->t->set_var('interview', '');
2496 $this->t->set_var('interviewer', $interviewer);
2497 $this->t->set_var('name',$name);
2498 $this->t->set_var('individual',$individual);
2499 $this->t->set_var('date','');
2500 $this->t->set_var('notes','');
2501 $this->t->set_var('interview_type',$interview_type);
2502 $this->t->set_var('eqpresppi_checked','checked');
2503 $this->t->set_var('lang_done','Cancel');
2504 $this->t->set_var('lang_action','Adding New PPI');
2505 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview=' .
2506 $interview . '&action=' . 'insert'));
2509 if($action == 'edit' || $action == 'view') {
2510 $sql = "SELECT * FROM tc_interview WHERE interview=" . $interview . " AND interview_type='ppi'";
2511 $this->db->query($sql,__LINE__,__FILE__);
2512 $this->db->next_record();
2513 $this->t->set_var('interview',$interview);
2514 $this->t->set_var('name',$name);
2515 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2516 $this->t->set_var('individual',$this->db->f('individual'));
2517 $this->t->set_var('date',$this->db->f('date'));
2518 $this->t->set_var('notes',$this->db->f('notes'));
2519 $this->t->set_var('interview_type',$this->db->f('interview_type'));
2520 if($this->db->f('interview_type') == 'ppi') { $this->t->set_var('eqpresppi_checked','checked'); }
2523 if($action == 'edit') {
2524 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2525 $this->t->set_var('lang_done','Cancel');
2526 $this->t->set_var('lang_action','Editing PPI');
2527 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview='.
2528 $interview . '&action=' . 'save'));
2531 if($action == 'view') {
2532 $date = $this->db->f('date');
2533 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2534 $this->t->set_var('readonly','READONLY');
2535 $this->t->set_var('disabled','DISABLED');
2536 $this->t->set_var('lang_done','Done');
2537 $this->t->set_var('lang_action','Viewing PPI');
2538 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview=' .
2539 $interview . '&action=' . 'edit'));
2542 $this->t->set_var('lang_reset','Clear Form');
2543 $this->t->set_var('lang_add','Add PPI');
2544 $this->t->set_var('lang_save','Save Changes');
2545 $this->t->set_var('edithandle','');
2546 $this->t->set_var('addhandle','');
2548 $this->t->pfp('out','form');
2550 if($action == 'view') { $this->t->set_var('lang_save','Edit PPI'); }
2551 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2552 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2554 $this->save_sessiondata();
2559 $this->t->set_file(array('int_view_t' => 'int_view.tpl'));
2560 $this->t->set_block('int_view_t','district_list','list');
2562 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2563 $num_quarters = get_var('num_quarters',array('GET','POST'));
2564 if($num_quarters == '') { $num_quarters = $this->default_int_num_quarters; }
2565 $this->t->set_var('num_quarters',$num_quarters);
2566 if($num_quarters == 1) {
2567 $this->t->set_var('lang_num_quarters','Quarter of History');
2569 $this->t->set_var('lang_num_quarters','Quarters of History');
2571 $this->t->set_var('lang_filter','Filter');
2573 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2574 $this->t->set_var('int_link_title','Hometeaching Interviews');
2576 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
2577 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
2579 $this->t->set_var('title','Hometeaching Interviews');
2581 $num_months = $num_quarters * 3 - 1;
2582 $current_month = $this->current_month;
2583 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
2584 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
2585 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
2586 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
2588 $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";
2589 $this->db->query($sql,__LINE__,__FILE__);
2591 while ($this->db->next_record()) {
2592 $districts[$i]['district'] = $this->db->f('district');
2593 $districts[$i]['name'] = $this->db->f('name');
2594 $districts[$i]['supervisor'] = $this->db->f('supervisor');
2598 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
2599 $this->db->query($sql,__LINE__,__FILE__);
2601 while ($this->db->next_record()) {
2602 $individual[$i] = $this->db->f('individual');
2603 $indiv_name[$i] = $this->db->f('name');
2604 $indiv_phone[$individual[$i]] = $this->db->f('phone');
2607 array_multisort($indiv_name, $individual);
2608 for($i=0; $i < count($individual); $i++) {
2609 $id = $individual[$i];
2610 $indivs[$id] = $indiv_name[$i];
2613 $total_companionships = 0;
2614 $this->nextmatchs->template_alternate_row_color(&$this->t);
2615 for ($i=0; $i < count($districts); $i++) {
2616 $this->t->set_var('district_number',$districts[$i]['district']);
2617 $this->t->set_var('district_name',$districts[$i]['name']);
2618 $supervisor = $districts[$i]['supervisor'];
2620 // Select all the unique companionship numbers for this district
2621 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$i]['district'];
2622 $this->db->query($sql,__LINE__,__FILE__);
2623 $j=0; $unique_companionships = '';
2624 while ($this->db->next_record()) {
2625 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
2629 $comp_width=250; $int_width=75; $table_width=$comp_width + $num_months*$int_width;
2630 $table_data=""; $num_companionships = $j; $num_indivs = 0;
2631 for($m=$num_months; $m >= 0; $m--) { $ints[$m] = 0; }
2632 for ($j=0; $j < count($unique_companionships); $j++) {
2633 // Select all the companions in each companionship
2634 $sql = "SELECT * FROM tc_companion where valid=1 and ".
2635 "companionship=". $unique_companionships[$j]['companionship'];
2636 $this->db->query($sql,__LINE__,__FILE__);
2638 $comp = $unique_companionships[$j]['companionship'];
2639 for($m=$num_months; $m >= 0; $m--) { $int_recorded[$comp][$m] = 0; }
2640 while ($this->db->next_record()) {
2641 // Get this companions information
2643 $companionship = $this->db->f('companionship');
2644 $individual = $this->db->f('individual');
2645 $name = $indivs[$individual];
2646 $phone = $indiv_phone[$individual];
2647 $link_data['menuaction'] = 'tc.tc.int_update';
2648 $link_data['companionship'] = $companionship;
2649 $link_data['interviewer'] = $supervisor;
2650 $link_data['individual'] = $individual;
2651 $link_data['name'] = $name;
2652 $link_data['interview'] = '';
2653 $link_data['interview_type'] = 'hti';
2654 $link_data['action'] = 'add';
2655 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2656 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2658 // Find out how many times Interviews were performed in the past $num_months for this individual
2659 $header_row="<th width=$comp_width><font size=-2>Companionship</th>";
2660 for($m=$num_months; $m >= 0; $m--) {
2661 $month = $current_month - $m;
2662 $year = $this->current_year;
2664 $remainder = $month;
2665 $month = 12 + $remainder;
2668 if($month < 10) { $month = "0"."$month"; }
2669 $month_start = "$year"."-"."$month"."-"."01";
2670 $month_end = "$year"."-"."$month"."-"."31";
2671 $month = "$month"."/"."$year";
2672 $sql = "SELECT * FROM tc_interview WHERE date >= '$month_start' AND date <= '$month_end' ".
2673 "AND individual=" . $individual . " AND interview_type='hti' ORDER BY date DESC";
2674 $this->db2->query($sql,__LINE__,__FILE__);
2675 $header_row .= "<th width=$int_width><font size=-2>$month</th>";
2677 if(!$total_ints[$m]) { $total_ints[$m] = 0; }
2678 if($this->db2->next_record()) {
2679 if(!$int_recorded[$companionship][$m]) {
2682 $int_recorded[$companionship][$m]=1;
2684 $link_data['menuaction'] = 'tc.tc.int_update';
2685 $link_data['companionship'] = $companionship;
2686 $link_data['interviewer'] = $this->db2->f('interviewer');
2687 $link_data['individual'] = $individual;
2688 $link_data['name'] = $name;
2689 $link_data['interview'] = $this->db2->f('interview');
2690 $link_data['action'] = 'view';
2691 $link_data['interview_type'] = 'hti';
2692 $date = $this->db2->f('date');
2693 $date_array = explode("-",$date);
2694 $month = $date_array[1];
2695 $day = $date_array[2];
2696 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2697 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2700 $table_data .= "<td> </td>";
2703 $table_data .= "</tr>";
2706 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2708 $total_companionships += $num_companionships;
2709 $stat_data = "<tr><td><b><font size=-2>$num_companionships Companionships<br>Interview Totals:</font></b></td>";
2711 // Print the hometeaching interview stats
2712 for($m=$num_months; $m >=0; $m--) {
2713 $month = $current_month - $m;
2714 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
2715 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
2716 //print "$month % $this->monthly_hometeaching_interview_stats = $month_begins <br>";
2717 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
2718 if(($month_begins) == 1) {
2721 $total += $ints[$m];
2723 $percent = ceil(($total / $num_companionships)*100);
2724 $stat_data .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
2726 $stat_data .= "</tr>";
2728 $this->t->set_var('table_width',$table_width);
2729 $this->t->set_var('header_row',$header_row);
2730 $this->t->set_var('table_data',$table_data);
2731 $this->t->set_var('stat_data',$stat_data);
2732 $this->t->fp('list','district_list',True);
2735 // Display the totals
2737 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>Interview Totals:</font></b></td>";
2738 for($m=$num_months; $m >=0; $m--) {
2739 $month = $current_month - $m;
2740 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
2741 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
2742 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
2743 if(($month_begins) == 1) {
2744 $total = $total_ints[$m];
2746 $total += $total_ints[$m];
2748 $percent = ceil(($total / $total_companionships)*100);
2749 $totals .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
2753 $this->t->set_var('totals',$totals);
2754 $this->t->pfp('out','int_view_t');
2755 $this->save_sessiondata();
2758 function int_update()
2760 $this->t->set_file(array('form' => 'int_update.tpl'));
2761 $this->t->set_block('form','interviewer_list','int_list');
2762 $this->t->set_block('form','add','addhandle');
2763 $this->t->set_block('form','edit','edithandle');
2765 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2766 $this->t->set_var('readonly','');
2767 $this->t->set_var('disabled','');
2768 $this->t->set_var('eqpresppi','');
2770 $action = get_var('action',array('GET','POST'));
2771 $companionship = get_var('companionship',array('GET','POST'));
2772 $interviewer = get_var('interviewer',array('GET','POST'));
2773 $name = get_var('name',array('GET','POST'));
2774 $interview = get_var('interview',array('GET','POST'));
2775 $individual = get_var('individual',array('GET','POST'));
2776 $date = get_var('date',array('GET','POST'));
2777 $notes = get_var('notes',array('GET','POST'));
2778 $interview_type = get_var('interview_type',array('GET','POST'));
2780 $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)";
2781 $this->db2->query($sql,__LINE__,__FILE__);
2782 while ($this->db2->next_record()) {
2783 $indiv = $this->db2->f('individual');
2784 $interviewer_name = $this->db2->f('name');
2785 if($indiv == $interviewer) {
2786 $this->t->set_var('interviewer',$indiv . ' selected');
2788 $this->t->set_var('interviewer',$indiv);
2790 $this->t->set_var('interviewer_name',$interviewer_name);
2791 $this->t->fp('int_list','interviewer_list',True);
2794 if($action == 'save') {
2795 $notes = get_var('notes',array('POST'));
2796 $this->db->query("UPDATE tc_interview set " .
2797 " interview='" . $interview . "'" .
2798 ", interviewer='" . $interviewer . "'" .
2799 ", individual='" . $individual . "'" .
2800 ", date='" . $date . "'" .
2801 ", notes=\"" . $notes . "\"" .
2802 ", interview_type='" . $interview_type . "'" .
2803 " WHERE interview=" . $interview,__LINE__,__FILE__);
2808 if($action == 'insert') {
2809 $notes = get_var('notes',array('POST'));
2810 $this->db->query("INSERT INTO tc_interview (interviewer,individual,date,notes,interview_type) " .
2811 "VALUES ('" . $interviewer . "','" . $individual . "','" .
2812 $date . "',\"" . $notes ."\",'" . $interview_type . "')",__LINE__,__FILE__);
2817 if($action == 'add') {
2818 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2819 $this->t->set_var('interview', '');
2820 $this->t->set_var('interviewer', $interviewer);
2821 $this->t->set_var('name',$name);
2822 $this->t->set_var('individual',$individual);
2823 $this->t->set_var('date','');
2824 $this->t->set_var('notes','');
2825 $this->t->set_var('interview_type',$interview_type);
2826 $this->t->set_var('lang_done','Cancel');
2827 $this->t->set_var('lang_action','Adding New Interview');
2828 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
2829 $interview . '&action=' . 'insert'));
2832 if($action == 'edit' || $action == 'view') {
2833 $sql = "SELECT * FROM tc_interview WHERE interview=" . $interview . " AND interview_type='hti'";
2834 $this->db->query($sql,__LINE__,__FILE__);
2835 $this->db->next_record();
2836 $this->t->set_var('interview',$interview);
2837 $this->t->set_var('name',$name);
2838 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2839 $this->t->set_var('individual',$this->db->f('individual'));
2840 $this->t->set_var('date',$this->db->f('date'));
2841 $this->t->set_var('notes',$this->db->f('notes'));
2842 $this->t->set_var('interview_type',$this->db->f('interview_type'));
2843 if($this->db->f('interview_type') == 'ppi') { $this->t->set_var('eqpresppi_checked','checked'); }
2846 if($action == 'edit') {
2847 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2848 $this->t->set_var('lang_done','Cancel');
2849 $this->t->set_var('lang_action','Editing Interview');
2850 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
2851 $interview . '&action=' . 'save'));
2854 if($action == 'view') {
2855 $date = $this->db->f('date');
2856 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2857 $this->t->set_var('readonly','READONLY');
2858 $this->t->set_var('disabled','DISABLED');
2859 $this->t->set_var('lang_done','Done');
2860 $this->t->set_var('lang_action','Viewing Interview');
2861 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
2862 $interview . '&action=' . 'edit'));
2865 $this->t->set_var('lang_reset','Clear Form');
2866 $this->t->set_var('lang_add','Add Interview');
2867 $this->t->set_var('lang_save','Save Changes');
2868 $this->t->set_var('edithandle','');
2869 $this->t->set_var('addhandle','');
2871 $this->t->pfp('out','form');
2873 if($action == 'view') { $this->t->set_var('lang_save','Edit Interview'); }
2874 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2875 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2877 $this->save_sessiondata();
2882 $this->t->set_file(array('vis_view_t' => 'vis_view.tpl'));
2883 $this->t->set_block('vis_view_t','visit_list','list1');
2884 $this->t->set_block('vis_view_t','family_list','list2');
2886 $this->t->set_var('lang_name','Family Name');
2887 $this->t->set_var('lang_date','Date');
2889 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2890 $this->t->set_var('vis_link_title','View Yearly Visits');
2892 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
2893 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2895 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2896 $num_years = get_var('num_years',array('GET','POST'));
2897 if($num_years == '') { $num_years = $this->default_vis_num_years; }
2898 $this->t->set_var('num_years',$num_years);
2899 if($num_years == 1) {
2900 $this->t->set_var('lang_num_years','Year of History');
2902 $this->t->set_var('lang_num_years','Years of History');
2904 $this->t->set_var('lang_filter','Filter');
2906 $year = date('Y') - $num_years + 1;
2907 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2909 $sql = "SELECT * FROM tc_visit WHERE companionship=0 and date > '$year_start' ORDER BY date DESC";
2910 $this->db->query($sql,__LINE__,__FILE__);
2911 $total_records = $this->db->num_rows();
2914 while ($this->db->next_record()) {
2915 $visit_list[$i]['visit'] = $this->db->f('visit');
2916 $visit_list[$i]['family'] = $this->db->f('family');
2917 $visit_list[$i]['date'] = $this->db->f('date');
2921 for ($i=0; $i < count($visit_list); $i++) {
2922 $this->nextmatchs->template_alternate_row_color(&$this->t);
2924 $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'";
2925 $this->db->query($sql,__LINE__,__FILE__);
2926 $this->db->next_record();
2928 $this->t->set_var('family',$visit_list[$i]['family']);
2929 $this->t->set_var('family_name',$this->db->f('name'));
2930 $this->t->set_var('date',$visit_list[$i]['date']);
2932 $link_data['menuaction'] = 'tc.tc.vis_update';
2933 $link_data['visit'] = $visit_list[$i]['visit'];
2934 $link_data['name'] = $this->db->f('name');
2935 $link_data['date'] = $visit_list[$i]['date'];
2936 $link_data['action'] = 'view';
2937 $this->t->set_var('view',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
2938 $this->t->set_var('lang_view','View');
2940 $link_data['menuaction'] = 'tc.tc.vis_update';
2941 $link_data['visit'] = $visit_list[$i]['visit'];
2942 $link_data['name'] = $this->db->f('name');
2943 $link_data['date'] = $visit_list[$i]['date'];
2944 $link_data['action'] = 'edit';
2945 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
2946 $this->t->set_var('lang_edit','Edit');
2948 $this->t->fp('list1','visit_list',True);
2951 // List the families that are available to record a visit against
2952 $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'";
2953 $this->db->query($sql,__LINE__,__FILE__);
2954 $total_records = $this->db->num_rows();
2957 while ($this->db->next_record()) {
2958 $family_names[$i] = $this->db->f('name');
2959 $family_ids[$i] = $this->db->f('family');
2961 } array_multisort($family_names, $family_ids);
2963 for ($i=0; $i < count($family_names); $i++) {
2964 $link_data['menuaction'] = 'tc.tc.vis_update';
2965 $link_data['visit'] = '';
2966 $link_data['family'] = $family_ids[$i];
2967 $link_data['action'] = 'add';
2968 $link_data['name'] = $family_names[$i];
2969 $this->t->set_var('add',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
2971 $this->t->set_var('name',$family_names[$i]);
2972 if(($i+1) % 3 == 0) {
2973 $this->t->set_var('table_sep',"</td></tr><tr>");
2975 $this->t->set_var('table_sep',"</td>");
2977 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
2979 $this->t->fp('list2','family_list',True);
2982 $this->t->pfp('out','vis_view_t');
2983 $this->save_sessiondata();
2986 function vis_update()
2988 $this->t->set_file(array('form' => 'vis_update.tpl'));
2989 $this->t->set_block('form','add','addhandle');
2990 $this->t->set_block('form','edit','edithandle');
2992 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2993 $this->t->set_var('readonly','');
2994 $this->t->set_var('disabled','');
2996 $action = get_var('action',array('GET','POST'));
2997 $visit = get_var('visit',array('GET','POST'));
2998 $family = get_var('family',array('GET','POST'));
2999 $name = get_var('name',array('GET','POST'));
3000 $date = get_var('date',array('GET','POST'));
3001 $notes = get_var('notes',array('GET','POST'));
3004 if($action == 'save') {
3005 $notes = get_var('notes',array('POST'));
3006 $this->db->query("UPDATE tc_visit set " .
3007 " date='" . $date . "'" .
3008 ", notes=\"" . $notes . "\"" .
3009 " WHERE visit=" . $visit,__LINE__,__FILE__);
3014 if($action == 'insert') {
3015 $notes = get_var('notes',array('POST'));
3016 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes) " .
3017 "VALUES ('" . $family . "','" . $companionship . "','" .
3018 $date . "',\"" . $notes . "\")",__LINE__,__FILE__);
3023 if($action == 'add') {
3024 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
3025 $this->t->set_var('family', $family);
3026 $this->t->set_var('visit', '');
3027 $this->t->set_var('name', $name);
3028 $this->t->set_var('date','');
3029 $this->t->set_var('notes','');
3030 $this->t->set_var('lang_done','Cancel');
3031 $this->t->set_var('lang_action','Adding New Visit');
3032 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&family=' .
3033 $family . '&action=' . 'insert'));
3036 if($action == 'edit' || $action == 'view') {
3037 $sql = "SELECT * FROM tc_visit WHERE visit=".$visit;
3038 $this->db->query($sql,__LINE__,__FILE__);
3039 $this->db->next_record();
3040 $this->t->set_var('visit',$visit);
3041 $this->t->set_var('name',$name);
3042 $this->t->set_var('family', $family);
3043 $this->t->set_var('date',$this->db->f('date'));
3044 $this->t->set_var('notes',$this->db->f('notes'));
3047 if($action == 'edit') {
3048 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
3049 $this->t->set_var('lang_done','Cancel');
3050 $this->t->set_var('lang_action','Editing Visit');
3051 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit=' .
3052 $visit . '&action=' . 'save'));
3055 if($action == 'view') {
3056 $date = $this->db->f('date');
3057 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
3058 $this->t->set_var('readonly','READONLY');
3059 $this->t->set_var('disabled','DISABLED');
3060 $this->t->set_var('lang_done','Done');
3061 $this->t->set_var('lang_action','Viewing Visit');
3062 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit=' .
3063 $visit . '&action=' . 'edit'));
3066 $this->t->set_var('lang_reset','Clear Form');
3067 $this->t->set_var('lang_add','Add Visit');
3068 $this->t->set_var('lang_save','Save Changes');
3069 $this->t->set_var('edithandle','');
3070 $this->t->set_var('addhandle','');
3072 $this->t->pfp('out','form');
3074 if($action == 'view') { $this->t->set_var('lang_save','Edit Visit'); }
3075 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
3076 if($action == 'add') { $this->t->pfp('addhandle','add'); }
3078 $this->save_sessiondata();
3083 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3084 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3085 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3087 $this->t->set_file(array('att_view_t' => 'att_view.tpl'));
3088 $this->t->set_block('att_view_t','act_list','list');
3090 $this->t->set_block('att_view_t','month_list','list1');
3091 $this->t->set_block('att_view_t','header_list','list2');
3092 $this->t->set_block('att_view_t','individual_list','list3');
3094 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3095 $num_quarters = get_var('num_quarters',array('GET','POST'));
3096 if($num_quarters == '') { $num_quarters = $this->default_att_num_quarters; }
3097 $this->t->set_var('num_quarters',$num_quarters);
3098 $this->t->set_var('lang_filter','Filter');
3099 if($num_quarters == 1) {
3100 $this->t->set_var('lang_num_quarters','Quarter of History');
3102 $this->t->set_var('lang_num_quarters','Quarters of History');
3105 $num_months = $num_quarters * 3;
3106 $current_month = $this->current_month;
3107 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
3108 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
3109 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
3110 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
3112 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
3113 $this->db->query($sql,__LINE__,__FILE__);
3115 while ($this->db->next_record()) {
3116 $individual_name[$i] = $this->db->f('name');
3117 $individual[$i] = $this->db->f('individual');
3120 array_multisort($individual_name, $individual);
3122 // Create a list of sunday dates for a window of 3 months back and current month
3126 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, ($current_month-$num_months)+1, 1, date("y")));
3127 $last_date = explode("-",$sunday_list[0]['date']);
3128 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3129 $time_limit = mktime(0, 0, 0, $current_month, 31, date("y"));
3130 while($last_time < $time_limit) {
3131 $day = date("w",$last_time);
3132 if(date("w",$last_time) == 0) {
3133 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3134 $last_date = explode("-",$sunday_list[$i]['date']);
3135 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3136 $sunday_list[$i]['day'] = $last_date[2];
3137 $sunday_list[$i]['month'] = date("M",$last_time);
3138 $sunday_list[$i]['year'] = $last_date[0];
3140 $last_date = $sunday_list[$i]['date'];
3142 $last_time += 90000;
3143 if($found_sunday) { $i++; $found_sunday=0; }
3146 $total_individuals = count($individual);
3147 $old_month=$sunday_list[0]['month']; $span=0;
3148 for ($i=0; $i < count($sunday_list); $i++) {
3149 $date = $sunday_list[$i]['date'];
3150 $this->t->set_var('date',$sunday_list[$i]['date']);
3151 $this->t->set_var('day',$sunday_list[$i]['day']);
3152 if(($old_month != $sunday_list[$i]['month']) || $i == count($sunday_list)-1) {
3153 if($i == count($sunday_list)-1) { $span++; }
3154 $cur_month = $sunday_list[$i]['month'];
3155 $old_month = $sunday_list[$i]['month'];
3156 $link_data['menuaction'] = 'tc.tc.att_update';
3157 $link_data['month'] = $sunday_list[$i-1]['month'];
3158 $link_data['year'] = $sunday_list[$i-1]['year'];
3159 $link_data['action'] = 'update_month';
3160 $cur_month = $sunday_list[$i-1]['month'];
3161 $cur_year = $sunday_list[$i-1]['year'];
3162 $header_row .= "<th><font size=-3>$cur_month $cur_year</font></th>";
3163 $this->t->set_var('update_month',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3164 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3165 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3166 $this->t->set_var('span',$span); $span=0;
3167 $this->t->fp('list1','month_list',True);
3171 $this->t->set_var('total_individuals',$total_individuals);
3172 $this->t->set_var('header_row',$header_row);
3174 $individual_width=200; $att_width=25; $total_width=$individual_width;
3175 for ($i=0; $i < count($sunday_list); $i++) {
3176 $link_data['menuaction'] = 'tc.tc.att_update';
3177 $link_data['month'] = $sunday_list[$i]['month'];
3178 $link_data['year'] = $sunday_list[$i]['year'];
3179 $link_data['day'] = $sunday_list[$i]['day'];
3180 $link_data['date'] = $sunday_list[$i]['date'];
3181 $link_data['action'] = 'update_day';
3182 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3183 $this->t->set_var('date',$sunday_list[$i]['date']);
3184 $this->t->set_var('day',$sunday_list[$i]['day']);
3185 $this->t->set_var('month',$sunday_list[$i]['month']);
3186 $this->t->set_var('year',$sunday_list[$i]['year']);
3187 $this->t->fp('list2','header_list',True);
3188 $total_width += $att_width;
3189 $attendance[$monthnum[$sunday_list[$i]['month']]]=0;
3192 for ($i=0; $i < count($individual); $i++) {
3194 $this->nextmatchs->template_alternate_row_color(&$this->t);
3195 $this->t->set_var('individual_name',$individual_name[$i]);
3196 #print "checking for individual: " . $individual[$i] . "<br>";
3197 for ($j=0; $j < count($sunday_list); $j++) {
3198 #print "checking for date: " . $sunday_list[$j]['date'] . "<br>";
3199 #print "SELECT * FROM tc_attendance WHERE date='"
3200 # . $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i] . "<br>";
3201 $sql = "SELECT * FROM tc_attendance WHERE date='" .
3202 $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i];
3203 $this->db->query($sql,__LINE__,__FILE__);
3204 if($this->db->next_record()) {
3205 $cur_month = $sunday_list[$j]['month'];
3206 if($attended[$i][$cur_month] != 1) {
3207 $attended[$i][$cur_month]=1;
3208 $attendance[$monthnum[$cur_month]]++;
3210 $att_table .= '<td align=center><img src="images/checkmark.gif"></td>';
3212 $att_table .= '<td> </td>';
3215 $this->t->set_var('att_table',$att_table);
3216 $this->t->fp('list3','individual_list',True);
3218 $this->t->set_var('total_width',$total_width);
3219 $this->t->set_var('individual_width',$individual_width);
3220 $this->t->set_var('att_width',$att_width);
3222 # Now calculate attendance for these months
3223 $attendance_str = "";
3224 $nonattendance_str = "";
3225 $aveattendance_str = "";
3226 $avenonattendance_str = "";
3228 $ave_total_attended=0;
3230 foreach($attendance as $att => $value) {
3231 $total_attended = $attendance[$att];
3232 $ave_total_attended += $attendance[$att]; $num_months++;
3233 $percent = ceil(($total_attended / $total_individuals)*100);
3234 $attendance_str.="<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3235 $total_nonattended = $total_individuals - $total_attended;
3236 $percent = ceil(($total_nonattended / $total_individuals)*100);
3237 $nonattendance_str.="<td align=center><font size=-2><b>$total_nonattended ($percent%)</b></font></td>";
3239 $total_attended = ceil(($ave_total_attended / $num_months));
3240 $percent = ceil(($total_attended / $total_individuals)*100);
3241 $aveattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3242 $total_attended = $total_individuals - ceil(($ave_total_attended / $num_months));
3243 $percent = ceil(($total_attended / $total_individuals)*100);
3244 $avenonattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3247 $this->t->set_var('attendance',$attendance_str);
3248 $this->t->set_var('aveattendance',$aveattendance_str);
3249 $this->t->set_var('nonattendance',$nonattendance_str);
3250 $this->t->set_var('avenonattendance',$avenonattendance_str);
3252 $this->t->pfp('out','att_view_t');
3253 $this->save_sessiondata();
3256 function att_update()
3258 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3259 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3260 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3262 $this->t->set_file(array('form' => 'att_update.tpl'));
3263 $this->t->set_block('form','edit','edithandle');
3265 $this->t->set_block('form','month_list','list1');
3266 $this->t->set_block('form','header_list','list2');
3267 $this->t->set_block('form','individual_list','list3');
3269 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3271 $action = get_var('action',array('GET','POST'));
3272 $month = get_var('month',array('GET','POST'));
3273 $year = get_var('year',array('GET','POST'));
3274 $day = get_var('day',array('GET','POST'));
3275 $date = get_var('date',array('GET','POST'));
3277 if($action == 'save_month' || $action == 'save_day') {
3278 $new_data = get_var('individuals_attended',array('POST'));
3279 $month = $monthnum[$month]; if($month < 10) { $month = "0" . $month; }
3281 if($action == 'save_month') {
3282 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-%'",__LINE__,__FILE__);
3285 if($action == 'save_day') {
3286 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-".$day."'",__LINE__,__FILE__);
3289 foreach ($new_data as $data) {
3290 $data_array = explode("-",$data);
3291 $indiv = $data_array[0];
3292 $date = "$data_array[1]-$data_array[2]-$data_array[3]";
3293 $this->db->query("INSERT INTO tc_attendance (individual,date) " .
3294 "VALUES (" . $indiv . ",'". $date . "')",__LINE__,__FILE__);
3301 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
3302 $this->db->query($sql,__LINE__,__FILE__);
3304 while ($this->db->next_record()) {
3305 $indiv_name[$i] = $this->db->f('name');
3306 $individual[$i] = $this->db->f('individual');
3307 $indiv_attending[$individual[$i]] = $this->db->f('attending');
3310 array_multisort($indiv_name, $individual);
3312 if($action == 'update_month') {
3313 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_month'));
3317 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], 1, $year));
3318 $last_date = explode("-",$sunday_list[0]['date']);
3319 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3320 $time_limit = mktime(0, 0, 0, $monthnum[$month], 31, $year);
3321 while($last_time <= $time_limit) {
3322 $day = date("w",$last_time);
3323 if(date("w",$last_time) == 0) {
3324 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3325 $last_date = explode("-",$sunday_list[$i]['date']);
3326 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3327 $sunday_list[$i]['day'] = $last_date[2];
3328 $sunday_list[$i]['month'] = date("M",$last_time);
3329 $sunday_list[$i]['year'] = $last_date[0];
3332 $last_time += 90000;
3333 if($found_sunday) { $i++; $found_sunday=0; }
3336 $this->t->set_var('span', $i);
3337 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3338 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3339 $this->t->fp('list1','month_list',True);
3340 $indiv_width=200; $att_width=25; $total_width=$indiv_width;
3341 for ($i=0; $i < count($sunday_list); $i++) {
3342 $link_data['menuaction'] = 'tc.tc.att_update';
3343 $link_data['month'] = $sunday_list[$i]['month'];
3344 $link_data['year'] = $sunday_list[$i]['year'];
3345 $link_data['day'] = $sunday_list[$i]['day'];
3346 $link_data['date'] = $sunday_list[$i]['date'];
3347 $link_data['action'] = 'update_day';
3348 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3349 $this->t->set_var('date',$sunday_list[$i]['date']);
3350 $this->t->set_var('day',$sunday_list[$i]['day']);
3351 $this->t->set_var('month',$sunday_list[$i]['month']);
3352 $this->t->set_var('year',$sunday_list[$i]['year']);
3353 $this->t->fp('list2','header_list',True);
3354 $total_width += $att_width;
3358 if($action == 'update_day') {
3359 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_day'));
3360 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], $day, $year));
3361 $this->t->set_var('month',$month);
3362 $this->t->set_var('year',$year);
3363 $this->t->fp('list1','month_list',True);
3364 $this->t->set_var('date',$date);
3365 $this->t->set_var('day',$day);
3366 $this->t->set_var('month',$month);
3367 $this->t->set_var('year',$year);
3368 $this->t->fp('list2','header_list',True);
3371 for ($i=0; $i < count($individual); $i++) {
3373 $this->nextmatchs->template_alternate_row_color(&$this->t);
3374 $this->t->set_var('individual_name',$indiv_name[$i]);
3375 for ($j=0; $j < count($sunday_list); $j++) {
3376 $sql = "SELECT * FROM tc_attendance WHERE date='" .
3377 $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i];
3378 $this->db->query($sql,__LINE__,__FILE__);
3379 $value = $individual[$i] . "-" . $sunday_list[$j]['date'];
3380 if($this->db->next_record()) {
3381 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'" checked></td>';
3382 } else if($indiv_attending[$individual[$i]] == 1) {
3383 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'" checked></td>';
3385 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'"></td>';
3388 $this->t->set_var('att_table',$att_table);
3389 $this->t->fp('list3','individual_list',True);
3392 $this->t->set_var('lang_done', 'Cancel');
3393 $this->t->set_var('lang_reset','Clear Form');
3394 $this->t->set_var('lang_save','Save Changes');
3396 $this->t->pfp('out','form');
3397 $this->t->pfp('addhandle','edit');
3399 $this->save_sessiondata();
3404 $this->t->set_file(array('dir_view_t' => 'dir_view.tpl'));
3405 $this->t->set_block('dir_view_t','dir_list','list');
3407 $sql = "SELECT * FROM tc_individual where valid=1 and hh_position='Head of Household' ORDER BY name ASC";
3408 $this->db->query($sql,__LINE__,__FILE__);
3410 while ($this->db->next_record()) {
3411 $parent[$i]['id'] = $this->db->f('individual');
3412 $parent[$i]['name'] = $this->db->f('name');
3413 $parent[$i]['phone'] = $this->db->f('phone');
3414 $parent[$i]['address'] = $this->db->f('address');
3418 for ($i=0; $i < count($parent); $i++) {
3419 $name = $parent[$i]['name'];
3420 $phone = $parent[$i]['phone'];
3421 $address = $parent[$i]['address'];
3422 $this->t->set_var('name', $name);
3423 $this->t->set_var('address', $address);
3424 $this->t->set_var('phone', $phone);
3425 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3426 $this->t->set_var('tr_color',$tr_color);
3427 $this->t->fp('list','dir_list',True);
3428 //print "$phone $name $address<br>";
3430 $this->t->pfp('out','dir_view_t');
3431 $this->save_sessiondata();
3436 $this->t->set_file(array('org_view_t' => 'org_view.tpl'));
3437 $this->t->set_block('org_view_t','calling_list','list1');
3438 $this->t->set_block('org_view_t','org_list','list2');
3440 # Display a list ordered alphabetically
3441 $sql = "SELECT * FROM tc_calling AS tc JOIN tc_individual AS ti WHERE tc.individual=ti.individual ORDER BY name ASC";
3442 $this->db->query($sql,__LINE__,__FILE__);
3444 while ($this->db->next_record()) {
3445 $calling[$i]['name'] = $this->db->f('name');
3446 $calling[$i]['position'] = $this->db->f('position');
3447 $calling[$i]['sustained'] = $this->db->f('sustained');
3448 $calling[$i]['organization'] = $this->db->f('organization');
3451 for ($i=0; $i < count($calling); $i++) {
3452 $name = $calling[$i]['name'];
3453 $position = $calling[$i]['position'];
3454 $sustained = $calling[$i]['sustained'];
3455 $organization = $calling[$i]['organization'];
3456 $this->t->set_var('name', $name);
3457 $this->t->set_var('position', $position);
3458 $this->t->set_var('sustained', $sustained);
3459 $this->t->set_var('organization', $organization);
3460 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3461 $this->t->set_var('tr_color',$tr_color);
3462 $this->t->fp('list1','calling_list',True);
3465 # Display a list ordered by organization
3466 $sql = "SELECT * FROM tc_calling AS tc JOIN tc_individual AS ti where tc.individual=ti.individual ORDER BY organization ASC";
3467 $this->db->query($sql,__LINE__,__FILE__);
3469 while ($this->db->next_record()) {
3470 $calling[$i]['name'] = $this->db->f('name');
3471 $calling[$i]['position'] = $this->db->f('position');
3472 $calling[$i]['sustained'] = $this->db->f('sustained');
3473 $calling[$i]['organization'] = $this->db->f('organization');
3476 for ($i=0; $i < count($calling); $i++) {
3477 $name = $calling[$i]['name'];
3478 $position = $calling[$i]['position'];
3479 $sustained = $calling[$i]['sustained'];
3480 $organization = $calling[$i]['organization'];
3481 $this->t->set_var('name', $name);
3482 $this->t->set_var('position', $position);
3483 $this->t->set_var('sustained', $sustained);
3484 $this->t->set_var('organization', $organization);
3485 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3486 $this->t->set_var('tr_color',$tr_color);
3487 $this->t->fp('list2','org_list',True);
3490 $this->t->pfp('out','org_view_t');
3491 $this->save_sessiondata();
3496 $this->t->set_file(array('sched_t' => 'schedule.tpl'));
3497 $this->t->set_block('sched_t','presidency_list','list');
3499 $action = get_var('action',array('GET','POST'));
3501 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule&action=save'));
3502 $this->t->set_var('title','Scheduling Tool');
3504 $this->t->set_var('lang_save','Save Schedule');
3505 $this->t->set_var('lang_reset','Cancel');
3507 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
3508 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
3510 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
3511 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
3513 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
3514 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
3516 $date_width=160; $time_width=220; $indiv_width=170; $family_width=180; $location_width=100;
3517 $table_width=$date_width + $time_width + $indiv_width + $family_width + $location_width;
3518 $header_row = "<th width=$date_width><font size=-2>Date</th>";
3519 $header_row.= "<th width=$time_width><font size=-2>Time</th>";
3520 $header_row.= "<th width=$indiv_width><font size=-2>individual</th>";
3521 $header_row.= "<th width=$family_width><font size=-2>Family</th>";
3522 $header_row.= "<th width=$location_width><font size=-2>Location</th>";
3525 $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";
3526 $this->db->query($sql,__LINE__,__FILE__);
3528 while ($this->db->next_record()) {
3529 $presidency_data[$i]['id'] = $this->db->f('presidency');
3530 $presidency_data[$i]['name'] = $this->db->f('name');
3531 $presidency_data[$i]['indiv'] = $this->db->f('individual');
3532 $presidency2name[$presidency_data[$i]['id']] = $presidency_data[$i]['name'];
3533 $presidency2indiv[$presidency_data[$i]['id']] = $presidency_data[$i]['indiv'];
3537 $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";
3538 $this->db->query($sql,__LINE__,__FILE__);
3540 while ($this->db->next_record()) {
3541 $family_id[$i] = $this->db->f('family');
3542 $family_name[$i] = $this->db->f('name');
3543 $familyid2name[$family_id[$i]] = $family_name[$i];
3544 $familyid2address[$family_id[$i]] = $this->db->f('address');
3547 array_multisort($family_name, $family_id);
3549 if($action == 'save') {
3550 $new_data = get_var('sched',array('POST'));
3551 foreach ($new_data as $presidency_array) {
3552 foreach ($presidency_array as $entry) {
3553 $presidency = $entry['presidency'];
3554 $appointment = $entry['appointment'];
3555 $location = $entry['location'];
3556 $date = $entry['date'];
3557 $hour = $entry['hour'];
3558 $minute = $entry['minute'];
3560 $indiv = $entry['individual'];
3561 $family = $entry['family'];
3562 $location = $entry['location'];
3563 if($pm) { $hour = $hour + 12; }
3564 $time = $hour.':'.$minute.':'.'00';
3567 // Zero out family or individual if they are invalid
3568 if($indiv == "") { $indiv=0; }
3569 if($family == "") { $family=0; }
3571 // Update our location
3572 if($location == "") {
3574 $family_name_array = explode(",", $familyid2name[$family]);
3575 $family_last_name = $family_name_array[0];
3576 $family_address = $familyid2address[$family];
3577 $location = "$family_last_name"." home ($family_address)";
3578 } else if($indiv > 0) {
3579 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
3580 $supervisor_last_name = $supervisor_name_array[0];
3581 print "presidency2indiv: $presidency $presidency2indiv[$presidency]<br>";
3582 $sql = "SELECT * FROM tc_individual where individual='$presidency2indiv[$presidency]'";
3583 $this->db2->query($sql,__LINE__,__FILE__);
3584 if($this->db2->next_record()) {
3585 $supervisor_address = $this->db2->f('address');
3587 $location = "$supervisor_last_name"." home ($supervisor_address)";
3591 // Zero out the family or individual if date = NULL
3598 if(($indiv == 0) && ($family == 0)) { $location = ""; }
3600 // Update an existing appointment
3601 if($appointment < $this->max_appointments)
3603 //Only perform a database update if we have made a change to this appointment
3604 $sql = "SELECT * FROM tc_appointment where " .
3605 "appointment='$appointment'" .
3606 " and presidency='$presidency'" .
3607 " and individual='$indiv'" .
3608 " and family='$family'" .
3609 " and date='$date'" .
3610 " and time='$time'" .
3611 " and location='$location'";
3612 $this->db->query($sql,__LINE__,__FILE__);
3613 if(!$this->db->next_record()) {
3614 $old_date = $this->db->f('date');
3615 $old_time = $this->db->f('time');
3616 $this->db2->query("UPDATE tc_appointment set" .
3617 " family=" . $family .
3618 " ,individual=" . $indiv .
3619 " ,date='" . $date . "'" .
3620 " ,time='" . $time . "'" .
3621 " ,location='" . $location . "'" .
3622 " ,presidency='" . $presidency . "'" .
3623 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
3625 // Email the appointment
3626 $this->email_appt($appointment);
3630 // Add a new appointment
3631 else if(($appointment >= $this->max_appointments) && ($date != "") && ($time != ""))
3633 //print "adding entry: appt=$appointment date: $date time: $time individual: $indiv family: $family<br>";
3634 $this->db2->query("INSERT INTO tc_appointment (appointment,presidency,family,individual,date,time,location,uid) " .
3635 "VALUES (NULL,'" . $presidency . "','" . $family . "','" . $indiv . "','" .
3636 $date . "','" . $time . "','" . $location . "','" . $uid ."')",__LINE__,__FILE__);
3638 // Now reselect this entry from the database to see if we need
3639 // to send an appointment out for it.
3640 $sql = "SELECT * FROM tc_appointment where " .
3641 "individual='$indiv'" .
3642 " and family='$family'" .
3643 " and presidency='$presidency'" .
3644 " and date='$date'" .
3645 " and time='$time'" .
3647 " and location='$location'";
3648 $this->db3->query($sql,__LINE__,__FILE__);
3649 if($this->db3->next_record()) {
3650 // Email the appointment if warranted
3651 if(($date != "") && ($time != "") && (($indiv > 0) || $family > 0)) {
3652 $this->email_appt($this->db3->f('appointment'));
3659 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule');
3660 //Header('Location: ' . $take_me_to_url);
3663 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY individual ASC";
3664 $this->db->query($sql,__LINE__,__FILE__);
3666 while ($this->db->next_record()) {
3667 $individual[$i] = $this->db->f('individual');
3668 $indiv_name[$i] = $this->db->f('name');
3669 $indiv_phone[$individual[$i]] = $this->db->f('phone');
3672 array_multisort($indiv_name, $individual);
3674 for ($i=0; $i < count($presidency_data); $i++) {
3675 $presidency = $presidency_data[$i]['id'];
3676 $interviewer = $presidency_data[$i]['individual'];
3677 $name = $presidency_data[$i]['name'];
3678 $this->t->set_var('presidency_name',$name);
3681 // query the database for all the appointments
3682 $sql = "SELECT * FROM tc_appointment where presidency=$presidency and date>=CURDATE() ORDER BY date ASC, time ASC";
3683 $this->db->query($sql,__LINE__,__FILE__);
3685 // Prefill any existing appointment slots
3686 while ($this->db->next_record()) {
3687 $appointment = $this->db->f('appointment');
3688 $indiv = $this->db->f('individual');
3689 $family = $this->db->f('family');
3690 $location = $this->db->f('location');
3692 if($location == "") {
3694 $family_name_array = explode(",", $familyid2name[$family]);
3695 $family_last_name = $family_name_array[0];
3696 $family_address = $familyid2address[$family];
3697 $location = "$family_last_name"." home ($family_address)";
3698 } else if($indiv > 0) {
3699 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
3700 $supervisor_last_name = $supervisor_name_array[0];
3701 $sql = "SELECT * FROM tc_individual where individual='$presidency2indiv[$presidency]'";
3702 $this->db2->query($sql,__LINE__,__FILE__);
3703 if($this->db2->next_record()) {
3704 $supervisor_address = $this->db2->f('address');
3706 $location = "$supervisor_last_name"." home ($supervisor_address)";
3710 $date = $this->db->f('date');
3711 $date_array = explode("-",$date);
3712 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
3713 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
3715 $time = $this->db->f('time');
3716 $time_array = explode(":",$time);
3717 $hour = $time_array[0];
3718 $minute = $time_array[1];
3720 if($hour > 12) { $pm=1; $hour = $hour - 12; }
3721 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
3723 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3726 $table_data.= '<td align=left>';
3727 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]',$date,'','','','','',$this->cal_options);
3728 $table_data.= '</td>';
3730 // Hour & Minutes selection
3731 $table_data.= "<td align=center>";
3732 $table_data .= $this->get_time_selection_form($hour, $minute, $pm, $presidency, $appointment);
3733 $table_data.= "</td>";
3735 // individual drop down list (for PPIs)
3736 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][individual] STYLE="font-size : 8pt">';
3737 $table_data.= '<option value=0></option>';
3738 for ($j=0; $j < count($individual); $j++) {
3739 $id = $individual[$j];
3740 $name = $indiv_name[$j];
3741 if($individual[$j] == $indiv) {
3742 $selected[$id] = 'selected="selected"';
3744 $selected[$id] = '';
3746 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
3748 $table_data.='</select></td>';
3750 // Family drop down list (for Visits)
3751 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family] STYLE="font-size : 8pt">';
3752 $table_data.= '<option value=0></option>';
3753 for ($j=0; $j < count($individual); $j++) {
3754 $id = $family_id[$j];
3755 $name = $family_name[$j];
3756 if($family_id[$j] == $family) {
3757 $selected[$id] = 'selected="selected"';
3759 $selected[$id] = '';
3761 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
3763 $table_data.='</select></td>';
3765 // Location text box
3766 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
3767 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="'.$location.'" STYLE="font-size : 8pt">';
3769 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3770 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3772 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3773 $this->t->set_var('tr_color',$tr_color);
3776 // Create blank appointment slot
3777 for ($b=0; $b < 4; $b++) {
3778 $appointment = $this->max_appointments + $b;
3779 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3782 $table_data.= '<td align=left>';
3783 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]','','','','','','',$this->cal_options);
3784 $table_data.= '</td>';
3787 $table_data.= "<td align=center>";
3788 $table_data .= $this->get_time_selection_form(0, 0, 0, $presidency, $appointment);
3789 $table_data.= "</td>";
3791 // individual drop down list
3792 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][individual] STYLE="font-size : 8pt">';
3793 $table_data.= '<option value=0></option>';
3794 for ($j=0; $j < count($individual); $j++) {
3795 $id = $individual[$j];
3796 $name = $indiv_name[$j];
3797 $table_data.= '<option value='.$id.'>'.$name.'</option>';
3799 $table_data.='</select></td>';
3801 // Family drop down list
3802 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family] STYLE="font-size : 8pt">';
3803 $table_data.= '<option value=0></option>';
3804 for ($j=0; $j < count($individual); $j++) {
3805 $id = $family_id[$j];
3806 $name = $family_name[$j];
3807 $table_data.= '<option value='.$id.'>'.$name.' Family</option>';
3809 $table_data.='</select></td>';
3811 // Location text box
3812 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
3813 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="" STYLE="font-size : 8pt">';
3815 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3816 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3818 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3819 $this->t->set_var('tr_color',$tr_color);
3822 $this->t->set_var('table_data',$table_data);
3823 $this->t->set_var('header_row',$header_row);
3824 $this->t->set_var('table_width',$table_width);
3825 $this->t->fp('list','presidency_list',True);
3828 $this->t->pfp('out','sched_t');
3829 $this->save_sessiondata();
3834 $this->t->set_file(array('email_t' => 'email.tpl'));
3835 $this->t->set_block('email_t','individual_list','list');
3837 $action = get_var('action',array('GET','POST'));
3839 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email'));
3840 $this->t->set_var('title','Email Tool');
3842 $this->t->set_var('lang_email','Send Email');
3843 $this->t->set_var('lang_reset','Cancel');
3845 $this->t->set_var('email_member_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=member'));
3846 $this->t->set_var('email_member_link_title','Email Quorum Member');
3848 $this->t->set_var('email_quorum_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=quorum'));
3849 $this->t->set_var('email_quorum_link_title','Email Quorum');
3851 $this->t->set_var('email_reminder_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=reminder'));
3852 $this->t->set_var('email_reminder_link_title','Email Reminders');
3854 $this->t->set_var('email_edit_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=edit'));
3855 $this->t->set_var('email_edit_link_title','Edit Email Addresses');
3858 $this->t->set_var('table_width',$table_width);
3860 $this->t->pfp('out','email_t');
3861 $this->save_sessiondata();
3866 $this->t->set_file(array('admin_t' => 'admin.tpl'));
3867 $this->t->set_block('admin_t','upload','uploadhandle');
3868 $this->t->set_block('admin_t','admin','adminhandle');
3869 $this->t->set_block('admin_t','cmd','cmdhandle');
3870 $this->t->set_block('admin_t','presidency','presidencyhandle');
3872 $this->t->set_var('upload_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=upload'));
3873 $this->t->set_var('presidency_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=presidency'));
3875 $action = get_var('action',array('GET','POST'));
3877 $this->t->pfp('out','admin_t');
3879 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY individual ASC";
3880 $this->db->query($sql,__LINE__,__FILE__);
3882 while ($this->db->next_record()) {
3883 $individual[$i] = $this->db->f('individual');
3884 $indiv_name[$i] = $this->db->f('name');
3885 $indiv2name[$individual[$i]] = $indiv_name[$i];
3888 array_multisort($indiv_name, $individual);
3890 if($action == 'upload') {
3891 $target_path = $this->upload_target_path . '/' . basename( $_FILES['uploadedfile']['name']);
3893 if(($_FILES['uploadedfile']['type'] == "application/zip") ||
3894 ($_FILES['uploadedfile']['type'] == "application/x-zip-compressed") ||
3895 ($_FILES['uploadedfile']['type'] == "application/x-zip") ||
3896 ($_FILES['uploadedfile']['type'] == "application/octet-stream")) {
3898 if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
3899 $uploadstatus = "<b><font color=red> -E- Unable to move the uploaded file to ";
3900 $uploadstatus.= "the target path (check the path and permissions) of: $target_path</font></b>";
3901 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
3902 $uploadstatus.= "Tmp Filename : " . $_FILES['uploadedfile']['tmp_name'] . "<br>";
3903 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
3904 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
3905 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
3906 $uploadstatus.= "Error : " . $_FILES['uploadedfile']['error'] . "<br>";
3907 $this->t->set_var('uploadstatus',$uploadstatus);
3908 $this->t->pfp('uploadhandle','upload',True);
3912 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
3913 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
3914 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
3915 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
3916 $this->t->set_var('uploadstatus',$uploadstatus);
3917 $this->t->pfp('uploadhandle','upload');
3918 $this->t->set_var('uploadhandle','');
3919 print "<table border=1 width=80%><tr><td>\n<pre>";
3921 # make a directory for this data to be stored in
3922 $date="data_" . date("Y_m_d");
3923 $data_dir = $this->upload_target_path . '/' . $date;
3924 print "-> Making the data directory: $date<br>\n";
3925 exec('mkdir -p ' . $data_dir . ' 2>&1', $result, $return_code);
3926 if($return_code != 0) {
3927 print implode('\n',$result) . "<br>";
3928 print "<b><font color=red>";
3929 print "-E- Unable to create the data directory. Aborting import.";
3930 print "</font></b>";
3934 # move the file uploaded into this directory
3935 print "-> Moving the uploaded file into the data dir<br>\n";
3936 exec('mv ' . $target_path . ' ' . $data_dir . '/' . ' 2>&1', $result, $return_code);
3937 if($return_code != 0) {
3938 print implode('\n',$result) . "<br>";
3939 print "<b><font color=red>";
3940 print "-E- Unable to move the uploaded file into the data dir. Aborting import.";
3941 print "</font></b>";
3945 # unzip the data into this directory
3946 print "-> Unzipping the data<br>\n";
3947 exec($this->unzip_path .' -u '. $data_dir . '/*.zip -d ' . $data_dir . ' 2>&1', $result, $return_code);
3948 if($return_code != 0) {
3949 print implode('\n',$result) . "<br>";
3950 print "<b><font color=red>";
3951 print "-E- Unable to unzip the uploaded file into the data dir: $data_dir. Aborting import.";
3952 print "</font></b>";
3955 exec('mv ' . $data_dir . '/*/* '. $data_dir . ' 2>&1', $result, $return_code);
3957 # update the data_latest link to point to this new directory
3958 print "-> Updating the latest data dir link<br>\n";
3959 $data_latest = $this->upload_target_path . '/data_latest';
3960 exec('rm ' . $data_latest. '; ln -s ' . $data_dir .' '. $data_latest .' 2>&1', $result, $return_code);
3961 if($return_code != 0) {
3962 print implode('\n',$result) . "<br>";
3963 print "<b><font color=red>";
3964 print "-E- Unable to update the data latest link. Aborting import.";
3965 print "</font></b>";
3969 # run the import perl script to encorporate it into the DB
3970 ob_start('ob_logstdout', 2);
3971 print "-> Importing the data into the database<br>\n";
3972 ob_flush(); flush(); sleep(1);
3973 $import_log = $this->upload_target_path . '/import.log';
3974 $data_log = $this->upload_target_path . '/data.log';
3975 $import_cmd = $this->script_path . '/import_ward_data ' . $data_latest . ' 2>&1 | tee ' . $import_log;
3976 $parse_cmd = $this->script_path . '/parse_ward_data -v ' . $data_latest . ' > ' . $data_log . '2>&1';
3977 #print "import_cmd: $import_cmd<br>";
3978 #print "parse_cmd: $parse_cmd<br>";
3979 ob_start('ob_logstdout', 2);
3980 passthru($import_cmd);
3981 passthru($parse_cmd);
3982 ob_flush(); flush(); sleep(1);
3984 # fix the permissions of the data dir
3985 exec('chmod -R o-rwx ' . $data_dir, $result, $return_code);
3987 $this->t->pfp('cmdhandle','cmd');
3988 print "</pre></td></tr></table>";
3989 } else if(($_FILES['uploadedfile']['type'] != "application/zip") &&
3990 ($_FILES['uploadedfile']['type'] != "application/x-zip-compressed") &&
3991 ($_FILES['uploadedfile']['type'] != "application/x-zip") &&
3992 ($_FILES['uploadedfile']['type'] != "application/octet-stream")) {
3993 $uploadstatus = "<b><font color=red>The file format must be a .zip file, please try again! </font></b>";
3994 $uploadstatus.= "<br><br><b>Detected file format: " . $_FILES['uploadedfile']['type'] . "</b>";
3995 $this->t->set_var('uploadstatus',$uploadstatus);
3996 $this->t->pfp('uploadhandle','upload',True);
3998 $uploadstatus = "<b><font color=red> There was an error (" . $_FILES['uploadedfile']['error'];
3999 $uploadstatus.= ") uploading the file, please try again! </font></b>";
4000 $this->t->set_var('uploadstatus',$uploadstatus);
4001 $this->t->pfp('uploadhandle','upload',True);
4003 } else if($action == "presidency") {
4004 $new_data = get_var('eqpres',array('POST'));
4005 foreach ($new_data as $entry) {
4007 $email = $entry['email'];
4008 $indiv = $entry['indiv'];
4009 $name = $entry['name'];
4010 $district = $entry['district'];
4011 $president = $entry['president'];
4012 $counselor = $entry['counselor'];
4013 $secretary = $entry['secretary'];
4014 // look up the individual name for the ID
4015 $name = $indiv2name[$indiv];
4016 //print "id=$id indiv=$indiv name=$name email=$email district=$district president=$president ";
4017 //print "counselor=$counselor secretary=$secretary<br>";
4019 if(($indiv > 0) || ($name != "")) {
4020 if($id < $this->max_presidency_members) {
4021 //print "Updating Existing Entry<br>";
4022 $this->db2->query("UPDATE tc_presidency set" .
4023 " individual=" . $indiv .
4024 " ,district=" . $district .
4025 " ,email='" . $email . "'" .
4026 " ,president='" . $president . "'" .
4027 " ,counselor='" . $counselor . "'" .
4028 " ,secretary='" . $secretary . "'" .
4029 " WHERE presidency=" . $id,__LINE__,__FILE__);
4031 //print "Adding New Entry<br>";
4032 $this->db2->query("INSERT INTO tc_presidency (presidency,individual,district," .
4033 "email,president,counselor,secretary,valid) " .
4034 "VALUES (NULL,'" . $indiv . "','" . $district . "','" .
4035 $email . "','" . $president . "','" .
4036 $counselor . "','" . $secretary . "','1'" .
4037 ")",__LINE__,__FILE__);
4040 //print "Ignoring Blank Entry<br>";
4044 // Now update the tc_district table appropriately
4046 // Delete all the previous district entries from the table
4047 $this->db->query("DELETE from tc_district where valid=1",__LINE__,__FILE__);
4048 $this->db->query("DELETE from tc_district where valid=0",__LINE__,__FILE__);
4050 // Always add a "District 0" assigned to the High Priests Group
4052 $name = "High Priests";
4055 $this->db2->query("INSERT INTO tc_district (district,supervisor,valid) " .
4056 "VALUES ('" . $district . "','" .
4057 $indiv . "','" . $valid . "'" .
4058 ")",__LINE__,__FILE__);
4060 // Requery the tc_presidency table
4061 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1";
4062 $this->db->query($sql,__LINE__,__FILE__);
4063 while ($this->db->next_record()) {
4064 // Extract the data for each presidency record
4065 $id = $this->db->f('presidency');
4066 $indiv = $this->db->f('individual');
4067 $name = $this->db->f('name');
4068 $district = $this->db->f('district');
4071 // If we have a valid district, add it to the district table
4073 $this->db2->query("INSERT INTO tc_district (district,supervisor,valid) " .
4074 "VALUES ('" . $district . "','" .
4075 $indiv . "','" . $valid . "'" .
4076 ")",__LINE__,__FILE__);
4080 $this->t->set_var('adminhandle','');
4081 $this->t->pfp('adminhandle','admin');
4085 $this->t->set_var('adminhandle','');
4086 $this->t->pfp('adminhandle','admin');
4089 // Now save off the data needed for a Presidency Table Update
4091 $sql = "SELECT tp.*, ti.name FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1";
4092 $this->db->query($sql,__LINE__,__FILE__);
4094 $header_row = "<th>Individual</th><th>Email</th><th>District</th><th>President</th><th>Counselor</th><th>Secretary</th>";
4095 while ($this->db->next_record()) {
4096 // Extract the data for each presidency record
4097 $id = $this->db->f('presidency');
4098 $indiv = $this->db->f('individual');
4099 $district = $this->db->f('district');
4100 $name = $this->db->f('name');
4101 $email = $this->db->f('email');
4102 $president = $this->db->f('president');
4103 $counselor = $this->db->f('counselor');
4104 $secretary = $this->db->f('secretary');
4106 // Create the forms needed in the table
4107 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4110 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4113 if($eqpresidency == 0) {
4114 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4115 $table_data.= '<option value=0></option>';
4116 for ($j=0; $j < count($individual); $j++) {
4117 $tmp_id = $individual[$j];
4118 $name = $indiv_name[$j];
4119 if($individual[$j] == $indiv) {
4121 $selected = 'selected="selected"';
4125 $table_data.= '<option value='.$tmp_id.' '.$selected.'>'.$name.'</option>';
4127 $table_data.='</select></td>';
4128 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="'.$indivname.'">';
4130 $table_data.= '<td align=left><input type=text size="20" name="eqpresname" value="Presidency"></td>';
4131 $table_data.= '<input type=hidden name="eqpres['.$id.'][name]" value="Presidency">';
4135 $table_data .= '<td><input type="text" size="50" name="eqpres['.$id.'][email]" value="'.$email.'"></td>';
4138 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4139 $table_data.= '<option value=0></option>';
4140 for ($j=0; $j <= $this->max_num_districts; $j++) {
4141 if($district == $j) {
4142 $selected = 'selected="selected"';
4146 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4148 $table_data.='</select></td>';
4151 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4152 if($president == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4153 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4154 $table_data.='</select></td>';
4157 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4158 if($counselor == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4159 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4160 $table_data.='</select></td>';
4163 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4164 if($secretary == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4165 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4166 $table_data.='</select></td>';
4169 $table_data .= "</tr>\n";
4170 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4171 $this->t->set_var('tr_color',$tr_color);
4174 // Now create 1 blank row to always have a line available to add a new individual with
4175 $id = $this->max_presidency_members;
4176 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4178 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4180 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4181 $table_data.= '<option value=0></option>';
4182 for ($j=0; $j < count($individual); $j++) {
4183 $tmp_id = $individual[$j];
4184 $name = $indiv_name[$j];
4185 $table_data.= '<option value='.$tmp_id.'>'.$name.'</option>';
4187 $table_data.='</select></td>';
4188 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="">';
4190 $table_data.='<td><input type="text" size="50" name="eqpres['.$id.'][email]" value=""></td>';
4192 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4193 $table_data.= '<option value=0></option>';
4194 for ($j=0; $j <= $this->max_num_districts; $j++) {
4196 $selected = 'selected="selected"';
4200 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4202 $table_data.='</select></td>';
4204 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4205 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4206 $table_data.='</select></td>';
4208 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4209 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4210 $table_data.='</select></td>';
4212 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4213 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4214 $table_data.='</select></td>';
4216 $table_data .= "</tr>\n";
4217 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4218 $this->t->set_var('tr_color',$tr_color);
4220 $this->t->set_var('header_row',$header_row);
4221 $this->t->set_var('table_data',$table_data);
4222 $this->t->pfp('presidencyhandle','presidency',True);
4224 $this->save_sessiondata();
4227 function email_appt($appointment)
4229 //print "Emailing notification of appointment: $appointment <br>";
4231 $sql = "SELECT * FROM tc_appointment where appointment='$appointment'";
4232 $this->db->query($sql,__LINE__,__FILE__);
4234 while ($this->db->next_record()) {
4235 $appointment = $this->db->f('appointment');
4236 $presidency = $this->db->f('presidency');
4237 $location = $this->db->f('location');
4240 $indiv = $this->db->f('individual');
4242 $family = $this->db->f('family');
4246 $uid = $this->db->f('uid');
4248 // Extract the year, month, day, hours, minutes, seconds from the appointment time
4249 $appt_date = $this->db->f('date');
4250 $date_array = explode("-",$appt_date);
4251 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
4252 $appt_time = $this->db->f('time');
4253 $time_array = explode(":",$appt_time);
4254 $hour = $time_array[0]; $minute = $time_array[1]; $seconds = $time_array[2];
4256 // Format the appointment time into an iCal UTC equivalent
4257 $dtstamp = gmdate("Ymd"."\T"."His"."\Z");
4258 $dtstart = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds,$month,$day,$year));
4259 $dtstartstr = date("l, F d, o g:i A", mktime($hour,$minute,$seconds,$month,$day,$year));
4261 $sql = "SELECT tp.email AS email1, ti.email AS email2, ti.name AS name FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.presidency='$presidency'";
4262 $this->db2->query($sql,__LINE__,__FILE__);
4263 if($this->db2->next_record()) {
4264 if ($this->db2->f('email1') != "") {
4265 $email = $this->db2->f('email1');
4267 $email = $this->db2->f('email2');
4269 $interviewer = $this->db2->f('name');
4272 // Set the email address of the interviewer
4276 $sql = "SELECT * FROM tc_individual where individual='$indiv'";
4277 $this->db2->query($sql,__LINE__,__FILE__);
4278 if($this->db2->next_record()) {
4279 $indiv_name = $this->db2->f('name');
4280 $phone = $this->db2->f('phone');
4281 $appt_name = $indiv_name . " Interview";
4282 $duration = $this->default_ppi_appt_duration * 60;
4287 $sql = "SELECT * FROM tc_family WHERE family='$family'";
4288 $this->db2->query($sql,__LINE__,__FILE__);
4289 if($this->db2->next_record()) {
4290 $individual = $this->db2->f('individual');
4291 $sql = "SELECT * FROM tc_individual where individual='$individual'";
4292 $this->db3->query($sql,__LINE__,__FILE__);
4293 if($this->db3->next_record()) {
4294 $phone = $this->db3->f('phone');
4295 $family_name = $this->db3->f('name');
4296 $phone = $this->db3->f('phone');
4298 $appt_name = $family_name . " Family Visit";
4299 $duration = $this->default_visit_appt_duration * 60;
4303 $dtend = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4304 $dtendstr = date("g:i A", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4305 $date = $dtstartstr . "-" . $dtendstr;
4306 $description = "$appt_name : $phone";
4308 if(($uid == 0) && ($appt_name != "")) {
4309 // Create a new calendar item for this appointment, since this must be the first time we
4310 // are sending it out.
4311 print "Sent new appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4312 $uid = rand() . rand(); // Generate a random identifier for this appointment
4313 $subject = "Created: $appt_name";
4315 $this->db->query("UPDATE tc_appointment set" .
4317 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4319 $action = "PUBLISH";
4320 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4321 $dtend, $date, $location, $appt_name, $description, $uid);
4322 } else if(($uid != 0) && ($appt_name == "")) {
4323 // Remove the calendar item for this appointment since it has already been sent
4324 // and there is no name we have changed it to.
4325 print "Sent deleted appointment to " . $interviewer . " at " . $email . " for " . $appt_date . " " . $appt_time . "<br>";
4326 $subject = "Canceled: $appt_date $appt_time";
4328 $this->db->query("UPDATE tc_appointment set" .
4330 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4333 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4334 $dtend, $date, $location, $subject, $subject, $uid);
4335 } else if($uid != 0) {
4336 // Update the existing appointment since we have changed it
4337 print "Sent updated appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4339 $subject = "Canceled: $appt_date $appt_time";
4341 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4342 $dtend, $date, $location, $subject, $subject, $uid);
4344 $uid = rand() . rand(); // Generate a random identifier for this appointment
4345 $this->db->query("UPDATE tc_appointment set" .
4347 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4349 $subject = "Updated: $appt_name";
4350 $action = "PUBLISH";
4351 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4352 $dtend, $date, $location, $appt_name, $description, $uid);
4358 function send_ical_appt($action, $to, $from, $subject, $dtstamp, $dtstart, $dtend, $date, $location, $summary, $description, $uid)
4360 // Initialize our local variables
4361 $boundary = "=MIME_APPOINTMENT_BOUNDARY";
4365 // Form the headers for the email message
4366 $headers.="X-Mailer: PHP/" . phpversion() . "\n";
4367 $headers.="Mime-Version: 1.0\n";
4368 $headers.="Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
4369 $headers.="Content-Disposition: inline\n";
4370 $headers.="Reply-To: $from\n";
4371 $headers.="From: $from\n";
4373 // Print the plaintext version of the appointment
4374 $message.="--$boundary\n";
4375 $message.="Content-Type: text/plain; charset=us-ascii\n";
4376 $message.="Content-Disposition: inline\n";
4378 $message.="What: $description\n";
4379 $message.="When: $date\n";
4380 $message.="Where: $location\n";
4383 // Print the .ics attachment version of the appointment
4384 $message.="--$boundary\n";
4385 $message.="Content-Type: text/calendar; charset=us-ascii\n";
4386 $message.="Content-Disposition: attachment; filename=\"appointment.ics\"\n";
4388 $message.="BEGIN:VCALENDAR" . "\n";
4389 $message.="VERSION:2.0" . "\n";
4390 $message.="PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN" . "\n";
4391 $message.="METHOD:$action" . "\n";
4392 $message.="BEGIN:VEVENT" . "\n";
4393 $message.="ORGANIZER:MAILTO:$from". "\n";
4394 $message.="DTSTAMP:$dtstamp" . "\n";
4395 $message.="DTSTART:$dtstart" . "\n";
4396 $message.="DTEND:$dtend" . "\n";
4397 $message.="SUMMARY:$summary" . "\n";
4398 $message.="DESCRIPTION:$description" . "\n";
4399 $message.="LOCATION:$location" . "\n";
4400 $message.="UID:$uid" ."\n";
4401 $message.="TRANSP:OPAQUE" . "\n";
4402 $message.="SEQUENCE:0" . "\n";
4403 $message.="CLASS:PUBLIC" . "\n";
4404 $message.="END:VEVENT" . "\n";
4405 $message.="END:VCALENDAR" . "\n";
4407 // Complete the message
4408 $message.="--$boundary\n";
4411 mail($to, $subject, $message, $headers);
4414 function get_time_selection_form($hour, $minute, $pm, $presidency, $appointment)
4419 if($hour == 0) { $blank = 1; }
4421 if($this->time_drop_down_lists == 1) {
4422 // Create drop down lists to get the time
4423 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][hour]>';
4424 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4425 foreach(range(1,12) as $num) {
4427 $selected = 'selected="selected"';
4431 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4433 $form_data.= '</select>';
4434 $form_data.= ' : ';
4435 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][minute]>';
4436 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4439 if($num < 10) { $num = "0" . "$num"; }
4440 if($minute == $num) {
4441 $selected = 'selected="selected"';
4445 if($blank == 1) { $selected = ""; }
4446 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4447 $num = $num + $this->time_drop_down_list_inc;
4449 $form_data.= '</select>';
4451 // Use free form text fields to get the time
4457 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][hour] value='.$hour.'>';
4459 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][minute] value='.$minute.'>';
4460 $form_data.= ' ';
4462 // Always use a drop-down select form for am/pm
4463 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][pm]>';
4466 $form_data.= '<option value=0 selected>am</option>';
4467 $form_data.= '<option value=1>pm</option>';
4470 $form_data.= '<option value=0>am</option>';
4471 $form_data.= '<option value=1 selected>pm</option>';
4474 $form_data.= '<option value=""></option>';
4475 $form_data.= '<option value=0>am</option>';
4476 $form_data.= '<option value=1>pm</option>';
4478 $form_data.= '</select>';