forked from 702webdev/Google-Calendar-API-Booking-Form
-
Notifications
You must be signed in to change notification settings - Fork 0
/
booking.php
231 lines (196 loc) · 9.53 KB
/
booking.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<script>
function startOver(){
window.location="ADDRESS TOP WHERE EVER YOU PUT THIS FILE ON THE SERVER/busbooking.php";
}
</script>
<?php
require_once('libs/cal/corecal.php');
$thecal = 'court1';
/*
* Advance is the amount of time in the future someone can book something.
* days
* weeks
* months
* If it is 0, it will allow unlimited future booking
*/
/*
* ------ Instructions ------
* Fill in where is says put calendar id with the id of your calendar which can be found by doing the following.
*
* 1. Access your Google Calendar at https://www.calendar.google.com.
* 2. Click on the drop down arrow next to the affected calendar and select 'Calendar settings'
* 3. Copy the string beside 'Calendar ID' and paste it in.
*
* You will also need the API Key for Google Calendar as well.
*/
$calendarId = "CALENDER ID GOES HERE";
$courts = array(
'court1' => array('cid' => 'court1', 'name' => 'court1', 'id' => 'CALENDER ID GOES HERE', 'starttime' => '10:00:00', 'endtime' => '20:00:00', 'advance' => '52 weeks'),
);
$APIKEY = 'PUT API KEY HERE';
$message = "";
if(isset($_POST['submit']) && $_POST['submit'] == 'Book Court'){
/* This section is to set the date in the correct format
* and to set the ending time to 15 minutes past the time
* that they selected and set time to 15 minuts prior
* to the time they selected which is used to determine
* information about the location of each booking and if
* the driver can get to the two places within one trip.
*/
$date = $_POST['startdate'];
$startdate = date("Y-m-d", strtotime($date));
$From = $_POST['starttime'];
$Minutes = 15;
$endtime1 = date("H:i", strtotime($From)+($Minutes*60));
$locationStartTime = date("H:i", strtotime($From)-($Minutes*60));
$endtime;
/* This section gets the location that the user wants to be picked up
* and gets the location of any booking that is 15 minutes before or
* 15 minutes after the time that they selected. It then will get the
* distance between the two points in miles.
*/
//$startlocation = $_POST['location'];
//$endlocation = getEndLocation($startdate,$locationStartTime,$endtime1,$courts[$_POST['calendar']]['id']);
//$startLoc = $startlocation;
//$endLoc = $endlocation;
//if ($endlocation != ""){
//$start = getLatLong($startLoc);
//$finish = getLatLong($endLoc);
//$distance = Haversine($start, $finish);
//}else{
//$distance = 0;
//}
if ($_POST['passengers'] == '1'){
$titleDetails = $_POST['title'] .';'. $_POST['passengers'] .'per';
}else{
$titleDetails = $_POST['title'] .';'. $_POST['passengers'] .'ppl';
}
/*
* Check to see if everything was filled out properly.
*/
if(date('Ymd') > date('Ymd',strtotime($_POST['startdate']))){
$message = 'You cannot make a booking in the past. Please check your date.';
}
elseif($_POST['starttime'] == ''){
$message = 'You must enter a start time.';
?>
<script type="text/javascript">
<!--
window.document.write('<link type="text/css" rel="stylesheet" href="https://www.therange702.com/parallax/busbooking.css"><h2><span style="color: #ff0000;">Unfortunately, that time is already booked. <br></span></h2><p><em><strong>Please give us a call at (702) 485-3232 and we\'ll get you on the schedule...</strong></em> </p><p> </p><p>Thank you!</p><div style="width:100%; text-align: center;"><a href="https://www.therange702.com/parallax/busbooking.php" >Click Here to Start Over</a></div>');
//-->
</script>
<?php
}
elseif ($_POST['title'] == '') {
$message = 'You must enter your name';
?>
<script type="text/javascript">
<!--
window.document.write('<link type="text/css" rel="stylesheet" href="https://www.therange702.com/parallax/busbooking.css"><h2><span style="color: #ff0000;">There was an error in your submission please be sure to fill out all the required fields. <br>-Thank You</span></h2>');
//-->
</script>
<?php
}
elseif ($_POST['passengers'] == '') {
$message = 'You must enter your name';
?>
<script type="text/javascript">
<!--
window.document.write('<link type="text/css" rel="stylesheet" href="https://www.therange702.com/parallax/busbooking.css"><h2><span style="color: #ff0000;">There was an error in your submission please be sure to fill out all the required fields. <br>-Thank You</span></h2>');
//-->
</script>
<?php
}
elseif ($_POST['email'] == '') {
$message = 'You must enter your email address';
?>
<script type="text/javascript">
<!--
window.document.write('<link type="text/css" rel="stylesheet" href="https://www.therange702.com/parallax/busbooking.css"><h2><span style="color: #ff0000;">There was an error in your submission please be sure to fill out all the required fields. <br>-Thank You</span></h2>');
//-->
</script>
<?php
}
elseif ($_POST['phone'] == '') {
$message = 'You must enter your phone number';
?>
<script type="text/javascript">
<!--
window.document.write('<link type="text/css" rel="stylesheet" href="https://www.therange702.com/parallax/busbooking.css"><h2><span style="color: #ff0000;">There was an error in your submission please be sure to fill out all the required fields. <br>-Thank You</span></h2>');
//-->
</script>
<?php
}
/*
* Check to see if booking is available for this time.
*/
elseif(date('Hms', strtotime($_POST['starttime'] . ':00')) < date('Hms', strtotime($courts[$_POST['calendar']]['starttime'])) || date('Hms', strtotime($endtime1 . ':00')) > date('Hms', strtotime($courts[$_POST['calendar']]['endtime']))){
$message = 'Booking not available during this time. Please select another time.';
?>
<script type="text/javascript">
<!--
window.document.write('<link type="text/css" rel="stylesheet" href="https://www.therange702.com/parallax/busbooking.css"><h2><span style="color: #ff0000;">Unfortunately, that time is already booked. <br></span></h2><p><em><strong>Please give us a call at (702) 485-3232 and we\'ll get you on the schedule...</strong></em> </p><p> </p><p>Thank you!</p>');
//-->
</script>
<?php
}
/*
* Check to see if we are alowed to book this far in advance.
*/
elseif(date('Ymd',strtotime($_POST['startdate'])) > date('Ymd',strtotime('+' . $courts[$_POST['calendar']]['advance'],strtotime($_POST['startdate'])))){
$message = 'You cannot book that far into the future. You can only book ' . $courts[$_POST['calendar']]['advance'] . ' in the future. Please try again.';
//$message .= date('Ymd',strtotime($_POST['startdate'])) . ' > ' . date('Ymd',strtotime('+' . $courts[$_POST['calendar']]['advance'],strtotime($_POST['startdate'])));
}
/*
* Check and see if a booking already exists.
*/
elseif(isTimeBooked($startdate,$_POST['starttime'],$endtime1,$courts[$_POST['calendar']]['id'])){
$message = 'Time already booked. Please select another time.';
?>
<script type="text/javascript">
<!--
window.document.write('<link type="text/css" rel="stylesheet" href="https://www.therange702.com/parallax/busbooking.css"><h2><span style="color: #ff0000;">Unfortunately, that time is already booked. <br></span></h2><p><em><strong>Please give us a call at (702) 485-3232 and we\'ll get you on the schedule...</strong></em> </p><p> </p><p>Thank you!</p>');
//-->
</script>
<?php
/*
* Check and see if distance between location is too far for one trip.
*/
//elseif($distance >= 3.00){
//$message = 'Time chosen will conflict with other bookings due to the distance between locations.';
/*
* Everything is good, submit the event.
*/
}else{
$postargs = createPostArgsJSON($startdate,$_POST['starttime'],$endtime1,$titleDetails,$_POST['location'],$_POST['requests']);
$token = getAccessToken();
$result = sendPostRequest($postargs,$token,$courts[$_POST['calendar']]['id']);
//echo '<pre>' . $result . '</pre>';
$emailaddress = "[email protected]";
$customeremail = $_POST['email'];
$subject = "New Online Bus Booking from The Range 702";
$email = $_POST['email'];
$military_time = $_POST['starttime'];
$standard_time = date('h:i A', strtotime($military_time));
$message="";
$message.="Name: ".$_POST['title']."\r\n";
$message.="E-Mail: ".$_POST['email']."\r\n";
$message.="Phone Number: ".$_POST['phone']."\r\n\r\n";
$message.="\r\n Booking Information:\r\n\r\n";
$message.="Passengers: ".$_POST['passengers']."\r\n";
$message.="Pick Up Date: ".$date."\r\n";
$message.="Pick Up Time: ".$standard_time."\r\n";
$message.="Pick Up Location: ".$_POST['location']."\r\n";
$message=$message."\r\nMessage:\r\n".$_POST['requests'];
mail($emailaddress,$subject,$message,"From: $email" );
mail($customeremail,$subject,$message,"From: [email protected]" );
?>
<script type="text/javascript">
<!--
window.document.write('<link type="text/css" rel="stylesheet" href="https://www.therange702.com/parallax/busbooking.css"><h2><span style="color: #339966;">The shuttle was booked. You will recieve an email confirmation shortly. <br>-Thank You</span></h2>');
//-->
</script>
<?php
}
}
?>