-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustomPHP.php
408 lines (343 loc) · 11.7 KB
/
customPHP.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<?php
function refresh(){
echo "<meta http-equiv='refresh' content='0'>";
}
function getPOSTazienda (){
$nazienda= filter_input(INPUT_POST, 'nazienda');
return $nazienda;
}
function getPOSTtelefono(){
$telefono=filter_input(INPUT_POST, 'telefono');
return $telefono;
}
function getPOSTemail(){
$email=filter_input(INPUT_POST, 'email');
return $email;
}
function getPOSTnome(){
$nome=filter_input(INPUT_POST, 'nome');
return $nome;
}
function getPOSTcognome(){
$cognome=filter_input(INPUT_POST, 'cognome');
return $cognome;
}
function getPOSTindirizzo(){
$indirizzo=filter_input(INPUT_POST, 'indirizzo');
return $indirizzo;
}
function getPOSTsede(){
$sede=filter_input(INPUT_POST, 'sede');
return $sede;
}
function getPOSTcodFisc(){
$codiceFiscale=filter_input(INPUT_POST, 'codiceFiscale');
return $codiceFiscale;
}
function getPOSTpIVA(){
$PIVA=filter_input(INPUT_POST, 'PIVA');
return $PIVA;
}
function getPOSTcap(){
$cap=filter_input(INPUT_POST, 'cap');
return $cap;
}
function getNomeAzienda($email){
require 'db.php';
$SQL = "SELECT NAZIENDA FROM users WHERE email='$email'";
$result = $mysqli->query($SQL);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
$nomeAzienda=$row['NAZIENDA'];
}
}
$mysqli->close();
return $nomeAzienda;
}
function getID($email){
require 'db.php';
$SQL="SELECT id FROM users WHERE email='$email'";
$result=$mysqli->query($SQL);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
$ID=$row['id'];
}
}
$mysqli->close();
return $ID;
}
function getTelefono($email){
require 'db.php';
$SQL="SELECT TELEFONO FROM users WHERE email='$email'";
$result = $mysqli->query($SQL);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
$telefono=$row['TELEFONO'];
}
}
$mysqli->close();
return $telefono;
}
function getNome($email){
require 'db.php';
$SQL="SELECT first_name FROM users WHERE email='$email'";
$result = $mysqli->query($SQL);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
$nome=$row['first_name'];
}
}
$mysqli->close();
return $nome;
}
function getCognome($email){
require 'db.php';
$SQL="SELECT last_name FROM users WHERE email='$email'";
$result = $mysqli->query($SQL);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
$cognome=$row['last_name'];
}
}
$mysqli->close();
return $cognome;
}
function getIndirizzzo($email){
require 'db.php';
$SQL="SELECT Indirizzo FROM users WHERE email='$email'";
$result = $mysqli->query($SQL);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
$Indirizzo=$row['Indirizzo'];
}
}
$mysqli->close();
return $Indirizzo;
}
function getSede($email){
require 'db.php';
$SQL="SELECT Sede FROM users WHERE email='$email'";
$result = $mysqli->query($SQL);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
$Sede=$row['Sede'];
}
}
$mysqli->close();
return $Sede;
}
function getCodFisc($email){
require 'db.php';
$SQL="SELECT CODFIS FROM users WHERE email='$email'";
$result = $mysqli->query($SQL);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
$CodFis=$row['CODFIS'];
}
}
$mysqli->close();
return $CodFis;
}
function getPIVA($email){
require 'db.php';
$SQL="SELECT PIVA FROM users WHERE email='$email'";
$result = $mysqli->query($SQL);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
$PIVA=$row['PIVA'];
}
}
$mysqli->close();
return $PIVA;
}
function getCAP($email){
require 'db.php';
$SQL="SELECT CAP FROM users WHERE email='$email'";
$result = $mysqli->query($SQL);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
$CAP=$row['CAP'];
}
}
$mysqli->close();
return $CAP;
}
function modificaDati($nome, $cognome, $indirizzo, $sede, $cap, $PIVA, $telefono, $codiceFiscale, $nomeAzienda, $ID, $email){
require 'db.php';
$SQL = "UPDATE users SET NAZIENDA='$nomeAzienda', Sede='$sede', Indirizzo='$indirizzo', PIVA='$PIVA', CODFIS='$codiceFiscale', CAP='$cap', telefono='$telefono', "
. " id=$ID, first_name='$nome', last_name='$cognome' WHERE email='$email'";
$mysqli->query($SQL);
$mysqli->close();
}
function getLastID(){
require 'db.php';
$sql='SELECT ID FROM monitora WHERE ID=(SELECT MAX(ID) FROM monitora)';
$result=$mysqli->query($sql);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
$lastID=$row['ID'];
}
}else{
$row['ID']=0;
$lastID=$row['ID'];
}
return $lastID;
}
function getUserID($email){
require 'db.php';
$sql="SELECT ID FROM users WHERE email='$email'";
$result=$mysqli->query($sql);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
$IDutente=$row['ID'];
}
return $IDutente;
}
}
function getIDambiente($nomeAmbiente){
require 'db.php';
$sql="SELECT ID FROM ambiente WHERE nome='$nomeAmbiente'";
$result=$mysqli->query($sql);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
$IDambiente=$row['ID'];
}
}
$mysqli->close();
return $IDambiente;
}
function removeSensore1($IDriga, $submit){
require 'db.php';
if(isset($_POST[$submit])){
$SQL="DELETE FROM monitora WHERE ID=$IDriga";
$mysqli->query($SQL);
echo refresh();
}
}
function mostraSensore($nomeAmbiente){
require 'db.php';
$IDambiente= getIDambiente($nomeAmbiente);
$sqlA='SELECT m.ID, s.marca, s.tipo, m.valore, m.data, m.ora, s.unitamisura'
. ' FROM sensore s JOIN monitora m ON s.ID=m.IDsensore'
. " WHERE IDambiente=$IDambiente";
if(isset($mysqli)){
$result=$mysqli->query($sqlA);
}
if(!isset($result)){
trigger_error('invalid query');
}
if($result->num_rows>0){
$SensoreDato[getLastID()]=0;
$i=0;
while($row=$result->fetch_assoc()){
$SensoreDato[$i]=array($row['marca'], $row['tipo'], $row['unitamisura'], $row['valore'], $row['data'],$row['ora'], $row['ID']);
$i++;
}
if($i<6){
for($j=$i; $j<6; $j++){
$SensoreDato[$j]=array(0,0,0,0,0,0);
}
}
}else{
for($i=0; $i<6; $i++){
$SensoreDato[$i]=array(0,0,0,0,0,0);
}
}
$mysqli->close();
return $SensoreDato;
}
function get_options(){
require 'db.php';
$sqlA='SELECT * FROM ambiente';
$resultA=$mysqli->query($sqlA);
if($resultA->num_rows>0){
while($row=$resultA->fetch_assoc()){
$str='<option value="'.$row['NOME'].'">'.$row['NOME'].'</option>';
echo $str;
}
}else {
echo '0 results';
}
}
function insert_into_monitora($IDsensore, $nomeAmbiente, $a, $valore, $data, $ora){
require 'db.php';
$sql="SELECT ID FROM ambiente WHERE NOME='$nomeAmbiente'";
$result=$mysqli->query($sql);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
$IDambiente=$row['ID'];
}
$sql1="INSERT INTO monitora (ID, IDambiente, IDsensore, VALORE, DATA, ORA) VALUES($a,$IDambiente,$IDsensore,'$valore','$data','$ora')";
$mysqli->query($sql1);
}
}
//echo getLastID();
function getPOSTambienti1 (){
$ambiente= filter_input(INPUT_POST, 'ambienti1');
return $ambiente;
}
function getPOSTambienti2(){
$ambiente=filter_input(INPUT_POST, 'ambienti2');
return $ambiente;
}
function getPOSTambienti3(){
$ambiente=filter_input(INPUT_POST, 'ambienti3');
return $ambiente;
}
function getPOSTambienti4(){
$ambiente=filter_input(INPUT_POST, 'ambienti4');
return $ambiente;
}
function getPOSTambienti5(){
$ambiente=filter_input(INPUT_POST, 'ambienti5');
return $ambiente;
}
function getPOSTambienti6(){
$ambiente=filter_input(INPUT_POST, 'ambienti6');
return $ambiente;
}
function selectSensore(){
require 'db.php';
$sqlS='SELECT * FROM sensore';
if(isset($mysqli)){
$resultS=$mysqli->query($sqlS);
}
if($resultS->num_rows>0){
while($row=$resultS->fetch_assoc()){
$Sensore[$row['ID']]=array($row['ID'], $row['MARCA'], $row['TIPO'], $row['UNITAMISURA']);
}
}
return $Sensore;
}
function count_decimals($x){
return strlen(substr(strrchr($x+'', '.'), 1));
}
function random($min, $max){
$decimals = max(count_decimals($min), count_decimals($max));
$factor = pow(10, $decimals);
return rand($min*$factor, $max*$factor) / $factor;
}
function getDati($email){
require 'db.php';
$IDutente= getUserID($email);
$sql='SELECT a.NOME, s.MARCA, s.TIPO, m.VALORE, s.UNITAMISURA, m.DATA, m.ORA '.
'FROM MONITORA m JOIN AMBIENTE a ON m.IDambiente=a.ID JOIN SENSORE s ON m.IDsensore=s.ID '.
"WHERE IDcliente=$IDutente";
$result=$mysqli->query($sql);
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
$str='<tr><td>'. htmlspecialchars($row['NOME']). ' </td><td>'. htmlspecialchars($row['MARCA']). ' </td><td>'. htmlspecialchars($row['TIPO']). ' </td><td>'. htmlspecialchars($row['VALORE']). ' </td><td>'. htmlspecialchars($row['UNITAMISURA']). ' </td><td>'. htmlspecialchars($row['DATA']). ' </td><td>'. htmlspecialchars($row['ORA']). ' </td><tr>';
echo $str;
}
}
}
function authenticate($email, $password){
$file=explode(PHP_EOL, file_get_contents("accounts.txt"));
foreach($file as $line){
list($email, $password)=explode(",",$line);
if($_POST['email']==$email && $_POST['password']==$password){
return true;
}
}
return false;
}