From 88519279bd018d85833744dca45fbe559c793803 Mon Sep 17 00:00:00 2001 From: skeeter Date: Mon, 16 Jul 2001 11:38:40 +0000 Subject: [PATCH] First cut with n-tier design. --- calendar/inc/class.bocalendar.inc.php | 760 +++++++++ calendar/inc/class.socalendar.inc.php | 277 ++++ calendar/inc/class.socalendar_.inc.php | 29 + calendar/inc/class.socalendar__.inc.php | 415 +++++ calendar/inc/class.socalendar_sql.inc.php | 599 +++++++ calendar/inc/class.uicalendar.inc.php | 1802 +++++++++++++++++++++ 6 files changed, 3882 insertions(+) create mode 100755 calendar/inc/class.bocalendar.inc.php create mode 100755 calendar/inc/class.socalendar.inc.php create mode 100755 calendar/inc/class.socalendar_.inc.php create mode 100755 calendar/inc/class.socalendar__.inc.php create mode 100755 calendar/inc/class.socalendar_sql.inc.php create mode 100755 calendar/inc/class.uicalendar.inc.php diff --git a/calendar/inc/class.bocalendar.inc.php b/calendar/inc/class.bocalendar.inc.php new file mode 100755 index 0000000000..7d86a41086 --- /dev/null +++ b/calendar/inc/class.bocalendar.inc.php @@ -0,0 +1,760 @@ + * + * http://www.radix.net/~cknudsen * + * Modified by Mark Peters * + * -------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 2 of the License, or (at your * + * option) any later version. * + \**************************************************************************/ + + /* $Id$ */ + + class bocalendar + { + var $public_functions = Array( + 'read_entries' => True, + 'read_entry' => True, + 'add_entry' => True, + 'update_entry' => True + ); + + var $debug = False; + + var $so; + var $cached_events; + var $repeating_events; + var $datetime; + var $day; + var $month; + var $year; + + var $owner; + var $holiday_color; + var $printer_friendly = False; + + var $holiday_locales; + var $holidays; + var $cached_holidays; + + var $filter; + var $cat_id; + var $users_timeformat; + + var $use_session = False; + + function bocalendar($session=False) + { + global $phpgw, $phpgw_info, $date, $year, $month, $day; + + $phpgw->nextmatchs = CreateObject('phpgwapi.nextmatchs'); + + $this->so = CreateObject('calendar.socalendar'); + $this->datetime = $this->so->datetime; + + $this->filter = ' '.$phpgw_info['user']['preferences']['calendar']['defaultfilter'].' '; + + if($session) + { + $this->read_sessiondata(); + $this->use_session = True; + } + + if(isset($this->so->owner)) + { + $this->owner = $this->so->owner; + } + else + { + $this->so->owner = $this->owner; + } + + if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12') + { + $this->users_timeformat = 'h:i a'; + } + else + { + $this->users_timeformat = 'H:i'; + } + + $this->holiday_color = (substr($phpgw_info['theme']['bg07'],0,1)=='#'?'':'#').$phpgw_info['theme']['bg07']; + + global $filter, $fcat_id, $owner, $month, $day, $year, $friendly; + + if($friendly == 1) + { + $this->printer_friendly = True; + } + + if(isset($filter)) { $this->filter = ' '.chop($filter).' '; } + if(isset($fcat_id)) { $this->cat_id = $fcat_id; } + + if(isset($date)) + { + $this->year = intval(substr($date,0,4)); + $this->month = intval(substr($date,4,2)); + $this->day = intval(substr($date,6,2)); + } + else + { + if(isset($year)) + { + $this->year = $year; + } + if(isset($month)) + { + $this->month = $month; + } + if(isset($day)) + { + $this->day = $day; + } + } + } + + function save_sessiondata($data) + { + if ($this->use_session) + { + global $phpgw; + if($this->debug) { echo '
Save:'; _debug_array($data); } + $phpgw->session->appsession('session_data','calendar',$data); + } + } + + function read_sessiondata() + { + global $phpgw; + + $data = $phpgw->session->appsession('session_data','calendar'); + if($this->debug) { echo '
Read:'; _debug_array($data); } + + $this->filter = $data['filter']; + $this->cat_id = $data['cat_id']; + $this->owner = $data['owner']; + $this->year = $data['year']; + $this->month = $data['month']; + $this->day = $data['day']; + + } + + function strip_html($dirty = '') + { + + if ($dirty == '') + { + $dirty = array(); + return $dirty; + } + else + { + global $phpgw; + for($i=0;$istrip_html($dirty[$i][$name]); + } + } + return $cleaned; + } + } + + function read_entry($id) + { + return $this->so->read_entry($id); + } + + /* Private functions */ + + /* Begin Calendar functions */ + function auto_load_holidays($locale) + { + if($this->so->count_of_holidays($locale) == 0) + { + global $phpgw_info, $HTTP_HOST, $SERVER_PORT; + + @set_time_limit(0); + + /* get the file that contains the calendar events for your locale */ + /* "http://www.phpgroupware.org/cal/holidays.US"; */ + $network = CreateObject('phpgwapi.network'); + if(isset($phpgw_info['server']['holidays_url_path']) && $phpgw_info['server']['holidays_url_path'] != 'localhost') + { + $load_from = $phpgw_info['server']['holidays_url_path']; + } + else + { + $pos = strpos(' '.$phpgw_info['server']['webserver_url'],$HTTP_HOST); + if($pos == 0) + { + switch($SERVER_PORT) + { + case 80: + $http_protocol = 'http://'; + break; + case 443: + $http_protocol = 'https://'; + break; + } + $server_host = $http_protocol.$HTTP_HOST.$phpgw_info['server']['webserver_url']; + } + else + { + $server_host = $phpgw_info['server']['webserver_url']; + } + $load_from = $server_host.'/calendar/setup'; + } +// echo 'Loading from: '.$load_from.'/holidays.'.strtoupper($locale)."
\n"; + $lines = $network->gethttpsocketfile($load_from.'/holidays.'.strtoupper($locale)); + if (!$lines) + { + return false; + } + $c_lines = count($lines); + for($i=0;$i<$c_lines;$i++) + { +// echo 'Line #'.$i.' : '.$lines[$i]."
\n"; + $holiday = explode("\t",$lines[$i]); + if(count($holiday) == 7) + { + $holiday['locale'] = $holiday[0]; + $holiday['name'] = addslashes($holiday[1]); + $holiday['mday'] = intval($holiday[2]); + $holiday['month_num'] = intval($holiday[3]); + $holiday['occurence'] = intval($holiday[4]); + $holiday['dow'] = intval($holiday[5]); + $holiday['observance_rule'] = intval($holiday[6]); + $holiday['hol_id'] = 0; + $this->so->save_holiday($holiday); + } + } + } + } + + function build_holiday_query() + { + @reset($this->holiday_locales); + if(count(@$this->holiday_locales) == 0) + { + return False; + } + $sql = 'SELECT * FROM phpgw_cal_holidays WHERE locale in ('; + $find_it = ''; + while(list($key,$value) = each($this->holiday_locales)) + { + if($find_it) + { + $find_it .= ','; + } + $find_it .= "'".$value."'"; + } + $sql .= $find_it.')'; + + return $sql; + } + + function sort_holidays_by_date($holidays) + { + $c_holidays = count($holidays); + for($outer_loop=0;$outer_loop<($c_holidays - 1);$outer_loop++) + { + for($inner_loop=$outer_loop;$inner_loop<$c_holidays;$inner_loop++) + { + if($holidays[$outer_loop]['date'] > $holidays[$inner_loop]['date']) + { + $temp = $holidays[$inner_loop]; + $holidays[$inner_loop] = $holidays[$outer_loop]; + $holidays[$outer_loop] = $temp; + } + } + } + return $holidays; + } + + function set_holidays_to_date($holidays) + { + $new_holidays = Array(); + for($i=0;$i\n"; + $new_holidays[date('Ymd',$holidays[$i]['date'])][] = $holidays[$i]; + } + return $new_holidays; + } + + function read_holiday() + { + global $phpgw, $phpgw_info; + + if(isset($this->cached_holidays)) + { + return $this->cached_holidays; + } + + if(@$phpgw_info['user']['preferences']['common']['country']) + { + $this->holiday_locales[] = $phpgw_info['user']['preferences']['common']['country']; + } + elseif(@$phpgw_info['user']['preferences']['calendar']['locale']) + { + $this->holiday_locales[] = $phpgw_info['user']['preferences']['calendar']['locale']; + } + + if($this->owner != $phpgw_info['user']['account_id']) + { + $owner_pref = CreateObject('phpgwapi.preferences',$owner); + $owner_prefs = $owner_pref->read_repository(); + if(@$owner_prefs['common']['country']) + { + $this->holiday_locales[] = $owner_prefs['common']['country']; + } + elseif(@$owner_prefs['calendar']['locale']) + { + $this->holiday_locales[] = $owner_prefs['calendar']['locale']; + } + unset($owner_pref); + } + + @reset($this->holiday_locales); + if($phpgw_info['server']['auto_load_holidays'] == True) + { + while(list($key,$value) = each($this->holiday_locales)) + { + $this->auto_load_holidays($value); + } + } + + $sql = $this->build_holiday_query(); + if($sql == False) + { + return array(); + } + $holidays = $this->so->read_holidays($sql); + $temp_locale = $phpgw_info['user']['preferences']['common']['country']; + for($i=0;$icalculate_date($holidays[$i], $holidays, $this->year, $this->datetime, $c); + unset($holidaycalc); + if($c != $i) + { + $i = $c; + } + } + $this->holidays = $this->sort_holidays_by_date($holidays); + $this->cached_holidays = $this->set_holidays_to_date($this->holidays); + $phpgw_info['user']['preferences']['common']['country'] = $temp_locale; + return $this->holidays; + } + /* End Calendar functions */ + + + function check_perms($needed,$user=0) + { + global $grants; + if($user == 0) + { + return ($this->so->rights & $needed); + } + else + { + return ($grants[$user] & $needed); + } + } + + function display_status($user_status) + { + global $phpgw_info; + + if(isset($phpgw_info['user']['preferences']['calendar']['display_status']) && $phpgw_info['user']['preferences']['calendar']['display_status'] == True) + { + return ' ('.$user_status.')'; + } + else + { + return ''; + } + } + + function get_long_status($status_short) + { + switch ($status_short) + { + case 'A': + $status = lang('Accepted'); + break; + case 'R': + $status = lang('Rejected'); + break; + case 'T': + $status = lang('Tentative'); + break; + case 'U': + $status = lang('No Response'); + break; + } + return $status; + } + + function is_private($event,$owner,$field='') + { + global $phpgw, $phpgw_info, $grants; + + if($owner == 0) { $owner = $phpgw_info['user']['account_id']; } + if ($owner == $phpgw_info['user']['account_id'] || ($grants[$owner] & PHPGW_ACL_PRIVATE) || ($event->public == 1)) + { + $is_private = False; + } + elseif($event->public == 0) + { + $is_private = True; + } + elseif($event->public == 2) + { + $is_private = True; + $groups = $phpgw->accounts->memberships($owner); + while ($group = each($groups)) + { + if (strpos(' '.implode($event->groups,',').' ',$group[1]['account_id'])) + { + $is_private = False; + } + } + } + else + { + $is_private = False; + } + + return $is_private; + } + + function get_short_field($event,$is_private=True,$field='') + { + if ($is_private) + { + $str = 'private'; + } + elseif (strlen($event->$field) > 19) + { + $str = substr($event->$field, 0 , 19) . '...'; + } + else + { + $str = $event->$field; + } + + return $str; + } + + function sort_event($event,$date) + { + $inserted = False; + if($this->cached_events[$date]) + { + for($i=0;$icached_events[$date]);$i++) + { + $events = $this->cached_events[$date][$i]; + $events_id = $events->id; + $event_id = $event->id; + if($events->id == $event->id) + { + $inserted = True; + break; + } + $year = substr($date,0,4); + $month = substr($date,4,2); + $day = substr($date,6,2); + if(date('Hi',mktime($event->start->hour,$event->start->min,$event->start->sec,$month,$day,$year)) < date('Hi',mktime($events->start->hour,$events->start->min,$events->start->sec,$month,$day,$year))) + { + for($j=count($this->cached_events[$date]);$j>=$i;$j--) + { + $this->cached_events[$date][$j + 1] = $this->cached_events[$date][$j]; + } + $inserted = True; + $this->cached_events[$date][$j] = $event; + break; + } + } + } + if(!$inserted) + { + $this->cached_events[$date][] = $event; + } + } + + function check_repeating_events($datetime) + { + global $phpgw, $phpgw_info; + + @reset($this->repeating_events); + $search_date_full = date('Ymd',$datetime); + $search_date_year = date('Y',$datetime); + $search_date_month = date('m',$datetime); + $search_date_day = date('d',$datetime); + $search_date_dow = date('w',$datetime); + $search_beg_day = mktime(0,0,0,$search_date_month,$search_date_day,$search_date_year); + $repeated = $this->repeating_events; + $r_events = count($repeated); + for ($i=0;$i<$r_events;$i++) + { + $rep_events = $this->repeating_events[$i]; + $id = $rep_events->id; + $event_beg_day = mktime(0,0,0,$rep_events->start->month,$rep_events->start->mday,$rep_events->start->year); + if($rep_events->recur_enddate->month != 0 && $rep_events->recur_enddate->mday != 0 && $rep_events->recur_enddate->year != 0) + { + $event_recur_time = mktime($rep_events->recur_enddate->hour,$rep_events->recur_enddate->min,$rep_events->recur_enddate->sec,$rep_events->recur_enddate->month,$rep_events->recur_enddate->mday,$rep_events->recur_enddate->year); + } + else + { + $event_recur_time = mktime(0,0,0,1,1,2030); + } + $end_recur_date = date('Ymd',$event_recur_time); + $full_event_date = date('Ymd',$event_beg_day); + + // only repeat after the beginning, and if there is an rpt_end before the end date + if (($search_date_full > $end_recur_date) || ($search_date_full < $full_event_date)) + { + continue; + } + + if ($search_date_full == $full_event_date) + { + $this->sort_event($rep_events,$search_date_full); + continue; + } + else + { + $freq = $rep_events->recur_interval; + $type = $rep_events->recur_type; + switch($type) + { + case MCAL_RECUR_DAILY: + if (floor(($search_beg_day - $event_beg_day)/86400) % $freq) + { + continue; + } + else + { + $this->sort_event($rep_events,$search_date_full); + } + break; + case MCAL_RECUR_WEEKLY: + if (floor(($search_beg_day - $event_beg_day)/604800) % $freq) + { + continue; + } + $check = 0; + switch($search_date_dow) + { + case 0: + $check = MCAL_M_SUNDAY; + break; + case 1: + $check = MCAL_M_MONDAY; + break; + case 2: + $check = MCAL_M_TUESDAY; + break; + case 3: + $check = MCAL_M_WEDNESDAY; + break; + case 4: + $check = MCAL_M_THURSDAY; + break; + case 5: + $check = MCAL_M_FRIDAY; + break; + case 6: + $check = MCAL_M_SATURDAY; + break; + } + if ($rep_events->recur_data & $check) + { + $this->sort_event($rep_events,$search_date_full); + } + break; + case MCAL_RECUR_MONTHLY_WDAY: + if ((($search_date_year - $rep_events->start->year) * 12 + $search_date_month - $rep_events->start->month) % $freq) + { + continue; + } + + if (($this->datetime->day_of_week($rep_events->start->year,$rep_events->start->month,$rep_events->start->mday) == $this->datetime->day_of_week($search_date_year,$search_date_month,$search_date_day)) && + (ceil($rep_events->start->mday/7) == ceil($search_date_day/7))) + { + $this->sort_event($rep_events,$search_date_full); + } + break; + case MCAL_RECUR_MONTHLY_MDAY: + if ((($search_date_year - $rep_events->start->year) * 12 + $search_date_month - $rep_events->start->month) % $freq) + { + continue; + } + if ($search_date_day == $rep_events->start->mday) + { + $this->sort_event($rep_events,$search_date_full); + } + break; + case MCAL_RECUR_YEARLY: + if (($search_date_year - $rep_events->start->year) % $freq) + { + continue; + } + if (date('dm',$datetime) == date('dm',$event_beg_day)) + { + $this->sort_event($rep_events,$search_date_full); + } + break; + } + } + } // end for loop + } // end function + + function store_to_cache($syear,$smonth,$sday) + { + global $phpgw, $phpgw_info; + + $edate = mktime(23,59,59,$smonth + 1,$sday + 1,$syear); + $eyear = date('Y',$edate); + $emonth = date('m',$edate); + $eday = date('d',$edate); + $cached_event_ids = $this->so->list_events($syear,$smonth,$sday,$eyear,$emonth,$eday); + $cached_event_ids_repeating = $this->so->list_repeated_events($syear,$smonth,$sday,$eyear,$emonth,$eday); + + $c_cached_ids = count($cached_event_ids); + $c_cached_ids_repeating = count($cached_event_ids_repeating); + + $this->cached_events = Array(); + + if($c_cached_ids == 0 && $c_cached_ids_repeating == 0) + { + return; + } + + $this->cached_events = Array(); + if($c_cached_ids) + { + for($i=0;$i<$c_cached_ids;$i++) + { + $event = $this->so->read_entry($cached_event_ids[$i]); + $starttime = mktime($event->start->hour,$event->start->min,$event->start->sec,$event->start->month,$event->start->mday,$event->start->year) - $this->datetime->tz_offset; + $endtime = mktime($event->end->hour,$event->end->min,$event->end->sec,$event->end->month,$event->end->mday,$event->end->year) - $this->datetime->tz_offset; + $this->cached_events[date('Ymd',$starttime)][] = $event; + if($this->cached_events[date('Ymd',$endtime)][count($this->cached_events[date('Ymd',$endtime)]) - 1] != $event) + { + $this->cached_events[date('Ymd',$endtime)][] = $event; + } + } + } + + $this->repeating_events = Array(); + if($c_cached_ids_repeating) + { + for($i=0;$i<$c_cached_ids_repeating;$i++) + { + $this->repeating_events[$i] = $this->so->read_entry($cached_event_ids_repeating[$i]); + } + $edate -= $this->datetime->tz_offset; + for($date=mktime(0,0,0,$smonth,$sday,$syear) - $this->datetime->tz_offset;$date<$edate;$date += (60 * 60 * 24)) + { + $this->check_repeating_events($date); + } + } + } + + function set_week_array($startdate,$cellcolor,$weekly) + { + global $phpgw, $phpgw_info; + + $today = date('Ymd',time()); + for ($j=0;$j<7;$j++) + { + $date = $this->datetime->gmtdate($startdate + ($j * 86400)); + + $holidays = $this->cached_holidays[$date['full']]; + if($weekly) + { + $cellcolor = $phpgw->nextmatchs->alternate_row_color($cellcolor); + } + + $day_image = ''; + if($holidays) + { + $extra = ' bgcolor="'.$this->holiday_color.'"'; + $class = 'minicalhol'; + if ($date['full'] == $today) + { + $day_image = ' background="'.$phpgw->common->image('calendar','mini_day_block.gif').'"'; + } + } + elseif ($date['full'] != $today) + { + $extra = ' bgcolor="'.$cellcolor.'"'; + $class = 'minicalendar'; + } + else + { + $extra = ' bgcolor="'.$phpgw_info['theme']['cal_today'].'"'; + $class = 'minicalendar'; + $day_image = ' background="'.$phpgw->common->image('calendar','mini_day_block.gif').'"'; + } + + if($this->printer_friendly && @$phpgw_info['user']['preferences']['calendar']['print_black_white']) + { + $extra = ''; + } + + $new_event = False; + if(!$this->printer_friendly && $this->check_perms(PHPGW_ACL_ADD)) + { + $new_event = True; + } + $holiday_name = Array(); + if($holidays) + { + for($k=0;$kcached_events[$date['full']]; + $appts = False; + if($rep_events) + { + $appts = True; + } + $week = ''; + if (!$j || ($j && substr($date['full'],6,2) == '01')) + { + $week = 'week ' .(int)((date('z',($startdate+(24*3600*4)))+7)/7); + } + $daily[$date['full']] = Array( + 'extra' => $extra, + 'new_event' => $new_event, + 'holidays' => $holiday_name, + 'appts' => $appts, + 'week' => $week, + 'day_image'=> $day_image, + 'class' => $class + ); + } +// $this->_debug_array($daily); + return $daily; + } + + function _debug_array($data) + { + echo '
UI:'; + _debug_array($data); + } + } +?> diff --git a/calendar/inc/class.socalendar.inc.php b/calendar/inc/class.socalendar.inc.php new file mode 100755 index 0000000000..791eccfb5b --- /dev/null +++ b/calendar/inc/class.socalendar.inc.php @@ -0,0 +1,277 @@ + * + * -------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 2 of the License, or (at your * + * option) any later version. * + \**************************************************************************/ + + /* $Id$ */ + + class socalendar + { + var $cal; + var $rights; + + var $db; + + var $owner; + var $datetime; + + function socalendar() + { + global $phpgw, $rights, $owner; + + $this->db = $phpgw->db; + $this->rights = $rights; + if(isset($owner)) { $this->owner = $owner; } + $this->datetime = CreateObject('phpgwapi.datetime'); + } + + function makeobj() + { + if (!is_object($this->cal)) + { + $this->cal = CreateObject('calendar.socalendar_'); + $this->cal->open('INBOX',intval($this->owner)); + } + return; + } + + function read_entry($id) + { + $this->makeobj(); + if ($this->rights & PHPGW_ACL_READ) + { + return $this->cal->fetch_event($id); + } + else + { + $rtrn = array('No access' => 'No access'); + return $rtrn; + } + } + + function list_events($startYear,$startMonth,$startDay,$endYear='',$endMonth='',$endDay='') + { + $this->makeobj(); + return $this->cal->list_events($startYear,$startMonth,$startDay,$endYear,$endMonth,$endDay,$this->datetime->tz_offset); + } + + function list_repeated_events($syear,$smonth,$sday,$eyear,$emonth,$eday) + { + global $phpgw, $phpgw_info; + + if($phpgw_info['server']['calendar_type'] != 'sql') + { + return Array(); + } + + $starttime = mktime(0,0,0,$smonth,$sday,$syear); + $endtime = mktime(23,59,59,$emonth,$eday,$eyear); + $sql = "AND (phpgw_cal.cal_type='M') " + . 'AND (phpgw_cal_user.cal_login='.$this->owner.' ' + . 'AND (phpgw_cal.datetime >= '.$starttime.') ' + . 'AND (((phpgw_cal_repeats.recur_enddate >= '.$starttime.') AND (phpgw_cal_repeats.recur_enddate <= '.$endtime.')) OR (phpgw_cal_repeats.recur_enddate=0))) ' + . 'ORDER BY phpgw_cal.datetime ASC, phpgw_cal.edatetime ASC, phpgw_cal.priority ASC'; + + $events = $this->get_event_ids(True,$sql); + + return $events; + } + + function read_from_store($startYear,$startMonth,$startDay,$endYear='',$endMonth='',$endDay='') + { + $events = $this->list_events($startYear,$startMonth,$startDay,$endYear,$endMonth,$endDay); + $events_cached = Array(); + for($i=0;$iread_entry($events[$i]); + } + return $events_cached; + } + + function get_event_ids($include_repeats=False, $sql='') + { + $this->makeobj(); + return $this->cal->get_event_ids($include_repeats,$sql); + } + + function add_entry($userid,$fields) + { + $this->makeobj(); + if ($this->rights & PHPGW_ACL_ADD) + { + $this->cal->add($userid,$fields,$fields['access'],$fields['cat_id'],$fields['tid']); + } + return; + } + + function get_lastid() + { + $this->makeobj(); + $entry = $this->cal->read_last_entry(); + $ab_id = $entry[0]['id']; + return $ab_id; + } + + function update_entry($userid,$fields) + { + $this->makeobj(); + if ($this->rights & PHPGW_ACL_EDIT) + { + $this->cal->update($fields['ab_id'],$userid,$fields,$fields['access'],$fields['cat_id']); + } + return; + } + + function delete_entry($ab_id) + { + $this->makeobj(); + if ($this->rights & PHPGW_ACL_DELETE) + { + $this->cal->delete($ab_id); + } + return; + } + + /* Begin Holiday functions */ + function save_holiday($holiday) + { + if(isset($holiday['hol_id']) && $holiday['hol_id']) + { +// echo "Updating LOCALE='".$holiday['locale']."' NAME='".$holiday['name']."' extra=(".$holiday['mday'].'/'.$holiday['month_num'].'/'.$holiday['occurence'].'/'.$holiday['dow'].'/'.$holiday['observance_rule'].")
\n"; + $sql = "UPDATE phpgw_cal_holidays SET name='".$holiday['name']."', mday=".$holiday['mday'].', month_num='.$holiday['month_num'].', occurence='.$holiday['occurence'].', dow='.$holiday['dow'].', observance_rule='.intval($holiday['observance_rule']).' WHERE hol_id='.$holiday['hol_id']; + } + else + { +// echo "Inserting LOCALE='".$holiday['locale']."' NAME='".$holiday['name']."' extra=(".$holiday['mday'].'/'.$holiday['month_num'].'/'.$holiday['occurence'].'/'.$holiday['dow'].'/'.$holiday['observance_rule'].")
\n"; + $sql = 'INSERT INTO phpgw_cal_holidays(locale,name,mday,month_num,occurence,dow,observance_rule) ' + . "VALUES('".strtoupper($holiday['locale'])."','".$holiday['name']."',".$holiday['mday'].','.$holiday['month_num'].','.$holiday['occurence'].','.$holiday['dow'].','.intval($holiday['observance_rule']).")"; + } + $this->db->query($sql,__LINE__,__FILE__); + } + + function read_holidays($sql) + { + global $phpgw; + + $this->db->query($sql,__LINE__,__FILE__); + $holidays = Array(); + while($this->db->next_record()) + { + $holidays[] = Array( + 'index' => $this->db->f('hol_id'), + 'locale' => $this->db->f('locale'), + 'name' => $phpgw->strip_html($this->db->f('name')), + 'day' => intval($this->db->f('mday')), + 'month' => intval($this->db->f('month_num')), + 'occurence' => intval($this->db->f('occurence')), + 'dow' => intval($this->db->f('dow')), + 'observance_rule' => $this->db->f('observance_rule') + ); + } + + return $holidays; + } + + /* Private functions */ + /* Holiday */ + function count_of_holidays($locale) + { + $sql = "SELECT count(*) FROM phpgw_cal_holidays WHERE locale='".$locale."'"; + $this->db->query($sql,__LINE__,__FILE__); + $this->db->next_record(); + return $this->db->f(0); + } + /* End Holiday functions */ + + /* Begin mcal equiv functions */ + function get_cached_event() + { + return $this->cal->event; + } + + function add_attribute($var,$value) + { + $this->cal->add_attribute($var,$value); + } + + function event_init() + { + $this->makeobj(); + $this->cal->event_init(); + } + + function set_start($year,$month,$day=0,$hour=0,$min=0,$sec=0) + { + $this->cal->set_start($year,$month,$day,$hour,$min,$sec); + } + + function set_end($year,$month,$day=0,$hour=0,$min=0,$sec=0) + { + $this->cal->set_end($year,$month,$day,$hour,$min,$sec); + } + + function set_title($title='') + { + $this->cal->set_title($title); + } + + function set_description($description='') + { + $this->cal->set_description($description); + } + + function set_class($class) + { + $this->cal->set_class($class); + } + + function set_category($category='') + { + $this->cal->set_category($category); + } + + function set_alarm($alarm) + { + $this->cal->set_alarm($alarm); + } + + function set_recur_none() + { + $this->cal->set_recur_none(); + } + + function set_recur_daily($year,$month,$day,$interval) + { + $this->cal->set_recur_daily($year,$month,$day,$interval); + } + + function set_recur_weekly($year,$month,$day,$interval,$weekdays) + { + $this->cal->set_recur_weekly($year,$month,$day,$interval,$weekdays); + } + + function set_recur_monthly_mday($year,$month,$day,$interval) + { + $this->cal->set_recur_monthly_mday($year,$month,$day,$interval); + } + + function set_recur_monthly_wday($year,$month,$day,$interval) + { + $this->cal->set_recur_monthly_wday($year,$month,$day,$interval); + } + + function set_recur_yearly($year,$month,$day,$interval) + { + $this->cal->set_recur_yearly($year,$month,$day,$interval); + } + + /* End mcal equiv functions */ + } +?> diff --git a/calendar/inc/class.socalendar_.inc.php b/calendar/inc/class.socalendar_.inc.php new file mode 100755 index 0000000000..a88ac7fcfb --- /dev/null +++ b/calendar/inc/class.socalendar_.inc.php @@ -0,0 +1,29 @@ + * + * http://www.radix.net/~cknudsen * + * Modified by Mark Peters * + * -------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 2 of the License, or (at your * + * option) any later version. * + \**************************************************************************/ + + /* $Id$ */ + + if(@$phpgw_info['server']['calendar_type'] == 'mcal' && + extension_loaded('mcal') == False) + { + $phpgw_info['server']['calendar_type'] = 'sql'; + } +// This will be elminated when ical is fully implemented + else + { + $phpgw_info['server']['calendar_type'] = 'sql'; + } + include(PHPGW_INCLUDE_ROOT.'/calendar/inc/class.socalendar__.inc.php'); + include(PHPGW_INCLUDE_ROOT.'/calendar/inc/class.socalendar_'.$phpgw_info['server']['calendar_type'].'.inc.php'); +?> diff --git a/calendar/inc/class.socalendar__.inc.php b/calendar/inc/class.socalendar__.inc.php new file mode 100755 index 0000000000..6c623dc970 --- /dev/null +++ b/calendar/inc/class.socalendar__.inc.php @@ -0,0 +1,415 @@ + * + * http://www.radix.net/~cknudsen * + * Modified by Mark Peters * + * -------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 2 of the License, or (at your * + * option) any later version. * + \**************************************************************************/ + + /* $Id$ */ + +if (@$phpgw_info['flags']['included_classes']['socalendar__']) +{ + return; +} + +$phpgw_info['flags']['included_classes']['socalendar__'] = True; + +include(PHPGW_SERVER_ROOT.'/calendar/setup/setup.inc.php'); + +if(extension_loaded('mcal') == False) +{ + define('MCAL_RECUR_NONE',0); + define('MCAL_RECUR_DAILY',1); + define('MCAL_RECUR_WEEKLY',2); + define('MCAL_RECUR_MONTHLY_MDAY',3); + define('MCAL_RECUR_MONTHLY_WDAY',4); + define('MCAL_RECUR_YEARLY',5); + + define('MCAL_M_SUNDAY',1); + define('MCAL_M_MONDAY',2); + define('MCAL_M_TUESDAY',4); + define('MCAL_M_WEDNESDAY',8); + define('MCAL_M_THURSDAY',16); + define('MCAL_M_FRIDAY',32); + define('MCAL_M_SATURDAY',64); + + define('MCAL_M_WEEKDAYS',63); + define('MCAL_M_WEEKEND',65); + define('MCAL_M_ALLDAYS',127); +} + +define('MSG_DELETED',0); +define('MSG_MODIFIED',1); +define('MSG_ADDED',2); +define('MSG_REJECTED',3); +define('MSG_TENTATIVE',4); +define('MSG_ACCEPTED',5); + +define('REJECTED',0); +define('NO_RESPONSE',1); +define('TENTATIVE',2); +define('ACCEPTED',3); + +class socalendar__ +{ + var $event; + var $stream; + var $user; + var $users_status; + var $modified; + var $deleted; + var $added; + var $datetime; + + function socalendar__() + { + $this->datetime = CreateObject('phpgwapi.datetime'); + } + + function send_update($msg_type,$participants,$old_event=False,$new_event=False) + { + global $phpgw, $phpgw_info; + + $phpgw_info['user']['preferences'] = $phpgw->common->create_emailpreferences($phpgw_info['user']['preferences']); + $sender = $phpgw_info['user']['preferences']['email']['address']; + + $temp_tz_offset = $phpgw_info['user']['preferences']['common']['tz_offset']; + $temp_timeformat = $phpgw_info['user']['preferences']['common']['timeformat']; + $temp_dateformat = $phpgw_info['user']['preferences']['common']['dateformat']; + + $tz_offset = ((60 * 60) * intval($temp_tz_offset)); + + if($old_event != False) + { + $t_old_start_time = mktime($old_event->start->hour,$old_event->start->min,$old_event->start->sec,$old_event->start->month,$old_event->start->mday,$old_event->start->year); + if($t_old_start_time < (time() - 86400)) + { + return False; + } + } + + $temp_user = $phpgw_info['user']; + + if((is_int($this->user) && $this->user != $temp_user['account_id']) || + (is_string($this->user) && $this->user != $temp_user['account_lid'])) + { + if(is_string($this->user)) + { + $user = $phpgw->accounts->name2id($this->user); + } + elseif(is_int($this->user)) + { + $user = $this->user; + } + + $accounts = CreateObject('phpgwapi.accounts',$user); + $phpgw_info['user'] = $accounts->read_repository(); + + $pref = CreateObject('phpgwapi.preferences',$user); + $phpgw_info['user']['preferences'] = $pref->read_repository(); + } + else + { + $user = $phpgw_info['user']['account_id']; + } + + $phpgw_info['user']['preferences'] = $phpgw->common->create_emailpreferences($phpgw_info['user']['preferences'],$user); + + $send = CreateObject('phpgwapi.send'); + + switch($msg_type) + { + case MSG_DELETED: + $action = 'Deleted'; + $event_id = $old_event->id; + $msgtype = '"calendar";'; + break; + case MSG_MODIFIED: + $action = 'Modified'; + $event_id = $old_event->id; + $msgtype = '"calendar"; Version="'.$phpgw_info['server']['versions']['calendar'].'"; Id="'.$new_event->id.'"'; + break; + case MSG_ADDED: + $action = 'Added'; + $event_id = $old_event->id; + $msgtype = '"calendar"; Version="'.$phpgw_info['server']['versions']['calendar'].'"; Id="'.$new_event->id.'"'; + break; + case MSG_REJECTED: + $action = 'Rejected'; + $event_id = $old_event->id; + $msgtype = '"calendar";'; + break; + case MSG_TENTATIVE: + $action = 'Tentative'; + $event_id = $old_event->id; + $msgtype = '"calendar";'; + break; + case MSG_ACCEPTED: + $action = 'Tentative'; + $event_id = $old_event->id; + $msgtype = '"calendar";'; + break; + } + + if($old_event != False) + { + $old_event_datetime = $t_old_start_time - $this->datetime->tz_offset; + } + + if($new_event != False) + { + $new_event_datetime = mktime($new_event->start->hour,$new_event->start->min,$new_event->start->sec,$new_event->start->month,$new_event->start->mday,$new_event->start->year) - $this->datetime->tz_offset; + } + + while(list($userid,$statusid) = each($participants)) + { + if(intval($userid) != $phpgw_info['user']['account_id']) + { +// echo "Msg Type = ".$msg_type."
\n"; +// echo "userid = ".$userid."
\n"; + $preferences = CreateObject('phpgwapi.preferences',intval($userid)); + $part_prefs = $preferences->read_repository(); + if(!isset($part_prefs['calendar']['send_updates']) || !$part_prefs['calendar']['send_updates']) + { + continue; + } + $part_prefs = $phpgw->common->create_emailpreferences($part_prefs,intval($userid)); + $to = $part_prefs['email']['address']; +// echo "Email being sent to: ".$to."
\n"; + + $phpgw_info['user']['preferences']['common']['tz_offset'] = $part_prefs['common']['tz_offset']; + $phpgw_info['user']['preferences']['common']['timeformat'] = $part_prefs['common']['timeformat']; + $phpgw_info['user']['preferences']['common']['dateformat'] = $part_prefs['common']['dateformat']; + + $new_tz_offset = ((60 * 60) * intval($phpgw_info['user']['preferences']['common']['tz_offset'])); + + if($old_event != False) + { + $old_event_date = $phpgw->common->show_date($old_event_datetime); + } + + if($new_event != False) + { + $new_event_date = $phpgw->common->show_date($new_event_datetime); + } + + switch($msg_type) + { + case MSG_DELETED: + $action_date = $old_event_date; + $body = 'Your meeting scehduled for '.$old_event_date.' has been canceled'; + break; + case MSG_MODIFIED: + $action_date = $new_event_date; + $body = 'Your meeting that had been scheduled for '.$old_event_date.' has been rescheduled to '.$new_event_date; + break; + case MSG_ADDED: + $action_date = $new_event_date; + $body = 'You have a meeting scheduled for '.$new_event_date; + break; + case MSG_REJECTED: + case MSG_TENTATIVE: + case MSG_ACCEPTED: + $action_date = $old_event_date; + $body = 'On '.$phpgw->common->show_date(time() - $new_tz_offset).' '.$phpgw->common->grab_owner_name($phpgw_info['user']['account_id']).' '.$action.' your meeting request for '.$old_event_date; + break; + } + $subject = 'Calendar Event ('.$action.') #'.$event_id.': '.$action_date.' (L)'; + $returncode = $send->msg('email',$to,$subject,$body,$msgtype,'','','',$sender); + } + } + unset($send); + + if((is_int($this->user) && $this->user != $temp_user['account_id']) || + (is_string($this->user) && $this->user != $temp_user['account_lid'])) + { + $phpgw_info['user'] = $temp_user; + } + + $phpgw_info['user']['preferences']['common']['tz_offset'] = $temp_tz_offset; + $phpgw_info['user']['preferences']['common']['timeformat'] = $temp_timeformat; + $phpgw_info['user']['preferences']['common']['dateformat'] = $temp_dateformat; + } + + function prepare_recipients(&$new_event,$old_event) + { + // Find modified and deleted users..... + while(list($old_userid,$old_status) = each($old_event->participants)) + { + if(isset($new_event->participants[$old_userid])) + { +// echo "Modifying event for user ".$old_userid."
\n"; + $this->modified[intval($old_userid)] = $new_status; + } + else + { +// echo "Deleting user ".$old_userid." from the event
\n"; + $this->deleted[intval($old_userid)] = $old_status; + } + } + // Find new users..... + while(list($new_userid,$new_status) = each($new_event->participants)) + { + if(!isset($old_event->participants[$new_userid])) + { +// echo "Adding event for user ".$new_userid."
\n"; + $this->added[$new_userid] = 'U'; + $new_event->participants[$new_userid] = 'U'; + } + } + + if(count($this->added) > 0 || count($this->modified) > 0 || count($this->deleted) > 0) + { + if(count($this->added) > 0) + { + $this->send_update(MSG_ADDED,$this->added,'',$new_event); + } + if(count($this->modified) > 0) + { + $this->send_update(MSG_MODIFIED,$this->modified,$old_event,$new_event); + } + if(count($this->deleted) > 0) + { + $this->send_update(MSG_DELETED,$this->deleted,$old_event); + } + } + } + + function event_init() + { + CreateObject('calendar.calendar_item'); + $this->event = new calendar_item; + $this->event->start = new calendar_time; + $this->event->end = new calendar_time; + $this->event->mod = new calendar_time; + $this->event->recur_enddate = new calendar_time; + $this->add_attribute('owner',intval($this->user)); + } + + function set_category($category='') + { + $this->event->category = $category; + } + + function set_title($title='') + { + $this->event->title = $title; + } + + function set_description($description='') + { + $this->event->description = $description; + } + + function set_start($year,$month,$day=0,$hour=0,$min=0,$sec=0) + { + $this->event->start->year = intval($year); + $this->event->start->month = intval($month); + $this->event->start->mday = intval($day); + $this->event->start->hour = intval($hour); + $this->event->start->min = intval($min); + $this->event->start->sec = intval($sec); + $this->event->start->alarm = 0; + } + + function set_end($year,$month,$day=0,$hour=0,$min=0,$sec=0) + { + $this->event->end->year = intval($year); + $this->event->end->month = intval($month); + $this->event->end->mday = intval($day); + $this->event->end->hour = intval($hour); + $this->event->end->min = intval($min); + $this->event->end->sec = intval($sec); + $this->event->end->alarm = 0; + } + + function set_alarm($alarm) + { + $this->event->alarm = intval($alarm); + } + + function set_class($class) + { + $this->event->public = $class; + } + + function set_common_recur($year,$month,$day,$interval) + { + $this->event->recur_interval = intval($interval); + if(intval($day) == 0 && intval($month) == 0 && intval($year) == 0) + { + $this->event->recur_enddate->year = 0; + $this->event->recur_enddate->month = 0; + $this->event->recur_enddate->mday = 0; + } + else + { + $this->event->recur_enddate->year = intval($year); + $this->event->recur_enddate->month = intval($month); + $this->event->recur_enddate->mday = intval($day); + } + $this->event->recur_enddate->hour = 0; + $this->event->recur_enddate->min = 0; + $this->event->recur_enddate->sec = 0; + $this->event->recur_enddate->alarm = 0; + $this->event->recur_data = 0; + } + + function set_recur_none() + { + $this->set_common_recur(0,0,0,0); + $this->event->recur_type = MCAL_RECUR_NONE; + } + + function set_recur_daily($year,$month,$day,$interval) + { + $this->set_common_recur(intval($year),intval($month),intval($day),$interval); + $this->event->recur_type = MCAL_RECUR_DAILY; + } + + function set_recur_weekly($year,$month,$day,$interval,$weekdays) + { + $this->set_common_recur(intval($year),intval($month),intval($day),$interval); + $this->event->recur_type = MCAL_RECUR_WEEKLY; + $this->event->recur_data = intval($weekdays); + } + + function set_recur_monthly_mday($year,$month,$day,$interval) + { + $this->set_common_recur(intval($year),intval($month),intval($day),$interval); + $this->event->recur_type = MCAL_RECUR_MONTHLY_MDAY; + } + + function set_recur_monthly_wday($year,$month,$day,$interval) + { + $this->set_common_recur(intval($year),intval($month),intval($day),$interval); + $this->event->recur_type = MCAL_RECUR_MONTHLY_WDAY; + } + + function set_recur_yearly($year,$month,$day,$interval) + { + $this->set_common_recur(intval($year),intval($month),intval($day),$interval); + $this->event->recur_type = MCAL_RECUR_YEARLY; + } + + function fetch_current_stream_event() + { + return $this->fetch_event($this->event->id); + } + + function add_attribute($attribute,$value,$element='') + { + if(is_array($value)) + { + reset($value); + } + eval("\$this->event->".$attribute." = ".$value.";"); + } +} diff --git a/calendar/inc/class.socalendar_sql.inc.php b/calendar/inc/class.socalendar_sql.inc.php new file mode 100755 index 0000000000..c4897063e3 --- /dev/null +++ b/calendar/inc/class.socalendar_sql.inc.php @@ -0,0 +1,599 @@ + * + * http://www.radix.net/~cknudsen * + * Modified by Mark Peters * + * -------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 2 of the License, or (at your * + * option) any later version. * + \**************************************************************************/ + + /* $Id$ */ + +if (@$phpgw_info['flags']['included_classes']['socalendar_']) +{ + return; +} + +$phpgw_info['flags']['included_classes']['socalendar_'] = True; + +class socalendar_ extends socalendar__ +{ + var $deleted_events = Array(); + + var $cal_event; + var $today = Array('raw','day','month','year','full','dow','dm','bd'); + + function open($calendar='',$user='',$passwd='',$options='') + { + global $phpgw, $phpgw_info; + + if($user=='') + { + settype($user,'integer'); + $user = $phpgw_info['user']['account_id']; + } + elseif(is_int($user)) + { + $this->user = $user; + } + elseif(is_string($user)) + { + $this->user = $phpgw->accounts->name2id($user); + } + + $this->stream = $phpgw->db; + return $this->stream; + } + + function popen($calendar='',$user='',$passwd='',$options='') + { + return $this->open($calendar,$user,$passwd,$options); + } + + function reopen($calendar,$options='') + { + return $this->stream; + } + + function close($options='') + { + return True; + } + + function create_calendar($calendar='') + { + return $calendar; + } + + function rename_calendar($old_name='',$new_name='') + { + return $new_name; + } + + function delete_calendar($calendar='') + { + $this->stream->query('SELECT cal_id FROM phpgw_cal WHERE owner='.intval($calendar),__LINE__,__FILE__); + if($this->stream->num_rows()) + { + while($this->stream->next_record()) + { + $this->delete_event(intval($this->stream->f('cal_id'))); + } + $this->expunge(); + } + $this->stream->lock(array('phpgw_cal_user')); + $this->stream->query('DELETE FROM phpgw_cal_user WHERE cal_login='.intval($calendar),__LINE__,__FILE__); + $this->stream->unlock(); + + return $calendar; + } + + function fetch_event($event_id,$options='') + { + global $phpgw; + + if(!isset($this->stream)) + { + return False; + } + + $this->stream->lock(array('phpgw_cal','phpgw_cal_user','phpgw_cal_repeats')); + + $this->stream->query('SELECT * FROM phpgw_cal WHERE cal_id='.$event_id,__LINE__,__FILE__); + + if($this->stream->num_rows() > 0) + { + $this->event_init(); + + $this->stream->next_record(); + // Load the calendar event data from the db into $event structure + // Use http://www.php.net/manual/en/function.mcal-fetch-event.php as the reference + $this->add_attribute('owner',intval($this->stream->f('owner'))); + $this->add_attribute('id',intval($this->stream->f('cal_id'))); + $this->set_class(intval($this->stream->f('is_public'))); + $this->set_category(intval($this->stream->f('category'))); + $this->set_title($phpgw->strip_html($this->stream->f('title'))); + $this->set_description($phpgw->strip_html($this->stream->f('description'))); + + // This is the preferred method once everything is normalized... + //$this->event->alarm = intval($this->stream->f('alarm')); + // But until then, do it this way... + //Legacy Support (New) + $this->event->alarm = 0; + + $this->add_attribute('datetime',intval($this->stream->f('datetime'))); + $datetime = $this->datetime->localdates($this->stream->f('datetime')); + $this->set_start($datetime['year'],$datetime['month'],$datetime['day'],$datetime['hour'],$datetime['minute'],$datetime['second']); + + $datetime = $this->datetime->localdates($this->stream->f('mdatetime')); + $this->event->mod->year = $datetime['year']; + $this->event->mod->month = $datetime['month']; + $this->event->mod->mday = $datetime['day']; + $this->event->mod->hour = $datetime['hour']; + $this->event->mod->min = $datetime['minute']; + $this->event->mod->sec = $datetime['second']; + $this->event->mod->alarm = 0; + + $this->add_attribute('edatetime',intval($this->stream->f('edatetime'))); + $datetime = $this->datetime->localdates($this->stream->f('edatetime')); + $this->set_end($datetime['year'],$datetime['month'],$datetime['day'],$datetime['hour'],$datetime['minute'],$datetime['second']); + + //Legacy Support + $this->add_attribute('priority',intval($this->stream->f('priority'))); + if($this->stream->f('cal_group') || $this->stream->f('groups') != 'NULL') + { + $groups = explode(',',$this->stream->f('groups')); + for($j=1;$jevent->groups[] = $groups[$j]; + } + } + + $this->stream->query('SELECT * FROM phpgw_cal_repeats WHERE cal_id='.$event_id,__LINE__,__FILE__); + if($this->stream->num_rows()) + { + $this->stream->next_record(); + + $this->event->recur_type = intval($this->stream->f('recur_type')); + $this->event->recur_interval = intval($this->stream->f('recur_interval')); + $enddate = $this->stream->f('recur_enddate'); + if($enddate != 0 && $enddate != Null) + { + $datetime = $this->datetime->localdates($enddate); + $this->event->recur_enddate->year = $datetime['year']; + $this->event->recur_enddate->month = $datetime['month']; + $this->event->recur_enddate->mday = $datetime['day']; + $this->event->recur_enddate->hour = $datetime['hour']; + $this->event->recur_enddate->min = $datetime['minute']; + $this->event->recur_enddate->sec = $datetime['second']; + $this->event->recur_enddate->alarm = 0; + } + else + { + $this->event->recur_enddate->year = 0; + $this->event->recur_enddate->month = 0; + $this->event->recur_enddate->mday = 0; + $this->event->recur_enddate->hour = 0; + $this->event->recur_enddate->min = 0; + $this->event->recur_enddate->sec = 0; + $this->event->recur_enddate->alarm = 0; + } +// echo 'Event ID#'.$this->event->id.' : Enddate = '.$enddate."
\n"; + $this->event->recur_data = $this->stream->f('recur_data'); + } + + //Legacy Support + $this->stream->query('SELECT * FROM phpgw_cal_user WHERE cal_id='.$event_id,__LINE__,__FILE__); + if($this->stream->num_rows()) + { + while($this->stream->next_record()) + { + if(intval($this->stream->f('cal_login')) == intval($this->user)) + { + $this->event->users_status = $this->stream->f('cal_status'); + } +// $this->event->participants[$this->stream->f('cal_login')] = $this->stream->f('cal_status'); +// $this->add_attribute('participants',$this->stream->f('cal_status'),intval($this->stream->f('cal_login'))); + $this->add_attribute('participants['.intval($this->stream->f('cal_login')).']',$this->stream->f('cal_status')); + } + } + } + else + { + $this->event = False; + } + + $this->stream->unlock(); + + return $this->event; + } + + function list_events($startYear,$startMonth,$startDay,$endYear='',$endMonth='',$endDay='',$tz_offset) + { + if(!isset($this->stream)) + { + return False; + } + + $datetime = mktime(0,0,0,$startMonth,$startDay,$startYear) - $tz_offset; + $user_where = ' AND (phpgw_cal_user.cal_login = '.$this->user.') '; + $startDate = 'AND (phpgw_cal.datetime >= '.$datetime.') '; + + if($endYear != '' && $endMonth != '' && $endDay != '') + { + $edatetime = mktime(23,59,59,intval($endMonth),intval($endDay),intval($endYear)) - $tz_offset; + $endDate = 'AND (phpgw_cal.edatetime <= '.$edatetime.') '; + } + else + { + $endDate = ''; + } + + $order_by = 'ORDER BY phpgw_cal.datetime ASC, phpgw_cal.edatetime ASC, phpgw_cal.priority ASC'; + return $this->get_event_ids(False,$user_where.$startDate.$endDate.$order_by); + } + + function append_event() + { + $this->save_event($this->event); + $this->send_update(MSG_ADDED,$this->event->participants,'',$this->event); + return $this->event->id; + } + + function store_event() + { + if($this->event->id != 0) + { + $new_event = $this->event; + $old_event = $this->fetch_event($new_event->id); + $this->prepare_recipients($new_event,$old_event); + $this->event = $new_event; + } + else + { + while(list($key,$value) = each($this->event->participants)) + { + $this->add_attribute('participants['.intval($key).']','U'); + } + $this->send_update(MSG_ADDED,$this->event->participants,'',$this->event); + } + return $this->save_event($this->event); + } + + function delete_event($event_id) + { + $this->deleted_events[] = $event_id; + } + + function snooze($event_id) + { + //Turn off an alarm for an event + //Returns true. + } + + function list_alarms($begin_year='',$begin_month='',$begin_day='',$end_year='',$end_month='',$end_day='') + { + //Return a list of events that has an alarm triggered at the given datetime + //Returns an array of event ID's + } + + // The function definition doesn't look correct... + // Need more information for this function + function next_recurrence($weekstart,$next) + { +// return next_recurrence (int stream, int weekstart, array next); + } + + function expunge() + { + if(count($this->deleted_events) <= 0) + { + return 1; + } + $this_event = $this->event; + $locks = Array( + 'phpgw_cal', + 'phpgw_cal_user', + 'phpgw_cal_repeats' + ); + $this->stream->lock($locks); + for($i=0;$ideleted_events);$i++) + { + $event_id = $this->deleted_events[$i]; + + $event = $this->fetch_event($event_id); + $this->send_update(MSG_DELETED,$event->participants,$event); + + for($k=0;$kstream->query('DELETE FROM '.$locks[$k].' WHERE cal_id='.$event_id,__LINE__,__FILE__); + } + } + $this->stream->unlock(); + $this->event = $this_event; + return 1; + } + + /***************** Local functions for SQL based Calendar *****************/ + + function get_event_ids($search_repeats=False,$extra='') + { + if($search_repeats == True) + { + $repeats_from = ', phpgw_cal_repeats '; + $repeats_where = 'AND (phpgw_cal_repeats.cal_id = phpgw_cal.cal_id) '; + } + else + { + $repeats_from = ' '; + $repeats_where = ''; + } + + $sql = 'SELECT DISTINCT phpgw_cal.cal_id,' + . 'phpgw_cal.datetime,phpgw_cal.edatetime,' + . 'phpgw_cal.priority ' + . 'FROM phpgw_cal, phpgw_cal_user' + . $repeats_from + . 'WHERE (phpgw_cal_user.cal_id = phpgw_cal.cal_id) ' + . $repeats_where . $extra; + $this->stream->query($sql,__LINE__,__FILE__); + + $retval = Array(); + if($this->stream->num_rows() == 0) + { + return $retval; + } + + while($this->stream->next_record()) + { + $retval[] = intval($this->stream->f('cal_id')); + } + return $retval; + } + + function save_event(&$event) + { + global $phpgw_info; + + $locks = Array( + 'phpgw_cal', + 'phpgw_cal_user', + 'phpgw_cal_repeats' + ); + $this->stream->lock($locks); + if($event->id == 0) + { + $temp_name = tempnam($phpgw_info['server']['temp_dir'],'cal'); + $this->stream->query('INSERT INTO phpgw_cal(title,owner,priority,is_public) ' + . "values('".$temp_name."',".$event->owner.",".$event->priority.",".$event->public.")"); + $this->stream->query("SELECT cal_id FROM phpgw_cal WHERE title='".$temp_name."'"); + $this->stream->next_record(); + $event->id = $this->stream->f('cal_id'); + } + + $date = mktime($event->start->hour,$event->start->min,$event->start->sec,$event->start->month,$event->start->mday,$event->start->year) - $this->datetime->tz_offset; + $enddate = mktime($event->end->hour,$event->end->min,$event->end->sec,$event->end->month,$event->end->mday,$event->end->year) - $this->datetime->tz_offset; + $today = time() - $this->datetime->tz_offset; +// $today = time(); + + if($event->recur_type != MCAL_RECUR_NONE) + { + $type = 'M'; + } + else + { + $type = 'E'; + } + + $cat = ''; + if($event->category != 0) + { + $cat = 'category='.$event->category.', '; + } + + $sql = 'UPDATE phpgw_cal SET ' + . 'owner='.$event->owner.', ' + . 'datetime='.$date.', ' + . 'mdatetime='.$today.', ' + . 'edatetime='.$enddate.', ' + . 'priority='.$event->priority.', ' + . $cat + . "cal_type='".$type."', " + . 'is_public='.$event->public.', ' + . "title='".addslashes($event->title)."', " + . "description='".addslashes($event->description)."' " + . 'WHERE cal_id='.$event->id; + + $this->stream->query($sql,__LINE__,__FILE__); + + $this->stream->query('DELETE FROM phpgw_cal_user WHERE cal_id='.$event->id,__LINE__,__FILE__); + + reset($event->participants); + while (list($key,$value) = each($event->participants)) + { + if(intval($key) == intval($this->user)) + { + $value = 'A'; + } + $this->stream->query('INSERT INTO phpgw_cal_user(cal_id,cal_login,cal_status) ' + . 'VALUES('.$event->id.','.intval($key).",'".$value."')",__LINE__,__FILE__); + } + + if($event->recur_type != MCAL_RECUR_NONE) + { + if($event->recur_enddate->month != 0 && $event->recur_enddate->mday != 0 && $event->recur_enddate->year != 0) + { + $end = mktime($event->recur_enddate->hour,$event->recur_enddate->min,$event->recur_enddate->sec,$event->recur_enddate->month,$event->recur_enddate->mday,$event->recur_enddate->year) - $this->datetime->tz_offset; + } + else + { + $end = 0; + } + + $this->stream->query('SELECT count(cal_id) FROM phpgw_cal_repeats WHERE cal_id='.$event->id,__LINE__,__FILE__); + $this->stream->next_record(); + $num_rows = $this->stream->f(0); + if($num_rows == 0) + { + $this->stream->query('INSERT INTO phpgw_cal_repeats(cal_id,recur_type,recur_enddate,recur_data,recur_interval) ' + .'VALUES('.$event->id.','.$event->recur_type.','.$end.','.$event->recur_data.','.$event->recur_interval.')',__LINE__,__FILE__); + } + else + { + $this->stream->query('UPDATE phpgw_cal_repeats ' + .'SET recur_type='.$event->recur_type.', ' + .'recur_enddate='.$end.', ' + .'recur_data='.$event->recur_data.', recur_interval='.$event->recur_interval.' ' + .'WHERE cal_id='.$event->id,__LINE__,__FILE__); + } + } + else + { + $this->stream->query('DELETE FROM phpgw_cal_repeats WHERE cal_id='.$event->id,__LINE__,__FILE__); + } + + $this->stream->unlock(); + return True; + } + + function set_status($id,$owner,$status) + { + $status_code_short = Array( + REJECTED => 'R', + NO_RESPONSE => 'U', + TENTATIVE => 'T', + ACCEPTED => 'A' + ); + $temp_event = $this->event; + $old_event = $this->fetch_event($id); + switch($status) + { + case REJECTED: + $this->send_update(MSG_REJECTED,$old_event->participants,$old_event); + $this->stream->query("DELETE FROM phpgw_cal_user WHERE cal_id=".$id." AND cal_login=".$owner,__LINE__,__FILE__); + break; + case TENTATIVE: + $this->send_update(MSG_TENTATIVE,$old_event->participants,$old_event); + $this->stream->query("UPDATE phpgw_cal_user SET cal_status='".$status_code_short[$status]."' WHERE cal_id=".$id." AND cal_login=".$owner,__LINE__,__FILE__); + break; + case ACCEPTED: + $this->send_update(MSG_ACCEPTED,$old_event->participants,$old_event); + $this->stream->query("UPDATE phpgw_cal_user SET cal_status='".$status_code_short[$status]."' WHERE cal_id=".$id." AND cal_login=".$owner,__LINE__,__FILE__); + break; + } + $this->event = $temp_event; + return True; + } + +// End of ICal style support....... + + function group_search($owner=0) + { + global $phpgw, $phpgw_info; + + $owner = $owner==$phpgw_info['user']['account_id']?0:$owner; + $groups = substr($phpgw->common->sql_search('phpgw_cal.groups',intval($owner)),4); + if (!$groups) + { + return ''; + } + else + { + return "(phpgw_cal.is_public=2 AND (". $groups .')) '; + } + } + + function normalizeminutes(&$minutes) + { + $hour = 0; + $min = intval($minutes); + if($min >= 60) + { + $hour += $min / 60; + $min %= 60; + } + settype($minutes,'integer'); + $minutes = $min; + return $hour; + } + + function splittime_($time) + { + global $phpgw_info; + + $temp = array('hour','minute','second','ampm'); + $time = strrev($time); + $second = (int)strrev(substr($time,0,2)); + $minute = (int)strrev(substr($time,2,2)); + $hour = (int)strrev(substr($time,4)); + $temp['second'] = (int)$second; + $temp['minute'] = (int)$minute; + $temp['hour'] = (int)$hour; + $temp['ampm'] = ' '; + + return $temp; + } + + function splittime($time,$follow_24_rule=True) + { + global $phpgw_info; + + $temp = array('hour','minute','second','ampm'); + $time = strrev($time); + $second = intval(strrev(substr($time,0,2))); + $minute = intval(strrev(substr($time,2,2))); + $hour = intval(strrev(substr($time,4))); + $hour += $this->normalizeminutes(&$minute); + $temp['second'] = $second; + $temp['minute'] = $minute; + $temp['hour'] = $hour; + $temp['ampm'] = ' '; + if($follow_24_rule == True) + { + if ($phpgw_info['user']['preferences']['common']['timeformat'] == '24') + { + return $temp; + } + + $temp['ampm'] = 'am'; + + if ((int)$temp['hour'] > 12) + { + $temp['hour'] = (int)((int)$temp['hour'] - 12); + $temp['ampm'] = 'pm'; + } + elseif ((int)$temp['hour'] == 12) + { + $temp['ampm'] = 'pm'; + } + } + return $temp; + } + + function date_to_epoch($d) + { + return $this->localdates(mktime(0,0,0,intval(substr($d,4,2)),intval(substr($d,6,2)),intval(substr($d,0,4)))); + } + + function build_time_for_display($fixed_time) + { + global $phpgw_info; + + $time = $this->splittime($fixed_time); + $str = ''; + $str .= $time['hour'].':'.((int)$time['minute']<=9?'0':'').$time['minute']; + + if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12') + { + $str .= ' ' . $time['ampm']; + } + + return $str; + } +} +?> diff --git a/calendar/inc/class.uicalendar.inc.php b/calendar/inc/class.uicalendar.inc.php new file mode 100755 index 0000000000..61e96fd914 --- /dev/null +++ b/calendar/inc/class.uicalendar.inc.php @@ -0,0 +1,1802 @@ + * + * http://www.radix.net/~cknudsen * + * Modified by Mark Peters * + * -------------------------------------------- * + * This program is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 2 of the License, or (at your * + * option) any later version. * + \**************************************************************************/ + + /* $Id$ */ + + class uicalendar + { + var $template; + var $template_dir; + var $printer_friendly; + + var $owner; + +// var $contacts; + var $bo; + var $cat; + var $prefs; + + var $holidays; + var $holiday_color; + + var $debug = False; + + var $filter; + var $cat_id; + + var $public_functions = array( + 'mini_calendar' => True, + 'index' => True, + 'month' => True, + 'week' => True, + 'year' => True, + 'view' => True, + 'add' => True, + 'edit' => True, + 'delete' => True + ); + + function uicalendar() + { + global $phpgw, $phpgw_info, $friendly; + + $phpgw->browser = CreateObject('phpgwapi.browser'); + + if($friendly == 1) + { + $this->printer_friendly = True; + } + else + { + $this->printer_friendly = False; + } + + $this->bo = CreateObject('calendar.bocalendar',True); + if(!isset($this->bo->year)) + { + $this->bo->year = date('Y',time()); + } + if(!isset($this->bo->month)) + { + $this->bo->month = date('m',time()); + } + if(!isset($this->bo->day)) + { + $this->bo->day = date('d',time()); + } + + $this->owner = $this->bo->owner; + $this->template = $phpgw->template; + $this->template_dir = $phpgw->common->get_tpl_dir('calendar'); + $this->cat = CreateObject('phpgwapi.categories'); + $this->prefs = $phpgw_info['user']['preferences']['calendar']; + + $this->holiday_color = (substr($phpgw_info['theme']['bg07'],0,1)=='#'?'':'#').$phpgw_info['theme']['bg07']; + + $this->filter = $this->bo->filter; + $this->cat_id = $this->bo->cat_id; + + $this->users_timeformat = $this->bo->users_timeformat; + + $this->save_sessiondata(); + + if($this->debug) + { + $this->_debug_sqsof(); + } + } + + /* Public functions */ + + function mini_calendar($day,$month,$year,$link='',$buttons="none",$outside_month=True) + { + global $phpgw, $phpgw_info; + + $this->bo->read_holiday(); + + $date = $this->bo->datetime->makegmttime(0,0,0,$month,$day,$year); + $month_ago = intval(date('Ymd',mktime(0,0,0,$month - 1,$day,$year))); + $month_ahead = intval(date('Ymd',mktime(0,0,0,$month + 1,$day,$year))); + $monthstart = intval(date('Ymd',mktime(0,0,0,$month,1,$year))); + $monthend = intval(date('Ymd',mktime(0,0,0,$month + 1,0,$year))); + + $weekstarttime = $this->bo->datetime->get_weekday_start($year,$month,1); + + $p = CreateObject('phpgwapi.Template',$this->template_dir); + $p->set_unknowns('remove'); + + $templates = Array( + 'mini_calendar' => 'mini_cal.tpl' + ); + $p->set_file($templates); + $p->set_block('mini_calendar','mini_cal','mini_cal'); + $p->set_block('mini_calendar','mini_week','mini_week'); + $p->set_block('mini_calendar','mini_day','mini_day'); + + if($this->printer_friendly == False) + { + $month = '' . lang($phpgw->common->show_date($date['raw'],'F')).' '.$phpgw->common->show_date($date['raw'],'Y').''; + } + else + { + $month = lang($phpgw->common->show_date($date['raw'],'F')).' '.$phpgw->common->show_date($date['raw'],'Y'); + } + + $var = Array( + 'cal_img_root' => $phpgw->common->image('calendar','mini-calendar-bar.gif'), + 'bgcolor' => $phpgw_info['theme']['bg_color'], + 'bgcolor1' => $phpgw_info['theme']['bg_color'], + 'month' => $month, + 'bgcolor2' => $phpgw_info['theme']['cal_dayview'], + 'holiday_color' => $this->holiday_color + ); + + $p->set_var($var); + + switch(strtolower($buttons)) + { + case 'right': + $var = Array( + 'nextmonth' => '' + ); + break; + case 'left': + $var = Array( + 'prevmonth' => '' + ); + break; + case 'both': + $var = Array( + 'prevmonth' => '', + 'nextmonth' => '' + ); + break; + case 'none': + default: + $var = Array( + 'prevmonth' => '', + 'nextmonth' => '' + ); + break; + } + $p->set_var($var); + + for($i=0;$i<7;$i++) + { + $p->set_var('dayname','' . substr(lang($this->bo->datetime->days[$i]),0,2) . ''); + $p->parse('daynames','mini_day',True); + } + $today = date('Ymd',time()); + unset($date); + for($i=$weekstarttime;date('Ymd',$i)<=$monthend;$i += (24 * 3600 * 7)) + { + unset($var); + $daily = $this->bo->set_week_array($i,$cellcolor,$weekly); + @reset($daily); + while(list($date,$day_params) = each($daily)) + { +// echo 'Mini-Cal Date : '.$date."
\n"; + $year = intval(substr($date,0,4)); + $month = intval(substr($date,4,2)); + $day = intval(substr($date,6,2)); + $str = ''; + if(($date >= $monthstart && $date <= $monthend) || $outside_month == True) + { + if(!$this->printer_friendly) + { + $str = ''.$day.''; + } + else + { + $str = $day; + } + + } + $var[] = Array( + 'day_image' => $day_params['day_image'], + 'dayname' => $str + ); + } + for($l=0;$loutput_template_array($p,'monthweek_day','mini_day',$var[$l]); + } + $p->parse('display_monthweek','mini_week',True); + $p->set_var('dayname',''); + $p->set_var('monthweek_day',''); + } + + $return_value = $p->fp('out','mini_cal'); + unset($p); + return $return_value; + } + + function index() + { + global $phpgw; + + Header('Location: '. $this->page()); + $phpgw->common->phpgw_exit(); + } + + function month() + { + global $phpgw, $thismonth, $thisday, $thisyear; + + $this->bo->read_holiday(); + + $templates = Array( + 'index_t' => 'index.tpl' + ); + + $this->template->set_file($templates); + + $m = mktime(0,0,0,$this->bo->month,1,$this->bo->year); + + if ($this->printer_friendly == False) + { + $phpgw->common->phpgw_header(); + echo parse_navbar(); + $this->header(); + + $printer = ''; + $param = '&year='.$this->bo->year.'&month='.$this->bo->month.'&friendly=1&filter='.$filter; + $print = '[".lang('Printer Friendly').']'; + $minical_prev = $this->mini_calendar(1,$this->bo->month - 1,$this->bo->year,'day'); + $minical_next = $this->mini_calendar(1,$this->bo->month + 1,$this->bo->year,'day'); + } + else + { + $printer = ''; + $print = ''; + if($this->preferences['display_minicals'] == 'Y' || $this->preferences['display_minicals']) + { + $minical_prev = $this->mini_calendar(1,$this->bo->month - 1,$this->bo->year,'day'); + $minical_next = $this->mini_calendar(1,$this->bo->month + 1,$this->bo->year,'day'); + } + else + { + $minical_prev = ''; + $minical_next = ''; + } + } + + $var = Array( + 'printer_friendly' => $printer, + 'bg_text' => $phpgw_info['theme']['bg_text'], + 'small_calendar_prev' => $minical_prev, + 'month_identifier' => lang(strftime("%B",$m)) . ' ' . $this->bo->year, + 'username' => $phpgw->common->grab_owner_name($this->owner), + 'small_calendar_next' => $minical_next, + 'large_month' => $this->display_month($this->bo->month,$this->bo->year,True,$this->owner), + 'print' => $print + ); + + $this->template->set_var($var); + $this->template->pparse('out','index_t'); + if($this->printer_friendly) + { + $phpgw->common->phpgw_exit(); + } + else + { + $this->footer(); + } + } + + function week() + { + + global $phpgw, $phpgw_info; + + $next = $this->bo->datetime->makegmttime(0,0,0,$this->bo->month,$this->bo->day + 7,$this->bo->year); + $prev = $this->bo->datetime->makegmttime(0,0,0,$this->bo->month,$this->bo->day - 7,$this->bo->year); + + $nextmonth = $this->bo->datetime->makegmttime(0,0,0,$this->bo->month + 1,1,$this->bo->year); + $prevmonth = $this->bo->datetime->makegmttime(0,0,0,$this->bo->month - 1,1,$this->bo->year); + + $first = $this->bo->datetime->gmtdate($this->bo->datetime->get_weekday_start($this->bo->year, $this->bo->month, $this->bo->day)); + $last = $this->bo->datetime->gmtdate($first['raw'] + 518400); + +// Week Label + $week_id = lang(strftime("%B",$first['raw'])).' '.$first['day']; + if($first['month'] <> $last['month'] && $first['year'] <> $last['year']) + { + $week_id .= ', '.$first['year']; + } + $week_id .= ' - '; + if($first['month'] <> $last['month']) + { + $week_id .= lang(strftime("%B",$last['raw'])).' '; + } + $week_id .= $last['day'].', '.$last['year']; + + $p = CreateObject('phpgwapi.Template',$this->template_dir); + $templates = Array( + 'week_t' => 'week.tpl' + ); + + $p->set_file($templates); + + if (!$this->printer_friendly) + { + $phpgw->common->phpgw_header(); + echo parse_navbar(); + $this->header(); + $printer_header = ''; + $prev_week_link = '<<'; + $next_week_link = '>>'; + $param = '&year='.$this->bo->year.'&month='.$this->bo->month.'&day='.$this->bo->day.'&friendly=1'; + $printer_friendly = '[".lang('Printer Friendly').']'; + $minical_this = $this->mini_calendar($this->bo->day,$this->bo->month,$this->bo->year,'day'); + $minical_prev = $this->mini_calendar(1,$this->bo->month - 1,$this->bo->year,'day'); + $minical_next = $this->mini_calendar(1,$this->bo->month + 1,$this->bo->year,'day'); + } + else + { + $printer_header = ''; + $prev_week_link = '<<'; + $next_week_link = '>>'; + $printer_friendly = ''; + if($this->prefs['display_minicals'] == 'Y' || $this->prefs['display_minicals']) + { + $minical_this = $this->mini_calendar($this->bo->day,$this->bo->month,$this->bo->year,'day'); + $minical_prev = $this->mini_calendar(1,$this->bo->month - 1,$this->bo->year,'day'); + $minical_next = $this->mini_calendar(1,$this->bo->month + 1,$this->bo->year,'day'); + } + else + { + $minical_this = ''; + $minical_prev = ''; + $minical_next = ''; + } + } + + $var = Array( + 'printer_header' => $printer_header, + 'bg_text' => $phpgw_info['themem']['bg_text'], + 'small_calendar_prev' => $minical_prev, + 'prev_week_link' => $prev_week_link, + 'small_calendar_this' => $minical_this, + 'week_identifier' => $week_id, + 'next_week_link' => $next_week_link, + 'username' => $phpgw->common->grab_owner_name($this->owner), + 'small_calendar_next' => $minical_next, + 'week_display' => $this->display_weekly($this->bo->day,$this->bo->month,$this->bo->year,true,$this->owner), + 'printer_friendly' => $printer_friendly + ); + + $p->set_var($var); + $p->pparse('out','week_t'); + flush(); + if($this->printer_friendly) + { + $phpgw->common->phpgw_exit(); + } + else + { + $this->footer(); + } + } + + function year() + { + global $phpgw, $phpgw_info; + + if ($this->printer_friendly) + { + echo ''; + } + else + { + $phpgw->common->phpgw_header(); + echo parse_navbar(); + $this->header(); + } +?> + +
+ + +printer_friendly) + { + echo ' + + +printer_friendly) + { + echo ' + + +printer_friendly) + { + $link = 'day.php'; + } + else + { + $link = ''; + } + for($i=1;$i<13;$i++) + { + echo ''; + } + } +?> + +
<<'; + } +?> + + bo->year; ?> + >>'; + } +?> +
'; + echo $this->mini_calendar($i,$i,$this->bo->year,$link,'none',False); + if($i % 3 == 0) + { + echo '
+
+printer_friendly) + { + $phpgw->common->phpgw_exit(); + } + else + { + echo ' ['.lang('Printer Friendly').']'; + $this->footer(); + } + } + + function view() + { + global $phpgw,$phpgw_info,$cal_id,$submit,$referer; + + $phpgw->common->phpgw_header(); + echo parse_navbar(); + $this->header(); + + // First, make sure they have permission to this entry + if ($cal_id < 1) + { + echo lang('Invalid entry id.'); + $phpgw->common->phpgw_footer(); + $phpgw->common->phpgw_exit(); + } + + if($this->bo->check_perms(PHPGW_ACL_READ) == False) + { + echo lang('You do not have permission to read this record!'); + $phpgw->common->phpgw_footer(); + $phpgw->common->phpgw_exit(); + } + + $event = $this->bo->read_entry($cal_id); + + echo '
'; + + if(isset($event->id)) + { + echo $this->view_event($event); + + $thisyear = $event->start->year; + $thismonth = $event->start->month; + $thisday = $event->start->mday; + + $p = CreateObject('phpgwapi.Template',$this->template_dir); + + $templates = Array( + 'form_button' => 'form_button_script.tpl' + ); + $p->set_file($templates); + + if ($this->owner == $event->owner && $this->bo->check_perms(PHPGW_ACL_EDIT) == True) + { + $var = Array( + 'action_url_button' => $this->page('edit','&cal_id='.$cal_id), + 'action_text_button' => lang('Edit'), + 'action_confirm_button' => '', + 'action_extra_field' => '' + ); + $p->set_var($var); + echo $p->fp('out','form_button'); + } + + if ($this->owner == $event->owner && $this->bo->check_perms(PHPGW_ACL_DELETE) == True) + { + $var = Array( + 'action_url_button' => $this->page('delete','&cal_id='.$cal_id), + 'action_text_button' => lang('Delete'), + 'action_confirm_button' => "onClick=\"return confirm('".lang("Are you sure\\nyou want to\\ndelete this entry ?\\n\\nThis will delete\\nthis entry for all users.")."')\"", + 'action_extra_field' => '' + ); + $p->set_var($var); + echo $p->fp('out','form_button'); + } + } + else + { + echo lang("Sorry, the owner has just deleted this event").'.'; + } + echo '
'; + $this->footer(); + } + + function edit() + { + global $phpgw, $phpgw_info, $cal_id, $readsess, $hour, $minute, $cd; + + $sb = CreateObject('phpgwapi.sbox'); + if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12') + { + $hourformat = 'h'; + } + else + { + $hourformat = 'H'; + } + + if ($cal_id > 0) + { + $event = $this->bo->read_entry(intval($cal_id)); + + $can_edit = False; + + if(($event->owner == $this->owner) && ($this->bo->check_perms(PHPGW_ACL_EDIT) == True)) + { + if($event->public != True) + { + if($this->bo->check_perms(PHPGW_ACL_PRIVATE) == True) + { + $can_edit = True; + } + } + else + { + $can_edit = True; + } + } + + if($can_edit == False) + { + header('Location: '.$this->page('view','&cal_id='.$cal_id)); + } + } + elseif(isset($readsess)) + { + $event = unserialize(str_replace('O:8:"stdClass"','O:13:"calendar_time"',serialize($phpgw->session->appsession('entry','calendar')))); + + if($event->owner == 0) + { + $this->so->add_attribute('owner',$this->owner); + } + + $can_edit = True; + } + else + { + if($this->bo->check_perms(PHPGW_ACL_ADD) == False) + { + header('Location: '.$this->page('view','&cal_id='.$cal_id)); + } + + $this->so->event_init(); + $this->so->add_attribute('id',0); + + $can_edit = True; + + if (!isset($hour)) + { + $thishour = 0; + } + else + { + $thishour = (int)$hour; + } + + if (!isset($minute)) + { + $thisminute = 00; + } + else + { + $thisminute = (int)$minute; + } + + $this->so->set_start($this->bo->year,$this->bo->month,$this->bo->day,$thishour,$thisminute,0); + $this->so->set_end($this->bo->year,$this->bo->month,$this->bo->day,$thishour,$thisminute,0); + $this->so->set_title(''); + $this->so->set_description(''); + $this->so->add_attribute('priority',2); + if($this->preferences['default_private'] == 'Y' || $this->prefs['default_private'] == True) + { + $this->so->set_class(False); + } + else + { + $this->so->set_class(True); + } + + $this->so->set_recur_none(); + $event = $this->so->get_cached_event(); + } + + $start = mktime($event->start->hour,$event->start->min,$event->start->sec,$event->start->month,$event->start->mday,$event->start->year) - $this->bo->datetime->tz_offset; + $end = mktime($event->end->hour,$event->end->min,$event->end->sec,$event->end->month,$event->end->mday,$event->end->year) - $this->bo->datetime->tz_offset; + + $phpgw->common->phpgw_header(); + echo parse_navbar(); + + $p = CreateObject('phpgwapi.Template',$this->template_dir); + $templates = Array( + 'edit' => 'edit.tpl', + 'form_button' => 'form_button_script.tpl' + ); + $p->set_file($templates); + $p->set_block('edit','edit_entry','edit_entry'); + $p->set_block('edit','list','list'); + $p->set_block('edit','hr','hr'); + + if($cal_id > 0) + { + $action = lang('Calendar - Edit'); + } + else + { + $action = lang('Calendar - Add'); + } + + if($cd) + { + $errormsg = $phpgw->common->check_code($cd); + } + else + { + $errormsg = ''; + } + + $common_hidden = ''."\n" + . ''."\n"; + + $vars = Array( + 'font' => $phpgw_info['theme']['font'], + 'bg_color' => $phpgw_info['theme']['bg_text'], + 'calendar_action' => $action, + 'action_url' => $this->page('update'), + 'common_hidden' => $common_hidden, + 'errormsg' => $errormsg + ); + + $p->set_var($vars); + +// Brief Description + $var[] = Array( + 'field' => lang('Title'), + 'data' => '' + ); + +// Full Description + $var[] = Array( + 'field' => lang('Full Description'), + 'data' => '' + ); + +// Display Categories + $var[] = Array( + 'field' => lang('Category'), + 'data' => '' + ); + +// Date + $day_html = $sb->getDays('start[mday]',intval($phpgw->common->show_date($start,'d'))); + $month_html = $sb->getMonthText('start[month]',intval($phpgw->common->show_date($start,'n'))); + $year_html = $sb->getYears('start[year]',intval($phpgw->common->show_date($start,'Y')),intval($phpgw->common->show_date($start,'Y'))); + $var[] = Array( + 'field' => lang('Start Date'), + 'data' => $phpgw->common->dateformatorder($year_html,$month_html,$day_html) + ); + +// Time + $amsel = ' checked'; $pmsel = ''; + if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12') + { + if ($event->start->hour >= 12) + { + $amsel = ''; $pmsel = ' checked'; + } + } + $str = ':'; + if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12') + { + $str .= 'am'; + $str .= 'pm'; + } + $var[] = Array( + 'field' => lang('Start Time'), + 'data' => $str + ); + +// End Date + $day_html = $sb->getDays('end[mday]',intval($phpgw->common->show_date($end,'d'))); + $month_html = $sb->getMonthText('end[month]',intval($phpgw->common->show_date($end,'n'))); + $year_html = $sb->getYears('end[year]',intval($phpgw->common->show_date($end,'Y')),intval($phpgw->common->show_date($end,'Y'))); + $var[] = Array( + 'field' => lang('End Date'), + 'data' => $phpgw->common->dateformatorder($year_html,$month_html,$day_html) + ); + +// End Time + $amsel = ' checked'; $pmsel = ''; + if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12') + { + if ($event->end->hour >= 12) + { + $amsel = ''; $pmsel = ' checked'; + } + } + + $str = ':'; + if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12') + { + $str .= 'am'; + $str .= 'pm'; + } + $var[] = Array( + 'field' => lang("End Time"), + 'data' => $str + ); + +// Priority + $var[] = Array( + 'field' => lang('Priority'), + 'data' => $sb->getPriority('priority',$event->priority) + ); + +// Access + $str = 'public != True) + { + $str .= ' checked'; + } + $str .= '>'; + $var[] = Array( + 'field' => lang('Private'), + 'data' => $str + ); + + function build_part_list(&$users,$accounts,$owner) + { + global $phpgw; + if($accounts == False) + { + return; + } + while(list($index,$id) = each($accounts)) + { + if(intval($id) == $owner) + { + continue; + } + if(!isset($users[intval($id)])) + { + if($phpgw->accounts->exists(intval($id)) == True) + { + $users[intval($id)] = $phpgw->common->grab_owner_name(intval($id)); + } + if($phpgw->accounts->get_type(intval($id)) == 'g') + { + build_part_list($users,$phpgw->acl->get_ids_for_location(intval($id),1,'phpgw_group'),$owner); + } + } + } + } + +// Participants + $accounts = $phpgw->acl->get_ids_for_location('run',1,'calendar'); + $users = Array(); + build_part_list($users,$accounts,$owner); + while(list($key,$status) = each($event->participants)) + { + $parts[$key] = ' selected'; + } + + $str = "\n".' '; + $var[] = Array( + 'field' => lang('Participants'), + 'data' => $str + ); + +// I Participate + $str = ' 0) && isset($event->participants[$owner])) || !isset($id)) + { + $str .= ' checked'; + } + $str .= '>'; + $var[] = Array( + 'field' => $phpgw->common->grab_owner_name($owner).' '.lang('Participates'), + 'data' => $str + ); + + for($i=0;$ioutput_template_array($p,'row','list',$var[$i]); + } + + unset($var); + +// Repeat Type + $p->set_var('hr_text','
'); + $p->parse('row','hr',True); + $p->set_var('hr_text','
'.lang('Repeating Event Information').'

'); + $p->parse('row','hr',True); + $str = ''; + $var[] = Array( + 'field' => lang('Repeat Type'), + 'data' => $str + ); + + $str = 'recur_enddate->year != 0 && $event->recur_enddate->month != 0 && $event->recur_enddate->mday != 0) + { + $str .= ' checked'; + $recur_end = mktime($event->recur_enddate->hour,$event->recur_enddate->min,$event->recur_enddate->sec,$event->recur_enddate->month,$event->recur_enddate->mday,$event->recur_enddate->year) - $this->bo->datetime->tz_offset; + } + else + { + $recur_end = mktime($event->start->hour,$event->start->min,$event->start->sec,$event->start->month,$event->start->mday,$event->start->year) + 86400 - $this->bo->datetime->tz_offset; + } + + $str .= '>'.lang('Use End Date').' '; + + $day_html = $sb->getDays('recur_enddate[mday]',intval($phpgw->common->show_date($recur_end,'d'))); + $month_html = $sb->getMonthText('recur_enddate[month]',intval($phpgw->common->show_date($recur_end,'n'))); + $year_html = $sb->getYears('recur_enddate[year]',intval($phpgw->common->show_date($recur_end,'Y')),intval($phpgw->common->show_date($recur_end,'Y'))); + $str .= $phpgw->common->dateformatorder($year_html,$month_html,$day_html); + + $var[] = Array( + 'field' => lang('Repeat End Date'), + 'data' => $str + ); + + $str = 'recur_data & MCAL_M_SUNDAY) ?' checked':'').'> '.lang('Sunday').' '; + $str .= 'recur_data & MCAL_M_MONDAY) ?' checked':'').'> '.lang('Monday').' '; + $str .= 'recur_data & MCAL_M_TUESDAY) ?' checked':'').'> '.lang('Tuesday').' '; + $str .= 'recur_data & MCAL_M_WEDNESDAY) ?' checked':'').'> '.lang('Wednesday').'
'; + $str .= 'recur_data & MCAL_M_THURSDAY) ?' checked':'').'> '.lang('Thursday').' '; + $str .= 'recur_data & MCAL_M_FRIDAY) ?' checked':'').'> '.lang('Friday').' '; + $str .= 'recur_data & MCAL_M_SATURDAY) ?' checked':'').'> '.lang('Saturday').' '; + + $var[] = Array( + 'field' => lang('Repeat Day').'
'.lang('(for weekly)'), + 'data' => $str + ); + + $var[] = Array( + 'field' => lang('Frequency'), + 'data' => '' + ); + + for($i=0;$ioutput_template_array($p,'row','list',$var[$i]); + } + + $p->set_var('submit_button',lang('Submit')); + + if ($cal_id > 0) + { + $action_url_button = $this->page('delete','&cal_id='.$cal_id); + $action_text_button = lang('Delete'); + $action_confirm_button = "onClick=\"return confirm('".lang("Are you sure\\nyou want to \\ndelete this entry?\\n\\nThis will delete\\nthis entry for all users.")."')\""; + $var = Array( + 'action_url_button' => $action_url_button, + 'action_text_button' => $action_text_button, + 'action_confirm_button' => $action_confirm_button, + 'action_extra_field' => '' + ); + $p->set_var($var); + $p->parse('delete_button','form_button'); + } + else + { + $p->set_var('delete_button',''); + } + $p->pparse('out','edit_entry'); + $this->footer(); + } + + /* Private functions */ + + function _debug_sqsof() + { + $data = array( + 'filter' => $this->filter, + 'cat_id' => $this->cat_id, + 'owner' => $this->owner, + 'year' => $this->bo->year, + 'month' => $this->bo->month, + 'day' => $this->bo->day + ); + echo '
UI:'; + _debug_array($data); + } + + /* Called only by get_list(), just prior to page footer. */ + function save_sessiondata() + { + $data = array( + 'filter' => $this->filter, + 'cat_id' => $this->cat_id, + 'owner' => $this->owner, + 'year' => $this->bo->year, + 'month' => $this->bo->month, + 'day' => $this->bo->day + ); + $this->bo->save_sessiondata($data); + } + + function output_template_array(&$p,$row,$list,$var) + { + $p->set_var($var); + $p->parse($row,$list,True); + } + + function page($page='',$params='') + { + global $phpgw, $phpgw_info; + + if($page == '') + { + $page_ = explode('.',$this->prefs['defaultcalendar']); + $page = $page_[0]; + if ($page=='index' || ($page != 'day' && $page != 'week' && $page != 'month' && $page != 'year')) + { + $page = 'month'; + $phpgw->preferences->add('calendar','defaultcalendar','month'); + $phpgw->preferences->save_repository(); + } + } + return $phpgw->link('/index.php','menuaction='.$phpgw_info['flags']['currentapp'].'.ui'.$phpgw_info['flags']['currentapp'].'.'.$page.$params); + } + + function header() + { + if (floor(phpversion()) == 4) + { + global $date, $year, $month, $day, $thisyear, $thismonth, $thisday, $filter, $keywords; + global $matrixtype, $participants, $owner, $phpgw, $grants, $rights, $SCRIPT_FILENAME, $remainder, $tpl; + } + + $cols = 8; + if($this->bo->check_perms(PHPGW_ACL_PRIVATE) == True) + { + $cols++; + } + + $tpl = CreateObject('phpgwapi.Template',$this->template_dir); + $tpl->set_unknowns('remove'); + + include($this->template_dir.'/header.inc.php'); + flush(); + } + + function footer() + { + global $phpgw; + + if (@$this->printer_friendly) + { + $phpgw->common->phpgw_footer(); + $phpgw->common->phpgw_exit(); + } + + $p = CreateObject('phpgwapi.Template',$this->template_dir); + + $templates = Array( + 'footer' => 'footer.tpl' + ); + + $p->set_file($templates); + $p->set_block('footer','footer_table','footer_table'); + $p->set_block('footer','footer_row','footer_row'); + + $m = $this->bo->month; + $y = $this->bo->year; + + $d_time = mktime(0,0,0,$m,1,$y); + $thisdate = date('Ymd', $d_time); + $y--; + + $str = ''; + + for ($i = 0; $i < 25; $i++) + { + $m++; + if ($m > 12) + { + $m = 1; + $y++; + } + $d = mktime(0,0,0,$m,1,$y); + $str .= ''."\n"; + } + + $var = Array( + 'action_url' => $this->page('week',''), + 'form_name' => 'SelectWeek', + 'label' => lang('Week'), + 'form_label' => 'date', + 'form_onchange' => 'document.SelectWeek.submit()', + 'row' => $str, + 'go' => lang('Go!') + ); + + $this->output_template_array($p,'table_row','footer_row',$var); + + $str = ''; + for ($i = ($y - 3); $i < ($y + 3); $i++) + { + $str .= '