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;
28 var $upload_target_path;
31 var $public_functions = array
53 $this->default_ht_num_months = 3;
54 $this->default_ppi_num_months = 3;
55 $this->default_ppi_num_years = 0;
56 $this->default_att_num_months = 3;
57 $this->upload_target_path = "/home/users/eqpres/eq_data/";
58 $this->script_path = "/usr/share/phpgroupware/eq/";
60 $this->db = $GLOBALS['phpgw']->db;
61 $this->db2 = $this->db;
62 $this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
63 $this->t = $GLOBALS['phpgw']->template;
64 $this->account = $GLOBALS['phpgw_info']['user']['account_id'];
65 $this->grants = $GLOBALS['phpgw']->acl->get_grants('eq');
66 $this->grants[$this->account] = PHPGW_ACL_READ + PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE;
68 $this->jscal = CreateObject('phpgwapi.jscalendar'); // before phpgw_header() !!!
69 $this->cal_options = 'daFormat : "%Y-%m-%d",
70 ifFormat : "%Y-%m-%d",
74 $GLOBALS['phpgw_info']['flags']['app_header'] = 'Elders Quorum Tools';
75 $GLOBALS['phpgw']->common->phpgw_header();
77 $this->current_month = `date '+%m'`;
78 $this->current_month = $this->current_month-0; // Make it numeric
79 $this->current_year = `date '+%Y'`;
80 $this->current_year = $this->current_year-0; // Make it numeric
83 $this->display_app_header();
86 function save_sessiondata()
91 function display_app_header()
93 $this->t->set_file(array('eq_header' => 'header.tpl'));
95 if (isset($phpgw_info['user']['preferences']['eq']['eq_font']))
97 $font = $phpgw_info['user']['preferences']['eq']['eq_font'];
104 $this->t->set_var('bg_color',$phpgw_info['theme']['th_bg']);
105 $this->t->set_var('font',$font);
106 $link_data['menuaction'] = 'eq.eq.ht_view';
107 $this->t->set_var('link_hometeaching',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
108 $this->t->set_var('lang_hometeaching','HomeTeaching');
109 $link_data['menuaction'] = 'eq.eq.act_list';
110 $this->t->set_var('link_activity',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
111 $this->t->set_var('lang_activity','Activities');
112 $link_data['menuaction'] = 'eq.eq.par_view';
113 $this->t->set_var('link_participation',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
114 $this->t->set_var('lang_participation','Participation');
115 $link_data['menuaction'] = 'eq.eq.ppi_view';
116 $this->t->set_var('link_ppi',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
117 $this->t->set_var('lang_ppi','PPIs');
118 $link_data['menuaction'] = 'eq.eq.vis_view';
119 $this->t->set_var('link_visit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
120 $this->t->set_var('lang_visit','Visits');
121 $link_data['menuaction'] = 'eq.eq.att_view';
122 $this->t->set_var('link_attendance',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
123 $this->t->set_var('lang_attendance','Attendance');
124 $link_data['menuaction'] = 'eq.eq.dir_view';
125 $this->t->set_var('link_dir',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
126 $this->t->set_var('lang_dir','Directory');
127 $link_data['menuaction'] = 'eq.eq.org_view';
128 $this->t->set_var('link_org',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
129 $this->t->set_var('lang_org','Callings');
130 $link_data['menuaction'] = 'eq.eq.admin';
131 $this->t->set_var('link_admin',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
132 $this->t->set_var('lang_admin','Admin');
134 $this->t->pparse('out','eq_header');
139 $this->t->set_file(array('ht_view_t' => 'ht_view.tpl'));
140 $this->t->set_block('ht_view_t','district_list','list');
142 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
143 $num_months = get_var('num_months',array('GET','POST'));
144 if($num_months == '') { $num_months = $this->default_ht_num_months; }
145 $this->t->set_var('num_months',$num_months);
146 $this->t->set_var('lang_filter','Filter');
147 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
148 else { $this->t->set_var('lang_num_months','Months of History'); }
150 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
151 $this->t->set_var('title','Hometeaching');
153 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
154 $this->db->query($sql,__LINE__,__FILE__);
156 while ($this->db->next_record())
158 $districts[$i]['district'] = $this->db->f('district');
159 $districts[$i]['name'] = $this->db->f('name');
160 $districts[$i]['supervisor'] = $this->db->f('supervisor');
164 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
165 $this->db->query($sql,__LINE__,__FILE__);
167 while ($this->db->next_record())
169 $elder_id[$i] = $this->db->f('elder');
170 $elder_name[$i] = $this->db->f('name');
171 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
174 array_multisort($elder_name, $elder_id);
176 // Make an array mapping elder_ids to elder_names
177 for($i=0; $i < count($elder_id); $i++) {
179 $elders[$id] = $elder_name[$i];
182 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
183 $this->db->query($sql,__LINE__,__FILE__);
184 while ($this->db->next_record())
186 $aaronic_id = $this->db->f('aaronic');
187 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
188 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
192 $this->nextmatchs->template_alternate_row_color(&$this->t);
193 for ($i=0; $i < count($districts); $i++) {
194 $this->t->set_var('district_number',$districts[$i]['district']);
195 $this->t->set_var('district_name',$districts[$i]['name']);
196 $supervisor = $districts[$i]['supervisor'];
197 $unique_companionships='';
199 // Select all the unique companionship numbers for this district
200 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $districts[$i]['district'];
201 $this->db->query($sql,__LINE__,__FILE__);
203 while ($this->db->next_record())
205 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
209 $comp_width=450; $visit_width=25; $table_width=$comp_width + $num_months*$visit_width;
210 $table_data=""; $num_companionships = 0; $num_families = 0;
211 for($m=$num_months; $m >= 0; $m--) { $visits[$m] = 0; }
212 for ($j=0; $j < count($unique_companionships); $j++) {
213 $companion_table_entry = "";
214 // Select all the companions in each companionship
215 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
216 "companionship=". $unique_companionships[$j]['companionship'];
217 $this->db->query($sql,__LINE__,__FILE__);
219 while ($this->db->next_record())
221 // Get this companions information
222 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
223 $companionship = $this->db->f('companionship');
224 $elder_id = $this->db->f('elder');
225 $aaronic_id = $this->db->f('aaronic');
227 $name = $elders[$elder_id];
228 $phone = $elder_phone[$elder_id];
230 else if($aaronic_id) {
231 $name = $aaronic[$aaronic_id]['name'];
232 $phone = $aaronic[$aaronic_id]['phone'];
234 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
236 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
238 // Get the names of the families assigned this home teaching companionship
239 $sql = "SELECT * from eq_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
240 $sql = $sql . " ORDER BY name ASC";
241 $this->db->query($sql,__LINE__,__FILE__);
243 while ($this->db->next_record())
245 $num_families++; $total_families++;
246 $family_name = $this->db->f('name');
247 $family_id = $this->db->f('family');
248 $this->nextmatchs->template_alternate_row_color(&$this->t);
249 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
250 // Find out how many times Visits were performed by this companionship
251 // in the past $num_months for this Family
252 $header_row="<th width=$comp_width><font size=-2>Families</th>";
253 for($m=$num_months; $m >= 0; $m--) {
254 $month = $this->current_month - $m;
255 $year = $this->current_year;
256 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
257 if($month < 10) { $month = "0"."$month"; }
258 $month_start = "$year"."-"."$month"."-"."01";
259 $month_end = "$year"."-"."$month"."-"."31";
260 $month = "$month"."/"."$year";
261 //print "m: $m month: $month year: $year month_start: $month_start month_end: $month_end<br>";
262 // Add this to the query to filter on only visits made by this companionship:
263 // " AND companionship=" . $unique_companionships[$j]['companionship'].
264 $sql = "SELECT * FROM eq_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
265 " AND companionship!=0".
266 " AND family=". $family_id;
267 $this->db2->query($sql,__LINE__,__FILE__);
268 $link_data['menuaction'] = 'eq.eq.ht_update';
269 $link_data['date'] = $month_start;
270 $link_data['month_start'] = $month_start;
271 $link_data['month_end'] = $month_end;
272 $link_data['month'] = $month;
273 $link_data['district'] = $districts[$i]['district'];
274 $link_data['district_name'] = $districts[$i]['name'];
275 $link_data['action'] = 'view';
276 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
277 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
278 if(!$total_visits[$m]) { $total_visits[$m] = 0; }
279 if($this->db2->next_record()) {
280 if($this->db2->f('visited') == 'y') {
281 $visits[$m]++; $total_visits[$m]++;
282 $table_data .= '<td align=center><a href="'.$link.'"><img src="checkmark.gif"></a></td>';
284 else if($this->db2->f('visited') == 'n') {
285 $table_data .= '<td align=center><a href="'.$link.'"><img src="x.gif"></a></td>';
288 $visits[$m]++; $total_visits[$m]++;
289 $table_data .= "<td> </td>";
293 $visits[$m]++; $total_visits[$m]++;
294 $table_data .= "<td> </td>";
297 $table_data .= "</tr>";
300 $table_data .= "<tr><td colspan=20></td></tr>";
302 $table_data .= "<tr><td colspan=20><hr></td></tr>";
303 $stat_data = "<tr><td><b><font size=-2>$num_families Families<br>Visit Totals:</font></b></td>";
305 for($m=$num_months; $m >=0; $m--) {
306 $percent = ceil(($visits[$m] / $num_families)*100);
307 $stat_data .= "<td align=center><font size=-2><b>$visits[$m]<br>$percent%</font></b></td>";
309 $stat_data .= "</tr>";
311 $this->t->set_var('table_width',$table_width);
312 $this->t->set_var('header_row',$header_row);
313 $this->t->set_var('table_data',$table_data);
314 $this->t->set_var('stat_data',$stat_data);
315 $this->t->fp('list','district_list',True);
318 $totals = "<tr><td><b><font size=-2>$total_families Total Families<br>Visit Totals:</font></b></td>";
319 for($m=$num_months; $m >=0; $m--) {
320 $percent = ceil(($total_visits[$m] / $total_families)*100);
321 $totals .= "<td align=center><font size=-2><b>$total_visits[$m]<br>$percent%</font></b></td>";
325 $this->t->set_var('totals',$totals);
327 $this->t->pfp('out','ht_view_t');
328 $this->save_sessiondata();
334 $this->t->set_file(array('ht_update_t' => 'ht_update.tpl'));
335 $this->t->set_block('ht_update_t','district_list','list');
336 $this->t->set_block('ht_update_t','save','savehandle');
338 $district = get_var('district',array('GET','POST'));
339 $district_name = get_var('district_name',array('GET','POST'));
340 $date = get_var('date',array('GET','POST'));
341 $month = get_var('month',array('GET','POST'));
342 $month_start = get_var('month_start',array('GET','POST'));
343 $month_end = get_var('month_end',array('GET','POST'));
344 $action = get_var('action',array('GET','POST'));
346 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
347 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_update&action=save'));
348 $this->t->set_var('lang_done','Cancel');
349 $this->t->set_var('district_name',$district_name);
350 $this->t->set_var('district_number',$district);
351 $this->t->set_var('title','Hometeaching Update ' . $month);
352 $this->t->set_var('date',$date);
354 if($action == 'save')
356 // Get a list of all the companionships in this district
357 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $district;
358 $this->db->query($sql,__LINE__,__FILE__);
360 while ($this->db->next_record())
362 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
365 for ($j=0; $j < count($unique_companionships); $j++)
367 // FIXME: We won't be able to go back and edit history on families that have been
368 // reassigned to a different companionship. The following delete command will not delete
369 // the history of visits under an older companionship, only the ones for the existing
370 // companionship. This will lead to duplicate visits being entered for an older
371 // month for the same family, making it impossible to change the past history once
372 // a family is reassigned. However, you will be able to view the history just fine.
374 //$comp=$unique_companionships[$j]['companionship'];
375 //print "deleting from eq_visit where companionship=$comp and date=$date and district=$district<br>";
376 // Delete all the visits that have taken place for all families for this month
377 $this->db->query("DELETE from eq_visit where companionship=" . $unique_companionships[$j]['companionship'] .
378 " AND " . "date='" . $date . "'",__LINE__,__FILE__);
381 // Now, add the visits that are checked for this month
382 $new_data = get_var('family_visited',array('POST'));
383 foreach ($new_data as $family)
385 foreach ($family as $data)
387 //print "family_visited: $data <br>";
388 $data_array = explode("/",$data);
389 $family_id = $data_array[0];
390 $companionship = $data_array[1];
391 $date = $data_array[2];
392 $visited = $data_array[3];
393 if($visited == "") { $visited = $data_array[4]; }
394 //print "family_id: $family_id companionship: $companionship date: $date visited: $visited<br>";
395 $this->db->query("INSERT INTO eq_visit (family,companionship,date,notes,visited) "
396 . "VALUES (" . $family_id .",". $companionship .",'". $date ."','','". $visited ."')",__LINE__,__FILE__);
403 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
404 $this->db->query($sql,__LINE__,__FILE__);
406 while ($this->db->next_record())
408 $elder_id[$i] = $this->db->f('elder');
409 $elder_name[$i] = $this->db->f('name');
410 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
413 array_multisort($elder_name, $elder_id);
415 // Make an array mapping elder_ids to elder_names
416 for($i=0; $i < count($elder_id); $i++) {
418 $elders[$id] = $elder_name[$i];
421 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
422 $this->db->query($sql,__LINE__,__FILE__);
423 while ($this->db->next_record())
425 $aaronic_id = $this->db->f('aaronic');
426 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
427 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
430 // Select all the unique companionship numbers for this district
431 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $district;
432 $this->db->query($sql,__LINE__,__FILE__);
433 $j=0; $unique_companionships='';
434 while ($this->db->next_record())
436 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
440 $comp_width=300; $visit_width=25; $table_width=$comp_width + $visit_width;
441 $table_data=""; $num_companionships = 0; $num_families = 0; $visits=0;
442 for ($j=0; $j < count($unique_companionships); $j++) {
443 $companion_table_entry = "";
444 // Select all the companions in each companionship
445 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
446 "companionship=". $unique_companionships[$j]['companionship'];
447 $this->db->query($sql,__LINE__,__FILE__);
449 while ($this->db->next_record())
451 // Get this companions information
452 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
453 $companionship = $this->db->f('companionship');
454 $elder_id = $this->db->f('elder');
455 $aaronic_id = $this->db->f('aaronic');
457 $name = $elders[$elder_id];
458 $phone = $elder_phone[$elder_id];
460 else if($aaronic_id) {
461 $name = $aaronic[$aaronic_id]['name'];
462 $phone = $aaronic[$aaronic_id]['phone'];
464 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
466 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
468 // Get the names of the families assigned this home teaching companionship
469 $sql = "SELECT * from eq_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
470 $sql = $sql . " ORDER BY name ASC";
471 $this->db->query($sql,__LINE__,__FILE__);
472 while ($this->db->next_record())
474 $num_families++; $total_families++;
475 $family_name = $this->db->f('name');
476 $family_id = $this->db->f('family');
477 $this->nextmatchs->template_alternate_row_color(&$this->t);
478 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
480 $header_row="<th width=$comp_width><font size=-2>Families</th>";
481 $sql = "SELECT * FROM eq_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
482 " AND companionship!=0".
483 " AND family=". $family_id;
484 $this->db2->query($sql,__LINE__,__FILE__);
485 $value = $family_id . "/" . $unique_companionships[$j]['companionship'] . "/" . $date;
486 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
487 if(!$total_visits) { $total_visits = 0; }
488 if($this->db2->next_record()) {
489 if($this->db2->f('visited') == 'y') {
490 $visits++; $total_visits++;
491 $table_data .= '<td width=100 align=center>';
492 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y" checked>Y';
493 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
494 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/"> ';
495 $table_data .= '</td>';
496 } else if($this->db2->f('visited') == 'n') {
497 $table_data .= '<td width=100 align=center>';
498 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
499 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n" checked>N';
500 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/">';
501 $table_data .= '</td>';
503 $table_data .= '<td width=100 align=center>';
504 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
505 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
506 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
507 $table_data .= '</td>';
512 $table_data .= '<td width=100 align=center>';
513 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
514 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
515 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
516 $table_data .= '</td>';
519 $table_data .= "</tr>";
520 $table_data .= "<tr><td colspan=20></td></tr>";
522 $table_data .= "<tr><td colspan=20><hr></td></tr>";
523 $stat_data = "<tr><td><b><font size=-2>$num_families Families<br>Visit Totals:</font></b></td>";
525 $percent = ceil(($visits / $num_families)*100);
526 $stat_data .= "<td align=center><font size=-2><b>$visits<br>$percent%</font></b></td>";
527 $stat_data .= "</tr>";
529 $this->t->set_var('table_width',$table_width);
530 $this->t->set_var('header_row',$header_row);
531 $this->t->set_var('table_data',$table_data);
532 $this->t->set_var('stat_data',$stat_data);
533 $this->t->fp('list','district_list',True);
535 $this->t->set_var('lang_reset','Clear Form');
536 $this->t->set_var('lang_save','Save Changes');
537 $this->t->set_var('savehandle','');
539 $this->t->pfp('out','ht_update_t');
540 $this->t->pfp('addhandle','save');
542 $this->save_sessiondata();
547 $this->t->set_file(array('act_list_t' => 'act_list.tpl'));
548 $this->t->set_block('act_list_t','act_list','list');
550 $this->t->set_var('lang_name','Activity Name');
551 $this->t->set_var('lang_date','Date');
553 $sql = "SELECT * FROM eq_activity ORDER BY date DESC";
554 $this->db->query($sql,__LINE__,__FILE__);
555 $total_records = $this->db->num_rows();
558 while ($this->db->next_record())
560 $activity_list[$i]['name'] = $this->db->f('name');
561 $activity_list[$i]['date'] = $this->db->f('date');
562 $activity_list[$i]['activity'] = $this->db->f('activity');
566 for ($i=0; $i < count($activity_list); $i++)
568 $this->nextmatchs->template_alternate_row_color(&$this->t);
569 $this->t->set_var('name',$activity_list[$i]['name']);
570 $this->t->set_var('date',$activity_list[$i]['date']);
572 $link_data['menuaction'] = 'eq.eq.act_view';
573 $link_data['activity'] = $activity_list[$i]['activity'];
574 $link_data['action'] = 'view';
575 $this->t->set_var('view',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
576 $this->t->set_var('lang_view','View');
578 $link_data['menuaction'] = 'eq.eq.act_update';
579 $link_data['activity'] = $activity_list[$i]['activity'];
580 $link_data['action'] = 'edit';
581 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
582 $this->t->set_var('lang_edit','Edit');
584 $link_data['menuaction'] = 'eq.eq.act_update';
585 $link_data['activity'] = '0';
586 $link_data['action'] = 'add';
587 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/eq/index.php',$link_data)
588 . '"><input type="submit" name="Add" value="' . 'Add Activity' .'"></font></form>');
590 $this->t->fp('list','act_list',True);
593 $this->t->pfp('out','act_list_t');
594 $this->save_sessiondata();
599 $this->t->set_file(array('act_view_t' => 'act_view.tpl'));
600 $this->t->set_block('act_view_t','part_list','list');
602 $sql = "SELECT * FROM eq_activity WHERE activity=" . intval(get_var('activity',array('GET','POST')));
603 $this->db->query($sql,__LINE__,__FILE__);
604 $this->db->next_record();
605 $this->t->set_var('name', $this->db->f('name'));
606 $this->t->set_var('date', $this->db->f('date'));
607 $this->t->set_var('notes', $this->db->f('notes'));
609 $this->t->set_var('lang_name','Activity Name');
610 $this->t->set_var('lang_date','Date');
611 $this->t->set_var('lang_notes','Notes');
612 $this->t->set_var('lang_done','Done');
613 $this->t->set_var('lang_action','View');
615 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
616 $this->t->set_var('tr_color',$tr_color);
618 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_list'));
620 $link_data['menuaction'] = 'eq.eq.act_update';
621 $link_data['activity'] = get_var('activity',array('GET','POST'));
622 $link_data['action'] = 'edit';
623 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
624 $this->t->set_var('lang_edit','Edit');
625 $this->t->set_var('cal_date',$this->db->f('date'));
627 // Now find out which elders participated in this activity
628 $sql = "SELECT * FROM eq_participation WHERE activity=" . intval(get_var('activity',array('GET','POST')));
629 $this->db->query($sql,__LINE__,__FILE__);
630 $total_records = $this->db->num_rows();
633 while ($this->db->next_record())
635 $part_list[$i]['elder'] = $this->db->f('elder');
639 for ($i=0; $i < count($part_list); $i++)
641 $sql = "SELECT * FROM eq_elder WHERE elder=" . $part_list[$i]['elder'];
642 $this->db->query($sql,__LINE__,__FILE__);
643 $this->db->next_record();
644 $names[$i] = $this->db->f('name');
647 for ($i=0; $i < count($names); $i++)
649 //$this->nextmatchs->template_alternate_row_color(&$this->t);
650 $this->t->set_var('elder_name',$names[$i]);
651 if(($i+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
652 else { $this->t->set_var('table_sep',"</td>"); }
653 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
654 $this->t->fp('list','part_list',True);
657 $this->t->pfp('out','act_view_t');
658 $this->save_sessiondata();
661 function act_update()
663 $this->t->set_file(array('form' => 'act_update.tpl'));
664 $this->t->set_block('form','elder_list','list');
665 $this->t->set_block('form','add','addhandle');
666 $this->t->set_block('form','edit','edithandle');
667 $this->t->set_var('lang_done','Done');
669 $action = get_var('action',array('GET','POST'));
670 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_list'));
671 $activity['activity'] = intval(get_var('activity',array('GET','POST')));
673 if($action == 'save')
675 $activity['name'] = $this->db->db_addslashes(get_var('name',array('POST')));
676 $activity['date'] = $this->db->db_addslashes(get_var('date',array('POST')));
677 $activity['notes']= $this->db->db_addslashes(get_var('notes',array('POST')));
678 $this->db->query("UPDATE eq_activity set " .
679 " name='" . $activity['name'] .
680 "', date='" . $activity['date'] . "'" .
681 ", notes='" . $activity['notes'] . "'" .
682 " WHERE activity=" . $activity['activity'],__LINE__,__FILE__);
684 // Delete all the elders who have particiapted in this activity
685 $this->db->query("DELETE from eq_participation where activity=".$activity['activity'],__LINE__,__FILE__);
687 // Re-add the elders who are checked as having participated in this activity
688 $elders = get_var('elder_name',array('POST'));
689 foreach ($elders as $elder)
691 $this->db->query("INSERT INTO eq_participation (elder,activity) "
692 . "VALUES (" . $elder . ",". $activity['activity'] . ")",__LINE__,__FILE__);
699 if($action == 'insert')
701 $activity['name'] = $this->db->db_addslashes(get_var('name',array('POST')));
702 $activity['date'] = $this->db->db_addslashes(get_var('date',array('POST')));
703 $activity['notes']= $this->db->db_addslashes(get_var('notes',array('POST')));
704 $this->db->query("INSERT INTO eq_activity (name,date,notes) "
705 . "VALUES ('" . $activity['name'] . "','"
706 . $activity['date'] . "','" . $activity['notes'] . "')",__LINE__,__FILE__);
713 $activity['activity'] = 0;
714 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
715 $this->t->set_var('name','');
716 $this->t->set_var('date','');
717 $this->t->set_var('notes','');
718 $this->t->set_var('lang_done','Cancel');
719 $this->t->set_var('lang_action','Adding New Activity');
720 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_update&activity='
721 . $activity['activity'] . '&action=' . 'insert'));
724 if($action == 'edit')
726 $sql = "SELECT * FROM eq_activity WHERE activity=" . $activity['activity'];
727 $this->db->query($sql,__LINE__,__FILE__);
728 $this->db->next_record();
729 $this->t->set_var('cal_date',$this->jscal->input('date',$this->db->f('date'),'','','','','',$this->cal_options));
730 $this->t->set_var('name', $this->db->f('name'));
731 $this->t->set_var('date', $this->db->f('date'));
732 $this->t->set_var('notes', $this->db->f('notes'));
733 $this->t->set_var('lang_done','Cancel');
734 $this->t->set_var('lang_action','Editing Activity');
735 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_update&activity='
736 . $activity['activity'] . '&action=' . 'save'));
740 $sql = "SELECT * FROM eq_elder";
741 $this->db->query($sql,__LINE__,__FILE__);
743 while ($this->db->next_record())
745 if($this->db->f('valid') == 1 || $action != 'add') {
746 $elder_name[$i] = $this->db->f('name');
747 $elder_id[$i] = $this->db->f('elder');
748 $elder_valid[$i] = $this->db->f('valid');
752 array_multisort($elder_name, $elder_id, $elder_valid);
755 for ($i=0; $i < count($elder_id); $i++)
757 //$this->nextmatchs->template_alternate_row_color(&$this->t);
758 $sql = "SELECT * FROM eq_participation where activity=". $activity['activity'] . " AND elder=" . $elder_id[$i];
759 $this->db->query($sql,__LINE__,__FILE__);
760 if($this->db->next_record()) { $this->t->set_var('checked','checked'); $checked=1; }
761 else { $this->t->set_var('checked',''); $checked=0; }
762 if($checked || $elder_valid[$i] == 1) {
763 $this->t->set_var('elder_name',$elder_name[$i]);
764 $this->t->set_var('elder',$elder_id[$i]);
765 if(($j+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
766 else { $this->t->set_var('table_sep',"</td>"); }
767 if(($j) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
768 $this->t->fp('list','elder_list',True);
773 $this->t->set_var('lang_reset','Clear Form');
774 $this->t->set_var('lang_add','Add Activity');
775 $this->t->set_var('lang_save','Save Changes');
776 $this->t->set_var('edithandle','');
777 $this->t->set_var('addhandle','');
779 $this->t->pfp('out','form');
780 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
781 if($action == 'add') { $this->t->pfp('addhandle','add'); }
783 $this->save_sessiondata();
788 $this->t->set_file(array('par_view_t' => 'par_view.tpl'));
789 $this->t->set_block('par_view_t','header_list','list1');
790 $this->t->set_block('par_view_t','elder_list','list2');
792 $sql = "SELECT * FROM eq_elder where valid=1";
793 $this->db->query($sql,__LINE__,__FILE__);
795 while ($this->db->next_record())
797 $elder_name[$i] = $this->db->f('name');
798 $elder_id[$i] = $this->db->f('elder');
801 array_multisort($elder_name, $elder_id);
803 $sql = "SELECT * FROM eq_activity ORDER BY date DESC";
804 $this->db->query($sql,__LINE__,__FILE__);
805 $total_records = $this->db->num_rows();
808 while ($this->db->next_record())
810 $activity_list[$i]['name'] = $this->db->f('name');
811 $activity_list[$i]['date'] = $this->db->f('date');
812 $activity_list[$i]['activity'] = $this->db->f('activity');
813 if($activity_list[$i]['date'] == '0000-00-00') { $activity_list[$i]['date']=""; }
817 $elder_width=250; $part_width=25; $act_width=50;
818 $total_width=$elder_width+$part_width;
819 for ($i=0; $i < count($activity_list); $i++) {
820 $this->t->set_var('activity_name',$activity_list[$i]['name']);
821 $this->t->set_var('activity_date',$activity_list[$i]['date']);
822 $this->t->fp('list1','header_list',True);
823 $total_width += $act_width;
826 for ($i=0; $i < count($elder_id); $i++) {
827 $participated=0; $part_table = '';
828 $this->nextmatchs->template_alternate_row_color(&$this->t);
829 $this->t->set_var('elder_name',$elder_name[$i]);
830 for ($j=0; $j < count($activity_list); $j++) {
831 $sql = "SELECT * FROM eq_participation where activity="
832 . $activity_list[$j]['activity'] . " AND elder=" . $elder_id[$i];
833 $this->db->query($sql,__LINE__,__FILE__);
834 if($this->db->next_record()) {
835 $part_table .= '<td align=center><img src="checkmark.gif"></td>';
838 $part_table .= '<td> </td>';
841 if($participated) { $part_table .= '<td align=center><img src="checkmark.gif">'.$participated.'</td>'; }
842 else { $part_table .= '<td> </td>'; }
843 $this->t->set_var('part_table',$part_table);
844 $this->t->fp('list2','elder_list',True);
846 $this->t->set_var('total_width',$total_width);
847 $this->t->set_var('elder_width',$elder_width);
848 $this->t->set_var('part_width',$part_width);
849 $this->t->set_var('act_width',$act_width);
850 $this->t->pfp('out','par_view_t');
851 $this->save_sessiondata();
856 $this->t->set_file(array('ppi_sched_t' => 'ppi_sched.tpl'));
857 $this->t->set_block('ppi_sched_t','elder_list','list');
858 $action = get_var('action',array('GET','POST'));
860 $this->t->set_var('lang_save','Save Priorities & Notes');
861 $this->t->set_var('lang_reset','Clear Changes');
863 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
864 $this->t->set_var('ppi_link_title','Hometeaching PPIs');
866 $this->t->set_var('eqpres_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view&eqpresppi=1'));
867 $this->t->set_var('eqpres_ppi_link_title','EQ President Yearly PPIs');
869 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched'));
870 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
872 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched&action=save'));
873 $this->t->set_var('title','EQ President Yearly PPIs Scheduler');
875 $elder_width=450; $phone_width=25; $pri_width=10; $notes_width=128;
876 $table_width=$elder_width + $phone_width + $pri_width + $notes_width;
877 $header_row = "<th width=$elder_width><font size=-2>Elder Name</th>";
878 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
879 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
880 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
881 $table_data=""; $completed_data=""; $totals_data="";
885 if($action == 'save')
887 $new_data = get_var('ppi_notes',array('POST'));
888 foreach ($new_data as $entry)
890 $ppi_notes = $entry['notes'];
891 $elder_id = $entry['elder_id'];
892 $ppi_pri = $entry['pri'];
894 // Perform database save actions here
895 $this->db->query("UPDATE eq_elder set " .
896 " ppi_notes='" . $ppi_notes . "'" .
897 ",ppi_pri='" . $ppi_pri . "'" .
898 " WHERE elder=" . $elder_id,__LINE__,__FILE__);
902 $take_me_to_url = $GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched');
903 Header('Location: ' . $take_me_to_url);
906 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY ppi_pri ASC";
907 $this->db->query($sql,__LINE__,__FILE__);
909 $total_elders=0; $elders_with_yearly_ppi=0;
913 while ($this->db->next_record())
915 $elder_id[$i] = $this->db->f('elder');
916 $elder_name[$i] = $this->db->f('name');
917 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
918 $elder_ppi_pri[$elder_id[$i]] = $this->db->f('ppi_pri');
919 $elder_ppi_notes[$elder_id[$i]] = $this->db->f('ppi_notes');
924 $max = count($elder_id);
926 for($i=0; $i < $max; $i++) {
928 $name = $elder_name[$i];
929 $phone = $elder_phone[$id];
930 $ppi_pri = $elder_ppi_pri[$id];
931 $ppi_notes = $elder_ppi_notes[$id];
933 // If this elder has had a yearly PPI this year, don't show him on the schedule list
934 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
935 $sql = "SELECT * FROM eq_ppi WHERE date > '$year_start' AND date < '$year_end' ".
936 "AND elder=" . $id . " AND eqpresppi=1";
937 $this->db2->query($sql,__LINE__,__FILE__);
939 if(!$this->db2->next_record()) {
940 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
941 $table_data.= "<td align=center>$phone</td>";
942 //$table_data.= "<td align=center>$ppi_pri</td>";
943 $table_data.= "<td align=center>";
944 $table_data.= '<select name=ppi_notes['.$i.'][pri]>';
945 foreach(range(0,6) as $num) {
946 if($num == 0) { $num = 1; } else {$num = $num*5; }
947 if($ppi_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
948 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
950 $table_data.= '</select></td>';
951 $table_data.= '<td><input type=text size="50" maxlength="128" name="ppi_notes['.$i.'][notes]" value="'.$ppi_notes.'">';
952 $table_data.= '<input type=hidden name="ppi_notes['.$i.'][elder_id]" value="'.$id.'">';
953 $table_data.= '<input type=hidden name="ppi_notes['.$i.'][elder_name]" value="'.$name.'">';
954 $table_data.= '</td>';
955 $table_data.= '</tr>';
956 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
957 $this->t->set_var('tr_color',$tr_color);
959 $elders_with_yearly_ppi++;
960 $date = $this->db2->f('date');
961 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
962 $completed_data.= "<td align=left>$phone</td>";
963 $completed_data.= "<td align=left>$date</td>";
964 $completed_data.= '</tr>';
965 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
966 $this->t->set_var('tr_color2',$tr_color2);
970 $name_width=300; $phone_width=150; $date_width=100;
971 $completed_table_width=$name_width + $phone_width + $date_width;
972 $completed_header_row = "<th width=$name_width><font size=-2>Elder Name</th>";
973 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
974 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
976 $elders_width=300; $totals_width=100;
977 $totals_table_width=$elders_width + $totals_width;
978 $totals_header_row = "<th width=$elders_width><font size=-2>Elders</th>";
979 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
980 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
981 $totals_data.= "<td align=left><font size=-2><b>Total Elders with yearly PPIs completed:</b></font></td>";
982 $totals_data.= "<td align=center><font size=-2><b>$elders_with_yearly_ppi / $total_elders</b></font></td>";
983 $percent = ceil(($elders_with_yearly_ppi / $total_elders)*100);
984 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
985 $this->t->set_var('tr_color',$tr_color);
986 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
987 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
988 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
989 $totals_data.= "</tr>";
991 $this->t->set_var('table_width',$table_width);
992 $this->t->set_var('header_row',$header_row);
993 $this->t->set_var('table_data',$table_data);
994 $this->t->set_var('totals_header_row',$totals_header_row);
995 $this->t->set_var('totals_table_width',$totals_table_width);
996 $this->t->set_var('completed_header_row',$completed_header_row);
997 $this->t->set_var('completed_table_width',$completed_table_width);
998 $this->t->set_var('completed',$completed_data);
999 $this->t->set_var('totals',$totals_data);
1000 $this->t->fp('list','elder_list',True);
1002 $this->t->pfp('out','ppi_sched_t');
1003 $this->save_sessiondata();
1009 $this->t->set_file(array('ppi_view_t' => 'ppi_view.tpl'));
1010 $this->t->set_block('ppi_view_t','district_list','list');
1012 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
1013 $num_months = get_var('num_months',array('GET','POST'));
1014 if($num_months == '') { $num_months = $this->default_ppi_num_months; }
1015 $this->t->set_var('num_months',$num_months);
1016 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
1017 else { $this->t->set_var('lang_num_months','Months of History'); }
1018 $this->t->set_var('lang_filter','Filter');
1019 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
1021 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
1022 $this->t->set_var('ppi_link_title','Hometeaching PPIs');
1024 $this->t->set_var('eqpres_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view&eqpresppi=1'));
1025 $this->t->set_var('eqpres_ppi_link_title','EQ President Yearly PPIs');
1026 $eqpresppi = get_var('eqpresppi',array('GET','POST'));
1028 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched'));
1029 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
1031 if($eqpresppi == 1) {
1032 $this->t->set_var('title','EQ President Yearly PPIs');
1033 $num_months = get_var('num_months',array('GET','POST'));
1034 if($num_months == '') { $num_months = $this->default_ppi_num_years; }
1035 $this->t->set_var('num_months',$num_months);
1036 if($num_months == 1) { $this->t->set_var('lang_num_months','Year of History'); }
1037 else { $this->t->set_var('lang_num_months','Years of History'); }
1040 $this->t->set_var('title','Hometeaching PPIs');
1043 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
1044 $this->db->query($sql,__LINE__,__FILE__);
1046 while ($this->db->next_record())
1048 if(($eqpresppi == 1) && ($this->db->f('district') == 1)) {
1049 $districts[$i]['district'] = $this->db->f('district');
1050 $districts[$i]['name'] = $this->db->f('name');
1051 $districts[$i]['supervisor'] = $this->db->f('supervisor');
1052 } else if($eqpresppi == 0) {
1053 $districts[$i]['district'] = $this->db->f('district');
1054 $districts[$i]['name'] = $this->db->f('name');
1055 $districts[$i]['supervisor'] = $this->db->f('supervisor');
1060 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
1061 $this->db->query($sql,__LINE__,__FILE__);
1063 while ($this->db->next_record())
1065 $elder_id[$i] = $this->db->f('elder');
1066 $elder_name[$i] = $this->db->f('name');
1067 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
1068 $elder_ppi_pri[$elder_id[$i]] = $this->db->f('ppi_pri');
1069 $elder_ppi_notes[$elder_id[$i]] = $this->db->f('ppi_notes');
1072 array_multisort($elder_name, $elder_id);
1073 for($i=0; $i < count($elder_id); $i++) {
1074 $id = $elder_id[$i];
1075 $elders[$id] = $elder_name[$i];
1078 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
1079 $this->db->query($sql,__LINE__,__FILE__);
1080 while ($this->db->next_record())
1082 $aaronic_id = $this->db->f('aaronic');
1083 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
1084 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
1087 $total_companionships = 0;
1088 $this->nextmatchs->template_alternate_row_color(&$this->t);
1089 for ($i=0; $i < count($districts); $i++) {
1090 if($eqpresppi == 1) {
1091 $this->t->set_var('district_number','*');
1092 $this->t->set_var('district_name','EQ President');
1094 $this->t->set_var('district_number',$districts[$i]['district']);
1095 $this->t->set_var('district_name',$districts[$i]['name']);
1097 $supervisor = $districts[$i]['supervisor'];
1098 $unique_companionships='';
1100 // Select all the unique companionship numbers for this district
1101 if($eqpresppi == 1) {
1102 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1";
1105 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $districts[$i]['district'];
1107 $this->db->query($sql,__LINE__,__FILE__);
1109 while ($this->db->next_record())
1111 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
1115 $comp_width=400; $ppi_width=25; $table_width=$comp_width + $num_months*$ppi_width;
1116 $table_data=""; $num_companionships = $j; $num_elders = 0;
1117 for($m=$num_months; $m >= 0; $m--) { $ppis[$m] = 0; }
1118 for ($j=0; $j < count($unique_companionships); $j++) {
1119 // Select all the companions in each companionship
1121 $sql = "SELECT * FROM eq_companionship where valid=1 and aaronic=0 and ".
1122 "companionship=". $unique_companionships[$j]['companionship'];
1125 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
1126 "companionship=". $unique_companionships[$j]['companionship'];
1128 $this->db->query($sql,__LINE__,__FILE__);
1130 $comp = $unique_companionships[$j]['companionship'];
1131 for($m=$num_months; $m >= 0; $m--) { $ppi_recorded[$comp][$m] = 0; }
1132 while ($this->db->next_record())
1134 // Get this companions information
1136 $companionship = $this->db->f('companionship');
1137 $elder_id = $this->db->f('elder');
1138 $aaronic_id = $this->db->f('aaronic');
1140 $name = $elders[$elder_id];
1141 $phone = $elder_phone[$elder_id];
1143 else if($aaronic_id) {
1144 $name = $aaronic[$aaronic_id]['name'];
1145 $phone = $aaronic[$aaronic_id]['phone'];
1147 $link_data['menuaction'] = 'eq.eq.ppi_update';
1148 $link_data['companionship'] = $companionship;
1149 $link_data['interviewer'] = $supervisor;
1150 $link_data['elder'] = $elder_id;
1151 $link_data['aaronic'] = $aaronic_id;
1152 $link_data['name'] = $name;
1153 $link_data['ppi'] = '';
1154 $link_data['eqpresppi'] = $eqpresppi;
1155 $link_data['action'] = 'add';
1156 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1157 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1159 // Find out how many times PPIs were performed in the past $num_months for this Elder
1160 $header_row="<th width=$comp_width><font size=-2>Companionship</th>";
1161 for($m=$num_months; $m >= 0; $m--) {
1162 if($eqpresppi == 1) {
1163 $year = date('Y') - $m;
1164 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
1165 $sql = "SELECT * FROM eq_ppi WHERE date > '$year_start' AND date < '$year_end' ".
1166 "AND elder=" . $elder_id . " AND aaronic=" . $aaronic_id . " AND eqpresppi=1";
1167 $this->db2->query($sql,__LINE__,__FILE__);
1168 $header_row .= "<th width=150><font size=-2>$year</th>";
1171 $month = $this->current_month - $m;
1172 $year = $this->current_year;
1173 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
1174 if($month < 10) { $month = "0"."$month"; }
1175 $month_start = "$year"."-"."$month"."-"."01";
1176 $month_end = "$year"."-"."$month"."-"."31";
1177 $month = "$month"."/"."$year";
1178 $sql = "SELECT * FROM eq_ppi WHERE date >= '$month_start' AND date <= '$month_end' ".
1179 "AND elder=" . $elder_id . " AND aaronic=" . $aaronic_id . " AND eqpresppi=0";
1180 $this->db2->query($sql,__LINE__,__FILE__);
1181 $header_row .= "<th width=$ppi_width><font size=-2>$month</th>";
1183 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
1184 if($this->db2->next_record()) {
1185 if(!$ppi_recorded[$companionship][$m]) {
1186 $ppis[$m]++; $total_ppis[$m]++; $ppi_recorded[$companionship][$m]=1;
1188 $link_data['menuaction'] = 'eq.eq.ppi_update';
1189 $link_data['companionship'] = $companionship;
1190 $link_data['interviewer'] = $this->db2->f('interviewer');
1191 $link_data['elder'] = $elder_id;
1192 $link_data['aaronic'] = $aaronic_id;
1193 $link_data['name'] = $name;
1194 $link_data['ppi'] = $this->db2->f('ppi');
1195 $link_data['eqpresppi'] = $eqpresppi;
1196 $link_data['action'] = 'view';
1197 $date = $this->db2->f('date');
1198 $date_array = explode("-",$date);
1199 $month = $date_array[1];
1200 $day = $date_array[2];
1201 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1202 $table_data .= '<td align=center><a href='.$link.'><img src="checkmark.gif"><br>'.$month.'-'.$day.'</a></td>';
1204 else { $table_data .= "<td> </td>"; }
1206 $table_data .= "</tr>";
1209 $table_data .= "<tr><td colspan=20><hr></td></tr>";
1211 // Now add Elders not assigned to any companionship to the table if we are in eqpresppi mode
1212 if($eqpresppi == 1) {
1213 $table_data .= "<tr bgcolor=\"#c9c9c9\"><td colspan=20><b>Unassigned Potential Home Teachers</b><hr></td></tr>";
1214 foreach($elders as $elder_id => $value) {
1215 $sql = "SELECT * FROM eq_companionship where valid=1 and elder=".$elder_id;
1216 $this->db->query($sql,__LINE__,__FILE__);
1217 if(!$this->db->next_record()) {
1218 // We found an Elder not in a companionship, add them to the table
1221 $name = $elders[$elder_id];
1222 $link_data['menuaction'] = 'eq.eq.ppi_update';
1223 $link_data['companionship'] = $companionship;
1224 $link_data['interviewer'] = $supervisor;
1225 $link_data['elder'] = $elder_id;
1226 $link_data['name'] = $name;
1227 $link_data['ppi'] = '';
1228 $link_data['eqpresppi'] = $eqpresppi;
1229 $link_data['action'] = 'add';
1230 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1231 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td><a href=$link>$name</a></td>";
1232 for($m=$num_months; $m >= 0; $m--) {
1233 $year = date('Y') - $m;
1234 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
1235 $sql = "SELECT * FROM eq_ppi WHERE date > '$year_start' AND date < '$year_end' ".
1236 "AND elder=" . $elder_id . " AND eqpresppi=1";
1237 $this->db2->query($sql,__LINE__,__FILE__);
1238 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
1239 if($this->db2->next_record()) {
1240 $ppis[$m]++; $total_ppis[$m]++;
1241 $link_data['menuaction'] = 'eq.eq.ppi_update';
1242 $link_data['companionship'] = $companionship;
1243 $link_data['interviewer'] = $supervisor;
1244 $link_data['elder'] = $elder_id;
1245 $link_data['name'] = $name;
1246 $link_data['ppi'] = $this->db2->f('ppi');
1247 $link_data['eqpresppi'] = $eqpresppi;
1248 $link_data['action'] = 'view';
1249 $date = $this->db2->f('date');
1250 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1251 $table_data .= '<td align=center><a href='.$link.'><img src="checkmark.gif"><br>'.$date.'</a></td>';
1253 else { $table_data .= "<td> </td>"; }
1255 $table_data .= "</tr>";
1259 $total_companionships += $num_companionships;
1260 if($eqpresppi == 1) {
1261 $stat_data = "<tr><td><b><font size=-2>$num_elders Elders<br>PPI Totals:</font></b></td>";
1263 $stat_data = "<tr><td><b><font size=-2>$num_companionships Companionships<br>PPI Totals:</font></b></td>";
1265 for($m=$num_months; $m >=0; $m--) {
1266 if($eqpresppi == 1) { $percent = ceil(($ppis[$m] / $num_elders)*100); }
1267 else { $percent = ceil(($ppis[$m] / $num_companionships)*100); }
1268 $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
1270 $stat_data .= "</tr>";
1272 $this->t->set_var('table_width',$table_width);
1273 $this->t->set_var('header_row',$header_row);
1274 $this->t->set_var('table_data',$table_data);
1275 $this->t->set_var('stat_data',$stat_data);
1276 $this->t->fp('list','district_list',True);
1279 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>PPI Totals:</font></b></td>";
1280 for($m=$num_months; $m >=0; $m--) {
1281 $percent = ceil(($total_ppis[$m] / $total_companionships)*100);
1282 $totals .= "<td align=center><font size=-2><b>$total_ppis[$m]<br>$percent%</font></b></td>";
1286 $this->t->set_var('totals',$totals);
1287 $this->t->pfp('out','ppi_view_t');
1288 $this->save_sessiondata();
1291 function ppi_update()
1293 $this->t->set_file(array('form' => 'ppi_update.tpl'));
1294 $this->t->set_block('form','interviewer_list','int_list');
1295 $this->t->set_block('form','add','addhandle');
1296 $this->t->set_block('form','edit','edithandle');
1298 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
1299 $this->t->set_var('readonly','');
1300 $this->t->set_var('disabled','');
1302 $action = get_var('action',array('GET','POST'));
1303 $companionship = get_var('companionship',array('GET','POST'));
1304 $interviewer = get_var('interviewer',array('GET','POST'));
1305 $name = get_var('name',array('GET','POST'));
1306 $ppi = get_var('ppi',array('GET','POST'));
1307 $elder = get_var('elder',array('GET','POST'));
1308 $aaronic = get_var('aaronic',array('GET','POST'));
1309 $date = get_var('date',array('GET','POST'));
1310 $notes = get_var('notes',array('GET','POST'));
1311 $eqpresppi = get_var('eqpresppi',array('GET','POST'));
1313 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
1314 $this->db->query($sql,__LINE__,__FILE__);
1315 while ($this->db->next_record())
1317 $supervisor = $this->db->f('supervisor');
1318 $sql = "SELECT * FROM eq_elder WHERE elder=" . $supervisor;
1319 $this->db2->query($sql,__LINE__,__FILE__);
1320 $this->db2->next_record();
1321 $interviewer_name = $this->db2->f('name');
1323 if($supervisor == $interviewer) {
1324 $this->t->set_var('interviewer',$supervisor . ' selected');
1326 $this->t->set_var('interviewer',$interviewer);
1328 $this->t->set_var('interviewer_name',$interviewer_name);
1329 $this->t->fp('int_list','interviewer_list',True);
1332 if($action == 'save')
1334 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
1335 $this->db->query("UPDATE eq_ppi set " .
1336 " ppi='" . $ppi . "'" .
1337 ", interviewer='" . $interviewer . "'" .
1338 ", elder='" . $elder . "'" .
1339 ", aaronic='" . $aaronic . "'" .
1340 ", date='" . $date . "'" .
1341 ", notes='" . $notes . "'" .
1342 ", eqpresppi='" . $eqpresppi . "'" .
1343 " WHERE ppi=" . $ppi,__LINE__,__FILE__);
1348 if($action == 'insert')
1350 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
1351 $this->db->query("INSERT INTO eq_ppi (interviewer,elder,aaronic,date,notes,eqpresppi) "
1352 . "VALUES ('" . $interviewer . "','" . $elder . "','" . $aaronic . "','"
1353 . $date . "','" . $notes . "','" . $eqpresppi ."')",__LINE__,__FILE__);
1358 if($action == 'add')
1360 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
1361 $this->t->set_var('ppi', '');
1362 $this->t->set_var('interviewer', $interviewer);
1363 $this->t->set_var('name',$name);
1364 $this->t->set_var('elder',$elder);
1365 $this->t->set_var('aaronic',$aaronic);
1366 $this->t->set_var('date','');
1367 $this->t->set_var('notes','');
1368 $this->t->set_var('eqpresppi',$eqpresppi);
1369 $this->t->set_var('lang_done','Cancel');
1370 $this->t->set_var('lang_action','Adding New PPI');
1371 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
1372 . $ppi . '&action=' . 'insert'));
1375 if($action == 'edit' || $action == 'view')
1377 $sql = "SELECT * FROM eq_ppi WHERE ppi=".$ppi;
1378 $this->db->query($sql,__LINE__,__FILE__);
1379 $this->db->next_record();
1380 $this->t->set_var('ppi',$ppi);
1381 $this->t->set_var('name',$name);
1382 $this->t->set_var('interviewer', $this->db->f('interviewer'));
1383 $this->t->set_var('elder',$this->db->f('elder'));
1384 $this->t->set_var('aaronic',$this->db->f('aaronic'));
1385 $this->t->set_var('date',$this->db->f('date'));
1386 $this->t->set_var('notes',$this->db->f('notes'));
1387 $this->t->set_var('eqpresppi',$this->db->f('eqpresppi'));
1390 if($action == 'edit')
1392 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
1393 $this->t->set_var('lang_done','Cancel');
1394 $this->t->set_var('lang_action','Editing PPI');
1395 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
1396 . $ppi . '&action=' . 'save'));
1399 if($action == 'view')
1401 $date = $this->db->f('date');
1402 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
1403 $this->t->set_var('readonly','READONLY');
1404 $this->t->set_var('disabled','DISABLED');
1405 $this->t->set_var('lang_done','Done');
1406 $this->t->set_var('lang_action','Viewing PPI');
1407 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
1408 . $ppi . '&action=' . 'edit'));
1411 $this->t->set_var('lang_reset','Clear Form');
1412 $this->t->set_var('lang_add','Add PPI');
1413 $this->t->set_var('lang_save','Save Changes');
1414 $this->t->set_var('edithandle','');
1415 $this->t->set_var('addhandle','');
1417 $this->t->pfp('out','form');
1419 if($action == 'view') { $this->t->set_var('lang_save','Edit PPI'); }
1420 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
1421 if($action == 'add') { $this->t->pfp('addhandle','add'); }
1423 $this->save_sessiondata();
1428 $this->t->set_file(array('vis_view_t' => 'vis_view.tpl'));
1429 $this->t->set_block('vis_view_t','visit_list','list1');
1430 $this->t->set_block('vis_view_t','family_list','list2');
1432 $this->t->set_var('lang_name','Family Name');
1433 $this->t->set_var('lang_date','Date');
1435 $sql = "SELECT * FROM eq_visit WHERE companionship=0 ORDER BY date DESC";
1436 $this->db->query($sql,__LINE__,__FILE__);
1437 $total_records = $this->db->num_rows();
1440 while ($this->db->next_record())
1442 $visit_list[$i]['visit'] = $this->db->f('visit');
1443 $visit_list[$i]['family'] = $this->db->f('family');
1444 $visit_list[$i]['date'] = $this->db->f('date');
1448 for ($i=0; $i < count($visit_list); $i++)
1450 $this->nextmatchs->template_alternate_row_color(&$this->t);
1452 $sql = "SELECT * FROM eq_family WHERE family=".$visit_list[$i]['family'];
1453 $this->db->query($sql,__LINE__,__FILE__);
1454 $this->db->next_record();
1456 $this->t->set_var('family',$visit_list[$i]['family']);
1457 $this->t->set_var('family_name',$this->db->f('name'));
1458 $this->t->set_var('date',$visit_list[$i]['date']);
1460 $link_data['menuaction'] = 'eq.eq.vis_update';
1461 $link_data['visit'] = $visit_list[$i]['visit'];
1462 $link_data['name'] = $this->db->f('name');
1463 $link_data['date'] = $visit_list[$i]['date'];
1464 $link_data['action'] = 'view';
1465 $this->t->set_var('view',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1466 $this->t->set_var('lang_view','View');
1468 $link_data['menuaction'] = 'eq.eq.vis_update';
1469 $link_data['visit'] = $visit_list[$i]['visit'];
1470 $link_data['name'] = $this->db->f('name');
1471 $link_data['date'] = $visit_list[$i]['date'];
1472 $link_data['action'] = 'edit';
1473 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1474 $this->t->set_var('lang_edit','Edit');
1476 $this->t->fp('list1','visit_list',True);
1479 // List the families that are available to record a visit against
1480 $sql = "SELECT * FROM eq_family WHERE valid=1";
1481 $this->db->query($sql,__LINE__,__FILE__);
1482 $total_records = $this->db->num_rows();
1485 while ($this->db->next_record())
1487 $family_names[$i] = $this->db->f('name');
1488 $family_ids[$i] = $this->db->f('family');
1490 } array_multisort($family_names, $family_ids);
1492 for ($i=0; $i < count($family_names); $i++)
1494 $link_data['menuaction'] = 'eq.eq.vis_update';
1495 $link_data['visit'] = '';
1496 $link_data['family'] = $family_ids[$i];
1497 $link_data['action'] = 'add';
1498 $link_data['name'] = $family_names[$i];
1499 $this->t->set_var('add',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1501 $this->t->set_var('name',$family_names[$i]);
1502 if(($i+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
1503 else { $this->t->set_var('table_sep',"</td>"); }
1504 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
1506 $this->t->fp('list2','family_list',True);
1509 $this->t->pfp('out','vis_view_t');
1510 $this->save_sessiondata();
1513 function vis_update()
1515 $this->t->set_file(array('form' => 'vis_update.tpl'));
1516 $this->t->set_block('form','add','addhandle');
1517 $this->t->set_block('form','edit','edithandle');
1519 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
1520 $this->t->set_var('readonly','');
1521 $this->t->set_var('disabled','');
1523 $action = get_var('action',array('GET','POST'));
1524 $visit = get_var('visit',array('GET','POST'));
1525 $family = get_var('family',array('GET','POST'));
1526 $name = get_var('name',array('GET','POST'));
1527 $date = get_var('date',array('GET','POST'));
1528 $notes = get_var('notes',array('GET','POST'));
1531 if($action == 'save')
1533 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
1534 $this->db->query("UPDATE eq_visit set " .
1535 " date='" . $date . "'" .
1536 ", notes='" . $notes . "'" .
1537 " WHERE visit=" . $visit,__LINE__,__FILE__);
1542 if($action == 'insert')
1544 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
1545 $this->db->query("INSERT INTO eq_visit (family,companionship,date,notes) "
1546 . "VALUES ('" . $family . "','" . $companionship . "','"
1547 . $date . "','" . $notes . "')",__LINE__,__FILE__);
1552 if($action == 'add')
1554 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
1555 $this->t->set_var('family', $family);
1556 $this->t->set_var('visit', '');
1557 $this->t->set_var('name', $name);
1558 $this->t->set_var('date','');
1559 $this->t->set_var('notes','');
1560 $this->t->set_var('lang_done','Cancel');
1561 $this->t->set_var('lang_action','Adding New Visit');
1562 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&family='
1563 . $family . '&action=' . 'insert'));
1566 if($action == 'edit' || $action == 'view')
1568 $sql = "SELECT * FROM eq_visit WHERE visit=".$visit;
1569 $this->db->query($sql,__LINE__,__FILE__);
1570 $this->db->next_record();
1571 $this->t->set_var('visit',$visit);
1572 $this->t->set_var('name',$name);
1573 $this->t->set_var('family', $family);
1574 $this->t->set_var('date',$this->db->f('date'));
1575 $this->t->set_var('notes',$this->db->f('notes'));
1578 if($action == 'edit')
1580 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
1581 $this->t->set_var('lang_done','Cancel');
1582 $this->t->set_var('lang_action','Editing Visit');
1583 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&visit='
1584 . $visit . '&action=' . 'save'));
1587 if($action == 'view')
1589 $date = $this->db->f('date');
1590 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
1591 $this->t->set_var('readonly','READONLY');
1592 $this->t->set_var('disabled','DISABLED');
1593 $this->t->set_var('lang_done','Done');
1594 $this->t->set_var('lang_action','Viewing Visit');
1595 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&visit='
1596 . $visit . '&action=' . 'edit'));
1599 $this->t->set_var('lang_reset','Clear Form');
1600 $this->t->set_var('lang_add','Add Visit');
1601 $this->t->set_var('lang_save','Save Changes');
1602 $this->t->set_var('edithandle','');
1603 $this->t->set_var('addhandle','');
1605 $this->t->pfp('out','form');
1607 if($action == 'view') { $this->t->set_var('lang_save','Edit Visit'); }
1608 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
1609 if($action == 'add') { $this->t->pfp('addhandle','add'); }
1611 $this->save_sessiondata();
1616 $this->t->set_file(array('att_view_t' => 'att_view.tpl'));
1617 $this->t->set_block('att_view_t','act_list','list');
1619 $this->t->set_block('att_view_t','month_list','list1');
1620 $this->t->set_block('att_view_t','header_list','list2');
1621 $this->t->set_block('att_view_t','elder_list','list3');
1623 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_view'));
1624 $num_months = get_var('num_months',array('GET','POST'));
1625 if($num_months == '') { $num_months = $this->default_att_num_months; }
1626 $this->t->set_var('num_months',$num_months);
1627 $this->t->set_var('lang_filter','Filter');
1628 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
1629 else { $this->t->set_var('lang_num_months','Months of History'); }
1631 $sql = "SELECT * FROM eq_elder where valid=1";
1632 $this->db->query($sql,__LINE__,__FILE__);
1634 while ($this->db->next_record())
1636 $elder_name[$i] = $this->db->f('name');
1637 $elder_id[$i] = $this->db->f('elder');
1640 array_multisort($elder_name, $elder_id);
1643 // Create a list of sunday dates for a window of 3 months back and current month
1647 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, date("m")-$num_months, 1, date("y")));
1648 $last_date = explode("-",$sunday_list[0]['date']);
1649 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
1650 $time_limit = mktime(0, 0, 0, date("m"), date("t"), date("y"));
1651 while($last_time < $time_limit)
1653 $day = date("w",$last_time);
1654 if(date("w",$last_time) == 0) {
1655 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
1656 $last_date = explode("-",$sunday_list[$i]['date']);
1657 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
1658 $sunday_list[$i]['day'] = $last_date[2];
1659 $sunday_list[$i]['month'] = date("M",$last_time);
1660 $sunday_list[$i]['year'] = $last_date[0];
1663 $last_time += 90000;
1664 if($found_sunday) { $i++; $found_sunday=0; }
1667 $total_elders = count($elder_id);
1668 $old_month=$sunday_list[0]['month']; $span=0;
1669 for ($i=0; $i < count($sunday_list); $i++) {
1670 $date = $sunday_list[$i]['date'];
1671 $this->t->set_var('date',$sunday_list[$i]['date']);
1672 $this->t->set_var('day',$sunday_list[$i]['day']);
1673 if(($old_month != $sunday_list[$i]['month']) || $i == count($sunday_list)-1) {
1674 if($i == count($sunday_list)-1) { $span++; }
1675 $cur_month = $sunday_list[$i]['month'];
1676 $old_month = $sunday_list[$i]['month'];
1677 $link_data['menuaction'] = 'eq.eq.att_update';
1678 $link_data['month'] = $sunday_list[$i-1]['month'];
1679 $link_data['year'] = $sunday_list[$i-1]['year'];
1680 $link_data['action'] = 'update_month';
1681 $cur_month = $sunday_list[$i-1]['month'];
1682 $cur_year = $sunday_list[$i-1]['year'];
1683 $header_row .= "<th><font size=-3>$cur_month $cur_year</font></th>";
1684 $this->t->set_var('update_month',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1685 $this->t->set_var('month',$sunday_list[$i-1]['month']);
1686 $this->t->set_var('year',$sunday_list[$i-1]['year']);
1687 $this->t->set_var('span',$span); $span=0;
1688 $this->t->fp('list1','month_list',True);
1691 $this->t->set_var('total_elders',$total_elders);
1692 $this->t->set_var('header_row',$header_row);
1694 $elder_width=200; $att_width=25; $total_width=$elder_width;
1695 for ($i=0; $i < count($sunday_list); $i++) {
1696 $link_data['menuaction'] = 'eq.eq.att_update';
1697 $link_data['month'] = $sunday_list[$i]['month'];
1698 $link_data['year'] = $sunday_list[$i]['year'];
1699 $link_data['day'] = $sunday_list[$i]['day'];
1700 $link_data['date'] = $sunday_list[$i]['date'];
1701 $link_data['action'] = 'update_day';
1702 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1703 $this->t->set_var('date',$sunday_list[$i]['date']);
1704 $this->t->set_var('day',$sunday_list[$i]['day']);
1705 $this->t->set_var('month',$sunday_list[$i]['month']);
1706 $this->t->set_var('year',$sunday_list[$i]['year']);
1707 $this->t->fp('list2','header_list',True);
1708 $total_width += $att_width;
1711 for ($i=0; $i < count($elder_id); $i++) {
1713 $this->nextmatchs->template_alternate_row_color(&$this->t);
1714 $this->t->set_var('elder_name',$elder_name[$i]);
1715 #print "checking for elder: " . $elder_id[$i] . "<br>";
1716 for ($j=0; $j < count($sunday_list); $j++) {
1717 #print "checking for date: " . $sunday_list[$j]['date'] . "<br>";
1718 #print "SELECT * FROM eq_attendance WHERE date='"
1719 # . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i] . "<br>";
1720 $sql = "SELECT * FROM eq_attendance WHERE date='"
1721 . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i];
1722 $this->db->query($sql,__LINE__,__FILE__);
1723 if($this->db->next_record()) {
1724 $cur_month = $sunday_list[$j]['month'];
1725 if($attended[$i][$cur_month] != 1) {
1726 $attended[$i][$cur_month]=1;
1727 $attendance[$cur_month]++;
1729 $att_table .= '<td align=center><img src="checkmark.gif"></td>';
1731 $att_table .= '<td> </td>';
1734 $this->t->set_var('att_table',$att_table);
1735 $this->t->fp('list3','elder_list',True);
1737 $this->t->set_var('total_width',$total_width);
1738 $this->t->set_var('elder_width',$elder_width);
1739 $this->t->set_var('att_width',$att_width);
1741 # Now calculate attendance for these months
1742 $attendance_str = "";
1743 $nonattendance_str = "";
1744 $aveattendance_str = "";
1745 $avenonattendance_str = "";
1747 $ave_total_attended=0;
1748 foreach($attendance as $att => $value) {
1749 $total_attended = $attendance[$att];
1750 $ave_total_attended += $attendance[$att]; $num_months++;
1751 $percent = ceil(($total_attended / $total_elders)*100);
1752 $attendance_str.="<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
1753 $total_nonattended = $total_elders - $total_attended;
1754 $percent = ceil(($total_nonattended / $total_elders)*100);
1755 $nonattendance_str.="<td align=center><font size=-2><b>$total_nonattended ($percent%)</b></font></td>";
1757 $total_attended = ceil(($ave_total_attended / $num_months));
1758 $percent = ceil(($total_attended / $total_elders)*100);
1759 $aveattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
1760 $total_attended = $total_elders - ceil(($ave_total_attended / $num_months));
1761 $percent = ceil(($total_attended / $total_elders)*100);
1762 $avenonattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
1765 $this->t->set_var('attendance',$attendance_str);
1766 $this->t->set_var('aveattendance',$aveattendance_str);
1767 $this->t->set_var('nonattendance',$nonattendance_str);
1768 $this->t->set_var('avenonattendance',$avenonattendance_str);
1770 $this->t->pfp('out','att_view_t');
1771 $this->save_sessiondata();
1774 function att_update()
1776 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
1777 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
1778 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
1780 $this->t->set_file(array('form' => 'att_update.tpl'));
1781 $this->t->set_block('form','edit','edithandle');
1783 $this->t->set_block('form','month_list','list1');
1784 $this->t->set_block('form','header_list','list2');
1785 $this->t->set_block('form','elder_list','list3');
1787 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_view'));
1789 $action = get_var('action',array('GET','POST'));
1790 $month = get_var('month',array('GET','POST'));
1791 $year = get_var('year',array('GET','POST'));
1792 $day = get_var('day',array('GET','POST'));
1793 $date = get_var('date',array('GET','POST'));
1795 if($action == 'save_month' || $action == 'save_day')
1797 $new_data = get_var('elders_attended',array('POST'));
1798 $month = $monthnum[$month]; if($month < 10) { $month = "0" . $month; }
1800 if($action == 'save_month') {
1801 $this->db->query("DELETE from eq_attendance where date LIKE '".$year."-".$month."-%'",__LINE__,__FILE__);
1804 if($action == 'save_day') {
1805 $this->db->query("DELETE from eq_attendance where date LIKE '".$year."-".$month."-".$day."'",__LINE__,__FILE__);
1808 foreach ($new_data as $data)
1810 $data_array = explode("-",$data);
1811 $elder = $data_array[0];
1812 $date = "$data_array[1]-$data_array[2]-$data_array[3]";
1813 $this->db->query("INSERT INTO eq_attendance (elder,date) "
1814 . "VALUES (" . $elder . ",'". $date . "')",__LINE__,__FILE__);
1821 $sql = "SELECT * FROM eq_elder where valid=1";
1822 $this->db->query($sql,__LINE__,__FILE__);
1824 while ($this->db->next_record())
1826 $elder_name[$i] = $this->db->f('name');
1827 $elder_id[$i] = $this->db->f('elder');
1830 array_multisort($elder_name, $elder_id);
1832 if($action == 'update_month')
1834 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_update&action=save_month'));
1838 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], 1, $year));
1839 $last_date = explode("-",$sunday_list[0]['date']);
1840 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
1841 $time_limit = mktime(0, 0, 0, $monthnum[$month], 31, $year);
1842 while($last_time <= $time_limit)
1844 $day = date("w",$last_time);
1845 if(date("w",$last_time) == 0) {
1846 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
1847 $last_date = explode("-",$sunday_list[$i]['date']);
1848 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
1849 $sunday_list[$i]['day'] = $last_date[2];
1850 $sunday_list[$i]['month'] = date("M",$last_time);
1851 $sunday_list[$i]['year'] = $last_date[0];
1854 $last_time += 90000;
1855 if($found_sunday) { $i++; $found_sunday=0; }
1858 $this->t->set_var('span', $i);
1859 $this->t->set_var('month',$sunday_list[$i-1]['month']);
1860 $this->t->set_var('year',$sunday_list[$i-1]['year']);
1861 $this->t->fp('list1','month_list',True);
1862 $elder_width=200; $att_width=25; $total_width=$elder_width;
1863 for ($i=0; $i < count($sunday_list); $i++) {
1864 $link_data['menuaction'] = 'eq.eq.att_update';
1865 $link_data['month'] = $sunday_list[$i]['month'];
1866 $link_data['year'] = $sunday_list[$i]['year'];
1867 $link_data['day'] = $sunday_list[$i]['day'];
1868 $link_data['date'] = $sunday_list[$i]['date'];
1869 $link_data['action'] = 'update_day';
1870 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1871 $this->t->set_var('date',$sunday_list[$i]['date']);
1872 $this->t->set_var('day',$sunday_list[$i]['day']);
1873 $this->t->set_var('month',$sunday_list[$i]['month']);
1874 $this->t->set_var('year',$sunday_list[$i]['year']);
1875 $this->t->fp('list2','header_list',True);
1876 $total_width += $att_width;
1880 if($action == 'update_day')
1882 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_update&action=save_day'));
1883 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], $day, $year));
1884 $this->t->set_var('month',$month);
1885 $this->t->set_var('year',$year);
1886 $this->t->fp('list1','month_list',True);
1887 $this->t->set_var('date',$date);
1888 $this->t->set_var('day',$day);
1889 $this->t->set_var('month',$month);
1890 $this->t->set_var('year',$year);
1891 $this->t->fp('list2','header_list',True);
1894 for ($i=0; $i < count($elder_id); $i++) {
1896 $this->nextmatchs->template_alternate_row_color(&$this->t);
1897 $this->t->set_var('elder_name',$elder_name[$i]);
1898 for ($j=0; $j < count($sunday_list); $j++) {
1899 $sql = "SELECT * FROM eq_attendance WHERE date='"
1900 . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i];
1901 $this->db->query($sql,__LINE__,__FILE__);
1902 $value = $elder_id[$i] . "-" . $sunday_list[$j]['date'];
1903 if($this->db->next_record()) {
1904 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'" checked></td>';
1906 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'"></td>';
1909 $this->t->set_var('att_table',$att_table);
1910 $this->t->fp('list3','elder_list',True);
1913 $this->t->set_var('lang_done', 'Cancel');
1914 $this->t->set_var('lang_reset','Clear Form');
1915 $this->t->set_var('lang_save','Save Changes');
1917 $this->t->pfp('out','form');
1918 $this->t->pfp('addhandle','edit');
1920 $this->save_sessiondata();
1925 $this->t->set_file(array('dir_view_t' => 'dir_view.tpl'));
1926 $this->t->set_block('dir_view_t','dir_list','list');
1928 $sql = "SELECT * FROM eq_parent where valid=1 ORDER BY name ASC";
1929 $this->db->query($sql,__LINE__,__FILE__);
1931 while ($this->db->next_record())
1933 $parent[$i]['id'] = $this->db->f('parent');
1934 $parent[$i]['name'] = $this->db->f('name');
1935 $parent[$i]['phone'] = $this->db->f('phone');
1936 $parent[$i]['address'] = $this->db->f('address');
1940 for ($i=0; $i < count($parent); $i++)
1942 $name = $parent[$i]['name'];
1943 $phone = $parent[$i]['phone'];
1944 $address = $parent[$i]['address'];
1945 $this->t->set_var('name', $name);
1946 $this->t->set_var('address', $address);
1947 $this->t->set_var('phone', $phone);
1948 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1949 $this->t->set_var('tr_color',$tr_color);
1950 $this->t->fp('list','dir_list',True);
1951 //print "$phone $name $address<br>";
1953 $this->t->pfp('out','dir_view_t');
1954 $this->save_sessiondata();
1959 $this->t->set_file(array('org_view_t' => 'org_view.tpl'));
1960 $this->t->set_block('org_view_t','calling_list','list1');
1961 $this->t->set_block('org_view_t','org_list','list2');
1963 # Display a list ordered alphabetically
1964 $sql = "SELECT * FROM eq_calling ORDER BY name ASC";
1965 $this->db->query($sql,__LINE__,__FILE__);
1967 while ($this->db->next_record())
1969 $calling[$i]['id'] = $this->db->f('indiv_id');
1970 $calling[$i]['name'] = $this->db->f('name');
1971 $calling[$i]['position'] = $this->db->f('position');
1972 $calling[$i]['sustained'] = $this->db->f('sustained');
1973 $calling[$i]['organization'] = $this->db->f('organization');
1976 for ($i=0; $i < count($calling); $i++)
1978 $name = $calling[$i]['name'];
1979 $position = $calling[$i]['position'];
1980 $sustained = $calling[$i]['sustained'];
1981 $organization = $calling[$i]['organization'];
1982 $this->t->set_var('name', $name);
1983 $this->t->set_var('position', $position);
1984 $this->t->set_var('sustained', $sustained);
1985 $this->t->set_var('organization', $organization);
1986 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1987 $this->t->set_var('tr_color',$tr_color);
1988 $this->t->fp('list1','calling_list',True);
1991 # Display a list ordered by organization
1992 $sql = "SELECT * FROM eq_calling ORDER BY sequence ASC";
1993 $this->db->query($sql,__LINE__,__FILE__);
1995 while ($this->db->next_record())
1997 $calling[$i]['id'] = $this->db->f('indiv_id');
1998 $calling[$i]['name'] = $this->db->f('name');
1999 $calling[$i]['position'] = $this->db->f('position');
2000 $calling[$i]['sustained'] = $this->db->f('sustained');
2001 $calling[$i]['organization'] = $this->db->f('organization');
2004 for ($i=0; $i < count($calling); $i++)
2006 $name = $calling[$i]['name'];
2007 $position = $calling[$i]['position'];
2008 $sustained = $calling[$i]['sustained'];
2009 $organization = $calling[$i]['organization'];
2010 $this->t->set_var('name', $name);
2011 $this->t->set_var('position', $position);
2012 $this->t->set_var('sustained', $sustained);
2013 $this->t->set_var('organization', $organization);
2014 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2015 $this->t->set_var('tr_color',$tr_color);
2016 $this->t->fp('list2','org_list',True);
2019 $this->t->pfp('out','org_view_t');
2020 $this->save_sessiondata();
2025 $this->t->set_file(array('admin_t' => 'admin.tpl'));
2026 $this->t->set_block('admin_t','upload','uploadhandle');
2027 $this->t->set_block('admin_t','admin','adminhandle');
2028 $this->t->set_block('admin_t','cmd','cmdhandle');
2030 $this->t->set_var('upload_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.admin&action=upload'));
2032 $action = get_var('action',array('GET','POST'));
2034 $this->t->pfp('out','admin_t');
2036 if($action == 'upload')
2038 $target_path = $this->upload_target_path . basename( $_FILES['uploadedfile']['name']);
2040 if(($_FILES['uploadedfile']['type'] == "application/zip") &&
2041 (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))) {
2042 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
2043 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
2044 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
2045 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
2046 $this->t->set_var('uploadstatus',$uploadstatus);
2047 $this->t->pfp('uploadhandle','upload');
2048 $this->t->set_var('uploadhandle','');
2049 print "<table border=1 width=80%><tr><td>\n<pre>";
2051 # make a directory for this data to be stored in
2052 $date="data_" . date("Y_m_d");
2053 $data_dir = $this->upload_target_path . $date;
2054 print "-> Making the data directory: $date<br>\n";
2055 exec('mkdir ' . $data_dir . ' 2>&1', $result, $return_code);
2056 if($return_code != 0) {
2057 print implode('\n',$result) . "<br>";
2058 print "<b><font color=red>";
2059 print "-E- Unable to create the data directory. Aborting import.";
2060 print "</font></b>";
2064 # move the file uploaded into this directory
2065 print "-> Moving the uploaded file into the data dir<br>\n";
2066 exec('mv ' . $target_path . ' ' . $data_dir . '/' . ' 2>&1', $result, $return_code);
2067 if($return_code != 0) {
2068 print implode('\n',$result) . "<br>";
2069 print "<b><font color=red>";
2070 print "-E- Unable to move the uploaded file into the data dir. Aborting import.";
2071 print "</font></b>";
2075 # unzip the data into this directory
2076 print "-> Unzipping the data<br>\n";
2077 $data_file = $data_dir . '';
2078 exec('unzip ' . $data_dir . '/*.zip -d ' . $data_dir . ' 2>&1', $result, $return_code);
2079 if($return_code != 0) {
2080 print implode('\n',$result) . "<br>";
2081 print "<b><font color=red>";
2082 print "-E- Unable to unzip the uploaded file into the data dir. Aborting import.";
2083 print "</font></b>";
2086 exec('mv ' . $data_dir . '/*/* '. $data_dir . ' 2>&1', $result, $return_code);
2088 # update the data_latest link to point to this new directory
2089 print "-> Updating the latest data dir link<br>\n";
2090 $data_latest = $this->upload_target_path . 'data_latest';
2091 exec('rm ' . $data_latest. '; ln -s ' . $data_dir .' '. $data_latest .' 2>&1', $result, $return_code);
2092 if($return_code != 0) {
2093 print implode('\n',$result) . "<br>";
2094 print "<b><font color=red>";
2095 print "-E- Unable to update the data latest link. Aborting import.";
2096 print "</font></b>";
2100 # run the import perl script to encorporate it into the DB
2101 ob_start('ob_logstdout', 2);
2102 print "-> Importing the data into the EQ database<br>\n";
2103 ob_flush(); flush(); sleep(1);
2104 $import_log = $this->upload_target_path . '/import.log';
2105 $data_log = $this->upload_target_path . '/data.log';
2106 $import_cmd = $this->script_path . 'import_ward_data ' . $data_latest . ' | tee ' . $import_log;
2107 $parse_cmd = $this->script_path . 'parse_ward_data -v ' . $data_latest . ' > ' . $data_log;
2108 #print "import_cmd: $import_cmd<br>";
2109 #print "parse_cmd: $parse_cmd<br>";
2110 ob_start('ob_logstdout', 2);
2111 passthru($import_cmd);
2112 passthru($parse_cmd);
2113 ob_flush(); flush(); sleep(1);
2115 # fix the permissions of the data dir
2116 exec('chmod -R o-rwx ' . $data_dir, $result, $return_code);
2118 $this->t->pfp('cmdhandle','cmd');
2119 print "</pre></td></tr></table>";
2121 } else if($_FILES['uploadedfile']['type'] != "application/zip") {
2122 $uploadstatus = "<b><font color=red>The file format must be a .zip file, please try again! </font></b>";
2123 $this->t->set_var('uploadstatus',$uploadstatus);
2126 $uploadstatus = "<b><font color=red> There was an error (" . $_FILES['uploadedfile']['error'];
2127 $uploadstatus.= ") uploading the file, please try again! </font></b>";
2128 $this->t->set_var('uploadstatus',$uploadstatus);
2133 $this->t->set_var('adminhandle','');
2134 $this->t->pfp('adminhandle','admin');
2137 $this->save_sessiondata();