2 /**************************************************************************\
3 * Application: phpGroupWare - 3rd Counselor *
4 * Framework: http://www.phpgroupware.org *
5 * Author: Alan J. Pippin (apippin@pippins.net) *
6 * ----------------------------------------------- *
7 * This program is free software; you can redistribute it and/or modify it *
8 * under the terms of the GNU General Public License as published by the *
9 * Free Software Foundation; either version 2 of the License, or (at your *
10 * option) any later version. *
11 \**************************************************************************/
12 /* $Id: class.tc.inc.php,v 1.1.1.1 2005/07/20 07:40:32 ajp Exp $ */
24 var $default_ht_num_months;
25 var $default_ppi_num_months;
26 var $default_ppi_num_years;
27 var $default_int_num_quarters;
28 var $default_int_num_years;
29 var $default_vis_num_years;
30 var $default_att_num_quarters;
31 var $max_num_districts;
34 var $upload_target_path;
36 var $max_appointments;
37 var $max_presidency_members;
39 var $public_functions = array
64 'willing_view' => True,
65 'willing_update' => True,
66 'send_ical_appt' => True,
67 'assign_view' => True,
68 'assign_update' => True,
69 'get_time_selection_form' => True,
74 if(file_exists("setup/tc_config.local")) {
75 include("setup/tc_config.local");
77 include("setup/tc_config");
80 $this->script_path = "$this->application_path"."/bin";
81 $this->max_presidency_members = 99;
82 $this->max_appointments = 32768;
84 $this->db = $GLOBALS['phpgw']->db;
85 $this->db2 = $this->db;
86 $this->db3 = $this->db;
87 $this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
88 $this->t = $GLOBALS['phpgw']->template;
89 $this->account = $GLOBALS['phpgw_info']['user']['account_id'];
90 $this->grants = $GLOBALS['phpgw']->acl->get_grants('tc');
91 $this->grants[$this->account] = PHPGW_ACL_READ + PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE;
93 $this->jscal = CreateObject('tc.jscalendar'); // before phpgw_header() !!!
94 $this->cal_options = 'daFormat : "%Y-%m-%d",
95 ifFormat : "%Y-%m-%d",
99 $GLOBALS['phpgw_info']['flags']['app_header'] = 'The 3rd Counselor';
100 $GLOBALS['phpgw']->common->phpgw_header();
102 $this->current_day = `date '+%d'`;
103 $this->current_day = $this->current_day-0; // Make it numeric
104 $this->current_month = `date '+%m'`;
105 $this->current_month = $this->current_month-0; // Make it numeric
106 $this->current_year = `date '+%Y'`;
107 $this->current_year = $this->current_year-0; // Make it numeric
110 $this->display_app_header();
113 function logToFile($func, $msg)
116 $fd = fopen($this->upload_target_path . "/tc_trace.log", "a");
117 // append date/time to message
118 $str = "[" . date("Y/m/d h:i:s", mktime()) . "] [" . $func . "] " . $msg;
120 fwrite($fd, $str . "\n");
125 function save_sessiondata()
129 function display_app_header()
131 $this->t->set_file(array('tc_header' => 'header.tpl'));
133 if (isset($phpgw_info['user']['preferences']['tc']['tc_font']))
135 $font = $phpgw_info['user']['preferences']['tc']['tc_font'];
142 $this->t->set_var('bg_color',$phpgw_info['theme']['th_bg']);
143 $this->t->set_var('font',$font);
144 $link_data['menuaction'] = 'tc.tc.ht_view';
145 $this->t->set_var('link_hometeaching',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
146 $this->t->set_var('lang_hometeaching','HomeTeaching');
147 $link_data['menuaction'] = 'tc.tc.act_list';
148 $this->t->set_var('link_activity',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
149 $this->t->set_var('lang_activity','Activities');
150 $link_data['menuaction'] = 'tc.tc.willing_view';
151 $this->t->set_var('link_willing',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
152 $this->t->set_var('lang_willing','Willingness');
153 $link_data['menuaction'] = 'tc.tc.assign_view';
154 $this->t->set_var('link_assignment',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
155 $this->t->set_var('lang_assignment','Assignments');
156 $link_data['menuaction'] = 'tc.tc.par_view';
157 $this->t->set_var('link_participation',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
158 $this->t->set_var('lang_participation','Participation');
159 $link_data['menuaction'] = 'tc.tc.ppi_view';
160 $this->t->set_var('link_ppi',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
161 $this->t->set_var('lang_ppi','PPIs');
162 $link_data['menuaction'] = 'tc.tc.int_view';
163 $this->t->set_var('link_int',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
164 $this->t->set_var('lang_int','Interviews');
165 $link_data['menuaction'] = 'tc.tc.vis_view';
166 $this->t->set_var('link_visit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
167 $this->t->set_var('lang_visit','Visits');
168 $link_data['menuaction'] = 'tc.tc.att_view';
169 $this->t->set_var('link_attendance',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
170 $this->t->set_var('lang_attendance','Attendance');
171 $link_data['menuaction'] = 'tc.tc.dir_view';
172 $this->t->set_var('link_dir',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
173 $this->t->set_var('lang_dir','Directory');
174 $link_data['menuaction'] = 'tc.tc.org_view';
175 $this->t->set_var('link_org',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
176 $this->t->set_var('lang_org','Callings');
177 $link_data['menuaction'] = 'tc.tc.admin';
178 $this->t->set_var('link_admin',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
179 $this->t->set_var('lang_admin','Admin');
180 $link_data['menuaction'] = 'tc.tc.schedule';
181 $this->t->set_var('link_schedule',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
182 $this->t->set_var('lang_schedule','Scheduling');
183 $link_data['menuaction'] = 'tc.tc.email';
184 $this->t->set_var('link_email',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
185 $this->t->set_var('lang_email','Email');
187 $this->t->pparse('out','tc_header');
192 $this->t->set_file(array('ht_view_t' => 'ht_view.tpl'));
193 $this->t->set_block('ht_view_t','district_list','list');
195 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
196 $num_months = get_var('num_months',array('GET','POST'));
197 if($num_months == '') { $num_months = $this->default_ht_num_months; }
198 $this->t->set_var('num_months',$num_months);
199 $this->t->set_var('lang_filter','Filter');
200 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
201 else { $this->t->set_var('lang_num_months','Months of History'); }
203 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
204 $this->t->set_var('title','Hometeaching');
206 $sql = "SELECT * FROM tc_district AS td JOIN tc_individual AS ti WHERE td.supervisor=ti.individual AND td.valid=1 ORDER BY td.district ASC";
207 $this->db->query($sql,__LINE__,__FILE__);
209 while ($this->db->next_record()) {
210 $districts[$i]['district'] = $this->db->f('district');
211 $districts[$i]['name'] = $this->db->f('name');
212 $districts[$i]['supervisor'] = $this->db->f('supervisor');
216 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
217 $this->db->query($sql,__LINE__,__FILE__);
219 while ($this->db->next_record()) {
220 $individual[$i] = $this->db->f('individual');
221 $indiv_name[$i] = $this->db->f('name');
222 $indiv_phone[$individual[$i]] = $this->db->f('phone');
225 array_multisort($indiv_name, $individual);
227 // Make an array mapping individuals to indiv_names
228 for($i=0; $i < count($individual); $i++) {
229 $id = $individual[$i];
230 $indivs[$id] = $indiv_name[$i];
233 $this->nextmatchs->template_alternate_row_color(&$this->t);
234 for($m=$num_months; $m >= 0; $m--) { $total_families[$m]=0; }
235 for ($i=0; $i < count($districts); $i++) {
236 $this->t->set_var('district_number',$districts[$i]['district']);
237 $this->t->set_var('district_name',$districts[$i]['name']);
238 $supervisor = $districts[$i]['supervisor'];
240 // Select all the unique companionship numbers for this district
241 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$i]['district'];
242 $this->db->query($sql,__LINE__,__FILE__);
243 $j=0; $unique_companionships = '';
244 while ($this->db->next_record()) {
245 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
249 $comp_width=450; $visit_width=25; $table_width=$comp_width + $num_months*$visit_width;
250 $table_data=""; $num_companionships = 0;
251 for($m=$num_months; $m >= 0; $m--) {
255 for ($j=0; $j < count($unique_companionships); $j++) {
256 $companion_table_entry = "";
257 // Select all the companions in each companionship
258 $sql = "SELECT * FROM tc_companionship where valid=1 and ".
259 "companionship=". $unique_companionships[$j]['companionship'];
260 $this->db->query($sql,__LINE__,__FILE__);
262 while ($this->db->next_record()) {
263 // Get this companions information
264 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
265 $companionship = $this->db->f('companionship');
266 $individual = $this->db->f('individual');
267 $name = $indivs[$individual];
268 $phone = $indiv_phone[$individual];
269 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
271 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
273 // Get the names of the families assigned this home teaching companionship
274 $sql = "SELECT * FROM tc_family AS tf JOIN tc_individual AS ti WHERE tf.individual=ti.individual AND tf.valid=1 AND tf.companionship=".$unique_companionships[$j]['companionship'];
275 $sql = $sql . " ORDER BY name ASC";
276 $this->db->query($sql,__LINE__,__FILE__);
278 while ($this->db->next_record()) {
279 $family_name = $this->db->f('name');
280 $family_id = $this->db->f('family');
281 $this->nextmatchs->template_alternate_row_color(&$this->t);
282 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
283 // Find out how many times Visits were performed by this companionship
284 // in the past $num_months for this Family
285 $header_row="<th width=$comp_width><font size=-2>Families</th>";
286 for($m=$num_months; $m >= 0; $m--) {
287 $month = $this->current_month - $m;
288 $year = $this->current_year;
289 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
290 if($month < 10) { $month = "0"."$month"; }
291 $month_start = "$year"."-"."$month"."-"."01";
292 $month_end = "$year"."-"."$month"."-"."31";
293 $month = "$month"."/"."$year";
295 //print "m: $m month: $month year: $year month_start: $month_start month_end: $month_end<br>";
296 // Add this to the query to filter on only visits made by this companionship:
297 // " AND companionship=" . $unique_companionships[$j]['companionship'].
299 // First check to see if the currently assigned companionship has visited them
300 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
301 " AND companionship=".$unique_companionships[$j]['companionship'].
302 " AND family=". $family_id;
303 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
304 if($this->db2->num_rows($query_id) == 0) {
305 // We did not find any visits made by the currently assigned companionship,
306 // look for visits made by any other companionship other than 0. (0 == Presidency Visit)
307 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
308 " AND companionship!=0".
309 " AND family=". $family_id;
310 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
312 $this->db2->query($sql,__LINE__,__FILE__);
313 $link_data['menuaction'] = 'tc.tc.ht_update';
314 $link_data['date'] = $month_start;
315 $link_data['month_start'] = $month_start;
316 $link_data['month_end'] = $month_end;
317 $link_data['month'] = $month;
318 $link_data['district'] = $districts[$i]['district'];
319 $link_data['district_name'] = $districts[$i]['name'];
320 $link_data['action'] = 'view';
321 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
322 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
323 if(!$total_visits[$m]) { $total_visits[$m] = 0; }
324 if($this->db2->next_record()) {
325 if($this->db2->f('visited') == 'y') {
326 $visits[$m]++; $total_visits[$m]++;
327 $num_families[$m]++; $total_families[$m]++;
328 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/checkmark.gif"></a></td>';
329 } else if($this->db2->f('visited') == 'n') {
330 $num_families[$m]++; $total_families[$m]++;
331 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/x.gif"></a></td>';
333 //$visits[$m]++; $total_visits[$m]++;
334 $table_data .= "<td> </td>";
337 //$visits[$m]++; $total_visits[$m]++;
338 $table_data .= "<td> </td>";
341 $table_data .= "</tr>";
344 $table_data .= "<tr><td colspan=20></td></tr>";
346 $table_data .= "<tr><td colspan=20><hr></td></tr>";
347 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
349 for($m=$num_months; $m >=0; $m--) {
350 if($num_families[$m] > 0) {
351 $percent = ceil(($visits[$m] / $num_families[$m])*100);
355 $stat_data .= "<td align=center><font size=-2><b>$visits[$m] / $num_families[$m]<br>$percent%</font></b></td>";
357 $stat_data .= "</tr>";
359 $this->t->set_var('table_width',$table_width);
360 $this->t->set_var('header_row',$header_row);
361 $this->t->set_var('table_data',$table_data);
362 $this->t->set_var('stat_data',$stat_data);
363 $this->t->fp('list','district_list',True);
366 $totals = "<tr><td><b><font size=-2>Total Families Hometaught:<br>Total Hometeaching Percentage:</font></b></td>";
367 for($m=$num_months; $m >=0; $m--) {
368 if($total_families[$m] > 0) {
369 $percent = ceil(($total_visits[$m] / $total_families[$m])*100);
373 $totals .= "<td align=center><font size=-2><b>$total_visits[$m] / $total_families[$m]<br>$percent%</font></b></td>";
377 $this->t->set_var('totals',$totals);
379 $this->t->pfp('out','ht_view_t');
380 $this->save_sessiondata();
386 $this->t->set_file(array('ht_update_t' => 'ht_update.tpl'));
387 $this->t->set_block('ht_update_t','district_list','list');
388 $this->t->set_block('ht_update_t','save','savehandle');
390 $district = get_var('district',array('GET','POST'));
391 $district_name = get_var('district_name',array('GET','POST'));
392 $date = get_var('date',array('GET','POST'));
393 $month = get_var('month',array('GET','POST'));
394 $month_start = get_var('month_start',array('GET','POST'));
395 $month_end = get_var('month_end',array('GET','POST'));
396 $action = get_var('action',array('GET','POST'));
398 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
399 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_update&action=save'));
400 $this->t->set_var('lang_done','Cancel');
401 $this->t->set_var('district_name',$district_name);
402 $this->t->set_var('district_number',$district);
403 $this->t->set_var('title','Hometeaching Update ' . $month);
404 $this->t->set_var('date',$date);
406 if($action == 'save') {
407 // Get a list of all the companionships in this district
408 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $district;
409 $this->db->query($sql,__LINE__,__FILE__);
410 $j=0; $unique_companionships = '';
411 while ($this->db->next_record()) {
412 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
415 for ($j=0; $j < count($unique_companionships); $j++) {
416 //$comp=$unique_companionships[$j]['companionship'];
417 //print "deleting from tc_visit where companionship=$comp and date=$date and district=$district<br>";
418 // Delete all the visits that have taken place for all families for this companionsthip for this month
419 $this->db->query("DELETE from tc_visit where companionship=" . $unique_companionships[$j]['companionship'] .
420 " AND " . "date='" . $date . "'",__LINE__,__FILE__);
423 // Now, add the visits that are checked for this month
424 $new_data = get_var('family_visited',array('POST'));
425 foreach ($new_data as $family) {
426 foreach ($family as $data) {
427 //print "family_visited: $data <br>";
428 $data_array = explode("/",$data);
429 $family_id = $data_array[0];
430 $companionship = $data_array[1];
431 $date = $data_array[2];
432 $visited = $data_array[3];
433 if($visited == "") { $visited = $data_array[4]; }
434 //print "family_id: $family_id companionship: $companionship date: $date visited: $visited<br>";
435 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes,visited) " .
436 "VALUES (" . $family_id .",". $companionship .",'". $date ."','','". $visited ."')",__LINE__,__FILE__);
443 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
444 $this->db->query($sql,__LINE__,__FILE__);
446 while ($this->db->next_record()) {
447 $individual[$i] = $this->db->f('individual');
448 $indiv_name[$i] = $this->db->f('name');
449 $indiv_phone[$individual[$i]] = $this->db->f('phone');
452 array_multisort($indiv_name, $individual);
454 // Make an array mapping individuals to indiv_names
455 for($i=0; $i < count($individual); $i++) {
456 $id = $individual[$i];
457 $indivs[$id] = $indiv_name[$i];
460 // Select all the unique companionship numbers for this district
461 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $district;
462 $this->db->query($sql,__LINE__,__FILE__);
463 $j=0; $unique_companionships = '';
464 while ($this->db->next_record()) {
465 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
469 $comp_width=300; $visit_width=25; $table_width=$comp_width + $visit_width;
470 $table_data=""; $num_companionships = 0; $num_families = 0; $visits=0;
471 for ($j=0; $j < count($unique_companionships); $j++) {
472 $companion_table_entry = "";
473 // Select all the companions in each companionship
474 $sql = "SELECT * FROM tc_companionship where valid=1 and ".
475 "companionship=". $unique_companionships[$j]['companionship'];
476 $this->db->query($sql,__LINE__,__FILE__);
478 while ($this->db->next_record()) {
479 // Get this companions information
480 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
481 $companionship = $this->db->f('companionship');
482 $individual = $this->db->f('individual');
483 $name = $indivs[$individual];
484 $phone = $indiv_phone[$individual];
485 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
487 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
489 // Get the names of the families assigned this home teaching companionship
490 $sql = "SELECT * FROM tc_family AS tf JOIN tc_individual AS ti WHERE tf.individual=ti.individual AND tf.valid=1 AND tf.companionship=".$unique_companionships[$j]['companionship'];
491 $sql = $sql . " ORDER BY ti.name ASC";
492 $this->db->query($sql,__LINE__,__FILE__);
493 while ($this->db->next_record()) {
494 $family_name = $this->db->f('name');
495 $family_id = $this->db->f('family');
496 $this->nextmatchs->template_alternate_row_color(&$this->t);
497 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
499 $header_row="<th width=$comp_width><font size=-2>Families</th>";
501 // First check to see if the currently assigned companionship has visited them
502 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
503 " AND companionship=".$unique_companionships[$j]['companionship'].
504 " AND family=". $family_id;
505 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
506 if($this->db2->num_rows($query_id) == 0) {
507 // We did not find any visits made by the currently assigned companionship,
508 // look for visits made by any other companionship other than 0. (0 == Presidency Visit)
509 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
510 " AND companionship!=0".
511 " AND family=". $family_id;
512 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
515 $value = $family_id . "/" . $unique_companionships[$j]['companionship'] . "/" . $date;
516 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
517 if(!$total_visits) { $total_visits = 0; }
518 if($this->db2->next_record()) {
519 if($this->db2->f('visited') == 'y') {
520 $visits++; $total_visits++; $num_families++;
521 $table_data .= '<td width=100 align=center>';
522 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y" checked>Y';
523 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
524 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/"> ';
525 $table_data .= '</td>';
526 } else if($this->db2->f('visited') == 'n') {
528 $table_data .= '<td width=100 align=center>';
529 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
530 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n" checked>N';
531 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/">';
532 $table_data .= '</td>';
534 $table_data .= '<td width=100 align=center>';
535 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
536 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
537 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
538 $table_data .= '</td>';
543 $table_data .= '<td width=100 align=center>';
544 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
545 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
546 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
547 $table_data .= '</td>';
550 $table_data .= "</tr>";
551 $table_data .= "<tr><td colspan=20></td></tr>";
553 $table_data .= "<tr><td colspan=20><hr></td></tr>";
554 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
556 $percent = ceil(($visits / $num_families)*100);
557 $stat_data .= "<td align=center><font size=-2><b>$visits / $num_families<br>$percent%</font></b></td>";
558 $stat_data .= "</tr>";
560 $this->t->set_var('table_width',$table_width);
561 $this->t->set_var('header_row',$header_row);
562 $this->t->set_var('table_data',$table_data);
563 $this->t->set_var('stat_data',$stat_data);
564 $this->t->fp('list','district_list',True);
566 $this->t->set_var('lang_reset','Clear Form');
567 $this->t->set_var('lang_save','Save Changes');
568 $this->t->set_var('savehandle','');
570 $this->t->pfp('out','ht_update_t');
571 $this->t->pfp('addhandle','save');
573 $this->save_sessiondata();
578 $this->t->set_file(array('act_list_t' => 'act_list.tpl'));
579 $this->t->set_block('act_list_t','act_list','list');
581 $this->t->set_var('lang_name','Assignment');
582 $this->t->set_var('lang_date','Date');
583 $this->t->set_var('lang_notes','Description');
585 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
586 $this->db->query($sql,__LINE__,__FILE__);
587 $total_records = $this->db->num_rows();
590 while ($this->db->next_record()) {
591 $activity_list[$i]['activity'] = $this->db->f('activity');
592 $activity_list[$i]['assignment'] = $this->db->f('assignment');
593 $activity_list[$i]['date'] = $this->db->f('date');
594 $activity_list[$i]['notes'] = $this->db->f('notes');
596 $sql = "SELECT * FROM tc_assignment WHERE assignment='" . $activity_list[$i]['assignment'] . "'";
597 $this->db2->query($sql,__LINE__,__FILE__);
598 if($this->db2->next_record()) {
599 $activity_list[$i]['name'] = $this->db2->f('name');
600 $activity_list[$i]['abbreviation'] = $this->db2->f('abbreviation');
605 for ($i=0; $i < count($activity_list); $i++) {
606 $this->nextmatchs->template_alternate_row_color(&$this->t);
607 $this->t->set_var('name',$activity_list[$i]['name']);
608 $this->t->set_var('date',$activity_list[$i]['date']);
609 $activity_notes = $activity_list[$i]['notes'];
610 if(strlen($activity_notes) > 40) { $activity_notes = substr($activity_notes,0,40) . "..."; }
611 $this->t->set_var('notes',$activity_notes);
613 $link_data['menuaction'] = 'tc.tc.act_view';
614 $link_data['activity'] = $activity_list[$i]['activity'];
615 $link_data['action'] = 'view';
616 $this->t->set_var('view',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
617 $this->t->set_var('lang_view','View');
619 $link_data['menuaction'] = 'tc.tc.act_update';
620 $link_data['activity'] = $activity_list[$i]['activity'];
621 $link_data['action'] = 'edit';
622 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
623 $this->t->set_var('lang_edit','Edit');
625 $this->t->fp('list','act_list',True);
628 $link_data['menuaction'] = 'tc.tc.act_update';
629 $link_data['activity'] = '0';
630 $link_data['action'] = 'add';
631 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/tc/index.php',$link_data) .
632 '"><input type="submit" name="Add" value="' . 'Add Activity' .'"></font></form>');
634 $this->t->pfp('out','act_list_t');
635 $this->save_sessiondata();
640 $this->t->set_file(array('act_view_t' => 'act_view.tpl'));
641 $this->t->set_block('act_view_t','part_list','list');
643 $sql = "SELECT * FROM tc_activity WHERE activity=" . intval(get_var('activity',array('GET','POST')));
644 $this->db->query($sql,__LINE__,__FILE__);
645 $this->db->next_record();
646 $this->t->set_var('assignment', $this->db->f('assignment'));
647 $this->t->set_var('date', $this->db->f('date'));
648 $this->t->set_var('notes', $this->db->f('notes'));
650 $sql = "SELECT * FROM tc_assignment WHERE assignment='" . $this->db->f('assignment') . "'";
651 $this->db2->query($sql,__LINE__,__FILE__);
652 if($this->db2->next_record()) {
653 $this->t->set_var('name', $this->db2->f('name'));
654 $this->t->set_var('abbreviation', $this->db2->f('abbreviation'));
656 $this->t->set_var('lang_name','Assignment');
657 $this->t->set_var('lang_date','Date');
658 $this->t->set_var('lang_notes','Description');
659 $this->t->set_var('lang_done','Done');
660 $this->t->set_var('lang_action','View');
662 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
663 $this->t->set_var('tr_color',$tr_color);
665 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_list'));
667 $link_data['menuaction'] = 'tc.tc.act_update';
668 $link_data['activity'] = get_var('activity',array('GET','POST'));
669 $link_data['action'] = 'edit';
670 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
671 $this->t->set_var('lang_edit','Edit');
672 $this->t->set_var('cal_date',$this->db->f('date'));
674 // Now find out which indivs participated in this activity
675 $sql = "SELECT * FROM tc_participation WHERE activity=" . intval(get_var('activity',array('GET','POST')));
676 $this->db->query($sql,__LINE__,__FILE__);
677 $total_records = $this->db->num_rows();
680 while ($this->db->next_record()) {
681 $part_list[$i]['individual'] = $this->db->f('individual');
685 for ($i=0; $i < count($part_list); $i++) {
686 $sql = "SELECT * FROM tc_individual WHERE individual=" . $part_list[$i]['individual'];
687 $this->db->query($sql,__LINE__,__FILE__);
688 $this->db->next_record();
689 $names[$i] = $this->db->f('name');
693 for ($i=0; $i < count($names); $i++) {
694 //$this->nextmatchs->template_alternate_row_color(&$this->t);
695 $this->t->set_var('individual_name',$names[$i]);
696 if(($i+1) % 3 == 0) {
697 $this->t->set_var('table_sep',"</td></tr><tr>");
699 $this->t->set_var('table_sep',"</td>");
701 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
702 $this->t->fp('list','part_list',True);
705 $this->t->pfp('out','act_view_t');
706 $this->save_sessiondata();
709 function act_update()
711 $this->t->set_file(array('form' => 'act_update.tpl'));
712 $this->t->set_block('form','individual_list','list');
713 $this->t->set_block('form','add','addhandle');
714 $this->t->set_block('form','edit','edithandle');
715 $this->t->set_var('lang_done','Done');
717 $action = get_var('action',array('GET','POST'));
718 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_list'));
719 $activity['activity'] = intval(get_var('activity',array('GET','POST')));
721 if($action == 'save') {
722 $activity['assignment'] = get_var('assignment',array('POST'));
723 $activity['date'] = get_var('date',array('POST'));
724 $activity['notes']= get_var('notes',array('POST'));
725 $this->db->query("UPDATE tc_activity set " .
726 " assignment='" . $activity['assignment'] .
727 "', date='" . $activity['date'] . "'" .
728 ", notes='" . $activity['notes'] . "'" .
729 " WHERE activity=" . $activity['activity'],__LINE__,__FILE__);
731 // Delete all the individuals who have particiapted in this activity
732 $this->db->query("DELETE from tc_participation where activity=".$activity['activity'],__LINE__,__FILE__);
734 // Re-add the individuals who are checked as having participated in this activity
735 $indivs = get_var('individual_name',array('POST'));
736 if(is_array($indivs)) { // Only do the foreach loop if we have a valid array of indivs to work with
737 foreach ($indivs as $individual) {
738 $this->db->query("INSERT INTO tc_participation (individual,activity) " .
739 "VALUES (" . $individual . ",". $activity['activity'] . ")",__LINE__,__FILE__);
747 if($action == 'insert') {
748 $activity['assignment'] = get_var('assignment',array('POST'));
749 $activity['date'] = get_var('date',array('POST'));
750 $activity['notes']= get_var('notes',array('POST'));
751 $this->db->query("INSERT INTO tc_activity (assignment,date,notes) " .
752 "VALUES ('" . $activity['assignment'] . "','" .
753 $activity['date'] . "','" . $activity['notes'] . "')",__LINE__,__FILE__);
755 $sql = "SELECT * FROM tc_activity WHERE assignment='".$activity['assignment']."' " .
756 " AND date='".$activity['date']."' AND notes='".$activity['notes']."'";
757 $this->db->query($sql,__LINE__,__FILE__);
758 if($this->db->next_record()) {
759 //print "activity: " . $this->db->f('activity') . "<br>";
760 $activity['activity'] = $this->db->f('activity');
763 $indivs = get_var('individual_name',array('POST'));
764 foreach ($indivs as $individual)
766 $this->db->query("INSERT INTO tc_participation (individual,activity) " .
767 "VALUES (" . $individual . ",". $activity['activity'] . ")",__LINE__,__FILE__);
774 if($action == 'add') {
775 $activity['activity'] = 0;
776 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
777 $this->t->set_var('assignment','');
778 $this->t->set_var('date','');
779 $this->t->set_var('notes','');
780 $this->t->set_var('lang_done','Cancel');
781 $this->t->set_var('lang_action','Adding New Activity');
782 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_update&activity=' .
783 $activity['activity'] . '&action=' . 'insert'));
786 if($action == 'edit') {
787 $sql = "SELECT * FROM tc_activity WHERE activity=" . $activity['activity'];
788 $this->db->query($sql,__LINE__,__FILE__);
789 $this->db->next_record();
790 $this->t->set_var('cal_date',$this->jscal->input('date',$this->db->f('date'),'','','','','',$this->cal_options));
791 $this->t->set_var('assignment', $this->db->f('assignment'));
792 $assignment = $this->db->f('assignment');
793 $this->t->set_var('date', $this->db->f('date'));
794 $this->t->set_var('notes', $this->db->f('notes'));
795 $this->t->set_var('lang_done','Cancel');
796 $this->t->set_var('lang_action','Editing Activity');
797 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_update&activity=' .
798 $activity['activity'] . '&action=' . 'save'));
801 // Create the assignments drop-down list
802 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
803 $this->db->query($sql,__LINE__,__FILE__);
805 while ($this->db->next_record()) {
806 $assignments[$i]['assignment'] = $this->db->f('assignment');
807 $assignments[$i]['name'] = $this->db->f('name');
808 $assignments[$i]['abbreviation'] = $this->db->f('abbreviation');
812 $assignment_data.= '<select name=assignment>';
813 $assignment_data.= '<option value=0></option>';
814 for ($j=0; $j < count($assignments); $j++) {
815 $id = $assignments[$j]['assignment'];
816 $name = $assignments[$j]['name'];
817 if($assignments[$j]['assignment'] == $assignment) {
818 $selected[$id] = 'selected="selected"';
822 $assignment_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
824 $assignment_data.='</select>';
825 $this->t->set_var('assignment_data',$assignment_data);
827 // Create individual selection boxes
828 $sql = "SELECT * FROM tc_individual";
829 $this->db->query($sql,__LINE__,__FILE__);
831 while ($this->db->next_record()) {
832 if($this->db->f('valid') == 1 || $action != 'add') {
833 $indiv_name[$i] = $this->db->f('name');
834 $individual[$i] = $this->db->f('individual');
835 $indiv_valid[$i] = $this->db->f('valid');
839 array_multisort($indiv_name, $individual, $indiv_valid);
842 for ($i=0; $i < count($individual); $i++) {
843 //$this->nextmatchs->template_alternate_row_color(&$this->t);
844 $sql = "SELECT * FROM tc_participation where activity=". $activity['activity'] . " AND individual=" . $individual[$i];
845 $this->db->query($sql,__LINE__,__FILE__);
846 if($this->db->next_record()) {
847 $this->t->set_var('checked','checked');
850 $this->t->set_var('checked','');
853 if($checked || $indiv_valid[$i] == 1) {
854 $this->t->set_var('individual_name',$indiv_name[$i]);
855 $this->t->set_var('individual',$individual[$i]);
856 if(($j+1) % 3 == 0) {
857 $this->t->set_var('table_sep',"</td></tr><tr>");
859 $this->t->set_var('table_sep',"</td>");
861 if(($j) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
862 $this->t->fp('list','individual_list',True);
867 $this->t->set_var('lang_reset','Clear Form');
868 $this->t->set_var('lang_add','Add Activity');
869 $this->t->set_var('lang_save','Save Changes');
870 $this->t->set_var('edithandle','');
871 $this->t->set_var('addhandle','');
873 $this->t->pfp('out','form');
874 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
875 if($action == 'add') { $this->t->pfp('addhandle','add'); }
877 $this->save_sessiondata();
880 function assign_view()
882 $this->t->set_file(array('assign_view_t' => 'assign_view.tpl'));
883 $this->t->set_block('assign_view_t','assign_view','list');
885 $this->t->set_var('lang_name','Assignment Name');
886 $this->t->set_var('lang_code','Abbreviation');
888 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
889 $this->db->query($sql,__LINE__,__FILE__);
890 $total_records = $this->db->num_rows();
893 while ($this->db->next_record()) {
894 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
895 $assignment_list[$i]['name'] = $this->db->f('name');
896 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
900 for ($i=0; $i < count($assignment_list); $i++) {
901 $this->nextmatchs->template_alternate_row_color(&$this->t);
902 $this->t->set_var('name',$assignment_list[$i]['name']);
903 $this->t->set_var('abbreviation',$assignment_list[$i]['abbreviation']);
905 $link_data['menuaction'] = 'tc.tc.assign_update';
906 $link_data['assignment'] = $assignment_list[$i]['assignment'];
907 $link_data['action'] = 'edit';
908 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
909 $this->t->set_var('lang_edit','Edit');
911 $link_data['menuaction'] = 'tc.tc.assign_update';
912 $link_data['assignment'] = '0';
913 $link_data['action'] = 'add';
914 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/tc/index.php',$link_data) .
915 '"><input type="submit" name="Add" value="' . 'Add Assignment' .'"></font></form>');
917 $this->t->fp('list','assign_view',True);
920 $this->t->pfp('out','assign_view_t');
921 $this->save_sessiondata();
924 function assign_update()
926 $this->t->set_file(array('form' => 'assign_update.tpl'));
927 $this->t->set_block('form','add','addhandle');
928 $this->t->set_block('form','edit','edithandle');
929 $this->t->set_var('lang_done','Done');
931 $action = get_var('action',array('GET','POST'));
932 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_view'));
933 $assignment['assignment'] = intval(get_var('assignment',array('GET','POST')));
935 if($action == 'save') {
936 $assignment['name'] = get_var('name',array('POST'));
937 $assignment['abbreviation'] = get_var('abbreviation',array('POST'));
938 $this->db->query("UPDATE tc_assignment set " .
939 " name='" . $assignment['name'] . "'" .
940 ", abbreviation='" . $assignment['abbreviation'] . "'" .
941 " WHERE assignment=" . $assignment['assignment'],__LINE__,__FILE__);
943 $this->assign_view();
947 if($action == 'insert') {
948 $assignment['name'] = get_var('name',array('POST'));
949 $assignment['abbreviation'] = get_var('abbreviation',array('POST'));
950 $this->db->query("INSERT INTO tc_assignment (name,abbreviation) " .
951 "VALUES ('" . $assignment['name'] . "','" .
952 $assignment['abbreviation'] . "')",__LINE__,__FILE__);
953 $this->assign_view();
957 if($action == 'add') {
958 $assignment['assignment'] = 0;
959 $this->t->set_var('name','');
960 $this->t->set_var('abbreviation','');
961 $this->t->set_var('lang_done','Cancel');
962 $this->t->set_var('lang_action','Adding New Assignment');
963 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_update&assignment=' .
964 $assignment['assignment'] . '&action=' . 'insert'));
967 if($action == 'edit')
969 $sql = "SELECT * FROM tc_assignment WHERE assignment=" . $assignment['assignment'];
970 $this->db->query($sql,__LINE__,__FILE__);
971 $this->db->next_record();
972 $this->t->set_var('name', $this->db->f('name'));
973 $this->t->set_var('abbreviation', $this->db->f('abbreviation'));
974 $this->t->set_var('lang_done','Cancel');
975 $this->t->set_var('lang_action','Editing Assignment');
976 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_update&assignment=' .
977 $assignment['assignment'] . '&action=' . 'save'));
980 $this->t->set_var('lang_reset','Clear Form');
981 $this->t->set_var('lang_add','Add Assignment');
982 $this->t->set_var('lang_save','Save Changes');
983 $this->t->set_var('edithandle','');
984 $this->t->set_var('addhandle','');
986 $this->t->pfp('out','form');
987 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
988 if($action == 'add') { $this->t->pfp('addhandle','add'); }
990 $this->save_sessiondata();
995 $this->t->set_file(array('par_view_t' => 'par_view.tpl'));
996 $this->t->set_block('par_view_t','header_list','list1');
997 $this->t->set_block('par_view_t','individual_list','list2');
999 // TODO: changed this so it picks the quorum dynamically
1000 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1";
1001 $this->db->query($sql,__LINE__,__FILE__);
1003 while ($this->db->next_record()) {
1004 $individual_name[$i] = $this->db->f('name');
1005 $individual[$i] = $this->db->f('individual');
1008 array_multisort($individual_name, $individual);
1010 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
1011 $this->db->query($sql,__LINE__,__FILE__);
1012 $total_records = $this->db->num_rows();
1015 while ($this->db->next_record()) {
1016 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1017 $activity_list[$i]['date'] = $this->db->f('date');
1018 $activity_list[$i]['activity'] = $this->db->f('activity');
1022 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1023 $this->db->query($sql,__LINE__,__FILE__);
1025 while($this->db->next_record()) {
1026 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1027 $assignment_list[$i]['name'] = $this->db->f('name');
1028 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1032 $individual_width=300; $part_width=25; $assignment_width=50;
1033 $total_width=$individual_width+$part_width;
1034 for ($i=0; $i < count($assignment_list); $i++) {
1035 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1036 $this->t->set_var('assignment_abbreviation',$assignment_list[$i]['abbreviation']);
1037 $this->t->fp('list1','header_list',True);
1038 $total_width += $assignment_width;
1041 for ($i=0; $i < count($individual); $i++) {
1042 $participated=0; $part_table = '';
1043 $this->nextmatchs->template_alternate_row_color(&$this->t);
1044 $this->t->set_var('individual_name',$individual_name[$i]);
1045 for ($j=0; $j < count($assignment_list); $j++) {
1046 $date = "0000-00-00"; $checkmark=0; $num_matches=0;
1047 for ($k=0; $k < count($activity_list); $k++) {
1048 if($assignment_list[$j]['assignment'] == $activity_list[$k]['assignment']) {
1049 $sql = "SELECT * FROM tc_participation where " .
1050 " activity=" . $activity_list[$k]['activity'] .
1051 " AND individual=" . $individual[$i];
1052 $this->db->query($sql,__LINE__,__FILE__);
1053 while($this->db->next_record()) {
1054 if($activity_list[$k]['date'] > $date) {
1055 $date = $activity_list[$k]['date'];
1064 $part_table .= '<td align=center><img src="images/checkmark.gif">';
1065 $part_table .= '<font size=-2>'.$num_matches.'</font><br>';
1066 $part_table .= '<font size=-2>'.$date.'</font></td>';
1068 $part_table .= '<td> </td>';
1072 $part_table .= '<td align=center><img src="images/checkmark.gif">'.$participated.'</td>';
1074 $part_table .= '<td> </td>';
1076 $this->t->set_var('part_table',$part_table);
1077 $this->t->fp('list2','individual_list',True);
1079 $this->t->set_var('total_width',$total_width);
1080 $this->t->set_var('individual_width',$individual_width);
1081 $this->t->set_var('part_width',$part_width);
1082 $this->t->set_var('act_width',$act_width);
1083 $this->t->pfp('out','par_view_t');
1084 $this->save_sessiondata();
1087 function willing_view()
1089 $this->t->set_file(array('willing_view_t' => 'willing_view.tpl'));
1090 $this->t->set_block('willing_view_t','header_list','list1');
1091 $this->t->set_block('willing_view_t','individual_list','list2');
1093 $this->t->set_var('lang_filter','Filter');
1094 $this->t->set_var('lang_filter_unwilling','Filter out unwilling individuals:');
1096 $filter_unwilling = get_var('filter_unwilling',array('POST'));
1097 $this->t->set_var('filter_unwilling',$filter_unwilling);
1099 if($filter_unwilling == 'y' || $filter_unwilling == '') {
1100 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\" checked>Y";
1101 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\">N";
1102 $filter_input.= " ";
1104 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\">Y";
1105 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\" checked>N";
1106 $filter_input.= " ";
1108 $this->t->set_var('filter_input',$filter_input);
1110 // TODO: changed this so it picks the quorum dynamically
1111 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1";
1112 $this->db->query($sql,__LINE__,__FILE__);
1114 while ($this->db->next_record()) {
1115 $indiv_name[$i] = $this->db->f('name');
1116 $individual[$i] = $this->db->f('individual');
1117 $indiv_phone[$individual[$i]] = $this->db->f('phone');
1120 array_multisort($indiv_name, $individual);
1122 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1123 $this->db->query($sql,__LINE__,__FILE__);
1125 while($this->db->next_record()) {
1126 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1127 $assignment_list[$i]['name'] = $this->db->f('name');
1128 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1132 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
1133 $this->db->query($sql,__LINE__,__FILE__);
1134 $total_records = $this->db->num_rows();
1137 while ($this->db->next_record()) {
1138 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1139 $activity_list[$i]['date'] = $this->db->f('date');
1140 $activity_list[$i]['activity'] = $this->db->f('activity');
1144 $indiv_width=275; $willing_width=40; $assignment_width=50;
1145 $total_width=$indiv_width+$willing_width;
1147 for ($i=0; $i < count($assignment_list); $i++) {
1148 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1149 $this->t->set_var('assignment_abbreviation',$assignment_list[$i]['abbreviation']);
1150 $this->t->fp('list1','header_list',True);
1151 $total_width += $assignment_width;
1152 $total_willing[$i] = 0;
1155 for ($i=0; $i < count($individual); $i++) {
1156 $willing_table = ''; $indiv_willing=0;
1157 $this->t->set_var('individual_name',$indiv_name[$i]);
1158 $this->t->set_var('individual_phone',$indiv_phone[$individual[$i]]);
1159 $this->t->set_var('editurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_update&individual=' .
1160 $individual[$i] . '&action=' . 'edit'));
1161 for ($j=0; $j < count($assignment_list); $j++) {
1162 $found_willingness=0;
1163 $sql = "SELECT * FROM tc_willingness where " .
1164 " assignment=" . $assignment_list[$j]['assignment'] .
1165 " AND individual=" . $individual[$i];
1166 $this->db->query($sql,__LINE__,__FILE__);
1167 while($this->db->next_record()) {
1168 $found_willingness=1;
1170 $sql = "SELECT * FROM tc_activity where " .
1171 " assignment=". $assignment_list[$j]['assignment'] .
1172 " ORDER by date DESC";
1173 $this->db2->query($sql,__LINE__,__FILE__);
1174 if($this->db2->next_record()) {
1175 $activity = $this->db2->f('activity');
1176 $date = $this->db2->f('date');
1177 $sql = "SELECT * FROM tc_participation where " .
1178 " activity=" . $activity .
1179 " AND individual=". $individual[$i];
1180 $this->db3->query($sql,__LINE__,__FILE__);
1181 if($this->db3->next_record()) {
1186 if($this->db->f('willing') == 'y') {
1187 $total_willing[$j]++;
1189 $willing_table .= '<td align=center><img src="images/checkmark.gif"><br><font size=-2>'.$date_part.'</font></td></td>';
1190 } else if($this->db->f('willing') == 'n') {
1191 $willing_table .= '<td align=center><img src="images/x.gif"></td>';
1194 $willing_table .= "<td> </td>";
1197 if(!$found_willingness) {
1199 $willing_table .= "<td> </td>";
1202 if(($indiv_willing == 1) || ($filter_unwilling == 'n')) {
1203 $this->t->set_var('willing_table',$willing_table);
1204 $this->t->fp('list2','individual_list',True);
1205 $this->nextmatchs->template_alternate_row_color(&$this->t);
1209 $stat_table = '<td><b>Total Willing to Serve</b></td>';
1210 for ($j=0; $j < count($assignment_list); $j++) {
1211 $stat_table .= "<td align=center><b>".$total_willing[$j]."</b></td>";
1213 $this->t->set_var('stat_table',$stat_table);
1215 $this->t->set_var('total_width',$total_width);
1216 $this->t->set_var('individual_width',$indiv_width);
1217 $this->t->set_var('willing_width',$willing_width);
1218 $this->t->pfp('out','willing_view_t');
1219 $this->save_sessiondata();
1222 function willing_update()
1224 //print "<font color=red>Willingness Update Under Constrcution</font>";
1225 //$this->willing_view();
1228 $this->t->set_file(array('willing_update_t' => 'willing_update.tpl'));
1229 $this->t->set_block('willing_update_t','assignment_list','list');
1230 $this->t->set_block('willing_update_t','save','savehandle');
1232 $individual = get_var('individual',array('GET','POST'));
1233 $this->t->set_var('individual',$individual);
1234 $action = get_var('action',array('GET','POST'));
1236 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_view'));
1237 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_update&action=save'));
1238 $this->t->set_var('lang_done','Cancel');
1239 $this->t->set_var('title','Willingness Update ');
1241 if($action == 'save') {
1242 // Delete all the previous willingness entries for this individual
1243 $this->db->query("DELETE from tc_willingness where individual=" . $individual ,__LINE__,__FILE__);
1245 // Now, add the assignment willingness that is checked for this individual
1246 $new_data = get_var('willingness',array('POST'));
1247 foreach ($new_data as $data) {
1248 $data_array = explode("/",$data);
1249 $assignment = $data_array[0];
1250 $willing = $data_array[1];
1251 //print "individual: $individual assignment: $assignment willing: $willing<br>";
1252 $this->db->query("INSERT INTO tc_willingness (individual,assignment,willing) " .
1253 "VALUES (" . $individual .",". $assignment .",'". $willing . "')",__LINE__,__FILE__);
1255 $this->willing_view();
1259 $assignment_width=300; $willing_width=25; $table_width=$assignment_width + $willing_width;
1262 // Find out the individual's name
1263 $sql = "SELECT * FROM tc_individual WHERE individual=".$individual." AND valid=1";
1264 $this->db->query($sql,__LINE__,__FILE__);
1265 if($this->db->next_record()) {
1266 $indiv_name = $this->db->f('name');
1267 $this->t->set_var('individual_name',$indiv_name);
1270 // Select all the assignments
1271 $sql = "SELECT * FROM tc_assignment ORDER by name ASC";
1272 $this->db->query($sql,__LINE__,__FILE__);
1274 while ($this->db->next_record()) {
1275 $assignment = $this->db->f('assignment');
1276 $assignment_name = $this->db->f('name');
1277 $assignment_abbreviation = $this->db->f('abbreviation');
1279 $this->nextmatchs->template_alternate_row_color(&$this->t);
1280 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$assignment_name</td>";
1282 $header_row="<th width=$comp_width><font size=-2>Assignments</th><th>Willingness</th>";
1283 $sql = "SELECT * FROM tc_willingness WHERE individual=".$individual." AND assignment=".$assignment;
1284 $this->db2->query($sql,__LINE__,__FILE__);
1285 $value = $assignment;
1287 if($this->db2->next_record()) {
1288 if($this->db2->f('willing') == 'y') {
1289 $table_data .= '<td width=100 align=center>';
1290 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y" checked>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.'/"> ';
1293 $table_data .= '</td>';
1294 } else if($this->db2->f('willing') == 'n') {
1295 $table_data .= '<td width=100 align=center>';
1296 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1297 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n" checked>N';
1298 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/">';
1299 $table_data .= '</td>';
1301 $table_data .= '<td width=100 align=center>';
1302 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1303 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1304 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1305 $table_data .= '</td>';
1308 $table_data .= '<td width=100 align=center>';
1309 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1310 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1311 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1312 $table_data .= '</td>';
1315 $table_data .= "\n";
1316 $table_data .= "</tr>";
1317 $table_data .= "<tr><td colspan=20></td></tr>";
1320 $table_data .= "<tr><td colspan=20><hr></td></tr>";
1322 $this->t->set_var('table_width',$table_width);
1323 $this->t->set_var('header_row',$header_row);
1324 $this->t->set_var('table_data',$table_data);
1325 $this->t->fp('list','assignment_list',True);
1327 $this->t->set_var('lang_reset','Clear Form');
1328 $this->t->set_var('lang_save','Save Changes');
1329 $this->t->set_var('savehandle','');
1331 $this->t->pfp('out','willing_update_t');
1332 $this->t->pfp('addhandle','save');
1334 $this->save_sessiondata();
1338 function ppi_sched()
1340 $this->t->set_file(array('ppi_sched_t' => 'ppi_sched.tpl'));
1341 $this->t->set_block('ppi_sched_t','individual_list','indivlist');
1342 $this->t->set_block('ppi_sched_t','appt_list','apptlist');
1343 $action = get_var('action',array('GET','POST'));
1345 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1346 $this->t->set_var('lang_reset','Clear Changes');
1348 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
1349 $this->t->set_var('ppi_link_title','Yearly PPIs');
1351 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
1352 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
1354 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched&action=save'));
1355 $this->t->set_var('title','Yearly PPI Scheduler');
1357 $indiv_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $ppi_date_width=20;
1358 $table_width=$indiv_width + $phone_width + $pri_width + $notes_width + $ppi_date_width;
1359 $header_row = "<th width=$indiv_width><font size=-2>individual Name</th>";
1360 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1361 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1362 $header_row.= "<th width=$ppi_date_width><font size=-2>Last PPI</th>";
1363 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1364 $table_data=""; $completed_data=""; $totals_data="";
1368 // Get the President
1369 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti where tp.individual=ti.individual AND tp.president=1 AND tp.valid=1";
1370 $this->db->query($sql,__LINE__,__FILE__);
1371 if($this->db->next_record()) {
1372 $president_name = $this->db->f('name');
1373 $president_name_array = explode(",",$president_name);
1374 $president_last_name = $president_name_array[0];
1375 $president_id = $this->db->f('individual');
1376 $presidency_id = $this->db->f('presidency');
1377 $interviewer = $this->db->f('individual');
1378 $district_number = '*';
1379 $district_name = $president_name;
1380 $president_address = $this->db->f('address');
1382 print "<hr><font color=red><h3>-E- Unable to locate President in tc_presidency table</h3></font></hr>";
1386 if($action == 'save') {
1387 // Save any changes made to the appointment table
1388 $new_data = get_var('appt_notes',array('POST'));
1389 if($new_data != "") {
1390 foreach ($new_data as $entry) {
1391 $indiv = $entry['individual'];
1392 $appointment = $entry['appointment'];
1393 $location = $entry['location'];
1394 if($location == "") { $location = "$president_last_name"." home ($president_address)"; }
1395 if($indiv == 0) { $location = ""; }
1397 //Only perform a database update if we have made a change to this appointment
1398 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and individual='$indiv' and location='$location'";
1399 $this->db->query($sql,__LINE__,__FILE__);
1400 if(!$this->db->next_record()) {
1401 // Perform database save actions here
1402 $this->db->query("UPDATE tc_appointment set " .
1403 " individual='" . $indiv . "'" .
1404 ",location='" . $location . "'" .
1405 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1406 // Email the appointment
1407 $this->email_appt($appointment);
1412 // Save any changes made to the ppi notes table
1413 $new_data = get_var('notes',array('POST'));
1414 foreach ($new_data as $entry) {
1415 $notes = $entry['notes'];
1416 $individual = $entry['individual'];
1417 $priority = $entry['pri'];
1419 // Perform database save actions here
1420 $sql = "SELECT * FROM tc_individual WHERE individual='$individual'";
1421 $this->db->query($sql,__LINE__,__FILE__);
1422 if ($this->db->next_record()) {
1423 $scheduling_priority = $this->db->f('scheduling_priority');
1424 //$this->logToFile("ppi_sched", "UPDATE tc_scheduling_priority SET priority='$priority', notes=\"$notes\" WHERE scheduling_priority='$scheduling_priority'");
1425 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$priority', notes=\"$notes\" WHERE scheduling_priority='$scheduling_priority'", __LINE__, __FILE__);
1429 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched');
1430 //Header('Location: ' . $take_me_to_url);
1433 // create the individual id -> individual name mapping
1434 // TODO: changed this so it picks the quorum dynamically
1435 $sql = "SELECT * FROM tc_individual where valid=1 and steward='Elder' ORDER BY name ASC";
1436 $this->db->query($sql,__LINE__,__FILE__);
1440 while ($this->db->next_record()) {
1441 $indiv_name[$i] = $this->db->f('name');
1442 $individual[$i] = $this->db->f('individual');
1445 array_multisort($indiv_name, $individual);
1447 // APPOINTMENT TABLE
1448 $date_width=250; $time_width=100; $indiv_width=200; $location_width=100;
1449 $appt_table_width=$date_width + $time_width + $indiv_width + $location_width;
1450 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1451 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1452 $appt_header_row.= "<th width=$indiv_width><font size=-2>indiv</th>";
1453 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
1454 $appt_table_data = "";
1456 $total_indivs=0; $indivs_with_yearly_ppi=0;
1458 // Display a scheduling table for the President
1459 $table_data=""; $appt_table_data="";
1460 $table_title = "District ".$district_number.": ".$district_name.": All indivs with Yearly PPI Not Completed";
1461 $appt_table_title = "District ".$district_number.": ".$district_name.": Yearly PPI Appointment Slots";
1462 $this->t->set_var('table_title',$table_title);
1463 $this->t->set_var('appt_table_title',$appt_table_title);
1465 // query the database for all the appointments
1466 $sql = "SELECT * FROM tc_appointment where presidency=".$presidency_id." and date>=CURDATE() ORDER BY date ASC, time ASC";
1467 $this->db->query($sql,__LINE__,__FILE__);
1469 while ($this->db->next_record()) {
1470 $appointment = $this->db->f('appointment');
1471 $indiv = $this->db->f('individual');
1472 $location = $this->db->f('location');
1473 if(($location == "") && ($indiv > 0)) { $location = "$president_last_name"." home ($president_address)"; }
1475 $date = $this->db->f('date');
1476 $date_array = explode("-",$date);
1477 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1478 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1480 $time = $this->db->f('time');
1481 $time_array = explode(":",$time);
1482 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1484 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1485 $appt_table_data.= "<td align=center>$day_string</td>";
1486 $appt_table_data.= "<td align=center>$time_string</td>";
1488 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][individual]>';
1489 $appt_table_data.= '<option value=0></option>';
1490 for ($i=0; $i < count($individual); $i++) {
1491 $id = $individual[$i];
1492 $name = $indiv_name[$i];
1493 if($individual[$i] == $indiv) {
1494 $selected[$id] = 'selected="selected"';
1496 $selected[$id] = '';
1498 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1500 $appt_table_data.='</select></td>';
1502 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
1503 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
1505 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1507 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1508 $this->t->set_var('tr_color',$tr_color);
1511 $this->t->set_var('appt_table_data',$appt_table_data);
1512 $this->t->set_var('appt_header_row',$appt_header_row);
1513 $this->t->set_var('appt_table_width',$appt_table_width);
1515 // PPI SCHEDULING TABLE
1516 // TODO: changed this so it picks the quorum dynamically
1517 $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";
1518 $this->db->query($sql,__LINE__,__FILE__);
1522 while ($this->db->next_record()) {
1523 $individual[$i] = $this->db->f('individual');
1524 $indiv_name[$i] = $this->db->f('name');
1525 $indiv_phone[$individual[$i]] = $this->db->f('phone');
1526 $indiv_priority[$individual[$i]] = $this->db->f('priority');
1527 $indiv_notes[$individual[$i]] = $this->db->f('notes');
1532 $max = count($individual);
1534 for($i=0; $i < $max; $i++) {
1535 $id = $individual[$i];
1536 $name = $indiv_name[$i];
1537 $phone = $indiv_phone[$id];
1538 $priority = $indiv_priority[$id];
1539 $notes = $indiv_notes[$id];
1541 // If this individual has had a yearly PPI this year, don't show him on the schedule list
1542 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
1543 $sql = "SELECT * FROM tc_interview WHERE date > '$year_start' AND date < '$year_end' ".
1544 "AND individual=" . $id . " AND interview_type='ppi'";
1545 $this->db2->query($sql,__LINE__,__FILE__);
1547 if(!$this->db2->next_record()) {
1548 $sql = "SELECT * FROM tc_interview WHERE individual=" . $id . " AND interview_type='ppi' ORDER BY date DESC";
1549 $this->db->query($sql,__LINE__,__FILE__);
1550 if($this->db->next_record()) {
1551 $date = $this->db->f('date');
1555 $link_data['menuaction'] = 'tc.tc.ppi_update';
1556 $link_data['individual'] = $id;
1557 $link_data['name'] = $name;
1558 $link_data['interview'] = '';
1559 $link_data['interview_type'] = 1;
1560 $link_data['action'] = 'add';
1561 $link_data['interviewer'] = $interviewer;
1562 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1563 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1564 $this->t->set_var('tr_color',$tr_color);
1565 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1566 $table_data.= "<td align=center>$phone</td>";
1567 //$table_data.= "<td align=center>$priority</td>";
1568 $table_data.= "<td align=center>";
1569 $table_data.= '<select name=notes['.$i.'][pri]>';
1570 foreach(range(0,6) as $num) {
1571 if($num == 0) { $num = 1; } else {$num = $num*5; }
1572 if($priority == $num) {
1573 $selected[$num] = 'selected="selected"';
1575 $selected[$num] = '';
1577 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1579 $table_data.= '</select></td>';
1580 $table_data.= "<td align=center>$date</td>";
1581 $table_data.= '<td><input type=text size="50" maxlength="128" name="notes['.$i.'][notes]" value="'.$notes.'">';
1582 $table_data.= '<input type=hidden name="notes['.$i.'][individual]" value="'.$id.'">';
1583 $table_data.= '<input type=hidden name="notes['.$i.'][indiv_name]" value="'.$name.'">';
1584 $table_data.= '</td>';
1585 $table_data.= '</tr>';
1587 $link_data['menuaction'] = 'tc.tc.ppi_update';
1588 $link_data['interviewer'] = $this->db2->f('interviewer');
1589 $link_data['individual'] = $this->db2->f('individual');
1590 $link_data['name'] = $name;
1591 $link_data['interview'] = $this->db2->f('interview');
1592 $link_data['interview_type'] = $this->db2->f('interview_type');
1593 $link_data['action'] = 'view';
1594 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1595 $indivs_with_yearly_ppi++;
1596 $date = $this->db2->f('date');
1597 $notes = $this->db2->f('notes');
1598 if(strlen($notes) > 40) { $notes = substr($notes,0,40) . "..."; }
1599 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1600 $this->t->set_var('tr_color2',$tr_color2);
1601 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1602 $completed_data.= "<td align=center>$phone</td>";
1603 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1604 $completed_data.= "<td align=left>$notes</td>";
1605 $completed_data.= '</tr>';
1607 } // End for individuals Loop
1609 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1610 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1611 $completed_header_row = "<th width=$name_width><font size=-2>Individual Name</th>";
1612 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1613 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1614 $completed_header_row.= "<th width=$notes_width><font size=-2>PPI Notes</th>";
1616 $this->t->set_var('table_width',$table_width);
1617 $this->t->set_var('header_row',$header_row);
1618 $this->t->set_var('table_data',$table_data);
1619 $this->t->set_var('completed_header_row',$completed_header_row);
1620 $this->t->set_var('completed_table_width',$completed_table_width);
1621 $this->t->set_var('completed',$completed_data);
1622 $this->t->fp('indivlist','individual_list',True);
1624 $indivs_width=300; $totals_width=100;
1625 $totals_table_width=$indivs_width + $totals_width;
1626 $totals_header_row = "<th width=$indivs_width><font size=-2>Individuals</th>";
1627 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
1628 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1629 $totals_data.= "<td align=left><font size=-2><b>Total Individuals with yearly PPIs completed:</b></font></td>";
1630 $totals_data.= "<td align=center><font size=-2><b>$indivs_with_yearly_ppi / $total_indivs</b></font></td>";
1631 $percent = ceil(($indivs_with_yearly_ppi / $total_indivs)*100);
1632 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1633 $this->t->set_var('tr_color',$tr_color);
1634 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1635 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
1636 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
1637 $totals_data.= "</tr>";
1639 $this->t->set_var('totals',$totals_data);
1640 $this->t->set_var('totals_header_row',$totals_header_row);
1641 $this->t->set_var('totals_table_width',$totals_table_width);
1643 $this->t->pfp('out','ppi_sched_t');
1644 $this->save_sessiondata();
1648 function int_sched()
1650 $this->t->set_file(array('int_sched_t' => 'int_sched.tpl'));
1651 $this->t->set_block('int_sched_t','individual_list','indivlist');
1652 $this->t->set_block('int_sched_t','appt_list','apptlist');
1653 $action = get_var('action',array('GET','POST'));
1655 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1656 $this->t->set_var('lang_reset','Clear Changes');
1658 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
1659 $this->t->set_var('int_link_title','Hometeaching Interviews');
1661 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
1662 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
1664 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched&action=save'));
1665 $this->t->set_var('title','Hometeaching Interviews Scheduler');
1667 $indiv_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $int_date_width=20;
1668 $table_width=$indiv_width + $phone_width + $pri_width + $notes_width + $int_date_width;
1669 $header_row = "<th width=$indiv_width><font size=-2>individual Name</th>";
1670 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1671 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1672 $header_row.= "<th width=$int_date_width><font size=-2>Last Interview</th>";
1673 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1674 $table_data=""; $completed_data=""; $totals_data="";
1678 $nextyear = $year + 1;
1679 if($month >= 1 && $month <= 3) { $quarter_start=$year."-01-01"; $quarter_end=$year."-04-01"; }
1680 if($month >= 4 && $month <= 6) { $quarter_start=$year."-04-01"; $quarter_end=$year."-07-01"; }
1681 if($month >= 7 && $month <= 9) { $quarter_start=$year."-07-01"; $quarter_end=$year."-10-01"; }
1682 if($month >= 10 && $month <= 12) { $quarter_start=$year."-10-01"; $quarter_end=$nextyear."-01-01"; }
1683 //print "year: $year month: $month quarter_start: $quarter_start quarter_end: $quarter_end<br>";
1685 // create the individual id -> individual name mapping
1686 // TODO: changed this so it picks the quorum dynamically
1687 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1 ORDER BY name ASC";
1688 $this->db->query($sql,__LINE__,__FILE__);
1690 $individual_data = NULL;
1691 $indiv_name_data = NULL;
1692 while ($this->db->next_record()) {
1693 $indiv_name_data[$i] = $this->db->f('name');
1694 $individual_data[$i] = $this->db->f('individual');
1695 $individ2name[$individual_data[$i]] = $indiv_name_data[$i];
1698 // add any YM that are home teachers
1699 $sql = "SELECT * FROM tc_companionship where valid=1";
1700 $this->db->query($sql,__LINE__,__FILE__);
1701 while ($this->db->next_record()) {
1702 $tmp_individual = $this->db->f('individual');
1703 $sql = "Select * FROM tc_individual where individual='$tmp_individual' and steward='' and valid=1";
1704 $this->db2->query($sql,__LINE__,__FILE__);
1705 while ($this->db2->next_record()) {
1706 $indiv_name_data[$i] = $this->db2->f('name');
1707 $individual_data[$i] = $this->db2->f('individual');
1708 $individ2name[$individual_data[$i]] = $indiv_name_data[$i];
1712 array_multisort($indiv_name_data, $individual_data);
1714 if($action == 'save') {
1715 // Save any changes made to the appointment table
1716 $new_data = get_var('appt_notes',array('POST'));
1717 if($new_data != "") {
1718 foreach ($new_data as $entry) {
1719 $indiv = $entry['individual'];
1720 $appointment = $entry['appointment'];
1721 $location = $entry['location'];
1722 if($location == "") {
1723 $supervisor = $entry['supervisor'];
1724 $supervisor_array = explode(",", $individ2name[$supervisor]);
1725 $supervisor_last_name = $supervisor_array[0];
1726 $sql = "SELECT * FROM tc_individual where individual='$supervisor'";
1727 $this->db2->query($sql,__LINE__,__FILE__);
1728 if($this->db2->next_record()) {
1729 $mls_id = $this->db2->f('mls_id');
1731 $sql = "SELECT * FROM tc_individual where mls_id='$mls_id'";
1732 $this->db2->query($sql,__LINE__,__FILE__);
1733 if($this->db2->next_record()) {
1734 $supervisor_address = $this->db2->f('address');
1736 $location = "$supervisor_last_name"." home ($supervisor_address)";
1738 if($indiv == 0) { $location = ""; }
1740 //print "indiv: $indiv appointment: $appointment <br>";
1741 //Only perform a database update if we have made a change to this appointment
1742 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and individual='$indiv' and location='$location'";
1743 $this->db->query($sql,__LINE__,__FILE__);
1744 if(!$this->db->next_record()) {
1745 // Perform database save actions here
1746 $this->db->query("UPDATE tc_appointment set " .
1747 " individual='" . $indiv . "'" .
1748 ",location='" . $location . "'" .
1749 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1750 // Email the appointment
1751 $this->email_appt($appointment);
1756 // Save any changes made to the int notes table
1757 $new_data = get_var('hti_notes',array('POST'));
1758 foreach ($new_data as $entry) {
1759 $hti_notes = $entry['notes'];
1760 $individual = $entry['individual'];
1761 $indiv_name = $entry['indiv_name'];
1762 $hti_pri = $entry['pri'];
1763 //print "hti_notes: $hti_notes indiv_name: $indiv_name <Br>";
1764 // Perform database save actions here
1765 $this->db->query("SELECT * FROM tc_companionship WHERE individual=$individual and valid=1",__LINE__,__FILE__);
1766 if ($this->db->next_record()) {
1767 $scheduling_priority = $this->db->f('scheduling_priority');
1768 //$this->logToFile("int_sched", "UPDATE tc_scheduling_priority SET priority='$hti_pri', notes=\"$hti_notes\" WHERE scheduling_priority='$scheduling_priority'");
1769 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$hti_pri', notes=\"$hti_notes\" WHERE scheduling_priority='$scheduling_priority'",__LINE__,__FILE__);
1773 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched');
1774 //Header('Location: ' . $take_me_to_url);
1777 // Get the Districts
1778 $sql = "SELECT * FROM tc_district AS td JOIN (tc_presidency AS tp, tc_individual AS ti) WHERE td.district=tp.district AND td.supervisor=ti.individual AND td.valid=1 ORDER BY td.district ASC";
1779 $this->db->query($sql,__LINE__,__FILE__);
1781 while ($this->db->next_record()) {
1782 $district = $this->db->f('district');
1783 $districts[$i]['district'] = $this->db->f('district');
1784 $districts[$i]['name'] = $this->db->f('name');
1785 $districts[$i]['supervisor'] = $this->db->f('supervisor');
1786 $districts[$i]['presidency'] = $this->db->f('presidency');
1790 // APPOINTMENT TABLE
1792 $date_width=250; $time_width=100; $indiv_width=200; $location_width=100;
1793 $appt_table_width=$date_width + $time_width + $indiv_width + $location_width;
1794 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1795 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1796 $appt_header_row.= "<th width=$indiv_width><font size=-2>Individual</th>";
1797 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
1798 $appt_table_data = "";
1800 $total_comps=0; $comps_with_quarterly_int=0;
1802 // Display a scheduling table for each district
1803 for ($d=0; $d < count($districts); $d++) {
1804 $table_data=""; $appt_table_data="";
1805 $this->t->set_var('district_number',$districts[$d]['district']);
1806 $this->t->set_var('district_name',$districts[$d]['name']);
1807 $supervisor = $districts[$d]['supervisor'];
1808 $supervisor_array = explode(",", $supervisor);
1809 $supervisor_last_name = $supervisor_array[0];
1810 $sql = "SELECT * FROM tc_individual where individual='$supervisor'";
1811 $this->db2->query($sql,__LINE__,__FILE__);
1812 if($this->db2->next_record()) {
1813 $mls_id = $this->db2->f('mls_id');
1815 $sql = "SELECT * FROM tc_individual where mls_id='$mls_id'";
1816 $this->db2->query($sql,__LINE__,__FILE__);
1817 if($this->db2->next_record()) {
1818 $supervisor_address = $this->db2->f('address');
1820 $location = "$supervisor_last_name"." home ($supervisor_address)";
1821 $table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": All Individuals with Interviews Not Completed";
1822 $appt_table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": Interview Appointment Slots";
1823 $this->t->set_var('table_title',$table_title);
1824 $this->t->set_var('appt_table_title',$appt_table_title);
1826 // query the database for all the appointments
1827 $sql = "SELECT * FROM tc_appointment where presidency=".$districts[$d]['presidency']." and date>=CURDATE() ORDER BY date ASC, time ASC";
1828 $this->db->query($sql,__LINE__,__FILE__);
1830 while ($this->db->next_record()) {
1831 $appointment = $this->db->f('appointment');
1832 $indiv = $this->db->f('individual');
1833 $location = $this->db->f('location');
1834 if(($location == "") && ($indiv > 0)) { $location = "$supervisor_last_name"." home ($supervisor_address)"; }
1836 $date = $this->db->f('date');
1837 $date_array = explode("-",$date);
1838 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1839 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1841 $time = $this->db->f('time');
1842 $time_array = explode(":",$time);
1843 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1845 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1846 $appt_table_data.= "<td align=center>$day_string</td>";
1847 $appt_table_data.= "<td align=center>$time_string</td>";
1849 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][individual]>';
1850 $appt_table_data.= '<option value=0></option>';
1851 for ($i=0; $i < count($individual_data); $i++) {
1852 $id = $individual_data[$i];
1853 $name = $indiv_name_data[$i];
1854 if($individual_data[$i] == $indiv) {
1855 $selected[$id] = 'selected="selected"';
1857 $selected[$id] = '';
1859 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1861 $appt_table_data.='</select></td>';
1863 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
1864 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
1866 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1867 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][supervisor]" value="'.$supervisor.'">';
1869 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1870 $this->t->set_var('tr_color',$tr_color);
1873 $this->t->set_var('appt_table_data',$appt_table_data);
1874 $this->t->set_var('appt_header_row',$appt_header_row);
1875 $this->t->set_var('appt_table_width',$appt_table_width);
1877 // INTERVIEW SCHEDULING TABLE
1879 // Select all the unique companionship numbers for this district
1880 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$d]['district'];
1881 $this->db->query($sql,__LINE__,__FILE__);
1882 $j=0; $unique_companionships = '';
1883 while ($this->db->next_record())
1885 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
1890 for ($j=0; $j < count($unique_companionships); $j++) {
1891 // Select all the companions from each companionship
1892 $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'];
1893 $this->db->query($sql,__LINE__,__FILE__);
1894 $k=0; $int_completed=0;
1895 $comp = $unique_companionships[$j]['companionship'];
1896 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1897 $this->t->set_var('tr_color',$tr_color);
1899 while ($this->db->next_record()) {
1900 // Get this companions information
1901 $individual = $this->db->f('individual');
1903 $id = $this->db->f('individual');
1904 $name = $this->db->f('name');
1905 $phone = $this->db->f('phone');
1906 $hti_pri = $this->db->f('priority');
1907 $hti_notes = $this->db->f('notes');
1909 // If the companionship has already had its quarterly interview,
1910 // Skip the other companion in the companionship.
1911 if($int_completed == 1) {
1912 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1913 $completed_data.= "<td align=center>$phone</td>";
1914 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1915 $completed_data.= "<td align=left>$hti_notes</td>";
1916 $completed_data.= '</tr>';
1917 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1918 $this->t->set_var('tr_color2',$tr_color2);
1919 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1920 $this->t->set_var('tr_color',$tr_color);
1924 // If this companionship has had a hometeaching interview this quarter, don't show them on the schedule list
1925 $sql = "SELECT * FROM tc_interview WHERE date >= '$quarter_start' AND date < '$quarter_end' AND individual='$id'";
1926 $this->db2->query($sql,__LINE__,__FILE__);
1928 if(!$this->db2->next_record()) {
1929 $sql = "SELECT * FROM tc_interview WHERE individual='$id' ORDER BY date DESC";
1930 $this->db3->query($sql,__LINE__,__FILE__);
1931 if($this->db3->next_record()) {
1932 $date = $this->db3->f('date');
1936 $link_data['menuaction'] = 'tc.tc.int_update';
1937 $link_data['individual'] = $id;
1938 $link_data['name'] = $name;
1939 $link_data['interview'] = '';
1940 $link_data['action'] = 'add';
1941 $link_data['interviewer'] = $districts[$d]['supervisor'];
1942 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1943 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1944 $table_data.= "<td align=center>$phone</td>";
1945 $table_data.= "<td align=center>";
1946 $table_data.= '<select name=hti_notes['.$i.'][pri]>';
1947 foreach(range(0,6) as $num) {
1948 if($num == 0) { $num = 1; } else {$num = $num*5; }
1949 if($hti_pri == $num) {
1950 $selected[$num] = 'selected="selected"';
1952 $selected[$num] = '';
1954 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1956 $table_data.= '</select></td>';
1957 $table_data.= "<td align=center>$date</td>";
1958 $table_data.= '<td><input type=text size="50" maxlength="128" name="hti_notes['.$i.'][notes]" value="'.$hti_notes.'">';
1959 $table_data.= '<input type=hidden name="hti_notes['.$i.'][individual]" value="'.$id.'">';
1960 $table_data.= '<input type=hidden name="hti_notes['.$i.'][indiv_name]" value="'.$name.'">';
1961 $table_data.= '</td>';
1962 $table_data.= '</tr>'."\n";
1965 $link_data['menuaction'] = 'tc.tc.int_update';
1966 $link_data['interviewer'] = $this->db2->f('interviewer');
1967 $link_data['individual'] = $this->db2->f('individual');
1968 $link_data['name'] = $name;
1969 $link_data['interview'] = $this->db2->f('interview');
1970 $link_data['action'] = 'view';
1971 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1972 $comps_with_quarterly_int++;
1974 $date = $this->db2->f('date');
1975 $hti_notes = $this->db2->f('notes');
1976 if(strlen($hti_notes) > 40) { $hti_notes = substr($hti_notes,0,40) . "..."; }
1977 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1978 $completed_data.= "<td align=center>$phone</td>";
1979 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1980 $completed_data.= "<td align=left>$hti_notes</td>";
1981 $completed_data.= '</tr>';
1986 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1987 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1988 $completed_header_row = "<th width=$name_width><font size=-2>Individual Name</th>";
1989 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1990 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1991 $completed_header_row.= "<th width=$notes_width><font size=-2>Interview Notes</th>";
1993 $this->t->set_var('table_width',$table_width);
1994 $this->t->set_var('header_row',$header_row);
1995 $this->t->set_var('table_data',$table_data);
1996 $this->t->set_var('completed_header_row',$completed_header_row);
1997 $this->t->set_var('completed_table_width',$completed_table_width);
1998 $this->t->set_var('completed',$completed_data);
1999 $this->t->fp('indivlist','individual_list',True);
2001 } // End for each district loop
2004 $indivs_width=300; $totals_width=100;
2005 $totals_table_width=$indivs_width + $totals_width;
2006 $totals_header_row = "<th width=$indivs_width><font size=-2>Individuals</th>";
2007 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2008 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2009 $totals_data.= "<td align=left><font size=-2><b>Total Companionships with interviews completed:</b></font></td>";
2010 $totals_data.= "<td align=center><font size=-2><b>$comps_with_quarterly_int / $total_comps</b></font></td>";
2011 $percent = ceil(($comps_with_quarterly_int / $total_comps)*100);
2012 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2013 $this->t->set_var('tr_color',$tr_color);
2014 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2015 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2016 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2017 $totals_data.= "</tr>";
2019 $this->t->set_var('totals',$totals_data);
2020 $this->t->set_var('totals_header_row',$totals_header_row);
2021 $this->t->set_var('totals_table_width',$totals_table_width);
2023 $this->t->pfp('out','int_sched_t');
2024 $this->save_sessiondata();
2028 function vis_sched()
2030 $this->t->set_file(array('vis_sched_t' => 'vis_sched.tpl'));
2031 $this->t->set_block('vis_sched_t','family_list','familylist');
2032 $this->t->set_block('vis_sched_t','appt_list','apptlist');
2033 $action = get_var('action',array('GET','POST'));
2035 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
2036 $this->t->set_var('lang_reset','Clear Changes');
2038 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2039 $this->t->set_var('vis_link_title','View Yearly Visits');
2041 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
2042 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2044 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched&action=save'));
2045 $this->t->set_var('title','Presidency Yearly Visit Scheduler');
2047 $family_width=500; $phone_width=40; $pri_width=10; $notes_width=128; $visit_date_width=20;
2048 $table_width=$family_width + $phone_width + $pri_width + $notes_width + $visit_date_width;
2049 $header_row = "<th width=$family_width><font size=-2>Family Name</th>";
2050 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2051 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
2052 $header_row.= "<th width=$visit_date_width><font size=-2>Last Visit</th>";
2053 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
2054 $table_data=""; $completed_data=""; $totals_data="";
2058 // create the family id -> family name mapping
2059 $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";
2060 $this->db->query($sql,__LINE__,__FILE__);
2063 while ($this->db->next_record()) {
2064 $family_id[$i] = $this->db->f('family');
2065 $family_name[$i] = $this->db->f('name');
2066 $familyid2name[$family_id[$i]] = $family_name[$i];
2067 $familyid2address[$family_id[$i]] = $this->db->f('address');
2070 array_multisort($family_name, $family_id);
2072 if($action == 'save') {
2073 // Save any changes made to the appointment table
2074 $new_data = get_var('appt_notes',array('POST'));
2075 if($new_data != "") {
2076 foreach ($new_data as $entry) {
2077 $family = $entry['family'];
2078 $appointment = $entry['appointment'];
2079 $location = $entry['location'];
2080 if($location == "") {
2081 $family_name_array = explode(",", $familyid2name[$family]);
2082 $family_last_name = $family_name_array[0];
2083 $family_address = $familyid2address[$family];
2084 $location = "$family_last_name"." home ($family_address)";
2086 if($family == 0) { $location = ""; }
2088 //Only perform a database update if we have made a change to this appointment
2089 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and family='$family' and location='$location'";
2090 $this->db->query($sql,__LINE__,__FILE__);
2091 if(!$this->db->next_record()) {
2092 // Perform database save actions here
2093 $this->db->query("UPDATE tc_appointment set " .
2094 " family='" . $family . "'" .
2095 ",location='" . $location . "'" .
2096 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
2098 // Email the appointment
2099 $this->email_appt($appointment);
2104 // Save any changes made to the visit notes table
2105 $new_data = get_var('vis_notes',array('POST'));
2106 foreach ($new_data as $entry) {
2107 $visit_notes = $entry['notes'];
2108 $family = $entry['family_id'];
2109 $visit_pri = $entry['pri'];
2110 // Perform database save actions here
2111 $this->db->query("SELECT * FROM tc_family WHERE family='$family'",__LINE__,__FILE__);
2112 if ($this->db->next_record()) {
2113 $scheduling_priority = $this->db->f('scheduling_priority');
2114 //$this->logToFile("vis_sched", "UPDATE tc_scheduling_priority SET priority='$visit_pri', notes=\"$visit_notes\" WHERE scheduling_priority='$scheduling_priority'");
2115 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$visit_pri', notes=\"$visit_notes\" WHERE scheduling_priority='$scheduling_priority'", __LINE__, __FILE__);
2119 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched');
2120 //Header('Location: ' . $take_me_to_url);
2123 // APPOINTMENT TABLE
2124 $date_width=250; $time_width=100; $family_width=250; $location_width=100;
2125 $appt_table_width=$date_width + $time_width + $family_width + $location_width;
2126 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
2127 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
2128 $appt_header_row.= "<th width=$family_width><font size=-2>Family</th>";
2129 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
2130 $appt_table_data = "";
2132 // Find out what the President ID is
2133 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.president=1 AND tp.valid=1";
2134 $this->db->query($sql,__LINE__,__FILE__);
2135 if($this->db->next_record()) {
2136 $presidency_name = $this->db->f('name');
2137 $presidency_id = $this->db->f('presidency');
2139 print "<hr><font color=red><h3>-E- Unable to locate Presidency in tc_presidency table</h3></font></hr>";
2143 // query the database for all the appointments
2144 $sql = "SELECT * FROM tc_appointment where presidency=$presidency_id and date>=CURDATE() ORDER BY date ASC, time ASC";
2145 $this->db->query($sql,__LINE__,__FILE__);
2147 while ($this->db->next_record()) {
2148 $appointment = $this->db->f('appointment');
2149 $family = $this->db->f('family');
2150 $location = $this->db->f('location');
2151 $family_name_array = explode(",", $familyid2name[$family]);
2152 $family_last_name = $family_name_array[0];
2153 $family_address = $familyid2address[$family];
2154 if(($location == "") && ($family > 0)) { $location = "$family_last_name"." home ($family_address)"; }
2156 $date = $this->db->f('date');
2157 $date_array = explode("-",$date);
2158 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
2159 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
2161 $time = $this->db->f('time');
2162 $time_array = explode(":",$time);
2163 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
2165 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2166 $appt_table_data.= "<td align=center>$day_string</td>";
2167 $appt_table_data.= "<td align=center>$time_string</td>";
2169 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][family]>';
2170 $appt_table_data.= '<option value=0></option>';
2171 for ($i=0; $i < count($family_id); $i++) {
2172 $id = $family_id[$i];
2173 $name = $family_name[$i];
2174 if($family_id[$i] == $family) {
2175 $selected[$id] = 'selected="selected"';
2177 $selected[$id] = '';
2179 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
2181 $appt_table_data.='</select></td>';
2183 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
2184 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
2186 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
2188 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2189 $this->t->set_var('tr_color',$tr_color);
2192 $this->t->set_var('appt_table_data',$appt_table_data);
2193 $this->t->set_var('appt_header_row',$appt_header_row);
2194 $this->t->set_var('appt_table_width',$appt_table_width);
2197 // VISIT SCHEDULING TABLE
2198 $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";
2199 $this->db->query($sql,__LINE__,__FILE__);
2201 $total_families=0; $families_with_yearly_visit=0;
2203 while ( $this->db->next_record()) {
2205 $id = $this->db->f('family');
2206 $name = $this->db->f('name');
2207 $phone = $this->db->f('phone');
2208 $vis_pri = $this->db->f('priority');
2209 $vis_notes = $this->db->f('notes');
2211 // If this family has had a yearly visit this year, don't show them on the schedule list
2212 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2213 $sql = "SELECT * FROM tc_visit WHERE date > '$year_start' AND date < '$year_end' ".
2214 "AND family=" . $id . " AND companionship=0";
2215 $this->db2->query($sql,__LINE__,__FILE__);
2217 if(!$this->db2->next_record()) {
2218 $sql = "SELECT * FROM tc_visit WHERE family=" . $id . " AND companionship=0 ORDER BY date DESC";
2219 $this->db3->query($sql,__LINE__,__FILE__);
2220 if($this->db3->next_record()) {
2221 $date = $this->db3->f('date');
2225 $link_data['menuaction'] = 'tc.tc.vis_update';
2226 $link_data['visit'] = '';
2227 $link_data['family'] = $id;
2228 $link_data['name'] = $name;
2229 $link_data['action'] = 'add';
2230 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2231 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2232 $table_data.= "<td align=center>$phone</td>";
2233 $table_data.= "<td align=center>";
2234 $table_data.= '<select name=vis_notes['.$id.'][pri]>';
2235 foreach(range(0,6) as $num) {
2236 if($num == 0) { $num = 1; } else {$num = $num*5; }
2237 if($vis_pri == $num) {
2238 $selected[$num] = 'selected="selected"';
2240 $selected[$num] = '';
2242 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2244 $table_data.= '</select></td>';
2245 $table_data.= "<td align=center>$date</td>";
2246 $table_data.= '<td><input type=text size="50" maxlength="128" name="vis_notes['.$id.'][notes]" value="'.$vis_notes.'">';
2247 $table_data.= '<input type=hidden name="vis_notes['.$id.'][family_id]" value="'.$id.'">';
2248 $table_data.= '<input type=hidden name="vis_notes['.$id.'][family_name]" value="'.$name.'">';
2249 $table_data.= '</td>';
2250 $table_data.= '</tr>';
2251 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2252 $this->t->set_var('tr_color',$tr_color);
2254 $link_data['menuaction'] = 'tc.tc.vis_update';
2255 $link_data['visit'] = $this->db2->f('visit');
2256 $link_data['family'] = $this->db2->f('family');
2257 $link_data['name'] = $name;
2258 $link_data['date'] = $this->db2->f('date');
2259 $link_data['action'] = 'view';
2260 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2261 $families_with_yearly_visit++;
2262 $date = $this->db2->f('date');
2263 $vis_notes = $this->db2->f('notes');
2264 if(strlen($vis_notes) > 40) { $vis_notes = stripslashes(substr($vis_notes,0,40) . "..."); }
2265 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2266 $completed_data.= "<td align=center>$phone</td>";
2267 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2268 $completed_data.= "<td align=left>$vis_notes</td>";
2269 $completed_data.= '</tr>';
2270 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
2271 $this->t->set_var('tr_color2',$tr_color2);
2275 $name_width=190; $phone_width=100; $date_width=100; $notes_width=300;
2276 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
2277 $completed_header_row = "<th width=$name_width><font size=-2>Family Name</th>";
2278 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2279 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
2280 $completed_header_row.= "<th width=$notes_width><font size=-2>Visit Notes</th>";
2282 $family_width=300; $totals_width=100;
2283 $totals_table_width=$family_width + $totals_width;
2284 $totals_header_row = "<th width=$family_width><font size=-2>Families</th>";
2285 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2286 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2287 $totals_data.= "<td align=left><font size=-2><b>Total Families with yearly Visits completed:</b></font></td>";
2288 $totals_data.= "<td align=center><font size=-2><b>$families_with_yearly_visit / $total_families</b></font></td>";
2289 $percent = ceil(($families_with_yearly_visit / $total_families)*100);
2290 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2291 $this->t->set_var('tr_color',$tr_color);
2292 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2293 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2294 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2295 $totals_data.= "</tr>";
2297 $this->t->set_var('table_width',$table_width);
2298 $this->t->set_var('header_row',$header_row);
2299 $this->t->set_var('table_data',$table_data);
2300 $this->t->set_var('totals_header_row',$totals_header_row);
2301 $this->t->set_var('totals_table_width',$totals_table_width);
2302 $this->t->set_var('completed_header_row',$completed_header_row);
2303 $this->t->set_var('completed_table_width',$completed_table_width);
2304 $this->t->set_var('completed',$completed_data);
2305 $this->t->set_var('totals',$totals_data);
2306 $this->t->fp('familylist','family_list',True);
2307 $this->t->fp('apptlist','appt_list',True);
2309 $this->t->pfp('out','vis_sched_t');
2310 $this->save_sessiondata();
2315 $this->t->set_file(array('ppi_view_t' => 'ppi_view.tpl'));
2316 $this->t->set_block('ppi_view_t','district_list','list');
2318 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2319 $num_months = get_var('num_months',array('GET','POST'));
2320 if($num_months == '') { $num_months = $this->default_ppi_num_months; }
2321 $this->t->set_var('num_months',$num_months);
2322 if($num_months == 1) {
2323 $this->t->set_var('lang_num_months','Month of History');
2325 $this->t->set_var('lang_num_months','Months of History');
2327 $this->t->set_var('lang_filter','Filter');
2328 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2330 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2331 $this->t->set_var('ppi_link_title','Yearly PPIs');
2333 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
2334 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
2336 $this->t->set_var('title','Yearly PPIs');
2337 $num_months = get_var('num_months',array('GET','POST'));
2338 if($num_months == '') { $num_months = $this->default_ppi_num_years; }
2339 $this->t->set_var('num_months',$num_months);
2340 if($num_months == 1) {
2341 $this->t->set_var('lang_num_months','Year of History');
2343 $this->t->set_var('lang_num_months','Years of History');
2346 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.president=1 AND tp.valid=1";
2347 $this->db->query($sql,__LINE__,__FILE__);
2348 if($this->db->next_record()) {
2349 $president_name = $this->db->f('name');
2350 $interviewer = $this->db->f('individual');
2351 $interview_type = 'ppi';
2353 print "<hr><font color=red><h3>-E- Unable to locate President in tc_presidency table</h3></font></hr>";
2356 $this->t->set_var('district_number','*');
2357 $this->t->set_var('district_name',$president_name);
2359 // TODO: changed this so it picks the quorum dynamically
2360 $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";
2361 $this->db->query($sql,__LINE__,__FILE__);
2363 while ($this->db->next_record()) {
2364 $individual[$i] = $this->db->f('individual');
2365 $indiv_name[$i] = $this->db->f('name');
2366 $indiv_phone[$individual[$i]] = $this->db->f('phone');
2367 $indiv_priority[$individual[$i]] = $this->db->f('priority');
2368 $indiv_notes[$individual[$i]] = $this->db->f('notes');
2372 array_multisort($indiv_name, $individual);
2373 //var_dump($indiv_name); print "<br><br>"; var_dump($individual);
2375 $header_row="<th width=$comp_width><font size=-2>Individual Name</th>";
2377 $indiv_width=400; $ppi_width=75; $table_width=$indiv_width + $num_months*$ppi_width;
2379 for($m=$num_months; $m >= 0; $m--) {
2380 $year = date('Y') - $m;
2381 $header_row .= "<th width=150><font size=-2>$year</th>";
2385 for ($j=0; $j < count($individual); $j++) {
2386 $id = $individual[$j];
2387 $name = $indiv_name[$j];
2388 $phone = $indiv_phone[$id];
2390 $link_data['menuaction'] = 'tc.tc.ppi_update';
2391 $link_data['interviewer'] = $interviewer;
2392 $link_data['indiv'] = $id;
2393 $link_data['name'] = $name;
2394 $link_data['interview'] = '';
2395 $link_data['interview_type'] = $interview_type;
2396 $link_data['action'] = 'add';
2397 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2398 $this->nextmatchs->template_alternate_row_color(&$this->t);
2399 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2401 // Find out how many times PPIs were performed in the past $num_months for this individual
2402 for($m=$num_months; $m >= 0; $m--) {
2403 $year = date('Y') - $m;
2404 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2405 $sql = "SELECT * FROM tc_interview WHERE date > '$year_start' AND date < '$year_end' ".
2406 "AND individual=" . $id . " AND interview_type='ppi'";
2407 $this->db2->query($sql,__LINE__,__FILE__);
2409 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
2410 if($this->db2->next_record()) {
2411 $ppis[$m]++; $total_ppis[$m]++; $ppi_recorded[$companionship][$m]=1;
2412 $link_data['menuaction'] = 'tc.tc.ppi_update';
2413 $link_data['companionship'] = $companionship;
2414 $link_data['interviewer'] = $this->db2->f('interviewer');
2415 $link_data['indiv'] = $id;
2416 $link_data['name'] = $name;
2417 $link_data['interview'] = $this->db2->f('interview');
2418 $link_data['interview_type'] = $interview_type;
2419 $link_data['action'] = 'view';
2420 $date = $this->db2->f('date');
2421 $date_array = explode("-",$date);
2422 $month = $date_array[1];
2423 $day = $date_array[2];
2424 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2425 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2427 $table_data .= "<td> </td>";
2430 $table_data .= "</tr>\n";
2432 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2434 $stat_data = "<tr><td><b><font size=-2>$total_indivs Individuals<br>PPI Totals:</font></b></td>";
2435 for($m=$num_months; $m >=0; $m--) {
2436 $percent = ceil(($ppis[$m] / $total_indivs)*100);
2437 $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
2439 $stat_data .= "</tr>";
2441 $this->t->set_var('table_width',$table_width);
2442 $this->t->set_var('header_row',$header_row);
2443 $this->t->set_var('table_data',$table_data);
2444 $this->t->set_var('stat_data',$stat_data);
2445 $this->t->pfp('out','ppi_view_t');
2446 $this->save_sessiondata();
2449 function ppi_update()
2451 $this->t->set_file(array('form' => 'ppi_update.tpl'));
2452 $this->t->set_block('form','interviewer_list','int_list');
2453 $this->t->set_block('form','add','addhandle');
2454 $this->t->set_block('form','edit','edithandle');
2456 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2457 $this->t->set_var('readonly','');
2458 $this->t->set_var('disabled','');
2460 $action = get_var('action',array('GET','POST'));
2461 $companionship = get_var('companionship',array('GET','POST'));
2462 $interviewer = get_var('interviewer',array('GET','POST'));
2463 $name = get_var('name',array('GET','POST'));
2464 $interview = get_var('interview',array('GET','POST'));
2465 $indiv = get_var('indiv',array('GET','POST'));
2466 $date = get_var('date',array('GET','POST'));
2467 $notes = get_var('notes',array('GET','POST'));
2468 $interview_type = get_var('interview_type',array('GET','POST'));
2470 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1 AND (tp.president=1 OR tp.counselor=1 OR tp.secretary=1)";
2471 $this->db2->query($sql,__LINE__,__FILE__);
2472 while ($this->db2->next_record()) {
2473 $indiv = $this->db2->f('individual');
2474 $interviewer_name = $this->db2->f('name');
2475 if($indiv == $interviewer) {
2476 $this->t->set_var('interviewer',$interviewer . ' selected');
2478 $this->t->set_var('interviewer',$interviewer);
2480 $this->t->set_var('interviewer_name',$interviewer_name);
2481 $this->t->set_var('interview_type_checked','');
2482 $this->t->fp('int_list','interviewer_list',True);
2485 if($action == 'save') {
2486 $notes = get_var('notes',array('POST'));
2487 $this->db->query("UPDATE tc_interview set " .
2488 " interview='" . $interview . "'" .
2489 ", interviewer='" . $interviewer . "'" .
2490 ", individual='" . $indiv . "'" .
2491 ", date='" . $date . "'" .
2492 ", notes='" . $notes . "'" .
2493 ", interview_type='" . $interview_type . "'" .
2494 " WHERE interview=" . $interview,__LINE__,__FILE__);
2499 if($action == 'insert') {
2500 $notes = get_var('notes',array('POST'));
2501 $this->db->query("INSERT INTO tc_interview (interviewer,individual,date,notes,interview_type) " .
2502 "VALUES ('" . $interviewer . "','" . $indiv . "','" .
2503 $date . "','" . $notes . "','" . $interview_type ."')",__LINE__,__FILE__);
2508 if($action == 'add') {
2509 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2510 $this->t->set_var('interview', '');
2511 $this->t->set_var('interviewer', $interviewer);
2512 $this->t->set_var('name',$name);
2513 $this->t->set_var('indiv',$indiv);
2514 $this->t->set_var('date','');
2515 $this->t->set_var('notes','');
2516 $this->t->set_var('interview_type',$interview_type);
2517 $this->t->set_var('interview_type_checked','checked');
2518 $this->t->set_var('lang_done','Cancel');
2519 $this->t->set_var('lang_action','Adding New PPI');
2520 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview=' .
2521 $interview . '&action=' . 'insert'));
2524 if($action == 'edit' || $action == 'view') {
2525 $sql = "SELECT * FROM tc_interview WHERE interview=".$interview;
2526 $this->db->query($sql,__LINE__,__FILE__);
2527 $this->db->next_record();
2528 $this->t->set_var('interview',$interview);
2529 $this->t->set_var('name',$name);
2530 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2531 $this->t->set_var('indiv',$this->db->f('indiv'));
2532 $this->t->set_var('date',$this->db->f('date'));
2533 $this->t->set_var('notes',$this->db->f('notes'));
2534 $this->t->set_var('interview_type',$this->db->f('interview_type'));
2535 if($this->db->f('interview_type') == 1) { $this->t->set_var('interview_type_checked','checked'); }
2538 if($action == 'edit') {
2539 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2540 $this->t->set_var('lang_done','Cancel');
2541 $this->t->set_var('lang_action','Editing PPI');
2542 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview='.
2543 $interview . '&action=' . 'save'));
2546 if($action == 'view') {
2547 $date = $this->db->f('date');
2548 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2549 $this->t->set_var('readonly','READONLY');
2550 $this->t->set_var('disabled','DISABLED');
2551 $this->t->set_var('lang_done','Done');
2552 $this->t->set_var('lang_action','Viewing PPI');
2553 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview=' .
2554 $interview . '&action=' . 'edit'));
2557 $this->t->set_var('lang_reset','Clear Form');
2558 $this->t->set_var('lang_add','Add PPI');
2559 $this->t->set_var('lang_save','Save Changes');
2560 $this->t->set_var('edithandle','');
2561 $this->t->set_var('addhandle','');
2563 $this->t->pfp('out','form');
2565 if($action == 'view') { $this->t->set_var('lang_save','Edit PPI'); }
2566 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2567 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2569 $this->save_sessiondata();
2574 $this->t->set_file(array('int_view_t' => 'int_view.tpl'));
2575 $this->t->set_block('int_view_t','district_list','list');
2577 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2578 $num_quarters = get_var('num_quarters',array('GET','POST'));
2579 if($num_quarters == '') { $num_quarters = $this->default_int_num_quarters; }
2580 $this->t->set_var('num_quarters',$num_quarters);
2581 if($num_quarters == 1) {
2582 $this->t->set_var('lang_num_quarters','Quarter of History');
2584 $this->t->set_var('lang_num_quarters','Quarters of History');
2586 $this->t->set_var('lang_filter','Filter');
2588 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2589 $this->t->set_var('int_link_title','Hometeaching Interviews');
2591 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
2592 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
2594 $this->t->set_var('title','Hometeaching Interviews');
2596 $num_months = $num_quarters * 3 - 1;
2597 $current_month = $this->current_month;
2598 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
2599 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
2600 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
2601 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
2603 $sql = "SELECT * FROM tc_district AS td JOIN tc_individual AS ti WHERE td.supervisor=ti.individual AND td.valid=1 ORDER BY td.district ASC";
2604 $this->db->query($sql,__LINE__,__FILE__);
2606 while ($this->db->next_record()) {
2607 $districts[$i]['district'] = $this->db->f('district');
2608 $districts[$i]['name'] = $this->db->f('name');
2609 $districts[$i]['supervisor'] = $this->db->f('supervisor');
2613 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
2614 $this->db->query($sql,__LINE__,__FILE__);
2616 while ($this->db->next_record()) {
2617 $individual[$i] = $this->db->f('individual');
2618 $indiv_name[$i] = $this->db->f('name');
2619 $indiv_phone[$individual[$i]] = $this->db->f('phone');
2622 array_multisort($indiv_name, $individual);
2623 for($i=0; $i < count($individual); $i++) {
2624 $id = $individual[$i];
2625 $indivs[$id] = $indiv_name[$i];
2628 $total_companionships = 0;
2629 $this->nextmatchs->template_alternate_row_color(&$this->t);
2630 for ($i=0; $i < count($districts); $i++) {
2631 $this->t->set_var('district_number',$districts[$i]['district']);
2632 $this->t->set_var('district_name',$districts[$i]['name']);
2633 $supervisor = $districts[$i]['supervisor'];
2635 // Select all the unique companionship numbers for this district
2636 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$i]['district'];
2637 $this->db->query($sql,__LINE__,__FILE__);
2638 $j=0; $unique_companionships = '';
2639 while ($this->db->next_record()) {
2640 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
2644 $comp_width=250; $int_width=75; $table_width=$comp_width + $num_months*$int_width;
2645 $table_data=""; $num_companionships = $j; $num_indivs = 0;
2646 for($m=$num_months; $m >= 0; $m--) { $ints[$m] = 0; }
2647 for ($j=0; $j < count($unique_companionships); $j++) {
2648 // Select all the companions in each companionship
2649 $sql = "SELECT * FROM tc_companionship where valid=1 and ".
2650 "companionship=". $unique_companionships[$j]['companionship'];
2651 $this->db->query($sql,__LINE__,__FILE__);
2653 $comp = $unique_companionships[$j]['companionship'];
2654 for($m=$num_months; $m >= 0; $m--) { $int_recorded[$comp][$m] = 0; }
2655 while ($this->db->next_record()) {
2656 // Get this companions information
2658 $companionship = $this->db->f('companionship');
2659 $individual = $this->db->f('individual');
2660 $name = $indivs[$individual];
2661 $phone = $indiv_phone[$individual];
2662 $link_data['menuaction'] = 'tc.tc.int_update';
2663 $link_data['companionship'] = $companionship;
2664 $link_data['interviewer'] = $supervisor;
2665 $link_data['indiv'] = $individual;
2666 $link_data['name'] = $name;
2667 $link_data['interview'] = '';
2668 $link_data['action'] = 'add';
2669 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2670 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2672 // Find out how many times Interviews were performed in the past $num_months for this individual
2673 $header_row="<th width=$comp_width><font size=-2>Companionship</th>";
2674 for($m=$num_months; $m >= 0; $m--) {
2675 $month = $current_month - $m;
2676 $year = $this->current_year;
2678 $remainder = $month;
2679 $month = 12 + $remainder;
2682 if($month < 10) { $month = "0"."$month"; }
2683 $month_start = "$year"."-"."$month"."-"."01";
2684 $month_end = "$year"."-"."$month"."-"."31";
2685 $month = "$month"."/"."$year";
2686 $sql = "SELECT * FROM tc_interview WHERE date >= '$month_start' AND date <= '$month_end' ".
2687 "AND individual=" . $individual;
2688 $this->db2->query($sql,__LINE__,__FILE__);
2689 $header_row .= "<th width=$int_width><font size=-2>$month</th>";
2691 if(!$total_ints[$m]) { $total_ints[$m] = 0; }
2692 if($this->db2->next_record()) {
2693 if(!$int_recorded[$companionship][$m]) {
2696 $int_recorded[$companionship][$m]=1;
2698 $link_data['menuaction'] = 'tc.tc.int_update';
2699 $link_data['companionship'] = $companionship;
2700 $link_data['interviewer'] = $this->db2->f('interviewer');
2701 $link_data['indiv'] = $individual;
2702 $link_data['name'] = $name;
2703 $link_data['interview'] = $this->db2->f('interview');
2704 $link_data['action'] = 'view';
2705 $date = $this->db2->f('date');
2706 $date_array = explode("-",$date);
2707 $month = $date_array[1];
2708 $day = $date_array[2];
2709 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2710 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2713 $table_data .= "<td> </td>";
2716 $table_data .= "</tr>";
2719 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2721 $total_companionships += $num_companionships;
2722 $stat_data = "<tr><td><b><font size=-2>$num_companionships Companionships<br>Interview Totals:</font></b></td>";
2724 // Print the hometeaching interview stats
2725 for($m=$num_months; $m >=0; $m--) {
2726 $month = $current_month - $m;
2727 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
2728 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
2729 //print "$month % $this->monthly_hometeaching_interview_stats = $month_begins <br>";
2730 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
2731 if(($month_begins) == 1) {
2734 $total += $ints[$m];
2736 $percent = ceil(($total / $num_companionships)*100);
2737 $stat_data .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
2739 $stat_data .= "</tr>";
2741 $this->t->set_var('table_width',$table_width);
2742 $this->t->set_var('header_row',$header_row);
2743 $this->t->set_var('table_data',$table_data);
2744 $this->t->set_var('stat_data',$stat_data);
2745 $this->t->fp('list','district_list',True);
2748 // Display the totals
2750 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>Interview Totals:</font></b></td>";
2751 for($m=$num_months; $m >=0; $m--) {
2752 $month = $current_month - $m;
2753 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
2754 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
2755 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
2756 if(($month_begins) == 1) {
2757 $total = $total_ints[$m];
2759 $total += $total_ints[$m];
2761 $percent = ceil(($total / $total_companionships)*100);
2762 $totals .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
2766 $this->t->set_var('totals',$totals);
2767 $this->t->pfp('out','int_view_t');
2768 $this->save_sessiondata();
2771 function int_update()
2773 $this->t->set_file(array('form' => 'int_update.tpl'));
2774 $this->t->set_block('form','interviewer_list','int_list');
2775 $this->t->set_block('form','add','addhandle');
2776 $this->t->set_block('form','edit','edithandle');
2778 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2779 $this->t->set_var('readonly','');
2780 $this->t->set_var('disabled','');
2781 $this->t->set_var('interview_type_checked','');
2783 $action = get_var('action',array('GET','POST'));
2784 $companionship = get_var('companionship',array('GET','POST'));
2785 $interviewer = get_var('interviewer',array('GET','POST'));
2786 $name = get_var('name',array('GET','POST'));
2787 $interview = get_var('interview',array('GET','POST'));
2788 $indiv = get_var('indiv',array('GET','POST'));
2789 $date = get_var('date',array('GET','POST'));
2790 $notes = get_var('notes',array('GET','POST'));
2791 $interview_type = get_var('interview_type',array('GET','POST'));
2793 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1 AND (tp.president=1 OR tp.counselor=1 OR tp.secretary=1 OR tp.district!=0)";
2794 $this->db2->query($sql,__LINE__,__FILE__);
2795 while ($this->db2->next_record()) {
2796 $indiv = $this->db2->f('individual');
2797 $interviewer_name = $this->db2->f('name');
2798 if($indiv == $interviewer) {
2799 $this->t->set_var('interviewer',$interviewer . ' selected');
2801 $this->t->set_var('interviewer',$interviewer);
2803 $this->t->set_var('interviewer_name',$interviewer_name);
2804 $this->t->fp('int_list','interviewer_list',True);
2807 if($action == 'save') {
2808 $notes = get_var('notes',array('POST'));
2809 $this->db->query("UPDATE tc_interview set " .
2810 " interview='" . $interview . "'" .
2811 ", interviewer='" . $interviewer . "'" .
2812 ", individual='" . $indiv . "'" .
2813 ", date='" . $date . "'" .
2814 ", notes='" . $notes . "'" .
2815 ", interview_type='" . $interview_type . "'" .
2816 " WHERE interview=" . $interview,__LINE__,__FILE__);
2821 if($action == 'insert') {
2822 $notes = get_var('notes',array('POST'));
2823 $this->db->query("INSERT INTO tc_interview (interviewer,individual,date,notes,interview_type) " .
2824 "VALUES ('" . $interviewer . "','" . $indiv . "','" .
2825 $date . "','" . $notes ."','" . $interview_type . "')",__LINE__,__FILE__);
2830 if($action == 'add') {
2831 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2832 $this->t->set_var('interview', '');
2833 $this->t->set_var('interviewer', $interviewer);
2834 $this->t->set_var('name',$name);
2835 $this->t->set_var('indiv',$indiv);
2836 $this->t->set_var('date','');
2837 $this->t->set_var('notes','');
2838 $this->t->set_var('lang_done','Cancel');
2839 $this->t->set_var('lang_action','Adding New Interview');
2840 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
2841 $interview . '&action=' . 'insert'));
2844 if($action == 'edit' || $action == 'view') {
2845 $sql = "SELECT * FROM tc_interview WHERE interview=".$interview;
2846 $this->db->query($sql,__LINE__,__FILE__);
2847 $this->db->next_record();
2848 $this->t->set_var('interview',$interview);
2849 $this->t->set_var('name',$name);
2850 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2851 $this->t->set_var('indiv',$this->db->f('individual'));
2852 $this->t->set_var('date',$this->db->f('date'));
2853 $this->t->set_var('notes',$this->db->f('notes'));
2854 if($this->db->f('interview_type') == 1) { $this->t->set_var('interview_type_checked','checked'); }
2857 if($action == 'edit') {
2858 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2859 $this->t->set_var('lang_done','Cancel');
2860 $this->t->set_var('lang_action','Editing Interview');
2861 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
2862 $interview . '&action=' . 'save'));
2865 if($action == 'view') {
2866 $date = $this->db->f('date');
2867 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2868 $this->t->set_var('readonly','READONLY');
2869 $this->t->set_var('disabled','DISABLED');
2870 $this->t->set_var('lang_done','Done');
2871 $this->t->set_var('lang_action','Viewing Interview');
2872 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
2873 $interview . '&action=' . 'edit'));
2876 $this->t->set_var('lang_reset','Clear Form');
2877 $this->t->set_var('lang_add','Add Interview');
2878 $this->t->set_var('lang_save','Save Changes');
2879 $this->t->set_var('edithandle','');
2880 $this->t->set_var('addhandle','');
2882 $this->t->pfp('out','form');
2884 if($action == 'view') { $this->t->set_var('lang_save','Edit Interview'); }
2885 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2886 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2888 $this->save_sessiondata();
2893 $this->t->set_file(array('vis_view_t' => 'vis_view.tpl'));
2894 $this->t->set_block('vis_view_t','visit_list','list1');
2895 $this->t->set_block('vis_view_t','family_list','list2');
2897 $this->t->set_var('lang_name','Family Name');
2898 $this->t->set_var('lang_date','Date');
2900 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2901 $this->t->set_var('vis_link_title','View Yearly Visits');
2903 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
2904 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2906 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2907 $num_years = get_var('num_years',array('GET','POST'));
2908 if($num_years == '') { $num_years = $this->default_vis_num_years; }
2909 $this->t->set_var('num_years',$num_years);
2910 if($num_years == 1) {
2911 $this->t->set_var('lang_num_years','Year of History');
2913 $this->t->set_var('lang_num_years','Years of History');
2915 $this->t->set_var('lang_filter','Filter');
2917 $year = date('Y') - $num_years + 1;
2918 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2920 $sql = "SELECT * FROM tc_visit WHERE companionship=0 and date > '$year_start' ORDER BY date DESC";
2921 $this->db->query($sql,__LINE__,__FILE__);
2922 $total_records = $this->db->num_rows();
2925 while ($this->db->next_record()) {
2926 $visit_list[$i]['visit'] = $this->db->f('visit');
2927 $visit_list[$i]['family'] = $this->db->f('family');
2928 $visit_list[$i]['date'] = $this->db->f('date');
2932 for ($i=0; $i < count($visit_list); $i++) {
2933 $this->nextmatchs->template_alternate_row_color(&$this->t);
2935 $sql = "SELECT * FROM tc_family AS tf JOIN tc_individual AS ti WHERE tf.individual=ti.individual AND tf.family=".$visit_list[$i]['family'];
2936 $this->db->query($sql,__LINE__,__FILE__);
2937 $this->db->next_record();
2939 $this->t->set_var('family',$visit_list[$i]['family']);
2940 $this->t->set_var('family_name',$this->db->f('name'));
2941 $this->t->set_var('date',$visit_list[$i]['date']);
2943 $link_data['menuaction'] = 'tc.tc.vis_update';
2944 $link_data['visit'] = $visit_list[$i]['visit'];
2945 $link_data['name'] = $this->db->f('name');
2946 $link_data['date'] = $visit_list[$i]['date'];
2947 $link_data['action'] = 'view';
2948 $this->t->set_var('view',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
2949 $this->t->set_var('lang_view','View');
2951 $link_data['menuaction'] = 'tc.tc.vis_update';
2952 $link_data['visit'] = $visit_list[$i]['visit'];
2953 $link_data['name'] = $this->db->f('name');
2954 $link_data['date'] = $visit_list[$i]['date'];
2955 $link_data['action'] = 'edit';
2956 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
2957 $this->t->set_var('lang_edit','Edit');
2959 $this->t->fp('list1','visit_list',True);
2962 // List the families that are available to record a visit against
2963 $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";
2964 $this->db->query($sql,__LINE__,__FILE__);
2965 $total_records = $this->db->num_rows();
2968 while ($this->db->next_record()) {
2969 $family_names[$i] = $this->db->f('name');
2970 $family_ids[$i] = $this->db->f('family');
2972 } array_multisort($family_names, $family_ids);
2974 for ($i=0; $i < count($family_names); $i++) {
2975 $link_data['menuaction'] = 'tc.tc.vis_update';
2976 $link_data['visit'] = '';
2977 $link_data['family'] = $family_ids[$i];
2978 $link_data['action'] = 'add';
2979 $link_data['name'] = $family_names[$i];
2980 $this->t->set_var('add',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
2982 $this->t->set_var('name',$family_names[$i]);
2983 if(($i+1) % 3 == 0) {
2984 $this->t->set_var('table_sep',"</td></tr><tr>");
2986 $this->t->set_var('table_sep',"</td>");
2988 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
2990 $this->t->fp('list2','family_list',True);
2993 $this->t->pfp('out','vis_view_t');
2994 $this->save_sessiondata();
2997 function vis_update()
2999 $this->t->set_file(array('form' => 'vis_update.tpl'));
3000 $this->t->set_block('form','add','addhandle');
3001 $this->t->set_block('form','edit','edithandle');
3003 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
3004 $this->t->set_var('readonly','');
3005 $this->t->set_var('disabled','');
3007 $action = get_var('action',array('GET','POST'));
3008 $visit = get_var('visit',array('GET','POST'));
3009 $family = get_var('family',array('GET','POST'));
3010 $name = get_var('name',array('GET','POST'));
3011 $date = get_var('date',array('GET','POST'));
3012 $notes = get_var('notes',array('GET','POST'));
3015 if($action == 'save') {
3016 $notes = get_var('notes',array('POST'));
3017 $this->db->query("UPDATE tc_visit set " .
3018 " date='" . $date . "'" .
3019 ", notes='" . $notes . "'" .
3020 " WHERE visit=" . $visit,__LINE__,__FILE__);
3025 if($action == 'insert') {
3026 $notes = get_var('notes',array('POST'));
3027 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes) " .
3028 "VALUES ('" . $family . "','" . $companionship . "','" .
3029 $date . "','" . $notes . "')",__LINE__,__FILE__);
3034 if($action == 'add') {
3035 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
3036 $this->t->set_var('family', $family);
3037 $this->t->set_var('visit', '');
3038 $this->t->set_var('name', $name);
3039 $this->t->set_var('date','');
3040 $this->t->set_var('notes','');
3041 $this->t->set_var('lang_done','Cancel');
3042 $this->t->set_var('lang_action','Adding New Visit');
3043 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&family=' .
3044 $family . '&action=' . 'insert'));
3047 if($action == 'edit' || $action == 'view') {
3048 $sql = "SELECT * FROM tc_visit WHERE visit=".$visit;
3049 $this->db->query($sql,__LINE__,__FILE__);
3050 $this->db->next_record();
3051 $this->t->set_var('visit',$visit);
3052 $this->t->set_var('name',$name);
3053 $this->t->set_var('family', $family);
3054 $this->t->set_var('date',$this->db->f('date'));
3055 $this->t->set_var('notes',$this->db->f('notes'));
3058 if($action == 'edit') {
3059 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
3060 $this->t->set_var('lang_done','Cancel');
3061 $this->t->set_var('lang_action','Editing Visit');
3062 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit=' .
3063 $visit . '&action=' . 'save'));
3066 if($action == 'view') {
3067 $date = $this->db->f('date');
3068 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
3069 $this->t->set_var('readonly','READONLY');
3070 $this->t->set_var('disabled','DISABLED');
3071 $this->t->set_var('lang_done','Done');
3072 $this->t->set_var('lang_action','Viewing Visit');
3073 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit=' .
3074 $visit . '&action=' . 'edit'));
3077 $this->t->set_var('lang_reset','Clear Form');
3078 $this->t->set_var('lang_add','Add Visit');
3079 $this->t->set_var('lang_save','Save Changes');
3080 $this->t->set_var('edithandle','');
3081 $this->t->set_var('addhandle','');
3083 $this->t->pfp('out','form');
3085 if($action == 'view') { $this->t->set_var('lang_save','Edit Visit'); }
3086 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
3087 if($action == 'add') { $this->t->pfp('addhandle','add'); }
3089 $this->save_sessiondata();
3094 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3095 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3096 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3098 $this->t->set_file(array('att_view_t' => 'att_view.tpl'));
3099 $this->t->set_block('att_view_t','act_list','list');
3101 $this->t->set_block('att_view_t','month_list','list1');
3102 $this->t->set_block('att_view_t','header_list','list2');
3103 $this->t->set_block('att_view_t','individual_list','list3');
3105 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3106 $num_quarters = get_var('num_quarters',array('GET','POST'));
3107 if($num_quarters == '') { $num_quarters = $this->default_att_num_quarters; }
3108 $this->t->set_var('num_quarters',$num_quarters);
3109 $this->t->set_var('lang_filter','Filter');
3110 if($num_quarters == 1) {
3111 $this->t->set_var('lang_num_quarters','Quarter of History');
3113 $this->t->set_var('lang_num_quarters','Quarters of History');
3116 $num_months = $num_quarters * 3;
3117 $current_month = $this->current_month;
3118 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
3119 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
3120 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
3121 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
3123 // TODO: changed this so it picks the quorum dynamically
3124 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1";
3125 $this->db->query($sql,__LINE__,__FILE__);
3127 while ($this->db->next_record()) {
3128 $individual_name[$i] = $this->db->f('name');
3129 $individual[$i] = $this->db->f('individual');
3132 array_multisort($individual_name, $individual);
3134 // Create a list of sunday dates for a window of 3 months back and current month
3138 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, ($current_month-$num_months)+1, 1, date("y")));
3139 $last_date = explode("-",$sunday_list[0]['date']);
3140 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3141 $time_limit = mktime(0, 0, 0, $current_month, 31, date("y"));
3142 while($last_time < $time_limit) {
3143 $day = date("w",$last_time);
3144 if(date("w",$last_time) == 0) {
3145 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3146 $last_date = explode("-",$sunday_list[$i]['date']);
3147 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3148 $sunday_list[$i]['day'] = $last_date[2];
3149 $sunday_list[$i]['month'] = date("M",$last_time);
3150 $sunday_list[$i]['year'] = $last_date[0];
3152 $last_date = $sunday_list[$i]['date'];
3154 $last_time += 90000;
3155 if($found_sunday) { $i++; $found_sunday=0; }
3158 $total_individuals = count($individual);
3159 $old_month=$sunday_list[0]['month']; $span=0;
3160 for ($i=0; $i < count($sunday_list); $i++) {
3161 $date = $sunday_list[$i]['date'];
3162 $this->t->set_var('date',$sunday_list[$i]['date']);
3163 $this->t->set_var('day',$sunday_list[$i]['day']);
3164 if(($old_month != $sunday_list[$i]['month']) || $i == count($sunday_list)-1) {
3165 if($i == count($sunday_list)-1) { $span++; }
3166 $cur_month = $sunday_list[$i]['month'];
3167 $old_month = $sunday_list[$i]['month'];
3168 $link_data['menuaction'] = 'tc.tc.att_update';
3169 $link_data['month'] = $sunday_list[$i-1]['month'];
3170 $link_data['year'] = $sunday_list[$i-1]['year'];
3171 $link_data['action'] = 'update_month';
3172 $cur_month = $sunday_list[$i-1]['month'];
3173 $cur_year = $sunday_list[$i-1]['year'];
3174 $header_row .= "<th><font size=-3>$cur_month $cur_year</font></th>";
3175 $this->t->set_var('update_month',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3176 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3177 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3178 $this->t->set_var('span',$span); $span=0;
3179 $this->t->fp('list1','month_list',True);
3183 $this->t->set_var('total_individuals',$total_individuals);
3184 $this->t->set_var('header_row',$header_row);
3186 $individual_width=200; $att_width=25; $total_width=$individual_width;
3187 for ($i=0; $i < count($sunday_list); $i++) {
3188 $link_data['menuaction'] = 'tc.tc.att_update';
3189 $link_data['month'] = $sunday_list[$i]['month'];
3190 $link_data['year'] = $sunday_list[$i]['year'];
3191 $link_data['day'] = $sunday_list[$i]['day'];
3192 $link_data['date'] = $sunday_list[$i]['date'];
3193 $link_data['action'] = 'update_day';
3194 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3195 $this->t->set_var('date',$sunday_list[$i]['date']);
3196 $this->t->set_var('day',$sunday_list[$i]['day']);
3197 $this->t->set_var('month',$sunday_list[$i]['month']);
3198 $this->t->set_var('year',$sunday_list[$i]['year']);
3199 $this->t->fp('list2','header_list',True);
3200 $total_width += $att_width;
3201 $attendance[$monthnum[$sunday_list[$i]['month']]]=0;
3204 for ($i=0; $i < count($individual); $i++) {
3206 $this->nextmatchs->template_alternate_row_color(&$this->t);
3207 $this->t->set_var('individual_name',$individual_name[$i]);
3208 #print "checking for individual: " . $individual[$i] . "<br>";
3209 for ($j=0; $j < count($sunday_list); $j++) {
3210 #print "checking for date: " . $sunday_list[$j]['date'] . "<br>";
3211 #print "SELECT * FROM tc_attendance WHERE date='"
3212 # . $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i] . "<br>";
3213 $sql = "SELECT * FROM tc_attendance WHERE date='" .
3214 $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i];
3215 $this->db->query($sql,__LINE__,__FILE__);
3216 if($this->db->next_record()) {
3217 $cur_month = $sunday_list[$j]['month'];
3218 if($attended[$i][$cur_month] != 1) {
3219 $attended[$i][$cur_month]=1;
3220 $attendance[$monthnum[$cur_month]]++;
3222 $att_table .= '<td align=center><img src="images/checkmark.gif"></td>';
3224 $att_table .= '<td> </td>';
3227 $this->t->set_var('att_table',$att_table);
3228 $this->t->fp('list3','individual_list',True);
3230 $this->t->set_var('total_width',$total_width);
3231 $this->t->set_var('individual_width',$individual_width);
3232 $this->t->set_var('att_width',$att_width);
3234 # Now calculate attendance for these months
3235 $attendance_str = "";
3236 $nonattendance_str = "";
3237 $aveattendance_str = "";
3238 $avenonattendance_str = "";
3240 $ave_total_attended=0;
3242 foreach($attendance as $att => $value) {
3243 $total_attended = $attendance[$att];
3244 $ave_total_attended += $attendance[$att]; $num_months++;
3245 $percent = ceil(($total_attended / $total_individuals)*100);
3246 $attendance_str.="<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3247 $total_nonattended = $total_individuals - $total_attended;
3248 $percent = ceil(($total_nonattended / $total_individuals)*100);
3249 $nonattendance_str.="<td align=center><font size=-2><b>$total_nonattended ($percent%)</b></font></td>";
3251 $total_attended = ceil(($ave_total_attended / $num_months));
3252 $percent = ceil(($total_attended / $total_individuals)*100);
3253 $aveattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3254 $total_attended = $total_individuals - ceil(($ave_total_attended / $num_months));
3255 $percent = ceil(($total_attended / $total_individuals)*100);
3256 $avenonattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3259 $this->t->set_var('attendance',$attendance_str);
3260 $this->t->set_var('aveattendance',$aveattendance_str);
3261 $this->t->set_var('nonattendance',$nonattendance_str);
3262 $this->t->set_var('avenonattendance',$avenonattendance_str);
3264 $this->t->pfp('out','att_view_t');
3265 $this->save_sessiondata();
3268 function att_update()
3270 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3271 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3272 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3274 $this->t->set_file(array('form' => 'att_update.tpl'));
3275 $this->t->set_block('form','edit','edithandle');
3277 $this->t->set_block('form','month_list','list1');
3278 $this->t->set_block('form','header_list','list2');
3279 $this->t->set_block('form','individual_list','list3');
3281 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3283 $action = get_var('action',array('GET','POST'));
3284 $month = get_var('month',array('GET','POST'));
3285 $year = get_var('year',array('GET','POST'));
3286 $day = get_var('day',array('GET','POST'));
3287 $date = get_var('date',array('GET','POST'));
3289 if($action == 'save_month' || $action == 'save_day') {
3290 $new_data = get_var('individuals_attended',array('POST'));
3291 $month = $monthnum[$month]; if($month < 10) { $month = "0" . $month; }
3293 if($action == 'save_month') {
3294 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-%'",__LINE__,__FILE__);
3297 if($action == 'save_day') {
3298 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-".$day."'",__LINE__,__FILE__);
3301 foreach ($new_data as $data) {
3302 $data_array = explode("-",$data);
3303 $indiv = $data_array[0];
3304 $date = "$data_array[1]-$data_array[2]-$data_array[3]";
3305 $this->db->query("INSERT INTO tc_attendance (individual,date) " .
3306 "VALUES (" . $indiv . ",'". $date . "')",__LINE__,__FILE__);
3313 // TODO: changed this so it picks the quorum dynamically
3314 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1";
3315 $this->db->query($sql,__LINE__,__FILE__);
3317 while ($this->db->next_record()) {
3318 $indiv_name[$i] = $this->db->f('name');
3319 $individual[$i] = $this->db->f('individual');
3320 $indiv_attending[$individual[$i]] = $this->db->f('attending');
3323 array_multisort($indiv_name, $individual);
3325 if($action == 'update_month') {
3326 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_month'));
3330 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], 1, $year));
3331 $last_date = explode("-",$sunday_list[0]['date']);
3332 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3333 $time_limit = mktime(0, 0, 0, $monthnum[$month], 31, $year);
3334 while($last_time <= $time_limit) {
3335 $day = date("w",$last_time);
3336 if(date("w",$last_time) == 0) {
3337 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3338 $last_date = explode("-",$sunday_list[$i]['date']);
3339 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3340 $sunday_list[$i]['day'] = $last_date[2];
3341 $sunday_list[$i]['month'] = date("M",$last_time);
3342 $sunday_list[$i]['year'] = $last_date[0];
3345 $last_time += 90000;
3346 if($found_sunday) { $i++; $found_sunday=0; }
3349 $this->t->set_var('span', $i);
3350 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3351 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3352 $this->t->fp('list1','month_list',True);
3353 $indiv_width=200; $att_width=25; $total_width=$indiv_width;
3354 for ($i=0; $i < count($sunday_list); $i++) {
3355 $link_data['menuaction'] = 'tc.tc.att_update';
3356 $link_data['month'] = $sunday_list[$i]['month'];
3357 $link_data['year'] = $sunday_list[$i]['year'];
3358 $link_data['day'] = $sunday_list[$i]['day'];
3359 $link_data['date'] = $sunday_list[$i]['date'];
3360 $link_data['action'] = 'update_day';
3361 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3362 $this->t->set_var('date',$sunday_list[$i]['date']);
3363 $this->t->set_var('day',$sunday_list[$i]['day']);
3364 $this->t->set_var('month',$sunday_list[$i]['month']);
3365 $this->t->set_var('year',$sunday_list[$i]['year']);
3366 $this->t->fp('list2','header_list',True);
3367 $total_width += $att_width;
3371 if($action == 'update_day') {
3372 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_day'));
3373 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], $day, $year));
3374 $this->t->set_var('month',$month);
3375 $this->t->set_var('year',$year);
3376 $this->t->fp('list1','month_list',True);
3377 $this->t->set_var('date',$date);
3378 $this->t->set_var('day',$day);
3379 $this->t->set_var('month',$month);
3380 $this->t->set_var('year',$year);
3381 $this->t->fp('list2','header_list',True);
3384 for ($i=0; $i < count($individual); $i++) {
3386 $this->nextmatchs->template_alternate_row_color(&$this->t);
3387 $this->t->set_var('individual_name',$indiv_name[$i]);
3388 for ($j=0; $j < count($sunday_list); $j++) {
3389 $sql = "SELECT * FROM tc_attendance WHERE date='" .
3390 $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i];
3391 $this->db->query($sql,__LINE__,__FILE__);
3392 $value = $individual[$i] . "-" . $sunday_list[$j]['date'];
3393 if($this->db->next_record()) {
3394 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'" checked></td>';
3395 } else if($indiv_attending[$individual[$i]] == 1) {
3396 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'" checked></td>';
3398 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'"></td>';
3401 $this->t->set_var('att_table',$att_table);
3402 $this->t->fp('list3','individual_list',True);
3405 $this->t->set_var('lang_done', 'Cancel');
3406 $this->t->set_var('lang_reset','Clear Form');
3407 $this->t->set_var('lang_save','Save Changes');
3409 $this->t->pfp('out','form');
3410 $this->t->pfp('addhandle','edit');
3412 $this->save_sessiondata();
3417 $this->t->set_file(array('dir_view_t' => 'dir_view.tpl'));
3418 $this->t->set_block('dir_view_t','dir_list','list');
3420 $sql = "SELECT * FROM tc_individual where valid=1 and hh_position='Head of Household' ORDER BY name ASC";
3421 $this->db->query($sql,__LINE__,__FILE__);
3423 while ($this->db->next_record()) {
3424 $parent[$i]['id'] = $this->db->f('individual');
3425 $parent[$i]['name'] = $this->db->f('name');
3426 $parent[$i]['phone'] = $this->db->f('phone');
3427 $parent[$i]['address'] = $this->db->f('address');
3431 for ($i=0; $i < count($parent); $i++) {
3432 $name = $parent[$i]['name'];
3433 $phone = $parent[$i]['phone'];
3434 $address = $parent[$i]['address'];
3435 $this->t->set_var('name', $name);
3436 $this->t->set_var('address', $address);
3437 $this->t->set_var('phone', $phone);
3438 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3439 $this->t->set_var('tr_color',$tr_color);
3440 $this->t->fp('list','dir_list',True);
3441 //print "$phone $name $address<br>";
3443 $this->t->pfp('out','dir_view_t');
3444 $this->save_sessiondata();
3449 $this->t->set_file(array('org_view_t' => 'org_view.tpl'));
3450 $this->t->set_block('org_view_t','calling_list','list1');
3451 $this->t->set_block('org_view_t','org_list','list2');
3453 # Display a list ordered alphabetically
3454 $sql = "SELECT * FROM tc_calling ORDER BY name ASC";
3455 $this->db->query($sql,__LINE__,__FILE__);
3457 while ($this->db->next_record()) {
3458 $calling[$i]['name'] = $this->db->f('name');
3459 $calling[$i]['position'] = $this->db->f('position');
3460 $calling[$i]['sustained'] = $this->db->f('sustained');
3461 $calling[$i]['organization'] = $this->db->f('organization');
3464 for ($i=0; $i < count($calling); $i++) {
3465 $name = $calling[$i]['name'];
3466 $position = $calling[$i]['position'];
3467 $sustained = $calling[$i]['sustained'];
3468 $organization = $calling[$i]['organization'];
3469 $this->t->set_var('name', $name);
3470 $this->t->set_var('position', $position);
3471 $this->t->set_var('sustained', $sustained);
3472 $this->t->set_var('organization', $organization);
3473 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3474 $this->t->set_var('tr_color',$tr_color);
3475 $this->t->fp('list1','calling_list',True);
3478 # Display a list ordered by organization
3479 $sql = "SELECT * FROM tc_calling ORDER BY organization ASC";
3480 $this->db->query($sql,__LINE__,__FILE__);
3482 while ($this->db->next_record()) {
3483 $calling[$i]['name'] = $this->db->f('name');
3484 $calling[$i]['position'] = $this->db->f('position');
3485 $calling[$i]['sustained'] = $this->db->f('sustained');
3486 $calling[$i]['organization'] = $this->db->f('organization');
3489 for ($i=0; $i < count($calling); $i++) {
3490 $name = $calling[$i]['name'];
3491 $position = $calling[$i]['position'];
3492 $sustained = $calling[$i]['sustained'];
3493 $organization = $calling[$i]['organization'];
3494 $this->t->set_var('name', $name);
3495 $this->t->set_var('position', $position);
3496 $this->t->set_var('sustained', $sustained);
3497 $this->t->set_var('organization', $organization);
3498 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3499 $this->t->set_var('tr_color',$tr_color);
3500 $this->t->fp('list2','org_list',True);
3503 $this->t->pfp('out','org_view_t');
3504 $this->save_sessiondata();
3509 $this->t->set_file(array('sched_t' => 'schedule.tpl'));
3510 $this->t->set_block('sched_t','presidency_list','list');
3512 $action = get_var('action',array('GET','POST'));
3514 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule&action=save'));
3515 $this->t->set_var('title','Scheduling Tool');
3517 $this->t->set_var('lang_save','Save Schedule');
3518 $this->t->set_var('lang_reset','Cancel');
3520 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
3521 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
3523 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
3524 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
3526 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
3527 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
3529 $date_width=150; $time_width=220; $indiv_width=170; $family_width=180; $location_width=100;
3530 $table_width=$date_width + $time_width + $indiv_width + $family_width + $location_width;
3531 $header_row = "<th width=$date_width><font size=-2>Date</th>";
3532 $header_row.= "<th width=$time_width><font size=-2>Time</th>";
3533 $header_row.= "<th width=$indiv_width><font size=-2>individual</th>";
3534 $header_row.= "<th width=$family_width><font size=-2>Family</th>";
3535 $header_row.= "<th width=$location_width><font size=-2>Location</th>";
3538 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1 GROUP BY tp.individual ORDER BY ti.name ASC";
3539 $this->db->query($sql,__LINE__,__FILE__);
3541 while ($this->db->next_record()) {
3542 $presidency_data[$i]['id'] = $this->db->f('presidency');
3543 $presidency_data[$i]['name'] = $this->db->f('name');
3544 $presidency_data[$i]['indiv'] = $this->db->f('individual');
3545 $presidency2name[$presidency_data[$i]['id']] = $presidency_data[$i]['name'];
3546 $presidency2indiv[$presidency_data[$i]['id']] = $presidency_data[$i]['individual'];
3550 $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";
3551 $this->db->query($sql,__LINE__,__FILE__);
3553 while ($this->db->next_record()) {
3554 $family_id[$i] = $this->db->f('family');
3555 $family_name[$i] = $this->db->f('name');
3556 $familyid2name[$family_id[$i]] = $family_name[$i];
3557 $familyid2address[$family_id[$i]] = $this->db->f('address');
3560 array_multisort($family_name, $family_id);
3562 if($action == 'save') {
3563 $new_data = get_var('sched',array('POST'));
3564 foreach ($new_data as $presidency_array) {
3565 foreach ($presidency_array as $entry) {
3566 $presidency = $entry['presidency'];
3567 $appointment = $entry['appointment'];
3568 $location = $entry['location'];
3569 $date = $entry['date'];
3570 $hour = $entry['hour'];
3571 $minute = $entry['minute'];
3573 $indiv = $entry['individual'];
3574 $family = $entry['family'];
3575 $location = $entry['location'];
3576 if($pm) { $hour = $hour + 12; }
3577 $time = $hour.':'.$minute.':'.'00';
3580 // Update our location
3581 if($location == "") {
3583 $family_name_array = explode(",", $familyid2name[$family]);
3584 $family_last_name = $family_name_array[0];
3585 $family_address = $familyid2address[$family];
3586 $location = "$family_last_name"." home ($family_address)";
3587 } else if($indiv > 0) {
3588 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
3589 $supervisor_last_name = $supervisor_name_array[0];
3590 $sql = "SELECT * FROM tc_individual where individual='$presidency2indiv[$presidency]'";
3591 $this->db2->query($sql,__LINE__,__FILE__);
3592 if($this->db2->next_record()) {
3593 $mls_id = $this->db2->f('mls_id');
3595 $sql = "SELECT * FROM tc_individual where mls_id='$mls_id'";
3596 $this->db2->query($sql,__LINE__,__FILE__);
3597 if($this->db2->next_record()) {
3598 $supervisor_address = $this->db2->f('address');
3600 $location = "$supervisor_last_name"." home ($supervisor_address)";
3604 // Zero out the family or individual if date = NULL
3611 if(($indiv == 0) && ($family == 0)) { $location = ""; }
3613 // Update an existing appointment
3614 if($appointment < $this->max_appointments)
3616 //Only perform a database update if we have made a change to this appointment
3617 $sql = "SELECT * FROM tc_appointment where " .
3618 "appointment='$appointment'" .
3619 " and presidency='$presidency'" .
3620 " and individual='$indiv'" .
3621 " and family='$family'" .
3622 " and date='$date'" .
3623 " and time='$time'" .
3624 " and location='$location'";
3625 $this->db->query($sql,__LINE__,__FILE__);
3626 if(!$this->db->next_record()) {
3627 $old_date = $this->db->f('date');
3628 $old_time = $this->db->f('time');
3629 $this->db2->query("UPDATE tc_appointment set" .
3630 " family=" . $family .
3631 " ,individual=" . $indiv .
3632 " ,date='" . $date . "'" .
3633 " ,time='" . $time . "'" .
3634 " ,location='" . $location . "'" .
3635 " ,presidency='" . $presidency . "'" .
3636 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
3638 // Email the appointment
3639 $this->email_appt($appointment);
3643 // Add a new appointment
3644 else if(($appointment >= $this->max_appointments) && ($date != "") && ($time != ""))
3646 //print "adding entry: appt=$appointment date: $date time: $time individual: $indiv family: $family<br>";
3647 $this->db2->query("INSERT INTO tc_appointment (appointment,presidency,family,individual,date,time,location,uid) " .
3648 "VALUES (NULL,'" . $presidency . "','" . $family . "','" . $indiv . "','" .
3649 $date . "','" . $time . "','" . $location . "','" . $uid ."')",__LINE__,__FILE__);
3651 // Now reselect this entry from the database to see if we need
3652 // to send an appointment out for it.
3653 $sql = "SELECT * FROM tc_appointment where " .
3654 "individual='$indiv'" .
3655 " and family='$family'" .
3656 " and presidency='$presidency'" .
3657 " and date='$date'" .
3658 " and time='$time'" .
3660 " and location='$location'";
3661 $this->db3->query($sql,__LINE__,__FILE__);
3662 if($this->db3->next_record()) {
3663 // Email the appointment if warranted
3664 if(($date != "") && ($time != "") && (($indiv > 0) || $family > 0)) {
3665 $this->email_appt($this->db3->f('appointment'));
3672 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule');
3673 //Header('Location: ' . $take_me_to_url);
3676 // TODO: changed this so it picks the quorum dynamically
3677 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1 ORDER BY individual ASC";
3678 $this->db->query($sql,__LINE__,__FILE__);
3680 while ($this->db->next_record()) {
3681 $individual[$i] = $this->db->f('individual');
3682 $indiv_name[$i] = $this->db->f('name');
3683 $indiv_phone[$individual[$i]] = $this->db->f('phone');
3686 array_multisort($indiv_name, $individual);
3688 for ($i=0; $i < count($presidency_data); $i++) {
3689 $presidency = $presidency_data[$i]['id'];
3690 $interviewer = $presidency_data[$i]['individual'];
3691 $name = $presidency_data[$i]['name'];
3692 $this->t->set_var('presidency_name',$name);
3695 // query the database for all the appointments
3696 $sql = "SELECT * FROM tc_appointment where presidency=$presidency and date>=CURDATE() ORDER BY date ASC, time ASC";
3697 $this->db->query($sql,__LINE__,__FILE__);
3699 // Prefill any existing appointment slots
3700 while ($this->db->next_record()) {
3701 $appointment = $this->db->f('appointment');
3702 $indiv = $this->db->f('individual');
3703 $family = $this->db->f('family');
3704 $location = $this->db->f('location');
3706 if($location == "") {
3708 $family_name_array = explode(",", $familyid2name[$family]);
3709 $family_last_name = $family_name_array[0];
3710 $family_address = $familyid2address[$family];
3711 $location = "$family_last_name"." home ($family_address)";
3712 } else if($indiv > 0) {
3713 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
3714 $supervisor_last_name = $supervisor_name_array[0];
3715 $sql = "SELECT * FROM tc_individual where individual='$presidency2indiv[$presidency]'";
3716 $this->db2->query($sql,__LINE__,__FILE__);
3717 if($this->db2->next_record()) {
3718 $mls_id = $this->db2->f('mls_id');
3720 $sql = "SELECT * FROM tc_individual where mls_id='$mls_id'";
3721 $this->db2->query($sql,__LINE__,__FILE__);
3722 if($this->db2->next_record()) {
3723 $supervisor_address = $this->db2->f('address');
3725 $location = "$supervisor_last_name"." home ($supervisor_address)";
3729 $date = $this->db->f('date');
3730 $date_array = explode("-",$date);
3731 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
3732 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
3734 $time = $this->db->f('time');
3735 $time_array = explode(":",$time);
3736 $hour = $time_array[0];
3737 $minute = $time_array[1];
3739 if($hour > 12) { $pm=1; $hour = $hour - 12; }
3740 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
3742 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3745 $table_data.= '<td align=left>';
3746 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]',$date,'','','','','',$this->cal_options);
3747 $table_data.= '</td>';
3749 // Hour & Minutes selection
3750 $table_data.= "<td align=center>";
3751 $table_data .= $this->get_time_selection_form($hour, $minute, $pm, $presidency, $appointment);
3752 $table_data.= "</td>";
3754 // individual drop down list (for PPIs)
3755 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][indiv] STYLE="font-size : 8pt">';
3756 $table_data.= '<option value=0></option>';
3757 for ($j=0; $j < count($individual); $j++) {
3758 $id = $individual[$j];
3759 $name = $indiv_name[$j];
3760 if($individual[$j] == $indiv) {
3761 $selected[$id] = 'selected="selected"';
3763 $selected[$id] = '';
3765 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
3767 $table_data.='</select></td>';
3769 // Family drop down list (for Visits)
3770 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family] STYLE="font-size : 8pt">';
3771 $table_data.= '<option value=0></option>';
3772 for ($j=0; $j < count($individual); $j++) {
3773 $id = $family_id[$j];
3774 $name = $family_name[$j];
3775 if($family_id[$j] == $family) {
3776 $selected[$id] = 'selected="selected"';
3778 $selected[$id] = '';
3780 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
3782 $table_data.='</select></td>';
3784 // Location text box
3785 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
3786 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="'.$location.'" STYLE="font-size : 8pt">';
3788 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3789 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3791 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3792 $this->t->set_var('tr_color',$tr_color);
3795 // Create blank appointment slot
3796 for ($b=0; $b < 4; $b++) {
3797 $appointment = $this->max_appointments + $b;
3798 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3801 $table_data.= '<td align=left>';
3802 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]','','','','','','',$this->cal_options);
3803 $table_data.= '</td>';
3806 $table_data.= "<td align=center>";
3807 $table_data .= $this->get_time_selection_form(0, 0, 0, $presidency, $appointment);
3808 $table_data.= "</td>";
3810 // individual drop down list
3811 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][indiv] STYLE="font-size : 8pt">';
3812 $table_data.= '<option value=0></option>';
3813 for ($j=0; $j < count($individual); $j++) {
3814 $id = $individual[$j];
3815 $name = $indiv_name[$j];
3816 $table_data.= '<option value='.$id.'>'.$name.'</option>';
3818 $table_data.='</select></td>';
3820 // Family drop down list
3821 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family] STYLE="font-size : 8pt">';
3822 $table_data.= '<option value=0></option>';
3823 for ($j=0; $j < count($individual); $j++) {
3824 $id = $family_id[$j];
3825 $name = $family_name[$j];
3826 $table_data.= '<option value='.$id.'>'.$name.' Family</option>';
3828 $table_data.='</select></td>';
3830 // Location text box
3831 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
3832 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="" STYLE="font-size : 8pt">';
3834 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3835 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3837 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3838 $this->t->set_var('tr_color',$tr_color);
3841 $this->t->set_var('table_data',$table_data);
3842 $this->t->set_var('header_row',$header_row);
3843 $this->t->set_var('table_width',$table_width);
3844 $this->t->fp('list','presidency_list',True);
3847 $this->t->pfp('out','sched_t');
3848 $this->save_sessiondata();
3853 $this->t->set_file(array('email_t' => 'email.tpl'));
3854 $this->t->set_block('email_t','individual_list','list');
3856 $action = get_var('action',array('GET','POST'));
3858 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email'));
3859 $this->t->set_var('title','Email Tool');
3861 $this->t->set_var('lang_email','Send Email');
3862 $this->t->set_var('lang_reset','Cancel');
3864 $this->t->set_var('email_member_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=member'));
3865 $this->t->set_var('email_member_link_title','Email Quorum Member');
3867 $this->t->set_var('email_quorum_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=quorum'));
3868 $this->t->set_var('email_quorum_link_title','Email Quorum');
3870 $this->t->set_var('email_reminder_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=reminder'));
3871 $this->t->set_var('email_reminder_link_title','Email Reminders');
3873 $this->t->set_var('email_edit_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=edit'));
3874 $this->t->set_var('email_edit_link_title','Edit Email Addresses');
3877 $this->t->set_var('table_width',$table_width);
3879 $this->t->pfp('out','email_t');
3880 $this->save_sessiondata();
3885 $this->t->set_file(array('admin_t' => 'admin.tpl'));
3886 $this->t->set_block('admin_t','upload','uploadhandle');
3887 $this->t->set_block('admin_t','admin','adminhandle');
3888 $this->t->set_block('admin_t','cmd','cmdhandle');
3889 $this->t->set_block('admin_t','presidency','presidencyhandle');
3891 $this->t->set_var('upload_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=upload'));
3892 $this->t->set_var('presidency_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=presidency'));
3894 $action = get_var('action',array('GET','POST'));
3896 $this->t->pfp('out','admin_t');
3898 // TODO: changed this so it picks the quorum dynamically
3899 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1 ORDER BY individual ASC";
3900 $this->db->query($sql,__LINE__,__FILE__);
3902 while ($this->db->next_record()) {
3903 $individual[$i] = $this->db->f('individual');
3904 $indiv_name[$i] = $this->db->f('name');
3905 $indiv2name[$individual[$i]] = $indiv_name[$i];
3908 array_multisort($indiv_name, $individual);
3910 if($action == 'upload') {
3911 $target_path = $this->upload_target_path . '/' . basename( $_FILES['uploadedfile']['name']);
3913 if(($_FILES['uploadedfile']['type'] == "application/zip") ||
3914 ($_FILES['uploadedfile']['type'] == "application/x-zip-compressed") ||
3915 ($_FILES['uploadedfile']['type'] == "application/x-zip") ||
3916 ($_FILES['uploadedfile']['type'] == "application/octet-stream")) {
3918 if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
3919 $uploadstatus = "<b><font color=red> -E- Unable to move the uploaded file to ";
3920 $uploadstatus.= "the target path (check the path and permissions) of: $target_path</font></b>";
3921 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
3922 $uploadstatus.= "Tmp Filename : " . $_FILES['uploadedfile']['tmp_name'] . "<br>";
3923 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
3924 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
3925 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
3926 $uploadstatus.= "Error : " . $_FILES['uploadedfile']['error'] . "<br>";
3927 $this->t->set_var('uploadstatus',$uploadstatus);
3928 $this->t->pfp('uploadhandle','upload',True);
3932 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
3933 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
3934 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
3935 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
3936 $this->t->set_var('uploadstatus',$uploadstatus);
3937 $this->t->pfp('uploadhandle','upload');
3938 $this->t->set_var('uploadhandle','');
3939 print "<table border=1 width=80%><tr><td>\n<pre>";
3941 # make a directory for this data to be stored in
3942 $date="data_" . date("Y_m_d");
3943 $data_dir = $this->upload_target_path . '/' . $date;
3944 print "-> Making the data directory: $date<br>\n";
3945 exec('mkdir -p ' . $data_dir . ' 2>&1', $result, $return_code);
3946 if($return_code != 0) {
3947 print implode('\n',$result) . "<br>";
3948 print "<b><font color=red>";
3949 print "-E- Unable to create the data directory. Aborting import.";
3950 print "</font></b>";
3954 # move the file uploaded into this directory
3955 print "-> Moving the uploaded file into the data dir<br>\n";
3956 exec('mv ' . $target_path . ' ' . $data_dir . '/' . ' 2>&1', $result, $return_code);
3957 if($return_code != 0) {
3958 print implode('\n',$result) . "<br>";
3959 print "<b><font color=red>";
3960 print "-E- Unable to move the uploaded file into the data dir. Aborting import.";
3961 print "</font></b>";
3965 # unzip the data into this directory
3966 print "-> Unzipping the data<br>\n";
3967 exec($this->unzip_path .' -u '. $data_dir . '/*.zip -d ' . $data_dir . ' 2>&1', $result, $return_code);
3968 if($return_code != 0) {
3969 print implode('\n',$result) . "<br>";
3970 print "<b><font color=red>";
3971 print "-E- Unable to unzip the uploaded file into the data dir: $data_dir. Aborting import.";
3972 print "</font></b>";
3975 exec('mv ' . $data_dir . '/*/* '. $data_dir . ' 2>&1', $result, $return_code);
3977 # update the data_latest link to point to this new directory
3978 print "-> Updating the latest data dir link<br>\n";
3979 $data_latest = $this->upload_target_path . '/data_latest';
3980 exec('rm ' . $data_latest. '; ln -s ' . $data_dir .' '. $data_latest .' 2>&1', $result, $return_code);
3981 if($return_code != 0) {
3982 print implode('\n',$result) . "<br>";
3983 print "<b><font color=red>";
3984 print "-E- Unable to update the data latest link. Aborting import.";
3985 print "</font></b>";
3989 # run the import perl script to encorporate it into the DB
3990 ob_start('ob_logstdout', 2);
3991 print "-> Importing the data into the database<br>\n";
3992 ob_flush(); flush(); sleep(1);
3993 $import_log = $this->upload_target_path . '/import.log';
3994 $data_log = $this->upload_target_path . '/data.log';
3995 $import_cmd = $this->script_path . '/import_ward_data ' . $data_latest . ' 2>&1 | tee ' . $import_log;
3996 $parse_cmd = $this->script_path . '/parse_ward_data -v ' . $data_latest . ' > ' . $data_log . '2>&1';
3997 #print "import_cmd: $import_cmd<br>";
3998 #print "parse_cmd: $parse_cmd<br>";
3999 ob_start('ob_logstdout', 2);
4000 passthru($import_cmd);
4001 passthru($parse_cmd);
4002 ob_flush(); flush(); sleep(1);
4004 # fix the permissions of the data dir
4005 exec('chmod -R o-rwx ' . $data_dir, $result, $return_code);
4007 $this->t->pfp('cmdhandle','cmd');
4008 print "</pre></td></tr></table>";
4009 } else if(($_FILES['uploadedfile']['type'] != "application/zip") &&
4010 ($_FILES['uploadedfile']['type'] != "application/x-zip-compressed") &&
4011 ($_FILES['uploadedfile']['type'] != "application/x-zip") &&
4012 ($_FILES['uploadedfile']['type'] != "application/octet-stream")) {
4013 $uploadstatus = "<b><font color=red>The file format must be a .zip file, please try again! </font></b>";
4014 $uploadstatus.= "<br><br><b>Detected file format: " . $_FILES['uploadedfile']['type'] . "</b>";
4015 $this->t->set_var('uploadstatus',$uploadstatus);
4016 $this->t->pfp('uploadhandle','upload',True);
4018 $uploadstatus = "<b><font color=red> There was an error (" . $_FILES['uploadedfile']['error'];
4019 $uploadstatus.= ") uploading the file, please try again! </font></b>";
4020 $this->t->set_var('uploadstatus',$uploadstatus);
4021 $this->t->pfp('uploadhandle','upload',True);
4023 } else if($action == "presidency") {
4024 $new_data = get_var('eqpres',array('POST'));
4025 foreach ($new_data as $entry) {
4027 $email = $entry['email'];
4028 $indiv = $entry['indiv'];
4029 $name = $entry['name'];
4030 $district = $entry['district'];
4031 $president = $entry['president'];
4032 $counselor = $entry['counselor'];
4033 $secretary = $entry['secretary'];
4034 // look up the individual name for the ID
4035 $name = $indiv2name[$indiv];
4036 //print "id=$id indiv=$indiv name=$name email=$email district=$district president=$president ";
4037 //print "counselor=$counselor secretary=$secretary<br>";
4039 if(($indiv > 0) || ($name != "")) {
4040 if($id < $this->max_presidency_members) {
4041 //print "Updating Existing Entry<br>";
4042 $this->db2->query("UPDATE tc_presidency set" .
4043 " individual=" . $indiv .
4044 " ,district=" . $district .
4045 " ,email='" . $email . "'" .
4046 " ,president='" . $president . "'" .
4047 " ,counselor='" . $counselor . "'" .
4048 " ,secretary='" . $secretary . "'" .
4049 " WHERE presidency=" . $id,__LINE__,__FILE__);
4051 //print "Adding New Entry<br>";
4052 $this->db2->query("INSERT INTO tc_presidency (presidency,individual,district," .
4053 "email,president,counselor,secretary,valid) " .
4054 "VALUES (NULL,'" . $indiv . "','" . $district . "','" .
4055 $email . "','" . $president . "','" .
4056 $counselor . "','" . $secretary . "','1'" .
4057 ")",__LINE__,__FILE__);
4060 //print "Ignoring Blank Entry<br>";
4064 // Now update the tc_district table appropriately
4066 // Delete all the previous district entries from the table
4067 $this->db->query("DELETE from tc_district where valid=1",__LINE__,__FILE__);
4068 $this->db->query("DELETE from tc_district where valid=0",__LINE__,__FILE__);
4070 // Always add a "District 0" assigned to the High Priests Group
4072 $name = "High Priests";
4075 $this->db2->query("INSERT INTO tc_district (district,supervisor,valid) " .
4076 "VALUES ('" . $district . "','" .
4077 $indiv . "','" . $valid . "'" .
4078 ")",__LINE__,__FILE__);
4080 // Requery the tc_presidency table
4081 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1";
4082 $this->db->query($sql,__LINE__,__FILE__);
4083 while ($this->db->next_record()) {
4084 // Extract the data for each presidency record
4085 $id = $this->db->f('presidency');
4086 $indiv = $this->db->f('individual');
4087 $name = $this->db->f('name');
4088 $district = $this->db->f('district');
4091 // If we have a valid district, add it to the district table
4093 $this->db2->query("INSERT INTO tc_district (district,supervisor,valid) " .
4094 "VALUES ('" . $district . "','" .
4095 $indiv . "','" . $valid . "'" .
4096 ")",__LINE__,__FILE__);
4100 $this->t->set_var('adminhandle','');
4101 $this->t->pfp('adminhandle','admin');
4105 $this->t->set_var('adminhandle','');
4106 $this->t->pfp('adminhandle','admin');
4109 // Now save off the data needed for a Presidency Table Update
4111 $sql = "SELECT tp.*, ti.name FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1";
4112 $this->db->query($sql,__LINE__,__FILE__);
4114 $header_row = "<th>Individual</th><th>Email</th><th>District</th><th>President</th><th>Counselor</th><th>Secretary</th>";
4115 while ($this->db->next_record()) {
4116 // Extract the data for each presidency record
4117 $id = $this->db->f('presidency');
4118 $indiv = $this->db->f('individual');
4119 $district = $this->db->f('district');
4120 $name = $this->db->f('name');
4121 $email = $this->db->f('email');
4122 $president = $this->db->f('president');
4123 $counselor = $this->db->f('counselor');
4124 $secretary = $this->db->f('secretary');
4126 // Create the forms needed in the table
4127 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4130 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4133 if($eqpresidency == 0) {
4134 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4135 $table_data.= '<option value=0></option>';
4136 for ($j=0; $j < count($individual); $j++) {
4137 $tmp_id = $individual[$j];
4138 $name = $indiv_name[$j];
4139 if($individual[$j] == $indiv) {
4141 $selected = 'selected="selected"';
4145 $table_data.= '<option value='.$tmp_id.' '.$selected.'>'.$name.'</option>';
4147 $table_data.='</select></td>';
4148 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="'.$indivname.'">';
4150 $table_data.= '<td align=left><input type=text size="20" name="eqpresname" value="Presidency"></td>';
4151 $table_data.= '<input type=hidden name="eqpres['.$id.'][name]" value="Presidency">';
4155 $table_data .= '<td><input type="text" size="50" name="eqpres['.$id.'][email]" value="'.$email.'"></td>';
4158 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4159 $table_data.= '<option value=0></option>';
4160 for ($j=0; $j <= $this->max_num_districts; $j++) {
4161 if($district == $j) {
4162 $selected = 'selected="selected"';
4166 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4168 $table_data.='</select></td>';
4171 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4172 if($president == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4173 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4174 $table_data.='</select></td>';
4177 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4178 if($counselor == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4179 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4180 $table_data.='</select></td>';
4183 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4184 if($secretary == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4185 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4186 $table_data.='</select></td>';
4189 $table_data .= "</tr>\n";
4190 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4191 $this->t->set_var('tr_color',$tr_color);
4194 // Now create 1 blank row to always have a line available to add a new individual with
4195 $id = $this->max_presidency_members;
4196 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4198 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4200 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4201 $table_data.= '<option value=0></option>';
4202 for ($j=0; $j < count($individual); $j++) {
4203 $tmp_id = $individual[$j];
4204 $name = $indiv_name[$j];
4205 $table_data.= '<option value='.$tmp_id.'>'.$name.'</option>';
4207 $table_data.='</select></td>';
4208 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="">';
4210 $table_data.='<td><input type="text" size="50" name="eqpres['.$id.'][email]" value=""></td>';
4212 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4213 $table_data.= '<option value=0></option>';
4214 for ($j=0; $j <= $this->max_num_districts; $j++) {
4216 $selected = 'selected="selected"';
4220 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4222 $table_data.='</select></td>';
4224 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4225 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4226 $table_data.='</select></td>';
4228 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4229 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4230 $table_data.='</select></td>';
4232 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4233 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4234 $table_data.='</select></td>';
4236 $table_data .= "</tr>\n";
4237 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4238 $this->t->set_var('tr_color',$tr_color);
4240 $this->t->set_var('header_row',$header_row);
4241 $this->t->set_var('table_data',$table_data);
4242 $this->t->pfp('presidencyhandle','presidency',True);
4244 $this->save_sessiondata();
4247 function email_appt($appointment)
4249 //print "Emailing notification of appointment: $appointment <br>";
4251 $sql = "SELECT * FROM tc_appointment where appointment='$appointment'";
4252 $this->db->query($sql,__LINE__,__FILE__);
4254 while ($this->db->next_record()) {
4255 $appointment = $this->db->f('appointment');
4256 $presidency = $this->db->f('presidency');
4257 $location = $this->db->f('location');
4260 $indiv = $this->db->f('individual');
4262 $family = $this->db->f('family');
4266 $uid = $this->db->f('uid');
4268 // Extract the year, month, day, hours, minutes, seconds from the appointment time
4269 $appt_date = $this->db->f('date');
4270 $date_array = explode("-",$appt_date);
4271 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
4272 $appt_time = $this->db->f('time');
4273 $time_array = explode(":",$appt_time);
4274 $hour = $time_array[0]; $minute = $time_array[1]; $seconds = $time_array[2];
4276 // Format the appointment time into an iCal UTC equivalent
4277 $dtstamp = gmdate("Ymd"."\T"."His"."\Z");
4278 $dtstart = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds,$month,$day,$year));
4279 $dtstartstr = date("l, F d, o g:i A", mktime($hour,$minute,$seconds,$month,$day,$year));
4281 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.presidency='$presidency'";
4282 $this->db2->query($sql,__LINE__,__FILE__);
4283 if($this->db2->next_record()) {
4284 $email = $this->db2->f('email');
4285 $interviewer = $this->db2->f('name');
4288 // Set the email address of the interviewer
4292 $sql = "SELECT * FROM tc_individual where individual='$indiv'";
4293 $this->db2->query($sql,__LINE__,__FILE__);
4294 if($this->db2->next_record()) {
4295 $indiv_name = $this->db2->f('name');
4296 $phone = $this->db2->f('phone');
4297 $appt_name = $indiv_name . " Interview";
4298 $duration = $this->default_ppi_appt_duration * 60;
4303 $sql = "SELECT * FROM tc_family WHERE family='$family'";
4304 $this->db2->query($sql,__LINE__,__FILE__);
4305 if($this->db2->next_record()) {
4306 $individual = $this->db2->f('individual');
4307 $sql = "SELECT * FROM tc_individual where individual='$individual'";
4308 $this->db3->query($sql,__LINE__,__FILE__);
4309 if($this->db3->next_record()) {
4310 $phone = $this->db3->f('phone');
4311 $family_name = $this->db3->f('name');
4312 $phone = $this->db3->f('phone');
4314 $appt_name = $family_name . " Family Visit";
4315 $duration = $this->default_visit_appt_duration * 60;
4319 $dtend = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4320 $dtendstr = date("g:i A", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4321 $date = $dtstartstr . "-" . $dtendstr;
4322 $description = "$appt_name : $phone";
4324 if(($uid == 0) && ($appt_name != "")) {
4325 // Create a new calendar item for this appointment, since this must be the first time we
4326 // are sending it out.
4327 print "Sent new appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4328 $uid = rand() . rand(); // Generate a random identifier for this appointment
4329 $subject = "Created: $appt_name";
4331 $this->db->query("UPDATE tc_appointment set" .
4333 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4335 $action = "PUBLISH";
4336 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4337 $dtend, $date, $location, $appt_name, $description, $uid);
4338 } else if(($uid != 0) && ($appt_name == "")) {
4339 // Remove the calendar item for this appointment since it has already been sent
4340 // and there is no name we have changed it to.
4341 print "Sent deleted appointment to " . $interviewer . " at " . $email . " for " . $appt_date . " " . $appt_time . "<br>";
4342 $subject = "Canceled: $appt_date $appt_time";
4344 $this->db->query("UPDATE tc_appointment set" .
4346 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4349 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4350 $dtend, $date, $location, $subject, $subject, $uid);
4351 } else if($uid != 0) {
4352 // Update the existing appointment since we have changed it
4353 print "Sent updated appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4355 $subject = "Canceled: $appt_date $appt_time";
4357 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4358 $dtend, $date, $location, $subject, $subject, $uid);
4360 $uid = rand() . rand(); // Generate a random identifier for this appointment
4361 $this->db->query("UPDATE tc_appointment set" .
4363 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4365 $subject = "Updated: $appt_name";
4366 $action = "PUBLISH";
4367 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4368 $dtend, $date, $location, $appt_name, $description, $uid);
4374 function send_ical_appt($action, $to, $from, $subject, $dtstamp, $dtstart, $dtend, $date, $location, $summary, $description, $uid)
4376 // Initialize our local variables
4377 $boundary = "=MIME_APPOINTMENT_BOUNDARY";
4381 // Form the headers for the email message
4382 $headers.="X-Mailer: PHP/" . phpversion() . "\n";
4383 $headers.="Mime-Version: 1.0\n";
4384 $headers.="Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
4385 $headers.="Content-Disposition: inline\n";
4386 $headers.="Reply-To: $from\n";
4387 $headers.="From: $from\n";
4389 // Print the plaintext version of the appointment
4390 $message.="--$boundary\n";
4391 $message.="Content-Type: text/plain; charset=us-ascii\n";
4392 $message.="Content-Disposition: inline\n";
4394 $message.="What: $description\n";
4395 $message.="When: $date\n";
4396 $message.="Where: $location\n";
4399 // Print the .ics attachment version of the appointment
4400 $message.="--$boundary\n";
4401 $message.="Content-Type: text/calendar; charset=us-ascii\n";
4402 $message.="Content-Disposition: attachment; filename=\"appointment.ics\"\n";
4404 $message.="BEGIN:VCALENDAR" . "\n";
4405 $message.="VERSION:2.0" . "\n";
4406 $message.="PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN" . "\n";
4407 $message.="METHOD:$action" . "\n";
4408 $message.="BEGIN:VEVENT" . "\n";
4409 $message.="ORGANIZER:MAILTO:$from". "\n";
4410 $message.="DTSTAMP:$dtstamp" . "\n";
4411 $message.="DTSTART:$dtstart" . "\n";
4412 $message.="DTEND:$dtend" . "\n";
4413 $message.="SUMMARY:$summary" . "\n";
4414 $message.="DESCRIPTION:$description" . "\n";
4415 $message.="LOCATION:$location" . "\n";
4416 $message.="UID:$uid" ."\n";
4417 $message.="TRANSP:OPAQUE" . "\n";
4418 $message.="SEQUENCE:0" . "\n";
4419 $message.="CLASS:PUBLIC" . "\n";
4420 $message.="END:VEVENT" . "\n";
4421 $message.="END:VCALENDAR" . "\n";
4423 // Complete the message
4424 $message.="--$boundary\n";
4427 mail($to, $subject, $message, $headers);
4430 function get_time_selection_form($hour, $minute, $pm, $presidency, $appointment)
4435 if($hour == 0) { $blank = 1; }
4437 if($this->time_drop_down_lists == 1) {
4438 // Create drop down lists to get the time
4439 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][hour]>';
4440 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4441 foreach(range(1,12) as $num) {
4443 $selected = 'selected="selected"';
4447 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4449 $form_data.= '</select>';
4450 $form_data.= ' : ';
4451 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][minute]>';
4452 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4455 if($num < 10) { $num = "0" . "$num"; }
4456 if($minute == $num) {
4457 $selected = 'selected="selected"';
4461 if($blank == 1) { $selected = ""; }
4462 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4463 $num = $num + $this->time_drop_down_list_inc;
4465 $form_data.= '</select>';
4467 // Use free form text fields to get the time
4473 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][hour] value='.$hour.'>';
4475 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][minute] value='.$minute.'>';
4476 $form_data.= ' ';
4478 // Always use a drop-down select form for am/pm
4479 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][pm]>';
4482 $form_data.= '<option value=0 selected>am</option>';
4483 $form_data.= '<option value=1>pm</option>';
4486 $form_data.= '<option value=0>am</option>';
4487 $form_data.= '<option value=1 selected>pm</option>';
4490 $form_data.= '<option value=""></option>';
4491 $form_data.= '<option value=0>am</option>';
4492 $form_data.= '<option value=1>pm</option>';
4494 $form_data.= '</select>';