2 /**************************************************************************\
4 * http://www.phpgroupware.org *
5 * ----------------------------------------------- *
6 * This program is free software; you can redistribute it and/or modify it *
7 * under the terms of the GNU General Public License as published by the *
8 * Free Software Foundation; either version 2 of the License, or (at your *
9 * option) any later version. *
10 \**************************************************************************/
11 /* $Id: class.eq.inc.php,v 1.1.1.1 2005/07/20 07:40:32 ajp Exp $ */
22 var $default_ht_num_months;
23 var $default_ppi_num_months;
24 var $default_ppi_num_years;
25 var $default_int_num_quarters;
26 var $default_int_num_years;
27 var $default_vis_num_years;
28 var $default_att_num_quarters;
29 var $max_num_districts;
32 var $upload_target_path;
34 var $max_appointments;
35 var $max_presidency_members;
37 var $public_functions = array
61 'willing_view' => True,
62 'willing_update' => True,
63 'send_ical_appt' => True,
64 'assign_view' => True,
65 'assign_update' => True,
70 // LOCAL CONFIGURATION. PLEASE UPDATE AS APPROPRIATE.
71 $this->upload_target_path = "/home/users/eqpres/eq_data";
72 $this->script_path = "/usr/share/phpgroupware/eq/bin";
73 $this->default_ht_num_months = 3;
74 $this->default_ppi_num_months = 3;
75 $this->default_ppi_num_years = 0;
76 $this->default_int_num_quarters = 1;
77 $this->default_int_num_years = 0;
78 $this->default_att_num_quarters = 1;
79 $this->default_vis_num_years = 1;
80 $this->max_num_districts = 4;
81 $this->max_presidency_members = 99;
82 $this->max_appointments = 32768;
83 // END LOCAL CONFIGURATION
85 $this->db = $GLOBALS['phpgw']->db;
86 $this->db2 = $this->db;
87 $this->db3 = $this->db;
88 $this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
89 $this->t = $GLOBALS['phpgw']->template;
90 $this->account = $GLOBALS['phpgw_info']['user']['account_id'];
91 $this->grants = $GLOBALS['phpgw']->acl->get_grants('eq');
92 $this->grants[$this->account] = PHPGW_ACL_READ + PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE;
94 $this->jscal = CreateObject('eq.jscalendar'); // before phpgw_header() !!!
95 $this->cal_options = 'daFormat : "%Y-%m-%d",
96 ifFormat : "%Y-%m-%d",
100 $GLOBALS['phpgw_info']['flags']['app_header'] = 'Elders Quorum Tools - The 3rd Counselor';
101 $GLOBALS['phpgw']->common->phpgw_header();
103 $this->current_day = `date '+%d'`;
104 $this->current_day = $this->current_day-0; // Make it numeric
105 $this->current_month = `date '+%m'`;
106 $this->current_month = $this->current_month-0; // Make it numeric
107 $this->current_year = `date '+%Y'`;
108 $this->current_year = $this->current_year-0; // Make it numeric
111 $this->display_app_header();
114 function save_sessiondata()
119 function display_app_header()
121 $this->t->set_file(array('eq_header' => 'header.tpl'));
123 if (isset($phpgw_info['user']['preferences']['eq']['eq_font']))
125 $font = $phpgw_info['user']['preferences']['eq']['eq_font'];
132 $this->t->set_var('bg_color',$phpgw_info['theme']['th_bg']);
133 $this->t->set_var('font',$font);
134 $link_data['menuaction'] = 'eq.eq.ht_view';
135 $this->t->set_var('link_hometeaching',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
136 $this->t->set_var('lang_hometeaching','HomeTeaching');
137 $link_data['menuaction'] = 'eq.eq.act_list';
138 $this->t->set_var('link_activity',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
139 $this->t->set_var('lang_activity','Activities');
140 $link_data['menuaction'] = 'eq.eq.willing_view';
141 $this->t->set_var('link_willing',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
142 $this->t->set_var('lang_willing','Willingness');
143 $link_data['menuaction'] = 'eq.eq.assign_view';
144 $this->t->set_var('link_assignment',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
145 $this->t->set_var('lang_assignment','Assignments');
146 $link_data['menuaction'] = 'eq.eq.par_view';
147 $this->t->set_var('link_participation',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
148 $this->t->set_var('lang_participation','Participation');
149 $link_data['menuaction'] = 'eq.eq.ppi_view';
150 $this->t->set_var('link_ppi',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
151 $this->t->set_var('lang_ppi','PPIs');
152 $link_data['menuaction'] = 'eq.eq.int_view';
153 $this->t->set_var('link_int',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
154 $this->t->set_var('lang_int','Interviews');
155 $link_data['menuaction'] = 'eq.eq.vis_view';
156 $this->t->set_var('link_visit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
157 $this->t->set_var('lang_visit','Visits');
158 $link_data['menuaction'] = 'eq.eq.att_view';
159 $this->t->set_var('link_attendance',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
160 $this->t->set_var('lang_attendance','Attendance');
161 $link_data['menuaction'] = 'eq.eq.dir_view';
162 $this->t->set_var('link_dir',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
163 $this->t->set_var('lang_dir','Directory');
164 $link_data['menuaction'] = 'eq.eq.org_view';
165 $this->t->set_var('link_org',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
166 $this->t->set_var('lang_org','Callings');
167 $link_data['menuaction'] = 'eq.eq.admin';
168 $this->t->set_var('link_admin',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
169 $this->t->set_var('lang_admin','Admin');
170 $link_data['menuaction'] = 'eq.eq.schedule';
171 $this->t->set_var('link_schedule',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
172 $this->t->set_var('lang_schedule','Scheduling');
174 $this->t->pparse('out','eq_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('/eq/index.php','menuaction=eq.eq.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('/eq/index.php','menuaction=eq.eq.ht_view'));
191 $this->t->set_var('title','Hometeaching');
193 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
194 $this->db->query($sql,__LINE__,__FILE__);
196 while ($this->db->next_record())
198 $districts[$i]['district'] = $this->db->f('district');
199 $districts[$i]['name'] = $this->db->f('name');
200 $districts[$i]['supervisor'] = $this->db->f('supervisor');
204 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
205 $this->db->query($sql,__LINE__,__FILE__);
207 while ($this->db->next_record())
209 $elder_id[$i] = $this->db->f('elder');
210 $elder_name[$i] = $this->db->f('name');
211 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
214 array_multisort($elder_name, $elder_id);
216 // Make an array mapping elder_ids to elder_names
217 for($i=0; $i < count($elder_id); $i++) {
219 $elders[$id] = $elder_name[$i];
222 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
223 $this->db->query($sql,__LINE__,__FILE__);
224 while ($this->db->next_record())
226 $aaronic_id = $this->db->f('aaronic');
227 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
228 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
232 $this->nextmatchs->template_alternate_row_color(&$this->t);
233 for ($i=0; $i < count($districts); $i++) {
234 $this->t->set_var('district_number',$districts[$i]['district']);
235 $this->t->set_var('district_name',$districts[$i]['name']);
236 $supervisor = $districts[$i]['supervisor'];
237 $unique_companionships='';
239 // Select all the unique companionship numbers for this district
240 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $districts[$i]['district'];
241 $this->db->query($sql,__LINE__,__FILE__);
243 while ($this->db->next_record())
245 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
249 $comp_width=450; $visit_width=25; $table_width=$comp_width + $num_months*$visit_width;
250 $table_data=""; $num_companionships = 0; $num_families = 0;
251 for($m=$num_months; $m >= 0; $m--) { $visits[$m] = 0; }
252 for ($j=0; $j < count($unique_companionships); $j++) {
253 $companion_table_entry = "";
254 // Select all the companions in each companionship
255 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
256 "companionship=". $unique_companionships[$j]['companionship'];
257 $this->db->query($sql,__LINE__,__FILE__);
259 while ($this->db->next_record())
261 // Get this companions information
262 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
263 $companionship = $this->db->f('companionship');
264 $elder_id = $this->db->f('elder');
265 $aaronic_id = $this->db->f('aaronic');
267 $name = $elders[$elder_id];
268 $phone = $elder_phone[$elder_id];
270 else if($aaronic_id) {
271 $name = $aaronic[$aaronic_id]['name'];
272 $phone = $aaronic[$aaronic_id]['phone'];
274 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
276 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
278 // Get the names of the families assigned this home teaching companionship
279 $sql = "SELECT * from eq_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
280 $sql = $sql . " ORDER BY name ASC";
281 $this->db->query($sql,__LINE__,__FILE__);
283 while ($this->db->next_record())
285 $num_families++; $total_families++;
286 $family_name = $this->db->f('name');
287 $family_id = $this->db->f('family');
288 $this->nextmatchs->template_alternate_row_color(&$this->t);
289 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
290 // Find out how many times Visits were performed by this companionship
291 // in the past $num_months for this Family
292 $header_row="<th width=$comp_width><font size=-2>Families</th>";
293 for($m=$num_months; $m >= 0; $m--) {
294 $month = $this->current_month - $m;
295 $year = $this->current_year;
296 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
297 if($month < 10) { $month = "0"."$month"; }
298 $month_start = "$year"."-"."$month"."-"."01";
299 $month_end = "$year"."-"."$month"."-"."31";
300 $month = "$month"."/"."$year";
301 //print "m: $m month: $month year: $year month_start: $month_start month_end: $month_end<br>";
302 // Add this to the query to filter on only visits made by this companionship:
303 // " AND companionship=" . $unique_companionships[$j]['companionship'].
304 $sql = "SELECT * FROM eq_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
305 " AND companionship!=0".
306 " AND family=". $family_id;
307 $this->db2->query($sql,__LINE__,__FILE__);
308 $link_data['menuaction'] = 'eq.eq.ht_update';
309 $link_data['date'] = $month_start;
310 $link_data['month_start'] = $month_start;
311 $link_data['month_end'] = $month_end;
312 $link_data['month'] = $month;
313 $link_data['district'] = $districts[$i]['district'];
314 $link_data['district_name'] = $districts[$i]['name'];
315 $link_data['action'] = 'view';
316 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
317 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
318 if(!$total_visits[$m]) { $total_visits[$m] = 0; }
319 if($this->db2->next_record()) {
320 if($this->db2->f('visited') == 'y') {
321 $visits[$m]++; $total_visits[$m]++;
322 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/checkmark.gif"></a></td>';
324 else if($this->db2->f('visited') == 'n') {
325 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/x.gif"></a></td>';
328 $visits[$m]++; $total_visits[$m]++;
329 $table_data .= "<td> </td>";
333 $visits[$m]++; $total_visits[$m]++;
334 $table_data .= "<td> </td>";
337 $table_data .= "</tr>";
340 $table_data .= "<tr><td colspan=20></td></tr>";
342 $table_data .= "<tr><td colspan=20><hr></td></tr>";
343 $stat_data = "<tr><td><b><font size=-2>$num_families Families<br>Visit Totals:</font></b></td>";
345 for($m=$num_months; $m >=0; $m--) {
346 $percent = ceil(($visits[$m] / $num_families)*100);
347 $stat_data .= "<td align=center><font size=-2><b>$visits[$m]<br>$percent%</font></b></td>";
349 $stat_data .= "</tr>";
351 $this->t->set_var('table_width',$table_width);
352 $this->t->set_var('header_row',$header_row);
353 $this->t->set_var('table_data',$table_data);
354 $this->t->set_var('stat_data',$stat_data);
355 $this->t->fp('list','district_list',True);
358 $totals = "<tr><td><b><font size=-2>$total_families Total Families<br>Visit Totals:</font></b></td>";
359 for($m=$num_months; $m >=0; $m--) {
360 $percent = ceil(($total_visits[$m] / $total_families)*100);
361 $totals .= "<td align=center><font size=-2><b>$total_visits[$m]<br>$percent%</font></b></td>";
365 $this->t->set_var('totals',$totals);
367 $this->t->pfp('out','ht_view_t');
368 $this->save_sessiondata();
374 $this->t->set_file(array('ht_update_t' => 'ht_update.tpl'));
375 $this->t->set_block('ht_update_t','district_list','list');
376 $this->t->set_block('ht_update_t','save','savehandle');
378 $district = get_var('district',array('GET','POST'));
379 $district_name = get_var('district_name',array('GET','POST'));
380 $date = get_var('date',array('GET','POST'));
381 $month = get_var('month',array('GET','POST'));
382 $month_start = get_var('month_start',array('GET','POST'));
383 $month_end = get_var('month_end',array('GET','POST'));
384 $action = get_var('action',array('GET','POST'));
386 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
387 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_update&action=save'));
388 $this->t->set_var('lang_done','Cancel');
389 $this->t->set_var('district_name',$district_name);
390 $this->t->set_var('district_number',$district);
391 $this->t->set_var('title','Hometeaching Update ' . $month);
392 $this->t->set_var('date',$date);
394 if($action == 'save')
396 // Get a list of all the companionships in this district
397 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $district;
398 $this->db->query($sql,__LINE__,__FILE__);
400 while ($this->db->next_record())
402 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
405 for ($j=0; $j < count($unique_companionships); $j++)
407 // FIXME: We won't be able to go back and edit history on families that have been
408 // reassigned to a different companionship. The following delete command will not delete
409 // the history of visits under an older companionship, only the ones for the existing
410 // companionship. This will lead to duplicate visits being entered for an older
411 // month for the same family, making it impossible to change the past history once
412 // a family is reassigned. However, you will be able to view the history just fine.
414 //$comp=$unique_companionships[$j]['companionship'];
415 //print "deleting from eq_visit where companionship=$comp and date=$date and district=$district<br>";
416 // Delete all the visits that have taken place for all families for this month
417 $this->db->query("DELETE from eq_visit where companionship=" . $unique_companionships[$j]['companionship'] .
418 " AND " . "date='" . $date . "'",__LINE__,__FILE__);
421 // Now, add the visits that are checked for this month
422 $new_data = get_var('family_visited',array('POST'));
423 foreach ($new_data as $family)
425 foreach ($family as $data)
427 //print "family_visited: $data <br>";
428 $data_array = explode("/",$data);
429 $family_id = $data_array[0];
430 $companionship = $data_array[1];
431 $date = $data_array[2];
432 $visited = $data_array[3];
433 if($visited == "") { $visited = $data_array[4]; }
434 //print "family_id: $family_id companionship: $companionship date: $date visited: $visited<br>";
435 $this->db->query("INSERT INTO eq_visit (family,companionship,date,notes,visited) "
436 . "VALUES (" . $family_id .",". $companionship .",'". $date ."','','". $visited ."')",__LINE__,__FILE__);
443 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
444 $this->db->query($sql,__LINE__,__FILE__);
446 while ($this->db->next_record())
448 $elder_id[$i] = $this->db->f('elder');
449 $elder_name[$i] = $this->db->f('name');
450 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
453 array_multisort($elder_name, $elder_id);
455 // Make an array mapping elder_ids to elder_names
456 for($i=0; $i < count($elder_id); $i++) {
458 $elders[$id] = $elder_name[$i];
461 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
462 $this->db->query($sql,__LINE__,__FILE__);
463 while ($this->db->next_record())
465 $aaronic_id = $this->db->f('aaronic');
466 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
467 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
470 // Select all the unique companionship numbers for this district
471 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $district;
472 $this->db->query($sql,__LINE__,__FILE__);
473 $j=0; $unique_companionships='';
474 while ($this->db->next_record())
476 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
480 $comp_width=300; $visit_width=25; $table_width=$comp_width + $visit_width;
481 $table_data=""; $num_companionships = 0; $num_families = 0; $visits=0;
482 for ($j=0; $j < count($unique_companionships); $j++) {
483 $companion_table_entry = "";
484 // Select all the companions in each companionship
485 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
486 "companionship=". $unique_companionships[$j]['companionship'];
487 $this->db->query($sql,__LINE__,__FILE__);
489 while ($this->db->next_record())
491 // Get this companions information
492 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
493 $companionship = $this->db->f('companionship');
494 $elder_id = $this->db->f('elder');
495 $aaronic_id = $this->db->f('aaronic');
497 $name = $elders[$elder_id];
498 $phone = $elder_phone[$elder_id];
500 else if($aaronic_id) {
501 $name = $aaronic[$aaronic_id]['name'];
502 $phone = $aaronic[$aaronic_id]['phone'];
504 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
506 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
508 // Get the names of the families assigned this home teaching companionship
509 $sql = "SELECT * from eq_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
510 $sql = $sql . " ORDER BY name ASC";
511 $this->db->query($sql,__LINE__,__FILE__);
512 while ($this->db->next_record())
514 $num_families++; $total_families++;
515 $family_name = $this->db->f('name');
516 $family_id = $this->db->f('family');
517 $this->nextmatchs->template_alternate_row_color(&$this->t);
518 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
520 $header_row="<th width=$comp_width><font size=-2>Families</th>";
521 $sql = "SELECT * FROM eq_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
522 " AND companionship!=0".
523 " AND family=". $family_id;
524 $this->db2->query($sql,__LINE__,__FILE__);
525 $value = $family_id . "/" . $unique_companionships[$j]['companionship'] . "/" . $date;
526 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
527 if(!$total_visits) { $total_visits = 0; }
528 if($this->db2->next_record()) {
529 if($this->db2->f('visited') == 'y') {
530 $visits++; $total_visits++;
531 $table_data .= '<td width=100 align=center>';
532 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y" checked>Y';
533 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
534 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/"> ';
535 $table_data .= '</td>';
536 } else if($this->db2->f('visited') == 'n') {
537 $table_data .= '<td width=100 align=center>';
538 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
539 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n" checked>N';
540 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/">';
541 $table_data .= '</td>';
543 $table_data .= '<td width=100 align=center>';
544 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
545 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
546 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
547 $table_data .= '</td>';
552 $table_data .= '<td width=100 align=center>';
553 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
554 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
555 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
556 $table_data .= '</td>';
559 $table_data .= "</tr>";
560 $table_data .= "<tr><td colspan=20></td></tr>";
562 $table_data .= "<tr><td colspan=20><hr></td></tr>";
563 $stat_data = "<tr><td><b><font size=-2>$num_families Families<br>Visit Totals:</font></b></td>";
565 $percent = ceil(($visits / $num_families)*100);
566 $stat_data .= "<td align=center><font size=-2><b>$visits<br>$percent%</font></b></td>";
567 $stat_data .= "</tr>";
569 $this->t->set_var('table_width',$table_width);
570 $this->t->set_var('header_row',$header_row);
571 $this->t->set_var('table_data',$table_data);
572 $this->t->set_var('stat_data',$stat_data);
573 $this->t->fp('list','district_list',True);
575 $this->t->set_var('lang_reset','Clear Form');
576 $this->t->set_var('lang_save','Save Changes');
577 $this->t->set_var('savehandle','');
579 $this->t->pfp('out','ht_update_t');
580 $this->t->pfp('addhandle','save');
582 $this->save_sessiondata();
587 $this->t->set_file(array('act_list_t' => 'act_list.tpl'));
588 $this->t->set_block('act_list_t','act_list','list');
590 $this->t->set_var('lang_name','Assignment');
591 $this->t->set_var('lang_date','Date');
592 $this->t->set_var('lang_notes','Description');
594 $sql = "SELECT * FROM eq_activity ORDER BY date DESC";
595 $this->db->query($sql,__LINE__,__FILE__);
596 $total_records = $this->db->num_rows();
599 while ($this->db->next_record())
601 $activity_list[$i]['activity'] = $this->db->f('activity');
602 $activity_list[$i]['assignment'] = $this->db->f('assignment');
603 $activity_list[$i]['date'] = $this->db->f('date');
604 $activity_list[$i]['notes'] = $this->db->f('notes');
606 $sql = "SELECT * FROM eq_assignment WHERE assignment='" . $activity_list[$i]['assignment'] . "'";
607 $this->db2->query($sql,__LINE__,__FILE__);
608 if($this->db2->next_record())
610 $activity_list[$i]['name'] = $this->db2->f('name');
611 $activity_list[$i]['code'] = $this->db2->f('code');
616 for ($i=0; $i < count($activity_list); $i++)
618 $this->nextmatchs->template_alternate_row_color(&$this->t);
619 $this->t->set_var('name',$activity_list[$i]['name']);
620 $this->t->set_var('date',$activity_list[$i]['date']);
621 $activity_notes = $activity_list[$i]['notes'];
622 if(strlen($activity_notes) > 40) { $activity_notes = substr($activity_notes,0,40) . "..."; }
623 $this->t->set_var('notes',$activity_notes);
625 $link_data['menuaction'] = 'eq.eq.act_view';
626 $link_data['activity'] = $activity_list[$i]['activity'];
627 $link_data['action'] = 'view';
628 $this->t->set_var('view',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
629 $this->t->set_var('lang_view','View');
631 $link_data['menuaction'] = 'eq.eq.act_update';
632 $link_data['activity'] = $activity_list[$i]['activity'];
633 $link_data['action'] = 'edit';
634 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
635 $this->t->set_var('lang_edit','Edit');
637 $link_data['menuaction'] = 'eq.eq.act_update';
638 $link_data['activity'] = '0';
639 $link_data['action'] = 'add';
640 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/eq/index.php',$link_data)
641 . '"><input type="submit" name="Add" value="' . 'Add Activity' .'"></font></form>');
643 $this->t->fp('list','act_list',True);
646 $this->t->pfp('out','act_list_t');
647 $this->save_sessiondata();
652 $this->t->set_file(array('act_view_t' => 'act_view.tpl'));
653 $this->t->set_block('act_view_t','part_list','list');
655 $sql = "SELECT * FROM eq_activity WHERE activity=" . intval(get_var('activity',array('GET','POST')));
656 $this->db->query($sql,__LINE__,__FILE__);
657 $this->db->next_record();
658 $this->t->set_var('assignment', $this->db->f('assignment'));
659 $this->t->set_var('date', $this->db->f('date'));
660 $this->t->set_var('notes', $this->db->f('notes'));
662 $sql = "SELECT * FROM eq_assignment WHERE assignment='" . $this->db->f('assignment') . "'";
663 $this->db2->query($sql,__LINE__,__FILE__);
664 if($this->db2->next_record())
666 $this->t->set_var('name', $this->db2->f('name'));
667 $this->t->set_var('code', $this->db2->f('code'));
669 $this->t->set_var('lang_name','Assignment');
670 $this->t->set_var('lang_date','Date');
671 $this->t->set_var('lang_notes','Description');
672 $this->t->set_var('lang_done','Done');
673 $this->t->set_var('lang_action','View');
675 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
676 $this->t->set_var('tr_color',$tr_color);
678 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_list'));
680 $link_data['menuaction'] = 'eq.eq.act_update';
681 $link_data['activity'] = get_var('activity',array('GET','POST'));
682 $link_data['action'] = 'edit';
683 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
684 $this->t->set_var('lang_edit','Edit');
685 $this->t->set_var('cal_date',$this->db->f('date'));
687 // Now find out which elders participated in this activity
688 $sql = "SELECT * FROM eq_participation WHERE activity=" . intval(get_var('activity',array('GET','POST')));
689 $this->db->query($sql,__LINE__,__FILE__);
690 $total_records = $this->db->num_rows();
693 while ($this->db->next_record())
695 $part_list[$i]['elder'] = $this->db->f('elder');
699 for ($i=0; $i < count($part_list); $i++)
701 $sql = "SELECT * FROM eq_elder WHERE elder=" . $part_list[$i]['elder'];
702 $this->db->query($sql,__LINE__,__FILE__);
703 $this->db->next_record();
704 $names[$i] = $this->db->f('name');
707 for ($i=0; $i < count($names); $i++)
709 //$this->nextmatchs->template_alternate_row_color(&$this->t);
710 $this->t->set_var('elder_name',$names[$i]);
711 if(($i+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
712 else { $this->t->set_var('table_sep',"</td>"); }
713 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
714 $this->t->fp('list','part_list',True);
717 $this->t->pfp('out','act_view_t');
718 $this->save_sessiondata();
721 function act_update()
723 $this->t->set_file(array('form' => 'act_update.tpl'));
724 $this->t->set_block('form','elder_list','list');
725 $this->t->set_block('form','add','addhandle');
726 $this->t->set_block('form','edit','edithandle');
727 $this->t->set_var('lang_done','Done');
729 $action = get_var('action',array('GET','POST'));
730 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_list'));
731 $activity['activity'] = intval(get_var('activity',array('GET','POST')));
733 if($action == 'save')
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("UPDATE eq_activity set " .
739 " assignment='" . $activity['assignment'] .
740 "', date='" . $activity['date'] . "'" .
741 ", notes='" . $activity['notes'] . "'" .
742 " WHERE activity=" . $activity['activity'],__LINE__,__FILE__);
744 // Delete all the elders who have particiapted in this activity
745 $this->db->query("DELETE from eq_participation where activity=".$activity['activity'],__LINE__,__FILE__);
747 // Re-add the elders who are checked as having participated in this activity
748 $elders = get_var('elder_name',array('POST'));
749 foreach ($elders as $elder)
751 $this->db->query("INSERT INTO eq_participation (elder,activity) "
752 . "VALUES (" . $elder . ",". $activity['activity'] . ")",__LINE__,__FILE__);
759 if($action == 'insert')
761 $activity['assignment'] = get_var('assignment',array('POST'));
762 $activity['date'] = get_var('date',array('POST'));
763 $activity['notes']= get_var('notes',array('POST'));
764 $this->db->query("INSERT INTO eq_activity (assignment,date,notes) "
765 . "VALUES ('" . $activity['assignment'] . "','"
766 . $activity['date'] . "','" . $activity['notes'] . "')",__LINE__,__FILE__);
768 $sql = "SELECT * FROM eq_activity WHERE assignment='".$activity['assignment']."' "
769 . " AND date='".$activity['date']."' AND notes='".$activity['notes']."'";
770 $this->db->query($sql,__LINE__,__FILE__);
771 if($this->db->next_record()) {
772 //print "activity: " . $this->db->f('activity') . "<br>";
773 $activity['activity'] = $this->db->f('activity');
776 $elders = get_var('elder_name',array('POST'));
777 foreach ($elders as $elder)
779 $this->db->query("INSERT INTO eq_participation (elder,activity) "
780 . "VALUES (" . $elder . ",". $activity['activity'] . ")",__LINE__,__FILE__);
789 $activity['activity'] = 0;
790 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
791 $this->t->set_var('assignment','');
792 $this->t->set_var('date','');
793 $this->t->set_var('notes','');
794 $this->t->set_var('lang_done','Cancel');
795 $this->t->set_var('lang_action','Adding New Activity');
796 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_update&activity='
797 . $activity['activity'] . '&action=' . 'insert'));
800 if($action == 'edit')
802 $sql = "SELECT * FROM eq_activity WHERE activity=" . $activity['activity'];
803 $this->db->query($sql,__LINE__,__FILE__);
804 $this->db->next_record();
805 $this->t->set_var('cal_date',$this->jscal->input('date',$this->db->f('date'),'','','','','',$this->cal_options));
806 $this->t->set_var('assignment', $this->db->f('assignment'));
807 $assignment = $this->db->f('assignment');
808 $this->t->set_var('date', $this->db->f('date'));
809 $this->t->set_var('notes', $this->db->f('notes'));
810 $this->t->set_var('lang_done','Cancel');
811 $this->t->set_var('lang_action','Editing Activity');
812 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_update&activity='
813 . $activity['activity'] . '&action=' . 'save'));
817 // Create the assignments drop-down list
818 $sql = "SELECT * FROM eq_assignment ORDER BY name ASC";
819 $this->db->query($sql,__LINE__,__FILE__);
821 while ($this->db->next_record())
823 $assignments[$i]['assignment'] = $this->db->f('assignment');
824 $assignments[$i]['name'] = $this->db->f('name');
825 $assignments[$i]['code'] = $this->db->f('code');
829 $assignment_data.= '<select name=assignment>';
830 $assignment_data.= '<option value=0></option>';
831 for ($j=0; $j < count($assignments); $j++) {
832 $id = $assignments[$j]['assignment'];
833 $name = $assignments[$j]['name'];
834 if($assignments[$j]['assignment'] == $assignment) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
835 $assignment_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
837 $assignment_data.='</select>';
838 $this->t->set_var('assignment_data',$assignment_data);
840 // Create elder selection boxes
841 $sql = "SELECT * FROM eq_elder";
842 $this->db->query($sql,__LINE__,__FILE__);
844 while ($this->db->next_record())
846 if($this->db->f('valid') == 1 || $action != 'add') {
847 $elder_name[$i] = $this->db->f('name');
848 $elder_id[$i] = $this->db->f('elder');
849 $elder_valid[$i] = $this->db->f('valid');
853 array_multisort($elder_name, $elder_id, $elder_valid);
856 for ($i=0; $i < count($elder_id); $i++)
858 //$this->nextmatchs->template_alternate_row_color(&$this->t);
859 $sql = "SELECT * FROM eq_participation where activity=". $activity['activity'] . " AND elder=" . $elder_id[$i];
860 $this->db->query($sql,__LINE__,__FILE__);
861 if($this->db->next_record()) { $this->t->set_var('checked','checked'); $checked=1; }
862 else { $this->t->set_var('checked',''); $checked=0; }
863 if($checked || $elder_valid[$i] == 1) {
864 $this->t->set_var('elder_name',$elder_name[$i]);
865 $this->t->set_var('elder',$elder_id[$i]);
866 if(($j+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
867 else { $this->t->set_var('table_sep',"</td>"); }
868 if(($j) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
869 $this->t->fp('list','elder_list',True);
874 $this->t->set_var('lang_reset','Clear Form');
875 $this->t->set_var('lang_add','Add Activity');
876 $this->t->set_var('lang_save','Save Changes');
877 $this->t->set_var('edithandle','');
878 $this->t->set_var('addhandle','');
880 $this->t->pfp('out','form');
881 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
882 if($action == 'add') { $this->t->pfp('addhandle','add'); }
884 $this->save_sessiondata();
887 function assign_view()
889 $this->t->set_file(array('assign_view_t' => 'assign_view.tpl'));
890 $this->t->set_block('assign_view_t','assign_view','list');
892 $this->t->set_var('lang_name','Assignment Name');
893 $this->t->set_var('lang_code','Code');
895 $sql = "SELECT * FROM eq_assignment ORDER BY name ASC";
896 $this->db->query($sql,__LINE__,__FILE__);
897 $total_records = $this->db->num_rows();
900 while ($this->db->next_record())
902 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
903 $assignment_list[$i]['name'] = $this->db->f('name');
904 $assignment_list[$i]['code'] = $this->db->f('code');
908 for ($i=0; $i < count($assignment_list); $i++)
910 $this->nextmatchs->template_alternate_row_color(&$this->t);
911 $this->t->set_var('name',$assignment_list[$i]['name']);
912 $this->t->set_var('code',$assignment_list[$i]['code']);
914 $link_data['menuaction'] = 'eq.eq.assign_update';
915 $link_data['assignment'] = $assignment_list[$i]['assignment'];
916 $link_data['action'] = 'edit';
917 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
918 $this->t->set_var('lang_edit','Edit');
920 $link_data['menuaction'] = 'eq.eq.assign_update';
921 $link_data['assignment'] = '0';
922 $link_data['action'] = 'add';
923 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/eq/index.php',$link_data)
924 . '"><input type="submit" name="Add" value="' . 'Add Assignment' .'"></font></form>');
926 $this->t->fp('list','assign_view',True);
929 $this->t->pfp('out','assign_view_t');
930 $this->save_sessiondata();
933 function assign_update()
935 $this->t->set_file(array('form' => 'assign_update.tpl'));
936 $this->t->set_block('form','add','addhandle');
937 $this->t->set_block('form','edit','edithandle');
938 $this->t->set_var('lang_done','Done');
940 $action = get_var('action',array('GET','POST'));
941 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.assign_view'));
942 $assignment['assignment'] = intval(get_var('assignment',array('GET','POST')));
944 if($action == 'save')
946 $assignment['name'] = get_var('name',array('POST'));
947 $assignment['code'] = get_var('code',array('POST'));
948 $this->db->query("UPDATE eq_assignment set " .
949 " name='" . $assignment['name'] . "'" .
950 ", code='" . $assignment['code'] . "'" .
951 " WHERE assignment=" . $assignment['assignment'],__LINE__,__FILE__);
953 $this->assign_view();
957 if($action == 'insert')
959 $assignment['name'] = get_var('name',array('POST'));
960 $assignment['code'] = get_var('code',array('POST'));
961 $this->db->query("INSERT INTO eq_assignment (name,code) "
962 . "VALUES ('" . $assignment['name'] . "','"
963 . $assignment['code'] . "')",__LINE__,__FILE__);
964 $this->assign_view();
970 $assignment['assignment'] = 0;
971 $this->t->set_var('name','');
972 $this->t->set_var('code','');
973 $this->t->set_var('lang_done','Cancel');
974 $this->t->set_var('lang_action','Adding New Assignment');
975 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.assign_update&assignment='
976 . $assignment['assignment'] . '&action=' . 'insert'));
979 if($action == 'edit')
981 $sql = "SELECT * FROM eq_assignment WHERE assignment=" . $assignment['assignment'];
982 $this->db->query($sql,__LINE__,__FILE__);
983 $this->db->next_record();
984 $this->t->set_var('name', $this->db->f('name'));
985 $this->t->set_var('code', $this->db->f('code'));
986 $this->t->set_var('lang_done','Cancel');
987 $this->t->set_var('lang_action','Editing Assignment');
988 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.assign_update&assignment='
989 . $assignment['assignment'] . '&action=' . 'save'));
993 $this->t->set_var('lang_reset','Clear Form');
994 $this->t->set_var('lang_add','Add Assignment');
995 $this->t->set_var('lang_save','Save Changes');
996 $this->t->set_var('edithandle','');
997 $this->t->set_var('addhandle','');
999 $this->t->pfp('out','form');
1000 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
1001 if($action == 'add') { $this->t->pfp('addhandle','add'); }
1003 $this->save_sessiondata();
1008 $this->t->set_file(array('par_view_t' => 'par_view.tpl'));
1009 $this->t->set_block('par_view_t','header_list','list1');
1010 $this->t->set_block('par_view_t','elder_list','list2');
1012 $sql = "SELECT * FROM eq_elder where valid=1";
1013 $this->db->query($sql,__LINE__,__FILE__);
1015 while ($this->db->next_record())
1017 $elder_name[$i] = $this->db->f('name');
1018 $elder_id[$i] = $this->db->f('elder');
1021 array_multisort($elder_name, $elder_id);
1023 $sql = "SELECT * FROM eq_activity ORDER BY date DESC";
1024 $this->db->query($sql,__LINE__,__FILE__);
1025 $total_records = $this->db->num_rows();
1028 while ($this->db->next_record())
1030 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1031 $activity_list[$i]['date'] = $this->db->f('date');
1032 $activity_list[$i]['activity'] = $this->db->f('activity');
1036 $sql = "SELECT * FROM eq_assignment ORDER BY name ASC";
1037 $this->db->query($sql,__LINE__,__FILE__);
1039 while($this->db->next_record())
1041 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1042 $assignment_list[$i]['name'] = $this->db->f('name');
1043 $assignment_list[$i]['code'] = $this->db->f('code');
1047 $elder_width=300; $part_width=25; $assignment_width=50;
1048 $total_width=$elder_width+$part_width;
1049 for ($i=0; $i < count($assignment_list); $i++) {
1050 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1051 $this->t->set_var('assignment_code',$assignment_list[$i]['code']);
1052 $this->t->fp('list1','header_list',True);
1053 $total_width += $assignment_width;
1056 for ($i=0; $i < count($elder_id); $i++) {
1057 $participated=0; $part_table = '';
1058 $this->nextmatchs->template_alternate_row_color(&$this->t);
1059 $this->t->set_var('elder_name',$elder_name[$i]);
1060 for ($j=0; $j < count($assignment_list); $j++) {
1061 $date = "0000-00-00"; $checkmark=0; $num_matches=0;
1062 for ($k=0; $k < count($activity_list); $k++) {
1063 if($assignment_list[$j]['assignment'] == $activity_list[$k]['assignment']) {
1064 $sql = "SELECT * FROM eq_participation where "
1065 . " activity=" . $activity_list[$k]['activity']
1066 . " AND elder=" . $elder_id[$i];
1067 $this->db->query($sql,__LINE__,__FILE__);
1068 while($this->db->next_record()) {
1069 if($activity_list[$k]['date'] > $date) {
1070 $date = $activity_list[$k]['date'];
1079 $part_table .= '<td align=center><img src="images/checkmark.gif">';
1080 $part_table .= '<font size=-2>'.$num_matches.'</font><br>';
1081 $part_table .= '<font size=-2>'.$date.'</font></td>';
1083 $part_table .= '<td> </td>';
1086 if($participated) { $part_table .= '<td align=center><img src="images/checkmark.gif">'.$participated.'</td>'; }
1087 else { $part_table .= '<td> </td>'; }
1088 $this->t->set_var('part_table',$part_table);
1089 $this->t->fp('list2','elder_list',True);
1091 $this->t->set_var('total_width',$total_width);
1092 $this->t->set_var('elder_width',$elder_width);
1093 $this->t->set_var('part_width',$part_width);
1094 $this->t->set_var('act_width',$act_width);
1095 $this->t->pfp('out','par_view_t');
1096 $this->save_sessiondata();
1099 function willing_view()
1101 $this->t->set_file(array('willing_view_t' => 'willing_view.tpl'));
1102 $this->t->set_block('willing_view_t','header_list','list1');
1103 $this->t->set_block('willing_view_t','elder_list','list2');
1105 $this->t->set_var('lang_filter','Filter');
1106 $this->t->set_var('lang_filter_unwilling','Filter out unwilling Elders:');
1108 $filter_unwilling = get_var('filter_unwilling',array('POST'));
1109 $this->t->set_var('filter_unwilling',$filter_unwilling);
1111 if($filter_unwilling == 'y' || $filter_unwilling == '') {
1112 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\" checked>Y";
1113 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\">N";
1114 $filter_input.= " ";
1116 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\">Y";
1117 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\" checked>N";
1118 $filter_input.= " ";
1120 $this->t->set_var('filter_input',$filter_input);
1122 $sql = "SELECT * FROM eq_elder where valid=1";
1123 $this->db->query($sql,__LINE__,__FILE__);
1125 while ($this->db->next_record())
1127 $elder_name[$i] = $this->db->f('name');
1128 $elder_id[$i] = $this->db->f('elder');
1129 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
1132 array_multisort($elder_name, $elder_id);
1134 $sql = "SELECT * FROM eq_assignment ORDER BY name ASC";
1135 $this->db->query($sql,__LINE__,__FILE__);
1137 while($this->db->next_record())
1139 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1140 $assignment_list[$i]['name'] = $this->db->f('name');
1141 $assignment_list[$i]['code'] = $this->db->f('code');
1145 $sql = "SELECT * FROM eq_activity ORDER BY date DESC";
1146 $this->db->query($sql,__LINE__,__FILE__);
1147 $total_records = $this->db->num_rows();
1150 while ($this->db->next_record())
1152 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1153 $activity_list[$i]['date'] = $this->db->f('date');
1154 $activity_list[$i]['activity'] = $this->db->f('activity');
1158 $elder_width=275; $willing_width=40; $assignment_width=50;
1159 $total_width=$elder_width+$willing_width;
1161 for ($i=0; $i < count($assignment_list); $i++) {
1162 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1163 $this->t->set_var('assignment_code',$assignment_list[$i]['code']);
1164 $this->t->fp('list1','header_list',True);
1165 $total_width += $assignment_width;
1166 $total_willing[$i] = 0;
1169 for ($i=0; $i < count($elder_id); $i++) {
1170 $willing_table = ''; $elder_willing=0;
1171 $this->t->set_var('elder_name',$elder_name[$i]);
1172 $this->t->set_var('elder_phone',$elder_phone[$elder_id[$i]]);
1173 $this->t->set_var('editurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.willing_update&elder_id='
1174 . $elder_id[$i] . '&action=' . 'edit'));
1175 for ($j=0; $j < count($assignment_list); $j++) {
1176 $found_willingness=0;
1177 $sql = "SELECT * FROM eq_willingness where "
1178 . " assignment=" . $assignment_list[$j]['assignment']
1179 . " AND elder=" . $elder_id[$i];
1180 $this->db->query($sql,__LINE__,__FILE__);
1181 while($this->db->next_record()) {
1182 $found_willingness=1;
1184 $sql = "SELECT * FROM eq_activity where "
1185 . " assignment=". $assignment_list[$j]['assignment']
1186 . " ORDER by date DESC";
1187 $this->db2->query($sql,__LINE__,__FILE__);
1188 if($this->db2->next_record()) {
1189 $activity = $this->db2->f('activity');
1190 $date = $this->db2->f('date');
1191 $sql = "SELECT * FROM eq_participation where "
1192 . " activity=" . $activity
1193 . " AND elder=". $elder_id[$i];
1194 $this->db3->query($sql,__LINE__,__FILE__);
1195 if($this->db3->next_record()) {
1200 if($this->db->f('willing') == 'y') {
1201 $total_willing[$j]++;
1203 $willing_table .= '<td align=center><img src="images/checkmark.gif"><br><font size=-2>'.$date_part.'</font></td></td>';
1205 else if($this->db->f('willing') == 'n') {
1206 $willing_table .= '<td align=center><img src="images/x.gif"></td>';
1210 $willing_table .= "<td> </td>";
1213 if(!$found_willingness) {
1215 $willing_table .= "<td> </td>";
1218 if(($elder_willing == 1) || ($filter_unwilling == 'n')) {
1219 $this->t->set_var('willing_table',$willing_table);
1220 $this->t->fp('list2','elder_list',True);
1221 $this->nextmatchs->template_alternate_row_color(&$this->t);
1225 $stat_table = '<td><b>Total Willing to Serve</b></td>';
1226 for ($j=0; $j < count($assignment_list); $j++) {
1227 $stat_table .= "<td align=center><b>".$total_willing[$j]."</b></td>";
1229 $this->t->set_var('stat_table',$stat_table);
1231 $this->t->set_var('total_width',$total_width);
1232 $this->t->set_var('elder_width',$elder_width);
1233 $this->t->set_var('willing_width',$willing_width);
1234 $this->t->pfp('out','willing_view_t');
1235 $this->save_sessiondata();
1238 function willing_update()
1240 //print "<font color=red>Willingness Update Under Constrcution</font>";
1241 //$this->willing_view();
1244 $this->t->set_file(array('willing_update_t' => 'willing_update.tpl'));
1245 $this->t->set_block('willing_update_t','assignment_list','list');
1246 $this->t->set_block('willing_update_t','save','savehandle');
1248 $elder_id = get_var('elder_id',array('GET','POST'));
1249 $this->t->set_var('elder_id',$elder_id);
1250 $action = get_var('action',array('GET','POST'));
1252 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.willing_view'));
1253 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.willing_update&action=save'));
1254 $this->t->set_var('lang_done','Cancel');
1255 $this->t->set_var('title','Willingness Update ');
1257 if($action == 'save')
1259 // Delete all the previous willingness entries for this elder
1260 $this->db->query("DELETE from eq_willingness where elder=" . $elder_id ,__LINE__,__FILE__);
1262 // Now, add the assignment willingness that is checked for this elder
1263 $new_data = get_var('willingness',array('POST'));
1264 foreach ($new_data as $data)
1266 $data_array = explode("/",$data);
1267 $assignment = $data_array[0];
1268 $willing = $data_array[1];
1269 //print "elder_id: $elder_id assignment: $assignment willing: $willing<br>";
1270 $this->db->query("INSERT INTO eq_willingness (elder,assignment,willing) "
1271 . "VALUES (" . $elder_id .",". $assignment .",'". $willing . "')",__LINE__,__FILE__);
1273 $this->willing_view();
1277 $assignment_width=300; $willing_width=25; $table_width=$assignment_width + $willing_width;
1280 // Find out the elder's name
1281 $sql = "SELECT * FROM eq_elder WHERE elder=".$elder_id." AND valid=1";
1282 $this->db->query($sql,__LINE__,__FILE__);
1283 if($this->db->next_record()) {
1284 $elder_name = $this->db->f('name');
1285 $this->t->set_var('elder_name',$elder_name);
1288 // Select all the assignments
1289 $sql = "SELECT * FROM eq_assignment ORDER by name ASC";
1290 $this->db->query($sql,__LINE__,__FILE__);
1292 while ($this->db->next_record())
1294 $assignment = $this->db->f('assignment');
1295 $assignment_name = $this->db->f('name');
1296 $assignment_code = $this->db->f('code');
1298 $this->nextmatchs->template_alternate_row_color(&$this->t);
1299 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$assignment_name</td>";
1301 $header_row="<th width=$comp_width><font size=-2>Assignments</th><th>Willingness</th>";
1302 $sql = "SELECT * FROM eq_willingness WHERE elder=".$elder_id." AND assignment=".$assignment;
1303 $this->db2->query($sql,__LINE__,__FILE__);
1304 $value = $assignment;
1306 if($this->db2->next_record()) {
1307 if($this->db2->f('willing') == 'y') {
1308 $table_data .= '<td width=100 align=center>';
1309 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y" checked>Y';
1310 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1311 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/"> ';
1312 $table_data .= '</td>';
1313 } else if($this->db2->f('willing') == 'n') {
1314 $table_data .= '<td width=100 align=center>';
1315 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1316 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n" checked>N';
1317 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/">';
1318 $table_data .= '</td>';
1320 $table_data .= '<td width=100 align=center>';
1321 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1322 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1323 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1324 $table_data .= '</td>';
1328 $table_data .= '<td width=100 align=center>';
1329 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1330 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1331 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1332 $table_data .= '</td>';
1335 $table_data .= "\n";
1336 $table_data .= "</tr>";
1337 $table_data .= "<tr><td colspan=20></td></tr>";
1340 $table_data .= "<tr><td colspan=20><hr></td></tr>";
1342 $this->t->set_var('table_width',$table_width);
1343 $this->t->set_var('header_row',$header_row);
1344 $this->t->set_var('table_data',$table_data);
1345 $this->t->fp('list','assignment_list',True);
1347 $this->t->set_var('lang_reset','Clear Form');
1348 $this->t->set_var('lang_save','Save Changes');
1349 $this->t->set_var('savehandle','');
1351 $this->t->pfp('out','willing_update_t');
1352 $this->t->pfp('addhandle','save');
1354 $this->save_sessiondata();
1358 function ppi_sched()
1360 $this->t->set_file(array('ppi_sched_t' => 'ppi_sched.tpl'));
1361 $this->t->set_block('ppi_sched_t','elder_list','elderlist');
1362 $this->t->set_block('ppi_sched_t','appt_list','apptlist');
1363 $action = get_var('action',array('GET','POST'));
1365 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1366 $this->t->set_var('lang_reset','Clear Changes');
1368 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
1369 $this->t->set_var('ppi_link_title','Yearly PPIs');
1371 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched'));
1372 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
1374 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched&action=save'));
1375 $this->t->set_var('title','Yearly PPI Scheduler');
1377 $elder_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $ppi_date_width=20;
1378 $table_width=$elder_width + $phone_width + $pri_width + $notes_width + $ppi_date_width;
1379 $header_row = "<th width=$elder_width><font size=-2>Elder Name</th>";
1380 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1381 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1382 $header_row.= "<th width=$ppi_date_width><font size=-2>Last PPI</th>";
1383 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1384 $table_data=""; $completed_data=""; $totals_data="";
1388 if($action == 'save')
1390 // Save any changes made to the appointment table
1391 $new_data = get_var('appt_notes',array('POST'));
1392 foreach ($new_data as $entry)
1394 $elder = $entry['elder'];
1395 $appointment = $entry['appointment'];
1397 //print "elder: $elder appointment: $appointment <br>";
1399 //Only perform a database update if we have made a change to this appointment
1400 $sql = "SELECT * FROM eq_appointment where appointment='$appointment' and elder='$elder'";
1401 $this->db->query($sql,__LINE__,__FILE__);
1402 if(!$this->db->next_record()) {
1403 // Perform database save actions here
1404 $this->db->query("UPDATE eq_appointment set " .
1405 " elder='" . $elder . "'" .
1406 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1407 // Email the appointment
1408 $this->email_appt($appointment);
1413 // Save any changes made to the ppi notes table
1414 $new_data = get_var('ppi_notes',array('POST'));
1415 foreach ($new_data as $entry)
1417 $ppi_notes = $entry['notes'];
1418 $elder_id = $entry['elder_id'];
1419 $ppi_pri = $entry['pri'];
1421 // Perform database save actions here
1422 $this->db->query("UPDATE eq_elder set " .
1423 " ppi_notes='" . $ppi_notes . "'" .
1424 ",ppi_pri='" . $ppi_pri . "'" .
1425 " WHERE elder=" . $elder_id,__LINE__,__FILE__);
1429 $take_me_to_url = $GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched');
1430 Header('Location: ' . $take_me_to_url);
1433 // Get the EQ President
1434 $sql = "SELECT * FROM eq_presidency where president=1 and valid=1";
1435 $this->db->query($sql,__LINE__,__FILE__);
1436 if($this->db->next_record()) {
1437 $president_name = $this->db->f('name');
1438 $president_id = $this->db->f('elder');
1439 $presidency_id = $this->db->f('presidency');
1440 $interviewer = $this->db->f('elder');
1441 $district_number = '*';
1442 $district_name = $president_name;
1444 print "<hr><font color=red><h3>-E- Unable to locate EQ President in eq_presidency table</h3></font></hr>";
1448 // create the elder id -> elder name mapping
1449 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY name ASC";
1450 $this->db->query($sql,__LINE__,__FILE__);
1454 while ($this->db->next_record())
1456 $elder_name[$i] = $this->db->f('name');
1457 $elder_id[$i] = $this->db->f('elder');
1460 array_multisort($elder_name, $elder_id);
1462 // APPOINTMENT TABLE
1463 $date_width=150; $time_width=100; $elder_width=200;
1464 $appt_table_width=$date_width + $time_width + $elder_width;
1465 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1466 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1467 $appt_header_row.= "<th width=$elder_width><font size=-2>Elder</th>";
1468 $appt_table_data = "";
1470 $total_elders=0; $elders_with_yearly_ppi=0;
1472 // Display a scheduling table for the EQ President
1473 $table_data=""; $appt_table_data="";
1474 $table_title = "District ".$district_number.": ".$district_name.": All Elders with Yearly PPI Not Completed";
1475 $appt_table_title = "District ".$district_number.": ".$district_name.": Yearly PPI Appointment Slots";
1476 $this->t->set_var('table_title',$table_title);
1477 $this->t->set_var('appt_table_title',$appt_table_title);
1479 // query the database for all the appointments
1480 $sql = "SELECT * FROM eq_appointment where presidency=".$presidency_id." and date>=CURDATE() ORDER BY date ASC, time ASC";
1481 $this->db->query($sql,__LINE__,__FILE__);
1483 while ($this->db->next_record())
1485 $appointment = $this->db->f('appointment');
1486 $elder = $this->db->f('elder');
1488 $date = $this->db->f('date');
1489 $date_array = explode("-",$date);
1490 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1491 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1493 $time = $this->db->f('time');
1494 $time_array = explode(":",$time);
1495 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1497 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1498 $appt_table_data.= "<td align=center>$day_string</td>";
1499 $appt_table_data.= "<td align=center>$time_string</td>";
1501 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][elder]>';
1502 $appt_table_data.= '<option value=0></option>';
1503 for ($i=0; $i < count($elder_id); $i++) {
1504 $id = $elder_id[$i];
1505 $name = $elder_name[$i];
1506 if($elder_id[$i] == $elder) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
1507 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1509 $appt_table_data.='</select></td>';
1511 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1513 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1514 $this->t->set_var('tr_color',$tr_color);
1517 $this->t->set_var('appt_table_data',$appt_table_data);
1518 $this->t->set_var('appt_header_row',$appt_header_row);
1519 $this->t->set_var('appt_table_width',$appt_table_width);
1521 // PPI SCHEDULING TABLE
1522 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY ppi_pri ASC";
1523 $this->db->query($sql,__LINE__,__FILE__);
1527 while ($this->db->next_record())
1529 $elder_id[$i] = $this->db->f('elder');
1530 $elder_name[$i] = $this->db->f('name');
1531 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
1532 $elder_ppi_pri[$elder_id[$i]] = $this->db->f('ppi_pri');
1533 $elder_ppi_notes[$elder_id[$i]] = $this->db->f('ppi_notes');
1538 $max = count($elder_id);
1540 for($i=0; $i < $max; $i++) {
1541 $id = $elder_id[$i];
1542 $name = $elder_name[$i];
1543 $phone = $elder_phone[$id];
1544 $ppi_pri = $elder_ppi_pri[$id];
1545 $ppi_notes = $elder_ppi_notes[$id];
1547 // If this elder has had a yearly PPI this year, don't show him on the schedule list
1548 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
1549 $sql = "SELECT * FROM eq_ppi WHERE date > '$year_start' AND date < '$year_end' ".
1551 $this->db2->query($sql,__LINE__,__FILE__);
1553 if(!$this->db2->next_record()) {
1554 $sql = "SELECT * FROM eq_ppi WHERE elder=" . $id . " ORDER BY date DESC";
1555 $this->db->query($sql,__LINE__,__FILE__);
1556 if($this->db->next_record()) { $date = $this->db->f('date'); } else { $date = ""; }
1557 $link_data['menuaction'] = 'eq.eq.ppi_update';
1558 $link_data['elder'] = $id;
1559 $link_data['name'] = $name;
1560 $link_data['ppi'] = '';
1561 $link_data['eqpresppi'] = 1;
1562 $link_data['action'] = 'add';
1563 $link_data['interviewer'] = $interviewer;
1564 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1565 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1566 $this->t->set_var('tr_color',$tr_color);
1567 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1568 $table_data.= "<td align=center>$phone</td>";
1569 //$table_data.= "<td align=center>$ppi_pri</td>";
1570 $table_data.= "<td align=center>";
1571 $table_data.= '<select name=ppi_notes['.$i.'][pri]>';
1572 foreach(range(0,6) as $num) {
1573 if($num == 0) { $num = 1; } else {$num = $num*5; }
1574 if($ppi_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
1575 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1577 $table_data.= '</select></td>';
1578 $table_data.= "<td align=center>$date</td>";
1579 $table_data.= '<td><input type=text size="50" maxlength="128" name="ppi_notes['.$i.'][notes]" value="'.$ppi_notes.'">';
1580 $table_data.= '<input type=hidden name="ppi_notes['.$i.'][elder_id]" value="'.$id.'">';
1581 $table_data.= '<input type=hidden name="ppi_notes['.$i.'][elder_name]" value="'.$name.'">';
1582 $table_data.= '</td>';
1583 $table_data.= '</tr>';
1585 $link_data['menuaction'] = 'eq.eq.ppi_update';
1586 $link_data['interviewer'] = $this->db2->f('interviewer');
1587 $link_data['elder'] = $this->db2->f('elder');
1588 $link_data['name'] = $name;
1589 $link_data['ppi'] = $this->db2->f('ppi');
1590 $link_data['eqpresppi'] = $this->db2->f('eqpresppi');
1591 $link_data['action'] = 'view';
1592 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1593 $elders_with_yearly_ppi++;
1594 $date = $this->db2->f('date');
1595 $ppi_notes = $this->db2->f('notes');
1596 if(strlen($ppi_notes) > 40) { $ppi_notes = substr($ppi_notes,0,40) . "..."; }
1597 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1598 $this->t->set_var('tr_color2',$tr_color2);
1599 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1600 $completed_data.= "<td align=center>$phone</td>";
1601 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1602 $completed_data.= "<td align=left>$ppi_notes</td>";
1603 $completed_data.= '</tr>';
1605 } // End for Elders Loop
1607 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1608 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1609 $completed_header_row = "<th width=$name_width><font size=-2>Elder Name</th>";
1610 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1611 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1612 $completed_header_row.= "<th width=$notes_width><font size=-2>PPI Notes</th>";
1614 $this->t->set_var('table_width',$table_width);
1615 $this->t->set_var('header_row',$header_row);
1616 $this->t->set_var('table_data',$table_data);
1617 $this->t->set_var('completed_header_row',$completed_header_row);
1618 $this->t->set_var('completed_table_width',$completed_table_width);
1619 $this->t->set_var('completed',$completed_data);
1620 $this->t->fp('elderlist','elder_list',True);
1622 $elders_width=300; $totals_width=100;
1623 $totals_table_width=$elders_width + $totals_width;
1624 $totals_header_row = "<th width=$elders_width><font size=-2>Elders</th>";
1625 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
1626 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1627 $totals_data.= "<td align=left><font size=-2><b>Total Elders with yearly PPIs completed:</b></font></td>";
1628 $totals_data.= "<td align=center><font size=-2><b>$elders_with_yearly_ppi / $total_elders</b></font></td>";
1629 $percent = ceil(($elders_with_yearly_ppi / $total_elders)*100);
1630 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1631 $this->t->set_var('tr_color',$tr_color);
1632 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1633 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
1634 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
1635 $totals_data.= "</tr>";
1637 $this->t->set_var('totals',$totals_data);
1638 $this->t->set_var('totals_header_row',$totals_header_row);
1639 $this->t->set_var('totals_table_width',$totals_table_width);
1641 $this->t->pfp('out','ppi_sched_t');
1642 $this->save_sessiondata();
1646 function int_sched()
1648 $this->t->set_file(array('int_sched_t' => 'int_sched.tpl'));
1649 $this->t->set_block('int_sched_t','elder_list','elderlist');
1650 $this->t->set_block('int_sched_t','appt_list','apptlist');
1651 $action = get_var('action',array('GET','POST'));
1653 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1654 $this->t->set_var('lang_reset','Clear Changes');
1656 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_view'));
1657 $this->t->set_var('int_link_title','Hometeaching Interviews');
1659 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_sched'));
1660 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
1662 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_sched&action=save'));
1663 $this->t->set_var('title','Hometeaching Interviews Scheduler');
1665 $elder_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $int_date_width=20;
1666 $table_width=$elder_width + $phone_width + $pri_width + $notes_width + $int_date_width;
1667 $header_row = "<th width=$elder_width><font size=-2>Elder Name</th>";
1668 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1669 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1670 $header_row.= "<th width=$int_date_width><font size=-2>Last Interview</th>";
1671 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1672 $table_data=""; $completed_data=""; $totals_data="";
1676 $nextyear = $year + 1;
1677 if($month >= 1 && $month <= 3) { $quarter_start=$year."-01-01"; $quarter_end=$year."-04-01"; }
1678 if($month >= 4 && $month <= 6) { $quarter_start=$year."-04-01"; $quarter_end=$year."-07-01"; }
1679 if($month >= 7 && $month <= 9) { $quarter_start=$year."-07-01"; $quarter_end=$year."-10-01"; }
1680 if($month >= 10 && $month <= 12) { $quarter_start=$year."-10-01"; $quarter_end=$nextyear."-01-01"; }
1681 //print "year: $year month: $month quarter_start: $quarter_start quarter_end: $quarter_end<br>";
1683 if($action == 'save')
1685 // Save any changes made to the appointment table
1686 $new_data = get_var('appt_notes',array('POST'));
1687 foreach ($new_data as $entry)
1689 $elder = $entry['elder'];
1690 $appointment = $entry['appointment'];
1692 //print "elder: $elder appointment: $appointment <br>";
1693 //Only perform a database update if we have made a change to this appointment
1694 $sql = "SELECT * FROM eq_appointment where appointment='$appointment' and elder='$elder'";
1695 $this->db->query($sql,__LINE__,__FILE__);
1696 if(!$this->db->next_record()) {
1697 // Perform database save actions here
1698 $this->db->query("UPDATE eq_appointment set " .
1699 " elder='" . $elder . "'" .
1700 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1702 // Email the appointment
1703 $this->email_appt($appointment);
1707 // Save any changes made to the int notes table
1708 $new_data = get_var('int_notes',array('POST'));
1709 foreach ($new_data as $entry)
1711 $int_notes = $entry['notes'];
1712 $elder_id = $entry['elder_id'];
1713 $elder_name = $entry['elder_name'];
1714 $int_pri = $entry['pri'];
1715 $aaronic = $entry['aaronic'];
1716 //print "int_notes: $int_notes elder_name: $elder_name aaronic: $aaronic <Br>";
1718 // Perform database save actions here
1719 $this->db->query("UPDATE eq_elder set " .
1720 " int_notes='" . $int_notes . "'" .
1721 ",int_pri='" . $int_pri . "'" .
1722 " WHERE elder=" . $elder_id,__LINE__,__FILE__);
1727 $take_me_to_url = $GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_sched');
1728 Header('Location: ' . $take_me_to_url);
1731 // Get the Districts
1732 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
1733 $this->db->query($sql,__LINE__,__FILE__);
1735 while ($this->db->next_record())
1737 $district = $this->db->f('district');
1738 $districts[$i]['district'] = $this->db->f('district');
1739 $districts[$i]['name'] = $this->db->f('name');
1740 $districts[$i]['supervisor'] = $this->db->f('supervisor');
1741 $sql = "SELECT * FROM eq_presidency where district=$district and valid=1";
1742 $this->db2->query($sql,__LINE__,__FILE__);
1743 if($this->db2->next_record()) {
1744 $districts[$i]['presidency'] = $this->db2->f('presidency');
1749 // create the elder id -> elder name mapping
1750 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY name ASC";
1751 $this->db->query($sql,__LINE__,__FILE__);
1753 $elder_id_data = NULL;
1754 $elder_name_data = NULL;
1755 while ($this->db->next_record())
1757 $elder_name_data[$i] = $this->db->f('name');
1758 $elder_id_data[$i] = $this->db->f('elder');
1761 array_multisort($elder_name_data, $elder_id_data);
1763 // APPOINTMENT TABLE
1765 $date_width=150; $time_width=100; $elder_width=200;
1766 $appt_table_width=$date_width + $time_width + $elder_width;
1767 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1768 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1769 $appt_header_row.= "<th width=$elder_width><font size=-2>Elder</th>";
1770 $appt_table_data = "";
1772 $total_comps=0; $comps_with_quarterly_int=0;
1774 // Display a scheduling table for each district
1775 for ($d=0; $d < count($districts); $d++) {
1776 $table_data=""; $appt_table_data="";
1777 $this->t->set_var('district_number',$districts[$d]['district']);
1778 $this->t->set_var('district_name',$districts[$d]['name']);
1779 $supervisor = $districts[$d]['supervisor'];
1780 $table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": All Elders with Interviews Not Completed";
1781 $appt_table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": Interview Appointment Slots";
1782 $this->t->set_var('table_title',$table_title);
1783 $this->t->set_var('appt_table_title',$appt_table_title);
1785 // query the database for all the appointments
1786 $sql = "SELECT * FROM eq_appointment where presidency=".$districts[$d]['presidency']." and date>=CURDATE() ORDER BY date ASC, time ASC";
1787 $this->db->query($sql,__LINE__,__FILE__);
1789 while ($this->db->next_record())
1791 $appointment = $this->db->f('appointment');
1792 $elder = $this->db->f('elder');
1794 $date = $this->db->f('date');
1795 $date_array = explode("-",$date);
1796 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1797 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1799 $time = $this->db->f('time');
1800 $time_array = explode(":",$time);
1801 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1803 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1804 $appt_table_data.= "<td align=center>$day_string</td>";
1805 $appt_table_data.= "<td align=center>$time_string</td>";
1807 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][elder]>';
1808 $appt_table_data.= '<option value=0></option>';
1809 for ($i=0; $i < count($elder_id_data); $i++) {
1810 $id = $elder_id_data[$i];
1811 $name = $elder_name_data[$i];
1812 if($elder_id_data[$i] == $elder) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
1813 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1815 $appt_table_data.='</select></td>';
1817 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1819 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1820 $this->t->set_var('tr_color',$tr_color);
1823 $this->t->set_var('appt_table_data',$appt_table_data);
1824 $this->t->set_var('appt_header_row',$appt_header_row);
1825 $this->t->set_var('appt_table_width',$appt_table_width);
1827 // INTERVIEW SCHEDULING TABLE
1829 // Select all the unique companionship numbers for this district
1830 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $districts[$d]['district'];
1831 $this->db->query($sql,__LINE__,__FILE__);
1833 while ($this->db->next_record())
1835 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
1840 for ($j=0; $j < count($unique_companionships); $j++) {
1841 // Select all the companions from each companionship
1842 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
1843 "companionship=". $unique_companionships[$j]['companionship'];
1844 $this->db->query($sql,__LINE__,__FILE__);
1845 $k=0; $int_completed=0;
1846 $comp = $unique_companionships[$j]['companionship'];
1847 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1848 $this->t->set_var('tr_color',$tr_color);
1850 while ($this->db->next_record())
1852 // Get this companions information
1853 $elder_id = $this->db->f('elder');
1854 $aaronic_id = $this->db->f('aaronic');
1856 $sql = "SELECT * FROM eq_elder where elder=$elder_id";
1857 $this->db2->query($sql,__LINE__,__FILE__);
1858 if($this->db2->next_record())
1860 $elder_id = $this->db2->f('elder');
1861 $elder_name = $this->db2->f('name');
1862 $elder_phone[$elder_id] = $this->db2->f('phone');
1863 $elder_int_pri[$elder_id] = $this->db2->f('int_pri');
1864 $elder_int_notes[$elder_id] = $this->db2->f('int_notes');
1868 $sql = "SELECT * FROM eq_aaronic where aaronic=$aaronic_id";
1869 $this->db2->query($sql,__LINE__,__FILE__);
1870 if($this->db2->next_record())
1872 $elder_id = $this->db2->f('aaronic');
1873 $elder_name = $this->db2->f('name');
1874 $elder_phone[$elder_id] = $this->db2->f('phone');
1880 $name = $elder_name;
1881 $phone = $elder_phone[$id];
1882 $int_pri = $elder_int_pri[$id];
1883 $int_notes = $elder_int_notes[$id];
1884 $aaronic = $elder_aaronic;
1886 // If the companionship has already had its quarterly interview,
1887 // Skip the other companion in the companionship.
1888 if($int_completed == 1) {
1889 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1890 $completed_data.= "<td align=center>$phone</td>";
1891 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1892 $completed_data.= "<td align=left>$int_notes</td>";
1893 $completed_data.= '</tr>';
1894 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1895 $this->t->set_var('tr_color2',$tr_color2);
1896 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1897 $this->t->set_var('tr_color',$tr_color);
1901 // If this companionship has had a hometeaching interview this quarter, don't show them on the schedule list
1902 $sql = "SELECT * FROM eq_interview WHERE date >= '$quarter_start' AND date < '$quarter_end' ".
1904 $this->db2->query($sql,__LINE__,__FILE__);
1906 if(!$this->db2->next_record()) {
1907 $sql = "SELECT * FROM eq_interview WHERE elder=" . $id . " ORDER BY date DESC";
1908 $this->db3->query($sql,__LINE__,__FILE__);
1909 if($this->db3->next_record()) { $date = $this->db3->f('date'); } else { $date = ""; }
1910 $link_data['menuaction'] = 'eq.eq.int_update';
1911 $link_data['elder'] = $id;
1912 $link_data['aaronic'] = 0;
1913 $link_data['name'] = $name;
1914 $link_data['interview'] = '';
1915 $link_data['action'] = 'add';
1916 $link_data['interviewer'] = $districts[$d]['supervisor'];
1917 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1918 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1919 $table_data.= "<td align=center>$phone</td>";
1920 $table_data.= "<td align=center>";
1922 $table_data.= '<select name=int_notes['.$i.'][pri]>';
1923 foreach(range(0,6) as $num) {
1924 if($num == 0) { $num = 1; } else {$num = $num*5; }
1925 if($int_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
1926 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1928 $table_data.= '</select></td>';
1930 $table_data.= "<td align=center>$date</td>";
1932 $table_data.= '<td><input type=text size="50" maxlength="128" name="int_notes['.$i.'][notes]" value="'.$int_notes.'">';
1934 $table_data.= '<input type=hidden name="int_notes['.$i.'][elder_id]" value="'.$id.'">';
1935 $table_data.= '<input type=hidden name="int_notes['.$i.'][elder_name]" value="'.$name.'">';
1936 $table_data.= '<input type=hidden name="int_notes['.$i.'][aaronic]" value="'.$aaronic.'">';
1937 $table_data.= '</td>';
1938 $table_data.= '</tr>'."\n";
1941 $link_data['menuaction'] = 'eq.eq.int_update';
1942 $link_data['interviewer'] = $this->db2->f('interviewer');
1943 $link_data['elder'] = $this->db2->f('elder');
1944 $link_data['aaronic'] = $this->db2->f('aaronic');
1945 $link_data['name'] = $name;
1946 $link_data['interview'] = $this->db2->f('int');
1947 $link_data['action'] = 'view';
1948 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1949 $comps_with_quarterly_int++;
1951 $date = $this->db2->f('date');
1952 $int_notes = $this->db2->f('notes');
1953 if(strlen($int_notes) > 40) { $int_notes = substr($int_notes,0,40) . "..."; }
1954 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1955 $completed_data.= "<td align=center>$phone</td>";
1956 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1957 $completed_data.= "<td align=left>$int_notes</td>";
1958 $completed_data.= '</tr>';
1963 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1964 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1965 $completed_header_row = "<th width=$name_width><font size=-2>Elder Name</th>";
1966 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1967 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1968 $completed_header_row.= "<th width=$notes_width><font size=-2>Interview Notes</th>";
1970 $this->t->set_var('table_width',$table_width);
1971 $this->t->set_var('header_row',$header_row);
1972 $this->t->set_var('table_data',$table_data);
1973 $this->t->set_var('completed_header_row',$completed_header_row);
1974 $this->t->set_var('completed_table_width',$completed_table_width);
1975 $this->t->set_var('completed',$completed_data);
1976 $this->t->fp('elderlist','elder_list',True);
1978 } // End for each district loop
1981 $elders_width=300; $totals_width=100;
1982 $totals_table_width=$elders_width + $totals_width;
1983 $totals_header_row = "<th width=$elders_width><font size=-2>Elders</th>";
1984 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
1985 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1986 $totals_data.= "<td align=left><font size=-2><b>Total Companionships with interviews completed:</b></font></td>";
1987 $totals_data.= "<td align=center><font size=-2><b>$comps_with_quarterly_int / $total_comps</b></font></td>";
1988 $percent = ceil(($comps_with_quarterly_int / $total_comps)*100);
1989 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1990 $this->t->set_var('tr_color',$tr_color);
1991 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1992 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
1993 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
1994 $totals_data.= "</tr>";
1996 $this->t->set_var('totals',$totals_data);
1997 $this->t->set_var('totals_header_row',$totals_header_row);
1998 $this->t->set_var('totals_table_width',$totals_table_width);
2000 $this->t->pfp('out','int_sched_t');
2001 $this->save_sessiondata();
2005 function vis_sched()
2007 $this->t->set_file(array('vis_sched_t' => 'vis_sched.tpl'));
2008 $this->t->set_block('vis_sched_t','family_list','familylist');
2009 $this->t->set_block('vis_sched_t','appt_list','apptlist');
2010 $action = get_var('action',array('GET','POST'));
2012 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
2013 $this->t->set_var('lang_reset','Clear Changes');
2015 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
2016 $this->t->set_var('vis_link_title','View Yearly Visits');
2018 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched'));
2019 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2021 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched&action=save'));
2022 $this->t->set_var('title','EQ Presidency Yearly Visit Scheduler');
2024 $family_width=500; $phone_width=40; $pri_width=10; $notes_width=128; $visit_date_width=20;
2025 $table_width=$family_width + $phone_width + $pri_width + $notes_width + $visit_date_width;
2026 $header_row = "<th width=$family_width><font size=-2>Family Name</th>";
2027 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2028 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
2029 $header_row.= "<th width=$visit_date_width><font size=-2>Last Visit</th>";
2030 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
2031 $table_data=""; $completed_data=""; $totals_data="";
2035 if($action == 'save')
2037 // Save any changes made to the appointment table
2038 $new_data = get_var('appt_notes',array('POST'));
2039 foreach ($new_data as $entry)
2041 $family = $entry['family'];
2042 $appointment = $entry['appointment'];
2044 //Only perform a database update if we have made a change to this appointment
2045 $sql = "SELECT * FROM eq_appointment where appointment='$appointment' and family='$family'";
2046 $this->db->query($sql,__LINE__,__FILE__);
2047 if(!$this->db->next_record()) {
2049 // Perform database save actions here
2050 $this->db->query("UPDATE eq_appointment set " .
2051 " family='" . $family . "'" .
2052 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
2054 // Email the appointment
2055 $this->email_appt($appointment);
2059 // Save any changes made to the visit notes table
2060 $new_data = get_var('vis_notes',array('POST'));
2061 foreach ($new_data as $entry)
2063 $visit_notes = $entry['notes'];
2064 $family_id = $entry['family_id'];
2065 $visit_pri = $entry['pri'];
2067 // Perform database save actions here
2068 $this->db->query("UPDATE eq_family set " .
2069 " visit_notes='" . $visit_notes . "'" .
2070 ",visit_pri='" . $visit_pri . "'" .
2071 " WHERE family=" . $family_id,__LINE__,__FILE__);
2075 $take_me_to_url = $GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched');
2076 Header('Location: ' . $take_me_to_url);
2079 // APPOINTMENT TABLE
2080 $date_width=150; $time_width=100; $family_width=250;
2081 $appt_table_width=$date_width + $time_width + $family_width;
2082 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
2083 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
2084 $appt_header_row.= "<th width=$family_width><font size=-2>Family</th>";
2085 $appt_table_data = "";
2087 // Find out what the EQ Presidency ID is
2088 $sql = "SELECT * FROM eq_presidency where eqpres=1 and valid=1";
2089 $this->db->query($sql,__LINE__,__FILE__);
2090 if($this->db->next_record()) {
2091 $presidency_name = $this->db->f('name');
2092 $presidency_id = $this->db->f('presidency');
2094 print "<hr><font color=red><h3>-E- Unable to locate EQ Presidency in eq_presidency table</h3></font></hr>";
2098 // create the family id -> family name mapping
2099 $sql = "SELECT * FROM eq_family where valid=1 and elder_id != 0 ORDER BY name ASC";
2100 $this->db->query($sql,__LINE__,__FILE__);
2103 while ($this->db->next_record())
2105 $family_id[$i] = $this->db->f('family');
2106 $family_name[$i] = $this->db->f('name');
2109 array_multisort($family_name, $family_id);
2111 // query the database for all the appointments
2112 $sql = "SELECT * FROM eq_appointment where presidency=$presidency_id and date>=CURDATE() ORDER BY date ASC, time ASC";
2113 $this->db->query($sql,__LINE__,__FILE__);
2115 while ($this->db->next_record())
2117 $appointment = $this->db->f('appointment');
2118 $family = $this->db->f('family');
2120 $date = $this->db->f('date');
2121 $date_array = explode("-",$date);
2122 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
2123 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
2125 $time = $this->db->f('time');
2126 $time_array = explode(":",$time);
2127 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
2129 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2130 $appt_table_data.= "<td align=center>$day_string</td>";
2131 $appt_table_data.= "<td align=center>$time_string</td>";
2133 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][family]>';
2134 $appt_table_data.= '<option value=0></option>';
2135 for ($i=0; $i < count($family_id); $i++) {
2136 $id = $family_id[$i];
2137 $name = $family_name[$i];
2138 if($family_id[$i] == $family) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
2139 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
2141 $appt_table_data.='</select></td>';
2143 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
2145 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2146 $this->t->set_var('tr_color',$tr_color);
2149 $this->t->set_var('appt_table_data',$appt_table_data);
2150 $this->t->set_var('appt_header_row',$appt_header_row);
2151 $this->t->set_var('appt_table_width',$appt_table_width);
2154 // VISIT SCHEDULING TABLE
2155 $sql = "SELECT * FROM eq_family where valid=1 and elder_id != 0 ORDER BY visit_pri ASC";
2156 $this->db->query($sql,__LINE__,__FILE__);
2158 $total_families=0; $families_with_yearly_visit=0;
2162 $family_name = NULL;
2163 $family_phone = NULL;
2164 $family_visit_pri = NULL;
2165 $family_visit_notes = NULL;
2166 while ($this->db->next_record())
2168 $family_id[$i] = $this->db->f('family');
2169 $family_name[$i] = $this->db->f('name');
2170 $family_phone[$family_id[$i]] = $family_id[$i] . " ERROR";
2171 $family_visit_pri[$family_id[$i]] = $this->db->f('visit_pri');
2172 $family_visit_notes[$family_id[$i]] = $this->db->f('visit_notes');
2177 $sql = "SELECT * FROM eq_parent where valid=1";
2178 $this->db->query($sql,__LINE__,__FILE__);
2179 while ($this->db->next_record())
2181 $family = $this->db->f('family');
2182 $phone = $this->db->f('phone');
2183 $family_phone[$family] = $phone;
2186 $max = count($family_id);
2188 for($i=0; $i < $max; $i++) {
2189 $id = $family_id[$i];
2190 $name = $family_name[$i];
2191 $phone = $family_phone[$id];
2192 $vis_pri = $family_visit_pri[$id];
2193 $vis_notes = $family_visit_notes[$id];
2195 // If this family has had a yearly visit this year, don't show them on the schedule list
2196 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2197 $sql = "SELECT * FROM eq_visit WHERE date > '$year_start' AND date < '$year_end' ".
2198 "AND family=" . $id . " AND companionship=0";
2199 $this->db2->query($sql,__LINE__,__FILE__);
2201 if(!$this->db2->next_record()) {
2202 $sql = "SELECT * FROM eq_visit WHERE family=" . $id . " AND companionship=0 ORDER BY date DESC";
2203 $this->db->query($sql,__LINE__,__FILE__);
2204 if($this->db->next_record()) { $date = $this->db->f('date'); } else { $date = ""; }
2205 $link_data['menuaction'] = 'eq.eq.vis_update';
2206 $link_data['visit'] = '';
2207 $link_data['family'] = $id;
2208 $link_data['name'] = $name;
2209 $link_data['action'] = 'add';
2210 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2211 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2212 $table_data.= "<td align=center>$phone</td>";
2213 $table_data.= "<td align=center>";
2214 $table_data.= '<select name=vis_notes['.$i.'][pri]>';
2215 foreach(range(0,6) as $num) {
2216 if($num == 0) { $num = 1; } else {$num = $num*5; }
2217 if($vis_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
2218 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2220 $table_data.= '</select></td>';
2221 $table_data.= "<td align=center>$date</td>";
2222 $table_data.= '<td><input type=text size="50" maxlength="128" name="vis_notes['.$i.'][notes]" value="'.$vis_notes.'">';
2223 $table_data.= '<input type=hidden name="vis_notes['.$i.'][family_id]" value="'.$id.'">';
2224 $table_data.= '<input type=hidden name="vis_notes['.$i.'][family_name]" value="'.$name.'">';
2225 $table_data.= '</td>';
2226 $table_data.= '</tr>';
2227 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2228 $this->t->set_var('tr_color',$tr_color);
2230 $link_data['menuaction'] = 'eq.eq.vis_update';
2231 $link_data['visit'] = $this->db2->f('visit');
2232 $link_data['family'] = $this->db2->f('family');
2233 $link_data['name'] = $name;
2234 $link_data['date'] = $this->db2->f('date');
2235 $link_data['action'] = 'view';
2236 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2237 $families_with_yearly_visit++;
2238 $date = $this->db2->f('date');
2239 $vis_notes = $this->db2->f('notes');
2240 if(strlen($vis_notes) > 40) { $vis_notes = stripslashes(substr($vis_notes,0,40) . "..."); }
2241 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2242 $completed_data.= "<td align=center>$phone</td>";
2243 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2244 $completed_data.= "<td align=left>$vis_notes</td>";
2245 $completed_data.= '</tr>';
2246 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
2247 $this->t->set_var('tr_color2',$tr_color2);
2251 $name_width=190; $phone_width=100; $date_width=100; $notes_width=300;
2252 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
2253 $completed_header_row = "<th width=$name_width><font size=-2>Family Name</th>";
2254 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2255 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
2256 $completed_header_row.= "<th width=$notes_width><font size=-2>Visit Notes</th>";
2258 $family_width=300; $totals_width=100;
2259 $totals_table_width=$family_width + $totals_width;
2260 $totals_header_row = "<th width=$family_width><font size=-2>Families</th>";
2261 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2262 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2263 $totals_data.= "<td align=left><font size=-2><b>Total Families with yearly Visits completed:</b></font></td>";
2264 $totals_data.= "<td align=center><font size=-2><b>$families_with_yearly_visit / $total_families</b></font></td>";
2265 $percent = ceil(($families_with_yearly_visit / $total_families)*100);
2266 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2267 $this->t->set_var('tr_color',$tr_color);
2268 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2269 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2270 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2271 $totals_data.= "</tr>";
2273 $this->t->set_var('table_width',$table_width);
2274 $this->t->set_var('header_row',$header_row);
2275 $this->t->set_var('table_data',$table_data);
2276 $this->t->set_var('totals_header_row',$totals_header_row);
2277 $this->t->set_var('totals_table_width',$totals_table_width);
2278 $this->t->set_var('completed_header_row',$completed_header_row);
2279 $this->t->set_var('completed_table_width',$completed_table_width);
2280 $this->t->set_var('completed',$completed_data);
2281 $this->t->set_var('totals',$totals_data);
2282 $this->t->fp('familylist','family_list',True);
2283 $this->t->fp('apptlist','appt_list',True);
2285 $this->t->pfp('out','vis_sched_t');
2286 $this->save_sessiondata();
2292 $this->t->set_file(array('ppi_view_t' => 'ppi_view.tpl'));
2293 $this->t->set_block('ppi_view_t','district_list','list');
2295 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
2296 $num_months = get_var('num_months',array('GET','POST'));
2297 if($num_months == '') { $num_months = $this->default_ppi_num_months; }
2298 $this->t->set_var('num_months',$num_months);
2299 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
2300 else { $this->t->set_var('lang_num_months','Months of History'); }
2301 $this->t->set_var('lang_filter','Filter');
2302 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
2304 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
2305 $this->t->set_var('ppi_link_title','Yearly PPIs');
2307 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched'));
2308 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
2310 $this->t->set_var('title','Yearly PPIs');
2311 $num_months = get_var('num_months',array('GET','POST'));
2312 if($num_months == '') { $num_months = $this->default_ppi_num_years; }
2313 $this->t->set_var('num_months',$num_months);
2314 if($num_months == 1) { $this->t->set_var('lang_num_months','Year of History'); }
2315 else { $this->t->set_var('lang_num_months','Years of History'); }
2317 $sql = "SELECT * FROM eq_presidency where president=1 and valid=1";
2318 $this->db->query($sql,__LINE__,__FILE__);
2319 if($this->db->next_record()) {
2320 $president_name = $this->db->f('name');
2321 $interviewer = $this->db->f('elder');
2324 print "<hr><font color=red><h3>-E- Unable to locate EQ President in eq_presidency table</h3></font></hr>";
2327 $this->t->set_var('district_number','*');
2328 $this->t->set_var('district_name',$president_name);
2330 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
2331 $this->db->query($sql,__LINE__,__FILE__);
2333 while ($this->db->next_record())
2335 $elder_id[$i] = $this->db->f('elder');
2336 $elder_name[$i] = $this->db->f('name');
2337 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
2338 $elder_ppi_pri[$elder_id[$i]] = $this->db->f('ppi_pri');
2339 $elder_ppi_notes[$elder_id[$i]] = $this->db->f('ppi_notes');
2343 array_multisort($elder_name, $elder_id);
2344 //var_dump($elder_name); print "<br><br>"; var_dump($elder_id);
2346 $header_row="<th width=$comp_width><font size=-2>Elder Name</th>";
2348 $elder_width=400; $ppi_width=75; $table_width=$elder_width + $num_months*$ppi_width;
2350 for($m=$num_months; $m >= 0; $m--) {
2351 $year = date('Y') - $m;
2352 $header_row .= "<th width=150><font size=-2>$year</th>";
2356 for ($j=0; $j < count($elder_id); $j++) {
2357 $id = $elder_id[$j];
2358 $name = $elder_name[$j];
2359 $phone = $elder_phone[$id];
2361 $link_data['menuaction'] = 'eq.eq.ppi_update';
2362 $link_data['interviewer'] = $interviewer;
2363 $link_data['elder'] = $id;
2364 $link_data['name'] = $name;
2365 $link_data['ppi'] = '';
2366 $link_data['eqpresppi'] = $eqpresppi;
2367 $link_data['action'] = 'add';
2368 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2369 $this->nextmatchs->template_alternate_row_color(&$this->t);
2370 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2372 // Find out how many times PPIs were performed in the past $num_months for this Elder
2373 for($m=$num_months; $m >= 0; $m--) {
2374 $year = date('Y') - $m;
2375 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2376 $sql = "SELECT * FROM eq_ppi WHERE date > '$year_start' AND date < '$year_end' ".
2378 $this->db2->query($sql,__LINE__,__FILE__);
2380 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
2381 if($this->db2->next_record()) {
2382 $ppis[$m]++; $total_ppis[$m]++; $ppi_recorded[$companionship][$m]=1;
2383 $link_data['menuaction'] = 'eq.eq.ppi_update';
2384 $link_data['companionship'] = $companionship;
2385 $link_data['interviewer'] = $this->db2->f('interviewer');
2386 $link_data['elder'] = $id;
2387 $link_data['name'] = $name;
2388 $link_data['ppi'] = $this->db2->f('ppi');
2389 $link_data['eqpresppi'] = $eqpresppi;
2390 $link_data['action'] = 'view';
2391 $date = $this->db2->f('date');
2392 $date_array = explode("-",$date);
2393 $month = $date_array[1];
2394 $day = $date_array[2];
2395 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2396 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2398 else { $table_data .= "<td> </td>"; }
2400 $table_data .= "</tr>\n";
2402 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2404 $stat_data = "<tr><td><b><font size=-2>$total_elders Elders<br>PPI Totals:</font></b></td>";
2405 for($m=$num_months; $m >=0; $m--) {
2406 $percent = ceil(($ppis[$m] / $total_elders)*100);
2407 $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
2409 $stat_data .= "</tr>";
2411 $this->t->set_var('table_width',$table_width);
2412 $this->t->set_var('header_row',$header_row);
2413 $this->t->set_var('table_data',$table_data);
2414 $this->t->set_var('stat_data',$stat_data);
2415 $this->t->pfp('out','ppi_view_t');
2416 $this->save_sessiondata();
2419 function ppi_update()
2421 $this->t->set_file(array('form' => 'ppi_update.tpl'));
2422 $this->t->set_block('form','interviewer_list','int_list');
2423 $this->t->set_block('form','add','addhandle');
2424 $this->t->set_block('form','edit','edithandle');
2426 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
2427 $this->t->set_var('readonly','');
2428 $this->t->set_var('disabled','');
2430 $action = get_var('action',array('GET','POST'));
2431 $companionship = get_var('companionship',array('GET','POST'));
2432 $interviewer = get_var('interviewer',array('GET','POST'));
2433 $name = get_var('name',array('GET','POST'));
2434 $ppi = get_var('ppi',array('GET','POST'));
2435 $elder = get_var('elder',array('GET','POST'));
2436 $aaronic = get_var('aaronic',array('GET','POST'));
2437 $date = get_var('date',array('GET','POST'));
2438 $notes = get_var('notes',array('GET','POST'));
2439 $eqpresppi = get_var('eqpresppi',array('GET','POST'));
2441 $sql = "SELECT * FROM eq_elder WHERE elder=" . $interviewer;
2442 $this->db2->query($sql,__LINE__,__FILE__);
2443 $this->db2->next_record();
2444 $interviewer_name = $this->db2->f('name');
2445 $this->t->set_var('interviewer',$interviewer . ' selected');
2446 $this->t->set_var('interviewer_name',$interviewer_name);
2447 $this->t->fp('int_list','interviewer_list',True);
2449 if($action == 'save')
2451 $notes = get_var('notes',array('POST'));
2452 $this->db->query("UPDATE eq_ppi set " .
2453 " ppi='" . $ppi . "'" .
2454 ", interviewer='" . $interviewer . "'" .
2455 ", elder='" . $elder . "'" .
2456 ", date='" . $date . "'" .
2457 ", notes='" . $notes . "'" .
2458 ", eqpresppi='" . $eqpresppi . "'" .
2459 " WHERE ppi=" . $ppi,__LINE__,__FILE__);
2464 if($action == 'insert')
2466 $notes = get_var('notes',array('POST'));
2467 $this->db->query("INSERT INTO eq_ppi (interviewer,elder,date,notes,eqpresppi) "
2468 . "VALUES ('" . $interviewer . "','" . $elder . "','"
2469 . $date . "','" . $notes . "','" . $eqpresppi ."')",__LINE__,__FILE__);
2474 if($action == 'add')
2476 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2477 $this->t->set_var('ppi', '');
2478 $this->t->set_var('interviewer', $interviewer);
2479 $this->t->set_var('name',$name);
2480 $this->t->set_var('elder',$elder);
2481 $this->t->set_var('date','');
2482 $this->t->set_var('notes','');
2483 $this->t->set_var('eqpresppi',$eqpresppi);
2484 $this->t->set_var('lang_done','Cancel');
2485 $this->t->set_var('lang_action','Adding New PPI');
2486 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
2487 . $ppi . '&action=' . 'insert'));
2490 if($action == 'edit' || $action == 'view')
2492 $sql = "SELECT * FROM eq_ppi WHERE ppi=".$ppi;
2493 $this->db->query($sql,__LINE__,__FILE__);
2494 $this->db->next_record();
2495 $this->t->set_var('ppi',$ppi);
2496 $this->t->set_var('name',$name);
2497 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2498 $this->t->set_var('elder',$this->db->f('elder'));
2499 $this->t->set_var('date',$this->db->f('date'));
2500 $this->t->set_var('notes',$this->db->f('notes'));
2501 $this->t->set_var('eqpresppi',$this->db->f('eqpresppi'));
2504 if($action == 'edit')
2506 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2507 $this->t->set_var('lang_done','Cancel');
2508 $this->t->set_var('lang_action','Editing PPI');
2509 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
2510 . $ppi . '&action=' . 'save'));
2513 if($action == 'view')
2515 $date = $this->db->f('date');
2516 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2517 $this->t->set_var('readonly','READONLY');
2518 $this->t->set_var('disabled','DISABLED');
2519 $this->t->set_var('lang_done','Done');
2520 $this->t->set_var('lang_action','Viewing PPI');
2521 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
2522 . $ppi . '&action=' . 'edit'));
2525 $this->t->set_var('lang_reset','Clear Form');
2526 $this->t->set_var('lang_add','Add PPI');
2527 $this->t->set_var('lang_save','Save Changes');
2528 $this->t->set_var('edithandle','');
2529 $this->t->set_var('addhandle','');
2531 $this->t->pfp('out','form');
2533 if($action == 'view') { $this->t->set_var('lang_save','Edit PPI'); }
2534 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2535 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2537 $this->save_sessiondata();
2542 $this->t->set_file(array('int_view_t' => 'int_view.tpl'));
2543 $this->t->set_block('int_view_t','district_list','list');
2545 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_view'));
2546 $num_quarters = get_var('num_quarters',array('GET','POST'));
2547 if($num_quarters == '') { $num_quarters = $this->default_int_num_quarters; }
2548 $this->t->set_var('num_quarters',$num_quarters);
2549 if($num_quarters == 1) { $this->t->set_var('lang_num_quarters','Quarter of History'); }
2550 else { $this->t->set_var('lang_num_quarters','Quarters of History'); }
2551 $this->t->set_var('lang_filter','Filter');
2553 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_view'));
2554 $this->t->set_var('int_link_title','Hometeaching Interviews');
2556 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_sched'));
2557 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
2559 $this->t->set_var('title','Hometeaching Interviews');
2561 $num_months = $num_quarters * 3 - 1;
2562 $current_month = $this->current_month;
2563 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
2564 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
2565 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
2566 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
2568 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
2569 $this->db->query($sql,__LINE__,__FILE__);
2571 while ($this->db->next_record())
2573 $districts[$i]['district'] = $this->db->f('district');
2574 $districts[$i]['name'] = $this->db->f('name');
2575 $districts[$i]['supervisor'] = $this->db->f('supervisor');
2579 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
2580 $this->db->query($sql,__LINE__,__FILE__);
2582 while ($this->db->next_record())
2584 $elder_id[$i] = $this->db->f('elder');
2585 $elder_name[$i] = $this->db->f('name');
2586 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
2589 array_multisort($elder_name, $elder_id);
2590 for($i=0; $i < count($elder_id); $i++) {
2591 $id = $elder_id[$i];
2592 $elders[$id] = $elder_name[$i];
2595 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
2596 $this->db->query($sql,__LINE__,__FILE__);
2597 while ($this->db->next_record())
2599 $aaronic_id = $this->db->f('aaronic');
2600 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
2601 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
2604 $total_companionships = 0;
2605 $this->nextmatchs->template_alternate_row_color(&$this->t);
2606 for ($i=0; $i < count($districts); $i++) {
2607 $this->t->set_var('district_number',$districts[$i]['district']);
2608 $this->t->set_var('district_name',$districts[$i]['name']);
2609 $supervisor = $districts[$i]['supervisor'];
2610 $unique_companionships='';
2612 // Select all the unique companionship numbers for this district
2613 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $districts[$i]['district'];
2615 $this->db->query($sql,__LINE__,__FILE__);
2617 while ($this->db->next_record())
2619 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
2623 $comp_width=250; $int_width=75; $table_width=$comp_width + $num_months*$int_width;
2624 $table_data=""; $num_companionships = $j; $num_elders = 0;
2625 for($m=$num_months; $m >= 0; $m--) { $ints[$m] = 0; }
2626 for ($j=0; $j < count($unique_companionships); $j++) {
2627 // Select all the companions in each companionship
2628 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
2629 "companionship=". $unique_companionships[$j]['companionship'];
2630 $this->db->query($sql,__LINE__,__FILE__);
2632 $comp = $unique_companionships[$j]['companionship'];
2633 for($m=$num_months; $m >= 0; $m--) { $int_recorded[$comp][$m] = 0; }
2634 while ($this->db->next_record())
2636 // Get this companions information
2638 $companionship = $this->db->f('companionship');
2639 $elder_id = $this->db->f('elder');
2640 $aaronic_id = $this->db->f('aaronic');
2642 $name = $elders[$elder_id];
2643 $phone = $elder_phone[$elder_id];
2645 else if($aaronic_id) {
2646 $name = $aaronic[$aaronic_id]['name'];
2647 $phone = $aaronic[$aaronic_id]['phone'];
2649 $link_data['menuaction'] = 'eq.eq.int_update';
2650 $link_data['companionship'] = $companionship;
2651 $link_data['interviewer'] = $supervisor;
2652 $link_data['elder'] = $elder_id;
2653 $link_data['aaronic'] = $aaronic_id;
2654 $link_data['name'] = $name;
2655 $link_data['interview'] = '';
2656 $link_data['action'] = 'add';
2657 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2658 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2660 // Find out how many times Interviews were performed in the past $num_months for this Elder
2661 $header_row="<th width=$comp_width><font size=-2>Companionship</th>";
2662 for($m=$num_months; $m >= 0; $m--) {
2663 $month = $current_month - $m;
2664 $year = $this->current_year;
2665 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
2666 if($month < 10) { $month = "0"."$month"; }
2667 $month_start = "$year"."-"."$month"."-"."01";
2668 $month_end = "$year"."-"."$month"."-"."31";
2669 $month = "$month"."/"."$year";
2670 $sql = "SELECT * FROM eq_interview WHERE date >= '$month_start' AND date <= '$month_end' ".
2671 "AND elder=" . $elder_id . " AND aaronic=" . $aaronic_id;
2672 $this->db2->query($sql,__LINE__,__FILE__);
2673 $header_row .= "<th width=$int_width><font size=-2>$month</th>";
2675 if(!$total_ints[$m]) { $total_ints[$m] = 0; }
2676 if($this->db2->next_record()) {
2677 if(!$int_recorded[$companionship][$m]) {
2678 $ints[$m]++; $total_ints[$m]++; $int_recorded[$companionship][$m]=1;
2680 $link_data['menuaction'] = 'eq.eq.int_update';
2681 $link_data['companionship'] = $companionship;
2682 $link_data['interviewer'] = $this->db2->f('interviewer');
2683 $link_data['elder'] = $elder_id;
2684 $link_data['aaronic'] = $aaronic_id;
2685 $link_data['name'] = $name;
2686 $link_data['interview'] = $this->db2->f('interview');
2687 $link_data['action'] = 'view';
2688 $date = $this->db2->f('date');
2689 $date_array = explode("-",$date);
2690 $month = $date_array[1];
2691 $day = $date_array[2];
2692 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2693 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2695 else { $table_data .= "<td> </td>"; }
2697 $table_data .= "</tr>";
2700 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2702 $total_companionships += $num_companionships;
2703 $stat_data = "<tr><td><b><font size=-2>$num_companionships Companionships<br>Interview Quarterly Totals:</font></b></td>";
2705 for($m=$num_months; $m >=0; $m--) {
2706 $month = $current_month - $m;
2707 if(($month % 3) == 1) { $quarter_total = $ints[$m]; }
2708 else { $quarter_total += $ints[$m]; }
2709 $percent = ceil(($quarter_total / $num_companionships)*100);
2710 $stat_data .= "<td align=center><font size=-2><b>$quarter_total<br>$percent%</font></b></td>";
2712 $stat_data .= "</tr>";
2714 $this->t->set_var('table_width',$table_width);
2715 $this->t->set_var('header_row',$header_row);
2716 $this->t->set_var('table_data',$table_data);
2717 $this->t->set_var('stat_data',$stat_data);
2718 $this->t->fp('list','district_list',True);
2721 // Display the totals, cummulative per quarter
2723 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>Interview Quarterly Totals:</font></b></td>";
2724 for($m=$num_months; $m >=0; $m--) {
2725 $month = $current_month - $m;
2726 if(($month % 3) == 1) { $quarter_total = $total_ints[$m]; }
2727 else { $quarter_total += $total_ints[$m]; }
2728 $percent = ceil(($quarter_total / $total_companionships)*100);
2729 $totals .= "<td align=center><font size=-2><b>$quarter_total<br>$percent%</font></b></td>";
2733 $this->t->set_var('totals',$totals);
2734 $this->t->pfp('out','int_view_t');
2735 $this->save_sessiondata();
2738 function int_update()
2740 $this->t->set_file(array('form' => 'int_update.tpl'));
2741 $this->t->set_block('form','interviewer_list','int_list');
2742 $this->t->set_block('form','add','addhandle');
2743 $this->t->set_block('form','edit','edithandle');
2745 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_view'));
2746 $this->t->set_var('readonly','');
2747 $this->t->set_var('disabled','');
2749 $action = get_var('action',array('GET','POST'));
2750 $companionship = get_var('companionship',array('GET','POST'));
2751 $interviewer = get_var('interviewer',array('GET','POST'));
2752 $name = get_var('name',array('GET','POST'));
2753 $interview = get_var('interview',array('GET','POST'));
2754 $elder = get_var('elder',array('GET','POST'));
2755 $aaronic = get_var('aaronic',array('GET','POST'));
2756 $date = get_var('date',array('GET','POST'));
2757 $notes = get_var('notes',array('GET','POST'));
2759 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
2760 $this->db->query($sql,__LINE__,__FILE__);
2761 while ($this->db->next_record())
2763 $supervisor = $this->db->f('supervisor');
2764 $sql = "SELECT * FROM eq_elder WHERE elder=" . $supervisor;
2765 $this->db2->query($sql,__LINE__,__FILE__);
2766 $this->db2->next_record();
2767 $interviewer_name = $this->db2->f('name');
2769 if($supervisor == $interviewer) {
2770 $this->t->set_var('interviewer',$supervisor . ' selected');
2772 $this->t->set_var('interviewer',$interviewer);
2774 $this->t->set_var('interviewer_name',$interviewer_name);
2775 $this->t->fp('int_list','interviewer_list',True);
2778 if($action == 'save')
2780 $notes = get_var('notes',array('POST'));
2781 $this->db->query("UPDATE eq_interview set " .
2782 " interview='" . $interview . "'" .
2783 ", interviewer='" . $interviewer . "'" .
2784 ", elder='" . $elder . "'" .
2785 ", aaronic='" . $aaronic . "'" .
2786 ", date='" . $date . "'" .
2787 ", notes='" . $notes . "'" .
2788 " WHERE interview=" . $interview,__LINE__,__FILE__);
2793 if($action == 'insert')
2795 $notes = get_var('notes',array('POST'));
2796 $this->db->query("INSERT INTO eq_interview (interviewer,elder,aaronic,date,notes) "
2797 . "VALUES ('" . $interviewer . "','" . $elder . "','" . $aaronic . "','"
2798 . $date . "','" . $notes ."')",__LINE__,__FILE__);
2803 if($action == 'add')
2805 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2806 $this->t->set_var('interview', '');
2807 $this->t->set_var('interviewer', $interviewer);
2808 $this->t->set_var('name',$name);
2809 $this->t->set_var('elder',$elder);
2810 $this->t->set_var('aaronic',$aaronic);
2811 $this->t->set_var('date','');
2812 $this->t->set_var('notes','');
2813 $this->t->set_var('lang_done','Cancel');
2814 $this->t->set_var('lang_action','Adding New Interview');
2815 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_update&interview='
2816 . $interview . '&action=' . 'insert'));
2819 if($action == 'edit' || $action == 'view')
2821 $sql = "SELECT * FROM eq_interview WHERE interview=".$interview;
2822 $this->db->query($sql,__LINE__,__FILE__);
2823 $this->db->next_record();
2824 $this->t->set_var('interview',$interview);
2825 $this->t->set_var('name',$name);
2826 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2827 $this->t->set_var('elder',$this->db->f('elder'));
2828 $this->t->set_var('aaronic',$this->db->f('aaronic'));
2829 $this->t->set_var('date',$this->db->f('date'));
2830 $this->t->set_var('notes',$this->db->f('notes'));
2833 if($action == 'edit')
2835 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2836 $this->t->set_var('lang_done','Cancel');
2837 $this->t->set_var('lang_action','Editing Interview');
2838 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_update&interview='
2839 . $interview . '&action=' . 'save'));
2842 if($action == 'view')
2844 $date = $this->db->f('date');
2845 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2846 $this->t->set_var('readonly','READONLY');
2847 $this->t->set_var('disabled','DISABLED');
2848 $this->t->set_var('lang_done','Done');
2849 $this->t->set_var('lang_action','Viewing Interview');
2850 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_update&interview='
2851 . $interview . '&action=' . 'edit'));
2854 $this->t->set_var('lang_reset','Clear Form');
2855 $this->t->set_var('lang_add','Add Interview');
2856 $this->t->set_var('lang_save','Save Changes');
2857 $this->t->set_var('edithandle','');
2858 $this->t->set_var('addhandle','');
2860 $this->t->pfp('out','form');
2862 if($action == 'view') { $this->t->set_var('lang_save','Edit Interview'); }
2863 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2864 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2866 $this->save_sessiondata();
2871 $this->t->set_file(array('vis_view_t' => 'vis_view.tpl'));
2872 $this->t->set_block('vis_view_t','visit_list','list1');
2873 $this->t->set_block('vis_view_t','family_list','list2');
2875 $this->t->set_var('lang_name','Family Name');
2876 $this->t->set_var('lang_date','Date');
2878 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
2879 $this->t->set_var('vis_link_title','View Yearly Visits');
2881 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched'));
2882 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2884 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
2885 $num_years = get_var('num_years',array('GET','POST'));
2886 if($num_years == '') { $num_years = $this->default_vis_num_years; }
2887 $this->t->set_var('num_years',$num_years);
2888 if($num_years == 1) { $this->t->set_var('lang_num_years','Year of History'); }
2889 else { $this->t->set_var('lang_num_years','Years of History'); }
2890 $this->t->set_var('lang_filter','Filter');
2892 $year = date('Y') - $num_years + 1;
2893 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2895 $sql = "SELECT * FROM eq_visit WHERE companionship=0 and date > '$year_start' ORDER BY date DESC";
2896 $this->db->query($sql,__LINE__,__FILE__);
2897 $total_records = $this->db->num_rows();
2900 while ($this->db->next_record())
2902 $visit_list[$i]['visit'] = $this->db->f('visit');
2903 $visit_list[$i]['family'] = $this->db->f('family');
2904 $visit_list[$i]['date'] = $this->db->f('date');
2908 for ($i=0; $i < count($visit_list); $i++)
2910 $this->nextmatchs->template_alternate_row_color(&$this->t);
2912 $sql = "SELECT * FROM eq_family WHERE family=".$visit_list[$i]['family'];
2913 $this->db->query($sql,__LINE__,__FILE__);
2914 $this->db->next_record();
2916 $this->t->set_var('family',$visit_list[$i]['family']);
2917 $this->t->set_var('family_name',$this->db->f('name'));
2918 $this->t->set_var('date',$visit_list[$i]['date']);
2920 $link_data['menuaction'] = 'eq.eq.vis_update';
2921 $link_data['visit'] = $visit_list[$i]['visit'];
2922 $link_data['name'] = $this->db->f('name');
2923 $link_data['date'] = $visit_list[$i]['date'];
2924 $link_data['action'] = 'view';
2925 $this->t->set_var('view',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
2926 $this->t->set_var('lang_view','View');
2928 $link_data['menuaction'] = 'eq.eq.vis_update';
2929 $link_data['visit'] = $visit_list[$i]['visit'];
2930 $link_data['name'] = $this->db->f('name');
2931 $link_data['date'] = $visit_list[$i]['date'];
2932 $link_data['action'] = 'edit';
2933 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
2934 $this->t->set_var('lang_edit','Edit');
2936 $this->t->fp('list1','visit_list',True);
2939 // List the families that are available to record a visit against
2940 $sql = "SELECT * FROM eq_family WHERE valid=1";
2941 $this->db->query($sql,__LINE__,__FILE__);
2942 $total_records = $this->db->num_rows();
2945 while ($this->db->next_record())
2947 $family_names[$i] = $this->db->f('name');
2948 $family_ids[$i] = $this->db->f('family');
2950 } array_multisort($family_names, $family_ids);
2952 for ($i=0; $i < count($family_names); $i++)
2954 $link_data['menuaction'] = 'eq.eq.vis_update';
2955 $link_data['visit'] = '';
2956 $link_data['family'] = $family_ids[$i];
2957 $link_data['action'] = 'add';
2958 $link_data['name'] = $family_names[$i];
2959 $this->t->set_var('add',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
2961 $this->t->set_var('name',$family_names[$i]);
2962 if(($i+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
2963 else { $this->t->set_var('table_sep',"</td>"); }
2964 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
2966 $this->t->fp('list2','family_list',True);
2969 $this->t->pfp('out','vis_view_t');
2970 $this->save_sessiondata();
2973 function vis_update()
2975 $this->t->set_file(array('form' => 'vis_update.tpl'));
2976 $this->t->set_block('form','add','addhandle');
2977 $this->t->set_block('form','edit','edithandle');
2979 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
2980 $this->t->set_var('readonly','');
2981 $this->t->set_var('disabled','');
2983 $action = get_var('action',array('GET','POST'));
2984 $visit = get_var('visit',array('GET','POST'));
2985 $family = get_var('family',array('GET','POST'));
2986 $name = get_var('name',array('GET','POST'));
2987 $date = get_var('date',array('GET','POST'));
2988 $notes = get_var('notes',array('GET','POST'));
2991 if($action == 'save')
2993 $notes = get_var('notes',array('POST'));
2994 $this->db->query("UPDATE eq_visit set " .
2995 " date='" . $date . "'" .
2996 ", notes='" . $notes . "'" .
2997 " WHERE visit=" . $visit,__LINE__,__FILE__);
3002 if($action == 'insert')
3004 $notes = get_var('notes',array('POST'));
3005 $this->db->query("INSERT INTO eq_visit (family,companionship,date,notes) "
3006 . "VALUES ('" . $family . "','" . $companionship . "','"
3007 . $date . "','" . $notes . "')",__LINE__,__FILE__);
3012 if($action == 'add')
3014 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
3015 $this->t->set_var('family', $family);
3016 $this->t->set_var('visit', '');
3017 $this->t->set_var('name', $name);
3018 $this->t->set_var('date','');
3019 $this->t->set_var('notes','');
3020 $this->t->set_var('lang_done','Cancel');
3021 $this->t->set_var('lang_action','Adding New Visit');
3022 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&family='
3023 . $family . '&action=' . 'insert'));
3026 if($action == 'edit' || $action == 'view')
3028 $sql = "SELECT * FROM eq_visit WHERE visit=".$visit;
3029 $this->db->query($sql,__LINE__,__FILE__);
3030 $this->db->next_record();
3031 $this->t->set_var('visit',$visit);
3032 $this->t->set_var('name',$name);
3033 $this->t->set_var('family', $family);
3034 $this->t->set_var('date',$this->db->f('date'));
3035 $this->t->set_var('notes',$this->db->f('notes'));
3038 if($action == 'edit')
3040 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
3041 $this->t->set_var('lang_done','Cancel');
3042 $this->t->set_var('lang_action','Editing Visit');
3043 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&visit='
3044 . $visit . '&action=' . 'save'));
3047 if($action == 'view')
3049 $date = $this->db->f('date');
3050 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
3051 $this->t->set_var('readonly','READONLY');
3052 $this->t->set_var('disabled','DISABLED');
3053 $this->t->set_var('lang_done','Done');
3054 $this->t->set_var('lang_action','Viewing Visit');
3055 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&visit='
3056 . $visit . '&action=' . 'edit'));
3059 $this->t->set_var('lang_reset','Clear Form');
3060 $this->t->set_var('lang_add','Add Visit');
3061 $this->t->set_var('lang_save','Save Changes');
3062 $this->t->set_var('edithandle','');
3063 $this->t->set_var('addhandle','');
3065 $this->t->pfp('out','form');
3067 if($action == 'view') { $this->t->set_var('lang_save','Edit Visit'); }
3068 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
3069 if($action == 'add') { $this->t->pfp('addhandle','add'); }
3071 $this->save_sessiondata();
3076 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3077 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3078 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3080 $this->t->set_file(array('att_view_t' => 'att_view.tpl'));
3081 $this->t->set_block('att_view_t','act_list','list');
3083 $this->t->set_block('att_view_t','month_list','list1');
3084 $this->t->set_block('att_view_t','header_list','list2');
3085 $this->t->set_block('att_view_t','elder_list','list3');
3087 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_view'));
3088 $num_quarters = get_var('num_quarters',array('GET','POST'));
3089 if($num_quarters == '') { $num_quarters = $this->default_att_num_quarters; }
3090 $this->t->set_var('num_quarters',$num_quarters);
3091 $this->t->set_var('lang_filter','Filter');
3092 if($num_quarters == 1) { $this->t->set_var('lang_num_quarters','Quarter of History'); }
3093 else { $this->t->set_var('lang_num_quarters','Quarters of History'); }
3095 $num_months = $num_quarters * 3;
3096 $current_month = $this->current_month;
3097 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
3098 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
3099 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
3100 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
3102 $sql = "SELECT * FROM eq_elder where valid=1";
3103 $this->db->query($sql,__LINE__,__FILE__);
3105 while ($this->db->next_record())
3107 $elder_name[$i] = $this->db->f('name');
3108 $elder_id[$i] = $this->db->f('elder');
3111 array_multisort($elder_name, $elder_id);
3113 // Create a list of sunday dates for a window of 3 months back and current month
3117 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $current_month-$num_months, 1, date("y")));
3118 $last_date = explode("-",$sunday_list[0]['date']);
3119 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3120 $time_limit = mktime(0, 0, 0, date("m"), date("t"), date("y"));
3121 while($last_time < $time_limit)
3123 $day = date("w",$last_time);
3124 if(date("w",$last_time) == 0) {
3125 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3126 $last_date = explode("-",$sunday_list[$i]['date']);
3127 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3128 $sunday_list[$i]['day'] = $last_date[2];
3129 $sunday_list[$i]['month'] = date("M",$last_time);
3130 $sunday_list[$i]['year'] = $last_date[0];
3133 $last_time += 90000;
3134 if($found_sunday) { $i++; $found_sunday=0; }
3137 $total_elders = count($elder_id);
3138 $old_month=$sunday_list[0]['month']; $span=0;
3139 for ($i=0; $i < count($sunday_list); $i++) {
3140 $date = $sunday_list[$i]['date'];
3141 $this->t->set_var('date',$sunday_list[$i]['date']);
3142 $this->t->set_var('day',$sunday_list[$i]['day']);
3143 if(($old_month != $sunday_list[$i]['month']) || $i == count($sunday_list)-1) {
3144 if($i == count($sunday_list)-1) { $span++; }
3145 $cur_month = $sunday_list[$i]['month'];
3146 $old_month = $sunday_list[$i]['month'];
3147 $link_data['menuaction'] = 'eq.eq.att_update';
3148 $link_data['month'] = $sunday_list[$i-1]['month'];
3149 $link_data['year'] = $sunday_list[$i-1]['year'];
3150 $link_data['action'] = 'update_month';
3151 $cur_month = $sunday_list[$i-1]['month'];
3152 $cur_year = $sunday_list[$i-1]['year'];
3153 $header_row .= "<th><font size=-3>$cur_month $cur_year</font></th>";
3154 $this->t->set_var('update_month',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
3155 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3156 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3157 $this->t->set_var('span',$span); $span=0;
3158 $this->t->fp('list1','month_list',True);
3161 $this->t->set_var('total_elders',$total_elders);
3162 $this->t->set_var('header_row',$header_row);
3164 $elder_width=200; $att_width=25; $total_width=$elder_width;
3165 for ($i=0; $i < count($sunday_list); $i++) {
3166 $link_data['menuaction'] = 'eq.eq.att_update';
3167 $link_data['month'] = $sunday_list[$i]['month'];
3168 $link_data['year'] = $sunday_list[$i]['year'];
3169 $link_data['day'] = $sunday_list[$i]['day'];
3170 $link_data['date'] = $sunday_list[$i]['date'];
3171 $link_data['action'] = 'update_day';
3172 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
3173 $this->t->set_var('date',$sunday_list[$i]['date']);
3174 $this->t->set_var('day',$sunday_list[$i]['day']);
3175 $this->t->set_var('month',$sunday_list[$i]['month']);
3176 $this->t->set_var('year',$sunday_list[$i]['year']);
3177 $this->t->fp('list2','header_list',True);
3178 $total_width += $att_width;
3179 $attendance[$monthnum[$sunday_list[$i]['month']]]=0;
3182 for ($i=0; $i < count($elder_id); $i++) {
3184 $this->nextmatchs->template_alternate_row_color(&$this->t);
3185 $this->t->set_var('elder_name',$elder_name[$i]);
3186 #print "checking for elder: " . $elder_id[$i] . "<br>";
3187 for ($j=0; $j < count($sunday_list); $j++) {
3188 #print "checking for date: " . $sunday_list[$j]['date'] . "<br>";
3189 #print "SELECT * FROM eq_attendance WHERE date='"
3190 # . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i] . "<br>";
3191 $sql = "SELECT * FROM eq_attendance WHERE date='"
3192 . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i];
3193 $this->db->query($sql,__LINE__,__FILE__);
3194 if($this->db->next_record()) {
3195 $cur_month = $sunday_list[$j]['month'];
3196 if($attended[$i][$cur_month] != 1) {
3197 $attended[$i][$cur_month]=1;
3198 $attendance[$monthnum[$cur_month]]++;
3200 $att_table .= '<td align=center><img src="images/checkmark.gif"></td>';
3202 $att_table .= '<td> </td>';
3205 $this->t->set_var('att_table',$att_table);
3206 $this->t->fp('list3','elder_list',True);
3208 $this->t->set_var('total_width',$total_width);
3209 $this->t->set_var('elder_width',$elder_width);
3210 $this->t->set_var('att_width',$att_width);
3212 # Now calculate attendance for these months
3213 $attendance_str = "";
3214 $nonattendance_str = "";
3215 $aveattendance_str = "";
3216 $avenonattendance_str = "";
3218 $ave_total_attended=0;
3220 foreach($attendance as $att => $value) {
3221 $total_attended = $attendance[$att];
3222 $ave_total_attended += $attendance[$att]; $num_months++;
3223 $percent = ceil(($total_attended / $total_elders)*100);
3224 $attendance_str.="<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3225 $total_nonattended = $total_elders - $total_attended;
3226 $percent = ceil(($total_nonattended / $total_elders)*100);
3227 $nonattendance_str.="<td align=center><font size=-2><b>$total_nonattended ($percent%)</b></font></td>";
3229 $total_attended = ceil(($ave_total_attended / $num_months));
3230 $percent = ceil(($total_attended / $total_elders)*100);
3231 $aveattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3232 $total_attended = $total_elders - ceil(($ave_total_attended / $num_months));
3233 $percent = ceil(($total_attended / $total_elders)*100);
3234 $avenonattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3237 $this->t->set_var('attendance',$attendance_str);
3238 $this->t->set_var('aveattendance',$aveattendance_str);
3239 $this->t->set_var('nonattendance',$nonattendance_str);
3240 $this->t->set_var('avenonattendance',$avenonattendance_str);
3242 $this->t->pfp('out','att_view_t');
3243 $this->save_sessiondata();
3246 function att_update()
3248 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3249 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3250 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3252 $this->t->set_file(array('form' => 'att_update.tpl'));
3253 $this->t->set_block('form','edit','edithandle');
3255 $this->t->set_block('form','month_list','list1');
3256 $this->t->set_block('form','header_list','list2');
3257 $this->t->set_block('form','elder_list','list3');
3259 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_view'));
3261 $action = get_var('action',array('GET','POST'));
3262 $month = get_var('month',array('GET','POST'));
3263 $year = get_var('year',array('GET','POST'));
3264 $day = get_var('day',array('GET','POST'));
3265 $date = get_var('date',array('GET','POST'));
3267 if($action == 'save_month' || $action == 'save_day')
3269 $new_data = get_var('elders_attended',array('POST'));
3270 $month = $monthnum[$month]; if($month < 10) { $month = "0" . $month; }
3272 if($action == 'save_month') {
3273 $this->db->query("DELETE from eq_attendance where date LIKE '".$year."-".$month."-%'",__LINE__,__FILE__);
3276 if($action == 'save_day') {
3277 $this->db->query("DELETE from eq_attendance where date LIKE '".$year."-".$month."-".$day."'",__LINE__,__FILE__);
3280 foreach ($new_data as $data)
3282 $data_array = explode("-",$data);
3283 $elder = $data_array[0];
3284 $date = "$data_array[1]-$data_array[2]-$data_array[3]";
3285 $this->db->query("INSERT INTO eq_attendance (elder,date) "
3286 . "VALUES (" . $elder . ",'". $date . "')",__LINE__,__FILE__);
3293 $sql = "SELECT * FROM eq_elder where valid=1";
3294 $this->db->query($sql,__LINE__,__FILE__);
3296 while ($this->db->next_record())
3298 $elder_name[$i] = $this->db->f('name');
3299 $elder_id[$i] = $this->db->f('elder');
3300 $elder_attending[$elder_id[$i]] = $this->db->f('attending');
3303 array_multisort($elder_name, $elder_id);
3305 if($action == 'update_month')
3307 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_update&action=save_month'));
3311 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], 1, $year));
3312 $last_date = explode("-",$sunday_list[0]['date']);
3313 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3314 $time_limit = mktime(0, 0, 0, $monthnum[$month], 31, $year);
3315 while($last_time <= $time_limit)
3317 $day = date("w",$last_time);
3318 if(date("w",$last_time) == 0) {
3319 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3320 $last_date = explode("-",$sunday_list[$i]['date']);
3321 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3322 $sunday_list[$i]['day'] = $last_date[2];
3323 $sunday_list[$i]['month'] = date("M",$last_time);
3324 $sunday_list[$i]['year'] = $last_date[0];
3327 $last_time += 90000;
3328 if($found_sunday) { $i++; $found_sunday=0; }
3331 $this->t->set_var('span', $i);
3332 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3333 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3334 $this->t->fp('list1','month_list',True);
3335 $elder_width=200; $att_width=25; $total_width=$elder_width;
3336 for ($i=0; $i < count($sunday_list); $i++) {
3337 $link_data['menuaction'] = 'eq.eq.att_update';
3338 $link_data['month'] = $sunday_list[$i]['month'];
3339 $link_data['year'] = $sunday_list[$i]['year'];
3340 $link_data['day'] = $sunday_list[$i]['day'];
3341 $link_data['date'] = $sunday_list[$i]['date'];
3342 $link_data['action'] = 'update_day';
3343 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
3344 $this->t->set_var('date',$sunday_list[$i]['date']);
3345 $this->t->set_var('day',$sunday_list[$i]['day']);
3346 $this->t->set_var('month',$sunday_list[$i]['month']);
3347 $this->t->set_var('year',$sunday_list[$i]['year']);
3348 $this->t->fp('list2','header_list',True);
3349 $total_width += $att_width;
3353 if($action == 'update_day')
3355 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_update&action=save_day'));
3356 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], $day, $year));
3357 $this->t->set_var('month',$month);
3358 $this->t->set_var('year',$year);
3359 $this->t->fp('list1','month_list',True);
3360 $this->t->set_var('date',$date);
3361 $this->t->set_var('day',$day);
3362 $this->t->set_var('month',$month);
3363 $this->t->set_var('year',$year);
3364 $this->t->fp('list2','header_list',True);
3367 for ($i=0; $i < count($elder_id); $i++) {
3369 $this->nextmatchs->template_alternate_row_color(&$this->t);
3370 $this->t->set_var('elder_name',$elder_name[$i]);
3371 for ($j=0; $j < count($sunday_list); $j++) {
3372 $sql = "SELECT * FROM eq_attendance WHERE date='"
3373 . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i];
3374 $this->db->query($sql,__LINE__,__FILE__);
3375 $value = $elder_id[$i] . "-" . $sunday_list[$j]['date'];
3376 if($this->db->next_record()) {
3377 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'" checked></td>';
3378 } else if($elder_attending[$elder_id[$i]] == 1) {
3379 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'" checked></td>';
3381 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'"></td>';
3384 $this->t->set_var('att_table',$att_table);
3385 $this->t->fp('list3','elder_list',True);
3388 $this->t->set_var('lang_done', 'Cancel');
3389 $this->t->set_var('lang_reset','Clear Form');
3390 $this->t->set_var('lang_save','Save Changes');
3392 $this->t->pfp('out','form');
3393 $this->t->pfp('addhandle','edit');
3395 $this->save_sessiondata();
3400 $this->t->set_file(array('dir_view_t' => 'dir_view.tpl'));
3401 $this->t->set_block('dir_view_t','dir_list','list');
3403 $sql = "SELECT * FROM eq_parent where valid=1 ORDER BY name ASC";
3404 $this->db->query($sql,__LINE__,__FILE__);
3406 while ($this->db->next_record())
3408 $parent[$i]['id'] = $this->db->f('parent');
3409 $parent[$i]['name'] = $this->db->f('name');
3410 $parent[$i]['phone'] = $this->db->f('phone');
3411 $parent[$i]['address'] = $this->db->f('address');
3415 for ($i=0; $i < count($parent); $i++)
3417 $name = $parent[$i]['name'];
3418 $phone = $parent[$i]['phone'];
3419 $address = $parent[$i]['address'];
3420 $this->t->set_var('name', $name);
3421 $this->t->set_var('address', $address);
3422 $this->t->set_var('phone', $phone);
3423 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3424 $this->t->set_var('tr_color',$tr_color);
3425 $this->t->fp('list','dir_list',True);
3426 //print "$phone $name $address<br>";
3428 $this->t->pfp('out','dir_view_t');
3429 $this->save_sessiondata();
3434 $this->t->set_file(array('org_view_t' => 'org_view.tpl'));
3435 $this->t->set_block('org_view_t','calling_list','list1');
3436 $this->t->set_block('org_view_t','org_list','list2');
3438 # Display a list ordered alphabetically
3439 $sql = "SELECT * FROM eq_calling ORDER BY name ASC";
3440 $this->db->query($sql,__LINE__,__FILE__);
3442 while ($this->db->next_record())
3444 $calling[$i]['id'] = $this->db->f('indiv_id');
3445 $calling[$i]['name'] = $this->db->f('name');
3446 $calling[$i]['position'] = $this->db->f('position');
3447 $calling[$i]['sustained'] = $this->db->f('sustained');
3448 $calling[$i]['organization'] = $this->db->f('organization');
3451 for ($i=0; $i < count($calling); $i++)
3453 $name = $calling[$i]['name'];
3454 $position = $calling[$i]['position'];
3455 $sustained = $calling[$i]['sustained'];
3456 $organization = $calling[$i]['organization'];
3457 $this->t->set_var('name', $name);
3458 $this->t->set_var('position', $position);
3459 $this->t->set_var('sustained', $sustained);
3460 $this->t->set_var('organization', $organization);
3461 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3462 $this->t->set_var('tr_color',$tr_color);
3463 $this->t->fp('list1','calling_list',True);
3466 # Display a list ordered by organization
3467 $sql = "SELECT * FROM eq_calling ORDER BY sequence ASC";
3468 $this->db->query($sql,__LINE__,__FILE__);
3470 while ($this->db->next_record())
3472 $calling[$i]['id'] = $this->db->f('indiv_id');
3473 $calling[$i]['name'] = $this->db->f('name');
3474 $calling[$i]['position'] = $this->db->f('position');
3475 $calling[$i]['sustained'] = $this->db->f('sustained');
3476 $calling[$i]['organization'] = $this->db->f('organization');
3479 for ($i=0; $i < count($calling); $i++)
3481 $name = $calling[$i]['name'];
3482 $position = $calling[$i]['position'];
3483 $sustained = $calling[$i]['sustained'];
3484 $organization = $calling[$i]['organization'];
3485 $this->t->set_var('name', $name);
3486 $this->t->set_var('position', $position);
3487 $this->t->set_var('sustained', $sustained);
3488 $this->t->set_var('organization', $organization);
3489 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3490 $this->t->set_var('tr_color',$tr_color);
3491 $this->t->fp('list2','org_list',True);
3494 $this->t->pfp('out','org_view_t');
3495 $this->save_sessiondata();
3500 $this->t->set_file(array('sched_t' => 'schedule.tpl'));
3501 $this->t->set_block('sched_t','presidency_list','list');
3503 $action = get_var('action',array('GET','POST'));
3505 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.schedule&action=save'));
3506 $this->t->set_var('title','EQ Scheduling Tool');
3508 $this->t->set_var('lang_save','Save Schedule');
3509 $this->t->set_var('lang_reset','Cancel');
3511 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched'));
3512 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
3514 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_sched'));
3515 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
3517 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched'));
3518 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
3520 $date_width=150; $time_width=200; $elder_width=200; $family_width=200;
3521 $table_width=$date_width + $time_width + $elder_width + $family_width;
3522 $header_row = "<th width=$date_width><font size=-2>Date</th>";
3523 $header_row.= "<th width=$time_width><font size=-2>Time</th>";
3524 $header_row.= "<th width=$elder_width><font size=-2>Elder</th>";
3525 $header_row.= "<th width=$family_width><font size=-2>Family</th>";
3528 if($action == 'save')
3530 $new_data = get_var('sched',array('POST'));
3531 foreach ($new_data as $presidency_array)
3533 foreach ($presidency_array as $entry)
3535 $presidency = $entry['presidency'];
3536 $appointment = $entry['appointment'];
3537 $date = $entry['date'];
3538 $hour = $entry['hour'];
3539 $minute = $entry['minute'];
3541 $elder = $entry['elder'];
3542 $family = $entry['family'];
3543 if($pm) { $hour = $hour + 12; }
3544 $time = $hour.':'.$minute.':'.'00';
3547 // Zero out the family or elder if date = NULL
3553 // Update an existing appointment
3554 if($appointment < $this->max_appointments)
3556 //Only perform a database update if we have made a change to this appointment
3557 $sql = "SELECT * FROM eq_appointment where " .
3558 "appointment='$appointment'" .
3559 " and presidency='$presidency'" .
3560 " and elder='$elder'" .
3561 " and family='$family'" .
3562 " and date='$date'" .
3563 " and time='$time'";
3564 $this->db->query($sql,__LINE__,__FILE__);
3565 if(!$this->db->next_record()) {
3566 $old_date = $this->db->f('date');
3567 $old_time = $this->db->f('time');
3568 $this->db2->query("UPDATE eq_appointment set" .
3569 " family=" . $family .
3570 " ,elder=" . $elder .
3571 " ,date='" . $date . "'" .
3572 " ,time='" . $time . "'" .
3573 " ,presidency='" . $presidency . "'" .
3574 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
3576 // Email the appointment
3577 $this->email_appt($appointment);
3581 // Add a new appointment
3582 else if(($appointment >= $this->max_appointments) && ($date != "") && ($time != ""))
3584 //print "adding entry: appt=$appointment date: $date time: $time elder: $elder family: $family<br>";
3585 $this->db2->query("INSERT INTO eq_appointment (appointment,presidency,family,elder,date,time,uid) "
3586 . "VALUES (NULL,'" . $presidency . "','" . $family . "','"
3587 . $elder . "','" . $date . "','" . $time . "','" . $uid ."')",__LINE__,__FILE__);
3589 // Now reselect this entry from the database to see if we need
3590 // to send an appointment out for it.
3591 $sql = "SELECT * FROM eq_appointment where " .
3593 " and family='$family'" .
3594 " and presidency='$presidency'" .
3595 " and date='$date'" .
3596 " and time='$time'" .
3598 $this->db3->query($sql,__LINE__,__FILE__);
3599 if($this->db3->next_record()) {
3600 // Email the appointment if warranted
3601 if(($date != "") && ($time != "") && (($elder > 0) || $family > 0)) {
3602 $this->email_appt($this->db3->f('appointment'));
3609 $take_me_to_url = $GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.schedule');
3610 Header('Location: ' . $take_me_to_url);
3613 $sql = "SELECT * FROM eq_presidency where valid=1";
3614 $this->db->query($sql,__LINE__,__FILE__);
3616 while ($this->db->next_record())
3618 $presidency_data[$i]['id'] = $this->db->f('presidency');
3619 $presidency_data[$i]['name'] = $this->db->f('name');
3620 $presidency_data[$i]['elder'] = $this->db->f('elder');
3624 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
3625 $this->db->query($sql,__LINE__,__FILE__);
3627 while ($this->db->next_record())
3629 $elder_id[$i] = $this->db->f('elder');
3630 $elder_name[$i] = $this->db->f('name');
3631 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
3634 array_multisort($elder_name, $elder_id);
3636 $sql = "SELECT * FROM eq_family where valid=1 and elder_id != 0 ORDER BY name ASC";
3637 $this->db->query($sql,__LINE__,__FILE__);
3639 while ($this->db->next_record())
3641 $family_id[$i] = $this->db->f('family');
3642 $family_name[$i] = $this->db->f('name');
3645 array_multisort($family_name, $family_id);
3647 for ($i=0; $i < count($presidency_data); $i++) {
3648 $presidency = $presidency_data[$i]['id'];
3649 $interviewer = $presidency_data[$i]['elder'];
3650 $name = $presidency_data[$i]['name'];
3651 $this->t->set_var('presidency_name',$name);
3654 // query the database for all the appointments
3655 $sql = "SELECT * FROM eq_appointment where presidency=$presidency and date>=CURDATE() ORDER BY date ASC, time ASC";
3656 $this->db->query($sql,__LINE__,__FILE__);
3658 // Prefill any existing appointment slots
3659 while ($this->db->next_record())
3661 $appointment = $this->db->f('appointment');
3662 $elder = $this->db->f('elder');
3663 $family = $this->db->f('family');
3665 $date = $this->db->f('date');
3666 $date_array = explode("-",$date);
3667 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
3668 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
3670 $time = $this->db->f('time');
3671 $time_array = explode(":",$time);
3672 $hour = $time_array[0];
3673 $minute = $time_array[1];
3675 if($hour > 12) { $pm=1; $hour = $hour - 12; }
3676 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
3678 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3681 $table_data.= '<td align=left>';
3682 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]',$date,'','','','','',$this->cal_options);
3683 $table_data.= '</td>';
3685 // Hour & Minutes selection
3686 $table_data.= "<td align=center>";
3687 $table_data.= '<select name=sched['.$presidency.']['.$appointment.'][hour]>';
3688 foreach(range(1,12) as $num) {
3689 if($hour == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
3690 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
3692 $table_data.= '</select>';
3693 $table_data.= ' : ';
3694 $table_data.= '<select name=sched['.$presidency.']['.$appointment.'][minute]>';
3695 foreach(range(0,3) as $num) {
3696 $num = $num * 15; if($num == 0) { $num = "00"; }
3697 if($minute == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
3698 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
3700 $table_data.= '</select>';
3701 $table_data.= '<select name=sched['.$presidency.']['.$appointment.'][pm]>';
3702 if($pm == 0) { $table_data.= '<option value=0 selected>am</option>'; $table_data.= '<option value=1>pm</option>'; }
3703 else { $table_data.= '<option value=0>am</option>'; $table_data.= '<option value=1 selected>pm</option>'; }
3704 $table_data.= '</select>';
3705 $table_data.= "</td>";
3707 // Elder drop down list (for PPIs)
3708 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][elder]>';
3709 $table_data.= '<option value=0></option>';
3710 for ($j=0; $j < count($elder_id); $j++) {
3711 $id = $elder_id[$j];
3712 $name = $elder_name[$j];
3713 if($elder_id[$j] == $elder) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
3714 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
3716 $table_data.='</select></td>';
3718 // Family drop down list (for Visits)
3719 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family]>';
3720 $table_data.= '<option value=0></option>';
3721 for ($j=0; $j < count($elder_id); $j++) {
3722 $id = $family_id[$j];
3723 $name = $family_name[$j];
3724 if($family_id[$j] == $family) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
3725 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
3727 $table_data.='</select></td>';
3729 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3730 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3732 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3733 $this->t->set_var('tr_color',$tr_color);
3737 // Create blank appointment slot
3738 for ($b=0; $b < 4; $b++) {
3739 $appointment = $this->max_appointments + $b;
3740 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3743 $table_data.= '<td align=left>';
3744 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]','','','','','','',$this->cal_options);
3745 $table_data.= '</td>';
3748 $table_data.= "<td align=center>";
3749 $table_data.= '<select name=sched['.$presidency.']['.$appointment.'][hour]>';
3750 $table_data.= '<option value=""></option>';
3751 foreach(range(1,12) as $num) {
3752 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
3754 $table_data.= '</select>';
3755 $table_data.= ' : ';
3756 $table_data.= '<select name=sched['.$presidency.']['.$appointment.'][minute]>';
3757 $table_data.= '<option value=""></option>';
3758 foreach(range(0,3) as $num) {
3759 $num = $num * 15; if($num == 0) { $num = "00"; }
3760 $table_data.= '<option value='.$num.'>'.$num.'</option>';
3762 $table_data.= '</select>';
3763 $table_data.= '<select name=sched['.$presidency.']['.$appointment.'][pm]>';
3764 $table_data.= '<option value=""></option>';
3765 $table_data.= '<option value=0>am</option>';
3766 $table_data.= '<option value=1>pm</option>';
3767 $table_data.= '</select>';
3768 $table_data.= "</td>";
3770 // Elder drop down list
3771 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][elder]>';
3772 $table_data.= '<option value=0></option>';
3773 for ($j=0; $j < count($elder_id); $j++) {
3774 $id = $elder_id[$j];
3775 $name = $elder_name[$j];
3776 $table_data.= '<option value='.$id.'>'.$name.'</option>';
3778 $table_data.='</select></td>';
3780 // Family drop down list
3781 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family]>';
3782 $table_data.= '<option value=0></option>';
3783 for ($j=0; $j < count($elder_id); $j++) {
3784 $id = $family_id[$j];
3785 $name = $family_name[$j];
3786 $table_data.= '<option value='.$id.'>'.$name.' Family</option>';
3788 $table_data.='</select></td>';
3790 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3791 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3793 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3794 $this->t->set_var('tr_color',$tr_color);
3797 $this->t->set_var('table_data',$table_data);
3798 $this->t->set_var('header_row',$header_row);
3799 $this->t->set_var('table_width',$table_width);
3800 $this->t->fp('list','presidency_list',True);
3804 $this->t->pfp('out','sched_t');
3805 $this->save_sessiondata();
3810 $this->t->set_file(array('admin_t' => 'admin.tpl'));
3811 $this->t->set_block('admin_t','upload','uploadhandle');
3812 $this->t->set_block('admin_t','admin','adminhandle');
3813 $this->t->set_block('admin_t','cmd','cmdhandle');
3814 $this->t->set_block('admin_t','presidency','presidencyhandle');
3816 $this->t->set_var('upload_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.admin&action=upload'));
3817 $this->t->set_var('presidency_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.admin&action=presidency'));
3819 $action = get_var('action',array('GET','POST'));
3821 $this->t->pfp('out','admin_t');
3823 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
3824 $this->db->query($sql,__LINE__,__FILE__);
3826 while ($this->db->next_record())
3828 $elder_id[$i] = $this->db->f('elder');
3829 $elder_name[$i] = $this->db->f('name');
3830 $elder2name[$elder_id[$i]] = $elder_name[$i];
3833 array_multisort($elder_name, $elder_id);
3835 if($action == 'upload')
3837 $target_path = $this->upload_target_path . '/' . basename( $_FILES['uploadedfile']['name']);
3839 if(($_FILES['uploadedfile']['type'] == "application/zip") ||
3840 ($_FILES['uploadedfile']['type'] == "application/x-zip-compressed") ||
3841 ($_FILES['uploadedfile']['type'] == "application/x-zip") ||
3842 ($_FILES['uploadedfile']['type'] == "application/octet-stream")) {
3844 if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
3845 $uploadstatus = "<b><font color=red> -E- Unable to move the uploaded file to ";
3846 $uploadstatus.= "the target path (check the path and permissions) of: $target_path</font></b>";
3847 $this->t->set_var('uploadstatus',$uploadstatus);
3848 $this->t->pfp('uploadhandle','upload',True);
3852 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
3853 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
3854 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
3855 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
3856 $this->t->set_var('uploadstatus',$uploadstatus);
3857 $this->t->pfp('uploadhandle','upload');
3858 $this->t->set_var('uploadhandle','');
3859 print "<table border=1 width=80%><tr><td>\n<pre>";
3861 # make a directory for this data to be stored in
3862 $date="data_" . date("Y_m_d");
3863 $data_dir = $this->upload_target_path . '/' . $date;
3864 print "-> Making the data directory: $date<br>\n";
3865 exec('mkdir -p ' . $data_dir . ' 2>&1', $result, $return_code);
3866 if($return_code != 0) {
3867 print implode('\n',$result) . "<br>";
3868 print "<b><font color=red>";
3869 print "-E- Unable to create the data directory. Aborting import.";
3870 print "</font></b>";
3874 # move the file uploaded into this directory
3875 print "-> Moving the uploaded file into the data dir<br>\n";
3876 exec('mv ' . $target_path . ' ' . $data_dir . '/' . ' 2>&1', $result, $return_code);
3877 if($return_code != 0) {
3878 print implode('\n',$result) . "<br>";
3879 print "<b><font color=red>";
3880 print "-E- Unable to move the uploaded file into the data dir. Aborting import.";
3881 print "</font></b>";
3885 # unzip the data into this directory
3886 print "-> Unzipping the data<br>\n";
3887 $data_file = $data_dir . '';
3888 exec('unzip ' . $data_dir . '/*.zip -d ' . $data_dir . ' 2>&1', $result, $return_code);
3889 if($return_code != 0) {
3890 print implode('\n',$result) . "<br>";
3891 print "<b><font color=red>";
3892 print "-E- Unable to unzip the uploaded file into the data dir. Aborting import.";
3893 print "</font></b>";
3896 exec('mv ' . $data_dir . '/*/* '. $data_dir . ' 2>&1', $result, $return_code);
3898 # update the data_latest link to point to this new directory
3899 print "-> Updating the latest data dir link<br>\n";
3900 $data_latest = $this->upload_target_path . '/data_latest';
3901 exec('rm ' . $data_latest. '; ln -s ' . $data_dir .' '. $data_latest .' 2>&1', $result, $return_code);
3902 if($return_code != 0) {
3903 print implode('\n',$result) . "<br>";
3904 print "<b><font color=red>";
3905 print "-E- Unable to update the data latest link. Aborting import.";
3906 print "</font></b>";
3910 # run the import perl script to encorporate it into the DB
3911 ob_start('ob_logstdout', 2);
3912 print "-> Importing the data into the EQ database<br>\n";
3913 ob_flush(); flush(); sleep(1);
3914 $import_log = $this->upload_target_path . '/import.log';
3915 $data_log = $this->upload_target_path . '/data.log';
3916 $import_cmd = $this->script_path . '/import_ward_data ' . $data_latest . ' 2>&1 | tee ' . $import_log;
3917 $parse_cmd = $this->script_path . '/parse_ward_data -v ' . $data_latest . ' > ' . $data_log . '2>&1';
3918 #print "import_cmd: $import_cmd<br>";
3919 #print "parse_cmd: $parse_cmd<br>";
3920 ob_start('ob_logstdout', 2);
3921 passthru($import_cmd);
3922 passthru($parse_cmd);
3923 ob_flush(); flush(); sleep(1);
3925 # fix the permissions of the data dir
3926 exec('chmod -R o-rwx ' . $data_dir, $result, $return_code);
3928 $this->t->pfp('cmdhandle','cmd');
3929 print "</pre></td></tr></table>";
3931 } else if(($_FILES['uploadedfile']['type'] != "application/zip") &&
3932 ($_FILES['uploadedfile']['type'] != "application/x-zip-compressed") &&
3933 ($_FILES['uploadedfile']['type'] != "application/x-zip") &&
3934 ($_FILES['uploadedfile']['type'] != "application/octet-stream")) {
3935 $uploadstatus = "<b><font color=red>The file format must be a .zip file, please try again! </font></b>";
3936 $uploadstatus.= "<br><br><b>Detected file format: " . $_FILES['uploadedfile']['type'] . "</b>";
3937 $this->t->set_var('uploadstatus',$uploadstatus);
3938 $this->t->pfp('uploadhandle','upload',True);
3940 $uploadstatus = "<b><font color=red> There was an error (" . $_FILES['uploadedfile']['error'];
3941 $uploadstatus.= ") uploading the file, please try again! </font></b>";
3942 $this->t->set_var('uploadstatus',$uploadstatus);
3943 $this->t->pfp('uploadhandle','upload',True);
3946 else if($action == "presidency")
3948 $new_data = get_var('eqpres',array('POST'));
3949 foreach ($new_data as $entry)
3952 $email = $entry['email'];
3953 $elder = $entry['elder'];
3954 $name = $entry['name'];
3955 $district = $entry['district'];
3956 $president = $entry['president'];
3957 $counselor = $entry['counselor'];
3958 $secretary = $entry['secretary'];
3959 $eqpresidency = $entry['eqpresidency'];
3960 // Set the elder id to 0 for EQ Presidency tagged entry
3961 if($eqpresidency == 1) { $elder="0"; }
3962 // Re-look up the elder name for the ID if we aren't an EQ Presidency tagged entry
3963 else { $name = $elder2name[$elder]; }
3964 //print "id=$id elder=$elder name=$name email=$email district=$district president=$president ";
3965 //print "counselor=$counselor secretary=$secretary eqpres=$eqpresidency<br>";
3967 if(($elder > 0) || ($name != "")) {
3968 if($id < $this->max_presidency_members) {
3969 //print "Updating Existing Entry<br>";
3970 $this->db2->query("UPDATE eq_presidency set" .
3971 " elder=" . $elder .
3972 " ,district=" . $district .
3973 " ,name='" . $name . "'" .
3974 " ,email='" . $email . "'" .
3975 " ,president='" . $president . "'" .
3976 " ,counselor='" . $counselor . "'" .
3977 " ,secretary='" . $secretary . "'" .
3978 " ,eqpres='" . $eqpresidency . "'" .
3979 " WHERE presidency=" . $id,__LINE__,__FILE__);
3982 //print "Adding New Entry<br>";
3983 $this->db2->query("INSERT INTO eq_presidency (presidency,elder,district,name,"
3984 . "email,president,counselor,secretary,eqpres,valid) "
3985 . "VALUES (NULL,'" . $elder . "','" . $district . "','"
3986 . $name . "','" . $email . "','" . $president . "','"
3987 . $counselor . "','" . $secretary . "','" . $eqpres . "','1'"
3988 .")",__LINE__,__FILE__);
3991 //print "Ignoring Blank Entry<br>";
3995 // Now update the eq_district table appropriately
3997 // Delete all the previous district entries from the table
3998 $this->db->query("DELETE from eq_district where valid=1",__LINE__,__FILE__);
3999 $this->db->query("DELETE from eq_district where valid=0",__LINE__,__FILE__);
4001 // Always add a "District 0" assigned to the High Priests Group
4003 $name = "High Priests";
4006 $this->db2->query("INSERT INTO eq_district (district,name,supervisor,valid) "
4007 . "VALUES ('" . $district . "','" . $name . "','"
4008 . $elder . "','" . $valid . "'"
4009 .")",__LINE__,__FILE__);
4012 // Requery the eq_presidency table
4013 $sql = "SELECT * FROM eq_presidency where valid=1";
4014 $this->db->query($sql,__LINE__,__FILE__);
4015 while ($this->db->next_record())
4017 // Extract the data for each presidency record
4018 $id = $this->db->f('presidency');
4019 $elder = $this->db->f('elder');
4020 $name = $this->db->f('name');
4021 $district = $this->db->f('district');
4022 $name = $this->db->f('name');
4025 // If we have a valid district, add it to the district table
4027 $this->db2->query("INSERT INTO eq_district (district,name,supervisor,valid) "
4028 . "VALUES ('" . $district . "','" . $name . "','"
4029 . $elder . "','" . $valid . "'"
4030 .")",__LINE__,__FILE__);
4035 $this->t->set_var('adminhandle','');
4036 $this->t->pfp('adminhandle','admin');
4040 $this->t->set_var('adminhandle','');
4041 $this->t->pfp('adminhandle','admin');
4044 // Now save off the data needed for an EQ Presidency Table Update
4046 $sql = "SELECT * FROM eq_presidency where valid=1";
4047 $this->db->query($sql,__LINE__,__FILE__);
4049 $header_row = "<th>Elder</th><th>Email</th><th>District</th><th>President</th><th>Counselor</th><th>Secretary</th><th>EQ Presidency</th>";
4050 while ($this->db->next_record())
4052 // Extract the data for each presidency record
4053 $id = $this->db->f('presidency');
4054 $elder = $this->db->f('elder');
4055 $district = $this->db->f('district');
4056 $name = $this->db->f('name');
4057 $email = $this->db->f('email');
4058 $president = $this->db->f('president');
4059 $counselor = $this->db->f('counselor');
4060 $secretary = $this->db->f('secretary');
4061 $eqpresidency = $this->db->f('eqpres');
4063 // Create the forms needed in the table
4064 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4067 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4070 if($eqpresidency == 0) {
4071 $table_data.= '<td align=center><select name="eqpres['.$id.'][elder]">';
4072 $table_data.= '<option value=0></option>';
4073 for ($j=0; $j < count($elder_id); $j++) {
4074 $tmp_id = $elder_id[$j];
4075 $name = $elder_name[$j];
4076 if($elder_id[$j] == $elder) { $eldername = $name; $selected = 'selected="selected"'; } else { $selected = ''; }
4077 $table_data.= '<option value='.$tmp_id.' '.$selected.'>'.$name.'</option>';
4079 $table_data.='</select></td>';
4080 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="'.$eldername.'">';
4082 $table_data.= '<td align=left><input type=text size="20" name="eqpresname" value="EQ Presidency"></td>';
4083 $table_data.= '<input type=hidden name="eqpres['.$id.'][name]" value="EQ Presidency">';
4087 $table_data .= '<td><input type="text" size="50" name="eqpres['.$id.'][email]" value="'.$email.'"></td>';
4090 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4091 $table_data.= '<option value=0></option>';
4092 for ($j=0; $j <= $this->max_num_districts; $j++) {
4093 if($district == $j) { $selected = 'selected="selected"'; } else { $selected = ''; }
4094 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4096 $table_data.='</select></td>';
4099 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4100 if($president == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4101 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4102 $table_data.='</select></td>';
4105 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4106 if($counselor == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4107 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4108 $table_data.='</select></td>';
4111 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4112 if($secretary == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4113 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4114 $table_data.='</select></td>';
4117 $table_data.= '<td align=center><select name="eqpres['.$id.'][eqpresidency]">';
4118 if($eqpresidency == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4119 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4120 $table_data.='</select></td>';
4123 $table_data .= "</tr>\n";
4124 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4125 $this->t->set_var('tr_color',$tr_color);
4128 // Now create 1 blank row to always have a line available to add a new elder with
4129 $id = $this->max_presidency_members;
4130 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4132 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4134 $table_data.= '<td align=center><select name="eqpres['.$id.'][elder]">';
4135 $table_data.= '<option value=0></option>';
4136 for ($j=0; $j < count($elder_id); $j++) {
4137 $tmp_id = $elder_id[$j];
4138 $name = $elder_name[$j];
4139 $table_data.= '<option value='.$tmp_id.'>'.$name.'</option>';
4141 $table_data.='</select></td>';
4142 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="">';
4144 $table_data.='<td><input type="text" size="50" name="eqpres['.$id.'][email]" value=""></td>';
4146 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4147 $table_data.= '<option value=0></option>';
4148 for ($j=0; $j <= $this->max_num_districts; $j++) {
4149 if($j == 0) { $selected = 'selected="selected"'; } else { $selected = ''; }
4150 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4152 $table_data.='</select></td>';
4154 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4155 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4156 $table_data.='</select></td>';
4158 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4159 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4160 $table_data.='</select></td>';
4162 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4163 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4164 $table_data.='</select></td>';
4166 $table_data.= '<td align=center><select name="eqpres['.$id.'][eqpresidency]">';
4167 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4168 $table_data.='</select></td>';
4170 $table_data .= "</tr>\n";
4171 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4172 $this->t->set_var('tr_color',$tr_color);
4174 $this->t->set_var('header_row',$header_row);
4175 $this->t->set_var('table_data',$table_data);
4176 $this->t->pfp('presidencyhandle','presidency',True);
4178 $this->save_sessiondata();
4181 function email_appt($appointment)
4183 //print "Emailing notification of appointment: $appointment <br>";
4185 $sql = "SELECT * FROM eq_appointment where appointment='$appointment'";
4186 $this->db->query($sql,__LINE__,__FILE__);
4188 while ($this->db->next_record())
4190 $appointment = $this->db->f('appointment');
4191 $presidency = $this->db->f('presidency');
4194 $elder = $this->db->f('elder');
4196 $family = $this->db->f('family');
4201 $uid = $this->db->f('uid');
4203 // Extract the year, month, day, hours, minutes, seconds from the appointment time
4204 $appt_date = $this->db->f('date');
4205 $date_array = explode("-",$appt_date);
4206 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
4207 $appt_time = $this->db->f('time');
4208 $time_array = explode(":",$appt_time);
4209 $hour = $time_array[0]; $minute = $time_array[1]; $seconds = $time_array[2];
4211 // Format the appointment time into an iCal UTC equivalent
4212 $dtstamp = gmdate("Ymd"."\T"."His"."\Z");
4213 $dtstart = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds,$month,$day,$year));
4215 // Set the email address of the person making the appointment
4216 $from = $GLOBALS['phpgw_info']['user']['fullname'] . "<" .
4217 $GLOBALS['phpgw_info']['user']['preferences']['email']['address'] . ">";
4219 $sql = "SELECT * FROM eq_presidency where presidency='$presidency'";
4220 $this->db2->query($sql,__LINE__,__FILE__);
4221 if($this->db2->next_record()) {
4222 $email = $this->db2->f('email');
4223 $interviewer = $this->db2->f('name');
4227 $sql = "SELECT * FROM eq_elder where elder='$elder'";
4228 $this->db2->query($sql,__LINE__,__FILE__);
4229 if($this->db2->next_record()) {
4230 $elder_name = $this->db2->f('name');
4231 $phone = $this->db2->f('phone');
4232 $appt_name = $elder_name . " Interview";
4233 $location = "$interviewer"."'s home";
4234 $duration = 1800; // 30 minutes
4239 $sql = "SELECT * FROM eq_family where family='$family'";
4240 $this->db2->query($sql,__LINE__,__FILE__);
4241 if($this->db2->next_record()) {
4242 $family_name = $this->db2->f('name');
4243 $phone = $this->db2->f('phone');
4244 $elder_id = $this->db2->f('elder_id');
4245 $appt_name = $family_name . " Family Visit";
4246 $sql = "SELECT * FROM eq_elder where elder='$elder_id'";
4247 $this->db3->query($sql,__LINE__,__FILE__);
4248 if($this->db3->next_record()) {
4249 $phone = $this->db3->f('phone');
4251 $sql = "SELECT * FROM eq_parent where family='$family'";
4252 $this->db3->query($sql,__LINE__,__FILE__);
4253 if($this->db3->next_record()) {
4254 $location=$this->db3->f('address');
4256 $duration = 2700; // 45 minutes
4260 $dtend = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4261 $description = "$appt_name : $phone";
4263 if(($uid == 0) && ($appt_name != "")) {
4264 // Create a new calendar item for this appointment, since this must be the first time we
4265 // are sending it out.
4266 print "Sent new appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4267 $uid = rand() . rand(); // Generate a random identifier for this appointment
4268 $subject = "Created: $appt_name";
4270 $this->db->query("UPDATE eq_appointment set" .
4272 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4274 $action = "PUBLISH";
4275 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4276 $dtend, $location, $appt_name, $description, $uid);
4278 } else if(($uid != 0) && ($appt_name == "")) {
4279 // Remove the calendar item for this appointment since it has already been sent
4280 // and there is no name we have changed it to.
4281 print "Sent deleted appointment to " . $interviewer . " at " . $email . " for " . $appt_date . " " . $appt_time . "<br>";
4282 $subject = "Canceled: $appt_date $appt_time";
4284 $this->db->query("UPDATE eq_appointment set" .
4286 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4289 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4290 $dtend, $location, $appt_name, $description, $uid);
4292 } else if($uid != 0) {
4293 // Update the existing appointment since we have changed it
4294 print "Sent updated appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4296 $subject = "Canceled: $appt_date $appt_time";
4298 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4299 $dtend, $location, $appt_name, $description, $uid);
4301 $uid = rand() . rand(); // Generate a random identifier for this appointment
4302 $this->db->query("UPDATE eq_appointment set" .
4304 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4306 $subject = "Updated: $appt_name";
4307 $action = "PUBLISH";
4308 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4309 $dtend, $location, $appt_name, $description, $uid);
4317 function send_ical_appt($action, $to, $from, $subject, $dtstamp, $dtstart, $dtend, $location, $summary, $description, $uid)
4319 $headers = 'From: ' . "$from" . "\n" .
4320 'Reply-To: ' . "$from" . "\n" .
4321 'X-Mailer: PHP/' . phpversion() . "\n" .
4322 'Content-Type: text/calendar;' . "\n" .
4323 'Content-Transfer-Encoding: 7bit' . "\n";
4325 //$message = "phone: $phone date: $date time: $time";
4327 $message.="BEGIN:VCALENDAR" . "\n";
4328 $message.="VERSION:2.0" . "\n";
4329 $message.="PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN" . "\n";
4330 $message.="METHOD:$action" . "\n";
4331 $message.="BEGIN:VEVENT" . "\n";
4332 $message.="ORGANIZER:MAILTO:$from". "\n";
4333 $message.="DTSTAMP:$dtstamp" . "\n";
4334 $message.="DTSTART:$dtstart" . "\n";
4335 $message.="DTEND:$dtend" . "\n";
4336 $message.="SUMMARY:$summary" . "\n";
4337 $message.="DESCRIPTION:$description" . "\n";
4338 $message.="LOCATION:$location" . "\n";
4339 $message.="UID:$uid" ."\n";
4340 $message.="TRANSP:OPAQUE" . "\n";
4341 $message.="SEQUENCE:0" . "\n";
4342 $message.="CLASS:PUBLIC" . "\n";
4343 $message.="END:VEVENT" . "\n";
4344 $message.="END:VCALENDAR" . "\n";
4346 mail($to, $subject, $message, $headers);