Skip to content

Commit 3a08ae5

Browse files
authored
Merge pull request #10 from flu0/master
ZKTeco LP500: Adds support for Card State, Attendance Type.
2 parents 8985d5a + de85df4 commit 3a08ae5

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

example.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
<th>State</th>
111111
<th>Date</th>
112112
<th>Time</th>
113+
<th>Type</th>
113114
</tr>
114115
<?php
115116
$attendance = $zk->getAttendance();
@@ -125,6 +126,7 @@
125126
<td><?php echo(ZK\Util::getAttState($attItem['state'])); ?></td>
126127
<td><?php echo(date("d-m-Y", strtotime($attItem['timestamp']))); ?></td>
127128
<td><?php echo(date("H:i:s", strtotime($attItem['timestamp']))); ?></td>
129+
<td><?php echo(ZK\Util::getAttType($attItem['type'])); ?></td>
128130
</tr>
129131
<?php
130132
}

zklib/src/Attendance.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ public function get(ZKLib $self)
3838
$id = str_replace(chr(0), '', $id);
3939
$state = hexdec(substr($u[1], 56, 2));
4040
$timestamp = Util::decodeTime(hexdec(Util::reverseHex(substr($u[1], 58, 8))));
41-
41+
$type = hexdec(Util::reverseHex(substr($u[1], 66, 2 )));
42+
4243
$attendance[] = [
4344
'uid' => $uid,
4445
'id' => $id,
4546
'state' => $state,
46-
'timestamp' => $timestamp
47+
'timestamp' => $timestamp,
48+
'type' => $type
4749
];
4850

4951
$attData = substr($attData, 40);

zklib/src/Util.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class Util
5555

5656
const ATT_STATE_FINGERPRINT = 1;
5757
const ATT_STATE_PASSWORD = 0;
58+
const ATT_STATE_CARD = 2;
59+
60+
const ATT_TYPE_CHECK_IN = 0;
61+
const ATT_TYPE_CHECK_OUT = 1;
5862

5963
/**
6064
* Encode a timestamp send at the timeclock
@@ -284,12 +288,36 @@ static public function getAttState($state)
284288
case self::ATT_STATE_PASSWORD:
285289
$ret = 'Password';
286290
break;
291+
case self::ATT_STATE_CARD:
292+
$ret = 'Card';
293+
break;
287294
default:
288295
$ret = 'Unknown';
289296
}
290297

291298
return $ret;
292299
}
300+
301+
/**
302+
* Get Attendance Type string
303+
* @param integer $type
304+
* @return string
305+
*/
306+
static public function getAttType($type)
307+
{
308+
switch ($type) {
309+
case self::ATT_TYPE_CHECK_IN:
310+
$ret = 'Check-in';
311+
break;
312+
case self::ATT_TYPE_CHECK_OUT:
313+
$ret = 'Check-out';
314+
break;
315+
default:
316+
$ret = 'Undefined';
317+
}
318+
319+
return $ret;
320+
}
293321

294322
/**
295323
* Receive data from device
@@ -376,4 +404,4 @@ static private function logger(ZKLib $self, $str)
376404

377405
file_put_contents($log, $row, FILE_APPEND);
378406
}
379-
}
407+
}

0 commit comments

Comments
 (0)