<?php
	
	//-----------------------------------------------------------------------------
	$sonde_exists_erreur = 0;

	//-----------------------------------------------------------------------------
	date_default_timezone_set('Europe/Paris');
	$marqueur_temps_maintenant = time();
	$marqueur_temps_maintenant = mktime(0, 0, 0, date("m", $marqueur_temps_maintenant)  , date("d", $marqueur_temps_maintenant) + 1, date("Y", $marqueur_temps_maintenant) );

	//-----------------------------------------------------------------------------
	$query = "SELECT aqcm_SITE_ID,aqcm_SERVER_PWD,aqcm_T_MAX FROM AQCM05_SONDES_MESURES WHERE (aqcm_MAC='" . $mac . "')";
	
	//echo $query . "</br>";

	$result = mysqli_query($link, $query); 
	
	if ( ! $result ) {	
		$sonde_exists_erreur = 2;
	}
	else {
		if ( mysqli_num_rows($result) != 1 ) {	
			$sonde_exists_erreur = 3;
		}
		else {
			
			if ( $row = mysqli_fetch_array($result, MYSQLI_BOTH) ) {
				
				extract($row);

				if (    ! ( password_verify($sent_SERVER_PWD, $aqcm_SERVER_PWD ) ) 
					    OR ( $aqcm_SITE_ID != $sent_SITE_ID ) 
					    OR ( $aqcm_T_MAX   <= $marqueur_temps_maintenant ) 
					) {
					$sonde_exists_erreur = 5;
				} 
				else {
					$sonde_exists_erreur = 0;
				}
			}
			else {
				$sonde_exists_erreur = 4;
			}
			
		}
	}

?>
