<?
header('Access-Control-Allow-Origin: *');
//header('Content-Type: application/json');

$ofc = $_GET['ofc'];
/*
if ($id){
    echo $id;
}
else {
    echo 'All Items';
}
*/


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


//$id = '003';
//$query = "SELECT * FROM reports WHERE officer = '" .$ofc. "' ORDER BY rpt_txn ";
$query = "SELECT id, rpt_txn, status, DATE(rpt_txn) as 'rpt_date' FROM reports WHERE officer = '" .$ofc. "' ORDER BY rpt_txn ";
$dbresult = $mysqli->query($query);

//echo 'Hello...here1';
//die();

$mysqli->close();

$data = [];

while($row = $dbresult->fetch_array(MYSQLI_ASSOC)){
    $data[] = array(
        'id' => $row['id'],
        'rpt_txn' => $row['rpt_txn'],
        'status' => $row['status'],
        'rpt_date' => $row['rpt_date']
    );
}

if($dbresult){
    $result = json_encode($data);              
}
else {
    $result = "{success:false}";
}

echo $result;

?>