-
Notifications
You must be signed in to change notification settings - Fork 0
/
manageUserRestrictions.php
255 lines (224 loc) · 7.91 KB
/
manageUserRestrictions.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
<html>
<head>
<?php require_once 'UI/styleIncludes.php'?>
<title>Manage User Restrictions</title>
<script type="text/javascript">
$(document).ready(function(){
var url = window.location.toString();
url = url.split('?');
if(url[1] != undefined){
tabParameter = url[1].split('=')[1];
tabParameter = '#' + tabParameter;
//remove active
$('.nav.nav-tabs .active').removeClass('active');
$('.tab-content .active').removeClass('in active');
$('.nav.nav-tabs li > a[href="' + tabParameter + '"]').parents('li').addClass('active');
$('.tab-content ' + tabParameter).addClass('in active');
}
});
</script>
</head>
<body>
<?php require_once 'requires.php';
require_once 'UI/navBar.php'; ?>
<?php
if(isset($_POST['DELETE_RESTRICTION_ID']) && $user->type == 'ADMINISTRATOR'){
$result = $user->removeRestrictionRequest($_POST['DELETE_RESTRICTION_ID'], $_POST['RESTRICTION_TABLE']);
if($result){ showBanner('#restrictionDeleted');}
else{ showBanner('#error');}
}
else if (isset($_POST['REJECT_RESTRICTION_ID']) && $user->type == 'SUPER_USER'){
$result = $user->approveRestriction($_POST['REJECT_RESTRICTION_ID'], $_POST['RESTRICTION_TABLE'], false);
if($result){ showBanner('#restrictionRejected');}
else{ showBanner('#error');}
}
else if(isset($_POST['APPROVE_RESTRICTION_ID']) && $user->type == 'SUPER_USER'){
$result = $user->approveRestriction($_POST['APPROVE_RESTRICTION_ID'], $_POST['RESTRICTION_TABLE'], true);
if($result){ showBanner('#restrictionApproved');}
else{ showBanner('#error');}
}
?>
<div class="contents">
<div id="restrictionApproved" class="alert alert-success" style="display: none;">
<strong><i class="fa fa-check"></i>Restriction Approved.</strong>
</div>
<div id="restrictionRejected" class="alert alert-danger" style="display: none;">
<strong><i class="fa fa-times"></i>Restriction Rejected.</strong>
</div>
<div id="restrictionDeleted" class="alert alert-warning" style="display: none;">
<strong><i class="fa fa-trash"></i>Restriction Deleted.</strong>
</div>
<div id="error" class="alert alert-warning" style="display: none;">
<strong><i class="fa fa-times"></i>Error Occured.</strong>
</div>
<h1>Pending Restrictions</h1>
<?php
if($user->type == 'ADMINISTRATOR' || $user->type == 'SUPER_USER'){
?>
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#airline">Airline Restrictions</a></li>
<li><a data-toggle="tab" href="#region">Region Restrictions</a></li>
</ul>
<div class="tab-content">
<div id="airline" class="tab-pane fade in active">
<h3>Airline Restrictions</h3>
<table class="table table-hover">
<thead>
<tr>
<th>User ID</th>
<th>Name</th>
<th>Restricted Airline</th>
<th>Status</th>
<th></th>
<?php if($user->type == 'SUPER_USER'){ echo "<th></th>";}?>
</tr>
</thead>
<tbody>
<?php
/* Create new instance of database manager */
$dbMan = new DatabaseManager();
/* Establish Connection with the database */
if(!$dbMan->establishConnection()){
//database connection error
return;
}
/* Create new request to get all pending airline restrictions */
$request = new Request('getPendingAirlineRestrictions', 'se_Airline_Restrictions');
$request->transformCommand();
/* Execute query */
$results = $dbMan->executeQuery($request);
if($results == null){
//request failed
}
else{
$rows = $results->num_rows;
for ($i = 0 ; $i < $rows ; ++$i){
$results->data_seek($i);
$row = $results->fetch_array(MYSQLI_NUM);
$userId = $row[1];
$restrictionId = $row[0];
$name = "$row[2] $row[3]";
$airline = $row[4];
$status = $row[5];
echo "<tr>";
echo "<td>$userId</td>";
echo "<td>$name</td>";
echo "<td>$airline</td>";
echo "<td>$status</td>";
echo "<td>";
displayRestrictionButtons($user->type, $restrictionId, 'se_Airline_Restrictions');
echo "</td>";
echo "</tr>";
}
if($rows <= 0){
echo "<tr><td>No items</td></tr>";
}
}
?>
</tbody>
</table>
</div>
<div id="region" class="tab-pane fade">
<h3>Region Restrictions</h3>
<table class="table table-hover">
<thead>
<tr>
<th>User ID</th>
<th>Name</th>
<th>Restricted Region</th>
<th>Status</th>
<th></th>
<?php if($user->type == 'SUPER_USER'){ echo "<th></th>";}?>
</tr>
</thead>
<tbody>
<?php
/* Create new instance of database manager */
$dbMan = new DatabaseManager();
/* Establish Connection with the database */
if(!$dbMan->establishConnection()){
//database connection error
return;
}
/* Create new request to get all pending airline restrictions */
$request = new Request('getPendingRegionRestrictions', 'se_Region_Restrictions');
$request->transformCommand();
/* Execute query */
$results = $dbMan->executeQuery($request);
if($results == null){
//request failed
}
else{
$rows = $results->num_rows;
for ($i = 0 ; $i < $rows ; ++$i){
$results->data_seek($i);
$row = $results->fetch_array(MYSQLI_NUM);
$userId = $row[1];
$restrictionId = $row[0];
$name = "$row[2] $row[3]";
$region = $row[4];
$status = $row[5];
echo "<tr>";
echo "<td>$userId</td>";
echo "<td>$name</td>";
echo "<td>$region</td>";
echo "<td>$status</td>";
echo "<td>";
displayRestrictionButtons($user->type, $restrictionId, 'se_Region_Restrictions');
echo "</td>";
echo "</tr>";
}
if($rows <= 0){
echo "<tr><td>No items</td></tr>";
}
}
?>
</tbody>
</table>
</div>
</div>
<?php
if($user->type == 'ADMINISTRATOR'){
?>
<a href="addRestriction.php" class="btn btn-success">Request a new Restriction</a>
<?php
}
}?>
</div>
</body>
</html>
<?php
function displayRestrictionButtons($userType, $restrictionId, $restrictionTable){
$param = '';
if($restrictionTable == 'se_Region_Restrictions'){ $param = 'region';}
else{ $param = 'airline';}
if($userType == 'SUPER_USER'){
echo "<form method='post' action='manageUserRestrictions.php?tab=$param'>";
echo "<input type='hidden' value='$restrictionId' name='REJECT_RESTRICTION_ID' />";
echo "<input type='hidden' value='$restrictionTable' name='RESTRICTION_TABLE' />";
echo "<button type='submit' class='btn btn-danger'>Reject</button>";
echo "</form></td><td>";
echo "<form method='post' action='manageUserRestrictions.php?tab=$param'>";
echo "<input type='hidden' value='$restrictionId' name='APPROVE_RESTRICTION_ID' />";
echo "<input type='hidden' value='$restrictionTable' name='RESTRICTION_TABLE' />";
echo "<button type='submit' class='btn btn-success'>Approve</button>";
echo "</form></td>";
}
if($userType == 'ADMINISTRATOR'){
echo "<form method='post' action='manageUserRestrictions.php?tab=$param'>";
echo "<input type='hidden' value='$restrictionId' name='DELETE_RESTRICTION_ID' />";
echo "<input type='hidden' value='$restrictionTable' name='RESTRICTION_TABLE' />";
echo "<button type='submit' class='btn btn-danger'>Delete</button>";
echo "</form>";
}
}
function showBanner($selector){
echo <<<_END
<script type="text/javascript">
$(document).ready(function(){
$('$selector').show();
});
</script>
_END;
}
?>