2 /**************************************************************************\
4 * http://www.phpgroupware.org *
5 * ----------------------------------------------- *
6 * This program is free software; you can redistribute it and/or modify it *
7 * under the terms of the GNU General Public License as published by the *
8 * Free Software Foundation; either version 2 of the License, or (at your *
9 * option) any later version. *
10 \**************************************************************************/
11 /* $Id: class.eq.inc.php,v 1.1.1.1 2005/07/20 07:40:32 ajp Exp $ */
22 var $default_ht_num_months;
23 var $default_ppi_num_months;
24 var $default_ppi_num_years;
25 var $default_int_num_quarters;
26 var $default_int_num_years;
27 var $default_vis_num_years;
28 var $default_att_num_quarters;
29 var $max_num_districts;
32 var $upload_target_path;
34 var $max_appointments;
35 var $max_presidency_members;
37 var $public_functions = array
61 'willing_view' => True,
62 'willing_update' => True,
63 'send_ical_appt' => True,
64 'assign_view' => True,
65 'assign_update' => True,
66 'get_time_selection_form' => True,
71 // LOCAL CONFIGURATION. PLEASE UPDATE AS APPROPRIATE.
72 $this->upload_target_path = "/home/users/eqpres/eq_data";
73 $this->script_path = "/usr/share/phpgroupware/eq/bin";
74 $this->default_ht_num_months = 3;
75 $this->default_ppi_num_months = 3;
76 $this->default_ppi_num_years = 0;
77 $this->default_int_num_quarters = 1;
78 $this->default_int_num_years = 0;
79 $this->default_att_num_quarters = 1;
80 $this->default_vis_num_years = 1;
81 $this->max_num_districts = 4;
82 $this->time_drop_down_lists = 1;
83 $this->monthly_hometeaching_interviews = 0;
84 $this->time_drop_down_list_inc = 15;
85 $this->default_visit_appt_duration = 45;
86 $this->default_ppi_appt_duration = 30;
87 $this->max_presidency_members = 99;
88 $this->max_appointments = 32768;
89 // END LOCAL CONFIGURATION
91 $this->db = $GLOBALS['phpgw']->db;
92 $this->db2 = $this->db;
93 $this->db3 = $this->db;
94 $this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
95 $this->t = $GLOBALS['phpgw']->template;
96 $this->account = $GLOBALS['phpgw_info']['user']['account_id'];
97 $this->grants = $GLOBALS['phpgw']->acl->get_grants('eq');
98 $this->grants[$this->account] = PHPGW_ACL_READ + PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE;
100 $this->jscal = CreateObject('eq.jscalendar'); // before phpgw_header() !!!
101 $this->cal_options = 'daFormat : "%Y-%m-%d",
102 ifFormat : "%Y-%m-%d",
104 weekNumbers : false';
106 $GLOBALS['phpgw_info']['flags']['app_header'] = 'Elders Quorum Tools - The 3rd Counselor';
107 $GLOBALS['phpgw']->common->phpgw_header();
109 $this->current_day = `date '+%d'`;
110 $this->current_day = $this->current_day-0; // Make it numeric
111 $this->current_month = `date '+%m'`;
112 $this->current_month = $this->current_month-0; // Make it numeric
113 $this->current_year = `date '+%Y'`;
114 $this->current_year = $this->current_year-0; // Make it numeric
117 $this->display_app_header();
120 function save_sessiondata()
125 function display_app_header()
127 $this->t->set_file(array('eq_header' => 'header.tpl'));
129 if (isset($phpgw_info['user']['preferences']['eq']['eq_font']))
131 $font = $phpgw_info['user']['preferences']['eq']['eq_font'];
138 $this->t->set_var('bg_color',$phpgw_info['theme']['th_bg']);
139 $this->t->set_var('font',$font);
140 $link_data['menuaction'] = 'eq.eq.ht_view';
141 $this->t->set_var('link_hometeaching',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
142 $this->t->set_var('lang_hometeaching','HomeTeaching');
143 $link_data['menuaction'] = 'eq.eq.act_list';
144 $this->t->set_var('link_activity',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
145 $this->t->set_var('lang_activity','Activities');
146 $link_data['menuaction'] = 'eq.eq.willing_view';
147 $this->t->set_var('link_willing',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
148 $this->t->set_var('lang_willing','Willingness');
149 $link_data['menuaction'] = 'eq.eq.assign_view';
150 $this->t->set_var('link_assignment',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
151 $this->t->set_var('lang_assignment','Assignments');
152 $link_data['menuaction'] = 'eq.eq.par_view';
153 $this->t->set_var('link_participation',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
154 $this->t->set_var('lang_participation','Participation');
155 $link_data['menuaction'] = 'eq.eq.ppi_view';
156 $this->t->set_var('link_ppi',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
157 $this->t->set_var('lang_ppi','PPIs');
158 $link_data['menuaction'] = 'eq.eq.int_view';
159 $this->t->set_var('link_int',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
160 $this->t->set_var('lang_int','Interviews');
161 $link_data['menuaction'] = 'eq.eq.vis_view';
162 $this->t->set_var('link_visit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
163 $this->t->set_var('lang_visit','Visits');
164 $link_data['menuaction'] = 'eq.eq.att_view';
165 $this->t->set_var('link_attendance',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
166 $this->t->set_var('lang_attendance','Attendance');
167 $link_data['menuaction'] = 'eq.eq.dir_view';
168 $this->t->set_var('link_dir',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
169 $this->t->set_var('lang_dir','Directory');
170 $link_data['menuaction'] = 'eq.eq.org_view';
171 $this->t->set_var('link_org',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
172 $this->t->set_var('lang_org','Callings');
173 $link_data['menuaction'] = 'eq.eq.admin';
174 $this->t->set_var('link_admin',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
175 $this->t->set_var('lang_admin','Admin');
176 $link_data['menuaction'] = 'eq.eq.schedule';
177 $this->t->set_var('link_schedule',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
178 $this->t->set_var('lang_schedule','Scheduling');
180 $this->t->pparse('out','eq_header');
185 $this->t->set_file(array('ht_view_t' => 'ht_view.tpl'));
186 $this->t->set_block('ht_view_t','district_list','list');
188 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
189 $num_months = get_var('num_months',array('GET','POST'));
190 if($num_months == '') { $num_months = $this->default_ht_num_months; }
191 $this->t->set_var('num_months',$num_months);
192 $this->t->set_var('lang_filter','Filter');
193 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
194 else { $this->t->set_var('lang_num_months','Months of History'); }
196 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
197 $this->t->set_var('title','Hometeaching');
199 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
200 $this->db->query($sql,__LINE__,__FILE__);
202 while ($this->db->next_record())
204 $districts[$i]['district'] = $this->db->f('district');
205 $districts[$i]['name'] = $this->db->f('name');
206 $districts[$i]['supervisor'] = $this->db->f('supervisor');
210 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
211 $this->db->query($sql,__LINE__,__FILE__);
213 while ($this->db->next_record())
215 $elder_id[$i] = $this->db->f('elder');
216 $elder_name[$i] = $this->db->f('name');
217 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
220 array_multisort($elder_name, $elder_id);
222 // Make an array mapping elder_ids to elder_names
223 for($i=0; $i < count($elder_id); $i++) {
225 $elders[$id] = $elder_name[$i];
228 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
229 $this->db->query($sql,__LINE__,__FILE__);
230 while ($this->db->next_record())
232 $aaronic_id = $this->db->f('aaronic');
233 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
234 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
238 $this->nextmatchs->template_alternate_row_color(&$this->t);
239 for ($i=0; $i < count($districts); $i++) {
240 $this->t->set_var('district_number',$districts[$i]['district']);
241 $this->t->set_var('district_name',$districts[$i]['name']);
242 $supervisor = $districts[$i]['supervisor'];
243 $unique_companionships='';
245 // Select all the unique companionship numbers for this district
246 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $districts[$i]['district'];
247 $this->db->query($sql,__LINE__,__FILE__);
249 while ($this->db->next_record())
251 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
255 $comp_width=450; $visit_width=25; $table_width=$comp_width + $num_months*$visit_width;
256 $table_data=""; $num_companionships = 0; $num_families = 0;
257 for($m=$num_months; $m >= 0; $m--) { $visits[$m] = 0; }
258 for ($j=0; $j < count($unique_companionships); $j++) {
259 $companion_table_entry = "";
260 // Select all the companions in each companionship
261 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
262 "companionship=". $unique_companionships[$j]['companionship'];
263 $this->db->query($sql,__LINE__,__FILE__);
265 while ($this->db->next_record())
267 // Get this companions information
268 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
269 $companionship = $this->db->f('companionship');
270 $elder_id = $this->db->f('elder');
271 $aaronic_id = $this->db->f('aaronic');
273 $name = $elders[$elder_id];
274 $phone = $elder_phone[$elder_id];
276 else if($aaronic_id) {
277 $name = $aaronic[$aaronic_id]['name'];
278 $phone = $aaronic[$aaronic_id]['phone'];
280 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
282 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
284 // Get the names of the families assigned this home teaching companionship
285 $sql = "SELECT * from eq_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
286 $sql = $sql . " ORDER BY name ASC";
287 $this->db->query($sql,__LINE__,__FILE__);
289 while ($this->db->next_record())
291 $num_families++; $total_families++;
292 $family_name = $this->db->f('name');
293 $family_id = $this->db->f('family');
294 $this->nextmatchs->template_alternate_row_color(&$this->t);
295 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
296 // Find out how many times Visits were performed by this companionship
297 // in the past $num_months for this Family
298 $header_row="<th width=$comp_width><font size=-2>Families</th>";
299 for($m=$num_months; $m >= 0; $m--) {
300 $month = $this->current_month - $m;
301 $year = $this->current_year;
302 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
303 if($month < 10) { $month = "0"."$month"; }
304 $month_start = "$year"."-"."$month"."-"."01";
305 $month_end = "$year"."-"."$month"."-"."31";
306 $month = "$month"."/"."$year";
307 //print "m: $m month: $month year: $year month_start: $month_start month_end: $month_end<br>";
308 // Add this to the query to filter on only visits made by this companionship:
309 // " AND companionship=" . $unique_companionships[$j]['companionship'].
310 $sql = "SELECT * FROM eq_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
311 " AND companionship!=0".
312 " AND family=". $family_id;
313 $this->db2->query($sql,__LINE__,__FILE__);
314 $link_data['menuaction'] = 'eq.eq.ht_update';
315 $link_data['date'] = $month_start;
316 $link_data['month_start'] = $month_start;
317 $link_data['month_end'] = $month_end;
318 $link_data['month'] = $month;
319 $link_data['district'] = $districts[$i]['district'];
320 $link_data['district_name'] = $districts[$i]['name'];
321 $link_data['action'] = 'view';
322 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
323 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
324 if(!$total_visits[$m]) { $total_visits[$m] = 0; }
325 if($this->db2->next_record()) {
326 if($this->db2->f('visited') == 'y') {
327 $visits[$m]++; $total_visits[$m]++;
328 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/checkmark.gif"></a></td>';
330 else if($this->db2->f('visited') == 'n') {
331 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/x.gif"></a></td>';
334 $visits[$m]++; $total_visits[$m]++;
335 $table_data .= "<td> </td>";
339 $visits[$m]++; $total_visits[$m]++;
340 $table_data .= "<td> </td>";
343 $table_data .= "</tr>";
346 $table_data .= "<tr><td colspan=20></td></tr>";
348 $table_data .= "<tr><td colspan=20><hr></td></tr>";
349 $stat_data = "<tr><td><b><font size=-2>$num_families Families<br>Visit Totals:</font></b></td>";
351 for($m=$num_months; $m >=0; $m--) {
352 $percent = ceil(($visits[$m] / $num_families)*100);
353 $stat_data .= "<td align=center><font size=-2><b>$visits[$m]<br>$percent%</font></b></td>";
355 $stat_data .= "</tr>";
357 $this->t->set_var('table_width',$table_width);
358 $this->t->set_var('header_row',$header_row);
359 $this->t->set_var('table_data',$table_data);
360 $this->t->set_var('stat_data',$stat_data);
361 $this->t->fp('list','district_list',True);
364 $totals = "<tr><td><b><font size=-2>$total_families Total Families<br>Visit Totals:</font></b></td>";
365 for($m=$num_months; $m >=0; $m--) {
366 $percent = ceil(($total_visits[$m] / $total_families)*100);
367 $totals .= "<td align=center><font size=-2><b>$total_visits[$m]<br>$percent%</font></b></td>";
371 $this->t->set_var('totals',$totals);
373 $this->t->pfp('out','ht_view_t');
374 $this->save_sessiondata();
380 $this->t->set_file(array('ht_update_t' => 'ht_update.tpl'));
381 $this->t->set_block('ht_update_t','district_list','list');
382 $this->t->set_block('ht_update_t','save','savehandle');
384 $district = get_var('district',array('GET','POST'));
385 $district_name = get_var('district_name',array('GET','POST'));
386 $date = get_var('date',array('GET','POST'));
387 $month = get_var('month',array('GET','POST'));
388 $month_start = get_var('month_start',array('GET','POST'));
389 $month_end = get_var('month_end',array('GET','POST'));
390 $action = get_var('action',array('GET','POST'));
392 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
393 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_update&action=save'));
394 $this->t->set_var('lang_done','Cancel');
395 $this->t->set_var('district_name',$district_name);
396 $this->t->set_var('district_number',$district);
397 $this->t->set_var('title','Hometeaching Update ' . $month);
398 $this->t->set_var('date',$date);
400 if($action == 'save')
402 // Get a list of all the companionships in this district
403 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $district;
404 $this->db->query($sql,__LINE__,__FILE__);
406 while ($this->db->next_record())
408 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
411 for ($j=0; $j < count($unique_companionships); $j++)
413 // FIXME: We won't be able to go back and edit history on families that have been
414 // reassigned to a different companionship. The following delete command will not delete
415 // the history of visits under an older companionship, only the ones for the existing
416 // companionship. This will lead to duplicate visits being entered for an older
417 // month for the same family, making it impossible to change the past history once
418 // a family is reassigned. However, you will be able to view the history just fine.
420 //$comp=$unique_companionships[$j]['companionship'];
421 //print "deleting from eq_visit where companionship=$comp and date=$date and district=$district<br>";
422 // Delete all the visits that have taken place for all families for this month
423 $this->db->query("DELETE from eq_visit where companionship=" . $unique_companionships[$j]['companionship'] .
424 " AND " . "date='" . $date . "'",__LINE__,__FILE__);
427 // Now, add the visits that are checked for this month
428 $new_data = get_var('family_visited',array('POST'));
429 foreach ($new_data as $family)
431 foreach ($family as $data)
433 //print "family_visited: $data <br>";
434 $data_array = explode("/",$data);
435 $family_id = $data_array[0];
436 $companionship = $data_array[1];
437 $date = $data_array[2];
438 $visited = $data_array[3];
439 if($visited == "") { $visited = $data_array[4]; }
440 //print "family_id: $family_id companionship: $companionship date: $date visited: $visited<br>";
441 $this->db->query("INSERT INTO eq_visit (family,companionship,date,notes,visited) "
442 . "VALUES (" . $family_id .",". $companionship .",'". $date ."','','". $visited ."')",__LINE__,__FILE__);
449 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
450 $this->db->query($sql,__LINE__,__FILE__);
452 while ($this->db->next_record())
454 $elder_id[$i] = $this->db->f('elder');
455 $elder_name[$i] = $this->db->f('name');
456 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
459 array_multisort($elder_name, $elder_id);
461 // Make an array mapping elder_ids to elder_names
462 for($i=0; $i < count($elder_id); $i++) {
464 $elders[$id] = $elder_name[$i];
467 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
468 $this->db->query($sql,__LINE__,__FILE__);
469 while ($this->db->next_record())
471 $aaronic_id = $this->db->f('aaronic');
472 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
473 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
476 // Select all the unique companionship numbers for this district
477 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $district;
478 $this->db->query($sql,__LINE__,__FILE__);
479 $j=0; $unique_companionships='';
480 while ($this->db->next_record())
482 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
486 $comp_width=300; $visit_width=25; $table_width=$comp_width + $visit_width;
487 $table_data=""; $num_companionships = 0; $num_families = 0; $visits=0;
488 for ($j=0; $j < count($unique_companionships); $j++) {
489 $companion_table_entry = "";
490 // Select all the companions in each companionship
491 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
492 "companionship=". $unique_companionships[$j]['companionship'];
493 $this->db->query($sql,__LINE__,__FILE__);
495 while ($this->db->next_record())
497 // Get this companions information
498 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
499 $companionship = $this->db->f('companionship');
500 $elder_id = $this->db->f('elder');
501 $aaronic_id = $this->db->f('aaronic');
503 $name = $elders[$elder_id];
504 $phone = $elder_phone[$elder_id];
506 else if($aaronic_id) {
507 $name = $aaronic[$aaronic_id]['name'];
508 $phone = $aaronic[$aaronic_id]['phone'];
510 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
512 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
514 // Get the names of the families assigned this home teaching companionship
515 $sql = "SELECT * from eq_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
516 $sql = $sql . " ORDER BY name ASC";
517 $this->db->query($sql,__LINE__,__FILE__);
518 while ($this->db->next_record())
520 $num_families++; $total_families++;
521 $family_name = $this->db->f('name');
522 $family_id = $this->db->f('family');
523 $this->nextmatchs->template_alternate_row_color(&$this->t);
524 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
526 $header_row="<th width=$comp_width><font size=-2>Families</th>";
527 $sql = "SELECT * FROM eq_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
528 " AND companionship!=0".
529 " AND family=". $family_id;
530 $this->db2->query($sql,__LINE__,__FILE__);
531 $value = $family_id . "/" . $unique_companionships[$j]['companionship'] . "/" . $date;
532 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
533 if(!$total_visits) { $total_visits = 0; }
534 if($this->db2->next_record()) {
535 if($this->db2->f('visited') == 'y') {
536 $visits++; $total_visits++;
537 $table_data .= '<td width=100 align=center>';
538 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y" checked>Y';
539 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
540 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/"> ';
541 $table_data .= '</td>';
542 } else if($this->db2->f('visited') == 'n') {
543 $table_data .= '<td width=100 align=center>';
544 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
545 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n" checked>N';
546 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/">';
547 $table_data .= '</td>';
549 $table_data .= '<td width=100 align=center>';
550 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
551 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
552 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
553 $table_data .= '</td>';
558 $table_data .= '<td width=100 align=center>';
559 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
560 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
561 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
562 $table_data .= '</td>';
565 $table_data .= "</tr>";
566 $table_data .= "<tr><td colspan=20></td></tr>";
568 $table_data .= "<tr><td colspan=20><hr></td></tr>";
569 $stat_data = "<tr><td><b><font size=-2>$num_families Families<br>Visit Totals:</font></b></td>";
571 $percent = ceil(($visits / $num_families)*100);
572 $stat_data .= "<td align=center><font size=-2><b>$visits<br>$percent%</font></b></td>";
573 $stat_data .= "</tr>";
575 $this->t->set_var('table_width',$table_width);
576 $this->t->set_var('header_row',$header_row);
577 $this->t->set_var('table_data',$table_data);
578 $this->t->set_var('stat_data',$stat_data);
579 $this->t->fp('list','district_list',True);
581 $this->t->set_var('lang_reset','Clear Form');
582 $this->t->set_var('lang_save','Save Changes');
583 $this->t->set_var('savehandle','');
585 $this->t->pfp('out','ht_update_t');
586 $this->t->pfp('addhandle','save');
588 $this->save_sessiondata();
593 $this->t->set_file(array('act_list_t' => 'act_list.tpl'));
594 $this->t->set_block('act_list_t','act_list','list');
596 $this->t->set_var('lang_name','Assignment');
597 $this->t->set_var('lang_date','Date');
598 $this->t->set_var('lang_notes','Description');
600 $sql = "SELECT * FROM eq_activity ORDER BY date DESC";
601 $this->db->query($sql,__LINE__,__FILE__);
602 $total_records = $this->db->num_rows();
605 while ($this->db->next_record())
607 $activity_list[$i]['activity'] = $this->db->f('activity');
608 $activity_list[$i]['assignment'] = $this->db->f('assignment');
609 $activity_list[$i]['date'] = $this->db->f('date');
610 $activity_list[$i]['notes'] = $this->db->f('notes');
612 $sql = "SELECT * FROM eq_assignment WHERE assignment='" . $activity_list[$i]['assignment'] . "'";
613 $this->db2->query($sql,__LINE__,__FILE__);
614 if($this->db2->next_record())
616 $activity_list[$i]['name'] = $this->db2->f('name');
617 $activity_list[$i]['code'] = $this->db2->f('code');
622 for ($i=0; $i < count($activity_list); $i++)
624 $this->nextmatchs->template_alternate_row_color(&$this->t);
625 $this->t->set_var('name',$activity_list[$i]['name']);
626 $this->t->set_var('date',$activity_list[$i]['date']);
627 $activity_notes = $activity_list[$i]['notes'];
628 if(strlen($activity_notes) > 40) { $activity_notes = substr($activity_notes,0,40) . "..."; }
629 $this->t->set_var('notes',$activity_notes);
631 $link_data['menuaction'] = 'eq.eq.act_view';
632 $link_data['activity'] = $activity_list[$i]['activity'];
633 $link_data['action'] = 'view';
634 $this->t->set_var('view',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
635 $this->t->set_var('lang_view','View');
637 $link_data['menuaction'] = 'eq.eq.act_update';
638 $link_data['activity'] = $activity_list[$i]['activity'];
639 $link_data['action'] = 'edit';
640 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
641 $this->t->set_var('lang_edit','Edit');
643 $link_data['menuaction'] = 'eq.eq.act_update';
644 $link_data['activity'] = '0';
645 $link_data['action'] = 'add';
646 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/eq/index.php',$link_data)
647 . '"><input type="submit" name="Add" value="' . 'Add Activity' .'"></font></form>');
649 $this->t->fp('list','act_list',True);
652 $this->t->pfp('out','act_list_t');
653 $this->save_sessiondata();
658 $this->t->set_file(array('act_view_t' => 'act_view.tpl'));
659 $this->t->set_block('act_view_t','part_list','list');
661 $sql = "SELECT * FROM eq_activity WHERE activity=" . intval(get_var('activity',array('GET','POST')));
662 $this->db->query($sql,__LINE__,__FILE__);
663 $this->db->next_record();
664 $this->t->set_var('assignment', $this->db->f('assignment'));
665 $this->t->set_var('date', $this->db->f('date'));
666 $this->t->set_var('notes', $this->db->f('notes'));
668 $sql = "SELECT * FROM eq_assignment WHERE assignment='" . $this->db->f('assignment') . "'";
669 $this->db2->query($sql,__LINE__,__FILE__);
670 if($this->db2->next_record())
672 $this->t->set_var('name', $this->db2->f('name'));
673 $this->t->set_var('code', $this->db2->f('code'));
675 $this->t->set_var('lang_name','Assignment');
676 $this->t->set_var('lang_date','Date');
677 $this->t->set_var('lang_notes','Description');
678 $this->t->set_var('lang_done','Done');
679 $this->t->set_var('lang_action','View');
681 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
682 $this->t->set_var('tr_color',$tr_color);
684 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_list'));
686 $link_data['menuaction'] = 'eq.eq.act_update';
687 $link_data['activity'] = get_var('activity',array('GET','POST'));
688 $link_data['action'] = 'edit';
689 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
690 $this->t->set_var('lang_edit','Edit');
691 $this->t->set_var('cal_date',$this->db->f('date'));
693 // Now find out which elders participated in this activity
694 $sql = "SELECT * FROM eq_participation WHERE activity=" . intval(get_var('activity',array('GET','POST')));
695 $this->db->query($sql,__LINE__,__FILE__);
696 $total_records = $this->db->num_rows();
699 while ($this->db->next_record())
701 $part_list[$i]['elder'] = $this->db->f('elder');
705 for ($i=0; $i < count($part_list); $i++)
707 $sql = "SELECT * FROM eq_elder WHERE elder=" . $part_list[$i]['elder'];
708 $this->db->query($sql,__LINE__,__FILE__);
709 $this->db->next_record();
710 $names[$i] = $this->db->f('name');
713 for ($i=0; $i < count($names); $i++)
715 //$this->nextmatchs->template_alternate_row_color(&$this->t);
716 $this->t->set_var('elder_name',$names[$i]);
717 if(($i+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
718 else { $this->t->set_var('table_sep',"</td>"); }
719 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
720 $this->t->fp('list','part_list',True);
723 $this->t->pfp('out','act_view_t');
724 $this->save_sessiondata();
727 function act_update()
729 $this->t->set_file(array('form' => 'act_update.tpl'));
730 $this->t->set_block('form','elder_list','list');
731 $this->t->set_block('form','add','addhandle');
732 $this->t->set_block('form','edit','edithandle');
733 $this->t->set_var('lang_done','Done');
735 $action = get_var('action',array('GET','POST'));
736 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_list'));
737 $activity['activity'] = intval(get_var('activity',array('GET','POST')));
739 if($action == 'save')
741 $activity['assignment'] = get_var('assignment',array('POST'));
742 $activity['date'] = get_var('date',array('POST'));
743 $activity['notes']= get_var('notes',array('POST'));
744 $this->db->query("UPDATE eq_activity set " .
745 " assignment='" . $activity['assignment'] .
746 "', date='" . $activity['date'] . "'" .
747 ", notes='" . $activity['notes'] . "'" .
748 " WHERE activity=" . $activity['activity'],__LINE__,__FILE__);
750 // Delete all the elders who have particiapted in this activity
751 $this->db->query("DELETE from eq_participation where activity=".$activity['activity'],__LINE__,__FILE__);
753 // Re-add the elders who are checked as having participated in this activity
754 $elders = get_var('elder_name',array('POST'));
755 foreach ($elders as $elder)
757 $this->db->query("INSERT INTO eq_participation (elder,activity) "
758 . "VALUES (" . $elder . ",". $activity['activity'] . ")",__LINE__,__FILE__);
765 if($action == 'insert')
767 $activity['assignment'] = get_var('assignment',array('POST'));
768 $activity['date'] = get_var('date',array('POST'));
769 $activity['notes']= get_var('notes',array('POST'));
770 $this->db->query("INSERT INTO eq_activity (assignment,date,notes) "
771 . "VALUES ('" . $activity['assignment'] . "','"
772 . $activity['date'] . "','" . $activity['notes'] . "')",__LINE__,__FILE__);
774 $sql = "SELECT * FROM eq_activity WHERE assignment='".$activity['assignment']."' "
775 . " AND date='".$activity['date']."' AND notes='".$activity['notes']."'";
776 $this->db->query($sql,__LINE__,__FILE__);
777 if($this->db->next_record()) {
778 //print "activity: " . $this->db->f('activity') . "<br>";
779 $activity['activity'] = $this->db->f('activity');
782 $elders = get_var('elder_name',array('POST'));
783 foreach ($elders as $elder)
785 $this->db->query("INSERT INTO eq_participation (elder,activity) "
786 . "VALUES (" . $elder . ",". $activity['activity'] . ")",__LINE__,__FILE__);
795 $activity['activity'] = 0;
796 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
797 $this->t->set_var('assignment','');
798 $this->t->set_var('date','');
799 $this->t->set_var('notes','');
800 $this->t->set_var('lang_done','Cancel');
801 $this->t->set_var('lang_action','Adding New Activity');
802 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_update&activity='
803 . $activity['activity'] . '&action=' . 'insert'));
806 if($action == 'edit')
808 $sql = "SELECT * FROM eq_activity WHERE activity=" . $activity['activity'];
809 $this->db->query($sql,__LINE__,__FILE__);
810 $this->db->next_record();
811 $this->t->set_var('cal_date',$this->jscal->input('date',$this->db->f('date'),'','','','','',$this->cal_options));
812 $this->t->set_var('assignment', $this->db->f('assignment'));
813 $assignment = $this->db->f('assignment');
814 $this->t->set_var('date', $this->db->f('date'));
815 $this->t->set_var('notes', $this->db->f('notes'));
816 $this->t->set_var('lang_done','Cancel');
817 $this->t->set_var('lang_action','Editing Activity');
818 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_update&activity='
819 . $activity['activity'] . '&action=' . 'save'));
823 // Create the assignments drop-down list
824 $sql = "SELECT * FROM eq_assignment ORDER BY name ASC";
825 $this->db->query($sql,__LINE__,__FILE__);
827 while ($this->db->next_record())
829 $assignments[$i]['assignment'] = $this->db->f('assignment');
830 $assignments[$i]['name'] = $this->db->f('name');
831 $assignments[$i]['code'] = $this->db->f('code');
835 $assignment_data.= '<select name=assignment>';
836 $assignment_data.= '<option value=0></option>';
837 for ($j=0; $j < count($assignments); $j++) {
838 $id = $assignments[$j]['assignment'];
839 $name = $assignments[$j]['name'];
840 if($assignments[$j]['assignment'] == $assignment) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
841 $assignment_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
843 $assignment_data.='</select>';
844 $this->t->set_var('assignment_data',$assignment_data);
846 // Create elder selection boxes
847 $sql = "SELECT * FROM eq_elder";
848 $this->db->query($sql,__LINE__,__FILE__);
850 while ($this->db->next_record())
852 if($this->db->f('valid') == 1 || $action != 'add') {
853 $elder_name[$i] = $this->db->f('name');
854 $elder_id[$i] = $this->db->f('elder');
855 $elder_valid[$i] = $this->db->f('valid');
859 array_multisort($elder_name, $elder_id, $elder_valid);
862 for ($i=0; $i < count($elder_id); $i++)
864 //$this->nextmatchs->template_alternate_row_color(&$this->t);
865 $sql = "SELECT * FROM eq_participation where activity=". $activity['activity'] . " AND elder=" . $elder_id[$i];
866 $this->db->query($sql,__LINE__,__FILE__);
867 if($this->db->next_record()) { $this->t->set_var('checked','checked'); $checked=1; }
868 else { $this->t->set_var('checked',''); $checked=0; }
869 if($checked || $elder_valid[$i] == 1) {
870 $this->t->set_var('elder_name',$elder_name[$i]);
871 $this->t->set_var('elder',$elder_id[$i]);
872 if(($j+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
873 else { $this->t->set_var('table_sep',"</td>"); }
874 if(($j) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
875 $this->t->fp('list','elder_list',True);
880 $this->t->set_var('lang_reset','Clear Form');
881 $this->t->set_var('lang_add','Add Activity');
882 $this->t->set_var('lang_save','Save Changes');
883 $this->t->set_var('edithandle','');
884 $this->t->set_var('addhandle','');
886 $this->t->pfp('out','form');
887 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
888 if($action == 'add') { $this->t->pfp('addhandle','add'); }
890 $this->save_sessiondata();
893 function assign_view()
895 $this->t->set_file(array('assign_view_t' => 'assign_view.tpl'));
896 $this->t->set_block('assign_view_t','assign_view','list');
898 $this->t->set_var('lang_name','Assignment Name');
899 $this->t->set_var('lang_code','Code');
901 $sql = "SELECT * FROM eq_assignment ORDER BY name ASC";
902 $this->db->query($sql,__LINE__,__FILE__);
903 $total_records = $this->db->num_rows();
906 while ($this->db->next_record())
908 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
909 $assignment_list[$i]['name'] = $this->db->f('name');
910 $assignment_list[$i]['code'] = $this->db->f('code');
914 for ($i=0; $i < count($assignment_list); $i++)
916 $this->nextmatchs->template_alternate_row_color(&$this->t);
917 $this->t->set_var('name',$assignment_list[$i]['name']);
918 $this->t->set_var('code',$assignment_list[$i]['code']);
920 $link_data['menuaction'] = 'eq.eq.assign_update';
921 $link_data['assignment'] = $assignment_list[$i]['assignment'];
922 $link_data['action'] = 'edit';
923 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
924 $this->t->set_var('lang_edit','Edit');
926 $link_data['menuaction'] = 'eq.eq.assign_update';
927 $link_data['assignment'] = '0';
928 $link_data['action'] = 'add';
929 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/eq/index.php',$link_data)
930 . '"><input type="submit" name="Add" value="' . 'Add Assignment' .'"></font></form>');
932 $this->t->fp('list','assign_view',True);
935 $this->t->pfp('out','assign_view_t');
936 $this->save_sessiondata();
939 function assign_update()
941 $this->t->set_file(array('form' => 'assign_update.tpl'));
942 $this->t->set_block('form','add','addhandle');
943 $this->t->set_block('form','edit','edithandle');
944 $this->t->set_var('lang_done','Done');
946 $action = get_var('action',array('GET','POST'));
947 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.assign_view'));
948 $assignment['assignment'] = intval(get_var('assignment',array('GET','POST')));
950 if($action == 'save')
952 $assignment['name'] = get_var('name',array('POST'));
953 $assignment['code'] = get_var('code',array('POST'));
954 $this->db->query("UPDATE eq_assignment set " .
955 " name='" . $assignment['name'] . "'" .
956 ", code='" . $assignment['code'] . "'" .
957 " WHERE assignment=" . $assignment['assignment'],__LINE__,__FILE__);
959 $this->assign_view();
963 if($action == 'insert')
965 $assignment['name'] = get_var('name',array('POST'));
966 $assignment['code'] = get_var('code',array('POST'));
967 $this->db->query("INSERT INTO eq_assignment (name,code) "
968 . "VALUES ('" . $assignment['name'] . "','"
969 . $assignment['code'] . "')",__LINE__,__FILE__);
970 $this->assign_view();
976 $assignment['assignment'] = 0;
977 $this->t->set_var('name','');
978 $this->t->set_var('code','');
979 $this->t->set_var('lang_done','Cancel');
980 $this->t->set_var('lang_action','Adding New Assignment');
981 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.assign_update&assignment='
982 . $assignment['assignment'] . '&action=' . 'insert'));
985 if($action == 'edit')
987 $sql = "SELECT * FROM eq_assignment WHERE assignment=" . $assignment['assignment'];
988 $this->db->query($sql,__LINE__,__FILE__);
989 $this->db->next_record();
990 $this->t->set_var('name', $this->db->f('name'));
991 $this->t->set_var('code', $this->db->f('code'));
992 $this->t->set_var('lang_done','Cancel');
993 $this->t->set_var('lang_action','Editing Assignment');
994 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.assign_update&assignment='
995 . $assignment['assignment'] . '&action=' . 'save'));
999 $this->t->set_var('lang_reset','Clear Form');
1000 $this->t->set_var('lang_add','Add Assignment');
1001 $this->t->set_var('lang_save','Save Changes');
1002 $this->t->set_var('edithandle','');
1003 $this->t->set_var('addhandle','');
1005 $this->t->pfp('out','form');
1006 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
1007 if($action == 'add') { $this->t->pfp('addhandle','add'); }
1009 $this->save_sessiondata();
1014 $this->t->set_file(array('par_view_t' => 'par_view.tpl'));
1015 $this->t->set_block('par_view_t','header_list','list1');
1016 $this->t->set_block('par_view_t','elder_list','list2');
1018 $sql = "SELECT * FROM eq_elder where valid=1";
1019 $this->db->query($sql,__LINE__,__FILE__);
1021 while ($this->db->next_record())
1023 $elder_name[$i] = $this->db->f('name');
1024 $elder_id[$i] = $this->db->f('elder');
1027 array_multisort($elder_name, $elder_id);
1029 $sql = "SELECT * FROM eq_activity ORDER BY date DESC";
1030 $this->db->query($sql,__LINE__,__FILE__);
1031 $total_records = $this->db->num_rows();
1034 while ($this->db->next_record())
1036 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1037 $activity_list[$i]['date'] = $this->db->f('date');
1038 $activity_list[$i]['activity'] = $this->db->f('activity');
1042 $sql = "SELECT * FROM eq_assignment ORDER BY name ASC";
1043 $this->db->query($sql,__LINE__,__FILE__);
1045 while($this->db->next_record())
1047 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1048 $assignment_list[$i]['name'] = $this->db->f('name');
1049 $assignment_list[$i]['code'] = $this->db->f('code');
1053 $elder_width=300; $part_width=25; $assignment_width=50;
1054 $total_width=$elder_width+$part_width;
1055 for ($i=0; $i < count($assignment_list); $i++) {
1056 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1057 $this->t->set_var('assignment_code',$assignment_list[$i]['code']);
1058 $this->t->fp('list1','header_list',True);
1059 $total_width += $assignment_width;
1062 for ($i=0; $i < count($elder_id); $i++) {
1063 $participated=0; $part_table = '';
1064 $this->nextmatchs->template_alternate_row_color(&$this->t);
1065 $this->t->set_var('elder_name',$elder_name[$i]);
1066 for ($j=0; $j < count($assignment_list); $j++) {
1067 $date = "0000-00-00"; $checkmark=0; $num_matches=0;
1068 for ($k=0; $k < count($activity_list); $k++) {
1069 if($assignment_list[$j]['assignment'] == $activity_list[$k]['assignment']) {
1070 $sql = "SELECT * FROM eq_participation where "
1071 . " activity=" . $activity_list[$k]['activity']
1072 . " AND elder=" . $elder_id[$i];
1073 $this->db->query($sql,__LINE__,__FILE__);
1074 while($this->db->next_record()) {
1075 if($activity_list[$k]['date'] > $date) {
1076 $date = $activity_list[$k]['date'];
1085 $part_table .= '<td align=center><img src="images/checkmark.gif">';
1086 $part_table .= '<font size=-2>'.$num_matches.'</font><br>';
1087 $part_table .= '<font size=-2>'.$date.'</font></td>';
1089 $part_table .= '<td> </td>';
1092 if($participated) { $part_table .= '<td align=center><img src="images/checkmark.gif">'.$participated.'</td>'; }
1093 else { $part_table .= '<td> </td>'; }
1094 $this->t->set_var('part_table',$part_table);
1095 $this->t->fp('list2','elder_list',True);
1097 $this->t->set_var('total_width',$total_width);
1098 $this->t->set_var('elder_width',$elder_width);
1099 $this->t->set_var('part_width',$part_width);
1100 $this->t->set_var('act_width',$act_width);
1101 $this->t->pfp('out','par_view_t');
1102 $this->save_sessiondata();
1105 function willing_view()
1107 $this->t->set_file(array('willing_view_t' => 'willing_view.tpl'));
1108 $this->t->set_block('willing_view_t','header_list','list1');
1109 $this->t->set_block('willing_view_t','elder_list','list2');
1111 $this->t->set_var('lang_filter','Filter');
1112 $this->t->set_var('lang_filter_unwilling','Filter out unwilling Elders:');
1114 $filter_unwilling = get_var('filter_unwilling',array('POST'));
1115 $this->t->set_var('filter_unwilling',$filter_unwilling);
1117 if($filter_unwilling == 'y' || $filter_unwilling == '') {
1118 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\" checked>Y";
1119 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\">N";
1120 $filter_input.= " ";
1122 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\">Y";
1123 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\" checked>N";
1124 $filter_input.= " ";
1126 $this->t->set_var('filter_input',$filter_input);
1128 $sql = "SELECT * FROM eq_elder where valid=1";
1129 $this->db->query($sql,__LINE__,__FILE__);
1131 while ($this->db->next_record())
1133 $elder_name[$i] = $this->db->f('name');
1134 $elder_id[$i] = $this->db->f('elder');
1135 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
1138 array_multisort($elder_name, $elder_id);
1140 $sql = "SELECT * FROM eq_assignment ORDER BY name ASC";
1141 $this->db->query($sql,__LINE__,__FILE__);
1143 while($this->db->next_record())
1145 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1146 $assignment_list[$i]['name'] = $this->db->f('name');
1147 $assignment_list[$i]['code'] = $this->db->f('code');
1151 $sql = "SELECT * FROM eq_activity ORDER BY date DESC";
1152 $this->db->query($sql,__LINE__,__FILE__);
1153 $total_records = $this->db->num_rows();
1156 while ($this->db->next_record())
1158 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1159 $activity_list[$i]['date'] = $this->db->f('date');
1160 $activity_list[$i]['activity'] = $this->db->f('activity');
1164 $elder_width=275; $willing_width=40; $assignment_width=50;
1165 $total_width=$elder_width+$willing_width;
1167 for ($i=0; $i < count($assignment_list); $i++) {
1168 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1169 $this->t->set_var('assignment_code',$assignment_list[$i]['code']);
1170 $this->t->fp('list1','header_list',True);
1171 $total_width += $assignment_width;
1172 $total_willing[$i] = 0;
1175 for ($i=0; $i < count($elder_id); $i++) {
1176 $willing_table = ''; $elder_willing=0;
1177 $this->t->set_var('elder_name',$elder_name[$i]);
1178 $this->t->set_var('elder_phone',$elder_phone[$elder_id[$i]]);
1179 $this->t->set_var('editurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.willing_update&elder_id='
1180 . $elder_id[$i] . '&action=' . 'edit'));
1181 for ($j=0; $j < count($assignment_list); $j++) {
1182 $found_willingness=0;
1183 $sql = "SELECT * FROM eq_willingness where "
1184 . " assignment=" . $assignment_list[$j]['assignment']
1185 . " AND elder=" . $elder_id[$i];
1186 $this->db->query($sql,__LINE__,__FILE__);
1187 while($this->db->next_record()) {
1188 $found_willingness=1;
1190 $sql = "SELECT * FROM eq_activity where "
1191 . " assignment=". $assignment_list[$j]['assignment']
1192 . " ORDER by date DESC";
1193 $this->db2->query($sql,__LINE__,__FILE__);
1194 if($this->db2->next_record()) {
1195 $activity = $this->db2->f('activity');
1196 $date = $this->db2->f('date');
1197 $sql = "SELECT * FROM eq_participation where "
1198 . " activity=" . $activity
1199 . " AND elder=". $elder_id[$i];
1200 $this->db3->query($sql,__LINE__,__FILE__);
1201 if($this->db3->next_record()) {
1206 if($this->db->f('willing') == 'y') {
1207 $total_willing[$j]++;
1209 $willing_table .= '<td align=center><img src="images/checkmark.gif"><br><font size=-2>'.$date_part.'</font></td></td>';
1211 else if($this->db->f('willing') == 'n') {
1212 $willing_table .= '<td align=center><img src="images/x.gif"></td>';
1216 $willing_table .= "<td> </td>";
1219 if(!$found_willingness) {
1221 $willing_table .= "<td> </td>";
1224 if(($elder_willing == 1) || ($filter_unwilling == 'n')) {
1225 $this->t->set_var('willing_table',$willing_table);
1226 $this->t->fp('list2','elder_list',True);
1227 $this->nextmatchs->template_alternate_row_color(&$this->t);
1231 $stat_table = '<td><b>Total Willing to Serve</b></td>';
1232 for ($j=0; $j < count($assignment_list); $j++) {
1233 $stat_table .= "<td align=center><b>".$total_willing[$j]."</b></td>";
1235 $this->t->set_var('stat_table',$stat_table);
1237 $this->t->set_var('total_width',$total_width);
1238 $this->t->set_var('elder_width',$elder_width);
1239 $this->t->set_var('willing_width',$willing_width);
1240 $this->t->pfp('out','willing_view_t');
1241 $this->save_sessiondata();
1244 function willing_update()
1246 //print "<font color=red>Willingness Update Under Constrcution</font>";
1247 //$this->willing_view();
1250 $this->t->set_file(array('willing_update_t' => 'willing_update.tpl'));
1251 $this->t->set_block('willing_update_t','assignment_list','list');
1252 $this->t->set_block('willing_update_t','save','savehandle');
1254 $elder_id = get_var('elder_id',array('GET','POST'));
1255 $this->t->set_var('elder_id',$elder_id);
1256 $action = get_var('action',array('GET','POST'));
1258 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.willing_view'));
1259 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.willing_update&action=save'));
1260 $this->t->set_var('lang_done','Cancel');
1261 $this->t->set_var('title','Willingness Update ');
1263 if($action == 'save')
1265 // Delete all the previous willingness entries for this elder
1266 $this->db->query("DELETE from eq_willingness where elder=" . $elder_id ,__LINE__,__FILE__);
1268 // Now, add the assignment willingness that is checked for this elder
1269 $new_data = get_var('willingness',array('POST'));
1270 foreach ($new_data as $data)
1272 $data_array = explode("/",$data);
1273 $assignment = $data_array[0];
1274 $willing = $data_array[1];
1275 //print "elder_id: $elder_id assignment: $assignment willing: $willing<br>";
1276 $this->db->query("INSERT INTO eq_willingness (elder,assignment,willing) "
1277 . "VALUES (" . $elder_id .",". $assignment .",'". $willing . "')",__LINE__,__FILE__);
1279 $this->willing_view();
1283 $assignment_width=300; $willing_width=25; $table_width=$assignment_width + $willing_width;
1286 // Find out the elder's name
1287 $sql = "SELECT * FROM eq_elder WHERE elder=".$elder_id." AND valid=1";
1288 $this->db->query($sql,__LINE__,__FILE__);
1289 if($this->db->next_record()) {
1290 $elder_name = $this->db->f('name');
1291 $this->t->set_var('elder_name',$elder_name);
1294 // Select all the assignments
1295 $sql = "SELECT * FROM eq_assignment ORDER by name ASC";
1296 $this->db->query($sql,__LINE__,__FILE__);
1298 while ($this->db->next_record())
1300 $assignment = $this->db->f('assignment');
1301 $assignment_name = $this->db->f('name');
1302 $assignment_code = $this->db->f('code');
1304 $this->nextmatchs->template_alternate_row_color(&$this->t);
1305 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$assignment_name</td>";
1307 $header_row="<th width=$comp_width><font size=-2>Assignments</th><th>Willingness</th>";
1308 $sql = "SELECT * FROM eq_willingness WHERE elder=".$elder_id." AND assignment=".$assignment;
1309 $this->db2->query($sql,__LINE__,__FILE__);
1310 $value = $assignment;
1312 if($this->db2->next_record()) {
1313 if($this->db2->f('willing') == 'y') {
1314 $table_data .= '<td width=100 align=center>';
1315 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y" checked>Y';
1316 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1317 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/"> ';
1318 $table_data .= '</td>';
1319 } else if($this->db2->f('willing') == 'n') {
1320 $table_data .= '<td width=100 align=center>';
1321 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1322 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n" checked>N';
1323 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/">';
1324 $table_data .= '</td>';
1326 $table_data .= '<td width=100 align=center>';
1327 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1328 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1329 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1330 $table_data .= '</td>';
1334 $table_data .= '<td width=100 align=center>';
1335 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">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.'/" checked> ';
1338 $table_data .= '</td>';
1341 $table_data .= "\n";
1342 $table_data .= "</tr>";
1343 $table_data .= "<tr><td colspan=20></td></tr>";
1346 $table_data .= "<tr><td colspan=20><hr></td></tr>";
1348 $this->t->set_var('table_width',$table_width);
1349 $this->t->set_var('header_row',$header_row);
1350 $this->t->set_var('table_data',$table_data);
1351 $this->t->fp('list','assignment_list',True);
1353 $this->t->set_var('lang_reset','Clear Form');
1354 $this->t->set_var('lang_save','Save Changes');
1355 $this->t->set_var('savehandle','');
1357 $this->t->pfp('out','willing_update_t');
1358 $this->t->pfp('addhandle','save');
1360 $this->save_sessiondata();
1364 function ppi_sched()
1366 $this->t->set_file(array('ppi_sched_t' => 'ppi_sched.tpl'));
1367 $this->t->set_block('ppi_sched_t','elder_list','elderlist');
1368 $this->t->set_block('ppi_sched_t','appt_list','apptlist');
1369 $action = get_var('action',array('GET','POST'));
1371 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1372 $this->t->set_var('lang_reset','Clear Changes');
1374 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
1375 $this->t->set_var('ppi_link_title','Yearly PPIs');
1377 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched'));
1378 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
1380 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched&action=save'));
1381 $this->t->set_var('title','Yearly PPI Scheduler');
1383 $elder_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $ppi_date_width=20;
1384 $table_width=$elder_width + $phone_width + $pri_width + $notes_width + $ppi_date_width;
1385 $header_row = "<th width=$elder_width><font size=-2>Elder Name</th>";
1386 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1387 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1388 $header_row.= "<th width=$ppi_date_width><font size=-2>Last PPI</th>";
1389 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1390 $table_data=""; $completed_data=""; $totals_data="";
1394 if($action == 'save')
1396 // Save any changes made to the appointment table
1397 $new_data = get_var('appt_notes',array('POST'));
1398 if($new_data != "") {
1399 foreach ($new_data as $entry)
1401 $elder = $entry['elder'];
1402 $appointment = $entry['appointment'];
1404 //print "elder: $elder appointment: $appointment <br>";
1406 //Only perform a database update if we have made a change to this appointment
1407 $sql = "SELECT * FROM eq_appointment where appointment='$appointment' and elder='$elder'";
1408 $this->db->query($sql,__LINE__,__FILE__);
1409 if(!$this->db->next_record()) {
1410 // Perform database save actions here
1411 $this->db->query("UPDATE eq_appointment set " .
1412 " elder='" . $elder . "'" .
1413 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1414 // Email the appointment
1415 $this->email_appt($appointment);
1421 // Save any changes made to the ppi notes table
1422 $new_data = get_var('ppi_notes',array('POST'));
1423 foreach ($new_data as $entry)
1425 $ppi_notes = $entry['notes'];
1426 $elder_id = $entry['elder_id'];
1427 $ppi_pri = $entry['pri'];
1429 // Perform database save actions here
1430 $this->db->query("UPDATE eq_elder set " .
1431 " ppi_notes='" . $ppi_notes . "'" .
1432 ",ppi_pri='" . $ppi_pri . "'" .
1433 " WHERE elder=" . $elder_id,__LINE__,__FILE__);
1437 $take_me_to_url = $GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched');
1438 //Header('Location: ' . $take_me_to_url);
1441 // Get the EQ President
1442 $sql = "SELECT * FROM eq_presidency where president=1 and valid=1";
1443 $this->db->query($sql,__LINE__,__FILE__);
1444 if($this->db->next_record()) {
1445 $president_name = $this->db->f('name');
1446 $president_id = $this->db->f('elder');
1447 $presidency_id = $this->db->f('presidency');
1448 $interviewer = $this->db->f('elder');
1449 $district_number = '*';
1450 $district_name = $president_name;
1452 print "<hr><font color=red><h3>-E- Unable to locate EQ President in eq_presidency table</h3></font></hr>";
1456 // create the elder id -> elder name mapping
1457 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY name ASC";
1458 $this->db->query($sql,__LINE__,__FILE__);
1462 while ($this->db->next_record())
1464 $elder_name[$i] = $this->db->f('name');
1465 $elder_id[$i] = $this->db->f('elder');
1468 array_multisort($elder_name, $elder_id);
1470 // APPOINTMENT TABLE
1471 $date_width=150; $time_width=100; $elder_width=200;
1472 $appt_table_width=$date_width + $time_width + $elder_width;
1473 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1474 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1475 $appt_header_row.= "<th width=$elder_width><font size=-2>Elder</th>";
1476 $appt_table_data = "";
1478 $total_elders=0; $elders_with_yearly_ppi=0;
1480 // Display a scheduling table for the EQ President
1481 $table_data=""; $appt_table_data="";
1482 $table_title = "District ".$district_number.": ".$district_name.": All Elders with Yearly PPI Not Completed";
1483 $appt_table_title = "District ".$district_number.": ".$district_name.": Yearly PPI Appointment Slots";
1484 $this->t->set_var('table_title',$table_title);
1485 $this->t->set_var('appt_table_title',$appt_table_title);
1487 // query the database for all the appointments
1488 $sql = "SELECT * FROM eq_appointment where presidency=".$presidency_id." and date>=CURDATE() ORDER BY date ASC, time ASC";
1489 $this->db->query($sql,__LINE__,__FILE__);
1491 while ($this->db->next_record())
1493 $appointment = $this->db->f('appointment');
1494 $elder = $this->db->f('elder');
1496 $date = $this->db->f('date');
1497 $date_array = explode("-",$date);
1498 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1499 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1501 $time = $this->db->f('time');
1502 $time_array = explode(":",$time);
1503 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1505 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1506 $appt_table_data.= "<td align=center>$day_string</td>";
1507 $appt_table_data.= "<td align=center>$time_string</td>";
1509 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][elder]>';
1510 $appt_table_data.= '<option value=0></option>';
1511 for ($i=0; $i < count($elder_id); $i++) {
1512 $id = $elder_id[$i];
1513 $name = $elder_name[$i];
1514 if($elder_id[$i] == $elder) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
1515 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1517 $appt_table_data.='</select></td>';
1519 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1521 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1522 $this->t->set_var('tr_color',$tr_color);
1525 $this->t->set_var('appt_table_data',$appt_table_data);
1526 $this->t->set_var('appt_header_row',$appt_header_row);
1527 $this->t->set_var('appt_table_width',$appt_table_width);
1529 // PPI SCHEDULING TABLE
1530 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY ppi_pri ASC";
1531 $this->db->query($sql,__LINE__,__FILE__);
1535 while ($this->db->next_record())
1537 $elder_id[$i] = $this->db->f('elder');
1538 $elder_name[$i] = $this->db->f('name');
1539 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
1540 $elder_ppi_pri[$elder_id[$i]] = $this->db->f('ppi_pri');
1541 $elder_ppi_notes[$elder_id[$i]] = $this->db->f('ppi_notes');
1546 $max = count($elder_id);
1548 for($i=0; $i < $max; $i++) {
1549 $id = $elder_id[$i];
1550 $name = $elder_name[$i];
1551 $phone = $elder_phone[$id];
1552 $ppi_pri = $elder_ppi_pri[$id];
1553 $ppi_notes = $elder_ppi_notes[$id];
1555 // If this elder has had a yearly PPI this year, don't show him on the schedule list
1556 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
1557 $sql = "SELECT * FROM eq_ppi WHERE date > '$year_start' AND date < '$year_end' ".
1559 $this->db2->query($sql,__LINE__,__FILE__);
1561 if(!$this->db2->next_record()) {
1562 $sql = "SELECT * FROM eq_ppi WHERE elder=" . $id . " ORDER BY date DESC";
1563 $this->db->query($sql,__LINE__,__FILE__);
1564 if($this->db->next_record()) { $date = $this->db->f('date'); } else { $date = ""; }
1565 $link_data['menuaction'] = 'eq.eq.ppi_update';
1566 $link_data['elder'] = $id;
1567 $link_data['name'] = $name;
1568 $link_data['ppi'] = '';
1569 $link_data['eqpresppi'] = 1;
1570 $link_data['action'] = 'add';
1571 $link_data['interviewer'] = $interviewer;
1572 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1573 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1574 $this->t->set_var('tr_color',$tr_color);
1575 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1576 $table_data.= "<td align=center>$phone</td>";
1577 //$table_data.= "<td align=center>$ppi_pri</td>";
1578 $table_data.= "<td align=center>";
1579 $table_data.= '<select name=ppi_notes['.$i.'][pri]>';
1580 foreach(range(0,6) as $num) {
1581 if($num == 0) { $num = 1; } else {$num = $num*5; }
1582 if($ppi_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
1583 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1585 $table_data.= '</select></td>';
1586 $table_data.= "<td align=center>$date</td>";
1587 $table_data.= '<td><input type=text size="50" maxlength="128" name="ppi_notes['.$i.'][notes]" value="'.$ppi_notes.'">';
1588 $table_data.= '<input type=hidden name="ppi_notes['.$i.'][elder_id]" value="'.$id.'">';
1589 $table_data.= '<input type=hidden name="ppi_notes['.$i.'][elder_name]" value="'.$name.'">';
1590 $table_data.= '</td>';
1591 $table_data.= '</tr>';
1593 $link_data['menuaction'] = 'eq.eq.ppi_update';
1594 $link_data['interviewer'] = $this->db2->f('interviewer');
1595 $link_data['elder'] = $this->db2->f('elder');
1596 $link_data['name'] = $name;
1597 $link_data['ppi'] = $this->db2->f('ppi');
1598 $link_data['eqpresppi'] = $this->db2->f('eqpresppi');
1599 $link_data['action'] = 'view';
1600 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1601 $elders_with_yearly_ppi++;
1602 $date = $this->db2->f('date');
1603 $ppi_notes = $this->db2->f('notes');
1604 if(strlen($ppi_notes) > 40) { $ppi_notes = substr($ppi_notes,0,40) . "..."; }
1605 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1606 $this->t->set_var('tr_color2',$tr_color2);
1607 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1608 $completed_data.= "<td align=center>$phone</td>";
1609 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1610 $completed_data.= "<td align=left>$ppi_notes</td>";
1611 $completed_data.= '</tr>';
1613 } // End for Elders Loop
1615 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1616 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1617 $completed_header_row = "<th width=$name_width><font size=-2>Elder Name</th>";
1618 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1619 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1620 $completed_header_row.= "<th width=$notes_width><font size=-2>PPI Notes</th>";
1622 $this->t->set_var('table_width',$table_width);
1623 $this->t->set_var('header_row',$header_row);
1624 $this->t->set_var('table_data',$table_data);
1625 $this->t->set_var('completed_header_row',$completed_header_row);
1626 $this->t->set_var('completed_table_width',$completed_table_width);
1627 $this->t->set_var('completed',$completed_data);
1628 $this->t->fp('elderlist','elder_list',True);
1630 $elders_width=300; $totals_width=100;
1631 $totals_table_width=$elders_width + $totals_width;
1632 $totals_header_row = "<th width=$elders_width><font size=-2>Elders</th>";
1633 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
1634 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1635 $totals_data.= "<td align=left><font size=-2><b>Total Elders with yearly PPIs completed:</b></font></td>";
1636 $totals_data.= "<td align=center><font size=-2><b>$elders_with_yearly_ppi / $total_elders</b></font></td>";
1637 $percent = ceil(($elders_with_yearly_ppi / $total_elders)*100);
1638 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1639 $this->t->set_var('tr_color',$tr_color);
1640 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1641 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
1642 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
1643 $totals_data.= "</tr>";
1645 $this->t->set_var('totals',$totals_data);
1646 $this->t->set_var('totals_header_row',$totals_header_row);
1647 $this->t->set_var('totals_table_width',$totals_table_width);
1649 $this->t->pfp('out','ppi_sched_t');
1650 $this->save_sessiondata();
1654 function int_sched()
1656 $this->t->set_file(array('int_sched_t' => 'int_sched.tpl'));
1657 $this->t->set_block('int_sched_t','elder_list','elderlist');
1658 $this->t->set_block('int_sched_t','appt_list','apptlist');
1659 $action = get_var('action',array('GET','POST'));
1661 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1662 $this->t->set_var('lang_reset','Clear Changes');
1664 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_view'));
1665 $this->t->set_var('int_link_title','Hometeaching Interviews');
1667 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_sched'));
1668 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
1670 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_sched&action=save'));
1671 $this->t->set_var('title','Hometeaching Interviews Scheduler');
1673 $elder_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $int_date_width=20;
1674 $table_width=$elder_width + $phone_width + $pri_width + $notes_width + $int_date_width;
1675 $header_row = "<th width=$elder_width><font size=-2>Elder Name</th>";
1676 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1677 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1678 $header_row.= "<th width=$int_date_width><font size=-2>Last Interview</th>";
1679 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1680 $table_data=""; $completed_data=""; $totals_data="";
1684 $nextyear = $year + 1;
1685 if($month >= 1 && $month <= 3) { $quarter_start=$year."-01-01"; $quarter_end=$year."-04-01"; }
1686 if($month >= 4 && $month <= 6) { $quarter_start=$year."-04-01"; $quarter_end=$year."-07-01"; }
1687 if($month >= 7 && $month <= 9) { $quarter_start=$year."-07-01"; $quarter_end=$year."-10-01"; }
1688 if($month >= 10 && $month <= 12) { $quarter_start=$year."-10-01"; $quarter_end=$nextyear."-01-01"; }
1689 //print "year: $year month: $month quarter_start: $quarter_start quarter_end: $quarter_end<br>";
1691 if($action == 'save')
1693 // Save any changes made to the appointment table
1694 $new_data = get_var('appt_notes',array('POST'));
1695 if($new_data != "") {
1696 foreach ($new_data as $entry)
1698 $elder = $entry['elder'];
1699 $appointment = $entry['appointment'];
1701 //print "elder: $elder appointment: $appointment <br>";
1702 //Only perform a database update if we have made a change to this appointment
1703 $sql = "SELECT * FROM eq_appointment where appointment='$appointment' and elder='$elder'";
1704 $this->db->query($sql,__LINE__,__FILE__);
1705 if(!$this->db->next_record()) {
1706 // Perform database save actions here
1707 $this->db->query("UPDATE eq_appointment set " .
1708 " elder='" . $elder . "'" .
1709 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1711 // Email the appointment
1712 $this->email_appt($appointment);
1717 // Save any changes made to the int notes table
1718 $new_data = get_var('int_notes',array('POST'));
1719 foreach ($new_data as $entry)
1721 $int_notes = $entry['notes'];
1722 $elder_id = $entry['elder_id'];
1723 $elder_name = $entry['elder_name'];
1724 $int_pri = $entry['pri'];
1725 $aaronic = $entry['aaronic'];
1726 //print "int_notes: $int_notes elder_name: $elder_name aaronic: $aaronic <Br>";
1728 // Perform database save actions here
1729 $this->db->query("UPDATE eq_elder set " .
1730 " int_notes='" . $int_notes . "'" .
1731 ",int_pri='" . $int_pri . "'" .
1732 " WHERE elder=" . $elder_id,__LINE__,__FILE__);
1737 $take_me_to_url = $GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_sched');
1738 //Header('Location: ' . $take_me_to_url);
1741 // Get the Districts
1742 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
1743 $this->db->query($sql,__LINE__,__FILE__);
1745 while ($this->db->next_record())
1747 $district = $this->db->f('district');
1748 $districts[$i]['district'] = $this->db->f('district');
1749 $districts[$i]['name'] = $this->db->f('name');
1750 $districts[$i]['supervisor'] = $this->db->f('supervisor');
1751 $sql = "SELECT * FROM eq_presidency where district=$district and valid=1";
1752 $this->db2->query($sql,__LINE__,__FILE__);
1753 if($this->db2->next_record()) {
1754 $districts[$i]['presidency'] = $this->db2->f('presidency');
1759 // create the elder id -> elder name mapping
1760 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY name ASC";
1761 $this->db->query($sql,__LINE__,__FILE__);
1763 $elder_id_data = NULL;
1764 $elder_name_data = NULL;
1765 while ($this->db->next_record())
1767 $elder_name_data[$i] = $this->db->f('name');
1768 $elder_id_data[$i] = $this->db->f('elder');
1771 array_multisort($elder_name_data, $elder_id_data);
1773 // APPOINTMENT TABLE
1775 $date_width=150; $time_width=100; $elder_width=200;
1776 $appt_table_width=$date_width + $time_width + $elder_width;
1777 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1778 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1779 $appt_header_row.= "<th width=$elder_width><font size=-2>Elder</th>";
1780 $appt_table_data = "";
1782 $total_comps=0; $comps_with_quarterly_int=0;
1784 // Display a scheduling table for each district
1785 for ($d=0; $d < count($districts); $d++) {
1786 $table_data=""; $appt_table_data="";
1787 $this->t->set_var('district_number',$districts[$d]['district']);
1788 $this->t->set_var('district_name',$districts[$d]['name']);
1789 $supervisor = $districts[$d]['supervisor'];
1790 $table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": All Elders with Interviews Not Completed";
1791 $appt_table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": Interview Appointment Slots";
1792 $this->t->set_var('table_title',$table_title);
1793 $this->t->set_var('appt_table_title',$appt_table_title);
1795 // query the database for all the appointments
1796 $sql = "SELECT * FROM eq_appointment where presidency=".$districts[$d]['presidency']." and date>=CURDATE() ORDER BY date ASC, time ASC";
1797 $this->db->query($sql,__LINE__,__FILE__);
1799 while ($this->db->next_record())
1801 $appointment = $this->db->f('appointment');
1802 $elder = $this->db->f('elder');
1804 $date = $this->db->f('date');
1805 $date_array = explode("-",$date);
1806 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1807 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1809 $time = $this->db->f('time');
1810 $time_array = explode(":",$time);
1811 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1813 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1814 $appt_table_data.= "<td align=center>$day_string</td>";
1815 $appt_table_data.= "<td align=center>$time_string</td>";
1817 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][elder]>';
1818 $appt_table_data.= '<option value=0></option>';
1819 for ($i=0; $i < count($elder_id_data); $i++) {
1820 $id = $elder_id_data[$i];
1821 $name = $elder_name_data[$i];
1822 if($elder_id_data[$i] == $elder) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
1823 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1825 $appt_table_data.='</select></td>';
1827 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1829 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1830 $this->t->set_var('tr_color',$tr_color);
1833 $this->t->set_var('appt_table_data',$appt_table_data);
1834 $this->t->set_var('appt_header_row',$appt_header_row);
1835 $this->t->set_var('appt_table_width',$appt_table_width);
1837 // INTERVIEW SCHEDULING TABLE
1839 // Select all the unique companionship numbers for this district
1840 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $districts[$d]['district'];
1841 $this->db->query($sql,__LINE__,__FILE__);
1843 while ($this->db->next_record())
1845 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
1850 for ($j=0; $j < count($unique_companionships); $j++) {
1851 // Select all the companions from each companionship
1852 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
1853 "companionship=". $unique_companionships[$j]['companionship'];
1854 $this->db->query($sql,__LINE__,__FILE__);
1855 $k=0; $int_completed=0;
1856 $comp = $unique_companionships[$j]['companionship'];
1857 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1858 $this->t->set_var('tr_color',$tr_color);
1860 while ($this->db->next_record())
1862 // Get this companions information
1863 $elder_id = $this->db->f('elder');
1864 $aaronic_id = $this->db->f('aaronic');
1866 $sql = "SELECT * FROM eq_elder where elder=$elder_id";
1867 $this->db2->query($sql,__LINE__,__FILE__);
1868 if($this->db2->next_record())
1870 $elder_id = $this->db2->f('elder');
1871 $elder_name = $this->db2->f('name');
1872 $elder_phone[$elder_id] = $this->db2->f('phone');
1873 $elder_int_pri[$elder_id] = $this->db2->f('int_pri');
1874 $elder_int_notes[$elder_id] = $this->db2->f('int_notes');
1878 $sql = "SELECT * FROM eq_aaronic where aaronic=$aaronic_id";
1879 $this->db2->query($sql,__LINE__,__FILE__);
1880 if($this->db2->next_record())
1882 $elder_id = $this->db2->f('aaronic');
1883 $elder_name = $this->db2->f('name');
1884 $elder_phone[$elder_id] = $this->db2->f('phone');
1890 $name = $elder_name;
1891 $phone = $elder_phone[$id];
1892 $int_pri = $elder_int_pri[$id];
1893 $int_notes = $elder_int_notes[$id];
1894 $aaronic = $elder_aaronic;
1896 // If the companionship has already had its quarterly interview,
1897 // Skip the other companion in the companionship.
1898 if($int_completed == 1) {
1899 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1900 $completed_data.= "<td align=center>$phone</td>";
1901 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1902 $completed_data.= "<td align=left>$int_notes</td>";
1903 $completed_data.= '</tr>';
1904 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1905 $this->t->set_var('tr_color2',$tr_color2);
1906 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1907 $this->t->set_var('tr_color',$tr_color);
1911 // If this companionship has had a hometeaching interview this quarter, don't show them on the schedule list
1912 $sql = "SELECT * FROM eq_ppi WHERE date >= '$quarter_start' AND date < '$quarter_end' ".
1914 $this->db2->query($sql,__LINE__,__FILE__);
1916 if(!$this->db2->next_record()) {
1917 $sql = "SELECT * FROM eq_ppi WHERE elder=" . $id . " ORDER BY date DESC";
1918 $this->db3->query($sql,__LINE__,__FILE__);
1919 if($this->db3->next_record()) { $date = $this->db3->f('date'); } else { $date = ""; }
1920 $link_data['menuaction'] = 'eq.eq.int_update';
1921 $link_data['elder'] = $id;
1922 $link_data['aaronic'] = 0;
1923 $link_data['name'] = $name;
1924 $link_data['ppi'] = '';
1925 $link_data['action'] = 'add';
1926 $link_data['interviewer'] = $districts[$d]['supervisor'];
1927 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1928 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1929 $table_data.= "<td align=center>$phone</td>";
1930 $table_data.= "<td align=center>";
1932 $table_data.= '<select name=int_notes['.$i.'][pri]>';
1933 foreach(range(0,6) as $num) {
1934 if($num == 0) { $num = 1; } else {$num = $num*5; }
1935 if($int_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
1936 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1938 $table_data.= '</select></td>';
1940 $table_data.= "<td align=center>$date</td>";
1942 $table_data.= '<td><input type=text size="50" maxlength="128" name="int_notes['.$i.'][notes]" value="'.$int_notes.'">';
1944 $table_data.= '<input type=hidden name="int_notes['.$i.'][elder_id]" value="'.$id.'">';
1945 $table_data.= '<input type=hidden name="int_notes['.$i.'][elder_name]" value="'.$name.'">';
1946 $table_data.= '<input type=hidden name="int_notes['.$i.'][aaronic]" value="'.$aaronic.'">';
1947 $table_data.= '</td>';
1948 $table_data.= '</tr>'."\n";
1951 $link_data['menuaction'] = 'eq.eq.int_update';
1952 $link_data['interviewer'] = $this->db2->f('interviewer');
1953 $link_data['elder'] = $this->db2->f('elder');
1954 $link_data['aaronic'] = $this->db2->f('aaronic');
1955 $link_data['name'] = $name;
1956 $link_data['ppi'] = $this->db2->f('ppi');
1957 $link_data['action'] = 'view';
1958 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
1959 $comps_with_quarterly_int++;
1961 $date = $this->db2->f('date');
1962 $int_notes = $this->db2->f('notes');
1963 if(strlen($int_notes) > 40) { $int_notes = substr($int_notes,0,40) . "..."; }
1964 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1965 $completed_data.= "<td align=center>$phone</td>";
1966 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1967 $completed_data.= "<td align=left>$int_notes</td>";
1968 $completed_data.= '</tr>';
1973 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1974 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1975 $completed_header_row = "<th width=$name_width><font size=-2>Elder Name</th>";
1976 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1977 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1978 $completed_header_row.= "<th width=$notes_width><font size=-2>Interview Notes</th>";
1980 $this->t->set_var('table_width',$table_width);
1981 $this->t->set_var('header_row',$header_row);
1982 $this->t->set_var('table_data',$table_data);
1983 $this->t->set_var('completed_header_row',$completed_header_row);
1984 $this->t->set_var('completed_table_width',$completed_table_width);
1985 $this->t->set_var('completed',$completed_data);
1986 $this->t->fp('elderlist','elder_list',True);
1988 } // End for each district loop
1991 $elders_width=300; $totals_width=100;
1992 $totals_table_width=$elders_width + $totals_width;
1993 $totals_header_row = "<th width=$elders_width><font size=-2>Elders</th>";
1994 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
1995 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1996 $totals_data.= "<td align=left><font size=-2><b>Total Companionships with interviews completed:</b></font></td>";
1997 $totals_data.= "<td align=center><font size=-2><b>$comps_with_quarterly_int / $total_comps</b></font></td>";
1998 $percent = ceil(($comps_with_quarterly_int / $total_comps)*100);
1999 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2000 $this->t->set_var('tr_color',$tr_color);
2001 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2002 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2003 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2004 $totals_data.= "</tr>";
2006 $this->t->set_var('totals',$totals_data);
2007 $this->t->set_var('totals_header_row',$totals_header_row);
2008 $this->t->set_var('totals_table_width',$totals_table_width);
2010 $this->t->pfp('out','int_sched_t');
2011 $this->save_sessiondata();
2015 function vis_sched()
2017 $this->t->set_file(array('vis_sched_t' => 'vis_sched.tpl'));
2018 $this->t->set_block('vis_sched_t','family_list','familylist');
2019 $this->t->set_block('vis_sched_t','appt_list','apptlist');
2020 $action = get_var('action',array('GET','POST'));
2022 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
2023 $this->t->set_var('lang_reset','Clear Changes');
2025 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
2026 $this->t->set_var('vis_link_title','View Yearly Visits');
2028 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched'));
2029 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2031 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched&action=save'));
2032 $this->t->set_var('title','EQ Presidency Yearly Visit Scheduler');
2034 $family_width=500; $phone_width=40; $pri_width=10; $notes_width=128; $visit_date_width=20;
2035 $table_width=$family_width + $phone_width + $pri_width + $notes_width + $visit_date_width;
2036 $header_row = "<th width=$family_width><font size=-2>Family Name</th>";
2037 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2038 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
2039 $header_row.= "<th width=$visit_date_width><font size=-2>Last Visit</th>";
2040 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
2041 $table_data=""; $completed_data=""; $totals_data="";
2045 if($action == 'save')
2047 // Save any changes made to the appointment table
2048 $new_data = get_var('appt_notes',array('POST'));
2049 if($new_data != "") {
2050 foreach ($new_data as $entry)
2052 $family = $entry['family'];
2053 $appointment = $entry['appointment'];
2055 //Only perform a database update if we have made a change to this appointment
2056 $sql = "SELECT * FROM eq_appointment where appointment='$appointment' and family='$family'";
2057 $this->db->query($sql,__LINE__,__FILE__);
2058 if(!$this->db->next_record()) {
2060 // Perform database save actions here
2061 $this->db->query("UPDATE eq_appointment set " .
2062 " family='" . $family . "'" .
2063 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
2065 // Email the appointment
2066 $this->email_appt($appointment);
2071 // Save any changes made to the visit notes table
2072 $new_data = get_var('vis_notes',array('POST'));
2073 foreach ($new_data as $entry)
2075 $visit_notes = $entry['notes'];
2076 $family_id = $entry['family_id'];
2077 $visit_pri = $entry['pri'];
2079 // Perform database save actions here
2080 $this->db->query("UPDATE eq_family set " .
2081 " visit_notes='" . $visit_notes . "'" .
2082 ",visit_pri='" . $visit_pri . "'" .
2083 " WHERE family=" . $family_id,__LINE__,__FILE__);
2087 $take_me_to_url = $GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched');
2088 //Header('Location: ' . $take_me_to_url);
2091 // APPOINTMENT TABLE
2092 $date_width=150; $time_width=100; $family_width=250;
2093 $appt_table_width=$date_width + $time_width + $family_width;
2094 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
2095 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
2096 $appt_header_row.= "<th width=$family_width><font size=-2>Family</th>";
2097 $appt_table_data = "";
2099 // Find out what the EQ Presidency ID is
2100 $sql = "SELECT * FROM eq_presidency where eqpres=1 and valid=1";
2101 $this->db->query($sql,__LINE__,__FILE__);
2102 if($this->db->next_record()) {
2103 $presidency_name = $this->db->f('name');
2104 $presidency_id = $this->db->f('presidency');
2106 print "<hr><font color=red><h3>-E- Unable to locate EQ Presidency in eq_presidency table</h3></font></hr>";
2110 // create the family id -> family name mapping
2111 $sql = "SELECT * FROM eq_family where valid=1 and elder_id != 0 ORDER BY name ASC";
2112 $this->db->query($sql,__LINE__,__FILE__);
2115 while ($this->db->next_record())
2117 $family_id[$i] = $this->db->f('family');
2118 $family_name[$i] = $this->db->f('name');
2121 array_multisort($family_name, $family_id);
2123 // query the database for all the appointments
2124 $sql = "SELECT * FROM eq_appointment where presidency=$presidency_id and date>=CURDATE() ORDER BY date ASC, time ASC";
2125 $this->db->query($sql,__LINE__,__FILE__);
2127 while ($this->db->next_record())
2129 $appointment = $this->db->f('appointment');
2130 $family = $this->db->f('family');
2132 $date = $this->db->f('date');
2133 $date_array = explode("-",$date);
2134 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
2135 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
2137 $time = $this->db->f('time');
2138 $time_array = explode(":",$time);
2139 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
2141 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2142 $appt_table_data.= "<td align=center>$day_string</td>";
2143 $appt_table_data.= "<td align=center>$time_string</td>";
2145 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][family]>';
2146 $appt_table_data.= '<option value=0></option>';
2147 for ($i=0; $i < count($family_id); $i++) {
2148 $id = $family_id[$i];
2149 $name = $family_name[$i];
2150 if($family_id[$i] == $family) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
2151 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
2153 $appt_table_data.='</select></td>';
2155 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
2157 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2158 $this->t->set_var('tr_color',$tr_color);
2161 $this->t->set_var('appt_table_data',$appt_table_data);
2162 $this->t->set_var('appt_header_row',$appt_header_row);
2163 $this->t->set_var('appt_table_width',$appt_table_width);
2166 // VISIT SCHEDULING TABLE
2167 $sql = "SELECT * FROM eq_family where valid=1 and elder_id != 0 ORDER BY visit_pri ASC";
2168 $this->db->query($sql,__LINE__,__FILE__);
2170 $total_families=0; $families_with_yearly_visit=0;
2174 $family_name = NULL;
2175 $family_phone = NULL;
2176 $family_visit_pri = NULL;
2177 $family_visit_notes = NULL;
2178 while ($this->db->next_record())
2180 $family_id[$i] = $this->db->f('family');
2181 $family_name[$i] = $this->db->f('name');
2182 $family_phone[$family_id[$i]] = $family_id[$i] . " ERROR";
2183 $family_visit_pri[$family_id[$i]] = $this->db->f('visit_pri');
2184 $family_visit_notes[$family_id[$i]] = $this->db->f('visit_notes');
2189 $sql = "SELECT * FROM eq_parent where valid=1";
2190 $this->db->query($sql,__LINE__,__FILE__);
2191 while ($this->db->next_record())
2193 $family = $this->db->f('family');
2194 $phone = $this->db->f('phone');
2195 $family_phone[$family] = $phone;
2198 $max = count($family_id);
2200 for($i=0; $i < $max; $i++) {
2201 $id = $family_id[$i];
2202 $name = $family_name[$i];
2203 $phone = $family_phone[$id];
2204 $vis_pri = $family_visit_pri[$id];
2205 $vis_notes = $family_visit_notes[$id];
2207 // If this family has had a yearly visit this year, don't show them on the schedule list
2208 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2209 $sql = "SELECT * FROM eq_visit WHERE date > '$year_start' AND date < '$year_end' ".
2210 "AND family=" . $id . " AND companionship=0";
2211 $this->db2->query($sql,__LINE__,__FILE__);
2213 if(!$this->db2->next_record()) {
2214 $sql = "SELECT * FROM eq_visit WHERE family=" . $id . " AND companionship=0 ORDER BY date DESC";
2215 $this->db->query($sql,__LINE__,__FILE__);
2216 if($this->db->next_record()) { $date = $this->db->f('date'); } else { $date = ""; }
2217 $link_data['menuaction'] = 'eq.eq.vis_update';
2218 $link_data['visit'] = '';
2219 $link_data['family'] = $id;
2220 $link_data['name'] = $name;
2221 $link_data['action'] = 'add';
2222 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2223 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2224 $table_data.= "<td align=center>$phone</td>";
2225 $table_data.= "<td align=center>";
2226 $table_data.= '<select name=vis_notes['.$i.'][pri]>';
2227 foreach(range(0,6) as $num) {
2228 if($num == 0) { $num = 1; } else {$num = $num*5; }
2229 if($vis_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
2230 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2232 $table_data.= '</select></td>';
2233 $table_data.= "<td align=center>$date</td>";
2234 $table_data.= '<td><input type=text size="50" maxlength="128" name="vis_notes['.$i.'][notes]" value="'.$vis_notes.'">';
2235 $table_data.= '<input type=hidden name="vis_notes['.$i.'][family_id]" value="'.$id.'">';
2236 $table_data.= '<input type=hidden name="vis_notes['.$i.'][family_name]" value="'.$name.'">';
2237 $table_data.= '</td>';
2238 $table_data.= '</tr>';
2239 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2240 $this->t->set_var('tr_color',$tr_color);
2242 $link_data['menuaction'] = 'eq.eq.vis_update';
2243 $link_data['visit'] = $this->db2->f('visit');
2244 $link_data['family'] = $this->db2->f('family');
2245 $link_data['name'] = $name;
2246 $link_data['date'] = $this->db2->f('date');
2247 $link_data['action'] = 'view';
2248 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2249 $families_with_yearly_visit++;
2250 $date = $this->db2->f('date');
2251 $vis_notes = $this->db2->f('notes');
2252 if(strlen($vis_notes) > 40) { $vis_notes = stripslashes(substr($vis_notes,0,40) . "..."); }
2253 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2254 $completed_data.= "<td align=center>$phone</td>";
2255 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2256 $completed_data.= "<td align=left>$vis_notes</td>";
2257 $completed_data.= '</tr>';
2258 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
2259 $this->t->set_var('tr_color2',$tr_color2);
2263 $name_width=190; $phone_width=100; $date_width=100; $notes_width=300;
2264 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
2265 $completed_header_row = "<th width=$name_width><font size=-2>Family Name</th>";
2266 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2267 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
2268 $completed_header_row.= "<th width=$notes_width><font size=-2>Visit Notes</th>";
2270 $family_width=300; $totals_width=100;
2271 $totals_table_width=$family_width + $totals_width;
2272 $totals_header_row = "<th width=$family_width><font size=-2>Families</th>";
2273 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2274 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2275 $totals_data.= "<td align=left><font size=-2><b>Total Families with yearly Visits completed:</b></font></td>";
2276 $totals_data.= "<td align=center><font size=-2><b>$families_with_yearly_visit / $total_families</b></font></td>";
2277 $percent = ceil(($families_with_yearly_visit / $total_families)*100);
2278 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2279 $this->t->set_var('tr_color',$tr_color);
2280 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2281 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2282 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2283 $totals_data.= "</tr>";
2285 $this->t->set_var('table_width',$table_width);
2286 $this->t->set_var('header_row',$header_row);
2287 $this->t->set_var('table_data',$table_data);
2288 $this->t->set_var('totals_header_row',$totals_header_row);
2289 $this->t->set_var('totals_table_width',$totals_table_width);
2290 $this->t->set_var('completed_header_row',$completed_header_row);
2291 $this->t->set_var('completed_table_width',$completed_table_width);
2292 $this->t->set_var('completed',$completed_data);
2293 $this->t->set_var('totals',$totals_data);
2294 $this->t->fp('familylist','family_list',True);
2295 $this->t->fp('apptlist','appt_list',True);
2297 $this->t->pfp('out','vis_sched_t');
2298 $this->save_sessiondata();
2304 $this->t->set_file(array('ppi_view_t' => 'ppi_view.tpl'));
2305 $this->t->set_block('ppi_view_t','district_list','list');
2307 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
2308 $num_months = get_var('num_months',array('GET','POST'));
2309 if($num_months == '') { $num_months = $this->default_ppi_num_months; }
2310 $this->t->set_var('num_months',$num_months);
2311 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
2312 else { $this->t->set_var('lang_num_months','Months of History'); }
2313 $this->t->set_var('lang_filter','Filter');
2314 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
2316 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
2317 $this->t->set_var('ppi_link_title','Yearly PPIs');
2319 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched'));
2320 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
2322 $this->t->set_var('title','Yearly PPIs');
2323 $num_months = get_var('num_months',array('GET','POST'));
2324 if($num_months == '') { $num_months = $this->default_ppi_num_years; }
2325 $this->t->set_var('num_months',$num_months);
2326 if($num_months == 1) { $this->t->set_var('lang_num_months','Year of History'); }
2327 else { $this->t->set_var('lang_num_months','Years of History'); }
2329 $sql = "SELECT * FROM eq_presidency where president=1 and valid=1";
2330 $this->db->query($sql,__LINE__,__FILE__);
2331 if($this->db->next_record()) {
2332 $president_name = $this->db->f('name');
2333 $interviewer = $this->db->f('elder');
2336 print "<hr><font color=red><h3>-E- Unable to locate EQ President in eq_presidency table</h3></font></hr>";
2339 $this->t->set_var('district_number','*');
2340 $this->t->set_var('district_name',$president_name);
2342 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
2343 $this->db->query($sql,__LINE__,__FILE__);
2345 while ($this->db->next_record())
2347 $elder_id[$i] = $this->db->f('elder');
2348 $elder_name[$i] = $this->db->f('name');
2349 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
2350 $elder_ppi_pri[$elder_id[$i]] = $this->db->f('ppi_pri');
2351 $elder_ppi_notes[$elder_id[$i]] = $this->db->f('ppi_notes');
2355 array_multisort($elder_name, $elder_id);
2356 //var_dump($elder_name); print "<br><br>"; var_dump($elder_id);
2358 $header_row="<th width=$comp_width><font size=-2>Elder Name</th>";
2360 $elder_width=400; $ppi_width=75; $table_width=$elder_width + $num_months*$ppi_width;
2362 for($m=$num_months; $m >= 0; $m--) {
2363 $year = date('Y') - $m;
2364 $header_row .= "<th width=150><font size=-2>$year</th>";
2368 for ($j=0; $j < count($elder_id); $j++) {
2369 $id = $elder_id[$j];
2370 $name = $elder_name[$j];
2371 $phone = $elder_phone[$id];
2373 $link_data['menuaction'] = 'eq.eq.ppi_update';
2374 $link_data['interviewer'] = $interviewer;
2375 $link_data['elder'] = $id;
2376 $link_data['name'] = $name;
2377 $link_data['ppi'] = '';
2378 $link_data['eqpresppi'] = $eqpresppi;
2379 $link_data['action'] = 'add';
2380 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2381 $this->nextmatchs->template_alternate_row_color(&$this->t);
2382 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2384 // Find out how many times PPIs were performed in the past $num_months for this Elder
2385 for($m=$num_months; $m >= 0; $m--) {
2386 $year = date('Y') - $m;
2387 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2388 $sql = "SELECT * FROM eq_ppi WHERE date > '$year_start' AND date < '$year_end' ".
2389 "AND elder=" . $id . " AND eqpresppi=1";
2390 $this->db2->query($sql,__LINE__,__FILE__);
2392 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
2393 if($this->db2->next_record()) {
2394 $ppis[$m]++; $total_ppis[$m]++; $ppi_recorded[$companionship][$m]=1;
2395 $link_data['menuaction'] = 'eq.eq.ppi_update';
2396 $link_data['companionship'] = $companionship;
2397 $link_data['interviewer'] = $this->db2->f('interviewer');
2398 $link_data['elder'] = $id;
2399 $link_data['name'] = $name;
2400 $link_data['ppi'] = $this->db2->f('ppi');
2401 $link_data['eqpresppi'] = $eqpresppi;
2402 $link_data['action'] = 'view';
2403 $date = $this->db2->f('date');
2404 $date_array = explode("-",$date);
2405 $month = $date_array[1];
2406 $day = $date_array[2];
2407 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2408 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2410 else { $table_data .= "<td> </td>"; }
2412 $table_data .= "</tr>\n";
2414 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2416 $stat_data = "<tr><td><b><font size=-2>$total_elders Elders<br>PPI Totals:</font></b></td>";
2417 for($m=$num_months; $m >=0; $m--) {
2418 $percent = ceil(($ppis[$m] / $total_elders)*100);
2419 $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
2421 $stat_data .= "</tr>";
2423 $this->t->set_var('table_width',$table_width);
2424 $this->t->set_var('header_row',$header_row);
2425 $this->t->set_var('table_data',$table_data);
2426 $this->t->set_var('stat_data',$stat_data);
2427 $this->t->pfp('out','ppi_view_t');
2428 $this->save_sessiondata();
2431 function ppi_update()
2433 $this->t->set_file(array('form' => 'ppi_update.tpl'));
2434 $this->t->set_block('form','interviewer_list','int_list');
2435 $this->t->set_block('form','add','addhandle');
2436 $this->t->set_block('form','edit','edithandle');
2438 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_view'));
2439 $this->t->set_var('readonly','');
2440 $this->t->set_var('disabled','');
2442 $action = get_var('action',array('GET','POST'));
2443 $companionship = get_var('companionship',array('GET','POST'));
2444 $interviewer = get_var('interviewer',array('GET','POST'));
2445 $name = get_var('name',array('GET','POST'));
2446 $ppi = get_var('ppi',array('GET','POST'));
2447 $elder = get_var('elder',array('GET','POST'));
2448 $aaronic = get_var('aaronic',array('GET','POST'));
2449 $date = get_var('date',array('GET','POST'));
2450 $notes = get_var('notes',array('GET','POST'));
2451 $eqpresppi = get_var('eqpresppi',array('GET','POST'));
2453 $sql = "SELECT * FROM eq_elder WHERE elder=" . $interviewer;
2454 $this->db2->query($sql,__LINE__,__FILE__);
2455 $this->db2->next_record();
2456 $interviewer_name = $this->db2->f('name');
2457 $this->t->set_var('interviewer',$interviewer . ' selected');
2458 $this->t->set_var('interviewer_name',$interviewer_name);
2459 $this->t->set_var('eqpresppi_checked','');
2460 $this->t->fp('int_list','interviewer_list',True);
2462 if($action == 'save')
2464 $notes = get_var('notes',array('POST'));
2465 $this->db->query("UPDATE eq_ppi set " .
2466 " ppi='" . $ppi . "'" .
2467 ", interviewer='" . $interviewer . "'" .
2468 ", elder='" . $elder . "'" .
2469 ", aaronic='" . $aaronic . "'" .
2470 ", date='" . $date . "'" .
2471 ", notes='" . $notes . "'" .
2472 ", eqpresppi='" . $eqpresppi . "'" .
2473 " WHERE ppi=" . $ppi,__LINE__,__FILE__);
2478 if($action == 'insert')
2480 $notes = get_var('notes',array('POST'));
2481 $this->db->query("INSERT INTO eq_ppi (interviewer,elder,aaronic,date,notes,eqpresppi) "
2482 . "VALUES ('" . $interviewer . "','" . $elder . "','" . $aaronic . "','"
2483 . $date . "','" . $notes . "','" . $eqpresppi ."')",__LINE__,__FILE__);
2488 if($action == 'add')
2490 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2491 $this->t->set_var('ppi', '');
2492 $this->t->set_var('interviewer', $interviewer);
2493 $this->t->set_var('name',$name);
2494 $this->t->set_var('elder',$elder);
2495 $this->t->set_var('date','');
2496 $this->t->set_var('notes','');
2497 $this->t->set_var('eqpresppi',$eqpresppi);
2498 $this->t->set_var('eqpresppi_checked','checked');
2499 $this->t->set_var('lang_done','Cancel');
2500 $this->t->set_var('lang_action','Adding New PPI');
2501 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
2502 . $ppi . '&action=' . 'insert'));
2505 if($action == 'edit' || $action == 'view')
2507 $sql = "SELECT * FROM eq_ppi WHERE ppi=".$ppi;
2508 $this->db->query($sql,__LINE__,__FILE__);
2509 $this->db->next_record();
2510 $this->t->set_var('ppi',$ppi);
2511 $this->t->set_var('name',$name);
2512 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2513 $this->t->set_var('elder',$this->db->f('elder'));
2514 $this->t->set_var('date',$this->db->f('date'));
2515 $this->t->set_var('notes',$this->db->f('notes'));
2516 $this->t->set_var('eqpresppi',$this->db->f('eqpresppi'));
2517 if($this->db->f('eqpresppi') == 1) { $this->t->set_var('eqpresppi_checked','checked'); }
2520 if($action == 'edit')
2522 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2523 $this->t->set_var('lang_done','Cancel');
2524 $this->t->set_var('lang_action','Editing PPI');
2525 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
2526 . $ppi . '&action=' . 'save'));
2529 if($action == 'view')
2531 $date = $this->db->f('date');
2532 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2533 $this->t->set_var('readonly','READONLY');
2534 $this->t->set_var('disabled','DISABLED');
2535 $this->t->set_var('lang_done','Done');
2536 $this->t->set_var('lang_action','Viewing PPI');
2537 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_update&ppi='
2538 . $ppi . '&action=' . 'edit'));
2541 $this->t->set_var('lang_reset','Clear Form');
2542 $this->t->set_var('lang_add','Add PPI');
2543 $this->t->set_var('lang_save','Save Changes');
2544 $this->t->set_var('edithandle','');
2545 $this->t->set_var('addhandle','');
2547 $this->t->pfp('out','form');
2549 if($action == 'view') { $this->t->set_var('lang_save','Edit PPI'); }
2550 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2551 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2553 $this->save_sessiondata();
2558 $this->t->set_file(array('int_view_t' => 'int_view.tpl'));
2559 $this->t->set_block('int_view_t','district_list','list');
2561 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_view'));
2562 $num_quarters = get_var('num_quarters',array('GET','POST'));
2563 if($num_quarters == '') { $num_quarters = $this->default_int_num_quarters; }
2564 $this->t->set_var('num_quarters',$num_quarters);
2565 if($num_quarters == 1) { $this->t->set_var('lang_num_quarters','Quarter of History'); }
2566 else { $this->t->set_var('lang_num_quarters','Quarters of History'); }
2567 $this->t->set_var('lang_filter','Filter');
2569 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_view'));
2570 $this->t->set_var('int_link_title','Hometeaching Interviews');
2572 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_sched'));
2573 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
2575 $this->t->set_var('title','Hometeaching Interviews');
2577 $num_months = $num_quarters * 3 - 1;
2578 $current_month = $this->current_month;
2579 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
2580 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
2581 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
2582 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
2584 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
2585 $this->db->query($sql,__LINE__,__FILE__);
2587 while ($this->db->next_record())
2589 $districts[$i]['district'] = $this->db->f('district');
2590 $districts[$i]['name'] = $this->db->f('name');
2591 $districts[$i]['supervisor'] = $this->db->f('supervisor');
2595 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
2596 $this->db->query($sql,__LINE__,__FILE__);
2598 while ($this->db->next_record())
2600 $elder_id[$i] = $this->db->f('elder');
2601 $elder_name[$i] = $this->db->f('name');
2602 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
2605 array_multisort($elder_name, $elder_id);
2606 for($i=0; $i < count($elder_id); $i++) {
2607 $id = $elder_id[$i];
2608 $elders[$id] = $elder_name[$i];
2611 $sql = "SELECT * FROM eq_aaronic where valid=1 ORDER BY aaronic ASC";
2612 $this->db->query($sql,__LINE__,__FILE__);
2613 while ($this->db->next_record())
2615 $aaronic_id = $this->db->f('aaronic');
2616 $aaronic[$aaronic_id]['name'] = $this->db->f('name');
2617 $aaronic[$aaronic_id]['phone'] = $this->db->f('phone');
2620 $total_companionships = 0;
2621 $this->nextmatchs->template_alternate_row_color(&$this->t);
2622 for ($i=0; $i < count($districts); $i++) {
2623 $this->t->set_var('district_number',$districts[$i]['district']);
2624 $this->t->set_var('district_name',$districts[$i]['name']);
2625 $supervisor = $districts[$i]['supervisor'];
2626 $unique_companionships='';
2628 // Select all the unique companionship numbers for this district
2629 $sql = "SELECT distinct companionship FROM eq_companionship where valid=1 and district=". $districts[$i]['district'];
2631 $this->db->query($sql,__LINE__,__FILE__);
2633 while ($this->db->next_record())
2635 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
2639 $comp_width=250; $int_width=75; $table_width=$comp_width + $num_months*$int_width;
2640 $table_data=""; $num_companionships = $j; $num_elders = 0;
2641 for($m=$num_months; $m >= 0; $m--) { $ints[$m] = 0; }
2642 for ($j=0; $j < count($unique_companionships); $j++) {
2643 // Select all the companions in each companionship
2644 $sql = "SELECT * FROM eq_companionship where valid=1 and ".
2645 "companionship=". $unique_companionships[$j]['companionship'];
2646 $this->db->query($sql,__LINE__,__FILE__);
2648 $comp = $unique_companionships[$j]['companionship'];
2649 for($m=$num_months; $m >= 0; $m--) { $int_recorded[$comp][$m] = 0; }
2650 while ($this->db->next_record())
2652 // Get this companions information
2654 $companionship = $this->db->f('companionship');
2655 $elder_id = $this->db->f('elder');
2656 $aaronic_id = $this->db->f('aaronic');
2658 $name = $elders[$elder_id];
2659 $phone = $elder_phone[$elder_id];
2661 else if($aaronic_id) {
2662 $name = $aaronic[$aaronic_id]['name'];
2663 $phone = $aaronic[$aaronic_id]['phone'];
2665 $link_data['menuaction'] = 'eq.eq.int_update';
2666 $link_data['companionship'] = $companionship;
2667 $link_data['interviewer'] = $supervisor;
2668 $link_data['elder'] = $elder_id;
2669 $link_data['aaronic'] = $aaronic_id;
2670 $link_data['name'] = $name;
2671 $link_data['ppi'] = '';
2672 $link_data['action'] = 'add';
2673 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2674 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2676 // Find out how many times Interviews were performed in the past $num_months for this Elder
2677 $header_row="<th width=$comp_width><font size=-2>Companionship</th>";
2678 for($m=$num_months; $m >= 0; $m--) {
2679 $month = $current_month - $m;
2680 $year = $this->current_year;
2681 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
2682 if($month < 10) { $month = "0"."$month"; }
2683 $month_start = "$year"."-"."$month"."-"."01";
2684 $month_end = "$year"."-"."$month"."-"."31";
2685 $month = "$month"."/"."$year";
2686 $sql = "SELECT * FROM eq_ppi WHERE date >= '$month_start' AND date <= '$month_end' ".
2687 "AND elder=" . $elder_id . " AND aaronic=" . $aaronic_id;
2688 $this->db2->query($sql,__LINE__,__FILE__);
2689 $header_row .= "<th width=$int_width><font size=-2>$month</th>";
2691 if(!$total_ints[$m]) { $total_ints[$m] = 0; }
2692 if($this->db2->next_record()) {
2693 if(!$int_recorded[$companionship][$m]) {
2694 $ints[$m]++; $total_ints[$m]++; $int_recorded[$companionship][$m]=1;
2696 $link_data['menuaction'] = 'eq.eq.int_update';
2697 $link_data['companionship'] = $companionship;
2698 $link_data['interviewer'] = $this->db2->f('interviewer');
2699 $link_data['elder'] = $elder_id;
2700 $link_data['aaronic'] = $aaronic_id;
2701 $link_data['name'] = $name;
2702 $link_data['ppi'] = $this->db2->f('ppi');
2703 $link_data['action'] = 'view';
2704 $date = $this->db2->f('date');
2705 $date_array = explode("-",$date);
2706 $month = $date_array[1];
2707 $day = $date_array[2];
2708 $link = $GLOBALS['phpgw']->link('/eq/index.php',$link_data);
2709 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2711 else { $table_data .= "<td> </td>"; }
2713 $table_data .= "</tr>";
2716 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2718 $total_companionships += $num_companionships;
2719 $stat_data = "<tr><td><b><font size=-2>$num_companionships Companionships<br>Interview Quarterly Totals:</font></b></td>";
2721 // Print the hometeaching interview stats
2722 if($this->monthly_hometeaching_interviews == 0) { //Quarterly
2723 for($m=$num_months; $m >=0; $m--) {
2724 $month = $current_month - $m;
2725 if(($month % 3) == 1) { $quarter_total = $ints[$m]; }
2726 else { $quarter_total += $ints[$m]; }
2727 $percent = ceil(($quarter_total / $num_companionships)*100);
2728 $stat_data .= "<td align=center><font size=-2><b>$quarter_total<br>$percent%</font></b></td>";
2730 $stat_data .= "</tr>";
2733 for($m=$num_months; $m >=0; $m--) {
2734 $percent = ceil(($ints[$m] / $num_companionships)*100);
2735 $stat_data .= "<td align=center><font size=-2><b>$ints[$m]<br>$percent%</font></b></td>";
2737 $stat_data .= "</tr>";
2740 $this->t->set_var('table_width',$table_width);
2741 $this->t->set_var('header_row',$header_row);
2742 $this->t->set_var('table_data',$table_data);
2743 $this->t->set_var('stat_data',$stat_data);
2744 $this->t->fp('list','district_list',True);
2747 // Display the totals
2748 if($this->monthly_hometeaching_interviews == 0) { //Quarterly
2750 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>Interview Quarterly Totals:</font></b></td>";
2751 for($m=$num_months; $m >=0; $m--) {
2752 $month = $current_month - $m;
2753 if(($month % 3) == 1) { $quarter_total = $total_ints[$m]; }
2754 else { $quarter_total += $total_ints[$m]; }
2755 $percent = ceil(($quarter_total / $total_companionships)*100);
2756 $totals .= "<td align=center><font size=-2><b>$quarter_total<br>$percent%</font></b></td>";
2761 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>Interview Monthly Totals:</font></b></td>";
2762 for($m=$num_months; $m >=0; $m--) {
2763 $percent = ceil(($total_ints[$m] / $total_companionships)*100);
2764 $totals .= "<td align=center><font size=-2><b>$total_ints[$m]<br>$percent%</font></b></td>";
2769 $this->t->set_var('totals',$totals);
2770 $this->t->pfp('out','int_view_t');
2771 $this->save_sessiondata();
2774 function int_update()
2776 $this->t->set_file(array('form' => 'int_update.tpl'));
2777 $this->t->set_block('form','interviewer_list','int_list');
2778 $this->t->set_block('form','add','addhandle');
2779 $this->t->set_block('form','edit','edithandle');
2781 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_view'));
2782 $this->t->set_var('readonly','');
2783 $this->t->set_var('disabled','');
2784 $this->t->set_var('eqpresppi_checked','');
2786 $action = get_var('action',array('GET','POST'));
2787 $companionship = get_var('companionship',array('GET','POST'));
2788 $interviewer = get_var('interviewer',array('GET','POST'));
2789 $name = get_var('name',array('GET','POST'));
2790 $ppi = get_var('ppi',array('GET','POST'));
2791 $elder = get_var('elder',array('GET','POST'));
2792 $aaronic = get_var('aaronic',array('GET','POST'));
2793 $date = get_var('date',array('GET','POST'));
2794 $notes = get_var('notes',array('GET','POST'));
2795 $eqpresppi = get_var('eqpresppi',array('GET','POST'));
2797 $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
2798 $this->db->query($sql,__LINE__,__FILE__);
2799 while ($this->db->next_record())
2801 $supervisor = $this->db->f('supervisor');
2802 $sql = "SELECT * FROM eq_elder WHERE elder=" . $supervisor;
2803 $this->db2->query($sql,__LINE__,__FILE__);
2804 $this->db2->next_record();
2805 $interviewer_name = $this->db2->f('name');
2807 if($supervisor == $interviewer) {
2808 $this->t->set_var('interviewer',$supervisor . ' selected');
2810 $this->t->set_var('interviewer',$interviewer);
2812 $this->t->set_var('interviewer_name',$interviewer_name);
2813 $this->t->fp('int_list','interviewer_list',True);
2816 if($action == 'save')
2818 $notes = get_var('notes',array('POST'));
2819 $this->db->query("UPDATE eq_ppi set " .
2820 " ppi='" . $ppi . "'" .
2821 ", interviewer='" . $interviewer . "'" .
2822 ", elder='" . $elder . "'" .
2823 ", aaronic='" . $aaronic . "'" .
2824 ", date='" . $date . "'" .
2825 ", notes='" . $notes . "'" .
2826 ", eqpresppi='" . $eqpresppi . "'" .
2827 " WHERE ppi=" . $ppi,__LINE__,__FILE__);
2832 if($action == 'insert')
2834 $notes = get_var('notes',array('POST'));
2835 $this->db->query("INSERT INTO eq_ppi (interviewer,elder,aaronic,date,notes,eqpresppi) "
2836 . "VALUES ('" . $interviewer . "','" . $elder . "','" . $aaronic . "','"
2837 . $date . "','" . $notes ."','" . $eqpresppi . "')",__LINE__,__FILE__);
2842 if($action == 'add')
2844 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2845 $this->t->set_var('ppi', '');
2846 $this->t->set_var('interviewer', $interviewer);
2847 $this->t->set_var('name',$name);
2848 $this->t->set_var('elder',$elder);
2849 $this->t->set_var('aaronic',$aaronic);
2850 $this->t->set_var('date','');
2851 $this->t->set_var('notes','');
2852 $this->t->set_var('lang_done','Cancel');
2853 $this->t->set_var('lang_action','Adding New Interview');
2854 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_update&ppi='
2855 . $ppi . '&action=' . 'insert'));
2858 if($action == 'edit' || $action == 'view')
2860 $sql = "SELECT * FROM eq_ppi WHERE ppi=".$ppi;
2861 $this->db->query($sql,__LINE__,__FILE__);
2862 $this->db->next_record();
2863 $this->t->set_var('ppi',$ppi);
2864 $this->t->set_var('name',$name);
2865 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2866 $this->t->set_var('elder',$this->db->f('elder'));
2867 $this->t->set_var('aaronic',$this->db->f('aaronic'));
2868 $this->t->set_var('date',$this->db->f('date'));
2869 $this->t->set_var('notes',$this->db->f('notes'));
2870 if($this->db->f('eqpresppi') == 1) { $this->t->set_var('eqpresppi_checked','checked'); }
2873 if($action == 'edit')
2875 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2876 $this->t->set_var('lang_done','Cancel');
2877 $this->t->set_var('lang_action','Editing Interview');
2878 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_update&ppi='
2879 . $ppi . '&action=' . 'save'));
2882 if($action == 'view')
2884 $date = $this->db->f('date');
2885 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2886 $this->t->set_var('readonly','READONLY');
2887 $this->t->set_var('disabled','DISABLED');
2888 $this->t->set_var('lang_done','Done');
2889 $this->t->set_var('lang_action','Viewing Interview');
2890 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_update&ppi='
2891 . $ppi . '&action=' . 'edit'));
2894 $this->t->set_var('lang_reset','Clear Form');
2895 $this->t->set_var('lang_add','Add Interview');
2896 $this->t->set_var('lang_save','Save Changes');
2897 $this->t->set_var('edithandle','');
2898 $this->t->set_var('addhandle','');
2900 $this->t->pfp('out','form');
2902 if($action == 'view') { $this->t->set_var('lang_save','Edit Interview'); }
2903 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2904 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2906 $this->save_sessiondata();
2911 $this->t->set_file(array('vis_view_t' => 'vis_view.tpl'));
2912 $this->t->set_block('vis_view_t','visit_list','list1');
2913 $this->t->set_block('vis_view_t','family_list','list2');
2915 $this->t->set_var('lang_name','Family Name');
2916 $this->t->set_var('lang_date','Date');
2918 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
2919 $this->t->set_var('vis_link_title','View Yearly Visits');
2921 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched'));
2922 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2924 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
2925 $num_years = get_var('num_years',array('GET','POST'));
2926 if($num_years == '') { $num_years = $this->default_vis_num_years; }
2927 $this->t->set_var('num_years',$num_years);
2928 if($num_years == 1) { $this->t->set_var('lang_num_years','Year of History'); }
2929 else { $this->t->set_var('lang_num_years','Years of History'); }
2930 $this->t->set_var('lang_filter','Filter');
2932 $year = date('Y') - $num_years + 1;
2933 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2935 $sql = "SELECT * FROM eq_visit WHERE companionship=0 and date > '$year_start' ORDER BY date DESC";
2936 $this->db->query($sql,__LINE__,__FILE__);
2937 $total_records = $this->db->num_rows();
2940 while ($this->db->next_record())
2942 $visit_list[$i]['visit'] = $this->db->f('visit');
2943 $visit_list[$i]['family'] = $this->db->f('family');
2944 $visit_list[$i]['date'] = $this->db->f('date');
2948 for ($i=0; $i < count($visit_list); $i++)
2950 $this->nextmatchs->template_alternate_row_color(&$this->t);
2952 $sql = "SELECT * FROM eq_family WHERE family=".$visit_list[$i]['family'];
2953 $this->db->query($sql,__LINE__,__FILE__);
2954 $this->db->next_record();
2956 $this->t->set_var('family',$visit_list[$i]['family']);
2957 $this->t->set_var('family_name',$this->db->f('name'));
2958 $this->t->set_var('date',$visit_list[$i]['date']);
2960 $link_data['menuaction'] = 'eq.eq.vis_update';
2961 $link_data['visit'] = $visit_list[$i]['visit'];
2962 $link_data['name'] = $this->db->f('name');
2963 $link_data['date'] = $visit_list[$i]['date'];
2964 $link_data['action'] = 'view';
2965 $this->t->set_var('view',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
2966 $this->t->set_var('lang_view','View');
2968 $link_data['menuaction'] = 'eq.eq.vis_update';
2969 $link_data['visit'] = $visit_list[$i]['visit'];
2970 $link_data['name'] = $this->db->f('name');
2971 $link_data['date'] = $visit_list[$i]['date'];
2972 $link_data['action'] = 'edit';
2973 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
2974 $this->t->set_var('lang_edit','Edit');
2976 $this->t->fp('list1','visit_list',True);
2979 // List the families that are available to record a visit against
2980 $sql = "SELECT * FROM eq_family WHERE valid=1";
2981 $this->db->query($sql,__LINE__,__FILE__);
2982 $total_records = $this->db->num_rows();
2985 while ($this->db->next_record())
2987 $family_names[$i] = $this->db->f('name');
2988 $family_ids[$i] = $this->db->f('family');
2990 } array_multisort($family_names, $family_ids);
2992 for ($i=0; $i < count($family_names); $i++)
2994 $link_data['menuaction'] = 'eq.eq.vis_update';
2995 $link_data['visit'] = '';
2996 $link_data['family'] = $family_ids[$i];
2997 $link_data['action'] = 'add';
2998 $link_data['name'] = $family_names[$i];
2999 $this->t->set_var('add',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
3001 $this->t->set_var('name',$family_names[$i]);
3002 if(($i+1) % 3 == 0) { $this->t->set_var('table_sep',"</td></tr><tr>"); }
3003 else { $this->t->set_var('table_sep',"</td>"); }
3004 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
3006 $this->t->fp('list2','family_list',True);
3009 $this->t->pfp('out','vis_view_t');
3010 $this->save_sessiondata();
3013 function vis_update()
3015 $this->t->set_file(array('form' => 'vis_update.tpl'));
3016 $this->t->set_block('form','add','addhandle');
3017 $this->t->set_block('form','edit','edithandle');
3019 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view'));
3020 $this->t->set_var('readonly','');
3021 $this->t->set_var('disabled','');
3023 $action = get_var('action',array('GET','POST'));
3024 $visit = get_var('visit',array('GET','POST'));
3025 $family = get_var('family',array('GET','POST'));
3026 $name = get_var('name',array('GET','POST'));
3027 $date = get_var('date',array('GET','POST'));
3028 $notes = get_var('notes',array('GET','POST'));
3031 if($action == 'save')
3033 $notes = get_var('notes',array('POST'));
3034 $this->db->query("UPDATE eq_visit set " .
3035 " date='" . $date . "'" .
3036 ", notes='" . $notes . "'" .
3037 " WHERE visit=" . $visit,__LINE__,__FILE__);
3042 if($action == 'insert')
3044 $notes = get_var('notes',array('POST'));
3045 $this->db->query("INSERT INTO eq_visit (family,companionship,date,notes) "
3046 . "VALUES ('" . $family . "','" . $companionship . "','"
3047 . $date . "','" . $notes . "')",__LINE__,__FILE__);
3052 if($action == 'add')
3054 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
3055 $this->t->set_var('family', $family);
3056 $this->t->set_var('visit', '');
3057 $this->t->set_var('name', $name);
3058 $this->t->set_var('date','');
3059 $this->t->set_var('notes','');
3060 $this->t->set_var('lang_done','Cancel');
3061 $this->t->set_var('lang_action','Adding New Visit');
3062 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&family='
3063 . $family . '&action=' . 'insert'));
3066 if($action == 'edit' || $action == 'view')
3068 $sql = "SELECT * FROM eq_visit WHERE visit=".$visit;
3069 $this->db->query($sql,__LINE__,__FILE__);
3070 $this->db->next_record();
3071 $this->t->set_var('visit',$visit);
3072 $this->t->set_var('name',$name);
3073 $this->t->set_var('family', $family);
3074 $this->t->set_var('date',$this->db->f('date'));
3075 $this->t->set_var('notes',$this->db->f('notes'));
3078 if($action == 'edit')
3080 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
3081 $this->t->set_var('lang_done','Cancel');
3082 $this->t->set_var('lang_action','Editing Visit');
3083 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&visit='
3084 . $visit . '&action=' . 'save'));
3087 if($action == 'view')
3089 $date = $this->db->f('date');
3090 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
3091 $this->t->set_var('readonly','READONLY');
3092 $this->t->set_var('disabled','DISABLED');
3093 $this->t->set_var('lang_done','Done');
3094 $this->t->set_var('lang_action','Viewing Visit');
3095 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_update&visit='
3096 . $visit . '&action=' . 'edit'));
3099 $this->t->set_var('lang_reset','Clear Form');
3100 $this->t->set_var('lang_add','Add Visit');
3101 $this->t->set_var('lang_save','Save Changes');
3102 $this->t->set_var('edithandle','');
3103 $this->t->set_var('addhandle','');
3105 $this->t->pfp('out','form');
3107 if($action == 'view') { $this->t->set_var('lang_save','Edit Visit'); }
3108 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
3109 if($action == 'add') { $this->t->pfp('addhandle','add'); }
3111 $this->save_sessiondata();
3116 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3117 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3118 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3120 $this->t->set_file(array('att_view_t' => 'att_view.tpl'));
3121 $this->t->set_block('att_view_t','act_list','list');
3123 $this->t->set_block('att_view_t','month_list','list1');
3124 $this->t->set_block('att_view_t','header_list','list2');
3125 $this->t->set_block('att_view_t','elder_list','list3');
3127 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_view'));
3128 $num_quarters = get_var('num_quarters',array('GET','POST'));
3129 if($num_quarters == '') { $num_quarters = $this->default_att_num_quarters; }
3130 $this->t->set_var('num_quarters',$num_quarters);
3131 $this->t->set_var('lang_filter','Filter');
3132 if($num_quarters == 1) { $this->t->set_var('lang_num_quarters','Quarter of History'); }
3133 else { $this->t->set_var('lang_num_quarters','Quarters of History'); }
3135 $num_months = $num_quarters * 3;
3136 $current_month = $this->current_month;
3137 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
3138 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
3139 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
3140 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
3142 $sql = "SELECT * FROM eq_elder where valid=1";
3143 $this->db->query($sql,__LINE__,__FILE__);
3145 while ($this->db->next_record())
3147 $elder_name[$i] = $this->db->f('name');
3148 $elder_id[$i] = $this->db->f('elder');
3151 array_multisort($elder_name, $elder_id);
3153 // Create a list of sunday dates for a window of 3 months back and current month
3157 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $current_month-$num_months, 1, date("y")));
3158 $last_date = explode("-",$sunday_list[0]['date']);
3159 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3160 $time_limit = mktime(0, 0, 0, date("m"), date("t"), date("y"));
3161 while($last_time < $time_limit)
3163 $day = date("w",$last_time);
3164 if(date("w",$last_time) == 0) {
3165 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3166 $last_date = explode("-",$sunday_list[$i]['date']);
3167 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3168 $sunday_list[$i]['day'] = $last_date[2];
3169 $sunday_list[$i]['month'] = date("M",$last_time);
3170 $sunday_list[$i]['year'] = $last_date[0];
3173 $last_time += 90000;
3174 if($found_sunday) { $i++; $found_sunday=0; }
3177 $total_elders = count($elder_id);
3178 $old_month=$sunday_list[0]['month']; $span=0;
3179 for ($i=0; $i < count($sunday_list); $i++) {
3180 $date = $sunday_list[$i]['date'];
3181 $this->t->set_var('date',$sunday_list[$i]['date']);
3182 $this->t->set_var('day',$sunday_list[$i]['day']);
3183 if(($old_month != $sunday_list[$i]['month']) || $i == count($sunday_list)-1) {
3184 if($i == count($sunday_list)-1) { $span++; }
3185 $cur_month = $sunday_list[$i]['month'];
3186 $old_month = $sunday_list[$i]['month'];
3187 $link_data['menuaction'] = 'eq.eq.att_update';
3188 $link_data['month'] = $sunday_list[$i-1]['month'];
3189 $link_data['year'] = $sunday_list[$i-1]['year'];
3190 $link_data['action'] = 'update_month';
3191 $cur_month = $sunday_list[$i-1]['month'];
3192 $cur_year = $sunday_list[$i-1]['year'];
3193 $header_row .= "<th><font size=-3>$cur_month $cur_year</font></th>";
3194 $this->t->set_var('update_month',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
3195 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3196 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3197 $this->t->set_var('span',$span); $span=0;
3198 $this->t->fp('list1','month_list',True);
3201 $this->t->set_var('total_elders',$total_elders);
3202 $this->t->set_var('header_row',$header_row);
3204 $elder_width=200; $att_width=25; $total_width=$elder_width;
3205 for ($i=0; $i < count($sunday_list); $i++) {
3206 $link_data['menuaction'] = 'eq.eq.att_update';
3207 $link_data['month'] = $sunday_list[$i]['month'];
3208 $link_data['year'] = $sunday_list[$i]['year'];
3209 $link_data['day'] = $sunday_list[$i]['day'];
3210 $link_data['date'] = $sunday_list[$i]['date'];
3211 $link_data['action'] = 'update_day';
3212 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
3213 $this->t->set_var('date',$sunday_list[$i]['date']);
3214 $this->t->set_var('day',$sunday_list[$i]['day']);
3215 $this->t->set_var('month',$sunday_list[$i]['month']);
3216 $this->t->set_var('year',$sunday_list[$i]['year']);
3217 $this->t->fp('list2','header_list',True);
3218 $total_width += $att_width;
3219 $attendance[$monthnum[$sunday_list[$i]['month']]]=0;
3222 for ($i=0; $i < count($elder_id); $i++) {
3224 $this->nextmatchs->template_alternate_row_color(&$this->t);
3225 $this->t->set_var('elder_name',$elder_name[$i]);
3226 #print "checking for elder: " . $elder_id[$i] . "<br>";
3227 for ($j=0; $j < count($sunday_list); $j++) {
3228 #print "checking for date: " . $sunday_list[$j]['date'] . "<br>";
3229 #print "SELECT * FROM eq_attendance WHERE date='"
3230 # . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i] . "<br>";
3231 $sql = "SELECT * FROM eq_attendance WHERE date='"
3232 . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i];
3233 $this->db->query($sql,__LINE__,__FILE__);
3234 if($this->db->next_record()) {
3235 $cur_month = $sunday_list[$j]['month'];
3236 if($attended[$i][$cur_month] != 1) {
3237 $attended[$i][$cur_month]=1;
3238 $attendance[$monthnum[$cur_month]]++;
3240 $att_table .= '<td align=center><img src="images/checkmark.gif"></td>';
3242 $att_table .= '<td> </td>';
3245 $this->t->set_var('att_table',$att_table);
3246 $this->t->fp('list3','elder_list',True);
3248 $this->t->set_var('total_width',$total_width);
3249 $this->t->set_var('elder_width',$elder_width);
3250 $this->t->set_var('att_width',$att_width);
3252 # Now calculate attendance for these months
3253 $attendance_str = "";
3254 $nonattendance_str = "";
3255 $aveattendance_str = "";
3256 $avenonattendance_str = "";
3258 $ave_total_attended=0;
3260 foreach($attendance as $att => $value) {
3261 $total_attended = $attendance[$att];
3262 $ave_total_attended += $attendance[$att]; $num_months++;
3263 $percent = ceil(($total_attended / $total_elders)*100);
3264 $attendance_str.="<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3265 $total_nonattended = $total_elders - $total_attended;
3266 $percent = ceil(($total_nonattended / $total_elders)*100);
3267 $nonattendance_str.="<td align=center><font size=-2><b>$total_nonattended ($percent%)</b></font></td>";
3269 $total_attended = ceil(($ave_total_attended / $num_months));
3270 $percent = ceil(($total_attended / $total_elders)*100);
3271 $aveattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3272 $total_attended = $total_elders - ceil(($ave_total_attended / $num_months));
3273 $percent = ceil(($total_attended / $total_elders)*100);
3274 $avenonattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3277 $this->t->set_var('attendance',$attendance_str);
3278 $this->t->set_var('aveattendance',$aveattendance_str);
3279 $this->t->set_var('nonattendance',$nonattendance_str);
3280 $this->t->set_var('avenonattendance',$avenonattendance_str);
3282 $this->t->pfp('out','att_view_t');
3283 $this->save_sessiondata();
3286 function att_update()
3288 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3289 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3290 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3292 $this->t->set_file(array('form' => 'att_update.tpl'));
3293 $this->t->set_block('form','edit','edithandle');
3295 $this->t->set_block('form','month_list','list1');
3296 $this->t->set_block('form','header_list','list2');
3297 $this->t->set_block('form','elder_list','list3');
3299 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_view'));
3301 $action = get_var('action',array('GET','POST'));
3302 $month = get_var('month',array('GET','POST'));
3303 $year = get_var('year',array('GET','POST'));
3304 $day = get_var('day',array('GET','POST'));
3305 $date = get_var('date',array('GET','POST'));
3307 if($action == 'save_month' || $action == 'save_day')
3309 $new_data = get_var('elders_attended',array('POST'));
3310 $month = $monthnum[$month]; if($month < 10) { $month = "0" . $month; }
3312 if($action == 'save_month') {
3313 $this->db->query("DELETE from eq_attendance where date LIKE '".$year."-".$month."-%'",__LINE__,__FILE__);
3316 if($action == 'save_day') {
3317 $this->db->query("DELETE from eq_attendance where date LIKE '".$year."-".$month."-".$day."'",__LINE__,__FILE__);
3320 foreach ($new_data as $data)
3322 $data_array = explode("-",$data);
3323 $elder = $data_array[0];
3324 $date = "$data_array[1]-$data_array[2]-$data_array[3]";
3325 $this->db->query("INSERT INTO eq_attendance (elder,date) "
3326 . "VALUES (" . $elder . ",'". $date . "')",__LINE__,__FILE__);
3333 $sql = "SELECT * FROM eq_elder where valid=1";
3334 $this->db->query($sql,__LINE__,__FILE__);
3336 while ($this->db->next_record())
3338 $elder_name[$i] = $this->db->f('name');
3339 $elder_id[$i] = $this->db->f('elder');
3340 $elder_attending[$elder_id[$i]] = $this->db->f('attending');
3343 array_multisort($elder_name, $elder_id);
3345 if($action == 'update_month')
3347 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_update&action=save_month'));
3351 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], 1, $year));
3352 $last_date = explode("-",$sunday_list[0]['date']);
3353 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3354 $time_limit = mktime(0, 0, 0, $monthnum[$month], 31, $year);
3355 while($last_time <= $time_limit)
3357 $day = date("w",$last_time);
3358 if(date("w",$last_time) == 0) {
3359 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3360 $last_date = explode("-",$sunday_list[$i]['date']);
3361 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3362 $sunday_list[$i]['day'] = $last_date[2];
3363 $sunday_list[$i]['month'] = date("M",$last_time);
3364 $sunday_list[$i]['year'] = $last_date[0];
3367 $last_time += 90000;
3368 if($found_sunday) { $i++; $found_sunday=0; }
3371 $this->t->set_var('span', $i);
3372 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3373 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3374 $this->t->fp('list1','month_list',True);
3375 $elder_width=200; $att_width=25; $total_width=$elder_width;
3376 for ($i=0; $i < count($sunday_list); $i++) {
3377 $link_data['menuaction'] = 'eq.eq.att_update';
3378 $link_data['month'] = $sunday_list[$i]['month'];
3379 $link_data['year'] = $sunday_list[$i]['year'];
3380 $link_data['day'] = $sunday_list[$i]['day'];
3381 $link_data['date'] = $sunday_list[$i]['date'];
3382 $link_data['action'] = 'update_day';
3383 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
3384 $this->t->set_var('date',$sunday_list[$i]['date']);
3385 $this->t->set_var('day',$sunday_list[$i]['day']);
3386 $this->t->set_var('month',$sunday_list[$i]['month']);
3387 $this->t->set_var('year',$sunday_list[$i]['year']);
3388 $this->t->fp('list2','header_list',True);
3389 $total_width += $att_width;
3393 if($action == 'update_day')
3395 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.att_update&action=save_day'));
3396 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], $day, $year));
3397 $this->t->set_var('month',$month);
3398 $this->t->set_var('year',$year);
3399 $this->t->fp('list1','month_list',True);
3400 $this->t->set_var('date',$date);
3401 $this->t->set_var('day',$day);
3402 $this->t->set_var('month',$month);
3403 $this->t->set_var('year',$year);
3404 $this->t->fp('list2','header_list',True);
3407 for ($i=0; $i < count($elder_id); $i++) {
3409 $this->nextmatchs->template_alternate_row_color(&$this->t);
3410 $this->t->set_var('elder_name',$elder_name[$i]);
3411 for ($j=0; $j < count($sunday_list); $j++) {
3412 $sql = "SELECT * FROM eq_attendance WHERE date='"
3413 . $sunday_list[$j]['date'] . "' AND elder=" . $elder_id[$i];
3414 $this->db->query($sql,__LINE__,__FILE__);
3415 $value = $elder_id[$i] . "-" . $sunday_list[$j]['date'];
3416 if($this->db->next_record()) {
3417 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'" checked></td>';
3418 } else if($elder_attending[$elder_id[$i]] == 1) {
3419 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'" checked></td>';
3421 $att_table .= '<td align=center><input type="checkbox" name="elders_attended[]" value="'.$value.'"></td>';
3424 $this->t->set_var('att_table',$att_table);
3425 $this->t->fp('list3','elder_list',True);
3428 $this->t->set_var('lang_done', 'Cancel');
3429 $this->t->set_var('lang_reset','Clear Form');
3430 $this->t->set_var('lang_save','Save Changes');
3432 $this->t->pfp('out','form');
3433 $this->t->pfp('addhandle','edit');
3435 $this->save_sessiondata();
3440 $this->t->set_file(array('dir_view_t' => 'dir_view.tpl'));
3441 $this->t->set_block('dir_view_t','dir_list','list');
3443 $sql = "SELECT * FROM eq_parent where valid=1 ORDER BY name ASC";
3444 $this->db->query($sql,__LINE__,__FILE__);
3446 while ($this->db->next_record())
3448 $parent[$i]['id'] = $this->db->f('parent');
3449 $parent[$i]['name'] = $this->db->f('name');
3450 $parent[$i]['phone'] = $this->db->f('phone');
3451 $parent[$i]['address'] = $this->db->f('address');
3455 for ($i=0; $i < count($parent); $i++)
3457 $name = $parent[$i]['name'];
3458 $phone = $parent[$i]['phone'];
3459 $address = $parent[$i]['address'];
3460 $this->t->set_var('name', $name);
3461 $this->t->set_var('address', $address);
3462 $this->t->set_var('phone', $phone);
3463 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3464 $this->t->set_var('tr_color',$tr_color);
3465 $this->t->fp('list','dir_list',True);
3466 //print "$phone $name $address<br>";
3468 $this->t->pfp('out','dir_view_t');
3469 $this->save_sessiondata();
3474 $this->t->set_file(array('org_view_t' => 'org_view.tpl'));
3475 $this->t->set_block('org_view_t','calling_list','list1');
3476 $this->t->set_block('org_view_t','org_list','list2');
3478 # Display a list ordered alphabetically
3479 $sql = "SELECT * FROM eq_calling ORDER BY name ASC";
3480 $this->db->query($sql,__LINE__,__FILE__);
3482 while ($this->db->next_record())
3484 $calling[$i]['id'] = $this->db->f('indiv_id');
3485 $calling[$i]['name'] = $this->db->f('name');
3486 $calling[$i]['position'] = $this->db->f('position');
3487 $calling[$i]['sustained'] = $this->db->f('sustained');
3488 $calling[$i]['organization'] = $this->db->f('organization');
3491 for ($i=0; $i < count($calling); $i++)
3493 $name = $calling[$i]['name'];
3494 $position = $calling[$i]['position'];
3495 $sustained = $calling[$i]['sustained'];
3496 $organization = $calling[$i]['organization'];
3497 $this->t->set_var('name', $name);
3498 $this->t->set_var('position', $position);
3499 $this->t->set_var('sustained', $sustained);
3500 $this->t->set_var('organization', $organization);
3501 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3502 $this->t->set_var('tr_color',$tr_color);
3503 $this->t->fp('list1','calling_list',True);
3506 # Display a list ordered by organization
3507 $sql = "SELECT * FROM eq_calling ORDER BY sequence ASC";
3508 $this->db->query($sql,__LINE__,__FILE__);
3510 while ($this->db->next_record())
3512 $calling[$i]['id'] = $this->db->f('indiv_id');
3513 $calling[$i]['name'] = $this->db->f('name');
3514 $calling[$i]['position'] = $this->db->f('position');
3515 $calling[$i]['sustained'] = $this->db->f('sustained');
3516 $calling[$i]['organization'] = $this->db->f('organization');
3519 for ($i=0; $i < count($calling); $i++)
3521 $name = $calling[$i]['name'];
3522 $position = $calling[$i]['position'];
3523 $sustained = $calling[$i]['sustained'];
3524 $organization = $calling[$i]['organization'];
3525 $this->t->set_var('name', $name);
3526 $this->t->set_var('position', $position);
3527 $this->t->set_var('sustained', $sustained);
3528 $this->t->set_var('organization', $organization);
3529 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3530 $this->t->set_var('tr_color',$tr_color);
3531 $this->t->fp('list2','org_list',True);
3534 $this->t->pfp('out','org_view_t');
3535 $this->save_sessiondata();
3540 $this->t->set_file(array('sched_t' => 'schedule.tpl'));
3541 $this->t->set_block('sched_t','presidency_list','list');
3543 $action = get_var('action',array('GET','POST'));
3545 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.schedule&action=save'));
3546 $this->t->set_var('title','EQ Scheduling Tool');
3548 $this->t->set_var('lang_save','Save Schedule');
3549 $this->t->set_var('lang_reset','Cancel');
3551 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched'));
3552 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
3554 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.int_sched'));
3555 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
3557 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ppi_sched'));
3558 $this->t->set_var('schedule_ppi_link_title','Schedule Yearly PPIs');
3560 $date_width=150; $time_width=200; $elder_width=200; $family_width=200;
3561 $table_width=$date_width + $time_width + $elder_width + $family_width;
3562 $header_row = "<th width=$date_width><font size=-2>Date</th>";
3563 $header_row.= "<th width=$time_width><font size=-2>Time</th>";
3564 $header_row.= "<th width=$elder_width><font size=-2>Elder</th>";
3565 $header_row.= "<th width=$family_width><font size=-2>Family</th>";
3568 if($action == 'save')
3570 $new_data = get_var('sched',array('POST'));
3571 foreach ($new_data as $presidency_array)
3573 foreach ($presidency_array as $entry)
3575 $presidency = $entry['presidency'];
3576 $appointment = $entry['appointment'];
3577 $date = $entry['date'];
3578 $hour = $entry['hour'];
3579 $minute = $entry['minute'];
3581 $elder = $entry['elder'];
3582 $family = $entry['family'];
3583 if($pm) { $hour = $hour + 12; }
3584 $time = $hour.':'.$minute.':'.'00';
3587 // Zero out the family or elder if date = NULL
3593 // Update an existing appointment
3594 if($appointment < $this->max_appointments)
3596 //Only perform a database update if we have made a change to this appointment
3597 $sql = "SELECT * FROM eq_appointment where " .
3598 "appointment='$appointment'" .
3599 " and presidency='$presidency'" .
3600 " and elder='$elder'" .
3601 " and family='$family'" .
3602 " and date='$date'" .
3603 " and time='$time'";
3604 $this->db->query($sql,__LINE__,__FILE__);
3605 if(!$this->db->next_record()) {
3606 $old_date = $this->db->f('date');
3607 $old_time = $this->db->f('time');
3608 $this->db2->query("UPDATE eq_appointment set" .
3609 " family=" . $family .
3610 " ,elder=" . $elder .
3611 " ,date='" . $date . "'" .
3612 " ,time='" . $time . "'" .
3613 " ,presidency='" . $presidency . "'" .
3614 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
3616 // Email the appointment
3617 $this->email_appt($appointment);
3621 // Add a new appointment
3622 else if(($appointment >= $this->max_appointments) && ($date != "") && ($time != ""))
3624 //print "adding entry: appt=$appointment date: $date time: $time elder: $elder family: $family<br>";
3625 $this->db2->query("INSERT INTO eq_appointment (appointment,presidency,family,elder,date,time,uid) "
3626 . "VALUES (NULL,'" . $presidency . "','" . $family . "','"
3627 . $elder . "','" . $date . "','" . $time . "','" . $uid ."')",__LINE__,__FILE__);
3629 // Now reselect this entry from the database to see if we need
3630 // to send an appointment out for it.
3631 $sql = "SELECT * FROM eq_appointment where " .
3633 " and family='$family'" .
3634 " and presidency='$presidency'" .
3635 " and date='$date'" .
3636 " and time='$time'" .
3638 $this->db3->query($sql,__LINE__,__FILE__);
3639 if($this->db3->next_record()) {
3640 // Email the appointment if warranted
3641 if(($date != "") && ($time != "") && (($elder > 0) || $family > 0)) {
3642 $this->email_appt($this->db3->f('appointment'));
3649 $take_me_to_url = $GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.schedule');
3650 //Header('Location: ' . $take_me_to_url);
3653 $sql = "SELECT * FROM eq_presidency where valid=1";
3654 $this->db->query($sql,__LINE__,__FILE__);
3656 while ($this->db->next_record())
3658 $presidency_data[$i]['id'] = $this->db->f('presidency');
3659 $presidency_data[$i]['name'] = $this->db->f('name');
3660 $presidency_data[$i]['elder'] = $this->db->f('elder');
3664 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
3665 $this->db->query($sql,__LINE__,__FILE__);
3667 while ($this->db->next_record())
3669 $elder_id[$i] = $this->db->f('elder');
3670 $elder_name[$i] = $this->db->f('name');
3671 $elder_phone[$elder_id[$i]] = $this->db->f('phone');
3674 array_multisort($elder_name, $elder_id);
3676 $sql = "SELECT * FROM eq_family where valid=1 and elder_id != 0 ORDER BY name ASC";
3677 $this->db->query($sql,__LINE__,__FILE__);
3679 while ($this->db->next_record())
3681 $family_id[$i] = $this->db->f('family');
3682 $family_name[$i] = $this->db->f('name');
3685 array_multisort($family_name, $family_id);
3687 for ($i=0; $i < count($presidency_data); $i++) {
3688 $presidency = $presidency_data[$i]['id'];
3689 $interviewer = $presidency_data[$i]['elder'];
3690 $name = $presidency_data[$i]['name'];
3691 $this->t->set_var('presidency_name',$name);
3694 // query the database for all the appointments
3695 $sql = "SELECT * FROM eq_appointment where presidency=$presidency and date>=CURDATE() ORDER BY date ASC, time ASC";
3696 $this->db->query($sql,__LINE__,__FILE__);
3698 // Prefill any existing appointment slots
3699 while ($this->db->next_record())
3701 $appointment = $this->db->f('appointment');
3702 $elder = $this->db->f('elder');
3703 $family = $this->db->f('family');
3705 $date = $this->db->f('date');
3706 $date_array = explode("-",$date);
3707 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
3708 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
3710 $time = $this->db->f('time');
3711 $time_array = explode(":",$time);
3712 $hour = $time_array[0];
3713 $minute = $time_array[1];
3715 if($hour > 12) { $pm=1; $hour = $hour - 12; }
3716 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
3718 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3721 $table_data.= '<td align=left>';
3722 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]',$date,'','','','','',$this->cal_options);
3723 $table_data.= '</td>';
3725 // Hour & Minutes selection
3726 $table_data.= "<td align=center>";
3727 $table_data .= $this->get_time_selection_form($hour, $minute, $pm, $presidency, $appointment);
3728 $table_data.= "</td>";
3730 // Elder drop down list (for PPIs)
3731 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][elder]>';
3732 $table_data.= '<option value=0></option>';
3733 for ($j=0; $j < count($elder_id); $j++) {
3734 $id = $elder_id[$j];
3735 $name = $elder_name[$j];
3736 if($elder_id[$j] == $elder) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
3737 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
3739 $table_data.='</select></td>';
3741 // Family drop down list (for Visits)
3742 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family]>';
3743 $table_data.= '<option value=0></option>';
3744 for ($j=0; $j < count($elder_id); $j++) {
3745 $id = $family_id[$j];
3746 $name = $family_name[$j];
3747 if($family_id[$j] == $family) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
3748 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
3750 $table_data.='</select></td>';
3752 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3753 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3755 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3756 $this->t->set_var('tr_color',$tr_color);
3760 // Create blank appointment slot
3761 for ($b=0; $b < 4; $b++) {
3762 $appointment = $this->max_appointments + $b;
3763 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
3766 $table_data.= '<td align=left>';
3767 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]','','','','','','',$this->cal_options);
3768 $table_data.= '</td>';
3771 $table_data.= "<td align=center>";
3772 $table_data .= $this->get_time_selection_form(0, 0, 0, $presidency, $appointment);
3773 $table_data.= "</td>";
3775 // Elder drop down list
3776 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][elder]>';
3777 $table_data.= '<option value=0></option>';
3778 for ($j=0; $j < count($elder_id); $j++) {
3779 $id = $elder_id[$j];
3780 $name = $elder_name[$j];
3781 $table_data.= '<option value='.$id.'>'.$name.'</option>';
3783 $table_data.='</select></td>';
3785 // Family drop down list
3786 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family]>';
3787 $table_data.= '<option value=0></option>';
3788 for ($j=0; $j < count($elder_id); $j++) {
3789 $id = $family_id[$j];
3790 $name = $family_name[$j];
3791 $table_data.= '<option value='.$id.'>'.$name.' Family</option>';
3793 $table_data.='</select></td>';
3795 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
3796 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
3798 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3799 $this->t->set_var('tr_color',$tr_color);
3802 $this->t->set_var('table_data',$table_data);
3803 $this->t->set_var('header_row',$header_row);
3804 $this->t->set_var('table_width',$table_width);
3805 $this->t->fp('list','presidency_list',True);
3809 $this->t->pfp('out','sched_t');
3810 $this->save_sessiondata();
3815 $this->t->set_file(array('admin_t' => 'admin.tpl'));
3816 $this->t->set_block('admin_t','upload','uploadhandle');
3817 $this->t->set_block('admin_t','admin','adminhandle');
3818 $this->t->set_block('admin_t','cmd','cmdhandle');
3819 $this->t->set_block('admin_t','presidency','presidencyhandle');
3821 $this->t->set_var('upload_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.admin&action=upload'));
3822 $this->t->set_var('presidency_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.admin&action=presidency'));
3824 $action = get_var('action',array('GET','POST'));
3826 $this->t->pfp('out','admin_t');
3828 $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
3829 $this->db->query($sql,__LINE__,__FILE__);
3831 while ($this->db->next_record())
3833 $elder_id[$i] = $this->db->f('elder');
3834 $elder_name[$i] = $this->db->f('name');
3835 $elder2name[$elder_id[$i]] = $elder_name[$i];
3838 array_multisort($elder_name, $elder_id);
3840 if($action == 'upload')
3842 $target_path = $this->upload_target_path . '/' . basename( $_FILES['uploadedfile']['name']);
3844 if(($_FILES['uploadedfile']['type'] == "application/zip") ||
3845 ($_FILES['uploadedfile']['type'] == "application/x-zip-compressed") ||
3846 ($_FILES['uploadedfile']['type'] == "application/x-zip") ||
3847 ($_FILES['uploadedfile']['type'] == "application/octet-stream")) {
3849 if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
3850 $uploadstatus = "<b><font color=red> -E- Unable to move the uploaded file to ";
3851 $uploadstatus.= "the target path (check the path and permissions) of: $target_path</font></b>";
3852 $this->t->set_var('uploadstatus',$uploadstatus);
3853 $this->t->pfp('uploadhandle','upload',True);
3857 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
3858 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
3859 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
3860 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
3861 $this->t->set_var('uploadstatus',$uploadstatus);
3862 $this->t->pfp('uploadhandle','upload');
3863 $this->t->set_var('uploadhandle','');
3864 print "<table border=1 width=80%><tr><td>\n<pre>";
3866 # make a directory for this data to be stored in
3867 $date="data_" . date("Y_m_d");
3868 $data_dir = $this->upload_target_path . '/' . $date;
3869 print "-> Making the data directory: $date<br>\n";
3870 exec('mkdir -p ' . $data_dir . ' 2>&1', $result, $return_code);
3871 if($return_code != 0) {
3872 print implode('\n',$result) . "<br>";
3873 print "<b><font color=red>";
3874 print "-E- Unable to create the data directory. Aborting import.";
3875 print "</font></b>";
3879 # move the file uploaded into this directory
3880 print "-> Moving the uploaded file into the data dir<br>\n";
3881 exec('mv ' . $target_path . ' ' . $data_dir . '/' . ' 2>&1', $result, $return_code);
3882 if($return_code != 0) {
3883 print implode('\n',$result) . "<br>";
3884 print "<b><font color=red>";
3885 print "-E- Unable to move the uploaded file into the data dir. Aborting import.";
3886 print "</font></b>";
3890 # unzip the data into this directory
3891 print "-> Unzipping the data<br>\n";
3892 $data_file = $data_dir . '';
3893 exec('unzip ' . $data_dir . '/*.zip -d ' . $data_dir . ' 2>&1', $result, $return_code);
3894 if($return_code != 0) {
3895 print implode('\n',$result) . "<br>";
3896 print "<b><font color=red>";
3897 print "-E- Unable to unzip the uploaded file into the data dir. Aborting import.";
3898 print "</font></b>";
3901 exec('mv ' . $data_dir . '/*/* '. $data_dir . ' 2>&1', $result, $return_code);
3903 # update the data_latest link to point to this new directory
3904 print "-> Updating the latest data dir link<br>\n";
3905 $data_latest = $this->upload_target_path . '/data_latest';
3906 exec('rm ' . $data_latest. '; ln -s ' . $data_dir .' '. $data_latest .' 2>&1', $result, $return_code);
3907 if($return_code != 0) {
3908 print implode('\n',$result) . "<br>";
3909 print "<b><font color=red>";
3910 print "-E- Unable to update the data latest link. Aborting import.";
3911 print "</font></b>";
3915 # run the import perl script to encorporate it into the DB
3916 ob_start('ob_logstdout', 2);
3917 print "-> Importing the data into the EQ database<br>\n";
3918 ob_flush(); flush(); sleep(1);
3919 $import_log = $this->upload_target_path . '/import.log';
3920 $data_log = $this->upload_target_path . '/data.log';
3921 $import_cmd = $this->script_path . '/import_ward_data ' . $data_latest . ' 2>&1 | tee ' . $import_log;
3922 $parse_cmd = $this->script_path . '/parse_ward_data -v ' . $data_latest . ' > ' . $data_log . '2>&1';
3923 #print "import_cmd: $import_cmd<br>";
3924 #print "parse_cmd: $parse_cmd<br>";
3925 ob_start('ob_logstdout', 2);
3926 passthru($import_cmd);
3927 passthru($parse_cmd);
3928 ob_flush(); flush(); sleep(1);
3930 # fix the permissions of the data dir
3931 exec('chmod -R o-rwx ' . $data_dir, $result, $return_code);
3933 $this->t->pfp('cmdhandle','cmd');
3934 print "</pre></td></tr></table>";
3936 } else if(($_FILES['uploadedfile']['type'] != "application/zip") &&
3937 ($_FILES['uploadedfile']['type'] != "application/x-zip-compressed") &&
3938 ($_FILES['uploadedfile']['type'] != "application/x-zip") &&
3939 ($_FILES['uploadedfile']['type'] != "application/octet-stream")) {
3940 $uploadstatus = "<b><font color=red>The file format must be a .zip file, please try again! </font></b>";
3941 $uploadstatus.= "<br><br><b>Detected file format: " . $_FILES['uploadedfile']['type'] . "</b>";
3942 $this->t->set_var('uploadstatus',$uploadstatus);
3943 $this->t->pfp('uploadhandle','upload',True);
3945 $uploadstatus = "<b><font color=red> There was an error (" . $_FILES['uploadedfile']['error'];
3946 $uploadstatus.= ") uploading the file, please try again! </font></b>";
3947 $this->t->set_var('uploadstatus',$uploadstatus);
3948 $this->t->pfp('uploadhandle','upload',True);
3951 else if($action == "presidency")
3953 $new_data = get_var('eqpres',array('POST'));
3954 foreach ($new_data as $entry)
3957 $email = $entry['email'];
3958 $elder = $entry['elder'];
3959 $name = $entry['name'];
3960 $district = $entry['district'];
3961 $president = $entry['president'];
3962 $counselor = $entry['counselor'];
3963 $secretary = $entry['secretary'];
3964 $eqpresidency = $entry['eqpresidency'];
3965 // Set the elder id to 0 for EQ Presidency tagged entry
3966 if($eqpresidency == 1) { $elder="0"; }
3967 // Re-look up the elder name for the ID if we aren't an EQ Presidency tagged entry
3968 else { $name = $elder2name[$elder]; }
3969 //print "id=$id elder=$elder name=$name email=$email district=$district president=$president ";
3970 //print "counselor=$counselor secretary=$secretary eqpres=$eqpresidency<br>";
3972 if(($elder > 0) || ($name != "")) {
3973 if($id < $this->max_presidency_members) {
3974 //print "Updating Existing Entry<br>";
3975 $this->db2->query("UPDATE eq_presidency set" .
3976 " elder=" . $elder .
3977 " ,district=" . $district .
3978 " ,name='" . $name . "'" .
3979 " ,email='" . $email . "'" .
3980 " ,president='" . $president . "'" .
3981 " ,counselor='" . $counselor . "'" .
3982 " ,secretary='" . $secretary . "'" .
3983 " ,eqpres='" . $eqpresidency . "'" .
3984 " WHERE presidency=" . $id,__LINE__,__FILE__);
3987 //print "Adding New Entry<br>";
3988 $this->db2->query("INSERT INTO eq_presidency (presidency,elder,district,name,"
3989 . "email,president,counselor,secretary,eqpres,valid) "
3990 . "VALUES (NULL,'" . $elder . "','" . $district . "','"
3991 . $name . "','" . $email . "','" . $president . "','"
3992 . $counselor . "','" . $secretary . "','" . $eqpres . "','1'"
3993 .")",__LINE__,__FILE__);
3996 //print "Ignoring Blank Entry<br>";
4000 // Now update the eq_district table appropriately
4002 // Delete all the previous district entries from the table
4003 $this->db->query("DELETE from eq_district where valid=1",__LINE__,__FILE__);
4004 $this->db->query("DELETE from eq_district where valid=0",__LINE__,__FILE__);
4006 // Always add a "District 0" assigned to the High Priests Group
4008 $name = "High Priests";
4011 $this->db2->query("INSERT INTO eq_district (district,name,supervisor,valid) "
4012 . "VALUES ('" . $district . "','" . $name . "','"
4013 . $elder . "','" . $valid . "'"
4014 .")",__LINE__,__FILE__);
4017 // Requery the eq_presidency table
4018 $sql = "SELECT * FROM eq_presidency where valid=1";
4019 $this->db->query($sql,__LINE__,__FILE__);
4020 while ($this->db->next_record())
4022 // Extract the data for each presidency record
4023 $id = $this->db->f('presidency');
4024 $elder = $this->db->f('elder');
4025 $name = $this->db->f('name');
4026 $district = $this->db->f('district');
4027 $name = $this->db->f('name');
4030 // If we have a valid district, add it to the district table
4032 $this->db2->query("INSERT INTO eq_district (district,name,supervisor,valid) "
4033 . "VALUES ('" . $district . "','" . $name . "','"
4034 . $elder . "','" . $valid . "'"
4035 .")",__LINE__,__FILE__);
4040 $this->t->set_var('adminhandle','');
4041 $this->t->pfp('adminhandle','admin');
4045 $this->t->set_var('adminhandle','');
4046 $this->t->pfp('adminhandle','admin');
4049 // Now save off the data needed for an EQ Presidency Table Update
4051 $sql = "SELECT * FROM eq_presidency where valid=1";
4052 $this->db->query($sql,__LINE__,__FILE__);
4054 $header_row = "<th>Elder</th><th>Email</th><th>District</th><th>President</th><th>Counselor</th><th>Secretary</th><th>EQ Presidency</th>";
4055 while ($this->db->next_record())
4057 // Extract the data for each presidency record
4058 $id = $this->db->f('presidency');
4059 $elder = $this->db->f('elder');
4060 $district = $this->db->f('district');
4061 $name = $this->db->f('name');
4062 $email = $this->db->f('email');
4063 $president = $this->db->f('president');
4064 $counselor = $this->db->f('counselor');
4065 $secretary = $this->db->f('secretary');
4066 $eqpresidency = $this->db->f('eqpres');
4068 // Create the forms needed in the table
4069 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4072 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4075 if($eqpresidency == 0) {
4076 $table_data.= '<td align=center><select name="eqpres['.$id.'][elder]">';
4077 $table_data.= '<option value=0></option>';
4078 for ($j=0; $j < count($elder_id); $j++) {
4079 $tmp_id = $elder_id[$j];
4080 $name = $elder_name[$j];
4081 if($elder_id[$j] == $elder) { $eldername = $name; $selected = 'selected="selected"'; } else { $selected = ''; }
4082 $table_data.= '<option value='.$tmp_id.' '.$selected.'>'.$name.'</option>';
4084 $table_data.='</select></td>';
4085 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="'.$eldername.'">';
4087 $table_data.= '<td align=left><input type=text size="20" name="eqpresname" value="EQ Presidency"></td>';
4088 $table_data.= '<input type=hidden name="eqpres['.$id.'][name]" value="EQ Presidency">';
4092 $table_data .= '<td><input type="text" size="50" name="eqpres['.$id.'][email]" value="'.$email.'"></td>';
4095 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4096 $table_data.= '<option value=0></option>';
4097 for ($j=0; $j <= $this->max_num_districts; $j++) {
4098 if($district == $j) { $selected = 'selected="selected"'; } else { $selected = ''; }
4099 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4101 $table_data.='</select></td>';
4104 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4105 if($president == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4106 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4107 $table_data.='</select></td>';
4110 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4111 if($counselor == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4112 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4113 $table_data.='</select></td>';
4116 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4117 if($secretary == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4118 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4119 $table_data.='</select></td>';
4122 $table_data.= '<td align=center><select name="eqpres['.$id.'][eqpresidency]">';
4123 if($eqpresidency == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4124 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4125 $table_data.='</select></td>';
4128 $table_data .= "</tr>\n";
4129 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4130 $this->t->set_var('tr_color',$tr_color);
4133 // Now create 1 blank row to always have a line available to add a new elder with
4134 $id = $this->max_presidency_members;
4135 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4137 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4139 $table_data.= '<td align=center><select name="eqpres['.$id.'][elder]">';
4140 $table_data.= '<option value=0></option>';
4141 for ($j=0; $j < count($elder_id); $j++) {
4142 $tmp_id = $elder_id[$j];
4143 $name = $elder_name[$j];
4144 $table_data.= '<option value='.$tmp_id.'>'.$name.'</option>';
4146 $table_data.='</select></td>';
4147 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="">';
4149 $table_data.='<td><input type="text" size="50" name="eqpres['.$id.'][email]" value=""></td>';
4151 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4152 $table_data.= '<option value=0></option>';
4153 for ($j=0; $j <= $this->max_num_districts; $j++) {
4154 if($j == 0) { $selected = 'selected="selected"'; } else { $selected = ''; }
4155 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4157 $table_data.='</select></td>';
4159 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4160 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4161 $table_data.='</select></td>';
4163 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4164 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4165 $table_data.='</select></td>';
4167 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4168 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4169 $table_data.='</select></td>';
4171 $table_data.= '<td align=center><select name="eqpres['.$id.'][eqpresidency]">';
4172 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4173 $table_data.='</select></td>';
4175 $table_data .= "</tr>\n";
4176 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4177 $this->t->set_var('tr_color',$tr_color);
4179 $this->t->set_var('header_row',$header_row);
4180 $this->t->set_var('table_data',$table_data);
4181 $this->t->pfp('presidencyhandle','presidency',True);
4183 $this->save_sessiondata();
4186 function email_appt($appointment)
4188 //print "Emailing notification of appointment: $appointment <br>";
4190 $sql = "SELECT * FROM eq_appointment where appointment='$appointment'";
4191 $this->db->query($sql,__LINE__,__FILE__);
4193 while ($this->db->next_record())
4195 $appointment = $this->db->f('appointment');
4196 $presidency = $this->db->f('presidency');
4199 $elder = $this->db->f('elder');
4201 $family = $this->db->f('family');
4206 $uid = $this->db->f('uid');
4208 // Extract the year, month, day, hours, minutes, seconds from the appointment time
4209 $appt_date = $this->db->f('date');
4210 $date_array = explode("-",$appt_date);
4211 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
4212 $appt_time = $this->db->f('time');
4213 $time_array = explode(":",$appt_time);
4214 $hour = $time_array[0]; $minute = $time_array[1]; $seconds = $time_array[2];
4216 // Format the appointment time into an iCal UTC equivalent
4217 $dtstamp = gmdate("Ymd"."\T"."His"."\Z");
4218 $dtstart = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds,$month,$day,$year));
4219 $dtstartstr = date("l, F d, o g:i A", mktime($hour,$minute,$seconds,$month,$day,$year));
4221 // Set the email address of the person making the appointment
4222 $from = $GLOBALS['phpgw_info']['user']['fullname'] . "<" .
4223 $GLOBALS['phpgw_info']['user']['preferences']['email']['address'] . ">";
4225 $sql = "SELECT * FROM eq_presidency where presidency='$presidency'";
4226 $this->db2->query($sql,__LINE__,__FILE__);
4227 if($this->db2->next_record()) {
4228 $email = $this->db2->f('email');
4229 $interviewer = $this->db2->f('name');
4233 $sql = "SELECT * FROM eq_elder where elder='$elder'";
4234 $this->db2->query($sql,__LINE__,__FILE__);
4235 if($this->db2->next_record()) {
4236 $elder_name = $this->db2->f('name');
4237 $phone = $this->db2->f('phone');
4238 $appt_name = $elder_name . " Interview";
4239 $location = "$interviewer"."'s home";
4240 $duration = $this->default_ppi_appt_duration * 60;
4245 $sql = "SELECT * FROM eq_family where family='$family'";
4246 $this->db2->query($sql,__LINE__,__FILE__);
4247 if($this->db2->next_record()) {
4248 $family_name = $this->db2->f('name');
4249 $phone = $this->db2->f('phone');
4250 $elder_id = $this->db2->f('elder_id');
4251 $appt_name = $family_name . " Family Visit";
4252 $sql = "SELECT * FROM eq_elder where elder='$elder_id'";
4253 $this->db3->query($sql,__LINE__,__FILE__);
4254 if($this->db3->next_record()) {
4255 $phone = $this->db3->f('phone');
4257 $sql = "SELECT * FROM eq_parent where family='$family'";
4258 $this->db3->query($sql,__LINE__,__FILE__);
4259 if($this->db3->next_record()) {
4260 $location=$this->db3->f('address');
4262 $duration = $this->default_visit_appt_duration * 60;
4266 $dtend = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4267 $dtendstr = date("g:i A", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4268 $date = $dtstartstr . "-" . $dtendstr;
4269 $description = "$appt_name : $phone";
4271 if(($uid == 0) && ($appt_name != "")) {
4272 // Create a new calendar item for this appointment, since this must be the first time we
4273 // are sending it out.
4274 print "Sent new appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4275 $uid = rand() . rand(); // Generate a random identifier for this appointment
4276 $subject = "Created: $appt_name";
4278 $this->db->query("UPDATE eq_appointment set" .
4280 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4282 $action = "PUBLISH";
4283 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4284 $dtend, $date, $location, $appt_name, $description, $uid);
4286 } else if(($uid != 0) && ($appt_name == "")) {
4287 // Remove the calendar item for this appointment since it has already been sent
4288 // and there is no name we have changed it to.
4289 print "Sent deleted appointment to " . $interviewer . " at " . $email . " for " . $appt_date . " " . $appt_time . "<br>";
4290 $subject = "Canceled: $appt_date $appt_time";
4292 $this->db->query("UPDATE eq_appointment set" .
4294 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4297 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4298 $dtend, $date, $location, $subject, $subject, $uid);
4300 } else if($uid != 0) {
4301 // Update the existing appointment since we have changed it
4302 print "Sent updated appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4304 $subject = "Canceled: $appt_date $appt_time";
4306 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4307 $dtend, $date, $location, $subject, $subject, $uid);
4309 $uid = rand() . rand(); // Generate a random identifier for this appointment
4310 $this->db->query("UPDATE eq_appointment set" .
4312 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4314 $subject = "Updated: $appt_name";
4315 $action = "PUBLISH";
4316 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4317 $dtend, $date, $location, $appt_name, $description, $uid);
4325 function send_ical_appt($action, $to, $from, $subject, $dtstamp, $dtstart, $dtend, $date, $location, $summary, $description, $uid)
4327 // Initialize our local variables
4328 $boundary = "=MIME_APPOINTMENT_BOUNDARY";
4332 // Form the headers for the email message
4333 $headers.="X-Mailer: PHP/" . phpversion() . "\n";
4334 $headers.="Mime-Version: 1.0\n";
4335 $headers.="Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
4336 $headers.="Content-Disposition: inline\n";
4337 $headers.="Reply-To: $from\n";
4338 $headers.="From: $from\n";
4340 // Print the plaintext version of the appointment
4341 $message.="--$boundary\n";
4342 $message.="Content-Type: text/plain; charset=us-ascii\n";
4343 $message.="Content-Disposition: inline\n";
4345 $message.="What: $description\n";
4346 $message.="When: $date\n";
4347 $message.="Where: $location\n";
4350 // Print the .ics attachment version of the appointment
4351 $message.="--$boundary\n";
4352 $message.="Content-Type: text/calendar; charset=us-ascii\n";
4353 $message.="Content-Disposition: attachment; filename=\"appointment.ics\"\n";
4355 $message.="BEGIN:VCALENDAR" . "\n";
4356 $message.="VERSION:2.0" . "\n";
4357 $message.="PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN" . "\n";
4358 $message.="METHOD:$action" . "\n";
4359 $message.="BEGIN:VEVENT" . "\n";
4360 $message.="ORGANIZER:MAILTO:$from". "\n";
4361 $message.="DTSTAMP:$dtstamp" . "\n";
4362 $message.="DTSTART:$dtstart" . "\n";
4363 $message.="DTEND:$dtend" . "\n";
4364 $message.="SUMMARY:$summary" . "\n";
4365 $message.="DESCRIPTION:$description" . "\n";
4366 $message.="LOCATION:$location" . "\n";
4367 $message.="UID:$uid" ."\n";
4368 $message.="TRANSP:OPAQUE" . "\n";
4369 $message.="SEQUENCE:0" . "\n";
4370 $message.="CLASS:PUBLIC" . "\n";
4371 $message.="END:VEVENT" . "\n";
4372 $message.="END:VCALENDAR" . "\n";
4374 // Complete the message
4375 $message.="--$boundary\n";
4378 mail($to, $subject, $message, $headers);
4382 function get_time_selection_form($hour, $minute, $pm, $presidency, $appointment)
4387 if($hour == 0) { $blank = 1; }
4389 if($this->time_drop_down_lists == 1) {
4390 // Create drop down lists to get the time
4391 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][hour]>';
4392 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4393 foreach(range(1,12) as $num) {
4394 if($hour == $num) { $selected = 'selected="selected"'; } else { $selected = ''; }
4395 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4397 $form_data.= '</select>';
4398 $form_data.= ' : ';
4399 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][minute]>';
4400 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4403 if($num < 10) { $num = "0" . "$num"; }
4404 if($minute == $num) { $selected = 'selected="selected"'; } else { $selected = ''; }
4405 if($blank == 1) { $selected = ""; }
4406 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4407 $num = $num + $this->time_drop_down_list_inc;
4409 $form_data.= '</select>';
4411 // Use free form text fields to get the time
4412 if($blank == 1) { $hour = ""; $minute = ""; $ampm = ""; }
4413 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][hour] value='.$hour.'>';
4415 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][minute] value='.$minute.'>';
4416 $form_data.= ' ';
4418 // Always use a drop-down select form for am/pm
4419 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][pm]>';
4421 if($pm == 0) { $form_data.= '<option value=0 selected>am</option>'; $form_data.= '<option value=1>pm</option>'; }
4422 if($pm == 1) { $form_data.= '<option value=0>am</option>'; $form_data.= '<option value=1 selected>pm</option>'; }
4424 $form_data.= '<option value=""></option>';
4425 $form_data.= '<option value=0>am</option>';
4426 $form_data.= '<option value=1>pm</option>';
4428 $form_data.= '</select>';