function add_delta_ymd($date, $delta_years = 0, $delta_months = 0, $delta_days = 0) { // delta_years adjustment: // Use this to adjust for next and previous years. // Add the $delta_years to the current year and make the new date. if ($delta_years != 0) { // Split the date into its components. list($year, $month, $day) = explode("-", $date); // Careful to check for leap year effects! if ($month == 2 && $day == 29) { // Check the number of days in the month/year, with the day set to 1. $tmp_date = date("Y-m", mktime(1, 0, 0, $month, 1, $year + $delta_years)); list($new_year, $new_month) = explode("-", $tmp_date); $days_in_month = number_of_days_in_month($new_year, $new_month); // Lower the day value if it exceeds the number of days in the new month/year. if ($days_in_month < $day) { $day = $days_in_month; } $date = $new_year . '-' . $month . '-' . $day; } else { $new_year = $year + $delta_years; $date = sprintf("%04d-%02d-%02d", $new_year, $month, $day); } } // delta_months adjustment: // Use this to adjust for next and previous months. // Note: This DOES NOT subtract 30 days! // Use $delta_days for that type of calculation. // Add the $delta_months to the current month and make the new date. if ($delta_months != 0) { // Split the date into its components. list($year, $month, $day) = explode("-", $date); // Calculate New Month and Year $new_year = $year; $new_month = $month + $delta_months; if ($delta_months < -840 || $delta_months > 840) { $new_month = $month; } // Bad Delta if ($delta_months > 0) { // Adding Months while ($new_month > 12) { // Adjust so $new_month is between 1 and 12. $new_year++; $new_month -= 12; } } elseif ($delta_months < 0) { // Subtracting Months while ($new_month < 1) { // Adjust so $new_month is between 1 and 12. $new_year--; $new_month += 12; } } // Careful to check for number of days in the new month! $days_in_month = number_of_days_in_month($new_year, $new_month); // Lower the day value if it exceeds the number of days in the new month/year. if ($days_in_month < $day) { $day = $days_in_month; } $date = sprintf("%04d-%02d-%02d", $new_year, $new_month, $day); } // delta_days adjustment: // Use this to adjust for next and previous days. // Add the $delta_days to the current day and make the new date. if ($delta_days != 0) { // Split the date into its components. list($year, $month, $day) = explode("-", $date); // Create New Date $date = date("Y-m-d", mktime(1, 0, 0, $month, $day, $year) + $delta_days * 24 * 60 * 60); } // Check Valid Date, Use for TroubleShooting //list($year, $month, $day) = explode("-", $date); //$valid = checkdate($month, $day, $year); //if (!$valid) return "Error, function add_delta_ymd: Could not process valid date!"; return $date; }
function get_month_view_event_data($date, $location = DEFAULT_LOCATION_NAME) { // Get the event data for the selected month, year and location. global $location_db_name; list($year, $month, $day) = explode("-", $date); $query = "SELECT *\n\t\t\t\t\t\tFROM " . DATE_TIME_SCHEDULE_TABLE . ", " . BOOKING_EVENT_TABLE . " WHERE\n\t\t\t\t\t\t" . DATE_TIME_SCHEDULE_TABLE . "." . $location_db_name[$location] . " != 0 AND\n\t\t\t\t\t\t" . DATE_TIME_SCHEDULE_TABLE . "." . $location_db_name[$location] . " = " . BOOKING_EVENT_TABLE . ".event_id AND\n\t\t\t\t\t\t" . DATE_TIME_SCHEDULE_TABLE . ".schedule_date_time >= '" . $year . "-" . $month . "-01 00:00:01' AND\n\t\t\t\t\t\t" . DATE_TIME_SCHEDULE_TABLE . ".schedule_date_time < '" . $year . "-" . sprintf("%02d", $month) . "-31 23:59:59' \n\t\t\t\t\t\tORDER BY " . DATE_TIME_SCHEDULE_TABLE . ".schedule_date_time"; //echo $query."<br /><br />"; $result = wrap_db_query($query); $db_num_rows = wrap_db_num_rows($result); // Event Row Data Assoc. Array // $event_row_data['date']['event_id'] = 'db_row_id|row_span|start_time|end_time'; $event_row_data = array(array()); global $event_row_data; // Get the Display Times and Number of Rows $data_display_times = get_times_in_range(MIN_BOOKING_HOUR, MAX_BOOKING_HOUR, BOOKING_TIME_INTERVAL, true); $number_of_display_time_rows = count($data_display_times); // Get Month Information $number_of_days_in_the_month = number_of_days_in_month($year, $month); // Create an Assoc. Time array for index lookup. $display_time_lookup = array(); for ($i = 0; $i < $number_of_display_time_rows; $i++) { $display_time_lookup[$data_display_times[$i]] = $i; } // $event_row_data array - build out the schedule date blocks for ($day = 1; $day <= $number_of_days_in_the_month; $day++) { $for_date = $year . "-" . $month . "-" . sprintf("%02d", $day); $event_row_data[$for_date][0] = ''; } if (!$result) { return false; } // no database events // Go thru the database $result data and fill out the $event_row_data array. $previous_event_id = 0; $row_span = 0; $row = 0; $event = array(); //echo "<h1>TESTING</h1>"; for ($row = 0; $row <= $db_num_rows; $row++) { // define db variables $event = wrap_db_fetch_array($result); $db_event_id = $event['event_id']; //echo "ID: $db_event_id<br />"; list($db_starting_date, $db_starting_time) = explode(" ", $event['schedule_date_time']); list($db_hr, $db_min, $db_sec) = explode(":", $db_starting_time); $db_starting_time = sprintf("%02d", $db_hr) . ':' . sprintf("%02d", $db_min); if ($previous_event_id != $db_event_id || $previous_event_date != $db_starting_date || $previous_event_id == 0) { // event_id has changed / or first event_id if ($previous_event_id != 0) { // if not first id, then define $event_row_data array // place the event data into $event_row_data: 'db_row_id|row_span|start_time|end_time' $event_row_data[$event_start_date][$previous_event_id] = $event_start_db_row_id . "|" . $row_span . "|" . $event_start_time . "|" . $data_display_times[$display_time_lookup[$event_start_time] + $row_span]; // echo values for testing //echo "Define Event -> " . $event_start_date ."/" . $previous_event_id . " => " . $event_row_data[$event_start_date][$previous_event_id] . "<br />"; // initialize the row_span for the new event $row_span = 1; } // Mark the event starting time and db row id to be used to data_seeking //echo "<strong>Mark Start:</strong> ".$db_starting_date.", ".$row.", ".$db_event_id."<br />"; $event_start_time = $db_starting_time; // mark the starting time $event_start_date = $db_starting_date; // mark the starting date $event_start_db_row_id = $row; // mark the starting db row $row_span = 1; } else { // same event_id //echo "<strong>Same Event ID:</strong> ".$db_starting_time.", ".$row.", ".$db_event_id."<br />"; $row_span++; } $previous_event_id = $db_event_id; $previous_event_date = $db_starting_date; } // end of while // Display/Check the $event_row_data for errors //echo "<br />"; //for ($day=1; $day<=$number_of_days_in_the_month; $day++) { //$test_date = $year."-".$month."-".sprintf("%02d", $day); //echo "Test Date: ".$test_date."<br />"; //while (list($key, $value) = each($event_row_data[$test_date])) { //echo "Event ID: ".$key." Value: ".$value."<br />"; //} //} // return the resulting data object return $result; }
<?php // month_nav_widget.php // Displays the Month Navigation // Setup the weekday index array values $wdays_ind = array(); $wdays_ind = weekday_index_array(WEEK_START); $days_in_the_month = number_of_days_in_month(SELECTED_DATE_YEAR, SELECTED_DATE_MONTH); $month_begin_wday = weekday_short_name(beginning_weekday_of_the_month(SELECTED_DATE_YEAR, SELECTED_DATE_MONTH)); ?> <!-- month_nav_widget.php --> <table cellspacing="2" cellpadding="1" width="100%" border="0"> <!-- header --> <tr> <?php reset($wdays_ind); foreach ($wdays_ind as $index) { ?> <td align="center" valign="middle" class="BgcolorBright"><b class="FontSoftSmall"><?php echo weekday_short_name($index); ?> </b></td> <?php } ?> </tr> <!-- rows --> <?php $count = 0;
$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>"; $page_error_message .= "The form has been updated to reflect the maximum end and recurrence dates (where applicable).<br>Please check these dates, select an appropriate start date and re-submit the form."; } } elseif (!check_valid_date($ending_date)) { $page_error_message = "Your ending date does not exist. There are only " . number_of_days_in_month($_POST['end_year'], $_POST['end_mon']) . " days in " . month_name($_POST['end_mon']) . " " . $_POST['end_year'] . ". Please check the calendar and try again."; } elseif (!check_valid_date($recur_date) && $recur_interval != '') { $page_error_message = "Your recurring date does not exist. There are only " . number_of_days_in_month($_POST['recur_year'], $_POST['recur_mon']) . " days in " . month_name($_POST['recur_mon']) . " " . $_POST['recur_year'] . ". Please check the calendar and try again."; } elseif (implode("", explode("-", $ending_date)) . implode("", explode(":", $_POST['end_time'])) + 0 <= implode("", explode("-", $starting_date)) . implode("", explode(":", $_POST['start_time'])) + 0) { $page_error_message = "Your ending date and time must occur after your starting " . "date and time. Please check your dates and times and try again."; } elseif (implode("", explode("-", $recur_date)) + 0 <= implode("", explode("-", $ending_date)) + 0 && !($recur_interval == 'none' || $recur_interval == '')) { $page_error_message = "Your recurring until date must occur after your ending " . "date. Please check your dates and try again."; } // end of if/elseif //if recurrence interval is set to none, overwrite the recur_date with //the start date to prevent entry of past recur dates into the db if ($recur_interval == 'none' || $recur_interval == '') { $recur_date = $starting_date; } // CHECK FOR OVERLAPPING RECURRENCE PROBLEM //echo "Recurrence Dates:<br />"; reset($recurring_dates); while (list($date, $freq) = each($recurring_dates)) {