Skip to content

Commit 50ce9c8

Browse files
author
Jim Hu
committed
change handling of multiday allday events in week view; other misc changes
1 parent cb7df85 commit 50ce9c8

12 files changed

+165
-64
lines changed

calendars/US Holidays.ics

+1-1
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ DTSTAMP:20061010T210116Z
660660
SUMMARY:Daylight Saving Time Ends (-1 hour)
661661
CREATED:20081223T190054Z
662662
DTEND;VALUE=DATE:20021028
663-
RRULE:FREQ=YEARLY;INTERVAL=1;UNTIL=20071027;BYMONTH=10;BYDAY=-1SU
663+
RRULE:FREQ=YEARLY;INTERVAL=1;UNTIL=20071027T0000Z;BYMONTH=10;BYDAY=-1SU
664664
END:VEVENT
665665
BEGIN:VEVENT
666666
SEQUENCE:4

calendars/test.ics

+23
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ END:VEVENT
6666

6767
BEGIN:VEVENT
6868
SEQUENCE:7
69+
UID:starts on 12
6970
DTSTAMP:20020918T224617Z
7071
SUMMARY:5 days
7172
STATUS:CONFIRMED
@@ -74,4 +75,26 @@ DTSTART;TZID=US/Eastern:20081212
7475
URL:http://google.com
7576
END:VEVENT
7677

78+
BEGIN:VEVENT
79+
SEQUENCE:7
80+
UID:starts on 10
81+
DTSTAMP:20020918T224617Z
82+
SUMMARY:5 days b4
83+
STATUS:CONFIRMED
84+
DURATION:P4DT48H
85+
DTSTART;TZID=US/Eastern:20081210
86+
URL:http://google.com
87+
END:VEVENT
88+
89+
BEGIN:VEVENT
90+
SEQUENCE:7
91+
UID:starts on 07
92+
DTSTAMP:20020918T224617Z
93+
SUMMARY:5 days 07
94+
STATUS:CONFIRMED
95+
DURATION:P3D
96+
DTSTART;TZID=US/Eastern:20081207
97+
URL:http://google.com
98+
END:VEVENT
99+
77100
END:VCALENDAR

default_config.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private function __construct(){
2222
$this->day_end = '2000'; // End time for day grid
2323
$this->gridLength = '15'; // Grid distance in minutes for day view, multiples of 15 preferred
2424
$this->num_years = '1'; // Number of years (up and back) to display in 'Jump to'
25-
$this->month_event_lines = '1'; // Number of lines to wrap each event title in month view, 0 means display all lines.
25+
$this->month_event_lines = '0'; // Number of lines to wrap each event title in month view, 0 means display all lines.
2626
$this->tomorrows_events_lines = '1'; // Number of lines to wrap each event title in the 'Tommorrow's events' box, 0 means display all lines.
2727
$this->allday_week_lines = '1'; // Number of lines to wrap each event title in all-day events in week view, 0 means display all lines.
2828
$this->week_events_lines = '1'; // Number of lines to wrap each event title in the 'Tommorrow's events' box, 0 means display all lines.

error.php

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ function error($error_msg='There was an error processing the request.', $file='N
4444
'rss_valid' => '',
4545
'error_msg' => $error_msg,
4646
'error_calendar' => $error_calendar,
47-
'generated' => $generated,
4847
'l_powered_by' => $lang['l_powered_by'],
4948
'l_error_back' => $lang['l_error_back'],
5049
'l_error_window' => $lang['l_error_window'],

functions/date_functions.php

+27-10
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,33 @@ function chooseOffset($time, $timezone = '') {
153153
}
154154
return $offset;
155155
}
156-
156+
/* Returns a string to make event text with a link to popup boxes
157+
$arr is a master array item
158+
$lines is the number of lines to restrict the event_text to, using word_wrap
159+
$length is the length of one line
160+
$link_class is a css class
161+
$pre_text and $post_text are to add tags around the link text (e.g. <b> or<i>)
162+
163+
$title is the tooltip for the link
164+
*/
157165
function openevent($event_date, $time, $uid, $arr, $lines = 0, $length = 0, $link_class = '', $pre_text = '', $post_text = '') {
158-
global $cpath, $master_array;
166+
global $cpath, $timeFormat, $dateFormat_week;
159167
$return = '';
160168
$event_text = stripslashes(urldecode($arr["event_text"]));
161-
if (empty($start)) {
169+
# build tooltip
170+
if ($time == -1) {
171+
$start = localizeDate($dateFormat_week, $arr['start_unixtime']);
172+
$end = localizeDate($dateFormat_week, ($arr['end_unixtime'] - 60));
162173
$title = $event_text;
174+
if ($start != $end) $title = "$start - $end $event_text";
163175
} else {
164-
$title = $arr['event_start'].' - '.$arr['event_end'].': '.$event_text;
176+
$start = date($timeFormat, $arr['start_unixtime']);
177+
$end = date($timeFormat, $arr['end_unixtime']);
178+
$title = "$start: $event_text";
179+
if ($start != $end) $title = "$start - $end $event_text";
165180
}
181+
$title .= "\n".urldecode($arr['description'])."\n".urldecode($arr['location']);
182+
$title = trim($title);
166183
# for iCal pseudo tag <http> comptability
167184
if (ereg("<([[:alpha:]]+://)([^<>[:space:]]+)>",$event_text,$matches)) {
168185
$full_event_text = $matches[1] . $matches[2];
@@ -181,14 +198,14 @@ function openevent($event_date, $time, $uid, $arr, $lines = 0, $length = 0, $lin
181198
$escaped_date = addslashes($event_date);
182199
$escaped_time = addslashes($time);
183200
$escaped_uid = addslashes($uid);
184-
$event_data = addslashes(serialize ($master_array[$event_date][$time][$uid]));
201+
$event_data = addslashes(serialize ($arr));
185202
// fix for URL-length bug in IE: populate and submit a hidden form on click
186203
static $popup_data_index = 0;
187-
$return = "
188-
<script language=\"Javascript\" type=\"text/javascript\"><!--
189-
var eventData = new EventData('$escaped_date', '$escaped_time', '$escaped_uid','$cpath','$event_data');
190-
document.popup_data[$popup_data_index] = eventData;
191-
// --></script>";
204+
$return = "
205+
<script language='Javascript' type='text/javascript'><!--
206+
var eventData = new EventData('$escaped_date', '$escaped_time', '$escaped_uid','$cpath','$event_data');
207+
document.popup_data[$popup_data_index] = eventData;
208+
// --></script>";
192209

193210
$return .= '<a class="'.$link_class.'" title="'.$title.'" href="#" onclick="openEventWindow('.$popup_data_index.'); return false;">';
194211
$popup_data_index++;

functions/list_functions.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ function list_years() {
7676

7777

7878
function list_weeks() {
79-
global $getdate, $this_year, $cal, $dateFormat_week_jump, $week_start_day;
79+
global $getdate, $this_year, $cal, $dateFormat_week_jump, $phpiCal_config;
8080
ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $getdate, $day_array2);
8181
$this_day = $day_array2[3];
8282
$this_month = $day_array2[2];
8383
$this_year = $day_array2[1];
8484
$check_week = strtotime($getdate);
85-
$start_week_time = strtotime(dateOfWeek(date("Ymd", strtotime("$this_year-01-01")), $week_start_day));
85+
$start_week_time = strtotime(dateOfWeek(date("Ymd", strtotime("$this_year-01-01")), $phpiCal_config->week_start_day));
8686
$end_week_time = $start_week_time + (6 * 25 * 60 * 60);
8787
$return = '';
8888

functions/parse/end_vevent.php

+10-9
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@
124124
break;
125125
case 'UNTIL':
126126
# UNTIL must be in UTC
127-
$until = date("YmdHis",strtotime($val));
127+
$until = date("YmdHis",strtotime($val));
128128
ereg ('([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})', $until, $regs);
129-
$until_unixtime = mktime($regs[4],$regs[5],@$regs[6],$regs[2],$regs[3],$regs[1]);
129+
$until_unixtime = mktime($regs[4],@$regs[5],@$regs[6],$regs[2],$regs[3],$regs[1]);
130130
$recur_array[($start_date)][($hour.$minute)][$uid]['recur'][$key] = localizeDate($dateFormat_week,$until);
131131
break;
132132
case 'INTERVAL':
@@ -181,7 +181,8 @@
181181
$wkst3char = two2threeCharDays($wkst);
182182
if($current_view == 'search') $freq_type = 'none';
183183
# $recur is the recurrence info that goes into the master array for this VEVENT
184-
$recur = @$recur_array[($start_date)][($hour.$minute)][$uid]['recur'];
184+
$recur ='';
185+
if (isset($recur_array[($start_date)][($hour.$minute)][$uid]['recur'])) $recur = $recur_array[($start_date)][($hour.$minute)][$uid]['recur'];
185186

186187
/* ============================ Load $recur_data ============================
187188
$recur_data is an array of unix times for days of recurrences of an event. This code handles repeats at the day level or above. The next loop handles the times.
@@ -214,7 +215,7 @@
214215
if ($next_range_unixtime < $start_date_unixtime) $next_range_unixtime = $start_date_unixtime;
215216

216217
# stop at the until limit if set
217-
if(isset($until) && $end_range_unixtime > $until_unixtime) $end_range_unixtime = $until_unixtime;
218+
if(isset($until) && $end_range_unixtime > $until_unixtime) $end_range_unixtime = $until_unixtime;else $until_unixtime = $mArray_end;
218219

219220
# more adjustments
220221
switch ($freq_type){
@@ -257,10 +258,10 @@
257258
}
258259
break;
259260
case 'year':
260-
$times = expand_bymonth($time); #echo "exp bymonth";dump_times($times);
261-
$times = expand_byweekno($times); #echo "exp byweekno";dump_times($times);
262-
$times = expand_byyearday($times); #echo "exp byyearday";dump_times($times);
263-
$times = expand_bymonthday($times); #echo "\nexp bymonthday";dump_times($times);
261+
$times = expand_bymonth($time); #echo "exp bymonth";dump_times($times);
262+
$times = expand_byweekno($times); #echo "exp byweekno";dump_times($times);
263+
$times = expand_byyearday($times); #echo "exp byyearday";dump_times($times);
264+
$times = expand_bymonthday($times); #echo "\nexp bymonthday";dump_times($times);
264265
foreach($times as $time){
265266
add_recur(expand_byday($time));
266267
}
@@ -319,7 +320,7 @@
319320
# the day is not the last day of the recurrence
320321
if ($this_date_tmp < $end_date_tmp) $display_end_tmp = '2400';
321322
}
322-
if($this_date_tmp == $end_date_tmp && ($end_time == '0000' ||$time_key == -1)) continue;
323+
if($this_date_tmp == $end_date_tmp && ($end_time == '0000' && $time_key == -1)) continue;
323324
$master_array[$this_date_tmp][$time_key][$uid] = array (
324325
'event_start' => $start_time, # hhmm
325326
'event_end' => $end_time, # hhmm

functions/parse/recur_functions.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
function add_recur($times,$freq=''){
1212
global $recur_data;
13-
global $count, $mArray_begin, $mArray_end, $except_dates, $start_date, $start_date_unixtime,$end_range_unixtime, $day_offset, $current_view;
13+
global $count, $mArray_begin, $mArray_end, $except_dates, $start_date, $start_date_unixtime,$end_range_unixtime,$until_unixtime, $day_offset, $current_view;
1414
if (!is_array($times)) $times = array($times);
1515
/* BYMONTH, BYWEEKNO, BYYEARDAY, BYMONTHDAY, BYDAY, BYHOUR, BYMINUTE, BYSECOND and BYSETPOS */
1616
#dump_times($times);
@@ -27,7 +27,7 @@ function add_recur($times,$freq=''){
2727
}
2828
$until_date = date("Ymd",$end_range_unixtime);
2929
foreach ($times as $time){
30-
#echo "time:". date("Ymd",$time)."\n";
30+
#echo "time:". date("Ymd",$time)." $until_date<br>\n";
3131
if (!isset($time) || $time == '') continue;
3232
$date = date("Ymd",$time);
3333
$time = strtotime("$date 12:00:00");
@@ -38,6 +38,7 @@ function add_recur($times,$freq=''){
3838
&& $time != ''
3939
&& !in_array($time, $recur_data)
4040
&& !in_array($date, $except_dates)
41+
&& $time <= $until_unixtime
4142
&& $time >= $start_date_unixtime
4243
&& $date <= $until_date
4344
){

functions/template.php

+70-16
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ function draw_print($template_p) {
6565

6666
$seen_events = array();
6767
$final = '';
68+
$events_week = 0;
6869
foreach($master_array as $key => $val) {
6970
preg_match ('/([0-9]{6})([0-9]{2})/', $key, $regs);
7071
if (((@$regs[1] == $parse_month) && ($printview == 'month')) || (($key == $getdate) && ($printview == 'day')) || ((($key >= $week_start) && ($key <= $week_end)) && ($printview == 'week')) || ((substr(@$regs[1],0,4) == $parse_year) && ($printview == 'year'))) {
71-
@$events_week++;
72+
$events_week++;
7273
$dayofmonth = strtotime ($key);
7374
$dayofmonth = localizeDate ($dateFormat_day, $dayofmonth);
7475
$events_tmp = $loop_event;
@@ -86,10 +87,10 @@ function draw_print($template_p) {
8687
$day_events++;
8788
if (isset($new_val2['event_text'])) {
8889
$event_text = stripslashes(urldecode($new_val2['event_text']));
89-
$location = stripslashes(urldecode(@$new_val2['location']));
90-
$description = stripslashes(urldecode(@$new_val2['description']));
91-
$event_start = @$new_val2['event_start'];
92-
$event_end = @$new_val2['event_end'];
90+
$location = stripslashes(urldecode($new_val2['location']));
91+
$description = stripslashes(urldecode($new_val2['description']));
92+
$event_start = $new_val2['event_start'];
93+
$event_end = $new_val2['event_end'];
9394
if (isset($new_val2['display_end'])) $event_end = $new_val2['display_end'];
9495
if (!isset($new_val2['event_start'])) {
9596
$event_start = $lang['l_all_day'];
@@ -271,22 +272,73 @@ function draw_week($template_p) {
271272
}
272273
#echo "<pre>";print_r($nbrGridCols);
273274
// Replaces the allday events
275+
preg_match("!<\!-- loop allday row on -->(.*)<\!-- loop alldaysofweek on -->!Uis", $this->page, $match1);
276+
$loop_row_begin = trim($match1[1]); # <tr>etc
274277
preg_match("!<\!-- loop allday on -->(.*)<\!-- loop allday off -->!Uis", $this->page, $match1);
275278
preg_match("!<\!-- loop alldaysofweek on -->(.*)<\!-- loop allday on -->!Uis", $this->page, $match2);
276279
preg_match("!<\!-- loop allday off -->(.*)<\!-- loop alldaysofweek off -->!Uis", $this->page, $match3);
277-
$loop_ad = trim($match1[1]);
278-
$loop_begin = trim($match2[1]);
279-
$loop_end = trim($match3[1]);
280+
$loop_ad = trim($match1[1]); # one day cell
281+
$loop_begin = trim($match2[1]); # <td>
282+
$loop_end = trim($match3[1]); # </td>
283+
preg_match("!<\!-- loop alldaysofweek off -->(.*)<\!-- loop allday row off -->!Uis", $this->page, $match3);
284+
$loop_row_end = trim($match3[1]); # </tr>
285+
$allday_uids = array();
286+
$allday_uid_dates = array();
280287
$weekreplace = '';
281-
foreach ($weekarray as $get_date) {
288+
foreach ($weekarray as $i=>$get_date){
289+
if (isset($master_array[$get_date]['-1']) && is_array($master_array[$get_date]['-1']) && !empty($master_array[$get_date]['-1'])){
290+
foreach ($master_array[$get_date]['-1'] as $uid => $allday){
291+
if (!array_key_exists($uid, $allday_uids)) $allday_uids[$uid] = $get_date;
292+
$allday_uid_dates[$uid][] = $get_date;
293+
}
294+
}
295+
}
296+
# new allday routine is better for multiday events
297+
while(!empty($allday_uids)){
298+
$row = $loop_row_begin;
299+
$day = 0;
300+
$replace ='';
301+
while ($day < $phpiCal_config->week_length){
302+
$colspan = 0;
303+
$replace .= $loop_begin; # <td>
304+
if(array_search($weekarray[$day], $allday_uids)){
305+
$uid = array_search($weekarray[$day], $allday_uids);
306+
unset($allday_uids[$uid]);
307+
$allday = $master_array[$weekarray[$day]]['-1'][$uid];
308+
foreach ($allday_uid_dates[$uid] as $date){
309+
#$ev = (!isset($ev)) ? " $uid ":"";
310+
#$replace .= $ev;
311+
$colspan += $nbrGridCols[$weekarray[$day]];
312+
$day++;
313+
}
314+
$event_calno = $allday['calnumber'];
315+
$event_calno = (($event_calno - 1) % $phpiCal_config->unique_colors) + 1;
316+
$event = openevent($get_date, -1, $uid, $allday, $phpiCal_config->allday_week_lines, 11, 'psf');
317+
$loop_tmp = str_replace('{ALLDAY}', $event, $loop_ad);
318+
$loop_tmp = str_replace('{CALNO}', $event_calno, $loop_tmp);
319+
$replace .= $loop_tmp;
320+
$replace .= $loop_end;
321+
}else{
322+
$colspan = $nbrGridCols[$weekarray[$day]];
323+
$replace .= $loop_end;
324+
$day++;
325+
}
326+
unset ($ev);
327+
$replace = str_replace('{COLSPAN}', "colspan='$colspan'", $replace);
328+
}
329+
$row .= "$replace $loop_row_end\n";
330+
$weekreplace .= "$row\n";
331+
}
332+
/* old routine
333+
foreach ($weekarray as $i=>$get_date) {
282334
$replace = $loop_begin;
283335
$colspan = 'colspan="'.$nbrGridCols[$get_date].'"';
284336
$replace = str_replace('{COLSPAN}', $colspan, $replace);
285337
if (isset($master_array[$get_date]['-1']) && is_array($master_array[$get_date]['-1']) && !empty($master_array[$get_date]['-1']) ) {
286338
foreach ($master_array[$get_date]['-1'] as $uid => $allday) {
287339
$event_calno = $allday['calnumber'];
288340
$event_calno = (($event_calno - 1) % $phpiCal_config->unique_colors) + 1;
289-
$event = openevent($get_date, -1, $uid, $allday, 1, 11, 'psf');
341+
$event = openevent($get_date, -1, $uid, $allday, $phpiCal_config->allday_week_lines, 11, 'psf');
290342
$loop_tmp = str_replace('{ALLDAY}', $event, $loop_ad);
291343
$loop_tmp = str_replace('{CALNO}', $event_calno, $loop_tmp);
292344
$replace .= $loop_tmp;
@@ -295,6 +347,7 @@ function draw_week($template_p) {
295347
$replace .= $loop_end;
296348
$weekreplace .= $replace;
297349
}
350+
*/
298351
$this->page = preg_replace('!<\!-- loop alldaysofweek on -->.*<\!-- loop alldaysofweek off -->!Uis', $weekreplace, $this->page);
299352

300353
// Replaces the daysofweek
@@ -726,10 +779,10 @@ function tomorrows_events() {
726779
$event_text = strip_tags($event_text, '<b><i><u>');
727780
if ($event_text != "") {
728781
if (!isset($val["event_start"])) {
729-
$return_adtmp = openevent($next_day, $cal_time, $uid, $val, $tomorrows_events_lines, 21, 'psf');
782+
$return_adtmp = openevent($next_day, $cal_time, $uid, $val, $phpiCal_config->tomorrows_events_lines, 21, 'psf');
730783
$replace_ad .= str_replace('{T_ALLDAY}', $return_adtmp, $loop_t_ad);
731784
} else {
732-
$return_etmp = openevent($next_day, $cal_time, $uid, $val, $tomorrows_events_lines, 21, 'ps3');
785+
$return_etmp = openevent($next_day, $cal_time, $uid, $val, $phpiCal_config->tomorrows_events_lines, 21, 'ps3');
733786
$replace_e .= str_replace('{T_EVENT}', $return_etmp, $loop_t_e);
734787
}
735788
}
@@ -910,6 +963,7 @@ function draw_month($template_p, $offset = '+0', $type) {
910963
} else {
911964
$temp = $t_month[2];
912965
}
966+
$switch['ALLDAY'] = $switch['EVENT'] = '';
913967
if (isset($master_array[$daylink]) && $i <= $phpiCal_config->week_length) {
914968
if ($type != 'small') {
915969
foreach ($master_array[$daylink] as $cal_time => $event_times) {
@@ -920,7 +974,7 @@ function draw_month($template_p, $offset = '+0', $type) {
920974
if ($cal_time == -1) {
921975
if ($type == 'large') {
922976
$switch['ALLDAY'] .= '<div class="V10"><img src="templates/'.$phpiCal_config->template.'/images/monthdot_'.$event_calno.'.gif" alt="" width="9" height="9" border="0" />';
923-
$switch['ALLDAY'] .= openevent($daylink, $cal_time, $uid, $val, $month_event_lines, 15, 'psf');
977+
$switch['ALLDAY'] .= openevent($daylink, $cal_time, $uid, $val, $phpiCal_config->month_event_lines, 15, 'psf');
924978
$switch['ALLDAY'] .= (isset($val['location']) && $val['location'] != '') ? $val['location']."<br />" : '';
925979
$switch['ALLDAY'] .= '</div>';
926980
} else {
@@ -929,8 +983,8 @@ function draw_month($template_p, $offset = '+0', $type) {
929983
} else {
930984
$start2 = date($timeFormat_small, $val['start_unixtime']);
931985
if ($type == 'large') {
932-
@$switch['EVENT'] .= '<div class="V9"><img src="templates/'.$phpiCal_config->template.'/images/monthdot_'.$event_calno.'.gif" alt="" width="9" height="9" border="0" />';
933-
$switch['EVENT'] .= openevent($daylink, $cal_time, $uid, $val, $month_event_lines, 10, 'ps3', "$start2 ").'';
986+
$switch['EVENT'] .= '<div class="V9"><img src="templates/'.$phpiCal_config->template.'/images/monthdot_'.$event_calno.'.gif" alt="" width="9" height="9" border="0" />';
987+
$switch['EVENT'] .= openevent($daylink, $cal_time, $uid, $val, $phpiCal_config->month_event_lines, 10, 'ps3', "$start2 ").'';
934988
$switch['EVENT'] .= (isset($val['location']) && $val['location'] != '') ? "<br />".$val['location']."<br />" : '';
935989
$switch['EVENT'] .= '</div>';
936990
} else {
@@ -1008,7 +1062,7 @@ function monthbottom() {
10081062
$switch['CALNAME'] = $val['calname'];
10091063
if (!isset($val['event_start'])) {
10101064
$switch['START_TIME'] = $lang['l_all_day'];
1011-
$switch['EVENT_TEXT'] = openevent($m_start, $cal_time, $uid, $val, @$month_event_lines, 15, 'psf');
1065+
$switch['EVENT_TEXT'] = openevent($m_start, $cal_time, $uid, $val, $phpiCal_config->month_event_lines, 15, 'psf');
10121066
$switch['DESCRIPTION'] = urldecode($val['description']);
10131067
} else {
10141068
$event_start = $val['start_unixtime'];

0 commit comments

Comments
 (0)