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 valid=1 and 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 valid=1 and 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 = $j; $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
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 $table_data .= "<tr><td colspan=20><hr></td></tr>";
972 // Now add Elders not assigned to any companionship to the table if we are in eqpresppi mode
973 if($eqpresppi == 1) {
974 $table_data .= "<tr bgcolor=\"#c9c9c9\"><hr><td colspan=20><b>Unassigned Potential Home Teachers</b><hr></td></tr>";
975 foreach($elders as $elder_id => $value) {
976 $sql = "SELECT * FROM eq_companionship where valid=1 and elder=".$elder_id;
977 $this->db->query($sql,__LINE__,__FILE__);
978 if(!$this->db->next_record()) {
979 // We found an Elder not in a companionship, add them to the table
982 $name = $elders[$elder_id];
983 $link_data['menuaction'] = 'eq.eq.ppi_update';
984 $link_data['companionship'] = $companionship;
985 $link_data['interviewer'] = $supervisor;
986 $link_data['elder'] = $elder_id;
987 $link_data['name'] = $name;
988 $link_data['ppi'] = '';
989 $link_data['eqpresppi'] = $eqpresppi;
990 $link_data['action'] = 'add';
991 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
992 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td><a href=$link>$name</a></td>";
993 for($m=$num_months; $m >= 0; $m--) {
994 $year = date('Y') - $m;
995 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
996 $sql = "SELECT * FROM eq_ppi WHERE date > '$year_start' AND date < '$year_end' ".
997 "AND elder=" . $elder_id . " AND eqpresppi=1";
998 $this->db2->query($sql,__LINE__,__FILE__);
999 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
1000 if($this->db2->next_record()) {
1001 $ppis[$m]++; $total_ppis[$m]++;
1002 $link_data['menuaction'] = 'eq.eq.ppi_update';
1003 $link_data['companionship'] = $companionship;
1004 $link_data['interviewer'] = $supervisor;
1005 $link_data['elder'] = $elder_id;
1006 $link_data['name'] = $name;
1007 $link_data['ppi'] = $this->db2->f('ppi');
1008 $link_data['eqpresppi'] = $eqpresppi;
1009 $link_data['action'] = 'view';
1010 $date = $this->db2->f('date');
1011 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1012 $table_data .= '<td align=center><a href='.$link.'><img src="checkmark.gif"><br>'.$date.'</a></td>';
1014 else { $table_data .= "<td> </td>"; }
1016 $table_data .= "</tr>";
1020 $total_companionships += $num_companionships;
1021 if($eqpresppi == 1) {
1022 $stat_data = "<tr><td><b><font size=-2>$num_elders Elders<br>PPI Totals:</font></b></td>";
1024 $stat_data = "<tr><td><b><font size=-2>$num_companionships Companionships<br>PPI Totals:</font></b></td>";
1026 for($m=$num_months; $m >=0; $m--) {
1027 if($eqpresppi == 1) { $percent = ceil(($ppis[$m] / $num_elders)*100); }
1028 else { $percent = ceil(($ppis[$m] / $num_companionships)*100); }
1029 $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
1031 $stat_data .= "</tr>";
1033 $this->t->set_var('table_width',$table_width);
1034 $this->t->set_var('header_row',$header_row);
1035 $this->t->set_var('table_data',$table_data);
1036 $this->t->set_var('stat_data',$stat_data);
1037 $this->t->fp('list','district_list',True);
1040 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>PPI Totals:</font></b></td>";
1041 for($m=$num_months; $m >=0; $m--) {
1042 $percent = ceil(($total_ppis[$m] / $total_companionships)*100);
1043 $totals .= "<td align=center><font size=-2><b>$total_ppis[$m]<br>$percent%</font></b></td>";
1047 $this->t->set_var('totals',$totals);
1048 $this->t->pfp('out','ppi_view_t');
1049 $this->save_sessiondata();
1052 function ppi_update()
1054 $this->t->set_file(array('form' => 'ppi_update.tpl'));
1055 $this->t->set_block('form','interviewer_list','int_list');
1056 $this->t->set_block('form','add','addhandle');
1057 $this->t->set_block('form','edit','edithandle');
1059 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
1060 $this->t->set_var('readonly','');
1061 $this->t->set_var('disabled','');
1063 $action = get_var('action',array('GET','POST'));
1064 $companionship = get_var('companionship',array('GET','POST'));
1065 $interviewer = get_var('interviewer',array('GET','POST'));
1066 $name = get_var('name',array('GET','POST'));
1067 $ppi = get_var('ppi',array('GET','POST'));
1068 $elder = get_var('elder',array('GET','POST'));
1069 $date = get_var('date',array('GET','POST'));
1070 $notes = get_var('notes',array('GET','POST'));
1071 $eqpresppi = get_var('eqpresppi',array('GET','POST'));
1073 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
1074 $this->db->query($sql,__LINE__,__FILE__);
1075 while ($this->db->next_record())
1077 $supervisor = $this->db->f('supervisor');
1078 $sql = "SELECT * FROM eq_elder WHERE elder=" . $supervisor;
1079 $this->db2->query($sql,__LINE__,__FILE__);
1080 $this->db2->next_record();
1081 $interviewer_name = $this->db2->f('name');
1083 if($supervisor == $interviewer) {
1084 $this->t->set_var('interviewer',$supervisor . ' selected');
1086 $this->t->set_var('interviewer',$interviewer);
1088 $this->t->set_var('interviewer_name',$interviewer_name);
1089 $this->t->fp('int_list','interviewer_list',True);
1092 if($action == 'save')
1094 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
1095 $this->db->query("UPDATE eq_ppi set " .
1096 " ppi='" . $ppi . "'" .
1097 ", interviewer='" . $interviewer . "'" .
1098 ", elder='" . $elder . "'" .
1099 ", date='" . $date . "'" .
1100 ", notes='" . $notes . "'" .
1101 ", eqpresppi='" . $eqpresppi . "'" .
1102 " WHERE ppi=" . $ppi,__LINE__,__FILE__);
1107 if($action == 'insert')
1109 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
1110 $this->db->query("INSERT INTO eq_ppi (interviewer,elder,date,notes,eqpresppi) "
1111 . "VALUES ('" . $interviewer . "','" . $elder . "','"
1112 . $date . "','" . $notes . "','" . $eqpresppi ."')",__LINE__,__FILE__);
1117 if($action == 'add')
1119 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
1120 $this->t->set_var('ppi', '');
1121 $this->t->set_var('interviewer', $interviewer);
1122 $this->t->set_var('name',$name);
1123 $this->t->set_var('elder',$elder);
1124 $this->t->set_var('date','');
1125 $this->t->set_var('notes','');
1126 $this->t->set_var('eqpresppi',$eqpresppi);
1127 $this->t->set_var('lang_done','Cancel');
1128 $this->t->set_var('lang_action','Adding New PPI');
1129 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
1130 . $ppi . '&action=' . 'insert'));
1133 if($action == 'edit' || $action == 'view')
1135 $sql = "SELECT * FROM eq_ppi WHERE ppi=".$ppi;
1136 $this->db->query($sql,__LINE__,__FILE__);
1137 $this->db->next_record();
1138 $this->t->set_var('ppi',$ppi);
1139 $this->t->set_var('name',$name);
1140 $this->t->set_var('interviewer', $this->db->f('interviewer'));
1141 $this->t->set_var('elder',$this->db->f('elder'));
1142 $this->t->set_var('date',$this->db->f('date'));
1143 $this->t->set_var('notes',$this->db->f('notes'));
1144 $this->t->set_var('eqpresppi',$this->db->f('eqpresppi'));
1147 if($action == 'edit')
1149 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
1150 $this->t->set_var('lang_done','Cancel');
1151 $this->t->set_var('lang_action','Editing PPI');
1152 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
1153 . $ppi . '&action=' . 'save'));
1156 if($action == 'view')
1158 $date = $this->db->f('date');
1159 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
1160 $this->t->set_var('readonly','READONLY');
1161 $this->t->set_var('disabled','DISABLED');
1162 $this->t->set_var('lang_done','Done');
1163 $this->t->set_var('lang_action','Viewing PPI');
1164 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
1165 . $ppi . '&action=' . 'edit'));
1168 $this->t->set_var('lang_reset','Clear Form');
1169 $this->t->set_var('lang_add','Add PPI');
1170 $this->t->set_var('lang_save','Save Changes');
1171 $this->t->set_var('edithandle','');
1172 $this->t->set_var('addhandle','');
1174 $this->t->pfp('out','form');
1176 if($action == 'view') { $this->t->set_var('lang_save','Edit PPI'); }
1177 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
1178 if($action == 'add') { $this->t->pfp('addhandle','add'); }
1180 $this->save_sessiondata();
1185 $this->t->set_file(array('vis_view_t' => 'vis_view.tpl'));
1186 $this->t->set_block('vis_view_t','visit_list','list1');
1187 $this->t->set_block('vis_view_t','family_list','list2');
1189 $this->t->set_var('lang_name','Family Name');
1190 $this->t->set_var('lang_date','Date');
1192 $sql = "SELECT * FROM eq_visit WHERE companionship=0 ORDER BY date DESC";
1193 $this->db->query($sql,__LINE__,__FILE__);
1194 $total_records = $this->db->num_rows();
1197 while ($this->db->next_record())
1199 $visit_list[$i]['visit'] = $this->db->f('visit');
1200 $visit_list[$i]['family'] = $this->db->f('family');
1201 $visit_list[$i]['date'] = $this->db->f('date');
1205 for ($i=0; $i < count($visit_list); $i++)
1207 $this->nextmatchs->template_alternate_row_color(&$this->t);
1209 $sql = "SELECT * FROM eq_family WHERE family=".$visit_list[$i]['family'];
1210 $this->db->query($sql,__LINE__,__FILE__);
1211 $this->db->next_record();
1213 $this->t->set_var('family',$visit_list[$i]['family']);
1214 $this->t->set_var('family_name',$this->db->f('name'));
1215 $this->t->set_var('date',$visit_list[$i]['date']);
1217 $link_data['menuaction'] = 'eq.eq.vis_update';
1218 $link_data['visit'] = $visit_list[$i]['visit'];
1219 $link_data['name'] = $this->db->f('name');
1220 $link_data['date'] = $visit_list[$i]['date'];
1221 $link_data['action'] = 'view';
1222 $this->t->set_var('view',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1223 $this->t->set_var('lang_view','View');
1225 $link_data['menuaction'] = 'eq.eq.vis_update';
1226 $link_data['visit'] = $visit_list[$i]['visit'];
1227 $link_data['name'] = $this->db->f('name');
1228 $link_data['date'] = $visit_list[$i]['date'];
1229 $link_data['action'] = 'edit';
1230 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1231 $this->t->set_var('lang_edit','Edit');
1233 $this->t->fp('list1','visit_list',True);
1236 // List the families that are available to record a visit against
1237 $sql = "SELECT * FROM eq_family WHERE valid=1";
1238 $this->db->query($sql,__LINE__,__FILE__);
1239 $total_records = $this->db->num_rows();
1242 while ($this->db->next_record())
1244 $family_names[$i] = $this->db->f('name');
1245 $family_ids[$i] = $this->db->f('family');
1247 } array_multisort($family_names, $family_ids);
1249 for ($i=0; $i < count($family_names); $i++)
1251 $link_data['menuaction'] = 'eq.eq.vis_update';
1252 $link_data['visit'] = '';
1253 $link_data['family'] = $family_ids[$i];
1254 $link_data['action'] = 'add';
1255 $link_data['name'] = $family_names[$i];
1256 $this->t->set_var('add',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1258 $this->t->set_var('name',$family_names[$i]);
1259 if(($i+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
1260 else { $this->t->set_var('table_sep',"</td>"); }
1261 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
1263 $this->t->fp('list2','family_list',True);
1266 $this->t->pfp('out','vis_view_t');
1267 $this->save_sessiondata();
1270 function vis_update()
1272 $this->t->set_file(array('form' => 'vis_update.tpl'));
1273 $this->t->set_block('form','add','addhandle');
1274 $this->t->set_block('form','edit','edithandle');
1276 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
1277 $this->t->set_var('readonly','');
1278 $this->t->set_var('disabled','');
1280 $action = get_var('action',array('GET','POST'));
1281 $visit = get_var('visit',array('GET','POST'));
1282 $family = get_var('family',array('GET','POST'));
1283 $name = get_var('name',array('GET','POST'));
1284 $date = get_var('date',array('GET','POST'));
1285 $notes = get_var('notes',array('GET','POST'));
1288 if($action == 'save')
1290 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
1291 $this->db->query("UPDATE eq_visit set " .
1292 " date='" . $date . "'" .
1293 ", notes='" . $notes . "'" .
1294 " WHERE visit=" . $visit,__LINE__,__FILE__);
1299 if($action == 'insert')
1301 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
1302 $this->db->query("INSERT INTO eq_visit (family,companionship,date,notes) "
1303 . "VALUES ('" . $family . "','" . $companionship . "','"
1304 . $date . "','" . $notes . "')",__LINE__,__FILE__);
1309 if($action == 'add')
1311 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
1312 $this->t->set_var('family', $family);
1313 $this->t->set_var('visit', '');
1314 $this->t->set_var('name', $name);
1315 $this->t->set_var('date','');
1316 $this->t->set_var('notes','');
1317 $this->t->set_var('lang_done','Cancel');
1318 $this->t->set_var('lang_action','Adding New Visit');
1319 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&family='
1320 . $family . '&action=' . 'insert'));
1323 if($action == 'edit' || $action == 'view')
1325 $sql = "SELECT * FROM eq_visit WHERE visit=".$visit;
1326 $this->db->query($sql,__LINE__,__FILE__);
1327 $this->db->next_record();
1328 $this->t->set_var('visit',$visit);
1329 $this->t->set_var('name',$name);
1330 $this->t->set_var('family', $family);
1331 $this->t->set_var('date',$this->db->f('date'));
1332 $this->t->set_var('notes',$this->db->f('notes'));
1335 if($action == 'edit')
1337 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
1338 $this->t->set_var('lang_done','Cancel');
1339 $this->t->set_var('lang_action','Editing Visit');
1340 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&visit='
1341 . $visit . '&action=' . 'save'));
1344 if($action == 'view')
1346 $date = $this->db->f('date');
1347 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
1348 $this->t->set_var('readonly','READONLY');
1349 $this->t->set_var('disabled','DISABLED');
1350 $this->t->set_var('lang_done','Done');
1351 $this->t->set_var('lang_action','Viewing Visit');
1352 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&visit='
1353 . $visit . '&action=' . 'edit'));
1356 $this->t->set_var('lang_reset','Clear Form');
1357 $this->t->set_var('lang_add','Add Visit');
1358 $this->t->set_var('lang_save','Save Changes');
1359 $this->t->set_var('edithandle','');
1360 $this->t->set_var('addhandle','');
1362 $this->t->pfp('out','form');
1364 if($action == 'view') { $this->t->set_var('lang_save','Edit Visit'); }
1365 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
1366 if($action == 'add') { $this->t->pfp('addhandle','add'); }
1368 $this->save_sessiondata();
1373 $this->t->set_file(array('att_view_t' => 'att_view.tpl'));
1374 $this->t->set_block('att_view_t','act_list','list');
1376 $this->t->set_block('att_view_t','month_list','list1');
1377 $this->t->set_block('att_view_t','header_list','list2');
1378 $this->t->set_block('att_view_t','elder_list','list3');
1380 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_view'));
1381 $num_months = get_var('num_months',array('GET','POST'));
1382 if($num_months == '') { $num_months = $this->default_att_num_months; }
1383 $this->t->set_var('num_months',$num_months);
1384 $this->t->set_var('lang_filter','Filter');
1385 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
1386 else { $this->t->set_var('lang_num_months','Months of History'); }
1388 $sql = "SELECT * FROM eq_elder where valid=1";
1389 $this->db->query($sql,__LINE__,__FILE__);
1391 while ($this->db->next_record())
1393 $elder_name[$i] = $this->db->f('name');
1394 $elder_id[$i] = $this->db->f('elder');
1397 array_multisort($elder_name, $elder_id);
1400 // Create a list of sunday dates for a window of 3 months back and current month
1404 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, date("m")-$num_months, 1, date("y")));
1405 $last_date = explode("-",$sunday_list[0]['date']);
1406 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
1407 $time_limit = mktime(0, 0, 0, date("m"), date("t"), date("y"));
1408 while($last_time < $time_limit)
1410 $day = date("w",$last_time);
1411 if(date("w",$last_time) == 0) {
1412 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
1413 $last_date = explode("-",$sunday_list[$i]['date']);
1414 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
1415 $sunday_list[$i]['day'] = $last_date[2];
1416 $sunday_list[$i]['month'] = date("M",$last_time);
1417 $sunday_list[$i]['year'] = $last_date[0];
1420 $last_time += 90000;
1421 if($found_sunday) { $i++; $found_sunday=0; }
1424 $old_month=$sunday_list[0]['month']; $span=0;
1425 for ($i=0; $i < count($sunday_list); $i++) {
1426 $date = $sunday_list[$i]['date'];
1427 $this->t->set_var('date',$sunday_list[$i]['date']);
1428 $this->t->set_var('day',$sunday_list[$i]['day']);
1429 if(($old_month != $sunday_list[$i]['month']) || $i == count($sunday_list)-1) {
1430 if($i == count($sunday_list)-1) { $span++; }
1431 $cur_month = $sunday_list[$i]['month'];
1432 $old_month = $sunday_list[$i]['month'];
1433 $link_data['menuaction'] = 'eq.eq.att_update';
1434 $link_data['month'] = $sunday_list[$i-1]['month'];
1435 $link_data['year'] = $sunday_list[$i-1]['year'];
1436 $link_data['action'] = 'update_month';
1437 $this->t->set_var('update_month',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1438 $this->t->set_var('month',$sunday_list[$i-1]['month']);
1439 $this->t->set_var('year',$sunday_list[$i-1]['year']);
1440 $this->t->set_var('span',$span); $span=0;
1441 $this->t->fp('list1','month_list',True);
1445 $elder_width=200; $att_width=25; $total_width=$elder_width;
1446 for ($i=0; $i < count($sunday_list); $i++) {
1447 $link_data['menuaction'] = 'eq.eq.att_update';
1448 $link_data['month'] = $sunday_list[$i]['month'];
1449 $link_data['year'] = $sunday_list[$i]['year'];
1450 $link_data['day'] = $sunday_list[$i]['day'];
1451 $link_data['date'] = $sunday_list[$i]['date'];
1452 $link_data['action'] = 'update_day';
1453 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1454 $this->t->set_var('date',$sunday_list[$i]['date']);
1455 $this->t->set_var('day',$sunday_list[$i]['day']);
1456 $this->t->set_var('month',$sunday_list[$i]['month']);
1457 $this->t->set_var('year',$sunday_list[$i]['year']);
1458 $this->t->fp('list2','header_list',True);
1459 $total_width += $att_width;
1462 for ($i=0; $i < count($elder_id); $i++) {
1464 $this->nextmatchs->template_alternate_row_color(&$this->t);
1465 $this->t->set_var('elder_name',$elder_name[$i]);
1466 #print "checking for elder: " . $elder_id[$i] . "<br>";
1467 for ($j=0; $j < count($sunday_list); $j++) {
1468 #print "checking for date: " . $sunday_list[$j]['date'] . "<br>";
1469 #print "SELECT * FROM eq_attendance WHERE date='"
1470 # . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i] . "<br>";
1471 $sql = "SELECT * FROM eq_attendance WHERE date='"
1472 . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i];
1473 $this->db->query($sql,__LINE__,__FILE__);
1474 if($this->db->next_record()) {
1475 $att_table .= '<td align=center><img src="checkmark.gif"></td>';
1477 $att_table .= '<td> </td>';
1480 $this->t->set_var('att_table',$att_table);
1481 $this->t->fp('list3','elder_list',True);
1483 $this->t->set_var('total_width',$total_width);
1484 $this->t->set_var('elder_width',$elder_width);
1485 $this->t->set_var('att_width',$att_width);
1487 $this->t->pfp('out','att_view_t');
1488 $this->save_sessiondata();
1491 function att_update()
1493 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
1494 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
1495 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
1497 $this->t->set_file(array('form' => 'att_update.tpl'));
1498 $this->t->set_block('form','edit','edithandle');
1500 $this->t->set_block('form','month_list','list1');
1501 $this->t->set_block('form','header_list','list2');
1502 $this->t->set_block('form','elder_list','list3');
1504 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_view'));
1506 $action = get_var('action',array('GET','POST'));
1507 $month = get_var('month',array('GET','POST'));
1508 $year = get_var('year',array('GET','POST'));
1509 $day = get_var('day',array('GET','POST'));
1510 $date = get_var('date',array('GET','POST'));
1512 if($action == 'save_month' || $action == 'save_day')
1514 $new_data = get_var('elders_attended',array('POST'));
1515 $month = $monthnum[$month]; if($month < 10) { $month = "0" . $month; }
1517 if($action == 'save_month') {
1518 $this->db->query("DELETE from eq_attendance where date LIKE '".$year."-".$month."-%'",__LINE__,__FILE__);
1521 if($action == 'save_day') {
1522 $this->db->query("DELETE from eq_attendance where date LIKE '".$year."-".$month."-".$day."'",__LINE__,__FILE__);
1525 foreach ($new_data as $data)
1527 $data_array = explode("-",$data);
1528 $elder = $data_array[0];
1529 $date = "$data_array[1]-$data_array[2]-$data_array[3]";
1530 $this->db->query("INSERT INTO eq_attendance (elder,date) "
1531 . "VALUES (" . $elder . ",'". $date . "')",__LINE__,__FILE__);
1538 $sql = "SELECT * FROM eq_elder where valid=1";
1539 $this->db->query($sql,__LINE__,__FILE__);
1541 while ($this->db->next_record())
1543 $elder_name[$i] = $this->db->f('name');
1544 $elder_id[$i] = $this->db->f('elder');
1547 array_multisort($elder_name, $elder_id);
1549 if($action == 'update_month')
1551 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_update&action=save_month'));
1555 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], 1, $year));
1556 $last_date = explode("-",$sunday_list[0]['date']);
1557 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
1558 $time_limit = mktime(0, 0, 0, $monthnum[$month], 31, $year);
1559 while($last_time <= $time_limit)
1561 $day = date("w",$last_time);
1562 if(date("w",$last_time) == 0) {
1563 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
1564 $last_date = explode("-",$sunday_list[$i]['date']);
1565 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
1566 $sunday_list[$i]['day'] = $last_date[2];
1567 $sunday_list[$i]['month'] = date("M",$last_time);
1568 $sunday_list[$i]['year'] = $last_date[0];
1571 $last_time += 90000;
1572 if($found_sunday) { $i++; $found_sunday=0; }
1575 $this->t->set_var('span', $i);
1576 $this->t->set_var('month',$sunday_list[$i-1]['month']);
1577 $this->t->set_var('year',$sunday_list[$i-1]['year']);
1578 $this->t->fp('list1','month_list',True);
1579 $elder_width=200; $att_width=25; $total_width=$elder_width;
1580 for ($i=0; $i < count($sunday_list); $i++) {
1581 $link_data['menuaction'] = 'eq.eq.att_update';
1582 $link_data['month'] = $sunday_list[$i]['month'];
1583 $link_data['year'] = $sunday_list[$i]['year'];
1584 $link_data['day'] = $sunday_list[$i]['day'];
1585 $link_data['date'] = $sunday_list[$i]['date'];
1586 $link_data['action'] = 'update_day';
1587 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1588 $this->t->set_var('date',$sunday_list[$i]['date']);
1589 $this->t->set_var('day',$sunday_list[$i]['day']);
1590 $this->t->set_var('month',$sunday_list[$i]['month']);
1591 $this->t->set_var('year',$sunday_list[$i]['year']);
1592 $this->t->fp('list2','header_list',True);
1593 $total_width += $att_width;
1597 if($action == 'update_day')
1599 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_update&action=save_day'));
1600 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], $day, $year));
1601 $this->t->set_var('month',$month);
1602 $this->t->set_var('year',$year);
1603 $this->t->fp('list1','month_list',True);
1604 $this->t->set_var('date',$date);
1605 $this->t->set_var('day',$day);
1606 $this->t->set_var('month',$month);
1607 $this->t->set_var('year',$year);
1608 $this->t->fp('list2','header_list',True);
1611 for ($i=0; $i < count($elder_id); $i++) {
1613 $this->nextmatchs->template_alternate_row_color(&$this->t);
1614 $this->t->set_var('elder_name',$elder_name[$i]);
1615 for ($j=0; $j < count($sunday_list); $j++) {
1616 $sql = "SELECT * FROM eq_attendance WHERE date='"
1617 . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i];
1618 $this->db->query($sql,__LINE__,__FILE__);
1619 $value = $elder_id[$i] . "-" . $sunday_list[$j]['date'];
1620 if($this->db->next_record()) {
1621 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'" checked></td>';
1623 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'"></td>';
1626 $this->t->set_var('att_table',$att_table);
1627 $this->t->fp('list3','elder_list',True);
1630 $this->t->set_var('lang_done', 'Cancel');
1631 $this->t->set_var('lang_reset','Clear Form');
1632 $this->t->set_var('lang_save','Save Changes');
1634 $this->t->pfp('out','form');
1635 $this->t->pfp('addhandle','edit');
1637 $this->save_sessiondata();