-
Notifications
You must be signed in to change notification settings - Fork 0
/
Index2.php
220 lines (187 loc) · 6.74 KB
/
Index2.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
<?php
session_start();
include('conexion.php');
include('Ficha.php');
// Instanciar la clase Ficha
$ficha = new Ficha($conn);
// Procesar el formulario de agregar ficha
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['agregar_ficha'])) {
$numero_ficha = $_POST['numero_ficha'];
$numero_archivo = $_POST['numero_archivo'];
$estanteria = $_POST['estanteria'];
$usuario_id = $_SESSION['id_usuario'];
// Verificar que el formato de estantería sea "XX-XX-XX"
if (!preg_match('/^\d{2}-\d{2}-\d{2}$/', $estanteria)) {
echo "<p style='color: red;'>Formato de estantería incorrecto. Debe ser XX-XX-XX.</p>";
} else {
$ficha->agregarFicha($numero_ficha, $numero_archivo, $estanteria, $usuario_id);
}
}
// Procesar el formulario de búsqueda
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['buscar_ficha'])) {
$fecha_buscar = $_POST['buscar_fecha'];
$numero_ficha_buscar = $_POST['buscar_numero_ficha'];
// Llamar a la función listarFichas con los parámetros de búsqueda
$resultadosBusqueda = $ficha->obtenerFichas($fecha_buscar, $numero_ficha_buscar);
}
// Buscar fichas por número si se recibe una solicitud POST de búsqueda
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['accion']) && $_POST['accion'] === 'buscar_por_numero') {
// Obtener el número de ficha ingresado en el formulario
$numeroBusqueda = $conn->real_escape_string($_POST['numero_busqueda']);
// Query para buscar fichas por número
$sql = "SELECT fichas.*, usuario.username
FROM fichas
LEFT JOIN usuario ON fichas.usuario_ID = usuario.id
WHERE fichas.numero = '$numeroBusqueda'";
// Ejecutar la consulta y manejar errores
$result = $conn->query($sql);
if ($result !== FALSE) {
$fichas = ($result->num_rows > 0) ? $result->fetch_all(MYSQLI_ASSOC) : [];
} else {
echo "Error en la consulta: " . $conn->error;
$fichas = [];
}
}
// Buscar fichas por fecha si se recibe una solicitud POST de búsqueda
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['accion']) && $_POST['accion'] === 'buscar_por_fecha') {
// Obtener la fecha de búsqueda ingresada en el formulario
$fechaBusqueda = $conn->real_escape_string($_POST['fecha_busqueda']);
// Query para buscar fichas por fecha
$sql = "SELECT fichas.*, usuario.username
FROM fichas
LEFT JOIN usuario ON fichas.usuario_ID = usuario.idate(format)
WHERE DATE(fichas.fecha_creacion) = '$fechaBusqueda'";
// Ejecutar la consulta y manejar errores
$result = $conn->query($sql);
if ($result !== FALSE) {
$fichas = ($result->num_rows > 0) ? $result->fetch_all(MYSQLI_ASSOC) : [];
} else {
echo "Error en la consulta: " . $conn->error;
$fichas = [];
}
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Aplicación de Fichas</title>
<style>
body {
font-family: 'Arial', sans-serif;
margin: 0;
padding: 0;
}
nav {
background-color: #333;
padding: 10px;
text-align: center;
}
nav a {
color: white;
text-decoration: none;
margin: 0 10px;
}
.container {
max-width: 800px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 5px;
}
label {
display: block;
margin-bottom: 5px;
}
input {
width: 100%;
padding: 8px;
margin-bottom: 10px;
box-sizing: border-box;
}
input[type="submit"] {
background-color: #4caf50;
color: white;
cursor: pointer;
}
.form-container {
margin-bottom: 20px;
}
.separator {
border-top: 1px solid #ddd;
margin: 20px 0;
}
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 20px;
margin-top: 20px;
}
.grid-item {
border: 1px solid #ddd;
padding: 15px;
border-radius: 5px;
background-color: #f9f9f9;
}
h2 {
margin-bottom: 10px;
}
</style>
</head>
<body>
<!-- Encabezado con enlaces de navegación -->
<nav>
<a href="index.php">Inicio</a>
<a href="crear_usuario.php">Crear Usuario</a>
<a href="login.php">Iniciar Sesión</a>
<!-- Agrega más enlaces según tus necesidades -->
</nav>
<div class="container">
<!-- Formulario de ingreso y búsqueda de fichas -->
<form method="post" action="">
<!-- Campos para agregar ficha -->
<label for="numero_ficha">Número de Ficha:</label>
<input type="text" name="numero_ficha" required><br>
<label for="numero_archivo">Número de Archivo:</label>
<input type="text" name="numero_archivo" required><br>
<label for="estanteria">Estantería (Formato XX-XX-XX):</label>
<input type="text" name="estanteria" pattern="\d{2}-\d{2}-\d{2}" required title="Formato válido: XX-XX-XX"><br>
<input type="submit" name="agregar_ficha" value="Agregar Ficha">
</form>
<!-- Formulario de búsqueda de fichas -->
<div class="form-container">
<form action="" method="post">
<label for="numero_busqueda">Buscar por Número de Ficha:</label>
<input type="text" name="numero_busqueda" id="numero_busqueda" required>
<input type="hidden" name="accion" value="buscar_por_numero">
<button type="submit">Buscar por Número de Ficha</button>
</form>
</div>
<div class="form-container">
<form action="" method="post">
<label for="fecha_busqueda">Fecha a Buscar:</label>
<input type="date" name="fecha_busqueda" id="fecha_busqueda" required>
<input type="hidden" name="accion" value="buscar_por_fecha">
<button type="submit">Buscar por Fecha</button>
</form>
</div>
<div class="separator"></div>
<!-- Mostrar la lista de fichas -->
<?php
if (isset($resultadosBusqueda)) {
echo "<h2>Resultados de la Búsqueda:</h2>";
foreach ($resultadosBusqueda as $resultado) {
$ficha->mostrarFichaEnGrid($resultado);
}
} else {
echo "<h2>Listado de Fichas:</h2>";
$todasLasFichas = $ficha->obtenerFichas();
foreach ($todasLasFichas as $fichaItem) {
$ficha->mostrarFichaEnGrid($fichaItem);
}
}
?>
</div>
</body>
</html>