From e3f3eacc9393d0f3a12321366a9e2083b5d25c7f Mon Sep 17 00:00:00 2001 From: jwangen Date: Sun, 8 Dec 2002 09:45:58 +0000 Subject: Fixed various bugs, Currently working on events that span multiple days --- calendars/greg.ics | 4 +- functions/date_functions.php | 165 ++++++++++++++++++++++++++++++++++++++++++- functions/draw_functions.php | 17 +---- functions/ical_parser.php | 64 +++++++++++++---- functions/todo.js | 38 +++++----- week.php | 4 +- 6 files changed, 241 insertions(+), 51 deletions(-) diff --git a/calendars/greg.ics b/calendars/greg.ics index b5de9b9..e4647c7 100644 --- a/calendars/greg.ics +++ b/calendars/greg.ics @@ -32,8 +32,8 @@ SEQUENCE:1 DTSTAMP:20021121T170222Z SUMMARY:Melissa Pitches concert (time?) UID:80DFC162-FD77-11D6-B909-000393BBDCD8 -DTSTART;TZID=US/Eastern:20021123T190000 -DURATION:PT2H30M +DTSTART;TZID=US/Eastern:20021120T130000 +DTEND;TZID=US/Eastern:20021123T100000 END:VEVENT BEGIN:VEVENT 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 @@ - \ No newline at end of file + \ 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].'
'; + $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 @@ - - + + diff --git a/week.php b/week.php index 43a6add..474cdc0 100644 --- a/week.php +++ b/week.php @@ -297,8 +297,8 @@ for ($i=0;$i<7;$i++) { $event_text = stripslashes(urldecode($this_time_arr[($event_length[$thisday][$i]["key"])]["event_text"])); $event_text = word_wrap($event_text, 25, $week_events_lines); $event_text2 = urlencode(addslashes($this_time_arr[($event_length[$thisday][$i]["key"])]["event_text"])); - $event_start = strtotime ($this_time_arr[($event_length[$thisday][$i]["key"])]["event_start"]); - $event_end = strtotime ($this_time_arr[($event_length[$thisday][$i]["key"])]["event_end"]); + $event_start = $this_time_arr[($event_length[$thisday][$i]["key"])]["start_unixtime"]; + $event_end = $this_time_arr[($event_length[$thisday][$i]["key"])]["end_unixtime"]; $description = urlencode(addslashes($this_time_arr[($event_length[$thisday][$i]["key"])]["description"])); $event_start = date ($timeFormat, $event_start); $event_end = date ($timeFormat, $event_end); -- cgit v1.2.3