Commit dc70015ccd988338b7926529a5715ced6d5a39fc

Authored by grouille
1 parent 487764be

Correction site

Showing 3 changed files with 7 additions and 42 deletions   Show diff stats
site/accesBase.php
... ... @@ -111,23 +111,6 @@
111 111 $tab = pg_fetch_all($result);
112 112 return $tab;
113 113 }
114   -
115   - /*function upload($index,$maxsize=FALSE,$extensions=FALSE)
116   - {
117   - //Test1: fichier correctement uploadé
118   - if (!isset($_FILES[$index]) OR $_FILES[$index]['error'] > 0) return FALSE;
119   - //Test2: taille limite
120   - if ($maxsize !== FALSE AND $_FILES[$index]['size'] > $maxsize) return FALSE;
121   - //Test3: extension
122   - $ext = substr(strrchr($_FILES[$index]['name'],'.'),1);
123   - if ($extensions !== FALSE AND !in_array($ext,$extensions)) return FALSE;
124   - $name = "main";
125   - $extension_upload = strtolower( substr( strrchr($_FILES['fichier']['name'], '.') ,1) );
126   - $dossier = "upload/";
127   - $fichier = $name.".".$extension_upload;
128   - //$fichier = basename($_FILES[$index]['name']);
129   - return move_uploaded_file($_FILES['fichier']['tmp_name'],$dossier.$fichier);
130   - }*/
131 114  
132 115 function load($tmp_name, $name)
133 116 {
... ... @@ -144,24 +127,6 @@
144 127 return False;
145 128 }
146 129  
147   - function update_values()
148   - {
149   - $rep = 'data';
150   - $fichiers = array_diff(scandir($rep), array('..', '.'));
151   - $db = connexion();
152   - foreach($fichiers as $fichier) {
153   - $parametres = simplexml_load_file('data/'.$fichier);
154   - list($ip_address) = $parametres->xpath("parametre[@name='ip_address']");
155   - list($numero) = $parametres->xpath("parametre[@name='numero']");
156   - list($name) = $parametres->xpath("parametre[@name='name']");
157   - list($data) = $parametres->xpath("parametre[@name='data']");
158   -
159   - $query = "UPDATE capteurs SET value='$data' WHERE raspberry='$ip_address' and numero='$numero' and nom='$name'";
160   - $result = pg_query($db, $query) or die("La requête a echoué : ".pg_last_error());
161   - }
162   - deconnexion($db);
163   - }
164   -
165 130 function update_bdd($ip_address, $numero, $data, $date)
166 131 {
167 132 $name = getSensorName($ip_address, $numero);
... ... @@ -287,9 +252,14 @@
287 252 }
288 253 }
289 254  
290   - function add($nom, $type, $raspberry, $numero, $unite, $version)
  255 + function add($nom, $type, $raspberry, $unite, $version)
291 256 {
292 257 $db = connexion();
  258 + $query = "SELECT MAX(numero) as numero FROM capteurs WHERE raspberry = '$raspberry'";
  259 + $result = pg_query($db, $query) or die("La requête a echoué : ".pg_last_error());
  260 + $tab = pg_fetch_assoc($result);
  261 + $numero = $tab['numero'] +1;
  262 + if($numero > 4) return False;
293 263 $query = "SELECT * FROM capteurs WHERE nom = '$nom' OR (raspberry = '$raspberry' AND numero = '$numero')";
294 264 $result = pg_query($db, $query) or die("La requête a echoué : ".pg_last_error());
295 265 if (pg_affected_rows($result)!=0){
... ...
site/add.php
... ... @@ -20,7 +20,7 @@ session_start();
20 20 <br/>
21 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>
22 22 <?php
23   - if(add($_POST['nom'], $_POST['type'], $_POST['raspberry'], $_POST['numero'], $_POST['unite'], $_POST['version']))
  23 + if(add($_POST['nom'], $_POST['type'], $_POST['raspberry'], $_POST['unite'], $_POST['version']))
24 24 {
25 25 $arduino_simple = "[Arduino_init]\r\n";
26 26 $arduino_spi = "[Arduino_spi_init]\r\n";
... ...
site/addSensor.php
... ... @@ -34,11 +34,6 @@ $raspberrys = getRaspberrys();
34 34 </tr>
35 35  
36 36 <tr>
37   - <td><label for="numero">Numéro du capteur : </label></td>
38   - <td><input type="text" id="numero" name="numero" /></td>
39   - </tr>
40   -
41   - <tr>
42 37 <td><label for="unite">Unite de mesure : </label></td>
43 38 <td><input type="text" id="unite" name="unite" /></td>
44 39 </tr>
... ...