Example #1
0
function get_recurrence_dates($event_start_date, $event_end_date, $recur_end_date = '', $recur_frequency = '', $recur_interval = '')
{
    $recur_interval = strtolower($recur_interval);
    //echo "<br />Start Date: ".$event_start_date."<br />";
    //echo "End Date: ".$event_end_date."<br />";
    //echo "Recur Date: ".$recur_end_date."<br />";
    //echo "Interval: ".$recur_interval."<br /><br />";
    $days_span = days_span($event_start_date, $event_end_date);
    //echo "Days Span: ".$days_span."<br />";
    // For each day we will attempt to determine the
    // recurrence dates for this event.
    $recur_days = array();
    $recur_days[] = $event_start_date;
    // Define Date "Values" for Numeric Comparison
    $recur_end_date_value = implode("", explode("-", $recur_end_date)) + 0;
    $event_end_date_value = implode("", explode("-", $event_end_date)) + 0;
    // Define Variables for Recur Monthly by Weekday Occurence of the Month
    list($start_year, $start_month, $start_day) = explode("-", $event_start_date);
    $start_weekday = weekday_of_the_month($event_start_date);
    $start_weekday_occurrence = weekday_occurrence($event_start_date);
    $recur_date_value = 0;
    $i = 1;
    if ($recur_end_date_value > $event_end_date_value && $recur_interval != '' && $recur_interval != 'none' && $recur_end_date != '') {
        while ($recur_date_value < $recur_end_date_value && $i < 100) {
            // Recur Daily
            if ($recur_interval == 'day') {
                $recur_date = add_delta_ymd($event_start_date, 0, 0, $i * $recur_frequency);
                // Recur Weekly
            } elseif ($recur_interval == 'week') {
                $recur_date = add_delta_ymd($event_start_date, 0, 0, $i * 7 * $recur_frequency);
                // Recur Monthly by Day of the Month
            } elseif ($recur_interval == 'day-month') {
                $recur_date = add_delta_ymd($event_start_date, 0, $i * $recur_frequency, 0);
                // Recur Monthly by Weekday Occurence of the Month (The Difficult One!)
            } elseif ($recur_interval == 'weekday-month') {
                $new_month = $start_month + $i * $recur_frequency;
                $new_year = $start_year;
                while ($new_month > 12) {
                    // Adjust so $new_month is between 1 and 12.
                    $new_year++;
                    $new_month -= 12;
                }
                $recur_date = xst_weekday_of_the_month($start_weekday_occurrence, $start_weekday, $new_year, $new_month);
                //echo "Weekday: ".weekday_of_the_month($event_start_date)."<br />";
                //echo "Occurence: ".weekday_occurrence($event_start_date)."<br />";
                //echo "Xst Recur Date: ".$recur_date."<br />";
                //echo "Year: $new_year, Month: $new_month<br />";
            } elseif ($recur_interval == 'year') {
                $recur_date = add_delta_ymd($event_start_date, $i, 0, 0);
            }
            $recur_date_value = implode("", explode("-", $recur_date)) + 0;
            if ($recur_date_value > $recur_end_date_value) {
                break;
            }
            if ($recur_date != '') {
                $recur_days[] = $recur_date;
            }
            $i++;
        }
        // end of while
    }
    // end of if
    // If the event spans more than 1 day then we need to
    // determine the dates of each of those days, for each recurrency.
    // We do this after, because of the last date of the month differences.
    $spanning_days = array();
    if ($days_span > 1 && $recur_interval != 'day') {
        foreach ($recur_days as $recur_day) {
            for ($days = 1; $days < $days_span; $days++) {
                $spanning_days[] = add_delta_ymd($recur_day, 0, 0, $days);
            }
            // end of for $days_span
        }
        // end of foreach $recur_day
    }
    reset($spanning_days);
    // Merge the two arrays together and get the unique dates.
    @($all_days = array_merge($spanning_days, $recur_days));
    @($all_days_assoc = array_count_values($all_days));
    // dates assoc with counts/freq
    @ksort($all_days_assoc);
    return $all_days_assoc;
}
Example #2
0
         $_POST['recur_day'] = $limited_day;
         $_REQUEST['recur_year'] = $limited_year;
         $_REQUEST['recur_mon'] = $limited_month;
         $_REQUEST['recur_day'] = $limited_day;
         //fail the request
         $dates_within_limit = false;
         $bookingTooFarAhead = true;
     }
 }
 // DEFINE THE RECURRING DATES, FREQUENCY AND INTERVAL
 $recur_freq = stripslashes($_REQUEST['recur_freq']);
 $recur_interval = stripslashes($_REQUEST['recur_interval']);
 $recurring_dates = array();
 $recurring_dates = get_recurrence_dates($starting_date, $ending_date, $recur_date, $recur_freq, $recur_interval);
 //NUMBER OF SPANNING DAYS (NOT including the recurrence dates)
 $days_span = days_span($starting_date, $ending_date);
 //echo "<br />Days Span: $days_span<br />";
 // CHECK REQUIRED FIELDS
 if ($_POST['subject'] == "") {
     $page_error_message = "You have not filled out the add form completely. Please type in a subject.";
 } elseif ($unix_starting_date < $unix_todays_date) {
     $page_error_message = "Your starting date is in the past! Please enter a start date in the future.";
 } elseif (!check_valid_date($starting_date)) {
     $page_error_message = "Your starting date does not exist. There are only " . number_of_days_in_month($_POST['start_year'], $_POST['start_mon']) . " days in " . month_name($_POST['start_mon']) . " " . $_POST['start_year'] . ". Please check the calendar and try again.";
 } elseif (!$dates_within_limit) {
     if ($bookingTooSoonAhead) {
         $page_error_message = "Your starting time is outside of the minimum booking period of " . $bookeeMinimumAdvanceBookingLimit . " hours.<br><br>";
         $page_error_message .= "Please select a later booking slot and re-submit the form.";
     } else {
         //Basically: $bookingTooFarAhead == true
         $page_error_message = "Your ending date is outside of the booking limit of " . $bookeeAdvanceBookingLimit / 24 . " days.<br><br>";