-
Notifications
You must be signed in to change notification settings - Fork 4
/
admin_index.php
209 lines (185 loc) · 6.63 KB
/
admin_index.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
<?php
include('include/head.php');
include('include/global.php');
if(isset($_POST['submit'])){
?>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Biometric Attendance - Administrator</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<?php
$keyword = $_POST['search'];
if(!empty($keyword)){
$sql = "SELECT * FROM users WHERE username='".$keyword."'";
$result = mysql_query($sql);
if(mysql_num_rows($result)> 0){
while($row = mysql_fetch_array($result)){
echo "<div class='container'"
."<div class='row'>"
."<div class='col-md-12'>"
."<h2 class='text-center'>Match Found</h2>"
."<table class='table table-bordered table-hover'>"
."<thead>"
."<tr>"
."<th class='col-md'>Full Name</th>"
."<th class='col-md'>Username</th>"
."<th class='col-md'>Email</th>"
."<th class='col-md'>Department</th>"
."</tr>"
."</thead>"
."<tbody>";
echo "<tr>"
."<td>".$row['fullname']."</td>"
."<td>".$row['username']."</td>"
."<td>".$row['email']."</td>"
."<td>".$row['department']."</td>"
."</tr>";
echo
"</tbody>"
."</table>"
."</div>"
."</div>"
."</div>";
echo " <br/>Click here to <a href='admin_index.php'>go back.</a>";
}
}else {
echo "<div class='form'>
<h3>User does not exist.</h3>
<br/>Click here to <a href='admin_index.php'>go back.</a></div>";
}
}
}
else{
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin|Users</title>
<?php include('include/head.php'); ?>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Biometric Attendance - Administrator</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container">
<h2 class="text-center display-3 text-muted text-bold">Users</h2>
</div>
<div class="row">
<div class="container">
<div class="col-md-4"></div>
<div class="col-md-4"></div>
<div class="col-md-4">
<form method="post" class="">
<div class="container">
<div class="form-group">
<input type="text" name="search" class="pr-3" placeholder="Search" aria-label="Search">
<input type="submit" name="submit" value="Search" class="btn btn-success">
</div>
</div>
</form>
</div>
</div>
</div>
<div class="container">
<div class="container my-2">
<a class="btn btn-info " href="<?php $base_path ?>registration.php">Create New User +</a>
</div>
<?php
$sql = "SELECT * FROM `users`";
$result = mysql_query($sql) or die("Query failed");
$arr = array();
$i = 0;
while ($row = mysql_fetch_array($result)) {
$arr[$i] = array(
'id' => $row['id'],
'fullname' => $row['fullname'],
'username' => $row['username'],
'email' => $row['email'],
'password' => $row['password'],
'department' => $row['department']
);
$i++;
}
if (count($arr) > 0) {
echo "<div class='row'>"
."<div class='col-md-12'>"
."<table class='table table-bordered table-hover '>"
."<thead>"
."<tr>"
."<th class='col-md'>id</th>"
."<th class='col-md'>Full Name</th>"
."<th class='col-md'>Username</th>"
."<th class='col-md'>Email</th>"
."<th class='col-md'>Department</th>"
."<th class='col-md'>Modify</th>"
."</tr>"
."</thead>"
."<tbody>";
foreach ($arr as $row) {
echo "<tr>"
."<td>".$row['id']."</td>"
."<td>".$row['fullname']."</td>"
."<td>".$row['username']."</td>"
."<td>".$row['email']."</td>"
."<td>".$row['department']."</td>"
."<td><a href='".$base_path."read.php?id={$row['id']}' class='btn btn-warning'>View</a> | "
."<a href='".$base_path."update.php?id={$row['id']}' class='btn btn-primary'>Edit</a> | "
."<a href='#' onclick='delete_user({$row['id']})' class='btn btn-danger'>Delete</a> </td>"
."</tr>";
}
echo
"</tbody>"
."</table>"
."</div>"
."</div>";
} else {
echo 'Log Empty';
}
}
?>
</div>
<?php
$action = isset($_GET['action']) ? $_GET['action'] : "";
if($action=='deleted'){
echo "<div class='alert alert-success>Record was deleted</div>'";
}
?>
<script type="text/javascript">
function delete_user(id){
var answer = confirm("Are you sure ? ");
if(answer){
window.location = 'delete.php?id=' + id;
}
}
</script>
</body>
</html>