<?php
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 = '';
if ($postData->photo1!='') $photo1 = $postData->photo1;
$photo2 = '';
if ($postData->photo2!='') $photo2 = $postData->photo2;

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

//$mysqli = new mysqli("localhost", "afxtech1_myori", "myori2017", "afxtech1_myori");
include_once("db_connect.php");

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

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

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


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);
}


$mysqli->close();


?>