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

$id = $_GET['id'];
/*
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 id, rpt_txn, name, location,
//            remark1, remark2, officer, status, area,
//            reporter, reporter_email, reporter_phone,
//            assignby, assigndt, notes, priority, category,
//            lat, lng, manu, item
//            FROM reports WHERE id = '" .$id. "' LIMIT 1";
  
//fuad:20211107          
$query = "SELECT id, rpt_txn, name, location,
            remark1, remark2, officer, status, area,
            reporter, reporter_email, reporter_phone,
            assignby, assigndt, notes, priority, category,
            lat, lng, manu, item, 
            product_category, product_subcategory, product_name, product_detail, product_manufacturer, price
            FROM reports WHERE id = '" .$id. "' LIMIT 1";
$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'],
        'name' => $row['name'],
        'location' => $row['location'],
        //'photo' => $row['photo'],
        //'photo2' => $row['photo2'],
        //'photo3' => $row['photo4'],
        //'photo4' => $row['photo4'],
        'status' => $row['status'],
        'remark1' => $row['remark1'],
        'remark2' => $row['remark2'],
        'officer' => $row['officer'],
        'status' => $row['status'],
        'area' => $row['area'],
        
        'reporter' => $row['reporter'],
        'rpt_email' => $row['reporter_email'],
        'rpt_phone' => $row['reporter_phone'],
        
        'assignby' => $row['assignby'],
        'assigndt' => $row['assigndt'],
        'notes' => $row['notes'],
        'priority' => $row['priority'],
        'category' => $row['category'],
        
        'lat' => $row['lat'],
        'lng' => $row['lng'],
        
        'manu' => $row['manu'],
        'item' => $row['item'],  
        
        'pcategory' => $row['product_category'],
        'psubcategory' => $row['product_subcategory'], 
        'pname' => $row['product_name'], 
        'pdetail' => $row['product_detail'], 
        'pmanufacturer' => $row['product_manufacturer'], 
        'price' => $row['price'], 
        
    );
}

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

echo $result;

?>