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
60 $this->default_ht_num_months = 3;
61 $this->default_ppi_num_months = 3;
62 $this->default_ppi_num_years = 0;
63 $this->default_int_num_quarters = 1;
64 $this->default_int_num_months = 3;
65 $this->default_int_num_years = 0;
66 $this->default_att_num_quarters = 3;
67 $this->default_att_num_months = 3;
68 $this->upload_target_path = "/home/users/eqpres/eq_data/";
69 $this->script_path = "/usr/share/phpgroupware/eq/";
71 $this->db = $GLOBALS['phpgw']->db;
72 $this->db2 = $this->db;
73 $this->db3 = $this->db;
74 $this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
75 $this->t = $GLOBALS['phpgw']->template;
76 $this->account = $GLOBALS['phpgw_info']['user']['account_id'];
77 $this->grants = $GLOBALS['phpgw']->acl->get_grants('eq');
78 $this->grants[$this->account] = PHPGW_ACL_READ + PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE;
80 $this->jscal = CreateObject('phpgwapi.jscalendar'); // before phpgw_header() !!!
81 $this->cal_options = 'daFormat : "%Y-%m-%d",
82 ifFormat : "%Y-%m-%d",
86 $GLOBALS['phpgw_info']['flags']['app_header'] = 'Elders Quorum Tools';
87 $GLOBALS['phpgw']->common->phpgw_header();
89 $this->current_day = `date '+%d'`;
90 $this->current_day = $this->current_day-0; // Make it numeric
91 $this->current_month = `date '+%m'`;
92 $this->current_month = $this->current_month-0; // Make it numeric
93 $this->current_year = `date '+%Y'`;
94 $this->current_year = $this->current_year-0; // Make it numeric
97 $this->display_app_header();
100 function save_sessiondata()
105 function display_app_header()
107 $this->t->set_file(array('eq_header' => 'header.tpl'));
109 if (isset($phpgw_info['user']['preferences']['eq']['eq_font']))
111 $font = $phpgw_info['user']['preferences']['eq']['eq_font'];
118 $this->t->set_var('bg_color',$phpgw_info['theme']['th_bg']);
119 $this->t->set_var('font',$font);
120 $link_data['menuaction'] = 'eq.eq.ht_view';
121 $this->t->set_var('link_hometeaching',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
122 $this->t->set_var('lang_hometeaching','HomeTeaching');
123 $link_data['menuaction'] = 'eq.eq.act_list';
124 $this->t->set_var('link_activity',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
125 $this->t->set_var('lang_activity','Activities');
126 $link_data['menuaction'] = 'eq.eq.par_view';
127 $this->t->set_var('link_participation',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
128 $this->t->set_var('lang_participation','Participation');
129 $link_data['menuaction'] = 'eq.eq.ppi_view';
130 $this->t->set_var('link_ppi',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
131 $this->t->set_var('lang_ppi','PPIs');
132 $link_data['menuaction'] = 'eq.eq.int_view';
133 $this->t->set_var('link_int',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
134 $this->t->set_var('lang_int','Interviews');
135 $link_data['menuaction'] = 'eq.eq.vis_view';
136 $this->t->set_var('link_visit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
137 $this->t->set_var('lang_visit','Visits');
138 $link_data['menuaction'] = 'eq.eq.att_view';
139 $this->t->set_var('link_attendance',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
140 $this->t->set_var('lang_attendance','Attendance');
141 $link_data['menuaction'] = 'eq.eq.dir_view';
142 $this->t->set_var('link_dir',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
143 $this->t->set_var('lang_dir','Directory');
144 $link_data['menuaction'] = 'eq.eq.org_view';
145 $this->t->set_var('link_org',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
146 $this->t->set_var('lang_org','Callings');
147 $link_data['menuaction'] = 'eq.eq.admin';
148 $this->t->set_var('link_admin',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
149 $this->t->set_var('lang_admin','Admin');
150 $link_data['menuaction'] = 'eq.eq.schedule';
151 $this->t->set_var('link_schedule',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
152 $this->t->set_var('lang_schedule','Scheduling');
154 $this->t->pparse('out','eq_header');
159 $this->t->set_file(array('ht_view_t' => 'ht_view.tpl'));
160 $this->t->set_block('ht_view_t','district_list','list');
162 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
163 $num_months = get_var('num_months',array('GET','POST'));
164 if($num_months == '') { $num_months = $this->default_ht_num_months; }
165 $this->t->set_var('num_months',$num_months);
166 $this->t->set_var('lang_filter','Filter');
167 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
168 else { $this->t->set_var('lang_num_months','Months of History'); }
170 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
171 $this->t->set_var('title','Hometeaching');
173 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
174 $this->db->query($sql,__LINE__,__FILE__);
176 while ($this->db->next_record())
178 $districts[$i]['district'] = $this->db->f('district');
179 $districts[$i]['name'] = $this->db->f('name');
180 $districts[$i]['supervisor'] = $this->db->f('supervisor');
184 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
185 $this->db->query($sql,__LINE__,__FILE__);
187 while ($this->db->next_record())
189 $elder_id[$i] = $this->db->f('elder');
190 $elder_name[$i] = $this->db->f('name');
191 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
194 array_multisort($elder_name, $elder_id);
196 // Make an array mapping elder_ids to elder_names
197 for($i=0; $i < count($elder_id); $i++) {
199 $elders[$id] = $elder_name[$i];
202 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
203 $this->db->query($sql,__LINE__,__FILE__);
204 while ($this->db->next_record())
206 $aaronic_id = $this->db->f('aaronic');
207 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
208 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
212 $this->nextmatchs->template_alternate_row_color(&$this->t);
213 for ($i=0; $i < count($districts); $i++) {
214 $this->t->set_var('district_number',$districts[$i]['district']);
215 $this->t->set_var('district_name',$districts[$i]['name']);
216 $supervisor = $districts[$i]['supervisor'];
217 $unique_companionships='';
219 // Select all the unique companionship numbers for this district
220 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $districts[$i]['district'];
221 $this->db->query($sql,__LINE__,__FILE__);
223 while ($this->db->next_record())
225 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
229 $comp_width=450; $visit_width=25; $table_width=$comp_width + $num_months*$visit_width;
230 $table_data=""; $num_companionships = 0; $num_families = 0;
231 for($m=$num_months; $m >= 0; $m--) { $visits[$m] = 0; }
232 for ($j=0; $j < count($unique_companionships); $j++) {
233 $companion_table_entry = "";
234 // Select all the companions in each companionship
235 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
236 "companionship=". $unique_companionships[$j]['companionship'];
237 $this->db->query($sql,__LINE__,__FILE__);
239 while ($this->db->next_record())
241 // Get this companions information
242 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
243 $companionship = $this->db->f('companionship');
244 $elder_id = $this->db->f('elder');
245 $aaronic_id = $this->db->f('aaronic');
247 $name = $elders[$elder_id];
248 $phone = $elder_phone[$elder_id];
250 else if($aaronic_id) {
251 $name = $aaronic[$aaronic_id]['name'];
252 $phone = $aaronic[$aaronic_id]['phone'];
254 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
256 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
258 // Get the names of the families assigned this home teaching companionship
259 $sql = "SELECT * from eq_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
260 $sql = $sql . " ORDER BY name ASC";
261 $this->db->query($sql,__LINE__,__FILE__);
263 while ($this->db->next_record())
265 $num_families++; $total_families++;
266 $family_name = $this->db->f('name');
267 $family_id = $this->db->f('family');
268 $this->nextmatchs->template_alternate_row_color(&$this->t);
269 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
270 // Find out how many times Visits were performed by this companionship
271 // in the past $num_months for this Family
272 $header_row="<th width=$comp_width><font size=-2>Families</th>";
273 for($m=$num_months; $m >= 0; $m--) {
274 $month = $this->current_month - $m;
275 $year = $this->current_year;
276 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
277 if($month < 10) { $month = "0"."$month"; }
278 $month_start = "$year"."-"."$month"."-"."01";
279 $month_end = "$year"."-"."$month"."-"."31";
280 $month = "$month"."/"."$year";
281 //print "m: $m month: $month year: $year month_start: $month_start month_end: $month_end<br>";
282 // Add this to the query to filter on only visits made by this companionship:
283 // " AND companionship=" . $unique_companionships[$j]['companionship'].
284 $sql = "SELECT * FROM eq_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
285 " AND companionship!=0".
286 " AND family=". $family_id;
287 $this->db2->query($sql,__LINE__,__FILE__);
288 $link_data['menuaction'] = 'eq.eq.ht_update';
289 $link_data['date'] = $month_start;
290 $link_data['month_start'] = $month_start;
291 $link_data['month_end'] = $month_end;
292 $link_data['month'] = $month;
293 $link_data['district'] = $districts[$i]['district'];
294 $link_data['district_name'] = $districts[$i]['name'];
295 $link_data['action'] = 'view';
296 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
297 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
298 if(!$total_visits[$m]) { $total_visits[$m] = 0; }
299 if($this->db2->next_record()) {
300 if($this->db2->f('visited') == 'y') {
301 $visits[$m]++; $total_visits[$m]++;
302 $table_data .= '<td align=center><a href="'.$link.'"><img src="checkmark.gif"></a></td>';
304 else if($this->db2->f('visited') == 'n') {
305 $table_data .= '<td align=center><a href="'.$link.'"><img src="x.gif"></a></td>';
308 $visits[$m]++; $total_visits[$m]++;
309 $table_data .= "<td> </td>";
313 $visits[$m]++; $total_visits[$m]++;
314 $table_data .= "<td> </td>";
317 $table_data .= "</tr>";
320 $table_data .= "<tr><td colspan=20></td></tr>";
322 $table_data .= "<tr><td colspan=20><hr></td></tr>";
323 $stat_data = "<tr><td><b><font size=-2>$num_families Families<br>Visit Totals:</font></b></td>";
325 for($m=$num_months; $m >=0; $m--) {
326 $percent = ceil(($visits[$m] / $num_families)*100);
327 $stat_data .= "<td align=center><font size=-2><b>$visits[$m]<br>$percent%</font></b></td>";
329 $stat_data .= "</tr>";
331 $this->t->set_var('table_width',$table_width);
332 $this->t->set_var('header_row',$header_row);
333 $this->t->set_var('table_data',$table_data);
334 $this->t->set_var('stat_data',$stat_data);
335 $this->t->fp('list','district_list',True);
338 $totals = "<tr><td><b><font size=-2>$total_families Total Families<br>Visit Totals:</font></b></td>";
339 for($m=$num_months; $m >=0; $m--) {
340 $percent = ceil(($total_visits[$m] / $total_families)*100);
341 $totals .= "<td align=center><font size=-2><b>$total_visits[$m]<br>$percent%</font></b></td>";
345 $this->t->set_var('totals',$totals);
347 $this->t->pfp('out','ht_view_t');
348 $this->save_sessiondata();
354 $this->t->set_file(array('ht_update_t' => 'ht_update.tpl'));
355 $this->t->set_block('ht_update_t','district_list','list');
356 $this->t->set_block('ht_update_t','save','savehandle');
358 $district = get_var('district',array('GET','POST'));
359 $district_name = get_var('district_name',array('GET','POST'));
360 $date = get_var('date',array('GET','POST'));
361 $month = get_var('month',array('GET','POST'));
362 $month_start = get_var('month_start',array('GET','POST'));
363 $month_end = get_var('month_end',array('GET','POST'));
364 $action = get_var('action',array('GET','POST'));
366 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
367 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_update&action=save'));
368 $this->t->set_var('lang_done','Cancel');
369 $this->t->set_var('district_name',$district_name);
370 $this->t->set_var('district_number',$district);
371 $this->t->set_var('title','Hometeaching Update ' . $month);
372 $this->t->set_var('date',$date);
374 if($action == 'save')
376 // Get a list of all the companionships in this district
377 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $district;
378 $this->db->query($sql,__LINE__,__FILE__);
380 while ($this->db->next_record())
382 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
385 for ($j=0; $j < count($unique_companionships); $j++)
387 // FIXME: We won't be able to go back and edit history on families that have been
388 // reassigned to a different companionship. The following delete command will not delete
389 // the history of visits under an older companionship, only the ones for the existing
390 // companionship. This will lead to duplicate visits being entered for an older
391 // month for the same family, making it impossible to change the past history once
392 // a family is reassigned. However, you will be able to view the history just fine.
394 //$comp=$unique_companionships[$j]['companionship'];
395 //print "deleting from eq_visit where companionship=$comp and date=$date and district=$district<br>";
396 // Delete all the visits that have taken place for all families for this month
397 $this->db->query("DELETE from eq_visit where companionship=" . $unique_companionships[$j]['companionship'] .
398 " AND " . "date='" . $date . "'",__LINE__,__FILE__);
401 // Now, add the visits that are checked for this month
402 $new_data = get_var('family_visited',array('POST'));
403 foreach ($new_data as $family)
405 foreach ($family as $data)
407 //print "family_visited: $data <br>";
408 $data_array = explode("/",$data);
409 $family_id = $data_array[0];
410 $companionship = $data_array[1];
411 $date = $data_array[2];
412 $visited = $data_array[3];
413 if($visited == "") { $visited = $data_array[4]; }
414 //print "family_id: $family_id companionship: $companionship date: $date visited: $visited<br>";
415 $this->db->query("INSERT INTO eq_visit (family,companionship,date,notes,visited) "
416 . "VALUES (" . $family_id .",". $companionship .",'". $date ."','','". $visited ."')",__LINE__,__FILE__);
423 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
424 $this->db->query($sql,__LINE__,__FILE__);
426 while ($this->db->next_record())
428 $elder_id[$i] = $this->db->f('elder');
429 $elder_name[$i] = $this->db->f('name');
430 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
433 array_multisort($elder_name, $elder_id);
435 // Make an array mapping elder_ids to elder_names
436 for($i=0; $i < count($elder_id); $i++) {
438 $elders[$id] = $elder_name[$i];
441 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
442 $this->db->query($sql,__LINE__,__FILE__);
443 while ($this->db->next_record())
445 $aaronic_id = $this->db->f('aaronic');
446 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
447 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
450 // Select all the unique companionship numbers for this district
451 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $district;
452 $this->db->query($sql,__LINE__,__FILE__);
453 $j=0; $unique_companionships='';
454 while ($this->db->next_record())
456 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
460 $comp_width=300; $visit_width=25; $table_width=$comp_width + $visit_width;
461 $table_data=""; $num_companionships = 0; $num_families = 0; $visits=0;
462 for ($j=0; $j < count($unique_companionships); $j++) {
463 $companion_table_entry = "";
464 // Select all the companions in each companionship
465 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
466 "companionship=". $unique_companionships[$j]['companionship'];
467 $this->db->query($sql,__LINE__,__FILE__);
469 while ($this->db->next_record())
471 // Get this companions information
472 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
473 $companionship = $this->db->f('companionship');
474 $elder_id = $this->db->f('elder');
475 $aaronic_id = $this->db->f('aaronic');
477 $name = $elders[$elder_id];
478 $phone = $elder_phone[$elder_id];
480 else if($aaronic_id) {
481 $name = $aaronic[$aaronic_id]['name'];
482 $phone = $aaronic[$aaronic_id]['phone'];
484 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
486 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
488 // Get the names of the families assigned this home teaching companionship
489 $sql = "SELECT * from eq_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
490 $sql = $sql . " ORDER BY name ASC";
491 $this->db->query($sql,__LINE__,__FILE__);
492 while ($this->db->next_record())
494 $num_families++; $total_families++;
495 $family_name = $this->db->f('name');
496 $family_id = $this->db->f('family');
497 $this->nextmatchs->template_alternate_row_color(&$this->t);
498 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
500 $header_row="<th width=$comp_width><font size=-2>Families</th>";
501 $sql = "SELECT * FROM eq_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
502 " AND companionship!=0".
503 " AND family=". $family_id;
504 $this->db2->query($sql,__LINE__,__FILE__);
505 $value = $family_id . "/" . $unique_companionships[$j]['companionship'] . "/" . $date;
506 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
507 if(!$total_visits) { $total_visits = 0; }
508 if($this->db2->next_record()) {
509 if($this->db2->f('visited') == 'y') {
510 $visits++; $total_visits++;
511 $table_data .= '<td width=100 align=center>';
512 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y" checked>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.'/"> ';
515 $table_data .= '</td>';
516 } else if($this->db2->f('visited') == 'n') {
517 $table_data .= '<td width=100 align=center>';
518 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
519 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n" checked>N';
520 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/">';
521 $table_data .= '</td>';
523 $table_data .= '<td width=100 align=center>';
524 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
525 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
526 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
527 $table_data .= '</td>';
532 $table_data .= '<td width=100 align=center>';
533 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
534 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
535 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
536 $table_data .= '</td>';
539 $table_data .= "</tr>";
540 $table_data .= "<tr><td colspan=20></td></tr>";
542 $table_data .= "<tr><td colspan=20><hr></td></tr>";
543 $stat_data = "<tr><td><b><font size=-2>$num_families Families<br>Visit Totals:</font></b></td>";
545 $percent = ceil(($visits / $num_families)*100);
546 $stat_data .= "<td align=center><font size=-2><b>$visits<br>$percent%</font></b></td>";
547 $stat_data .= "</tr>";
549 $this->t->set_var('table_width',$table_width);
550 $this->t->set_var('header_row',$header_row);
551 $this->t->set_var('table_data',$table_data);
552 $this->t->set_var('stat_data',$stat_data);
553 $this->t->fp('list','district_list',True);
555 $this->t->set_var('lang_reset','Clear Form');
556 $this->t->set_var('lang_save','Save Changes');
557 $this->t->set_var('savehandle','');
559 $this->t->pfp('out','ht_update_t');
560 $this->t->pfp('addhandle','save');
562 $this->save_sessiondata();
567 $this->t->set_file(array('act_list_t' => 'act_list.tpl'));
568 $this->t->set_block('act_list_t','act_list','list');
570 $this->t->set_var('lang_name','Activity Name');
571 $this->t->set_var('lang_date','Date');
573 $sql = "SELECT * FROM eq_activity ORDER BY date DESC";
574 $this->db->query($sql,__LINE__,__FILE__);
575 $total_records = $this->db->num_rows();
578 while ($this->db->next_record())
580 $activity_list[$i]['name'] = $this->db->f('name');
581 $activity_list[$i]['date'] = $this->db->f('date');
582 $activity_list[$i]['activity'] = $this->db->f('activity');
586 for ($i=0; $i < count($activity_list); $i++)
588 $this->nextmatchs->template_alternate_row_color(&$this->t);
589 $this->t->set_var('name',$activity_list[$i]['name']);
590 $this->t->set_var('date',$activity_list[$i]['date']);
592 $link_data['menuaction'] = 'eq.eq.act_view';
593 $link_data['activity'] = $activity_list[$i]['activity'];
594 $link_data['action'] = 'view';
595 $this->t->set_var('view',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
596 $this->t->set_var('lang_view','View');
598 $link_data['menuaction'] = 'eq.eq.act_update';
599 $link_data['activity'] = $activity_list[$i]['activity'];
600 $link_data['action'] = 'edit';
601 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
602 $this->t->set_var('lang_edit','Edit');
604 $link_data['menuaction'] = 'eq.eq.act_update';
605 $link_data['activity'] = '0';
606 $link_data['action'] = 'add';
607 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/eq/index.php',$link_data)
608 . '"><input type="submit" name="Add" value="' . 'Add Activity' .'"></font></form>');
610 $this->t->fp('list','act_list',True);
613 $this->t->pfp('out','act_list_t');
614 $this->save_sessiondata();
619 $this->t->set_file(array('act_view_t' => 'act_view.tpl'));
620 $this->t->set_block('act_view_t','part_list','list');
622 $sql = "SELECT * FROM eq_activity WHERE activity=" . intval(get_var('activity',array('GET','POST')));
623 $this->db->query($sql,__LINE__,__FILE__);
624 $this->db->next_record();
625 $this->t->set_var('name', $this->db->f('name'));
626 $this->t->set_var('date', $this->db->f('date'));
627 $this->t->set_var('notes', $this->db->f('notes'));
629 $this->t->set_var('lang_name','Activity Name');
630 $this->t->set_var('lang_date','Date');
631 $this->t->set_var('lang_notes','Notes');
632 $this->t->set_var('lang_done','Done');
633 $this->t->set_var('lang_action','View');
635 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
636 $this->t->set_var('tr_color',$tr_color);
638 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_list'));
640 $link_data['menuaction'] = 'eq.eq.act_update';
641 $link_data['activity'] = get_var('activity',array('GET','POST'));
642 $link_data['action'] = 'edit';
643 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
644 $this->t->set_var('lang_edit','Edit');
645 $this->t->set_var('cal_date',$this->db->f('date'));
647 // Now find out which elders participated in this activity
648 $sql = "SELECT * FROM eq_participation WHERE activity=" . intval(get_var('activity',array('GET','POST')));
649 $this->db->query($sql,__LINE__,__FILE__);
650 $total_records = $this->db->num_rows();
653 while ($this->db->next_record())
655 $part_list[$i]['elder'] = $this->db->f('elder');
659 for ($i=0; $i < count($part_list); $i++)
661 $sql = "SELECT * FROM eq_elder WHERE elder=" . $part_list[$i]['elder'];
662 $this->db->query($sql,__LINE__,__FILE__);
663 $this->db->next_record();
664 $names[$i] = $this->db->f('name');
667 for ($i=0; $i < count($names); $i++)
669 //$this->nextmatchs->template_alternate_row_color(&$this->t);
670 $this->t->set_var('elder_name',$names[$i]);
671 if(($i+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
672 else { $this->t->set_var('table_sep',"</td>"); }
673 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
674 $this->t->fp('list','part_list',True);
677 $this->t->pfp('out','act_view_t');
678 $this->save_sessiondata();
681 function act_update()
683 $this->t->set_file(array('form' => 'act_update.tpl'));
684 $this->t->set_block('form','elder_list','list');
685 $this->t->set_block('form','add','addhandle');
686 $this->t->set_block('form','edit','edithandle');
687 $this->t->set_var('lang_done','Done');
689 $action = get_var('action',array('GET','POST'));
690 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_list'));
691 $activity['activity'] = intval(get_var('activity',array('GET','POST')));
693 if($action == 'save')
695 $activity['name'] = $this->db->db_addslashes(get_var('name',array('POST')));
696 $activity['date'] = $this->db->db_addslashes(get_var('date',array('POST')));
697 $activity['notes']= $this->db->db_addslashes(get_var('notes',array('POST')));
698 $this->db->query("UPDATE eq_activity set " .
699 " name='" . $activity['name'] .
700 "', date='" . $activity['date'] . "'" .
701 ", notes='" . $activity['notes'] . "'" .
702 " WHERE activity=" . $activity['activity'],__LINE__,__FILE__);
704 // Delete all the elders who have particiapted in this activity
705 $this->db->query("DELETE from eq_participation where activity=".$activity['activity'],__LINE__,__FILE__);
707 // Re-add the elders who are checked as having participated in this activity
708 $elders = get_var('elder_name',array('POST'));
709 foreach ($elders as $elder)
711 $this->db->query("INSERT INTO eq_participation (elder,activity) "
712 . "VALUES (" . $elder . ",". $activity['activity'] . ")",__LINE__,__FILE__);
719 if($action == 'insert')
721 $activity['name'] = $this->db->db_addslashes(get_var('name',array('POST')));
722 $activity['date'] = $this->db->db_addslashes(get_var('date',array('POST')));
723 $activity['notes']= $this->db->db_addslashes(get_var('notes',array('POST')));
724 $this->db->query("INSERT INTO eq_activity (name,date,notes) "
725 . "VALUES ('" . $activity['name'] . "','"
726 . $activity['date'] . "','" . $activity['notes'] . "')",__LINE__,__FILE__);
733 $activity['activity'] = 0;
734 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
735 $this->t->set_var('name','');
736 $this->t->set_var('date','');
737 $this->t->set_var('notes','');
738 $this->t->set_var('lang_done','Cancel');
739 $this->t->set_var('lang_action','Adding New Activity');
740 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_update&activity='
741 . $activity['activity'] . '&action=' . 'insert'));
744 if($action == 'edit')
746 $sql = "SELECT * FROM eq_activity WHERE activity=" . $activity['activity'];
747 $this->db->query($sql,__LINE__,__FILE__);
748 $this->db->next_record();
749 $this->t->set_var('cal_date',$this->jscal->input('date',$this->db->f('date'),'','','','','',$this->cal_options));
750 $this->t->set_var('name', $this->db->f('name'));
751 $this->t->set_var('date', $this->db->f('date'));
752 $this->t->set_var('notes', $this->db->f('notes'));
753 $this->t->set_var('lang_done','Cancel');
754 $this->t->set_var('lang_action','Editing Activity');
755 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_update&activity='
756 . $activity['activity'] . '&action=' . 'save'));
760 $sql = "SELECT * FROM eq_elder";
761 $this->db->query($sql,__LINE__,__FILE__);
763 while ($this->db->next_record())
765 if($this->db->f('valid') == 1 || $action != 'add') {
766 $elder_name[$i] = $this->db->f('name');
767 $elder_id[$i] = $this->db->f('elder');
768 $elder_valid[$i] = $this->db->f('valid');
772 array_multisort($elder_name, $elder_id, $elder_valid);
775 for ($i=0; $i < count($elder_id); $i++)
777 //$this->nextmatchs->template_alternate_row_color(&$this->t);
778 $sql = "SELECT * FROM eq_participation where activity=". $activity['activity'] . " AND elder=" . $elder_id[$i];
779 $this->db->query($sql,__LINE__,__FILE__);
780 if($this->db->next_record()) { $this->t->set_var('checked','checked'); $checked=1; }
781 else { $this->t->set_var('checked',''); $checked=0; }
782 if($checked || $elder_valid[$i] == 1) {
783 $this->t->set_var('elder_name',$elder_name[$i]);
784 $this->t->set_var('elder',$elder_id[$i]);
785 if(($j+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
786 else { $this->t->set_var('table_sep',"</td>"); }
787 if(($j) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
788 $this->t->fp('list','elder_list',True);
793 $this->t->set_var('lang_reset','Clear Form');
794 $this->t->set_var('lang_add','Add Activity');
795 $this->t->set_var('lang_save','Save Changes');
796 $this->t->set_var('edithandle','');
797 $this->t->set_var('addhandle','');
799 $this->t->pfp('out','form');
800 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
801 if($action == 'add') { $this->t->pfp('addhandle','add'); }
803 $this->save_sessiondata();
808 $this->t->set_file(array('par_view_t' => 'par_view.tpl'));
809 $this->t->set_block('par_view_t','header_list','list1');
810 $this->t->set_block('par_view_t','elder_list','list2');
812 $sql = "SELECT * FROM eq_elder where valid=1";
813 $this->db->query($sql,__LINE__,__FILE__);
815 while ($this->db->next_record())
817 $elder_name[$i] = $this->db->f('name');
818 $elder_id[$i] = $this->db->f('elder');
821 array_multisort($elder_name, $elder_id);
823 $sql = "SELECT * FROM eq_activity ORDER BY date DESC";
824 $this->db->query($sql,__LINE__,__FILE__);
825 $total_records = $this->db->num_rows();
828 while ($this->db->next_record())
830 $activity_list[$i]['name'] = $this->db->f('name');
831 $activity_list[$i]['date'] = $this->db->f('date');
832 $activity_list[$i]['activity'] = $this->db->f('activity');
833 if($activity_list[$i]['date'] == '0000-00-00') { $activity_list[$i]['date']=""; }
837 $elder_width=250; $part_width=25; $act_width=50;
838 $total_width=$elder_width+$part_width;
839 for ($i=0; $i < count($activity_list); $i++) {
840 $this->t->set_var('activity_name',$activity_list[$i]['name']);
841 $this->t->set_var('activity_date',$activity_list[$i]['date']);
842 $this->t->fp('list1','header_list',True);
843 $total_width += $act_width;
846 for ($i=0; $i < count($elder_id); $i++) {
847 $participated=0; $part_table = '';
848 $this->nextmatchs->template_alternate_row_color(&$this->t);
849 $this->t->set_var('elder_name',$elder_name[$i]);
850 for ($j=0; $j < count($activity_list); $j++) {
851 $sql = "SELECT * FROM eq_participation where activity="
852 . $activity_list[$j]['activity'] . " AND elder=" . $elder_id[$i];
853 $this->db->query($sql,__LINE__,__FILE__);
854 if($this->db->next_record()) {
855 $part_table .= '<td align=center><img src="checkmark.gif"></td>';
858 $part_table .= '<td> </td>';
861 if($participated) { $part_table .= '<td align=center><img src="checkmark.gif">'.$participated.'</td>'; }
862 else { $part_table .= '<td> </td>'; }
863 $this->t->set_var('part_table',$part_table);
864 $this->t->fp('list2','elder_list',True);
866 $this->t->set_var('total_width',$total_width);
867 $this->t->set_var('elder_width',$elder_width);
868 $this->t->set_var('part_width',$part_width);
869 $this->t->set_var('act_width',$act_width);
870 $this->t->pfp('out','par_view_t');
871 $this->save_sessiondata();
876 $this->t->set_file(array('ppi_sched_t' => 'ppi_sched.tpl'));
877 $this->t->set_block('ppi_sched_t','elder_list','elderlist');
878 $this->t->set_block('ppi_sched_t','appt_list','apptlist');
879 $action = get_var('action',array('GET','POST'));
881 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
882 $this->t->set_var('lang_reset','Clear Changes');
884 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
885 $this->t->set_var('ppi_link_title','Yearly PPIs');
887 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched'));
888 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
890 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched&action=save'));
891 $this->t->set_var('title','Yearly PPI Scheduler');
893 $elder_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $ppi_date_width=20;
894 $table_width=$elder_width + $phone_width + $pri_width + $notes_width + $ppi_date_width;
895 $header_row = "<th width=$elder_width><font size=-2>Elder Name</th>";
896 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
897 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
898 $header_row.= "<th width=$ppi_date_width><font size=-2>Last PPI</th>";
899 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
900 $table_data=""; $completed_data=""; $totals_data="";
904 if($action == 'save')
906 // Save any changes made to the appointment table
907 $new_data = get_var('appt_notes',array('POST'));
908 foreach ($new_data as $entry)
910 $elder = $entry['elder'];
911 $appointment = $entry['appointment'];
913 //print "elder: $elder appointment: $appointment <br>";
915 // Perform database save actions here
916 $this->db->query("UPDATE eq_appointment set " .
917 " elder='" . $elder . "'" .
918 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
922 // Save any changes made to the ppi notes table
923 $new_data = get_var('ppi_notes',array('POST'));
924 foreach ($new_data as $entry)
926 $ppi_notes = $entry['notes'];
927 $elder_id = $entry['elder_id'];
928 $ppi_pri = $entry['pri'];
930 // Perform database save actions here
931 $this->db->query("UPDATE eq_elder set " .
932 " ppi_notes='" . $ppi_notes . "'" .
933 ",ppi_pri='" . $ppi_pri . "'" .
934 " WHERE elder=" . $elder_id,__LINE__,__FILE__);
938 $take_me_to_url = $GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched');
939 Header('Location: ' . $take_me_to_url);
942 // Get the EQ President
943 $sql = "SELECT * FROM eq_presidency where president=1 and valid=1";
944 $this->db->query($sql,__LINE__,__FILE__);
945 if($this->db->next_record()) {
946 $president_name = $this->db->f('name');
947 $president_id = $this->db->f('elder');
948 $presidency_id = $this->db->f('presidency');
949 $district_number = '*';
950 $district_name = $president_name;
952 print "<hr><font color=red><h3>-E- Unable to locate EQ President in eq_presidency table</h3></font></hr>";
956 // create the elder id -> elder name mapping
957 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY name ASC";
958 $this->db->query($sql,__LINE__,__FILE__);
962 while ($this->db->next_record())
964 $elder_name[$i] = $this->db->f('name');
965 $elder_id[$i] = $this->db->f('elder');
968 array_multisort($elder_name, $elder_id);
971 $date_width=150; $time_width=100; $elder_width=200;
972 $appt_table_width=$date_width + $time_width + $elder_width;
973 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
974 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
975 $appt_header_row.= "<th width=$elder_width><font size=-2>Elder</th>";
976 $appt_table_data = "";
978 $total_elders=0; $elders_with_yearly_ppi=0;
980 // Display a scheduling table for the EQ President
981 $table_data=""; $appt_table_data="";
982 $table_title = "District ".$district_number.": ".$district_name.": All Elders with Yearly PPI Not Completed";
983 $appt_table_title = "District ".$district_number.": ".$district_name.": Yearly PPI Appointment Slots";
984 $this->t->set_var('table_title',$table_title);
985 $this->t->set_var('appt_table_title',$appt_table_title);
987 // query the database for all the appointments
988 $sql = "SELECT * FROM eq_appointment where presidency=".$presidency_id." and date>=CURDATE() ORDER BY date ASC, time ASC";
989 $this->db->query($sql,__LINE__,__FILE__);
991 while ($this->db->next_record())
993 $appointment = $this->db->f('appointment');
994 $elder = $this->db->f('elder');
996 $date = $this->db->f('date');
997 $date_array = explode("-",$date);
998 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
999 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1001 $time = $this->db->f('time');
1002 $time_array = explode(":",$time);
1003 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1005 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1006 $appt_table_data.= "<td align=center>$day_string</td>";
1007 $appt_table_data.= "<td align=center>$time_string</td>";
1009 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][elder]>';
1010 $appt_table_data.= '<option value=0></option>';
1011 for ($i=0; $i < count($elder_id); $i++) {
1012 $id = $elder_id[$i];
1013 $name = $elder_name[$i];
1014 if($elder_id[$i] == $elder) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
1015 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1017 $appt_table_data.='</select></td>';
1019 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1021 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1022 $this->t->set_var('tr_color',$tr_color);
1025 $this->t->set_var('appt_table_data',$appt_table_data);
1026 $this->t->set_var('appt_header_row',$appt_header_row);
1027 $this->t->set_var('appt_table_width',$appt_table_width);
1029 // PPI SCHEDULING TABLE
1030 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY ppi_pri ASC";
1031 $this->db->query($sql,__LINE__,__FILE__);
1035 while ($this->db->next_record())
1037 $elder_id[$i] = $this->db->f('elder');
1038 $elder_name[$i] = $this->db->f('name');
1039 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
1040 $elder_ppi_pri[$elder_id[$i]] = $this->db->f('ppi_pri');
1041 $elder_ppi_notes[$elder_id[$i]] = $this->db->f('ppi_notes');
1046 $max = count($elder_id);
1048 for($i=0; $i < $max; $i++) {
1049 $id = $elder_id[$i];
1050 $name = $elder_name[$i];
1051 $phone = $elder_phone[$id];
1052 $ppi_pri = $elder_ppi_pri[$id];
1053 $ppi_notes = $elder_ppi_notes[$id];
1055 // If this elder has had a yearly PPI this year, don't show him on the schedule list
1056 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
1057 $sql = "SELECT * FROM eq_ppi WHERE date > '$year_start' AND date < '$year_end' ".
1059 $this->db2->query($sql,__LINE__,__FILE__);
1061 if(!$this->db2->next_record()) {
1062 $sql = "SELECT * FROM eq_ppi WHERE elder=" . $id . " ORDER BY date DESC";
1063 $this->db->query($sql,__LINE__,__FILE__);
1064 if($this->db->next_record()) { $date = $this->db->f('date'); } else { $date = ""; }
1065 $link_data['menuaction'] = 'eq.eq.ppi_update';
1066 $link_data['elder'] = $id;
1067 $link_data['name'] = $name;
1068 $link_data['ppi'] = '';
1069 $link_data['eqpresppi'] = 1;
1070 $link_data['action'] = 'add';
1071 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1072 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1073 $this->t->set_var('tr_color',$tr_color);
1074 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1075 $table_data.= "<td align=center>$phone</td>";
1076 //$table_data.= "<td align=center>$ppi_pri</td>";
1077 $table_data.= "<td align=center>";
1078 $table_data.= '<select name=ppi_notes['.$i.'][pri]>';
1079 foreach(range(0,6) as $num) {
1080 if($num == 0) { $num = 1; } else {$num = $num*5; }
1081 if($ppi_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
1082 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1084 $table_data.= '</select></td>';
1085 $table_data.= "<td align=center>$date</td>";
1086 $table_data.= '<td><input type=text size="50" maxlength="128" name="ppi_notes['.$i.'][notes]" value="'.$ppi_notes.'">';
1087 $table_data.= '<input type=hidden name="ppi_notes['.$i.'][elder_id]" value="'.$id.'">';
1088 $table_data.= '<input type=hidden name="ppi_notes['.$i.'][elder_name]" value="'.$name.'">';
1089 $table_data.= '</td>';
1090 $table_data.= '</tr>';
1092 $link_data['menuaction'] = 'eq.eq.ppi_update';
1093 $link_data['interviewer'] = $this->db2->f('interviewer');
1094 $link_data['elder'] = $this->db2->f('elder');
1095 $link_data['name'] = $name;
1096 $link_data['ppi'] = $this->db2->f('ppi');
1097 $link_data['eqpresppi'] = $this->db2->f('eqpresppi');
1098 $link_data['action'] = 'view';
1099 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1100 $elders_with_yearly_ppi++;
1101 $date = $this->db2->f('date');
1102 $ppi_notes = $this->db2->f('notes');
1103 if(strlen($ppi_notes) > 40) { $ppi_notes = substr($ppi_notes,0,40) . "..."; }
1104 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1105 $this->t->set_var('tr_color2',$tr_color2);
1106 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1107 $completed_data.= "<td align=center>$phone</td>";
1108 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1109 $completed_data.= "<td align=left>$ppi_notes</td>";
1110 $completed_data.= '</tr>';
1112 } // End for Elders Loop
1114 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1115 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1116 $completed_header_row = "<th width=$name_width><font size=-2>Elder Name</th>";
1117 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1118 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1119 $completed_header_row.= "<th width=$notes_width><font size=-2>PPI Notes</th>";
1121 $this->t->set_var('table_width',$table_width);
1122 $this->t->set_var('header_row',$header_row);
1123 $this->t->set_var('table_data',$table_data);
1124 $this->t->set_var('completed_header_row',$completed_header_row);
1125 $this->t->set_var('completed_table_width',$completed_table_width);
1126 $this->t->set_var('completed',$completed_data);
1127 $this->t->fp('elderlist','elder_list',True);
1129 $elders_width=300; $totals_width=100;
1130 $totals_table_width=$elders_width + $totals_width;
1131 $totals_header_row = "<th width=$elders_width><font size=-2>Elders</th>";
1132 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
1133 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1134 $totals_data.= "<td align=left><font size=-2><b>Total Elders with yearly PPIs completed:</b></font></td>";
1135 $totals_data.= "<td align=center><font size=-2><b>$elders_with_yearly_ppi / $total_elders</b></font></td>";
1136 $percent = ceil(($elders_with_yearly_ppi / $total_elders)*100);
1137 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1138 $this->t->set_var('tr_color',$tr_color);
1139 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1140 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
1141 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
1142 $totals_data.= "</tr>";
1144 $this->t->set_var('totals',$totals_data);
1145 $this->t->set_var('totals_header_row',$totals_header_row);
1146 $this->t->set_var('totals_table_width',$totals_table_width);
1148 $this->t->pfp('out','ppi_sched_t');
1149 $this->save_sessiondata();
1153 function int_sched()
1155 $this->t->set_file(array('int_sched_t' => 'int_sched.tpl'));
1156 $this->t->set_block('int_sched_t','elder_list','elderlist');
1157 $this->t->set_block('int_sched_t','appt_list','apptlist');
1158 $action = get_var('action',array('GET','POST'));
1160 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1161 $this->t->set_var('lang_reset','Clear Changes');
1163 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_view'));
1164 $this->t->set_var('int_link_title','Hometeaching Interviews');
1166 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_sched'));
1167 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
1169 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_sched&action=save'));
1170 $this->t->set_var('title','Hometeaching Interviews Scheduler');
1172 $elder_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $int_date_width=20;
1173 $table_width=$elder_width + $phone_width + $pri_width + $notes_width + $int_date_width;
1174 $header_row = "<th width=$elder_width><font size=-2>Elder Name</th>";
1175 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1176 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1177 $header_row.= "<th width=$int_date_width><font size=-2>Last Interview</th>";
1178 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1179 $table_data=""; $completed_data=""; $totals_data="";
1183 $nextyear = $year + 1;
1184 if($month >= 1 && $month <= 3) { $quarter_start=$year."-01-01"; $quarter_end=$year."-04-01"; }
1185 if($month >= 4 && $month <= 6) { $quarter_start=$year."-04-01"; $quarter_end=$year."-07-01"; }
1186 if($month >= 7 && $month <= 9) { $quarter_start=$year."-07-01"; $quarter_end=$year."-10-01"; }
1187 if($month >= 10 && $month <= 12) { $quarter_start=$year."-10-01"; $quarter_end=$nextyear."-01-01"; }
1188 //print "year: $year month: $month quarter_start: $quarter_start quarter_end: $quarter_end<br>";
1190 if($action == 'save')
1192 // Save any changes made to the appointment table
1193 $new_data = get_var('appt_notes',array('POST'));
1194 foreach ($new_data as $entry)
1196 $elder = $entry['elder'];
1197 $appointment = $entry['appointment'];
1199 //print "elder: $elder appointment: $appointment <br>";
1201 // Perform database save actions here
1202 $this->db->query("UPDATE eq_appointment set " .
1203 " elder='" . $elder . "'" .
1204 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1208 // Save any changes made to the int notes table
1209 $new_data = get_var('int_notes',array('POST'));
1210 foreach ($new_data as $entry)
1212 $int_notes = $entry['notes'];
1213 $elder_id = $entry['elder_id'];
1214 $elder_name = $entry['elder_name'];
1215 $int_pri = $entry['pri'];
1216 $aaronic = $entry['aaronic'];
1218 // Perform database save actions here
1219 $this->db->query("UPDATE eq_elder set " .
1220 " int_notes='" . $int_notes . "'" .
1221 ",int_pri='" . $int_pri . "'" .
1222 " WHERE elder=" . $elder_id,__LINE__,__FILE__);
1227 $take_me_to_url = $GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_sched');
1228 Header('Location: ' . $take_me_to_url);
1231 // Get the Districts
1232 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
1233 $this->db->query($sql,__LINE__,__FILE__);
1235 while ($this->db->next_record())
1237 $district = $this->db->f('district');
1238 $districts[$i]['district'] = $this->db->f('district');
1239 $districts[$i]['name'] = $this->db->f('name');
1240 $districts[$i]['supervisor'] = $this->db->f('supervisor');
1241 $sql = "SELECT * FROM eq_presidency where district=$district and valid=1";
1242 $this->db2->query($sql,__LINE__,__FILE__);
1243 if($this->db2->next_record()) {
1244 $districts[$i]['presidency'] = $this->db2->f('presidency');
1249 // create the elder id -> elder name mapping
1250 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY name ASC";
1251 $this->db->query($sql,__LINE__,__FILE__);
1253 $elder_id_data = NULL;
1254 $elder_name_data = NULL;
1255 while ($this->db->next_record())
1257 $elder_name_data[$i] = $this->db->f('name');
1258 $elder_id_data[$i] = $this->db->f('elder');
1261 array_multisort($elder_name_data, $elder_id_data);
1263 // APPOINTMENT TABLE
1265 $date_width=150; $time_width=100; $elder_width=200;
1266 $appt_table_width=$date_width + $time_width + $elder_width;
1267 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1268 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1269 $appt_header_row.= "<th width=$elder_width><font size=-2>Elder</th>";
1270 $appt_table_data = "";
1272 $total_comps=0; $comps_with_quarterly_int=0;
1274 // Display a scheduling table for each district
1275 for ($d=0; $d < count($districts); $d++) {
1276 $table_data=""; $appt_table_data="";
1277 $this->t->set_var('district_number',$districts[$d]['district']);
1278 $this->t->set_var('district_name',$districts[$d]['name']);
1279 $supervisor = $districts[$d]['supervisor'];
1280 $table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": All Elders with Interviews Not Completed";
1281 $appt_table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": Interview Appointment Slots";
1282 $this->t->set_var('table_title',$table_title);
1283 $this->t->set_var('appt_table_title',$appt_table_title);
1285 // query the database for all the appointments
1286 $sql = "SELECT * FROM eq_appointment where presidency=".$districts[$d]['presidency']." and date>=CURDATE() ORDER BY date ASC, time ASC";
1287 $this->db->query($sql,__LINE__,__FILE__);
1289 while ($this->db->next_record())
1291 $appointment = $this->db->f('appointment');
1292 $elder = $this->db->f('elder');
1294 $date = $this->db->f('date');
1295 $date_array = explode("-",$date);
1296 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1297 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1299 $time = $this->db->f('time');
1300 $time_array = explode(":",$time);
1301 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1303 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1304 $appt_table_data.= "<td align=center>$day_string</td>";
1305 $appt_table_data.= "<td align=center>$time_string</td>";
1307 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][elder]>';
1308 $appt_table_data.= '<option value=0></option>';
1309 for ($i=0; $i < count($elder_id_data); $i++) {
1310 $id = $elder_id_data[$i];
1311 $name = $elder_name_data[$i];
1312 if($elder_id_data[$i] == $elder) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
1313 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1315 $appt_table_data.='</select></td>';
1317 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1319 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1320 $this->t->set_var('tr_color',$tr_color);
1323 $this->t->set_var('appt_table_data',$appt_table_data);
1324 $this->t->set_var('appt_header_row',$appt_header_row);
1325 $this->t->set_var('appt_table_width',$appt_table_width);
1327 // INTERVIEW SCHEDULING TABLE
1329 // Select all the unique companionship numbers for this district
1330 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $districts[$d]['district'];
1331 $this->db->query($sql,__LINE__,__FILE__);
1333 while ($this->db->next_record())
1335 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
1340 for ($j=0; $j < count($unique_companionships); $j++) {
1341 // Select all the companions from each companionship
1342 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
1343 "companionship=". $unique_companionships[$j]['companionship'];
1344 $this->db->query($sql,__LINE__,__FILE__);
1345 $k=0; $int_completed=0;
1346 $comp = $unique_companionships[$j]['companionship'];
1347 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1348 $this->t->set_var('tr_color',$tr_color);
1350 while ($this->db->next_record())
1352 // Get this companions information
1353 $elder_id = $this->db->f('elder');
1354 $aaronic_id = $this->db->f('aaronic');
1356 $sql = "SELECT * FROM eq_elder where elder=$elder_id";
1357 $this->db2->query($sql,__LINE__,__FILE__);
1358 if($this->db2->next_record())
1360 $elder_id = $this->db2->f('elder');
1361 $elder_name = $this->db2->f('name');
1362 $elder_phone[$elder_id] = $this->db2->f('phone');
1363 $elder_int_pri[$elder_id] = $this->db2->f('int_pri');
1364 $elder_int_notes[$elder_id] = $this->db2->f('int_notes');
1368 $sql = "SELECT * FROM eq_aaronic where aaronic=$aaronic_id";
1369 $this->db2->query($sql,__LINE__,__FILE__);
1370 if($this->db2->next_record())
1372 $elder_id = $this->db2->f('aaronic');
1373 $elder_name = $this->db2->f('name');
1374 $elder_phone[$elder_id] = $this->db2->f('phone');
1380 $name = $elder_name;
1381 $phone = $elder_phone[$id];
1382 $int_pri = $elder_int_pri[$id];
1383 $int_notes = $elder_int_notes[$id];
1384 $aaronic = $elder_aaronic;
1386 // If the companionship has already had its quarterly interview,
1387 // Skip the other companion in the companionship.
1388 if($int_completed == 1) {
1389 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1390 $completed_data.= "<td align=center>$phone</td>";
1391 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1392 $completed_data.= "<td align=left>$int_notes</td>";
1393 $completed_data.= '</tr>';
1394 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1395 $this->t->set_var('tr_color2',$tr_color2);
1396 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1397 $this->t->set_var('tr_color',$tr_color);
1401 // If this companionship has had a hometeaching interview this quarter, don't show them on the schedule list
1402 $sql = "SELECT * FROM eq_interview WHERE date >= '$quarter_start' AND date < '$quarter_end' ".
1404 $this->db2->query($sql,__LINE__,__FILE__);
1406 if(!$this->db2->next_record()) {
1407 $sql = "SELECT * FROM eq_interview WHERE elder=" . $id . " ORDER BY date DESC";
1408 $this->db3->query($sql,__LINE__,__FILE__);
1409 if($this->db3->next_record()) { $date = $this->db3->f('date'); } else { $date = ""; }
1410 $link_data['menuaction'] = 'eq.eq.int_update';
1411 $link_data['elder'] = $id;
1412 $link_data['aaronic'] = 0;
1413 $link_data['name'] = $name;
1414 $link_data['interview'] = '';
1415 $link_data['action'] = 'add';
1416 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1417 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1418 $table_data.= "<td align=center>$phone</td>";
1419 $table_data.= "<td align=center>";
1420 $table_data.= '<select name=int_notes['.$i.'][pri]>';
1421 foreach(range(0,6) as $num) {
1422 if($num == 0) { $num = 1; } else {$num = $num*5; }
1423 if($int_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
1424 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1426 $table_data.= '</select></td>';
1427 $table_data.= "<td align=center>$date</td>";
1428 $table_data.= '<td><input type=text size="50" maxlength="128" name="int_notes['.$i.'][notes]" value="'.$int_notes.'">';
1429 $table_data.= '<input type=hidden name="int_notes['.$i.'][elder_id]" value="'.$id.'">';
1430 $table_data.= '<input type=hidden name="int_notes['.$i.'][elder_name]" value="'.$name.'">';
1431 $table_data.= '<input type=hidden name="int_notes['.$i.'][aaronic]" value="'.$aaronic.'">';
1432 $table_data.= '</td>';
1433 $table_data.= '</tr>';
1436 $link_data['menuaction'] = 'eq.eq.int_update';
1437 $link_data['interviewer'] = $this->db2->f('interviewer');
1438 $link_data['elder'] = $this->db2->f('elder');
1439 $link_data['aaronic'] = $this->db2->f('aaronic');
1440 $link_data['name'] = $name;
1441 $link_data['interview'] = $this->db2->f('int');
1442 $link_data['action'] = 'view';
1443 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1444 $comps_with_quarterly_int++;
1446 $date = $this->db2->f('date');
1447 $int_notes = $this->db2->f('notes');
1448 if(strlen($int_notes) > 40) { $int_notes = substr($int_notes,0,40) . "..."; }
1449 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1450 $completed_data.= "<td align=center>$phone</td>";
1451 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1452 $completed_data.= "<td align=left>$int_notes</td>";
1453 $completed_data.= '</tr>';
1458 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1459 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1460 $completed_header_row = "<th width=$name_width><font size=-2>Elder Name</th>";
1461 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1462 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1463 $completed_header_row.= "<th width=$notes_width><font size=-2>Interview Notes</th>";
1465 $this->t->set_var('table_width',$table_width);
1466 $this->t->set_var('header_row',$header_row);
1467 $this->t->set_var('table_data',$table_data);
1468 $this->t->set_var('completed_header_row',$completed_header_row);
1469 $this->t->set_var('completed_table_width',$completed_table_width);
1470 $this->t->set_var('completed',$completed_data);
1471 $this->t->fp('elderlist','elder_list',True);
1473 } // End for each district loop
1476 $elders_width=300; $totals_width=100;
1477 $totals_table_width=$elders_width + $totals_width;
1478 $totals_header_row = "<th width=$elders_width><font size=-2>Elders</th>";
1479 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
1480 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1481 $totals_data.= "<td align=left><font size=-2><b>Total Companionships with interviews completed:</b></font></td>";
1482 $totals_data.= "<td align=center><font size=-2><b>$comps_with_quarterly_int / $total_comps</b></font></td>";
1483 $percent = ceil(($comps_with_quarterly_int / $total_comps)*100);
1484 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1485 $this->t->set_var('tr_color',$tr_color);
1486 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1487 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
1488 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
1489 $totals_data.= "</tr>";
1491 $this->t->set_var('totals',$totals_data);
1492 $this->t->set_var('totals_header_row',$totals_header_row);
1493 $this->t->set_var('totals_table_width',$totals_table_width);
1495 $this->t->pfp('out','int_sched_t');
1496 $this->save_sessiondata();
1500 function vis_sched()
1502 $this->t->set_file(array('vis_sched_t' => 'vis_sched.tpl'));
1503 $this->t->set_block('vis_sched_t','family_list','familylist');
1504 $this->t->set_block('vis_sched_t','appt_list','apptlist');
1505 $action = get_var('action',array('GET','POST'));
1507 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1508 $this->t->set_var('lang_reset','Clear Changes');
1510 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
1511 $this->t->set_var('vis_link_title','View Yearly Visits');
1513 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched'));
1514 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
1516 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched&action=save'));
1517 $this->t->set_var('title','EQ Presidency Yearly Visit Scheduler');
1519 $family_width=500; $phone_width=40; $pri_width=10; $notes_width=128; $visit_date_width=20;
1520 $table_width=$family_width + $phone_width + $pri_width + $notes_width + $visit_date_width;
1521 $header_row = "<th width=$family_width><font size=-2>Family Name</th>";
1522 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1523 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1524 $header_row.= "<th width=$visit_date_width><font size=-2>Last Visit</th>";
1525 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1526 $table_data=""; $completed_data=""; $totals_data="";
1530 if($action == 'save')
1532 // Save any changes made to the appointment table
1533 $new_data = get_var('appt_notes',array('POST'));
1534 foreach ($new_data as $entry)
1536 $family = $entry['family'];
1537 $appointment = $entry['appointment'];
1539 // Perform database save actions here
1540 $this->db->query("UPDATE eq_appointment set " .
1541 " family='" . $family . "'" .
1542 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1546 // Save any changes made to the visit notes table
1547 $new_data = get_var('vis_notes',array('POST'));
1548 foreach ($new_data as $entry)
1550 $visit_notes = $entry['notes'];
1551 $family_id = $entry['family_id'];
1552 $visit_pri = $entry['pri'];
1554 // Perform database save actions here
1555 $this->db->query("UPDATE eq_family set " .
1556 " visit_notes='" . $visit_notes . "'" .
1557 ",visit_pri='" . $visit_pri . "'" .
1558 " WHERE family=" . $family_id,__LINE__,__FILE__);
1562 $take_me_to_url = $GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched');
1563 Header('Location: ' . $take_me_to_url);
1566 // APPOINTMENT TABLE
1567 $date_width=150; $time_width=100; $family_width=250;
1568 $appt_table_width=$date_width + $time_width + $family_width;
1569 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1570 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1571 $appt_header_row.= "<th width=$family_width><font size=-2>Family</th>";
1572 $appt_table_data = "";
1574 // Find out what the EQ Presidency ID is
1575 $sql = "SELECT * FROM eq_presidency where president=0 and counselor=0 and secretary=0 and valid=1";
1576 $this->db->query($sql,__LINE__,__FILE__);
1577 if($this->db->next_record()) {
1578 $presidency_name = $this->db->f('name');
1579 $presidency_id = $this->db->f('presidency');
1581 print "<hr><font color=red><h3>-E- Unable to locate EQ Presidency in eq_presidency table</h3></font></hr>";
1585 // create the family id -> family name mapping
1586 $sql = "SELECT * FROM eq_family where valid=1 and elder_id != 0 ORDER BY name ASC";
1587 $this->db->query($sql,__LINE__,__FILE__);
1590 while ($this->db->next_record())
1592 $family_id[$i] = $this->db->f('family');
1593 $family_name[$i] = $this->db->f('name');
1596 array_multisort($family_name, $family_id);
1598 // query the database for all the appointments
1599 $sql = "SELECT * FROM eq_appointment where presidency=$presidency_id and date>=CURDATE() ORDER BY date ASC, time ASC";
1600 $this->db->query($sql,__LINE__,__FILE__);
1602 while ($this->db->next_record())
1604 $appointment = $this->db->f('appointment');
1605 $family = $this->db->f('family');
1607 $date = $this->db->f('date');
1608 $date_array = explode("-",$date);
1609 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1610 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1612 $time = $this->db->f('time');
1613 $time_array = explode(":",$time);
1614 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1616 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1617 $appt_table_data.= "<td align=center>$day_string</td>";
1618 $appt_table_data.= "<td align=center>$time_string</td>";
1620 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][family]>';
1621 $appt_table_data.= '<option value=0></option>';
1622 for ($i=0; $i < count($family_id); $i++) {
1623 $id = $family_id[$i];
1624 $name = $family_name[$i];
1625 if($family_id[$i] == $family) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
1626 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
1628 $appt_table_data.='</select></td>';
1630 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1632 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1633 $this->t->set_var('tr_color',$tr_color);
1636 $this->t->set_var('appt_table_data',$appt_table_data);
1637 $this->t->set_var('appt_header_row',$appt_header_row);
1638 $this->t->set_var('appt_table_width',$appt_table_width);
1641 // VISIT SCHEDULING TABLE
1642 $sql = "SELECT * FROM eq_family where valid=1 and elder_id != 0 ORDER BY visit_pri ASC";
1643 $this->db->query($sql,__LINE__,__FILE__);
1645 $total_families=0; $families_with_yearly_visit=0;
1649 $family_name = NULL;
1650 $family_phone = NULL;
1651 $family_visit_pri = NULL;
1652 $family_visit_notes = NULL;
1653 while ($this->db->next_record())
1655 $family_id[$i] = $this->db->f('family');
1656 $family_name[$i] = $this->db->f('name');
1657 $family_phone[$family_id[$i]] = $family_id[$i] . " ERROR";
1658 $family_visit_pri[$family_id[$i]] = $this->db->f('visit_pri');
1659 $family_visit_notes[$family_id[$i]] = $this->db->f('visit_notes');
1664 $sql = "SELECT * FROM eq_parent where valid=1";
1665 $this->db->query($sql,__LINE__,__FILE__);
1666 while ($this->db->next_record())
1668 $family = $this->db->f('family');
1669 $phone = $this->db->f('phone');
1670 $family_phone[$family] = $phone;
1673 $max = count($family_id);
1675 for($i=0; $i < $max; $i++) {
1676 $id = $family_id[$i];
1677 $name = $family_name[$i];
1678 $phone = $family_phone[$id];
1679 $vis_pri = $family_visit_pri[$id];
1680 $vis_notes = $family_visit_notes[$id];
1682 // If this family has had a yearly visit this year, don't show them on the schedule list
1683 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
1684 $sql = "SELECT * FROM eq_visit WHERE date > '$year_start' AND date < '$year_end' ".
1685 "AND family=" . $id . " AND companionship=0";
1686 $this->db2->query($sql,__LINE__,__FILE__);
1688 if(!$this->db2->next_record()) {
1689 $sql = "SELECT * FROM eq_visit WHERE family=" . $id . " AND companionship=0 ORDER BY date DESC";
1690 $this->db->query($sql,__LINE__,__FILE__);
1691 if($this->db->next_record()) { $date = $this->db->f('date'); } else { $date = ""; }
1692 $link_data['menuaction'] = 'eq.eq.vis_update';
1693 $link_data['visit'] = '';
1694 $link_data['family'] = $id;
1695 $link_data['name'] = $name;
1696 $link_data['action'] = 'add';
1697 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1698 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
1699 $table_data.= "<td align=center>$phone</td>";
1700 $table_data.= "<td align=center>";
1701 $table_data.= '<select name=vis_notes['.$i.'][pri]>';
1702 foreach(range(0,6) as $num) {
1703 if($num == 0) { $num = 1; } else {$num = $num*5; }
1704 if($vis_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
1705 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1707 $table_data.= '</select></td>';
1708 $table_data.= "<td align=center>$date</td>";
1709 $table_data.= '<td><input type=text size="50" maxlength="128" name="vis_notes['.$i.'][notes]" value="'.$vis_notes.'">';
1710 $table_data.= '<input type=hidden name="vis_notes['.$i.'][family_id]" value="'.$id.'">';
1711 $table_data.= '<input type=hidden name="vis_notes['.$i.'][family_name]" value="'.$name.'">';
1712 $table_data.= '</td>';
1713 $table_data.= '</tr>';
1714 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1715 $this->t->set_var('tr_color',$tr_color);
1717 $link_data['menuaction'] = 'eq.eq.vis_update';
1718 $link_data['visit'] = $this->db2->f('visit');
1719 $link_data['family'] = $this->db2->f('family');
1720 $link_data['name'] = $name;
1721 $link_data['date'] = $this->db2->f('date');
1722 $link_data['action'] = 'view';
1723 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1724 $families_with_yearly_visit++;
1725 $date = $this->db2->f('date');
1726 $vis_notes = $this->db2->f('notes');
1727 if(strlen($vis_notes) > 40) { $vis_notes = substr($vis_notes,0,40) . "..."; }
1728 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
1729 $completed_data.= "<td align=center>$phone</td>";
1730 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1731 $completed_data.= "<td align=left>$vis_notes</td>";
1732 $completed_data.= '</tr>';
1733 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1734 $this->t->set_var('tr_color2',$tr_color2);
1738 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1739 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1740 $completed_header_row = "<th width=$name_width><font size=-2>Family Name</th>";
1741 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1742 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1743 $completed_header_row.= "<th width=$notes_width><font size=-2>Visit Notes</th>";
1745 $family_width=300; $totals_width=100;
1746 $totals_table_width=$family_width + $totals_width;
1747 $totals_header_row = "<th width=$family_width><font size=-2>Families</th>";
1748 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
1749 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1750 $totals_data.= "<td align=left><font size=-2><b>Total Families with yearly Visits completed:</b></font></td>";
1751 $totals_data.= "<td align=center><font size=-2><b>$families_with_yearly_visit / $total_families</b></font></td>";
1752 $percent = ceil(($families_with_yearly_visit / $total_families)*100);
1753 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1754 $this->t->set_var('tr_color',$tr_color);
1755 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1756 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
1757 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
1758 $totals_data.= "</tr>";
1760 $this->t->set_var('table_width',$table_width);
1761 $this->t->set_var('header_row',$header_row);
1762 $this->t->set_var('table_data',$table_data);
1763 $this->t->set_var('totals_header_row',$totals_header_row);
1764 $this->t->set_var('totals_table_width',$totals_table_width);
1765 $this->t->set_var('completed_header_row',$completed_header_row);
1766 $this->t->set_var('completed_table_width',$completed_table_width);
1767 $this->t->set_var('completed',$completed_data);
1768 $this->t->set_var('totals',$totals_data);
1769 $this->t->fp('familylist','family_list',True);
1770 $this->t->fp('apptlist','appt_list',True);
1772 $this->t->pfp('out','vis_sched_t');
1773 $this->save_sessiondata();
1779 $this->t->set_file(array('ppi_view_t' => 'ppi_view.tpl'));
1780 $this->t->set_block('ppi_view_t','district_list','list');
1782 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
1783 $num_months = get_var('num_months',array('GET','POST'));
1784 if($num_months == '') { $num_months = $this->default_ppi_num_months; }
1785 $this->t->set_var('num_months',$num_months);
1786 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
1787 else { $this->t->set_var('lang_num_months','Months of History'); }
1788 $this->t->set_var('lang_filter','Filter');
1789 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
1791 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
1792 $this->t->set_var('ppi_link_title','Yearly PPIs');
1794 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched'));
1795 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
1797 $this->t->set_var('title','Yearly PPIs');
1798 $num_months = get_var('num_months',array('GET','POST'));
1799 if($num_months == '') { $num_months = $this->default_ppi_num_years; }
1800 $this->t->set_var('num_months',$num_months);
1801 if($num_months == 1) { $this->t->set_var('lang_num_months','Year of History'); }
1802 else { $this->t->set_var('lang_num_months','Years of History'); }
1804 $sql = "SELECT * FROM eq_presidency where president=1 and valid=1";
1805 $this->db->query($sql,__LINE__,__FILE__);
1806 if($this->db->next_record()) {
1807 $president_name = $this->db->f('name');
1808 $interviewer = $this->db->f('elder');
1811 print "<hr><font color=red><h3>-E- Unable to locate EQ President in eq_presidency table</h3></font></hr>";
1814 $this->t->set_var('district_number','*');
1815 $this->t->set_var('district_name',$president_name);
1817 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
1818 $this->db->query($sql,__LINE__,__FILE__);
1820 while ($this->db->next_record())
1822 $elder_id[$i] = $this->db->f('elder');
1823 $elder_name[$i] = $this->db->f('name');
1824 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
1825 $elder_ppi_pri[$elder_id[$i]] = $this->db->f('ppi_pri');
1826 $elder_ppi_notes[$elder_id[$i]] = $this->db->f('ppi_notes');
1830 array_multisort($elder_name, $elder_id);
1831 //var_dump($elder_name); print "<br><br>"; var_dump($elder_id);
1833 $header_row="<th width=$comp_width><font size=-2>Elder Name</th>";
1835 $elder_width=400; $ppi_width=75; $table_width=$elder_width + $num_months*$ppi_width;
1837 for($m=$num_months; $m >= 0; $m--) {
1838 $year = date('Y') - $m;
1839 $header_row .= "<th width=150><font size=-2>$year</th>";
1843 for ($j=0; $j < count($elder_id); $j++) {
1844 $id = $elder_id[$j];
1845 $name = $elder_name[$j];
1846 $phone = $elder_phone[$id];
1848 $link_data['menuaction'] = 'eq.eq.ppi_update';
1849 $link_data['interviewer'] = $interviewer;
1850 $link_data['elder'] = $id;
1851 $link_data['name'] = $name;
1852 $link_data['ppi'] = '';
1853 $link_data['eqpresppi'] = $eqpresppi;
1854 $link_data['action'] = 'add';
1855 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1856 $this->nextmatchs->template_alternate_row_color(&$this->t);
1857 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1859 // Find out how many times PPIs were performed in the past $num_months for this Elder
1860 for($m=$num_months; $m >= 0; $m--) {
1861 $year = date('Y') - $m;
1862 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
1863 $sql = "SELECT * FROM eq_ppi WHERE date > '$year_start' AND date < '$year_end' ".
1865 $this->db2->query($sql,__LINE__,__FILE__);
1867 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
1868 if($this->db2->next_record()) {
1869 $ppis[$m]++; $total_ppis[$m]++; $ppi_recorded[$companionship][$m]=1;
1870 $link_data['menuaction'] = 'eq.eq.ppi_update';
1871 $link_data['companionship'] = $companionship;
1872 $link_data['interviewer'] = $this->db2->f('interviewer');
1873 $link_data['elder'] = $id;
1874 $link_data['name'] = $name;
1875 $link_data['ppi'] = $this->db2->f('ppi');
1876 $link_data['eqpresppi'] = $eqpresppi;
1877 $link_data['action'] = 'view';
1878 $date = $this->db2->f('date');
1879 $date_array = explode("-",$date);
1880 $month = $date_array[1];
1881 $day = $date_array[2];
1882 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1883 $table_data .= '<td align=center><a href='.$link.'><img src="checkmark.gif"> '.$month.'-'.$day.'</a></td>';
1885 else { $table_data .= "<td> </td>"; }
1887 $table_data .= "</tr>\n";
1889 $table_data .= "<tr><td colspan=20><hr></td></tr>";
1891 $stat_data = "<tr><td><b><font size=-2>$total_elders Elders<br>PPI Totals:</font></b></td>";
1892 for($m=$num_months; $m >=0; $m--) {
1893 $percent = ceil(($ppis[$m] / $total_elders)*100);
1894 $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
1896 $stat_data .= "</tr>";
1898 $this->t->set_var('table_width',$table_width);
1899 $this->t->set_var('header_row',$header_row);
1900 $this->t->set_var('table_data',$table_data);
1901 $this->t->set_var('stat_data',$stat_data);
1902 $this->t->pfp('out','ppi_view_t');
1903 $this->save_sessiondata();
1906 function ppi_update()
1908 $this->t->set_file(array('form' => 'ppi_update.tpl'));
1909 $this->t->set_block('form','interviewer_list','int_list');
1910 $this->t->set_block('form','add','addhandle');
1911 $this->t->set_block('form','edit','edithandle');
1913 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
1914 $this->t->set_var('readonly','');
1915 $this->t->set_var('disabled','');
1917 $action = get_var('action',array('GET','POST'));
1918 $companionship = get_var('companionship',array('GET','POST'));
1919 $interviewer = get_var('interviewer',array('GET','POST'));
1920 $name = get_var('name',array('GET','POST'));
1921 $ppi = get_var('ppi',array('GET','POST'));
1922 $elder = get_var('elder',array('GET','POST'));
1923 $aaronic = get_var('aaronic',array('GET','POST'));
1924 $date = get_var('date',array('GET','POST'));
1925 $notes = get_var('notes',array('GET','POST'));
1926 $eqpresppi = get_var('eqpresppi',array('GET','POST'));
1928 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
1929 $this->db->query($sql,__LINE__,__FILE__);
1930 while ($this->db->next_record())
1932 $supervisor = $this->db->f('supervisor');
1933 $sql = "SELECT * FROM eq_elder WHERE elder=" . $supervisor;
1934 $this->db2->query($sql,__LINE__,__FILE__);
1935 $this->db2->next_record();
1936 $interviewer_name = $this->db2->f('name');
1938 if($supervisor == $interviewer) {
1939 $this->t->set_var('interviewer',$supervisor . ' selected');
1941 $this->t->set_var('interviewer',$interviewer);
1943 $this->t->set_var('interviewer_name',$interviewer_name);
1944 $this->t->fp('int_list','interviewer_list',True);
1947 if($action == 'save')
1949 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
1950 $this->db->query("UPDATE eq_ppi set " .
1951 " ppi='" . $ppi . "'" .
1952 ", interviewer='" . $interviewer . "'" .
1953 ", elder='" . $elder . "'" .
1954 ", date='" . $date . "'" .
1955 ", notes='" . $notes . "'" .
1956 ", eqpresppi='" . $eqpresppi . "'" .
1957 " WHERE ppi=" . $ppi,__LINE__,__FILE__);
1962 if($action == 'insert')
1964 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
1965 $this->db->query("INSERT INTO eq_ppi (interviewer,elder,date,notes,eqpresppi) "
1966 . "VALUES ('" . $interviewer . "','" . $elder . "','"
1967 . $date . "','" . $notes . "','" . $eqpresppi ."')",__LINE__,__FILE__);
1972 if($action == 'add')
1974 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
1975 $this->t->set_var('ppi', '');
1976 $this->t->set_var('interviewer', $interviewer);
1977 $this->t->set_var('name',$name);
1978 $this->t->set_var('elder',$elder);
1979 $this->t->set_var('date','');
1980 $this->t->set_var('notes','');
1981 $this->t->set_var('eqpresppi',$eqpresppi);
1982 $this->t->set_var('lang_done','Cancel');
1983 $this->t->set_var('lang_action','Adding New PPI');
1984 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
1985 . $ppi . '&action=' . 'insert'));
1988 if($action == 'edit' || $action == 'view')
1990 $sql = "SELECT * FROM eq_ppi WHERE ppi=".$ppi;
1991 $this->db->query($sql,__LINE__,__FILE__);
1992 $this->db->next_record();
1993 $this->t->set_var('ppi',$ppi);
1994 $this->t->set_var('name',$name);
1995 $this->t->set_var('interviewer', $this->db->f('interviewer'));
1996 $this->t->set_var('elder',$this->db->f('elder'));
1997 $this->t->set_var('date',$this->db->f('date'));
1998 $this->t->set_var('notes',$this->db->f('notes'));
1999 $this->t->set_var('eqpresppi',$this->db->f('eqpresppi'));
2002 if($action == 'edit')
2004 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2005 $this->t->set_var('lang_done','Cancel');
2006 $this->t->set_var('lang_action','Editing PPI');
2007 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
2008 . $ppi . '&action=' . 'save'));
2011 if($action == 'view')
2013 $date = $this->db->f('date');
2014 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2015 $this->t->set_var('readonly','READONLY');
2016 $this->t->set_var('disabled','DISABLED');
2017 $this->t->set_var('lang_done','Done');
2018 $this->t->set_var('lang_action','Viewing PPI');
2019 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
2020 . $ppi . '&action=' . 'edit'));
2023 $this->t->set_var('lang_reset','Clear Form');
2024 $this->t->set_var('lang_add','Add PPI');
2025 $this->t->set_var('lang_save','Save Changes');
2026 $this->t->set_var('edithandle','');
2027 $this->t->set_var('addhandle','');
2029 $this->t->pfp('out','form');
2031 if($action == 'view') { $this->t->set_var('lang_save','Edit PPI'); }
2032 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2033 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2035 $this->save_sessiondata();
2040 $this->t->set_file(array('int_view_t' => 'int_view.tpl'));
2041 $this->t->set_block('int_view_t','district_list','list');
2043 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_view'));
2044 $num_months = get_var('num_months',array('GET','POST'));
2045 if($num_months == '') { $num_months = $this->default_int_num_months; }
2046 $this->t->set_var('num_months',$num_months);
2047 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
2048 else { $this->t->set_var('lang_num_months','Months of History'); }
2049 $this->t->set_var('lang_filter','Filter');
2050 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_view'));
2052 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_view'));
2053 $this->t->set_var('int_link_title','Hometeaching Interviews');
2055 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_sched'));
2056 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
2058 $this->t->set_var('title','Hometeaching Interviews');
2060 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
2061 $this->db->query($sql,__LINE__,__FILE__);
2063 while ($this->db->next_record())
2065 $districts[$i]['district'] = $this->db->f('district');
2066 $districts[$i]['name'] = $this->db->f('name');
2067 $districts[$i]['supervisor'] = $this->db->f('supervisor');
2071 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
2072 $this->db->query($sql,__LINE__,__FILE__);
2074 while ($this->db->next_record())
2076 $elder_id[$i] = $this->db->f('elder');
2077 $elder_name[$i] = $this->db->f('name');
2078 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
2081 array_multisort($elder_name, $elder_id);
2082 for($i=0; $i < count($elder_id); $i++) {
2083 $id = $elder_id[$i];
2084 $elders[$id] = $elder_name[$i];
2087 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
2088 $this->db->query($sql,__LINE__,__FILE__);
2089 while ($this->db->next_record())
2091 $aaronic_id = $this->db->f('aaronic');
2092 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
2093 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
2096 $total_companionships = 0;
2097 $this->nextmatchs->template_alternate_row_color(&$this->t);
2098 for ($i=0; $i < count($districts); $i++) {
2099 $this->t->set_var('district_number',$districts[$i]['district']);
2100 $this->t->set_var('district_name',$districts[$i]['name']);
2101 $supervisor = $districts[$i]['supervisor'];
2102 $unique_companionships='';
2104 // Select all the unique companionship numbers for this district
2105 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $districts[$i]['district'];
2107 $this->db->query($sql,__LINE__,__FILE__);
2109 while ($this->db->next_record())
2111 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
2115 $comp_width=250; $int_width=75; $table_width=$comp_width + $num_months*$int_width;
2116 $table_data=""; $num_companionships = $j; $num_elders = 0;
2117 for($m=$num_months; $m >= 0; $m--) { $ints[$m] = 0; }
2118 for ($j=0; $j < count($unique_companionships); $j++) {
2119 // Select all the companions in each companionship
2120 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
2121 "companionship=". $unique_companionships[$j]['companionship'];
2122 $this->db->query($sql,__LINE__,__FILE__);
2124 $comp = $unique_companionships[$j]['companionship'];
2125 for($m=$num_months; $m >= 0; $m--) { $int_recorded[$comp][$m] = 0; }
2126 while ($this->db->next_record())
2128 // Get this companions information
2130 $companionship = $this->db->f('companionship');
2131 $elder_id = $this->db->f('elder');
2132 $aaronic_id = $this->db->f('aaronic');
2134 $name = $elders[$elder_id];
2135 $phone = $elder_phone[$elder_id];
2137 else if($aaronic_id) {
2138 $name = $aaronic[$aaronic_id]['name'];
2139 $phone = $aaronic[$aaronic_id]['phone'];
2141 $link_data['menuaction'] = 'eq.eq.int_update';
2142 $link_data['companionship'] = $companionship;
2143 $link_data['interviewer'] = $supervisor;
2144 $link_data['elder'] = $elder_id;
2145 $link_data['aaronic'] = $aaronic_id;
2146 $link_data['name'] = $name;
2147 $link_data['interview'] = '';
2148 $link_data['action'] = 'add';
2149 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2150 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2152 // Find out how many times Interviews were performed in the past $num_months for this Elder
2153 $header_row="<th width=$comp_width><font size=-2>Companionship</th>";
2154 for($m=$num_months; $m >= 0; $m--) {
2155 $month = $this->current_month - $m;
2156 $year = $this->current_year;
2157 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
2158 if($month < 10) { $month = "0"."$month"; }
2159 $month_start = "$year"."-"."$month"."-"."01";
2160 $month_end = "$year"."-"."$month"."-"."31";
2161 $month = "$month"."/"."$year";
2162 $sql = "SELECT * FROM eq_interview WHERE date >= '$month_start' AND date <= '$month_end' ".
2163 "AND elder=" . $elder_id . " AND aaronic=" . $aaronic_id;
2164 $this->db2->query($sql,__LINE__,__FILE__);
2165 $header_row .= "<th width=$int_width><font size=-2>$month</th>";
2167 if(!$total_ints[$m]) { $total_ints[$m] = 0; }
2168 if($this->db2->next_record()) {
2169 if(!$int_recorded[$companionship][$m]) {
2170 $ints[$m]++; $total_ints[$m]++; $int_recorded[$companionship][$m]=1;
2172 $link_data['menuaction'] = 'eq.eq.int_update';
2173 $link_data['companionship'] = $companionship;
2174 $link_data['interviewer'] = $this->db2->f('interviewer');
2175 $link_data['elder'] = $elder_id;
2176 $link_data['aaronic'] = $aaronic_id;
2177 $link_data['name'] = $name;
2178 $link_data['interview'] = $this->db2->f('interview');
2179 $link_data['action'] = 'view';
2180 $date = $this->db2->f('date');
2181 $date_array = explode("-",$date);
2182 $month = $date_array[1];
2183 $day = $date_array[2];
2184 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2185 $table_data .= '<td align=center><a href='.$link.'><img src="checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2187 else { $table_data .= "<td> </td>"; }
2189 $table_data .= "</tr>";
2192 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2194 $total_companionships += $num_companionships;
2195 $stat_data = "<tr><td><b><font size=-2>$num_companionships Companionships<br>Interview Quarterly Totals:</font></b></td>";
2197 for($m=$num_months; $m >=0; $m--) {
2198 $month = $this->current_month - $m;
2199 if(($month % 3) == 1) { $quarter_total = $ints[$m]; }
2200 else { $quarter_total += $ints[$m]; }
2201 $percent = ceil(($quarter_total / $num_companionships)*100);
2202 $stat_data .= "<td align=center><font size=-2><b>$quarter_total<br>$percent%</font></b></td>";
2204 $stat_data .= "</tr>";
2206 $this->t->set_var('table_width',$table_width);
2207 $this->t->set_var('header_row',$header_row);
2208 $this->t->set_var('table_data',$table_data);
2209 $this->t->set_var('stat_data',$stat_data);
2210 $this->t->fp('list','district_list',True);
2213 // Display the totals, cummulative per quarter
2215 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>Interview Quarterly Totals:</font></b></td>";
2216 for($m=$num_months; $m >=0; $m--) {
2217 $month = $this->current_month - $m;
2218 if(($month % 3) == 1) { $quarter_total = $total_ints[$m]; }
2219 else { $quarter_total += $total_ints[$m]; }
2220 $percent = ceil(($quarter_total / $total_companionships)*100);
2221 $totals .= "<td align=center><font size=-2><b>$quarter_total<br>$percent%</font></b></td>";
2225 $this->t->set_var('totals',$totals);
2226 $this->t->pfp('out','int_view_t');
2227 $this->save_sessiondata();
2230 function int_update()
2232 $this->t->set_file(array('form' => 'int_update.tpl'));
2233 $this->t->set_block('form','interviewer_list','int_list');
2234 $this->t->set_block('form','add','addhandle');
2235 $this->t->set_block('form','edit','edithandle');
2237 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_view'));
2238 $this->t->set_var('readonly','');
2239 $this->t->set_var('disabled','');
2241 $action = get_var('action',array('GET','POST'));
2242 $companionship = get_var('companionship',array('GET','POST'));
2243 $interviewer = get_var('interviewer',array('GET','POST'));
2244 $name = get_var('name',array('GET','POST'));
2245 $interview = get_var('interview',array('GET','POST'));
2246 $elder = get_var('elder',array('GET','POST'));
2247 $aaronic = get_var('aaronic',array('GET','POST'));
2248 $date = get_var('date',array('GET','POST'));
2249 $notes = get_var('notes',array('GET','POST'));
2251 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
2252 $this->db->query($sql,__LINE__,__FILE__);
2253 while ($this->db->next_record())
2255 $supervisor = $this->db->f('supervisor');
2256 $sql = "SELECT * FROM eq_elder WHERE elder=" . $supervisor;
2257 $this->db2->query($sql,__LINE__,__FILE__);
2258 $this->db2->next_record();
2259 $interviewer_name = $this->db2->f('name');
2261 if($supervisor == $interviewer) {
2262 $this->t->set_var('interviewer',$supervisor . ' selected');
2264 $this->t->set_var('interviewer',$interviewer);
2266 $this->t->set_var('interviewer_name',$interviewer_name);
2267 $this->t->fp('int_list','interviewer_list',True);
2270 if($action == 'save')
2272 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
2273 $this->db->query("UPDATE eq_interview set " .
2274 " interview='" . $interview . "'" .
2275 ", interviewer='" . $interviewer . "'" .
2276 ", elder='" . $elder . "'" .
2277 ", aaronic='" . $aaronic . "'" .
2278 ", date='" . $date . "'" .
2279 ", notes='" . $notes . "'" .
2280 " WHERE interview=" . $interview,__LINE__,__FILE__);
2285 if($action == 'insert')
2287 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
2288 $this->db->query("INSERT INTO eq_interview (interviewer,elder,aaronic,date,notes) "
2289 . "VALUES ('" . $interviewer . "','" . $elder . "','" . $aaronic . "','"
2290 . $date . "','" . $notes ."')",__LINE__,__FILE__);
2295 if($action == 'add')
2297 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2298 $this->t->set_var('interview', '');
2299 $this->t->set_var('interviewer', $interviewer);
2300 $this->t->set_var('name',$name);
2301 $this->t->set_var('elder',$elder);
2302 $this->t->set_var('aaronic',$aaronic);
2303 $this->t->set_var('date','');
2304 $this->t->set_var('notes','');
2305 $this->t->set_var('lang_done','Cancel');
2306 $this->t->set_var('lang_action','Adding New Interview');
2307 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_update&interview='
2308 . $interview . '&action=' . 'insert'));
2311 if($action == 'edit' || $action == 'view')
2313 $sql = "SELECT * FROM eq_interview WHERE interview=".$interview;
2314 $this->db->query($sql,__LINE__,__FILE__);
2315 $this->db->next_record();
2316 $this->t->set_var('interview',$interview);
2317 $this->t->set_var('name',$name);
2318 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2319 $this->t->set_var('elder',$this->db->f('elder'));
2320 $this->t->set_var('aaronic',$this->db->f('aaronic'));
2321 $this->t->set_var('date',$this->db->f('date'));
2322 $this->t->set_var('notes',$this->db->f('notes'));
2325 if($action == 'edit')
2327 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2328 $this->t->set_var('lang_done','Cancel');
2329 $this->t->set_var('lang_action','Editing Interview');
2330 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_update&interview='
2331 . $interview . '&action=' . 'save'));
2334 if($action == 'view')
2336 $date = $this->db->f('date');
2337 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2338 $this->t->set_var('readonly','READONLY');
2339 $this->t->set_var('disabled','DISABLED');
2340 $this->t->set_var('lang_done','Done');
2341 $this->t->set_var('lang_action','Viewing Interview');
2342 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_update&interview='
2343 . $interview . '&action=' . 'edit'));
2346 $this->t->set_var('lang_reset','Clear Form');
2347 $this->t->set_var('lang_add','Add Interview');
2348 $this->t->set_var('lang_save','Save Changes');
2349 $this->t->set_var('edithandle','');
2350 $this->t->set_var('addhandle','');
2352 $this->t->pfp('out','form');
2354 if($action == 'view') { $this->t->set_var('lang_save','Edit Interview'); }
2355 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2356 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2358 $this->save_sessiondata();
2363 $this->t->set_file(array('vis_view_t' => 'vis_view.tpl'));
2364 $this->t->set_block('vis_view_t','visit_list','list1');
2365 $this->t->set_block('vis_view_t','family_list','list2');
2367 $this->t->set_var('lang_name','Family Name');
2368 $this->t->set_var('lang_date','Date');
2370 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
2371 $this->t->set_var('vis_link_title','View Yearly Visits');
2373 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched'));
2374 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2377 $sql = "SELECT * FROM eq_visit WHERE companionship=0 ORDER BY date DESC";
2378 $this->db->query($sql,__LINE__,__FILE__);
2379 $total_records = $this->db->num_rows();
2382 while ($this->db->next_record())
2384 $visit_list[$i]['visit'] = $this->db->f('visit');
2385 $visit_list[$i]['family'] = $this->db->f('family');
2386 $visit_list[$i]['date'] = $this->db->f('date');
2390 for ($i=0; $i < count($visit_list); $i++)
2392 $this->nextmatchs->template_alternate_row_color(&$this->t);
2394 $sql = "SELECT * FROM eq_family WHERE family=".$visit_list[$i]['family'];
2395 $this->db->query($sql,__LINE__,__FILE__);
2396 $this->db->next_record();
2398 $this->t->set_var('family',$visit_list[$i]['family']);
2399 $this->t->set_var('family_name',$this->db->f('name'));
2400 $this->t->set_var('date',$visit_list[$i]['date']);
2402 $link_data['menuaction'] = 'eq.eq.vis_update';
2403 $link_data['visit'] = $visit_list[$i]['visit'];
2404 $link_data['name'] = $this->db->f('name');
2405 $link_data['date'] = $visit_list[$i]['date'];
2406 $link_data['action'] = 'view';
2407 $this->t->set_var('view',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
2408 $this->t->set_var('lang_view','View');
2410 $link_data['menuaction'] = 'eq.eq.vis_update';
2411 $link_data['visit'] = $visit_list[$i]['visit'];
2412 $link_data['name'] = $this->db->f('name');
2413 $link_data['date'] = $visit_list[$i]['date'];
2414 $link_data['action'] = 'edit';
2415 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
2416 $this->t->set_var('lang_edit','Edit');
2418 $this->t->fp('list1','visit_list',True);
2421 // List the families that are available to record a visit against
2422 $sql = "SELECT * FROM eq_family WHERE valid=1";
2423 $this->db->query($sql,__LINE__,__FILE__);
2424 $total_records = $this->db->num_rows();
2427 while ($this->db->next_record())
2429 $family_names[$i] = $this->db->f('name');
2430 $family_ids[$i] = $this->db->f('family');
2432 } array_multisort($family_names, $family_ids);
2434 for ($i=0; $i < count($family_names); $i++)
2436 $link_data['menuaction'] = 'eq.eq.vis_update';
2437 $link_data['visit'] = '';
2438 $link_data['family'] = $family_ids[$i];
2439 $link_data['action'] = 'add';
2440 $link_data['name'] = $family_names[$i];
2441 $this->t->set_var('add',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
2443 $this->t->set_var('name',$family_names[$i]);
2444 if(($i+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
2445 else { $this->t->set_var('table_sep',"</td>"); }
2446 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
2448 $this->t->fp('list2','family_list',True);
2451 $this->t->pfp('out','vis_view_t');
2452 $this->save_sessiondata();
2455 function vis_update()
2457 $this->t->set_file(array('form' => 'vis_update.tpl'));
2458 $this->t->set_block('form','add','addhandle');
2459 $this->t->set_block('form','edit','edithandle');
2461 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
2462 $this->t->set_var('readonly','');
2463 $this->t->set_var('disabled','');
2465 $action = get_var('action',array('GET','POST'));
2466 $visit = get_var('visit',array('GET','POST'));
2467 $family = get_var('family',array('GET','POST'));
2468 $name = get_var('name',array('GET','POST'));
2469 $date = get_var('date',array('GET','POST'));
2470 $notes = get_var('notes',array('GET','POST'));
2473 if($action == 'save')
2475 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
2476 $this->db->query("UPDATE eq_visit set " .
2477 " date='" . $date . "'" .
2478 ", notes='" . $notes . "'" .
2479 " WHERE visit=" . $visit,__LINE__,__FILE__);
2484 if($action == 'insert')
2486 $notes = $this->db->db_addslashes(get_var('notes',array('POST')));
2487 $this->db->query("INSERT INTO eq_visit (family,companionship,date,notes) "
2488 . "VALUES ('" . $family . "','" . $companionship . "','"
2489 . $date . "','" . $notes . "')",__LINE__,__FILE__);
2494 if($action == 'add')
2496 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2497 $this->t->set_var('family', $family);
2498 $this->t->set_var('visit', '');
2499 $this->t->set_var('name', $name);
2500 $this->t->set_var('date','');
2501 $this->t->set_var('notes','');
2502 $this->t->set_var('lang_done','Cancel');
2503 $this->t->set_var('lang_action','Adding New Visit');
2504 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&family='
2505 . $family . '&action=' . 'insert'));
2508 if($action == 'edit' || $action == 'view')
2510 $sql = "SELECT * FROM eq_visit WHERE visit=".$visit;
2511 $this->db->query($sql,__LINE__,__FILE__);
2512 $this->db->next_record();
2513 $this->t->set_var('visit',$visit);
2514 $this->t->set_var('name',$name);
2515 $this->t->set_var('family', $family);
2516 $this->t->set_var('date',$this->db->f('date'));
2517 $this->t->set_var('notes',$this->db->f('notes'));
2520 if($action == 'edit')
2522 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2523 $this->t->set_var('lang_done','Cancel');
2524 $this->t->set_var('lang_action','Editing Visit');
2525 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&visit='
2526 . $visit . '&action=' . 'save'));
2529 if($action == 'view')
2531 $date = $this->db->f('date');
2532 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2533 $this->t->set_var('readonly','READONLY');
2534 $this->t->set_var('disabled','DISABLED');
2535 $this->t->set_var('lang_done','Done');
2536 $this->t->set_var('lang_action','Viewing Visit');
2537 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&visit='
2538 . $visit . '&action=' . 'edit'));
2541 $this->t->set_var('lang_reset','Clear Form');
2542 $this->t->set_var('lang_add','Add Visit');
2543 $this->t->set_var('lang_save','Save Changes');
2544 $this->t->set_var('edithandle','');
2545 $this->t->set_var('addhandle','');
2547 $this->t->pfp('out','form');
2549 if($action == 'view') { $this->t->set_var('lang_save','Edit Visit'); }
2550 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2551 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2553 $this->save_sessiondata();
2558 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
2559 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
2560 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
2562 $this->t->set_file(array('att_view_t' => 'att_view.tpl'));
2563 $this->t->set_block('att_view_t','act_list','list');
2565 $this->t->set_block('att_view_t','month_list','list1');
2566 $this->t->set_block('att_view_t','header_list','list2');
2567 $this->t->set_block('att_view_t','elder_list','list3');
2569 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_view'));
2570 $num_months = get_var('num_months',array('GET','POST'));
2571 if($num_months == '') { $num_months = $this->default_att_num_months; }
2572 $this->t->set_var('num_months',$num_months);
2573 $this->t->set_var('lang_filter','Filter');
2574 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
2575 else { $this->t->set_var('lang_num_months','Months of History'); }
2577 $sql = "SELECT * FROM eq_elder where valid=1";
2578 $this->db->query($sql,__LINE__,__FILE__);
2580 while ($this->db->next_record())
2582 $elder_name[$i] = $this->db->f('name');
2583 $elder_id[$i] = $this->db->f('elder');
2586 array_multisort($elder_name, $elder_id);
2589 // Create a list of sunday dates for a window of 3 months back and current month
2593 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, date("m")-$num_months, 1, date("y")));
2594 $last_date = explode("-",$sunday_list[0]['date']);
2595 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
2596 $time_limit = mktime(0, 0, 0, date("m"), date("t"), date("y"));
2597 while($last_time < $time_limit)
2599 $day = date("w",$last_time);
2600 if(date("w",$last_time) == 0) {
2601 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
2602 $last_date = explode("-",$sunday_list[$i]['date']);
2603 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
2604 $sunday_list[$i]['day'] = $last_date[2];
2605 $sunday_list[$i]['month'] = date("M",$last_time);
2606 $sunday_list[$i]['year'] = $last_date[0];
2609 $last_time += 90000;
2610 if($found_sunday) { $i++; $found_sunday=0; }
2613 $total_elders = count($elder_id);
2614 $old_month=$sunday_list[0]['month']; $span=0;
2615 for ($i=0; $i < count($sunday_list); $i++) {
2616 $date = $sunday_list[$i]['date'];
2617 $this->t->set_var('date',$sunday_list[$i]['date']);
2618 $this->t->set_var('day',$sunday_list[$i]['day']);
2619 if(($old_month != $sunday_list[$i]['month']) || $i == count($sunday_list)-1) {
2620 if($i == count($sunday_list)-1) { $span++; }
2621 $cur_month = $sunday_list[$i]['month'];
2622 $old_month = $sunday_list[$i]['month'];
2623 $link_data['menuaction'] = 'eq.eq.att_update';
2624 $link_data['month'] = $sunday_list[$i-1]['month'];
2625 $link_data['year'] = $sunday_list[$i-1]['year'];
2626 $link_data['action'] = 'update_month';
2627 $cur_month = $sunday_list[$i-1]['month'];
2628 $cur_year = $sunday_list[$i-1]['year'];
2629 $header_row .= "<th><font size=-3>$cur_month $cur_year</font></th>";
2630 $this->t->set_var('update_month',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
2631 $this->t->set_var('month',$sunday_list[$i-1]['month']);
2632 $this->t->set_var('year',$sunday_list[$i-1]['year']);
2633 $this->t->set_var('span',$span); $span=0;
2634 $this->t->fp('list1','month_list',True);
2637 $this->t->set_var('total_elders',$total_elders);
2638 $this->t->set_var('header_row',$header_row);
2640 $elder_width=200; $att_width=25; $total_width=$elder_width;
2641 for ($i=0; $i < count($sunday_list); $i++) {
2642 $link_data['menuaction'] = 'eq.eq.att_update';
2643 $link_data['month'] = $sunday_list[$i]['month'];
2644 $link_data['year'] = $sunday_list[$i]['year'];
2645 $link_data['day'] = $sunday_list[$i]['day'];
2646 $link_data['date'] = $sunday_list[$i]['date'];
2647 $link_data['action'] = 'update_day';
2648 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
2649 $this->t->set_var('date',$sunday_list[$i]['date']);
2650 $this->t->set_var('day',$sunday_list[$i]['day']);
2651 $this->t->set_var('month',$sunday_list[$i]['month']);
2652 $this->t->set_var('year',$sunday_list[$i]['year']);
2653 $this->t->fp('list2','header_list',True);
2654 $total_width += $att_width;
2655 $attendance[$monthnum[$sunday_list[$i]['month']]]=0;
2658 for ($i=0; $i < count($elder_id); $i++) {
2660 $this->nextmatchs->template_alternate_row_color(&$this->t);
2661 $this->t->set_var('elder_name',$elder_name[$i]);
2662 #print "checking for elder: " . $elder_id[$i] . "<br>";
2663 for ($j=0; $j < count($sunday_list); $j++) {
2664 #print "checking for date: " . $sunday_list[$j]['date'] . "<br>";
2665 #print "SELECT * FROM eq_attendance WHERE date='"
2666 # . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i] . "<br>";
2667 $sql = "SELECT * FROM eq_attendance WHERE date='"
2668 . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i];
2669 $this->db->query($sql,__LINE__,__FILE__);
2670 if($this->db->next_record()) {
2671 $cur_month = $sunday_list[$j]['month'];
2672 if($attended[$i][$cur_month] != 1) {
2673 $attended[$i][$cur_month]=1;
2674 $attendance[$monthnum[$cur_month]]++;
2676 $att_table .= '<td align=center><img src="checkmark.gif"></td>';
2678 $att_table .= '<td> </td>';
2681 $this->t->set_var('att_table',$att_table);
2682 $this->t->fp('list3','elder_list',True);
2684 $this->t->set_var('total_width',$total_width);
2685 $this->t->set_var('elder_width',$elder_width);
2686 $this->t->set_var('att_width',$att_width);
2688 # Now calculate attendance for these months
2689 $attendance_str = "";
2690 $nonattendance_str = "";
2691 $aveattendance_str = "";
2692 $avenonattendance_str = "";
2694 $ave_total_attended=0;
2696 foreach($attendance as $att => $value) {
2697 $total_attended = $attendance[$att];
2698 $ave_total_attended += $attendance[$att]; $num_months++;
2699 $percent = ceil(($total_attended / $total_elders)*100);
2700 $attendance_str.="<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
2701 $total_nonattended = $total_elders - $total_attended;
2702 $percent = ceil(($total_nonattended / $total_elders)*100);
2703 $nonattendance_str.="<td align=center><font size=-2><b>$total_nonattended ($percent%)</b></font></td>";
2705 $total_attended = ceil(($ave_total_attended / $num_months));
2706 $percent = ceil(($total_attended / $total_elders)*100);
2707 $aveattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
2708 $total_attended = $total_elders - ceil(($ave_total_attended / $num_months));
2709 $percent = ceil(($total_attended / $total_elders)*100);
2710 $avenonattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
2713 $this->t->set_var('attendance',$attendance_str);
2714 $this->t->set_var('aveattendance',$aveattendance_str);
2715 $this->t->set_var('nonattendance',$nonattendance_str);
2716 $this->t->set_var('avenonattendance',$avenonattendance_str);
2718 $this->t->pfp('out','att_view_t');
2719 $this->save_sessiondata();
2722 function att_update()
2724 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
2725 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
2726 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
2728 $this->t->set_file(array('form' => 'att_update.tpl'));
2729 $this->t->set_block('form','edit','edithandle');
2731 $this->t->set_block('form','month_list','list1');
2732 $this->t->set_block('form','header_list','list2');
2733 $this->t->set_block('form','elder_list','list3');
2735 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_view'));
2737 $action = get_var('action',array('GET','POST'));
2738 $month = get_var('month',array('GET','POST'));
2739 $year = get_var('year',array('GET','POST'));
2740 $day = get_var('day',array('GET','POST'));
2741 $date = get_var('date',array('GET','POST'));
2743 if($action == 'save_month' || $action == 'save_day')
2745 $new_data = get_var('elders_attended',array('POST'));
2746 $month = $monthnum[$month]; if($month < 10) { $month = "0" . $month; }
2748 if($action == 'save_month') {
2749 $this->db->query("DELETE from eq_attendance where date LIKE '".$year."-".$month."-%'",__LINE__,__FILE__);
2752 if($action == 'save_day') {
2753 $this->db->query("DELETE from eq_attendance where date LIKE '".$year."-".$month."-".$day."'",__LINE__,__FILE__);
2756 foreach ($new_data as $data)
2758 $data_array = explode("-",$data);
2759 $elder = $data_array[0];
2760 $date = "$data_array[1]-$data_array[2]-$data_array[3]";
2761 $this->db->query("INSERT INTO eq_attendance (elder,date) "
2762 . "VALUES (" . $elder . ",'". $date . "')",__LINE__,__FILE__);
2769 $sql = "SELECT * FROM eq_elder where valid=1";
2770 $this->db->query($sql,__LINE__,__FILE__);
2772 while ($this->db->next_record())
2774 $elder_name[$i] = $this->db->f('name');
2775 $elder_id[$i] = $this->db->f('elder');
2778 array_multisort($elder_name, $elder_id);
2780 if($action == 'update_month')
2782 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_update&action=save_month'));
2786 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], 1, $year));
2787 $last_date = explode("-",$sunday_list[0]['date']);
2788 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
2789 $time_limit = mktime(0, 0, 0, $monthnum[$month], 31, $year);
2790 while($last_time <= $time_limit)
2792 $day = date("w",$last_time);
2793 if(date("w",$last_time) == 0) {
2794 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
2795 $last_date = explode("-",$sunday_list[$i]['date']);
2796 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
2797 $sunday_list[$i]['day'] = $last_date[2];
2798 $sunday_list[$i]['month'] = date("M",$last_time);
2799 $sunday_list[$i]['year'] = $last_date[0];
2802 $last_time += 90000;
2803 if($found_sunday) { $i++; $found_sunday=0; }
2806 $this->t->set_var('span', $i);
2807 $this->t->set_var('month',$sunday_list[$i-1]['month']);
2808 $this->t->set_var('year',$sunday_list[$i-1]['year']);
2809 $this->t->fp('list1','month_list',True);
2810 $elder_width=200; $att_width=25; $total_width=$elder_width;
2811 for ($i=0; $i < count($sunday_list); $i++) {
2812 $link_data['menuaction'] = 'eq.eq.att_update';
2813 $link_data['month'] = $sunday_list[$i]['month'];
2814 $link_data['year'] = $sunday_list[$i]['year'];
2815 $link_data['day'] = $sunday_list[$i]['day'];
2816 $link_data['date'] = $sunday_list[$i]['date'];
2817 $link_data['action'] = 'update_day';
2818 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
2819 $this->t->set_var('date',$sunday_list[$i]['date']);
2820 $this->t->set_var('day',$sunday_list[$i]['day']);
2821 $this->t->set_var('month',$sunday_list[$i]['month']);
2822 $this->t->set_var('year',$sunday_list[$i]['year']);
2823 $this->t->fp('list2','header_list',True);
2824 $total_width += $att_width;
2828 if($action == 'update_day')
2830 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_update&action=save_day'));
2831 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], $day, $year));
2832 $this->t->set_var('month',$month);
2833 $this->t->set_var('year',$year);
2834 $this->t->fp('list1','month_list',True);
2835 $this->t->set_var('date',$date);
2836 $this->t->set_var('day',$day);
2837 $this->t->set_var('month',$month);
2838 $this->t->set_var('year',$year);
2839 $this->t->fp('list2','header_list',True);
2842 for ($i=0; $i < count($elder_id); $i++) {
2844 $this->nextmatchs->template_alternate_row_color(&$this->t);
2845 $this->t->set_var('elder_name',$elder_name[$i]);
2846 for ($j=0; $j < count($sunday_list); $j++) {
2847 $sql = "SELECT * FROM eq_attendance WHERE date='"
2848 . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i];
2849 $this->db->query($sql,__LINE__,__FILE__);
2850 $value = $elder_id[$i] . "-" . $sunday_list[$j]['date'];
2851 if($this->db->next_record()) {
2852 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'" checked></td>';
2854 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'"></td>';
2857 $this->t->set_var('att_table',$att_table);
2858 $this->t->fp('list3','elder_list',True);
2861 $this->t->set_var('lang_done', 'Cancel');
2862 $this->t->set_var('lang_reset','Clear Form');
2863 $this->t->set_var('lang_save','Save Changes');
2865 $this->t->pfp('out','form');
2866 $this->t->pfp('addhandle','edit');
2868 $this->save_sessiondata();
2873 $this->t->set_file(array('dir_view_t' => 'dir_view.tpl'));
2874 $this->t->set_block('dir_view_t','dir_list','list');
2876 $sql = "SELECT * FROM eq_parent where valid=1 ORDER BY name ASC";
2877 $this->db->query($sql,__LINE__,__FILE__);
2879 while ($this->db->next_record())
2881 $parent[$i]['id'] = $this->db->f('parent');
2882 $parent[$i]['name'] = $this->db->f('name');
2883 $parent[$i]['phone'] = $this->db->f('phone');
2884 $parent[$i]['address'] = $this->db->f('address');
2888 for ($i=0; $i < count($parent); $i++)
2890 $name = $parent[$i]['name'];
2891 $phone = $parent[$i]['phone'];
2892 $address = $parent[$i]['address'];
2893 $this->t->set_var('name', $name);
2894 $this->t->set_var('address', $address);
2895 $this->t->set_var('phone', $phone);
2896 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2897 $this->t->set_var('tr_color',$tr_color);
2898 $this->t->fp('list','dir_list',True);
2899 //print "$phone $name $address<br>";
2901 $this->t->pfp('out','dir_view_t');
2902 $this->save_sessiondata();
2907 $this->t->set_file(array('org_view_t' => 'org_view.tpl'));
2908 $this->t->set_block('org_view_t','calling_list','list1');
2909 $this->t->set_block('org_view_t','org_list','list2');
2911 # Display a list ordered alphabetically
2912 $sql = "SELECT * FROM eq_calling ORDER BY name ASC";
2913 $this->db->query($sql,__LINE__,__FILE__);
2915 while ($this->db->next_record())
2917 $calling[$i]['id'] = $this->db->f('indiv_id');
2918 $calling[$i]['name'] = $this->db->f('name');
2919 $calling[$i]['position'] = $this->db->f('position');
2920 $calling[$i]['sustained'] = $this->db->f('sustained');
2921 $calling[$i]['organization'] = $this->db->f('organization');
2924 for ($i=0; $i < count($calling); $i++)
2926 $name = $calling[$i]['name'];
2927 $position = $calling[$i]['position'];
2928 $sustained = $calling[$i]['sustained'];
2929 $organization = $calling[$i]['organization'];
2930 $this->t->set_var('name', $name);
2931 $this->t->set_var('position', $position);
2932 $this->t->set_var('sustained', $sustained);
2933 $this->t->set_var('organization', $organization);
2934 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2935 $this->t->set_var('tr_color',$tr_color);
2936 $this->t->fp('list1','calling_list',True);
2939 # Display a list ordered by organization
2940 $sql = "SELECT * FROM eq_calling ORDER BY sequence ASC";
2941 $this->db->query($sql,__LINE__,__FILE__);
2943 while ($this->db->next_record())
2945 $calling[$i]['id'] = $this->db->f('indiv_id');
2946 $calling[$i]['name'] = $this->db->f('name');
2947 $calling[$i]['position'] = $this->db->f('position');
2948 $calling[$i]['sustained'] = $this->db->f('sustained');
2949 $calling[$i]['organization'] = $this->db->f('organization');
2952 for ($i=0; $i < count($calling); $i++)
2954 $name = $calling[$i]['name'];
2955 $position = $calling[$i]['position'];
2956 $sustained = $calling[$i]['sustained'];
2957 $organization = $calling[$i]['organization'];
2958 $this->t->set_var('name', $name);
2959 $this->t->set_var('position', $position);
2960 $this->t->set_var('sustained', $sustained);
2961 $this->t->set_var('organization', $organization);
2962 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2963 $this->t->set_var('tr_color',$tr_color);
2964 $this->t->fp('list2','org_list',True);
2967 $this->t->pfp('out','org_view_t');
2968 $this->save_sessiondata();
2973 $this->t->set_file(array('sched_t' => 'schedule.tpl'));
2974 $this->t->set_block('sched_t','presidency_list','list');
2976 $action = get_var('action',array('GET','POST'));
2978 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.schedule&action=save'));
2979 $this->t->set_var('title','EQ Scheduling Tool');
2981 $this->t->set_var('lang_save','Save Schedule');
2982 $this->t->set_var('lang_reset','Cancel');
2984 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched'));
2985 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2987 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_sched'));
2988 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
2990 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched'));
2991 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
2993 $date_width=150; $time_width=200; $elder_width=200; $family_width=200;
2994 $table_width=$date_width + $time_width + $elder_width + $family_width;
2995 $header_row = "<th width=$date_width><font size=-2>Date</th>";
2996 $header_row.= "<th width=$time_width><font size=-2>Time</th>";
2997 $header_row.= "<th width=$elder_width><font size=-2>Elder</th>";
2998 $header_row.= "<th width=$family_width><font size=-2>Family</th>";
3001 if($action == 'save')
3003 $new_data = get_var('sched',array('POST'));
3004 foreach ($new_data as $presidency_array)
3006 foreach ($presidency_array as $entry)
3008 $presidency = $entry['presidency'];
3009 $appointment = $entry['appointment'];
3010 $date = $entry['date'];
3011 $hour = $entry['hour'];
3012 $minute = $entry['minute'];
3014 $elder = $entry['elder'];
3015 $family = $entry['family'];
3016 if($pm) { $hour = $hour + 12; }
3017 $time = $hour.':'.$minute.':'.'00';
3019 // Update an existing appointment
3020 if($appointment != 0)
3022 $this->db->query("UPDATE eq_appointment set" .
3023 " family=" . $family .
3024 " ,elder=" . $elder .
3025 " ,date='" . $date . "'" .
3026 " ,time='" . $time . "'" .
3027 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
3029 //print "updating entry: appt=$appointment date: $date time: $time elder: $elder family: $family<br>";
3032 // Add a new appointment
3033 else if(($appointment == 0) && ($date != "") && ($time != ""))
3035 $this->db->query("INSERT INTO eq_appointment (appointment,presidency,family,elder,date,time) "
3036 . "VALUES ('" . $appointment . "','" . $presidency . "','" . $family . "','"
3037 . $elder . "','" . $date . "','" . $time ."')",__LINE__,__FILE__);
3039 //print "adding entry: appt=$appointment date: $date time: $time elder: $elder family: $family<br>";
3044 $take_me_to_url = $GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.schedule');
3045 Header('Location: ' . $take_me_to_url);
3048 $sql = "SELECT * FROM eq_presidency where valid=1";
3049 $this->db->query($sql,__LINE__,__FILE__);
3051 while ($this->db->next_record())
3053 $presidency_data[$i]['id'] = $this->db->f('presidency');
3054 $presidency_data[$i]['name'] = $this->db->f('name');
3055 $presidency_data[$i]['elder'] = $this->db->f('elder');
3059 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
3060 $this->db->query($sql,__LINE__,__FILE__);
3062 while ($this->db->next_record())
3064 $elder_id[$i] = $this->db->f('elder');
3065 $elder_name[$i] = $this->db->f('name');
3066 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
3069 array_multisort($elder_name, $elder_id);
3071 $sql = "SELECT * FROM eq_family where valid=1 and elder_id != 0 ORDER BY name ASC";
3072 $this->db->query($sql,__LINE__,__FILE__);
3074 while ($this->db->next_record())
3076 $family_id[$i] = $this->db->f('family');
3077 $family_name[$i] = $this->db->f('name');
3080 array_multisort($family_name, $family_id);
3082 for ($i=0; $i < count($presidency_data); $i++) {
3083 $presidency = $presidency_data[$i]['id'];
3084 $interviewer = $presidency_data[$i]['elder'];
3085 $name = $presidency_data[$i]['name'];
3086 $this->t->set_var('presidency_name',$name);
3089 // query the database for all the appointments
3090 $sql = "SELECT * FROM eq_appointment where presidency=$presidency and date>=CURDATE() ORDER BY date ASC, time ASC";
3091 $this->db->query($sql,__LINE__,__FILE__);
3093 // Prefill any existing appointment slots
3094 while ($this->db->next_record())
3096 $appointment = $this->db->f('appointment');
3097 $elder = $this->db->f('elder');
3098 $family = $this->db->f('family');
3100 $date = $this->db->f('date');
3101 $date_array = explode("-",$date);
3102 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
3103 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
3105 $time = $this->db->f('time');
3106 $time_array = explode(":",$time);
3107 $hour = $time_array[0];
3108 $minute = $time_array[1];
3110 if($hour > 12) { $pm=1; $hour = $hour - 12; }
3111 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
3113 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3116 $table_data.= '<td align=left>';
3117 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]',$date,'','','','','',$this->cal_options);
3118 $table_data.= '</td>';
3120 // Hour & Minutes selection
3121 $table_data.= "<td align=center>";
3122 $table_data.= '<select name=sched['.$presidency.']['.$appointment.'][hour]>';
3123 foreach(range(1,12) as $num) {
3124 if($hour == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
3125 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
3127 $table_data.= '</select>';
3128 $table_data.= ' : ';
3129 $table_data.= '<select name=sched['.$presidency.']['.$appointment.'][minute]>';
3130 foreach(range(0,3) as $num) {
3131 $num = $num * 15; if($num == 0) { $num = "00"; }
3132 if($minute == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
3133 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
3135 $table_data.= '</select>';
3136 $table_data.= '<select name=sched['.$presidency.']['.$appointment.'][pm]>';
3137 if($pm == 0) { $table_data.= '<option value=0 selected>am</option>'; $table_data.= '<option value=1>pm</option>'; }
3138 else { $table_data.= '<option value=0>am</option>'; $table_data.= '<option value=1 selected>pm</option>'; }
3139 $table_data.= '</select>';
3140 $table_data.= "</td>";
3142 // Elder drop down list (for PPIs)
3143 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][elder]>';
3144 $table_data.= '<option value=0></option>';
3145 for ($j=0; $j < count($elder_id); $j++) {
3146 $id = $elder_id[$j];
3147 $name = $elder_name[$j];
3148 if($elder_id[$j] == $elder) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
3149 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
3151 $table_data.='</select></td>';
3153 // Family drop down list (for Visits)
3154 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family]>';
3155 $table_data.= '<option value=0></option>';
3156 for ($j=0; $j < count($elder_id); $j++) {
3157 $id = $family_id[$j];
3158 $name = $family_name[$j];
3159 if($family_id[$j] == $family) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
3160 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
3162 $table_data.='</select></td>';
3164 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3165 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3167 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3168 $this->t->set_var('tr_color',$tr_color);
3172 // Create blank appointment slot
3174 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3177 $table_data.= '<td align=left>';
3178 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]','','','','','','',$this->cal_options);
3179 $table_data.= '</td>';
3182 $table_data.= "<td align=center>";
3183 $table_data.= '<select name=sched['.$presidency.']['.$appointment.'][hour]>';
3184 $table_data.= '<option value=""></option>';
3185 foreach(range(1,12) as $num) {
3186 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
3188 $table_data.= '</select>';
3189 $table_data.= ' : ';
3190 $table_data.= '<select name=sched['.$presidency.']['.$appointment.'][minute]>';
3191 $table_data.= '<option value=""></option>';
3192 foreach(range(0,3) as $num) {
3193 $num = $num * 15; if($num == 0) { $num = "00"; }
3194 $table_data.= '<option value='.$num.'>'.$num.'</option>';
3196 $table_data.= '</select>';
3197 $table_data.= '<select name=sched['.$presidency.']['.$appointment.'][pm]>';
3198 $table_data.= '<option value=""></option>';
3199 $table_data.= '<option value=0>am</option>';
3200 $table_data.= '<option value=1>pm</option>';
3201 $table_data.= '</select>';
3202 $table_data.= "</td>";
3204 // Elder drop down list
3205 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][elder]>';
3206 $table_data.= '<option value=0></option>';
3207 for ($j=0; $j < count($elder_id); $j++) {
3208 $id = $elder_id[$j];
3209 $name = $elder_name[$j];
3210 $table_data.= '<option value='.$id.'>'.$name.'</option>';
3212 $table_data.='</select></td>';
3214 // Family drop down list
3215 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family]>';
3216 $table_data.= '<option value=0></option>';
3217 for ($j=0; $j < count($elder_id); $j++) {
3218 $id = $family_id[$j];
3219 $name = $family_name[$j];
3220 $table_data.= '<option value='.$id.'>'.$name.' Family</option>';
3222 $table_data.='</select></td>';
3224 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3225 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3227 $this->t->set_var('table_data',$table_data);
3228 $this->t->set_var('header_row',$header_row);
3229 $this->t->set_var('table_width',$table_width);
3230 $this->t->fp('list','presidency_list',True);
3234 $this->t->pfp('out','sched_t');
3235 $this->save_sessiondata();
3240 $this->t->set_file(array('admin_t' => 'admin.tpl'));
3241 $this->t->set_block('admin_t','upload','uploadhandle');
3242 $this->t->set_block('admin_t','admin','adminhandle');
3243 $this->t->set_block('admin_t','cmd','cmdhandle');
3245 $this->t->set_var('upload_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.admin&action=upload'));
3247 $action = get_var('action',array('GET','POST'));
3249 $this->t->pfp('out','admin_t');
3251 if($action == 'upload')
3253 $target_path = $this->upload_target_path . basename( $_FILES['uploadedfile']['name']);
3255 if((($_FILES['uploadedfile']['type'] == "application/zip") ||
3256 ($_FILES['uploadedfile']['type'] == "application/x-zip-compressed") ||
3257 ($_FILES['uploadedfile']['type'] == "application/x-zip") ||
3258 ($_FILES['uploadedfile']['type'] == "application/octet-stream")) &&
3259 (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))) {
3260 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
3261 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
3262 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
3263 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
3264 $this->t->set_var('uploadstatus',$uploadstatus);
3265 $this->t->pfp('uploadhandle','upload');
3266 $this->t->set_var('uploadhandle','');
3267 print "<table border=1 width=80%><tr><td>\n<pre>";
3269 # make a directory for this data to be stored in
3270 $date="data_" . date("Y_m_d");
3271 $data_dir = $this->upload_target_path . $date;
3272 print "-> Making the data directory: $date<br>\n";
3273 exec('mkdir ' . $data_dir . ' 2>&1', $result, $return_code);
3274 if($return_code != 0) {
3275 print implode('\n',$result) . "<br>";
3276 print "<b><font color=red>";
3277 print "-E- Unable to create the data directory. Aborting import.";
3278 print "</font></b>";
3282 # move the file uploaded into this directory
3283 print "-> Moving the uploaded file into the data dir<br>\n";
3284 exec('mv ' . $target_path . ' ' . $data_dir . '/' . ' 2>&1', $result, $return_code);
3285 if($return_code != 0) {
3286 print implode('\n',$result) . "<br>";
3287 print "<b><font color=red>";
3288 print "-E- Unable to move the uploaded file into the data dir. Aborting import.";
3289 print "</font></b>";
3293 # unzip the data into this directory
3294 print "-> Unzipping the data<br>\n";
3295 $data_file = $data_dir . '';
3296 exec('unzip ' . $data_dir . '/*.zip -d ' . $data_dir . ' 2>&1', $result, $return_code);
3297 if($return_code != 0) {
3298 print implode('\n',$result) . "<br>";
3299 print "<b><font color=red>";
3300 print "-E- Unable to unzip the uploaded file into the data dir. Aborting import.";
3301 print "</font></b>";
3304 exec('mv ' . $data_dir . '/*/* '. $data_dir . ' 2>&1', $result, $return_code);
3306 # update the data_latest link to point to this new directory
3307 print "-> Updating the latest data dir link<br>\n";
3308 $data_latest = $this->upload_target_path . 'data_latest';
3309 exec('rm ' . $data_latest. '; ln -s ' . $data_dir .' '. $data_latest .' 2>&1', $result, $return_code);
3310 if($return_code != 0) {
3311 print implode('\n',$result) . "<br>";
3312 print "<b><font color=red>";
3313 print "-E- Unable to update the data latest link. Aborting import.";
3314 print "</font></b>";
3318 # run the import perl script to encorporate it into the DB
3319 ob_start('ob_logstdout', 2);
3320 print "-> Importing the data into the EQ database<br>\n";
3321 ob_flush(); flush(); sleep(1);
3322 $import_log = $this->upload_target_path . '/import.log';
3323 $data_log = $this->upload_target_path . '/data.log';
3324 $import_cmd = $this->script_path . 'import_ward_data ' . $data_latest . ' | tee ' . $import_log;
3325 $parse_cmd = $this->script_path . 'parse_ward_data -v ' . $data_latest . ' > ' . $data_log;
3326 #print "import_cmd: $import_cmd<br>";
3327 #print "parse_cmd: $parse_cmd<br>";
3328 ob_start('ob_logstdout', 2);
3329 passthru($import_cmd);
3330 passthru($parse_cmd);
3331 ob_flush(); flush(); sleep(1);
3333 # fix the permissions of the data dir
3334 exec('chmod -R o-rwx ' . $data_dir, $result, $return_code);
3336 $this->t->pfp('cmdhandle','cmd');
3337 print "</pre></td></tr></table>";
3339 } else if(($_FILES['uploadedfile']['type'] != "application/zip") &&
3340 ($_FILES['uploadedfile']['type'] != "application/x-zip-compressed") &&
3341 ($_FILES['uploadedfile']['type'] != "application/x-zip") &&
3342 ($_FILES['uploadedfile']['type'] != "application/octet-stream")) {
3343 $uploadstatus = "<b><font color=red>The file format must be a .zip file, please try again! </font></b>";
3344 $uploadstatus.= "<br><br><b>Detected file format: " . $_FILES['uploadedfile']['type'] . "</b>";
3345 $this->t->set_var('uploadstatus',$uploadstatus);
3346 $this->t->pfp('uploadhandle','upload',True);
3348 $uploadstatus = "<b><font color=red> There was an error (" . $_FILES['uploadedfile']['error'];
3349 $uploadstatus.= ") uploading the file, please try again! </font></b>";
3350 $this->t->set_var('uploadstatus',$uploadstatus);
3351 $this->t->pfp('uploadhandle','upload',True);
3356 $this->t->set_var('adminhandle','');
3357 $this->t->pfp('adminhandle','admin');
3360 $this->save_sessiondata();