<?php

// array for JSON response
$response = array();

// include db connect class
require_once __DIR__ . '/db_config.php';


if (isset($_POST['ticket'])) {

    $con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysql_error());
    $ticket=$_POST['ticket'];
    $cname=$_POST['cname'];
    $email=$_POST['mail'];
    $s=$_POST['status'];
    
    if($s=="accept"){
        $status="underprogress";
        $dtcolumn="accepteddateandtime";
        $by="acceptedby";
    }else{
        $status="rejected";
        $dtcolumn="rejecteddateandtime";
        $by="rejectedby";
    }
    
    date_default_timezone_set('Asia/Calcutta');
    $dt=date('Y-m-d H:i:s');

    $query="UPDATE tickets SET ticketstatus='$status',$dtcolumn='$dt',$by='$email' WHERE ticketnumber='$ticket' AND companyname='$cname' AND Assignedto='$email'";
    if (mysqli_query($con,$query)) {
        $response["s"] = 1;
    } else {
        $response["s"] = 0;
    }
    mysqli_close($con);
}
     // echoing JSON response
    echo json_encode($response);

?>