<?php

require_once('Conn.php');
$conn = $connection;
require_once('complaint_hierarchy.php');
header('Content-Type: application/json');

if($_SERVER['REQUEST_METHOD'] != 'GET') {
    header('HTTPS/1.1 405');
    echo json_encode(array(["message" => "method not allowed" , "status" => "false"]));
    exit;
}


$query = "SELECT * FROM complaint_list";

$result = mysqli_query($connection , $query);
if($result) {
    $response = array();
    $i = 0;
    while($row = mysqli_fetch_assoc($result))  {
        $response[$i]['cid'] = $row['cid'];
        $response[$i]['details'] = $row['details'];
        $response[$i]['path'] = complaint_full_path($conn, $row);
        $response[$i]['priority'] = $row['priority'];
        $response[$i]['subdivision'] = $row['subdivision'];
        $response[$i]['code'] = $row['code'];
        $i++;        

    }

    echo json_encode($response);
}
else {
    echo json_encode(array(["message" => mysqli_error($connection) , "status" => "false"])); 
}

?>
