-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetdata.php
338 lines (319 loc) · 13.5 KB
/
getdata.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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<?php
//Connect to database
require 'connectDB.php';
date_default_timezone_set('Asia/Damascus');
$d = date("Y-m-d");
$t = date("H:i:sa");
if (isset($_GET['FingerID']) && isset($_GET['device_token'])) {
$fingerID = $_GET['FingerID'];
$device_uid = $_GET['device_token'];
$sql = "SELECT * FROM devices WHERE device_uid=?";
$result = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($result, $sql)) {
echo "SQL_Error_Select_device";
exit();
}
else{
mysqli_stmt_bind_param($result, "s", $device_uid);
mysqli_stmt_execute($result);
$resultl = mysqli_stmt_get_result($result);
if ($row = mysqli_fetch_assoc($resultl)){
$device_mode = $row['device_mode'];
$device_dep = $row['device_dep'];
if ($device_mode == 1) {
$sql = "SELECT * FROM users WHERE fingerprint_id=?";
$result = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($result, $sql)) {
echo "SQL_Error_Select_card";
exit();
}
else{
mysqli_stmt_bind_param($result, "s", $fingerID);
mysqli_stmt_execute($result);
$resultl = mysqli_stmt_get_result($result);
if ($row = mysqli_fetch_assoc($resultl)){
//*****************************************************
//An existed fingerprint has been detected for Login or Logout
if ($row['username'] != "None" && $row['add_fingerid'] == 0){
$Uname = $row['username'];
$Number = $row['registrationnumber'];
$sql = "SELECT * FROM users_logs WHERE fingerprint_id=? AND checkindate=? AND timeout=''";
$result = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($result, $sql)) {
echo "SQL_Error_Select_logs";
exit();
}
else{
mysqli_stmt_bind_param($result, "ss", $fingerID, $d);
mysqli_stmt_execute($result);
$resultl = mysqli_stmt_get_result($result);
//*****************************************************
//Login
if (!$row = mysqli_fetch_assoc($resultl)){
$sql = "INSERT INTO users_logs (username, serialnumber, fingerprint_id, device_uid, device_dep,checkindate, timein, timeout) VALUES (? ,?, ?, ?, ?, ?, ?, ?)";
$result = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($result, $sql)) {
echo "SQL_Error_Select_login1";
exit();
}
else{
$timeout = "00:00:00";
mysqli_stmt_bind_param($result, "sdisssss", $Uname, $Number, $fingerID, $device_uid, $device_dep, $d, $t, $timeout);
mysqli_stmt_execute($result);
echo "login".$Uname;
exit();
}
}
//*****************************************************
//Logout
else{
$sql="UPDATE users_logs SET timeout=?, fingerout=1 WHERE fingerprint_id=? AND checkindate=? AND fingerout=0";
$result = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($result, $sql)) {
echo "SQL_Error_insert_logout1";
exit();
}
else{
mysqli_stmt_bind_param($result, "sis", $t, $fingerID, $d);
mysqli_stmt_execute($result);
echo "logout".$Uname;
exit();
}
}
}
}
else{
echo "Not registerd!";
exit();
}
}
else{
echo "Not found!";
exit();
}
}
}
else if ($device_mode == 0) {
//New Fingerprint has been added
$sql = "SELECT * FROM users WHERE fingerprint_id=? AND device_uid=?";
$result = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($result, $sql)) {
echo "SQL_Error_Select_card";
exit();
}
else{
mysqli_stmt_bind_param($result, "ss", $fingerID, $device_uid);
mysqli_stmt_execute($result);
$resultl = mysqli_stmt_get_result($result);
if ($row = mysqli_fetch_assoc($resultl)){
echo "available";
exit();
}
else{
$sql = "INSERT INTO users ( device_uid, device_dep, fingerprint_id, user_date, add_fingerid) VALUES (?, ?, ?, CURDATE(), 0)";
$result = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($result, $sql)) {
echo "SQL_Error_Select_add";
exit();
}
else{
mysqli_stmt_bind_param($result, "sss", $device_uid, $device_dep, $fingerID );
mysqli_stmt_execute($result);
echo "succesful";
exit();
}
}
}
}
}
else{
echo "Invalid Device!";
exit();
}
}
}
if (isset($_GET['Get_Fingerid']) && isset($_GET['device_token'])) {
$device_uid = $_GET['device_token'];
$sql = "SELECT * FROM devices WHERE device_uid=?";
$result = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($result, $sql)) {
echo "SQL_Error_Select_device";
exit();
}
else{
mysqli_stmt_bind_param($result, "s", $device_uid);
mysqli_stmt_execute($result);
$resultl = mysqli_stmt_get_result($result);
if ($row = mysqli_fetch_assoc($resultl)){
if ($_GET['Get_Fingerid'] == "get_id") {
$sql= "SELECT fingerprint_id FROM users WHERE add_fingerid=1 AND device_uid=? LIMIT 1";
$result = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($result, $sql)) {
echo "SQL_Error_Select";
exit();
}
else{
mysqli_stmt_bind_param($result, "s", $device_uid);
mysqli_stmt_execute($result);
$resultl = mysqli_stmt_get_result($result);
if ($row = mysqli_fetch_assoc($resultl)) {
echo "add-id".$row['fingerprint_id'];
exit();
}
else{
echo "Nothing";
exit();
}
}
}
else{
exit();
}
}
else{
echo "Invalid Device";
exit();
}
}
}
if (isset($_GET['Check_mode']) && isset($_GET['device_token'])) {
$device_uid = $_GET['device_token'];
$sql = "SELECT * FROM devices WHERE device_uid=?";
$result = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($result, $sql)) {
echo "SQL_Error_Select_device";
exit();
}
else{
mysqli_stmt_bind_param($result, "s", $device_uid);
mysqli_stmt_execute($result);
$resultl = mysqli_stmt_get_result($result);
if ($row = mysqli_fetch_assoc($resultl)){
if ($_GET['Check_mode'] == "get_mode") {
$sql= "SELECT device_mode FROM devices WHERE device_uid=?";
$result = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($result, $sql)) {
echo "SQL_Error_Select";
exit();
}
else{
mysqli_stmt_bind_param($result, "s", $device_uid);
mysqli_stmt_execute($result);
$resultl = mysqli_stmt_get_result($result);
if ($row = mysqli_fetch_assoc($resultl)) {
echo "mode".$row['device_mode'];
exit();
}
else{
echo "Nothing";
exit();
}
}
}
else{
exit();
}
}
else{
echo "Invalid Device";
exit();
}
}
}
if (!empty($_GET['confirm_id']) && isset($_GET['device_token'])) {
$fingerid = $_GET['confirm_id'];
$device_uid = $_GET['device_token'];
$sql = "SELECT * FROM devices WHERE device_uid=?";
$result = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($result, $sql)) {
echo "SQL_Error_Select_device";
exit();
}
else{
mysqli_stmt_bind_param($result, "s", $device_uid);
mysqli_stmt_execute($result);
$resultl = mysqli_stmt_get_result($result);
if ($row = mysqli_fetch_assoc($resultl)){
$sql="UPDATE users SET fingerprint_select=0 WHERE fingerprint_select=1 AND device_uid=?";
$result = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($result, $sql)) {
echo "SQL_Error_Select";
exit();
}
else{
mysqli_stmt_bind_param($result, "s", $device_uid);
mysqli_stmt_execute($result);
$sql="UPDATE users SET add_fingerid=0, fingerprint_select=1 WHERE fingerprint_id=? AND device_uid=?";
$result = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($result, $sql)) {
echo "SQL_Error_Select";
exit();
}
else{
mysqli_stmt_bind_param($result, "ss", $fingerid, $device_uid);
mysqli_stmt_execute($result);
echo "Fingerprint has been added!";
exit();
}
}
}
else{
echo "Invalid Device";
exit();
}
}
}
if (isset($_GET['DeleteID']) && isset($_GET['device_token'])) {
$device_uid = $_GET['device_token'];
if ($_GET['DeleteID'] == "check") {
$sql = "SELECT * FROM devices WHERE device_uid=?";
$result = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($result, $sql)) {
echo "SQL_Error_Select_device";
exit();
}
else{
mysqli_stmt_bind_param($result, "s", $device_uid);
mysqli_stmt_execute($result);
$resultl = mysqli_stmt_get_result($result);
if ($row = mysqli_fetch_assoc($resultl)){
$sql = "SELECT fingerprint_id FROM users WHERE del_fingerid=1 AND device_uid=? LIMIT 1";
$result = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($result, $sql)) {
echo "SQL_Error_Select";
exit();
}
else{
mysqli_stmt_bind_param($result, "s", $device_uid);
mysqli_stmt_execute($result);
$resultl = mysqli_stmt_get_result($result);
if ($row = mysqli_fetch_assoc($resultl)) {
echo "del-id".$row['fingerprint_id'];
$sql = "DELETE FROM users WHERE del_fingerid=1";
$result = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($result, $sql)) {
echo "SQL_Error_delete";
exit();
}
else{
mysqli_stmt_execute($result);
exit();
}
}
else{
echo "nothing";
exit();
}
}
}
else{
echo "Invalid Device";
exit();
}
}
}
else{
exit();
}
}
?>