Esempio n. 1
0
function processBooking()
{
    // rather than recursively calling query, insert all rows with one query
    global $general;
    // database table to store reservations
    $table = 'reservations';
    // reservation date
    $reservation_date = $_SESSION['selectedDate'];
    // prepare POST data for storage in database:
    // $keys
    // $values
    if ($_POST['action'] == 'submit') {
        $keys = array();
        $values = array();
        $i = 1;
        // prepare arrays for database query
        foreach ($_POST as $key => $value) {
            if ($key != "action" && $key != "dbdate" && $key != "reservation_date" && $key != "recurring_dbdate" && $key != "captcha" && $key != "barrier" && $key != "reservation_author" && $key != "email_type" && $key != "captchaField1" && $key != "captchaField2" && $key != "captchaField3") {
                $keys[$i] = $key;
                $values[$i] = "'" . $value . "'";
            }
            // remember some values
            if ($key == "reservation_date") {
                $reservation_date = strtotime($value);
            } else {
                if ($key == 'reservation_booker_name') {
                    $_SESSION['author'] = $value;
                } else {
                    if ($key == 'reservation_time') {
                        $_SESSION['reservation_time'] = "'" . $value . "'";
                    } else {
                        if ($key == 'reservation_pax') {
                            $_SESSION['reservation_pax'] = "'" . $value . "'";
                        }
                    }
                }
            }
            if ($key == "reservation_date") {
                $keys[$i] = $key;
                $values[$i] = "'" . $_SESSION['selectedDate'] . "'";
            }
            $i++;
        }
        // END foreach $_POST
        // =-=-=-=Store in database =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        // clear old booking number
        $_SESSION['booking_number'] = '';
        // variables
        $res_pax = $_POST['reservation_pax'] ? (int) $_POST['reservation_pax'] : 0;
        // sanitize old booking numbers
        $clr = querySQL('sanitize_unique_id');
        // create and store booking number
        if (!$_POST['reservation_id'] || $_POST['reservation_id'] == '') {
            $_SESSION['booking_number'] = uniqueBookingnumber();
            //$_SESSION['messages'][] = _booknum.":  ' ".$_SESSION['booking_number']." '";
            $keys[] = 'reservation_bookingnumber';
            $values[] = "'" . $_SESSION['booking_number'] . "'";
        }
        // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        // enter into database
        // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        // build new reservation date
        $index = array_search('reservation_date', $keys);
        // build for availability calculation
        $index = array_search('reservation_wait', $keys);
        if ($index) {
            $values[$index] = '1';
            $waitlist = '1';
        }
        //Check Availability
        // =-=-=-=-=-=-=-=-=
        // get Pax by timeslot
        $resbyTime = reservationsByTime('pax');
        $tblbyTime = reservationsByTime('tbl');
        // get availability by timeslot
        $occupancy = getAvailability($resbyTime, $general['timeintervall']);
        $tbl_occupancy = getAvailability($tblbyTime, $general['timeintervall']);
        //cut both " ' " from reservation_pax
        $res_pax = substr($_SESSION['reservation_pax'], 0, -1);
        $res_pax = substr($_SESSION['reservation_pax'], 1);
        $startvalue = $_SESSION['reservation_time'];
        //cut both " ' " from reservation_time
        $startvalue = substr($startvalue, 0, -1);
        $startvalue = substr($startvalue, 1);
        $val_capacity = $_SESSION['outlet_max_capacity'] - $occupancy[$startvalue];
        $tbl_capacity = $_SESSION['outlet_max_tables'] - $tbl_occupancy[$startvalue];
        if ((int) $res_pax > $val_capacity || $tbl_capacity < 1) {
            //prevent double entry
            $index = array_search('reservation_wait', $keys);
            if ($index > 0) {
                $values[$index] = '1';
                // = waitlist
                $waitlist = '1';
            } else {
                // error on new entry
                $keys[] = 'reservation_wait';
                $values[] = '1';
                // = waitlist
                $waitlist = '1';
            }
        }
        // END Availability
        if ($waitlist != 1) {
            // number of database fields
            $max_keys = count($keys);
            // enter into database
            // -----
            $query = "INSERT INTO `{$table}` (" . implode(',', $keys) . ") VALUES (" . implode(',', $values) . ") ON DUPLICATE KEY UPDATE ";
            // Build 'on duplicate' query
            for ($i = 1; $i <= $max_keys; $i++) {
                if ($keys[$i] != '') {
                    $query .= $keys[$i] . "=" . $values[$i] . ",";
                } else {
                    $max_keys++;
                }
            }
            // run sql query
            $query = substr($query, 0, -1);
            $result = query($query);
            $_SESSION['result'] = $result;
            // Reservation ID
            $resID = mysql_insert_id();
            // *** send confirmation email
            if ($_POST['email_type'] != 'no') {
                include '../web/classes/email.class.php';
            }
            // store new reservation in history
            $result = query("INSERT INTO `res_history` (reservation_id,author) VALUES ('%d','%s')", $resID, $_SESSION['author']);
            // Reservation was done
            $waitlist = 2;
        }
        // reservation done, handle back waitlist status
        return $waitlist;
    }
}
Esempio n. 2
0
 $_SESSION['reservation_date'] = $reservation_date;
 $_SESSION['recurring_date'] = $recurring_date;
 list($y1, $m1, $d1) = explode("-", $reservation_date);
 list($y2, $m2, $d2) = explode("-", $recurring_date);
 // =-=-=-=Store in database =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 // clear old booking number
 $_SESSION['booking_number'] = $_POST['reservation_bookingnumber'] == '' ? '' : $_POST['reservation_bookingnumber'];
 // memorize selected date
 $selectedDate = $_SESSION['selectedDate'];
 // res_dat is the beginning of circling through recurring dates
 $res_dat = $reservation_date;
 // sanitize old booking numbers
 $clr = querySQL('sanitize_unique_id');
 // create and store booking number
 if (!$_POST['reservation_id']) {
     $_SESSION['booking_number'] = uniqueBookingnumber();
     //$_SESSION['booking_number'] = '123';
     $keys[] = 'reservation_bookingnumber';
     $values[] = "'" . $_SESSION['booking_number'] . "'";
 }
 //store recurring reservation
 if ($recurring_date > $reservation_date) {
     $repeatid = querySQL('res_repeat');
     $keys[] = 'repeat_id';
     $values[] = "'" . $repeatid . "'";
 }
 // UNIX time
 $res_dat = mktime(0, 0, 0, (int) $m1, (int) $d1, (int) $y1);
 $recurring_date = mktime(0, 0, 0, (int) $m2, (int) $d2, (int) $y2);
 $recurring_date = $recurring_date < $res_dat ? $res_dat : $recurring_date;
 // daily or weekly recurring?