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()
116 function display_app_header()
118 $this->t->set_file(array('tc_header' => 'header.tpl'));
120 if (isset($phpgw_info['user']['preferences']['tc']['tc_font']))
122 $font = $phpgw_info['user']['preferences']['tc']['tc_font'];
129 $this->t->set_var('bg_color',$phpgw_info['theme']['th_bg']);
130 $this->t->set_var('font',$font);
131 $link_data['menuaction'] = 'tc.tc.ht_view';
132 $this->t->set_var('link_hometeaching',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
133 $this->t->set_var('lang_hometeaching','HomeTeaching');
134 $link_data['menuaction'] = 'tc.tc.act_list';
135 $this->t->set_var('link_activity',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
136 $this->t->set_var('lang_activity','Activities');
137 $link_data['menuaction'] = 'tc.tc.willing_view';
138 $this->t->set_var('link_willing',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
139 $this->t->set_var('lang_willing','Willingness');
140 $link_data['menuaction'] = 'tc.tc.assign_view';
141 $this->t->set_var('link_assignment',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
142 $this->t->set_var('lang_assignment','Assignments');
143 $link_data['menuaction'] = 'tc.tc.par_view';
144 $this->t->set_var('link_participation',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
145 $this->t->set_var('lang_participation','Participation');
146 $link_data['menuaction'] = 'tc.tc.ppi_view';
147 $this->t->set_var('link_ppi',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
148 $this->t->set_var('lang_ppi','PPIs');
149 $link_data['menuaction'] = 'tc.tc.int_view';
150 $this->t->set_var('link_int',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
151 $this->t->set_var('lang_int','Interviews');
152 $link_data['menuaction'] = 'tc.tc.vis_view';
153 $this->t->set_var('link_visit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
154 $this->t->set_var('lang_visit','Visits');
155 $link_data['menuaction'] = 'tc.tc.att_view';
156 $this->t->set_var('link_attendance',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
157 $this->t->set_var('lang_attendance','Attendance');
158 $link_data['menuaction'] = 'tc.tc.dir_view';
159 $this->t->set_var('link_dir',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
160 $this->t->set_var('lang_dir','Directory');
161 $link_data['menuaction'] = 'tc.tc.org_view';
162 $this->t->set_var('link_org',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
163 $this->t->set_var('lang_org','Callings');
164 $link_data['menuaction'] = 'tc.tc.admin';
165 $this->t->set_var('link_admin',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
166 $this->t->set_var('lang_admin','Admin');
167 $link_data['menuaction'] = 'tc.tc.schedule';
168 $this->t->set_var('link_schedule',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
169 $this->t->set_var('lang_schedule','Scheduling');
170 $link_data['menuaction'] = 'tc.tc.email';
171 $this->t->set_var('link_email',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
172 $this->t->set_var('lang_email','Email');
174 $this->t->pparse('out','tc_header');
179 $this->t->set_file(array('ht_view_t' => 'ht_view.tpl'));
180 $this->t->set_block('ht_view_t','district_list','list');
182 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
183 $num_months = get_var('num_months',array('GET','POST'));
184 if($num_months == '') { $num_months = $this->default_ht_num_months; }
185 $this->t->set_var('num_months',$num_months);
186 $this->t->set_var('lang_filter','Filter');
187 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
188 else { $this->t->set_var('lang_num_months','Months of History'); }
190 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
191 $this->t->set_var('title','Hometeaching');
193 $sql = "SELECT * FROM tc_district where valid=1 ORDER BY district ASC";
194 $this->db->query($sql,__LINE__,__FILE__);
196 while ($this->db->next_record()) {
197 $districts[$i]['district'] = $this->db->f('district');
198 $districts[$i]['name'] = $this->db->f('name');
199 $districts[$i]['supervisor'] = $this->db->f('supervisor');
203 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
204 $this->db->query($sql,__LINE__,__FILE__);
206 while ($this->db->next_record()) {
207 $individual[$i] = $this->db->f('individual');
208 $indiv_name[$i] = $this->db->f('name');
209 $indiv_phone[$individual[$i]] = $this->db->f('phone');
212 array_multisort($indiv_name, $individual);
214 // Make an array mapping individuals to indiv_names
215 for($i=0; $i < count($individual); $i++) {
216 $id = $individual[$i];
217 $indivs[$id] = $indiv_name[$i];
220 $this->nextmatchs->template_alternate_row_color(&$this->t);
221 for($m=$num_months; $m >= 0; $m--) { $total_families[$m]=0; }
222 for ($i=0; $i < count($districts); $i++) {
223 $this->t->set_var('district_number',$districts[$i]['district']);
224 $this->t->set_var('district_name',$districts[$i]['name']);
225 $supervisor = $districts[$i]['supervisor'];
227 // Select all the unique companionship numbers for this district
228 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$i]['district'];
229 $this->db->query($sql,__LINE__,__FILE__);
230 $j=0; $unique_companionships = '';
231 while ($this->db->next_record()) {
232 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
236 $comp_width=450; $visit_width=25; $table_width=$comp_width + $num_months*$visit_width;
237 $table_data=""; $num_companionships = 0;
238 for($m=$num_months; $m >= 0; $m--) {
242 for ($j=0; $j < count($unique_companionships); $j++) {
243 $companion_table_entry = "";
244 // Select all the companions in each companionship
245 $sql = "SELECT * FROM tc_companionship where valid=1 and ".
246 "companionship=". $unique_companionships[$j]['companionship'];
247 $this->db->query($sql,__LINE__,__FILE__);
249 while ($this->db->next_record()) {
250 // Get this companions information
251 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
252 $companionship = $this->db->f('companionship');
253 $individual = $this->db->f('individual');
254 $name = $indivs[$individual];
255 $phone = $indiv_phone[$individual];
256 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
258 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
260 // Get the names of the families assigned this home teaching companionship
261 $sql = "SELECT * from tc_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
262 $sql = $sql . " ORDER BY name ASC";
263 $this->db->query($sql,__LINE__,__FILE__);
265 while ($this->db->next_record()) {
266 $family_name = $this->db->f('name');
267 $family_id = $this->db->f('family');
268 $this->nextmatchs->template_alternate_row_color(&$this->t);
269 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
270 // Find out how many times Visits were performed by this companionship
271 // in the past $num_months for this Family
272 $header_row="<th width=$comp_width><font size=-2>Families</th>";
273 for($m=$num_months; $m >= 0; $m--) {
274 $month = $this->current_month - $m;
275 $year = $this->current_year;
276 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
277 if($month < 10) { $month = "0"."$month"; }
278 $month_start = "$year"."-"."$month"."-"."01";
279 $month_end = "$year"."-"."$month"."-"."31";
280 $month = "$month"."/"."$year";
282 //print "m: $m month: $month year: $year month_start: $month_start month_end: $month_end<br>";
283 // Add this to the query to filter on only visits made by this companionship:
284 // " AND companionship=" . $unique_companionships[$j]['companionship'].
286 // First check to see if the currently assigned companionship has visited them
287 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
288 " AND companionship=".$unique_companionships[$j]['companionship'].
289 " AND family=". $family_id;
290 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
291 if($this->db2->num_rows($query_id) == 0) {
292 // We did not find any visits made by the currently assigned companionship,
293 // look for visits made by any other companionship other than 0. (0 == Presidency Visit)
294 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
295 " AND companionship!=0".
296 " AND family=". $family_id;
297 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
299 $this->db2->query($sql,__LINE__,__FILE__);
300 $link_data['menuaction'] = 'tc.tc.ht_update';
301 $link_data['date'] = $month_start;
302 $link_data['month_start'] = $month_start;
303 $link_data['month_end'] = $month_end;
304 $link_data['month'] = $month;
305 $link_data['district'] = $districts[$i]['district'];
306 $link_data['district_name'] = $districts[$i]['name'];
307 $link_data['action'] = 'view';
308 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
309 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
310 if(!$total_visits[$m]) { $total_visits[$m] = 0; }
311 if($this->db2->next_record()) {
312 if($this->db2->f('visited') == 'y') {
313 $visits[$m]++; $total_visits[$m]++;
314 $num_families[$m]++; $total_families[$m]++;
315 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/checkmark.gif"></a></td>';
316 } else if($this->db2->f('visited') == 'n') {
317 $num_families[$m]++; $total_families[$m]++;
318 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/x.gif"></a></td>';
320 //$visits[$m]++; $total_visits[$m]++;
321 $table_data .= "<td> </td>";
324 //$visits[$m]++; $total_visits[$m]++;
325 $table_data .= "<td> </td>";
328 $table_data .= "</tr>";
331 $table_data .= "<tr><td colspan=20></td></tr>";
333 $table_data .= "<tr><td colspan=20><hr></td></tr>";
334 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
336 for($m=$num_months; $m >=0; $m--) {
337 if($num_families[$m] > 0) {
338 $percent = ceil(($visits[$m] / $num_families[$m])*100);
342 $stat_data .= "<td align=center><font size=-2><b>$visits[$m] / $num_families[$m]<br>$percent%</font></b></td>";
344 $stat_data .= "</tr>";
346 $this->t->set_var('table_width',$table_width);
347 $this->t->set_var('header_row',$header_row);
348 $this->t->set_var('table_data',$table_data);
349 $this->t->set_var('stat_data',$stat_data);
350 $this->t->fp('list','district_list',True);
353 $totals = "<tr><td><b><font size=-2>Total Families Hometaught:<br>Total Hometeaching Percentage:</font></b></td>";
354 for($m=$num_months; $m >=0; $m--) {
355 if($total_families[$m] > 0) {
356 $percent = ceil(($total_visits[$m] / $total_families[$m])*100);
360 $totals .= "<td align=center><font size=-2><b>$total_visits[$m] / $total_families[$m]<br>$percent%</font></b></td>";
364 $this->t->set_var('totals',$totals);
366 $this->t->pfp('out','ht_view_t');
367 $this->save_sessiondata();
373 $this->t->set_file(array('ht_update_t' => 'ht_update.tpl'));
374 $this->t->set_block('ht_update_t','district_list','list');
375 $this->t->set_block('ht_update_t','save','savehandle');
377 $district = get_var('district',array('GET','POST'));
378 $district_name = get_var('district_name',array('GET','POST'));
379 $date = get_var('date',array('GET','POST'));
380 $month = get_var('month',array('GET','POST'));
381 $month_start = get_var('month_start',array('GET','POST'));
382 $month_end = get_var('month_end',array('GET','POST'));
383 $action = get_var('action',array('GET','POST'));
385 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
386 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_update&action=save'));
387 $this->t->set_var('lang_done','Cancel');
388 $this->t->set_var('district_name',$district_name);
389 $this->t->set_var('district_number',$district);
390 $this->t->set_var('title','Hometeaching Update ' . $month);
391 $this->t->set_var('date',$date);
393 if($action == 'save') {
394 // Get a list of all the companionships in this district
395 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $district;
396 $this->db->query($sql,__LINE__,__FILE__);
397 $j=0; $unique_companionships = '';
398 while ($this->db->next_record()) {
399 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
402 for ($j=0; $j < count($unique_companionships); $j++) {
403 //$comp=$unique_companionships[$j]['companionship'];
404 //print "deleting from tc_visit where companionship=$comp and date=$date and district=$district<br>";
405 // Delete all the visits that have taken place for all families for this companionsthip for this month
406 $this->db->query("DELETE from tc_visit where companionship=" . $unique_companionships[$j]['companionship'] .
407 " AND " . "date='" . $date . "'",__LINE__,__FILE__);
410 // Now, add the visits that are checked for this month
411 $new_data = get_var('family_visited',array('POST'));
412 foreach ($new_data as $family) {
413 foreach ($family as $data) {
414 //print "family_visited: $data <br>";
415 $data_array = explode("/",$data);
416 $family_id = $data_array[0];
417 $companionship = $data_array[1];
418 $date = $data_array[2];
419 $visited = $data_array[3];
420 if($visited == "") { $visited = $data_array[4]; }
421 //print "family_id: $family_id companionship: $companionship date: $date visited: $visited<br>";
422 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes,visited) " .
423 "VALUES (" . $family_id .",". $companionship .",'". $date ."','','". $visited ."')",__LINE__,__FILE__);
430 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
431 $this->db->query($sql,__LINE__,__FILE__);
433 while ($this->db->next_record()) {
434 $individual[$i] = $this->db->f('individual');
435 $indiv_name[$i] = $this->db->f('name');
436 $indiv_phone[$individual[$i]] = $this->db->f('phone');
439 array_multisort($indiv_name, $individual);
441 // Make an array mapping individuals to indiv_names
442 for($i=0; $i < count($individual); $i++) {
443 $id = $individual[$i];
444 $indivs[$id] = $indiv_name[$i];
447 // Select all the unique companionship numbers for this district
448 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $district;
449 $this->db->query($sql,__LINE__,__FILE__);
450 $j=0; $unique_companionships = '';
451 while ($this->db->next_record()) {
452 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
456 $comp_width=300; $visit_width=25; $table_width=$comp_width + $visit_width;
457 $table_data=""; $num_companionships = 0; $num_families = 0; $visits=0;
458 for ($j=0; $j < count($unique_companionships); $j++) {
459 $companion_table_entry = "";
460 // Select all the companions in each companionship
461 $sql = "SELECT * FROM tc_companionship where valid=1 and ".
462 "companionship=". $unique_companionships[$j]['companionship'];
463 $this->db->query($sql,__LINE__,__FILE__);
465 while ($this->db->next_record()) {
466 // Get this companions information
467 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
468 $companionship = $this->db->f('companionship');
469 $individual = $this->db->f('individual');
470 $name = $indivs[$individual];
471 $phone = $indiv_phone[$individual];
472 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
474 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
476 // Get the names of the families assigned this home teaching companionship
477 $sql = "SELECT * from tc_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
478 $sql = $sql . " ORDER BY name ASC";
479 $this->db->query($sql,__LINE__,__FILE__);
480 while ($this->db->next_record()) {
481 $family_name = $this->db->f('name');
482 $family_id = $this->db->f('family');
483 $this->nextmatchs->template_alternate_row_color(&$this->t);
484 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
486 $header_row="<th width=$comp_width><font size=-2>Families</th>";
488 // First check to see if the currently assigned companionship has visited them
489 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
490 " AND companionship=".$unique_companionships[$j]['companionship'].
491 " AND family=". $family_id;
492 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
493 if($this->db2->num_rows($query_id) == 0) {
494 // We did not find any visits made by the currently assigned companionship,
495 // look for visits made by any other companionship other than 0. (0 == Presidency Visit)
496 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
497 " AND companionship!=0".
498 " AND family=". $family_id;
499 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
502 $value = $family_id . "/" . $unique_companionships[$j]['companionship'] . "/" . $date;
503 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
504 if(!$total_visits) { $total_visits = 0; }
505 if($this->db2->next_record()) {
506 if($this->db2->f('visited') == 'y') {
507 $visits++; $total_visits++; $num_families++;
508 $table_data .= '<td width=100 align=center>';
509 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y" checked>Y';
510 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
511 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/"> ';
512 $table_data .= '</td>';
513 } else if($this->db2->f('visited') == 'n') {
515 $table_data .= '<td width=100 align=center>';
516 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
517 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n" checked>N';
518 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/">';
519 $table_data .= '</td>';
521 $table_data .= '<td width=100 align=center>';
522 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
523 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
524 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
525 $table_data .= '</td>';
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">N';
533 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
534 $table_data .= '</td>';
537 $table_data .= "</tr>";
538 $table_data .= "<tr><td colspan=20></td></tr>";
540 $table_data .= "<tr><td colspan=20><hr></td></tr>";
541 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
543 $percent = ceil(($visits / $num_families)*100);
544 $stat_data .= "<td align=center><font size=-2><b>$visits / $num_families<br>$percent%</font></b></td>";
545 $stat_data .= "</tr>";
547 $this->t->set_var('table_width',$table_width);
548 $this->t->set_var('header_row',$header_row);
549 $this->t->set_var('table_data',$table_data);
550 $this->t->set_var('stat_data',$stat_data);
551 $this->t->fp('list','district_list',True);
553 $this->t->set_var('lang_reset','Clear Form');
554 $this->t->set_var('lang_save','Save Changes');
555 $this->t->set_var('savehandle','');
557 $this->t->pfp('out','ht_update_t');
558 $this->t->pfp('addhandle','save');
560 $this->save_sessiondata();
565 $this->t->set_file(array('act_list_t' => 'act_list.tpl'));
566 $this->t->set_block('act_list_t','act_list','list');
568 $this->t->set_var('lang_name','Assignment');
569 $this->t->set_var('lang_date','Date');
570 $this->t->set_var('lang_notes','Description');
572 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
573 $this->db->query($sql,__LINE__,__FILE__);
574 $total_records = $this->db->num_rows();
577 while ($this->db->next_record()) {
578 $activity_list[$i]['activity'] = $this->db->f('activity');
579 $activity_list[$i]['assignment'] = $this->db->f('assignment');
580 $activity_list[$i]['date'] = $this->db->f('date');
581 $activity_list[$i]['notes'] = $this->db->f('notes');
583 $sql = "SELECT * FROM tc_assignment WHERE assignment='" . $activity_list[$i]['assignment'] . "'";
584 $this->db2->query($sql,__LINE__,__FILE__);
585 if($this->db2->next_record()) {
586 $activity_list[$i]['name'] = $this->db2->f('name');
587 $activity_list[$i]['abbreviation'] = $this->db2->f('abbreviation');
592 for ($i=0; $i < count($activity_list); $i++) {
593 $this->nextmatchs->template_alternate_row_color(&$this->t);
594 $this->t->set_var('name',$activity_list[$i]['name']);
595 $this->t->set_var('date',$activity_list[$i]['date']);
596 $activity_notes = $activity_list[$i]['notes'];
597 if(strlen($activity_notes) > 40) { $activity_notes = substr($activity_notes,0,40) . "..."; }
598 $this->t->set_var('notes',$activity_notes);
600 $link_data['menuaction'] = 'tc.tc.act_view';
601 $link_data['activity'] = $activity_list[$i]['activity'];
602 $link_data['action'] = 'view';
603 $this->t->set_var('view',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
604 $this->t->set_var('lang_view','View');
606 $link_data['menuaction'] = 'tc.tc.act_update';
607 $link_data['activity'] = $activity_list[$i]['activity'];
608 $link_data['action'] = 'edit';
609 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
610 $this->t->set_var('lang_edit','Edit');
612 $this->t->fp('list','act_list',True);
615 $link_data['menuaction'] = 'tc.tc.act_update';
616 $link_data['activity'] = '0';
617 $link_data['action'] = 'add';
618 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/tc/index.php',$link_data) .
619 '"><input type="submit" name="Add" value="' . 'Add Activity' .'"></font></form>');
621 $this->t->pfp('out','act_list_t');
622 $this->save_sessiondata();
627 $this->t->set_file(array('act_view_t' => 'act_view.tpl'));
628 $this->t->set_block('act_view_t','part_list','list');
630 $sql = "SELECT * FROM tc_activity WHERE activity=" . intval(get_var('activity',array('GET','POST')));
631 $this->db->query($sql,__LINE__,__FILE__);
632 $this->db->next_record();
633 $this->t->set_var('assignment', $this->db->f('assignment'));
634 $this->t->set_var('date', $this->db->f('date'));
635 $this->t->set_var('notes', $this->db->f('notes'));
637 $sql = "SELECT * FROM tc_assignment WHERE assignment='" . $this->db->f('assignment') . "'";
638 $this->db2->query($sql,__LINE__,__FILE__);
639 if($this->db2->next_record()) {
640 $this->t->set_var('name', $this->db2->f('name'));
641 $this->t->set_var('abbreviation', $this->db2->f('abbreviation'));
643 $this->t->set_var('lang_name','Assignment');
644 $this->t->set_var('lang_date','Date');
645 $this->t->set_var('lang_notes','Description');
646 $this->t->set_var('lang_done','Done');
647 $this->t->set_var('lang_action','View');
649 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
650 $this->t->set_var('tr_color',$tr_color);
652 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_list'));
654 $link_data['menuaction'] = 'tc.tc.act_update';
655 $link_data['activity'] = get_var('activity',array('GET','POST'));
656 $link_data['action'] = 'edit';
657 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
658 $this->t->set_var('lang_edit','Edit');
659 $this->t->set_var('cal_date',$this->db->f('date'));
661 // Now find out which indivs participated in this activity
662 $sql = "SELECT * FROM tc_participation WHERE activity=" . intval(get_var('activity',array('GET','POST')));
663 $this->db->query($sql,__LINE__,__FILE__);
664 $total_records = $this->db->num_rows();
667 while ($this->db->next_record()) {
668 $part_list[$i]['individual'] = $this->db->f('individual');
672 for ($i=0; $i < count($part_list); $i++) {
673 $sql = "SELECT * FROM tc_individual WHERE individual=" . $part_list[$i]['individual'];
674 $this->db->query($sql,__LINE__,__FILE__);
675 $this->db->next_record();
676 $names[$i] = $this->db->f('name');
680 for ($i=0; $i < count($names); $i++) {
681 //$this->nextmatchs->template_alternate_row_color(&$this->t);
682 $this->t->set_var('indiv_name',$names[$i]);
683 if(($i+1) % 3 == 0) {
684 $this->t->set_var('table_sep',"</td></tr><tr>");
686 $this->t->set_var('table_sep',"</td>");
688 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
689 $this->t->fp('list','part_list',True);
692 $this->t->pfp('out','act_view_t');
693 $this->save_sessiondata();
696 function act_update()
698 $this->t->set_file(array('form' => 'act_update.tpl'));
699 $this->t->set_block('form','individual_list','list');
700 $this->t->set_block('form','add','addhandle');
701 $this->t->set_block('form','edit','edithandle');
702 $this->t->set_var('lang_done','Done');
704 $action = get_var('action',array('GET','POST'));
705 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_list'));
706 $activity['activity'] = intval(get_var('activity',array('GET','POST')));
708 if($action == 'save') {
709 $activity['assignment'] = get_var('assignment',array('POST'));
710 $activity['date'] = get_var('date',array('POST'));
711 $activity['notes']= get_var('notes',array('POST'));
712 $this->db->query("UPDATE tc_activity set " .
713 " assignment='" . $activity['assignment'] .
714 "', date='" . $activity['date'] . "'" .
715 ", notes='" . $activity['notes'] . "'" .
716 " WHERE activity=" . $activity['activity'],__LINE__,__FILE__);
718 // Delete all the individuals who have particiapted in this activity
719 $this->db->query("DELETE from tc_participation where activity=".$activity['activity'],__LINE__,__FILE__);
721 // Re-add the individuals who are checked as having participated in this activity
722 $indivs = get_var('individual_name',array('POST'));
723 if(is_array($indivs)) { // Only do the foreach loop if we have a valid array of indivs to work with
724 foreach ($indivs as $indiv) {
725 $this->db->query("INSERT INTO tc_participation (individual,activity) " .
726 "VALUES (" . $individual . ",". $activity['activity'] . ")",__LINE__,__FILE__);
734 if($action == 'insert') {
735 $activity['assignment'] = get_var('assignment',array('POST'));
736 $activity['date'] = get_var('date',array('POST'));
737 $activity['notes']= get_var('notes',array('POST'));
738 $this->db->query("INSERT INTO tc_activity (assignment,date,notes) " .
739 "VALUES ('" . $activity['assignment'] . "','" .
740 $activity['date'] . "','" . $activity['notes'] . "')",__LINE__,__FILE__);
742 $sql = "SELECT * FROM tc_activity WHERE assignment='".$activity['assignment']."' " .
743 " AND date='".$activity['date']."' AND notes='".$activity['notes']."'";
744 $this->db->query($sql,__LINE__,__FILE__);
745 if($this->db->next_record()) {
746 //print "activity: " . $this->db->f('activity') . "<br>";
747 $activity['activity'] = $this->db->f('activity');
750 $indivs = get_var('individual_name',array('POST'));
751 foreach ($indivs as $indiv)
753 $this->db->query("INSERT INTO tc_participation (individual,activity) " .
754 "VALUES (" . $individual . ",". $activity['activity'] . ")",__LINE__,__FILE__);
761 if($action == 'add') {
762 $activity['activity'] = 0;
763 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
764 $this->t->set_var('assignment','');
765 $this->t->set_var('date','');
766 $this->t->set_var('notes','');
767 $this->t->set_var('lang_done','Cancel');
768 $this->t->set_var('lang_action','Adding New Activity');
769 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_update&activity=' .
770 $activity['activity'] . '&action=' . 'insert'));
773 if($action == 'edit') {
774 $sql = "SELECT * FROM tc_activity WHERE activity=" . $activity['activity'];
775 $this->db->query($sql,__LINE__,__FILE__);
776 $this->db->next_record();
777 $this->t->set_var('cal_date',$this->jscal->input('date',$this->db->f('date'),'','','','','',$this->cal_options));
778 $this->t->set_var('assignment', $this->db->f('assignment'));
779 $assignment = $this->db->f('assignment');
780 $this->t->set_var('date', $this->db->f('date'));
781 $this->t->set_var('notes', $this->db->f('notes'));
782 $this->t->set_var('lang_done','Cancel');
783 $this->t->set_var('lang_action','Editing Activity');
784 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_update&activity=' .
785 $activity['activity'] . '&action=' . 'save'));
788 // Create the assignments drop-down list
789 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
790 $this->db->query($sql,__LINE__,__FILE__);
792 while ($this->db->next_record()) {
793 $assignments[$i]['assignment'] = $this->db->f('assignment');
794 $assignments[$i]['name'] = $this->db->f('name');
795 $assignments[$i]['abbreviation'] = $this->db->f('abbreviation');
799 $assignment_data.= '<select name=assignment>';
800 $assignment_data.= '<option value=0></option>';
801 for ($j=0; $j < count($assignments); $j++) {
802 $id = $assignments[$j]['assignment'];
803 $name = $assignments[$j]['name'];
804 if($assignments[$j]['assignment'] == $assignment) {
805 $selected[$id] = 'selected="selected"';
809 $assignment_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
811 $assignment_data.='</select>';
812 $this->t->set_var('assignment_data',$assignment_data);
814 // Create individual selection boxes
815 $sql = "SELECT * FROM tc_individual";
816 $this->db->query($sql,__LINE__,__FILE__);
818 while ($this->db->next_record()) {
819 if($this->db->f('valid') == 1 || $action != 'add') {
820 $indiv_name[$i] = $this->db->f('name');
821 $individual[$i] = $this->db->f('individual');
822 $indiv_valid[$i] = $this->db->f('valid');
826 array_multisort($indiv_name, $individual, $indiv_valid);
829 for ($i=0; $i < count($individual); $i++) {
830 //$this->nextmatchs->template_alternate_row_color(&$this->t);
831 $sql = "SELECT * FROM tc_participation where activity=". $activity['activity'] . " AND individual=" . $individual[$i];
832 $this->db->query($sql,__LINE__,__FILE__);
833 if($this->db->next_record()) {
834 $this->t->set_var('checked','checked');
837 $this->t->set_var('checked','');
840 if($checked || $indiv_valid[$i] == 1) {
841 $this->t->set_var('individual_name',$indiv_name[$i]);
842 $this->t->set_var('individual',$individual[$i]);
843 if(($j+1) % 3 == 0) {
844 $this->t->set_var('table_sep',"</td></tr><tr>");
846 $this->t->set_var('table_sep',"</td>");
848 if(($j) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
849 $this->t->fp('list','individual_list',True);
854 $this->t->set_var('lang_reset','Clear Form');
855 $this->t->set_var('lang_add','Add Activity');
856 $this->t->set_var('lang_save','Save Changes');
857 $this->t->set_var('edithandle','');
858 $this->t->set_var('addhandle','');
860 $this->t->pfp('out','form');
861 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
862 if($action == 'add') { $this->t->pfp('addhandle','add'); }
864 $this->save_sessiondata();
867 function assign_view()
869 $this->t->set_file(array('assign_view_t' => 'assign_view.tpl'));
870 $this->t->set_block('assign_view_t','assign_view','list');
872 $this->t->set_var('lang_name','Assignment Name');
873 $this->t->set_var('lang_code','Abbreviation');
875 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
876 $this->db->query($sql,__LINE__,__FILE__);
877 $total_records = $this->db->num_rows();
880 while ($this->db->next_record()) {
881 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
882 $assignment_list[$i]['name'] = $this->db->f('name');
883 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
887 for ($i=0; $i < count($assignment_list); $i++) {
888 $this->nextmatchs->template_alternate_row_color(&$this->t);
889 $this->t->set_var('name',$assignment_list[$i]['name']);
890 $this->t->set_var('abbreviation',$assignment_list[$i]['abbreviation']);
892 $link_data['menuaction'] = 'tc.tc.assign_update';
893 $link_data['assignment'] = $assignment_list[$i]['assignment'];
894 $link_data['action'] = 'edit';
895 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
896 $this->t->set_var('lang_edit','Edit');
898 $link_data['menuaction'] = 'tc.tc.assign_update';
899 $link_data['assignment'] = '0';
900 $link_data['action'] = 'add';
901 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/tc/index.php',$link_data) .
902 '"><input type="submit" name="Add" value="' . 'Add Assignment' .'"></font></form>');
904 $this->t->fp('list','assign_view',True);
907 $this->t->pfp('out','assign_view_t');
908 $this->save_sessiondata();
911 function assign_update()
913 $this->t->set_file(array('form' => 'assign_update.tpl'));
914 $this->t->set_block('form','add','addhandle');
915 $this->t->set_block('form','edit','edithandle');
916 $this->t->set_var('lang_done','Done');
918 $action = get_var('action',array('GET','POST'));
919 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_view'));
920 $assignment['assignment'] = intval(get_var('assignment',array('GET','POST')));
922 if($action == 'save') {
923 $assignment['name'] = get_var('name',array('POST'));
924 $assignment['abbreviation'] = get_var('abbreviation',array('POST'));
925 $this->db->query("UPDATE tc_assignment set " .
926 " name='" . $assignment['name'] . "'" .
927 ", abbreviation='" . $assignment['abbreviation'] . "'" .
928 " WHERE assignment=" . $assignment['assignment'],__LINE__,__FILE__);
930 $this->assign_view();
934 if($action == 'insert') {
935 $assignment['name'] = get_var('name',array('POST'));
936 $assignment['abbreviation'] = get_var('abbreviation',array('POST'));
937 $this->db->query("INSERT INTO tc_assignment (name,abbreviation) " .
938 "VALUES ('" . $assignment['name'] . "','" .
939 $assignment['abbreviation'] . "')",__LINE__,__FILE__);
940 $this->assign_view();
944 if($action == 'add') {
945 $assignment['assignment'] = 0;
946 $this->t->set_var('name','');
947 $this->t->set_var('abbreviation','');
948 $this->t->set_var('lang_done','Cancel');
949 $this->t->set_var('lang_action','Adding New Assignment');
950 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_update&assignment=' .
951 $assignment['assignment'] . '&action=' . 'insert'));
954 if($action == 'edit')
956 $sql = "SELECT * FROM tc_assignment WHERE assignment=" . $assignment['assignment'];
957 $this->db->query($sql,__LINE__,__FILE__);
958 $this->db->next_record();
959 $this->t->set_var('name', $this->db->f('name'));
960 $this->t->set_var('abbreviation', $this->db->f('abbreviation'));
961 $this->t->set_var('lang_done','Cancel');
962 $this->t->set_var('lang_action','Editing Assignment');
963 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_update&assignment=' .
964 $assignment['assignment'] . '&action=' . 'save'));
967 $this->t->set_var('lang_reset','Clear Form');
968 $this->t->set_var('lang_add','Add Assignment');
969 $this->t->set_var('lang_save','Save Changes');
970 $this->t->set_var('edithandle','');
971 $this->t->set_var('addhandle','');
973 $this->t->pfp('out','form');
974 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
975 if($action == 'add') { $this->t->pfp('addhandle','add'); }
977 $this->save_sessiondata();
982 $this->t->set_file(array('par_view_t' => 'par_view.tpl'));
983 $this->t->set_block('par_view_t','header_list','list1');
984 $this->t->set_block('par_view_t','individual_list','list2');
986 // TODO: changed this so it picks the quorum dynamically
987 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1";
988 $this->db->query($sql,__LINE__,__FILE__);
990 while ($this->db->next_record()) {
991 $individual_name[$i] = $this->db->f('name');
992 $individual[$i] = $this->db->f('individual');
995 array_multisort($individual_name, $individual);
997 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
998 $this->db->query($sql,__LINE__,__FILE__);
999 $total_records = $this->db->num_rows();
1002 while ($this->db->next_record()) {
1003 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1004 $activity_list[$i]['date'] = $this->db->f('date');
1005 $activity_list[$i]['activity'] = $this->db->f('activity');
1009 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1010 $this->db->query($sql,__LINE__,__FILE__);
1012 while($this->db->next_record()) {
1013 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1014 $assignment_list[$i]['name'] = $this->db->f('name');
1015 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1019 $individual_width=300; $part_width=25; $assignment_width=50;
1020 $total_width=$individual_width+$part_width;
1021 for ($i=0; $i < count($assignment_list); $i++) {
1022 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1023 $this->t->set_var('assignment_abbreviation',$assignment_list[$i]['abbreviation']);
1024 $this->t->fp('list1','header_list',True);
1025 $total_width += $assignment_width;
1028 for ($i=0; $i < count($individual); $i++) {
1029 $participated=0; $part_table = '';
1030 $this->nextmatchs->template_alternate_row_color(&$this->t);
1031 $this->t->set_var('individual_name',$individual_name[$i]);
1032 for ($j=0; $j < count($assignment_list); $j++) {
1033 $date = "0000-00-00"; $checkmark=0; $num_matches=0;
1034 for ($k=0; $k < count($activity_list); $k++) {
1035 if($assignment_list[$j]['assignment'] == $activity_list[$k]['assignment']) {
1036 $sql = "SELECT * FROM tc_participation where " .
1037 " activity=" . $activity_list[$k]['activity'] .
1038 " AND individual=" . $individual[$i];
1039 $this->db->query($sql,__LINE__,__FILE__);
1040 while($this->db->next_record()) {
1041 if($activity_list[$k]['date'] > $date) {
1042 $date = $activity_list[$k]['date'];
1051 $part_table .= '<td align=center><img src="images/checkmark.gif">';
1052 $part_table .= '<font size=-2>'.$num_matches.'</font><br>';
1053 $part_table .= '<font size=-2>'.$date.'</font></td>';
1055 $part_table .= '<td> </td>';
1059 $part_table .= '<td align=center><img src="images/checkmark.gif">'.$participated.'</td>';
1061 $part_table .= '<td> </td>';
1063 $this->t->set_var('part_table',$part_table);
1064 $this->t->fp('list2','individual_list',True);
1066 $this->t->set_var('total_width',$total_width);
1067 $this->t->set_var('individual_width',$individual_width);
1068 $this->t->set_var('part_width',$part_width);
1069 $this->t->set_var('act_width',$act_width);
1070 $this->t->pfp('out','par_view_t');
1071 $this->save_sessiondata();
1074 function willing_view()
1076 $this->t->set_file(array('willing_view_t' => 'willing_view.tpl'));
1077 $this->t->set_block('willing_view_t','header_list','list1');
1078 $this->t->set_block('willing_view_t','individual_list','list2');
1080 $this->t->set_var('lang_filter','Filter');
1081 $this->t->set_var('lang_filter_unwilling','Filter out unwilling individuals:');
1083 $filter_unwilling = get_var('filter_unwilling',array('POST'));
1084 $this->t->set_var('filter_unwilling',$filter_unwilling);
1086 if($filter_unwilling == 'y' || $filter_unwilling == '') {
1087 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\" checked>Y";
1088 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\">N";
1089 $filter_input.= " ";
1091 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\">Y";
1092 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\" checked>N";
1093 $filter_input.= " ";
1095 $this->t->set_var('filter_input',$filter_input);
1097 // TODO: changed this so it picks the quorum dynamically
1098 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1";
1099 $this->db->query($sql,__LINE__,__FILE__);
1101 while ($this->db->next_record()) {
1102 $indiv_name[$i] = $this->db->f('name');
1103 $individual[$i] = $this->db->f('individual');
1104 $indiv_phone[$individual[$i]] = $this->db->f('phone');
1107 array_multisort($indiv_name, $individual);
1109 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1110 $this->db->query($sql,__LINE__,__FILE__);
1112 while($this->db->next_record()) {
1113 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1114 $assignment_list[$i]['name'] = $this->db->f('name');
1115 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1119 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
1120 $this->db->query($sql,__LINE__,__FILE__);
1121 $total_records = $this->db->num_rows();
1124 while ($this->db->next_record()) {
1125 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1126 $activity_list[$i]['date'] = $this->db->f('date');
1127 $activity_list[$i]['activity'] = $this->db->f('activity');
1131 $indiv_width=275; $willing_width=40; $assignment_width=50;
1132 $total_width=$indiv_width+$willing_width;
1134 for ($i=0; $i < count($assignment_list); $i++) {
1135 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1136 $this->t->set_var('assignment_abbreviation',$assignment_list[$i]['abbreviation']);
1137 $this->t->fp('list1','header_list',True);
1138 $total_width += $assignment_width;
1139 $total_willing[$i] = 0;
1142 for ($i=0; $i < count($individual); $i++) {
1143 $willing_table = ''; $indiv_willing=0;
1144 $this->t->set_var('individual_name',$indiv_name[$i]);
1145 $this->t->set_var('individual_phone',$indiv_phone[$individual[$i]]);
1146 $this->t->set_var('editurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_update&individual=' .
1147 $individual[$i] . '&action=' . 'edit'));
1148 for ($j=0; $j < count($assignment_list); $j++) {
1149 $found_willingness=0;
1150 $sql = "SELECT * FROM tc_willingness where " .
1151 " assignment=" . $assignment_list[$j]['assignment'] .
1152 " AND individual=" . $individual[$i];
1153 $this->db->query($sql,__LINE__,__FILE__);
1154 while($this->db->next_record()) {
1155 $found_willingness=1;
1157 $sql = "SELECT * FROM tc_activity where " .
1158 " assignment=". $assignment_list[$j]['assignment'] .
1159 " ORDER by date DESC";
1160 $this->db2->query($sql,__LINE__,__FILE__);
1161 if($this->db2->next_record()) {
1162 $activity = $this->db2->f('activity');
1163 $date = $this->db2->f('date');
1164 $sql = "SELECT * FROM tc_participation where " .
1165 " activity=" . $activity .
1166 " AND individual=". $individual[$i];
1167 $this->db3->query($sql,__LINE__,__FILE__);
1168 if($this->db3->next_record()) {
1173 if($this->db->f('willing') == 'y') {
1174 $total_willing[$j]++;
1176 $willing_table .= '<td align=center><img src="images/checkmark.gif"><br><font size=-2>'.$date_part.'</font></td></td>';
1177 } else if($this->db->f('willing') == 'n') {
1178 $willing_table .= '<td align=center><img src="images/x.gif"></td>';
1181 $willing_table .= "<td> </td>";
1184 if(!$found_willingness) {
1186 $willing_table .= "<td> </td>";
1189 if(($indiv_willing == 1) || ($filter_unwilling == 'n')) {
1190 $this->t->set_var('willing_table',$willing_table);
1191 $this->t->fp('list2','individual_list',True);
1192 $this->nextmatchs->template_alternate_row_color(&$this->t);
1196 $stat_table = '<td><b>Total Willing to Serve</b></td>';
1197 for ($j=0; $j < count($assignment_list); $j++) {
1198 $stat_table .= "<td align=center><b>".$total_willing[$j]."</b></td>";
1200 $this->t->set_var('stat_table',$stat_table);
1202 $this->t->set_var('total_width',$total_width);
1203 $this->t->set_var('individual_width',$indiv_width);
1204 $this->t->set_var('willing_width',$willing_width);
1205 $this->t->pfp('out','willing_view_t');
1206 $this->save_sessiondata();
1209 function willing_update()
1211 //print "<font color=red>Willingness Update Under Constrcution</font>";
1212 //$this->willing_view();
1215 $this->t->set_file(array('willing_update_t' => 'willing_update.tpl'));
1216 $this->t->set_block('willing_update_t','assignment_list','list');
1217 $this->t->set_block('willing_update_t','save','savehandle');
1219 $individual = get_var('individual',array('GET','POST'));
1220 $this->t->set_var('individual',$individual);
1221 $action = get_var('action',array('GET','POST'));
1223 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_view'));
1224 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_update&action=save'));
1225 $this->t->set_var('lang_done','Cancel');
1226 $this->t->set_var('title','Willingness Update ');
1228 if($action == 'save') {
1229 // Delete all the previous willingness entries for this individual
1230 $this->db->query("DELETE from tc_willingness where individual=" . $individual ,__LINE__,__FILE__);
1232 // Now, add the assignment willingness that is checked for this individual
1233 $new_data = get_var('willingness',array('POST'));
1234 foreach ($new_data as $data) {
1235 $data_array = explode("/",$data);
1236 $assignment = $data_array[0];
1237 $willing = $data_array[1];
1238 //print "individual: $individual assignment: $assignment willing: $willing<br>";
1239 $this->db->query("INSERT INTO tc_willingness (individual,assignment,willing) " .
1240 "VALUES (" . $individual .",". $assignment .",'". $willing . "')",__LINE__,__FILE__);
1242 $this->willing_view();
1246 $assignment_width=300; $willing_width=25; $table_width=$assignment_width + $willing_width;
1249 // Find out the individual's name
1250 $sql = "SELECT * FROM tc_individual WHERE individual=".$individual." AND valid=1";
1251 $this->db->query($sql,__LINE__,__FILE__);
1252 if($this->db->next_record()) {
1253 $indiv_name = $this->db->f('name');
1254 $this->t->set_var('individual_name',$indiv_name);
1257 // Select all the assignments
1258 $sql = "SELECT * FROM tc_assignment ORDER by name ASC";
1259 $this->db->query($sql,__LINE__,__FILE__);
1261 while ($this->db->next_record()) {
1262 $assignment = $this->db->f('assignment');
1263 $assignment_name = $this->db->f('name');
1264 $assignment_abbreviation = $this->db->f('abbreviation');
1266 $this->nextmatchs->template_alternate_row_color(&$this->t);
1267 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$assignment_name</td>";
1269 $header_row="<th width=$comp_width><font size=-2>Assignments</th><th>Willingness</th>";
1270 $sql = "SELECT * FROM tc_willingness WHERE individual=".$individual." AND assignment=".$assignment;
1271 $this->db2->query($sql,__LINE__,__FILE__);
1272 $value = $assignment;
1274 if($this->db2->next_record()) {
1275 if($this->db2->f('willing') == 'y') {
1276 $table_data .= '<td width=100 align=center>';
1277 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y" checked>Y';
1278 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1279 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/"> ';
1280 $table_data .= '</td>';
1281 } else if($this->db2->f('willing') == 'n') {
1282 $table_data .= '<td width=100 align=center>';
1283 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1284 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n" checked>N';
1285 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/">';
1286 $table_data .= '</td>';
1288 $table_data .= '<td width=100 align=center>';
1289 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1290 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1291 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1292 $table_data .= '</td>';
1295 $table_data .= '<td width=100 align=center>';
1296 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1297 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1298 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1299 $table_data .= '</td>';
1302 $table_data .= "\n";
1303 $table_data .= "</tr>";
1304 $table_data .= "<tr><td colspan=20></td></tr>";
1307 $table_data .= "<tr><td colspan=20><hr></td></tr>";
1309 $this->t->set_var('table_width',$table_width);
1310 $this->t->set_var('header_row',$header_row);
1311 $this->t->set_var('table_data',$table_data);
1312 $this->t->fp('list','assignment_list',True);
1314 $this->t->set_var('lang_reset','Clear Form');
1315 $this->t->set_var('lang_save','Save Changes');
1316 $this->t->set_var('savehandle','');
1318 $this->t->pfp('out','willing_update_t');
1319 $this->t->pfp('addhandle','save');
1321 $this->save_sessiondata();
1325 function ppi_sched()
1327 $this->t->set_file(array('ppi_sched_t' => 'ppi_sched.tpl'));
1328 $this->t->set_block('ppi_sched_t','individual_list','indivlist');
1329 $this->t->set_block('ppi_sched_t','appt_list','apptlist');
1330 $action = get_var('action',array('GET','POST'));
1332 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1333 $this->t->set_var('lang_reset','Clear Changes');
1335 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
1336 $this->t->set_var('ppi_link_title','Yearly PPIs');
1338 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
1339 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
1341 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched&action=save'));
1342 $this->t->set_var('title','Yearly PPI Scheduler');
1344 $indiv_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $ppi_date_width=20;
1345 $table_width=$indiv_width + $phone_width + $pri_width + $notes_width + $ppi_date_width;
1346 $header_row = "<th width=$indiv_width><font size=-2>individual Name</th>";
1347 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1348 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1349 $header_row.= "<th width=$ppi_date_width><font size=-2>Last PPI</th>";
1350 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1351 $table_data=""; $completed_data=""; $totals_data="";
1355 // Get the President
1356 $sql = "SELECT * FROM tc_presidency where president=1 and valid=1";
1357 $this->db->query($sql,__LINE__,__FILE__);
1358 if($this->db->next_record()) {
1359 $president_name = $this->db->f('name');
1360 $president_name_array = explode(",",$president_name);
1361 $president_last_name = $president_name_array[0];
1362 $president_id = $this->db->f('individual');
1363 $presidency_id = $this->db->f('presidency');
1364 $interviewer = $this->db->f('individual');
1365 $district_number = '*';
1366 $district_name = $president_name;
1367 $sql = "SELECT * FROM tc_individual where individual='$president_id'";
1368 $this->db2->query($sql,__LINE__,__FILE__);
1369 if($this->db2->next_record()) {
1370 $mls_id = $this->db2->f('mls_id');
1372 $sql = "SELECT * FROM tc_individual where mls_id='$mls_id'";
1373 $this->db2->query($sql,__LINE__,__FILE__);
1374 if($this->db2->next_record()) {
1375 $president_address = $this->db2->f('address');
1378 print "<hr><font color=red><h3>-E- Unable to locate President in tc_presidency table</h3></font></hr>";
1382 if($action == 'save') {
1383 // Save any changes made to the appointment table
1384 $new_data = get_var('appt_notes',array('POST'));
1385 if($new_data != "") {
1386 foreach ($new_data as $entry) {
1387 $indiv = $entry['individual'];
1388 $appointment = $entry['appointment'];
1389 $location = $entry['location'];
1390 if($location == "") { $location = "$president_last_name"." home ($president_address)"; }
1391 if($indiv == 0) { $location = ""; }
1393 //Only perform a database update if we have made a change to this appointment
1394 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and individual='$indiv' and location='$location'";
1395 $this->db->query($sql,__LINE__,__FILE__);
1396 if(!$this->db->next_record()) {
1397 // Perform database save actions here
1398 $this->db->query("UPDATE tc_appointment set " .
1399 " individual='" . $indiv . "'" .
1400 ",location='" . $location . "'" .
1401 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1402 // Email the appointment
1403 $this->email_appt($appointment);
1408 // Save any changes made to the ppi notes table
1409 $new_data = get_var('notes',array('POST'));
1410 foreach ($new_data as $entry) {
1411 $notes = $entry['notes'];
1412 $individual = $entry['individual'];
1413 $priority = $entry['pri'];
1415 // Perform database save actions here
1416 $sql = "SELECT * FROM tc_individual WHERE individual='$individual'";
1417 $this->db->query($sql,__LINE__,__FILE__);
1418 if ($this->db->next_record()) {
1419 $scheduling_priority = $this->db->f('scheduling_priority');
1420 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$priority' AND notes=\"$notes\" WHERE scheduling_priority='$scheduling_priority'", __LINE__, __FILE__);
1424 $this->db->query("UPDATE tc_individual set " .
1425 " notes='" . $notes . "'" .
1426 ",priority='" . $priority . "'" .
1427 " WHERE individual=" . $individual,__LINE__,__FILE__);
1433 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched');
1434 //Header('Location: ' . $take_me_to_url);
1437 // create the individual id -> individual name mapping
1438 // TODO: changed this so it picks the quorum dynamically
1439 $sql = "SELECT * FROM tc_individual where valid=1 and steward='Elder' ORDER BY name ASC";
1440 $this->db->query($sql,__LINE__,__FILE__);
1444 while ($this->db->next_record()) {
1445 $indiv_name[$i] = $this->db->f('name');
1446 $individual[$i] = $this->db->f('individual');
1449 array_multisort($indiv_name, $individual);
1451 // APPOINTMENT TABLE
1452 $date_width=250; $time_width=100; $indiv_width=200; $location_width=100;
1453 $appt_table_width=$date_width + $time_width + $indiv_width + $location_width;
1454 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1455 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1456 $appt_header_row.= "<th width=$indiv_width><font size=-2>indiv</th>";
1457 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
1458 $appt_table_data = "";
1460 $total_indivs=0; $indivs_with_yearly_ppi=0;
1462 // Display a scheduling table for the President
1463 $table_data=""; $appt_table_data="";
1464 $table_title = "District ".$district_number.": ".$district_name.": All indivs with Yearly PPI Not Completed";
1465 $appt_table_title = "District ".$district_number.": ".$district_name.": Yearly PPI Appointment Slots";
1466 $this->t->set_var('table_title',$table_title);
1467 $this->t->set_var('appt_table_title',$appt_table_title);
1469 // query the database for all the appointments
1470 $sql = "SELECT * FROM tc_appointment where presidency=".$presidency_id." and date>=CURDATE() ORDER BY date ASC, time ASC";
1471 $this->db->query($sql,__LINE__,__FILE__);
1473 while ($this->db->next_record()) {
1474 $appointment = $this->db->f('appointment');
1475 $indiv = $this->db->f('individual');
1476 $location = $this->db->f('location');
1477 if(($location == "") && ($indiv > 0)) { $location = "$president_last_name"." home ($president_address)"; }
1479 $date = $this->db->f('date');
1480 $date_array = explode("-",$date);
1481 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1482 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1484 $time = $this->db->f('time');
1485 $time_array = explode(":",$time);
1486 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1488 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1489 $appt_table_data.= "<td align=center>$day_string</td>";
1490 $appt_table_data.= "<td align=center>$time_string</td>";
1492 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][individual]>';
1493 $appt_table_data.= '<option value=0></option>';
1494 for ($i=0; $i < count($individual); $i++) {
1495 $id = $individual[$i];
1496 $name = $indiv_name[$i];
1497 if($individual[$i] == $indiv) {
1498 $selected[$id] = 'selected="selected"';
1500 $selected[$id] = '';
1502 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1504 $appt_table_data.='</select></td>';
1506 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
1507 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
1509 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1511 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1512 $this->t->set_var('tr_color',$tr_color);
1515 $this->t->set_var('appt_table_data',$appt_table_data);
1516 $this->t->set_var('appt_header_row',$appt_header_row);
1517 $this->t->set_var('appt_table_width',$appt_table_width);
1519 // PPI SCHEDULING TABLE
1520 // TODO: changed this so it picks the quorum dynamically
1521 $sql = "SELECT * FROM tc_individual as ti JOIN tc_scheduling_priority as tsp where ti.scheduling_priority=tsp.scheduling_priority and steward='Elder' and valid=1 ORDER by tsp.priority ASC, ti.name ASC";
1522 $this->db->query($sql,__LINE__,__FILE__);
1526 while ($this->db->next_record()) {
1527 $individual[$i] = $this->db->f('individual');
1528 $indiv_name[$i] = $this->db->f('name');
1529 $indiv_phone[$individual[$i]] = $this->db->f('phone');
1530 $indiv_priority[$individual[$i]] = $this->db->f('priority');
1531 $indiv_notes[$individual[$i]] = $this->db->f('notes');
1536 $max = count($individual);
1538 for($i=0; $i < $max; $i++) {
1539 $id = $individual[$i];
1540 $name = $indiv_name[$i];
1541 $phone = $indiv_phone[$id];
1542 $priority = $indiv_priority[$id];
1543 $notes = $indiv_notes[$id];
1545 // If this individual has had a yearly PPI this year, don't show him on the schedule list
1546 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
1547 $sql = "SELECT * FROM tc_interview WHERE date > '$year_start' AND date < '$year_end' ".
1548 "AND individual=" . $id . " AND interview_type='ppi'";
1549 $this->db2->query($sql,__LINE__,__FILE__);
1551 if(!$this->db2->next_record()) {
1552 $sql = "SELECT * FROM tc_interview WHERE individual=" . $id . " AND interview_type='ppi' ORDER BY date DESC";
1553 $this->db->query($sql,__LINE__,__FILE__);
1554 if($this->db->next_record()) {
1555 $date = $this->db->f('date');
1559 $link_data['menuaction'] = 'tc.tc.ppi_update';
1560 $link_data['individual'] = $id;
1561 $link_data['name'] = $name;
1562 $link_data['interview'] = '';
1563 $link_data['interview_type'] = 1;
1564 $link_data['action'] = 'add';
1565 $link_data['interviewer'] = $interviewer;
1566 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1567 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1568 $this->t->set_var('tr_color',$tr_color);
1569 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1570 $table_data.= "<td align=center>$phone</td>";
1571 //$table_data.= "<td align=center>$priority</td>";
1572 $table_data.= "<td align=center>";
1573 $table_data.= '<select name=notes['.$i.'][pri]>';
1574 foreach(range(0,6) as $num) {
1575 if($num == 0) { $num = 1; } else {$num = $num*5; }
1576 if($priority == $num) {
1577 $selected[$num] = 'selected="selected"';
1579 $selected[$num] = '';
1581 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1583 $table_data.= '</select></td>';
1584 $table_data.= "<td align=center>$date</td>";
1585 $table_data.= '<td><input type=text size="50" maxlength="128" name="notes['.$i.'][notes]" value="'.$notes.'">';
1586 $table_data.= '<input type=hidden name="notes['.$i.'][individual]" value="'.$id.'">';
1587 $table_data.= '<input type=hidden name="notes['.$i.'][indiv_name]" value="'.$name.'">';
1588 $table_data.= '</td>';
1589 $table_data.= '</tr>';
1591 $link_data['menuaction'] = 'tc.tc.ppi_update';
1592 $link_data['interviewer'] = $this->db2->f('interviewer');
1593 $link_data['individual'] = $this->db2->f('individual');
1594 $link_data['name'] = $name;
1595 $link_data['interview'] = $this->db2->f('interview');
1596 $link_data['interview_type'] = $this->db2->f('interview_type');
1597 $link_data['action'] = 'view';
1598 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1599 $indivs_with_yearly_ppi++;
1600 $date = $this->db2->f('date');
1601 $notes = $this->db2->f('notes');
1602 if(strlen($notes) > 40) { $notes = substr($notes,0,40) . "..."; }
1603 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1604 $this->t->set_var('tr_color2',$tr_color2);
1605 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1606 $completed_data.= "<td align=center>$phone</td>";
1607 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1608 $completed_data.= "<td align=left>$notes</td>";
1609 $completed_data.= '</tr>';
1611 } // End for individuals Loop
1613 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1614 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1615 $completed_header_row = "<th width=$name_width><font size=-2>Individual Name</th>";
1616 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1617 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1618 $completed_header_row.= "<th width=$notes_width><font size=-2>PPI Notes</th>";
1620 $this->t->set_var('table_width',$table_width);
1621 $this->t->set_var('header_row',$header_row);
1622 $this->t->set_var('table_data',$table_data);
1623 $this->t->set_var('completed_header_row',$completed_header_row);
1624 $this->t->set_var('completed_table_width',$completed_table_width);
1625 $this->t->set_var('completed',$completed_data);
1626 $this->t->fp('indivlist','individual_list',True);
1628 $indivs_width=300; $totals_width=100;
1629 $totals_table_width=$indivs_width + $totals_width;
1630 $totals_header_row = "<th width=$indivs_width><font size=-2>Individuals</th>";
1631 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
1632 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1633 $totals_data.= "<td align=left><font size=-2><b>Total Individuals with yearly PPIs completed:</b></font></td>";
1634 $totals_data.= "<td align=center><font size=-2><b>$indivs_with_yearly_ppi / $total_indivs</b></font></td>";
1635 $percent = ceil(($indivs_with_yearly_ppi / $total_indivs)*100);
1636 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1637 $this->t->set_var('tr_color',$tr_color);
1638 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1639 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
1640 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
1641 $totals_data.= "</tr>";
1643 $this->t->set_var('totals',$totals_data);
1644 $this->t->set_var('totals_header_row',$totals_header_row);
1645 $this->t->set_var('totals_table_width',$totals_table_width);
1647 $this->t->pfp('out','ppi_sched_t');
1648 $this->save_sessiondata();
1652 function int_sched()
1654 $this->t->set_file(array('int_sched_t' => 'int_sched.tpl'));
1655 $this->t->set_block('int_sched_t','individual_list','indivlist');
1656 $this->t->set_block('int_sched_t','appt_list','apptlist');
1657 $action = get_var('action',array('GET','POST'));
1659 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1660 $this->t->set_var('lang_reset','Clear Changes');
1662 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
1663 $this->t->set_var('int_link_title','Hometeaching Interviews');
1665 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
1666 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
1668 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched&action=save'));
1669 $this->t->set_var('title','Hometeaching Interviews Scheduler');
1671 $indiv_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $int_date_width=20;
1672 $table_width=$indiv_width + $phone_width + $pri_width + $notes_width + $int_date_width;
1673 $header_row = "<th width=$indiv_width><font size=-2>individual Name</th>";
1674 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1675 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1676 $header_row.= "<th width=$int_date_width><font size=-2>Last Interview</th>";
1677 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1678 $table_data=""; $completed_data=""; $totals_data="";
1682 $nextyear = $year + 1;
1683 if($month >= 1 && $month <= 3) { $quarter_start=$year."-01-01"; $quarter_end=$year."-04-01"; }
1684 if($month >= 4 && $month <= 6) { $quarter_start=$year."-04-01"; $quarter_end=$year."-07-01"; }
1685 if($month >= 7 && $month <= 9) { $quarter_start=$year."-07-01"; $quarter_end=$year."-10-01"; }
1686 if($month >= 10 && $month <= 12) { $quarter_start=$year."-10-01"; $quarter_end=$nextyear."-01-01"; }
1687 //print "year: $year month: $month quarter_start: $quarter_start quarter_end: $quarter_end<br>";
1689 // create the individual id -> individual name mapping
1690 // TODO: changed this so it picks the quorum dynamically
1691 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1 ORDER BY name ASC";
1692 $this->db->query($sql,__LINE__,__FILE__);
1694 $individual_data = NULL;
1695 $indiv_name_data = NULL;
1696 while ($this->db->next_record()) {
1697 $indiv_name_data[$i] = $this->db->f('name');
1698 $individual_data[$i] = $this->db->f('individual');
1699 $individ2name[$individual_data[$i]] = $indiv_name_data[$i];
1702 // add any YM that are home teachers
1703 $sql = "SELECT * FROM tc_companionship where valid=1";
1704 $this->db->query($sql,__LINE__,__FILE__);
1705 while ($this->db->next_record()) {
1706 $tmp_individual = $this->db->f('individual');
1707 $sql = "Select * FROM tc_individual where individual='$tmp_individual' and steward='' and valid=1";
1708 $this->db2->query($sql,__LINE__,__FILE__);
1709 while ($this->db2->next_record()) {
1710 $indiv_name_data[$i] = $this->db2->f('name');
1711 $individual_data[$i] = $this->db2->f('individual');
1712 $individ2name[$individual_data[$i]] = $indiv_name_data[$i];
1716 array_multisort($indiv_name_data, $individual_data);
1718 if($action == 'save') {
1719 // Save any changes made to the appointment table
1720 $new_data = get_var('appt_notes',array('POST'));
1721 if($new_data != "") {
1722 foreach ($new_data as $entry) {
1723 $indiv = $entry['individual'];
1724 $appointment = $entry['appointment'];
1725 $location = $entry['location'];
1726 if($location == "") {
1727 $supervisor = $entry['supervisor'];
1728 $supervisor_array = explode(",", $individ2name[$supervisor]);
1729 $supervisor_last_name = $supervisor_array[0];
1730 $sql = "SELECT * FROM tc_individual where individual='$supervisor'";
1731 $this->db2->query($sql,__LINE__,__FILE__);
1732 if($this->db2->next_record()) {
1733 $mls_id = $this->db2->f('mls_id');
1735 $sql = "SELECT * FROM tc_individual where mls_id='$mls_id'";
1736 $this->db2->query($sql,__LINE__,__FILE__);
1737 if($this->db2->next_record()) {
1738 $supervisor_address = $this->db2->f('address');
1740 $location = "$supervisor_last_name"." home ($supervisor_address)";
1742 if($indiv == 0) { $location = ""; }
1744 //print "indiv: $indiv appointment: $appointment <br>";
1745 //Only perform a database update if we have made a change to this appointment
1746 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and individual='$indiv' and location='$location'";
1747 $this->db->query($sql,__LINE__,__FILE__);
1748 if(!$this->db->next_record()) {
1749 // Perform database save actions here
1750 $this->db->query("UPDATE tc_appointment set " .
1751 " individual='" . $indiv . "'" .
1752 ",location='" . $location . "'" .
1753 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1754 // Email the appointment
1755 $this->email_appt($appointment);
1760 // Save any changes made to the int notes table
1761 $new_data = get_var('hti_notes',array('POST'));
1762 foreach ($new_data as $entry) {
1763 $hti_notes = $entry['notes'];
1764 $individual = $entry['individual'];
1765 $indiv_name = $entry['indiv_name'];
1766 $hti_pri = $entry['pri'];
1767 //print "hti_notes: $hti_notes indiv_name: $indiv_name <Br>";
1768 // Perform database save actions here
1769 $this->db->query("SELECT * FROM tc_companionship WHERE individual=$individual and valid=1",__LINE__,__FILE__);
1770 if ($this->db->next_record()) {
1771 $scheduling_priority = $this->db->f('scheduling_priority');
1772 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$hti_pri' and notes=\"hti_notes\" where scheduling_priority=$scheduling_priority",__LINE__,__FILE__);
1775 $this->db->query("UPDATE tc_individual set " .
1776 " hti_notes='" . $hti_notes . "'" .
1777 ",hti_pri='" . $hti_pri . "'" .
1778 " WHERE individual=" . $individual,__LINE__,__FILE__);
1782 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched');
1783 //Header('Location: ' . $take_me_to_url);
1786 // Get the Districts
1787 $sql = "SELECT * FROM tc_district where valid=1 ORDER BY district ASC";
1788 $this->db->query($sql,__LINE__,__FILE__);
1790 while ($this->db->next_record()) {
1791 $district = $this->db->f('district');
1792 $districts[$i]['district'] = $this->db->f('district');
1793 $districts[$i]['name'] = $this->db->f('name');
1794 $districts[$i]['supervisor'] = $this->db->f('supervisor');
1795 $sql = "SELECT * FROM tc_presidency where district=$district and valid=1";
1796 $this->db2->query($sql,__LINE__,__FILE__);
1797 if($this->db2->next_record()) {
1798 $districts[$i]['presidency'] = $this->db2->f('presidency');
1803 // APPOINTMENT TABLE
1805 $date_width=250; $time_width=100; $indiv_width=200; $location_width=100;
1806 $appt_table_width=$date_width + $time_width + $indiv_width + $location_width;
1807 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1808 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1809 $appt_header_row.= "<th width=$indiv_width><font size=-2>Individual</th>";
1810 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
1811 $appt_table_data = "";
1813 $total_comps=0; $comps_with_quarterly_int=0;
1815 // Display a scheduling table for each district
1816 for ($d=0; $d < count($districts); $d++) {
1817 $table_data=""; $appt_table_data="";
1818 $this->t->set_var('district_number',$districts[$d]['district']);
1819 $this->t->set_var('district_name',$districts[$d]['name']);
1820 $supervisor = $districts[$d]['supervisor'];
1821 $supervisor_array = explode(",", $supervisor);
1822 $supervisor_last_name = $supervisor_array[0];
1823 $sql = "SELECT * FROM tc_individual where individual='$supervisor'";
1824 $this->db2->query($sql,__LINE__,__FILE__);
1825 if($this->db2->next_record()) {
1826 $mls_id = $this->db2->f('mls_id');
1828 $sql = "SELECT * FROM tc_individual where mls_id='$mls_id'";
1829 $this->db2->query($sql,__LINE__,__FILE__);
1830 if($this->db2->next_record()) {
1831 $supervisor_address = $this->db2->f('address');
1833 $location = "$supervisor_last_name"." home ($supervisor_address)";
1834 $table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": All Individuals with Interviews Not Completed";
1835 $appt_table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": Interview Appointment Slots";
1836 $this->t->set_var('table_title',$table_title);
1837 $this->t->set_var('appt_table_title',$appt_table_title);
1839 // query the database for all the appointments
1840 $sql = "SELECT * FROM tc_appointment where presidency=".$districts[$d]['presidency']." and date>=CURDATE() ORDER BY date ASC, time ASC";
1841 $this->db->query($sql,__LINE__,__FILE__);
1843 while ($this->db->next_record()) {
1844 $appointment = $this->db->f('appointment');
1845 $indiv = $this->db->f('individual');
1846 $location = $this->db->f('location');
1847 if(($location == "") && ($indiv > 0)) { $location = "$supervisor_last_name"." home ($supervisor_address)"; }
1849 $date = $this->db->f('date');
1850 $date_array = explode("-",$date);
1851 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1852 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1854 $time = $this->db->f('time');
1855 $time_array = explode(":",$time);
1856 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1858 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1859 $appt_table_data.= "<td align=center>$day_string</td>";
1860 $appt_table_data.= "<td align=center>$time_string</td>";
1862 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][individual]>';
1863 $appt_table_data.= '<option value=0></option>';
1864 for ($i=0; $i < count($individual_data); $i++) {
1865 $id = $individual_data[$i];
1866 $name = $indiv_name_data[$i];
1867 if($individual_data[$i] == $indiv) {
1868 $selected[$id] = 'selected="selected"';
1870 $selected[$id] = '';
1872 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1874 $appt_table_data.='</select></td>';
1876 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
1877 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
1879 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1880 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][supervisor]" value="'.$supervisor.'">';
1882 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1883 $this->t->set_var('tr_color',$tr_color);
1886 $this->t->set_var('appt_table_data',$appt_table_data);
1887 $this->t->set_var('appt_header_row',$appt_header_row);
1888 $this->t->set_var('appt_table_width',$appt_table_width);
1890 // INTERVIEW SCHEDULING TABLE
1892 // Select all the unique companionship numbers for this district
1893 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$d]['district'];
1894 $this->db->query($sql,__LINE__,__FILE__);
1895 $j=0; $unique_companionships = '';
1896 while ($this->db->next_record())
1898 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
1903 for ($j=0; $j < count($unique_companionships); $j++) {
1904 // Select all the companions from each companionship
1905 $sql = "SELECT * FROM tc_companionship AS tc JOIN (tc_scheduling_priority AS tsp, tc_individual as ti) WHERE tc.scheduling_priority=tsp.scheduling_priority AND tc.individual=ti.individual AND tc.valid=1 AND tc.companionship=". $unique_companionships[$j]['companionship'];
1906 $this->db->query($sql,__LINE__,__FILE__);
1907 $k=0; $int_completed=0;
1908 $comp = $unique_companionships[$j]['companionship'];
1909 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1910 $this->t->set_var('tr_color',$tr_color);
1912 while ($this->db->next_record()) {
1913 // Get this companions information
1914 $individual = $this->db->f('individual');
1916 $id = $this->db->f('individual');
1917 $name = $this->db->f('name');
1918 $phone = $this->db->f('phone');
1919 $hti_pri = $this->db->f('priority');
1920 $hti_notes = $this->db->f('notes');
1922 // If the companionship has already had its quarterly interview,
1923 // Skip the other companion in the companionship.
1924 if($int_completed == 1) {
1925 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1926 $completed_data.= "<td align=center>$phone</td>";
1927 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1928 $completed_data.= "<td align=left>$hti_notes</td>";
1929 $completed_data.= '</tr>';
1930 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1931 $this->t->set_var('tr_color2',$tr_color2);
1932 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1933 $this->t->set_var('tr_color',$tr_color);
1937 // If this companionship has had a hometeaching interview this quarter, don't show them on the schedule list
1938 $sql = "SELECT * FROM tc_interview WHERE date >= '$quarter_start' AND date < '$quarter_end' AND individual='$id'";
1939 $this->db2->query($sql,__LINE__,__FILE__);
1941 if(!$this->db2->next_record()) {
1942 $sql = "SELECT * FROM tc_interview WHERE individual='$id' ORDER BY date DESC";
1943 $this->db3->query($sql,__LINE__,__FILE__);
1944 if($this->db3->next_record()) {
1945 $date = $this->db3->f('date');
1949 $link_data['menuaction'] = 'tc.tc.int_update';
1950 $link_data['individual'] = $id;
1951 $link_data['name'] = $name;
1952 $link_data['interview'] = '';
1953 $link_data['action'] = 'add';
1954 $link_data['interviewer'] = $districts[$d]['supervisor'];
1955 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1956 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1957 $table_data.= "<td align=center>$phone</td>";
1958 $table_data.= "<td align=center>";
1959 $table_data.= '<select name=hti_notes['.$i.'][pri]>';
1960 foreach(range(0,6) as $num) {
1961 if($num == 0) { $num = 1; } else {$num = $num*5; }
1962 if($hti_pri == $num) {
1963 $selected[$num] = 'selected="selected"';
1965 $selected[$num] = '';
1967 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1969 $table_data.= '</select></td>';
1970 $table_data.= "<td align=center>$date</td>";
1971 $table_data.= '<td><input type=text size="50" maxlength="128" name="hti_notes['.$i.'][notes]" value="'.$hti_notes.'">';
1972 $table_data.= '<input type=hidden name="hti_notes['.$i.'][individual]" value="'.$id.'">';
1973 $table_data.= '<input type=hidden name="hti_notes['.$i.'][indiv_name]" value="'.$name.'">';
1974 $table_data.= '</td>';
1975 $table_data.= '</tr>'."\n";
1978 $link_data['menuaction'] = 'tc.tc.int_update';
1979 $link_data['interviewer'] = $this->db2->f('interviewer');
1980 $link_data['individual'] = $this->db2->f('individual');
1981 $link_data['name'] = $name;
1982 $link_data['interview'] = $this->db2->f('interview');
1983 $link_data['action'] = 'view';
1984 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1985 $comps_with_quarterly_int++;
1987 $date = $this->db2->f('date');
1988 $hti_notes = $this->db2->f('notes');
1989 if(strlen($hti_notes) > 40) { $hti_notes = substr($hti_notes,0,40) . "..."; }
1990 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1991 $completed_data.= "<td align=center>$phone</td>";
1992 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1993 $completed_data.= "<td align=left>$hti_notes</td>";
1994 $completed_data.= '</tr>';
1999 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
2000 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
2001 $completed_header_row = "<th width=$name_width><font size=-2>Individual Name</th>";
2002 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2003 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
2004 $completed_header_row.= "<th width=$notes_width><font size=-2>Interview Notes</th>";
2006 $this->t->set_var('table_width',$table_width);
2007 $this->t->set_var('header_row',$header_row);
2008 $this->t->set_var('table_data',$table_data);
2009 $this->t->set_var('completed_header_row',$completed_header_row);
2010 $this->t->set_var('completed_table_width',$completed_table_width);
2011 $this->t->set_var('completed',$completed_data);
2012 $this->t->fp('indivlist','individual_list',True);
2014 } // End for each district loop
2017 $indivs_width=300; $totals_width=100;
2018 $totals_table_width=$indivs_width + $totals_width;
2019 $totals_header_row = "<th width=$indivs_width><font size=-2>Individuals</th>";
2020 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2021 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2022 $totals_data.= "<td align=left><font size=-2><b>Total Companionships with interviews completed:</b></font></td>";
2023 $totals_data.= "<td align=center><font size=-2><b>$comps_with_quarterly_int / $total_comps</b></font></td>";
2024 $percent = ceil(($comps_with_quarterly_int / $total_comps)*100);
2025 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2026 $this->t->set_var('tr_color',$tr_color);
2027 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2028 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2029 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2030 $totals_data.= "</tr>";
2032 $this->t->set_var('totals',$totals_data);
2033 $this->t->set_var('totals_header_row',$totals_header_row);
2034 $this->t->set_var('totals_table_width',$totals_table_width);
2036 $this->t->pfp('out','int_sched_t');
2037 $this->save_sessiondata();
2041 function vis_sched()
2043 $this->t->set_file(array('vis_sched_t' => 'vis_sched.tpl'));
2044 $this->t->set_block('vis_sched_t','family_list','familylist');
2045 $this->t->set_block('vis_sched_t','appt_list','apptlist');
2046 $action = get_var('action',array('GET','POST'));
2048 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
2049 $this->t->set_var('lang_reset','Clear Changes');
2051 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2052 $this->t->set_var('vis_link_title','View Yearly Visits');
2054 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
2055 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2057 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched&action=save'));
2058 $this->t->set_var('title','Presidency Yearly Visit Scheduler');
2060 $family_width=500; $phone_width=40; $pri_width=10; $notes_width=128; $visit_date_width=20;
2061 $table_width=$family_width + $phone_width + $pri_width + $notes_width + $visit_date_width;
2062 $header_row = "<th width=$family_width><font size=-2>Family Name</th>";
2063 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2064 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
2065 $header_row.= "<th width=$visit_date_width><font size=-2>Last Visit</th>";
2066 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
2067 $table_data=""; $completed_data=""; $totals_data="";
2071 // create the family id -> family name mapping
2072 $sql = "SELECT * FROM tc_family where valid=1 and individual != 0 and companionship != 0 ORDER BY name ASC";
2073 $this->db->query($sql,__LINE__,__FILE__);
2076 while ($this->db->next_record()) {
2077 $family_id[$i] = $this->db->f('family');
2078 $family_name[$i] = $this->db->f('name');
2079 $familyid2name[$family_id[$i]] = $family_name[$i];
2080 $sql = "SELECT * FROM tc_individual where family='$family_id[$i]'";
2081 $this->db2->query($sql,__LINE__,__FILE__);
2082 if($this->db2->next_record()) {
2083 $familyid2address[$family_id[$i]] = $this->db2->f('address');
2087 array_multisort($family_name, $family_id);
2089 if($action == 'save') {
2090 // Save any changes made to the appointment table
2091 $new_data = get_var('appt_notes',array('POST'));
2092 if($new_data != "") {
2093 foreach ($new_data as $entry) {
2094 $family = $entry['family'];
2095 $appointment = $entry['appointment'];
2096 $location = $entry['location'];
2097 if($location == "") {
2098 $family_name_array = explode(",", $familyid2name[$family]);
2099 $family_last_name = $family_name_array[0];
2100 $family_address = $familyid2address[$family];
2101 $location = "$family_last_name"." home ($family_address)";
2103 if($family == 0) { $location = ""; }
2105 //Only perform a database update if we have made a change to this appointment
2106 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and family='$family' and location='$location'";
2107 $this->db->query($sql,__LINE__,__FILE__);
2108 if(!$this->db->next_record()) {
2109 // Perform database save actions here
2110 $this->db->query("UPDATE tc_appointment set " .
2111 " family='" . $family . "'" .
2112 ",location='" . $location . "'" .
2113 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
2115 // Email the appointment
2116 $this->email_appt($appointment);
2121 // Save any changes made to the visit notes table
2122 $new_data = get_var('vis_notes',array('POST'));
2123 foreach ($new_data as $entry) {
2124 $visit_notes = $entry['notes'];
2125 $family = $entry['family_id'];
2126 $visit_pri = $entry['pri'];
2128 // Perform database save actions here
2129 $this->db->query("SELECT * FROM tc_family WHERE family='$family'",__LINE__,__FILE__);
2130 if ($this->db->next_record()) {
2131 $scheduling_priority = $this->db->f('scheduling_priority');
2132 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$visit_pri' AND notes=\"$visit_notes\" WHERE scheduling_priority='$scheduling_priority'",__LINE__,__FILE__);
2135 $this->db->query("UPDATE tc_family set " .
2136 " visit_notes='" . $visit_notes . "'" .
2137 ",visit_pri='" . $visit_pri . "'" .
2138 " WHERE family=" . $family,__LINE__,__FILE__);
2142 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched');
2143 //Header('Location: ' . $take_me_to_url);
2146 // APPOINTMENT TABLE
2147 $date_width=250; $time_width=100; $family_width=250; $location_width=100;
2148 $appt_table_width=$date_width + $time_width + $family_width + $location_width;
2149 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
2150 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
2151 $appt_header_row.= "<th width=$family_width><font size=-2>Family</th>";
2152 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
2153 $appt_table_data = "";
2155 // Find out what the President ID is
2156 $sql = "SELECT * FROM tc_presidency where president=1 and valid=1";
2157 $this->db->query($sql,__LINE__,__FILE__);
2158 if($this->db->next_record()) {
2159 $presidency_name = $this->db->f('name');
2160 $presidency_id = $this->db->f('presidency');
2162 print "<hr><font color=red><h3>-E- Unable to locate Presidency in tc_presidency table</h3></font></hr>";
2166 // query the database for all the appointments
2167 $sql = "SELECT * FROM tc_appointment where presidency=$presidency_id and date>=CURDATE() ORDER BY date ASC, time ASC";
2168 $this->db->query($sql,__LINE__,__FILE__);
2170 while ($this->db->next_record()) {
2171 $appointment = $this->db->f('appointment');
2172 $family = $this->db->f('family');
2173 $location = $this->db->f('location');
2174 $family_name_array = explode(",", $familyid2name[$family]);
2175 $family_last_name = $family_name_array[0];
2176 $family_address = $familyid2address[$family];
2177 if(($location == "") && ($family > 0)) { $location = "$family_last_name"." home ($family_address)"; }
2179 $date = $this->db->f('date');
2180 $date_array = explode("-",$date);
2181 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
2182 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
2184 $time = $this->db->f('time');
2185 $time_array = explode(":",$time);
2186 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
2188 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2189 $appt_table_data.= "<td align=center>$day_string</td>";
2190 $appt_table_data.= "<td align=center>$time_string</td>";
2192 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][family]>';
2193 $appt_table_data.= '<option value=0></option>';
2194 for ($i=0; $i < count($family_id); $i++) {
2195 $id = $family_id[$i];
2196 $name = $family_name[$i];
2197 if($family_id[$i] == $family) {
2198 $selected[$id] = 'selected="selected"';
2200 $selected[$id] = '';
2202 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
2204 $appt_table_data.='</select></td>';
2206 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
2207 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
2209 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
2211 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2212 $this->t->set_var('tr_color',$tr_color);
2215 $this->t->set_var('appt_table_data',$appt_table_data);
2216 $this->t->set_var('appt_header_row',$appt_header_row);
2217 $this->t->set_var('appt_table_width',$appt_table_width);
2220 // VISIT SCHEDULING TABLE
2221 $sql = "SELECT * FROM tc_family AS tf JOIN tc_scheduling_priority AS tsp WHERE tf.scheduling_priority=tsp.scheduling_priority AND tf.valid=1 AND tf.individual != 0 AND tf.companionship != 0 ORDER BY tsp.priority ASC, tf.name ASC";
2222 $this->db->query($sql,__LINE__,__FILE__);
2224 $total_families=0; $families_with_yearly_visit=0;
2228 $family_name = NULL;
2229 $family_phone = NULL;
2230 $family_visit_pri = NULL;
2231 $family_visit_notes = NULL;
2232 while ($this->db->next_record()) {
2233 $family_id[$i] = $this->db->f('family');
2234 $family_name[$i] = $this->db->f('name');
2235 $family_phone[$family_id[$i]] = $family_id[$i] . " ERROR";
2236 $family_visit_pri[$family_id[$i]] = $this->db->f('visit_pri');
2237 $family_visit_notes[$family_id[$i]] = $this->db->f('visit_notes');
2242 $sql = "SELECT * FROM tc_individual where valid=1";
2243 $this->db->query($sql,__LINE__,__FILE__);
2244 while ($this->db->next_record()) {
2245 $family = $this->db->f('family');
2246 $phone = $this->db->f('phone');
2247 $family_phone[$family] = $phone;
2250 $max = count($family_id);
2252 for($i=0; $i < $max; $i++) {
2253 $id = $family_id[$i];
2254 $name = $family_name[$i];
2255 $phone = $family_phone[$id];
2256 $vis_pri = $family_visit_pri[$id];
2257 $vis_notes = $family_visit_notes[$id];
2259 // If this family has had a yearly visit this year, don't show them on the schedule list
2260 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2261 $sql = "SELECT * FROM tc_visit WHERE date > '$year_start' AND date < '$year_end' ".
2262 "AND family=" . $id . " AND companionship=0";
2263 $this->db2->query($sql,__LINE__,__FILE__);
2265 if(!$this->db2->next_record()) {
2266 $sql = "SELECT * FROM tc_visit WHERE family=" . $id . " AND companionship=0 ORDER BY date DESC";
2267 $this->db->query($sql,__LINE__,__FILE__);
2268 if($this->db->next_record()) {
2269 $date = $this->db->f('date');
2273 $link_data['menuaction'] = 'tc.tc.vis_update';
2274 $link_data['visit'] = '';
2275 $link_data['family'] = $id;
2276 $link_data['name'] = $name;
2277 $link_data['action'] = 'add';
2278 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2279 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2280 $table_data.= "<td align=center>$phone</td>";
2281 $table_data.= "<td align=center>";
2282 $table_data.= '<select name=vis_notes['.$i.'][pri]>';
2283 foreach(range(0,6) as $num) {
2284 if($num == 0) { $num = 1; } else {$num = $num*5; }
2285 if($vis_pri == $num) {
2286 $selected[$num] = 'selected="selected"';
2288 $selected[$num] = '';
2290 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2292 $table_data.= '</select></td>';
2293 $table_data.= "<td align=center>$date</td>";
2294 $table_data.= '<td><input type=text size="50" maxlength="128" name="vis_notes['.$i.'][notes]" value="'.$vis_notes.'">';
2295 $table_data.= '<input type=hidden name="vis_notes['.$i.'][family_id]" value="'.$id.'">';
2296 $table_data.= '<input type=hidden name="vis_notes['.$i.'][family_name]" value="'.$name.'">';
2297 $table_data.= '</td>';
2298 $table_data.= '</tr>';
2299 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2300 $this->t->set_var('tr_color',$tr_color);
2302 $link_data['menuaction'] = 'tc.tc.vis_update';
2303 $link_data['visit'] = $this->db2->f('visit');
2304 $link_data['family'] = $this->db2->f('family');
2305 $link_data['name'] = $name;
2306 $link_data['date'] = $this->db2->f('date');
2307 $link_data['action'] = 'view';
2308 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2309 $families_with_yearly_visit++;
2310 $date = $this->db2->f('date');
2311 $vis_notes = $this->db2->f('notes');
2312 if(strlen($vis_notes) > 40) { $vis_notes = stripslashes(substr($vis_notes,0,40) . "..."); }
2313 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2314 $completed_data.= "<td align=center>$phone</td>";
2315 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2316 $completed_data.= "<td align=left>$vis_notes</td>";
2317 $completed_data.= '</tr>';
2318 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
2319 $this->t->set_var('tr_color2',$tr_color2);
2323 $name_width=190; $phone_width=100; $date_width=100; $notes_width=300;
2324 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
2325 $completed_header_row = "<th width=$name_width><font size=-2>Family Name</th>";
2326 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2327 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
2328 $completed_header_row.= "<th width=$notes_width><font size=-2>Visit Notes</th>";
2330 $family_width=300; $totals_width=100;
2331 $totals_table_width=$family_width + $totals_width;
2332 $totals_header_row = "<th width=$family_width><font size=-2>Families</th>";
2333 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2334 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2335 $totals_data.= "<td align=left><font size=-2><b>Total Families with yearly Visits completed:</b></font></td>";
2336 $totals_data.= "<td align=center><font size=-2><b>$families_with_yearly_visit / $total_families</b></font></td>";
2337 $percent = ceil(($families_with_yearly_visit / $total_families)*100);
2338 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2339 $this->t->set_var('tr_color',$tr_color);
2340 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2341 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2342 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2343 $totals_data.= "</tr>";
2345 $this->t->set_var('table_width',$table_width);
2346 $this->t->set_var('header_row',$header_row);
2347 $this->t->set_var('table_data',$table_data);
2348 $this->t->set_var('totals_header_row',$totals_header_row);
2349 $this->t->set_var('totals_table_width',$totals_table_width);
2350 $this->t->set_var('completed_header_row',$completed_header_row);
2351 $this->t->set_var('completed_table_width',$completed_table_width);
2352 $this->t->set_var('completed',$completed_data);
2353 $this->t->set_var('totals',$totals_data);
2354 $this->t->fp('familylist','family_list',True);
2355 $this->t->fp('apptlist','appt_list',True);
2357 $this->t->pfp('out','vis_sched_t');
2358 $this->save_sessiondata();
2363 $this->t->set_file(array('ppi_view_t' => 'ppi_view.tpl'));
2364 $this->t->set_block('ppi_view_t','district_list','list');
2366 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2367 $num_months = get_var('num_months',array('GET','POST'));
2368 if($num_months == '') { $num_months = $this->default_ppi_num_months; }
2369 $this->t->set_var('num_months',$num_months);
2370 if($num_months == 1) {
2371 $this->t->set_var('lang_num_months','Month of History');
2373 $this->t->set_var('lang_num_months','Months of History');
2375 $this->t->set_var('lang_filter','Filter');
2376 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2378 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2379 $this->t->set_var('ppi_link_title','Yearly PPIs');
2381 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
2382 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
2384 $this->t->set_var('title','Yearly PPIs');
2385 $num_months = get_var('num_months',array('GET','POST'));
2386 if($num_months == '') { $num_months = $this->default_ppi_num_years; }
2387 $this->t->set_var('num_months',$num_months);
2388 if($num_months == 1) {
2389 $this->t->set_var('lang_num_months','Year of History');
2391 $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('individual');
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_individual AS ti JOIN tc_scheduling_priority as tsp where ti.scheduling_priority=tsp.scheduling_priority and ti.steward='Elder' and ti.valid=1 ORDER BY ti.individual ASC";
2409 $this->db->query($sql,__LINE__,__FILE__);
2411 while ($this->db->next_record()) {
2412 $individual[$i] = $this->db->f('individual');
2413 $indiv_name[$i] = $this->db->f('name');
2414 $indiv_phone[$individual[$i]] = $this->db->f('phone');
2415 $indiv_priority[$individual[$i]] = $this->db->f('priority');
2416 $indiv_notes[$individual[$i]] = $this->db->f('notes');
2420 array_multisort($indiv_name, $individual);
2421 //var_dump($indiv_name); print "<br><br>"; var_dump($individual);
2423 $header_row="<th width=$comp_width><font size=-2>Individual Name</th>";
2425 $indiv_width=400; $ppi_width=75; $table_width=$indiv_width + $num_months*$ppi_width;
2427 for($m=$num_months; $m >= 0; $m--) {
2428 $year = date('Y') - $m;
2429 $header_row .= "<th width=150><font size=-2>$year</th>";
2433 for ($j=0; $j < count($individual); $j++) {
2434 $id = $individual[$j];
2435 $name = $indiv_name[$j];
2436 $phone = $indiv_phone[$id];
2438 $link_data['menuaction'] = 'tc.tc.ppi_update';
2439 $link_data['interviewer'] = $interviewer;
2440 $link_data['indiv'] = $id;
2441 $link_data['name'] = $name;
2442 $link_data['interview'] = '';
2443 $link_data['interview_type'] = $interview_type;
2444 $link_data['action'] = 'add';
2445 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2446 $this->nextmatchs->template_alternate_row_color(&$this->t);
2447 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2449 // Find out how many times PPIs were performed in the past $num_months for this individual
2450 for($m=$num_months; $m >= 0; $m--) {
2451 $year = date('Y') - $m;
2452 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2453 $sql = "SELECT * FROM tc_interview WHERE date > '$year_start' AND date < '$year_end' ".
2454 "AND individual=" . $id . " AND interview_type='ppi'";
2455 $this->db2->query($sql,__LINE__,__FILE__);
2457 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
2458 if($this->db2->next_record()) {
2459 $ppis[$m]++; $total_ppis[$m]++; $ppi_recorded[$companionship][$m]=1;
2460 $link_data['menuaction'] = 'tc.tc.ppi_update';
2461 $link_data['companionship'] = $companionship;
2462 $link_data['interviewer'] = $this->db2->f('interviewer');
2463 $link_data['indiv'] = $id;
2464 $link_data['name'] = $name;
2465 $link_data['interview'] = $this->db2->f('interview');
2466 $link_data['interview_type'] = $interview_type;
2467 $link_data['action'] = 'view';
2468 $date = $this->db2->f('date');
2469 $date_array = explode("-",$date);
2470 $month = $date_array[1];
2471 $day = $date_array[2];
2472 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2473 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2475 $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()) {
2521 $indiv = $this->db2->f('individual');
2522 $interviewer_name = $this->db2->f('name');
2523 if($indiv == $interviewer) {
2524 $this->t->set_var('interviewer',$interviewer . ' selected');
2526 $this->t->set_var('interviewer',$interviewer);
2528 $this->t->set_var('interviewer_name',$interviewer_name);
2529 $this->t->set_var('interview_type_checked','');
2530 $this->t->fp('int_list','interviewer_list',True);
2533 if($action == 'save') {
2534 $notes = get_var('notes',array('POST'));
2535 $this->db->query("UPDATE tc_interview set " .
2536 " interview='" . $interview . "'" .
2537 ", interviewer='" . $interviewer . "'" .
2538 ", individual='" . $indiv . "'" .
2539 ", date='" . $date . "'" .
2540 ", notes='" . $notes . "'" .
2541 ", interview_type='" . $interview_type . "'" .
2542 " WHERE interview=" . $interview,__LINE__,__FILE__);
2547 if($action == 'insert') {
2548 $notes = get_var('notes',array('POST'));
2549 $this->db->query("INSERT INTO tc_interview (interviewer,individual,date,notes,interview_type) " .
2550 "VALUES ('" . $interviewer . "','" . $indiv . "','" .
2551 $date . "','" . $notes . "','" . $interview_type ."')",__LINE__,__FILE__);
2556 if($action == 'add') {
2557 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2558 $this->t->set_var('interview', '');
2559 $this->t->set_var('interviewer', $interviewer);
2560 $this->t->set_var('name',$name);
2561 $this->t->set_var('indiv',$indiv);
2562 $this->t->set_var('date','');
2563 $this->t->set_var('notes','');
2564 $this->t->set_var('interview_type',$interview_type);
2565 $this->t->set_var('interview_type_checked','checked');
2566 $this->t->set_var('lang_done','Cancel');
2567 $this->t->set_var('lang_action','Adding New PPI');
2568 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview=' .
2569 $interview . '&action=' . 'insert'));
2572 if($action == 'edit' || $action == 'view') {
2573 $sql = "SELECT * FROM tc_interview WHERE interview=".$interview;
2574 $this->db->query($sql,__LINE__,__FILE__);
2575 $this->db->next_record();
2576 $this->t->set_var('interview',$interview);
2577 $this->t->set_var('name',$name);
2578 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2579 $this->t->set_var('indiv',$this->db->f('indiv'));
2580 $this->t->set_var('date',$this->db->f('date'));
2581 $this->t->set_var('notes',$this->db->f('notes'));
2582 $this->t->set_var('interview_type',$this->db->f('interview_type'));
2583 if($this->db->f('interview_type') == 1) { $this->t->set_var('interview_type_checked','checked'); }
2586 if($action == 'edit') {
2587 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2588 $this->t->set_var('lang_done','Cancel');
2589 $this->t->set_var('lang_action','Editing PPI');
2590 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview='.
2591 $interview . '&action=' . 'save'));
2594 if($action == 'view') {
2595 $date = $this->db->f('date');
2596 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2597 $this->t->set_var('readonly','READONLY');
2598 $this->t->set_var('disabled','DISABLED');
2599 $this->t->set_var('lang_done','Done');
2600 $this->t->set_var('lang_action','Viewing PPI');
2601 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview=' .
2602 $interview . '&action=' . 'edit'));
2605 $this->t->set_var('lang_reset','Clear Form');
2606 $this->t->set_var('lang_add','Add PPI');
2607 $this->t->set_var('lang_save','Save Changes');
2608 $this->t->set_var('edithandle','');
2609 $this->t->set_var('addhandle','');
2611 $this->t->pfp('out','form');
2613 if($action == 'view') { $this->t->set_var('lang_save','Edit PPI'); }
2614 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2615 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2617 $this->save_sessiondata();
2622 $this->t->set_file(array('int_view_t' => 'int_view.tpl'));
2623 $this->t->set_block('int_view_t','district_list','list');
2625 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2626 $num_quarters = get_var('num_quarters',array('GET','POST'));
2627 if($num_quarters == '') { $num_quarters = $this->default_int_num_quarters; }
2628 $this->t->set_var('num_quarters',$num_quarters);
2629 if($num_quarters == 1) {
2630 $this->t->set_var('lang_num_quarters','Quarter of History');
2632 $this->t->set_var('lang_num_quarters','Quarters of History');
2634 $this->t->set_var('lang_filter','Filter');
2636 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2637 $this->t->set_var('int_link_title','Hometeaching Interviews');
2639 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
2640 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
2642 $this->t->set_var('title','Hometeaching Interviews');
2644 $num_months = $num_quarters * 3 - 1;
2645 $current_month = $this->current_month;
2646 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
2647 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
2648 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
2649 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
2651 $sql = "SELECT * FROM tc_district where valid=1 ORDER BY district ASC";
2652 $this->db->query($sql,__LINE__,__FILE__);
2654 while ($this->db->next_record()) {
2655 $districts[$i]['district'] = $this->db->f('district');
2656 $districts[$i]['name'] = $this->db->f('name');
2657 $districts[$i]['supervisor'] = $this->db->f('supervisor');
2661 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
2662 $this->db->query($sql,__LINE__,__FILE__);
2664 while ($this->db->next_record()) {
2665 $individual[$i] = $this->db->f('individual');
2666 $indiv_name[$i] = $this->db->f('name');
2667 $indiv_phone[$individual[$i]] = $this->db->f('phone');
2670 array_multisort($indiv_name, $individual);
2671 for($i=0; $i < count($individual); $i++) {
2672 $id = $individual[$i];
2673 $indivs[$id] = $indiv_name[$i];
2676 $total_companionships = 0;
2677 $this->nextmatchs->template_alternate_row_color(&$this->t);
2678 for ($i=0; $i < count($districts); $i++) {
2679 $this->t->set_var('district_number',$districts[$i]['district']);
2680 $this->t->set_var('district_name',$districts[$i]['name']);
2681 $supervisor = $districts[$i]['supervisor'];
2683 // Select all the unique companionship numbers for this district
2684 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$i]['district'];
2685 $this->db->query($sql,__LINE__,__FILE__);
2686 $j=0; $unique_companionships = '';
2687 while ($this->db->next_record()) {
2688 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
2692 $comp_width=250; $int_width=75; $table_width=$comp_width + $num_months*$int_width;
2693 $table_data=""; $num_companionships = $j; $num_indivs = 0;
2694 for($m=$num_months; $m >= 0; $m--) { $ints[$m] = 0; }
2695 for ($j=0; $j < count($unique_companionships); $j++) {
2696 // Select all the companions in each companionship
2697 $sql = "SELECT * FROM tc_companionship where valid=1 and ".
2698 "companionship=". $unique_companionships[$j]['companionship'];
2699 $this->db->query($sql,__LINE__,__FILE__);
2701 $comp = $unique_companionships[$j]['companionship'];
2702 for($m=$num_months; $m >= 0; $m--) { $int_recorded[$comp][$m] = 0; }
2703 while ($this->db->next_record()) {
2704 // Get this companions information
2706 $companionship = $this->db->f('companionship');
2707 $individual = $this->db->f('individual');
2708 $name = $indivs[$individual];
2709 $phone = $indiv_phone[$individual];
2710 $link_data['menuaction'] = 'tc.tc.int_update';
2711 $link_data['companionship'] = $companionship;
2712 $link_data['interviewer'] = $supervisor;
2713 $link_data['indiv'] = $individual;
2714 $link_data['name'] = $name;
2715 $link_data['interview'] = '';
2716 $link_data['action'] = 'add';
2717 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2718 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2720 // Find out how many times Interviews were performed in the past $num_months for this individual
2721 $header_row="<th width=$comp_width><font size=-2>Companionship</th>";
2722 for($m=$num_months; $m >= 0; $m--) {
2723 $month = $current_month - $m;
2724 $year = $this->current_year;
2726 $remainder = $month;
2727 $month = 12 + $remainder;
2730 if($month < 10) { $month = "0"."$month"; }
2731 $month_start = "$year"."-"."$month"."-"."01";
2732 $month_end = "$year"."-"."$month"."-"."31";
2733 $month = "$month"."/"."$year";
2734 $sql = "SELECT * FROM tc_interview WHERE date >= '$month_start' AND date <= '$month_end' ".
2735 "AND individual=" . $individual;
2736 $this->db2->query($sql,__LINE__,__FILE__);
2737 $header_row .= "<th width=$int_width><font size=-2>$month</th>";
2739 if(!$total_ints[$m]) { $total_ints[$m] = 0; }
2740 if($this->db2->next_record()) {
2741 if(!$int_recorded[$companionship][$m]) {
2744 $int_recorded[$companionship][$m]=1;
2746 $link_data['menuaction'] = 'tc.tc.int_update';
2747 $link_data['companionship'] = $companionship;
2748 $link_data['interviewer'] = $this->db2->f('interviewer');
2749 $link_data['indiv'] = $individual;
2750 $link_data['name'] = $name;
2751 $link_data['interview'] = $this->db2->f('interview');
2752 $link_data['action'] = 'view';
2753 $date = $this->db2->f('date');
2754 $date_array = explode("-",$date);
2755 $month = $date_array[1];
2756 $day = $date_array[2];
2757 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2758 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2761 $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) {
2782 $total += $ints[$m];
2784 $percent = ceil(($total / $num_companionships)*100);
2785 $stat_data .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
2787 $stat_data .= "</tr>";
2789 $this->t->set_var('table_width',$table_width);
2790 $this->t->set_var('header_row',$header_row);
2791 $this->t->set_var('table_data',$table_data);
2792 $this->t->set_var('stat_data',$stat_data);
2793 $this->t->fp('list','district_list',True);
2796 // Display the totals
2798 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>Interview Totals:</font></b></td>";
2799 for($m=$num_months; $m >=0; $m--) {
2800 $month = $current_month - $m;
2801 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
2802 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
2803 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
2804 if(($month_begins) == 1) {
2805 $total = $total_ints[$m];
2807 $total += $total_ints[$m];
2809 $percent = ceil(($total / $total_companionships)*100);
2810 $totals .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
2814 $this->t->set_var('totals',$totals);
2815 $this->t->pfp('out','int_view_t');
2816 $this->save_sessiondata();
2819 function int_update()
2821 $this->t->set_file(array('form' => 'int_update.tpl'));
2822 $this->t->set_block('form','interviewer_list','int_list');
2823 $this->t->set_block('form','add','addhandle');
2824 $this->t->set_block('form','edit','edithandle');
2826 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2827 $this->t->set_var('readonly','');
2828 $this->t->set_var('disabled','');
2829 $this->t->set_var('interview_type_checked','');
2831 $action = get_var('action',array('GET','POST'));
2832 $companionship = get_var('companionship',array('GET','POST'));
2833 $interviewer = get_var('interviewer',array('GET','POST'));
2834 $name = get_var('name',array('GET','POST'));
2835 $interview = get_var('interview',array('GET','POST'));
2836 $indiv = get_var('indiv',array('GET','POST'));
2837 $date = get_var('date',array('GET','POST'));
2838 $notes = get_var('notes',array('GET','POST'));
2839 $interview_type = get_var('interview_type',array('GET','POST'));
2841 $sql = "SELECT * FROM tc_presidency where valid=1 and (president=1 or counselor=1 or secretary=1 or district!=0)";
2842 $this->db2->query($sql,__LINE__,__FILE__);
2843 while ($this->db2->next_record()) {
2844 $indiv = $this->db2->f('individual');
2845 $interviewer_name = $this->db2->f('name');
2846 if($indiv == $interviewer) {
2847 $this->t->set_var('interviewer',$interviewer . ' selected');
2849 $this->t->set_var('interviewer',$interviewer);
2851 $this->t->set_var('interviewer_name',$interviewer_name);
2852 $this->t->fp('int_list','interviewer_list',True);
2855 if($action == 'save') {
2856 $notes = get_var('notes',array('POST'));
2857 $this->db->query("UPDATE tc_interview set " .
2858 " interview='" . $interview . "'" .
2859 ", interviewer='" . $interviewer . "'" .
2860 ", individual='" . $indiv . "'" .
2861 ", date='" . $date . "'" .
2862 ", notes='" . $notes . "'" .
2863 ", interview_type='" . $interview_type . "'" .
2864 " WHERE interview=" . $interview,__LINE__,__FILE__);
2869 if($action == 'insert') {
2870 $notes = get_var('notes',array('POST'));
2871 $this->db->query("INSERT INTO tc_interview (interviewer,individual,date,notes,interview_type) " .
2872 "VALUES ('" . $interviewer . "','" . $indiv . "','" .
2873 $date . "','" . $notes ."','" . $interview_type . "')",__LINE__,__FILE__);
2878 if($action == 'add') {
2879 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2880 $this->t->set_var('interview', '');
2881 $this->t->set_var('interviewer', $interviewer);
2882 $this->t->set_var('name',$name);
2883 $this->t->set_var('indiv',$indiv);
2884 $this->t->set_var('date','');
2885 $this->t->set_var('notes','');
2886 $this->t->set_var('lang_done','Cancel');
2887 $this->t->set_var('lang_action','Adding New Interview');
2888 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
2889 $interview . '&action=' . 'insert'));
2892 if($action == 'edit' || $action == 'view') {
2893 $sql = "SELECT * FROM tc_interview WHERE interview=".$interview;
2894 $this->db->query($sql,__LINE__,__FILE__);
2895 $this->db->next_record();
2896 $this->t->set_var('interview',$interview);
2897 $this->t->set_var('name',$name);
2898 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2899 $this->t->set_var('indiv',$this->db->f('individual'));
2900 $this->t->set_var('date',$this->db->f('date'));
2901 $this->t->set_var('notes',$this->db->f('notes'));
2902 if($this->db->f('interview_type') == 1) { $this->t->set_var('interview_type_checked','checked'); }
2905 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') {
2914 $date = $this->db->f('date');
2915 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2916 $this->t->set_var('readonly','READONLY');
2917 $this->t->set_var('disabled','DISABLED');
2918 $this->t->set_var('lang_done','Done');
2919 $this->t->set_var('lang_action','Viewing Interview');
2920 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
2921 $interview . '&action=' . 'edit'));
2924 $this->t->set_var('lang_reset','Clear Form');
2925 $this->t->set_var('lang_add','Add Interview');
2926 $this->t->set_var('lang_save','Save Changes');
2927 $this->t->set_var('edithandle','');
2928 $this->t->set_var('addhandle','');
2930 $this->t->pfp('out','form');
2932 if($action == 'view') { $this->t->set_var('lang_save','Edit Interview'); }
2933 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2934 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2936 $this->save_sessiondata();
2941 $this->t->set_file(array('vis_view_t' => 'vis_view.tpl'));
2942 $this->t->set_block('vis_view_t','visit_list','list1');
2943 $this->t->set_block('vis_view_t','family_list','list2');
2945 $this->t->set_var('lang_name','Family Name');
2946 $this->t->set_var('lang_date','Date');
2948 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2949 $this->t->set_var('vis_link_title','View Yearly Visits');
2951 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
2952 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2954 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2955 $num_years = get_var('num_years',array('GET','POST'));
2956 if($num_years == '') { $num_years = $this->default_vis_num_years; }
2957 $this->t->set_var('num_years',$num_years);
2958 if($num_years == 1) {
2959 $this->t->set_var('lang_num_years','Year of History');
2961 $this->t->set_var('lang_num_years','Years of History');
2963 $this->t->set_var('lang_filter','Filter');
2965 $year = date('Y') - $num_years + 1;
2966 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2968 $sql = "SELECT * FROM tc_visit WHERE companionship=0 and date > '$year_start' ORDER BY date DESC";
2969 $this->db->query($sql,__LINE__,__FILE__);
2970 $total_records = $this->db->num_rows();
2973 while ($this->db->next_record()) {
2974 $visit_list[$i]['visit'] = $this->db->f('visit');
2975 $visit_list[$i]['family'] = $this->db->f('family');
2976 $visit_list[$i]['date'] = $this->db->f('date');
2980 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 companionship != 0 and valid=1";
3012 $this->db->query($sql,__LINE__,__FILE__);
3013 $total_records = $this->db->num_rows();
3016 while ($this->db->next_record()) {
3017 $family_names[$i] = $this->db->f('name');
3018 $family_ids[$i] = $this->db->f('family');
3020 } array_multisort($family_names, $family_ids);
3022 for ($i=0; $i < count($family_names); $i++) {
3023 $link_data['menuaction'] = 'tc.tc.vis_update';
3024 $link_data['visit'] = '';
3025 $link_data['family'] = $family_ids[$i];
3026 $link_data['action'] = 'add';
3027 $link_data['name'] = $family_names[$i];
3028 $this->t->set_var('add',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3030 $this->t->set_var('name',$family_names[$i]);
3031 if(($i+1) % 3 == 0) {
3032 $this->t->set_var('table_sep',"</td></tr><tr>");
3034 $this->t->set_var('table_sep',"</td>");
3036 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
3038 $this->t->fp('list2','family_list',True);
3041 $this->t->pfp('out','vis_view_t');
3042 $this->save_sessiondata();
3045 function vis_update()
3047 $this->t->set_file(array('form' => 'vis_update.tpl'));
3048 $this->t->set_block('form','add','addhandle');
3049 $this->t->set_block('form','edit','edithandle');
3051 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
3052 $this->t->set_var('readonly','');
3053 $this->t->set_var('disabled','');
3055 $action = get_var('action',array('GET','POST'));
3056 $visit = get_var('visit',array('GET','POST'));
3057 $family = get_var('family',array('GET','POST'));
3058 $name = get_var('name',array('GET','POST'));
3059 $date = get_var('date',array('GET','POST'));
3060 $notes = get_var('notes',array('GET','POST'));
3063 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') {
3074 $notes = get_var('notes',array('POST'));
3075 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes) " .
3076 "VALUES ('" . $family . "','" . $companionship . "','" .
3077 $date . "','" . $notes . "')",__LINE__,__FILE__);
3082 if($action == 'add') {
3083 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
3084 $this->t->set_var('family', $family);
3085 $this->t->set_var('visit', '');
3086 $this->t->set_var('name', $name);
3087 $this->t->set_var('date','');
3088 $this->t->set_var('notes','');
3089 $this->t->set_var('lang_done','Cancel');
3090 $this->t->set_var('lang_action','Adding New Visit');
3091 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&family=' .
3092 $family . '&action=' . 'insert'));
3095 if($action == 'edit' || $action == 'view') {
3096 $sql = "SELECT * FROM tc_visit WHERE visit=".$visit;
3097 $this->db->query($sql,__LINE__,__FILE__);
3098 $this->db->next_record();
3099 $this->t->set_var('visit',$visit);
3100 $this->t->set_var('name',$name);
3101 $this->t->set_var('family', $family);
3102 $this->t->set_var('date',$this->db->f('date'));
3103 $this->t->set_var('notes',$this->db->f('notes'));
3106 if($action == 'edit') {
3107 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
3108 $this->t->set_var('lang_done','Cancel');
3109 $this->t->set_var('lang_action','Editing Visit');
3110 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit=' .
3111 $visit . '&action=' . 'save'));
3114 if($action == 'view') {
3115 $date = $this->db->f('date');
3116 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
3117 $this->t->set_var('readonly','READONLY');
3118 $this->t->set_var('disabled','DISABLED');
3119 $this->t->set_var('lang_done','Done');
3120 $this->t->set_var('lang_action','Viewing Visit');
3121 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit=' .
3122 $visit . '&action=' . 'edit'));
3125 $this->t->set_var('lang_reset','Clear Form');
3126 $this->t->set_var('lang_add','Add Visit');
3127 $this->t->set_var('lang_save','Save Changes');
3128 $this->t->set_var('edithandle','');
3129 $this->t->set_var('addhandle','');
3131 $this->t->pfp('out','form');
3133 if($action == 'view') { $this->t->set_var('lang_save','Edit Visit'); }
3134 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
3135 if($action == 'add') { $this->t->pfp('addhandle','add'); }
3137 $this->save_sessiondata();
3142 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3143 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3144 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3146 $this->t->set_file(array('att_view_t' => 'att_view.tpl'));
3147 $this->t->set_block('att_view_t','act_list','list');
3149 $this->t->set_block('att_view_t','month_list','list1');
3150 $this->t->set_block('att_view_t','header_list','list2');
3151 $this->t->set_block('att_view_t','individual_list','list3');
3153 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3154 $num_quarters = get_var('num_quarters',array('GET','POST'));
3155 if($num_quarters == '') { $num_quarters = $this->default_att_num_quarters; }
3156 $this->t->set_var('num_quarters',$num_quarters);
3157 $this->t->set_var('lang_filter','Filter');
3158 if($num_quarters == 1) {
3159 $this->t->set_var('lang_num_quarters','Quarter of History');
3161 $this->t->set_var('lang_num_quarters','Quarters of History');
3164 $num_months = $num_quarters * 3;
3165 $current_month = $this->current_month;
3166 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
3167 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
3168 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
3169 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
3171 // TODO: changed this so it picks the quorum dynamically
3172 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1";
3173 $this->db->query($sql,__LINE__,__FILE__);
3175 while ($this->db->next_record()) {
3176 $individual_name[$i] = $this->db->f('name');
3177 $individual[$i] = $this->db->f('individual');
3180 array_multisort($individual_name, $individual);
3182 // Create a list of sunday dates for a window of 3 months back and current month
3186 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, ($current_month-$num_months)+1, 1, date("y")));
3187 $last_date = explode("-",$sunday_list[0]['date']);
3188 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3189 $time_limit = mktime(0, 0, 0, $current_month, 31, date("y"));
3190 while($last_time < $time_limit) {
3191 $day = date("w",$last_time);
3192 if(date("w",$last_time) == 0) {
3193 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3194 $last_date = explode("-",$sunday_list[$i]['date']);
3195 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3196 $sunday_list[$i]['day'] = $last_date[2];
3197 $sunday_list[$i]['month'] = date("M",$last_time);
3198 $sunday_list[$i]['year'] = $last_date[0];
3200 $last_date = $sunday_list[$i]['date'];
3202 $last_time += 90000;
3203 if($found_sunday) { $i++; $found_sunday=0; }
3206 $total_individuals = count($individual);
3207 $old_month=$sunday_list[0]['month']; $span=0;
3208 for ($i=0; $i < count($sunday_list); $i++) {
3209 $date = $sunday_list[$i]['date'];
3210 $this->t->set_var('date',$sunday_list[$i]['date']);
3211 $this->t->set_var('day',$sunday_list[$i]['day']);
3212 if(($old_month != $sunday_list[$i]['month']) || $i == count($sunday_list)-1) {
3213 if($i == count($sunday_list)-1) { $span++; }
3214 $cur_month = $sunday_list[$i]['month'];
3215 $old_month = $sunday_list[$i]['month'];
3216 $link_data['menuaction'] = 'tc.tc.att_update';
3217 $link_data['month'] = $sunday_list[$i-1]['month'];
3218 $link_data['year'] = $sunday_list[$i-1]['year'];
3219 $link_data['action'] = 'update_month';
3220 $cur_month = $sunday_list[$i-1]['month'];
3221 $cur_year = $sunday_list[$i-1]['year'];
3222 $header_row .= "<th><font size=-3>$cur_month $cur_year</font></th>";
3223 $this->t->set_var('update_month',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3224 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3225 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3226 $this->t->set_var('span',$span); $span=0;
3227 $this->t->fp('list1','month_list',True);
3231 $this->t->set_var('total_individuals',$total_individuals);
3232 $this->t->set_var('header_row',$header_row);
3234 $individual_width=200; $att_width=25; $total_width=$individual_width;
3235 for ($i=0; $i < count($sunday_list); $i++) {
3236 $link_data['menuaction'] = 'tc.tc.att_update';
3237 $link_data['month'] = $sunday_list[$i]['month'];
3238 $link_data['year'] = $sunday_list[$i]['year'];
3239 $link_data['day'] = $sunday_list[$i]['day'];
3240 $link_data['date'] = $sunday_list[$i]['date'];
3241 $link_data['action'] = 'update_day';
3242 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3243 $this->t->set_var('date',$sunday_list[$i]['date']);
3244 $this->t->set_var('day',$sunday_list[$i]['day']);
3245 $this->t->set_var('month',$sunday_list[$i]['month']);
3246 $this->t->set_var('year',$sunday_list[$i]['year']);
3247 $this->t->fp('list2','header_list',True);
3248 $total_width += $att_width;
3249 $attendance[$monthnum[$sunday_list[$i]['month']]]=0;
3252 for ($i=0; $i < count($individual); $i++) {
3254 $this->nextmatchs->template_alternate_row_color(&$this->t);
3255 $this->t->set_var('individual_name',$individual_name[$i]);
3256 #print "checking for individual: " . $individual[$i] . "<br>";
3257 for ($j=0; $j < count($sunday_list); $j++) {
3258 #print "checking for date: " . $sunday_list[$j]['date'] . "<br>";
3259 #print "SELECT * FROM tc_attendance WHERE date='"
3260 # . $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i] . "<br>";
3261 $sql = "SELECT * FROM tc_attendance WHERE date='" .
3262 $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i];
3263 $this->db->query($sql,__LINE__,__FILE__);
3264 if($this->db->next_record()) {
3265 $cur_month = $sunday_list[$j]['month'];
3266 if($attended[$i][$cur_month] != 1) {
3267 $attended[$i][$cur_month]=1;
3268 $attendance[$monthnum[$cur_month]]++;
3270 $att_table .= '<td align=center><img src="images/checkmark.gif"></td>';
3272 $att_table .= '<td> </td>';
3275 $this->t->set_var('att_table',$att_table);
3276 $this->t->fp('list3','individual_list',True);
3278 $this->t->set_var('total_width',$total_width);
3279 $this->t->set_var('individual_width',$individual_width);
3280 $this->t->set_var('att_width',$att_width);
3282 # Now calculate attendance for these months
3283 $attendance_str = "";
3284 $nonattendance_str = "";
3285 $aveattendance_str = "";
3286 $avenonattendance_str = "";
3288 $ave_total_attended=0;
3290 foreach($attendance as $att => $value) {
3291 $total_attended = $attendance[$att];
3292 $ave_total_attended += $attendance[$att]; $num_months++;
3293 $percent = ceil(($total_attended / $total_individuals)*100);
3294 $attendance_str.="<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3295 $total_nonattended = $total_individuals - $total_attended;
3296 $percent = ceil(($total_nonattended / $total_individuals)*100);
3297 $nonattendance_str.="<td align=center><font size=-2><b>$total_nonattended ($percent%)</b></font></td>";
3299 $total_attended = ceil(($ave_total_attended / $num_months));
3300 $percent = ceil(($total_attended / $total_individuals)*100);
3301 $aveattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3302 $total_attended = $total_individuals - ceil(($ave_total_attended / $num_months));
3303 $percent = ceil(($total_attended / $total_individuals)*100);
3304 $avenonattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3307 $this->t->set_var('attendance',$attendance_str);
3308 $this->t->set_var('aveattendance',$aveattendance_str);
3309 $this->t->set_var('nonattendance',$nonattendance_str);
3310 $this->t->set_var('avenonattendance',$avenonattendance_str);
3312 $this->t->pfp('out','att_view_t');
3313 $this->save_sessiondata();
3316 function att_update()
3318 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3319 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3320 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3322 $this->t->set_file(array('form' => 'att_update.tpl'));
3323 $this->t->set_block('form','edit','edithandle');
3325 $this->t->set_block('form','month_list','list1');
3326 $this->t->set_block('form','header_list','list2');
3327 $this->t->set_block('form','individual_list','list3');
3329 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3331 $action = get_var('action',array('GET','POST'));
3332 $month = get_var('month',array('GET','POST'));
3333 $year = get_var('year',array('GET','POST'));
3334 $day = get_var('day',array('GET','POST'));
3335 $date = get_var('date',array('GET','POST'));
3337 if($action == 'save_month' || $action == 'save_day') {
3338 $new_data = get_var('individuals_attended',array('POST'));
3339 $month = $monthnum[$month]; if($month < 10) { $month = "0" . $month; }
3341 if($action == 'save_month') {
3342 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-%'",__LINE__,__FILE__);
3345 if($action == 'save_day') {
3346 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-".$day."'",__LINE__,__FILE__);
3349 foreach ($new_data as $data) {
3350 $data_array = explode("-",$data);
3351 $indiv = $data_array[0];
3352 $date = "$data_array[1]-$data_array[2]-$data_array[3]";
3353 $this->db->query("INSERT INTO tc_attendance (individual,date) " .
3354 "VALUES (" . $indiv . ",'". $date . "')",__LINE__,__FILE__);
3361 // TODO: changed this so it picks the quorum dynamically
3362 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1";
3363 $this->db->query($sql,__LINE__,__FILE__);
3365 while ($this->db->next_record()) {
3366 $indiv_name[$i] = $this->db->f('name');
3367 $individual[$i] = $this->db->f('individual');
3368 $indiv_attending[$individual[$i]] = $this->db->f('attending');
3371 array_multisort($indiv_name, $individual);
3373 if($action == 'update_month') {
3374 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_month'));
3378 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], 1, $year));
3379 $last_date = explode("-",$sunday_list[0]['date']);
3380 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3381 $time_limit = mktime(0, 0, 0, $monthnum[$month], 31, $year);
3382 while($last_time <= $time_limit) {
3383 $day = date("w",$last_time);
3384 if(date("w",$last_time) == 0) {
3385 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3386 $last_date = explode("-",$sunday_list[$i]['date']);
3387 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3388 $sunday_list[$i]['day'] = $last_date[2];
3389 $sunday_list[$i]['month'] = date("M",$last_time);
3390 $sunday_list[$i]['year'] = $last_date[0];
3393 $last_time += 90000;
3394 if($found_sunday) { $i++; $found_sunday=0; }
3397 $this->t->set_var('span', $i);
3398 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3399 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3400 $this->t->fp('list1','month_list',True);
3401 $indiv_width=200; $att_width=25; $total_width=$indiv_width;
3402 for ($i=0; $i < count($sunday_list); $i++) {
3403 $link_data['menuaction'] = 'tc.tc.att_update';
3404 $link_data['month'] = $sunday_list[$i]['month'];
3405 $link_data['year'] = $sunday_list[$i]['year'];
3406 $link_data['day'] = $sunday_list[$i]['day'];
3407 $link_data['date'] = $sunday_list[$i]['date'];
3408 $link_data['action'] = 'update_day';
3409 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3410 $this->t->set_var('date',$sunday_list[$i]['date']);
3411 $this->t->set_var('day',$sunday_list[$i]['day']);
3412 $this->t->set_var('month',$sunday_list[$i]['month']);
3413 $this->t->set_var('year',$sunday_list[$i]['year']);
3414 $this->t->fp('list2','header_list',True);
3415 $total_width += $att_width;
3419 if($action == 'update_day') {
3420 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_day'));
3421 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], $day, $year));
3422 $this->t->set_var('month',$month);
3423 $this->t->set_var('year',$year);
3424 $this->t->fp('list1','month_list',True);
3425 $this->t->set_var('date',$date);
3426 $this->t->set_var('day',$day);
3427 $this->t->set_var('month',$month);
3428 $this->t->set_var('year',$year);
3429 $this->t->fp('list2','header_list',True);
3432 for ($i=0; $i < count($individual); $i++) {
3434 $this->nextmatchs->template_alternate_row_color(&$this->t);
3435 $this->t->set_var('individual_name',$indiv_name[$i]);
3436 for ($j=0; $j < count($sunday_list); $j++) {
3437 $sql = "SELECT * FROM tc_attendance WHERE date='" .
3438 $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i];
3439 $this->db->query($sql,__LINE__,__FILE__);
3440 $value = $individual[$i] . "-" . $sunday_list[$j]['date'];
3441 if($this->db->next_record()) {
3442 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'" checked></td>';
3443 } else if($indiv_attending[$individual[$i]] == 1) {
3444 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'" checked></td>';
3446 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'"></td>';
3449 $this->t->set_var('att_table',$att_table);
3450 $this->t->fp('list3','individual_list',True);
3453 $this->t->set_var('lang_done', 'Cancel');
3454 $this->t->set_var('lang_reset','Clear Form');
3455 $this->t->set_var('lang_save','Save Changes');
3457 $this->t->pfp('out','form');
3458 $this->t->pfp('addhandle','edit');
3460 $this->save_sessiondata();
3465 $this->t->set_file(array('dir_view_t' => 'dir_view.tpl'));
3466 $this->t->set_block('dir_view_t','dir_list','list');
3468 $sql = "SELECT * FROM tc_individual where valid=1 and hh_position='Head of Household' ORDER BY name ASC";
3469 $this->db->query($sql,__LINE__,__FILE__);
3471 while ($this->db->next_record()) {
3472 $parent[$i]['id'] = $this->db->f('individual');
3473 $parent[$i]['name'] = $this->db->f('name');
3474 $parent[$i]['phone'] = $this->db->f('phone');
3475 $parent[$i]['address'] = $this->db->f('address');
3479 for ($i=0; $i < count($parent); $i++) {
3480 $name = $parent[$i]['name'];
3481 $phone = $parent[$i]['phone'];
3482 $address = $parent[$i]['address'];
3483 $this->t->set_var('name', $name);
3484 $this->t->set_var('address', $address);
3485 $this->t->set_var('phone', $phone);
3486 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3487 $this->t->set_var('tr_color',$tr_color);
3488 $this->t->fp('list','dir_list',True);
3489 //print "$phone $name $address<br>";
3491 $this->t->pfp('out','dir_view_t');
3492 $this->save_sessiondata();
3497 $this->t->set_file(array('org_view_t' => 'org_view.tpl'));
3498 $this->t->set_block('org_view_t','calling_list','list1');
3499 $this->t->set_block('org_view_t','org_list','list2');
3501 # Display a list ordered alphabetically
3502 $sql = "SELECT * FROM tc_calling ORDER BY name ASC";
3503 $this->db->query($sql,__LINE__,__FILE__);
3505 while ($this->db->next_record()) {
3506 $calling[$i]['name'] = $this->db->f('name');
3507 $calling[$i]['position'] = $this->db->f('position');
3508 $calling[$i]['sustained'] = $this->db->f('sustained');
3509 $calling[$i]['organization'] = $this->db->f('organization');
3512 for ($i=0; $i < count($calling); $i++) {
3513 $name = $calling[$i]['name'];
3514 $position = $calling[$i]['position'];
3515 $sustained = $calling[$i]['sustained'];
3516 $organization = $calling[$i]['organization'];
3517 $this->t->set_var('name', $name);
3518 $this->t->set_var('position', $position);
3519 $this->t->set_var('sustained', $sustained);
3520 $this->t->set_var('organization', $organization);
3521 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3522 $this->t->set_var('tr_color',$tr_color);
3523 $this->t->fp('list1','calling_list',True);
3526 # Display a list ordered by organization
3527 $sql = "SELECT * FROM tc_calling ORDER BY organization ASC";
3528 $this->db->query($sql,__LINE__,__FILE__);
3530 while ($this->db->next_record()) {
3531 $calling[$i]['name'] = $this->db->f('name');
3532 $calling[$i]['position'] = $this->db->f('position');
3533 $calling[$i]['sustained'] = $this->db->f('sustained');
3534 $calling[$i]['organization'] = $this->db->f('organization');
3537 for ($i=0; $i < count($calling); $i++) {
3538 $name = $calling[$i]['name'];
3539 $position = $calling[$i]['position'];
3540 $sustained = $calling[$i]['sustained'];
3541 $organization = $calling[$i]['organization'];
3542 $this->t->set_var('name', $name);
3543 $this->t->set_var('position', $position);
3544 $this->t->set_var('sustained', $sustained);
3545 $this->t->set_var('organization', $organization);
3546 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3547 $this->t->set_var('tr_color',$tr_color);
3548 $this->t->fp('list2','org_list',True);
3551 $this->t->pfp('out','org_view_t');
3552 $this->save_sessiondata();
3557 $this->t->set_file(array('sched_t' => 'schedule.tpl'));
3558 $this->t->set_block('sched_t','presidency_list','list');
3560 $action = get_var('action',array('GET','POST'));
3562 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule&action=save'));
3563 $this->t->set_var('title','Scheduling Tool');
3565 $this->t->set_var('lang_save','Save Schedule');
3566 $this->t->set_var('lang_reset','Cancel');
3568 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
3569 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
3571 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
3572 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
3574 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
3575 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
3577 $date_width=150; $time_width=220; $indiv_width=170; $family_width=180; $location_width=100;
3578 $table_width=$date_width + $time_width + $indiv_width + $family_width + $location_width;
3579 $header_row = "<th width=$date_width><font size=-2>Date</th>";
3580 $header_row.= "<th width=$time_width><font size=-2>Time</th>";
3581 $header_row.= "<th width=$indiv_width><font size=-2>individual</th>";
3582 $header_row.= "<th width=$family_width><font size=-2>Family</th>";
3583 $header_row.= "<th width=$location_width><font size=-2>Location</th>";
3586 $sql = "SELECT * FROM tc_presidency where valid=1 GROUP BY individual ORDER BY name ASC";
3587 $this->db->query($sql,__LINE__,__FILE__);
3589 while ($this->db->next_record()) {
3590 $presidency_data[$i]['id'] = $this->db->f('presidency');
3591 $presidency_data[$i]['name'] = $this->db->f('name');
3592 $presidency_data[$i]['indiv'] = $this->db->f('individual');
3593 $presidency2name[$presidency_data[$i]['id']] = $presidency_data[$i]['name'];
3594 $presidency2indiv[$presidency_data[$i]['id']] = $presidency_data[$i]['individual'];
3598 $sql = "SELECT * FROM tc_family where valid=1 and individual != 0 ORDER BY name ASC";
3599 $this->db->query($sql,__LINE__,__FILE__);
3601 while ($this->db->next_record()) {
3602 $family_id[$i] = $this->db->f('family');
3603 $family_name[$i] = $this->db->f('name');
3604 $familyid2name[$family_id[$i]] = $family_name[$i];
3605 $sql = "SELECT * FROM tc_individual where family='$family_id[$i]' and hh_position='Head of Household'";
3606 $this->db2->query($sql,__LINE__,__FILE__);
3607 if($this->db2->next_record()) {
3608 $familyid2address[$family_id[$i]] = $this->db2->f('address');
3612 array_multisort($family_name, $family_id);
3614 if($action == 'save') {
3615 $new_data = get_var('sched',array('POST'));
3616 foreach ($new_data as $presidency_array) {
3617 foreach ($presidency_array as $entry) {
3618 $presidency = $entry['presidency'];
3619 $appointment = $entry['appointment'];
3620 $location = $entry['location'];
3621 $date = $entry['date'];
3622 $hour = $entry['hour'];
3623 $minute = $entry['minute'];
3625 $indiv = $entry['individual'];
3626 $family = $entry['family'];
3627 $location = $entry['location'];
3628 if($pm) { $hour = $hour + 12; }
3629 $time = $hour.':'.$minute.':'.'00';
3632 // Update our location
3633 if($location == "") {
3635 $family_name_array = explode(",", $familyid2name[$family]);
3636 $family_last_name = $family_name_array[0];
3637 $family_address = $familyid2address[$family];
3638 $location = "$family_last_name"." home ($family_address)";
3639 } else if($indiv > 0) {
3640 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
3641 $supervisor_last_name = $supervisor_name_array[0];
3642 $sql = "SELECT * FROM tc_individual where individual='$presidency2indiv[$presidency]'";
3643 $this->db2->query($sql,__LINE__,__FILE__);
3644 if($this->db2->next_record()) {
3645 $mls_id = $this->db2->f('mls_id');
3647 $sql = "SELECT * FROM tc_individual where mls_id='$mls_id'";
3648 $this->db2->query($sql,__LINE__,__FILE__);
3649 if($this->db2->next_record()) {
3650 $supervisor_address = $this->db2->f('address');
3652 $location = "$supervisor_last_name"." home ($supervisor_address)";
3656 // Zero out the family or individual if date = NULL
3663 if(($indiv == 0) && ($family == 0)) { $location = ""; }
3665 // Update an existing appointment
3666 if($appointment < $this->max_appointments)
3668 //Only perform a database update if we have made a change to this appointment
3669 $sql = "SELECT * FROM tc_appointment where " .
3670 "appointment='$appointment'" .
3671 " and presidency='$presidency'" .
3672 " and individual='$indiv'" .
3673 " and family='$family'" .
3674 " and date='$date'" .
3675 " and time='$time'" .
3676 " and location='$location'";
3677 $this->db->query($sql,__LINE__,__FILE__);
3678 if(!$this->db->next_record()) {
3679 $old_date = $this->db->f('date');
3680 $old_time = $this->db->f('time');
3681 $this->db2->query("UPDATE tc_appointment set" .
3682 " family=" . $family .
3683 " ,individual=" . $indiv .
3684 " ,date='" . $date . "'" .
3685 " ,time='" . $time . "'" .
3686 " ,location='" . $location . "'" .
3687 " ,presidency='" . $presidency . "'" .
3688 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
3690 // Email the appointment
3691 $this->email_appt($appointment);
3695 // Add a new appointment
3696 else if(($appointment >= $this->max_appointments) && ($date != "") && ($time != ""))
3698 //print "adding entry: appt=$appointment date: $date time: $time individual: $indiv family: $family<br>";
3699 $this->db2->query("INSERT INTO tc_appointment (appointment,presidency,family,individual,date,time,location,uid) " .
3700 "VALUES (NULL,'" . $presidency . "','" . $family . "','" . $indiv . "','" .
3701 $date . "','" . $time . "','" . $location . "','" . $uid ."')",__LINE__,__FILE__);
3703 // Now reselect this entry from the database to see if we need
3704 // to send an appointment out for it.
3705 $sql = "SELECT * FROM tc_appointment where " .
3706 "individual='$indiv'" .
3707 " and family='$family'" .
3708 " and presidency='$presidency'" .
3709 " and date='$date'" .
3710 " and time='$time'" .
3712 " and location='$location'";
3713 $this->db3->query($sql,__LINE__,__FILE__);
3714 if($this->db3->next_record()) {
3715 // Email the appointment if warranted
3716 if(($date != "") && ($time != "") && (($indiv > 0) || $family > 0)) {
3717 $this->email_appt($this->db3->f('appointment'));
3724 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule');
3725 //Header('Location: ' . $take_me_to_url);
3728 // TODO: changed this so it picks the quorum dynamically
3729 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1 ORDER BY individual ASC";
3730 $this->db->query($sql,__LINE__,__FILE__);
3732 while ($this->db->next_record()) {
3733 $individual[$i] = $this->db->f('individual');
3734 $indiv_name[$i] = $this->db->f('name');
3735 $indiv_phone[$individual[$i]] = $this->db->f('phone');
3738 array_multisort($indiv_name, $individual);
3740 for ($i=0; $i < count($presidency_data); $i++) {
3741 $presidency = $presidency_data[$i]['id'];
3742 $interviewer = $presidency_data[$i]['individual'];
3743 $name = $presidency_data[$i]['name'];
3744 $this->t->set_var('presidency_name',$name);
3747 // query the database for all the appointments
3748 $sql = "SELECT * FROM tc_appointment where presidency=$presidency and date>=CURDATE() ORDER BY date ASC, time ASC";
3749 $this->db->query($sql,__LINE__,__FILE__);
3751 // Prefill any existing appointment slots
3752 while ($this->db->next_record()) {
3753 $appointment = $this->db->f('appointment');
3754 $indiv = $this->db->f('individual');
3755 $family = $this->db->f('family');
3756 $location = $this->db->f('location');
3758 if($location == "") {
3760 $family_name_array = explode(",", $familyid2name[$family]);
3761 $family_last_name = $family_name_array[0];
3762 $family_address = $familyid2address[$family];
3763 $location = "$family_last_name"." home ($family_address)";
3764 } else if($indiv > 0) {
3765 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
3766 $supervisor_last_name = $supervisor_name_array[0];
3767 $sql = "SELECT * FROM tc_individual where individual='$presidency2indiv[$presidency]'";
3768 $this->db2->query($sql,__LINE__,__FILE__);
3769 if($this->db2->next_record()) {
3770 $mls_id = $this->db2->f('mls_id');
3772 $sql = "SELECT * FROM tc_individual where mls_id='$mls_id'";
3773 $this->db2->query($sql,__LINE__,__FILE__);
3774 if($this->db2->next_record()) {
3775 $supervisor_address = $this->db2->f('address');
3777 $location = "$supervisor_last_name"." home ($supervisor_address)";
3781 $date = $this->db->f('date');
3782 $date_array = explode("-",$date);
3783 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
3784 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
3786 $time = $this->db->f('time');
3787 $time_array = explode(":",$time);
3788 $hour = $time_array[0];
3789 $minute = $time_array[1];
3791 if($hour > 12) { $pm=1; $hour = $hour - 12; }
3792 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
3794 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3797 $table_data.= '<td align=left>';
3798 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]',$date,'','','','','',$this->cal_options);
3799 $table_data.= '</td>';
3801 // Hour & Minutes selection
3802 $table_data.= "<td align=center>";
3803 $table_data .= $this->get_time_selection_form($hour, $minute, $pm, $presidency, $appointment);
3804 $table_data.= "</td>";
3806 // individual drop down list (for PPIs)
3807 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][indiv] STYLE="font-size : 8pt">';
3808 $table_data.= '<option value=0></option>';
3809 for ($j=0; $j < count($individual); $j++) {
3810 $id = $individual[$j];
3811 $name = $indiv_name[$j];
3812 if($individual[$j] == $indiv) {
3813 $selected[$id] = 'selected="selected"';
3815 $selected[$id] = '';
3817 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
3819 $table_data.='</select></td>';
3821 // Family drop down list (for Visits)
3822 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family] STYLE="font-size : 8pt">';
3823 $table_data.= '<option value=0></option>';
3824 for ($j=0; $j < count($individual); $j++) {
3825 $id = $family_id[$j];
3826 $name = $family_name[$j];
3827 if($family_id[$j] == $family) {
3828 $selected[$id] = 'selected="selected"';
3830 $selected[$id] = '';
3832 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
3834 $table_data.='</select></td>';
3836 // Location text box
3837 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
3838 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="'.$location.'" STYLE="font-size : 8pt">';
3840 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3841 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3843 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3844 $this->t->set_var('tr_color',$tr_color);
3847 // Create blank appointment slot
3848 for ($b=0; $b < 4; $b++) {
3849 $appointment = $this->max_appointments + $b;
3850 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3853 $table_data.= '<td align=left>';
3854 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]','','','','','','',$this->cal_options);
3855 $table_data.= '</td>';
3858 $table_data.= "<td align=center>";
3859 $table_data .= $this->get_time_selection_form(0, 0, 0, $presidency, $appointment);
3860 $table_data.= "</td>";
3862 // individual drop down list
3863 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][indiv] STYLE="font-size : 8pt">';
3864 $table_data.= '<option value=0></option>';
3865 for ($j=0; $j < count($individual); $j++) {
3866 $id = $individual[$j];
3867 $name = $indiv_name[$j];
3868 $table_data.= '<option value='.$id.'>'.$name.'</option>';
3870 $table_data.='</select></td>';
3872 // Family drop down list
3873 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family] STYLE="font-size : 8pt">';
3874 $table_data.= '<option value=0></option>';
3875 for ($j=0; $j < count($individual); $j++) {
3876 $id = $family_id[$j];
3877 $name = $family_name[$j];
3878 $table_data.= '<option value='.$id.'>'.$name.' Family</option>';
3880 $table_data.='</select></td>';
3882 // Location text box
3883 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
3884 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="" STYLE="font-size : 8pt">';
3886 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3887 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3889 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3890 $this->t->set_var('tr_color',$tr_color);
3893 $this->t->set_var('table_data',$table_data);
3894 $this->t->set_var('header_row',$header_row);
3895 $this->t->set_var('table_width',$table_width);
3896 $this->t->fp('list','presidency_list',True);
3899 $this->t->pfp('out','sched_t');
3900 $this->save_sessiondata();
3905 $this->t->set_file(array('email_t' => 'email.tpl'));
3906 $this->t->set_block('email_t','individual_list','list');
3908 $action = get_var('action',array('GET','POST'));
3910 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email'));
3911 $this->t->set_var('title','Email Tool');
3913 $this->t->set_var('lang_email','Send Email');
3914 $this->t->set_var('lang_reset','Cancel');
3916 $this->t->set_var('email_member_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=member'));
3917 $this->t->set_var('email_member_link_title','Email Quorum Member');
3919 $this->t->set_var('email_quorum_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=quorum'));
3920 $this->t->set_var('email_quorum_link_title','Email Quorum');
3922 $this->t->set_var('email_reminder_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=reminder'));
3923 $this->t->set_var('email_reminder_link_title','Email Reminders');
3925 $this->t->set_var('email_edit_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=edit'));
3926 $this->t->set_var('email_edit_link_title','Edit Email Addresses');
3929 $this->t->set_var('table_width',$table_width);
3931 $this->t->pfp('out','email_t');
3932 $this->save_sessiondata();
3937 $this->t->set_file(array('admin_t' => 'admin.tpl'));
3938 $this->t->set_block('admin_t','upload','uploadhandle');
3939 $this->t->set_block('admin_t','admin','adminhandle');
3940 $this->t->set_block('admin_t','cmd','cmdhandle');
3941 $this->t->set_block('admin_t','presidency','presidencyhandle');
3943 $this->t->set_var('upload_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=upload'));
3944 $this->t->set_var('presidency_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=presidency'));
3946 $action = get_var('action',array('GET','POST'));
3948 $this->t->pfp('out','admin_t');
3950 // TODO: changed this so it picks the quorum dynamically
3951 $sql = "SELECT * FROM tc_individual where steward='Elder' and valid=1 ORDER BY individual ASC";
3952 $this->db->query($sql,__LINE__,__FILE__);
3954 while ($this->db->next_record()) {
3955 $individual[$i] = $this->db->f('individual');
3956 $indiv_name[$i] = $this->db->f('name');
3957 $indiv2name[$individual[$i]] = $indiv_name[$i];
3960 array_multisort($indiv_name, $individual);
3962 if($action == 'upload') {
3963 $target_path = $this->upload_target_path . '/' . basename( $_FILES['uploadedfile']['name']);
3965 if(($_FILES['uploadedfile']['type'] == "application/zip") ||
3966 ($_FILES['uploadedfile']['type'] == "application/x-zip-compressed") ||
3967 ($_FILES['uploadedfile']['type'] == "application/x-zip") ||
3968 ($_FILES['uploadedfile']['type'] == "application/octet-stream")) {
3970 if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
3971 $uploadstatus = "<b><font color=red> -E- Unable to move the uploaded file to ";
3972 $uploadstatus.= "the target path (check the path and permissions) of: $target_path</font></b>";
3973 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
3974 $uploadstatus.= "Tmp Filename : " . $_FILES['uploadedfile']['tmp_name'] . "<br>";
3975 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
3976 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
3977 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
3978 $uploadstatus.= "Error : " . $_FILES['uploadedfile']['error'] . "<br>";
3979 $this->t->set_var('uploadstatus',$uploadstatus);
3980 $this->t->pfp('uploadhandle','upload',True);
3984 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
3985 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
3986 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
3987 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
3988 $this->t->set_var('uploadstatus',$uploadstatus);
3989 $this->t->pfp('uploadhandle','upload');
3990 $this->t->set_var('uploadhandle','');
3991 print "<table border=1 width=80%><tr><td>\n<pre>";
3993 # make a directory for this data to be stored in
3994 $date="data_" . date("Y_m_d");
3995 $data_dir = $this->upload_target_path . '/' . $date;
3996 print "-> Making the data directory: $date<br>\n";
3997 exec('mkdir -p ' . $data_dir . ' 2>&1', $result, $return_code);
3998 if($return_code != 0) {
3999 print implode('\n',$result) . "<br>";
4000 print "<b><font color=red>";
4001 print "-E- Unable to create the data directory. Aborting import.";
4002 print "</font></b>";
4006 # move the file uploaded into this directory
4007 print "-> Moving the uploaded file into the data dir<br>\n";
4008 exec('mv ' . $target_path . ' ' . $data_dir . '/' . ' 2>&1', $result, $return_code);
4009 if($return_code != 0) {
4010 print implode('\n',$result) . "<br>";
4011 print "<b><font color=red>";
4012 print "-E- Unable to move the uploaded file into the data dir. Aborting import.";
4013 print "</font></b>";
4017 # unzip the data into this directory
4018 print "-> Unzipping the data<br>\n";
4019 exec($this->unzip_path .' -u '. $data_dir . '/*.zip -d ' . $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 unzip the uploaded file into the data dir: $data_dir. Aborting import.";
4024 print "</font></b>";
4027 exec('mv ' . $data_dir . '/*/* '. $data_dir . ' 2>&1', $result, $return_code);
4029 # update the data_latest link to point to this new directory
4030 print "-> Updating the latest data dir link<br>\n";
4031 $data_latest = $this->upload_target_path . '/data_latest';
4032 exec('rm ' . $data_latest. '; ln -s ' . $data_dir .' '. $data_latest .' 2>&1', $result, $return_code);
4033 if($return_code != 0) {
4034 print implode('\n',$result) . "<br>";
4035 print "<b><font color=red>";
4036 print "-E- Unable to update the data latest link. Aborting import.";
4037 print "</font></b>";
4041 # run the import perl script to encorporate it into the DB
4042 ob_start('ob_logstdout', 2);
4043 print "-> Importing the data into the database<br>\n";
4044 ob_flush(); flush(); sleep(1);
4045 $import_log = $this->upload_target_path . '/import.log';
4046 $data_log = $this->upload_target_path . '/data.log';
4047 $import_cmd = $this->script_path . '/import_ward_data ' . $data_latest . ' 2>&1 | tee ' . $import_log;
4048 $parse_cmd = $this->script_path . '/parse_ward_data -v ' . $data_latest . ' > ' . $data_log . '2>&1';
4049 #print "import_cmd: $import_cmd<br>";
4050 #print "parse_cmd: $parse_cmd<br>";
4051 ob_start('ob_logstdout', 2);
4052 passthru($import_cmd);
4053 passthru($parse_cmd);
4054 ob_flush(); flush(); sleep(1);
4056 # fix the permissions of the data dir
4057 exec('chmod -R o-rwx ' . $data_dir, $result, $return_code);
4059 $this->t->pfp('cmdhandle','cmd');
4060 print "</pre></td></tr></table>";
4061 } else if(($_FILES['uploadedfile']['type'] != "application/zip") &&
4062 ($_FILES['uploadedfile']['type'] != "application/x-zip-compressed") &&
4063 ($_FILES['uploadedfile']['type'] != "application/x-zip") &&
4064 ($_FILES['uploadedfile']['type'] != "application/octet-stream")) {
4065 $uploadstatus = "<b><font color=red>The file format must be a .zip file, please try again! </font></b>";
4066 $uploadstatus.= "<br><br><b>Detected file format: " . $_FILES['uploadedfile']['type'] . "</b>";
4067 $this->t->set_var('uploadstatus',$uploadstatus);
4068 $this->t->pfp('uploadhandle','upload',True);
4070 $uploadstatus = "<b><font color=red> There was an error (" . $_FILES['uploadedfile']['error'];
4071 $uploadstatus.= ") uploading the file, please try again! </font></b>";
4072 $this->t->set_var('uploadstatus',$uploadstatus);
4073 $this->t->pfp('uploadhandle','upload',True);
4075 } else if($action == "presidency") {
4076 $new_data = get_var('eqpres',array('POST'));
4077 foreach ($new_data as $entry) {
4079 $email = $entry['email'];
4080 $indiv = $entry['indiv'];
4081 $name = $entry['name'];
4082 $district = $entry['district'];
4083 $president = $entry['president'];
4084 $counselor = $entry['counselor'];
4085 $secretary = $entry['secretary'];
4086 // look up the individual name for the ID
4087 $name = $indiv2name[$indiv];
4088 //print "id=$id indiv=$indiv name=$name email=$email district=$district president=$president ";
4089 //print "counselor=$counselor secretary=$secretary<br>";
4091 if(($indiv > 0) || ($name != "")) {
4092 if($id < $this->max_presidency_members) {
4093 //print "Updating Existing Entry<br>";
4094 $this->db2->query("UPDATE tc_presidency set" .
4095 " individual=" . $indiv .
4096 " ,district=" . $district .
4097 " ,name='" . $name . "'" .
4098 " ,email='" . $email . "'" .
4099 " ,president='" . $president . "'" .
4100 " ,counselor='" . $counselor . "'" .
4101 " ,secretary='" . $secretary . "'" .
4102 " WHERE presidency=" . $id,__LINE__,__FILE__);
4104 //print "Adding New Entry<br>";
4105 $this->db2->query("INSERT INTO tc_presidency (presidency,individual,district,name," .
4106 "email,president,counselor,secretary,valid) " .
4107 "VALUES (NULL,'" . $indiv . "','" . $district . "','" .
4108 $name . "','" . $email . "','" . $president . "','" .
4109 $counselor . "','" . $secretary . "','1'" .
4110 ")",__LINE__,__FILE__);
4113 //print "Ignoring Blank Entry<br>";
4117 // Now update the tc_district table appropriately
4119 // Delete all the previous district entries from the table
4120 $this->db->query("DELETE from tc_district where valid=1",__LINE__,__FILE__);
4121 $this->db->query("DELETE from tc_district where valid=0",__LINE__,__FILE__);
4123 // Always add a "District 0" assigned to the High Priests Group
4125 $name = "High Priests";
4128 $this->db2->query("INSERT INTO tc_district (district,name,supervisor,valid) " .
4129 "VALUES ('" . $district . "','" . $name . "','" .
4130 $indiv . "','" . $valid . "'" .
4131 ")",__LINE__,__FILE__);
4133 // Requery the tc_presidency table
4134 $sql = "SELECT * FROM tc_presidency where valid=1";
4135 $this->db->query($sql,__LINE__,__FILE__);
4136 while ($this->db->next_record()) {
4137 // Extract the data for each presidency record
4138 $id = $this->db->f('presidency');
4139 $indiv = $this->db->f('individual');
4140 $name = $this->db->f('name');
4141 $district = $this->db->f('district');
4142 $name = $this->db->f('name');
4145 // If we have a valid district, add it to the district table
4147 $this->db2->query("INSERT INTO tc_district (district,name,supervisor,valid) " .
4148 "VALUES ('" . $district . "','" . $name . "','" .
4149 $indiv . "','" . $valid . "'" .
4150 ")",__LINE__,__FILE__);
4154 $this->t->set_var('adminhandle','');
4155 $this->t->pfp('adminhandle','admin');
4159 $this->t->set_var('adminhandle','');
4160 $this->t->pfp('adminhandle','admin');
4163 // Now save off the data needed for a Presidency Table Update
4165 $sql = "SELECT * FROM tc_presidency where valid=1";
4166 $this->db->query($sql,__LINE__,__FILE__);
4168 $header_row = "<th>Individual</th><th>Email</th><th>District</th><th>President</th><th>Counselor</th><th>Secretary</th>";
4169 while ($this->db->next_record()) {
4170 // Extract the data for each presidency record
4171 $id = $this->db->f('presidency');
4172 $indiv = $this->db->f('individual');
4173 $district = $this->db->f('district');
4174 $name = $this->db->f('name');
4175 $email = $this->db->f('email');
4176 $president = $this->db->f('president');
4177 $counselor = $this->db->f('counselor');
4178 $secretary = $this->db->f('secretary');
4180 // Create the forms needed in the table
4181 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4184 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4187 if($eqpresidency == 0) {
4188 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4189 $table_data.= '<option value=0></option>';
4190 for ($j=0; $j < count($individual); $j++) {
4191 $tmp_id = $individual[$j];
4192 $name = $indiv_name[$j];
4193 if($individual[$j] == $indiv) {
4195 $selected = 'selected="selected"';
4199 $table_data.= '<option value='.$tmp_id.' '.$selected.'>'.$name.'</option>';
4201 $table_data.='</select></td>';
4202 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="'.$indivname.'">';
4204 $table_data.= '<td align=left><input type=text size="20" name="eqpresname" value="Presidency"></td>';
4205 $table_data.= '<input type=hidden name="eqpres['.$id.'][name]" value="Presidency">';
4209 $table_data .= '<td><input type="text" size="50" name="eqpres['.$id.'][email]" value="'.$email.'"></td>';
4212 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4213 $table_data.= '<option value=0></option>';
4214 for ($j=0; $j <= $this->max_num_districts; $j++) {
4215 if($district == $j) {
4216 $selected = 'selected="selected"';
4220 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4222 $table_data.='</select></td>';
4225 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4226 if($president == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4227 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4228 $table_data.='</select></td>';
4231 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4232 if($counselor == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4233 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4234 $table_data.='</select></td>';
4237 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4238 if($secretary == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4239 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4240 $table_data.='</select></td>';
4243 $table_data .= "</tr>\n";
4244 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4245 $this->t->set_var('tr_color',$tr_color);
4248 // Now create 1 blank row to always have a line available to add a new individual with
4249 $id = $this->max_presidency_members;
4250 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4252 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4254 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4255 $table_data.= '<option value=0></option>';
4256 for ($j=0; $j < count($individual); $j++) {
4257 $tmp_id = $individual[$j];
4258 $name = $indiv_name[$j];
4259 $table_data.= '<option value='.$tmp_id.'>'.$name.'</option>';
4261 $table_data.='</select></td>';
4262 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="">';
4264 $table_data.='<td><input type="text" size="50" name="eqpres['.$id.'][email]" value=""></td>';
4266 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4267 $table_data.= '<option value=0></option>';
4268 for ($j=0; $j <= $this->max_num_districts; $j++) {
4270 $selected = 'selected="selected"';
4274 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4276 $table_data.='</select></td>';
4278 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4279 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4280 $table_data.='</select></td>';
4282 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4283 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4284 $table_data.='</select></td>';
4286 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4287 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4288 $table_data.='</select></td>';
4290 $table_data .= "</tr>\n";
4291 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4292 $this->t->set_var('tr_color',$tr_color);
4294 $this->t->set_var('header_row',$header_row);
4295 $this->t->set_var('table_data',$table_data);
4296 $this->t->pfp('presidencyhandle','presidency',True);
4298 $this->save_sessiondata();
4301 function email_appt($appointment)
4303 //print "Emailing notification of appointment: $appointment <br>";
4305 $sql = "SELECT * FROM tc_appointment where appointment='$appointment'";
4306 $this->db->query($sql,__LINE__,__FILE__);
4308 while ($this->db->next_record()) {
4309 $appointment = $this->db->f('appointment');
4310 $presidency = $this->db->f('presidency');
4311 $location = $this->db->f('location');
4314 $indiv = $this->db->f('individual');
4316 $family = $this->db->f('family');
4320 $uid = $this->db->f('uid');
4322 // Extract the year, month, day, hours, minutes, seconds from the appointment time
4323 $appt_date = $this->db->f('date');
4324 $date_array = explode("-",$appt_date);
4325 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
4326 $appt_time = $this->db->f('time');
4327 $time_array = explode(":",$appt_time);
4328 $hour = $time_array[0]; $minute = $time_array[1]; $seconds = $time_array[2];
4330 // Format the appointment time into an iCal UTC equivalent
4331 $dtstamp = gmdate("Ymd"."\T"."His"."\Z");
4332 $dtstart = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds,$month,$day,$year));
4333 $dtstartstr = date("l, F d, o g:i A", mktime($hour,$minute,$seconds,$month,$day,$year));
4335 $sql = "SELECT * FROM tc_presidency where presidency='$presidency'";
4336 $this->db2->query($sql,__LINE__,__FILE__);
4337 if($this->db2->next_record()) {
4338 $email = $this->db2->f('email');
4339 $interviewer = $this->db2->f('name');
4342 // Set the email address of the interviewer
4346 $sql = "SELECT * FROM tc_individual where individual='$indiv'";
4347 $this->db2->query($sql,__LINE__,__FILE__);
4348 if($this->db2->next_record()) {
4349 $indiv_name = $this->db2->f('name');
4350 $phone = $this->db2->f('phone');
4351 $appt_name = $indiv_name . " Interview";
4352 $duration = $this->default_ppi_appt_duration * 60;
4357 $sql = "SELECT * FROM tc_family where family='$family'";
4358 $this->db2->query($sql,__LINE__,__FILE__);
4359 if($this->db2->next_record()) {
4360 $family_name = $this->db2->f('name');
4361 $phone = $this->db2->f('phone');
4362 $individual = $this->db2->f('individual');
4363 $appt_name = $family_name . " Family Visit";
4364 $sql = "SELECT * FROM tc_individual where individual='$individual'";
4365 $this->db3->query($sql,__LINE__,__FILE__);
4366 if($this->db3->next_record()) {
4367 $phone = $this->db3->f('phone');
4369 $duration = $this->default_visit_appt_duration * 60;
4373 $dtend = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4374 $dtendstr = date("g:i A", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4375 $date = $dtstartstr . "-" . $dtendstr;
4376 $description = "$appt_name : $phone";
4378 if(($uid == 0) && ($appt_name != "")) {
4379 // Create a new calendar item for this appointment, since this must be the first time we
4380 // are sending it out.
4381 print "Sent new appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4382 $uid = rand() . rand(); // Generate a random identifier for this appointment
4383 $subject = "Created: $appt_name";
4385 $this->db->query("UPDATE tc_appointment set" .
4387 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4389 $action = "PUBLISH";
4390 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4391 $dtend, $date, $location, $appt_name, $description, $uid);
4392 } else if(($uid != 0) && ($appt_name == "")) {
4393 // Remove the calendar item for this appointment since it has already been sent
4394 // and there is no name we have changed it to.
4395 print "Sent deleted appointment to " . $interviewer . " at " . $email . " for " . $appt_date . " " . $appt_time . "<br>";
4396 $subject = "Canceled: $appt_date $appt_time";
4398 $this->db->query("UPDATE tc_appointment set" .
4400 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4403 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4404 $dtend, $date, $location, $subject, $subject, $uid);
4405 } else if($uid != 0) {
4406 // Update the existing appointment since we have changed it
4407 print "Sent updated appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4409 $subject = "Canceled: $appt_date $appt_time";
4411 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4412 $dtend, $date, $location, $subject, $subject, $uid);
4414 $uid = rand() . rand(); // Generate a random identifier for this appointment
4415 $this->db->query("UPDATE tc_appointment set" .
4417 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4419 $subject = "Updated: $appt_name";
4420 $action = "PUBLISH";
4421 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4422 $dtend, $date, $location, $appt_name, $description, $uid);
4428 function send_ical_appt($action, $to, $from, $subject, $dtstamp, $dtstart, $dtend, $date, $location, $summary, $description, $uid)
4430 // Initialize our local variables
4431 $boundary = "=MIME_APPOINTMENT_BOUNDARY";
4435 // Form the headers for the email message
4436 $headers.="X-Mailer: PHP/" . phpversion() . "\n";
4437 $headers.="Mime-Version: 1.0\n";
4438 $headers.="Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
4439 $headers.="Content-Disposition: inline\n";
4440 $headers.="Reply-To: $from\n";
4441 $headers.="From: $from\n";
4443 // Print the plaintext version of the appointment
4444 $message.="--$boundary\n";
4445 $message.="Content-Type: text/plain; charset=us-ascii\n";
4446 $message.="Content-Disposition: inline\n";
4448 $message.="What: $description\n";
4449 $message.="When: $date\n";
4450 $message.="Where: $location\n";
4453 // Print the .ics attachment version of the appointment
4454 $message.="--$boundary\n";
4455 $message.="Content-Type: text/calendar; charset=us-ascii\n";
4456 $message.="Content-Disposition: attachment; filename=\"appointment.ics\"\n";
4458 $message.="BEGIN:VCALENDAR" . "\n";
4459 $message.="VERSION:2.0" . "\n";
4460 $message.="PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN" . "\n";
4461 $message.="METHOD:$action" . "\n";
4462 $message.="BEGIN:VEVENT" . "\n";
4463 $message.="ORGANIZER:MAILTO:$from". "\n";
4464 $message.="DTSTAMP:$dtstamp" . "\n";
4465 $message.="DTSTART:$dtstart" . "\n";
4466 $message.="DTEND:$dtend" . "\n";
4467 $message.="SUMMARY:$summary" . "\n";
4468 $message.="DESCRIPTION:$description" . "\n";
4469 $message.="LOCATION:$location" . "\n";
4470 $message.="UID:$uid" ."\n";
4471 $message.="TRANSP:OPAQUE" . "\n";
4472 $message.="SEQUENCE:0" . "\n";
4473 $message.="CLASS:PUBLIC" . "\n";
4474 $message.="END:VEVENT" . "\n";
4475 $message.="END:VCALENDAR" . "\n";
4477 // Complete the message
4478 $message.="--$boundary\n";
4481 mail($to, $subject, $message, $headers);
4484 function get_time_selection_form($hour, $minute, $pm, $presidency, $appointment)
4489 if($hour == 0) { $blank = 1; }
4491 if($this->time_drop_down_lists == 1) {
4492 // Create drop down lists to get the time
4493 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][hour]>';
4494 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4495 foreach(range(1,12) as $num) {
4497 $selected = 'selected="selected"';
4501 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4503 $form_data.= '</select>';
4504 $form_data.= ' : ';
4505 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][minute]>';
4506 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4509 if($num < 10) { $num = "0" . "$num"; }
4510 if($minute == $num) {
4511 $selected = 'selected="selected"';
4515 if($blank == 1) { $selected = ""; }
4516 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4517 $num = $num + $this->time_drop_down_list_inc;
4519 $form_data.= '</select>';
4521 // Use free form text fields to get the time
4527 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][hour] value='.$hour.'>';
4529 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][minute] value='.$minute.'>';
4530 $form_data.= ' ';
4532 // Always use a drop-down select form for am/pm
4533 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][pm]>';
4536 $form_data.= '<option value=0 selected>am</option>';
4537 $form_data.= '<option value=1>pm</option>';
4540 $form_data.= '<option value=0>am</option>';
4541 $form_data.= '<option value=1 selected>pm</option>';
4544 $form_data.= '<option value=""></option>';
4545 $form_data.= '<option value=0>am</option>';
4546 $form_data.= '<option value=1>pm</option>';
4548 $form_data.= '</select>';