Skip to content

Commit

Permalink
Replace Indent Tab with Space
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Fahri committed May 24, 2022
1 parent 1ba1099 commit 6dee3fe
Showing 1 changed file with 131 additions and 131 deletions.
262 changes: 131 additions & 131 deletions src/Fingerprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,79 +6,79 @@
*/
class Fingerprint
{
private static $conn;
private static $ip;
private static $port;
private static $comkey;
private static $isConnected = false;
private static $NL = "\r\n";

private static $payload = [
'GetAttLog' => '<GetAttLog><ArgComKey xsi:type=\"xsd:integer\">#COMKEY</ArgComKey>#PIN</GetAttLog>',
'GetUserInfo' => '<GetUserInfo><ArgComKey xsi:type=\"xsd:integer\">#COMKEY</ArgComKey>#PIN</GetUserInfo>'
];

public function connect($ip, $port=80, $comkey=0)
{
static::$ip = $ip;
static::$port = $port;
static::$comkey = $comkey;

static::$conn = @fsockopen(static::$ip, static::$port, $errno, $errstr, 1);

if (static::$conn) {
static::$isConnected = true;
}else{
static::$isConnected = false;
}
return (new static);
}

public function getStatus()
{
return static::$isConnected ? 'connected' : 'disconnected';
}

public function getUserInfo($pin='all')
{
$payload = self::$payload['GetUserInfo'];

static::connect(static::$ip, static::$port, static::$comkey);

if (is_array($pin)) {
$pinPayload = "";
foreach ($pin as $value) {
$pinPayload .= "<Arg><PIN>".$value."</PIN></Arg>";
}
$pin = $pinPayload;
}else {
$pin = "<Arg><PIN>".$pin."</PIN></Arg>";
}

$payload = str_replace("#PIN", $pin, $payload);

$this->generateRequest($payload);
private static $conn;
private static $ip;
private static $port;
private static $comkey;
private static $isConnected = false;
private static $NL = "\r\n";

private static $payload = [
'GetAttLog' => '<GetAttLog><ArgComKey xsi:type=\"xsd:integer\">#COMKEY</ArgComKey>#PIN</GetAttLog>',
'GetUserInfo' => '<GetUserInfo><ArgComKey xsi:type=\"xsd:integer\">#COMKEY</ArgComKey>#PIN</GetUserInfo>'
];

public function connect($ip, $port=80, $comkey=0)
{
static::$ip = $ip;
static::$port = $port;
static::$comkey = $comkey;

static::$conn = @fsockopen(static::$ip, static::$port, $errno, $errstr, 1);

if (static::$conn) {
static::$isConnected = true;
}else{
static::$isConnected = false;
}
return (new static);
}

public function getStatus()
{
return static::$isConnected ? 'connected' : 'disconnected';
}

public function getUserInfo($pin='all')
{
$payload = self::$payload['GetUserInfo'];

static::connect(static::$ip, static::$port, static::$comkey);

if (is_array($pin)) {
$pinPayload = "";
foreach ($pin as $value) {
$pinPayload .= "<Arg><PIN>".$value."</PIN></Arg>";
}
$pin = $pinPayload;
}else {
$pin = "<Arg><PIN>".$pin."</PIN></Arg>";
}

$payload = str_replace("#PIN", $pin, $payload);

$this->generateRequest($payload);

$buffer = "";
$isStartNow = false;
while ($res = fgets(static::$conn, 1024)) {
if (strpos($res, "<GetUserInfoResponse>") !== false) {
$isStartNow = true;
}
if($isStartNow) {
$buffer = $buffer.$res;
}
}
$isStartNow = false;
while ($res = fgets(static::$conn, 1024)) {
if (strpos($res, "<GetUserInfoResponse>") !== false) {
$isStartNow = true;
}
if($isStartNow) {
$buffer = $buffer.$res;
}
}

$gaRes = ["<GetUserInfoResponse>", "</GetUserInfoResponse>", "\r\n"];
$buffer = str_replace($gaRes, "", $buffer);
$gaRes = ["<GetUserInfoResponse>", "</GetUserInfoResponse>", "\r\n"];
$buffer = str_replace($gaRes, "", $buffer);

fclose(static::$conn);
return static::parseUserInfoData($buffer);
}
fclose(static::$conn);
return static::parseUserInfoData($buffer);
}

private static function parseUserInfoData($data="") {
private static function parseUserInfoData($data="") {

$dataRow = explode("<Row>", $data);
array_shift($dataRow);
Expand Down Expand Up @@ -110,49 +110,49 @@ private static function parseUserInfoData($data="") {
return $userData;
}

public function getAttendance($pin='all', $date_start=null, $date_end=null)
{
if ($date_start != null && $date_end == null) {
$date_end = $date_start;
}
public function getAttendance($pin='all', $date_start=null, $date_end=null)
{
if ($date_start != null && $date_end == null) {
$date_end = $date_start;
}

$payload = self::$payload['GetAttLog'];
$payload = self::$payload['GetAttLog'];

static::connect(static::$ip, static::$port, static::$comkey);
static::connect(static::$ip, static::$port, static::$comkey);

if (is_array($pin)) {
$pinPayload = "";
foreach ($pin as $value) {
$pinPayload .= "<Arg><PIN>".$value."</PIN></Arg>";
}
$pin = $pinPayload;
}else {
$pin = "<Arg><PIN>".$pin."</PIN></Arg>";
}
if (is_array($pin)) {
$pinPayload = "";
foreach ($pin as $value) {
$pinPayload .= "<Arg><PIN>".$value."</PIN></Arg>";
}
$pin = $pinPayload;
}else {
$pin = "<Arg><PIN>".$pin."</PIN></Arg>";
}

$payload = str_replace("#PIN", $pin, $payload);
$payload = str_replace("#PIN", $pin, $payload);

$this->generateRequest($payload);
$this->generateRequest($payload);

$buffer = "";
$isStartNow = false;
while ($res = fgets(static::$conn, 1024)) {
if (strpos($res, "<GetAttLogResponse>") !== false) {
$isStartNow = true;
}
if($isStartNow) {
$buffer = $buffer.$res;
}
}

$gaRes = ["<GetAttLogResponse>", "</GetAttLogResponse>", "\r\n"];
$buffer = str_replace($gaRes, "", $buffer);

fclose(static::$conn);
return static::parseAttendanceData($buffer, $date_start, $date_end);
}

private static function parseAttendanceData($data="", $date_start=null, $date_end=null) {
$isStartNow = false;
while ($res = fgets(static::$conn, 1024)) {
if (strpos($res, "<GetAttLogResponse>") !== false) {
$isStartNow = true;
}
if($isStartNow) {
$buffer = $buffer.$res;
}
}

$gaRes = ["<GetAttLogResponse>", "</GetAttLogResponse>", "\r\n"];
$buffer = str_replace($gaRes, "", $buffer);

fclose(static::$conn);
return static::parseAttendanceData($buffer, $date_start, $date_end);
}

private static function parseAttendanceData($data="", $date_start=null, $date_end=null) {
$dataRow = explode("<Row>", $data);
array_shift($dataRow);

Expand All @@ -168,29 +168,29 @@ private static function parseAttendanceData($data="", $date_start=null, $date_en
$workcode = static::getValueFromTag($endRow, "<WorkCode>", "</WorkCode>");

if ($date_start != null && $date_end != null) {
$rangeDate = static::dateRange($date_start, $date_end);
$rangeDate = static::dateRange($date_start, $date_end);

$dateCheck = explode(' ', $datetime)[0];
$dateCheck = explode(' ', $datetime)[0];

if (in_array($dateCheck, $rangeDate)) {
$fingerData[] = [
'pin' => $fid,
'datetime' => $datetime,
'verified' => $verified,
'status' => $status,
'workcode' => $workcode,
];
}
if (in_array($dateCheck, $rangeDate)) {
$fingerData[] = [
'pin' => $fid,
'datetime' => $datetime,
'verified' => $verified,
'status' => $status,
'workcode' => $workcode,
];
}

} else {
$fingerData[] = [
'pin' => $fid,
'datetime' => $datetime,
'verified' => $verified,
'status' => $status,
'workcode' => $workcode,
];
$fingerData[] = [
'pin' => $fid,
'datetime' => $datetime,
'verified' => $verified,
'status' => $status,
'workcode' => $workcode,
];
}
}

Expand All @@ -213,7 +213,7 @@ private static function getValueFromTag($a, $b, $c)

private static function dateRange($startDate, $endDate)
{
$dateRange = [];
$dateRange = [];
$period = new \DatePeriod(
new \DateTime($startDate),
new \DateInterval('P1D'),
Expand All @@ -224,21 +224,21 @@ private static function dateRange($startDate, $endDate)
array_push($dateRange, $value->format('Y-m-d'));
}

array_push($dateRange, date('Y-m-d', strtotime($endDate)));
array_push($dateRange, date('Y-m-d', strtotime($endDate)));

return $dateRange;
}

private function generateRequest($payload)
{
$payload = str_replace("#COMKEY", static::$comkey, $payload);
fputs(static::$conn, "POST /iWsService HTTP/1.0".self::$NL);
private function generateRequest($payload)
{
$payload = str_replace("#COMKEY", static::$comkey, $payload);
fputs(static::$conn, "POST /iWsService HTTP/1.0".self::$NL);
fputs(static::$conn, "Content-Type: text/xml".self::$NL);
fputs(static::$conn, "Content-Length: ".strlen($payload).self::$NL.self::$NL);
fputs(static::$conn, $payload.self::$NL);
}
}

public function __call($method, $parameters)
public function __call($method, $parameters)
{
return $this->$method(...$parameters);
}
Expand Down

0 comments on commit 6dee3fe

Please sign in to comment.