-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
161 lines (146 loc) · 5.89 KB
/
admin.php
File metadata and controls
161 lines (146 loc) · 5.89 KB
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
<?php include 'header.php'; ?>
<?php require_once "php/User.php"; ?>
<?php require_once "php/Ship.php"; ?>
<?php require_once "php/Station.php"; ?>
<?php require_once "php/Ferry.php"; ?>
<?php require_once 'securearea.php'; ?>
<?php require_once 'adminzone.php'; ?>
<div class="container">
<div class="row">
<div class="col">
<h2>Add new admin</h2>
<div class="form-group">
<label>Pick User</label>
<select class="form-control" id="selectAdmin" required>
<?php
$User = new User();
$allUsers = $User->getAllUsers();
for($i = 0; $i < count($allUsers); $i++){
if($allUsers[$i]["is_admin"] == false){
//Insert Station Options
?><option value="<?php echo $allUsers[$i]['userid']; ?>"><?php echo $allUsers[$i]['firstname'] . " " . $allUsers[$i]['lastname']; ?></option>
<?php } ?>
<?php
}
?>
</select>
<button id="addAdminBtn" class="btn btn-primary">Make Admin</button>
</div>
</div>
<div class="col">
<h2>Add new station</h2>
<div class="form-group">
<label>Station Name</label>
<input class="form-control" type="text" id="stationNameInput" required>
<label>Station Location</label>
<input class="form-control" type="text" id="stationLocationInput" required>
<button id="addStationBtn" class="btn btn-primary">Add Station</button>
</div>
</div>
</div>
<div class="row">
<div class="col">
<h2>Add new ship</h2>
<div class="form-group">
<label>Ship Name</label>
<input class="form-control" type="text" id="shipNameInput" required>
<label>Ship Capacity</label>
<input class="form-control" type="text" id="shipCapacityInput" required>
<button id="addShipBtn" class="btn btn-primary">Add Ship</button>
</div>
</div>
<div class="col">
<h2>Add new trip</h2>
<div class="form-group">
<label>Departure Time</label>
<input class="form-control" type="date" id="departDateInput" required>
<input class="form-control" type="time" id="departTimeInput" required>
<label>Arrival Time</label>
<input class="form-control" type="date" id="arrivalDateInput" required>
<input class="form-control" type="time" id="arrivalTimeInput" required>
<label>Time in Port</label>
<input class="form-control" type="int" id="timeInPortInput" required>
<label>Select Departure Port</label>
<select class="form-control" id="departPortSelected">
<?php
$Station = new Station();
$stationOptions = $Station->getAllStations();
for($i = 0; $i < count($stationOptions); $i++){
//Insert Station Options
?><option value="<?php echo $stationOptions[$i]['stationid']; ?>"><?php echo $stationOptions[$i]['stopname']; ?></option>
<?php
}
?>
</select>
<label>Select Arrival Port</label>
<select class="form-control" id="arrivalPortSelected">
<?php
$Station = new Station();
$stationOptions = $Station->getAllStations();
for($i = 0; $i < count($stationOptions); $i++){
//Insert Station Options
?><option value="<?php echo $stationOptions[$i]['stationid']; ?>"><?php echo $stationOptions[$i]['stopname']; ?></option>
<?php
}
?>
</select>
<label>Select Ship</label>
<select class="form-control" id="shipSelected">
<?php
$Ship = new Ship();
$ships = $Ship->getAllShips();
for($i = 0; $i < count($ships); $i++){
?><option value="<?php echo $ships[$i]['shipid']; ?>"><?php echo $ships[$i]['shipname']; ?></option>
<?php
}
?>
</select>
<button id="addTripBtn" class="btn btn-primary">Add</button>
</div>
</div>
</div>
</div>
<script>
document.getElementById("addAdminBtn").addEventListener("click", addAdmin);
document.getElementById("addStationBtn").addEventListener("click", addStation);
document.getElementById("addShipBtn").addEventListener("click", addShip);
document.getElementById("addTripBtn").addEventListener("click", addTrip);
function addAdmin(){
var selectElement = document.getElementById("selectAdmin");
var selectedUser = selectElement.options[selectElement.selectedIndex].value;
httpGetAsync("api/addAdmin.php?id="+selectedUser, function(response){
console.log(response);
});
}
function addStation(){
var stationNameInput = document.getElementById("stationNameInput").value;
var stationLocationInput = document.getElementById("stationLocationInput").value;
httpGetAsync("api/addStation.php?name="+stationNameInput+"&loc="+stationLocationInput, function(response){
console.log(response);
});
}
function addShip(){
var shipName = document.getElementById("shipNameInput").value;
var shipCap = document.getElementById("shipCapacityInput").value;
httpGetAsync("api/addShip.php?name="+shipName+"&cap="+shipCap, function(response){
console.log(response);
});
}
function addTrip(){
var departDate = document.getElementById("departDateInput").value;
var departTime = document.getElementById("departTimeInput").value;
var arrivalDate = document.getElementById("arrivalDateInput").value;
var arrivalTime = document.getElementById("arrivalTimeInput").value;
var timeInPort = document.getElementById("timeInPortInput").value;
alert(document.getElementById("departDateInput").valueAsNumber);
var srcStop = document.getElementById("departPortSelected").value;
var dstStop = document.getElementById("arrivalPortSelected").value;
var shipId = document.getElementById("shipSelected").value;
var departTimestamp = document.getElementById("departDateInput").valueAsNumber + document.getElementById("departTimeInput").valueAsNumber;
var arrivalTimestamp = document.getElementById("arrivalDateInput").valueAsNumber + document.getElementById("arrivalTimeInput").valueAsNumber;
httpGetAsync("api/addTrip.php?dep="+departTimestamp+"&arr="+arrivalTimestamp+"&tip="+timeInPort+"&src="+srcStop+"&dst="+dstStop+"&ship="+shipId, function(response){
console.log(response);
});
}
</script>
<?php include 'footer.php'; ?>