<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8"/>
		<title>Création des parcours</title>
		<link rel="shortcut icon" type="image/x-icon" href="../mmd/favicon.ico"/>
		<link rel="stylesheet" type="text/css" href="../style.css"/>
		<link rel="stylesheet" type="text/css" href="style.css"/>

		<script src="javaParcours.js" type="text/javascript"></script>
		<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
		<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true"></script>
		<script src="//google-maps-utility-library-v3.googlecode.com/svn/trunk/geolocationmarker/src/geolocationmarker-compiled.js"></script>

		<script>
			//Recuperation des informations sur le start
			function getInfosDepart(str) {
				if (str=="") {
					document.getElementById("pointDepart").innerHTML="";
					return;
				} 
				if (window.XMLHttpRequest) {
				//Pour IE7, Firefox, Chrome, Opera, Safari
					xmlhttp=new XMLHttpRequest();
				} else { //Pour IE6 et IE5
					xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				xmlhttp.onreadystatechange=function() {
					if (xmlhttp.readyState==4 && xmlhttp.status==200) {
						document.getElementById("pointDepart").innerHTML=xmlhttp.responseText;
						//console.log(xmlhttp.responseText);
						pointStartEnd(xmlhttp.responseText, 0);
					}
				}
				xmlhttp.open("GET","codeGet/getPointDepart.php?q="+str,true);
				xmlhttp.send();
			}//getInfosDepart(str)

			//Recuperer les infos sur les waypoints
			function getWaypoints(){
				var values = $('#listeWaypoints').val();
				if (values=="") {
				document.getElementById("wayPoints").innerHTML="";
				return;
					} 
					if (window.XMLHttpRequest) {
				//Pour IE7, Firefox, Chrome, Opera, Safari
				xmlhttp=new XMLHttpRequest();
					} else { //Pour IE6 et IE5
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
					}
					xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4 && xmlhttp.status==200) {
					document.getElementById("wayPoints").innerHTML=xmlhttp.responseText;
					//console.log(xmlhttp.responseText);
					getWayPoints(xmlhttp.responseText); //;49.188779;-0.363831;;49.188113;-0.362346;;49.188022;-0.359942; 
				}
					}
					xmlhttp.open("GET","codeGet/getWaypoints.php?q="+values,true);
					xmlhttp.send();
			}//getWaypoints

			//Recuperer les information sur le end
			function getInfosEnd(str){
					if (str=="") {
				document.getElementById("pointEnd").innerHTML="";
				return;
					} 
					if (window.XMLHttpRequest) {
				//Pour IE7, Firefox, Chrome, Opera, Safari
				xmlhttp=new XMLHttpRequest();
					} else { //Pour IE6 et IE5
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
					}
					xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4 && xmlhttp.status==200) {
					document.getElementById("pointEnd").innerHTML=xmlhttp.responseText;
					//console.log(xmlhttp.responseText);
					pointStartEnd(xmlhttp.responseText, 1);
				}
					}
					xmlhttp.open("GET","codeGet/getPointEnd.php?q="+str,true);
					xmlhttp.send();
			}//getInfosEnd
		</script>

	</head>
	<body>
		<a href="../"><div class="back_arrow"></div></a>
		<style type="text/css">
		.back_arrow {
			background: url('../mmd/return.svg') no-repeat center;
			cursor: pointer;
			position: absolute;
			top: 50px;
			left: 50px;
			width: 50px;
			height: 50px;
			opacity: 1;
		}

		.back_arrow:hover {
			opacity: 0.5;
		}
		</style>

		<?php

			// connexion à la base
			$db = mysql_connect('localhost', 'root', 'm148r43a9Y@%Z')	or die('Erreur de connexion '.mysql_error());
			
			// sélection de la base	
			mysql_select_db('smartpassTest2',$db)	or die('Erreur de selection '.mysql_error()); 
			 
			 
			$ip = $_SERVER['REMOTE_ADDR'];// on récupère l'ip

		?>
		<h1>Création des parcours</h1>
		<section id="mapSection"></section>



		<?php
		 
			$select = mysql_query("SELECT id, NomDeLetablissement FROM InformationsGenerales");
			echo '<form method="post" action="recuperation.php">';

			//Start Point
			echo '<h2>Start Point</h2>';
			echo '<select name="start" onchange="getInfosDepart(this.value)">';
			while($fetch = mysql_fetch_array($select)){
		?>	
			<option value="<?php echo $fetch['id']; ?>"><?php echo $fetch['NomDeLetablissement']; ?></option>	
		<?php
			}
			echo '</select>';

			//WayPoints
			$select1 = mysql_query("SELECT id, NomDeLetablissement FROM InformationsGenerales");
			echo '<h2>Ways Points</h2>';
				echo '<select name="listePoints[]" id="listeWaypoints" multiple onchange="getWaypoints()">';
				while($fetch = mysql_fetch_array($select1)){
				?>	
					<option value="<?php echo $fetch['id']; ?>"><?php echo $fetch['NomDeLetablissement']; ?></option>	
					<?php
				}
				echo '</select>';

				//End Point
			$select2 = mysql_query("SELECT id, NomDeLetablissement FROM InformationsGenerales");
			echo '<h2>End Point</h2>';
				echo '<select name="end" onchange="getInfosEnd(this.value)">';
				while($fetch = mysql_fetch_array($select2)){
				?>	
					<option value="<?php echo $fetch['id']; ?>"><?php echo $fetch['NomDeLetablissement']; ?></option>	
					<?php
				}
				echo '</select>';
			echo '<h2>Nom du parcours:<h2>';
			echo '<input type="text" name="nom" placeholder="Nom du Parcours" required />';
			echo '<input type="submit" value="Valider" name="construction" class="myButton"/>';

		?>

		<div id = "pointDepart" style = "display:none;"></div>
		<div id = "pointEnd" style = "display:none;"></div>
		<div id = "wayPoints" style = "display:none;"></div>

	</body>
</html>