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_presidency_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->script_path = "$this->application_path"."/bin";
83 $this->max_presidency_members = 99;
84 $this->max_appointments = 32768;
86 $this->db = $GLOBALS['phpgw']->db;
87 $this->db2 = $this->db;
88 $this->db3 = $this->db;
89 $this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
90 $this->t = $GLOBALS['phpgw']->template;
91 $this->account = $GLOBALS['phpgw_info']['user']['account_id'];
92 $this->grants = $GLOBALS['phpgw']->acl->get_grants('tc');
93 $this->grants[$this->account] = PHPGW_ACL_READ + PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE;
95 $this->jscal = CreateObject('tc.jscalendar'); // before phpgw_header() !!!
96 $this->cal_options = 'daFormat : "%Y-%m-%d",
97 ifFormat : "%Y-%m-%d",
101 $GLOBALS['phpgw_info']['flags']['app_header'] = 'The 3rd Counselor';
102 $GLOBALS['phpgw']->common->phpgw_header();
104 $this->current_day = `date '+%d'`;
105 $this->current_day = $this->current_day-0; // Make it numeric
106 $this->current_month = `date '+%m'`;
107 $this->current_month = $this->current_month-0; // Make it numeric
108 $this->current_year = `date '+%Y'`;
109 $this->current_year = $this->current_year-0; // Make it numeric
111 if ($this->ppi_frequency == 12) {
112 $this->ppi_frequency_label = "Annual";
113 } else if ($this->ppi_frequency == 6) {
114 $this->ppi_frequency_label = "Semi-Annual";
115 } else if ($this->ppi_frequency == 3) {
116 $this->ppi_frequency_label = "Quarterly";
117 } else if ($this->ppi_frequency == 1) {
118 $this->ppi_frequency_label = "Monthly";
120 $this->ppi_frequency_label = "Periodic";
124 $this->display_app_header();
127 function logToFile($func, $msg)
130 $fd = fopen($this->upload_target_path . "/tc_trace.log", "a");
131 // append date/time to message
132 $str = "[" . date("Y/m/d h:i:s", mktime()) . "] [" . $func . "] " . $msg;
134 fwrite($fd, $str . "\n");
139 function save_sessiondata()
143 function display_app_header()
145 $this->t->set_file(array('tc_header' => 'header.tpl'));
147 if (isset($phpgw_info['user']['preferences']['tc']['tc_font']))
149 $font = $phpgw_info['user']['preferences']['tc']['tc_font'];
156 $this->t->set_var('bg_color',$phpgw_info['theme']['th_bg']);
157 $this->t->set_var('font',$font);
158 $link_data['menuaction'] = 'tc.tc.ht_view';
159 $this->t->set_var('link_hometeaching',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
160 $this->t->set_var('lang_hometeaching','HomeTeaching');
161 $link_data['menuaction'] = 'tc.tc.act_list';
162 $this->t->set_var('link_activity',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
163 $this->t->set_var('lang_activity','Activities');
164 $link_data['menuaction'] = 'tc.tc.willing_view';
165 $this->t->set_var('link_willing',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
166 $this->t->set_var('lang_willing','Willingness');
167 $link_data['menuaction'] = 'tc.tc.assign_view';
168 $this->t->set_var('link_assignment',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
169 $this->t->set_var('lang_assignment','Assignments');
170 $link_data['menuaction'] = 'tc.tc.par_view';
171 $this->t->set_var('link_participation',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
172 $this->t->set_var('lang_participation','Participation');
173 $link_data['menuaction'] = 'tc.tc.ppi_view';
174 $this->t->set_var('link_ppi',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
175 $this->t->set_var('lang_ppi','PPIs');
176 $link_data['menuaction'] = 'tc.tc.int_view';
177 $this->t->set_var('link_int',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
178 $this->t->set_var('lang_int','Interviews');
179 $link_data['menuaction'] = 'tc.tc.vis_view';
180 $this->t->set_var('link_visit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
181 $this->t->set_var('lang_visit','Visits');
182 $link_data['menuaction'] = 'tc.tc.att_view';
183 $this->t->set_var('link_attendance',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
184 $this->t->set_var('lang_attendance','Attendance');
185 $link_data['menuaction'] = 'tc.tc.dir_view';
186 $this->t->set_var('link_dir',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
187 $this->t->set_var('lang_dir','Directory');
188 $link_data['menuaction'] = 'tc.tc.org_view';
189 $this->t->set_var('link_org',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
190 $this->t->set_var('lang_org','Callings');
191 $link_data['menuaction'] = 'tc.tc.admin';
192 $this->t->set_var('link_admin',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
193 $this->t->set_var('lang_admin','Admin');
194 $link_data['menuaction'] = 'tc.tc.schedule';
195 $this->t->set_var('link_schedule',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
196 $this->t->set_var('lang_schedule','Scheduling');
197 $link_data['menuaction'] = 'tc.tc.email';
198 $this->t->set_var('link_email',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
199 $this->t->set_var('lang_email','Email');
201 $this->t->pparse('out','tc_header');
206 $this->t->set_file(array('ht_view_t' => 'ht_view.tpl'));
207 $this->t->set_block('ht_view_t','district_list','list');
209 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
210 $num_months = get_var('num_months',array('GET','POST'));
211 if($num_months == '') { $num_months = $this->default_ht_num_months; }
212 $this->t->set_var('num_months',$num_months);
213 $this->t->set_var('lang_filter','Filter');
214 if($num_months == 1) { $this->t->set_var('lang_num_months','Month of History'); }
215 else { $this->t->set_var('lang_num_months','Months of History'); }
217 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
218 $this->t->set_var('title','Hometeaching');
220 $this->t->set_var('ht_sandbox_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_sandbox'));
221 $this->t->set_var('ht_sandbox_link_title','Hometeaching Sandbox');
223 $sql = "SELECT * FROM tc_district AS td JOIN tc_individual AS ti WHERE td.supervisor=ti.individual AND td.valid=1 ORDER BY td.district ASC";
224 $this->db->query($sql,__LINE__,__FILE__);
226 while ($this->db->next_record()) {
227 $districts[$i]['district'] = $this->db->f('district');
228 $districts[$i]['name'] = $this->db->f('name');
229 $districts[$i]['supervisor'] = $this->db->f('supervisor');
233 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
234 $this->db->query($sql,__LINE__,__FILE__);
236 while ($this->db->next_record()) {
237 $individual[$i] = $this->db->f('individual');
238 $indiv_name[$i] = $this->db->f('name');
239 $indiv_phone[$individual[$i]] = $this->db->f('phone');
242 array_multisort($indiv_name, $individual);
244 // Make an array mapping individuals to indiv_names
245 for($i=0; $i < count($individual); $i++) {
246 $id = $individual[$i];
247 $indivs[$id] = $indiv_name[$i];
250 $this->nextmatchs->template_alternate_row_color(&$this->t);
251 for($m=$num_months; $m >= 0; $m--) { $total_families[$m]=0; }
252 for ($i=0; $i < count($districts); $i++) {
253 $this->t->set_var('district_number',$districts[$i]['district']);
254 $this->t->set_var('district_name',$districts[$i]['name']);
255 $supervisor = $districts[$i]['supervisor'];
257 // Select all the unique companionship numbers for this district
258 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$i]['district'];
259 $this->db->query($sql,__LINE__,__FILE__);
260 $j=0; $unique_companionships = '';
261 while ($this->db->next_record()) {
262 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
266 $comp_width=450; $visit_width=25; $table_width=$comp_width + $num_months*$visit_width;
267 $table_data=""; $num_companionships = 0;
268 for($m=$num_months; $m >= 0; $m--) {
272 for ($j=0; $j < count($unique_companionships); $j++) {
273 $companion_table_entry = "";
274 // Select all the companions in each companionship
275 $sql = "SELECT * FROM tc_companion where valid=1 and ".
276 "companionship=". $unique_companionships[$j]['companionship'];
277 $this->db->query($sql,__LINE__,__FILE__);
279 while ($this->db->next_record()) {
280 // Get this companions information
281 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
282 $companionship = $this->db->f('companionship');
283 $individual = $this->db->f('individual');
284 $name = $indivs[$individual];
285 $phone = $indiv_phone[$individual];
286 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
288 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
290 // Get the names of the families assigned this home teaching companionship
291 $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'];
292 $sql = $sql . " ORDER BY name ASC";
293 $this->db->query($sql,__LINE__,__FILE__);
295 while ($this->db->next_record()) {
296 $family_name = $this->db->f('name');
297 $family_id = $this->db->f('family');
298 $this->nextmatchs->template_alternate_row_color(&$this->t);
299 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
300 // Find out how many times Visits were performed by this companionship
301 // in the past $num_months for this Family
302 $header_row="<th width=$comp_width><font size=-2>Families</th>";
303 for($m=$num_months; $m >= 0; $m--) {
304 $month = $this->current_month - $m;
305 $year = $this->current_year;
306 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
307 if($month < 10) { $month = "0"."$month"; }
308 $month_start = "$year"."-"."$month"."-"."01";
309 $month_end = "$year"."-"."$month"."-"."31";
310 $month = "$month"."/"."$year";
312 //print "m: $m month: $month year: $year month_start: $month_start month_end: $month_end<br>";
313 // Add this to the query to filter on only visits made by this companionship:
314 // " AND companionship=" . $unique_companionships[$j]['companionship'].
316 // First check to see if the currently assigned companionship has visited them
317 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
318 " AND companionship=".$unique_companionships[$j]['companionship'].
319 " AND family=". $family_id;
320 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
321 if($this->db2->num_rows($query_id) == 0) {
322 // We did not find any visits made by the currently assigned companionship,
323 // look for visits made by any other companionship other than 0. (0 == Presidency Visit)
324 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
325 " AND companionship!=0".
326 " AND family=". $family_id;
327 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
329 $this->db2->query($sql,__LINE__,__FILE__);
330 $link_data['menuaction'] = 'tc.tc.ht_update';
331 $link_data['date'] = $month_start;
332 $link_data['month_start'] = $month_start;
333 $link_data['month_end'] = $month_end;
334 $link_data['month'] = $month;
335 $link_data['district'] = $districts[$i]['district'];
336 $link_data['district_name'] = $districts[$i]['name'];
337 $link_data['action'] = 'view';
338 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
339 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
340 if(!$total_visits[$m]) { $total_visits[$m] = 0; }
341 if($this->db2->next_record()) {
342 if($this->db2->f('visited') == 'y') {
343 $visits[$m]++; $total_visits[$m]++;
344 $num_families[$m]++; $total_families[$m]++;
345 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/checkmark.gif"></a></td>';
346 } else if($this->db2->f('visited') == 'n') {
347 $num_families[$m]++; $total_families[$m]++;
348 $table_data .= '<td align=center><a href="'.$link.'"><img src="images/x.gif"></a></td>';
350 //$visits[$m]++; $total_visits[$m]++;
351 $table_data .= "<td> </td>";
354 //$visits[$m]++; $total_visits[$m]++;
355 $table_data .= "<td> </td>";
358 $table_data .= "</tr>";
361 $table_data .= "<tr><td colspan=20></td></tr>";
363 $table_data .= "<tr><td colspan=20><hr></td></tr>";
364 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
366 for($m=$num_months; $m >=0; $m--) {
367 if($num_families[$m] > 0) {
368 $percent = ceil(($visits[$m] / $num_families[$m])*100);
372 $stat_data .= "<td align=center><font size=-2><b>$visits[$m] / $num_families[$m]<br>$percent%</font></b></td>";
374 $stat_data .= "</tr>";
376 $this->t->set_var('table_width',$table_width);
377 $this->t->set_var('header_row',$header_row);
378 $this->t->set_var('table_data',$table_data);
379 $this->t->set_var('stat_data',$stat_data);
380 $this->t->fp('list','district_list',True);
383 $totals = "<tr><td><b><font size=-2>Total Families Hometaught:<br>Total Hometeaching Percentage:</font></b></td>";
384 for($m=$num_months; $m >=0; $m--) {
385 if($total_families[$m] > 0) {
386 $percent = ceil(($total_visits[$m] / $total_families[$m])*100);
390 $totals .= "<td align=center><font size=-2><b>$total_visits[$m] / $total_families[$m]<br>$percent%</font></b></td>";
394 $this->t->set_var('totals',$totals);
396 $this->t->pfp('out','ht_view_t');
397 $this->save_sessiondata();
401 function ht_sandbox()
403 $this->t->set_file(array('ht_sandbox_t' => 'ht_sandbox.tpl'));
404 $this->t->set_block('ht_sandbox_t','comp_list','c_list');
405 $this->t->set_block('ht_sandbox_t','district_list','d_list');
406 $this->t->set_block('ht_sandbox_t','unassigned_ht_list','uht_list');
407 $this->t->set_block('ht_sandbox_t','assigned_ht_list','aht_list');
408 $this->t->set_block('ht_sandbox_t','unassigned_family_list','uf_list');
409 $this->t->set_block('ht_sandbox_t','assigned_family_list','af_list');
410 $this->t->set_block('ht_sandbox_t','district_table_list','dt_list');
411 $this->t->set_block('ht_sandbox_t','companionship_table_list','ct_list');
413 $this->t->set_var('submit_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_sandbox&action=add'));
415 $action = get_var('action',array('GET','POST'));
417 $this->t->set_var('title','Hometeaching Sandbox');
420 #$this->t->set_var('debug_list',$_POST['add']);
421 $companionship = get_var('companionship',array('POST'));
422 $district = get_var('district',array('POST'));
423 $assignedHT_list = get_var('assignedHT',array('POST'));
424 $unassignedHT_list = get_var('unassignedHT',array('POST'));
425 $assigned_family_list = get_var('assignedFamiles',array('POST'));
426 $unassigned_family_list = get_var('unassignedFamilies',array('POST'));
428 if ($assignedHT_list || $unassignedHT_list) {
429 $sql = "INSERT INTO tc_companionship_sandbox (tc_companionship,district) VALUES (\"NULL\",\"$district\")";
430 $this->db2->query($sql,__LINE__,__FILE__);
431 $companionship_sandbox = mysql_insert_id();
433 foreach ($assignedHT_list as $individual) {
434 $sql = "INSERT INTO tc_companion_sandbox (individual,companionship) VALUES (\"$individual\",\"$companionship_sandbox\")";
435 $this->db->query($sql,__LINE__,__FILE__);
437 foreach ($unassignedHT_list as $individual) {
438 $sql = "INSERT INTO tc_companion_sandbox (individual,companionship) VALUES (\"$individual\",\"$companionship_sandbox\")";
439 $this->db->query($sql,__LINE__,__FILE__);
441 foreach ($assigned_family_list as $family) {
442 $sql = "UPDATE tc_family_sandbox SET companionship=$companionship_sandbox WHERE family=$family";
443 $this->db->query($sql,__LINE__,__FILE__);
445 foreach ($unassigned_family_list as $family) {
446 $sql = "UPDATE tc_family_sandbox SET companionship=$companionship_sandbox WHERE family=$family";
447 $this->db->query($sql,__LINE__,__FILE__);
450 $this->t->set_var('debug_list','You must select at least one companion!');
452 } else if ($_POST['delete']) {
453 #$this->t->set_var('debug_list',$_POST['delete']);
454 $companionship = get_var('companionship',array('POST'));
455 #$this->t->set_var('debug_list',$companionship);
457 if ($companionship > 0) {
459 $sql = "UPDATE tc_family_sandbox SET companionship=NULL WHERE companionship=$companionship";
460 $this->db->query($sql,__LINE__,__FILE__);
463 $sql = "DELETE FROM tc_companion_sandbox WHERE companionship=$companionship";
464 $this->db->query($sql,__LINE__,__FILE__);
466 # remove companionship
467 $sql = "DELETE FROM tc_companionship_sandbox WHERE companionship=$companionship";
468 $this->db->query($sql,__LINE__,__FILE__);
470 $this->t->set_var('debug_list','You must select a companionship to delete!');
472 } else if ($_POST['update']) {
473 #$this->t->set_var('debug_list',$_POST['update']);
474 $companionship = get_var('companionship',array('POST'));
475 $district = get_var('district',array('POST'));
476 $assignedHT_list = get_var('assignedHT',array('POST'));
477 $unassignedHT_list = get_var('unassignedHT',array('POST'));
478 $assigned_family_list = get_var('assignedFamiles',array('POST'));
479 $unassigned_family_list = get_var('unassignedFamilies',array('POST'));
480 #$this->t->set_var('debug_list',$district);
482 if ($companionship > 0) {
483 if ($assignedHT_list || $unassignedHT_list) {
484 # clear out existing info about companionship
485 $sql = "UPDATE tc_family_sandbox SET companionship=NULL WHERE companionship=$companionship";
486 $this->db->query($sql,__LINE__,__FILE__);
487 $sql = "DELETE FROM tc_companion_sandbox WHERE companionship=$companionship";
488 $this->db->query($sql,__LINE__,__FILE__);
490 # set new info about companionship
491 $sql = "UPDATE tc_companionship_sandbox SET district=$district WHERE companionship=$companionship";
492 $this->db->query($sql,__LINE__,__FILE__);
493 foreach ($assignedHT_list as $individual) {
494 $sql = "INSERT INTO tc_companion_sandbox (individual,companionship) VALUES (\"$individual\",\"$companionship\")";
495 $this->db->query($sql,__LINE__,__FILE__);
497 foreach ($unassignedHT_list as $individual) {
498 $sql = "INSERT INTO tc_companion_sandbox (individual,companionship) VALUES (\"$individual\",\"$companionship\")";
499 $this->db->query($sql,__LINE__,__FILE__);
501 foreach ($assigned_family_list as $family) {
502 $sql = "UPDATE tc_family_sandbox SET companionship=$companionship WHERE family=$family";
503 $this->db->query($sql,__LINE__,__FILE__);
505 foreach ($unassigned_family_list as $family) {
506 $sql = "UPDATE tc_family_sandbox SET companionship=$companionship WHERE family=$family";
507 $this->db->query($sql,__LINE__,__FILE__);
510 $this->t->set_var('debug_list','You must select at least one companion!');
513 $this->t->set_var('debug_list','You must select a companionship to update!');
515 } else if ($_POST['reset']) {
516 #$this->t->set_var('debug_list',$_POST['reset']);
518 $sql = "TRUNCATE TABLE tc_district_sandbox";
519 $this->db->query($sql,__LINE__,__FILE__);
520 $sql = "TRUNCATE TABLE tc_family_sandbox";
521 $this->db->query($sql,__LINE__,__FILE__);
522 $sql = "TRUNCATE TABLE tc_companion_sandbox";
523 $this->db->query($sql,__LINE__,__FILE__);
524 $sql = "TRUNCATE TABLE tc_companionship_sandbox";
525 $this->db->query($sql,__LINE__,__FILE__);
527 # populate tc_district_sandbox
528 $sql = "SELECT * FROM tc_district WHERE valid=1";
529 $this->db->query($sql,__LINE__,__FILE__);
530 while ($this->db->next_record()) {
531 $district = $this->db->f('district');
532 $supervisor = $this->db->f('supervisor');
533 $sql = "INSERT INTO tc_district_sandbox (district,supervisor) VALUES (\"$district\",\"$supervisor\")";
534 $this->db2->query($sql,__LINE__,__FILE__);
537 # populate family, companion, and companionship tables
538 $sql = "SELECT * FROM tc_companionship WHERE valid=1";
539 $this->db->query($sql,__LINE__,__FILE__);
540 while ($this->db->next_record()) {
541 $companionship = $this->db->f('companionship');
542 $district = $this->db->f('district');
543 $sql = "INSERT INTO tc_companionship_sandbox (tc_companionship,district) VALUES (\"$companionship\",\"$district\")";
544 $this->db2->query($sql,__LINE__,__FILE__);
545 $companionship_sandbox = mysql_insert_id();
547 $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";
548 $this->db2->query($sql,__LINE__,__FILE__);
549 while ($this->db2->next_record()) {
550 $individual = $this->db2->f('individual');
551 $sql = "INSERT INTO tc_companion_sandbox (individual,companionship) VALUES (\"$individual\",\"$companionship_sandbox\")";
552 $this->db3->query($sql,__LINE__,__FILE__);
555 $sql = "SELECT * FROM tc_family WHERE companionship=$companionship AND valid=1";
556 $this->db2->query($sql,__LINE__,__FILE__);
557 while ($this->db2->next_record()) {
558 $individual = $this->db2->f('individual');
559 $family = $this->db2->f('family');
560 $sql = "INSERT INTO tc_family_sandbox (tc_family,individual,companionship) VALUES (\"$family\",\"$individual\",\"$companionship_sandbox\")";
561 $this->db3->query($sql,__LINE__,__FILE__);
564 } else if ($_POST['changes']) {
565 $this->ht_sandbox_changes();
568 // get list of companionships
569 $sql = "SELECT DISTINCT companionship FROM tc_companionship_sandbox ORDER BY companionship ASC";
570 $this->db->query($sql,__LINE__,__FILE__);
571 $unique_companionships = '';
572 $unique_companionships[0]['companionship'] = 0;
573 $this->t->set_var('companionship_list','<option value="0">New Companionship</option>');
574 $this->t->fp('c_list','comp_list',True);
576 while ($this->db->next_record()) {
577 $companionship = $this->db->f('companionship');
578 $unique_companionships[$j]['companionship'] = $companionship;
579 $combined_companionship = "";
580 $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";
581 $this->db2->query($sql,__LINE__,__FILE__);
582 while ($this->db2->next_record()) {
583 if ($combined_companionship == "") {
584 $combined_companionship .= $this->db2->f('name');
586 $combined_companionship .= " / " . $this->db2->f('name');
589 $this->t->set_var('companionship_list','<option value="'.$companionship.'">'.$combined_companionship.'</option>');
590 $this->t->fp('c_list','comp_list',True);
594 # get list of districts
595 $sql = "SELECT DISTINCT district FROM tc_district_sandbox ORDER BY district ASC";
596 $this->db->query($sql,__LINE__,__FILE__);
599 while ($this->db->next_record()) {
600 $districts[$num_districts] = $this->db->f('district');
601 $this->t->set_var('district','<option value="'.$districts[$num_districts].'">'.$districts[$num_districts].'</option>');
602 $this->t->fp('d_list','district_list',True);
606 # get list of individuals who are and are not home teachers
607 $sql = "SELECT * FROM tc_individual WHERE steward='$this->default_stewardship' AND valid=1 ORDER BY name ASC";
608 $this->db->query($sql,__LINE__,__FILE__);
609 while ($this->db->next_record()) {
610 $individual = $this->db->f('individual');
611 $name = $this->db->f('name');
612 $sql = "SELECT DISTINCT * FROM tc_companion_sandbox WHERE individual=$individual";
613 $this->db2->query($sql,__LINE__,__FILE__);
614 if ($this->db2->next_record()) {
615 $this->t->set_var('assigned_ht','<option value="'.$individual.'">'.$name.'</option>');
616 $this->t->fp('aht_list','assigned_ht_list',True);
618 $this->t->set_var('unassigned_ht','<option value="'.$individual.'">'.$name.'</option>');
619 $this->t->fp('uht_list','unassigned_ht_list',True);
623 # get list of families who are and are not assigned home teachers
624 $sql = "SELECT * FROM tc_family_sandbox AS tf JOIN tc_individual AS ti WHERE tf.individual=ti.individual ORDER BY ti.name ASC";
625 $this->db->query($sql,__LINE__,__FILE__);
626 while ($this->db->next_record()) {
627 $individual = $this->db->f('individual');
628 $family = $this->db->f('family');
629 $name = $this->db->f('name');
630 if ($this->db->f('companionship') != 0) {
631 $this->t->set_var('assigned_family','<option value="'.$family.'">'.$name.' Family</option>');
632 $this->t->fp('af_list','assigned_family_list',True);
634 $this->t->set_var('unassigned_family','<option value="'.$family.'">'.$name.' Family</option>');
635 $this->t->fp('uf_list','unassigned_family_list',True);
639 # populate ht districts table
640 $sandbox_table_data = "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">";
642 # set up column headers
643 $sandbox_table_data .= "<tr>";
644 for ($d = 0; $d < $num_districts; $d++) {
645 $sandbox_table_data .= "<th align=\"center\" bgcolor=\"#c9c9c9\">District " . $districts[$d] . "</th>";
648 # get each companionship in each district
649 $sandbox_table_data .= "<tr>";
650 for ($d = 0; $d < $num_districts; $d++) {
651 $sandbox_table_data .= "<td valign=\"Top\">";
652 $sandbox_table_data .= "<table>";
653 $sql = "SELECT DISTINCT companionship FROM tc_companionship_sandbox WHERE district=$districts[$d] ORDER BY companionship ASC";
654 $this->db->query($sql,__LINE__,__FILE__);
655 while ($this->db->next_record()) {
656 $sandbox_table_data .= "<tr><td><table>";
657 $companionship = $this->db->f('companionship');
658 # get names of companions in this companionship
659 $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";
660 $this->db2->query($sql,__LINE__,__FILE__);
661 $companion_names = "";
662 while ($this->db2->next_record()) {
663 if ($companion_names == "") {
664 $companion_names .= $this->db2->f('name');
666 $companion_names .= " / " . $this->db2->f('name');
669 $this->nextmatchs->template_alternate_row_color(&$this->t);
670 $sandbox_table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
671 $sandbox_table_data .= "<th bgcolor=#d3dce3 align=\"Left\" bgcolor=\"#c9c9c9\">$companion_names</th></tr>";
672 $sandbox_table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td><table>";
674 # get families they visit
675 $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";
676 $this->db2->query($sql,__LINE__,__FILE__);
677 while ($this->db2->next_record()) {
678 $family_name = $this->db2->f('name') . " Family";
679 $family_id = $this->db2->f('tc_family');
680 $tc_companionship = $this->db2->f('tc_companionship');
681 $this->nextmatchs->template_alternate_row_color(&$this->t);
682 $sandbox_table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
683 $sandbox_table_data .= "<td align=\"Left\" width=\"1000\">$family_name</td>";
685 # get 12 months visit data for given family
686 for($m=$this->sandbox_stats_num_months; $m > 0; $m--) {
687 $month = $this->current_month - $m;
688 $year = $this->current_year;
689 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
690 if($month < 10) { $month = "0"."$month"; }
691 $month_start = "$year"."-"."$month"."-"."01";
692 $month_end = "$year"."-"."$month"."-"."31";
693 $month = "$month"."/"."$year";
695 if ($this->sandbox_visits_comp_only == 0) {
696 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' AND companionship!=0 AND family=". $family_id;
698 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' AND companionship=$tc_companionship AND family=". $family_id;
700 $query_id = $this->db3->query($sql,__LINE__,__FILE__);
702 if($this->db3->next_record()) {
703 if($this->db3->f('visited') == 'y') {
704 $sandbox_table_data .= "<td align=\"Right\"><img src=\"images/checkmark.gif\"></td>";
705 } else if($this->db3->f('visited') == 'n') {
706 $sandbox_table_data .= "<td align=\"Right\"><img src=\"images/x.gif\"></td>";
708 $sandbox_table_data .= "<td> </td>";
711 $sandbox_table_data .= "<td> </td>";
714 $sandbox_table_data .= "</tr>";
716 $sandbox_table_data .= "</table></td></tr>";
717 $sandbox_table_data .= "</table></td></tr>";
720 $sandbox_table_data .= "</table>";
721 $sandbox_table_data .= "</td>";
723 $sandbox_table_data .= "</tr>";
725 $sandbox_table_data .= "</table>";
726 $this->t->set_var('district_table',$sandbox_table_data);
728 $this->t->pfp('out','ht_sandbox_t');
729 $this->save_sessiondata();
732 function ht_sandbox_changes()
734 // list all companionships deleted
735 $email_contents = "Removed Companionships\n\n";
736 $sql = "SELECT * FROM tc_companionship WHERE companionship NOT IN (SELECT tc_companionship FROM tc_companionship_sandbox) AND valid=1";
737 $this->db->query($sql,__LINE__,__FILE__);
738 while ($this->db->next_record()) {
739 $companionship = $this->db->f('companionship');
740 $sql = "SELECT * FROM tc_companion AS tc JOIN tc_individual AS ti WHERE tc.individual=ti.individual AND tc.companionship=$companionship";
741 $this->db2->query($sql,__LINE__,__FILE__);
742 $companion_names = "";
743 while ($this->db2->next_record()) {
744 if ($companion_names == "") {
745 $companion_names .= $this->db2->f('name');
747 $companion_names .= " / " . $this->db2->f('name');
750 $email_contents .= "\t$companion_names\n";
752 $email_contents .= "\n\n\n";
754 // list all companionships added
755 $email_contents .= "New Companionships\n\n";
756 $sql = "SELECT * FROM tc_companionship_sandbox WHERE tc_companionship=0";
757 $this->db->query($sql,__LINE__,__FILE__);
758 while ($this->db->next_record()) {
759 $companionship = $this->db->f('companionship');
760 $sql = "SELECT * FROM tc_companion_sandbox AS tcs JOIN tc_individual AS ti WHERE tcs.individual=ti.individual AND tcs.companionship=$companionship";
761 $this->db2->query($sql,__LINE__,__FILE__);
762 $companion_names = "";
763 while ($this->db2->next_record()) {
764 if ($companion_names == "") {
765 $companion_names .= $this->db2->f('name');
767 $companion_names .= " / " . $this->db2->f('name');
770 $email_contents .= "\t$companion_names\n";
771 $sql = "SELECT * FROM tc_family_sandbox AS tfs JOIN tc_individual AS ti WHERE tfs.individual=ti.individual AND companionship=$companionship";
772 $this->db2->query($sql,__LINE__,__FILE__);
773 while ($this->db2->next_record()) {
774 $family_name = $this->db2->f('name') . " Family";
775 $email_contents .= "\t\t$family_name\n";
778 $email_contents .= "\n\n\n";
780 // list all companionships with changes
781 $email_contents .= "Modified Companionships\n\n";
782 $sql = "SELECT tcps.* FROM tc_companionship AS tc JOIN tc_companionship_sandbox AS tcps WHERE tc.companionship=tcps.tc_companionship";
783 $this->db->query($sql,__LINE__,__FILE__);
784 while ($this->db->next_record()) {
785 $companionship = $this->db->f('companionship');
786 $tc_companionship = $this->db->f('tc_companionship');
788 // compare companion list
790 // list removed families
791 // list added families
793 $email_contents .= "\n\n\n";
795 // email changes to presidency
796 $to = "owenleonard@gmail.com";
797 $subject = "HomeTeaching Changes";
798 $message .= "$email_contents";
799 $headers = 'From: webmaster@example.com' . "\r\n" .
800 'Reply-To: webmaster@example.com' . "\r\n" .
801 'X-Mailer: PHP/' . phpversion();
804 mail($to, $subject, $message, $headers);
809 $this->t->set_file(array('ht_update_t' => 'ht_update.tpl'));
810 $this->t->set_block('ht_update_t','district_list','list');
811 $this->t->set_block('ht_update_t','save','savehandle');
813 $district = get_var('district',array('GET','POST'));
814 $district_name = get_var('district_name',array('GET','POST'));
815 $date = get_var('date',array('GET','POST'));
816 $month = get_var('month',array('GET','POST'));
817 $month_start = get_var('month_start',array('GET','POST'));
818 $month_end = get_var('month_end',array('GET','POST'));
819 $action = get_var('action',array('GET','POST'));
821 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
822 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_update&action=save'));
823 $this->t->set_var('lang_done','Cancel');
824 $this->t->set_var('district_name',$district_name);
825 $this->t->set_var('district_number',$district);
826 $this->t->set_var('title','Hometeaching Update ' . $month);
827 $this->t->set_var('date',$date);
829 if($action == 'save') {
830 // Get a list of all the companionships in this district
831 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $district;
832 $this->db->query($sql,__LINE__,__FILE__);
833 $j=0; $unique_companionships = '';
834 while ($this->db->next_record()) {
835 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
838 for ($j=0; $j < count($unique_companionships); $j++) {
839 //$comp=$unique_companionships[$j]['companionship'];
840 //print "deleting from tc_visit where companionship=$comp and date=$date and district=$district<br>";
841 // Delete all the visits that have taken place for all families for this companionsthip for this month
842 $this->db->query("DELETE from tc_visit where companionship=" . $unique_companionships[$j]['companionship'] .
843 " AND " . "date='" . $date . "'",__LINE__,__FILE__);
846 // Now, add the visits that are checked for this month
847 $new_data = get_var('family_visited',array('POST'));
848 foreach ($new_data as $family) {
849 foreach ($family as $data) {
850 //print "family_visited: $data <br>";
851 $data_array = explode("/",$data);
852 $family_id = $data_array[0];
853 $companionship = $data_array[1];
854 $date = $data_array[2];
855 $visited = $data_array[3];
856 if($visited == "") { $visited = $data_array[4]; }
857 //print "family_id: $family_id companionship: $companionship date: $date visited: $visited<br>";
858 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes,visited) " .
859 "VALUES (" . $family_id .",". $companionship .",'". $date ."','','". $visited ."')",__LINE__,__FILE__);
866 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
867 $this->db->query($sql,__LINE__,__FILE__);
869 while ($this->db->next_record()) {
870 $individual[$i] = $this->db->f('individual');
871 $indiv_name[$i] = $this->db->f('name');
872 $indiv_phone[$individual[$i]] = $this->db->f('phone');
875 array_multisort($indiv_name, $individual);
877 // Make an array mapping individuals to indiv_names
878 for($i=0; $i < count($individual); $i++) {
879 $id = $individual[$i];
880 $indivs[$id] = $indiv_name[$i];
883 // Select all the unique companionship numbers for this district
884 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $district;
885 $this->db->query($sql,__LINE__,__FILE__);
886 $j=0; $unique_companionships = '';
887 while ($this->db->next_record()) {
888 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
892 $comp_width=300; $visit_width=25; $table_width=$comp_width + $visit_width;
893 $table_data=""; $num_companionships = 0; $num_families = 0; $visits=0;
894 for ($j=0; $j < count($unique_companionships); $j++) {
895 $companion_table_entry = "";
896 // Select all the companions in each companionship
897 $sql = "SELECT * FROM tc_companionship where valid=1 and ".
898 "companionship=". $unique_companionships[$j]['companionship'];
899 $this->db->query($sql,__LINE__,__FILE__);
901 while ($this->db->next_record()) {
902 // Get this companions information
903 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
904 $companionship = $this->db->f('companionship');
905 $individual = $this->db->f('individual');
906 $name = $indivs[$individual];
907 $phone = $indiv_phone[$individual];
908 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
910 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
912 // Get the names of the families assigned this home teaching companionship
913 $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'];
914 $sql = $sql . " ORDER BY ti.name ASC";
915 $this->db->query($sql,__LINE__,__FILE__);
916 while ($this->db->next_record()) {
917 $family_name = $this->db->f('name');
918 $family_id = $this->db->f('family');
919 $this->nextmatchs->template_alternate_row_color(&$this->t);
920 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
922 $header_row="<th width=$comp_width><font size=-2>Families</th>";
924 // First check to see if the currently assigned companionship has visited them
925 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
926 " AND companionship=".$unique_companionships[$j]['companionship'].
927 " AND family=". $family_id;
928 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
929 if($this->db2->num_rows($query_id) == 0) {
930 // We did not find any visits made by the currently assigned companionship,
931 // look for visits made by any other companionship other than 0. (0 == Presidency Visit)
932 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
933 " AND companionship!=0".
934 " AND family=". $family_id;
935 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
938 $value = $family_id . "/" . $unique_companionships[$j]['companionship'] . "/" . $date;
939 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
940 if(!$total_visits) { $total_visits = 0; }
941 if($this->db2->next_record()) {
942 if($this->db2->f('visited') == 'y') {
943 $visits++; $total_visits++; $num_families++;
944 $table_data .= '<td width=100 align=center>';
945 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y" checked>Y';
946 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
947 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/"> ';
948 $table_data .= '</td>';
949 } else if($this->db2->f('visited') == 'n') {
951 $table_data .= '<td width=100 align=center>';
952 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
953 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n" checked>N';
954 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/">';
955 $table_data .= '</td>';
957 $table_data .= '<td width=100 align=center>';
958 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
959 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
960 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
961 $table_data .= '</td>';
966 $table_data .= '<td width=100 align=center>';
967 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
968 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
969 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
970 $table_data .= '</td>';
973 $table_data .= "</tr>";
974 $table_data .= "<tr><td colspan=20></td></tr>";
976 $table_data .= "<tr><td colspan=20><hr></td></tr>";
977 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
979 $percent = ceil(($visits / $num_families)*100);
980 $stat_data .= "<td align=center><font size=-2><b>$visits / $num_families<br>$percent%</font></b></td>";
981 $stat_data .= "</tr>";
983 $this->t->set_var('table_width',$table_width);
984 $this->t->set_var('header_row',$header_row);
985 $this->t->set_var('table_data',$table_data);
986 $this->t->set_var('stat_data',$stat_data);
987 $this->t->fp('list','district_list',True);
989 $this->t->set_var('lang_reset','Clear Form');
990 $this->t->set_var('lang_save','Save Changes');
991 $this->t->set_var('savehandle','');
993 $this->t->pfp('out','ht_update_t');
994 $this->t->pfp('addhandle','save');
996 $this->save_sessiondata();
1001 $this->t->set_file(array('act_list_t' => 'act_list.tpl'));
1002 $this->t->set_block('act_list_t','act_list','list');
1004 $this->t->set_var('lang_name','Assignment');
1005 $this->t->set_var('lang_date','Date');
1006 $this->t->set_var('lang_notes','Description');
1008 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
1009 $this->db->query($sql,__LINE__,__FILE__);
1010 $total_records = $this->db->num_rows();
1013 while ($this->db->next_record()) {
1014 $activity_list[$i]['activity'] = $this->db->f('activity');
1015 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1016 $activity_list[$i]['date'] = $this->db->f('date');
1017 $activity_list[$i]['notes'] = $this->db->f('notes');
1019 $sql = "SELECT * FROM tc_assignment WHERE assignment='" . $activity_list[$i]['assignment'] . "'";
1020 $this->db2->query($sql,__LINE__,__FILE__);
1021 if($this->db2->next_record()) {
1022 $activity_list[$i]['name'] = $this->db2->f('name');
1023 $activity_list[$i]['abbreviation'] = $this->db2->f('abbreviation');
1028 for ($i=0; $i < count($activity_list); $i++) {
1029 $this->nextmatchs->template_alternate_row_color(&$this->t);
1030 $this->t->set_var('name',$activity_list[$i]['name']);
1031 $this->t->set_var('date',$activity_list[$i]['date']);
1032 $activity_notes = $activity_list[$i]['notes'];
1033 if(strlen($activity_notes) > 40) { $activity_notes = substr($activity_notes,0,40) . "..."; }
1034 $this->t->set_var('notes',$activity_notes);
1036 $link_data['menuaction'] = 'tc.tc.act_view';
1037 $link_data['activity'] = $activity_list[$i]['activity'];
1038 $link_data['action'] = 'view';
1039 $this->t->set_var('view',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
1040 $this->t->set_var('lang_view','View');
1042 $link_data['menuaction'] = 'tc.tc.act_update';
1043 $link_data['activity'] = $activity_list[$i]['activity'];
1044 $link_data['action'] = 'edit';
1045 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
1046 $this->t->set_var('lang_edit','Edit');
1048 $this->t->fp('list','act_list',True);
1051 $link_data['menuaction'] = 'tc.tc.act_update';
1052 $link_data['activity'] = '0';
1053 $link_data['action'] = 'add';
1054 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/tc/index.php',$link_data) .
1055 '"><input type="submit" name="Add" value="' . 'Add Activity' .'"></font></form>');
1057 $this->t->pfp('out','act_list_t');
1058 $this->save_sessiondata();
1063 $this->t->set_file(array('act_view_t' => 'act_view.tpl'));
1064 $this->t->set_block('act_view_t','part_list','list');
1066 $sql = "SELECT * FROM tc_activity WHERE activity=" . intval(get_var('activity',array('GET','POST')));
1067 $this->db->query($sql,__LINE__,__FILE__);
1068 $this->db->next_record();
1069 $this->t->set_var('assignment', $this->db->f('assignment'));
1070 $this->t->set_var('date', $this->db->f('date'));
1071 $this->t->set_var('notes', $this->db->f('notes'));
1073 $sql = "SELECT * FROM tc_assignment WHERE assignment='" . $this->db->f('assignment') . "'";
1074 $this->db2->query($sql,__LINE__,__FILE__);
1075 if($this->db2->next_record()) {
1076 $this->t->set_var('name', $this->db2->f('name'));
1077 $this->t->set_var('abbreviation', $this->db2->f('abbreviation'));
1079 $this->t->set_var('lang_name','Assignment');
1080 $this->t->set_var('lang_date','Date');
1081 $this->t->set_var('lang_notes','Description');
1082 $this->t->set_var('lang_done','Done');
1083 $this->t->set_var('lang_action','View');
1085 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1086 $this->t->set_var('tr_color',$tr_color);
1088 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_list'));
1090 $link_data['menuaction'] = 'tc.tc.act_update';
1091 $link_data['activity'] = get_var('activity',array('GET','POST'));
1092 $link_data['action'] = 'edit';
1093 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
1094 $this->t->set_var('lang_edit','Edit');
1095 $this->t->set_var('cal_date',$this->db->f('date'));
1097 // Now find out which indivs participated in this activity
1098 $sql = "SELECT * FROM tc_participation WHERE activity=" . intval(get_var('activity',array('GET','POST')));
1099 $this->db->query($sql,__LINE__,__FILE__);
1100 $total_records = $this->db->num_rows();
1103 while ($this->db->next_record()) {
1104 $part_list[$i]['individual'] = $this->db->f('individual');
1108 for ($i=0; $i < count($part_list); $i++) {
1109 $sql = "SELECT * FROM tc_individual WHERE individual=" . $part_list[$i]['individual'];
1110 $this->db->query($sql,__LINE__,__FILE__);
1111 $this->db->next_record();
1112 $names[$i] = $this->db->f('name');
1116 for ($i=0; $i < count($names); $i++) {
1117 //$this->nextmatchs->template_alternate_row_color(&$this->t);
1118 $this->t->set_var('individual_name',$names[$i]);
1119 if(($i+1) % 3 == 0) {
1120 $this->t->set_var('table_sep',"</td></tr><tr>");
1122 $this->t->set_var('table_sep',"</td>");
1124 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
1125 $this->t->fp('list','part_list',True);
1128 $this->t->pfp('out','act_view_t');
1129 $this->save_sessiondata();
1132 function act_update()
1134 $this->t->set_file(array('form' => 'act_update.tpl'));
1135 $this->t->set_block('form','individual_list','list');
1136 $this->t->set_block('form','add','addhandle');
1137 $this->t->set_block('form','edit','edithandle');
1138 $this->t->set_var('lang_done','Done');
1140 $action = get_var('action',array('GET','POST'));
1141 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_list'));
1142 $activity['activity'] = intval(get_var('activity',array('GET','POST')));
1144 if($action == 'save') {
1145 $activity['assignment'] = get_var('assignment',array('POST'));
1146 $activity['date'] = get_var('date',array('POST'));
1147 $activity['notes']= get_var('notes',array('POST'));
1148 $this->db->query("UPDATE tc_activity set " .
1149 " assignment='" . $activity['assignment'] .
1150 "', date='" . $activity['date'] . "'" .
1151 ", notes=\"" . $activity['notes'] . "\"" .
1152 " WHERE activity=" . $activity['activity'],__LINE__,__FILE__);
1154 // Delete all the individuals who have particiapted in this activity
1155 $this->db->query("DELETE from tc_participation where activity=".$activity['activity'],__LINE__,__FILE__);
1157 // Re-add the individuals who are checked as having participated in this activity
1158 $indivs = get_var('individual_name',array('POST'));
1159 if(is_array($indivs)) { // Only do the foreach loop if we have a valid array of indivs to work with
1160 foreach ($indivs as $individual) {
1161 $this->db->query("INSERT INTO tc_participation (individual,activity) " .
1162 "VALUES (" . $individual . ",". $activity['activity'] . ")",__LINE__,__FILE__);
1170 if($action == 'insert') {
1171 $activity['assignment'] = get_var('assignment',array('POST'));
1172 $activity['date'] = get_var('date',array('POST'));
1173 $activity['notes']= get_var('notes',array('POST'));
1174 $this->db->query("INSERT INTO tc_activity (assignment,date,notes) " .
1175 "VALUES ('" . $activity['assignment'] . "','" .
1176 $activity['date'] . "',\"" . $activity['notes'] . "\")",__LINE__,__FILE__);
1178 $sql = "SELECT * FROM tc_activity WHERE assignment='".$activity['assignment']."' " .
1179 " AND date='".$activity['date']."' AND notes=\"".$activity['notes']."\"";
1180 $this->db->query($sql,__LINE__,__FILE__);
1181 if($this->db->next_record()) {
1182 //print "activity: " . $this->db->f('activity') . "<br>";
1183 $activity['activity'] = $this->db->f('activity');
1186 $indivs = get_var('individual_name',array('POST'));
1187 foreach ($indivs as $individual)
1189 $this->db->query("INSERT INTO tc_participation (individual,activity) " .
1190 "VALUES (" . $individual . ",". $activity['activity'] . ")",__LINE__,__FILE__);
1197 if($action == 'add') {
1198 $activity['activity'] = 0;
1199 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
1200 $this->t->set_var('assignment','');
1201 $this->t->set_var('date','');
1202 $this->t->set_var('notes','');
1203 $this->t->set_var('lang_done','Cancel');
1204 $this->t->set_var('lang_action','Adding New Activity');
1205 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_update&activity=' .
1206 $activity['activity'] . '&action=' . 'insert'));
1209 if($action == 'edit') {
1210 $sql = "SELECT * FROM tc_activity WHERE activity=" . $activity['activity'];
1211 $this->db->query($sql,__LINE__,__FILE__);
1212 $this->db->next_record();
1213 $this->t->set_var('cal_date',$this->jscal->input('date',$this->db->f('date'),'','','','','',$this->cal_options));
1214 $this->t->set_var('assignment', $this->db->f('assignment'));
1215 $assignment = $this->db->f('assignment');
1216 $this->t->set_var('date', $this->db->f('date'));
1217 $this->t->set_var('notes', $this->db->f('notes'));
1218 $this->t->set_var('lang_done','Cancel');
1219 $this->t->set_var('lang_action','Editing Activity');
1220 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_update&activity=' .
1221 $activity['activity'] . '&action=' . 'save'));
1224 // Create the assignments drop-down list
1225 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1226 $this->db->query($sql,__LINE__,__FILE__);
1228 while ($this->db->next_record()) {
1229 $assignments[$i]['assignment'] = $this->db->f('assignment');
1230 $assignments[$i]['name'] = $this->db->f('name');
1231 $assignments[$i]['abbreviation'] = $this->db->f('abbreviation');
1235 $assignment_data.= '<select name=assignment>';
1236 $assignment_data.= '<option value=0></option>';
1237 for ($j=0; $j < count($assignments); $j++) {
1238 $id = $assignments[$j]['assignment'];
1239 $name = $assignments[$j]['name'];
1240 if($assignments[$j]['assignment'] == $assignment) {
1241 $selected[$id] = 'selected="selected"';
1243 $selected[$id] = '';
1245 $assignment_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1247 $assignment_data.='</select>';
1248 $this->t->set_var('assignment_data',$assignment_data);
1250 // Create individual selection boxes
1251 $sql = "SELECT * FROM tc_individual";
1252 $this->db->query($sql,__LINE__,__FILE__);
1254 while ($this->db->next_record()) {
1255 if($this->db->f('valid') == 1 || $action != 'add') {
1256 $indiv_name[$i] = $this->db->f('name');
1257 $individual[$i] = $this->db->f('individual');
1258 $indiv_valid[$i] = $this->db->f('valid');
1262 array_multisort($indiv_name, $individual, $indiv_valid);
1265 for ($i=0; $i < count($individual); $i++) {
1266 //$this->nextmatchs->template_alternate_row_color(&$this->t);
1267 $sql = "SELECT * FROM tc_participation where activity=". $activity['activity'] . " AND individual=" . $individual[$i];
1268 $this->db->query($sql,__LINE__,__FILE__);
1269 if($this->db->next_record()) {
1270 $this->t->set_var('checked','checked');
1273 $this->t->set_var('checked','');
1276 if($checked || $indiv_valid[$i] == 1) {
1277 $this->t->set_var('individual_name',$indiv_name[$i]);
1278 $this->t->set_var('individual',$individual[$i]);
1279 if(($j+1) % 3 == 0) {
1280 $this->t->set_var('table_sep',"</td></tr><tr>");
1282 $this->t->set_var('table_sep',"</td>");
1284 if(($j) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
1285 $this->t->fp('list','individual_list',True);
1290 $this->t->set_var('lang_reset','Clear Form');
1291 $this->t->set_var('lang_add','Add Activity');
1292 $this->t->set_var('lang_save','Save Changes');
1293 $this->t->set_var('edithandle','');
1294 $this->t->set_var('addhandle','');
1296 $this->t->pfp('out','form');
1297 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
1298 if($action == 'add') { $this->t->pfp('addhandle','add'); }
1300 $this->save_sessiondata();
1303 function assign_view()
1305 $this->t->set_file(array('assign_view_t' => 'assign_view.tpl'));
1306 $this->t->set_block('assign_view_t','assign_view','list');
1308 $this->t->set_var('lang_name','Assignment Name');
1309 $this->t->set_var('lang_code','Abbreviation');
1311 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1312 $this->db->query($sql,__LINE__,__FILE__);
1313 $total_records = $this->db->num_rows();
1316 while ($this->db->next_record()) {
1317 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1318 $assignment_list[$i]['name'] = $this->db->f('name');
1319 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1323 for ($i=0; $i < count($assignment_list); $i++) {
1324 $this->nextmatchs->template_alternate_row_color(&$this->t);
1325 $this->t->set_var('name',$assignment_list[$i]['name']);
1326 $this->t->set_var('abbreviation',$assignment_list[$i]['abbreviation']);
1328 $link_data['menuaction'] = 'tc.tc.assign_update';
1329 $link_data['assignment'] = $assignment_list[$i]['assignment'];
1330 $link_data['action'] = 'edit';
1331 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
1332 $this->t->set_var('lang_edit','Edit');
1334 $link_data['menuaction'] = 'tc.tc.assign_update';
1335 $link_data['assignment'] = '0';
1336 $link_data['action'] = 'add';
1337 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/tc/index.php',$link_data) .
1338 '"><input type="submit" name="Add" value="' . 'Add Assignment' .'"></font></form>');
1340 $this->t->fp('list','assign_view',True);
1343 $this->t->pfp('out','assign_view_t');
1344 $this->save_sessiondata();
1347 function assign_update()
1349 $this->t->set_file(array('form' => 'assign_update.tpl'));
1350 $this->t->set_block('form','add','addhandle');
1351 $this->t->set_block('form','edit','edithandle');
1352 $this->t->set_var('lang_done','Done');
1354 $action = get_var('action',array('GET','POST'));
1355 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_view'));
1356 $assignment['assignment'] = intval(get_var('assignment',array('GET','POST')));
1358 if($action == 'save') {
1359 $assignment['name'] = get_var('name',array('POST'));
1360 $assignment['abbreviation'] = get_var('abbreviation',array('POST'));
1361 $this->db->query("UPDATE tc_assignment set " .
1362 " name='" . $assignment['name'] . "'" .
1363 ", abbreviation='" . $assignment['abbreviation'] . "'" .
1364 " WHERE assignment=" . $assignment['assignment'],__LINE__,__FILE__);
1366 $this->assign_view();
1370 if($action == 'insert') {
1371 $assignment['name'] = get_var('name',array('POST'));
1372 $assignment['abbreviation'] = get_var('abbreviation',array('POST'));
1373 $this->db->query("INSERT INTO tc_assignment (name,abbreviation) " .
1374 "VALUES ('" . $assignment['name'] . "','" .
1375 $assignment['abbreviation'] . "')",__LINE__,__FILE__);
1376 $this->assign_view();
1380 if($action == 'add') {
1381 $assignment['assignment'] = 0;
1382 $this->t->set_var('name','');
1383 $this->t->set_var('abbreviation','');
1384 $this->t->set_var('lang_done','Cancel');
1385 $this->t->set_var('lang_action','Adding New Assignment');
1386 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_update&assignment=' .
1387 $assignment['assignment'] . '&action=' . 'insert'));
1390 if($action == 'edit')
1392 $sql = "SELECT * FROM tc_assignment WHERE assignment=" . $assignment['assignment'];
1393 $this->db->query($sql,__LINE__,__FILE__);
1394 $this->db->next_record();
1395 $this->t->set_var('name', $this->db->f('name'));
1396 $this->t->set_var('abbreviation', $this->db->f('abbreviation'));
1397 $this->t->set_var('lang_done','Cancel');
1398 $this->t->set_var('lang_action','Editing Assignment');
1399 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_update&assignment=' .
1400 $assignment['assignment'] . '&action=' . 'save'));
1403 $this->t->set_var('lang_reset','Clear Form');
1404 $this->t->set_var('lang_add','Add Assignment');
1405 $this->t->set_var('lang_save','Save Changes');
1406 $this->t->set_var('edithandle','');
1407 $this->t->set_var('addhandle','');
1409 $this->t->pfp('out','form');
1410 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
1411 if($action == 'add') { $this->t->pfp('addhandle','add'); }
1413 $this->save_sessiondata();
1418 $this->t->set_file(array('par_view_t' => 'par_view.tpl'));
1419 $this->t->set_block('par_view_t','header_list','list1');
1420 $this->t->set_block('par_view_t','individual_list','list2');
1422 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
1423 $this->db->query($sql,__LINE__,__FILE__);
1425 while ($this->db->next_record()) {
1426 $individual_name[$i] = $this->db->f('name');
1427 $individual[$i] = $this->db->f('individual');
1430 array_multisort($individual_name, $individual);
1432 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
1433 $this->db->query($sql,__LINE__,__FILE__);
1434 $total_records = $this->db->num_rows();
1437 while ($this->db->next_record()) {
1438 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1439 $activity_list[$i]['date'] = $this->db->f('date');
1440 $activity_list[$i]['activity'] = $this->db->f('activity');
1444 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1445 $this->db->query($sql,__LINE__,__FILE__);
1447 while($this->db->next_record()) {
1448 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1449 $assignment_list[$i]['name'] = $this->db->f('name');
1450 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1454 $individual_width=300; $part_width=25; $assignment_width=50;
1455 $total_width=$individual_width+$part_width;
1456 for ($i=0; $i < count($assignment_list); $i++) {
1457 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1458 $this->t->set_var('assignment_abbreviation',$assignment_list[$i]['abbreviation']);
1459 $this->t->fp('list1','header_list',True);
1460 $total_width += $assignment_width;
1463 for ($i=0; $i < count($individual); $i++) {
1464 $participated=0; $part_table = '';
1465 $this->nextmatchs->template_alternate_row_color(&$this->t);
1466 $this->t->set_var('individual_name',$individual_name[$i]);
1467 for ($j=0; $j < count($assignment_list); $j++) {
1468 $date = "0000-00-00"; $checkmark=0; $num_matches=0;
1469 for ($k=0; $k < count($activity_list); $k++) {
1470 if($assignment_list[$j]['assignment'] == $activity_list[$k]['assignment']) {
1471 $sql = "SELECT * FROM tc_participation where " .
1472 " activity=" . $activity_list[$k]['activity'] .
1473 " AND individual=" . $individual[$i];
1474 $this->db->query($sql,__LINE__,__FILE__);
1475 while($this->db->next_record()) {
1476 if($activity_list[$k]['date'] > $date) {
1477 $date = $activity_list[$k]['date'];
1486 $part_table .= '<td align=center><img src="images/checkmark.gif">';
1487 $part_table .= '<font size=-2>'.$num_matches.'</font><br>';
1488 $part_table .= '<font size=-2>'.$date.'</font></td>';
1490 $part_table .= '<td> </td>';
1494 $part_table .= '<td align=center><img src="images/checkmark.gif">'.$participated.'</td>';
1496 $part_table .= '<td> </td>';
1498 $this->t->set_var('part_table',$part_table);
1499 $this->t->fp('list2','individual_list',True);
1501 $this->t->set_var('total_width',$total_width);
1502 $this->t->set_var('individual_width',$individual_width);
1503 $this->t->set_var('part_width',$part_width);
1504 $this->t->set_var('act_width',$act_width);
1505 $this->t->pfp('out','par_view_t');
1506 $this->save_sessiondata();
1509 function willing_view()
1511 $this->t->set_file(array('willing_view_t' => 'willing_view.tpl'));
1512 $this->t->set_block('willing_view_t','header_list','list1');
1513 $this->t->set_block('willing_view_t','individual_list','list2');
1515 $this->t->set_var('lang_filter','Filter');
1516 $this->t->set_var('lang_filter_unwilling','Filter out unwilling individuals:');
1518 $filter_unwilling = get_var('filter_unwilling',array('POST'));
1519 $this->t->set_var('filter_unwilling',$filter_unwilling);
1521 if($filter_unwilling == 'y' || $filter_unwilling == '') {
1522 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\" checked>Y";
1523 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\">N";
1524 $filter_input.= " ";
1526 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\">Y";
1527 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\" checked>N";
1528 $filter_input.= " ";
1530 $this->t->set_var('filter_input',$filter_input);
1532 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
1533 $this->db->query($sql,__LINE__,__FILE__);
1535 while ($this->db->next_record()) {
1536 $indiv_name[$i] = $this->db->f('name');
1537 $individual[$i] = $this->db->f('individual');
1538 $indiv_phone[$individual[$i]] = $this->db->f('phone');
1541 array_multisort($indiv_name, $individual);
1543 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1544 $this->db->query($sql,__LINE__,__FILE__);
1546 while($this->db->next_record()) {
1547 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1548 $assignment_list[$i]['name'] = $this->db->f('name');
1549 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1553 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
1554 $this->db->query($sql,__LINE__,__FILE__);
1555 $total_records = $this->db->num_rows();
1558 while ($this->db->next_record()) {
1559 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1560 $activity_list[$i]['date'] = $this->db->f('date');
1561 $activity_list[$i]['activity'] = $this->db->f('activity');
1565 $indiv_width=275; $willing_width=40; $assignment_width=50;
1566 $total_width=$indiv_width+$willing_width;
1568 for ($i=0; $i < count($assignment_list); $i++) {
1569 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1570 $this->t->set_var('assignment_abbreviation',$assignment_list[$i]['abbreviation']);
1571 $this->t->fp('list1','header_list',True);
1572 $total_width += $assignment_width;
1573 $total_willing[$i] = 0;
1576 for ($i=0; $i < count($individual); $i++) {
1577 $willing_table = ''; $indiv_willing=0;
1578 $this->t->set_var('individual_name',$indiv_name[$i]);
1579 $this->t->set_var('individual_phone',$indiv_phone[$individual[$i]]);
1580 $this->t->set_var('editurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_update&individual=' .
1581 $individual[$i] . '&action=' . 'edit'));
1582 for ($j=0; $j < count($assignment_list); $j++) {
1583 $found_willingness=0;
1584 $sql = "SELECT * FROM tc_willingness where " .
1585 " assignment=" . $assignment_list[$j]['assignment'] .
1586 " AND individual=" . $individual[$i];
1587 $this->db->query($sql,__LINE__,__FILE__);
1588 while($this->db->next_record()) {
1589 $found_willingness=1;
1591 $sql = "SELECT * FROM tc_activity where " .
1592 " assignment=". $assignment_list[$j]['assignment'] .
1593 " ORDER by date DESC";
1594 $this->db2->query($sql,__LINE__,__FILE__);
1595 if($this->db2->next_record()) {
1596 $activity = $this->db2->f('activity');
1597 $date = $this->db2->f('date');
1598 $sql = "SELECT * FROM tc_participation where " .
1599 " activity=" . $activity .
1600 " AND individual=". $individual[$i];
1601 $this->db3->query($sql,__LINE__,__FILE__);
1602 if($this->db3->next_record()) {
1607 if($this->db->f('willing') == 'y') {
1608 $total_willing[$j]++;
1610 $willing_table .= '<td align=center><img src="images/checkmark.gif"><br><font size=-2>'.$date_part.'</font></td></td>';
1611 } else if($this->db->f('willing') == 'n') {
1612 $willing_table .= '<td align=center><img src="images/x.gif"></td>';
1615 $willing_table .= "<td> </td>";
1618 if(!$found_willingness) {
1620 $willing_table .= "<td> </td>";
1623 if(($indiv_willing == 1) || ($filter_unwilling == 'n')) {
1624 $this->t->set_var('willing_table',$willing_table);
1625 $this->t->fp('list2','individual_list',True);
1626 $this->nextmatchs->template_alternate_row_color(&$this->t);
1630 $stat_table = '<td><b>Total Willing to Serve</b></td>';
1631 for ($j=0; $j < count($assignment_list); $j++) {
1632 $stat_table .= "<td align=center><b>".$total_willing[$j]."</b></td>";
1634 $this->t->set_var('stat_table',$stat_table);
1636 $this->t->set_var('total_width',$total_width);
1637 $this->t->set_var('individual_width',$indiv_width);
1638 $this->t->set_var('willing_width',$willing_width);
1639 $this->t->pfp('out','willing_view_t');
1640 $this->save_sessiondata();
1643 function willing_update()
1645 //print "<font color=red>Willingness Update Under Constrcution</font>";
1646 //$this->willing_view();
1649 $this->t->set_file(array('willing_update_t' => 'willing_update.tpl'));
1650 $this->t->set_block('willing_update_t','assignment_list','list');
1651 $this->t->set_block('willing_update_t','save','savehandle');
1653 $individual = get_var('individual',array('GET','POST'));
1654 $this->t->set_var('individual',$individual);
1655 $action = get_var('action',array('GET','POST'));
1657 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_view'));
1658 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_update&action=save'));
1659 $this->t->set_var('lang_done','Cancel');
1660 $this->t->set_var('title','Willingness Update ');
1662 if($action == 'save') {
1663 // Delete all the previous willingness entries for this individual
1664 $this->db->query("DELETE from tc_willingness where individual=" . $individual ,__LINE__,__FILE__);
1666 // Now, add the assignment willingness that is checked for this individual
1667 $new_data = get_var('willingness',array('POST'));
1668 foreach ($new_data as $data) {
1669 $data_array = explode("/",$data);
1670 $assignment = $data_array[0];
1671 $willing = $data_array[1];
1672 //print "individual: $individual assignment: $assignment willing: $willing<br>";
1673 $this->db->query("INSERT INTO tc_willingness (individual,assignment,willing) " .
1674 "VALUES (" . $individual .",". $assignment .",'". $willing . "')",__LINE__,__FILE__);
1676 $this->willing_view();
1680 $assignment_width=300; $willing_width=25; $table_width=$assignment_width + $willing_width;
1683 // Find out the individual's name
1684 $sql = "SELECT * FROM tc_individual WHERE individual=".$individual." AND valid=1";
1685 $this->db->query($sql,__LINE__,__FILE__);
1686 if($this->db->next_record()) {
1687 $indiv_name = $this->db->f('name');
1688 $this->t->set_var('individual_name',$indiv_name);
1691 // Select all the assignments
1692 $sql = "SELECT * FROM tc_assignment ORDER by name ASC";
1693 $this->db->query($sql,__LINE__,__FILE__);
1695 while ($this->db->next_record()) {
1696 $assignment = $this->db->f('assignment');
1697 $assignment_name = $this->db->f('name');
1698 $assignment_abbreviation = $this->db->f('abbreviation');
1700 $this->nextmatchs->template_alternate_row_color(&$this->t);
1701 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$assignment_name</td>";
1703 $header_row="<th width=$comp_width><font size=-2>Assignments</th><th>Willingness</th>";
1704 $sql = "SELECT * FROM tc_willingness WHERE individual=".$individual." AND assignment=".$assignment;
1705 $this->db2->query($sql,__LINE__,__FILE__);
1706 $value = $assignment;
1708 if($this->db2->next_record()) {
1709 if($this->db2->f('willing') == 'y') {
1710 $table_data .= '<td width=100 align=center>';
1711 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y" checked>Y';
1712 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1713 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/"> ';
1714 $table_data .= '</td>';
1715 } else if($this->db2->f('willing') == 'n') {
1716 $table_data .= '<td width=100 align=center>';
1717 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1718 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n" checked>N';
1719 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/">';
1720 $table_data .= '</td>';
1722 $table_data .= '<td width=100 align=center>';
1723 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1724 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1725 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1726 $table_data .= '</td>';
1729 $table_data .= '<td width=100 align=center>';
1730 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1731 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1732 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1733 $table_data .= '</td>';
1736 $table_data .= "\n";
1737 $table_data .= "</tr>";
1738 $table_data .= "<tr><td colspan=20></td></tr>";
1741 $table_data .= "<tr><td colspan=20><hr></td></tr>";
1743 $this->t->set_var('table_width',$table_width);
1744 $this->t->set_var('header_row',$header_row);
1745 $this->t->set_var('table_data',$table_data);
1746 $this->t->fp('list','assignment_list',True);
1748 $this->t->set_var('lang_reset','Clear Form');
1749 $this->t->set_var('lang_save','Save Changes');
1750 $this->t->set_var('savehandle','');
1752 $this->t->pfp('out','willing_update_t');
1753 $this->t->pfp('addhandle','save');
1755 $this->save_sessiondata();
1759 function ppi_sched()
1761 $this->t->set_file(array('ppi_sched_t' => 'ppi_sched.tpl'));
1762 $this->t->set_block('ppi_sched_t','individual_list','indivlist');
1763 $this->t->set_block('ppi_sched_t','appt_list','apptlist');
1764 $action = get_var('action',array('GET','POST'));
1766 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1767 $this->t->set_var('lang_reset','Clear Changes');
1769 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
1770 $this->t->set_var('ppi_link_title',$this->ppi_frequency_label . ' PPIs');
1772 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
1773 $this->t->set_var('schedule_ppi_link_title','Schedule ' . $this->ppi_frequency_label . ' PPIs');
1775 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched&action=save'));
1776 $this->t->set_var('title',$this->ppi_frequency_label . ' PPI Scheduler');
1778 $header_row = "<th ><font size=-2>Individual Name</th>";
1779 $header_row.= "<th><font size=-2>Phone</th>";
1780 $header_row.= "<th><font size=-2>Priority</th>";
1781 $header_row.= "<th><font size=-2>Last PPI</th>";
1782 $header_row.= "<th><font size=-2>Scheduling Notes</th>";
1783 $table_data=""; $completed_data=""; $totals_data="";
1787 $period = intval(($month-1)/$this->ppi_frequency) + 1;
1788 $start_of_period = ($period-1)*$this->ppi_frequency + 1;
1789 $end_of_period = $period * $this->ppi_frequency;
1791 if($action == 'save') {
1792 // Save any changes made to the appointment table
1793 $new_data = get_var('appt_notes',array('POST'));
1794 if($new_data != "") {
1795 foreach ($new_data as $entry) {
1796 $indiv = $entry['individual'];
1797 $appointment = $entry['appointment'];
1798 $location = $entry['location'];
1799 $presidency_location = $entry['presidency_location'];
1800 if($location == "") { $location = $presidency_location; }
1801 if($indiv == 0) { $location = ""; }
1803 //Only perform a database update if we have made a change to this appointment
1804 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and individual='$indiv' and location='$location'";
1805 $this->db->query($sql,__LINE__,__FILE__);
1806 if(!$this->db->next_record()) {
1807 // Perform database save actions here
1808 $this->db->query("UPDATE tc_appointment set " .
1809 " individual='" . $indiv . "'" .
1810 ",location='" . $location . "'" .
1811 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1812 // Email the appointment
1813 $this->email_appt($appointment);
1818 // Save any changes made to the ppi notes table
1819 $new_data = get_var('notes',array('POST'));
1820 foreach ($new_data as $entry) {
1821 $notes = $entry['notes'];
1822 $individual = $entry['individual'];
1823 $priority = $entry['pri'];
1825 // Perform database save actions here
1826 $sql = "SELECT * FROM tc_individual WHERE individual='$individual'";
1827 $this->db->query($sql,__LINE__,__FILE__);
1828 if ($this->db->next_record()) {
1829 $scheduling_priority = $this->db->f('scheduling_priority');
1830 //$this->logToFile("ppi_sched", "UPDATE tc_scheduling_priority SET priority='$priority', notes=\"$notes\" WHERE scheduling_priority='$scheduling_priority'");
1831 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$priority', notes=\"$notes\" WHERE scheduling_priority='$scheduling_priority'", __LINE__, __FILE__);
1835 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched');
1836 //Header('Location: ' . $take_me_to_url);
1839 // create the individual id -> individual name mapping
1840 $sql = "SELECT * FROM tc_individual where valid=1 and steward='$this->default_stewardship' ORDER BY name ASC";
1841 $this->db->query($sql,__LINE__,__FILE__);
1845 while ($this->db->next_record()) {
1846 $indiv_name[$i] = $this->db->f('name');
1847 $individual[$i] = $this->db->f('individual');
1850 array_multisort($indiv_name, $individual);
1852 // APPOINTMENT TABLE
1853 $appt_header_row = "<th><font size=-2>Date</th>";
1854 $appt_header_row.= "<th><font size=-2>Time</th>";
1855 $appt_header_row.= "<th><font size=-2>Individual</th>";
1856 $appt_header_row.= "<th><font size=-2>Location</th>";
1857 $appt_table_data = "";
1860 $total_indivs=0; $indivs_with_yearly_ppi=0;
1862 // Get the President
1863 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti where tp.individual=ti.individual AND tp.valid=1 AND ";
1864 if($this->yearly_ppi_interviewer == 1) { $sql .= " (tp.president=1)"; }
1865 if($this->yearly_ppi_interviewer == 2) { $sql .= " (tp.president=1 OR tp.counselor=1)"; }
1866 if($this->yearly_ppi_interviewer == 3) { $sql .= " (tp.president=1 OR tp.counselor=1 OR tp.secretary=1)"; }
1867 $this->db->query($sql,__LINE__,__FILE__);
1868 while ($this->db->next_record()) {
1869 $presidency_name = $this->db->f('name');
1870 $presidency_name_array = explode(",",$presidency_name);
1871 $presidency_last_name = $presidency_name_array[0];
1872 $presidency_id = $this->db->f('presidency');
1873 $presidency_address = $this->db->f('address');
1874 $presidency_location = "$presidency_last_name"." home ($presidency_address)";
1875 $appt_table_data = "";
1877 // Display a scheduling table for this presidency member
1878 $not_completed_table_title = "All individuals with " . $this->ppi_frequency_label . " PPI Not Completed";
1879 $appt_table_title = $presidency_name . ": " . $this->ppi_frequency_label." PPI Appointment Slots";
1880 $this->t->set_var('not_completed_table_title',$not_completed_table_title);
1881 $this->t->set_var('appt_table_title',$appt_table_title);
1883 // query the database for all the appointments
1884 $sql = "SELECT * FROM tc_appointment where presidency=".$presidency_id." and date>=CURDATE() ORDER BY date ASC, time ASC";
1885 $this->db2->query($sql,__LINE__,__FILE__);
1887 while ($this->db2->next_record()) {
1888 $appointment = $this->db2->f('appointment');
1889 $indiv = $this->db2->f('individual');
1890 $location = $this->db2->f('location');
1891 if(($location == "") && ($indiv > 0)) { $location = $presidency_location; }
1893 $date = $this->db2->f('date');
1894 $date_array = explode("-",$date);
1895 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1896 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1898 $time = $this->db2->f('time');
1899 $time_array = explode(":",$time);
1900 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1902 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1903 $appt_table_data.= "<td align=center>$day_string</td>";
1904 $appt_table_data.= "<td align=center>$time_string</td>";
1906 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][individual]>';
1907 $appt_table_data.= '<option value=0></option>';
1908 for ($i=0; $i < count($individual); $i++) {
1909 $id = $individual[$i];
1910 $name = $indiv_name[$i];
1911 if($individual[$i] == $indiv) {
1912 $selected[$id] = 'selected="selected"';
1914 $selected[$id] = '';
1916 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1918 $appt_table_data.='</select></td>';
1920 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
1921 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
1923 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1925 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1926 $this->t->set_var('tr_color',$tr_color);
1928 $this->t->set_var('appt_table_data',$appt_table_data);
1929 $this->t->set_var('appt_header_row',$appt_header_row);
1930 $this->t->set_var('lang_save','Save Appts for ' . $presidency_name);
1932 $this->t->fp('apptlist','appt_list',True);
1935 // PPI SCHEDULING TABLE
1936 $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";
1937 $this->db->query($sql,__LINE__,__FILE__);
1941 while ($this->db->next_record()) {
1942 $individual[$i] = $this->db->f('individual');
1943 $indiv_name[$i] = $this->db->f('name');
1944 $indiv_phone[$individual[$i]] = $this->db->f('phone');
1945 $indiv_priority[$individual[$i]] = $this->db->f('priority');
1946 $indiv_notes[$individual[$i]] = $this->db->f('notes');
1951 $max = count($individual);
1953 for($i=0; $i < $max; $i++) {
1954 $id = $individual[$i];
1955 $name = $indiv_name[$i];
1956 $phone = $indiv_phone[$id];
1957 $priority = $indiv_priority[$id];
1958 $notes = $indiv_notes[$id];
1960 // If this individual has had a PPI this period, don't show him on the schedule list
1961 $year_start = $year . "-" . $start_of_period . "-01";
1962 $year_end = $year . "-" . $end_of_period . "-31";
1963 $sql = "SELECT * FROM tc_interview WHERE date >= '$year_start' AND date <= '$year_end' ".
1964 "AND individual=" . $id . " AND interview_type='ppi' ORDER BY date DESC";
1965 $this->db2->query($sql,__LINE__,__FILE__);
1967 if(!$this->db2->next_record()) {
1968 $sql = "SELECT * FROM tc_interview WHERE individual=" . $id . " AND interview_type='ppi' ORDER BY date DESC";
1969 $this->db->query($sql,__LINE__,__FILE__);
1970 if($this->db->next_record()) {
1971 $date = $this->db->f('date');
1975 $link_data['menuaction'] = 'tc.tc.ppi_update';
1976 $link_data['individual'] = $id;
1977 $link_data['name'] = $name;
1978 $link_data['interview'] = '';
1979 $link_data['interview_type'] = 1;
1980 $link_data['action'] = 'add';
1981 $link_data['interviewer'] = $interviewer;
1982 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1983 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1984 $this->t->set_var('tr_color',$tr_color);
1985 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1986 $table_data.= "<td align=center>$phone</td>";
1987 //$table_data.= "<td align=center>$priority</td>";
1988 $table_data.= "<td align=center>";
1989 $table_data.= '<select name=notes['.$i.'][pri]>';
1990 foreach(range(0,6) as $num) {
1991 if($num == 0) { $num = 1; } else {$num = $num*5; }
1992 if($priority == $num) {
1993 $selected[$num] = 'selected="selected"';
1995 $selected[$num] = '';
1997 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1999 $table_data.= '</select></td>';
2000 $table_data.= "<td align=center>$date</td>";
2001 $table_data.= '<td><input type=text size="50" maxlength="128" name="notes['.$i.'][notes]" value="'.$notes.'">';
2002 $table_data.= '<input type=hidden name="notes['.$i.'][individual]" value="'.$id.'">';
2003 $table_data.= '<input type=hidden name="notes['.$i.'][indiv_name]" value="'.$name.'">';
2004 $table_data.= '</td>';
2005 $table_data.= '</tr>';
2007 $link_data['menuaction'] = 'tc.tc.ppi_update';
2008 $link_data['interviewer'] = $this->db2->f('interviewer');
2009 $link_data['individual'] = $this->db2->f('individual');
2010 $link_data['name'] = $name;
2011 $link_data['interview'] = $this->db2->f('interview');
2012 $link_data['interview_type'] = $this->db2->f('interview_type');
2013 $link_data['action'] = 'view';
2014 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2015 $indivs_with_yearly_ppi++;
2016 $date = $this->db2->f('date');
2017 $notes = $this->db2->f('notes');
2018 if(strlen($notes) > 40) { $notes = substr($notes,0,40) . "..."; }
2019 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
2020 $this->t->set_var('tr_color2',$tr_color2);
2021 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2022 $completed_data.= "<td align=center>$phone</td>";
2023 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2024 $completed_data.= "<td align=left>$notes</td>";
2025 $completed_data.= '</tr>';
2027 } // End for individuals Loop
2029 $completed_table_title = "All individuals with " . $this->ppi_frequency_label . " PPI Completed";
2030 $completed_header_row = "<th><font size=-2>Individual</th>";
2031 $completed_header_row.= "<th><font size=-2>Phone</th>";
2032 $completed_header_row.= "<th><font size=-2>Date</th>";
2033 $completed_header_row.= "<th><font size=-2>PPI Notes</th>";
2035 $this->t->set_var('completed_table_title',$completed_table_title);
2036 $this->t->set_var('header_row',$header_row);
2037 $this->t->set_var('table_data',$table_data);
2038 $this->t->set_var('completed_header_row',$completed_header_row);
2039 $this->t->set_var('completed',$completed_data);
2040 $this->t->set_var('lang_save','Save Pri / Notes');
2041 $this->t->fp('indivlist','individual_list',True);
2043 $totals_header_row = "<th><font size=-2>Individuals</th>";
2044 $totals_header_row.= "<th><font size=-2>$year</th>";
2045 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2046 $totals_data.= "<td align=left><font size=-2><b>Total Individuals with " . $this->ppi_frequency_label . " PPIs completed:</b></font></td>";
2047 $totals_data.= "<td align=center><font size=-2><b>$indivs_with_yearly_ppi / $total_indivs</b></font></td>";
2048 $percent = ceil(($indivs_with_yearly_ppi / $total_indivs)*100);
2049 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2050 $this->t->set_var('tr_color',$tr_color);
2051 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2052 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2053 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2054 $totals_data.= "</tr>";
2056 $this->t->set_var('totals',$totals_data);
2057 $this->t->set_var('totals_header_row',$totals_header_row);
2058 $this->t->set_var('ppi_frequency_label',$this->ppi_frequency_label);
2060 $this->t->pfp('out','ppi_sched_t');
2061 $this->save_sessiondata();
2065 function int_sched()
2067 $this->t->set_file(array('int_sched_t' => 'int_sched.tpl'));
2068 $this->t->set_block('int_sched_t','individual_list','indivlist');
2069 $this->t->set_block('int_sched_t','appt_list','apptlist');
2070 $action = get_var('action',array('GET','POST'));
2072 $this->t->set_var('lang_reset','Clear Changes');
2074 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2075 $this->t->set_var('int_link_title','Hometeaching Interviews');
2077 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
2078 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
2080 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched&action=save'));
2081 $this->t->set_var('title','Hometeaching Interviews Scheduler');
2083 $header_row = "<th><font size=-2>Individual</th>";
2084 $header_row.= "<th><font size=-2>Phone</th>";
2085 $header_row.= "<th><font size=-2>Priority</th>";
2086 $header_row.= "<th><font size=-2>Last Interview</th>";
2087 $header_row.= "<th><font size=-2>Scheduling Notes</th>";
2088 $table_data=""; $completed_data=""; $totals_data="";
2092 $nextyear = $year + 1;
2093 if($month >= 1 && $month <= 3) { $quarter_start=$year."-01-01"; $quarter_end=$year."-04-01"; }
2094 if($month >= 4 && $month <= 6) { $quarter_start=$year."-04-01"; $quarter_end=$year."-07-01"; }
2095 if($month >= 7 && $month <= 9) { $quarter_start=$year."-07-01"; $quarter_end=$year."-10-01"; }
2096 if($month >= 10 && $month <= 12) { $quarter_start=$year."-10-01"; $quarter_end=$nextyear."-01-01"; }
2097 //print "year: $year month: $month quarter_start: $quarter_start quarter_end: $quarter_end<br>";
2099 // create the individual id -> individual name mapping
2100 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY name ASC";
2101 $this->db->query($sql,__LINE__,__FILE__);
2103 $individual_data = NULL;
2104 $indiv_name_data = NULL;
2105 while ($this->db->next_record()) {
2106 $indiv_name_data[$i] = $this->db->f('name');
2107 $individual_data[$i] = $this->db->f('individual');
2108 $individ2name[$individual_data[$i]] = $indiv_name_data[$i];
2111 // add any YM that are home teachers
2112 $sql = "SELECT * FROM tc_companionship where valid=1";
2113 $this->db->query($sql,__LINE__,__FILE__);
2114 while ($this->db->next_record()) {
2115 $tmp_individual = $this->db->f('individual');
2116 $sql = "Select * FROM tc_individual where individual='$tmp_individual' and steward='' and valid=1";
2117 $this->db2->query($sql,__LINE__,__FILE__);
2118 while ($this->db2->next_record()) {
2119 $indiv_name_data[$i] = $this->db2->f('name');
2120 $individual_data[$i] = $this->db2->f('individual');
2121 $individ2name[$individual_data[$i]] = $indiv_name_data[$i];
2125 array_multisort($indiv_name_data, $individual_data);
2127 if($action == 'save') {
2128 // Save any changes made to the appointment table
2129 $new_data = get_var('appt_notes',array('POST'));
2130 if($new_data != "") {
2131 foreach ($new_data as $entry) {
2132 $indiv = $entry['individual'];
2133 $appointment = $entry['appointment'];
2134 $location = $entry['location'];
2135 if($location == "") {
2136 $supervisor = $entry['supervisor'];
2137 $supervisor_array = explode(",", $individ2name[$supervisor]);
2138 $supervisor_last_name = $supervisor_array[0];
2139 $sql = "SELECT * FROM tc_individual where individual='$supervisor'";
2140 $this->db2->query($sql,__LINE__,__FILE__);
2141 if($this->db2->next_record()) {
2142 $supervisor_address = $this->db2->f('address');
2144 $location = "$supervisor_last_name"." home ($supervisor_address)";
2146 if($indiv == 0) { $location = ""; }
2148 //print "indiv: $indiv appointment: $appointment <br>";
2149 //Only perform a database update if we have made a change to this appointment
2150 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and individual='$indiv' and location='$location'";
2151 $this->db->query($sql,__LINE__,__FILE__);
2152 if(!$this->db->next_record()) {
2153 // Perform database save actions here
2154 $this->db->query("UPDATE tc_appointment set " .
2155 " individual='" . $indiv . "'" .
2156 ",location='" . $location . "'" .
2157 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
2158 // Email the appointment
2159 $this->email_appt($appointment);
2164 // Save any changes made to the int notes table
2165 $new_data = get_var('hti_notes',array('POST'));
2166 foreach ($new_data as $entry) {
2167 $hti_notes = $entry['notes'];
2168 $individual = $entry['individual'];
2169 $indiv_name = $entry['indiv_name'];
2170 $hti_pri = $entry['pri'];
2171 //print "hti_notes: $hti_notes indiv_name: $indiv_name <Br>";
2172 // Perform database save actions here
2173 $this->db->query("SELECT * FROM tc_companion WHERE individual=$individual and valid=1",__LINE__,__FILE__);
2174 if ($this->db->next_record()) {
2175 $scheduling_priority = $this->db->f('scheduling_priority');
2176 //$this->logToFile("int_sched", "UPDATE tc_scheduling_priority SET priority='$hti_pri', notes=\"$hti_notes\" WHERE scheduling_priority='$scheduling_priority'");
2177 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$hti_pri', notes=\"$hti_notes\" WHERE scheduling_priority='$scheduling_priority'",__LINE__,__FILE__);
2181 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched');
2182 //Header('Location: ' . $take_me_to_url);
2185 // Get the Districts
2186 $sql = "SELECT * FROM tc_district AS td JOIN (tc_presidency AS tp, tc_individual AS ti) WHERE td.district=tp.district AND td.supervisor=ti.individual AND td.valid=1 ORDER BY td.district ASC";
2187 $this->db->query($sql,__LINE__,__FILE__);
2189 while ($this->db->next_record()) {
2190 $district = $this->db->f('district');
2191 $districts[$i]['district'] = $this->db->f('district');
2192 $districts[$i]['name'] = $this->db->f('name');
2193 $districts[$i]['supervisor'] = $this->db->f('supervisor');
2194 $districts[$i]['presidency'] = $this->db->f('presidency');
2198 // APPOINTMENT TABLE
2200 $appt_header_row = "<th><font size=-2>Date</th>";
2201 $appt_header_row.= "<th><font size=-2>Time</th>";
2202 $appt_header_row.= "<th><font size=-2>Individual</th>";
2203 $appt_header_row.= "<th><font size=-2>Location</th>";
2204 $appt_table_data = "";
2206 $total_comps=0; $comps_with_quarterly_int=0;
2208 // Display a scheduling table for each district
2209 for ($d=0; $d < count($districts); $d++) {
2210 $table_data=""; $appt_table_data="";
2211 $this->t->set_var('district_number',$districts[$d]['district']);
2212 $this->t->set_var('district_name',$districts[$d]['name']);
2213 $supervisor = $districts[$d]['supervisor'];
2214 $supervisor_array = explode(",", $supervisor);
2215 $supervisor_last_name = $supervisor_array[0];
2216 $sql = "SELECT * FROM tc_individual where individual='$supervisor'";
2217 $this->db2->query($sql,__LINE__,__FILE__);
2218 if($this->db2->next_record()) {
2219 $supervisor_address = $this->db2->f('address');
2221 $location = "$supervisor_last_name"." home ($supervisor_address)";
2222 $table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": All Individuals with Interviews Not Completed";
2223 $appt_table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": Interview Appointment Slots";
2224 $this->t->set_var('table_title',$table_title);
2225 $this->t->set_var('appt_table_title',$appt_table_title);
2227 // query the database for all the appointments
2228 $sql = "SELECT * FROM tc_appointment where presidency=".$districts[$d]['presidency']." and date>=CURDATE() ORDER BY date ASC, time ASC";
2229 $this->db->query($sql,__LINE__,__FILE__);
2231 while ($this->db->next_record()) {
2232 $appointment = $this->db->f('appointment');
2233 $indiv = $this->db->f('individual');
2234 $location = $this->db->f('location');
2235 if(($location == "") && ($indiv > 0)) { $location = "$supervisor_last_name"." home ($supervisor_address)"; }
2237 $date = $this->db->f('date');
2238 $date_array = explode("-",$date);
2239 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
2240 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
2242 $time = $this->db->f('time');
2243 $time_array = explode(":",$time);
2244 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
2246 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2247 $appt_table_data.= "<td align=center>$day_string</td>";
2248 $appt_table_data.= "<td align=center>$time_string</td>";
2250 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][individual]>';
2251 $appt_table_data.= '<option value=0></option>';
2252 for ($i=0; $i < count($individual_data); $i++) {
2253 $id = $individual_data[$i];
2254 $name = $indiv_name_data[$i];
2255 if($individual_data[$i] == $indiv) {
2256 $selected[$id] = 'selected="selected"';
2258 $selected[$id] = '';
2260 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
2262 $appt_table_data.='</select></td>';
2264 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
2265 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
2267 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
2268 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][supervisor]" value="'.$supervisor.'">';
2270 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2271 $this->t->set_var('tr_color',$tr_color);
2274 $this->t->set_var('appt_table_data',$appt_table_data);
2275 $this->t->set_var('appt_header_row',$appt_header_row);
2277 // INTERVIEW SCHEDULING TABLE
2279 // Select all the unique companionship numbers for this district
2280 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$d]['district'];
2281 $this->db->query($sql,__LINE__,__FILE__);
2282 $j=0; $unique_companionships = '';
2283 while ($this->db->next_record())
2285 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
2290 for ($j=0; $j < count($unique_companionships); $j++) {
2291 // Select all the companions from each companionship
2292 $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'];
2293 $this->db->query($sql,__LINE__,__FILE__);
2294 $k=0; $int_completed=0;
2295 $comp = $unique_companionships[$j]['companionship'];
2296 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2297 $this->t->set_var('tr_color',$tr_color);
2299 while ($this->db->next_record()) {
2300 // Get this companions information
2301 $individual = $this->db->f('individual');
2303 $id = $this->db->f('individual');
2304 $name = $this->db->f('name');
2305 $phone = $this->db->f('phone');
2306 $hti_pri = $this->db->f('priority');
2307 $hti_notes = $this->db->f('notes');
2309 // If the companionship has already had its quarterly interview,
2310 // Skip the other companion in the companionship.
2311 if($int_completed == 1) {
2312 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2313 $completed_data.= "<td align=center>$phone</td>";
2314 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2315 $completed_data.= "<td align=left>$hti_notes</td>";
2316 $completed_data.= '</tr>';
2317 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
2318 $this->t->set_var('tr_color2',$tr_color2);
2319 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2320 $this->t->set_var('tr_color',$tr_color);
2324 // If this companionship has had a hometeaching interview this quarter, don't show them on the schedule list
2325 $sql = "SELECT * FROM tc_interview WHERE date >= '$quarter_start' AND date < '$quarter_end' AND individual='$id' AND interview_type='hti'";
2326 $this->db2->query($sql,__LINE__,__FILE__);
2328 if(!$this->db2->next_record()) {
2329 $sql = "SELECT * FROM tc_interview WHERE individual='$id' AND interview_type='hti' ORDER BY date DESC";
2330 $this->db3->query($sql,__LINE__,__FILE__);
2331 if($this->db3->next_record()) {
2332 $date = $this->db3->f('date');
2336 $link_data['menuaction'] = 'tc.tc.int_update';
2337 $link_data['individual'] = $id;
2338 $link_data['name'] = $name;
2339 $link_data['interview'] = '';
2340 $link_data['action'] = 'add';
2341 $link_data['interview_type'] = 'hti';
2342 $link_data['interviewer'] = $districts[$d]['supervisor'];
2343 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2344 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2345 $table_data.= "<td align=center>$phone</td>";
2346 $table_data.= "<td align=center>";
2347 $table_data.= '<select name=hti_notes['.$i.'][pri]>';
2348 foreach(range(0,6) as $num) {
2349 if($num == 0) { $num = 1; } else {$num = $num*5; }
2350 if($hti_pri == $num) {
2351 $selected[$num] = 'selected="selected"';
2353 $selected[$num] = '';
2355 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2357 $table_data.= '</select></td>';
2358 $table_data.= "<td align=center>$date</td>";
2359 $table_data.= '<td><input type=text size="50" maxlength="128" name="hti_notes['.$i.'][notes]" value="'.$hti_notes.'">';
2360 $table_data.= '<input type=hidden name="hti_notes['.$i.'][individual]" value="'.$id.'">';
2361 $table_data.= '<input type=hidden name="hti_notes['.$i.'][indiv_name]" value="'.$name.'">';
2362 $table_data.= '</td>';
2363 $table_data.= '</tr>'."\n";
2366 $link_data['menuaction'] = 'tc.tc.int_update';
2367 $link_data['interviewer'] = $this->db2->f('interviewer');
2368 $link_data['individual'] = $this->db2->f('individual');
2369 $link_data['name'] = $name;
2370 $link_data['interview'] = $this->db2->f('interview');
2371 $link_data['interview_type'] = 'hti';
2372 $link_data['action'] = 'view';
2373 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2374 $comps_with_quarterly_int++;
2376 $date = $this->db2->f('date');
2377 $hti_notes = $this->db2->f('notes');
2378 if(strlen($hti_notes) > 40) { $hti_notes = substr($hti_notes,0,40) . "..."; }
2379 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2380 $completed_data.= "<td align=center>$phone</td>";
2381 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2382 $completed_data.= "<td align=left>$hti_notes</td>";
2383 $completed_data.= '</tr>';
2388 $completed_header_row = "<th><font size=-2>Individual</th>";
2389 $completed_header_row.= "<th><font size=-2>Phone</th>";
2390 $completed_header_row.= "<th><font size=-2>Date</th>";
2391 $completed_header_row.= "<th><font size=-2>Interview Notes</th>";
2393 $this->t->set_var('header_row',$header_row);
2394 $this->t->set_var('table_data',$table_data);
2395 $this->t->set_var('completed_header_row',$completed_header_row);
2396 $this->t->set_var('completed',$completed_data);
2397 $this->t->set_var('lang_save_appt','Save Appts for ' . $districts[$d]['name']);
2398 $this->t->set_var('lang_save_pri_notes','Save Pri / Notes for '. $districts[$d]['name']);
2399 $this->t->fp('indivlist','individual_list',True);
2401 } // End for each district loop
2404 $totals_header_row = "<th><font size=-2>Individuals</th>";
2405 $totals_header_row.= "<th><font size=-2>$year</th>";
2406 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2407 $totals_data.= "<td align=left><font size=-2><b>Total Companionships with interviews completed:</b></font></td>";
2408 $totals_data.= "<td align=center><font size=-2><b>$comps_with_quarterly_int / $total_comps</b></font></td>";
2409 $percent = ceil(($comps_with_quarterly_int / $total_comps)*100);
2410 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2411 $this->t->set_var('tr_color',$tr_color);
2412 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2413 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2414 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2415 $totals_data.= "</tr>";
2417 $this->t->set_var('totals',$totals_data);
2418 $this->t->set_var('totals_header_row',$totals_header_row);
2420 $this->t->pfp('out','int_sched_t');
2421 $this->save_sessiondata();
2425 function vis_sched()
2427 $this->t->set_file(array('vis_sched_t' => 'vis_sched.tpl'));
2428 $this->t->set_block('vis_sched_t','family_list','familylist');
2429 $this->t->set_block('vis_sched_t','appt_list','apptlist');
2430 $action = get_var('action',array('GET','POST'));
2432 $this->t->set_var('lang_reset','Clear Changes');
2434 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2435 $this->t->set_var('vis_link_title','View Yearly Visits');
2437 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
2438 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2440 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched&action=save'));
2441 $this->t->set_var('title','Presidency Yearly Visit Scheduler');
2443 $header_row = "<th><font size=-2>Family Name</th>";
2444 $header_row.= "<th><font size=-2>Phone</th>";
2445 $header_row.= "<th><font size=-2>Priority</th>";
2446 $header_row.= "<th><font size=-2>Last Visit</th>";
2447 $header_row.= "<th><font size=-2>Scheduling Notes</th>";
2448 $table_data=""; $completed_data=""; $totals_data="";
2452 // create the family id -> family name mapping
2453 $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";
2454 $this->db->query($sql,__LINE__,__FILE__);
2457 while ($this->db->next_record()) {
2458 $family_id[$i] = $this->db->f('family');
2459 $family_name[$i] = $this->db->f('name');
2460 $familyid2name[$family_id[$i]] = $family_name[$i];
2461 $familyid2address[$family_id[$i]] = $this->db->f('address');
2464 array_multisort($family_name, $family_id);
2466 if($action == 'save') {
2467 // Save any changes made to the appointment table
2468 $new_data = get_var('appt_notes',array('POST'));
2469 if($new_data != "") {
2470 foreach ($new_data as $entry) {
2471 $family = $entry['family'];
2472 $appointment = $entry['appointment'];
2473 $location = $entry['location'];
2474 if($location == "") {
2475 $family_name_array = explode(",", $familyid2name[$family]);
2476 $family_last_name = $family_name_array[0];
2477 $family_address = $familyid2address[$family];
2478 $location = "$family_last_name"." home ($family_address)";
2480 if($family == 0) { $location = ""; }
2482 //Only perform a database update if we have made a change to this appointment
2483 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and family='$family' and location='$location'";
2484 $this->db->query($sql,__LINE__,__FILE__);
2485 if(!$this->db->next_record()) {
2486 // Perform database save actions here
2487 $this->db->query("UPDATE tc_appointment set " .
2488 " family='" . $family . "'" .
2489 ",location='" . $location . "'" .
2490 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
2492 // Email the appointment
2493 $this->email_appt($appointment);
2498 // Save any changes made to the visit notes table
2499 $new_data = get_var('vis_notes',array('POST'));
2500 foreach ($new_data as $entry) {
2501 $visit_notes = $entry['notes'];
2502 $family = $entry['family_id'];
2503 $visit_pri = $entry['pri'];
2504 // Perform database save actions here
2505 $this->db->query("SELECT * FROM tc_family WHERE family='$family'",__LINE__,__FILE__);
2506 if ($this->db->next_record()) {
2507 $scheduling_priority = $this->db->f('scheduling_priority');
2508 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$visit_pri', notes=\"$visit_notes\" WHERE scheduling_priority='$scheduling_priority'", __LINE__, __FILE__);
2512 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched');
2513 //Header('Location: ' . $take_me_to_url);
2516 // APPOINTMENT TABLE
2517 $appt_header_row = "<th><font size=-2>Date</th>";
2518 $appt_header_row.= "<th><font size=-2>Time</th>";
2519 $appt_header_row.= "<th><font size=-2>Family</th>";
2520 $appt_header_row.= "<th><font size=-2>Location</th>";
2521 $appt_table_data = "";
2523 // Find out what the President ID is
2524 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.president=1 AND tp.valid=1";
2525 $this->db->query($sql,__LINE__,__FILE__);
2526 if($this->db->next_record()) {
2527 $presidency_name = $this->db->f('name');
2528 $presidency_id = $this->db->f('presidency');
2530 print "<hr><font color=red><h3>-E- Unable to locate Presidency in tc_presidency table</h3></font></hr>";
2534 // query the database for all the appointments
2535 $sql = "SELECT * FROM tc_appointment where presidency=$presidency_id and date>=CURDATE() ORDER BY date ASC, time ASC";
2536 $this->db->query($sql,__LINE__,__FILE__);
2538 while ($this->db->next_record()) {
2539 $appointment = $this->db->f('appointment');
2540 $family = $this->db->f('family');
2541 $location = $this->db->f('location');
2542 $family_name_array = explode(",", $familyid2name[$family]);
2543 $family_last_name = $family_name_array[0];
2544 $family_address = $familyid2address[$family];
2545 if(($location == "") && ($family > 0)) { $location = "$family_last_name"." home ($family_address)"; }
2547 $date = $this->db->f('date');
2548 $date_array = explode("-",$date);
2549 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
2550 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
2552 $time = $this->db->f('time');
2553 $time_array = explode(":",$time);
2554 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
2556 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2557 $appt_table_data.= "<td align=center>$day_string</td>";
2558 $appt_table_data.= "<td align=center>$time_string</td>";
2560 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][family]>';
2561 $appt_table_data.= '<option value=0></option>';
2562 for ($i=0; $i < count($family_id); $i++) {
2563 $id = $family_id[$i];
2564 $name = $family_name[$i];
2565 if($family_id[$i] == $family) {
2566 $selected[$id] = 'selected="selected"';
2568 $selected[$id] = '';
2570 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
2572 $appt_table_data.='</select></td>';
2574 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
2575 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
2577 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
2579 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2580 $this->t->set_var('tr_color',$tr_color);
2583 $this->t->set_var('appt_table_data',$appt_table_data);
2584 $this->t->set_var('appt_header_row',$appt_header_row);
2587 // VISIT SCHEDULING TABLE
2588 $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";
2589 $this->db->query($sql,__LINE__,__FILE__);
2591 $total_families=0; $families_with_yearly_visit=0;
2593 while ( $this->db->next_record()) {
2595 $id = $this->db->f('family');
2596 $name = $this->db->f('name');
2597 $phone = $this->db->f('phone');
2598 $vis_pri = $this->db->f('priority');
2599 $vis_notes = $this->db->f('notes');
2601 // If this family has had a yearly visit this year, don't show them on the schedule list
2602 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2603 $sql = "SELECT * FROM tc_visit WHERE date > '$year_start' AND date < '$year_end' ".
2604 "AND family=" . $id . " AND companionship=0";
2605 $this->db2->query($sql,__LINE__,__FILE__);
2607 if(!$this->db2->next_record()) {
2608 $sql = "SELECT * FROM tc_visit WHERE family=" . $id . " AND companionship=0 ORDER BY date DESC";
2609 $this->db3->query($sql,__LINE__,__FILE__);
2610 if($this->db3->next_record()) {
2611 $date = $this->db3->f('date');
2615 $link_data['menuaction'] = 'tc.tc.vis_update';
2616 $link_data['visit'] = '';
2617 $link_data['family'] = $id;
2618 $link_data['name'] = $name;
2619 $link_data['action'] = 'add';
2620 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2621 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2622 $table_data.= "<td align=center>$phone</td>";
2623 $table_data.= "<td align=center>";
2624 $table_data.= '<select name=vis_notes['.$id.'][pri]>';
2625 foreach(range(0,6) as $num) {
2626 if($num == 0) { $num = 1; } else {$num = $num*5; }
2627 if($vis_pri == $num) {
2628 $selected[$num] = 'selected="selected"';
2630 $selected[$num] = '';
2632 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2634 $table_data.= '</select></td>';
2635 $table_data.= "<td align=center>$date</td>";
2636 $table_data.= '<td><input type=text size="50" maxlength="128" name="vis_notes['.$id.'][notes]" value="'.$vis_notes.'">';
2637 $table_data.= '<input type=hidden name="vis_notes['.$id.'][family_id]" value="'.$id.'">';
2638 $table_data.= '<input type=hidden name="vis_notes['.$id.'][family_name]" value="'.$name.'">';
2639 $table_data.= '</td>';
2640 $table_data.= '</tr>';
2641 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2642 $this->t->set_var('tr_color',$tr_color);
2644 $link_data['menuaction'] = 'tc.tc.vis_update';
2645 $link_data['visit'] = $this->db2->f('visit');
2646 $link_data['family'] = $this->db2->f('family');
2647 $link_data['name'] = $name;
2648 $link_data['date'] = $this->db2->f('date');
2649 $link_data['action'] = 'view';
2650 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2651 $families_with_yearly_visit++;
2652 $date = $this->db2->f('date');
2653 $vis_notes = $this->db2->f('notes');
2654 if(strlen($vis_notes) > 40) { $vis_notes = stripslashes(substr($vis_notes,0,40) . "..."); }
2655 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2656 $completed_data.= "<td align=center>$phone</td>";
2657 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2658 $completed_data.= "<td align=left>$vis_notes</td>";
2659 $completed_data.= '</tr>';
2660 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
2661 $this->t->set_var('tr_color2',$tr_color2);
2665 $completed_header_row = "<th><font size=-2>Family Name</th>";
2666 $completed_header_row.= "<th><font size=-2>Phone</th>";
2667 $completed_header_row.= "<th><font size=-2>Date</th>";
2668 $completed_header_row.= "<th><font size=-2>Visit Notes</th>";
2670 $totals_header_row = "<th><font size=-2>Families</th>";
2671 $totals_header_row.= "<th><font size=-2>$year</th>";
2672 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2673 $totals_data.= "<td align=left><font size=-2><b>Total Families with yearly Visits completed:</b></font></td>";
2674 $totals_data.= "<td align=center><font size=-2><b>$families_with_yearly_visit / $total_families</b></font></td>";
2675 $percent = ceil(($families_with_yearly_visit / $total_families)*100);
2676 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2677 $this->t->set_var('tr_color',$tr_color);
2678 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2679 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2680 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2681 $totals_data.= "</tr>";
2683 $this->t->set_var('header_row',$header_row);
2684 $this->t->set_var('table_data',$table_data);
2685 $this->t->set_var('totals_header_row',$totals_header_row);
2686 $this->t->set_var('completed_header_row',$completed_header_row);
2687 $this->t->set_var('completed',$completed_data);
2688 $this->t->set_var('totals',$totals_data);
2689 $this->t->fp('familylist','family_list',True);
2690 $this->t->set_var('lang_save_appt','Save Appts');
2691 $this->t->set_var('lang_save_pri_notes','Save Pri / Notes');
2692 $this->t->fp('apptlist','appt_list',True);
2694 $this->t->pfp('out','vis_sched_t');
2695 $this->save_sessiondata();
2700 $this->t->set_file(array('ppi_view_t' => 'ppi_view.tpl'));
2701 $this->t->set_block('ppi_view_t','district_list','list');
2703 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2704 $num_months = get_var('num_months',array('GET','POST'));
2705 if($num_months == '') { $num_months = $this->default_ppi_num_months; }
2706 $this->t->set_var('num_months',$num_months);
2707 if($num_months == 1) {
2708 $this->t->set_var('lang_num_months','Month of History');
2710 $this->t->set_var('lang_num_months','Months of History');
2712 $this->t->set_var('lang_filter','Filter');
2713 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2715 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2716 $this->t->set_var('ppi_link_title',$this->ppi_frequency_label . ' PPIs');
2718 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
2719 $this->t->set_var('schedule_ppi_link_title','Schedule ' . $this->ppi_frequency_label . ' PPIs');
2721 $this->t->set_var('title',$this->ppi_frequency_label . ' PPIs');
2722 $num_months = get_var('num_months',array('GET','POST'));
2723 if($num_months == '') { $num_months = $this->default_ppi_num_years; }
2724 $this->t->set_var('num_months',$num_months);
2725 if($num_months == 1) {
2726 $this->t->set_var('lang_num_months','Year of History');
2728 $this->t->set_var('lang_num_months','Years of History');
2731 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.president=1 AND tp.valid=1";
2732 $this->db->query($sql,__LINE__,__FILE__);
2733 if($this->db->next_record()) {
2734 $president_name = $this->db->f('name');
2735 $interviewer = $this->db->f('individual');
2737 print "<hr><font color=red><h3>-E- Unable to locate President in tc_presidency table</h3></font></hr>";
2740 $this->t->set_var('district_number','*');
2741 $this->t->set_var('district_name',$president_name);
2743 $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";
2744 $this->db->query($sql,__LINE__,__FILE__);
2746 while ($this->db->next_record()) {
2747 $individual[$i] = $this->db->f('individual');
2748 $indiv_name[$i] = $this->db->f('name');
2749 $indiv_phone[$individual[$i]] = $this->db->f('phone');
2750 $indiv_priority[$individual[$i]] = $this->db->f('priority');
2751 $indiv_notes[$individual[$i]] = $this->db->f('notes');
2755 array_multisort($indiv_name, $individual);
2756 //var_dump($indiv_name); print "<br><br>"; var_dump($individual);
2758 $header_row="<th width=$comp_width><font size=-2>Individual</th>";
2760 $indiv_width=400; $ppi_width=75; $table_width=$indiv_width + $num_months*$ppi_width;
2762 for($m=$num_months; $m >= 0; $m--) {
2763 $year = date('Y') - $m;
2764 $header_row .= "<th width=150><font size=-2>$year</th>";
2768 for ($j=0; $j < count($individual); $j++) {
2769 $id = $individual[$j];
2770 $name = $indiv_name[$j];
2771 $phone = $indiv_phone[$id];
2773 $link_data['menuaction'] = 'tc.tc.ppi_update';
2774 $link_data['interviewer'] = $interviewer;
2775 $link_data['individual'] = $id;
2776 $link_data['name'] = $name;
2777 $link_data['interview'] = '';
2778 $link_data['interview_type'] = 'ppi';
2779 $link_data['action'] = 'add';
2780 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2781 $this->nextmatchs->template_alternate_row_color(&$this->t);
2782 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2784 // Find out how many times PPIs were performed in the past $num_months for this individual
2785 for($m=$num_months; $m >= 0; $m--) {
2786 $year = date('Y') - $m;
2787 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2788 $sql = "SELECT * FROM tc_interview WHERE date > '$year_start' AND date < '$year_end' ".
2789 "AND individual=" . $id . " AND interview_type='ppi' ORDER BY date DESC";
2790 $this->db2->query($sql,__LINE__,__FILE__);
2792 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
2793 if($this->db2->next_record()) {
2794 $ppis[$m]++; $total_ppis[$m]++; $ppi_recorded[$companionship][$m]=1;
2795 $link_data['menuaction'] = 'tc.tc.ppi_update';
2796 $link_data['companionship'] = $companionship;
2797 $link_data['interviewer'] = $this->db2->f('interviewer');
2798 $link_data['indiv'] = $id;
2799 $link_data['name'] = $name;
2800 $link_data['interview'] = $this->db2->f('interview');
2801 $link_data['interview_type'] = 'ppi';
2802 $link_data['action'] = 'view';
2803 $date = $this->db2->f('date');
2804 $date_array = explode("-",$date);
2805 $month = $date_array[1];
2806 $day = $date_array[2];
2807 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2808 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2810 $table_data .= "<td> </td>";
2813 $table_data .= "</tr>\n";
2815 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2817 $stat_data = "<tr><td><b><font size=-2>$total_indivs Individuals<br>PPI Totals:</font></b></td>";
2818 for($m=$num_months; $m >=0; $m--) {
2819 $percent = ceil(($ppis[$m] / $total_indivs)*100);
2820 $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
2822 $stat_data .= "</tr>";
2824 $this->t->set_var('table_width',$table_width);
2825 $this->t->set_var('header_row',$header_row);
2826 $this->t->set_var('table_data',$table_data);
2827 $this->t->set_var('stat_data',$stat_data);
2828 $this->t->pfp('out','ppi_view_t');
2829 $this->save_sessiondata();
2832 function ppi_update()
2834 $this->t->set_file(array('form' => 'ppi_update.tpl'));
2835 $this->t->set_block('form','interviewer_list','int_list');
2836 $this->t->set_block('form','add','addhandle');
2837 $this->t->set_block('form','edit','edithandle');
2839 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2840 $this->t->set_var('readonly','');
2841 $this->t->set_var('disabled','');
2843 $action = get_var('action',array('GET','POST'));
2844 $companionship = get_var('companionship',array('GET','POST'));
2845 $interviewer = get_var('interviewer',array('GET','POST'));
2846 $name = get_var('name',array('GET','POST'));
2847 $interview = get_var('interview',array('GET','POST'));
2848 $individual = get_var('individual',array('GET','POST'));
2849 $date = get_var('date',array('GET','POST'));
2850 $notes = get_var('notes',array('GET','POST'));
2851 $interview_type = get_var('interview_type',array('GET','POST'));
2853 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1 AND ";
2854 if($this->yearly_ppi_interviewer == 1) { $sql .= " (tp.president=1)"; }
2855 if($this->yearly_ppi_interviewer == 2) { $sql .= " (tp.president=1 OR tp.counselor=1)"; }
2856 if($this->yearly_ppi_interviewer == 3) { $sql .= " (tp.president=1 OR tp.counselor=1 OR tp.secretary=1)"; }
2857 $this->db2->query($sql,__LINE__,__FILE__);
2858 while ($this->db2->next_record()) {
2859 $indiv = $this->db2->f('individual');
2860 $interviewer_name = $this->db2->f('name');
2861 if($indiv == $interviewer) {
2862 $this->t->set_var('interviewer',$indiv . ' selected');
2864 $this->t->set_var('interviewer',$indiv);
2866 #print "indiv: $indiv interviewer: $interviewer<br>";
2867 $this->t->set_var('interviewer_name',$interviewer_name);
2868 $this->t->set_var('eqpresppi_checked','checked');
2869 $this->t->fp('int_list','interviewer_list',True);
2871 #print "selected interviewer: $interviewer<br>";
2872 if($action == 'save') {
2873 $notes = get_var('notes',array('POST'));
2874 $this->db->query("UPDATE tc_interview set " .
2875 " interview='" . $interview . "'" .
2876 ", interviewer='" . $interviewer . "'" .
2877 ", individual='" . $individual . "'" .
2878 ", date='" . $date . "'" .
2879 ", notes=\"" . $notes . "\"" .
2880 ", interview_type='" . $interview_type . "'" .
2881 " WHERE interview=" . $interview,__LINE__,__FILE__);
2886 if($action == 'insert') {
2887 $notes = get_var('notes',array('POST'));
2888 $this->db->query("INSERT INTO tc_interview (interviewer,individual,date,notes,interview_type) " .
2889 "VALUES ('" . $interviewer . "','" . $individual . "','" .
2890 $date . "',\"" . $notes . "\",'" . $interview_type ."')",__LINE__,__FILE__);
2895 if($action == 'add') {
2896 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2897 $this->t->set_var('interview', '');
2898 $this->t->set_var('interviewer', $interviewer);
2899 $this->t->set_var('name',$name);
2900 $this->t->set_var('individual',$individual);
2901 $this->t->set_var('date','');
2902 $this->t->set_var('notes','');
2903 $this->t->set_var('interview_type',$interview_type);
2904 $this->t->set_var('eqpresppi_checked','checked');
2905 $this->t->set_var('lang_done','Cancel');
2906 $this->t->set_var('lang_action','Adding New PPI');
2907 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview=' .
2908 $interview . '&action=' . 'insert'));
2911 if($action == 'edit' || $action == 'view') {
2912 $sql = "SELECT * FROM tc_interview WHERE interview=" . $interview . " AND interview_type='ppi'";
2913 $this->db->query($sql,__LINE__,__FILE__);
2914 $this->db->next_record();
2915 $this->t->set_var('interview',$interview);
2916 $this->t->set_var('name',$name);
2917 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2918 $this->t->set_var('individual',$this->db->f('individual'));
2919 $this->t->set_var('date',$this->db->f('date'));
2920 $this->t->set_var('notes',$this->db->f('notes'));
2921 $this->t->set_var('interview_type',$this->db->f('interview_type'));
2922 if($this->db->f('interview_type') == 'ppi') { $this->t->set_var('eqpresppi_checked','checked'); }
2925 if($action == 'edit') {
2926 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2927 $this->t->set_var('lang_done','Cancel');
2928 $this->t->set_var('lang_action','Editing PPI');
2929 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview='.
2930 $interview . '&action=' . 'save'));
2933 if($action == 'view') {
2934 $date = $this->db->f('date');
2935 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2936 $this->t->set_var('readonly','READONLY');
2937 $this->t->set_var('disabled','DISABLED');
2938 $this->t->set_var('lang_done','Done');
2939 $this->t->set_var('lang_action','Viewing PPI');
2940 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview=' .
2941 $interview . '&action=' . 'edit'));
2944 $this->t->set_var('lang_reset','Clear Form');
2945 $this->t->set_var('lang_add','Add PPI');
2946 $this->t->set_var('lang_save','Save Changes');
2947 $this->t->set_var('edithandle','');
2948 $this->t->set_var('addhandle','');
2950 $this->t->pfp('out','form');
2952 if($action == 'view') { $this->t->set_var('lang_save','Edit PPI'); }
2953 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2954 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2956 $this->save_sessiondata();
2961 $this->t->set_file(array('int_view_t' => 'int_view.tpl'));
2962 $this->t->set_block('int_view_t','district_list','list');
2964 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2965 $num_quarters = get_var('num_quarters',array('GET','POST'));
2966 if($num_quarters == '') { $num_quarters = $this->default_int_num_quarters; }
2967 $this->t->set_var('num_quarters',$num_quarters);
2968 if($num_quarters == 1) {
2969 $this->t->set_var('lang_num_quarters','Quarter of History');
2971 $this->t->set_var('lang_num_quarters','Quarters of History');
2973 $this->t->set_var('lang_filter','Filter');
2975 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2976 $this->t->set_var('int_link_title','Hometeaching Interviews');
2978 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
2979 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
2981 $this->t->set_var('title','Hometeaching Interviews');
2983 $num_months = $num_quarters * 3 - 1;
2984 $current_month = $this->current_month;
2985 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
2986 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
2987 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
2988 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
2990 $sql = "SELECT * FROM tc_district AS td JOIN tc_individual AS ti WHERE td.supervisor=ti.individual AND td.valid=1 ORDER BY td.district ASC";
2991 $this->db->query($sql,__LINE__,__FILE__);
2993 while ($this->db->next_record()) {
2994 $districts[$i]['district'] = $this->db->f('district');
2995 $districts[$i]['name'] = $this->db->f('name');
2996 $districts[$i]['supervisor'] = $this->db->f('supervisor');
3000 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
3001 $this->db->query($sql,__LINE__,__FILE__);
3003 while ($this->db->next_record()) {
3004 $individual[$i] = $this->db->f('individual');
3005 $indiv_name[$i] = $this->db->f('name');
3006 $indiv_phone[$individual[$i]] = $this->db->f('phone');
3009 array_multisort($indiv_name, $individual);
3010 for($i=0; $i < count($individual); $i++) {
3011 $id = $individual[$i];
3012 $indivs[$id] = $indiv_name[$i];
3015 $total_companionships = 0;
3016 $this->nextmatchs->template_alternate_row_color(&$this->t);
3017 for ($i=0; $i < count($districts); $i++) {
3018 $this->t->set_var('district_number',$districts[$i]['district']);
3019 $this->t->set_var('district_name',$districts[$i]['name']);
3020 $supervisor = $districts[$i]['supervisor'];
3022 // Select all the unique companionship numbers for this district
3023 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$i]['district'];
3024 $this->db->query($sql,__LINE__,__FILE__);
3025 $j=0; $unique_companionships = '';
3026 while ($this->db->next_record()) {
3027 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
3031 $comp_width=250; $int_width=75; $table_width=$comp_width + $num_months*$int_width;
3032 $table_data=""; $num_companionships = $j; $num_indivs = 0;
3033 for($m=$num_months; $m >= 0; $m--) { $ints[$m] = 0; }
3034 for ($j=0; $j < count($unique_companionships); $j++) {
3035 // Select all the companions in each companionship
3036 $sql = "SELECT * FROM tc_companion where valid=1 and ".
3037 "companionship=". $unique_companionships[$j]['companionship'];
3038 $this->db->query($sql,__LINE__,__FILE__);
3040 $comp = $unique_companionships[$j]['companionship'];
3041 for($m=$num_months; $m >= 0; $m--) { $int_recorded[$comp][$m] = 0; }
3042 while ($this->db->next_record()) {
3043 // Get this companions information
3045 $companionship = $this->db->f('companionship');
3046 $individual = $this->db->f('individual');
3047 $name = $indivs[$individual];
3048 $phone = $indiv_phone[$individual];
3049 $link_data['menuaction'] = 'tc.tc.int_update';
3050 $link_data['companionship'] = $companionship;
3051 $link_data['interviewer'] = $supervisor;
3052 $link_data['individual'] = $individual;
3053 $link_data['name'] = $name;
3054 $link_data['interview'] = '';
3055 $link_data['interview_type'] = 'hti';
3056 $link_data['action'] = 'add';
3057 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
3058 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
3060 // Find out how many times Interviews were performed in the past $num_months for this individual
3061 $header_row="<th width=$comp_width><font size=-2>Companionship</th>";
3062 for($m=$num_months; $m >= 0; $m--) {
3063 $month = $current_month - $m;
3064 $year = $this->current_year;
3066 $remainder = $month;
3067 $month = 12 + $remainder;
3070 if($month < 10) { $month = "0"."$month"; }
3071 $month_start = "$year"."-"."$month"."-"."01";
3072 $month_end = "$year"."-"."$month"."-"."31";
3073 $month = "$month"."/"."$year";
3074 $sql = "SELECT * FROM tc_interview WHERE date >= '$month_start' AND date <= '$month_end' ".
3075 "AND individual=" . $individual . " AND interview_type='hti' ORDER BY date DESC";
3076 $this->db2->query($sql,__LINE__,__FILE__);
3077 $header_row .= "<th width=$int_width><font size=-2>$month</th>";
3079 if(!$total_ints[$m]) { $total_ints[$m] = 0; }
3080 if($this->db2->next_record()) {
3081 if(!$int_recorded[$companionship][$m]) {
3084 $int_recorded[$companionship][$m]=1;
3086 $link_data['menuaction'] = 'tc.tc.int_update';
3087 $link_data['companionship'] = $companionship;
3088 $link_data['interviewer'] = $this->db2->f('interviewer');
3089 $link_data['individual'] = $individual;
3090 $link_data['name'] = $name;
3091 $link_data['interview'] = $this->db2->f('interview');
3092 $link_data['action'] = 'view';
3093 $link_data['interview_type'] = 'hti';
3094 $date = $this->db2->f('date');
3095 $date_array = explode("-",$date);
3096 $month = $date_array[1];
3097 $day = $date_array[2];
3098 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
3099 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
3102 $table_data .= "<td> </td>";
3105 $table_data .= "</tr>";
3108 $table_data .= "<tr><td colspan=20><hr></td></tr>";
3110 $total_companionships += $num_companionships;
3111 $stat_data = "<tr><td><b><font size=-2>$num_companionships Companionships<br>Interview Totals:</font></b></td>";
3113 // Print the hometeaching interview stats
3114 for($m=$num_months; $m >=0; $m--) {
3115 $month = $current_month - $m;
3116 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
3117 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
3118 //print "$month % $this->monthly_hometeaching_interview_stats = $month_begins <br>";
3119 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
3120 if(($month_begins) == 1) {
3123 $total += $ints[$m];
3125 $percent = ceil(($total / $num_companionships)*100);
3126 $stat_data .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
3128 $stat_data .= "</tr>";
3130 $this->t->set_var('table_width',$table_width);
3131 $this->t->set_var('header_row',$header_row);
3132 $this->t->set_var('table_data',$table_data);
3133 $this->t->set_var('stat_data',$stat_data);
3134 $this->t->fp('list','district_list',True);
3137 // Display the totals
3139 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>Interview Totals:</font></b></td>";
3140 for($m=$num_months; $m >=0; $m--) {
3141 $month = $current_month - $m;
3142 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
3143 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
3144 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
3145 if(($month_begins) == 1) {
3146 $total = $total_ints[$m];
3148 $total += $total_ints[$m];
3150 $percent = ceil(($total / $total_companionships)*100);
3151 $totals .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
3155 $this->t->set_var('totals',$totals);
3156 $this->t->pfp('out','int_view_t');
3157 $this->save_sessiondata();
3160 function int_update()
3162 $this->t->set_file(array('form' => 'int_update.tpl'));
3163 $this->t->set_block('form','interviewer_list','int_list');
3164 $this->t->set_block('form','add','addhandle');
3165 $this->t->set_block('form','edit','edithandle');
3167 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
3168 $this->t->set_var('readonly','');
3169 $this->t->set_var('disabled','');
3170 $this->t->set_var('eqpresppi','');
3172 $action = get_var('action',array('GET','POST'));
3173 $companionship = get_var('companionship',array('GET','POST'));
3174 $interviewer = get_var('interviewer',array('GET','POST'));
3175 $name = get_var('name',array('GET','POST'));
3176 $interview = get_var('interview',array('GET','POST'));
3177 $individual = get_var('individual',array('GET','POST'));
3178 $date = get_var('date',array('GET','POST'));
3179 $notes = get_var('notes',array('GET','POST'));
3180 $interview_type = get_var('interview_type',array('GET','POST'));
3182 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1 AND (tp.president=1 OR tp.counselor=1 OR tp.secretary=1 OR tp.district!=0)";
3183 $this->db2->query($sql,__LINE__,__FILE__);
3184 while ($this->db2->next_record()) {
3185 $indiv = $this->db2->f('individual');
3186 $interviewer_name = $this->db2->f('name');
3187 if($indiv == $interviewer) {
3188 $this->t->set_var('interviewer',$indiv . ' selected');
3190 $this->t->set_var('interviewer',$indiv);
3192 $this->t->set_var('interviewer_name',$interviewer_name);
3193 $this->t->fp('int_list','interviewer_list',True);
3196 if($action == 'save') {
3197 $notes = get_var('notes',array('POST'));
3198 $this->db->query("UPDATE tc_interview set " .
3199 " interview='" . $interview . "'" .
3200 ", interviewer='" . $interviewer . "'" .
3201 ", individual='" . $individual . "'" .
3202 ", date='" . $date . "'" .
3203 ", notes=\"" . $notes . "\"" .
3204 ", interview_type='" . $interview_type . "'" .
3205 " WHERE interview=" . $interview,__LINE__,__FILE__);
3210 if($action == 'insert') {
3211 $notes = get_var('notes',array('POST'));
3212 $this->db->query("INSERT INTO tc_interview (interviewer,individual,date,notes,interview_type) " .
3213 "VALUES ('" . $interviewer . "','" . $individual . "','" .
3214 $date . "',\"" . $notes ."\",'" . $interview_type . "')",__LINE__,__FILE__);
3219 if($action == 'add') {
3220 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
3221 $this->t->set_var('interview', '');
3222 $this->t->set_var('interviewer', $interviewer);
3223 $this->t->set_var('name',$name);
3224 $this->t->set_var('individual',$individual);
3225 $this->t->set_var('date','');
3226 $this->t->set_var('notes','');
3227 $this->t->set_var('interview_type',$interview_type);
3228 $this->t->set_var('lang_done','Cancel');
3229 $this->t->set_var('lang_action','Adding New Interview');
3230 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
3231 $interview . '&action=' . 'insert'));
3234 if($action == 'edit' || $action == 'view') {
3235 $sql = "SELECT * FROM tc_interview WHERE interview=" . $interview . " AND interview_type='hti'";
3236 $this->db->query($sql,__LINE__,__FILE__);
3237 $this->db->next_record();
3238 $this->t->set_var('interview',$interview);
3239 $this->t->set_var('name',$name);
3240 $this->t->set_var('interviewer', $this->db->f('interviewer'));
3241 $this->t->set_var('individual',$this->db->f('individual'));
3242 $this->t->set_var('date',$this->db->f('date'));
3243 $this->t->set_var('notes',$this->db->f('notes'));
3244 $this->t->set_var('interview_type',$this->db->f('interview_type'));
3245 if($this->db->f('interview_type') == 'ppi') { $this->t->set_var('eqpresppi_checked','checked'); }
3248 if($action == 'edit') {
3249 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
3250 $this->t->set_var('lang_done','Cancel');
3251 $this->t->set_var('lang_action','Editing Interview');
3252 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
3253 $interview . '&action=' . 'save'));
3256 if($action == 'view') {
3257 $date = $this->db->f('date');
3258 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
3259 $this->t->set_var('readonly','READONLY');
3260 $this->t->set_var('disabled','DISABLED');
3261 $this->t->set_var('lang_done','Done');
3262 $this->t->set_var('lang_action','Viewing Interview');
3263 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
3264 $interview . '&action=' . 'edit'));
3267 $this->t->set_var('lang_reset','Clear Form');
3268 $this->t->set_var('lang_add','Add Interview');
3269 $this->t->set_var('lang_save','Save Changes');
3270 $this->t->set_var('edithandle','');
3271 $this->t->set_var('addhandle','');
3273 $this->t->pfp('out','form');
3275 if($action == 'view') { $this->t->set_var('lang_save','Edit Interview'); }
3276 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
3277 if($action == 'add') { $this->t->pfp('addhandle','add'); }
3279 $this->save_sessiondata();
3284 $this->t->set_file(array('vis_view_t' => 'vis_view.tpl'));
3285 $this->t->set_block('vis_view_t','visit_list','list1');
3286 $this->t->set_block('vis_view_t','family_list','list2');
3288 $this->t->set_var('lang_name','Family Name');
3289 $this->t->set_var('lang_date','Date');
3291 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
3292 $this->t->set_var('vis_link_title','View Yearly Visits');
3294 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
3295 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
3297 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
3298 $num_years = get_var('num_years',array('GET','POST'));
3299 if($num_years == '') { $num_years = $this->default_vis_num_years; }
3300 $this->t->set_var('num_years',$num_years);
3301 if($num_years == 1) {
3302 $this->t->set_var('lang_num_years','Year of History');
3304 $this->t->set_var('lang_num_years','Years of History');
3306 $this->t->set_var('lang_filter','Filter');
3308 $year = date('Y') - $num_years + 1;
3309 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
3311 $sql = "SELECT * FROM tc_visit WHERE companionship=0 and date > '$year_start' ORDER BY date DESC";
3312 $this->db->query($sql,__LINE__,__FILE__);
3313 $total_records = $this->db->num_rows();
3316 while ($this->db->next_record()) {
3317 $visit_list[$i]['visit'] = $this->db->f('visit');
3318 $visit_list[$i]['family'] = $this->db->f('family');
3319 $visit_list[$i]['date'] = $this->db->f('date');
3323 for ($i=0; $i < count($visit_list); $i++) {
3324 $this->nextmatchs->template_alternate_row_color(&$this->t);
3326 $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'";
3327 $this->db->query($sql,__LINE__,__FILE__);
3328 $this->db->next_record();
3330 $this->t->set_var('family',$visit_list[$i]['family']);
3331 $this->t->set_var('family_name',$this->db->f('name'));
3332 $this->t->set_var('date',$visit_list[$i]['date']);
3334 $link_data['menuaction'] = 'tc.tc.vis_update';
3335 $link_data['visit'] = $visit_list[$i]['visit'];
3336 $link_data['name'] = $this->db->f('name');
3337 $link_data['date'] = $visit_list[$i]['date'];
3338 $link_data['action'] = 'view';
3339 $this->t->set_var('view',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3340 $this->t->set_var('lang_view','View');
3342 $link_data['menuaction'] = 'tc.tc.vis_update';
3343 $link_data['visit'] = $visit_list[$i]['visit'];
3344 $link_data['name'] = $this->db->f('name');
3345 $link_data['date'] = $visit_list[$i]['date'];
3346 $link_data['action'] = 'edit';
3347 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3348 $this->t->set_var('lang_edit','Edit');
3350 $this->t->fp('list1','visit_list',True);
3353 // List the families that are available to record a visit against
3354 $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'";
3355 $this->db->query($sql,__LINE__,__FILE__);
3356 $total_records = $this->db->num_rows();
3359 while ($this->db->next_record()) {
3360 $family_names[$i] = $this->db->f('name');
3361 $family_ids[$i] = $this->db->f('family');
3363 } array_multisort($family_names, $family_ids);
3365 for ($i=0; $i < count($family_names); $i++) {
3366 $link_data['menuaction'] = 'tc.tc.vis_update';
3367 $link_data['visit'] = '';
3368 $link_data['family'] = $family_ids[$i];
3369 $link_data['action'] = 'add';
3370 $link_data['name'] = $family_names[$i];
3371 $this->t->set_var('add',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3373 $this->t->set_var('name',$family_names[$i]);
3374 if(($i+1) % 3 == 0) {
3375 $this->t->set_var('table_sep',"</td></tr><tr>");
3377 $this->t->set_var('table_sep',"</td>");
3379 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
3381 $this->t->fp('list2','family_list',True);
3384 $this->t->pfp('out','vis_view_t');
3385 $this->save_sessiondata();
3388 function vis_update()
3390 $this->t->set_file(array('form' => 'vis_update.tpl'));
3391 $this->t->set_block('form','add','addhandle');
3392 $this->t->set_block('form','edit','edithandle');
3394 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
3395 $this->t->set_var('readonly','');
3396 $this->t->set_var('disabled','');
3398 $action = get_var('action',array('GET','POST'));
3399 $visit = get_var('visit',array('GET','POST'));
3400 $family = get_var('family',array('GET','POST'));
3401 $name = get_var('name',array('GET','POST'));
3402 $date = get_var('date',array('GET','POST'));
3403 $notes = get_var('notes',array('GET','POST'));
3406 if($action == 'save') {
3407 $notes = get_var('notes',array('POST'));
3408 $this->db->query("UPDATE tc_visit set " .
3409 " date='" . $date . "'" .
3410 ", notes=\"" . $notes . "\"" .
3411 " WHERE visit=" . $visit,__LINE__,__FILE__);
3416 if($action == 'insert') {
3417 $notes = get_var('notes',array('POST'));
3418 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes) " .
3419 "VALUES ('" . $family . "','" . $companionship . "','" .
3420 $date . "',\"" . $notes . "\")",__LINE__,__FILE__);
3425 if($action == 'add') {
3426 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
3427 $this->t->set_var('family', $family);
3428 $this->t->set_var('visit', '');
3429 $this->t->set_var('name', $name);
3430 $this->t->set_var('date','');
3431 $this->t->set_var('notes','');
3432 $this->t->set_var('lang_done','Cancel');
3433 $this->t->set_var('lang_action','Adding New Visit');
3434 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&family=' .
3435 $family . '&action=' . 'insert'));
3438 if($action == 'edit' || $action == 'view') {
3439 $sql = "SELECT * FROM tc_visit WHERE visit=".$visit;
3440 $this->db->query($sql,__LINE__,__FILE__);
3441 $this->db->next_record();
3442 $this->t->set_var('visit',$visit);
3443 $this->t->set_var('name',$name);
3444 $this->t->set_var('family', $family);
3445 $this->t->set_var('date',$this->db->f('date'));
3446 $this->t->set_var('notes',$this->db->f('notes'));
3449 if($action == 'edit') {
3450 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
3451 $this->t->set_var('lang_done','Cancel');
3452 $this->t->set_var('lang_action','Editing Visit');
3453 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit=' .
3454 $visit . '&action=' . 'save'));
3457 if($action == 'view') {
3458 $date = $this->db->f('date');
3459 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
3460 $this->t->set_var('readonly','READONLY');
3461 $this->t->set_var('disabled','DISABLED');
3462 $this->t->set_var('lang_done','Done');
3463 $this->t->set_var('lang_action','Viewing Visit');
3464 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit=' .
3465 $visit . '&action=' . 'edit'));
3468 $this->t->set_var('lang_reset','Clear Form');
3469 $this->t->set_var('lang_add','Add Visit');
3470 $this->t->set_var('lang_save','Save Changes');
3471 $this->t->set_var('edithandle','');
3472 $this->t->set_var('addhandle','');
3474 $this->t->pfp('out','form');
3476 if($action == 'view') { $this->t->set_var('lang_save','Edit Visit'); }
3477 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
3478 if($action == 'add') { $this->t->pfp('addhandle','add'); }
3480 $this->save_sessiondata();
3485 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3486 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3487 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3489 $this->t->set_file(array('att_view_t' => 'att_view.tpl'));
3490 $this->t->set_block('att_view_t','act_list','list');
3492 $this->t->set_block('att_view_t','month_list','list1');
3493 $this->t->set_block('att_view_t','header_list','list2');
3494 $this->t->set_block('att_view_t','individual_list','list3');
3496 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3497 $num_quarters = get_var('num_quarters',array('GET','POST'));
3498 if($num_quarters == '') { $num_quarters = $this->default_att_num_quarters; }
3499 $this->t->set_var('num_quarters',$num_quarters);
3500 $this->t->set_var('lang_filter','Filter');
3501 if($num_quarters == 1) {
3502 $this->t->set_var('lang_num_quarters','Quarter of History');
3504 $this->t->set_var('lang_num_quarters','Quarters of History');
3507 $num_months = $num_quarters * 3;
3508 $current_month = $this->current_month;
3509 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
3510 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
3511 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
3512 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
3514 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
3515 $this->db->query($sql,__LINE__,__FILE__);
3517 while ($this->db->next_record()) {
3518 $individual_name[$i] = $this->db->f('name');
3519 $individual[$i] = $this->db->f('individual');
3522 array_multisort($individual_name, $individual);
3524 // Create a list of sunday dates for a window of 3 months back and current month
3528 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, ($current_month-$num_months)+1, 1, date("y")));
3529 $last_date = explode("-",$sunday_list[0]['date']);
3530 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3531 $time_limit = mktime(0, 0, 0, $current_month, 31, date("y"));
3532 while($last_time < $time_limit) {
3533 $day = date("w",$last_time);
3534 if(date("w",$last_time) == 0) {
3535 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3536 $last_date = explode("-",$sunday_list[$i]['date']);
3537 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3538 $sunday_list[$i]['day'] = $last_date[2];
3539 $sunday_list[$i]['month'] = date("M",$last_time);
3540 $sunday_list[$i]['year'] = $last_date[0];
3542 $last_date = $sunday_list[$i]['date'];
3544 $last_time += 90000;
3545 if($found_sunday) { $i++; $found_sunday=0; }
3548 $total_individuals = count($individual);
3549 $old_month=$sunday_list[0]['month']; $span=0;
3550 for ($i=0; $i < count($sunday_list); $i++) {
3551 $date = $sunday_list[$i]['date'];
3552 $this->t->set_var('date',$sunday_list[$i]['date']);
3553 $this->t->set_var('day',$sunday_list[$i]['day']);
3554 if(($old_month != $sunday_list[$i]['month']) || $i == count($sunday_list)-1) {
3555 if($i == count($sunday_list)-1) { $span++; }
3556 $cur_month = $sunday_list[$i]['month'];
3557 $old_month = $sunday_list[$i]['month'];
3558 $link_data['menuaction'] = 'tc.tc.att_update';
3559 $link_data['month'] = $sunday_list[$i-1]['month'];
3560 $link_data['year'] = $sunday_list[$i-1]['year'];
3561 $link_data['action'] = 'update_month';
3562 $cur_month = $sunday_list[$i-1]['month'];
3563 $cur_year = $sunday_list[$i-1]['year'];
3564 $header_row .= "<th><font size=-3>$cur_month $cur_year</font></th>";
3565 $this->t->set_var('update_month',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3566 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3567 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3568 $this->t->set_var('span',$span); $span=0;
3569 $this->t->fp('list1','month_list',True);
3573 $this->t->set_var('total_individuals',$total_individuals);
3574 $this->t->set_var('header_row',$header_row);
3576 $individual_width=200; $att_width=25; $total_width=$individual_width;
3577 for ($i=0; $i < count($sunday_list); $i++) {
3578 $link_data['menuaction'] = 'tc.tc.att_update';
3579 $link_data['month'] = $sunday_list[$i]['month'];
3580 $link_data['year'] = $sunday_list[$i]['year'];
3581 $link_data['day'] = $sunday_list[$i]['day'];
3582 $link_data['date'] = $sunday_list[$i]['date'];
3583 $link_data['action'] = 'update_day';
3584 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3585 $this->t->set_var('date',$sunday_list[$i]['date']);
3586 $this->t->set_var('day',$sunday_list[$i]['day']);
3587 $this->t->set_var('month',$sunday_list[$i]['month']);
3588 $this->t->set_var('year',$sunday_list[$i]['year']);
3589 $this->t->fp('list2','header_list',True);
3590 $total_width += $att_width;
3591 $attendance[$monthnum[$sunday_list[$i]['month']]]=0;
3594 for ($i=0; $i < count($individual); $i++) {
3596 $this->nextmatchs->template_alternate_row_color(&$this->t);
3597 $this->t->set_var('individual_name',$individual_name[$i]);
3598 #print "checking for individual: " . $individual[$i] . "<br>";
3599 for ($j=0; $j < count($sunday_list); $j++) {
3600 #print "checking for date: " . $sunday_list[$j]['date'] . "<br>";
3601 #print "SELECT * FROM tc_attendance WHERE date='"
3602 # . $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i] . "<br>";
3603 $sql = "SELECT * FROM tc_attendance WHERE date='" .
3604 $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i];
3605 $this->db->query($sql,__LINE__,__FILE__);
3606 if($this->db->next_record()) {
3607 $cur_month = $sunday_list[$j]['month'];
3608 if($attended[$i][$cur_month] != 1) {
3609 $attended[$i][$cur_month]=1;
3610 $attendance[$monthnum[$cur_month]]++;
3612 $att_table .= '<td align=center><img src="images/checkmark.gif"></td>';
3614 $att_table .= '<td> </td>';
3617 $this->t->set_var('att_table',$att_table);
3618 $this->t->fp('list3','individual_list',True);
3620 $this->t->set_var('total_width',$total_width);
3621 $this->t->set_var('individual_width',$individual_width);
3622 $this->t->set_var('att_width',$att_width);
3624 # Now calculate attendance for these months
3625 $attendance_str = "";
3626 $nonattendance_str = "";
3627 $aveattendance_str = "";
3628 $avenonattendance_str = "";
3630 $ave_total_attended=0;
3632 foreach($attendance as $att => $value) {
3633 $total_attended = $attendance[$att];
3634 $ave_total_attended += $attendance[$att]; $num_months++;
3635 $percent = ceil(($total_attended / $total_individuals)*100);
3636 $attendance_str.="<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3637 $total_nonattended = $total_individuals - $total_attended;
3638 $percent = ceil(($total_nonattended / $total_individuals)*100);
3639 $nonattendance_str.="<td align=center><font size=-2><b>$total_nonattended ($percent%)</b></font></td>";
3641 $total_attended = ceil(($ave_total_attended / $num_months));
3642 $percent = ceil(($total_attended / $total_individuals)*100);
3643 $aveattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3644 $total_attended = $total_individuals - ceil(($ave_total_attended / $num_months));
3645 $percent = ceil(($total_attended / $total_individuals)*100);
3646 $avenonattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3649 $this->t->set_var('attendance',$attendance_str);
3650 $this->t->set_var('aveattendance',$aveattendance_str);
3651 $this->t->set_var('nonattendance',$nonattendance_str);
3652 $this->t->set_var('avenonattendance',$avenonattendance_str);
3654 $this->t->pfp('out','att_view_t');
3655 $this->save_sessiondata();
3658 function att_update()
3660 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3661 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3662 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3664 $this->t->set_file(array('form' => 'att_update.tpl'));
3665 $this->t->set_block('form','edit','edithandle');
3667 $this->t->set_block('form','month_list','list1');
3668 $this->t->set_block('form','header_list','list2');
3669 $this->t->set_block('form','individual_list','list3');
3671 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3673 $action = get_var('action',array('GET','POST'));
3674 $month = get_var('month',array('GET','POST'));
3675 $year = get_var('year',array('GET','POST'));
3676 $day = get_var('day',array('GET','POST'));
3677 $date = get_var('date',array('GET','POST'));
3679 if($action == 'save_month' || $action == 'save_day') {
3680 $new_data = get_var('individuals_attended',array('POST'));
3681 $month = $monthnum[$month]; if($month < 10) { $month = "0" . $month; }
3683 if($action == 'save_month') {
3684 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-%'",__LINE__,__FILE__);
3687 if($action == 'save_day') {
3688 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-".$day."'",__LINE__,__FILE__);
3691 foreach ($new_data as $data) {
3692 $data_array = explode("-",$data);
3693 $indiv = $data_array[0];
3694 $date = "$data_array[1]-$data_array[2]-$data_array[3]";
3695 $this->db->query("INSERT INTO tc_attendance (individual,date) " .
3696 "VALUES (" . $indiv . ",'". $date . "')",__LINE__,__FILE__);
3703 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
3704 $this->db->query($sql,__LINE__,__FILE__);
3706 while ($this->db->next_record()) {
3707 $indiv_name[$i] = $this->db->f('name');
3708 $individual[$i] = $this->db->f('individual');
3709 $indiv_attending[$individual[$i]] = $this->db->f('attending');
3712 array_multisort($indiv_name, $individual);
3714 if($action == 'update_month') {
3715 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_month'));
3719 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], 1, $year));
3720 $last_date = explode("-",$sunday_list[0]['date']);
3721 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3722 $time_limit = mktime(0, 0, 0, $monthnum[$month], 31, $year);
3723 while($last_time <= $time_limit) {
3724 $day = date("w",$last_time);
3725 if(date("w",$last_time) == 0) {
3726 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3727 $last_date = explode("-",$sunday_list[$i]['date']);
3728 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3729 $sunday_list[$i]['day'] = $last_date[2];
3730 $sunday_list[$i]['month'] = date("M",$last_time);
3731 $sunday_list[$i]['year'] = $last_date[0];
3734 $last_time += 90000;
3735 if($found_sunday) { $i++; $found_sunday=0; }
3738 $this->t->set_var('span', $i);
3739 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3740 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3741 $this->t->fp('list1','month_list',True);
3742 $indiv_width=200; $att_width=25; $total_width=$indiv_width;
3743 for ($i=0; $i < count($sunday_list); $i++) {
3744 $link_data['menuaction'] = 'tc.tc.att_update';
3745 $link_data['month'] = $sunday_list[$i]['month'];
3746 $link_data['year'] = $sunday_list[$i]['year'];
3747 $link_data['day'] = $sunday_list[$i]['day'];
3748 $link_data['date'] = $sunday_list[$i]['date'];
3749 $link_data['action'] = 'update_day';
3750 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3751 $this->t->set_var('date',$sunday_list[$i]['date']);
3752 $this->t->set_var('day',$sunday_list[$i]['day']);
3753 $this->t->set_var('month',$sunday_list[$i]['month']);
3754 $this->t->set_var('year',$sunday_list[$i]['year']);
3755 $this->t->fp('list2','header_list',True);
3756 $total_width += $att_width;
3760 if($action == 'update_day') {
3761 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_day'));
3762 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], $day, $year));
3763 $this->t->set_var('month',$month);
3764 $this->t->set_var('year',$year);
3765 $this->t->fp('list1','month_list',True);
3766 $this->t->set_var('date',$date);
3767 $this->t->set_var('day',$day);
3768 $this->t->set_var('month',$month);
3769 $this->t->set_var('year',$year);
3770 $this->t->fp('list2','header_list',True);
3773 for ($i=0; $i < count($individual); $i++) {
3775 $this->nextmatchs->template_alternate_row_color(&$this->t);
3776 $this->t->set_var('individual_name',$indiv_name[$i]);
3777 for ($j=0; $j < count($sunday_list); $j++) {
3778 $sql = "SELECT * FROM tc_attendance WHERE date='" .
3779 $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i];
3780 $this->db->query($sql,__LINE__,__FILE__);
3781 $value = $individual[$i] . "-" . $sunday_list[$j]['date'];
3782 if($this->db->next_record()) {
3783 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'" checked></td>';
3784 } else if($indiv_attending[$individual[$i]] == 1) {
3785 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'" checked></td>';
3787 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'"></td>';
3790 $this->t->set_var('att_table',$att_table);
3791 $this->t->fp('list3','individual_list',True);
3794 $this->t->set_var('lang_done', 'Cancel');
3795 $this->t->set_var('lang_reset','Clear Form');
3796 $this->t->set_var('lang_save','Save Changes');
3798 $this->t->pfp('out','form');
3799 $this->t->pfp('addhandle','edit');
3801 $this->save_sessiondata();
3806 $this->t->set_file(array('dir_view_t' => 'dir_view.tpl'));
3807 $this->t->set_block('dir_view_t','dir_list','list');
3809 $sql = "SELECT * FROM tc_individual where valid=1 and hh_position='Head of Household' ORDER BY name ASC";
3810 $this->db->query($sql,__LINE__,__FILE__);
3812 while ($this->db->next_record()) {
3813 $parent[$i]['id'] = $this->db->f('individual');
3814 $parent[$i]['name'] = $this->db->f('name');
3815 $parent[$i]['phone'] = $this->db->f('phone');
3816 $parent[$i]['address'] = $this->db->f('address');
3820 for ($i=0; $i < count($parent); $i++) {
3821 $name = $parent[$i]['name'];
3822 $phone = $parent[$i]['phone'];
3823 $address = $parent[$i]['address'];
3824 $this->t->set_var('name', $name);
3825 $this->t->set_var('address', $address);
3826 $this->t->set_var('phone', $phone);
3827 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3828 $this->t->set_var('tr_color',$tr_color);
3829 $this->t->fp('list','dir_list',True);
3830 //print "$phone $name $address<br>";
3832 $this->t->pfp('out','dir_view_t');
3833 $this->save_sessiondata();
3838 $this->t->set_file(array('org_view_t' => 'org_view.tpl'));
3839 $this->t->set_block('org_view_t','calling_list','list1');
3840 $this->t->set_block('org_view_t','org_list','list2');
3842 # Display a list ordered alphabetically
3843 $sql = "SELECT * FROM tc_calling AS tc JOIN tc_individual AS ti WHERE tc.individual=ti.individual ORDER BY name ASC";
3844 $this->db->query($sql,__LINE__,__FILE__);
3846 while ($this->db->next_record()) {
3847 $calling[$i]['name'] = $this->db->f('name');
3848 $calling[$i]['position'] = $this->db->f('position');
3849 $calling[$i]['sustained'] = $this->db->f('sustained');
3850 $calling[$i]['organization'] = $this->db->f('organization');
3853 for ($i=0; $i < count($calling); $i++) {
3854 $name = $calling[$i]['name'];
3855 $position = $calling[$i]['position'];
3856 $sustained = $calling[$i]['sustained'];
3857 $organization = $calling[$i]['organization'];
3858 $this->t->set_var('name', $name);
3859 $this->t->set_var('position', $position);
3860 $this->t->set_var('sustained', $sustained);
3861 $this->t->set_var('organization', $organization);
3862 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3863 $this->t->set_var('tr_color',$tr_color);
3864 $this->t->fp('list1','calling_list',True);
3867 # Display a list ordered by organization
3868 $sql = "SELECT * FROM tc_calling AS tc JOIN tc_individual AS ti where tc.individual=ti.individual ORDER BY organization ASC";
3869 $this->db->query($sql,__LINE__,__FILE__);
3871 while ($this->db->next_record()) {
3872 $calling[$i]['name'] = $this->db->f('name');
3873 $calling[$i]['position'] = $this->db->f('position');
3874 $calling[$i]['sustained'] = $this->db->f('sustained');
3875 $calling[$i]['organization'] = $this->db->f('organization');
3878 for ($i=0; $i < count($calling); $i++) {
3879 $name = $calling[$i]['name'];
3880 $position = $calling[$i]['position'];
3881 $sustained = $calling[$i]['sustained'];
3882 $organization = $calling[$i]['organization'];
3883 $this->t->set_var('name', $name);
3884 $this->t->set_var('position', $position);
3885 $this->t->set_var('sustained', $sustained);
3886 $this->t->set_var('organization', $organization);
3887 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3888 $this->t->set_var('tr_color',$tr_color);
3889 $this->t->fp('list2','org_list',True);
3892 $this->t->pfp('out','org_view_t');
3893 $this->save_sessiondata();
3898 $this->t->set_file(array('sched_t' => 'schedule.tpl'));
3899 $this->t->set_block('sched_t','presidency_list','list');
3901 $action = get_var('action',array('GET','POST'));
3903 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule&action=save'));
3904 $this->t->set_var('title','Scheduling Tool');
3906 $this->t->set_var('lang_save','Save Schedule');
3907 $this->t->set_var('lang_reset','Cancel');
3909 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
3910 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
3912 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
3913 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
3915 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
3916 $this->t->set_var('schedule_ppi_link_title','Schedule ' . $this->ppi_frequency_label . ' PPIs');
3918 $date_width=160; $time_width=220; $indiv_width=170; $family_width=180; $location_width=100;
3919 $table_width=$date_width + $time_width + $indiv_width + $family_width + $location_width;
3920 $header_row = "<th width=$date_width><font size=-2>Date</th>";
3921 $header_row.= "<th width=$time_width><font size=-2>Time</th>";
3922 $header_row.= "<th width=$indiv_width><font size=-2>Individual</th>";
3923 $header_row.= "<th width=$family_width><font size=-2>Family</th>";
3924 $header_row.= "<th width=$location_width><font size=-2>Location</th>";
3927 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1 GROUP BY tp.individual ORDER BY ti.name ASC";
3928 $this->db->query($sql,__LINE__,__FILE__);
3930 while ($this->db->next_record()) {
3931 $presidency_data[$i]['id'] = $this->db->f('presidency');
3932 $presidency_data[$i]['name'] = $this->db->f('name');
3933 $presidency_data[$i]['indiv'] = $this->db->f('individual');
3934 $presidency2name[$presidency_data[$i]['id']] = $presidency_data[$i]['name'];
3935 $presidency2indiv[$presidency_data[$i]['id']] = $presidency_data[$i]['indiv'];
3939 $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";
3940 $this->db->query($sql,__LINE__,__FILE__);
3942 while ($this->db->next_record()) {
3943 $family_id[$i] = $this->db->f('family');
3944 $family_name[$i] = $this->db->f('name');
3945 $familyid2name[$family_id[$i]] = $family_name[$i];
3946 $familyid2address[$family_id[$i]] = $this->db->f('address');
3949 array_multisort($family_name, $family_id);
3951 if($action == 'save') {
3952 $new_data = get_var('sched',array('POST'));
3953 foreach ($new_data as $presidency_array) {
3954 foreach ($presidency_array as $entry) {
3955 $presidency = $entry['presidency'];
3956 $appointment = $entry['appointment'];
3957 $location = $entry['location'];
3958 $date = $entry['date'];
3959 $hour = $entry['hour'];
3960 $minute = $entry['minute'];
3962 $indiv = $entry['individual'];
3963 $family = $entry['family'];
3964 $location = $entry['location'];
3965 if($pm) { $hour = $hour + 12; }
3966 $time = $hour.':'.$minute.':'.'00';
3969 // Zero out family or individual if they are invalid
3970 if($indiv == "") { $indiv=0; }
3971 if($family == "") { $family=0; }
3973 // Update our location
3974 if($location == "") {
3976 $family_name_array = explode(",", $familyid2name[$family]);
3977 $family_last_name = $family_name_array[0];
3978 $family_address = $familyid2address[$family];
3979 $location = "$family_last_name"." home ($family_address)";
3980 } else if($indiv > 0) {
3981 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
3982 $supervisor_last_name = $supervisor_name_array[0];
3983 #print "presidency2indiv: $presidency $presidency2indiv[$presidency]<br>";
3984 $sql = "SELECT * FROM tc_individual where individual='$presidency2indiv[$presidency]'";
3985 $this->db2->query($sql,__LINE__,__FILE__);
3986 if($this->db2->next_record()) {
3987 $supervisor_address = $this->db2->f('address');
3989 $location = "$supervisor_last_name"." home ($supervisor_address)";
3993 // Zero out the family or individual if date = NULL
4000 if(($indiv == 0) && ($family == 0)) { $location = ""; }
4002 // Update an existing appointment
4003 if($appointment < $this->max_appointments)
4005 //Only perform a database update if we have made a change to this appointment
4006 $sql = "SELECT * FROM tc_appointment where " .
4007 "appointment='$appointment'" .
4008 " and presidency='$presidency'" .
4009 " and individual='$indiv'" .
4010 " and family='$family'" .
4011 " and date='$date'" .
4012 " and time='$time'" .
4013 " and location='$location'";
4014 $this->db->query($sql,__LINE__,__FILE__);
4015 if(!$this->db->next_record()) {
4016 $old_date = $this->db->f('date');
4017 $old_time = $this->db->f('time');
4018 $this->db2->query("UPDATE tc_appointment set" .
4019 " family=" . $family .
4020 " ,individual=" . $indiv .
4021 " ,date='" . $date . "'" .
4022 " ,time='" . $time . "'" .
4023 " ,location='" . $location . "'" .
4024 " ,presidency='" . $presidency . "'" .
4025 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4027 // Email the appointment
4028 $this->email_appt($appointment);
4032 // Add a new appointment
4033 else if(($appointment >= $this->max_appointments) && ($date != "") && ($time != ""))
4035 //print "adding entry: appt=$appointment date: $date time: $time individual: $indiv family: $family<br>";
4036 $this->db2->query("INSERT INTO tc_appointment (appointment,presidency,family,individual,date,time,location,uid) " .
4037 "VALUES (NULL,'" . $presidency . "','" . $family . "','" . $indiv . "','" .
4038 $date . "','" . $time . "','" . $location . "','" . $uid ."')",__LINE__,__FILE__);
4040 // Now reselect this entry from the database to see if we need
4041 // to send an appointment out for it.
4042 $sql = "SELECT * FROM tc_appointment where " .
4043 "individual='$indiv'" .
4044 " and family='$family'" .
4045 " and presidency='$presidency'" .
4046 " and date='$date'" .
4047 " and time='$time'" .
4049 " and location='$location'";
4050 $this->db3->query($sql,__LINE__,__FILE__);
4051 if($this->db3->next_record()) {
4052 // Email the appointment if warranted
4053 if(($date != "") && ($time != "") && (($indiv > 0) || $family > 0)) {
4054 $this->email_appt($this->db3->f('appointment'));
4061 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule');
4062 //Header('Location: ' . $take_me_to_url);
4065 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY individual ASC";
4066 $this->db->query($sql,__LINE__,__FILE__);
4068 while ($this->db->next_record()) {
4069 $individual[$i] = $this->db->f('individual');
4070 $indiv_name[$i] = $this->db->f('name');
4071 $indiv_phone[$individual[$i]] = $this->db->f('phone');
4074 array_multisort($indiv_name, $individual);
4076 for ($i=0; $i < count($presidency_data); $i++) {
4077 $presidency = $presidency_data[$i]['id'];
4078 $interviewer = $presidency_data[$i]['individual'];
4079 $name = $presidency_data[$i]['name'];
4080 $this->t->set_var('presidency_name',$name);
4083 // query the database for all the appointments
4084 $sql = "SELECT * FROM tc_appointment where presidency=$presidency and date>=CURDATE() ORDER BY date ASC, time ASC";
4085 $this->db->query($sql,__LINE__,__FILE__);
4087 // Prefill any existing appointment slots
4088 while ($this->db->next_record()) {
4089 $appointment = $this->db->f('appointment');
4090 $indiv = $this->db->f('individual');
4091 $family = $this->db->f('family');
4092 $location = $this->db->f('location');
4094 if($location == "") {
4096 $family_name_array = explode(",", $familyid2name[$family]);
4097 $family_last_name = $family_name_array[0];
4098 $family_address = $familyid2address[$family];
4099 $location = "$family_last_name"." home ($family_address)";
4100 } else if($indiv > 0) {
4101 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
4102 $supervisor_last_name = $supervisor_name_array[0];
4103 $sql = "SELECT * FROM tc_individual where individual='$presidency2indiv[$presidency]'";
4104 $this->db2->query($sql,__LINE__,__FILE__);
4105 if($this->db2->next_record()) {
4106 $supervisor_address = $this->db2->f('address');
4108 $location = "$supervisor_last_name"." home ($supervisor_address)";
4112 $date = $this->db->f('date');
4113 $date_array = explode("-",$date);
4114 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
4115 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
4117 $time = $this->db->f('time');
4118 $time_array = explode(":",$time);
4119 $hour = $time_array[0];
4120 $minute = $time_array[1];
4122 if($hour > 12) { $pm=1; $hour = $hour - 12; }
4123 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
4125 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4128 $table_data.= '<td align=left>';
4129 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]',$date,'','','','','',$this->cal_options);
4130 $table_data.= '</td>';
4132 // Hour & Minutes selection
4133 $table_data.= "<td align=center>";
4134 $table_data .= $this->get_time_selection_form($hour, $minute, $pm, $presidency, $appointment);
4135 $table_data.= "</td>";
4137 // individual drop down list (for PPIs)
4138 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][individual] STYLE="font-size : 8pt">';
4139 $table_data.= '<option value=0></option>';
4140 for ($j=0; $j < count($individual); $j++) {
4141 $id = $individual[$j];
4142 $name = $indiv_name[$j];
4143 if($individual[$j] == $indiv) {
4144 $selected[$id] = 'selected="selected"';
4146 $selected[$id] = '';
4148 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
4150 $table_data.='</select></td>';
4152 // Family drop down list (for Visits)
4153 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family] STYLE="font-size : 8pt">';
4154 $table_data.= '<option value=0></option>';
4155 for ($j=0; $j < count($individual); $j++) {
4156 $id = $family_id[$j];
4157 $name = $family_name[$j];
4158 if($family_id[$j] == $family) {
4159 $selected[$id] = 'selected="selected"';
4161 $selected[$id] = '';
4163 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
4165 $table_data.='</select></td>';
4167 // Location text box
4168 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
4169 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="'.$location.'" STYLE="font-size : 8pt">';
4171 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
4172 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
4174 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4175 $this->t->set_var('tr_color',$tr_color);
4178 // Create blank appointment slot
4179 for ($b=0; $b < 4; $b++) {
4180 $appointment = $this->max_appointments + $b;
4181 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4184 $table_data.= '<td align=left>';
4185 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]','','','','','','',$this->cal_options);
4186 $table_data.= '</td>';
4189 $table_data.= "<td align=center>";
4190 $table_data .= $this->get_time_selection_form(0, 0, 0, $presidency, $appointment);
4191 $table_data.= "</td>";
4193 // individual drop down list
4194 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][individual] STYLE="font-size : 8pt">';
4195 $table_data.= '<option value=0></option>';
4196 for ($j=0; $j < count($individual); $j++) {
4197 $id = $individual[$j];
4198 $name = $indiv_name[$j];
4199 $table_data.= '<option value='.$id.'>'.$name.'</option>';
4201 $table_data.='</select></td>';
4203 // Family drop down list
4204 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family] STYLE="font-size : 8pt">';
4205 $table_data.= '<option value=0></option>';
4206 for ($j=0; $j < count($individual); $j++) {
4207 $id = $family_id[$j];
4208 $name = $family_name[$j];
4209 $table_data.= '<option value='.$id.'>'.$name.' Family</option>';
4211 $table_data.='</select></td>';
4213 // Location text box
4214 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
4215 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="" STYLE="font-size : 8pt">';
4217 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
4218 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
4220 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4221 $this->t->set_var('tr_color',$tr_color);
4224 $this->t->set_var('table_data',$table_data);
4225 $this->t->set_var('header_row',$header_row);
4226 $this->t->set_var('table_width',$table_width);
4227 $this->t->fp('list','presidency_list',True);
4230 $this->t->pfp('out','sched_t');
4231 $this->save_sessiondata();
4236 $this->t->set_file(array('email_t' => 'email.tpl'));
4237 $this->t->set_block('email_t','individual_list','list');
4239 $action = get_var('action',array('GET','POST'));
4241 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email'));
4242 $this->t->set_var('title','Email Tool');
4244 $this->t->set_var('lang_email','Send Email');
4245 $this->t->set_var('lang_reset','Cancel');
4247 $this->t->set_var('email_member_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=member'));
4248 $this->t->set_var('email_member_link_title','Email Quorum Member');
4250 $this->t->set_var('email_quorum_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=quorum'));
4251 $this->t->set_var('email_quorum_link_title','Email Quorum');
4253 $this->t->set_var('email_reminder_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=reminder'));
4254 $this->t->set_var('email_reminder_link_title','Email Reminders');
4256 $this->t->set_var('email_edit_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=edit'));
4257 $this->t->set_var('email_edit_link_title','Edit Email Addresses');
4260 $this->t->set_var('table_width',$table_width);
4262 $this->t->pfp('out','email_t');
4263 $this->save_sessiondata();
4268 $this->t->set_file(array('admin_t' => 'admin.tpl'));
4269 $this->t->set_block('admin_t','upload','uploadhandle');
4270 $this->t->set_block('admin_t','admin','adminhandle');
4271 $this->t->set_block('admin_t','cmd','cmdhandle');
4272 $this->t->set_block('admin_t','presidency','presidencyhandle');
4274 $this->t->set_var('upload_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=upload'));
4275 $this->t->set_var('presidency_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=presidency'));
4277 $action = get_var('action',array('GET','POST'));
4279 $this->t->pfp('out','admin_t');
4281 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY individual ASC";
4282 $this->db->query($sql,__LINE__,__FILE__);
4284 while ($this->db->next_record()) {
4285 $individual[$i] = $this->db->f('individual');
4286 $indiv_name[$i] = $this->db->f('name');
4287 $indiv2name[$individual[$i]] = $indiv_name[$i];
4290 array_multisort($indiv_name, $individual);
4292 if($action == 'upload') {
4293 $target_path = $this->upload_target_path . '/' . basename( $_FILES['uploadedfile']['name']);
4295 if(($_FILES['uploadedfile']['type'] == "application/zip") ||
4296 ($_FILES['uploadedfile']['type'] == "application/x-zip-compressed") ||
4297 ($_FILES['uploadedfile']['type'] == "application/x-zip") ||
4298 ($_FILES['uploadedfile']['type'] == "application/octet-stream")) {
4300 if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
4301 $uploadstatus = "<b><font color=red> -E- Unable to move the uploaded file to ";
4302 $uploadstatus.= "the target path (check the path and permissions) of: $target_path</font></b>";
4303 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
4304 $uploadstatus.= "Tmp Filename : " . $_FILES['uploadedfile']['tmp_name'] . "<br>";
4305 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
4306 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
4307 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
4308 $uploadstatus.= "Error : " . $_FILES['uploadedfile']['error'] . "<br>";
4309 $this->t->set_var('uploadstatus',$uploadstatus);
4310 $this->t->pfp('uploadhandle','upload',True);
4314 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
4315 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
4316 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
4317 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
4318 $this->t->set_var('uploadstatus',$uploadstatus);
4319 $this->t->pfp('uploadhandle','upload');
4320 $this->t->set_var('uploadhandle','');
4321 print "<table border=1 width=80%><tr><td>\n<pre>";
4323 # make a directory for this data to be stored in
4324 $date="data_" . date("Y_m_d");
4325 $data_dir = $this->upload_target_path . '/' . $date;
4326 print "-> Making the data directory: $date<br>\n";
4327 exec('mkdir -p ' . $data_dir . ' 2>&1', $result, $return_code);
4328 if($return_code != 0) {
4329 print implode('\n',$result) . "<br>";
4330 print "<b><font color=red>";
4331 print "-E- Unable to create the data directory. Aborting import.";
4332 print "</font></b>";
4336 # move the file uploaded into this directory
4337 print "-> Moving the uploaded file into the data dir<br>\n";
4338 exec('mv ' . $target_path . ' ' . $data_dir . '/' . ' 2>&1', $result, $return_code);
4339 if($return_code != 0) {
4340 print implode('\n',$result) . "<br>";
4341 print "<b><font color=red>";
4342 print "-E- Unable to move the uploaded file into the data dir. Aborting import.";
4343 print "</font></b>";
4347 # unzip the data into this directory
4348 print "-> Unzipping the data<br>\n";
4349 exec($this->unzip_path .' -u '. $data_dir . '/*.zip -d ' . $data_dir . ' 2>&1', $result, $return_code);
4350 if($return_code != 0) {
4351 print implode('\n',$result) . "<br>";
4352 print "<b><font color=red>";
4353 print "-E- Unable to unzip the uploaded file into the data dir: $data_dir. Aborting import.";
4354 print "</font></b>";
4357 exec('mv ' . $data_dir . '/*/* '. $data_dir . ' 2>&1', $result, $return_code);
4359 # update the data_latest link to point to this new directory
4360 print "-> Updating the latest data dir link<br>\n";
4361 $data_latest = $this->upload_target_path . '/data_latest';
4362 exec('rm ' . $data_latest. '; ln -s ' . $data_dir .' '. $data_latest .' 2>&1', $result, $return_code);
4363 if($return_code != 0) {
4364 print implode('\n',$result) . "<br>";
4365 print "<b><font color=red>";
4366 print "-E- Unable to update the data latest link. Aborting import.";
4367 print "</font></b>";
4371 # run the import perl script to encorporate it into the DB
4372 ob_start('ob_logstdout', 2);
4373 print "-> Importing the data into the database<br>\n";
4374 ob_flush(); flush(); sleep(1);
4375 $import_log = $this->upload_target_path . '/import.log';
4376 $data_log = $this->upload_target_path . '/data.log';
4377 $import_cmd = $this->script_path . '/import_ward_data ' . $data_latest . ' 2>&1 | tee ' . $import_log;
4378 $parse_cmd = $this->script_path . '/parse_ward_data -v ' . $data_latest . ' > ' . $data_log . '2>&1';
4379 #print "import_cmd: $import_cmd<br>";
4380 #print "parse_cmd: $parse_cmd<br>";
4381 ob_start('ob_logstdout', 2);
4382 passthru($import_cmd);
4383 passthru($parse_cmd);
4384 ob_flush(); flush(); sleep(1);
4386 # fix the permissions of the data dir
4387 exec('chmod -R o-rwx ' . $data_dir, $result, $return_code);
4389 $this->t->pfp('cmdhandle','cmd');
4390 print "</pre></td></tr></table>";
4391 } else if(($_FILES['uploadedfile']['type'] != "application/zip") &&
4392 ($_FILES['uploadedfile']['type'] != "application/x-zip-compressed") &&
4393 ($_FILES['uploadedfile']['type'] != "application/x-zip") &&
4394 ($_FILES['uploadedfile']['type'] != "application/octet-stream")) {
4395 $uploadstatus = "<b><font color=red>The file format must be a .zip file, please try again! </font></b>";
4396 $uploadstatus.= "<br><br><b>Detected file format: " . $_FILES['uploadedfile']['type'] . "</b>";
4397 $this->t->set_var('uploadstatus',$uploadstatus);
4398 $this->t->pfp('uploadhandle','upload',True);
4400 $uploadstatus = "<b><font color=red> There was an error (" . $_FILES['uploadedfile']['error'];
4401 $uploadstatus.= ") uploading the file, please try again! </font></b>";
4402 $this->t->set_var('uploadstatus',$uploadstatus);
4403 $this->t->pfp('uploadhandle','upload',True);
4405 } else if($action == "presidency") {
4406 $new_data = get_var('eqpres',array('POST'));
4407 foreach ($new_data as $entry) {
4409 $email = $entry['email'];
4410 $indiv = $entry['indiv'];
4411 $name = $entry['name'];
4412 $district = $entry['district'];
4413 $president = $entry['president'];
4414 $counselor = $entry['counselor'];
4415 $secretary = $entry['secretary'];
4416 // look up the individual name for the ID
4417 $name = $indiv2name[$indiv];
4418 //print "id=$id indiv=$indiv name=$name email=$email district=$district president=$president ";
4419 //print "counselor=$counselor secretary=$secretary<br>";
4421 if(($indiv > 0) || ($name != "")) {
4422 if($id < $this->max_presidency_members) {
4423 //print "Updating Existing Entry<br>";
4424 $this->db2->query("UPDATE tc_presidency set" .
4425 " individual=" . $indiv .
4426 " ,district=" . $district .
4427 " ,email='" . $email . "'" .
4428 " ,president='" . $president . "'" .
4429 " ,counselor='" . $counselor . "'" .
4430 " ,secretary='" . $secretary . "'" .
4431 " WHERE presidency=" . $id,__LINE__,__FILE__);
4433 //print "Adding New Entry<br>";
4434 $this->db2->query("INSERT INTO tc_presidency (presidency,individual,district," .
4435 "email,president,counselor,secretary,valid) " .
4436 "VALUES (NULL,'" . $indiv . "','" . $district . "','" .
4437 $email . "','" . $president . "','" .
4438 $counselor . "','" . $secretary . "','1'" .
4439 ")",__LINE__,__FILE__);
4442 //print "Ignoring Blank Entry<br>";
4446 // Now update the tc_district table appropriately
4448 // Delete all the previous district entries from the table
4449 $this->db->query("DELETE from tc_district where valid=1",__LINE__,__FILE__);
4450 $this->db->query("DELETE from tc_district where valid=0",__LINE__,__FILE__);
4452 // Always add a "District 0" assigned to the High Priests Group
4454 $name = "High Priests";
4457 $this->db2->query("INSERT INTO tc_district (district,supervisor,valid) " .
4458 "VALUES ('" . $district . "','" .
4459 $indiv . "','" . $valid . "'" .
4460 ")",__LINE__,__FILE__);
4462 // Requery the tc_presidency table
4463 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1";
4464 $this->db->query($sql,__LINE__,__FILE__);
4465 while ($this->db->next_record()) {
4466 // Extract the data for each presidency record
4467 $id = $this->db->f('presidency');
4468 $indiv = $this->db->f('individual');
4469 $name = $this->db->f('name');
4470 $district = $this->db->f('district');
4473 // If we have a valid district, add it to the district table
4475 $this->db2->query("INSERT INTO tc_district (district,supervisor,valid) " .
4476 "VALUES ('" . $district . "','" .
4477 $indiv . "','" . $valid . "'" .
4478 ")",__LINE__,__FILE__);
4482 $this->t->set_var('adminhandle','');
4483 $this->t->pfp('adminhandle','admin');
4487 $this->t->set_var('adminhandle','');
4488 $this->t->pfp('adminhandle','admin');
4491 // Now save off the data needed for a Presidency Table Update
4493 $sql = "SELECT tp.*, ti.name FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1";
4494 $this->db->query($sql,__LINE__,__FILE__);
4496 $header_row = "<th>Individual</th><th>Email</th><th>District</th><th>President</th><th>Counselor</th><th>Secretary</th>";
4497 while ($this->db->next_record()) {
4498 // Extract the data for each presidency record
4499 $id = $this->db->f('presidency');
4500 $indiv = $this->db->f('individual');
4501 $district = $this->db->f('district');
4502 $name = $this->db->f('name');
4503 $email = $this->db->f('email');
4504 $president = $this->db->f('president');
4505 $counselor = $this->db->f('counselor');
4506 $secretary = $this->db->f('secretary');
4508 // Create the forms needed in the table
4509 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4512 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4515 if($eqpresidency == 0) {
4516 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4517 $table_data.= '<option value=0></option>';
4518 for ($j=0; $j < count($individual); $j++) {
4519 $tmp_id = $individual[$j];
4520 $name = $indiv_name[$j];
4521 if($individual[$j] == $indiv) {
4523 $selected = 'selected="selected"';
4527 $table_data.= '<option value='.$tmp_id.' '.$selected.'>'.$name.'</option>';
4529 $table_data.='</select></td>';
4530 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="'.$indivname.'">';
4532 $table_data.= '<td align=left><input type=text size="20" name="eqpresname" value="Presidency"></td>';
4533 $table_data.= '<input type=hidden name="eqpres['.$id.'][name]" value="Presidency">';
4537 $table_data .= '<td><input type="text" size="50" name="eqpres['.$id.'][email]" value="'.$email.'"></td>';
4540 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4541 $table_data.= '<option value=0></option>';
4542 for ($j=0; $j <= $this->max_num_districts; $j++) {
4543 if($district == $j) {
4544 $selected = 'selected="selected"';
4548 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4550 $table_data.='</select></td>';
4553 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4554 if($president == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4555 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4556 $table_data.='</select></td>';
4559 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4560 if($counselor == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4561 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4562 $table_data.='</select></td>';
4565 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4566 if($secretary == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4567 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4568 $table_data.='</select></td>';
4571 $table_data .= "</tr>\n";
4572 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4573 $this->t->set_var('tr_color',$tr_color);
4576 // Now create 1 blank row to always have a line available to add a new individual with
4577 $id = $this->max_presidency_members;
4578 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4580 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4582 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4583 $table_data.= '<option value=0></option>';
4584 for ($j=0; $j < count($individual); $j++) {
4585 $tmp_id = $individual[$j];
4586 $name = $indiv_name[$j];
4587 $table_data.= '<option value='.$tmp_id.'>'.$name.'</option>';
4589 $table_data.='</select></td>';
4590 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="">';
4592 $table_data.='<td><input type="text" size="50" name="eqpres['.$id.'][email]" value=""></td>';
4594 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4595 $table_data.= '<option value=0></option>';
4596 for ($j=0; $j <= $this->max_num_districts; $j++) {
4598 $selected = 'selected="selected"';
4602 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4604 $table_data.='</select></td>';
4606 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4607 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4608 $table_data.='</select></td>';
4610 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4611 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4612 $table_data.='</select></td>';
4614 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4615 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4616 $table_data.='</select></td>';
4618 $table_data .= "</tr>\n";
4619 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4620 $this->t->set_var('tr_color',$tr_color);
4622 $this->t->set_var('header_row',$header_row);
4623 $this->t->set_var('table_data',$table_data);
4624 $this->t->pfp('presidencyhandle','presidency',True);
4626 $this->save_sessiondata();
4629 function email_appt($appointment)
4631 //print "Emailing notification of appointment: $appointment <br>";
4633 $sql = "SELECT * FROM tc_appointment where appointment='$appointment'";
4634 $this->db->query($sql,__LINE__,__FILE__);
4636 while ($this->db->next_record()) {
4637 $appointment = $this->db->f('appointment');
4638 $presidency = $this->db->f('presidency');
4639 $location = $this->db->f('location');
4642 $indiv = $this->db->f('individual');
4644 $family = $this->db->f('family');
4648 $uid = $this->db->f('uid');
4650 // Extract the year, month, day, hours, minutes, seconds from the appointment time
4651 $appt_date = $this->db->f('date');
4652 $date_array = explode("-",$appt_date);
4653 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
4654 $appt_time = $this->db->f('time');
4655 $time_array = explode(":",$appt_time);
4656 $hour = $time_array[0]; $minute = $time_array[1]; $seconds = $time_array[2];
4658 // Format the appointment time into an iCal UTC equivalent
4659 $dtstamp = gmdate("Ymd"."\T"."His"."\Z");
4660 $dtstart = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds,$month,$day,$year));
4661 $dtstartstr = date("l, F d, o g:i A", mktime($hour,$minute,$seconds,$month,$day,$year));
4663 $sql = "SELECT tp.email AS email1, ti.email AS email2, ti.name AS name FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.presidency='$presidency'";
4664 $this->db2->query($sql,__LINE__,__FILE__);
4665 if($this->db2->next_record()) {
4666 if ($this->db2->f('email1') != "") {
4667 $email = $this->db2->f('email1');
4669 $email = $this->db2->f('email2');
4671 $interviewer = $this->db2->f('name');
4674 // Set the email address of the interviewer
4678 $sql = "SELECT * FROM tc_individual where individual='$indiv'";
4679 $this->db2->query($sql,__LINE__,__FILE__);
4680 if($this->db2->next_record()) {
4681 $indiv_name = $this->db2->f('name');
4682 $phone = $this->db2->f('phone');
4683 $appt_name = $indiv_name . " Interview";
4684 $duration = $this->default_ppi_appt_duration * 60;
4689 $sql = "SELECT * FROM tc_family WHERE family='$family'";
4690 $this->db2->query($sql,__LINE__,__FILE__);
4691 if($this->db2->next_record()) {
4692 $individual = $this->db2->f('individual');
4693 $sql = "SELECT * FROM tc_individual where individual='$individual'";
4694 $this->db3->query($sql,__LINE__,__FILE__);
4695 if($this->db3->next_record()) {
4696 $phone = $this->db3->f('phone');
4697 $family_name = $this->db3->f('name');
4698 $phone = $this->db3->f('phone');
4700 $appt_name = $family_name . " Family Visit";
4701 $duration = $this->default_visit_appt_duration * 60;
4705 $dtend = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4706 $dtendstr = date("g:i A", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4707 $date = $dtstartstr . "-" . $dtendstr;
4708 $description = "$appt_name : $phone";
4710 if(($uid == 0) && ($appt_name != "")) {
4711 // Create a new calendar item for this appointment, since this must be the first time we
4712 // are sending it out.
4713 print "Sent new appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4714 $uid = rand() . rand(); // Generate a random identifier for this appointment
4715 $subject = "Created: $appt_name";
4717 $this->db->query("UPDATE tc_appointment set" .
4719 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4721 $action = "PUBLISH";
4722 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4723 $dtend, $date, $location, $appt_name, $description, $uid);
4724 } else if(($uid != 0) && ($appt_name == "")) {
4725 // Remove the calendar item for this appointment since it has already been sent
4726 // and there is no name we have changed it to.
4727 print "Sent deleted appointment to " . $interviewer . " at " . $email . " for " . $appt_date . " " . $appt_time . "<br>";
4728 $subject = "Canceled: $appt_date $appt_time";
4730 $this->db->query("UPDATE tc_appointment set" .
4732 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4735 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4736 $dtend, $date, $location, $subject, $subject, $uid);
4737 } else if($uid != 0) {
4738 // Update the existing appointment since we have changed it
4739 print "Sent updated appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4741 $subject = "Canceled: $appt_date $appt_time";
4743 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4744 $dtend, $date, $location, $subject, $subject, $uid);
4746 $uid = rand() . rand(); // Generate a random identifier for this appointment
4747 $this->db->query("UPDATE tc_appointment set" .
4749 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4751 $subject = "Updated: $appt_name";
4752 $action = "PUBLISH";
4753 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4754 $dtend, $date, $location, $appt_name, $description, $uid);
4760 function send_ical_appt($action, $to, $from, $subject, $dtstamp, $dtstart, $dtend, $date, $location, $summary, $description, $uid)
4762 // Initialize our local variables
4763 $boundary = "=MIME_APPOINTMENT_BOUNDARY";
4767 // Form the headers for the email message
4768 $headers.="X-Mailer: PHP/" . phpversion() . "\n";
4769 $headers.="Mime-Version: 1.0\n";
4770 $headers.="Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
4771 $headers.="Content-Disposition: inline\n";
4772 $headers.="Reply-To: $from\n";
4773 $headers.="From: $from\n";
4775 // Print the plaintext version of the appointment
4776 $message.="--$boundary\n";
4777 $message.="Content-Type: text/plain; charset=us-ascii\n";
4778 $message.="Content-Disposition: inline\n";
4780 $message.="What: $description\n";
4781 $message.="When: $date\n";
4782 $message.="Where: $location\n";
4785 // Print the .ics attachment version of the appointment
4786 $message.="--$boundary\n";
4787 $message.="Content-Type: text/calendar; charset=us-ascii\n";
4788 $message.="Content-Disposition: attachment; filename=\"appointment.ics\"\n";
4790 $message.="BEGIN:VCALENDAR" . "\n";
4791 $message.="VERSION:2.0" . "\n";
4792 $message.="PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN" . "\n";
4793 $message.="METHOD:$action" . "\n";
4794 $message.="BEGIN:VEVENT" . "\n";
4795 $message.="ORGANIZER:MAILTO:$from". "\n";
4796 $message.="DTSTAMP:$dtstamp" . "\n";
4797 $message.="DTSTART:$dtstart" . "\n";
4798 $message.="DTEND:$dtend" . "\n";
4799 $message.="SUMMARY:$summary" . "\n";
4800 $message.="DESCRIPTION:$description" . "\n";
4801 $message.="LOCATION:$location" . "\n";
4802 $message.="UID:$uid" ."\n";
4803 $message.="TRANSP:OPAQUE" . "\n";
4804 $message.="SEQUENCE:0" . "\n";
4805 $message.="CLASS:PUBLIC" . "\n";
4806 $message.="END:VEVENT" . "\n";
4807 $message.="END:VCALENDAR" . "\n";
4809 // Complete the message
4810 $message.="--$boundary\n";
4813 mail($to, $subject, $message, $headers);
4816 function get_time_selection_form($hour, $minute, $pm, $presidency, $appointment)
4821 if($hour == 0) { $blank = 1; }
4823 if($this->time_drop_down_lists == 1) {
4824 // Create drop down lists to get the time
4825 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][hour]>';
4826 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4827 foreach(range(1,12) as $num) {
4829 $selected = 'selected="selected"';
4833 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4835 $form_data.= '</select>';
4836 $form_data.= ' : ';
4837 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][minute]>';
4838 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4841 if($num < 10) { $num = "0" . "$num"; }
4842 if($minute == $num) {
4843 $selected = 'selected="selected"';
4847 if($blank == 1) { $selected = ""; }
4848 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4849 $num = $num + $this->time_drop_down_list_inc;
4851 $form_data.= '</select>';
4853 // Use free form text fields to get the time
4859 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][hour] value='.$hour.'>';
4861 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][minute] value='.$minute.'>';
4862 $form_data.= ' ';
4864 // Always use a drop-down select form for am/pm
4865 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][pm]>';
4868 $form_data.= '<option value=0 selected>am</option>';
4869 $form_data.= '<option value=1>pm</option>';
4872 $form_data.= '<option value=0>am</option>';
4873 $form_data.= '<option value=1 selected>pm</option>';
4876 $form_data.= '<option value=""></option>';
4877 $form_data.= '<option value=0>am</option>';
4878 $form_data.= '<option value=1>pm</option>';
4880 $form_data.= '</select>';