<?php

if (isset($_POST['status'])) {
    include 'dbconnect.php';
    $statusTokens = array_map(function($statusTokens) {
    return $statusTokens['statusOwner'];
    }, json_decode($_POST['statusDrawer'], true));
    $statusTokenString = "'" . implode("','", $statusTokens) . "'";
    date_default_timezone_set('Africa/Nairobi');
    $twentyFourHoursAgo = date('Y-m-d H:i:s', strtotime('-24 hours'));
    $query = "SELECT * FROM status WHERE userid IN ($statusTokenString) AND timestamp >= '$twentyFourHoursAgo' ORDER BY id DESC";
    $result = pg_query($db, $query);
if ($result) {
    $status = array();
    while ($row = pg_fetch_assoc($result)) {
    $status[] = $row;
    }
    echo json_encode($status);
}
 else {
    $failed = [
    'success' => false,
    'message' => 'Database error'
];
echo json_encode($failed);
 }
}
?>