<?php
require_once 'classes/ConDB.php';

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

header('Content-type: application/json');
if (isset($_REQUEST['emp_submit'])) {
    $db = new ConDB();
    
    $request = $db-> _cleanInputs($_REQUEST);
    // $request = $_REQUEST;
    
    
    extract($request);
   
    if ($employer_no == '' || $employer_name == '' || $employer_dep == '' || $dev_id == '' || $employer_pos == '') {
        $msg = new getErrorMsg('7');
        $json = array('statusMessage' => $msg->errMsg, 'statusNumber' => $msg->errNo);
        echo json_encode($json);
        return false;
    } else {
        $emp_check = new checkEmployerId($employer_no); 
    }
    $inloop = false;
    if (!$emp_check->available) {
        $msg = new getErrorMsg('3');
        $inloop = true;
    }

    if ($inloop) {

        //header('Content-type: application/json');
        $json = array('statusMessage' => $msg->errMsg, 'statusNumber' => $msg->errNo);
        echo json_encode($json);
        return false;
    } else {

         $reg_emp_qry = "insert into employee_table(emp_no,emp_name,emp_dept,emp_position,log_lock,device_id) values('".$employer_no."','".$employer_name."','".$employer_dep."','" . $employer_pos."','".isset($dev_lock)."','".$dev_id."')";

        $resutl= mysql_query($reg_emp_qry, $db->conn);
        $inserted_id = mysql_insert_id();
        if (mysql_affected_rows() > 0) {

            $msg = new getErrorMsg('0');
            $json = array('Emp_Id' => $inserted_id, 'statusMessage' => $msg->errMsg, 'statusNumber' => $msg->errNo);
            echo json_encode($json);

            return false;
        } else {
//            echo $reg_user_qry;
            $msg = new getErrorMsg('9');
            $json = array('statusMessage' => $msg->errMsg, 'statusNumber' => $msg->errNo);
            echo json_encode($json);
//                echo $reg_user_qry;
            return false;
        }
    }

}
?>