<?php
	
	error_reporting(0);
	
	$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());
	}
	
	
	
	
		// echo "<script type=\"text/javascript\" src=\"droits.js\"></script>";  

?>

<script>	        
function Deplacer(l1,l2) {
		if (l1.options.selectedIndex>=0) {
			o=new Option(l1.options[l1.options.selectedIndex].text,l1.options[l1.options.selectedIndex].value);
			l2.options[l2.options.length]=o;
			l1.options[l1.options.selectedIndex]=null;
		}else{
			alert("Aucune date sélectionné !.");
		}
	}  

function aaenregistrer() 
{ alert("Bingo");
}
	
function enregistrer() 
{
	
		var title = "";
		var url = "";
		var data = "";

		var optlist = document.getElementById("liste2");
		var size = optlist.options.length;
		
		
		//alert(optlist);
		
	   // var selectElmt = document.getElementById("selection_identifiant");
		//var user = selectElmt.options[selectElmt.selectedIndex].text;

		//alert(user);

		for(i = 0; i < size; i++) // size
		{
			title = optlist.options[i].text;
			title = optlist.options[i].value;
			
			//var ele = document.getElementById('liste2').value;
			
			
		//	var i = title.selectedIndex;
		//alert(i);
			
			if(data != "") 
			//data +="&";
			data +=" ";
			//data += "tab" + String(i) + "=" + title;
			
			data += title;
		}    	 
	
		alert(data);
	
	    var XHR = null;

		if(window.XMLHttpRequest) // Firefox
			XHR = new XMLHttpRequest();
		else if(window.ActiveXObject) // Internet Explorer
			XHR = new ActiveXObject("Microsoft.XMLHTTP");
		else { // XMLHttpRequest non supporté par le navigateur
			alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
			return;
		}
	
	
		var url = "enregistre_reservation.php?listing=" +data;
		//var url = "reponse_ajax.php?listing=" +data + "&id=" +user;
		
		
		XHR.open("GET",url, true);

		XHR.onreadystatechange = function attente() 
		{

			if(XHR.readyState == 4)   
		  	  {
				document.getElementById("div1").innerHTML = "Mise a jour ";
				alert("Mise à jour");

   			  }
		}
		
		XHR.send(null);		
		return;
}
	
	
</script>

		<form action="" method="get" id="reservation" name="reservation" >
		
		<table align="left" cellspacing="1" cellpadding="5" border="0" bgcolor="#D5D5D5" width="800">
		<tr bgcolor="#F1F3F5">
		<td colspan="4">Réservation disponible :</td>
		<tr bgcolor="#FFFFFF">
		
		<td align="left">
	
		
<?php
		  
			
			
		$sql = 'SELECT * FROM reservation_2015 WHERE statut = "disponible"';
		$result = mysql_query($sql);
		//$count  = mysql_num_rows($result);
		//$data = mysql_fetch_array($result);
		
		echo '<select id="liste1" name="selection_projet" size="6" style="width:250px" align=top >';
		
		while ($data = mysql_fetch_array($result))
		{   $id =  $data['id'];
			$start =  $data['debut'];
			$stop = $data['depart'];
			$fusion = $start . " au " .$stop;
			echo "<option value=$id >$fusion</option>";
			
		}
		
		echo '</select>';
 ?>
 
 
 		</td>
		
		<td align="left" >
		<INPUT type="button" value="Ajouter >>>" onClick="Deplacer(this.form.liste1,this.form.liste2)">
		<BR><BR>
		<INPUT type="button" value="&lt;&lt;&lt; Enlever" onClick="Deplacer(this.form.liste2,this.form.liste1)">
		</td>
		
		<TD align="center"><BR>
		<SELECT align=top id="liste2" name="liste2" size=6 style="width:250px">

<?php
	/*	for($j=0;$j<=4;$j++) 
		   { echo "<option value=$j >$j</option>";
		   }*/
?>		   	
		</SELECT>
		</TD>	
		
		<input type="hidden" name="valide" id="valide" value="">
		<input type="hidden" name="selection_membre" id="selection_membre" value="">
				
		<tr bgcolor="#F1F3F5">
		<td colspan="4" align="center">
		<!-- <input type="buttont" name="soumettre" value="Soumettre" /> -->
		<INPUT type="button" value="Appliquer" onclick="enregistrer()">
		<!-- ;return(false)  -->
		</td>
		</tr>
		
		</table>
		</form>
		
		
		<div id="div1"></div>
		