diff --git a/site/accesBase.php b/site/accesBase.php index 7e9577d..6d2f35a 100644 --- a/site/accesBase.php +++ b/site/accesBase.php @@ -252,6 +252,27 @@ } } + function removeRpi($ip) + { + $db = connexion(); + $query = "SELECT nom FROM capteurs WHERE raspberry = '$ip'"; + $result = pg_query($db, $query) or die("La requ te a echou : ".pg_last_error()); + $capteurs = pg_fetch_all($result); + foreach($capteurs as $capteur) + { + remove($capteur['nom']); + } + $query = "REMOVE FROM raspberry WHERE ip = '$ip'"; + $result = pg_query($db, $query) or die("La requ te a echou : ".pg_last_error()); + deconnexion($db); + if (pg_affected_rows($result)!=0){ + return True; + } + else{ + return False; + } + } + function add($nom, $type, $raspberry, $unite, $version) { $db = connexion(); @@ -263,12 +284,14 @@ $query = "SELECT * FROM capteurs WHERE nom = '$nom' OR (raspberry = '$raspberry' AND numero = '$numero')"; $result = pg_query($db, $query) or die("La requête a echoué : ".pg_last_error()); if (pg_affected_rows($result)!=0){ + deconnexion($db); return False; } else { $query = "INSERT INTO capteurs VALUES($numero, '$nom', '$raspberry', '$type', 0, '$unite', $version)"; $result = pg_query($db, $query) or die("La requête a echoué : ".pg_last_error()); + deconnexion($db); if (pg_affected_rows($result)!=0){ return True; } @@ -278,6 +301,22 @@ } } + function remove($nom) + { + $db = connexion(); + $query = "REMOVE FROM history WHERE sensor = '$nom'"; + $result = pg_query($db, $query) or die("La requ te a echou : ".pg_last_error()); + $query = "REMOVE FROM capteurs WHERE nom = '$nom'"; + $result = pg_query($db, $query) or die("La requ te a echou : ".pg_last_error()); + deconnexion($db); + if (pg_affected_rows($result)!=0){ + return True; + } + else{ + return False; + } + } + function makeArray($tab, $column) { foreach($tab as $element) diff --git a/site/add.php b/site/add.php index ad513bc..ce1c00a 100644 --- a/site/add.php +++ b/site/add.php @@ -18,7 +18,7 @@ session_start();