-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
94 lines (74 loc) · 2.23 KB
/
Copy pathapi.php
File metadata and controls
94 lines (74 loc) · 2.23 KB
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
<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST');
header('Access-Control-Allow-Headers: Content-Type, Authorization');
header('Permissions-Policy: browsing-context="self"');
switch ($_SERVER['REQUEST_METHOD']) {
case 'POST':
if (isset($_POST['modo'])) {
devolverDatos($_POST['modo']);
} else {
echo json_encode(['error' => 'ERROR POST']);
}
break;
case 'GET':
echo json_encode(['error' => 'Use POST']);
break;
default:
echo json_encode(['error' => 'ERROR default']);
}
/**
* Devuelve los datos según el modo especificado.
*
* @param string $modo El modo de operación para determinar qué datos devolver.
*/
function devolverDatos(string $modo)
{
header("HTTP/1.1 200 OK");
include_once 'funcs/conexion.php';
include_once 'funcs/consultas.php';
include_once 'funcs/sqlfuncs.php';
$datos = array();
switch ($modo) {
case '24h':
case 'fecha':
$datos = datos24h($conn, $modo);
break;
case 'temperaturas':
$datos = temperaturas($conn);
break;
case 'otros':
$datos = humedadYPresion($conn);
break;
case 'last14days':
$datos = last14days($conn);
break;
case 'comparar':
$fecha1 = $_POST['fecha'] ?? null;
$fecha2 = $_POST['fecha2'] ?? null;
$datos = comparar($conn, $fecha1, $fecha2);
break;
case 'comparar_meses':
$mes1 = $_POST['mes1'] ?? null;
$mes2 = $_POST['mes2'] ?? null;
$datos = compararMeses($conn, $mes1, $mes2);
break;
case 'externa':
$datos = externa($conn);
break;
case 'precipitacion':
$datos = precipitacion($conn);
break;
case 'precipitacion_anio':
$datos = precipitacion_anio($conn);
break;
case 'status':
$datos = status($conn);
break;
default:
echo json_encode(['error' => 'MODE ERROR']);
return;
}
echo json_encode($datos);
}