function create_date_time_schedule_data($date, $location = DEFAULT_LOCATION_NAME) { //echo "<p>create_date_time_schedule_data function: $date</p>"; // create the date time schedule data for the specified year and month. global $location_db_name; list($year, $month, $day) = explode("-", $date); // query for the date time data for the 1st of the month, limit only 1 $result = wrap_db_query("SELECT * FROM " . DATE_TIME_SCHEDULE_TABLE . " WHERE\n\t\t\t\t\t\t" . $location_db_name[$location] . " >= 0 AND\n\t\t\t\t\t\tschedule_date_time = '" . $year . "-" . $month . "-01 " . MIN_BOOKING_HOUR . ":00:00'\n\t\t\t\t\t\tLIMIT 0,1"); if (!defined(BOOKING_TIME_INTERVAL)) { define(BOOKING_TIME_INTERVAL, 30); } // If there are no result(s) then we need to create the data for this month. if (!(wrap_db_num_rows($result) >= 1) || !$result) { // Define Valid Times (hh:mm format) $valid_times = get_times_in_range(sprintf("%02d", MIN_BOOKING_HOUR) . ':00', sprintf("%02d", MAX_BOOKING_HOUR) . ':00', BOOKING_TIME_INTERVAL, false); // Define Starting Weekday Value (0=Sunday, 1=Monday,...,6=Saturday) $dayoftheweekid = beginning_weekday_of_the_month($year, $month); for ($i = 1; $i <= 31; $i++) { // For Each Day in the Month. if (check_valid_date($year . '-' . $month . '-' . $i)) { //echo "Loop ID: $i<br />"; if ($dayoftheweekid == 7) { $dayoftheweekid = 0; } //echo "Day of the Week ID: $dayoftheweekid <br />"; foreach ($valid_times as $valid_time) { $result = wrap_db_query("INSERT INTO " . DATE_TIME_SCHEDULE_TABLE . " \n\t\t\t\t\t\tSET schedule_date_time = '" . $year . "-" . $month . "-" . sprintf("%02d", $i) . " " . $valid_time . "', day_of_the_week_id = " . $dayoftheweekid); } $dayoftheweekid++; } // end of if } // end of for loop // Order the table if modified. $result = wrap_db_query("ALTER TABLE " . DATE_TIME_SCHEDULE_TABLE . " ORDER BY schedule_date_time"); // Optimize all of the main tables. $result = wrap_db_query("OPTIMIZE TABLE " . DATE_TIME_SCHEDULE_TABLE); $result = wrap_db_query("OPTIMIZE TABLE " . BOOKING_EVENT_TABLE); $result = wrap_db_query("OPTIMIZE TABLE " . BOOKING_USER_TABLE); } // end of if return true; }
} 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>"; $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);
function get_day_view_event_data($date, $location = DEFAULT_LOCATION_NAME) { // Get the event data for the selected day, month, year and location. global $location_db_name; // Sanitize for MySQL $date = wrap_db_escape_string($date); // Check Valid Date if (!check_valid_date($date)) { $date = '1970-01-01'; } list($year, $month, $day) = explode("-", $date); $query = "SELECT * \r\n\t\t\t\t\t\tFROM " . DATE_TIME_SCHEDULE_TABLE . ", " . BOOKING_EVENT_TABLE . " WHERE \r\n\t\t\t\t\t\t" . DATE_TIME_SCHEDULE_TABLE . "." . $location_db_name[$location] . " != 0 AND \r\n\t\t\t\t\t\t" . DATE_TIME_SCHEDULE_TABLE . "." . $location_db_name[$location] . " = " . BOOKING_EVENT_TABLE . ".event_id AND \r\n\t\t\t\t\t\t" . DATE_TIME_SCHEDULE_TABLE . ".schedule_date_time >= '" . $date . " 00:00:00' AND \r\n\t\t\t\t\t\t" . DATE_TIME_SCHEDULE_TABLE . ".schedule_date_time <= '" . $date . " 23:59:59' \r\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['display_time'] = 'db_row_id|row_span|start_time|end_time'; $event_row_data = 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); // Create an Assoc. Date 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 time blocks foreach ($data_display_times as $display_time) { $event_row_data[$display_time] = ''; } reset($data_display_times); if (!$result) { //echo "No Database Events / Results<br />"; return false; } // 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_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_time] = $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_row_data[$event_start_time] . "<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_time.", ".$row.", ".$db_event_id."<br />"; $event_start_time = $db_starting_time; // mark the starting time $event_start_db_row_id = $row; // mark the starting db row $row_span = 1; } else { // same event_id // Set the 'row_span' for the spanning cells of the event to zero ('row_span' = 0) $event_row_data[$db_starting_time] = 0; //echo "<strong>Same Event ID:</strong> ".$db_starting_time.", ".$row.", ".$db_event_id."<br />"; $row_span++; } $previous_event_id = $db_event_id; } // end of while // Display/Check the $event_row_data for errors //echo "<br />"; //foreach ($data_display_times as $display_time) { // echo $display_time." Event Row Data: ".$event_row_data[$display_time]."<br />"; //} // return the resulting data object return $result; }