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 save_sessiondata()
117 function display_app_header()
119 $this->t->set_file(array('tc_header' => 'header.tpl'));
121 if (isset($phpgw_info['user']['preferences']['tc']['tc_font']))
123 $font = $phpgw_info['user']['preferences']['tc']['tc_font'];
130 $this->t->set_var('bg_color',$phpgw_info['theme']['th_bg']);
131 $this->t->set_var('font',$font);
132 $link_data['menuaction'] = 'tc.tc.ht_view';
133 $this->t->set_var('link_hometeaching',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
134 $this->t->set_var('lang_hometeaching','HomeTeaching');
135 $link_data['menuaction'] = 'tc.tc.act_list';
136 $this->t->set_var('link_activity',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
137 $this->t->set_var('lang_activity','Activities');
138 $link_data['menuaction'] = 'tc.tc.willing_view';
139 $this->t->set_var('link_willing',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
140 $this->t->set_var('lang_willing','Willingness');
141 $link_data['menuaction'] = 'tc.tc.assign_view';
142 $this->t->set_var('link_assignment',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
143 $this->t->set_var('lang_assignment','Assignments');
144 $link_data['menuaction'] = 'tc.tc.par_view';
145 $this->t->set_var('link_participation',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
146 $this->t->set_var('lang_participation','Participation');
147 $link_data['menuaction'] = 'tc.tc.ppi_view';
148 $this->t->set_var('link_ppi',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
149 $this->t->set_var('lang_ppi','PPIs');
150 $link_data['menuaction'] = 'tc.tc.int_view';
151 $this->t->set_var('link_int',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
152 $this->t->set_var('lang_int','Interviews');
153 $link_data['menuaction'] = 'tc.tc.vis_view';
154 $this->t->set_var('link_visit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
155 $this->t->set_var('lang_visit','Visits');
156 $link_data['menuaction'] = 'tc.tc.att_view';
157 $this->t->set_var('link_attendance',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
158 $this->t->set_var('lang_attendance','Attendance');
159 $link_data['menuaction'] = 'tc.tc.dir_view';
160 $this->t->set_var('link_dir',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
161 $this->t->set_var('lang_dir','Directory');
162 $link_data['menuaction'] = 'tc.tc.org_view';
163 $this->t->set_var('link_org',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
164 $this->t->set_var('lang_org','Callings');
165 $link_data['menuaction'] = 'tc.tc.admin';
166 $this->t->set_var('link_admin',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
167 $this->t->set_var('lang_admin','Admin');
168 $link_data['menuaction'] = 'tc.tc.schedule';
169 $this->t->set_var('link_schedule',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
170 $this->t->set_var('lang_schedule','Scheduling');
171 $link_data['menuaction'] = 'tc.tc.email';
172 $this->t->set_var('link_email',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
173 $this->t->set_var('lang_email','Email');
175 $this->t->pparse('out','tc_header');
180 $this->t->set_file(array('ht_view_t' => 'ht_view.tpl'));
181 $this->t->set_block('ht_view_t','district_list','list');
183 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
184 $num_months = get_var('num_months',array('GET','POST'));
185 if($num_months == '') { $num_months = $this->default_ht_num_months; }
186 $this->t->set_var('num_months',$num_months);
187 $this->t->set_var('lang_filter','Filter');
188 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
189 else { $this->t->set_var('lang_num_months','Months of History'); }
191 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
192 $this->t->set_var('title','Hometeaching');
194 $sql = "SELECT * FROM tc_district where valid=1 ORDER BY district ASC";
195 $this->db->query($sql,__LINE__,__FILE__);
197 while ($this->db->next_record()) {
198 $districts[$i]['district'] = $this->db->f('district');
199 $districts[$i]['name'] = $this->db->f('name');
200 $districts[$i]['supervisor'] = $this->db->f('supervisor');
204 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
205 $this->db->query($sql,__LINE__,__FILE__);
207 while ($this->db->next_record()) {
208 $individual[$i] = $this->db->f('individual');
209 $indiv_name[$i] = $this->db->f('name');
210 $indiv_phone[$individual[$i]] = $this->db->f('phone');
213 array_multisort($indiv_name, $individual);
215 // Make an array mapping individuals to indiv_names
216 for($i=0; $i < count($individual); $i++) {
217 $id = $individual[$i];
218 $indivs[$id] = $indiv_name[$i];
221 $this->nextmatchs->template_alternate_row_color(&$this->t);
222 for($m=$num_months; $m >= 0; $m--) { $total_families[$m]=0; }
223 for ($i=0; $i < count($districts); $i++) {
224 $this->t->set_var('district_number',$districts[$i]['district']);
225 $this->t->set_var('district_name',$districts[$i]['name']);
226 $supervisor = $districts[$i]['supervisor'];
228 // Select all the unique companionship numbers for this district
229 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$i]['district'];
230 $this->db->query($sql,__LINE__,__FILE__);
231 $j=0; $unique_companionships = '';
232 while ($this->db->next_record()) {
233 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
237 $comp_width=450; $visit_width=25; $table_width=$comp_width + $num_months*$visit_width;
238 $table_data=""; $num_companionships = 0;
239 for($m=$num_months; $m >= 0; $m--) {
243 for ($j=0; $j < count($unique_companionships); $j++) {
244 $companion_table_entry = "";
245 // Select all the companions in each companionship
246 $sql = "SELECT * FROM tc_companionship where valid=1 and ".
247 "companionship=". $unique_companionships[$j]['companionship'];
248 $this->db->query($sql,__LINE__,__FILE__);
250 while ($this->db->next_record()) {
251 // Get this companions information
252 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
253 $companionship = $this->db->f('companionship');
254 $individual = $this->db->f('individual');
255 $name = $indivs[$individual];
256 $phone = $indiv_phone[$individual];
257 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
259 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
261 // Get the names of the families assigned this home teaching companionship
262 $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'];
263 $sql = $sql . " ORDER BY name ASC";
264 $this->db->query($sql,__LINE__,__FILE__);
266 while ($this->db->next_record()) {
267 $family_name = $this->db->f('name');
268 $family_id = $this->db->f('family');
269 $this->nextmatchs->template_alternate_row_color(&$this->t);
270 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
271 // Find out how many times Visits were performed by this companionship
272 // in the past $num_months for this Family
273 $header_row="<th width=$comp_width><font size=-2>Families</th>";
274 for($m=$num_months; $m >= 0; $m--) {
275 $month = $this->current_month - $m;
276 $year = $this->current_year;
277 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
278 if($month < 10) { $month = "0"."$month"; }
279 $month_start = "$year"."-"."$month"."-"."01";
280 $month_end = "$year"."-"."$month"."-"."31";
281 $month = "$month"."/"."$year";
283 //print "m: $m month: $month year: $year month_start: $month_start month_end: $month_end<br>";
284 // Add this to the query to filter on only visits made by this companionship:
285 // " AND companionship=" . $unique_companionships[$j]['companionship'].
287 // First check to see if the currently assigned companionship has visited them
288 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
289 " AND companionship=".$unique_companionships[$j]['companionship'].
290 " AND family=". $family_id;
291 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
292 if($this->db2->num_rows($query_id) == 0) {
293 // We did not find any visits made by the currently assigned companionship,
294 // look for visits made by any other companionship other than 0. (0 == Presidency Visit)
295 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
296 " AND companionship!=0".
297 " AND family=". $family_id;
298 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
300 $this->db2->query($sql,__LINE__,__FILE__);
301 $link_data['menuaction'] = 'tc.tc.ht_update';
302 $link_data['date'] = $month_start;
303 $link_data['month_start'] = $month_start;
304 $link_data['month_end'] = $month_end;
305 $link_data['month'] = $month;
306 $link_data['district'] = $districts[$i]['district'];
307 $link_data['district_name'] = $districts[$i]['name'];
308 $link_data['action'] = 'view';
309 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
310 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
311 if(!$total_visits[$m]) { $total_visits[$m] = 0; }
312 if($this->db2->next_record()) {
313 if($this->db2->f('visited') == 'y') {
314 $visits[$m]++; $total_visits[$m]++;
315 $num_families[$m]++; $total_families[$m]++;
316 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/checkmark.gif"></a></td>';
317 } else if($this->db2->f('visited') == 'n') {
318 $num_families[$m]++; $total_families[$m]++;
319 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/x.gif"></a></td>';
321 //$visits[$m]++; $total_visits[$m]++;
322 $table_data .= "<td> </td>";
325 //$visits[$m]++; $total_visits[$m]++;
326 $table_data .= "<td> </td>";
329 $table_data .= "</tr>";
332 $table_data .= "<tr><td colspan=20></td></tr>";
334 $table_data .= "<tr><td colspan=20><hr></td></tr>";
335 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
337 for($m=$num_months; $m >=0; $m--) {
338 if($num_families[$m] > 0) {
339 $percent = ceil(($visits[$m] / $num_families[$m])*100);
343 $stat_data .= "<td align=center><font size=-2><b>$visits[$m] / $num_families[$m]<br>$percent%</font></b></td>";
345 $stat_data .= "</tr>";
347 $this->t->set_var('table_width',$table_width);
348 $this->t->set_var('header_row',$header_row);
349 $this->t->set_var('table_data',$table_data);
350 $this->t->set_var('stat_data',$stat_data);
351 $this->t->fp('list','district_list',True);
354 $totals = "<tr><td><b><font size=-2>Total Families Hometaught:<br>Total Hometeaching Percentage:</font></b></td>";
355 for($m=$num_months; $m >=0; $m--) {
356 if($total_families[$m] > 0) {
357 $percent = ceil(($total_visits[$m] / $total_families[$m])*100);
361 $totals .= "<td align=center><font size=-2><b>$total_visits[$m] / $total_families[$m]<br>$percent%</font></b></td>";
365 $this->t->set_var('totals',$totals);
367 $this->t->pfp('out','ht_view_t');
368 $this->save_sessiondata();
374 $this->t->set_file(array('ht_update_t' => 'ht_update.tpl'));
375 $this->t->set_block('ht_update_t','district_list','list');
376 $this->t->set_block('ht_update_t','save','savehandle');
378 $district = get_var('district',array('GET','POST'));
379 $district_name = get_var('district_name',array('GET','POST'));
380 $date = get_var('date',array('GET','POST'));
381 $month = get_var('month',array('GET','POST'));
382 $month_start = get_var('month_start',array('GET','POST'));
383 $month_end = get_var('month_end',array('GET','POST'));
384 $action = get_var('action',array('GET','POST'));
386 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
387 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_update&action=save'));
388 $this->t->set_var('lang_done','Cancel');
389 $this->t->set_var('district_name',$district_name);
390 $this->t->set_var('district_number',$district);
391 $this->t->set_var('title','Hometeaching Update ' . $month);
392 $this->t->set_var('date',$date);
394 if($action == 'save') {
395 // Get a list of all the companionships in this district
396 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $district;
397 $this->db->query($sql,__LINE__,__FILE__);
398 $j=0; $unique_companionships = '';
399 while ($this->db->next_record()) {
400 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
403 for ($j=0; $j < count($unique_companionships); $j++) {
404 //$comp=$unique_companionships[$j]['companionship'];
405 //print "deleting from tc_visit where companionship=$comp and date=$date and district=$district<br>";
406 // Delete all the visits that have taken place for all families for this companionsthip for this month
407 $this->db->query("DELETE from tc_visit where companionship=" . $unique_companionships[$j]['companionship'] .
408 " AND " . "date='" . $date . "'",__LINE__,__FILE__);
411 // Now, add the visits that are checked for this month
412 $new_data = get_var('family_visited',array('POST'));
413 foreach ($new_data as $family) {
414 foreach ($family as $data) {
415 //print "family_visited: $data <br>";
416 $data_array = explode("/",$data);
417 $family_id = $data_array[0];
418 $companionship = $data_array[1];
419 $date = $data_array[2];
420 $visited = $data_array[3];
421 if($visited == "") { $visited = $data_array[4]; }
422 //print "family_id: $family_id companionship: $companionship date: $date visited: $visited<br>";
423 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes,visited) " .
424 "VALUES (" . $family_id .",". $companionship .",'". $date ."','','". $visited ."')",__LINE__,__FILE__);
431 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
432 $this->db->query($sql,__LINE__,__FILE__);
434 while ($this->db->next_record()) {
435 $individual[$i] = $this->db->f('individual');
436 $indiv_name[$i] = $this->db->f('name');
437 $indiv_phone[$individual[$i]] = $this->db->f('phone');
440 array_multisort($indiv_name, $individual);
442 // Make an array mapping individuals to indiv_names
443 for($i=0; $i < count($individual); $i++) {
444 $id = $individual[$i];
445 $indivs[$id] = $indiv_name[$i];
448 // Select all the unique companionship numbers for this district
449 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $district;
450 $this->db->query($sql,__LINE__,__FILE__);
451 $j=0; $unique_companionships = '';
452 while ($this->db->next_record()) {
453 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
457 $comp_width=300; $visit_width=25; $table_width=$comp_width + $visit_width;
458 $table_data=""; $num_companionships = 0; $num_families = 0; $visits=0;
459 for ($j=0; $j < count($unique_companionships); $j++) {
460 $companion_table_entry = "";
461 // Select all the companions in each companionship
462 $sql = "SELECT * FROM tc_companionship where valid=1 and ".
463 "companionship=". $unique_companionships[$j]['companionship'];
464 $this->db->query($sql,__LINE__,__FILE__);
466 while ($this->db->next_record()) {
467 // Get this companions information
468 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
469 $companionship = $this->db->f('companionship');
470 $individual = $this->db->f('individual');
471 $name = $indivs[$individual];
472 $phone = $indiv_phone[$individual];
473 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
475 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
477 // Get the names of the families assigned this home teaching companionship
478 $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'];
479 $sql = $sql . " ORDER BY ti.name ASC";
480 $this->db->query($sql,__LINE__,__FILE__);
481 while ($this->db->next_record()) {
482 $family_name = $this->db->f('name');
483 $family_id = $this->db->f('family');
484 $this->nextmatchs->template_alternate_row_color(&$this->t);
485 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
487 $header_row="<th width=$comp_width><font size=-2>Families</th>";
489 // First check to see if the currently assigned companionship has visited them
490 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
491 " AND companionship=".$unique_companionships[$j]['companionship'].
492 " AND family=". $family_id;
493 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
494 if($this->db2->num_rows($query_id) == 0) {
495 // We did not find any visits made by the currently assigned companionship,
496 // look for visits made by any other companionship other than 0. (0 == Presidency Visit)
497 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
498 " AND companionship!=0".
499 " AND family=". $family_id;
500 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
503 $value = $family_id . "/" . $unique_companionships[$j]['companionship'] . "/" . $date;
504 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
505 if(!$total_visits) { $total_visits = 0; }
506 if($this->db2->next_record()) {
507 if($this->db2->f('visited') == 'y') {
508 $visits++; $total_visits++; $num_families++;
509 $table_data .= '<td width=100 align=center>';
510 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y" checked>Y';
511 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
512 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/"> ';
513 $table_data .= '</td>';
514 } else if($this->db2->f('visited') == 'n') {
516 $table_data .= '<td width=100 align=center>';
517 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
518 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n" checked>N';
519 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/">';
520 $table_data .= '</td>';
522 $table_data .= '<td width=100 align=center>';
523 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
524 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
525 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
526 $table_data .= '</td>';
531 $table_data .= '<td width=100 align=center>';
532 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
533 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
534 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
535 $table_data .= '</td>';
538 $table_data .= "</tr>";
539 $table_data .= "<tr><td colspan=20></td></tr>";
541 $table_data .= "<tr><td colspan=20><hr></td></tr>";
542 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
544 $percent = ceil(($visits / $num_families)*100);
545 $stat_data .= "<td align=center><font size=-2><b>$visits / $num_families<br>$percent%</font></b></td>";
546 $stat_data .= "</tr>";
548 $this->t->set_var('table_width',$table_width);
549 $this->t->set_var('header_row',$header_row);
550 $this->t->set_var('table_data',$table_data);
551 $this->t->set_var('stat_data',$stat_data);
552 $this->t->fp('list','district_list',True);
554 $this->t->set_var('lang_reset','Clear Form');
555 $this->t->set_var('lang_save','Save Changes');
556 $this->t->set_var('savehandle','');
558 $this->t->pfp('out','ht_update_t');
559 $this->t->pfp('addhandle','save');
561 $this->save_sessiondata();
566 $this->t->set_file(array('act_list_t' => 'act_list.tpl'));
567 $this->t->set_block('act_list_t','act_list','list');
569 $this->t->set_var('lang_name','Assignment');
570 $this->t->set_var('lang_date','Date');
571 $this->t->set_var('lang_notes','Description');
573 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
574 $this->db->query($sql,__LINE__,__FILE__);
575 $total_records = $this->db->num_rows();
578 while ($this->db->next_record()) {
579 $activity_list[$i]['activity'] = $this->db->f('activity');
580 $activity_list[$i]['assignment'] = $this->db->f('assignment');
581 $activity_list[$i]['date'] = $this->db->f('date');
582 $activity_list[$i]['notes'] = $this->db->f('notes');
584 $sql = "SELECT * FROM tc_assignment WHERE assignment='" . $activity_list[$i]['assignment'] . "'";
585 $this->db2->query($sql,__LINE__,__FILE__);
586 if($this->db2->next_record()) {
587 $activity_list[$i]['name'] = $this->db2->f('name');
588 $activity_list[$i]['abbreviation'] = $this->db2->f('abbreviation');
593 for ($i=0; $i < count($activity_list); $i++) {
594 $this->nextmatchs->template_alternate_row_color(&$this->t);
595 $this->t->set_var('name',$activity_list[$i]['name']);
596 $this->t->set_var('date',$activity_list[$i]['date']);
597 $activity_notes = $activity_list[$i]['notes'];
598 if(strlen($activity_notes) > 40) { $activity_notes = substr($activity_notes,0,40) . "..."; }
599 $this->t->set_var('notes',$activity_notes);
601 $link_data['menuaction'] = 'tc.tc.act_view';
602 $link_data['activity'] = $activity_list[$i]['activity'];
603 $link_data['action'] = 'view';
604 $this->t->set_var('view',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
605 $this->t->set_var('lang_view','View');
607 $link_data['menuaction'] = 'tc.tc.act_update';
608 $link_data['activity'] = $activity_list[$i]['activity'];
609 $link_data['action'] = 'edit';
610 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
611 $this->t->set_var('lang_edit','Edit');
613 $this->t->fp('list','act_list',True);
616 $link_data['menuaction'] = 'tc.tc.act_update';
617 $link_data['activity'] = '0';
618 $link_data['action'] = 'add';
619 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/tc/index.php',$link_data) .
620 '"><input type="submit" name="Add" value="' . 'Add Activity' .'"></font></form>');
622 $this->t->pfp('out','act_list_t');
623 $this->save_sessiondata();
628 $this->t->set_file(array('act_view_t' => 'act_view.tpl'));
629 $this->t->set_block('act_view_t','part_list','list');
631 $sql = "SELECT * FROM tc_activity WHERE activity=" . intval(get_var('activity',array('GET','POST')));
632 $this->db->query($sql,__LINE__,__FILE__);
633 $this->db->next_record();
634 $this->t->set_var('assignment', $this->db->f('assignment'));
635 $this->t->set_var('date', $this->db->f('date'));
636 $this->t->set_var('notes', $this->db->f('notes'));
638 $sql = "SELECT * FROM tc_assignment WHERE assignment='" . $this->db->f('assignment') . "'";
639 $this->db2->query($sql,__LINE__,__FILE__);
640 if($this->db2->next_record()) {
641 $this->t->set_var('name', $this->db2->f('name'));
642 $this->t->set_var('abbreviation', $this->db2->f('abbreviation'));
644 $this->t->set_var('lang_name','Assignment');
645 $this->t->set_var('lang_date','Date');
646 $this->t->set_var('lang_notes','Description');
647 $this->t->set_var('lang_done','Done');
648 $this->t->set_var('lang_action','View');
650 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
651 $this->t->set_var('tr_color',$tr_color);
653 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_list'));
655 $link_data['menuaction'] = 'tc.tc.act_update';
656 $link_data['activity'] = get_var('activity',array('GET','POST'));
657 $link_data['action'] = 'edit';
658 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
659 $this->t->set_var('lang_edit','Edit');
660 $this->t->set_var('cal_date',$this->db->f('date'));
662 // Now find out which indivs participated in this activity
663 $sql = "SELECT * FROM tc_participation WHERE activity=" . intval(get_var('activity',array('GET','POST')));
664 $this->db->query($sql,__LINE__,__FILE__);
665 $total_records = $this->db->num_rows();
668 while ($this->db->next_record()) {
669 $part_list[$i]['individual'] = $this->db->f('individual');
673 for ($i=0; $i < count($part_list); $i++) {
674 $sql = "SELECT * FROM tc_individual WHERE individual=" . $part_list[$i]['individual'];
675 $this->db->query($sql,__LINE__,__FILE__);
676 $this->db->next_record();
677 $names[$i] = $this->db->f('name');
681 for ($i=0; $i < count($names); $i++) {
682 //$this->nextmatchs->template_alternate_row_color(&$this->t);
683 $this->t->set_var('indiv_name',$names[$i]);
684 if(($i+1) % 3 == 0) {
685 $this->t->set_var('table_sep',"</td></tr><tr>");
687 $this->t->set_var('table_sep',"</td>");
689 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
690 $this->t->fp('list','part_list',True);
693 $this->t->pfp('out','act_view_t');
694 $this->save_sessiondata();
697 function act_update()
699 $this->t->set_file(array('form' => 'act_update.tpl'));
700 $this->t->set_block('form','individual_list','list');
701 $this->t->set_block('form','add','addhandle');
702 $this->t->set_block('form','edit','edithandle');
703 $this->t->set_var('lang_done','Done');
705 $action = get_var('action',array('GET','POST'));
706 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_list'));
707 $activity['activity'] = intval(get_var('activity',array('GET','POST')));
709 if($action == 'save') {
710 $activity['assignment'] = get_var('assignment',array('POST'));
711 $activity['date'] = get_var('date',array('POST'));
712 $activity['notes']= get_var('notes',array('POST'));
713 $this->db->query("UPDATE tc_activity set " .
714 " assignment='" . $activity['assignment'] .
715 "', date='" . $activity['date'] . "'" .
716 ", notes='" . $activity['notes'] . "'" .
717 " WHERE activity=" . $activity['activity'],__LINE__,__FILE__);
719 // Delete all the individuals who have particiapted in this activity
720 $this->db->query("DELETE from tc_participation where activity=".$activity['activity'],__LINE__,__FILE__);
722 // Re-add the individuals who are checked as having participated in this activity
723 $indivs = get_var('individual_name',array('POST'));
724 if(is_array($indivs)) { // Only do the foreach loop if we have a valid array of indivs to work with
725 foreach ($indivs as $indiv) {
726 $this->db->query("INSERT INTO tc_participation (individual,activity) " .
727 "VALUES (" . $individual . ",". $activity['activity'] . ")",__LINE__,__FILE__);
735 if($action == 'insert') {
736 $activity['assignment'] = get_var('assignment',array('POST'));
737 $activity['date'] = get_var('date',array('POST'));
738 $activity['notes']= get_var('notes',array('POST'));
739 $this->db->query("INSERT INTO tc_activity (assignment,date,notes) " .
740 "VALUES ('" . $activity['assignment'] . "','" .
741 $activity['date'] . "','" . $activity['notes'] . "')",__LINE__,__FILE__);
743 $sql = "SELECT * FROM tc_activity WHERE assignment='".$activity['assignment']."' " .
744 " AND date='".$activity['date']."' AND notes='".$activity['notes']."'";
745 $this->db->query($sql,__LINE__,__FILE__);
746 if($this->db->next_record()) {
747 //print "activity: " . $this->db->f('activity') . "<br>";
748 $activity['activity'] = $this->db->f('activity');
751 $indivs = get_var('individual_name',array('POST'));
752 foreach ($indivs as $indiv)
754 $this->db->query("INSERT INTO tc_participation (individual,activity) " .
755 "VALUES (" . $individual . ",". $activity['activity'] . ")",__LINE__,__FILE__);
762 if($action == 'add') {
763 $activity['activity'] = 0;
764 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
765 $this->t->set_var('assignment','');
766 $this->t->set_var('date','');
767 $this->t->set_var('notes','');
768 $this->t->set_var('lang_done','Cancel');
769 $this->t->set_var('lang_action','Adding New Activity');
770 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_update&activity=' .
771 $activity['activity'] . '&action=' . 'insert'));
774 if($action == 'edit') {
775 $sql = "SELECT * FROM tc_activity WHERE activity=" . $activity['activity'];
776 $this->db->query($sql,__LINE__,__FILE__);
777 $this->db->next_record();
778 $this->t->set_var('cal_date',$this->jscal->input('date',$this->db->f('date'),'','','','','',$this->cal_options));
779 $this->t->set_var('assignment', $this->db->f('assignment'));
780 $assignment = $this->db->f('assignment');
781 $this->t->set_var('date', $this->db->f('date'));
782 $this->t->set_var('notes', $this->db->f('notes'));
783 $this->t->set_var('lang_done','Cancel');
784 $this->t->set_var('lang_action','Editing Activity');
785 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_update&activity=' .
786 $activity['activity'] . '&action=' . 'save'));
789 // Create the assignments drop-down list
790 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
791 $this->db->query($sql,__LINE__,__FILE__);
793 while ($this->db->next_record()) {
794 $assignments[$i]['assignment'] = $this->db->f('assignment');
795 $assignments[$i]['name'] = $this->db->f('name');
796 $assignments[$i]['abbreviation'] = $this->db->f('abbreviation');
800 $assignment_data.= '<select name=assignment>';
801 $assignment_data.= '<option value=0></option>';
802 for ($j=0; $j < count($assignments); $j++) {
803 $id = $assignments[$j]['assignment'];
804 $name = $assignments[$j]['name'];
805 if($assignments[$j]['assignment'] == $assignment) {
806 $selected[$id] = 'selected="selected"';
810 $assignment_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
812 $assignment_data.='</select>';
813 $this->t->set_var('assignment_data',$assignment_data);
815 // Create individual selection boxes
816 $sql = "SELECT * FROM tc_individual";
817 $this->db->query($sql,__LINE__,__FILE__);
819 while ($this->db->next_record()) {
820 if($this->db->f('valid') == 1 || $action != 'add') {
821 $indiv_name[$i] = $this->db->f('name');
822 $individual[$i] = $this->db->f('individual');
823 $indiv_valid[$i] = $this->db->f('valid');
827 array_multisort($indiv_name, $individual, $indiv_valid);
830 for ($i=0; $i < count($individual); $i++) {
831 //$this->nextmatchs->template_alternate_row_color(&$this->t);
832 $sql = "SELECT * FROM tc_participation where activity=". $activity['activity'] . " AND individual=" . $individual[$i];
833 $this->db->query($sql,__LINE__,__FILE__);
834 if($this->db->next_record()) {
835 $this->t->set_var('checked','checked');
838 $this->t->set_var('checked','');
841 if($checked || $indiv_valid[$i] == 1) {
842 $this->t->set_var('individual_name',$indiv_name[$i]);
843 $this->t->set_var('individual',$individual[$i]);
844 if(($j+1) % 3 == 0) {
845 $this->t->set_var('table_sep',"</td></tr><tr>");
847 $this->t->set_var('table_sep',"</td>");
849 if(($j) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
850 $this->t->fp('list','individual_list',True);
855 $this->t->set_var('lang_reset','Clear Form');
856 $this->t->set_var('lang_add','Add Activity');
857 $this->t->set_var('lang_save','Save Changes');
858 $this->t->set_var('edithandle','');
859 $this->t->set_var('addhandle','');
861 $this->t->pfp('out','form');
862 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
863 if($action == 'add') { $this->t->pfp('addhandle','add'); }
865 $this->save_sessiondata();
868 function assign_view()
870 $this->t->set_file(array('assign_view_t' => 'assign_view.tpl'));
871 $this->t->set_block('assign_view_t','assign_view','list');
873 $this->t->set_var('lang_name','Assignment Name');
874 $this->t->set_var('lang_code','Abbreviation');
876 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
877 $this->db->query($sql,__LINE__,__FILE__);
878 $total_records = $this->db->num_rows();
881 while ($this->db->next_record()) {
882 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
883 $assignment_list[$i]['name'] = $this->db->f('name');
884 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
888 for ($i=0; $i < count($assignment_list); $i++) {
889 $this->nextmatchs->template_alternate_row_color(&$this->t);
890 $this->t->set_var('name',$assignment_list[$i]['name']);
891 $this->t->set_var('abbreviation',$assignment_list[$i]['abbreviation']);
893 $link_data['menuaction'] = 'tc.tc.assign_update';
894 $link_data['assignment'] = $assignment_list[$i]['assignment'];
895 $link_data['action'] = 'edit';
896 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
897 $this->t->set_var('lang_edit','Edit');
899 $link_data['menuaction'] = 'tc.tc.assign_update';
900 $link_data['assignment'] = '0';
901 $link_data['action'] = 'add';
902 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/tc/index.php',$link_data) .
903 '"><input type="submit" name="Add" value="' . 'Add Assignment' .'"></font></form>');
905 $this->t->fp('list','assign_view',True);
908 $this->t->pfp('out','assign_view_t');
909 $this->save_sessiondata();
912 function assign_update()
914 $this->t->set_file(array('form' => 'assign_update.tpl'));
915 $this->t->set_block('form','add','addhandle');
916 $this->t->set_block('form','edit','edithandle');
917 $this->t->set_var('lang_done','Done');
919 $action = get_var('action',array('GET','POST'));
920 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_view'));
921 $assignment['assignment'] = intval(get_var('assignment',array('GET','POST')));
923 if($action == 'save') {
924 $assignment['name'] = get_var('name',array('POST'));
925 $assignment['abbreviation'] = get_var('abbreviation',array('POST'));
926 $this->db->query("UPDATE tc_assignment set " .
927 " name='" . $assignment['name'] . "'" .
928 ", abbreviation='" . $assignment['abbreviation'] . "'" .
929 " WHERE assignment=" . $assignment['assignment'],__LINE__,__FILE__);
931 $this->assign_view();
935 if($action == 'insert') {
936 $assignment['name'] = get_var('name',array('POST'));
937 $assignment['abbreviation'] = get_var('abbreviation',array('POST'));
938 $this->db->query("INSERT INTO tc_assignment (name,abbreviation) " .
939 "VALUES ('" . $assignment['name'] . "','" .
940 $assignment['abbreviation'] . "')",__LINE__,__FILE__);
941 $this->assign_view();
945 if($action == 'add') {
946 $assignment['assignment'] = 0;
947 $this->t->set_var('name','');
948 $this->t->set_var('abbreviation','');
949 $this->t->set_var('lang_done','Cancel');
950 $this->t->set_var('lang_action','Adding New Assignment');
951 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_update&assignment=' .
952 $assignment['assignment'] . '&action=' . 'insert'));
955 if($action == 'edit')
957 $sql = "SELECT * FROM tc_assignment WHERE assignment=" . $assignment['assignment'];
958 $this->db->query($sql,__LINE__,__FILE__);
959 $this->db->next_record();
960 $this->t->set_var('name', $this->db->f('name'));
961 $this->t->set_var('abbreviation', $this->db->f('abbreviation'));
962 $this->t->set_var('lang_done','Cancel');
963 $this->t->set_var('lang_action','Editing Assignment');
964 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_update&assignment=' .
965 $assignment['assignment'] . '&action=' . 'save'));
968 $this->t->set_var('lang_reset','Clear Form');
969 $this->t->set_var('lang_add','Add Assignment');
970 $this->t->set_var('lang_save','Save Changes');
971 $this->t->set_var('edithandle','');
972 $this->t->set_var('addhandle','');
974 $this->t->pfp('out','form');
975 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
976 if($action == 'add') { $this->t->pfp('addhandle','add'); }
978 $this->save_sessiondata();
983 $this->t->set_file(array('par_view_t' => 'par_view.tpl'));
984 $this->t->set_block('par_view_t','header_list','list1');
985 $this->t->set_block('par_view_t','individual_list','list2');
987 // TODO: changed this so it picks the quorum dynamically
988 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1";
989 $this->db->query($sql,__LINE__,__FILE__);
991 while ($this->db->next_record()) {
992 $individual_name[$i] = $this->db->f('name');
993 $individual[$i] = $this->db->f('individual');
996 array_multisort($individual_name, $individual);
998 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
999 $this->db->query($sql,__LINE__,__FILE__);
1000 $total_records = $this->db->num_rows();
1003 while ($this->db->next_record()) {
1004 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1005 $activity_list[$i]['date'] = $this->db->f('date');
1006 $activity_list[$i]['activity'] = $this->db->f('activity');
1010 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1011 $this->db->query($sql,__LINE__,__FILE__);
1013 while($this->db->next_record()) {
1014 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1015 $assignment_list[$i]['name'] = $this->db->f('name');
1016 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1020 $individual_width=300; $part_width=25; $assignment_width=50;
1021 $total_width=$individual_width+$part_width;
1022 for ($i=0; $i < count($assignment_list); $i++) {
1023 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1024 $this->t->set_var('assignment_abbreviation',$assignment_list[$i]['abbreviation']);
1025 $this->t->fp('list1','header_list',True);
1026 $total_width += $assignment_width;
1029 for ($i=0; $i < count($individual); $i++) {
1030 $participated=0; $part_table = '';
1031 $this->nextmatchs->template_alternate_row_color(&$this->t);
1032 $this->t->set_var('individual_name',$individual_name[$i]);
1033 for ($j=0; $j < count($assignment_list); $j++) {
1034 $date = "0000-00-00"; $checkmark=0; $num_matches=0;
1035 for ($k=0; $k < count($activity_list); $k++) {
1036 if($assignment_list[$j]['assignment'] == $activity_list[$k]['assignment']) {
1037 $sql = "SELECT * FROM tc_participation where " .
1038 " activity=" . $activity_list[$k]['activity'] .
1039 " AND individual=" . $individual[$i];
1040 $this->db->query($sql,__LINE__,__FILE__);
1041 while($this->db->next_record()) {
1042 if($activity_list[$k]['date'] > $date) {
1043 $date = $activity_list[$k]['date'];
1052 $part_table .= '<td align=center><img src="images/checkmark.gif">';
1053 $part_table .= '<font size=-2>'.$num_matches.'</font><br>';
1054 $part_table .= '<font size=-2>'.$date.'</font></td>';
1056 $part_table .= '<td> </td>';
1060 $part_table .= '<td align=center><img src="images/checkmark.gif">'.$participated.'</td>';
1062 $part_table .= '<td> </td>';
1064 $this->t->set_var('part_table',$part_table);
1065 $this->t->fp('list2','individual_list',True);
1067 $this->t->set_var('total_width',$total_width);
1068 $this->t->set_var('individual_width',$individual_width);
1069 $this->t->set_var('part_width',$part_width);
1070 $this->t->set_var('act_width',$act_width);
1071 $this->t->pfp('out','par_view_t');
1072 $this->save_sessiondata();
1075 function willing_view()
1077 $this->t->set_file(array('willing_view_t' => 'willing_view.tpl'));
1078 $this->t->set_block('willing_view_t','header_list','list1');
1079 $this->t->set_block('willing_view_t','individual_list','list2');
1081 $this->t->set_var('lang_filter','Filter');
1082 $this->t->set_var('lang_filter_unwilling','Filter out unwilling individuals:');
1084 $filter_unwilling = get_var('filter_unwilling',array('POST'));
1085 $this->t->set_var('filter_unwilling',$filter_unwilling);
1087 if($filter_unwilling == 'y' || $filter_unwilling == '') {
1088 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\" checked>Y";
1089 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\">N";
1090 $filter_input.= " ";
1092 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\">Y";
1093 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\" checked>N";
1094 $filter_input.= " ";
1096 $this->t->set_var('filter_input',$filter_input);
1098 // TODO: changed this so it picks the quorum dynamically
1099 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1";
1100 $this->db->query($sql,__LINE__,__FILE__);
1102 while ($this->db->next_record()) {
1103 $indiv_name[$i] = $this->db->f('name');
1104 $individual[$i] = $this->db->f('individual');
1105 $indiv_phone[$individual[$i]] = $this->db->f('phone');
1108 array_multisort($indiv_name, $individual);
1110 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1111 $this->db->query($sql,__LINE__,__FILE__);
1113 while($this->db->next_record()) {
1114 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1115 $assignment_list[$i]['name'] = $this->db->f('name');
1116 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1120 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
1121 $this->db->query($sql,__LINE__,__FILE__);
1122 $total_records = $this->db->num_rows();
1125 while ($this->db->next_record()) {
1126 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1127 $activity_list[$i]['date'] = $this->db->f('date');
1128 $activity_list[$i]['activity'] = $this->db->f('activity');
1132 $indiv_width=275; $willing_width=40; $assignment_width=50;
1133 $total_width=$indiv_width+$willing_width;
1135 for ($i=0; $i < count($assignment_list); $i++) {
1136 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1137 $this->t->set_var('assignment_abbreviation',$assignment_list[$i]['abbreviation']);
1138 $this->t->fp('list1','header_list',True);
1139 $total_width += $assignment_width;
1140 $total_willing[$i] = 0;
1143 for ($i=0; $i < count($individual); $i++) {
1144 $willing_table = ''; $indiv_willing=0;
1145 $this->t->set_var('individual_name',$indiv_name[$i]);
1146 $this->t->set_var('individual_phone',$indiv_phone[$individual[$i]]);
1147 $this->t->set_var('editurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_update&individual=' .
1148 $individual[$i] . '&action=' . 'edit'));
1149 for ($j=0; $j < count($assignment_list); $j++) {
1150 $found_willingness=0;
1151 $sql = "SELECT * FROM tc_willingness where " .
1152 " assignment=" . $assignment_list[$j]['assignment'] .
1153 " AND individual=" . $individual[$i];
1154 $this->db->query($sql,__LINE__,__FILE__);
1155 while($this->db->next_record()) {
1156 $found_willingness=1;
1158 $sql = "SELECT * FROM tc_activity where " .
1159 " assignment=". $assignment_list[$j]['assignment'] .
1160 " ORDER by date DESC";
1161 $this->db2->query($sql,__LINE__,__FILE__);
1162 if($this->db2->next_record()) {
1163 $activity = $this->db2->f('activity');
1164 $date = $this->db2->f('date');
1165 $sql = "SELECT * FROM tc_participation where " .
1166 " activity=" . $activity .
1167 " AND individual=". $individual[$i];
1168 $this->db3->query($sql,__LINE__,__FILE__);
1169 if($this->db3->next_record()) {
1174 if($this->db->f('willing') == 'y') {
1175 $total_willing[$j]++;
1177 $willing_table .= '<td align=center><img src="images/checkmark.gif"><br><font size=-2>'.$date_part.'</font></td></td>';
1178 } else if($this->db->f('willing') == 'n') {
1179 $willing_table .= '<td align=center><img src="images/x.gif"></td>';
1182 $willing_table .= "<td> </td>";
1185 if(!$found_willingness) {
1187 $willing_table .= "<td> </td>";
1190 if(($indiv_willing == 1) || ($filter_unwilling == 'n')) {
1191 $this->t->set_var('willing_table',$willing_table);
1192 $this->t->fp('list2','individual_list',True);
1193 $this->nextmatchs->template_alternate_row_color(&$this->t);
1197 $stat_table = '<td><b>Total Willing to Serve</b></td>';
1198 for ($j=0; $j < count($assignment_list); $j++) {
1199 $stat_table .= "<td align=center><b>".$total_willing[$j]."</b></td>";
1201 $this->t->set_var('stat_table',$stat_table);
1203 $this->t->set_var('total_width',$total_width);
1204 $this->t->set_var('individual_width',$indiv_width);
1205 $this->t->set_var('willing_width',$willing_width);
1206 $this->t->pfp('out','willing_view_t');
1207 $this->save_sessiondata();
1210 function willing_update()
1212 //print "<font color=red>Willingness Update Under Constrcution</font>";
1213 //$this->willing_view();
1216 $this->t->set_file(array('willing_update_t' => 'willing_update.tpl'));
1217 $this->t->set_block('willing_update_t','assignment_list','list');
1218 $this->t->set_block('willing_update_t','save','savehandle');
1220 $individual = get_var('individual',array('GET','POST'));
1221 $this->t->set_var('individual',$individual);
1222 $action = get_var('action',array('GET','POST'));
1224 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_view'));
1225 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_update&action=save'));
1226 $this->t->set_var('lang_done','Cancel');
1227 $this->t->set_var('title','Willingness Update ');
1229 if($action == 'save') {
1230 // Delete all the previous willingness entries for this individual
1231 $this->db->query("DELETE from tc_willingness where individual=" . $individual ,__LINE__,__FILE__);
1233 // Now, add the assignment willingness that is checked for this individual
1234 $new_data = get_var('willingness',array('POST'));
1235 foreach ($new_data as $data) {
1236 $data_array = explode("/",$data);
1237 $assignment = $data_array[0];
1238 $willing = $data_array[1];
1239 //print "individual: $individual assignment: $assignment willing: $willing<br>";
1240 $this->db->query("INSERT INTO tc_willingness (individual,assignment,willing) " .
1241 "VALUES (" . $individual .",". $assignment .",'". $willing . "')",__LINE__,__FILE__);
1243 $this->willing_view();
1247 $assignment_width=300; $willing_width=25; $table_width=$assignment_width + $willing_width;
1250 // Find out the individual's name
1251 $sql = "SELECT * FROM tc_individual WHERE individual=".$individual." AND valid=1";
1252 $this->db->query($sql,__LINE__,__FILE__);
1253 if($this->db->next_record()) {
1254 $indiv_name = $this->db->f('name');
1255 $this->t->set_var('individual_name',$indiv_name);
1258 // Select all the assignments
1259 $sql = "SELECT * FROM tc_assignment ORDER by name ASC";
1260 $this->db->query($sql,__LINE__,__FILE__);
1262 while ($this->db->next_record()) {
1263 $assignment = $this->db->f('assignment');
1264 $assignment_name = $this->db->f('name');
1265 $assignment_abbreviation = $this->db->f('abbreviation');
1267 $this->nextmatchs->template_alternate_row_color(&$this->t);
1268 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$assignment_name</td>";
1270 $header_row="<th width=$comp_width><font size=-2>Assignments</th><th>Willingness</th>";
1271 $sql = "SELECT * FROM tc_willingness WHERE individual=".$individual." AND assignment=".$assignment;
1272 $this->db2->query($sql,__LINE__,__FILE__);
1273 $value = $assignment;
1275 if($this->db2->next_record()) {
1276 if($this->db2->f('willing') == 'y') {
1277 $table_data .= '<td width=100 align=center>';
1278 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y" checked>Y';
1279 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1280 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/"> ';
1281 $table_data .= '</td>';
1282 } else if($this->db2->f('willing') == 'n') {
1283 $table_data .= '<td width=100 align=center>';
1284 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1285 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n" checked>N';
1286 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/">';
1287 $table_data .= '</td>';
1289 $table_data .= '<td width=100 align=center>';
1290 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1291 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1292 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1293 $table_data .= '</td>';
1296 $table_data .= '<td width=100 align=center>';
1297 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1298 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1299 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1300 $table_data .= '</td>';
1303 $table_data .= "\n";
1304 $table_data .= "</tr>";
1305 $table_data .= "<tr><td colspan=20></td></tr>";
1308 $table_data .= "<tr><td colspan=20><hr></td></tr>";
1310 $this->t->set_var('table_width',$table_width);
1311 $this->t->set_var('header_row',$header_row);
1312 $this->t->set_var('table_data',$table_data);
1313 $this->t->fp('list','assignment_list',True);
1315 $this->t->set_var('lang_reset','Clear Form');
1316 $this->t->set_var('lang_save','Save Changes');
1317 $this->t->set_var('savehandle','');
1319 $this->t->pfp('out','willing_update_t');
1320 $this->t->pfp('addhandle','save');
1322 $this->save_sessiondata();
1326 function ppi_sched()
1328 $this->t->set_file(array('ppi_sched_t' => 'ppi_sched.tpl'));
1329 $this->t->set_block('ppi_sched_t','individual_list','indivlist');
1330 $this->t->set_block('ppi_sched_t','appt_list','apptlist');
1331 $action = get_var('action',array('GET','POST'));
1333 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1334 $this->t->set_var('lang_reset','Clear Changes');
1336 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
1337 $this->t->set_var('ppi_link_title','Yearly PPIs');
1339 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
1340 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
1342 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched&action=save'));
1343 $this->t->set_var('title','Yearly PPI Scheduler');
1345 $indiv_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $ppi_date_width=20;
1346 $table_width=$indiv_width + $phone_width + $pri_width + $notes_width + $ppi_date_width;
1347 $header_row = "<th width=$indiv_width><font size=-2>individual Name</th>";
1348 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1349 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1350 $header_row.= "<th width=$ppi_date_width><font size=-2>Last PPI</th>";
1351 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1352 $table_data=""; $completed_data=""; $totals_data="";
1356 // Get the President
1357 $sql = "SELECT * FROM tc_presidency where president=1 and valid=1";
1358 $this->db->query($sql,__LINE__,__FILE__);
1359 if($this->db->next_record()) {
1360 $president_name = $this->db->f('name');
1361 $president_name_array = explode(",",$president_name);
1362 $president_last_name = $president_name_array[0];
1363 $president_id = $this->db->f('individual');
1364 $presidency_id = $this->db->f('presidency');
1365 $interviewer = $this->db->f('individual');
1366 $district_number = '*';
1367 $district_name = $president_name;
1368 $sql = "SELECT * FROM tc_individual where individual='$president_id'";
1369 $this->db2->query($sql,__LINE__,__FILE__);
1370 if($this->db2->next_record()) {
1371 $mls_id = $this->db2->f('mls_id');
1373 $sql = "SELECT * FROM tc_individual where mls_id='$mls_id'";
1374 $this->db2->query($sql,__LINE__,__FILE__);
1375 if($this->db2->next_record()) {
1376 $president_address = $this->db2->f('address');
1379 print "<hr><font color=red><h3>-E- Unable to locate President in tc_presidency table</h3></font></hr>";
1383 if($action == 'save') {
1384 // Save any changes made to the appointment table
1385 $new_data = get_var('appt_notes',array('POST'));
1386 if($new_data != "") {
1387 foreach ($new_data as $entry) {
1388 $indiv = $entry['individual'];
1389 $appointment = $entry['appointment'];
1390 $location = $entry['location'];
1391 if($location == "") { $location = "$president_last_name"." home ($president_address)"; }
1392 if($indiv == 0) { $location = ""; }
1394 //Only perform a database update if we have made a change to this appointment
1395 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and individual='$indiv' and location='$location'";
1396 $this->db->query($sql,__LINE__,__FILE__);
1397 if(!$this->db->next_record()) {
1398 // Perform database save actions here
1399 $this->db->query("UPDATE tc_appointment set " .
1400 " individual='" . $indiv . "'" .
1401 ",location='" . $location . "'" .
1402 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1403 // Email the appointment
1404 $this->email_appt($appointment);
1409 // Save any changes made to the ppi notes table
1410 $new_data = get_var('notes',array('POST'));
1411 foreach ($new_data as $entry) {
1412 $notes = $entry['notes'];
1413 $individual = $entry['individual'];
1414 $priority = $entry['pri'];
1416 // Perform database save actions here
1417 $sql = "SELECT * FROM tc_individual WHERE individual='$individual'";
1418 $this->db->query($sql,__LINE__,__FILE__);
1419 if ($this->db->next_record()) {
1420 $scheduling_priority = $this->db->f('scheduling_priority');
1421 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$priority' AND notes=\"$notes\" WHERE scheduling_priority='$scheduling_priority'", __LINE__, __FILE__);
1425 $this->db->query("UPDATE tc_individual set " .
1426 " notes='" . $notes . "'" .
1427 ",priority='" . $priority . "'" .
1428 " WHERE individual=" . $individual,__LINE__,__FILE__);
1434 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched');
1435 //Header('Location: ' . $take_me_to_url);
1438 // create the individual id -> individual name mapping
1439 // TODO: changed this so it picks the quorum dynamically
1440 $sql = "SELECT * FROM tc_individual where valid=1 and steward='Elder' ORDER BY name ASC";
1441 $this->db->query($sql,__LINE__,__FILE__);
1445 while ($this->db->next_record()) {
1446 $indiv_name[$i] = $this->db->f('name');
1447 $individual[$i] = $this->db->f('individual');
1450 array_multisort($indiv_name, $individual);
1452 // APPOINTMENT TABLE
1453 $date_width=250; $time_width=100; $indiv_width=200; $location_width=100;
1454 $appt_table_width=$date_width + $time_width + $indiv_width + $location_width;
1455 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1456 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1457 $appt_header_row.= "<th width=$indiv_width><font size=-2>indiv</th>";
1458 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
1459 $appt_table_data = "";
1461 $total_indivs=0; $indivs_with_yearly_ppi=0;
1463 // Display a scheduling table for the President
1464 $table_data=""; $appt_table_data="";
1465 $table_title = "District ".$district_number.": ".$district_name.": All indivs with Yearly PPI Not Completed";
1466 $appt_table_title = "District ".$district_number.": ".$district_name.": Yearly PPI Appointment Slots";
1467 $this->t->set_var('table_title',$table_title);
1468 $this->t->set_var('appt_table_title',$appt_table_title);
1470 // query the database for all the appointments
1471 $sql = "SELECT * FROM tc_appointment where presidency=".$presidency_id." and date>=CURDATE() ORDER BY date ASC, time ASC";
1472 $this->db->query($sql,__LINE__,__FILE__);
1474 while ($this->db->next_record()) {
1475 $appointment = $this->db->f('appointment');
1476 $indiv = $this->db->f('individual');
1477 $location = $this->db->f('location');
1478 if(($location == "") && ($indiv > 0)) { $location = "$president_last_name"." home ($president_address)"; }
1480 $date = $this->db->f('date');
1481 $date_array = explode("-",$date);
1482 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1483 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1485 $time = $this->db->f('time');
1486 $time_array = explode(":",$time);
1487 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1489 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1490 $appt_table_data.= "<td align=center>$day_string</td>";
1491 $appt_table_data.= "<td align=center>$time_string</td>";
1493 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][individual]>';
1494 $appt_table_data.= '<option value=0></option>';
1495 for ($i=0; $i < count($individual); $i++) {
1496 $id = $individual[$i];
1497 $name = $indiv_name[$i];
1498 if($individual[$i] == $indiv) {
1499 $selected[$id] = 'selected="selected"';
1501 $selected[$id] = '';
1503 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1505 $appt_table_data.='</select></td>';
1507 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
1508 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
1510 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1512 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1513 $this->t->set_var('tr_color',$tr_color);
1516 $this->t->set_var('appt_table_data',$appt_table_data);
1517 $this->t->set_var('appt_header_row',$appt_header_row);
1518 $this->t->set_var('appt_table_width',$appt_table_width);
1520 // PPI SCHEDULING TABLE
1521 // TODO: changed this so it picks the quorum dynamically
1522 $sql = "SELECT * FROM tc_individual as ti JOIN tc_scheduling_priority as tsp where ti.scheduling_priority=tsp.scheduling_priority and steward='Elder' and valid=1 ORDER by tsp.priority ASC, ti.name ASC";
1523 $this->db->query($sql,__LINE__,__FILE__);
1527 while ($this->db->next_record()) {
1528 $individual[$i] = $this->db->f('individual');
1529 $indiv_name[$i] = $this->db->f('name');
1530 $indiv_phone[$individual[$i]] = $this->db->f('phone');
1531 $indiv_priority[$individual[$i]] = $this->db->f('priority');
1532 $indiv_notes[$individual[$i]] = $this->db->f('notes');
1537 $max = count($individual);
1539 for($i=0; $i < $max; $i++) {
1540 $id = $individual[$i];
1541 $name = $indiv_name[$i];
1542 $phone = $indiv_phone[$id];
1543 $priority = $indiv_priority[$id];
1544 $notes = $indiv_notes[$id];
1546 // If this individual has had a yearly PPI this year, don't show him on the schedule list
1547 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
1548 $sql = "SELECT * FROM tc_interview WHERE date > '$year_start' AND date < '$year_end' ".
1549 "AND individual=" . $id . " AND interview_type='ppi'";
1550 $this->db2->query($sql,__LINE__,__FILE__);
1552 if(!$this->db2->next_record()) {
1553 $sql = "SELECT * FROM tc_interview WHERE individual=" . $id . " AND interview_type='ppi' ORDER BY date DESC";
1554 $this->db->query($sql,__LINE__,__FILE__);
1555 if($this->db->next_record()) {
1556 $date = $this->db->f('date');
1560 $link_data['menuaction'] = 'tc.tc.ppi_update';
1561 $link_data['individual'] = $id;
1562 $link_data['name'] = $name;
1563 $link_data['interview'] = '';
1564 $link_data['interview_type'] = 1;
1565 $link_data['action'] = 'add';
1566 $link_data['interviewer'] = $interviewer;
1567 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1568 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1569 $this->t->set_var('tr_color',$tr_color);
1570 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1571 $table_data.= "<td align=center>$phone</td>";
1572 //$table_data.= "<td align=center>$priority</td>";
1573 $table_data.= "<td align=center>";
1574 $table_data.= '<select name=notes['.$i.'][pri]>';
1575 foreach(range(0,6) as $num) {
1576 if($num == 0) { $num = 1; } else {$num = $num*5; }
1577 if($priority == $num) {
1578 $selected[$num] = 'selected="selected"';
1580 $selected[$num] = '';
1582 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1584 $table_data.= '</select></td>';
1585 $table_data.= "<td align=center>$date</td>";
1586 $table_data.= '<td><input type=text size="50" maxlength="128" name="notes['.$i.'][notes]" value="'.$notes.'">';
1587 $table_data.= '<input type=hidden name="notes['.$i.'][individual]" value="'.$id.'">';
1588 $table_data.= '<input type=hidden name="notes['.$i.'][indiv_name]" value="'.$name.'">';
1589 $table_data.= '</td>';
1590 $table_data.= '</tr>';
1592 $link_data['menuaction'] = 'tc.tc.ppi_update';
1593 $link_data['interviewer'] = $this->db2->f('interviewer');
1594 $link_data['individual'] = $this->db2->f('individual');
1595 $link_data['name'] = $name;
1596 $link_data['interview'] = $this->db2->f('interview');
1597 $link_data['interview_type'] = $this->db2->f('interview_type');
1598 $link_data['action'] = 'view';
1599 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1600 $indivs_with_yearly_ppi++;
1601 $date = $this->db2->f('date');
1602 $notes = $this->db2->f('notes');
1603 if(strlen($notes) > 40) { $notes = substr($notes,0,40) . "..."; }
1604 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1605 $this->t->set_var('tr_color2',$tr_color2);
1606 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1607 $completed_data.= "<td align=center>$phone</td>";
1608 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1609 $completed_data.= "<td align=left>$notes</td>";
1610 $completed_data.= '</tr>';
1612 } // End for individuals Loop
1614 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1615 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1616 $completed_header_row = "<th width=$name_width><font size=-2>Individual Name</th>";
1617 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1618 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1619 $completed_header_row.= "<th width=$notes_width><font size=-2>PPI Notes</th>";
1621 $this->t->set_var('table_width',$table_width);
1622 $this->t->set_var('header_row',$header_row);
1623 $this->t->set_var('table_data',$table_data);
1624 $this->t->set_var('completed_header_row',$completed_header_row);
1625 $this->t->set_var('completed_table_width',$completed_table_width);
1626 $this->t->set_var('completed',$completed_data);
1627 $this->t->fp('indivlist','individual_list',True);
1629 $indivs_width=300; $totals_width=100;
1630 $totals_table_width=$indivs_width + $totals_width;
1631 $totals_header_row = "<th width=$indivs_width><font size=-2>Individuals</th>";
1632 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
1633 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1634 $totals_data.= "<td align=left><font size=-2><b>Total Individuals with yearly PPIs completed:</b></font></td>";
1635 $totals_data.= "<td align=center><font size=-2><b>$indivs_with_yearly_ppi / $total_indivs</b></font></td>";
1636 $percent = ceil(($indivs_with_yearly_ppi / $total_indivs)*100);
1637 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1638 $this->t->set_var('tr_color',$tr_color);
1639 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1640 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
1641 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
1642 $totals_data.= "</tr>";
1644 $this->t->set_var('totals',$totals_data);
1645 $this->t->set_var('totals_header_row',$totals_header_row);
1646 $this->t->set_var('totals_table_width',$totals_table_width);
1648 $this->t->pfp('out','ppi_sched_t');
1649 $this->save_sessiondata();
1653 function int_sched()
1655 $this->t->set_file(array('int_sched_t' => 'int_sched.tpl'));
1656 $this->t->set_block('int_sched_t','individual_list','indivlist');
1657 $this->t->set_block('int_sched_t','appt_list','apptlist');
1658 $action = get_var('action',array('GET','POST'));
1660 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1661 $this->t->set_var('lang_reset','Clear Changes');
1663 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
1664 $this->t->set_var('int_link_title','Hometeaching Interviews');
1666 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
1667 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
1669 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched&action=save'));
1670 $this->t->set_var('title','Hometeaching Interviews Scheduler');
1672 $indiv_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $int_date_width=20;
1673 $table_width=$indiv_width + $phone_width + $pri_width + $notes_width + $int_date_width;
1674 $header_row = "<th width=$indiv_width><font size=-2>individual Name</th>";
1675 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1676 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1677 $header_row.= "<th width=$int_date_width><font size=-2>Last Interview</th>";
1678 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1679 $table_data=""; $completed_data=""; $totals_data="";
1683 $nextyear = $year + 1;
1684 if($month >= 1 && $month <= 3) { $quarter_start=$year."-01-01"; $quarter_end=$year."-04-01"; }
1685 if($month >= 4 && $month <= 6) { $quarter_start=$year."-04-01"; $quarter_end=$year."-07-01"; }
1686 if($month >= 7 && $month <= 9) { $quarter_start=$year."-07-01"; $quarter_end=$year."-10-01"; }
1687 if($month >= 10 && $month <= 12) { $quarter_start=$year."-10-01"; $quarter_end=$nextyear."-01-01"; }
1688 //print "year: $year month: $month quarter_start: $quarter_start quarter_end: $quarter_end<br>";
1690 // create the individual id -> individual name mapping
1691 // TODO: changed this so it picks the quorum dynamically
1692 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1 ORDER BY name ASC";
1693 $this->db->query($sql,__LINE__,__FILE__);
1695 $individual_data = NULL;
1696 $indiv_name_data = NULL;
1697 while ($this->db->next_record()) {
1698 $indiv_name_data[$i] = $this->db->f('name');
1699 $individual_data[$i] = $this->db->f('individual');
1700 $individ2name[$individual_data[$i]] = $indiv_name_data[$i];
1703 // add any YM that are home teachers
1704 $sql = "SELECT * FROM tc_companionship where valid=1";
1705 $this->db->query($sql,__LINE__,__FILE__);
1706 while ($this->db->next_record()) {
1707 $tmp_individual = $this->db->f('individual');
1708 $sql = "Select * FROM tc_individual where individual='$tmp_individual' and steward='' and valid=1";
1709 $this->db2->query($sql,__LINE__,__FILE__);
1710 while ($this->db2->next_record()) {
1711 $indiv_name_data[$i] = $this->db2->f('name');
1712 $individual_data[$i] = $this->db2->f('individual');
1713 $individ2name[$individual_data[$i]] = $indiv_name_data[$i];
1717 array_multisort($indiv_name_data, $individual_data);
1719 if($action == 'save') {
1720 // Save any changes made to the appointment table
1721 $new_data = get_var('appt_notes',array('POST'));
1722 if($new_data != "") {
1723 foreach ($new_data as $entry) {
1724 $indiv = $entry['individual'];
1725 $appointment = $entry['appointment'];
1726 $location = $entry['location'];
1727 if($location == "") {
1728 $supervisor = $entry['supervisor'];
1729 $supervisor_array = explode(",", $individ2name[$supervisor]);
1730 $supervisor_last_name = $supervisor_array[0];
1731 $sql = "SELECT * FROM tc_individual where individual='$supervisor'";
1732 $this->db2->query($sql,__LINE__,__FILE__);
1733 if($this->db2->next_record()) {
1734 $mls_id = $this->db2->f('mls_id');
1736 $sql = "SELECT * FROM tc_individual where mls_id='$mls_id'";
1737 $this->db2->query($sql,__LINE__,__FILE__);
1738 if($this->db2->next_record()) {
1739 $supervisor_address = $this->db2->f('address');
1741 $location = "$supervisor_last_name"." home ($supervisor_address)";
1743 if($indiv == 0) { $location = ""; }
1745 //print "indiv: $indiv appointment: $appointment <br>";
1746 //Only perform a database update if we have made a change to this appointment
1747 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and individual='$indiv' and location='$location'";
1748 $this->db->query($sql,__LINE__,__FILE__);
1749 if(!$this->db->next_record()) {
1750 // Perform database save actions here
1751 $this->db->query("UPDATE tc_appointment set " .
1752 " individual='" . $indiv . "'" .
1753 ",location='" . $location . "'" .
1754 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1755 // Email the appointment
1756 $this->email_appt($appointment);
1761 // Save any changes made to the int notes table
1762 $new_data = get_var('hti_notes',array('POST'));
1763 foreach ($new_data as $entry) {
1764 $hti_notes = $entry['notes'];
1765 $individual = $entry['individual'];
1766 $indiv_name = $entry['indiv_name'];
1767 $hti_pri = $entry['pri'];
1768 //print "hti_notes: $hti_notes indiv_name: $indiv_name <Br>";
1769 // Perform database save actions here
1770 $this->db->query("SELECT * FROM tc_companionship WHERE individual=$individual and valid=1",__LINE__,__FILE__);
1771 if ($this->db->next_record()) {
1772 $scheduling_priority = $this->db->f('scheduling_priority');
1773 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$hti_pri' and notes=\"hti_notes\" where scheduling_priority=$scheduling_priority",__LINE__,__FILE__);
1776 $this->db->query("UPDATE tc_individual set " .
1777 " hti_notes='" . $hti_notes . "'" .
1778 ",hti_pri='" . $hti_pri . "'" .
1779 " WHERE individual=" . $individual,__LINE__,__FILE__);
1783 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched');
1784 //Header('Location: ' . $take_me_to_url);
1787 // Get the Districts
1788 $sql = "SELECT * FROM tc_district where valid=1 ORDER BY district ASC";
1789 $this->db->query($sql,__LINE__,__FILE__);
1791 while ($this->db->next_record()) {
1792 $district = $this->db->f('district');
1793 $districts[$i]['district'] = $this->db->f('district');
1794 $districts[$i]['name'] = $this->db->f('name');
1795 $districts[$i]['supervisor'] = $this->db->f('supervisor');
1796 $sql = "SELECT * FROM tc_presidency where district=$district and valid=1";
1797 $this->db2->query($sql,__LINE__,__FILE__);
1798 if($this->db2->next_record()) {
1799 $districts[$i]['presidency'] = $this->db2->f('presidency');
1804 // APPOINTMENT TABLE
1806 $date_width=250; $time_width=100; $indiv_width=200; $location_width=100;
1807 $appt_table_width=$date_width + $time_width + $indiv_width + $location_width;
1808 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1809 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1810 $appt_header_row.= "<th width=$indiv_width><font size=-2>Individual</th>";
1811 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
1812 $appt_table_data = "";
1814 $total_comps=0; $comps_with_quarterly_int=0;
1816 // Display a scheduling table for each district
1817 for ($d=0; $d < count($districts); $d++) {
1818 $table_data=""; $appt_table_data="";
1819 $this->t->set_var('district_number',$districts[$d]['district']);
1820 $this->t->set_var('district_name',$districts[$d]['name']);
1821 $supervisor = $districts[$d]['supervisor'];
1822 $supervisor_array = explode(",", $supervisor);
1823 $supervisor_last_name = $supervisor_array[0];
1824 $sql = "SELECT * FROM tc_individual where individual='$supervisor'";
1825 $this->db2->query($sql,__LINE__,__FILE__);
1826 if($this->db2->next_record()) {
1827 $mls_id = $this->db2->f('mls_id');
1829 $sql = "SELECT * FROM tc_individual where mls_id='$mls_id'";
1830 $this->db2->query($sql,__LINE__,__FILE__);
1831 if($this->db2->next_record()) {
1832 $supervisor_address = $this->db2->f('address');
1834 $location = "$supervisor_last_name"." home ($supervisor_address)";
1835 $table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": All Individuals with Interviews Not Completed";
1836 $appt_table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": Interview Appointment Slots";
1837 $this->t->set_var('table_title',$table_title);
1838 $this->t->set_var('appt_table_title',$appt_table_title);
1840 // query the database for all the appointments
1841 $sql = "SELECT * FROM tc_appointment where presidency=".$districts[$d]['presidency']." and date>=CURDATE() ORDER BY date ASC, time ASC";
1842 $this->db->query($sql,__LINE__,__FILE__);
1844 while ($this->db->next_record()) {
1845 $appointment = $this->db->f('appointment');
1846 $indiv = $this->db->f('individual');
1847 $location = $this->db->f('location');
1848 if(($location == "") && ($indiv > 0)) { $location = "$supervisor_last_name"." home ($supervisor_address)"; }
1850 $date = $this->db->f('date');
1851 $date_array = explode("-",$date);
1852 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1853 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1855 $time = $this->db->f('time');
1856 $time_array = explode(":",$time);
1857 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1859 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1860 $appt_table_data.= "<td align=center>$day_string</td>";
1861 $appt_table_data.= "<td align=center>$time_string</td>";
1863 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][individual]>';
1864 $appt_table_data.= '<option value=0></option>';
1865 for ($i=0; $i < count($individual_data); $i++) {
1866 $id = $individual_data[$i];
1867 $name = $indiv_name_data[$i];
1868 if($individual_data[$i] == $indiv) {
1869 $selected[$id] = 'selected="selected"';
1871 $selected[$id] = '';
1873 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1875 $appt_table_data.='</select></td>';
1877 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
1878 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
1880 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1881 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][supervisor]" value="'.$supervisor.'">';
1883 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1884 $this->t->set_var('tr_color',$tr_color);
1887 $this->t->set_var('appt_table_data',$appt_table_data);
1888 $this->t->set_var('appt_header_row',$appt_header_row);
1889 $this->t->set_var('appt_table_width',$appt_table_width);
1891 // INTERVIEW SCHEDULING TABLE
1893 // Select all the unique companionship numbers for this district
1894 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$d]['district'];
1895 $this->db->query($sql,__LINE__,__FILE__);
1896 $j=0; $unique_companionships = '';
1897 while ($this->db->next_record())
1899 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
1904 for ($j=0; $j < count($unique_companionships); $j++) {
1905 // Select all the companions from each companionship
1906 $sql = "SELECT * FROM tc_companionship 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'];
1907 $this->db->query($sql,__LINE__,__FILE__);
1908 $k=0; $int_completed=0;
1909 $comp = $unique_companionships[$j]['companionship'];
1910 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1911 $this->t->set_var('tr_color',$tr_color);
1913 while ($this->db->next_record()) {
1914 // Get this companions information
1915 $individual = $this->db->f('individual');
1917 $id = $this->db->f('individual');
1918 $name = $this->db->f('name');
1919 $phone = $this->db->f('phone');
1920 $hti_pri = $this->db->f('priority');
1921 $hti_notes = $this->db->f('notes');
1923 // If the companionship has already had its quarterly interview,
1924 // Skip the other companion in the companionship.
1925 if($int_completed == 1) {
1926 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1927 $completed_data.= "<td align=center>$phone</td>";
1928 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1929 $completed_data.= "<td align=left>$hti_notes</td>";
1930 $completed_data.= '</tr>';
1931 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1932 $this->t->set_var('tr_color2',$tr_color2);
1933 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1934 $this->t->set_var('tr_color',$tr_color);
1938 // If this companionship has had a hometeaching interview this quarter, don't show them on the schedule list
1939 $sql = "SELECT * FROM tc_interview WHERE date >= '$quarter_start' AND date < '$quarter_end' AND individual='$id'";
1940 $this->db2->query($sql,__LINE__,__FILE__);
1942 if(!$this->db2->next_record()) {
1943 $sql = "SELECT * FROM tc_interview WHERE individual='$id' ORDER BY date DESC";
1944 $this->db3->query($sql,__LINE__,__FILE__);
1945 if($this->db3->next_record()) {
1946 $date = $this->db3->f('date');
1950 $link_data['menuaction'] = 'tc.tc.int_update';
1951 $link_data['individual'] = $id;
1952 $link_data['name'] = $name;
1953 $link_data['interview'] = '';
1954 $link_data['action'] = 'add';
1955 $link_data['interviewer'] = $districts[$d]['supervisor'];
1956 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1957 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1958 $table_data.= "<td align=center>$phone</td>";
1959 $table_data.= "<td align=center>";
1960 $table_data.= '<select name=hti_notes['.$i.'][pri]>';
1961 foreach(range(0,6) as $num) {
1962 if($num == 0) { $num = 1; } else {$num = $num*5; }
1963 if($hti_pri == $num) {
1964 $selected[$num] = 'selected="selected"';
1966 $selected[$num] = '';
1968 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1970 $table_data.= '</select></td>';
1971 $table_data.= "<td align=center>$date</td>";
1972 $table_data.= '<td><input type=text size="50" maxlength="128" name="hti_notes['.$i.'][notes]" value="'.$hti_notes.'">';
1973 $table_data.= '<input type=hidden name="hti_notes['.$i.'][individual]" value="'.$id.'">';
1974 $table_data.= '<input type=hidden name="hti_notes['.$i.'][indiv_name]" value="'.$name.'">';
1975 $table_data.= '</td>';
1976 $table_data.= '</tr>'."\n";
1979 $link_data['menuaction'] = 'tc.tc.int_update';
1980 $link_data['interviewer'] = $this->db2->f('interviewer');
1981 $link_data['individual'] = $this->db2->f('individual');
1982 $link_data['name'] = $name;
1983 $link_data['interview'] = $this->db2->f('interview');
1984 $link_data['action'] = 'view';
1985 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1986 $comps_with_quarterly_int++;
1988 $date = $this->db2->f('date');
1989 $hti_notes = $this->db2->f('notes');
1990 if(strlen($hti_notes) > 40) { $hti_notes = substr($hti_notes,0,40) . "..."; }
1991 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1992 $completed_data.= "<td align=center>$phone</td>";
1993 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1994 $completed_data.= "<td align=left>$hti_notes</td>";
1995 $completed_data.= '</tr>';
2000 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
2001 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
2002 $completed_header_row = "<th width=$name_width><font size=-2>Individual Name</th>";
2003 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2004 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
2005 $completed_header_row.= "<th width=$notes_width><font size=-2>Interview Notes</th>";
2007 $this->t->set_var('table_width',$table_width);
2008 $this->t->set_var('header_row',$header_row);
2009 $this->t->set_var('table_data',$table_data);
2010 $this->t->set_var('completed_header_row',$completed_header_row);
2011 $this->t->set_var('completed_table_width',$completed_table_width);
2012 $this->t->set_var('completed',$completed_data);
2013 $this->t->fp('indivlist','individual_list',True);
2015 } // End for each district loop
2018 $indivs_width=300; $totals_width=100;
2019 $totals_table_width=$indivs_width + $totals_width;
2020 $totals_header_row = "<th width=$indivs_width><font size=-2>Individuals</th>";
2021 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2022 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2023 $totals_data.= "<td align=left><font size=-2><b>Total Companionships with interviews completed:</b></font></td>";
2024 $totals_data.= "<td align=center><font size=-2><b>$comps_with_quarterly_int / $total_comps</b></font></td>";
2025 $percent = ceil(($comps_with_quarterly_int / $total_comps)*100);
2026 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2027 $this->t->set_var('tr_color',$tr_color);
2028 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2029 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2030 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2031 $totals_data.= "</tr>";
2033 $this->t->set_var('totals',$totals_data);
2034 $this->t->set_var('totals_header_row',$totals_header_row);
2035 $this->t->set_var('totals_table_width',$totals_table_width);
2037 $this->t->pfp('out','int_sched_t');
2038 $this->save_sessiondata();
2042 function vis_sched()
2044 $this->t->set_file(array('vis_sched_t' => 'vis_sched.tpl'));
2045 $this->t->set_block('vis_sched_t','family_list','familylist');
2046 $this->t->set_block('vis_sched_t','appt_list','apptlist');
2047 $action = get_var('action',array('GET','POST'));
2049 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
2050 $this->t->set_var('lang_reset','Clear Changes');
2052 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2053 $this->t->set_var('vis_link_title','View Yearly Visits');
2055 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
2056 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2058 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched&action=save'));
2059 $this->t->set_var('title','Presidency Yearly Visit Scheduler');
2061 $family_width=500; $phone_width=40; $pri_width=10; $notes_width=128; $visit_date_width=20;
2062 $table_width=$family_width + $phone_width + $pri_width + $notes_width + $visit_date_width;
2063 $header_row = "<th width=$family_width><font size=-2>Family Name</th>";
2064 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2065 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
2066 $header_row.= "<th width=$visit_date_width><font size=-2>Last Visit</th>";
2067 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
2068 $table_data=""; $completed_data=""; $totals_data="";
2072 // create the family id -> family name mapping
2073 $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 ORDER BY ti.name ASC";
2074 $this->db->query($sql,__LINE__,__FILE__);
2077 while ($this->db->next_record()) {
2078 $family_id[$i] = $this->db->f('family');
2079 $family_name[$i] = $this->db->f('name');
2080 $familyid2name[$family_id[$i]] = $family_name[$i];
2081 $familyid2address[$family_id[$i]] = $this->db->f('address');
2084 array_multisort($family_name, $family_id);
2086 if($action == 'save') {
2087 // Save any changes made to the appointment table
2088 $new_data = get_var('appt_notes',array('POST'));
2089 if($new_data != "") {
2090 foreach ($new_data as $entry) {
2091 $family = $entry['family'];
2092 $appointment = $entry['appointment'];
2093 $location = $entry['location'];
2094 if($location == "") {
2095 $family_name_array = explode(",", $familyid2name[$family]);
2096 $family_last_name = $family_name_array[0];
2097 $family_address = $familyid2address[$family];
2098 $location = "$family_last_name"." home ($family_address)";
2100 if($family == 0) { $location = ""; }
2102 //Only perform a database update if we have made a change to this appointment
2103 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and family='$family' and location='$location'";
2104 $this->db->query($sql,__LINE__,__FILE__);
2105 if(!$this->db->next_record()) {
2106 // Perform database save actions here
2107 $this->db->query("UPDATE tc_appointment set " .
2108 " family='" . $family . "'" .
2109 ",location='" . $location . "'" .
2110 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
2112 // Email the appointment
2113 $this->email_appt($appointment);
2118 // Save any changes made to the visit notes table
2119 $new_data = get_var('vis_notes',array('POST'));
2120 foreach ($new_data as $entry) {
2121 $visit_notes = $entry['notes'];
2122 $family = $entry['family_id'];
2123 $visit_pri = $entry['pri'];
2125 // Perform database save actions here
2126 $this->db->query("SELECT * FROM tc_family WHERE family='$family'",__LINE__,__FILE__);
2127 if ($this->db->next_record()) {
2128 $scheduling_priority = $this->db->f('scheduling_priority');
2129 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$visit_pri' AND notes=\"$visit_notes\" WHERE scheduling_priority='$scheduling_priority'",__LINE__,__FILE__);
2132 $this->db->query("UPDATE tc_family set " .
2133 " visit_notes='" . $visit_notes . "'" .
2134 ",visit_pri='" . $visit_pri . "'" .
2135 " WHERE family=" . $family,__LINE__,__FILE__);
2139 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched');
2140 //Header('Location: ' . $take_me_to_url);
2143 // APPOINTMENT TABLE
2144 $date_width=250; $time_width=100; $family_width=250; $location_width=100;
2145 $appt_table_width=$date_width + $time_width + $family_width + $location_width;
2146 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
2147 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
2148 $appt_header_row.= "<th width=$family_width><font size=-2>Family</th>";
2149 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
2150 $appt_table_data = "";
2152 // Find out what the President ID is
2153 $sql = "SELECT * FROM tc_presidency where president=1 and valid=1";
2154 $this->db->query($sql,__LINE__,__FILE__);
2155 if($this->db->next_record()) {
2156 $presidency_name = $this->db->f('name');
2157 $presidency_id = $this->db->f('presidency');
2159 print "<hr><font color=red><h3>-E- Unable to locate Presidency in tc_presidency table</h3></font></hr>";
2163 // query the database for all the appointments
2164 $sql = "SELECT * FROM tc_appointment where presidency=$presidency_id and date>=CURDATE() ORDER BY date ASC, time ASC";
2165 $this->db->query($sql,__LINE__,__FILE__);
2167 while ($this->db->next_record()) {
2168 $appointment = $this->db->f('appointment');
2169 $family = $this->db->f('family');
2170 $location = $this->db->f('location');
2171 $family_name_array = explode(",", $familyid2name[$family]);
2172 $family_last_name = $family_name_array[0];
2173 $family_address = $familyid2address[$family];
2174 if(($location == "") && ($family > 0)) { $location = "$family_last_name"." home ($family_address)"; }
2176 $date = $this->db->f('date');
2177 $date_array = explode("-",$date);
2178 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
2179 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
2181 $time = $this->db->f('time');
2182 $time_array = explode(":",$time);
2183 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
2185 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2186 $appt_table_data.= "<td align=center>$day_string</td>";
2187 $appt_table_data.= "<td align=center>$time_string</td>";
2189 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][family]>';
2190 $appt_table_data.= '<option value=0></option>';
2191 for ($i=0; $i < count($family_id); $i++) {
2192 $id = $family_id[$i];
2193 $name = $family_name[$i];
2194 if($family_id[$i] == $family) {
2195 $selected[$id] = 'selected="selected"';
2197 $selected[$id] = '';
2199 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
2201 $appt_table_data.='</select></td>';
2203 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
2204 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
2206 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
2208 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2209 $this->t->set_var('tr_color',$tr_color);
2212 $this->t->set_var('appt_table_data',$appt_table_data);
2213 $this->t->set_var('appt_header_row',$appt_header_row);
2214 $this->t->set_var('appt_table_width',$appt_table_width);
2217 // VISIT SCHEDULING TABLE
2218 $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 ORDER BY tsp.priority ASC, ti.name ASC";
2219 $this->db->query($sql,__LINE__,__FILE__);
2221 $total_families=0; $families_with_yearly_visit=0;
2223 while ( $this->db->next_record()) {
2225 $id = $this->db->f('family');
2226 $name = $this->db->f('name');
2227 $phone = $this->db->f('phone');
2228 $vis_pri = $this->db->f('priority');
2229 $vis_notes = $this->db->f('notes');
2231 // If this family has had a yearly visit this year, don't show them on the schedule list
2232 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2233 $sql = "SELECT * FROM tc_visit WHERE date > '$year_start' AND date < '$year_end' ".
2234 "AND family=" . $id . " AND companionship=0";
2235 $this->db2->query($sql,__LINE__,__FILE__);
2237 if(!$this->db2->next_record()) {
2238 $sql = "SELECT * FROM tc_visit WHERE family=" . $id . " AND companionship=0 ORDER BY date DESC";
2239 $this->db3->query($sql,__LINE__,__FILE__);
2240 if($this->db3->next_record()) {
2241 $date = $this->db3->f('date');
2245 $link_data['menuaction'] = 'tc.tc.vis_update';
2246 $link_data['visit'] = '';
2247 $link_data['family'] = $id;
2248 $link_data['name'] = $name;
2249 $link_data['action'] = 'add';
2250 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2251 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2252 $table_data.= "<td align=center>$phone</td>";
2253 $table_data.= "<td align=center>";
2254 $table_data.= '<select name=vis_notes['.$i.'][pri]>';
2255 foreach(range(0,6) as $num) {
2256 if($num == 0) { $num = 1; } else {$num = $num*5; }
2257 if($vis_pri == $num) {
2258 $selected[$num] = 'selected="selected"';
2260 $selected[$num] = '';
2262 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2264 $table_data.= '</select></td>';
2265 $table_data.= "<td align=center>$date</td>";
2266 $table_data.= '<td><input type=text size="50" maxlength="128" name="vis_notes['.$i.'][notes]" value="'.$vis_notes.'">';
2267 $table_data.= '<input type=hidden name="vis_notes['.$i.'][family_id]" value="'.$id.'">';
2268 $table_data.= '<input type=hidden name="vis_notes['.$i.'][family_name]" value="'.$name.'">';
2269 $table_data.= '</td>';
2270 $table_data.= '</tr>';
2271 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2272 $this->t->set_var('tr_color',$tr_color);
2274 $link_data['menuaction'] = 'tc.tc.vis_update';
2275 $link_data['visit'] = $this->db2->f('visit');
2276 $link_data['family'] = $this->db2->f('family');
2277 $link_data['name'] = $name;
2278 $link_data['date'] = $this->db2->f('date');
2279 $link_data['action'] = 'view';
2280 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2281 $families_with_yearly_visit++;
2282 $date = $this->db2->f('date');
2283 $vis_notes = $this->db2->f('notes');
2284 if(strlen($vis_notes) > 40) { $vis_notes = stripslashes(substr($vis_notes,0,40) . "..."); }
2285 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2286 $completed_data.= "<td align=center>$phone</td>";
2287 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2288 $completed_data.= "<td align=left>$vis_notes</td>";
2289 $completed_data.= '</tr>';
2290 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
2291 $this->t->set_var('tr_color2',$tr_color2);
2295 $name_width=190; $phone_width=100; $date_width=100; $notes_width=300;
2296 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
2297 $completed_header_row = "<th width=$name_width><font size=-2>Family Name</th>";
2298 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2299 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
2300 $completed_header_row.= "<th width=$notes_width><font size=-2>Visit Notes</th>";
2302 $family_width=300; $totals_width=100;
2303 $totals_table_width=$family_width + $totals_width;
2304 $totals_header_row = "<th width=$family_width><font size=-2>Families</th>";
2305 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2306 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2307 $totals_data.= "<td align=left><font size=-2><b>Total Families with yearly Visits completed:</b></font></td>";
2308 $totals_data.= "<td align=center><font size=-2><b>$families_with_yearly_visit / $total_families</b></font></td>";
2309 $percent = ceil(($families_with_yearly_visit / $total_families)*100);
2310 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2311 $this->t->set_var('tr_color',$tr_color);
2312 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2313 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2314 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2315 $totals_data.= "</tr>";
2317 $this->t->set_var('table_width',$table_width);
2318 $this->t->set_var('header_row',$header_row);
2319 $this->t->set_var('table_data',$table_data);
2320 $this->t->set_var('totals_header_row',$totals_header_row);
2321 $this->t->set_var('totals_table_width',$totals_table_width);
2322 $this->t->set_var('completed_header_row',$completed_header_row);
2323 $this->t->set_var('completed_table_width',$completed_table_width);
2324 $this->t->set_var('completed',$completed_data);
2325 $this->t->set_var('totals',$totals_data);
2326 $this->t->fp('familylist','family_list',True);
2327 $this->t->fp('apptlist','appt_list',True);
2329 $this->t->pfp('out','vis_sched_t');
2330 $this->save_sessiondata();
2335 $this->t->set_file(array('ppi_view_t' => 'ppi_view.tpl'));
2336 $this->t->set_block('ppi_view_t','district_list','list');
2338 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2339 $num_months = get_var('num_months',array('GET','POST'));
2340 if($num_months == '') { $num_months = $this->default_ppi_num_months; }
2341 $this->t->set_var('num_months',$num_months);
2342 if($num_months == 1) {
2343 $this->t->set_var('lang_num_months','Month of History');
2345 $this->t->set_var('lang_num_months','Months of History');
2347 $this->t->set_var('lang_filter','Filter');
2348 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2350 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2351 $this->t->set_var('ppi_link_title','Yearly PPIs');
2353 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
2354 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
2356 $this->t->set_var('title','Yearly PPIs');
2357 $num_months = get_var('num_months',array('GET','POST'));
2358 if($num_months == '') { $num_months = $this->default_ppi_num_years; }
2359 $this->t->set_var('num_months',$num_months);
2360 if($num_months == 1) {
2361 $this->t->set_var('lang_num_months','Year of History');
2363 $this->t->set_var('lang_num_months','Years of History');
2366 $sql = "SELECT * FROM tc_presidency where president=1 and valid=1";
2367 $this->db->query($sql,__LINE__,__FILE__);
2368 if($this->db->next_record()) {
2369 $president_name = $this->db->f('name');
2370 $interviewer = $this->db->f('individual');
2371 $interview_type = 'ppi';
2373 print "<hr><font color=red><h3>-E- Unable to locate President in tc_presidency table</h3></font></hr>";
2376 $this->t->set_var('district_number','*');
2377 $this->t->set_var('district_name',$president_name);
2379 // TODO: changed this so it picks the quorum dynamically
2380 $sql = "SELECT * FROM tc_individual AS ti JOIN tc_scheduling_priority as tsp where ti.scheduling_priority=tsp.scheduling_priority and ti.steward='Elder' and ti.valid=1 ORDER BY ti.individual ASC";
2381 $this->db->query($sql,__LINE__,__FILE__);
2383 while ($this->db->next_record()) {
2384 $individual[$i] = $this->db->f('individual');
2385 $indiv_name[$i] = $this->db->f('name');
2386 $indiv_phone[$individual[$i]] = $this->db->f('phone');
2387 $indiv_priority[$individual[$i]] = $this->db->f('priority');
2388 $indiv_notes[$individual[$i]] = $this->db->f('notes');
2392 array_multisort($indiv_name, $individual);
2393 //var_dump($indiv_name); print "<br><br>"; var_dump($individual);
2395 $header_row="<th width=$comp_width><font size=-2>Individual Name</th>";
2397 $indiv_width=400; $ppi_width=75; $table_width=$indiv_width + $num_months*$ppi_width;
2399 for($m=$num_months; $m >= 0; $m--) {
2400 $year = date('Y') - $m;
2401 $header_row .= "<th width=150><font size=-2>$year</th>";
2405 for ($j=0; $j < count($individual); $j++) {
2406 $id = $individual[$j];
2407 $name = $indiv_name[$j];
2408 $phone = $indiv_phone[$id];
2410 $link_data['menuaction'] = 'tc.tc.ppi_update';
2411 $link_data['interviewer'] = $interviewer;
2412 $link_data['indiv'] = $id;
2413 $link_data['name'] = $name;
2414 $link_data['interview'] = '';
2415 $link_data['interview_type'] = $interview_type;
2416 $link_data['action'] = 'add';
2417 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2418 $this->nextmatchs->template_alternate_row_color(&$this->t);
2419 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2421 // Find out how many times PPIs were performed in the past $num_months for this individual
2422 for($m=$num_months; $m >= 0; $m--) {
2423 $year = date('Y') - $m;
2424 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2425 $sql = "SELECT * FROM tc_interview WHERE date > '$year_start' AND date < '$year_end' ".
2426 "AND individual=" . $id . " AND interview_type='ppi'";
2427 $this->db2->query($sql,__LINE__,__FILE__);
2429 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
2430 if($this->db2->next_record()) {
2431 $ppis[$m]++; $total_ppis[$m]++; $ppi_recorded[$companionship][$m]=1;
2432 $link_data['menuaction'] = 'tc.tc.ppi_update';
2433 $link_data['companionship'] = $companionship;
2434 $link_data['interviewer'] = $this->db2->f('interviewer');
2435 $link_data['indiv'] = $id;
2436 $link_data['name'] = $name;
2437 $link_data['interview'] = $this->db2->f('interview');
2438 $link_data['interview_type'] = $interview_type;
2439 $link_data['action'] = 'view';
2440 $date = $this->db2->f('date');
2441 $date_array = explode("-",$date);
2442 $month = $date_array[1];
2443 $day = $date_array[2];
2444 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2445 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2447 $table_data .= "<td> </td>";
2450 $table_data .= "</tr>\n";
2452 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2454 $stat_data = "<tr><td><b><font size=-2>$total_indivs Individuals<br>PPI Totals:</font></b></td>";
2455 for($m=$num_months; $m >=0; $m--) {
2456 $percent = ceil(($ppis[$m] / $total_indivs)*100);
2457 $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
2459 $stat_data .= "</tr>";
2461 $this->t->set_var('table_width',$table_width);
2462 $this->t->set_var('header_row',$header_row);
2463 $this->t->set_var('table_data',$table_data);
2464 $this->t->set_var('stat_data',$stat_data);
2465 $this->t->pfp('out','ppi_view_t');
2466 $this->save_sessiondata();
2469 function ppi_update()
2471 $this->t->set_file(array('form' => 'ppi_update.tpl'));
2472 $this->t->set_block('form','interviewer_list','int_list');
2473 $this->t->set_block('form','add','addhandle');
2474 $this->t->set_block('form','edit','edithandle');
2476 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2477 $this->t->set_var('readonly','');
2478 $this->t->set_var('disabled','');
2480 $action = get_var('action',array('GET','POST'));
2481 $companionship = get_var('companionship',array('GET','POST'));
2482 $interviewer = get_var('interviewer',array('GET','POST'));
2483 $name = get_var('name',array('GET','POST'));
2484 $interview = get_var('interview',array('GET','POST'));
2485 $indiv = get_var('indiv',array('GET','POST'));
2486 $date = get_var('date',array('GET','POST'));
2487 $notes = get_var('notes',array('GET','POST'));
2488 $interview_type = get_var('interview_type',array('GET','POST'));
2490 $sql = "SELECT * FROM tc_presidency where valid=1 and (president=1 or counselor=1 or secretary=1)";
2491 $this->db2->query($sql,__LINE__,__FILE__);
2492 while ($this->db2->next_record()) {
2493 $indiv = $this->db2->f('individual');
2494 $interviewer_name = $this->db2->f('name');
2495 if($indiv == $interviewer) {
2496 $this->t->set_var('interviewer',$interviewer . ' selected');
2498 $this->t->set_var('interviewer',$interviewer);
2500 $this->t->set_var('interviewer_name',$interviewer_name);
2501 $this->t->set_var('interview_type_checked','');
2502 $this->t->fp('int_list','interviewer_list',True);
2505 if($action == 'save') {
2506 $notes = get_var('notes',array('POST'));
2507 $this->db->query("UPDATE tc_interview set " .
2508 " interview='" . $interview . "'" .
2509 ", interviewer='" . $interviewer . "'" .
2510 ", individual='" . $indiv . "'" .
2511 ", date='" . $date . "'" .
2512 ", notes='" . $notes . "'" .
2513 ", interview_type='" . $interview_type . "'" .
2514 " WHERE interview=" . $interview,__LINE__,__FILE__);
2519 if($action == 'insert') {
2520 $notes = get_var('notes',array('POST'));
2521 $this->db->query("INSERT INTO tc_interview (interviewer,individual,date,notes,interview_type) " .
2522 "VALUES ('" . $interviewer . "','" . $indiv . "','" .
2523 $date . "','" . $notes . "','" . $interview_type ."')",__LINE__,__FILE__);
2528 if($action == 'add') {
2529 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2530 $this->t->set_var('interview', '');
2531 $this->t->set_var('interviewer', $interviewer);
2532 $this->t->set_var('name',$name);
2533 $this->t->set_var('indiv',$indiv);
2534 $this->t->set_var('date','');
2535 $this->t->set_var('notes','');
2536 $this->t->set_var('interview_type',$interview_type);
2537 $this->t->set_var('interview_type_checked','checked');
2538 $this->t->set_var('lang_done','Cancel');
2539 $this->t->set_var('lang_action','Adding New PPI');
2540 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview=' .
2541 $interview . '&action=' . 'insert'));
2544 if($action == 'edit' || $action == 'view') {
2545 $sql = "SELECT * FROM tc_interview WHERE interview=".$interview;
2546 $this->db->query($sql,__LINE__,__FILE__);
2547 $this->db->next_record();
2548 $this->t->set_var('interview',$interview);
2549 $this->t->set_var('name',$name);
2550 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2551 $this->t->set_var('indiv',$this->db->f('indiv'));
2552 $this->t->set_var('date',$this->db->f('date'));
2553 $this->t->set_var('notes',$this->db->f('notes'));
2554 $this->t->set_var('interview_type',$this->db->f('interview_type'));
2555 if($this->db->f('interview_type') == 1) { $this->t->set_var('interview_type_checked','checked'); }
2558 if($action == 'edit') {
2559 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2560 $this->t->set_var('lang_done','Cancel');
2561 $this->t->set_var('lang_action','Editing PPI');
2562 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview='.
2563 $interview . '&action=' . 'save'));
2566 if($action == 'view') {
2567 $date = $this->db->f('date');
2568 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2569 $this->t->set_var('readonly','READONLY');
2570 $this->t->set_var('disabled','DISABLED');
2571 $this->t->set_var('lang_done','Done');
2572 $this->t->set_var('lang_action','Viewing PPI');
2573 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview=' .
2574 $interview . '&action=' . 'edit'));
2577 $this->t->set_var('lang_reset','Clear Form');
2578 $this->t->set_var('lang_add','Add PPI');
2579 $this->t->set_var('lang_save','Save Changes');
2580 $this->t->set_var('edithandle','');
2581 $this->t->set_var('addhandle','');
2583 $this->t->pfp('out','form');
2585 if($action == 'view') { $this->t->set_var('lang_save','Edit PPI'); }
2586 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2587 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2589 $this->save_sessiondata();
2594 $this->t->set_file(array('int_view_t' => 'int_view.tpl'));
2595 $this->t->set_block('int_view_t','district_list','list');
2597 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2598 $num_quarters = get_var('num_quarters',array('GET','POST'));
2599 if($num_quarters == '') { $num_quarters = $this->default_int_num_quarters; }
2600 $this->t->set_var('num_quarters',$num_quarters);
2601 if($num_quarters == 1) {
2602 $this->t->set_var('lang_num_quarters','Quarter of History');
2604 $this->t->set_var('lang_num_quarters','Quarters of History');
2606 $this->t->set_var('lang_filter','Filter');
2608 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2609 $this->t->set_var('int_link_title','Hometeaching Interviews');
2611 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
2612 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
2614 $this->t->set_var('title','Hometeaching Interviews');
2616 $num_months = $num_quarters * 3 - 1;
2617 $current_month = $this->current_month;
2618 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
2619 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
2620 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
2621 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
2623 $sql = "SELECT * FROM tc_district where valid=1 ORDER BY district ASC";
2624 $this->db->query($sql,__LINE__,__FILE__);
2626 while ($this->db->next_record()) {
2627 $districts[$i]['district'] = $this->db->f('district');
2628 $districts[$i]['name'] = $this->db->f('name');
2629 $districts[$i]['supervisor'] = $this->db->f('supervisor');
2633 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
2634 $this->db->query($sql,__LINE__,__FILE__);
2636 while ($this->db->next_record()) {
2637 $individual[$i] = $this->db->f('individual');
2638 $indiv_name[$i] = $this->db->f('name');
2639 $indiv_phone[$individual[$i]] = $this->db->f('phone');
2642 array_multisort($indiv_name, $individual);
2643 for($i=0; $i < count($individual); $i++) {
2644 $id = $individual[$i];
2645 $indivs[$id] = $indiv_name[$i];
2648 $total_companionships = 0;
2649 $this->nextmatchs->template_alternate_row_color(&$this->t);
2650 for ($i=0; $i < count($districts); $i++) {
2651 $this->t->set_var('district_number',$districts[$i]['district']);
2652 $this->t->set_var('district_name',$districts[$i]['name']);
2653 $supervisor = $districts[$i]['supervisor'];
2655 // Select all the unique companionship numbers for this district
2656 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$i]['district'];
2657 $this->db->query($sql,__LINE__,__FILE__);
2658 $j=0; $unique_companionships = '';
2659 while ($this->db->next_record()) {
2660 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
2664 $comp_width=250; $int_width=75; $table_width=$comp_width + $num_months*$int_width;
2665 $table_data=""; $num_companionships = $j; $num_indivs = 0;
2666 for($m=$num_months; $m >= 0; $m--) { $ints[$m] = 0; }
2667 for ($j=0; $j < count($unique_companionships); $j++) {
2668 // Select all the companions in each companionship
2669 $sql = "SELECT * FROM tc_companionship where valid=1 and ".
2670 "companionship=". $unique_companionships[$j]['companionship'];
2671 $this->db->query($sql,__LINE__,__FILE__);
2673 $comp = $unique_companionships[$j]['companionship'];
2674 for($m=$num_months; $m >= 0; $m--) { $int_recorded[$comp][$m] = 0; }
2675 while ($this->db->next_record()) {
2676 // Get this companions information
2678 $companionship = $this->db->f('companionship');
2679 $individual = $this->db->f('individual');
2680 $name = $indivs[$individual];
2681 $phone = $indiv_phone[$individual];
2682 $link_data['menuaction'] = 'tc.tc.int_update';
2683 $link_data['companionship'] = $companionship;
2684 $link_data['interviewer'] = $supervisor;
2685 $link_data['indiv'] = $individual;
2686 $link_data['name'] = $name;
2687 $link_data['interview'] = '';
2688 $link_data['action'] = 'add';
2689 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2690 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2692 // Find out how many times Interviews were performed in the past $num_months for this individual
2693 $header_row="<th width=$comp_width><font size=-2>Companionship</th>";
2694 for($m=$num_months; $m >= 0; $m--) {
2695 $month = $current_month - $m;
2696 $year = $this->current_year;
2698 $remainder = $month;
2699 $month = 12 + $remainder;
2702 if($month < 10) { $month = "0"."$month"; }
2703 $month_start = "$year"."-"."$month"."-"."01";
2704 $month_end = "$year"."-"."$month"."-"."31";
2705 $month = "$month"."/"."$year";
2706 $sql = "SELECT * FROM tc_interview WHERE date >= '$month_start' AND date <= '$month_end' ".
2707 "AND individual=" . $individual;
2708 $this->db2->query($sql,__LINE__,__FILE__);
2709 $header_row .= "<th width=$int_width><font size=-2>$month</th>";
2711 if(!$total_ints[$m]) { $total_ints[$m] = 0; }
2712 if($this->db2->next_record()) {
2713 if(!$int_recorded[$companionship][$m]) {
2716 $int_recorded[$companionship][$m]=1;
2718 $link_data['menuaction'] = 'tc.tc.int_update';
2719 $link_data['companionship'] = $companionship;
2720 $link_data['interviewer'] = $this->db2->f('interviewer');
2721 $link_data['indiv'] = $individual;
2722 $link_data['name'] = $name;
2723 $link_data['interview'] = $this->db2->f('interview');
2724 $link_data['action'] = 'view';
2725 $date = $this->db2->f('date');
2726 $date_array = explode("-",$date);
2727 $month = $date_array[1];
2728 $day = $date_array[2];
2729 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2730 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2733 $table_data .= "<td> </td>";
2736 $table_data .= "</tr>";
2739 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2741 $total_companionships += $num_companionships;
2742 $stat_data = "<tr><td><b><font size=-2>$num_companionships Companionships<br>Interview Totals:</font></b></td>";
2744 // Print the hometeaching interview stats
2745 for($m=$num_months; $m >=0; $m--) {
2746 $month = $current_month - $m;
2747 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
2748 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
2749 //print "$month % $this->monthly_hometeaching_interview_stats = $month_begins <br>";
2750 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
2751 if(($month_begins) == 1) {
2754 $total += $ints[$m];
2756 $percent = ceil(($total / $num_companionships)*100);
2757 $stat_data .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
2759 $stat_data .= "</tr>";
2761 $this->t->set_var('table_width',$table_width);
2762 $this->t->set_var('header_row',$header_row);
2763 $this->t->set_var('table_data',$table_data);
2764 $this->t->set_var('stat_data',$stat_data);
2765 $this->t->fp('list','district_list',True);
2768 // Display the totals
2770 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>Interview Totals:</font></b></td>";
2771 for($m=$num_months; $m >=0; $m--) {
2772 $month = $current_month - $m;
2773 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
2774 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
2775 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
2776 if(($month_begins) == 1) {
2777 $total = $total_ints[$m];
2779 $total += $total_ints[$m];
2781 $percent = ceil(($total / $total_companionships)*100);
2782 $totals .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
2786 $this->t->set_var('totals',$totals);
2787 $this->t->pfp('out','int_view_t');
2788 $this->save_sessiondata();
2791 function int_update()
2793 $this->t->set_file(array('form' => 'int_update.tpl'));
2794 $this->t->set_block('form','interviewer_list','int_list');
2795 $this->t->set_block('form','add','addhandle');
2796 $this->t->set_block('form','edit','edithandle');
2798 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2799 $this->t->set_var('readonly','');
2800 $this->t->set_var('disabled','');
2801 $this->t->set_var('interview_type_checked','');
2803 $action = get_var('action',array('GET','POST'));
2804 $companionship = get_var('companionship',array('GET','POST'));
2805 $interviewer = get_var('interviewer',array('GET','POST'));
2806 $name = get_var('name',array('GET','POST'));
2807 $interview = get_var('interview',array('GET','POST'));
2808 $indiv = get_var('indiv',array('GET','POST'));
2809 $date = get_var('date',array('GET','POST'));
2810 $notes = get_var('notes',array('GET','POST'));
2811 $interview_type = get_var('interview_type',array('GET','POST'));
2813 $sql = "SELECT * FROM tc_presidency where valid=1 and (president=1 or counselor=1 or secretary=1 or district!=0)";
2814 $this->db2->query($sql,__LINE__,__FILE__);
2815 while ($this->db2->next_record()) {
2816 $indiv = $this->db2->f('individual');
2817 $interviewer_name = $this->db2->f('name');
2818 if($indiv == $interviewer) {
2819 $this->t->set_var('interviewer',$interviewer . ' selected');
2821 $this->t->set_var('interviewer',$interviewer);
2823 $this->t->set_var('interviewer_name',$interviewer_name);
2824 $this->t->fp('int_list','interviewer_list',True);
2827 if($action == 'save') {
2828 $notes = get_var('notes',array('POST'));
2829 $this->db->query("UPDATE tc_interview set " .
2830 " interview='" . $interview . "'" .
2831 ", interviewer='" . $interviewer . "'" .
2832 ", individual='" . $indiv . "'" .
2833 ", date='" . $date . "'" .
2834 ", notes='" . $notes . "'" .
2835 ", interview_type='" . $interview_type . "'" .
2836 " WHERE interview=" . $interview,__LINE__,__FILE__);
2841 if($action == 'insert') {
2842 $notes = get_var('notes',array('POST'));
2843 $this->db->query("INSERT INTO tc_interview (interviewer,individual,date,notes,interview_type) " .
2844 "VALUES ('" . $interviewer . "','" . $indiv . "','" .
2845 $date . "','" . $notes ."','" . $interview_type . "')",__LINE__,__FILE__);
2850 if($action == 'add') {
2851 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2852 $this->t->set_var('interview', '');
2853 $this->t->set_var('interviewer', $interviewer);
2854 $this->t->set_var('name',$name);
2855 $this->t->set_var('indiv',$indiv);
2856 $this->t->set_var('date','');
2857 $this->t->set_var('notes','');
2858 $this->t->set_var('lang_done','Cancel');
2859 $this->t->set_var('lang_action','Adding New Interview');
2860 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
2861 $interview . '&action=' . 'insert'));
2864 if($action == 'edit' || $action == 'view') {
2865 $sql = "SELECT * FROM tc_interview WHERE interview=".$interview;
2866 $this->db->query($sql,__LINE__,__FILE__);
2867 $this->db->next_record();
2868 $this->t->set_var('interview',$interview);
2869 $this->t->set_var('name',$name);
2870 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2871 $this->t->set_var('indiv',$this->db->f('individual'));
2872 $this->t->set_var('date',$this->db->f('date'));
2873 $this->t->set_var('notes',$this->db->f('notes'));
2874 if($this->db->f('interview_type') == 1) { $this->t->set_var('interview_type_checked','checked'); }
2877 if($action == 'edit') {
2878 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2879 $this->t->set_var('lang_done','Cancel');
2880 $this->t->set_var('lang_action','Editing Interview');
2881 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
2882 $interview . '&action=' . 'save'));
2885 if($action == 'view') {
2886 $date = $this->db->f('date');
2887 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2888 $this->t->set_var('readonly','READONLY');
2889 $this->t->set_var('disabled','DISABLED');
2890 $this->t->set_var('lang_done','Done');
2891 $this->t->set_var('lang_action','Viewing Interview');
2892 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
2893 $interview . '&action=' . 'edit'));
2896 $this->t->set_var('lang_reset','Clear Form');
2897 $this->t->set_var('lang_add','Add Interview');
2898 $this->t->set_var('lang_save','Save Changes');
2899 $this->t->set_var('edithandle','');
2900 $this->t->set_var('addhandle','');
2902 $this->t->pfp('out','form');
2904 if($action == 'view') { $this->t->set_var('lang_save','Edit Interview'); }
2905 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2906 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2908 $this->save_sessiondata();
2913 $this->t->set_file(array('vis_view_t' => 'vis_view.tpl'));
2914 $this->t->set_block('vis_view_t','visit_list','list1');
2915 $this->t->set_block('vis_view_t','family_list','list2');
2917 $this->t->set_var('lang_name','Family Name');
2918 $this->t->set_var('lang_date','Date');
2920 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2921 $this->t->set_var('vis_link_title','View Yearly Visits');
2923 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
2924 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2926 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2927 $num_years = get_var('num_years',array('GET','POST'));
2928 if($num_years == '') { $num_years = $this->default_vis_num_years; }
2929 $this->t->set_var('num_years',$num_years);
2930 if($num_years == 1) {
2931 $this->t->set_var('lang_num_years','Year of History');
2933 $this->t->set_var('lang_num_years','Years of History');
2935 $this->t->set_var('lang_filter','Filter');
2937 $year = date('Y') - $num_years + 1;
2938 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2940 $sql = "SELECT * FROM tc_visit WHERE companionship=0 and date > '$year_start' ORDER BY date DESC";
2941 $this->db->query($sql,__LINE__,__FILE__);
2942 $total_records = $this->db->num_rows();
2945 while ($this->db->next_record()) {
2946 $visit_list[$i]['visit'] = $this->db->f('visit');
2947 $visit_list[$i]['family'] = $this->db->f('family');
2948 $visit_list[$i]['date'] = $this->db->f('date');
2952 for ($i=0; $i < count($visit_list); $i++) {
2953 $this->nextmatchs->template_alternate_row_color(&$this->t);
2955 $sql = "SELECT * FROM tc_family AS tf JOIN tc_individual AS ti WHERE tf.individual=ti.individual AND tf.family=".$visit_list[$i]['family'];
2956 $this->db->query($sql,__LINE__,__FILE__);
2957 $this->db->next_record();
2959 $this->t->set_var('family',$visit_list[$i]['family']);
2960 $this->t->set_var('family_name',$this->db->f('name'));
2961 $this->t->set_var('date',$visit_list[$i]['date']);
2963 $link_data['menuaction'] = 'tc.tc.vis_update';
2964 $link_data['visit'] = $visit_list[$i]['visit'];
2965 $link_data['name'] = $this->db->f('name');
2966 $link_data['date'] = $visit_list[$i]['date'];
2967 $link_data['action'] = 'view';
2968 $this->t->set_var('view',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
2969 $this->t->set_var('lang_view','View');
2971 $link_data['menuaction'] = 'tc.tc.vis_update';
2972 $link_data['visit'] = $visit_list[$i]['visit'];
2973 $link_data['name'] = $this->db->f('name');
2974 $link_data['date'] = $visit_list[$i]['date'];
2975 $link_data['action'] = 'edit';
2976 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
2977 $this->t->set_var('lang_edit','Edit');
2979 $this->t->fp('list1','visit_list',True);
2982 // List the families that are available to record a visit against
2983 $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";
2984 $this->db->query($sql,__LINE__,__FILE__);
2985 $total_records = $this->db->num_rows();
2988 while ($this->db->next_record()) {
2989 $family_names[$i] = $this->db->f('name');
2990 $family_ids[$i] = $this->db->f('family');
2992 } array_multisort($family_names, $family_ids);
2994 for ($i=0; $i < count($family_names); $i++) {
2995 $link_data['menuaction'] = 'tc.tc.vis_update';
2996 $link_data['visit'] = '';
2997 $link_data['family'] = $family_ids[$i];
2998 $link_data['action'] = 'add';
2999 $link_data['name'] = $family_names[$i];
3000 $this->t->set_var('add',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3002 $this->t->set_var('name',$family_names[$i]);
3003 if(($i+1) % 3 == 0) {
3004 $this->t->set_var('table_sep',"</td></tr><tr>");
3006 $this->t->set_var('table_sep',"</td>");
3008 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
3010 $this->t->fp('list2','family_list',True);
3013 $this->t->pfp('out','vis_view_t');
3014 $this->save_sessiondata();
3017 function vis_update()
3019 $this->t->set_file(array('form' => 'vis_update.tpl'));
3020 $this->t->set_block('form','add','addhandle');
3021 $this->t->set_block('form','edit','edithandle');
3023 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
3024 $this->t->set_var('readonly','');
3025 $this->t->set_var('disabled','');
3027 $action = get_var('action',array('GET','POST'));
3028 $visit = get_var('visit',array('GET','POST'));
3029 $family = get_var('family',array('GET','POST'));
3030 $name = get_var('name',array('GET','POST'));
3031 $date = get_var('date',array('GET','POST'));
3032 $notes = get_var('notes',array('GET','POST'));
3035 if($action == 'save') {
3036 $notes = get_var('notes',array('POST'));
3037 $this->db->query("UPDATE tc_visit set " .
3038 " date='" . $date . "'" .
3039 ", notes='" . $notes . "'" .
3040 " WHERE visit=" . $visit,__LINE__,__FILE__);
3045 if($action == 'insert') {
3046 $notes = get_var('notes',array('POST'));
3047 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes) " .
3048 "VALUES ('" . $family . "','" . $companionship . "','" .
3049 $date . "','" . $notes . "')",__LINE__,__FILE__);
3054 if($action == 'add') {
3055 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
3056 $this->t->set_var('family', $family);
3057 $this->t->set_var('visit', '');
3058 $this->t->set_var('name', $name);
3059 $this->t->set_var('date','');
3060 $this->t->set_var('notes','');
3061 $this->t->set_var('lang_done','Cancel');
3062 $this->t->set_var('lang_action','Adding New Visit');
3063 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&family=' .
3064 $family . '&action=' . 'insert'));
3067 if($action == 'edit' || $action == 'view') {
3068 $sql = "SELECT * FROM tc_visit WHERE visit=".$visit;
3069 $this->db->query($sql,__LINE__,__FILE__);
3070 $this->db->next_record();
3071 $this->t->set_var('visit',$visit);
3072 $this->t->set_var('name',$name);
3073 $this->t->set_var('family', $family);
3074 $this->t->set_var('date',$this->db->f('date'));
3075 $this->t->set_var('notes',$this->db->f('notes'));
3078 if($action == 'edit') {
3079 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
3080 $this->t->set_var('lang_done','Cancel');
3081 $this->t->set_var('lang_action','Editing Visit');
3082 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit=' .
3083 $visit . '&action=' . 'save'));
3086 if($action == 'view') {
3087 $date = $this->db->f('date');
3088 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
3089 $this->t->set_var('readonly','READONLY');
3090 $this->t->set_var('disabled','DISABLED');
3091 $this->t->set_var('lang_done','Done');
3092 $this->t->set_var('lang_action','Viewing Visit');
3093 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit=' .
3094 $visit . '&action=' . 'edit'));
3097 $this->t->set_var('lang_reset','Clear Form');
3098 $this->t->set_var('lang_add','Add Visit');
3099 $this->t->set_var('lang_save','Save Changes');
3100 $this->t->set_var('edithandle','');
3101 $this->t->set_var('addhandle','');
3103 $this->t->pfp('out','form');
3105 if($action == 'view') { $this->t->set_var('lang_save','Edit Visit'); }
3106 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
3107 if($action == 'add') { $this->t->pfp('addhandle','add'); }
3109 $this->save_sessiondata();
3114 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3115 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3116 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3118 $this->t->set_file(array('att_view_t' => 'att_view.tpl'));
3119 $this->t->set_block('att_view_t','act_list','list');
3121 $this->t->set_block('att_view_t','month_list','list1');
3122 $this->t->set_block('att_view_t','header_list','list2');
3123 $this->t->set_block('att_view_t','individual_list','list3');
3125 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3126 $num_quarters = get_var('num_quarters',array('GET','POST'));
3127 if($num_quarters == '') { $num_quarters = $this->default_att_num_quarters; }
3128 $this->t->set_var('num_quarters',$num_quarters);
3129 $this->t->set_var('lang_filter','Filter');
3130 if($num_quarters == 1) {
3131 $this->t->set_var('lang_num_quarters','Quarter of History');
3133 $this->t->set_var('lang_num_quarters','Quarters of History');
3136 $num_months = $num_quarters * 3;
3137 $current_month = $this->current_month;
3138 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
3139 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
3140 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
3141 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
3143 // TODO: changed this so it picks the quorum dynamically
3144 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1";
3145 $this->db->query($sql,__LINE__,__FILE__);
3147 while ($this->db->next_record()) {
3148 $individual_name[$i] = $this->db->f('name');
3149 $individual[$i] = $this->db->f('individual');
3152 array_multisort($individual_name, $individual);
3154 // Create a list of sunday dates for a window of 3 months back and current month
3158 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, ($current_month-$num_months)+1, 1, date("y")));
3159 $last_date = explode("-",$sunday_list[0]['date']);
3160 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3161 $time_limit = mktime(0, 0, 0, $current_month, 31, date("y"));
3162 while($last_time < $time_limit) {
3163 $day = date("w",$last_time);
3164 if(date("w",$last_time) == 0) {
3165 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3166 $last_date = explode("-",$sunday_list[$i]['date']);
3167 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3168 $sunday_list[$i]['day'] = $last_date[2];
3169 $sunday_list[$i]['month'] = date("M",$last_time);
3170 $sunday_list[$i]['year'] = $last_date[0];
3172 $last_date = $sunday_list[$i]['date'];
3174 $last_time += 90000;
3175 if($found_sunday) { $i++; $found_sunday=0; }
3178 $total_individuals = count($individual);
3179 $old_month=$sunday_list[0]['month']; $span=0;
3180 for ($i=0; $i < count($sunday_list); $i++) {
3181 $date = $sunday_list[$i]['date'];
3182 $this->t->set_var('date',$sunday_list[$i]['date']);
3183 $this->t->set_var('day',$sunday_list[$i]['day']);
3184 if(($old_month != $sunday_list[$i]['month']) || $i == count($sunday_list)-1) {
3185 if($i == count($sunday_list)-1) { $span++; }
3186 $cur_month = $sunday_list[$i]['month'];
3187 $old_month = $sunday_list[$i]['month'];
3188 $link_data['menuaction'] = 'tc.tc.att_update';
3189 $link_data['month'] = $sunday_list[$i-1]['month'];
3190 $link_data['year'] = $sunday_list[$i-1]['year'];
3191 $link_data['action'] = 'update_month';
3192 $cur_month = $sunday_list[$i-1]['month'];
3193 $cur_year = $sunday_list[$i-1]['year'];
3194 $header_row .= "<th><font size=-3>$cur_month $cur_year</font></th>";
3195 $this->t->set_var('update_month',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3196 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3197 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3198 $this->t->set_var('span',$span); $span=0;
3199 $this->t->fp('list1','month_list',True);
3203 $this->t->set_var('total_individuals',$total_individuals);
3204 $this->t->set_var('header_row',$header_row);
3206 $individual_width=200; $att_width=25; $total_width=$individual_width;
3207 for ($i=0; $i < count($sunday_list); $i++) {
3208 $link_data['menuaction'] = 'tc.tc.att_update';
3209 $link_data['month'] = $sunday_list[$i]['month'];
3210 $link_data['year'] = $sunday_list[$i]['year'];
3211 $link_data['day'] = $sunday_list[$i]['day'];
3212 $link_data['date'] = $sunday_list[$i]['date'];
3213 $link_data['action'] = 'update_day';
3214 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3215 $this->t->set_var('date',$sunday_list[$i]['date']);
3216 $this->t->set_var('day',$sunday_list[$i]['day']);
3217 $this->t->set_var('month',$sunday_list[$i]['month']);
3218 $this->t->set_var('year',$sunday_list[$i]['year']);
3219 $this->t->fp('list2','header_list',True);
3220 $total_width += $att_width;
3221 $attendance[$monthnum[$sunday_list[$i]['month']]]=0;
3224 for ($i=0; $i < count($individual); $i++) {
3226 $this->nextmatchs->template_alternate_row_color(&$this->t);
3227 $this->t->set_var('individual_name',$individual_name[$i]);
3228 #print "checking for individual: " . $individual[$i] . "<br>";
3229 for ($j=0; $j < count($sunday_list); $j++) {
3230 #print "checking for date: " . $sunday_list[$j]['date'] . "<br>";
3231 #print "SELECT * FROM tc_attendance WHERE date='"
3232 # . $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i] . "<br>";
3233 $sql = "SELECT * FROM tc_attendance WHERE date='" .
3234 $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i];
3235 $this->db->query($sql,__LINE__,__FILE__);
3236 if($this->db->next_record()) {
3237 $cur_month = $sunday_list[$j]['month'];
3238 if($attended[$i][$cur_month] != 1) {
3239 $attended[$i][$cur_month]=1;
3240 $attendance[$monthnum[$cur_month]]++;
3242 $att_table .= '<td align=center><img src="images/checkmark.gif"></td>';
3244 $att_table .= '<td> </td>';
3247 $this->t->set_var('att_table',$att_table);
3248 $this->t->fp('list3','individual_list',True);
3250 $this->t->set_var('total_width',$total_width);
3251 $this->t->set_var('individual_width',$individual_width);
3252 $this->t->set_var('att_width',$att_width);
3254 # Now calculate attendance for these months
3255 $attendance_str = "";
3256 $nonattendance_str = "";
3257 $aveattendance_str = "";
3258 $avenonattendance_str = "";
3260 $ave_total_attended=0;
3262 foreach($attendance as $att => $value) {
3263 $total_attended = $attendance[$att];
3264 $ave_total_attended += $attendance[$att]; $num_months++;
3265 $percent = ceil(($total_attended / $total_individuals)*100);
3266 $attendance_str.="<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3267 $total_nonattended = $total_individuals - $total_attended;
3268 $percent = ceil(($total_nonattended / $total_individuals)*100);
3269 $nonattendance_str.="<td align=center><font size=-2><b>$total_nonattended ($percent%)</b></font></td>";
3271 $total_attended = ceil(($ave_total_attended / $num_months));
3272 $percent = ceil(($total_attended / $total_individuals)*100);
3273 $aveattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3274 $total_attended = $total_individuals - ceil(($ave_total_attended / $num_months));
3275 $percent = ceil(($total_attended / $total_individuals)*100);
3276 $avenonattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3279 $this->t->set_var('attendance',$attendance_str);
3280 $this->t->set_var('aveattendance',$aveattendance_str);
3281 $this->t->set_var('nonattendance',$nonattendance_str);
3282 $this->t->set_var('avenonattendance',$avenonattendance_str);
3284 $this->t->pfp('out','att_view_t');
3285 $this->save_sessiondata();
3288 function att_update()
3290 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3291 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3292 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3294 $this->t->set_file(array('form' => 'att_update.tpl'));
3295 $this->t->set_block('form','edit','edithandle');
3297 $this->t->set_block('form','month_list','list1');
3298 $this->t->set_block('form','header_list','list2');
3299 $this->t->set_block('form','individual_list','list3');
3301 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3303 $action = get_var('action',array('GET','POST'));
3304 $month = get_var('month',array('GET','POST'));
3305 $year = get_var('year',array('GET','POST'));
3306 $day = get_var('day',array('GET','POST'));
3307 $date = get_var('date',array('GET','POST'));
3309 if($action == 'save_month' || $action == 'save_day') {
3310 $new_data = get_var('individuals_attended',array('POST'));
3311 $month = $monthnum[$month]; if($month < 10) { $month = "0" . $month; }
3313 if($action == 'save_month') {
3314 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-%'",__LINE__,__FILE__);
3317 if($action == 'save_day') {
3318 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-".$day."'",__LINE__,__FILE__);
3321 foreach ($new_data as $data) {
3322 $data_array = explode("-",$data);
3323 $indiv = $data_array[0];
3324 $date = "$data_array[1]-$data_array[2]-$data_array[3]";
3325 $this->db->query("INSERT INTO tc_attendance (individual,date) " .
3326 "VALUES (" . $indiv . ",'". $date . "')",__LINE__,__FILE__);
3333 // TODO: changed this so it picks the quorum dynamically
3334 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1";
3335 $this->db->query($sql,__LINE__,__FILE__);
3337 while ($this->db->next_record()) {
3338 $indiv_name[$i] = $this->db->f('name');
3339 $individual[$i] = $this->db->f('individual');
3340 $indiv_attending[$individual[$i]] = $this->db->f('attending');
3343 array_multisort($indiv_name, $individual);
3345 if($action == 'update_month') {
3346 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_month'));
3350 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], 1, $year));
3351 $last_date = explode("-",$sunday_list[0]['date']);
3352 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3353 $time_limit = mktime(0, 0, 0, $monthnum[$month], 31, $year);
3354 while($last_time <= $time_limit) {
3355 $day = date("w",$last_time);
3356 if(date("w",$last_time) == 0) {
3357 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3358 $last_date = explode("-",$sunday_list[$i]['date']);
3359 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3360 $sunday_list[$i]['day'] = $last_date[2];
3361 $sunday_list[$i]['month'] = date("M",$last_time);
3362 $sunday_list[$i]['year'] = $last_date[0];
3365 $last_time += 90000;
3366 if($found_sunday) { $i++; $found_sunday=0; }
3369 $this->t->set_var('span', $i);
3370 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3371 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3372 $this->t->fp('list1','month_list',True);
3373 $indiv_width=200; $att_width=25; $total_width=$indiv_width;
3374 for ($i=0; $i < count($sunday_list); $i++) {
3375 $link_data['menuaction'] = 'tc.tc.att_update';
3376 $link_data['month'] = $sunday_list[$i]['month'];
3377 $link_data['year'] = $sunday_list[$i]['year'];
3378 $link_data['day'] = $sunday_list[$i]['day'];
3379 $link_data['date'] = $sunday_list[$i]['date'];
3380 $link_data['action'] = 'update_day';
3381 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3382 $this->t->set_var('date',$sunday_list[$i]['date']);
3383 $this->t->set_var('day',$sunday_list[$i]['day']);
3384 $this->t->set_var('month',$sunday_list[$i]['month']);
3385 $this->t->set_var('year',$sunday_list[$i]['year']);
3386 $this->t->fp('list2','header_list',True);
3387 $total_width += $att_width;
3391 if($action == 'update_day') {
3392 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_day'));
3393 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], $day, $year));
3394 $this->t->set_var('month',$month);
3395 $this->t->set_var('year',$year);
3396 $this->t->fp('list1','month_list',True);
3397 $this->t->set_var('date',$date);
3398 $this->t->set_var('day',$day);
3399 $this->t->set_var('month',$month);
3400 $this->t->set_var('year',$year);
3401 $this->t->fp('list2','header_list',True);
3404 for ($i=0; $i < count($individual); $i++) {
3406 $this->nextmatchs->template_alternate_row_color(&$this->t);
3407 $this->t->set_var('individual_name',$indiv_name[$i]);
3408 for ($j=0; $j < count($sunday_list); $j++) {
3409 $sql = "SELECT * FROM tc_attendance WHERE date='" .
3410 $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i];
3411 $this->db->query($sql,__LINE__,__FILE__);
3412 $value = $individual[$i] . "-" . $sunday_list[$j]['date'];
3413 if($this->db->next_record()) {
3414 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'" checked></td>';
3415 } else if($indiv_attending[$individual[$i]] == 1) {
3416 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'" checked></td>';
3418 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'"></td>';
3421 $this->t->set_var('att_table',$att_table);
3422 $this->t->fp('list3','individual_list',True);
3425 $this->t->set_var('lang_done', 'Cancel');
3426 $this->t->set_var('lang_reset','Clear Form');
3427 $this->t->set_var('lang_save','Save Changes');
3429 $this->t->pfp('out','form');
3430 $this->t->pfp('addhandle','edit');
3432 $this->save_sessiondata();
3437 $this->t->set_file(array('dir_view_t' => 'dir_view.tpl'));
3438 $this->t->set_block('dir_view_t','dir_list','list');
3440 $sql = "SELECT * FROM tc_individual where valid=1 and hh_position='Head of Household' ORDER BY name ASC";
3441 $this->db->query($sql,__LINE__,__FILE__);
3443 while ($this->db->next_record()) {
3444 $parent[$i]['id'] = $this->db->f('individual');
3445 $parent[$i]['name'] = $this->db->f('name');
3446 $parent[$i]['phone'] = $this->db->f('phone');
3447 $parent[$i]['address'] = $this->db->f('address');
3451 for ($i=0; $i < count($parent); $i++) {
3452 $name = $parent[$i]['name'];
3453 $phone = $parent[$i]['phone'];
3454 $address = $parent[$i]['address'];
3455 $this->t->set_var('name', $name);
3456 $this->t->set_var('address', $address);
3457 $this->t->set_var('phone', $phone);
3458 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3459 $this->t->set_var('tr_color',$tr_color);
3460 $this->t->fp('list','dir_list',True);
3461 //print "$phone $name $address<br>";
3463 $this->t->pfp('out','dir_view_t');
3464 $this->save_sessiondata();
3469 $this->t->set_file(array('org_view_t' => 'org_view.tpl'));
3470 $this->t->set_block('org_view_t','calling_list','list1');
3471 $this->t->set_block('org_view_t','org_list','list2');
3473 # Display a list ordered alphabetically
3474 $sql = "SELECT * FROM tc_calling ORDER BY name ASC";
3475 $this->db->query($sql,__LINE__,__FILE__);
3477 while ($this->db->next_record()) {
3478 $calling[$i]['name'] = $this->db->f('name');
3479 $calling[$i]['position'] = $this->db->f('position');
3480 $calling[$i]['sustained'] = $this->db->f('sustained');
3481 $calling[$i]['organization'] = $this->db->f('organization');
3484 for ($i=0; $i < count($calling); $i++) {
3485 $name = $calling[$i]['name'];
3486 $position = $calling[$i]['position'];
3487 $sustained = $calling[$i]['sustained'];
3488 $organization = $calling[$i]['organization'];
3489 $this->t->set_var('name', $name);
3490 $this->t->set_var('position', $position);
3491 $this->t->set_var('sustained', $sustained);
3492 $this->t->set_var('organization', $organization);
3493 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3494 $this->t->set_var('tr_color',$tr_color);
3495 $this->t->fp('list1','calling_list',True);
3498 # Display a list ordered by organization
3499 $sql = "SELECT * FROM tc_calling ORDER BY organization ASC";
3500 $this->db->query($sql,__LINE__,__FILE__);
3502 while ($this->db->next_record()) {
3503 $calling[$i]['name'] = $this->db->f('name');
3504 $calling[$i]['position'] = $this->db->f('position');
3505 $calling[$i]['sustained'] = $this->db->f('sustained');
3506 $calling[$i]['organization'] = $this->db->f('organization');
3509 for ($i=0; $i < count($calling); $i++) {
3510 $name = $calling[$i]['name'];
3511 $position = $calling[$i]['position'];
3512 $sustained = $calling[$i]['sustained'];
3513 $organization = $calling[$i]['organization'];
3514 $this->t->set_var('name', $name);
3515 $this->t->set_var('position', $position);
3516 $this->t->set_var('sustained', $sustained);
3517 $this->t->set_var('organization', $organization);
3518 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3519 $this->t->set_var('tr_color',$tr_color);
3520 $this->t->fp('list2','org_list',True);
3523 $this->t->pfp('out','org_view_t');
3524 $this->save_sessiondata();
3529 $this->t->set_file(array('sched_t' => 'schedule.tpl'));
3530 $this->t->set_block('sched_t','presidency_list','list');
3532 $action = get_var('action',array('GET','POST'));
3534 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule&action=save'));
3535 $this->t->set_var('title','Scheduling Tool');
3537 $this->t->set_var('lang_save','Save Schedule');
3538 $this->t->set_var('lang_reset','Cancel');
3540 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
3541 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
3543 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
3544 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
3546 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
3547 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
3549 $date_width=150; $time_width=220; $indiv_width=170; $family_width=180; $location_width=100;
3550 $table_width=$date_width + $time_width + $indiv_width + $family_width + $location_width;
3551 $header_row = "<th width=$date_width><font size=-2>Date</th>";
3552 $header_row.= "<th width=$time_width><font size=-2>Time</th>";
3553 $header_row.= "<th width=$indiv_width><font size=-2>individual</th>";
3554 $header_row.= "<th width=$family_width><font size=-2>Family</th>";
3555 $header_row.= "<th width=$location_width><font size=-2>Location</th>";
3558 $sql = "SELECT * FROM tc_presidency where valid=1 GROUP BY individual ORDER BY name ASC";
3559 $this->db->query($sql,__LINE__,__FILE__);
3561 while ($this->db->next_record()) {
3562 $presidency_data[$i]['id'] = $this->db->f('presidency');
3563 $presidency_data[$i]['name'] = $this->db->f('name');
3564 $presidency_data[$i]['indiv'] = $this->db->f('individual');
3565 $presidency2name[$presidency_data[$i]['id']] = $presidency_data[$i]['name'];
3566 $presidency2indiv[$presidency_data[$i]['id']] = $presidency_data[$i]['individual'];
3570 $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 ORDER BY ti.name ASC";
3571 $this->db->query($sql,__LINE__,__FILE__);
3573 while ($this->db->next_record()) {
3574 $family_id[$i] = $this->db->f('family');
3575 $family_name[$i] = $this->db->f('name');
3576 $familyid2name[$family_id[$i]] = $family_name[$i];
3577 $familyid2address[$family_id[$i]] = $this->db->f('address');
3580 array_multisort($family_name, $family_id);
3582 if($action == 'save') {
3583 $new_data = get_var('sched',array('POST'));
3584 foreach ($new_data as $presidency_array) {
3585 foreach ($presidency_array as $entry) {
3586 $presidency = $entry['presidency'];
3587 $appointment = $entry['appointment'];
3588 $location = $entry['location'];
3589 $date = $entry['date'];
3590 $hour = $entry['hour'];
3591 $minute = $entry['minute'];
3593 $indiv = $entry['individual'];
3594 $family = $entry['family'];
3595 $location = $entry['location'];
3596 if($pm) { $hour = $hour + 12; }
3597 $time = $hour.':'.$minute.':'.'00';
3600 // Update our location
3601 if($location == "") {
3603 $family_name_array = explode(",", $familyid2name[$family]);
3604 $family_last_name = $family_name_array[0];
3605 $family_address = $familyid2address[$family];
3606 $location = "$family_last_name"." home ($family_address)";
3607 } else if($indiv > 0) {
3608 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
3609 $supervisor_last_name = $supervisor_name_array[0];
3610 $sql = "SELECT * FROM tc_individual where individual='$presidency2indiv[$presidency]'";
3611 $this->db2->query($sql,__LINE__,__FILE__);
3612 if($this->db2->next_record()) {
3613 $mls_id = $this->db2->f('mls_id');
3615 $sql = "SELECT * FROM tc_individual where mls_id='$mls_id'";
3616 $this->db2->query($sql,__LINE__,__FILE__);
3617 if($this->db2->next_record()) {
3618 $supervisor_address = $this->db2->f('address');
3620 $location = "$supervisor_last_name"." home ($supervisor_address)";
3624 // Zero out the family or individual if date = NULL
3631 if(($indiv == 0) && ($family == 0)) { $location = ""; }
3633 // Update an existing appointment
3634 if($appointment < $this->max_appointments)
3636 //Only perform a database update if we have made a change to this appointment
3637 $sql = "SELECT * FROM tc_appointment where " .
3638 "appointment='$appointment'" .
3639 " and presidency='$presidency'" .
3640 " and individual='$indiv'" .
3641 " and family='$family'" .
3642 " and date='$date'" .
3643 " and time='$time'" .
3644 " and location='$location'";
3645 $this->db->query($sql,__LINE__,__FILE__);
3646 if(!$this->db->next_record()) {
3647 $old_date = $this->db->f('date');
3648 $old_time = $this->db->f('time');
3649 $this->db2->query("UPDATE tc_appointment set" .
3650 " family=" . $family .
3651 " ,individual=" . $indiv .
3652 " ,date='" . $date . "'" .
3653 " ,time='" . $time . "'" .
3654 " ,location='" . $location . "'" .
3655 " ,presidency='" . $presidency . "'" .
3656 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
3658 // Email the appointment
3659 $this->email_appt($appointment);
3663 // Add a new appointment
3664 else if(($appointment >= $this->max_appointments) && ($date != "") && ($time != ""))
3666 //print "adding entry: appt=$appointment date: $date time: $time individual: $indiv family: $family<br>";
3667 $this->db2->query("INSERT INTO tc_appointment (appointment,presidency,family,individual,date,time,location,uid) " .
3668 "VALUES (NULL,'" . $presidency . "','" . $family . "','" . $indiv . "','" .
3669 $date . "','" . $time . "','" . $location . "','" . $uid ."')",__LINE__,__FILE__);
3671 // Now reselect this entry from the database to see if we need
3672 // to send an appointment out for it.
3673 $sql = "SELECT * FROM tc_appointment where " .
3674 "individual='$indiv'" .
3675 " and family='$family'" .
3676 " and presidency='$presidency'" .
3677 " and date='$date'" .
3678 " and time='$time'" .
3680 " and location='$location'";
3681 $this->db3->query($sql,__LINE__,__FILE__);
3682 if($this->db3->next_record()) {
3683 // Email the appointment if warranted
3684 if(($date != "") && ($time != "") && (($indiv > 0) || $family > 0)) {
3685 $this->email_appt($this->db3->f('appointment'));
3692 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule');
3693 //Header('Location: ' . $take_me_to_url);
3696 // TODO: changed this so it picks the quorum dynamically
3697 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1 ORDER BY individual ASC";
3698 $this->db->query($sql,__LINE__,__FILE__);
3700 while ($this->db->next_record()) {
3701 $individual[$i] = $this->db->f('individual');
3702 $indiv_name[$i] = $this->db->f('name');
3703 $indiv_phone[$individual[$i]] = $this->db->f('phone');
3706 array_multisort($indiv_name, $individual);
3708 for ($i=0; $i < count($presidency_data); $i++) {
3709 $presidency = $presidency_data[$i]['id'];
3710 $interviewer = $presidency_data[$i]['individual'];
3711 $name = $presidency_data[$i]['name'];
3712 $this->t->set_var('presidency_name',$name);
3715 // query the database for all the appointments
3716 $sql = "SELECT * FROM tc_appointment where presidency=$presidency and date>=CURDATE() ORDER BY date ASC, time ASC";
3717 $this->db->query($sql,__LINE__,__FILE__);
3719 // Prefill any existing appointment slots
3720 while ($this->db->next_record()) {
3721 $appointment = $this->db->f('appointment');
3722 $indiv = $this->db->f('individual');
3723 $family = $this->db->f('family');
3724 $location = $this->db->f('location');
3726 if($location == "") {
3728 $family_name_array = explode(",", $familyid2name[$family]);
3729 $family_last_name = $family_name_array[0];
3730 $family_address = $familyid2address[$family];
3731 $location = "$family_last_name"." home ($family_address)";
3732 } else if($indiv > 0) {
3733 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
3734 $supervisor_last_name = $supervisor_name_array[0];
3735 $sql = "SELECT * FROM tc_individual where individual='$presidency2indiv[$presidency]'";
3736 $this->db2->query($sql,__LINE__,__FILE__);
3737 if($this->db2->next_record()) {
3738 $mls_id = $this->db2->f('mls_id');
3740 $sql = "SELECT * FROM tc_individual where mls_id='$mls_id'";
3741 $this->db2->query($sql,__LINE__,__FILE__);
3742 if($this->db2->next_record()) {
3743 $supervisor_address = $this->db2->f('address');
3745 $location = "$supervisor_last_name"." home ($supervisor_address)";
3749 $date = $this->db->f('date');
3750 $date_array = explode("-",$date);
3751 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
3752 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
3754 $time = $this->db->f('time');
3755 $time_array = explode(":",$time);
3756 $hour = $time_array[0];
3757 $minute = $time_array[1];
3759 if($hour > 12) { $pm=1; $hour = $hour - 12; }
3760 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
3762 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3765 $table_data.= '<td align=left>';
3766 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]',$date,'','','','','',$this->cal_options);
3767 $table_data.= '</td>';
3769 // Hour & Minutes selection
3770 $table_data.= "<td align=center>";
3771 $table_data .= $this->get_time_selection_form($hour, $minute, $pm, $presidency, $appointment);
3772 $table_data.= "</td>";
3774 // individual drop down list (for PPIs)
3775 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][indiv] STYLE="font-size : 8pt">';
3776 $table_data.= '<option value=0></option>';
3777 for ($j=0; $j < count($individual); $j++) {
3778 $id = $individual[$j];
3779 $name = $indiv_name[$j];
3780 if($individual[$j] == $indiv) {
3781 $selected[$id] = 'selected="selected"';
3783 $selected[$id] = '';
3785 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
3787 $table_data.='</select></td>';
3789 // Family drop down list (for Visits)
3790 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family] STYLE="font-size : 8pt">';
3791 $table_data.= '<option value=0></option>';
3792 for ($j=0; $j < count($individual); $j++) {
3793 $id = $family_id[$j];
3794 $name = $family_name[$j];
3795 if($family_id[$j] == $family) {
3796 $selected[$id] = 'selected="selected"';
3798 $selected[$id] = '';
3800 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
3802 $table_data.='</select></td>';
3804 // Location text box
3805 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
3806 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="'.$location.'" STYLE="font-size : 8pt">';
3808 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3809 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3811 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3812 $this->t->set_var('tr_color',$tr_color);
3815 // Create blank appointment slot
3816 for ($b=0; $b < 4; $b++) {
3817 $appointment = $this->max_appointments + $b;
3818 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3821 $table_data.= '<td align=left>';
3822 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]','','','','','','',$this->cal_options);
3823 $table_data.= '</td>';
3826 $table_data.= "<td align=center>";
3827 $table_data .= $this->get_time_selection_form(0, 0, 0, $presidency, $appointment);
3828 $table_data.= "</td>";
3830 // individual drop down list
3831 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][indiv] STYLE="font-size : 8pt">';
3832 $table_data.= '<option value=0></option>';
3833 for ($j=0; $j < count($individual); $j++) {
3834 $id = $individual[$j];
3835 $name = $indiv_name[$j];
3836 $table_data.= '<option value='.$id.'>'.$name.'</option>';
3838 $table_data.='</select></td>';
3840 // Family drop down list
3841 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family] STYLE="font-size : 8pt">';
3842 $table_data.= '<option value=0></option>';
3843 for ($j=0; $j < count($individual); $j++) {
3844 $id = $family_id[$j];
3845 $name = $family_name[$j];
3846 $table_data.= '<option value='.$id.'>'.$name.' Family</option>';
3848 $table_data.='</select></td>';
3850 // Location text box
3851 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
3852 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="" STYLE="font-size : 8pt">';
3854 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3855 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3857 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3858 $this->t->set_var('tr_color',$tr_color);
3861 $this->t->set_var('table_data',$table_data);
3862 $this->t->set_var('header_row',$header_row);
3863 $this->t->set_var('table_width',$table_width);
3864 $this->t->fp('list','presidency_list',True);
3867 $this->t->pfp('out','sched_t');
3868 $this->save_sessiondata();
3873 $this->t->set_file(array('email_t' => 'email.tpl'));
3874 $this->t->set_block('email_t','individual_list','list');
3876 $action = get_var('action',array('GET','POST'));
3878 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email'));
3879 $this->t->set_var('title','Email Tool');
3881 $this->t->set_var('lang_email','Send Email');
3882 $this->t->set_var('lang_reset','Cancel');
3884 $this->t->set_var('email_member_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=member'));
3885 $this->t->set_var('email_member_link_title','Email Quorum Member');
3887 $this->t->set_var('email_quorum_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=quorum'));
3888 $this->t->set_var('email_quorum_link_title','Email Quorum');
3890 $this->t->set_var('email_reminder_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=reminder'));
3891 $this->t->set_var('email_reminder_link_title','Email Reminders');
3893 $this->t->set_var('email_edit_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=edit'));
3894 $this->t->set_var('email_edit_link_title','Edit Email Addresses');
3897 $this->t->set_var('table_width',$table_width);
3899 $this->t->pfp('out','email_t');
3900 $this->save_sessiondata();
3905 $this->t->set_file(array('admin_t' => 'admin.tpl'));
3906 $this->t->set_block('admin_t','upload','uploadhandle');
3907 $this->t->set_block('admin_t','admin','adminhandle');
3908 $this->t->set_block('admin_t','cmd','cmdhandle');
3909 $this->t->set_block('admin_t','presidency','presidencyhandle');
3911 $this->t->set_var('upload_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=upload'));
3912 $this->t->set_var('presidency_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=presidency'));
3914 $action = get_var('action',array('GET','POST'));
3916 $this->t->pfp('out','admin_t');
3918 // TODO: changed this so it picks the quorum dynamically
3919 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1 ORDER BY individual ASC";
3920 $this->db->query($sql,__LINE__,__FILE__);
3922 while ($this->db->next_record()) {
3923 $individual[$i] = $this->db->f('individual');
3924 $indiv_name[$i] = $this->db->f('name');
3925 $indiv2name[$individual[$i]] = $indiv_name[$i];
3928 array_multisort($indiv_name, $individual);
3930 if($action == 'upload') {
3931 $target_path = $this->upload_target_path . '/' . basename( $_FILES['uploadedfile']['name']);
3933 if(($_FILES['uploadedfile']['type'] == "application/zip") ||
3934 ($_FILES['uploadedfile']['type'] == "application/x-zip-compressed") ||
3935 ($_FILES['uploadedfile']['type'] == "application/x-zip") ||
3936 ($_FILES['uploadedfile']['type'] == "application/octet-stream")) {
3938 if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
3939 $uploadstatus = "<b><font color=red> -E- Unable to move the uploaded file to ";
3940 $uploadstatus.= "the target path (check the path and permissions) of: $target_path</font></b>";
3941 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
3942 $uploadstatus.= "Tmp Filename : " . $_FILES['uploadedfile']['tmp_name'] . "<br>";
3943 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
3944 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
3945 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
3946 $uploadstatus.= "Error : " . $_FILES['uploadedfile']['error'] . "<br>";
3947 $this->t->set_var('uploadstatus',$uploadstatus);
3948 $this->t->pfp('uploadhandle','upload',True);
3952 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
3953 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
3954 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
3955 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
3956 $this->t->set_var('uploadstatus',$uploadstatus);
3957 $this->t->pfp('uploadhandle','upload');
3958 $this->t->set_var('uploadhandle','');
3959 print "<table border=1 width=80%><tr><td>\n<pre>";
3961 # make a directory for this data to be stored in
3962 $date="data_" . date("Y_m_d");
3963 $data_dir = $this->upload_target_path . '/' . $date;
3964 print "-> Making the data directory: $date<br>\n";
3965 exec('mkdir -p ' . $data_dir . ' 2>&1', $result, $return_code);
3966 if($return_code != 0) {
3967 print implode('\n',$result) . "<br>";
3968 print "<b><font color=red>";
3969 print "-E- Unable to create the data directory. Aborting import.";
3970 print "</font></b>";
3974 # move the file uploaded into this directory
3975 print "-> Moving the uploaded file into the data dir<br>\n";
3976 exec('mv ' . $target_path . ' ' . $data_dir . '/' . ' 2>&1', $result, $return_code);
3977 if($return_code != 0) {
3978 print implode('\n',$result) . "<br>";
3979 print "<b><font color=red>";
3980 print "-E- Unable to move the uploaded file into the data dir. Aborting import.";
3981 print "</font></b>";
3985 # unzip the data into this directory
3986 print "-> Unzipping the data<br>\n";
3987 exec($this->unzip_path .' -u '. $data_dir . '/*.zip -d ' . $data_dir . ' 2>&1', $result, $return_code);
3988 if($return_code != 0) {
3989 print implode('\n',$result) . "<br>";
3990 print "<b><font color=red>";
3991 print "-E- Unable to unzip the uploaded file into the data dir: $data_dir. Aborting import.";
3992 print "</font></b>";
3995 exec('mv ' . $data_dir . '/*/* '. $data_dir . ' 2>&1', $result, $return_code);
3997 # update the data_latest link to point to this new directory
3998 print "-> Updating the latest data dir link<br>\n";
3999 $data_latest = $this->upload_target_path . '/data_latest';
4000 exec('rm ' . $data_latest. '; ln -s ' . $data_dir .' '. $data_latest .' 2>&1', $result, $return_code);
4001 if($return_code != 0) {
4002 print implode('\n',$result) . "<br>";
4003 print "<b><font color=red>";
4004 print "-E- Unable to update the data latest link. Aborting import.";
4005 print "</font></b>";
4009 # run the import perl script to encorporate it into the DB
4010 ob_start('ob_logstdout', 2);
4011 print "-> Importing the data into the database<br>\n";
4012 ob_flush(); flush(); sleep(1);
4013 $import_log = $this->upload_target_path . '/import.log';
4014 $data_log = $this->upload_target_path . '/data.log';
4015 $import_cmd = $this->script_path . '/import_ward_data ' . $data_latest . ' 2>&1 | tee ' . $import_log;
4016 $parse_cmd = $this->script_path . '/parse_ward_data -v ' . $data_latest . ' > ' . $data_log . '2>&1';
4017 #print "import_cmd: $import_cmd<br>";
4018 #print "parse_cmd: $parse_cmd<br>";
4019 ob_start('ob_logstdout', 2);
4020 passthru($import_cmd);
4021 passthru($parse_cmd);
4022 ob_flush(); flush(); sleep(1);
4024 # fix the permissions of the data dir
4025 exec('chmod -R o-rwx ' . $data_dir, $result, $return_code);
4027 $this->t->pfp('cmdhandle','cmd');
4028 print "</pre></td></tr></table>";
4029 } else if(($_FILES['uploadedfile']['type'] != "application/zip") &&
4030 ($_FILES['uploadedfile']['type'] != "application/x-zip-compressed") &&
4031 ($_FILES['uploadedfile']['type'] != "application/x-zip") &&
4032 ($_FILES['uploadedfile']['type'] != "application/octet-stream")) {
4033 $uploadstatus = "<b><font color=red>The file format must be a .zip file, please try again! </font></b>";
4034 $uploadstatus.= "<br><br><b>Detected file format: " . $_FILES['uploadedfile']['type'] . "</b>";
4035 $this->t->set_var('uploadstatus',$uploadstatus);
4036 $this->t->pfp('uploadhandle','upload',True);
4038 $uploadstatus = "<b><font color=red> There was an error (" . $_FILES['uploadedfile']['error'];
4039 $uploadstatus.= ") uploading the file, please try again! </font></b>";
4040 $this->t->set_var('uploadstatus',$uploadstatus);
4041 $this->t->pfp('uploadhandle','upload',True);
4043 } else if($action == "presidency") {
4044 $new_data = get_var('eqpres',array('POST'));
4045 foreach ($new_data as $entry) {
4047 $email = $entry['email'];
4048 $indiv = $entry['indiv'];
4049 $name = $entry['name'];
4050 $district = $entry['district'];
4051 $president = $entry['president'];
4052 $counselor = $entry['counselor'];
4053 $secretary = $entry['secretary'];
4054 // look up the individual name for the ID
4055 $name = $indiv2name[$indiv];
4056 //print "id=$id indiv=$indiv name=$name email=$email district=$district president=$president ";
4057 //print "counselor=$counselor secretary=$secretary<br>";
4059 if(($indiv > 0) || ($name != "")) {
4060 if($id < $this->max_presidency_members) {
4061 //print "Updating Existing Entry<br>";
4062 $this->db2->query("UPDATE tc_presidency set" .
4063 " individual=" . $indiv .
4064 " ,district=" . $district .
4065 " ,name='" . $name . "'" .
4066 " ,email='" . $email . "'" .
4067 " ,president='" . $president . "'" .
4068 " ,counselor='" . $counselor . "'" .
4069 " ,secretary='" . $secretary . "'" .
4070 " WHERE presidency=" . $id,__LINE__,__FILE__);
4072 //print "Adding New Entry<br>";
4073 $this->db2->query("INSERT INTO tc_presidency (presidency,individual,district,name," .
4074 "email,president,counselor,secretary,valid) " .
4075 "VALUES (NULL,'" . $indiv . "','" . $district . "','" .
4076 $name . "','" . $email . "','" . $president . "','" .
4077 $counselor . "','" . $secretary . "','1'" .
4078 ")",__LINE__,__FILE__);
4081 //print "Ignoring Blank Entry<br>";
4085 // Now update the tc_district table appropriately
4087 // Delete all the previous district entries from the table
4088 $this->db->query("DELETE from tc_district where valid=1",__LINE__,__FILE__);
4089 $this->db->query("DELETE from tc_district where valid=0",__LINE__,__FILE__);
4091 // Always add a "District 0" assigned to the High Priests Group
4093 $name = "High Priests";
4096 $this->db2->query("INSERT INTO tc_district (district,name,supervisor,valid) " .
4097 "VALUES ('" . $district . "','" . $name . "','" .
4098 $indiv . "','" . $valid . "'" .
4099 ")",__LINE__,__FILE__);
4101 // Requery the tc_presidency table
4102 $sql = "SELECT * FROM tc_presidency where valid=1";
4103 $this->db->query($sql,__LINE__,__FILE__);
4104 while ($this->db->next_record()) {
4105 // Extract the data for each presidency record
4106 $id = $this->db->f('presidency');
4107 $indiv = $this->db->f('individual');
4108 $name = $this->db->f('name');
4109 $district = $this->db->f('district');
4110 $name = $this->db->f('name');
4113 // If we have a valid district, add it to the district table
4115 $this->db2->query("INSERT INTO tc_district (district,name,supervisor,valid) " .
4116 "VALUES ('" . $district . "','" . $name . "','" .
4117 $indiv . "','" . $valid . "'" .
4118 ")",__LINE__,__FILE__);
4122 $this->t->set_var('adminhandle','');
4123 $this->t->pfp('adminhandle','admin');
4127 $this->t->set_var('adminhandle','');
4128 $this->t->pfp('adminhandle','admin');
4131 // Now save off the data needed for a Presidency Table Update
4133 $sql = "SELECT * FROM tc_presidency where valid=1";
4134 $this->db->query($sql,__LINE__,__FILE__);
4136 $header_row = "<th>Individual</th><th>Email</th><th>District</th><th>President</th><th>Counselor</th><th>Secretary</th>";
4137 while ($this->db->next_record()) {
4138 // Extract the data for each presidency record
4139 $id = $this->db->f('presidency');
4140 $indiv = $this->db->f('individual');
4141 $district = $this->db->f('district');
4142 $name = $this->db->f('name');
4143 $email = $this->db->f('email');
4144 $president = $this->db->f('president');
4145 $counselor = $this->db->f('counselor');
4146 $secretary = $this->db->f('secretary');
4148 // Create the forms needed in the table
4149 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4152 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4155 if($eqpresidency == 0) {
4156 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4157 $table_data.= '<option value=0></option>';
4158 for ($j=0; $j < count($individual); $j++) {
4159 $tmp_id = $individual[$j];
4160 $name = $indiv_name[$j];
4161 if($individual[$j] == $indiv) {
4163 $selected = 'selected="selected"';
4167 $table_data.= '<option value='.$tmp_id.' '.$selected.'>'.$name.'</option>';
4169 $table_data.='</select></td>';
4170 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="'.$indivname.'">';
4172 $table_data.= '<td align=left><input type=text size="20" name="eqpresname" value="Presidency"></td>';
4173 $table_data.= '<input type=hidden name="eqpres['.$id.'][name]" value="Presidency">';
4177 $table_data .= '<td><input type="text" size="50" name="eqpres['.$id.'][email]" value="'.$email.'"></td>';
4180 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4181 $table_data.= '<option value=0></option>';
4182 for ($j=0; $j <= $this->max_num_districts; $j++) {
4183 if($district == $j) {
4184 $selected = 'selected="selected"';
4188 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4190 $table_data.='</select></td>';
4193 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4194 if($president == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4195 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4196 $table_data.='</select></td>';
4199 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4200 if($counselor == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4201 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4202 $table_data.='</select></td>';
4205 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4206 if($secretary == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4207 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4208 $table_data.='</select></td>';
4211 $table_data .= "</tr>\n";
4212 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4213 $this->t->set_var('tr_color',$tr_color);
4216 // Now create 1 blank row to always have a line available to add a new individual with
4217 $id = $this->max_presidency_members;
4218 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4220 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4222 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4223 $table_data.= '<option value=0></option>';
4224 for ($j=0; $j < count($individual); $j++) {
4225 $tmp_id = $individual[$j];
4226 $name = $indiv_name[$j];
4227 $table_data.= '<option value='.$tmp_id.'>'.$name.'</option>';
4229 $table_data.='</select></td>';
4230 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="">';
4232 $table_data.='<td><input type="text" size="50" name="eqpres['.$id.'][email]" value=""></td>';
4234 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4235 $table_data.= '<option value=0></option>';
4236 for ($j=0; $j <= $this->max_num_districts; $j++) {
4238 $selected = 'selected="selected"';
4242 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4244 $table_data.='</select></td>';
4246 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4247 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4248 $table_data.='</select></td>';
4250 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4251 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4252 $table_data.='</select></td>';
4254 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4255 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4256 $table_data.='</select></td>';
4258 $table_data .= "</tr>\n";
4259 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4260 $this->t->set_var('tr_color',$tr_color);
4262 $this->t->set_var('header_row',$header_row);
4263 $this->t->set_var('table_data',$table_data);
4264 $this->t->pfp('presidencyhandle','presidency',True);
4266 $this->save_sessiondata();
4269 function email_appt($appointment)
4271 //print "Emailing notification of appointment: $appointment <br>";
4273 $sql = "SELECT * FROM tc_appointment where appointment='$appointment'";
4274 $this->db->query($sql,__LINE__,__FILE__);
4276 while ($this->db->next_record()) {
4277 $appointment = $this->db->f('appointment');
4278 $presidency = $this->db->f('presidency');
4279 $location = $this->db->f('location');
4282 $indiv = $this->db->f('individual');
4284 $family = $this->db->f('family');
4288 $uid = $this->db->f('uid');
4290 // Extract the year, month, day, hours, minutes, seconds from the appointment time
4291 $appt_date = $this->db->f('date');
4292 $date_array = explode("-",$appt_date);
4293 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
4294 $appt_time = $this->db->f('time');
4295 $time_array = explode(":",$appt_time);
4296 $hour = $time_array[0]; $minute = $time_array[1]; $seconds = $time_array[2];
4298 // Format the appointment time into an iCal UTC equivalent
4299 $dtstamp = gmdate("Ymd"."\T"."His"."\Z");
4300 $dtstart = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds,$month,$day,$year));
4301 $dtstartstr = date("l, F d, o g:i A", mktime($hour,$minute,$seconds,$month,$day,$year));
4303 $sql = "SELECT * FROM tc_presidency where presidency='$presidency'";
4304 $this->db2->query($sql,__LINE__,__FILE__);
4305 if($this->db2->next_record()) {
4306 $email = $this->db2->f('email');
4307 $interviewer = $this->db2->f('name');
4310 // Set the email address of the interviewer
4314 $sql = "SELECT * FROM tc_individual where individual='$indiv'";
4315 $this->db2->query($sql,__LINE__,__FILE__);
4316 if($this->db2->next_record()) {
4317 $indiv_name = $this->db2->f('name');
4318 $phone = $this->db2->f('phone');
4319 $appt_name = $indiv_name . " Interview";
4320 $duration = $this->default_ppi_appt_duration * 60;
4325 $sql = "SELECT * FROM tc_family WHERE family='$family'";
4326 $this->db2->query($sql,__LINE__,__FILE__);
4327 if($this->db2->next_record()) {
4328 $individual = $this->db2->f('individual');
4329 $sql = "SELECT * FROM tc_individual where individual='$individual'";
4330 $this->db3->query($sql,__LINE__,__FILE__);
4331 if($this->db3->next_record()) {
4332 $phone = $this->db3->f('phone');
4333 $family_name = $this->db3->f('name');
4334 $phone = $this->db3->f('phone');
4336 $appt_name = $family_name . " Family Visit";
4337 $duration = $this->default_visit_appt_duration * 60;
4341 $dtend = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4342 $dtendstr = date("g:i A", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4343 $date = $dtstartstr . "-" . $dtendstr;
4344 $description = "$appt_name : $phone";
4346 if(($uid == 0) && ($appt_name != "")) {
4347 // Create a new calendar item for this appointment, since this must be the first time we
4348 // are sending it out.
4349 print "Sent new appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4350 $uid = rand() . rand(); // Generate a random identifier for this appointment
4351 $subject = "Created: $appt_name";
4353 $this->db->query("UPDATE tc_appointment set" .
4355 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4357 $action = "PUBLISH";
4358 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4359 $dtend, $date, $location, $appt_name, $description, $uid);
4360 } else if(($uid != 0) && ($appt_name == "")) {
4361 // Remove the calendar item for this appointment since it has already been sent
4362 // and there is no name we have changed it to.
4363 print "Sent deleted appointment to " . $interviewer . " at " . $email . " for " . $appt_date . " " . $appt_time . "<br>";
4364 $subject = "Canceled: $appt_date $appt_time";
4366 $this->db->query("UPDATE tc_appointment set" .
4368 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4371 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4372 $dtend, $date, $location, $subject, $subject, $uid);
4373 } else if($uid != 0) {
4374 // Update the existing appointment since we have changed it
4375 print "Sent updated appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4377 $subject = "Canceled: $appt_date $appt_time";
4379 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4380 $dtend, $date, $location, $subject, $subject, $uid);
4382 $uid = rand() . rand(); // Generate a random identifier for this appointment
4383 $this->db->query("UPDATE tc_appointment set" .
4385 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4387 $subject = "Updated: $appt_name";
4388 $action = "PUBLISH";
4389 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4390 $dtend, $date, $location, $appt_name, $description, $uid);
4396 function send_ical_appt($action, $to, $from, $subject, $dtstamp, $dtstart, $dtend, $date, $location, $summary, $description, $uid)
4398 // Initialize our local variables
4399 $boundary = "=MIME_APPOINTMENT_BOUNDARY";
4403 // Form the headers for the email message
4404 $headers.="X-Mailer: PHP/" . phpversion() . "\n";
4405 $headers.="Mime-Version: 1.0\n";
4406 $headers.="Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
4407 $headers.="Content-Disposition: inline\n";
4408 $headers.="Reply-To: $from\n";
4409 $headers.="From: $from\n";
4411 // Print the plaintext version of the appointment
4412 $message.="--$boundary\n";
4413 $message.="Content-Type: text/plain; charset=us-ascii\n";
4414 $message.="Content-Disposition: inline\n";
4416 $message.="What: $description\n";
4417 $message.="When: $date\n";
4418 $message.="Where: $location\n";
4421 // Print the .ics attachment version of the appointment
4422 $message.="--$boundary\n";
4423 $message.="Content-Type: text/calendar; charset=us-ascii\n";
4424 $message.="Content-Disposition: attachment; filename=\"appointment.ics\"\n";
4426 $message.="BEGIN:VCALENDAR" . "\n";
4427 $message.="VERSION:2.0" . "\n";
4428 $message.="PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN" . "\n";
4429 $message.="METHOD:$action" . "\n";
4430 $message.="BEGIN:VEVENT" . "\n";
4431 $message.="ORGANIZER:MAILTO:$from". "\n";
4432 $message.="DTSTAMP:$dtstamp" . "\n";
4433 $message.="DTSTART:$dtstart" . "\n";
4434 $message.="DTEND:$dtend" . "\n";
4435 $message.="SUMMARY:$summary" . "\n";
4436 $message.="DESCRIPTION:$description" . "\n";
4437 $message.="LOCATION:$location" . "\n";
4438 $message.="UID:$uid" ."\n";
4439 $message.="TRANSP:OPAQUE" . "\n";
4440 $message.="SEQUENCE:0" . "\n";
4441 $message.="CLASS:PUBLIC" . "\n";
4442 $message.="END:VEVENT" . "\n";
4443 $message.="END:VCALENDAR" . "\n";
4445 // Complete the message
4446 $message.="--$boundary\n";
4449 mail($to, $subject, $message, $headers);
4452 function get_time_selection_form($hour, $minute, $pm, $presidency, $appointment)
4457 if($hour == 0) { $blank = 1; }
4459 if($this->time_drop_down_lists == 1) {
4460 // Create drop down lists to get the time
4461 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][hour]>';
4462 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4463 foreach(range(1,12) as $num) {
4465 $selected = 'selected="selected"';
4469 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4471 $form_data.= '</select>';
4472 $form_data.= ' : ';
4473 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][minute]>';
4474 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4477 if($num < 10) { $num = "0" . "$num"; }
4478 if($minute == $num) {
4479 $selected = 'selected="selected"';
4483 if($blank == 1) { $selected = ""; }
4484 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4485 $num = $num + $this->time_drop_down_list_inc;
4487 $form_data.= '</select>';
4489 // Use free form text fields to get the time
4495 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][hour] value='.$hour.'>';
4497 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][minute] value='.$minute.'>';
4498 $form_data.= ' ';
4500 // Always use a drop-down select form for am/pm
4501 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][pm]>';
4504 $form_data.= '<option value=0 selected>am</option>';
4505 $form_data.= '<option value=1>pm</option>';
4508 $form_data.= '<option value=0>am</option>';
4509 $form_data.= '<option value=1 selected>pm</option>';
4512 $form_data.= '<option value=""></option>';
4513 $form_data.= '<option value=0>am</option>';
4514 $form_data.= '<option value=1>pm</option>';
4516 $form_data.= '</select>';