<?php 

require_once '../includes/DbOperations.php';

$response = array();

if($_SERVER['REQUEST_METHOD'] == 'POST'){


	if(!empty($_POST['day']) and !empty($_POST['orders']) and !empty($_POST['user']) and !empty($_POST['status'])) {
		if(isset($_POST['day']) and isset($_POST['orders']) and isset($_POST['user']) and isset($_POST['status']) ) {
			$db =  new DbOperations();

			$result = $db -> createMondayOrder( $_POST['day'],$_POST['orders'], $_POST['user'],  $_POST['status']);
	

	if($result == 1){
				
				$response['error'] = false;
				$response['message'] = "Order created successfully";	
			}
			elseif($result == 0){
				$response['error'] = true;
				$response['message'] = "Order creation failed";
			}elseif($result == 5){
					$response['error'] = true;
				$response['message'] = "You have already ordered!";
			}

	}else{
		echo "no";
	}
}else{
			$response['error'] = true;
			$response['message'] = "Required fields are missing";
		}
}else{
	$response['error'] = true;
	$response['message'] = "Invalid Request";
}

echo json_encode($response);
?>