Commit 1c58232e3c1872a9cc828d9e5f63b68696e89a7f

Authored by root
1 parent 3bff9633

MAJ site en lien avec Ansible

site/accesBase.php
... ... @@ -207,6 +207,34 @@
207 207 return (int)$tab['version'];
208 208 }
209 209  
  210 + function getRaspberrys()
  211 + {
  212 + $db = connexion();
  213 + $query = "SELECT * FROM raspberry";
  214 + $result = pg_query($db, $query) or die("La requ te a echou : ".pg_last_error());
  215 + $tab = pg_fetch_all($result);
  216 + deconnexion($db);
  217 + return $tab;
  218 + }
  219 +
  220 + function getSetup($raspberry)
  221 + {
  222 + $db = connexion();
  223 + $query = "SELECT setup FROM raspberry WHERE ip = '$raspberry'";
  224 + $result = pg_query($db, $query) or die("La requ te a echou : ".pg_last_error());
  225 + $tab = pg_fetch_assoc($result);
  226 + deconnexion($db);
  227 + return $tab['setup'];
  228 + }
  229 +
  230 + function setup($raspberry)
  231 + {
  232 + $db = connexion();
  233 + $query = "UPDATE raspberry SET setup = 0 WHERE ip = '$raspberry'";
  234 + $result = pg_query($db, $query) or die("La requ te a echou : ".pg_last_error());
  235 + deconnexion($db);
  236 + }
  237 +
210 238 function add($nom, $type, $raspberry, $numero, $unite, $version)
211 239 {
212 240 $db = connexion();
... ...
site/add.php
... ... @@ -26,6 +26,8 @@ session_start();
26 26 $arduino_spi = "[Arduino_spi_init]\r\n";
27 27 $nucleo = "[Nucleo_init]\r\n";
28 28  
  29 + $setup = getSetup($_POST['raspberry']);
  30 +
29 31 if($_POST['version'] == 0)
30 32 {
31 33 $ini = $arduino_simple;
... ... @@ -38,8 +40,9 @@ session_start();
38 40 {
39 41 $ini = $nucleo;
40 42 }
41   - $ini = $ini.$_POST['raspberry']." capteur=".$_POST['numero']."\n";
  43 + $ini = $ini.$_POST['raspberry']." capteur=".$_POST['numero']." setup=".$setup."\n";
42 44 file_put_contents('upload/inventaire.ini', $ini);
  45 + setup($_POST['raspberry']);
43 46 ?>
44 47 <div class="alert alert-success" role="alert">
45 48 Le capteur a bien été ajouté !
... ...
site/addSensor.php
  1 +<?php
  2 +$raspberrys = getRaspberrys();
  3 +?>
1 4 <div class="row">
2 5 <div class="col-4 col-md-4 offset-md-4 offset-4">
3 6 <br/>
... ... @@ -17,7 +20,17 @@
17 20  
18 21 <tr>
19 22 <td><label for="raspberry">Raspberry : </label></td>
20   - <td><input type="text" id="raspberry" name="raspberry" /></td>
  23 + <td>
  24 + <div class="form-group my-1 mr-sm-2">
  25 + <select class="custom-select my-1 mr-sm-2" id="raspberry" name="raspberry">
  26 + <?php
  27 + foreach($raspberrys as $raspberry)
  28 + { ?>
  29 + <option><?php echo $raspberry['ip'];?></option>
  30 + <?php }?>
  31 + </select>
  32 + </div>
  33 + </td>
21 34 </tr>
22 35  
23 36 <tr>
... ...
site/upload/inventaire.ini
1   -[Arduino]
2   -172.26.145.111 capteur=2-0
3   -
  1 +[Arduino_init]
  2 +172.26.145.112 capteur=2 setup=1
... ...