aboutsummaryrefslogtreecommitdiffstats
path: root/functions
diff options
context:
space:
mode:
authorJim Hu <jimhu@users.sourceforge.net>2008-12-27 10:58:50 +0000
committerJim Hu <jimhu@users.sourceforge.net>2008-12-27 10:58:50 +0000
commit333f00a0225a94e94f4388937e1741e102c5b110 (patch)
tree060911b53d2d4feffee5c69927a1fdeeae0915ed /functions
parentf53afe845eff0f8712afbdcb908995df267a005f (diff)
downloadphpicalendar-333f00a0225a94e94f4388937e1741e102c5b110.tar.gz
phpicalendar-333f00a0225a94e94f4388937e1741e102c5b110.tar.bz2
phpicalendar-333f00a0225a94e94f4388937e1741e102c5b110.zip
rewrite and condense master array writing in end_vevent.php. Condense draw_week in template.php. bump vers
Diffstat (limited to 'functions')
-rw-r--r--functions/date_functions.php2
-rw-r--r--functions/ical_parser.php4
-rw-r--r--functions/init/configs.php2
-rw-r--r--functions/parse/end_vevent.php262
-rw-r--r--functions/parse/overlapping_events.php20
-rw-r--r--functions/parse/recur_functions.php2
-rw-r--r--functions/template.php111
7 files changed, 156 insertions, 247 deletions
diff --git a/functions/date_functions.php b/functions/date_functions.php
index 07950ec..c03c5ae 100644
--- a/functions/date_functions.php
+++ b/functions/date_functions.php
@@ -166,6 +166,7 @@ function chooseOffset($time, $timezone = '') {
function openevent($event_date, $time, $uid, $arr, $lines = 0, $length = 0, $link_class = '', $pre_text = '', $post_text = '') {
global $cpath, $master_array;
+ $return = '';
$event_text = stripslashes(urldecode($arr["event_text"]));
if (empty($start)) {
$title = $event_text;
@@ -248,6 +249,7 @@ function extractDateTime($data, $property, $field) {
// Extract date-time values.
// Pull out the date and time values. Minimum year is 1970.
preg_match ('/([0-9]{4})([0-9]{2})([0-9]{2})T{0,1}([0-9]{0,2})([0-9]{0,2})/', $data, $regs);
+ if (!isset ($regs[1])) return;
if ($regs[1] < 1970) {
$regs[1] = '1971';
}
diff --git a/functions/ical_parser.php b/functions/ical_parser.php
index 0272da7..2791f65 100644
--- a/functions/ical_parser.php
+++ b/functions/ical_parser.php
@@ -480,8 +480,8 @@ $template_started = getmicrotime();
//If you want to see the values in the arrays, uncomment below.
#print '<pre>';
#var_dump($phpiCal_config);
-//print_r($master_array);
-//print_r($overlap_array);
+#print_r($master_array);
+#var_dump($overlap_array['20081211']);
//print_r($day_array);
//print_r($rrule_array);
//print_r($byday_arr);
diff --git a/functions/init/configs.php b/functions/init/configs.php
index 5d5a9c9..f94c47b 100644
--- a/functions/init/configs.php
+++ b/functions/init/configs.php
@@ -45,7 +45,7 @@ while ($fillTime < $phpiCal_config->day_end) {
$fill_h = $dTime[1];
$fill_min = $dTime[2];
$fill_min = sprintf('%02d', $fill_min + $phpiCal_config->gridLength);
- if ($fill_min == 60) {
+ if ($fill_min >= 60) {
$fill_h = sprintf('%02d', ($fill_h + 1));
$fill_min = '00';
}
diff --git a/functions/parse/end_vevent.php b/functions/parse/end_vevent.php
index e35160c..502d54c 100644
--- a/functions/parse/end_vevent.php
+++ b/functions/parse/end_vevent.php
@@ -13,13 +13,6 @@ What happens in this file:
if (!isset($start_date)) $start_date = "19700101";
-// Handle DURATION
-if (!isset($end_unixtime)) {
- if(!isset($the_duration)) $the_duration = 0;
- $end_unixtime = $start_unixtime + $the_duration;
- $end_time = date ('Hi', $end_unixtime);
-}
-
// CLASS support
if (isset($class)) {
if ($class == 'PRIVATE') {
@@ -29,7 +22,7 @@ if (isset($class)) {
$summary ='**CONFIDENTIAL**';
$description ='**CONFIDENTIAL**';
}
-}
+}
// make sure we have some value for $uid
if (!isset($uid)) {
@@ -44,44 +37,44 @@ if (!isset($uid)) {
}
$uid_list[] = $uid;
+# Handle DURATION
+if (!isset($end_unixtime)) {
+ if(!isset($the_duration)) $the_duration = 0;
+ $end_unixtime = $start_unixtime + $the_duration;
+ $end_time = date ('Hi', $end_unixtime);
+}
+# at this point $end_unixtime should be set
# adjust event start and end times
if (isset($start_time) && isset($end_time)) {
// Mozilla style all-day events or just really long events
- if (($end_time - $start_time) > 2345) {
+ if (($end_unixtime - $start_unixtime) > 24*60*60) {
$allday_start = $start_date;
$allday_end = ($start_date + 1);
}
}
-# disallow events with negative length
-if ($end_unixtime < $start_unixtime){
- $end_date = $start_date;
- $end_time = $start_time;
- $end_unixtime = $start_unixtime;
-}
# look for events that span more than one day
-if (isset($start_unixtime,$end_unixtime) && date('Ymd',$start_unixtime) != date('Ymd',$end_unixtime)) {
+if (isset($start_unixtime,$end_unixtime) && date('Ymd',$start_unixtime) < date('Ymd',$end_unixtime)) {
$spans_day = true;
- $bleed_check = (($start_unixtime - $end_unixtime) < (60*60*24)) ? '-1' : '0';
+ $bleed_check = (($start_unixtime - $end_unixtime) <= (60*60*24)) ? '-1' : '0';
} else {
$spans_day = false;
$bleed_check = 0;
}
-# get hour and minute adjusted to allowed grid times
-if (isset($start_time) && $start_time != '') {
- preg_match ('/([0-9]{2})([0-9]{2})/', $start_time, $time);
- preg_match ('/([0-9]{2})([0-9]{2})/', $end_time, $time2);
- 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);
- preg_match ('/([0-9]{2})([0-9]{2})/', $drawKey['draw_start'], $time3);
- $hour = $time3[1];
- $minute = $time3[2];
+$length = $end_unixtime - $start_unixtime;
+if ($length < 0){
+ $length = 0;
+ $end_time = $start_time;
}
+# get hour and minute adjusted to allowed grid times
+$drawKey = drawEventTimes($start_time, $end_time);
+preg_match ('/([0-9]{2})([0-9]{2})/', $drawKey['draw_start'], $time3);
+preg_match ('/([0-9]{2})([0-9]{2})/', $drawKey['draw_end'], $time4);
+$hour = $time3[1];
+$minute = $time3[2];
+$end_hour = $time4[1];
+$end_minute = $time4[2];
+
// RECURRENCE-ID Support
if (isset($recurrence_d)) {
@@ -89,16 +82,6 @@ if (isset($recurrence_d)) {
$recurrence_delete["$recurrence_d"]["$recurrence_t"] = $uid;
}
-
-# treat nonrepeating events as rrule events with one instance
-if (!isset($rrule_array) && $start_unixtime < $mArray_end && $end_unixtime > $mArray_begin){
- $rrule_array['FREQ'] = 'YEARLY';
- $rrule_array['START_DATE'] = $start_date;
- $rrule_array['UNTIL'] = $start_date;
-# $rrule_array['END'] = 'end';
-}
-
-
if (isset($allday_start) && $allday_start != '') {
$hour = '-';
$minute = '1';
@@ -140,9 +123,6 @@ foreach ($rrule_array as $key => $val) {
$recur_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = $count;
break;
case 'UNTIL':
- #$until = str_replace('T', '', $val);
- #$until = str_replace('Z', '', $until);
- #if (strlen($until) == 8) $until = $until.'235959';
# UNTIL must be in UTC
$until = date("YmdHis",strtotime($val));
ereg ('([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})', $until, $regs);
@@ -197,6 +177,8 @@ foreach ($rrule_array as $key => $val) {
break;
}
}
+if($current_view == 'search') $freq_type = 'none';
+
# $recur is the recurrence info that goes into the master array for this VEVENT
$recur = @$recur_array[($start_date)][($hour.$minute)][$uid]['recur'];
@@ -223,24 +205,17 @@ $end_range_unixtime = $mArray_end+60*60*24;
$start_date_unixtime = strtotime($start_date);
$next_range_unixtime = $start_date_unixtime;
-#conditions where we can not iterate over the whole range
-if($count == 1000000){
- if($interval == 1) {
- $next_range_unixtime = $mArray_begin;
- }else{
- # can we calculate the right start time?
- # pick the right compare function from date_functions.php
- # $diff is the number of occurrences between start_date and next_range_time
- # $func = $freq_type.'Compare';
- # $diff = $func(date('Ymd',strtotime($getdate)), $start_date);
- # $next_range_unixtime = strtotime('+'.$diff*$interval.' '.$freq_type, $start_date_unixtime); echo "<pre>$summary\nnext $freq_type $diff $freq_type".date("Ymd",$start_date_unixtime)."\n";
- }
-}
-// if the beginning of our range is less than the start of the item, we may as well set it equal to it
+# conditions where we don't need to iterate over the whole range
+# if repeating without limit, and steps are by 1, don't go back before the mArray beginning.
+if($count == 1000000 && $interval == 1 && $mArray_begin > $next_range_unixtime) $next_range_unixtime = $mArray_begin;
+
+# if the beginning of our range is less than the start of the item, we may as well set the range to start at start_time
if ($next_range_unixtime < $start_date_unixtime) $next_range_unixtime = $start_date_unixtime;
+# stop at the until limit if set
if(isset($until) && $end_range_unixtime > $until_unixtime) $end_range_unixtime = $until_unixtime;
+# more adjustments
switch ($freq_type){
case 'week':
# need to get the first value of $next_range_unixtime onto the right day of the week
@@ -250,6 +225,8 @@ switch ($freq_type){
$end_range_unixtime += 366*24*60*60;
break;
}
+
+#nonrepeating events can stop at the first instance
if(!isset($rrule_array['FREQ']) && isset($end_date)){
$end_range_unixtime = strtotime($end_date);
$count = 1;
@@ -262,7 +239,6 @@ one $next_range_time per repeat, but the BYXXX rules may write more than one eve
$next_date_time handles those instances within a $freq_type */
#echo "<pre>$summary\n\tstart mArray time:".date("Ymd his",$mArray_begin)."\n\tnext_range_unixtime:".date("Ymd his",$next_range_unixtime)."\n\tend range time ".date("Ymd his",$end_range_unixtime)."\n";
$recur_data = array();
-if($current_view == 'search') $freq_type = 'none';
while ($next_range_unixtime <= $end_range_unixtime && $count > 0) {
$year = date("Y", $next_range_unixtime);
$month = date('m', $next_range_unixtime);
@@ -298,8 +274,17 @@ while ($next_range_unixtime <= $end_range_unixtime && $count > 0) {
} #end while loop
sort($recur_data);
-/* ============================ Use $recur_data array to write the master array ============================*/
-// This used to use 5 different blocks to write the array... can it be reduced further?
+/* ============================ Use $recur_data array to write the master array ============================
+// This used to use 5 different blocks to write the array... can it be reduced further?
+
+For each recurrence date, an event may still cross day boundaries. So we need to loop from the start_date for that recurrence to the end of that recurrence.
+To generate $recur_data we mostly only paid attention to start times.
+
+Now, a single event must be split into multiple master array values for each day on which it occurs
+
+$hour and $minute are the values from the start_time, rounded to the nearest grid time.
+
+*/
$recur_data_hour = @substr($start_time,0,2);
$recur_data_minute = @substr($start_time,2,2);
if (isset($allday_start) && $allday_start != ''){
@@ -307,114 +292,59 @@ if (isset($allday_start) && $allday_start != ''){
$recur_data_minute = '00';
}
foreach($recur_data as $recur_data_unixtime) {
- $recur_data_year = date('Y', $recur_data_unixtime);
- $recur_data_month = date('m', $recur_data_unixtime);
- $recur_data_day = date('d', $recur_data_unixtime);
- $recur_data_date = $recur_data_year.$recur_data_month.$recur_data_day;
-
- /* at this point the recur data year, month, day, hour, and minute are in the default timezone for the phpicalendar installation, if that is set. We need to compare whether both the event timezone and the the phpicaledar timezone are in the same state wrt std vs daylight time. */
+ $recur_data_year = date('Y', $recur_data_unixtime);
+ $recur_data_month = date('m', $recur_data_unixtime);
+ $recur_data_day = date('d', $recur_data_unixtime);
+ $recur_data_date = $recur_data_year.$recur_data_month.$recur_data_day;
+
+ # initialize the loop range to the recur date + grid time
+ $next_range_unixtime = mktime($recur_data_hour,$recur_data_minute,0,$recur_data_month,$recur_data_day,$recur_data_year);
+ $end_range_unixtime = $next_range_unixtime + $length;
+ $end_date_tmp = date("Ymd",$end_range_unixtime);
+ #echo "<pre>$summary ".date("Ymd H:i:s",$next_range_unixtime)." ".date("Ymd H:i:s",$end_range_unixtime)."\n";
- if (isset($allday_start) && $allday_start != '') {
- $start_time2 = $recur_data_unixtime;
- $end_time2 = strtotime('+'.$diff_allday_days.' days', $recur_data_unixtime);
- while ($start_time2 < $end_time2) {
- $start_date2 = date('Ymd', $start_time2);
- $master_array[($start_date2)][('-1')][$uid] = array (
- 'event_text' => $summary,
- 'description' => $description,
- 'location' => $location,
- 'organizer' => serialize($organizer),
- 'attendee' => serialize($attendee),
- 'calnumber' => $calnumber,
- 'calname' => $actual_calname,
- 'url' => $url,
- 'status' => $status,
- 'class' => $class,
- 'recur' => $recur );
- $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;
- if (($end_time >= $phpiCal_config->bleed_time) && ($bleed_check == '-1')) {
- $start_tmp = strtotime(date('Ymd',$start_unixtime_tmp));
- $end_date_tmp = date('Ymd',$end_unixtime_tmp);
- while ($start_tmp < $end_unixtime_tmp) {
- $start_date_tmp = date('Ymd',$start_tmp);
- if ($start_date_tmp == $recur_data_year.$recur_data_month.$recur_data_day) {
- $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';
- $display_end_tmp = $end_time;
- }
- $master_array[$start_date_tmp][$time_tmp][$uid] = array (
- 'event_start' => $start_time_tmp,
- 'event_end' => $end_time_tmp,
- 'start_unixtime' => $start_unixtime_tmp,
- 'end_unixtime' => $end_unixtime_tmp,
- 'event_text' => $summary, #
- 'event_length' => $length,
- 'event_overlap' => 0,
- 'description' => $description,
- 'status' => $status,
- 'class' => $class,
- 'spans_day' => true,
- 'location' => $location,
- 'organizer' => serialize($organizer),
- 'attendee' => serialize($attendee),
- 'calnumber' => $calnumber,
- 'calname' => $actual_calname,
- 'url' => $url,
- 'recur' => $recur);
- if (isset($display_end_tmp)){
- $master_array[$start_date_tmp][$time_tmp][$uid]['display_end'] = $display_end_tmp;
- }
- checkOverlap($start_date_tmp, $time_tmp, $uid);
- $start_tmp = strtotime('+1 day',$start_tmp);
- }
- } else {
- if ($bleed_check == '-1') {
- $display_end_tmp = $end_time;
- $end_time_tmp1 = '2400';
-
- }
- if (!isset($end_time_tmp1)) $end_time_tmp1 = $end_time;
- $master_array[($recur_data_date)][($hour.$minute)][$uid] = array (
- 'event_start' => $start_time,
- 'event_end' => $end_time_tmp1,
- 'start_unixtime' => $start_unixtime_tmp,
- 'end_unixtime' => $end_unixtime_tmp,
- 'event_text' => $summary,
- 'event_length' => $length,
- 'event_overlap' => 0,
- 'description' => $description,
- 'status' => $status,
- 'class' => $class,
- 'spans_day' => false,
- 'location' => $location,
- 'organizer' => serialize($organizer),
- 'attendee' => serialize($attendee),
- 'calnumber' => $calnumber,
- 'calname' => $actual_calname,
- 'url' => $url,
- 'recur' => $recur);
- if (isset($display_end_tmp)){
- $master_array[($recur_data_date)][($hour.$minute)][$uid]['display_end'] = $display_end_tmp;
- }
- checkOverlap($recur_data_date, ($hour.$minute), $uid);
-
+ # default the time_key to -1 for allday events, overwrite as needed
+ $time_key = -1;
+
+ $start_unixtime_tmp = strtotime($recur_data_date.$start_time);
+ $end_unixtime_tmp = strtotime($end_date_tmp.$end_time);
+ while (date("Ymd", $next_range_unixtime) <= $end_date_tmp) {
+ $this_date_tmp = date('Ymd',$next_range_unixtime);
+ $next_range_unixtime = strtotime('+1 day',$next_range_unixtime);
+
+ if (!isset($allday_start) || $allday_start == '') $time_key = $hour.$minute;
+ $display_end_tmp = $end_hour.$end_minute;
+ if($time_key > -1){
+ # the day is not the first day of the recurrence
+ if ($this_date_tmp > $recur_data_date) $time_key = '0000';
+ # the day is not the last day of the recurrence
+ if ($this_date_tmp < $end_date_tmp) $display_end_tmp = '2400';
}
+ if($this_date_tmp == $end_date_tmp && $end_time == '0000') continue;
+ $master_array[$this_date_tmp][$time_key][$uid] = array (
+ 'event_start' => $start_time, # hhmm
+ 'event_end' => $end_time, # hhmm
+ 'display_end' => $display_end_tmp, # hhmm display_start is $time_key
+ 'start_unixtime' => $start_unixtime_tmp, # start unixtime for this recurrence
+ 'end_unixtime' => $end_unixtime_tmp, # end unixtime for this recurrence
+ 'event_text' => $summary, #
+ 'event_length' => $length, # length in seconds
+ 'event_overlap' => 0, # checkOverlap modifies this
+ 'description' => $description,
+ 'status' => $status,
+ 'class' => $class,
+ 'spans_day' => $spans_day,
+ 'location' => $location,
+ 'organizer' => serialize($organizer),
+ 'attendee' => serialize($attendee),
+ 'calnumber' => $calnumber,
+ 'calname' => $actual_calname,
+ 'url' => $url,
+ 'recur' => $recur
+ );
+ checkOverlap($this_date_tmp, $time_key, $uid);
}
-
-}
-
+} # end foreach recur_data
unset($recur_data);
diff --git a/functions/parse/overlapping_events.php b/functions/parse/overlapping_events.php
index 224f79b..cca0ce5 100644
--- a/functions/parse/overlapping_events.php
+++ b/functions/parse/overlapping_events.php
@@ -109,14 +109,6 @@ function flatten_ol_blocks($event_date, $ol_blocks, $new_block_key) {
}
// Builds $overlap_array structure, and updates event_overlap in $master_array for the given events.
-function checkOverlap($event_date, $event_time, $uid) {
- global $master_array, $overlap_array;
- if (!isset($event_date)) return;
- $event = $master_array[$event_date][$event_time][$uid];
- // Copy out the array - we replace this at the end.
- $ol_day_array = @$overlap_array[$event_date];
- $drawTimes = drawEventTimes($event['event_start'], $event['event_end']);
-
// For a given date,
// - check to see if the event's already in a block, and if so, add it.
// - make sure the new block doesn't overlap another block, and if so, merge the blocks.
@@ -140,8 +132,16 @@ function checkOverlap($event_date, $event_time, $uid) {
// 'count' - number of overlaps that time range (can be zero if that range has no overlaps).
// 'start' - start_time for the overlap block.
// 'end' - end_time for the overlap block.
-
+function checkOverlap($event_date, $event_time, $uid) {
+ global $master_array, $overlap_array;
+ if (!isset($event_date)) return;
+ $event = $master_array[$event_date][$event_time][$uid];
+ // Copy out the array - we replace this at the end.
$ol_day_array = @$overlap_array[$event_date];
+ $draw_end = $event['event_end'];
+ if (isset($event['display_end'])) $draw_end = $event['display_end'];
+ $drawTimes = drawEventTimes($event['event_start'], $draw_end);
+
// Track if $event has been merged in, so we don't re-add the details to 'event' or 'overlapRanges' multiple times.
$already_merged_once = false;
// First, check the existing overlap blocks, see if the event overlaps with any.
@@ -180,7 +180,7 @@ function checkOverlap($event_date, $event_time, $uid) {
foreach ($time as $loop_event_key => $loop_event) {
// Make sure we haven't already dealt with the event, and we're not checking against ourself.
if ($loop_event['event_overlap'] == 0 && $loop_event_key != $uid) {
- $loopDrawTimes = drawEventTimes($loop_event['event_start'], $loop_event['event_end']);
+ $loopDrawTimes = drawEventTimes($loop_event['event_start'], $loop_event['display_end']);
if ($loopDrawTimes['draw_start'] < $drawTimes['draw_end'] && $loopDrawTimes['draw_end'] > $drawTimes['draw_start']) {
if ($loopDrawTimes['draw_start'] < $drawTimes['draw_start']) {
$block_start = $loopDrawTimes['draw_start'];
diff --git a/functions/parse/recur_functions.php b/functions/parse/recur_functions.php
index 0526e1d..7a4af96 100644
--- a/functions/parse/recur_functions.php
+++ b/functions/parse/recur_functions.php
@@ -251,4 +251,4 @@ function dump_times($times){
#var_dump($times);
foreach($times as $time) echo "\ndate:".date("Y-m-d H:i:s",$time);
echo "</pre>";
-}
+} \ No newline at end of file
diff --git a/functions/template.php b/functions/template.php
index 8656f5a..969e7e7 100644
--- a/functions/template.php
+++ b/functions/template.php
@@ -250,7 +250,6 @@ class Page {
global $phpiCal_config, $start_week_time, $getdate, $cal, $master_array, $dateFormat_week_list, $current_view, $day_array, $timeFormat, $timeFormat_small;
// Figure out colspans and initialize weekarray
- $dayborder = 0;
$thisdate = $start_week_time;
$swt = $start_week_time;
for ($i=0;$i < $phpiCal_config->week_length;$i++) {
@@ -267,9 +266,10 @@ class Page {
}
}
$weekarray[$i] = $thisday;
+ $event_length[$thisday] = array ();
$thisdate = ($thisdate + (25 * 60 * 60));
}
- #echo "<pre>";print_r($nbrGridCols);
+
// Replaces the allday events
preg_match("!<\!-- loop allday on -->(.*)<\!-- loop allday off -->!Uis", $this->page, $match1);
preg_match("!<\!-- loop alldaysofweek on -->(.*)<\!-- loop allday on -->!Uis", $this->page, $match2);
@@ -301,27 +301,19 @@ class Page {
preg_match("!<\!-- loop daysofweek on -->(.*)<\!-- loop daysofweek off -->!Uis", $this->page, $match1);
$loop_dof = trim($match1[1]);
$start_wt = strtotime(dateOfWeek($getdate, $phpiCal_config->week_start_day));
- $start_day = strtotime($phpiCal_config->week_start_day);
$weekday_loop = '';
for ($i=0; $i<$phpiCal_config->week_length; $i++) {
- $day_num = date("w", $start_day);
$daylink = date('Ymd', $start_wt);
- if ($current_view == 'day') {
- $weekday = $daysofweek_lang[$day_num];
- } else {
- $weekday = localizeDate($dateFormat_week_list, strtotime($daylink));
- }
-
+ $weekday = localizeDate($dateFormat_week_list, strtotime($daylink));
if ($daylink == $getdate) {
$row1 = 'rowToday';
$row2 = 'rowOn';
$row3 = 'rowToday';
- } else {
+ }else{
$row1 = 'rowOff';
$row2 = 'rowOn';
$row3 = 'rowOff';
}
- $start_day = strtotime("+1 day", $start_day);
$start_wt = strtotime("+1 day", $start_wt);
$colspan = 'colspan="'.$nbrGridCols[$daylink].'"';
$search = array('{DAY}', '{DAYLINK}', '{ROW1}', '{ROW2}', '{ROW3}', '{COLSPAN}');
@@ -344,12 +336,10 @@ class Page {
$this_month = $day_array2[2];
$this_year = $day_array2[1];
$thisdate = $swt;
- for ($i=0; $i < 7; $i++) {
- $thisday = date("Ymd", $thisdate);
- $event_length[$thisday] = array ();
- $thisdate = ($thisdate + (25 * 60 * 60));
- }
+
$weekdisplay = '';
+
+ #day_array is an array of time blocks of length $phpiCal_config->gridLength
foreach ($day_array as $key) {
$cal_time = $key;
preg_match('/([0-9]{2})([0-9]{2})/', $key, $regs_tmp);
@@ -371,78 +361,64 @@ class Page {
$weekdisplay .= '<tr>';
$weekdisplay .= '<td bgcolor="#a1a5a9" width="1" height="' . $phpiCal_config->gridLength . '"></td>';
}
-
- // initialize $thisdate again
- $thisdate = $swt;
-
- // loop this part 7 times, one for each day
- for ($week_loop=0; $week_loop<$phpiCal_config->week_length; $week_loop++) {
- $thisday = date("Ymd", $thisdate);
- $dayborder = 0;
- unset($this_time_arr);
-
+
+ /* add columns in the $cal_time grid slot for each day
+ each cell will have $this_time_arr of events */
+ foreach ($weekarray as $thisday) {
+ $this_time_arr = array();
+ $dayborder = 0;
if ($phpiCal_config->day_start == $cal_time && isset($master_array[$thisday]) && is_array($master_array[$thisday])) {
+ # want to pile up all the events before day_start that end in the displayed times
foreach($master_array[$thisday] as $time_key => $time_arr) {
- if ((int)$time_key <= (int)$cal_time) {
- if (is_array($time_arr) && $time_key != '-1') {
- foreach($time_arr as $uid => $event_tmp) {
- if ((int)$event_tmp['event_end'] > (int)$cal_time) {
- $this_time_arr[$uid] = $event_tmp;
- }
- }
- }
- } else {
- break;
+ if ((int)$time_key <= (int)$cal_time && is_array($time_arr) && $time_key != '-1') {
+ foreach($time_arr as $uid => $event_tmp) {
+ if ((int)$event_tmp['display_end'] > (int)$cal_time) $this_time_arr[$uid] = $event_tmp;
+ }
}
}
} else {
+ # events that start in internal cal_times the grid
if (isset($master_array[$thisday][$cal_time]) && sizeof($master_array[$thisday][$cal_time]) > 0) {
- $this_time_arr = $master_array[$thisday][$cal_time];
+ $this_time_arr = $master_array[$thisday][$cal_time];
}
}
-
- // check for eventstart
- if (isset($this_time_arr) && sizeof($this_time_arr) > 0) {
- #print "<pre>";print_r ($this_time_arr);print "</pre>";
- foreach ($this_time_arr as $eventKey => $loopevent) {
- $drawEvent = drawEventTimes ($cal_time, $loopevent["event_end"]);
- $j = 0;
- while (isset($event_length[$thisday][$j])) {
- if ($event_length[$thisday][$j]["state"] == "ended") {
- $event_length[$thisday][$j] = array ("length" => ($drawEvent["draw_length"] / $phpiCal_config->gridLength), "key" => $eventKey, "overlap" => $loopevent["event_overlap"],"state" => "begin");
- break;
- }
- $j++;
- }
- if ($j == sizeof($event_length[$thisday])) {
- array_push ($event_length[$thisday], array ("length" => ($drawEvent["draw_length"] / $phpiCal_config->gridLength), "key" => $eventKey, "overlap" => $loopevent["event_overlap"],"state" => "begin"));
+ // go through $this_time_array and fill the event_length array
+ foreach ($this_time_arr as $eventKey => $loopevent) {
+ $drawEvent = drawEventTimes ($cal_time, $loopevent["display_end"]);
+ $j = 0;
+ while (isset($event_length[$thisday][$j])) {
+ if ($event_length[$thisday][$j]["state"] == "ended") {
+ $event_length[$thisday][$j] = array ("length" => ($drawEvent["draw_length"] / $phpiCal_config->gridLength), "key" => $eventKey, "overlap" => $loopevent["event_overlap"],"state" => "begin");
+ break;
}
+ $j++;
+ }
+ if ($j == sizeof(@$event_length[$thisday])) {
+ $event_length[$thisday][] = array ("length" => ($drawEvent["draw_length"] / $phpiCal_config->gridLength), "key" => $eventKey, "overlap" => $loopevent["event_overlap"],"state" => "begin");
}
}
-
- if (sizeof($event_length[$thisday]) == 0) {
+ if (empty($event_length[$thisday])) {
+ # no events
if ($dayborder == 0) {
$class = ' class="weekborder"';
$dayborder++;
} else {
$class = '';
$dayborder = 0;
- }
-
+ }
$drawWidth = 1;
$colspan_width = round((80 / $nbrGridCols[$thisday]) * $drawWidth);
- $weekdisplay .= '<td width="' . $colspan_width . '" colspan="' . $nbrGridCols[$thisday] . '" ' . $class . '>&nbsp;</td>'."\n";
-
+ $weekdisplay .= '<td width="' . $colspan_width . '" colspan="' . $nbrGridCols[$thisday] . '" ' . $class . '>&nbsp;</td>'."\n";
} else {
+ # have events
$emptyWidth = $nbrGridCols[$thisday];
// Used to "join" ended events, so the ended case below results in one colspan'd td instead of multiple tds.
$ended_counter = 0;
- for ($i=0;$i<sizeof($event_length[$thisday]);$i++) {
-
- $drawWidth = $nbrGridCols[$thisday] / ($event_length[$thisday][$i]["overlap"] + 1);
+ foreach($event_length[$thisday] as $i=>$el) {
+ $drawWidth = $nbrGridCols[$thisday] / ($el["overlap"] + 1);
$emptyWidth = $emptyWidth - $drawWidth;
- switch ($event_length[$thisday][$i]["state"]) {
+ switch ($el["state"]) {
case "begin":
if ($ended_counter) {
$weekdisplay .= '<td colspan="' . $ended_counter . '" '.$class.'>&nbsp;</td>';
@@ -502,7 +478,6 @@ class Page {
array_pop($event_length[$thisday]);
}
}
- $thisdate = ($thisdate + (25 * 60 * 60));
}
$weekdisplay .= "</tr>\n";
}
@@ -860,6 +835,8 @@ class Page {
function draw_month($template_p, $offset = '+0', $type) {
global $phpiCal_config, $getdate, $master_array, $this_year, $this_month, $dateFormat_month, $cal, $minical_view, $month_event_lines, $daysofweekreallyshort_lang, $daysofweekshort_lang, $daysofweek_lang, $timeFormat_small, $timeFormat;
+
+ $unique_colors = $phpiCal_config->unique_colors;
preg_match("!<\!-- loop weekday on -->(.*)<\!-- loop weekday off -->!Uis", $template_p, $match1);
preg_match("!<\!-- loop monthdays on -->(.*)<\!-- loop monthdays off -->!Uis", $template_p, $match2);
preg_match("!<\!-- switch notthismonth on -->(.*)<\!-- switch notthismonth off -->!Uis", $template_p, $match3);
@@ -938,8 +915,8 @@ class Page {
foreach ($master_array[$daylink] as $cal_time => $event_times) {
foreach ($event_times as $uid => $val) {
$event_calno = $val['calnumber'];
- $event_calno = (($event_calno - 1) % $phpiCal_config->unique_colors) + 1;
- if (!isset($val['event_start'])) {
+ $event_calno = (($event_calno - 1) % $unique_colors) + 1;
+ if ($cal_time == -1) {
if ($type == 'large') {
$switch['ALLDAY'] .= '<div class="V10"><img src="templates/'.$phpiCal_config->template.'/images/monthdot_'.$event_calno.'.gif" alt="" width="9" height="9" border="0" />';
$switch['ALLDAY'] .= openevent($daylink, $cal_time, $uid, $val, $month_event_lines, 15, 'psf');

© 2014-2024 Faster IT GmbH | imprint | privacy policy