Skip to content

Commit e277b4b

Browse files
author
Yaroslav Vodvud
committed
Fixed adding Card Number issue
1 parent 4602482 commit e277b4b

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

zklib/ZKLib.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,12 @@ public function getUser()
228228
* @param string $name (max length = 24)
229229
* @param int|string $password (max length = 8, only numbers - depends device setting)
230230
* @param int $role Default Util::LEVEL_USER
231+
* @param int $cardno Default 0 (max length = 10, only numbers)
231232
* @return bool|mixed
232233
*/
233-
public function setUser($uid, $userid, $name, $password, $role = Util::LEVEL_USER)
234+
public function setUser($uid, $userid, $name, $password, $role = Util::LEVEL_USER, $cardno = 0)
234235
{
235-
return (new ZK\User())->set($this, $uid, $userid, $name, $password, $role);
236+
return (new ZK\User())->set($this, $uid, $userid, $name, $password, $role, $cardno);
236237
}
237238

238239
/**

zklib/src/User.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ class User
1313
* @param string $name (max length = 24)
1414
* @param int|string $password (max length = 8, only numbers - depends device setting)
1515
* @param int $role Default Util::LEVEL_USER
16+
* @param int $cardno Default 0 (max length = 10, only numbers)
1617
* @return bool|mixed
1718
*/
18-
public function set(ZKLib $self, $uid, $userid, $name, $password, $role = Util::LEVEL_USER)
19+
public function set(ZKLib $self, $uid, $userid, $name, $password, $role = Util::LEVEL_USER, $cardno = 0)
1920
{
2021
$self->_section = __METHOD__;
2122

@@ -24,20 +25,24 @@ public function set(ZKLib $self, $uid, $userid, $name, $password, $role = Util::
2425
(int)$uid > Util::USHRT_MAX ||
2526
strlen($userid) > 9 ||
2627
strlen($name) > 24 ||
27-
strlen($password) > 8
28+
strlen($password) > 8 ||
29+
strlen($cardno) > 10
2830
) {
2931
return false;
3032
}
3133

3234
$command = Util::CMD_SET_USER;
3335
$byte1 = chr((int)($uid % 256));
3436
$byte2 = chr((int)($uid >> 8));
37+
$cardno = hex2bin(Util::reverseHex(dechex($cardno)));
38+
3539
$command_string = implode('', [
3640
$byte1,
3741
$byte2,
3842
chr($role),
3943
str_pad($password, 8, chr(0)),
40-
str_pad($name, 28, chr(0)),
44+
str_pad($name, 24, chr(0)),
45+
str_pad($cardno, 4, chr(0)),
4146
str_pad(chr(1), 9, chr(0)),
4247
str_pad($userid, 9, chr(0)),
4348
str_repeat(chr(0), 15)

0 commit comments

Comments
 (0)