Commit 62c2874380d71ba7811b49fa9670c4a834515020
1 parent
00fff372
Suppression RPI + capteur
Showing
10 changed files
with
188 additions
and
6 deletions
Show diff stats
site/accesBase.php
... | ... | @@ -252,6 +252,27 @@ |
252 | 252 | } |
253 | 253 | } |
254 | 254 | |
255 | + function removeRpi($ip) | |
256 | + { | |
257 | + $db = connexion(); | |
258 | + $query = "SELECT nom FROM capteurs WHERE raspberry = '$ip'"; | |
259 | + $result = pg_query($db, $query) or die("La requ te a echou : ".pg_last_error()); | |
260 | + $capteurs = pg_fetch_all($result); | |
261 | + foreach($capteurs as $capteur) | |
262 | + { | |
263 | + remove($capteur['nom']); | |
264 | + } | |
265 | + $query = "REMOVE FROM raspberry WHERE ip = '$ip'"; | |
266 | + $result = pg_query($db, $query) or die("La requ te a echou : ".pg_last_error()); | |
267 | + deconnexion($db); | |
268 | + if (pg_affected_rows($result)!=0){ | |
269 | + return True; | |
270 | + } | |
271 | + else{ | |
272 | + return False; | |
273 | + } | |
274 | + } | |
275 | + | |
255 | 276 | function add($nom, $type, $raspberry, $unite, $version) |
256 | 277 | { |
257 | 278 | $db = connexion(); |
... | ... | @@ -263,12 +284,14 @@ |
263 | 284 | $query = "SELECT * FROM capteurs WHERE nom = '$nom' OR (raspberry = '$raspberry' AND numero = '$numero')"; |
264 | 285 | $result = pg_query($db, $query) or die("La requête a echoué : ".pg_last_error()); |
265 | 286 | if (pg_affected_rows($result)!=0){ |
287 | + deconnexion($db); | |
266 | 288 | return False; |
267 | 289 | } |
268 | 290 | else |
269 | 291 | { |
270 | 292 | $query = "INSERT INTO capteurs VALUES($numero, '$nom', '$raspberry', '$type', 0, '$unite', $version)"; |
271 | 293 | $result = pg_query($db, $query) or die("La requête a echoué : ".pg_last_error()); |
294 | + deconnexion($db); | |
272 | 295 | if (pg_affected_rows($result)!=0){ |
273 | 296 | return True; |
274 | 297 | } |
... | ... | @@ -278,6 +301,22 @@ |
278 | 301 | } |
279 | 302 | } |
280 | 303 | |
304 | + function remove($nom) | |
305 | + { | |
306 | + $db = connexion(); | |
307 | + $query = "REMOVE FROM history WHERE sensor = '$nom'"; | |
308 | + $result = pg_query($db, $query) or die("La requ te a echou : ".pg_last_error()); | |
309 | + $query = "REMOVE FROM capteurs WHERE nom = '$nom'"; | |
310 | + $result = pg_query($db, $query) or die("La requ te a echou : ".pg_last_error()); | |
311 | + deconnexion($db); | |
312 | + if (pg_affected_rows($result)!=0){ | |
313 | + return True; | |
314 | + } | |
315 | + else{ | |
316 | + return False; | |
317 | + } | |
318 | + } | |
319 | + | |
281 | 320 | function makeArray($tab, $column) |
282 | 321 | { |
283 | 322 | foreach($tab as $element) | ... | ... |
site/add.php
... | ... | @@ -18,7 +18,7 @@ session_start(); |
18 | 18 | <div class="row"> |
19 | 19 | <div class="col-6 col-md-6 offset-md-3 offset-3"> |
20 | 20 | <br/> |
21 | - <h1 style="margin-bottom:20px; margin-top:70px; border-bottom:1px solid #CCC; padding-bottom:20px;"><i class="fas fa-history"></i> Historique</h1> | |
21 | + <h1 style="margin-bottom:20px; margin-top:70px; border-bottom:1px solid #CCC; padding-bottom:20px;"><i class="fas fa-history"></i> Ajout d'un capteur</h1> | |
22 | 22 | <?php |
23 | 23 | if(add($_POST['nom'], $_POST['type'], $_POST['raspberry'], $_POST['unite'], $_POST['version'])) |
24 | 24 | { |
... | ... | @@ -57,7 +57,7 @@ session_start(); |
57 | 57 | <div class="alert alert-danger" role="alert"> |
58 | 58 | Echec lors de l'ajout. Vérifiez vos informations ! |
59 | 59 | </div> |
60 | - <meta http-equiv="Refresh" content="3;url=ajoutCapteur.php" /> | |
60 | + <meta http-equiv="Refresh" content="3;url=gestionCapteur.php" /> | |
61 | 61 | <?php |
62 | 62 | } |
63 | 63 | ?> | ... | ... |
site/addRpi.php
... | ... | @@ -18,7 +18,7 @@ session_start(); |
18 | 18 | <div class="row"> |
19 | 19 | <div class="col-6 col-md-6 offset-md-3 offset-3"> |
20 | 20 | <br/> |
21 | - <h1 style="margin-bottom:20px; margin-top:60px; border-bottom:1px solid #CCC; padding-bottom:20px;"><i class="fas fa-history"></i> Historique</h1> | |
21 | + <h1 style="margin-bottom:20px; margin-top:60px; border-bottom:1px solid #CCC; padding-bottom:20px;"><i class="fas fa-history"></i> Ajout d'une Raspberry</h1> | |
22 | 22 | <?php |
23 | 23 | if(addRpi($_POST['ip'])) |
24 | 24 | { |
... | ... | @@ -35,7 +35,7 @@ session_start(); |
35 | 35 | <div class="alert alert-danger" role="alert"> |
36 | 36 | Echec lors de l'ajout. La Raspberry existe peut-être déjà ! |
37 | 37 | </div> |
38 | - <meta http-equiv="Refresh" content="3;url=ajoutRaspberry.php" /> | |
38 | + <meta http-equiv="Refresh" content="3;url=gestionRaspberry.php" /> | |
39 | 39 | <?php |
40 | 40 | } |
41 | 41 | ?> | ... | ... |
site/ajoutRaspberry.php
site/ajoutCapteur.php renamed to site/gestionCapteur.php
site/header.php
... | ... | @@ -10,8 +10,8 @@ |
10 | 10 | require_once("accesBase.php") ; |
11 | 11 | $membre = getMembreByIdPwd($_SESSION['Login'], $_SESSION['Password']); |
12 | 12 | ?> |
13 | - <a href="ajoutRaspberry.php"><i class="far fa-plus-square"></i> Raspberry</a> | |
14 | - <a href="ajoutCapteur.php"><i class="far fa-plus-square"></i> Capteur</a> | |
13 | + <a href="gestionRaspberry.php"><i class="far fa-plus-square"></i> Raspberry</a> | |
14 | + <a href="gestionCapteur.php"><i class="far fa-plus-square"></i> Capteur</a> | |
15 | 15 | <a href="send.php"><i class="fa fa-file-upload"></i> Upload</a> |
16 | 16 | <a href="history.php"><i class="fas fa-history"></i> Historique</a> |
17 | 17 | <a href="rechercheGraphe.php"><i class="fas fa-chart-line"></i> Graphiques</a> | ... | ... |
... | ... | @@ -0,0 +1,53 @@ |
1 | +<?php | |
2 | +session_start(); | |
3 | +?> | |
4 | +<!DOCTYPE html> | |
5 | + | |
6 | +<html> | |
7 | + <head> | |
8 | + <?php include("head.php"); ?> | |
9 | + </head> | |
10 | + | |
11 | + <!-- Contenu du site --> | |
12 | + <body> | |
13 | + <?php | |
14 | + include("header.php"); | |
15 | + if(isset($_SESSION['Login'], $_SESSION['Password'])) | |
16 | + { | |
17 | + ?> | |
18 | + <div class="row"> | |
19 | + <div class="col-6 col-md-6 offset-md-3 offset-3"> | |
20 | + <br/> | |
21 | + <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> | |
22 | + <?php | |
23 | + if(remove($_POST['nom'])) | |
24 | + { | |
25 | + ?> | |
26 | + <div class="alert alert-success" role="alert"> | |
27 | + Le capteur a bien été supprimé ! | |
28 | + </div> | |
29 | + <meta http-equiv="Refresh" content="3;url=accueil.php" /> | |
30 | + <?php | |
31 | + } | |
32 | + else | |
33 | + { | |
34 | + ?> | |
35 | + <div class="alert alert-danger" role="alert"> | |
36 | + Echec lors de la suppression. Vérifiez vos informations ! | |
37 | + </div> | |
38 | + <meta http-equiv="Refresh" content="3;url=gestionCapteur.php" /> | |
39 | + <?php | |
40 | + } | |
41 | + ?> | |
42 | + </div> | |
43 | + </div> | |
44 | + <?php | |
45 | + } | |
46 | + else | |
47 | + { | |
48 | + include("formConnexion.php"); | |
49 | + } | |
50 | + ?> | |
51 | + </body> | |
52 | +</html> | |
53 | + | ... | ... |
... | ... | @@ -0,0 +1,18 @@ |
1 | +<div class="row"> | |
2 | + <div class="col-6 col-md-6 offset-md-3 offset-3"> | |
3 | + <br/> | |
4 | + <h1 style="margin-bottom:20px; margin-top:60px; border-bottom:1px solid #CCC; padding-bottom:20px;"><i class="far fa-plus-square"></i> Suppression d'une Raspberry</h1> | |
5 | + <form action="removeRpi.php" method="post"> | |
6 | + <table class="table table-striped table-bordered"> | |
7 | + <tbody> | |
8 | + <tr> | |
9 | + <td><label for="ip">Adresse IP : 172.26.145. </label></td> | |
10 | + <td><input type="text" id="ip" name="ip" placeholder="114" size="3" minlength="3" maxlength="3"/></td> | |
11 | + </tr> | |
12 | + </tbody> | |
13 | + </table> | |
14 | + <input type="submit" class="btn btn-dark btn-lg btn-block" style="margin-top:20px; margin-bottom:20px;" value="Supprimer la Raspberry"/> | |
15 | + <br/> | |
16 | + </form> | |
17 | + </div> | |
18 | +</div> | ... | ... |
... | ... | @@ -0,0 +1,52 @@ |
1 | +<?php | |
2 | +session_start(); | |
3 | +?> | |
4 | +<!DOCTYPE html> | |
5 | + | |
6 | +<html> | |
7 | + <head> | |
8 | + <?php include("head.php"); ?> | |
9 | + </head> | |
10 | + | |
11 | + <!-- Contenu du site --> | |
12 | + <body> | |
13 | + <?php | |
14 | + include("header.php"); | |
15 | + if(isset($_SESSION['Login'], $_SESSION['Password'])) | |
16 | + { | |
17 | + ?> | |
18 | + <div class="row"> | |
19 | + <div class="col-6 col-md-6 offset-md-3 offset-3"> | |
20 | + <br/> | |
21 | + <h1 style="margin-bottom:20px; margin-top:60px; border-bottom:1px solid #CCC; padding-bottom:20px;"><i class="fas fa-history"></i> Suppression d'une Raspberry</h1> | |
22 | + <?php | |
23 | + if(removeRpi($_POST['ip'])) | |
24 | + { | |
25 | + ?> | |
26 | + <div class="alert alert-success" role="alert"> | |
27 | + La Raspberry a bien été supprimée ! | |
28 | + </div> | |
29 | + <?php | |
30 | + } | |
31 | + else | |
32 | + { | |
33 | + ?> | |
34 | + <div class="alert alert-danger" role="alert"> | |
35 | + Echec lors de la suppression. | |
36 | + </div> | |
37 | + <meta http-equiv="Refresh" content="3;url=gestionRaspberry.php" /> | |
38 | + <?php | |
39 | + } | |
40 | + ?> | |
41 | + </div> | |
42 | + </div> | |
43 | + <?php | |
44 | + } | |
45 | + else | |
46 | + { | |
47 | + include("formConnexion.php"); | |
48 | + } | |
49 | + ?> | |
50 | + </body> | |
51 | +</html> | |
52 | + | ... | ... |
... | ... | @@ -0,0 +1,18 @@ |
1 | +<div class="row"> | |
2 | + <div class="col-6 col-md-6 offset-md-3 offset-3"> | |
3 | + <br/> | |
4 | + <h1 style="margin-bottom:20px; margin-top:60px; border-bottom:1px solid #CCC; padding-bottom:20px;"><i class="far fa-minus-square"></i> Suppression d'un capteur</h1> | |
5 | + <form action="remove.php" method="post"> | |
6 | + <table class="table table-striped table-bordered"> | |
7 | + <tbody> | |
8 | + <tr> | |
9 | + <td><label for="nom">Nom du capteur : </label></td> | |
10 | + <td><input type="text" id="nom" name="nom" /></td> | |
11 | + </tr> | |
12 | + </tbody> | |
13 | + </table> | |
14 | + <input type="submit" class="btn btn-dark btn-lg btn-block" style="margin-top:20px; margin-bottom:20px;" value="Supprimer le capteur"/> | |
15 | + <br/> | |
16 | + </form> | |
17 | + </div> | |
18 | +</div> | ... | ... |