-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrum_booking.php
388 lines (372 loc) · 16.3 KB
/
drum_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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<?php
// TODO: Allow the user too check a box too say that they are already a current user, or check if they are currently logged in
// TODO: Tidy up functions to make this more readable and legable, also try turn this into a class
error_reporting(0);
//This includes the connect.inc file, that connects to the database
include('INC/connect.inc');
//This connects to the php code that will send an email when called
include('INC/mailsend.php');
//This connects to the database
$db;
//This starts the session
session_start();
include_once 'header.php';
//This is the sql for getting what days are open for lessons
$sql="SELECT Day, Time FROM days_teaching WHERE Booked IS NULL";
//This is creating the variable to connect to the database and then put in the sql
$result=mysqli_query($db, $sql);
//This creates the array for the times that are open and free
$ARR_BOOK = [];
//This creats the days that i am currently teaching
$ARR_DAYS = ['Tues', 'Fri', 'Sat'];
//This loops through the data that was collected about what days i have available, and then adds them to the array
while($row = mysqli_fetch_array($result)){
$ARR_BOOK[] = $row;
}
// TODO: Make this page join into a success page
//This checks if the parents are in the database and if they are in the database then it will then grab the ID of that parent and return it
function ParentCheck($parentfn, $parentln, $email, $db){
$sql_parent_check = "SELECT ParentID FROM parents WHERE ParentFN = '$parentfn' AND ParentLN = '$parentln' AND Contact_Email = '$email'";
$resultp = mysqli_query($db, $sql_parent_check);
if(mysqli_num_rows($resultp)==1){
$rowp = mysqli_fetch_array($resultp);
$PID = $rowp['ParentID'];
echo "Hello";
return $PID;
} else {
}
}
//This checks if the student of the parent is in the database, and if it is then it will grab its ID, and then run the applicatoin Insert function
//If the student is not found it will add the student then run through this code again
function StudentCheck($studentfn, $studentln, $PID, $time, $studentage, $studentgender, $db){
$sql_student_check = "SELECT StudentID FROM students WHERE StudentFN = '$studentfn' AND StudentLN = '$studentln' AND ParentID = $PID";
$resultc = mysqli_query($db, $sql_student_check);
echo "Student is being checked";
if(mysqli_num_rows($resultc)==1){
echo "Student Has Been Checked";
$rowc = mysqli_fetch_array($resultc);
$SID = $rowc['StudentID'];
ApplicationInsert($PID, $SID, $time, $db);
} else {
echo "Student is being added 1";
StudentAdd($PID, $studentfn, $studentln, $studentage, $studentgender, $db);
}
}
//This adds the student to the data base and then runs the student check funciton
function StudentAdd($PID, $studentfn, $studentln, $studentage, $studentgender, $db){
$sql_student_add = "INSERT INTO students (StudentID, ParentID, StudentFN, StudentLN, Student_Age, Student_Gender, ID) VALUES (NULL, $PID, '$studentfn', '$studentln', $studentage, '$studentgender', NULL)";
echo "$sql_student_add";
if(mysqli_query($db, $sql_student_add)){
echo "Student Has Been added";
StudentCheck($studentfn, $studentln, $PID, $time, $studentage, $studentgender, $db);
}
}
//This adds an applicatoin to the applicatoin table of the data base and then also sends an email out confirming the booking
function ApplicationInsert($PID, $SID, $time, $db){
$sql = "INSERT INTO applications (APP_ID, ParentID, StudentID, Time, Status) VALUES (NULL, $PID, $SID, '$time', 'Pending')";
if(mysqli_query($db, $sql)){
echo "<script>location='success.php'</script>";
$body = "Thank You for Sending through the Application for $time. The application is currently in the Pending Status and you will be notified when this changes.";
Mail::sendMail('Booking Application', $body, $email);
} else {
echo "<script>location='error.php'</script>";
}
}
//This adds a user too the database if the parent is not currently a registered parent in the database
function UserAdd($parentfn, $parentln, $email, $phone, $db){
echo "useradd";
$username = $parentfn.'.'.$parentln; //Creating a username for the user
$pass = rand(); //generating a random number for the password
$passh = hash("sha256", $pass); //hashing the password
$random = rand(); //Creating a random number for the verification link that will be sent too the email
$hash = hash("sha256", $random); //hashing the verification link
$sqluser_add = "INSERT INTO loginform (ID, User, Email, Avatar, Verifybit, Pass) VALUES (NULL, '$username', '$email', 'image/default.jpg', '$hash', '$passh')";
echo "$sqluser_add"; //Inserting the user into the databse
if(mysqli_query($db, $sqluser_add)){
echo "Hello2";
$sql_user_search = "SELECT * FROM loginform WHERE Email='$email' "; //Grabing the id of the newly created user
$result=mysqli_query($db, $sql_user_search);
$row = mysqli_fetch_array($result);
$UID = $row['ID'];//setting the users id = $UID variable
$sql_parent_add = "INSERT INTO parents (ID, ParentID, ParentFN, ParentLN, Contact_Email, PH) VALUES ($UID, NULL, '$parentfn', '$parentln', '$email', $phone)"; //inserting the parent into the databse connected to the UID of the login account so they are linked.
if(mysqli_query($db, $sql_parent_add)){
$unamepass = array($username, $pass, $hash); //Creating an array too return back
return $unamepass;
}
}
}
//This uses variable variables to create the different div ID and Classes and other data required
function CardCreator($DATA){
//$Data[0] stands for the day, e.g. Tues, Fri, Sat, and this just adds count too it e.g. countSAT, countFRI
${'count'.$DATA[0]} += 1;
//This creates the variables with their information, and then adds it too a variable to be stored into an array
//This creates the Time of the available slot tag
${$DATA[0].${'count'.$DATA[0]}} = $DATA[1];
$Day1 = ${$DATA[0].${'count'.$DATA[0]}};
//This creats a variable to make it visible
${$DATA[0].'V'.${'count'.$DATA[0]}} = "visible";
$DayV1 = ${$DATA[0].'V'.${'count'.$DATA[0]}};
//This creates the available tag
${$DATA[0].'A'.${'count'.$DATA[0]}} = "Available";
$DayA1 = ${$DATA[0].'A'.${'count'.$DATA[0]}};
//This puts all of the data into an array
$daydata = array($Day1, $DayV1, $DayA1);
//This returns the array
return $daydata;
}
//This code will run when the submit button is pressed on the form, and all the inputs that are required are filled.
if(isset($_POST['submit'])){
//This sets all the Post data to a variable so it will become ready to be used
$time = $_POST['my_fld'];
$studentfn = $_POST['StudentF'];
$studentln = $_POST['StudentL'];
$studentage = $_POST['StudentAge'];
$studentgender = $_POST['Gender'];
$parentfn = $_POST['ParentF'];
$parentln = $_POST['ParentL'];
$email = strtolower($_POST['ContactEmail']);
$phone = $_POST['Ph'];
//This checks for the parent to see if the parent is in the database, and then checks for the student, and then sends an email out
if(null !== ParentCheck($parentfn, $parentln, $email, $db)){
$PID = ParentCheck($parentfn, $parentln, $email, $db);
StudentCheck($studentfn, $studentln, $PID, $time, $studentage, $studentgender, $db);
} else {
//If the parent was not found this code will be run and it will create a user, and then repeat the code above, and then send the user his/her account deatils
$userarray = UserAdd($parentfn, $parentln, $email, $phone, $db);
$username = $userarray[0];
$pass = $userarray[1];
$hash = $userarray[2];
if(null !== ParentCheck($parentfn, $parentln, $email, $db)){
// TODO: Set up correctly with new database systems.
// TODO: Make Username lowecase
// TODO: Set up the student acount creation
$PID = ParentCheck($parentfn, $parentln, $email, $db);
StudentCheck($studentfn, $studentln, $PID, $time, $studentage, $studentgender, $db);
$applicationemail = "
<html><body>
<br>
<br>
Thanks for sending through your Application for lessons at $time!
<br>
Your Account has been created, but you cant login until you verify your email.
<br>
Your Account details are below aswell as your email Verification link.
<br>
<br>
<br>
<table rules='all' style='border-color: #666;' cellpadding='10'>
<tr style='background: #2980b9;'><td></td><td></td>
<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>$username</td></tr>
<tr><td><strong>Email:</strong> </td><td>$email</td></tr>
<tr style='background: #eee;'><td><strong>Password:</strong> </td><td>$pass</td></tr>
<tr><td><strong>Verification:</strong> </td><td>digitech.cas.school.nz:8080/declan/verify.php?email='$email'&hash=$hash</td></tr>
<tr style='background: #2980b9;'><td></td><td></td>
</table>
</body></html>
";
Mail::sendMail('Verification Email', $applicationemail, $email);
}
}
}
?>
<!DOCTYPE html>
<html>
<header>
<body>
<div class="spinner-wrapper">
<div class="spinner">
<div class="rect1"></div>
<div class="rect2"></div>
<div class="rect3"></div>
<div class="rect4"></div>
<div class="rect5"></div>
</div>
</div>
<!-- This is the header of the page, with the first child being the bg image
followed on by the logo, and then the burger menu and motto. -->
<div class="header-bg"></div>
<nav>
<a href="index.php">
<img src="img/headinglogo.png" />
</a>
<a href="javascript:void(0)" id="slide-toggle" class="icon ion-md-menu"></a>
<div class="motto">
<h1>Scroll Down For Booking!</h1>
</div>
</nav>
<div class="scrolldown">
<p>Scroll Down for More Infomation</p>
<a href="javascript:void(0)" id= "scrolldownarrow1" class="icon ion-md-arrow-dropdown"></a>
<a href="javascript:void(0)" id= "scrolldownarrow1" class="icon ion-md-arrow-dropdown"></a>
</div>
</header>
<!-- This is the heading above each card -->
<div class="headings">
<h1>Want Lessons?</h1>
</div>
<!-- This is the darck background behind the form-->
<div class="bg-model" style="display: none;">
<!-- This is the white box where the form is-->
<div class="model-content" style="display: none;">
<!-- This is the content inside of the white form box -->
<div class="model-content-inner">
<!-- This is the form -->
<form id="Booking_form" method="POST" action="#">
<div class="form_input">
<!-- This is the X close button on the top right hand corner -->
<div class="formhead">
<a href="javascript:void(0)" id="form-close" class="icon ion-md-close-circle-outline"></a>
<h2>Please Fill Out</h2>
</div>
<!-- This is the form for the person to fill out -->
<input type="hidden" name="my_fld" id="my_fld" value="" />
<input type="text" name="StudentF" placeholder="Childs First Name" required>
<input type="text" name="StudentL" placeholder="Childs Last Name" required>
<input type="text" name="StudentAge" placeholder="Childs Age" required>
<input type="radio" name="Gender" value="Male">
<label for="GenderB">Boy</label>
<input type="radio" name="Gender" value="Female">
<label for="GenderG">Girl</label>
<input type="radio" name="Gender" value="Other">
<label for="GenderO">Other</label>
<input type="text" name="ParentF" placeholder="Parents First Name" required>
<input type="text" name="ParentL" placeholder="Parents Last Name" required>
<input type="email" name="ContactEmail" placeholder="Contact Email" required>
<input type="text" name="Ph" placeholder="Phone Number" required>
<input type="submit" name="submit" value="Submit!">
</div>
</form>
</div>
</div>
</div>
<!-- This ist he divs for the differnet days, there are 3 currently -->
<div class="days">
<div class="drums_day1">
<div class="date_title">
<h1>Tuesday<h1>
</div>
<!-- This uses a function called CardCreator to create the variables and add them into an array
ready to be used to below to create a card using the Information that had been gathored from
the database -->
<?php
$counting = 0;
foreach ($ARR_BOOK as $DATA) {
if($DATA[0] === 'Tues'){
$dayarray = CardCreator($DATA); //This grabs all of the available tuesday times for lessons
$day1 = $dayarray[0]; //This gets the id for the card (Time of lesson)
$dayv1 = $dayarray[1]; //This sets the visibility of the card
$daya1 = $dayarray[2]; //This sets the availability text of the cards
$counting += 1;
echo "<div class='book_card' id= $day1 style='visibility: $dayv1'>";
echo "<a class='booklnk' href='#' data-timeslot= $day1>";
echo "<p1>$day1</p1>";
echo "<p2>$daya1</p2>";
echo "</a>";
echo "</div>";
}
}
if($counting < 1){ //If there is no available tuesday, it allows you too ask to be added too the waiting list
echo "<div class='book_card' id= Tues1 style='visibility: visible'>";
echo "<a class='booklnk' href='#' data-timeslot= WaitingT>";
echo "<p1>None Available</p1>";
echo "<p2>Join the Waiting List!</p2>";
echo "</a>";
echo "</div>";
}
?>
</div>
<div class="drums_day2">
<div class="date_title">
<h1>Friday<h1>
</div>
<?php
//This works the same as tuesday except for Fridays
$counting = 0;
foreach ($ARR_BOOK as $DATA) {
if($DATA[0] === 'Fri'){
$dayarray = CardCreator($DATA);
$day1 = $dayarray[0];
$dayv1 = $dayarray[1];
$daya1 = $dayarray[2];
$counting += 1;
echo "<div class='book_card' id= $day1 style='visibility: $dayv1'>";
echo "<a class='booklnk' href='#' data-timeslot= $day1>";
echo "<p1>$day1</p1>";
echo "<p2>$daya1</p2>";
echo "</a>";
echo "</div>";
}
}
if($counting < 1){
echo "<div class='book_card' id= Fri1 style='visibility: visible'>";
echo "<a class='booklnk' href='#' data-timeslot= WaitingF>";
echo "<p1>None Available</p1>";
echo "<p2>Join the Waiting List!</p2>";
echo "</a>";
echo "</div>";
}
?>
</div>
<div class="drums_day3">
<div class="date_title">
<h1>Saturday<h1>
</div>
<?php
//This works the same as tuesday and friday except it does it for saturday
$counting = 0;
foreach ($ARR_BOOK as $DATA) {
if($DATA[0] === 'Sat'){
$dayarray = CardCreator($DATA);
$day1 = $dayarray[0];
$dayv1 = $dayarray[1];
$daya1 = $dayarray[2];
$counting += 1;
echo "<div class='book_card' id= $day1 style='visibility: $dayv1'>";
echo "<a class='booklnk' href='#' data-timeslot= $day1>";
echo "<p1>$day1</p1>";
echo "<p2>$daya1</p2>";
echo "</a>";
echo "</div>";
}
}
if($counting < 1){
echo "<div class='book_card' id= Sat1 style='visibility: visible'>";
echo "<a class='booklnk' href='#' data-timeslot= WaitingS>";
echo "<p1>None Available</p1>";
echo "<p2>Join the Waiting List!</p2>";
echo "</a>";
echo "</div>";
}
?>
</div>
</div>
<?php include_once 'footer.php';
?>
</body>
<!-- This is the card, and the card txt, and the link to the next page -->
<!-- This is the javascript that is used to make the animations work -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<script src="JS/index_functions.js">
</script>
<script>
$('.booklnk').click(function(e){
//prevent default link click
e.preventDefault();
//get the data from the link that was clicked
var timeslot = $(this).data('timeslot');
//modify the form so when the user submits it the field is sent
//tip, you can change the input from type="text" to type="hidden"
//so the user cannot see it, but for example purpose it's easier to show it.
$('#my_fld').val(timeslot);
$('.bg-model').fadeIn(1000);
$('.model-content').show(1000);
return false; //helps prevent double click link access
});
$('#form-close').click(function(e){
e.preventDefault();
$('.bg-model').fadeOut(500);
$('.model-content').fadeOut(300);
});
</script>
</html>