<html> 
 <head>
 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>DEBUG</title>
 </head>
<body>

<?php 
//Fichiers contenant les fonctions utilis�es dans le script.
require("../outils/gui.php");
require("../outils/session.php");
require("../outils/mise_en_page.php");


//V�rifier si la session est valide.
verifierSession($Bsession_id);

//V�rifier les droits de l'utilisateur.
$privilege_base = lirePrivilege($Bsession_id);
if ($privilege_base != 2)
	die("Vous n'avez pas les droits!");


print("Cette page compare chaque enregistrement du calendrier par chalet et sort les dates qui sont en double. Donc si une date apparait sous un chalet c'est qu'il y a 2 location du meme chalet &agrave; la meme date donc une erreur<BR><BR>");	
	
	

$sql_chalet = "SELECT base_ref1chalets.num_chalet, base_ref1chalets.nom
				FROM base_ref1chalets
				WHERE base_ref1chalets.actif = 'O';";
$result_chalet = mysqli_query($GLOBALS["___mysqli_ston"], $sql_chalet)
	or die ("Ne peut lire dans la table ".$sql_chalet);
$num_chalet = mysqli_num_rows($result_chalet);
while ($row_chalet = mysqli_fetch_row($result_chalet))
{
	print($row_chalet[1]."<BR>");


	$sql_cal = "SELECT date, etat, num_chalet,c1,c2,c3,c4  
		        FROM base_calendrier
				WHERE num_chalet = '$row_chalet[0]'
				ORDER BY date;";
	$result_cal = mysqli_query($GLOBALS["___mysqli_ston"], $sql_cal)
		or die ("Ne peut lire dans la table ".$sql_cal);
	$num_cal = mysqli_num_rows($result_cal);

	
	while ($row_cal = mysqli_fetch_row($result_cal))
	{
		if ($date_prec == $row_cal[0])
		{
			//va chercher le contrat_id de la colision	
			if($row_cal[3] <> 0){
				$contrat=$row_cal[3];
			}elseif($row_cal[4] <> 0){
				$contrat=$row_cal[4];
			}elseif($row_cal[5] <> 0){
				$contrat=$row_cal[5];
			}elseif($row_cal[6] <> 0){	
				$contrat=$row_cal[6];
			}
			
			//va chercher le contrat_id de la colision pr&eacute;c&eacute;dente
			if($c1_prec <> 0){
				$contrat_prec=$c1_prec;
			}elseif($c2_prec <> 0){
				$contrat_prec=$c2_prec;
			}elseif($c3_prec <> 0){
				$contrat_prec=$c3_prec;
			}elseif($c4_prec <> 0){	
				$contrat_prec=$c4_prec;
			}
			
			//va chercher le contrat 1
			$sql_contrat = "SELECT *  
		        FROM base_contrat
				WHERE code_contrat = '$contrat';";
			$result_contrat = mysqli_query($GLOBALS["___mysqli_ston"], $sql_contrat)
			or die ("Ne peut lire dans la table ".$sql_contrat);
			$row_contrat = mysqli_fetch_row($result_contrat);
			
			//va chercher les contrat 2
			$sql_contrat2 = "SELECT *  
		        FROM base_contrat
				WHERE code_contrat = '$contrat_prec';";
			$result_contrat2 = mysqli_query($GLOBALS["___mysqli_ston"], $sql_contrat2)
			or die ("Ne peut lire dans la table ".$sql_contrat2);
			$row_contrat2 = mysqli_fetch_row($result_contrat2);
			print("date=".$row_cal[0]." - Erreur entre le contrat no=
			<a href=\"../contract/gestion-contract.php?Bsession_id=$Bsession_id&code_contrat=$row_contrat[0]&code_client=$row_contrat[2]\">".$row_contrat[1]."</a>
			 et le contrat no=
			 <a href=\"../contract/gestion-contract.php?Bsession_id=$Bsession_id&code_contrat=$row_contrat2[0]&code_client=$row_contrat2[2]\">".$row_contrat2[1]."</a>, etat=".$row_cal[1]."<BR>");
			print("");				
		}
		$date_prec = $row_cal[0];
		$c1_prec = $row_cal[3];
		$c2_prec = $row_cal[4];
		$c3_prec = $row_cal[5];
		$c4_prec = $row_cal[6];
	}

	print("<HR>");
}	
	




?>

</body>
</html>	
