<?php
session_start();
?>
<!DOCTYPE html>

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

        <!-- Contenu du site -->
        <body>
                <?php 
                include("header.php");
                if(isset($_SESSION['Login'], $_SESSION['Password']))
                {
                        ?>
			<div class="row">
			        <div class="col-6 col-md-6 offset-md-3 offset-3">
                			<br/>
                			<h1 style="margin-bottom:20px; margin-top:70px; border-bottom:1px solid #CCC; padding-bottom:20px;"><i class="fas fa-history"></i> Suppression d'un capteur</h1>
					<?php
					$nom = $_POST['nom'];
					$numero = getNumero($nom);
					$raspberry = getRaspberry($nom);
					$version = getVersion($nom);
					if(remove($nom))
					{
						$arduino_simple = "[Arduino_delete]\r\n";
						$arduino_spi = "[Arduino_delete]\r\n";
						$nucleo = "[Nucleo_delete]\r\n";

						if($version == 0)
						{
							$ini = $arduino_simple;
						}
						elseif($version == 1)
						{
							$ini = $arduino_spi;
						}
						elseif($version == 2)
						{
							$ini = $nucleo;
						}

						$ini = $ini.$raspberry." capteur=".$numero."-".$version." setup=0\n";
						file_put_contents('upload/inventaire.ini', $ini);

						//exec("super cmd.sh");
						?>
						<div class="alert alert-success" role="alert">
					     		Le capteur a bien été supprimé !
						</div>
						<meta http-equiv="Refresh" content="3;url=accueil.php" />
						<?php
					}
					else
					{
						?>
						<div class="alert alert-danger" role="alert">
					     		Echec lors de la suppression. Vérifiez vos informations !
						</div>
						<meta http-equiv="Refresh" content="3;url=gestionCapteur.php" />
						<?php
					}
					?>
        			</div>
			</div>
			<?php
                }
                else
                {
                        include("formConnexion.php");
                }
                ?>
        </body>
</html>

