<?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-8">  -->
						<!-- Content -->
				<!--		<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>
						-->		
						
					<!--		<div class="page">	-->
								
					<!--		<div class="examples">  -->
							
							
							<div id="tabs">
							  <ul>
								<li><a href="#tabs-1">Paramétres</a></li>
								<li><a href="#tabs-2">Checklist</a></li>
								<li><a href="#tabs-3">Documents</a></li>
							  </ul>
							  
							  <div id="tabs-1">

							  <table align="left" cellspacing="1" cellpadding="5" border="0" bgcolor="#D5D5D5" width="550">
											
							<tr bgcolor="#FFFFFF">
							<td align="right" valign="top">Nom du projet :</td>
							<td align="left" valign="middle" colspan="1">
							<input type="text" id="nom_projet" name ="nom_projet" size="30" maxlength="30" value="" > *</td>
							</tr>
							
							<tr bgcolor="#FFFFFF">
							<td align="right" valign="top">Owner :</td>
							<td align="left" valign="middle" colspan="1">
							<input type="text" id="owner" name="owner" size="30" maxlength="30" value=""  > *</td>
							</tr>
							
							<tr bgcolor="#FFFFFF">
							<td align="right" valign="top">Date de début :</td>
							<td align="left" valign="middle" colspan="1">
							<input type="text" id="date_debut" name="date_debut"> 
							</td>
							</tr>
							
							
							<tr bgcolor="#FFFFFF">
							<td align="right" valign="top">Date de début :</td>
							<td align="left" valign="middle" colspan="1">
							<input type="text" id="date_debut" name="date_debut"> 
							</td>
							</tr>
							
							<tr bgcolor="#FFFFFF">
							<td align="right" valign="top">Date de début :</td>
							<td align="left" valign="middle" colspan="1">
							<input type="text" id="date_debut" name="date_debut"> 
							</td>
							</tr>
							
							<tr bgcolor="#FFFFFF">
							<td align="right" valign="top">Date de début :</td>
							<td align="left" valign="middle" colspan="1">
							<input type="text" id="date_debut" name="date_debut"> 
							</td>
							</tr>
							
							</table>
							
							<br/><br/><br/><br/><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%">
  <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
  
  
  
</table> 

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

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