-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ficha.php
66 lines (51 loc) · 2.29 KB
/
Ficha.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
<?php
// Ficha.php - Clase para manejar las operaciones de la ficha
class Ficha {
private $conn;
public function __construct($conn) {
$this->conn = $conn;
}
public function agregarFicha($numeroFicha, $numeroArchivo, $estanteria, $idUsuario) {
$fechaCreacion = date("Y-m-d H:i:s");
$sqlInsertarFicha = "INSERT INTO fichas (numero, numero_archivo, estanteria, fecha_creacion, usuario_ID)
VALUES ('$numeroFicha', '$numeroArchivo', '$estanteria', '$fechaCreacion', '$idUsuario')";
if ($this->conn->query($sqlInsertarFicha) !== TRUE) {
echo "Error al agregar la ficha: " . $this->conn->error;
}
}
public function eliminarFicha($idFicha) {
$sqlEliminarFicha = "DELETE FROM fichas WHERE id = '$idFicha'";
if ($this->conn->query($sqlEliminarFicha) !== TRUE) {
echo "Error al eliminar la ficha: " . $this->conn->error;
}
}
public function actualizarFicha($idFicha, $numeroFicha) {
$sqlActualizarFicha = "UPDATE fichas SET numero = '$numeroFicha' WHERE id = '$idFicha'";
if ($this->conn->query($sqlActualizarFicha) !== TRUE) {
echo "Error al actualizar la ficha: " . $this->conn->error;
}
}
public function obtenerFichas() {
$sqlObtenerFichas = "SELECT fichas.*, usuario.username
FROM fichas
LEFT JOIN usuario ON fichas.usuario_ID = usuario.id";
$resultObtenerFichas = $this->conn->query($sqlObtenerFichas);
if ($resultObtenerFichas !== FALSE) {
$fichas = ($resultObtenerFichas->num_rows > 0) ? $resultObtenerFichas->fetch_all(MYSQLI_ASSOC) : [];
} else {
echo "Error en la consulta: " . $this->conn->error;
$fichas = [];
}
return $fichas;
}
public function mostrarFichaEnGrid($fichaItem) {
echo "<div class='grid-item'>";
echo "Número de Ficha: " . $fichaItem['numero'] . "<br>";
echo "Número de Archivo: " . $fichaItem['numero_archivo'] . "<br>";
echo "Estantería: " . $fichaItem['estanteria'] . "<br>";
echo "Nombre del Usuario: " . $fichaItem['username'] . "<br>";
// Agregar más detalles si es necesario
echo "</div>";
}
}
?>