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 (district) VALUES (\"$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 (district) VALUES (\"$district\")";
544 $this->db2->query($sql,__LINE__,__FILE__);
545 $companionship_sandbox = mysql_insert_id();
547 $sql = "SELECT * FROM tc_companion WHERE companionship=$companionship AND 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__);
566 // get list of companionships
567 $sql = "SELECT DISTINCT companionship FROM tc_companionship_sandbox ORDER BY companionship ASC";
568 $this->db->query($sql,__LINE__,__FILE__);
569 $unique_companionships = '';
570 $unique_companionships[0]['companionship'] = 0;
571 $this->t->set_var('companionship_list','<option value="0">New Companionship</option>');
572 $this->t->fp('c_list','comp_list',True);
574 while ($this->db->next_record()) {
575 $companionship = $this->db->f('companionship');
576 $unique_companionships[$j]['companionship'] = $companionship;
577 $combined_companionship = "";
578 $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";
579 $this->db2->query($sql,__LINE__,__FILE__);
580 while ($this->db2->next_record()) {
581 if ($combined_companionship == "") {
582 $combined_companionship .= $this->db2->f('name');
584 $combined_companionship .= " / " . $this->db2->f('name');
587 $this->t->set_var('companionship_list','<option value="'.$companionship.'">'.$combined_companionship.'</option>');
588 $this->t->fp('c_list','comp_list',True);
592 # get list of districts
593 $sql = "SELECT DISTINCT district FROM tc_district_sandbox ORDER BY district ASC";
594 $this->db->query($sql,__LINE__,__FILE__);
597 while ($this->db->next_record()) {
598 $districts[$num_districts] = $this->db->f('district');
599 $this->t->set_var('district','<option value="'.$districts[$num_districts].'">'.$districts[$num_districts].'</option>');
600 $this->t->fp('d_list','district_list',True);
604 # get list of individuals who are and are not home teachers
605 $sql = "SELECT * FROM tc_individual WHERE steward='$this->default_stewardship' AND valid=1 ORDER BY name ASC";
606 $this->db->query($sql,__LINE__,__FILE__);
607 while ($this->db->next_record()) {
608 $individual = $this->db->f('individual');
609 $name = $this->db->f('name');
610 $sql = "SELECT DISTINCT * FROM tc_companion_sandbox WHERE individual=$individual";
611 $this->db2->query($sql,__LINE__,__FILE__);
612 if ($this->db2->next_record()) {
613 $this->t->set_var('assigned_ht','<option value="'.$individual.'">'.$name.'</option>');
614 $this->t->fp('aht_list','assigned_ht_list',True);
616 $this->t->set_var('unassigned_ht','<option value="'.$individual.'">'.$name.'</option>');
617 $this->t->fp('uht_list','unassigned_ht_list',True);
621 # get list of families who are and are not assigned home teachers
622 $sql = "SELECT * FROM tc_family_sandbox AS tf JOIN tc_individual AS ti WHERE tf.individual=ti.individual ORDER BY ti.name ASC";
623 $this->db->query($sql,__LINE__,__FILE__);
624 while ($this->db->next_record()) {
625 $individual = $this->db->f('individual');
626 $family = $this->db->f('family');
627 $name = $this->db->f('name');
628 if ($this->db->f('companionship') != 0) {
629 $this->t->set_var('assigned_family','<option value="'.$family.'">'.$name.' Family</option>');
630 $this->t->fp('af_list','assigned_family_list',True);
632 $this->t->set_var('unassigned_family','<option value="'.$family.'">'.$name.' Family</option>');
633 $this->t->fp('uf_list','unassigned_family_list',True);
637 # populate ht districts table
638 $sandbox_table_data = "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">";
640 # set up column headers
641 $sandbox_table_data .= "<tr>";
642 for ($d = 0; $d < $num_districts; $d++) {
643 $sandbox_table_data .= "<th align=\"center\" bgcolor=\"#c9c9c9\">District " . $districts[$d] . "</th>";
646 # get each companionship in each district
647 $sandbox_table_data .= "<tr>";
648 for ($d = 0; $d < $num_districts; $d++) {
649 $sandbox_table_data .= "<td valign=\"Top\">";
650 $sandbox_table_data .= "<table>";
651 $sql = "SELECT DISTINCT companionship FROM tc_companionship_sandbox WHERE district=$districts[$d] ORDER BY companionship ASC";
652 $this->db->query($sql,__LINE__,__FILE__);
653 while ($this->db->next_record()) {
654 $sandbox_table_data .= "<tr><td><table>";
655 $companionship = $this->db->f('companionship');
656 # get names of companions in this companionship
657 $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";
658 $this->db2->query($sql,__LINE__,__FILE__);
659 $companion_names = "";
660 while ($this->db2->next_record()) {
661 if ($companion_names == "") {
662 $companion_names .= $this->db2->f('name');
664 $companion_names .= " / " . $this->db2->f('name');
667 $sandbox_table_data .= "<tr><th align=\"Left\" bgcolor=\"#c9c9c9\">$companion_names</th></tr>";
668 $sandbox_table_data .= "<tr><td><table>";
670 # get families they visit
671 $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";
672 $this->db2->query($sql,__LINE__,__FILE__);
673 while ($this->db2->next_record()) {
674 $family_name = $this->db2->f('name') . " Family";
675 $family_id = $this->db2->f('tc_family');
676 $sandbox_table_data .= "<tr>";
677 $sandbox_table_data .= "<td align=\"Left\">$family_name</td>";
679 # get 12 months visit data for given family
680 for($m=12; $m >= 0; $m--) {
681 $month = $this->current_month - $m;
682 $year = $this->current_year;
683 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
684 if($month < 10) { $month = "0"."$month"; }
685 $month_start = "$year"."-"."$month"."-"."01";
686 $month_end = "$year"."-"."$month"."-"."31";
687 $month = "$month"."/"."$year";
689 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' AND companionship!=0 AND family=". $family_id;
690 $query_id = $this->db3->query($sql,__LINE__,__FILE__);
692 if($this->db3->next_record()) {
693 if($this->db3->f('visited') == 'y') {
694 $sandbox_table_data .= "<td align=\"Right\"><img src=\"images/checkmark.gif\"></td>";
695 } else if($this->db3->f('visited') == 'n') {
696 $sandbox_table_data .= "<td align=\"Right\"><img src=\"images/x.gif\"></td>";
698 $sandbox_table_data .= "<td> </td>";
701 $sandbox_table_data .= "<td> </td>";
704 $sandbox_table_data .= "</tr>";
706 $sandbox_table_data .= "</table></td></tr>";
707 $sandbox_table_data .= "</table></td></tr>";
710 $sandbox_table_data .= "</table>";
711 $sandbox_table_data .= "</td>";
713 $sandbox_table_data .= "</tr>";
715 $sandbox_table_data .= "</table>";
716 $this->t->set_var('district_table',$sandbox_table_data);
718 $this->t->pfp('out','ht_sandbox_t');
719 $this->save_sessiondata();
725 $this->t->set_file(array('ht_update_t' => 'ht_update.tpl'));
726 $this->t->set_block('ht_update_t','district_list','list');
727 $this->t->set_block('ht_update_t','save','savehandle');
729 $district = get_var('district',array('GET','POST'));
730 $district_name = get_var('district_name',array('GET','POST'));
731 $date = get_var('date',array('GET','POST'));
732 $month = get_var('month',array('GET','POST'));
733 $month_start = get_var('month_start',array('GET','POST'));
734 $month_end = get_var('month_end',array('GET','POST'));
735 $action = get_var('action',array('GET','POST'));
737 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_view'));
738 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ht_update&action=save'));
739 $this->t->set_var('lang_done','Cancel');
740 $this->t->set_var('district_name',$district_name);
741 $this->t->set_var('district_number',$district);
742 $this->t->set_var('title','Hometeaching Update ' . $month);
743 $this->t->set_var('date',$date);
745 if($action == 'save') {
746 // Get a list of all the companionships in this district
747 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $district;
748 $this->db->query($sql,__LINE__,__FILE__);
749 $j=0; $unique_companionships = '';
750 while ($this->db->next_record()) {
751 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
754 for ($j=0; $j < count($unique_companionships); $j++) {
755 //$comp=$unique_companionships[$j]['companionship'];
756 //print "deleting from tc_visit where companionship=$comp and date=$date and district=$district<br>";
757 // Delete all the visits that have taken place for all families for this companionsthip for this month
758 $this->db->query("DELETE from tc_visit where companionship=" . $unique_companionships[$j]['companionship'] .
759 " AND " . "date='" . $date . "'",__LINE__,__FILE__);
762 // Now, add the visits that are checked for this month
763 $new_data = get_var('family_visited',array('POST'));
764 foreach ($new_data as $family) {
765 foreach ($family as $data) {
766 //print "family_visited: $data <br>";
767 $data_array = explode("/",$data);
768 $family_id = $data_array[0];
769 $companionship = $data_array[1];
770 $date = $data_array[2];
771 $visited = $data_array[3];
772 if($visited == "") { $visited = $data_array[4]; }
773 //print "family_id: $family_id companionship: $companionship date: $date visited: $visited<br>";
774 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes,visited) " .
775 "VALUES (" . $family_id .",". $companionship .",'". $date ."','','". $visited ."')",__LINE__,__FILE__);
782 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
783 $this->db->query($sql,__LINE__,__FILE__);
785 while ($this->db->next_record()) {
786 $individual[$i] = $this->db->f('individual');
787 $indiv_name[$i] = $this->db->f('name');
788 $indiv_phone[$individual[$i]] = $this->db->f('phone');
791 array_multisort($indiv_name, $individual);
793 // Make an array mapping individuals to indiv_names
794 for($i=0; $i < count($individual); $i++) {
795 $id = $individual[$i];
796 $indivs[$id] = $indiv_name[$i];
799 // Select all the unique companionship numbers for this district
800 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $district;
801 $this->db->query($sql,__LINE__,__FILE__);
802 $j=0; $unique_companionships = '';
803 while ($this->db->next_record()) {
804 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
808 $comp_width=300; $visit_width=25; $table_width=$comp_width + $visit_width;
809 $table_data=""; $num_companionships = 0; $num_families = 0; $visits=0;
810 for ($j=0; $j < count($unique_companionships); $j++) {
811 $companion_table_entry = "";
812 // Select all the companions in each companionship
813 $sql = "SELECT * FROM tc_companionship where valid=1 and ".
814 "companionship=". $unique_companionships[$j]['companionship'];
815 $this->db->query($sql,__LINE__,__FILE__);
817 while ($this->db->next_record()) {
818 // Get this companions information
819 if($companion_table_entry != "") { $companion_table_entry .= "<td> / </td>"; }
820 $companionship = $this->db->f('companionship');
821 $individual = $this->db->f('individual');
822 $name = $indivs[$individual];
823 $phone = $indiv_phone[$individual];
824 $companion_table_entry .= "<td title=\"$phone\"><b>$name</b></td>";
826 $table_data.= "<tr bgcolor=#d3dce3><td colspan=20><table><tr>$companion_table_entry</tr></table><hr></td></tr>";
828 // Get the names of the families assigned this home teaching companionship
829 $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'];
830 $sql = $sql . " ORDER BY ti.name ASC";
831 $this->db->query($sql,__LINE__,__FILE__);
832 while ($this->db->next_record()) {
833 $family_name = $this->db->f('name');
834 $family_id = $this->db->f('family');
835 $this->nextmatchs->template_alternate_row_color(&$this->t);
836 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$family_name Family</td>";
838 $header_row="<th width=$comp_width><font size=-2>Families</th>";
840 // First check to see if the currently assigned companionship has visited them
841 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
842 " AND companionship=".$unique_companionships[$j]['companionship'].
843 " AND family=". $family_id;
844 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
845 if($this->db2->num_rows($query_id) == 0) {
846 // We did not find any visits made by the currently assigned companionship,
847 // look for visits made by any other companionship other than 0. (0 == Presidency Visit)
848 $sql = "SELECT * FROM tc_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
849 " AND companionship!=0".
850 " AND family=". $family_id;
851 $query_id = $this->db2->query($sql,__LINE__,__FILE__);
854 $value = $family_id . "/" . $unique_companionships[$j]['companionship'] . "/" . $date;
855 $header_row .= "<th width=$visit_width><font size=-2><a href=$link>$month</a></th>";
856 if(!$total_visits) { $total_visits = 0; }
857 if($this->db2->next_record()) {
858 if($this->db2->f('visited') == 'y') {
859 $visits++; $total_visits++; $num_families++;
860 $table_data .= '<td width=100 align=center>';
861 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y" checked>Y';
862 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
863 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/"> ';
864 $table_data .= '</td>';
865 } else if($this->db2->f('visited') == 'n') {
867 $table_data .= '<td width=100 align=center>';
868 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
869 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n" checked>N';
870 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/">';
871 $table_data .= '</td>';
873 $table_data .= '<td width=100 align=center>';
874 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
875 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
876 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
877 $table_data .= '</td>';
882 $table_data .= '<td width=100 align=center>';
883 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/y">Y';
884 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/n">N';
885 $table_data .= '<input type="radio" name="family_visited['.$family_id.'][]" value="'.$value.'/" checked> ';
886 $table_data .= '</td>';
889 $table_data .= "</tr>";
890 $table_data .= "<tr><td colspan=20></td></tr>";
892 $table_data .= "<tr><td colspan=20><hr></td></tr>";
893 $stat_data = "<tr><td><b><font size=-2>Families Hometaught:<br>Hometeaching Percentage:</font></b></td>";
895 $percent = ceil(($visits / $num_families)*100);
896 $stat_data .= "<td align=center><font size=-2><b>$visits / $num_families<br>$percent%</font></b></td>";
897 $stat_data .= "</tr>";
899 $this->t->set_var('table_width',$table_width);
900 $this->t->set_var('header_row',$header_row);
901 $this->t->set_var('table_data',$table_data);
902 $this->t->set_var('stat_data',$stat_data);
903 $this->t->fp('list','district_list',True);
905 $this->t->set_var('lang_reset','Clear Form');
906 $this->t->set_var('lang_save','Save Changes');
907 $this->t->set_var('savehandle','');
909 $this->t->pfp('out','ht_update_t');
910 $this->t->pfp('addhandle','save');
912 $this->save_sessiondata();
917 $this->t->set_file(array('act_list_t' => 'act_list.tpl'));
918 $this->t->set_block('act_list_t','act_list','list');
920 $this->t->set_var('lang_name','Assignment');
921 $this->t->set_var('lang_date','Date');
922 $this->t->set_var('lang_notes','Description');
924 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
925 $this->db->query($sql,__LINE__,__FILE__);
926 $total_records = $this->db->num_rows();
929 while ($this->db->next_record()) {
930 $activity_list[$i]['activity'] = $this->db->f('activity');
931 $activity_list[$i]['assignment'] = $this->db->f('assignment');
932 $activity_list[$i]['date'] = $this->db->f('date');
933 $activity_list[$i]['notes'] = $this->db->f('notes');
935 $sql = "SELECT * FROM tc_assignment WHERE assignment='" . $activity_list[$i]['assignment'] . "'";
936 $this->db2->query($sql,__LINE__,__FILE__);
937 if($this->db2->next_record()) {
938 $activity_list[$i]['name'] = $this->db2->f('name');
939 $activity_list[$i]['abbreviation'] = $this->db2->f('abbreviation');
944 for ($i=0; $i < count($activity_list); $i++) {
945 $this->nextmatchs->template_alternate_row_color(&$this->t);
946 $this->t->set_var('name',$activity_list[$i]['name']);
947 $this->t->set_var('date',$activity_list[$i]['date']);
948 $activity_notes = $activity_list[$i]['notes'];
949 if(strlen($activity_notes) > 40) { $activity_notes = substr($activity_notes,0,40) . "..."; }
950 $this->t->set_var('notes',$activity_notes);
952 $link_data['menuaction'] = 'tc.tc.act_view';
953 $link_data['activity'] = $activity_list[$i]['activity'];
954 $link_data['action'] = 'view';
955 $this->t->set_var('view',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
956 $this->t->set_var('lang_view','View');
958 $link_data['menuaction'] = 'tc.tc.act_update';
959 $link_data['activity'] = $activity_list[$i]['activity'];
960 $link_data['action'] = 'edit';
961 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
962 $this->t->set_var('lang_edit','Edit');
964 $this->t->fp('list','act_list',True);
967 $link_data['menuaction'] = 'tc.tc.act_update';
968 $link_data['activity'] = '0';
969 $link_data['action'] = 'add';
970 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/tc/index.php',$link_data) .
971 '"><input type="submit" name="Add" value="' . 'Add Activity' .'"></font></form>');
973 $this->t->pfp('out','act_list_t');
974 $this->save_sessiondata();
979 $this->t->set_file(array('act_view_t' => 'act_view.tpl'));
980 $this->t->set_block('act_view_t','part_list','list');
982 $sql = "SELECT * FROM tc_activity WHERE activity=" . intval(get_var('activity',array('GET','POST')));
983 $this->db->query($sql,__LINE__,__FILE__);
984 $this->db->next_record();
985 $this->t->set_var('assignment', $this->db->f('assignment'));
986 $this->t->set_var('date', $this->db->f('date'));
987 $this->t->set_var('notes', $this->db->f('notes'));
989 $sql = "SELECT * FROM tc_assignment WHERE assignment='" . $this->db->f('assignment') . "'";
990 $this->db2->query($sql,__LINE__,__FILE__);
991 if($this->db2->next_record()) {
992 $this->t->set_var('name', $this->db2->f('name'));
993 $this->t->set_var('abbreviation', $this->db2->f('abbreviation'));
995 $this->t->set_var('lang_name','Assignment');
996 $this->t->set_var('lang_date','Date');
997 $this->t->set_var('lang_notes','Description');
998 $this->t->set_var('lang_done','Done');
999 $this->t->set_var('lang_action','View');
1001 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1002 $this->t->set_var('tr_color',$tr_color);
1004 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_list'));
1006 $link_data['menuaction'] = 'tc.tc.act_update';
1007 $link_data['activity'] = get_var('activity',array('GET','POST'));
1008 $link_data['action'] = 'edit';
1009 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
1010 $this->t->set_var('lang_edit','Edit');
1011 $this->t->set_var('cal_date',$this->db->f('date'));
1013 // Now find out which indivs participated in this activity
1014 $sql = "SELECT * FROM tc_participation WHERE activity=" . intval(get_var('activity',array('GET','POST')));
1015 $this->db->query($sql,__LINE__,__FILE__);
1016 $total_records = $this->db->num_rows();
1019 while ($this->db->next_record()) {
1020 $part_list[$i]['individual'] = $this->db->f('individual');
1024 for ($i=0; $i < count($part_list); $i++) {
1025 $sql = "SELECT * FROM tc_individual WHERE individual=" . $part_list[$i]['individual'];
1026 $this->db->query($sql,__LINE__,__FILE__);
1027 $this->db->next_record();
1028 $names[$i] = $this->db->f('name');
1032 for ($i=0; $i < count($names); $i++) {
1033 //$this->nextmatchs->template_alternate_row_color(&$this->t);
1034 $this->t->set_var('individual_name',$names[$i]);
1035 if(($i+1) % 3 == 0) {
1036 $this->t->set_var('table_sep',"</td></tr><tr>");
1038 $this->t->set_var('table_sep',"</td>");
1040 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
1041 $this->t->fp('list','part_list',True);
1044 $this->t->pfp('out','act_view_t');
1045 $this->save_sessiondata();
1048 function act_update()
1050 $this->t->set_file(array('form' => 'act_update.tpl'));
1051 $this->t->set_block('form','individual_list','list');
1052 $this->t->set_block('form','add','addhandle');
1053 $this->t->set_block('form','edit','edithandle');
1054 $this->t->set_var('lang_done','Done');
1056 $action = get_var('action',array('GET','POST'));
1057 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_list'));
1058 $activity['activity'] = intval(get_var('activity',array('GET','POST')));
1060 if($action == 'save') {
1061 $activity['assignment'] = get_var('assignment',array('POST'));
1062 $activity['date'] = get_var('date',array('POST'));
1063 $activity['notes']= get_var('notes',array('POST'));
1064 $this->db->query("UPDATE tc_activity set " .
1065 " assignment='" . $activity['assignment'] .
1066 "', date='" . $activity['date'] . "'" .
1067 ", notes=\"" . $activity['notes'] . "\"" .
1068 " WHERE activity=" . $activity['activity'],__LINE__,__FILE__);
1070 // Delete all the individuals who have particiapted in this activity
1071 $this->db->query("DELETE from tc_participation where activity=".$activity['activity'],__LINE__,__FILE__);
1073 // Re-add the individuals who are checked as having participated in this activity
1074 $indivs = get_var('individual_name',array('POST'));
1075 if(is_array($indivs)) { // Only do the foreach loop if we have a valid array of indivs to work with
1076 foreach ($indivs as $individual) {
1077 $this->db->query("INSERT INTO tc_participation (individual,activity) " .
1078 "VALUES (" . $individual . ",". $activity['activity'] . ")",__LINE__,__FILE__);
1086 if($action == 'insert') {
1087 $activity['assignment'] = get_var('assignment',array('POST'));
1088 $activity['date'] = get_var('date',array('POST'));
1089 $activity['notes']= get_var('notes',array('POST'));
1090 $this->db->query("INSERT INTO tc_activity (assignment,date,notes) " .
1091 "VALUES ('" . $activity['assignment'] . "','" .
1092 $activity['date'] . "',\"" . $activity['notes'] . "\")",__LINE__,__FILE__);
1094 $sql = "SELECT * FROM tc_activity WHERE assignment='".$activity['assignment']."' " .
1095 " AND date='".$activity['date']."' AND notes=\"".$activity['notes']."\"";
1096 $this->db->query($sql,__LINE__,__FILE__);
1097 if($this->db->next_record()) {
1098 //print "activity: " . $this->db->f('activity') . "<br>";
1099 $activity['activity'] = $this->db->f('activity');
1102 $indivs = get_var('individual_name',array('POST'));
1103 foreach ($indivs as $individual)
1105 $this->db->query("INSERT INTO tc_participation (individual,activity) " .
1106 "VALUES (" . $individual . ",". $activity['activity'] . ")",__LINE__,__FILE__);
1113 if($action == 'add') {
1114 $activity['activity'] = 0;
1115 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
1116 $this->t->set_var('assignment','');
1117 $this->t->set_var('date','');
1118 $this->t->set_var('notes','');
1119 $this->t->set_var('lang_done','Cancel');
1120 $this->t->set_var('lang_action','Adding New Activity');
1121 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_update&activity=' .
1122 $activity['activity'] . '&action=' . 'insert'));
1125 if($action == 'edit') {
1126 $sql = "SELECT * FROM tc_activity WHERE activity=" . $activity['activity'];
1127 $this->db->query($sql,__LINE__,__FILE__);
1128 $this->db->next_record();
1129 $this->t->set_var('cal_date',$this->jscal->input('date',$this->db->f('date'),'','','','','',$this->cal_options));
1130 $this->t->set_var('assignment', $this->db->f('assignment'));
1131 $assignment = $this->db->f('assignment');
1132 $this->t->set_var('date', $this->db->f('date'));
1133 $this->t->set_var('notes', $this->db->f('notes'));
1134 $this->t->set_var('lang_done','Cancel');
1135 $this->t->set_var('lang_action','Editing Activity');
1136 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.act_update&activity=' .
1137 $activity['activity'] . '&action=' . 'save'));
1140 // Create the assignments drop-down list
1141 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1142 $this->db->query($sql,__LINE__,__FILE__);
1144 while ($this->db->next_record()) {
1145 $assignments[$i]['assignment'] = $this->db->f('assignment');
1146 $assignments[$i]['name'] = $this->db->f('name');
1147 $assignments[$i]['abbreviation'] = $this->db->f('abbreviation');
1151 $assignment_data.= '<select name=assignment>';
1152 $assignment_data.= '<option value=0></option>';
1153 for ($j=0; $j < count($assignments); $j++) {
1154 $id = $assignments[$j]['assignment'];
1155 $name = $assignments[$j]['name'];
1156 if($assignments[$j]['assignment'] == $assignment) {
1157 $selected[$id] = 'selected="selected"';
1159 $selected[$id] = '';
1161 $assignment_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1163 $assignment_data.='</select>';
1164 $this->t->set_var('assignment_data',$assignment_data);
1166 // Create individual selection boxes
1167 $sql = "SELECT * FROM tc_individual";
1168 $this->db->query($sql,__LINE__,__FILE__);
1170 while ($this->db->next_record()) {
1171 if($this->db->f('valid') == 1 || $action != 'add') {
1172 $indiv_name[$i] = $this->db->f('name');
1173 $individual[$i] = $this->db->f('individual');
1174 $indiv_valid[$i] = $this->db->f('valid');
1178 array_multisort($indiv_name, $individual, $indiv_valid);
1181 for ($i=0; $i < count($individual); $i++) {
1182 //$this->nextmatchs->template_alternate_row_color(&$this->t);
1183 $sql = "SELECT * FROM tc_participation where activity=". $activity['activity'] . " AND individual=" . $individual[$i];
1184 $this->db->query($sql,__LINE__,__FILE__);
1185 if($this->db->next_record()) {
1186 $this->t->set_var('checked','checked');
1189 $this->t->set_var('checked','');
1192 if($checked || $indiv_valid[$i] == 1) {
1193 $this->t->set_var('individual_name',$indiv_name[$i]);
1194 $this->t->set_var('individual',$individual[$i]);
1195 if(($j+1) % 3 == 0) {
1196 $this->t->set_var('table_sep',"</td></tr><tr>");
1198 $this->t->set_var('table_sep',"</td>");
1200 if(($j) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
1201 $this->t->fp('list','individual_list',True);
1206 $this->t->set_var('lang_reset','Clear Form');
1207 $this->t->set_var('lang_add','Add Activity');
1208 $this->t->set_var('lang_save','Save Changes');
1209 $this->t->set_var('edithandle','');
1210 $this->t->set_var('addhandle','');
1212 $this->t->pfp('out','form');
1213 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
1214 if($action == 'add') { $this->t->pfp('addhandle','add'); }
1216 $this->save_sessiondata();
1219 function assign_view()
1221 $this->t->set_file(array('assign_view_t' => 'assign_view.tpl'));
1222 $this->t->set_block('assign_view_t','assign_view','list');
1224 $this->t->set_var('lang_name','Assignment Name');
1225 $this->t->set_var('lang_code','Abbreviation');
1227 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1228 $this->db->query($sql,__LINE__,__FILE__);
1229 $total_records = $this->db->num_rows();
1232 while ($this->db->next_record()) {
1233 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1234 $assignment_list[$i]['name'] = $this->db->f('name');
1235 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1239 for ($i=0; $i < count($assignment_list); $i++) {
1240 $this->nextmatchs->template_alternate_row_color(&$this->t);
1241 $this->t->set_var('name',$assignment_list[$i]['name']);
1242 $this->t->set_var('abbreviation',$assignment_list[$i]['abbreviation']);
1244 $link_data['menuaction'] = 'tc.tc.assign_update';
1245 $link_data['assignment'] = $assignment_list[$i]['assignment'];
1246 $link_data['action'] = 'edit';
1247 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
1248 $this->t->set_var('lang_edit','Edit');
1250 $link_data['menuaction'] = 'tc.tc.assign_update';
1251 $link_data['assignment'] = '0';
1252 $link_data['action'] = 'add';
1253 $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/tc/index.php',$link_data) .
1254 '"><input type="submit" name="Add" value="' . 'Add Assignment' .'"></font></form>');
1256 $this->t->fp('list','assign_view',True);
1259 $this->t->pfp('out','assign_view_t');
1260 $this->save_sessiondata();
1263 function assign_update()
1265 $this->t->set_file(array('form' => 'assign_update.tpl'));
1266 $this->t->set_block('form','add','addhandle');
1267 $this->t->set_block('form','edit','edithandle');
1268 $this->t->set_var('lang_done','Done');
1270 $action = get_var('action',array('GET','POST'));
1271 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_view'));
1272 $assignment['assignment'] = intval(get_var('assignment',array('GET','POST')));
1274 if($action == 'save') {
1275 $assignment['name'] = get_var('name',array('POST'));
1276 $assignment['abbreviation'] = get_var('abbreviation',array('POST'));
1277 $this->db->query("UPDATE tc_assignment set " .
1278 " name='" . $assignment['name'] . "'" .
1279 ", abbreviation='" . $assignment['abbreviation'] . "'" .
1280 " WHERE assignment=" . $assignment['assignment'],__LINE__,__FILE__);
1282 $this->assign_view();
1286 if($action == 'insert') {
1287 $assignment['name'] = get_var('name',array('POST'));
1288 $assignment['abbreviation'] = get_var('abbreviation',array('POST'));
1289 $this->db->query("INSERT INTO tc_assignment (name,abbreviation) " .
1290 "VALUES ('" . $assignment['name'] . "','" .
1291 $assignment['abbreviation'] . "')",__LINE__,__FILE__);
1292 $this->assign_view();
1296 if($action == 'add') {
1297 $assignment['assignment'] = 0;
1298 $this->t->set_var('name','');
1299 $this->t->set_var('abbreviation','');
1300 $this->t->set_var('lang_done','Cancel');
1301 $this->t->set_var('lang_action','Adding New Assignment');
1302 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_update&assignment=' .
1303 $assignment['assignment'] . '&action=' . 'insert'));
1306 if($action == 'edit')
1308 $sql = "SELECT * FROM tc_assignment WHERE assignment=" . $assignment['assignment'];
1309 $this->db->query($sql,__LINE__,__FILE__);
1310 $this->db->next_record();
1311 $this->t->set_var('name', $this->db->f('name'));
1312 $this->t->set_var('abbreviation', $this->db->f('abbreviation'));
1313 $this->t->set_var('lang_done','Cancel');
1314 $this->t->set_var('lang_action','Editing Assignment');
1315 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.assign_update&assignment=' .
1316 $assignment['assignment'] . '&action=' . 'save'));
1319 $this->t->set_var('lang_reset','Clear Form');
1320 $this->t->set_var('lang_add','Add Assignment');
1321 $this->t->set_var('lang_save','Save Changes');
1322 $this->t->set_var('edithandle','');
1323 $this->t->set_var('addhandle','');
1325 $this->t->pfp('out','form');
1326 if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
1327 if($action == 'add') { $this->t->pfp('addhandle','add'); }
1329 $this->save_sessiondata();
1334 $this->t->set_file(array('par_view_t' => 'par_view.tpl'));
1335 $this->t->set_block('par_view_t','header_list','list1');
1336 $this->t->set_block('par_view_t','individual_list','list2');
1338 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
1339 $this->db->query($sql,__LINE__,__FILE__);
1341 while ($this->db->next_record()) {
1342 $individual_name[$i] = $this->db->f('name');
1343 $individual[$i] = $this->db->f('individual');
1346 array_multisort($individual_name, $individual);
1348 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
1349 $this->db->query($sql,__LINE__,__FILE__);
1350 $total_records = $this->db->num_rows();
1353 while ($this->db->next_record()) {
1354 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1355 $activity_list[$i]['date'] = $this->db->f('date');
1356 $activity_list[$i]['activity'] = $this->db->f('activity');
1360 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1361 $this->db->query($sql,__LINE__,__FILE__);
1363 while($this->db->next_record()) {
1364 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1365 $assignment_list[$i]['name'] = $this->db->f('name');
1366 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1370 $individual_width=300; $part_width=25; $assignment_width=50;
1371 $total_width=$individual_width+$part_width;
1372 for ($i=0; $i < count($assignment_list); $i++) {
1373 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1374 $this->t->set_var('assignment_abbreviation',$assignment_list[$i]['abbreviation']);
1375 $this->t->fp('list1','header_list',True);
1376 $total_width += $assignment_width;
1379 for ($i=0; $i < count($individual); $i++) {
1380 $participated=0; $part_table = '';
1381 $this->nextmatchs->template_alternate_row_color(&$this->t);
1382 $this->t->set_var('individual_name',$individual_name[$i]);
1383 for ($j=0; $j < count($assignment_list); $j++) {
1384 $date = "0000-00-00"; $checkmark=0; $num_matches=0;
1385 for ($k=0; $k < count($activity_list); $k++) {
1386 if($assignment_list[$j]['assignment'] == $activity_list[$k]['assignment']) {
1387 $sql = "SELECT * FROM tc_participation where " .
1388 " activity=" . $activity_list[$k]['activity'] .
1389 " AND individual=" . $individual[$i];
1390 $this->db->query($sql,__LINE__,__FILE__);
1391 while($this->db->next_record()) {
1392 if($activity_list[$k]['date'] > $date) {
1393 $date = $activity_list[$k]['date'];
1402 $part_table .= '<td align=center><img src="images/checkmark.gif">';
1403 $part_table .= '<font size=-2>'.$num_matches.'</font><br>';
1404 $part_table .= '<font size=-2>'.$date.'</font></td>';
1406 $part_table .= '<td> </td>';
1410 $part_table .= '<td align=center><img src="images/checkmark.gif">'.$participated.'</td>';
1412 $part_table .= '<td> </td>';
1414 $this->t->set_var('part_table',$part_table);
1415 $this->t->fp('list2','individual_list',True);
1417 $this->t->set_var('total_width',$total_width);
1418 $this->t->set_var('individual_width',$individual_width);
1419 $this->t->set_var('part_width',$part_width);
1420 $this->t->set_var('act_width',$act_width);
1421 $this->t->pfp('out','par_view_t');
1422 $this->save_sessiondata();
1425 function willing_view()
1427 $this->t->set_file(array('willing_view_t' => 'willing_view.tpl'));
1428 $this->t->set_block('willing_view_t','header_list','list1');
1429 $this->t->set_block('willing_view_t','individual_list','list2');
1431 $this->t->set_var('lang_filter','Filter');
1432 $this->t->set_var('lang_filter_unwilling','Filter out unwilling individuals:');
1434 $filter_unwilling = get_var('filter_unwilling',array('POST'));
1435 $this->t->set_var('filter_unwilling',$filter_unwilling);
1437 if($filter_unwilling == 'y' || $filter_unwilling == '') {
1438 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\" checked>Y";
1439 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\">N";
1440 $filter_input.= " ";
1442 $filter_input = "<input type=\"radio\" name=\"filter_unwilling\" value=\"y\">Y";
1443 $filter_input.= "<input type=\"radio\" name=\"filter_unwilling\" value=\"n\" checked>N";
1444 $filter_input.= " ";
1446 $this->t->set_var('filter_input',$filter_input);
1448 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
1449 $this->db->query($sql,__LINE__,__FILE__);
1451 while ($this->db->next_record()) {
1452 $indiv_name[$i] = $this->db->f('name');
1453 $individual[$i] = $this->db->f('individual');
1454 $indiv_phone[$individual[$i]] = $this->db->f('phone');
1457 array_multisort($indiv_name, $individual);
1459 $sql = "SELECT * FROM tc_assignment ORDER BY name ASC";
1460 $this->db->query($sql,__LINE__,__FILE__);
1462 while($this->db->next_record()) {
1463 $assignment_list[$i]['assignment'] = $this->db->f('assignment');
1464 $assignment_list[$i]['name'] = $this->db->f('name');
1465 $assignment_list[$i]['abbreviation'] = $this->db->f('abbreviation');
1469 $sql = "SELECT * FROM tc_activity ORDER BY date DESC";
1470 $this->db->query($sql,__LINE__,__FILE__);
1471 $total_records = $this->db->num_rows();
1474 while ($this->db->next_record()) {
1475 $activity_list[$i]['assignment'] = $this->db->f('assignment');
1476 $activity_list[$i]['date'] = $this->db->f('date');
1477 $activity_list[$i]['activity'] = $this->db->f('activity');
1481 $indiv_width=275; $willing_width=40; $assignment_width=50;
1482 $total_width=$indiv_width+$willing_width;
1484 for ($i=0; $i < count($assignment_list); $i++) {
1485 $this->t->set_var('assignment_name',$assignment_list[$i]['name']);
1486 $this->t->set_var('assignment_abbreviation',$assignment_list[$i]['abbreviation']);
1487 $this->t->fp('list1','header_list',True);
1488 $total_width += $assignment_width;
1489 $total_willing[$i] = 0;
1492 for ($i=0; $i < count($individual); $i++) {
1493 $willing_table = ''; $indiv_willing=0;
1494 $this->t->set_var('individual_name',$indiv_name[$i]);
1495 $this->t->set_var('individual_phone',$indiv_phone[$individual[$i]]);
1496 $this->t->set_var('editurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_update&individual=' .
1497 $individual[$i] . '&action=' . 'edit'));
1498 for ($j=0; $j < count($assignment_list); $j++) {
1499 $found_willingness=0;
1500 $sql = "SELECT * FROM tc_willingness where " .
1501 " assignment=" . $assignment_list[$j]['assignment'] .
1502 " AND individual=" . $individual[$i];
1503 $this->db->query($sql,__LINE__,__FILE__);
1504 while($this->db->next_record()) {
1505 $found_willingness=1;
1507 $sql = "SELECT * FROM tc_activity where " .
1508 " assignment=". $assignment_list[$j]['assignment'] .
1509 " ORDER by date DESC";
1510 $this->db2->query($sql,__LINE__,__FILE__);
1511 if($this->db2->next_record()) {
1512 $activity = $this->db2->f('activity');
1513 $date = $this->db2->f('date');
1514 $sql = "SELECT * FROM tc_participation where " .
1515 " activity=" . $activity .
1516 " AND individual=". $individual[$i];
1517 $this->db3->query($sql,__LINE__,__FILE__);
1518 if($this->db3->next_record()) {
1523 if($this->db->f('willing') == 'y') {
1524 $total_willing[$j]++;
1526 $willing_table .= '<td align=center><img src="images/checkmark.gif"><br><font size=-2>'.$date_part.'</font></td></td>';
1527 } else if($this->db->f('willing') == 'n') {
1528 $willing_table .= '<td align=center><img src="images/x.gif"></td>';
1531 $willing_table .= "<td> </td>";
1534 if(!$found_willingness) {
1536 $willing_table .= "<td> </td>";
1539 if(($indiv_willing == 1) || ($filter_unwilling == 'n')) {
1540 $this->t->set_var('willing_table',$willing_table);
1541 $this->t->fp('list2','individual_list',True);
1542 $this->nextmatchs->template_alternate_row_color(&$this->t);
1546 $stat_table = '<td><b>Total Willing to Serve</b></td>';
1547 for ($j=0; $j < count($assignment_list); $j++) {
1548 $stat_table .= "<td align=center><b>".$total_willing[$j]."</b></td>";
1550 $this->t->set_var('stat_table',$stat_table);
1552 $this->t->set_var('total_width',$total_width);
1553 $this->t->set_var('individual_width',$indiv_width);
1554 $this->t->set_var('willing_width',$willing_width);
1555 $this->t->pfp('out','willing_view_t');
1556 $this->save_sessiondata();
1559 function willing_update()
1561 //print "<font color=red>Willingness Update Under Constrcution</font>";
1562 //$this->willing_view();
1565 $this->t->set_file(array('willing_update_t' => 'willing_update.tpl'));
1566 $this->t->set_block('willing_update_t','assignment_list','list');
1567 $this->t->set_block('willing_update_t','save','savehandle');
1569 $individual = get_var('individual',array('GET','POST'));
1570 $this->t->set_var('individual',$individual);
1571 $action = get_var('action',array('GET','POST'));
1573 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_view'));
1574 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.willing_update&action=save'));
1575 $this->t->set_var('lang_done','Cancel');
1576 $this->t->set_var('title','Willingness Update ');
1578 if($action == 'save') {
1579 // Delete all the previous willingness entries for this individual
1580 $this->db->query("DELETE from tc_willingness where individual=" . $individual ,__LINE__,__FILE__);
1582 // Now, add the assignment willingness that is checked for this individual
1583 $new_data = get_var('willingness',array('POST'));
1584 foreach ($new_data as $data) {
1585 $data_array = explode("/",$data);
1586 $assignment = $data_array[0];
1587 $willing = $data_array[1];
1588 //print "individual: $individual assignment: $assignment willing: $willing<br>";
1589 $this->db->query("INSERT INTO tc_willingness (individual,assignment,willing) " .
1590 "VALUES (" . $individual .",". $assignment .",'". $willing . "')",__LINE__,__FILE__);
1592 $this->willing_view();
1596 $assignment_width=300; $willing_width=25; $table_width=$assignment_width + $willing_width;
1599 // Find out the individual's name
1600 $sql = "SELECT * FROM tc_individual WHERE individual=".$individual." AND valid=1";
1601 $this->db->query($sql,__LINE__,__FILE__);
1602 if($this->db->next_record()) {
1603 $indiv_name = $this->db->f('name');
1604 $this->t->set_var('individual_name',$indiv_name);
1607 // Select all the assignments
1608 $sql = "SELECT * FROM tc_assignment ORDER by name ASC";
1609 $this->db->query($sql,__LINE__,__FILE__);
1611 while ($this->db->next_record()) {
1612 $assignment = $this->db->f('assignment');
1613 $assignment_name = $this->db->f('name');
1614 $assignment_abbreviation = $this->db->f('abbreviation');
1616 $this->nextmatchs->template_alternate_row_color(&$this->t);
1617 $table_data.="<tr bgcolor=". $this->t->get_var('tr_color') ."><td>$assignment_name</td>";
1619 $header_row="<th width=$comp_width><font size=-2>Assignments</th><th>Willingness</th>";
1620 $sql = "SELECT * FROM tc_willingness WHERE individual=".$individual." AND assignment=".$assignment;
1621 $this->db2->query($sql,__LINE__,__FILE__);
1622 $value = $assignment;
1624 if($this->db2->next_record()) {
1625 if($this->db2->f('willing') == 'y') {
1626 $table_data .= '<td width=100 align=center>';
1627 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y" checked>Y';
1628 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1629 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/"> ';
1630 $table_data .= '</td>';
1631 } else if($this->db2->f('willing') == 'n') {
1632 $table_data .= '<td width=100 align=center>';
1633 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1634 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n" checked>N';
1635 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/">';
1636 $table_data .= '</td>';
1638 $table_data .= '<td width=100 align=center>';
1639 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1640 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1641 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1642 $table_data .= '</td>';
1645 $table_data .= '<td width=100 align=center>';
1646 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/y">Y';
1647 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/n">N';
1648 $table_data .= '<input type="radio" name="willingness['.$assignment.']" value="'.$value.'/" checked> ';
1649 $table_data .= '</td>';
1652 $table_data .= "\n";
1653 $table_data .= "</tr>";
1654 $table_data .= "<tr><td colspan=20></td></tr>";
1657 $table_data .= "<tr><td colspan=20><hr></td></tr>";
1659 $this->t->set_var('table_width',$table_width);
1660 $this->t->set_var('header_row',$header_row);
1661 $this->t->set_var('table_data',$table_data);
1662 $this->t->fp('list','assignment_list',True);
1664 $this->t->set_var('lang_reset','Clear Form');
1665 $this->t->set_var('lang_save','Save Changes');
1666 $this->t->set_var('savehandle','');
1668 $this->t->pfp('out','willing_update_t');
1669 $this->t->pfp('addhandle','save');
1671 $this->save_sessiondata();
1675 function ppi_sched()
1677 $this->t->set_file(array('ppi_sched_t' => 'ppi_sched.tpl'));
1678 $this->t->set_block('ppi_sched_t','individual_list','indivlist');
1679 $this->t->set_block('ppi_sched_t','appt_list','apptlist');
1680 $action = get_var('action',array('GET','POST'));
1682 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1683 $this->t->set_var('lang_reset','Clear Changes');
1685 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
1686 $this->t->set_var('ppi_link_title',$this->ppi_frequency_label . ' PPIs');
1688 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
1689 $this->t->set_var('schedule_ppi_link_title','Schedule ' . $this->ppi_frequency_label . ' PPIs');
1691 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched&action=save'));
1692 $this->t->set_var('title',$this->ppi_frequency_label . ' PPI Scheduler');
1694 $indiv_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $ppi_date_width=20;
1695 $table_width=$indiv_width + $phone_width + $pri_width + $notes_width + $ppi_date_width;
1696 $header_row = "<th width=$indiv_width><font size=-2>individual Name</th>";
1697 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1698 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
1699 $header_row.= "<th width=$ppi_date_width><font size=-2>Last PPI</th>";
1700 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
1701 $table_data=""; $completed_data=""; $totals_data="";
1705 $period = intval(($month-1)/$this->ppi_frequency) + 1;
1706 $start_of_period = ($period-1)*$this->ppi_frequency + 1;
1707 $end_of_period = $period * $this->ppi_frequency;
1709 if($action == 'save') {
1710 // Save any changes made to the appointment table
1711 $new_data = get_var('appt_notes',array('POST'));
1712 if($new_data != "") {
1713 foreach ($new_data as $entry) {
1714 $indiv = $entry['individual'];
1715 $appointment = $entry['appointment'];
1716 $location = $entry['location'];
1717 $presidency_location = $entry['presidency_location'];
1718 if($location == "") { $location = $presidency_location; }
1719 if($indiv == 0) { $location = ""; }
1721 //Only perform a database update if we have made a change to this appointment
1722 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and individual='$indiv' and location='$location'";
1723 $this->db->query($sql,__LINE__,__FILE__);
1724 if(!$this->db->next_record()) {
1725 // Perform database save actions here
1726 $this->db->query("UPDATE tc_appointment set " .
1727 " individual='" . $indiv . "'" .
1728 ",location='" . $location . "'" .
1729 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
1730 // Email the appointment
1731 $this->email_appt($appointment);
1736 // Save any changes made to the ppi notes table
1737 $new_data = get_var('notes',array('POST'));
1738 foreach ($new_data as $entry) {
1739 $notes = $entry['notes'];
1740 $individual = $entry['individual'];
1741 $priority = $entry['pri'];
1743 // Perform database save actions here
1744 $sql = "SELECT * FROM tc_individual WHERE individual='$individual'";
1745 $this->db->query($sql,__LINE__,__FILE__);
1746 if ($this->db->next_record()) {
1747 $scheduling_priority = $this->db->f('scheduling_priority');
1748 //$this->logToFile("ppi_sched", "UPDATE tc_scheduling_priority SET priority='$priority', notes=\"$notes\" WHERE scheduling_priority='$scheduling_priority'");
1749 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$priority', notes=\"$notes\" WHERE scheduling_priority='$scheduling_priority'", __LINE__, __FILE__);
1753 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched');
1754 //Header('Location: ' . $take_me_to_url);
1757 // create the individual id -> individual name mapping
1758 $sql = "SELECT * FROM tc_individual where valid=1 and steward='$this->default_stewardship' ORDER BY name ASC";
1759 $this->db->query($sql,__LINE__,__FILE__);
1763 while ($this->db->next_record()) {
1764 $indiv_name[$i] = $this->db->f('name');
1765 $individual[$i] = $this->db->f('individual');
1768 array_multisort($indiv_name, $individual);
1770 // APPOINTMENT TABLE
1771 $date_width=250; $time_width=100; $indiv_width=200; $location_width=100;
1772 $appt_table_width=$date_width + $time_width + $indiv_width + $location_width;
1773 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
1774 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
1775 $appt_header_row.= "<th width=$indiv_width><font size=-2>Individual</th>";
1776 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
1777 $appt_table_data = "";
1780 $total_indivs=0; $indivs_with_yearly_ppi=0;
1782 // Get the President
1783 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti where tp.individual=ti.individual AND tp.valid=1 AND ";
1784 if($this->yearly_ppi_interviewer == 1) { $sql .= " (tp.president=1)"; }
1785 if($this->yearly_ppi_interviewer == 2) { $sql .= " (tp.president=1 OR tp.counselor=1)"; }
1786 if($this->yearly_ppi_interviewer == 3) { $sql .= " (tp.president=1 OR tp.counselor=1 OR tp.secretary=1)"; }
1787 $this->db->query($sql,__LINE__,__FILE__);
1788 while ($this->db->next_record()) {
1789 $presidency_name = $this->db->f('name');
1790 $presidency_name_array = explode(",",$presidency_name);
1791 $presidency_last_name = $presidency_name_array[0];
1792 $presidency_id = $this->db->f('presidency');
1793 $presidency_address = $this->db->f('address');
1794 $presidency_location = "$presidency_last_name"." home ($presidency_address)";
1795 $appt_table_data = "";
1797 // Display a scheduling table for this presidency member
1798 $district_number = '*';
1799 $district_name = $presidency_name;
1800 $not_completed_table_title = "District ".$district_number.": ".$district_name.": All indivs with " . $this->ppi_frequency_label . " PPI Not Completed";
1801 $appt_table_title = "District ".$district_number.": ".$district_name.": ".$this->ppi_frequency_label." PPI Appointment Slots";
1802 $this->t->set_var('not_completed_table_title',$not_completed_table_title);
1803 $this->t->set_var('appt_table_title',$appt_table_title);
1805 // query the database for all the appointments
1806 $sql = "SELECT * FROM tc_appointment where presidency=".$presidency_id." and date>=CURDATE() ORDER BY date ASC, time ASC";
1807 $this->db2->query($sql,__LINE__,__FILE__);
1809 while ($this->db2->next_record()) {
1810 $appointment = $this->db2->f('appointment');
1811 $indiv = $this->db2->f('individual');
1812 $location = $this->db2->f('location');
1813 if(($location == "") && ($indiv > 0)) { $location = $presidency_location; }
1815 $date = $this->db2->f('date');
1816 $date_array = explode("-",$date);
1817 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
1818 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
1820 $time = $this->db2->f('time');
1821 $time_array = explode(":",$time);
1822 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
1824 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1825 $appt_table_data.= "<td align=center>$day_string</td>";
1826 $appt_table_data.= "<td align=center>$time_string</td>";
1828 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][individual]>';
1829 $appt_table_data.= '<option value=0></option>';
1830 for ($i=0; $i < count($individual); $i++) {
1831 $id = $individual[$i];
1832 $name = $indiv_name[$i];
1833 if($individual[$i] == $indiv) {
1834 $selected[$id] = 'selected="selected"';
1836 $selected[$id] = '';
1838 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
1840 $appt_table_data.='</select></td>';
1842 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
1843 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
1845 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
1847 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1848 $this->t->set_var('tr_color',$tr_color);
1850 $this->t->set_var('appt_table_data',$appt_table_data);
1851 $this->t->set_var('appt_header_row',$appt_header_row);
1852 $this->t->set_var('appt_table_width',$appt_table_width);
1853 $this->t->fp('apptlist','appt_list',True);
1856 // PPI SCHEDULING TABLE
1857 $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";
1858 $this->db->query($sql,__LINE__,__FILE__);
1862 while ($this->db->next_record()) {
1863 $individual[$i] = $this->db->f('individual');
1864 $indiv_name[$i] = $this->db->f('name');
1865 $indiv_phone[$individual[$i]] = $this->db->f('phone');
1866 $indiv_priority[$individual[$i]] = $this->db->f('priority');
1867 $indiv_notes[$individual[$i]] = $this->db->f('notes');
1872 $max = count($individual);
1874 for($i=0; $i < $max; $i++) {
1875 $id = $individual[$i];
1876 $name = $indiv_name[$i];
1877 $phone = $indiv_phone[$id];
1878 $priority = $indiv_priority[$id];
1879 $notes = $indiv_notes[$id];
1881 // If this individual has had a PPI this period, don't show him on the schedule list
1882 $year_start = $year . "-" . $start_of_period . "-01";
1883 $year_end = $year . "-" . $end_of_period . "-31";
1884 $sql = "SELECT * FROM tc_interview WHERE date >= '$year_start' AND date <= '$year_end' ".
1885 "AND individual=" . $id . " AND interview_type='ppi' ORDER BY date DESC";
1886 $this->db2->query($sql,__LINE__,__FILE__);
1888 if(!$this->db2->next_record()) {
1889 $sql = "SELECT * FROM tc_interview WHERE individual=" . $id . " AND interview_type='ppi' ORDER BY date DESC";
1890 $this->db->query($sql,__LINE__,__FILE__);
1891 if($this->db->next_record()) {
1892 $date = $this->db->f('date');
1896 $link_data['menuaction'] = 'tc.tc.ppi_update';
1897 $link_data['individual'] = $id;
1898 $link_data['name'] = $name;
1899 $link_data['interview'] = '';
1900 $link_data['interview_type'] = 1;
1901 $link_data['action'] = 'add';
1902 $link_data['interviewer'] = $interviewer;
1903 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1904 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1905 $this->t->set_var('tr_color',$tr_color);
1906 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1907 $table_data.= "<td align=center>$phone</td>";
1908 //$table_data.= "<td align=center>$priority</td>";
1909 $table_data.= "<td align=center>";
1910 $table_data.= '<select name=notes['.$i.'][pri]>';
1911 foreach(range(0,6) as $num) {
1912 if($num == 0) { $num = 1; } else {$num = $num*5; }
1913 if($priority == $num) {
1914 $selected[$num] = 'selected="selected"';
1916 $selected[$num] = '';
1918 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
1920 $table_data.= '</select></td>';
1921 $table_data.= "<td align=center>$date</td>";
1922 $table_data.= '<td><input type=text size="50" maxlength="128" name="notes['.$i.'][notes]" value="'.$notes.'">';
1923 $table_data.= '<input type=hidden name="notes['.$i.'][individual]" value="'.$id.'">';
1924 $table_data.= '<input type=hidden name="notes['.$i.'][indiv_name]" value="'.$name.'">';
1925 $table_data.= '</td>';
1926 $table_data.= '</tr>';
1928 $link_data['menuaction'] = 'tc.tc.ppi_update';
1929 $link_data['interviewer'] = $this->db2->f('interviewer');
1930 $link_data['individual'] = $this->db2->f('individual');
1931 $link_data['name'] = $name;
1932 $link_data['interview'] = $this->db2->f('interview');
1933 $link_data['interview_type'] = $this->db2->f('interview_type');
1934 $link_data['action'] = 'view';
1935 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
1936 $indivs_with_yearly_ppi++;
1937 $date = $this->db2->f('date');
1938 $notes = $this->db2->f('notes');
1939 if(strlen($notes) > 40) { $notes = substr($notes,0,40) . "..."; }
1940 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
1941 $this->t->set_var('tr_color2',$tr_color2);
1942 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
1943 $completed_data.= "<td align=center>$phone</td>";
1944 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
1945 $completed_data.= "<td align=left>$notes</td>";
1946 $completed_data.= '</tr>';
1948 } // End for individuals Loop
1950 $completed_table_title = "District ".$district_number.": ".$district_name.": All indivs with " . $this->ppi_frequency_label . " PPI Completed";
1951 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
1952 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
1953 $completed_header_row = "<th width=$name_width><font size=-2>Individual</th>";
1954 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
1955 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
1956 $completed_header_row.= "<th width=$notes_width><font size=-2>PPI Notes</th>";
1958 $this->t->set_var('completed_table_title',$completed_table_title);
1959 $this->t->set_var('table_width',$table_width);
1960 $this->t->set_var('header_row',$header_row);
1961 $this->t->set_var('table_data',$table_data);
1962 $this->t->set_var('completed_header_row',$completed_header_row);
1963 $this->t->set_var('completed_table_width',$completed_table_width);
1964 $this->t->set_var('completed',$completed_data);
1965 $this->t->fp('indivlist','individual_list',True);
1967 $indivs_width=300; $totals_width=100;
1968 $totals_table_width=$indivs_width + $totals_width;
1969 $totals_header_row = "<th width=$indivs_width><font size=-2>Individuals</th>";
1970 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
1971 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1972 $totals_data.= "<td align=left><font size=-2><b>Total Individuals with " . $this->ppi_frequency_label . " PPIs completed:</b></font></td>";
1973 $totals_data.= "<td align=center><font size=-2><b>$indivs_with_yearly_ppi / $total_indivs</b></font></td>";
1974 $percent = ceil(($indivs_with_yearly_ppi / $total_indivs)*100);
1975 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
1976 $this->t->set_var('tr_color',$tr_color);
1977 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
1978 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
1979 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
1980 $totals_data.= "</tr>";
1982 $this->t->set_var('totals',$totals_data);
1983 $this->t->set_var('totals_header_row',$totals_header_row);
1984 $this->t->set_var('totals_table_width',$totals_table_width);
1986 $this->t->pfp('out','ppi_sched_t');
1987 $this->save_sessiondata();
1991 function int_sched()
1993 $this->t->set_file(array('int_sched_t' => 'int_sched.tpl'));
1994 $this->t->set_block('int_sched_t','individual_list','indivlist');
1995 $this->t->set_block('int_sched_t','appt_list','apptlist');
1996 $action = get_var('action',array('GET','POST'));
1998 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
1999 $this->t->set_var('lang_reset','Clear Changes');
2001 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2002 $this->t->set_var('int_link_title','Hometeaching Interviews');
2004 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
2005 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
2007 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched&action=save'));
2008 $this->t->set_var('title','Hometeaching Interviews Scheduler');
2010 $indiv_width=500; $phone_width=25; $pri_width=10; $notes_width=128; $int_date_width=20;
2011 $table_width=$indiv_width + $phone_width + $pri_width + $notes_width + $int_date_width;
2012 $header_row = "<th width=$indiv_width><font size=-2>Individual</th>";
2013 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2014 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
2015 $header_row.= "<th width=$int_date_width><font size=-2>Last Interview</th>";
2016 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
2017 $table_data=""; $completed_data=""; $totals_data="";
2021 $nextyear = $year + 1;
2022 if($month >= 1 && $month <= 3) { $quarter_start=$year."-01-01"; $quarter_end=$year."-04-01"; }
2023 if($month >= 4 && $month <= 6) { $quarter_start=$year."-04-01"; $quarter_end=$year."-07-01"; }
2024 if($month >= 7 && $month <= 9) { $quarter_start=$year."-07-01"; $quarter_end=$year."-10-01"; }
2025 if($month >= 10 && $month <= 12) { $quarter_start=$year."-10-01"; $quarter_end=$nextyear."-01-01"; }
2026 //print "year: $year month: $month quarter_start: $quarter_start quarter_end: $quarter_end<br>";
2028 // create the individual id -> individual name mapping
2029 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY name ASC";
2030 $this->db->query($sql,__LINE__,__FILE__);
2032 $individual_data = NULL;
2033 $indiv_name_data = NULL;
2034 while ($this->db->next_record()) {
2035 $indiv_name_data[$i] = $this->db->f('name');
2036 $individual_data[$i] = $this->db->f('individual');
2037 $individ2name[$individual_data[$i]] = $indiv_name_data[$i];
2040 // add any YM that are home teachers
2041 $sql = "SELECT * FROM tc_companionship where valid=1";
2042 $this->db->query($sql,__LINE__,__FILE__);
2043 while ($this->db->next_record()) {
2044 $tmp_individual = $this->db->f('individual');
2045 $sql = "Select * FROM tc_individual where individual='$tmp_individual' and steward='' and valid=1";
2046 $this->db2->query($sql,__LINE__,__FILE__);
2047 while ($this->db2->next_record()) {
2048 $indiv_name_data[$i] = $this->db2->f('name');
2049 $individual_data[$i] = $this->db2->f('individual');
2050 $individ2name[$individual_data[$i]] = $indiv_name_data[$i];
2054 array_multisort($indiv_name_data, $individual_data);
2056 if($action == 'save') {
2057 // Save any changes made to the appointment table
2058 $new_data = get_var('appt_notes',array('POST'));
2059 if($new_data != "") {
2060 foreach ($new_data as $entry) {
2061 $indiv = $entry['individual'];
2062 $appointment = $entry['appointment'];
2063 $location = $entry['location'];
2064 if($location == "") {
2065 $supervisor = $entry['supervisor'];
2066 $supervisor_array = explode(",", $individ2name[$supervisor]);
2067 $supervisor_last_name = $supervisor_array[0];
2068 $sql = "SELECT * FROM tc_individual where individual='$supervisor'";
2069 $this->db2->query($sql,__LINE__,__FILE__);
2070 if($this->db2->next_record()) {
2071 $supervisor_address = $this->db2->f('address');
2073 $location = "$supervisor_last_name"." home ($supervisor_address)";
2075 if($indiv == 0) { $location = ""; }
2077 //print "indiv: $indiv appointment: $appointment <br>";
2078 //Only perform a database update if we have made a change to this appointment
2079 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and individual='$indiv' and location='$location'";
2080 $this->db->query($sql,__LINE__,__FILE__);
2081 if(!$this->db->next_record()) {
2082 // Perform database save actions here
2083 $this->db->query("UPDATE tc_appointment set " .
2084 " individual='" . $indiv . "'" .
2085 ",location='" . $location . "'" .
2086 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
2087 // Email the appointment
2088 $this->email_appt($appointment);
2093 // Save any changes made to the int notes table
2094 $new_data = get_var('hti_notes',array('POST'));
2095 foreach ($new_data as $entry) {
2096 $hti_notes = $entry['notes'];
2097 $individual = $entry['individual'];
2098 $indiv_name = $entry['indiv_name'];
2099 $hti_pri = $entry['pri'];
2100 //print "hti_notes: $hti_notes indiv_name: $indiv_name <Br>";
2101 // Perform database save actions here
2102 $this->db->query("SELECT * FROM tc_companion WHERE individual=$individual and valid=1",__LINE__,__FILE__);
2103 if ($this->db->next_record()) {
2104 $scheduling_priority = $this->db->f('scheduling_priority');
2105 //$this->logToFile("int_sched", "UPDATE tc_scheduling_priority SET priority='$hti_pri', notes=\"$hti_notes\" WHERE scheduling_priority='$scheduling_priority'");
2106 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$hti_pri', notes=\"$hti_notes\" WHERE scheduling_priority='$scheduling_priority'",__LINE__,__FILE__);
2110 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched');
2111 //Header('Location: ' . $take_me_to_url);
2114 // Get the Districts
2115 $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";
2116 $this->db->query($sql,__LINE__,__FILE__);
2118 while ($this->db->next_record()) {
2119 $district = $this->db->f('district');
2120 $districts[$i]['district'] = $this->db->f('district');
2121 $districts[$i]['name'] = $this->db->f('name');
2122 $districts[$i]['supervisor'] = $this->db->f('supervisor');
2123 $districts[$i]['presidency'] = $this->db->f('presidency');
2127 // APPOINTMENT TABLE
2129 $date_width=250; $time_width=100; $indiv_width=200; $location_width=100;
2130 $appt_table_width=$date_width + $time_width + $indiv_width + $location_width;
2131 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
2132 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
2133 $appt_header_row.= "<th width=$indiv_width><font size=-2>Individual</th>";
2134 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
2135 $appt_table_data = "";
2137 $total_comps=0; $comps_with_quarterly_int=0;
2139 // Display a scheduling table for each district
2140 for ($d=0; $d < count($districts); $d++) {
2141 $table_data=""; $appt_table_data="";
2142 $this->t->set_var('district_number',$districts[$d]['district']);
2143 $this->t->set_var('district_name',$districts[$d]['name']);
2144 $supervisor = $districts[$d]['supervisor'];
2145 $supervisor_array = explode(",", $supervisor);
2146 $supervisor_last_name = $supervisor_array[0];
2147 $sql = "SELECT * FROM tc_individual where individual='$supervisor'";
2148 $this->db2->query($sql,__LINE__,__FILE__);
2149 if($this->db2->next_record()) {
2150 $supervisor_address = $this->db2->f('address');
2152 $location = "$supervisor_last_name"." home ($supervisor_address)";
2153 $table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": All Individuals with Interviews Not Completed";
2154 $appt_table_title = "District ".$districts[$d]['district'].": ".$districts[$d]['name'].": Interview Appointment Slots";
2155 $this->t->set_var('table_title',$table_title);
2156 $this->t->set_var('appt_table_title',$appt_table_title);
2158 // query the database for all the appointments
2159 $sql = "SELECT * FROM tc_appointment where presidency=".$districts[$d]['presidency']." and date>=CURDATE() ORDER BY date ASC, time ASC";
2160 $this->db->query($sql,__LINE__,__FILE__);
2162 while ($this->db->next_record()) {
2163 $appointment = $this->db->f('appointment');
2164 $indiv = $this->db->f('individual');
2165 $location = $this->db->f('location');
2166 if(($location == "") && ($indiv > 0)) { $location = "$supervisor_last_name"." home ($supervisor_address)"; }
2168 $date = $this->db->f('date');
2169 $date_array = explode("-",$date);
2170 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
2171 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
2173 $time = $this->db->f('time');
2174 $time_array = explode(":",$time);
2175 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
2177 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2178 $appt_table_data.= "<td align=center>$day_string</td>";
2179 $appt_table_data.= "<td align=center>$time_string</td>";
2181 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][individual]>';
2182 $appt_table_data.= '<option value=0></option>';
2183 for ($i=0; $i < count($individual_data); $i++) {
2184 $id = $individual_data[$i];
2185 $name = $indiv_name_data[$i];
2186 if($individual_data[$i] == $indiv) {
2187 $selected[$id] = 'selected="selected"';
2189 $selected[$id] = '';
2191 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
2193 $appt_table_data.='</select></td>';
2195 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
2196 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
2198 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
2199 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][supervisor]" value="'.$supervisor.'">';
2201 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2202 $this->t->set_var('tr_color',$tr_color);
2205 $this->t->set_var('appt_table_data',$appt_table_data);
2206 $this->t->set_var('appt_header_row',$appt_header_row);
2207 $this->t->set_var('appt_table_width',$appt_table_width);
2209 // INTERVIEW SCHEDULING TABLE
2211 // Select all the unique companionship numbers for this district
2212 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$d]['district'];
2213 $this->db->query($sql,__LINE__,__FILE__);
2214 $j=0; $unique_companionships = '';
2215 while ($this->db->next_record())
2217 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
2222 for ($j=0; $j < count($unique_companionships); $j++) {
2223 // Select all the companions from each companionship
2224 $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'];
2225 $this->db->query($sql,__LINE__,__FILE__);
2226 $k=0; $int_completed=0;
2227 $comp = $unique_companionships[$j]['companionship'];
2228 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2229 $this->t->set_var('tr_color',$tr_color);
2231 while ($this->db->next_record()) {
2232 // Get this companions information
2233 $individual = $this->db->f('individual');
2235 $id = $this->db->f('individual');
2236 $name = $this->db->f('name');
2237 $phone = $this->db->f('phone');
2238 $hti_pri = $this->db->f('priority');
2239 $hti_notes = $this->db->f('notes');
2241 // If the companionship has already had its quarterly interview,
2242 // Skip the other companion in the companionship.
2243 if($int_completed == 1) {
2244 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2245 $completed_data.= "<td align=center>$phone</td>";
2246 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2247 $completed_data.= "<td align=left>$hti_notes</td>";
2248 $completed_data.= '</tr>';
2249 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
2250 $this->t->set_var('tr_color2',$tr_color2);
2251 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2252 $this->t->set_var('tr_color',$tr_color);
2256 // If this companionship has had a hometeaching interview this quarter, don't show them on the schedule list
2257 $sql = "SELECT * FROM tc_interview WHERE date >= '$quarter_start' AND date < '$quarter_end' AND individual='$id' AND interview_type='hti'";
2258 $this->db2->query($sql,__LINE__,__FILE__);
2260 if(!$this->db2->next_record()) {
2261 $sql = "SELECT * FROM tc_interview WHERE individual='$id' AND interview_type='hti' ORDER BY date DESC";
2262 $this->db3->query($sql,__LINE__,__FILE__);
2263 if($this->db3->next_record()) {
2264 $date = $this->db3->f('date');
2268 $link_data['menuaction'] = 'tc.tc.int_update';
2269 $link_data['individual'] = $id;
2270 $link_data['name'] = $name;
2271 $link_data['interview'] = '';
2272 $link_data['action'] = 'add';
2273 $link_data['interview_type'] = 'hti';
2274 $link_data['interviewer'] = $districts[$d]['supervisor'];
2275 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2276 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2277 $table_data.= "<td align=center>$phone</td>";
2278 $table_data.= "<td align=center>";
2279 $table_data.= '<select name=hti_notes['.$i.'][pri]>';
2280 foreach(range(0,6) as $num) {
2281 if($num == 0) { $num = 1; } else {$num = $num*5; }
2282 if($hti_pri == $num) {
2283 $selected[$num] = 'selected="selected"';
2285 $selected[$num] = '';
2287 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2289 $table_data.= '</select></td>';
2290 $table_data.= "<td align=center>$date</td>";
2291 $table_data.= '<td><input type=text size="50" maxlength="128" name="hti_notes['.$i.'][notes]" value="'.$hti_notes.'">';
2292 $table_data.= '<input type=hidden name="hti_notes['.$i.'][individual]" value="'.$id.'">';
2293 $table_data.= '<input type=hidden name="hti_notes['.$i.'][indiv_name]" value="'.$name.'">';
2294 $table_data.= '</td>';
2295 $table_data.= '</tr>'."\n";
2298 $link_data['menuaction'] = 'tc.tc.int_update';
2299 $link_data['interviewer'] = $this->db2->f('interviewer');
2300 $link_data['individual'] = $this->db2->f('individual');
2301 $link_data['name'] = $name;
2302 $link_data['interview'] = $this->db2->f('interview');
2303 $link_data['interview_type'] = 'hti';
2304 $link_data['action'] = 'view';
2305 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2306 $comps_with_quarterly_int++;
2308 $date = $this->db2->f('date');
2309 $hti_notes = $this->db2->f('notes');
2310 if(strlen($hti_notes) > 40) { $hti_notes = substr($hti_notes,0,40) . "..."; }
2311 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2312 $completed_data.= "<td align=center>$phone</td>";
2313 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2314 $completed_data.= "<td align=left>$hti_notes</td>";
2315 $completed_data.= '</tr>';
2320 $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
2321 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
2322 $completed_header_row = "<th width=$name_width><font size=-2>Individual</th>";
2323 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2324 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
2325 $completed_header_row.= "<th width=$notes_width><font size=-2>Interview Notes</th>";
2327 $this->t->set_var('table_width',$table_width);
2328 $this->t->set_var('header_row',$header_row);
2329 $this->t->set_var('table_data',$table_data);
2330 $this->t->set_var('completed_header_row',$completed_header_row);
2331 $this->t->set_var('completed_table_width',$completed_table_width);
2332 $this->t->set_var('completed',$completed_data);
2333 $this->t->fp('indivlist','individual_list',True);
2335 } // End for each district loop
2338 $indivs_width=300; $totals_width=100;
2339 $totals_table_width=$indivs_width + $totals_width;
2340 $totals_header_row = "<th width=$indivs_width><font size=-2>Individuals</th>";
2341 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2342 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2343 $totals_data.= "<td align=left><font size=-2><b>Total Companionships with interviews completed:</b></font></td>";
2344 $totals_data.= "<td align=center><font size=-2><b>$comps_with_quarterly_int / $total_comps</b></font></td>";
2345 $percent = ceil(($comps_with_quarterly_int / $total_comps)*100);
2346 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2347 $this->t->set_var('tr_color',$tr_color);
2348 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2349 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2350 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2351 $totals_data.= "</tr>";
2353 $this->t->set_var('totals',$totals_data);
2354 $this->t->set_var('totals_header_row',$totals_header_row);
2355 $this->t->set_var('totals_table_width',$totals_table_width);
2357 $this->t->pfp('out','int_sched_t');
2358 $this->save_sessiondata();
2362 function vis_sched()
2364 $this->t->set_file(array('vis_sched_t' => 'vis_sched.tpl'));
2365 $this->t->set_block('vis_sched_t','family_list','familylist');
2366 $this->t->set_block('vis_sched_t','appt_list','apptlist');
2367 $action = get_var('action',array('GET','POST'));
2369 $this->t->set_var('lang_save','Save Appt / Pri / Notes');
2370 $this->t->set_var('lang_reset','Clear Changes');
2372 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
2373 $this->t->set_var('vis_link_title','View Yearly Visits');
2375 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
2376 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
2378 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched&action=save'));
2379 $this->t->set_var('title','Presidency Yearly Visit Scheduler');
2381 $family_width=500; $phone_width=40; $pri_width=10; $notes_width=128; $visit_date_width=20;
2382 $table_width=$family_width + $phone_width + $pri_width + $notes_width + $visit_date_width;
2383 $header_row = "<th width=$family_width><font size=-2>Family Name</th>";
2384 $header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2385 $header_row.= "<th width=$pri_width><font size=-2>Priority</th>";
2386 $header_row.= "<th width=$visit_date_width><font size=-2>Last Visit</th>";
2387 $header_row.= "<th width=$notes_width><font size=-2>Scheduling Notes</th>";
2388 $table_data=""; $completed_data=""; $totals_data="";
2392 // create the family id -> family name mapping
2393 $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";
2394 $this->db->query($sql,__LINE__,__FILE__);
2397 while ($this->db->next_record()) {
2398 $family_id[$i] = $this->db->f('family');
2399 $family_name[$i] = $this->db->f('name');
2400 $familyid2name[$family_id[$i]] = $family_name[$i];
2401 $familyid2address[$family_id[$i]] = $this->db->f('address');
2404 array_multisort($family_name, $family_id);
2406 if($action == 'save') {
2407 // Save any changes made to the appointment table
2408 $new_data = get_var('appt_notes',array('POST'));
2409 if($new_data != "") {
2410 foreach ($new_data as $entry) {
2411 $family = $entry['family'];
2412 $appointment = $entry['appointment'];
2413 $location = $entry['location'];
2414 if($location == "") {
2415 $family_name_array = explode(",", $familyid2name[$family]);
2416 $family_last_name = $family_name_array[0];
2417 $family_address = $familyid2address[$family];
2418 $location = "$family_last_name"." home ($family_address)";
2420 if($family == 0) { $location = ""; }
2422 //Only perform a database update if we have made a change to this appointment
2423 $sql = "SELECT * FROM tc_appointment where appointment='$appointment' and family='$family' and location='$location'";
2424 $this->db->query($sql,__LINE__,__FILE__);
2425 if(!$this->db->next_record()) {
2426 // Perform database save actions here
2427 $this->db->query("UPDATE tc_appointment set " .
2428 " family='" . $family . "'" .
2429 ",location='" . $location . "'" .
2430 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
2432 // Email the appointment
2433 $this->email_appt($appointment);
2438 // Save any changes made to the visit notes table
2439 $new_data = get_var('vis_notes',array('POST'));
2440 foreach ($new_data as $entry) {
2441 $visit_notes = $entry['notes'];
2442 $family = $entry['family_id'];
2443 $visit_pri = $entry['pri'];
2444 // Perform database save actions here
2445 $this->db->query("SELECT * FROM tc_family WHERE family='$family'",__LINE__,__FILE__);
2446 if ($this->db->next_record()) {
2447 $scheduling_priority = $this->db->f('scheduling_priority');
2448 $this->db2->query("UPDATE tc_scheduling_priority SET priority='$visit_pri', notes=\"$visit_notes\" WHERE scheduling_priority='$scheduling_priority'", __LINE__, __FILE__);
2452 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched');
2453 //Header('Location: ' . $take_me_to_url);
2456 // APPOINTMENT TABLE
2457 $date_width=250; $time_width=100; $family_width=250; $location_width=100;
2458 $appt_table_width=$date_width + $time_width + $family_width + $location_width;
2459 $appt_header_row = "<th width=$date_width><font size=-2>Date</th>";
2460 $appt_header_row.= "<th width=$time_width><font size=-2>Time</th>";
2461 $appt_header_row.= "<th width=$family_width><font size=-2>Family</th>";
2462 $appt_header_row.= "<th width=$location_width><font size=-2>Location</th>";
2463 $appt_table_data = "";
2465 // Find out what the President ID is
2466 $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";
2467 $this->db->query($sql,__LINE__,__FILE__);
2468 if($this->db->next_record()) {
2469 $presidency_name = $this->db->f('name');
2470 $presidency_id = $this->db->f('presidency');
2472 print "<hr><font color=red><h3>-E- Unable to locate Presidency in tc_presidency table</h3></font></hr>";
2476 // query the database for all the appointments
2477 $sql = "SELECT * FROM tc_appointment where presidency=$presidency_id and date>=CURDATE() ORDER BY date ASC, time ASC";
2478 $this->db->query($sql,__LINE__,__FILE__);
2480 while ($this->db->next_record()) {
2481 $appointment = $this->db->f('appointment');
2482 $family = $this->db->f('family');
2483 $location = $this->db->f('location');
2484 $family_name_array = explode(",", $familyid2name[$family]);
2485 $family_last_name = $family_name_array[0];
2486 $family_address = $familyid2address[$family];
2487 if(($location == "") && ($family > 0)) { $location = "$family_last_name"." home ($family_address)"; }
2489 $date = $this->db->f('date');
2490 $date_array = explode("-",$date);
2491 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
2492 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
2494 $time = $this->db->f('time');
2495 $time_array = explode(":",$time);
2496 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
2498 $appt_table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2499 $appt_table_data.= "<td align=center>$day_string</td>";
2500 $appt_table_data.= "<td align=center>$time_string</td>";
2502 $appt_table_data.= '<td align=center><select name=appt_notes['.$appointment.'][family]>';
2503 $appt_table_data.= '<option value=0></option>';
2504 for ($i=0; $i < count($family_id); $i++) {
2505 $id = $family_id[$i];
2506 $name = $family_name[$i];
2507 if($family_id[$i] == $family) {
2508 $selected[$id] = 'selected="selected"';
2510 $selected[$id] = '';
2512 $appt_table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
2514 $appt_table_data.='</select></td>';
2516 $appt_table_data.= '<td align=center><input type=text size="35" maxlength="120" ';
2517 $appt_table_data.= 'name="appt_notes['.$appointment.'][location]" value="'.$location.'">';
2519 $appt_table_data.= '<input type=hidden name="appt_notes['.$appointment.'][appointment]" value="'.$appointment.'">';
2521 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2522 $this->t->set_var('tr_color',$tr_color);
2525 $this->t->set_var('appt_table_data',$appt_table_data);
2526 $this->t->set_var('appt_header_row',$appt_header_row);
2527 $this->t->set_var('appt_table_width',$appt_table_width);
2530 // VISIT SCHEDULING TABLE
2531 $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";
2532 $this->db->query($sql,__LINE__,__FILE__);
2534 $total_families=0; $families_with_yearly_visit=0;
2536 while ( $this->db->next_record()) {
2538 $id = $this->db->f('family');
2539 $name = $this->db->f('name');
2540 $phone = $this->db->f('phone');
2541 $vis_pri = $this->db->f('priority');
2542 $vis_notes = $this->db->f('notes');
2544 // If this family has had a yearly visit this year, don't show them on the schedule list
2545 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2546 $sql = "SELECT * FROM tc_visit WHERE date > '$year_start' AND date < '$year_end' ".
2547 "AND family=" . $id . " AND companionship=0";
2548 $this->db2->query($sql,__LINE__,__FILE__);
2550 if(!$this->db2->next_record()) {
2551 $sql = "SELECT * FROM tc_visit WHERE family=" . $id . " AND companionship=0 ORDER BY date DESC";
2552 $this->db3->query($sql,__LINE__,__FILE__);
2553 if($this->db3->next_record()) {
2554 $date = $this->db3->f('date');
2558 $link_data['menuaction'] = 'tc.tc.vis_update';
2559 $link_data['visit'] = '';
2560 $link_data['family'] = $id;
2561 $link_data['name'] = $name;
2562 $link_data['action'] = 'add';
2563 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2564 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2565 $table_data.= "<td align=center>$phone</td>";
2566 $table_data.= "<td align=center>";
2567 $table_data.= '<select name=vis_notes['.$id.'][pri]>';
2568 foreach(range(0,6) as $num) {
2569 if($num == 0) { $num = 1; } else {$num = $num*5; }
2570 if($vis_pri == $num) {
2571 $selected[$num] = 'selected="selected"';
2573 $selected[$num] = '';
2575 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
2577 $table_data.= '</select></td>';
2578 $table_data.= "<td align=center>$date</td>";
2579 $table_data.= '<td><input type=text size="50" maxlength="128" name="vis_notes['.$id.'][notes]" value="'.$vis_notes.'">';
2580 $table_data.= '<input type=hidden name="vis_notes['.$id.'][family_id]" value="'.$id.'">';
2581 $table_data.= '<input type=hidden name="vis_notes['.$id.'][family_name]" value="'.$name.'">';
2582 $table_data.= '</td>';
2583 $table_data.= '</tr>';
2584 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2585 $this->t->set_var('tr_color',$tr_color);
2587 $link_data['menuaction'] = 'tc.tc.vis_update';
2588 $link_data['visit'] = $this->db2->f('visit');
2589 $link_data['family'] = $this->db2->f('family');
2590 $link_data['name'] = $name;
2591 $link_data['date'] = $this->db2->f('date');
2592 $link_data['action'] = 'view';
2593 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2594 $families_with_yearly_visit++;
2595 $date = $this->db2->f('date');
2596 $vis_notes = $this->db2->f('notes');
2597 if(strlen($vis_notes) > 40) { $vis_notes = stripslashes(substr($vis_notes,0,40) . "..."); }
2598 $completed_data.= "<tr bgcolor=". $this->t->get_var('tr_color2') ."><td title=\"$phone\"><a href=$link>$name Family</a></td>";
2599 $completed_data.= "<td align=center>$phone</td>";
2600 $completed_data.= "<td align=center><a href=".$link.">$date</a></td>";
2601 $completed_data.= "<td align=left>$vis_notes</td>";
2602 $completed_data.= '</tr>';
2603 $tr_color2 = $this->nextmatchs->alternate_row_color($tr_color2);
2604 $this->t->set_var('tr_color2',$tr_color2);
2608 $name_width=190; $phone_width=100; $date_width=100; $notes_width=300;
2609 $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
2610 $completed_header_row = "<th width=$name_width><font size=-2>Family Name</th>";
2611 $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";
2612 $completed_header_row.= "<th width=$date_width><font size=-2>Date</th>";
2613 $completed_header_row.= "<th width=$notes_width><font size=-2>Visit Notes</th>";
2615 $family_width=300; $totals_width=100;
2616 $totals_table_width=$family_width + $totals_width;
2617 $totals_header_row = "<th width=$family_width><font size=-2>Families</th>";
2618 $totals_header_row.= "<th width=$totals_width><font size=-2>$year</th>";
2619 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2620 $totals_data.= "<td align=left><font size=-2><b>Total Families with yearly Visits completed:</b></font></td>";
2621 $totals_data.= "<td align=center><font size=-2><b>$families_with_yearly_visit / $total_families</b></font></td>";
2622 $percent = ceil(($families_with_yearly_visit / $total_families)*100);
2623 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
2624 $this->t->set_var('tr_color',$tr_color);
2625 $totals_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
2626 $totals_data.= "<td align=left><font size=-2><b>Percentage:</b></font></td>";
2627 $totals_data.= "<td align=center><font size=-2><b>$percent%</b></font></td>";
2628 $totals_data.= "</tr>";
2630 $this->t->set_var('table_width',$table_width);
2631 $this->t->set_var('header_row',$header_row);
2632 $this->t->set_var('table_data',$table_data);
2633 $this->t->set_var('totals_header_row',$totals_header_row);
2634 $this->t->set_var('totals_table_width',$totals_table_width);
2635 $this->t->set_var('completed_header_row',$completed_header_row);
2636 $this->t->set_var('completed_table_width',$completed_table_width);
2637 $this->t->set_var('completed',$completed_data);
2638 $this->t->set_var('totals',$totals_data);
2639 $this->t->fp('familylist','family_list',True);
2640 $this->t->fp('apptlist','appt_list',True);
2642 $this->t->pfp('out','vis_sched_t');
2643 $this->save_sessiondata();
2648 $this->t->set_file(array('ppi_view_t' => 'ppi_view.tpl'));
2649 $this->t->set_block('ppi_view_t','district_list','list');
2651 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2652 $num_months = get_var('num_months',array('GET','POST'));
2653 if($num_months == '') { $num_months = $this->default_ppi_num_months; }
2654 $this->t->set_var('num_months',$num_months);
2655 if($num_months == 1) {
2656 $this->t->set_var('lang_num_months','Month of History');
2658 $this->t->set_var('lang_num_months','Months of History');
2660 $this->t->set_var('lang_filter','Filter');
2661 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2663 $this->t->set_var('ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2664 $this->t->set_var('ppi_link_title',$this->ppi_frequency_label . ' PPIs');
2666 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
2667 $this->t->set_var('schedule_ppi_link_title','Schedule ' . $this->ppi_frequency_label . ' PPIs');
2669 $this->t->set_var('title',$this->ppi_frequency_label . ' PPIs');
2670 $num_months = get_var('num_months',array('GET','POST'));
2671 if($num_months == '') { $num_months = $this->default_ppi_num_years; }
2672 $this->t->set_var('num_months',$num_months);
2673 if($num_months == 1) {
2674 $this->t->set_var('lang_num_months','Year of History');
2676 $this->t->set_var('lang_num_months','Years of History');
2679 $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";
2680 $this->db->query($sql,__LINE__,__FILE__);
2681 if($this->db->next_record()) {
2682 $president_name = $this->db->f('name');
2683 $interviewer = $this->db->f('individual');
2685 print "<hr><font color=red><h3>-E- Unable to locate President in tc_presidency table</h3></font></hr>";
2688 $this->t->set_var('district_number','*');
2689 $this->t->set_var('district_name',$president_name);
2691 $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";
2692 $this->db->query($sql,__LINE__,__FILE__);
2694 while ($this->db->next_record()) {
2695 $individual[$i] = $this->db->f('individual');
2696 $indiv_name[$i] = $this->db->f('name');
2697 $indiv_phone[$individual[$i]] = $this->db->f('phone');
2698 $indiv_priority[$individual[$i]] = $this->db->f('priority');
2699 $indiv_notes[$individual[$i]] = $this->db->f('notes');
2703 array_multisort($indiv_name, $individual);
2704 //var_dump($indiv_name); print "<br><br>"; var_dump($individual);
2706 $header_row="<th width=$comp_width><font size=-2>Individual</th>";
2708 $indiv_width=400; $ppi_width=75; $table_width=$indiv_width + $num_months*$ppi_width;
2710 for($m=$num_months; $m >= 0; $m--) {
2711 $year = date('Y') - $m;
2712 $header_row .= "<th width=150><font size=-2>$year</th>";
2716 for ($j=0; $j < count($individual); $j++) {
2717 $id = $individual[$j];
2718 $name = $indiv_name[$j];
2719 $phone = $indiv_phone[$id];
2721 $link_data['menuaction'] = 'tc.tc.ppi_update';
2722 $link_data['interviewer'] = $interviewer;
2723 $link_data['individual'] = $id;
2724 $link_data['name'] = $name;
2725 $link_data['interview'] = '';
2726 $link_data['interview_type'] = 'ppi';
2727 $link_data['action'] = 'add';
2728 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2729 $this->nextmatchs->template_alternate_row_color(&$this->t);
2730 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
2732 // Find out how many times PPIs were performed in the past $num_months for this individual
2733 for($m=$num_months; $m >= 0; $m--) {
2734 $year = date('Y') - $m;
2735 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
2736 $sql = "SELECT * FROM tc_interview WHERE date > '$year_start' AND date < '$year_end' ".
2737 "AND individual=" . $id . " AND interview_type='ppi' ORDER BY date DESC";
2738 $this->db2->query($sql,__LINE__,__FILE__);
2740 if(!$total_ppis[$m]) { $total_ppis[$m] = 0; }
2741 if($this->db2->next_record()) {
2742 $ppis[$m]++; $total_ppis[$m]++; $ppi_recorded[$companionship][$m]=1;
2743 $link_data['menuaction'] = 'tc.tc.ppi_update';
2744 $link_data['companionship'] = $companionship;
2745 $link_data['interviewer'] = $this->db2->f('interviewer');
2746 $link_data['indiv'] = $id;
2747 $link_data['name'] = $name;
2748 $link_data['interview'] = $this->db2->f('interview');
2749 $link_data['interview_type'] = 'ppi';
2750 $link_data['action'] = 'view';
2751 $date = $this->db2->f('date');
2752 $date_array = explode("-",$date);
2753 $month = $date_array[1];
2754 $day = $date_array[2];
2755 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
2756 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
2758 $table_data .= "<td> </td>";
2761 $table_data .= "</tr>\n";
2763 $table_data .= "<tr><td colspan=20><hr></td></tr>";
2765 $stat_data = "<tr><td><b><font size=-2>$total_indivs Individuals<br>PPI Totals:</font></b></td>";
2766 for($m=$num_months; $m >=0; $m--) {
2767 $percent = ceil(($ppis[$m] / $total_indivs)*100);
2768 $stat_data .= "<td align=center><font size=-2><b>$ppis[$m]<br>$percent%</font></b></td>";
2770 $stat_data .= "</tr>";
2772 $this->t->set_var('table_width',$table_width);
2773 $this->t->set_var('header_row',$header_row);
2774 $this->t->set_var('table_data',$table_data);
2775 $this->t->set_var('stat_data',$stat_data);
2776 $this->t->pfp('out','ppi_view_t');
2777 $this->save_sessiondata();
2780 function ppi_update()
2782 $this->t->set_file(array('form' => 'ppi_update.tpl'));
2783 $this->t->set_block('form','interviewer_list','int_list');
2784 $this->t->set_block('form','add','addhandle');
2785 $this->t->set_block('form','edit','edithandle');
2787 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_view'));
2788 $this->t->set_var('readonly','');
2789 $this->t->set_var('disabled','');
2791 $action = get_var('action',array('GET','POST'));
2792 $companionship = get_var('companionship',array('GET','POST'));
2793 $interviewer = get_var('interviewer',array('GET','POST'));
2794 $name = get_var('name',array('GET','POST'));
2795 $interview = get_var('interview',array('GET','POST'));
2796 $individual = get_var('individual',array('GET','POST'));
2797 $date = get_var('date',array('GET','POST'));
2798 $notes = get_var('notes',array('GET','POST'));
2799 $interview_type = get_var('interview_type',array('GET','POST'));
2801 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1 AND ";
2802 if($this->yearly_ppi_interviewer == 1) { $sql .= " (tp.president=1)"; }
2803 if($this->yearly_ppi_interviewer == 2) { $sql .= " (tp.president=1 OR tp.counselor=1)"; }
2804 if($this->yearly_ppi_interviewer == 3) { $sql .= " (tp.president=1 OR tp.counselor=1 OR tp.secretary=1)"; }
2805 $this->db2->query($sql,__LINE__,__FILE__);
2806 while ($this->db2->next_record()) {
2807 $indiv = $this->db2->f('individual');
2808 $interviewer_name = $this->db2->f('name');
2809 if($indiv == $interviewer) {
2810 $this->t->set_var('interviewer',$indiv . ' selected');
2812 $this->t->set_var('interviewer',$indiv);
2814 #print "indiv: $indiv interviewer: $interviewer<br>";
2815 $this->t->set_var('interviewer_name',$interviewer_name);
2816 $this->t->set_var('eqpresppi_checked','checked');
2817 $this->t->fp('int_list','interviewer_list',True);
2819 #print "selected interviewer: $interviewer<br>";
2820 if($action == 'save') {
2821 $notes = get_var('notes',array('POST'));
2822 $this->db->query("UPDATE tc_interview set " .
2823 " interview='" . $interview . "'" .
2824 ", interviewer='" . $interviewer . "'" .
2825 ", individual='" . $individual . "'" .
2826 ", date='" . $date . "'" .
2827 ", notes=\"" . $notes . "\"" .
2828 ", interview_type='" . $interview_type . "'" .
2829 " WHERE interview=" . $interview,__LINE__,__FILE__);
2834 if($action == 'insert') {
2835 $notes = get_var('notes',array('POST'));
2836 $this->db->query("INSERT INTO tc_interview (interviewer,individual,date,notes,interview_type) " .
2837 "VALUES ('" . $interviewer . "','" . $individual . "','" .
2838 $date . "',\"" . $notes . "\",'" . $interview_type ."')",__LINE__,__FILE__);
2843 if($action == 'add') {
2844 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
2845 $this->t->set_var('interview', '');
2846 $this->t->set_var('interviewer', $interviewer);
2847 $this->t->set_var('name',$name);
2848 $this->t->set_var('individual',$individual);
2849 $this->t->set_var('date','');
2850 $this->t->set_var('notes','');
2851 $this->t->set_var('interview_type',$interview_type);
2852 $this->t->set_var('eqpresppi_checked','checked');
2853 $this->t->set_var('lang_done','Cancel');
2854 $this->t->set_var('lang_action','Adding New PPI');
2855 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview=' .
2856 $interview . '&action=' . 'insert'));
2859 if($action == 'edit' || $action == 'view') {
2860 $sql = "SELECT * FROM tc_interview WHERE interview=" . $interview . " AND interview_type='ppi'";
2861 $this->db->query($sql,__LINE__,__FILE__);
2862 $this->db->next_record();
2863 $this->t->set_var('interview',$interview);
2864 $this->t->set_var('name',$name);
2865 $this->t->set_var('interviewer', $this->db->f('interviewer'));
2866 $this->t->set_var('individual',$this->db->f('individual'));
2867 $this->t->set_var('date',$this->db->f('date'));
2868 $this->t->set_var('notes',$this->db->f('notes'));
2869 $this->t->set_var('interview_type',$this->db->f('interview_type'));
2870 if($this->db->f('interview_type') == 'ppi') { $this->t->set_var('eqpresppi_checked','checked'); }
2873 if($action == 'edit') {
2874 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
2875 $this->t->set_var('lang_done','Cancel');
2876 $this->t->set_var('lang_action','Editing PPI');
2877 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview='.
2878 $interview . '&action=' . 'save'));
2881 if($action == 'view') {
2882 $date = $this->db->f('date');
2883 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
2884 $this->t->set_var('readonly','READONLY');
2885 $this->t->set_var('disabled','DISABLED');
2886 $this->t->set_var('lang_done','Done');
2887 $this->t->set_var('lang_action','Viewing PPI');
2888 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_update&interview=' .
2889 $interview . '&action=' . 'edit'));
2892 $this->t->set_var('lang_reset','Clear Form');
2893 $this->t->set_var('lang_add','Add PPI');
2894 $this->t->set_var('lang_save','Save Changes');
2895 $this->t->set_var('edithandle','');
2896 $this->t->set_var('addhandle','');
2898 $this->t->pfp('out','form');
2900 if($action == 'view') { $this->t->set_var('lang_save','Edit PPI'); }
2901 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
2902 if($action == 'add') { $this->t->pfp('addhandle','add'); }
2904 $this->save_sessiondata();
2909 $this->t->set_file(array('int_view_t' => 'int_view.tpl'));
2910 $this->t->set_block('int_view_t','district_list','list');
2912 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2913 $num_quarters = get_var('num_quarters',array('GET','POST'));
2914 if($num_quarters == '') { $num_quarters = $this->default_int_num_quarters; }
2915 $this->t->set_var('num_quarters',$num_quarters);
2916 if($num_quarters == 1) {
2917 $this->t->set_var('lang_num_quarters','Quarter of History');
2919 $this->t->set_var('lang_num_quarters','Quarters of History');
2921 $this->t->set_var('lang_filter','Filter');
2923 $this->t->set_var('int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
2924 $this->t->set_var('int_link_title','Hometeaching Interviews');
2926 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
2927 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
2929 $this->t->set_var('title','Hometeaching Interviews');
2931 $num_months = $num_quarters * 3 - 1;
2932 $current_month = $this->current_month;
2933 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
2934 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
2935 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
2936 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
2938 $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";
2939 $this->db->query($sql,__LINE__,__FILE__);
2941 while ($this->db->next_record()) {
2942 $districts[$i]['district'] = $this->db->f('district');
2943 $districts[$i]['name'] = $this->db->f('name');
2944 $districts[$i]['supervisor'] = $this->db->f('supervisor');
2948 $sql = "SELECT * FROM tc_individual where valid=1 ORDER BY individual ASC";
2949 $this->db->query($sql,__LINE__,__FILE__);
2951 while ($this->db->next_record()) {
2952 $individual[$i] = $this->db->f('individual');
2953 $indiv_name[$i] = $this->db->f('name');
2954 $indiv_phone[$individual[$i]] = $this->db->f('phone');
2957 array_multisort($indiv_name, $individual);
2958 for($i=0; $i < count($individual); $i++) {
2959 $id = $individual[$i];
2960 $indivs[$id] = $indiv_name[$i];
2963 $total_companionships = 0;
2964 $this->nextmatchs->template_alternate_row_color(&$this->t);
2965 for ($i=0; $i < count($districts); $i++) {
2966 $this->t->set_var('district_number',$districts[$i]['district']);
2967 $this->t->set_var('district_name',$districts[$i]['name']);
2968 $supervisor = $districts[$i]['supervisor'];
2970 // Select all the unique companionship numbers for this district
2971 $sql = "SELECT distinct companionship FROM tc_companionship where valid=1 and district=". $districts[$i]['district'];
2972 $this->db->query($sql,__LINE__,__FILE__);
2973 $j=0; $unique_companionships = '';
2974 while ($this->db->next_record()) {
2975 $unique_companionships[$j]['companionship'] = $this->db->f('companionship');
2979 $comp_width=250; $int_width=75; $table_width=$comp_width + $num_months*$int_width;
2980 $table_data=""; $num_companionships = $j; $num_indivs = 0;
2981 for($m=$num_months; $m >= 0; $m--) { $ints[$m] = 0; }
2982 for ($j=0; $j < count($unique_companionships); $j++) {
2983 // Select all the companions in each companionship
2984 $sql = "SELECT * FROM tc_companion where valid=1 and ".
2985 "companionship=". $unique_companionships[$j]['companionship'];
2986 $this->db->query($sql,__LINE__,__FILE__);
2988 $comp = $unique_companionships[$j]['companionship'];
2989 for($m=$num_months; $m >= 0; $m--) { $int_recorded[$comp][$m] = 0; }
2990 while ($this->db->next_record()) {
2991 // Get this companions information
2993 $companionship = $this->db->f('companionship');
2994 $individual = $this->db->f('individual');
2995 $name = $indivs[$individual];
2996 $phone = $indiv_phone[$individual];
2997 $link_data['menuaction'] = 'tc.tc.int_update';
2998 $link_data['companionship'] = $companionship;
2999 $link_data['interviewer'] = $supervisor;
3000 $link_data['individual'] = $individual;
3001 $link_data['name'] = $name;
3002 $link_data['interview'] = '';
3003 $link_data['interview_type'] = 'hti';
3004 $link_data['action'] = 'add';
3005 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
3006 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
3008 // Find out how many times Interviews were performed in the past $num_months for this individual
3009 $header_row="<th width=$comp_width><font size=-2>Companionship</th>";
3010 for($m=$num_months; $m >= 0; $m--) {
3011 $month = $current_month - $m;
3012 $year = $this->current_year;
3014 $remainder = $month;
3015 $month = 12 + $remainder;
3018 if($month < 10) { $month = "0"."$month"; }
3019 $month_start = "$year"."-"."$month"."-"."01";
3020 $month_end = "$year"."-"."$month"."-"."31";
3021 $month = "$month"."/"."$year";
3022 $sql = "SELECT * FROM tc_interview WHERE date >= '$month_start' AND date <= '$month_end' ".
3023 "AND individual=" . $individual . " AND interview_type='hti' ORDER BY date DESC";
3024 $this->db2->query($sql,__LINE__,__FILE__);
3025 $header_row .= "<th width=$int_width><font size=-2>$month</th>";
3027 if(!$total_ints[$m]) { $total_ints[$m] = 0; }
3028 if($this->db2->next_record()) {
3029 if(!$int_recorded[$companionship][$m]) {
3032 $int_recorded[$companionship][$m]=1;
3034 $link_data['menuaction'] = 'tc.tc.int_update';
3035 $link_data['companionship'] = $companionship;
3036 $link_data['interviewer'] = $this->db2->f('interviewer');
3037 $link_data['individual'] = $individual;
3038 $link_data['name'] = $name;
3039 $link_data['interview'] = $this->db2->f('interview');
3040 $link_data['action'] = 'view';
3041 $link_data['interview_type'] = 'hti';
3042 $date = $this->db2->f('date');
3043 $date_array = explode("-",$date);
3044 $month = $date_array[1];
3045 $day = $date_array[2];
3046 $link = $GLOBALS['phpgw']->link('/tc/index.php',$link_data);
3047 $table_data .= '<td align=center><a href='.$link.'><img src="images/checkmark.gif"> '.$month.'-'.$day.'</a></td>';
3050 $table_data .= "<td> </td>";
3053 $table_data .= "</tr>";
3056 $table_data .= "<tr><td colspan=20><hr></td></tr>";
3058 $total_companionships += $num_companionships;
3059 $stat_data = "<tr><td><b><font size=-2>$num_companionships Companionships<br>Interview Totals:</font></b></td>";
3061 // Print the hometeaching interview stats
3062 for($m=$num_months; $m >=0; $m--) {
3063 $month = $current_month - $m;
3064 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
3065 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
3066 //print "$month % $this->monthly_hometeaching_interview_stats = $month_begins <br>";
3067 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
3068 if(($month_begins) == 1) {
3071 $total += $ints[$m];
3073 $percent = ceil(($total / $num_companionships)*100);
3074 $stat_data .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
3076 $stat_data .= "</tr>";
3078 $this->t->set_var('table_width',$table_width);
3079 $this->t->set_var('header_row',$header_row);
3080 $this->t->set_var('table_data',$table_data);
3081 $this->t->set_var('stat_data',$stat_data);
3082 $this->t->fp('list','district_list',True);
3085 // Display the totals
3087 $totals = "<tr><td><b><font size=-2>$total_companionships Total Comps<br>Interview Totals:</font></b></td>";
3088 for($m=$num_months; $m >=0; $m--) {
3089 $month = $current_month - $m;
3090 if($month < 0) { $month = 12 + $month; } // Handle going backwards over a year boundary
3091 $month_begins = $month % $this->monthly_hometeaching_interview_stats;
3092 if($this->monthly_hometeaching_interview_stats == 1) { $month_begins = 1; }
3093 if(($month_begins) == 1) {
3094 $total = $total_ints[$m];
3096 $total += $total_ints[$m];
3098 $percent = ceil(($total / $total_companionships)*100);
3099 $totals .= "<td align=center><font size=-2><b>$total<br>$percent%</font></b></td>";
3103 $this->t->set_var('totals',$totals);
3104 $this->t->pfp('out','int_view_t');
3105 $this->save_sessiondata();
3108 function int_update()
3110 $this->t->set_file(array('form' => 'int_update.tpl'));
3111 $this->t->set_block('form','interviewer_list','int_list');
3112 $this->t->set_block('form','add','addhandle');
3113 $this->t->set_block('form','edit','edithandle');
3115 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_view'));
3116 $this->t->set_var('readonly','');
3117 $this->t->set_var('disabled','');
3118 $this->t->set_var('eqpresppi','');
3120 $action = get_var('action',array('GET','POST'));
3121 $companionship = get_var('companionship',array('GET','POST'));
3122 $interviewer = get_var('interviewer',array('GET','POST'));
3123 $name = get_var('name',array('GET','POST'));
3124 $interview = get_var('interview',array('GET','POST'));
3125 $individual = get_var('individual',array('GET','POST'));
3126 $date = get_var('date',array('GET','POST'));
3127 $notes = get_var('notes',array('GET','POST'));
3128 $interview_type = get_var('interview_type',array('GET','POST'));
3130 $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)";
3131 $this->db2->query($sql,__LINE__,__FILE__);
3132 while ($this->db2->next_record()) {
3133 $indiv = $this->db2->f('individual');
3134 $interviewer_name = $this->db2->f('name');
3135 if($indiv == $interviewer) {
3136 $this->t->set_var('interviewer',$indiv . ' selected');
3138 $this->t->set_var('interviewer',$indiv);
3140 $this->t->set_var('interviewer_name',$interviewer_name);
3141 $this->t->fp('int_list','interviewer_list',True);
3144 if($action == 'save') {
3145 $notes = get_var('notes',array('POST'));
3146 $this->db->query("UPDATE tc_interview set " .
3147 " interview='" . $interview . "'" .
3148 ", interviewer='" . $interviewer . "'" .
3149 ", individual='" . $individual . "'" .
3150 ", date='" . $date . "'" .
3151 ", notes=\"" . $notes . "\"" .
3152 ", interview_type='" . $interview_type . "'" .
3153 " WHERE interview=" . $interview,__LINE__,__FILE__);
3158 if($action == 'insert') {
3159 $notes = get_var('notes',array('POST'));
3160 $this->db->query("INSERT INTO tc_interview (interviewer,individual,date,notes,interview_type) " .
3161 "VALUES ('" . $interviewer . "','" . $individual . "','" .
3162 $date . "',\"" . $notes ."\",'" . $interview_type . "')",__LINE__,__FILE__);
3167 if($action == 'add') {
3168 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
3169 $this->t->set_var('interview', '');
3170 $this->t->set_var('interviewer', $interviewer);
3171 $this->t->set_var('name',$name);
3172 $this->t->set_var('individual',$individual);
3173 $this->t->set_var('date','');
3174 $this->t->set_var('notes','');
3175 $this->t->set_var('interview_type',$interview_type);
3176 $this->t->set_var('lang_done','Cancel');
3177 $this->t->set_var('lang_action','Adding New Interview');
3178 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
3179 $interview . '&action=' . 'insert'));
3182 if($action == 'edit' || $action == 'view') {
3183 $sql = "SELECT * FROM tc_interview WHERE interview=" . $interview . " AND interview_type='hti'";
3184 $this->db->query($sql,__LINE__,__FILE__);
3185 $this->db->next_record();
3186 $this->t->set_var('interview',$interview);
3187 $this->t->set_var('name',$name);
3188 $this->t->set_var('interviewer', $this->db->f('interviewer'));
3189 $this->t->set_var('individual',$this->db->f('individual'));
3190 $this->t->set_var('date',$this->db->f('date'));
3191 $this->t->set_var('notes',$this->db->f('notes'));
3192 $this->t->set_var('interview_type',$this->db->f('interview_type'));
3193 if($this->db->f('interview_type') == 'ppi') { $this->t->set_var('eqpresppi_checked','checked'); }
3196 if($action == 'edit') {
3197 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
3198 $this->t->set_var('lang_done','Cancel');
3199 $this->t->set_var('lang_action','Editing Interview');
3200 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
3201 $interview . '&action=' . 'save'));
3204 if($action == 'view') {
3205 $date = $this->db->f('date');
3206 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
3207 $this->t->set_var('readonly','READONLY');
3208 $this->t->set_var('disabled','DISABLED');
3209 $this->t->set_var('lang_done','Done');
3210 $this->t->set_var('lang_action','Viewing Interview');
3211 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_update&interview=' .
3212 $interview . '&action=' . 'edit'));
3215 $this->t->set_var('lang_reset','Clear Form');
3216 $this->t->set_var('lang_add','Add Interview');
3217 $this->t->set_var('lang_save','Save Changes');
3218 $this->t->set_var('edithandle','');
3219 $this->t->set_var('addhandle','');
3221 $this->t->pfp('out','form');
3223 if($action == 'view') { $this->t->set_var('lang_save','Edit Interview'); }
3224 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
3225 if($action == 'add') { $this->t->pfp('addhandle','add'); }
3227 $this->save_sessiondata();
3232 $this->t->set_file(array('vis_view_t' => 'vis_view.tpl'));
3233 $this->t->set_block('vis_view_t','visit_list','list1');
3234 $this->t->set_block('vis_view_t','family_list','list2');
3236 $this->t->set_var('lang_name','Family Name');
3237 $this->t->set_var('lang_date','Date');
3239 $this->t->set_var('vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
3240 $this->t->set_var('vis_link_title','View Yearly Visits');
3242 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
3243 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
3245 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
3246 $num_years = get_var('num_years',array('GET','POST'));
3247 if($num_years == '') { $num_years = $this->default_vis_num_years; }
3248 $this->t->set_var('num_years',$num_years);
3249 if($num_years == 1) {
3250 $this->t->set_var('lang_num_years','Year of History');
3252 $this->t->set_var('lang_num_years','Years of History');
3254 $this->t->set_var('lang_filter','Filter');
3256 $year = date('Y') - $num_years + 1;
3257 $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01";
3259 $sql = "SELECT * FROM tc_visit WHERE companionship=0 and date > '$year_start' ORDER BY date DESC";
3260 $this->db->query($sql,__LINE__,__FILE__);
3261 $total_records = $this->db->num_rows();
3264 while ($this->db->next_record()) {
3265 $visit_list[$i]['visit'] = $this->db->f('visit');
3266 $visit_list[$i]['family'] = $this->db->f('family');
3267 $visit_list[$i]['date'] = $this->db->f('date');
3271 for ($i=0; $i < count($visit_list); $i++) {
3272 $this->nextmatchs->template_alternate_row_color(&$this->t);
3274 $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'";
3275 $this->db->query($sql,__LINE__,__FILE__);
3276 $this->db->next_record();
3278 $this->t->set_var('family',$visit_list[$i]['family']);
3279 $this->t->set_var('family_name',$this->db->f('name'));
3280 $this->t->set_var('date',$visit_list[$i]['date']);
3282 $link_data['menuaction'] = 'tc.tc.vis_update';
3283 $link_data['visit'] = $visit_list[$i]['visit'];
3284 $link_data['name'] = $this->db->f('name');
3285 $link_data['date'] = $visit_list[$i]['date'];
3286 $link_data['action'] = 'view';
3287 $this->t->set_var('view',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3288 $this->t->set_var('lang_view','View');
3290 $link_data['menuaction'] = 'tc.tc.vis_update';
3291 $link_data['visit'] = $visit_list[$i]['visit'];
3292 $link_data['name'] = $this->db->f('name');
3293 $link_data['date'] = $visit_list[$i]['date'];
3294 $link_data['action'] = 'edit';
3295 $this->t->set_var('edit',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3296 $this->t->set_var('lang_edit','Edit');
3298 $this->t->fp('list1','visit_list',True);
3301 // List the families that are available to record a visit against
3302 $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'";
3303 $this->db->query($sql,__LINE__,__FILE__);
3304 $total_records = $this->db->num_rows();
3307 while ($this->db->next_record()) {
3308 $family_names[$i] = $this->db->f('name');
3309 $family_ids[$i] = $this->db->f('family');
3311 } array_multisort($family_names, $family_ids);
3313 for ($i=0; $i < count($family_names); $i++) {
3314 $link_data['menuaction'] = 'tc.tc.vis_update';
3315 $link_data['visit'] = '';
3316 $link_data['family'] = $family_ids[$i];
3317 $link_data['action'] = 'add';
3318 $link_data['name'] = $family_names[$i];
3319 $this->t->set_var('add',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3321 $this->t->set_var('name',$family_names[$i]);
3322 if(($i+1) % 3 == 0) {
3323 $this->t->set_var('table_sep',"</td></tr><tr>");
3325 $this->t->set_var('table_sep',"</td>");
3327 if(($i) % 3 == 0) { $this->nextmatchs->template_alternate_row_color(&$this->t); }
3329 $this->t->fp('list2','family_list',True);
3332 $this->t->pfp('out','vis_view_t');
3333 $this->save_sessiondata();
3336 function vis_update()
3338 $this->t->set_file(array('form' => 'vis_update.tpl'));
3339 $this->t->set_block('form','add','addhandle');
3340 $this->t->set_block('form','edit','edithandle');
3342 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_view'));
3343 $this->t->set_var('readonly','');
3344 $this->t->set_var('disabled','');
3346 $action = get_var('action',array('GET','POST'));
3347 $visit = get_var('visit',array('GET','POST'));
3348 $family = get_var('family',array('GET','POST'));
3349 $name = get_var('name',array('GET','POST'));
3350 $date = get_var('date',array('GET','POST'));
3351 $notes = get_var('notes',array('GET','POST'));
3354 if($action == 'save') {
3355 $notes = get_var('notes',array('POST'));
3356 $this->db->query("UPDATE tc_visit set " .
3357 " date='" . $date . "'" .
3358 ", notes=\"" . $notes . "\"" .
3359 " WHERE visit=" . $visit,__LINE__,__FILE__);
3364 if($action == 'insert') {
3365 $notes = get_var('notes',array('POST'));
3366 $this->db->query("INSERT INTO tc_visit (family,companionship,date,notes) " .
3367 "VALUES ('" . $family . "','" . $companionship . "','" .
3368 $date . "',\"" . $notes . "\")",__LINE__,__FILE__);
3373 if($action == 'add') {
3374 $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
3375 $this->t->set_var('family', $family);
3376 $this->t->set_var('visit', '');
3377 $this->t->set_var('name', $name);
3378 $this->t->set_var('date','');
3379 $this->t->set_var('notes','');
3380 $this->t->set_var('lang_done','Cancel');
3381 $this->t->set_var('lang_action','Adding New Visit');
3382 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&family=' .
3383 $family . '&action=' . 'insert'));
3386 if($action == 'edit' || $action == 'view') {
3387 $sql = "SELECT * FROM tc_visit WHERE visit=".$visit;
3388 $this->db->query($sql,__LINE__,__FILE__);
3389 $this->db->next_record();
3390 $this->t->set_var('visit',$visit);
3391 $this->t->set_var('name',$name);
3392 $this->t->set_var('family', $family);
3393 $this->t->set_var('date',$this->db->f('date'));
3394 $this->t->set_var('notes',$this->db->f('notes'));
3397 if($action == 'edit') {
3398 $this->t->set_var('cal_date',$this->jscal->input('date',$date,'','','','','',$this->cal_options));
3399 $this->t->set_var('lang_done','Cancel');
3400 $this->t->set_var('lang_action','Editing Visit');
3401 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit=' .
3402 $visit . '&action=' . 'save'));
3405 if($action == 'view') {
3406 $date = $this->db->f('date');
3407 $this->t->set_var('cal_date','<input type=text size="10" maxlength="10" name="date" value="'.$date.'" readonly>');
3408 $this->t->set_var('readonly','READONLY');
3409 $this->t->set_var('disabled','DISABLED');
3410 $this->t->set_var('lang_done','Done');
3411 $this->t->set_var('lang_action','Viewing Visit');
3412 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_update&visit=' .
3413 $visit . '&action=' . 'edit'));
3416 $this->t->set_var('lang_reset','Clear Form');
3417 $this->t->set_var('lang_add','Add Visit');
3418 $this->t->set_var('lang_save','Save Changes');
3419 $this->t->set_var('edithandle','');
3420 $this->t->set_var('addhandle','');
3422 $this->t->pfp('out','form');
3424 if($action == 'view') { $this->t->set_var('lang_save','Edit Visit'); }
3425 if($action == 'edit' || $action == 'view') { $this->t->pfp('addhandle','edit'); }
3426 if($action == 'add') { $this->t->pfp('addhandle','add'); }
3428 $this->save_sessiondata();
3433 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3434 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3435 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3437 $this->t->set_file(array('att_view_t' => 'att_view.tpl'));
3438 $this->t->set_block('att_view_t','act_list','list');
3440 $this->t->set_block('att_view_t','month_list','list1');
3441 $this->t->set_block('att_view_t','header_list','list2');
3442 $this->t->set_block('att_view_t','individual_list','list3');
3444 $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3445 $num_quarters = get_var('num_quarters',array('GET','POST'));
3446 if($num_quarters == '') { $num_quarters = $this->default_att_num_quarters; }
3447 $this->t->set_var('num_quarters',$num_quarters);
3448 $this->t->set_var('lang_filter','Filter');
3449 if($num_quarters == 1) {
3450 $this->t->set_var('lang_num_quarters','Quarter of History');
3452 $this->t->set_var('lang_num_quarters','Quarters of History');
3455 $num_months = $num_quarters * 3;
3456 $current_month = $this->current_month;
3457 if($current_month >= 1 && $current_month <= 3) { $current_month=3; }
3458 else if($current_month >= 4 && $current_month <= 6) { $current_month=6; }
3459 else if($current_month >= 7 && $current_month <= 9) { $current_month=9; }
3460 else if($current_month >= 10 && $current_month <= 12) { $current_month=12; }
3462 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
3463 $this->db->query($sql,__LINE__,__FILE__);
3465 while ($this->db->next_record()) {
3466 $individual_name[$i] = $this->db->f('name');
3467 $individual[$i] = $this->db->f('individual');
3470 array_multisort($individual_name, $individual);
3472 // Create a list of sunday dates for a window of 3 months back and current month
3476 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, ($current_month-$num_months)+1, 1, date("y")));
3477 $last_date = explode("-",$sunday_list[0]['date']);
3478 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3479 $time_limit = mktime(0, 0, 0, $current_month, 31, date("y"));
3480 while($last_time < $time_limit) {
3481 $day = date("w",$last_time);
3482 if(date("w",$last_time) == 0) {
3483 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3484 $last_date = explode("-",$sunday_list[$i]['date']);
3485 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3486 $sunday_list[$i]['day'] = $last_date[2];
3487 $sunday_list[$i]['month'] = date("M",$last_time);
3488 $sunday_list[$i]['year'] = $last_date[0];
3490 $last_date = $sunday_list[$i]['date'];
3492 $last_time += 90000;
3493 if($found_sunday) { $i++; $found_sunday=0; }
3496 $total_individuals = count($individual);
3497 $old_month=$sunday_list[0]['month']; $span=0;
3498 for ($i=0; $i < count($sunday_list); $i++) {
3499 $date = $sunday_list[$i]['date'];
3500 $this->t->set_var('date',$sunday_list[$i]['date']);
3501 $this->t->set_var('day',$sunday_list[$i]['day']);
3502 if(($old_month != $sunday_list[$i]['month']) || $i == count($sunday_list)-1) {
3503 if($i == count($sunday_list)-1) { $span++; }
3504 $cur_month = $sunday_list[$i]['month'];
3505 $old_month = $sunday_list[$i]['month'];
3506 $link_data['menuaction'] = 'tc.tc.att_update';
3507 $link_data['month'] = $sunday_list[$i-1]['month'];
3508 $link_data['year'] = $sunday_list[$i-1]['year'];
3509 $link_data['action'] = 'update_month';
3510 $cur_month = $sunday_list[$i-1]['month'];
3511 $cur_year = $sunday_list[$i-1]['year'];
3512 $header_row .= "<th><font size=-3>$cur_month $cur_year</font></th>";
3513 $this->t->set_var('update_month',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3514 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3515 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3516 $this->t->set_var('span',$span); $span=0;
3517 $this->t->fp('list1','month_list',True);
3521 $this->t->set_var('total_individuals',$total_individuals);
3522 $this->t->set_var('header_row',$header_row);
3524 $individual_width=200; $att_width=25; $total_width=$individual_width;
3525 for ($i=0; $i < count($sunday_list); $i++) {
3526 $link_data['menuaction'] = 'tc.tc.att_update';
3527 $link_data['month'] = $sunday_list[$i]['month'];
3528 $link_data['year'] = $sunday_list[$i]['year'];
3529 $link_data['day'] = $sunday_list[$i]['day'];
3530 $link_data['date'] = $sunday_list[$i]['date'];
3531 $link_data['action'] = 'update_day';
3532 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3533 $this->t->set_var('date',$sunday_list[$i]['date']);
3534 $this->t->set_var('day',$sunday_list[$i]['day']);
3535 $this->t->set_var('month',$sunday_list[$i]['month']);
3536 $this->t->set_var('year',$sunday_list[$i]['year']);
3537 $this->t->fp('list2','header_list',True);
3538 $total_width += $att_width;
3539 $attendance[$monthnum[$sunday_list[$i]['month']]]=0;
3542 for ($i=0; $i < count($individual); $i++) {
3544 $this->nextmatchs->template_alternate_row_color(&$this->t);
3545 $this->t->set_var('individual_name',$individual_name[$i]);
3546 #print "checking for individual: " . $individual[$i] . "<br>";
3547 for ($j=0; $j < count($sunday_list); $j++) {
3548 #print "checking for date: " . $sunday_list[$j]['date'] . "<br>";
3549 #print "SELECT * FROM tc_attendance WHERE date='"
3550 # . $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i] . "<br>";
3551 $sql = "SELECT * FROM tc_attendance WHERE date='" .
3552 $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i];
3553 $this->db->query($sql,__LINE__,__FILE__);
3554 if($this->db->next_record()) {
3555 $cur_month = $sunday_list[$j]['month'];
3556 if($attended[$i][$cur_month] != 1) {
3557 $attended[$i][$cur_month]=1;
3558 $attendance[$monthnum[$cur_month]]++;
3560 $att_table .= '<td align=center><img src="images/checkmark.gif"></td>';
3562 $att_table .= '<td> </td>';
3565 $this->t->set_var('att_table',$att_table);
3566 $this->t->fp('list3','individual_list',True);
3568 $this->t->set_var('total_width',$total_width);
3569 $this->t->set_var('individual_width',$individual_width);
3570 $this->t->set_var('att_width',$att_width);
3572 # Now calculate attendance for these months
3573 $attendance_str = "";
3574 $nonattendance_str = "";
3575 $aveattendance_str = "";
3576 $avenonattendance_str = "";
3578 $ave_total_attended=0;
3580 foreach($attendance as $att => $value) {
3581 $total_attended = $attendance[$att];
3582 $ave_total_attended += $attendance[$att]; $num_months++;
3583 $percent = ceil(($total_attended / $total_individuals)*100);
3584 $attendance_str.="<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3585 $total_nonattended = $total_individuals - $total_attended;
3586 $percent = ceil(($total_nonattended / $total_individuals)*100);
3587 $nonattendance_str.="<td align=center><font size=-2><b>$total_nonattended ($percent%)</b></font></td>";
3589 $total_attended = ceil(($ave_total_attended / $num_months));
3590 $percent = ceil(($total_attended / $total_individuals)*100);
3591 $aveattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3592 $total_attended = $total_individuals - ceil(($ave_total_attended / $num_months));
3593 $percent = ceil(($total_attended / $total_individuals)*100);
3594 $avenonattendance_str .= "<td align=center><font size=-2><b>$total_attended ($percent%)</b></font></td>";
3597 $this->t->set_var('attendance',$attendance_str);
3598 $this->t->set_var('aveattendance',$aveattendance_str);
3599 $this->t->set_var('nonattendance',$nonattendance_str);
3600 $this->t->set_var('avenonattendance',$avenonattendance_str);
3602 $this->t->pfp('out','att_view_t');
3603 $this->save_sessiondata();
3606 function att_update()
3608 $monthnum['Jan']=1; $monthnum['Feb']=2; $monthnum['Mar']=3; $monthnum['Apr']=4;
3609 $monthnum['May']=5; $monthnum['Jun']=6; $monthnum['Jul']=7; $monthnum['Aug']=8;
3610 $monthnum['Sep']=9; $monthnum['Oct']=10; $monthnum['Nov']=11; $monthnum['Dec']=12;
3612 $this->t->set_file(array('form' => 'att_update.tpl'));
3613 $this->t->set_block('form','edit','edithandle');
3615 $this->t->set_block('form','month_list','list1');
3616 $this->t->set_block('form','header_list','list2');
3617 $this->t->set_block('form','individual_list','list3');
3619 $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_view'));
3621 $action = get_var('action',array('GET','POST'));
3622 $month = get_var('month',array('GET','POST'));
3623 $year = get_var('year',array('GET','POST'));
3624 $day = get_var('day',array('GET','POST'));
3625 $date = get_var('date',array('GET','POST'));
3627 if($action == 'save_month' || $action == 'save_day') {
3628 $new_data = get_var('individuals_attended',array('POST'));
3629 $month = $monthnum[$month]; if($month < 10) { $month = "0" . $month; }
3631 if($action == 'save_month') {
3632 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-%'",__LINE__,__FILE__);
3635 if($action == 'save_day') {
3636 $this->db->query("DELETE from tc_attendance where date LIKE '".$year."-".$month."-".$day."'",__LINE__,__FILE__);
3639 foreach ($new_data as $data) {
3640 $data_array = explode("-",$data);
3641 $indiv = $data_array[0];
3642 $date = "$data_array[1]-$data_array[2]-$data_array[3]";
3643 $this->db->query("INSERT INTO tc_attendance (individual,date) " .
3644 "VALUES (" . $indiv . ",'". $date . "')",__LINE__,__FILE__);
3651 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1";
3652 $this->db->query($sql,__LINE__,__FILE__);
3654 while ($this->db->next_record()) {
3655 $indiv_name[$i] = $this->db->f('name');
3656 $individual[$i] = $this->db->f('individual');
3657 $indiv_attending[$individual[$i]] = $this->db->f('attending');
3660 array_multisort($indiv_name, $individual);
3662 if($action == 'update_month') {
3663 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_month'));
3667 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], 1, $year));
3668 $last_date = explode("-",$sunday_list[0]['date']);
3669 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3670 $time_limit = mktime(0, 0, 0, $monthnum[$month], 31, $year);
3671 while($last_time <= $time_limit) {
3672 $day = date("w",$last_time);
3673 if(date("w",$last_time) == 0) {
3674 $sunday_list[$i]['date'] = date("Y-m-d", $last_time);
3675 $last_date = explode("-",$sunday_list[$i]['date']);
3676 $last_time = mktime(0, 0, 0, $last_date[1], $last_date[2], $last_date[0]);
3677 $sunday_list[$i]['day'] = $last_date[2];
3678 $sunday_list[$i]['month'] = date("M",$last_time);
3679 $sunday_list[$i]['year'] = $last_date[0];
3682 $last_time += 90000;
3683 if($found_sunday) { $i++; $found_sunday=0; }
3686 $this->t->set_var('span', $i);
3687 $this->t->set_var('month',$sunday_list[$i-1]['month']);
3688 $this->t->set_var('year',$sunday_list[$i-1]['year']);
3689 $this->t->fp('list1','month_list',True);
3690 $indiv_width=200; $att_width=25; $total_width=$indiv_width;
3691 for ($i=0; $i < count($sunday_list); $i++) {
3692 $link_data['menuaction'] = 'tc.tc.att_update';
3693 $link_data['month'] = $sunday_list[$i]['month'];
3694 $link_data['year'] = $sunday_list[$i]['year'];
3695 $link_data['day'] = $sunday_list[$i]['day'];
3696 $link_data['date'] = $sunday_list[$i]['date'];
3697 $link_data['action'] = 'update_day';
3698 $this->t->set_var('update_day',$GLOBALS['phpgw']->link('/tc/index.php',$link_data));
3699 $this->t->set_var('date',$sunday_list[$i]['date']);
3700 $this->t->set_var('day',$sunday_list[$i]['day']);
3701 $this->t->set_var('month',$sunday_list[$i]['month']);
3702 $this->t->set_var('year',$sunday_list[$i]['year']);
3703 $this->t->fp('list2','header_list',True);
3704 $total_width += $att_width;
3708 if($action == 'update_day') {
3709 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.att_update&action=save_day'));
3710 $sunday_list[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $monthnum[$month], $day, $year));
3711 $this->t->set_var('month',$month);
3712 $this->t->set_var('year',$year);
3713 $this->t->fp('list1','month_list',True);
3714 $this->t->set_var('date',$date);
3715 $this->t->set_var('day',$day);
3716 $this->t->set_var('month',$month);
3717 $this->t->set_var('year',$year);
3718 $this->t->fp('list2','header_list',True);
3721 for ($i=0; $i < count($individual); $i++) {
3723 $this->nextmatchs->template_alternate_row_color(&$this->t);
3724 $this->t->set_var('individual_name',$indiv_name[$i]);
3725 for ($j=0; $j < count($sunday_list); $j++) {
3726 $sql = "SELECT * FROM tc_attendance WHERE date='" .
3727 $sunday_list[$j]['date'] . "' AND individual=" . $individual[$i];
3728 $this->db->query($sql,__LINE__,__FILE__);
3729 $value = $individual[$i] . "-" . $sunday_list[$j]['date'];
3730 if($this->db->next_record()) {
3731 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'" checked></td>';
3732 } else if($indiv_attending[$individual[$i]] == 1) {
3733 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'" checked></td>';
3735 $att_table .= '<td align=center><input type="checkbox" name="individuals_attended[]" value="'.$value.'"></td>';
3738 $this->t->set_var('att_table',$att_table);
3739 $this->t->fp('list3','individual_list',True);
3742 $this->t->set_var('lang_done', 'Cancel');
3743 $this->t->set_var('lang_reset','Clear Form');
3744 $this->t->set_var('lang_save','Save Changes');
3746 $this->t->pfp('out','form');
3747 $this->t->pfp('addhandle','edit');
3749 $this->save_sessiondata();
3754 $this->t->set_file(array('dir_view_t' => 'dir_view.tpl'));
3755 $this->t->set_block('dir_view_t','dir_list','list');
3757 $sql = "SELECT * FROM tc_individual where valid=1 and hh_position='Head of Household' ORDER BY name ASC";
3758 $this->db->query($sql,__LINE__,__FILE__);
3760 while ($this->db->next_record()) {
3761 $parent[$i]['id'] = $this->db->f('individual');
3762 $parent[$i]['name'] = $this->db->f('name');
3763 $parent[$i]['phone'] = $this->db->f('phone');
3764 $parent[$i]['address'] = $this->db->f('address');
3768 for ($i=0; $i < count($parent); $i++) {
3769 $name = $parent[$i]['name'];
3770 $phone = $parent[$i]['phone'];
3771 $address = $parent[$i]['address'];
3772 $this->t->set_var('name', $name);
3773 $this->t->set_var('address', $address);
3774 $this->t->set_var('phone', $phone);
3775 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3776 $this->t->set_var('tr_color',$tr_color);
3777 $this->t->fp('list','dir_list',True);
3778 //print "$phone $name $address<br>";
3780 $this->t->pfp('out','dir_view_t');
3781 $this->save_sessiondata();
3786 $this->t->set_file(array('org_view_t' => 'org_view.tpl'));
3787 $this->t->set_block('org_view_t','calling_list','list1');
3788 $this->t->set_block('org_view_t','org_list','list2');
3790 # Display a list ordered alphabetically
3791 $sql = "SELECT * FROM tc_calling AS tc JOIN tc_individual AS ti WHERE tc.individual=ti.individual ORDER BY name ASC";
3792 $this->db->query($sql,__LINE__,__FILE__);
3794 while ($this->db->next_record()) {
3795 $calling[$i]['name'] = $this->db->f('name');
3796 $calling[$i]['position'] = $this->db->f('position');
3797 $calling[$i]['sustained'] = $this->db->f('sustained');
3798 $calling[$i]['organization'] = $this->db->f('organization');
3801 for ($i=0; $i < count($calling); $i++) {
3802 $name = $calling[$i]['name'];
3803 $position = $calling[$i]['position'];
3804 $sustained = $calling[$i]['sustained'];
3805 $organization = $calling[$i]['organization'];
3806 $this->t->set_var('name', $name);
3807 $this->t->set_var('position', $position);
3808 $this->t->set_var('sustained', $sustained);
3809 $this->t->set_var('organization', $organization);
3810 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3811 $this->t->set_var('tr_color',$tr_color);
3812 $this->t->fp('list1','calling_list',True);
3815 # Display a list ordered by organization
3816 $sql = "SELECT * FROM tc_calling AS tc JOIN tc_individual AS ti where tc.individual=ti.individual ORDER BY organization ASC";
3817 $this->db->query($sql,__LINE__,__FILE__);
3819 while ($this->db->next_record()) {
3820 $calling[$i]['name'] = $this->db->f('name');
3821 $calling[$i]['position'] = $this->db->f('position');
3822 $calling[$i]['sustained'] = $this->db->f('sustained');
3823 $calling[$i]['organization'] = $this->db->f('organization');
3826 for ($i=0; $i < count($calling); $i++) {
3827 $name = $calling[$i]['name'];
3828 $position = $calling[$i]['position'];
3829 $sustained = $calling[$i]['sustained'];
3830 $organization = $calling[$i]['organization'];
3831 $this->t->set_var('name', $name);
3832 $this->t->set_var('position', $position);
3833 $this->t->set_var('sustained', $sustained);
3834 $this->t->set_var('organization', $organization);
3835 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
3836 $this->t->set_var('tr_color',$tr_color);
3837 $this->t->fp('list2','org_list',True);
3840 $this->t->pfp('out','org_view_t');
3841 $this->save_sessiondata();
3846 $this->t->set_file(array('sched_t' => 'schedule.tpl'));
3847 $this->t->set_block('sched_t','presidency_list','list');
3849 $action = get_var('action',array('GET','POST'));
3851 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule&action=save'));
3852 $this->t->set_var('title','Scheduling Tool');
3854 $this->t->set_var('lang_save','Save Schedule');
3855 $this->t->set_var('lang_reset','Cancel');
3857 $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.vis_sched'));
3858 $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits');
3860 $this->t->set_var('schedule_int_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.int_sched'));
3861 $this->t->set_var('schedule_int_link_title','Schedule Hometeaching Interviews');
3863 $this->t->set_var('schedule_ppi_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.ppi_sched'));
3864 $this->t->set_var('schedule_ppi_link_title','Schedule ' . $this->ppi_frequency_label . ' PPIs');
3866 $date_width=160; $time_width=220; $indiv_width=170; $family_width=180; $location_width=100;
3867 $table_width=$date_width + $time_width + $indiv_width + $family_width + $location_width;
3868 $header_row = "<th width=$date_width><font size=-2>Date</th>";
3869 $header_row.= "<th width=$time_width><font size=-2>Time</th>";
3870 $header_row.= "<th width=$indiv_width><font size=-2>Individual</th>";
3871 $header_row.= "<th width=$family_width><font size=-2>Family</th>";
3872 $header_row.= "<th width=$location_width><font size=-2>Location</th>";
3875 $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";
3876 $this->db->query($sql,__LINE__,__FILE__);
3878 while ($this->db->next_record()) {
3879 $presidency_data[$i]['id'] = $this->db->f('presidency');
3880 $presidency_data[$i]['name'] = $this->db->f('name');
3881 $presidency_data[$i]['indiv'] = $this->db->f('individual');
3882 $presidency2name[$presidency_data[$i]['id']] = $presidency_data[$i]['name'];
3883 $presidency2indiv[$presidency_data[$i]['id']] = $presidency_data[$i]['indiv'];
3887 $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";
3888 $this->db->query($sql,__LINE__,__FILE__);
3890 while ($this->db->next_record()) {
3891 $family_id[$i] = $this->db->f('family');
3892 $family_name[$i] = $this->db->f('name');
3893 $familyid2name[$family_id[$i]] = $family_name[$i];
3894 $familyid2address[$family_id[$i]] = $this->db->f('address');
3897 array_multisort($family_name, $family_id);
3899 if($action == 'save') {
3900 $new_data = get_var('sched',array('POST'));
3901 foreach ($new_data as $presidency_array) {
3902 foreach ($presidency_array as $entry) {
3903 $presidency = $entry['presidency'];
3904 $appointment = $entry['appointment'];
3905 $location = $entry['location'];
3906 $date = $entry['date'];
3907 $hour = $entry['hour'];
3908 $minute = $entry['minute'];
3910 $indiv = $entry['individual'];
3911 $family = $entry['family'];
3912 $location = $entry['location'];
3913 if($pm) { $hour = $hour + 12; }
3914 $time = $hour.':'.$minute.':'.'00';
3917 // Zero out family or individual if they are invalid
3918 if($indiv == "") { $indiv=0; }
3919 if($family == "") { $family=0; }
3921 // Update our location
3922 if($location == "") {
3924 $family_name_array = explode(",", $familyid2name[$family]);
3925 $family_last_name = $family_name_array[0];
3926 $family_address = $familyid2address[$family];
3927 $location = "$family_last_name"." home ($family_address)";
3928 } else if($indiv > 0) {
3929 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
3930 $supervisor_last_name = $supervisor_name_array[0];
3931 #print "presidency2indiv: $presidency $presidency2indiv[$presidency]<br>";
3932 $sql = "SELECT * FROM tc_individual where individual='$presidency2indiv[$presidency]'";
3933 $this->db2->query($sql,__LINE__,__FILE__);
3934 if($this->db2->next_record()) {
3935 $supervisor_address = $this->db2->f('address');
3937 $location = "$supervisor_last_name"." home ($supervisor_address)";
3941 // Zero out the family or individual if date = NULL
3948 if(($indiv == 0) && ($family == 0)) { $location = ""; }
3950 // Update an existing appointment
3951 if($appointment < $this->max_appointments)
3953 //Only perform a database update if we have made a change to this appointment
3954 $sql = "SELECT * FROM tc_appointment where " .
3955 "appointment='$appointment'" .
3956 " and presidency='$presidency'" .
3957 " and individual='$indiv'" .
3958 " and family='$family'" .
3959 " and date='$date'" .
3960 " and time='$time'" .
3961 " and location='$location'";
3962 $this->db->query($sql,__LINE__,__FILE__);
3963 if(!$this->db->next_record()) {
3964 $old_date = $this->db->f('date');
3965 $old_time = $this->db->f('time');
3966 $this->db2->query("UPDATE tc_appointment set" .
3967 " family=" . $family .
3968 " ,individual=" . $indiv .
3969 " ,date='" . $date . "'" .
3970 " ,time='" . $time . "'" .
3971 " ,location='" . $location . "'" .
3972 " ,presidency='" . $presidency . "'" .
3973 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
3975 // Email the appointment
3976 $this->email_appt($appointment);
3980 // Add a new appointment
3981 else if(($appointment >= $this->max_appointments) && ($date != "") && ($time != ""))
3983 //print "adding entry: appt=$appointment date: $date time: $time individual: $indiv family: $family<br>";
3984 $this->db2->query("INSERT INTO tc_appointment (appointment,presidency,family,individual,date,time,location,uid) " .
3985 "VALUES (NULL,'" . $presidency . "','" . $family . "','" . $indiv . "','" .
3986 $date . "','" . $time . "','" . $location . "','" . $uid ."')",__LINE__,__FILE__);
3988 // Now reselect this entry from the database to see if we need
3989 // to send an appointment out for it.
3990 $sql = "SELECT * FROM tc_appointment where " .
3991 "individual='$indiv'" .
3992 " and family='$family'" .
3993 " and presidency='$presidency'" .
3994 " and date='$date'" .
3995 " and time='$time'" .
3997 " and location='$location'";
3998 $this->db3->query($sql,__LINE__,__FILE__);
3999 if($this->db3->next_record()) {
4000 // Email the appointment if warranted
4001 if(($date != "") && ($time != "") && (($indiv > 0) || $family > 0)) {
4002 $this->email_appt($this->db3->f('appointment'));
4009 $take_me_to_url = $GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.schedule');
4010 //Header('Location: ' . $take_me_to_url);
4013 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY individual ASC";
4014 $this->db->query($sql,__LINE__,__FILE__);
4016 while ($this->db->next_record()) {
4017 $individual[$i] = $this->db->f('individual');
4018 $indiv_name[$i] = $this->db->f('name');
4019 $indiv_phone[$individual[$i]] = $this->db->f('phone');
4022 array_multisort($indiv_name, $individual);
4024 for ($i=0; $i < count($presidency_data); $i++) {
4025 $presidency = $presidency_data[$i]['id'];
4026 $interviewer = $presidency_data[$i]['individual'];
4027 $name = $presidency_data[$i]['name'];
4028 $this->t->set_var('presidency_name',$name);
4031 // query the database for all the appointments
4032 $sql = "SELECT * FROM tc_appointment where presidency=$presidency and date>=CURDATE() ORDER BY date ASC, time ASC";
4033 $this->db->query($sql,__LINE__,__FILE__);
4035 // Prefill any existing appointment slots
4036 while ($this->db->next_record()) {
4037 $appointment = $this->db->f('appointment');
4038 $indiv = $this->db->f('individual');
4039 $family = $this->db->f('family');
4040 $location = $this->db->f('location');
4042 if($location == "") {
4044 $family_name_array = explode(",", $familyid2name[$family]);
4045 $family_last_name = $family_name_array[0];
4046 $family_address = $familyid2address[$family];
4047 $location = "$family_last_name"." home ($family_address)";
4048 } else if($indiv > 0) {
4049 $supervisor_name_array = explode(",",$presidency2name[$presidency]);
4050 $supervisor_last_name = $supervisor_name_array[0];
4051 $sql = "SELECT * FROM tc_individual where individual='$presidency2indiv[$presidency]'";
4052 $this->db2->query($sql,__LINE__,__FILE__);
4053 if($this->db2->next_record()) {
4054 $supervisor_address = $this->db2->f('address');
4056 $location = "$supervisor_last_name"." home ($supervisor_address)";
4060 $date = $this->db->f('date');
4061 $date_array = explode("-",$date);
4062 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
4063 $day_string = date("l d-M-Y", mktime(0,0,0,$month,$day,$year));
4065 $time = $this->db->f('time');
4066 $time_array = explode(":",$time);
4067 $hour = $time_array[0];
4068 $minute = $time_array[1];
4070 if($hour > 12) { $pm=1; $hour = $hour - 12; }
4071 $time_string = date("g:i a", mktime($time_array[0], $time_array[1], $time_array[2]));
4073 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4076 $table_data.= '<td align=left>';
4077 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]',$date,'','','','','',$this->cal_options);
4078 $table_data.= '</td>';
4080 // Hour & Minutes selection
4081 $table_data.= "<td align=center>";
4082 $table_data .= $this->get_time_selection_form($hour, $minute, $pm, $presidency, $appointment);
4083 $table_data.= "</td>";
4085 // individual drop down list (for PPIs)
4086 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][individual] STYLE="font-size : 8pt">';
4087 $table_data.= '<option value=0></option>';
4088 for ($j=0; $j < count($individual); $j++) {
4089 $id = $individual[$j];
4090 $name = $indiv_name[$j];
4091 if($individual[$j] == $indiv) {
4092 $selected[$id] = 'selected="selected"';
4094 $selected[$id] = '';
4096 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
4098 $table_data.='</select></td>';
4100 // Family drop down list (for Visits)
4101 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family] STYLE="font-size : 8pt">';
4102 $table_data.= '<option value=0></option>';
4103 for ($j=0; $j < count($individual); $j++) {
4104 $id = $family_id[$j];
4105 $name = $family_name[$j];
4106 if($family_id[$j] == $family) {
4107 $selected[$id] = 'selected="selected"';
4109 $selected[$id] = '';
4111 $table_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.' Family</option>';
4113 $table_data.='</select></td>';
4115 // Location text box
4116 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
4117 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="'.$location.'" STYLE="font-size : 8pt">';
4119 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
4120 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
4122 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4123 $this->t->set_var('tr_color',$tr_color);
4126 // Create blank appointment slot
4127 for ($b=0; $b < 4; $b++) {
4128 $appointment = $this->max_appointments + $b;
4129 $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4132 $table_data.= '<td align=left>';
4133 $table_data.= $this->jscal->input('sched['.$presidency.']['.$appointment.'][date]','','','','','','',$this->cal_options);
4134 $table_data.= '</td>';
4137 $table_data.= "<td align=center>";
4138 $table_data .= $this->get_time_selection_form(0, 0, 0, $presidency, $appointment);
4139 $table_data.= "</td>";
4141 // individual drop down list
4142 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][individual] STYLE="font-size : 8pt">';
4143 $table_data.= '<option value=0></option>';
4144 for ($j=0; $j < count($individual); $j++) {
4145 $id = $individual[$j];
4146 $name = $indiv_name[$j];
4147 $table_data.= '<option value='.$id.'>'.$name.'</option>';
4149 $table_data.='</select></td>';
4151 // Family drop down list
4152 $table_data.= '<td align=center><select name=sched['.$presidency.']['.$appointment.'][family] STYLE="font-size : 8pt">';
4153 $table_data.= '<option value=0></option>';
4154 for ($j=0; $j < count($individual); $j++) {
4155 $id = $family_id[$j];
4156 $name = $family_name[$j];
4157 $table_data.= '<option value='.$id.'>'.$name.' Family</option>';
4159 $table_data.='</select></td>';
4161 // Location text box
4162 $table_data.= '<td align=center><input type=text size="25" maxlength="120" ';
4163 $table_data.= 'name="sched['.$presidency.']['.$appointment.'][location]" value="" STYLE="font-size : 8pt">';
4165 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][appointment]" value="'.$appointment.'">';
4166 $table_data.= '<input type=hidden name="sched['.$presidency.']['.$appointment.'][presidency]" value="'.$presidency.'">';
4168 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4169 $this->t->set_var('tr_color',$tr_color);
4172 $this->t->set_var('table_data',$table_data);
4173 $this->t->set_var('header_row',$header_row);
4174 $this->t->set_var('table_width',$table_width);
4175 $this->t->fp('list','presidency_list',True);
4178 $this->t->pfp('out','sched_t');
4179 $this->save_sessiondata();
4184 $this->t->set_file(array('email_t' => 'email.tpl'));
4185 $this->t->set_block('email_t','individual_list','list');
4187 $action = get_var('action',array('GET','POST'));
4189 $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email'));
4190 $this->t->set_var('title','Email Tool');
4192 $this->t->set_var('lang_email','Send Email');
4193 $this->t->set_var('lang_reset','Cancel');
4195 $this->t->set_var('email_member_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=member'));
4196 $this->t->set_var('email_member_link_title','Email Quorum Member');
4198 $this->t->set_var('email_quorum_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=quorum'));
4199 $this->t->set_var('email_quorum_link_title','Email Quorum');
4201 $this->t->set_var('email_reminder_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=reminder'));
4202 $this->t->set_var('email_reminder_link_title','Email Reminders');
4204 $this->t->set_var('email_edit_link',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.email&action=edit'));
4205 $this->t->set_var('email_edit_link_title','Edit Email Addresses');
4208 $this->t->set_var('table_width',$table_width);
4210 $this->t->pfp('out','email_t');
4211 $this->save_sessiondata();
4216 $this->t->set_file(array('admin_t' => 'admin.tpl'));
4217 $this->t->set_block('admin_t','upload','uploadhandle');
4218 $this->t->set_block('admin_t','admin','adminhandle');
4219 $this->t->set_block('admin_t','cmd','cmdhandle');
4220 $this->t->set_block('admin_t','presidency','presidencyhandle');
4222 $this->t->set_var('upload_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=upload'));
4223 $this->t->set_var('presidency_action',$GLOBALS['phpgw']->link('/tc/index.php','menuaction=tc.tc.admin&action=presidency'));
4225 $action = get_var('action',array('GET','POST'));
4227 $this->t->pfp('out','admin_t');
4229 $sql = "SELECT * FROM tc_individual where steward='$this->default_stewardship' and valid=1 ORDER BY individual ASC";
4230 $this->db->query($sql,__LINE__,__FILE__);
4232 while ($this->db->next_record()) {
4233 $individual[$i] = $this->db->f('individual');
4234 $indiv_name[$i] = $this->db->f('name');
4235 $indiv2name[$individual[$i]] = $indiv_name[$i];
4238 array_multisort($indiv_name, $individual);
4240 if($action == 'upload') {
4241 $target_path = $this->upload_target_path . '/' . basename( $_FILES['uploadedfile']['name']);
4243 if(($_FILES['uploadedfile']['type'] == "application/zip") ||
4244 ($_FILES['uploadedfile']['type'] == "application/x-zip-compressed") ||
4245 ($_FILES['uploadedfile']['type'] == "application/x-zip") ||
4246 ($_FILES['uploadedfile']['type'] == "application/octet-stream")) {
4248 if(!move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
4249 $uploadstatus = "<b><font color=red> -E- Unable to move the uploaded file to ";
4250 $uploadstatus.= "the target path (check the path and permissions) of: $target_path</font></b>";
4251 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
4252 $uploadstatus.= "Tmp Filename : " . $_FILES['uploadedfile']['tmp_name'] . "<br>";
4253 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
4254 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
4255 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
4256 $uploadstatus.= "Error : " . $_FILES['uploadedfile']['error'] . "<br>";
4257 $this->t->set_var('uploadstatus',$uploadstatus);
4258 $this->t->pfp('uploadhandle','upload',True);
4262 $uploadstatus = "<b>The following file was uploaded successfully: </b><br><br>";
4263 $uploadstatus.= "Filename : " . $_FILES['uploadedfile']['name'] . "<br>";
4264 $uploadstatus.= "Type : " . $_FILES['uploadedfile']['type'] . "<br>";
4265 $uploadstatus.= "Size : " . $_FILES['uploadedfile']['size'] . "<br>";
4266 $this->t->set_var('uploadstatus',$uploadstatus);
4267 $this->t->pfp('uploadhandle','upload');
4268 $this->t->set_var('uploadhandle','');
4269 print "<table border=1 width=80%><tr><td>\n<pre>";
4271 # make a directory for this data to be stored in
4272 $date="data_" . date("Y_m_d");
4273 $data_dir = $this->upload_target_path . '/' . $date;
4274 print "-> Making the data directory: $date<br>\n";
4275 exec('mkdir -p ' . $data_dir . ' 2>&1', $result, $return_code);
4276 if($return_code != 0) {
4277 print implode('\n',$result) . "<br>";
4278 print "<b><font color=red>";
4279 print "-E- Unable to create the data directory. Aborting import.";
4280 print "</font></b>";
4284 # move the file uploaded into this directory
4285 print "-> Moving the uploaded file into the data dir<br>\n";
4286 exec('mv ' . $target_path . ' ' . $data_dir . '/' . ' 2>&1', $result, $return_code);
4287 if($return_code != 0) {
4288 print implode('\n',$result) . "<br>";
4289 print "<b><font color=red>";
4290 print "-E- Unable to move the uploaded file into the data dir. Aborting import.";
4291 print "</font></b>";
4295 # unzip the data into this directory
4296 print "-> Unzipping the data<br>\n";
4297 exec($this->unzip_path .' -u '. $data_dir . '/*.zip -d ' . $data_dir . ' 2>&1', $result, $return_code);
4298 if($return_code != 0) {
4299 print implode('\n',$result) . "<br>";
4300 print "<b><font color=red>";
4301 print "-E- Unable to unzip the uploaded file into the data dir: $data_dir. Aborting import.";
4302 print "</font></b>";
4305 exec('mv ' . $data_dir . '/*/* '. $data_dir . ' 2>&1', $result, $return_code);
4307 # update the data_latest link to point to this new directory
4308 print "-> Updating the latest data dir link<br>\n";
4309 $data_latest = $this->upload_target_path . '/data_latest';
4310 exec('rm ' . $data_latest. '; ln -s ' . $data_dir .' '. $data_latest .' 2>&1', $result, $return_code);
4311 if($return_code != 0) {
4312 print implode('\n',$result) . "<br>";
4313 print "<b><font color=red>";
4314 print "-E- Unable to update the data latest link. Aborting import.";
4315 print "</font></b>";
4319 # run the import perl script to encorporate it into the DB
4320 ob_start('ob_logstdout', 2);
4321 print "-> Importing the data into the database<br>\n";
4322 ob_flush(); flush(); sleep(1);
4323 $import_log = $this->upload_target_path . '/import.log';
4324 $data_log = $this->upload_target_path . '/data.log';
4325 $import_cmd = $this->script_path . '/import_ward_data ' . $data_latest . ' 2>&1 | tee ' . $import_log;
4326 $parse_cmd = $this->script_path . '/parse_ward_data -v ' . $data_latest . ' > ' . $data_log . '2>&1';
4327 #print "import_cmd: $import_cmd<br>";
4328 #print "parse_cmd: $parse_cmd<br>";
4329 ob_start('ob_logstdout', 2);
4330 passthru($import_cmd);
4331 passthru($parse_cmd);
4332 ob_flush(); flush(); sleep(1);
4334 # fix the permissions of the data dir
4335 exec('chmod -R o-rwx ' . $data_dir, $result, $return_code);
4337 $this->t->pfp('cmdhandle','cmd');
4338 print "</pre></td></tr></table>";
4339 } else if(($_FILES['uploadedfile']['type'] != "application/zip") &&
4340 ($_FILES['uploadedfile']['type'] != "application/x-zip-compressed") &&
4341 ($_FILES['uploadedfile']['type'] != "application/x-zip") &&
4342 ($_FILES['uploadedfile']['type'] != "application/octet-stream")) {
4343 $uploadstatus = "<b><font color=red>The file format must be a .zip file, please try again! </font></b>";
4344 $uploadstatus.= "<br><br><b>Detected file format: " . $_FILES['uploadedfile']['type'] . "</b>";
4345 $this->t->set_var('uploadstatus',$uploadstatus);
4346 $this->t->pfp('uploadhandle','upload',True);
4348 $uploadstatus = "<b><font color=red> There was an error (" . $_FILES['uploadedfile']['error'];
4349 $uploadstatus.= ") uploading the file, please try again! </font></b>";
4350 $this->t->set_var('uploadstatus',$uploadstatus);
4351 $this->t->pfp('uploadhandle','upload',True);
4353 } else if($action == "presidency") {
4354 $new_data = get_var('eqpres',array('POST'));
4355 foreach ($new_data as $entry) {
4357 $email = $entry['email'];
4358 $indiv = $entry['indiv'];
4359 $name = $entry['name'];
4360 $district = $entry['district'];
4361 $president = $entry['president'];
4362 $counselor = $entry['counselor'];
4363 $secretary = $entry['secretary'];
4364 // look up the individual name for the ID
4365 $name = $indiv2name[$indiv];
4366 //print "id=$id indiv=$indiv name=$name email=$email district=$district president=$president ";
4367 //print "counselor=$counselor secretary=$secretary<br>";
4369 if(($indiv > 0) || ($name != "")) {
4370 if($id < $this->max_presidency_members) {
4371 //print "Updating Existing Entry<br>";
4372 $this->db2->query("UPDATE tc_presidency set" .
4373 " individual=" . $indiv .
4374 " ,district=" . $district .
4375 " ,email='" . $email . "'" .
4376 " ,president='" . $president . "'" .
4377 " ,counselor='" . $counselor . "'" .
4378 " ,secretary='" . $secretary . "'" .
4379 " WHERE presidency=" . $id,__LINE__,__FILE__);
4381 //print "Adding New Entry<br>";
4382 $this->db2->query("INSERT INTO tc_presidency (presidency,individual,district," .
4383 "email,president,counselor,secretary,valid) " .
4384 "VALUES (NULL,'" . $indiv . "','" . $district . "','" .
4385 $email . "','" . $president . "','" .
4386 $counselor . "','" . $secretary . "','1'" .
4387 ")",__LINE__,__FILE__);
4390 //print "Ignoring Blank Entry<br>";
4394 // Now update the tc_district table appropriately
4396 // Delete all the previous district entries from the table
4397 $this->db->query("DELETE from tc_district where valid=1",__LINE__,__FILE__);
4398 $this->db->query("DELETE from tc_district where valid=0",__LINE__,__FILE__);
4400 // Always add a "District 0" assigned to the High Priests Group
4402 $name = "High Priests";
4405 $this->db2->query("INSERT INTO tc_district (district,supervisor,valid) " .
4406 "VALUES ('" . $district . "','" .
4407 $indiv . "','" . $valid . "'" .
4408 ")",__LINE__,__FILE__);
4410 // Requery the tc_presidency table
4411 $sql = "SELECT * FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1";
4412 $this->db->query($sql,__LINE__,__FILE__);
4413 while ($this->db->next_record()) {
4414 // Extract the data for each presidency record
4415 $id = $this->db->f('presidency');
4416 $indiv = $this->db->f('individual');
4417 $name = $this->db->f('name');
4418 $district = $this->db->f('district');
4421 // If we have a valid district, add it to the district table
4423 $this->db2->query("INSERT INTO tc_district (district,supervisor,valid) " .
4424 "VALUES ('" . $district . "','" .
4425 $indiv . "','" . $valid . "'" .
4426 ")",__LINE__,__FILE__);
4430 $this->t->set_var('adminhandle','');
4431 $this->t->pfp('adminhandle','admin');
4435 $this->t->set_var('adminhandle','');
4436 $this->t->pfp('adminhandle','admin');
4439 // Now save off the data needed for a Presidency Table Update
4441 $sql = "SELECT tp.*, ti.name FROM tc_presidency AS tp JOIN tc_individual AS ti WHERE tp.individual=ti.individual AND tp.valid=1";
4442 $this->db->query($sql,__LINE__,__FILE__);
4444 $header_row = "<th>Individual</th><th>Email</th><th>District</th><th>President</th><th>Counselor</th><th>Secretary</th>";
4445 while ($this->db->next_record()) {
4446 // Extract the data for each presidency record
4447 $id = $this->db->f('presidency');
4448 $indiv = $this->db->f('individual');
4449 $district = $this->db->f('district');
4450 $name = $this->db->f('name');
4451 $email = $this->db->f('email');
4452 $president = $this->db->f('president');
4453 $counselor = $this->db->f('counselor');
4454 $secretary = $this->db->f('secretary');
4456 // Create the forms needed in the table
4457 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4460 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4463 if($eqpresidency == 0) {
4464 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4465 $table_data.= '<option value=0></option>';
4466 for ($j=0; $j < count($individual); $j++) {
4467 $tmp_id = $individual[$j];
4468 $name = $indiv_name[$j];
4469 if($individual[$j] == $indiv) {
4471 $selected = 'selected="selected"';
4475 $table_data.= '<option value='.$tmp_id.' '.$selected.'>'.$name.'</option>';
4477 $table_data.='</select></td>';
4478 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="'.$indivname.'">';
4480 $table_data.= '<td align=left><input type=text size="20" name="eqpresname" value="Presidency"></td>';
4481 $table_data.= '<input type=hidden name="eqpres['.$id.'][name]" value="Presidency">';
4485 $table_data .= '<td><input type="text" size="50" name="eqpres['.$id.'][email]" value="'.$email.'"></td>';
4488 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4489 $table_data.= '<option value=0></option>';
4490 for ($j=0; $j <= $this->max_num_districts; $j++) {
4491 if($district == $j) {
4492 $selected = 'selected="selected"';
4496 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4498 $table_data.='</select></td>';
4501 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4502 if($president == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4503 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4504 $table_data.='</select></td>';
4507 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4508 if($counselor == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4509 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4510 $table_data.='</select></td>';
4513 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4514 if($secretary == 1) { $table_data .= '<option value=0>0</option><option value=1 selected="selected">1</option>'; }
4515 else { $table_data .= '<option value=0 selected="selected">0</option><option value=1>1</option>'; }
4516 $table_data.='</select></td>';
4519 $table_data .= "</tr>\n";
4520 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4521 $this->t->set_var('tr_color',$tr_color);
4524 // Now create 1 blank row to always have a line available to add a new individual with
4525 $id = $this->max_presidency_members;
4526 $table_data .= "<tr bgcolor=". $this->t->get_var('tr_color') .">";
4528 $table_data .= '<input type=hidden name="eqpres['.$id.'][id]" value="'.$id.'">';
4530 $table_data.= '<td align=center><select name="eqpres['.$id.'][indiv]">';
4531 $table_data.= '<option value=0></option>';
4532 for ($j=0; $j < count($individual); $j++) {
4533 $tmp_id = $individual[$j];
4534 $name = $indiv_name[$j];
4535 $table_data.= '<option value='.$tmp_id.'>'.$name.'</option>';
4537 $table_data.='</select></td>';
4538 $table_data.='<input type=hidden name="eqpres['.$id.'][name]" value="">';
4540 $table_data.='<td><input type="text" size="50" name="eqpres['.$id.'][email]" value=""></td>';
4542 $table_data.= '<td align=center><select name="eqpres['.$id.'][district]">';
4543 $table_data.= '<option value=0></option>';
4544 for ($j=0; $j <= $this->max_num_districts; $j++) {
4546 $selected = 'selected="selected"';
4550 $table_data.= '<option value='.$j.' '.$selected.'>'.$j.'</option>';
4552 $table_data.='</select></td>';
4554 $table_data.= '<td align=center><select name="eqpres['.$id.'][president]">';
4555 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4556 $table_data.='</select></td>';
4558 $table_data.= '<td align=center><select name="eqpres['.$id.'][counselor]">';
4559 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4560 $table_data.='</select></td>';
4562 $table_data.= '<td align=center><select name="eqpres['.$id.'][secretary]">';
4563 $table_data.= '<option value=0>0</option><option value=1>1</option>';
4564 $table_data.='</select></td>';
4566 $table_data .= "</tr>\n";
4567 $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
4568 $this->t->set_var('tr_color',$tr_color);
4570 $this->t->set_var('header_row',$header_row);
4571 $this->t->set_var('table_data',$table_data);
4572 $this->t->pfp('presidencyhandle','presidency',True);
4574 $this->save_sessiondata();
4577 function email_appt($appointment)
4579 //print "Emailing notification of appointment: $appointment <br>";
4581 $sql = "SELECT * FROM tc_appointment where appointment='$appointment'";
4582 $this->db->query($sql,__LINE__,__FILE__);
4584 while ($this->db->next_record()) {
4585 $appointment = $this->db->f('appointment');
4586 $presidency = $this->db->f('presidency');
4587 $location = $this->db->f('location');
4590 $indiv = $this->db->f('individual');
4592 $family = $this->db->f('family');
4596 $uid = $this->db->f('uid');
4598 // Extract the year, month, day, hours, minutes, seconds from the appointment time
4599 $appt_date = $this->db->f('date');
4600 $date_array = explode("-",$appt_date);
4601 $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2];
4602 $appt_time = $this->db->f('time');
4603 $time_array = explode(":",$appt_time);
4604 $hour = $time_array[0]; $minute = $time_array[1]; $seconds = $time_array[2];
4606 // Format the appointment time into an iCal UTC equivalent
4607 $dtstamp = gmdate("Ymd"."\T"."His"."\Z");
4608 $dtstart = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds,$month,$day,$year));
4609 $dtstartstr = date("l, F d, o g:i A", mktime($hour,$minute,$seconds,$month,$day,$year));
4611 $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'";
4612 $this->db2->query($sql,__LINE__,__FILE__);
4613 if($this->db2->next_record()) {
4614 if ($this->db2->f('email1') != "") {
4615 $email = $this->db2->f('email1');
4617 $email = $this->db2->f('email2');
4619 $interviewer = $this->db2->f('name');
4622 // Set the email address of the interviewer
4626 $sql = "SELECT * FROM tc_individual where individual='$indiv'";
4627 $this->db2->query($sql,__LINE__,__FILE__);
4628 if($this->db2->next_record()) {
4629 $indiv_name = $this->db2->f('name');
4630 $phone = $this->db2->f('phone');
4631 $appt_name = $indiv_name . " Interview";
4632 $duration = $this->default_ppi_appt_duration * 60;
4637 $sql = "SELECT * FROM tc_family WHERE family='$family'";
4638 $this->db2->query($sql,__LINE__,__FILE__);
4639 if($this->db2->next_record()) {
4640 $individual = $this->db2->f('individual');
4641 $sql = "SELECT * FROM tc_individual where individual='$individual'";
4642 $this->db3->query($sql,__LINE__,__FILE__);
4643 if($this->db3->next_record()) {
4644 $phone = $this->db3->f('phone');
4645 $family_name = $this->db3->f('name');
4646 $phone = $this->db3->f('phone');
4648 $appt_name = $family_name . " Family Visit";
4649 $duration = $this->default_visit_appt_duration * 60;
4653 $dtend = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4654 $dtendstr = date("g:i A", mktime($hour,$minute,$seconds+$duration,$month,$day,$year));
4655 $date = $dtstartstr . "-" . $dtendstr;
4656 $description = "$appt_name : $phone";
4658 if(($uid == 0) && ($appt_name != "")) {
4659 // Create a new calendar item for this appointment, since this must be the first time we
4660 // are sending it out.
4661 print "Sent new appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4662 $uid = rand() . rand(); // Generate a random identifier for this appointment
4663 $subject = "Created: $appt_name";
4665 $this->db->query("UPDATE tc_appointment set" .
4667 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4669 $action = "PUBLISH";
4670 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4671 $dtend, $date, $location, $appt_name, $description, $uid);
4672 } else if(($uid != 0) && ($appt_name == "")) {
4673 // Remove the calendar item for this appointment since it has already been sent
4674 // and there is no name we have changed it to.
4675 print "Sent deleted appointment to " . $interviewer . " at " . $email . " for " . $appt_date . " " . $appt_time . "<br>";
4676 $subject = "Canceled: $appt_date $appt_time";
4678 $this->db->query("UPDATE tc_appointment set" .
4680 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4683 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4684 $dtend, $date, $location, $subject, $subject, $uid);
4685 } else if($uid != 0) {
4686 // Update the existing appointment since we have changed it
4687 print "Sent updated appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "<br>";
4689 $subject = "Canceled: $appt_date $appt_time";
4691 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4692 $dtend, $date, $location, $subject, $subject, $uid);
4694 $uid = rand() . rand(); // Generate a random identifier for this appointment
4695 $this->db->query("UPDATE tc_appointment set" .
4697 " WHERE appointment=" . $appointment,__LINE__,__FILE__);
4699 $subject = "Updated: $appt_name";
4700 $action = "PUBLISH";
4701 $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart,
4702 $dtend, $date, $location, $appt_name, $description, $uid);
4708 function send_ical_appt($action, $to, $from, $subject, $dtstamp, $dtstart, $dtend, $date, $location, $summary, $description, $uid)
4710 // Initialize our local variables
4711 $boundary = "=MIME_APPOINTMENT_BOUNDARY";
4715 // Form the headers for the email message
4716 $headers.="X-Mailer: PHP/" . phpversion() . "\n";
4717 $headers.="Mime-Version: 1.0\n";
4718 $headers.="Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
4719 $headers.="Content-Disposition: inline\n";
4720 $headers.="Reply-To: $from\n";
4721 $headers.="From: $from\n";
4723 // Print the plaintext version of the appointment
4724 $message.="--$boundary\n";
4725 $message.="Content-Type: text/plain; charset=us-ascii\n";
4726 $message.="Content-Disposition: inline\n";
4728 $message.="What: $description\n";
4729 $message.="When: $date\n";
4730 $message.="Where: $location\n";
4733 // Print the .ics attachment version of the appointment
4734 $message.="--$boundary\n";
4735 $message.="Content-Type: text/calendar; charset=us-ascii\n";
4736 $message.="Content-Disposition: attachment; filename=\"appointment.ics\"\n";
4738 $message.="BEGIN:VCALENDAR" . "\n";
4739 $message.="VERSION:2.0" . "\n";
4740 $message.="PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN" . "\n";
4741 $message.="METHOD:$action" . "\n";
4742 $message.="BEGIN:VEVENT" . "\n";
4743 $message.="ORGANIZER:MAILTO:$from". "\n";
4744 $message.="DTSTAMP:$dtstamp" . "\n";
4745 $message.="DTSTART:$dtstart" . "\n";
4746 $message.="DTEND:$dtend" . "\n";
4747 $message.="SUMMARY:$summary" . "\n";
4748 $message.="DESCRIPTION:$description" . "\n";
4749 $message.="LOCATION:$location" . "\n";
4750 $message.="UID:$uid" ."\n";
4751 $message.="TRANSP:OPAQUE" . "\n";
4752 $message.="SEQUENCE:0" . "\n";
4753 $message.="CLASS:PUBLIC" . "\n";
4754 $message.="END:VEVENT" . "\n";
4755 $message.="END:VCALENDAR" . "\n";
4757 // Complete the message
4758 $message.="--$boundary\n";
4761 mail($to, $subject, $message, $headers);
4764 function get_time_selection_form($hour, $minute, $pm, $presidency, $appointment)
4769 if($hour == 0) { $blank = 1; }
4771 if($this->time_drop_down_lists == 1) {
4772 // Create drop down lists to get the time
4773 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][hour]>';
4774 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4775 foreach(range(1,12) as $num) {
4777 $selected = 'selected="selected"';
4781 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4783 $form_data.= '</select>';
4784 $form_data.= ' : ';
4785 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][minute]>';
4786 if($blank == 1) { $form_data.= '<option value=""></option>'; }
4789 if($num < 10) { $num = "0" . "$num"; }
4790 if($minute == $num) {
4791 $selected = 'selected="selected"';
4795 if($blank == 1) { $selected = ""; }
4796 $form_data.= '<option value='.$num.' '.$selected.'>'.$num.'</option>';
4797 $num = $num + $this->time_drop_down_list_inc;
4799 $form_data.= '</select>';
4801 // Use free form text fields to get the time
4807 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][hour] value='.$hour.'>';
4809 $form_data.= '<input type=text size=2 name=sched['.$presidency.']['.$appointment.'][minute] value='.$minute.'>';
4810 $form_data.= ' ';
4812 // Always use a drop-down select form for am/pm
4813 $form_data.= '<select name=sched['.$presidency.']['.$appointment.'][pm]>';
4816 $form_data.= '<option value=0 selected>am</option>';
4817 $form_data.= '<option value=1>pm</option>';
4820 $form_data.= '<option value=0>am</option>';
4821 $form_data.= '<option value=1 selected>pm</option>';
4824 $form_data.= '<option value=""></option>';
4825 $form_data.= '<option value=0>am</option>';
4826 $form_data.= '<option value=1>pm</option>';
4828 $form_data.= '</select>';