<?php
			
			session_start();
			include("corps_html.php");
			include('database.php');
			include('config.php');
		
?>	
<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>


$(document).ready(function()
{
		$(".selection_famille").change(function()
		{
			var nom_famille = $(this).val();
			var dataString = 'nom_famille='+ nom_famille;
			//alert(nom_famille);

			$.ajax
			({
				type: "POST",
				url: "ajax_projet.php",
				data: dataString,
				cache: false,
				success: function(html)
				{
					//alert(html);
					$(".selection_projet").html(html);
				}
			});

		});

});

function valider_creer_bloc()
{

			nom_bloc = document.getElementById('nom_bloc').value;
			selection_famille = document.getElementById('selection_famille').value;
			selection_projet = document.getElementById('selection_projet').value;
			date_dispo_schema = document.getElementById('date_dispo_schema').value;
			date_debut_layout = document.getElementById('date_debut_layout').value;
			duree_jours = document.getElementById('duree_jours').value;
			date_fin = document.getElementById('date_fin').value;
			owner = document.getElementById('owner').value;
			recommandations = document.getElementById('recommandations').value;
			
			//alert(nom_bloc + " " + selection_famille + " " + selection_projet + " " + date_dispo_schema + " " + date_debut_layout + " " + duree_jours + " " + date_fin + " " + owner + " " + recommandations);
				
			if(nom_bloc.length  == '' || owner.length == '' || selection_famille == 'vide' || selection_projet == 'vide')
			{
						$(function()
						{
									$( "#message_incomplet" ).dialog({
									modal: true,
									title: "Infos",
									buttons: {
												Ok: function()
												{
													$( this ).dialog( "close" );
												}
											 }
										});
						});
			}
			else
			{
				var data = 'nom_bloc='+nom_bloc
				+'&selection_famille='+selection_famille
				+'&selection_projet='+selection_projet
				+'&date_dispo_schema='+date_dispo_schema
				+'&date_debut_layout='+date_debut_layout
				+'&duree_jours='+duree_jours
				+'&date_fin='+date_fin
				+'&owner='+owner
				+'&recommandations='+recommandations;
				
				//alert(data);

				$.ajax({
							type: "POST",
							url: "sauver_bloc.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_bloc_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 bloc</span></h2>
							</div>
								
							<!-- Single Page -->
							<div class="page">
								
							<div class="examples">
							
							<!----
							Nom du bloc	
							Choix de la famille
							Choix du projet :
							-->
							
							<table style="width:100%" border="1" cellspacing="1" cellpadding="5" bgcolor="#D5D5D5">		
							
									<tr bgcolor="#FFFFFF">
									<td>Nom du bloc :</td>
									<td><input type="text" id="nom_bloc" name ="nom_bloc" size="30" maxlength="30" value="" > *</td>
									</tr>
									
									<tr bgcolor="#FFFFFF">
									<td>Choix de la famille :</td>
									<td >
									<select id="selection_famille" name="selection_famille" class="selection_famille">
									<option value="vide">- - - Selection famille - - -</option>
<?php
									for ($i=0; $i < count($tab_famille_projet) ; $i++) 
									{
										echo '<option value="'.$tab_famille_projet[$i].'">'.$tab_famille_projet[$i].'</option>';
									}
?>
									</select> *
									</td>
									</tr>
									
									<tr bgcolor="#FFFFFF">
									<td>Choix du projet :</td>
									<td><select id="selection_projet" name="selection_projet" class="selection_projet">
									<option selected="selected">- - - Selection projet - - -</option>
									</select> *
									</tr>
									</td>
									
									<tr>
									<td>Schéma disponible :</td>
									<td><input type="text" id="date_dispo_schema" name="date_dispo_schema"></td>
									</tr>
									
									<tr>
									<td>Début Layout :</td>
									<td><input type="text" id="date_debut_layout" name="date_debut_layout"></td>
									</tr>
									
									<tr>
									<td>Durée prévue:</td>
									<td>						
									<input type="text" size="12" id="duree_jours" name="duree_jours"  value="" > en jours
									<input type="submit" name="calculer" value="Calculer" />
									</td>
									</tr>		
									
									<tr>
									<td>Estimation :</td>
									<td><input type="text" size="12" id="date_fin"  name="date_fin" value="" > </td>
									</tr>
									
							

									<tr>
									<td>Owner :</td>
									<td><input type="text" id="owner" name="owner" size="30" maxlength="30" value=""  > *</td>
									</tr>
							
									<tr>
									<td>Recommandations :</td>
									<td><textarea id="recommandations" name="recommandations" rows="8" cols="60" ></textarea></td>
									</tr>

									</table>		
						
							
									<br/><br/>
							<input class="btn btn-primary" type="submit" value="Ajouter" name="ajouter" onclick="valider_creer_bloc()" />
		
							<!------->
							
							</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>
			
			
			<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 bloc a été enregistré dans la database.
			</p>
			</div>
			
			<div id="message_bloc_existe" style="display: none">
			<p>
			<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
			Le bloc existe déjà dans la database !.
			</p>
			</div>
			

</body>
</html>
