diff options
author | jwangen <jwangen> | 2002-12-08 09:45:58 +0000 |
---|---|---|
committer | jwangen <jwangen> | 2002-12-08 09:45:58 +0000 |
commit | e3f3eacc9393d0f3a12321366a9e2083b5d25c7f (patch) | |
tree | 4a5532724a3a7d20766e08166ce759ec98474f8b /functions | |
parent | 6847abd72e87f2a18d2fe44c55ac7c5eb567d03d (diff) | |
download | phpicalendar-e3f3eacc9393d0f3a12321366a9e2083b5d25c7f.tar.gz phpicalendar-e3f3eacc9393d0f3a12321366a9e2083b5d25c7f.tar.bz2 phpicalendar-e3f3eacc9393d0f3a12321366a9e2083b5d25c7f.zip |
Fixed various bugs, Currently working on events that span multiple days
Diffstat (limited to 'functions')
-rw-r--r-- | functions/date_functions.php | 165 | ||||
-rw-r--r-- | functions/draw_functions.php | 17 | ||||
-rw-r--r-- | functions/ical_parser.php | 64 | ||||
-rw-r--r-- | functions/todo.js | 38 |
4 files changed, 237 insertions, 47 deletions
diff --git a/functions/date_functions.php b/functions/date_functions.php index 893e61a..9f6cb15 100644 --- a/functions/date_functions.php +++ b/functions/date_functions.php @@ -1 +1,164 @@ -<?php
// date_functions.php
// functions for returning or comparing dates
// not a date function, but I didn't know where to put it
// for backwards compatibility
if (phpversion() < '4.1') {
function array_key_exists($key, $arr) {
if (!is_array($arr)) return false;
foreach (array_keys($arr) as $k) {
if ("$k" == "$key") return true;
}
return false;
}
}
// takes iCalendar 2 day format and makes it into 3 characters
// if $txt is true, it returns the 3 letters, otherwise it returns the
// integer of that day; 0=Sun, 1=Mon, etc.
function two2threeCharDays($day, $txt=true) {
switch($day) {
case 'SU': return ($txt ? 'sun' : '0');
case 'MO': return ($txt ? 'mon' : '1');
case 'TU': return ($txt ? 'tue' : '2');
case 'WE': return ($txt ? 'wed' : '3');
case 'TH': return ($txt ? 'thu' : '4');
case 'FR': return ($txt ? 'fri' : '5');
case 'SA': return ($txt ? 'sat' : '6');
}
}
// dateOfWeek() takes a date in Ymd and a day of week in 3 letters or more
// and returns the date of that day. (ie: "sun" or "sunday" would be acceptable values of $day but not "su")
function dateOfWeek($Ymd, $day) {
global $week_start_day;
if (!isset($week_start_day)) $week_start_day = 'Sunday';
$timestamp = strtotime($Ymd);
$num = date('w', strtotime($week_start_day));
$start_day_time = strtotime((date('w',$timestamp)==$num ? "$week_start_day" : "last $week_start_day"), $timestamp);
$ret_unixtime = strtotime($day,$start_day_time);
$ret_unixtime = strtotime('+12 hours', $ret_unixtime);
$ret = date('Ymd',$ret_unixtime);
return $ret;
}
// function to compare to dates in Ymd and return the number of weeks
// that differ between them. requires dateOfWeek()
function weekCompare($now, $then) {
global $week_start_day;
$sun_now = dateOfWeek($now, $week_start_day);
$sun_then = dateOfWeek($then, $week_start_day);
$seconds_now = strtotime($sun_now);
$seconds_then = strtotime($sun_then);
$diff_seconds = $seconds_now - $seconds_then;
$diff_minutes = $diff_seconds/60;
$diff_hours = $diff_minutes/60;
$diff_days = round($diff_hours/24);
$diff_weeks = $diff_days/7;
return $diff_weeks;
}
// function to compare to dates in Ymd and return the number of days
// that differ between them.
function dayCompare($now, $then) {
$seconds_now = strtotime($now);
$seconds_then = strtotime($then);
$diff_seconds = $seconds_now - $seconds_then;
$diff_minutes = $diff_seconds/60;
$diff_hours = $diff_minutes/60;
$diff_days = round($diff_hours/24);
return $diff_days;
}
// function to compare to dates in Ymd and return the number of months
// that differ between them.
function monthCompare($now, $then) {
ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $now, $date_now);
ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $then, $date_then);
$diff_years = $date_now[1] - $date_then[1];
$diff_months = $date_now[2] - $date_then[2];
if ($date_now[2] < $date_then[2]) {
$diff_years -= 1;
$diff_months = ($diff_months + 12) % 12;
}
$diff_months = ($diff_years * 12) + $diff_months;
return $diff_months;
}
function yearCompare($now, $then) {
ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $now, $date_now);
ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $then, $date_then);
$diff_years = $date_now[1] - $date_then[1];
return $diff_years;
}
// localizeDate() - similar to strftime but uses our preset arrays of localized
// months and week days and only supports %A, %a, %B, %b, %e, and %Y
// more can be added as needed but trying to keep it small while we can
function localizeDate($format, $timestamp) {
global $daysofweek_lang, $daysofweekshort_lang, $daysofweekreallyshort_lang, $monthsofyear_lang, $monthsofyear_lang, $monthsofyearshort_lang;
$year = date("Y", $timestamp);
$month = date("n", $timestamp)-1;
$day = date("j", $timestamp);
$dayofweek = date("w", $timestamp);
$date = str_replace('%Y', $year, $format);
$date = str_replace('%e', $day, $date);
$date = str_replace('%B', $monthsofyear_lang[$month], $date);
$date = str_replace('%b', $monthsofyearshort_lang[$month], $date);
$date = str_replace('%A', $daysofweek_lang[$dayofweek], $date);
$date = str_replace('%a', $daysofweekshort_lang[$dayofweek], $date);
return $date;
}
// calcOffset takes an offset (ie, -0500) and returns it in the number of seconds
function calcOffset($offset_str) {
$sign = substr($offset_str, 0, 1);
$hours = substr($offset_str, 1, 2);
$mins = substr($offset_str, 3, 2);
$secs = ((int)$hours * 3600) + ((int)$mins * 60);
if ($sign == '-') $secs = 0 - $secs;
return $secs;
}
// calcTime calculates the unixtime of a new offset by comparing it to the current offset
// $have is the current offset (ie, '-0500')
// $want is the wanted offset (ie, '-0700')
// $time is the unixtime relative to $have
function calcTime($have, $want, $time) {
if ($have == 'none' || $want == 'none') return $time;
$have_secs = calcOffset($have);
$want_secs = calcOffset($want);
$diff = $want_secs - $have_secs;
$time += $diff;
return $time;
}
function chooseOffset($time) {
global $timezone, $tz_array;
if (!isset($timezone)) $timezone = '';
switch ($timezone) {
case '':
$offset = 'none';
break;
case 'Same as Server':
$offset = date('O', $time);
break;
default:
if (is_array($tz_array) && array_key_exists($timezone, $tz_array)) {
$dlst = date('I', $time);
$offset = $tz_array[$timezone][$dlst];
} else {
$offset = '+0000';
}
}
return $offset;
}
?>
\ No newline at end of file +<?php +// date_functions.php +// functions for returning or comparing dates + +// not a date function, but I didn't know where to put it +// for backwards compatibility +if (phpversion() < '4.1') { + function array_key_exists($key, $arr) { + if (!is_array($arr)) return false; + foreach (array_keys($arr) as $k) { + if ("$k" == "$key") return true; + } + return false; + } +} + +// takes iCalendar 2 day format and makes it into 3 characters +// if $txt is true, it returns the 3 letters, otherwise it returns the +// integer of that day; 0=Sun, 1=Mon, etc. +function two2threeCharDays($day, $txt=true) { + switch($day) { + case 'SU': return ($txt ? 'sun' : '0'); + case 'MO': return ($txt ? 'mon' : '1'); + case 'TU': return ($txt ? 'tue' : '2'); + case 'WE': return ($txt ? 'wed' : '3'); + case 'TH': return ($txt ? 'thu' : '4'); + case 'FR': return ($txt ? 'fri' : '5'); + case 'SA': return ($txt ? 'sat' : '6'); + } +} + +// dateOfWeek() takes a date in Ymd and a day of week in 3 letters or more +// and returns the date of that day. (ie: "sun" or "sunday" would be acceptable values of $day but not "su") +function dateOfWeek($Ymd, $day) { + global $week_start_day; + if (!isset($week_start_day)) $week_start_day = 'Sunday'; + $timestamp = strtotime($Ymd); + $num = date('w', strtotime($week_start_day)); + $start_day_time = strtotime((date('w',$timestamp)==$num ? "$week_start_day" : "last $week_start_day"), $timestamp); + $ret_unixtime = strtotime($day,$start_day_time); + $ret_unixtime = strtotime('+12 hours', $ret_unixtime); + $ret = date('Ymd',$ret_unixtime); + return $ret; +} + +// function to compare to dates in Ymd and return the number of weeks +// that differ between them. requires dateOfWeek() +function weekCompare($now, $then) { + global $week_start_day; + $sun_now = dateOfWeek($now, $week_start_day); + $sun_then = dateOfWeek($then, $week_start_day); + $seconds_now = strtotime($sun_now); + $seconds_then = strtotime($sun_then); + $diff_seconds = $seconds_now - $seconds_then; + $diff_minutes = $diff_seconds/60; + $diff_hours = $diff_minutes/60; + $diff_days = round($diff_hours/24); + $diff_weeks = $diff_days/7; + + return $diff_weeks; +} + +// function to compare to dates in Ymd and return the number of days +// that differ between them. +function dayCompare($now, $then) { + $seconds_now = strtotime($now); + $seconds_then = strtotime($then); + $diff_seconds = $seconds_now - $seconds_then; + $diff_minutes = $diff_seconds/60; + $diff_hours = $diff_minutes/60; + $diff_days = round($diff_hours/24); + + return $diff_days; +} + +// function to compare to dates in Ymd and return the number of months +// that differ between them. +function monthCompare($now, $then) { + ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $now, $date_now); + ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $then, $date_then); + $diff_years = $date_now[1] - $date_then[1]; + $diff_months = $date_now[2] - $date_then[2]; + if ($date_now[2] < $date_then[2]) { + $diff_years -= 1; + $diff_months = ($diff_months + 12) % 12; + } + $diff_months = ($diff_years * 12) + $diff_months; + + return $diff_months; +} + +function yearCompare($now, $then) { + ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $now, $date_now); + ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $then, $date_then); + $diff_years = $date_now[1] - $date_then[1]; + return $diff_years; +} + +// localizeDate() - similar to strftime but uses our preset arrays of localized +// months and week days and only supports %A, %a, %B, %b, %e, and %Y +// more can be added as needed but trying to keep it small while we can +function localizeDate($format, $timestamp) { + global $daysofweek_lang, $daysofweekshort_lang, $daysofweekreallyshort_lang, $monthsofyear_lang, $monthsofyear_lang, $monthsofyearshort_lang; + $year = date("Y", $timestamp); + $month = date("n", $timestamp)-1; + $day = date("j", $timestamp); + $dayofweek = date("w", $timestamp); + + $date = str_replace('%Y', $year, $format); + $date = str_replace('%e', $day, $date); + $date = str_replace('%B', $monthsofyear_lang[$month], $date); + $date = str_replace('%b', $monthsofyearshort_lang[$month], $date); + $date = str_replace('%A', $daysofweek_lang[$dayofweek], $date); + $date = str_replace('%a', $daysofweekshort_lang[$dayofweek], $date); + + return $date; + +} +// calcOffset takes an offset (ie, -0500) and returns it in the number of seconds +function calcOffset($offset_str) { + $sign = substr($offset_str, 0, 1); + $hours = substr($offset_str, 1, 2); + $mins = substr($offset_str, 3, 2); + $secs = ((int)$hours * 3600) + ((int)$mins * 60); + if ($sign == '-') $secs = 0 - $secs; + return $secs; +} + +// calcTime calculates the unixtime of a new offset by comparing it to the current offset +// $have is the current offset (ie, '-0500') +// $want is the wanted offset (ie, '-0700') +// $time is the unixtime relative to $have +function calcTime($have, $want, $time) { + if ($have == 'none' || $want == 'none') return $time; + $have_secs = calcOffset($have); + $want_secs = calcOffset($want); + $diff = $want_secs - $have_secs; + $time += $diff; + return $time; +} + +function chooseOffset($time) { + global $timezone, $tz_array; + if (!isset($timezone)) $timezone = ''; + switch ($timezone) { + case '': + $offset = 'none'; + break; + case 'Same as Server': + $offset = date('O', $time); + break; + default: + if (is_array($tz_array) && array_key_exists($timezone, $tz_array)) { + $dlst = date('I', $time); + $offset = $tz_array[$timezone][$dlst]; + } else { + $offset = '+0000'; + } + } + return $offset; +} + + +?>
\ No newline at end of file diff --git a/functions/draw_functions.php b/functions/draw_functions.php index d54c250..f84b5c2 100644 --- a/functions/draw_functions.php +++ b/functions/draw_functions.php @@ -38,22 +38,11 @@ function drawEventTimes ($start, $end) { // word wrap function that returns specified number of lines // when lines is 0, it returns the entire string as wordwrap() does it function word_wrap($str, $length, $lines=0) { - $str = wordwrap($str, $length); if ($lines > 0) { - $str_arr = explode("\n", $str); - if (count($str_arr) < $lines) $lines = count($str_arr); - $str = ''; - for ($i=0; $i<($lines-1);$i++) { - $str .= $str_arr[$i].'<br>'; + $len = $length * $lines; + if ($len < strlen($str)) { + $str = substr($str,0,$len).'...'; } - if (count($str_arr) > ($lines)) { - $tmp_str = substr($str_arr[$i], 0, ($length-2)); - $str .= $tmp_str . '...'; - } else { - $str .= $str_arr[$i]; - } - } else { - $str = nl2br(trim($str)); } return $str; } diff --git a/functions/ical_parser.php b/functions/ical_parser.php index eda7cc6..b3dd4d1 100644 --- a/functions/ical_parser.php +++ b/functions/ical_parser.php @@ -122,6 +122,8 @@ if ($parse_file) { $start_date_tmp = $recurrence_id['date']; if (!isset($start_date)) $start_date = $old_start_date; if (!isset($start_time)) $start_time = $master_array[$old_start_date][$old_start_time][$uid]['event_start']; + if (!isset($start_unixtime)) $start_unixtime = $master_array[$old_start_date][$old_start_time][$uid]['start_unixtime']; + if (!isset($end_unixtime)) $end_unixtime = $master_array[$old_start_date][$old_start_time][$uid]['end_unixtime']; if (!isset($end_time)) $end_time = $master_array[$old_start_date][$old_start_time][$uid]['event_end']; if (!isset($summary)) $summary = $master_array[$old_start_date][$old_start_time][$uid]['event_text']; if (!isset($length)) $length = $master_array[$old_start_date][$old_start_time][$uid]['event_length']; @@ -145,16 +147,20 @@ if ($parse_file) { $allday_start = $start_date; $allday_end = ($start_date + 1); } - - // If the events go past midnight - // Needs to be re-thunk - if ($end_time < $start_time) $end_time = 2359; } - + if (isset($start_unixtime,$end_unixtime) && date('d',$start_unixtime) != date('d',$end_unixtime)) { + $spans_day = true; + } else { + $spans_day = false; + } if (isset($start_time) && $start_time != '') { ereg ('([0-9]{2})([0-9]{2})', $start_time, $time); ereg ('([0-9]{2})([0-9]{2})', $end_time, $time2); - $length = ($time2[1]*60+$time2[2]) - ($time[1]*60+$time[2]); + if (isset($start_unixtime) && isset($end_unixtime)) { + $length = $end_unixtime - $start_unixtime; + } else { + $length = ($time2[1]*60+$time2[2]) - ($time[1]*60+$time[2]); + } $drawKey = drawEventTimes($start_time, $end_time); ereg ('([0-9]{2})([0-9]{2})', $drawKey['draw_start'], $time3); @@ -193,9 +199,33 @@ if ($parse_file) { // Handling regular events if ((isset($start_time) && $start_time != '') && (!isset($allday_start) || $allday_start == '')) { - $nbrOfOverlaps = checkOverlap($start_date, $start_time, $end_time, $uid); - $master_array[($start_date)][($hour.$minute)][$uid] = array ('event_start' => $start_time, 'event_text' => $summary, 'event_end' => $end_time, 'event_length' => $length, 'event_overlap' => $nbrOfOverlaps, 'description' => $description, 'status' => $status, 'class' => $class); - if (!$write_processed) $master_array[($start_date)][($hour.$minute)][$uid]['exception'] = true; + if ($spans_day) { + $start_tmp = strtotime(date('Ymd',$start_unixtime)); + $end_date_tmp = date('Ymd',$end_unixtime); + while ($start_tmp < $end_unixtime) { + $start_date_tmp = date('Ymd',$start_tmp); + if ($start_date_tmp == $start_date) { + $time_tmp = $hour.$minute; + $start_time_tmp = $start_time; + } else { + $time_tmp = '0000'; + $start_time_tmp = '0000'; + } + if ($start_date_tmp == $end_date_tmp) { + $end_time_tmp = $end_time; + } else { + $end_time_tmp = '2400'; + } + $nbrOfOverlaps = checkOverlap($start_date_tmp, $start_time_tmp, $end_time_tmp, $uid); + $master_array[$start_date_tmp][$time_tmp][$uid] = array ('event_start' => $start_time_tmp, 'event_end' => $end_time_tmp, 'start_unixtime' => $start_unixtime, 'end_unixtime' => $end_unixtime, 'event_text' => $summary, 'event_length' => $length, 'event_overlap' => $nbrOfOverlaps, 'description' => $description, 'status' => $status, 'class' => $class, 'spans_day' => true); + $start_tmp = strtotime('+1 day',$start_tmp); + } + if (!$write_processed) $master_array[$start_date][($hour.$minute)][$uid]['exception'] = true; + } else { + $nbrOfOverlaps = checkOverlap($start_date, $start_time, $end_time, $uid); + $master_array[($start_date)][($hour.$minute)][$uid] = array ('event_start' => $start_time, 'event_end' => $end_time, 'start_unixtime' => $start_unixtime, 'end_unixtime' => $end_unixtime, 'event_text' => $summary, 'event_length' => $length, 'event_overlap' => $nbrOfOverlaps, 'description' => $description, 'status' => $status, 'class' => $class, 'spans_day' => false); + if (!$write_processed) $master_array[($start_date)][($hour.$minute)][$uid]['exception'] = true; + } } // Handling of the recurring events, RRULE @@ -445,8 +475,14 @@ if ($parse_file) { } // use the same code to write the data instead of always changing it 5 times if (isset($recur_data) && is_array($recur_data)) { + $recur_data_hour = substr($start_time,0,2); + $recur_data_minute = substr($start_time,2,2); foreach($recur_data as $recur_data_time) { - $recur_data_date = date('Ymd', $recur_data_time); + $recur_data_year = date('Y', $recur_data_time); + $recur_data_month = date('m', $recur_data_time); + $recur_data_day = date('d', $recur_data_time); + $recur_data_date = $recur_data_year.$recur_data_month.$recur_data_day; + if (($recur_data_time > $start_date_time) && ($recur_data_time <= $end_date_time) && ($count_to != $count) && !in_array($recur_data_date, $except_dates)) { if (isset($allday_start) && $allday_start != '') { $start_time2 = $recur_data_time; @@ -457,8 +493,10 @@ if ($parse_file) { $start_time2 = strtotime('+1 day', $start_time2); } } else { + $start_unixtime_tmp = mktime($recur_data_hour,$recur_data_minute,0,$recur_data_month,$recur_data_day,$recur_data_year); + $end_unixtime_tmp = $start_unixtime_tmp + $length; $nbrOfOverlaps = checkOverlap($recur_data_date, $start_time, $end_time, $uid); - $master_array[($recur_data_date)][($hour.$minute)][$uid] = array ('event_start' => $start_time, 'event_text' => $summary, 'event_end' => $end_time, 'event_length' => $length, 'event_overlap' => $nbrOfOverlaps, 'description' => $description, 'status' => $status, 'class' => $class); + $master_array[($recur_data_date)][($hour.$minute)][$uid] = array ('event_start' => $start_time, 'event_end' => $end_time, 'start_unixtime' => $start_unixtime_tmp, 'end_unixtime' => $end_unixtime_tmp, 'event_text' => $summary, 'event_length' => $length, 'event_overlap' => $nbrOfOverlaps, 'description' => $description, 'status' => $status, 'class' => $class); } } } @@ -799,8 +837,8 @@ if ($parse_file) { $minutes = ereg_replace('M', '', $duration[4]); $seconds = ereg_replace('S', '', $duration[5]); $the_duration = ($weeks * 60 * 60 * 24 * 7) + ($days * 60 * 60 * 24) + ($hours * 60 * 60) + ($minutes * 60) + ($seconds); - $beginning = (strtotime($start_time) + $the_duration); - $end_time = date ('Hi', $beginning); + $end_unixtime = $start_unixtime + $the_duration; + $end_time = date ('Hi', $end_unixtime); $first_duration = FALSE; } break; diff --git a/functions/todo.js b/functions/todo.js index cdcb7f8..d53d2dd 100644 --- a/functions/todo.js +++ b/functions/todo.js @@ -1,19 +1,19 @@ -
-<script language="JavaScript" type="text/javascript">
-<!--
- function openTodoInfo(vtodo_array)
- {
- var windowW = 450;
- var windowH = 275;
-
- var url = "includes/todo.php?vtodo_array="+vtodo_array;
-
- options = "scrollbars=no"+",width="+windowW+",height="+windowH;
-
- info = window.open(url, "Popup", options);
-
- info.focus();
- }
-
-//-->
-</script>
+ +<script language="JavaScript" type="text/javascript"> +<!-- + function openTodoInfo(vtodo_array) + { + var windowW = 450; + var windowH = 275; + + var url = "includes/todo.php?vtodo_array="+vtodo_array; + + options = "scrollbars=no"+",width="+windowW+",height="+windowH; + + info = window.open(url, "Popup", options); + + info.focus(); + } + +//--> +</script> |