<?php

require 'db.php';

$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
if(isset($postdata) && !empty($postdata))
{

$orderid = mysqli_real_escape_string($con, trim($request->value));
$delicode = mysqli_real_escape_string($con, trim($request->status));

$sql = "SELECT * FROM orders where order_id = '$orderid'";
$result = mysqli_query($con,$sql);
if($rows = mysqli_fetch_assoc($result))
{
	$status = $rows['status'];
}

if($status == "processing" && $delicode != null)
{
    if($delicode != null && $orderid != null)
    {
        $sql = "UPDATE orders set status = 'processing', rid='$delicode', r_status = 'pending',  o_status='3'  where order_id = '$orderid'";
        $result = mysqli_query($con,$sql);
        if($result)
        {
            $rows = array('status'=>true,'message' => 'Assist Re-Assigned');
            echo json_encode($rows);
        }
        else
        {
            $rows = array('status'=>false,'message' => 'Order Missing');
            echo json_encode($rows);
        }
    }
    else
    {
        $rows = array('status'=>false,'message' => 'Assist Missing');
        echo json_encode($rows);  
    }
}
else
{
    $rows = array('status'=>false,'message' => 'Order Status Error');
    echo json_encode($rows); 
}
}

?>