2 /**************************************************************************\
4 * http://www.phpgroupware.org *
5 * ----------------------------------------------- *
6 * This program is free software; you can redistribute it and/or modify it *
7 * under the terms of the GNU General Public License as published by the *
8 * Free Software Foundation; either version 2 of the License, or (at your *
9 * option) any later version. *
10 \**************************************************************************/
11 /* $Id: class.eq.inc.php,v 1.1.1.1 2001/05/20 07:40:32 seek3r Exp $ */
22 var $default_ht_num_months;
23 var $default_ppi_num_months;
24 var $default_ppi_num_years;
25 var $default_att_num_months;
28 var $upload_target_path;
31 var $public_functions = array
52 $this->default_ht_num_months = 3;
53 $this->default_ppi_num_months = 3;
54 $this->default_ppi_num_years = 0;
55 $this->default_att_num_months = 3;
56 $this->upload_target_path = "/home/users/eqpres/eq_data/";
57 $this->script_path = "/usr/share/phpgroupware/eq/";
59 $this->db = $GLOBALS['phpgw']->db;
60 $this->db2 = $this->db;
61 $this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
62 $this->t = $GLOBALS['phpgw']->template;
63 $this->account = $GLOBALS['phpgw_info']['user']['account_id'];
64 $this->grants = $GLOBALS['phpgw']->acl->get_grants('eq');
65 $this->grants[$this->account] = PHPGW_ACL_READ + PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE;
67 $this->jscal = CreateObject('phpgwapi.jscalendar'); // before phpgw_header() !!!
68 $this->cal_options = 'daFormat : "%Y-%m-%d",
69 ifFormat : "%Y-%m-%d",
73 $GLOBALS['phpgw_info']['flags']['app_header'] = 'Elders Quorum Tools';
74 $GLOBALS['phpgw']->common->phpgw_header();
76 $this->current_month = `date '+%m'`;
77 $this->current_month = $this->current_month-0; // Make it numeric
78 $this->current_year = `date '+%Y'`;
79 $this->current_year = $this->current_year-0; // Make it numeric
82 $this->display_app_header();
85 function save_sessiondata()
90 function display_app_header()
92 $this->t->set_file(array('eq_header' => 'header.tpl'));
94 if (isset($phpgw_info['user']['preferences']['eq']['eq_font']))
96 $font = $phpgw_info['user']['preferences']['eq']['eq_font'];
103 $this->t->set_var('bg_color',$phpgw_info['theme']['th_bg']);
104 $this->t->set_var('font',$font);
105 $link_data['menuaction'] = 'eq.eq.ht_view';
106 $this->t->set_var('link_hometeaching',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
107 $this->t->set_var('lang_hometeaching','HomeTeaching');
108 $link_data['menuaction'] = 'eq.eq.act_list';
109 $this->t->set_var('link_activity',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
110 $this->t->set_var('lang_activity','Activities');
111 $link_data['menuaction'] = 'eq.eq.par_view';
112 $this->t->set_var('link_participation',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
113 $this->t->set_var('lang_participation','Participation');
114 $link_data['menuaction'] = 'eq.eq.ppi_view';
115 $this->t->set_var('link_ppi',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
116 $this->t->set_var('lang_ppi','PPIs');
117 $link_data['menuaction'] = 'eq.eq.vis_view';
118 $this->t->set_var('link_visit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
119 $this->t->set_var('lang_visit','Visits');
120 $link_data['menuaction'] = 'eq.eq.att_view';
121 $this->t->set_var('link_attendance',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
122 $this->t->set_var('lang_attendance','Attendance');
123 $link_data['menuaction'] = 'eq.eq.dir_view';
124 $this->t->set_var('link_dir',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
125 $this->t->set_var('lang_dir','Directory');
126 $link_data['menuaction'] = 'eq.eq.org_view';
127 $this->t->set_var('link_org',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
128 $this->t->set_var('lang_org','Callings');
129 $link_data['menuaction'] = 'eq.eq.admin';
130 $this->t->set_var('link_admin',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
131 $this->t->set_var('lang_admin','Admin');
133 $this->t->pparse('out','eq_header');
138 $this->t->set_file(array('ht_view_t' => 'ht_view.tpl'));
139 $this->t->set_block('ht_view_t','district_list','list');
141 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
142 $num_months = get_var('num_months',array('GET','POST'));
143 if($num_months == '') { $num_months = $this->default_ht_num_months; }
144 $this->t->set_var('num_months',$num_months);
145 $this->t->set_var('lang_filter','Filter');
146 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
147 else { $this->t->set_var('lang_num_months','Months of History'); }
149 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
150 $this->t->set_var('title','Hometeaching');
152 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
153 $this->db->query($sql,__LINE__,__FILE__);
155 while ($this->db->next_record())
157 $districts[$i]['district'] = $this->db->f('district');
158 $districts[$i]['name'] = $this->db->f('name');
159 $districts[$i]['supervisor'] = $this->db->f('supervisor');
163 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
164 $this->db->query($sql,__LINE__,__FILE__);
166 while ($this->db->next_record())
168 $elder_id[$i] = $this->db->f('elder');
169 $elder_name[$i] = $this->db->f('name');
170 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
173 array_multisort($elder_name, $elder_id);
175 // Make an array mapping elder_ids to elder_names
176 for($i=0; $i < count($elder_id); $i++) {
178 $elders[$id] = $elder_name[$i];
181 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
182 $this->db->query($sql,__LINE__,__FILE__);
183 while ($this->db->next_record())
185 $aaronic_id = $this->db->f('aaronic');
186 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
187 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
191 $this->nextmatchs->template_alternate_row_color(&$this->t);
192 for ($i=0; $i < count($districts); $i++) {
193 $this->t->set_var('district_number',$districts[$i]['district']);
194 $this->t->set_var('district_name',$districts[$i]['name']);
195 $supervisor = $districts[$i]['supervisor'];
196 $unique_companionships='';
198 // Select all the unique companionship numbers for this district
199 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $districts[$i]['district'];
200 $this->db->query($sql,__LINE__,__FILE__);
202 while ($this->db->next_record())
204 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
208 $comp_width=450; $visit_width=25; $table_width=$comp_width + $num_months*$visit_width;
209 $table_data=""; $num_companionships = 0; $num_families = 0;
210 for($m=$num_months; $m >= 0; $m--) { $visits[$m] = 0; }
211 for ($j=0; $j < count($unique_companionships); $j++) {
212 $companion_table_entry = "";
213 // Select all the companions in each companionship
214 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
215 "companionship=". $unique_companionships[$j]['companionship'];
216 $this->db->query($sql,__LINE__,__FILE__);
218 while ($this->db->next_record())
220 // Get this companions information
221 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
222 $companionship = $this->db->f('companionship');
223 $elder_id = $this->db->f('elder');
224 $aaronic_id = $this->db->f('aaronic');
226 $name = $elders[$elder_id];
227 $phone = $elder_phone[$elder_id];
229 else if($aaronic_id) {
230 $name = $aaronic[$aaronic_id]['name'];
231 $phone = $aaronic[$aaronic_id]['phone'];
233 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
235 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
237 // Get the names of the families assigned this home teaching companionship
238 $sql = "SELECT * from eq_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
239 $sql = $sql . " ORDER BY name ASC";
240 $this->db->query($sql,__LINE__,__FILE__);
242 while ($this->db->next_record())
244 $num_families++; $total_families++;
245 $family_name = $this->db->f('name');
246 $family_id = $this->db->f('family');
247 $this->nextmatchs->template_alternate_row_color(&$this->t);
248 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
249 // Find out how many times Visits were performed by this companionship
250 // in the past $num_months for this Family
251 $header_row="<th width=$comp_width><font size=-2>Families</th>";
252 for($m=$num_months; $m >= 0; $m--) {
253 $month = $this->current_month - $m;
254 $year = $this->current_year;
255 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
256 if($month < 10) { $month = "0"."$month"; }
257 $month_start = "$year"."-"."$month"."-"."01";
258 $month_end = "$year"."-"."$month"."-"."31";
259 $month = "$month"."/"."$year";
260 //print "m: $m month: $month year: $year month_start: $month_start month_end: $month_end<br>";
261 // Add this to the query to filter on only visits made by this companionship:
262 // " AND companionship=" . $unique_companionships[$j]['companionship'].
263 $sql = "SELECT * FROM eq_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
264 " AND companionship!=0".
265 " AND family=". $family_id;
266 $this->db2->query($sql,__LINE__,__FILE__);
267 $link_data['menuaction'] = 'eq.eq.ht_update';
268 $link_data['date'] = $month_start;
269 $link_data['month_start'] = $month_start;
270 $link_data['month_end'] = $month_end;
271 $link_data['month'] = $month;
272 $link_data['district'] = $districts[$i]['district'];
273 $link_data['district_name'] = $districts[$i]['name'];
274 $link_data['action'] = 'view';
275 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
276 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
277 if(!$total_visits[$m]) { $total_visits[$m] = 0; }
278 if($this->db2->next_record()) {
279 if($this->db2->f('visited') == 'y') {
280 $visits[$m]++; $total_visits[$m]++;
281 $table_data .= '<td align=center><a href="'.$link.'"><img src="checkmark.gif"></a></td>';
283 else if($this->db2->f('visited') == 'n') {
284 $table_data .= '<td align=center><a href="'.$link.'"><img src="x.gif"></a></td>';
287 $visits[$m]++; $total_visits[$m]++;
288 $table_data .= "<td> </td>";
292 $visits[$m]++; $total_visits[$m]++;
293 $table_data .= "<td> </td>";
296 $table_data .= "</tr>";
299 $table_data .= "<tr><td colspan=20></td></tr>";
301 $table_data .= "<tr><td colspan=20><hr></td></tr>";
302 $stat_data = "<tr><td><b><font size=-2>$num_families Families<br>Visit Totals:</font></b></td>";
304 for($m=$num_months; $m >=0; $m--) {
305 $percent = ceil(($visits[$m] / $num_families)*100);
306 $stat_data .= "<td align=center><font size=-2><b>$visits[$m]<br>$percent%</font></b></td>";
308 $stat_data .= "</tr>";
310 $this->t->set_var('table_width',$table_width);
311 $this->t->set_var('header_row',$header_row);
312 $this->t->set_var('table_data',$table_data);
313 $this->t->set_var('stat_data',$stat_data);
314 $this->t->fp('list','district_list',True);
317 $totals = "<tr><td><b><font size=-2>$total_families Total Families<br>Visit Totals:</font></b></td>";
318 for($m=$num_months; $m >=0; $m--) {
319 $percent = ceil(($total_visits[$m] / $total_families)*100);
320 $totals .= "<td align=center><font size=-2><b>$total_visits[$m]<br>$percent%</font></b></td>";
324 $this->t->set_var('totals',$totals);
326 $this->t->pfp('out','ht_view_t');
327 $this->save_sessiondata();
333 $this->t->set_file(array('ht_update_t' => 'ht_update.tpl'));
334 $this->t->set_block('ht_update_t','district_list','list');
335 $this->t->set_block('ht_update_t','save','savehandle');
337 $district = get_var('district',array('GET','POST'));
338 $district_name = get_var('district_name',array('GET','POST'));
339 $date = get_var('date',array('GET','POST'));
340 $month = get_var('month',array('GET','POST'));
341 $month_start = get_var('month_start',array('GET','POST'));
342 $month_end = get_var('month_end',array('GET','POST'));
343 $action = get_var('action',array('GET','POST'));
345 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
346 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_update&action=save'));
347 $this->t->set_var('lang_done','Cancel');
348 $this->t->set_var('district_name',$district_name);
349 $this->t->set_var('district_number',$district);
350 $this->t->set_var('title','Hometeaching Update ' . $month);
351 $this->t->set_var('date',$date);
353 if($action == 'save')
355 // Get a list of all the companionships in this district
356 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $district;
357 $this->db->query($sql,__LINE__,__FILE__);
359 while ($this->db->next_record())
361 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
364 for ($j=0; $j < count($unique_companionships); $j++)
366 // FIXME: We won't be able to go back and edit history on families that have been
367 // reassigned to a different companionship. The following delete command will not delete
368 // the history of visits under an older companionship, only the ones for the existing
369 // companionship. This will lead to duplicate visits being entered for an older
370 // month for the same family, making it impossible to change the past history once
371 // a family is reassigned. However, you will be able to view the history just fine.
373 //$comp=$unique_companionships[$j]['companionship'];
374 //print "deleting from eq_visit where companionship=$comp and date=$date and district=$district<br>";
375 // Delete all the visits that have taken place for all families for this month
376 $this->db->query("DELETE from eq_visit where companionship=" . $unique_companionships[$j]['companionship'] .
377 " AND " . "date='" . $date . "'",__LINE__,__FILE__);
380 // Now, add the visits that are checked for this month
381 $new_data = get_var('family_visited',array('POST'));
382 foreach ($new_data as $family)
384 foreach ($family as $data)
386 //print "family_visited: $data <br>";
387 $data_array = explode("/",$data);
388 $family_id = $data_array[0];
389 $companionship = $data_array[1];
390 $date = $data_array[2];
391 $visited = $data_array[3];
392 if($visited == "") { $visited = $data_array[4]; }
393 //print "family_id: $family_id companionship: $companionship date: $date visited: $visited<br>";
394 $this->db->query("INSERT INTO eq_visit (family,companionship,date,notes,visited) "
395 . "VALUES (" . $family_id .",". $companionship .",'". $date ."','','". $visited ."')",__LINE__,__FILE__);
402 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
403 $this->db->query($sql,__LINE__,__FILE__);
405 while ($this->db->next_record())
407 $elder_id[$i] = $this->db->f('elder');
408 $elder_name[$i] = $this->db->f('name');
409 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
412 array_multisort($elder_name, $elder_id);
414 // Make an array mapping elder_ids to elder_names
415 for($i=0; $i < count($elder_id); $i++) {
417 $elders[$id] = $elder_name[$i];
420 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
421 $this->db->query($sql,__LINE__,__FILE__);
422 while ($this->db->next_record())
424 $aaronic_id = $this->db->f('aaronic');
425 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
426 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
429 // Select all the unique companionship numbers for this district
430 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $district;
431 $this->db->query($sql,__LINE__,__FILE__);
432 $j=0; $unique_companionships='';
433 while ($this->db->next_record())
435 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
439 $comp_width=300; $visit_width=25; $table_width=$comp_width + $visit_width;
440 $table_data=""; $num_companionships = 0; $num_families = 0; $visits=0;
441 for ($j=0; $j < count($unique_companionships); $j++) {
442 $companion_table_entry = "";
443 // Select all the companions in each companionship
444 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
445 "companionship=". $unique_companionships[$j]['companionship'];
446 $this->db->query($sql,__LINE__,__FILE__);
448 while ($this->db->next_record())
450 // Get this companions information
451 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
452 $companionship = $this->db->f('companionship');
453 $elder_id = $this->db->f('elder');
454 $aaronic_id = $this->db->f('aaronic');
456 $name = $elders[$elder_id];
457 $phone = $elder_phone[$elder_id];
459 else if($aaronic_id) {
460 $name = $aaronic[$aaronic_id]['name'];
461 $phone = $aaronic[$aaronic_id]['phone'];
463 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
465 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
467 // Get the names of the families assigned this home teaching companionship
468 $sql = "SELECT * from eq_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
469 $sql = $sql . " ORDER BY name ASC";
470 $this->db->query($sql,__LINE__,__FILE__);
471 while ($this->db->next_record())
473 $num_families++; $total_families++;
474 $family_name = $this->db->f('name');
475 $family_id = $this->db->f('family');
476 $this->nextmatchs->template_alternate_row_color(&$this->t);
477 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
479 $header_row="<th width=$comp_width><font size=-2>Families</th>";
480 $sql = "SELECT * FROM eq_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
481 " AND companionship!=0".
482 " AND family=". $family_id;
483 $this->db2->query($sql,__LINE__,__FILE__);
484 $value = $family_id . "/" . $unique_companionships[$j]['companionship'] . "/" . $date;
485 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
486 if(!$total_visits) { $total_visits = 0; }
487 if($this->db2->next_record()) {
488 if($this->db2->f('visited') == 'y') {
489 $visits++; $total_visits++;
490 $table_data .= '<td width=100 align=center>';
491 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y" checked>Y';
492 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
493 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/"> ';
494 $table_data .= '</td>';
495 } else if($this->db2->f('visited') == 'n') {
496 $table_data .= '<td width=100 align=center>';
497 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
498 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n" checked>N';
499 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/">';
500 $table_data .= '</td>';
502 $table_data .= '<td width=100 align=center>';
503 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
504 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
505 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
506 $table_data .= '</td>';
511 $table_data .= '<td width=100 align=center>';
512 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
513 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
514 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
515 $table_data .= '</td>';
518 $table_data .= "</tr>";
519 $table_data .= "<tr><td colspan=20></td></tr>";
521 $table_data .= "<tr><td colspan=20><hr></td></tr>";
522 $stat_data = "<tr><td><b><font size=-2>$num_families Families<br>Visit Totals:</font></b></td>";
524 $percent = ceil(($visits / $num_families)*100);
525 $stat_data .= "<td align=center><font size=-2><b>$visits<br>$percent%</font></b></td>";
526 $stat_data .= "</tr>";
528 $this->t->set_var('table_width',$table_width);
529 $this->t->set_var('header_row',$header_row);
530 $this->t->set_var('table_data',$table_data);
531 $this->t->set_var('stat_data',$stat_data);
532 $this->t->fp('list','district_list',True);
534 $this->t->set_var('lang_reset','Clear Form');
535 $this->t->set_var('lang_save','Save Changes');
536 $this->t->set_var('savehandle','');
538 $this->t->pfp('out','ht_update_t');
539 $this->t->pfp('addhandle','save');
541 $this->save_sessiondata();
546 $this->t->set_file(array('act_list_t' => 'act_list.tpl'));
547 $this->t->set_block('act_list_t','act_list','list');
549 $this->t->set_var('lang_name','Activity Name');
550 $this->t->set_var('lang_date','Date');
552 $sql = "SELECT * FROM eq_activity ORDER BY date DESC";
553 $this->db->query($sql,__LINE__,__FILE__);
554 $total_records = $this->db->num_rows();
557 while ($this->db->next_record())
559 $activity_list[$i]['name'] = $this->db->f('name');
560 $activity_list[$i]['date'] = $this->db->f('date');
561 $activity_list[$i]['activity'] = $this->db->f('activity');
565 for ($i=0; $i < count($activity_list); $i++)
567 $this->nextmatchs->template_alternate_row_color(&$this->t);
568 $this->t->set_var('name',$activity_list[$i]['name']);
569 $this->t->set_var('date',$activity_list[$i]['date']);
571 $link_data['menuaction'] = 'eq.eq.act_view';
572 $link_data['activity'] = $activity_list[$i]['activity'];
573 $link_data['action'] = 'view';
574 $this->t->set_var('view',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
575 $this->t->set_var('lang_view','View');
577 $link_data['menuaction'] = 'eq.eq.act_update';
578 $link_data['activity'] = $activity_list[$i]['activity'];
579 $link_data['action'] = 'edit';
580 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
581 $this->t->set_var('lang_edit','Edit');
583 $link_data['menuaction'] = 'eq.eq.act_update';
584 $link_data['activity'] = '0';
585 $link_data['action'] = 'add';
586 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/eq/index.php',$link_data)
587 . '"><input type="submit" name="Add" value="' . 'Add Activity' .'"></font></form>');
589 $this->t->fp('list','act_list',True);
592 $this->t->pfp('out','act_list_t');
593 $this->save_sessiondata();
598 $this->t->set_file(array('act_view_t' => 'act_view.tpl'));
599 $this->t->set_block('act_view_t','part_list','list');
601 $sql = "SELECT * FROM eq_activity WHERE activity=" . intval(get_var('activity',array('GET','POST')));
602 $this->db->query($sql,__LINE__,__FILE__);
603 $this->db->next_record();
604 $this->t->set_var('name', $this->db->f('name'));
605 $this->t->set_var('date', $this->db->f('date'));
606 $this->t->set_var('notes', $this->db->f('notes'));
608 $this->t->set_var('lang_name','Activity Name');
609 $this->t->set_var('lang_date','Date');
610 $this->t->set_var('lang_notes','Notes');
611 $this->t->set_var('lang_done','Done');
612 $this->t->set_var('lang_action','View');
614 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
615 $this->t->set_var('tr_color',$tr_color);
617 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_list'));
619 $link_data['menuaction'] = 'eq.eq.act_update';
620 $link_data['activity'] = get_var('activity',array('GET','POST'));
621 $link_data['action'] = 'edit';
622 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
623 $this->t->set_var('lang_edit','Edit');
624 $this->t->set_var('cal_date',$this->db->f('date'));
626 // Now find out which elders participated in this activity
627 $sql = "SELECT * FROM eq_participation WHERE activity=" . intval(get_var('activity',array('GET','POST')));
628 $this->db->query($sql,__LINE__,__FILE__);
629 $total_records = $this->db->num_rows();
632 while ($this->db->next_record())
634 $part_list[$i]['elder'] = $this->db->f('elder');
638 for ($i=0; $i < count($part_list); $i++)
640 $sql = "SELECT * FROM eq_elder WHERE elder=" . $part_list[$i]['elder'];
641 $this->db->query($sql,__LINE__,__FILE__);
642 $this->db->next_record();
643 $names[$i] = $this->db->f('name');
646 for ($i=0; $i < count($names); $i++)
648 //$this->nextmatchs->template_alternate_row_color(&$this->t);
649 $this->t->set_var('elder_name',$names[$i]);
650 if(($i+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
651 else { $this->t->set_var('table_sep',"</td>"); }
652 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
653 $this->t->fp('list','part_list',True);
656 $this->t->pfp('out','act_view_t');
657 $this->save_sessiondata();
660 function act_update()
662 $this->t->set_file(array('form' => 'act_update.tpl'));
663 $this->t->set_block('form','elder_list','list');
664 $this->t->set_block('form','add','addhandle');
665 $this->t->set_block('form','edit','edithandle');
666 $this->t->set_var('lang_done','Done');
668 $action = get_var('action',array('GET','POST'));
669 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_list'));
670 $activity['activity'] = intval(get_var('activity',array('GET','POST')));
672 if($action == 'save')
674 $activity['name'] = $this->db->db_addslashes(get_var('name',array('POST')));
675 $activity['date'] = $this->db->db_addslashes(get_var('date',array('POST')));
676 $activity['notes']= $this->db->db_addslashes(get_var('notes',array('POST')));
677 $this->db->query("UPDATE eq_activity set " .
678 " name='" . $activity['name'] .
679 "', date='" . $activity['date'] . "'" .
680 ", notes='" . $activity['notes'] . "'" .
681 " WHERE activity=" . $activity['activity'],__LINE__,__FILE__);
683 // Delete all the elders who have particiapted in this activity
684 $this->db->query("DELETE from eq_participation where activity=".$activity['activity'],__LINE__,__FILE__);
686 // Re-add the elders who are checked as having participated in this activity
687 $elders = get_var('elder_name',array('POST'));
688 foreach ($elders as $elder)
690 $this->db->query("INSERT INTO eq_participation (elder,activity) "
691 . "VALUES (" . $elder . ",". $activity['activity'] . ")",__LINE__,__FILE__);
698 if($action == 'insert')
700 $activity['name'] = $this->db->db_addslashes(get_var('name',array('POST')));
701 $activity['date'] = $this->db->db_addslashes(get_var('date',array('POST')));
702 $activity['notes']= $this->db->db_addslashes(get_var('notes',array('POST')));
703 $this->db->query("INSERT INTO eq_activity (name,date,notes) "
704 . "VALUES ('" . $activity['name'] . "','"
705 . $activity['date'] . "','" . $activity['notes'] . "')",__LINE__,__FILE__);
712 $activity['activity'] = 0;
713 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
714 $this->t->set_var('name','');
715 $this->t->set_var('date','');
716 $this->t->set_var('notes','');
717 $this->t->set_var('lang_done','Cancel');
718 $this->t->set_var('lang_action','Adding New Activity');
719 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_update&activity='
720 . $activity['activity'] . '&action=' . 'insert'));
723 if($action == 'edit')
725 $sql = "SELECT * FROM eq_activity WHERE activity=" . $activity['activity'];
726 $this->db->query($sql,__LINE__,__FILE__);
727 $this->db->next_record();
728 $this->t->set_var('cal_date',$this->jscal->input('date',$this->db->f('date'),'','','','','',$this->cal_options));
729 $this->t->set_var('name', $this->db->f('name'));
730 $this->t->set_var('date', $this->db->f('date'));
731 $this->t->set_var('notes', $this->db->f('notes'));
732 $this->t->set_var('lang_done','Cancel');
733 $this->t->set_var('lang_action','Editing Activity');
734 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_update&activity='
735 . $activity['activity'] . '&action=' . 'save'));
739 $sql = "SELECT * FROM eq_elder";
740 $this->db->query($sql,__LINE__,__FILE__);
742 while ($this->db->next_record())
744 if($this->db->f('valid') == 1 || $action != 'add') {
745 $elder_name[$i] = $this->db->f('name');
746 $elder_id[$i] = $this->db->f('elder');
747 $elder_valid[$i] = $this->db->f('valid');
751 array_multisort($elder_name, $elder_id, $elder_valid);
754 for ($i=0; $i < count($elder_id); $i++)
756 //$this->nextmatchs->template_alternate_row_color(&$this->t);
757 $sql = "SELECT * FROM eq_participation where activity=". $activity['activity'] . " AND elder=" . $elder_id[$i];
758 $this->db->query($sql,__LINE__,__FILE__);
759 if($this->db->next_record()) { $this->t->set_var('checked','checked'); $checked=1; }
760 else { $this->t->set_var('checked',''); $checked=0; }
761 if($checked || $elder_valid[$i] == 1) {
762 $this->t->set_var('elder_name',$elder_name[$i]);
763 $this->t->set_var('elder',$elder_id[$i]);
764 if(($j+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
765 else { $this->t->set_var('table_sep',"</td>"); }
766 if(($j) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
767 $this->t->fp('list','elder_list',True);
772 $this->t->set_var('lang_reset','Clear Form');
773 $this->t->set_var('lang_add','Add Activity');
774 $this->t->set_var('lang_save','Save Changes');
775 $this->t->set_var('edithandle','');
776 $this->t->set_var('addhandle','');
778 $this->t->pfp('out','form');
779 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
780 if($action == 'add') { $this->t->pfp('addhandle','add'); }
782 $this->save_sessiondata();
787 $this->t->set_file(array('par_view_t' => 'par_view.tpl'));
788 $this->t->set_block('par_view_t','header_list','list1');
789 $this->t->set_block('par_view_t','elder_list','list2');
791 $sql = "SELECT * FROM eq_elder where valid=1";
792 $this->db->query($sql,__LINE__,__FILE__);
794 while ($this->db->next_record())
796 $elder_name[$i] = $this->db->f('name');
797 $elder_id[$i] = $this->db->f('elder');
800 array_multisort($elder_name, $elder_id);
802 $sql = "SELECT * FROM eq_activity ORDER BY date DESC";
803 $this->db->query($sql,__LINE__,__FILE__);
804 $total_records = $this->db->num_rows();
807 while ($this->db->next_record())
809 $activity_list[$i]['name'] = $this->db->f('name');
810 $activity_list[$i]['date'] = $this->db->f('date');
811 $activity_list[$i]['activity'] = $this->db->f('activity');
812 if($activity_list[$i]['date'] == '0000-00-00') { $activity_list[$i]['date']=""; }
816 $elder_width=250; $part_width=25; $act_width=50;
817 $total_width=$elder_width+$part_width;
818 for ($i=0; $i < count($activity_list); $i++) {
819 $this->t->set_var('activity_name',$activity_list[$i]['name']);
820 $this->t->set_var('activity_date',$activity_list[$i]['date']);
821 $this->t->fp('list1','header_list',True);
822 $total_width += $act_width;
825 for ($i=0; $i < count($elder_id); $i++) {
826 $participated=0; $part_table = '';
827 $this->nextmatchs->template_alternate_row_color(&$this->t);
828 $this->t->set_var('elder_name',$elder_name[$i]);
829 for ($j=0; $j < count($activity_list); $j++) {
830 $sql = "SELECT * FROM eq_participation where activity="
831 . $activity_list[$j]['activity'] . " AND elder=" . $elder_id[$i];
832 $this->db->query($sql,__LINE__,__FILE__);
833 if($this->db->next_record()) {
834 $part_table .= '<td align=center><img src="checkmark.gif"></td>';
837 $part_table .= '<td> </td>';
840 if($participated) { $part_table .= '<td align=center><img src="checkmark.gif">'.$participated.'</td>'; }
841 else { $part_table .= '<td> </td>'; }
842 $this->t->set_var('part_table',$part_table);
843 $this->t->fp('list2','elder_list',True);
845 $this->t->set_var('total_width',$total_width);
846 $this->t->set_var('elder_width',$elder_width);
847 $this->t->set_var('part_width',$part_width);
848 $this->t->set_var('act_width',$act_width);
849 $this->t->pfp('out','par_view_t');
850 $this->save_sessiondata();
855 $this->t->set_file(array('ppi_view_t' => 'ppi_view.tpl'));
856 $this->t->set_block('ppi_view_t','district_list','list');
858 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
859 $num_months = get_var('num_months',array('GET','POST'));
860 if($num_months == '') { $num_months = $this->default_ppi_num_months; }
861 $this->t->set_var('num_months',$num_months);
862 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
863 else { $this->t->set_var('lang_num_months','Months of History'); }
864 $this->t->set_var('lang_filter','Filter');
866 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
867 $this->t->set_var('eqpres_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view&eqpresppi=1'));
868 $eqpresppi = get_var('eqpresppi',array('GET','POST'));
870 if($eqpresppi == 1) {
871 $num_months = get_var('num_months',array('GET','POST'));
872 if($num_months == '') { $num_months = $this->default_ppi_num_years; }
873 $this->t->set_var('num_months',$num_months);
874 $this->t->set_var('ppi_link_title','PPIs');
875 $this->t->set_var('title','EQ President Yearly PPIs');
876 if($num_months == 1) { $this->t->set_var('lang_num_months','Year of History'); }
877 else { $this->t->set_var('lang_num_months','Years of History'); }
878 $this->t->set_var('eqpres_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
881 $this->t->set_var('ppi_link_title','EQ President Yearly PPIs');
882 $this->t->set_var('title','PPIs');
885 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
886 $this->db->query($sql,__LINE__,__FILE__);
888 while ($this->db->next_record())
890 if($eqpresppi == 1 && $this->db->f('district') == 1) {
891 $districts[$i]['district'] = $this->db->f('district');
892 $districts[$i]['name'] = $this->db->f('name');
893 $districts[$i]['supervisor'] = $this->db->f('supervisor');
894 } else if($eqpresppi == 0) {
895 $districts[$i]['district'] = $this->db->f('district');
896 $districts[$i]['name'] = $this->db->f('name');
897 $districts[$i]['supervisor'] = $this->db->f('supervisor');
902 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
903 $this->db->query($sql,__LINE__,__FILE__);
905 while ($this->db->next_record())
907 $elder_id[$i] = $this->db->f('elder');
908 $elder_name[$i] = $this->db->f('name');
909 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
912 array_multisort($elder_name, $elder_id);
913 for($i=0; $i < count($elder_id); $i++) {
915 $elders[$id] = $elder_name[$i];
918 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
919 $this->db->query($sql,__LINE__,__FILE__);
920 while ($this->db->next_record())
922 $aaronic_id = $this->db->f('aaronic');
923 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
924 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
927 $total_companionships = 0;
928 $this->nextmatchs->template_alternate_row_color(&$this->t);
929 for ($i=0; $i < count($districts); $i++) {
930 if($eqpresppi == 1) {
931 $this->t->set_var('district_number','*');
932 $this->t->set_var('district_name','EQ President');
934 $this->t->set_var('district_number',$districts[$i]['district']);
935 $this->t->set_var('district_name',$districts[$i]['name']);
937 $supervisor = $districts[$i]['supervisor'];
938 $unique_companionships='';
940 // Select all the unique companionship numbers for this district
941 if($eqpresppi == 1) {
942 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1";
945 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $districts[$i]['district'];
947 $this->db->query($sql,__LINE__,__FILE__);
949 while ($this->db->next_record())
951 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
955 $comp_width=400; $ppi_width=25; $table_width=$comp_width + $num_months*$ppi_width;
956 $table_data=""; $num_companionships = $j; $num_elders = 0;
957 for($m=$num_months; $m >= 0; $m--) { $ppis[$m] = 0; }
958 for ($j=0; $j < count($unique_companionships); $j++) {
959 // Select all the companions in each companionship
961 $sql = "SELECT * FROM eq_companionship where valid=1 and aaronic=0 and ".
962 "companionship=". $unique_companionships[$j]['companionship'];
965 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
966 "companionship=". $unique_companionships[$j]['companionship'];
968 $this->db->query($sql,__LINE__,__FILE__);
970 $comp = $unique_companionships[$j]['companionship'];
971 for($m=$num_months; $m >= 0; $m--) { $ppi_recorded[$comp][$m] = 0; }
972 while ($this->db->next_record())
974 // Get this companions information
976 $companionship = $this->db->f('companionship');
977 $elder_id = $this->db->f('elder');
978 $aaronic_id = $this->db->f('aaronic');
980 $name = $elders[$elder_id];
981 $phone = $elder_phone[$elder_id];
983 else if($aaronic_id) {
984 $name = $aaronic[$aaronic_id]['name'];
985 $phone = $aaronic[$aaronic_id]['phone'];
987 $link_data['menuaction'] = 'eq.eq.ppi_update';
988 $link_data['companionship'] = $companionship;
989 $link_data['interviewer'] = $supervisor;
990 $link_data['elder'] = $elder_id;
991 $link_data['aaronic'] = $aaronic_id;
992 $link_data['name'] = $name;
993 $link_data['ppi'] = '';
994 $link_data['eqpresppi'] = $eqpresppi;
995 $link_data['action'] = 'add';
996 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
997 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
999 // Find out how many times PPIs were performed in the past $num_months for this Elder
1000 $header_row="<th width=$comp_width><font size=-2>Companionship</th>";
1001 for($m=$num_months; $m >= 0; $m--) {
1002 if($eqpresppi == 1) {
1003 $year = date('Y') - $m;
1004 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
1005 $sql = "SELECT * FROM eq_ppi WHERE date > '$year_start' AND date < '$year_end' ".
1006 "AND elder=" . $elder_id . " AND aaronic=" . $aaronic_id . " AND eqpresppi=1";
1007 $this->db2->query($sql,__LINE__,__FILE__);
1008 $header_row .= "<th width=150><font size=-2>$year</th>";
1011 $month = $this->current_month - $m;
1012 $year = $this->current_year;
1013 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
1014 if($month < 10) { $month = "0"."$month"; }
1015 $month_start = "$year"."-"."$month"."-"."01";
1016 $month_end = "$year"."-"."$month"."-"."31";
1017 $month = "$month"."/"."$year";
1018 $sql = "SELECT * FROM eq_ppi WHERE date >= '$month_start' AND date <= '$month_end' ".
1019 "AND elder=" . $elder_id . " AND aaronic=" . $aaronic_id . " AND eqpresppi=0";
1020 $this->db2->query($sql,__LINE__,__FILE__);
1021 $header_row .= "<th width=$ppi_width><font size=-2>$month</th>";
1023 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
1024 if($this->db2->next_record()) {
1025 if(!$ppi_recorded[$companionship][$m]) {
1026 $ppis[$m]++; $total_ppis[$m]++; $ppi_recorded[$companionship][$m]=1;
1028 $link_data['menuaction'] = 'eq.eq.ppi_update';
1029 $link_data['companionship'] = $companionship;
1030 $link_data['interviewer'] = $this->db2->f('interviewer');
1031 $link_data['elder'] = $elder_id;
1032 $link_data['aaronic'] = $aaronic_id;
1033 $link_data['name'] = $name;
1034 $link_data['ppi'] = $this->db2->f('ppi');
1035 $link_data['eqpresppi'] = $eqpresppi;
1036 $link_data['action'] = 'view';
1037 $date = $this->db2->f('date');
1038 $date_array = explode("-",$date);
1039 $month = $date_array[1];
1040 $day = $date_array[2];
1041 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1042 $table_data .= '<td align=center><a href='.$link.'><img src="checkmark.gif"><br>'.$month.'-'.$day.'</a></td>';
1044 else { $table_data .= "<td> </td>"; }
1046 $table_data .= "</tr>";
1049 $table_data .= "<tr><td colspan=20><hr></td></tr>";
1051 // Now add Elders not assigned to any companionship to the table if we are in eqpresppi mode
1052 if($eqpresppi == 1) {
1053 $table_data .= "<tr bgcolor=\"#c9c9c9\"><hr><td colspan=20><b>Unassigned Potential Home Teachers</b><hr></td></tr>";
1054 foreach($elders as $elder_id => $value) {
1055 $sql = "SELECT * FROM eq_companionship where valid=1 and elder=".$elder_id;
1056 $this->db->query($sql,__LINE__,__FILE__);
1057 if(!$this->db->next_record()) {
1058 // We found an Elder not in a companionship, add them to the table
1061 $name = $elders[$elder_id];
1062 $link_data['menuaction'] = 'eq.eq.ppi_update';
1063 $link_data['companionship'] = $companionship;
1064 $link_data['interviewer'] = $supervisor;
1065 $link_data['elder'] = $elder_id;
1066 $link_data['name'] = $name;
1067 $link_data['ppi'] = '';
1068 $link_data['eqpresppi'] = $eqpresppi;
1069 $link_data['action'] = 'add';
1070 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1071 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td><a href=$link>$name</a></td>";
1072 for($m=$num_months; $m >= 0; $m--) {
1073 $year = date('Y') - $m;
1074 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
1075 $sql = "SELECT * FROM eq_ppi WHERE date > '$year_start' AND date < '$year_end' ".
1076 "AND elder=" . $elder_id . " AND eqpresppi=1";
1077 $this->db2->query($sql,__LINE__,__FILE__);
1078 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
1079 if($this->db2->next_record()) {
1080 $ppis[$m]++; $total_ppis[$m]++;
1081 $link_data['menuaction'] = 'eq.eq.ppi_update';
1082 $link_data['companionship'] = $companionship;
1083 $link_data['interviewer'] = $supervisor;
1084 $link_data['elder'] = $elder_id;
1085 $link_data['name'] = $name;
1086 $link_data['ppi'] = $this->db2->f('ppi');
1087 $link_data['eqpresppi'] = $eqpresppi;
1088 $link_data['action'] = 'view';
1089 $date = $this->db2->f('date');
1090 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1091 $table_data .= '<td align=center><a href='.$link.'><img src="checkmark.gif"><br>'.$date.'</a></td>';
1093 else { $table_data .= "<td> </td>"; }
1095 $table_data .= "</tr>";
1099 $total_companionships += $num_companionships;
1100 if($eqpresppi == 1) {
1101 $stat_data = "<tr><td><b><font size=-2>$num_elders Elders<br>PPI Totals:</font></b></td>";
1103 $stat_data = "<tr><td><b><font size=-2>$num_companionships Companionships<br>PPI Totals:</font></b></td>";
1105 for($m=$num_months; $m >=0; $m--) {
1106 if($eqpresppi == 1) { $percent = ceil(($ppis[$m] / $num_elders)*100); }
1107 else { $percent = ceil(($ppis[$m] / $num_companionships)*100); }
1108 $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
1110 $stat_data .= "</tr>";
1112 $this->t->set_var('table_width',$table_width);
1113 $this->t->set_var('header_row',$header_row);
1114 $this->t->set_var('table_data',$table_data);
1115 $this->t->set_var('stat_data',$stat_data);
1116 $this->t->fp('list','district_list',True);
1119 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>PPI Totals:</font></b></td>";
1120 for($m=$num_months; $m >=0; $m--) {
1121 $percent = ceil(($total_ppis[$m] / $total_companionships)*100);
1122 $totals .= "<td align=center><font size=-2><b>$total_ppis[$m]<br>$percent%</font></b></td>";
1126 $this->t->set_var('totals',$totals);
1127 $this->t->pfp('out','ppi_view_t');
1128 $this->save_sessiondata();
1131 function ppi_update()
1133 $this->t->set_file(array('form' => 'ppi_update.tpl'));
1134 $this->t->set_block('form','interviewer_list','int_list');
1135 $this->t->set_block('form','add','addhandle');
1136 $this->t->set_block('form','edit','edithandle');
1138 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
1139 $this->t->set_var('readonly','');
1140 $this->t->set_var('disabled','');
1142 $action = get_var('action',array('GET','POST'));
1143 $companionship = get_var('companionship',array('GET','POST'));
1144 $interviewer = get_var('interviewer',array('GET','POST'));
1145 $name = get_var('name',array('GET','POST'));
1146 $ppi = get_var('ppi',array('GET','POST'));
1147 $elder = get_var('elder',array('GET','POST'));
1148 $aaronic = get_var('aaronic',array('GET','POST'));
1149 $date = get_var('date',array('GET','POST'));
1150 $notes = get_var('notes',array('GET','POST'));
1151 $eqpresppi = get_var('eqpresppi',array('GET','POST'));
1153 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
1154 $this->db->query($sql,__LINE__,__FILE__);
1155 while ($this->db->next_record())
1157 $supervisor = $this->db->f('supervisor');
1158 $sql = "SELECT * FROM eq_elder WHERE elder=" . $supervisor;
1159 $this->db2->query($sql,__LINE__,__FILE__);
1160 $this->db2->next_record();
1161 $interviewer_name = $this->db2->f('name');
1163 if($supervisor == $interviewer) {
1164 $this->t->set_var('interviewer',$supervisor . ' selected');
1166 $this->t->set_var('interviewer',$interviewer);
1168 $this->t->set_var('interviewer_name',$interviewer_name);
1169 $this->t->fp('int_list','interviewer_list',True);
1172 if($action == 'save')
1174 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
1175 $this->db->query("UPDATE eq_ppi set " .
1176 " ppi='" . $ppi . "'" .
1177 ", interviewer='" . $interviewer . "'" .
1178 ", elder='" . $elder . "'" .
1179 ", aaronic='" . $aaronic . "'" .
1180 ", date='" . $date . "'" .
1181 ", notes='" . $notes . "'" .
1182 ", eqpresppi='" . $eqpresppi . "'" .
1183 " WHERE ppi=" . $ppi,__LINE__,__FILE__);
1188 if($action == 'insert')
1190 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
1191 $this->db->query("INSERT INTO eq_ppi (interviewer,elder,aaronic,date,notes,eqpresppi) "
1192 . "VALUES ('" . $interviewer . "','" . $elder . "','" . $aaronic . "','"
1193 . $date . "','" . $notes . "','" . $eqpresppi ."')",__LINE__,__FILE__);
1198 if($action == 'add')
1200 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
1201 $this->t->set_var('ppi', '');
1202 $this->t->set_var('interviewer', $interviewer);
1203 $this->t->set_var('name',$name);
1204 $this->t->set_var('elder',$elder);
1205 $this->t->set_var('aaronic',$aaronic);
1206 $this->t->set_var('date','');
1207 $this->t->set_var('notes','');
1208 $this->t->set_var('eqpresppi',$eqpresppi);
1209 $this->t->set_var('lang_done','Cancel');
1210 $this->t->set_var('lang_action','Adding New PPI');
1211 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
1212 . $ppi . '&action=' . 'insert'));
1215 if($action == 'edit' || $action == 'view')
1217 $sql = "SELECT * FROM eq_ppi WHERE ppi=".$ppi;
1218 $this->db->query($sql,__LINE__,__FILE__);
1219 $this->db->next_record();
1220 $this->t->set_var('ppi',$ppi);
1221 $this->t->set_var('name',$name);
1222 $this->t->set_var('interviewer', $this->db->f('interviewer'));
1223 $this->t->set_var('elder',$this->db->f('elder'));
1224 $this->t->set_var('aaronic',$this->db->f('aaronic'));
1225 $this->t->set_var('date',$this->db->f('date'));
1226 $this->t->set_var('notes',$this->db->f('notes'));
1227 $this->t->set_var('eqpresppi',$this->db->f('eqpresppi'));
1230 if($action == 'edit')
1232 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
1233 $this->t->set_var('lang_done','Cancel');
1234 $this->t->set_var('lang_action','Editing PPI');
1235 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
1236 . $ppi . '&action=' . 'save'));
1239 if($action == 'view')
1241 $date = $this->db->f('date');
1242 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
1243 $this->t->set_var('readonly','READONLY');
1244 $this->t->set_var('disabled','DISABLED');
1245 $this->t->set_var('lang_done','Done');
1246 $this->t->set_var('lang_action','Viewing PPI');
1247 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
1248 . $ppi . '&action=' . 'edit'));
1251 $this->t->set_var('lang_reset','Clear Form');
1252 $this->t->set_var('lang_add','Add PPI');
1253 $this->t->set_var('lang_save','Save Changes');
1254 $this->t->set_var('edithandle','');
1255 $this->t->set_var('addhandle','');
1257 $this->t->pfp('out','form');
1259 if($action == 'view') { $this->t->set_var('lang_save','Edit PPI'); }
1260 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
1261 if($action == 'add') { $this->t->pfp('addhandle','add'); }
1263 $this->save_sessiondata();
1268 $this->t->set_file(array('vis_view_t' => 'vis_view.tpl'));
1269 $this->t->set_block('vis_view_t','visit_list','list1');
1270 $this->t->set_block('vis_view_t','family_list','list2');
1272 $this->t->set_var('lang_name','Family Name');
1273 $this->t->set_var('lang_date','Date');
1275 $sql = "SELECT * FROM eq_visit WHERE companionship=0 ORDER BY date DESC";
1276 $this->db->query($sql,__LINE__,__FILE__);
1277 $total_records = $this->db->num_rows();
1280 while ($this->db->next_record())
1282 $visit_list[$i]['visit'] = $this->db->f('visit');
1283 $visit_list[$i]['family'] = $this->db->f('family');
1284 $visit_list[$i]['date'] = $this->db->f('date');
1288 for ($i=0; $i < count($visit_list); $i++)
1290 $this->nextmatchs->template_alternate_row_color(&$this->t);
1292 $sql = "SELECT * FROM eq_family WHERE family=".$visit_list[$i]['family'];
1293 $this->db->query($sql,__LINE__,__FILE__);
1294 $this->db->next_record();
1296 $this->t->set_var('family',$visit_list[$i]['family']);
1297 $this->t->set_var('family_name',$this->db->f('name'));
1298 $this->t->set_var('date',$visit_list[$i]['date']);
1300 $link_data['menuaction'] = 'eq.eq.vis_update';
1301 $link_data['visit'] = $visit_list[$i]['visit'];
1302 $link_data['name'] = $this->db->f('name');
1303 $link_data['date'] = $visit_list[$i]['date'];
1304 $link_data['action'] = 'view';
1305 $this->t->set_var('view',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1306 $this->t->set_var('lang_view','View');
1308 $link_data['menuaction'] = 'eq.eq.vis_update';
1309 $link_data['visit'] = $visit_list[$i]['visit'];
1310 $link_data['name'] = $this->db->f('name');
1311 $link_data['date'] = $visit_list[$i]['date'];
1312 $link_data['action'] = 'edit';
1313 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1314 $this->t->set_var('lang_edit','Edit');
1316 $this->t->fp('list1','visit_list',True);
1319 // List the families that are available to record a visit against
1320 $sql = "SELECT * FROM eq_family WHERE valid=1";
1321 $this->db->query($sql,__LINE__,__FILE__);
1322 $total_records = $this->db->num_rows();
1325 while ($this->db->next_record())
1327 $family_names[$i] = $this->db->f('name');
1328 $family_ids[$i] = $this->db->f('family');
1330 } array_multisort($family_names, $family_ids);
1332 for ($i=0; $i < count($family_names); $i++)
1334 $link_data['menuaction'] = 'eq.eq.vis_update';
1335 $link_data['visit'] = '';
1336 $link_data['family'] = $family_ids[$i];
1337 $link_data['action'] = 'add';
1338 $link_data['name'] = $family_names[$i];
1339 $this->t->set_var('add',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1341 $this->t->set_var('name',$family_names[$i]);
1342 if(($i+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
1343 else { $this->t->set_var('table_sep',"</td>"); }
1344 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
1346 $this->t->fp('list2','family_list',True);
1349 $this->t->pfp('out','vis_view_t');
1350 $this->save_sessiondata();
1353 function vis_update()
1355 $this->t->set_file(array('form' => 'vis_update.tpl'));
1356 $this->t->set_block('form','add','addhandle');
1357 $this->t->set_block('form','edit','edithandle');
1359 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
1360 $this->t->set_var('readonly','');
1361 $this->t->set_var('disabled','');
1363 $action = get_var('action',array('GET','POST'));
1364 $visit = get_var('visit',array('GET','POST'));
1365 $family = get_var('family',array('GET','POST'));
1366 $name = get_var('name',array('GET','POST'));
1367 $date = get_var('date',array('GET','POST'));
1368 $notes = get_var('notes',array('GET','POST'));
1371 if($action == 'save')
1373 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
1374 $this->db->query("UPDATE eq_visit set " .
1375 " date='" . $date . "'" .
1376 ", notes='" . $notes . "'" .
1377 " WHERE visit=" . $visit,__LINE__,__FILE__);
1382 if($action == 'insert')
1384 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
1385 $this->db->query("INSERT INTO eq_visit (family,companionship,date,notes) "
1386 . "VALUES ('" . $family . "','" . $companionship . "','"
1387 . $date . "','" . $notes . "')",__LINE__,__FILE__);
1392 if($action == 'add')
1394 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
1395 $this->t->set_var('family', $family);
1396 $this->t->set_var('visit', '');
1397 $this->t->set_var('name', $name);
1398 $this->t->set_var('date','');
1399 $this->t->set_var('notes','');
1400 $this->t->set_var('lang_done','Cancel');
1401 $this->t->set_var('lang_action','Adding New Visit');
1402 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&family='
1403 . $family . '&action=' . 'insert'));
1406 if($action == 'edit' || $action == 'view')
1408 $sql = "SELECT * FROM eq_visit WHERE visit=".$visit;
1409 $this->db->query($sql,__LINE__,__FILE__);
1410 $this->db->next_record();
1411 $this->t->set_var('visit',$visit);
1412 $this->t->set_var('name',$name);
1413 $this->t->set_var('family', $family);
1414 $this->t->set_var('date',$this->db->f('date'));
1415 $this->t->set_var('notes',$this->db->f('notes'));
1418 if($action == 'edit')
1420 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
1421 $this->t->set_var('lang_done','Cancel');
1422 $this->t->set_var('lang_action','Editing Visit');
1423 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&visit='
1424 . $visit . '&action=' . 'save'));
1427 if($action == 'view')
1429 $date = $this->db->f('date');
1430 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
1431 $this->t->set_var('readonly','READONLY');
1432 $this->t->set_var('disabled','DISABLED');
1433 $this->t->set_var('lang_done','Done');
1434 $this->t->set_var('lang_action','Viewing Visit');
1435 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&visit='
1436 . $visit . '&action=' . 'edit'));
1439 $this->t->set_var('lang_reset','Clear Form');
1440 $this->t->set_var('lang_add','Add Visit');
1441 $this->t->set_var('lang_save','Save Changes');
1442 $this->t->set_var('edithandle','');
1443 $this->t->set_var('addhandle','');
1445 $this->t->pfp('out','form');
1447 if($action == 'view') { $this->t->set_var('lang_save','Edit Visit'); }
1448 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
1449 if($action == 'add') { $this->t->pfp('addhandle','add'); }
1451 $this->save_sessiondata();
1456 $this->t->set_file(array('att_view_t' => 'att_view.tpl'));
1457 $this->t->set_block('att_view_t','act_list','list');
1459 $this->t->set_block('att_view_t','month_list','list1');
1460 $this->t->set_block('att_view_t','header_list','list2');
1461 $this->t->set_block('att_view_t','elder_list','list3');
1463 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_view'));
1464 $num_months = get_var('num_months',array('GET','POST'));
1465 if($num_months == '') { $num_months = $this->default_att_num_months; }
1466 $this->t->set_var('num_months',$num_months);
1467 $this->t->set_var('lang_filter','Filter');
1468 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
1469 else { $this->t->set_var('lang_num_months','Months of History'); }
1471 $sql = "SELECT * FROM eq_elder where valid=1";
1472 $this->db->query($sql,__LINE__,__FILE__);
1474 while ($this->db->next_record())
1476 $elder_name[$i] = $this->db->f('name');
1477 $elder_id[$i] = $this->db->f('elder');
1480 array_multisort($elder_name, $elder_id);
1483 // Create a list of sunday dates for a window of 3 months back and current month
1487 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, date("m")-$num_months, 1, date("y")));
1488 $last_date = explode("-",$sunday_list[0]['date']);
1489 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
1490 $time_limit = mktime(0, 0, 0, date("m"), date("t"), date("y"));
1491 while($last_time < $time_limit)
1493 $day = date("w",$last_time);
1494 if(date("w",$last_time) == 0) {
1495 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
1496 $last_date = explode("-",$sunday_list[$i]['date']);
1497 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
1498 $sunday_list[$i]['day'] = $last_date[2];
1499 $sunday_list[$i]['month'] = date("M",$last_time);
1500 $sunday_list[$i]['year'] = $last_date[0];
1503 $last_time += 90000;
1504 if($found_sunday) { $i++; $found_sunday=0; }
1507 $total_elders = count($elder_id);
1508 $old_month=$sunday_list[0]['month']; $span=0;
1509 for ($i=0; $i < count($sunday_list); $i++) {
1510 $date = $sunday_list[$i]['date'];
1511 $this->t->set_var('date',$sunday_list[$i]['date']);
1512 $this->t->set_var('day',$sunday_list[$i]['day']);
1513 if(($old_month != $sunday_list[$i]['month']) || $i == count($sunday_list)-1) {
1514 if($i == count($sunday_list)-1) { $span++; }
1515 $cur_month = $sunday_list[$i]['month'];
1516 $old_month = $sunday_list[$i]['month'];
1517 $link_data['menuaction'] = 'eq.eq.att_update';
1518 $link_data['month'] = $sunday_list[$i-1]['month'];
1519 $link_data['year'] = $sunday_list[$i-1]['year'];
1520 $link_data['action'] = 'update_month';
1521 $cur_month = $sunday_list[$i-1]['month'];
1522 $cur_year = $sunday_list[$i-1]['year'];
1523 $header_row .= "<th><font size=-3>$cur_month $cur_year</font></th>";
1524 $this->t->set_var('update_month',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1525 $this->t->set_var('month',$sunday_list[$i-1]['month']);
1526 $this->t->set_var('year',$sunday_list[$i-1]['year']);
1527 $this->t->set_var('span',$span); $span=0;
1528 $this->t->fp('list1','month_list',True);
1531 $this->t->set_var('total_elders',$total_elders);
1532 $this->t->set_var('header_row',$header_row);
1534 $elder_width=200; $att_width=25; $total_width=$elder_width;
1535 for ($i=0; $i < count($sunday_list); $i++) {
1536 $link_data['menuaction'] = 'eq.eq.att_update';
1537 $link_data['month'] = $sunday_list[$i]['month'];
1538 $link_data['year'] = $sunday_list[$i]['year'];
1539 $link_data['day'] = $sunday_list[$i]['day'];
1540 $link_data['date'] = $sunday_list[$i]['date'];
1541 $link_data['action'] = 'update_day';
1542 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1543 $this->t->set_var('date',$sunday_list[$i]['date']);
1544 $this->t->set_var('day',$sunday_list[$i]['day']);
1545 $this->t->set_var('month',$sunday_list[$i]['month']);
1546 $this->t->set_var('year',$sunday_list[$i]['year']);
1547 $this->t->fp('list2','header_list',True);
1548 $total_width += $att_width;
1551 for ($i=0; $i < count($elder_id); $i++) {
1553 $this->nextmatchs->template_alternate_row_color(&$this->t);
1554 $this->t->set_var('elder_name',$elder_name[$i]);
1555 #print "checking for elder: " . $elder_id[$i] . "<br>";
1556 for ($j=0; $j < count($sunday_list); $j++) {
1557 #print "checking for date: " . $sunday_list[$j]['date'] . "<br>";
1558 #print "SELECT * FROM eq_attendance WHERE date='"
1559 # . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i] . "<br>";
1560 $sql = "SELECT * FROM eq_attendance WHERE date='"
1561 . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i];
1562 $this->db->query($sql,__LINE__,__FILE__);
1563 if($this->db->next_record()) {
1564 $cur_month = $sunday_list[$j]['month'];
1565 if($attended[$i][$cur_month] != 1) {
1566 $attended[$i][$cur_month]=1;
1567 $attendance[$cur_month]++;
1569 $att_table .= '<td align=center><img src="checkmark.gif"></td>';
1571 $att_table .= '<td> </td>';
1574 $this->t->set_var('att_table',$att_table);
1575 $this->t->fp('list3','elder_list',True);
1577 $this->t->set_var('total_width',$total_width);
1578 $this->t->set_var('elder_width',$elder_width);
1579 $this->t->set_var('att_width',$att_width);
1581 # Now calculate attendance for these months
1582 $attendance_str = "";
1583 $nonattendance_str = "";
1584 $aveattendance_str = "";
1585 $avenonattendance_str = "";
1587 $ave_total_attended=0;
1588 foreach($attendance as $att => $value) {
1589 $total_attended = $attendance[$att];
1590 $ave_total_attended += $attendance[$att]; $num_months++;
1591 $percent = ceil(($total_attended / $total_elders)*100);
1592 $attendance_str.="<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
1593 $total_nonattended = $total_elders - $total_attended;
1594 $percent = ceil(($total_nonattended / $total_elders)*100);
1595 $nonattendance_str.="<td align=center><font size=-2><b>$total_nonattended ($percent%)</b></font></td>";
1597 $total_attended = ceil(($ave_total_attended / $num_months));
1598 $percent = ceil(($total_attended / $total_elders)*100);
1599 $aveattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
1600 $total_attended = $total_elders - ceil(($ave_total_attended / $num_months));
1601 $percent = ceil(($total_attended / $total_elders)*100);
1602 $avenonattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
1605 $this->t->set_var('attendance',$attendance_str);
1606 $this->t->set_var('aveattendance',$aveattendance_str);
1607 $this->t->set_var('nonattendance',$nonattendance_str);
1608 $this->t->set_var('avenonattendance',$avenonattendance_str);
1610 $this->t->pfp('out','att_view_t');
1611 $this->save_sessiondata();
1614 function att_update()
1616 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
1617 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
1618 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
1620 $this->t->set_file(array('form' => 'att_update.tpl'));
1621 $this->t->set_block('form','edit','edithandle');
1623 $this->t->set_block('form','month_list','list1');
1624 $this->t->set_block('form','header_list','list2');
1625 $this->t->set_block('form','elder_list','list3');
1627 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_view'));
1629 $action = get_var('action',array('GET','POST'));
1630 $month = get_var('month',array('GET','POST'));
1631 $year = get_var('year',array('GET','POST'));
1632 $day = get_var('day',array('GET','POST'));
1633 $date = get_var('date',array('GET','POST'));
1635 if($action == 'save_month' || $action == 'save_day')
1637 $new_data = get_var('elders_attended',array('POST'));
1638 $month = $monthnum[$month]; if($month < 10) { $month = "0" . $month; }
1640 if($action == 'save_month') {
1641 $this->db->query("DELETE from eq_attendance where date LIKE '".$year."-".$month."-%'",__LINE__,__FILE__);
1644 if($action == 'save_day') {
1645 $this->db->query("DELETE from eq_attendance where date LIKE '".$year."-".$month."-".$day."'",__LINE__,__FILE__);
1648 foreach ($new_data as $data)
1650 $data_array = explode("-",$data);
1651 $elder = $data_array[0];
1652 $date = "$data_array[1]-$data_array[2]-$data_array[3]";
1653 $this->db->query("INSERT INTO eq_attendance (elder,date) "
1654 . "VALUES (" . $elder . ",'". $date . "')",__LINE__,__FILE__);
1661 $sql = "SELECT * FROM eq_elder where valid=1";
1662 $this->db->query($sql,__LINE__,__FILE__);
1664 while ($this->db->next_record())
1666 $elder_name[$i] = $this->db->f('name');
1667 $elder_id[$i] = $this->db->f('elder');
1670 array_multisort($elder_name, $elder_id);
1672 if($action == 'update_month')
1674 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_update&action=save_month'));
1678 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], 1, $year));
1679 $last_date = explode("-",$sunday_list[0]['date']);
1680 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
1681 $time_limit = mktime(0, 0, 0, $monthnum[$month], 31, $year);
1682 while($last_time <= $time_limit)
1684 $day = date("w",$last_time);
1685 if(date("w",$last_time) == 0) {
1686 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
1687 $last_date = explode("-",$sunday_list[$i]['date']);
1688 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
1689 $sunday_list[$i]['day'] = $last_date[2];
1690 $sunday_list[$i]['month'] = date("M",$last_time);
1691 $sunday_list[$i]['year'] = $last_date[0];
1694 $last_time += 90000;
1695 if($found_sunday) { $i++; $found_sunday=0; }
1698 $this->t->set_var('span', $i);
1699 $this->t->set_var('month',$sunday_list[$i-1]['month']);
1700 $this->t->set_var('year',$sunday_list[$i-1]['year']);
1701 $this->t->fp('list1','month_list',True);
1702 $elder_width=200; $att_width=25; $total_width=$elder_width;
1703 for ($i=0; $i < count($sunday_list); $i++) {
1704 $link_data['menuaction'] = 'eq.eq.att_update';
1705 $link_data['month'] = $sunday_list[$i]['month'];
1706 $link_data['year'] = $sunday_list[$i]['year'];
1707 $link_data['day'] = $sunday_list[$i]['day'];
1708 $link_data['date'] = $sunday_list[$i]['date'];
1709 $link_data['action'] = 'update_day';
1710 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
1711 $this->t->set_var('date',$sunday_list[$i]['date']);
1712 $this->t->set_var('day',$sunday_list[$i]['day']);
1713 $this->t->set_var('month',$sunday_list[$i]['month']);
1714 $this->t->set_var('year',$sunday_list[$i]['year']);
1715 $this->t->fp('list2','header_list',True);
1716 $total_width += $att_width;
1720 if($action == 'update_day')
1722 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_update&action=save_day'));
1723 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], $day, $year));
1724 $this->t->set_var('month',$month);
1725 $this->t->set_var('year',$year);
1726 $this->t->fp('list1','month_list',True);
1727 $this->t->set_var('date',$date);
1728 $this->t->set_var('day',$day);
1729 $this->t->set_var('month',$month);
1730 $this->t->set_var('year',$year);
1731 $this->t->fp('list2','header_list',True);
1734 for ($i=0; $i < count($elder_id); $i++) {
1736 $this->nextmatchs->template_alternate_row_color(&$this->t);
1737 $this->t->set_var('elder_name',$elder_name[$i]);
1738 for ($j=0; $j < count($sunday_list); $j++) {
1739 $sql = "SELECT * FROM eq_attendance WHERE date='"
1740 . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i];
1741 $this->db->query($sql,__LINE__,__FILE__);
1742 $value = $elder_id[$i] . "-" . $sunday_list[$j]['date'];
1743 if($this->db->next_record()) {
1744 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'" checked></td>';
1746 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'"></td>';
1749 $this->t->set_var('att_table',$att_table);
1750 $this->t->fp('list3','elder_list',True);
1753 $this->t->set_var('lang_done', 'Cancel');
1754 $this->t->set_var('lang_reset','Clear Form');
1755 $this->t->set_var('lang_save','Save Changes');
1757 $this->t->pfp('out','form');
1758 $this->t->pfp('addhandle','edit');
1760 $this->save_sessiondata();
1765 $this->t->set_file(array('dir_view_t' => 'dir_view.tpl'));
1766 $this->t->set_block('dir_view_t','dir_list','list');
1768 $sql = "SELECT * FROM eq_parent where valid=1 ORDER BY name ASC";
1769 $this->db->query($sql,__LINE__,__FILE__);
1771 while ($this->db->next_record())
1773 $parent[$i]['id'] = $this->db->f('parent');
1774 $parent[$i]['name'] = $this->db->f('name');
1775 $parent[$i]['phone'] = $this->db->f('phone');
1776 $parent[$i]['address'] = $this->db->f('address');
1780 for ($i=0; $i < count($parent); $i++)
1782 $name = $parent[$i]['name'];
1783 $phone = $parent[$i]['phone'];
1784 $address = $parent[$i]['address'];
1785 $this->t->set_var('name', $name);
1786 $this->t->set_var('address', $address);
1787 $this->t->set_var('phone', $phone);
1788 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1789 $this->t->set_var('tr_color',$tr_color);
1790 $this->t->fp('list','dir_list',True);
1791 //print "$phone $name $address<br>";
1793 $this->t->pfp('out','dir_view_t');
1794 $this->save_sessiondata();
1799 $this->t->set_file(array('org_view_t' => 'org_view.tpl'));
1800 $this->t->set_block('org_view_t','calling_list','list1');
1801 $this->t->set_block('org_view_t','org_list','list2');
1803 # Display a list ordered alphabetically
1804 $sql = "SELECT * FROM eq_calling ORDER BY name ASC";
1805 $this->db->query($sql,__LINE__,__FILE__);
1807 while ($this->db->next_record())
1809 $calling[$i]['id'] = $this->db->f('indiv_id');
1810 $calling[$i]['name'] = $this->db->f('name');
1811 $calling[$i]['position'] = $this->db->f('position');
1812 $calling[$i]['sustained'] = $this->db->f('sustained');
1813 $calling[$i]['organization'] = $this->db->f('organization');
1816 for ($i=0; $i < count($calling); $i++)
1818 $name = $calling[$i]['name'];
1819 $position = $calling[$i]['position'];
1820 $sustained = $calling[$i]['sustained'];
1821 $organization = $calling[$i]['organization'];
1822 $this->t->set_var('name', $name);
1823 $this->t->set_var('position', $position);
1824 $this->t->set_var('sustained', $sustained);
1825 $this->t->set_var('organization', $organization);
1826 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1827 $this->t->set_var('tr_color',$tr_color);
1828 $this->t->fp('list1','calling_list',True);
1831 # Display a list ordered by organization
1832 $sql = "SELECT * FROM eq_calling ORDER BY sequence ASC";
1833 $this->db->query($sql,__LINE__,__FILE__);
1835 while ($this->db->next_record())
1837 $calling[$i]['id'] = $this->db->f('indiv_id');
1838 $calling[$i]['name'] = $this->db->f('name');
1839 $calling[$i]['position'] = $this->db->f('position');
1840 $calling[$i]['sustained'] = $this->db->f('sustained');
1841 $calling[$i]['organization'] = $this->db->f('organization');
1844 for ($i=0; $i < count($calling); $i++)
1846 $name = $calling[$i]['name'];
1847 $position = $calling[$i]['position'];
1848 $sustained = $calling[$i]['sustained'];
1849 $organization = $calling[$i]['organization'];
1850 $this->t->set_var('name', $name);
1851 $this->t->set_var('position', $position);
1852 $this->t->set_var('sustained', $sustained);
1853 $this->t->set_var('organization', $organization);
1854 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1855 $this->t->set_var('tr_color',$tr_color);
1856 $this->t->fp('list2','org_list',True);
1859 $this->t->pfp('out','org_view_t');
1860 $this->save_sessiondata();
1865 $this->t->set_file(array('admin_t' => 'admin.tpl'));
1866 $this->t->set_block('admin_t','upload','uploadhandle');
1867 $this->t->set_block('admin_t','admin','adminhandle');
1868 $this->t->set_block('admin_t','cmd','cmdhandle');
1870 $this->t->set_var('upload_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.admin&action=upload'));
1872 $action = get_var('action',array('GET','POST'));
1874 $this->t->pfp('out','admin_t');
1876 if($action == 'upload')
1878 $target_path = $this->upload_target_path . basename( $_FILES['uploadedfile']['name']);
1880 if(($_FILES['uploadedfile']['type'] == "application/zip") &&
1881 (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))) {
1882 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
1883 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
1884 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
1885 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
1886 $this->t->set_var('uploadstatus',$uploadstatus);
1887 $this->t->pfp('uploadhandle','upload');
1888 $this->t->set_var('uploadhandle','');
1889 print "<table border=1 width=80%><tr><td>\n<pre>";
1891 # make a directory for this data to be stored in
1892 $date="data_" . date("Y_m_d");
1893 $data_dir = $this->upload_target_path . $date;
1894 print "-> Making the data directory: $date<br>\n";
1895 exec('mkdir ' . $data_dir . ' 2>&1', $result, $return_code);
1896 if($return_code != 0) {
1897 print implode('\n',$result) . "<br>";
1898 print "<b><font color=red>";
1899 print "-E- Unable to create the data directory. Aborting import.";
1900 print "</font></b>";
1904 # move the file uploaded into this directory
1905 print "-> Moving the uploaded file into the data dir<br>\n";
1906 exec('mv ' . $target_path . ' ' . $data_dir . '/' . ' 2>&1', $result, $return_code);
1907 if($return_code != 0) {
1908 print implode('\n',$result) . "<br>";
1909 print "<b><font color=red>";
1910 print "-E- Unable to move the uploaded file into the data dir. Aborting import.";
1911 print "</font></b>";
1915 # unzip the data into this directory
1916 print "-> Unzipping the data<br>\n";
1917 $data_file = $data_dir . '';
1918 exec('unzip ' . $data_dir . '/*.zip -d ' . $data_dir . ' 2>&1', $result, $return_code);
1919 if($return_code != 0) {
1920 print implode('\n',$result) . "<br>";
1921 print "<b><font color=red>";
1922 print "-E- Unable to unzip the uploaded file into the data dir. Aborting import.";
1923 print "</font></b>";
1926 exec('mv ' . $data_dir . '/*/* '. $data_dir . ' 2>&1', $result, $return_code);
1928 # update the data_latest link to point to this new directory
1929 print "-> Updating the latest data dir link<br>\n";
1930 $data_latest = $this->upload_target_path . 'data_latest';
1931 exec('rm ' . $data_latest. '; ln -s ' . $data_dir .' '. $data_latest .' 2>&1', $result, $return_code);
1932 if($return_code != 0) {
1933 print implode('\n',$result) . "<br>";
1934 print "<b><font color=red>";
1935 print "-E- Unable to update the data latest link. Aborting import.";
1936 print "</font></b>";
1940 # run the import perl script to encorporate it into the DB
1941 ob_start('ob_logstdout', 2);
1942 print "-> Importing the data into the EQ database<br>\n";
1943 ob_flush(); flush(); sleep(1);
1944 $import_log = $this->upload_target_path . '/import.log';
1945 $data_log = $this->upload_target_path . '/data.log';
1946 $import_cmd = $this->script_path . 'import_ward_data ' . $data_latest . ' | tee ' . $import_log;
1947 $parse_cmd = $this->script_path . 'parse_ward_data -v ' . $data_latest . ' > ' . $data_log;
1948 #print "import_cmd: $import_cmd<br>";
1949 #print "parse_cmd: $parse_cmd<br>";
1950 ob_start('ob_logstdout', 2);
1951 passthru($import_cmd);
1952 passthru($parse_cmd);
1953 ob_flush(); flush(); sleep(1);
1955 # fix the permissions of the data dir
1956 exec('chmod -R o-rwx ' . $data_dir, $result, $return_code);
1958 $this->t->pfp('cmdhandle','cmd');
1959 print "</pre></td></tr></table>";
1961 } else if($_FILES['uploadedfile']['type'] != "application/zip") {
1962 $uploadstatus = "<b><font color=red>The file format must be a .zip file, please try again! </font></b>";
1963 $this->t->set_var('uploadstatus',$uploadstatus);
1966 $uploadstatus = "<b><font color=red> There was an error (" . $_FILES['uploadedfile']['error'];
1967 $uploadstatus.= ") uploading the file, please try again! </font></b>";
1968 $this->t->set_var('uploadstatus',$uploadstatus);
1973 $this->t->set_var('adminhandle','');
1974 $this->t->pfp('adminhandle','admin');
1977 $this->save_sessiondata();