envoiFichiers.php 3.71 KB
<?php
session_start();
$error = false;
/*$error2 = false;

if ( isset($_POST['sensor']) && count($_POST['sensor']<>0) ) {
     	$xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\r\n"
	.'<all>';
     	foreach($_POST['sensor'] as $sensor => $value)
	{
		$val = explode(":", $value);
		if(count($types)<>0 && !in_array($val[2], $types)) {$error2 = true;}
		else {$types[] = $val[2];}
		$xml = $xml. '<sensor>' . '<raspberry>' . htmlspecialchars($val[0]) . '</raspberry>' . '<numero>' . htmlspecialchars($val[1]) . '</numero>' . '</sensor>';
		$xml = $xml."\r\n";
	}
	$xml = $xml.'</all>';
        if(!$error2) {file_put_contents('upload/sensor.xml', $xml) ;}
}*/

if(isset($_POST['sensor']) && count($_POST['sensor']<>0))
{
	$ini = "";
	$arduino_simple = "[Arduino]\r\n";
	$arduino_spi = "[Arduino_spi]\r\n";
	$nucleo = "[Nucleo]\r\n";
	$a_simple = false;
	$a_spi = false;
	$n = false;
	foreach($_POST['sensor'] as $sensor => $value)
	{
		$val = explode(":", $value);
		if(count($types)<>0 && !in_array($val[2], $types)) {$error = true;}
		else {$types[] = $val[2];}
		$version = 1;//getSensorVersion($val[0], $val[1]);
		if($version == 0)
		{
			$a_simple = true;
			$arduino_simple = $arduino_simple.$val[0]." capteur=".$val[1]."\n";
		}
		elseif($version == 1)
		{
			$a_spi = true;
			$arduino_spi = $arduino_spi.$val[0]." capteur=".$val[1]."\n";
		}
		elseif($version == 2)
		{
			$n = true;
			$nucleo = $nucleo.$val[0]." capteur=".$val[1]."\n";
		}
	}
	echo $arduino_simple;
	echo $arduino_spi;
	echo $nucleo;
	if($a_simple) {$ini = $ini.$arduino_simple."\n";}
	if($a_spi) {$ini = $ini.$arduino_spi."\n";}
	if($n) {$ini = $ini.$nucleo."\n";}
	if(!$error) {file_put_contents('upload/inventaire.ini', $ini);}
}
?>
<!DOCTYPE html>

<html>
	<head>
		<?php include("head.php"); ?>
	</head>

	<!-- Contenu du site -->
	<body>
		<?php 
		include("header.php");
		if(!$error)
		{
		$upload1 = upload('fichier',FALSE, array('c', 'txt') );
		?>
		<div class="row">
			<div class="col-4 col-md-4 offset-md-4 offset-4">
				<br/>
				<h1 style="margin-bottom:50px; margin-top:50px; border-bottom:1px solid #CCC; padding-bottom:20px;"><i class="fa fa-cloud"></i> Envoi du fichier en ligne</h1>
				<?php if($upload1){
					?>
					<div class="alert alert-success" role="alert">
					  Upload du fichier réussi !
					</div>
					<?php
				}
				else {?>
					<div class="alert alert-danger" role="alert">
						Erreur lors du transfert du fichier !
					</div><?php 
				}
				?>
				<h1 style="margin-bottom:50px; margin-top:50px; border-bottom:1px solid #CCC; padding-bottom:20px;"><i class="fa fa-info-circle"></i> Informations complémentaires</h1>
				<table class="table table-striped table-bordered">
					<tbody>
						<tr>
							<td>Nom du fichier</td>
							<td><?php echo $_FILES['fichier']['name'];?></td>
						</tr>
						<tr>
							<td>Type</td>
							<td><?php echo $_FILES['fichier']['type'];?></td>
						</tr>
						<tr>
							<td>Localisation</td>
							<td><?php echo $_FILES['fichier']['tmp_name'];?></td>
						</tr>
						<tr>
							<td>Erreur</td>
							<td><?php echo $_FILES['fichier']['error'];?></td>
						</tr>
						<tr>
							<td>Taille</td>
							<td><?php echo $_FILES['fichier']['size'];?></td>

						</tr>
					</tbody>
				</table>

			</div>
		</div>
		<?php }
		else
		{
		?>
		<div class="row">
			<div class="col-4 col-md-4 offset-md-4 offset-4">
				<br/>
				<h1 style="margin-bottom:50px; margin-top:50px; border-bottom:1px solid #CCC; padding-bottom:20px;"><i class="fa fa-cloud"></i> Envoi du fichier en ligne</h1>
				<div class="alert alert-danger" role="alert">
				     Vous devez choisir des capteurs de même type !
				</div>
				<meta http-equiv="Refresh" content="3;url=send.php" />
			</div>
		</div>
		<?php
		}
		?>
	</body>
</html>