-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserpagetable.php
202 lines (167 loc) · 5.29 KB
/
userpagetable.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
<?php
$maxseats = 5;
$stops = null;
$query = "SELECT * FROM stops";
// selecting the stops
try{
mysqli_autocommit($conn, false);
$res = mysqli_query($conn, $query);
if(!$res){
throw new Exception();
}
mysqli_commit($conn);
} catch(Exception $e){
mysqli_rollback($conn);
mysqli_close($conn);
mysqli_free_result($res);
header("Location: index.php?indexqueryfailed");
exit();
}
// storing the stops and initializing the seats
for($i=0; $i < mysqli_num_rows($res); $i++){
$t = mysqli_fetch_assoc($res);
$stops[$i] = $t['stop'];
$seats[$i] = 0;
}
if(count($stops) > 0){
sort($stops);
}
$query = "SELECT * FROM members";
// selecting all the members
try{
mysqli_autocommit($conn, false);
$res = mysqli_query($conn, $query);
if(!$res){
throw new Exception();
}
mysqli_commit($conn);
} catch(Exception $e){
mysqli_rollback($conn);
mysqli_close($conn);
mysqli_free_result($res);
header("Location: index.php?indexqueryfailed");
exit();
}
// storing all the members and storing the fields in the different vectors
for($i=0; $i < mysqli_num_rows($res); $i++){
$usr = mysqli_fetch_assoc($res);
$min = 0;
$max = 0;
for($k=0; $k < count($stops); $k++){
if(strcasecmp($stops[$k], $usr['Departure']) == 0){
$min = $k;
}
if(strcasecmp($stops[$k], $usr['Arrival']) == 0){
$max = $k;
}
}
$departure[$usr['Name']] = $usr['Departure'];
$arrival[$usr['Name']] = $usr['Arrival'];
$usrseats[$usr['Name']] = $usr['Seats'];
$members[$i] = $usr['Name'];
// from min to max of the vector seats, add the seats prenoted by the member
for($j=$min; $j < $max; $j++){
$seats[$j] += $usr['Seats'];
}
}
for($i=0; $i < count($stops)-1; $i++){
echo '
<br><br><br>
<div class="alert alert-dark" role="alert">';
// checking if the departure or the arrival of the member of the session are the same, if the member has not prenoted these values are null
if((strcasecmp($stops[$i], $departure[$_SESSION['Name']]) == 0)){
echo '<b style="color:red">' .$stops[$i] .'</b>';
} else{
echo '<b>' .$stops[$i] .'</b>';
}
if(strcasecmp($stops[$i+1], $arrival[$_SESSION['Name']]) == 0){
echo '<b> -> </b> <b style="color:red">' .$stops[$i+1] .'</b> <b>, Total Booked Seats: </b>'; //.$seats[$i] .'/' .$maxseats .'</b>';
} else{
echo '<b> -> ' .$stops[$i+1] .', Total Booked Seats: </b>'; //.$seats[$i] .'/' .$maxseats .'</b>';
}
if($seats[$i] == 0){
echo '<b> The shuttle is empty for this segment </b>';
} else{
echo '<b>' .$seats[$i] .'/' .$maxseats .'</b>';
}
echo '
</div>
<table class="table table-striped table-dark">
<thead>
<tr>
<th scope="col">Users</th>
<th scope="col">Booked Seats</th>
</tr>
</thead>
<tbody>
';
// check if the segment is inside the member's travel
for($j=0; $j < count($members); $j++){
if( ((strcasecmp($stops[$i], $departure[$members[$j]]) == 0) || (strcasecmp($stops[$i], $departure[$members[$j]]) > 0)) &&
((strcasecmp($stops[$i+1], $arrival[$members[$j]]) == 0) || (strcasecmp($stops[$i+1], $arrival[$members[$j]]) < 0)) ){
if(strcmp($_SESSION['Name'], $members[$j]) == 0){
echo '
<tr>
<th scope="row"> <p style="color:red">' .$members[$j] .'</p> </th>
';
} else{
echo '
<tr>
<th scope="row">' .$members[$j] .'</th>
';
}
echo '<td>' .$usrseats[$members[$j]] .'</td>';
}
}
echo '
</tbody>
</table>
';
}
echo '<br><br><br>';
if(empty($usrseats[$_SESSION['Name']])){
echo'
<h1 id="journey" style="color: white" class="text-center">Book your journey!</h1>
<div id="prenotation" class="rounded">
<form action="interactions/prenote.php" method="POST">
<div class="form-group col-10">
<label style="color: white">Departure</label>
<input list="ldep" type="text" name="sdep" class="form-control" placeholder="Departure">
<datalist id="ldep">';
for($i=0; $i < count($stops); $i++){
echo '<option value="' .$stops[$i] .'">';
}
echo
'
</datalist>
</div>
<div class="form-group col-10">
<label style="color: white">Arrival</label>
<input list="larr" type="text" name="sarr" class="form-control" placeholder="Arrival">
<datalist id="larr">';
for($i=0; $i < count($stops); $i++){
echo '<option value="' .$stops[$i] .'">';
}
echo
'
</datalist>
</div>
<div class="form-group col-10">
<label style="color: white">#Seats</label>
<input type="number" name="seats" class="form-control" value="1" min="1" max="5">
</div>
<button name="prenote" id="prenoteb" type="submit" class="btn btn-primary" method="POST">Book</button>
</form>
</div>
';
} else{
echo '
<form action="interactions/delete.php" method="POST">
<div class="text-center">
<button name="deletet" id="deleteb" type="submit" class="btn btn-primary btn-lg" method="POST">Delete Travel</button>
</div>
</form>
';
}
mysqli_free_result($res);
?>