diff --git a/calendar/day.php b/calendar/day.php index 8ce4e03b76..c9ed6b12ee 100644 --- a/calendar/day.php +++ b/calendar/day.php @@ -37,7 +37,7 @@ include('../header.inc.php'); $view = 'day'; - $now = $phpgw->calendar->splitdate(mktime (0, 0, 0, $thismonth, $thisday, $thisyear) - ((60 * 60) * $phpgw_info['user']['preferences']['common']['tz_offset'])); + $now = $phpgw->calendar->makegmttime(0, 0, 0, $thismonth, $thisday, $thisyear); $template = Array( 'day_t' => 'day.tpl' @@ -62,7 +62,7 @@ $phpgw->template->set_var('date',lang(date('F',$m)).' '.$thisday.', '.$thisyear); $phpgw->template->set_var('username',$phpgw->common->grab_owner_name($owner)); $phpgw->template->set_var('daily_events',$phpgw->calendar->print_day_at_a_glance($now,$owner)); - $phpgw->template->set_var('small_calendar',$phpgw->calendar->mini_calendar($now['day'],$now['month'],$now['year'],'day.php')); + $phpgw->template->set_var('small_calendar',$phpgw->calendar->mini_calendar($thisday,$thismonth,$thisyear,'day.php')); if (!$friendly) { diff --git a/calendar/inc/class.calendar_sql.inc.php b/calendar/inc/class.calendar_sql.inc.php index 7c3ee82011..bf75942da9 100755 --- a/calendar/inc/class.calendar_sql.inc.php +++ b/calendar/inc/class.calendar_sql.inc.php @@ -120,1624 +120,2175 @@ return $this->cal_event; } - function set_filter() { - global $phpgw_info, $phpgw, $filter; - if (!isset($this->filter) || !$this->filter) { - if (isset($filter) && $filter) { - $this->filter = ' '.$filter.' '; - } else { - if (! $phpgw_info['user']['preferences']['calendar']['defaultfilter']) { - $phpgw->preferences->change('calendar','defaultfilter','all'); - $phpgw->preferences->commit(); - } - $this->filter = ' '.$phpgw_info['user']['preferences']['calendar']['defaultfilter'].' '; - } - } - } - - function check_perms($needed) - { - if($this->rights & $needed) - { - return True; - } - else - { - return False; - } - } - - function group_search($owner=0) { - global $phpgw, $phpgw_info; - - $owner = $owner==$phpgw_info['user']['account_id']?0:$owner; - $groups = substr($phpgw->common->sql_search('calendar_entry.cal_group',intval($owner)),4); - if (!$groups) { - return ''; - } else { - return "(calendar_entry.cal_access='group' AND (". $groups .')) '; - } - } - - function get_weekday_start($year,$month,$day) { - global $phpgw; - global $phpgw_info; - - $weekday = date('w',mktime(0,0,0,$month,$day,$year)); - if ($phpgw_info['user']['preferences']['calendar']['weekdaystarts'] == 'Monday') { - $this->days = array(0 => 'Mon', 1 => 'Tue', 2 => 'Wed', 3 => 'Thu', 4 => 'Fri', 5 => 'Sat', 6 => 'Sun'); - if ($weekday == 0) - $sb = mktime(0,0,0,$month,$day - 6,$year); - if ($weekday == 1) - $sb = mktime(0,0,0,$month,$day,$year); - $sb = mktime(0,0,0,$month,$day - ($weekday - 1),$year); - } else { - $this->days = array(0 => 'Sun', 1 => 'Mon', 2 => 'Tue', 3 => 'Wed', 4 => 'Thu', 5 => 'Fri', 6 => 'Sat'); - $sb = mktime(0,0,0,$month,$day - $weekday,$year); - } - - return $sb; -// - ((60 * 60) * intval($phpgw_info['user']['preferences']['common']['tz_offset'])); - } - - function normalizeminutes(&$minutes) { - $hour = 0; - $min = intval($minutes); - if($min >= 60) { - $hour += $min / 60; - $min %= 60; - } - settype($minutes,'integer'); - $minutes = $min; - return $hour; - } - - function addduration($hour,$minute,$ampm,$duration) { - $minute += $duration; - return $this->fixtime($hour,$minute,$ampm); - } - - function fixtime($hour=0,$minute=0,$ampm='') { - global $phpgw_info; - - $hour += (int)$this->normalizeminutes(&$minute); - if ($hour > 0) { - if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12') { -// $hour %= 12; - if (strtolower($ampm) == 'pm' && $hour <> 12) { - $hour += 12; - } - } - } - return ($hour * 10000) + ($minute * 100); - } - - 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) { - 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 ($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 makegmttime($hour,$minute,$second,$month,$day,$year) { - global $phpgw; - global $phpgw_info; - - return $this->gmtdate(mktime($hour, $minute, $second, $month, $day, $year)); - } - - function localdates($localtime) { - global $phpgw; - global $phpgw_info; - - $date = Array('raw','day','month','year','full','dow','dm','bd'); - $date['raw'] = $localtime; - $date['year'] = intval($phpgw->common->show_date($date['raw'],'Y')); - $date['month'] = intval($phpgw->common->show_date($date['raw'],'m')); - $date['day'] = intval($phpgw->common->show_date($date['raw'],'d')); - $date['full'] = intval($phpgw->common->show_date($date['raw'],'Ymd')); - $date['bd'] = mktime(0,0,0,$date['month'],$date['day'],$date['year']); - $date['dm'] = intval($phpgw->common->show_date($date['raw'],'dm')); - $date['dow'] = intval($phpgw->common->show_date($date['raw'],'w')); - $date['hour'] = intval($phpgw->common->show_date($date['raw'],'H')); - $date['minute'] = intval($phpgw->common->show_date($date['raw'],'i')); - return $date; - } - - function gmtdate($localtime) { - global $phpgw_info; - - $localtime -= ((60 * 60) * intval($phpgw_info['user']['preferences']['common']['tz_offset'])); - return $this->localdates($localtime); - } - - function splitdate($date) { - $temp = array('day','month','year','full','raw','dayofweek'); - $temp['raw'] = intval($date); - $temp['day'] = intval(date('d',(int)$date)); - $temp['month'] = intval(date('m',(int)$date)); - $temp['year'] = intval(date('Y',(int)$date)); - $temp['full'] = intval(date('Ymd',(int)$date)); - $temp['dayofweek'] = intval(date('w',(int)$date)); - return $temp; - } - - function date_to_epoch($d) { - return $this->splitdate(mktime(0,0,0,intval(substr($d,4,2)),intval(substr($d,6,2)),intval(substr($d,0,4)))); - } - - function overlap($starttime,$endtime,$participants,$groups,$owner=0,$id=0) { - global $phpgw; - global $phpgw_info; - - $retval = Array(); - $ok = False; - - $starttime -= ((60 * 60) * $phpgw_info['user']['preferences']['common']['tz_offset']); - $endtime -= ((60 * 60) * $phpgw_info['user']['preferences']['common']['tz_offset']); - - if($starttime == $endtime) $endtime = mktime($phpgw->common->show_date($starttime,'H'),$phpgw->common->show_date($starttime,'i'),0,$phpgw->common->show_date($starttime,'m'),$phpgw->common->show_date($starttime,'d') + 1,$phpgw->common->show_date($starttime,'Y')) - ((60*60) * $phpgw_info['user']['preferences']['common']['tz_offset']) - 1; - - $sql = 'SELECT DISTINCT calendar_entry.cal_id ' - . 'FROM calendar_entry, calendar_entry_user ' - . 'WHERE (calendar_entry_user.cal_id = calendar_entry.cal_id) AND ' - . ' ((('.$starttime.' <= calendar_entry.cal_datetime) AND ('.$endtime.' >= calendar_entry.cal_datetime) AND ('.$endtime.' <= calendar_entry.cal_edatetime)) ' - . 'OR (('.$starttime.' >= calendar_entry.cal_datetime) AND ('.$starttime.' < calendar_entry.cal_edatetime) AND ('.$endtime.' >= calendar_entry.cal_edatetime)) ' - . 'OR (('.$starttime.' <= calendar_entry.cal_datetime) AND ('.$endtime.' >= calendar_entry.cal_edatetime)) ' - . 'OR (('.$starttime.' >= calendar_entry.cal_datetime) AND ('.$endtime.' <= calendar_entry.cal_edatetime))) '; - - if(count($participants) || is_array($groups)) { - $p_g = ''; - if(count($participants)) { - $p_g .= '('; - for($i=0;$igroup_search($owner); - if ($group) { - if ($p_g) $p_g .= 'OR '; - $p_g .= $group; - } - if($p_g) $sql .= ' AND (' . $p_g . ')'; - } - - if($id) $sql .= ' AND calendar_entry.cal_id <> '.$id; - - $db2 = $phpgw->db; - - $phpgw->db->query($sql,__LINE__,__FILE__); - if(!$phpgw->db->num_rows()) return false; - while($phpgw->db->next_record()) { - $cal_id = intval($phpgw->db->f('cal_id')); - $db2->query('SELECT cal_type FROM calendar_entry_repeats WHERE cal_id='.$cal_id,__LINE__,__FILE__); - if(!$db2->num_rows()) { - $retval[] = $cal_id; - $ok = True; - } else { - if($db2->f('cal_type') <> 'monthlyByDay') { - $retval[] = $cal_id; - $ok = True; - } - } - } - if($ok) return $retval; else return False; - } - - function is_private($cal_info,$owner) { - global $phpgw; - global $phpgw_info; - - $is_private = False; - if ($owner == $phpgw_info['user']['account_id'] || $owner == 0 || $this->check_perms(16) == True) { - } elseif ($cal_info->access == 'private') { - $is_private = True; - } elseif($cal_info->access == 'group') { - $is_private = True; - $phpgw->db->query('SELECT account_lid FROM accounts WHERE account_id='.$owner,__LINE__,__FILE__); - $phpgw->db->next_record(); - $groups = $phpgw->accounts->read_groups($phpgw->db->f('account_lid')); - while ($group = each($groups)) { - if (strpos(' '.$cal_info->groups.' ',','.$group[0]).',') $is_private = False; - } - } - if ($is_private) { - $str = 'private'; - } elseif (strlen($cal_info->name) > 19) { - $str = substr($cal_info->name, 0 , 19); - $str .= '...'; - } else { - $str = $cal_info->name; - } - return $str; - } - - function timematrix($date,$starttime,$endtime,$participants) { - global $phpgw; - global $phpgw_info; - - if(!isset($phpgw_info['user']['preferences']['calendar']['interval']) || - !$phpgw_info['user']['preferences']['calendar']['interval']) { - $phpgw_info['user']['preferences']['calendar']['interval'] = 15; - } - $datetime = $this->gmtdate($date['raw']); - $increment = $phpgw_info['user']['preferences']['calendar']['interval']; - $interval = (int)(60 / $increment); - - $str = '
'.$phpgw->common->show_date($datetime['raw'],'l, F d, Y').'
'; - $str .= ''; - $str .= ''; - $str .= ''; - for($i=0;$i<24;$i++) { - for($j=0;$j<$interval;$j++) - switch($j) { - case 0: - if($interval == 4) { - $k = ($i<=9?'0':substr($i,0,1)); - } - $str .= ''; - break; - case 1: - if($interval == 4) { - $k = ($i<=9?substr($i,0,1):substr($i,1,2)); - } - $str .= ''; - break; - default: - $str .= ''; - break; - } - } - $str .= ''; - $str .= ''; - if(!$endtime) $endtime = $starttime; -// $endtime = $this->splittime_($this->addduration(intval($starttime['hour']),intval($starttime['minute']),$starttime['ampm'],$duration)); - - for($i=0;$iread_repeated_events($participants[$i]); - $str .= ''; - $str .= ''; - $events = $this->get_sorted_by_date($datetime['raw'],$participants[$i]); - if(!$this->sorted_re) { - for($j=0;$j<24;$j++) { - for($k=0;$k<$interval;$k++) { - $str .= ''; - } - } - } else { - for($h=0;$h<24;$h++) { - for($m=0;$m<$interval;$m++) { - $index = (($h * 10000) + (($m * $increment) * 100)); - $time_slice[$index]['marker'] = ' '; - $time_slice[$index]['color'] = $phpgw_info['theme']['bg_color']; - $time_slice[$index]['description'] = ''; - } - } - for($k=0;$k<$this->sorted_re;$k++) { - $event = $events[$k]; - $eventstart = $this->localdates($event->datetime); - $eventend = $this->localdates($event->edatetime); - $start = ($eventstart['hour'] * 10000) + ($eventstart['minute'] * 100); - $starttemp = $this->splittime("$start"); - $subminute = 0; - for($m=0;$m<$interval;$m++) { - $minutes = $increment * $m; - if(intval($starttemp['minute']) > $minutes && intval($starttemp['minute']) < ($minutes + $increment)) { - $subminute = ($starttemp['minute'] - $minutes) * 100; - } - } - $start -= $subminute; - $end = ($eventend['hour'] * 10000) + ($eventend['minute'] * 100); - $endtemp = $this->splittime("$end"); - $addminute = 0; - for($m=0;$m<$interval;$m++) { - $minutes = ($increment * $m); - if($endtemp['minute'] < ($minutes + $increment) && $endtemp['minute'] > $minutes) { - $addminute = ($minutes + $increment - $endtemp['minute']) * 100; - } - } - $end += $addminute; - $starttemp = $this->splittime("$start"); - $endtemp = $this->splittime("$end"); -// Do not display All-Day events in this free/busy time - if((($starttemp['hour'] == 0) && ($starttemp['minute'] == 0)) && (($endtemp['hour'] == 23) && ($endtemp['minute'] == 59))) { - } else { - for($h=$starttemp['hour'];$h<=$endtemp['hour'];$h++) { - $startminute = 0; - $endminute = $interval; - $hour = $h * 10000; - if($h == intval($starttemp['hour'])) - $startminute = ($starttemp['minute'] / $increment); - if($h == intval($endtemp['hour'])) - $endminute = ($endtemp['minute'] / $increment); - for($m=$startminute;$m<=$endminute;$m++) { - $index = ($hour + (($m * $increment) * 100)); - $time_slice[$index]['marker'] = '-'; - $time_slice[$index]['color'] = $phpgw_info['theme']['bg01']; - $time_slice[$index]['description'] = $this->is_private($event,$participants[$i]); - } - } - } - } - for($h=0;$h<24;$h++) { - $hour = $h * 10000; - for($m=0;$m<$interval;$m++) { - $index = ($hour + (($m * $increment) * 100)); - $str .= ''; - } - } - } - $str .= ''; - $str .= ''; - } - $str .= '
Participant'; - $str .= '"; - $str .= $k.''; - $str .= '"; - $str .= $k.''; - $str .= '"; - $str .= ' 
'.$phpgw->common->grab_owner_name($participants[$i]).' ".$time_slice[$index]['marker'].'
'; - return $str; - } - - // The orginal patch read this 30+ times in a loop, only read it once. - function read_repeated_events($owner=0) { - global $phpgw; - global $phpgw_info; - - $this->re = 0; - $this->set_filter(); - $owner = !$owner?$phpgw_info['user']['account_id']:$owner; - $sql = 'SELECT calendar_entry.cal_id ' - . 'FROM calendar_entry, calendar_entry_repeats, calendar_entry_user ' - . 'WHERE calendar_entry.cal_id=calendar_entry_repeats.cal_id AND ' - . "calendar_entry.cal_id = calendar_entry_user.cal_id AND calendar_entry.cal_type='M' AND "; - $sqlfilter=''; -// Private - if($this->filter==' all ' || strpos($this->filter,'private')) { - $sqlfilter .= '(calendar_entry_user.cal_login='.$owner." AND calendar_entry.cal_access='private') "; - } - -// Group Public - if($this->filter==' all ' || strpos($this->filter,'group')) { - if($sqlfilter) - $sqlfilter .= 'OR '; - $sqlfilter .= '(calendar_entry_user.cal_login='.$owner.' OR '.$this->group_search($owner).') '; - } - -// Global Public - if($this->filter==' all ' || strpos($this->filter,'public')) { - if($sqlfilter) - $sqlfilter .= 'OR '; - $sqlfilter .= "calendar_entry.cal_access='public' "; - } - $orderby = ' ORDER BY calendar_entry.cal_datetime ASC, calendar_entry.cal_edatetime ASC, calendar_entry.cal_priority ASC'; - - $db2 = $phpgw->db; - - if($sqlfilter) $sql .= '('.$sqlfilter.') '; - $sql .= $orderby; - - $db2->query($sql,__LINE__,__FILE__); - - $i = 0; - if($db2->num_rows()) { - while ($db2->next_record()) { - $repeated_event_id[$i++] = (int)$db2->f('cal_id'); - } - $this->re = $i; - $this->repeated_events = $this->getevent($repeated_event_id); - } else { - $this->repeated_events = Null; - } - } - - function link_to_entry($id, $pic, $description) { - global $phpgw; - global $phpgw_info; - - $str = ''; - if (!$this->printer_friendly) { - $p = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('calendar')); - $p->set_unknowns('remove'); - $p->set_file(array('link_pict' => 'link_pict.tpl')); - $p->set_block('link_pict','link_pict'); - $p->set_var('link_link',$phpgw->link($phpgw_info['server']['webserver_url'].'/calendar/view.php','id='.$id)); - $p->set_var('lang_view',lang('View this entry')); - $p->set_var('pic_image',$phpgw->common->get_image_path('calendar').'/'.$pic); - $p->set_var('description',$description); - $str = $p->finish($p->parse('out','link_pict')); - } - return $str; - } - - function build_time_for_display($fixed_time) { - global $phpgw_info; -// echo "
before: $fixed_time"; - $time = $this->splittime($fixed_time); -// echo '
test -> build_time_for_display () in if ' . $time['hour'] . ' ' . $time['ampm']; -// echo "
  $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; - } - - function check_repeating_entries($datetime) { - global $phpgw; - global $phpgw_info; - - $this->checked_re = 0; - if(!$this->re) return False; - $link = Array(); -// $date = $this->gmtdate($datetime); - $date = $this->localdates($datetime); - for ($i=0;$i<$this->re;$i++) { - $rep_events = $this->repeated_events[$i]; - $frequency = intval($rep_events->rpt_freq); - $start = $this->localdates($rep_events->datetime); - if($rep_events->rpt_use_end) - $enddate = $this->gmtdate($rep_events->rpt_end); - else - $enddate = $this->makegmttime(0,0,0,1,1,2007); - // only repeat after the beginning, and if there is an rpt_end before the end date - if ($rep_events->rpt_use_end && ($date['full'] > $enddate['full'])) { - continue; - } - - if ($date['full'] < $start['full']) { - continue; - } - - if ($date['full'] == $start['full']) { - $link[$this->checked_re] = $i; - $this->checked_re++; - } elseif ($rep_events->rpt_type == 'daily') { - if ((floor(($date['bd'] - $start['bd'])/86400) % $frequency)){ - continue; - } else { - $link[$this->checked_re++] = $i; -// $this->checked_re++; - } - } elseif ($rep_events->rpt_type == 'weekly') { - $isDay = strtoupper(substr($rep_events->rpt_days, $date['dow'], 1)); - if (floor(($date['bd'] - $start['bd'])/604800) % $frequency) { - continue; - } - if (strcmp($isDay,'Y') == 0) { - $link[$this->checked_re++] = $i; -// $this->checked_re++; - } - } elseif ($rep_events->rpt_type == 'monthlybyday') { - if ((($date['year'] - $start['year']) * 12 + $date['month'] - $start['month']) % $frequency) { - continue; - } - - if (($start['dow'] == $date['dow']) && - (ceil($start['day']/7) == ceil($date['day']/7))) { - $link[$this->checked_re++] = $i; -// $this->checked_re++; - } - } elseif ($rep_events->rpt_type == 'monthlybydate') { - if ((($date['year'] - $start['year']) * 12 + $date['month'] - $start['month']) % $frequency) { - continue; - } - if ($date['day'] == $start['day']) { - $link[$this->checked_re++] = $i; -// $this->checked_re++; - } - } elseif ($rep_events->rpt_type == 'yearly') { - if (($date['year'] - $start['year']) % $frequency) { - continue; - } - if ($date['dm'] == $start['dm']) { - $link[$this->checked_re++] = $i; -// $this->checked_re++; - } - } else { - // unknown rpt type - because of all our else ifs - } - } // end for loop - - if($this->checked_re) { - return $link; - } else { - return False; - } - } // end function - - function get_sorted_by_date($datetime,$owner=0) { - global $phpgw; - global $phpgw_info; - - $this->sorted_re = 0; - $this->set_filter(); - $owner = !$owner?$phpgw_info['user']['account_id']:$owner; - $rep_event = $this->check_repeating_entries($datetime); - $sql = 'SELECT DISTINCT calendar_entry.cal_id, calendar_entry.cal_datetime, ' - . 'calendar_entry.cal_edatetime, calendar_entry.cal_priority ' - . 'FROM calendar_entry, calendar_entry_user ' - . 'WHERE ((calendar_entry.cal_datetime >= '.$datetime.' AND calendar_entry.cal_datetime <= '.($datetime + 86399).') OR ' - . '(calendar_entry.cal_datetime <= '.$datetime.' AND calendar_entry.cal_edatetime >= '.($datetime + 86399).') OR ' - . '(calendar_entry.cal_edatetime >= '.$datetime.' AND calendar_entry.cal_edatetime <= '.($datetime + 86399).')) AND ' - . "calendar_entry_user.cal_id=calendar_entry.cal_id AND calendar_entry.cal_type != 'M' AND "; - $sqlfilter = ''; -// Private - if($this->filter==' all ' || strpos($this->filter,'private')) { - $sqlfilter .= '(calendar_entry_user.cal_login = '.$owner." AND calendar_entry.cal_access='private') "; - } - -// Group Public - if($this->filter==' all ' || strpos($this->filter,'group')) { - if($sqlfilter) - $sqlfilter .= 'OR '; - $sqlfilter .= $this->group_search($owner).' '; - } - -// Global Public - if($this->filter==' all ' || strpos($this->filter,'public')) { - if($sqlfilter) - $sqlfilter .= 'OR '; - $sqlfilter .= "calendar_entry.cal_access='public' "; - } - $orderby = ' ORDER BY calendar_entry.cal_datetime ASC, calendar_entry.cal_edatetime ASC, calendar_entry.cal_priority ASC'; - - $db2 = $phpgw->db; - - if($sqlfilter) $sql .= '('.$sqlfilter.') '; - $sql .= $orderby; - - $db2->query($sql,__LINE__,__FILE__); - - $events = Null; - $rep_events = Array(); - if($db2->num_rows()) { - while($db2->next_record()) { - $rep_events[$this->sorted_re++] = (int)$db2->f(0); - } - $events = $this->getevent($rep_events); - } else - $events = Array(CreateObject('calendar.calendar_item')); - - if(!$this->checked_re && !$this->sorted_re) return False; - - $e = CreateObject('calendar.calendar_item'); - for ($j=0;$j<$this->checked_re;$j++) { - $e = $this->repeated_events[$rep_event[$j]]; - $events[$this->sorted_re++] = $e; - } - if(!$this->sorted_re) return False; - if($this->sorted_re == 1) return $events; - for($outer_loop=0;$outer_loop<($this->sorted_re - 1);$outer_loop++) { - $outer = $events[$outer_loop]; - $outer_time = $phpgw->common->show_date($outer->datetime,'Hi'); - $outer_etime = $phpgw->common->show_date($outer->edatetime,'Hi'); - if($outer->datetime < $datetime) { - $outer_time = 0; - } - if($outer->edatetime > ($datetime + 86399)) { - $outer_etime = 2359; - } - for($inner_loop=$outer_loop;$inner_loop<$this->sorted_re;$inner_loop++) { - $inner = $events[$inner_loop]; - $inner_time = $phpgw->common->show_date($inner->datetime,'Hi'); - $inner_etime = $phpgw->common->show_date($inner->edatetime,'Hi'); - if($inner->datetime < $datetime) { - $inner_time = 0; - } - if($inner->edatetime > ($datetime + 86399)) { - $inner_etime = 2359; - } - if(($outer_time > $inner_time) || - (($outer_time == $inner_time) && ($outer_etime > $inner_etime))) { - $temp = $events[$inner_loop]; - $events[$inner_loop] = $events[$outer_loop]; - $events[$outer_loop] = $temp; - } - } - } - if(isset($events)) return $events; else return False; - } - - function large_month_header($month,$year,$display_name = False) { - global $phpgw; - global $phpgw_info; - - $this->weekstarttime = $this->get_weekday_start($year,$month,1); - - $p = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('calendar')); -// $p->halt_on_error('report'); - $p->set_unknowns('remove'); - $p->set_file(array('month_header' => 'month_header.tpl', - 'column_title' => 'column_title.tpl')); - $p->set_block('month_header','month_header'); - $p->set_block('column_title','column_title'); - - $p->set_var(array('bgcolor' => $phpgw_info['theme']['th_bg'], - 'font_color' => $phpgw_info['theme']['th_text'])); - if($display_name) { - $p->set_var('col_title',lang('name')); - $p->parse('column_header','column_title',True); - } - - for($i=0;$i<$this->daysinweek;$i++) { - $p->set_var('col_title',lang($this->days[$i])); - $p->parse('column_header','column_title',True); - } - return $p->finish($p->parse('out','month_header')); - } - - function display_week($startdate,$weekly,$cellcolor,$display_name = False,$owner=0,$monthstart=0,$monthend=0) { - global $phpgw; - global $phpgw_info; - - $str = ''; - $gr_events = CreateObject('calendar.calendar_item'); - $lr_events = CreateObject('calendar.calendar_item'); - - $p = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('calendar')); - $p->set_unknowns('remove'); - $p->set_file(array('month_header' => 'month_header.tpl', - 'month_column' => 'month_column.tpl', - 'month_day' => 'month_day.tpl', - 'week_day_event' => 'week_day_event.tpl', - 'week_day_events' => 'week_day_events.tpl')); - $p->set_block('month_header','month_header'); - $p->set_block('month_column','month_column'); - $p->set_block('month_day','month_day'); - $p->set_block('week_day_event','week_day_event'); - $p->set_block('week_day_events','week_day_events'); - - $p->set_var('extra',''); - if($display_name) { - $p->set_var('column_data',$phpgw->common->grab_owner_name($owner)); - $p->parse('column_header','month_column',True); - } - for ($j=0;$j<$this->daysinweek;$j++) { - $date = $this->gmtdate($startdate + ($j * 24 * 3600)); - $p->set_var('column_data',''); - $p->set_var('extra',''); - if ($weekly || ($date['full'] >= $monthstart && $date['full'] <= $monthend)) { - if($weekly) $cellcolor = $phpgw->nextmatchs->alternate_row_color($cellcolor); - if ($date['full'] == $this->today['full']) { - $p->set_var('extra',' bgcolor="'.$phpgw_info['theme']['cal_today'].'"'); - } else { - $p->set_var('extra',' bgcolor="'.$cellcolor.'"'); - } - - if (!$this->printer_friendly) { - $str = ''; - if($this->check_perms(PHPGW_ACL_ADD) == True) { - $str .= ''; - } - - $str .= 'check_perms(PHPGW_ACL_ADD) == True) { - $str .= 'alt="'.lang('New Entry').'" '; - } - - $str .= 'border="0" align="right">'; - - if($this->check_perms(PHPGW_ACL_ADD) == True) { - $str .= ''; - } - - $p->set_var('new_event_link',$str); - $str = ''.$date['day'].''; - $p->set_var('day_number',$str); - } else { - $p->set_var('new_event_link',''); - $p->set_var('day_number',$date['day']); - } - $p->parse('column_data','month_day',True); - - $rep_events = $this->get_sorted_by_date($date['raw'],$owner); - - if ($this->sorted_re) { - $lr_events = CreateObject('calendar.calendar_item'); - $p->set_var('week_day_font_size','2'); - $p->set_var('events',''); - for ($k=0;$k<$this->sorted_re;$k++) { - $lr_events = $rep_events[$k]; - $pict = 'circle.gif'; - for ($outer_loop=0;$outer_loop<$this->re;$outer_loop++) { - $gr_events = $this->repeated_events[$outer_loop]; - if ($gr_events->id == $lr_events->id) { - $pict = "rpt.gif"; - } - } -// $p->set_var('link_entry',$this->link_to_entry($lr_events->id, $pict, $this->is_private($lr_events,$owner).' - '.$lr_events->description)); - $p->set_var('link_entry',$this->link_to_entry($lr_events->id, $pict, $lr_events->description)); - if (intval($phpgw->common->show_date($lr_events->datetime,"Hi"))) { - if ($phpgw_info["user"]["preferences"]["common"]["timeformat"] == "12") { - $format = "h:i a"; - } else { - $format = "H:i"; - } - if($lr_events->datetime < $date["raw"] && $lr_events->rpt_type=="none") { - $temp_time = $this->makegmttime(0,0,0,$date["month"],$date["day"],$date["year"]); - $start_time = $phpgw->common->show_date($temp_time["raw"],$format); - } else { - $start_time = $phpgw->common->show_date($lr_events->datetime,$format); - } - - if($lr_events->edatetime > ($date["raw"] + 86400)) { - $temp_time = $this->makegmttime(23,59,59,$date["month"],$date["day"],$date["year"]); - $end_time = $phpgw->common->show_date($temp_time["raw"],$format); - } else { - $end_time = $phpgw->common->show_date($lr_events->edatetime,$format); - } - $p->set_var('start_time',$start_time); - $p->set_var('end_time',$end_time); - } else { - $p->set_var('start_time',''); - $p->set_var('end_time',''); - } - $p->set_var('name',$this->is_private($lr_events,$owner)); - $p->parse('events','week_day_event',True); - } - } - $p->parse('column_data','week_day_events',True); - $p->set_var('events',''); - if (!$j || ($j && $date["full"] == $monthstart)) { - $p->set_var('week_day_font_size','-2'); - if(!$this->printer_friendly) { - $str = 'week ' .(int)((date('z',($startdate+(24*3600*4)))+7)/7).''; - } else { - $str = 'week ' .(int)((date('z',($startdate+(24*3600*4)))+7)/7); - } - $p->set_var('events',$str); - $p->parse('column_data','week_day_events',True); - $p->set_var('events',''); - } - } - $p->parse('column_header','month_column',True); - $p->set_var('column_data',''); - } - return $p->finish($p->parse('out','month_header')); - } - - function display_large_month($month,$year,$showyear,$owner=0) { - global $phpgw, $phpgw_info; - - if($owner == $phpgw_info['user']['account_id']) $owner = 0; - $this->read_repeated_events($owner); - - $p = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('calendar')); - $p->set_unknowns('remove'); - $p->set_file(array('month' => 'month.tpl', - 'month_filler' => 'month_filler.tpl', - 'month_header' => 'month_header.tpl')); - $p->set_block('month','month'); - $p->set_block('month_filler','month_filler'); - $p->set_block('month_header','month_header'); - - $p->set_var('month_filler_text',$this->large_month_header($month,$year,False)); - $p->parse('row','month_filler',True); - - $monthstart = intval(date('Ymd',mktime(0,0,0,$month ,1,$year))); - $monthend = intval(date('Ymd',mktime(0,0,0,$month + 1,0,$year))); - - $today = $this->splitdate(time()); - - $cellcolor = $phpgw_info['theme']['row_on']; - - for ($i=$this->weekstarttime;intval(date('Ymd',$i))<=$monthend;$i += (24 * 3600 * 7)) { - $cellcolor = $phpgw->nextmatchs->alternate_row_color($cellcolor); - $p->set_var('month_filler_text',$this->display_week($i,False,$cellcolor,False,$owner,$monthstart,$monthend)); - $p->parse('row','month_filler',True); - } - return $p->finish($p->parse('out','month')); - } - - function display_large_week($day,$month,$year,$showyear,$owners=0) { - global $phpgw; - global $phpgw_info; - - $p = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('calendar')); - $p->set_unknowns('remove'); - $p->set_file(array('month' => 'month.tpl', - 'month_filler' => 'month_filler.tpl', - 'month_header' => 'month_header.tpl')); - $p->set_block('month','month'); - $p->set_block('month_filler','month_filler'); - $p->set_block('month_header','month_header'); - - $start = $this->get_weekday_start($year, $month, $day); - - $cellcolor = $phpgw_info['theme']['row_off']; - -// if ($phpgw_info['user']['preferences']['calendar']['weekdaystarts'] == 'Monday') { -// $start += 86400; -// } - -// $str = ''; - - $true_printer_friendly = $this->printer_friendly; - - if(is_array($owners)) { - $display_name = True; - $counter = count($owners); - $owners_array = $owners; - } else { - $display_name = False; - $counter = 1; - $owners_array[0] = $owners; - } - $p->set_var('month_filler_text',$this->large_month_header($month,$year,$display_name)); - $p->parse('row','month_filler',True); - - for($i=0;$i<$counter;$i++) { - $this->repeated_events = Null; - $owner = $owners_array[$i]; - if($owner <> $phpgw_info['user']['account_id'] && $owner <> 0) { - $this->printer_friendly = True; - } else { - $this->printer_friendly = $true_printer_friendly; - } - $this->read_repeated_events($owner); - $p->set_var('month_filler_text',$this->display_week($start,True,$cellcolor,$display_name,$owner)); - $p->parse('row','month_filler',True); - } - $this->printer_friendly = $true_printer_friendly; - return $p->finish($p->parse('out','month')); - } - - function pretty_small_calendar($day,$month,$year,$link='') { - global $phpgw, $phpgw_info, $view; - -// $tz_offset = (-1 * ((60 * 60) * intval($phpgw_info['user']['preferences']['common']['tz_offset']))); - $date = $this->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->get_weekday_start($year,$month,1); - - $str = ''; - $str .= ''; - $str .= ''; - $str .= ''; - $str .= ''; - $str .= '
'; - $str .= ''; - if ($view == 'day') { - $str .= ''; - } - $str .= ''; - - if ($view == 'year') { - $str .= ''; - $str .= ''; - } - - if ($view != 'year') { - $str .= ''; - } - $str .= ''; - $str .= ''; - for($i=0;$i<7;$i++) { - $str .= ''; - } - $str .= ''; - for($i=$weekstarttime;date('Ymd',$i)<=$monthend;$i += (24 * 3600 * 7)) { - $str .= ''; - for($j=0;$j<7;$j++) { - $cal = $this->gmtdate($i + ($j * 24 * 3600)); - if($cal['full'] >= $monthstart && $cal['full'] <= $monthend) { - $str .= ''; - } else { - $str .= ''; - } - } - $str .= ''; - } - $str .= '
'.$day.'
'; - } else { - $str .= ''; - } - - if ($view != 'year') { - if (!$this->printer_friendly) { - $str .= ''; - } - $str .= '<'; - if (!$this->printer_friendly) $str .= ''; - $str .= ''; - } - if (!$this->printer_friendly) { - $str .= ''; - } - $str .= lang($phpgw->common->show_date($date['raw'],'F')).' '.$year; - if(!$this->printer_friendly) $str .= ''; - if ($view != 'year') { - $str .= ''; - if (!$this->printer_friendly) { - $str .= ''; - } - $str .= '>'; - if (!$this->printer_friendly) { - $str .= ''; - } - $str .= '
'.substr(lang($days[$i]),0,2).'
'; - - if(!$this->printer_friendly) { - $str .= ''; - } - $str .= $cal['day']; - if(!$this->printer_friendly) $str .= ''; - $str .= '.
'; - $str .= '
'; - return $str; - } - - function display_small_month($month,$year,$showyear,$link='') { - global $phpgw; - global $phpgw_info; - - $weekstarttime = $this->get_weekday_start($year,$month,1); - - $str = ''; - $str .= ''; - - $monthstart = $this->splitdate(mktime(0,0,0,$month ,1,$year)); - $monthend = $this->splitdate(mktime(0,0,0,$month + 1,0,$year)); - - $str .= '' - . ''; - for($i=0;$i<$daysinweek;$i++) { - $str .= ''; - } - $str .= ''; - - for($i=$weekstarttime;date('Ymd',$i)<=$monthend['full'];$i+=604800) { - $str .= ''; - for($j=0;$j<$daysinweek;$j++) { - $date = $this->splitdate($i + ($j * 86400)); - if($date['full']>=$monthstart['full'] && - $date['full']<=$monthend['full']) { - $str .= ''; - } else { - $str .= ''; - } - } - $str .= ''; - } - $str .= '
'; - - if(!$this->printer_friendly) { - $str .= ''; - } - $str .= lang(date('F',$monthstart['raw'])); - - if($showyear) { - $str .= ' '.$year; - } - - if(!$this->printer_friendly) { - $str .= ''; - } - - $str .= '
'.lang($days[$i]).'
'; - if(!$this->printer_friendly || $link) { - $str .= ''; - } - $str .= ''.date('j',$date['raw']); - if(!$this->printer_friendly || $link) $str .= ''; - $str .= '
'; - return $str; - } - - function mini_calendar($day,$month,$year,$link='') { - global $phpgw, $phpgw_info, $view, $owner; - - $date = $this->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->get_weekday_start($year,$month,1); - - $p = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('calendar')); - $p->set_unknowns('remove'); - $p->set_file(array('mini_cal' => 'mini_cal.tpl', - 'mini_day' => 'mini_day.tpl', - 'mini_week' => 'mini_week.tpl')); - $p->set_block('mini_cal','mini_week','mini_day'); - $p->set_var('img_root',$phpgw->common->get_image_path('phpgwapi')); - $p->set_var('cal_img_root',$phpgw->common->get_image_path('calendar')); - $p->set_var('bgcolor',$phpgw_info['theme']['bg_color']); - $p->set_var('bgcolor1',$phpgw_info['theme']['bg_color']); - if(!$this->printer_friendly) - { - $p->set_var('month','' . lang($phpgw->common->show_date($date['raw'],'F')).' '.$year . ''); - } - else - { - $p->set_var('month',lang($phpgw->common->show_date($date['raw'],'F')).' '.$year); - } - - $p->set_var('prevmonth',$phpgw->link($phpgw_info['server']['webserver_url'].'/calendar/month.php','date='.$month_ago.'&owner='.$owner)); - $p->set_var('nextmonth',$phpgw->link($phpgw_info['server']['webserver_url'].'/calendar/month.php','date='.$month_ahead.'&owner='.$owner)); - - $p->set_var('bgcolor2',$phpgw_info['theme']['cal_dayview']); - for($i=0;$i<7;$i++) { - $p->set_var('dayname','' . substr(lang($this->days[$i]),0,2) . ''); - $p->parse('daynames','mini_day',True); - } - for($i=$weekstarttime;date('Ymd',$i)<=$monthend;$i += (24 * 3600 * 7)) { - for($j=0;$j<7;$j++) { - $str = ''; - $cal = $this->gmtdate($i + ($j * 24 * 3600)); - if($cal['full'] >= $monthstart && $cal['full'] <= $monthend) { - if ($cal['full'] == $this->today['full']) { - $p->set_var('day_image',' background="' . $phpgw_info['server']['webserver_url'] - . '/calendar/templates/' . $phpgw_info['server']['template_set'] - . '/images/mini_day_block.gif' . '"'); - //$p->set_var('bgcolor2','#'.$phpgw_info['theme']['cal_today']); - } else { - $p->set_var('day_image',''); - $p->set_var('bgcolor2','#FFFFFF'); - } - if(!$this->printer_friendly) { - $str .= ''; - } - $str .= $cal['day']; - if (!$this->printer_friendly) $str .= ''; - if ($cal['full'] == $this->today['full']) { - $p->set_var('dayname',"$str"); - } else { - $p->set_var('dayname',$str); - } - } else { - $p->set_var('day_image',''); - $p->set_var('bgcolor2','#FEFEFE'); - $str = ''; -// if(!$this->printer_friendly) { -// $str .= ''; -// } -// $str .= $cal['day']; -// if (!$this->printer_friendly) $str .= ''; - $p->set_var('dayname',$str); - } - $p->parse('monthweek_day','mini_day',True); +// End of ICal style support....... + + function set_filter() + { + global $phpgw_info, $phpgw, $filter; + if (!isset($this->filter) || !$this->filter) + { + if (isset($filter) && $filter) + { + $this->filter = ' '.$filter.' '; + } + else + { + if (! $phpgw_info['user']['preferences']['calendar']['defaultfilter']) + { + $phpgw->preferences->add('calendar','defaultfilter','all'); + $phpgw->preferences->save_repository(True); + } + $this->filter = ' '.$phpgw_info['user']['preferences']['calendar']['defaultfilter'].' '; + } } - $p->parse('display_monthweek','mini_week',True); - $p->set_var('dayname',''); - $p->set_var('monthweek_day',''); - } - return $p->finish($p->parse('out','mini_cal')); - } + } - function html_for_event_day_at_a_glance ($event) { - global $phpgw, $phpgw_info; + function check_perms($needed) + { + if($this->rights & $needed) + { + return True; + } + else + { + return False; + } + } - if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12') { - $format = 'h:i a'; - } else { - $format = 'H:i'; - } - - $ind = intval($phpgw->common->show_date($event->datetime,'H')); - - if($ind<$this->first_hour || $ind>$this->last_hour) $ind = 99; - - if(!isset($this->hour_arr[$ind]) || !$this->hour_arr[$ind]) $this->hour_arr[$ind] = ''; - - if (!$this->printer_friendly) { - $this->hour_arr[$ind] .= '"; - } - - $this->hour_arr[$ind] .= '[' . $phpgw->common->show_date($event->datetime,$format); - if ($event->datetime <> $event->edatetime) { // calc end time - $this->hour_arr[$ind] .= ' - ' . $phpgw->common->show_date($event->edatetime,$format); - $end_t_h = intval($phpgw->common->show_date($event->edatetime,'H')); - $end_t_m = intval($phpgw->common->show_date($event->edatetime,'i')); - if (end_t_m == 0) - $this->rowspan = $end_t_h - $ind; - else - $this->rowspan = $end_t_h - $ind + 1; - if(isset($this->rowspan_arr[$ind])) $r = $this->rowspan_arr[$ind]; else $r = 0; - if ($this->rowspan > $r && $this->rowspan > 1) - $this->rowspan_arr[$ind] = $this->rowspan; - } - $this->hour_arr[$ind] .= '] '; - $this->hour_arr[$ind] .= '' . $event->description . ''; - if ($event->priority == 3) { - $this->hour_arr[$ind] .= ''; - } - $this->hour_arr[$ind] .= $event->name; - - if ($event->priority == 3) { - $this->hour_arr[$ind] .= ''; - } - $this->hour_arr[$ind] .= '
'; - } - - function print_day_at_a_glance($date,$owner=0) { - global $phpgw; - global $phpgw_info; - - $this->read_repeated_events($owner); - - $p = new Template($phpgw->common->get_tpl_dir('calendar')); - $p->set_unknowns('remove'); - $p->set_file(array('day_cal' => 'day_cal.tpl', - 'mini_week' => 'mini_week.tpl', -// 'day_row_99' => 'day_row_99.tpl', - 'day_row_event' => 'day_row_event.tpl', - 'day_row_time' => 'day_row_time.tpl')); - $p->set_block('day_cal','mini_week','day_row_event','day_row_time'); - - - if (! $phpgw_info['user']['preferences']['calendar']['workdaystarts'] && - ! $phpgw_info['user']['preferences']['calendar']['workdayends']) { - - $phpgw_info['user']['preferences']['calendar']['workdaystarts'] = 8; - $phpgw_info['user']['preferences']['calendar']['workdayends'] = 16; - } - - $this->first_hour = (int)$phpgw_info['user']['preferences']['calendar']['workdaystarts'] + 1; - $this->last_hour = (int)$phpgw_info['user']['preferences']['calendar']['workdayends'] + 1; - - $events = array(CreateObject('calendar.calendar_item')); - - $events = $this->get_sorted_by_date($date['raw']); - - if(!$events) { - } else { - $event = CreateObject('calendar.calendar_item'); - for($i=0;$ihtml_for_event_day_at_a_glance($event); - } - } - - // 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. - $this->rowspan = 0; - $this->last_row = -1; - for ($i=0;$i<24;$i++) { - if(isset($this->rowspan_arr[$i])) $r = $this->rowspan_arr[$i]; else $r = 0; - if(isset($this->hour_arr[$i])) $h = $this->hour_arr[$i]; else $h = ''; - if ($this->rowspan > 1) { - if (strlen($h)) { - $this->hour_arr[$this->last_row] .= $this->hour_arr[$i]; - $this->hour_arr[$i] = ''; - $this->rowspan_arr[$i] = 0; - } - $this->rowspan--; - } elseif ($r > 1) { - $this->rowspan = $this->rowspan_arr[$i]; - $this->last_row = $i; - } - } - $p->set_var('time_bgcolor',$phpgw_info['theme']['cal_dayview']); - $p->set_var('bg_time_image',$phpgw->common->get_image_path('phpgwapi').'/navbar_filler.jpg'); - $p->set_var('font_color',$phpgw_info['theme']['bg_text']); - $p->set_var('font',$phpgw_info['theme']['font']); - if (isset($this->hour_arr[99]) && strlen($this->hour_arr[99])) { - $p->set_var('event',$this->hour_arr[99]); - $p->set_var('bgcolor',$phpgw->nextmatchs->alternate_row_color()); - $p->parse('monthweek_day','day_row_event',False); - - $p->set_var('open_link',''); - $p->set_var('close_link',''); - $p->set_var('time',' '); - $p->parse('monthweek_day','day_row_time',True); - $p->parse('row','mini_week',True); - $p->set_var('monthweek_day',''); - } - $this->rowspan = 0; - $times = 0; - for ($i=$this->first_hour;$i<=$this->last_hour;$i++) { - if(isset($this->hour_arr[$i])) $h = $this->hour_arr[$i]; else $h = ''; - $time = $this->build_time_for_display($i * 10000); - $p->set_var('extras',''); - $p->set_var('event',' '); - if ($this->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 (strlen($h)) { - $p->set_var('event',$this->hour_arr[$i]); - $p->set_var('bgcolor',$phpgw->nextmatchs->alternate_row_color()); - $p->parse('monthweek_day','day_row_event',False); - } - $this->rowspan--; - } else { - if (!strlen($h)) { - $p->set_var('event',' '); - $p->set_var('bgcolor',$phpgw->nextmatchs->alternate_row_color()); - $p->parse('monthweek_day','day_row_event',False); - } else { - $this->rowspan = isset($this->rowspan_arr[$i])?$this->rowspan_arr[$i]:0; - if ($this->rowspan > 1) { - $p->set_var('extras',' rowspan="'.$this->rowspan.'"'); - $p->set_var('event',$this->hour_arr[$i]); - $p->set_var('bgcolor',$phpgw->nextmatchs->alternate_row_color()); - $p->parse('monthweek_day','day_row_event',False); - } else { - $p->set_var('event',$this->hour_arr[$i]); - $p->set_var('bgcolor',$phpgw->nextmatchs->alternate_row_color()); - $p->parse('monthweek_day','day_row_event',False); - } - } - } - $p->set_var('open_link',''); - $p->set_var('close_link',''); - $str = ' - '; - if(!$this->printer_friendly && $this->check_perms(PHPGW_ACL_EDIT)) { - $str .= ''; - } - $p->set_var('open_link',$str); - $p->set_var('time',(intval(substr($time,0,strpos($time,':'))) < 10 ? '0'.$time : $time) ); - if(!$this->printer_friendly && $this->check_perms(PHPGW_ACL_EDIT)) { - $p->set_var('close_link',''); - } - $p->parse('monthweek_day','day_row_time',True); - $p->parse('row','mini_week',True); - $p->set_var('monthweek_day',''); - } // end for - return $p->finish($p->parse('out','day_cal')); - } // end function - - function prep($calid) { - global $phpgw; - global $phpgw_info; - - if(!$phpgw_info['user']['apps']['calendar']) return false; - - $db2 = $phpgw->db; + function group_search($owner=0) + { + global $phpgw, $phpgw_info; - $cal_id = array(); - if(is_long($calid)) { - if(!$calid) return false; - $cal_id[0] = $calid; - } elseif(is_string($calid)) { - $calid = $phpgw->account->name2id($calid); - $db2->query('SELECT cal_id FROM calendar_entry WHERE cal_owner='.$calid,__LINE__,__FILE__); - while($phpgw->db->next_record()) { - $cal_id[] = $db2->f('cal_id'); - } - } elseif(is_array($calid)) { - if(is_string($calid[0])) { - for($i=0;$iquery('SELECT cal_id FROM calendar_entry WHERE cal_owner='.$calid[$i],__LINE__,__FILE__); - while($db2->next_record()) { - $cal_id[] = $db2->f('cal_id'); - } - } - } elseif(is_long($calid[0])) { - $cal_id = $calid; - } - } - return $cal_id; - } - - function getwithindates($from,$to) { - global $phpgw; - global $phpgw_info; - - if(!$phpgw_info['user']['apps']['calendar']) return false; - - - $phpgw->db->query('SELECT cal_id FROM calendar_entry WHERE cal_date >= '.$from.' AND cal_date <= '.$to,__LINE__,__FILE__); - if($phpgw->db->num_rows()) { - while($phpgw->db->next_record()) { - $calid[count($calid)] = intval($phpgw->db->f('cal_id')); + $owner = $owner==$phpgw_info['user']['account_id']?0:$owner; + $groups = substr($phpgw->common->sql_search('calendar_entry.cal_group',intval($owner)),4); + if (!$groups) + { + return ''; + } + else + { + return "(calendar_entry.cal_access='group' AND (". $groups .')) '; + } } - return $this->getevent($calid); - } else { - return false; - } - } - function add($calinfo,$calid=0) { - global $phpgw; - global $phpgw_info; + function get_weekday_start($year,$month,$day) { + global $phpgw, $phpgw_info; - if(!$phpgw_info['user']['apps']['calendar']) return false; - if(!$calid) { - $phpgw->db->lock(array('calendar_entry','calendar_entry_user','calendar_entry_repeats')); - $phpgw->db->query("INSERT INTO calendar_entry(cal_name) VALUES('".addslashes($calinfo->name)."')",__LINE__,__FILE__); - $phpgw->db->query('SELECT MAX(cal_id) FROM calendar_entry',__LINE__,__FILE__); - $phpgw->db->next_record(); - $calid = $phpgw->db->f(0); - $phpgw->db->unlock(); - } - if($calid) return $this->modify($calinfo,$calid); - } + $weekday = date('w',mktime(0,0,0,$month,$day,$year)); + if ($phpgw_info['user']['preferences']['calendar']['weekdaystarts'] == 'Monday') + { + $this->days = array(0 => 'Mon', 1 => 'Tue', 2 => 'Wed', 3 => 'Thu', 4 => 'Fri', 5 => 'Sat', 6 => 'Sun'); + $sday = mktime(0,0,0,$month,$day - ($weekday - 1),$year); + } + else + { + $this->days = array(0 => 'Sun', 1 => 'Mon', 2 => 'Tue', 3 => 'Wed', 4 => 'Thu', 5 => 'Fri', 6 => 'Sat'); + $sday = mktime(0,0,0,$month,$day - $weekday,$year); + } - function delete($calid=0) { - global $phpgw; - - $cal_id = $this->prep($calid); - - if(!$cal_id) return false; - - $phpgw->db->lock(array('calendar_entry','calendar_entry_user','calendar_entry_repeats')); - - for($i=0;$idb->query('DELETE FROM calendar_entry_user WHERE cal_id='.$cal_id[$i],__LINE__,__FILE__); - $phpgw->db->query('DELETE FROM calendar_entry_repeats WHERE cal_id='.$cal_id[$i],__LINE__,__FILE__); - $phpgw->db->query('DELETE FROM calendar_entry WHERE cal_id='.$cal_id[$i],__LINE__,__FILE__); - } - $phpgw->db->unlock(); - } - - function modify($calinfo,$calid=0) { - global $phpgw; - global $phpgw_info; - - if(!$phpgw_info['user']['apps']['calendar']) return false; - - if(!$calid) return false; - - $phpgw->db->lock(array('calendar_entry','calendar_entry_user','calendar_entry_repeats')); - - $owner = ($calinfo->owner?$calinfo->owner:$phpgw_info['user']['account_id']); - if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12') { - if ($calinfo->ampm == 'pm' && ($calinfo->hour < 12 && $calinfo->hour <> 12)) { - $calinfo->hour += 12; + return $sday; } - if ($calinfo->end_ampm == 'pm' && ($calinfo->end_hour < 12 && $calinfo->end_hour <> 12)) { - $calinfo->end_hour += 12; - } - } - $date = mktime($calinfo->hour,$calinfo->minute,0,$calinfo->month,$calinfo->day,$calinfo->year) - ((60*60) * $phpgw_info['user']['preferences']['common']['tz_offset']); - $enddate = mktime($calinfo->end_hour,$calinfo->end_minute,0,$calinfo->end_month,$calinfo->end_day,$calinfo->end_year) - ((60*60) * $phpgw_info['user']['preferences']['common']['tz_offset']); - $today = time() - ((60*60) * $phpgw_info['user']['preferences']['common']['tz_offset']); - if($calinfo->rpt_type != 'none') - $rpt_type = 'M'; + 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) + { + 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 ($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 makegmttime($hour,$minute,$second,$month,$day,$year) + { + global $phpgw, $phpgw_info; + + return $this->gmtdate(mktime($hour, $minute, $second, $month, $day, $year)); + } + + function localdates($localtime) + { + global $phpgw, $phpgw_info; + + $date = Array('raw','day','month','year','full','dow','dm','bd'); + $date['raw'] = $localtime; + $date['year'] = intval($phpgw->common->show_date($date['raw'],'Y')); + $date['month'] = intval($phpgw->common->show_date($date['raw'],'m')); + $date['day'] = intval($phpgw->common->show_date($date['raw'],'d')); + $date['full'] = intval($phpgw->common->show_date($date['raw'],'Ymd')); + $date['bd'] = mktime(0,0,0,$date['month'],$date['day'],$date['year']); + $date['dm'] = intval($phpgw->common->show_date($date['raw'],'dm')); + $date['dow'] = intval($phpgw->common->show_date($date['raw'],'w')); + $date['hour'] = intval($phpgw->common->show_date($date['raw'],'H')); + $date['minute'] = intval($phpgw->common->show_date($date['raw'],'i')); + + return $date; + } + + function gmtdate($localtime) + { + global $phpgw_info; + + $localtime -= ((60 * 60) * intval($phpgw_info['user']['preferences']['common']['tz_offset'])); + + return $this->localdates($localtime); + } + + 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 overlap($starttime,$endtime,$participants,$groups,$owner=0,$id=0) + { + global $phpgw, $phpgw_info; + + $retval = Array(); + $ok = False; + + $starttime -= ((60 * 60) * $phpgw_info['user']['preferences']['common']['tz_offset']); + $endtime -= ((60 * 60) * $phpgw_info['user']['preferences']['common']['tz_offset']); + + if($starttime == $endtime) + { + $endtime = mktime($phpgw->common->show_date($starttime,'H'),$phpgw->common->show_date($starttime,'i'),0,$phpgw->common->show_date($starttime,'m'),$phpgw->common->show_date($starttime,'d') + 1,$phpgw->common->show_date($starttime,'Y')) - ((60*60) * $phpgw_info['user']['preferences']['common']['tz_offset']) - 1; + } + + $sql = 'SELECT DISTINCT calendar_entry.cal_id ' + . 'FROM calendar_entry, calendar_entry_user ' + . 'WHERE (calendar_entry_user.cal_id = calendar_entry.cal_id) AND ' + . ' ((('.$starttime.' <= calendar_entry.cal_datetime) AND ('.$endtime.' >= calendar_entry.cal_datetime) AND ('.$endtime.' <= calendar_entry.cal_edatetime)) ' + . 'OR (('.$starttime.' >= calendar_entry.cal_datetime) AND ('.$starttime.' < calendar_entry.cal_edatetime) AND ('.$endtime.' >= calendar_entry.cal_edatetime)) ' + . 'OR (('.$starttime.' <= calendar_entry.cal_datetime) AND ('.$endtime.' >= calendar_entry.cal_edatetime)) ' + . 'OR (('.$starttime.' >= calendar_entry.cal_datetime) AND ('.$endtime.' <= calendar_entry.cal_edatetime))) '; + + if(count($participants) || is_array($groups)) + { + $p_g = ''; + if(count($participants)) + { + $p_g .= '('; + for($i=0;$igroup_search($owner); + if ($group) + { + if ($p_g) + { + $p_g .= 'OR '; + } + $p_g .= $group; + } + if($p_g) + { + $sql .= ' AND (' . $p_g . ')'; + } + } + + if($id) + { + $sql .= ' AND calendar_entry.cal_id <> '.$id; + } + + $db2 = $phpgw->db; + + $phpgw->db->query($sql,__LINE__,__FILE__); + if(!$phpgw->db->num_rows()) + { + return false; + } + while($phpgw->db->next_record()) + { + $cal_id = intval($phpgw->db->f('cal_id')); + $db2->query('SELECT cal_type FROM calendar_entry_repeats WHERE cal_id='.$cal_id,__LINE__,__FILE__); + if(!$db2->num_rows()) + { + $retval[] = $cal_id; + $ok = True; + } + else + { + if($db2->f('cal_type') <> 'monthlyByDay') + { + $retval[] = $cal_id; + $ok = True; + } + } + } + if($ok) + { + return $retval; + } + else + { + return False; + } + } + + function is_private($cal_info,$owner) + { + global $phpgw, $phpgw_info; + + $is_private = False; + if ($owner == $phpgw_info['user']['account_id'] || $owner == 0 || $this->check_perms(16) == True) + { + } + elseif ($cal_info->access == 'private') + { + $is_private = True; + } + elseif($cal_info->access == 'group') + { + $is_private = True; + $groups = $phpgw->accounts->memberships($owner); + while ($group = each($groups)) + { + if (strpos(' '.$cal_info->groups.' ',','.$group[1]['account_id']).',') + { + $is_private = False; + } + } + } + + if ($is_private) + { + $str = 'private'; + } + elseif (strlen($cal_info->name) > 19) + { + $str = substr($cal_info->name, 0 , 19) . '...'; + } + else + { + $str = $cal_info->name; + } + return $str; + } + + function timematrix($date,$starttime,$endtime,$participants) + { + global $phpgw, $phpgw_info; + + if(!isset($phpgw_info['user']['preferences']['calendar']['interval']) || + !$phpgw_info['user']['preferences']['calendar']['interval']) + { + $phpgw_info['user']['preferences']['calendar']['interval'] = 15; + } + $datetime = $this->gmtdate($date['raw']); + $increment = $phpgw_info['user']['preferences']['calendar']['interval']; + $interval = (int)(60 / $increment); + + $str = '
'.$phpgw->common->show_date($datetime['raw'],'l, F d, Y').'
'; + $str .= ''; + $str .= ''; + $str .= ''; + for($i=0;$i<24;$i++) + { + for($j=0;$j<$interval;$j++) + { + switch($j) + { + case 0: + if($interval == 4) + { + $k = ($i<=9?'0':substr($i,0,1)); + } + $str .= ''; + break; + case 1: + if($interval == 4) + { + $k = ($i<=9?substr($i,0,1):substr($i,1,2)); + } + $str .= ''; + break; + default: + $str .= ''; + break; + } + } + } + $str .= ''; + $str .= ''; + if(!$endtime) + { + $endtime = $starttime; + } + for($i=0;$iread_repeated_events($participants[$i]); + $str .= ''; + $str .= ''; + $events = $this->get_sorted_by_date($datetime['raw'],$participants[$i]); + if(!$this->sorted_re) + { + for($j=0;$j<24;$j++) + { + for($k=0;$k<$interval;$k++) + { + $str .= ''; + } + } + } + else + { + for($h=0;$h<24;$h++) + { + for($m=0;$m<$interval;$m++) + { + $index = (($h * 10000) + (($m * $increment) * 100)); + $time_slice[$index]['marker'] = ' '; + $time_slice[$index]['color'] = $phpgw_info['theme']['bg_color']; + $time_slice[$index]['description'] = ''; + } + } + for($k=0;$k<$this->sorted_re;$k++) + { + $event = $events[$k]; + $eventstart = $this->localdates($event->datetime); + $eventend = $this->localdates($event->edatetime); + $start = ($eventstart['hour'] * 10000) + ($eventstart['minute'] * 100); + $starttemp = $this->splittime("$start"); + $subminute = 0; + for($m=0;$m<$interval;$m++) + { + $minutes = $increment * $m; + if(intval($starttemp['minute']) > $minutes && intval($starttemp['minute']) < ($minutes + $increment)) + { + $subminute = ($starttemp['minute'] - $minutes) * 100; + } + } + $start -= $subminute; + $end = ($eventend['hour'] * 10000) + ($eventend['minute'] * 100); + $endtemp = $this->splittime("$end"); + $addminute = 0; + for($m=0;$m<$interval;$m++) + { + $minutes = ($increment * $m); + if($endtemp['minute'] < ($minutes + $increment) && $endtemp['minute'] > $minutes) + { + $addminute = ($minutes + $increment - $endtemp['minute']) * 100; + } + } + $end += $addminute; + $starttemp = $this->splittime("$start"); + $endtemp = $this->splittime("$end"); +// Do not display All-Day events in this free/busy time + if((($starttemp['hour'] == 0) && ($starttemp['minute'] == 0)) && (($endtemp['hour'] == 23) && ($endtemp['minute'] == 59))) + { + } + else + { + for($h=$starttemp['hour'];$h<=$endtemp['hour'];$h++) + { + $startminute = 0; + $endminute = $interval; + $hour = $h * 10000; + if($h == intval($starttemp['hour'])) + { + $startminute = ($starttemp['minute'] / $increment); + } + if($h == intval($endtemp['hour'])) + { + $endminute = ($endtemp['minute'] / $increment); + } + for($m=$startminute;$m<=$endminute;$m++) + { + $index = ($hour + (($m * $increment) * 100)); + $time_slice[$index]['marker'] = '-'; + $time_slice[$index]['color'] = $phpgw_info['theme']['bg01']; + $time_slice[$index]['description'] = $this->is_private($event,$participants[$i]); + } + } + } + } + for($h=0;$h<24;$h++) + { + $hour = $h * 10000; + for($m=0;$m<$interval;$m++) + { + $index = ($hour + (($m * $increment) * 100)); + $str .= ''; + } + } + } + $str .= ''; + $str .= ''; + } + $str .= '
Participant'; + $str .= '"; + $str .= $k.''; + $str .= '"; + $str .= $k.''; + $str .= '"; + $str .= ' 
'.$phpgw->common->grab_owner_name($participants[$i]).' ".$time_slice[$index]['marker'].'
'; + return $str; + } + + function read_repeated_events($owner=0) + { + global $phpgw, $phpgw_info; + + $this->re = 0; + $this->set_filter(); + $owner = $owner == 0?$phpgw_info['user']['account_id']:$owner; + $sql = 'SELECT calendar_entry.cal_id ' + . 'FROM calendar_entry, calendar_entry_repeats, calendar_entry_user ' + . 'WHERE calendar_entry.cal_id=calendar_entry_repeats.cal_id AND ' + . "calendar_entry.cal_id = calendar_entry_user.cal_id AND calendar_entry.cal_type='M' AND "; + $sqlfilter=''; + +// Private + if($this->filter==' all ' || strpos($this->filter,'private')) + { + $sqlfilter .= '(calendar_entry_user.cal_login='.$owner." AND calendar_entry.cal_access='private') "; + } + +// Group Public + if($this->filter==' all ' || strpos($this->filter,'group')) + { + if($sqlfilter) + { + $sqlfilter .= 'OR '; + } + + $sqlfilter .= '(calendar_entry_user.cal_login='.$owner.' OR '.$this->group_search($owner).') '; + } + +// Global Public + if($this->filter==' all ' || strpos($this->filter,'public')) + { + if($sqlfilter) + { + $sqlfilter .= 'OR '; + } + $sqlfilter .= "calendar_entry.cal_access='public' "; + } + + $orderby = ' ORDER BY calendar_entry.cal_datetime ASC, calendar_entry.cal_edatetime ASC, calendar_entry.cal_priority ASC'; + + $db2 = $phpgw->db; + + if($sqlfilter) + { + $sql .= '('.$sqlfilter.') '; + } + + $sql .= $orderby; + + $db2->query($sql,__LINE__,__FILE__); + + $i = 0; + + if($db2->num_rows()) + { + while ($db2->next_record()) + { + $repeated_event_id[$i++] = (int)$db2->f('cal_id'); + } + $this->re = $i; + $this->repeated_events = $this->getevent($repeated_event_id); + } + else + { + $this->repeated_events = Null; + } + } + + function link_to_entry($id, $pic, $description) + { + global $phpgw, $phpgw_info; + + $str = ''; + if (!$this->printer_friendly) + { + $p = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('calendar')); + $p->set_unknowns('remove'); + $p->set_file(array('link_pict' => 'link_pict.tpl')); + $p->set_block('link_pict','link_pict'); + $p->set_var('link_link',$phpgw->link($phpgw_info['server']['webserver_url'].'/calendar/view.php','id='.$id)); + $p->set_var('lang_view',lang('View this entry')); + $p->set_var('pic_image',$phpgw->common->get_image_path('calendar').'/'.$pic); + $p->set_var('description',$description); + $str = $p->finish($p->parse('out','link_pict')); + } + return $str; + } + + function build_time_for_display($fixed_time) + { + global $phpgw_info; + +// echo "
before: $fixed_time"; + $time = $this->splittime($fixed_time); +// echo '
test -> build_time_for_display () in if ' . $time['hour'] . ' ' . $time['ampm']; +// echo "
  $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; + } + + function check_repeating_entries($datetime) + { + global $phpgw, $phpgw_info; + + $this->checked_re = 0; + + if(!$this->re) + { + return False; + } + + $link = Array(); +// $date = $this->gmtdate($datetime); + $date = $this->localdates($datetime); + for ($i=0;$i<$this->re;$i++) + { + $rep_events = $this->repeated_events[$i]; + $frequency = intval($rep_events->rpt_freq); + $start = $this->localdates($rep_events->datetime); + if($rep_events->rpt_use_end) + { + $enddate = $this->gmtdate($rep_events->rpt_end); + } + else + { + $enddate = $this->makegmttime(0,0,0,1,1,2007); + } + + // only repeat after the beginning, and if there is an rpt_end before the end date + if (($rep_events->rpt_use_end && ($date['full'] > $enddate['full'])) || + ($date['full'] < $start['full'])) + { + continue; + } + + if ($date['full'] == $start['full']) + { + $link[$this->checked_re++] = $i; + } + elseif ($rep_events->rpt_type == 'daily') + { + if ((floor(($date['bd'] - $start['bd'])/86400) % $frequency)) + { + continue; + } + else + { + $link[$this->checked_re++] = $i; + } + } + elseif ($rep_events->rpt_type == 'weekly') + { + $isDay = strtoupper(substr($rep_events->rpt_days, $date['dow'], 1)); + + if (floor(($date['bd'] - $start['bd'])/604800) % $frequency) + { + continue; + } + + if (strcmp($isDay,'Y') == 0) + { + $link[$this->checked_re++] = $i; + } + } + elseif ($rep_events->rpt_type == 'monthlybyday') + { + if ((($date['year'] - $start['year']) * 12 + $date['month'] - $start['month']) % $frequency) + { + continue; + } + + if (($start['dow'] == $date['dow']) && + (ceil($start['day']/7) == ceil($date['day']/7))) + { + $link[$this->checked_re++] = $i; + } + } + elseif ($rep_events->rpt_type == 'monthlybydate') + { + if ((($date['year'] - $start['year']) * 12 + $date['month'] - $start['month']) % $frequency) + { + continue; + } + + if ($date['day'] == $start['day']) + { + $link[$this->checked_re++] = $i; + } + } + elseif ($rep_events->rpt_type == 'yearly') + { + if (($date['year'] - $start['year']) % $frequency) + { + continue; + } + + if ($date['dm'] == $start['dm']) + { + $link[$this->checked_re++] = $i; + } + } + else + { + // unknown rpt type - because of all our else ifs + } + } // end for loop + + if($this->checked_re) + { + return $link; + } + else + { + return False; + } + } // end function + +// Start from here to meet coding stds....... + function get_sorted_by_date($datetime,$owner=0) + { + global $phpgw, $phpgw_info; + + $this->sorted_re = 0; + $this->set_filter(); + $owner = !$owner?$phpgw_info['user']['account_id']:$owner; + $rep_event = $this->check_repeating_entries($datetime); + $sql = 'SELECT DISTINCT calendar_entry.cal_id, calendar_entry.cal_datetime, ' + . 'calendar_entry.cal_edatetime, calendar_entry.cal_priority ' + . 'FROM calendar_entry, calendar_entry_user ' + . 'WHERE ((calendar_entry.cal_datetime >= '.$datetime.' AND calendar_entry.cal_datetime <= '.($datetime + 86399).') OR ' + . '(calendar_entry.cal_datetime <= '.$datetime.' AND calendar_entry.cal_edatetime >= '.($datetime + 86399).') OR ' + . '(calendar_entry.cal_edatetime >= '.$datetime.' AND calendar_entry.cal_edatetime <= '.($datetime + 86399).')) AND ' + . "calendar_entry_user.cal_id=calendar_entry.cal_id AND calendar_entry.cal_type != 'M' AND "; + + $sqlfilter = ''; + +// Private + if($this->filter==' all ' || strpos($this->filter,'private')) + { + $sqlfilter .= '(calendar_entry_user.cal_login = '.$owner." AND calendar_entry.cal_access='private') "; + } + +// Group Public + if($this->filter==' all ' || strpos($this->filter,'group')) + { + if($sqlfilter) + { + $sqlfilter .= 'OR '; + } + + $sqlfilter .= $this->group_search($owner).' '; + } + +// Global Public + if($this->filter==' all ' || strpos($this->filter,'public')) + { + if($sqlfilter) + { + $sqlfilter .= 'OR '; + } + + $sqlfilter .= "calendar_entry.cal_access='public' "; + } + + $orderby = ' ORDER BY calendar_entry.cal_datetime ASC, calendar_entry.cal_edatetime ASC, calendar_entry.cal_priority ASC'; + + $db2 = $phpgw->db; + + if($sqlfilter) + { + $sql .= '('.$sqlfilter.') '; + } + + $sql .= $orderby; + + $db2->query($sql,__LINE__,__FILE__); + + $events = Null; + $rep_events = Array(); + if($db2->num_rows()) + { + while($db2->next_record()) + { + $rep_events[$this->sorted_re++] = (int)$db2->f(0); + } + + $events = $this->getevent($rep_events); + } + else + { + $events = Array(CreateObject('calendar.calendar_item')); + } + + if(!$this->checked_re && !$this->sorted_re) + { + return False; + } + + $e = CreateObject('calendar.calendar_item'); + for ($j=0;$j<$this->checked_re;$j++) + { + $e = $this->repeated_events[$rep_event[$j]]; + $events[$this->sorted_re++] = $e; + } + + if($this->sorted_re == 0) + { + return False; + } + + if($this->sorted_re == 1) + { + return $events; + } + + for($outer_loop=0;$outer_loop<($this->sorted_re - 1);$outer_loop++) + { + $outer = $events[$outer_loop]; + $outer_time = $phpgw->common->show_date($outer->datetime,'Hi'); + $outer_etime = $phpgw->common->show_date($outer->edatetime,'Hi'); + + if($outer->datetime < $datetime) + { + $outer_time = 0; + } + + if($outer->edatetime > ($datetime + 86399)) + { + $outer_etime = 2359; + } + + for($inner_loop=$outer_loop;$inner_loop<$this->sorted_re;$inner_loop++) + { + $inner = $events[$inner_loop]; + $inner_time = $phpgw->common->show_date($inner->datetime,'Hi'); + $inner_etime = $phpgw->common->show_date($inner->edatetime,'Hi'); + + if($inner->datetime < $datetime) + { + $inner_time = 0; + } + + if($inner->edatetime > ($datetime + 86399)) + { + $inner_etime = 2359; + } + + if(($outer_time > $inner_time) || + (($outer_time == $inner_time) && ($outer_etime > $inner_etime))) + { + $temp = $events[$inner_loop]; + $events[$inner_loop] = $events[$outer_loop]; + $events[$outer_loop] = $temp; + } + } + } + + if(isset($events)) + { + return $events; + } + else + { + return False; + } + } + + function large_month_header($month,$year,$display_name = False) + { + global $phpgw, $phpgw_info; + + $this->weekstarttime = $this->get_weekday_start($year,$month,1); + + $p = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('calendar')); + $p->set_unknowns('remove'); + $templates = Array ( + 'month_header' => 'month_header.tpl', + 'column_title' => 'column_title.tpl' + ); + $p->set_file($templates); +// $p->set_block('month_header','month_header'); +// $p->set_block('column_title','column_title'); + + $var = Array( + 'bgcolor' => $phpgw_info['theme']['th_bg'], + 'font_color' => $phpgw_info['theme']['th_text'] + ); + $p->set_var($var); + + if($display_name == True) + { + $p->set_var('col_title',lang('name')); + $p->parse('column_header','column_title',True); + } + + for($i=0;$i<$this->daysinweek;$i++) + { + $p->set_var('col_title',lang($this->days[$i])); + $p->parse('column_header','column_title',True); + } + + return $p->finish($p->parse('out','month_header')); + } + + function display_week($startdate,$weekly,$cellcolor,$display_name = False,$owner=0,$monthstart=0,$monthend=0) + { + global $phpgw, $phpgw_info; + + $str = ''; + $gr_events = CreateObject('calendar.calendar_item'); + $lr_events = CreateObject('calendar.calendar_item'); + + $p = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('calendar')); + $p->set_unknowns('remove'); + + $templates = Array ( + 'month_header' => 'month_header.tpl', + 'month_column' => 'month_column.tpl', + 'month_day' => 'month_day.tpl', + 'week_day_event' => 'week_day_event.tpl', + 'week_day_events' => 'week_day_events.tpl' + ); + $p->set_file($templates); +// $p->set_block('month_header','month_header'); +// $p->set_block('month_column','month_column'); +// $p->set_block('month_day','month_day'); +// $p->set_block('week_day_event','week_day_event'); +// $p->set_block('week_day_events','week_day_events'); + + $p->set_var('extra',''); + + if($display_name) + { + $p->set_var('column_data',$phpgw->common->grab_owner_name($owner)); + $p->parse('column_header','month_column',True); + } + + for ($j=0;$j<$this->daysinweek;$j++) + { + $date = $this->gmtdate($startdate + ($j * 24 * 3600)); + $p->set_var('column_data',''); + $p->set_var('extra',''); + + if ($weekly || ($date['full'] >= $monthstart && $date['full'] <= $monthend)) + { + if($weekly) + { + $cellcolor = $phpgw->nextmatchs->alternate_row_color($cellcolor); + } + + if ($date['full'] == $this->today['full']) + { + $p->set_var('extra',' bgcolor="'.$phpgw_info['theme']['cal_today'].'"'); + } + else + { + $p->set_var('extra',' bgcolor="'.$cellcolor.'"'); + } + + if (!$this->printer_friendly) + { + $str = ''; + + if($this->check_perms(PHPGW_ACL_ADD) == True) + { + $str .= ''; + } + + $str .= 'check_perms(PHPGW_ACL_ADD) == True) + { + $str .= 'alt="'.lang('New Entry').'" '; + } + + $str .= 'border="0" align="right">'; + + if($this->check_perms(PHPGW_ACL_ADD) == True) + { + $str .= ''; + } + + $p->set_var('new_event_link',$str); + $str = ''.$date['day'].''; + $p->set_var('day_number',$str); + } + else + { + $p->set_var('new_event_link',''); + $p->set_var('day_number',$date['day']); + } + + $p->parse('column_data','month_day',True); + + $rep_events = $this->get_sorted_by_date($date['raw'],$owner); + + if ($this->sorted_re) + { + $lr_events = CreateObject('calendar.calendar_item'); + $p->set_var('week_day_font_size','2'); + $p->set_var('events',''); + for ($k=0;$k<$this->sorted_re;$k++) + { + $lr_events = $rep_events[$k]; + $pict = 'circle.gif'; + for ($outer_loop=0;$outer_loop<$this->re;$outer_loop++) + { + $gr_events = $this->repeated_events[$outer_loop]; + if ($gr_events->id == $lr_events->id) + { + $pict = "rpt.gif"; + } + } +// $p->set_var('link_entry',$this->link_to_entry($lr_events->id, $pict, $this->is_private($lr_events,$owner).' - '.$lr_events->description)); + $p->set_var('link_entry',$this->link_to_entry($lr_events->id, $pict, $lr_events->description)); + if (intval($phpgw->common->show_date($lr_events->datetime,"Hi"))) + { + if ($phpgw_info["user"]["preferences"]["common"]["timeformat"] == "12") + { + $format = "h:i a"; + } + else + { + $format = "H:i"; + } + + if($lr_events->datetime < $date["raw"] && $lr_events->rpt_type=="none") + { + $temp_time = $this->makegmttime(0,0,0,$date["month"],$date["day"],$date["year"]); + $start_time = $phpgw->common->show_date($temp_time["raw"],$format); + } + else + { + $start_time = $phpgw->common->show_date($lr_events->datetime,$format); + } + + if($lr_events->edatetime > ($date["raw"] + 86400)) + { + $temp_time = $this->makegmttime(23,59,59,$date["month"],$date["day"],$date["year"]); + $end_time = $phpgw->common->show_date($temp_time["raw"],$format); + } + else + { + $end_time = $phpgw->common->show_date($lr_events->edatetime,$format); + } + + $p->set_var('start_time',$start_time); + $p->set_var('end_time',$end_time); + } + else + { + $p->set_var('start_time',''); + $p->set_var('end_time',''); + } + + $p->set_var('name',$this->is_private($lr_events,$owner)); + $p->parse('events','week_day_event',True); + } + } + $p->parse('column_data','week_day_events',True); + $p->set_var('events',''); + if (!$j || ($j && $date["full"] == $monthstart)) + { + $p->set_var('week_day_font_size','-2'); + + if(!$this->printer_friendly) + { + $str = 'week ' .(int)((date('z',($startdate+(24*3600*4)))+7)/7).''; + } + else + { + $str = 'week ' .(int)((date('z',($startdate+(24*3600*4)))+7)/7); + } + + $p->set_var('events',$str); + $p->parse('column_data','week_day_events',True); + $p->set_var('events',''); + } + } + $p->parse('column_header','month_column',True); + $p->set_var('column_data',''); + } + return $p->finish($p->parse('out','month_header')); + } + + function display_large_month($month,$year,$showyear,$owner=0) + { + global $phpgw, $phpgw_info; + + if($owner == $phpgw_info['user']['account_id']) + { + $owner = 0; + } + + $this->read_repeated_events($owner); + + $p = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('calendar')); + $p->set_unknowns('remove'); + + $templates = Array( + 'month' => 'month.tpl', + 'month_filler' => 'month_filler.tpl', + 'month_header' => 'month_header.tpl' + ); + $p->set_file($templates); + +// $p->set_block('month','month'); +// $p->set_block('month_filler','month_filler'); +// $p->set_block('month_header','month_header'); + + $p->set_var('month_filler_text',$this->large_month_header($month,$year,False)); + $p->parse('row','month_filler',True); + + $monthstart = intval(date('Ymd',mktime(0,0,0,$month ,1,$year))); + $monthend = intval(date('Ymd',mktime(0,0,0,$month + 1,0,$year))); + + $cellcolor = $phpgw_info['theme']['row_on']; + + for ($i=$this->weekstarttime;intval(date('Ymd',$i))<=$monthend;$i += (24 * 3600 * 7)) + { + $cellcolor = $phpgw->nextmatchs->alternate_row_color($cellcolor); + $p->set_var('month_filler_text',$this->display_week($i,False,$cellcolor,False,$owner,$monthstart,$monthend)); + $p->parse('row','month_filler',True); + } + return $p->finish($p->parse('out','month')); + } + + function display_large_week($day,$month,$year,$showyear,$owners=0) + { + global $phpgw, $phpgw_info; + + $p = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('calendar')); + $p->set_unknowns('remove'); + + $templates = Array( + 'month' => 'month.tpl', + 'month_filler' => 'month_filler.tpl', + 'month_header' => 'month_header.tpl' + ); + $p->set_file($templates); + +// $p->set_block('month','month'); +// $p->set_block('month_filler','month_filler'); +// $p->set_block('month_header','month_header'); + + $start = $this->get_weekday_start($year, $month, $day); + + $cellcolor = $phpgw_info['theme']['row_off']; + +// if ($phpgw_info['user']['preferences']['calendar']['weekdaystarts'] == 'Monday') +// { +// $start += 86400; +// } + +// $str = ''; + + $true_printer_friendly = $this->printer_friendly; + + if(is_array($owners)) + { + $display_name = True; + $counter = count($owners); + $owners_array = $owners; + } + else + { + $display_name = False; + $counter = 1; + $owners_array[0] = $owners; + } + $p->set_var('month_filler_text',$this->large_month_header($month,$year,$display_name)); + $p->parse('row','month_filler',True); + + for($i=0;$i<$counter;$i++) + { + $this->repeated_events = Null; + $owner = $owners_array[$i]; + + if($owner <> $phpgw_info['user']['account_id'] && $owner <> 0) + { + $this->printer_friendly = True; + } + else + { + $this->printer_friendly = $true_printer_friendly; + } + + $this->read_repeated_events($owner); + $p->set_var('month_filler_text',$this->display_week($start,True,$cellcolor,$display_name,$owner)); + $p->parse('row','month_filler',True); + } + $this->printer_friendly = $true_printer_friendly; + return $p->finish($p->parse('out','month')); + } + +// This function may be removed in the near future..... + function pretty_small_calendar($day,$month,$year,$link='') + { + global $phpgw, $phpgw_info, $view; + +// $tz_offset = (-1 * ((60 * 60) * intval($phpgw_info['user']['preferences']['common']['tz_offset']))); + $date = $this->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->get_weekday_start($year,$month,1); + + $str = ''; + $str .= ''; + $str .= ''; + $str .= ''; + $str .= ''; + $str .= '
'; + $str .= ''; + + if ($view == 'day') + { + $str .= ''; + } + + $str .= ''; + + if ($view == 'year') + { + $str .= ''; + $str .= ''; + } + + if ($view != 'year') + { + $str .= ''; + } + $str .= ''; + $str .= ''; + + for($i=0;$i<7;$i++) + { + $str .= ''; + } + + $str .= ''; + + for($i=$weekstarttime;date('Ymd',$i)<=$monthend;$i += (24 * 3600 * 7)) + { + $str .= ''; + for($j=0;$j<7;$j++) + { + $cal = $this->gmtdate($i + ($j * 24 * 3600)); + + if($cal['full'] >= $monthstart && $cal['full'] <= $monthend) + { + $str .= ''; + } + else + { + $str .= ''; + } + } + $str .= ''; + } + $str .= '
'.$day.'
'; + } + else + { + $str .= ''; + } + + if ($view != 'year') + { + if (!$this->printer_friendly) + { + $str .= ''; + } + + $str .= '<'; + if (!$this->printer_friendly) + { + $str .= ''; + } + $str .= ''; + } + + if (!$this->printer_friendly) + { + $str .= ''; + } + + $str .= lang($phpgw->common->show_date($date['raw'],'F')).' '.$year; + + if(!$this->printer_friendly) + { + $str .= ''; + } + + if ($view != 'year') + { + $str .= ''; + + if (!$this->printer_friendly) + { + $str .= ''; + } + + $str .= '>'; + + if (!$this->printer_friendly) + { + $str .= ''; + } + + $str .= '
'.substr(lang($days[$i]),0,2).'
'; + + if(!$this->printer_friendly) + { + $str .= ''; + } + + $str .= $cal['day']; + + if(!$this->printer_friendly) + { + $str .= ''; + } + + $str .= '.
'; + $str .= '
'; + return $str; + } + +// This function may be removed in the near future..... + function display_small_month($month,$year,$showyear,$link='') + { + global $phpgw, $phpgw_info; + + $weekstarttime = $this->get_weekday_start($year,$month,1); + + $str = ''; + $str .= ''; + + $monthstart = $this->localdates(mktime(0,0,0,$month ,1,$year)); + $monthend = $this->localdates(mktime(0,0,0,$month + 1,0,$year)); + + $str .= ''; + + for($i=0;$i<$daysinweek;$i++) + { + $str .= ''; + } + + $str .= ''; + + for($i=$weekstarttime;date('Ymd',$i)<=$monthend['full'];$i+=604800) + { + $str .= ''; + for($j=0;$j<$daysinweek;$j++) + { + $date = $this->localdates($i + ($j * 86400)); + + if($date['full']>=$monthstart['full'] && + $date['full']<=$monthend['full']) + { + $str .= ''; + } + else + { + $str .= ''; + } + } + $str .= ''; + } + $str .= '
'; + + if(!$this->printer_friendly) + { + $str .= ''; + } + + $str .= lang(date('F',$monthstart['raw'])); + + if($showyear) + { + $str .= ' '.$year; + } + + if(!$this->printer_friendly) + { + $str .= ''; + } + + $str .= '
'.lang($days[$i]).'
'; + + if(!$this->printer_friendly || $link) + { + $str .= ''; + } + + $str .= ''.date('j',$date['raw']); + if(!$this->printer_friendly || $link) + { + $str .= ''; + } + + $str .= '
'; + return $str; + } + + function mini_calendar($day,$month,$year,$link='') + { + global $phpgw, $phpgw_info, $view; + + $date = $this->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->get_weekday_start($year,$month,1); + + $p = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('calendar')); + $p->set_unknowns('remove'); + + $templates = Array( + 'mini_cal' => 'mini_cal.tpl', + 'mini_day' => 'mini_day.tpl', + 'mini_week' => 'mini_week.tpl' + ); + $p->set_file($templates); + +// $p->set_block('mini_cal','mini_week','mini_day'); + $p->set_var('img_root',$phpgw->common->get_image_path('phpgwapi')); + $p->set_var('cal_img_root',$phpgw->common->get_image_path('calendar')); + $p->set_var('bgcolor',$phpgw_info['theme']['bg_color']); + $p->set_var('bgcolor1',$phpgw_info['theme']['bg_color']); + + if(!$this->printer_friendly) + { + $p->set_var('month','' . lang($phpgw->common->show_date($date['raw'],'F')).' '.$year . ''); + } + else + { + $p->set_var('month',lang($phpgw->common->show_date($date['raw'],'F')).' '.$year); + } + + $p->set_var('prevmonth',$phpgw->link($phpgw_info['server']['webserver_url'].'/calendar/month.php','date='.$month_ago.'&owner='.$this->owner)); + $p->set_var('nextmonth',$phpgw->link($phpgw_info['server']['webserver_url'].'/calendar/month.php','date='.$month_ahead.'&owner='.$this->owner)); + $p->set_var('bgcolor2',$phpgw_info['theme']['cal_dayview']); + + for($i=0;$i<7;$i++) + { + $p->set_var('dayname','' . substr(lang($this->days[$i]),0,2) . ''); + $p->parse('daynames','mini_day',True); + } + + for($i=$weekstarttime;date('Ymd',$i)<=$monthend;$i += (24 * 3600 * 7)) + { + for($j=0;$j<7;$j++) + { + $str = ''; + $cal = $this->gmtdate($i + ($j * 24 * 3600)); + if($cal['full'] >= $monthstart && $cal['full'] <= $monthend) + { + if ($cal['full'] == $this->today['full']) + { + $p->set_var('day_image',' background="' . $phpgw_info['server']['webserver_url'] + . '/calendar/templates/' . $phpgw_info['server']['template_set'] + . '/images/mini_day_block.gif' . '"'); + } + else + { + $p->set_var('day_image',''); + $p->set_var('bgcolor2','#FFFFFF'); + } + + if(!$this->printer_friendly) + { + $str .= ''; + } + + $str .= $cal['day']; + + if (!$this->printer_friendly) + { + $str .= ''; + } + + if ($cal['full'] == $this->today['full']) + { + $p->set_var('dayname',"$str"); + } + else + { + $p->set_var('dayname',$str); + } + } + else + { + $p->set_var('day_image',''); + $p->set_var('bgcolor2','#FEFEFE'); + $p->set_var('dayname',''); + } + + $p->parse('monthweek_day','mini_day',True); + } + $p->parse('display_monthweek','mini_week',True); + $p->set_var('dayname',''); + $p->set_var('monthweek_day',''); + } + + return $p->finish($p->parse('out','mini_cal')); + } + + function html_for_event_day_at_a_glance ($event) + { + global $phpgw, $phpgw_info; + + if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12') + { + $format = 'h:i a'; + } + else + { + $format = 'H:i'; + } + + $ind = intval($phpgw->common->show_date($event->datetime,'H')); + + if($ind<$this->first_hour || $ind>$this->last_hour) + { + $ind = 99; + } + + if(!isset($this->hour_arr[$ind]) || !$this->hour_arr[$ind]) + { + $this->hour_arr[$ind] = ''; + } + + if (!$this->printer_friendly) + { + $this->hour_arr[$ind] .= '"; + } + + $this->hour_arr[$ind] .= '[' . $phpgw->common->show_date($event->datetime,$format); + if ($event->datetime <> $event->edatetime) + { + $this->hour_arr[$ind] .= ' - ' . $phpgw->common->show_date($event->edatetime,$format); + $end_t_h = intval($phpgw->common->show_date($event->edatetime,'H')); + $end_t_m = intval($phpgw->common->show_date($event->edatetime,'i')); + + if (end_t_m == 0) + { + $this->rowspan = $end_t_h - $ind; + } + else + { + $this->rowspan = $end_t_h - $ind + 1; + } + + if(isset($this->rowspan_arr[$ind])) + { + $r = $this->rowspan_arr[$ind]; + } + else + { + $r = 0; + } + + if ($this->rowspan > $r && $this->rowspan > 1) + { + $this->rowspan_arr[$ind] = $this->rowspan; + } + } + $this->hour_arr[$ind] .= '] '; + $this->hour_arr[$ind] .= '' . $event->description . ''; + + if ($event->priority == 3) + { + $this->hour_arr[$ind] .= ''; + } + + $this->hour_arr[$ind] .= $event->name; + + if ($event->priority == 3) + { + $this->hour_arr[$ind] .= ''; + } + + $this->hour_arr[$ind] .= '
'; + } + + function print_day_at_a_glance($date,$owner=0) + { + global $phpgw, $phpgw_info; + + $this->read_repeated_events($owner); + + $p = new Template($phpgw->common->get_tpl_dir('calendar')); + $p->set_unknowns('remove'); + + $templates = Array( + 'day_cal' => 'day_cal.tpl', + 'mini_week' => 'mini_week.tpl', + 'day_row_99' => 'day_row_99.tpl', + 'day_row_event' => 'day_row_event.tpl', + 'day_row_time' => 'day_tow_time.tpl' + ); + $p->set_file($templates); + +// $p->set_block('day_cal','mini_week','day_row_event','day_row_time'); + + + if (! $phpgw_info['user']['preferences']['calendar']['workdaystarts'] && + ! $phpgw_info['user']['preferences']['calendar']['workdayends']) + { + + $phpgw_info['user']['preferences']['calendar']['workdaystarts'] = 8; + $phpgw_info['user']['preferences']['calendar']['workdayends'] = 16; + } + + $this->first_hour = (int)$phpgw_info['user']['preferences']['calendar']['workdaystarts'] + 1; + $this->last_hour = (int)$phpgw_info['user']['preferences']['calendar']['workdayends'] + 1; + + $events = array(CreateObject('calendar.calendar_item')); + + $events = $this->get_sorted_by_date($date['raw']); + + if(!$events) + { + } else - $rpt_type = 'E'; + { + $event = CreateObject('calendar.calendar_item'); + for($i=0;$ihtml_for_event_day_at_a_glance($event); + } + } + } - $query = 'UPDATE calendar_entry SET cal_owner='.$owner.", cal_name='".addslashes($calinfo->name)."', " - . "cal_description='".addslashes($calinfo->description)."', cal_datetime=".$date.', ' - . 'cal_mdatetime='.$today.', cal_edatetime='.$enddate.', ' - . 'cal_priority='.$calinfo->priority.", cal_type='".$rpt_type."' "; + // 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. + $this->rowspan = 0; + $this->last_row = -1; + for ($i=0;$i<24;$i++) + { + if(isset($this->rowspan_arr[$i])) + { + $r = $this->rowspan_arr[$i]; + } + else + { + $r = 0; + } + + if(isset($this->hour_arr[$i])) + { + $h = $this->hour_arr[$i]; + } + else + { + $h = ''; + } + + if ($this->rowspan > 1) + { + if (strlen($h)) + { + $this->hour_arr[$this->last_row] .= $this->hour_arr[$i]; + $this->hour_arr[$i] = ''; + $this->rowspan_arr[$i] = 0; + } + $this->rowspan--; + } + elseif ($r > 1) + { + $this->rowspan = $this->rowspan_arr[$i]; + $this->last_row = $i; + } + } + $p->set_var('time_bgcolor',$phpgw_info['theme']['cal_dayview']); + $p->set_var('bg_time_image',$phpgw->common->get_image_path('phpgwapi').'/navbar_filler.jpg'); + $p->set_var('font_color',$phpgw_info['theme']['bg_text']); + $p->set_var('font',$phpgw_info['theme']['font']); + if (isset($this->hour_arr[99]) && strlen($this->hour_arr[99])) + { + $p->set_var('event',$this->hour_arr[99]); + $p->set_var('bgcolor',$phpgw->nextmatchs->alternate_row_color()); + $p->parse('monthweek_day','day_row_event',False); + + $p->set_var('open_link',''); + $p->set_var('close_link',''); + $p->set_var('time',' '); + $p->parse('monthweek_day','day_row_time',True); + $p->parse('row','mini_week',True); + $p->set_var('monthweek_day',''); + } + $this->rowspan = 0; + $times = 0; + for ($i=$this->first_hour;$i<=$this->last_hour;$i++) + { + if(isset($this->hour_arr[$i])) + { + $h = $this->hour_arr[$i]; + } + else + { + $h = ''; + } + + $time = $this->build_time_for_display($i * 10000); + $p->set_var('extras',''); + $p->set_var('event',' '); + if ($this->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 (strlen($h)) + { + $p->set_var('event',$this->hour_arr[$i]); + $p->set_var('bgcolor',$phpgw->nextmatchs->alternate_row_color()); + $p->parse('monthweek_day','day_row_event',False); + } + $this->rowspan--; + } + else + { + if (!strlen($h)) + { + $p->set_var('event',' '); + $p->set_var('bgcolor',$phpgw->nextmatchs->alternate_row_color()); + $p->parse('monthweek_day','day_row_event',False); + } + else + { + $this->rowspan = isset($this->rowspan_arr[$i])?$this->rowspan_arr[$i]:0; + if ($this->rowspan > 1) + { + $p->set_var('extras',' rowspan="'.$this->rowspan.'"'); + $p->set_var('event',$this->hour_arr[$i]); + $p->set_var('bgcolor',$phpgw->nextmatchs->alternate_row_color()); + $p->parse('monthweek_day','day_row_event',False); + } + else + { + $p->set_var('event',$this->hour_arr[$i]); + $p->set_var('bgcolor',$phpgw->nextmatchs->alternate_row_color()); + $p->parse('monthweek_day','day_row_event',False); + } + } + } + $p->set_var('open_link',''); + $p->set_var('close_link',''); + $str = ' - '; + + if(!$this->printer_friendly && $this->check_perms(PHPGW_ACL_EDIT)) + { + $str .= ''; + } + + $p->set_var('open_link',$str); + $p->set_var('time',(intval(substr($time,0,strpos($time,':'))) < 10 ? '0'.$time : $time) ); + + if(!$this->printer_friendly && $this->check_perms(PHPGW_ACL_EDIT)) + { + $p->set_var('close_link',''); + } + + $p->parse('monthweek_day','day_row_time',True); + $p->parse('row','mini_week',True); + $p->set_var('monthweek_day',''); + } // end for + return $p->finish($p->parse('out','day_cal')); + } // end function - if(($calinfo->access == 'public' || $calinfo->access == 'group') && count($calinfo->groups)) { - $query .= ", cal_access='".$calinfo->access."', cal_group = '".$phpgw->accounts->array_to_string($calinfo->access,$calinfo->groups)."' "; - } elseif(($calinfo->access == 'group') && !count($calinfo->groups)) { - $query .= ", cal_access='private', cal_group = '' "; - } else { - $query .= ", cal_access='".$calinfo->access."', cal_group = '' "; - } + function prep($calid) + { + global $phpgw, $phpgw_info; - $query .= 'WHERE cal_id='.$calid; + if(!$phpgw_info['user']['apps']['calendar']) return false; - $phpgw->db->query($query,__LINE__,__FILE__); - - $phpgw->db->query('DELETE FROM calendar_entry_user WHERE cal_id='.$calid,__LINE__,__FILE__); - - while ($participant = each($calinfo->participants)) { - $phpgw->db->query('INSERT INTO calendar_entry_user(cal_id,cal_login,cal_status) ' - . "VALUES($calid,".$participant[1].",'A')",__LINE__,__FILE__); - } - - if(strcmp($calinfo->rpt_type,'none') <> 0) { - $freq = ($calinfo->rpt_freq?$calinfo->rpt_freq:0); - - if($calinfo->rpt_use_end) { - $end = mktime(12,0,0,$calinfo->rpt_month,$calinfo->rpt_day,$calinfo->rpt_year) - ((60*60) * $phpgw_info['user']['preferences']['common']['tz_offset']); - $use_end = 1; - } else { - $end = 'NULL'; - $use_end = 0; + $db2 = $phpgw->db; + + $cal_id = array(); + if(is_long($calid)) + { + if(!$calid) + { + return false; + } + + $cal_id[0] = $calid; + } + elseif(is_string($calid)) + { + $calid = $phpgw->account->name2id($calid); + $db2->query('SELECT cal_id FROM calendar_entry WHERE cal_owner='.$calid,__LINE__,__FILE__); + while($phpgw->db->next_record()) + { + $cal_id[] = $db2->f('cal_id'); + } + } + elseif(is_array($calid)) + { + + if(is_string($calid[0])) + { + + for($i=0;$iquery('SELECT cal_id FROM calendar_entry WHERE cal_owner='.$calid[$i],__LINE__,__FILE__); + while($db2->next_record()) + { + $cal_id[] = $db2->f('cal_id'); + } + } + } + elseif(is_long($calid[0])) + { + $cal_id = $calid; + } + } + return $cal_id; } - if($calinfo->rpt_type == 'weekly' || $calinfo->rpt_type == 'daily') { - $days = ($calinfo->rpt_sun?'y':'n') - . ($calinfo->rpt_mon?'y':'n') - . ($calinfo->rpt_tue?'y':'n') - . ($calinfo->rpt_wed?'y':'n') - . ($calinfo->rpt_thu?'y':'n') - . ($calinfo->rpt_fri?'y':'n') - . ($calinfo->rpt_sat?'y':'n'); - } else { - $days = 'nnnnnnn'; + function getwithindates($from,$to) + { + global $phpgw, $phpgw_info; + + if(!$phpgw_info['user']['apps']['calendar']) + { + return false; + } + + $phpgw->db->query('SELECT cal_id FROM calendar_entry WHERE cal_date >= '.$from.' AND cal_date <= '.$to,__LINE__,__FILE__); + + if($phpgw->db->num_rows()) + { + while($phpgw->db->next_record()) + { + $calid[count($calid)] = intval($phpgw->db->f('cal_id')); + } + return $this->getevent($calid); + } + else + { + return false; + } } - $phpgw->db->query('SELECT count(cal_id) FROM calendar_entry_repeats WHERE cal_id='.$calid,__LINE__,__FILE__); - $phpgw->db->next_record(); - $num_rows = $phpgw->db->f(0); - if(!$num_rows) { - $phpgw->db->query('INSERT INTO calendar_entry_repeats(cal_id,cal_type,cal_use_end,cal_end,cal_days,cal_frequency) ' - ."VALUES($calid,'".$calinfo->rpt_type."',$use_end,$end,'$days',$freq)",__LINE__,__FILE__); - } else { - $phpgw->db->query("UPDATE calendar_entry_repeats SET cal_type='".$calinfo->rpt_type."', cal_use_end=".$use_end.', ' - ."cal_end='".$end."', cal_days='".$days."', cal_frequency=".$freq.' ' - .'WHERE cal_id='.$calid,__LINE__,__FILE__); + + function add($calinfo,$calid=0) + { + global $phpgw, $phpgw_info; + + $db2 = $phpgw->db; + + if(!$phpgw_info['user']['apps']['calendar']) + { + return false; + } + + if(!$calid) + { + $db2->lock(array('calendar_entry','calendar_entry_user','calendar_entry_repeats')); + $db2->query("INSERT INTO calendar_entry(cal_name) VALUES('".addslashes($calinfo->name)."')",__LINE__,__FILE__); + $db2->query('SELECT MAX(cal_id) FROM calendar_entry',__LINE__,__FILE__); + $db2->next_record(); + $calid = $db2->f(0); + $db2->unlock(); + } + if($calid) + { + return $this->modify($calinfo,$calid); + } } - } else { - $phpgw->db->query('DELETE FROM calendar_entry_repeats WHERE cal_id='.$calid,__LINE__,__FILE__); - } - $phpgw->db->unlock(); - } - function getevent($calid) { - global $phpgw; + function delete($calid=0) + { + global $phpgw; - $cal_id = $this->prep($calid); + $cal_id = $this->prep($calid); - if(!$cal_id) return false; + if(!$cal_id) + { + return false; + } - $db2 = $phpgw->db; + $db2 = $phpgw->db; - $db2->lock(array('calendar_entry','calendar_entry_user','calendar_entry_repeats')); + $db2->lock(array('calendar_entry','calendar_entry_user','calendar_entry_repeats')); - $calendar = CreateObject('calendar.calendar_item'); + for($i=0;$iquery('DELETE FROM calendar_entry_user WHERE cal_id='.$cal_id[$i],__LINE__,__FILE__); + $db2->query('DELETE FROM calendar_entry_repeats WHERE cal_id='.$cal_id[$i],__LINE__,__FILE__); + $db2->query('DELETE FROM calendar_entry WHERE cal_id='.$cal_id[$i],__LINE__,__FILE__); + } + $db2->unlock(); + } - for($i=0;$iquery('SELECT * FROM calendar_entry WHERE cal_id='.$cal_id[$i],__LINE__,__FILE__); - $db2->next_record(); + if(!$phpgw_info['user']['apps']['calendar']) + { + return false; + } - $calendar->id = (int)$db2->f('cal_id'); - $calendar->owner = $db2->f('cal_owner'); + if(!$calid) + { + return false; + } - $calendar->datetime = $db2->f('cal_datetime'); - $date = $this->date_to_epoch($phpgw->common->show_date($calendar->datetime,'Ymd')); - $calendar->day = $date['day']; - $calendar->month = $date['month']; - $calendar->year = $date['year']; + $db2 = $phpgw->db; - $time = $this->splittime($phpgw->common->show_date($calendar->datetime,'His')); - $calendar->hour = (int)$time['hour']; - $calendar->minute = (int)$time['minute']; - $calendar->ampm = $time['ampm']; + $db2->lock(array('calendar_entry','calendar_entry_user','calendar_entry_repeats')); -// echo '
TEST: hour: ' . (int)$time['hour']; -// echo '
TEST: minute: ' . (int)$time['minute']; -// echo '
TEST: ampm: ' . $time['ampm']; -// echo '
TEST: hour: ' . $calendar->hour; -// echo '
TEST: minute: ' . $calendar->minute; -// echo '
TEST: ampm: ' . $calendar->ampm; + $owner = ($calinfo->owner?$calinfo->owner:$phpgw_info['user']['account_id']); + + if ($phpgw_info['user']['preferences']['common']['timeformat'] == '12') + { + if ($calinfo->ampm == 'pm' && ($calinfo->hour < 12 && $calinfo->hour <> 12)) + { + $calinfo->hour += 12; + } + + if ($calinfo->end_ampm == 'pm' && ($calinfo->end_hour < 12 && $calinfo->end_hour <> 12)) + { + $calinfo->end_hour += 12; + } + } + $date = $this->makegmttime($calinfo->hour,$calinfo->minute,0,$calinfo->month,$calinfo->day,$calinfo->year); + $enddate = $this->makegmttime($calinfo->end_hour,$calinfo->end_minute,0,$calinfo->end_month,$calinfo->end_day,$calinfo->end_year); + $today = $this->gmtdate(time()); - $calendar->mdatetime = $db2->f('cal_mdatetime'); - $date = $this->date_to_epoch($phpgw->common->show_date($calendar->mdatetime,'Ymd')); - $calendar->mod_day = $date['day']; - $calendar->mod_month = $date['month']; - $calendar->mod_year = $date['year']; + if($calinfo->rpt_type != 'none') + { + $rpt_type = 'M'; + } + else + { + $rpt_type = 'E'; + } - $time = $this->splittime($phpgw->common->show_date($calendar->mdatetime,'His')); - $calendar->mod_hour = (int)$time['hour']; - $calendar->mod_minute = (int)$time['minute']; - $calendar->mod_second = (int)$time['second']; - $calendar->mod_ampm = $time['ampm']; + $query = 'UPDATE calendar_entry SET cal_owner='.$owner.", cal_name='".addslashes($calinfo->name)."', " + . "cal_description='".addslashes($calinfo->description)."', cal_datetime=".$date.', ' + . 'cal_mdatetime='.$today.', cal_edatetime='.$enddate.', ' + . 'cal_priority='.$calinfo->priority.", cal_type='".$rpt_type."' "; - $calendar->edatetime = $db2->f('cal_edatetime'); - $date = $this->date_to_epoch($phpgw->common->show_date($calendar->edatetime,'Ymd')); - $calendar->end_day = $date['day']; - $calendar->end_month = $date['month']; - $calendar->end_year = $date['year']; + if(($calinfo->access == 'public' || $calinfo->access == 'group') && count($calinfo->groups)) + { + $query .= ", cal_access='".$calinfo->access."', cal_group = '".$phpgw->accounts->array_to_string($calinfo->access,$calinfo->groups)."' "; + } + elseif(($calinfo->access == 'group') && !count($calinfo->groups)) + { + $query .= ", cal_access='private', cal_group = '' "; + } + else + { + $query .= ", cal_access='".$calinfo->access."', cal_group = '' "; + } - $time = $this->splittime($phpgw->common->show_date($calendar->edatetime,'His')); - $calendar->end_hour = (int)$time['hour']; - $calendar->end_minute = (int)$time['minute']; - $calendar->end_second = (int)$time['second']; - $calendar->end_ampm = $time['ampm']; + $query .= 'WHERE cal_id='.$calid; - $calendar->priority = $db2->f('cal_priority'); + $db2->query($query,__LINE__,__FILE__); + + $db2->query('DELETE FROM calendar_entry_user WHERE cal_id='.$calid,__LINE__,__FILE__); + + while ($participant = each($calinfo->participants)) + { + $phpgw->db->query('INSERT INTO calendar_entry_user(cal_id,cal_login,cal_status) ' + . "VALUES($calid,".$participant[1].",'A')",__LINE__,__FILE__); + } + + if(strcmp($calinfo->rpt_type,'none') <> 0) + { + $freq = ($calinfo->rpt_freq?$calinfo->rpt_freq:0); + + if($calinfo->rpt_use_end) + { + $end = $this->makegmttime(0,0,0,$calinfo->rpt_month,$calinfo->rpt_day,$calinfo->rpt_year); + $use_end = 1; + } + else + { + $end = 'NULL'; + $use_end = 0; + } + + if($calinfo->rpt_type == 'weekly' || $calinfo->rpt_type == 'daily') + { + $days = ($calinfo->rpt_sun?'y':'n') + . ($calinfo->rpt_mon?'y':'n') + . ($calinfo->rpt_tue?'y':'n') + . ($calinfo->rpt_wed?'y':'n') + . ($calinfo->rpt_thu?'y':'n') + . ($calinfo->rpt_fri?'y':'n') + . ($calinfo->rpt_sat?'y':'n'); + } + else + { + $days = 'nnnnnnn'; + } + + $db2->query('SELECT count(cal_id) FROM calendar_entry_repeats WHERE cal_id='.$calid,__LINE__,__FILE__); + $db2->next_record(); + $num_rows = $db2->f(0); + if(!$num_rows) + { + $db2->query('INSERT INTO calendar_entry_repeats(cal_id,cal_type,cal_use_end,cal_end,cal_days,cal_frequency) ' + ."VALUES($calid,'".$calinfo->rpt_type."',$use_end,".$end['raw'].",'$days',$freq)",__LINE__,__FILE__); + } + else + { + $db2->query("UPDATE calendar_entry_repeats SET cal_type='".$calinfo->rpt_type."', cal_use_end=".$use_end.', ' + ."cal_end='".$end."', cal_days='".$days."', cal_frequency=".$freq.' ' + .'WHERE cal_id='.$calid,__LINE__,__FILE__); + } + } + else + { + $db2->query('DELETE FROM calendar_entry_repeats WHERE cal_id='.$calid,__LINE__,__FILE__); + } + + $db2->unlock(); + } + + function getevent($calid) + { + global $phpgw; + + $cal_id = $this->prep($calid); + + if(!$cal_id) + { + return false; + } + + $db2 = $phpgw->db; + + $db2->lock(array('calendar_entry','calendar_entry_user','calendar_entry_repeats')); + + $calendar = CreateObject('calendar.calendar_item'); + + for($i=0;$iquery('SELECT * FROM calendar_entry WHERE cal_id='.$cal_id[$i],__LINE__,__FILE__); + $db2->next_record(); + + $calendar->id = (int)$db2->f('cal_id'); + $calendar->owner = $db2->f('cal_owner'); + + $calendar->datetime = $db2->f('cal_datetime'); +// $date = $this->date_to_epoch($phpgw->common->show_date($calendar->datetime,'Ymd')); + $date = $this->localdates($calendar->datetime); + $calendar->day = $date['day']; + $calendar->month = $date['month']; + $calendar->year = $date['year']; + + $time = $this->splittime($phpgw->common->show_date($calendar->datetime,'His')); + $calendar->hour = (int)$time['hour']; + $calendar->minute = (int)$time['minute']; + $calendar->ampm = $time['ampm']; + + $calendar->mdatetime = $db2->f('cal_mdatetime'); +// $date = $this->date_to_epoch($phpgw->common->show_date($calendar->mdatetime,'Ymd')); + $date = $this->localdates($calendar->mdatetime); + $calendar->mod_day = $date['day']; + $calendar->mod_month = $date['month']; + $calendar->mod_year = $date['year']; + + $time = $this->splittime($phpgw->common->show_date($calendar->mdatetime,'His')); + $calendar->mod_hour = (int)$time['hour']; + $calendar->mod_minute = (int)$time['minute']; + $calendar->mod_second = (int)$time['second']; + $calendar->mod_ampm = $time['ampm']; + + $calendar->edatetime = $db2->f('cal_edatetime'); +// $date = $this->date_to_epoch($phpgw->common->show_date($calendar->edatetime,'Ymd')); + $date = $this->localdates($calendar->edatetime); + $calendar->end_day = $date['day']; + $calendar->end_month = $date['month']; + $calendar->end_year = $date['year']; + + $time = $this->splittime($phpgw->common->show_date($calendar->edatetime,'His')); + $calendar->end_hour = (int)$time['hour']; + $calendar->end_minute = (int)$time['minute']; + $calendar->end_second = (int)$time['second']; + $calendar->end_ampm = $time['ampm']; + + $calendar->priority = $db2->f('cal_priority'); // not loading webcal_entry.cal_type - $calendar->access = $db2->f('cal_access'); - $calendar->name = htmlspecialchars(stripslashes($db2->f('cal_name'))); - $calendar->description = htmlspecialchars(stripslashes($db2->f('cal_description'))); - if($db2->f('cal_group')) { - $groups = explode(',',$db2->f('cal_group')); - for($j=1;$jgroups[] = $groups[$j]; - } - } + $calendar->access = $db2->f('cal_access'); + $calendar->name = htmlspecialchars(stripslashes($db2->f('cal_name'))); + $calendar->description = htmlspecialchars(stripslashes($db2->f('cal_description'))); + if($db2->f('cal_group')) + { + $groups = explode(',',$db2->f('cal_group')); + for($j=1;$jgroups[] = $groups[$j]; + } + } - $db2->query('SELECT * FROM calendar_entry_repeats WHERE cal_id='.$cal_id[$i],__LINE__,__FILE__); - if($db2->num_rows()) { - $db2->next_record(); + $db2->query('SELECT * FROM calendar_entry_repeats WHERE cal_id='.$cal_id[$i],__LINE__,__FILE__); + if($db2->num_rows()) + { + $db2->next_record(); - $rpt_type = strtolower($db2->f('cal_type')); - $calendar->rpt_type = !$rpt_type?'none':$rpt_type; - $calendar->rpt_use_end = $db2->f('cal_use_end'); - if($calendar->rpt_use_end) { - $calendar->rpt_end = $db2->f('cal_end'); - $rpt_end = $phpgw->common->show_date($db2->f('cal_end'),'Ymd'); - $date = $this->date_to_epoch($rpt_end); - $calendar->rpt_end_day = (int)$date['day']; - $calendar->rpt_end_month = (int)$date['month']; - $calendar->rpt_end_year = (int)$date['year']; - } else { - $calendar->rpt_end = 0; - $calendar->rpt_end_day = 0; - $calendar->rpt_end_month = 0; - $calendar->rpt_end_year = 0; - } - $calendar->rpt_freq = (int)$db2->f('cal_frequency'); - $rpt_days = strtoupper($db2->f('cal_days')); - $calendar->rpt_days = $rpt_days; - $calendar->rpt_sun = (substr($rpt_days,0,1)=='Y'?1:0); - $calendar->rpt_mon = (substr($rpt_days,1,1)=='Y'?1:0); - $calendar->rpt_tue = (substr($rpt_days,2,1)=='Y'?1:0); - $calendar->rpt_wed = (substr($rpt_days,3,1)=='Y'?1:0); - $calendar->rpt_thu = (substr($rpt_days,4,1)=='Y'?1:0); - $calendar->rpt_fri = (substr($rpt_days,5,1)=='Y'?1:0); - $calendar->rpt_sat = (substr($rpt_days,6,1)=='Y'?1:0); - } + $rpt_type = strtolower($db2->f('cal_type')); + $calendar->rpt_type = !$rpt_type?'none':$rpt_type; + $calendar->rpt_use_end = $db2->f('cal_use_end'); + if($calendar->rpt_use_end) + { + $calendar->rpt_end = $db2->f('cal_end'); + $rpt_end = $phpgw->common->show_date($db2->f('cal_end'),'Ymd'); +// $date = $this->date_to_epoch($rpt_end); + $date = $this->localdates($db2->f('cal_end')); + $calendar->rpt_end_day = (int)$date['day']; + $calendar->rpt_end_month = (int)$date['month']; + $calendar->rpt_end_year = (int)$date['year']; + } + else + { + $calendar->rpt_end = 0; + $calendar->rpt_end_day = 0; + $calendar->rpt_end_month = 0; + $calendar->rpt_end_year = 0; + } + + $calendar->rpt_freq = (int)$db2->f('cal_frequency'); + $rpt_days = strtoupper($db2->f('cal_days')); + $calendar->rpt_days = $rpt_days; + $calendar->rpt_sun = (substr($rpt_days,0,1)=='Y'?1:0); + $calendar->rpt_mon = (substr($rpt_days,1,1)=='Y'?1:0); + $calendar->rpt_tue = (substr($rpt_days,2,1)=='Y'?1:0); + $calendar->rpt_wed = (substr($rpt_days,3,1)=='Y'?1:0); + $calendar->rpt_thu = (substr($rpt_days,4,1)=='Y'?1:0); + $calendar->rpt_fri = (substr($rpt_days,5,1)=='Y'?1:0); + $calendar->rpt_sat = (substr($rpt_days,6,1)=='Y'?1:0); + } - $db2->query('SELECT * FROM calendar_entry_user WHERE cal_id='.$cal_id[$i],__LINE__,__FILE__); - if($db2->num_rows()) { - while($db2->next_record()) { - $calendar->participants[] = $db2->f('cal_login'); - $calendar->status[] = $db2->f('cal_status'); - } - } - $calendar_item[$i] = $calendar; - } - $db2->unlock(); - return $calendar_item; - } + $db2->query('SELECT * FROM calendar_entry_user WHERE cal_id='.$cal_id[$i],__LINE__,__FILE__); + + if($db2->num_rows()) + { + while($db2->next_record()) + { + $calendar->participants[] = $db2->f('cal_login'); + $calendar->status[] = $db2->f('cal_status'); + } + } + + $calendar_item[$i] = $calendar; + } + $db2->unlock(); + + return $calendar_item; + } - function findevent() { - global $phpgw_info; + function findevent() + { + global $phpgw_info; - if(!$phpgw_info['user']['apps']['calendar']) return false; - } - } + if(!$phpgw_info['user']['apps']['calendar']) + { + return false; + } + } +} ?> diff --git a/calendar/inc/footer.inc.php b/calendar/inc/footer.inc.php index 60a4c3ec69..acc65fcfaf 100644 --- a/calendar/inc/footer.inc.php +++ b/calendar/inc/footer.inc.php @@ -73,17 +73,17 @@ } else { $d = date ("d"); } - $d_time = mktime(0,0,0,$m,$d,$y); - $thisdate = date("Ymd", $d_time); - $sun = $phpgw->calendar->get_weekday_start($y,$m,$d); + $thisdate = $phpgw->calendar->makegmttime(0,0,0,$m,$d,$y); + $sun = $phpgw->calendar->get_weekday_start($y,$m,$d) - + ((60 * 60) * intval($phpgw_info['user']['preferences']['common']['tz_offset'])); for ($i = -7; $i <= 7; $i++) { - $tsun = $sun + (3600 * 24 * 7 * $i); - $tsat = $tsun + (3600 * 24 * 6); - echo "\n"; } ?> diff --git a/calendar/month.php b/calendar/month.php index fbab288e01..c383e5ce64 100755 --- a/calendar/month.php +++ b/calendar/month.php @@ -28,10 +28,6 @@ include('../header.inc.php'); - $next = $phpgw->calendar->splitdate(mktime(2,0,0,$thismonth + 1,1,$thisyear)); - - $prev = $phpgw->calendar->splitdate(mktime(2,0,0,$thismonth - 1,1,$thisyear)); - $view = "month"; $p = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('calendar')); @@ -48,13 +44,12 @@ $p->set_var('bg_text',$phpgw_info['theme']['bg_text']); - $p->set_var('small_calendar_prev',$phpgw->calendar->mini_calendar(1,$prev['month'],$prev['year'],'day.php')); + $p->set_var('small_calendar_prev',$phpgw->calendar->mini_calendar(1,$thismonth - 1,$thisyear,'day.php')); - $m = mktime(2,0,0,$thismonth,1,$thisyear); + $m = mktime(0,0,0,$thismonth,1,$thisyear); $p->set_var('month_identifier',lang(strftime("%B",$m)) . ' ' . $thisyear); $p->set_var('username',$phpgw->common->grab_owner_name($owner)); - $p->set_var('small_calendar_next',$phpgw->calendar->mini_calendar(1,$next['month'],$next['year'],'day.php')); - flush(); + $p->set_var('small_calendar_next',$phpgw->calendar->mini_calendar(1,$thismonth + 1,$thisyear,'day.php')); $p->set_var('large_month',$phpgw->calendar->display_large_month($thismonth,$thisyear,True,$owner)); if (!$friendly) { $param = 'year='.$thisyear.'&month='.$thismonth.'&friendly=1&filter='.$filter.'&owner='.$owner; diff --git a/calendar/week.php b/calendar/week.php index bd28021a28..11f0e0d98c 100755 --- a/calendar/week.php +++ b/calendar/week.php @@ -14,122 +14,117 @@ /* $Id$ */ - $phpgw_info["flags"] = array("currentapp" => "calendar", "enable_nextmatchs_class" => True); + $phpgw_flags = Array( + 'currentapp' => 'calendar', + 'enable_nextmatchs_class' => True + ); + + $phpgw_info['flags'] = $phpgw_flags; - if (isset($friendly) && $friendly){ - $phpgw_info["flags"]["noheader"] = True; - $phpgw_info["flags"]["nonavbar"] = True; - $phpgw_info["flags"]["noappheader"] = True; - $phpgw_info["flags"]["noappfooter"] = True; - $phpgw_info["flags"]["nofooter"] = True; - } else { - $friendly = 0; - } - include("../header.inc.php"); + if (isset($friendly) && $friendly) + { + $phpgw_info['flags']['noheader'] = True; + $phpgw_info['flags']['nonavbar'] = True; + $phpgw_info['flags']['noappheader'] = True; + $phpgw_info['flags']['noappfooter'] = True; + $phpgw_info['flags']['nofooter'] = True; + } + else + { + $friendly = 0; + } + + include('../header.inc.php'); - if(isset($friendly) && $friendly) { - if(!isset($phpgw_info["user"]["preferences"]["calendar"]["weekdaystarts"])) - $phpgw_info["user"]["preferences"]["calendar"]["weekdaystarts"] = "Sunday"; + $next = $phpgw->calendar->makegmttime(0,0,0,$thismonth,$thisday + 7,$thisyear); + $prev = $phpgw->calendar->makegmttime(0,0,0,$thismonth,$thisday - 7,$thisyear); - if (isset($date) && strlen($date) > 0) { - $thisyear = substr($date, 0, 4); - $thismonth = substr($date, 4, 2); - $thisday = substr($date, 6, 2); - } else { - if (!isset($day) || !$day) - $thisday = $phpgw->calendar->today["day"]; - else - $thisday = $day; - if (!isset($month) || !$month) - $thismonth = $phpgw->calendar->today["month"]; - else - $thismonth = $month; - if (!isset($year) || !$year) - $thisyear = $phpgw->calendar->today["year"]; - else - $thisyear = $year; - } - } + $nextmonth = $phpgw->calendar->makegmttime(0,0,0,$thismonth + 1,1,$thisyear); + $prevmonth = $phpgw->calendar->makegmttime(0,0,0,$thismonth - 1,1,$thisyear); - if(!isset($owner)) { $owner = 0; } + $first = $phpgw->calendar->gmtdate($phpgw->calendar->get_weekday_start($thisyear, $thismonth, $thisday)); + $last = $phpgw->calendar->gmtdate($first['raw'] + 518400); - if(!isset($owner) || !$owner) { - $owner = $phpgw_info['user']['account_id']; - $rights = PHPGW_ACL_READ + PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE; - } else { - $grants = $phpgw->acl->get_grants('calendar'); - if($grants[$owner]) - { - $rights = $grants[$owner]; - if (!($rights & PHPGW_ACL_READ)) - { - $owner = $phpgw_info['user']['account_id']; - } - } - } + $p = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('calendar')); + $templates = Array( + 'week_t' => 'week.tpl' + ); + $p->set_file($templates); - $next = $phpgw->calendar->splitdate(mktime(2,0,0,$thismonth,$thisday + 7,$thisyear)); - $prev = $phpgw->calendar->splitdate(mktime(2,0,0,$thismonth,$thisday - 7,$thisyear)); + $p->set_block('week_t','week'); - $nextmonth = $phpgw->calendar->splitdate(mktime(2,0,0,$thismonth + 1,1,$thisyear)); - $prevmonth = $phpgw->calendar->splitdate(mktime(2,0,0,$thismonth - 1,1,$thisyear)); + if ($friendly) + { + $p->set_var('printer_friendly',''); + } + else + { + $p->set_var('printer_friendly',''); + } - if($phpgw_info["user"]["preferences"]["calendar"]["weekdaystarts"] == "Sunday") { - $start = 7200; - } else { - $start = 93600; - } - $first = $phpgw->calendar->splitdate($phpgw->calendar->get_weekday_start($thisyear, $thismonth, $thisday) + $start); - $last = $phpgw->calendar->splitdate($first["raw"] + 518400); + $p->set_var('bg_text',$phpgw_info['theme']['bg_text']); - $p = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('calendar')); - $p->set_file(array("week_t" => "week.tpl")); + $p->set_var('small_calendar_prev',$phpgw->calendar->mini_calendar($thisday,$thismonth - 1,$thisyear,'day.php')); + + if (!$friendly) + { + $p->set_var('prev_week_link','<<'); + } + else + { + $p->set_var('prev_week_link','<<'); + } + + $p->set_var('small_calendar_this',$phpgw->calendar->mini_calendar($thisday,$thismonth,$thisyear,'day.php')); - $p->set_block("week_t","week"); + $week_id = lang(strftime("%B",$first['raw'])).' '.$first['day']; - if ($friendly) { - $p->set_var("printer_friendly",""); - } else { - $p->set_var("printer_friendly",""); - } + 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->set_var("bg_text",$phpgw_info["theme"]["bg_text"]); + $p->set_var('week_identifier',$week_id); + + $p->set_var('username',$phpgw->common->grab_owner_name($owner)); - $p->set_var("small_calendar_prev",$phpgw->calendar->mini_calendar($thisday,$prevmonth["month"],$prevmonth["year"],"day.php")); - if (!$friendly) { - $p->set_var("prev_week_link","link("week.php","year=".$prev["year"]."&month=".$prev["month"]."&day=".$prev["day"])."\"><<"); - } else { - $p->set_var("prev_week_link","<<"); - } - $p->set_var("small_calendar_this",$phpgw->calendar->mini_calendar($thisday,$thismonth,$thisyear,"day.php")); + if (!$friendly) + { + $p->set_var('next_week_link','>>'); + } + else + { + $p->set_var('next_week_link','>>'); + } + + $p->set_var('small_calendar_next',$phpgw->calendar->mini_calendar($thisday,$$thismonth + 1,$thisyear,'day.php')); + + $p->set_var('week_display',$phpgw->calendar->display_large_week($thisday,$thismonth,$thisyear,true,$owner)); - $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->set_var("week_identifier",$week_id); - $p->set_var("username",$phpgw->common->grab_owner_name($owner)); - - if (!$friendly) { - $p->set_var("next_week_link","link("week.php","year=".$next["year"]."&month=".$next["month"]."&day=".$next["day"])."\">>>"); - } else { - $p->set_var("next_week_link",">>"); - } - $p->set_var("small_calendar_next",$phpgw->calendar->mini_calendar($thisday,$nextmonth["month"],$nextmonth["year"],"day.php")); - $p->set_var("week_display",$phpgw->calendar->display_large_week($thisday,$thismonth,$thisyear,true,$owner)); - - if (!$friendly) { - $param = 'year='.$thisyear.'&month='.$thismonth.'&friendly=1&filter='.$filter; - $p->set_var("print","link("",$param)."\" TARGET=\"cal_printer_friendly\" onMouseOver=\"window." - . "status = '" . lang("Generate printer-friendly version"). "'\">[". lang("Printer Friendly") . "]"); - $p->parse("out","week_t"); - $p->pparse("out","week_t"); - } else { - $p->set_var("print",""); - $p->parse("out","week_t"); - $p->pparse("out","week_t"); - } - $phpgw->common->phpgw_footer(); + if (!$friendly) + { + $param = 'year='.$thisyear.'&month='.$thismonth.'&friendly=1&filter='.$filter; + $p->set_var('print','[". lang('Printer Friendly') . ']'); + $p->parse('out','week_t'); + $p->pparse('out','week_t'); + } + else + { + $p->set_var('print',''); + $p->parse('out','week_t'); + $p->pparse('out','week_t'); + } + $phpgw->common->phpgw_footer(); ?>