<?php

// D1  D2   

 //if($start_date < D1 &&  $end_date > D1)

 
function check_chevauchement($start_date, $end_date, $checked_date)
{
	$start_ts = strtotime($start_date);
	$end_ts = strtotime($end_date);
	$checked_ts = strtotime($checked_date);

	if($checked_ts >= $start_ts && $checked_ts <= $end_ts)
	{
		$res = "ok";
	}
	else
	{
		$res = "non";
    }
  
	return($res);
  
} 
 
 
	
	$user = "root";
	$password = "";
	$host = "localhost";
	$db = "test";

	$db_connection = mysql_connect($host, $user, $password);
	mysql_select_db($db, $db_connection); 
	
	if(!$db_connection)
	{
		die('Could not connect: ' . mysql_error());
	}
 
	mysql_select_db($db, $db_connection); 
	$sql = 'SELECT * FROM reservation WHERE statut = "reserver"';
	$result = mysql_query($sql);	
	
	while ($data = mysql_fetch_array($result))
	{
		$debut =  $data['debut'];
		$depart = $data['depart'];
		
		$debut_date = date("d-m-Y", strtotime($debut));
		$debut_ts = strtotime($debut_date);
		 
		
		$depart_date = date("d-m-Y", strtotime($depart));
		$depart_ts = strtotime($depart_date);
		
		$date1 = "08-07-2015";
		$date2 = "08-08-2015";

		
		$date1_date = date("d-m-Y", strtotime($date1));
		$date1_ts = strtotime($date1_date);
		
		$date2_date = date("d-m-Y", strtotime($date2));
		$date2_ts = strtotime($date2_date);
		
		echo $debut_ts  ."  "  .$date1_ts  ."  "  .$date2_ts  ."  "  .$depart_ts;  
		
		
		if($date1_ts < $debut_ts && $date2_ts > $depart_ts)
		{ echo "recouvrement";
		}
		
		
		
		
	}	
 
 
 
function check_in_range($start_date, $end_date, $checked_date)
{
	$start_ts = strtotime($start_date);
	$end_ts = strtotime($end_date);
	$checked_ts = strtotime($checked_date);

	if($checked_ts >= $start_ts && $checked_ts <= $end_ts)
	{
		$res = "ok";
	}
	else
	{
		$res = "non";
    }
  
	return($res);
  
}

/*
$start_date = date("d-m-Y", strtotime('10-12-2014'));
$end_date =   date("d-m-Y", strtotime('18-12-2014'));
$checked_date =   date("d-m-Y", strtotime('21-12-2014'));


echo $start_date;
echo '<br>';
echo $end_date;

$val = check_in_range($start_date, $end_date, $checked_date);

if($val == "ok")
{	echo "Recouvrement";
}
else {
		echo "pas de recouvrement";
  }*/
?>