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_int_num_months;
26 var $default_int_num_years;
27 var $default_att_num_months;
30 var $upload_target_path;
33 var $public_functions = array
59 $this->default_ht_num_months = 3;
60 $this->default_ppi_num_months = 3;
61 $this->default_ppi_num_years = 0;
62 $this->default_int_num_months = 3;
63 $this->default_int_num_years = 0;
64 $this->default_att_num_months = 3;
65 $this->upload_target_path = "/home/users/eqpres/eq_data/";
66 $this->script_path = "/usr/share/phpgroupware/eq/";
68 $this->db = $GLOBALS['phpgw']->db;
69 $this->db2 = $this->db;
70 $this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
71 $this->t = $GLOBALS['phpgw']->template;
72 $this->account = $GLOBALS['phpgw_info']['user']['account_id'];
73 $this->grants = $GLOBALS['phpgw']->acl->get_grants('eq');
74 $this->grants[$this->account] = PHPGW_ACL_READ + PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE;
76 $this->jscal = CreateObject('phpgwapi.jscalendar'); // before phpgw_header() !!!
77 $this->cal_options = 'daFormat : "%Y-%m-%d",
78 ifFormat : "%Y-%m-%d",
82 $GLOBALS['phpgw_info']['flags']['app_header'] = 'Elders Quorum Tools';
83 $GLOBALS['phpgw']->common->phpgw_header();
85 $this->current_day = `date '+%d'`;
86 $this->current_day = $this->current_day-0; // Make it numeric
87 $this->current_month = `date '+%m'`;
88 $this->current_month = $this->current_month-0; // Make it numeric
89 $this->current_year = `date '+%Y'`;
90 $this->current_year = $this->current_year-0; // Make it numeric
93 $this->display_app_header();
96 function save_sessiondata()
101 function display_app_header()
103 $this->t->set_file(array('eq_header' => 'header.tpl'));
105 if (isset($phpgw_info['user']['preferences']['eq']['eq_font']))
107 $font = $phpgw_info['user']['preferences']['eq']['eq_font'];
114 $this->t->set_var('bg_color',$phpgw_info['theme']['th_bg']);
115 $this->t->set_var('font',$font);
116 $link_data['menuaction'] = 'eq.eq.ht_view';
117 $this->t->set_var('link_hometeaching',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
118 $this->t->set_var('lang_hometeaching','HomeTeaching');
119 $link_data['menuaction'] = 'eq.eq.act_list';
120 $this->t->set_var('link_activity',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
121 $this->t->set_var('lang_activity','Activities');
122 $link_data['menuaction'] = 'eq.eq.par_view';
123 $this->t->set_var('link_participation',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
124 $this->t->set_var('lang_participation','Participation');
125 $link_data['menuaction'] = 'eq.eq.ppi_view';
126 $this->t->set_var('link_ppi',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
127 $this->t->set_var('lang_ppi','PPIs');
128 $link_data['menuaction'] = 'eq.eq.int_view';
129 $this->t->set_var('link_int',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
130 $this->t->set_var('lang_int','Interviews');
131 $link_data['menuaction'] = 'eq.eq.vis_view';
132 $this->t->set_var('link_visit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
133 $this->t->set_var('lang_visit','Visits');
134 $link_data['menuaction'] = 'eq.eq.att_view';
135 $this->t->set_var('link_attendance',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
136 $this->t->set_var('lang_attendance','Attendance');
137 $link_data['menuaction'] = 'eq.eq.dir_view';
138 $this->t->set_var('link_dir',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
139 $this->t->set_var('lang_dir','Directory');
140 $link_data['menuaction'] = 'eq.eq.org_view';
141 $this->t->set_var('link_org',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
142 $this->t->set_var('lang_org','Callings');
143 $link_data['menuaction'] = 'eq.eq.admin';
144 $this->t->set_var('link_admin',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
145 $this->t->set_var('lang_admin','Admin');
146 $link_data['menuaction'] = 'eq.eq.schedule';
147 $this->t->set_var('link_schedule',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
148 $this->t->set_var('lang_schedule','Scheduling');
150 $this->t->pparse('out','eq_header');
155 $this->t->set_file(array('ht_view_t' => 'ht_view.tpl'));
156 $this->t->set_block('ht_view_t','district_list','list');
158 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
159 $num_months = get_var('num_months',array('GET','POST'));
160 if($num_months == '') { $num_months = $this->default_ht_num_months; }
161 $this->t->set_var('num_months',$num_months);
162 $this->t->set_var('lang_filter','Filter');
163 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
164 else { $this->t->set_var('lang_num_months','Months of History'); }
166 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
167 $this->t->set_var('title','Hometeaching');
169 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
170 $this->db->query($sql,__LINE__,__FILE__);
172 while ($this->db->next_record())
174 $districts[$i]['district'] = $this->db->f('district');
175 $districts[$i]['name'] = $this->db->f('name');
176 $districts[$i]['supervisor'] = $this->db->f('supervisor');
180 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
181 $this->db->query($sql,__LINE__,__FILE__);
183 while ($this->db->next_record())
185 $elder_id[$i] = $this->db->f('elder');
186 $elder_name[$i] = $this->db->f('name');
187 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
190 array_multisort($elder_name, $elder_id);
192 // Make an array mapping elder_ids to elder_names
193 for($i=0; $i < count($elder_id); $i++) {
195 $elders[$id] = $elder_name[$i];
198 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
199 $this->db->query($sql,__LINE__,__FILE__);
200 while ($this->db->next_record())
202 $aaronic_id = $this->db->f('aaronic');
203 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
204 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
208 $this->nextmatchs->template_alternate_row_color(&$this->t);
209 for ($i=0; $i < count($districts); $i++) {
210 $this->t->set_var('district_number',$districts[$i]['district']);
211 $this->t->set_var('district_name',$districts[$i]['name']);
212 $supervisor = $districts[$i]['supervisor'];
213 $unique_companionships='';
215 // Select all the unique companionship numbers for this district
216 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $districts[$i]['district'];
217 $this->db->query($sql,__LINE__,__FILE__);
219 while ($this->db->next_record())
221 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
225 $comp_width=450; $visit_width=25; $table_width=$comp_width + $num_months*$visit_width;
226 $table_data=""; $num_companionships = 0; $num_families = 0;
227 for($m=$num_months; $m >= 0; $m--) { $visits[$m] = 0; }
228 for ($j=0; $j < count($unique_companionships); $j++) {
229 $companion_table_entry = "";
230 // Select all the companions in each companionship
231 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
232 "companionship=". $unique_companionships[$j]['companionship'];
233 $this->db->query($sql,__LINE__,__FILE__);
235 while ($this->db->next_record())
237 // Get this companions information
238 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
239 $companionship = $this->db->f('companionship');
240 $elder_id = $this->db->f('elder');
241 $aaronic_id = $this->db->f('aaronic');
243 $name = $elders[$elder_id];
244 $phone = $elder_phone[$elder_id];
246 else if($aaronic_id) {
247 $name = $aaronic[$aaronic_id]['name'];
248 $phone = $aaronic[$aaronic_id]['phone'];
250 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
252 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
254 // Get the names of the families assigned this home teaching companionship
255 $sql = "SELECT * from eq_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
256 $sql = $sql . " ORDER BY name ASC";
257 $this->db->query($sql,__LINE__,__FILE__);
259 while ($this->db->next_record())
261 $num_families++; $total_families++;
262 $family_name = $this->db->f('name');
263 $family_id = $this->db->f('family');
264 $this->nextmatchs->template_alternate_row_color(&$this->t);
265 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
266 // Find out how many times Visits were performed by this companionship
267 // in the past $num_months for this Family
268 $header_row="<th width=$comp_width><font size=-2>Families</th>";
269 for($m=$num_months; $m >= 0; $m--) {
270 $month = $this->current_month - $m;
271 $year = $this->current_year;
272 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
273 if($month < 10) { $month = "0"."$month"; }
274 $month_start = "$year"."-"."$month"."-"."01";
275 $month_end = "$year"."-"."$month"."-"."31";
276 $month = "$month"."/"."$year";
277 //print "m: $m month: $month year: $year month_start: $month_start month_end: $month_end<br>";
278 // Add this to the query to filter on only visits made by this companionship:
279 // " AND companionship=" . $unique_companionships[$j]['companionship'].
280 $sql = "SELECT * FROM eq_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
281 " AND companionship!=0".
282 " AND family=". $family_id;
283 $this->db2->query($sql,__LINE__,__FILE__);
284 $link_data['menuaction'] = 'eq.eq.ht_update';
285 $link_data['date'] = $month_start;
286 $link_data['month_start'] = $month_start;
287 $link_data['month_end'] = $month_end;
288 $link_data['month'] = $month;
289 $link_data['district'] = $districts[$i]['district'];
290 $link_data['district_name'] = $districts[$i]['name'];
291 $link_data['action'] = 'view';
292 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
293 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
294 if(!$total_visits[$m]) { $total_visits[$m] = 0; }
295 if($this->db2->next_record()) {
296 if($this->db2->f('visited') == 'y') {
297 $visits[$m]++; $total_visits[$m]++;
298 $table_data .= '<td align=center><a href="'.$link.'"><img src="checkmark.gif"></a></td>';
300 else if($this->db2->f('visited') == 'n') {
301 $table_data .= '<td align=center><a href="'.$link.'"><img src="x.gif"></a></td>';
304 $visits[$m]++; $total_visits[$m]++;
305 $table_data .= "<td> </td>";
309 $visits[$m]++; $total_visits[$m]++;
310 $table_data .= "<td> </td>";
313 $table_data .= "</tr>";
316 $table_data .= "<tr><td colspan=20></td></tr>";
318 $table_data .= "<tr><td colspan=20><hr></td></tr>";
319 $stat_data = "<tr><td><b><font size=-2>$num_families Families<br>Visit Totals:</font></b></td>";
321 for($m=$num_months; $m >=0; $m--) {
322 $percent = ceil(($visits[$m] / $num_families)*100);
323 $stat_data .= "<td align=center><font size=-2><b>$visits[$m]<br>$percent%</font></b></td>";
325 $stat_data .= "</tr>";
327 $this->t->set_var('table_width',$table_width);
328 $this->t->set_var('header_row',$header_row);
329 $this->t->set_var('table_data',$table_data);
330 $this->t->set_var('stat_data',$stat_data);
331 $this->t->fp('list','district_list',True);
334 $totals = "<tr><td><b><font size=-2>$total_families Total Families<br>Visit Totals:</font></b></td>";
335 for($m=$num_months; $m >=0; $m--) {
336 $percent = ceil(($total_visits[$m] / $total_families)*100);
337 $totals .= "<td align=center><font size=-2><b>$total_visits[$m]<br>$percent%</font></b></td>";
341 $this->t->set_var('totals',$totals);
343 $this->t->pfp('out','ht_view_t');
344 $this->save_sessiondata();
350 $this->t->set_file(array('ht_update_t' => 'ht_update.tpl'));
351 $this->t->set_block('ht_update_t','district_list','list');
352 $this->t->set_block('ht_update_t','save','savehandle');
354 $district = get_var('district',array('GET','POST'));
355 $district_name = get_var('district_name',array('GET','POST'));
356 $date = get_var('date',array('GET','POST'));
357 $month = get_var('month',array('GET','POST'));
358 $month_start = get_var('month_start',array('GET','POST'));
359 $month_end = get_var('month_end',array('GET','POST'));
360 $action = get_var('action',array('GET','POST'));
362 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
363 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_update&action=save'));
364 $this->t->set_var('lang_done','Cancel');
365 $this->t->set_var('district_name',$district_name);
366 $this->t->set_var('district_number',$district);
367 $this->t->set_var('title','Hometeaching Update ' . $month);
368 $this->t->set_var('date',$date);
370 if($action == 'save')
372 // Get a list of all the companionships in this district
373 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $district;
374 $this->db->query($sql,__LINE__,__FILE__);
376 while ($this->db->next_record())
378 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
381 for ($j=0; $j < count($unique_companionships); $j++)
383 // FIXME: We won't be able to go back and edit history on families that have been
384 // reassigned to a different companionship. The following delete command will not delete
385 // the history of visits under an older companionship, only the ones for the existing
386 // companionship. This will lead to duplicate visits being entered for an older
387 // month for the same family, making it impossible to change the past history once
388 // a family is reassigned. However, you will be able to view the history just fine.
390 //$comp=$unique_companionships[$j]['companionship'];
391 //print "deleting from eq_visit where companionship=$comp and date=$date and district=$district<br>";
392 // Delete all the visits that have taken place for all families for this month
393 $this->db->query("DELETE from eq_visit where companionship=" . $unique_companionships[$j]['companionship'] .
394 " AND " . "date='" . $date . "'",__LINE__,__FILE__);
397 // Now, add the visits that are checked for this month
398 $new_data = get_var('family_visited',array('POST'));
399 foreach ($new_data as $family)
401 foreach ($family as $data)
403 //print "family_visited: $data <br>";
404 $data_array = explode("/",$data);
405 $family_id = $data_array[0];
406 $companionship = $data_array[1];
407 $date = $data_array[2];
408 $visited = $data_array[3];
409 if($visited == "") { $visited = $data_array[4]; }
410 //print "family_id: $family_id companionship: $companionship date: $date visited: $visited<br>";
411 $this->db->query("INSERT INTO eq_visit (family,companionship,date,notes,visited) "
412 . "VALUES (" . $family_id .",". $companionship .",'". $date ."','','". $visited ."')",__LINE__,__FILE__);
419 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
420 $this->db->query($sql,__LINE__,__FILE__);
422 while ($this->db->next_record())
424 $elder_id[$i] = $this->db->f('elder');
425 $elder_name[$i] = $this->db->f('name');
426 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
429 array_multisort($elder_name, $elder_id);
431 // Make an array mapping elder_ids to elder_names
432 for($i=0; $i < count($elder_id); $i++) {
434 $elders[$id] = $elder_name[$i];
437 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
438 $this->db->query($sql,__LINE__,__FILE__);
439 while ($this->db->next_record())
441 $aaronic_id = $this->db->f('aaronic');
442 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
443 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
446 // Select all the unique companionship numbers for this district
447 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $district;
448 $this->db->query($sql,__LINE__,__FILE__);
449 $j=0; $unique_companionships='';
450 while ($this->db->next_record())
452 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
456 $comp_width=300; $visit_width=25; $table_width=$comp_width + $visit_width;
457 $table_data=""; $num_companionships = 0; $num_families = 0; $visits=0;
458 for ($j=0; $j < count($unique_companionships); $j++) {
459 $companion_table_entry = "";
460 // Select all the companions in each companionship
461 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
462 "companionship=". $unique_companionships[$j]['companionship'];
463 $this->db->query($sql,__LINE__,__FILE__);
465 while ($this->db->next_record())
467 // Get this companions information
468 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
469 $companionship = $this->db->f('companionship');
470 $elder_id = $this->db->f('elder');
471 $aaronic_id = $this->db->f('aaronic');
473 $name = $elders[$elder_id];
474 $phone = $elder_phone[$elder_id];
476 else if($aaronic_id) {
477 $name = $aaronic[$aaronic_id]['name'];
478 $phone = $aaronic[$aaronic_id]['phone'];
480 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
482 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
484 // Get the names of the families assigned this home teaching companionship
485 $sql = "SELECT * from eq_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
486 $sql = $sql . " ORDER BY name ASC";
487 $this->db->query($sql,__LINE__,__FILE__);
488 while ($this->db->next_record())
490 $num_families++; $total_families++;
491 $family_name = $this->db->f('name');
492 $family_id = $this->db->f('family');
493 $this->nextmatchs->template_alternate_row_color(&$this->t);
494 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
496 $header_row="<th width=$comp_width><font size=-2>Families</th>";
497 $sql = "SELECT * FROM eq_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
498 " AND companionship!=0".
499 " AND family=". $family_id;
500 $this->db2->query($sql,__LINE__,__FILE__);
501 $value = $family_id . "/" . $unique_companionships[$j]['companionship'] . "/" . $date;
502 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
503 if(!$total_visits) { $total_visits = 0; }
504 if($this->db2->next_record()) {
505 if($this->db2->f('visited') == 'y') {
506 $visits++; $total_visits++;
507 $table_data .= '<td width=100 align=center>';
508 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y" checked>Y';
509 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
510 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/"> ';
511 $table_data .= '</td>';
512 } else if($this->db2->f('visited') == 'n') {
513 $table_data .= '<td width=100 align=center>';
514 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
515 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n" checked>N';
516 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/">';
517 $table_data .= '</td>';
519 $table_data .= '<td width=100 align=center>';
520 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
521 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
522 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
523 $table_data .= '</td>';
528 $table_data .= '<td width=100 align=center>';
529 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
530 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
531 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
532 $table_data .= '</td>';
535 $table_data .= "</tr>";
536 $table_data .= "<tr><td colspan=20></td></tr>";
538 $table_data .= "<tr><td colspan=20><hr></td></tr>";
539 $stat_data = "<tr><td><b><font size=-2>$num_families Families<br>Visit Totals:</font></b></td>";
541 $percent = ceil(($visits / $num_families)*100);
542 $stat_data .= "<td align=center><font size=-2><b>$visits<br>$percent%</font></b></td>";
543 $stat_data .= "</tr>";
545 $this->t->set_var('table_width',$table_width);
546 $this->t->set_var('header_row',$header_row);
547 $this->t->set_var('table_data',$table_data);
548 $this->t->set_var('stat_data',$stat_data);
549 $this->t->fp('list','district_list',True);
551 $this->t->set_var('lang_reset','Clear Form');
552 $this->t->set_var('lang_save','Save Changes');
553 $this->t->set_var('savehandle','');
555 $this->t->pfp('out','ht_update_t');
556 $this->t->pfp('addhandle','save');
558 $this->save_sessiondata();
563 $this->t->set_file(array('act_list_t' => 'act_list.tpl'));
564 $this->t->set_block('act_list_t','act_list','list');
566 $this->t->set_var('lang_name','Activity Name');
567 $this->t->set_var('lang_date','Date');
569 $sql = "SELECT * FROM eq_activity ORDER BY date DESC";
570 $this->db->query($sql,__LINE__,__FILE__);
571 $total_records = $this->db->num_rows();
574 while ($this->db->next_record())
576 $activity_list[$i]['name'] = $this->db->f('name');
577 $activity_list[$i]['date'] = $this->db->f('date');
578 $activity_list[$i]['activity'] = $this->db->f('activity');
582 for ($i=0; $i < count($activity_list); $i++)
584 $this->nextmatchs->template_alternate_row_color(&$this->t);
585 $this->t->set_var('name',$activity_list[$i]['name']);
586 $this->t->set_var('date',$activity_list[$i]['date']);
588 $link_data['menuaction'] = 'eq.eq.act_view';
589 $link_data['activity'] = $activity_list[$i]['activity'];
590 $link_data['action'] = 'view';
591 $this->t->set_var('view',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
592 $this->t->set_var('lang_view','View');
594 $link_data['menuaction'] = 'eq.eq.act_update';
595 $link_data['activity'] = $activity_list[$i]['activity'];
596 $link_data['action'] = 'edit';
597 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
598 $this->t->set_var('lang_edit','Edit');
600 $link_data['menuaction'] = 'eq.eq.act_update';
601 $link_data['activity'] = '0';
602 $link_data['action'] = 'add';
603 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/eq/index.php',$link_data)
604 . '"><input type="submit" name="Add" value="' . 'Add Activity' .'"></font></form>');
606 $this->t->fp('list','act_list',True);
609 $this->t->pfp('out','act_list_t');
610 $this->save_sessiondata();
615 $this->t->set_file(array('act_view_t' => 'act_view.tpl'));
616 $this->t->set_block('act_view_t','part_list','list');
618 $sql = "SELECT * FROM eq_activity WHERE activity=" . intval(get_var('activity',array('GET','POST')));
619 $this->db->query($sql,__LINE__,__FILE__);
620 $this->db->next_record();
621 $this->t->set_var('name', $this->db->f('name'));
622 $this->t->set_var('date', $this->db->f('date'));
623 $this->t->set_var('notes', $this->db->f('notes'));
625 $this->t->set_var('lang_name','Activity Name');
626 $this->t->set_var('lang_date','Date');
627 $this->t->set_var('lang_notes','Notes');
628 $this->t->set_var('lang_done','Done');
629 $this->t->set_var('lang_action','View');
631 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
632 $this->t->set_var('tr_color',$tr_color);
634 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_list'));
636 $link_data['menuaction'] = 'eq.eq.act_update';
637 $link_data['activity'] = get_var('activity',array('GET','POST'));
638 $link_data['action'] = 'edit';
639 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
640 $this->t->set_var('lang_edit','Edit');
641 $this->t->set_var('cal_date',$this->db->f('date'));
643 // Now find out which elders participated in this activity
644 $sql = "SELECT * FROM eq_participation WHERE activity=" . intval(get_var('activity',array('GET','POST')));
645 $this->db->query($sql,__LINE__,__FILE__);
646 $total_records = $this->db->num_rows();
649 while ($this->db->next_record())
651 $part_list[$i]['elder'] = $this->db->f('elder');
655 for ($i=0; $i < count($part_list); $i++)
657 $sql = "SELECT * FROM eq_elder WHERE elder=" . $part_list[$i]['elder'];
658 $this->db->query($sql,__LINE__,__FILE__);
659 $this->db->next_record();
660 $names[$i] = $this->db->f('name');
663 for ($i=0; $i < count($names); $i++)
665 //$this->nextmatchs->template_alternate_row_color(&$this->t);
666 $this->t->set_var('elder_name',$names[$i]);
667 if(($i+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
668 else { $this->t->set_var('table_sep',"</td>"); }
669 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
670 $this->t->fp('list','part_list',True);
673 $this->t->pfp('out','act_view_t');
674 $this->save_sessiondata();
677 function act_update()
679 $this->t->set_file(array('form' => 'act_update.tpl'));
680 $this->t->set_block('form','elder_list','list');
681 $this->t->set_block('form','add','addhandle');
682 $this->t->set_block('form','edit','edithandle');
683 $this->t->set_var('lang_done','Done');
685 $action = get_var('action',array('GET','POST'));
686 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_list'));
687 $activity['activity'] = intval(get_var('activity',array('GET','POST')));
689 if($action == 'save')
691 $activity['name'] = $this->db->db_addslashes(get_var('name',array('POST')));
692 $activity['date'] = $this->db->db_addslashes(get_var('date',array('POST')));
693 $activity['notes']= $this->db->db_addslashes(get_var('notes',array('POST')));
694 $this->db->query("UPDATE eq_activity set " .
695 " name='" . $activity['name'] .
696 "', date='" . $activity['date'] . "'" .
697 ", notes='" . $activity['notes'] . "'" .
698 " WHERE activity=" . $activity['activity'],__LINE__,__FILE__);
700 // Delete all the elders who have particiapted in this activity
701 $this->db->query("DELETE from eq_participation where activity=".$activity['activity'],__LINE__,__FILE__);
703 // Re-add the elders who are checked as having participated in this activity
704 $elders = get_var('elder_name',array('POST'));
705 foreach ($elders as $elder)
707 $this->db->query("INSERT INTO eq_participation (elder,activity) "
708 . "VALUES (" . $elder . ",". $activity['activity'] . ")",__LINE__,__FILE__);
715 if($action == 'insert')
717 $activity['name'] = $this->db->db_addslashes(get_var('name',array('POST')));
718 $activity['date'] = $this->db->db_addslashes(get_var('date',array('POST')));
719 $activity['notes']= $this->db->db_addslashes(get_var('notes',array('POST')));
720 $this->db->query("INSERT INTO eq_activity (name,date,notes) "
721 . "VALUES ('" . $activity['name'] . "','"
722 . $activity['date'] . "','" . $activity['notes'] . "')",__LINE__,__FILE__);
729 $activity['activity'] = 0;
730 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
731 $this->t->set_var('name','');
732 $this->t->set_var('date','');
733 $this->t->set_var('notes','');
734 $this->t->set_var('lang_done','Cancel');
735 $this->t->set_var('lang_action','Adding New Activity');
736 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_update&activity='
737 . $activity['activity'] . '&action=' . 'insert'));
740 if($action == 'edit')
742 $sql = "SELECT * FROM eq_activity WHERE activity=" . $activity['activity'];
743 $this->db->query($sql,__LINE__,__FILE__);
744 $this->db->next_record();
745 $this->t->set_var('cal_date',$this->jscal->input('date',$this->db->f('date'),'','','','','',$this->cal_options));
746 $this->t->set_var('name', $this->db->f('name'));
747 $this->t->set_var('date', $this->db->f('date'));
748 $this->t->set_var('notes', $this->db->f('notes'));
749 $this->t->set_var('lang_done','Cancel');
750 $this->t->set_var('lang_action','Editing Activity');
751 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_update&activity='
752 . $activity['activity'] . '&action=' . 'save'));
756 $sql = "SELECT * FROM eq_elder";
757 $this->db->query($sql,__LINE__,__FILE__);
759 while ($this->db->next_record())
761 if($this->db->f('valid') == 1 || $action != 'add') {
762 $elder_name[$i] = $this->db->f('name');
763 $elder_id[$i] = $this->db->f('elder');
764 $elder_valid[$i] = $this->db->f('valid');
768 array_multisort($elder_name, $elder_id, $elder_valid);
771 for ($i=0; $i < count($elder_id); $i++)
773 //$this->nextmatchs->template_alternate_row_color(&$this->t);
774 $sql = "SELECT * FROM eq_participation where activity=". $activity['activity'] . " AND elder=" . $elder_id[$i];
775 $this->db->query($sql,__LINE__,__FILE__);
776 if($this->db->next_record()) { $this->t->set_var('checked','checked'); $checked=1; }
777 else { $this->t->set_var('checked',''); $checked=0; }
778 if($checked || $elder_valid[$i] == 1) {
779 $this->t->set_var('elder_name',$elder_name[$i]);
780 $this->t->set_var('elder',$elder_id[$i]);
781 if(($j+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
782 else { $this->t->set_var('table_sep',"</td>"); }
783 if(($j) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
784 $this->t->fp('list','elder_list',True);
789 $this->t->set_var('lang_reset','Clear Form');
790 $this->t->set_var('lang_add','Add Activity');
791 $this->t->set_var('lang_save','Save Changes');
792 $this->t->set_var('edithandle','');
793 $this->t->set_var('addhandle','');
795 $this->t->pfp('out','form');
796 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
797 if($action == 'add') { $this->t->pfp('addhandle','add'); }
799 $this->save_sessiondata();
804 $this->t->set_file(array('par_view_t' => 'par_view.tpl'));
805 $this->t->set_block('par_view_t','header_list','list1');
806 $this->t->set_block('par_view_t','elder_list','list2');
808 $sql = "SELECT * FROM eq_elder where valid=1";
809 $this->db->query($sql,__LINE__,__FILE__);
811 while ($this->db->next_record())
813 $elder_name[$i] = $this->db->f('name');
814 $elder_id[$i] = $this->db->f('elder');
817 array_multisort($elder_name, $elder_id);
819 $sql = "SELECT * FROM eq_activity ORDER BY date DESC";
820 $this->db->query($sql,__LINE__,__FILE__);
821 $total_records = $this->db->num_rows();
824 while ($this->db->next_record())
826 $activity_list[$i]['name'] = $this->db->f('name');
827 $activity_list[$i]['date'] = $this->db->f('date');
828 $activity_list[$i]['activity'] = $this->db->f('activity');
829 if($activity_list[$i]['date'] == '0000-00-00') { $activity_list[$i]['date']=""; }
833 $elder_width=250; $part_width=25; $act_width=50;
834 $total_width=$elder_width+$part_width;
835 for ($i=0; $i < count($activity_list); $i++) {
836 $this->t->set_var('activity_name',$activity_list[$i]['name']);
837 $this->t->set_var('activity_date',$activity_list[$i]['date']);
838 $this->t->fp('list1','header_list',True);
839 $total_width += $act_width;
842 for ($i=0; $i < count($elder_id); $i++) {
843 $participated=0; $part_table = '';
844 $this->nextmatchs->template_alternate_row_color(&$this->t);
845 $this->t->set_var('elder_name',$elder_name[$i]);
846 for ($j=0; $j < count($activity_list); $j++) {
847 $sql = "SELECT * FROM eq_participation where activity="
848 . $activity_list[$j]['activity'] . " AND elder=" . $elder_id[$i];
849 $this->db->query($sql,__LINE__,__FILE__);
850 if($this->db->next_record()) {
851 $part_table .= '<td align=center><img src="checkmark.gif"></td>';
854 $part_table .= '<td> </td>';
857 if($participated) { $part_table .= '<td align=center><img src="checkmark.gif">'.$participated.'</td>'; }
858 else { $part_table .= '<td> </td>'; }
859 $this->t->set_var('part_table',$part_table);
860 $this->t->fp('list2','elder_list',True);
862 $this->t->set_var('total_width',$total_width);
863 $this->t->set_var('elder_width',$elder_width);
864 $this->t->set_var('part_width',$part_width);
865 $this->t->set_var('act_width',$act_width);
866 $this->t->pfp('out','par_view_t');
867 $this->save_sessiondata();
872 $this->t->set_file(array('ppi_sched_t' => 'ppi_sched.tpl'));
873 $this->t->set_block('ppi_sched_t','elder_list','elderlist');
874 $this->t->set_block('ppi_sched_t','appt_list','apptlist');
875 $action = get_var('action',array('GET','POST'));
877 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
878 $this->t->set_var('lang_reset','Clear Changes');
880 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
881 $this->t->set_var('ppi_link_title','Yearly PPIs');
883 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched'));
884 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
886 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched&action=save'));
887 $this->t->set_var('title','Yearly PPIs Scheduler');
889 $elder_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $ppi_date_width=20;
890 $table_width=$elder_width + $phone_width + $pri_width + $notes_width + $ppi_date_width;
891 $header_row = "<th width=$elder_width><font size=-2>Elder Name</th>";
892 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
893 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
894 $header_row.= "<th width=$ppi_date_width><font size=-2>Last PPI</th>";
895 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
896 $table_data=""; $completed_data=""; $totals_data="";
900 if($action == 'save')
902 // Save any changes made to the appointment table
903 $new_data = get_var('appt_notes',array('POST'));
904 foreach ($new_data as $entry)
906 $elder = $entry['elder'];
907 $appointment = $entry['appointment'];
909 //print "elder: $elder appointment: $appointment <br>";
911 // Perform database save actions here
912 $this->db->query("UPDATE eq_appointment set " .
913 " elder='" . $elder . "'" .
914 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
918 // Save any changes made to the ppi notes table
919 $new_data = get_var('ppi_notes',array('POST'));
920 foreach ($new_data as $entry)
922 $ppi_notes = $entry['notes'];
923 $elder_id = $entry['elder_id'];
924 $ppi_pri = $entry['pri'];
926 // Perform database save actions here
927 $this->db->query("UPDATE eq_elder set " .
928 " ppi_notes='" . $ppi_notes . "'" .
929 ",ppi_pri='" . $ppi_pri . "'" .
930 " WHERE elder=" . $elder_id,__LINE__,__FILE__);
934 $take_me_to_url = $GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched');
935 Header('Location: ' . $take_me_to_url);
939 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
940 $this->db->query($sql,__LINE__,__FILE__);
942 while ($this->db->next_record())
944 $districts[$i]['district'] = $this->db->f('district');
945 $districts[$i]['name'] = $this->db->f('name');
946 $districts[$i]['supervisor'] = $this->db->f('supervisor');
949 $districts[$i]['district'] = $i + 1;
950 $districts[$i]['name'] = "Unassigned";
951 $districts[$i]['supervisor'] = "Unassigned";
953 // create the elder id -> elder name mapping
954 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY name ASC";
955 $this->db->query($sql,__LINE__,__FILE__);
959 while ($this->db->next_record())
961 $elder_name[$i] = $this->db->f('name');
962 $elder_id[$i] = $this->db->f('elder');
965 array_multisort($elder_name, $elder_id);
969 $date_width=150; $time_width=100; $elder_width=200;
970 $appt_table_width=$date_width + $time_width + $elder_width;
971 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
972 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
973 $appt_header_row.= "<th width=$elder_width><font size=-2>Elder</th>";
974 $appt_table_data = "";
976 $total_elders=0; $elders_with_yearly_ppi=0;
978 // Display a scheduling table for each district
979 for ($d=0; $d < count($districts); $d++) {
980 $table_data=""; $appt_table_data="";
981 $this->t->set_var('district_number',$districts[$d]['district']);
982 $this->t->set_var('district_name',$districts[$d]['name']);
983 $supervisor = $districts[$d]['supervisor'];
984 $table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": All Elders with Yearly PPI Not Completed";
985 $appt_table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": Yearly PPI Appointment Slots";
986 $this->t->set_var('table_title',$table_title);
987 $this->t->set_var('appt_table_title',$appt_table_title);
989 // query the database for all the appointments
990 $sql = "SELECT * FROM eq_appointment where district=".$districts[$d]['district']." and date>=CURDATE() ORDER BY date ASC, time ASC";
991 $this->db->query($sql,__LINE__,__FILE__);
993 while ($this->db->next_record())
995 $appointment = $this->db->f('appointment');
996 $elder = $this->db->f('elder');
998 $date = $this->db->f('date');
999 $date_array = explode("-",$date);
1000 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1001 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1003 $time = $this->db->f('time');
1004 $time_array = explode(":",$time);
1005 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1007 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1008 $appt_table_data.= "<td align=center>$day_string</td>";
1009 $appt_table_data.= "<td align=center>$time_string</td>";
1011 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][elder]>';
1012 $appt_table_data.= '<option value=0></option>';
1013 for ($i=0; $i < count($elder_id); $i++) {
1014 $id = $elder_id[$i];
1015 $name = $elder_name[$i];
1016 if($elder_id[$i] == $elder) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
1017 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1019 $appt_table_data.='</select></td>';
1021 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1023 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1024 $this->t->set_var('tr_color',$tr_color);
1027 $this->t->set_var('appt_table_data',$appt_table_data);
1028 $this->t->set_var('appt_header_row',$appt_header_row);
1029 $this->t->set_var('appt_table_width',$appt_table_width);
1031 // PPI SCHEDULING TABLE
1032 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY ppi_pri ASC";
1033 $this->db->query($sql,__LINE__,__FILE__);
1037 while ($this->db->next_record())
1039 $sql2 = "SELECT * FROM eq_companionship where valid=1 and elder=".$this->db->f('elder');
1040 $this->db2->query($sql2,__LINE__,__FILE__);
1042 if(((!$this->db2->next_record()) && ($d == count($districts) - 1)) ||
1043 ($this->db2->f('district') == $districts[$d]['district'])) {
1044 $elder_id[$i] = $this->db->f('elder');
1045 $elder_name[$i] = $this->db->f('name');
1046 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
1047 $elder_ppi_pri[$elder_id[$i]] = $this->db->f('ppi_pri');
1048 $elder_ppi_notes[$elder_id[$i]] = $this->db->f('ppi_notes');
1054 $max = count($elder_id);
1056 for($i=0; $i < $max; $i++) {
1057 $id = $elder_id[$i];
1058 $name = $elder_name[$i];
1059 $phone = $elder_phone[$id];
1060 $ppi_pri = $elder_ppi_pri[$id];
1061 $ppi_notes = $elder_ppi_notes[$id];
1063 // If this elder has had a yearly PPI this year, don't show him on the schedule list
1064 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
1065 $sql = "SELECT * FROM eq_ppi WHERE date > '$year_start' AND date < '$year_end' ".
1067 $this->db2->query($sql,__LINE__,__FILE__);
1069 if(!$this->db2->next_record()) {
1070 $sql = "SELECT * FROM eq_ppi WHERE elder=" . $id . " ORDER BY date DESC";
1071 $this->db->query($sql,__LINE__,__FILE__);
1072 if($this->db->next_record()) { $date = $this->db->f('date'); } else { $date = ""; }
1073 $link_data['menuaction'] = 'eq.eq.ppi_update';
1074 $link_data['elder'] = $id;
1075 $link_data['aaronic'] = 0;
1076 $link_data['name'] = $name;
1077 $link_data['ppi'] = '';
1078 $link_data['eqpresppi'] = 1;
1079 $link_data['action'] = 'add';
1080 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1081 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1082 $table_data.= "<td align=center>$phone</td>";
1083 //$table_data.= "<td align=center>$ppi_pri</td>";
1084 $table_data.= "<td align=center>";
1085 $table_data.= '<select name=ppi_notes['.$i.'][pri]>';
1086 foreach(range(0,6) as $num) {
1087 if($num == 0) { $num = 1; } else {$num = $num*5; }
1088 if($ppi_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
1089 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1091 $table_data.= '</select></td>';
1092 $table_data.= "<td align=center>$date</td>";
1093 $table_data.= '<td><input type=text size="50" maxlength="128" name="ppi_notes['.$i.'][notes]" value="'.$ppi_notes.'">';
1094 $table_data.= '<input type=hidden name="ppi_notes['.$i.'][elder_id]" value="'.$id.'">';
1095 $table_data.= '<input type=hidden name="ppi_notes['.$i.'][elder_name]" value="'.$name.'">';
1096 $table_data.= '</td>';
1097 $table_data.= '</tr>';
1098 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1099 $this->t->set_var('tr_color',$tr_color);
1101 $link_data['menuaction'] = 'eq.eq.ppi_update';
1102 $link_data['interviewer'] = $this->db2->f('interviewer');
1103 $link_data['elder'] = $this->db2->f('elder');
1104 $link_data['aaronic'] = $this->db2->f('aaronic');
1105 $link_data['name'] = $name;
1106 $link_data['ppi'] = $this->db2->f('ppi');
1107 $link_data['eqpresppi'] = $this->db2->f('eqpresppi');
1108 $link_data['action'] = 'view';
1109 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1110 $elders_with_yearly_ppi++;
1111 $date = $this->db2->f('date');
1112 $ppi_notes = $this->db2->f('notes');
1113 if(strlen($ppi_notes) > 40) { $ppi_notes = substr($ppi_notes,0,40) . "..."; }
1114 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1115 $completed_data.= "<td align=center>$phone</td>";
1116 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1117 $completed_data.= "<td align=left>$ppi_notes</td>";
1118 $completed_data.= '</tr>';
1119 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1120 $this->t->set_var('tr_color2',$tr_color2);
1124 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1125 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1126 $completed_header_row = "<th width=$name_width><font size=-2>Elder Name</th>";
1127 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1128 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1129 $completed_header_row.= "<th width=$notes_width><font size=-2>PPI Notes</th>";
1131 $this->t->set_var('table_width',$table_width);
1132 $this->t->set_var('header_row',$header_row);
1133 $this->t->set_var('table_data',$table_data);
1134 $this->t->set_var('completed_header_row',$completed_header_row);
1135 $this->t->set_var('completed_table_width',$completed_table_width);
1136 $this->t->set_var('completed',$completed_data);
1137 $this->t->fp('elderlist','elder_list',True);
1139 } // End for each district loop
1141 // Now display a table of those elders not assigned to any companionships
1144 $elders_width=300; $totals_width=100;
1145 $totals_table_width=$elders_width + $totals_width;
1146 $totals_header_row = "<th width=$elders_width><font size=-2>Elders</th>";
1147 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
1148 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1149 $totals_data.= "<td align=left><font size=-2><b>Total Elders with yearly PPIs completed:</b></font></td>";
1150 $totals_data.= "<td align=center><font size=-2><b>$elders_with_yearly_ppi / $total_elders</b></font></td>";
1151 $percent = ceil(($elders_with_yearly_ppi / $total_elders)*100);
1152 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1153 $this->t->set_var('tr_color',$tr_color);
1154 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1155 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
1156 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
1157 $totals_data.= "</tr>";
1159 $this->t->set_var('totals',$totals_data);
1160 $this->t->set_var('totals_header_row',$totals_header_row);
1161 $this->t->set_var('totals_table_width',$totals_table_width);
1163 $this->t->pfp('out','ppi_sched_t');
1164 $this->save_sessiondata();
1168 function vis_sched()
1170 $this->t->set_file(array('vis_sched_t' => 'vis_sched.tpl'));
1171 $this->t->set_block('vis_sched_t','family_list','familylist');
1172 $this->t->set_block('vis_sched_t','appt_list','apptlist');
1173 $action = get_var('action',array('GET','POST'));
1175 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1176 $this->t->set_var('lang_reset','Clear Changes');
1178 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
1179 $this->t->set_var('vis_link_title','View Yearly Visits');
1181 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched'));
1182 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
1184 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched&action=save'));
1185 $this->t->set_var('title','EQ Presidency Yearly Visit Scheduler');
1187 $family_width=500; $phone_width=40; $pri_width=10; $notes_width=128; $visit_date_width=20;
1188 $table_width=$family_width + $phone_width + $pri_width + $notes_width + $visit_date_width;
1189 $header_row = "<th width=$family_width><font size=-2>Family Name</th>";
1190 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1191 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1192 $header_row.= "<th width=$visit_date_width><font size=-2>Last Visit</th>";
1193 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1194 $table_data=""; $completed_data=""; $totals_data="";
1198 if($action == 'save')
1200 // Save any changes made to the appointment table
1201 $new_data = get_var('appt_notes',array('POST'));
1202 foreach ($new_data as $entry)
1204 $family = $entry['family'];
1205 $appointment = $entry['appointment'];
1207 // Perform database save actions here
1208 $this->db->query("UPDATE eq_appointment set " .
1209 " family='" . $family . "'" .
1210 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1214 // Save any changes made to the visit notes table
1215 $new_data = get_var('vis_notes',array('POST'));
1216 foreach ($new_data as $entry)
1218 $visit_notes = $entry['notes'];
1219 $family_id = $entry['family_id'];
1220 $visit_pri = $entry['pri'];
1222 // Perform database save actions here
1223 $this->db->query("UPDATE eq_family set " .
1224 " visit_notes='" . $visit_notes . "'" .
1225 ",visit_pri='" . $visit_pri . "'" .
1226 " WHERE family=" . $family_id,__LINE__,__FILE__);
1230 $take_me_to_url = $GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched');
1231 Header('Location: ' . $take_me_to_url);
1234 // APPOINTMENT TABLE
1236 $date_width=150; $time_width=100; $family_width=250;
1237 $appt_table_width=$date_width + $time_width + $family_width;
1238 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1239 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1240 $appt_header_row.= "<th width=$family_width><font size=-2>Family</th>";
1241 $appt_table_data = "";
1243 // create the family id -> family name mapping
1244 $sql = "SELECT * FROM eq_family where valid=1 and elder_id != 0 ORDER BY name ASC";
1245 $this->db->query($sql,__LINE__,__FILE__);
1248 while ($this->db->next_record())
1250 $family_id[$i] = $this->db->f('family');
1251 $family_name[$i] = $this->db->f('name');
1254 array_multisort($family_name, $family_id);
1256 // query the database for all the appointments
1257 $sql = "SELECT * FROM eq_appointment where district=$district and date>=CURDATE() ORDER BY date ASC, time ASC";
1258 $this->db->query($sql,__LINE__,__FILE__);
1260 while ($this->db->next_record())
1262 $appointment = $this->db->f('appointment');
1263 $family = $this->db->f('family');
1265 $date = $this->db->f('date');
1266 $date_array = explode("-",$date);
1267 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1268 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1270 $time = $this->db->f('time');
1271 $time_array = explode(":",$time);
1272 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1274 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1275 $appt_table_data.= "<td align=center>$day_string</td>";
1276 $appt_table_data.= "<td align=center>$time_string</td>";
1278 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][family]>';
1279 $appt_table_data.= '<option value=0></option>';
1280 for ($i=0; $i < count($family_id); $i++) {
1281 $id = $family_id[$i];
1282 $name = $family_name[$i];
1283 if($family_id[$i] == $family) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
1284 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
1286 $appt_table_data.='</select></td>';
1288 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1290 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1291 $this->t->set_var('tr_color',$tr_color);
1294 $this->t->set_var('appt_table_data',$appt_table_data);
1295 $this->t->set_var('appt_header_row',$appt_header_row);
1296 $this->t->set_var('appt_table_width',$appt_table_width);
1299 // VISIT SCHEDULING TABLE
1300 $sql = "SELECT * FROM eq_family where valid=1 and elder_id != 0 ORDER BY visit_pri ASC";
1301 $this->db->query($sql,__LINE__,__FILE__);
1303 $total_families=0; $families_with_yearly_visit=0;
1307 $family_name = NULL;
1308 $family_phone = NULL;
1309 $family_visit_pri = NULL;
1310 $family_visit_notes = NULL;
1311 while ($this->db->next_record())
1313 $family_id[$i] = $this->db->f('family');
1314 $family_name[$i] = $this->db->f('name');
1315 $family_phone[$family_id[$i]] = $family_id[$i] . " ERROR";
1316 $family_visit_pri[$family_id[$i]] = $this->db->f('visit_pri');
1317 $family_visit_notes[$family_id[$i]] = $this->db->f('visit_notes');
1322 $sql = "SELECT * FROM eq_parent where valid=1";
1323 $this->db->query($sql,__LINE__,__FILE__);
1324 while ($this->db->next_record())
1326 $family = $this->db->f('family');
1327 $phone = $this->db->f('phone');
1328 $family_phone[$family] = $phone;
1331 $max = count($family_id);
1333 for($i=0; $i < $max; $i++) {
1334 $id = $family_id[$i];
1335 $name = $family_name[$i];
1336 $phone = $family_phone[$id];
1337 $vis_pri = $family_visit_pri[$id];
1338 $vis_notes = $family_visit_notes[$id];
1340 // If this family has had a yearly visit this year, don't show them on the schedule list
1341 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
1342 $sql = "SELECT * FROM eq_visit WHERE date > '$year_start' AND date < '$year_end' ".
1343 "AND family=" . $id . " AND companionship=0";
1344 $this->db2->query($sql,__LINE__,__FILE__);
1346 if(!$this->db2->next_record()) {
1347 $sql = "SELECT * FROM eq_visit WHERE family=" . $id . " AND companionship=0 ORDER BY date DESC";
1348 $this->db->query($sql,__LINE__,__FILE__);
1349 if($this->db->next_record()) { $date = $this->db->f('date'); } else { $date = ""; }
1350 $link_data['menuaction'] = 'eq.eq.vis_update';
1351 $link_data['visit'] = '';
1352 $link_data['family'] = $id;
1353 $link_data['name'] = $name;
1354 $link_data['action'] = 'add';
1355 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1356 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
1357 $table_data.= "<td align=center>$phone</td>";
1358 $table_data.= "<td align=center>";
1359 $table_data.= '<select name=vis_notes['.$i.'][pri]>';
1360 foreach(range(0,6) as $num) {
1361 if($num == 0) { $num = 1; } else {$num = $num*5; }
1362 if($vis_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
1363 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1365 $table_data.= '</select></td>';
1366 $table_data.= "<td align=center>$date</td>";
1367 $table_data.= '<td><input type=text size="50" maxlength="128" name="vis_notes['.$i.'][notes]" value="'.$vis_notes.'">';
1368 $table_data.= '<input type=hidden name="vis_notes['.$i.'][family_id]" value="'.$id.'">';
1369 $table_data.= '<input type=hidden name="vis_notes['.$i.'][family_name]" value="'.$name.'">';
1370 $table_data.= '</td>';
1371 $table_data.= '</tr>';
1372 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1373 $this->t->set_var('tr_color',$tr_color);
1375 $link_data['menuaction'] = 'eq.eq.vis_update';
1376 $link_data['visit'] = $this->db2->f('visit');
1377 $link_data['family'] = $this->db2->f('family');
1378 $link_data['name'] = $name;
1379 $link_data['date'] = $this->db2->f('date');
1380 $link_data['action'] = 'view';
1381 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1382 $families_with_yearly_visit++;
1383 $date = $this->db2->f('date');
1384 $vis_notes = $this->db2->f('notes');
1385 if(strlen($vis_notes) > 40) { $vis_notes = substr($vis_notes,0,40) . "..."; }
1386 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
1387 $completed_data.= "<td align=center>$phone</td>";
1388 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1389 $completed_data.= "<td align=left>$vis_notes</td>";
1390 $completed_data.= '</tr>';
1391 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1392 $this->t->set_var('tr_color2',$tr_color2);
1396 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1397 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1398 $completed_header_row = "<th width=$name_width><font size=-2>Family Name</th>";
1399 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1400 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1401 $completed_header_row.= "<th width=$notes_width><font size=-2>Visit Notes</th>";
1403 $family_width=300; $totals_width=100;
1404 $totals_table_width=$family_width + $totals_width;
1405 $totals_header_row = "<th width=$family_width><font size=-2>Families</th>";
1406 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
1407 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1408 $totals_data.= "<td align=left><font size=-2><b>Total Families with yearly Visits completed:</b></font></td>";
1409 $totals_data.= "<td align=center><font size=-2><b>$families_with_yearly_visit / $total_families</b></font></td>";
1410 $percent = ceil(($families_with_yearly_visit / $total_families)*100);
1411 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1412 $this->t->set_var('tr_color',$tr_color);
1413 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1414 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
1415 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
1416 $totals_data.= "</tr>";
1418 $this->t->set_var('table_width',$table_width);
1419 $this->t->set_var('header_row',$header_row);
1420 $this->t->set_var('table_data',$table_data);
1421 $this->t->set_var('totals_header_row',$totals_header_row);
1422 $this->t->set_var('totals_table_width',$totals_table_width);
1423 $this->t->set_var('completed_header_row',$completed_header_row);
1424 $this->t->set_var('completed_table_width',$completed_table_width);
1425 $this->t->set_var('completed',$completed_data);
1426 $this->t->set_var('totals',$totals_data);
1427 $this->t->fp('familylist','family_list',True);
1428 $this->t->fp('apptlist','appt_list',True);
1430 $this->t->pfp('out','vis_sched_t');
1431 $this->save_sessiondata();
1437 $this->t->set_file(array('ppi_view_t' => 'ppi_view.tpl'));
1438 $this->t->set_block('ppi_view_t','district_list','list');
1440 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
1441 $num_months = get_var('num_months',array('GET','POST'));
1442 if($num_months == '') { $num_months = $this->default_ppi_num_months; }
1443 $this->t->set_var('num_months',$num_months);
1444 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
1445 else { $this->t->set_var('lang_num_months','Months of History'); }
1446 $this->t->set_var('lang_filter','Filter');
1447 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
1449 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
1450 $this->t->set_var('ppi_link_title','Yearly PPIs');
1453 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched'));
1454 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
1456 $this->t->set_var('title','Yearly PPIs');
1457 $num_months = get_var('num_months',array('GET','POST'));
1458 if($num_months == '') { $num_months = $this->default_ppi_num_years; }
1459 $this->t->set_var('num_months',$num_months);
1460 if($num_months == 1) { $this->t->set_var('lang_num_months','Year of History'); }
1461 else { $this->t->set_var('lang_num_months','Years of History'); }
1463 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
1464 $this->db->query($sql,__LINE__,__FILE__);
1466 while ($this->db->next_record())
1468 $districts[$i]['district'] = $this->db->f('district');
1469 $districts[$i]['name'] = $this->db->f('name');
1470 $districts[$i]['supervisor'] = $this->db->f('supervisor');
1474 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
1475 $this->db->query($sql,__LINE__,__FILE__);
1477 while ($this->db->next_record())
1479 $elder_id[$i] = $this->db->f('elder');
1480 $elder_name[$i] = $this->db->f('name');
1481 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
1482 $elder_ppi_pri[$elder_id[$i]] = $this->db->f('ppi_pri');
1483 $elder_ppi_notes[$elder_id[$i]] = $this->db->f('ppi_notes');
1486 array_multisort($elder_name, $elder_id);
1487 for($i=0; $i < count($elder_id); $i++) {
1488 $id = $elder_id[$i];
1489 $elders[$id] = $elder_name[$i];
1492 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
1493 $this->db->query($sql,__LINE__,__FILE__);
1494 while ($this->db->next_record())
1496 $aaronic_id = $this->db->f('aaronic');
1497 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
1498 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
1501 $total_companionships = 0;
1503 $this->nextmatchs->template_alternate_row_color(&$this->t);
1504 for ($i=0; $i < count($districts); $i++) {
1505 $this->t->set_var('district_number',$districts[$i]['district']);
1506 $this->t->set_var('district_name',$districts[$i]['name']);
1507 $supervisor = $districts[$i]['supervisor'];
1508 $unique_companionships='';
1510 // Select all the unique companionship numbers for this district
1511 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $districts[$i]['district'];
1513 $this->db->query($sql,__LINE__,__FILE__);
1515 while ($this->db->next_record())
1517 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
1521 $comp_width=400; $ppi_width=75; $table_width=$comp_width + $num_months*$ppi_width;
1522 $table_data=""; $num_companionships = $j; $num_elders = 0;
1523 for($m=$num_months; $m >= 0; $m--) { $ppis[$m] = 0; }
1524 for ($j=0; $j < count($unique_companionships); $j++) {
1525 // Select all the companions in each companionship
1526 $sql = "SELECT * FROM eq_companionship where valid=1 and aaronic=0 and ".
1527 "companionship=". $unique_companionships[$j]['companionship'];
1528 $this->db->query($sql,__LINE__,__FILE__);
1530 $comp = $unique_companionships[$j]['companionship'];
1531 for($m=$num_months; $m >= 0; $m--) { $ppi_recorded[$comp][$m] = 0; }
1532 while ($this->db->next_record())
1534 // Get this companions information
1536 $companionship = $this->db->f('companionship');
1537 $elder_id = $this->db->f('elder');
1538 $aaronic_id = $this->db->f('aaronic');
1540 $name = $elders[$elder_id];
1541 $phone = $elder_phone[$elder_id];
1543 else if($aaronic_id) {
1544 $name = $aaronic[$aaronic_id]['name'];
1545 $phone = $aaronic[$aaronic_id]['phone'];
1547 $link_data['menuaction'] = 'eq.eq.ppi_update';
1548 $link_data['companionship'] = $companionship;
1549 $link_data['interviewer'] = $supervisor;
1550 $link_data['elder'] = $elder_id;
1551 $link_data['aaronic'] = $aaronic_id;
1552 $link_data['name'] = $name;
1553 $link_data['ppi'] = '';
1554 $link_data['eqpresppi'] = $eqpresppi;
1555 $link_data['action'] = 'add';
1556 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1557 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1559 // Find out how many times PPIs were performed in the past $num_months for this Elder
1560 $header_row="<th width=$comp_width><font size=-2>Companionship</th>";
1561 for($m=$num_months; $m >= 0; $m--) {
1562 $year = date('Y') - $m;
1563 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
1564 $sql = "SELECT * FROM eq_ppi WHERE date > '$year_start' AND date < '$year_end' ".
1565 "AND elder=" . $elder_id . " AND aaronic=" . $aaronic_id;
1566 $this->db2->query($sql,__LINE__,__FILE__);
1567 $header_row .= "<th width=150><font size=-2>$year</th>";
1569 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
1570 if($this->db2->next_record()) {
1571 $ppis[$m]++; $total_ppis[$m]++; $ppi_recorded[$companionship][$m]=1;
1572 $link_data['menuaction'] = 'eq.eq.ppi_update';
1573 $link_data['companionship'] = $companionship;
1574 $link_data['interviewer'] = $this->db2->f('interviewer');
1575 $link_data['elder'] = $elder_id;
1576 $link_data['aaronic'] = $aaronic_id;
1577 $link_data['name'] = $name;
1578 $link_data['ppi'] = $this->db2->f('ppi');
1579 $link_data['eqpresppi'] = $eqpresppi;
1580 $link_data['action'] = 'view';
1581 $date = $this->db2->f('date');
1582 $date_array = explode("-",$date);
1583 $month = $date_array[1];
1584 $day = $date_array[2];
1585 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1586 $table_data .= '<td align=center><a href='.$link.'><img src="checkmark.gif"> '.$month.'-'.$day.'</a></td>';
1588 else { $table_data .= "<td> </td>"; }
1590 $table_data .= "</tr>";
1593 $table_data .= "<tr><td colspan=20><hr></td></tr>";
1596 $total_companionships += $num_companionships;
1597 $total_elders += $num_elders;
1598 $stat_data = "<tr><td><b><font size=-2>$num_elders Elders<br>PPI Totals:</font></b></td>";
1600 for($m=$num_months; $m >=0; $m--) {
1601 $percent = ceil(($ppis[$m] / $num_elders)*100);
1602 $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
1604 $stat_data .= "</tr>";
1605 $this->t->set_var('table_width',$table_width);
1606 $this->t->set_var('header_row',$header_row);
1607 $this->t->set_var('table_data',$table_data);
1608 $this->t->set_var('stat_data',$stat_data);
1609 $this->t->fp('list','district_list',True);
1612 // Now add Elders not assigned to any companionship to the table
1616 $this->t->set_var('district_number','*');
1617 $this->t->set_var('district_name','Unassigned Potential Home Teachers');
1618 for($m=$num_months; $m >= 0; $m--) { $ppis[$m] = 0; }
1619 foreach($elders as $elder_id => $value) {
1620 $header_row="<th width=$comp_width><font size=-2>Elder</th>";
1621 $sql = "SELECT * FROM eq_companionship where valid=1 and elder=".$elder_id;
1622 $this->db->query($sql,__LINE__,__FILE__);
1623 if(!$this->db->next_record()) {
1624 // We found an Elder not in a companionship, add them to the table
1627 $name = $elders[$elder_id];
1628 $phone = $elder_phone[$elder_id];
1629 $link_data['menuaction'] = 'eq.eq.ppi_update';
1630 $link_data['companionship'] = $companionship;
1631 $link_data['interviewer'] = $supervisor;
1632 $link_data['elder'] = $elder_id;
1633 $link_data['name'] = $name;
1634 $link_data['ppi'] = '';
1635 $link_data['eqpresppi'] = $eqpresppi;
1636 $link_data['action'] = 'add';
1637 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1638 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1639 for($m=$num_months; $m >= 0; $m--) {
1640 $year = date('Y') - $m;
1641 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
1642 $sql = "SELECT * FROM eq_ppi WHERE date > '$year_start' AND date < '$year_end' ".
1643 "AND elder=" . $elder_id;
1644 $this->db2->query($sql,__LINE__,__FILE__);
1645 $header_row .= "<th width=150><font size=-2>$year</th>";
1647 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
1648 if($this->db2->next_record()) {
1649 $ppis[$m]++; $total_ppis[$m]++;
1650 $link_data['menuaction'] = 'eq.eq.ppi_update';
1651 $link_data['companionship'] = $companionship;
1652 $link_data['interviewer'] = $supervisor;
1653 $link_data['elder'] = $elder_id;
1654 $link_data['name'] = $name;
1655 $link_data['ppi'] = $this->db2->f('ppi');
1656 $link_data['eqpresppi'] = $eqpresppi;
1657 $link_data['action'] = 'view';
1658 $date = $this->db2->f('date');
1659 $date_array = explode("-",$date);
1660 $month = $date_array[1];
1661 $day = $date_array[2];
1662 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1663 $table_data .= '<td align=center><a href='.$link.'><img src="checkmark.gif"> '.$month.'-'.$day.'</a></td>';
1665 else { $table_data .= "<td> </td>"; }
1667 $table_data .= "</tr>";
1671 $total_companionships += $num_companionships;
1672 $total_elders += $num_elders;
1673 $stat_data = "<tr><td><b><font size=-2>$num_elders Elders<br>PPI Totals:</font></b></td>";
1675 for($m=$num_months; $m >=0; $m--) {
1676 $percent = ceil(($ppis[$m] / $num_elders)*100);
1677 $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
1679 $stat_data .= "</tr>";
1681 $this->t->set_var('table_width',$table_width);
1682 $this->t->set_var('header_row',$header_row);
1683 $this->t->set_var('table_data',$table_data);
1684 $this->t->set_var('stat_data',$stat_data);
1685 $this->t->fp('list','district_list',True);
1687 $totals = "<tr><td><b><font size=-2>$total_elders Total Elders<br>PPI Totals:</font></b></td>";
1688 for($m=$num_months; $m >=0; $m--) {
1689 $percent = ceil(($total_ppis[$m] / $total_elders)*100);
1690 $totals .= "<td align=center><font size=-2><b>$total_ppis[$m]<br>$percent%</font></b></td>";
1694 $this->t->set_var('totals',$totals);
1695 $this->t->pfp('out','ppi_view_t');
1696 $this->save_sessiondata();
1699 function ppi_update()
1701 $this->t->set_file(array('form' => 'ppi_update.tpl'));
1702 $this->t->set_block('form','interviewer_list','int_list');
1703 $this->t->set_block('form','add','addhandle');
1704 $this->t->set_block('form','edit','edithandle');
1706 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
1707 $this->t->set_var('readonly','');
1708 $this->t->set_var('disabled','');
1710 $action = get_var('action',array('GET','POST'));
1711 $companionship = get_var('companionship',array('GET','POST'));
1712 $interviewer = get_var('interviewer',array('GET','POST'));
1713 $name = get_var('name',array('GET','POST'));
1714 $ppi = get_var('ppi',array('GET','POST'));
1715 $elder = get_var('elder',array('GET','POST'));
1716 $aaronic = get_var('aaronic',array('GET','POST'));
1717 $date = get_var('date',array('GET','POST'));
1718 $notes = get_var('notes',array('GET','POST'));
1719 $eqpresppi = get_var('eqpresppi',array('GET','POST'));
1721 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
1722 $this->db->query($sql,__LINE__,__FILE__);
1723 while ($this->db->next_record())
1725 $supervisor = $this->db->f('supervisor');
1726 $sql = "SELECT * FROM eq_elder WHERE elder=" . $supervisor;
1727 $this->db2->query($sql,__LINE__,__FILE__);
1728 $this->db2->next_record();
1729 $interviewer_name = $this->db2->f('name');
1731 if($supervisor == $interviewer) {
1732 $this->t->set_var('interviewer',$supervisor . ' selected');
1734 $this->t->set_var('interviewer',$interviewer);
1736 $this->t->set_var('interviewer_name',$interviewer_name);
1737 $this->t->fp('int_list','interviewer_list',True);
1740 if($action == 'save')
1742 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
1743 $this->db->query("UPDATE eq_ppi set " .
1744 " ppi='" . $ppi . "'" .
1745 ", interviewer='" . $interviewer . "'" .
1746 ", elder='" . $elder . "'" .
1747 ", aaronic='" . $aaronic . "'" .
1748 ", date='" . $date . "'" .
1749 ", notes='" . $notes . "'" .
1750 ", eqpresppi='" . $eqpresppi . "'" .
1751 " WHERE ppi=" . $ppi,__LINE__,__FILE__);
1756 if($action == 'insert')
1758 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
1759 $this->db->query("INSERT INTO eq_ppi (interviewer,elder,aaronic,date,notes,eqpresppi) "
1760 . "VALUES ('" . $interviewer . "','" . $elder . "','" . $aaronic . "','"
1761 . $date . "','" . $notes . "','" . $eqpresppi ."')",__LINE__,__FILE__);
1766 if($action == 'add')
1768 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
1769 $this->t->set_var('ppi', '');
1770 $this->t->set_var('interviewer', $interviewer);
1771 $this->t->set_var('name',$name);
1772 $this->t->set_var('elder',$elder);
1773 $this->t->set_var('aaronic',$aaronic);
1774 $this->t->set_var('date','');
1775 $this->t->set_var('notes','');
1776 $this->t->set_var('eqpresppi',$eqpresppi);
1777 $this->t->set_var('lang_done','Cancel');
1778 $this->t->set_var('lang_action','Adding New PPI');
1779 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
1780 . $ppi . '&action=' . 'insert'));
1783 if($action == 'edit' || $action == 'view')
1785 $sql = "SELECT * FROM eq_ppi WHERE ppi=".$ppi;
1786 $this->db->query($sql,__LINE__,__FILE__);
1787 $this->db->next_record();
1788 $this->t->set_var('ppi',$ppi);
1789 $this->t->set_var('name',$name);
1790 $this->t->set_var('interviewer', $this->db->f('interviewer'));
1791 $this->t->set_var('elder',$this->db->f('elder'));
1792 $this->t->set_var('aaronic',$this->db->f('aaronic'));
1793 $this->t->set_var('date',$this->db->f('date'));
1794 $this->t->set_var('notes',$this->db->f('notes'));
1795 $this->t->set_var('eqpresppi',$this->db->f('eqpresppi'));
1798 if($action == 'edit')
1800 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
1801 $this->t->set_var('lang_done','Cancel');
1802 $this->t->set_var('lang_action','Editing PPI');
1803 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
1804 . $ppi . '&action=' . 'save'));
1807 if($action == 'view')
1809 $date = $this->db->f('date');
1810 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
1811 $this->t->set_var('readonly','READONLY');
1812 $this->t->set_var('disabled','DISABLED');
1813 $this->t->set_var('lang_done','Done');
1814 $this->t->set_var('lang_action','Viewing PPI');
1815 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
1816 . $ppi . '&action=' . 'edit'));
1819 $this->t->set_var('lang_reset','Clear Form');
1820 $this->t->set_var('lang_add','Add PPI');
1821 $this->t->set_var('lang_save','Save Changes');
1822 $this->t->set_var('edithandle','');
1823 $this->t->set_var('addhandle','');
1825 $this->t->pfp('out','form');
1827 if($action == 'view') { $this->t->set_var('lang_save','Edit PPI'); }
1828 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
1829 if($action == 'add') { $this->t->pfp('addhandle','add'); }
1831 $this->save_sessiondata();
1836 $this->t->set_file(array('int_view_t' => 'int_view.tpl'));
1837 $this->t->set_block('int_view_t','district_list','list');
1839 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_view'));
1840 $num_months = get_var('num_months',array('GET','POST'));
1841 if($num_months == '') { $num_months = $this->default_int_num_months; }
1842 $this->t->set_var('num_months',$num_months);
1843 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
1844 else { $this->t->set_var('lang_num_months','Months of History'); }
1845 $this->t->set_var('lang_filter','Filter');
1846 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_view'));
1848 $this->t->set_var('title','Hometeaching Interviews');
1850 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
1851 $this->db->query($sql,__LINE__,__FILE__);
1853 while ($this->db->next_record())
1855 $districts[$i]['district'] = $this->db->f('district');
1856 $districts[$i]['name'] = $this->db->f('name');
1857 $districts[$i]['supervisor'] = $this->db->f('supervisor');
1861 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
1862 $this->db->query($sql,__LINE__,__FILE__);
1864 while ($this->db->next_record())
1866 $elder_id[$i] = $this->db->f('elder');
1867 $elder_name[$i] = $this->db->f('name');
1868 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
1871 array_multisort($elder_name, $elder_id);
1872 for($i=0; $i < count($elder_id); $i++) {
1873 $id = $elder_id[$i];
1874 $elders[$id] = $elder_name[$i];
1877 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
1878 $this->db->query($sql,__LINE__,__FILE__);
1879 while ($this->db->next_record())
1881 $aaronic_id = $this->db->f('aaronic');
1882 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
1883 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
1886 $total_companionships = 0;
1887 $this->nextmatchs->template_alternate_row_color(&$this->t);
1888 for ($i=0; $i < count($districts); $i++) {
1889 $this->t->set_var('district_number',$districts[$i]['district']);
1890 $this->t->set_var('district_name',$districts[$i]['name']);
1891 $supervisor = $districts[$i]['supervisor'];
1892 $unique_companionships='';
1894 // Select all the unique companionship numbers for this district
1895 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $districts[$i]['district'];
1897 $this->db->query($sql,__LINE__,__FILE__);
1899 while ($this->db->next_record())
1901 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
1905 $comp_width=250; $int_width=75; $table_width=$comp_width + $num_months*$int_width;
1906 $table_data=""; $num_companionships = $j; $num_elders = 0;
1907 for($m=$num_months; $m >= 0; $m--) { $ints[$m] = 0; }
1908 for ($j=0; $j < count($unique_companionships); $j++) {
1909 // Select all the companions in each companionship
1910 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
1911 "companionship=". $unique_companionships[$j]['companionship'];
1912 $this->db->query($sql,__LINE__,__FILE__);
1914 $comp = $unique_companionships[$j]['companionship'];
1915 for($m=$num_months; $m >= 0; $m--) { $int_recorded[$comp][$m] = 0; }
1916 while ($this->db->next_record())
1918 // Get this companions information
1920 $companionship = $this->db->f('companionship');
1921 $elder_id = $this->db->f('elder');
1922 $aaronic_id = $this->db->f('aaronic');
1924 $name = $elders[$elder_id];
1925 $phone = $elder_phone[$elder_id];
1927 else if($aaronic_id) {
1928 $name = $aaronic[$aaronic_id]['name'];
1929 $phone = $aaronic[$aaronic_id]['phone'];
1931 $link_data['menuaction'] = 'eq.eq.int_update';
1932 $link_data['companionship'] = $companionship;
1933 $link_data['interviewer'] = $supervisor;
1934 $link_data['elder'] = $elder_id;
1935 $link_data['aaronic'] = $aaronic_id;
1936 $link_data['name'] = $name;
1937 $link_data['interview'] = '';
1938 $link_data['action'] = 'add';
1939 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1940 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1942 // Find out how many times Interviews were performed in the past $num_months for this Elder
1943 $header_row="<th width=$comp_width><font size=-2>Companionship</th>";
1944 for($m=$num_months; $m >= 0; $m--) {
1945 $month = $this->current_month - $m;
1946 $year = $this->current_year;
1947 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
1948 if($month < 10) { $month = "0"."$month"; }
1949 $month_start = "$year"."-"."$month"."-"."01";
1950 $month_end = "$year"."-"."$month"."-"."31";
1951 $month = "$month"."/"."$year";
1952 $sql = "SELECT * FROM eq_interview WHERE date >= '$month_start' AND date <= '$month_end' ".
1953 "AND elder=" . $elder_id . " AND aaronic=" . $aaronic_id;
1954 $this->db2->query($sql,__LINE__,__FILE__);
1955 $header_row .= "<th width=$int_width><font size=-2>$month</th>";
1957 if(!$total_ints[$m]) { $total_ints[$m] = 0; }
1958 if($this->db2->next_record()) {
1959 if(!$int_recorded[$companionship][$m]) {
1960 $ints[$m]++; $total_ints[$m]++; $int_recorded[$companionship][$m]=1;
1962 $link_data['menuaction'] = 'eq.eq.int_update';
1963 $link_data['companionship'] = $companionship;
1964 $link_data['interviewer'] = $this->db2->f('interviewer');
1965 $link_data['elder'] = $elder_id;
1966 $link_data['aaronic'] = $aaronic_id;
1967 $link_data['name'] = $name;
1968 $link_data['interview'] = $this->db2->f('interview');
1969 $link_data['action'] = 'view';
1970 $date = $this->db2->f('date');
1971 $date_array = explode("-",$date);
1972 $month = $date_array[1];
1973 $day = $date_array[2];
1974 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1975 $table_data .= '<td align=center><a href='.$link.'><img src="checkmark.gif"> '.$month.'-'.$day.'</a></td>';
1977 else { $table_data .= "<td> </td>"; }
1979 $table_data .= "</tr>";
1982 $table_data .= "<tr><td colspan=20><hr></td></tr>";
1984 $total_companionships += $num_companionships;
1985 $stat_data = "<tr><td><b><font size=-2>$num_companionships Companionships<br>Interview Quarterly Totals:</font></b></td>";
1987 for($m=$num_months; $m >=0; $m--) {
1988 $month = $this->current_month - $m;
1989 if(($month % 3) == 1) { $quarter_total = $ints[$m]; }
1990 else { $quarter_total += $ints[$m]; }
1991 $percent = ceil(($quarter_total / $num_companionships)*100);
1992 $stat_data .= "<td align=center><font size=-2><b>$quarter_total<br>$percent%</font></b></td>";
1994 $stat_data .= "</tr>";
1996 $this->t->set_var('table_width',$table_width);
1997 $this->t->set_var('header_row',$header_row);
1998 $this->t->set_var('table_data',$table_data);
1999 $this->t->set_var('stat_data',$stat_data);
2000 $this->t->fp('list','district_list',True);
2003 // Display the totals, cummulative per quarter
2005 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>Interview Quarterly Totals:</font></b></td>";
2006 for($m=$num_months; $m >=0; $m--) {
2007 $month = $this->current_month - $m;
2008 if(($month % 3) == 1) { $quarter_total = $total_ints[$m]; }
2009 else { $quarter_total += $total_ints[$m]; }
2010 $percent = ceil(($quarter_total / $total_companionships)*100);
2011 $totals .= "<td align=center><font size=-2><b>$quarter_total<br>$percent%</font></b></td>";
2015 $this->t->set_var('totals',$totals);
2016 $this->t->pfp('out','int_view_t');
2017 $this->save_sessiondata();
2020 function int_update()
2022 $this->t->set_file(array('form' => 'int_update.tpl'));
2023 $this->t->set_block('form','interviewer_list','int_list');
2024 $this->t->set_block('form','add','addhandle');
2025 $this->t->set_block('form','edit','edithandle');
2027 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_view'));
2028 $this->t->set_var('readonly','');
2029 $this->t->set_var('disabled','');
2031 $action = get_var('action',array('GET','POST'));
2032 $companionship = get_var('companionship',array('GET','POST'));
2033 $interviewer = get_var('interviewer',array('GET','POST'));
2034 $name = get_var('name',array('GET','POST'));
2035 $interview = get_var('interview',array('GET','POST'));
2036 $elder = get_var('elder',array('GET','POST'));
2037 $aaronic = get_var('aaronic',array('GET','POST'));
2038 $date = get_var('date',array('GET','POST'));
2039 $notes = get_var('notes',array('GET','POST'));
2041 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
2042 $this->db->query($sql,__LINE__,__FILE__);
2043 while ($this->db->next_record())
2045 $supervisor = $this->db->f('supervisor');
2046 $sql = "SELECT * FROM eq_elder WHERE elder=" . $supervisor;
2047 $this->db2->query($sql,__LINE__,__FILE__);
2048 $this->db2->next_record();
2049 $interviewer_name = $this->db2->f('name');
2051 if($supervisor == $interviewer) {
2052 $this->t->set_var('interviewer',$supervisor . ' selected');
2054 $this->t->set_var('interviewer',$interviewer);
2056 $this->t->set_var('interviewer_name',$interviewer_name);
2057 $this->t->fp('int_list','interviewer_list',True);
2060 if($action == 'save')
2062 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
2063 $this->db->query("UPDATE eq_interview set " .
2064 " interview='" . $interview . "'" .
2065 ", interviewer='" . $interviewer . "'" .
2066 ", elder='" . $elder . "'" .
2067 ", aaronic='" . $aaronic . "'" .
2068 ", date='" . $date . "'" .
2069 ", notes='" . $notes . "'" .
2070 " WHERE interview=" . $interview,__LINE__,__FILE__);
2075 if($action == 'insert')
2077 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
2078 $this->db->query("INSERT INTO eq_interview (interviewer,elder,aaronic,date,notes) "
2079 . "VALUES ('" . $interviewer . "','" . $elder . "','" . $aaronic . "','"
2080 . $date . "','" . $notes ."')",__LINE__,__FILE__);
2085 if($action == 'add')
2087 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2088 $this->t->set_var('interview', '');
2089 $this->t->set_var('interviewer', $interviewer);
2090 $this->t->set_var('name',$name);
2091 $this->t->set_var('elder',$elder);
2092 $this->t->set_var('aaronic',$aaronic);
2093 $this->t->set_var('date','');
2094 $this->t->set_var('notes','');
2095 $this->t->set_var('lang_done','Cancel');
2096 $this->t->set_var('lang_action','Adding New Interview');
2097 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_update&interview='
2098 . $interview . '&action=' . 'insert'));
2101 if($action == 'edit' || $action == 'view')
2103 $sql = "SELECT * FROM eq_interview WHERE interview=".$interview;
2104 $this->db->query($sql,__LINE__,__FILE__);
2105 $this->db->next_record();
2106 $this->t->set_var('interview',$interview);
2107 $this->t->set_var('name',$name);
2108 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2109 $this->t->set_var('elder',$this->db->f('elder'));
2110 $this->t->set_var('aaronic',$this->db->f('aaronic'));
2111 $this->t->set_var('date',$this->db->f('date'));
2112 $this->t->set_var('notes',$this->db->f('notes'));
2115 if($action == 'edit')
2117 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2118 $this->t->set_var('lang_done','Cancel');
2119 $this->t->set_var('lang_action','Editing Interview');
2120 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_update&interview='
2121 . $interview . '&action=' . 'save'));
2124 if($action == 'view')
2126 $date = $this->db->f('date');
2127 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2128 $this->t->set_var('readonly','READONLY');
2129 $this->t->set_var('disabled','DISABLED');
2130 $this->t->set_var('lang_done','Done');
2131 $this->t->set_var('lang_action','Viewing Interview');
2132 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_update&interview='
2133 . $interview . '&action=' . 'edit'));
2136 $this->t->set_var('lang_reset','Clear Form');
2137 $this->t->set_var('lang_add','Add Interview');
2138 $this->t->set_var('lang_save','Save Changes');
2139 $this->t->set_var('edithandle','');
2140 $this->t->set_var('addhandle','');
2142 $this->t->pfp('out','form');
2144 if($action == 'view') { $this->t->set_var('lang_save','Edit Interview'); }
2145 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2146 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2148 $this->save_sessiondata();
2153 $this->t->set_file(array('vis_view_t' => 'vis_view.tpl'));
2154 $this->t->set_block('vis_view_t','visit_list','list1');
2155 $this->t->set_block('vis_view_t','family_list','list2');
2157 $this->t->set_var('lang_name','Family Name');
2158 $this->t->set_var('lang_date','Date');
2160 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
2161 $this->t->set_var('vis_link_title','View Yearly Visits');
2163 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched'));
2164 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2167 $sql = "SELECT * FROM eq_visit WHERE companionship=0 ORDER BY date DESC";
2168 $this->db->query($sql,__LINE__,__FILE__);
2169 $total_records = $this->db->num_rows();
2172 while ($this->db->next_record())
2174 $visit_list[$i]['visit'] = $this->db->f('visit');
2175 $visit_list[$i]['family'] = $this->db->f('family');
2176 $visit_list[$i]['date'] = $this->db->f('date');
2180 for ($i=0; $i < count($visit_list); $i++)
2182 $this->nextmatchs->template_alternate_row_color(&$this->t);
2184 $sql = "SELECT * FROM eq_family WHERE family=".$visit_list[$i]['family'];
2185 $this->db->query($sql,__LINE__,__FILE__);
2186 $this->db->next_record();
2188 $this->t->set_var('family',$visit_list[$i]['family']);
2189 $this->t->set_var('family_name',$this->db->f('name'));
2190 $this->t->set_var('date',$visit_list[$i]['date']);
2192 $link_data['menuaction'] = 'eq.eq.vis_update';
2193 $link_data['visit'] = $visit_list[$i]['visit'];
2194 $link_data['name'] = $this->db->f('name');
2195 $link_data['date'] = $visit_list[$i]['date'];
2196 $link_data['action'] = 'view';
2197 $this->t->set_var('view',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
2198 $this->t->set_var('lang_view','View');
2200 $link_data['menuaction'] = 'eq.eq.vis_update';
2201 $link_data['visit'] = $visit_list[$i]['visit'];
2202 $link_data['name'] = $this->db->f('name');
2203 $link_data['date'] = $visit_list[$i]['date'];
2204 $link_data['action'] = 'edit';
2205 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
2206 $this->t->set_var('lang_edit','Edit');
2208 $this->t->fp('list1','visit_list',True);
2211 // List the families that are available to record a visit against
2212 $sql = "SELECT * FROM eq_family WHERE valid=1";
2213 $this->db->query($sql,__LINE__,__FILE__);
2214 $total_records = $this->db->num_rows();
2217 while ($this->db->next_record())
2219 $family_names[$i] = $this->db->f('name');
2220 $family_ids[$i] = $this->db->f('family');
2222 } array_multisort($family_names, $family_ids);
2224 for ($i=0; $i < count($family_names); $i++)
2226 $link_data['menuaction'] = 'eq.eq.vis_update';
2227 $link_data['visit'] = '';
2228 $link_data['family'] = $family_ids[$i];
2229 $link_data['action'] = 'add';
2230 $link_data['name'] = $family_names[$i];
2231 $this->t->set_var('add',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
2233 $this->t->set_var('name',$family_names[$i]);
2234 if(($i+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
2235 else { $this->t->set_var('table_sep',"</td>"); }
2236 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
2238 $this->t->fp('list2','family_list',True);
2241 $this->t->pfp('out','vis_view_t');
2242 $this->save_sessiondata();
2245 function vis_update()
2247 $this->t->set_file(array('form' => 'vis_update.tpl'));
2248 $this->t->set_block('form','add','addhandle');
2249 $this->t->set_block('form','edit','edithandle');
2251 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
2252 $this->t->set_var('readonly','');
2253 $this->t->set_var('disabled','');
2255 $action = get_var('action',array('GET','POST'));
2256 $visit = get_var('visit',array('GET','POST'));
2257 $family = get_var('family',array('GET','POST'));
2258 $name = get_var('name',array('GET','POST'));
2259 $date = get_var('date',array('GET','POST'));
2260 $notes = get_var('notes',array('GET','POST'));
2263 if($action == 'save')
2265 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
2266 $this->db->query("UPDATE eq_visit set " .
2267 " date='" . $date . "'" .
2268 ", notes='" . $notes . "'" .
2269 " WHERE visit=" . $visit,__LINE__,__FILE__);
2274 if($action == 'insert')
2276 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
2277 $this->db->query("INSERT INTO eq_visit (family,companionship,date,notes) "
2278 . "VALUES ('" . $family . "','" . $companionship . "','"
2279 . $date . "','" . $notes . "')",__LINE__,__FILE__);
2284 if($action == 'add')
2286 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2287 $this->t->set_var('family', $family);
2288 $this->t->set_var('visit', '');
2289 $this->t->set_var('name', $name);
2290 $this->t->set_var('date','');
2291 $this->t->set_var('notes','');
2292 $this->t->set_var('lang_done','Cancel');
2293 $this->t->set_var('lang_action','Adding New Visit');
2294 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&family='
2295 . $family . '&action=' . 'insert'));
2298 if($action == 'edit' || $action == 'view')
2300 $sql = "SELECT * FROM eq_visit WHERE visit=".$visit;
2301 $this->db->query($sql,__LINE__,__FILE__);
2302 $this->db->next_record();
2303 $this->t->set_var('visit',$visit);
2304 $this->t->set_var('name',$name);
2305 $this->t->set_var('family', $family);
2306 $this->t->set_var('date',$this->db->f('date'));
2307 $this->t->set_var('notes',$this->db->f('notes'));
2310 if($action == 'edit')
2312 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2313 $this->t->set_var('lang_done','Cancel');
2314 $this->t->set_var('lang_action','Editing Visit');
2315 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&visit='
2316 . $visit . '&action=' . 'save'));
2319 if($action == 'view')
2321 $date = $this->db->f('date');
2322 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2323 $this->t->set_var('readonly','READONLY');
2324 $this->t->set_var('disabled','DISABLED');
2325 $this->t->set_var('lang_done','Done');
2326 $this->t->set_var('lang_action','Viewing Visit');
2327 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&visit='
2328 . $visit . '&action=' . 'edit'));
2331 $this->t->set_var('lang_reset','Clear Form');
2332 $this->t->set_var('lang_add','Add Visit');
2333 $this->t->set_var('lang_save','Save Changes');
2334 $this->t->set_var('edithandle','');
2335 $this->t->set_var('addhandle','');
2337 $this->t->pfp('out','form');
2339 if($action == 'view') { $this->t->set_var('lang_save','Edit Visit'); }
2340 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2341 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2343 $this->save_sessiondata();
2348 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
2349 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
2350 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
2352 $this->t->set_file(array('att_view_t' => 'att_view.tpl'));
2353 $this->t->set_block('att_view_t','act_list','list');
2355 $this->t->set_block('att_view_t','month_list','list1');
2356 $this->t->set_block('att_view_t','header_list','list2');
2357 $this->t->set_block('att_view_t','elder_list','list3');
2359 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_view'));
2360 $num_months = get_var('num_months',array('GET','POST'));
2361 if($num_months == '') { $num_months = $this->default_att_num_months; }
2362 $this->t->set_var('num_months',$num_months);
2363 $this->t->set_var('lang_filter','Filter');
2364 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
2365 else { $this->t->set_var('lang_num_months','Months of History'); }
2367 $sql = "SELECT * FROM eq_elder where valid=1";
2368 $this->db->query($sql,__LINE__,__FILE__);
2370 while ($this->db->next_record())
2372 $elder_name[$i] = $this->db->f('name');
2373 $elder_id[$i] = $this->db->f('elder');
2376 array_multisort($elder_name, $elder_id);
2379 // Create a list of sunday dates for a window of 3 months back and current month
2383 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, date("m")-$num_months, 1, date("y")));
2384 $last_date = explode("-",$sunday_list[0]['date']);
2385 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
2386 $time_limit = mktime(0, 0, 0, date("m"), date("t"), date("y"));
2387 while($last_time < $time_limit)
2389 $day = date("w",$last_time);
2390 if(date("w",$last_time) == 0) {
2391 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
2392 $last_date = explode("-",$sunday_list[$i]['date']);
2393 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
2394 $sunday_list[$i]['day'] = $last_date[2];
2395 $sunday_list[$i]['month'] = date("M",$last_time);
2396 $sunday_list[$i]['year'] = $last_date[0];
2399 $last_time += 90000;
2400 if($found_sunday) { $i++; $found_sunday=0; }
2403 $total_elders = count($elder_id);
2404 $old_month=$sunday_list[0]['month']; $span=0;
2405 for ($i=0; $i < count($sunday_list); $i++) {
2406 $date = $sunday_list[$i]['date'];
2407 $this->t->set_var('date',$sunday_list[$i]['date']);
2408 $this->t->set_var('day',$sunday_list[$i]['day']);
2409 if(($old_month != $sunday_list[$i]['month']) || $i == count($sunday_list)-1) {
2410 if($i == count($sunday_list)-1) { $span++; }
2411 $cur_month = $sunday_list[$i]['month'];
2412 $old_month = $sunday_list[$i]['month'];
2413 $link_data['menuaction'] = 'eq.eq.att_update';
2414 $link_data['month'] = $sunday_list[$i-1]['month'];
2415 $link_data['year'] = $sunday_list[$i-1]['year'];
2416 $link_data['action'] = 'update_month';
2417 $cur_month = $sunday_list[$i-1]['month'];
2418 $cur_year = $sunday_list[$i-1]['year'];
2419 $header_row .= "<th><font size=-3>$cur_month $cur_year</font></th>";
2420 $this->t->set_var('update_month',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
2421 $this->t->set_var('month',$sunday_list[$i-1]['month']);
2422 $this->t->set_var('year',$sunday_list[$i-1]['year']);
2423 $this->t->set_var('span',$span); $span=0;
2424 $this->t->fp('list1','month_list',True);
2427 $this->t->set_var('total_elders',$total_elders);
2428 $this->t->set_var('header_row',$header_row);
2430 $elder_width=200; $att_width=25; $total_width=$elder_width;
2431 for ($i=0; $i < count($sunday_list); $i++) {
2432 $link_data['menuaction'] = 'eq.eq.att_update';
2433 $link_data['month'] = $sunday_list[$i]['month'];
2434 $link_data['year'] = $sunday_list[$i]['year'];
2435 $link_data['day'] = $sunday_list[$i]['day'];
2436 $link_data['date'] = $sunday_list[$i]['date'];
2437 $link_data['action'] = 'update_day';
2438 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
2439 $this->t->set_var('date',$sunday_list[$i]['date']);
2440 $this->t->set_var('day',$sunday_list[$i]['day']);
2441 $this->t->set_var('month',$sunday_list[$i]['month']);
2442 $this->t->set_var('year',$sunday_list[$i]['year']);
2443 $this->t->fp('list2','header_list',True);
2444 $total_width += $att_width;
2445 $attendance[$monthnum[$sunday_list[$i]['month']]]=0;
2448 for ($i=0; $i < count($elder_id); $i++) {
2450 $this->nextmatchs->template_alternate_row_color(&$this->t);
2451 $this->t->set_var('elder_name',$elder_name[$i]);
2452 #print "checking for elder: " . $elder_id[$i] . "<br>";
2453 for ($j=0; $j < count($sunday_list); $j++) {
2454 #print "checking for date: " . $sunday_list[$j]['date'] . "<br>";
2455 #print "SELECT * FROM eq_attendance WHERE date='"
2456 # . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i] . "<br>";
2457 $sql = "SELECT * FROM eq_attendance WHERE date='"
2458 . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i];
2459 $this->db->query($sql,__LINE__,__FILE__);
2460 if($this->db->next_record()) {
2461 $cur_month = $sunday_list[$j]['month'];
2462 if($attended[$i][$cur_month] != 1) {
2463 $attended[$i][$cur_month]=1;
2464 $attendance[$monthnum[$cur_month]]++;
2466 $att_table .= '<td align=center><img src="checkmark.gif"></td>';
2468 $att_table .= '<td> </td>';
2471 $this->t->set_var('att_table',$att_table);
2472 $this->t->fp('list3','elder_list',True);
2474 $this->t->set_var('total_width',$total_width);
2475 $this->t->set_var('elder_width',$elder_width);
2476 $this->t->set_var('att_width',$att_width);
2478 # Now calculate attendance for these months
2479 $attendance_str = "";
2480 $nonattendance_str = "";
2481 $aveattendance_str = "";
2482 $avenonattendance_str = "";
2484 $ave_total_attended=0;
2486 foreach($attendance as $att => $value) {
2487 $total_attended = $attendance[$att];
2488 $ave_total_attended += $attendance[$att]; $num_months++;
2489 $percent = ceil(($total_attended / $total_elders)*100);
2490 $attendance_str.="<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
2491 $total_nonattended = $total_elders - $total_attended;
2492 $percent = ceil(($total_nonattended / $total_elders)*100);
2493 $nonattendance_str.="<td align=center><font size=-2><b>$total_nonattended ($percent%)</b></font></td>";
2495 $total_attended = ceil(($ave_total_attended / $num_months));
2496 $percent = ceil(($total_attended / $total_elders)*100);
2497 $aveattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
2498 $total_attended = $total_elders - ceil(($ave_total_attended / $num_months));
2499 $percent = ceil(($total_attended / $total_elders)*100);
2500 $avenonattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
2503 $this->t->set_var('attendance',$attendance_str);
2504 $this->t->set_var('aveattendance',$aveattendance_str);
2505 $this->t->set_var('nonattendance',$nonattendance_str);
2506 $this->t->set_var('avenonattendance',$avenonattendance_str);
2508 $this->t->pfp('out','att_view_t');
2509 $this->save_sessiondata();
2512 function att_update()
2514 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
2515 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
2516 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
2518 $this->t->set_file(array('form' => 'att_update.tpl'));
2519 $this->t->set_block('form','edit','edithandle');
2521 $this->t->set_block('form','month_list','list1');
2522 $this->t->set_block('form','header_list','list2');
2523 $this->t->set_block('form','elder_list','list3');
2525 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_view'));
2527 $action = get_var('action',array('GET','POST'));
2528 $month = get_var('month',array('GET','POST'));
2529 $year = get_var('year',array('GET','POST'));
2530 $day = get_var('day',array('GET','POST'));
2531 $date = get_var('date',array('GET','POST'));
2533 if($action == 'save_month' || $action == 'save_day')
2535 $new_data = get_var('elders_attended',array('POST'));
2536 $month = $monthnum[$month]; if($month < 10) { $month = "0" . $month; }
2538 if($action == 'save_month') {
2539 $this->db->query("DELETE from eq_attendance where date LIKE '".$year."-".$month."-%'",__LINE__,__FILE__);
2542 if($action == 'save_day') {
2543 $this->db->query("DELETE from eq_attendance where date LIKE '".$year."-".$month."-".$day."'",__LINE__,__FILE__);
2546 foreach ($new_data as $data)
2548 $data_array = explode("-",$data);
2549 $elder = $data_array[0];
2550 $date = "$data_array[1]-$data_array[2]-$data_array[3]";
2551 $this->db->query("INSERT INTO eq_attendance (elder,date) "
2552 . "VALUES (" . $elder . ",'". $date . "')",__LINE__,__FILE__);
2559 $sql = "SELECT * FROM eq_elder where valid=1";
2560 $this->db->query($sql,__LINE__,__FILE__);
2562 while ($this->db->next_record())
2564 $elder_name[$i] = $this->db->f('name');
2565 $elder_id[$i] = $this->db->f('elder');
2568 array_multisort($elder_name, $elder_id);
2570 if($action == 'update_month')
2572 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_update&action=save_month'));
2576 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], 1, $year));
2577 $last_date = explode("-",$sunday_list[0]['date']);
2578 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
2579 $time_limit = mktime(0, 0, 0, $monthnum[$month], 31, $year);
2580 while($last_time <= $time_limit)
2582 $day = date("w",$last_time);
2583 if(date("w",$last_time) == 0) {
2584 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
2585 $last_date = explode("-",$sunday_list[$i]['date']);
2586 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
2587 $sunday_list[$i]['day'] = $last_date[2];
2588 $sunday_list[$i]['month'] = date("M",$last_time);
2589 $sunday_list[$i]['year'] = $last_date[0];
2592 $last_time += 90000;
2593 if($found_sunday) { $i++; $found_sunday=0; }
2596 $this->t->set_var('span', $i);
2597 $this->t->set_var('month',$sunday_list[$i-1]['month']);
2598 $this->t->set_var('year',$sunday_list[$i-1]['year']);
2599 $this->t->fp('list1','month_list',True);
2600 $elder_width=200; $att_width=25; $total_width=$elder_width;
2601 for ($i=0; $i < count($sunday_list); $i++) {
2602 $link_data['menuaction'] = 'eq.eq.att_update';
2603 $link_data['month'] = $sunday_list[$i]['month'];
2604 $link_data['year'] = $sunday_list[$i]['year'];
2605 $link_data['day'] = $sunday_list[$i]['day'];
2606 $link_data['date'] = $sunday_list[$i]['date'];
2607 $link_data['action'] = 'update_day';
2608 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
2609 $this->t->set_var('date',$sunday_list[$i]['date']);
2610 $this->t->set_var('day',$sunday_list[$i]['day']);
2611 $this->t->set_var('month',$sunday_list[$i]['month']);
2612 $this->t->set_var('year',$sunday_list[$i]['year']);
2613 $this->t->fp('list2','header_list',True);
2614 $total_width += $att_width;
2618 if($action == 'update_day')
2620 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_update&action=save_day'));
2621 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], $day, $year));
2622 $this->t->set_var('month',$month);
2623 $this->t->set_var('year',$year);
2624 $this->t->fp('list1','month_list',True);
2625 $this->t->set_var('date',$date);
2626 $this->t->set_var('day',$day);
2627 $this->t->set_var('month',$month);
2628 $this->t->set_var('year',$year);
2629 $this->t->fp('list2','header_list',True);
2632 for ($i=0; $i < count($elder_id); $i++) {
2634 $this->nextmatchs->template_alternate_row_color(&$this->t);
2635 $this->t->set_var('elder_name',$elder_name[$i]);
2636 for ($j=0; $j < count($sunday_list); $j++) {
2637 $sql = "SELECT * FROM eq_attendance WHERE date='"
2638 . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i];
2639 $this->db->query($sql,__LINE__,__FILE__);
2640 $value = $elder_id[$i] . "-" . $sunday_list[$j]['date'];
2641 if($this->db->next_record()) {
2642 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'" checked></td>';
2644 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'"></td>';
2647 $this->t->set_var('att_table',$att_table);
2648 $this->t->fp('list3','elder_list',True);
2651 $this->t->set_var('lang_done', 'Cancel');
2652 $this->t->set_var('lang_reset','Clear Form');
2653 $this->t->set_var('lang_save','Save Changes');
2655 $this->t->pfp('out','form');
2656 $this->t->pfp('addhandle','edit');
2658 $this->save_sessiondata();
2663 $this->t->set_file(array('dir_view_t' => 'dir_view.tpl'));
2664 $this->t->set_block('dir_view_t','dir_list','list');
2666 $sql = "SELECT * FROM eq_parent where valid=1 ORDER BY name ASC";
2667 $this->db->query($sql,__LINE__,__FILE__);
2669 while ($this->db->next_record())
2671 $parent[$i]['id'] = $this->db->f('parent');
2672 $parent[$i]['name'] = $this->db->f('name');
2673 $parent[$i]['phone'] = $this->db->f('phone');
2674 $parent[$i]['address'] = $this->db->f('address');
2678 for ($i=0; $i < count($parent); $i++)
2680 $name = $parent[$i]['name'];
2681 $phone = $parent[$i]['phone'];
2682 $address = $parent[$i]['address'];
2683 $this->t->set_var('name', $name);
2684 $this->t->set_var('address', $address);
2685 $this->t->set_var('phone', $phone);
2686 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2687 $this->t->set_var('tr_color',$tr_color);
2688 $this->t->fp('list','dir_list',True);
2689 //print "$phone $name $address<br>";
2691 $this->t->pfp('out','dir_view_t');
2692 $this->save_sessiondata();
2697 $this->t->set_file(array('org_view_t' => 'org_view.tpl'));
2698 $this->t->set_block('org_view_t','calling_list','list1');
2699 $this->t->set_block('org_view_t','org_list','list2');
2701 # Display a list ordered alphabetically
2702 $sql = "SELECT * FROM eq_calling ORDER BY name ASC";
2703 $this->db->query($sql,__LINE__,__FILE__);
2705 while ($this->db->next_record())
2707 $calling[$i]['id'] = $this->db->f('indiv_id');
2708 $calling[$i]['name'] = $this->db->f('name');
2709 $calling[$i]['position'] = $this->db->f('position');
2710 $calling[$i]['sustained'] = $this->db->f('sustained');
2711 $calling[$i]['organization'] = $this->db->f('organization');
2714 for ($i=0; $i < count($calling); $i++)
2716 $name = $calling[$i]['name'];
2717 $position = $calling[$i]['position'];
2718 $sustained = $calling[$i]['sustained'];
2719 $organization = $calling[$i]['organization'];
2720 $this->t->set_var('name', $name);
2721 $this->t->set_var('position', $position);
2722 $this->t->set_var('sustained', $sustained);
2723 $this->t->set_var('organization', $organization);
2724 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2725 $this->t->set_var('tr_color',$tr_color);
2726 $this->t->fp('list1','calling_list',True);
2729 # Display a list ordered by organization
2730 $sql = "SELECT * FROM eq_calling ORDER BY sequence ASC";
2731 $this->db->query($sql,__LINE__,__FILE__);
2733 while ($this->db->next_record())
2735 $calling[$i]['id'] = $this->db->f('indiv_id');
2736 $calling[$i]['name'] = $this->db->f('name');
2737 $calling[$i]['position'] = $this->db->f('position');
2738 $calling[$i]['sustained'] = $this->db->f('sustained');
2739 $calling[$i]['organization'] = $this->db->f('organization');
2742 for ($i=0; $i < count($calling); $i++)
2744 $name = $calling[$i]['name'];
2745 $position = $calling[$i]['position'];
2746 $sustained = $calling[$i]['sustained'];
2747 $organization = $calling[$i]['organization'];
2748 $this->t->set_var('name', $name);
2749 $this->t->set_var('position', $position);
2750 $this->t->set_var('sustained', $sustained);
2751 $this->t->set_var('organization', $organization);
2752 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2753 $this->t->set_var('tr_color',$tr_color);
2754 $this->t->fp('list2','org_list',True);
2757 $this->t->pfp('out','org_view_t');
2758 $this->save_sessiondata();
2763 $this->t->set_file(array('sched_t' => 'schedule.tpl'));
2764 $this->t->set_block('sched_t','district_list','list');
2766 $action = get_var('action',array('GET','POST'));
2768 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.schedule&action=save'));
2769 $this->t->set_var('title','EQ Scheduling Tool');
2771 $this->t->set_var('lang_save','Save Schedule');
2772 $this->t->set_var('lang_reset','Cancel');
2774 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched'));
2775 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
2777 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched'));
2778 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2780 $date_width=150; $time_width=200; $elder_width=200; $family_width=200;
2781 $table_width=$date_width + $time_width + $elder_width + $family_width;
2782 $header_row = "<th width=$date_width><font size=-2>Date</th>";
2783 $header_row.= "<th width=$time_width><font size=-2>Time</th>";
2784 $header_row.= "<th width=$elder_width><font size=-2>Elder</th>";
2785 $header_row.= "<th width=$family_width><font size=-2>Family</th>";
2788 if($action == 'save')
2790 $new_data = get_var('sched',array('POST'));
2791 foreach ($new_data as $district_array)
2793 foreach ($district_array as $entry)
2795 $district = $entry['district'];
2796 $appointment = $entry['appointment'];
2797 $date = $entry['date'];
2798 $hour = $entry['hour'];
2799 $minute = $entry['minute'];
2801 $elder = $entry['elder'];
2802 $family = $entry['family'];
2803 if($pm) { $hour = $hour + 12; }
2804 $time = $hour.':'.$minute.':'.'00';
2806 // Update an existing appointment
2807 if($appointment != 0)
2809 $this->db->query("UPDATE eq_appointment set" .
2810 " family=" . $family .
2811 " ,elder=" . $elder .
2812 " ,date='" . $date . "'" .
2813 " ,time='" . $time . "'" .
2814 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
2816 //print "updating entry: appt=$appointment date: $date time: $time elder: $elder family: $family<br>";
2819 // Add a new appointment
2820 else if(($appointment == 0) && ($date != "") && ($time != ""))
2822 $this->db->query("INSERT INTO eq_appointment (appointment,district,family,elder,date,time) "
2823 . "VALUES ('" . $appointment . "','" . $district . "','" . $family . "','"
2824 . $elder . "','" . $date . "','" . $time ."')",__LINE__,__FILE__);
2826 //print "adding entry: appt=$appointment date: $date time: $time elder: $elder family: $family<br>";
2831 $take_me_to_url = $GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.schedule');
2832 Header('Location: ' . $take_me_to_url);
2835 $sql = "SELECT * FROM eq_district where district != 0 ORDER BY district ASC";
2836 $this->db->query($sql,__LINE__,__FILE__);
2838 while ($this->db->next_record())
2840 $districts[$i]['district'] = $this->db->f('district');
2841 $districts[$i]['name'] = $this->db->f('name');
2842 $districts[$i]['supervisor'] = $this->db->f('supervisor');
2846 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
2847 $this->db->query($sql,__LINE__,__FILE__);
2849 while ($this->db->next_record())
2851 $elder_id[$i] = $this->db->f('elder');
2852 $elder_name[$i] = $this->db->f('name');
2853 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
2856 array_multisort($elder_name, $elder_id);
2858 $sql = "SELECT * FROM eq_family where valid=1 and elder_id != 0 ORDER BY name ASC";
2859 $this->db->query($sql,__LINE__,__FILE__);
2861 while ($this->db->next_record())
2863 $family_id[$i] = $this->db->f('family');
2864 $family_name[$i] = $this->db->f('name');
2867 array_multisort($family_name, $family_id);
2869 for ($i=0; $i < count($districts); $i++) {
2870 $district = $districts[$i]['district'];
2871 $this->t->set_var('district_number',$districts[$i]['district']);
2872 $this->t->set_var('district_name',$districts[$i]['name']);
2873 $supervisor = $districts[$i]['supervisor'];
2876 // query the database for all the appointments
2877 $sql = "SELECT * FROM eq_appointment where district=$district and date>=CURDATE() ORDER BY date ASC, time ASC";
2878 $this->db->query($sql,__LINE__,__FILE__);
2880 // Prefill any existing appointment slots
2881 while ($this->db->next_record())
2883 $appointment = $this->db->f('appointment');
2884 $elder = $this->db->f('elder');
2885 $family = $this->db->f('family');
2887 $date = $this->db->f('date');
2888 $date_array = explode("-",$date);
2889 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
2890 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
2892 $time = $this->db->f('time');
2893 $time_array = explode(":",$time);
2894 $hour = $time_array[0];
2895 $minute = $time_array[1];
2897 if($hour > 12) { $pm=1; $hour = $hour - 12; }
2898 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
2900 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2903 $table_data.= '<td align=left>';
2904 $table_data.= $this->jscal->input('sched['.$district.']['.$appointment.'][date]',$date,'','','','','',$this->cal_options);
2905 $table_data.= '</td>';
2907 // Hour & Minutes selection
2908 $table_data.= "<td align=center>";
2909 $table_data.= '<select name=sched['.$district.']['.$appointment.'][hour]>';
2910 foreach(range(1,12) as $num) {
2911 if($hour == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
2912 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2914 $table_data.= '</select>';
2915 $table_data.= ' : ';
2916 $table_data.= '<select name=sched['.$district.']['.$appointment.'][minute]>';
2917 foreach(range(0,3) as $num) {
2918 $num = $num * 15; if($num == 0) { $num = "00"; }
2919 if($minute == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
2920 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2922 $table_data.= '</select>';
2923 $table_data.= '<select name=sched['.$district.']['.$appointment.'][pm]>';
2924 if($pm == 0) { $table_data.= '<option value=0 selected>am</option>'; $table_data.= '<option value=1>pm</option>'; }
2925 else { $table_data.= '<option value=0>am</option>'; $table_data.= '<option value=1 selected>pm</option>'; }
2926 $table_data.= '</select>';
2927 $table_data.= "</td>";
2929 // Elder drop down list (for PPIs)
2930 $table_data.= '<td align=center><select name=sched['.$district.']['.$appointment.'][elder]>';
2931 $table_data.= '<option value=0></option>';
2932 for ($j=0; $j < count($elder_id); $j++) {
2933 $id = $elder_id[$j];
2934 $name = $elder_name[$j];
2935 if($elder_id[$j] == $elder) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
2936 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
2938 $table_data.='</select></td>';
2940 // Family drop down list (for Visits)
2941 $table_data.= '<td align=center><select name=sched['.$district.']['.$appointment.'][family]>';
2942 $table_data.= '<option value=0></option>';
2943 for ($j=0; $j < count($elder_id); $j++) {
2944 $id = $family_id[$j];
2945 $name = $family_name[$j];
2946 if($family_id[$j] == $family) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
2947 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
2949 $table_data.='</select></td>';
2951 $table_data.= '<input type=hidden name="sched['.$district.']['.$appointment.'][appointment]" value="'.$appointment.'">';
2952 $table_data.= '<input type=hidden name="sched['.$district.']['.$appointment.'][district]" value="'.$district.'">';
2954 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2955 $this->t->set_var('tr_color',$tr_color);
2959 // Create blank appointment slot
2961 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2964 $table_data.= '<td align=left>';
2965 $table_data.= $this->jscal->input('sched['.$district.']['.$appointment.'][date]','','','','','','',$this->cal_options);
2966 $table_data.= '</td>';
2969 $table_data.= "<td align=center>";
2970 $table_data.= '<select name=sched['.$district.']['.$appointment.'][hour]>';
2971 $table_data.= '<option value=""></option>';
2972 foreach(range(1,12) as $num) {
2973 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2975 $table_data.= '</select>';
2976 $table_data.= ' : ';
2977 $table_data.= '<select name=sched['.$district.']['.$appointment.'][minute]>';
2978 $table_data.= '<option value=""></option>';
2979 foreach(range(0,3) as $num) {
2980 $num = $num * 15; if($num == 0) { $num = "00"; }
2981 $table_data.= '<option value='.$num.'>'.$num.'</option>';
2983 $table_data.= '</select>';
2984 $table_data.= '<select name=sched['.$district.']['.$appointment.'][pm]>';
2985 $table_data.= '<option value=""></option>';
2986 $table_data.= '<option value=0>am</option>';
2987 $table_data.= '<option value=1>pm</option>';
2988 $table_data.= '</select>';
2989 $table_data.= "</td>";
2991 // Elder drop down list
2992 $table_data.= '<td align=center><select name=sched['.$district.']['.$appointment.'][elder]>';
2993 $table_data.= '<option value=0></option>';
2994 for ($j=0; $j < count($elder_id); $j++) {
2995 $id = $elder_id[$j];
2996 $name = $elder_name[$j];
2997 $table_data.= '<option value='.$id.'>'.$name.'</option>';
2999 $table_data.='</select></td>';
3001 // Family drop down list
3002 $table_data.= '<td align=center><select name=sched['.$district.']['.$appointment.'][family]>';
3003 $table_data.= '<option value=0></option>';
3004 for ($j=0; $j < count($elder_id); $j++) {
3005 $id = $family_id[$j];
3006 $name = $family_name[$j];
3007 $table_data.= '<option value='.$id.'>'.$name.' Family</option>';
3009 $table_data.='</select></td>';
3011 $table_data.= '<input type=hidden name="sched['.$district.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3012 $table_data.= '<input type=hidden name="sched['.$district.']['.$appointment.'][district]" value="'.$district.'">';
3014 $this->t->set_var('table_data',$table_data);
3015 $this->t->set_var('header_row',$header_row);
3016 $this->t->set_var('table_width',$table_width);
3017 $this->t->fp('list','district_list',True);
3021 $this->t->pfp('out','sched_t');
3022 $this->save_sessiondata();
3027 $this->t->set_file(array('admin_t' => 'admin.tpl'));
3028 $this->t->set_block('admin_t','upload','uploadhandle');
3029 $this->t->set_block('admin_t','admin','adminhandle');
3030 $this->t->set_block('admin_t','cmd','cmdhandle');
3032 $this->t->set_var('upload_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.admin&action=upload'));
3034 $action = get_var('action',array('GET','POST'));
3036 $this->t->pfp('out','admin_t');
3038 if($action == 'upload')
3040 $target_path = $this->upload_target_path . basename( $_FILES['uploadedfile']['name']);
3042 if((($_FILES['uploadedfile']['type'] == "application/zip") ||
3043 ($_FILES['uploadedfile']['type'] == "application/x-zip-compressed") ||
3044 ($_FILES['uploadedfile']['type'] == "application/x-zip") ||
3045 ($_FILES['uploadedfile']['type'] == "application/octet-stream")) &&
3046 (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))) {
3047 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
3048 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
3049 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
3050 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
3051 $this->t->set_var('uploadstatus',$uploadstatus);
3052 $this->t->pfp('uploadhandle','upload');
3053 $this->t->set_var('uploadhandle','');
3054 print "<table border=1 width=80%><tr><td>\n<pre>";
3056 # make a directory for this data to be stored in
3057 $date="data_" . date("Y_m_d");
3058 $data_dir = $this->upload_target_path . $date;
3059 print "-> Making the data directory: $date<br>\n";
3060 exec('mkdir ' . $data_dir . ' 2>&1', $result, $return_code);
3061 if($return_code != 0) {
3062 print implode('\n',$result) . "<br>";
3063 print "<b><font color=red>";
3064 print "-E- Unable to create the data directory. Aborting import.";
3065 print "</font></b>";
3069 # move the file uploaded into this directory
3070 print "-> Moving the uploaded file into the data dir<br>\n";
3071 exec('mv ' . $target_path . ' ' . $data_dir . '/' . ' 2>&1', $result, $return_code);
3072 if($return_code != 0) {
3073 print implode('\n',$result) . "<br>";
3074 print "<b><font color=red>";
3075 print "-E- Unable to move the uploaded file into the data dir. Aborting import.";
3076 print "</font></b>";
3080 # unzip the data into this directory
3081 print "-> Unzipping the data<br>\n";
3082 $data_file = $data_dir . '';
3083 exec('unzip ' . $data_dir . '/*.zip -d ' . $data_dir . ' 2>&1', $result, $return_code);
3084 if($return_code != 0) {
3085 print implode('\n',$result) . "<br>";
3086 print "<b><font color=red>";
3087 print "-E- Unable to unzip the uploaded file into the data dir. Aborting import.";
3088 print "</font></b>";
3091 exec('mv ' . $data_dir . '/*/* '. $data_dir . ' 2>&1', $result, $return_code);
3093 # update the data_latest link to point to this new directory
3094 print "-> Updating the latest data dir link<br>\n";
3095 $data_latest = $this->upload_target_path . 'data_latest';
3096 exec('rm ' . $data_latest. '; ln -s ' . $data_dir .' '. $data_latest .' 2>&1', $result, $return_code);
3097 if($return_code != 0) {
3098 print implode('\n',$result) . "<br>";
3099 print "<b><font color=red>";
3100 print "-E- Unable to update the data latest link. Aborting import.";
3101 print "</font></b>";
3105 # run the import perl script to encorporate it into the DB
3106 ob_start('ob_logstdout', 2);
3107 print "-> Importing the data into the EQ database<br>\n";
3108 ob_flush(); flush(); sleep(1);
3109 $import_log = $this->upload_target_path . '/import.log';
3110 $data_log = $this->upload_target_path . '/data.log';
3111 $import_cmd = $this->script_path . 'import_ward_data ' . $data_latest . ' | tee ' . $import_log;
3112 $parse_cmd = $this->script_path . 'parse_ward_data -v ' . $data_latest . ' > ' . $data_log;
3113 #print "import_cmd: $import_cmd<br>";
3114 #print "parse_cmd: $parse_cmd<br>";
3115 ob_start('ob_logstdout', 2);
3116 passthru($import_cmd);
3117 passthru($parse_cmd);
3118 ob_flush(); flush(); sleep(1);
3120 # fix the permissions of the data dir
3121 exec('chmod -R o-rwx ' . $data_dir, $result, $return_code);
3123 $this->t->pfp('cmdhandle','cmd');
3124 print "</pre></td></tr></table>";
3126 } else if(($_FILES['uploadedfile']['type'] != "application/zip") &&
3127 ($_FILES['uploadedfile']['type'] != "application/x-zip-compressed") &&
3128 ($_FILES['uploadedfile']['type'] != "application/x-zip") &&
3129 ($_FILES['uploadedfile']['type'] != "application/octet-stream")) {
3130 $uploadstatus = "<b><font color=red>The file format must be a .zip file, please try again! </font></b>";
3131 $uploadstatus.= "<br><br><b>Detected file format: " . $_FILES['uploadedfile']['type'] . "</b>";
3132 $this->t->set_var('uploadstatus',$uploadstatus);
3133 $this->t->pfp('uploadhandle','upload',True);
3135 $uploadstatus = "<b><font color=red> There was an error (" . $_FILES['uploadedfile']['error'];
3136 $uploadstatus.= ") uploading the file, please try again! </font></b>";
3137 $this->t->set_var('uploadstatus',$uploadstatus);
3138 $this->t->pfp('uploadhandle','upload',True);
3143 $this->t->set_var('adminhandle','');
3144 $this->t->pfp('adminhandle','admin');
3147 $this->save_sessiondata();