2 /**************************************************************************\
3 * Application: phpGroupWare - 3rd Counselor *
4 * Framework: http://www.phpgroupware.org *
5 * Author: Alan J. Pippin (apippin@pippins.net) *
6 * ----------------------------------------------- *
7 * This program is free software; you can redistribute it and/or modify it *
8 * under the terms of the GNU General Public License as published by the *
9 * Free Software Foundation; either version 2 of the License, or (at your *
10 * option) any later version. *
11 \**************************************************************************/
12 /* $Id: class.tc.inc.php,v 1.1.1.1 2005/07/20 07:40:32 ajp Exp $ */
24 var $default_ht_num_months;
25 var $default_ppi_num_months;
26 var $default_ppi_num_years;
27 var $default_int_num_quarters;
28 var $default_int_num_years;
29 var $default_vis_num_years;
30 var $default_att_num_quarters;
31 var $max_num_districts;
34 var $upload_target_path;
36 var $max_appointments;
37 var $max_leader_members;
38 var $ppi_frequency_label;
40 var $public_functions = array
65 'willing_view' => True,
66 'willing_update' => True,
67 'send_ical_appt' => True,
68 'assign_view' => True,
69 'assign_update' => True,
70 'get_time_selection_form' => True,
76 if(file_exists("setup/tc_config.local")) {
77 include("setup/tc_config.local");
79 include("setup/tc_config");
82 $this->jquery_url = $GLOBALS['phpgw']->link('inc/jquery/jquery.js');
83 $this->jquery_tablesorter_url = $GLOBALS['phpgw']->link('inc/jquery/jquery.tablesorter.js');
85 $this->script_path = "$this->application_path"."/bin";
86 $this->max_leader_members = 99;
87 $this->max_appointments = 32768;
89 $this->db = $GLOBALS['phpgw']->db;
90 $this->db2 = $this->db;
91 $this->db3 = $this->db;
92 $this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
93 $this->t = $GLOBALS['phpgw']->template;
94 $this->account = $GLOBALS['phpgw_info']['user']['account_id'];
95 $this->grants = $GLOBALS['phpgw']->acl->get_grants('tc');
96 $this->grants[$this->account] = PHPGW_ACL_READ + PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE;
98 $GLOBALS['phpgw_info']['flags']['css'] .= "-->\n</style>\n"
99 . '<link rel="stylesheet" type="text/css" media="all" href="'
100 . $GLOBALS['phpgw']->link('inc/jquery/jquery.tablesorter.css').'"/>'
101 . "\n<style type=\"text/css\">\n<!--\n";
103 $this->jscal = CreateObject('tc.jscalendar'); // before phpgw_header() !!!
104 $this->cal_options = 'daFormat : "%Y-%m-%d",
105 ifFormat : "%Y-%m-%d",
107 weekNumbers : false';
109 $GLOBALS['phpgw_info']['flags']['app_header'] = 'The 3rd Counselor';
110 $GLOBALS['phpgw']->common->phpgw_header();
112 $this->current_day = `date '+%d'`;
113 $this->current_day = $this->current_day-0; // Make it numeric
114 $this->current_month = `date '+%m'`;
115 $this->current_month = $this->current_month-0; // Make it numeric
116 $this->current_year = `date '+%Y'`;
117 $this->current_year = $this->current_year-0; // Make it numeric
119 if ($this->ppi_frequency == 12) {
120 $this->ppi_frequency_label = "Annual";
121 } else if ($this->ppi_frequency == 6) {
122 $this->ppi_frequency_label = "Semi-Annual";
123 } else if ($this->ppi_frequency == 3) {
124 $this->ppi_frequency_label = "Quarterly";
125 } else if ($this->ppi_frequency == 1) {
126 $this->ppi_frequency_label = "Monthly";
128 $this->ppi_frequency_label = "Periodic";
132 $this->display_app_header();
135 function logToFile($func, $msg)
138 $fd = fopen($this->upload_target_path . "/tc_trace.log", "a");
139 // append date/time to message
140 $str = "[" . date("Y/m/d h:i:s", mktime()) . "] [" . $func . "] " . $msg;
142 fwrite($fd, $str . "\n");
147 function save_sessiondata()
151 function display_app_header()
153 $this->t->set_file(array('tc_header' => 'header.tpl'));
155 if (isset($phpgw_info['user']['preferences']['tc']['tc_font']))
157 $font = $phpgw_info['user']['preferences']['tc']['tc_font'];
164 $this->t->set_var('bg_color',$phpgw_info['theme']['th_bg']);
165 $this->t->set_var('font',$font);
166 $link_data['menuaction'] = 'tc.tc.ht_view';
167 $this->t->set_var('link_hometeaching',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
168 $this->t->set_var('lang_hometeaching','HomeTeaching');
169 $link_data['menuaction'] = 'tc.tc.act_list';
170 $this->t->set_var('link_activity',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
171 $this->t->set_var('lang_activity','Activities');
172 $link_data['menuaction'] = 'tc.tc.willing_view';
173 $this->t->set_var('link_willing',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
174 $this->t->set_var('lang_willing','Willingness');
175 $link_data['menuaction'] = 'tc.tc.assign_view';
176 $this->t->set_var('link_assignment',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
177 $this->t->set_var('lang_assignment','Assignments');
178 $link_data['menuaction'] = 'tc.tc.par_view';
179 $this->t->set_var('link_participation',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
180 $this->t->set_var('lang_participation','Participation');
181 $link_data['menuaction'] = 'tc.tc.ppi_view';
182 $this->t->set_var('link_ppi',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
183 $this->t->set_var('lang_ppi','PPIs');
184 $link_data['menuaction'] = 'tc.tc.int_view';
185 $this->t->set_var('link_int',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
186 $this->t->set_var('lang_int','Interviews');
187 $link_data['menuaction'] = 'tc.tc.vis_view';
188 $this->t->set_var('link_visit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
189 $this->t->set_var('lang_visit','Visits');
190 $link_data['menuaction'] = 'tc.tc.att_view';
191 $this->t->set_var('link_attendance',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
192 $this->t->set_var('lang_attendance','Attendance');
193 $link_data['menuaction'] = 'tc.tc.dir_view';
194 $this->t->set_var('link_dir',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
195 $this->t->set_var('lang_dir','Directory');
196 $link_data['menuaction'] = 'tc.tc.org_view';
197 $this->t->set_var('link_org',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
198 $this->t->set_var('lang_org','Callings');
199 $link_data['menuaction'] = 'tc.tc.admin';
200 $this->t->set_var('link_admin',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
201 $this->t->set_var('lang_admin','Admin');
202 $link_data['menuaction'] = 'tc.tc.schedule';
203 $this->t->set_var('link_schedule',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
204 $this->t->set_var('lang_schedule','Scheduling');
205 $link_data['menuaction'] = 'tc.tc.email';
206 $this->t->set_var('link_email',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
207 $this->t->set_var('lang_email','Email');
209 $this->t->pparse('out','tc_header');
214 $this->t->set_file(array('ht_view_t' => 'ht_view.tpl'));
215 $this->t->set_block('ht_view_t','district_list','list');
217 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
218 $num_months = get_var('num_months',array('GET','POST'));
219 if($num_months == '') { $num_months = $this->default_ht_num_months; }
220 $this->t->set_var('num_months',$num_months);
221 $this->t->set_var('lang_filter','Filter');
222 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
223 else { $this->t->set_var('lang_num_months','Months of History'); }
225 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
226 $this->t->set_var('title','Hometeaching');
228 $this->t->set_var('ht_sandbox_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_sandbox'));
229 $this->t->set_var('ht_sandbox_link_title','Hometeaching Sandbox');
231 $sql = "SELECT * FROM tc_district AS td JOIN (tc_individual AS ti, tc_leader AS tl) WHERE td.leader=tl.leader AND tl.individual=ti.individual AND td.valid=1 ORDER BY td.district ASC";
232 $this->db->query($sql,__LINE__,__FILE__);
234 while ($this->db->next_record()) {
235 $districts[$i]['district'] = $this->db->f('district');
236 $districts[$i]['name'] = $this->db->f('name');
237 $districts[$i]['leader'] = $this->db->f('leader');
241 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
242 $this->db->query($sql,__LINE__,__FILE__);
244 while ($this->db->next_record()) {
245 $individual[$i] = $this->db->f('individual');
246 $indiv_name[$i] = $this->db->f('name');
247 $indiv_phone[$individual[$i]] = $this->db->f('phone');
250 array_multisort($indiv_name, $individual);
252 // Make an array mapping individuals to indiv_names
253 for($i=0; $i < count($individual); $i++) {
254 $id = $individual[$i];
255 $indivs[$id] = $indiv_name[$i];
258 $this->nextmatchs->template_alternate_row_color(&$this->t);
259 for($m=$num_months; $m >= 0; $m--) { $total_families[$m]=0; }
260 for ($i=0; $i < count($districts); $i++) {
261 $this->t->set_var('district_number',$districts[$i]['district']);
262 $this->t->set_var('district_name',$districts[$i]['name']);
263 $leader = $districts[$i]['leader'];
265 // Select all the unique companionship numbers for this district
266 $sql = "SELECT DISTINCT companionship FROM tc_companionship WHERE type='H' AND valid=1 AND district=". $districts[$i]['district'];
267 $this->db->query($sql,__LINE__,__FILE__);
268 $j=0; $unique_companionships = '';
269 while ($this->db->next_record()) {
270 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
274 $comp_width=450; $visit_width=25; $table_width=$comp_width + $num_months*$visit_width;
275 $table_data=""; $num_companionships = 0;
276 for($m=$num_months; $m >= 0; $m--) {
280 for ($j=0; $j < count($unique_companionships); $j++) {
281 $companion_table_entry = "";
282 // Select all the companions in each companionship
283 $sql = "SELECT * FROM tc_companion where valid=1 and ".
284 "companionship=". $unique_companionships[$j]['companionship'];
285 $this->db->query($sql,__LINE__,__FILE__);
287 while ($this->db->next_record()) {
288 // Get this companions information
289 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
290 $companionship = $this->db->f('companionship');
291 $individual = $this->db->f('individual');
292 $name = $indivs[$individual];
293 $phone = $indiv_phone[$individual];
294 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
296 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
298 // Get the names of the families assigned this home teaching companionship
299 $sql = "SELECT * FROM tc_family AS tf JOIN tc_individual AS ti WHERE tf.individual=ti.individual AND tf.valid=1 AND tf.companionship=".$unique_companionships[$j]['companionship'];
300 $sql = $sql . " ORDER BY name ASC";
301 $this->db->query($sql,__LINE__,__FILE__);
303 while ($this->db->next_record()) {
304 $family_name = $this->db->f('name');
305 $family_id = $this->db->f('family');
306 $this->nextmatchs->template_alternate_row_color(&$this->t);
307 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
308 // Find out how many times Visits were performed by this companionship
309 // in the past $num_months for this Family
310 $header_row="<th width=$comp_width><font size=-2>Families</th>";
311 for($m=$num_months; $m >= 0; $m--) {
312 $month = $this->current_month - $m;
313 $year = $this->current_year;
314 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
315 if($month < 10) { $month = "0"."$month"; }
316 $month_start = "$year"."-"."$month"."-"."01";
317 $month_end = "$year"."-"."$month"."-"."31";
318 $month = "$month"."/"."$year";
320 //print "m: $m month: $month year: $year month_start: $month_start month_end: $month_end<br>";
321 // Add this to the query to filter on only visits made by this companionship:
322 // " AND companionship=" . $unique_companionships[$j]['companionship'].
324 // First check to see if the currently assigned companionship has visited them
325 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
326 " AND companionship=".$unique_companionships[$j]['companionship'].
327 " AND family=". $family_id;
328 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
329 if($this->db2->num_rows($query_id) == 0) {
330 // We did not find any visits made by the currently assigned companionship,
331 // look for visits made by any other companionship other than 0. (0 == Presidency Visit)
332 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
333 " AND companionship!=0".
334 " AND family=". $family_id;
335 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
337 $this->db2->query($sql,__LINE__,__FILE__);
338 $link_data['menuaction'] = 'tc.tc.ht_update';
339 $link_data['date'] = $month_start;
340 $link_data['month_start'] = $month_start;
341 $link_data['month_end'] = $month_end;
342 $link_data['month'] = $month;
343 $link_data['district'] = $districts[$i]['district'];
344 $link_data['district_name'] = $districts[$i]['name'];
345 $link_data['action'] = 'view';
346 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
347 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
348 if(!$total_visits[$m]) { $total_visits[$m] = 0; }
349 if($this->db2->next_record()) {
350 if($this->db2->f('visited') == 'y') {
351 $visits[$m]++; $total_visits[$m]++;
352 $num_families[$m]++; $total_families[$m]++;
353 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/checkmark.gif"></a></td>';
354 } else if($this->db2->f('visited') == 'n') {
355 $num_families[$m]++; $total_families[$m]++;
356 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/x.gif"></a></td>';
358 //$visits[$m]++; $total_visits[$m]++;
359 $table_data .= "<td> </td>";
362 //$visits[$m]++; $total_visits[$m]++;
363 $table_data .= "<td> </td>";
366 $table_data .= "</tr>";
369 $table_data .= "<tr><td colspan=20></td></tr>";
371 $table_data .= "<tr><td colspan=20><hr></td></tr>";
372 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
374 for($m=$num_months; $m >=0; $m--) {
375 if($num_families[$m] > 0) {
376 $percent = ceil(($visits[$m] / $num_families[$m])*100);
380 $stat_data .= "<td align=center><font size=-2><b>$visits[$m] / $num_families[$m]<br>$percent%</font></b></td>";
382 $stat_data .= "</tr>";
384 $this->t->set_var('table_width',$table_width);
385 $this->t->set_var('header_row',$header_row);
386 $this->t->set_var('table_data',$table_data);
387 $this->t->set_var('stat_data',$stat_data);
388 $this->t->fp('list','district_list',True);
391 $totals = "<tr><td><b><font size=-2>Total Families Hometaught:<br>Total Hometeaching Percentage:</font></b></td>";
392 for($m=$num_months; $m >=0; $m--) {
393 if($total_families[$m] > 0) {
394 $percent = ceil(($total_visits[$m] / $total_families[$m])*100);
398 $totals .= "<td align=center><font size=-2><b>$total_visits[$m] / $total_families[$m]<br>$percent%</font></b></td>";
402 $this->t->set_var('totals',$totals);
404 $this->t->pfp('out','ht_view_t');
405 $this->save_sessiondata();
409 function ht_sandbox()
411 $this->t->set_file(array('ht_sandbox_t' => 'ht_sandbox.tpl'));
412 $this->t->set_block('ht_sandbox_t','switch_case_list','sc_list');
413 $this->t->set_block('ht_sandbox_t','comp_list','c_list');
414 $this->t->set_block('ht_sandbox_t','district_list','d_list');
415 $this->t->set_block('ht_sandbox_t','unassigned_ht_list','uht_list');
416 $this->t->set_block('ht_sandbox_t','assigned_ht_list','aht_list');
417 $this->t->set_block('ht_sandbox_t','unassigned_family_list','uf_list');
418 $this->t->set_block('ht_sandbox_t','assigned_family_list','af_list');
419 $this->t->set_block('ht_sandbox_t','district_table_list','dt_list');
420 $this->t->set_block('ht_sandbox_t','companionship_table_list','ct_list');
422 $this->t->set_var('submit_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_sandbox&action=add'));
423 $this->t->set_var('jquery_url',$this->jquery_url);
425 $action = get_var('action',array('GET','POST'));
427 $this->t->set_var('title','Hometeaching Sandbox');
430 #$this->t->set_var('debug_list',$_POST['add']);
431 $companionship = get_var('companionship',array('POST'));
432 $district = get_var('district',array('POST'));
433 $assignedHT_list = get_var('assignedHT',array('POST'));
434 $unassignedHT_list = get_var('unassignedHT',array('POST'));
435 $assigned_family_list = get_var('assignedFamiles',array('POST'));
436 $unassigned_family_list = get_var('unassignedFamilies',array('POST'));
438 if ($assignedHT_list || $unassignedHT_list) {
439 $sql = "INSERT INTO tc_companionship_sandbox (tc_companionship,district) VALUES (\"NULL\",\"$district\")";
440 $this->db2->query($sql,__LINE__,__FILE__);
441 $companionship_sandbox = mysql_insert_id();
443 foreach ($assignedHT_list as $individual) {
444 $sql = "INSERT INTO tc_companion_sandbox (individual,companionship) VALUES (\"$individual\",\"$companionship_sandbox\")";
445 $this->db->query($sql,__LINE__,__FILE__);
447 foreach ($unassignedHT_list as $individual) {
448 $sql = "INSERT INTO tc_companion_sandbox (individual,companionship) VALUES (\"$individual\",\"$companionship_sandbox\")";
449 $this->db->query($sql,__LINE__,__FILE__);
451 foreach ($assigned_family_list as $family) {
452 $sql = "UPDATE tc_family_sandbox SET companionship=$companionship_sandbox WHERE family=$family";
453 $this->db->query($sql,__LINE__,__FILE__);
455 foreach ($unassigned_family_list as $family) {
456 $sql = "UPDATE tc_family_sandbox SET companionship=$companionship_sandbox WHERE family=$family";
457 $this->db->query($sql,__LINE__,__FILE__);
460 $this->t->set_var('debug_list','You must select at least one companion!');
462 } else if ($_POST['delete']) {
463 #$this->t->set_var('debug_list',$_POST['delete']);
464 $companionship = get_var('companionship',array('POST'));
465 #$this->t->set_var('debug_list',$companionship);
467 if ($companionship > 0) {
469 $sql = "UPDATE tc_family_sandbox SET companionship=NULL WHERE companionship=$companionship";
470 $this->db->query($sql,__LINE__,__FILE__);
473 $sql = "DELETE FROM tc_companion_sandbox WHERE companionship=$companionship";
474 $this->db->query($sql,__LINE__,__FILE__);
476 # remove companionship
477 $sql = "DELETE FROM tc_companionship_sandbox WHERE companionship=$companionship";
478 $this->db->query($sql,__LINE__,__FILE__);
480 $this->t->set_var('debug_list','You must select a companionship to delete!');
482 } else if ($_POST['update']) {
483 #$this->t->set_var('debug_list',$_POST['update']);
484 $companionship = get_var('companionship',array('POST'));
485 $district = get_var('district',array('POST'));
486 $assignedHT_list = get_var('assignedHT',array('POST'));
487 $unassignedHT_list = get_var('unassignedHT',array('POST'));
488 $assigned_family_list = get_var('assignedFamiles',array('POST'));
489 $unassigned_family_list = get_var('unassignedFamilies',array('POST'));
490 #$this->t->set_var('debug_list',$district);
492 if ($companionship > 0) {
493 if ($assignedHT_list || $unassignedHT_list) {
494 # clear out existing info about companionship
495 $sql = "UPDATE tc_family_sandbox SET companionship=NULL WHERE companionship=$companionship";
496 $this->db->query($sql,__LINE__,__FILE__);
497 $sql = "DELETE FROM tc_companion_sandbox WHERE companionship=$companionship";
498 $this->db->query($sql,__LINE__,__FILE__);
500 # set new info about companionship
501 $sql = "UPDATE tc_companionship_sandbox SET district=$district WHERE companionship=$companionship";
502 $this->db->query($sql,__LINE__,__FILE__);
503 foreach ($assignedHT_list as $individual) {
504 $sql = "INSERT INTO tc_companion_sandbox (individual,companionship) VALUES (\"$individual\",\"$companionship\")";
505 $this->db->query($sql,__LINE__,__FILE__);
507 foreach ($unassignedHT_list as $individual) {
508 $sql = "INSERT INTO tc_companion_sandbox (individual,companionship) VALUES (\"$individual\",\"$companionship\")";
509 $this->db->query($sql,__LINE__,__FILE__);
511 foreach ($assigned_family_list as $family) {
512 $sql = "UPDATE tc_family_sandbox SET companionship=$companionship WHERE family=$family";
513 $this->db->query($sql,__LINE__,__FILE__);
515 foreach ($unassigned_family_list as $family) {
516 $sql = "UPDATE tc_family_sandbox SET companionship=$companionship WHERE family=$family";
517 $this->db->query($sql,__LINE__,__FILE__);
520 $this->t->set_var('debug_list','You must select at least one companion!');
523 $this->t->set_var('debug_list','You must select a companionship to update!');
525 } else if ($_POST['reset']) {
526 #$this->t->set_var('debug_list',$_POST['reset']);
528 $sql = "TRUNCATE TABLE tc_district_sandbox";
529 $this->db->query($sql,__LINE__,__FILE__);
530 $sql = "TRUNCATE TABLE tc_family_sandbox";
531 $this->db->query($sql,__LINE__,__FILE__);
532 $sql = "TRUNCATE TABLE tc_companion_sandbox";
533 $this->db->query($sql,__LINE__,__FILE__);
534 $sql = "TRUNCATE TABLE tc_companionship_sandbox";
535 $this->db->query($sql,__LINE__,__FILE__);
537 # populate tc_district_sandbox
538 $sql = "SELECT * FROM tc_district WHERE valid=1";
539 $this->db->query($sql,__LINE__,__FILE__);
540 while ($this->db->next_record()) {
541 $district = $this->db->f('district');
542 $leader = $this->db->f('leader');
543 $sql = "INSERT INTO tc_district_sandbox (district,leader) VALUES (\"$district\",\"$leader\")";
544 $this->db2->query($sql,__LINE__,__FILE__);
547 # populate family, companion, and companionship tables
548 $sql = "SELECT * FROM tc_companionship WHERE type='H' AND valid=1";
549 $this->db->query($sql,__LINE__,__FILE__);
550 while ($this->db->next_record()) {
551 $companionship = $this->db->f('companionship');
552 $district = $this->db->f('district');
553 $sql = "INSERT INTO tc_companionship_sandbox (tc_companionship,district) VALUES (\"$companionship\",\"$district\")";
554 $this->db2->query($sql,__LINE__,__FILE__);
555 $companionship_sandbox = mysql_insert_id();
557 $sql = "SELECT * FROM tc_companion AS tc JOIN tc_individual AS ti WHERE tc.individual=ti.individual AND tc.companionship=$companionship AND tc.valid=1 AND ti.valid=1";
558 $this->db2->query($sql,__LINE__,__FILE__);
559 while ($this->db2->next_record()) {
560 $individual = $this->db2->f('individual');
561 $sql = "INSERT INTO tc_companion_sandbox (individual,companionship) VALUES (\"$individual\",\"$companionship_sandbox\")";
562 $this->db3->query($sql,__LINE__,__FILE__);
565 $sql = "SELECT * FROM tc_family WHERE companionship=$companionship AND valid=1";
566 $this->db2->query($sql,__LINE__,__FILE__);
567 while ($this->db2->next_record()) {
568 $individual = $this->db2->f('individual');
569 $family = $this->db2->f('family');
570 $sql = "INSERT INTO tc_family_sandbox (tc_family,individual,companionship) VALUES (\"$family\",\"$individual\",\"$companionship_sandbox\")";
571 $this->db3->query($sql,__LINE__,__FILE__);
574 } else if ($_POST['changes']) {
575 $this->ht_sandbox_changes();
578 // get list of companionships
579 $sql = "SELECT DISTINCT companionship FROM tc_companionship_sandbox ORDER BY companionship ASC";
580 $this->db->query($sql,__LINE__,__FILE__);
581 $unique_companionships = '';
582 $unique_companionships[0]['companionship'] = 0;
583 $this->t->set_var('companionship_list','<option value="0">New Companionship</option>');
584 $this->t->fp('c_list','comp_list',True);
586 while ($this->db->next_record()) {
587 $companionship = $this->db->f('companionship');
588 $unique_companionships[$j]['companionship'] = $companionship;
589 $combined_companionship = "";
590 $sql = "SELECT * FROM tc_companion_sandbox AS tc JOIN tc_individual AS ti WHERE tc.individual=ti.individual AND tc.companionship=$companionship ORDER BY ti.name ASC";
591 $this->db2->query($sql,__LINE__,__FILE__);
592 while ($this->db2->next_record()) {
593 if ($combined_companionship == "") {
594 $combined_companionship .= $this->db2->f('name');
596 $combined_companionship .= " / " . $this->db2->f('name');
599 $this->t->set_var('companionship_list','<option value="'.$companionship.'">'.$combined_companionship.'</option>');
600 $this->t->fp('c_list','comp_list',True);
604 # get list of districts
605 $sql = "SELECT DISTINCT district FROM tc_district_sandbox ORDER BY district ASC";
606 $this->db->query($sql,__LINE__,__FILE__);
609 while ($this->db->next_record()) {
610 $districts[$num_districts] = $this->db->f('district');
611 $this->t->set_var('district','<option value="'.$districts[$num_districts].'">'.$districts[$num_districts].'</option>');
612 $this->t->fp('d_list','district_list',True);
616 # get list of individuals who are and are not home teachers
617 $sql = "SELECT * FROM tc_individual WHERE steward='$this->default_stewardship' AND valid=1 ORDER BY name ASC";
618 $this->db->query($sql,__LINE__,__FILE__);
619 while ($this->db->next_record()) {
620 $individual = $this->db->f('individual');
621 $name = $this->db->f('name');
622 $sql = "SELECT DISTINCT * FROM tc_companion_sandbox WHERE individual=$individual";
623 $this->db2->query($sql,__LINE__,__FILE__);
624 if ($this->db2->next_record()) {
625 $this->t->set_var('assigned_ht','<option value="'.$individual.'">'.$name.'</option>');
626 $this->t->fp('aht_list','assigned_ht_list',True);
628 $this->t->set_var('unassigned_ht','<option value="'.$individual.'">'.$name.'</option>');
629 $this->t->fp('uht_list','unassigned_ht_list',True);
633 # get list of families who are and are not assigned home teachers
634 $sql = "SELECT * FROM tc_family_sandbox AS tf JOIN tc_individual AS ti WHERE tf.individual=ti.individual ORDER BY ti.name ASC";
635 $this->db->query($sql,__LINE__,__FILE__);
636 while ($this->db->next_record()) {
637 $individual = $this->db->f('individual');
638 $family = $this->db->f('family');
639 $name = $this->db->f('name');
640 if ($this->db->f('companionship') != 0) {
641 $this->t->set_var('assigned_family','<option value="'.$family.'">'.$name.' Family</option>');
642 $this->t->fp('af_list','assigned_family_list',True);
644 $this->t->set_var('unassigned_family','<option value="'.$family.'">'.$name.' Family</option>');
645 $this->t->fp('uf_list','unassigned_family_list',True);
649 # populate ht districts table
650 $sandbox_table_data = "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">";
652 # set up column headers
653 $sandbox_table_data .= "<tr>";
654 for ($d = 0; $d < $num_districts; $d++) {
655 $sandbox_table_data .= "<th align=\"center\" bgcolor=\"#c9c9c9\">District " . $districts[$d] . "</th>";
658 # get each companionship in each district
659 $sandbox_table_data .= "<tr>";
660 for ($d = 0; $d < $num_districts; $d++) {
661 $sandbox_table_data .= "<td valign=\"Top\">";
662 $sandbox_table_data .= "<table>";
663 $sql = "SELECT DISTINCT companionship FROM tc_companionship_sandbox WHERE district=$districts[$d] ORDER BY companionship ASC";
664 $this->db->query($sql,__LINE__,__FILE__);
665 while ($this->db->next_record()) {
666 $switch_case_list = "";
667 $sandbox_table_data .= "<tr><td><table>";
668 $companionship = $this->db->f('companionship');
670 $switch_case_list .= "case '". $companionship ."':\n";
671 $switch_case_list .= " $(\"#district option:selected\").removeAttr(\"selected\");\n";
672 $switch_case_list .= " $(\"#assignedHT option:selected\").removeAttr(\"selected\");\n";
673 $switch_case_list .= " $(\"#assignedFamilies option:selected\").removeAttr(\"selected\");\n";
674 $switch_case_list .= " $(\"#district option[value='".$districts[$d]."']\").attr(\"selected\",true);\n";
676 # get names of companions in this companionship
677 $sql = "SELECT * FROM tc_companion_sandbox AS tc JOIN tc_individual AS ti WHERE tc.individual=ti.individual AND companionship=$companionship ORDER BY ti.name ASC";
678 $this->db2->query($sql,__LINE__,__FILE__);
679 $companion_names = "";
680 while ($this->db2->next_record()) {
681 if ($companion_names == "") {
682 $companion_names .= $this->db2->f('name');
684 $companion_names .= " / " . $this->db2->f('name');
686 $individual = $this->db2->f('individual');
687 $switch_case_list .= " $(\"#assignedHT option[value='".$individual."']\").attr(\"selected\",true);\n";
689 $this->nextmatchs->template_alternate_row_color(&$this->t);
690 $sandbox_table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
691 $sandbox_table_data .= "<th bgcolor=#d3dce3 align=\"Left\">$companion_names</th></tr>";
692 $sandbox_table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td><table>";
694 # get families they visit
695 $sql = "SELECT * FROM tc_companionship_sandbox AS tcp JOIN (tc_family_sandbox AS tf, tc_individual AS ti) WHERE tcp.companionship=$companionship AND tcp.companionship=tf.companionship AND tf.individual=ti.individual";
696 $this->db2->query($sql,__LINE__,__FILE__);
697 while ($this->db2->next_record()) {
698 $family_name = $this->db2->f('name') . " Family";
699 $family_id = $this->db2->f('tc_family');
700 $family = $this->db2->f('family');
701 $tc_companionship = $this->db2->f('tc_companionship');
702 $this->nextmatchs->template_alternate_row_color(&$this->t);
703 $sandbox_table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
704 $sandbox_table_data .= "<td align=\"Left\" width=\"1000\">$family_name</td>";
705 $switch_case_list .= " $(\"#assignedFamilies option[value='".$family."']\").attr(\"selected\",true);\n";
707 # get 12 months visit data for given family
708 for($m=$this->sandbox_stats_num_months; $m > 0; $m--) {
709 $month = $this->current_month - $m;
710 $year = $this->current_year;
711 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
712 if($month < 10) { $month = "0"."$month"; }
713 $month_start = "$year"."-"."$month"."-"."01";
714 $month_end = "$year"."-"."$month"."-"."31";
715 $month = "$month"."/"."$year";
717 if ($this->sandbox_visits_comp_only == 0) {
718 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' AND companionship!=0 AND family=". $family_id;
720 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' AND companionship=$tc_companionship AND family=". $family_id;
722 $query_id = $this->db3->query($sql,__LINE__,__FILE__);
724 if($this->db3->next_record()) {
725 if($this->db3->f('visited') == 'y') {
726 $sandbox_table_data .= "<td align=\"Right\"><img src=\"images/checkmark.gif\"></td>";
727 } else if($this->db3->f('visited') == 'n') {
728 $sandbox_table_data .= "<td align=\"Right\"><img src=\"images/x.gif\"></td>";
730 $sandbox_table_data .= "<td> </td>";
733 $sandbox_table_data .= "<td> </td>";
736 $sandbox_table_data .= "</tr>";
738 $sandbox_table_data .= "</table></td></tr>";
739 $sandbox_table_data .= "</table></td></tr>";
740 $switch_case_list .= "break;\n";
741 $this->t->set_var('switch_case_list',$switch_case_list);
742 $this->t->fp('sc_list','switch_case_list',True);
744 $sandbox_table_data .= "</table>";
745 $sandbox_table_data .= "</td>";
747 $sandbox_table_data .= "</tr>";
749 $sandbox_table_data .= "</table>";
750 $this->t->set_var('district_table',$sandbox_table_data);
752 $this->t->pfp('out','ht_sandbox_t');
753 $this->save_sessiondata();
756 function ht_sandbox_changes()
758 $email_contents = "Please review the following changes to home teaching.\r\n\r\n";
759 // list all companionships deleted
760 $email_contents .= "Removed Companionships\r\n\r\n";
761 $sql = "SELECT * FROM tc_companionship WHERE companionship NOT IN (SELECT tc_companionship FROM tc_companionship_sandbox) AND type='H' AND valid=1";
762 $this->db->query($sql,__LINE__,__FILE__);
763 while ($this->db->next_record()) {
764 $companionship = $this->db->f('companionship');
765 $sql = "SELECT * FROM tc_companion AS tc JOIN tc_individual AS ti WHERE tc.individual=ti.individual AND tc.companionship=$companionship";
766 $this->db2->query($sql,__LINE__,__FILE__);
767 $companion_names = "";
768 while ($this->db2->next_record()) {
769 if ($companion_names == "") {
770 $companion_names .= $this->db2->f('name');
772 $companion_names .= " / " . $this->db2->f('name');
775 $email_contents .= "\t$companion_names\r\n";
777 $email_contents .= "\r\n";
779 // list all companionships added
780 $email_contents .= "New Companionships\r\n\r\n";
781 $sql = "SELECT * FROM tc_companionship_sandbox WHERE tc_companionship=0";
782 $this->db->query($sql,__LINE__,__FILE__);
783 while ($this->db->next_record()) {
784 $companionship = $this->db->f('companionship');
785 $sql = "SELECT * FROM tc_companion_sandbox AS tcs JOIN tc_individual AS ti WHERE tcs.individual=ti.individual AND tcs.companionship=$companionship";
786 $this->db2->query($sql,__LINE__,__FILE__);
787 $companion_names = "";
788 while ($this->db2->next_record()) {
789 if ($companion_names == "") {
790 $companion_names .= $this->db2->f('name');
792 $companion_names .= " / " . $this->db2->f('name');
795 $email_contents .= "\t$companion_names\r\n";
796 $sql = "SELECT * FROM tc_family_sandbox AS tfs JOIN tc_individual AS ti WHERE tfs.individual=ti.individual AND companionship=$companionship";
797 $this->db2->query($sql,__LINE__,__FILE__);
798 while ($this->db2->next_record()) {
799 $family_name = $this->db2->f('name') . " Family";
800 $email_contents .= "\t\t$family_name\r\n";
803 $email_contents .= "\r\n";
805 // list all companionships with changes
806 $email_contents .= "Modified Companionships\r\n\r\n";
807 $sql = "SELECT tcps.* FROM tc_companionship AS tc JOIN tc_companionship_sandbox AS tcps WHERE tc.companionship=tcps.tc_companionship AND tc.type='H' AND tc.valid=1";
808 $this->db->query($sql,__LINE__,__FILE__);
809 while ($this->db->next_record()) {
810 $companionship = $this->db->f('companionship');
811 $tc_companionship = $this->db->f('tc_companionship');
812 $companionship_changed = 0;
814 // get current companion list
815 $sql = "SELECT * FROM tc_companion_sandbox AS tc JOIN tc_individual AS ti WHERE tc.companionship=$companionship AND tc.individual=ti.individual";
816 $this->db2->query($sql,__LINE__,__FILE__);
817 $companion_names = "";
818 while ($this->db2->next_record()) {
819 if ($companion_names == "") {
820 $companion_names .= $this->db2->f('name');
822 $companion_names .= " / " . $this->db2->f('name');
826 // list removed companions
827 $sql = "SELECT * FROM tc_companion AS tc JOIN tc_individual AS ti WHERE tc.companionship=$tc_companionship AND tc.individual=ti.individual AND tc.individual NOT IN (SELECT individual FROM tc_companion_sandbox WHERE companionship=$companionship)";
828 $this->db2->query($sql,__LINE__,__FILE__);
829 while ($this->db2->next_record()) {
830 if ($companionship_changed == 0) {
831 $companionship_changed = 1;
832 $email_contents .= "\t$companion_names\r\n";
834 $name = $this->db2->f('name');
835 $email_contents .= "\t\tremoved $name as a companion\r\n";
838 // list added companions
839 $sql = "SELECT * FROM tc_companion_sandbox AS tcs JOIN tc_individual AS ti WHERE tcs.companionship=$companionship AND tcs.individual=ti.individual AND tcs.individual NOT IN (SELECT individual FROM tc_companion WHERE companionship=$tc_companionship)";
840 $this->db2->query($sql,__LINE__,__FILE__);
841 while ($this->db2->next_record()) {
842 if ($companionship_changed == 0) {
843 $companionship_changed = 1;
844 $email_contents .= "\t$companion_names\r\n";
846 $name = $this->db2->f('name');
847 $email_contents .= "\t\tadded $name as a companion\r\n";
850 // list removed families
851 $sql = "SELECT * FROM tc_family AS tf JOIN tc_individual AS ti WHERE tf.individual=ti.individual AND tf.companionship=$tc_companionship AND tf.family NOT IN (SELECT tc_family FROM tc_family_sandbox WHERE companionship=$companionship)";
852 $this->db2->query($sql,__LINE__,__FILE__);
853 while ($this->db2->next_record()) {
854 if ($companionship_changed == 0) {
855 $companionship_changed = 1;
856 $email_contents .= "\t$companion_names\r\n";
858 $name = $this->db2->f('name');
859 $email_contents .= "\t\tremoved $name Family\r\n";
862 // list added families
863 $sql = "SELECT * FROM tc_family_sandbox AS tfs JOIN tc_individual AS ti WHERE tfs.individual=ti.individual AND tfs.companionship=$companionship AND tfs.individual NOT IN (SELECT individual FROM tc_family WHERE companionship=$tc_companionship)";
864 $this->db2->query($sql,__LINE__,__FILE__);
865 while ($this->db2->next_record()) {
866 if ($companionship_changed == 0) {
867 $companionship_changed = 1;
868 $email_contents .= "\t$companion_names\r\n";
870 $name = $this->db2->f('name');
871 $email_contents .= "\t\tadded $name Family\r\n";
874 $email_contents .= "\r\n";
876 // email changes to leader
877 $sql = "SELECT DISTINCT tp.email AS email1, ti.email AS email2 FROM tc_leader AS tl JOIN tc_individual AS ti WHERE tl.individual=ti.individual AND (tl.type='P' OR tl.type='C' OR tl.type='S') AND tl.valid=1";
878 $this->db->query($sql,__LINE__,__FILE__);
879 while ($this->db->next_record()) {
881 if ($this->db->f('email1') != "") {
882 $email = $this->db->f('email1');
884 $email = $this->db->f('email2');
892 $sql = "SELECT DISTINCT tp.email AS email1, ti.email AS email2 FROM tc_leader AS tl JOIN tc_individual AS ti WHERE tl.individual=ti.individual AND tl.type='P' AND tl.valid=1";
893 $this->db->query($sql,__LINE__,__FILE__);
894 if ($this->db->next_record()) {
895 if ($this->db->f('email1') != "") {
896 $from = $this->db->f('email1');
898 $from = $this->db->f('email2');
901 $from = "president@3rdcounselor";
903 $subject = "HomeTeaching Changes";
904 $message .= "$email_contents";
905 $headers = "From: $from\r\n" .
906 "Reply-To: $from\r\n" .
907 "X-Mailer: PHP/" . phpversion();
909 mail($to, $subject, $message, $headers);
914 $this->t->set_file(array('ht_update_t' => 'ht_update.tpl'));
915 $this->t->set_block('ht_update_t','district_list','list');
916 $this->t->set_block('ht_update_t','save','savehandle');
918 $district = get_var('district',array('GET','POST'));
919 $district_name = get_var('district_name',array('GET','POST'));
920 $date = get_var('date',array('GET','POST'));
921 $month = get_var('month',array('GET','POST'));
922 $month_start = get_var('month_start',array('GET','POST'));
923 $month_end = get_var('month_end',array('GET','POST'));
924 $action = get_var('action',array('GET','POST'));
926 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
927 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_update&action=save'));
928 $this->t->set_var('lang_done','Cancel');
929 $this->t->set_var('district_name',$district_name);
930 $this->t->set_var('district_number',$district);
931 $this->t->set_var('title','Hometeaching Update ' . $month);
932 $this->t->set_var('date',$date);
934 if($action == 'save') {
935 // Get a list of all the companionships in this district
936 $sql = "SELECT DISTINCT companionship FROM tc_companionship WHERE type='H' AND valid=1 AND district=". $district;
937 $this->db->query($sql,__LINE__,__FILE__);
938 $j=0; $unique_companionships = '';
939 while ($this->db->next_record()) {
940 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
943 for ($j=0; $j < count($unique_companionships); $j++) {
944 //$comp=$unique_companionships[$j]['companionship'];
945 //print "deleting from tc_visit where companionship=$comp and date=$date and district=$district<br>";
946 // Delete all the visits that have taken place for all families for this companionsthip for this month
947 $this->db->query("DELETE from tc_visit where companionship=" . $unique_companionships[$j]['companionship'] .
948 " AND " . "date='" . $date . "'",__LINE__,__FILE__);
951 // Now, add the visits that are checked for this month
952 $new_data = get_var('family_visited',array('POST'));
953 foreach ($new_data as $family) {
954 foreach ($family as $data) {
955 //print "family_visited: $data <br>";
956 $data_array = explode("/",$data);
957 $family_id = $data_array[0];
958 $companionship = $data_array[1];
959 $date = $data_array[2];
960 $visited = $data_array[3];
961 if($visited == "") { $visited = $data_array[4]; }
962 //print "family_id: $family_id companionship: $companionship date: $date visited: $visited<br>";
963 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes,visited) " .
964 "VALUES (" . $family_id .",". $companionship .",'". $date ."','','". $visited ."')",__LINE__,__FILE__);
971 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
972 $this->db->query($sql,__LINE__,__FILE__);
974 while ($this->db->next_record()) {
975 $individual[$i] = $this->db->f('individual');
976 $indiv_name[$i] = $this->db->f('name');
977 $indiv_phone[$individual[$i]] = $this->db->f('phone');
980 array_multisort($indiv_name, $individual);
982 // Make an array mapping individuals to indiv_names
983 for($i=0; $i < count($individual); $i++) {
984 $id = $individual[$i];
985 $indivs[$id] = $indiv_name[$i];
988 // Select all the unique companionship numbers for this district
989 $sql = "SELECT DISTINCT companionship FROM tc_companionship WHERE type='H' AND valid=1 AND district=". $district;
990 $this->db->query($sql,__LINE__,__FILE__);
991 $j=0; $unique_companionships = '';
992 while ($this->db->next_record()) {
993 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
997 $comp_width=300; $visit_width=25; $table_width=$comp_width + $visit_width;
998 $table_data=""; $num_companionships = 0; $num_families = 0; $visits=0;
999 for ($j=0; $j < count($unique_companionships); $j++) {
1000 $companion_table_entry = "";
1001 // Select all the companions in each companionship
1002 $sql = "SELECT * FROM tc_companionship WHERE type='H' AND valid=1 AND companionship=". $unique_companionships[$j]['companionship'];
1003 $this->db->query($sql,__LINE__,__FILE__);
1005 while ($this->db->next_record()) {
1006 // Get this companions information
1007 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
1008 $companionship = $this->db->f('companionship');
1009 $individual = $this->db->f('individual');
1010 $name = $indivs[$individual];
1011 $phone = $indiv_phone[$individual];
1012 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
1014 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
1016 // Get the names of the families assigned this home teaching companionship
1017 $sql = "SELECT * FROM tc_family AS tf JOIN tc_individual AS ti WHERE tf.individual=ti.individual AND tf.valid=1 AND tf.companionship=".$unique_companionships[$j]['companionship'];
1018 $sql = $sql . " ORDER BY ti.name ASC";
1019 $this->db->query($sql,__LINE__,__FILE__);
1020 while ($this->db->next_record()) {
1021 $family_name = $this->db->f('name');
1022 $family_id = $this->db->f('family');
1023 $this->nextmatchs->template_alternate_row_color(&$this->t);
1024 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
1026 $header_row="<th width=$comp_width><font size=-2>Families</th>";
1028 // First check to see if the currently assigned companionship has visited them
1029 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
1030 " AND companionship=".$unique_companionships[$j]['companionship'].
1031 " AND family=". $family_id;
1032 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
1033 if($this->db2->num_rows($query_id) == 0) {
1034 // We did not find any visits made by the currently assigned companionship,
1035 // look for visits made by any other companionship other than 0. (0 == Presidency Visit)
1036 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
1037 " AND companionship!=0".
1038 " AND family=". $family_id;
1039 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
1042 $value = $family_id . "/" . $unique_companionships[$j]['companionship'] . "/" . $date;
1043 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
1044 if(!$total_visits) { $total_visits = 0; }
1045 if($this->db2->next_record()) {
1046 if($this->db2->f('visited') == 'y') {
1047 $visits++; $total_visits++; $num_families++;
1048 $table_data .= '<td width=100 align=center>';
1049 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y" checked>Y';
1050 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
1051 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/"> ';
1052 $table_data .= '</td>';
1053 } else if($this->db2->f('visited') == 'n') {
1055 $table_data .= '<td width=100 align=center>';
1056 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
1057 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n" checked>N';
1058 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/">';
1059 $table_data .= '</td>';
1061 $table_data .= '<td width=100 align=center>';
1062 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
1063 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
1064 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
1065 $table_data .= '</td>';
1070 $table_data .= '<td width=100 align=center>';
1071 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
1072 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
1073 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
1074 $table_data .= '</td>';
1077 $table_data .= "</tr>";
1078 $table_data .= "<tr><td colspan=20></td></tr>";
1080 $table_data .= "<tr><td colspan=20><hr></td></tr>";
1081 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
1083 $percent = ceil(($visits / $num_families)*100);
1084 $stat_data .= "<td align=center><font size=-2><b>$visits / $num_families<br>$percent%</font></b></td>";
1085 $stat_data .= "</tr>";
1087 $this->t->set_var('table_width',$table_width);
1088 $this->t->set_var('header_row',$header_row);
1089 $this->t->set_var('table_data',$table_data);
1090 $this->t->set_var('stat_data',$stat_data);
1091 $this->t->fp('list','district_list',True);
1093 $this->t->set_var('lang_reset','Clear Form');
1094 $this->t->set_var('lang_save','Save Changes');
1095 $this->t->set_var('savehandle','');
1097 $this->t->pfp('out','ht_update_t');
1098 $this->t->pfp('addhandle','save');
1100 $this->save_sessiondata();
1105 $this->t->set_file(array('act_list_t' => 'act_list.tpl'));
1106 $this->t->set_block('act_list_t','act_list','list');
1108 $this->t->set_var('lang_name','Assignment');
1109 $this->t->set_var('lang_date','Date');
1110 $this->t->set_var('lang_notes','Description');
1112 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
1113 $this->db->query($sql,__LINE__,__FILE__);
1114 $total_records = $this->db->num_rows();
1117 while ($this->db->next_record()) {
1118 $activity_list[$i]['activity'] = $this->db->f('activity');
1119 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1120 $activity_list[$i]['date'] = $this->db->f('date');
1121 $activity_list[$i]['notes'] = $this->db->f('notes');
1123 $sql = "SELECT * FROM tc_assignment WHERE assignment='" . $activity_list[$i]['assignment'] . "'";
1124 $this->db2->query($sql,__LINE__,__FILE__);
1125 if($this->db2->next_record()) {
1126 $activity_list[$i]['name'] = $this->db2->f('name');
1127 $activity_list[$i]['abbreviation'] = $this->db2->f('abbreviation');
1132 for ($i=0; $i < count($activity_list); $i++) {
1133 $this->nextmatchs->template_alternate_row_color(&$this->t);
1134 $this->t->set_var('name',$activity_list[$i]['name']);
1135 $this->t->set_var('date',$activity_list[$i]['date']);
1136 $activity_notes = $activity_list[$i]['notes'];
1137 if(strlen($activity_notes) > 40) { $activity_notes = substr($activity_notes,0,40) . "..."; }
1138 $this->t->set_var('notes',$activity_notes);
1140 $link_data['menuaction'] = 'tc.tc.act_view';
1141 $link_data['activity'] = $activity_list[$i]['activity'];
1142 $link_data['action'] = 'view';
1143 $this->t->set_var('view',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
1144 $this->t->set_var('lang_view','View');
1146 $link_data['menuaction'] = 'tc.tc.act_update';
1147 $link_data['activity'] = $activity_list[$i]['activity'];
1148 $link_data['action'] = 'edit';
1149 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
1150 $this->t->set_var('lang_edit','Edit');
1152 $this->t->fp('list','act_list',True);
1155 $link_data['menuaction'] = 'tc.tc.act_update';
1156 $link_data['activity'] = '0';
1157 $link_data['action'] = 'add';
1158 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/tc/index.php',$link_data) .
1159 '"><input type="submit" name="Add" value="' . 'Add Activity' .'"></font></form>');
1161 $this->t->pfp('out','act_list_t');
1162 $this->save_sessiondata();
1167 $this->t->set_file(array('act_view_t' => 'act_view.tpl'));
1168 $this->t->set_block('act_view_t','part_list','list');
1170 $sql = "SELECT * FROM tc_activity WHERE activity=" . intval(get_var('activity',array('GET','POST')));
1171 $this->db->query($sql,__LINE__,__FILE__);
1172 $this->db->next_record();
1173 $this->t->set_var('assignment', $this->db->f('assignment'));
1174 $this->t->set_var('date', $this->db->f('date'));
1175 $this->t->set_var('notes', $this->db->f('notes'));
1177 $sql = "SELECT * FROM tc_assignment WHERE assignment='" . $this->db->f('assignment') . "'";
1178 $this->db2->query($sql,__LINE__,__FILE__);
1179 if($this->db2->next_record()) {
1180 $this->t->set_var('name', $this->db2->f('name'));
1181 $this->t->set_var('abbreviation', $this->db2->f('abbreviation'));
1183 $this->t->set_var('lang_name','Assignment');
1184 $this->t->set_var('lang_date','Date');
1185 $this->t->set_var('lang_notes','Description');
1186 $this->t->set_var('lang_done','Done');
1187 $this->t->set_var('lang_action','View');
1189 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1190 $this->t->set_var('tr_color',$tr_color);
1192 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_list'));
1194 $link_data['menuaction'] = 'tc.tc.act_update';
1195 $link_data['activity'] = get_var('activity',array('GET','POST'));
1196 $link_data['action'] = 'edit';
1197 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
1198 $this->t->set_var('lang_edit','Edit');
1199 $this->t->set_var('cal_date',$this->db->f('date'));
1201 // Now find out which indivs participated in this activity
1202 $sql = "SELECT * FROM tc_participation WHERE activity=" . intval(get_var('activity',array('GET','POST')));
1203 $this->db->query($sql,__LINE__,__FILE__);
1204 $total_records = $this->db->num_rows();
1207 while ($this->db->next_record()) {
1208 $part_list[$i]['individual'] = $this->db->f('individual');
1212 for ($i=0; $i < count($part_list); $i++) {
1213 $sql = "SELECT * FROM tc_individual WHERE individual=" . $part_list[$i]['individual'];
1214 $this->db->query($sql,__LINE__,__FILE__);
1215 $this->db->next_record();
1216 $names[$i] = $this->db->f('name');
1220 for ($i=0; $i < count($names); $i++) {
1221 //$this->nextmatchs->template_alternate_row_color(&$this->t);
1222 $this->t->set_var('individual_name',$names[$i]);
1223 if(($i+1) % 3 == 0) {
1224 $this->t->set_var('table_sep',"</td></tr><tr>");
1226 $this->t->set_var('table_sep',"</td>");
1228 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
1229 $this->t->fp('list','part_list',True);
1232 $this->t->pfp('out','act_view_t');
1233 $this->save_sessiondata();
1236 function act_update()
1238 $this->t->set_file(array('form' => 'act_update.tpl'));
1239 $this->t->set_block('form','individual_list','list');
1240 $this->t->set_block('form','add','addhandle');
1241 $this->t->set_block('form','edit','edithandle');
1242 $this->t->set_var('lang_done','Done');
1244 $action = get_var('action',array('GET','POST'));
1245 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_list'));
1246 $activity['activity'] = intval(get_var('activity',array('GET','POST')));
1248 if($action == 'save') {
1249 $activity['assignment'] = get_var('assignment',array('POST'));
1250 $activity['date'] = get_var('date',array('POST'));
1251 $activity['notes']= get_var('notes',array('POST'));
1252 $this->db->query("UPDATE tc_activity set " .
1253 " assignment='" . $activity['assignment'] .
1254 "', date='" . $activity['date'] . "'" .
1255 ", notes=\"" . $activity['notes'] . "\"" .
1256 " WHERE activity=" . $activity['activity'],__LINE__,__FILE__);
1258 // Delete all the individuals who have particiapted in this activity
1259 $this->db->query("DELETE from tc_participation where activity=".$activity['activity'],__LINE__,__FILE__);
1261 // Re-add the individuals who are checked as having participated in this activity
1262 $indivs = get_var('individual_name',array('POST'));
1263 if(is_array($indivs)) { // Only do the foreach loop if we have a valid array of indivs to work with
1264 foreach ($indivs as $individual) {
1265 $this->db->query("INSERT INTO tc_participation (individual,activity) " .
1266 "VALUES (" . $individual . ",". $activity['activity'] . ")",__LINE__,__FILE__);
1274 if($action == 'insert') {
1275 $activity['assignment'] = get_var('assignment',array('POST'));
1276 $activity['date'] = get_var('date',array('POST'));
1277 $activity['notes']= get_var('notes',array('POST'));
1278 $this->db->query("INSERT INTO tc_activity (assignment,date,notes) " .
1279 "VALUES ('" . $activity['assignment'] . "','" .
1280 $activity['date'] . "',\"" . $activity['notes'] . "\")",__LINE__,__FILE__);
1282 $sql = "SELECT * FROM tc_activity WHERE assignment='".$activity['assignment']."' " .
1283 " AND date='".$activity['date']."' AND notes=\"".$activity['notes']."\"";
1284 $this->db->query($sql,__LINE__,__FILE__);
1285 if($this->db->next_record()) {
1286 //print "activity: " . $this->db->f('activity') . "<br>";
1287 $activity['activity'] = $this->db->f('activity');
1290 $indivs = get_var('individual_name',array('POST'));
1291 foreach ($indivs as $individual)
1293 $this->db->query("INSERT INTO tc_participation (individual,activity) " .
1294 "VALUES (" . $individual . ",". $activity['activity'] . ")",__LINE__,__FILE__);
1301 if($action == 'add') {
1302 $activity['activity'] = 0;
1303 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
1304 $this->t->set_var('assignment','');
1305 $this->t->set_var('date','');
1306 $this->t->set_var('notes','');
1307 $this->t->set_var('lang_done','Cancel');
1308 $this->t->set_var('lang_action','Adding New Activity');
1309 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_update&activity=' .
1310 $activity['activity'] . '&action=' . 'insert'));
1313 if($action == 'edit') {
1314 $sql = "SELECT * FROM tc_activity WHERE activity=" . $activity['activity'];
1315 $this->db->query($sql,__LINE__,__FILE__);
1316 $this->db->next_record();
1317 $this->t->set_var('cal_date',$this->jscal->input('date',$this->db->f('date'),'','','','','',$this->cal_options));
1318 $this->t->set_var('assignment', $this->db->f('assignment'));
1319 $assignment = $this->db->f('assignment');
1320 $this->t->set_var('date', $this->db->f('date'));
1321 $this->t->set_var('notes', $this->db->f('notes'));
1322 $this->t->set_var('lang_done','Cancel');
1323 $this->t->set_var('lang_action','Editing Activity');
1324 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_update&activity=' .
1325 $activity['activity'] . '&action=' . 'save'));
1328 // Create the assignments drop-down list
1329 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1330 $this->db->query($sql,__LINE__,__FILE__);
1332 while ($this->db->next_record()) {
1333 $assignments[$i]['assignment'] = $this->db->f('assignment');
1334 $assignments[$i]['name'] = $this->db->f('name');
1335 $assignments[$i]['abbreviation'] = $this->db->f('abbreviation');
1339 $assignment_data.= '<select name=assignment>';
1340 $assignment_data.= '<option value=0></option>';
1341 for ($j=0; $j < count($assignments); $j++) {
1342 $id = $assignments[$j]['assignment'];
1343 $name = $assignments[$j]['name'];
1344 if($assignments[$j]['assignment'] == $assignment) {
1345 $selected[$id] = 'selected="selected"';
1347 $selected[$id] = '';
1349 $assignment_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1351 $assignment_data.='</select>';
1352 $this->t->set_var('assignment_data',$assignment_data);
1354 // Create individual selection boxes
1355 $sql = "SELECT * FROM tc_individual";
1356 $this->db->query($sql,__LINE__,__FILE__);
1358 while ($this->db->next_record()) {
1359 if($this->db->f('valid') == 1 || $action != 'add') {
1360 $indiv_name[$i] = $this->db->f('name');
1361 $individual[$i] = $this->db->f('individual');
1362 $indiv_valid[$i] = $this->db->f('valid');
1366 array_multisort($indiv_name, $individual, $indiv_valid);
1369 for ($i=0; $i < count($individual); $i++) {
1370 //$this->nextmatchs->template_alternate_row_color(&$this->t);
1371 $sql = "SELECT * FROM tc_participation where activity=". $activity['activity'] . " AND individual=" . $individual[$i];
1372 $this->db->query($sql,__LINE__,__FILE__);
1373 if($this->db->next_record()) {
1374 $this->t->set_var('checked','checked');
1377 $this->t->set_var('checked','');
1380 if($checked || $indiv_valid[$i] == 1) {
1381 $this->t->set_var('individual_name',$indiv_name[$i]);
1382 $this->t->set_var('individual',$individual[$i]);
1383 if(($j+1) % 3 == 0) {
1384 $this->t->set_var('table_sep',"</td></tr><tr>");
1386 $this->t->set_var('table_sep',"</td>");
1388 if(($j) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
1389 $this->t->fp('list','individual_list',True);
1394 $this->t->set_var('lang_reset','Clear Form');
1395 $this->t->set_var('lang_add','Add Activity');
1396 $this->t->set_var('lang_save','Save Changes');
1397 $this->t->set_var('edithandle','');
1398 $this->t->set_var('addhandle','');
1400 $this->t->pfp('out','form');
1401 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
1402 if($action == 'add') { $this->t->pfp('addhandle','add'); }
1404 $this->save_sessiondata();
1407 function assign_view()
1409 $this->t->set_file(array('assign_view_t' => 'assign_view.tpl'));
1410 $this->t->set_block('assign_view_t','assign_view','list');
1412 $this->t->set_var('lang_name','Assignment Name');
1413 $this->t->set_var('lang_code','Abbreviation');
1415 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1416 $this->db->query($sql,__LINE__,__FILE__);
1417 $total_records = $this->db->num_rows();
1420 while ($this->db->next_record()) {
1421 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1422 $assignment_list[$i]['name'] = $this->db->f('name');
1423 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1427 for ($i=0; $i < count($assignment_list); $i++) {
1428 $this->nextmatchs->template_alternate_row_color(&$this->t);
1429 $this->t->set_var('name',$assignment_list[$i]['name']);
1430 $this->t->set_var('abbreviation',$assignment_list[$i]['abbreviation']);
1432 $link_data['menuaction'] = 'tc.tc.assign_update';
1433 $link_data['assignment'] = $assignment_list[$i]['assignment'];
1434 $link_data['action'] = 'edit';
1435 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
1436 $this->t->set_var('lang_edit','Edit');
1438 $link_data['menuaction'] = 'tc.tc.assign_update';
1439 $link_data['assignment'] = '0';
1440 $link_data['action'] = 'add';
1441 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/tc/index.php',$link_data) .
1442 '"><input type="submit" name="Add" value="' . 'Add Assignment' .'"></font></form>');
1444 $this->t->fp('list','assign_view',True);
1447 $this->t->pfp('out','assign_view_t');
1448 $this->save_sessiondata();
1451 function assign_update()
1453 $this->t->set_file(array('form' => 'assign_update.tpl'));
1454 $this->t->set_block('form','add','addhandle');
1455 $this->t->set_block('form','edit','edithandle');
1456 $this->t->set_var('lang_done','Done');
1458 $action = get_var('action',array('GET','POST'));
1459 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_view'));
1460 $assignment['assignment'] = intval(get_var('assignment',array('GET','POST')));
1462 if($action == 'save') {
1463 $assignment['name'] = get_var('name',array('POST'));
1464 $assignment['abbreviation'] = get_var('abbreviation',array('POST'));
1465 $this->db->query("UPDATE tc_assignment set " .
1466 " name='" . $assignment['name'] . "'" .
1467 ", abbreviation='" . $assignment['abbreviation'] . "'" .
1468 " WHERE assignment=" . $assignment['assignment'],__LINE__,__FILE__);
1470 $this->assign_view();
1474 if($action == 'insert') {
1475 $assignment['name'] = get_var('name',array('POST'));
1476 $assignment['abbreviation'] = get_var('abbreviation',array('POST'));
1477 $this->db->query("INSERT INTO tc_assignment (name,abbreviation) " .
1478 "VALUES ('" . $assignment['name'] . "','" .
1479 $assignment['abbreviation'] . "')",__LINE__,__FILE__);
1480 $this->assign_view();
1484 if($action == 'add') {
1485 $assignment['assignment'] = 0;
1486 $this->t->set_var('name','');
1487 $this->t->set_var('abbreviation','');
1488 $this->t->set_var('lang_done','Cancel');
1489 $this->t->set_var('lang_action','Adding New Assignment');
1490 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_update&assignment=' .
1491 $assignment['assignment'] . '&action=' . 'insert'));
1494 if($action == 'edit')
1496 $sql = "SELECT * FROM tc_assignment WHERE assignment=" . $assignment['assignment'];
1497 $this->db->query($sql,__LINE__,__FILE__);
1498 $this->db->next_record();
1499 $this->t->set_var('name', $this->db->f('name'));
1500 $this->t->set_var('abbreviation', $this->db->f('abbreviation'));
1501 $this->t->set_var('lang_done','Cancel');
1502 $this->t->set_var('lang_action','Editing Assignment');
1503 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_update&assignment=' .
1504 $assignment['assignment'] . '&action=' . 'save'));
1507 $this->t->set_var('lang_reset','Clear Form');
1508 $this->t->set_var('lang_add','Add Assignment');
1509 $this->t->set_var('lang_save','Save Changes');
1510 $this->t->set_var('edithandle','');
1511 $this->t->set_var('addhandle','');
1513 $this->t->pfp('out','form');
1514 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
1515 if($action == 'add') { $this->t->pfp('addhandle','add'); }
1517 $this->save_sessiondata();
1522 $this->t->set_file(array('par_view_t' => 'par_view.tpl'));
1523 $this->t->set_block('par_view_t','header_list','list1');
1524 $this->t->set_block('par_view_t','individual_list','list2');
1526 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
1527 $this->db->query($sql,__LINE__,__FILE__);
1529 while ($this->db->next_record()) {
1530 $individual_name[$i] = $this->db->f('name');
1531 $individual[$i] = $this->db->f('individual');
1534 array_multisort($individual_name, $individual);
1536 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
1537 $this->db->query($sql,__LINE__,__FILE__);
1538 $total_records = $this->db->num_rows();
1541 while ($this->db->next_record()) {
1542 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1543 $activity_list[$i]['date'] = $this->db->f('date');
1544 $activity_list[$i]['activity'] = $this->db->f('activity');
1548 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1549 $this->db->query($sql,__LINE__,__FILE__);
1551 while($this->db->next_record()) {
1552 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1553 $assignment_list[$i]['name'] = $this->db->f('name');
1554 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1558 $individual_width=300; $part_width=25; $assignment_width=50;
1559 $total_width=$individual_width+$part_width;
1560 for ($i=0; $i < count($assignment_list); $i++) {
1561 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1562 $this->t->set_var('assignment_abbreviation',$assignment_list[$i]['abbreviation']);
1563 $this->t->fp('list1','header_list',True);
1564 $total_width += $assignment_width;
1567 for ($i=0; $i < count($individual); $i++) {
1568 $participated=0; $part_table = '';
1569 $this->nextmatchs->template_alternate_row_color(&$this->t);
1570 $this->t->set_var('individual_name',$individual_name[$i]);
1571 for ($j=0; $j < count($assignment_list); $j++) {
1572 $date = "0000-00-00"; $checkmark=0; $num_matches=0;
1573 for ($k=0; $k < count($activity_list); $k++) {
1574 if($assignment_list[$j]['assignment'] == $activity_list[$k]['assignment']) {
1575 $sql = "SELECT * FROM tc_participation where " .
1576 " activity=" . $activity_list[$k]['activity'] .
1577 " AND individual=" . $individual[$i];
1578 $this->db->query($sql,__LINE__,__FILE__);
1579 while($this->db->next_record()) {
1580 if($activity_list[$k]['date'] > $date) {
1581 $date = $activity_list[$k]['date'];
1590 $part_table .= '<td align=center><img src="images/checkmark.gif">';
1591 $part_table .= '<font size=-2>'.$num_matches.'</font><br>';
1592 $part_table .= '<font size=-2>'.$date.'</font></td>';
1594 $part_table .= '<td> </td>';
1598 $part_table .= '<td align=center><img src="images/checkmark.gif">'.$participated.'</td>';
1600 $part_table .= '<td> </td>';
1602 $this->t->set_var('part_table',$part_table);
1603 $this->t->fp('list2','individual_list',True);
1605 $this->t->set_var('total_width',$total_width);
1606 $this->t->set_var('individual_width',$individual_width);
1607 $this->t->set_var('part_width',$part_width);
1608 $this->t->set_var('act_width',$act_width);
1609 $this->t->pfp('out','par_view_t');
1610 $this->save_sessiondata();
1613 function willing_view()
1615 $this->t->set_file(array('willing_view_t' => 'willing_view.tpl'));
1616 $this->t->set_block('willing_view_t','header_list','list1');
1617 $this->t->set_block('willing_view_t','individual_list','list2');
1619 $this->t->set_var('lang_filter','Filter');
1620 $this->t->set_var('lang_filter_unwilling','Filter out unwilling individuals:');
1622 $filter_unwilling = get_var('filter_unwilling',array('POST'));
1623 $this->t->set_var('filter_unwilling',$filter_unwilling);
1625 if($filter_unwilling == 'y' || $filter_unwilling == '') {
1626 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\" checked>Y";
1627 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\">N";
1628 $filter_input.= " ";
1630 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\">Y";
1631 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\" checked>N";
1632 $filter_input.= " ";
1634 $this->t->set_var('filter_input',$filter_input);
1636 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
1637 $this->db->query($sql,__LINE__,__FILE__);
1639 while ($this->db->next_record()) {
1640 $indiv_name[$i] = $this->db->f('name');
1641 $individual[$i] = $this->db->f('individual');
1642 $indiv_phone[$individual[$i]] = $this->db->f('phone');
1645 array_multisort($indiv_name, $individual);
1647 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1648 $this->db->query($sql,__LINE__,__FILE__);
1650 while($this->db->next_record()) {
1651 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1652 $assignment_list[$i]['name'] = $this->db->f('name');
1653 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1657 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
1658 $this->db->query($sql,__LINE__,__FILE__);
1659 $total_records = $this->db->num_rows();
1662 while ($this->db->next_record()) {
1663 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1664 $activity_list[$i]['date'] = $this->db->f('date');
1665 $activity_list[$i]['activity'] = $this->db->f('activity');
1669 $indiv_width=275; $willing_width=40; $assignment_width=50;
1670 $total_width=$indiv_width+$willing_width;
1672 for ($i=0; $i < count($assignment_list); $i++) {
1673 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1674 $this->t->set_var('assignment_abbreviation',$assignment_list[$i]['abbreviation']);
1675 $this->t->fp('list1','header_list',True);
1676 $total_width += $assignment_width;
1677 $total_willing[$i] = 0;
1680 for ($i=0; $i < count($individual); $i++) {
1681 $willing_table = ''; $indiv_willing=0;
1682 $this->t->set_var('individual_name',$indiv_name[$i]);
1683 $this->t->set_var('individual_phone',$indiv_phone[$individual[$i]]);
1684 $this->t->set_var('editurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_update&individual=' .
1685 $individual[$i] . '&action=' . 'edit'));
1686 for ($j=0; $j < count($assignment_list); $j++) {
1687 $found_willingness=0;
1688 $sql = "SELECT * FROM tc_willingness where " .
1689 " assignment=" . $assignment_list[$j]['assignment'] .
1690 " AND individual=" . $individual[$i];
1691 $this->db->query($sql,__LINE__,__FILE__);
1692 while($this->db->next_record()) {
1693 $found_willingness=1;
1695 $sql = "SELECT * FROM tc_activity where " .
1696 " assignment=". $assignment_list[$j]['assignment'] .
1697 " ORDER by date DESC";
1698 $this->db2->query($sql,__LINE__,__FILE__);
1699 if($this->db2->next_record()) {
1700 $activity = $this->db2->f('activity');
1701 $date = $this->db2->f('date');
1702 $sql = "SELECT * FROM tc_participation where " .
1703 " activity=" . $activity .
1704 " AND individual=". $individual[$i];
1705 $this->db3->query($sql,__LINE__,__FILE__);
1706 if($this->db3->next_record()) {
1711 if($this->db->f('willing') == 'y') {
1712 $total_willing[$j]++;
1714 $willing_table .= '<td align=center><img src="images/checkmark.gif"><br><font size=-2>'.$date_part.'</font></td></td>';
1715 } else if($this->db->f('willing') == 'n') {
1716 $willing_table .= '<td align=center><img src="images/x.gif"></td>';
1719 $willing_table .= "<td> </td>";
1722 if(!$found_willingness) {
1724 $willing_table .= "<td> </td>";
1727 if(($indiv_willing == 1) || ($filter_unwilling == 'n')) {
1728 $this->t->set_var('willing_table',$willing_table);
1729 $this->t->fp('list2','individual_list',True);
1730 $this->nextmatchs->template_alternate_row_color(&$this->t);
1734 $stat_table = '<td><b>Total Willing to Serve</b></td>';
1735 for ($j=0; $j < count($assignment_list); $j++) {
1736 $stat_table .= "<td align=center><b>".$total_willing[$j]."</b></td>";
1738 $this->t->set_var('stat_table',$stat_table);
1740 $this->t->set_var('total_width',$total_width);
1741 $this->t->set_var('individual_width',$indiv_width);
1742 $this->t->set_var('willing_width',$willing_width);
1743 $this->t->pfp('out','willing_view_t');
1744 $this->save_sessiondata();
1747 function willing_update()
1749 //print "<font color=red>Willingness Update Under Constrcution</font>";
1750 //$this->willing_view();
1753 $this->t->set_file(array('willing_update_t' => 'willing_update.tpl'));
1754 $this->t->set_block('willing_update_t','assignment_list','list');
1755 $this->t->set_block('willing_update_t','save','savehandle');
1757 $individual = get_var('individual',array('GET','POST'));
1758 $this->t->set_var('individual',$individual);
1759 $action = get_var('action',array('GET','POST'));
1761 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_view'));
1762 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_update&action=save'));
1763 $this->t->set_var('lang_done','Cancel');
1764 $this->t->set_var('title','Willingness Update ');
1766 if($action == 'save') {
1767 // Delete all the previous willingness entries for this individual
1768 $this->db->query("DELETE from tc_willingness where individual=" . $individual ,__LINE__,__FILE__);
1770 // Now, add the assignment willingness that is checked for this individual
1771 $new_data = get_var('willingness',array('POST'));
1772 foreach ($new_data as $data) {
1773 $data_array = explode("/",$data);
1774 $assignment = $data_array[0];
1775 $willing = $data_array[1];
1776 //print "individual: $individual assignment: $assignment willing: $willing<br>";
1777 $this->db->query("INSERT INTO tc_willingness (individual,assignment,willing) " .
1778 "VALUES (" . $individual .",". $assignment .",'". $willing . "')",__LINE__,__FILE__);
1780 $this->willing_view();
1784 $assignment_width=300; $willing_width=25; $table_width=$assignment_width + $willing_width;
1787 // Find out the individual's name
1788 $sql = "SELECT * FROM tc_individual WHERE individual=".$individual." AND valid=1";
1789 $this->db->query($sql,__LINE__,__FILE__);
1790 if($this->db->next_record()) {
1791 $indiv_name = $this->db->f('name');
1792 $this->t->set_var('individual_name',$indiv_name);
1795 // Select all the assignments
1796 $sql = "SELECT * FROM tc_assignment ORDER by name ASC";
1797 $this->db->query($sql,__LINE__,__FILE__);
1799 while ($this->db->next_record()) {
1800 $assignment = $this->db->f('assignment');
1801 $assignment_name = $this->db->f('name');
1802 $assignment_abbreviation = $this->db->f('abbreviation');
1804 $this->nextmatchs->template_alternate_row_color(&$this->t);
1805 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$assignment_name</td>";
1807 $header_row="<th width=$comp_width><font size=-2>Assignments</th><th>Willingness</th>";
1808 $sql = "SELECT * FROM tc_willingness WHERE individual=".$individual." AND assignment=".$assignment;
1809 $this->db2->query($sql,__LINE__,__FILE__);
1810 $value = $assignment;
1812 if($this->db2->next_record()) {
1813 if($this->db2->f('willing') == 'y') {
1814 $table_data .= '<td width=100 align=center>';
1815 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y" checked>Y';
1816 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1817 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/"> ';
1818 $table_data .= '</td>';
1819 } else if($this->db2->f('willing') == 'n') {
1820 $table_data .= '<td width=100 align=center>';
1821 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1822 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n" checked>N';
1823 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/">';
1824 $table_data .= '</td>';
1826 $table_data .= '<td width=100 align=center>';
1827 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1828 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1829 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1830 $table_data .= '</td>';
1833 $table_data .= '<td width=100 align=center>';
1834 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1835 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1836 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1837 $table_data .= '</td>';
1840 $table_data .= "\n";
1841 $table_data .= "</tr>";
1842 $table_data .= "<tr><td colspan=20></td></tr>";
1845 $table_data .= "<tr><td colspan=20><hr></td></tr>";
1847 $this->t->set_var('table_width',$table_width);
1848 $this->t->set_var('header_row',$header_row);
1849 $this->t->set_var('table_data',$table_data);
1850 $this->t->fp('list','assignment_list',True);
1852 $this->t->set_var('lang_reset','Clear Form');
1853 $this->t->set_var('lang_save','Save Changes');
1854 $this->t->set_var('savehandle','');
1856 $this->t->pfp('out','willing_update_t');
1857 $this->t->pfp('addhandle','save');
1859 $this->save_sessiondata();
1863 function ppi_sched()
1865 $this->t->set_file(array('ppi_sched_t' => 'ppi_sched.tpl'));
1866 $this->t->set_block('ppi_sched_t','individual_list','indivlist');
1867 $this->t->set_block('ppi_sched_t','appt_list','apptlist');
1868 $action = get_var('action',array('GET','POST'));
1870 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1871 $this->t->set_var('lang_reset','Clear Changes');
1873 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
1874 $this->t->set_var('ppi_link_title',$this->ppi_frequency_label . ' PPIs');
1876 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
1877 $this->t->set_var('schedule_ppi_link_title','Schedule ' . $this->ppi_frequency_label . ' PPIs');
1879 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched&action=save'));
1880 $this->t->set_var('title',$this->ppi_frequency_label . ' PPI Scheduler');
1882 $header_row = "<th ><font size=-2>Individual Name</th>";
1883 $header_row.= "<th><font size=-2>Phone</th>";
1884 $header_row.= "<th><font size=-2>Priority</th>";
1885 $header_row.= "<th><font size=-2>Last PPI</th>";
1886 $header_row.= "<th><font size=-2>Scheduling Notes</th>";
1887 $table_data=""; $completed_data=""; $totals_data="";
1891 $period = intval(($month-1)/$this->ppi_frequency) + 1;
1892 $start_of_period = ($period-1)*$this->ppi_frequency + 1;
1893 $end_of_period = $period * $this->ppi_frequency;
1895 if($action == 'save') {
1896 // Save any changes made to the appointment table
1897 $new_data = get_var('appt_notes',array('POST'));
1898 if($new_data != "") {
1899 foreach ($new_data as $entry) {
1900 $indiv = $entry['individual'];
1901 $appointment = $entry['appointment'];
1902 $location = $entry['location'];
1903 $leader_location = $entry['leader_location'];
1904 if($location == "") { $location = $leader_location; }
1905 if($indiv == 0) { $location = ""; }
1907 //Only perform a database update if we have made a change to this appointment
1908 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and individual='$indiv' and location='$location'";
1909 $this->db->query($sql,__LINE__,__FILE__);
1910 if(!$this->db->next_record()) {
1911 // Perform database save actions here
1912 $this->db->query("UPDATE tc_appointment set " .
1913 " individual='" . $indiv . "'" .
1914 ",location='" . $location . "'" .
1915 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1916 // Email the appointment
1917 $this->email_appt($appointment);
1922 // Save any changes made to the ppi notes table
1923 $new_data = get_var('notes',array('POST'));
1924 foreach ($new_data as $entry) {
1925 $notes = $entry['notes'];
1926 $individual = $entry['individual'];
1927 $priority = $entry['pri'];
1929 // Perform database save actions here
1930 $sql = "SELECT * FROM tc_individual WHERE individual='$individual'";
1931 $this->db->query($sql,__LINE__,__FILE__);
1932 if ($this->db->next_record()) {
1933 $scheduling_priority = $this->db->f('scheduling_priority');
1934 //$this->logToFile("ppi_sched", "UPDATE tc_scheduling_priority SET priority='$priority', notes=\"$notes\" WHERE scheduling_priority='$scheduling_priority'");
1935 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$priority', notes=\"$notes\" WHERE scheduling_priority='$scheduling_priority'", __LINE__, __FILE__);
1939 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched');
1940 //Header('Location: ' . $take_me_to_url);
1943 // create the individual id -> individual name mapping
1944 $sql = "SELECT * FROM tc_individual where valid=1 and steward='$this->default_stewardship' ORDER BY name ASC";
1945 $this->db->query($sql,__LINE__,__FILE__);
1949 while ($this->db->next_record()) {
1950 $indiv_name[$i] = $this->db->f('name');
1951 $individual[$i] = $this->db->f('individual');
1954 array_multisort($indiv_name, $individual);
1956 // APPOINTMENT TABLE
1957 $appt_header_row = "<th><font size=-2>Date</th>";
1958 $appt_header_row.= "<th><font size=-2>Time</th>";
1959 $appt_header_row.= "<th><font size=-2>Individual</th>";
1960 $appt_header_row.= "<th><font size=-2>Location</th>";
1961 $appt_table_data = "";
1964 $total_indivs=0; $indivs_with_yearly_ppi=0;
1966 // Get the President
1967 $sql = "SELECT * FROM tc_leader AS tl JOIN tc_individual AS ti where tl.individual=ti.individual AND tl.valid=1 AND ";
1968 if($this->yearly_ppi_interviewer == 1) { $sql .= " (tl.type='P')"; }
1969 if($this->yearly_ppi_interviewer == 2) { $sql .= " (tl.type='P' OR tl.type='C')"; }
1970 if($this->yearly_ppi_interviewer == 3) { $sql .= " (tl.type='P' OR tl.type='C' OR tl.type='S')"; }
1971 $this->db->query($sql,__LINE__,__FILE__);
1972 while ($this->db->next_record()) {
1973 $leader_name = $this->db->f('name');
1974 $leader_name_array = explode(",",$leader_name);
1975 $leader_last_name = $leader_name_array[0];
1976 $leader_id = $this->db->f('leader');
1977 $leader_address = $this->db->f('address');
1978 $leader_location = "$leader_last_name"." home ($leader_address)";
1979 $appt_table_data = "";
1981 // Display a scheduling table for this leader member
1982 $not_completed_table_title = "All individuals with " . $this->ppi_frequency_label . " PPI Not Completed";
1983 $appt_table_title = $leader_name . ": " . $this->ppi_frequency_label." PPI Appointment Slots";
1984 $this->t->set_var('not_completed_table_title',$not_completed_table_title);
1985 $this->t->set_var('appt_table_title',$appt_table_title);
1987 // query the database for all the appointments
1988 $sql = "SELECT * FROM tc_appointment where leader=".$leader_id." and date>=CURDATE() ORDER BY date ASC, time ASC";
1989 $this->db2->query($sql,__LINE__,__FILE__);
1991 while ($this->db2->next_record()) {
1992 $appointment = $this->db2->f('appointment');
1993 $indiv = $this->db2->f('individual');
1994 $location = $this->db2->f('location');
1995 if(($location == "") && ($indiv > 0)) { $location = $leader_location; }
1997 $date = $this->db2->f('date');
1998 $date_array = explode("-",$date);
1999 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
2000 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
2002 $time = $this->db2->f('time');
2003 $time_array = explode(":",$time);
2004 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
2006 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2007 $appt_table_data.= "<td align=center>$day_string</td>";
2008 $appt_table_data.= "<td align=center>$time_string</td>";
2010 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][individual]>';
2011 $appt_table_data.= '<option value=0></option>';
2012 for ($i=0; $i < count($individual); $i++) {
2013 $id = $individual[$i];
2014 $name = $indiv_name[$i];
2015 if($individual[$i] == $indiv) {
2016 $selected[$id] = 'selected="selected"';
2018 $selected[$id] = '';
2020 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
2022 $appt_table_data.='</select></td>';
2024 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
2025 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
2027 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
2029 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2030 $this->t->set_var('tr_color',$tr_color);
2032 $this->t->set_var('appt_table_data',$appt_table_data);
2033 $this->t->set_var('appt_header_row',$appt_header_row);
2034 $this->t->set_var('lang_save','Save Appts for ' . $leader_name);
2036 $this->t->fp('apptlist','appt_list',True);
2039 // PPI SCHEDULING TABLE
2040 $sql = "SELECT * FROM tc_individual AS ti JOIN tc_scheduling_priority AS tsp WHERE ti.scheduling_priority=tsp.scheduling_priority AND steward='$this->default_stewardship' AND valid=1 ORDER BY tsp.priority ASC, ti.name ASC";
2041 $this->db->query($sql,__LINE__,__FILE__);
2045 while ($this->db->next_record()) {
2046 $individual[$i] = $this->db->f('individual');
2047 $indiv_name[$i] = $this->db->f('name');
2048 $indiv_phone[$individual[$i]] = $this->db->f('phone');
2049 $indiv_priority[$individual[$i]] = $this->db->f('priority');
2050 $indiv_notes[$individual[$i]] = $this->db->f('notes');
2055 $max = count($individual);
2057 for($i=0; $i < $max; $i++) {
2058 $id = $individual[$i];
2059 $name = $indiv_name[$i];
2060 $phone = $indiv_phone[$id];
2061 $priority = $indiv_priority[$id];
2062 $notes = $indiv_notes[$id];
2064 // If this individual has had a PPI this period, don't show him on the schedule list
2065 $year_start = $year . "-" . $start_of_period . "-01";
2066 $year_end = $year . "-" . $end_of_period . "-31";
2067 $sql = "SELECT * FROM tc_interview WHERE date >= '$year_start' AND date <= '$year_end' ".
2068 "AND individual=" . $id . " AND type='P' ORDER BY date DESC";
2069 $this->db2->query($sql,__LINE__,__FILE__);
2071 if(!$this->db2->next_record()) {
2072 $sql = "SELECT * FROM tc_interview WHERE individual=" . $id . " AND type='P' ORDER BY date DESC";
2073 $this->db->query($sql,__LINE__,__FILE__);
2074 if($this->db->next_record()) {
2075 $date = $this->db->f('date');
2079 $link_data['menuaction'] = 'tc.tc.ppi_update';
2080 $link_data['individual'] = $id;
2081 $link_data['name'] = $name;
2082 $link_data['interview'] = '';
2083 $link_data['type'] = 1;
2084 $link_data['action'] = 'add';
2085 $link_data['interviewer'] = $interviewer;
2086 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2087 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2088 $this->t->set_var('tr_color',$tr_color);
2089 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2090 $table_data.= "<td align=center>$phone</td>";
2091 //$table_data.= "<td align=center>$priority</td>";
2092 $table_data.= "<td align=center>";
2093 $table_data.= '<select name=notes['.$i.'][pri]>';
2094 foreach(range(0,6) as $num) {
2095 if($num == 0) { $num = 1; } else {$num = $num*5; }
2096 if($priority == $num) {
2097 $selected[$num] = 'selected="selected"';
2099 $selected[$num] = '';
2101 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2103 $table_data.= '</select></td>';
2104 $table_data.= "<td align=center>$date</td>";
2105 $table_data.= '<td><input type=text size="50" maxlength="128" name="notes['.$i.'][notes]" value="'.$notes.'">';
2106 $table_data.= '<input type=hidden name="notes['.$i.'][individual]" value="'.$id.'">';
2107 $table_data.= '<input type=hidden name="notes['.$i.'][indiv_name]" value="'.$name.'">';
2108 $table_data.= '</td>';
2109 $table_data.= '</tr>';
2111 $link_data['menuaction'] = 'tc.tc.ppi_update';
2112 $link_data['interviewer'] = $this->db2->f('interviewer');
2113 $link_data['individual'] = $this->db2->f('individual');
2114 $link_data['name'] = $name;
2115 $link_data['interview'] = $this->db2->f('interview');
2116 $link_data['type'] = $this->db2->f('type');
2117 $link_data['action'] = 'view';
2118 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2119 $indivs_with_yearly_ppi++;
2120 $date = $this->db2->f('date');
2121 $notes = $this->db2->f('notes');
2122 if(strlen($notes) > 40) { $notes = substr($notes,0,40) . "..."; }
2123 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
2124 $this->t->set_var('tr_color2',$tr_color2);
2125 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2126 $completed_data.= "<td align=center>$phone</td>";
2127 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2128 $completed_data.= "<td align=left>$notes</td>";
2129 $completed_data.= '</tr>';
2131 } // End for individuals Loop
2133 $completed_table_title = "All individuals with " . $this->ppi_frequency_label . " PPI Completed";
2134 $completed_header_row = "<th><font size=-2>Individual</th>";
2135 $completed_header_row.= "<th><font size=-2>Phone</th>";
2136 $completed_header_row.= "<th><font size=-2>Date</th>";
2137 $completed_header_row.= "<th><font size=-2>PPI Notes</th>";
2139 $this->t->set_var('completed_table_title',$completed_table_title);
2140 $this->t->set_var('header_row',$header_row);
2141 $this->t->set_var('table_data',$table_data);
2142 $this->t->set_var('completed_header_row',$completed_header_row);
2143 $this->t->set_var('completed',$completed_data);
2144 $this->t->set_var('lang_save','Save Pri / Notes');
2145 $this->t->fp('indivlist','individual_list',True);
2147 $totals_header_row = "<th><font size=-2>Individuals</th>";
2148 $totals_header_row.= "<th><font size=-2>$year</th>";
2149 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2150 $totals_data.= "<td align=left><font size=-2><b>Total Individuals with " . $this->ppi_frequency_label . " PPIs completed:</b></font></td>";
2151 $totals_data.= "<td align=center><font size=-2><b>$indivs_with_yearly_ppi / $total_indivs</b></font></td>";
2152 $percent = ceil(($indivs_with_yearly_ppi / $total_indivs)*100);
2153 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2154 $this->t->set_var('tr_color',$tr_color);
2155 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2156 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2157 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2158 $totals_data.= "</tr>";
2160 $this->t->set_var('totals',$totals_data);
2161 $this->t->set_var('totals_header_row',$totals_header_row);
2162 $this->t->set_var('ppi_frequency_label',$this->ppi_frequency_label);
2164 $this->t->pfp('out','ppi_sched_t');
2165 $this->save_sessiondata();
2169 function int_sched()
2171 $this->t->set_file(array('int_sched_t' => 'int_sched.tpl'));
2172 $this->t->set_block('int_sched_t','individual_list','indivlist');
2173 $this->t->set_block('int_sched_t','appt_list','apptlist');
2174 $action = get_var('action',array('GET','POST'));
2176 $this->t->set_var('lang_reset','Clear Changes');
2178 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2179 $this->t->set_var('int_link_title','Hometeaching Interviews');
2181 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
2182 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
2184 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched&action=save'));
2185 $this->t->set_var('title','Hometeaching Interviews Scheduler');
2187 $header_row = "<th><font size=-2>Individual</th>";
2188 $header_row.= "<th><font size=-2>Phone</th>";
2189 $header_row.= "<th><font size=-2>Priority</th>";
2190 $header_row.= "<th><font size=-2>Last Interview</th>";
2191 $header_row.= "<th><font size=-2>Scheduling Notes</th>";
2192 $table_data=""; $completed_data=""; $totals_data="";
2196 $nextyear = $year + 1;
2197 if($month >= 1 && $month <= 3) { $quarter_start=$year."-01-01"; $quarter_end=$year."-04-01"; }
2198 if($month >= 4 && $month <= 6) { $quarter_start=$year."-04-01"; $quarter_end=$year."-07-01"; }
2199 if($month >= 7 && $month <= 9) { $quarter_start=$year."-07-01"; $quarter_end=$year."-10-01"; }
2200 if($month >= 10 && $month <= 12) { $quarter_start=$year."-10-01"; $quarter_end=$nextyear."-01-01"; }
2201 //print "year: $year month: $month quarter_start: $quarter_start quarter_end: $quarter_end<br>";
2203 // create the individual id -> individual name mapping
2204 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY name ASC";
2205 $this->db->query($sql,__LINE__,__FILE__);
2207 $individual_data = NULL;
2208 $indiv_name_data = NULL;
2209 while ($this->db->next_record()) {
2210 $indiv_name_data[$i] = $this->db->f('name');
2211 $individual_data[$i] = $this->db->f('individual');
2212 $individ2name[$individual_data[$i]] = $indiv_name_data[$i];
2215 // add any YM that are home teachers
2216 $sql = "SELECT * FROM tc_companionship WHERE type='H' AND valid=1";
2217 $this->db->query($sql,__LINE__,__FILE__);
2218 while ($this->db->next_record()) {
2219 $tmp_individual = $this->db->f('individual');
2220 $sql = "Select * FROM tc_individual where individual='$tmp_individual' and steward='' and valid=1";
2221 $this->db2->query($sql,__LINE__,__FILE__);
2222 while ($this->db2->next_record()) {
2223 $indiv_name_data[$i] = $this->db2->f('name');
2224 $individual_data[$i] = $this->db2->f('individual');
2225 $individ2name[$individual_data[$i]] = $indiv_name_data[$i];
2229 array_multisort($indiv_name_data, $individual_data);
2231 if($action == 'save') {
2232 // Save any changes made to the appointment table
2233 $new_data = get_var('appt_notes',array('POST'));
2234 if($new_data != "") {
2235 foreach ($new_data as $entry) {
2236 $indiv = $entry['individual'];
2237 $appointment = $entry['appointment'];
2238 $location = $entry['location'];
2239 if($location == "") {
2240 $leader = $entry['leader'];
2241 $leader_array = explode(",", $individ2name[$leader]);
2242 $leader_last_name = $leader_array[0];
2243 $sql = "SELECT * FROM tc_individual where individual='$leader'";
2244 $this->db2->query($sql,__LINE__,__FILE__);
2245 if($this->db2->next_record()) {
2246 $leader_address = $this->db2->f('address');
2248 $location = "$leader_last_name"." home ($leader_address)";
2250 if($indiv == 0) { $location = ""; }
2252 //print "indiv: $indiv appointment: $appointment <br>";
2253 //Only perform a database update if we have made a change to this appointment
2254 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and individual='$indiv' and location='$location'";
2255 $this->db->query($sql,__LINE__,__FILE__);
2256 if(!$this->db->next_record()) {
2257 // Perform database save actions here
2258 $this->db->query("UPDATE tc_appointment set " .
2259 " individual='" . $indiv . "'" .
2260 ",location='" . $location . "'" .
2261 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
2262 // Email the appointment
2263 $this->email_appt($appointment);
2268 // Save any changes made to the int notes table
2269 $new_data = get_var('hti_notes',array('POST'));
2270 foreach ($new_data as $entry) {
2271 $hti_notes = $entry['notes'];
2272 $individual = $entry['individual'];
2273 $indiv_name = $entry['indiv_name'];
2274 $hti_pri = $entry['pri'];
2275 //print "hti_notes: $hti_notes indiv_name: $indiv_name <Br>";
2276 // Perform database save actions here
2277 $this->db->query("SELECT * FROM tc_companion WHERE individual=$individual and valid=1",__LINE__,__FILE__);
2278 if ($this->db->next_record()) {
2279 $scheduling_priority = $this->db->f('scheduling_priority');
2280 //$this->logToFile("int_sched", "UPDATE tc_scheduling_priority SET priority='$hti_pri', notes=\"$hti_notes\" WHERE scheduling_priority='$scheduling_priority'");
2281 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$hti_pri', notes=\"$hti_notes\" WHERE scheduling_priority='$scheduling_priority'",__LINE__,__FILE__);
2285 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched');
2286 //Header('Location: ' . $take_me_to_url);
2289 // Get the Districts
2290 $sql = "SELECT * FROM tc_district AS td JOIN (tc_leader AS tl, tc_individual AS ti) WHERE td.leader=tl.leader AND tl.individual=ti.individual AND td.valid=1 ORDER BY td.district ASC";
2291 $this->db->query($sql,__LINE__,__FILE__);
2293 while ($this->db->next_record()) {
2294 $district = $this->db->f('district');
2295 $districts[$i]['district'] = $this->db->f('district');
2296 $districts[$i]['name'] = $this->db->f('name');
2297 $districts[$i]['leader'] = $this->db->f('leader');
2301 // APPOINTMENT TABLE
2303 $appt_header_row = "<th><font size=-2>Date</th>";
2304 $appt_header_row.= "<th><font size=-2>Time</th>";
2305 $appt_header_row.= "<th><font size=-2>Individual</th>";
2306 $appt_header_row.= "<th><font size=-2>Location</th>";
2307 $appt_table_data = "";
2309 $total_comps=0; $comps_with_quarterly_int=0;
2311 // Display a scheduling table for each district
2312 for ($d=0; $d < count($districts); $d++) {
2313 $table_data=""; $appt_table_data="";
2314 $this->t->set_var('district_number',$districts[$d]['district']);
2315 $this->t->set_var('district_name',$districts[$d]['name']);
2316 $leader = $districts[$d]['leader'];
2317 $leader_array = explode(",", $leader);
2318 $leader_last_name = $leader_array[0];
2319 $sql = "SELECT * FROM tc_individual where individual='$leader'";
2320 $this->db2->query($sql,__LINE__,__FILE__);
2321 if($this->db2->next_record()) {
2322 $leader_address = $this->db2->f('address');
2324 $location = "$leader_last_name"." home ($leader_address)";
2325 $table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": All Individuals with Interviews Not Completed";
2326 $appt_table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": Interview Appointment Slots";
2327 $this->t->set_var('table_title',$table_title);
2328 $this->t->set_var('appt_table_title',$appt_table_title);
2330 // query the database for all the appointments
2331 $sql = "SELECT * FROM tc_appointment where leader=".$districts[$d]['leader']." and date>=CURDATE() ORDER BY date ASC, time ASC";
2332 $this->db->query($sql,__LINE__,__FILE__);
2334 while ($this->db->next_record()) {
2335 $appointment = $this->db->f('appointment');
2336 $indiv = $this->db->f('individual');
2337 $location = $this->db->f('location');
2338 if(($location == "") && ($indiv > 0)) { $location = "$leader_last_name"." home ($leader_address)"; }
2340 $date = $this->db->f('date');
2341 $date_array = explode("-",$date);
2342 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
2343 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
2345 $time = $this->db->f('time');
2346 $time_array = explode(":",$time);
2347 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
2349 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2350 $appt_table_data.= "<td align=center>$day_string</td>";
2351 $appt_table_data.= "<td align=center>$time_string</td>";
2353 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][individual]>';
2354 $appt_table_data.= '<option value=0></option>';
2355 for ($i=0; $i < count($individual_data); $i++) {
2356 $id = $individual_data[$i];
2357 $name = $indiv_name_data[$i];
2358 if($individual_data[$i] == $indiv) {
2359 $selected[$id] = 'selected="selected"';
2361 $selected[$id] = '';
2363 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
2365 $appt_table_data.='</select></td>';
2367 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
2368 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
2370 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
2371 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][leader]" value="'.$leader.'">';
2373 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2374 $this->t->set_var('tr_color',$tr_color);
2377 $this->t->set_var('appt_table_data',$appt_table_data);
2378 $this->t->set_var('appt_header_row',$appt_header_row);
2380 // INTERVIEW SCHEDULING TABLE
2382 // Select all the unique companionship numbers for this district
2383 $sql = "SELECT DISTINCT companionship FROM tc_companionship WHERE type='H' AND valid=1 AND district=". $districts[$d]['district'];
2384 $this->db->query($sql,__LINE__,__FILE__);
2385 $j=0; $unique_companionships = '';
2386 while ($this->db->next_record())
2388 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
2393 for ($j=0; $j < count($unique_companionships); $j++) {
2394 // Select all the companions from each companionship
2395 $sql = "SELECT * FROM tc_companion AS tc JOIN (tc_scheduling_priority AS tsp, tc_individual AS ti) WHERE tc.scheduling_priority=tsp.scheduling_priority AND tc.individual=ti.individual AND tc.valid=1 AND tc.companionship=". $unique_companionships[$j]['companionship'];
2396 $this->db->query($sql,__LINE__,__FILE__);
2397 $k=0; $int_completed=0;
2398 $comp = $unique_companionships[$j]['companionship'];
2399 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2400 $this->t->set_var('tr_color',$tr_color);
2402 while ($this->db->next_record()) {
2403 // Get this companions information
2404 $individual = $this->db->f('individual');
2406 $id = $this->db->f('individual');
2407 $name = $this->db->f('name');
2408 $phone = $this->db->f('phone');
2409 $hti_pri = $this->db->f('priority');
2410 $hti_notes = $this->db->f('notes');
2412 // If the companionship has already had its quarterly interview,
2413 // Skip the other companion in the companionship.
2414 if($int_completed == 1) {
2415 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2416 $completed_data.= "<td align=center>$phone</td>";
2417 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2418 $completed_data.= "<td align=left>$hti_notes</td>";
2419 $completed_data.= '</tr>';
2420 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
2421 $this->t->set_var('tr_color2',$tr_color2);
2422 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2423 $this->t->set_var('tr_color',$tr_color);
2427 // If this companionship has had a hometeaching interview this quarter, don't show them on the schedule list
2428 $sql = "SELECT * FROM tc_interview WHERE date >= '$quarter_start' AND date < '$quarter_end' AND individual='$id' AND type='H'";
2429 $this->db2->query($sql,__LINE__,__FILE__);
2431 if(!$this->db2->next_record()) {
2432 $sql = "SELECT * FROM tc_interview WHERE individual='$id' AND type='H' ORDER BY date DESC";
2433 $this->db3->query($sql,__LINE__,__FILE__);
2434 if($this->db3->next_record()) {
2435 $date = $this->db3->f('date');
2439 $link_data['menuaction'] = 'tc.tc.int_update';
2440 $link_data['individual'] = $id;
2441 $link_data['name'] = $name;
2442 $link_data['interview'] = '';
2443 $link_data['action'] = 'add';
2444 $link_data['type'] = 'H';
2445 $link_data['interviewer'] = $districts[$d]['leader'];
2446 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2447 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2448 $table_data.= "<td align=center>$phone</td>";
2449 $table_data.= "<td align=center>";
2450 $table_data.= '<select name=hti_notes['.$i.'][pri]>';
2451 foreach(range(0,6) as $num) {
2452 if($num == 0) { $num = 1; } else {$num = $num*5; }
2453 if($hti_pri == $num) {
2454 $selected[$num] = 'selected="selected"';
2456 $selected[$num] = '';
2458 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2460 $table_data.= '</select></td>';
2461 $table_data.= "<td align=center>$date</td>";
2462 $table_data.= '<td><input type=text size="50" maxlength="128" name="hti_notes['.$i.'][notes]" value="'.$hti_notes.'">';
2463 $table_data.= '<input type=hidden name="hti_notes['.$i.'][individual]" value="'.$id.'">';
2464 $table_data.= '<input type=hidden name="hti_notes['.$i.'][indiv_name]" value="'.$name.'">';
2465 $table_data.= '</td>';
2466 $table_data.= '</tr>'."\n";
2469 $link_data['menuaction'] = 'tc.tc.int_update';
2470 $link_data['interviewer'] = $this->db2->f('interviewer');
2471 $link_data['individual'] = $this->db2->f('individual');
2472 $link_data['name'] = $name;
2473 $link_data['interview'] = $this->db2->f('interview');
2474 $link_data['type'] = 'H';
2475 $link_data['action'] = 'view';
2476 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2477 $comps_with_quarterly_int++;
2479 $date = $this->db2->f('date');
2480 $hti_notes = $this->db2->f('notes');
2481 if(strlen($hti_notes) > 40) { $hti_notes = substr($hti_notes,0,40) . "..."; }
2482 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2483 $completed_data.= "<td align=center>$phone</td>";
2484 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2485 $completed_data.= "<td align=left>$hti_notes</td>";
2486 $completed_data.= '</tr>';
2491 $completed_header_row = "<th><font size=-2>Individual</th>";
2492 $completed_header_row.= "<th><font size=-2>Phone</th>";
2493 $completed_header_row.= "<th><font size=-2>Date</th>";
2494 $completed_header_row.= "<th><font size=-2>Interview Notes</th>";
2496 $this->t->set_var('header_row',$header_row);
2497 $this->t->set_var('table_data',$table_data);
2498 $this->t->set_var('completed_header_row',$completed_header_row);
2499 $this->t->set_var('completed',$completed_data);
2500 $this->t->set_var('lang_save_appt','Save Appts for ' . $districts[$d]['name']);
2501 $this->t->set_var('lang_save_pri_notes','Save Pri / Notes for '. $districts[$d]['name']);
2502 $this->t->fp('indivlist','individual_list',True);
2504 } // End for each district loop
2507 $totals_header_row = "<th><font size=-2>Individuals</th>";
2508 $totals_header_row.= "<th><font size=-2>$year</th>";
2509 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2510 $totals_data.= "<td align=left><font size=-2><b>Total Companionships with interviews completed:</b></font></td>";
2511 $totals_data.= "<td align=center><font size=-2><b>$comps_with_quarterly_int / $total_comps</b></font></td>";
2512 $percent = ceil(($comps_with_quarterly_int / $total_comps)*100);
2513 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2514 $this->t->set_var('tr_color',$tr_color);
2515 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2516 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2517 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2518 $totals_data.= "</tr>";
2520 $this->t->set_var('totals',$totals_data);
2521 $this->t->set_var('totals_header_row',$totals_header_row);
2523 $this->t->pfp('out','int_sched_t');
2524 $this->save_sessiondata();
2528 function vis_sched()
2530 $this->t->set_file(array('vis_sched_t' => 'vis_sched.tpl'));
2531 $this->t->set_block('vis_sched_t','family_list','familylist');
2532 $this->t->set_block('vis_sched_t','appt_list','apptlist');
2533 $action = get_var('action',array('GET','POST'));
2535 $this->t->set_var('lang_reset','Clear Changes');
2537 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2538 $this->t->set_var('vis_link_title','View Yearly Visits');
2540 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
2541 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2543 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched&action=save'));
2544 $this->t->set_var('title','Presidency Yearly Visit Scheduler');
2546 $header_row = "<th><font size=-2>Family Name</th>";
2547 $header_row.= "<th><font size=-2>Phone</th>";
2548 $header_row.= "<th><font size=-2>Priority</th>";
2549 $header_row.= "<th><font size=-2>Last Visit</th>";
2550 $header_row.= "<th><font size=-2>Scheduling Notes</th>";
2551 $table_data=""; $completed_data=""; $totals_data="";
2555 // create the family id -> family name mapping
2556 $sql = "SELECT * FROM tc_family AS tf JOIN tc_individual AS ti WHERE tf.individual=ti.individual AND tf.valid=1 AND tf.individual != 0 AND tf.companionship != 0 AND ti.steward='$this->default_stewardship' ORDER BY ti.name ASC";
2557 $this->db->query($sql,__LINE__,__FILE__);
2560 while ($this->db->next_record()) {
2561 $family_id[$i] = $this->db->f('family');
2562 $family_name[$i] = $this->db->f('name');
2563 $familyid2name[$family_id[$i]] = $family_name[$i];
2564 $familyid2address[$family_id[$i]] = $this->db->f('address');
2567 array_multisort($family_name, $family_id);
2569 if($action == 'save') {
2570 // Save any changes made to the appointment table
2571 $new_data = get_var('appt_notes',array('POST'));
2572 if($new_data != "") {
2573 foreach ($new_data as $entry) {
2574 $family = $entry['family'];
2575 $appointment = $entry['appointment'];
2576 $location = $entry['location'];
2577 if($location == "") {
2578 $family_name_array = explode(",", $familyid2name[$family]);
2579 $family_last_name = $family_name_array[0];
2580 $family_address = $familyid2address[$family];
2581 $location = "$family_last_name"." home ($family_address)";
2583 if($family == 0) { $location = ""; }
2585 //Only perform a database update if we have made a change to this appointment
2586 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and family='$family' and location='$location'";
2587 $this->db->query($sql,__LINE__,__FILE__);
2588 if(!$this->db->next_record()) {
2589 // Perform database save actions here
2590 $this->db->query("UPDATE tc_appointment set " .
2591 " family='" . $family . "'" .
2592 ",location='" . $location . "'" .
2593 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
2595 // Email the appointment
2596 $this->email_appt($appointment);
2601 // Save any changes made to the visit notes table
2602 $new_data = get_var('vis_notes',array('POST'));
2603 foreach ($new_data as $entry) {
2604 $visit_notes = $entry['notes'];
2605 $family = $entry['family_id'];
2606 $visit_pri = $entry['pri'];
2607 // Perform database save actions here
2608 $this->db->query("SELECT * FROM tc_family WHERE family='$family'",__LINE__,__FILE__);
2609 if ($this->db->next_record()) {
2610 $scheduling_priority = $this->db->f('scheduling_priority');
2611 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$visit_pri', notes=\"$visit_notes\" WHERE scheduling_priority='$scheduling_priority'", __LINE__, __FILE__);
2615 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched');
2616 //Header('Location: ' . $take_me_to_url);
2619 // APPOINTMENT TABLE
2620 $appt_header_row = "<th><font size=-2>Date</th>";
2621 $appt_header_row.= "<th><font size=-2>Time</th>";
2622 $appt_header_row.= "<th><font size=-2>Family</th>";
2623 $appt_header_row.= "<th><font size=-2>Location</th>";
2624 $appt_table_data = "";
2626 // Find out what the President ID is
2627 $sql = "SELECT * FROM tc_leader AS tl JOIN tc_individual AS ti WHERE tl.individual=ti.individual AND tl.type='P' AND tl.valid=1";
2628 $this->db->query($sql,__LINE__,__FILE__);
2629 if($this->db->next_record()) {
2630 $leader_name = $this->db->f('name');
2631 $leader_id = $this->db->f('leader');
2633 print "<hr><font color=red><h3>-E- Unable to locate Presidency in tc_leader table</h3></font></hr>";
2637 // query the database for all the appointments
2638 $sql = "SELECT * FROM tc_appointment where leader=$leader_id and date>=CURDATE() ORDER BY date ASC, time ASC";
2639 $this->db->query($sql,__LINE__,__FILE__);
2641 while ($this->db->next_record()) {
2642 $appointment = $this->db->f('appointment');
2643 $family = $this->db->f('family');
2644 $location = $this->db->f('location');
2645 $family_name_array = explode(",", $familyid2name[$family]);
2646 $family_last_name = $family_name_array[0];
2647 $family_address = $familyid2address[$family];
2648 if(($location == "") && ($family > 0)) { $location = "$family_last_name"." home ($family_address)"; }
2650 $date = $this->db->f('date');
2651 $date_array = explode("-",$date);
2652 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
2653 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
2655 $time = $this->db->f('time');
2656 $time_array = explode(":",$time);
2657 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
2659 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2660 $appt_table_data.= "<td align=center>$day_string</td>";
2661 $appt_table_data.= "<td align=center>$time_string</td>";
2663 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][family]>';
2664 $appt_table_data.= '<option value=0></option>';
2665 for ($i=0; $i < count($family_id); $i++) {
2666 $id = $family_id[$i];
2667 $name = $family_name[$i];
2668 if($family_id[$i] == $family) {
2669 $selected[$id] = 'selected="selected"';
2671 $selected[$id] = '';
2673 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
2675 $appt_table_data.='</select></td>';
2677 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
2678 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
2680 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
2682 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2683 $this->t->set_var('tr_color',$tr_color);
2686 $this->t->set_var('appt_table_data',$appt_table_data);
2687 $this->t->set_var('appt_header_row',$appt_header_row);
2690 // VISIT SCHEDULING TABLE
2691 $sql = "SELECT * FROM tc_family AS tf JOIN (tc_scheduling_priority AS tsp, tc_individual as ti) WHERE tf.scheduling_priority=tsp.scheduling_priority AND tf.individual=ti.individual AND tf.valid=1 AND tf.individual != 0 AND tf.companionship != 0 AND ti.steward='$this->default_stewardship' ORDER BY tsp.priority ASC, ti.name ASC";
2692 $this->db->query($sql,__LINE__,__FILE__);
2694 $total_families=0; $families_with_yearly_visit=0;
2696 while ( $this->db->next_record()) {
2698 $id = $this->db->f('family');
2699 $name = $this->db->f('name');
2700 $phone = $this->db->f('phone');
2701 $vis_pri = $this->db->f('priority');
2702 $vis_notes = $this->db->f('notes');
2704 // If this family has had a yearly visit this year, don't show them on the schedule list
2705 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2706 $sql = "SELECT * FROM tc_visit WHERE date > '$year_start' AND date < '$year_end' ".
2707 "AND family=" . $id . " AND companionship=0";
2708 $this->db2->query($sql,__LINE__,__FILE__);
2710 if(!$this->db2->next_record()) {
2711 $sql = "SELECT * FROM tc_visit WHERE family=" . $id . " AND companionship=0 ORDER BY date DESC";
2712 $this->db3->query($sql,__LINE__,__FILE__);
2713 if($this->db3->next_record()) {
2714 $date = $this->db3->f('date');
2718 $link_data['menuaction'] = 'tc.tc.vis_update';
2719 $link_data['visit'] = '';
2720 $link_data['family'] = $id;
2721 $link_data['name'] = $name;
2722 $link_data['action'] = 'add';
2723 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2724 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2725 $table_data.= "<td align=center>$phone</td>";
2726 $table_data.= "<td align=center>";
2727 $table_data.= '<select name=vis_notes['.$id.'][pri]>';
2728 foreach(range(0,6) as $num) {
2729 if($num == 0) { $num = 1; } else {$num = $num*5; }
2730 if($vis_pri == $num) {
2731 $selected[$num] = 'selected="selected"';
2733 $selected[$num] = '';
2735 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2737 $table_data.= '</select></td>';
2738 $table_data.= "<td align=center>$date</td>";
2739 $table_data.= '<td><input type=text size="50" maxlength="128" name="vis_notes['.$id.'][notes]" value="'.$vis_notes.'">';
2740 $table_data.= '<input type=hidden name="vis_notes['.$id.'][family_id]" value="'.$id.'">';
2741 $table_data.= '<input type=hidden name="vis_notes['.$id.'][family_name]" value="'.$name.'">';
2742 $table_data.= '</td>';
2743 $table_data.= '</tr>';
2744 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2745 $this->t->set_var('tr_color',$tr_color);
2747 $link_data['menuaction'] = 'tc.tc.vis_update';
2748 $link_data['visit'] = $this->db2->f('visit');
2749 $link_data['family'] = $this->db2->f('family');
2750 $link_data['name'] = $name;
2751 $link_data['date'] = $this->db2->f('date');
2752 $link_data['action'] = 'view';
2753 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2754 $families_with_yearly_visit++;
2755 $date = $this->db2->f('date');
2756 $vis_notes = $this->db2->f('notes');
2757 if(strlen($vis_notes) > 40) { $vis_notes = stripslashes(substr($vis_notes,0,40) . "..."); }
2758 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2759 $completed_data.= "<td align=center>$phone</td>";
2760 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2761 $completed_data.= "<td align=left>$vis_notes</td>";
2762 $completed_data.= '</tr>';
2763 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
2764 $this->t->set_var('tr_color2',$tr_color2);
2768 $completed_header_row = "<th><font size=-2>Family Name</th>";
2769 $completed_header_row.= "<th><font size=-2>Phone</th>";
2770 $completed_header_row.= "<th><font size=-2>Date</th>";
2771 $completed_header_row.= "<th><font size=-2>Visit Notes</th>";
2773 $totals_header_row = "<th><font size=-2>Families</th>";
2774 $totals_header_row.= "<th><font size=-2>$year</th>";
2775 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2776 $totals_data.= "<td align=left><font size=-2><b>Total Families with yearly Visits completed:</b></font></td>";
2777 $totals_data.= "<td align=center><font size=-2><b>$families_with_yearly_visit / $total_families</b></font></td>";
2778 $percent = ceil(($families_with_yearly_visit / $total_families)*100);
2779 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2780 $this->t->set_var('tr_color',$tr_color);
2781 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2782 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2783 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2784 $totals_data.= "</tr>";
2786 $this->t->set_var('header_row',$header_row);
2787 $this->t->set_var('table_data',$table_data);
2788 $this->t->set_var('totals_header_row',$totals_header_row);
2789 $this->t->set_var('completed_header_row',$completed_header_row);
2790 $this->t->set_var('completed',$completed_data);
2791 $this->t->set_var('totals',$totals_data);
2792 $this->t->fp('familylist','family_list',True);
2793 $this->t->set_var('lang_save_appt','Save Appts');
2794 $this->t->set_var('lang_save_pri_notes','Save Pri / Notes');
2795 $this->t->fp('apptlist','appt_list',True);
2797 $this->t->pfp('out','vis_sched_t');
2798 $this->save_sessiondata();
2803 $this->t->set_file(array('ppi_view_t' => 'ppi_view.tpl'));
2804 $this->t->set_block('ppi_view_t','district_list','list');
2806 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2807 $num_months = get_var('num_months',array('GET','POST'));
2808 if($num_months == '') { $num_months = $this->default_ppi_num_months; }
2809 $this->t->set_var('num_months',$num_months);
2810 if($num_months == 1) {
2811 $this->t->set_var('lang_num_months','Month of History');
2813 $this->t->set_var('lang_num_months','Months of History');
2815 $this->t->set_var('lang_filter','Filter');
2816 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2818 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2819 $this->t->set_var('ppi_link_title',$this->ppi_frequency_label . ' PPIs');
2821 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
2822 $this->t->set_var('schedule_ppi_link_title','Schedule ' . $this->ppi_frequency_label . ' PPIs');
2824 $this->t->set_var('title',$this->ppi_frequency_label . ' PPIs');
2825 $num_months = get_var('num_months',array('GET','POST'));
2826 if($num_months == '') { $num_months = $this->default_ppi_num_years; }
2827 $this->t->set_var('num_months',$num_months);
2828 if($num_months == 1) {
2829 $this->t->set_var('lang_num_months','Year of History');
2831 $this->t->set_var('lang_num_months','Years of History');
2834 $sql = "SELECT * FROM tc_leader AS tl JOIN tc_individual AS ti WHERE tl.individual=ti.individual AND tl.type='P' AND tl.valid=1";
2835 $this->db->query($sql,__LINE__,__FILE__);
2836 if($this->db->next_record()) {
2837 $president_name = $this->db->f('name');
2838 $interviewer = $this->db->f('individual');
2840 print "<hr><font color=red><h3>-E- Unable to locate President in tc_leader table</h3></font></hr>";
2843 $this->t->set_var('district_number','*');
2844 $this->t->set_var('district_name',$president_name);
2846 $sql = "SELECT * FROM tc_individual AS ti JOIN tc_scheduling_priority as tsp where ti.scheduling_priority=tsp.scheduling_priority and ti.steward='$this->default_stewardship' and ti.valid=1 ORDER BY ti.individual ASC";
2847 $this->db->query($sql,__LINE__,__FILE__);
2849 while ($this->db->next_record()) {
2850 $individual[$i] = $this->db->f('individual');
2851 $indiv_name[$i] = $this->db->f('name');
2852 $indiv_phone[$individual[$i]] = $this->db->f('phone');
2853 $indiv_priority[$individual[$i]] = $this->db->f('priority');
2854 $indiv_notes[$individual[$i]] = $this->db->f('notes');
2858 array_multisort($indiv_name, $individual);
2859 //var_dump($indiv_name); print "<br><br>"; var_dump($individual);
2861 $header_row="<th width=$comp_width><font size=-2>Individual</th>";
2863 $indiv_width=400; $ppi_width=75; $table_width=$indiv_width + $num_months*$ppi_width;
2865 for($m=$num_months; $m >= 0; $m--) {
2866 $year = date('Y') - $m;
2867 $header_row .= "<th width=150><font size=-2>$year</th>";
2871 for ($j=0; $j < count($individual); $j++) {
2872 $id = $individual[$j];
2873 $name = $indiv_name[$j];
2874 $phone = $indiv_phone[$id];
2876 $link_data['menuaction'] = 'tc.tc.ppi_update';
2877 $link_data['interviewer'] = $interviewer;
2878 $link_data['individual'] = $id;
2879 $link_data['name'] = $name;
2880 $link_data['interview'] = '';
2881 $link_data['type'] = 'P';
2882 $link_data['action'] = 'add';
2883 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2884 $this->nextmatchs->template_alternate_row_color(&$this->t);
2885 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2887 // Find out how many times PPIs were performed in the past $num_months for this individual
2888 for($m=$num_months; $m >= 0; $m--) {
2889 $year = date('Y') - $m;
2890 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2891 $sql = "SELECT * FROM tc_interview WHERE date > '$year_start' AND date < '$year_end' ".
2892 "AND individual=" . $id . " AND type='P' ORDER BY date DESC";
2893 $this->db2->query($sql,__LINE__,__FILE__);
2895 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
2896 if($this->db2->next_record()) {
2897 $ppis[$m]++; $total_ppis[$m]++; $ppi_recorded[$companionship][$m]=1;
2898 $link_data['menuaction'] = 'tc.tc.ppi_update';
2899 $link_data['companionship'] = $companionship;
2900 $link_data['interviewer'] = $this->db2->f('interviewer');
2901 $link_data['indiv'] = $id;
2902 $link_data['name'] = $name;
2903 $link_data['interview'] = $this->db2->f('interview');
2904 $link_data['type'] = 'P';
2905 $link_data['action'] = 'view';
2906 $date = $this->db2->f('date');
2907 $date_array = explode("-",$date);
2908 $month = $date_array[1];
2909 $day = $date_array[2];
2910 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2911 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2913 $table_data .= "<td> </td>";
2916 $table_data .= "</tr>\n";
2918 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2920 $stat_data = "<tr><td><b><font size=-2>$total_indivs Individuals<br>PPI Totals:</font></b></td>";
2921 for($m=$num_months; $m >=0; $m--) {
2922 $percent = ceil(($ppis[$m] / $total_indivs)*100);
2923 $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
2925 $stat_data .= "</tr>";
2927 $this->t->set_var('table_width',$table_width);
2928 $this->t->set_var('header_row',$header_row);
2929 $this->t->set_var('table_data',$table_data);
2930 $this->t->set_var('stat_data',$stat_data);
2931 $this->t->pfp('out','ppi_view_t');
2932 $this->save_sessiondata();
2935 function ppi_update()
2937 $this->t->set_file(array('form' => 'ppi_update.tpl'));
2938 $this->t->set_block('form','interviewer_list','int_list');
2939 $this->t->set_block('form','add','addhandle');
2940 $this->t->set_block('form','edit','edithandle');
2942 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2943 $this->t->set_var('readonly','');
2944 $this->t->set_var('disabled','');
2946 $action = get_var('action',array('GET','POST'));
2947 $companionship = get_var('companionship',array('GET','POST'));
2948 $interviewer = get_var('interviewer',array('GET','POST'));
2949 $name = get_var('name',array('GET','POST'));
2950 $interview = get_var('interview',array('GET','POST'));
2951 $individual = get_var('individual',array('GET','POST'));
2952 $date = get_var('date',array('GET','POST'));
2953 $notes = get_var('notes',array('GET','POST'));
2954 $type = get_var('type',array('GET','POST'));
2956 $sql = "SELECT * FROM tc_leader AS tl JOIN tc_individual AS ti WHERE tl.individual=ti.individual AND tl.valid=1 AND ";
2957 if($this->yearly_ppi_interviewer == 1) { $sql .= " (tl.type='P')"; }
2958 if($this->yearly_ppi_interviewer == 2) { $sql .= " (tl.type='P' OR tl.type='C')"; }
2959 if($this->yearly_ppi_interviewer == 3) { $sql .= " (tl.type='P' OR tl.type='C' OR tl.type='S')"; }
2960 $this->db2->query($sql,__LINE__,__FILE__);
2961 while ($this->db2->next_record()) {
2962 $indiv = $this->db2->f('individual');
2963 $interviewer_name = $this->db2->f('name');
2964 if($indiv == $interviewer) {
2965 $this->t->set_var('interviewer',$indiv . ' selected');
2967 $this->t->set_var('interviewer',$indiv);
2969 #print "indiv: $indiv interviewer: $interviewer<br>";
2970 $this->t->set_var('interviewer_name',$interviewer_name);
2971 $this->t->set_var('eqpresppi_checked','checked');
2972 $this->t->fp('int_list','interviewer_list',True);
2974 #print "selected interviewer: $interviewer<br>";
2975 if($action == 'save') {
2976 $notes = get_var('notes',array('POST'));
2977 $this->db->query("UPDATE tc_interview set " .
2978 " interview='" . $interview . "'" .
2979 ", interviewer='" . $interviewer . "'" .
2980 ", individual='" . $individual . "'" .
2981 ", date='" . $date . "'" .
2982 ", notes=\"" . $notes . "\"" .
2983 ", type='" . $type . "'" .
2984 " WHERE interview=" . $interview,__LINE__,__FILE__);
2989 if($action == 'insert') {
2990 $notes = get_var('notes',array('POST'));
2991 $this->db->query("INSERT INTO tc_interview (interviewer,individual,date,notes,type) " .
2992 "VALUES ('" . $interviewer . "','" . $individual . "','" .
2993 $date . "',\"" . $notes . "\",'" . $type ."')",__LINE__,__FILE__);
2998 if($action == 'add') {
2999 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
3000 $this->t->set_var('interview', '');
3001 $this->t->set_var('interviewer', $interviewer);
3002 $this->t->set_var('name',$name);
3003 $this->t->set_var('individual',$individual);
3004 $this->t->set_var('date','');
3005 $this->t->set_var('notes','');
3006 $this->t->set_var('type',$type);
3007 $this->t->set_var('eqpresppi_checked','checked');
3008 $this->t->set_var('lang_done','Cancel');
3009 $this->t->set_var('lang_action','Adding New PPI');
3010 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview=' .
3011 $interview . '&action=' . 'insert'));
3014 if($action == 'edit' || $action == 'view') {
3015 $sql = "SELECT * FROM tc_interview WHERE interview=" . $interview . " AND type='P'";
3016 $this->db->query($sql,__LINE__,__FILE__);
3017 $this->db->next_record();
3018 $this->t->set_var('interview',$interview);
3019 $this->t->set_var('name',$name);
3020 $this->t->set_var('interviewer', $this->db->f('interviewer'));
3021 $this->t->set_var('individual',$this->db->f('individual'));
3022 $this->t->set_var('date',$this->db->f('date'));
3023 $this->t->set_var('notes',$this->db->f('notes'));
3024 $this->t->set_var('type',$this->db->f('type'));
3025 if($this->db->f('type') == 'P') { $this->t->set_var('eqpresppi_checked','checked'); }
3028 if($action == 'edit') {
3029 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
3030 $this->t->set_var('lang_done','Cancel');
3031 $this->t->set_var('lang_action','Editing PPI');
3032 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview='.
3033 $interview . '&action=' . 'save'));
3036 if($action == 'view') {
3037 $date = $this->db->f('date');
3038 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
3039 $this->t->set_var('readonly','READONLY');
3040 $this->t->set_var('disabled','DISABLED');
3041 $this->t->set_var('lang_done','Done');
3042 $this->t->set_var('lang_action','Viewing PPI');
3043 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview=' .
3044 $interview . '&action=' . 'edit'));
3047 $this->t->set_var('lang_reset','Clear Form');
3048 $this->t->set_var('lang_add','Add PPI');
3049 $this->t->set_var('lang_save','Save Changes');
3050 $this->t->set_var('edithandle','');
3051 $this->t->set_var('addhandle','');
3053 $this->t->pfp('out','form');
3055 if($action == 'view') { $this->t->set_var('lang_save','Edit PPI'); }
3056 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
3057 if($action == 'add') { $this->t->pfp('addhandle','add'); }
3059 $this->save_sessiondata();
3064 $this->t->set_file(array('int_view_t' => 'int_view.tpl'));
3065 $this->t->set_block('int_view_t','district_list','list');
3067 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
3068 $num_quarters = get_var('num_quarters',array('GET','POST'));
3069 if($num_quarters == '') { $num_quarters = $this->default_int_num_quarters; }
3070 $this->t->set_var('num_quarters',$num_quarters);
3071 if($num_quarters == 1) {
3072 $this->t->set_var('lang_num_quarters','Quarter of History');
3074 $this->t->set_var('lang_num_quarters','Quarters of History');
3076 $this->t->set_var('lang_filter','Filter');
3078 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
3079 $this->t->set_var('int_link_title','Hometeaching Interviews');
3081 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
3082 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
3084 $this->t->set_var('title','Hometeaching Interviews');
3086 $num_months = $num_quarters * 3 - 1;
3087 $current_month = $this->current_month;
3088 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
3089 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
3090 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
3091 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
3093 $sql = "SELECT * FROM tc_district AS td JOIN (tc_individual AS ti, tc_leader AS tl) WHERE td.leader=tl.leader AND tl.individual=ti.individual AND td.valid=1 ORDER BY td.district ASC";
3094 $this->db->query($sql,__LINE__,__FILE__);
3096 while ($this->db->next_record()) {
3097 $districts[$i]['district'] = $this->db->f('district');
3098 $districts[$i]['name'] = $this->db->f('name');
3099 $districts[$i]['leader'] = $this->db->f('leader');
3103 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
3104 $this->db->query($sql,__LINE__,__FILE__);
3106 while ($this->db->next_record()) {
3107 $individual[$i] = $this->db->f('individual');
3108 $indiv_name[$i] = $this->db->f('name');
3109 $indiv_phone[$individual[$i]] = $this->db->f('phone');
3112 array_multisort($indiv_name, $individual);
3113 for($i=0; $i < count($individual); $i++) {
3114 $id = $individual[$i];
3115 $indivs[$id] = $indiv_name[$i];
3118 $total_companionships = 0;
3119 $this->nextmatchs->template_alternate_row_color(&$this->t);
3120 for ($i=0; $i < count($districts); $i++) {
3121 $this->t->set_var('district_number',$districts[$i]['district']);
3122 $this->t->set_var('district_name',$districts[$i]['name']);
3123 $leader = $districts[$i]['leader'];
3125 // Select all the unique companionship numbers for this district
3126 $sql = "SELECT DISTINCT companionship FROM tc_companionship WHERE type='H' AND valid=1 AND district=". $districts[$i]['district'];
3127 $this->db->query($sql,__LINE__,__FILE__);
3128 $j=0; $unique_companionships = '';
3129 while ($this->db->next_record()) {
3130 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
3134 $comp_width=250; $int_width=75; $table_width=$comp_width + $num_months*$int_width;
3135 $table_data=""; $num_companionships = $j; $num_indivs = 0;
3136 for($m=$num_months; $m >= 0; $m--) { $ints[$m] = 0; }
3137 for ($j=0; $j < count($unique_companionships); $j++) {
3138 // Select all the companions in each companionship
3139 $sql = "SELECT * FROM tc_companion where valid=1 and ".
3140 "companionship=". $unique_companionships[$j]['companionship'];
3141 $this->db->query($sql,__LINE__,__FILE__);
3143 $comp = $unique_companionships[$j]['companionship'];
3144 for($m=$num_months; $m >= 0; $m--) { $int_recorded[$comp][$m] = 0; }
3145 while ($this->db->next_record()) {
3146 // Get this companions information
3148 $companionship = $this->db->f('companionship');
3149 $individual = $this->db->f('individual');
3150 $name = $indivs[$individual];
3151 $phone = $indiv_phone[$individual];
3152 $link_data['menuaction'] = 'tc.tc.int_update';
3153 $link_data['companionship'] = $companionship;
3154 $link_data['interviewer'] = $leader;
3155 $link_data['individual'] = $individual;
3156 $link_data['name'] = $name;
3157 $link_data['interview'] = '';
3158 $link_data['type'] = 'H';
3159 $link_data['action'] = 'add';
3160 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
3161 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
3163 // Find out how many times Interviews were performed in the past $num_months for this individual
3164 $header_row="<th width=$comp_width><font size=-2>Companionship</th>";
3165 for($m=$num_months; $m >= 0; $m--) {
3166 $month = $current_month - $m;
3167 $year = $this->current_year;
3169 $remainder = $month;
3170 $month = 12 + $remainder;
3173 if($month < 10) { $month = "0"."$month"; }
3174 $month_start = "$year"."-"."$month"."-"."01";
3175 $month_end = "$year"."-"."$month"."-"."31";
3176 $month = "$month"."/"."$year";
3177 $sql = "SELECT * FROM tc_interview WHERE date >= '$month_start' AND date <= '$month_end' ".
3178 "AND individual=" . $individual . " AND type='H' ORDER BY date DESC";
3179 $this->db2->query($sql,__LINE__,__FILE__);
3180 $header_row .= "<th width=$int_width><font size=-2>$month</th>";
3182 if(!$total_ints[$m]) { $total_ints[$m] = 0; }
3183 if($this->db2->next_record()) {
3184 if(!$int_recorded[$companionship][$m]) {
3187 $int_recorded[$companionship][$m]=1;
3189 $link_data['menuaction'] = 'tc.tc.int_update';
3190 $link_data['companionship'] = $companionship;
3191 $link_data['interviewer'] = $this->db2->f('interviewer');
3192 $link_data['individual'] = $individual;
3193 $link_data['name'] = $name;
3194 $link_data['interview'] = $this->db2->f('interview');
3195 $link_data['action'] = 'view';
3196 $link_data['type'] = 'H';
3197 $date = $this->db2->f('date');
3198 $date_array = explode("-",$date);
3199 $month = $date_array[1];
3200 $day = $date_array[2];
3201 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
3202 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
3205 $table_data .= "<td> </td>";
3208 $table_data .= "</tr>";
3211 $table_data .= "<tr><td colspan=20><hr></td></tr>";
3213 $total_companionships += $num_companionships;
3214 $stat_data = "<tr><td><b><font size=-2>$num_companionships Companionships<br>Interview Totals:</font></b></td>";
3216 // Print the hometeaching interview stats
3217 for($m=$num_months; $m >=0; $m--) {
3218 $month = $current_month - $m;
3219 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
3220 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
3221 //print "$month % $this->monthly_hometeaching_interview_stats = $month_begins <br>";
3222 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
3223 if(($month_begins) == 1) {
3226 $total += $ints[$m];
3228 $percent = ceil(($total / $num_companionships)*100);
3229 $stat_data .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
3231 $stat_data .= "</tr>";
3233 $this->t->set_var('table_width',$table_width);
3234 $this->t->set_var('header_row',$header_row);
3235 $this->t->set_var('table_data',$table_data);
3236 $this->t->set_var('stat_data',$stat_data);
3237 $this->t->fp('list','district_list',True);
3240 // Display the totals
3242 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>Interview Totals:</font></b></td>";
3243 for($m=$num_months; $m >=0; $m--) {
3244 $month = $current_month - $m;
3245 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
3246 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
3247 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
3248 if(($month_begins) == 1) {
3249 $total = $total_ints[$m];
3251 $total += $total_ints[$m];
3253 $percent = ceil(($total / $total_companionships)*100);
3254 $totals .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
3258 $this->t->set_var('totals',$totals);
3259 $this->t->pfp('out','int_view_t');
3260 $this->save_sessiondata();
3263 function int_update()
3265 $this->t->set_file(array('form' => 'int_update.tpl'));
3266 $this->t->set_block('form','interviewer_list','int_list');
3267 $this->t->set_block('form','add','addhandle');
3268 $this->t->set_block('form','edit','edithandle');
3270 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
3271 $this->t->set_var('readonly','');
3272 $this->t->set_var('disabled','');
3273 $this->t->set_var('eqpresppi','');
3275 $action = get_var('action',array('GET','POST'));
3276 $companionship = get_var('companionship',array('GET','POST'));
3277 $interviewer = get_var('interviewer',array('GET','POST'));
3278 $name = get_var('name',array('GET','POST'));
3279 $interview = get_var('interview',array('GET','POST'));
3280 $individual = get_var('individual',array('GET','POST'));
3281 $date = get_var('date',array('GET','POST'));
3282 $notes = get_var('notes',array('GET','POST'));
3283 $type = get_var('type',array('GET','POST'));
3285 $sql = "SELECT * FROM tc_leader AS tl JOIN (tc_individual AS ti, tc_district AS td) WHERE tl.individual=ti.individual AND tl.leader=td.leader AND tl.valid=1 AND (tl.type='P' OR tl.type='C' OR tl.type='D' OR td.district!=0)";
3286 $this->db2->query($sql,__LINE__,__FILE__);
3287 while ($this->db2->next_record()) {
3288 $indiv = $this->db2->f('individual');
3289 $interviewer_name = $this->db2->f('name');
3290 if($indiv == $interviewer) {
3291 $this->t->set_var('interviewer',$indiv . ' selected');
3293 $this->t->set_var('interviewer',$indiv);
3295 $this->t->set_var('interviewer_name',$interviewer_name);
3296 $this->t->fp('int_list','interviewer_list',True);
3299 if($action == 'save') {
3300 $notes = get_var('notes',array('POST'));
3301 $this->db->query("UPDATE tc_interview set " .
3302 " interview='" . $interview . "'" .
3303 ", interviewer='" . $interviewer . "'" .
3304 ", individual='" . $individual . "'" .
3305 ", date='" . $date . "'" .
3306 ", notes=\"" . $notes . "\"" .
3307 ", type='" . $type . "'" .
3308 " WHERE interview=" . $interview,__LINE__,__FILE__);
3313 if($action == 'insert') {
3314 $notes = get_var('notes',array('POST'));
3315 $this->db->query("INSERT INTO tc_interview (interviewer,individual,date,notes,type) " .
3316 "VALUES ('" . $interviewer . "','" . $individual . "','" .
3317 $date . "',\"" . $notes ."\",'" . $type . "')",__LINE__,__FILE__);
3322 if($action == 'add') {
3323 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
3324 $this->t->set_var('interview', '');
3325 $this->t->set_var('interviewer', $interviewer);
3326 $this->t->set_var('name',$name);
3327 $this->t->set_var('individual',$individual);
3328 $this->t->set_var('date','');
3329 $this->t->set_var('notes','');
3330 $this->t->set_var('type',$type);
3331 $this->t->set_var('lang_done','Cancel');
3332 $this->t->set_var('lang_action','Adding New Interview');
3333 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
3334 $interview . '&action=' . 'insert'));
3337 if($action == 'edit' || $action == 'view') {
3338 $sql = "SELECT * FROM tc_interview WHERE interview=" . $interview . " AND type='H'";
3339 $this->db->query($sql,__LINE__,__FILE__);
3340 $this->db->next_record();
3341 $this->t->set_var('interview',$interview);
3342 $this->t->set_var('name',$name);
3343 $this->t->set_var('interviewer', $this->db->f('interviewer'));
3344 $this->t->set_var('individual',$this->db->f('individual'));
3345 $this->t->set_var('date',$this->db->f('date'));
3346 $this->t->set_var('notes',$this->db->f('notes'));
3347 $this->t->set_var('type',$this->db->f('type'));
3348 if($this->db->f('type') == 'P') { $this->t->set_var('eqpresppi_checked','checked'); }
3351 if($action == 'edit') {
3352 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
3353 $this->t->set_var('lang_done','Cancel');
3354 $this->t->set_var('lang_action','Editing Interview');
3355 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
3356 $interview . '&action=' . 'save'));
3359 if($action == 'view') {
3360 $date = $this->db->f('date');
3361 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
3362 $this->t->set_var('readonly','READONLY');
3363 $this->t->set_var('disabled','DISABLED');
3364 $this->t->set_var('lang_done','Done');
3365 $this->t->set_var('lang_action','Viewing Interview');
3366 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
3367 $interview . '&action=' . 'edit'));
3370 $this->t->set_var('lang_reset','Clear Form');
3371 $this->t->set_var('lang_add','Add Interview');
3372 $this->t->set_var('lang_save','Save Changes');
3373 $this->t->set_var('edithandle','');
3374 $this->t->set_var('addhandle','');
3376 $this->t->pfp('out','form');
3378 if($action == 'view') { $this->t->set_var('lang_save','Edit Interview'); }
3379 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
3380 if($action == 'add') { $this->t->pfp('addhandle','add'); }
3382 $this->save_sessiondata();
3387 $this->t->set_file(array('vis_view_t' => 'vis_view.tpl'));
3388 $this->t->set_block('vis_view_t','visit_list','list1');
3389 $this->t->set_block('vis_view_t','family_list','list2');
3391 $this->t->set_var('lang_name','Family Name');
3392 $this->t->set_var('lang_date','Date');
3394 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
3395 $this->t->set_var('vis_link_title','View Yearly Visits');
3397 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
3398 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
3400 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
3401 $num_years = get_var('num_years',array('GET','POST'));
3402 if($num_years == '') { $num_years = $this->default_vis_num_years; }
3403 $this->t->set_var('num_years',$num_years);
3404 if($num_years == 1) {
3405 $this->t->set_var('lang_num_years','Year of History');
3407 $this->t->set_var('lang_num_years','Years of History');
3409 $this->t->set_var('lang_filter','Filter');
3411 $year = date('Y') - $num_years + 1;
3412 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
3414 $sql = "SELECT * FROM tc_visit WHERE companionship=0 and date > '$year_start' ORDER BY date DESC";
3415 $this->db->query($sql,__LINE__,__FILE__);
3416 $total_records = $this->db->num_rows();
3419 while ($this->db->next_record()) {
3420 $visit_list[$i]['visit'] = $this->db->f('visit');
3421 $visit_list[$i]['family'] = $this->db->f('family');
3422 $visit_list[$i]['date'] = $this->db->f('date');
3426 for ($i=0; $i < count($visit_list); $i++) {
3427 $this->nextmatchs->template_alternate_row_color(&$this->t);
3429 $sql = "SELECT * FROM tc_family AS tf JOIN tc_individual AS ti WHERE tf.individual=ti.individual AND tf.family=".$visit_list[$i]['family']." AND ti.steward='$this->default_stewardship'";
3430 $this->db->query($sql,__LINE__,__FILE__);
3431 $this->db->next_record();
3433 $this->t->set_var('family',$visit_list[$i]['family']);
3434 $this->t->set_var('family_name',$this->db->f('name'));
3435 $this->t->set_var('date',$visit_list[$i]['date']);
3437 $link_data['menuaction'] = 'tc.tc.vis_update';
3438 $link_data['visit'] = $visit_list[$i]['visit'];
3439 $link_data['name'] = $this->db->f('name');
3440 $link_data['date'] = $visit_list[$i]['date'];
3441 $link_data['action'] = 'view';
3442 $this->t->set_var('view',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3443 $this->t->set_var('lang_view','View');
3445 $link_data['menuaction'] = 'tc.tc.vis_update';
3446 $link_data['visit'] = $visit_list[$i]['visit'];
3447 $link_data['name'] = $this->db->f('name');
3448 $link_data['date'] = $visit_list[$i]['date'];
3449 $link_data['action'] = 'edit';
3450 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3451 $this->t->set_var('lang_edit','Edit');
3453 $this->t->fp('list1','visit_list',True);
3456 // List the families that are available to record a visit against
3457 $sql = "SELECT * FROM tc_family AS tf JOIN tc_individual AS ti WHERE tf.individual=ti.individual AND tf.companionship != 0 AND tf.valid=1 AND ti.steward='$this->default_stewardship'";
3458 $this->db->query($sql,__LINE__,__FILE__);
3459 $total_records = $this->db->num_rows();
3462 while ($this->db->next_record()) {
3463 $family_names[$i] = $this->db->f('name');
3464 $family_ids[$i] = $this->db->f('family');
3466 } array_multisort($family_names, $family_ids);
3468 for ($i=0; $i < count($family_names); $i++) {
3469 $link_data['menuaction'] = 'tc.tc.vis_update';
3470 $link_data['visit'] = '';
3471 $link_data['family'] = $family_ids[$i];
3472 $link_data['action'] = 'add';
3473 $link_data['name'] = $family_names[$i];
3474 $this->t->set_var('add',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3476 $this->t->set_var('name',$family_names[$i]);
3477 if(($i+1) % 3 == 0) {
3478 $this->t->set_var('table_sep',"</td></tr><tr>");
3480 $this->t->set_var('table_sep',"</td>");
3482 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
3484 $this->t->fp('list2','family_list',True);
3487 $this->t->pfp('out','vis_view_t');
3488 $this->save_sessiondata();
3491 function vis_update()
3493 $this->t->set_file(array('form' => 'vis_update.tpl'));
3494 $this->t->set_block('form','add','addhandle');
3495 $this->t->set_block('form','edit','edithandle');
3497 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
3498 $this->t->set_var('readonly','');
3499 $this->t->set_var('disabled','');
3501 $action = get_var('action',array('GET','POST'));
3502 $visit = get_var('visit',array('GET','POST'));
3503 $family = get_var('family',array('GET','POST'));
3504 $name = get_var('name',array('GET','POST'));
3505 $date = get_var('date',array('GET','POST'));
3506 $notes = get_var('notes',array('GET','POST'));
3509 if($action == 'save') {
3510 $notes = get_var('notes',array('POST'));
3511 $this->db->query("UPDATE tc_visit set " .
3512 " date='" . $date . "'" .
3513 ", notes=\"" . $notes . "\"" .
3514 " WHERE visit=" . $visit,__LINE__,__FILE__);
3519 if($action == 'insert') {
3520 $notes = get_var('notes',array('POST'));
3521 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes) " .
3522 "VALUES ('" . $family . "','" . $companionship . "','" .
3523 $date . "',\"" . $notes . "\")",__LINE__,__FILE__);
3528 if($action == 'add') {
3529 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
3530 $this->t->set_var('family', $family);
3531 $this->t->set_var('visit', '');
3532 $this->t->set_var('name', $name);
3533 $this->t->set_var('date','');
3534 $this->t->set_var('notes','');
3535 $this->t->set_var('lang_done','Cancel');
3536 $this->t->set_var('lang_action','Adding New Visit');
3537 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&family=' .
3538 $family . '&action=' . 'insert'));
3541 if($action == 'edit' || $action == 'view') {
3542 $sql = "SELECT * FROM tc_visit WHERE visit=".$visit;
3543 $this->db->query($sql,__LINE__,__FILE__);
3544 $this->db->next_record();
3545 $this->t->set_var('visit',$visit);
3546 $this->t->set_var('name',$name);
3547 $this->t->set_var('family', $family);
3548 $this->t->set_var('date',$this->db->f('date'));
3549 $this->t->set_var('notes',$this->db->f('notes'));
3552 if($action == 'edit') {
3553 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
3554 $this->t->set_var('lang_done','Cancel');
3555 $this->t->set_var('lang_action','Editing Visit');
3556 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit=' .
3557 $visit . '&action=' . 'save'));
3560 if($action == 'view') {
3561 $date = $this->db->f('date');
3562 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
3563 $this->t->set_var('readonly','READONLY');
3564 $this->t->set_var('disabled','DISABLED');
3565 $this->t->set_var('lang_done','Done');
3566 $this->t->set_var('lang_action','Viewing Visit');
3567 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit=' .
3568 $visit . '&action=' . 'edit'));
3571 $this->t->set_var('lang_reset','Clear Form');
3572 $this->t->set_var('lang_add','Add Visit');
3573 $this->t->set_var('lang_save','Save Changes');
3574 $this->t->set_var('edithandle','');
3575 $this->t->set_var('addhandle','');
3577 $this->t->pfp('out','form');
3579 if($action == 'view') { $this->t->set_var('lang_save','Edit Visit'); }
3580 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
3581 if($action == 'add') { $this->t->pfp('addhandle','add'); }
3583 $this->save_sessiondata();
3588 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3589 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3590 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3592 $this->t->set_file(array('att_view_t' => 'att_view.tpl'));
3593 $this->t->set_block('att_view_t','act_list','list');
3595 $this->t->set_block('att_view_t','month_list','list1');
3596 $this->t->set_block('att_view_t','header_list','list2');
3597 $this->t->set_block('att_view_t','individual_list','list3');
3599 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3600 $num_quarters = get_var('num_quarters',array('GET','POST'));
3601 if($num_quarters == '') { $num_quarters = $this->default_att_num_quarters; }
3602 $this->t->set_var('num_quarters',$num_quarters);
3603 $this->t->set_var('lang_filter','Filter');
3604 if($num_quarters == 1) {
3605 $this->t->set_var('lang_num_quarters','Quarter of History');
3607 $this->t->set_var('lang_num_quarters','Quarters of History');
3610 $num_months = $num_quarters * 3;
3611 $current_month = $this->current_month;
3612 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
3613 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
3614 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
3615 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
3617 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
3618 $this->db->query($sql,__LINE__,__FILE__);
3620 while ($this->db->next_record()) {
3621 $individual_name[$i] = $this->db->f('name');
3622 $individual[$i] = $this->db->f('individual');
3625 array_multisort($individual_name, $individual);
3627 // Create a list of sunday dates for a window of 3 months back and current month
3631 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, ($current_month-$num_months)+1, 1, date("y")));
3632 $last_date = explode("-",$sunday_list[0]['date']);
3633 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3634 $time_limit = mktime(0, 0, 0, $current_month, 31, date("y"));
3635 while($last_time < $time_limit) {
3636 $day = date("w",$last_time);
3637 if(date("w",$last_time) == 0) {
3638 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3639 $last_date = explode("-",$sunday_list[$i]['date']);
3640 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3641 $sunday_list[$i]['day'] = $last_date[2];
3642 $sunday_list[$i]['month'] = date("M",$last_time);
3643 $sunday_list[$i]['year'] = $last_date[0];
3645 $last_date = $sunday_list[$i]['date'];
3647 $last_time += 90000;
3648 if($found_sunday) { $i++; $found_sunday=0; }
3651 $total_individuals = count($individual);
3652 $old_month=$sunday_list[0]['month']; $span=0;
3653 for ($i=0; $i < count($sunday_list); $i++) {
3654 $date = $sunday_list[$i]['date'];
3655 $this->t->set_var('date',$sunday_list[$i]['date']);
3656 $this->t->set_var('day',$sunday_list[$i]['day']);
3657 if(($old_month != $sunday_list[$i]['month']) || $i == count($sunday_list)-1) {
3658 if($i == count($sunday_list)-1) { $span++; }
3659 $cur_month = $sunday_list[$i]['month'];
3660 $old_month = $sunday_list[$i]['month'];
3661 $link_data['menuaction'] = 'tc.tc.att_update';
3662 $link_data['month'] = $sunday_list[$i-1]['month'];
3663 $link_data['year'] = $sunday_list[$i-1]['year'];
3664 $link_data['action'] = 'update_month';
3665 $cur_month = $sunday_list[$i-1]['month'];
3666 $cur_year = $sunday_list[$i-1]['year'];
3667 $header_row .= "<th><font size=-3>$cur_month $cur_year</font></th>";
3668 $this->t->set_var('update_month',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3669 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3670 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3671 $this->t->set_var('span',$span); $span=0;
3672 $this->t->fp('list1','month_list',True);
3676 $this->t->set_var('total_individuals',$total_individuals);
3677 $this->t->set_var('header_row',$header_row);
3679 $individual_width=200; $att_width=25; $total_width=$individual_width;
3680 for ($i=0; $i < count($sunday_list); $i++) {
3681 $link_data['menuaction'] = 'tc.tc.att_update';
3682 $link_data['month'] = $sunday_list[$i]['month'];
3683 $link_data['year'] = $sunday_list[$i]['year'];
3684 $link_data['day'] = $sunday_list[$i]['day'];
3685 $link_data['date'] = $sunday_list[$i]['date'];
3686 $link_data['action'] = 'update_day';
3687 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3688 $this->t->set_var('date',$sunday_list[$i]['date']);
3689 $this->t->set_var('day',$sunday_list[$i]['day']);
3690 $this->t->set_var('month',$sunday_list[$i]['month']);
3691 $this->t->set_var('year',$sunday_list[$i]['year']);
3692 $this->t->fp('list2','header_list',True);
3693 $total_width += $att_width;
3694 $attendance[$monthnum[$sunday_list[$i]['month']]]=0;
3697 for ($i=0; $i < count($individual); $i++) {
3699 $this->nextmatchs->template_alternate_row_color(&$this->t);
3700 $this->t->set_var('individual_name',$individual_name[$i]);
3701 #print "checking for individual: " . $individual[$i] . "<br>";
3702 for ($j=0; $j < count($sunday_list); $j++) {
3703 #print "checking for date: " . $sunday_list[$j]['date'] . "<br>";
3704 #print "SELECT * FROM tc_attendance WHERE date='"
3705 # . $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i] . "<br>";
3706 $sql = "SELECT * FROM tc_attendance WHERE date='" .
3707 $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i];
3708 $this->db->query($sql,__LINE__,__FILE__);
3709 if($this->db->next_record()) {
3710 $cur_month = $sunday_list[$j]['month'];
3711 if($attended[$i][$cur_month] != 1) {
3712 $attended[$i][$cur_month]=1;
3713 $attendance[$monthnum[$cur_month]]++;
3715 $att_table .= '<td align=center><img src="images/checkmark.gif"></td>';
3717 $att_table .= '<td> </td>';
3720 $this->t->set_var('att_table',$att_table);
3721 $this->t->fp('list3','individual_list',True);
3723 $this->t->set_var('total_width',$total_width);
3724 $this->t->set_var('individual_width',$individual_width);
3725 $this->t->set_var('att_width',$att_width);
3727 # Now calculate attendance for these months
3728 $attendance_str = "";
3729 $nonattendance_str = "";
3730 $aveattendance_str = "";
3731 $avenonattendance_str = "";
3733 $ave_total_attended=0;
3735 foreach($attendance as $att => $value) {
3736 $total_attended = $attendance[$att];
3737 $ave_total_attended += $attendance[$att]; $num_months++;
3738 $percent = ceil(($total_attended / $total_individuals)*100);
3739 $attendance_str.="<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3740 $total_nonattended = $total_individuals - $total_attended;
3741 $percent = ceil(($total_nonattended / $total_individuals)*100);
3742 $nonattendance_str.="<td align=center><font size=-2><b>$total_nonattended ($percent%)</b></font></td>";
3744 $total_attended = ceil(($ave_total_attended / $num_months));
3745 $percent = ceil(($total_attended / $total_individuals)*100);
3746 $aveattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3747 $total_attended = $total_individuals - ceil(($ave_total_attended / $num_months));
3748 $percent = ceil(($total_attended / $total_individuals)*100);
3749 $avenonattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3752 $this->t->set_var('attendance',$attendance_str);
3753 $this->t->set_var('aveattendance',$aveattendance_str);
3754 $this->t->set_var('nonattendance',$nonattendance_str);
3755 $this->t->set_var('avenonattendance',$avenonattendance_str);
3757 $this->t->pfp('out','att_view_t');
3758 $this->save_sessiondata();
3761 function att_update()
3763 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3764 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3765 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3767 $this->t->set_file(array('form' => 'att_update.tpl'));
3768 $this->t->set_block('form','edit','edithandle');
3770 $this->t->set_block('form','month_list','list1');
3771 $this->t->set_block('form','header_list','list2');
3772 $this->t->set_block('form','individual_list','list3');
3774 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3776 $action = get_var('action',array('GET','POST'));
3777 $month = get_var('month',array('GET','POST'));
3778 $year = get_var('year',array('GET','POST'));
3779 $day = get_var('day',array('GET','POST'));
3780 $date = get_var('date',array('GET','POST'));
3782 if($action == 'save_month' || $action == 'save_day') {
3783 $new_data = get_var('individuals_attended',array('POST'));
3784 $month = $monthnum[$month]; if($month < 10) { $month = "0" . $month; }
3786 if($action == 'save_month') {
3787 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-%'",__LINE__,__FILE__);
3790 if($action == 'save_day') {
3791 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-".$day."'",__LINE__,__FILE__);
3794 foreach ($new_data as $data) {
3795 $data_array = explode("-",$data);
3796 $indiv = $data_array[0];
3797 $date = "$data_array[1]-$data_array[2]-$data_array[3]";
3798 $this->db->query("INSERT INTO tc_attendance (individual,date) " .
3799 "VALUES (" . $indiv . ",'". $date . "')",__LINE__,__FILE__);
3806 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
3807 $this->db->query($sql,__LINE__,__FILE__);
3809 while ($this->db->next_record()) {
3810 $indiv_name[$i] = $this->db->f('name');
3811 $individual[$i] = $this->db->f('individual');
3812 $indiv_attending[$individual[$i]] = $this->db->f('attending');
3815 array_multisort($indiv_name, $individual);
3817 if($action == 'update_month') {
3818 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_month'));
3822 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], 1, $year));
3823 $last_date = explode("-",$sunday_list[0]['date']);
3824 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3825 $time_limit = mktime(0, 0, 0, $monthnum[$month], 31, $year);
3826 while($last_time <= $time_limit) {
3827 $day = date("w",$last_time);
3828 if(date("w",$last_time) == 0) {
3829 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3830 $last_date = explode("-",$sunday_list[$i]['date']);
3831 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3832 $sunday_list[$i]['day'] = $last_date[2];
3833 $sunday_list[$i]['month'] = date("M",$last_time);
3834 $sunday_list[$i]['year'] = $last_date[0];
3837 $last_time += 90000;
3838 if($found_sunday) { $i++; $found_sunday=0; }
3841 $this->t->set_var('span', $i);
3842 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3843 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3844 $this->t->fp('list1','month_list',True);
3845 $indiv_width=200; $att_width=25; $total_width=$indiv_width;
3846 for ($i=0; $i < count($sunday_list); $i++) {
3847 $link_data['menuaction'] = 'tc.tc.att_update';
3848 $link_data['month'] = $sunday_list[$i]['month'];
3849 $link_data['year'] = $sunday_list[$i]['year'];
3850 $link_data['day'] = $sunday_list[$i]['day'];
3851 $link_data['date'] = $sunday_list[$i]['date'];
3852 $link_data['action'] = 'update_day';
3853 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3854 $this->t->set_var('date',$sunday_list[$i]['date']);
3855 $this->t->set_var('day',$sunday_list[$i]['day']);
3856 $this->t->set_var('month',$sunday_list[$i]['month']);
3857 $this->t->set_var('year',$sunday_list[$i]['year']);
3858 $this->t->fp('list2','header_list',True);
3859 $total_width += $att_width;
3863 if($action == 'update_day') {
3864 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_day'));
3865 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], $day, $year));
3866 $this->t->set_var('month',$month);
3867 $this->t->set_var('year',$year);
3868 $this->t->fp('list1','month_list',True);
3869 $this->t->set_var('date',$date);
3870 $this->t->set_var('day',$day);
3871 $this->t->set_var('month',$month);
3872 $this->t->set_var('year',$year);
3873 $this->t->fp('list2','header_list',True);
3876 for ($i=0; $i < count($individual); $i++) {
3878 $this->nextmatchs->template_alternate_row_color(&$this->t);
3879 $this->t->set_var('individual_name',$indiv_name[$i]);
3880 for ($j=0; $j < count($sunday_list); $j++) {
3881 $sql = "SELECT * FROM tc_attendance WHERE date='" .
3882 $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i];
3883 $this->db->query($sql,__LINE__,__FILE__);
3884 $value = $individual[$i] . "-" . $sunday_list[$j]['date'];
3885 if($this->db->next_record()) {
3886 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'" checked></td>';
3887 } else if($indiv_attending[$individual[$i]] == 1) {
3888 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'" checked></td>';
3890 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'"></td>';
3893 $this->t->set_var('att_table',$att_table);
3894 $this->t->fp('list3','individual_list',True);
3897 $this->t->set_var('lang_done', 'Cancel');
3898 $this->t->set_var('lang_reset','Clear Form');
3899 $this->t->set_var('lang_save','Save Changes');
3901 $this->t->pfp('out','form');
3902 $this->t->pfp('addhandle','edit');
3904 $this->save_sessiondata();
3909 $this->t->set_file(array('dir_view_t' => 'dir_view.tpl'));
3910 $this->t->set_block('dir_view_t','dir_list','list');
3912 $sql = "SELECT * FROM tc_individual where valid=1 and hh_position='Head of Household' ORDER BY name ASC";
3913 $this->db->query($sql,__LINE__,__FILE__);
3915 while ($this->db->next_record()) {
3916 $parent[$i]['id'] = $this->db->f('individual');
3917 $parent[$i]['name'] = $this->db->f('name');
3918 $parent[$i]['phone'] = $this->db->f('phone');
3919 $parent[$i]['address'] = $this->db->f('address');
3923 for ($i=0; $i < count($parent); $i++) {
3924 $name = $parent[$i]['name'];
3925 $phone = $parent[$i]['phone'];
3926 $address = $parent[$i]['address'];
3927 $this->t->set_var('name', $name);
3928 $this->t->set_var('address', $address);
3929 $this->t->set_var('phone', $phone);
3930 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3931 $this->t->set_var('tr_color',$tr_color);
3932 $this->t->fp('list','dir_list',True);
3933 //print "$phone $name $address<br>";
3935 $this->t->pfp('out','dir_view_t');
3936 $this->save_sessiondata();
3941 $this->t->set_file(array('org_view_t' => 'org_view.tpl'));
3942 $this->t->set_block('org_view_t','calling_list','list');
3943 $this->t->set_var('jquery_url',$this->jquery_url);
3944 $this->t->set_var('jquery_tablesorter_url',$this->jquery_tablesorter_url);
3946 $sql = "SELECT * FROM tc_calling AS tc JOIN tc_individual AS ti where tc.individual=ti.individual ORDER BY name ASC";
3947 $this->db->query($sql,__LINE__,__FILE__);
3949 while ($this->db->next_record()) {
3950 $calling[$i]['name'] = $this->db->f('name');
3951 $calling[$i]['position'] = $this->db->f('position');
3952 $calling[$i]['sustained'] = $this->db->f('sustained');
3953 $calling[$i]['organization'] = $this->db->f('organization');
3956 for ($i=0; $i < count($calling); $i++) {
3957 $name = $calling[$i]['name'];
3958 $position = $calling[$i]['position'];
3959 $sustained = $calling[$i]['sustained'];
3960 $organization = $calling[$i]['organization'];
3961 $this->t->set_var('name', $name);
3962 $this->t->set_var('position', $position);
3963 $this->t->set_var('sustained', $sustained);
3964 $this->t->set_var('organization', $organization);
3965 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3966 $this->t->set_var('tr_color',$tr_color);
3967 $this->t->fp('list','calling_list',True);
3970 $this->t->pfp('out','org_view_t');
3971 $this->save_sessiondata();
3976 $this->t->set_file(array('sched_t' => 'schedule.tpl'));
3977 $this->t->set_block('sched_t','leader_list','list');
3979 $action = get_var('action',array('GET','POST'));
3981 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule&action=save'));
3982 $this->t->set_var('title','Scheduling Tool');
3984 $this->t->set_var('lang_save','Save Schedule');
3985 $this->t->set_var('lang_reset','Cancel');
3987 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
3988 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
3990 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
3991 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
3993 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
3994 $this->t->set_var('schedule_ppi_link_title','Schedule ' . $this->ppi_frequency_label . ' PPIs');
3996 $date_width=160; $time_width=220; $indiv_width=170; $family_width=180; $location_width=100;
3997 $table_width=$date_width + $time_width + $indiv_width + $family_width + $location_width;
3998 $header_row = "<th width=$date_width><font size=-2>Date</th>";
3999 $header_row.= "<th width=$time_width><font size=-2>Time</th>";
4000 $header_row.= "<th width=$indiv_width><font size=-2>Individual</th>";
4001 $header_row.= "<th width=$family_width><font size=-2>Family</th>";
4002 $header_row.= "<th width=$location_width><font size=-2>Location</th>";
4005 $sql = "SELECT * FROM tc_leader AS tl JOIN tc_individual AS ti WHERE tl.individual=ti.individual AND tl.valid=1 GROUP BY tl.individual ORDER BY ti.name ASC";
4006 $this->db->query($sql,__LINE__,__FILE__);
4008 while ($this->db->next_record()) {
4009 $leader_data[$i]['id'] = $this->db->f('leader');
4010 $leader_data[$i]['name'] = $this->db->f('name');
4011 $leader_data[$i]['indiv'] = $this->db->f('individual');
4012 $leader2name[$leader_data[$i]['id']] = $leader_data[$i]['name'];
4013 $leader2indiv[$leader_data[$i]['id']] = $leader_data[$i]['indiv'];
4017 $sql = "SELECT * FROM tc_family AS tf JOIN tc_individual AS ti WHERE tf.individual=ti.individual AND ti.steward='$this->default_stewardship' AND tf.valid=1 AND tf.individual != 0 ORDER BY ti.name ASC";
4018 $this->db->query($sql,__LINE__,__FILE__);
4020 while ($this->db->next_record()) {
4021 $family_id[$i] = $this->db->f('family');
4022 $family_name[$i] = $this->db->f('name');
4023 $familyid2name[$family_id[$i]] = $family_name[$i];
4024 $familyid2address[$family_id[$i]] = $this->db->f('address');
4027 array_multisort($family_name, $family_id);
4029 if($action == 'save') {
4030 $new_data = get_var('sched',array('POST'));
4031 foreach ($new_data as $leader_array) {
4032 foreach ($leader_array as $entry) {
4033 $leader = $entry['leader'];
4034 $appointment = $entry['appointment'];
4035 $location = $entry['location'];
4036 $date = $entry['date'];
4037 $hour = $entry['hour'];
4038 $minute = $entry['minute'];
4040 $indiv = $entry['individual'];
4041 $family = $entry['family'];
4042 $location = $entry['location'];
4043 if($pm) { $hour = $hour + 12; }
4044 $time = $hour.':'.$minute.':'.'00';
4047 // Zero out family or individual if they are invalid
4048 if($indiv == "") { $indiv=0; }
4049 if($family == "") { $family=0; }
4051 // Update our location
4052 if($location == "") {
4054 $family_name_array = explode(",", $familyid2name[$family]);
4055 $family_last_name = $family_name_array[0];
4056 $family_address = $familyid2address[$family];
4057 $location = "$family_last_name"." home ($family_address)";
4058 } else if($indiv > 0) {
4059 $leader_name_array = explode(",",$leader2name[$leader]);
4060 $leader_last_name = $leader_name_array[0];
4061 #print "leader2indiv: $leader $leader2indiv[$leader]<br>";
4062 $sql = "SELECT * FROM tc_individual where individual='$leader2indiv[$leader]'";
4063 $this->db2->query($sql,__LINE__,__FILE__);
4064 if($this->db2->next_record()) {
4065 $leader_address = $this->db2->f('address');
4067 $location = "$leader_last_name"." home ($leader_address)";
4071 // Zero out the family or individual if date = NULL
4078 if(($indiv == 0) && ($family == 0)) { $location = ""; }
4080 // Update an existing appointment
4081 if($appointment < $this->max_appointments)
4083 // If we deleted the appointment, we still need to send a cancellation to the right people
4084 // Make a note of the old email now in case we need it later
4085 $old_indiv_email = "";
4086 $sql = "SELECT * FROM tc_appointment where appointment='$appointment'";
4087 $this->db->query($sql,__LINE__,__FILE__);
4088 if($this->db->next_record()) {
4089 $old_individual = $this->db->f('individual');
4090 $old_family = $this->db->f('family');
4091 if($old_individual > 0) {
4092 $sql = "SELECT * FROM tc_individual where individual='$old_individual'";
4093 $this->db2->query($sql,__LINE__,__FILE__);
4094 if($this->db2->next_record()) {
4095 $old_indiv_email = $this->db2->f('email');
4098 if($old_family > 0) {
4099 $sql = "SELECT * FROM tc_family WHERE family='$old_family'";
4100 $this->db2->query($sql,__LINE__,__FILE__);
4101 if($this->db2->next_record()) {
4102 $old_individual = $this->db2->f('individual');
4103 $sql = "SELECT * FROM tc_individual where individual='$old_individual'";
4104 $this->db3->query($sql,__LINE__,__FILE__);
4105 if($this->db3->next_record()) {
4106 $old_indiv_email = $this->db3->f('email');
4112 //Only perform a database update if we have made a change to this appointment
4113 $sql = "SELECT * FROM tc_appointment where " .
4114 "appointment='$appointment'" .
4115 " and leader='$leader'" .
4116 " and individual='$indiv'" .
4117 " and family='$family'" .
4118 " and date='$date'" .
4119 " and time='$time'" .
4120 " and location='$location'";
4121 $this->db->query($sql,__LINE__,__FILE__);
4122 if(!$this->db->next_record()) {
4123 $old_date = $this->db->f('date');
4124 $old_time = $this->db->f('time');
4125 $this->db2->query("UPDATE tc_appointment set" .
4126 " family=" . $family .
4127 " ,individual=" . $indiv .
4128 " ,date='" . $date . "'" .
4129 " ,time='" . $time . "'" .
4130 " ,location='" . $location . "'" .
4131 " ,leader='" . $leader . "'" .
4132 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4134 // Email the appointment
4135 $this->email_appt($appointment, $old_indiv_email);
4139 // Add a new appointment
4140 else if(($appointment >= $this->max_appointments) && ($date != "") && ($time != ""))
4142 //print "adding entry: appt=$appointment date: $date time: $time individual: $indiv family: $family<br>";
4143 $this->db2->query("INSERT INTO tc_appointment (appointment,leader,family,individual,date,time,location,uid) " .
4144 "VALUES (NULL,'" . $leader . "','" . $family . "','" . $indiv . "','" .
4145 $date . "','" . $time . "','" . $location . "','" . $uid ."')",__LINE__,__FILE__);
4147 // Now reselect this entry from the database to see if we need
4148 // to send an appointment out for it.
4149 $sql = "SELECT * FROM tc_appointment where " .
4150 "individual='$indiv'" .
4151 " and family='$family'" .
4152 " and leader='$leader'" .
4153 " and date='$date'" .
4154 " and time='$time'" .
4156 " and location='$location'";
4157 $this->db3->query($sql,__LINE__,__FILE__);
4158 if($this->db3->next_record()) {
4159 // Email the appointment if warranted
4160 if(($date != "") && ($time != "") && (($indiv > 0) || $family > 0)) {
4161 $this->email_appt($this->db3->f('appointment'));
4168 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule');
4169 //Header('Location: ' . $take_me_to_url);
4172 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY individual ASC";
4173 $this->db->query($sql,__LINE__,__FILE__);
4175 while ($this->db->next_record()) {
4176 $individual[$i] = $this->db->f('individual');
4177 $indiv_name[$i] = $this->db->f('name');
4178 $indiv_phone[$individual[$i]] = $this->db->f('phone');
4181 array_multisort($indiv_name, $individual);
4183 for ($i=0; $i < count($leader_data); $i++) {
4184 $leader = $leader_data[$i]['id'];
4185 $interviewer = $leader_data[$i]['individual'];
4186 $name = $leader_data[$i]['name'];
4187 $this->t->set_var('leader_name',$name);
4190 // query the database for all the appointments
4191 $sql = "SELECT * FROM tc_appointment where leader=$leader and date>=CURDATE() ORDER BY date ASC, time ASC";
4192 $this->db->query($sql,__LINE__,__FILE__);
4194 // Prefill any existing appointment slots
4195 while ($this->db->next_record()) {
4196 $appointment = $this->db->f('appointment');
4197 $indiv = $this->db->f('individual');
4198 $family = $this->db->f('family');
4199 $location = $this->db->f('location');
4201 if($location == "") {
4203 $family_name_array = explode(",", $familyid2name[$family]);
4204 $family_last_name = $family_name_array[0];
4205 $family_address = $familyid2address[$family];
4206 $location = "$family_last_name"." home ($family_address)";
4207 } else if($indiv > 0) {
4208 $leader_name_array = explode(",",$leader2name[$leader]);
4209 $leader_last_name = $leader_name_array[0];
4210 $sql = "SELECT * FROM tc_individual where individual='$leader2indiv[$leader]'";
4211 $this->db2->query($sql,__LINE__,__FILE__);
4212 if($this->db2->next_record()) {
4213 $leader_address = $this->db2->f('address');
4215 $location = "$leader_last_name"." home ($leader_address)";
4219 $date = $this->db->f('date');
4220 $date_array = explode("-",$date);
4221 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
4222 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
4224 $time = $this->db->f('time');
4225 $time_array = explode(":",$time);
4226 $hour = $time_array[0];
4227 $minute = $time_array[1];
4229 if($hour > 12) { $pm=1; $hour = $hour - 12; }
4230 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
4232 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4235 $table_data.= '<td align=left>';
4236 $table_data.= $this->jscal->input('sched['.$leader.']['.$appointment.'][date]',$date,'','','','','',$this->cal_options);
4237 $table_data.= '</td>';
4239 // Hour & Minutes selection
4240 $table_data.= "<td align=center>";
4241 $table_data .= $this->get_time_selection_form($hour, $minute, $pm, $leader, $appointment);
4242 $table_data.= "</td>";
4244 // individual drop down list (for PPIs)
4245 $table_data.= '<td align=center><select name=sched['.$leader.']['.$appointment.'][individual] STYLE="font-size : 8pt">';
4246 $table_data.= '<option value=0></option>';
4247 for ($j=0; $j < count($individual); $j++) {
4248 $id = $individual[$j];
4249 $name = $indiv_name[$j];
4250 if($individual[$j] == $indiv) {
4251 $selected[$id] = 'selected="selected"';
4253 $selected[$id] = '';
4255 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
4257 $table_data.='</select></td>';
4259 // Family drop down list (for Visits)
4260 $table_data.= '<td align=center><select name=sched['.$leader.']['.$appointment.'][family] STYLE="font-size : 8pt">';
4261 $table_data.= '<option value=0></option>';
4262 for ($j=0; $j < count($individual); $j++) {
4263 $id = $family_id[$j];
4264 $name = $family_name[$j];
4265 if($family_id[$j] == $family) {
4266 $selected[$id] = 'selected="selected"';
4268 $selected[$id] = '';
4270 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
4272 $table_data.='</select></td>';
4274 // Location text box
4275 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
4276 $table_data.= 'name="sched['.$leader.']['.$appointment.'][location]" value="'.$location.'" STYLE="font-size : 8pt">';
4278 $table_data.= '<input type=hidden name="sched['.$leader.']['.$appointment.'][appointment]" value="'.$appointment.'">';
4279 $table_data.= '<input type=hidden name="sched['.$leader.']['.$appointment.'][leader]" value="'.$leader.'">';
4281 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4282 $this->t->set_var('tr_color',$tr_color);
4285 // Create blank appointment slot
4286 for ($b=0; $b < 4; $b++) {
4287 $appointment = $this->max_appointments + $b;
4288 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4291 $table_data.= '<td align=left>';
4292 $table_data.= $this->jscal->input('sched['.$leader.']['.$appointment.'][date]','','','','','','',$this->cal_options);
4293 $table_data.= '</td>';
4296 $table_data.= "<td align=center>";
4297 $table_data .= $this->get_time_selection_form(0, 0, 0, $leader, $appointment);
4298 $table_data.= "</td>";
4300 // individual drop down list
4301 $table_data.= '<td align=center><select name=sched['.$leader.']['.$appointment.'][individual] STYLE="font-size : 8pt">';
4302 $table_data.= '<option value=0></option>';
4303 for ($j=0; $j < count($individual); $j++) {
4304 $id = $individual[$j];
4305 $name = $indiv_name[$j];
4306 $table_data.= '<option value='.$id.'>'.$name.'</option>';
4308 $table_data.='</select></td>';
4310 // Family drop down list
4311 $table_data.= '<td align=center><select name=sched['.$leader.']['.$appointment.'][family] STYLE="font-size : 8pt">';
4312 $table_data.= '<option value=0></option>';
4313 for ($j=0; $j < count($individual); $j++) {
4314 $id = $family_id[$j];
4315 $name = $family_name[$j];
4316 $table_data.= '<option value='.$id.'>'.$name.' Family</option>';
4318 $table_data.='</select></td>';
4320 // Location text box
4321 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
4322 $table_data.= 'name="sched['.$leader.']['.$appointment.'][location]" value="" STYLE="font-size : 8pt">';
4324 $table_data.= '<input type=hidden name="sched['.$leader.']['.$appointment.'][appointment]" value="'.$appointment.'">';
4325 $table_data.= '<input type=hidden name="sched['.$leader.']['.$appointment.'][leader]" value="'.$leader.'">';
4327 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4328 $this->t->set_var('tr_color',$tr_color);
4331 $this->t->set_var('table_data',$table_data);
4332 $this->t->set_var('header_row',$header_row);
4333 $this->t->set_var('table_width',$table_width);
4334 $this->t->fp('list','leader_list',True);
4337 $this->t->pfp('out','sched_t');
4338 $this->save_sessiondata();
4343 $this->t->set_file(array('email_t' => 'email.tpl'));
4344 $this->t->set_block('email_t','individual_list','list');
4346 $action = get_var('action',array('GET','POST'));
4348 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email'));
4349 $this->t->set_var('title','Email Tool');
4351 $this->t->set_var('lang_email','Send Email');
4352 $this->t->set_var('lang_reset','Cancel');
4354 $this->t->set_var('email_member_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=member'));
4355 $this->t->set_var('email_member_link_title','Email Quorum Member');
4357 $this->t->set_var('email_quorum_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=quorum'));
4358 $this->t->set_var('email_quorum_link_title','Email Quorum');
4360 $this->t->set_var('email_reminder_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=reminder'));
4361 $this->t->set_var('email_reminder_link_title','Email Reminders');
4363 $this->t->set_var('email_edit_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=edit'));
4364 $this->t->set_var('email_edit_link_title','Edit Email Addresses');
4367 $this->t->set_var('table_width',$table_width);
4369 $this->t->pfp('out','email_t');
4370 $this->save_sessiondata();
4375 $this->t->set_file(array('admin_t' => 'admin.tpl'));
4376 $this->t->set_block('admin_t','upload','uploadhandle');
4377 $this->t->set_block('admin_t','admin','adminhandle');
4378 $this->t->set_block('admin_t','cmd','cmdhandle');
4379 $this->t->set_block('admin_t','leader','leaderhandle');
4381 $this->t->set_var('upload_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=upload'));
4382 $this->t->set_var('leader_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=leader'));
4384 $action = get_var('action',array('GET','POST'));
4386 $this->t->pfp('out','admin_t');
4388 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY individual ASC";
4389 $this->db->query($sql,__LINE__,__FILE__);
4391 while ($this->db->next_record()) {
4392 $individual[$i] = $this->db->f('individual');
4393 $indiv_name[$i] = $this->db->f('name');
4394 $indiv2name[$individual[$i]] = $indiv_name[$i];
4397 array_multisort($indiv_name, $individual);
4399 if($action == 'upload') {
4400 $target_path = $this->upload_target_path . '/' . basename( $_FILES['uploadedfile']['name']);
4402 if(($_FILES['uploadedfile']['type'] == "application/zip") ||
4403 ($_FILES['uploadedfile']['type'] == "application/x-zip-compressed") ||
4404 ($_FILES['uploadedfile']['type'] == "application/x-zip") ||
4405 ($_FILES['uploadedfile']['type'] == "application/octet-stream")) {
4407 if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
4408 $uploadstatus = "<b><font color=red> -E- Unable to move the uploaded file to ";
4409 $uploadstatus.= "the target path (check the path and permissions) of: $target_path</font></b>";
4410 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
4411 $uploadstatus.= "Tmp Filename : " . $_FILES['uploadedfile']['tmp_name'] . "<br>";
4412 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
4413 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
4414 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
4415 $uploadstatus.= "Error : " . $_FILES['uploadedfile']['error'] . "<br>";
4416 $this->t->set_var('uploadstatus',$uploadstatus);
4417 $this->t->pfp('uploadhandle','upload',True);
4421 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
4422 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
4423 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
4424 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
4425 $this->t->set_var('uploadstatus',$uploadstatus);
4426 $this->t->pfp('uploadhandle','upload');
4427 $this->t->set_var('uploadhandle','');
4428 print "<table border=1 width=80%><tr><td>\n<pre>";
4430 # make a directory for this data to be stored in
4431 $date="data_" . date("Y_m_d");
4432 $data_dir = $this->upload_target_path . '/' . $date;
4433 print "-> Making the data directory: $date<br>\n";
4434 exec('mkdir -p ' . $data_dir . ' 2>&1', $result, $return_code);
4435 if($return_code != 0) {
4436 print implode('\n',$result) . "<br>";
4437 print "<b><font color=red>";
4438 print "-E- Unable to create the data directory. Aborting import.";
4439 print "</font></b>";
4443 # move the file uploaded into this directory
4444 print "-> Moving the uploaded file into the data dir<br>\n";
4445 exec('mv ' . $target_path . ' ' . $data_dir . '/' . ' 2>&1', $result, $return_code);
4446 if($return_code != 0) {
4447 print implode('\n',$result) . "<br>";
4448 print "<b><font color=red>";
4449 print "-E- Unable to move the uploaded file into the data dir. Aborting import.";
4450 print "</font></b>";
4454 # unzip the data into this directory
4455 print "-> Unzipping the data<br>\n";
4456 exec($this->unzip_path .' -u '. $data_dir . '/*.zip -d ' . $data_dir . ' 2>&1', $result, $return_code);
4457 if($return_code != 0) {
4458 print implode('\n',$result) . "<br>";
4459 print "<b><font color=red>";
4460 print "-E- Unable to unzip the uploaded file into the data dir: $data_dir. Aborting import.";
4461 print "</font></b>";
4464 exec('mv ' . $data_dir . '/*/* '. $data_dir . ' 2>&1', $result, $return_code);
4466 # update the data_latest link to point to this new directory
4467 print "-> Updating the latest data dir link<br>\n";
4468 $data_latest = $this->upload_target_path . '/data_latest';
4469 exec('rm ' . $data_latest. '; ln -s ' . $data_dir .' '. $data_latest .' 2>&1', $result, $return_code);
4470 if($return_code != 0) {
4471 print implode('\n',$result) . "<br>";
4472 print "<b><font color=red>";
4473 print "-E- Unable to update the data latest link. Aborting import.";
4474 print "</font></b>";
4478 # run the import perl script to encorporate it into the DB
4479 ob_start('ob_logstdout', 2);
4480 print "-> Importing the data into the database<br>\n";
4481 ob_flush(); flush(); sleep(1);
4482 $import_log = $this->upload_target_path . '/import.log';
4483 $data_log = $this->upload_target_path . '/data.log';
4484 $import_cmd = $this->script_path . '/import_ward_data ' . $data_latest . ' 2>&1 | tee ' . $import_log;
4485 $parse_cmd = $this->script_path . '/parse_ward_data -v ' . $data_latest . ' > ' . $data_log . '2>&1';
4486 #print "import_cmd: $import_cmd<br>";
4487 #print "parse_cmd: $parse_cmd<br>";
4488 ob_start('ob_logstdout', 2);
4489 passthru($import_cmd);
4490 passthru($parse_cmd);
4491 ob_flush(); flush(); sleep(1);
4493 # fix the permissions of the data dir
4494 exec('chmod -R o-rwx ' . $data_dir, $result, $return_code);
4496 $this->t->pfp('cmdhandle','cmd');
4497 print "</pre></td></tr></table>";
4498 } else if(($_FILES['uploadedfile']['type'] != "application/zip") &&
4499 ($_FILES['uploadedfile']['type'] != "application/x-zip-compressed") &&
4500 ($_FILES['uploadedfile']['type'] != "application/x-zip") &&
4501 ($_FILES['uploadedfile']['type'] != "application/octet-stream")) {
4502 $uploadstatus = "<b><font color=red>The file format must be a .zip file, please try again! </font></b>";
4503 $uploadstatus.= "<br><br><b>Detected file format: " . $_FILES['uploadedfile']['type'] . "</b>";
4504 $this->t->set_var('uploadstatus',$uploadstatus);
4505 $this->t->pfp('uploadhandle','upload',True);
4507 $uploadstatus = "<b><font color=red> There was an error (" . $_FILES['uploadedfile']['error'];
4508 $uploadstatus.= ") uploading the file, please try again! </font></b>";
4509 $this->t->set_var('uploadstatus',$uploadstatus);
4510 $this->t->pfp('uploadhandle','upload',True);
4512 } else if($action == "leader") {
4513 $new_data = get_var('eqpres',array('POST'));
4515 // Delete all the previous district entries from the table
4516 $this->db->query("DELETE from tc_district where valid=1",__LINE__,__FILE__);
4517 $this->db->query("DELETE from tc_district where valid=0",__LINE__,__FILE__);
4519 // Always add a "District 0" assigned to the High Priests Group
4521 $name = "High Priests";
4524 $this->db2->query("INSERT INTO tc_district (district,leader,valid) " .
4525 "VALUES ('" . $district . "','" .
4526 $indiv . "','" . $valid . "'" .
4527 ")",__LINE__,__FILE__);
4529 foreach ($new_data as $entry) {
4531 $email = $entry['email'];
4532 $indiv = $entry['indiv'];
4533 $name = $entry['name'];
4534 $district = $entry['district'];
4535 $president = $entry['president'];
4536 $counselor = $entry['counselor'];
4537 $secretary = $entry['secretary'];
4538 // look up the individual name for the ID
4539 $name = $indiv2name[$indiv];
4540 //print "id=$id indiv=$indiv name=$name email=$email district=$district president=$president ";
4541 //print "counselor=$counselor secretary=$secretary<br>";
4543 if(($indiv > 0) || ($name != "")) {
4545 if ($secretary == 1) {$leader_type = 'S';}
4546 if ($counselor == 1) {$leader_type = 'C';}
4547 if ($president == 1) {$leader_type = 'P';}
4548 if($id < $this->max_leader_members) {
4549 //print "Updating Existing Entry<br>";
4550 $this->db2->query("UPDATE tc_leader set" .
4551 " individual=" . $indiv .
4552 " ,email='" . $email . "'" .
4553 " ,type='" . $leader_type . "'" .
4554 " WHERE leader=" . $id,__LINE__,__FILE__);
4556 //print "Adding New Entry<br>";
4557 $this->db2->query("INSERT INTO tc_leader (leader,individual," .
4558 "email,type,valid) " .
4559 "VALUES (NULL,'" . $indiv . "','" .
4560 $email . "','" . $leader_type . "','1'" .
4561 ")",__LINE__,__FILE__);
4562 $id = mysql_insert_id();
4565 // If we have a valid district, add it to the district table
4568 $this->db2->query("INSERT INTO tc_district (district,leader,valid) " .
4569 "VALUES ('" . $district . "','" .
4570 $id . "','" . $valid . "'" .
4571 ")",__LINE__,__FILE__);
4574 //print "Ignoring Blank Entry<br>";
4578 $this->t->set_var('adminhandle','');
4579 $this->t->pfp('adminhandle','admin');
4583 $this->t->set_var('adminhandle','');
4584 $this->t->pfp('adminhandle','admin');
4587 // Now save off the data needed for a Leader Table Update
4589 $sql = "SELECT tl.*, ti.name FROM tc_leader AS tl JOIN tc_individual AS ti WHERE tl.individual=ti.individual AND tl.valid=1";
4590 $this->db->query($sql,__LINE__,__FILE__);
4592 $header_row = "<th>Individual</th><th>Email</th><th>District</th><th>President</th><th>Counselor</th><th>Secretary</th>";
4593 while ($this->db->next_record()) {
4594 // Extract the data for each leader record
4595 $id = $this->db->f('leader');
4596 $indiv = $this->db->f('individual');
4597 $name = $this->db->f('name');
4598 $email = $this->db->f('email');
4599 $leader_type = $this->db->f('type');
4600 if ($leader_type == 'P') {$president = 1;} else {$president = 0;}
4601 if ($leader_type == 'C') {$counselor = 1;} else {$counselor = 0;}
4602 if ($leader_type == 'S') {$secretary = 1;} else {$secretary = 0;}
4604 $sql = "SELECT * FROM tc_district AS td JOIN tc_leader AS tl WHERE td.leader=tl.leader AND td.leader=$id AND td.district!=0 AND td.valid=1";
4605 $this->db2->query($sql,__LINE__,__FILE__);
4606 if ($this->db2->next_record()) {
4607 $district = $this->db2->f('district');
4612 // Create the forms needed in the table
4613 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4616 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4619 if($eqleader == 0) {
4620 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4621 $table_data.= '<option value=0></option>';
4622 for ($j=0; $j < count($individual); $j++) {
4623 $tmp_id = $individual[$j];
4624 $name = $indiv_name[$j];
4625 if($individual[$j] == $indiv) {
4627 $selected = 'selected="selected"';
4631 $table_data.= '<option value='.$tmp_id.' '.$selected.'>'.$name.'</option>';
4633 $table_data.='</select></td>';
4634 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="'.$indivname.'">';
4636 $table_data.= '<td align=left><input type=text size="20" name="eqpresname" value="Leader"></td>';
4637 $table_data.= '<input type=hidden name="eqpres['.$id.'][name]" value="Leader">';
4641 $table_data .= '<td><input type="text" size="50" name="eqpres['.$id.'][email]" value="'.$email.'"></td>';
4644 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4645 $table_data.= '<option value=0></option>';
4646 for ($j=0; $j <= $this->max_num_districts; $j++) {
4647 if($district == $j) {
4648 $selected = 'selected="selected"';
4652 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4654 $table_data.='</select></td>';
4657 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4658 if($president == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4659 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4660 $table_data.='</select></td>';
4663 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4664 if($counselor == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4665 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4666 $table_data.='</select></td>';
4669 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4670 if($secretary == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4671 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4672 $table_data.='</select></td>';
4675 $table_data .= "</tr>\n";
4676 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4677 $this->t->set_var('tr_color',$tr_color);
4680 // Now create 1 blank row to always have a line available to add a new individual with
4681 $id = $this->max_leader_members;
4682 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4684 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4686 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4687 $table_data.= '<option value=0></option>';
4688 for ($j=0; $j < count($individual); $j++) {
4689 $tmp_id = $individual[$j];
4690 $name = $indiv_name[$j];
4691 $table_data.= '<option value='.$tmp_id.'>'.$name.'</option>';
4693 $table_data.='</select></td>';
4694 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="">';
4696 $table_data.='<td><input type="text" size="50" name="eqpres['.$id.'][email]" value=""></td>';
4698 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4699 $table_data.= '<option value=0></option>';
4700 for ($j=0; $j <= $this->max_num_districts; $j++) {
4702 $selected = 'selected="selected"';
4706 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4708 $table_data.='</select></td>';
4710 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4711 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4712 $table_data.='</select></td>';
4714 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4715 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4716 $table_data.='</select></td>';
4718 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4719 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4720 $table_data.='</select></td>';
4722 $table_data .= "</tr>\n";
4723 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4724 $this->t->set_var('tr_color',$tr_color);
4726 $this->t->set_var('header_row',$header_row);
4727 $this->t->set_var('table_data',$table_data);
4728 $this->t->pfp('leaderhandle','leader',True);
4730 $this->save_sessiondata();
4733 function email_appt($appointment, $old_indiv_email)
4735 //print "Emailing notification of appointment: $appointment <br>";
4737 $sql = "SELECT * FROM tc_appointment where appointment='$appointment'";
4738 $this->db->query($sql,__LINE__,__FILE__);
4740 while ($this->db->next_record()) {
4741 $appointment = $this->db->f('appointment');
4742 $leader = $this->db->f('leader');
4743 $location = $this->db->f('location');
4746 $indiv = $this->db->f('individual');
4748 $family = $this->db->f('family');
4752 $uid = $this->db->f('uid');
4754 // Extract the year, month, day, hours, minutes, seconds from the appointment time
4755 $appt_date = $this->db->f('date');
4756 $date_array = explode("-",$appt_date);
4757 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
4758 $appt_time = $this->db->f('time');
4759 $time_array = explode(":",$appt_time);
4760 $hour = $time_array[0]; $minute = $time_array[1]; $seconds = $time_array[2];
4762 // Format the appointment time into an iCal UTC equivalent
4763 $dtstamp = gmdate("Ymd"."\T"."His"."\Z");
4764 $dtstart = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds,$month,$day,$year));
4765 $dtstartstr = date("l, F d, o g:i A", mktime($hour,$minute,$seconds,$month,$day,$year));
4767 $sql = "SELECT tl.email AS email1, ti.email AS email2, ti.name AS name FROM tc_leader AS tl JOIN tc_individual AS ti WHERE tl.individual=ti.individual AND tl.leader='$leader'";
4768 $this->db2->query($sql,__LINE__,__FILE__);
4769 if($this->db2->next_record()) {
4770 if ($this->db2->f('email1') != "") {
4771 $email = $this->db2->f('email1');
4773 $email = $this->db2->f('email2');
4775 $interviewer = $this->db2->f('name');
4778 // Set the email address of the interviewer
4782 $sql = "SELECT * FROM tc_individual where individual='$indiv'";
4783 $this->db2->query($sql,__LINE__,__FILE__);
4784 if($this->db2->next_record()) {
4785 $indiv_name = $this->db2->f('name');
4786 $phone = $this->db2->f('phone');
4787 $indiv_email = $this->db2->f('email');
4788 if(($this->email_individual_appt == 1) && ($indiv_email != "")) {
4789 $email .= ", $indiv_email";
4791 $appt_name = $indiv_name . " Interview";
4792 $duration = $this->default_ppi_appt_duration * 60;
4797 $sql = "SELECT * FROM tc_family WHERE family='$family'";
4798 $this->db2->query($sql,__LINE__,__FILE__);
4799 if($this->db2->next_record()) {
4800 $individual = $this->db2->f('individual');
4801 $sql = "SELECT * FROM tc_individual where individual='$individual'";
4802 $this->db3->query($sql,__LINE__,__FILE__);
4803 if($this->db3->next_record()) {
4804 $phone = $this->db3->f('phone');
4805 $family_name = $this->db3->f('name');
4806 $phone = $this->db3->f('phone');
4807 $indiv_email = $this->db3->f('email');
4808 if(($this->email_individual_appt == 1) && ($indiv_email != "")) {
4809 $email .= ", $indiv_email";
4812 $appt_name = $family_name . " Family Visit";
4813 $duration = $this->default_visit_appt_duration * 60;
4817 $dtend = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4818 $dtendstr = date("g:i A", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4819 $date = $dtstartstr . "-" . $dtendstr;
4820 $description = "$appt_name : $phone";
4822 if(($uid == 0) && ($appt_name != "")) {
4823 // Create a new calendar item for this appointment, since this must be the first time we
4824 // are sending it out.
4825 print "Sent new appointment for " . $interviewer . " to '" . $email . "' for " . $appt_name . "<br>";
4826 $uid = rand() . rand(); // Generate a random identifier for this appointment
4827 $subject = "Created: $appt_name";
4829 $this->db->query("UPDATE tc_appointment set" .
4831 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4833 $action = "PUBLISH";
4834 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4835 $dtend, $date, $location, $appt_name, $description, $uid);
4836 } else if(($uid != 0) && ($appt_name == "")) {
4837 // Remove the calendar item for this appointment since it has already been sent
4838 // and there is no name we have changed it to.
4839 if(($this->email_individual_appt == 1) && ($old_indiv_email != "")) {
4840 $email .= ", $old_indiv_email";
4842 print "Sent deleted appointment for " . $interviewer . " to '" . $email . "' for " . $appt_date . " " . $appt_time . "<br>";
4843 $subject = "Canceled: $appt_date $appt_time";
4845 $this->db->query("UPDATE tc_appointment set" .
4847 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4850 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4851 $dtend, $date, $location, $subject, $subject, $uid);
4852 } else if($uid != 0) {
4853 // Update the existing appointment since we have changed it
4854 print "Sent updated appointment for " . $interviewer . " to '" . $email . "' for " . $appt_name . "<br>";
4856 $subject = "Canceled: $appt_date $appt_time";
4858 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4859 $dtend, $date, $location, $subject, $subject, $uid);
4861 $uid = rand() . rand(); // Generate a random identifier for this appointment
4862 $this->db->query("UPDATE tc_appointment set" .
4864 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4866 $subject = "Updated: $appt_name";
4867 $action = "PUBLISH";
4868 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4869 $dtend, $date, $location, $appt_name, $description, $uid);
4875 function send_ical_appt($action, $to, $from, $subject, $dtstamp, $dtstart, $dtend, $date, $location, $summary, $description, $uid)
4877 // Initialize our local variables
4878 $boundary = "=MIME_APPOINTMENT_BOUNDARY";
4882 // Form the headers for the email message
4883 $headers.="X-Mailer: PHP/" . phpversion() . "\n";
4884 $headers.="Mime-Version: 1.0\n";
4885 $headers.="Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
4886 $headers.="Content-Disposition: inline\n";
4887 $headers.="Reply-To: $from\n";
4888 $headers.="From: $from\n";
4890 // Print the plaintext version of the appointment
4891 $message.="--$boundary\n";
4892 $message.="Content-Type: text/plain; charset=us-ascii\n";
4893 $message.="Content-Disposition: inline\n";
4895 $message.="What: $description\n";
4896 $message.="When: $date\n";
4897 $message.="Where: $location\n";
4900 // Print the .ics attachment version of the appointment
4901 $message.="--$boundary\n";
4902 $message.="Content-Type: text/calendar; charset=us-ascii\n";
4903 $message.="Content-Disposition: attachment; filename=\"appointment.ics\"\n";
4905 $message.="BEGIN:VCALENDAR" . "\n";
4906 $message.="VERSION:2.0" . "\n";
4907 $message.="PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN" . "\n";
4908 $message.="METHOD:$action" . "\n";
4909 $message.="BEGIN:VEVENT" . "\n";
4910 $message.="ORGANIZER:MAILTO:$from". "\n";
4911 $message.="DTSTAMP:$dtstamp" . "\n";
4912 $message.="DTSTART:$dtstart" . "\n";
4913 $message.="DTEND:$dtend" . "\n";
4914 $message.="SUMMARY:$summary" . "\n";
4915 $message.="DESCRIPTION:$description" . "\n";
4916 $message.="LOCATION:$location" . "\n";
4917 $message.="UID:$uid" ."\n";
4918 $message.="TRANSP:OPAQUE" . "\n";
4919 $message.="SEQUENCE:0" . "\n";
4920 $message.="CLASS:PUBLIC" . "\n";
4921 $message.="END:VEVENT" . "\n";
4922 $message.="END:VCALENDAR" . "\n";
4924 // Complete the message
4925 $message.="--$boundary\n";
4928 mail($to, $subject, $message, $headers);
4931 function get_time_selection_form($hour, $minute, $pm, $leader, $appointment)
4936 if($hour == 0) { $blank = 1; }
4938 if($this->time_drop_down_lists == 1) {
4939 // Create drop down lists to get the time
4940 $form_data.= '<select name=sched['.$leader.']['.$appointment.'][hour]>';
4941 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4942 foreach(range(1,12) as $num) {
4944 $selected = 'selected="selected"';
4948 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4950 $form_data.= '</select>';
4951 $form_data.= ' : ';
4952 $form_data.= '<select name=sched['.$leader.']['.$appointment.'][minute]>';
4953 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4956 if($num < 10) { $num = "0" . "$num"; }
4957 if($minute == $num) {
4958 $selected = 'selected="selected"';
4962 if($blank == 1) { $selected = ""; }
4963 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4964 $num = $num + $this->time_drop_down_list_inc;
4966 $form_data.= '</select>';
4968 // Use free form text fields to get the time
4974 $form_data.= '<input type=text size=2 name=sched['.$leader.']['.$appointment.'][hour] value='.$hour.'>';
4976 $form_data.= '<input type=text size=2 name=sched['.$leader.']['.$appointment.'][minute] value='.$minute.'>';
4977 $form_data.= ' ';
4979 // Always use a drop-down select form for am/pm
4980 $form_data.= '<select name=sched['.$leader.']['.$appointment.'][pm]>';
4983 $form_data.= '<option value=0 selected>am</option>';
4984 $form_data.= '<option value=1>pm</option>';
4987 $form_data.= '<option value=0>am</option>';
4988 $form_data.= '<option value=1 selected>pm</option>';
4991 $form_data.= '<option value=""></option>';
4992 $form_data.= '<option value=0>am</option>';
4993 $form_data.= '<option value=1>pm</option>';
4995 $form_data.= '</select>';