/
scheduleMod.php
111 lines (99 loc) · 2.45 KB
/
scheduleMod.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
<?php
require "classes.php";
function createConnection(){
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "fireDept";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
return $conn;
}
function closeConnection($conn){
$conn->close();
}
function executeQueryString($queryString)
{
$conn = createConnection();
if ($conn->query($queryString) === TRUE)
{
//echo "<br>New record created successfully<br>";
return true;
}
else
{
echo "Error: " . $queryString . "<br>" . $conn->error;
return false;
}
closeConnection($conn);
}
function insertScheduleTimeslot($schedule_timeslot){
$timeslot = $schedule_timeslot->getTimeslot();
$firemanId = $timeslot->getFirefighter()->getId();
$startDate = $timeslot -> getStartTime();
$endDate = $timeslot -> getEndTime();
$queryString = "call schedule_timeslot_insert('".$startDate."','".$endDate."',".$firemanId.");";
return executeQueryString($queryString);
}
function insertFirefighter($firstName, $lastName, $email, $phone, $secondaryPhone, $provider){
$queryString = "call firefighter_insert(" .
"'".
$firstName.
"'".
", ".
"'".
$lastName.
"'".
", ".
"'".
$email.
"'".
", ".
"'".
$phone.
"'".
", ".
"'".
$secondaryPhone.
"'".
", ".
"'".
$provider.
"'".
"); ";
$successfulFirefighterInsert = executeQueryString($queryString);
return "Firefighter:<br> FirstName:".$firstName."<br> Last Name: ".$lastName."<br>Successful:".$successfulFirefighterInsert."<br><br>";
}
function isValidFiremanId($id){
return true;
}
function isValidTimeslotId($id){
return true;
}
function isDateTime($dateTime){
return true;
}
$id = $_REQUEST["id"];
if($id == "0")
{
$firefighter_json = $_REQUEST["firefighter_json"];
$firefighter = Firefighter::getFirefighterFromJson($firefighter_json);
$fname = $firefighter -> getFirstName();
$lname = $firefighter -> getLastName();
$email = $firefighter -> getEmail();
$phone = $firefighter -> getPhone();
$secondaryPhone = $firefighter ->getSecondaryPhone();
$carrier = $firefighter ->getCarrier();
echo insertFirefighter($fname, $lname, $email, $phone, $secondaryPhone, $carrier);
}
else
{
$schedule_timeslot_json = $_REQUEST["schedule_timeslot_json"];
$schedule_timeslot = ScheduleTimeslot::getScheduleTimeslotFromJson($schedule_timeslot_json);
echo insertScheduleTimeslot($schedule_timeslot);
}
?>