<?php

require_once 'classes/ConDB.php';
require_once 'classes/getErrorMsg.php';

header('Content-type: application/json');
if (isset($_REQUEST['emp_submit'])) {
    $db = new ConDB();

	$request = $_REQUEST;

    
    extract($request);
    $inloop = false;
    if ($emp_no== '' || $dev_id == '') {
        $msg = new getErrorMsg('7');
        $inloop = true;
    }

    if ($inloop) {
        $json = array('statusMessage' => $msg->errMsg, 'statusNumber' => $msg->errNo);
        echo json_encode($json);
        return false;
          
    } else {
        $checkEmpQry = "select emp_id, emp_no, emp_name, emp_dept, emp_position, log_lock, device_id from employee_table where emp_no= '" . $emp_no . "'";

        $checkEmpRes = mysql_query($checkEmpQry, $db->conn);

	if (mysql_num_rows($checkEmpRes) == 1) {
            $empRow = mysql_fetch_assoc($checkEmpRes);
	        $checkDevLockQry = "select device_id, device_lock from device_table where device_id= '" . $dev_id . "'";
	        $checkDevLockRes = mysql_query($checkDevLockQry, $db->conn);
	
		if (mysql_num_rows($checkDevLockRes) == 1) {
			$devRow = mysql_fetch_assoc($checkDevLockRes );
			$msg = new getErrorMsg('0');
	            	$json = array('Employee_no' => $empRow['emp_no'], 'Employee_name' => $empRow['emp_name'], 'Employee_pos' => $empRow['emp_position'], 'Employee_depart' => $empRow['emp_dept'], 'Dev_lock' => $devRow ['device_lock'], 'statusMessage' => $msg->errMsg, 'statusNumber' => $msg->errNo);
	            	echo json_encode($json);
		}else{
	            $msg = new getErrorMsg('0');
	            $json = array('Employee_no' => $empRow['emp_no'], 'Employee_name' => $empRow['emp_name'], 'Employee_pos' => $empRow['emp_position'], 'Employee_depart' => $empRow['emp_dept'], 'Dev_lock' => "0", 'statusMessage' => $msg->errMsg, 'statusNumber' => $msg->errNo);
	            echo json_encode($json);
	        }
	        return false;
        } else {
            $msg = new getErrorMsg('12');
            $json = array('statusMessage' => $msg->errMsg, 'statusNumber' => $msg->errNo);
            echo json_encode($json);
            return false;
        }
    }
}
?>