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 2001/05/20 07:40:32 seek3r Exp $ */
22 var $default_ht_num_months;
23 var $default_ppi_num_months;
24 var $default_ppi_num_years;
25 var $default_att_num_months;
27 var $public_functions = array
45 $this->default_ht_num_months = 1;
46 $this->default_ppi_num_months = 1;
47 $this->default_ppi_num_years = 0;
48 $this->default_att_num_months = 1;
50 $this->db = $GLOBALS['phpgw']->db;
51 $this->db2 = $this->db;
52 $this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
53 $this->t = $GLOBALS['phpgw']->template;
54 $this->account = $GLOBALS['phpgw_info']['user']['account_id'];
55 $this->grants = $GLOBALS['phpgw']->acl->get_grants('eq');
56 $this->grants[$this->account] = PHPGW_ACL_READ + PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE;
58 $this->jscal = CreateObject('phpgwapi.jscalendar'); // before phpgw_header() !!!
59 $this->cal_options = 'daFormat : "%Y-%m-%d",
60 ifFormat : "%Y-%m-%d",
64 $GLOBALS['phpgw_info']['flags']['app_header'] = 'Elders Quorum Tools';
65 $GLOBALS['phpgw']->common->phpgw_header();
67 $this->display_app_header();
70 function save_sessiondata()
75 function display_app_header()
77 $this->t->set_file(array('eq_header' => 'header.tpl'));
79 if (isset($phpgw_info['user']['preferences']['eq']['eq_font']))
81 $font = $phpgw_info['user']['preferences']['eq']['eq_font'];
88 $this->t->set_var('bg_color',$phpgw_info['theme']['th_bg']);
89 $this->t->set_var('font',$font);
90 $link_data['menuaction'] = 'eq.eq.ht_view';
91 $this->t->set_var('link_hometeaching',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
92 $this->t->set_var('lang_hometeaching','HomeTeaching');
93 $link_data['menuaction'] = 'eq.eq.act_list';
94 $this->t->set_var('link_activity',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
95 $this->t->set_var('lang_activity','Activities');
96 $link_data['menuaction'] = 'eq.eq.par_view';
97 $this->t->set_var('link_participation',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
98 $this->t->set_var('lang_participation','Participation');
99 $link_data['menuaction'] = 'eq.eq.ppi_view';
100 $this->t->set_var('link_ppi',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
101 $this->t->set_var('lang_ppi','PPIs');
102 $link_data['menuaction'] = 'eq.eq.vis_view';
103 $this->t->set_var('link_visit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
104 $this->t->set_var('lang_visit','Visits');
105 $link_data['menuaction'] = 'eq.eq.att_view';
106 $this->t->set_var('link_attendance',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
107 $this->t->set_var('lang_attendance','Attendance');
109 $this->t->pparse('out','eq_header');
114 $this->t->set_file(array('ht_view_t' => 'ht_view.tpl'));
115 $this->t->set_block('ht_view_t','district_list','list');
117 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
118 $num_months = get_var('num_months',array('GET','POST'));
119 if($num_months == '') { $num_months = $this->default_ht_num_months; }
120 $this->t->set_var('num_months',$num_months);
121 $this->t->set_var('lang_filter','Filter');
122 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
123 else { $this->t->set_var('lang_num_months','Months of History'); }
125 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
126 $this->t->set_var('title','Hometeaching');
128 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
129 $this->db->query($sql,__LINE__,__FILE__);
131 while ($this->db->next_record())
133 $districts[$i]['district'] = $this->db->f('district');
134 $districts[$i]['name'] = $this->db->f('name');
135 $districts[$i]['supervisor'] = $this->db->f('supervisor');
139 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
140 $this->db->query($sql,__LINE__,__FILE__);
142 while ($this->db->next_record())
144 $elder_id[$i] = $this->db->f('elder');
145 $elder_name[$i] = $this->db->f('name');
148 array_multisort($elder_name, $elder_id);
150 // Make an array mapping elder_ids to elder_names
151 for($i=0; $i < count($elder_id); $i++) {
153 $elders[$id] = $elder_name[$i];
156 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
157 $this->db->query($sql,__LINE__,__FILE__);
158 while ($this->db->next_record())
160 $aaronic_id = $this->db->f('aaronic');
161 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
165 $this->nextmatchs->template_alternate_row_color(&$this->t);
166 for ($i=0; $i < count($districts); $i++) {
167 $this->t->set_var('district_number',$districts[$i]['district']);
168 $this->t->set_var('district_name',$districts[$i]['name']);
169 $supervisor = $districts[$i]['supervisor'];
170 $unique_companionships='';
172 // Select all the unique companionship numbers for this district
173 $sql = "SELECT distinct companionship FROM eq_companionship where district=". $districts[$i]['district'];
174 $this->db->query($sql,__LINE__,__FILE__);
176 while ($this->db->next_record())
178 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
182 $comp_width=450; $visit_width=25; $table_width=$comp_width + $num_months*$visit_width;
183 $table_data=""; $num_companionships = 0; $num_families = 0;
184 for($m=$num_months; $m >= 0; $m--) { $visits[$m] = 0; }
185 for ($j=0; $j < count($unique_companionships); $j++) {
186 $companion_table_entry = "";
187 // Select all the companions in each companionship
188 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
189 "companionship=". $unique_companionships[$j]['companionship'];
190 $this->db->query($sql,__LINE__,__FILE__);
192 while ($this->db->next_record())
194 // Get this companions information
195 if($companion_table_entry != "") { $companion_table_entry .= " / "; }
196 $companionship = $this->db->f('companionship');
197 $elder_id = $this->db->f('elder');
198 $aaronic_id = $this->db->f('aaronic');
199 if($elder_id) { $name = $elders[$elder_id]; }
200 else if($aaronic_id) { $name = $aaronic[$aaronic_id]['name']; }
201 $companion_table_entry .= "$name";
203 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><b>$companion_table_entry<hr></td></tr>";
205 // Get the names of the families assigned this home teaching companionship
206 $sql = "SELECT * from eq_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
207 $this->db->query($sql,__LINE__,__FILE__);
209 while ($this->db->next_record())
211 $num_families++; $total_families++;
212 $family_name = $this->db->f('name');
213 $family_id = $this->db->f('family');
214 $this->nextmatchs->template_alternate_row_color(&$this->t);
215 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
216 // Find out how many times Visits were performed by this companionship
217 // in the past $num_months for this Family
218 $header_row="<th width=$comp_width><font size=-2>Families</th>";
219 for($m=$num_months; $m >= 0; $m--) {
220 $month = date('m/Y', strtotime('-'.$m.' month'));
221 $month_start = date('Y-m', strtotime('-'.$m.' month')); $month_start .= "-01";
222 $month_end = date('Y-m', strtotime('-'.$m.' month')); $month_end .= "-31";
223 $sql = "SELECT * FROM eq_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
224 " AND companionship=" . $unique_companionships[$j]['companionship'].
225 " AND family=". $family_id;
226 $this->db2->query($sql,__LINE__,__FILE__);
227 $link_data['menuaction'] = 'eq.eq.ht_update';
228 $link_data['date'] = $month_start;
229 $link_data['month_start'] = $month_start;
230 $link_data['month_end'] = $month_end;
231 $link_data['month'] = $month;
232 $link_data['district'] = $districts[$i]['district'];
233 $link_data['district_name'] = $districts[$i]['name'];
234 $link_data['action'] = 'view';
235 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
236 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
237 if(!$total_visits[$m]) { $total_visits[$m] = 0; }
238 if($this->db2->next_record()) {
239 if($this->db2->f('visited') == 'y') {
240 $visits[$m]++; $total_visits[$m]++;
241 $table_data .= '<td align=center><a href="'.$link.'"><img src="checkmark.gif"></a></td>';
243 else if($this->db2->f('visited') == 'n') {
244 $table_data .= '<td align=center><a href="'.$link.'"><img src="x.gif"></a></td>';
246 else { $table_data .= "<td> </td>"; }
248 else { $table_data .= "<td> </td>"; }
250 $table_data .= "</tr>";
253 $table_data .= "<tr><td colspan=20></td></tr>";
255 $table_data .= "<tr><td colspan=20><hr></td></tr>";
256 $stat_data = "<tr><td><b><font size=-2>$num_families Families<br>Visit Totals:</font></b></td>";
258 for($m=$num_months; $m >=0; $m--) {
259 $percent = ceil(($visits[$m] / $num_families)*100);
260 $stat_data .= "<td align=center><font size=-2><b>$visits[$m]<br>$percent%</font></b></td>";
262 $stat_data .= "</tr>";
264 $this->t->set_var('table_width',$table_width);
265 $this->t->set_var('header_row',$header_row);
266 $this->t->set_var('table_data',$table_data);
267 $this->t->set_var('stat_data',$stat_data);
268 $this->t->fp('list','district_list',True);
271 $totals = "<tr><td><b><font size=-2>$total_families Total Families<br>Visit Totals:</font></b></td>";
272 for($m=$num_months; $m >=0; $m--) {
273 $percent = ceil(($total_visits[$m] / $total_families)*100);
274 $totals .= "<td align=center><font size=-2><b>$total_visits[$m]<br>$percent%</font></b></td>";
278 $this->t->set_var('totals',$totals);
280 $this->t->pfp('out','ht_view_t');
281 $this->save_sessiondata();
287 $this->t->set_file(array('ht_update_t' => 'ht_update.tpl'));
288 $this->t->set_block('ht_update_t','district_list','list');
289 $this->t->set_block('ht_update_t','save','savehandle');
291 $district = get_var('district',array('GET','POST'));
292 $district_name = get_var('district_name',array('GET','POST'));
293 $date = get_var('date',array('GET','POST'));
294 $month = get_var('month',array('GET','POST'));
295 $month_start = get_var('month_start',array('GET','POST'));
296 $month_end = get_var('month_end',array('GET','POST'));
297 $action = get_var('action',array('GET','POST'));
299 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
300 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_update&action=save'));
301 $this->t->set_var('lang_done','Cancel');
302 $this->t->set_var('district_name',$district_name);
303 $this->t->set_var('district_number',$district);
304 $this->t->set_var('title','Hometeaching Update ' . $month);
305 $this->t->set_var('date',$date);
307 if($action == 'save')
309 // Get a list of all the companionships in this district
310 $sql = "SELECT distinct companionship FROM eq_companionship where district=". $district;
311 $this->db->query($sql,__LINE__,__FILE__);
313 while ($this->db->next_record())
315 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
318 for ($j=0; $j < count($unique_companionships); $j++)
320 // Delete all the visits that have taken place for all families for this month
321 $this->db->query("DELETE from eq_visit where companionship=" . $unique_companionships[$j]['companionship'] .
322 " AND " . "date='" . $date . "'",__LINE__,__FILE__);
325 // Now, add the visits that are checked for this month
326 $new_data = get_var('family_visited',array('POST'));
327 foreach ($new_data as $family)
329 foreach ($family as $data)
331 //print "family_visited: $data <br>";
332 $data_array = explode("/",$data);
333 $family_id = $data_array[0];
334 $companionship = $data_array[1];
335 $date = $data_array[2];
336 $visited = $data_array[3];
337 if($visited == "") { $visited = $data_array[4]; }
338 //print "family_id: $family_id companionship: $companionship date: $date visited: $visited<br>";
339 $this->db->query("INSERT INTO eq_visit (family,companionship,date,notes,visited) "
340 . "VALUES (" . $family_id .",". $companionship .",'". $date ."','','". $visited ."')",__LINE__,__FILE__);
347 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
348 $this->db->query($sql,__LINE__,__FILE__);
350 while ($this->db->next_record())
352 $elder_id[$i] = $this->db->f('elder');
353 $elder_name[$i] = $this->db->f('name');
356 array_multisort($elder_name, $elder_id);
358 // Make an array mapping elder_ids to elder_names
359 for($i=0; $i < count($elder_id); $i++) {
361 $elders[$id] = $elder_name[$i];
364 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
365 $this->db->query($sql,__LINE__,__FILE__);
366 while ($this->db->next_record())
368 $aaronic_id = $this->db->f('aaronic');
369 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
372 // Select all the unique companionship numbers for this district
373 $sql = "SELECT distinct companionship FROM eq_companionship where district=". $district;
374 $this->db->query($sql,__LINE__,__FILE__);
375 $j=0; $unique_companionships='';
376 while ($this->db->next_record())
378 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
382 $comp_width=300; $visit_width=25; $table_width=$comp_width + $num_months*$visit_width;
383 $table_data=""; $num_companionships = 0; $num_families = 0; $visits=0;
384 for ($j=0; $j < count($unique_companionships); $j++) {
385 $companion_table_entry = "";
386 // Select all the companions in each companionship
387 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
388 "companionship=". $unique_companionships[$j]['companionship'];
389 $this->db->query($sql,__LINE__,__FILE__);
391 while ($this->db->next_record())
393 // Get this companions information
394 if($companion_table_entry != "") { $companion_table_entry .= " / "; }
395 $companionship = $this->db->f('companionship');
396 $elder_id = $this->db->f('elder');
397 $aaronic_id = $this->db->f('aaronic');
398 if($elder_id) { $name = $elders[$elder_id]; }
399 else if($aaronic_id) { $name = $aaronic[$aaronic_id]['name']; }
400 $companion_table_entry .= "$name";
402 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><b>$companion_table_entry</b><hr></td></tr>";
404 // Get the names of the families assigned this home teaching companionship
405 $sql = "SELECT * from eq_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
406 $this->db->query($sql,__LINE__,__FILE__);
407 while ($this->db->next_record())
409 $num_families++; $total_families++;
410 $family_name = $this->db->f('name');
411 $family_id = $this->db->f('family');
412 $this->nextmatchs->template_alternate_row_color(&$this->t);
413 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
415 $header_row="<th width=$comp_width><font size=-2>Families</th>";
416 $sql = "SELECT * FROM eq_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
417 " AND companionship=" . $unique_companionships[$j]['companionship'] .
418 " AND family=". $family_id;
419 $this->db2->query($sql,__LINE__,__FILE__);
420 $value = $family_id . "/" . $unique_companionships[$j]['companionship'] . "/" . $date;
421 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
422 if(!$total_visits) { $total_visits = 0; }
423 if($this->db2->next_record()) {
424 if($this->db2->f('visited') == 'y') {
425 $visits++; $total_visits++;
426 $table_data .= '<td width=100 align=center>';
427 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y" checked>Y';
428 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
429 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/"> ';
430 $table_data .= '</td>';
431 } else if($this->db2->f('visited') == 'n') {
432 $table_data .= '<td width=100 align=center>';
433 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
434 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n" checked>N';
435 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/">';
436 $table_data .= '</td>';
438 $table_data .= '<td width=100 align=center>';
439 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
440 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
441 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
442 $table_data .= '</td>';
447 $table_data .= '<td width=100 align=center>';
448 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
449 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
450 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
451 $table_data .= '</td>';
454 $table_data .= "</tr>";
455 $table_data .= "<tr><td colspan=20></td></tr>";
457 $table_data .= "<tr><td colspan=20><hr></td></tr>";
458 $stat_data = "<tr><td><b><font size=-2>$num_families Families<br>Visit Totals:</font></b></td>";
460 $percent = ceil(($visits / $num_families)*100);
461 $stat_data .= "<td align=center><font size=-2><b>$visits<br>$percent%</font></b></td>";
462 $stat_data .= "</tr>";
464 $this->t->set_var('table_width',$table_width);
465 $this->t->set_var('header_row',$header_row);
466 $this->t->set_var('table_data',$table_data);
467 $this->t->set_var('stat_data',$stat_data);
468 $this->t->fp('list','district_list',True);
470 $this->t->set_var('lang_reset','Clear Form');
471 $this->t->set_var('lang_save','Save Changes');
472 $this->t->set_var('savehandle','');
474 $this->t->pfp('out','ht_update_t');
475 $this->t->pfp('addhandle','save');
477 $this->save_sessiondata();
482 $this->t->set_file(array('act_list_t' => 'act_list.tpl'));
483 $this->t->set_block('act_list_t','act_list','list');
485 $this->t->set_var('lang_name','Activity Name');
486 $this->t->set_var('lang_date','Date');
488 $sql = "SELECT * FROM eq_activity ORDER BY date DESC";
489 $this->db->query($sql,__LINE__,__FILE__);
490 $total_records = $this->db->num_rows();
493 while ($this->db->next_record())
495 $activity_list[$i]['name'] = $this->db->f('name');
496 $activity_list[$i]['date'] = $this->db->f('date');
497 $activity_list[$i]['activity'] = $this->db->f('activity');
501 for ($i=0; $i < count($activity_list); $i++)
503 $this->nextmatchs->template_alternate_row_color(&$this->t);
504 $this->t->set_var('name',$activity_list[$i]['name']);
505 $this->t->set_var('date',$activity_list[$i]['date']);
507 $link_data['menuaction'] = 'eq.eq.act_view';
508 $link_data['activity'] = $activity_list[$i]['activity'];
509 $link_data['action'] = 'view';
510 $this->t->set_var('view',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
511 $this->t->set_var('lang_view','View');
513 $link_data['menuaction'] = 'eq.eq.act_update';
514 $link_data['activity'] = $activity_list[$i]['activity'];
515 $link_data['action'] = 'edit';
516 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
517 $this->t->set_var('lang_edit','Edit');
519 $link_data['menuaction'] = 'eq.eq.act_update';
520 $link_data['activity'] = '0';
521 $link_data['action'] = 'add';
522 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/eq/index.php',$link_data)
523 . '"><input type="submit" name="Add" value="' . 'Add Activity' .'"></font></form>');
525 $this->t->fp('list','act_list',True);
528 $this->t->pfp('out','act_list_t');
529 $this->save_sessiondata();
534 $this->t->set_file(array('act_view_t' => 'act_view.tpl'));
535 $this->t->set_block('act_view_t','part_list','list');
537 $sql = "SELECT * FROM eq_activity WHERE activity=" . intval(get_var('activity',array('GET','POST')));
538 $this->db->query($sql,__LINE__,__FILE__);
539 $this->db->next_record();
540 $this->t->set_var('name', $this->db->f('name'));
541 $this->t->set_var('date', $this->db->f('date'));
542 $this->t->set_var('notes', $this->db->f('notes'));
544 $this->t->set_var('lang_name','Activity Name');
545 $this->t->set_var('lang_date','Date');
546 $this->t->set_var('lang_notes','Notes');
547 $this->t->set_var('lang_done','Done');
548 $this->t->set_var('lang_action','View');
550 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
551 $this->t->set_var('tr_color',$tr_color);
553 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_list'));
555 $link_data['menuaction'] = 'eq.eq.act_update';
556 $link_data['activity'] = get_var('activity',array('GET','POST'));
557 $link_data['action'] = 'edit';
558 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
559 $this->t->set_var('lang_edit','Edit');
560 $this->t->set_var('cal_date',$this->db->f('date'));
562 // Now find out which elders participated in this activity
563 $sql = "SELECT * FROM eq_participation WHERE activity=" . intval(get_var('activity',array('GET','POST')));
564 $this->db->query($sql,__LINE__,__FILE__);
565 $total_records = $this->db->num_rows();
568 while ($this->db->next_record())
570 $part_list[$i]['elder'] = $this->db->f('elder');
574 for ($i=0; $i < count($part_list); $i++)
576 $sql = "SELECT * FROM eq_elder WHERE elder=" . $part_list[$i]['elder'];
577 $this->db->query($sql,__LINE__,__FILE__);
578 $this->db->next_record();
579 $names[$i] = $this->db->f('name');
582 for ($i=0; $i < count($names); $i++)
584 //$this->nextmatchs->template_alternate_row_color(&$this->t);
585 $this->t->set_var('elder_name',$names[$i]);
586 if(($i+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
587 else { $this->t->set_var('table_sep',"</td>"); }
588 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
589 $this->t->fp('list','part_list',True);
592 $this->t->pfp('out','act_view_t');
593 $this->save_sessiondata();
596 function act_update()
598 $this->t->set_file(array('form' => 'act_update.tpl'));
599 $this->t->set_block('form','elder_list','list');
600 $this->t->set_block('form','add','addhandle');
601 $this->t->set_block('form','edit','edithandle');
602 $this->t->set_var('lang_done','Done');
604 $action = get_var('action',array('GET','POST'));
605 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_list'));
606 $activity['activity'] = intval(get_var('activity',array('GET','POST')));
608 if($action == 'save')
610 $activity['name'] = $this->db->db_addslashes(get_var('name',array('POST')));
611 $activity['date'] = $this->db->db_addslashes(get_var('date',array('POST')));
612 $activity['notes']= $this->db->db_addslashes(get_var('notes',array('POST')));
613 $this->db->query("UPDATE eq_activity set " .
614 " name='" . $activity['name'] .
615 "', date='" . $activity['date'] . "'" .
616 ", notes='" . $activity['notes'] . "'" .
617 " WHERE activity=" . $activity['activity'],__LINE__,__FILE__);
619 // Delete all the elders who have particiapted in this activity
620 $this->db->query("DELETE from eq_participation where activity=".$activity['activity'],__LINE__,__FILE__);
622 // Re-add the elders who are checked as having participated in this activity
623 $elders = get_var('elder_name',array('POST'));
624 foreach ($elders as $elder)
626 $this->db->query("INSERT INTO eq_participation (elder,activity) "
627 . "VALUES (" . $elder . ",". $activity['activity'] . ")",__LINE__,__FILE__);
634 if($action == 'insert')
636 $activity['name'] = $this->db->db_addslashes(get_var('name',array('POST')));
637 $activity['date'] = $this->db->db_addslashes(get_var('date',array('POST')));
638 $activity['notes']= $this->db->db_addslashes(get_var('notes',array('POST')));
639 $this->db->query("INSERT INTO eq_activity (name,date,notes) "
640 . "VALUES ('" . $activity['name'] . "','"
641 . $activity['date'] . "','" . $activity['notes'] . "')",__LINE__,__FILE__);
648 $activity['activity'] = 0;
649 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
650 $this->t->set_var('name','');
651 $this->t->set_var('date','');
652 $this->t->set_var('notes','');
653 $this->t->set_var('lang_done','Cancel');
654 $this->t->set_var('lang_action','Adding New Activity');
655 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_update&activity='
656 . $activity['activity'] . '&action=' . 'insert'));
659 if($action == 'edit')
661 $sql = "SELECT * FROM eq_activity WHERE activity=" . $activity['activity'];
662 $this->db->query($sql,__LINE__,__FILE__);
663 $this->db->next_record();
664 $this->t->set_var('cal_date',$this->jscal->input('date',$this->db->f('date'),'','','','','',$this->cal_options));
665 $this->t->set_var('name', $this->db->f('name'));
666 $this->t->set_var('date', $this->db->f('date'));
667 $this->t->set_var('notes', $this->db->f('notes'));
668 $this->t->set_var('lang_done','Cancel');
669 $this->t->set_var('lang_action','Editing Activity');
670 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_update&activity='
671 . $activity['activity'] . '&action=' . 'save'));
675 $sql = "SELECT * FROM eq_elder";
676 $this->db->query($sql,__LINE__,__FILE__);
678 while ($this->db->next_record())
680 if($this->db->f('valid') == 1 || $action != 'add') {
681 $elder_name[$i] = $this->db->f('name');
682 $elder_id[$i] = $this->db->f('elder');
683 $elder_valid[$i] = $this->db->f('valid');
687 array_multisort($elder_name, $elder_id, $elder_valid);
690 for ($i=0; $i < count($elder_id); $i++)
692 //$this->nextmatchs->template_alternate_row_color(&$this->t);
693 $sql = "SELECT * FROM eq_participation where activity=". $activity['activity'] . " AND elder=" . $elder_id[$i];
694 $this->db->query($sql,__LINE__,__FILE__);
695 if($this->db->next_record()) { $this->t->set_var('checked','checked'); $checked=1; }
696 else { $this->t->set_var('checked',''); $checked=0; }
697 if($checked || $elder_valid[$i] == 1) {
698 $this->t->set_var('elder_name',$elder_name[$i]);
699 $this->t->set_var('elder',$elder_id[$i]);
700 if(($j+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
701 else { $this->t->set_var('table_sep',"</td>"); }
702 if(($j) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
703 $this->t->fp('list','elder_list',True);
708 $this->t->set_var('lang_reset','Clear Form');
709 $this->t->set_var('lang_add','Add Activity');
710 $this->t->set_var('lang_save','Save Changes');
711 $this->t->set_var('edithandle','');
712 $this->t->set_var('addhandle','');
714 $this->t->pfp('out','form');
715 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
716 if($action == 'add') { $this->t->pfp('addhandle','add'); }
718 $this->save_sessiondata();
723 $this->t->set_file(array('par_view_t' => 'par_view.tpl'));
724 $this->t->set_block('par_view_t','header_list','list1');
725 $this->t->set_block('par_view_t','elder_list','list2');
727 $sql = "SELECT * FROM eq_elder where valid=1";
728 $this->db->query($sql,__LINE__,__FILE__);
730 while ($this->db->next_record())
732 $elder_name[$i] = $this->db->f('name');
733 $elder_id[$i] = $this->db->f('elder');
736 array_multisort($elder_name, $elder_id);
738 $sql = "SELECT * FROM eq_activity ORDER BY date DESC";
739 $this->db->query($sql,__LINE__,__FILE__);
740 $total_records = $this->db->num_rows();
743 while ($this->db->next_record())
745 $activity_list[$i]['name'] = $this->db->f('name');
746 $activity_list[$i]['date'] = $this->db->f('date');
747 $activity_list[$i]['activity'] = $this->db->f('activity');
748 if($activity_list[$i]['date'] == '0000-00-00') { $activity_list[$i]['date']=""; }
752 $elder_width=250; $part_width=25; $act_width=50;
753 $total_width=$elder_width+$part_width;
754 for ($i=0; $i < count($activity_list); $i++) {
755 $this->t->set_var('activity_name',$activity_list[$i]['name']);
756 $this->t->set_var('activity_date',$activity_list[$i]['date']);
757 $this->t->fp('list1','header_list',True);
758 $total_width += $act_width;
761 for ($i=0; $i < count($elder_id); $i++) {
762 $participated=0; $part_table = '';
763 $this->nextmatchs->template_alternate_row_color(&$this->t);
764 $this->t->set_var('elder_name',$elder_name[$i]);
765 for ($j=0; $j < count($activity_list); $j++) {
766 $sql = "SELECT * FROM eq_participation where activity="
767 . $activity_list[$j]['activity'] . " AND elder=" . $elder_id[$i];
768 $this->db->query($sql,__LINE__,__FILE__);
769 if($this->db->next_record()) {
770 $part_table .= '<td align=center><img src="checkmark.gif"></td>';
773 $part_table .= '<td> </td>';
776 if($participated) { $part_table .= '<td align=center><img src="checkmark.gif">'.$participated.'</td>'; }
777 else { $part_table .= '<td> </td>'; }
778 $this->t->set_var('part_table',$part_table);
779 $this->t->fp('list2','elder_list',True);
781 $this->t->set_var('total_width',$total_width);
782 $this->t->set_var('elder_width',$elder_width);
783 $this->t->set_var('part_width',$part_width);
784 $this->t->set_var('act_width',$act_width);
785 $this->t->pfp('out','par_view_t');
786 $this->save_sessiondata();
791 $this->t->set_file(array('ppi_view_t' => 'ppi_view.tpl'));
792 $this->t->set_block('ppi_view_t','district_list','list');
794 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
795 $num_months = get_var('num_months',array('GET','POST'));
796 if($num_months == '') { $num_months = $this->default_ppi_num_months; }
797 $this->t->set_var('num_months',$num_months);
798 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
799 else { $this->t->set_var('lang_num_months','Months of History'); }
800 $this->t->set_var('lang_filter','Filter');
802 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
803 $this->t->set_var('eqpres_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view&eqpresppi=1'));
804 $eqpresppi = get_var('eqpresppi',array('GET','POST'));
806 if($eqpresppi == 1) {
807 $num_months = get_var('num_months',array('GET','POST'));
808 if($num_months == '') { $num_months = $this->default_ppi_num_years; }
809 $this->t->set_var('num_months',$num_months);
810 $this->t->set_var('ppi_link_title','PPIs');
811 $this->t->set_var('title','EQ President Yearly PPIs');
812 if($num_months == 1) { $this->t->set_var('lang_num_months','Year of History'); }
813 else { $this->t->set_var('lang_num_months','Years of History'); }
814 $this->t->set_var('eqpres_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
817 $this->t->set_var('ppi_link_title','EQ President Yearly PPIs');
818 $this->t->set_var('title','PPIs');
821 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
822 $this->db->query($sql,__LINE__,__FILE__);
824 while ($this->db->next_record())
826 $districts[$i]['district'] = $this->db->f('district');
827 $districts[$i]['name'] = $this->db->f('name');
828 $districts[$i]['supervisor'] = $this->db->f('supervisor');
829 if($eqpresppi == 0) { $i++; }
832 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
833 $this->db->query($sql,__LINE__,__FILE__);
835 while ($this->db->next_record())
837 $elder_id[$i] = $this->db->f('elder');
838 $elder_name[$i] = $this->db->f('name');
841 array_multisort($elder_name, $elder_id);
842 for($i=0; $i < count($elder_id); $i++) {
844 $elders[$id] = $elder_name[$i];
847 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
848 $this->db->query($sql,__LINE__,__FILE__);
849 while ($this->db->next_record())
851 $aaronic_id = $this->db->f('aaronic');
852 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
855 $total_companionships = 0;
856 $this->nextmatchs->template_alternate_row_color(&$this->t);
857 for ($i=0; $i < count($districts); $i++) {
858 if($eqpresppi == 1) {
859 $this->t->set_var('district_number','*');
860 $this->t->set_var('district_name','EQ President');
862 $this->t->set_var('district_number',$districts[$i]['district']);
863 $this->t->set_var('district_name',$districts[$i]['name']);
865 $supervisor = $districts[$i]['supervisor'];
866 $unique_companionships='';
868 // Select all the unique companionship numbers for this district
869 if($eqpresppi == 1) {
870 $sql = "SELECT distinct companionship FROM eq_companionship";
873 $sql = "SELECT distinct companionship FROM eq_companionship where district=". $districts[$i]['district'];
875 $this->db->query($sql,__LINE__,__FILE__);
877 while ($this->db->next_record())
879 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
883 $comp_width=400; $ppi_width=25; $table_width=$comp_width + $num_months*$ppi_width;
884 $table_data=""; $num_companionships = 0; $num_elders = 0;
885 for($m=$num_months; $m >= 0; $m--) { $ppis[$m] = 0; }
886 for ($j=0; $j < count($unique_companionships); $j++) {
887 // Select all the companions in each companionship
889 $sql = "SELECT * FROM eq_companionship where valid=1 and aaronic=0 and ".
890 "companionship=". $unique_companionships[$j]['companionship'];
893 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
894 "companionship=". $unique_companionships[$j]['companionship'];
896 $this->db->query($sql,__LINE__,__FILE__);
898 while ($this->db->next_record())
900 // Get this companions information
901 $num_elders++; $num_companionships++;
902 $companionship = $this->db->f('companionship');
903 $elder_id = $this->db->f('elder');
904 $aaronic_id = $this->db->f('aaronic');
905 if($elder_id) { $name = $elders[$elder_id]; }
906 else if($aaronic_id) { $name = $aaronic[$aaronic_id]['name']; }
907 $link_data['menuaction'] = 'eq.eq.ppi_update';
908 $link_data['companionship'] = $companionship;
909 $link_data['interviewer'] = $supervisor;
910 $link_data['elder'] = $elder_id;
911 $link_data['name'] = $name;
912 $link_data['ppi'] = '';
913 $link_data['eqpresppi'] = $eqpresppi;
914 $link_data['action'] = 'add';
915 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
916 if($aaronic_id == 0) {
917 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td><a href=$link>$name</a></td>";
919 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$name</td>";
922 // Find out how many times PPIs were performed in the past $num_months for this Elder
923 $header_row="<th width=$comp_width><font size=-2>Companionship</th>";
924 for($m=$num_months; $m >= 0; $m--) {
925 if($eqpresppi == 1) {
926 $year = date('Y') - $m;
927 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
928 $sql = "SELECT * FROM eq_ppi WHERE date > '$year_start' AND date < '$year_end' ".
929 "AND elder=" . $elder_id . " AND eqpresppi=1";
930 $this->db2->query($sql,__LINE__,__FILE__);
931 $header_row .= "<th width=150><font size=-2>$year</th>";
934 $month = date('m/Y', strtotime('-'.$m.' month'));
935 $month_start = date('Y-m', strtotime('-'.$m.' month')); $month_start .= "-01";
936 $month_end = date('Y-m', strtotime('-'.$m.' month')); $month_end .= "-31";
937 $sql = "SELECT * FROM eq_ppi WHERE date >= '$month_start' AND date <= '$month_end' ".
938 "AND elder=" . $elder_id . " AND eqpresppi=0";
939 $this->db2->query($sql,__LINE__,__FILE__);
940 $header_row .= "<th width=$ppi_width><font size=-2>$month</th>";
942 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
943 if($this->db2->next_record()) {
944 $ppis[$m]++; $total_ppis[$m]++;
945 $link_data['menuaction'] = 'eq.eq.ppi_update';
946 $link_data['companionship'] = $companionship;
947 $link_data['interviewer'] = $supervisor;
948 $link_data['elder'] = $elder_id;
949 $link_data['name'] = $name;
950 $link_data['ppi'] = $this->db2->f('ppi');
951 $link_data['eqpresppi'] = $eqpresppi;
952 $link_data['action'] = 'view';
953 $date = $this->db2->f('date');
954 $date_array = explode("-",$date);
955 $month = $date_array[1];
956 $day = $date_array[2];
957 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
959 if($aaronic_id == 0) {
960 $table_data .= '<td align=center><a href='.$link.'><img src="checkmark.gif"><br>'.$month.'-'.$day.'</a></td>';
962 $table_data .= '<td align=center><img src="checkmark.gif"></td>';
965 else { $table_data .= "<td> </td>"; }
967 $table_data .= "</tr>";
970 if($num_companionships % 2 != 0) { $num_companionships++; }
971 $table_data .= "<tr><td colspan=20><hr></td></tr>";
973 // Now add Elders not assigned to any companionship to the table if we are in eqpresppi mode
974 if($eqpresppi == 1) {
975 $table_data .= "<tr bgcolor=\"#c9c9c9\"><hr><td colspan=20><b>Unassigned Potential Home Teachers</b><hr></td></tr>";
976 foreach($elders as $elder_id => $value) {
977 $sql = "SELECT * FROM eq_companionship where valid=1 and elder=".$elder_id;
978 $this->db->query($sql,__LINE__,__FILE__);
979 if(!$this->db->next_record()) {
980 // We found an Elder not in a companionship, add them to the table
981 $num_elders++; $num_companionships++;
983 $name = $elders[$elder_id];
984 $link_data['menuaction'] = 'eq.eq.ppi_update';
985 $link_data['companionship'] = $companionship;
986 $link_data['interviewer'] = $supervisor;
987 $link_data['elder'] = $elder_id;
988 $link_data['name'] = $name;
989 $link_data['ppi'] = '';
990 $link_data['eqpresppi'] = $eqpresppi;
991 $link_data['action'] = 'add';
992 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
993 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td><a href=$link>$name</a></td>";
994 for($m=$num_months; $m >= 0; $m--) {
995 $year = date('Y') - $m;
996 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
997 $sql = "SELECT * FROM eq_ppi WHERE date > '$year_start' AND date < '$year_end' ".
998 "AND elder=" . $elder_id . " AND eqpresppi=1";
999 $this->db2->query($sql,__LINE__,__FILE__);
1000 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
1001 if($this->db2->next_record()) {
1002 $ppis[$m]++; $total_ppis[$m]++;
1003 $link_data['menuaction'] = 'eq.eq.ppi_update';
1004 $link_data['companionship'] = $companionship;
1005 $link_data['interviewer'] = $supervisor;
1006 $link_data['elder'] = $elder_id;
1007 $link_data['name'] = $name;
1008 $link_data['ppi'] = $this->db2->f('ppi');
1009 $link_data['eqpresppi'] = $eqpresppi;
1010 $link_data['action'] = 'view';
1011 $date = $this->db2->f('date');
1012 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1013 $table_data .= '<td align=center><a href='.$link.'><img src="checkmark.gif"><br>'.$date.'</a></td>';
1015 else { $table_data .= "<td> </td>"; }
1017 $table_data .= "</tr>";
1021 $num_companionships = ceil($num_companionships/2);
1022 $total_companionships += $num_companionships;
1023 if($eqpresppi == 1) {
1024 $stat_data = "<tr><td><b><font size=-2>$num_elders Elders<br>PPI Totals:</font></b></td>";
1026 $stat_data = "<tr><td><b><font size=-2>$num_companionships Companionships<br>PPI Totals:</font></b></td>";
1028 for($m=$num_months; $m >=0; $m--) {
1029 if($eqpresppi == 1) { $percent = ceil(($ppis[$m] / $num_elders)*100); }
1030 else { $percent = ceil(($ppis[$m] / $num_companionships)*100); }
1031 $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
1033 $stat_data .= "</tr>";
1035 $this->t->set_var('table_width',$table_width);
1036 $this->t->set_var('header_row',$header_row);
1037 $this->t->set_var('table_data',$table_data);
1038 $this->t->set_var('stat_data',$stat_data);
1039 $this->t->fp('list','district_list',True);
1042 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>PPI Totals:</font></b></td>";
1043 for($m=$num_months; $m >=0; $m--) {
1044 $percent = ceil(($total_ppis[$m] / $total_companionships)*100);
1045 $totals .= "<td align=center><font size=-2><b>$total_ppis[$m]<br>$percent%</font></b></td>";
1049 $this->t->set_var('totals',$totals);
1050 $this->t->pfp('out','ppi_view_t');
1051 $this->save_sessiondata();
1054 function ppi_update()
1056 $this->t->set_file(array('form' => 'ppi_update.tpl'));
1057 $this->t->set_block('form','interviewer_list','int_list');
1058 $this->t->set_block('form','add','addhandle');
1059 $this->t->set_block('form','edit','edithandle');
1061 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
1062 $this->t->set_var('readonly','');
1063 $this->t->set_var('disabled','');
1065 $action = get_var('action',array('GET','POST'));
1066 $companionship = get_var('companionship',array('GET','POST'));
1067 $interviewer = get_var('interviewer',array('GET','POST'));
1068 $name = get_var('name',array('GET','POST'));
1069 $ppi = get_var('ppi',array('GET','POST'));
1070 $elder = get_var('elder',array('GET','POST'));
1071 $date = get_var('date',array('GET','POST'));
1072 $notes = get_var('notes',array('GET','POST'));
1073 $eqpresppi = get_var('eqpresppi',array('GET','POST'));
1075 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
1076 $this->db->query($sql,__LINE__,__FILE__);
1077 while ($this->db->next_record())
1079 $supervisor = $this->db->f('supervisor');
1080 $sql = "SELECT * FROM eq_elder WHERE elder=" . $supervisor;
1081 $this->db2->query($sql,__LINE__,__FILE__);
1082 $this->db2->next_record();
1083 $interviewer_name = $this->db2->f('name');
1085 if($supervisor == $interviewer) {
1086 $this->t->set_var('interviewer',$supervisor . ' selected');
1088 $this->t->set_var('interviewer',$interviewer);
1090 $this->t->set_var('interviewer_name',$interviewer_name);
1091 $this->t->fp('int_list','interviewer_list',True);
1094 if($action == 'save')
1096 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
1097 $this->db->query("UPDATE eq_ppi set " .
1098 " ppi='" . $ppi . "'" .
1099 ", interviewer='" . $interviewer . "'" .
1100 ", elder='" . $elder . "'" .
1101 ", date='" . $date . "'" .
1102 ", notes='" . $notes . "'" .
1103 ", eqpresppi='" . $eqpresppi . "'" .
1104 " WHERE ppi=" . $ppi,__LINE__,__FILE__);
1109 if($action == 'insert')
1111 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
1112 $this->db->query("INSERT INTO eq_ppi (interviewer,elder,date,notes,eqpresppi) "
1113 . "VALUES ('" . $interviewer . "','" . $elder . "','"
1114 . $date . "','" . $notes . "','" . $eqpresppi ."')",__LINE__,__FILE__);
1119 if($action == 'add')
1121 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
1122 $this->t->set_var('ppi', '');
1123 $this->t->set_var('interviewer', $interviewer);
1124 $this->t->set_var('name',$name);
1125 $this->t->set_var('elder',$elder);
1126 $this->t->set_var('date','');
1127 $this->t->set_var('notes','');
1128 $this->t->set_var('eqpresppi',$eqpresppi);
1129 $this->t->set_var('lang_done','Cancel');
1130 $this->t->set_var('lang_action','Adding New PPI');
1131 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
1132 . $ppi . '&action=' . 'insert'));
1135 if($action == 'edit' || $action == 'view')
1137 $sql = "SELECT * FROM eq_ppi WHERE ppi=".$ppi;
1138 $this->db->query($sql,__LINE__,__FILE__);
1139 $this->db->next_record();
1140 $this->t->set_var('ppi',$ppi);
1141 $this->t->set_var('name',$name);
1142 $this->t->set_var('interviewer', $this->db->f('interviewer'));
1143 $this->t->set_var('elder',$this->db->f('elder'));
1144 $this->t->set_var('date',$this->db->f('date'));
1145 $this->t->set_var('notes',$this->db->f('notes'));
1146 $this->t->set_var('eqpresppi',$this->db->f('eqpresppi'));
1149 if($action == 'edit')
1151 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
1152 $this->t->set_var('lang_done','Cancel');
1153 $this->t->set_var('lang_action','Editing PPI');
1154 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
1155 . $ppi . '&action=' . 'save'));
1158 if($action == 'view')
1160 $date = $this->db->f('date');
1161 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
1162 $this->t->set_var('readonly','READONLY');
1163 $this->t->set_var('disabled','DISABLED');
1164 $this->t->set_var('lang_done','Done');
1165 $this->t->set_var('lang_action','Viewing PPI');
1166 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
1167 . $ppi . '&action=' . 'edit'));
1170 $this->t->set_var('lang_reset','Clear Form');
1171 $this->t->set_var('lang_add','Add PPI');
1172 $this->t->set_var('lang_save','Save Changes');
1173 $this->t->set_var('edithandle','');
1174 $this->t->set_var('addhandle','');
1176 $this->t->pfp('out','form');
1178 if($action == 'view') { $this->t->set_var('lang_save','Edit PPI'); }
1179 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
1180 if($action == 'add') { $this->t->pfp('addhandle','add'); }
1182 $this->save_sessiondata();
1187 $this->t->set_file(array('vis_view_t' => 'vis_view.tpl'));
1188 $this->t->set_block('vis_view_t','visit_list','list1');
1189 $this->t->set_block('vis_view_t','family_list','list2');
1191 $this->t->set_var('lang_name','Family Name');
1192 $this->t->set_var('lang_date','Date');
1194 $sql = "SELECT * FROM eq_visit WHERE companionship=0 ORDER BY date DESC";
1195 $this->db->query($sql,__LINE__,__FILE__);
1196 $total_records = $this->db->num_rows();
1199 while ($this->db->next_record())
1201 $visit_list[$i]['visit'] = $this->db->f('visit');
1202 $visit_list[$i]['family'] = $this->db->f('family');
1203 $visit_list[$i]['date'] = $this->db->f('date');
1207 for ($i=0; $i < count($visit_list); $i++)
1209 $this->nextmatchs->template_alternate_row_color(&$this->t);
1211 $sql = "SELECT * FROM eq_family WHERE valid=1 AND family=".$visit_list[$i]['family'];
1212 $this->db->query($sql,__LINE__,__FILE__);
1213 $this->db->next_record();
1215 $this->t->set_var('family',$visit_list[$i]['family']);
1216 $this->t->set_var('family_name',$this->db->f('name'));
1217 $this->t->set_var('date',$visit_list[$i]['date']);
1219 $link_data['menuaction'] = 'eq.eq.vis_update';
1220 $link_data['visit'] = $visit_list[$i]['visit'];
1221 $link_data['name'] = $this->db->f('name');
1222 $link_data['date'] = $visit_list[$i]['date'];
1223 $link_data['action'] = 'view';
1224 $this->t->set_var('view',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1225 $this->t->set_var('lang_view','View');
1227 $link_data['menuaction'] = 'eq.eq.vis_update';
1228 $link_data['visit'] = $visit_list[$i]['visit'];
1229 $link_data['name'] = $this->db->f('name');
1230 $link_data['date'] = $visit_list[$i]['date'];
1231 $link_data['action'] = 'edit';
1232 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1233 $this->t->set_var('lang_edit','Edit');
1235 $this->t->fp('list1','visit_list',True);
1238 // List the families that are available to record a visit against
1239 $sql = "SELECT * FROM eq_family WHERE valid=1";
1240 $this->db->query($sql,__LINE__,__FILE__);
1241 $total_records = $this->db->num_rows();
1244 while ($this->db->next_record())
1246 $family_names[$i] = $this->db->f('name');
1247 $family_ids[$i] = $this->db->f('family');
1249 } array_multisort($family_names, $family_ids);
1251 for ($i=0; $i < count($family_names); $i++)
1253 $link_data['menuaction'] = 'eq.eq.vis_update';
1254 $link_data['visit'] = '';
1255 $link_data['family'] = $family_ids[$i];
1256 $link_data['action'] = 'add';
1257 $link_data['name'] = $family_names[$i];
1258 $this->t->set_var('add',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1260 $this->t->set_var('name',$family_names[$i]);
1261 if(($i+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
1262 else { $this->t->set_var('table_sep',"</td>"); }
1263 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
1265 $this->t->fp('list2','family_list',True);
1268 $this->t->pfp('out','vis_view_t');
1269 $this->save_sessiondata();
1272 function vis_update()
1274 $this->t->set_file(array('form' => 'vis_update.tpl'));
1275 $this->t->set_block('form','add','addhandle');
1276 $this->t->set_block('form','edit','edithandle');
1278 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
1279 $this->t->set_var('readonly','');
1280 $this->t->set_var('disabled','');
1282 $action = get_var('action',array('GET','POST'));
1283 $visit = get_var('visit',array('GET','POST'));
1284 $family = get_var('family',array('GET','POST'));
1285 $name = get_var('name',array('GET','POST'));
1286 $date = get_var('date',array('GET','POST'));
1287 $notes = get_var('notes',array('GET','POST'));
1290 if($action == 'save')
1292 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
1293 $this->db->query("UPDATE eq_visit set " .
1294 " date='" . $date . "'" .
1295 ", notes='" . $notes . "'" .
1296 " WHERE visit=" . $visit,__LINE__,__FILE__);
1301 if($action == 'insert')
1303 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
1304 $this->db->query("INSERT INTO eq_visit (family,companionship,date,notes) "
1305 . "VALUES ('" . $family . "','" . $companionship . "','"
1306 . $date . "','" . $notes . "')",__LINE__,__FILE__);
1311 if($action == 'add')
1313 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
1314 $this->t->set_var('family', $family);
1315 $this->t->set_var('visit', '');
1316 $this->t->set_var('name', $name);
1317 $this->t->set_var('date','');
1318 $this->t->set_var('notes','');
1319 $this->t->set_var('lang_done','Cancel');
1320 $this->t->set_var('lang_action','Adding New Visit');
1321 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&family='
1322 . $family . '&action=' . 'insert'));
1325 if($action == 'edit' || $action == 'view')
1327 $sql = "SELECT * FROM eq_visit WHERE visit=".$visit;
1328 $this->db->query($sql,__LINE__,__FILE__);
1329 $this->db->next_record();
1330 $this->t->set_var('visit',$visit);
1331 $this->t->set_var('name',$name);
1332 $this->t->set_var('family', $family);
1333 $this->t->set_var('date',$this->db->f('date'));
1334 $this->t->set_var('notes',$this->db->f('notes'));
1337 if($action == 'edit')
1339 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
1340 $this->t->set_var('lang_done','Cancel');
1341 $this->t->set_var('lang_action','Editing Visit');
1342 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&visit='
1343 . $visit . '&action=' . 'save'));
1346 if($action == 'view')
1348 $date = $this->db->f('date');
1349 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
1350 $this->t->set_var('readonly','READONLY');
1351 $this->t->set_var('disabled','DISABLED');
1352 $this->t->set_var('lang_done','Done');
1353 $this->t->set_var('lang_action','Viewing Visit');
1354 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&visit='
1355 . $visit . '&action=' . 'edit'));
1358 $this->t->set_var('lang_reset','Clear Form');
1359 $this->t->set_var('lang_add','Add Visit');
1360 $this->t->set_var('lang_save','Save Changes');
1361 $this->t->set_var('edithandle','');
1362 $this->t->set_var('addhandle','');
1364 $this->t->pfp('out','form');
1366 if($action == 'view') { $this->t->set_var('lang_save','Edit Visit'); }
1367 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
1368 if($action == 'add') { $this->t->pfp('addhandle','add'); }
1370 $this->save_sessiondata();
1375 $this->t->set_file(array('att_view_t' => 'att_view.tpl'));
1376 $this->t->set_block('att_view_t','act_list','list');
1378 $this->t->set_block('att_view_t','month_list','list1');
1379 $this->t->set_block('att_view_t','header_list','list2');
1380 $this->t->set_block('att_view_t','elder_list','list3');
1382 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_view'));
1383 $num_months = get_var('num_months',array('GET','POST'));
1384 if($num_months == '') { $num_months = $this->default_att_num_months; }
1385 $this->t->set_var('num_months',$num_months);
1386 $this->t->set_var('lang_filter','Filter');
1387 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
1388 else { $this->t->set_var('lang_num_months','Months of History'); }
1390 $sql = "SELECT * FROM eq_elder where valid=1";
1391 $this->db->query($sql,__LINE__,__FILE__);
1393 while ($this->db->next_record())
1395 $elder_name[$i] = $this->db->f('name');
1396 $elder_id[$i] = $this->db->f('elder');
1399 array_multisort($elder_name, $elder_id);
1402 // Create a list of sunday dates for a window of 3 months back and current month
1406 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, date("m")-$num_months, 1, date("y")));
1407 $last_date = explode("-",$sunday_list[0]['date']);
1408 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
1409 $time_limit = mktime(0, 0, 0, date("m"), date("t"), date("y"));
1410 while($last_time < $time_limit)
1412 $day = date("w",$last_time);
1413 if(date("w",$last_time) == 0) {
1414 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
1415 $last_date = explode("-",$sunday_list[$i]['date']);
1416 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
1417 $sunday_list[$i]['day'] = $last_date[2];
1418 $sunday_list[$i]['month'] = date("M",$last_time);
1419 $sunday_list[$i]['year'] = $last_date[0];
1422 $last_time += 90000;
1423 if($found_sunday) { $i++; $found_sunday=0; }
1426 $old_month=$sunday_list[0]['month']; $span=0;
1427 for ($i=0; $i < count($sunday_list); $i++) {
1428 $date = $sunday_list[$i]['date'];
1429 $this->t->set_var('date',$sunday_list[$i]['date']);
1430 $this->t->set_var('day',$sunday_list[$i]['day']);
1431 if(($old_month != $sunday_list[$i]['month']) || $i == count($sunday_list)-1) {
1432 if($i == count($sunday_list)-1) { $span++; }
1433 $cur_month = $sunday_list[$i]['month'];
1434 $old_month = $sunday_list[$i]['month'];
1435 $link_data['menuaction'] = 'eq.eq.att_update';
1436 $link_data['month'] = $sunday_list[$i-1]['month'];
1437 $link_data['year'] = $sunday_list[$i-1]['year'];
1438 $link_data['action'] = 'update_month';
1439 $this->t->set_var('update_month',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1440 $this->t->set_var('month',$sunday_list[$i-1]['month']);
1441 $this->t->set_var('year',$sunday_list[$i-1]['year']);
1442 $this->t->set_var('span',$span); $span=0;
1443 $this->t->fp('list1','month_list',True);
1447 $elder_width=200; $att_width=25; $total_width=$elder_width;
1448 for ($i=0; $i < count($sunday_list); $i++) {
1449 $link_data['menuaction'] = 'eq.eq.att_update';
1450 $link_data['month'] = $sunday_list[$i]['month'];
1451 $link_data['year'] = $sunday_list[$i]['year'];
1452 $link_data['day'] = $sunday_list[$i]['day'];
1453 $link_data['date'] = $sunday_list[$i]['date'];
1454 $link_data['action'] = 'update_day';
1455 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1456 $this->t->set_var('date',$sunday_list[$i]['date']);
1457 $this->t->set_var('day',$sunday_list[$i]['day']);
1458 $this->t->set_var('month',$sunday_list[$i]['month']);
1459 $this->t->set_var('year',$sunday_list[$i]['year']);
1460 $this->t->fp('list2','header_list',True);
1461 $total_width += $att_width;
1464 for ($i=0; $i < count($elder_id); $i++) {
1466 $this->nextmatchs->template_alternate_row_color(&$this->t);
1467 $this->t->set_var('elder_name',$elder_name[$i]);
1468 #print "checking for elder: " . $elder_id[$i] . "<br>";
1469 for ($j=0; $j < count($sunday_list); $j++) {
1470 #print "checking for date: " . $sunday_list[$j]['date'] . "<br>";
1471 #print "SELECT * FROM eq_attendance WHERE date='"
1472 # . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i] . "<br>";
1473 $sql = "SELECT * FROM eq_attendance WHERE date='"
1474 . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i];
1475 $this->db->query($sql,__LINE__,__FILE__);
1476 if($this->db->next_record()) {
1477 $att_table .= '<td align=center><img src="checkmark.gif"></td>';
1479 $att_table .= '<td> </td>';
1482 $this->t->set_var('att_table',$att_table);
1483 $this->t->fp('list3','elder_list',True);
1485 $this->t->set_var('total_width',$total_width);
1486 $this->t->set_var('elder_width',$elder_width);
1487 $this->t->set_var('att_width',$att_width);
1489 $this->t->pfp('out','att_view_t');
1490 $this->save_sessiondata();
1493 function att_update()
1495 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
1496 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
1497 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
1499 $this->t->set_file(array('form' => 'att_update.tpl'));
1500 $this->t->set_block('form','edit','edithandle');
1502 $this->t->set_block('form','month_list','list1');
1503 $this->t->set_block('form','header_list','list2');
1504 $this->t->set_block('form','elder_list','list3');
1506 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_view'));
1508 $action = get_var('action',array('GET','POST'));
1509 $month = get_var('month',array('GET','POST'));
1510 $year = get_var('year',array('GET','POST'));
1511 $day = get_var('day',array('GET','POST'));
1512 $date = get_var('date',array('GET','POST'));
1514 if($action == 'save_month' || $action == 'save_day')
1516 $new_data = get_var('elders_attended',array('POST'));
1517 $month = $monthnum[$month]; if($month < 10) { $month = "0" . $month; }
1519 if($action == 'save_month') {
1520 $this->db->query("DELETE from eq_attendance where date LIKE '".$year."-".$month."-%'",__LINE__,__FILE__);
1523 if($action == 'save_day') {
1524 $this->db->query("DELETE from eq_attendance where date LIKE '".$year."-".$month."-".$day."'",__LINE__,__FILE__);
1527 foreach ($new_data as $data)
1529 $data_array = explode("-",$data);
1530 $elder = $data_array[0];
1531 $date = "$data_array[1]-$data_array[2]-$data_array[3]";
1532 $this->db->query("INSERT INTO eq_attendance (elder,date) "
1533 . "VALUES (" . $elder . ",'". $date . "')",__LINE__,__FILE__);
1540 $sql = "SELECT * FROM eq_elder where valid=1";
1541 $this->db->query($sql,__LINE__,__FILE__);
1543 while ($this->db->next_record())
1545 $elder_name[$i] = $this->db->f('name');
1546 $elder_id[$i] = $this->db->f('elder');
1549 array_multisort($elder_name, $elder_id);
1551 if($action == 'update_month')
1553 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_update&action=save_month'));
1557 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], 1, $year));
1558 $last_date = explode("-",$sunday_list[0]['date']);
1559 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
1560 $time_limit = mktime(0, 0, 0, $monthnum[$month], 31, $year);
1561 while($last_time <= $time_limit)
1563 $day = date("w",$last_time);
1564 if(date("w",$last_time) == 0) {
1565 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
1566 $last_date = explode("-",$sunday_list[$i]['date']);
1567 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
1568 $sunday_list[$i]['day'] = $last_date[2];
1569 $sunday_list[$i]['month'] = date("M",$last_time);
1570 $sunday_list[$i]['year'] = $last_date[0];
1573 $last_time += 90000;
1574 if($found_sunday) { $i++; $found_sunday=0; }
1577 $this->t->set_var('span', $i);
1578 $this->t->set_var('month',$sunday_list[$i-1]['month']);
1579 $this->t->set_var('year',$sunday_list[$i-1]['year']);
1580 $this->t->fp('list1','month_list',True);
1581 $elder_width=200; $att_width=25; $total_width=$elder_width;
1582 for ($i=0; $i < count($sunday_list); $i++) {
1583 $link_data['menuaction'] = 'eq.eq.att_update';
1584 $link_data['month'] = $sunday_list[$i]['month'];
1585 $link_data['year'] = $sunday_list[$i]['year'];
1586 $link_data['day'] = $sunday_list[$i]['day'];
1587 $link_data['date'] = $sunday_list[$i]['date'];
1588 $link_data['action'] = 'update_day';
1589 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1590 $this->t->set_var('date',$sunday_list[$i]['date']);
1591 $this->t->set_var('day',$sunday_list[$i]['day']);
1592 $this->t->set_var('month',$sunday_list[$i]['month']);
1593 $this->t->set_var('year',$sunday_list[$i]['year']);
1594 $this->t->fp('list2','header_list',True);
1595 $total_width += $att_width;
1599 if($action == 'update_day')
1601 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_update&action=save_day'));
1602 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], $day, $year));
1603 $this->t->set_var('month',$month);
1604 $this->t->set_var('year',$year);
1605 $this->t->fp('list1','month_list',True);
1606 $this->t->set_var('date',$date);
1607 $this->t->set_var('day',$day);
1608 $this->t->set_var('month',$month);
1609 $this->t->set_var('year',$year);
1610 $this->t->fp('list2','header_list',True);
1613 for ($i=0; $i < count($elder_id); $i++) {
1615 $this->nextmatchs->template_alternate_row_color(&$this->t);
1616 $this->t->set_var('elder_name',$elder_name[$i]);
1617 for ($j=0; $j < count($sunday_list); $j++) {
1618 $sql = "SELECT * FROM eq_attendance WHERE date='"
1619 . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i];
1620 $this->db->query($sql,__LINE__,__FILE__);
1621 $value = $elder_id[$i] . "-" . $sunday_list[$j]['date'];
1622 if($this->db->next_record()) {
1623 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'" checked></td>';
1625 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'"></td>';
1628 $this->t->set_var('att_table',$att_table);
1629 $this->t->fp('list3','elder_list',True);
1632 $this->t->set_var('lang_done', 'Cancel');
1633 $this->t->set_var('lang_reset','Clear Form');
1634 $this->t->set_var('lang_save','Save Changes');
1636 $this->t->pfp('out','form');
1637 $this->t->pfp('addhandle','edit');
1639 $this->save_sessiondata();