<?php

			session_start();
			include("corps_html.php");
			include('database.php');
			include('config.php');
			$nom_projet = "pipo";
			
			
			
function conversion_taille_fichier($bytes, $decimals )
{
			$sz = 'BKMGTP';
			$factor = floor((strlen($bytes) - 1) / 3);
			return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . $sz[$factor] ."o";
}

function association_extension($extension)
{
			$extension = strtolower($extension);	

			switch ($extension)
			{
				case "bmp": $ext="Image"; break;
				case "png": $ext="Image"; break;
				case "jpg": $ext="Image"; break;
				case "jpeg": $ext="Image"; break;
				case "gif": $ext="Image"; break;
				case "txt": $ext="Text File"; break;
				case "log": $ext="Log File"; break;
				case "pdf": $ext="PDF"; break;
				case "doc": $ext="Word"; break;
				case "docx": $ext="Word"; break;
				case "xls": $ext="Word"; break;
				case "xlsx": $ext="Excel"; break;
				case "csv": $ext="Excel"; break;
				case "ppt": $ext="PPT"; break;
				case "pptx": $ext="PPT"; break;
				case "zip": $ext="ZIP"; break;
				case "gz": $ext="ZIP"; break;
				case "gzip": $ext="ZIP"; break;
				case "rar": $ext="ZIP"; break;
				case "tar": $ext="Archive"; break;
				case "gds": $ext="Stream"; break;
				case "xml": $ext="XML"; break;
				case "dxf": $ext="Drawing"; break;
				case "bak": $ext="Backup"; break;
            
				default: $ext = "not define";
			}
		  
			return($ext);
		  
}
				
?>	

<link rel="stylesheet" type="text/css" href="style.css">

<link rel="stylesheet" href="fichier.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>

<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<!--
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/themes/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css" />
-->

<script>

$(function()
{
			$( "#date_debut_projet" ).datepicker();
			  $( "#tabs" ).tabs();
});

  
function valider_creer_projet()
{

			nom_projet = document.getElementById('nom_projet').value;
			owner = document.getElementById('owner').value;
			date_debut = document.getElementById('date_debut').value;
			duree = document.getElementById('duree').value;
			nom_famille = document.getElementById('nom_famille').value;
			status_projet = document.getElementById('status_projet').value;
			commentaires = document.getElementById('commentaires').value;
			
			//alert(nom_projet + " " + owner + " " + date_debut + " " + duree + " " + nom_famille + " " + status_projet + " " + commentaires);
				
			if(nom_projet.length  == '' || owner.length == '')
			{
	
						$(function()
						{
									$( "#message_incomplet" ).dialog({
									modal: true,
									title: "Infos",
									buttons: {
												Ok: function()
												{
													$( this ).dialog( "close" );
												}
											 }
										});
						});
			}
			else
			{
				var data = 'nom_projet='+nom_projet
				+'&owner='+owner
				+'&date_debut='+date_debut
				+'&duree='+duree
				+'&nom_famille='+nom_famille
				+'&status_projet='+status_projet
				+'&commentaires='+commentaires;
				
				alert(data);
				
				$.ajax({
							
							type: "POST",
							url: "sauver_projet.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 8-->
						<div class="content">
						
							<div class="page-header">
								
								<h2><i class="icon-bullhorn"></i> <span>Tableau de board du projet: <?php echo $nom_projet; ?></span></h2>
							</div>
								
							<!-- Single Page -->
							<div class="page">
								
						<div class="examples">
							
							
						<div id="tabs">
							  <ul>
								<li><a href="#tabs-1">Checklist Topcell</a></li>
								<li><a href="#tabs-2">Checklist Tapeout</a></li>
								<li><a href="#tabs-3">Documents</a></li>
							  </ul>
<!----------------------------------------->
							<div id="tabs-1">
							
									<table style="width:100%" border="1" cellspacing="1" cellpadding="5" bgcolor="#D5D5D5">		
							
									<tr bgcolor="#FFFFFF">
									<td>Nom du projet :</td>
									<td><input type="text" id="nom_projet" name ="nom_projet" size="30" maxlength="30" value="" > *</td>
									</tr>
									
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
									
									<tr>
									<td>Durée :</td>
									<td>
									<select id="duree" name="duree" size="1">
									<option value="1" selected="selected">1 mois</option>
									<option value="2">2 mois </option>
									<option value="3">3 mois </option>
									<option value="4">4 mois </option>
									<option value="5">5 mois </option>
									<option value="6">6 mois </option>
									<option value="2">7 mois </option>
									<option value="3">8 mois </option>
									<option value="4">9 mois </option>
									<option value="5">10 mois </option>
									<option value="6">11 mois </option>
									<option value="6">12 mois </option>
									</select>
									</td>
									</tr>
									
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
									
									<tr bgcolor="#FFFFFF">
									<td>Nom de la famille :</td>
									<td >
									<select id="nom_famille" name="nom_famille" size="1">
<?php							
									for ($i=0; $i < count($tab_famille_projet); $i++)
									{
										if($i == 0)
										{	
											echo "<option value= '$tab_famille_projet[$i]' select = 'selected' >$tab_famille_projet[$i]</option>";
										}
										else
										{	
											echo "<option value= '$tab_famille_projet[$i]' >$tab_famille_projet[$i]</option>";
										}	
									}
?>							
									</select></td>
									</tr>
									
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
									
									
									<tr>
									<td>Status :</td>
									<td>
									<select id="status_projet" name="status_projet">
									<option value="actif" selected="selected">Actif</option>
									<option value="inactif">Inactif</option>
									</select>
									</td>
									</tr>
									
									<tr bgcolor="#FFFFFF">
									<td>Commentaires :</td>
									<td>
									<textarea id="commentaires" name="commentaires" rows="8" cols="60" >
									</textarea></td>
									</tr>
									
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
									
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
							
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
									
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
									
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
									
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
		  
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
									
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
							
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
									
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
									
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
									
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
							
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
									
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
									
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
									
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
									
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
							
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
 
									</table> 
							
									<br/><br/>
									<input class="btn btn-primary" type="submit" value="Ajouter" name="ajouter" onclick="valider_creer_projet()" />
												
							  
							</div>
<!----------------------------------------->
							<div id="tabs-2">
									
									<table style="width:100%" border="1" cellspacing="1" cellpadding="5" bgcolor="#D5D5D5">		
							
									<tr bgcolor="#FFFFFF">
									<td>Nom du projet :</td>
									<td><input type="text" id="nom_projet" name ="nom_projet" size="30" maxlength="30" value="" > *</td>
									</tr>
									
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
									
									<tr>
									<td>Durée :</td>
									<td>
									<select id="duree" name="duree" size="1">
									<option value="1" selected="selected">1 mois</option>
									<option value="2">2 mois </option>
									<option value="3">3 mois </option>
									<option value="4">4 mois </option>
									<option value="5">5 mois </option>
									<option value="6">6 mois </option>
									<option value="2">7 mois </option>
									<option value="3">8 mois </option>
									<option value="4">9 mois </option>
									<option value="5">10 mois </option>
									<option value="6">11 mois </option>
									<option value="6">12 mois </option>
									</select>
									</td>
									</tr>
									
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>
									
									<tr bgcolor="#FFFFFF">
									<td>Nom de la famille :</td>
									<td >
									<select id="nom_famille" name="nom_famille" size="1">
<?php							
									for ($i=0; $i < count($tab_famille_projet); $i++)
									{
										if($i == 0)
										{	
											echo "<option value= '$tab_famille_projet[$i]' select = 'selected' >$tab_famille_projet[$i]</option>";
										}
										else
										{	
											echo "<option value= '$tab_famille_projet[$i]' >$tab_famille_projet[$i]</option>";
										}	
									}
?>							
									</select></td>
									</tr>
									
									<tr>
									<td>Owner :</td>
									<td><input type="text" id="date_debut" name="date_debut"></td>
									</tr>

									</table>		
									
									<br/><br/>
									<input class="btn btn-primary" type="submit" value="Ajouter" name="ajouter" onclick="valider_creer_projet()" />
									
			
							</div>
<!----------------------------------------->
							  
							<div id="tabs-3">
									<form action="uploads.php" method="post" enctype="multipart/form-data">
									Selection d'un document:
									<input type="file" name="fileToUpload" id="fileToUpload">
									<br>
									<input type="submit" value="Upload" name="submit">
									</form>
<?php
									$dir    = './uploads';
									$tab_files = scandir($dir);
									echo "<br><br><br>";
									
									chdir($dir);
?>							
									<table class="sortable" border="1">
									<thead>
									<tr>
									<th class="th_tableau_fichier">Nom</th>
									<th class="th_tableau_fichier">Type</th>
									<th class="th_tableau_fichier">Taille </th>
									<th class="th_tableau_fichier">Date modification</th>
									</tr>
									</thead>
<?php
									for ($i= 2; $i< count($tab_files) ; $i++) 
									{
										$taille_fichier = filesize($tab_files[$i]);
										$taille_fichier = conversion_taille_fichier($taille_fichier, 2 );
										$date = date ("m d Y H:i:s", filemtime($tab_files[$i]));
										$extension =  pathinfo($tab_files[$i], PATHINFO_EXTENSION);
										$str_msg = association_extension($extension);						
										$url = "./uploads/".$tab_files[$i];
										//echo "<a href=$url>$tab_files[$i]</a>" ."  " .conversion_taille_fichier($taille_fichier, 2 ) ."" .$date ."<br>";
											
										echo "	<tr class='$class'>
												<td class ='td_tableau_fichier'><a href='$url'>$tab_files[$i]</a></td>
												<td class ='td_tableau_fichier'>$str_msg</td>
												<td class ='td_tableau_fichier'>$taille_fichier</td>
												<td class ='td_tableau_fichier'>$date</td>
												</tr>";
									}	
?>
									</table>

									<p>toto</p>
 
							 
							</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>

			<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>
			

	
</body>
</html>
