<?php
session_start();
if(!isset($_SESSION['id']) || $_SESSION['id']=='')
{
    http_response_code(401);
    echo json_encode('Authentication Problem');
    exit;
}


/*include_once "../ichat/admin/route.php";
require_once 'database.php';
if(isset($_SESSION[$elhash]) && $_SESSION[$elhash] != "") { 
    $random_hash = $_SESSION[$elhash];
} else {
    $random_hash = uniqid();
    $_SESSION[$elhash] = $random_hash;
}*/


require_once 'database.php';

class Submit extends database
{
    public function index($data,$id)
    {
        $where['id']=$id;
        return $this->update('orders', $data, $where);
    }
}

if(!isset($_POST['data']) || $_POST['data']== "")
{
    http_response_code(400);
    echo json_encode(['Stage Not Found']);
    exit;
}

$data = $_POST['data'];
/*if($data['stage']=='1')
{
	$data['stage1']='1';
	unset($data['stage']);
}
elseif($data['stage']=='2')
{
	$data['stage2']='1';
	unset($data['stage']);
}
elseif($data['stage']=='3')
{
	$data['stage3']='1';
	unset($data['stage']);
}
elseif($data['stage']=='4')
{
	$data['stage4']='1';
	unset($data['stage']);
} */
if($data['stage']=='')
{
    http_response_code(400);
    echo json_encode(['Stage Not Found']);
    exit;
}

$ins = new Submit();
$id=$data['order_id'];
unset($data['order_id']);
$msg = "";
$res = $ins->index($data,$id);
if($res)
{
    http_response_code(200);
    echo json_encode('Completed Successfully');
    exit;
}
                
http_response_code(500);
echo json_encode(['Something went wrong']);
exit;
?>