Skip to content

Commit

Permalink
Fixed problem with repeating events not displaying properly for all d…
Browse files Browse the repository at this point in the history
…ate ranges.
  • Loading branch information
umcesrjones committed Oct 11, 2006
1 parent 76e4292 commit af84ad9
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 67 deletions.
2 changes: 1 addition & 1 deletion day.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

/* Pre-Load the repeated events for quckier access */
$repeated_events = read_repeated_events ( empty ( $user ) ? $login : $user,
$cat_id, $startdate );
$cat_id, $startdate, $enddate );

/* Pre-load the non-repeating events for quicker access */
$events = read_events ( empty ( $user ) ? $login : $user, $startdate, $enddate,
Expand Down
2 changes: 1 addition & 1 deletion freebusy.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
$enddate = mktime ( 0, 0, 0, date('m'), 1, date('Y') + 1 );

/* Pre-Load the repeated events for quicker access */
$repeated_events = read_repeated_events ( $user, '', $startdate );
$repeated_events = read_repeated_events ( $user, '', $startdate, $enddate );

/* Pre-load the non-repeating events for quicker access */
$events = read_events ( $user, $startdate, $enddate);
Expand Down
101 changes: 52 additions & 49 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2131,6 +2131,42 @@ function read_events ( $user, $startdate, $enddate, $cat_id = '') {
return query_events ( $user, false, $date_filter, $cat_id );
}

/**
* Reads all the repeated events for a user.
*
* This is only called once per page request to improve performance. All the
* events get loaded into the array <var>$repeated_events</var> sorted by time of day (not
* date).
*
* This will load all the repeated events into memory.
*
* <b>Notes:</b>
* - To get which events repeat on a specific date, use
* {@link get_repeating_entries()}.
* - To get all the dates that one specific event repeats on, call
* {@link get_all_dates()}.
*
* @param string $user Username
* @param int $cat_id Category ID to filter on (May be empty)
* @param int $date Cutoff date for repeating event cal_end in timestamp
* format (may be empty)
*
* @return array Array of RepeatingEvents sorted by time of day
*
* @uses query_events
*/
function read_repeated_events ( $user, $cat_id = '', $date = '', $enddate='' ) {
global $login, $layers, $jumpdate, $max_until;

//this date should help speed up things by eliminating events that
//won't display anyway
$jumpdate = $date;
$max_until = $enddate + ONE_DAY;
if ( $date != '') $date = date ('Ymd', $date );
$filter = ($date != '') ? "AND (webcal_entry_repeats.cal_end >= $date OR webcal_entry_repeats.cal_end IS NULL) " : '';
return query_events ( $user, true, $filter, $cat_id );
}

/**
* Reads all the tasks for a user with due date within the specified range of dates.
*
Expand Down Expand Up @@ -2242,7 +2278,7 @@ function get_tasks ( $date, $get_unapproved=true ) {
* @return array Array of Events sorted by time of day
*/
function query_events ( $user, $want_repeated, $date_filter, $cat_id ='', $is_task=false ) {
global $login, $thisyear, $thismonth, $layers, $result;
global $login, $thisyear, $thismonth, $layers, $result, $jumpdate, $max_until;
global $PUBLIC_ACCESS_DEFAULT_VISIBLE, $db_connection_info;

$cloneRepeats = array();
Expand Down Expand Up @@ -2432,7 +2468,8 @@ function query_events ( $user, $want_repeated, $date_filter, $cat_id ='', $is_ta
$resultcnt = count ( $result );
// TODO: allow passing this max_until as param in case we create
// a custom report that shows N years of events.
$max_until = mktime ( 0,0,0,$thismonth + 2,1, $thisyear);
if ( empty ( $max_until ) )
$max_until = mktime ( 0,0,0,$thismonth + 2,1, $thisyear);
for ( $i = 0; $i < $resultcnt; $i++ ) {
if ( $result[$i]->getID() != '' ) {
$rows = dbi_get_cached_rows ( 'SELECT cal_date, cal_exdate ' .
Expand Down Expand Up @@ -2469,7 +2506,7 @@ function query_events ( $user, $want_repeated, $date_filter, $cat_id ='', $is_ta
// So, let's do up to 365 days after current month.
// TODO: add this end time as a parameter in case someone creates
// a custom report that asks for N years of events.
$jump = mktime ( 0, 0, 0, $thismonth -1, 1, $thisyear);
//$jump = mktime ( 0, 0, 0, $thismonth -1, 1, $thisyear);
if ( $result[$i]->getRepeatCount() )
$rpt_count = $result[$i]->getRepeatCount() -1;
$date = $result[$i]->getDateTimeTS();
Expand All @@ -2493,7 +2530,7 @@ function query_events ( $user, $want_repeated, $date_filter, $cat_id ='', $is_ta
$result[$i]->getRepeatByDay(), $result[$i]->getRepeatBySetPos(),
$rpt_count, $until, $result[$i]->getRepeatWkst(),
$result[$i]->getRepeatExceptions(),
$result[$i]->getRepeatInclusions(), $jump );
$result[$i]->getRepeatInclusions(), $jumpdate );
$result[$i]->addRepeatAllDates($dates);
// serialize and save in cache for later use
// if ( ! empty ( $db_connection_info['cachedir'] ) ) {
Expand Down Expand Up @@ -2522,38 +2559,6 @@ function query_events ( $user, $want_repeated, $date_filter, $cat_id ='', $is_ta
return $result;
}

/**
* Reads all the repeated events for a user.
*
* This is only called once per page request to improve performance. All the
* events get loaded into the array <var>$repeated_events</var> sorted by time of day (not
* date).
*
* This will load all the repeated events into memory.
*
* <b>Notes:</b>
* - To get which events repeat on a specific date, use
* {@link get_repeating_entries()}.
* - To get all the dates that one specific event repeats on, call
* {@link get_all_dates()}.
*
* @param string $user Username
* @param int $cat_id Category ID to filter on (May be empty)
* @param int $date Cutoff date for repeating event cal_end in timestamp
* format (may be empty)
*
* @return array Array of RepeatingEvents sorted by time of day
*
* @uses query_events
*/
function read_repeated_events ( $user, $cat_id = '', $date = '' ) {
global $login;
global $layers;
if ( $date != '') $date = date ('Ymd', $date );
$filter = ($date != '') ? "AND (webcal_entry_repeats.cal_end >= $date OR webcal_entry_repeats.cal_end IS NULL) " : '';
return query_events ( $user, true, $filter, $cat_id );
}

/**
* Returns all the dates a specific event will fall on accounting for the repeating.
*
Expand Down Expand Up @@ -2754,14 +2759,12 @@ function get_all_dates ( $date, $rpt_type, $interval=1, $ByMonth ='',
$thisyear = substr($dateYmd, 0, 4);
$thisday = substr($dateYmd, 6, 2);
//skip to this year if called from query_events and we don't need count
// cek: commented out since it this is causing some events to not be
// loaded in year view and some reports.
//if ( ! empty ( $jump) && $Count == 999 ) {
// while ( date ( 'Y',$cdate ) < date ( 'Y', $jump ) ) {
// $thisyear += $interval;
// $cdate = mktime ( $hour, $minute, 0, 1, 1, $thisyear ) ;
// }
//}
if ( ! empty ( $jump) && $Count == 999 ) {
while ( date ( 'Y',$cdate ) < date ( 'Y', $jump ) ) {
$thisyear += $interval;
$cdate = mktime ( $hour, $minute, 0, 1, 1, $thisyear ) ;
}
}
$cdate = mktime ( $hour, $minute, 0, $thismonth, $thisday, $thisyear ) ;
while ($cdate <= $realend && $n <= $Count) {
$yret = array();
Expand Down Expand Up @@ -4989,9 +4992,9 @@ function daily_matrix ( $date, $participants, $popup = '' ) {
$cnt = count ( $participants );
for ( $i = 0; $i < $cnt; $i++ ) {
/* Pre-Load the repeated events for quckier access */
$repeated_events = read_repeated_events ( $participants[$i], '', $dateTS );
$repeated_events = read_repeated_events ( $participants[$i], '', $dateTS, $dateTS );
/* Pre-load the non-repeating events for quicker access */
$events = read_events ( $participants[$i], $dateTS , $dateTS );
$events = read_events ( $participants[$i], $dateTS, $dateTS );

// get all the repeating events for this date and store in array $rep
$rep = get_repeating_entries ( $participants[$i], $date );
Expand Down Expand Up @@ -5101,7 +5104,7 @@ function daily_matrix ( $date, $participants, $popup = '' ) {
array_unshift($participants, '_all_');
// Javascript for cells
//$MouseOut = 'onmouseout="this.style.backgroundColor=\'' . $CELLBG. '\';"';
$MouseOut = '';
$MouseOut = '';
$viewMsg = translate ( 'View this entry' );
// Display each participant
for ( $i = 0; $i <= $cnt; $i++ ) {
Expand Down Expand Up @@ -5137,9 +5140,9 @@ function daily_matrix ( $date, $participants, $popup = '' ) {
// This is the first line for 'all' users. No event here.
$space = "<span class=\"matrix\"><img src=\"images/pix.gif\" alt=\"\" /></span>";
} else if ($master[$participants[$i]][$r]['stat'] == "A") {
$space = "<a class=\"matrix\" href=\"view_entry.php?id={$master[$participants[$i]][$r]['ID']}\"><img src=\"images/pix.gif\" title=\"$viewMsg\" alt=\"$viewMsg\" /></a>";
$space = "<a class=\"matrix\" href=\"view_entry.php?id={$master[$participants[$i]][$r]['ID']}&friendly=1\"><img src=\"images/pix.gif\" title=\"$viewMsg\" alt=\"$viewMsg\" /></a>";
} else if ($master[$participants[$i]][$r]['stat'] == "W") {
$space = "<a class=\"matrix\" href=\"view_entry.php?id={$master[$participants[$i]][$r]['ID']}\"><img src=\"images/pixb.gif\" title=\"$viewMsg\" alt=\"$viewMsg\" /></a>";
$space = "<a class=\"matrix\" href=\"view_entry.php?id={$master[$participants[$i]][$r]['ID']}&friendly=1\"><img src=\"images/pixb.gif\" title=\"$viewMsg\" alt=\"$viewMsg\" /></a>";
}

$ret .= "<td class=\"matrixappts$border\" $style_width ";
Expand Down
2 changes: 1 addition & 1 deletion minical.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
print_header($INC,$HeadX,$BodyX,true);

/* Pre-Load the repeated events for quicker access */
$repeated_events = read_repeated_events ( $user, $cat_id, $startdate );
$repeated_events = read_repeated_events ( $user, $cat_id, $startdate, $enddate );

/* Pre-load the non-repeating events for quicker access */
$events = read_events ( $user, $startdate, $enddate, $cat_id );
Expand Down
3 changes: 2 additions & 1 deletion month.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@

/* Pre-Load the repeated events for quicker access */
$repeated_events = read_repeated_events (
( ! empty ( $user ) && strlen ( $user ) ) ? $user : $login, $cat_id, $startdate );
( ! empty ( $user ) && strlen ( $user ) )
? $user : $login, $cat_id, $startdate, $enddate );

/* Pre-load the non-repeating events for quicker access */
$events = read_events ( ( ! empty ( $user ) && strlen ( $user ) )
Expand Down
2 changes: 1 addition & 1 deletion report.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ function event_to_text ( $event, $date ) {
if ( empty ( $error ) && empty ( $list ) ) {
$cat_id = empty ( $report_cat_id ) ? '' : $report_cat_id;

$repeated_events = read_repeated_events ( $report_user, $cat_id, $start_date );
$repeated_events = read_repeated_events ( $report_user, $cat_id, $start_date, $end_date );
$events = read_events ( $report_user, $start_date, $end_date, $cat_id );

$get_unapproved = ( $DISPLAY_UNAPPROVED == 'Y' );
Expand Down
2 changes: 1 addition & 1 deletion rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@

/* Pre-Load the repeated events for quicker access */
if ( $allow_repeats == true )
$repeated_events = read_repeated_events ( $username, $cat_id, $startTime );
$repeated_events = read_repeated_events ( $username, $cat_id, $startTime, $endTime );

/* Pre-load the non-repeating events for quicker access */
$events = read_events ( $username, $startTime, $endTime, $cat_id );
Expand Down
2 changes: 1 addition & 1 deletion upcoming.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ function print_upcoming_event ( $e, $date ) {
} else {

/* Pre-Load the repeated events for quckier access */
$repeated_events = read_repeated_events ( $username, $cat_id, $startDate );
$repeated_events = read_repeated_events ( $username, $cat_id, $startDate, $endDate );

/* Pre-load the non-repeating events for quicker access */
$events = read_events ( $username, $startDate, $endDate, $cat_id );
Expand Down
2 changes: 1 addition & 1 deletion view_l.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
$re_save = array ();
for ( $i = 0; $i < count ( $viewusers ); $i++ ) {
/* Pre-Load the repeated events for quckier access */
$repeated_events = read_repeated_events ( $viewusers[$i], '', $startdate );
$repeated_events = read_repeated_events ( $viewusers[$i], '', $startdate, $enddate );
$re_save = array_merge($re_save, $repeated_events);
/* Pre-load the non-repeating events for quicker access */
$events = read_events ( $viewusers[$i], $startdate, $enddate );
Expand Down
2 changes: 1 addition & 1 deletion view_m.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
$viewusercnt = count ( $viewusers );
for ( $i = 0; $i < $viewusercnt; $i++ ) {
/* Pre-Load the repeated events for quckier access */
$repeated_events = read_repeated_events ( $viewusers[$i], '', $startdate );
$repeated_events = read_repeated_events ( $viewusers[$i], '', $startdate, $enddate );
$re_save[$i] = $repeated_events;
/* Pre-load the non-repeating events for quicker access */
$events = read_events ( $viewusers[$i], $startdate, $enddate );
Expand Down
2 changes: 1 addition & 1 deletion view_r.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
$uheader = '';
for ( $i = 0; $i < $viewusercnt; $i++ ) {
/* Pre-Load the repeated events for quckier access */
$repeated_events = read_repeated_events ( $viewusers[$i], '', $wkstart );
$repeated_events = read_repeated_events ( $viewusers[$i], '', $wkstart, $wkend );
$re_save[$i] = $repeated_events;
/* Pre-load the non-repeating events for quicker access
subtracting ONE_WEEK to allow cross-day events to display*/
Expand Down
2 changes: 1 addition & 1 deletion view_t.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ function print_header_timebar() {
$re_save = array ();
for ( $i = 0; $i < $viewusercnt; $i++ ) {
/* Pre-Load the repeated events for quckier access */
$repeated_events = read_repeated_events ( $viewusers[$i], '', $wkstart );
$repeated_events = read_repeated_events ( $viewusers[$i], '', $wkstart, $wkend );
$re_save = array_merge($re_save, $repeated_events);
/* Pre-load the non-repeating events for quicker access
subtracting ONE_WEEK to allow cross-day events to display*/
Expand Down
2 changes: 1 addition & 1 deletion view_v.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
$re_save = array ();
for ( $i = 0; $i < $viewusercnt; $i++ ) {
/* Pre-Load the repeated events for quicker access */
$re_save[$i] = read_repeated_events ( $viewusers[$i], '', $wkstart );
$re_save[$i] = read_repeated_events ( $viewusers[$i], '', $wkstart, $wkend );
/* Pre-load the non-repeating events for quicker access
subtracting ONE_WEEK to allow cross-dat events to display*/
$e_save[$i] = read_events ( $viewusers[$i], $wkstart - ONE_WEEK, $wkend );
Expand Down
2 changes: 1 addition & 1 deletion view_w.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
$re_save = array ();
for ( $i = 0; $i < $viewusercnt; $i++ ) {
/* Pre-Load the repeated events for quckier access */
$repeated_events = read_repeated_events ( $viewusers[$i], '', $wkstart );
$repeated_events = read_repeated_events ( $viewusers[$i], '', $wkstart, $wkend );
$re_save[$i] = $repeated_events;
/* Pre-load the non-repeating events for quicker access
subtracting ONE_WEEK to allow cross-day events to display*/
Expand Down
2 changes: 1 addition & 1 deletion week.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

/* Pre-Load the repeated events for quckier access */
$repeated_events = read_repeated_events ( strlen ( $user ) ? $user : $login,
$cat_id, $wkstart );
$cat_id, $wkstart, $wkend );

/* Pre-load the non-repeating events for quicker access */
//Start the search one week early to account for cross-day events
Expand Down
2 changes: 1 addition & 1 deletion week_details.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

/* Pre-Load the repeated events for quckier access */
$repeated_events = read_repeated_events ( strlen ( $user ) ?
$user : $login, $cat_id, $wkstart );
$user : $login, $cat_id, $wkstart, $wkend );

/* Pre-load the non-repeating events for quicker access */
$events = read_events ( strlen ( $user ) ? $user : $login, $wkstart, $wkend, $cat_id );
Expand Down
2 changes: 1 addition & 1 deletion week_ssi.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
$enddate = date ( 'Ymd', $wkend );

/* Pre-Load the repeated events for quckier access */
$repeated_events = read_repeated_events ( $login, '', $startdate );
$repeated_events = read_repeated_events ( $login, '', $startdate, $enddate );

/* Pre-load the non-repeating events for quicker access */
$events = read_events ( $login, $startdate, $enddate );
Expand Down
5 changes: 3 additions & 2 deletions year.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
if ( ! empty ( $BOLD_DAYS_IN_YEAR ) && $BOLD_DAYS_IN_YEAR == 'Y' ) {
/* Pre-Load the repeated events for quckier access */
$repeated_events = read_repeated_events (
( ! empty ( $user ) && strlen ( $user ) ) ? $user : $login, $cat_id, $startdate );
( ! empty ( $user ) && strlen ( $user ) ) ? $user : $login
, $cat_id, $startdate, $enddate );

/* Pre-load the non-repeating events for quicker access */
$events = read_events ( ( ! empty ( $user ) && strlen ( $user ) )
Expand Down Expand Up @@ -79,7 +80,7 @@
if ( empty ( $friendly ) ) {
$unapprovedStr = display_unapproved_events ( ( $is_assistant ||
$is_nonuser_admin ? $user : $login ) );
$printerStr = generate_printer_friendly ( 'month.php' );
$printerStr = generate_printer_friendly ( 'year.php' );
} else {
$unapprovedStr = $printerStr = '';
}
Expand Down

0 comments on commit af84ad9

Please sign in to comment.