<?php
	
	//error_reporting(0);
	include('database.php');
	DB_connexion(); 
	
	header( 'content-type: text/html; charset=utf-8' );
	
	$id_reservation = $_GET['id'];
	
	if(isset($_POST['valide']) && $_POST['valide'] == "ok")
 	  {						
					$nom = $_POST['nom'];
					$prenom = $_POST['prenom'];
					$tel = $_POST['tel'];
					$email = $_POST['email'];
					$debut = $_POST['debut'];
					$depart = $_POST['depart'];
					$statut = $_POST['selection_status'];
					
					$sql = "UPDATE reservation SET 
					nom = '$nom',
					prenom = '$prenom',
					telephone = '$tel',
					email = '$email',
					debut = '$debut',
					depart = '$depart', 
					statut = '$statut'
					WHERE id='$id_reservation' ";
					echo $sql;	
					$requete = mysql_query($sql); 
		 			header("Location: liste_reservation.php");   
	}		

	if(isset($_POST['valide']) && $_POST['valide'] == "annule")
	{  
		header("Location: liste_reservation.php");   
	}			
		
	$requete =  "select * from reservation where id = '$id_reservation' ";
	$result = mysql_query($requete);
	$data = mysql_fetch_array($result);
	
	$id = $data['id'];
	$nom = $data['nom'];
	$prenom = $data['prenom'];
	$tel = $data['telephone'];
	$email = $data['email'];
	$debut = $data['debut'];
	$depart = $data['depart'];
	$statut = $data['statut']; 
	
?>
	
<script type="text/javascript">

function fct_soumettre()
{
	verif = confirm("Voulez vous vraiment modifier la base de donnée");
 	
 	if(verif == true)
 	  { document.getElementById('valide').value="ok";
 	  }
 	
 	if(verif == false)
 	  { document.getElementById('valide').value="stop";
 	  }	

} 

function fct_annuler()
{
 	document.getElementById('valide').value="annule";
} 

</script>

<form action="" method="post" id="editer_bloc" name="editer_bloc" >

		<input type="hidden" name="valide" id="valide" value="">


		<table align="left" cellspacing="1" cellpadding="5" border="0" bgcolor="#D5D5D5" width="800">
		<tr bgcolor="#F1F3F5">
		<td colspan="2">Réservation: <?php echo $id;?></td>
		</tr>
		</tr>
		
		</td>
		</tr>
						
		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">Nom :</td>
		<td align="left" valign="middle" colspan="1">
		<input type="text" name="nom" size="70" maxlength="20" value="<?php echo $nom;?>" id="nom" >&nbsp;</td>
		</tr>
		
		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">Prénom :</td>
		<td align="left" valign="middle" colspan="1">
		<input type="text" name="prenom" size="70" maxlength="20" value="<?php echo $prenom;?>" id="prenom" >&nbsp;</td>
		</tr>
		
		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">Téléphone :</td>
		<td align="left" valign="middle" colspan="1">
		<input type="text" name="tel" size="70" maxlength="20" value="<?php echo $tel;?>" id="tel" >&nbsp;</td>
		</tr>
		
		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">Email :</td>
		<td align="left" valign="middle" colspan="1">
		<input type="text" name="email" size="70" maxlength="20" value="<?php echo $email;?>" id="email" >&nbsp;</td>
		</tr>
		
		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">Début :</td>
		<td align="left" valign="middle" colspan="1">
		<input type="text" name="debut" size="70" maxlength="20" value="<?php echo $debut;?>" id="debut" >&nbsp;</td>
		</tr>
		
		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">Départ :</td>
		<td align="left" valign="middle" colspan="1">
		<input type="text" name="depart" size="70" maxlength="20" value="<?php echo $depart;?>" id="depart" >&nbsp;</td>
		</tr>		
		
		<tr bgcolor="#FFFFFF">
		<td align="right" valign="top">Statut :</td>
		<td align="left" valign="middle" colspan="1">
		<select name="selection_status" size="1" > 

<?php

	if($statut == "Reservation")
	{   echo '
		<option value="Reservation" selected >Reservation</option>
		<option value="Annulation">Annulation</option>
		<option value="Louer">Louer</option> 
		<option value="Paiement">Paiement</option>
		<option value="Terminer">Terminer</option>';
	}
	if($statut == "Annulation")
	{   echo '
		<option value="Reservation" >Reservation</option>
		<option value="Annulation" selected >Annulation</option>
		<option value="Louer">Louer</option> 
		<option value="Paiement">Paiement</option>
		<option value="Terminer">Terminer</option>';
	}
	if($statut == "Louer")
	{   echo '
		<option value="Reservation" >Reservation</option>
		<option value="Annulation" selected >Annulation</option>
		<option value="Louer" selected>Louer</option> 
		<option value="Paiement">Paiement</option>
		<option value="Terminer">Terminer</option>';
	}
	if($statut == "Paiement")
	{   echo '
		<option value="Reservation" >Reservation</option>
		<option value="Annulation" >Annulation</option>
		<option value="Louer">Louer</option> 
		<option value="Paiement" selected >Paiement</option>
		<option value="Terminer">Terminer</option>';
	}
	if($statut == "Terminer")
	{   echo '
		<option value="Reservation" >Reservation</option>
		<option value="Annulation" >Annulation</option>
		<option value="Louer">Louer</option> 
		<option value="Paiement" selected >Paiement</option>
		<option value="Terminer" selected >Terminer</option>';
	}
	
?>
 
		</select>
		</tr>
				
		<tr bgcolor="#F1F3F5">
		<td colspan="2" align="center">
		
		<input type='submit' name='soumettre' value='Soumettre' onClick="fct_soumettre()" />
		<input type='submit' name='Annuler' value='Annuler' onClick="fct_annuler()" />  
		
		</td>
		</tr>
		
		</table>
		</div>
		</div>
		
		</form>


		</body>
		</html>