function processCheckIn($rfid) { $errors = 0; $processCheckInMessage = ""; $rfid = testInput($rfid); $date = date('Y-m-d H:i:s'); if (getMemberInfoByRFID($rfid, 'k.serial')["serial"] != null) { if (getMemberInfoByRFID($rfid, "c.active")["active"] == 0) { // check if user is active if (!createLog(getMemberInfoByRFID($rfid, "c.cid")["cid"], $date)) { // create a log with the current date $errors = 1; $processCheckInMessage .= 'Could not create a new log in the database!'; die; } else { if (!updateContactCheckinStatus($date, getMemberInfoByRFID($rfid, "c.cid")["cid"], 1)) { // update user table, set active to 1 and insert last checkin time $errors = 1; $processCheckInMessage .= 'Could not update member status when checking in!'; die; } else { $processCheckInMessage .= "Checkin successful!"; } } } else { if (!updateContactCheckinStatus($date, getMemberInfoByRFID($rfid, "c.cid")["cid"], 0)) { // update user table, set active to 0 and insert last checkout time $errors = 1; $processCheckInMessage .= 'Could not update member status when checking out!'; die; } else { if (!updateLog(getMemberInfoByRFID($rfid, "c.cid")["cid"], $date, getMemberInfoByRFID($rfid, "c.last_checkin_time")["last_checkin_time"])) { // close log, insert checkout time (current date time) $errors = 1; $processCheckInMessage .= 'Could not close the log for user check out!'; die; } else { $processCheckInMessage .= "Checkout successful!"; } } } } else { $errors = 1; $processCheckInMessage .= "RFID key not found in the database!"; } if ($errors == 1) { $processCheckInMessage = 'ERROR: ' . $processCheckInMessage; // in case there are errors, add 'ERROR: ' at the beginning of a status message. $response['hasErrors'] = $errors; $response['message'] = $processCheckInMessage; } else { $response['hasErrors'] = $errors; $response['message'] = $processCheckInMessage; $response['firstName'] = getMemberInfoByRFID($rfid, 'c.firstName')["firstName"]; $response['lastName'] = getMemberInfoByRFID($rfid, 'c.lastName')["lastName"]; $response['lastCheckInTime'] = getMemberInfoByRFID($rfid, 'c.last_checkin_time')["last_checkin_time"]; $response['lastCheckOutTime'] = getMemberInfoByRFID($rfid, 'c.last_checkout_time')["last_checkout_time"]; } return $response; }
<?php //////////////////////////////// //This is the REST web service that will give back info from the Seltzer DB. //////////////////////////////// //Altin Ukshini altin.ukshini@gmail.com //Created: Sep 20, 2015 // header("Content-Type:application/json"); include "functions.php"; // include functions $possible_url = array("getMemberInfoByRFID", "getMemberLastPaymentTimestamp", "getRFIDWhitelist", "doorLockCheck", "processCheckIn", "hackerspaceStatus", "isUserCheckedIn"); if (isset($_GET["action"]) && in_array($_GET["action"], $possible_url)) { $value = "An error has occurred"; switch ($_GET["action"]) { case "getMemberInfoByRFID": $value = getMemberInfoByRFID($_GET['rfid'], $_GET['fieldNames']); break; case "getMemberLastPaymentTimestamp": $value = getMemberLastPaymentTimestamp($_GET['rfid']); break; case "getRFIDWhitelist": $value = getRFIDWhitelist($_GET['fields']); break; case "doorLockCheck": $value = doorLockCheck($_GET['rfid']); break; case "processCheckIn": $value = processCheckIn($_GET['rfid']); break; case "hackerspaceStatus": $value = hackerspaceStatus();