forked from vodvud/php_zklib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.php
150 lines (146 loc) · 5.6 KB
/
example.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
<html>
<head>
<title>ZK Test</title>
</head>
<body>
<?php
date_default_timezone_set('Asia/Manila'); //Default Timezone Of Your Country
$enableGetDeviceInfo = true;
$enableGetUsers = true;
$enableGetData = true;
include('zklib/ZKLib.php');
$zk = new ZKLib(
'192.168.1.100' //your device IP
);
$ret = $zk->connect();
if ($ret) {
$zk->disableDevice();
$zk->setTime(date('Y-m-d H:i:s')); // Synchronize time
?>
<?php if($enableGetDeviceInfo === true) { ?>
<table border="1" cellpadding="5" cellspacing="2">
<tr>
<td><b>Status</b></td>
<td>Connected</td>
<td><b>Version</b></td>
<td><?php echo($zk->version()); ?></td>
<td><b>OS Version</b></td>
<td><?php echo($zk->osVersion()); ?></td>
<td><b>Platform</b></td>
<td><?php echo($zk->platform()); ?></td>
</tr>
<tr>
<td><b>Firmware Version</b></td>
<td><?php echo($zk->fmVersion()); ?></td>
<td><b>WorkCode</b></td>
<td><?php echo($zk->workCode()); ?></td>
<td><b>SSR</b></td>
<td><?php echo($zk->ssr()); ?></td>
<td><b>Pin Width</b></td>
<td><?php echo($zk->pinWidth()); ?></td>
</tr>
<tr>
<td><b>Face Function On</b></td>
<td><?php echo($zk->faceFunctionOn()); ?></td>
<td><b>Serial Number</b></td>
<td><?php echo($zk->serialNumber()); ?></td>
<td><b>Device Name</b></td>
<td><?php echo($zk->deviceName()); ?></td>
<td><b>Get Time</b></td>
<td><?php echo($zk->getTime()); ?></td>
</tr>
</table>
<?php } ?>
<hr/>
<?php if($enableGetUsers === true) { ?>
<table border="1" cellpadding="5" cellspacing="2" style="float: left; margin-right: 10px;">
<tr>
<th colspan="6">Data User</th>
</tr>
<tr>
<th>UID</th>
<th>ID</th>
<th>Name</th>
<th>Card #</th>
<th>Role</th>
<th>Password</th>
</tr>
<?php
try {
//$zk->setUser(1, '1', 'User1', '', ZK\Util::LEVEL_USER);
//$zk->setUser(2, '2', 'User2', '', ZK\Util::LEVEL_USER);
//$zk->setUser(3, '3', 'User3', '', ZK\Util::LEVEL_USER);
//$zk->setUser(5, '5', 'Admin', '1234', ZK\Util::LEVEL_ADMIN);
$users = $zk->getUser();
sleep(1);
foreach ($users as $uItem) {
?>
<tr>
<td><?php echo($uItem['uid']); ?></td>
<td><?php echo($uItem['userid']); ?></td>
<td><?php echo($uItem['name']); ?></td>
<td><?php echo($uItem['cardno']); ?></td>
<td><?php echo(ZK\Util::getUserRole($uItem['role'])); ?></td>
<td><?php echo($uItem['password']); ?> </td>
</tr>
<?php
}
} catch (Exception $e) {
header("HTTP/1.0 404 Not Found");
header('HTTP', true, 500); // 500 internal server error
}
//$zk->clearAdmin();
//$zk->clearUsers();
//$zk->removeUser(1);
?>
</table>
<?php } ?>
<?php if ($enableGetData === true) { ?>
<table border="1" cellpadding="5" cellspacing="2">
<tr>
<th colspan="7">Data Attendance</th>
</tr>
<tr>
<th>UID</th>
<th>ID</th>
<th>Name</th>
<th>State</th>
<th>Date</th>
<th>Time</th>
<th>Type</th>
</tr>
<?php
$attendance = $zk->getAttendance();
if (count($attendance) > 0) {
$attendance = array_reverse($attendance, true);
sleep(1);
foreach ($attendance as $attItem) {
?>
<tr>
<td><?php echo($attItem['uid']); ?></td>
<td><?php echo($attItem['id']); ?></td>
<td><?php echo(isset($users[$attItem['id']]) ? $users[$attItem['id']]['name'] : $attItem['id']); ?></td>
<td><?php echo(ZK\Util::getAttState($attItem['state'])); ?></td>
<td><?php echo(date("d-m-Y", strtotime($attItem['timestamp']))); ?></td>
<td><?php echo(date("H:i:s", strtotime($attItem['timestamp']))); ?></td>
<td><?php echo(ZK\Util::getAttType($attItem['type'])); ?></td>
</tr>
<?php
}
}
?>
</table>
<?php
if (count($attendance) > 0) {
//$zk->clearAttendance(); // Remove attendance log only if not empty
}
?>
<?php } ?>
<?php
$zk->setTime(date('Y-m-d H:i:s')); // Synchronize time
$zk->enableDevice();
$zk->disconnect();
}
?>
</body>
</html>