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

$officer = $_GET['o'];
/*
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 status = '0' ORDER BY rpt_txn ";
$query = "SELECT id, rpt_txn, DATE(rpt_txn) as 'rpt_date', status, type, category, priority, notes, location FROM reports WHERE status = '0' AND officer = '" .$officer. "' ORDER BY rpt_txn ";
$dbresult = $mysqli->query($query);

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

$mysqli->close();

$data = [];

while($row = $dbresult->fetch_array(MYSQLI_ASSOC)){
    $dt = date_create($row['rpt_date']);
    $data[] = array(
        'id' => $row['id'],
        'rpt_txn' => $row['rpt_txn'],
        'rpt_date' => $row['rpt_date'],
        'dt' => date_format($dt,"M d"),
        'status' => $row['status'],
        
        'type' => $row['type'],
        'cat' => $row['category'],
        'pri' => $row['priority'],
        'notes' => $row['notes'],
        'loc' => $row['location']
    );
}

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

echo $result;

?>