<?
header('Access-Control-Allow-Origin: *');

//var_dump(json_decode(file_get_contents("php://input")));
$postData = json_decode(file_get_contents("php://input"));

//echo 'Hello...here1' .'<br/>';
//echo 'Result:' . '<br/>';
//echo $postData->name;
//die();

$photo1 = null;
if ($postData->photo1!='') $photo1 = $postData->photo1;
$photo2 = null;
if ($postData->photo2!='') $photo2 = $postData->photo2;


if ($postData->jenis==='003') $status = 'C';

$query = "INSERT INTO reports_actions (id, officer, remark, action, status, photo1, photo2) VALUES ('" .$postData->id. "', '" .$postData->officer. "', '" .$postData->butiran. "', '" .$postData->jenis. "', " .$postData->status. ", '" .$photo1. "', '" .$photo2. "') ";
//echo 'query = ' .$query;
//die();

//$mysqli = new mysqli("localhost", "afxtech1_myori", "myori2017", "afxtech1_myori");
include_once("db_connect.php");
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
} 

if ($mysqli->query($query) === TRUE) {
    echo "New record created successfully";
    http_response_code(200);
} else {
    echo "Error: " . $query . "<br>" . $mysqli->error;
    http_response_code(500);
}


if ($postData->jenis==='003') {

    $query = "UPDATE reports SET status = 'C' AND remarks2 = 'KES SELESAI' where id = '".$postData->id."' ";
    if ($mysqli->query($query) === TRUE) {}    
    
}

$mysqli->close();

echo $result;

?>