<?php session_start();
// uncomment the following part to have an access restriction
// to registered users only to the webfor
/*
if (!$_SESSION["valid_user"] || $_SESSION["valid_status"] >'5')
{
// User not logged in, redirect to login page
Header("Location: ../myseat/login.php?target=../webform/index.php");
}
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML lang="en">
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
/*
* This file is the ONLINE WEB FORMULAR part of mySeat
* @version build18816
* @author Bernd Orttenburger <hide@address.com>
* @betatesting Adam Shaw <hide@address.com>
* @link http://www.myseat.us
* @copyright (c) 2007-2009 myseat
* @license http://creativecommons.org/licenses/by-nc-sa/3.0/us/
*
* Please refer to LICENSE for any additional information
*
* Copyright (c) 2006 Show_day / (c) 2007-2009 myseat
*
* Many thanks for Beta testing to Adam Shaw <hide@address.com>!
*
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the License for more details.
*/
?>
<!-- #################### From here you can edit #################### -->
<?
/*
- BASIC SETTINGS for Webform
*/
// Path to main application
// with backslash at beginning,no backslash at end
//e.g. '$path = "../folder/subfolder"
$path = "../myseat";
// name & email of your facility/hotel
$restaurant_name = "mySeat Restaurant";
$contact_email = "hide@address.com";
// BCC to send out confirmation emails
// write your bcc-emails with '||' between
// leave blank ""; to have no bcc emails
$bcc_emails="hide@address.com";
//Maximum number of Guests allowed to book per table
$define_pax = 8;
// Percentage to book over internet
// e.g. 60% = It's not possible to book over internet with
// more than 60% of the restaurant booked
$define_percent = 70; // %
// Time format 12-US /24-EU hours
$tformat = 24; // 12 or 24
// ****** SET CONFIGURATION ******
require_once($path.'/config.php');
// ****** SET LOCAL DATE ******
//setlocale(LC_TIME, $country);
setlocale(LC_ALL, $country); // note the charset info !
?>
<title>Table Reservation/mySeat</title>
<!-- Include CSS Stylesheets -->
<link href="css_webform.css" type="text/css" rel="stylesheet" media="all"/>
<link href="css_calendar.css" type="text/css" rel="stylesheet" media="all"/>
<!-- Include Javascripts -->
<script type="text/javascript" src="validation.js"></script>
<script type="text/javascript">
/* Validation without error message*/
wFORMS.showAlertOnError = false; /* or true */
function reload(form)
{
// Setting the variable with the value of selected Outlet's ID and Persons to book
var val1 = document.makereservation.outlet.options[document.makereservation.outlet.options.selectedIndex].value;
var val5 = document.makereservation.reservation_pax.options[document.makereservation.reservation_pax.options.selectedIndex].value;
if(val1 == "" ) {val1 = 0;}
if ( "<? echo $date_selector; ?>" == "drop") {
// Setting the variables with the value of selected date
var val2 = document.makereservation.day.options[document.makereservation.day.options.selectedIndex].value;
var val3 = document.makereservation.month.options[document.makereservation.month.options.selectedIndex].value;
var val4 = document.makereservation.year.options[document.makereservation.year.options.selectedIndex].value;
// Sending the outlet id in the query string to retrieve the time list
self.location='index.php?outlet=' + val1 + '&day=' + val2 + '&month=' + val3 + '&year=' + val4 + '&reservation_pax=' + val5 ;
}else{
var val2 = document.getElementById("date").value;
// Sending the outlet id in the query string to retrieve the time list
self.location='index.php?outlet=' + val1 + '&date=' + val2 + '&reservation_pax=' + val5 ;
}
}
/* TRIM ALL LEADING AND FOLLOWING WHITESPACE IN A STRING*/
function trimString (str) {
return str.replace(/^s+/g, '').replace(/s+$/g, '');
}
</script>
</HEAD>
<BODY>
<?php
function makeDayoffDates ($day,$month,$year,$outlet_id){
global $host, $user, $pass, $db;
$highlighted_dates = array();
$outlet_closeday = array();
mysql_connect($host, $user, $pass) or die ("No Connection");
mysql_select_db($db) or die ("No Database");
mysql_query("SET NAMES 'utf8'");
$result = mysql_query("SELECT outlet_closeday FROM outlets WHERE outlet_id=$outlet_id");
while($row = mysql_fetch_object($result)) {
$outlet_closeday_text= $row->outlet_closeday;
}
if ($outlet_closeday_text!="") {
$outlet_closeday= explode (",",$outlet_closeday_text);
$days_in_month = date("t", mktime(0, 0, 0, $month, 1, $year));
$i=1;
while ($i <= $days_in_month)
{
$closeday_today= date("w",mktime(0,0,0,$month, $i, $year));
foreach ($outlet_closeday as $closeday) {
if ($closeday == $closeday_today){
$highlighted_dates[] = date("Y-m-d",mktime(0,0,0,$month, $i, $year));
}
}
$i++;
}
return $highlighted_dates;
}//end if
}
function ShowFromDate($year_interval,$YearIntervalType) {
global $day,$month,$year;
// copy sections Day,Month,Year in the rigt order eg: US date yy/mm/dd
//DAY
echo " Day <select onChange=\"reload(this.form)\" name='day'>\n";
$i=1;
$CurrDay=date("d");
$CurrMonth=date("m");
$CurrYear=date("Y");
If(!IsSet($day)) $day=$CurrDay;
if($month<=$CurrMonth && $day<$CurrDay) $day=$CurrDay;
$days_in_month = date("t", mktime(0, 0, 0, $month, 1, $year));
while ($i <= $days_in_month)
{
$day_text = date("d.,D", mktime(0, 0, 0, $month, $i, $year));
$disable = ($month<=$CurrMonth && $i<$CurrDay) ? "disabled='disabled'" : "";
If(IsSet($day)) {
If($day == $i || ($i == substr($day,1,1) && (substr($day,0,1) == 0))) {
echo"<option ".$disable." value='$day' selected='selected'>".date("d.,D", mktime(0, 0, 0, $month, $day, $year));
$i++;
}Else{
If($i<10) {
echo "<option ".$disable." value='0".$i."'>".$day_text; }Else { echo "<option ".$disable." value='".$i."'>".$day_text; } $i++;}
}Else {
If($i == $CurrDay)
If($i<10) {
echo "<option ".$disable." value='0".$i."' selected='selected'>".$day_text; }Else { echo"<option ".$disable." value='".$i."'selected='selected'>".$day_text;}
Else {
If($i<10) { echo "<option ".$disable." value='".$i."'>".$day_text; }Else { echo "<option ".$disable." value='".$i."'> ".$day_text; } } $i++;}
echo "</option>\n";
}
echo "</select>\n";
//end
//Month
echo " Month <select onChange=\"reload(this.form)\" name='month'>\n";
$i=1;
while ($i <= 12)
{
If(IsSet($month)) {
If($month == $i || ($i == substr($month,1,1) && (substr($month,0,1) == 0))) {
echo"<option value='".$month."' selected='selected'> $month";
$i++;
}Else{
If($i<10) { echo "<option value='0".$i."'>0$i"; }Else { echo "<option value='".$i."'>$i"; } $i++;}
}Else {
If($i == $CurrMonth) {
If($i<10) { echo "<option value='0".$i."' selected='selected'>0$i"; }Else { echo "<option value='".$i."' selected='selected'>$i"; }
}Else { If($i<10){ echo "<option value='0".$i."'> 0$i\n"; }Else { echo "<option value='".$i."'>$i"; } } $i++;}
echo "</option>\n";
}
echo "</select>\n";
//end
//YEAR
echo " Year <select onChange=\"reload(this.form)\" name='year'>\n";
If($YearIntervalType == "Future") {
$i=$CurrYear+$year_interval;
while ($CurrYear < $i)
{
if ($year == $CurrYear) echo "<option value='".$CurrYear."' selected='selected'> $CurrYear\n";
else echo "<option value='".$CurrYear."'> $CurrYear\n";
$CurrYear++;
echo "</option>\n";
}
echo "</select>\n";
}
}
//end
/*
- Function to return the right name
*/
function makenamesright ($name){
$outofbounds = array('Herr','Herrn','Herren','Hr.','Frau','Fr.','Prof.','Dr.','hc.','Mr.','Mrs.','Miss','und','Familie');
trim($name); //remove spaces at front and end of string
$name_array = explode(" ",$name); // make array from string
$counter = 0;
foreach ($name_array as $pieces){
$found = FALSE;
foreach ($outofbounds as $bounds){
//check if there is a title
if ($pieces == $bounds) {
$found = TRUE;
$counter++;
$title = array_shift ($name_array); // remove title
if ($counter==1){
$name_array[] = ","; // set a comma
}
$name_array[] = $title; // move title to the end
}
}
if ($found == FALSE){break;}
}
$name = implode(" ", $name_array); //make new string
return $name; //give string back
} //close function makenamesright
/*
- Function to return the Time list as an array
- Outlet ID is used to generate the time list
*/
function getTimeList($OutletId,$tformat)
{
$outlet_open_time = "12:00:00";
$outlet_close_time = "22:00:00";
global $host, $user, $pass, $db, $error_outlet;
$timeslots = array();
// build list of timeslots from starttime to endtime
// in half an hour intervall
mysql_connect($host, $user, $pass) or die ("No Connection");
mysql_select_db($db) or die ("No Database");
mysql_query("SET NAMES 'utf8'");
$query = "SELECT * FROM outlets WHERE outlet_id=$OutletId-1+1";
$result = mysql_query($query) or trigger_error(mysql_error());
while($row = mysql_fetch_object($result)) {
$outlet_open_time = $row->outlet_open_time;
$outlet_close_time = $row->outlet_close_time;
}
list($h1,$m1) = explode(":",$outlet_open_time);
list($h2,$m2) = explode(":",$outlet_close_time);
$value = mktime($h1-1+1,$m1-1+1,0,date("m"),date("d"),date("Y"));
$endtime = mktime($h2-1+1,$m2-1+1,0,date("m"),date("d"),date("Y"));
$i = 1;
//echo $outlet_open_time."/".$outlet_close_time."/".$value."//"; // error reporting
echo"<select name='reservation_time' id='reservation_time' size='1'>\n";
while( $value <= $endtime )
{
// Generating the time drop down menu
echo "<option value='".date('H:i',$value)."'>";
$txt_value = ($tformat == 24) ? date('H:i',$value) : date("g:i a", $value);
echo $txt_value;
echo"</option>\n";
$value = mktime($h1-1+1,$m1+$i*30,0,date("m"),date("d"),date("Y"));
$i++;
}
echo"</select>";
mysql_close();
}
/*
- Function to return the oulet list
*/
function getOutletList($date_saison,$outlet_id,$closeday_today)
{
global $host, $user, $pass, $db, $path;
global $booking_date,$reservation_id,$define_percent,$reservation_pax;
$error_outlet = 1;
// connect to database
mysql_connect($host, $user, $pass) or die ("No Connection");
mysql_select_db($db) or die ("No Database");
mysql_query("SET NAMES 'utf8'");
//read outlets
$outlet_result = mysql_query("SELECT * FROM outlets WHERE webform = 1 AND saison_start <= $date_saison AND saison_end >= $date_saison") or die (mysql_error());
$count_outlet = mysql_num_rows($outlet_result);
$full_outlets = 0;
echo "<select onChange='reload(this.form)' class='required' name='outlet' id='outlet' size='1'>\n";
echo"<option value=''>Choose one</option>\n";
while($outlet_row = mysql_fetch_object($outlet_result)) {
$reservation_outlet_id = $outlet_row->outlet_id;
//calculate times&dates
$outlet_open_time = $outlet_row->outlet_open_time;
list($h1,$m1) = explode(":",$outlet_open_time);
$outlet_open_time = mktime($h1-1+1,$m1-1+1,0,date("m"),date("d"),date("Y"));
$hence_time = mktime();
$d2 = date("d",mktime());
$m2 = date("m",mktime());
$hence_date = $m2.$d2;
// ****** CALCULATE AVAILABILITY ******
$now_full=0;
include ("availability.inc.php");
//Request if full or not and if 'Now' is greater than Open Time
if ($now_reserved>($outlet_max_capacity/100*$define_percent) || $now_tables>($outlet_max_tables/100*$define_percent))
{
$now_full=1;
}else if ($hence_date==$date_saison && $hence_time > $outlet_open_time){
$now_full=1;
}
if($now_full == 0){
echo"<option value='".$reservation_outlet_id."-".$outlet_row->outlet_name."'";
if ($reservation_outlet_id == $outlet_id){echo" selected='selected' ";}
echo">".$outlet_row->outlet_name."</option>\n";
}else{$full_outlets++;}
}
echo "</select>\n";
echo " Only <b>available</b> restaurants are shown!";
if ($count_outlet == 0 || $full_outlets == $count_outlet ){
echo "<div class='errorcontainer'><div class='icon-error'>There are no restaurants to book at this date.<br />";
echo "Please try another date.</div></div><br />";
}
return $error_outlet;
mysql_close();
}
/*
- Function to return the persons list
*/
function getPaxList($pax,$reservation_pax)
{
echo "<select onChange='reload(this.form)' name='reservation_pax' id='reservation_pax' size='1' >\n";
for($x = 1; $x <= $pax; $x++) {
echo"<option value='".$x."'";
if ($reservation_pax == $x){echo" selected='selected' ";}
echo ">".$x."</option>\n";
}
echo "</select>\n";
}
/*
- Get variables
*/
//This stops SQL Injection in POST vars
foreach ($_POST as $key => $value) {
$_POST[$key] = addslashes(strip_tags($value));
}
//This stops SQL Injection in GET vars
foreach ($_GET as $key => $value) {
$_GET[$key] = addslashes(strip_tags($value));
}
// Getting the variables for AJAX request
if (isset($_GET['outlet']))
{
$outlet = $_GET['outlet'];
$dd = explode("-",$outlet);
$outlet_id = $dd[0];
$outlet_name = $dd[1];
} else {
$outlet = 0;
$outlet_id = 0;
}
$day = (isset($_GET['day'])) ? $_GET['day'] : date("d");
$month = (isset($_GET['month'])) ? $_GET['month'] : date("m");
$year = (isset($_GET['year'])) ? $_GET['year'] : date("Y");
if(isset($_GET['date'])){
$date = $_GET['date'];
$day = date("d",strtotime($date));
$month = date("m",strtotime($date));
$year = date("Y",strtotime($date));
$date = date("Y-m-d", mktime(0,0,0,$month,$day,$year));
$print_date = ($tformat == 24) ? date("d.m.Y", mktime(0,0,0,$month,$day,$year)) : date("F d Y", mktime(0,0,0,$month,$day,$year));
}else{
$date = date("Y-m-d", mktime());
}
$booking_date = $date;
// Getting the variables from form
if (isset($_GET['reservation_pax']))
{$reservation_pax = $_GET['reservation_pax'];}
else {$reservation_pax = 1;}
if (isset($_GET['reservation_guest_name']))
{$reservation_guest_name = $_GET['reservation_guest_name'];}
if (isset($_GET['reservation_time']))
{$reservation_time = $_GET['reservation_time'];}
if (isset($_GET['reservation_guest_phone']))
{$reservation_guest_phone = $_GET['reservation_guest_phone'];}
if (isset($_GET['reservation_guest_email']))
{$reservation_guest_email = $_GET['reservation_guest_email'];}
if (isset($_GET['reservation_notes']))
{$reservation_notes = $_GET['reservation_notes'];}
if (isset($_GET['action']))
{$action = $_GET['action'];}
else {$action = "";}
//prevent spam
if (isset($_GET['email']))
{$spam = $_GET['email'];}
// Default Data
$reservation_hotelguest_yn = "PASS";
$reservation_booker_name = "Webform";
$closeday_today= date('w',mktime(0,0,0,$month+0,$day+0,$year+0));
$reservation_id = 0;
$reservation_guest_adress = "DEFAULT";
$reservation_guest_city = "DEFAULT";
$now_full = 0;
$repeat_id = 0;
$date_saison=$month.$day;
$date_saison=$date_saison-1+1;
/*
- Store reservation in mySQL database
*/
$message_flag = 0;
if($action =="save" && $outlet_id !=0 && $spam ==""){
mysql_connect($host, $user, $pass) or die ("No Connection");
mysql_select_db($db) or die ("No Database");
mysql_query("SET NAMES 'utf8'");
$reservation_guest_name = makenamesright ($reservation_guest_name);
// write data
$cmd_write = "INSERT INTO reservations (
reservation_outlet_id,
reservation_date,
reservation_time,
reservation_guest_name,
reservation_guest_adress,
reservation_guest_city,
reservation_guest_email,
reservation_pax,
reservation_hotelguest_yn,
reservation_guest_phone,
reservation_notes,
reservation_wait,
reservation_booker_name,
repeat_id
) VALUES (
$outlet_id,
'$date',
'$reservation_time',
'$reservation_guest_name',
'$reservation_guest_adress',
'$reservation_guest_city',
'$reservation_guest_email',
$reservation_pax,
'$reservation_hotelguest_yn',
'$reservation_guest_phone',
'$reservation_notes',
$now_full,
'$reservation_booker_name',
'$repeat_id'
)";
$run_cmd_write = mysql_query($cmd_write);
$message_flag = mysql_affected_rows();
if($message_flag){
$email_adresses=$reservation_guest_email."||".$bcc_emails;
$emails_in_array=explode("||",$email_adresses);
$print_reservation_time = ($tformat == 24) ? date('H:i',$reservation_time) : date("g:i a",$reservation_time);
foreach($emails_in_array as $email)
{
// Text for confirmation email, please change it your way !!
$subject = "Your table reservation at ".$restaurant_name;
$body = "Reservation confirmation\n\nDear ".$reservation_guest_name.",\nThank you for your reservation on ".$restaurant_name." online. This email is to confirm the booking.\n";
$body .= "Your name ".$reservation_guest_name."\nYour email ".$reservation_guest_email."\nChange or cancel your reservation by sending us a message to ".$contact_email." or use our homepage.\n\n";
$body .= "Your reservation data:\n\n";
$body .= "Restaurant ".$outlet_name."\n";
$body .= "Date ".$print_date."\n";
$body .= "Time ".$print_reservation_time."\n";
$body .= "Persons ".$reservation_pax."\n";
$body .= "Notes ".$reservation_notes."\n\n";
$body .= "Value added tax is included. Service fees are included. Tax is included. ";
$body .= "Payment can done by cash, ec-card or credit card.\n";
$body .= "Cancellations of up to one day before the date of reservation are free of charge. ";
$body .= "Cancelled later or not at all, with the price of 50% the menu price.\n";
$body .= "There are parking facilities available for charge.\nPets are not allowed.\n";
$body .= $restaurant_name." enforces the following dress code policy: ";
$body .= "Business casual attire is permitted at all times, for fine dining Dinner jacket is permitted.";
$body .= "Acceptable business attire includes collared shirts, casual pants, slacks, skirts and dresses.";
$body .= "\n\nWe wish you a pleasant stay.\n\n";
$body .= "Your ".$restaurant_name." team\n";
//***
mail($email, $subject, $body,"From: $restaurant_name <$contact_email>"); //SEND OUT MAIL
//***
}
}
mysql_close();
}
// connect to database to verify outlet_id
// Is the set outlet available at the new date?
mysql_connect($host, $user, $pass) or die ("No Connection");
mysql_select_db($db) or die ("No Database");
mysql_query("SET NAMES 'utf8'");
//read outlets
$query = "SELECT $outlet_id FROM outlets WHERE outlet_id=$outlet_id AND saison_start<=$date_saison AND saison_end>=$date_saison";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$num_rows = mysql_num_rows($result);
echo mysql_error();
if($num_rows == 0){
$query = "SELECT $outlet_id FROM outlets WHERE saison_start <= $date_saison AND saison_end >= $date_saison";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
if(isset($row[1])){$outlet_id = $row[1];} //it's not available, set back to standard
}
mysql_close();
?>
<!-- #################### End business logic #################### -->
<!-- #################### From here you can edit - Beginn HTML page #################### -->
<div class="main">
<h1>Restaurant</h1>
<h2>Table Reservation Form</h2>
<div class='errorcontainer' style ="display:none"><div class='icon-error' id="alertMessagePlaceHolder" ></div></div>
<?
// message after saving the reservation
// don't touch it, please.
if($action =="save"){
echo ($message_flag) ? "<div class='errorcontainer'><div class='icon-ok'>Your reservation was sucessfully accepted.<br />Thank you for your reservation.<br />You get an email confirmation the next minutes.</div></div><br />" : "<div class='errorcontainer'><div class='icon-error'>There was an error on booking.<br />Please try again.</div></div><br />";}
?>
<div class="box">
<h1>Make reservation</h1>
<p>You hereby place a binding order for the selected table!</p>
<!-- Beginn of Userform -->
<form name="makereservation" id="makereservation" method="get" action="index.php" accept-charset="UTF-8">
<div>
<label><span>Date</span>
<input type="hidden" name ="date" id="date" value="<?echo $date ?>">
<?
include('calendar.class.php');
// initiate calendar
//mark dayoff in calendar
$calendar = new Calendar($date);
//set day link
$calendar->link_to = "index.php?&reservation_pax=".$reservation_pax."&outlet=".$outlet."&";
//mark dayoff in calendar
$dayoff_dates = array();
$dayoff_dates = makeDayoffDates ($day,$month,$year,$outlet_id);
$calendar->highlighted_dates = $dayoff_dates;
$calendar->link_days = TRUE;
//output calendar
print($calendar->output_calendar());
?>
<br/>
</label>
<label><span>Restaurant*</span>
<? $error_outlet=getOutletList($date_saison,$outlet_id,$closeday_today); ?>
</label>
<label><span>Persons</span>
<? getPaxList($define_pax,$reservation_pax); ?>
</label>
</div>
<label><span>Time</span>
<? if ($error_outlet != 0){ getTimeList($outlet_id,$tformat);}
else {echo "<br>";} ?>
</label>
<label><span>Name*</span>
<input name="reservation_guest_name" id="reservation_guest_name" class="required"/>
First name, Last name.
</label>
<label><span>Phone*</span>
<input name="reservation_guest_phone" id="reservation_guest_phone" class="validate-integer required"/>
Only numbers please.
</label>
<label><span>Email*</span>
<input name="reservation_guest_email" id="reservation_guest_email" class="validate-email required"/>
</label>
<!-- secure a human being is filling out the form start -->
<input name="email" id="email" class="start"/>
<script type="text/javascript">
document.getElementById('email').style.display = 'none';
</script>
<!-- secure a human being is filling out the form end -->
<label><span>Note</span>
<textarea name="reservation_notes" id="reservation_notes" rows=5 cols=25 class="start"/></textarea>
</label>
<input type="hidden" name="action" value="save">
<br/>
<div id="submitholder"><button type="submit" onClick="return confirm('Please press OK to confirm booking a table.')">Book Table</button></div>
</form>
<!-- end form -->
<div class="spacer">
<br/><br/><br/>
Are you too cowardly to place a reservation? <a href="/">Go back to homepage.</a><br/>
Any problems? <a href="mailto:<?php echo $contact_email?>">Send us an email.</a>
</div>
</div> <!-- box div close -->
</div> <!-- main div close -->
</BODY>
</HTML>