-
Notifications
You must be signed in to change notification settings - Fork 4
/
user.php
298 lines (216 loc) · 6.98 KB
/
user.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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<?php include("auth.php"); ?>
<?php
include 'include/global.php';
include 'include/function.php';
if (isset($_GET['action']) && $_GET['action'] == 'index') {
?>
<script type="text/javascript">
$('title').html('User');
function user_delete(user_id, user_name) {
var r = confirm("Delete user "+user_name+" ?");
if (r == true) {
push('user.php?action=delete&user_id='+user_id);
}
}
function user_register(user_id, user_name) {
$('body').ajaxMask();
regStats = 0;
regCt = -1;
try
{
timer_register.stop();
}
catch(err)
{
console.log('Registration timer has been init');
}
var limit = 4;
var ct = 1;
var timeout = 5000;
timer_register = $.timer(timeout, function() {
console.log("'"+user_name+"' registration checking...");
user_checkregister(user_id,$("#user_finger_"+user_id).html());
if (ct>=limit || regStats==1)
{
timer_register.stop();
console.log("'"+user_name+"' registration checking end");
if (ct>=limit && regStats==0)
{
alert("'"+user_name+"' registration fail!");
$('body').ajaxMask({ stop: true });
}
if (regStats==1)
{
$("#user_finger_"+user_id).html(regCt);
alert("'"+user_name+"' registration success!");
$('body').ajaxMask({ stop: true });
load('user.php?action=index');
}
}
ct++;
});
}
function user_checkregister(user_id, current) {
$.ajax({
url : "user.php?action=checkreg&user_id="+user_id+"¤t="+current,
type : "GET",
success : function(data)
{
try
{
var res = jQuery.parseJSON(data);
if (res.result)
{
regStats = 1;
$.each(res, function(key, value){
if (key=='current')
{
regCt = value;
}
});
}
}
catch(err)
{
alert(err.message);
}
}
});
}
</script>
<br>
<?php
$user = getUser();
if (count($user) > 0) {
echo "<div class='row'>"
."<div class='col-md-12'>"
."<table class='table table-bordered table-hover'>"
."<thead>"
."<tr>"
."<th class='col-md-1'>User ID</th>"
."<th class='col-md-2'>Matric Number</th>"
."<th class='col-md-4'>Department</th>"
."<th class='col-md-2'>Level</th>"
."<th class='col'>Template</th>"
."<th class='col'>Action</th>"
."</tr>"
."</thead>"
."<tbody>";
foreach ($user as $row) {
$finger = getUserFinger($row['user_id']);
$register = '';
$verification = '';
$url_register = base64_encode($base_path."register.php?user_id=".$row['user_id']);
$url_verification = base64_encode($base_path."verification.php?user_id=".$row['user_id']);
if (count($finger) == 0) {
$register = "<a href='finspot:FingerspotReg;$url_register' class='btn btn-xs btn-primary' onclick=\"user_register('".$row['user_id']."','".$row['user_name']."')\">Register</a>";
} else {
$verification = "<a href='finspot:FingerspotVer;$url_verification' class='btn btn-xs btn-success'>Mark</a>";
}
echo "<tr>"
."<td>".$row['user_id']."</td>"
."<td>".$row['user_name']."</td>"
."<td>".$row['department']."</td>"
."<td>".$row['level']."</td>"
."<td><code id='user_finger_".$row['user_id']."'>".count($finger)."</code></td>"
."<td>"
."<button type='button' class='btn btn-xs btn-danger' onclick=\"user_delete('".$row['user_id']."','".$row['user_name']."')\">Delete</button>"
." "
."$register"
."$verification"
."</td>"
."</tr>";
}
echo
"</tbody>"
."</table>"
."</div>"
."</div>";
} else {
echo 'No student added';
}
} elseif (isset($_GET['action']) && $_GET['action'] == 'create') {
?>
<script type="text/javascript">
$('title').html('Add user');
function user_store() {
user_name = $('#user_name').val();
push('user.php?action=store&user_name='+user_name);
}
</script>
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-4">
<div class="form-group">
<label for="user_name">Matric Number</label>
<input type="text" id="user_name" class="form-control" placeholder="Enter Matric Number">
</div>
<div class="form-group">
<label for="department">Department</label>
<input type="text" name="department" id="department" class="form-control" placeholder="Enter Department">
</div>
<div class="form-group">
<label for="level">Level</label>
<input type="number" name="level" id="level" class="form-control" placeholder="Level of Study">
</div>
<a class="btn btn-default" onclick="load('<?php echo $base_path?>user.php?action=index')">Back</a>
<button type="submit" class="btn btn-success" onclick="user_store()">Save</button>
</div>
<div class="col-md-4">
</div>
</div>
<?php
} elseif (isset($_GET['action']) && $_GET['action'] == 'store') {
$res = array();
$res['result'] = false;
if ($_GET['user_name'] == '' || !isset($_GET['user_name']) || empty($_GET['user_name'])) {
$res['user_name'] = "matric number can't empty";
} elseif (isset($_GET['user_name']) && !empty($_GET['user_name'])) {
$user_name = checkUserName($_GET['user_name']);
if ($user_name != 1) {
$res['user_name'] = $user_name;
}
}
if (count($res) > 1) {
echo json_encode($res);
} else {
$sql = "INSERT INTO user (user_name,department,level_study) VALUES (".$_GET['user_name'].",".$_GET['department'].",".$_GET['level'].")";
$result = mysql_query($sql) or die('Data not inserted');
if ($result) {
$res['result'] = true;
$res['reload'] = "user.php?action=index";
} else {
$res['server'] = "Error insert data!";
}
echo json_encode($res);
}
} elseif (isset($_GET['action']) && $_GET['action'] == 'delete') {
$sql1 = "DELETE FROM user WHERE user_id = '".$_GET['user_id']."' ";
$result1 = mysql_query($sql1);
$sql2 = "DELETE FROM finger WHERE user_id = '".$_GET['user_id']."' ";
$result2 = mysql_query($sql2);
if ($result1 && $result2) {
$res['result'] = true;
$res['reload'] = "user.php?action=index";
} else {
$res['server'] = "Error delete data!#".$sql1;
}
echo json_encode($res);
} elseif (isset ($_GET['action']) && $_GET['action'] == 'checkreg') {
$sql1 = "SELECT count(finger_id) as ct FROM finger WHERE user_id=".$_GET['user_id'];
$result1 = mysql_query($sql1);
$data1 = mysql_fetch_array($result1);
if (intval($data1['ct']) > intval($_GET['current'])) {
$res['result'] = true;
$res['current'] = intval($data1['ct']);
}
else
{
$res['result'] = false;
}
echo json_encode($res);
} else {
echo "Parameter invalid..";
}
?>