<?php

require_once __DIR__ . '/db_config.php';

$r = array();

$r["tickets"] = array();

if (isset($_POST["mail"]) ) {
 
$cname=$_POST["cname"];
$email=$_POST["mail"];
date_default_timezone_set('Asia/Calcutta');
$date=date('Y-m-d');

$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysql_error());

$assignQuery="SELECT f.customername,f.atmid as companyname,f.latitude,f.longitude,f.location,f.atmphonenumber,t.ticketnumber,
t.questionorcallreason,t.assigneddateandtime,t.ticketnumber,t.companyname as cname,t.ticketstatus,t.ticketstage,t.priority,t.atmid 
FROM tickets t 
INNER JOIN atmdetails f ON t.atmid=f.Id and t.customername=f.customername 
WHERE Assignedto='$email' AND t.companyname='$cname' AND (t.ticketstatus='assigned' OR t.ticketstatus='underprogress') 
ORDER BY t.assigneddateandtime ASC";

$result=mysqli_query($con,$assignQuery);

if(!empty($result) && mysqli_num_rows($result) > 0){
    while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
        array_push($r["tickets"], $row);
    }
}

}

echo str_replace("no data available","",json_encode($r));
//echo json_encode($r);

?>