<?php
			
			session_start();
			include("corps_html.php");
			include('database.php');
			DB_connexion(); 
			
			if(isset($_POST['ajouter']) && $_POST['ajouter'] == "Ajouter")
			{ 
				
					//header("Location: rafraichir.php");
				
					$nom_bloc = $_POST['nom_bloc'];
	        		$nom_projet = $_POST['selection_projet'];
	        		$owner = $_POST['owner'];
					$recommandations = $_POST['recommandations'];
					$heure = date("H:i");
					$date = date("d-m-Y"); 
					$infos = $heure ." " .$date;
					
					$table = $nom_projet	."_data";
					echo $table ." " .$nom_bloc ." " .$infos ." " .$owner ." " .$recommandations; 
					
					$sql = "SELECT * FROM $table WHERE nom_bloc = '$nom_bloc' ";
 					$requete = mysql_query($sql);   
					$nb_resultats = mysql_num_rows($requete);
 
     				if( $nb_resultats > 0 )
     				{
           			    echo "<script>alert(\"Le bloc existe déjà dans la base de donnée. \")</script>"; 
        			}
        			else 
					{ 
						//nom_bloc 
						//owner 
						//recommandations 
						// infos
							
						$sql = "INSERT INTO $table (id, nom_bloc, owner, recommandations, infos ) 
						VALUES ( '0', '$nom_bloc' , '$owner', '$recommandations', '$infos' )";
						$requete = mysql_query($sql); 
						echo $sql;
						
						if (!$requete) 
						{
							die('Requête invalide : ' . mysql_error());
						}
						
						$_SESSION['creer_bloc'] = "bloc";	
					}
				
			}
?>	

<script>

function selection_bloc()
{
	
}

</script>

<style>
textarea {
   resize: none;
}
</style>

<body>

	<div class="layout">

<?php
	include("header.php");
?>	
		
<!-- Main -->
		<div class="main">
			<div class="container">
				<div class="row">
				
				<div class="col-md-8">
						<!-- 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">
							
							<!------>
							
							<form action="" method="post" id="ajouter_bloc" name="ajouter_bloc" >

							<table align="left" cellspacing="1" cellpadding="5" border="0" bgcolor="#D5D5D5" width="800">
							
						
							<tr bgcolor="#FFFFFF">
							<td align="right" valign="top">Nom du bloc :</td>
							<td align="left" valign="middle" colspan="1">
							<input type="text" name="nom_bloc" size="70" maxlength="20" value="" id="gg" >&nbsp;</td>
							</tr>
							
							<input type="hidden" name="valide" id="valide" value="">
							
							<tr bgcolor="#FFFFFF">
							<td align="right" valign="top">Choix du projet :</td>
							<td align="left" valign="middle" colspan="1">
							<select name="selection_projet" size="1" >
<?php
							$sql = "SELECT * FROM projet"; 
							$req = mysql_query($sql); 
  
							while($resultat = mysql_fetch_row($req))
							{  
								$tab_projet[]= $resultat[1];
								echo '<option value="'.$resultat[1].'">'.$resultat[1]; 
								echo '</option>'; 
							} 
				   
							echo '</select>'; 

?>							
							
							
							</tr>
							
							<tr bgcolor="#FFFFFF">
							<td align="right" valign="top">SchÃ©ma disponible :</td>
							<td align="left" valign="middle" colspan="1">
							<input type="text" size="12" id="date_schema" READONLY name="date_schema" value="dfds" title="DD-MM-YYYY" > 
							<input type="button" value="=" onclick="displayCalendarFor('date_schema');"></td>
							</tr>
							
							<tr bgcolor="#FFFFFF">
							<td align="right" valign="top">DÃ©but Layout :</td>
							<td align="left" valign="middle" colspan="1">
							<input type="text" size="12" id="date_debut" READONLY name="date_debut" value="fggf" title="DD-MM-YYYY" > 
							<input type="button" value="=" onclick="displayCalendarFor('date_debut');"></td>
							</tr>
							
							<tr bgcolor="#FFFFFF">
							<td align="right" valign="top">Durée prévue:</td>
							<td align="left" valign="middle" colspan="1">
							<input type="text" size="12" id="duree_jours" name="duree_jours" value="ggf" > en jours
							<input type="submit" name="calculer" value="Calculer" />
							</td>
							</td>
							</tr>

							<tr bgcolor="#FFFFFF">
							<td align="right" valign="top">Estimation:</td>
							<td align="left" valign="middle" colspan="1">
							<input type="text" size="12" id="date_fin"  READONLY name="date_fin" value="fedde" > 
							</td>
							</tr>

							<tr bgcolor="#FFFFFF">
							<td align="right" valign="top">Owner :</td>
							<td align="left" valign="middle" colspan="1">
							<input type="text" name="owner" size="30" maxlength="40" style="background-color: grey" onFocus="javascript: this.blur()" value="dgsdgs" id="">&nbsp;</td>
							</tr>

							<tr bgcolor="#FFFFFF">
							<td align="right" valign="top">Recommandations :</td>
							<td align="left" valign="middle" colspan="1">
							<textarea name="recommandations" rows="12" cols="70" id="">
							</textarea></td>
							</tr>
							
							</table>
							
							<br/><br/><br/><br/><br/><br/>
							<input class="btn btn-primary" type="submit" value="Ajouter" name="ajouter" />
							</form>
		
<?php							
							if($_SESSION['creer_bloc'] == "bloc")
							{
								$_SESSION['creer_bloc'] = "";		
								echo " Bloc insérer dans la database.";
							}			
?>		
		
							<!------->
							
							</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>

</body>
</html>
