-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisitorList.php
202 lines (160 loc) · 7.87 KB
/
visitorList.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 include('session.php'); ?>
<?php include("config.php"); ?>
<?php
if($_SESSION['user_type'] != "ADMIN") {
header("Location: index.php");
}
?>
<?php
if($_SERVER["REQUEST_METHOD"] == "GET") {
// username and password sent from form
if(isset($_GET['deleteUser'])) {
$sql = "DELETE FROM User WHERE Username = '" . $_GET['deleteUser'] . "'";
$result = mysqli_query($db,$sql);
$logssql = "DELETE FROM Visit WHERE Username = '" . $_GET['deleteUser'] . "'";
$logsresult = mysqli_query($db,$logssql);
if($result && $logsresult) {
echo "<script type='text/javascript'>if(!alert(\"Successfully deleted user: " . $_GET['deleteUser'] . "\")) document.location = 'visitorList.php';</script>";
} else {
echo "<script type='text/javascript'>if(!alert(\"Error deleting user: " . $_GET['deleteUser'] . "\")) document.location = 'visitorList.php';</script>";
}
} else if(isset($_GET['deleteLogs'])) {
$sql = "DELETE FROM Visit WHERE Username = '" . $_GET['deleteLogs'] . "'";
$result = mysqli_query($db,$sql);
if($result == true) {
echo "<script type='text/javascript'>if(!alert(\"Successfully deleted logs for user: " . $_GET['deleteLogs'] . "\")) document.location = 'visitorList.php';</script>";
} else {
echo "<script type='text/javascript'>if(!alert(\"Error: Could not delete logs for user: " . $_GET['deleteLogs'] . "\")) document.location = 'visitorList.php';</script>";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<?php include("head.php"); ?>
<body>
<?php include("navbar.php"); ?>
<section>
<div class="container">
<div class="row text-center title-space">
<div class="col-md-12">
<h4>All Visitors In System</h4>
<br>
</div>
</div> <!-- End Row -->
<div class ="row">
<div class = "col-md-12">
<div class="text-center">
<button class="btn btn-primary style-bkg" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
🔍 Search Table
</button>
</div>
<div class="collapse" id="collapseExample">
<form class="form-horizontal" action="visitorList.php" method = "GET">
<fieldset>
<br>
<input id="SEARCH" name="SEARCH" value="true" type = "hidden">
<div class="row rowspace">
<!-- Select Basic -->
<div class="col-md-2 offset-md-3">
<p>Search Username</p>
</div>
<!-- Search input-->
<div class="col-md-4">
<input id="inputUsername" name="inputUsername" type="search" placeholder="Search Username" class="form-control input-md">
</div>
</div> <!-- End Row -->
<div class="row rowspace">
<!-- Select Basic -->
<div class="col-md-2 offset-md-3">
<p>Search Email</p>
</div>
<!-- Search input-->
<div class="col-md-4">
<input id="searchEmail" name="searchEmail" type="search" placeholder="Search Email" class="form-control input-md">
</div>
</div> <!-- End Row -->
<div class="row rowspace">
<!-- Select Basic -->
<div class="col-md-2 offset-md-3">
<p>Search Visits</p>
</div>
<!-- Search input-->
<div class="col-md-2">
<input id="searchVisitsFrom" name="searchVisitsFrom" type="search" placeholder="Start Value" class="form-control input-md">
</div>
<!-- Search input-->
<div class="col-md-2">
<input id="searchVisitsTo" name="searchVisitsTo" type="search" placeholder="End Value" class="form-control input-md">
</div>
</div> <!-- End Row -->
<br>
<div class="row">
<!-- Submit Button -->
<div class="col-md-6 offset-md-5">
<input class="btn btn-primary style-bkg btn-md" type="submit" width="100%" value="Search Visitors">
</div>
</div>
</fieldset>
</form>
</div> <!-- End Collapse Example -->
</div> <!-- End Column -->
</div> <!-- End Row -->
<br>
<div class ="row">
<div class = "col-md-12">
<div class="property-table-scroll">
<table class="table table-striped table-sm sortable">
<thead class="thead-dark">
<tr>
<th scope="col">Delete Visitor</th>
<th scope="col">Delete Log History</th>
<th scope="col">Username</th>
<th scope="col">Email</th>
<th scope="col">Logged Visits</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM User WHERE UserType = 'VISITOR'";
if (isset($_GET['SEARCH'])) {
if (isset($_GET['inputUsername']) && $_GET['inputUsername'] != NULL) {
$query .= " AND Username LIKE '%" . mysqli_real_escape_string($db, $_GET['inputUsername']) . "%'";
}
if (isset($_GET['searchEmail']) && $_GET['searchEmail'] != NULL) {
$query .= " AND Email LIKE '%" . mysqli_real_escape_string($db, $_GET['searchEmail']) . "%'";
}
if (isset($_GET['searchVisitsFrom']) && $_GET['searchVisitsFrom'] != NULL) {
$visitto = mysqli_real_escape_string($db, (isset($_GET['searchVisitsTo']) && $_GET['searchVisitsTo'] != NULL) ? $_GET['searchVisitsTo'] : $_GET['searchVisitFrom']);
if ($_GET['searchVisitFrom'] <= 0 && $visitto >= 0) {
$query .= " AND Username NOT IN (SELECT Username FROM Visit GROUP BY Username HAVING COUNT(Username) < " . mysqli_real_escape_string($db, $_GET['searchVisitsFrom']) . " OR COUNT(Username) > " . $visitto . ")";
} else {
$query .= " AND Username IN (SELECT Username FROM Visit GROUP BY Username HAVING COUNT(Username) >= " . mysqli_real_escape_string($db, $_GET['searchVisitsFrom']) . " AND COUNT(Username) <= " . $visitto . ")";
}
}
}
$query .= " ORDER BY Username";
//echo "<br>" . $query . "<br>";
$result = mysqli_query($db, $query);
while ($row = mysqli_fetch_array($result)) {?>
<tr>
<td class="link-color"><a href=<?php echo "visitorList.php?deleteUser=" . $row['Username'];?>>Delete</a></td>
<td class="link-color"><a href=<?php echo "visitorList.php?deleteLogs=" . $row['Username'];?>>Delete</a></td>
<td><?php echo $row['Username'];?></td>
<td><?php echo $row['Email'];?></td>
<td><?php
$visitsql = "SELECT COUNT(*) FROM Visit WHERE Username = '" . $row['Username'] . "'";
$visitresult = mysqli_query($db, $visitsql);
$visitrow = mysqli_fetch_array($visitresult);
echo $visitrow['COUNT(*)'];?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div> <!-- End Property Table Wrapper -->
</div> <!-- End Column -->
</div> <!-- End Row -->
</div> <!-- End Container -->
</section>
</body>
</html>