<?php

require_once __DIR__ . '/db_config.php';
require_once __DIR__ . '/notify.php';

$r = array();

if (isset($_POST["id"]) ) {
 
$report_id=$_POST["id"];
$cname=$_POST["cname"];
$user_id=$_POST["email"];
$emp_id=$_POST["emp_id"];

$reason="NA";
if(isset($_POST["reason"])){
    $reason = $_POST["reason"];
}

date_default_timezone_set("Asia/Calcutta");   //India time (GMT+5:30)
$datetime=date('Y-m-d H:i:s');
$status="rejected";

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

$query="UPDATE defect_report 
    SET rejected_status_DT='$datetime',status='$status',rejected_user_id='$user_id',reject_reason='$reason' 
    WHERE report_id='$report_id' AND companyname='$cname'";

$insertQuery="INSERT INTO defect_report_status_log(companyname,status,status_DT,user_id,datetime,report_id) 
         VALUES ('$cname','$status','$datetime','$user_id','$datetime','$report_id')";
         
    $result=mysqli_query($con,$query) && mysqli_query($con,$insertQuery);
    if($result){
        $r["s"] = 1;
        $noity=new notify();
        $message=$report_id.' '.'have been Rejected';
        $noity->send($con,$emp_id,$report_id,$message);
    }else{
        $r["s"] = 0;
    }

mysqli_close($con);

}

echo json_encode($r,JSON_UNESCAPED_SLASHES);


?>