<commit_before><?php

class Booking
{
	// Booking status types
	const TENTATIVE = 0;
	const CONFIRMED = 1;
	const REJECTED = 2;

	// Class members
	public $id;                         // Unique booking-id
	public $userid;                     // The user-id of this booking's user
	public $roomid;                     // The room-id of this booking's location
	public $title;                      // The title of the booking event.
	public $description;
	public $date_booked;                // Date that this booking was made
	public $start_time;                 // Start datetime
	public $end_time;                   // End datetime
	public $status = self::TENTATIVE;   // Booking status is tentative by default
	public $repeat =0;
	public $repeat_freq = 0;
	public $repeat_end=NULL;

	// NOTE: dates are in the format YYYY-MM-DD
	// NOTE: datetimes are in the format YYYY-MM-DD HH:MM:SS
	// TODO: Globalize the format of the date/time so it's consistent and easy
	// to maintain.

	/*
	 * Format a date into the database's date format.
	 *
	 * Takes 3 integers: year, month, and day and returns a date string. Will
	 * fail if the year-month-day combination is invalid as per the mktime
	 * function.
	 *
	 * @param year:integer
	 * @param month:integer
	 * @param day:integer
	 */
	function format_date($year, $month, $day){
		$time = new DateTime("$year-$month-$day");
		return $time->format('Y-m-d');
	}

	// Format a time into the DB's format
	// Takes 3 integers: hour, minute, and a selector (0 for AM, 1 for PM)
	// The hour should be specified for a 12-hour clock
	// Leading zeroes are not necessary in the arguments (so 2, 0, 0 is OK) 
	// Returns true on success, false on fail
	// Failure occurs when the combination of hour, minute, and selector is invalid
	// Returns a timestamp of the form: HH:MM:SS on success, in 24-hour format, or false on fail
	// Failure occurs when the combination of hour, minute, and selector is invalid
	function format_time($hour, $minute) {
		$time = new DateTime("t $hour:$minute:00");
		return $time->format('H:i:s');
	}

	function format_datetime(DateTime $time) {
		return $time->format('Y-m-d H:i:s');
	}
    
    
    /**
     * Validates a set of booking details, as submitted to the add_booking()
     * controller function (main controller). Note that the all_day, room,
     * client, and status properties of a booking are set up in our forms so
     * that they will always have valid values, so they are not checked here.
     * 
     * Returns 0 on successful validation of details, or one of the following:
     * 1 = The 'title' field is blank
     * 2 = The 'from' date is after the 'to' date
     * 3 = The 'from' date is before today's date
     * 4 = The 'from' time of a same-day event occurs at or after its 'to' time
     * 5 = A repeating event has a non-integer frequency
     * 6 = A repeating event has a frequency that is less than 1 day
     * 7 = A repeating event has an end-date that is before its from-date
     * 8 = The 'description' field is blank
     */
    functon validate_booking_details
        ( $title, $from_date, $to_date, $from_time, $to_time,
          $repeat, $repeat_freq, $repeat_end, $description ){
        
        // If the title field is empty, return error code 1
        if ($title == '') {
            return 1;
        }
        
        // If the from-date is after the to-date, return error code 2
        $from = ( substr($from_date, 0, 4) * 10000 ) +
                ( substr($from_date, 5, 2) * 100   ) +
                  substr($from_date, 8, 2);
        $to = ( substr($to_date, 0, 4) * 10000 ) +
              ( substr($to_date, 5, 2) * 100   ) +
                substr($to_date, 8, 2);
        if ($from > $to) {
            return 2;
        }
        
        // If the from-date is before today's date, return error code 3
        $today = date_format(new DateTime(), 'Y-m-d');
        $today = ( substr($today, 0, 4) * 10000 ) +
                 ( substr($today, 5, 2) * 100   ) +
                   substr($today, 8, 2);
        if ($from < $today) {
            return 3;
        }
        
        // If the event is same-day, and the from-time is after the to-time, return error code 4
        if ($from == $to) {<commit_msg>Added form checking -- fixed more<commit_after><?php

class Booking
{
	// Booking status types
	const TENTATIVE = 0;
	const CONFIRMED = 1;
	const REJECTED = 2;

	// Class members
	public $id;                         // Unique booking-id
	public $userid;                     // The user-id of this booking's user
	public $roomid;                     // The room-id of this booking's location
	public $title;                      // The title of the booking event.
	public $description;
	public $date_booked;                // Date that this booking was made
	public $start_time;                 // Start datetime
	public $end_time;                   // End datetime
	public $status = self::TENTATIVE;   // Booking status is tentative by default
	public $repeat =0;
	public $repeat_freq = 0;
	public $repeat_end=NULL;

	// NOTE: dates are in the format YYYY-MM-DD
	// NOTE: datetimes are in the format YYYY-MM-DD HH:MM:SS
	// TODO: Globalize the format of the date/time so it's consistent and easy
	// to maintain.

	/*
	 * Format a date into the database's date format.
	 *
	 * Takes 3 integers: year, month, and day and returns a date string. Will
	 * fail if the year-month-day combination is invalid as per the mktime
	 * function.
	 *
	 * @param year:integer
	 * @param month:integer
	 * @param day:integer
	 */
	function format_date($year, $month, $day){
		$time = new DateTime("$year-$month-$day");
		return $time->format('Y-m-d');
	}

	// Format a time into the DB's format
	// Takes 3 integers: hour, minute, and a selector (0 for AM, 1 for PM)
	// The hour should be specified for a 12-hour clock
	// Leading zeroes are not necessary in the arguments (so 2, 0, 0 is OK) 
	// Returns true on success, false on fail
	// Failure occurs when the combination of hour, minute, and selector is invalid
	// Returns a timestamp of the form: HH:MM:SS on success, in 24-hour format, or false on fail
	// Failure occurs when the combination of hour, minute, and selector is invalid
	function format_time($hour, $minute) {
		$time = new DateTime("t $hour:$minute:00");
		return $time->format('H:i:s');
	}

	function format_datetime(DateTime $time) {
		return $time->format('Y-m-d H:i:s');
	}
    
    
    /**
     * Validates a set of booking details, as submitted to the add_booking()
     * controller function (main controller). Note that the all_day, room,
     * client, and status properties of a booking are set up in our forms so
     * that they will always have valid values, so they are not checked here.
     * 
     * Returns 0 on successful validation of details, or one of the following:
     * 1 = The 'title' field is blank
     * 2 = The 'from' date is after the 'to' date
     * 3 = The 'from' date is before today's date
     * 4 = The 'from' time of a same-day event occurs at or after its 'to' time
     * 5 = A repeating event has a non-integer frequency
     * 6 = A repeating event has a frequency that is less than 1 day
     * 7 = A repeating event has an end-date that is before its from-date
     * 8 = The 'description' field is blank
     */
    functon validate_booking_details( $title, $from_date, $to_date, $from_time, $to_time, $repeat, $repeat_freq, $repeat_end, $description ){
        
        // If the title field is empty, return error code 1
        if ($title == '') {
            return 1;
        }
        
        // If the from-date is after the to-date, return error code 2
        $from = ( substr($from_date, 0, 4) * 10000 ) +
                ( substr($from_date, 5, 2) * 100   ) +
                  substr($from_date, 8, 2);
        $to = ( substr($to_date, 0, 4) * 10000 ) +
              ( substr($to_date, 5, 2) * 100   ) +
                substr($to_date, 8, 2);
        if ($from > $to) {
            return 2;
        }
        
        // If the from-date is before today's date, return error code 3
        $today = date_format(new DateTime(), 'Y-m-d');
        $today = ( substr($today, 0, 4) * 10000 ) +
                 ( substr($today, 5, 2) * 100   ) +
                   substr($today, 8, 2);
        if ($from < $today) {
            return 3;
        }
        
        // If the event is same-day, and the from-time is after the to-time, return error code 4
        if ($from == $to) {
{'fraction_non_alphanumeric': 0.10683609836451347, 'fraction_numerical': 0.01811977879750559, 'mean_word_length': 2.1728256812243374, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '511309', 'n_tokens_mistral': 2748, 'n_tokens_neox': 2485, 'n_words': 1034}