diff --git a/calendar/inc/class.bocalendar.inc.php b/calendar/inc/class.bocalendar.inc.php index 7d86a41086..c243d1e24e 100755 --- a/calendar/inc/class.bocalendar.inc.php +++ b/calendar/inc/class.bocalendar.inc.php @@ -20,6 +20,7 @@ 'read_entries' => True, 'read_entry' => True, 'add_entry' => True, + 'delete_entry' => True, 'update_entry' => True ); @@ -32,13 +33,12 @@ var $day; var $month; var $year; + var $prefs; var $owner; var $holiday_color; var $printer_friendly = False; - var $holiday_locales; - var $holidays; var $cached_holidays; var $filter; @@ -47,16 +47,18 @@ var $use_session = False; - function bocalendar($session=False) + function bocalendar($session=0) { - global $phpgw, $phpgw_info, $date, $year, $month, $day; +// if(floor(phpversion()) == 4) +// { + global $phpgw, $phpgw_info, $date, $year, $month, $day, $owner, $filter, $fcat_id, $friendly; +// } $phpgw->nextmatchs = CreateObject('phpgwapi.nextmatchs'); - $this->so = CreateObject('calendar.socalendar'); - $this->datetime = $this->so->datetime; + $this->grants = $phpgw->acl->get_grants('calendar'); - $this->filter = ' '.$phpgw_info['user']['preferences']['calendar']['defaultfilter'].' '; + if($this->debug) { echo "Read Use_Session : (".$session.")\n"; } if($session) { @@ -64,16 +66,21 @@ $this->use_session = True; } - if(isset($this->so->owner)) + if($this->debug) { echo "BO Filter : (".$this->filter.")\n"; } + if(isset($owner)) { - $this->owner = $this->so->owner; + $this->owner = $owner; } - else + elseif(!$this->owner) { - $this->so->owner = $this->owner; + $this->owner = $phpgw_info['user']['account_id']; } - - if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12') + + $this->prefs['common'] = $phpgw_info['user']['preferences']['common']; + $this->prefs['calendar'] = $phpgw_info['user']['preferences']['calendar']; + + + if ($this->prefs['common']['timeformat'] == '12') { $this->users_timeformat = 'h:i a'; } @@ -84,15 +91,18 @@ $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($filter)) { $this->filter = $filter; } + if(isset($cat_id)) { $this->cat_id = $cat_id; } + + if(!isset($this->filter)) + { + $this->filter = ' '.$this->prefs['calendar']['defaultfilter'].' '; + } if(isset($date)) { @@ -106,15 +116,32 @@ { $this->year = $year; } + elseif($this->year == 0) + { + $this->year = date('Y',time()); + } if(isset($month)) { $this->month = $month; } + elseif($this->month == 0) + { + $this->month = date('m',time()); + } if(isset($day)) { $this->day = $day; } + elseif($this->day == 0) + { + $this->day = date('d',time()); + } } + + $this->so = CreateObject('calendar.socalendar',$this->owner,$this->filter,$this->cat_id); + $this->datetime = $this->so->datetime; + + if($this->debug) { echo "BO Filter : (".$this->filter.")\n"; } } function save_sessiondata($data) @@ -140,233 +167,221 @@ $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); + if($this->check_perms(PHPGW_ACL_READ)) + { + return $this->so->read_entry($id); + } } + function add_entry($event) + { + if($this->check_perms(PHPGW_ACL_ADD)) + { + $this->so->add_entry($event); + } + } + + function update_entry($event) + { + if($this->check_perms(PHPGW_ACL_EDIT)) + { + $this->so->add_entry($event); + } + } + + function delete_entry($id) + { + if($this->check_perms(PHPGW_ACL_DELETE)) + { + $this->so->delete_entry($id); + } + } + + function expunge() + { + if($this->check_perms(PHPGW_ACL_DELETE)) + { + $this->so->expunge(); + } + } /* Private functions */ - /* Begin Calendar functions */ - function auto_load_holidays($locale) + function read_holidays() { - if($this->so->count_of_holidays($locale) == 0) - { - global $phpgw_info, $HTTP_HOST, $SERVER_PORT; - - @set_time_limit(0); + $holiday = CreateObject('calendar.boholiday',$this->year,$this->owner); + $this->cached_holidays = $holiday->read_holiday(); + unset($holiday); + } - /* 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') + function can_user_edit($event) + { + $can_edit = False; + + if(($event->owner == $this->owner) && ($this->check_perms(PHPGW_ACL_EDIT) == True)) + { + if($event->public != True) { - $load_from = $phpgw_info['server']['holidays_url_path']; + if($this->check_perms(PHPGW_ACL_PRIVATE) == True) + { + $can_edit = True; + } } 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); - } + $can_edit = True; } } + return $can_edit; } - function build_holiday_query() + function fix_update_time(&$time_param) { - @reset($this->holiday_locales); - if(count(@$this->holiday_locales) == 0) + global $phpgw_info; + + if ($this->prefs['common']['timeformat'] == '12') { - return False; - } - $sql = 'SELECT * FROM phpgw_cal_holidays WHERE locale in ('; - $find_it = ''; - while(list($key,$value) = each($this->holiday_locales)) - { - if($find_it) + if ($time_param[ampm] == 'pm') { - $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']) + if ($time_param[hour] <> 12) { - $temp = $holidays[$inner_loop]; - $holidays[$inner_loop] = $holidays[$outer_loop]; - $holidays[$outer_loop] = $temp; + $time_param[hour] += 12; } } + elseif ($time_param[ampm] == 'am') + { + if ($time_param[hour] == 12) + { + $time_param[hour] -= 12; + } + } + + if($time_param[hour] > 24) + { + $time_param[hour] -= 12; + } } - return $holidays; } - function set_holidays_to_date($holidays) + function validate_update($event) { - $new_holidays = Array(); - for($i=0;$ititle == '') { -// echo "Setting Holidays Date : ".date('Ymd',$holidays[$i]['date'])."\n"; - $new_holidays[date('Ymd',$holidays[$i]['date'])][] = $holidays[$i]; + $error = 40; } - return $new_holidays; + elseif (($this->datetime->time_valid($event->start->hour,$event->start->min,0) == False) || ($this->datetime->time_valid($event->end->hour,$event->end->min,0) == False)) + { + $error = 41; + } + elseif (($this->datetime->date_valid($event->start->year,$event->start->month,$event->start->mday) == False) || ($this->datetime->date_valid($event->end->year,$event->end->month,$event->end->mday) == False) || ($this->datetime->date_compare($event->start->year,$event->start->month,$event->start->mday,$event->end->year,$event->end->month,$event->end->mday) == 1)) + { + $error = 42; + } + elseif ($this->datetime->date_compare($event->start->year,$event->start->month,$event->start->mday,$event->end->year,$event->end->month,$event->end->mday) == 0) + { + if ($this->datetime->time_compare($event->start->hour,$event->start->min,0,$event->end->hour,$event->end->min,0) == 1) + { + $error = 42; + } + } + return $error; } - function read_holiday() + function overlap($starttime,$endtime,$participants,$owner=0,$id=0) { global $phpgw, $phpgw_info; - if(isset($this->cached_holidays)) + $retval = Array(); + $ok = False; + + if($starttime == $endtime && $phpgw->common->show_date($starttime,'Hi') == 0) { - return $this->cached_holidays; + $endtime = mktime(23,59,59,$phpgw->common->show_date($starttime,'m'),$phpgw->common->show_date($starttime,'d') + 1,$phpgw->common->show_date($starttime,'Y')) - $this->datetime->tz_offset; } - 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); - } + $sql = 'AND ((('.$starttime.' <= phpgw_cal.datetime) AND ('.$endtime.' >= phpgw_cal.datetime) AND ('.$endtime.' <= phpgw_cal.edatetime)) ' + . 'OR (('.$starttime.' >= phpgw_cal.datetime) AND ('.$starttime.' < phpgw_cal.edatetime) AND ('.$endtime.' >= phpgw_cal.edatetime)) ' + . 'OR (('.$starttime.' <= phpgw_cal.datetime) AND ('.$endtime.' >= phpgw_cal.edatetime)) ' + . 'OR (('.$starttime.' >= phpgw_cal.datetime) AND ('.$endtime.' <= phpgw_cal.edatetime))) '; - @reset($this->holiday_locales); - if($phpgw_info['server']['auto_load_holidays'] == True) + if(count($participants) > 0) { - while(list($key,$value) = each($this->holiday_locales)) + $p_g = ''; + if(count($participants)) { - $this->auto_load_holidays($value); + $users = Array(); + while(list($user,$status) = each($participants)) + { + $users[] = $user; + } + if($users) + { + $p_g .= 'phpgw_cal_user.cal_login in ('.implode(',',$users).')'; + } + } + if($p_g) + { + $sql .= ' AND (' . $p_g . ')'; } } - - $sql = $this->build_holiday_query(); - if($sql == False) + + if($id) { - return array(); + $sql .= ' AND phpgw_cal.cal_id <> '.$id; } - $holidays = $this->so->read_holidays($sql); - $temp_locale = $phpgw_info['user']['preferences']['common']['country']; - for($i=0;$iso->get_event_ids(False,$sql); + if($events == False) { - $c = $i; - $phpgw_info['user']['preferences']['common']['country'] = $holidays[$i]['locale']; - $holidaycalc = CreateObject('calendar.holidaycalc'); - $holidays[$i]['date'] = $holidaycalc->calculate_date($holidays[$i], $holidays, $this->year, $this->datetime, $c); - unset($holidaycalc); - if($c != $i) + return false; + } + + $db2 = $phpgw->db; + + for($i=0;$iquery('SELECT recur_type FROM phpgw_cal_repeats WHERE cal_id='.$events[$i],__LINE__,__FILE__); + if($db2->num_rows() == 0) { - $i = $c; + $retval[] = $events[$i]; + $ok = True; + } + else + { + $db2->next_record(); + if($db2->f('recur_type') <> MCAL_RECUR_MONTHLY_MDAY) + { + $retval[] = $events[$i]; + $ok = True; + } } } - $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) + if($ok == True) { - return ($this->so->rights & $needed); + return $retval; } else { - return ($grants[$user] & $needed); + return False; + } + } + + function check_perms($needed,$user=0) + { + if($user == 0) + { + return ($this->grants[$this->owner] & $needed); + } + else + { + return ($this->grants[$user] & $needed); } } @@ -374,7 +389,7 @@ { global $phpgw_info; - if(isset($phpgw_info['user']['preferences']['calendar']['display_status']) && $phpgw_info['user']['preferences']['calendar']['display_status'] == True) + if(isset($this->prefs['calendar']['display_status']) && $this->prefs['calendar']['display_status'] == True) { return ' ('.$user_status.')'; } @@ -406,10 +421,10 @@ function is_private($event,$owner,$field='') { - global $phpgw, $phpgw_info, $grants; + global $phpgw, $phpgw_info; - if($owner == 0) { $owner = $phpgw_info['user']['account_id']; } - if ($owner == $phpgw_info['user']['account_id'] || ($grants[$owner] & PHPGW_ACL_PRIVATE) || ($event->public == 1)) + if($owner == 0) { $owner = $this->owner; } + if ($owner == $phpgw_info['user']['account_id'] || $this->check_perms(PHPGW_ACL_PRIVATE,$owner) || ($event->public == 1)) { $is_private = False; } @@ -455,6 +470,72 @@ return $str; } + 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,$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 ($this->prefs['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 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 ($this->prefs['common']['timeformat'] == '12') + { + $str .= ' ' . $time['ampm']; + } + + return $str; + } + function sort_event($event,$date) { $inserted = False; @@ -619,14 +700,36 @@ } // end for loop } // end function - function store_to_cache($syear,$smonth,$sday) + function store_to_cache($syear,$smonth,$sday,$eyear=0,$emonth=0,$eday=0) { 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); + echo "Start Date : ".sprintf("%04d%02d%02d",$syear,$smonth,$sday)."\n"; + + if(!$eyear && !$emonth && !$eday) + { + $edate = mktime(23,59,59,$smonth + 1,$sday + 1,$syear); + $eyear = date('Y',$edate); + $emonth = date('m',$edate); + $eday = date('d',$edate); + } + else + { + if(!$eyear) + { + $eyear = $syear; + } + if(!$emonth) + { + $emonth = $smonth + 1; + } + if(!$eday) + { + $eday = $sday + 1; + } + $edate = mktime(23,59,59,$emonth,$eday,$eyear); + } + $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); @@ -646,10 +749,10 @@ 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; + $starttime = mktime($event->start->hour,$event->start->min,$event->start->sec,$event->start->month,$event->start->mday,$event->start->year); + $endtime = mktime($event->end->hour,$event->end->min,$event->end->sec,$event->end->month,$event->end->mday,$event->end->year); $this->cached_events[date('Ymd',$starttime)][] = $event; - if($this->cached_events[date('Ymd',$endtime)][count($this->cached_events[date('Ymd',$endtime)]) - 1] != $event) + if($this->cached_events[date('Ymd',$endtime)][count($this->cached_events[date('Ymd',$starttime)]) - 1] != $event) { $this->cached_events[date('Ymd',$endtime)][] = $event; } @@ -671,6 +774,105 @@ } } + /* Begin Appsession Data */ + function store_to_appsession($event) + { + global $phpgw; + $phpgw->session->appsession('entry','calendar',$event); + } + + function restore_from_appsession() + { + global $phpgw; + $this->event_init(); + $event = unserialize(str_replace('O:8:"stdClass"','O:13:"calendar_time"',serialize($phpgw->session->appsession('entry','calendar')))); + $this->so->cal->event = $event; + return $event; + } + /* End Appsession Data */ + + /* Begin of SO functions */ + function get_cached_event() + { + return $this->so->get_cached_event(); + } + + function add_attribute($var,$value) + { + $this->so->add_attribute($var,$value); + } + + function event_init() + { + $this->so->event_init(); + } + + function set_start($year,$month,$day=0,$hour=0,$min=0,$sec=0) + { + $this->so->set_start($year,$month,$day,$hour,$min,$sec); + } + + function set_end($year,$month,$day=0,$hour=0,$min=0,$sec=0) + { + $this->so->set_end($year,$month,$day,$hour,$min,$sec); + } + + function set_title($title='') + { + $this->so->set_title($title); + } + + function set_description($description='') + { + $this->so->set_description($description); + } + + function set_class($class) + { + $this->so->set_class($class); + } + + function set_category($category='') + { + $this->so->set_category($category); + } + + function set_alarm($alarm) + { + $this->so->set_alarm($alarm); + } + + function set_recur_none() + { + $this->so->set_recur_none(); + } + + function set_recur_daily($year,$month,$day,$interval) + { + $this->so->set_recur_daily($year,$month,$day,$interval); + } + + function set_recur_weekly($year,$month,$day,$interval,$weekdays) + { + $this->so->set_recur_weekly($year,$month,$day,$interval,$weekdays); + } + + function set_recur_monthly_mday($year,$month,$day,$interval) + { + $this->so->set_recur_monthly_mday($year,$month,$day,$interval); + } + + function set_recur_monthly_wday($year,$month,$day,$interval) + { + $this->so->set_recur_monthly_wday($year,$month,$day,$interval); + } + + function set_recur_yearly($year,$month,$day,$interval) + { + $this->so->set_recur_yearly($year,$month,$day,$interval); + } + /* End of SO functions */ + function set_week_array($startdate,$cellcolor,$weekly) { global $phpgw, $phpgw_info; @@ -708,7 +910,7 @@ $day_image = ' background="'.$phpgw->common->image('calendar','mini_day_block.gif').'"'; } - if($this->printer_friendly && @$phpgw_info['user']['preferences']['calendar']['print_black_white']) + if($this->printer_friendly && @$this->prefs['calendar']['print_black_white']) { $extra = ''; } @@ -743,7 +945,7 @@ 'holidays' => $holiday_name, 'appts' => $appts, 'week' => $week, - 'day_image'=> $day_image, + 'day_image' => $day_image, 'class' => $class ); } diff --git a/calendar/inc/class.socalendar.inc.php b/calendar/inc/class.socalendar.inc.php index 791eccfb5b..725a975f30 100755 --- a/calendar/inc/class.socalendar.inc.php +++ b/calendar/inc/class.socalendar.inc.php @@ -1,8 +1,10 @@ * + * Based on Webcalendar by Craig Knudsen * + * 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 * @@ -14,22 +16,43 @@ class socalendar { + var $debug = False; var $cal; - var $rights; - var $db; - var $owner; var $datetime; + var $filter; + var $cat_id; - function socalendar() + function socalendar($owner=0,$filter='',$cat_id='') { - global $phpgw, $rights, $owner; + global $phpgw; $this->db = $phpgw->db; - $this->rights = $rights; - if(isset($owner)) { $this->owner = $owner; } $this->datetime = CreateObject('phpgwapi.datetime'); + if($owner == 0) + { + $this->owner = $phpgw_info['user']['account_id']; + } + else + { + $this->owner = $owner; + } + + if($filter != '') + { + $this->filter = $filter; + } + + if($cat_id != '') + { + $this->cat_id = $cat_id; + } + if($this->debug) + { + echo 'SO Filter : '.$this->filter."\n"; + echo 'SO cat_id : '.$this->cat_id."\n"; + } } function makeobj() @@ -45,21 +68,24 @@ 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; - } + return $this->cal->fetch_event($id); } 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); + + $extra = ''; + if(strpos($this->filter,'private')) + { + $extra .= 'AND phpgw_cal.is_public=0 '; + } + + if($this->cat_id) + { + $extra .= 'AND phpgw_cal.category = '.$this->cat_id.' '; + } + return $this->cal->list_events($startYear,$startMonth,$startDay,$endYear,$endMonth,$endDay,$extra,$this->datetime->tz_offset); } function list_repeated_events($syear,$smonth,$sday,$eyear,$emonth,$eday) @@ -76,8 +102,24 @@ $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'; + . 'AND (((phpgw_cal_repeats.recur_enddate >= '.$starttime.') AND (phpgw_cal_repeats.recur_enddate <= '.$endtime.')) OR (phpgw_cal_repeats.recur_enddate=0))) '; + + if(strpos($this->filter,'private')) + { + $sql .= 'AND phpgw_cal.is_public=0 '; + } + + if($this->cat_id) + { + $sql .= 'AND phpgw_cal.category = '.$this->cat_id.' '; + } + + $sql .= 'ORDER BY phpgw_cal.datetime ASC, phpgw_cal.edatetime ASC, phpgw_cal.priority ASC'; + + if($this->debug) + { + echo "SO list_repeated_events : SQL : ".$sql."\n"; + } $events = $this->get_event_ids(True,$sql); @@ -101,16 +143,25 @@ return $this->cal->get_event_ids($include_repeats,$sql); } - function add_entry($userid,$fields) + function add_entry($event) { $this->makeobj(); - if ($this->rights & PHPGW_ACL_ADD) - { - $this->cal->add($userid,$fields,$fields['access'],$fields['cat_id'],$fields['tid']); - } - return; + $this->cal->store_event($event); } + function delete_entry($id) + { + $this->makeobj(); + $this->cal->delete_event($id); + } + + function expunge() + { + $this->makeobj(); + $this->cal->expunge(); + } + + function get_lastid() { $this->makeobj(); @@ -129,67 +180,6 @@ 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() { diff --git a/calendar/inc/class.socalendar_sql.inc.php b/calendar/inc/class.socalendar_sql.inc.php index c4897063e3..43c2783a69 100755 --- a/calendar/inc/class.socalendar_sql.inc.php +++ b/calendar/inc/class.socalendar_sql.inc.php @@ -213,7 +213,7 @@ class socalendar_ extends socalendar__ return $this->event; } - function list_events($startYear,$startMonth,$startDay,$endYear='',$endMonth='',$endDay='',$tz_offset) + function list_events($startYear,$startMonth,$startDay,$endYear='',$endMonth='',$endDay='',$extra='',$tz_offset=0) { if(!isset($this->stream)) { @@ -235,7 +235,7 @@ class socalendar_ extends socalendar__ } $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); + return $this->get_event_ids(False,$user_where.$startDate.$endDate.$extra.$order_by); } function append_event() @@ -508,20 +508,6 @@ class socalendar_ extends socalendar__ } } - 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; @@ -539,61 +525,9 @@ class socalendar_ extends socalendar__ 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 index 61e96fd914..9a2e0bcb4c 100755 --- a/calendar/inc/class.uicalendar.inc.php +++ b/calendar/inc/class.uicalendar.inc.php @@ -18,21 +18,15 @@ { 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( @@ -44,52 +38,32 @@ 'view' => True, 'add' => True, 'edit' => True, - 'delete' => True + 'update' => True, + 'delete' => True, + 'preferences' => True, + 'day' => True ); function uicalendar() { - global $phpgw, $phpgw_info, $friendly; + global $phpgw, $phpgw_info; $phpgw->browser = CreateObject('phpgwapi.browser'); - if($friendly == 1) - { - $this->printer_friendly = True; - } - else - { - $this->printer_friendly = False; - } + $this->bo = CreateObject('calendar.bocalendar',1); - $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->bo->use_session) + { + $this->save_sessiondata(); + } if($this->debug) { @@ -103,7 +77,7 @@ { global $phpgw, $phpgw_info; - $this->bo->read_holiday(); + $this->bo->read_holidays(); $date = $this->bo->datetime->makegmttime(0,0,0,$month,$day,$year); $month_ago = intval(date('Ymd',mktime(0,0,0,$month - 1,$day,$year))); @@ -124,7 +98,7 @@ $p->set_block('mini_calendar','mini_week','mini_week'); $p->set_block('mini_calendar','mini_day','mini_day'); - if($this->printer_friendly == False) + if($this->bo->printer_friendly == False) { $month = '' . lang($phpgw->common->show_date($date['raw'],'F')).' '.$phpgw->common->show_date($date['raw'],'Y').''; } @@ -193,7 +167,7 @@ $str = ''; if(($date >= $monthstart && $date <= $monthend) || $outside_month == True) { - if(!$this->printer_friendly) + if(!$this->bo->printer_friendly) { $str = ''.$day.''; } @@ -232,26 +206,29 @@ function month() { - global $phpgw, $thismonth, $thisday, $thisyear; + global $phpgw; - $this->bo->read_holiday(); + $this->bo->read_holidays(); + + $p = CreateObject('phpgwapi.Template',$this->template_dir); + $p->set_unknowns('remove'); $templates = Array( 'index_t' => 'index.tpl' ); - $this->template->set_file($templates); + $p->set_file($templates); $m = mktime(0,0,0,$this->bo->month,1,$this->bo->year); - if ($this->printer_friendly == False) + if (!$this->bo->printer_friendly) { $phpgw->common->phpgw_header(); echo parse_navbar(); $this->header(); $printer = ''; - $param = '&year='.$this->bo->year.'&month='.$this->bo->month.'&friendly=1&filter='.$filter; + $param = '&year='.$this->bo->year.'&month='.$this->bo->month.'&friendly=1'; $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'); @@ -260,7 +237,7 @@ { $printer = ''; $print = ''; - if($this->preferences['display_minicals'] == 'Y' || $this->preferences['display_minicals']) + if($this->bo->prefs['calendar']['display_minicals'] == 'Y' || $this->bo->prefs['calendar']['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'); @@ -277,19 +254,15 @@ '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), + 'username' => $phpgw->common->grab_owner_name($this->bo->owner), 'small_calendar_next' => $minical_next, - 'large_month' => $this->display_month($this->bo->month,$this->bo->year,True,$this->owner), + 'large_month' => $this->display_month($this->bo->month,$this->bo->year,True,$this->bo->owner), 'print' => $print ); - $this->template->set_var($var); - $this->template->pparse('out','index_t'); - if($this->printer_friendly) - { - $phpgw->common->phpgw_exit(); - } - else + $p->set_var($var); + $p->pparse('out','index_t'); + if(!$this->bo->printer_friendly) { $this->footer(); } @@ -300,6 +273,8 @@ global $phpgw, $phpgw_info; + $this->bo->read_holidays(); + $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); @@ -329,27 +304,27 @@ $p->set_file($templates); - if (!$this->printer_friendly) + if (!$this->bo->printer_friendly) { $phpgw->common->phpgw_header(); echo parse_navbar(); $this->header(); - $printer_header = ''; + $printer = ''; $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'); + $print = '[".lang('Printer Friendly').']'; + $minical_this = $this->mini_calendar($this->bo->day,$this->bo->month,$this->bo->year,'day','none',False); + $minical_prev = $this->mini_calendar(1,$this->bo->month - 1,$this->bo->year,'day','left',False); + $minical_next = $this->mini_calendar(1,$this->bo->month + 1,$this->bo->year,'day','right',False); } else { - $printer_header = ''; + $printer = ''; $prev_week_link = '<<'; $next_week_link = '>>'; - $printer_friendly = ''; - if($this->prefs['display_minicals'] == 'Y' || $this->prefs['display_minicals']) + $print = ''; + if($this->bo->prefs['calendar']['display_minicals'] == 'Y' || $this->bo->prefs['calendar']['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'); @@ -364,23 +339,23 @@ } $var = Array( - 'printer_header' => $printer_header, + 'printer_friendly' => $printer, '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), + 'username' => $phpgw->common->grab_owner_name($this->bo->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 + 'week_display' => $this->display_weekly($this->bo->day,$this->bo->month,$this->bo->year,true,$this->bo->owner), + 'print' => $print ); $p->set_var($var); $p->pparse('out','week_t'); flush(); - if($this->printer_friendly) + if($this->bo->printer_friendly) { $phpgw->common->phpgw_exit(); } @@ -394,7 +369,7 @@ { global $phpgw, $phpgw_info; - if ($this->printer_friendly) + if ($this->bo->printer_friendly) { echo ''; } @@ -410,7 +385,7 @@ printer_friendly) + if(!$this->bo->printer_friendly) { echo '<<'; } @@ -421,7 +396,7 @@ bo->year; ?> printer_friendly) + if(!$this->bo->printer_friendly) { echo '>>'; } @@ -430,7 +405,7 @@ printer_friendly) + if(!$this->bo->printer_friendly) { $link = 'day.php'; } @@ -452,7 +427,7 @@ printer_friendly) + if($this->bo->printer_friendly) { $phpgw->common->phpgw_exit(); } @@ -507,7 +482,7 @@ ); $p->set_file($templates); - if ($this->owner == $event->owner && $this->bo->check_perms(PHPGW_ACL_EDIT) == True) + if ($this->bo->owner == $event->owner && $this->bo->check_perms(PHPGW_ACL_EDIT) == True) { $var = Array( 'action_url_button' => $this->page('edit','&cal_id='.$cal_id), @@ -519,7 +494,7 @@ echo $p->fp('out','form_button'); } - if ($this->owner == $event->owner && $this->bo->check_perms(PHPGW_ACL_DELETE) == True) + if ($this->bo->owner == $event->owner && $this->bo->check_perms(PHPGW_ACL_DELETE) == True) { $var = Array( 'action_url_button' => $this->page('delete','&cal_id='.$cal_id), @@ -544,7 +519,7 @@ global $phpgw, $phpgw_info, $cal_id, $readsess, $hour, $minute, $cd; $sb = CreateObject('phpgwapi.sbox'); - if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12') + if ($this->bo->prefs['common']['timeformat'] == '12') { $hourformat = 'h'; } @@ -556,24 +531,9 @@ 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; - } - } - + + $can_edit = $this->bo->can_user_edit($event); + if($can_edit == False) { header('Location: '.$this->page('view','&cal_id='.$cal_id)); @@ -581,24 +541,24 @@ } elseif(isset($readsess)) { - $event = unserialize(str_replace('O:8:"stdClass"','O:13:"calendar_time"',serialize($phpgw->session->appsession('entry','calendar')))); + $event = $this->bo->restore_from_appsession; if($event->owner == 0) { - $this->so->add_attribute('owner',$this->owner); + $this->bo->add_attribute('owner',$this->bo->owner); } $can_edit = True; } else { - if($this->bo->check_perms(PHPGW_ACL_ADD) == False) + if(!$this->bo->check_perms(PHPGW_ACL_ADD)) { header('Location: '.$this->page('view','&cal_id='.$cal_id)); } - $this->so->event_init(); - $this->so->add_attribute('id',0); + $this->bo->event_init(); + $this->bo->add_attribute('id',0); $can_edit = True; @@ -620,22 +580,22 @@ $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->bo->set_start($this->bo->year,$this->bo->month,$this->bo->day,$thishour,$thisminute,0); + $this->bo->set_end($this->bo->year,$this->bo->month,$this->bo->day,$thishour,$thisminute,0); + $this->bo->set_title(''); + $this->bo->set_description(''); + $this->bo->add_attribute('priority',2); + if($this->bo->prefs['calendar']['default_private'] == 'Y' || $this->bo->prefs['calendar']['default_private'] == True) { - $this->so->set_class(False); + $this->bo->set_class(False); } else { - $this->so->set_class(True); + $this->bo->set_class(True); } - $this->so->set_recur_none(); - $event = $this->so->get_cached_event(); + $this->bo->set_recur_none(); + $event = $this->bo->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; @@ -672,8 +632,8 @@ $errormsg = ''; } - $common_hidden = ''."\n" - . ''."\n"; + $common_hidden = ''."\n" + . ''."\n"; $vars = Array( 'font' => $phpgw_info['theme']['font'], @@ -689,19 +649,19 @@ // Brief Description $var[] = Array( 'field' => lang('Title'), - 'data' => '' + 'data' => '' ); // Full Description $var[] = Array( 'field' => lang('Full Description'), - 'data' => ''.$event->description.'' + 'data' => ''.$event->description.'' ); // Display Categories $var[] = Array( 'field' => lang('Category'), - 'data' => ''.lang('Choose the category').''.$this->cat->formated_list('select','all',$event->category,True).'' + 'data' => ''.lang('Choose the category').''.$this->cat->formated_list('select','all',$event->category,True).'' ); // Date @@ -715,7 +675,7 @@ // Time $amsel = ' checked'; $pmsel = ''; - if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12') + if ($this->bo->prefs['common']['timeformat'] == '12') { if ($event->start->hour >= 12) { @@ -723,7 +683,7 @@ } } $str = ':'; - if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12') + if ($this->bo->prefs['common']['timeformat'] == '12') { $str .= 'am'; $str .= 'pm'; @@ -744,7 +704,7 @@ // End Time $amsel = ' checked'; $pmsel = ''; - if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12') + if ($this->bo->prefs['common']['timeformat'] == '12') { if ($event->end->hour >= 12) { @@ -753,7 +713,7 @@ } $str = ':'; - if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12') + if ($this->bo->prefs['common']['timeformat'] == '12') { $str .= 'am'; $str .= 'pm'; @@ -766,11 +726,11 @@ // Priority $var[] = Array( 'field' => lang('Priority'), - 'data' => $sb->getPriority('priority',$event->priority) + 'data' => $sb->getPriority('cal[priority]',$event->priority) ); // Access - $str = 'public != True) { $str .= ' checked'; @@ -862,7 +822,6 @@ $p->parse('row','hr',True); $p->set_var('hr_text',''.lang('Repeating Event Information').''); $p->parse('row','hr',True); - $str = ''; $rpt_type = Array( MCAL_RECUR_NONE, MCAL_RECUR_DAILY, @@ -879,6 +838,7 @@ MCAL_RECUR_MONTHLY_MDAY => 'Monthly (by date)', MCAL_RECUR_YEARLY => 'Yearly' ); + $str = ''; for($l=0;$l $str ); - $str = 'recur_enddate->year != 0 && $event->recur_enddate->month != 0 && $event->recur_enddate->mday != 0) { @@ -933,7 +893,7 @@ $var[] = Array( 'field' => lang('Frequency'), - 'data' => '' + 'data' => '' ); for($i=0;$ifooter(); } - /* Private functions */ + function update() + { + global $phpgw, $phpgw_info, $readsess, $cal, $participants, $start, $end, $recur_enddate; + if(!isset($readsess)) + { + $this->bo->fix_update_time($start); + $this->bo->fix_update_time($end); + + if(!isset($cal[private])) + { + $cal[private] = 'public'; + } + + $is_public = ($private == 'public'?1:0); + $this->bo->event_init(); + $this->bo->set_category($cal[category]); + $this->bo->set_title($cal[title]); + $this->bo->set_description($cal[description]); + $this->bo->set_start($start[year],$start[month],$start[mday],$start[hour],$start[min],0); + $this->bo->set_end($end[year],$end[month],$end[mday],$end[hour],$end[min],0); + $this->bo->set_class($is_public); + if($cal[id] != 0) + { + $this->bo->add_attribute('id',$cal[id]); + } + + if($cal[rpt_use_end] != 'y') + { + $recur_enddate[year] = 0; + $recur_enddate[month] = 0; + $recur_enddate[mday] = 0; + } + $cal[recur_data] = $cal[rpt_sun] + $cal[rpt_mon] + $cal[rpt_tue] + $cal[rpt_wed] + $cal[rpt_thu] + $cal[rpt_fri] + $cal[rpt_sat]; + + switch($cal[recur_type]) + { + case MCAL_RECUR_NONE: + $this->bo->set_recur_none(); + break; + case MCAL_RECUR_DAILY: + $this->bo->set_recur_daily($recur_enddate[year],$recur_enddate[month],$recur_enddate[mday],$cal[recur_interval]); + break; + case MCAL_RECUR_WEEKLY: + $this->bo->set_recur_weekly($recur_enddate[year],$recur_enddate[month],$recur_enddate[mday],$cal[recur_interval],$cal[recur_data]); + break; + case MCAL_RECUR_MONTHLY_MDAY: + $this->bo->set_recur_monthly_mday($recur_enddate[year],$recur_enddate[month],$recur_enddate[mday],$cal[recur_interval]); + break; + case MCAL_RECUR_MONTHLY_WDAY: + $this->bo->set_recur_monthly_wday($recur_enddate[year],$recur_enddate[month],$recur_enddate[mday],$cal[recur_interval]); + break; + case MCAL_RECUR_YEARLY: + $this->bo->set_recur_yearly($recur_enddate[year],$recur_enddate[month],$recur_enddate[mday],$cal[recur_interval]); + break; + } + + $parts = $participants; + $minparts = min($participants); + $part = Array(); + for($i=0;$iaccounts->get_type(intval($parts[$i])); + if($acct_type == 'u') + { + $part[$parts[$i]] = 1; + } + elseif($acct_type == 'g') + { + /* This pulls ALL users of a group and makes them as participants to the event */ + /* I would like to turn this back into a group thing. */ + $acct = CreateObject('phpgwapi.accounts',intval($parts[$i])); + $members = $acct->members(intval($parts[$i])); + unset($acct); + if($members == False) + { + continue; + } + while($member = each($members)) + { + $part[$member[1]['account_id']] = 1; + } + } + } + + @reset($part); + while(list($key,$value) = each($part)) + { + $this->bo->add_attribute('participants['.$key.']','U'); + } + + reset($participants); + if(!@$phpgw->calendar->event->participants[$cal[owner]]) + { + $this->bo->add_attribute('owner',$minparts); + } + $this->bo->add_attribute('priority',$cal[priority]); + $event = $this->bo->get_cached_event(); + + $this->bo->store_to_appsession($event); + $datetime_check = $this->bo->validate_update($event); + if($datetime_check) + { + Header('Location: '.$this->page('edit','&readsess='.$event->id.'&cd='.$datetime_check)); + } + + $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; + + $overlapping_events = $this->bo->overlap($start,$end,$event->participants,$event->owner,$event->id); + } + else + { + $event = $this->bo->restore_from_appsession(); + $datetime_check = $this->bo->validate_update($event); + $overlapping_events = False; + if($datetime_check) + { + Header('Location: '.$this->page('edit','&readsess='.$event->id.'&cd='.$datetime_check)); + } + } + + if(count($overlapping_events) > 0 && $overlapping_events != False) + { + $phpgw->common->phpgw_header(); + echo parse_navbar(); + + $p = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('calendar')); + $templates = Array( + 'overlap' => 'overlap.tpl', + 'form_button' => 'form_button_script.tpl' + ); + $p->set_file($templates); + + $p->set_var('color',$phpgw_info['theme']['bg_text']); + $p->set_var('overlap_title',lang('Scheduling Conflict')); + + $overlap = ''; + for($i=0;$ibo->read_entry($overlapping_events[$i]); + $overlap .= ''.$this->link_to_entry($over,$event->start->month,$event->start->mday,$event->start->year); + } + if(strlen($overlap) > 0) + { + $var = Array( + 'overlap_text' => lang('Your suggested time of x - x conflicts with the following existing calendar entries:',$phpgw->common->show_date($start),$phpgw->common->show_date($end)), + 'overlap_list' => $overlap + ); + } + else + { + $var = Array( + 'overlap_text' => '', + 'overlap_list' => '' + ); + } + + $p->set_var($var); +// $phpgw->calendar->event = $event; + + $var = Array( + 'action_url_button' => $this->page('update','&readsess='.$event->id.'&year='.$event->start->year.'&month='.$event->start->month.'&day='.$event->start->mday), + 'action_text_button' => lang('Ignore Conflict'), + 'action_confirm_button' => '', + 'action_extra_field' => '' + ); + $p->set_var($var); + + $p->parse('resubmit_button','form_button'); + + $var = Array( + 'action_url_button' => $this->page('update','&readsess='.$event->id.'&year='.$event->start->year.'&month='.$event->start->month.'&day='.$event->start->mday), + 'action_text_button' => lang('Re-Edit Event'), + 'action_confirm_button' => '', + 'action_extra_field' => '' + ); + $p->set_var($var); + + $p->parse('reedit_button','form_button'); + + $p->pparse('out','overlap'); +// $phpgw_info['flags']['nofooter'] = False; +// $phpgw->common->phpgw_footer(); + $this->footer(); + } + else + { + if(!$event->id) + { + $this->bo->add_entry($event); + } + elseif($event->id) + { + $this->bo->update_entry($event); + } + + Header('Location: '.$this->page('','&year='.$event->start->year.'&month='.$event->start->month.'&day='.$event->start->mday.'&cd=14&owner='.$this->bo->owner)); + } + } + + function delete() + { + global $cal_id; + $event = $this->bo->read_entry(intval($cal_id)); + if(($cal_id > 0) && ($event->owner == $this->bo->owner) && ($this->bo->check_perms(PHPGW_ACL_DELETE) == True)) + { + $date = sprintf("%04d%02d%02d",$event->start->year,$event->start->month,$event->start->mday); + + $this->bo->delete_entry(intval($cal_id)); + $this->bo->expunge(); + } + else + { + $date = sprintf("%04d%02d%02d",$this->bo->year,$this->bo->month,$this->bo->day); + } + Header('Location: '.$this->page('','&date='.$date)); + } + + function preferences() + { + global $phpgw, $phpgw_info, $submit, $prefs; + if ($submit) + { + $phpgw->preferences->read_repository(); + $phpgw->preferences->add('calendar','weekdaystarts',$prefs[weekdaystarts]); + $phpgw->preferences->add('calendar','workdaystarts',$prefs[workdaystarts]); + $phpgw->preferences->add('calendar','workdayends',$prefs[workdayends]); + $phpgw->preferences->add('calendar','defaultcalendar',$prefs[defaultcalendar]); + $phpgw->preferences->add('calendar','defaultfilter',$prefs[defaultfilter]); + $phpgw->preferences->add('calendar','interval',$prefs[interval]); + if ($prefs[mainscreen_showevents] == True) + { + $phpgw->preferences->add('calendar','mainscreen_showevents',$prefs[mainscreen_showevents]); + } + else + { + $phpgw->preferences->delete('calendar','mainscreen_showevents'); + } + if ($prefs[send_updates] == True) + { + $phpgw->preferences->add('calendar','send_updates',$prefs[send_updates]); + } + else + { + $phpgw->preferences->delete('calendar','send_updates'); + } + + if ($prefs[display_status] == True) + { + $phpgw->preferences->add('calendar','display_status',$prefs[display_status]); + } + else + { + $phpgw->preferences->delete('calendar','display_status'); + } + + if ($prefs[default_private] == True) + { + $phpgw->preferences->add('calendar','default_private',$prefs[default_private]); + } + else + { + $phpgw->preferences->delete('calendar','default_private'); + } + + if ($prefs[display_minicals] == True) + { + $phpgw->preferences->add('calendar','display_minicals',$prefs[display_minicals]); + } + else + { + $phpgw->preferences->delete('calendar','display_minicals'); + } + + if ($prefs[print_black_white] == True) + { + $phpgw->preferences->add('calendar','print_black_white',$prefs[print_black_white]); + } + else + { + $phpgw->preferences->delete('calendar','print_black_white'); + } + + $phpgw->preferences->save_repository(True); + + Header('Location: '.$phpgw->link('/preferences/index.php')); + $phpgw->common->phpgw_exit(); + } + + $phpgw->common->phpgw_header(); + echo parse_navbar(); + + $p = CreateObject('phpgwapi.Template',$this->template_dir); + $templates = Array( + 'pref' => 'pref.tpl', + 'pref_colspan' => 'pref_colspan.tpl', + 'pref_list' => 'pref_list.tpl' + ); + $p->set_file($templates); + + $var = Array( + 'title' => lang('Calendar preferences'), + 'action_url' => $this->page('preferences'), + 'bg_color' => $phpgw_info['theme']['th_bg'], + 'submit_lang' => lang('submit'), + 'text' => ' ' + ); + + $this->output_template_array($p,'row','pref_colspan',$var); + +// if ($totalerrors) +// { +// echo '' . $phpgw->common->error_list($errors) . ''; +// } + + $str = 'bo->prefs['calendar']['mainscreen_showevents'] == 'Y' || $this->bo->prefs['calendar']['mainscreen_showevents'] == True?' checked':'').'>'; + $this->display_item($p,lang('show day view on main screen'),$str); + + $t_weekday[$this->bo->prefs['calendar']['weekdaystarts']] = ' selected'; + $str = '' + . ''.lang('Monday').'' + . ''.lang('Sunday').'' +// The following is for Arabic support..... + . ''.lang('Saturday').'' + . ''; + $this->display_item($p,lang('weekday starts on'),$str); + + $t_workdaystarts[$this->bo->prefs['calendar']['workdaystarts']] = ' selected'; + $str = ''; + for ($i=0; $i<24; $i++) + { + $str .= '' + . $phpgw->common->formattime($i,'00') . ''; + } + $str .= ''; + $this->display_item($p,lang('work day starts on'),$str); + + $t_workdayends[$this->bo->prefs['calendar']['workdayends']] = ' selected'; + $str = ''; + for ($i=0; $i<24; $i++) + { + $str .= '' + . $phpgw->common->formattime($i,'00') . ''; + } + $str .= ''; + $this->display_item($p,lang('work day ends on'),$str); + + if(strpos('.',$this->bo->prefs['calendar']['defaultcalendar'])) + { + $temp = explode('.',$this->bo->prefs['calendar']['defaultcalendar']); + $this->bo->prefs['calendar']['defaultcalendar'] = $temp[0]; + } + $selected[$this->bo->prefs['calendar']['defaultcalendar']] = ' selected'; + if (!isset($this->bo->prefs['calendar']['defaultcalendar'])) + { + $selected['month'] = ' selected'; + } + $str = '' + . ''.lang('Yearly').'' + . ''.lang('Monthly').'' + . ''.lang('Weekly').'' + . ''.lang('Daily').'' + . ''; + $this->display_item($p,lang('default calendar view'),$str); + + $selected = array(); + $selected[$this->bo->prefs['calendar']['defaultfilter']] = ' selected'; + if (! isset($this->bo->prefs['calendar']['defaultfilter']) || $this->bo->prefs['calendar']['defaultfilter'] == 'private') + { + $selected['private'] = ' selected'; + } + $str = '' + . ''.lang('all').'' + . ''.lang('private only').'' +// . ''.lang('global public only').'' +// . ''.lang('group public only').'' +// . ''.lang('private and global public').'' +// . ''.lang('private and group public').'' +// . ''.lang('global public and group public').'' + . ''; + $this->display_item($p,lang('Default calendar filter'),$str); + + $selected = array(); + $selected[intval($this->bo->prefs['calendar']['interval'])] = ' selected'; + if (! isset($this->bo->prefs['calendar']['interval'])) + { + $selected[60] = ' selected'; + } + $var = Array( + 5 => '5', + 10 => '10', + 15 => '15', + 20 => '20', + 30 => '30', + 45 => '45', + 60 => '60' + ); + + $str = ''; + while(list($key,$value) = each($var)) + { + $str .= ''.$value.''; + } + $str .= ''; + $this->display_item($p,lang('Display interval in Day View'),$str); + + $str = 'bo->prefs['calendar']['send_updates'] == 'Y' || $this->bo->prefs['calendar']['send_updates'] == True?' checked':'').'>'; + $this->display_item($p,lang('Send/receive updates via email'),$str); + + $str = 'bo->prefs['calendar']['display_status'] == 'Y' || $this->bo->prefs['calendar']['display_status'] == True?' checked':'').'>'; + $this->display_item($p,lang('Display status of events'),$str); + + $str = 'bo->prefs['calendar']['default_private'] == 'Y' || $this->bo->prefs['calendar']['default_private'] == True?' checked':'').'>'; + $this->display_item($p,lang('When creating new events default set to private'),$str); + + $str = 'bo->prefs['calendar']['display_minicals'] == 'Y' || $this->bo->prefs['calendar']['display_minicals'] == True?' checked':'').'>'; + $this->display_item($p,lang('Display mini calendars when printing'),$str); + + $str = 'bo->prefs['calendar']['print_black_white'] == 'Y' || $this->bo->prefs['calendar']['print_black_white'] == True?' checked':'').'>'; + $this->display_item($p,lang('Print calendars in black & white'),$str); + + $p->pparse('out','pref'); + $phpgw->common->phpgw_footer(); + } + + function day() + { + global $phpgw; + + $this->bo->read_holidays(); + + $p = CreateObject('phpgwapi.Template',$this->template_dir); + + $template = Array( + 'day_t' => 'day.tpl' + ); + + $p->set_file($template); + + if (!$this->bo->printer_friendly) + { + $phpgw->common->phpgw_header(); + echo parse_navbar(); + $printer = ''; + $param = '&year='.$this->bo->year.'&month='.$this->bo->month.'&day='.$this->bo->day.'&friendly=1'; + $print = '[".lang('Printer Friendly').']'; + $minical = $this->mini_calendar($this->bo->day,$this->bo->month,$this->bo->year,'day'); + } + else + { + $printer = ''; + $print = ''; + if($this->bo->prefs['calendar']['display_minicals'] == 'Y' || $this->bo->prefs['calendar']['display_minicals']) + { + $minical = $this->mini_calendar($this->bo->day,$this->bo->month,$this->bo->year,'day'); + } + else + { + $minical = ''; + } + } + + + $now = $this->bo->datetime->makegmttime(0, 0, 0, $this->bo->month, $this->bo->day, $this->bo->year); + $now['raw'] += $this->bo->datetime->tz_offset; + $m = mktime(0,0,0,$this->bo->month,1,$this->bo->year); + + $var = Array( + 'printer_friendly' => $printer, + 'bg_text' => $phpgw_info['themem']['bg_text'], + 'daily_events' => $this->print_day($this->bo->year,$this->bo->month,$this->bo->day), + 'small_calendar' => $minical, + 'date' => lang(date('F',$m)).' '.sprintf("%02d",$this->bo->day).', '.$this->bo->year, + 'username' => $phpgw->common->grab_owner_name($owner), + 'print' => $print + ); + + $p->set_var($var); + + $p->pparse('out','day_t'); + if(!$this->so->printer_friendly) + { + $phpgw->common->phpgw_footer(); + } + else + { + $phpgw->common->phpgw_exit(); + } + } + + /* Private functions */ function _debug_sqsof() { $data = array( - 'filter' => $this->filter, - 'cat_id' => $this->cat_id, - 'owner' => $this->owner, + 'filter' => $this->bo->filter, + 'cat_id' => $this->bo->cat_id, + 'owner' => $this->bo->owner, 'year' => $this->bo->year, 'month' => $this->bo->month, 'day' => $this->bo->day @@ -985,9 +1435,9 @@ function save_sessiondata() { $data = array( - 'filter' => $this->filter, - 'cat_id' => $this->cat_id, - 'owner' => $this->owner, + 'filter' => $this->bo->filter, + 'cat_id' => $this->bo->cat_id, + 'owner' => $this->bo->owner, 'year' => $this->bo->year, 'month' => $this->bo->month, 'day' => $this->bo->day @@ -1001,13 +1451,25 @@ $p->parse($row,$list,True); } + function display_item(&$p,$field,$data) + { + global $phpgw, $tr_color; + $tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color); + $var = Array( + 'bg_color' => $tr_color, + 'field' => $field, + 'data' => $data + ); + $this->output_template_array($p,'row','pref_list',$var); + } + function page($page='',$params='') { global $phpgw, $phpgw_info; if($page == '') { - $page_ = explode('.',$this->prefs['defaultcalendar']); + $page_ = explode('.',$this->bo->prefs['calendar']['defaultcalendar']); $page = $page_[0]; if ($page=='index' || ($page != 'day' && $page != 'week' && $page != 'month' && $page != 'year')) { @@ -1023,8 +1485,7 @@ { 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; + global $phpgw, $cal_id, $date, $keywords, $matrixtype, $participants, $remainder, $tpl, $menuaction; } $cols = 8; @@ -1044,7 +1505,7 @@ { global $phpgw; - if (@$this->printer_friendly) + if (@$this->bo->printer_friendly) { $phpgw->common->phpgw_footer(); $phpgw->common->phpgw_exit(); @@ -1168,8 +1629,8 @@ global $phpgw, $phpgw_info, $grants; $str = ''; - $is_private = $this->bo->is_private($event,$this->owner); - $editable = ((!$this->printer_friendly) && (($is_private && $this->bo->check_perms(PHPGW_ACL_PRIVATE)) || !$is_private)); + $is_private = $this->bo->is_private($event,$this->bo->owner); + $editable = ((!$this->bo->printer_friendly) && (($is_private && $this->bo->check_perms(PHPGW_ACL_PRIVATE)) || !$is_private)); $p = CreateObject('phpgwapi.Template',$this->template_dir); $p->set_unknowns('remove'); $templates = Array( @@ -1190,7 +1651,7 @@ $nextday = mktime(0,0,0,$month,$day + 1,$year) - $this->bo->datetime->tz_offset; if (intval($phpgw->common->show_date($starttime,'Hi')) && $starttime == $endtime) { - $time = $phpgw->common->show_date($starttime,$this->users_timeformat); + $time = $phpgw->common->show_date($starttime,$this->bo->users_timeformat); } elseif ($starttime <= $rawdate_offset && $endtime >= $nextday - 60) { @@ -1200,20 +1661,20 @@ { if($starttime < $rawdate_offset && $event->recur_type==MCAL_RECUR_NONE) { - $start_time = $phpgw->common->show_date($rawdate_offset,$this->users_timeformat); + $start_time = $phpgw->common->show_date($rawdate_offset,$this->bo->users_timeformat); } else { - $start_time = $phpgw->common->show_date($starttime,$this->users_timeformat); + $start_time = $phpgw->common->show_date($starttime,$this->bo->users_timeformat); } if($endtime >= ($rawdate_offset + 86400)) { - $end_time = $phpgw->common->show_date(mktime(23,59,59,$month,$day,$year) - $this->bo->datetime->tz_offset,$this->users_timeformat); + $end_time = $phpgw->common->show_date(mktime(23,59,59,$month,$day,$year) - $this->bo->datetime->tz_offset,$this->bo->users_timeformat); } else { - $end_time = $phpgw->common->show_date($endtime,$this->users_timeformat); + $end_time = $phpgw->common->show_date($endtime,$this->bo->users_timeformat); } $time = $start_time.'-'.$end_time; } @@ -1323,7 +1784,7 @@ 'bgcolor' => $phpgw_info['theme']['th_bg'], 'font_color' => $phpgw_info['theme']['th_text'] ); - if($this->printer_friendly && @$this->preferences['print_black_white']) + if($this->bo->printer_friendly && @$this->bo->prefs['calendar']['print_black_white']) { $var = Array( 'bgcolor' => '', @@ -1354,8 +1815,8 @@ if($owner == 0) { $owner= $phpgw_info['user']['account_id']; } - $temp_owner = $this->owner; - $this->owner = $owner; + $temp_owner = $this->bo->owner; + $this->bo->owner = $owner; $str = ''; $p = CreateObject('phpgwapi.Template',$this->template_dir); @@ -1454,7 +1915,7 @@ $p->set_var('events',''); if($day_params['week']) { - if(!$this->printer_friendly) + if(!$this->bo->printer_friendly) { $str = '' .$day_params['week'].''; } @@ -1473,7 +1934,7 @@ $p->parse('column_header','month_column',True); $p->set_var('column_data',''); } - $this->owner = $temp_owner; + $this->bo->owner = $temp_owner; return $p->fp('out','monthly_header'); } @@ -1481,11 +1942,6 @@ { global $phpgw, $phpgw_info; -// if($owner == $phpgw_info['user']['account_id']) -// { -// $owner = 0; -// } - $this->bo->store_to_cache($year,$month,1); $monthstart = intval(date('Ymd',mktime(0,0,0,$month ,1,$year))); @@ -1538,7 +1994,7 @@ $cellcolor = $phpgw_info['theme']['row_off']; - $true_printer_friendly = $this->printer_friendly; + $true_printer_friendly = $this->bo->printer_friendly; if(is_array($owners)) { @@ -1557,7 +2013,7 @@ $p->set_var('day_events',$this->week_header($month,$year,$display_name)); $p->parse('row','event',True); - $original_owner = $this->so->owner; + $original_owner = $this->bo->owner; for($i=0;$i<$counter;$i++) { $this->so->owner = $owners_array[$i]; @@ -1565,8 +2021,8 @@ $p->set_var('day_events',$this->display_week($start,True,$cellcolor,$display_name,$owners_array[$i])); $p->parse('row','event',True); } - $this->so->owner = $original_owner; - $this->printer_friendly = $true_printer_friendly; + $this->bo->owner = $original_owner; + $this->bo->printer_friendly = $true_printer_friendly; return $p->fp('out','m_w_table'); } @@ -1618,7 +2074,7 @@ if ($event->category) { - $this->cat->categories($this->owner,'calendar'); + $this->cat->categories($this->bo->owner,'calendar'); $cat = $this->cat->return_single($event->category); $var[] = Array( 'field' => lang('Category'), @@ -1732,7 +2188,7 @@ if($event->recur_type == MCAL_RECUR_WEEKLY || $event->recur_type == MCAL_RECUR_DAILY) { $repeat_days = ''; - if($this->prefs['weekdaystarts'] == 'Sunday') + if($this->bo->prefs['calendar']['weekdaystarts'] == 'Sunday') { if (!!($event->recur_data & MCAL_M_SUNDAY) == True) { @@ -1763,7 +2219,7 @@ { $this->view_add_day(lang('Saturday'),$repeat_days); } - if($phpgw_info['user']['preferences']['calendar']['weekdaystarts'] == 'Monday') + if($this->bo->prefs['calendar']['weekdaystarts'] == 'Monday') { if (!!($event->recur_data & MCAL_M_SUNDAY) == True) { @@ -1798,5 +2254,280 @@ return $p->fp('out','view_event'); } + + function html_for_day($event,$first_hour,$last_hour,&$time,$month,$day,$year,&$rowspan,&$rowspan_arr) + { + $ind = intval($event->start->hour); + + if($ind<$first_hour || $ind>$last_hour) + { + $ind = 99; + } + + if(!isset($time[$ind]) || !$time[$ind]) + { + $time[$ind] = ''; + } + + $time[$ind] .= $this->link_to_entry($event,$month,$day,$year); + + $starttime = mktime($event->start->hour,$event->start->min,$event->start->sec,$event->start->month,$event->start->mday,$event->start->year); + $endtime = mktime($event->end->hour,$event->end->min,$event->end->sec,$event->end->month,$event->end->mday,$event->end->year); + + if ($starttime <> $endtime) + { + $rowspan = (int)(($endtime - $starttime) / 3600); + $mins = (int)((($endtime - $starttime) / 60) % 60); + + if ($mins <> 0) + { + $rowspan += 1; + } + + if ($rowspan > $rowspan_arr[$ind] && $rowspan > 1) + { + $rowspan_arr[$ind] = $rowspan; + } + } + } + + function print_day($year,$month,$day) + { + global $phpgw, $phpgw_info; + + $this->bo->store_to_cache($year,$month,$day); + + $p = CreateObject('phpgwapi.Template',$this->template_dir); + $p->set_unknowns('keep'); + + $templates = Array( + 'day_cal' => 'day_cal.tpl' + ); + $p->set_file($templates); + $p->set_block('day_cal','day','day'); + $p->set_block('day_cal','day_row','day_row'); + $p->set_block('day_cal','day_event','day_event'); + $p->set_block('day_cal','day_time','day_time'); + + if (! $this->bo->prefs['calendar']['workdaystarts'] && + ! $this->bo->prefs['calendar']['workdayends']) + { + + $phpgw->preferences->add('calendar','workdaystarts',8); + $phpgw->preferences->add('calendar','workdayends',16); + $phpgw->preferences->save_repository(); + $this->bo->prefs['calendar']['workdaystarts'] = 8; + $this->bo->prefs['calendar']['workdayends'] = 16; + } + + $t_format = $this->bo->prefs['common']['time_format']; + $phpgw->browser->browser(); + $browser_agent = $phpgw->browser->get_agent(); + if($browser_agent == 'MOZILLA') + { + if($t_format == '12') + { + $time_width=12; + } + else + { + $time_width=8; + } + } + else + { + if($t_format == '12') + { + $time_width=10; + } + else + { + $time_width=7; + } + } + $var = Array( + 'time_width' => $time_width, + 'time_bgcolor' => $phpgw_info['theme']['navbar_bg'], + 'font_color' => $phpgw_info['theme']['bg_text'], + 'time_border_color' => $phpgw_info['theme']['navbar_text'], + 'font' => $phpgw_info['theme']['font'] + ); + + $p->set_var($var); + + $first_hour = (int)$this->bo->prefs['calendar']['workdaystarts']; + $last_hour = (int)$this->bo->prefs['calendar']['workdayends']; + + for ($i=0;$i<24;$i++) + { + $this->rowspan_arr[$i] = 0; + } + + $events = Array( + CreateObject('calendar.calendar_item') + ); + $date_to_eval = sprintf("%04d%02d%02d",$year,$month,$day); + echo "DATE TO EVAL : $date_to_eval\n"; + echo "ITEMS FOUND : ".count($this->bo->cached_events[$date_to_eval])."\n"; + + while(list($cached_date,$event) = each($this->bo->cached_events)) + { + echo "Cached Events for : $cached_date : ".count($event)."\n"; + } + + $time = Array(); + + $cellcolor = $phpgw_info['theme']['row_on']; + $daily = $this->bo->set_week_array($this->bo->datetime->get_weekday_start($year, $month, $day),$cellcolor,True); + +// $events = $this->bo->cached_events[$date_to_eval]; + + echo "Extra params for $date_to_eval : ".$daily[$date_to_eval]['extra']."\n"; + + if($this->bo->cached_events[$date_to_eval]) + { + $events = $this->bo->cached_events[$date_to_eval]; + $c_events = count($events); + echo "Looping $c_events times\n"; + for($i=0;$i<$c_events;$i++) + { + $this->html_for_day($events[$i],$first_hour,$last_hour,$time,$month,$day,$year,$rowspan,$rowspan_arr); + } + } + + // squish events that use the same cell into the same cell. + // For example, an event from 8:00-9:15 and another from 9:30-9:45 both + // want to show up in the 8:00-9:59 cell. + $rowspan = 0; + $last_row = -1; + for ($i=0;$i<24;$i++) + { + if ($rowspan > 1) + { + if (isset($time[$i]) && strlen($time[$i]) > 0) + { + $rowspan_arr[$last_row] += $rowspan_arr[$i]; + if ($rowspan_arr[$i] <> 0) + { + $rowspan_arr[$last_row] -= 1; + } + $time[$last_row] .= $time[$i]; + $time[$i] = ''; + $rowspan_arr[$i] = 0; + } + $rowspan--; + } + elseif ($rowspan_arr[$i] > 1) + { + $rowspan = $rowspan_arr[$i]; + $last_row = $i; + } + } + + $holiday_names = $daily[$date_to_eval]['holidays']; + if(!$holiday_names) + { + $bgcolor = $phpgw->nextmatchs->alternate_row_color(); + } + else + { + $bgcolor = $phpgw_info['theme']['bg04']; + while(list($index,$name) = each($holiday_names)) + { + $time[99] = ''.$name.''.$time[99]; + } + } + + if (isset($time[99]) && strlen($time[99]) > 0) + { + $var = Array( + 'event' => $time[99], + 'bgcolor' => $bgcolor + ); + $p->set_var($var); + $p->parse('item','day_event',False); + + $var = Array( + 'open_link' => '', + 'time' => ' ', + 'close_link' => '' + ); + $p->set_var($var); + + $p->parse('item','day_time',True); + $p->parse('row','day_row',True); + $p->set_var('item',''); + } + $rowspan = 0; + for ($i=$first_hour;$i<=$last_hour;$i++) + { + $dtime = $this->bo->build_time_for_display($i * 10000); + $p->set_var('extras',''); + $p->set_var('event',' '); + if ($rowspan > 1) + { + // this might mean there's an overlap, or it could mean one event + // ends at 11:15 and another starts at 11:30. + if (isset($time[$i]) && strlen($time[$i])) + { + $p->set_var('event',$time[$i]); + $p->set_var('bgcolor',$phpgw->nextmatchs->alternate_row_color()); + $p->parse('item','day_event',False); + } + $rowspan--; + } + elseif (!isset($time[$i]) || !strlen($time[$i])) + { + $p->set_var('event',' '); + $p->set_var('bgcolor',$phpgw->nextmatchs->alternate_row_color()); + $p->parse('item','day_event',False); + } + else + { + $rowspan = intval($rowspan_arr[$i]); + if ($rowspan > 1) + { + $p->set_var('extras',' rowspan="'.$rowspan.'"'); + } + $p->set_var('event',$time[$i]); + $p->set_var('bgcolor',$phpgw->nextmatchs->alternate_row_color()); + $p->parse('item','day_event',False); + } + + $open_link = ' - '; + $close_link = ''; + + if(!$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_ADD)) + { + $new_hour = intval(substr($dtime,0,strpos($dtime,':'))); + if ($this->bo->prefs['common']['timeformat'] == '12' && $i >= 12) + { + $new_hour += 12; + } + + $new_minute = substr($dtime,strpos($dtime,':')+1,2); + + $open_link .= ''; + + $close_link = ''; + } + + $var = Array( + 'open_link' => $open_link, + 'time' => (intval(substr($dtime,0,strpos($dtime,':'))) < 10 ? '0'.$dtime : $dtime), + 'close_link' => $close_link + ); + + $p->set_var($var); + + $p->parse('item','day_time',True); + $p->parse('row','day_row',True); + $p->set_var('event',''); + $p->set_var('item',''); + } // end for + return $p->fp('out','day'); + } // end function } ?>