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 $ */
23 var $default_ht_num_months;
24 var $default_ppi_num_months;
25 var $default_ppi_num_years;
26 var $default_int_num_quarters;
27 var $default_int_num_years;
28 var $default_vis_num_years;
29 var $default_att_num_quarters;
30 var $max_num_districts;
33 var $upload_target_path;
35 var $max_appointments;
36 var $max_presidency_members;
38 var $public_functions = array
63 'willing_view' => True,
64 'willing_update' => True,
65 'send_ical_appt' => True,
66 'assign_view' => True,
67 'assign_update' => True,
68 'get_time_selection_form' => True,
73 if(file_exists("setup/tc_config.local")) {
74 include("setup/tc_config.local");
76 include("setup/tc_config");
79 $this->script_path = "$this->application_path"."/bin";
80 $this->max_presidency_members = 99;
81 $this->max_appointments = 32768;
83 $this->db = $GLOBALS['phpgw']->db;
84 $this->db2 = $this->db;
85 $this->db3 = $this->db;
86 $this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
87 $this->t = $GLOBALS['phpgw']->template;
88 $this->account = $GLOBALS['phpgw_info']['user']['account_id'];
89 $this->grants = $GLOBALS['phpgw']->acl->get_grants('tc');
90 $this->grants[$this->account] = PHPGW_ACL_READ + PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE;
92 $this->jscal = CreateObject('tc.jscalendar'); // before phpgw_header() !!!
93 $this->cal_options = 'daFormat : "%Y-%m-%d",
94 ifFormat : "%Y-%m-%d",
98 $GLOBALS['phpgw_info']['flags']['app_header'] = 'The 3rd Counselor';
99 $GLOBALS['phpgw']->common->phpgw_header();
101 $this->current_day = `date '+%d'`;
102 $this->current_day = $this->current_day-0; // Make it numeric
103 $this->current_month = `date '+%m'`;
104 $this->current_month = $this->current_month-0; // Make it numeric
105 $this->current_year = `date '+%Y'`;
106 $this->current_year = $this->current_year-0; // Make it numeric
109 $this->display_app_header();
112 function save_sessiondata()
117 function display_app_header()
119 $this->t->set_file(array('tc_header' => 'header.tpl'));
121 if (isset($phpgw_info['user']['preferences']['tc']['tc_font']))
123 $font = $phpgw_info['user']['preferences']['tc']['tc_font'];
130 $this->t->set_var('bg_color',$phpgw_info['theme']['th_bg']);
131 $this->t->set_var('font',$font);
132 $link_data['menuaction'] = 'tc.tc.ht_view';
133 $this->t->set_var('link_hometeaching',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
134 $this->t->set_var('lang_hometeaching','HomeTeaching');
135 $link_data['menuaction'] = 'tc.tc.act_list';
136 $this->t->set_var('link_activity',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
137 $this->t->set_var('lang_activity','Activities');
138 $link_data['menuaction'] = 'tc.tc.willing_view';
139 $this->t->set_var('link_willing',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
140 $this->t->set_var('lang_willing','Willingness');
141 $link_data['menuaction'] = 'tc.tc.assign_view';
142 $this->t->set_var('link_assignment',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
143 $this->t->set_var('lang_assignment','Assignments');
144 $link_data['menuaction'] = 'tc.tc.par_view';
145 $this->t->set_var('link_participation',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
146 $this->t->set_var('lang_participation','Participation');
147 $link_data['menuaction'] = 'tc.tc.ppi_view';
148 $this->t->set_var('link_ppi',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
149 $this->t->set_var('lang_ppi','PPIs');
150 $link_data['menuaction'] = 'tc.tc.int_view';
151 $this->t->set_var('link_int',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
152 $this->t->set_var('lang_int','Interviews');
153 $link_data['menuaction'] = 'tc.tc.vis_view';
154 $this->t->set_var('link_visit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
155 $this->t->set_var('lang_visit','Visits');
156 $link_data['menuaction'] = 'tc.tc.att_view';
157 $this->t->set_var('link_attendance',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
158 $this->t->set_var('lang_attendance','Attendance');
159 $link_data['menuaction'] = 'tc.tc.dir_view';
160 $this->t->set_var('link_dir',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
161 $this->t->set_var('lang_dir','Directory');
162 $link_data['menuaction'] = 'tc.tc.org_view';
163 $this->t->set_var('link_org',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
164 $this->t->set_var('lang_org','Callings');
165 $link_data['menuaction'] = 'tc.tc.admin';
166 $this->t->set_var('link_admin',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
167 $this->t->set_var('lang_admin','Admin');
168 $link_data['menuaction'] = 'tc.tc.schedule';
169 $this->t->set_var('link_schedule',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
170 $this->t->set_var('lang_schedule','Scheduling');
171 $link_data['menuaction'] = 'tc.tc.email';
172 $this->t->set_var('link_email',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
173 $this->t->set_var('lang_email','Email');
175 $this->t->pparse('out','tc_header');
180 $this->t->set_file(array('ht_view_t' => 'ht_view.tpl'));
181 $this->t->set_block('ht_view_t','district_list','list');
183 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
184 $num_months = get_var('num_months',array('GET','POST'));
185 if($num_months == '') { $num_months = $this->default_ht_num_months; }
186 $this->t->set_var('num_months',$num_months);
187 $this->t->set_var('lang_filter','Filter');
188 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
189 else { $this->t->set_var('lang_num_months','Months of History'); }
191 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
192 $this->t->set_var('title','Hometeaching');
194 $sql = "SELECT * FROM tc_district where valid=1 ORDER BY district ASC";
195 $this->db->query($sql,__LINE__,__FILE__);
197 while ($this->db->next_record())
199 $districts[$i]['district'] = $this->db->f('district');
200 $districts[$i]['name'] = $this->db->f('name');
201 $districts[$i]['supervisor'] = $this->db->f('supervisor');
205 $sql = "SELECT * FROM tc_indiv where valid=1 ORDER BY indiv ASC";
206 $this->db->query($sql,__LINE__,__FILE__);
208 while ($this->db->next_record())
210 $indiv_id[$i] = $this->db->f('indiv');
211 $indiv_name[$i] = $this->db->f('name');
212 $indiv_phone[$indiv_id[$i]] = $this->db->f('phone');
215 array_multisort($indiv_name, $indiv_id);
217 // Make an array mapping indiv_ids to indiv_names
218 for($i=0; $i < count($indiv_id); $i++) {
220 $indivs[$id] = $indiv_name[$i];
223 $this->nextmatchs->template_alternate_row_color(&$this->t);
224 for($m=$num_months; $m >= 0; $m--) { $total_families[$m]=0; }
225 for ($i=0; $i < count($districts); $i++) {
226 $this->t->set_var('district_number',$districts[$i]['district']);
227 $this->t->set_var('district_name',$districts[$i]['name']);
228 $supervisor = $districts[$i]['supervisor'];
230 // Select all the unique companionship numbers for this district
231 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$i]['district'];
232 $this->db->query($sql,__LINE__,__FILE__);
233 $j=0; $unique_companionships = '';
234 while ($this->db->next_record())
236 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
240 $comp_width=450; $visit_width=25; $table_width=$comp_width + $num_months*$visit_width;
241 $table_data=""; $num_companionships = 0;
242 for($m=$num_months; $m >= 0; $m--) { $visits[$m]=0; $num_families[$m]=0; }
243 for ($j=0; $j < count($unique_companionships); $j++) {
244 $companion_table_entry = "";
245 // Select all the companions in each companionship
246 $sql = "SELECT * FROM tc_companionship where valid=1 and ".
247 "companionship=". $unique_companionships[$j]['companionship'];
248 $this->db->query($sql,__LINE__,__FILE__);
250 while ($this->db->next_record())
252 // Get this companions information
253 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
254 $companionship = $this->db->f('companionship');
255 $indiv_id = $this->db->f('indiv');
256 $name = $indivs[$indiv_id];
257 $phone = $indiv_phone[$indiv_id];
258 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
260 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
262 // Get the names of the families assigned this home teaching companionship
263 $sql = "SELECT * from tc_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
264 $sql = $sql . " ORDER BY name ASC";
265 $this->db->query($sql,__LINE__,__FILE__);
267 while ($this->db->next_record())
269 $family_name = $this->db->f('name');
270 $family_id = $this->db->f('family');
271 $this->nextmatchs->template_alternate_row_color(&$this->t);
272 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
273 // Find out how many times Visits were performed by this companionship
274 // in the past $num_months for this Family
275 $header_row="<th width=$comp_width><font size=-2>Families</th>";
276 for($m=$num_months; $m >= 0; $m--) {
277 $month = $this->current_month - $m;
278 $year = $this->current_year;
279 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
280 if($month < 10) { $month = "0"."$month"; }
281 $month_start = "$year"."-"."$month"."-"."01";
282 $month_end = "$year"."-"."$month"."-"."31";
283 $month = "$month"."/"."$year";
285 //print "m: $m month: $month year: $year month_start: $month_start month_end: $month_end<br>";
286 // Add this to the query to filter on only visits made by this companionship:
287 // " AND companionship=" . $unique_companionships[$j]['companionship'].
289 // First check to see if the currently assigned companionship has visited them
290 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
291 " AND companionship=".$unique_companionships[$j]['companionship'].
292 " AND family=". $family_id;
293 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
294 if($this->db2->num_rows($query_id) == 0) {
295 // We did not find any visits made by the currently assigned companionship,
296 // look for visits made by any other companionship other than 0. (0 == EQ Presidency Visit)
297 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
298 " AND companionship!=0".
299 " AND family=". $family_id;
300 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
302 $this->db2->query($sql,__LINE__,__FILE__);
303 $link_data['menuaction'] = 'tc.tc.ht_update';
304 $link_data['date'] = $month_start;
305 $link_data['month_start'] = $month_start;
306 $link_data['month_end'] = $month_end;
307 $link_data['month'] = $month;
308 $link_data['district'] = $districts[$i]['district'];
309 $link_data['district_name'] = $districts[$i]['name'];
310 $link_data['action'] = 'view';
311 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
312 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
313 if(!$total_visits[$m]) { $total_visits[$m] = 0; }
314 if($this->db2->next_record()) {
315 if($this->db2->f('visited') == 'y') {
316 $visits[$m]++; $total_visits[$m]++;
317 $num_families[$m]++; $total_families[$m]++;
318 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/checkmark.gif"></a></td>';
320 else if($this->db2->f('visited') == 'n') {
321 $num_families[$m]++; $total_families[$m]++;
322 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/x.gif"></a></td>';
325 //$visits[$m]++; $total_visits[$m]++;
326 $table_data .= "<td> </td>";
330 //$visits[$m]++; $total_visits[$m]++;
331 $table_data .= "<td> </td>";
334 $table_data .= "</tr>";
337 $table_data .= "<tr><td colspan=20></td></tr>";
339 $table_data .= "<tr><td colspan=20><hr></td></tr>";
340 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
342 for($m=$num_months; $m >=0; $m--) {
343 if($num_families[$m] > 0) {
344 $percent = ceil(($visits[$m] / $num_families[$m])*100);
348 $stat_data .= "<td align=center><font size=-2><b>$visits[$m] / $num_families[$m]<br>$percent%</font></b></td>";
350 $stat_data .= "</tr>";
352 $this->t->set_var('table_width',$table_width);
353 $this->t->set_var('header_row',$header_row);
354 $this->t->set_var('table_data',$table_data);
355 $this->t->set_var('stat_data',$stat_data);
356 $this->t->fp('list','district_list',True);
359 $totals = "<tr><td><b><font size=-2>Total Families Hometaught:<br>Total Hometeaching Percentage:</font></b></td>";
360 for($m=$num_months; $m >=0; $m--) {
361 if($total_families[$m] > 0) {
362 $percent = ceil(($total_visits[$m] / $total_families[$m])*100);
366 $totals .= "<td align=center><font size=-2><b>$total_visits[$m] / $total_families[$m]<br>$percent%</font></b></td>";
370 $this->t->set_var('totals',$totals);
372 $this->t->pfp('out','ht_view_t');
373 $this->save_sessiondata();
379 $this->t->set_file(array('ht_update_t' => 'ht_update.tpl'));
380 $this->t->set_block('ht_update_t','district_list','list');
381 $this->t->set_block('ht_update_t','save','savehandle');
383 $district = get_var('district',array('GET','POST'));
384 $district_name = get_var('district_name',array('GET','POST'));
385 $date = get_var('date',array('GET','POST'));
386 $month = get_var('month',array('GET','POST'));
387 $month_start = get_var('month_start',array('GET','POST'));
388 $month_end = get_var('month_end',array('GET','POST'));
389 $action = get_var('action',array('GET','POST'));
391 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
392 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_update&action=save'));
393 $this->t->set_var('lang_done','Cancel');
394 $this->t->set_var('district_name',$district_name);
395 $this->t->set_var('district_number',$district);
396 $this->t->set_var('title','Hometeaching Update ' . $month);
397 $this->t->set_var('date',$date);
399 if($action == 'save')
401 // Get a list of all the companionships in this district
402 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $district;
403 $this->db->query($sql,__LINE__,__FILE__);
404 $j=0; $unique_companionships = '';
405 while ($this->db->next_record())
407 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
410 for ($j=0; $j < count($unique_companionships); $j++)
412 //$comp=$unique_companionships[$j]['companionship'];
413 //print "deleting from tc_visit where companionship=$comp and date=$date and district=$district<br>";
414 // Delete all the visits that have taken place for all families for this companionsthip for this month
415 $this->db->query("DELETE from tc_visit where companionship=" . $unique_companionships[$j]['companionship'] .
416 " AND " . "date='" . $date . "'",__LINE__,__FILE__);
419 // Now, add the visits that are checked for this month
420 $new_data = get_var('family_visited',array('POST'));
421 foreach ($new_data as $family)
423 foreach ($family as $data)
425 //print "family_visited: $data <br>";
426 $data_array = explode("/",$data);
427 $family_id = $data_array[0];
428 $companionship = $data_array[1];
429 $date = $data_array[2];
430 $visited = $data_array[3];
431 if($visited == "") { $visited = $data_array[4]; }
432 //print "family_id: $family_id companionship: $companionship date: $date visited: $visited<br>";
433 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes,visited) "
434 . "VALUES (" . $family_id .",". $companionship .",'". $date ."','','". $visited ."')",__LINE__,__FILE__);
441 $sql = "SELECT * FROM tc_indiv where valid=1 ORDER BY indiv ASC";
442 $this->db->query($sql,__LINE__,__FILE__);
444 while ($this->db->next_record())
446 $indiv_id[$i] = $this->db->f('indiv');
447 $indiv_name[$i] = $this->db->f('name');
448 $indiv_phone[$indiv_id[$i]] = $this->db->f('phone');
451 array_multisort($indiv_name, $indiv_id);
453 // Make an array mapping indiv_ids to indiv_names
454 for($i=0; $i < count($indiv_id); $i++) {
456 $indivs[$id] = $indiv_name[$i];
459 // Select all the unique companionship numbers for this district
460 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $district;
461 $this->db->query($sql,__LINE__,__FILE__);
462 $j=0; $unique_companionships = '';
463 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())
480 // Get this companions information
481 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
482 $companionship = $this->db->f('companionship');
483 $indiv_id = $this->db->f('indiv');
484 $name = $indivs[$indiv_id];
485 $phone = $indiv_phone[$indiv_id];
486 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
488 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
490 // Get the names of the families assigned this home teaching companionship
491 $sql = "SELECT * from tc_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
492 $sql = $sql . " ORDER BY name ASC";
493 $this->db->query($sql,__LINE__,__FILE__);
494 while ($this->db->next_record())
496 $family_name = $this->db->f('name');
497 $family_id = $this->db->f('family');
498 $this->nextmatchs->template_alternate_row_color(&$this->t);
499 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
501 $header_row="<th width=$comp_width><font size=-2>Families</th>";
503 // First check to see if the currently assigned companionship has visited them
504 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
505 " AND companionship=".$unique_companionships[$j]['companionship'].
506 " AND family=". $family_id;
507 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
508 if($this->db2->num_rows($query_id) == 0) {
509 // We did not find any visits made by the currently assigned companionship,
510 // look for visits made by any other companionship other than 0. (0 == EQ Presidency Visit)
511 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
512 " AND companionship!=0".
513 " AND family=". $family_id;
514 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
517 $value = $family_id . "/" . $unique_companionships[$j]['companionship'] . "/" . $date;
518 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
519 if(!$total_visits) { $total_visits = 0; }
520 if($this->db2->next_record()) {
521 if($this->db2->f('visited') == 'y') {
522 $visits++; $total_visits++; $num_families++;
523 $table_data .= '<td width=100 align=center>';
524 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y" checked>Y';
525 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
526 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/"> ';
527 $table_data .= '</td>';
528 } else if($this->db2->f('visited') == 'n') {
530 $table_data .= '<td width=100 align=center>';
531 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
532 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n" checked>N';
533 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/">';
534 $table_data .= '</td>';
536 $table_data .= '<td width=100 align=center>';
537 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
538 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
539 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
540 $table_data .= '</td>';
545 $table_data .= '<td width=100 align=center>';
546 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
547 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
548 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
549 $table_data .= '</td>';
552 $table_data .= "</tr>";
553 $table_data .= "<tr><td colspan=20></td></tr>";
555 $table_data .= "<tr><td colspan=20><hr></td></tr>";
556 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
558 $percent = ceil(($visits / $num_families)*100);
559 $stat_data .= "<td align=center><font size=-2><b>$visits / $num_families<br>$percent%</font></b></td>";
560 $stat_data .= "</tr>";
562 $this->t->set_var('table_width',$table_width);
563 $this->t->set_var('header_row',$header_row);
564 $this->t->set_var('table_data',$table_data);
565 $this->t->set_var('stat_data',$stat_data);
566 $this->t->fp('list','district_list',True);
568 $this->t->set_var('lang_reset','Clear Form');
569 $this->t->set_var('lang_save','Save Changes');
570 $this->t->set_var('savehandle','');
572 $this->t->pfp('out','ht_update_t');
573 $this->t->pfp('addhandle','save');
575 $this->save_sessiondata();
580 $this->t->set_file(array('act_list_t' => 'act_list.tpl'));
581 $this->t->set_block('act_list_t','act_list','list');
583 $this->t->set_var('lang_name','Assignment');
584 $this->t->set_var('lang_date','Date');
585 $this->t->set_var('lang_notes','Description');
587 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
588 $this->db->query($sql,__LINE__,__FILE__);
589 $total_records = $this->db->num_rows();
592 while ($this->db->next_record())
594 $activity_list[$i]['activity'] = $this->db->f('activity');
595 $activity_list[$i]['assignment'] = $this->db->f('assignment');
596 $activity_list[$i]['date'] = $this->db->f('date');
597 $activity_list[$i]['notes'] = $this->db->f('notes');
599 $sql = "SELECT * FROM tc_assignment WHERE assignment='" . $activity_list[$i]['assignment'] . "'";
600 $this->db2->query($sql,__LINE__,__FILE__);
601 if($this->db2->next_record())
603 $activity_list[$i]['name'] = $this->db2->f('name');
604 $activity_list[$i]['code'] = $this->db2->f('code');
609 for ($i=0; $i < count($activity_list); $i++)
611 $this->nextmatchs->template_alternate_row_color(&$this->t);
612 $this->t->set_var('name',$activity_list[$i]['name']);
613 $this->t->set_var('date',$activity_list[$i]['date']);
614 $activity_notes = $activity_list[$i]['notes'];
615 if(strlen($activity_notes) > 40) { $activity_notes = substr($activity_notes,0,40) . "..."; }
616 $this->t->set_var('notes',$activity_notes);
618 $link_data['menuaction'] = 'tc.tc.act_view';
619 $link_data['activity'] = $activity_list[$i]['activity'];
620 $link_data['action'] = 'view';
621 $this->t->set_var('view',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
622 $this->t->set_var('lang_view','View');
624 $link_data['menuaction'] = 'tc.tc.act_update';
625 $link_data['activity'] = $activity_list[$i]['activity'];
626 $link_data['action'] = 'edit';
627 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
628 $this->t->set_var('lang_edit','Edit');
630 $this->t->fp('list','act_list',True);
633 $link_data['menuaction'] = 'tc.tc.act_update';
634 $link_data['activity'] = '0';
635 $link_data['action'] = 'add';
636 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/tc/index.php',$link_data)
637 . '"><input type="submit" name="Add" value="' . 'Add Activity' .'"></font></form>');
639 $this->t->pfp('out','act_list_t');
640 $this->save_sessiondata();
645 $this->t->set_file(array('act_view_t' => 'act_view.tpl'));
646 $this->t->set_block('act_view_t','part_list','list');
648 $sql = "SELECT * FROM tc_activity WHERE activity=" . intval(get_var('activity',array('GET','POST')));
649 $this->db->query($sql,__LINE__,__FILE__);
650 $this->db->next_record();
651 $this->t->set_var('assignment', $this->db->f('assignment'));
652 $this->t->set_var('date', $this->db->f('date'));
653 $this->t->set_var('notes', $this->db->f('notes'));
655 $sql = "SELECT * FROM tc_assignment WHERE assignment='" . $this->db->f('assignment') . "'";
656 $this->db2->query($sql,__LINE__,__FILE__);
657 if($this->db2->next_record())
659 $this->t->set_var('name', $this->db2->f('name'));
660 $this->t->set_var('code', $this->db2->f('code'));
662 $this->t->set_var('lang_name','Assignment');
663 $this->t->set_var('lang_date','Date');
664 $this->t->set_var('lang_notes','Description');
665 $this->t->set_var('lang_done','Done');
666 $this->t->set_var('lang_action','View');
668 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
669 $this->t->set_var('tr_color',$tr_color);
671 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_list'));
673 $link_data['menuaction'] = 'tc.tc.act_update';
674 $link_data['activity'] = get_var('activity',array('GET','POST'));
675 $link_data['action'] = 'edit';
676 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
677 $this->t->set_var('lang_edit','Edit');
678 $this->t->set_var('cal_date',$this->db->f('date'));
680 // Now find out which indivs participated in this activity
681 $sql = "SELECT * FROM tc_participation WHERE activity=" . intval(get_var('activity',array('GET','POST')));
682 $this->db->query($sql,__LINE__,__FILE__);
683 $total_records = $this->db->num_rows();
686 while ($this->db->next_record())
688 $part_list[$i]['indiv'] = $this->db->f('indiv');
692 for ($i=0; $i < count($part_list); $i++)
694 $sql = "SELECT * FROM tc_indiv WHERE indiv=" . $part_list[$i]['indiv'];
695 $this->db->query($sql,__LINE__,__FILE__);
696 $this->db->next_record();
697 $names[$i] = $this->db->f('name');
700 for ($i=0; $i < count($names); $i++)
702 //$this->nextmatchs->template_alternate_row_color(&$this->t);
703 $this->t->set_var('indiv_name',$names[$i]);
704 if(($i+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
705 else { $this->t->set_var('table_sep',"</td>"); }
706 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
707 $this->t->fp('list','part_list',True);
710 $this->t->pfp('out','act_view_t');
711 $this->save_sessiondata();
714 function act_update()
716 $this->t->set_file(array('form' => 'act_update.tpl'));
717 $this->t->set_block('form','indiv_list','list');
718 $this->t->set_block('form','add','addhandle');
719 $this->t->set_block('form','edit','edithandle');
720 $this->t->set_var('lang_done','Done');
722 $action = get_var('action',array('GET','POST'));
723 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_list'));
724 $activity['activity'] = intval(get_var('activity',array('GET','POST')));
726 if($action == 'save')
728 $activity['assignment'] = get_var('assignment',array('POST'));
729 $activity['date'] = get_var('date',array('POST'));
730 $activity['notes']= get_var('notes',array('POST'));
731 $this->db->query("UPDATE tc_activity set " .
732 " assignment='" . $activity['assignment'] .
733 "', date='" . $activity['date'] . "'" .
734 ", notes='" . $activity['notes'] . "'" .
735 " WHERE activity=" . $activity['activity'],__LINE__,__FILE__);
737 // Delete all the individuals who have particiapted in this activity
738 $this->db->query("DELETE from tc_participation where activity=".$activity['activity'],__LINE__,__FILE__);
740 // Re-add the individuals who are checked as having participated in this activity
741 $indivs = get_var('indiv_name',array('POST'));
742 if(is_array($indivs)) { // Only do the foreach loop if we have a valid array of indivs to work with
743 foreach ($indivs as $indiv)
745 $this->db->query("INSERT INTO tc_participation (indiv,activity) "
746 . "VALUES (" . $indiv . ",". $activity['activity'] . ")",__LINE__,__FILE__);
754 if($action == 'insert')
756 $activity['assignment'] = get_var('assignment',array('POST'));
757 $activity['date'] = get_var('date',array('POST'));
758 $activity['notes']= get_var('notes',array('POST'));
759 $this->db->query("INSERT INTO tc_activity (assignment,date,notes) "
760 . "VALUES ('" . $activity['assignment'] . "','"
761 . $activity['date'] . "','" . $activity['notes'] . "')",__LINE__,__FILE__);
763 $sql = "SELECT * FROM tc_activity WHERE assignment='".$activity['assignment']."' "
764 . " AND date='".$activity['date']."' AND notes='".$activity['notes']."'";
765 $this->db->query($sql,__LINE__,__FILE__);
766 if($this->db->next_record()) {
767 //print "activity: " . $this->db->f('activity') . "<br>";
768 $activity['activity'] = $this->db->f('activity');
771 $indivs = get_var('indiv_name',array('POST'));
772 foreach ($indivs as $indiv)
774 $this->db->query("INSERT INTO tc_participation (indiv,activity) "
775 . "VALUES (" . $indiv . ",". $activity['activity'] . ")",__LINE__,__FILE__);
784 $activity['activity'] = 0;
785 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
786 $this->t->set_var('assignment','');
787 $this->t->set_var('date','');
788 $this->t->set_var('notes','');
789 $this->t->set_var('lang_done','Cancel');
790 $this->t->set_var('lang_action','Adding New Activity');
791 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_update&activity='
792 . $activity['activity'] . '&action=' . 'insert'));
795 if($action == 'edit')
797 $sql = "SELECT * FROM tc_activity WHERE activity=" . $activity['activity'];
798 $this->db->query($sql,__LINE__,__FILE__);
799 $this->db->next_record();
800 $this->t->set_var('cal_date',$this->jscal->input('date',$this->db->f('date'),'','','','','',$this->cal_options));
801 $this->t->set_var('assignment', $this->db->f('assignment'));
802 $assignment = $this->db->f('assignment');
803 $this->t->set_var('date', $this->db->f('date'));
804 $this->t->set_var('notes', $this->db->f('notes'));
805 $this->t->set_var('lang_done','Cancel');
806 $this->t->set_var('lang_action','Editing Activity');
807 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_update&activity='
808 . $activity['activity'] . '&action=' . 'save'));
812 // Create the assignments drop-down list
813 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
814 $this->db->query($sql,__LINE__,__FILE__);
816 while ($this->db->next_record())
818 $assignments[$i]['assignment'] = $this->db->f('assignment');
819 $assignments[$i]['name'] = $this->db->f('name');
820 $assignments[$i]['code'] = $this->db->f('code');
824 $assignment_data.= '<select name=assignment>';
825 $assignment_data.= '<option value=0></option>';
826 for ($j=0; $j < count($assignments); $j++) {
827 $id = $assignments[$j]['assignment'];
828 $name = $assignments[$j]['name'];
829 if($assignments[$j]['assignment'] == $assignment) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
830 $assignment_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
832 $assignment_data.='</select>';
833 $this->t->set_var('assignment_data',$assignment_data);
835 // Create individual selection boxes
836 $sql = "SELECT * FROM tc_indiv";
837 $this->db->query($sql,__LINE__,__FILE__);
839 while ($this->db->next_record())
841 if($this->db->f('valid') == 1 || $action != 'add') {
842 $indiv_name[$i] = $this->db->f('name');
843 $indiv_id[$i] = $this->db->f('indiv');
844 $indiv_valid[$i] = $this->db->f('valid');
848 array_multisort($indiv_name, $indiv_id, $indiv_valid);
851 for ($i=0; $i < count($indiv_id); $i++)
853 //$this->nextmatchs->template_alternate_row_color(&$this->t);
854 $sql = "SELECT * FROM tc_participation where activity=". $activity['activity'] . " AND indiv=" . $indiv_id[$i];
855 $this->db->query($sql,__LINE__,__FILE__);
856 if($this->db->next_record()) { $this->t->set_var('checked','checked'); $checked=1; }
857 else { $this->t->set_var('checked',''); $checked=0; }
858 if($checked || $indiv_valid[$i] == 1) {
859 $this->t->set_var('indiv_name',$indiv_name[$i]);
860 $this->t->set_var('indiv',$indiv_id[$i]);
861 if(($j+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
862 else { $this->t->set_var('table_sep',"</td>"); }
863 if(($j) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
864 $this->t->fp('list','indiv_list',True);
869 $this->t->set_var('lang_reset','Clear Form');
870 $this->t->set_var('lang_add','Add Activity');
871 $this->t->set_var('lang_save','Save Changes');
872 $this->t->set_var('edithandle','');
873 $this->t->set_var('addhandle','');
875 $this->t->pfp('out','form');
876 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
877 if($action == 'add') { $this->t->pfp('addhandle','add'); }
879 $this->save_sessiondata();
882 function assign_view()
884 $this->t->set_file(array('assign_view_t' => 'assign_view.tpl'));
885 $this->t->set_block('assign_view_t','assign_view','list');
887 $this->t->set_var('lang_name','Assignment Name');
888 $this->t->set_var('lang_code','Code');
890 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
891 $this->db->query($sql,__LINE__,__FILE__);
892 $total_records = $this->db->num_rows();
895 while ($this->db->next_record())
897 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
898 $assignment_list[$i]['name'] = $this->db->f('name');
899 $assignment_list[$i]['code'] = $this->db->f('code');
903 for ($i=0; $i < count($assignment_list); $i++)
905 $this->nextmatchs->template_alternate_row_color(&$this->t);
906 $this->t->set_var('name',$assignment_list[$i]['name']);
907 $this->t->set_var('code',$assignment_list[$i]['code']);
909 $link_data['menuaction'] = 'tc.tc.assign_update';
910 $link_data['assignment'] = $assignment_list[$i]['assignment'];
911 $link_data['action'] = 'edit';
912 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
913 $this->t->set_var('lang_edit','Edit');
915 $link_data['menuaction'] = 'tc.tc.assign_update';
916 $link_data['assignment'] = '0';
917 $link_data['action'] = 'add';
918 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/tc/index.php',$link_data)
919 . '"><input type="submit" name="Add" value="' . 'Add Assignment' .'"></font></form>');
921 $this->t->fp('list','assign_view',True);
924 $this->t->pfp('out','assign_view_t');
925 $this->save_sessiondata();
928 function assign_update()
930 $this->t->set_file(array('form' => 'assign_update.tpl'));
931 $this->t->set_block('form','add','addhandle');
932 $this->t->set_block('form','edit','edithandle');
933 $this->t->set_var('lang_done','Done');
935 $action = get_var('action',array('GET','POST'));
936 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_view'));
937 $assignment['assignment'] = intval(get_var('assignment',array('GET','POST')));
939 if($action == 'save')
941 $assignment['name'] = get_var('name',array('POST'));
942 $assignment['code'] = get_var('code',array('POST'));
943 $this->db->query("UPDATE tc_assignment set " .
944 " name='" . $assignment['name'] . "'" .
945 ", code='" . $assignment['code'] . "'" .
946 " WHERE assignment=" . $assignment['assignment'],__LINE__,__FILE__);
948 $this->assign_view();
952 if($action == 'insert')
954 $assignment['name'] = get_var('name',array('POST'));
955 $assignment['code'] = get_var('code',array('POST'));
956 $this->db->query("INSERT INTO tc_assignment (name,code) "
957 . "VALUES ('" . $assignment['name'] . "','"
958 . $assignment['code'] . "')",__LINE__,__FILE__);
959 $this->assign_view();
965 $assignment['assignment'] = 0;
966 $this->t->set_var('name','');
967 $this->t->set_var('code','');
968 $this->t->set_var('lang_done','Cancel');
969 $this->t->set_var('lang_action','Adding New Assignment');
970 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_update&assignment='
971 . $assignment['assignment'] . '&action=' . 'insert'));
974 if($action == 'edit')
976 $sql = "SELECT * FROM tc_assignment WHERE assignment=" . $assignment['assignment'];
977 $this->db->query($sql,__LINE__,__FILE__);
978 $this->db->next_record();
979 $this->t->set_var('name', $this->db->f('name'));
980 $this->t->set_var('code', $this->db->f('code'));
981 $this->t->set_var('lang_done','Cancel');
982 $this->t->set_var('lang_action','Editing Assignment');
983 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_update&assignment='
984 . $assignment['assignment'] . '&action=' . 'save'));
988 $this->t->set_var('lang_reset','Clear Form');
989 $this->t->set_var('lang_add','Add Assignment');
990 $this->t->set_var('lang_save','Save Changes');
991 $this->t->set_var('edithandle','');
992 $this->t->set_var('addhandle','');
994 $this->t->pfp('out','form');
995 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
996 if($action == 'add') { $this->t->pfp('addhandle','add'); }
998 $this->save_sessiondata();
1003 $this->t->set_file(array('par_view_t' => 'par_view.tpl'));
1004 $this->t->set_block('par_view_t','header_list','list1');
1005 $this->t->set_block('par_view_t','indiv_list','list2');
1007 // TODO: changed this so it picks the quorum dynamically
1008 $sql = "SELECT * FROM tc_indiv where steward='Elder' and valid=1";
1009 $this->db->query($sql,__LINE__,__FILE__);
1011 while ($this->db->next_record())
1013 $indiv_name[$i] = $this->db->f('name');
1014 $indiv_id[$i] = $this->db->f('indiv');
1017 array_multisort($indiv_name, $indiv_id);
1019 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
1020 $this->db->query($sql,__LINE__,__FILE__);
1021 $total_records = $this->db->num_rows();
1024 while ($this->db->next_record())
1026 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1027 $activity_list[$i]['date'] = $this->db->f('date');
1028 $activity_list[$i]['activity'] = $this->db->f('activity');
1032 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1033 $this->db->query($sql,__LINE__,__FILE__);
1035 while($this->db->next_record())
1037 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1038 $assignment_list[$i]['name'] = $this->db->f('name');
1039 $assignment_list[$i]['code'] = $this->db->f('code');
1043 $indiv_width=300; $part_width=25; $assignment_width=50;
1044 $total_width=$indiv_width+$part_width;
1045 for ($i=0; $i < count($assignment_list); $i++) {
1046 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1047 $this->t->set_var('assignment_code',$assignment_list[$i]['code']);
1048 $this->t->fp('list1','header_list',True);
1049 $total_width += $assignment_width;
1052 for ($i=0; $i < count($indiv_id); $i++) {
1053 $participated=0; $part_table = '';
1054 $this->nextmatchs->template_alternate_row_color(&$this->t);
1055 $this->t->set_var('indiv_name',$indiv_name[$i]);
1056 for ($j=0; $j < count($assignment_list); $j++) {
1057 $date = "0000-00-00"; $checkmark=0; $num_matches=0;
1058 for ($k=0; $k < count($activity_list); $k++) {
1059 if($assignment_list[$j]['assignment'] == $activity_list[$k]['assignment']) {
1060 $sql = "SELECT * FROM tc_participation where "
1061 . " activity=" . $activity_list[$k]['activity']
1062 . " AND indiv=" . $indiv_id[$i];
1063 $this->db->query($sql,__LINE__,__FILE__);
1064 while($this->db->next_record()) {
1065 if($activity_list[$k]['date'] > $date) {
1066 $date = $activity_list[$k]['date'];
1075 $part_table .= '<td align=center><img src="images/checkmark.gif">';
1076 $part_table .= '<font size=-2>'.$num_matches.'</font><br>';
1077 $part_table .= '<font size=-2>'.$date.'</font></td>';
1079 $part_table .= '<td> </td>';
1082 if($participated) { $part_table .= '<td align=center><img src="images/checkmark.gif">'.$participated.'</td>'; }
1083 else { $part_table .= '<td> </td>'; }
1084 $this->t->set_var('part_table',$part_table);
1085 $this->t->fp('list2','indiv_list',True);
1087 $this->t->set_var('total_width',$total_width);
1088 $this->t->set_var('indiv_width',$indiv_width);
1089 $this->t->set_var('part_width',$part_width);
1090 $this->t->set_var('act_width',$act_width);
1091 $this->t->pfp('out','par_view_t');
1092 $this->save_sessiondata();
1095 function willing_view()
1097 $this->t->set_file(array('willing_view_t' => 'willing_view.tpl'));
1098 $this->t->set_block('willing_view_t','header_list','list1');
1099 $this->t->set_block('willing_view_t','indiv_list','list2');
1101 $this->t->set_var('lang_filter','Filter');
1102 $this->t->set_var('lang_filter_unwilling','Filter out unwilling individuals:');
1104 $filter_unwilling = get_var('filter_unwilling',array('POST'));
1105 $this->t->set_var('filter_unwilling',$filter_unwilling);
1107 if($filter_unwilling == 'y' || $filter_unwilling == '') {
1108 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\" checked>Y";
1109 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\">N";
1110 $filter_input.= " ";
1112 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\">Y";
1113 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\" checked>N";
1114 $filter_input.= " ";
1116 $this->t->set_var('filter_input',$filter_input);
1118 // TODO: changed this so it picks the quorum dynamically
1119 $sql = "SELECT * FROM tc_indiv where steward='Elder' and valid=1";
1120 $this->db->query($sql,__LINE__,__FILE__);
1122 while ($this->db->next_record())
1124 $indiv_name[$i] = $this->db->f('name');
1125 $indiv_id[$i] = $this->db->f('indiv');
1126 $indiv_phone[$indiv_id[$i]] = $this->db->f('phone');
1129 array_multisort($indiv_name, $indiv_id);
1131 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1132 $this->db->query($sql,__LINE__,__FILE__);
1134 while($this->db->next_record())
1136 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1137 $assignment_list[$i]['name'] = $this->db->f('name');
1138 $assignment_list[$i]['code'] = $this->db->f('code');
1142 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
1143 $this->db->query($sql,__LINE__,__FILE__);
1144 $total_records = $this->db->num_rows();
1147 while ($this->db->next_record())
1149 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1150 $activity_list[$i]['date'] = $this->db->f('date');
1151 $activity_list[$i]['activity'] = $this->db->f('activity');
1155 $indiv_width=275; $willing_width=40; $assignment_width=50;
1156 $total_width=$indiv_width+$willing_width;
1158 for ($i=0; $i < count($assignment_list); $i++) {
1159 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1160 $this->t->set_var('assignment_code',$assignment_list[$i]['code']);
1161 $this->t->fp('list1','header_list',True);
1162 $total_width += $assignment_width;
1163 $total_willing[$i] = 0;
1166 for ($i=0; $i < count($indiv_id); $i++) {
1167 $willing_table = ''; $indiv_willing=0;
1168 $this->t->set_var('indiv_name',$indiv_name[$i]);
1169 $this->t->set_var('indiv_phone',$indiv_phone[$indiv_id[$i]]);
1170 $this->t->set_var('editurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_update&indiv_id='
1171 . $indiv_id[$i] . '&action=' . 'edit'));
1172 for ($j=0; $j < count($assignment_list); $j++) {
1173 $found_willingness=0;
1174 $sql = "SELECT * FROM tc_willingness where "
1175 . " assignment=" . $assignment_list[$j]['assignment']
1176 . " AND indiv=" . $indiv_id[$i];
1177 $this->db->query($sql,__LINE__,__FILE__);
1178 while($this->db->next_record()) {
1179 $found_willingness=1;
1181 $sql = "SELECT * FROM tc_activity where "
1182 . " assignment=". $assignment_list[$j]['assignment']
1183 . " ORDER by date DESC";
1184 $this->db2->query($sql,__LINE__,__FILE__);
1185 if($this->db2->next_record()) {
1186 $activity = $this->db2->f('activity');
1187 $date = $this->db2->f('date');
1188 $sql = "SELECT * FROM tc_participation where "
1189 . " activity=" . $activity
1190 . " AND indiv=". $indiv_id[$i];
1191 $this->db3->query($sql,__LINE__,__FILE__);
1192 if($this->db3->next_record()) {
1197 if($this->db->f('willing') == 'y') {
1198 $total_willing[$j]++;
1200 $willing_table .= '<td align=center><img src="images/checkmark.gif"><br><font size=-2>'.$date_part.'</font></td></td>';
1202 else if($this->db->f('willing') == 'n') {
1203 $willing_table .= '<td align=center><img src="images/x.gif"></td>';
1207 $willing_table .= "<td> </td>";
1210 if(!$found_willingness) {
1212 $willing_table .= "<td> </td>";
1215 if(($indiv_willing == 1) || ($filter_unwilling == 'n')) {
1216 $this->t->set_var('willing_table',$willing_table);
1217 $this->t->fp('list2','indiv_list',True);
1218 $this->nextmatchs->template_alternate_row_color(&$this->t);
1222 $stat_table = '<td><b>Total Willing to Serve</b></td>';
1223 for ($j=0; $j < count($assignment_list); $j++) {
1224 $stat_table .= "<td align=center><b>".$total_willing[$j]."</b></td>";
1226 $this->t->set_var('stat_table',$stat_table);
1228 $this->t->set_var('total_width',$total_width);
1229 $this->t->set_var('indiv_width',$indiv_width);
1230 $this->t->set_var('willing_width',$willing_width);
1231 $this->t->pfp('out','willing_view_t');
1232 $this->save_sessiondata();
1235 function willing_update()
1237 //print "<font color=red>Willingness Update Under Constrcution</font>";
1238 //$this->willing_view();
1241 $this->t->set_file(array('willing_update_t' => 'willing_update.tpl'));
1242 $this->t->set_block('willing_update_t','assignment_list','list');
1243 $this->t->set_block('willing_update_t','save','savehandle');
1245 $indiv_id = get_var('indiv_id',array('GET','POST'));
1246 $this->t->set_var('indiv_id',$indiv_id);
1247 $action = get_var('action',array('GET','POST'));
1249 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_view'));
1250 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_update&action=save'));
1251 $this->t->set_var('lang_done','Cancel');
1252 $this->t->set_var('title','Willingness Update ');
1254 if($action == 'save')
1256 // Delete all the previous willingness entries for this individual
1257 $this->db->query("DELETE from tc_willingness where indiv=" . $indiv_id ,__LINE__,__FILE__);
1259 // Now, add the assignment willingness that is checked for this individual
1260 $new_data = get_var('willingness',array('POST'));
1261 foreach ($new_data as $data)
1263 $data_array = explode("/",$data);
1264 $assignment = $data_array[0];
1265 $willing = $data_array[1];
1266 //print "indiv_id: $indiv_id assignment: $assignment willing: $willing<br>";
1267 $this->db->query("INSERT INTO tc_willingness (indiv,assignment,willing) "
1268 . "VALUES (" . $indiv_id .",". $assignment .",'". $willing . "')",__LINE__,__FILE__);
1270 $this->willing_view();
1274 $assignment_width=300; $willing_width=25; $table_width=$assignment_width + $willing_width;
1277 // Find out the individual's name
1278 $sql = "SELECT * FROM tc_indiv WHERE indiv=".$indiv_id." AND valid=1";
1279 $this->db->query($sql,__LINE__,__FILE__);
1280 if($this->db->next_record()) {
1281 $indiv_name = $this->db->f('name');
1282 $this->t->set_var('indiv_name',$indiv_name);
1285 // Select all the assignments
1286 $sql = "SELECT * FROM tc_assignment ORDER by name ASC";
1287 $this->db->query($sql,__LINE__,__FILE__);
1289 while ($this->db->next_record())
1291 $assignment = $this->db->f('assignment');
1292 $assignment_name = $this->db->f('name');
1293 $assignment_code = $this->db->f('code');
1295 $this->nextmatchs->template_alternate_row_color(&$this->t);
1296 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$assignment_name</td>";
1298 $header_row="<th width=$comp_width><font size=-2>Assignments</th><th>Willingness</th>";
1299 $sql = "SELECT * FROM tc_willingness WHERE indiv=".$indiv_id." AND assignment=".$assignment;
1300 $this->db2->query($sql,__LINE__,__FILE__);
1301 $value = $assignment;
1303 if($this->db2->next_record()) {
1304 if($this->db2->f('willing') == 'y') {
1305 $table_data .= '<td width=100 align=center>';
1306 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y" checked>Y';
1307 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1308 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/"> ';
1309 $table_data .= '</td>';
1310 } else if($this->db2->f('willing') == 'n') {
1311 $table_data .= '<td width=100 align=center>';
1312 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1313 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n" checked>N';
1314 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/">';
1315 $table_data .= '</td>';
1317 $table_data .= '<td width=100 align=center>';
1318 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1319 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1320 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1321 $table_data .= '</td>';
1325 $table_data .= '<td width=100 align=center>';
1326 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1327 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1328 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1329 $table_data .= '</td>';
1332 $table_data .= "\n";
1333 $table_data .= "</tr>";
1334 $table_data .= "<tr><td colspan=20></td></tr>";
1337 $table_data .= "<tr><td colspan=20><hr></td></tr>";
1339 $this->t->set_var('table_width',$table_width);
1340 $this->t->set_var('header_row',$header_row);
1341 $this->t->set_var('table_data',$table_data);
1342 $this->t->fp('list','assignment_list',True);
1344 $this->t->set_var('lang_reset','Clear Form');
1345 $this->t->set_var('lang_save','Save Changes');
1346 $this->t->set_var('savehandle','');
1348 $this->t->pfp('out','willing_update_t');
1349 $this->t->pfp('addhandle','save');
1351 $this->save_sessiondata();
1355 function ppi_sched()
1357 $this->t->set_file(array('ppi_sched_t' => 'ppi_sched.tpl'));
1358 $this->t->set_block('ppi_sched_t','indiv_list','indivlist');
1359 $this->t->set_block('ppi_sched_t','appt_list','apptlist');
1360 $action = get_var('action',array('GET','POST'));
1362 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1363 $this->t->set_var('lang_reset','Clear Changes');
1365 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
1366 $this->t->set_var('ppi_link_title','Yearly PPIs');
1368 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
1369 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
1371 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched&action=save'));
1372 $this->t->set_var('title','Yearly PPI Scheduler');
1374 $indiv_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $ppi_date_width=20;
1375 $table_width=$indiv_width + $phone_width + $pri_width + $notes_width + $ppi_date_width;
1376 $header_row = "<th width=$indiv_width><font size=-2>individual Name</th>";
1377 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1378 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1379 $header_row.= "<th width=$ppi_date_width><font size=-2>Last PPI</th>";
1380 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1381 $table_data=""; $completed_data=""; $totals_data="";
1385 // Get the EQ President
1386 $sql = "SELECT * FROM tc_presidency where president=1 and valid=1";
1387 $this->db->query($sql,__LINE__,__FILE__);
1388 if($this->db->next_record()) {
1389 $president_name = $this->db->f('name');
1390 $president_name_array = explode(",",$president_name);
1391 $president_last_name = $president_name_array[0];
1392 $president_id = $this->db->f('indiv');
1393 $presidency_id = $this->db->f('presidency');
1394 $interviewer = $this->db->f('indiv');
1395 $district_number = '*';
1396 $district_name = $president_name;
1397 $sql = "SELECT * FROM tc_indiv where indiv='$president_id'";
1398 $this->db2->query($sql,__LINE__,__FILE__);
1399 if($this->db2->next_record()) {
1400 $indiv_id = $this->db2->f('indiv_id');
1402 $sql = "SELECT * FROM tc_indiv where indiv_id='$indiv_id'";
1403 $this->db2->query($sql,__LINE__,__FILE__);
1404 if($this->db2->next_record()) {
1405 $president_address = $this->db2->f('address');
1408 print "<hr><font color=red><h3>-E- Unable to locate President in tc_presidency table</h3></font></hr>";
1412 if($action == 'save')
1414 // Save any changes made to the appointment table
1415 $new_data = get_var('appt_notes',array('POST'));
1416 if($new_data != "") {
1417 foreach ($new_data as $entry)
1419 $indiv = $entry['indiv'];
1420 $appointment = $entry['appointment'];
1421 $location = $entry['location'];
1422 if($location == "") { $location = "$president_last_name"." home ($president_address)"; }
1423 if($indiv == 0) { $location = ""; }
1425 //Only perform a database update if we have made a change to this appointment
1426 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and indiv='$indiv' and location='$location'";
1427 $this->db->query($sql,__LINE__,__FILE__);
1428 if(!$this->db->next_record()) {
1429 // Perform database save actions here
1430 $this->db->query("UPDATE tc_appointment set " .
1431 " indiv='" . $indiv . "'" .
1432 ",location='" . $location . "'" .
1433 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1434 // Email the appointment
1435 $this->email_appt($appointment);
1441 // Save any changes made to the ppi notes table
1442 $new_data = get_var('ppi_notes',array('POST'));
1443 foreach ($new_data as $entry)
1445 $ppi_notes = $entry['notes'];
1446 $indiv_id = $entry['indiv_id'];
1447 $ppi_pri = $entry['pri'];
1449 // Perform database save actions here
1450 $this->db->query("UPDATE tc_indiv set " .
1451 " ppi_notes='" . $ppi_notes . "'" .
1452 ",ppi_pri='" . $ppi_pri . "'" .
1453 " WHERE indiv=" . $indiv_id,__LINE__,__FILE__);
1457 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched');
1458 //Header('Location: ' . $take_me_to_url);
1461 // create the individual id -> individual name mapping
1462 // TODO: changed this so it picks the quorum dynamically
1463 $sql = "SELECT * FROM tc_indiv where valid=1 and steward='Elder' ORDER BY name ASC";
1464 $this->db->query($sql,__LINE__,__FILE__);
1468 while ($this->db->next_record())
1470 $indiv_name[$i] = $this->db->f('name');
1471 $indiv_id[$i] = $this->db->f('indiv');
1474 array_multisort($indiv_name, $indiv_id);
1476 // APPOINTMENT TABLE
1477 $date_width=250; $time_width=100; $indiv_width=200; $location_width=100;
1478 $appt_table_width=$date_width + $time_width + $indiv_width + $location_width;
1479 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1480 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1481 $appt_header_row.= "<th width=$indiv_width><font size=-2>indiv</th>";
1482 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
1483 $appt_table_data = "";
1485 $total_indivs=0; $indivs_with_yearly_ppi=0;
1487 // Display a scheduling table for the EQ President
1488 $table_data=""; $appt_table_data="";
1489 $table_title = "District ".$district_number.": ".$district_name.": All indivs with Yearly PPI Not Completed";
1490 $appt_table_title = "District ".$district_number.": ".$district_name.": Yearly PPI Appointment Slots";
1491 $this->t->set_var('table_title',$table_title);
1492 $this->t->set_var('appt_table_title',$appt_table_title);
1494 // query the database for all the appointments
1495 $sql = "SELECT * FROM tc_appointment where presidency=".$presidency_id." and date>=CURDATE() ORDER BY date ASC, time ASC";
1496 $this->db->query($sql,__LINE__,__FILE__);
1498 while ($this->db->next_record())
1500 $appointment = $this->db->f('appointment');
1501 $indiv = $this->db->f('indiv');
1502 $location = $this->db->f('location');
1503 if(($location == "") && ($indiv > 0)) { $location = "$president_last_name"." home ($president_address)"; }
1505 $date = $this->db->f('date');
1506 $date_array = explode("-",$date);
1507 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1508 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1510 $time = $this->db->f('time');
1511 $time_array = explode(":",$time);
1512 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1514 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1515 $appt_table_data.= "<td align=center>$day_string</td>";
1516 $appt_table_data.= "<td align=center>$time_string</td>";
1518 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][indiv]>';
1519 $appt_table_data.= '<option value=0></option>';
1520 for ($i=0; $i < count($indiv_id); $i++) {
1521 $id = $indiv_id[$i];
1522 $name = $indiv_name[$i];
1523 if($indiv_id[$i] == $indiv) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
1524 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1526 $appt_table_data.='</select></td>';
1528 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
1529 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
1531 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1533 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1534 $this->t->set_var('tr_color',$tr_color);
1537 $this->t->set_var('appt_table_data',$appt_table_data);
1538 $this->t->set_var('appt_header_row',$appt_header_row);
1539 $this->t->set_var('appt_table_width',$appt_table_width);
1541 // PPI SCHEDULING TABLE
1542 // TODO: changed this so it picks the quorum dynamically
1543 $sql = "SELECT * FROM tc_indiv where valid=1 and steward='Elder' ORDER BY ppi_pri ASC, name ASC";
1544 $this->db->query($sql,__LINE__,__FILE__);
1548 while ($this->db->next_record())
1550 $indiv_id[$i] = $this->db->f('indiv');
1551 $indiv_name[$i] = $this->db->f('name');
1552 $indiv_phone[$indiv_id[$i]] = $this->db->f('phone');
1553 $indiv_ppi_pri[$indiv_id[$i]] = $this->db->f('ppi_pri');
1554 $indiv_ppi_notes[$indiv_id[$i]] = $this->db->f('ppi_notes');
1559 $max = count($indiv_id);
1561 for($i=0; $i < $max; $i++) {
1562 $id = $indiv_id[$i];
1563 $name = $indiv_name[$i];
1564 $phone = $indiv_phone[$id];
1565 $ppi_pri = $indiv_ppi_pri[$id];
1566 $ppi_notes = $indiv_ppi_notes[$id];
1568 // If this individual has had a yearly PPI this year, don't show him on the schedule list
1569 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
1570 $sql = "SELECT * FROM tc_interview WHERE date > '$year_start' AND date < '$year_end' ".
1571 "AND indiv=" . $id . " AND interview_type='ppi'";
1572 $this->db2->query($sql,__LINE__,__FILE__);
1574 if(!$this->db2->next_record()) {
1575 $sql = "SELECT * FROM tc_interview WHERE indiv=" . $id . " AND interview_type='ppi' ORDER BY date DESC";
1576 $this->db->query($sql,__LINE__,__FILE__);
1577 if($this->db->next_record()) { $date = $this->db->f('date'); } else { $date = ""; }
1578 $link_data['menuaction'] = 'tc.tc.ppi_update';
1579 $link_data['indiv'] = $id;
1580 $link_data['name'] = $name;
1581 $link_data['interview'] = '';
1582 $link_data['interview_type'] = 1;
1583 $link_data['action'] = 'add';
1584 $link_data['interviewer'] = $interviewer;
1585 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1586 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1587 $this->t->set_var('tr_color',$tr_color);
1588 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1589 $table_data.= "<td align=center>$phone</td>";
1590 //$table_data.= "<td align=center>$ppi_pri</td>";
1591 $table_data.= "<td align=center>";
1592 $table_data.= '<select name=ppi_notes['.$i.'][pri]>';
1593 foreach(range(0,6) as $num) {
1594 if($num == 0) { $num = 1; } else {$num = $num*5; }
1595 if($ppi_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
1596 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1598 $table_data.= '</select></td>';
1599 $table_data.= "<td align=center>$date</td>";
1600 $table_data.= '<td><input type=text size="50" maxlength="128" name="ppi_notes['.$i.'][notes]" value="'.$ppi_notes.'">';
1601 $table_data.= '<input type=hidden name="ppi_notes['.$i.'][indiv_id]" value="'.$id.'">';
1602 $table_data.= '<input type=hidden name="ppi_notes['.$i.'][indiv_name]" value="'.$name.'">';
1603 $table_data.= '</td>';
1604 $table_data.= '</tr>';
1606 $link_data['menuaction'] = 'tc.tc.ppi_update';
1607 $link_data['interviewer'] = $this->db2->f('interviewer');
1608 $link_data['indiv'] = $this->db2->f('indiv');
1609 $link_data['name'] = $name;
1610 $link_data['interview'] = $this->db2->f('interview');
1611 $link_data['interview_type'] = $this->db2->f('interview_type');
1612 $link_data['action'] = 'view';
1613 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1614 $indivs_with_yearly_ppi++;
1615 $date = $this->db2->f('date');
1616 $ppi_notes = $this->db2->f('notes');
1617 if(strlen($ppi_notes) > 40) { $ppi_notes = substr($ppi_notes,0,40) . "..."; }
1618 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1619 $this->t->set_var('tr_color2',$tr_color2);
1620 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1621 $completed_data.= "<td align=center>$phone</td>";
1622 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1623 $completed_data.= "<td align=left>$ppi_notes</td>";
1624 $completed_data.= '</tr>';
1626 } // End for individuals Loop
1628 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1629 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1630 $completed_header_row = "<th width=$name_width><font size=-2>Individual Name</th>";
1631 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1632 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1633 $completed_header_row.= "<th width=$notes_width><font size=-2>PPI Notes</th>";
1635 $this->t->set_var('table_width',$table_width);
1636 $this->t->set_var('header_row',$header_row);
1637 $this->t->set_var('table_data',$table_data);
1638 $this->t->set_var('completed_header_row',$completed_header_row);
1639 $this->t->set_var('completed_table_width',$completed_table_width);
1640 $this->t->set_var('completed',$completed_data);
1641 $this->t->fp('indivlist','indiv_list',True);
1643 $indivs_width=300; $totals_width=100;
1644 $totals_table_width=$indivs_width + $totals_width;
1645 $totals_header_row = "<th width=$indivs_width><font size=-2>Individuals</th>";
1646 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
1647 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1648 $totals_data.= "<td align=left><font size=-2><b>Total Individuals with yearly PPIs completed:</b></font></td>";
1649 $totals_data.= "<td align=center><font size=-2><b>$indivs_with_yearly_ppi / $total_indivs</b></font></td>";
1650 $percent = ceil(($indivs_with_yearly_ppi / $total_indivs)*100);
1651 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1652 $this->t->set_var('tr_color',$tr_color);
1653 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1654 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
1655 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
1656 $totals_data.= "</tr>";
1658 $this->t->set_var('totals',$totals_data);
1659 $this->t->set_var('totals_header_row',$totals_header_row);
1660 $this->t->set_var('totals_table_width',$totals_table_width);
1662 $this->t->pfp('out','ppi_sched_t');
1663 $this->save_sessiondata();
1667 function int_sched()
1669 $this->t->set_file(array('int_sched_t' => 'int_sched.tpl'));
1670 $this->t->set_block('int_sched_t','indiv_list','indivlist');
1671 $this->t->set_block('int_sched_t','appt_list','apptlist');
1672 $action = get_var('action',array('GET','POST'));
1674 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1675 $this->t->set_var('lang_reset','Clear Changes');
1677 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
1678 $this->t->set_var('int_link_title','Hometeaching Interviews');
1680 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
1681 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
1683 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched&action=save'));
1684 $this->t->set_var('title','Hometeaching Interviews Scheduler');
1686 $indiv_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $int_date_width=20;
1687 $table_width=$indiv_width + $phone_width + $pri_width + $notes_width + $int_date_width;
1688 $header_row = "<th width=$indiv_width><font size=-2>individual Name</th>";
1689 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1690 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1691 $header_row.= "<th width=$int_date_width><font size=-2>Last Interview</th>";
1692 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1693 $table_data=""; $completed_data=""; $totals_data="";
1697 $nextyear = $year + 1;
1698 if($month >= 1 && $month <= 3) { $quarter_start=$year."-01-01"; $quarter_end=$year."-04-01"; }
1699 if($month >= 4 && $month <= 6) { $quarter_start=$year."-04-01"; $quarter_end=$year."-07-01"; }
1700 if($month >= 7 && $month <= 9) { $quarter_start=$year."-07-01"; $quarter_end=$year."-10-01"; }
1701 if($month >= 10 && $month <= 12) { $quarter_start=$year."-10-01"; $quarter_end=$nextyear."-01-01"; }
1702 //print "year: $year month: $month quarter_start: $quarter_start quarter_end: $quarter_end<br>";
1704 // create the individual id -> individual name mapping
1705 // TODO: changed this so it picks the quorum dynamically
1706 $sql = "SELECT * FROM tc_indiv where steward='Elder' and valid=1 ORDER BY name ASC";
1707 $this->db->query($sql,__LINE__,__FILE__);
1709 $indiv_id_data = NULL;
1710 $indiv_name_data = NULL;
1711 while ($this->db->next_record())
1713 $indiv_name_data[$i] = $this->db->f('name');
1714 $indiv_id_data[$i] = $this->db->f('indiv');
1715 $individ2name[$indiv_id_data[$i]] = $indiv_name_data[$i];
1718 // add any YM that are home teachers
1719 $sql = "SELECT * FROM tc_companionship where valid=1";
1720 $this->db->query($sql,__LINE__,__FILE__);
1721 while ($this->db->next_record())
1723 $tmp_indiv_id = $this->db->f('indiv');
1724 $sql = "Select * FROM tc_indiv where indiv='$tmp_indiv_id' and steward='' and valid=1";
1725 $this->db2->query($sql,__LINE__,__FILE__);
1726 while ($this->db2->next_record()) {
1727 $indiv_name_data[$i] = $this->db2->f('name');
1728 $indiv_id_data[$i] = $this->db2->f('indiv');
1729 $individ2name[$indiv_id_data[$i]] = $indiv_name_data[$i];
1733 array_multisort($indiv_name_data, $indiv_id_data);
1735 if($action == 'save')
1737 // Save any changes made to the appointment table
1738 $new_data = get_var('appt_notes',array('POST'));
1739 if($new_data != "") {
1740 foreach ($new_data as $entry)
1742 $indiv = $entry['indiv'];
1743 $appointment = $entry['appointment'];
1744 $location = $entry['location'];
1745 if($location == "") {
1746 $supervisor = $entry['supervisor'];
1747 $supervisor_array = explode(",", $individ2name[$supervisor]);
1748 $supervisor_last_name = $supervisor_array[0];
1749 $sql = "SELECT * FROM tc_indiv where indiv='$supervisor'";
1750 $this->db2->query($sql,__LINE__,__FILE__);
1751 if($this->db2->next_record()) {
1752 $indiv_id = $this->db2->f('indiv_id');
1754 $sql = "SELECT * FROM tc_indiv where indiv_id='$indiv_id'";
1755 $this->db2->query($sql,__LINE__,__FILE__);
1756 if($this->db2->next_record()) {
1757 $supervisor_address = $this->db2->f('address');
1759 $location = "$supervisor_last_name"." home ($supervisor_address)";
1761 if($indiv == 0) { $location = ""; }
1763 //print "indiv: $indiv appointment: $appointment <br>";
1764 //Only perform a database update if we have made a change to this appointment
1765 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and indiv='$indiv' and location='$location'";
1766 $this->db->query($sql,__LINE__,__FILE__);
1767 if(!$this->db->next_record()) {
1768 // Perform database save actions here
1769 $this->db->query("UPDATE tc_appointment set " .
1770 " indiv='" . $indiv . "'" .
1771 ",location='" . $location . "'" .
1772 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1774 // Email the appointment
1775 $this->email_appt($appointment);
1780 // Save any changes made to the int notes table
1781 $new_data = get_var('int_notes',array('POST'));
1782 foreach ($new_data as $entry)
1784 $int_notes = $entry['notes'];
1785 $indiv_id = $entry['indiv_id'];
1786 $indiv_name = $entry['indiv_name'];
1787 $int_pri = $entry['pri'];
1788 //print "int_notes: $int_notes indiv_name: $indiv_name <Br>";
1789 // Perform database save actions here
1790 $this->db->query("UPDATE tc_indiv set " .
1791 " int_notes='" . $int_notes . "'" .
1792 ",int_pri='" . $int_pri . "'" .
1793 " WHERE indiv=" . $indiv_id,__LINE__,__FILE__);
1797 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched');
1798 //Header('Location: ' . $take_me_to_url);
1801 // Get the Districts
1802 $sql = "SELECT * FROM tc_district where valid=1 ORDER BY district ASC";
1803 $this->db->query($sql,__LINE__,__FILE__);
1805 while ($this->db->next_record())
1807 $district = $this->db->f('district');
1808 $districts[$i]['district'] = $this->db->f('district');
1809 $districts[$i]['name'] = $this->db->f('name');
1810 $districts[$i]['supervisor'] = $this->db->f('supervisor');
1811 $sql = "SELECT * FROM tc_presidency where district=$district and valid=1";
1812 $this->db2->query($sql,__LINE__,__FILE__);
1813 if($this->db2->next_record()) {
1814 $districts[$i]['presidency'] = $this->db2->f('presidency');
1819 // APPOINTMENT TABLE
1821 $date_width=250; $time_width=100; $indiv_width=200; $location_width=100;
1822 $appt_table_width=$date_width + $time_width + $indiv_width + $location_width;
1823 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1824 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1825 $appt_header_row.= "<th width=$indiv_width><font size=-2>Individual</th>";
1826 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
1827 $appt_table_data = "";
1829 $total_comps=0; $comps_with_quarterly_int=0;
1831 // Display a scheduling table for each district
1832 for ($d=0; $d < count($districts); $d++) {
1833 $table_data=""; $appt_table_data="";
1834 $this->t->set_var('district_number',$districts[$d]['district']);
1835 $this->t->set_var('district_name',$districts[$d]['name']);
1836 $supervisor = $districts[$d]['supervisor'];
1837 $supervisor_array = explode(",", $supervisor);
1838 $supervisor_last_name = $supervisor_array[0];
1839 $sql = "SELECT * FROM tc_indiv where indiv='$supervisor'";
1840 $this->db2->query($sql,__LINE__,__FILE__);
1841 if($this->db2->next_record()) {
1842 $indiv_id = $this->db2->f('indiv_id');
1844 $sql = "SELECT * FROM tc_indiv where indiv_id='$indiv_id'";
1845 $this->db2->query($sql,__LINE__,__FILE__);
1846 if($this->db2->next_record()) {
1847 $supervisor_address = $this->db2->f('address');
1849 $location = "$supervisor_last_name"." home ($supervisor_address)";
1850 $table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": All Individuals with Interviews Not Completed";
1851 $appt_table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": Interview Appointment Slots";
1852 $this->t->set_var('table_title',$table_title);
1853 $this->t->set_var('appt_table_title',$appt_table_title);
1855 // query the database for all the appointments
1856 $sql = "SELECT * FROM tc_appointment where presidency=".$districts[$d]['presidency']." and date>=CURDATE() ORDER BY date ASC, time ASC";
1857 $this->db->query($sql,__LINE__,__FILE__);
1859 while ($this->db->next_record())
1861 $appointment = $this->db->f('appointment');
1862 $indiv = $this->db->f('indiv');
1863 $location = $this->db->f('location');
1864 if(($location == "") && ($indiv > 0)) { $location = "$supervisor_last_name"." home ($supervisor_address)"; }
1866 $date = $this->db->f('date');
1867 $date_array = explode("-",$date);
1868 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1869 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1871 $time = $this->db->f('time');
1872 $time_array = explode(":",$time);
1873 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1875 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1876 $appt_table_data.= "<td align=center>$day_string</td>";
1877 $appt_table_data.= "<td align=center>$time_string</td>";
1879 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][indiv]>';
1880 $appt_table_data.= '<option value=0></option>';
1881 for ($i=0; $i < count($indiv_id_data); $i++) {
1882 $id = $indiv_id_data[$i];
1883 $name = $indiv_name_data[$i];
1884 if($indiv_id_data[$i] == $indiv) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
1885 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1887 $appt_table_data.='</select></td>';
1889 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
1890 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
1892 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1893 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][supervisor]" value="'.$supervisor.'">';
1895 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1896 $this->t->set_var('tr_color',$tr_color);
1899 $this->t->set_var('appt_table_data',$appt_table_data);
1900 $this->t->set_var('appt_header_row',$appt_header_row);
1901 $this->t->set_var('appt_table_width',$appt_table_width);
1903 // INTERVIEW SCHEDULING TABLE
1905 // Select all the unique companionship numbers for this district
1906 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$d]['district'];
1907 $this->db->query($sql,__LINE__,__FILE__);
1908 $j=0; $unique_companionships = '';
1909 while ($this->db->next_record())
1911 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
1916 for ($j=0; $j < count($unique_companionships); $j++) {
1917 // Select all the companions from each companionship
1918 $sql = "SELECT * FROM tc_companionship where valid=1 and companionship=". $unique_companionships[$j]['companionship'];
1919 $this->db->query($sql,__LINE__,__FILE__);
1920 $k=0; $int_completed=0;
1921 $comp = $unique_companionships[$j]['companionship'];
1922 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1923 $this->t->set_var('tr_color',$tr_color);
1925 while ($this->db->next_record())
1927 // Get this companions information
1928 $indiv_id = $this->db->f('indiv');
1930 $sql = "SELECT * FROM tc_indiv where indiv='$indiv_id'";
1931 $this->db2->query($sql,__LINE__,__FILE__);
1932 if($this->db2->next_record())
1934 $indiv_id = $this->db2->f('indiv');
1935 $indiv_name = $this->db2->f('name');
1936 $indiv_phone[$indiv_id] = $this->db2->f('phone');
1937 $indiv_int_pri[$indiv_id] = $this->db2->f('int_pri');
1938 $indiv_int_notes[$indiv_id] = $this->db2->f('int_notes');
1941 $name = $indiv_name;
1942 $phone = $indiv_phone[$id];
1943 $int_pri = $indiv_int_pri[$id];
1944 $int_notes = $indiv_int_notes[$id];
1946 // If the companionship has already had its quarterly interview,
1947 // Skip the other companion in the companionship.
1948 if($int_completed == 1) {
1949 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1950 $completed_data.= "<td align=center>$phone</td>";
1951 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1952 $completed_data.= "<td align=left>$int_notes</td>";
1953 $completed_data.= '</tr>';
1954 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1955 $this->t->set_var('tr_color2',$tr_color2);
1956 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1957 $this->t->set_var('tr_color',$tr_color);
1961 // If this companionship has had a hometeaching interview this quarter, don't show them on the schedule list
1962 $sql = "SELECT * FROM tc_interview WHERE date >= '$quarter_start' AND date < '$quarter_end' AND indiv='$id'";
1963 $this->db2->query($sql,__LINE__,__FILE__);
1965 if(!$this->db2->next_record()) {
1966 $sql = "SELECT * FROM tc_interview WHERE indiv='$id' ORDER BY date DESC";
1967 $this->db3->query($sql,__LINE__,__FILE__);
1968 if($this->db3->next_record()) { $date = $this->db3->f('date'); } else { $date = ""; }
1969 $link_data['menuaction'] = 'tc.tc.int_update';
1970 $link_data['indiv'] = $id;
1971 $link_data['name'] = $name;
1972 $link_data['interview'] = '';
1973 $link_data['action'] = 'add';
1974 $link_data['interviewer'] = $districts[$d]['supervisor'];
1975 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1976 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1977 $table_data.= "<td align=center>$phone</td>";
1978 $table_data.= "<td align=center>";
1979 $table_data.= '<select name=int_notes['.$i.'][pri]>';
1980 foreach(range(0,6) as $num) {
1981 if($num == 0) { $num = 1; } else {$num = $num*5; }
1982 if($int_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
1983 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1985 $table_data.= '</select></td>';
1986 $table_data.= "<td align=center>$date</td>";
1987 $table_data.= '<td><input type=text size="50" maxlength="128" name="int_notes['.$i.'][notes]" value="'.$int_notes.'">';
1988 $table_data.= '<input type=hidden name="int_notes['.$i.'][indiv_id]" value="'.$id.'">';
1989 $table_data.= '<input type=hidden name="int_notes['.$i.'][indiv_name]" value="'.$name.'">';
1990 $table_data.= '</td>';
1991 $table_data.= '</tr>'."\n";
1994 $link_data['menuaction'] = 'tc.tc.int_update';
1995 $link_data['interviewer'] = $this->db2->f('interviewer');
1996 $link_data['indiv'] = $this->db2->f('indiv');
1997 $link_data['name'] = $name;
1998 $link_data['interview'] = $this->db2->f('interview');
1999 $link_data['action'] = 'view';
2000 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2001 $comps_with_quarterly_int++;
2003 $date = $this->db2->f('date');
2004 $int_notes = $this->db2->f('notes');
2005 if(strlen($int_notes) > 40) { $int_notes = substr($int_notes,0,40) . "..."; }
2006 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2007 $completed_data.= "<td align=center>$phone</td>";
2008 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2009 $completed_data.= "<td align=left>$int_notes</td>";
2010 $completed_data.= '</tr>';
2015 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
2016 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
2017 $completed_header_row = "<th width=$name_width><font size=-2>Individual Name</th>";
2018 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2019 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
2020 $completed_header_row.= "<th width=$notes_width><font size=-2>Interview Notes</th>";
2022 $this->t->set_var('table_width',$table_width);
2023 $this->t->set_var('header_row',$header_row);
2024 $this->t->set_var('table_data',$table_data);
2025 $this->t->set_var('completed_header_row',$completed_header_row);
2026 $this->t->set_var('completed_table_width',$completed_table_width);
2027 $this->t->set_var('completed',$completed_data);
2028 $this->t->fp('indivlist','indiv_list',True);
2030 } // End for each district loop
2033 $indivs_width=300; $totals_width=100;
2034 $totals_table_width=$indivs_width + $totals_width;
2035 $totals_header_row = "<th width=$indivs_width><font size=-2>Individuals</th>";
2036 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2037 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2038 $totals_data.= "<td align=left><font size=-2><b>Total Companionships with interviews completed:</b></font></td>";
2039 $totals_data.= "<td align=center><font size=-2><b>$comps_with_quarterly_int / $total_comps</b></font></td>";
2040 $percent = ceil(($comps_with_quarterly_int / $total_comps)*100);
2041 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2042 $this->t->set_var('tr_color',$tr_color);
2043 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2044 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2045 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2046 $totals_data.= "</tr>";
2048 $this->t->set_var('totals',$totals_data);
2049 $this->t->set_var('totals_header_row',$totals_header_row);
2050 $this->t->set_var('totals_table_width',$totals_table_width);
2052 $this->t->pfp('out','int_sched_t');
2053 $this->save_sessiondata();
2057 function vis_sched()
2059 $this->t->set_file(array('vis_sched_t' => 'vis_sched.tpl'));
2060 $this->t->set_block('vis_sched_t','family_list','familylist');
2061 $this->t->set_block('vis_sched_t','appt_list','apptlist');
2062 $action = get_var('action',array('GET','POST'));
2064 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
2065 $this->t->set_var('lang_reset','Clear Changes');
2067 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2068 $this->t->set_var('vis_link_title','View Yearly Visits');
2070 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
2071 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2073 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched&action=save'));
2074 $this->t->set_var('title','Presidency Yearly Visit Scheduler');
2076 $family_width=500; $phone_width=40; $pri_width=10; $notes_width=128; $visit_date_width=20;
2077 $table_width=$family_width + $phone_width + $pri_width + $notes_width + $visit_date_width;
2078 $header_row = "<th width=$family_width><font size=-2>Family Name</th>";
2079 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2080 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
2081 $header_row.= "<th width=$visit_date_width><font size=-2>Last Visit</th>";
2082 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
2083 $table_data=""; $completed_data=""; $totals_data="";
2087 // create the family id -> family name mapping
2088 $sql = "SELECT * FROM tc_family where valid=1 and indiv_id != 0 and companionship != 0 ORDER BY name ASC";
2089 $this->db->query($sql,__LINE__,__FILE__);
2092 while ($this->db->next_record())
2094 $family_id[$i] = $this->db->f('family');
2095 $family_name[$i] = $this->db->f('name');
2096 $familyid2name[$family_id[$i]] = $family_name[$i];
2097 $sql = "SELECT * FROM tc_indiv where family='$family_id[$i]'";
2098 $this->db2->query($sql,__LINE__,__FILE__);
2099 if($this->db2->next_record()) {
2100 $familyid2address[$family_id[$i]] = $this->db2->f('address');
2104 array_multisort($family_name, $family_id);
2106 if($action == 'save')
2108 // Save any changes made to the appointment table
2109 $new_data = get_var('appt_notes',array('POST'));
2110 if($new_data != "") {
2111 foreach ($new_data as $entry)
2113 $family = $entry['family'];
2114 $appointment = $entry['appointment'];
2115 $location = $entry['location'];
2116 if($location == "") {
2117 $family_name_array = explode(",", $familyid2name[$family]);
2118 $family_last_name = $family_name_array[0];
2119 $family_address = $familyid2address[$family];
2120 $location = "$family_last_name"." home ($family_address)";
2122 if($family == 0) { $location = ""; }
2124 //Only perform a database update if we have made a change to this appointment
2125 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and family='$family' and location='$location'";
2126 $this->db->query($sql,__LINE__,__FILE__);
2127 if(!$this->db->next_record()) {
2128 // Perform database save actions here
2129 $this->db->query("UPDATE tc_appointment set " .
2130 " family='" . $family . "'" .
2131 ",location='" . $location . "'" .
2132 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
2134 // Email the appointment
2135 $this->email_appt($appointment);
2140 // Save any changes made to the visit notes table
2141 $new_data = get_var('vis_notes',array('POST'));
2142 foreach ($new_data as $entry)
2144 $visit_notes = $entry['notes'];
2145 $family = $entry['family_id'];
2146 $visit_pri = $entry['pri'];
2148 // Perform database save actions here
2149 $this->db->query("UPDATE tc_family set " .
2150 " visit_notes='" . $visit_notes . "'" .
2151 ",visit_pri='" . $visit_pri . "'" .
2152 " WHERE family=" . $family,__LINE__,__FILE__);
2156 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched');
2157 //Header('Location: ' . $take_me_to_url);
2160 // APPOINTMENT TABLE
2161 $date_width=250; $time_width=100; $family_width=250; $location_width=100;
2162 $appt_table_width=$date_width + $time_width + $family_width + $location_width;
2163 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
2164 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
2165 $appt_header_row.= "<th width=$family_width><font size=-2>Family</th>";
2166 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
2167 $appt_table_data = "";
2169 // Find out what the EQ Presidency ID is
2170 $sql = "SELECT * FROM tc_presidency where eqpres=1 and valid=1";
2171 $this->db->query($sql,__LINE__,__FILE__);
2172 if($this->db->next_record()) {
2173 $presidency_name = $this->db->f('name');
2174 $presidency_id = $this->db->f('presidency');
2176 print "<hr><font color=red><h3>-E- Unable to locate Presidency in tc_presidency table</h3></font></hr>";
2180 // query the database for all the appointments
2181 $sql = "SELECT * FROM tc_appointment where presidency=$presidency_id and date>=CURDATE() ORDER BY date ASC, time ASC";
2182 $this->db->query($sql,__LINE__,__FILE__);
2184 while ($this->db->next_record())
2186 $appointment = $this->db->f('appointment');
2187 $family = $this->db->f('family');
2188 $location = $this->db->f('location');
2189 $family_name_array = explode(",", $familyid2name[$family]);
2190 $family_last_name = $family_name_array[0];
2191 $family_address = $familyid2address[$family];
2192 if(($location == "") && ($family > 0)) { $location = "$family_last_name"." home ($family_address)"; }
2194 $date = $this->db->f('date');
2195 $date_array = explode("-",$date);
2196 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
2197 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
2199 $time = $this->db->f('time');
2200 $time_array = explode(":",$time);
2201 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
2203 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2204 $appt_table_data.= "<td align=center>$day_string</td>";
2205 $appt_table_data.= "<td align=center>$time_string</td>";
2207 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][family]>';
2208 $appt_table_data.= '<option value=0></option>';
2209 for ($i=0; $i < count($family_id); $i++) {
2210 $id = $family_id[$i];
2211 $name = $family_name[$i];
2212 if($family_id[$i] == $family) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
2213 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
2215 $appt_table_data.='</select></td>';
2217 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
2218 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
2220 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
2222 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2223 $this->t->set_var('tr_color',$tr_color);
2226 $this->t->set_var('appt_table_data',$appt_table_data);
2227 $this->t->set_var('appt_header_row',$appt_header_row);
2228 $this->t->set_var('appt_table_width',$appt_table_width);
2231 // VISIT SCHEDULING TABLE
2232 $sql = "SELECT * FROM tc_family where valid=1 and indiv_id != 0 and companionship != 0 ORDER BY visit_pri ASC, name ASC";
2233 $this->db->query($sql,__LINE__,__FILE__);
2235 $total_families=0; $families_with_yearly_visit=0;
2239 $family_name = NULL;
2240 $family_phone = NULL;
2241 $family_visit_pri = NULL;
2242 $family_visit_notes = NULL;
2243 while ($this->db->next_record())
2245 $family_id[$i] = $this->db->f('family');
2246 $family_name[$i] = $this->db->f('name');
2247 $family_phone[$family_id[$i]] = $family_id[$i] . " ERROR";
2248 $family_visit_pri[$family_id[$i]] = $this->db->f('visit_pri');
2249 $family_visit_notes[$family_id[$i]] = $this->db->f('visit_notes');
2254 $sql = "SELECT * FROM tc_indiv where valid=1";
2255 $this->db->query($sql,__LINE__,__FILE__);
2256 while ($this->db->next_record())
2258 $family = $this->db->f('family');
2259 $phone = $this->db->f('phone');
2260 $family_phone[$family] = $phone;
2263 $max = count($family_id);
2265 for($i=0; $i < $max; $i++) {
2266 $id = $family_id[$i];
2267 $name = $family_name[$i];
2268 $phone = $family_phone[$id];
2269 $vis_pri = $family_visit_pri[$id];
2270 $vis_notes = $family_visit_notes[$id];
2272 // If this family has had a yearly visit this year, don't show them on the schedule list
2273 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2274 $sql = "SELECT * FROM tc_visit WHERE date > '$year_start' AND date < '$year_end' ".
2275 "AND family=" . $id . " AND companionship=0";
2276 $this->db2->query($sql,__LINE__,__FILE__);
2278 if(!$this->db2->next_record()) {
2279 $sql = "SELECT * FROM tc_visit WHERE family=" . $id . " AND companionship=0 ORDER BY date DESC";
2280 $this->db->query($sql,__LINE__,__FILE__);
2281 if($this->db->next_record()) { $date = $this->db->f('date'); } else { $date = ""; }
2282 $link_data['menuaction'] = 'tc.tc.vis_update';
2283 $link_data['visit'] = '';
2284 $link_data['family'] = $id;
2285 $link_data['name'] = $name;
2286 $link_data['action'] = 'add';
2287 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2288 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2289 $table_data.= "<td align=center>$phone</td>";
2290 $table_data.= "<td align=center>";
2291 $table_data.= '<select name=vis_notes['.$i.'][pri]>';
2292 foreach(range(0,6) as $num) {
2293 if($num == 0) { $num = 1; } else {$num = $num*5; }
2294 if($vis_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
2295 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2297 $table_data.= '</select></td>';
2298 $table_data.= "<td align=center>$date</td>";
2299 $table_data.= '<td><input type=text size="50" maxlength="128" name="vis_notes['.$i.'][notes]" value="'.$vis_notes.'">';
2300 $table_data.= '<input type=hidden name="vis_notes['.$i.'][family_id]" value="'.$id.'">';
2301 $table_data.= '<input type=hidden name="vis_notes['.$i.'][family_name]" value="'.$name.'">';
2302 $table_data.= '</td>';
2303 $table_data.= '</tr>';
2304 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2305 $this->t->set_var('tr_color',$tr_color);
2307 $link_data['menuaction'] = 'tc.tc.vis_update';
2308 $link_data['visit'] = $this->db2->f('visit');
2309 $link_data['family'] = $this->db2->f('family');
2310 $link_data['name'] = $name;
2311 $link_data['date'] = $this->db2->f('date');
2312 $link_data['action'] = 'view';
2313 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2314 $families_with_yearly_visit++;
2315 $date = $this->db2->f('date');
2316 $vis_notes = $this->db2->f('notes');
2317 if(strlen($vis_notes) > 40) { $vis_notes = stripslashes(substr($vis_notes,0,40) . "..."); }
2318 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2319 $completed_data.= "<td align=center>$phone</td>";
2320 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2321 $completed_data.= "<td align=left>$vis_notes</td>";
2322 $completed_data.= '</tr>';
2323 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
2324 $this->t->set_var('tr_color2',$tr_color2);
2328 $name_width=190; $phone_width=100; $date_width=100; $notes_width=300;
2329 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
2330 $completed_header_row = "<th width=$name_width><font size=-2>Family Name</th>";
2331 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2332 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
2333 $completed_header_row.= "<th width=$notes_width><font size=-2>Visit Notes</th>";
2335 $family_width=300; $totals_width=100;
2336 $totals_table_width=$family_width + $totals_width;
2337 $totals_header_row = "<th width=$family_width><font size=-2>Families</th>";
2338 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2339 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2340 $totals_data.= "<td align=left><font size=-2><b>Total Families with yearly Visits completed:</b></font></td>";
2341 $totals_data.= "<td align=center><font size=-2><b>$families_with_yearly_visit / $total_families</b></font></td>";
2342 $percent = ceil(($families_with_yearly_visit / $total_families)*100);
2343 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2344 $this->t->set_var('tr_color',$tr_color);
2345 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2346 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2347 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2348 $totals_data.= "</tr>";
2350 $this->t->set_var('table_width',$table_width);
2351 $this->t->set_var('header_row',$header_row);
2352 $this->t->set_var('table_data',$table_data);
2353 $this->t->set_var('totals_header_row',$totals_header_row);
2354 $this->t->set_var('totals_table_width',$totals_table_width);
2355 $this->t->set_var('completed_header_row',$completed_header_row);
2356 $this->t->set_var('completed_table_width',$completed_table_width);
2357 $this->t->set_var('completed',$completed_data);
2358 $this->t->set_var('totals',$totals_data);
2359 $this->t->fp('familylist','family_list',True);
2360 $this->t->fp('apptlist','appt_list',True);
2362 $this->t->pfp('out','vis_sched_t');
2363 $this->save_sessiondata();
2369 $this->t->set_file(array('ppi_view_t' => 'ppi_view.tpl'));
2370 $this->t->set_block('ppi_view_t','district_list','list');
2372 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2373 $num_months = get_var('num_months',array('GET','POST'));
2374 if($num_months == '') { $num_months = $this->default_ppi_num_months; }
2375 $this->t->set_var('num_months',$num_months);
2376 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
2377 else { $this->t->set_var('lang_num_months','Months of History'); }
2378 $this->t->set_var('lang_filter','Filter');
2379 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2381 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2382 $this->t->set_var('ppi_link_title','Yearly PPIs');
2384 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
2385 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
2387 $this->t->set_var('title','Yearly PPIs');
2388 $num_months = get_var('num_months',array('GET','POST'));
2389 if($num_months == '') { $num_months = $this->default_ppi_num_years; }
2390 $this->t->set_var('num_months',$num_months);
2391 if($num_months == 1) { $this->t->set_var('lang_num_months','Year of History'); }
2392 else { $this->t->set_var('lang_num_months','Years of History'); }
2394 $sql = "SELECT * FROM tc_presidency where president=1 and valid=1";
2395 $this->db->query($sql,__LINE__,__FILE__);
2396 if($this->db->next_record()) {
2397 $president_name = $this->db->f('name');
2398 $interviewer = $this->db->f('indiv');
2399 $interview_type = 'ppi';
2401 print "<hr><font color=red><h3>-E- Unable to locate President in tc_presidency table</h3></font></hr>";
2404 $this->t->set_var('district_number','*');
2405 $this->t->set_var('district_name',$president_name);
2407 // TODO: changed this so it picks the quorum dynamically
2408 $sql = "SELECT * FROM tc_indiv where steward='Elder' and valid=1 ORDER BY indiv ASC";
2409 $this->db->query($sql,__LINE__,__FILE__);
2411 while ($this->db->next_record())
2413 $indiv_id[$i] = $this->db->f('indiv');
2414 $indiv_name[$i] = $this->db->f('name');
2415 $indiv_phone[$indiv_id[$i]] = $this->db->f('phone');
2416 $indiv_ppi_pri[$indiv_id[$i]] = $this->db->f('ppi_pri');
2417 $indiv_ppi_notes[$indiv_id[$i]] = $this->db->f('ppi_notes');
2421 array_multisort($indiv_name, $indiv_id);
2422 //var_dump($indiv_name); print "<br><br>"; var_dump($indiv_id);
2424 $header_row="<th width=$comp_width><font size=-2>Individual Name</th>";
2426 $indiv_width=400; $ppi_width=75; $table_width=$indiv_width + $num_months*$ppi_width;
2428 for($m=$num_months; $m >= 0; $m--) {
2429 $year = date('Y') - $m;
2430 $header_row .= "<th width=150><font size=-2>$year</th>";
2434 for ($j=0; $j < count($indiv_id); $j++) {
2435 $id = $indiv_id[$j];
2436 $name = $indiv_name[$j];
2437 $phone = $indiv_phone[$id];
2439 $link_data['menuaction'] = 'tc.tc.ppi_update';
2440 $link_data['interviewer'] = $interviewer;
2441 $link_data['indiv'] = $id;
2442 $link_data['name'] = $name;
2443 $link_data['interview'] = '';
2444 $link_data['interview_type'] = $interview_type;
2445 $link_data['action'] = 'add';
2446 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2447 $this->nextmatchs->template_alternate_row_color(&$this->t);
2448 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2450 // Find out how many times PPIs were performed in the past $num_months for this individual
2451 for($m=$num_months; $m >= 0; $m--) {
2452 $year = date('Y') - $m;
2453 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2454 $sql = "SELECT * FROM tc_interview WHERE date > '$year_start' AND date < '$year_end' ".
2455 "AND indiv=" . $id . " AND interview_type='ppi'";
2456 $this->db2->query($sql,__LINE__,__FILE__);
2458 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
2459 if($this->db2->next_record()) {
2460 $ppis[$m]++; $total_ppis[$m]++; $ppi_recorded[$companionship][$m]=1;
2461 $link_data['menuaction'] = 'tc.tc.ppi_update';
2462 $link_data['companionship'] = $companionship;
2463 $link_data['interviewer'] = $this->db2->f('interviewer');
2464 $link_data['indiv'] = $id;
2465 $link_data['name'] = $name;
2466 $link_data['interview'] = $this->db2->f('interview');
2467 $link_data['interview_type'] = $interview_type;
2468 $link_data['action'] = 'view';
2469 $date = $this->db2->f('date');
2470 $date_array = explode("-",$date);
2471 $month = $date_array[1];
2472 $day = $date_array[2];
2473 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2474 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2476 else { $table_data .= "<td> </td>"; }
2478 $table_data .= "</tr>\n";
2480 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2482 $stat_data = "<tr><td><b><font size=-2>$total_indivs Individuals<br>PPI Totals:</font></b></td>";
2483 for($m=$num_months; $m >=0; $m--) {
2484 $percent = ceil(($ppis[$m] / $total_indivs)*100);
2485 $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
2487 $stat_data .= "</tr>";
2489 $this->t->set_var('table_width',$table_width);
2490 $this->t->set_var('header_row',$header_row);
2491 $this->t->set_var('table_data',$table_data);
2492 $this->t->set_var('stat_data',$stat_data);
2493 $this->t->pfp('out','ppi_view_t');
2494 $this->save_sessiondata();
2497 function ppi_update()
2499 $this->t->set_file(array('form' => 'ppi_update.tpl'));
2500 $this->t->set_block('form','interviewer_list','int_list');
2501 $this->t->set_block('form','add','addhandle');
2502 $this->t->set_block('form','edit','edithandle');
2504 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2505 $this->t->set_var('readonly','');
2506 $this->t->set_var('disabled','');
2508 $action = get_var('action',array('GET','POST'));
2509 $companionship = get_var('companionship',array('GET','POST'));
2510 $interviewer = get_var('interviewer',array('GET','POST'));
2511 $name = get_var('name',array('GET','POST'));
2512 $interview = get_var('interview',array('GET','POST'));
2513 $indiv = get_var('indiv',array('GET','POST'));
2514 $date = get_var('date',array('GET','POST'));
2515 $notes = get_var('notes',array('GET','POST'));
2516 $interview_type = get_var('interview_type',array('GET','POST'));
2518 $sql = "SELECT * FROM tc_presidency where valid=1 and (president=1 or counselor=1 or secretary=1)";
2519 $this->db2->query($sql,__LINE__,__FILE__);
2520 while ($this->db2->next_record())
2522 $indiv = $this->db2->f('indiv');
2523 $interviewer_name = $this->db2->f('name');
2524 if($indiv == $interviewer) {
2525 $this->t->set_var('interviewer',$interviewer . ' selected');
2527 $this->t->set_var('interviewer',$interviewer);
2529 $this->t->set_var('interviewer_name',$interviewer_name);
2530 $this->t->set_var('interview_type_checked','');
2531 $this->t->fp('int_list','interviewer_list',True);
2534 if($action == 'save')
2536 $notes = get_var('notes',array('POST'));
2537 $this->db->query("UPDATE tc_interview set " .
2538 " interview='" . $interview . "'" .
2539 ", interviewer='" . $interviewer . "'" .
2540 ", indiv='" . $indiv . "'" .
2541 ", date='" . $date . "'" .
2542 ", notes='" . $notes . "'" .
2543 ", interview_type='" . $interview_type . "'" .
2544 " WHERE interview=" . $interview,__LINE__,__FILE__);
2549 if($action == 'insert')
2551 $notes = get_var('notes',array('POST'));
2552 $this->db->query("INSERT INTO tc_interview (interviewer,indiv,date,notes,interview_type) "
2553 . "VALUES ('" . $interviewer . "','" . $indiv . "','"
2554 . $date . "','" . $notes . "','" . $interview_type ."')",__LINE__,__FILE__);
2559 if($action == 'add')
2561 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2562 $this->t->set_var('interview', '');
2563 $this->t->set_var('interviewer', $interviewer);
2564 $this->t->set_var('name',$name);
2565 $this->t->set_var('indiv',$indiv);
2566 $this->t->set_var('date','');
2567 $this->t->set_var('notes','');
2568 $this->t->set_var('interview_type',$interview_type);
2569 $this->t->set_var('interview_type_checked','checked');
2570 $this->t->set_var('lang_done','Cancel');
2571 $this->t->set_var('lang_action','Adding New PPI');
2572 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview='
2573 . $interview . '&action=' . 'insert'));
2576 if($action == 'edit' || $action == 'view')
2578 $sql = "SELECT * FROM tc_interview WHERE interview=".$interview;
2579 $this->db->query($sql,__LINE__,__FILE__);
2580 $this->db->next_record();
2581 $this->t->set_var('interview',$interview);
2582 $this->t->set_var('name',$name);
2583 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2584 $this->t->set_var('indiv',$this->db->f('indiv'));
2585 $this->t->set_var('date',$this->db->f('date'));
2586 $this->t->set_var('notes',$this->db->f('notes'));
2587 $this->t->set_var('interview_type',$this->db->f('interview_type'));
2588 if($this->db->f('interview_type') == 1) { $this->t->set_var('interview_type_checked','checked'); }
2591 if($action == 'edit')
2593 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2594 $this->t->set_var('lang_done','Cancel');
2595 $this->t->set_var('lang_action','Editing PPI');
2596 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview='
2597 . $interview . '&action=' . 'save'));
2600 if($action == 'view')
2602 $date = $this->db->f('date');
2603 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2604 $this->t->set_var('readonly','READONLY');
2605 $this->t->set_var('disabled','DISABLED');
2606 $this->t->set_var('lang_done','Done');
2607 $this->t->set_var('lang_action','Viewing PPI');
2608 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview='
2609 . $interview . '&action=' . 'edit'));
2612 $this->t->set_var('lang_reset','Clear Form');
2613 $this->t->set_var('lang_add','Add PPI');
2614 $this->t->set_var('lang_save','Save Changes');
2615 $this->t->set_var('edithandle','');
2616 $this->t->set_var('addhandle','');
2618 $this->t->pfp('out','form');
2620 if($action == 'view') { $this->t->set_var('lang_save','Edit PPI'); }
2621 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2622 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2624 $this->save_sessiondata();
2629 $this->t->set_file(array('int_view_t' => 'int_view.tpl'));
2630 $this->t->set_block('int_view_t','district_list','list');
2632 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2633 $num_quarters = get_var('num_quarters',array('GET','POST'));
2634 if($num_quarters == '') { $num_quarters = $this->default_int_num_quarters; }
2635 $this->t->set_var('num_quarters',$num_quarters);
2636 if($num_quarters == 1) { $this->t->set_var('lang_num_quarters','Quarter of History'); }
2637 else { $this->t->set_var('lang_num_quarters','Quarters of History'); }
2638 $this->t->set_var('lang_filter','Filter');
2640 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2641 $this->t->set_var('int_link_title','Hometeaching Interviews');
2643 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
2644 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
2646 $this->t->set_var('title','Hometeaching Interviews');
2648 $num_months = $num_quarters * 3 - 1;
2649 $current_month = $this->current_month;
2650 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
2651 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
2652 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
2653 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
2655 $sql = "SELECT * FROM tc_district where valid=1 ORDER BY district ASC";
2656 $this->db->query($sql,__LINE__,__FILE__);
2658 while ($this->db->next_record())
2660 $districts[$i]['district'] = $this->db->f('district');
2661 $districts[$i]['name'] = $this->db->f('name');
2662 $districts[$i]['supervisor'] = $this->db->f('supervisor');
2666 $sql = "SELECT * FROM tc_indiv where valid=1 ORDER BY indiv ASC";
2667 $this->db->query($sql,__LINE__,__FILE__);
2669 while ($this->db->next_record())
2671 $indiv_id[$i] = $this->db->f('indiv');
2672 $indiv_name[$i] = $this->db->f('name');
2673 $indiv_phone[$indiv_id[$i]] = $this->db->f('phone');
2676 array_multisort($indiv_name, $indiv_id);
2677 for($i=0; $i < count($indiv_id); $i++) {
2678 $id = $indiv_id[$i];
2679 $indivs[$id] = $indiv_name[$i];
2682 $total_companionships = 0;
2683 $this->nextmatchs->template_alternate_row_color(&$this->t);
2684 for ($i=0; $i < count($districts); $i++) {
2685 $this->t->set_var('district_number',$districts[$i]['district']);
2686 $this->t->set_var('district_name',$districts[$i]['name']);
2687 $supervisor = $districts[$i]['supervisor'];
2689 // Select all the unique companionship numbers for this district
2690 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$i]['district'];
2691 $this->db->query($sql,__LINE__,__FILE__);
2692 $j=0; $unique_companionships = '';
2693 while ($this->db->next_record())
2695 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
2699 $comp_width=250; $int_width=75; $table_width=$comp_width + $num_months*$int_width;
2700 $table_data=""; $num_companionships = $j; $num_indivs = 0;
2701 for($m=$num_months; $m >= 0; $m--) { $ints[$m] = 0; }
2702 for ($j=0; $j < count($unique_companionships); $j++) {
2703 // Select all the companions in each companionship
2704 $sql = "SELECT * FROM tc_companionship where valid=1 and ".
2705 "companionship=". $unique_companionships[$j]['companionship'];
2706 $this->db->query($sql,__LINE__,__FILE__);
2708 $comp = $unique_companionships[$j]['companionship'];
2709 for($m=$num_months; $m >= 0; $m--) { $int_recorded[$comp][$m] = 0; }
2710 while ($this->db->next_record())
2712 // Get this companions information
2714 $companionship = $this->db->f('companionship');
2715 $indiv_id = $this->db->f('indiv');
2716 $name = $indivs[$indiv_id];
2717 $phone = $indiv_phone[$indiv_id];
2718 $link_data['menuaction'] = 'tc.tc.int_update';
2719 $link_data['companionship'] = $companionship;
2720 $link_data['interviewer'] = $supervisor;
2721 $link_data['indiv'] = $indiv_id;
2722 $link_data['name'] = $name;
2723 $link_data['interview'] = '';
2724 $link_data['action'] = 'add';
2725 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2726 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2728 // Find out how many times Interviews were performed in the past $num_months for this individual
2729 $header_row="<th width=$comp_width><font size=-2>Companionship</th>";
2730 for($m=$num_months; $m >= 0; $m--) {
2731 $month = $current_month - $m;
2732 $year = $this->current_year;
2733 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
2734 if($month < 10) { $month = "0"."$month"; }
2735 $month_start = "$year"."-"."$month"."-"."01";
2736 $month_end = "$year"."-"."$month"."-"."31";
2737 $month = "$month"."/"."$year";
2738 $sql = "SELECT * FROM tc_interview WHERE date >= '$month_start' AND date <= '$month_end' ".
2739 "AND indiv=" . $indiv_id;
2740 $this->db2->query($sql,__LINE__,__FILE__);
2741 $header_row .= "<th width=$int_width><font size=-2>$month</th>";
2743 if(!$total_ints[$m]) { $total_ints[$m] = 0; }
2744 if($this->db2->next_record()) {
2745 if(!$int_recorded[$companionship][$m]) {
2746 $ints[$m]++; $total_ints[$m]++; $int_recorded[$companionship][$m]=1;
2748 $link_data['menuaction'] = 'tc.tc.int_update';
2749 $link_data['companionship'] = $companionship;
2750 $link_data['interviewer'] = $this->db2->f('interviewer');
2751 $link_data['indiv'] = $indiv_id;
2752 $link_data['name'] = $name;
2753 $link_data['interview'] = $this->db2->f('interview');
2754 $link_data['action'] = 'view';
2755 $date = $this->db2->f('date');
2756 $date_array = explode("-",$date);
2757 $month = $date_array[1];
2758 $day = $date_array[2];
2759 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2760 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2762 else { $table_data .= "<td> </td>"; }
2764 $table_data .= "</tr>";
2767 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2769 $total_companionships += $num_companionships;
2770 $stat_data = "<tr><td><b><font size=-2>$num_companionships Companionships<br>Interview Totals:</font></b></td>";
2772 // Print the hometeaching interview stats
2773 for($m=$num_months; $m >=0; $m--) {
2774 $month = $current_month - $m;
2775 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
2776 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
2777 //print "$month % $this->monthly_hometeaching_interview_stats = $month_begins <br>";
2778 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
2779 if(($month_begins) == 1) { $total = $ints[$m]; }
2780 else { $total += $ints[$m]; }
2781 $percent = ceil(($total / $num_companionships)*100);
2782 $stat_data .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
2784 $stat_data .= "</tr>";
2786 $this->t->set_var('table_width',$table_width);
2787 $this->t->set_var('header_row',$header_row);
2788 $this->t->set_var('table_data',$table_data);
2789 $this->t->set_var('stat_data',$stat_data);
2790 $this->t->fp('list','district_list',True);
2793 // Display the totals
2795 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>Interview Totals:</font></b></td>";
2796 for($m=$num_months; $m >=0; $m--) {
2797 $month = $current_month - $m;
2798 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
2799 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
2800 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
2801 if(($month_begins) == 1) { $total = $total_ints[$m]; }
2802 else { $total += $total_ints[$m]; }
2803 $percent = ceil(($total / $total_companionships)*100);
2804 $totals .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
2808 $this->t->set_var('totals',$totals);
2809 $this->t->pfp('out','int_view_t');
2810 $this->save_sessiondata();
2813 function int_update()
2815 $this->t->set_file(array('form' => 'int_update.tpl'));
2816 $this->t->set_block('form','interviewer_list','int_list');
2817 $this->t->set_block('form','add','addhandle');
2818 $this->t->set_block('form','edit','edithandle');
2820 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2821 $this->t->set_var('readonly','');
2822 $this->t->set_var('disabled','');
2823 $this->t->set_var('interview_type_checked','');
2825 $action = get_var('action',array('GET','POST'));
2826 $companionship = get_var('companionship',array('GET','POST'));
2827 $interviewer = get_var('interviewer',array('GET','POST'));
2828 $name = get_var('name',array('GET','POST'));
2829 $interview = get_var('interview',array('GET','POST'));
2830 $indiv = get_var('indiv',array('GET','POST'));
2831 $date = get_var('date',array('GET','POST'));
2832 $notes = get_var('notes',array('GET','POST'));
2833 $interview_type = get_var('interview_type',array('GET','POST'));
2835 $sql = "SELECT * FROM tc_presidency where valid=1 and (president=1 or counselor=1 or secretary=1 or district!=0)";
2836 $this->db2->query($sql,__LINE__,__FILE__);
2837 while ($this->db2->next_record())
2839 $indiv = $this->db2->f('indiv');
2840 $interviewer_name = $this->db2->f('name');
2841 if($indiv == $interviewer) {
2842 $this->t->set_var('interviewer',$interviewer . ' selected');
2844 $this->t->set_var('interviewer',$interviewer);
2846 $this->t->set_var('interviewer_name',$interviewer_name);
2847 $this->t->fp('int_list','interviewer_list',True);
2850 if($action == 'save')
2852 $notes = get_var('notes',array('POST'));
2853 $this->db->query("UPDATE tc_interview set " .
2854 " interview='" . $interview . "'" .
2855 ", interviewer='" . $interviewer . "'" .
2856 ", indiv='" . $indiv . "'" .
2857 ", date='" . $date . "'" .
2858 ", notes='" . $notes . "'" .
2859 ", interview_type='" . $interview_type . "'" .
2860 " WHERE interview=" . $interview,__LINE__,__FILE__);
2865 if($action == 'insert')
2867 $notes = get_var('notes',array('POST'));
2868 $this->db->query("INSERT INTO tc_interview (interviewer,indiv,date,notes,interview_type) "
2869 . "VALUES ('" . $interviewer . "','" . $indiv . "','"
2870 . $date . "','" . $notes ."','" . $interview_type . "')",__LINE__,__FILE__);
2875 if($action == 'add')
2877 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2878 $this->t->set_var('interview', '');
2879 $this->t->set_var('interviewer', $interviewer);
2880 $this->t->set_var('name',$name);
2881 $this->t->set_var('indiv',$indiv);
2882 $this->t->set_var('date','');
2883 $this->t->set_var('notes','');
2884 $this->t->set_var('lang_done','Cancel');
2885 $this->t->set_var('lang_action','Adding New Interview');
2886 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview='
2887 . $interview . '&action=' . 'insert'));
2890 if($action == 'edit' || $action == 'view')
2892 $sql = "SELECT * FROM tc_interview WHERE interview=".$interview;
2893 $this->db->query($sql,__LINE__,__FILE__);
2894 $this->db->next_record();
2895 $this->t->set_var('interview',$interview);
2896 $this->t->set_var('name',$name);
2897 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2898 $this->t->set_var('indiv',$this->db->f('indiv'));
2899 $this->t->set_var('date',$this->db->f('date'));
2900 $this->t->set_var('notes',$this->db->f('notes'));
2901 if($this->db->f('interview_type') == 1) { $this->t->set_var('interview_type_checked','checked'); }
2904 if($action == 'edit')
2906 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2907 $this->t->set_var('lang_done','Cancel');
2908 $this->t->set_var('lang_action','Editing Interview');
2909 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview='
2910 . $interview . '&action=' . 'save'));
2913 if($action == 'view')
2915 $date = $this->db->f('date');
2916 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2917 $this->t->set_var('readonly','READONLY');
2918 $this->t->set_var('disabled','DISABLED');
2919 $this->t->set_var('lang_done','Done');
2920 $this->t->set_var('lang_action','Viewing Interview');
2921 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview='
2922 . $interview . '&action=' . 'edit'));
2925 $this->t->set_var('lang_reset','Clear Form');
2926 $this->t->set_var('lang_add','Add Interview');
2927 $this->t->set_var('lang_save','Save Changes');
2928 $this->t->set_var('edithandle','');
2929 $this->t->set_var('addhandle','');
2931 $this->t->pfp('out','form');
2933 if($action == 'view') { $this->t->set_var('lang_save','Edit Interview'); }
2934 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2935 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2937 $this->save_sessiondata();
2942 $this->t->set_file(array('vis_view_t' => 'vis_view.tpl'));
2943 $this->t->set_block('vis_view_t','visit_list','list1');
2944 $this->t->set_block('vis_view_t','family_list','list2');
2946 $this->t->set_var('lang_name','Family Name');
2947 $this->t->set_var('lang_date','Date');
2949 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2950 $this->t->set_var('vis_link_title','View Yearly Visits');
2952 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
2953 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2955 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2956 $num_years = get_var('num_years',array('GET','POST'));
2957 if($num_years == '') { $num_years = $this->default_vis_num_years; }
2958 $this->t->set_var('num_years',$num_years);
2959 if($num_years == 1) { $this->t->set_var('lang_num_years','Year of History'); }
2960 else { $this->t->set_var('lang_num_years','Years of History'); }
2961 $this->t->set_var('lang_filter','Filter');
2963 $year = date('Y') - $num_years + 1;
2964 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2966 $sql = "SELECT * FROM tc_visit WHERE companionship=0 and date > '$year_start' ORDER BY date DESC";
2967 $this->db->query($sql,__LINE__,__FILE__);
2968 $total_records = $this->db->num_rows();
2971 while ($this->db->next_record())
2973 $visit_list[$i]['visit'] = $this->db->f('visit');
2974 $visit_list[$i]['family'] = $this->db->f('family');
2975 $visit_list[$i]['date'] = $this->db->f('date');
2979 for ($i=0; $i < count($visit_list); $i++)
2981 $this->nextmatchs->template_alternate_row_color(&$this->t);
2983 $sql = "SELECT * FROM tc_family WHERE family=".$visit_list[$i]['family'];
2984 $this->db->query($sql,__LINE__,__FILE__);
2985 $this->db->next_record();
2987 $this->t->set_var('family',$visit_list[$i]['family']);
2988 $this->t->set_var('family_name',$this->db->f('name'));
2989 $this->t->set_var('date',$visit_list[$i]['date']);
2991 $link_data['menuaction'] = 'tc.tc.vis_update';
2992 $link_data['visit'] = $visit_list[$i]['visit'];
2993 $link_data['name'] = $this->db->f('name');
2994 $link_data['date'] = $visit_list[$i]['date'];
2995 $link_data['action'] = 'view';
2996 $this->t->set_var('view',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
2997 $this->t->set_var('lang_view','View');
2999 $link_data['menuaction'] = 'tc.tc.vis_update';
3000 $link_data['visit'] = $visit_list[$i]['visit'];
3001 $link_data['name'] = $this->db->f('name');
3002 $link_data['date'] = $visit_list[$i]['date'];
3003 $link_data['action'] = 'edit';
3004 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3005 $this->t->set_var('lang_edit','Edit');
3007 $this->t->fp('list1','visit_list',True);
3010 // List the families that are available to record a visit against
3011 $sql = "SELECT * FROM tc_family WHERE valid=1";
3012 $this->db->query($sql,__LINE__,__FILE__);
3013 $total_records = $this->db->num_rows();
3016 while ($this->db->next_record())
3018 $family_names[$i] = $this->db->f('name');
3019 $family_ids[$i] = $this->db->f('family');
3021 } array_multisort($family_names, $family_ids);
3023 for ($i=0; $i < count($family_names); $i++)
3025 $link_data['menuaction'] = 'tc.tc.vis_update';
3026 $link_data['visit'] = '';
3027 $link_data['family'] = $family_ids[$i];
3028 $link_data['action'] = 'add';
3029 $link_data['name'] = $family_names[$i];
3030 $this->t->set_var('add',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3032 $this->t->set_var('name',$family_names[$i]);
3033 if(($i+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
3034 else { $this->t->set_var('table_sep',"</td>"); }
3035 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
3037 $this->t->fp('list2','family_list',True);
3040 $this->t->pfp('out','vis_view_t');
3041 $this->save_sessiondata();
3044 function vis_update()
3046 $this->t->set_file(array('form' => 'vis_update.tpl'));
3047 $this->t->set_block('form','add','addhandle');
3048 $this->t->set_block('form','edit','edithandle');
3050 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
3051 $this->t->set_var('readonly','');
3052 $this->t->set_var('disabled','');
3054 $action = get_var('action',array('GET','POST'));
3055 $visit = get_var('visit',array('GET','POST'));
3056 $family = get_var('family',array('GET','POST'));
3057 $name = get_var('name',array('GET','POST'));
3058 $date = get_var('date',array('GET','POST'));
3059 $notes = get_var('notes',array('GET','POST'));
3062 if($action == 'save')
3064 $notes = get_var('notes',array('POST'));
3065 $this->db->query("UPDATE tc_visit set " .
3066 " date='" . $date . "'" .
3067 ", notes='" . $notes . "'" .
3068 " WHERE visit=" . $visit,__LINE__,__FILE__);
3073 if($action == 'insert')
3075 $notes = get_var('notes',array('POST'));
3076 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes) "
3077 . "VALUES ('" . $family . "','" . $companionship . "','"
3078 . $date . "','" . $notes . "')",__LINE__,__FILE__);
3083 if($action == 'add')
3085 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
3086 $this->t->set_var('family', $family);
3087 $this->t->set_var('visit', '');
3088 $this->t->set_var('name', $name);
3089 $this->t->set_var('date','');
3090 $this->t->set_var('notes','');
3091 $this->t->set_var('lang_done','Cancel');
3092 $this->t->set_var('lang_action','Adding New Visit');
3093 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&family='
3094 . $family . '&action=' . 'insert'));
3097 if($action == 'edit' || $action == 'view')
3099 $sql = "SELECT * FROM tc_visit WHERE visit=".$visit;
3100 $this->db->query($sql,__LINE__,__FILE__);
3101 $this->db->next_record();
3102 $this->t->set_var('visit',$visit);
3103 $this->t->set_var('name',$name);
3104 $this->t->set_var('family', $family);
3105 $this->t->set_var('date',$this->db->f('date'));
3106 $this->t->set_var('notes',$this->db->f('notes'));
3109 if($action == 'edit')
3111 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
3112 $this->t->set_var('lang_done','Cancel');
3113 $this->t->set_var('lang_action','Editing Visit');
3114 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit='
3115 . $visit . '&action=' . 'save'));
3118 if($action == 'view')
3120 $date = $this->db->f('date');
3121 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
3122 $this->t->set_var('readonly','READONLY');
3123 $this->t->set_var('disabled','DISABLED');
3124 $this->t->set_var('lang_done','Done');
3125 $this->t->set_var('lang_action','Viewing Visit');
3126 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit='
3127 . $visit . '&action=' . 'edit'));
3130 $this->t->set_var('lang_reset','Clear Form');
3131 $this->t->set_var('lang_add','Add Visit');
3132 $this->t->set_var('lang_save','Save Changes');
3133 $this->t->set_var('edithandle','');
3134 $this->t->set_var('addhandle','');
3136 $this->t->pfp('out','form');
3138 if($action == 'view') { $this->t->set_var('lang_save','Edit Visit'); }
3139 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
3140 if($action == 'add') { $this->t->pfp('addhandle','add'); }
3142 $this->save_sessiondata();
3147 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3148 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3149 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3151 $this->t->set_file(array('att_view_t' => 'att_view.tpl'));
3152 $this->t->set_block('att_view_t','act_list','list');
3154 $this->t->set_block('att_view_t','month_list','list1');
3155 $this->t->set_block('att_view_t','header_list','list2');
3156 $this->t->set_block('att_view_t','indiv_list','list3');
3158 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3159 $num_quarters = get_var('num_quarters',array('GET','POST'));
3160 if($num_quarters == '') { $num_quarters = $this->default_att_num_quarters; }
3161 $this->t->set_var('num_quarters',$num_quarters);
3162 $this->t->set_var('lang_filter','Filter');
3163 if($num_quarters == 1) { $this->t->set_var('lang_num_quarters','Quarter of History'); }
3164 else { $this->t->set_var('lang_num_quarters','Quarters of History'); }
3166 $num_months = $num_quarters * 3;
3167 $current_month = $this->current_month;
3168 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
3169 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
3170 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
3171 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
3173 // TODO: changed this so it picks the quorum dynamically
3174 $sql = "SELECT * FROM tc_indiv where steward='Elder' and valid=1";
3175 $this->db->query($sql,__LINE__,__FILE__);
3177 while ($this->db->next_record())
3179 $indiv_name[$i] = $this->db->f('name');
3180 $indiv_id[$i] = $this->db->f('indiv');
3183 array_multisort($indiv_name, $indiv_id);
3185 // Create a list of sunday dates for a window of 3 months back and current month
3189 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, ($current_month-$num_months)+1, 1, date("y")));
3190 $last_date = explode("-",$sunday_list[0]['date']);
3191 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3192 $time_limit = mktime(0, 0, 0, $current_month, 31, date("y"));
3193 while($last_time < $time_limit)
3195 $day = date("w",$last_time);
3196 if(date("w",$last_time) == 0) {
3197 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3198 $last_date = explode("-",$sunday_list[$i]['date']);
3199 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3200 $sunday_list[$i]['day'] = $last_date[2];
3201 $sunday_list[$i]['month'] = date("M",$last_time);
3202 $sunday_list[$i]['year'] = $last_date[0];
3204 $last_date = $sunday_list[$i]['date'];
3206 $last_time += 90000;
3207 if($found_sunday) { $i++; $found_sunday=0; }
3210 $total_indivs = count($indiv_id);
3211 $old_month=$sunday_list[0]['month']; $span=0;
3212 for ($i=0; $i < count($sunday_list); $i++) {
3213 $date = $sunday_list[$i]['date'];
3214 $this->t->set_var('date',$sunday_list[$i]['date']);
3215 $this->t->set_var('day',$sunday_list[$i]['day']);
3216 if(($old_month != $sunday_list[$i]['month']) || $i == count($sunday_list)-1) {
3217 if($i == count($sunday_list)-1) { $span++; }
3218 $cur_month = $sunday_list[$i]['month'];
3219 $old_month = $sunday_list[$i]['month'];
3220 $link_data['menuaction'] = 'tc.tc.att_update';
3221 $link_data['month'] = $sunday_list[$i-1]['month'];
3222 $link_data['year'] = $sunday_list[$i-1]['year'];
3223 $link_data['action'] = 'update_month';
3224 $cur_month = $sunday_list[$i-1]['month'];
3225 $cur_year = $sunday_list[$i-1]['year'];
3226 $header_row .= "<th><font size=-3>$cur_month $cur_year</font></th>";
3227 $this->t->set_var('update_month',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3228 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3229 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3230 $this->t->set_var('span',$span); $span=0;
3231 $this->t->fp('list1','month_list',True);
3234 $this->t->set_var('total_indivs',$total_indivs);
3235 $this->t->set_var('header_row',$header_row);
3237 $indiv_width=200; $att_width=25; $total_width=$indiv_width;
3238 for ($i=0; $i < count($sunday_list); $i++) {
3239 $link_data['menuaction'] = 'tc.tc.att_update';
3240 $link_data['month'] = $sunday_list[$i]['month'];
3241 $link_data['year'] = $sunday_list[$i]['year'];
3242 $link_data['day'] = $sunday_list[$i]['day'];
3243 $link_data['date'] = $sunday_list[$i]['date'];
3244 $link_data['action'] = 'update_day';
3245 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3246 $this->t->set_var('date',$sunday_list[$i]['date']);
3247 $this->t->set_var('day',$sunday_list[$i]['day']);
3248 $this->t->set_var('month',$sunday_list[$i]['month']);
3249 $this->t->set_var('year',$sunday_list[$i]['year']);
3250 $this->t->fp('list2','header_list',True);
3251 $total_width += $att_width;
3252 $attendance[$monthnum[$sunday_list[$i]['month']]]=0;
3255 for ($i=0; $i < count($indiv_id); $i++) {
3257 $this->nextmatchs->template_alternate_row_color(&$this->t);
3258 $this->t->set_var('indiv_name',$indiv_name[$i]);
3259 #print "checking for indiv: " . $indiv_id[$i] . "<br>";
3260 for ($j=0; $j < count($sunday_list); $j++) {
3261 #print "checking for date: " . $sunday_list[$j]['date'] . "<br>";
3262 #print "SELECT * FROM tc_attendance WHERE date='"
3263 # . $sunday_list[$j]['date'] . "' AND indiv=" . $indiv_id[$i] . "<br>";
3264 $sql = "SELECT * FROM tc_attendance WHERE date='"
3265 . $sunday_list[$j]['date'] . "' AND indiv=" . $indiv_id[$i];
3266 $this->db->query($sql,__LINE__,__FILE__);
3267 if($this->db->next_record()) {
3268 $cur_month = $sunday_list[$j]['month'];
3269 if($attended[$i][$cur_month] != 1) {
3270 $attended[$i][$cur_month]=1;
3271 $attendance[$monthnum[$cur_month]]++;
3273 $att_table .= '<td align=center><img src="images/checkmark.gif"></td>';
3275 $att_table .= '<td> </td>';
3278 $this->t->set_var('att_table',$att_table);
3279 $this->t->fp('list3','indiv_list',True);
3281 $this->t->set_var('total_width',$total_width);
3282 $this->t->set_var('indiv_width',$indiv_width);
3283 $this->t->set_var('att_width',$att_width);
3285 # Now calculate attendance for these months
3286 $attendance_str = "";
3287 $nonattendance_str = "";
3288 $aveattendance_str = "";
3289 $avenonattendance_str = "";
3291 $ave_total_attended=0;
3293 foreach($attendance as $att => $value) {
3294 $total_attended = $attendance[$att];
3295 $ave_total_attended += $attendance[$att]; $num_months++;
3296 $percent = ceil(($total_attended / $total_indivs)*100);
3297 $attendance_str.="<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3298 $total_nonattended = $total_indivs - $total_attended;
3299 $percent = ceil(($total_nonattended / $total_indivs)*100);
3300 $nonattendance_str.="<td align=center><font size=-2><b>$total_nonattended ($percent%)</b></font></td>";
3302 $total_attended = ceil(($ave_total_attended / $num_months));
3303 $percent = ceil(($total_attended / $total_indivs)*100);
3304 $aveattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3305 $total_attended = $total_indivs - ceil(($ave_total_attended / $num_months));
3306 $percent = ceil(($total_attended / $total_indivs)*100);
3307 $avenonattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3310 $this->t->set_var('attendance',$attendance_str);
3311 $this->t->set_var('aveattendance',$aveattendance_str);
3312 $this->t->set_var('nonattendance',$nonattendance_str);
3313 $this->t->set_var('avenonattendance',$avenonattendance_str);
3315 $this->t->pfp('out','att_view_t');
3316 $this->save_sessiondata();
3319 function att_update()
3321 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3322 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3323 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3325 $this->t->set_file(array('form' => 'att_update.tpl'));
3326 $this->t->set_block('form','edit','edithandle');
3328 $this->t->set_block('form','month_list','list1');
3329 $this->t->set_block('form','header_list','list2');
3330 $this->t->set_block('form','indiv_list','list3');
3332 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3334 $action = get_var('action',array('GET','POST'));
3335 $month = get_var('month',array('GET','POST'));
3336 $year = get_var('year',array('GET','POST'));
3337 $day = get_var('day',array('GET','POST'));
3338 $date = get_var('date',array('GET','POST'));
3340 if($action == 'save_month' || $action == 'save_day')
3342 $new_data = get_var('indivs_attended',array('POST'));
3343 $month = $monthnum[$month]; if($month < 10) { $month = "0" . $month; }
3345 if($action == 'save_month') {
3346 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-%'",__LINE__,__FILE__);
3349 if($action == 'save_day') {
3350 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-".$day."'",__LINE__,__FILE__);
3353 foreach ($new_data as $data)
3355 $data_array = explode("-",$data);
3356 $indiv = $data_array[0];
3357 $date = "$data_array[1]-$data_array[2]-$data_array[3]";
3358 $this->db->query("INSERT INTO tc_attendance (indiv,date) "
3359 . "VALUES (" . $indiv . ",'". $date . "')",__LINE__,__FILE__);
3366 // TODO: changed this so it picks the quorum dynamically
3367 $sql = "SELECT * FROM tc_indiv where steward='Elder' and valid=1";
3368 $this->db->query($sql,__LINE__,__FILE__);
3370 while ($this->db->next_record())
3372 $indiv_name[$i] = $this->db->f('name');
3373 $indiv_id[$i] = $this->db->f('indiv');
3374 $indiv_attending[$indiv_id[$i]] = $this->db->f('attending');
3377 array_multisort($indiv_name, $indiv_id);
3379 if($action == 'update_month')
3381 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_month'));
3385 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], 1, $year));
3386 $last_date = explode("-",$sunday_list[0]['date']);
3387 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3388 $time_limit = mktime(0, 0, 0, $monthnum[$month], 31, $year);
3389 while($last_time <= $time_limit)
3391 $day = date("w",$last_time);
3392 if(date("w",$last_time) == 0) {
3393 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3394 $last_date = explode("-",$sunday_list[$i]['date']);
3395 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3396 $sunday_list[$i]['day'] = $last_date[2];
3397 $sunday_list[$i]['month'] = date("M",$last_time);
3398 $sunday_list[$i]['year'] = $last_date[0];
3401 $last_time += 90000;
3402 if($found_sunday) { $i++; $found_sunday=0; }
3405 $this->t->set_var('span', $i);
3406 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3407 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3408 $this->t->fp('list1','month_list',True);
3409 $indiv_width=200; $att_width=25; $total_width=$indiv_width;
3410 for ($i=0; $i < count($sunday_list); $i++) {
3411 $link_data['menuaction'] = 'tc.tc.att_update';
3412 $link_data['month'] = $sunday_list[$i]['month'];
3413 $link_data['year'] = $sunday_list[$i]['year'];
3414 $link_data['day'] = $sunday_list[$i]['day'];
3415 $link_data['date'] = $sunday_list[$i]['date'];
3416 $link_data['action'] = 'update_day';
3417 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3418 $this->t->set_var('date',$sunday_list[$i]['date']);
3419 $this->t->set_var('day',$sunday_list[$i]['day']);
3420 $this->t->set_var('month',$sunday_list[$i]['month']);
3421 $this->t->set_var('year',$sunday_list[$i]['year']);
3422 $this->t->fp('list2','header_list',True);
3423 $total_width += $att_width;
3427 if($action == 'update_day')
3429 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_day'));
3430 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], $day, $year));
3431 $this->t->set_var('month',$month);
3432 $this->t->set_var('year',$year);
3433 $this->t->fp('list1','month_list',True);
3434 $this->t->set_var('date',$date);
3435 $this->t->set_var('day',$day);
3436 $this->t->set_var('month',$month);
3437 $this->t->set_var('year',$year);
3438 $this->t->fp('list2','header_list',True);
3441 for ($i=0; $i < count($indiv_id); $i++) {
3443 $this->nextmatchs->template_alternate_row_color(&$this->t);
3444 $this->t->set_var('indiv_name',$indiv_name[$i]);
3445 for ($j=0; $j < count($sunday_list); $j++) {
3446 $sql = "SELECT * FROM tc_attendance WHERE date='"
3447 . $sunday_list[$j]['date'] . "' AND indiv=" . $indiv_id[$i];
3448 $this->db->query($sql,__LINE__,__FILE__);
3449 $value = $indiv_id[$i] . "-" . $sunday_list[$j]['date'];
3450 if($this->db->next_record()) {
3451 $att_table .= '<td align=center><input type="checkbox" name="indivs_attended[]" value="'.$value.'" checked></td>';
3452 } else if($indiv_attending[$indiv_id[$i]] == 1) {
3453 $att_table .= '<td align=center><input type="checkbox" name="indivs_attended[]" value="'.$value.'" checked></td>';
3455 $att_table .= '<td align=center><input type="checkbox" name="indivs_attended[]" value="'.$value.'"></td>';
3458 $this->t->set_var('att_table',$att_table);
3459 $this->t->fp('list3','indiv_list',True);
3462 $this->t->set_var('lang_done', 'Cancel');
3463 $this->t->set_var('lang_reset','Clear Form');
3464 $this->t->set_var('lang_save','Save Changes');
3466 $this->t->pfp('out','form');
3467 $this->t->pfp('addhandle','edit');
3469 $this->save_sessiondata();
3474 $this->t->set_file(array('dir_view_t' => 'dir_view.tpl'));
3475 $this->t->set_block('dir_view_t','dir_list','list');
3477 $sql = "SELECT * FROM tc_indiv where valid=1 and hh_position='Head of Household' ORDER BY name ASC";
3478 $this->db->query($sql,__LINE__,__FILE__);
3480 while ($this->db->next_record())
3482 $parent[$i]['id'] = $this->db->f('indiv');
3483 $parent[$i]['name'] = $this->db->f('name');
3484 $parent[$i]['phone'] = $this->db->f('phone');
3485 $parent[$i]['address'] = $this->db->f('address');
3489 for ($i=0; $i < count($parent); $i++)
3491 $name = $parent[$i]['name'];
3492 $phone = $parent[$i]['phone'];
3493 $address = $parent[$i]['address'];
3494 $this->t->set_var('name', $name);
3495 $this->t->set_var('address', $address);
3496 $this->t->set_var('phone', $phone);
3497 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3498 $this->t->set_var('tr_color',$tr_color);
3499 $this->t->fp('list','dir_list',True);
3500 //print "$phone $name $address<br>";
3502 $this->t->pfp('out','dir_view_t');
3503 $this->save_sessiondata();
3508 $this->t->set_file(array('org_view_t' => 'org_view.tpl'));
3509 $this->t->set_block('org_view_t','calling_list','list1');
3510 $this->t->set_block('org_view_t','org_list','list2');
3512 # Display a list ordered alphabetically
3513 $sql = "SELECT * FROM tc_calling ORDER BY name ASC";
3514 $this->db->query($sql,__LINE__,__FILE__);
3516 while ($this->db->next_record())
3518 $calling[$i]['id'] = $this->db->f('indiv_id');
3519 $calling[$i]['name'] = $this->db->f('name');
3520 $calling[$i]['position'] = $this->db->f('position');
3521 $calling[$i]['sustained'] = $this->db->f('sustained');
3522 $calling[$i]['organization'] = $this->db->f('organization');
3525 for ($i=0; $i < count($calling); $i++)
3527 $name = $calling[$i]['name'];
3528 $position = $calling[$i]['position'];
3529 $sustained = $calling[$i]['sustained'];
3530 $organization = $calling[$i]['organization'];
3531 $this->t->set_var('name', $name);
3532 $this->t->set_var('position', $position);
3533 $this->t->set_var('sustained', $sustained);
3534 $this->t->set_var('organization', $organization);
3535 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3536 $this->t->set_var('tr_color',$tr_color);
3537 $this->t->fp('list1','calling_list',True);
3540 # Display a list ordered by organization
3541 $sql = "SELECT * FROM tc_calling ORDER BY sequence ASC";
3542 $this->db->query($sql,__LINE__,__FILE__);
3544 while ($this->db->next_record())
3546 $calling[$i]['id'] = $this->db->f('indiv_id');
3547 $calling[$i]['name'] = $this->db->f('name');
3548 $calling[$i]['position'] = $this->db->f('position');
3549 $calling[$i]['sustained'] = $this->db->f('sustained');
3550 $calling[$i]['organization'] = $this->db->f('organization');
3553 for ($i=0; $i < count($calling); $i++)
3555 $name = $calling[$i]['name'];
3556 $position = $calling[$i]['position'];
3557 $sustained = $calling[$i]['sustained'];
3558 $organization = $calling[$i]['organization'];
3559 $this->t->set_var('name', $name);
3560 $this->t->set_var('position', $position);
3561 $this->t->set_var('sustained', $sustained);
3562 $this->t->set_var('organization', $organization);
3563 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3564 $this->t->set_var('tr_color',$tr_color);
3565 $this->t->fp('list2','org_list',True);
3568 $this->t->pfp('out','org_view_t');
3569 $this->save_sessiondata();
3574 $this->t->set_file(array('sched_t' => 'schedule.tpl'));
3575 $this->t->set_block('sched_t','presidency_list','list');
3577 $action = get_var('action',array('GET','POST'));
3579 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule&action=save'));
3580 $this->t->set_var('title','Scheduling Tool');
3582 $this->t->set_var('lang_save','Save Schedule');
3583 $this->t->set_var('lang_reset','Cancel');
3585 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
3586 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
3588 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
3589 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
3591 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
3592 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
3594 $date_width=150; $time_width=220; $indiv_width=170; $family_width=180; $location_width=100;
3595 $table_width=$date_width + $time_width + $indiv_width + $family_width + $location_width;
3596 $header_row = "<th width=$date_width><font size=-2>Date</th>";
3597 $header_row.= "<th width=$time_width><font size=-2>Time</th>";
3598 $header_row.= "<th width=$indiv_width><font size=-2>individual</th>";
3599 $header_row.= "<th width=$family_width><font size=-2>Family</th>";
3600 $header_row.= "<th width=$location_width><font size=-2>Location</th>";
3603 $sql = "SELECT * FROM tc_presidency where valid=1";
3604 $this->db->query($sql,__LINE__,__FILE__);
3606 while ($this->db->next_record())
3608 $presidency_data[$i]['id'] = $this->db->f('presidency');
3609 $presidency_data[$i]['name'] = $this->db->f('name');
3610 $presidency_data[$i]['indiv'] = $this->db->f('indiv');
3611 $presidency2name[$presidency_data[$i]['id']] = $presidency_data[$i]['name'];
3612 $presidency2indiv[$presidency_data[$i]['id']] = $presidency_data[$i]['indiv'];
3616 $sql = "SELECT * FROM tc_family where valid=1 and indiv_id != 0 ORDER BY name ASC";
3617 $this->db->query($sql,__LINE__,__FILE__);
3619 while ($this->db->next_record())
3621 $family_id[$i] = $this->db->f('family');
3622 $family_name[$i] = $this->db->f('name');
3623 $familyid2name[$family_id[$i]] = $family_name[$i];
3624 $sql = "SELECT * FROM tc_indiv where family='$family_id[$i]' and hh_position='Head of Household'";
3625 $this->db2->query($sql,__LINE__,__FILE__);
3626 if($this->db2->next_record()) {
3627 $familyid2address[$family_id[$i]] = $this->db2->f('address');
3631 array_multisort($family_name, $family_id);
3633 if($action == 'save')
3635 $new_data = get_var('sched',array('POST'));
3636 foreach ($new_data as $presidency_array)
3638 foreach ($presidency_array as $entry)
3640 $presidency = $entry['presidency'];
3641 $appointment = $entry['appointment'];
3642 $location = $entry['location'];
3643 $date = $entry['date'];
3644 $hour = $entry['hour'];
3645 $minute = $entry['minute'];
3647 $indiv = $entry['indiv'];
3648 $family = $entry['family'];
3649 $location = $entry['location'];
3650 if($pm) { $hour = $hour + 12; }
3651 $time = $hour.':'.$minute.':'.'00';
3654 // Update our location
3655 if($location == "") {
3657 $family_name_array = explode(",", $familyid2name[$family]);
3658 $family_last_name = $family_name_array[0];
3659 $family_address = $familyid2address[$family];
3660 $location = "$family_last_name"." home ($family_address)";
3662 else if($indiv > 0) {
3663 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
3664 $supervisor_last_name = $supervisor_name_array[0];
3665 $sql = "SELECT * FROM tc_indiv where indiv='$presidency2indiv[$presidency]'";
3666 $this->db2->query($sql,__LINE__,__FILE__);
3667 if($this->db2->next_record()) {
3668 $indiv_id = $this->db2->f('indiv_id');
3670 $sql = "SELECT * FROM tc_indiv where indiv_id='$indiv_id'";
3671 $this->db2->query($sql,__LINE__,__FILE__);
3672 if($this->db2->next_record()) {
3673 $supervisor_address = $this->db2->f('address');
3675 $location = "$supervisor_last_name"." home ($supervisor_address)";
3679 // Zero out the family or individual if date = NULL
3686 if(($indiv == 0) && ($family == 0)) { $location = ""; }
3688 // Update an existing appointment
3689 if($appointment < $this->max_appointments)
3691 //Only perform a database update if we have made a change to this appointment
3692 $sql = "SELECT * FROM tc_appointment where " .
3693 "appointment='$appointment'" .
3694 " and presidency='$presidency'" .
3695 " and indiv='$indiv'" .
3696 " and family='$family'" .
3697 " and date='$date'" .
3698 " and time='$time'" .
3699 " and location='$location'";
3700 $this->db->query($sql,__LINE__,__FILE__);
3701 if(!$this->db->next_record()) {
3702 $old_date = $this->db->f('date');
3703 $old_time = $this->db->f('time');
3704 $this->db2->query("UPDATE tc_appointment set" .
3705 " family=" . $family .
3706 " ,indiv=" . $indiv .
3707 " ,date='" . $date . "'" .
3708 " ,time='" . $time . "'" .
3709 " ,location='" . $location . "'" .
3710 " ,presidency='" . $presidency . "'" .
3711 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
3713 // Email the appointment
3714 $this->email_appt($appointment);
3718 // Add a new appointment
3719 else if(($appointment >= $this->max_appointments) && ($date != "") && ($time != ""))
3721 //print "adding entry: appt=$appointment date: $date time: $time indiv: $indiv family: $family<br>";
3722 $this->db2->query("INSERT INTO tc_appointment (appointment,presidency,family,indiv,date,time,location,uid) "
3723 . "VALUES (NULL,'" . $presidency . "','" . $family . "','" . $indiv . "','"
3724 . $date . "','" . $time . "','" . $location . "','" . $uid ."')",__LINE__,__FILE__);
3726 // Now reselect this entry from the database to see if we need
3727 // to send an appointment out for it.
3728 $sql = "SELECT * FROM tc_appointment where " .
3730 " and family='$family'" .
3731 " and presidency='$presidency'" .
3732 " and date='$date'" .
3733 " and time='$time'" .
3735 " and location='$location'";
3736 $this->db3->query($sql,__LINE__,__FILE__);
3737 if($this->db3->next_record()) {
3738 // Email the appointment if warranted
3739 if(($date != "") && ($time != "") && (($indiv > 0) || $family > 0)) {
3740 $this->email_appt($this->db3->f('appointment'));
3747 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule');
3748 //Header('Location: ' . $take_me_to_url);
3751 // TODO: changed this so it picks the quorum dynamically
3752 $sql = "SELECT * FROM tc_indiv where steward='Elder' and valid=1 ORDER BY indiv ASC";
3753 $this->db->query($sql,__LINE__,__FILE__);
3755 while ($this->db->next_record())
3757 $indiv_id[$i] = $this->db->f('indiv');
3758 $indiv_name[$i] = $this->db->f('name');
3759 $indiv_phone[$indiv_id[$i]] = $this->db->f('phone');
3762 array_multisort($indiv_name, $indiv_id);
3764 for ($i=0; $i < count($presidency_data); $i++) {
3765 $presidency = $presidency_data[$i]['id'];
3766 $interviewer = $presidency_data[$i]['indiv'];
3767 $name = $presidency_data[$i]['name'];
3768 $this->t->set_var('presidency_name',$name);
3771 // query the database for all the appointments
3772 $sql = "SELECT * FROM tc_appointment where presidency=$presidency and date>=CURDATE() ORDER BY date ASC, time ASC";
3773 $this->db->query($sql,__LINE__,__FILE__);
3775 // Prefill any existing appointment slots
3776 while ($this->db->next_record())
3778 $appointment = $this->db->f('appointment');
3779 $indiv = $this->db->f('indiv');
3780 $family = $this->db->f('family');
3781 $location = $this->db->f('location');
3783 if($location == "") {
3785 $family_name_array = explode(",", $familyid2name[$family]);
3786 $family_last_name = $family_name_array[0];
3787 $family_address = $familyid2address[$family];
3788 $location = "$family_last_name"." home ($family_address)";
3790 else if($indiv > 0) {
3791 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
3792 $supervisor_last_name = $supervisor_name_array[0];
3793 $sql = "SELECT * FROM tc_indiv where indiv='$presidency2indiv[$presidency]'";
3794 $this->db2->query($sql,__LINE__,__FILE__);
3795 if($this->db2->next_record()) {
3796 $indiv_id = $this->db2->f('indiv_id');
3798 $sql = "SELECT * FROM tc_indiv where indiv_id='$indiv_id'";
3799 $this->db2->query($sql,__LINE__,__FILE__);
3800 if($this->db2->next_record()) {
3801 $supervisor_address = $this->db2->f('address');
3803 $location = "$supervisor_last_name"." home ($supervisor_address)";
3807 $date = $this->db->f('date');
3808 $date_array = explode("-",$date);
3809 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
3810 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
3812 $time = $this->db->f('time');
3813 $time_array = explode(":",$time);
3814 $hour = $time_array[0];
3815 $minute = $time_array[1];
3817 if($hour > 12) { $pm=1; $hour = $hour - 12; }
3818 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
3820 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3823 $table_data.= '<td align=left>';
3824 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]',$date,'','','','','',$this->cal_options);
3825 $table_data.= '</td>';
3827 // Hour & Minutes selection
3828 $table_data.= "<td align=center>";
3829 $table_data .= $this->get_time_selection_form($hour, $minute, $pm, $presidency, $appointment);
3830 $table_data.= "</td>";
3832 // individual drop down list (for PPIs)
3833 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][indiv] STYLE="font-size : 8pt">';
3834 $table_data.= '<option value=0></option>';
3835 for ($j=0; $j < count($indiv_id); $j++) {
3836 $id = $indiv_id[$j];
3837 $name = $indiv_name[$j];
3838 if($indiv_id[$j] == $indiv) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
3839 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
3841 $table_data.='</select></td>';
3843 // Family drop down list (for Visits)
3844 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family] STYLE="font-size : 8pt">';
3845 $table_data.= '<option value=0></option>';
3846 for ($j=0; $j < count($indiv_id); $j++) {
3847 $id = $family_id[$j];
3848 $name = $family_name[$j];
3849 if($family_id[$j] == $family) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
3850 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
3852 $table_data.='</select></td>';
3854 // Location text box
3855 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
3856 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="'.$location.'" STYLE="font-size : 8pt">';
3858 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3859 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3861 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3862 $this->t->set_var('tr_color',$tr_color);
3866 // Create blank appointment slot
3867 for ($b=0; $b < 4; $b++) {
3868 $appointment = $this->max_appointments + $b;
3869 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3872 $table_data.= '<td align=left>';
3873 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]','','','','','','',$this->cal_options);
3874 $table_data.= '</td>';
3877 $table_data.= "<td align=center>";
3878 $table_data .= $this->get_time_selection_form(0, 0, 0, $presidency, $appointment);
3879 $table_data.= "</td>";
3881 // individual drop down list
3882 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][indiv] STYLE="font-size : 8pt">';
3883 $table_data.= '<option value=0></option>';
3884 for ($j=0; $j < count($indiv_id); $j++) {
3885 $id = $indiv_id[$j];
3886 $name = $indiv_name[$j];
3887 $table_data.= '<option value='.$id.'>'.$name.'</option>';
3889 $table_data.='</select></td>';
3891 // Family drop down list
3892 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family] STYLE="font-size : 8pt">';
3893 $table_data.= '<option value=0></option>';
3894 for ($j=0; $j < count($indiv_id); $j++) {
3895 $id = $family_id[$j];
3896 $name = $family_name[$j];
3897 $table_data.= '<option value='.$id.'>'.$name.' Family</option>';
3899 $table_data.='</select></td>';
3901 // Location text box
3902 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
3903 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="" STYLE="font-size : 8pt">';
3905 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3906 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3908 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3909 $this->t->set_var('tr_color',$tr_color);
3912 $this->t->set_var('table_data',$table_data);
3913 $this->t->set_var('header_row',$header_row);
3914 $this->t->set_var('table_width',$table_width);
3915 $this->t->fp('list','presidency_list',True);
3919 $this->t->pfp('out','sched_t');
3920 $this->save_sessiondata();
3925 $this->t->set_file(array('email_t' => 'email.tpl'));
3926 $this->t->set_block('email_t','indiv_list','list');
3928 $action = get_var('action',array('GET','POST'));
3930 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email'));
3931 $this->t->set_var('title','Email Tool');
3933 $this->t->set_var('lang_email','Send Email');
3934 $this->t->set_var('lang_reset','Cancel');
3936 $this->t->set_var('email_member_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=member'));
3937 $this->t->set_var('email_member_link_title','Email Quorum Member');
3939 $this->t->set_var('email_quorum_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=quorum'));
3940 $this->t->set_var('email_quorum_link_title','Email Quorum');
3942 $this->t->set_var('email_reminder_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=reminder'));
3943 $this->t->set_var('email_reminder_link_title','Email Reminders');
3945 $this->t->set_var('email_edit_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=edit'));
3946 $this->t->set_var('email_edit_link_title','Edit Email Addresses');
3949 $this->t->set_var('table_width',$table_width);
3951 $this->t->pfp('out','email_t');
3952 $this->save_sessiondata();
3957 $this->t->set_file(array('admin_t' => 'admin.tpl'));
3958 $this->t->set_block('admin_t','upload','uploadhandle');
3959 $this->t->set_block('admin_t','admin','adminhandle');
3960 $this->t->set_block('admin_t','cmd','cmdhandle');
3961 $this->t->set_block('admin_t','presidency','presidencyhandle');
3963 $this->t->set_var('upload_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=upload'));
3964 $this->t->set_var('presidency_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=presidency'));
3966 $action = get_var('action',array('GET','POST'));
3968 $this->t->pfp('out','admin_t');
3970 // TODO: changed this so it picks the quorum dynamically
3971 $sql = "SELECT * FROM tc_indiv where steward='Elder' and valid=1 ORDER BY indiv ASC";
3972 $this->db->query($sql,__LINE__,__FILE__);
3974 while ($this->db->next_record())
3976 $indiv_id[$i] = $this->db->f('indiv');
3977 $indiv_name[$i] = $this->db->f('name');
3978 $indiv2name[$indiv_id[$i]] = $indiv_name[$i];
3981 array_multisort($indiv_name, $indiv_id);
3983 if($action == 'upload')
3985 $target_path = $this->upload_target_path . '/' . basename( $_FILES['uploadedfile']['name']);
3987 if(($_FILES['uploadedfile']['type'] == "application/zip") ||
3988 ($_FILES['uploadedfile']['type'] == "application/x-zip-compressed") ||
3989 ($_FILES['uploadedfile']['type'] == "application/x-zip") ||
3990 ($_FILES['uploadedfile']['type'] == "application/octet-stream")) {
3992 if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
3993 $uploadstatus = "<b><font color=red> -E- Unable to move the uploaded file to ";
3994 $uploadstatus.= "the target path (check the path and permissions) of: $target_path</font></b>";
3995 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
3996 $uploadstatus.= "Tmp Filename : " . $_FILES['uploadedfile']['tmp_name'] . "<br>";
3997 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
3998 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
3999 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
4000 $uploadstatus.= "Error : " . $_FILES['uploadedfile']['error'] . "<br>";
4001 $this->t->set_var('uploadstatus',$uploadstatus);
4002 $this->t->pfp('uploadhandle','upload',True);
4006 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
4007 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
4008 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
4009 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
4010 $this->t->set_var('uploadstatus',$uploadstatus);
4011 $this->t->pfp('uploadhandle','upload');
4012 $this->t->set_var('uploadhandle','');
4013 print "<table border=1 width=80%><tr><td>\n<pre>";
4015 # make a directory for this data to be stored in
4016 $date="data_" . date("Y_m_d");
4017 $data_dir = $this->upload_target_path . '/' . $date;
4018 print "-> Making the data directory: $date<br>\n";
4019 exec('mkdir -p ' . $data_dir . ' 2>&1', $result, $return_code);
4020 if($return_code != 0) {
4021 print implode('\n',$result) . "<br>";
4022 print "<b><font color=red>";
4023 print "-E- Unable to create the data directory. Aborting import.";
4024 print "</font></b>";
4028 # move the file uploaded into this directory
4029 print "-> Moving the uploaded file into the data dir<br>\n";
4030 exec('mv ' . $target_path . ' ' . $data_dir . '/' . ' 2>&1', $result, $return_code);
4031 if($return_code != 0) {
4032 print implode('\n',$result) . "<br>";
4033 print "<b><font color=red>";
4034 print "-E- Unable to move the uploaded file into the data dir. Aborting import.";
4035 print "</font></b>";
4039 # unzip the data into this directory
4040 print "-> Unzipping the data<br>\n";
4041 exec($this->unzip_path .' -u '. $data_dir . '/*.zip -d ' . $data_dir . ' 2>&1', $result, $return_code);
4042 if($return_code != 0) {
4043 print implode('\n',$result) . "<br>";
4044 print "<b><font color=red>";
4045 print "-E- Unable to unzip the uploaded file into the data dir: $data_dir. Aborting import.";
4046 print "</font></b>";
4049 exec('mv ' . $data_dir . '/*/* '. $data_dir . ' 2>&1', $result, $return_code);
4051 # update the data_latest link to point to this new directory
4052 print "-> Updating the latest data dir link<br>\n";
4053 $data_latest = $this->upload_target_path . '/data_latest';
4054 exec('rm ' . $data_latest. '; ln -s ' . $data_dir .' '. $data_latest .' 2>&1', $result, $return_code);
4055 if($return_code != 0) {
4056 print implode('\n',$result) . "<br>";
4057 print "<b><font color=red>";
4058 print "-E- Unable to update the data latest link. Aborting import.";
4059 print "</font></b>";
4063 # run the import perl script to encorporate it into the DB
4064 ob_start('ob_logstdout', 2);
4065 print "-> Importing the data into the database<br>\n";
4066 ob_flush(); flush(); sleep(1);
4067 $import_log = $this->upload_target_path . '/import.log';
4068 $data_log = $this->upload_target_path . '/data.log';
4069 $import_cmd = $this->script_path . '/import_ward_data ' . $data_latest . ' 2>&1 | tee ' . $import_log;
4070 $parse_cmd = $this->script_path . '/parse_ward_data -v ' . $data_latest . ' > ' . $data_log . '2>&1';
4071 #print "import_cmd: $import_cmd<br>";
4072 #print "parse_cmd: $parse_cmd<br>";
4073 ob_start('ob_logstdout', 2);
4074 passthru($import_cmd);
4075 passthru($parse_cmd);
4076 ob_flush(); flush(); sleep(1);
4078 # fix the permissions of the data dir
4079 exec('chmod -R o-rwx ' . $data_dir, $result, $return_code);
4081 $this->t->pfp('cmdhandle','cmd');
4082 print "</pre></td></tr></table>";
4084 } else if(($_FILES['uploadedfile']['type'] != "application/zip") &&
4085 ($_FILES['uploadedfile']['type'] != "application/x-zip-compressed") &&
4086 ($_FILES['uploadedfile']['type'] != "application/x-zip") &&
4087 ($_FILES['uploadedfile']['type'] != "application/octet-stream")) {
4088 $uploadstatus = "<b><font color=red>The file format must be a .zip file, please try again! </font></b>";
4089 $uploadstatus.= "<br><br><b>Detected file format: " . $_FILES['uploadedfile']['type'] . "</b>";
4090 $this->t->set_var('uploadstatus',$uploadstatus);
4091 $this->t->pfp('uploadhandle','upload',True);
4093 $uploadstatus = "<b><font color=red> There was an error (" . $_FILES['uploadedfile']['error'];
4094 $uploadstatus.= ") uploading the file, please try again! </font></b>";
4095 $this->t->set_var('uploadstatus',$uploadstatus);
4096 $this->t->pfp('uploadhandle','upload',True);
4099 else if($action == "presidency")
4101 $new_data = get_var('eqpres',array('POST'));
4102 foreach ($new_data as $entry)
4105 $email = $entry['email'];
4106 $indiv = $entry['indiv'];
4107 $name = $entry['name'];
4108 $district = $entry['district'];
4109 $president = $entry['president'];
4110 $counselor = $entry['counselor'];
4111 $secretary = $entry['secretary'];
4112 $eqpresidency = $entry['eqpresidency'];
4113 // Set the individual id to 0 for EQ Presidency tagged entry
4114 if($eqpresidency == 1) { $indiv="0"; }
4115 // Re-look up the individual name for the ID if we aren't an EQ Presidency tagged entry
4116 else { $name = $indiv2name[$indiv]; }
4117 //print "id=$id indiv=$indiv name=$name email=$email district=$district president=$president ";
4118 //print "counselor=$counselor secretary=$secretary eqpres=$eqpresidency<br>";
4120 if(($indiv > 0) || ($name != "")) {
4121 if($id < $this->max_presidency_members) {
4122 //print "Updating Existing Entry<br>";
4123 $this->db2->query("UPDATE tc_presidency set" .
4124 " indiv=" . $indiv .
4125 " ,district=" . $district .
4126 " ,name='" . $name . "'" .
4127 " ,email='" . $email . "'" .
4128 " ,president='" . $president . "'" .
4129 " ,counselor='" . $counselor . "'" .
4130 " ,secretary='" . $secretary . "'" .
4131 " ,eqpres='" . $eqpresidency . "'" .
4132 " WHERE presidency=" . $id,__LINE__,__FILE__);
4135 //print "Adding New Entry<br>";
4136 $this->db2->query("INSERT INTO tc_presidency (presidency,indiv,district,name,"
4137 . "email,president,counselor,secretary,eqpres,valid) "
4138 . "VALUES (NULL,'" . $indiv . "','" . $district . "','"
4139 . $name . "','" . $email . "','" . $president . "','"
4140 . $counselor . "','" . $secretary . "','" . $eqpres . "','1'"
4141 .")",__LINE__,__FILE__);
4144 //print "Ignoring Blank Entry<br>";
4148 // Now update the tc_district table appropriately
4150 // Delete all the previous district entries from the table
4151 $this->db->query("DELETE from tc_district where valid=1",__LINE__,__FILE__);
4152 $this->db->query("DELETE from tc_district where valid=0",__LINE__,__FILE__);
4154 // Always add a "District 0" assigned to the High Priests Group
4156 $name = "High Priests";
4159 $this->db2->query("INSERT INTO tc_district (district,name,supervisor,valid) "
4160 . "VALUES ('" . $district . "','" . $name . "','"
4161 . $indiv . "','" . $valid . "'"
4162 .")",__LINE__,__FILE__);
4165 // Requery the tc_presidency table
4166 $sql = "SELECT * FROM tc_presidency where valid=1";
4167 $this->db->query($sql,__LINE__,__FILE__);
4168 while ($this->db->next_record())
4170 // Extract the data for each presidency record
4171 $id = $this->db->f('presidency');
4172 $indiv = $this->db->f('indiv');
4173 $name = $this->db->f('name');
4174 $district = $this->db->f('district');
4175 $name = $this->db->f('name');
4178 // If we have a valid district, add it to the district table
4180 $this->db2->query("INSERT INTO tc_district (district,name,supervisor,valid) "
4181 . "VALUES ('" . $district . "','" . $name . "','"
4182 . $indiv . "','" . $valid . "'"
4183 .")",__LINE__,__FILE__);
4188 $this->t->set_var('adminhandle','');
4189 $this->t->pfp('adminhandle','admin');
4193 $this->t->set_var('adminhandle','');
4194 $this->t->pfp('adminhandle','admin');
4197 // Now save off the data needed for an EQ Presidency Table Update
4199 $sql = "SELECT * FROM tc_presidency where valid=1";
4200 $this->db->query($sql,__LINE__,__FILE__);
4202 $header_row = "<th>Individual</th><th>Email</th><th>District</th><th>President</th><th>Counselor</th><th>Secretary</th><th>Presidency</th>";
4203 while ($this->db->next_record())
4205 // Extract the data for each presidency record
4206 $id = $this->db->f('presidency');
4207 $indiv = $this->db->f('indiv');
4208 $district = $this->db->f('district');
4209 $name = $this->db->f('name');
4210 $email = $this->db->f('email');
4211 $president = $this->db->f('president');
4212 $counselor = $this->db->f('counselor');
4213 $secretary = $this->db->f('secretary');
4214 $eqpresidency = $this->db->f('eqpres');
4216 // Create the forms needed in the table
4217 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4220 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4223 if($eqpresidency == 0) {
4224 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4225 $table_data.= '<option value=0></option>';
4226 for ($j=0; $j < count($indiv_id); $j++) {
4227 $tmp_id = $indiv_id[$j];
4228 $name = $indiv_name[$j];
4229 if($indiv_id[$j] == $indiv) { $indivname = $name; $selected = 'selected="selected"'; } else { $selected = ''; }
4230 $table_data.= '<option value='.$tmp_id.' '.$selected.'>'.$name.'</option>';
4232 $table_data.='</select></td>';
4233 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="'.$indivname.'">';
4235 $table_data.= '<td align=left><input type=text size="20" name="eqpresname" value="Presidency"></td>';
4236 $table_data.= '<input type=hidden name="eqpres['.$id.'][name]" value="Presidency">';
4240 $table_data .= '<td><input type="text" size="50" name="eqpres['.$id.'][email]" value="'.$email.'"></td>';
4243 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4244 $table_data.= '<option value=0></option>';
4245 for ($j=0; $j <= $this->max_num_districts; $j++) {
4246 if($district == $j) { $selected = 'selected="selected"'; } else { $selected = ''; }
4247 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4249 $table_data.='</select></td>';
4252 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4253 if($president == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4254 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4255 $table_data.='</select></td>';
4258 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4259 if($counselor == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4260 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4261 $table_data.='</select></td>';
4264 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4265 if($secretary == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4266 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4267 $table_data.='</select></td>';
4270 $table_data.= '<td align=center><select name="eqpres['.$id.'][eqpresidency]">';
4271 if($eqpresidency == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4272 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4273 $table_data.='</select></td>';
4276 $table_data .= "</tr>\n";
4277 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4278 $this->t->set_var('tr_color',$tr_color);
4281 // Now create 1 blank row to always have a line available to add a new individual with
4282 $id = $this->max_presidency_members;
4283 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4285 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4287 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4288 $table_data.= '<option value=0></option>';
4289 for ($j=0; $j < count($indiv_id); $j++) {
4290 $tmp_id = $indiv_id[$j];
4291 $name = $indiv_name[$j];
4292 $table_data.= '<option value='.$tmp_id.'>'.$name.'</option>';
4294 $table_data.='</select></td>';
4295 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="">';
4297 $table_data.='<td><input type="text" size="50" name="eqpres['.$id.'][email]" value=""></td>';
4299 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4300 $table_data.= '<option value=0></option>';
4301 for ($j=0; $j <= $this->max_num_districts; $j++) {
4302 if($j == 0) { $selected = 'selected="selected"'; } else { $selected = ''; }
4303 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4305 $table_data.='</select></td>';
4307 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4308 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4309 $table_data.='</select></td>';
4311 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4312 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4313 $table_data.='</select></td>';
4315 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4316 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4317 $table_data.='</select></td>';
4319 $table_data.= '<td align=center><select name="eqpres['.$id.'][eqpresidency]">';
4320 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4321 $table_data.='</select></td>';
4323 $table_data .= "</tr>\n";
4324 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4325 $this->t->set_var('tr_color',$tr_color);
4327 $this->t->set_var('header_row',$header_row);
4328 $this->t->set_var('table_data',$table_data);
4329 $this->t->pfp('presidencyhandle','presidency',True);
4331 $this->save_sessiondata();
4334 function email_appt($appointment)
4336 //print "Emailing notification of appointment: $appointment <br>";
4338 $sql = "SELECT * FROM tc_appointment where appointment='$appointment'";
4339 $this->db->query($sql,__LINE__,__FILE__);
4341 while ($this->db->next_record())
4343 $appointment = $this->db->f('appointment');
4344 $presidency = $this->db->f('presidency');
4345 $location = $this->db->f('location');
4348 $indiv = $this->db->f('indiv');
4350 $family = $this->db->f('family');
4354 $uid = $this->db->f('uid');
4356 // Extract the year, month, day, hours, minutes, seconds from the appointment time
4357 $appt_date = $this->db->f('date');
4358 $date_array = explode("-",$appt_date);
4359 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
4360 $appt_time = $this->db->f('time');
4361 $time_array = explode(":",$appt_time);
4362 $hour = $time_array[0]; $minute = $time_array[1]; $seconds = $time_array[2];
4364 // Format the appointment time into an iCal UTC equivalent
4365 $dtstamp = gmdate("Ymd"."\T"."His"."\Z");
4366 $dtstart = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds,$month,$day,$year));
4367 $dtstartstr = date("l, F d, o g:i A", mktime($hour,$minute,$seconds,$month,$day,$year));
4369 $sql = "SELECT * FROM tc_presidency where presidency='$presidency'";
4370 $this->db2->query($sql,__LINE__,__FILE__);
4371 if($this->db2->next_record()) {
4372 $email = $this->db2->f('email');
4373 $interviewer = $this->db2->f('name');
4376 // Set the email address of the interviewer
4380 $sql = "SELECT * FROM tc_indiv where indiv='$indiv'";
4381 $this->db2->query($sql,__LINE__,__FILE__);
4382 if($this->db2->next_record()) {
4383 $indiv_name = $this->db2->f('name');
4384 $phone = $this->db2->f('phone');
4385 $appt_name = $indiv_name . " Interview";
4386 $duration = $this->default_ppi_appt_duration * 60;
4391 $sql = "SELECT * FROM tc_family where family='$family'";
4392 $this->db2->query($sql,__LINE__,__FILE__);
4393 if($this->db2->next_record()) {
4394 $family_name = $this->db2->f('name');
4395 $phone = $this->db2->f('phone');
4396 $indiv_id = $this->db2->f('indiv_id');
4397 $appt_name = $family_name . " Family Visit";
4398 $sql = "SELECT * FROM tc_indiv where indiv='$indiv_id'";
4399 $this->db3->query($sql,__LINE__,__FILE__);
4400 if($this->db3->next_record()) {
4401 $phone = $this->db3->f('phone');
4403 $duration = $this->default_visit_appt_duration * 60;
4407 $dtend = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4408 $dtendstr = date("g:i A", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4409 $date = $dtstartstr . "-" . $dtendstr;
4410 $description = "$appt_name : $phone";
4412 if(($uid == 0) && ($appt_name != "")) {
4413 // Create a new calendar item for this appointment, since this must be the first time we
4414 // are sending it out.
4415 print "Sent new appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4416 $uid = rand() . rand(); // Generate a random identifier for this appointment
4417 $subject = "Created: $appt_name";
4419 $this->db->query("UPDATE tc_appointment set" .
4421 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4423 $action = "PUBLISH";
4424 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4425 $dtend, $date, $location, $appt_name, $description, $uid);
4427 } else if(($uid != 0) && ($appt_name == "")) {
4428 // Remove the calendar item for this appointment since it has already been sent
4429 // and there is no name we have changed it to.
4430 print "Sent deleted appointment to " . $interviewer . " at " . $email . " for " . $appt_date . " " . $appt_time . "<br>";
4431 $subject = "Canceled: $appt_date $appt_time";
4433 $this->db->query("UPDATE tc_appointment set" .
4435 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4438 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4439 $dtend, $date, $location, $subject, $subject, $uid);
4441 } else if($uid != 0) {
4442 // Update the existing appointment since we have changed it
4443 print "Sent updated appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4445 $subject = "Canceled: $appt_date $appt_time";
4447 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4448 $dtend, $date, $location, $subject, $subject, $uid);
4450 $uid = rand() . rand(); // Generate a random identifier for this appointment
4451 $this->db->query("UPDATE tc_appointment set" .
4453 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4455 $subject = "Updated: $appt_name";
4456 $action = "PUBLISH";
4457 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4458 $dtend, $date, $location, $appt_name, $description, $uid);
4466 function send_ical_appt($action, $to, $from, $subject, $dtstamp, $dtstart, $dtend, $date, $location, $summary, $description, $uid)
4468 // Initialize our local variables
4469 $boundary = "=MIME_APPOINTMENT_BOUNDARY";
4473 // Form the headers for the email message
4474 $headers.="X-Mailer: PHP/" . phpversion() . "\n";
4475 $headers.="Mime-Version: 1.0\n";
4476 $headers.="Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
4477 $headers.="Content-Disposition: inline\n";
4478 $headers.="Reply-To: $from\n";
4479 $headers.="From: $from\n";
4481 // Print the plaintext version of the appointment
4482 $message.="--$boundary\n";
4483 $message.="Content-Type: text/plain; charset=us-ascii\n";
4484 $message.="Content-Disposition: inline\n";
4486 $message.="What: $description\n";
4487 $message.="When: $date\n";
4488 $message.="Where: $location\n";
4491 // Print the .ics attachment version of the appointment
4492 $message.="--$boundary\n";
4493 $message.="Content-Type: text/calendar; charset=us-ascii\n";
4494 $message.="Content-Disposition: attachment; filename=\"appointment.ics\"\n";
4496 $message.="BEGIN:VCALENDAR" . "\n";
4497 $message.="VERSION:2.0" . "\n";
4498 $message.="PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN" . "\n";
4499 $message.="METHOD:$action" . "\n";
4500 $message.="BEGIN:VEVENT" . "\n";
4501 $message.="ORGANIZER:MAILTO:$from". "\n";
4502 $message.="DTSTAMP:$dtstamp" . "\n";
4503 $message.="DTSTART:$dtstart" . "\n";
4504 $message.="DTEND:$dtend" . "\n";
4505 $message.="SUMMARY:$summary" . "\n";
4506 $message.="DESCRIPTION:$description" . "\n";
4507 $message.="LOCATION:$location" . "\n";
4508 $message.="UID:$uid" ."\n";
4509 $message.="TRANSP:OPAQUE" . "\n";
4510 $message.="SEQUENCE:0" . "\n";
4511 $message.="CLASS:PUBLIC" . "\n";
4512 $message.="END:VEVENT" . "\n";
4513 $message.="END:VCALENDAR" . "\n";
4515 // Complete the message
4516 $message.="--$boundary\n";
4519 mail($to, $subject, $message, $headers);
4523 function get_time_selection_form($hour, $minute, $pm, $presidency, $appointment)
4528 if($hour == 0) { $blank = 1; }
4530 if($this->time_drop_down_lists == 1) {
4531 // Create drop down lists to get the time
4532 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][hour]>';
4533 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4534 foreach(range(1,12) as $num) {
4535 if($hour == $num) { $selected = 'selected="selected"'; } else { $selected = ''; }
4536 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4538 $form_data.= '</select>';
4539 $form_data.= ' : ';
4540 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][minute]>';
4541 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4544 if($num < 10) { $num = "0" . "$num"; }
4545 if($minute == $num) { $selected = 'selected="selected"'; } else { $selected = ''; }
4546 if($blank == 1) { $selected = ""; }
4547 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4548 $num = $num + $this->time_drop_down_list_inc;
4550 $form_data.= '</select>';
4552 // Use free form text fields to get the time
4553 if($blank == 1) { $hour = ""; $minute = ""; $ampm = ""; }
4554 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][hour] value='.$hour.'>';
4556 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][minute] value='.$minute.'>';
4557 $form_data.= ' ';
4559 // Always use a drop-down select form for am/pm
4560 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][pm]>';
4562 if($pm == 0) { $form_data.= '<option value=0 selected>am</option>'; $form_data.= '<option value=1>pm</option>'; }
4563 if($pm == 1) { $form_data.= '<option value=0>am</option>'; $form_data.= '<option value=1 selected>pm</option>'; }
4565 $form_data.= '<option value=""></option>';
4566 $form_data.= '<option value=0>am</option>';
4567 $form_data.= '<option value=1>pm</option>';
4569 $form_data.= '</select>';