X-Git-Url: http://git.pippins.net/embedvideo/.git/static/git-logo.png?a=blobdiff_plain;f=inc%2Fclass.eq.inc.php;h=4c26542c8efcc38020379282c3aec1f27e86166c;hb=b3872cd7052dadb30eace5b37b246501860c80dd;hp=38786c2677d685232f0bea25f0352cc112cb7c39;hpb=70a759d295cc5da026b112a2498d5d1958ab23af;p=eq%2F.git diff --git a/inc/class.eq.inc.php b/inc/class.eq.inc.php index 38786c2..4c26542 100644 --- a/inc/class.eq.inc.php +++ b/inc/class.eq.inc.php @@ -22,9 +22,10 @@ class eq var $default_ht_num_months; var $default_ppi_num_months; var $default_ppi_num_years; - var $default_int_num_months; + var $default_int_num_quarters; var $default_int_num_years; - var $default_att_num_months; + var $default_vis_num_years; + var $default_att_num_quarters; var $current_year; var $current_month; var $upload_target_path; @@ -52,7 +53,11 @@ class eq 'dir_view' => True, 'org_view' => True, 'schedule' => True, - 'admin' => True + 'admin' => True, + 'email_appt' => True, + 'send_ical_appt' => True, + 'assign_view' => True, + 'assign_update' => True, ); function eq() @@ -61,10 +66,9 @@ class eq $this->default_ppi_num_months = 3; $this->default_ppi_num_years = 0; $this->default_int_num_quarters = 1; - $this->default_int_num_months = 3; $this->default_int_num_years = 0; $this->default_att_num_quarters = 1; - $this->default_att_num_months = 3; + $this->default_vis_num_years = 1; $this->upload_target_path = "/home/users/eqpres/eq_data/"; $this->script_path = "/usr/share/phpgroupware/eq/"; @@ -123,6 +127,9 @@ class eq $link_data['menuaction'] = 'eq.eq.act_list'; $this->t->set_var('link_activity',$GLOBALS['phpgw']->link('/eq/index.php',$link_data)); $this->t->set_var('lang_activity','Activities'); + $link_data['menuaction'] = 'eq.eq.assign_view'; + $this->t->set_var('link_assignment',$GLOBALS['phpgw']->link('/eq/index.php',$link_data)); + $this->t->set_var('lang_assignment','Assignments'); $link_data['menuaction'] = 'eq.eq.par_view'; $this->t->set_var('link_participation',$GLOBALS['phpgw']->link('/eq/index.php',$link_data)); $this->t->set_var('lang_participation','Participation'); @@ -569,6 +576,7 @@ class eq $this->t->set_var('lang_name','Activity Name'); $this->t->set_var('lang_date','Date'); + $this->t->set_var('lang_notes','Description'); $sql = "SELECT * FROM eq_activity ORDER BY date DESC"; $this->db->query($sql,__LINE__,__FILE__); @@ -577,9 +585,18 @@ class eq $i = 0; while ($this->db->next_record()) { - $activity_list[$i]['name'] = $this->db->f('name'); - $activity_list[$i]['date'] = $this->db->f('date'); $activity_list[$i]['activity'] = $this->db->f('activity'); + $activity_list[$i]['assignment'] = $this->db->f('assignment'); + $activity_list[$i]['date'] = $this->db->f('date'); + $activity_list[$i]['notes'] = $this->db->f('notes'); + + $sql = "SELECT * FROM eq_assignment WHERE assignment='" . $activity_list[$i]['assignment'] . "'"; + $this->db2->query($sql,__LINE__,__FILE__); + if($this->db2->next_record()) + { + $activity_list[$i]['name'] = $this->db2->f('name'); + $activity_list[$i]['code'] = $this->db2->f('code'); + } $i++; } @@ -588,6 +605,9 @@ class eq $this->nextmatchs->template_alternate_row_color(&$this->t); $this->t->set_var('name',$activity_list[$i]['name']); $this->t->set_var('date',$activity_list[$i]['date']); + $activity_notes = $activity_list[$i]['notes']; + if(strlen($activity_notes) > 40) { $activity_notes = substr($activity_notes,0,40) . "..."; } + $this->t->set_var('notes',$activity_notes); $link_data['menuaction'] = 'eq.eq.act_view'; $link_data['activity'] = $activity_list[$i]['activity']; @@ -622,13 +642,20 @@ class eq $sql = "SELECT * FROM eq_activity WHERE activity=" . intval(get_var('activity',array('GET','POST'))); $this->db->query($sql,__LINE__,__FILE__); $this->db->next_record(); - $this->t->set_var('name', $this->db->f('name')); + $this->t->set_var('assignment', $this->db->f('assignment')); $this->t->set_var('date', $this->db->f('date')); $this->t->set_var('notes', $this->db->f('notes')); - + + $sql = "SELECT * FROM eq_assignment WHERE assignment='" . $this->db->f('assignment') . "'"; + $this->db2->query($sql,__LINE__,__FILE__); + if($this->db2->next_record()) + { + $this->t->set_var('name', $this->db2->f('name')); + $this->t->set_var('code', $this->db2->f('code')); + } $this->t->set_var('lang_name','Activity Name'); $this->t->set_var('lang_date','Date'); - $this->t->set_var('lang_notes','Notes'); + $this->t->set_var('lang_notes','Description'); $this->t->set_var('lang_done','Done'); $this->t->set_var('lang_action','View'); @@ -643,7 +670,7 @@ class eq $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data)); $this->t->set_var('lang_edit','Edit'); $this->t->set_var('cal_date',$this->db->f('date')); - + // Now find out which elders participated in this activity $sql = "SELECT * FROM eq_participation WHERE activity=" . intval(get_var('activity',array('GET','POST'))); $this->db->query($sql,__LINE__,__FILE__); @@ -689,14 +716,14 @@ class eq $action = get_var('action',array('GET','POST')); $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_list')); $activity['activity'] = intval(get_var('activity',array('GET','POST'))); - + if($action == 'save') { - $activity['name'] = $this->db->db_addslashes(get_var('name',array('POST'))); + $activity['assignment'] = $this->db->db_addslashes(get_var('assignment',array('POST'))); $activity['date'] = $this->db->db_addslashes(get_var('date',array('POST'))); $activity['notes']= $this->db->db_addslashes(get_var('notes',array('POST'))); $this->db->query("UPDATE eq_activity set " . - " name='" . $activity['name'] . + " assignment='" . $activity['assignment'] . "', date='" . $activity['date'] . "'" . ", notes='" . $activity['notes'] . "'" . " WHERE activity=" . $activity['activity'],__LINE__,__FILE__); @@ -718,12 +745,28 @@ class eq if($action == 'insert') { - $activity['name'] = $this->db->db_addslashes(get_var('name',array('POST'))); + $activity['assignment'] = $this->db->db_addslashes(get_var('assignment',array('POST'))); $activity['date'] = $this->db->db_addslashes(get_var('date',array('POST'))); $activity['notes']= $this->db->db_addslashes(get_var('notes',array('POST'))); - $this->db->query("INSERT INTO eq_activity (name,date,notes) " - . "VALUES ('" . $activity['name'] . "','" + $this->db->query("INSERT INTO eq_activity (assignment,date,notes) " + . "VALUES ('" . $activity['assignment'] . "','" . $activity['date'] . "','" . $activity['notes'] . "')",__LINE__,__FILE__); + + $sql = "SELECT * FROM eq_activity WHERE assignment='".$activity['assignment']."' " + . " AND date='".$activity['date']."' AND notes='".$activity['notes']."'"; + $this->db->query($sql,__LINE__,__FILE__); + if($this->db->next_record()) { + print "activity: " . $this->db->f('activity') . "
"; + $activity['activity'] = $this->db->f('activity'); + } + + $elders = get_var('elder_name',array('POST')); + foreach ($elders as $elder) + { + $this->db->query("INSERT INTO eq_participation (elder,activity) " + . "VALUES (" . $elder . ",". $activity['activity'] . ")",__LINE__,__FILE__); + } + $this->act_list(); return false; } @@ -732,7 +775,7 @@ class eq { $activity['activity'] = 0; $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options)); - $this->t->set_var('name',''); + $this->t->set_var('assignment',''); $this->t->set_var('date',''); $this->t->set_var('notes',''); $this->t->set_var('lang_done','Cancel'); @@ -747,7 +790,8 @@ class eq $this->db->query($sql,__LINE__,__FILE__); $this->db->next_record(); $this->t->set_var('cal_date',$this->jscal->input('date',$this->db->f('date'),'','','','','',$this->cal_options)); - $this->t->set_var('name', $this->db->f('name')); + $this->t->set_var('assignment', $this->db->f('assignment')); + $assignment = $this->db->f('assignment'); $this->t->set_var('date', $this->db->f('date')); $this->t->set_var('notes', $this->db->f('notes')); $this->t->set_var('lang_done','Cancel'); @@ -757,6 +801,30 @@ class eq } + // Create the assignments drop-down list + $sql = "SELECT * FROM eq_assignment ORDER BY name ASC"; + $this->db->query($sql,__LINE__,__FILE__); + $i = 0; + while ($this->db->next_record()) + { + $assignments[$i]['assignment'] = $this->db->f('assignment'); + $assignments[$i]['name'] = $this->db->f('name'); + $assignments[$i]['code'] = $this->db->f('code'); + $i++; + } + + $assignment_data.= ''; + $this->t->set_var('assignment_data',$assignment_data); + + // Create elder selection boxes $sql = "SELECT * FROM eq_elder"; $this->db->query($sql,__LINE__,__FILE__); $i=0; @@ -803,6 +871,125 @@ class eq $this->save_sessiondata(); } + function assign_view() + { + $this->t->set_file(array('assign_view_t' => 'assign_view.tpl')); + $this->t->set_block('assign_view_t','assign_view','list'); + + $this->t->set_var('lang_name','Assignment Name'); + $this->t->set_var('lang_code','Code'); + + $sql = "SELECT * FROM eq_assignment ORDER BY name ASC"; + $this->db->query($sql,__LINE__,__FILE__); + $total_records = $this->db->num_rows(); + + $i = 0; + while ($this->db->next_record()) + { + $assignment_list[$i]['assignment'] = $this->db->f('assignment'); + $assignment_list[$i]['name'] = $this->db->f('name'); + $assignment_list[$i]['code'] = $this->db->f('code'); + $i++; + } + + for ($i=0; $i < count($assignment_list); $i++) + { + $this->nextmatchs->template_alternate_row_color(&$this->t); + $this->t->set_var('name',$assignment_list[$i]['name']); + $this->t->set_var('code',$assignment_list[$i]['code']); + + $link_data['menuaction'] = 'eq.eq.assign_update'; + $link_data['assignment'] = $assignment_list[$i]['assignment']; + $link_data['action'] = 'edit'; + $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data)); + $this->t->set_var('lang_edit','Edit'); + + $link_data['menuaction'] = 'eq.eq.assign_update'; + $link_data['assignment'] = '0'; + $link_data['action'] = 'add'; + $this->t->set_var('add','
'); + + $this->t->fp('list','assign_view',True); + } + + $this->t->pfp('out','assign_view_t'); + $this->save_sessiondata(); + } + + function assign_update() + { + $this->t->set_file(array('form' => 'assign_update.tpl')); + $this->t->set_block('form','add','addhandle'); + $this->t->set_block('form','edit','edithandle'); + $this->t->set_var('lang_done','Done'); + + $action = get_var('action',array('GET','POST')); + $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.assign_view')); + $assignment['assignment'] = intval(get_var('assignment',array('GET','POST'))); + + if($action == 'save') + { + $assignment['name'] = $this->db->db_addslashes(get_var('name',array('POST'))); + $assignment['code'] = $this->db->db_addslashes(get_var('code',array('POST'))); + $this->db->query("UPDATE eq_assignment set " . + " name='" . $assignment['name'] . "'" . + ", code='" . $assignment['code'] . "'" . + " WHERE assignment=" . $assignment['assignment'],__LINE__,__FILE__); + + $this->assign_view(); + return false; + } + + if($action == 'insert') + { + $assignment['name'] = $this->db->db_addslashes(get_var('name',array('POST'))); + $assignment['code'] = $this->db->db_addslashes(get_var('code',array('POST'))); + $this->db->query("INSERT INTO eq_assignment (name,code) " + . "VALUES ('" . $assignment['name'] . "','" + . $assignment['code'] . "')",__LINE__,__FILE__); + $this->assign_view(); + return false; + } + + if($action == 'add') + { + $assignment['assignment'] = 0; + $this->t->set_var('name',''); + $this->t->set_var('code',''); + $this->t->set_var('lang_done','Cancel'); + $this->t->set_var('lang_action','Adding New Assignment'); + $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.assign_update&assignment=' + . $assignment['assignment'] . '&action=' . 'insert')); + } + + if($action == 'edit') + { + $sql = "SELECT * FROM eq_assignment WHERE assignment=" . $assignment['assignment']; + $this->db->query($sql,__LINE__,__FILE__); + $this->db->next_record(); + $this->t->set_var('name', $this->db->f('name')); + $this->t->set_var('code', $this->db->f('code')); + $this->t->set_var('lang_done','Cancel'); + $this->t->set_var('lang_action','Editing Assignment'); + $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.assign_update&assignment=' + . $assignment['assignment'] . '&action=' . 'save')); + + } + + $this->t->set_var('lang_reset','Clear Form'); + $this->t->set_var('lang_add','Add Assignment'); + $this->t->set_var('lang_save','Save Changes'); + $this->t->set_var('edithandle',''); + $this->t->set_var('addhandle',''); + + $this->t->pfp('out','form'); + if($action == 'edit') { $this->t->pfp('addhandle','edit'); } + if($action == 'add') { $this->t->pfp('addhandle','add'); } + + $this->save_sessiondata(); + } + function par_view() { $this->t->set_file(array('par_view_t' => 'par_view.tpl')); @@ -827,32 +1014,56 @@ class eq $i = 0; while ($this->db->next_record()) { - $activity_list[$i]['name'] = $this->db->f('name'); + $activity_list[$i]['assignment'] = $this->db->f('assignment'); $activity_list[$i]['date'] = $this->db->f('date'); $activity_list[$i]['activity'] = $this->db->f('activity'); - if($activity_list[$i]['date'] == '0000-00-00') { $activity_list[$i]['date']=""; } $i++; } - $elder_width=250; $part_width=25; $act_width=50; + $sql = "SELECT * FROM eq_assignment ORDER BY name ASC"; + $this->db->query($sql,__LINE__,__FILE__); + $i=0; + while($this->db->next_record()) + { + $assignment_list[$i]['assignment'] = $this->db->f('assignment'); + $assignment_list[$i]['name'] = $this->db->f('name'); + $assignment_list[$i]['code'] = $this->db->f('code'); + $i++; + } + + $elder_width=270; $part_width=25; $assignment_width=50; $total_width=$elder_width+$part_width; - for ($i=0; $i < count($activity_list); $i++) { - $this->t->set_var('activity_name',$activity_list[$i]['name']); - $this->t->set_var('activity_date',$activity_list[$i]['date']); + for ($i=0; $i < count($assignment_list); $i++) { + $this->t->set_var('assignment_name',$assignment_list[$i]['name']); + $this->t->set_var('assignment_code',$assignment_list[$i]['code']); $this->t->fp('list1','header_list',True); - $total_width += $act_width; + $total_width += $assignment_width; } for ($i=0; $i < count($elder_id); $i++) { $participated=0; $part_table = ''; $this->nextmatchs->template_alternate_row_color(&$this->t); $this->t->set_var('elder_name',$elder_name[$i]); - for ($j=0; $j < count($activity_list); $j++) { - $sql = "SELECT * FROM eq_participation where activity=" - . $activity_list[$j]['activity'] . " AND elder=" . $elder_id[$i]; - $this->db->query($sql,__LINE__,__FILE__); - if($this->db->next_record()) { - $part_table .= ''; + for ($j=0; $j < count($assignment_list); $j++) { + $date = "0000-00-00"; $checkmark=0; $num_matches=0; + for ($k=0; $k < count($activity_list); $k++) { + if($assignment_list[$j]['assignment'] == $activity_list[$k]['assignment']) { + $sql = "SELECT * FROM eq_participation where " + . " activity=" . $activity_list[$k]['activity'] + . " AND elder=" . $elder_id[$i]; + $this->db->query($sql,__LINE__,__FILE__); + while($this->db->next_record()) { + if($activity_list[$k]['date'] > $date) { + $date = $activity_list[$k]['date']; + } + $checkmark=1; + $num_matches++; + $participated++; + } + } + } + if($checkmark) { + $part_table .= ''.$num_matches.'
'.$date.''; $participated++; } else { $part_table .= ' '; @@ -917,6 +1128,9 @@ class eq " elder='" . $elder . "'" . " WHERE appointment=" . $appointment,__LINE__,__FILE__); + // Email the appointment + $this->email_appt($appointment); + } // Save any changes made to the ppi notes table @@ -1203,6 +1417,8 @@ class eq " elder='" . $elder . "'" . " WHERE appointment=" . $appointment,__LINE__,__FILE__); + // Email the appointment + $this->email_appt($appointment); } // Save any changes made to the int notes table @@ -1535,12 +1751,14 @@ class eq { $family = $entry['family']; $appointment = $entry['appointment']; - + // Perform database save actions here $this->db->query("UPDATE eq_appointment set " . " family='" . $family . "'" . " WHERE appointment=" . $appointment,__LINE__,__FILE__); + // Email the appointment + $this->email_appt($appointment); } // Save any changes made to the visit notes table @@ -2378,9 +2596,19 @@ class eq $this->t->set_var('schedule_vis_link',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_sched')); $this->t->set_var('schedule_vis_link_title','Schedule Yearly Visits'); + + $this->t->set_var('linkurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.vis_view')); + $num_years = get_var('num_years',array('GET','POST')); + if($num_years == '') { $num_years = $this->default_vis_num_years; } + $this->t->set_var('num_years',$num_years); + if($num_years == 1) { $this->t->set_var('lang_num_years','Year of History'); } + else { $this->t->set_var('lang_num_years','Years of History'); } + $this->t->set_var('lang_filter','Filter'); + $year = date('Y') - $num_years + 1; + $year_start = $year - 1 . "-12-31"; $year_end = $year + 1 . "-01-01"; - $sql = "SELECT * FROM eq_visit WHERE companionship=0 ORDER BY date DESC"; + $sql = "SELECT * FROM eq_visit WHERE companionship=0 and date > '$year_start' ORDER BY date DESC"; $this->db->query($sql,__LINE__,__FILE__); $total_records = $this->db->num_rows(); @@ -2785,6 +3013,7 @@ class eq { $elder_name[$i] = $this->db->f('name'); $elder_id[$i] = $this->db->f('elder'); + $elder_attending[$elder_id[$i]] = $this->db->f('attending'); $i++; } array_multisort($elder_name, $elder_id); @@ -2862,6 +3091,8 @@ class eq $value = $elder_id[$i] . "-" . $sunday_list[$j]['date']; if($this->db->next_record()) { $att_table .= ''; + } else if($elder_attending[$elder_id[$i]] == 1) { + $att_table .= ''; } else { $att_table .= ''; } @@ -3027,6 +3258,7 @@ class eq $family = $entry['family']; if($pm) { $hour = $hour + 12; } $time = $hour.':'.$minute.':'.'00'; + $uid = 0; // Update an existing appointment if($appointment != 0) @@ -3038,7 +3270,8 @@ class eq " ,time='" . $time . "'" . " WHERE appointment=" . $appointment,__LINE__,__FILE__); - //print "updating entry: appt=$appointment date: $date time: $time elder: $elder family: $family
"; + // Email the appointment + $this->email_appt($appointment); } // Add a new appointment @@ -3046,7 +3279,7 @@ class eq { $this->db->query("INSERT INTO eq_appointment (appointment,presidency,family,elder,date,time) " . "VALUES ('" . $appointment . "','" . $presidency . "','" . $family . "','" - . $elder . "','" . $date . "','" . $time ."')",__LINE__,__FILE__); + . $elder . "','" . $date . "','" . $time . "','" . $uid ."')",__LINE__,__FILE__); //print "adding entry: appt=$appointment date: $date time: $time elder: $elder family: $family
"; } @@ -3371,7 +3604,175 @@ class eq $this->save_sessiondata(); } - + + function email_appt($appointment) + { + //print "Emailing notification of appointment: $appointment
"; + + $sql = "SELECT * FROM eq_appointment where appointment='$appointment'"; + $this->db->query($sql,__LINE__,__FILE__); + + while ($this->db->next_record()) + { + $appointment = $this->db->f('appointment'); + $presidency = $this->db->f('presidency'); + $interviewer = ""; + $email = ""; + $elder = $this->db->f('elder'); + $elder_name = ""; + $family = $this->db->f('family'); + $family_name = ""; + $appt_name = ""; + $phone = ""; + $location = ""; + $uid = $this->db->f('uid'); + + // Extract the year, month, day, hours, minutes, seconds from the appointment time + $appt_date = $this->db->f('date'); + $date_array = explode("-",$appt_date); + $year = $date_array[0]; $month = $date_array[1]; $day = $date_array[2]; + $appt_time = $this->db->f('time'); + $time_array = explode(":",$appt_time); + $hour = $time_array[0]; $minute = $time_array[1]; $seconds = $time_array[2]; + + // Format the appointment time into an iCal UTC equivalent + $dtstamp = gmdate("Ymd"."\T"."His"."\Z"); + $dtstart = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds,$month,$day,$year)); + + // Set the email address of the person making the appointment + $from = $GLOBALS['phpgw_info']['user']['fullname'] . "<" . + $GLOBALS['phpgw_info']['user']['preferences']['email']['address'] . ">"; + + $sql = "SELECT * FROM eq_presidency where presidency='$presidency'"; + $this->db2->query($sql,__LINE__,__FILE__); + if($this->db2->next_record()) { + $email = $this->db2->f('email'); + $interviewer = $this->db2->f('name'); + } + + if($elder > 0) { + $sql = "SELECT * FROM eq_elder where elder='$elder'"; + $this->db2->query($sql,__LINE__,__FILE__); + if($this->db2->next_record()) { + $elder_name = $this->db2->f('name'); + $phone = $this->db2->f('phone'); + $appt_name = $elder_name . " Interview"; + $location = "$interviewer"."'s home"; + $duration = 1800; // 30 minutes + } + } + + if($family > 0) { + $sql = "SELECT * FROM eq_family where family='$family'"; + $this->db2->query($sql,__LINE__,__FILE__); + if($this->db2->next_record()) { + $family_name = $this->db2->f('name'); + $phone = $this->db2->f('phone'); + $elder_id = $this->db2->f('elder_id'); + $appt_name = $family_name . " Family Visit"; + $sql = "SELECT * FROM eq_elder where elder='$elder_id'"; + $this->db3->query($sql,__LINE__,__FILE__); + if($this->db3->next_record()) { + $phone = $this->db3->f('phone'); + } + $sql = "SELECT * FROM eq_parent where family='$family'"; + $this->db3->query($sql,__LINE__,__FILE__); + if($this->db3->next_record()) { + $location=$this->db3->f('address'); + } + $duration = 2700; // 45 minutes + } + } + + $dtend = gmdate("Ymd"."\T"."His"."\Z", mktime($hour,$minute,$seconds+$duration,$month,$day,$year)); + $description = "$appt_name : $phone"; + + if(($uid == 0) && ($appt_name != "")) { + // Create a new calendar item for this appointment, since this must be the first time we + // are sending it out. + print "Sent new appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "
"; + $uid = rand() . rand(); // Generate a random identifier for this appointment + $subject = "Created: $appt_name"; + + $this->db->query("UPDATE eq_appointment set" . + " uid=" . $uid . + " WHERE appointment=" . $appointment,__LINE__,__FILE__); + + $action = "PUBLISH"; + $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart, + $dtend, $location, $appt_name, $description, $uid); + + } else if(($uid != 0) && ($appt_name == "")) { + // Remove the calendar item for this appointment since it has already been sent + // and there is no name we have changed it to. + print "Sent deleted appointment to " . $interviewer . " at " . $email . " for " . $appt_date . " " . $appt_time . "
"; + $subject = "Canceled: $appt_date $appt_time"; + + $this->db->query("UPDATE eq_appointment set" . + " uid=0" . + " WHERE appointment=" . $appointment,__LINE__,__FILE__); + + $action = "CANCEL"; + $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart, + $dtend, $location, $appt_name, $description, $uid); + + } else if($uid != 0) { + // Update the existing appointment since we have changed it + print "Sent updated appointment to " . $interviewer . " at " . $email . " for " . $appt_name . "
"; + + $subject = "Canceled: $appt_date $appt_time"; + $action = "CANCEL"; + $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart, + $dtend, $location, $appt_name, $description, $uid); + + $uid = rand() . rand(); // Generate a random identifier for this appointment + $this->db->query("UPDATE eq_appointment set" . + " uid=" . $uid . + " WHERE appointment=" . $appointment,__LINE__,__FILE__); + + $subject = "Updated: $appt_name"; + $action = "PUBLISH"; + $this->send_ical_appt($action, $email, $from, $subject, $dtstamp, $dtstart, + $dtend, $location, $appt_name, $description, $uid); + } + + } + + return true; + } + + function send_ical_appt($action, $to, $from, $subject, $dtstamp, $dtstart, $dtend, $location, $summary, $description, $uid) + { + $headers = 'From: ' . "$from" . "\n" . + 'Reply-To: ' . "$from" . "\n" . + 'X-Mailer: PHP/' . phpversion() . "\n" . + 'Content-Type: text/calendar;' . "\n" . + 'Content-Transfer-Encoding: 7bit' . "\n"; + + //$message = "phone: $phone date: $date time: $time"; + $message =""; + $message.="BEGIN:VCALENDAR" . "\n"; + $message.="VERSION:2.0" . "\n"; + $message.="PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN" . "\n"; + $message.="METHOD:$action" . "\n"; + $message.="BEGIN:VEVENT" . "\n"; + $message.="ORGANIZER:MAILTO:$from". "\n"; + $message.="DTSTAMP:$dtstamp" . "\n"; + $message.="DTSTART:$dtstart" . "\n"; + $message.="DTEND:$dtend" . "\n"; + $message.="SUMMARY:$summary" . "\n"; + $message.="DESCRIPTION:$description" . "\n"; + $message.="LOCATION:$location" . "\n"; + $message.="UID:$uid" ."\n"; + $message.="TRANSP:OPAQUE" . "\n"; + $message.="SEQUENCE:0" . "\n"; + $message.="CLASS:PUBLIC" . "\n"; + $message.="END:VEVENT" . "\n"; + $message.="END:VCALENDAR" . "\n"; + + mail($to, $subject, $message, $headers); + + } } ?>