<?php
			session_start();
			//include("corps_html_bis.php");
			include("corps_html.php");
			include('database.php');
			include('config.php');
			DB_connexion(); 
	
?>	

<link rel="stylesheet" type="text/css" href="style.css">
<link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<script>

function active_champ_projet()
{
			
			document.getElementById("champ_projet").style.visibility='visible';

			nom_famille = document.getElementById('nom_famille').value;
			var dataString = 'nom_famille='+ nom_famille;
			
			var bouton = "<input class='btn btn-primary' type='submit' value='Ajout' id='ajout' name='ajout' onclick='creer_tapeout()' >"; 
			
			$.ajax
			({
				type: "POST",
				url: "ajax_tapeout_liste_projet.php",
				data: dataString,
				cache: false,
				success: function(html)
				{
					//alert(html);
					document.getElementById('champ_projet').innerHTML = html + bouton;

				
				}
			});
			
}



function creer_tapeout()
{
			var nom_famille = document.getElementById('nom_famille').value;
			var nom_projet = document.getElementById('nom_projet').value;
			var nom_revision = document.getElementById('nom_revision').value;
			var owner = document.getElementById('owner').value;
		
			var data = 'nom_famille='+nom_famille
				+'&nom_projet='+nom_projet
				+'&nom_revision='+nom_revision
				+'&owner='+owner;
			
			alert("toto");
			
			$.ajax({
					type: "POST",
					url: "sauver_tapeout.php", 
					data: data,
					success: function (reponse) 
					{
						if(reponse == "ok")
						{
							$( "#message_sauvegarde" ).dialog({
								modal: true,
								title: "Infos",
								buttons:{
											Ok: function()
											{
												$( this ).dialog( "close" );
											}
										}
															});
						}
						if(reponse == "erreur")
						{
							$( "#message_projet_existe" ).dialog({
								modal: true,
								title: "Infos",
								buttons: {
											Ok: function()
											{
												$( this ).dialog( "close" );
											}
										 }
																});

						}
									
					},
							
					error : function(request)
					{
						console.log(request.responseText);
					}
			});
			
			
}
</script>

<body>

	<div class="layout">

<?php
	include("header.php");
?>	
		
<!-- Main -->
		<div class="main">
			<div class="container">
				<div class="row">
				
				<div class="col-md-12">
						<!-- Content -->
						<div class="content">
							<div class="page-header">
								<!--<h3>Interface du gestionnaire de projets</h3> -->
								<h2><i class="icon-bullhorn"></i> <span>Créer un Tapeout</span></h2>
							</div>
								
							<!-- Single Page -->
							<div class="page">
								
							<div class="examples">
							
							<!------>
							
							<div id='champ_famille' > 
							<p>				
							<div class="center">
			
							<label>Famille de produit: </label>
							<select name='nom_famille' id='nom_famille' onchange='active_champ_projet()'>
							<option value="vide">- - - Choisissez - - -</option>
<?php
							for($i=0; $i < count($tab_famille_projet) ; $i++) 
							{
								echo '<option value="'.$tab_famille_projet[$i].'">'.$tab_famille_projet[$i].'</option>'; 
							}
?>
							</select>
							</div>		
							</p>		
							</div>
							
							
							<div id='champ_projet' style="visibility: hidden;"  >  
							<div class="center">					
							</br>
							</div>					
							</div> 

							</br>
														
							<div id='champ_bloc' style="visibility: hidden;"  >  
							<div class="center">					
							</br>
							</div>  					
							</div> 
						
							<!------->
							
							</div>	
								
							<div class="clear"></div>

							<div class="clear"></div>
							</div>
							<!-- End Single Page -->
						</div>
						<!-- End Content -->
				</div>
					
				</div>
			</div>
		</div>
<!-- End Main -->
		
<?php
	include("footer.php");
?>		
			<div id="message_incomplet" style="display: none">
			<p>
			<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
			Champs obligatoire(s) vide !.
			</p>
			</div>
			
			<div id="message_sauvegarde" style="display: none">
			<p>
			<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
			Le projet a été enregistré dans la database.
			</p>
			</div>
			
			<div id="message_projet_existe" style="display: none">
			<p>
			<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
			Le projet existe déjà dans la database !.
			</p>
			</div>


	</div>

</body>
</html>
