📄 calendar.class.inc
字号:
$sql .= " AND cal_events.todo='1'"; }elseif(!$todos) { $sql .= " AND cal_events.todo='0'"; } if($formail) { $sql .= " AND cal_reminders.email_sent='0'"; } $this->query($sql); return $this->num_rows(); } function get_event($event_id) { $sql = "SELECT * FROM cal_events WHERE id='$event_id'"; $this->query($sql); if($this->next_record(MYSQL_ASSOC)) { return $this->Record; }else { return false; } } function get_events_for_period($user_id, $start_offset, $days, $index_hour=false) { $interval_end = mktime(0, 0, 0, date("m", $start_offset) , date("d", $start_offset)+$days, date("Y", $start_offset)); $year = date("Y", $start_offset); $month = date("m", $start_offset); $day = date("d", $start_offset); $events = $this->get_events_in_array(0, 0, $user_id, $start_offset, $interval_end, $day, $month, $year, 0, 'Ymd', $index_hour); return $events; } function delete_event($event_id) { if($event = $this->get_event($event_id)) { global $GO_SECURITY; $GO_SECURITY->delete_acl($event['acl_read']); $GO_SECURITY->delete_acl($event['acl_write']); $sql = "DELETE FROM cal_events WHERE id='$event_id'"; $this->query($sql); $sql = "DELETE FROM cal_events_calendars WHERE event_id='$event_id'"; $this->query($sql); $sql = "DELETE FROM cal_reminders WHERE event_id='$event_id'"; $this->query($sql); $sql = "DELETE FROM cal_participants WHERE event_id='$event_id'"; $this->query($sql); $sql = "DELETE FROM cal_exceptions WHERE event_id='$event_id'"; $this->query($sql); $cal = new calendar(); $this->get_event_resources($event_id); while($this->next_record()) { $cal->delete_event($this->f('id')); } } return false; } function add_exception($exception) { $exception['id'] = $this->nextid('cal_exceptions'); return $this->insert_row('cal_exceptions', $exception); } function is_exception($event_id, $time) { $sql = "SELECT * FROM cal_exceptions WHERE event_id='$event_id' AND time='$time'"; $this->query($sql); return $this->next_record(); } function delete_user($user_id) { $delete = new calendar(); $sql = "SELECT * FROM cal_calendars WHERE user_id='$user_id'"; $this->query($sql); while($this->next_record()) { $delete->delete_calendar($this->f('id')); } $sql = "SELECT * FROM cal_events WHERE user_id='$user_id'"; $this->query($sql); while($this->next_record()) { $delete->delete_event($this->f('id')); } $this->get_user_views($user_id); while($this->next_record()) { $delete->delete_view($this->f('id')); } $this->query("DELETE FROM cal_settings WHERE user_id='$user_id'"); } function get_view_color($view_id, $event_id) { $sql = "SELECT cal_views_calendars.background FROM cal_events_calendars ". "INNER JOIN cal_views_calendars ON cal_events_calendars.calendar_id=". "cal_views_calendars.calendar_id WHERE cal_events_calendars.event_id=$event_id AND cal_views_calendars.view_id=$view_id"; $this->query($sql); if($this->num_rows() == 1 && $this->next_record()) { return $this->f('background'); } return 'FFFFCC'; } function get_event_from_ical_object($object) { global $GO_MODULES; if(!isset($this->ical2array)) { require_once($GO_MODULES->modules['calendar']['class_path'].'ical2array.class.inc'); $this->ical2array = new ical2array(); } global $GO_SECURITY; if(!isset($object['DTSTART']) || !isset($object['SUMMARY'])) { return false; } $event['name'] = isset($object['SUMMARY']['value']) ? trim($object['SUMMARY']['value']) : ''; if(isset($object['SUMMARY']['params']['ENCODING']) && $object['SUMMARY']['params']['ENCODING'] == 'QUOTED-PRINTABLE') { $event['name'] = quoted_printable_decode($event['name']); } $event['description'] = isset($object['DESCRIPTION']['value']) ? trim($object['DESCRIPTION']['value']) : ''; if(isset($object['DESCRIPTION']['params']['ENCODING']) && $object['DESCRIPTION']['params']['ENCODING'] == 'QUOTED-PRINTABLE') { $event['description'] = quoted_printable_decode($event['description']); } $event['location'] = isset($object['LOCATION']['value']) ? trim($object['LOCATION']['value']) : ''; if(isset($object['LOCATION']['params']['ENCODING']) && $object['LOCATION']['params']['ENCODING'] == 'QUOTED-PRINTABLE') { $event['location'] = quoted_printable_decode($event['location']); } $event['status_id'] = $this->get_status_id($object['STATUS']['value']); $event['all_day_event'] = (isset($object['DTSTART']['params']['VALUE']) && strtoupper($object['DTSTART']['params']['VALUE']) == 'DATE') ? true : false; if($event['all_day_event']) { $timezone_id=''; }else { $timezone_id = isset($object['DTEND']['params']['TZID']) ? $object['DTEND']['params']['TZID'] : ''; } $event['start_time'] = $this->ical2array->parse_date($object['DTSTART']['value'], $timezone_id); if(isset($object['DTEND']['value'])) { $timezone_id = isset($object['DTEND']['params']['TZID']) ? $object['DTEND']['params']['TZID'] : ''; $event['end_time'] = $this->ical2array->parse_date($object['DTEND']['value'], $timezone_id); }elseif(isset($object['DURATION']['value'])) { $duration = $this->ical2array->parse_date($object['DURATION']['value']); $event['end_time'] = $event['start_time']+$duration; } if($event['name'] != '' && $event['start_time'] > 0 && $event['end_time'] > 0) { $event['all_day_event'] = (isset($object['DTSTART']['params']['VALUE']) && strtoupper($object['DTSTART']['params']['VALUE']) == 'DATE') ? true : false; //for Nokia. It doesn't send all day event in any way. If the local times are equal and the //time is 0:00 hour then this is probably an all day event. if($event['end_time'] == $event['start_time'] && date('G', gmt_to_local_time($event['start_time']))==0) { $event['all_day_event'] = '1'; //$event['start_time'] = gmt_to_local_time($event['start_time']); } if($event['all_day_event']) { $event['end_time'] += 86340; } if(isset($object['CLASS']['value'])) { if($object['CLASS']['value'] == 'PRIVATE') { $event['permissions'] = PRIVATE_EVENT; }else { $cal_settings = $this->get_settings($GO_SECURITY->user_id); $event['permissions'] = $cal_settings['permissions']; } } $event['sun'] = 0; $event['mon'] = 0; $event['tue'] = 0; $event['wed'] = 0; $event['thu'] = 0; $event['fri'] = 0; $event['sat'] = 0; $event['repeat_every'] = 0; $event['repeat_forever'] = 0; $event['repeat_type'] = REPEAT_NONE; $event['repeat_end_time'] = 0; $event['month_time'] = 0; if (isset($object['RRULE']['value'])) { if(!$rrule = $this->ical2array->parse_rrule($object['RRULE']['value'])) { //Recurrence rule is not understood by GO, abort import return false; } if(isset($rrule['FREQ'])) { if (isset($rrule['UNTIL'])) { if($event['repeat_end_time'] = $this->ical2array->parse_date($rrule['UNTIL'])) { $event['repeat_end_time'] = mktime(0,0,0, date('n', $event['repeat_end_time']), date('j', $event['repeat_end_time'])+1, date('Y', $event['repeat_end_time'])); }else { $event['repeat_forever'] = 1; } }elseif(isset($rrule['COUNT'])) { //TODO figure out end time $event['repeat_forever'] = 1; }else { $event['repeat_forever'] = 1; } $event['repeat_every'] = $rrule['INTERVAL']; switch($rrule['FREQ']) { case 'DAILY': $event['repeat_type'] = REPEAT_DAILY; break; case 'WEEKLY': $event['repeat_type'] = REPEAT_WEEKLY; $days = explode(',', $rrule['BYDAY']); $event['sun'] = in_array('SU', $days) ? '1' : '0'; $event['mon'] = in_array('MO', $days) ? '1' : '0'; $event['tue'] = in_array('TU', $days) ? '1' : '0'; $event['wed'] = in_array('WE', $days) ? '1' : '0'; $event['thu'] = in_array('TH', $days) ? '1' : '0'; $event['fri'] = in_array('FR', $days) ? '1' : '0'; $event['sat'] = in_array('SA', $days) ? '1' : '0'; break; case 'MONTHLY': if (isset($rrule['BYDAY'])) { $event['repeat_type'] = REPEAT_MONTH_DAY; $event['month_time'] = $rrule['BYDAY'][0]; $day = substr($rrule['BYDAY'], 1); switch($day) { case 'MO': $event['mon'] = 1; break; case 'TU': $event['tue'] = 1; break; case 'WE': $event['wed'] = 1; break; case 'TH': $event['thu'] = 1; break; case 'FR': $event['fri'] = 1; break; case 'SA': $event['sat'] = 1; break; case 'SUN': $event['sun'] = 1; break; } }else { $event['repeat_type'] = REPEAT_MONTH_DATE; if (isset($rrule['BYMONTHDAY'])) { //GO Supports only one single monthday $bymonthday = explode(',',$rrule['BYMONTHDAY']); if($bymonthday[0] > 0 && date('j', $event['start_time']) != $bymonthday[0]) { go_log(LOG_DEBUG, 'ByMonthDay: '.$bymonthday[0]); $duration = $event['end_time'] - $event['start_time']; $event['start_time'] = mktime( date('G',$event['start_time']), date('i', $event['start_time']), 0, date('n',$event['start_time']), $bymonthday[0], date('Y',$event['start_time'])); $event['end_time'] = $event['start_time']+$duration; } } } break; case 'YEARLY': $event['repeat_type'] = REPEAT_YEARLY; if (isset($rrule['BYMONTH'])) { //GO Supports only one single month $bymonth = explode(',',$rrule['BYMONTH']); if($bymonth[0] > 0 && date('n', $event['start_time']) != $bymonth[0]) { $duration = $event['end_time'] - $event['start_time']; $event['start_time'] = mktime( date('G',$event['start_time']), date('i', $event['start_time']), 0, $bymonth[0], date('j',$event['start_time']), date('Y',$event['start_time'])); $event['end_time'] = $event['start_time']+$duration; } } break; } } } if (isset($object['X-GO-BGCOLOR']['value'])) { $event['background'] = $object['X-GO-BGCOLOR']['value']; }else { $event['background'] = 'FFFFCC'; } $event['reminder'] = 0; $event['completion_time'] =0; $event['todo'] = '0'; return $event; } return false; } function get_event_from_ical_file($ical_file) { global $GO_MODULES; require_once($GO_MODULES->modules['calendar']['class_path'].'ical2array.class.inc'); $this->ical2array = new ical2array(); $vcalendar = $this->ical2array->parse_file($ical_file); while($object = array_shift($vcalendar[0]['objects'])) { if($object['type'] == 'VEVENT') { if($event = $this->get_event_from_ical_object($object)) { return $event; } } } return false; } function import_ical_string($ical_string, $calendar_id) { global $GO_MODULES; require_once($GO_MODULES->modules['calendar']['class_path'].'ical2array.class.inc'); $this->ical2array = new ical2array(); $vcalendar = $this->ical2array->parse_string($ical_string); while($object = array_shift($vcalendar[0]['objects'])) { if($object['type'] == 'VEVENT') { if($event = $this->get_event_from_ical_object($object)) { $event['acl_read'] = $GO_SECURITY->get_new_acl('calendar_read'); $event['acl_write'] = $GO_SECURITY->get_new_acl('calendar_write'); $event = array_map('addslashes', $event); $event = array_map('trim', $event); if ($event['acl_read'] && $event['acl_write'] && $event_id = $this->add_event($event)) { $this->subscribe_event($event_id, $calendar_id); if($event['permissions'] != PRIVATE_EVENT) { $GO_SECURITY->add_group_to_acl($GO_CONFIG->group_everyone, $event['acl_read']); } $GO_SECURITY->add_user_to_acl($GO_SECURITY->user_id, $event['acl_write']); return $event_id; }else { $GO_SECURITY->delete_acl($event['acl_read']); $GO_SECURITY->delete_acl($event['acl_write']); } } } } return false; } //TODO: VTODO and attendee support function import_ical_file($user_id, $ical_file, $calendar_id, $return_event_id=false) { global $GO_CONFIG, $GO_SECURITY, $GO_MODULES; $count = 0; $cal_module = $GO_MODULES->get_module('calendar'); if ($calendar = $this->get_calendar($calendar_id) && $cal_module) { require_once($cal_module['class_path'].'ical2array.class.inc'); $this->ical2array = new ical2array(); $vcalendar = $this->ical2array->parse_file($ical_file); while($object = array_shift($vcalendar[0]['objects'])) { if($object['type'] == 'VEVENT') { if($event = $this->get_event_from_ical_object($object)) { $event['acl_read'] = $GO_SECURITY->get_new_acl('calendar_read'); $event['acl_write'] = $GO_SECURITY->get_new_acl('calendar_write'); $event = array_map('addslashes', $event); $event = array_map('trim', $event); if ($event['acl_read'] && $event['acl_write'] && $event_id = $this->add_event($event)) { $count++; $this->subscribe_event($event_id, $calendar_id); $GO_SECURITY->add_group_to_acl($GO_CONFIG->group_everyone, $event['acl_read']); $GO_SECURITY->add_user_to_acl($GO_SECURITY->user_id, $event['acl_write']); }else { $GO_SECURITY->delete_acl($event['acl_read']); $GO_SECURITY->delete_acl($event['acl_write']); } } } } } return $count; } function get_conflicts($start_time, $end_time, $calendars, $participants) { global $GO_USERS, $RFC822; $conflicts=array(); $participants_array = $RFC822->explode_address_list($participants); for($i=0;$i<sizeof($participants_array);$i++) { if(!empty($participants_array[$i])) { $id = 0; if($member_profile = $GO_USERS->get_user_by_email(smart_addslashes($participants_array[$i]))) { $id = $member_profile["id"]; $member_events = false; if($id) { $member_events = $this->get_events_in_array(0, 0, $id, $start_time, $end_time); foreach($member_events as $event) { $conflicts[$event['id']]=$event; } } } } } foreach($calendars as $calendar_id) { $cal_events = $this->get_events_in_array($calendar_id, 0, 0, $start_time, $end_time); foreach($cal_events as $event) { $conflicts[$event['id']]=$event; } } return $conflicts; }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -