<html>
<!--    cibl&egrave; par:  index.php
					[Tout autre fichier contenant un bouton "Menu principal"]

		cible:  	membre/membre.php
 -->

<!-- param�tre �mis:        -session_id         le num�ro de la session

	 param�tre recevable :  -session_id         le num�ro de la session
 -->

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Menu principal</title>
<link href="baseCSS.css" rel="stylesheet" type="text/css">


</head>
<body>


<?php 

require("outils/gui.php");
require("outils/mise_en_page.php");
require("outils/session.php");
require("historique.php");

//V�rifier si la session est valide.
$Bsession_id = $_GET["Bsession_id"];
verifierSession($Bsession_id);

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



historique("historique.txt","MENU PRINCIPAL",$Bsession_id);

print("<center><table cellspacing=0 cellpadding=0 width=750px border=0>");
print("<tr><td bgcolor=white width=27px><img src=coin-haut-gauche.gif></td>");
print("<td bgcolor=#636300><center><font face=Arial,Helvetica size=3 color=white><b>Menu principal de la gestion des bases</b></td>");
print("<td bgcolor=white width=27px><img src=coin-haut-droit.gif></td>");
print("</tr></table>");

print("<center><table cellspacing=0 cellpadding=0 width=750px border=0>");

print ("<tr><td bgcolor=#E7EFCE><BR><center>");
print("<form action=\"client/client.php?Bsession_id=".$_GET['Bsession_id']."\" method=\"post\" name=\"client\">");
print("<input type=\"hidden\" name=\"Bsession_id\" value=".$_GET['Bsession_id'].">");
print("<input type=\"submit\" name=\"client\" value=\"Gestion des clients\"></form>");

print("</center></td><td bgcolor=#E7EFCE><BR><center>");
print("<form action=\"calendrier/calendrier.php?Bsession_id=".$_GET['Bsession_id']."\" method=\"post\" name=\"calendrier\">");
print("<input type=\"hidden\" name=\"Bsession_id\" value=".$_GET['Bsession_id'].">");
print("<input type=\"submit\" name=\"calendrier\" value=\"Calendrier des disponibilit&eacute;\"></form>");

print("</center></td><td bgcolor=#E7EFCE><BR><center>");
print("<form action=\"contract/contract.php?Bsession_id=".$_GET['Bsession_id']."\" method=\"post\" name=\"contrat\">");
print("<input type=\"hidden\" name=\"Bsession_id\" value=".$_GET['Bsession_id'].">");
print("<input type=\"submit\" name=\"contrat\" value=\"Gestion des contrats\"></form>");

print("</center></td></tr><tr><td bgcolor=#E7EFCE><center>");
if ($privilege_base == 2)//protection pour les droits de modification
{
	print("<form action=\"reference/choix-ref1.php?Bsession_id=".$_GET['Bsession_id']."\" method=\"post\" name=\"constantes\">");
	print("<input type=\"hidden\" name=\"Bsession_id\" value=".$_GET['Bsession_id'].">");
	print("<input type=\"submit\" name=\"constantes\" value=\"Gestion des constantes\"></form>");
}	

print("</center></td><td bgcolor=#E7EFCE><center>");
print("<form action=\"rapport/rapport.php?Bsession_id=".$_GET['Bsession_id']."\" method=\"post\" name=\"rapport\">");
print("<input type=\"hidden\" name=\"Bsession_id\" value=".$_GET['Bsession_id'].">");
print("<input type=\"submit\" name=\"rapport\" value=\"Rapport\"></form>");


print("</center></td><td bgcolor=#E7EFCE><center>");
print("<form action=\"rapport/location.php?Bsession_id=".$_GET['Bsession_id']."\" method=\"post\" name=\"detail_location\">");
print("<input type=\"hidden\" name=\"Bsession_id\" value=".$_GET['Bsession_id'].">");
print("<input type=\"submit\" name=\"detail_location\" value=\"Liste des contrats\"></form>");

	
print("</center></td></tr></table>");

print("<center><table cellspacing=0 cellpadding=0 width=750px border=0>");
print("<tr><td bgcolor=white width=27px><img src=coin-bas-gauche.gif></td>");
print("<td bgcolor=#636300 width=746px></td>");
print("<td bgcolor=white width=27px><img src=coin-bas-droit.gif></td>");
print("</tr></table><BR><BR>");


print("</td></tr>");
print ("</table></div>");











//v&eacute;rification des colision
$sql_chalet = "SELECT base_ref1chalets.num_chalet, base_ref1chalets.nom
				FROM base_ref1chalets
				WHERE base_ref1chalets.actif = 'O';";
$result_chalet = mysql_query($sql_chalet)
	or die ("Ne peut lire dans la table ".$sql_chalet);
$num_chalet = mysql_numrows($result_chalet);
while ($row_chalet = mysql_fetch_row ($result_chalet))
{

	$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 = mysql_query($sql_cal)
		or die ("Ne peut lire dans la table ".$sql_cal);
	$num_cal = mysql_numrows($result_cal);

	while ($row_cal = mysql_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 = mysql_query($sql_contrat)
			or die ("Ne peut lire dans la table ".$sql_contrat);
			$row_contrat = mysql_fetch_row ($result_contrat);
			
			//va chercher les contrat 2
			$sql_contrat2 = "SELECT *  
		        FROM base_contrat
				WHERE code_contrat = '$contrat_prec';";
			$result_contrat2 = mysql_query($sql_contrat2)
			or die ("Ne peut lire dans la table ".$sql_contrat2);
			$row_contrat2 = mysql_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];
	}

	
}	














?>

<br><br>


<!--RESERVATION-->
<center><table cellspacing=0 cellpadding=0 width=750px border=0>
<tr><td bgcolor=white width=27px><img src=coin-haut-gauche.gif></td>
<td bgcolor=#636300><center><font face=Arial,Helvetica size=3 color=white><b>R&eacute;servation</b></td>
<td bgcolor=white width=27px><img src=coin-haut-droit.gif></td>
</tr></table>

<center>
<table cellspacing=0 cellpadding=0 width=750px border=1>
<?php 
$sql_reservation = "SELECT code_reservation, organisme, refere, tel, date_debut, date_fin, date_emission, commentaire, refere2
	   		  		  FROM base_reservation
					 WHERE actif = 'O'
					 ORDER BY date_emission;";

// Ex�cute la requ�te et mettre les r�sultats dans $result
$result_reservation = mysql_query($sql_reservation) or die ("Ne peut lire dans la table base_ref1chalets<br><br>".$sql_reservation);
// obtenir le nombre d'enregistrement. 0 si invalide, 1 si valide.
$num_reservation = mysql_numrows($result_reservation);

while ($row_reservation = mysql_fetch_row ($result_reservation))
{	
	//MISE A ZERO DES VARIABLES
	$code_reservation = 0;
	$organisme = 0;
	$refere = 0;
	$tel = 0;
	$date_debut = 0;
	$date_fin = 0;
	$date_emission = 0;	
	$commentaire = 0;	
		
	if ($num_reservation)//si il y a des reservation
	{
		$chalet_nom_tot = "";
		$code_reservation = ($row_reservation[0]);
		$organisme = ($row_reservation[1]);
		$refere = ($row_reservation[2]);
		$tel = ($row_reservation[3]);
		$date_debut = ($row_reservation[4]);
		$date_fin = ($row_reservation[5]);
		$date_emission = ($row_reservation[6]);
		$commentaire = ($row_reservation[7]);
		$refere2 = ($row_reservation[8]);

		//trouve tout les chalets pour la reservation
		$sql_chalet = "SELECT base_ref1chalets.nom, base_chalets.num_chalet
		   		  FROM base_ref1chalets, base_chalets
				 WHERE base_chalets.code_contrat = '$code_reservation'
		 			  AND base_chalets.actif = 'O'
					  AND base_chalets.reservation = 'O'
		              AND base_ref1chalets.num_chalet = base_chalets.num_chalet;";
		$result_chalet = mysql_query($sql_chalet) or die ("Ne peut lire dans la table base_ref1chalets<br><br>".$sql_chalet);
		$num_chalet = mysql_numrows($result_chalet);
		
		while ($row_chalet = mysql_fetch_row ($result_chalet))
		{
			$chalet_nom = ($row_chalet[0]);
			$chalet_nom_tot = ($chalet_nom_tot." ".$chalet_nom.",");		//INCR�MENTATION DES NOMS DE CHALETS DANS UNE SEUL VARIABLE
		}
		
		//AFFICHAGE DES DONNEES
		?>
		<tr>
			<td width=50px bgcolor=#C8DB8D>
			<h2><B>No</B>
		</td><td width=100px bgcolor=#C8DB8D>
			<h2><B>Fait par</B>
		</td><td  width=100px bgcolor=#C8DB8D>
			<h2><B>date emission</B>
		</td><td bgcolor=#C8DB8D>
			<h2><B>Chalet</B>
		</td><td width=180px bgcolor=#C8DB8D>
			<h2><B>Date</B>
		</td>
		
	
		</tr><tr>
		<td bgcolor=#E7EFCE>
			<?php print("<h2><a href=reservation/reservation-contract.php?Bsession_id=".$Bsession_id."&numero=".$code_reservation."&val_chalet=1>".$code_reservation."</a>"); ?>
		</td><td bgcolor=#E7EFCE>
			<?php print("<h2>".$refere); ?>
		</td><td bgcolor=#E7EFCE>
			<?php print("<h2>".$date_emission); ?>
		</td><td bgcolor=#E7EFCE>
			<?php print("<h2>".$chalet_nom_tot); ?>
		</td><td bgcolor=#E7EFCE>
			<?php print("<h2>Du ".$date_debut." au ".$date_fin); ?>
		</td>
		</tr><tr>
		<td colspan=2 bgcolor=#C8DB8D>
			<h2><B>Client</B>
		</td><td bgcolor=#C8DB8D>
			<h2><B>Telephone</B>
		</td><td colspan=2 bgcolor=#C8DB8D>
			<h2><B>Commentaire</B>
		</td>
		</tr>
	
		<tr>
		<td colspan=2 bgcolor=#E7EFCE>
			<?php print("<h2>".$organisme); ?>
		</td><td bgcolor=#E7EFCE>
			<h2><?php print("<h2>".$tel); ?>
		</td><td colspan=2 bgcolor=#E7EFCE>
			<h2><?php print("<h2>".$commentaire); ?>
		</td>
		</tr>
		
		<tr>
		<td colspan=5 bgcolor=#C8DB8D>
			<h2><B>R&eacute;f&eacute;r&eacute; par:</B> <?php print($refere2); ?>
		</tr>
	
		
		
		
		<!--SEPARATEUR-->
		<tr>
			<td colspan=6 bgcolor=#636300>
			<h2>&nbsp;
			</td>
		</tr>
		
		
	<?php 	
		
	}
	else
	{
		die ("Il y a un probl�me dans la base de donn&eacute;es reservation !".$sql_reservation);
	}	
}	
	
	
?>


</table>


<center><table cellspacing=0 cellpadding=0 width=750px border=0>
<tr><td bgcolor=white width=27px><img src=coin-bas-gauche.gif></td>
<td bgcolor=#636300 width=746px>
<?php 
print("<form action=\"reservation/reservation-contract.php?Bsession_id=".$_GET['Bsession_id']."\" method=\"post\" name=\"reservation\">");
print("<input type=\"hidden\" name=\"Bsession_id\" value=".$_GET['Bsession_id'].">");
print("<input type=\"submit\" name=\"reservation\" value=\"Ajouter une r&eacute;servation\"></form>");
?>



</td>
<td bgcolor=white width=27px><img src=coin-bas-droit.gif></td>
</tr></table><BR><BR>








</body>
</html>
