-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVehiculo.php
103 lines (97 loc) · 5.3 KB
/
Vehiculo.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
<?php
include("myconnection.php");
include("token.php");
switch ($_SERVER['REQUEST_METHOD']) {
case "POST":
$data = json_decode(file_get_contents("php://input"), true);
if(($user = token($data["token"])) != false) {
$time_pre = microtime(true);
$sql = "INSERT INTO `transporte`.`vehiculo` (`patente`, `anho_patente`, `anho_fabricacion`, `marca`, `modelo`) VALUES ('" . $data["patente"] . "', '" . $data["anho_patente"] . "', '" . $data["anho_fabricacion"] . "', '" . $data["marca"] . "', '" . $data["modelo"] . "');";
$ejecucionSQL = $conexion->prepare($sql);
$ejecucionSQL->execute();
$time_post = microtime(true);
$time = $time_post - $time_pre;
$time = $time*pow(10, 3);
$sql = "INSERT INTO `transporte`.`auditoria` (`fecha_acceso`, `user`, `response_time`, `endpoint`) VALUES ('".date('Y-m-d H:i:s')."', '".token($data["token"])."', '".$time."', 'agregarVehiculo.php');";
$ejecucionSQL = $conexion->prepare($sql);
$ejecucionSQL->execute();
}
break;
case "GET":
if(token($_GET['token']) != false) {
$time_pre = microtime(true);
if (!empty($_GET['id'])) {
$sql = "SELECT * FROM vehiculo WHERE id=".$_GET["id"].";";
$ejecucionSQL = $conexion->prepare($sql);
$ejecucionSQL->execute();
$res = $ejecucionSQL->fetch(PDO::FETCH_ASSOC);
echo json_encode($res);
} else {
$sql = "SELECT * FROM vehiculo";
$ejecucionSQL = $conexion->prepare($sql);
$ejecucionSQL->execute();
$vehiculos = array();
while($res = $ejecucionSQL->fetch(PDO::FETCH_ASSOC)) {
$vehiculos["vehiculos"][] = $res;
}
echo json_encode($vehiculos);
$time_post = microtime(true);
$time = $time_post - $time_pre;
$time = $time * pow(10, 3);
$sql = "INSERT INTO `transporte`.`auditoria` (`fecha_acceso`, `user`, `response_time`, `endpoint`) VALUES ('" . date('Y-m-d H:i:s') . "', '" . token($_GET['token']) . "', '" . $time . "', 'listarChofer');";
$ejecucionSQL = $conexion->prepare($sql);
$ejecucionSQL->execute();
}
}
break;
case "PUT":
$data = json_decode(file_get_contents("php://input"), true);
if(($user = token($data["token"])) != false) {
$time_pre = microtime(true);
if (isset($data["patente"])) {
$sql = "UPDATE `transporte`.`vehiculo` SET `patente` = '" . $data["patente"] . "' WHERE `vehiculo_id` = '" . $data["vehiculo_id"] . "';";
$ejecucionSQL = $conexion->prepare($sql);
$ejecucionSQL->execute();
}
if (isset($data["anho_patente"])) {
$sql = "UPDATE `transporte`.`vehiculo` SET `anho_patente` = '" . $data["anho_patente"] . "' WHERE `vehiculo_id` = '" . $data["vehiculo_id"] . "';";
$ejecucionSQL = $conexion->prepare($sql);
$ejecucionSQL->execute();
}
if (isset($data["anho_fabricacion"])) {
$sql = "UPDATE `transporte`.`vehiculo` SET `anho_fabricacion` = '" . $data["anho_fabricacion"] . "' WHERE `vehiculo_id` = '" . $data["vehiculo_id"] . "';";
$ejecucionSQL = $conexion->prepare($sql);
$ejecucionSQL->execute();
}
if (isset($data["marca"])) {
$sql = "UPDATE `transporte`.`vehiculo` SET `marca` = '" . $data["marca"] . "' WHERE `vehiculo_id` = '" . $data["vehiculo_id"] . "';";
$ejecucionSQL = $conexion->prepare($sql);
$ejecucionSQL->execute();
}
if (isset($data["modelo"])) {
$sql = "UPDATE `transporte`.`vehiculo` SET `modelo` = '" . $data["modelo"] . "' WHERE `vehiculo_id` = '" . $data["vehiculo_id"] . "';";
$ejecucionSQL = $conexion->prepare($sql);
$ejecucionSQL->execute();
}
$time_post = microtime(true);
$time = $time_post - $time_pre;
$sql = "INSERT INTO `transporte`.`auditoria` (`fecha_acceso`, `user`, `response_time`, `endpoint`) VALUES ('".date('Y-m-d H:i:s')."', '".token($data["token"])."', '".$time."', 'modificarVehiculo.php');";
$ejecucionSQL = $conexion->prepare($sql);
$ejecucionSQL->execute();
}
break;
case "DELETE":
$data = json_decode(file_get_contents("php://input"), true);
if(($user = token($data["token"])) != false) {
$time_pre = microtime(true);
$sql = "DELETE FROM `transporte`.`vehiculo` WHERE `vehiculo_id` = '" . $data["vehiculo_id"] . "';";
$ejecucionSQL = $conexion->prepare($sql);
$ejecucionSQL->execute();
$time_post = microtime(true);
$time = $time_post - $time_pre;
$sql = "INSERT INTO `transporte`.`auditoria` (`fecha_acceso`, `user`, `response_time`, `endpoint`) VALUES ('".date('Y-m-d H:i:s')."', '".token($data["token"])."', '".$time."', 'eliminarVehiculo.php');";
$ejecucionSQL = $conexion->prepare($sql);
$ejecucionSQL->execute();
}
break;
}