<?php
	include '../db/db.php';
	session_start();
	$log=htmlspecialchars(trim($_SESSION['user']), ENT_QUOTES, 'UTF-8');
	if (empty($log)) {
	     
	  $redirectUrl = "index.php";
	  echo "<script type=\"text/javascript\">";
	  echo "window.location.href = '$redirectUrl'";
	  echo "</script>";
		 
	}

	if (array_key_exists('cart_details_load', $_POST)) {//data table
	    $sql = "SELECT  * FROM order_details WHERE order_status = '3'" ;

		//echo $sql;
	    $data = array();
	    $result = mysqli_query($conn,$sql);
	    while ($row = mysqli_fetch_assoc($result)) {
	        $data[] = $row;
	    }
	    echo json_encode($data);
	}
	if (array_key_exists('deliver_order', $_POST)) {//data table
		$row_id=htmlspecialchars(trim($_POST['row_id']), ENT_QUOTES, 'UTF-8');
	    $sql = "UPDATE order_details SET order_status ='3' WHERE id= '$row_id'";
		$result = mysqli_query($conn, $sql);
		if ($result) {
			$response['status'] = "ok";
		}else{
			$response['status'] = "err";
		}
		echo json_encode($response);
	}
	if (array_key_exists('reject_order', $_POST)) {//data table
		$row_id=htmlspecialchars(trim($_POST['row_id']), ENT_QUOTES, 'UTF-8');
	    $sql = "UPDATE order_details SET order_status ='2' WHERE id= '$row_id'";
		$result = mysqli_query($conn, $sql);
		if ($result) {
			$response['status'] = "ok";
		}else{
			$response['status'] = "err";
		}
		echo json_encode($response);
	}

	if (isset($_POST['reasons'])) {//data table
		$row_id=htmlspecialchars(trim($_POST['id_r']), ENT_QUOTES, 'UTF-8');
		$val=htmlspecialchars(trim($_POST['reasons']), ENT_QUOTES, 'UTF-8');
	    $sql = "UPDATE order_details SET order_status ='$val' WHERE id= '$row_id'";
		$result = mysqli_query($conn, $sql);
		if ($result) {
			$response['status'] = "ok";
		}else{
			$response['status'] = "err";
		}
		echo json_encode($response);
	}
?>