2 /**************************************************************************\
3 * Application: phpGroupWare - eq *
4 * Framework: http://www.phpgroupware.org *
5 * Author: Alan J. Pippin (apippin@pippins.net) *
6 * ----------------------------------------------- *
7 * This program is free software; you can redistribute it and/or modify it *
8 * under the terms of the GNU General Public License as published by the *
9 * Free Software Foundation; either version 2 of the License, or (at your *
10 * option) any later version. *
11 \**************************************************************************/
12 /* $Id: class.eq.inc.php,v 1.1.1.1 2005/07/20 07:40:32 ajp Exp $ */
23 var $default_ht_num_months;
24 var $default_ppi_num_months;
25 var $default_ppi_num_years;
26 var $default_int_num_quarters;
27 var $default_int_num_years;
28 var $default_vis_num_years;
29 var $default_att_num_quarters;
30 var $max_num_districts;
33 var $upload_target_path;
35 var $max_appointments;
36 var $max_presidency_members;
38 var $public_functions = array
63 'willing_view' => True,
64 'willing_update' => True,
65 'send_ical_appt' => True,
66 'assign_view' => True,
67 'assign_update' => True,
68 'get_time_selection_form' => True,
73 if(file_exists("setup/eq_config.local")) {
74 include("setup/eq_config.local");
76 include("setup/eq_config");
79 $this->script_path = "$this->application_path"."/bin";
80 $this->max_presidency_members = 99;
81 $this->max_appointments = 32768;
83 $this->db = $GLOBALS['phpgw']->db;
84 $this->db2 = $this->db;
85 $this->db3 = $this->db;
86 $this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
87 $this->t = $GLOBALS['phpgw']->template;
88 $this->account = $GLOBALS['phpgw_info']['user']['account_id'];
89 $this->grants = $GLOBALS['phpgw']->acl->get_grants('eq');
90 $this->grants[$this->account] = PHPGW_ACL_READ + PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE;
92 $this->jscal = CreateObject('eq.jscalendar'); // before phpgw_header() !!!
93 $this->cal_options = 'daFormat : "%Y-%m-%d",
94 ifFormat : "%Y-%m-%d",
98 $GLOBALS['phpgw_info']['flags']['app_header'] = 'Elders Quorum Tools - The 3rd Counselor';
99 $GLOBALS['phpgw']->common->phpgw_header();
101 $this->current_day = `date '+%d'`;
102 $this->current_day = $this->current_day-0; // Make it numeric
103 $this->current_month = `date '+%m'`;
104 $this->current_month = $this->current_month-0; // Make it numeric
105 $this->current_year = `date '+%Y'`;
106 $this->current_year = $this->current_year-0; // Make it numeric
109 $this->display_app_header();
112 function save_sessiondata()
117 function display_app_header()
119 $this->t->set_file(array('eq_header' => 'header.tpl'));
121 if (isset($phpgw_info['user']['preferences']['eq']['eq_font']))
123 $font = $phpgw_info['user']['preferences']['eq']['eq_font'];
130 $this->t->set_var('bg_color',$phpgw_info['theme']['th_bg']);
131 $this->t->set_var('font',$font);
132 $link_data['menuaction'] = 'eq.eq.ht_view';
133 $this->t->set_var('link_hometeaching',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
134 $this->t->set_var('lang_hometeaching','HomeTeaching');
135 $link_data['menuaction'] = 'eq.eq.act_list';
136 $this->t->set_var('link_activity',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
137 $this->t->set_var('lang_activity','Activities');
138 $link_data['menuaction'] = 'eq.eq.willing_view';
139 $this->t->set_var('link_willing',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
140 $this->t->set_var('lang_willing','Willingness');
141 $link_data['menuaction'] = 'eq.eq.assign_view';
142 $this->t->set_var('link_assignment',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
143 $this->t->set_var('lang_assignment','Assignments');
144 $link_data['menuaction'] = 'eq.eq.par_view';
145 $this->t->set_var('link_participation',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
146 $this->t->set_var('lang_participation','Participation');
147 $link_data['menuaction'] = 'eq.eq.ppi_view';
148 $this->t->set_var('link_ppi',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
149 $this->t->set_var('lang_ppi','PPIs');
150 $link_data['menuaction'] = 'eq.eq.int_view';
151 $this->t->set_var('link_int',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
152 $this->t->set_var('lang_int','Interviews');
153 $link_data['menuaction'] = 'eq.eq.vis_view';
154 $this->t->set_var('link_visit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
155 $this->t->set_var('lang_visit','Visits');
156 $link_data['menuaction'] = 'eq.eq.att_view';
157 $this->t->set_var('link_attendance',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
158 $this->t->set_var('lang_attendance','Attendance');
159 $link_data['menuaction'] = 'eq.eq.dir_view';
160 $this->t->set_var('link_dir',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
161 $this->t->set_var('lang_dir','Directory');
162 $link_data['menuaction'] = 'eq.eq.org_view';
163 $this->t->set_var('link_org',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
164 $this->t->set_var('lang_org','Callings');
165 $link_data['menuaction'] = 'eq.eq.admin';
166 $this->t->set_var('link_admin',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
167 $this->t->set_var('lang_admin','Admin');
168 $link_data['menuaction'] = 'eq.eq.schedule';
169 $this->t->set_var('link_schedule',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
170 $this->t->set_var('lang_schedule','Scheduling');
171 $link_data['menuaction'] = 'eq.eq.email';
172 $this->t->set_var('link_email',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
173 $this->t->set_var('lang_email','Email');
175 $this->t->pparse('out','eq_header');
180 $this->t->set_file(array('ht_view_t' => 'ht_view.tpl'));
181 $this->t->set_block('ht_view_t','district_list','list');
183 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
184 $num_months = get_var('num_months',array('GET','POST'));
185 if($num_months == '') { $num_months = $this->default_ht_num_months; }
186 $this->t->set_var('num_months',$num_months);
187 $this->t->set_var('lang_filter','Filter');
188 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
189 else { $this->t->set_var('lang_num_months','Months of History'); }
191 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
192 $this->t->set_var('title','Hometeaching');
194 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
195 $this->db->query($sql,__LINE__,__FILE__);
197 while ($this->db->next_record())
199 $districts[$i]['district'] = $this->db->f('district');
200 $districts[$i]['name'] = $this->db->f('name');
201 $districts[$i]['supervisor'] = $this->db->f('supervisor');
205 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
206 $this->db->query($sql,__LINE__,__FILE__);
208 while ($this->db->next_record())
210 $elder_id[$i] = $this->db->f('elder');
211 $elder_name[$i] = $this->db->f('name');
212 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
215 array_multisort($elder_name, $elder_id);
217 // Make an array mapping elder_ids to elder_names
218 for($i=0; $i < count($elder_id); $i++) {
220 $elders[$id] = $elder_name[$i];
223 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
224 $this->db->query($sql,__LINE__,__FILE__);
225 while ($this->db->next_record())
227 $aaronic_id = $this->db->f('aaronic');
228 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
229 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
232 $this->nextmatchs->template_alternate_row_color(&$this->t);
233 for($m=$num_months; $m >= 0; $m--) { $total_families[$m]=0; }
234 for ($i=0; $i < count($districts); $i++) {
235 $this->t->set_var('district_number',$districts[$i]['district']);
236 $this->t->set_var('district_name',$districts[$i]['name']);
237 $supervisor = $districts[$i]['supervisor'];
238 $unique_companionships='';
240 // Select all the unique companionship numbers for this district
241 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $districts[$i]['district'];
242 $this->db->query($sql,__LINE__,__FILE__);
244 while ($this->db->next_record())
246 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
250 $comp_width=450; $visit_width=25; $table_width=$comp_width + $num_months*$visit_width;
251 $table_data=""; $num_companionships = 0;
252 for($m=$num_months; $m >= 0; $m--) { $visits[$m]=0; $num_families[$m]=0; }
253 for ($j=0; $j < count($unique_companionships); $j++) {
254 $companion_table_entry = "";
255 // Select all the companions in each companionship
256 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
257 "companionship=". $unique_companionships[$j]['companionship'];
258 $this->db->query($sql,__LINE__,__FILE__);
260 while ($this->db->next_record())
262 // Get this companions information
263 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
264 $companionship = $this->db->f('companionship');
265 $elder_id = $this->db->f('elder');
266 $aaronic_id = $this->db->f('aaronic');
268 $name = $elders[$elder_id];
269 $phone = $elder_phone[$elder_id];
271 else if($aaronic_id) {
272 $name = $aaronic[$aaronic_id]['name'];
273 $phone = $aaronic[$aaronic_id]['phone'];
275 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
277 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
279 // Get the names of the families assigned this home teaching companionship
280 $sql = "SELECT * from eq_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
281 $sql = $sql . " ORDER BY name ASC";
282 $this->db->query($sql,__LINE__,__FILE__);
284 while ($this->db->next_record())
286 $family_name = $this->db->f('name');
287 $family_id = $this->db->f('family');
288 $this->nextmatchs->template_alternate_row_color(&$this->t);
289 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
290 // Find out how many times Visits were performed by this companionship
291 // in the past $num_months for this Family
292 $header_row="<th width=$comp_width><font size=-2>Families</th>";
293 for($m=$num_months; $m >= 0; $m--) {
294 $month = $this->current_month - $m;
295 $year = $this->current_year;
296 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
297 if($month < 10) { $month = "0"."$month"; }
298 $month_start = "$year"."-"."$month"."-"."01";
299 $month_end = "$year"."-"."$month"."-"."31";
300 $month = "$month"."/"."$year";
302 //print "m: $m month: $month year: $year month_start: $month_start month_end: $month_end<br>";
303 // Add this to the query to filter on only visits made by this companionship:
304 // " AND companionship=" . $unique_companionships[$j]['companionship'].
306 // First check to see if the currently assigned companionship has visited them
307 $sql = "SELECT * FROM eq_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
308 " AND companionship=".$unique_companionships[$j]['companionship'].
309 " AND family=". $family_id;
310 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
311 if($this->db2->num_rows($query_id) == 0) {
312 // We did not find any visits made by the currently assigned companionship,
313 // look for visits made by any other companionship other than 0. (0 == EQ Presidency Visit)
314 $sql = "SELECT * FROM eq_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
315 " AND companionship!=0".
316 " AND family=". $family_id;
317 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
319 $this->db2->query($sql,__LINE__,__FILE__);
320 $link_data['menuaction'] = 'eq.eq.ht_update';
321 $link_data['date'] = $month_start;
322 $link_data['month_start'] = $month_start;
323 $link_data['month_end'] = $month_end;
324 $link_data['month'] = $month;
325 $link_data['district'] = $districts[$i]['district'];
326 $link_data['district_name'] = $districts[$i]['name'];
327 $link_data['action'] = 'view';
328 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
329 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
330 if(!$total_visits[$m]) { $total_visits[$m] = 0; }
331 if($this->db2->next_record()) {
332 if($this->db2->f('visited') == 'y') {
333 $visits[$m]++; $total_visits[$m]++;
334 $num_families[$m]++; $total_families[$m]++;
335 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/checkmark.gif"></a></td>';
337 else if($this->db2->f('visited') == 'n') {
338 $num_families[$m]++; $total_families[$m]++;
339 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/x.gif"></a></td>';
342 //$visits[$m]++; $total_visits[$m]++;
343 $table_data .= "<td> </td>";
347 //$visits[$m]++; $total_visits[$m]++;
348 $table_data .= "<td> </td>";
351 $table_data .= "</tr>";
354 $table_data .= "<tr><td colspan=20></td></tr>";
356 $table_data .= "<tr><td colspan=20><hr></td></tr>";
357 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
359 for($m=$num_months; $m >=0; $m--) {
360 if($num_families[$m] > 0) {
361 $percent = ceil(($visits[$m] / $num_families[$m])*100);
365 $stat_data .= "<td align=center><font size=-2><b>$visits[$m] / $num_families[$m]<br>$percent%</font></b></td>";
367 $stat_data .= "</tr>";
369 $this->t->set_var('table_width',$table_width);
370 $this->t->set_var('header_row',$header_row);
371 $this->t->set_var('table_data',$table_data);
372 $this->t->set_var('stat_data',$stat_data);
373 $this->t->fp('list','district_list',True);
376 $totals = "<tr><td><b><font size=-2>Total Families Hometaught:<br>Total Hometeaching Percentage:</font></b></td>";
377 for($m=$num_months; $m >=0; $m--) {
378 if($total_families[$m] > 0) {
379 $percent = ceil(($total_visits[$m] / $total_families[$m])*100);
383 $totals .= "<td align=center><font size=-2><b>$total_visits[$m] / $total_families[$m]<br>$percent%</font></b></td>";
387 $this->t->set_var('totals',$totals);
389 $this->t->pfp('out','ht_view_t');
390 $this->save_sessiondata();
396 $this->t->set_file(array('ht_update_t' => 'ht_update.tpl'));
397 $this->t->set_block('ht_update_t','district_list','list');
398 $this->t->set_block('ht_update_t','save','savehandle');
400 $district = get_var('district',array('GET','POST'));
401 $district_name = get_var('district_name',array('GET','POST'));
402 $date = get_var('date',array('GET','POST'));
403 $month = get_var('month',array('GET','POST'));
404 $month_start = get_var('month_start',array('GET','POST'));
405 $month_end = get_var('month_end',array('GET','POST'));
406 $action = get_var('action',array('GET','POST'));
408 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
409 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_update&action=save'));
410 $this->t->set_var('lang_done','Cancel');
411 $this->t->set_var('district_name',$district_name);
412 $this->t->set_var('district_number',$district);
413 $this->t->set_var('title','Hometeaching Update ' . $month);
414 $this->t->set_var('date',$date);
416 if($action == 'save')
418 // Get a list of all the companionships in this district
419 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $district;
420 $this->db->query($sql,__LINE__,__FILE__);
422 while ($this->db->next_record())
424 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
427 for ($j=0; $j < count($unique_companionships); $j++)
429 //$comp=$unique_companionships[$j]['companionship'];
430 //print "deleting from eq_visit where companionship=$comp and date=$date and district=$district<br>";
431 // Delete all the visits that have taken place for all families for this companionsthip for this month
432 $this->db->query("DELETE from eq_visit where companionship=" . $unique_companionships[$j]['companionship'] .
433 " AND " . "date='" . $date . "'",__LINE__,__FILE__);
436 // Now, add the visits that are checked for this month
437 $new_data = get_var('family_visited',array('POST'));
438 foreach ($new_data as $family)
440 foreach ($family as $data)
442 //print "family_visited: $data <br>";
443 $data_array = explode("/",$data);
444 $family_id = $data_array[0];
445 $companionship = $data_array[1];
446 $date = $data_array[2];
447 $visited = $data_array[3];
448 if($visited == "") { $visited = $data_array[4]; }
449 //print "family_id: $family_id companionship: $companionship date: $date visited: $visited<br>";
450 $this->db->query("INSERT INTO eq_visit (family,companionship,date,notes,visited) "
451 . "VALUES (" . $family_id .",". $companionship .",'". $date ."','','". $visited ."')",__LINE__,__FILE__);
458 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
459 $this->db->query($sql,__LINE__,__FILE__);
461 while ($this->db->next_record())
463 $elder_id[$i] = $this->db->f('elder');
464 $elder_name[$i] = $this->db->f('name');
465 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
468 array_multisort($elder_name, $elder_id);
470 // Make an array mapping elder_ids to elder_names
471 for($i=0; $i < count($elder_id); $i++) {
473 $elders[$id] = $elder_name[$i];
476 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
477 $this->db->query($sql,__LINE__,__FILE__);
478 while ($this->db->next_record())
480 $aaronic_id = $this->db->f('aaronic');
481 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
482 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
485 // Select all the unique companionship numbers for this district
486 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $district;
487 $this->db->query($sql,__LINE__,__FILE__);
488 $j=0; $unique_companionships='';
489 while ($this->db->next_record())
491 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
495 $comp_width=300; $visit_width=25; $table_width=$comp_width + $visit_width;
496 $table_data=""; $num_companionships = 0; $num_families = 0; $visits=0;
497 for ($j=0; $j < count($unique_companionships); $j++) {
498 $companion_table_entry = "";
499 // Select all the companions in each companionship
500 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
501 "companionship=". $unique_companionships[$j]['companionship'];
502 $this->db->query($sql,__LINE__,__FILE__);
504 while ($this->db->next_record())
506 // Get this companions information
507 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
508 $companionship = $this->db->f('companionship');
509 $elder_id = $this->db->f('elder');
510 $aaronic_id = $this->db->f('aaronic');
512 $name = $elders[$elder_id];
513 $phone = $elder_phone[$elder_id];
515 else if($aaronic_id) {
516 $name = $aaronic[$aaronic_id]['name'];
517 $phone = $aaronic[$aaronic_id]['phone'];
519 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
521 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
523 // Get the names of the families assigned this home teaching companionship
524 $sql = "SELECT * from eq_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
525 $sql = $sql . " ORDER BY name ASC";
526 $this->db->query($sql,__LINE__,__FILE__);
527 while ($this->db->next_record())
529 $family_name = $this->db->f('name');
530 $family_id = $this->db->f('family');
531 $this->nextmatchs->template_alternate_row_color(&$this->t);
532 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
534 $header_row="<th width=$comp_width><font size=-2>Families</th>";
536 // First check to see if the currently assigned companionship has visited them
537 $sql = "SELECT * FROM eq_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
538 " AND companionship=".$unique_companionships[$j]['companionship'].
539 " AND family=". $family_id;
540 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
541 if($this->db2->num_rows($query_id) == 0) {
542 // We did not find any visits made by the currently assigned companionship,
543 // look for visits made by any other companionship other than 0. (0 == EQ Presidency Visit)
544 $sql = "SELECT * FROM eq_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
545 " AND companionship!=0".
546 " AND family=". $family_id;
547 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
550 $value = $family_id . "/" . $unique_companionships[$j]['companionship'] . "/" . $date;
551 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
552 if(!$total_visits) { $total_visits = 0; }
553 if($this->db2->next_record()) {
554 if($this->db2->f('visited') == 'y') {
555 $visits++; $total_visits++; $num_families++;
556 $table_data .= '<td width=100 align=center>';
557 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y" checked>Y';
558 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
559 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/"> ';
560 $table_data .= '</td>';
561 } else if($this->db2->f('visited') == 'n') {
563 $table_data .= '<td width=100 align=center>';
564 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
565 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n" checked>N';
566 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/">';
567 $table_data .= '</td>';
569 $table_data .= '<td width=100 align=center>';
570 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
571 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
572 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
573 $table_data .= '</td>';
578 $table_data .= '<td width=100 align=center>';
579 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
580 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
581 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
582 $table_data .= '</td>';
585 $table_data .= "</tr>";
586 $table_data .= "<tr><td colspan=20></td></tr>";
588 $table_data .= "<tr><td colspan=20><hr></td></tr>";
589 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
591 $percent = ceil(($visits / $num_families)*100);
592 $stat_data .= "<td align=center><font size=-2><b>$visits / $num_families<br>$percent%</font></b></td>";
593 $stat_data .= "</tr>";
595 $this->t->set_var('table_width',$table_width);
596 $this->t->set_var('header_row',$header_row);
597 $this->t->set_var('table_data',$table_data);
598 $this->t->set_var('stat_data',$stat_data);
599 $this->t->fp('list','district_list',True);
601 $this->t->set_var('lang_reset','Clear Form');
602 $this->t->set_var('lang_save','Save Changes');
603 $this->t->set_var('savehandle','');
605 $this->t->pfp('out','ht_update_t');
606 $this->t->pfp('addhandle','save');
608 $this->save_sessiondata();
613 $this->t->set_file(array('act_list_t' => 'act_list.tpl'));
614 $this->t->set_block('act_list_t','act_list','list');
616 $this->t->set_var('lang_name','Assignment');
617 $this->t->set_var('lang_date','Date');
618 $this->t->set_var('lang_notes','Description');
620 $sql = "SELECT * FROM eq_activity ORDER BY date DESC";
621 $this->db->query($sql,__LINE__,__FILE__);
622 $total_records = $this->db->num_rows();
625 while ($this->db->next_record())
627 $activity_list[$i]['activity'] = $this->db->f('activity');
628 $activity_list[$i]['assignment'] = $this->db->f('assignment');
629 $activity_list[$i]['date'] = $this->db->f('date');
630 $activity_list[$i]['notes'] = $this->db->f('notes');
632 $sql = "SELECT * FROM eq_assignment WHERE assignment='" . $activity_list[$i]['assignment'] . "'";
633 $this->db2->query($sql,__LINE__,__FILE__);
634 if($this->db2->next_record())
636 $activity_list[$i]['name'] = $this->db2->f('name');
637 $activity_list[$i]['code'] = $this->db2->f('code');
642 for ($i=0; $i < count($activity_list); $i++)
644 $this->nextmatchs->template_alternate_row_color(&$this->t);
645 $this->t->set_var('name',$activity_list[$i]['name']);
646 $this->t->set_var('date',$activity_list[$i]['date']);
647 $activity_notes = $activity_list[$i]['notes'];
648 if(strlen($activity_notes) > 40) { $activity_notes = substr($activity_notes,0,40) . "..."; }
649 $this->t->set_var('notes',$activity_notes);
651 $link_data['menuaction'] = 'eq.eq.act_view';
652 $link_data['activity'] = $activity_list[$i]['activity'];
653 $link_data['action'] = 'view';
654 $this->t->set_var('view',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
655 $this->t->set_var('lang_view','View');
657 $link_data['menuaction'] = 'eq.eq.act_update';
658 $link_data['activity'] = $activity_list[$i]['activity'];
659 $link_data['action'] = 'edit';
660 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
661 $this->t->set_var('lang_edit','Edit');
663 $link_data['menuaction'] = 'eq.eq.act_update';
664 $link_data['activity'] = '0';
665 $link_data['action'] = 'add';
666 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/eq/index.php',$link_data)
667 . '"><input type="submit" name="Add" value="' . 'Add Activity' .'"></font></form>');
669 $this->t->fp('list','act_list',True);
672 $this->t->pfp('out','act_list_t');
673 $this->save_sessiondata();
678 $this->t->set_file(array('act_view_t' => 'act_view.tpl'));
679 $this->t->set_block('act_view_t','part_list','list');
681 $sql = "SELECT * FROM eq_activity WHERE activity=" . intval(get_var('activity',array('GET','POST')));
682 $this->db->query($sql,__LINE__,__FILE__);
683 $this->db->next_record();
684 $this->t->set_var('assignment', $this->db->f('assignment'));
685 $this->t->set_var('date', $this->db->f('date'));
686 $this->t->set_var('notes', $this->db->f('notes'));
688 $sql = "SELECT * FROM eq_assignment WHERE assignment='" . $this->db->f('assignment') . "'";
689 $this->db2->query($sql,__LINE__,__FILE__);
690 if($this->db2->next_record())
692 $this->t->set_var('name', $this->db2->f('name'));
693 $this->t->set_var('code', $this->db2->f('code'));
695 $this->t->set_var('lang_name','Assignment');
696 $this->t->set_var('lang_date','Date');
697 $this->t->set_var('lang_notes','Description');
698 $this->t->set_var('lang_done','Done');
699 $this->t->set_var('lang_action','View');
701 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
702 $this->t->set_var('tr_color',$tr_color);
704 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_list'));
706 $link_data['menuaction'] = 'eq.eq.act_update';
707 $link_data['activity'] = get_var('activity',array('GET','POST'));
708 $link_data['action'] = 'edit';
709 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
710 $this->t->set_var('lang_edit','Edit');
711 $this->t->set_var('cal_date',$this->db->f('date'));
713 // Now find out which elders participated in this activity
714 $sql = "SELECT * FROM eq_participation WHERE activity=" . intval(get_var('activity',array('GET','POST')));
715 $this->db->query($sql,__LINE__,__FILE__);
716 $total_records = $this->db->num_rows();
719 while ($this->db->next_record())
721 $part_list[$i]['elder'] = $this->db->f('elder');
725 for ($i=0; $i < count($part_list); $i++)
727 $sql = "SELECT * FROM eq_elder WHERE elder=" . $part_list[$i]['elder'];
728 $this->db->query($sql,__LINE__,__FILE__);
729 $this->db->next_record();
730 $names[$i] = $this->db->f('name');
733 for ($i=0; $i < count($names); $i++)
735 //$this->nextmatchs->template_alternate_row_color(&$this->t);
736 $this->t->set_var('elder_name',$names[$i]);
737 if(($i+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
738 else { $this->t->set_var('table_sep',"</td>"); }
739 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
740 $this->t->fp('list','part_list',True);
743 $this->t->pfp('out','act_view_t');
744 $this->save_sessiondata();
747 function act_update()
749 $this->t->set_file(array('form' => 'act_update.tpl'));
750 $this->t->set_block('form','elder_list','list');
751 $this->t->set_block('form','add','addhandle');
752 $this->t->set_block('form','edit','edithandle');
753 $this->t->set_var('lang_done','Done');
755 $action = get_var('action',array('GET','POST'));
756 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_list'));
757 $activity['activity'] = intval(get_var('activity',array('GET','POST')));
759 if($action == 'save')
761 $activity['assignment'] = get_var('assignment',array('POST'));
762 $activity['date'] = get_var('date',array('POST'));
763 $activity['notes']= get_var('notes',array('POST'));
764 $this->db->query("UPDATE eq_activity set " .
765 " assignment='" . $activity['assignment'] .
766 "', date='" . $activity['date'] . "'" .
767 ", notes='" . $activity['notes'] . "'" .
768 " WHERE activity=" . $activity['activity'],__LINE__,__FILE__);
770 // Delete all the elders who have particiapted in this activity
771 $this->db->query("DELETE from eq_participation where activity=".$activity['activity'],__LINE__,__FILE__);
773 // Re-add the elders who are checked as having participated in this activity
774 $elders = get_var('elder_name',array('POST'));
775 foreach ($elders as $elder)
777 $this->db->query("INSERT INTO eq_participation (elder,activity) "
778 . "VALUES (" . $elder . ",". $activity['activity'] . ")",__LINE__,__FILE__);
785 if($action == 'insert')
787 $activity['assignment'] = get_var('assignment',array('POST'));
788 $activity['date'] = get_var('date',array('POST'));
789 $activity['notes']= get_var('notes',array('POST'));
790 $this->db->query("INSERT INTO eq_activity (assignment,date,notes) "
791 . "VALUES ('" . $activity['assignment'] . "','"
792 . $activity['date'] . "','" . $activity['notes'] . "')",__LINE__,__FILE__);
794 $sql = "SELECT * FROM eq_activity WHERE assignment='".$activity['assignment']."' "
795 . " AND date='".$activity['date']."' AND notes='".$activity['notes']."'";
796 $this->db->query($sql,__LINE__,__FILE__);
797 if($this->db->next_record()) {
798 //print "activity: " . $this->db->f('activity') . "<br>";
799 $activity['activity'] = $this->db->f('activity');
802 $elders = get_var('elder_name',array('POST'));
803 foreach ($elders as $elder)
805 $this->db->query("INSERT INTO eq_participation (elder,activity) "
806 . "VALUES (" . $elder . ",". $activity['activity'] . ")",__LINE__,__FILE__);
815 $activity['activity'] = 0;
816 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
817 $this->t->set_var('assignment','');
818 $this->t->set_var('date','');
819 $this->t->set_var('notes','');
820 $this->t->set_var('lang_done','Cancel');
821 $this->t->set_var('lang_action','Adding New Activity');
822 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_update&activity='
823 . $activity['activity'] . '&action=' . 'insert'));
826 if($action == 'edit')
828 $sql = "SELECT * FROM eq_activity WHERE activity=" . $activity['activity'];
829 $this->db->query($sql,__LINE__,__FILE__);
830 $this->db->next_record();
831 $this->t->set_var('cal_date',$this->jscal->input('date',$this->db->f('date'),'','','','','',$this->cal_options));
832 $this->t->set_var('assignment', $this->db->f('assignment'));
833 $assignment = $this->db->f('assignment');
834 $this->t->set_var('date', $this->db->f('date'));
835 $this->t->set_var('notes', $this->db->f('notes'));
836 $this->t->set_var('lang_done','Cancel');
837 $this->t->set_var('lang_action','Editing Activity');
838 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_update&activity='
839 . $activity['activity'] . '&action=' . 'save'));
843 // Create the assignments drop-down list
844 $sql = "SELECT * FROM eq_assignment ORDER BY name ASC";
845 $this->db->query($sql,__LINE__,__FILE__);
847 while ($this->db->next_record())
849 $assignments[$i]['assignment'] = $this->db->f('assignment');
850 $assignments[$i]['name'] = $this->db->f('name');
851 $assignments[$i]['code'] = $this->db->f('code');
855 $assignment_data.= '<select name=assignment>';
856 $assignment_data.= '<option value=0></option>';
857 for ($j=0; $j < count($assignments); $j++) {
858 $id = $assignments[$j]['assignment'];
859 $name = $assignments[$j]['name'];
860 if($assignments[$j]['assignment'] == $assignment) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
861 $assignment_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
863 $assignment_data.='</select>';
864 $this->t->set_var('assignment_data',$assignment_data);
866 // Create elder selection boxes
867 $sql = "SELECT * FROM eq_elder";
868 $this->db->query($sql,__LINE__,__FILE__);
870 while ($this->db->next_record())
872 if($this->db->f('valid') == 1 || $action != 'add') {
873 $elder_name[$i] = $this->db->f('name');
874 $elder_id[$i] = $this->db->f('elder');
875 $elder_valid[$i] = $this->db->f('valid');
879 array_multisort($elder_name, $elder_id, $elder_valid);
882 for ($i=0; $i < count($elder_id); $i++)
884 //$this->nextmatchs->template_alternate_row_color(&$this->t);
885 $sql = "SELECT * FROM eq_participation where activity=". $activity['activity'] . " AND elder=" . $elder_id[$i];
886 $this->db->query($sql,__LINE__,__FILE__);
887 if($this->db->next_record()) { $this->t->set_var('checked','checked'); $checked=1; }
888 else { $this->t->set_var('checked',''); $checked=0; }
889 if($checked || $elder_valid[$i] == 1) {
890 $this->t->set_var('elder_name',$elder_name[$i]);
891 $this->t->set_var('elder',$elder_id[$i]);
892 if(($j+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
893 else { $this->t->set_var('table_sep',"</td>"); }
894 if(($j) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
895 $this->t->fp('list','elder_list',True);
900 $this->t->set_var('lang_reset','Clear Form');
901 $this->t->set_var('lang_add','Add Activity');
902 $this->t->set_var('lang_save','Save Changes');
903 $this->t->set_var('edithandle','');
904 $this->t->set_var('addhandle','');
906 $this->t->pfp('out','form');
907 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
908 if($action == 'add') { $this->t->pfp('addhandle','add'); }
910 $this->save_sessiondata();
913 function assign_view()
915 $this->t->set_file(array('assign_view_t' => 'assign_view.tpl'));
916 $this->t->set_block('assign_view_t','assign_view','list');
918 $this->t->set_var('lang_name','Assignment Name');
919 $this->t->set_var('lang_code','Code');
921 $sql = "SELECT * FROM eq_assignment ORDER BY name ASC";
922 $this->db->query($sql,__LINE__,__FILE__);
923 $total_records = $this->db->num_rows();
926 while ($this->db->next_record())
928 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
929 $assignment_list[$i]['name'] = $this->db->f('name');
930 $assignment_list[$i]['code'] = $this->db->f('code');
934 for ($i=0; $i < count($assignment_list); $i++)
936 $this->nextmatchs->template_alternate_row_color(&$this->t);
937 $this->t->set_var('name',$assignment_list[$i]['name']);
938 $this->t->set_var('code',$assignment_list[$i]['code']);
940 $link_data['menuaction'] = 'eq.eq.assign_update';
941 $link_data['assignment'] = $assignment_list[$i]['assignment'];
942 $link_data['action'] = 'edit';
943 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
944 $this->t->set_var('lang_edit','Edit');
946 $link_data['menuaction'] = 'eq.eq.assign_update';
947 $link_data['assignment'] = '0';
948 $link_data['action'] = 'add';
949 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/eq/index.php',$link_data)
950 . '"><input type="submit" name="Add" value="' . 'Add Assignment' .'"></font></form>');
952 $this->t->fp('list','assign_view',True);
955 $this->t->pfp('out','assign_view_t');
956 $this->save_sessiondata();
959 function assign_update()
961 $this->t->set_file(array('form' => 'assign_update.tpl'));
962 $this->t->set_block('form','add','addhandle');
963 $this->t->set_block('form','edit','edithandle');
964 $this->t->set_var('lang_done','Done');
966 $action = get_var('action',array('GET','POST'));
967 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.assign_view'));
968 $assignment['assignment'] = intval(get_var('assignment',array('GET','POST')));
970 if($action == 'save')
972 $assignment['name'] = get_var('name',array('POST'));
973 $assignment['code'] = get_var('code',array('POST'));
974 $this->db->query("UPDATE eq_assignment set " .
975 " name='" . $assignment['name'] . "'" .
976 ", code='" . $assignment['code'] . "'" .
977 " WHERE assignment=" . $assignment['assignment'],__LINE__,__FILE__);
979 $this->assign_view();
983 if($action == 'insert')
985 $assignment['name'] = get_var('name',array('POST'));
986 $assignment['code'] = get_var('code',array('POST'));
987 $this->db->query("INSERT INTO eq_assignment (name,code) "
988 . "VALUES ('" . $assignment['name'] . "','"
989 . $assignment['code'] . "')",__LINE__,__FILE__);
990 $this->assign_view();
996 $assignment['assignment'] = 0;
997 $this->t->set_var('name','');
998 $this->t->set_var('code','');
999 $this->t->set_var('lang_done','Cancel');
1000 $this->t->set_var('lang_action','Adding New Assignment');
1001 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.assign_update&assignment='
1002 . $assignment['assignment'] . '&action=' . 'insert'));
1005 if($action == 'edit')
1007 $sql = "SELECT * FROM eq_assignment WHERE assignment=" . $assignment['assignment'];
1008 $this->db->query($sql,__LINE__,__FILE__);
1009 $this->db->next_record();
1010 $this->t->set_var('name', $this->db->f('name'));
1011 $this->t->set_var('code', $this->db->f('code'));
1012 $this->t->set_var('lang_done','Cancel');
1013 $this->t->set_var('lang_action','Editing Assignment');
1014 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.assign_update&assignment='
1015 . $assignment['assignment'] . '&action=' . 'save'));
1019 $this->t->set_var('lang_reset','Clear Form');
1020 $this->t->set_var('lang_add','Add Assignment');
1021 $this->t->set_var('lang_save','Save Changes');
1022 $this->t->set_var('edithandle','');
1023 $this->t->set_var('addhandle','');
1025 $this->t->pfp('out','form');
1026 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
1027 if($action == 'add') { $this->t->pfp('addhandle','add'); }
1029 $this->save_sessiondata();
1034 $this->t->set_file(array('par_view_t' => 'par_view.tpl'));
1035 $this->t->set_block('par_view_t','header_list','list1');
1036 $this->t->set_block('par_view_t','elder_list','list2');
1038 $sql = "SELECT * FROM eq_elder where valid=1";
1039 $this->db->query($sql,__LINE__,__FILE__);
1041 while ($this->db->next_record())
1043 $elder_name[$i] = $this->db->f('name');
1044 $elder_id[$i] = $this->db->f('elder');
1047 array_multisort($elder_name, $elder_id);
1049 $sql = "SELECT * FROM eq_activity ORDER BY date DESC";
1050 $this->db->query($sql,__LINE__,__FILE__);
1051 $total_records = $this->db->num_rows();
1054 while ($this->db->next_record())
1056 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1057 $activity_list[$i]['date'] = $this->db->f('date');
1058 $activity_list[$i]['activity'] = $this->db->f('activity');
1062 $sql = "SELECT * FROM eq_assignment ORDER BY name ASC";
1063 $this->db->query($sql,__LINE__,__FILE__);
1065 while($this->db->next_record())
1067 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1068 $assignment_list[$i]['name'] = $this->db->f('name');
1069 $assignment_list[$i]['code'] = $this->db->f('code');
1073 $elder_width=300; $part_width=25; $assignment_width=50;
1074 $total_width=$elder_width+$part_width;
1075 for ($i=0; $i < count($assignment_list); $i++) {
1076 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1077 $this->t->set_var('assignment_code',$assignment_list[$i]['code']);
1078 $this->t->fp('list1','header_list',True);
1079 $total_width += $assignment_width;
1082 for ($i=0; $i < count($elder_id); $i++) {
1083 $participated=0; $part_table = '';
1084 $this->nextmatchs->template_alternate_row_color(&$this->t);
1085 $this->t->set_var('elder_name',$elder_name[$i]);
1086 for ($j=0; $j < count($assignment_list); $j++) {
1087 $date = "0000-00-00"; $checkmark=0; $num_matches=0;
1088 for ($k=0; $k < count($activity_list); $k++) {
1089 if($assignment_list[$j]['assignment'] == $activity_list[$k]['assignment']) {
1090 $sql = "SELECT * FROM eq_participation where "
1091 . " activity=" . $activity_list[$k]['activity']
1092 . " AND elder=" . $elder_id[$i];
1093 $this->db->query($sql,__LINE__,__FILE__);
1094 while($this->db->next_record()) {
1095 if($activity_list[$k]['date'] > $date) {
1096 $date = $activity_list[$k]['date'];
1105 $part_table .= '<td align=center><img src="images/checkmark.gif">';
1106 $part_table .= '<font size=-2>'.$num_matches.'</font><br>';
1107 $part_table .= '<font size=-2>'.$date.'</font></td>';
1109 $part_table .= '<td> </td>';
1112 if($participated) { $part_table .= '<td align=center><img src="images/checkmark.gif">'.$participated.'</td>'; }
1113 else { $part_table .= '<td> </td>'; }
1114 $this->t->set_var('part_table',$part_table);
1115 $this->t->fp('list2','elder_list',True);
1117 $this->t->set_var('total_width',$total_width);
1118 $this->t->set_var('elder_width',$elder_width);
1119 $this->t->set_var('part_width',$part_width);
1120 $this->t->set_var('act_width',$act_width);
1121 $this->t->pfp('out','par_view_t');
1122 $this->save_sessiondata();
1125 function willing_view()
1127 $this->t->set_file(array('willing_view_t' => 'willing_view.tpl'));
1128 $this->t->set_block('willing_view_t','header_list','list1');
1129 $this->t->set_block('willing_view_t','elder_list','list2');
1131 $this->t->set_var('lang_filter','Filter');
1132 $this->t->set_var('lang_filter_unwilling','Filter out unwilling Elders:');
1134 $filter_unwilling = get_var('filter_unwilling',array('POST'));
1135 $this->t->set_var('filter_unwilling',$filter_unwilling);
1137 if($filter_unwilling == 'y' || $filter_unwilling == '') {
1138 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\" checked>Y";
1139 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\">N";
1140 $filter_input.= " ";
1142 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\">Y";
1143 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\" checked>N";
1144 $filter_input.= " ";
1146 $this->t->set_var('filter_input',$filter_input);
1148 $sql = "SELECT * FROM eq_elder where valid=1";
1149 $this->db->query($sql,__LINE__,__FILE__);
1151 while ($this->db->next_record())
1153 $elder_name[$i] = $this->db->f('name');
1154 $elder_id[$i] = $this->db->f('elder');
1155 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
1158 array_multisort($elder_name, $elder_id);
1160 $sql = "SELECT * FROM eq_assignment ORDER BY name ASC";
1161 $this->db->query($sql,__LINE__,__FILE__);
1163 while($this->db->next_record())
1165 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1166 $assignment_list[$i]['name'] = $this->db->f('name');
1167 $assignment_list[$i]['code'] = $this->db->f('code');
1171 $sql = "SELECT * FROM eq_activity ORDER BY date DESC";
1172 $this->db->query($sql,__LINE__,__FILE__);
1173 $total_records = $this->db->num_rows();
1176 while ($this->db->next_record())
1178 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1179 $activity_list[$i]['date'] = $this->db->f('date');
1180 $activity_list[$i]['activity'] = $this->db->f('activity');
1184 $elder_width=275; $willing_width=40; $assignment_width=50;
1185 $total_width=$elder_width+$willing_width;
1187 for ($i=0; $i < count($assignment_list); $i++) {
1188 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1189 $this->t->set_var('assignment_code',$assignment_list[$i]['code']);
1190 $this->t->fp('list1','header_list',True);
1191 $total_width += $assignment_width;
1192 $total_willing[$i] = 0;
1195 for ($i=0; $i < count($elder_id); $i++) {
1196 $willing_table = ''; $elder_willing=0;
1197 $this->t->set_var('elder_name',$elder_name[$i]);
1198 $this->t->set_var('elder_phone',$elder_phone[$elder_id[$i]]);
1199 $this->t->set_var('editurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.willing_update&elder_id='
1200 . $elder_id[$i] . '&action=' . 'edit'));
1201 for ($j=0; $j < count($assignment_list); $j++) {
1202 $found_willingness=0;
1203 $sql = "SELECT * FROM eq_willingness where "
1204 . " assignment=" . $assignment_list[$j]['assignment']
1205 . " AND elder=" . $elder_id[$i];
1206 $this->db->query($sql,__LINE__,__FILE__);
1207 while($this->db->next_record()) {
1208 $found_willingness=1;
1210 $sql = "SELECT * FROM eq_activity where "
1211 . " assignment=". $assignment_list[$j]['assignment']
1212 . " ORDER by date DESC";
1213 $this->db2->query($sql,__LINE__,__FILE__);
1214 if($this->db2->next_record()) {
1215 $activity = $this->db2->f('activity');
1216 $date = $this->db2->f('date');
1217 $sql = "SELECT * FROM eq_participation where "
1218 . " activity=" . $activity
1219 . " AND elder=". $elder_id[$i];
1220 $this->db3->query($sql,__LINE__,__FILE__);
1221 if($this->db3->next_record()) {
1226 if($this->db->f('willing') == 'y') {
1227 $total_willing[$j]++;
1229 $willing_table .= '<td align=center><img src="images/checkmark.gif"><br><font size=-2>'.$date_part.'</font></td></td>';
1231 else if($this->db->f('willing') == 'n') {
1232 $willing_table .= '<td align=center><img src="images/x.gif"></td>';
1236 $willing_table .= "<td> </td>";
1239 if(!$found_willingness) {
1241 $willing_table .= "<td> </td>";
1244 if(($elder_willing == 1) || ($filter_unwilling == 'n')) {
1245 $this->t->set_var('willing_table',$willing_table);
1246 $this->t->fp('list2','elder_list',True);
1247 $this->nextmatchs->template_alternate_row_color(&$this->t);
1251 $stat_table = '<td><b>Total Willing to Serve</b></td>';
1252 for ($j=0; $j < count($assignment_list); $j++) {
1253 $stat_table .= "<td align=center><b>".$total_willing[$j]."</b></td>";
1255 $this->t->set_var('stat_table',$stat_table);
1257 $this->t->set_var('total_width',$total_width);
1258 $this->t->set_var('elder_width',$elder_width);
1259 $this->t->set_var('willing_width',$willing_width);
1260 $this->t->pfp('out','willing_view_t');
1261 $this->save_sessiondata();
1264 function willing_update()
1266 //print "<font color=red>Willingness Update Under Constrcution</font>";
1267 //$this->willing_view();
1270 $this->t->set_file(array('willing_update_t' => 'willing_update.tpl'));
1271 $this->t->set_block('willing_update_t','assignment_list','list');
1272 $this->t->set_block('willing_update_t','save','savehandle');
1274 $elder_id = get_var('elder_id',array('GET','POST'));
1275 $this->t->set_var('elder_id',$elder_id);
1276 $action = get_var('action',array('GET','POST'));
1278 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.willing_view'));
1279 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.willing_update&action=save'));
1280 $this->t->set_var('lang_done','Cancel');
1281 $this->t->set_var('title','Willingness Update ');
1283 if($action == 'save')
1285 // Delete all the previous willingness entries for this elder
1286 $this->db->query("DELETE from eq_willingness where elder=" . $elder_id ,__LINE__,__FILE__);
1288 // Now, add the assignment willingness that is checked for this elder
1289 $new_data = get_var('willingness',array('POST'));
1290 foreach ($new_data as $data)
1292 $data_array = explode("/",$data);
1293 $assignment = $data_array[0];
1294 $willing = $data_array[1];
1295 //print "elder_id: $elder_id assignment: $assignment willing: $willing<br>";
1296 $this->db->query("INSERT INTO eq_willingness (elder,assignment,willing) "
1297 . "VALUES (" . $elder_id .",". $assignment .",'". $willing . "')",__LINE__,__FILE__);
1299 $this->willing_view();
1303 $assignment_width=300; $willing_width=25; $table_width=$assignment_width + $willing_width;
1306 // Find out the elder's name
1307 $sql = "SELECT * FROM eq_elder WHERE elder=".$elder_id." AND valid=1";
1308 $this->db->query($sql,__LINE__,__FILE__);
1309 if($this->db->next_record()) {
1310 $elder_name = $this->db->f('name');
1311 $this->t->set_var('elder_name',$elder_name);
1314 // Select all the assignments
1315 $sql = "SELECT * FROM eq_assignment ORDER by name ASC";
1316 $this->db->query($sql,__LINE__,__FILE__);
1318 while ($this->db->next_record())
1320 $assignment = $this->db->f('assignment');
1321 $assignment_name = $this->db->f('name');
1322 $assignment_code = $this->db->f('code');
1324 $this->nextmatchs->template_alternate_row_color(&$this->t);
1325 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$assignment_name</td>";
1327 $header_row="<th width=$comp_width><font size=-2>Assignments</th><th>Willingness</th>";
1328 $sql = "SELECT * FROM eq_willingness WHERE elder=".$elder_id." AND assignment=".$assignment;
1329 $this->db2->query($sql,__LINE__,__FILE__);
1330 $value = $assignment;
1332 if($this->db2->next_record()) {
1333 if($this->db2->f('willing') == 'y') {
1334 $table_data .= '<td width=100 align=center>';
1335 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y" checked>Y';
1336 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1337 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/"> ';
1338 $table_data .= '</td>';
1339 } else if($this->db2->f('willing') == 'n') {
1340 $table_data .= '<td width=100 align=center>';
1341 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1342 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n" checked>N';
1343 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/">';
1344 $table_data .= '</td>';
1346 $table_data .= '<td width=100 align=center>';
1347 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1348 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1349 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1350 $table_data .= '</td>';
1354 $table_data .= '<td width=100 align=center>';
1355 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1356 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1357 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1358 $table_data .= '</td>';
1361 $table_data .= "\n";
1362 $table_data .= "</tr>";
1363 $table_data .= "<tr><td colspan=20></td></tr>";
1366 $table_data .= "<tr><td colspan=20><hr></td></tr>";
1368 $this->t->set_var('table_width',$table_width);
1369 $this->t->set_var('header_row',$header_row);
1370 $this->t->set_var('table_data',$table_data);
1371 $this->t->fp('list','assignment_list',True);
1373 $this->t->set_var('lang_reset','Clear Form');
1374 $this->t->set_var('lang_save','Save Changes');
1375 $this->t->set_var('savehandle','');
1377 $this->t->pfp('out','willing_update_t');
1378 $this->t->pfp('addhandle','save');
1380 $this->save_sessiondata();
1384 function ppi_sched()
1386 $this->t->set_file(array('ppi_sched_t' => 'ppi_sched.tpl'));
1387 $this->t->set_block('ppi_sched_t','elder_list','elderlist');
1388 $this->t->set_block('ppi_sched_t','appt_list','apptlist');
1389 $action = get_var('action',array('GET','POST'));
1391 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1392 $this->t->set_var('lang_reset','Clear Changes');
1394 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
1395 $this->t->set_var('ppi_link_title','Yearly PPIs');
1397 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched'));
1398 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
1400 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched&action=save'));
1401 $this->t->set_var('title','Yearly PPI Scheduler');
1403 $elder_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $ppi_date_width=20;
1404 $table_width=$elder_width + $phone_width + $pri_width + $notes_width + $ppi_date_width;
1405 $header_row = "<th width=$elder_width><font size=-2>Elder Name</th>";
1406 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1407 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1408 $header_row.= "<th width=$ppi_date_width><font size=-2>Last PPI</th>";
1409 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1410 $table_data=""; $completed_data=""; $totals_data="";
1414 // Get the EQ President
1415 $sql = "SELECT * FROM eq_presidency where president=1 and valid=1";
1416 $this->db->query($sql,__LINE__,__FILE__);
1417 if($this->db->next_record()) {
1418 $president_name = $this->db->f('name');
1419 $president_name_array = explode(",",$president_name);
1420 $president_last_name = $president_name_array[0];
1421 $president_id = $this->db->f('elder');
1422 $presidency_id = $this->db->f('presidency');
1423 $interviewer = $this->db->f('elder');
1424 $district_number = '*';
1425 $district_name = $president_name;
1427 print "<hr><font color=red><h3>-E- Unable to locate EQ President in eq_presidency table</h3></font></hr>";
1431 if($action == 'save')
1433 // Save any changes made to the appointment table
1434 $new_data = get_var('appt_notes',array('POST'));
1435 if($new_data != "") {
1436 foreach ($new_data as $entry)
1438 $elder = $entry['elder'];
1439 $appointment = $entry['appointment'];
1440 $location = $entry['location'];
1441 if($location == "") { $location = "$president_last_name"." home"; }
1442 if($elder == 0) { $location = ""; }
1444 //Only perform a database update if we have made a change to this appointment
1445 $sql = "SELECT * FROM eq_appointment where appointment='$appointment' and elder='$elder' and location='$location'";
1446 $this->db->query($sql,__LINE__,__FILE__);
1447 if(!$this->db->next_record()) {
1448 // Perform database save actions here
1449 $this->db->query("UPDATE eq_appointment set " .
1450 " elder='" . $elder . "'" .
1451 ",location='" . $location . "'" .
1452 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1453 // Email the appointment
1454 $this->email_appt($appointment);
1460 // Save any changes made to the ppi notes table
1461 $new_data = get_var('ppi_notes',array('POST'));
1462 foreach ($new_data as $entry)
1464 $ppi_notes = $entry['notes'];
1465 $elder_id = $entry['elder_id'];
1466 $ppi_pri = $entry['pri'];
1468 // Perform database save actions here
1469 $this->db->query("UPDATE eq_elder set " .
1470 " ppi_notes='" . $ppi_notes . "'" .
1471 ",ppi_pri='" . $ppi_pri . "'" .
1472 " WHERE elder=" . $elder_id,__LINE__,__FILE__);
1476 $take_me_to_url = $GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched');
1477 //Header('Location: ' . $take_me_to_url);
1480 // create the elder id -> elder name mapping
1481 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY name ASC";
1482 $this->db->query($sql,__LINE__,__FILE__);
1486 while ($this->db->next_record())
1488 $elder_name[$i] = $this->db->f('name');
1489 $elder_id[$i] = $this->db->f('elder');
1492 array_multisort($elder_name, $elder_id);
1494 // APPOINTMENT TABLE
1495 $date_width=250; $time_width=100; $elder_width=200; $location_width=100;
1496 $appt_table_width=$date_width + $time_width + $elder_width + $location_width;
1497 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1498 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1499 $appt_header_row.= "<th width=$elder_width><font size=-2>Elder</th>";
1500 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
1501 $appt_table_data = "";
1503 $total_elders=0; $elders_with_yearly_ppi=0;
1505 // Display a scheduling table for the EQ President
1506 $table_data=""; $appt_table_data="";
1507 $table_title = "District ".$district_number.": ".$district_name.": All Elders with Yearly PPI Not Completed";
1508 $appt_table_title = "District ".$district_number.": ".$district_name.": Yearly PPI Appointment Slots";
1509 $this->t->set_var('table_title',$table_title);
1510 $this->t->set_var('appt_table_title',$appt_table_title);
1512 // query the database for all the appointments
1513 $sql = "SELECT * FROM eq_appointment where presidency=".$presidency_id." and date>=CURDATE() ORDER BY date ASC, time ASC";
1514 $this->db->query($sql,__LINE__,__FILE__);
1516 while ($this->db->next_record())
1518 $appointment = $this->db->f('appointment');
1519 $elder = $this->db->f('elder');
1520 $location = $this->db->f('location');
1521 if(($location == "") && ($elder > 0)) { $location = "$president_last_name"." home"; }
1523 $date = $this->db->f('date');
1524 $date_array = explode("-",$date);
1525 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1526 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1528 $time = $this->db->f('time');
1529 $time_array = explode(":",$time);
1530 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1532 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1533 $appt_table_data.= "<td align=center>$day_string</td>";
1534 $appt_table_data.= "<td align=center>$time_string</td>";
1536 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][elder]>';
1537 $appt_table_data.= '<option value=0></option>';
1538 for ($i=0; $i < count($elder_id); $i++) {
1539 $id = $elder_id[$i];
1540 $name = $elder_name[$i];
1541 if($elder_id[$i] == $elder) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
1542 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1544 $appt_table_data.='</select></td>';
1546 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
1547 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
1549 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1551 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1552 $this->t->set_var('tr_color',$tr_color);
1555 $this->t->set_var('appt_table_data',$appt_table_data);
1556 $this->t->set_var('appt_header_row',$appt_header_row);
1557 $this->t->set_var('appt_table_width',$appt_table_width);
1559 // PPI SCHEDULING TABLE
1560 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY ppi_pri ASC";
1561 $this->db->query($sql,__LINE__,__FILE__);
1565 while ($this->db->next_record())
1567 $elder_id[$i] = $this->db->f('elder');
1568 $elder_name[$i] = $this->db->f('name');
1569 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
1570 $elder_ppi_pri[$elder_id[$i]] = $this->db->f('ppi_pri');
1571 $elder_ppi_notes[$elder_id[$i]] = $this->db->f('ppi_notes');
1576 $max = count($elder_id);
1578 for($i=0; $i < $max; $i++) {
1579 $id = $elder_id[$i];
1580 $name = $elder_name[$i];
1581 $phone = $elder_phone[$id];
1582 $ppi_pri = $elder_ppi_pri[$id];
1583 $ppi_notes = $elder_ppi_notes[$id];
1585 // If this elder has had a yearly PPI this year, don't show him on the schedule list
1586 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
1587 $sql = "SELECT * FROM eq_ppi WHERE date > '$year_start' AND date < '$year_end' ".
1588 "AND elder=" . $id . " AND eqpresppi=1";
1589 $this->db2->query($sql,__LINE__,__FILE__);
1591 if(!$this->db2->next_record()) {
1592 $sql = "SELECT * FROM eq_ppi WHERE elder=" . $id . " ORDER BY date DESC";
1593 $this->db->query($sql,__LINE__,__FILE__);
1594 if($this->db->next_record()) { $date = $this->db->f('date'); } else { $date = ""; }
1595 $link_data['menuaction'] = 'eq.eq.ppi_update';
1596 $link_data['elder'] = $id;
1597 $link_data['name'] = $name;
1598 $link_data['ppi'] = '';
1599 $link_data['eqpresppi'] = 1;
1600 $link_data['action'] = 'add';
1601 $link_data['interviewer'] = $interviewer;
1602 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1603 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1604 $this->t->set_var('tr_color',$tr_color);
1605 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1606 $table_data.= "<td align=center>$phone</td>";
1607 //$table_data.= "<td align=center>$ppi_pri</td>";
1608 $table_data.= "<td align=center>";
1609 $table_data.= '<select name=ppi_notes['.$i.'][pri]>';
1610 foreach(range(0,6) as $num) {
1611 if($num == 0) { $num = 1; } else {$num = $num*5; }
1612 if($ppi_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
1613 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1615 $table_data.= '</select></td>';
1616 $table_data.= "<td align=center>$date</td>";
1617 $table_data.= '<td><input type=text size="50" maxlength="128" name="ppi_notes['.$i.'][notes]" value="'.$ppi_notes.'">';
1618 $table_data.= '<input type=hidden name="ppi_notes['.$i.'][elder_id]" value="'.$id.'">';
1619 $table_data.= '<input type=hidden name="ppi_notes['.$i.'][elder_name]" value="'.$name.'">';
1620 $table_data.= '</td>';
1621 $table_data.= '</tr>';
1623 $link_data['menuaction'] = 'eq.eq.ppi_update';
1624 $link_data['interviewer'] = $this->db2->f('interviewer');
1625 $link_data['elder'] = $this->db2->f('elder');
1626 $link_data['name'] = $name;
1627 $link_data['ppi'] = $this->db2->f('ppi');
1628 $link_data['eqpresppi'] = $this->db2->f('eqpresppi');
1629 $link_data['action'] = 'view';
1630 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1631 $elders_with_yearly_ppi++;
1632 $date = $this->db2->f('date');
1633 $ppi_notes = $this->db2->f('notes');
1634 if(strlen($ppi_notes) > 40) { $ppi_notes = substr($ppi_notes,0,40) . "..."; }
1635 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1636 $this->t->set_var('tr_color2',$tr_color2);
1637 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1638 $completed_data.= "<td align=center>$phone</td>";
1639 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1640 $completed_data.= "<td align=left>$ppi_notes</td>";
1641 $completed_data.= '</tr>';
1643 } // End for Elders Loop
1645 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1646 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1647 $completed_header_row = "<th width=$name_width><font size=-2>Elder Name</th>";
1648 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1649 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1650 $completed_header_row.= "<th width=$notes_width><font size=-2>PPI Notes</th>";
1652 $this->t->set_var('table_width',$table_width);
1653 $this->t->set_var('header_row',$header_row);
1654 $this->t->set_var('table_data',$table_data);
1655 $this->t->set_var('completed_header_row',$completed_header_row);
1656 $this->t->set_var('completed_table_width',$completed_table_width);
1657 $this->t->set_var('completed',$completed_data);
1658 $this->t->fp('elderlist','elder_list',True);
1660 $elders_width=300; $totals_width=100;
1661 $totals_table_width=$elders_width + $totals_width;
1662 $totals_header_row = "<th width=$elders_width><font size=-2>Elders</th>";
1663 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
1664 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1665 $totals_data.= "<td align=left><font size=-2><b>Total Elders with yearly PPIs completed:</b></font></td>";
1666 $totals_data.= "<td align=center><font size=-2><b>$elders_with_yearly_ppi / $total_elders</b></font></td>";
1667 $percent = ceil(($elders_with_yearly_ppi / $total_elders)*100);
1668 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1669 $this->t->set_var('tr_color',$tr_color);
1670 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1671 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
1672 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
1673 $totals_data.= "</tr>";
1675 $this->t->set_var('totals',$totals_data);
1676 $this->t->set_var('totals_header_row',$totals_header_row);
1677 $this->t->set_var('totals_table_width',$totals_table_width);
1679 $this->t->pfp('out','ppi_sched_t');
1680 $this->save_sessiondata();
1684 function int_sched()
1686 $this->t->set_file(array('int_sched_t' => 'int_sched.tpl'));
1687 $this->t->set_block('int_sched_t','elder_list','elderlist');
1688 $this->t->set_block('int_sched_t','appt_list','apptlist');
1689 $action = get_var('action',array('GET','POST'));
1691 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1692 $this->t->set_var('lang_reset','Clear Changes');
1694 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_view'));
1695 $this->t->set_var('int_link_title','Hometeaching Interviews');
1697 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_sched'));
1698 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
1700 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_sched&action=save'));
1701 $this->t->set_var('title','Hometeaching Interviews Scheduler');
1703 $elder_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $int_date_width=20;
1704 $table_width=$elder_width + $phone_width + $pri_width + $notes_width + $int_date_width;
1705 $header_row = "<th width=$elder_width><font size=-2>Elder Name</th>";
1706 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1707 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1708 $header_row.= "<th width=$int_date_width><font size=-2>Last Interview</th>";
1709 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1710 $table_data=""; $completed_data=""; $totals_data="";
1714 $nextyear = $year + 1;
1715 if($month >= 1 && $month <= 3) { $quarter_start=$year."-01-01"; $quarter_end=$year."-04-01"; }
1716 if($month >= 4 && $month <= 6) { $quarter_start=$year."-04-01"; $quarter_end=$year."-07-01"; }
1717 if($month >= 7 && $month <= 9) { $quarter_start=$year."-07-01"; $quarter_end=$year."-10-01"; }
1718 if($month >= 10 && $month <= 12) { $quarter_start=$year."-10-01"; $quarter_end=$nextyear."-01-01"; }
1719 //print "year: $year month: $month quarter_start: $quarter_start quarter_end: $quarter_end<br>";
1721 // create the elder id -> elder name mapping
1722 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY name ASC";
1723 $this->db->query($sql,__LINE__,__FILE__);
1725 $elder_id_data = NULL;
1726 $elder_name_data = NULL;
1727 while ($this->db->next_record())
1729 $elder_name_data[$i] = $this->db->f('name');
1730 $elder_id_data[$i] = $this->db->f('elder');
1731 $elderid2name[$elder_id_data[$i]] = $elder_name_data[$i];
1734 array_multisort($elder_name_data, $elder_id_data);
1736 if($action == 'save')
1738 // Save any changes made to the appointment table
1739 $new_data = get_var('appt_notes',array('POST'));
1740 if($new_data != "") {
1741 foreach ($new_data as $entry)
1743 $elder = $entry['elder'];
1744 $appointment = $entry['appointment'];
1745 $location = $entry['location'];
1746 if($location == "") {
1747 $supervisor = $entry['supervisor'];
1748 $supervisor_array = explode(",", $elderid2name[$supervisor]);
1749 $supervisor_last_name = $supervisor_array[0];
1750 $location = "$supervisor_last_name"." home";
1752 if($elder == 0) { $location = ""; }
1754 //print "elder: $elder appointment: $appointment <br>";
1755 //Only perform a database update if we have made a change to this appointment
1756 $sql = "SELECT * FROM eq_appointment where appointment='$appointment' and elder='$elder' and location='$location'";
1757 $this->db->query($sql,__LINE__,__FILE__);
1758 if(!$this->db->next_record()) {
1759 // Perform database save actions here
1760 $this->db->query("UPDATE eq_appointment set " .
1761 " elder='" . $elder . "'" .
1762 ",location='" . $location . "'" .
1763 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1765 // Email the appointment
1766 $this->email_appt($appointment);
1771 // Save any changes made to the int notes table
1772 $new_data = get_var('int_notes',array('POST'));
1773 foreach ($new_data as $entry)
1775 $int_notes = $entry['notes'];
1776 $elder_id = $entry['elder_id'];
1777 $elder_name = $entry['elder_name'];
1778 $int_pri = $entry['pri'];
1779 $aaronic = $entry['aaronic'];
1780 //print "int_notes: $int_notes elder_name: $elder_name aaronic: $aaronic <Br>";
1782 // Perform database save actions here
1783 $this->db->query("UPDATE eq_elder set " .
1784 " int_notes='" . $int_notes . "'" .
1785 ",int_pri='" . $int_pri . "'" .
1786 " WHERE elder=" . $elder_id,__LINE__,__FILE__);
1791 $take_me_to_url = $GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_sched');
1792 //Header('Location: ' . $take_me_to_url);
1795 // Get the Districts
1796 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
1797 $this->db->query($sql,__LINE__,__FILE__);
1799 while ($this->db->next_record())
1801 $district = $this->db->f('district');
1802 $districts[$i]['district'] = $this->db->f('district');
1803 $districts[$i]['name'] = $this->db->f('name');
1804 $districts[$i]['supervisor'] = $this->db->f('supervisor');
1805 $sql = "SELECT * FROM eq_presidency where district=$district and valid=1";
1806 $this->db2->query($sql,__LINE__,__FILE__);
1807 if($this->db2->next_record()) {
1808 $districts[$i]['presidency'] = $this->db2->f('presidency');
1813 // APPOINTMENT TABLE
1815 $date_width=250; $time_width=100; $elder_width=200; $location_width=100;
1816 $appt_table_width=$date_width + $time_width + $elder_width + $location_width;
1817 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1818 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1819 $appt_header_row.= "<th width=$elder_width><font size=-2>Elder</th>";
1820 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
1821 $appt_table_data = "";
1823 $total_comps=0; $comps_with_quarterly_int=0;
1825 // Display a scheduling table for each district
1826 for ($d=0; $d < count($districts); $d++) {
1827 $table_data=""; $appt_table_data="";
1828 $this->t->set_var('district_number',$districts[$d]['district']);
1829 $this->t->set_var('district_name',$districts[$d]['name']);
1830 $supervisor = $districts[$d]['supervisor'];
1831 $supervisor_array = explode(",", $supervisor);
1832 $supervisor_last_name = $supervisor_array[0];
1833 $table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": All Elders with Interviews Not Completed";
1834 $appt_table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": Interview Appointment Slots";
1835 $this->t->set_var('table_title',$table_title);
1836 $this->t->set_var('appt_table_title',$appt_table_title);
1838 // query the database for all the appointments
1839 $sql = "SELECT * FROM eq_appointment where presidency=".$districts[$d]['presidency']." and date>=CURDATE() ORDER BY date ASC, time ASC";
1840 $this->db->query($sql,__LINE__,__FILE__);
1842 while ($this->db->next_record())
1844 $appointment = $this->db->f('appointment');
1845 $elder = $this->db->f('elder');
1846 $location = $this->db->f('location');
1847 if(($location == "") && ($elder > 0)) { $location = "$supervisor_last_name"." home"; }
1849 $date = $this->db->f('date');
1850 $date_array = explode("-",$date);
1851 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1852 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1854 $time = $this->db->f('time');
1855 $time_array = explode(":",$time);
1856 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1858 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1859 $appt_table_data.= "<td align=center>$day_string</td>";
1860 $appt_table_data.= "<td align=center>$time_string</td>";
1862 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][elder]>';
1863 $appt_table_data.= '<option value=0></option>';
1864 for ($i=0; $i < count($elder_id_data); $i++) {
1865 $id = $elder_id_data[$i];
1866 $name = $elder_name_data[$i];
1867 if($elder_id_data[$i] == $elder) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
1868 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1870 $appt_table_data.='</select></td>';
1872 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
1873 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
1875 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1876 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][supervisor]" value="'.$supervisor.'">';
1878 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1879 $this->t->set_var('tr_color',$tr_color);
1882 $this->t->set_var('appt_table_data',$appt_table_data);
1883 $this->t->set_var('appt_header_row',$appt_header_row);
1884 $this->t->set_var('appt_table_width',$appt_table_width);
1886 // INTERVIEW SCHEDULING TABLE
1888 // Select all the unique companionship numbers for this district
1889 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $districts[$d]['district'];
1890 $this->db->query($sql,__LINE__,__FILE__);
1892 while ($this->db->next_record())
1894 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
1899 for ($j=0; $j < count($unique_companionships); $j++) {
1900 // Select all the companions from each companionship
1901 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
1902 "companionship=". $unique_companionships[$j]['companionship'];
1903 $this->db->query($sql,__LINE__,__FILE__);
1904 $k=0; $int_completed=0;
1905 $comp = $unique_companionships[$j]['companionship'];
1906 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1907 $this->t->set_var('tr_color',$tr_color);
1909 while ($this->db->next_record())
1911 // Get this companions information
1912 $elder_id = $this->db->f('elder');
1913 $aaronic_id = $this->db->f('aaronic');
1915 $sql = "SELECT * FROM eq_elder where elder=$elder_id";
1916 $this->db2->query($sql,__LINE__,__FILE__);
1917 if($this->db2->next_record())
1919 $elder_id = $this->db2->f('elder');
1920 $elder_name = $this->db2->f('name');
1921 $elder_phone[$elder_id] = $this->db2->f('phone');
1922 $elder_int_pri[$elder_id] = $this->db2->f('int_pri');
1923 $elder_int_notes[$elder_id] = $this->db2->f('int_notes');
1927 $sql = "SELECT * FROM eq_aaronic where aaronic=$aaronic_id";
1928 $this->db2->query($sql,__LINE__,__FILE__);
1929 if($this->db2->next_record())
1931 $elder_id = $this->db2->f('aaronic');
1932 $elder_name = $this->db2->f('name');
1933 $elder_phone[$elder_id] = $this->db2->f('phone');
1939 $name = $elder_name;
1940 $phone = $elder_phone[$id];
1941 $int_pri = $elder_int_pri[$id];
1942 $int_notes = $elder_int_notes[$id];
1943 $aaronic = $elder_aaronic;
1945 // If the companionship has already had its quarterly interview,
1946 // Skip the other companion in the companionship.
1947 if($int_completed == 1) {
1948 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1949 $completed_data.= "<td align=center>$phone</td>";
1950 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1951 $completed_data.= "<td align=left>$int_notes</td>";
1952 $completed_data.= '</tr>';
1953 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1954 $this->t->set_var('tr_color2',$tr_color2);
1955 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1956 $this->t->set_var('tr_color',$tr_color);
1960 // If this companionship has had a hometeaching interview this quarter, don't show them on the schedule list
1961 $sql = "SELECT * FROM eq_ppi WHERE date >= '$quarter_start' AND date < '$quarter_end' ".
1963 $this->db2->query($sql,__LINE__,__FILE__);
1965 if(!$this->db2->next_record()) {
1966 $sql = "SELECT * FROM eq_ppi WHERE elder=" . $id . " ORDER BY date DESC";
1967 $this->db3->query($sql,__LINE__,__FILE__);
1968 if($this->db3->next_record()) { $date = $this->db3->f('date'); } else { $date = ""; }
1969 $link_data['menuaction'] = 'eq.eq.int_update';
1970 $link_data['elder'] = $id;
1971 $link_data['aaronic'] = 0;
1972 $link_data['name'] = $name;
1973 $link_data['ppi'] = '';
1974 $link_data['action'] = 'add';
1975 $link_data['interviewer'] = $districts[$d]['supervisor'];
1976 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1977 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1978 $table_data.= "<td align=center>$phone</td>";
1979 $table_data.= "<td align=center>";
1981 $table_data.= '<select name=int_notes['.$i.'][pri]>';
1982 foreach(range(0,6) as $num) {
1983 if($num == 0) { $num = 1; } else {$num = $num*5; }
1984 if($int_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
1985 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1987 $table_data.= '</select></td>';
1989 $table_data.= "<td align=center>$date</td>";
1991 $table_data.= '<td><input type=text size="50" maxlength="128" name="int_notes['.$i.'][notes]" value="'.$int_notes.'">';
1993 $table_data.= '<input type=hidden name="int_notes['.$i.'][elder_id]" value="'.$id.'">';
1994 $table_data.= '<input type=hidden name="int_notes['.$i.'][elder_name]" value="'.$name.'">';
1995 $table_data.= '<input type=hidden name="int_notes['.$i.'][aaronic]" value="'.$aaronic.'">';
1996 $table_data.= '</td>';
1997 $table_data.= '</tr>'."\n";
2000 $link_data['menuaction'] = 'eq.eq.int_update';
2001 $link_data['interviewer'] = $this->db2->f('interviewer');
2002 $link_data['elder'] = $this->db2->f('elder');
2003 $link_data['aaronic'] = $this->db2->f('aaronic');
2004 $link_data['name'] = $name;
2005 $link_data['ppi'] = $this->db2->f('ppi');
2006 $link_data['action'] = 'view';
2007 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2008 $comps_with_quarterly_int++;
2010 $date = $this->db2->f('date');
2011 $int_notes = $this->db2->f('notes');
2012 if(strlen($int_notes) > 40) { $int_notes = substr($int_notes,0,40) . "..."; }
2013 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2014 $completed_data.= "<td align=center>$phone</td>";
2015 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2016 $completed_data.= "<td align=left>$int_notes</td>";
2017 $completed_data.= '</tr>';
2022 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
2023 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
2024 $completed_header_row = "<th width=$name_width><font size=-2>Elder Name</th>";
2025 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2026 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
2027 $completed_header_row.= "<th width=$notes_width><font size=-2>Interview Notes</th>";
2029 $this->t->set_var('table_width',$table_width);
2030 $this->t->set_var('header_row',$header_row);
2031 $this->t->set_var('table_data',$table_data);
2032 $this->t->set_var('completed_header_row',$completed_header_row);
2033 $this->t->set_var('completed_table_width',$completed_table_width);
2034 $this->t->set_var('completed',$completed_data);
2035 $this->t->fp('elderlist','elder_list',True);
2037 } // End for each district loop
2040 $elders_width=300; $totals_width=100;
2041 $totals_table_width=$elders_width + $totals_width;
2042 $totals_header_row = "<th width=$elders_width><font size=-2>Elders</th>";
2043 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2044 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2045 $totals_data.= "<td align=left><font size=-2><b>Total Companionships with interviews completed:</b></font></td>";
2046 $totals_data.= "<td align=center><font size=-2><b>$comps_with_quarterly_int / $total_comps</b></font></td>";
2047 $percent = ceil(($comps_with_quarterly_int / $total_comps)*100);
2048 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2049 $this->t->set_var('tr_color',$tr_color);
2050 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2051 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2052 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2053 $totals_data.= "</tr>";
2055 $this->t->set_var('totals',$totals_data);
2056 $this->t->set_var('totals_header_row',$totals_header_row);
2057 $this->t->set_var('totals_table_width',$totals_table_width);
2059 $this->t->pfp('out','int_sched_t');
2060 $this->save_sessiondata();
2064 function vis_sched()
2066 $this->t->set_file(array('vis_sched_t' => 'vis_sched.tpl'));
2067 $this->t->set_block('vis_sched_t','family_list','familylist');
2068 $this->t->set_block('vis_sched_t','appt_list','apptlist');
2069 $action = get_var('action',array('GET','POST'));
2071 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
2072 $this->t->set_var('lang_reset','Clear Changes');
2074 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
2075 $this->t->set_var('vis_link_title','View Yearly Visits');
2077 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched'));
2078 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2080 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched&action=save'));
2081 $this->t->set_var('title','EQ Presidency Yearly Visit Scheduler');
2083 $family_width=500; $phone_width=40; $pri_width=10; $notes_width=128; $visit_date_width=20;
2084 $table_width=$family_width + $phone_width + $pri_width + $notes_width + $visit_date_width;
2085 $header_row = "<th width=$family_width><font size=-2>Family Name</th>";
2086 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2087 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
2088 $header_row.= "<th width=$visit_date_width><font size=-2>Last Visit</th>";
2089 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
2090 $table_data=""; $completed_data=""; $totals_data="";
2094 // create the family id -> family name mapping
2095 $sql = "SELECT * FROM eq_family where valid=1 and elder_id != 0 ORDER BY name ASC";
2096 $this->db->query($sql,__LINE__,__FILE__);
2099 while ($this->db->next_record())
2101 $family_id[$i] = $this->db->f('family');
2102 $family_name[$i] = $this->db->f('name');
2103 $familyid2name[$family_id[$i]] = $family_name[$i];
2104 $sql = "SELECT * FROM eq_parent where family='$family_id[$i]'";
2105 $this->db2->query($sql,__LINE__,__FILE__);
2106 if($this->db2->next_record()) {
2107 $familyid2address[$family_id[$i]] = $this->db2->f('address');
2111 array_multisort($family_name, $family_id);
2113 if($action == 'save')
2115 // Save any changes made to the appointment table
2116 $new_data = get_var('appt_notes',array('POST'));
2117 if($new_data != "") {
2118 foreach ($new_data as $entry)
2120 $family = $entry['family'];
2121 $appointment = $entry['appointment'];
2122 $location = $entry['location'];
2123 if($location == "") {
2124 $family_name_array = explode(",", $familyid2name[$family]);
2125 $family_last_name = $family_name_array[0];
2126 $family_address = $familyid2address[$family];
2127 $location = "$family_last_name"." home ($family_address)";
2129 if($family == 0) { $location = ""; }
2131 //Only perform a database update if we have made a change to this appointment
2132 $sql = "SELECT * FROM eq_appointment where appointment='$appointment' and family='$family' and location='$location'";
2133 $this->db->query($sql,__LINE__,__FILE__);
2134 if(!$this->db->next_record()) {
2135 // Perform database save actions here
2136 $this->db->query("UPDATE eq_appointment set " .
2137 " family='" . $family . "'" .
2138 ",location='" . $location . "'" .
2139 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
2141 // Email the appointment
2142 $this->email_appt($appointment);
2147 // Save any changes made to the visit notes table
2148 $new_data = get_var('vis_notes',array('POST'));
2149 foreach ($new_data as $entry)
2151 $visit_notes = $entry['notes'];
2152 $family = $entry['family_id'];
2153 $visit_pri = $entry['pri'];
2155 // Perform database save actions here
2156 $this->db->query("UPDATE eq_family set " .
2157 " visit_notes='" . $visit_notes . "'" .
2158 ",visit_pri='" . $visit_pri . "'" .
2159 " WHERE family=" . $family,__LINE__,__FILE__);
2163 $take_me_to_url = $GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched');
2164 //Header('Location: ' . $take_me_to_url);
2167 // APPOINTMENT TABLE
2168 $date_width=250; $time_width=100; $family_width=250; $location_width=100;
2169 $appt_table_width=$date_width + $time_width + $family_width + $location_width;
2170 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
2171 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
2172 $appt_header_row.= "<th width=$family_width><font size=-2>Family</th>";
2173 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
2174 $appt_table_data = "";
2176 // Find out what the EQ Presidency ID is
2177 $sql = "SELECT * FROM eq_presidency where eqpres=1 and valid=1";
2178 $this->db->query($sql,__LINE__,__FILE__);
2179 if($this->db->next_record()) {
2180 $presidency_name = $this->db->f('name');
2181 $presidency_id = $this->db->f('presidency');
2183 print "<hr><font color=red><h3>-E- Unable to locate EQ Presidency in eq_presidency table</h3></font></hr>";
2187 // query the database for all the appointments
2188 $sql = "SELECT * FROM eq_appointment where presidency=$presidency_id and date>=CURDATE() ORDER BY date ASC, time ASC";
2189 $this->db->query($sql,__LINE__,__FILE__);
2191 while ($this->db->next_record())
2193 $appointment = $this->db->f('appointment');
2194 $family = $this->db->f('family');
2195 $location = $this->db->f('location');
2196 $family_name_array = explode(",", $familyid2name[$family]);
2197 $family_last_name = $family_name_array[0];
2198 $family_address = $familyid2address[$family];
2199 if(($location == "") && ($family > 0)) { $location = "$family_last_name"." home ($family_address)"; }
2201 $date = $this->db->f('date');
2202 $date_array = explode("-",$date);
2203 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
2204 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
2206 $time = $this->db->f('time');
2207 $time_array = explode(":",$time);
2208 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
2210 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2211 $appt_table_data.= "<td align=center>$day_string</td>";
2212 $appt_table_data.= "<td align=center>$time_string</td>";
2214 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][family]>';
2215 $appt_table_data.= '<option value=0></option>';
2216 for ($i=0; $i < count($family_id); $i++) {
2217 $id = $family_id[$i];
2218 $name = $family_name[$i];
2219 if($family_id[$i] == $family) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
2220 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
2222 $appt_table_data.='</select></td>';
2224 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
2225 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
2227 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
2229 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2230 $this->t->set_var('tr_color',$tr_color);
2233 $this->t->set_var('appt_table_data',$appt_table_data);
2234 $this->t->set_var('appt_header_row',$appt_header_row);
2235 $this->t->set_var('appt_table_width',$appt_table_width);
2238 // VISIT SCHEDULING TABLE
2239 $sql = "SELECT * FROM eq_family where valid=1 and elder_id != 0 ORDER BY visit_pri ASC";
2240 $this->db->query($sql,__LINE__,__FILE__);
2242 $total_families=0; $families_with_yearly_visit=0;
2246 $family_name = NULL;
2247 $family_phone = NULL;
2248 $family_visit_pri = NULL;
2249 $family_visit_notes = NULL;
2250 while ($this->db->next_record())
2252 $family_id[$i] = $this->db->f('family');
2253 $family_name[$i] = $this->db->f('name');
2254 $family_phone[$family_id[$i]] = $family_id[$i] . " ERROR";
2255 $family_visit_pri[$family_id[$i]] = $this->db->f('visit_pri');
2256 $family_visit_notes[$family_id[$i]] = $this->db->f('visit_notes');
2261 $sql = "SELECT * FROM eq_parent where valid=1";
2262 $this->db->query($sql,__LINE__,__FILE__);
2263 while ($this->db->next_record())
2265 $family = $this->db->f('family');
2266 $phone = $this->db->f('phone');
2267 $family_phone[$family] = $phone;
2270 $max = count($family_id);
2272 for($i=0; $i < $max; $i++) {
2273 $id = $family_id[$i];
2274 $name = $family_name[$i];
2275 $phone = $family_phone[$id];
2276 $vis_pri = $family_visit_pri[$id];
2277 $vis_notes = $family_visit_notes[$id];
2279 // If this family has had a yearly visit this year, don't show them on the schedule list
2280 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2281 $sql = "SELECT * FROM eq_visit WHERE date > '$year_start' AND date < '$year_end' ".
2282 "AND family=" . $id . " AND companionship=0";
2283 $this->db2->query($sql,__LINE__,__FILE__);
2285 if(!$this->db2->next_record()) {
2286 $sql = "SELECT * FROM eq_visit WHERE family=" . $id . " AND companionship=0 ORDER BY date DESC";
2287 $this->db->query($sql,__LINE__,__FILE__);
2288 if($this->db->next_record()) { $date = $this->db->f('date'); } else { $date = ""; }
2289 $link_data['menuaction'] = 'eq.eq.vis_update';
2290 $link_data['visit'] = '';
2291 $link_data['family'] = $id;
2292 $link_data['name'] = $name;
2293 $link_data['action'] = 'add';
2294 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2295 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2296 $table_data.= "<td align=center>$phone</td>";
2297 $table_data.= "<td align=center>";
2298 $table_data.= '<select name=vis_notes['.$i.'][pri]>';
2299 foreach(range(0,6) as $num) {
2300 if($num == 0) { $num = 1; } else {$num = $num*5; }
2301 if($vis_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
2302 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2304 $table_data.= '</select></td>';
2305 $table_data.= "<td align=center>$date</td>";
2306 $table_data.= '<td><input type=text size="50" maxlength="128" name="vis_notes['.$i.'][notes]" value="'.$vis_notes.'">';
2307 $table_data.= '<input type=hidden name="vis_notes['.$i.'][family_id]" value="'.$id.'">';
2308 $table_data.= '<input type=hidden name="vis_notes['.$i.'][family_name]" value="'.$name.'">';
2309 $table_data.= '</td>';
2310 $table_data.= '</tr>';
2311 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2312 $this->t->set_var('tr_color',$tr_color);
2314 $link_data['menuaction'] = 'eq.eq.vis_update';
2315 $link_data['visit'] = $this->db2->f('visit');
2316 $link_data['family'] = $this->db2->f('family');
2317 $link_data['name'] = $name;
2318 $link_data['date'] = $this->db2->f('date');
2319 $link_data['action'] = 'view';
2320 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2321 $families_with_yearly_visit++;
2322 $date = $this->db2->f('date');
2323 $vis_notes = $this->db2->f('notes');
2324 if(strlen($vis_notes) > 40) { $vis_notes = stripslashes(substr($vis_notes,0,40) . "..."); }
2325 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2326 $completed_data.= "<td align=center>$phone</td>";
2327 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2328 $completed_data.= "<td align=left>$vis_notes</td>";
2329 $completed_data.= '</tr>';
2330 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
2331 $this->t->set_var('tr_color2',$tr_color2);
2335 $name_width=190; $phone_width=100; $date_width=100; $notes_width=300;
2336 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
2337 $completed_header_row = "<th width=$name_width><font size=-2>Family Name</th>";
2338 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2339 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
2340 $completed_header_row.= "<th width=$notes_width><font size=-2>Visit Notes</th>";
2342 $family_width=300; $totals_width=100;
2343 $totals_table_width=$family_width + $totals_width;
2344 $totals_header_row = "<th width=$family_width><font size=-2>Families</th>";
2345 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2346 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2347 $totals_data.= "<td align=left><font size=-2><b>Total Families with yearly Visits completed:</b></font></td>";
2348 $totals_data.= "<td align=center><font size=-2><b>$families_with_yearly_visit / $total_families</b></font></td>";
2349 $percent = ceil(($families_with_yearly_visit / $total_families)*100);
2350 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2351 $this->t->set_var('tr_color',$tr_color);
2352 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2353 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2354 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2355 $totals_data.= "</tr>";
2357 $this->t->set_var('table_width',$table_width);
2358 $this->t->set_var('header_row',$header_row);
2359 $this->t->set_var('table_data',$table_data);
2360 $this->t->set_var('totals_header_row',$totals_header_row);
2361 $this->t->set_var('totals_table_width',$totals_table_width);
2362 $this->t->set_var('completed_header_row',$completed_header_row);
2363 $this->t->set_var('completed_table_width',$completed_table_width);
2364 $this->t->set_var('completed',$completed_data);
2365 $this->t->set_var('totals',$totals_data);
2366 $this->t->fp('familylist','family_list',True);
2367 $this->t->fp('apptlist','appt_list',True);
2369 $this->t->pfp('out','vis_sched_t');
2370 $this->save_sessiondata();
2376 $this->t->set_file(array('ppi_view_t' => 'ppi_view.tpl'));
2377 $this->t->set_block('ppi_view_t','district_list','list');
2379 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
2380 $num_months = get_var('num_months',array('GET','POST'));
2381 if($num_months == '') { $num_months = $this->default_ppi_num_months; }
2382 $this->t->set_var('num_months',$num_months);
2383 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
2384 else { $this->t->set_var('lang_num_months','Months of History'); }
2385 $this->t->set_var('lang_filter','Filter');
2386 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
2388 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
2389 $this->t->set_var('ppi_link_title','Yearly PPIs');
2391 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched'));
2392 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
2394 $this->t->set_var('title','Yearly PPIs');
2395 $num_months = get_var('num_months',array('GET','POST'));
2396 if($num_months == '') { $num_months = $this->default_ppi_num_years; }
2397 $this->t->set_var('num_months',$num_months);
2398 if($num_months == 1) { $this->t->set_var('lang_num_months','Year of History'); }
2399 else { $this->t->set_var('lang_num_months','Years of History'); }
2401 $sql = "SELECT * FROM eq_presidency where president=1 and valid=1";
2402 $this->db->query($sql,__LINE__,__FILE__);
2403 if($this->db->next_record()) {
2404 $president_name = $this->db->f('name');
2405 $interviewer = $this->db->f('elder');
2408 print "<hr><font color=red><h3>-E- Unable to locate EQ President in eq_presidency table</h3></font></hr>";
2411 $this->t->set_var('district_number','*');
2412 $this->t->set_var('district_name',$president_name);
2414 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
2415 $this->db->query($sql,__LINE__,__FILE__);
2417 while ($this->db->next_record())
2419 $elder_id[$i] = $this->db->f('elder');
2420 $elder_name[$i] = $this->db->f('name');
2421 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
2422 $elder_ppi_pri[$elder_id[$i]] = $this->db->f('ppi_pri');
2423 $elder_ppi_notes[$elder_id[$i]] = $this->db->f('ppi_notes');
2427 array_multisort($elder_name, $elder_id);
2428 //var_dump($elder_name); print "<br><br>"; var_dump($elder_id);
2430 $header_row="<th width=$comp_width><font size=-2>Elder Name</th>";
2432 $elder_width=400; $ppi_width=75; $table_width=$elder_width + $num_months*$ppi_width;
2434 for($m=$num_months; $m >= 0; $m--) {
2435 $year = date('Y') - $m;
2436 $header_row .= "<th width=150><font size=-2>$year</th>";
2440 for ($j=0; $j < count($elder_id); $j++) {
2441 $id = $elder_id[$j];
2442 $name = $elder_name[$j];
2443 $phone = $elder_phone[$id];
2445 $link_data['menuaction'] = 'eq.eq.ppi_update';
2446 $link_data['interviewer'] = $interviewer;
2447 $link_data['elder'] = $id;
2448 $link_data['name'] = $name;
2449 $link_data['ppi'] = '';
2450 $link_data['eqpresppi'] = $eqpresppi;
2451 $link_data['action'] = 'add';
2452 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2453 $this->nextmatchs->template_alternate_row_color(&$this->t);
2454 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2456 // Find out how many times PPIs were performed in the past $num_months for this Elder
2457 for($m=$num_months; $m >= 0; $m--) {
2458 $year = date('Y') - $m;
2459 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2460 $sql = "SELECT * FROM eq_ppi WHERE date > '$year_start' AND date < '$year_end' ".
2461 "AND elder=" . $id . " AND eqpresppi=1";
2462 $this->db2->query($sql,__LINE__,__FILE__);
2464 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
2465 if($this->db2->next_record()) {
2466 $ppis[$m]++; $total_ppis[$m]++; $ppi_recorded[$companionship][$m]=1;
2467 $link_data['menuaction'] = 'eq.eq.ppi_update';
2468 $link_data['companionship'] = $companionship;
2469 $link_data['interviewer'] = $this->db2->f('interviewer');
2470 $link_data['elder'] = $id;
2471 $link_data['name'] = $name;
2472 $link_data['ppi'] = $this->db2->f('ppi');
2473 $link_data['eqpresppi'] = $eqpresppi;
2474 $link_data['action'] = 'view';
2475 $date = $this->db2->f('date');
2476 $date_array = explode("-",$date);
2477 $month = $date_array[1];
2478 $day = $date_array[2];
2479 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2480 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2482 else { $table_data .= "<td> </td>"; }
2484 $table_data .= "</tr>\n";
2486 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2488 $stat_data = "<tr><td><b><font size=-2>$total_elders Elders<br>PPI Totals:</font></b></td>";
2489 for($m=$num_months; $m >=0; $m--) {
2490 $percent = ceil(($ppis[$m] / $total_elders)*100);
2491 $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
2493 $stat_data .= "</tr>";
2495 $this->t->set_var('table_width',$table_width);
2496 $this->t->set_var('header_row',$header_row);
2497 $this->t->set_var('table_data',$table_data);
2498 $this->t->set_var('stat_data',$stat_data);
2499 $this->t->pfp('out','ppi_view_t');
2500 $this->save_sessiondata();
2503 function ppi_update()
2505 $this->t->set_file(array('form' => 'ppi_update.tpl'));
2506 $this->t->set_block('form','interviewer_list','int_list');
2507 $this->t->set_block('form','add','addhandle');
2508 $this->t->set_block('form','edit','edithandle');
2510 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
2511 $this->t->set_var('readonly','');
2512 $this->t->set_var('disabled','');
2514 $action = get_var('action',array('GET','POST'));
2515 $companionship = get_var('companionship',array('GET','POST'));
2516 $interviewer = get_var('interviewer',array('GET','POST'));
2517 $name = get_var('name',array('GET','POST'));
2518 $ppi = get_var('ppi',array('GET','POST'));
2519 $elder = get_var('elder',array('GET','POST'));
2520 $aaronic = get_var('aaronic',array('GET','POST'));
2521 $date = get_var('date',array('GET','POST'));
2522 $notes = get_var('notes',array('GET','POST'));
2523 $eqpresppi = get_var('eqpresppi',array('GET','POST'));
2525 $sql = "SELECT * FROM eq_elder WHERE elder=" . $interviewer;
2526 $this->db2->query($sql,__LINE__,__FILE__);
2527 $this->db2->next_record();
2528 $interviewer_name = $this->db2->f('name');
2529 $this->t->set_var('interviewer',$interviewer . ' selected');
2530 $this->t->set_var('interviewer_name',$interviewer_name);
2531 $this->t->set_var('eqpresppi_checked','');
2532 $this->t->fp('int_list','interviewer_list',True);
2534 if($action == 'save')
2536 $notes = get_var('notes',array('POST'));
2537 $this->db->query("UPDATE eq_ppi set " .
2538 " ppi='" . $ppi . "'" .
2539 ", interviewer='" . $interviewer . "'" .
2540 ", elder='" . $elder . "'" .
2541 ", aaronic='" . $aaronic . "'" .
2542 ", date='" . $date . "'" .
2543 ", notes='" . $notes . "'" .
2544 ", eqpresppi='" . $eqpresppi . "'" .
2545 " WHERE ppi=" . $ppi,__LINE__,__FILE__);
2550 if($action == 'insert')
2552 $notes = get_var('notes',array('POST'));
2553 $this->db->query("INSERT INTO eq_ppi (interviewer,elder,aaronic,date,notes,eqpresppi) "
2554 . "VALUES ('" . $interviewer . "','" . $elder . "','" . $aaronic . "','"
2555 . $date . "','" . $notes . "','" . $eqpresppi ."')",__LINE__,__FILE__);
2560 if($action == 'add')
2562 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2563 $this->t->set_var('ppi', '');
2564 $this->t->set_var('interviewer', $interviewer);
2565 $this->t->set_var('name',$name);
2566 $this->t->set_var('elder',$elder);
2567 $this->t->set_var('date','');
2568 $this->t->set_var('notes','');
2569 $this->t->set_var('eqpresppi',$eqpresppi);
2570 $this->t->set_var('eqpresppi_checked','checked');
2571 $this->t->set_var('lang_done','Cancel');
2572 $this->t->set_var('lang_action','Adding New PPI');
2573 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
2574 . $ppi . '&action=' . 'insert'));
2577 if($action == 'edit' || $action == 'view')
2579 $sql = "SELECT * FROM eq_ppi WHERE ppi=".$ppi;
2580 $this->db->query($sql,__LINE__,__FILE__);
2581 $this->db->next_record();
2582 $this->t->set_var('ppi',$ppi);
2583 $this->t->set_var('name',$name);
2584 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2585 $this->t->set_var('elder',$this->db->f('elder'));
2586 $this->t->set_var('date',$this->db->f('date'));
2587 $this->t->set_var('notes',$this->db->f('notes'));
2588 $this->t->set_var('eqpresppi',$this->db->f('eqpresppi'));
2589 if($this->db->f('eqpresppi') == 1) { $this->t->set_var('eqpresppi_checked','checked'); }
2592 if($action == 'edit')
2594 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2595 $this->t->set_var('lang_done','Cancel');
2596 $this->t->set_var('lang_action','Editing PPI');
2597 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
2598 . $ppi . '&action=' . 'save'));
2601 if($action == 'view')
2603 $date = $this->db->f('date');
2604 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2605 $this->t->set_var('readonly','READONLY');
2606 $this->t->set_var('disabled','DISABLED');
2607 $this->t->set_var('lang_done','Done');
2608 $this->t->set_var('lang_action','Viewing PPI');
2609 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
2610 . $ppi . '&action=' . 'edit'));
2613 $this->t->set_var('lang_reset','Clear Form');
2614 $this->t->set_var('lang_add','Add PPI');
2615 $this->t->set_var('lang_save','Save Changes');
2616 $this->t->set_var('edithandle','');
2617 $this->t->set_var('addhandle','');
2619 $this->t->pfp('out','form');
2621 if($action == 'view') { $this->t->set_var('lang_save','Edit PPI'); }
2622 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2623 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2625 $this->save_sessiondata();
2630 $this->t->set_file(array('int_view_t' => 'int_view.tpl'));
2631 $this->t->set_block('int_view_t','district_list','list');
2633 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_view'));
2634 $num_quarters = get_var('num_quarters',array('GET','POST'));
2635 if($num_quarters == '') { $num_quarters = $this->default_int_num_quarters; }
2636 $this->t->set_var('num_quarters',$num_quarters);
2637 if($num_quarters == 1) { $this->t->set_var('lang_num_quarters','Quarter of History'); }
2638 else { $this->t->set_var('lang_num_quarters','Quarters of History'); }
2639 $this->t->set_var('lang_filter','Filter');
2641 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_view'));
2642 $this->t->set_var('int_link_title','Hometeaching Interviews');
2644 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_sched'));
2645 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
2647 $this->t->set_var('title','Hometeaching Interviews');
2649 $num_months = $num_quarters * 3 - 1;
2650 $current_month = $this->current_month;
2651 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
2652 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
2653 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
2654 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
2656 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
2657 $this->db->query($sql,__LINE__,__FILE__);
2659 while ($this->db->next_record())
2661 $districts[$i]['district'] = $this->db->f('district');
2662 $districts[$i]['name'] = $this->db->f('name');
2663 $districts[$i]['supervisor'] = $this->db->f('supervisor');
2667 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
2668 $this->db->query($sql,__LINE__,__FILE__);
2670 while ($this->db->next_record())
2672 $elder_id[$i] = $this->db->f('elder');
2673 $elder_name[$i] = $this->db->f('name');
2674 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
2677 array_multisort($elder_name, $elder_id);
2678 for($i=0; $i < count($elder_id); $i++) {
2679 $id = $elder_id[$i];
2680 $elders[$id] = $elder_name[$i];
2683 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
2684 $this->db->query($sql,__LINE__,__FILE__);
2685 while ($this->db->next_record())
2687 $aaronic_id = $this->db->f('aaronic');
2688 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
2689 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
2692 $total_companionships = 0;
2693 $this->nextmatchs->template_alternate_row_color(&$this->t);
2694 for ($i=0; $i < count($districts); $i++) {
2695 $this->t->set_var('district_number',$districts[$i]['district']);
2696 $this->t->set_var('district_name',$districts[$i]['name']);
2697 $supervisor = $districts[$i]['supervisor'];
2698 $unique_companionships='';
2700 // Select all the unique companionship numbers for this district
2701 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $districts[$i]['district'];
2703 $this->db->query($sql,__LINE__,__FILE__);
2705 while ($this->db->next_record())
2707 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
2711 $comp_width=250; $int_width=75; $table_width=$comp_width + $num_months*$int_width;
2712 $table_data=""; $num_companionships = $j; $num_elders = 0;
2713 for($m=$num_months; $m >= 0; $m--) { $ints[$m] = 0; }
2714 for ($j=0; $j < count($unique_companionships); $j++) {
2715 // Select all the companions in each companionship
2716 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
2717 "companionship=". $unique_companionships[$j]['companionship'];
2718 $this->db->query($sql,__LINE__,__FILE__);
2720 $comp = $unique_companionships[$j]['companionship'];
2721 for($m=$num_months; $m >= 0; $m--) { $int_recorded[$comp][$m] = 0; }
2722 while ($this->db->next_record())
2724 // Get this companions information
2726 $companionship = $this->db->f('companionship');
2727 $elder_id = $this->db->f('elder');
2728 $aaronic_id = $this->db->f('aaronic');
2730 $name = $elders[$elder_id];
2731 $phone = $elder_phone[$elder_id];
2733 else if($aaronic_id) {
2734 $name = $aaronic[$aaronic_id]['name'];
2735 $phone = $aaronic[$aaronic_id]['phone'];
2737 $link_data['menuaction'] = 'eq.eq.int_update';
2738 $link_data['companionship'] = $companionship;
2739 $link_data['interviewer'] = $supervisor;
2740 $link_data['elder'] = $elder_id;
2741 $link_data['aaronic'] = $aaronic_id;
2742 $link_data['name'] = $name;
2743 $link_data['ppi'] = '';
2744 $link_data['action'] = 'add';
2745 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2746 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2748 // Find out how many times Interviews were performed in the past $num_months for this Elder
2749 $header_row="<th width=$comp_width><font size=-2>Companionship</th>";
2750 for($m=$num_months; $m >= 0; $m--) {
2751 $month = $current_month - $m;
2752 $year = $this->current_year;
2753 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
2754 if($month < 10) { $month = "0"."$month"; }
2755 $month_start = "$year"."-"."$month"."-"."01";
2756 $month_end = "$year"."-"."$month"."-"."31";
2757 $month = "$month"."/"."$year";
2758 $sql = "SELECT * FROM eq_ppi WHERE date >= '$month_start' AND date <= '$month_end' ".
2759 "AND elder=" . $elder_id . " AND aaronic=" . $aaronic_id;
2760 $this->db2->query($sql,__LINE__,__FILE__);
2761 $header_row .= "<th width=$int_width><font size=-2>$month</th>";
2763 if(!$total_ints[$m]) { $total_ints[$m] = 0; }
2764 if($this->db2->next_record()) {
2765 if(!$int_recorded[$companionship][$m]) {
2766 $ints[$m]++; $total_ints[$m]++; $int_recorded[$companionship][$m]=1;
2768 $link_data['menuaction'] = 'eq.eq.int_update';
2769 $link_data['companionship'] = $companionship;
2770 $link_data['interviewer'] = $this->db2->f('interviewer');
2771 $link_data['elder'] = $elder_id;
2772 $link_data['aaronic'] = $aaronic_id;
2773 $link_data['name'] = $name;
2774 $link_data['ppi'] = $this->db2->f('ppi');
2775 $link_data['action'] = 'view';
2776 $date = $this->db2->f('date');
2777 $date_array = explode("-",$date);
2778 $month = $date_array[1];
2779 $day = $date_array[2];
2780 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2781 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2783 else { $table_data .= "<td> </td>"; }
2785 $table_data .= "</tr>";
2788 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2790 $total_companionships += $num_companionships;
2791 $stat_data = "<tr><td><b><font size=-2>$num_companionships Companionships<br>Interview Totals:</font></b></td>";
2793 // Print the hometeaching interview stats
2794 for($m=$num_months; $m >=0; $m--) {
2795 $month = $current_month - $m;
2796 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
2797 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
2798 //print "$month % $this->monthly_hometeaching_interview_stats = $month_begins <br>";
2799 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
2800 if(($month_begins) == 1) { $total = $ints[$m]; }
2801 else { $total += $ints[$m]; }
2802 $percent = ceil(($total / $num_companionships)*100);
2803 $stat_data .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
2805 $stat_data .= "</tr>";
2807 $this->t->set_var('table_width',$table_width);
2808 $this->t->set_var('header_row',$header_row);
2809 $this->t->set_var('table_data',$table_data);
2810 $this->t->set_var('stat_data',$stat_data);
2811 $this->t->fp('list','district_list',True);
2814 // Display the totals
2816 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>Interview Totals:</font></b></td>";
2817 for($m=$num_months; $m >=0; $m--) {
2818 $month = $current_month - $m;
2819 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
2820 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
2821 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
2822 if(($month_begins) == 1) { $total = $total_ints[$m]; }
2823 else { $total += $total_ints[$m]; }
2824 $percent = ceil(($total / $total_companionships)*100);
2825 $totals .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
2829 $this->t->set_var('totals',$totals);
2830 $this->t->pfp('out','int_view_t');
2831 $this->save_sessiondata();
2834 function int_update()
2836 $this->t->set_file(array('form' => 'int_update.tpl'));
2837 $this->t->set_block('form','interviewer_list','int_list');
2838 $this->t->set_block('form','add','addhandle');
2839 $this->t->set_block('form','edit','edithandle');
2841 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_view'));
2842 $this->t->set_var('readonly','');
2843 $this->t->set_var('disabled','');
2844 $this->t->set_var('eqpresppi_checked','');
2846 $action = get_var('action',array('GET','POST'));
2847 $companionship = get_var('companionship',array('GET','POST'));
2848 $interviewer = get_var('interviewer',array('GET','POST'));
2849 $name = get_var('name',array('GET','POST'));
2850 $ppi = get_var('ppi',array('GET','POST'));
2851 $elder = get_var('elder',array('GET','POST'));
2852 $aaronic = get_var('aaronic',array('GET','POST'));
2853 $date = get_var('date',array('GET','POST'));
2854 $notes = get_var('notes',array('GET','POST'));
2855 $eqpresppi = get_var('eqpresppi',array('GET','POST'));
2857 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
2858 $this->db->query($sql,__LINE__,__FILE__);
2859 while ($this->db->next_record())
2861 $supervisor = $this->db->f('supervisor');
2862 $sql = "SELECT * FROM eq_elder WHERE elder=" . $supervisor;
2863 $this->db2->query($sql,__LINE__,__FILE__);
2864 $this->db2->next_record();
2865 $interviewer_name = $this->db2->f('name');
2867 if($supervisor == $interviewer) {
2868 $this->t->set_var('interviewer',$supervisor . ' selected');
2870 $this->t->set_var('interviewer',$interviewer);
2872 $this->t->set_var('interviewer_name',$interviewer_name);
2873 $this->t->fp('int_list','interviewer_list',True);
2876 if($action == 'save')
2878 $notes = get_var('notes',array('POST'));
2879 $this->db->query("UPDATE eq_ppi set " .
2880 " ppi='" . $ppi . "'" .
2881 ", interviewer='" . $interviewer . "'" .
2882 ", elder='" . $elder . "'" .
2883 ", aaronic='" . $aaronic . "'" .
2884 ", date='" . $date . "'" .
2885 ", notes='" . $notes . "'" .
2886 ", eqpresppi='" . $eqpresppi . "'" .
2887 " WHERE ppi=" . $ppi,__LINE__,__FILE__);
2892 if($action == 'insert')
2894 $notes = get_var('notes',array('POST'));
2895 $this->db->query("INSERT INTO eq_ppi (interviewer,elder,aaronic,date,notes,eqpresppi) "
2896 . "VALUES ('" . $interviewer . "','" . $elder . "','" . $aaronic . "','"
2897 . $date . "','" . $notes ."','" . $eqpresppi . "')",__LINE__,__FILE__);
2902 if($action == 'add')
2904 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2905 $this->t->set_var('ppi', '');
2906 $this->t->set_var('interviewer', $interviewer);
2907 $this->t->set_var('name',$name);
2908 $this->t->set_var('elder',$elder);
2909 $this->t->set_var('aaronic',$aaronic);
2910 $this->t->set_var('date','');
2911 $this->t->set_var('notes','');
2912 $this->t->set_var('lang_done','Cancel');
2913 $this->t->set_var('lang_action','Adding New Interview');
2914 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_update&ppi='
2915 . $ppi . '&action=' . 'insert'));
2918 if($action == 'edit' || $action == 'view')
2920 $sql = "SELECT * FROM eq_ppi WHERE ppi=".$ppi;
2921 $this->db->query($sql,__LINE__,__FILE__);
2922 $this->db->next_record();
2923 $this->t->set_var('ppi',$ppi);
2924 $this->t->set_var('name',$name);
2925 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2926 $this->t->set_var('elder',$this->db->f('elder'));
2927 $this->t->set_var('aaronic',$this->db->f('aaronic'));
2928 $this->t->set_var('date',$this->db->f('date'));
2929 $this->t->set_var('notes',$this->db->f('notes'));
2930 if($this->db->f('eqpresppi') == 1) { $this->t->set_var('eqpresppi_checked','checked'); }
2933 if($action == 'edit')
2935 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2936 $this->t->set_var('lang_done','Cancel');
2937 $this->t->set_var('lang_action','Editing Interview');
2938 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_update&ppi='
2939 . $ppi . '&action=' . 'save'));
2942 if($action == 'view')
2944 $date = $this->db->f('date');
2945 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2946 $this->t->set_var('readonly','READONLY');
2947 $this->t->set_var('disabled','DISABLED');
2948 $this->t->set_var('lang_done','Done');
2949 $this->t->set_var('lang_action','Viewing Interview');
2950 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_update&ppi='
2951 . $ppi . '&action=' . 'edit'));
2954 $this->t->set_var('lang_reset','Clear Form');
2955 $this->t->set_var('lang_add','Add Interview');
2956 $this->t->set_var('lang_save','Save Changes');
2957 $this->t->set_var('edithandle','');
2958 $this->t->set_var('addhandle','');
2960 $this->t->pfp('out','form');
2962 if($action == 'view') { $this->t->set_var('lang_save','Edit Interview'); }
2963 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2964 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2966 $this->save_sessiondata();
2971 $this->t->set_file(array('vis_view_t' => 'vis_view.tpl'));
2972 $this->t->set_block('vis_view_t','visit_list','list1');
2973 $this->t->set_block('vis_view_t','family_list','list2');
2975 $this->t->set_var('lang_name','Family Name');
2976 $this->t->set_var('lang_date','Date');
2978 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
2979 $this->t->set_var('vis_link_title','View Yearly Visits');
2981 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched'));
2982 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2984 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
2985 $num_years = get_var('num_years',array('GET','POST'));
2986 if($num_years == '') { $num_years = $this->default_vis_num_years; }
2987 $this->t->set_var('num_years',$num_years);
2988 if($num_years == 1) { $this->t->set_var('lang_num_years','Year of History'); }
2989 else { $this->t->set_var('lang_num_years','Years of History'); }
2990 $this->t->set_var('lang_filter','Filter');
2992 $year = date('Y') - $num_years + 1;
2993 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2995 $sql = "SELECT * FROM eq_visit WHERE companionship=0 and date > '$year_start' ORDER BY date DESC";
2996 $this->db->query($sql,__LINE__,__FILE__);
2997 $total_records = $this->db->num_rows();
3000 while ($this->db->next_record())
3002 $visit_list[$i]['visit'] = $this->db->f('visit');
3003 $visit_list[$i]['family'] = $this->db->f('family');
3004 $visit_list[$i]['date'] = $this->db->f('date');
3008 for ($i=0; $i < count($visit_list); $i++)
3010 $this->nextmatchs->template_alternate_row_color(&$this->t);
3012 $sql = "SELECT * FROM eq_family WHERE family=".$visit_list[$i]['family'];
3013 $this->db->query($sql,__LINE__,__FILE__);
3014 $this->db->next_record();
3016 $this->t->set_var('family',$visit_list[$i]['family']);
3017 $this->t->set_var('family_name',$this->db->f('name'));
3018 $this->t->set_var('date',$visit_list[$i]['date']);
3020 $link_data['menuaction'] = 'eq.eq.vis_update';
3021 $link_data['visit'] = $visit_list[$i]['visit'];
3022 $link_data['name'] = $this->db->f('name');
3023 $link_data['date'] = $visit_list[$i]['date'];
3024 $link_data['action'] = 'view';
3025 $this->t->set_var('view',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
3026 $this->t->set_var('lang_view','View');
3028 $link_data['menuaction'] = 'eq.eq.vis_update';
3029 $link_data['visit'] = $visit_list[$i]['visit'];
3030 $link_data['name'] = $this->db->f('name');
3031 $link_data['date'] = $visit_list[$i]['date'];
3032 $link_data['action'] = 'edit';
3033 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
3034 $this->t->set_var('lang_edit','Edit');
3036 $this->t->fp('list1','visit_list',True);
3039 // List the families that are available to record a visit against
3040 $sql = "SELECT * FROM eq_family WHERE valid=1";
3041 $this->db->query($sql,__LINE__,__FILE__);
3042 $total_records = $this->db->num_rows();
3045 while ($this->db->next_record())
3047 $family_names[$i] = $this->db->f('name');
3048 $family_ids[$i] = $this->db->f('family');
3050 } array_multisort($family_names, $family_ids);
3052 for ($i=0; $i < count($family_names); $i++)
3054 $link_data['menuaction'] = 'eq.eq.vis_update';
3055 $link_data['visit'] = '';
3056 $link_data['family'] = $family_ids[$i];
3057 $link_data['action'] = 'add';
3058 $link_data['name'] = $family_names[$i];
3059 $this->t->set_var('add',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
3061 $this->t->set_var('name',$family_names[$i]);
3062 if(($i+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
3063 else { $this->t->set_var('table_sep',"</td>"); }
3064 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
3066 $this->t->fp('list2','family_list',True);
3069 $this->t->pfp('out','vis_view_t');
3070 $this->save_sessiondata();
3073 function vis_update()
3075 $this->t->set_file(array('form' => 'vis_update.tpl'));
3076 $this->t->set_block('form','add','addhandle');
3077 $this->t->set_block('form','edit','edithandle');
3079 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
3080 $this->t->set_var('readonly','');
3081 $this->t->set_var('disabled','');
3083 $action = get_var('action',array('GET','POST'));
3084 $visit = get_var('visit',array('GET','POST'));
3085 $family = get_var('family',array('GET','POST'));
3086 $name = get_var('name',array('GET','POST'));
3087 $date = get_var('date',array('GET','POST'));
3088 $notes = get_var('notes',array('GET','POST'));
3091 if($action == 'save')
3093 $notes = get_var('notes',array('POST'));
3094 $this->db->query("UPDATE eq_visit set " .
3095 " date='" . $date . "'" .
3096 ", notes='" . $notes . "'" .
3097 " WHERE visit=" . $visit,__LINE__,__FILE__);
3102 if($action == 'insert')
3104 $notes = get_var('notes',array('POST'));
3105 $this->db->query("INSERT INTO eq_visit (family,companionship,date,notes) "
3106 . "VALUES ('" . $family . "','" . $companionship . "','"
3107 . $date . "','" . $notes . "')",__LINE__,__FILE__);
3112 if($action == 'add')
3114 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
3115 $this->t->set_var('family', $family);
3116 $this->t->set_var('visit', '');
3117 $this->t->set_var('name', $name);
3118 $this->t->set_var('date','');
3119 $this->t->set_var('notes','');
3120 $this->t->set_var('lang_done','Cancel');
3121 $this->t->set_var('lang_action','Adding New Visit');
3122 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&family='
3123 . $family . '&action=' . 'insert'));
3126 if($action == 'edit' || $action == 'view')
3128 $sql = "SELECT * FROM eq_visit WHERE visit=".$visit;
3129 $this->db->query($sql,__LINE__,__FILE__);
3130 $this->db->next_record();
3131 $this->t->set_var('visit',$visit);
3132 $this->t->set_var('name',$name);
3133 $this->t->set_var('family', $family);
3134 $this->t->set_var('date',$this->db->f('date'));
3135 $this->t->set_var('notes',$this->db->f('notes'));
3138 if($action == 'edit')
3140 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
3141 $this->t->set_var('lang_done','Cancel');
3142 $this->t->set_var('lang_action','Editing Visit');
3143 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&visit='
3144 . $visit . '&action=' . 'save'));
3147 if($action == 'view')
3149 $date = $this->db->f('date');
3150 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
3151 $this->t->set_var('readonly','READONLY');
3152 $this->t->set_var('disabled','DISABLED');
3153 $this->t->set_var('lang_done','Done');
3154 $this->t->set_var('lang_action','Viewing Visit');
3155 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&visit='
3156 . $visit . '&action=' . 'edit'));
3159 $this->t->set_var('lang_reset','Clear Form');
3160 $this->t->set_var('lang_add','Add Visit');
3161 $this->t->set_var('lang_save','Save Changes');
3162 $this->t->set_var('edithandle','');
3163 $this->t->set_var('addhandle','');
3165 $this->t->pfp('out','form');
3167 if($action == 'view') { $this->t->set_var('lang_save','Edit Visit'); }
3168 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
3169 if($action == 'add') { $this->t->pfp('addhandle','add'); }
3171 $this->save_sessiondata();
3176 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3177 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3178 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3180 $this->t->set_file(array('att_view_t' => 'att_view.tpl'));
3181 $this->t->set_block('att_view_t','act_list','list');
3183 $this->t->set_block('att_view_t','month_list','list1');
3184 $this->t->set_block('att_view_t','header_list','list2');
3185 $this->t->set_block('att_view_t','elder_list','list3');
3187 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_view'));
3188 $num_quarters = get_var('num_quarters',array('GET','POST'));
3189 if($num_quarters == '') { $num_quarters = $this->default_att_num_quarters; }
3190 $this->t->set_var('num_quarters',$num_quarters);
3191 $this->t->set_var('lang_filter','Filter');
3192 if($num_quarters == 1) { $this->t->set_var('lang_num_quarters','Quarter of History'); }
3193 else { $this->t->set_var('lang_num_quarters','Quarters of History'); }
3195 $num_months = $num_quarters * 3;
3196 $current_month = $this->current_month;
3197 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
3198 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
3199 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
3200 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
3202 $sql = "SELECT * FROM eq_elder where valid=1";
3203 $this->db->query($sql,__LINE__,__FILE__);
3205 while ($this->db->next_record())
3207 $elder_name[$i] = $this->db->f('name');
3208 $elder_id[$i] = $this->db->f('elder');
3211 array_multisort($elder_name, $elder_id);
3213 // Create a list of sunday dates for a window of 3 months back and current month
3217 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, ($current_month-$num_months)+1, 1, date("y")));
3218 $last_date = explode("-",$sunday_list[0]['date']);
3219 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3220 $time_limit = mktime(0, 0, 0, $current_month, 31, date("y"));
3221 while($last_time < $time_limit)
3223 $day = date("w",$last_time);
3224 if(date("w",$last_time) == 0) {
3225 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3226 $last_date = explode("-",$sunday_list[$i]['date']);
3227 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3228 $sunday_list[$i]['day'] = $last_date[2];
3229 $sunday_list[$i]['month'] = date("M",$last_time);
3230 $sunday_list[$i]['year'] = $last_date[0];
3232 $last_date = $sunday_list[$i]['date'];
3234 $last_time += 90000;
3235 if($found_sunday) { $i++; $found_sunday=0; }
3238 $total_elders = count($elder_id);
3239 $old_month=$sunday_list[0]['month']; $span=0;
3240 for ($i=0; $i < count($sunday_list); $i++) {
3241 $date = $sunday_list[$i]['date'];
3242 $this->t->set_var('date',$sunday_list[$i]['date']);
3243 $this->t->set_var('day',$sunday_list[$i]['day']);
3244 if(($old_month != $sunday_list[$i]['month']) || $i == count($sunday_list)-1) {
3245 if($i == count($sunday_list)-1) { $span++; }
3246 $cur_month = $sunday_list[$i]['month'];
3247 $old_month = $sunday_list[$i]['month'];
3248 $link_data['menuaction'] = 'eq.eq.att_update';
3249 $link_data['month'] = $sunday_list[$i-1]['month'];
3250 $link_data['year'] = $sunday_list[$i-1]['year'];
3251 $link_data['action'] = 'update_month';
3252 $cur_month = $sunday_list[$i-1]['month'];
3253 $cur_year = $sunday_list[$i-1]['year'];
3254 $header_row .= "<th><font size=-3>$cur_month $cur_year</font></th>";
3255 $this->t->set_var('update_month',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
3256 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3257 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3258 $this->t->set_var('span',$span); $span=0;
3259 $this->t->fp('list1','month_list',True);
3262 $this->t->set_var('total_elders',$total_elders);
3263 $this->t->set_var('header_row',$header_row);
3265 $elder_width=200; $att_width=25; $total_width=$elder_width;
3266 for ($i=0; $i < count($sunday_list); $i++) {
3267 $link_data['menuaction'] = 'eq.eq.att_update';
3268 $link_data['month'] = $sunday_list[$i]['month'];
3269 $link_data['year'] = $sunday_list[$i]['year'];
3270 $link_data['day'] = $sunday_list[$i]['day'];
3271 $link_data['date'] = $sunday_list[$i]['date'];
3272 $link_data['action'] = 'update_day';
3273 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
3274 $this->t->set_var('date',$sunday_list[$i]['date']);
3275 $this->t->set_var('day',$sunday_list[$i]['day']);
3276 $this->t->set_var('month',$sunday_list[$i]['month']);
3277 $this->t->set_var('year',$sunday_list[$i]['year']);
3278 $this->t->fp('list2','header_list',True);
3279 $total_width += $att_width;
3280 $attendance[$monthnum[$sunday_list[$i]['month']]]=0;
3283 for ($i=0; $i < count($elder_id); $i++) {
3285 $this->nextmatchs->template_alternate_row_color(&$this->t);
3286 $this->t->set_var('elder_name',$elder_name[$i]);
3287 #print "checking for elder: " . $elder_id[$i] . "<br>";
3288 for ($j=0; $j < count($sunday_list); $j++) {
3289 #print "checking for date: " . $sunday_list[$j]['date'] . "<br>";
3290 #print "SELECT * FROM eq_attendance WHERE date='"
3291 # . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i] . "<br>";
3292 $sql = "SELECT * FROM eq_attendance WHERE date='"
3293 . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i];
3294 $this->db->query($sql,__LINE__,__FILE__);
3295 if($this->db->next_record()) {
3296 $cur_month = $sunday_list[$j]['month'];
3297 if($attended[$i][$cur_month] != 1) {
3298 $attended[$i][$cur_month]=1;
3299 $attendance[$monthnum[$cur_month]]++;
3301 $att_table .= '<td align=center><img src="images/checkmark.gif"></td>';
3303 $att_table .= '<td> </td>';
3306 $this->t->set_var('att_table',$att_table);
3307 $this->t->fp('list3','elder_list',True);
3309 $this->t->set_var('total_width',$total_width);
3310 $this->t->set_var('elder_width',$elder_width);
3311 $this->t->set_var('att_width',$att_width);
3313 # Now calculate attendance for these months
3314 $attendance_str = "";
3315 $nonattendance_str = "";
3316 $aveattendance_str = "";
3317 $avenonattendance_str = "";
3319 $ave_total_attended=0;
3321 foreach($attendance as $att => $value) {
3322 $total_attended = $attendance[$att];
3323 $ave_total_attended += $attendance[$att]; $num_months++;
3324 $percent = ceil(($total_attended / $total_elders)*100);
3325 $attendance_str.="<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3326 $total_nonattended = $total_elders - $total_attended;
3327 $percent = ceil(($total_nonattended / $total_elders)*100);
3328 $nonattendance_str.="<td align=center><font size=-2><b>$total_nonattended ($percent%)</b></font></td>";
3330 $total_attended = ceil(($ave_total_attended / $num_months));
3331 $percent = ceil(($total_attended / $total_elders)*100);
3332 $aveattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3333 $total_attended = $total_elders - ceil(($ave_total_attended / $num_months));
3334 $percent = ceil(($total_attended / $total_elders)*100);
3335 $avenonattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3338 $this->t->set_var('attendance',$attendance_str);
3339 $this->t->set_var('aveattendance',$aveattendance_str);
3340 $this->t->set_var('nonattendance',$nonattendance_str);
3341 $this->t->set_var('avenonattendance',$avenonattendance_str);
3343 $this->t->pfp('out','att_view_t');
3344 $this->save_sessiondata();
3347 function att_update()
3349 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3350 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3351 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3353 $this->t->set_file(array('form' => 'att_update.tpl'));
3354 $this->t->set_block('form','edit','edithandle');
3356 $this->t->set_block('form','month_list','list1');
3357 $this->t->set_block('form','header_list','list2');
3358 $this->t->set_block('form','elder_list','list3');
3360 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_view'));
3362 $action = get_var('action',array('GET','POST'));
3363 $month = get_var('month',array('GET','POST'));
3364 $year = get_var('year',array('GET','POST'));
3365 $day = get_var('day',array('GET','POST'));
3366 $date = get_var('date',array('GET','POST'));
3368 if($action == 'save_month' || $action == 'save_day')
3370 $new_data = get_var('elders_attended',array('POST'));
3371 $month = $monthnum[$month]; if($month < 10) { $month = "0" . $month; }
3373 if($action == 'save_month') {
3374 $this->db->query("DELETE from eq_attendance where date LIKE '".$year."-".$month."-%'",__LINE__,__FILE__);
3377 if($action == 'save_day') {
3378 $this->db->query("DELETE from eq_attendance where date LIKE '".$year."-".$month."-".$day."'",__LINE__,__FILE__);
3381 foreach ($new_data as $data)
3383 $data_array = explode("-",$data);
3384 $elder = $data_array[0];
3385 $date = "$data_array[1]-$data_array[2]-$data_array[3]";
3386 $this->db->query("INSERT INTO eq_attendance (elder,date) "
3387 . "VALUES (" . $elder . ",'". $date . "')",__LINE__,__FILE__);
3394 $sql = "SELECT * FROM eq_elder where valid=1";
3395 $this->db->query($sql,__LINE__,__FILE__);
3397 while ($this->db->next_record())
3399 $elder_name[$i] = $this->db->f('name');
3400 $elder_id[$i] = $this->db->f('elder');
3401 $elder_attending[$elder_id[$i]] = $this->db->f('attending');
3404 array_multisort($elder_name, $elder_id);
3406 if($action == 'update_month')
3408 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_update&action=save_month'));
3412 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], 1, $year));
3413 $last_date = explode("-",$sunday_list[0]['date']);
3414 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3415 $time_limit = mktime(0, 0, 0, $monthnum[$month], 31, $year);
3416 while($last_time <= $time_limit)
3418 $day = date("w",$last_time);
3419 if(date("w",$last_time) == 0) {
3420 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3421 $last_date = explode("-",$sunday_list[$i]['date']);
3422 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3423 $sunday_list[$i]['day'] = $last_date[2];
3424 $sunday_list[$i]['month'] = date("M",$last_time);
3425 $sunday_list[$i]['year'] = $last_date[0];
3428 $last_time += 90000;
3429 if($found_sunday) { $i++; $found_sunday=0; }
3432 $this->t->set_var('span', $i);
3433 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3434 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3435 $this->t->fp('list1','month_list',True);
3436 $elder_width=200; $att_width=25; $total_width=$elder_width;
3437 for ($i=0; $i < count($sunday_list); $i++) {
3438 $link_data['menuaction'] = 'eq.eq.att_update';
3439 $link_data['month'] = $sunday_list[$i]['month'];
3440 $link_data['year'] = $sunday_list[$i]['year'];
3441 $link_data['day'] = $sunday_list[$i]['day'];
3442 $link_data['date'] = $sunday_list[$i]['date'];
3443 $link_data['action'] = 'update_day';
3444 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
3445 $this->t->set_var('date',$sunday_list[$i]['date']);
3446 $this->t->set_var('day',$sunday_list[$i]['day']);
3447 $this->t->set_var('month',$sunday_list[$i]['month']);
3448 $this->t->set_var('year',$sunday_list[$i]['year']);
3449 $this->t->fp('list2','header_list',True);
3450 $total_width += $att_width;
3454 if($action == 'update_day')
3456 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_update&action=save_day'));
3457 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], $day, $year));
3458 $this->t->set_var('month',$month);
3459 $this->t->set_var('year',$year);
3460 $this->t->fp('list1','month_list',True);
3461 $this->t->set_var('date',$date);
3462 $this->t->set_var('day',$day);
3463 $this->t->set_var('month',$month);
3464 $this->t->set_var('year',$year);
3465 $this->t->fp('list2','header_list',True);
3468 for ($i=0; $i < count($elder_id); $i++) {
3470 $this->nextmatchs->template_alternate_row_color(&$this->t);
3471 $this->t->set_var('elder_name',$elder_name[$i]);
3472 for ($j=0; $j < count($sunday_list); $j++) {
3473 $sql = "SELECT * FROM eq_attendance WHERE date='"
3474 . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i];
3475 $this->db->query($sql,__LINE__,__FILE__);
3476 $value = $elder_id[$i] . "-" . $sunday_list[$j]['date'];
3477 if($this->db->next_record()) {
3478 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'" checked></td>';
3479 } else if($elder_attending[$elder_id[$i]] == 1) {
3480 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'" checked></td>';
3482 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'"></td>';
3485 $this->t->set_var('att_table',$att_table);
3486 $this->t->fp('list3','elder_list',True);
3489 $this->t->set_var('lang_done', 'Cancel');
3490 $this->t->set_var('lang_reset','Clear Form');
3491 $this->t->set_var('lang_save','Save Changes');
3493 $this->t->pfp('out','form');
3494 $this->t->pfp('addhandle','edit');
3496 $this->save_sessiondata();
3501 $this->t->set_file(array('dir_view_t' => 'dir_view.tpl'));
3502 $this->t->set_block('dir_view_t','dir_list','list');
3504 $sql = "SELECT * FROM eq_parent where valid=1 ORDER BY name ASC";
3505 $this->db->query($sql,__LINE__,__FILE__);
3507 while ($this->db->next_record())
3509 $parent[$i]['id'] = $this->db->f('parent');
3510 $parent[$i]['name'] = $this->db->f('name');
3511 $parent[$i]['phone'] = $this->db->f('phone');
3512 $parent[$i]['address'] = $this->db->f('address');
3516 for ($i=0; $i < count($parent); $i++)
3518 $name = $parent[$i]['name'];
3519 $phone = $parent[$i]['phone'];
3520 $address = $parent[$i]['address'];
3521 $this->t->set_var('name', $name);
3522 $this->t->set_var('address', $address);
3523 $this->t->set_var('phone', $phone);
3524 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3525 $this->t->set_var('tr_color',$tr_color);
3526 $this->t->fp('list','dir_list',True);
3527 //print "$phone $name $address<br>";
3529 $this->t->pfp('out','dir_view_t');
3530 $this->save_sessiondata();
3535 $this->t->set_file(array('org_view_t' => 'org_view.tpl'));
3536 $this->t->set_block('org_view_t','calling_list','list1');
3537 $this->t->set_block('org_view_t','org_list','list2');
3539 # Display a list ordered alphabetically
3540 $sql = "SELECT * FROM eq_calling ORDER BY name ASC";
3541 $this->db->query($sql,__LINE__,__FILE__);
3543 while ($this->db->next_record())
3545 $calling[$i]['id'] = $this->db->f('indiv_id');
3546 $calling[$i]['name'] = $this->db->f('name');
3547 $calling[$i]['position'] = $this->db->f('position');
3548 $calling[$i]['sustained'] = $this->db->f('sustained');
3549 $calling[$i]['organization'] = $this->db->f('organization');
3552 for ($i=0; $i < count($calling); $i++)
3554 $name = $calling[$i]['name'];
3555 $position = $calling[$i]['position'];
3556 $sustained = $calling[$i]['sustained'];
3557 $organization = $calling[$i]['organization'];
3558 $this->t->set_var('name', $name);
3559 $this->t->set_var('position', $position);
3560 $this->t->set_var('sustained', $sustained);
3561 $this->t->set_var('organization', $organization);
3562 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3563 $this->t->set_var('tr_color',$tr_color);
3564 $this->t->fp('list1','calling_list',True);
3567 # Display a list ordered by organization
3568 $sql = "SELECT * FROM eq_calling ORDER BY sequence ASC";
3569 $this->db->query($sql,__LINE__,__FILE__);
3571 while ($this->db->next_record())
3573 $calling[$i]['id'] = $this->db->f('indiv_id');
3574 $calling[$i]['name'] = $this->db->f('name');
3575 $calling[$i]['position'] = $this->db->f('position');
3576 $calling[$i]['sustained'] = $this->db->f('sustained');
3577 $calling[$i]['organization'] = $this->db->f('organization');
3580 for ($i=0; $i < count($calling); $i++)
3582 $name = $calling[$i]['name'];
3583 $position = $calling[$i]['position'];
3584 $sustained = $calling[$i]['sustained'];
3585 $organization = $calling[$i]['organization'];
3586 $this->t->set_var('name', $name);
3587 $this->t->set_var('position', $position);
3588 $this->t->set_var('sustained', $sustained);
3589 $this->t->set_var('organization', $organization);
3590 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3591 $this->t->set_var('tr_color',$tr_color);
3592 $this->t->fp('list2','org_list',True);
3595 $this->t->pfp('out','org_view_t');
3596 $this->save_sessiondata();
3601 $this->t->set_file(array('sched_t' => 'schedule.tpl'));
3602 $this->t->set_block('sched_t','presidency_list','list');
3604 $action = get_var('action',array('GET','POST'));
3606 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.schedule&action=save'));
3607 $this->t->set_var('title','EQ Scheduling Tool');
3609 $this->t->set_var('lang_save','Save Schedule');
3610 $this->t->set_var('lang_reset','Cancel');
3612 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched'));
3613 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
3615 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_sched'));
3616 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
3618 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched'));
3619 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
3621 $date_width=150; $time_width=225; $elder_width=200; $family_width=200; $location_width=100;
3622 $table_width=$date_width + $time_width + $elder_width + $family_width + $location_width;
3623 $header_row = "<th width=$date_width><font size=-2>Date</th>";
3624 $header_row.= "<th width=$time_width><font size=-2>Time</th>";
3625 $header_row.= "<th width=$elder_width><font size=-2>Elder</th>";
3626 $header_row.= "<th width=$family_width><font size=-2>Family</th>";
3627 $header_row.= "<th width=$location_width><font size=-2>Location</th>";
3630 $sql = "SELECT * FROM eq_presidency where valid=1";
3631 $this->db->query($sql,__LINE__,__FILE__);
3633 while ($this->db->next_record())
3635 $presidency_data[$i]['id'] = $this->db->f('presidency');
3636 $presidency_data[$i]['name'] = $this->db->f('name');
3637 $presidency_data[$i]['elder'] = $this->db->f('elder');
3638 $presidency2name[$presidency_data[$i]['id']] = $presidency_data[$i]['name'];
3642 $sql = "SELECT * FROM eq_family where valid=1 and elder_id != 0 ORDER BY name ASC";
3643 $this->db->query($sql,__LINE__,__FILE__);
3645 while ($this->db->next_record())
3647 $family_id[$i] = $this->db->f('family');
3648 $family_name[$i] = $this->db->f('name');
3649 $familyid2name[$family_id[$i]] = $family_name[$i];
3650 $sql = "SELECT * FROM eq_parent where family='$family_id[$i]'";
3651 $this->db2->query($sql,__LINE__,__FILE__);
3652 if($this->db2->next_record()) {
3653 $familyid2address[$family_id[$i]] = $this->db2->f('address');
3657 array_multisort($family_name, $family_id);
3659 if($action == 'save')
3661 $new_data = get_var('sched',array('POST'));
3662 foreach ($new_data as $presidency_array)
3664 foreach ($presidency_array as $entry)
3666 $presidency = $entry['presidency'];
3667 $appointment = $entry['appointment'];
3668 $location = $entry['location'];
3669 $date = $entry['date'];
3670 $hour = $entry['hour'];
3671 $minute = $entry['minute'];
3673 $elder = $entry['elder'];
3674 $family = $entry['family'];
3675 $location = $entry['location'];
3676 if($pm) { $hour = $hour + 12; }
3677 $time = $hour.':'.$minute.':'.'00';
3680 // Update our location
3681 if($location == "") {
3683 $family_name_array = explode(",", $familyid2name[$family]);
3684 $family_last_name = $family_name_array[0];
3685 $family_address = $familyid2address[$family];
3686 $location = "$family_last_name"." home ($family_address)";
3688 else if($elder > 0) {
3689 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
3690 $supervisor_last_name = $supervisor_name_array[0];
3691 $location = "$supervisor_last_name"." home";
3695 // Zero out the family or elder if date = NULL
3702 if(($elder == 0) && ($family == 0)) { $location = ""; }
3704 // Update an existing appointment
3705 if($appointment < $this->max_appointments)
3707 //Only perform a database update if we have made a change to this appointment
3708 $sql = "SELECT * FROM eq_appointment where " .
3709 "appointment='$appointment'" .
3710 " and presidency='$presidency'" .
3711 " and elder='$elder'" .
3712 " and family='$family'" .
3713 " and date='$date'" .
3714 " and time='$time'" .
3715 " and location='$location'";
3716 $this->db->query($sql,__LINE__,__FILE__);
3717 if(!$this->db->next_record()) {
3718 $old_date = $this->db->f('date');
3719 $old_time = $this->db->f('time');
3720 $this->db2->query("UPDATE eq_appointment set" .
3721 " family=" . $family .
3722 " ,elder=" . $elder .
3723 " ,date='" . $date . "'" .
3724 " ,time='" . $time . "'" .
3725 " ,location='" . $location . "'" .
3726 " ,presidency='" . $presidency . "'" .
3727 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
3729 // Email the appointment
3730 $this->email_appt($appointment);
3734 // Add a new appointment
3735 else if(($appointment >= $this->max_appointments) && ($date != "") && ($time != ""))
3737 //print "adding entry: appt=$appointment date: $date time: $time elder: $elder family: $family<br>";
3738 $this->db2->query("INSERT INTO eq_appointment (appointment,presidency,family,elder,date,time,location,uid) "
3739 . "VALUES (NULL,'" . $presidency . "','" . $family . "','" . $elder . "','"
3740 . $date . "','" . $time . "','" . $location . "','" . $uid ."')",__LINE__,__FILE__);
3742 // Now reselect this entry from the database to see if we need
3743 // to send an appointment out for it.
3744 $sql = "SELECT * FROM eq_appointment where " .
3746 " and family='$family'" .
3747 " and presidency='$presidency'" .
3748 " and date='$date'" .
3749 " and time='$time'" .
3751 " and location='$location'";
3752 $this->db3->query($sql,__LINE__,__FILE__);
3753 if($this->db3->next_record()) {
3754 // Email the appointment if warranted
3755 if(($date != "") && ($time != "") && (($elder > 0) || $family > 0)) {
3756 $this->email_appt($this->db3->f('appointment'));
3763 $take_me_to_url = $GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.schedule');
3764 //Header('Location: ' . $take_me_to_url);
3767 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
3768 $this->db->query($sql,__LINE__,__FILE__);
3770 while ($this->db->next_record())
3772 $elder_id[$i] = $this->db->f('elder');
3773 $elder_name[$i] = $this->db->f('name');
3774 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
3777 array_multisort($elder_name, $elder_id);
3779 for ($i=0; $i < count($presidency_data); $i++) {
3780 $presidency = $presidency_data[$i]['id'];
3781 $interviewer = $presidency_data[$i]['elder'];
3782 $name = $presidency_data[$i]['name'];
3783 $this->t->set_var('presidency_name',$name);
3786 // query the database for all the appointments
3787 $sql = "SELECT * FROM eq_appointment where presidency=$presidency and date>=CURDATE() ORDER BY date ASC, time ASC";
3788 $this->db->query($sql,__LINE__,__FILE__);
3790 // Prefill any existing appointment slots
3791 while ($this->db->next_record())
3793 $appointment = $this->db->f('appointment');
3794 $elder = $this->db->f('elder');
3795 $family = $this->db->f('family');
3796 $location = $this->db->f('location');
3798 if($location == "") {
3800 $family_name_array = explode(",", $familyid2name[$family]);
3801 $family_last_name = $family_name_array[0];
3802 $family_address = $familyid2address[$family];
3803 $location = "$family_last_name"." home ($family_address)";
3805 else if($elder > 0) {
3806 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
3807 $supervisor_last_name = $supervisor_name_array[0];
3808 $location = "$supervisor_last_name"." home";
3812 $date = $this->db->f('date');
3813 $date_array = explode("-",$date);
3814 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
3815 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
3817 $time = $this->db->f('time');
3818 $time_array = explode(":",$time);
3819 $hour = $time_array[0];
3820 $minute = $time_array[1];
3822 if($hour > 12) { $pm=1; $hour = $hour - 12; }
3823 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
3825 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3828 $table_data.= '<td align=left>';
3829 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]',$date,'','','','','',$this->cal_options);
3830 $table_data.= '</td>';
3832 // Hour & Minutes selection
3833 $table_data.= "<td align=center>";
3834 $table_data .= $this->get_time_selection_form($hour, $minute, $pm, $presidency, $appointment);
3835 $table_data.= "</td>";
3837 // Elder drop down list (for PPIs)
3838 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][elder]>';
3839 $table_data.= '<option value=0></option>';
3840 for ($j=0; $j < count($elder_id); $j++) {
3841 $id = $elder_id[$j];
3842 $name = $elder_name[$j];
3843 if($elder_id[$j] == $elder) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
3844 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
3846 $table_data.='</select></td>';
3848 // Family drop down list (for Visits)
3849 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family]>';
3850 $table_data.= '<option value=0></option>';
3851 for ($j=0; $j < count($elder_id); $j++) {
3852 $id = $family_id[$j];
3853 $name = $family_name[$j];
3854 if($family_id[$j] == $family) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
3855 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
3857 $table_data.='</select></td>';
3859 // Location text box
3860 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
3861 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="'.$location.'">';
3863 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3864 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3866 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3867 $this->t->set_var('tr_color',$tr_color);
3871 // Create blank appointment slot
3872 for ($b=0; $b < 4; $b++) {
3873 $appointment = $this->max_appointments + $b;
3874 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3877 $table_data.= '<td align=left>';
3878 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]','','','','','','',$this->cal_options);
3879 $table_data.= '</td>';
3882 $table_data.= "<td align=center>";
3883 $table_data .= $this->get_time_selection_form(0, 0, 0, $presidency, $appointment);
3884 $table_data.= "</td>";
3886 // Elder drop down list
3887 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][elder]>';
3888 $table_data.= '<option value=0></option>';
3889 for ($j=0; $j < count($elder_id); $j++) {
3890 $id = $elder_id[$j];
3891 $name = $elder_name[$j];
3892 $table_data.= '<option value='.$id.'>'.$name.'</option>';
3894 $table_data.='</select></td>';
3896 // Family drop down list
3897 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family]>';
3898 $table_data.= '<option value=0></option>';
3899 for ($j=0; $j < count($elder_id); $j++) {
3900 $id = $family_id[$j];
3901 $name = $family_name[$j];
3902 $table_data.= '<option value='.$id.'>'.$name.' Family</option>';
3904 $table_data.='</select></td>';
3906 // Location text box
3907 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
3908 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="">';
3910 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3911 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3913 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3914 $this->t->set_var('tr_color',$tr_color);
3917 $this->t->set_var('table_data',$table_data);
3918 $this->t->set_var('header_row',$header_row);
3919 $this->t->set_var('table_width',$table_width);
3920 $this->t->fp('list','presidency_list',True);
3924 $this->t->pfp('out','sched_t');
3925 $this->save_sessiondata();
3930 $this->t->set_file(array('email_t' => 'email.tpl'));
3931 $this->t->set_block('email_t','elder_list','list');
3933 $action = get_var('action',array('GET','POST'));
3935 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.email'));
3936 $this->t->set_var('title','EQ Email Tool');
3938 $this->t->set_var('lang_email','Send Email');
3939 $this->t->set_var('lang_reset','Cancel');
3941 $this->t->set_var('email_member_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.email&action=member'));
3942 $this->t->set_var('email_member_link_title','Email Quorum Member');
3944 $this->t->set_var('email_quorum_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.email&action=quorum'));
3945 $this->t->set_var('email_quorum_link_title','Email Quorum');
3947 $this->t->set_var('email_reminder_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.email&action=reminder'));
3948 $this->t->set_var('email_reminder_link_title','Email Reminders');
3950 $this->t->set_var('email_edit_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.email&action=edit'));
3951 $this->t->set_var('email_edit_link_title','Edit Email Addresses');
3954 $this->t->set_var('table_width',$table_width);
3956 $this->t->pfp('out','email_t');
3957 $this->save_sessiondata();
3962 $this->t->set_file(array('admin_t' => 'admin.tpl'));
3963 $this->t->set_block('admin_t','upload','uploadhandle');
3964 $this->t->set_block('admin_t','admin','adminhandle');
3965 $this->t->set_block('admin_t','cmd','cmdhandle');
3966 $this->t->set_block('admin_t','presidency','presidencyhandle');
3968 $this->t->set_var('upload_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.admin&action=upload'));
3969 $this->t->set_var('presidency_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.admin&action=presidency'));
3971 $action = get_var('action',array('GET','POST'));
3973 $this->t->pfp('out','admin_t');
3975 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
3976 $this->db->query($sql,__LINE__,__FILE__);
3978 while ($this->db->next_record())
3980 $elder_id[$i] = $this->db->f('elder');
3981 $elder_name[$i] = $this->db->f('name');
3982 $elder2name[$elder_id[$i]] = $elder_name[$i];
3985 array_multisort($elder_name, $elder_id);
3987 if($action == 'upload')
3989 $target_path = $this->upload_target_path . '/' . basename( $_FILES['uploadedfile']['name']);
3991 if(($_FILES['uploadedfile']['type'] == "application/zip") ||
3992 ($_FILES['uploadedfile']['type'] == "application/x-zip-compressed") ||
3993 ($_FILES['uploadedfile']['type'] == "application/x-zip") ||
3994 ($_FILES['uploadedfile']['type'] == "application/octet-stream")) {
3996 if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
3997 $uploadstatus = "<b><font color=red> -E- Unable to move the uploaded file to ";
3998 $uploadstatus.= "the target path (check the path and permissions) of: $target_path</font></b>";
3999 $this->t->set_var('uploadstatus',$uploadstatus);
4000 $this->t->pfp('uploadhandle','upload',True);
4004 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
4005 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
4006 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
4007 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
4008 $this->t->set_var('uploadstatus',$uploadstatus);
4009 $this->t->pfp('uploadhandle','upload');
4010 $this->t->set_var('uploadhandle','');
4011 print "<table border=1 width=80%><tr><td>\n<pre>";
4013 # make a directory for this data to be stored in
4014 $date="data_" . date("Y_m_d");
4015 $data_dir = $this->upload_target_path . '/' . $date;
4016 print "-> Making the data directory: $date<br>\n";
4017 exec('mkdir -p ' . $data_dir . ' 2>&1', $result, $return_code);
4018 if($return_code != 0) {
4019 print implode('\n',$result) . "<br>";
4020 print "<b><font color=red>";
4021 print "-E- Unable to create the data directory. Aborting import.";
4022 print "</font></b>";
4026 # move the file uploaded into this directory
4027 print "-> Moving the uploaded file into the data dir<br>\n";
4028 exec('mv ' . $target_path . ' ' . $data_dir . '/' . ' 2>&1', $result, $return_code);
4029 if($return_code != 0) {
4030 print implode('\n',$result) . "<br>";
4031 print "<b><font color=red>";
4032 print "-E- Unable to move the uploaded file into the data dir. Aborting import.";
4033 print "</font></b>";
4037 # unzip the data into this directory
4038 print "-> Unzipping the data<br>\n";
4039 exec($this->unzip_path .' -u '. $data_dir . '/*.zip -d ' . $data_dir . ' 2>&1', $result, $return_code);
4040 if($return_code != 0) {
4041 print implode('\n',$result) . "<br>";
4042 print "<b><font color=red>";
4043 print "-E- Unable to unzip the uploaded file into the data dir: $data_dir. Aborting import.";
4044 print "</font></b>";
4047 exec('mv ' . $data_dir . '/*/* '. $data_dir . ' 2>&1', $result, $return_code);
4049 # update the data_latest link to point to this new directory
4050 print "-> Updating the latest data dir link<br>\n";
4051 $data_latest = $this->upload_target_path . '/data_latest';
4052 exec('rm ' . $data_latest. '; ln -s ' . $data_dir .' '. $data_latest .' 2>&1', $result, $return_code);
4053 if($return_code != 0) {
4054 print implode('\n',$result) . "<br>";
4055 print "<b><font color=red>";
4056 print "-E- Unable to update the data latest link. Aborting import.";
4057 print "</font></b>";
4061 # run the import perl script to encorporate it into the DB
4062 ob_start('ob_logstdout', 2);
4063 print "-> Importing the data into the EQ database<br>\n";
4064 ob_flush(); flush(); sleep(1);
4065 $import_log = $this->upload_target_path . '/import.log';
4066 $data_log = $this->upload_target_path . '/data.log';
4067 $import_cmd = $this->script_path . '/import_ward_data ' . $data_latest . ' 2>&1 | tee ' . $import_log;
4068 $parse_cmd = $this->script_path . '/parse_ward_data -v ' . $data_latest . ' > ' . $data_log . '2>&1';
4069 #print "import_cmd: $import_cmd<br>";
4070 #print "parse_cmd: $parse_cmd<br>";
4071 ob_start('ob_logstdout', 2);
4072 passthru($import_cmd);
4073 passthru($parse_cmd);
4074 ob_flush(); flush(); sleep(1);
4076 # fix the permissions of the data dir
4077 exec('chmod -R o-rwx ' . $data_dir, $result, $return_code);
4079 $this->t->pfp('cmdhandle','cmd');
4080 print "</pre></td></tr></table>";
4082 } else if(($_FILES['uploadedfile']['type'] != "application/zip") &&
4083 ($_FILES['uploadedfile']['type'] != "application/x-zip-compressed") &&
4084 ($_FILES['uploadedfile']['type'] != "application/x-zip") &&
4085 ($_FILES['uploadedfile']['type'] != "application/octet-stream")) {
4086 $uploadstatus = "<b><font color=red>The file format must be a .zip file, please try again! </font></b>";
4087 $uploadstatus.= "<br><br><b>Detected file format: " . $_FILES['uploadedfile']['type'] . "</b>";
4088 $this->t->set_var('uploadstatus',$uploadstatus);
4089 $this->t->pfp('uploadhandle','upload',True);
4091 $uploadstatus = "<b><font color=red> There was an error (" . $_FILES['uploadedfile']['error'];
4092 $uploadstatus.= ") uploading the file, please try again! </font></b>";
4093 $this->t->set_var('uploadstatus',$uploadstatus);
4094 $this->t->pfp('uploadhandle','upload',True);
4097 else if($action == "presidency")
4099 $new_data = get_var('eqpres',array('POST'));
4100 foreach ($new_data as $entry)
4103 $email = $entry['email'];
4104 $elder = $entry['elder'];
4105 $name = $entry['name'];
4106 $district = $entry['district'];
4107 $president = $entry['president'];
4108 $counselor = $entry['counselor'];
4109 $secretary = $entry['secretary'];
4110 $eqpresidency = $entry['eqpresidency'];
4111 // Set the elder id to 0 for EQ Presidency tagged entry
4112 if($eqpresidency == 1) { $elder="0"; }
4113 // Re-look up the elder name for the ID if we aren't an EQ Presidency tagged entry
4114 else { $name = $elder2name[$elder]; }
4115 //print "id=$id elder=$elder name=$name email=$email district=$district president=$president ";
4116 //print "counselor=$counselor secretary=$secretary eqpres=$eqpresidency<br>";
4118 if(($elder > 0) || ($name != "")) {
4119 if($id < $this->max_presidency_members) {
4120 //print "Updating Existing Entry<br>";
4121 $this->db2->query("UPDATE eq_presidency set" .
4122 " elder=" . $elder .
4123 " ,district=" . $district .
4124 " ,name='" . $name . "'" .
4125 " ,email='" . $email . "'" .
4126 " ,president='" . $president . "'" .
4127 " ,counselor='" . $counselor . "'" .
4128 " ,secretary='" . $secretary . "'" .
4129 " ,eqpres='" . $eqpresidency . "'" .
4130 " WHERE presidency=" . $id,__LINE__,__FILE__);
4133 //print "Adding New Entry<br>";
4134 $this->db2->query("INSERT INTO eq_presidency (presidency,elder,district,name,"
4135 . "email,president,counselor,secretary,eqpres,valid) "
4136 . "VALUES (NULL,'" . $elder . "','" . $district . "','"
4137 . $name . "','" . $email . "','" . $president . "','"
4138 . $counselor . "','" . $secretary . "','" . $eqpres . "','1'"
4139 .")",__LINE__,__FILE__);
4142 //print "Ignoring Blank Entry<br>";
4146 // Now update the eq_district table appropriately
4148 // Delete all the previous district entries from the table
4149 $this->db->query("DELETE from eq_district where valid=1",__LINE__,__FILE__);
4150 $this->db->query("DELETE from eq_district where valid=0",__LINE__,__FILE__);
4152 // Always add a "District 0" assigned to the High Priests Group
4154 $name = "High Priests";
4157 $this->db2->query("INSERT INTO eq_district (district,name,supervisor,valid) "
4158 . "VALUES ('" . $district . "','" . $name . "','"
4159 . $elder . "','" . $valid . "'"
4160 .")",__LINE__,__FILE__);
4163 // Requery the eq_presidency table
4164 $sql = "SELECT * FROM eq_presidency where valid=1";
4165 $this->db->query($sql,__LINE__,__FILE__);
4166 while ($this->db->next_record())
4168 // Extract the data for each presidency record
4169 $id = $this->db->f('presidency');
4170 $elder = $this->db->f('elder');
4171 $name = $this->db->f('name');
4172 $district = $this->db->f('district');
4173 $name = $this->db->f('name');
4176 // If we have a valid district, add it to the district table
4178 $this->db2->query("INSERT INTO eq_district (district,name,supervisor,valid) "
4179 . "VALUES ('" . $district . "','" . $name . "','"
4180 . $elder . "','" . $valid . "'"
4181 .")",__LINE__,__FILE__);
4186 $this->t->set_var('adminhandle','');
4187 $this->t->pfp('adminhandle','admin');
4191 $this->t->set_var('adminhandle','');
4192 $this->t->pfp('adminhandle','admin');
4195 // Now save off the data needed for an EQ Presidency Table Update
4197 $sql = "SELECT * FROM eq_presidency where valid=1";
4198 $this->db->query($sql,__LINE__,__FILE__);
4200 $header_row = "<th>Elder</th><th>Email</th><th>District</th><th>President</th><th>Counselor</th><th>Secretary</th><th>EQ Presidency</th>";
4201 while ($this->db->next_record())
4203 // Extract the data for each presidency record
4204 $id = $this->db->f('presidency');
4205 $elder = $this->db->f('elder');
4206 $district = $this->db->f('district');
4207 $name = $this->db->f('name');
4208 $email = $this->db->f('email');
4209 $president = $this->db->f('president');
4210 $counselor = $this->db->f('counselor');
4211 $secretary = $this->db->f('secretary');
4212 $eqpresidency = $this->db->f('eqpres');
4214 // Create the forms needed in the table
4215 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4218 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4221 if($eqpresidency == 0) {
4222 $table_data.= '<td align=center><select name="eqpres['.$id.'][elder]">';
4223 $table_data.= '<option value=0></option>';
4224 for ($j=0; $j < count($elder_id); $j++) {
4225 $tmp_id = $elder_id[$j];
4226 $name = $elder_name[$j];
4227 if($elder_id[$j] == $elder) { $eldername = $name; $selected = 'selected="selected"'; } else { $selected = ''; }
4228 $table_data.= '<option value='.$tmp_id.' '.$selected.'>'.$name.'</option>';
4230 $table_data.='</select></td>';
4231 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="'.$eldername.'">';
4233 $table_data.= '<td align=left><input type=text size="20" name="eqpresname" value="EQ Presidency"></td>';
4234 $table_data.= '<input type=hidden name="eqpres['.$id.'][name]" value="EQ Presidency">';
4238 $table_data .= '<td><input type="text" size="50" name="eqpres['.$id.'][email]" value="'.$email.'"></td>';
4241 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4242 $table_data.= '<option value=0></option>';
4243 for ($j=0; $j <= $this->max_num_districts; $j++) {
4244 if($district == $j) { $selected = 'selected="selected"'; } else { $selected = ''; }
4245 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4247 $table_data.='</select></td>';
4250 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4251 if($president == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4252 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4253 $table_data.='</select></td>';
4256 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4257 if($counselor == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4258 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4259 $table_data.='</select></td>';
4262 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4263 if($secretary == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4264 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4265 $table_data.='</select></td>';
4268 $table_data.= '<td align=center><select name="eqpres['.$id.'][eqpresidency]">';
4269 if($eqpresidency == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4270 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4271 $table_data.='</select></td>';
4274 $table_data .= "</tr>\n";
4275 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4276 $this->t->set_var('tr_color',$tr_color);
4279 // Now create 1 blank row to always have a line available to add a new elder with
4280 $id = $this->max_presidency_members;
4281 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4283 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4285 $table_data.= '<td align=center><select name="eqpres['.$id.'][elder]">';
4286 $table_data.= '<option value=0></option>';
4287 for ($j=0; $j < count($elder_id); $j++) {
4288 $tmp_id = $elder_id[$j];
4289 $name = $elder_name[$j];
4290 $table_data.= '<option value='.$tmp_id.'>'.$name.'</option>';
4292 $table_data.='</select></td>';
4293 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="">';
4295 $table_data.='<td><input type="text" size="50" name="eqpres['.$id.'][email]" value=""></td>';
4297 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4298 $table_data.= '<option value=0></option>';
4299 for ($j=0; $j <= $this->max_num_districts; $j++) {
4300 if($j == 0) { $selected = 'selected="selected"'; } else { $selected = ''; }
4301 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4303 $table_data.='</select></td>';
4305 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4306 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4307 $table_data.='</select></td>';
4309 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4310 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4311 $table_data.='</select></td>';
4313 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4314 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4315 $table_data.='</select></td>';
4317 $table_data.= '<td align=center><select name="eqpres['.$id.'][eqpresidency]">';
4318 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4319 $table_data.='</select></td>';
4321 $table_data .= "</tr>\n";
4322 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4323 $this->t->set_var('tr_color',$tr_color);
4325 $this->t->set_var('header_row',$header_row);
4326 $this->t->set_var('table_data',$table_data);
4327 $this->t->pfp('presidencyhandle','presidency',True);
4329 $this->save_sessiondata();
4332 function email_appt($appointment)
4334 //print "Emailing notification of appointment: $appointment <br>";
4336 $sql = "SELECT * FROM eq_appointment where appointment='$appointment'";
4337 $this->db->query($sql,__LINE__,__FILE__);
4339 while ($this->db->next_record())
4341 $appointment = $this->db->f('appointment');
4342 $presidency = $this->db->f('presidency');
4343 $location = $this->db->f('location');
4346 $elder = $this->db->f('elder');
4348 $family = $this->db->f('family');
4352 $uid = $this->db->f('uid');
4354 // Extract the year, month, day, hours, minutes, seconds from the appointment time
4355 $appt_date = $this->db->f('date');
4356 $date_array = explode("-",$appt_date);
4357 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
4358 $appt_time = $this->db->f('time');
4359 $time_array = explode(":",$appt_time);
4360 $hour = $time_array[0]; $minute = $time_array[1]; $seconds = $time_array[2];
4362 // Format the appointment time into an iCal UTC equivalent
4363 $dtstamp = gmdate("Ymd"."\T"."His"."\Z");
4364 $dtstart = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds,$month,$day,$year));
4365 $dtstartstr = date("l, F d, o g:i A", mktime($hour,$minute,$seconds,$month,$day,$year));
4367 // Set the email address of the person making the appointment
4368 $from = $GLOBALS['phpgw_info']['user']['fullname'] . "<" .
4369 $GLOBALS['phpgw_info']['user']['preferences']['email']['address'] . ">";
4371 $sql = "SELECT * FROM eq_presidency where presidency='$presidency'";
4372 $this->db2->query($sql,__LINE__,__FILE__);
4373 if($this->db2->next_record()) {
4374 $email = $this->db2->f('email');
4375 $interviewer = $this->db2->f('name');
4379 $sql = "SELECT * FROM eq_elder where elder='$elder'";
4380 $this->db2->query($sql,__LINE__,__FILE__);
4381 if($this->db2->next_record()) {
4382 $elder_name = $this->db2->f('name');
4383 $phone = $this->db2->f('phone');
4384 $appt_name = $elder_name . " Interview";
4385 $duration = $this->default_ppi_appt_duration * 60;
4390 $sql = "SELECT * FROM eq_family where family='$family'";
4391 $this->db2->query($sql,__LINE__,__FILE__);
4392 if($this->db2->next_record()) {
4393 $family_name = $this->db2->f('name');
4394 $phone = $this->db2->f('phone');
4395 $elder_id = $this->db2->f('elder_id');
4396 $appt_name = $family_name . " Family Visit";
4397 $sql = "SELECT * FROM eq_elder where elder='$elder_id'";
4398 $this->db3->query($sql,__LINE__,__FILE__);
4399 if($this->db3->next_record()) {
4400 $phone = $this->db3->f('phone');
4402 $duration = $this->default_visit_appt_duration * 60;
4406 $dtend = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4407 $dtendstr = date("g:i A", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4408 $date = $dtstartstr . "-" . $dtendstr;
4409 $description = "$appt_name : $phone";
4411 if(($uid == 0) && ($appt_name != "")) {
4412 // Create a new calendar item for this appointment, since this must be the first time we
4413 // are sending it out.
4414 print "Sent new appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4415 $uid = rand() . rand(); // Generate a random identifier for this appointment
4416 $subject = "Created: $appt_name";
4418 $this->db->query("UPDATE eq_appointment set" .
4420 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4422 $action = "PUBLISH";
4423 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4424 $dtend, $date, $location, $appt_name, $description, $uid);
4426 } else if(($uid != 0) && ($appt_name == "")) {
4427 // Remove the calendar item for this appointment since it has already been sent
4428 // and there is no name we have changed it to.
4429 print "Sent deleted appointment to " . $interviewer . " at " . $email . " for " . $appt_date . " " . $appt_time . "<br>";
4430 $subject = "Canceled: $appt_date $appt_time";
4432 $this->db->query("UPDATE eq_appointment set" .
4434 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4437 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4438 $dtend, $date, $location, $subject, $subject, $uid);
4440 } else if($uid != 0) {
4441 // Update the existing appointment since we have changed it
4442 print "Sent updated appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4444 $subject = "Canceled: $appt_date $appt_time";
4446 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4447 $dtend, $date, $location, $subject, $subject, $uid);
4449 $uid = rand() . rand(); // Generate a random identifier for this appointment
4450 $this->db->query("UPDATE eq_appointment set" .
4452 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4454 $subject = "Updated: $appt_name";
4455 $action = "PUBLISH";
4456 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4457 $dtend, $date, $location, $appt_name, $description, $uid);
4465 function send_ical_appt($action, $to, $from, $subject, $dtstamp, $dtstart, $dtend, $date, $location, $summary, $description, $uid)
4467 // Initialize our local variables
4468 $boundary = "=MIME_APPOINTMENT_BOUNDARY";
4472 // Form the headers for the email message
4473 $headers.="X-Mailer: PHP/" . phpversion() . "\n";
4474 $headers.="Mime-Version: 1.0\n";
4475 $headers.="Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
4476 $headers.="Content-Disposition: inline\n";
4477 $headers.="Reply-To: $from\n";
4478 $headers.="From: $from\n";
4480 // Print the plaintext version of the appointment
4481 $message.="--$boundary\n";
4482 $message.="Content-Type: text/plain; charset=us-ascii\n";
4483 $message.="Content-Disposition: inline\n";
4485 $message.="What: $description\n";
4486 $message.="When: $date\n";
4487 $message.="Where: $location\n";
4490 // Print the .ics attachment version of the appointment
4491 $message.="--$boundary\n";
4492 $message.="Content-Type: text/calendar; charset=us-ascii\n";
4493 $message.="Content-Disposition: attachment; filename=\"appointment.ics\"\n";
4495 $message.="BEGIN:VCALENDAR" . "\n";
4496 $message.="VERSION:2.0" . "\n";
4497 $message.="PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN" . "\n";
4498 $message.="METHOD:$action" . "\n";
4499 $message.="BEGIN:VEVENT" . "\n";
4500 $message.="ORGANIZER:MAILTO:$from". "\n";
4501 $message.="DTSTAMP:$dtstamp" . "\n";
4502 $message.="DTSTART:$dtstart" . "\n";
4503 $message.="DTEND:$dtend" . "\n";
4504 $message.="SUMMARY:$summary" . "\n";
4505 $message.="DESCRIPTION:$description" . "\n";
4506 $message.="LOCATION:$location" . "\n";
4507 $message.="UID:$uid" ."\n";
4508 $message.="TRANSP:OPAQUE" . "\n";
4509 $message.="SEQUENCE:0" . "\n";
4510 $message.="CLASS:PUBLIC" . "\n";
4511 $message.="END:VEVENT" . "\n";
4512 $message.="END:VCALENDAR" . "\n";
4514 // Complete the message
4515 $message.="--$boundary\n";
4518 mail($to, $subject, $message, $headers);
4522 function get_time_selection_form($hour, $minute, $pm, $presidency, $appointment)
4527 if($hour == 0) { $blank = 1; }
4529 if($this->time_drop_down_lists == 1) {
4530 // Create drop down lists to get the time
4531 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][hour]>';
4532 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4533 foreach(range(1,12) as $num) {
4534 if($hour == $num) { $selected = 'selected="selected"'; } else { $selected = ''; }
4535 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4537 $form_data.= '</select>';
4538 $form_data.= ' : ';
4539 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][minute]>';
4540 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4543 if($num < 10) { $num = "0" . "$num"; }
4544 if($minute == $num) { $selected = 'selected="selected"'; } else { $selected = ''; }
4545 if($blank == 1) { $selected = ""; }
4546 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4547 $num = $num + $this->time_drop_down_list_inc;
4549 $form_data.= '</select>';
4551 // Use free form text fields to get the time
4552 if($blank == 1) { $hour = ""; $minute = ""; $ampm = ""; }
4553 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][hour] value='.$hour.'>';
4555 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][minute] value='.$minute.'>';
4556 $form_data.= ' ';
4558 // Always use a drop-down select form for am/pm
4559 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][pm]>';
4561 if($pm == 0) { $form_data.= '<option value=0 selected>am</option>'; $form_data.= '<option value=1>pm</option>'; }
4562 if($pm == 1) { $form_data.= '<option value=0>am</option>'; $form_data.= '<option value=1 selected>pm</option>'; }
4564 $form_data.= '<option value=""></option>';
4565 $form_data.= '<option value=0>am</option>';
4566 $form_data.= '<option value=1>pm</option>';
4568 $form_data.= '</select>';