-
Notifications
You must be signed in to change notification settings - Fork 1
/
newPlane.php
55 lines (48 loc) · 1.91 KB
/
newPlane.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
<?php
require("ceckUser.php");
require ("SQLconnect.php");
$SQL = "SELECT callsign FROM planes";
$res = $conn->query($SQL);
$callsignList = Array();
while($callsign = $res->fetch_array())
array_push($callsignList,$callsign[0]);
$SQL='SELECT airport FROM airports';
$res = $conn->query($SQL);
$airportList = Array();
while($airport = $res->fetch_array()){
array_push($airportList, $airport[0]);
}
$hashedIP = hash("sha256",$_SERVER['REMOTE_ADDR']);
$stmt = $conn->prepare('SELECT selected_control_zone , username FROM atc_login_data WHERE hashedIP = ?');
$stmt->bind_param("s",$hashedIP);
$stmt->execute();
$res = $stmt->get_result();
$user = $res -> fetch_object();
$selected_control_zone = $user->selected_control_zone;
$username = $user->username;
if(!in_array($_REQUEST['destination'],$airportList))
echo('<script>alert("Invalid airport, please select an airport from the dropdown list")</script>');
else if(in_array($_REQUEST['callsign'], $callsignList))
echo('<script>alert("Another user is already using this callsign")</script>');
else {
$stmt = $conn->prepare('
INSERT INTO planes (callsign, aircraft, clearance, current_control_zone,origin,destination,last_time_edited,created_by)
VALUES ( ? , ? , ? , ? , ? , ? , UNIX_TIMESTAMP(), ?);
');
$stmt->bind_param(
"sssssss",
$_REQUEST['callsign'],
$_REQUEST['plane'],
$_REQUEST['clearance'],
$selected_control_zone,
$selected_control_zone,
$_REQUEST['destination'],
$username
);
$stmt->execute();
$res=$stmt->get_result();
}
mysqli_close($conn);
echo('<script>window.location.replace("ATCplaneList.php")</script>');
exit();
?>