Auto commit: 2025-11-24T22:25:22.567Z

This commit is contained in:
Flatlogic Bot 2025-11-24 22:25:22 +00:00
parent 164954c0a2
commit c862b7dabc
7 changed files with 790 additions and 0 deletions

168
citas.php Normal file
View File

@ -0,0 +1,168 @@
<?php
require_once 'db/config.php';
require_once 'header.php';
try {
$pdo = db();
// Create table if it doesn't exist
$pdo->exec("CREATE TABLE IF NOT EXISTS citas (
id INT AUTO_INCREMENT PRIMARY KEY,
fecha DATE NOT NULL,
hora TIME NOT NULL,
id_departamento INT NOT NULL,
lugar VARCHAR(255),
usuarios TEXT,
estado VARCHAR(50) DEFAULT 'Pendiente',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (id_departamento) REFERENCES departamentos(id)
)");
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_cita'])) {
$fecha = $_POST['fecha'];
$hora = $_POST['hora'];
$id_departamento = $_POST['id_departamento'];
$lugar = trim($_POST['lugar']);
$usuarios = trim($_POST['usuarios']);
$estado = $_POST['estado'];
if (!empty($fecha) && !empty($hora) && !empty($id_departamento)) {
$stmt = $pdo->prepare("INSERT INTO citas (fecha, hora, id_departamento, lugar, usuarios, estado) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->execute([$fecha, $hora, $id_departamento, $lugar, $usuarios, $estado]);
echo '<div class="alert alert-success" role="alert">Cita añadida con éxito.</div>';
} else {
echo '<div class="alert alert-danger" role="alert">Fecha, hora y departamento son obligatorios.</div>';
}
}
// Fetch all departments for dropdown
$departamentos_stmt = $pdo->query("SELECT id, nombre FROM departamentos ORDER BY nombre");
$departamentos = $departamentos_stmt->fetchAll(PDO::FETCH_ASSOC);
// Fetch all citas
$stmt = $pdo->query("SELECT c.id, c.fecha, c.hora, dep.nombre as departamento_nombre, c.lugar, c.usuarios, c.estado, c.created_at
FROM citas c
JOIN departamentos dep ON c.id_departamento = dep.id
ORDER BY c.fecha DESC, c.hora DESC");
$citas = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
die("Error de base de datos: " . $e->getMessage());
}
?>
<div class="container-fluid px-4">
<h1 class="mt-4">Citas</h1>
<ol class="breadcrumb mb-4">
<li class="breadcrumb-item"><a href="index.php">Dashboard</a></li>
<li class="breadcrumb-item active">Citas</li>
</ol>
<div class="card mb-4">
<div class="card-header">
<i class="fas fa-table me-1"></i>
Añadir Nueva Cita
</div>
<div class="card-body">
<form action="citas.php" method="POST">
<div class="row mb-3">
<div class="col-md-6">
<div class="form-floating mb-3">
<input class="form-control" id="inputFecha" type="date" name="fecha" required />
<label for="inputFecha">Fecha</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating mb-3">
<input class="form-control" id="inputHora" type="time" name="hora" required />
<label for="inputHora">Hora</label>
</div>
</div>
</div>
<div class="row mb-3">
<div class="col-md-6">
<div class="form-floating mb-3">
<select class="form-select" id="selectDepartamento" name="id_departamento" required>
<option value="">Seleccione un departamento</option>
<?php foreach ($departamentos as $departamento): ?>
<option value="<?php echo $departamento['id']; ?>"><?php echo htmlspecialchars($departamento['nombre']); ?></option>
<?php endforeach; ?>
</select>
<label for="selectDepartamento">Departamento</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating mb-3">
<input class="form-control" id="inputLugar" type="text" name="lugar" placeholder="Lugar" />
<label for="inputLugar">Lugar (Lat, Lon)</label>
</div>
</div>
</div>
<div class="form-floating mb-3">
<textarea class="form-control" id="inputUsuarios" name="usuarios" placeholder="Usuarios" style="height: 100px;"></textarea>
<label for="inputUsuarios">Usuarios</label>
</div>
<div class="form-floating mb-3">
<select class="form-select" id="selectEstado" name="estado">
<option value="Pendiente">Pendiente</option>
<option value="Confirmada">Confirmada</option>
<option value="Cancelada">Cancelada</option>
</select>
<label for="selectEstado">Estado</label>
</div>
<div class="mt-4 mb-0">
<div class="d-grid">
<button type="submit" name="add_cita" class="btn btn-primary btn-block">Añadir Cita</button>
</div>
</div>
</form>
</div>
</div>
<div class="card mb-4">
<div class="card-header">
<i class="fas fa-table me-1"></i>
Lista de Citas
</div>
<div class="card-body">
<table id="datatablesSimple" class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Fecha y Hora</th>
<th>Departamento</th>
<th>Lugar</th>
<th>Usuarios</th>
<th>Estado</th>
</tr>
</thead>
<tbody>
<?php if (!empty($citas)):
foreach ($citas as $cita):
?>
<tr>
<td><?php echo htmlspecialchars($cita['id']); ?></td>
<td><?php echo htmlspecialchars($cita['fecha'] . ' ' . $cita['hora']); ?></td>
<td><?php echo htmlspecialchars($cita['departamento_nombre']); ?></td>
<td><?php echo htmlspecialchars($cita['lugar']); ?></td>
<td><?php echo htmlspecialchars($cita['usuarios']); ?></td>
<td><?php echo htmlspecialchars($cita['estado']); ?></td>
</tr>
<?php
endforeach;
else:
?>
<tr>
<td colspan="6" class="text-center">No hay citas registradas.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php
require_once 'footer.php';
?>

149
consultas.php Normal file
View File

@ -0,0 +1,149 @@
<?php
require_once 'db/config.php';
require_once 'header.php';
try {
$pdo = db();
// Create table if it doesn't exist
$pdo->exec("CREATE TABLE IF NOT EXISTS consultas (
id INT AUTO_INCREMENT PRIMARY KEY,
id_taxista INT NOT NULL,
id_departamento INT NOT NULL,
resultado TEXT,
fecha_consulta TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (id_taxista) REFERENCES drivers(id),
FOREIGN KEY (id_departamento) REFERENCES departamentos(id)
)");
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_consulta'])) {
$id_taxista = $_POST['id_taxista'];
$id_departamento = $_POST['id_departamento'];
$resultado = trim($_POST['resultado']);
if (!empty($id_taxista) && !empty($id_departamento)) {
$stmt = $pdo->prepare("INSERT INTO consultas (id_taxista, id_departamento, resultado) VALUES (?, ?, ?)");
$stmt->execute([$id_taxista, $id_departamento, $resultado]);
echo '<div class="alert alert-success" role="alert">Consulta añadida con éxito.</div>';
} else {
echo '<div class="alert alert-danger" role="alert">Taxista y departamento son obligatorios.</div>';
}
}
// Fetch all drivers for dropdown
$drivers_stmt = $pdo->query("SELECT id, name FROM drivers ORDER BY name");
$drivers = $drivers_stmt->fetchAll(PDO::FETCH_ASSOC);
// Fetch all departments for dropdown
$departamentos_stmt = $pdo->query("SELECT id, nombre FROM departamentos ORDER BY nombre");
$departamentos = $departamentos_stmt->fetchAll(PDO::FETCH_ASSOC);
// Fetch all consultas
$stmt = $pdo->query("SELECT c.id, d.name as taxista_nombre, dep.nombre as departamento_nombre, c.resultado, c.fecha_consulta
FROM consultas c
JOIN drivers d ON c.id_taxista = d.id
JOIN departamentos dep ON c.id_departamento = dep.id
ORDER BY c.fecha_consulta DESC");
$consultas = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
die("Error de base de datos: " . $e->getMessage());
}
?>
<div class="container-fluid px-4">
<h1 class="mt-4">Consultas</h1>
<ol class="breadcrumb mb-4">
<li class="breadcrumb-item"><a href="index.php">Dashboard</a></li>
<li class="breadcrumb-item active">Consultas</li>
</ol>
<div class="card mb-4">
<div class="card-header">
<i class="fas fa-table me-1"></i>
Añadir Nueva Consulta
</div>
<div class="card-body">
<form action="consultas.php" method="POST">
<div class="row mb-3">
<div class="col-md-6">
<div class="form-floating mb-3">
<select class="form-select" id="selectTaxista" name="id_taxista" required>
<option value="">Seleccione un taxista</option>
<?php foreach ($drivers as $driver): ?>
<option value="<?php echo $driver['id']; ?>"><?php echo htmlspecialchars($driver['name']); ?></option>
<?php endforeach; ?>
</select>
<label for="selectTaxista">Taxista</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating mb-3">
<select class="form-select" id="selectDepartamento" name="id_departamento" required>
<option value="">Seleccione un departamento</option>
<?php foreach ($departamentos as $departamento): ?>
<option value="<?php echo $departamento['id']; ?>"><?php echo htmlspecialchars($departamento['nombre']); ?></option>
<?php endforeach; ?>
</select>
<label for="selectDepartamento">Departamento</label>
</div>
</div>
</div>
<div class="form-floating mb-3">
<textarea class="form-control" id="inputResultado" name="resultado" placeholder="Resultado de la consulta" style="height: 100px;"></textarea>
<label for="inputResultado">Resultado</label>
</div>
<div class="mt-4 mb-0">
<div class="d-grid">
<button type="submit" name="add_consulta" class="btn btn-primary btn-block">Añadir Consulta</button>
</div>
</div>
</form>
</div>
</div>
<div class="card mb-4">
<div class="card-header">
<i class="fas fa-table me-1"></i>
Lista de Consultas
</div>
<div class="card-body">
<table id="datatablesSimple" class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Taxista</th>
<th>Departamento</th>
<th>Resultado</th>
<th>Fecha</th>
</tr>
</thead>
<tbody>
<?php if (!empty($consultas)):
foreach ($consultas as $consulta):
?>
<tr>
<td><?php echo htmlspecialchars($consulta['id']); ?></td>
<td><?php echo htmlspecialchars($consulta['taxista_nombre']); ?></td>
<td><?php echo htmlspecialchars($consulta['departamento_nombre']); ?></td>
<td><?php echo htmlspecialchars($consulta['resultado']); ?></td>
<td><?php echo htmlspecialchars($consulta['fecha_consulta']); ?></td>
</tr>
<?php
endforeach;
else:
?>
<tr>
<td colspan="5" class="text-center">No hay consultas registradas.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php
require_once 'footer.php';
?>

114
departamentos.php Normal file
View File

@ -0,0 +1,114 @@
<?php
require_once 'db/config.php';
require_once 'header.php';
try {
$pdo = db();
// Create table if it doesn't exist
$pdo->exec("CREATE TABLE IF NOT EXISTS departamentos (
id INT AUTO_INCREMENT PRIMARY KEY,
nombre VARCHAR(255) NOT NULL,
color VARCHAR(7) DEFAULT '#FFFFFF',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)");
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_department'])) {
$nombre = trim($_POST['nombre']);
$color = trim($_POST['color']);
if (!empty($nombre)) {
$stmt = $pdo->prepare("INSERT INTO departamentos (nombre, color) VALUES (?, ?)");
$stmt->execute([$nombre, $color]);
echo '<div class="alert alert-success" role="alert">Departamento añadido con éxito.</div>';
} else {
echo '<div class="alert alert-danger" role="alert">El nombre del departamento es obligatorio.</div>';
}
}
// Fetch all departments
$stmt = $pdo->query("SELECT id, nombre, color, created_at FROM departamentos ORDER BY created_at DESC");
$departamentos = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
die("Error de base de datos: " . $e->getMessage());
}
?>
<div class="container-fluid px-4">
<h1 class="mt-4">Departamentos</h1>
<ol class="breadcrumb mb-4">
<li class="breadcrumb-item"><a href="index.php">Dashboard</a></li>
<li class="breadcrumb-item active">Departamentos</li>
</ol>
<div class="card mb-4">
<div class="card-header">
<i class="fas fa-table me-1"></i>
Añadir Nuevo Departamento
</div>
<div class="card-body">
<form action="departamentos.php" method="POST">
<div class="row mb-3">
<div class="col-md-6">
<div class="form-floating mb-3 mb-md-0">
<input class="form-control" id="inputNombre" type="text" name="nombre" placeholder="Nombre del departamento" required />
<label for="inputNombre">Nombre del departamento</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating">
<input class="form-control" id="inputColor" type="color" name="color" value="#FFFFFF" />
<label for="inputColor">Color</label>
</div>
</div>
</div>
<div class="mt-4 mb-0">
<div class="d-grid">
<button type="submit" name="add_department" class="btn btn-primary btn-block">Añadir Departamento</button>
</div>
</div>
</form>
</div>
</div>
<div class="card mb-4">
<div class="card-header">
<i class="fas fa-table me-1"></i>
Lista de Departamentos
</div>
<div class="card-body">
<table id="datatablesSimple" class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Nombre</th>
<th>Color</th>
<th>Fecha de Creación</th>
</tr>
</thead>
<tbody>
<?php if (!empty($departamentos)): ?>
<?php foreach ($departamentos as $departamento): ?>
<tr>
<td><?php echo htmlspecialchars($departamento['id']); ?></td>
<td><?php echo htmlspecialchars($departamento['nombre']); ?></td>
<td style="background-color: <?php echo htmlspecialchars($departamento['color']); ?>;"><?php echo htmlspecialchars($departamento['color']); ?></td>
<td><?php echo htmlspecialchars($departamento['created_at']); ?></td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="4" class="text-center">No hay departamentos registrados.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php
require_once 'footer.php';
?>

147
documents.php Normal file
View File

@ -0,0 +1,147 @@
<?php
require_once 'db/config.php';
// --- DB Schema Setup ---
try {
$pdo = db();
// Create documents table
$pdo->exec("CREATE TABLE IF NOT EXISTS documents (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
description TEXT,
file_name VARCHAR(255) NOT NULL,
file_path VARCHAR(255) NOT NULL,
uploaded_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");
} catch (PDOException $e) {
die("DB ERROR: " . $e->getMessage());
}
// --- File Upload Logic ---
$upload_dir = 'uploads/';
$message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['document'])) {
if (!is_dir($upload_dir)) {
mkdir($upload_dir, 0755, true);
}
$title = $_POST['title'] ?? 'Sin Título';
$description = $_POST['description'] ?? '';
$file_name = basename($_FILES['document']['name']);
$file_tmp = $_FILES['document']['tmp_name'];
$file_error = $_FILES['document']['error'];
if ($file_error === UPLOAD_ERR_OK) {
$safe_file_name = uniqid() . '-' . preg_replace("/[^a-zA-Z0-9._-]/", "", $file_name);
$file_path = $upload_dir . $safe_file_name;
if (move_uploaded_file($file_tmp, $file_path)) {
try {
$stmt = $pdo->prepare("INSERT INTO documents (title, description, file_name, file_path) VALUES (?, ?, ?, ?)");
$stmt->execute([$title, $description, $file_name, $file_path]);
$message = '<div class="alert alert-success">Documento subido con éxito.</div>';
} catch (PDOException $e) {
$message = '<div class="alert alert-danger">Error al guardar en la base de datos: ' . $e->getMessage() . '</div>';
}
} else {
$message = '<div class="alert alert-danger">Error al mover el fichero subido.</div>';
}
} else {
$message = '<div class="alert alert-danger">Error en la subida del fichero: ' . $file_error . '</div>';
}
}
// --- Fetch Documents ---
$documents = [];
try {
$stmt = $pdo->query("SELECT id, title, description, file_name, file_path, uploaded_at FROM documents ORDER BY uploaded_at DESC");
$documents = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
$message .= '<div class="alert alert-danger">Error al obtener los documentos: ' . $e->getMessage() . '</div>';
}
include 'header.php';
?>
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h2">Gestor de Documentos</h1>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#uploadModal">
<i class="bi bi-upload"></i> Subir Documento
</button>
</div>
<?php echo $message; ?>
<div class="card">
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th>Título</th>
<th>Descripción</th>
<th>Fichero</th>
<th>Fecha de Subida</th>
<th>Acciones</th>
</tr>
</thead>
<tbody>
<?php if (empty($documents)): ?>
<tr>
<td colspan="5" class="text-center">No hay documentos todavía.</td>
</tr>
<?php else: ?>
<?php foreach ($documents as $doc): ?>
<tr>
<td><?php echo htmlspecialchars($doc['title']); ?></td>
<td><?php echo htmlspecialchars($doc['description']); ?></td>
<td><?php echo htmlspecialchars($doc['file_name']); ?></td>
<td><?php echo date("d/m/Y H:i", strtotime($doc['uploaded_at'])); ?></td>
<td>
<a href="<?php echo htmlspecialchars($doc['file_path']); ?>" class="btn btn-sm btn-outline-primary" download>
<i class="bi bi-download"></i> Descargar
</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Upload Modal -->
<div class="modal fade" id="uploadModal" tabindex="-1" aria-labelledby="uploadModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="uploadModalLabel">Subir Nuevo Documento</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="documents.php" method="post" enctype="multipart/form-data">
<div class="modal-body">
<div class="mb-3">
<label for="title" class="form-label">Título del Documento</label>
<input type="text" class="form-control" id="title" name="title" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Descripción (Opcional)</label>
<textarea class="form-control" id="description" name="description" rows="3"></textarea>
</div>
<div class="mb-3">
<label for="document" class="form-label">Seleccionar Fichero</label>
<input class="form-control" type="file" id="document" name="document" required>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cerrar</button>
<button type="submit" class="btn btn-primary">Subir</button>
</div>
</form>
</div>
</div>
</div>
<?php include 'footer.php'; ?>

View File

@ -52,6 +52,21 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="drivers.php"><i class="bi bi-person-badge"></i> Conductores</a> <a class="nav-link" href="drivers.php"><i class="bi bi-person-badge"></i> Conductores</a>
</li> </li>
<li class="nav-item">
<a class="nav-link" href="documents.php"><i class="bi bi-file-earmark-text"></i> Documentos</a>
</li>
<li class="nav-item">
<a class="nav-link" href="departamentos.php"><i class="bi bi-building"></i> Departamentos</a>
</li>
<li class="nav-item">
<a class="nav-link" href="consultas.php"><i class="bi bi-patch-question"></i> Consultas</a>
</li>
<li class="nav-item">
<a class="nav-link" href="citas.php"><i class="bi bi-calendar-check"></i> Citas</a>
</li>
<li class="nav-item">
<a class="nav-link" href="localizacion.php"><i class="bi bi-geo-alt"></i> Localización</a>
</li>
</ul> </ul>
</div> </div>
</div> </div>

197
localizacion.php Normal file
View File

@ -0,0 +1,197 @@
<?php
require_once 'db/config.php';
require_once 'header.php';
try {
$pdo = db();
// Create taxis table if it doesn't exist (as a dependency)
$pdo->exec("CREATE TABLE IF NOT EXISTS taxis (
id INT AUTO_INCREMENT PRIMARY KEY,
matricula VARCHAR(255) NOT NULL UNIQUE,
modelo VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)");
// Create localizacion_taxis table if it doesn't exist
$pdo->exec("CREATE TABLE IF NOT EXISTS localizacion_taxis (
id INT AUTO_INCREMENT PRIMARY KEY,
id_taxi INT NOT NULL,
latitud DECIMAL(10, 8) NOT NULL,
longitud DECIMAL(11, 8) NOT NULL,
ultima_actualizacion TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (id_taxi) REFERENCES taxis(id)
)");
// Handle form submission to add a new taxi for simplicity
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_taxi'])) {
$matricula = trim($_POST['matricula']);
$modelo = trim($_POST['modelo']);
if(!empty($matricula)) {
$stmt = $pdo->prepare("INSERT INTO taxis (matricula, modelo) VALUES (?, ?) ON DUPLICATE KEY UPDATE modelo=VALUES(modelo)");
$stmt->execute([$matricula, $modelo]);
}
}
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_localizacion'])) {
$id_taxi = $_POST['id_taxi'];
$latitud = $_POST['latitud'];
$longitud = $_POST['longitud'];
if (!empty($id_taxi) && is_numeric($latitud) && is_numeric($longitud)) {
// Check if a location for this taxi already exists
$stmt_check = $pdo->prepare("SELECT id FROM localizacion_taxis WHERE id_taxi = ?");
$stmt_check->execute([$id_taxi]);
$existing_location = $stmt_check->fetch();
if ($existing_location) {
// Update existing location
$stmt = $pdo->prepare("UPDATE localizacion_taxis SET latitud = ?, longitud = ? WHERE id_taxi = ?");
$stmt->execute([$latitud, $longitud, $id_taxi]);
} else {
// Insert new location
$stmt = $pdo->prepare("INSERT INTO localizacion_taxis (id_taxi, latitud, longitud) VALUES (?, ?, ?)");
$stmt->execute([$id_taxi, $latitud, $longitud]);
}
echo '<div class="alert alert-success" role="alert">Localización actualizada con éxito.</div>';
} else {
echo '<div class="alert alert-danger" role="alert">Todos los campos son obligatorios y la latitud/longitud deben ser números.</div>';
}
}
// Fetch all taxis for dropdown
$taxis_stmt = $pdo->query("SELECT id, matricula, modelo FROM taxis ORDER BY matricula");
$taxis = $taxis_stmt->fetchAll(PDO::FETCH_ASSOC);
// Fetch all locations
$stmt = $pdo->query("SELECT lt.id, t.matricula, t.modelo, lt.latitud, lt.longitud, lt.ultima_actualizacion
FROM localizacion_taxis lt
JOIN taxis t ON lt.id_taxi = t.id
ORDER BY lt.ultima_actualizacion DESC");
$localizaciones = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
die("Error de base de datos: " . $e->getMessage());
}
?>
<div class="container-fluid px-4">
<h1 class="mt-4">Localización de Taxis</h1>
<ol class="breadcrumb mb-4">
<li class="breadcrumb-item"><a href="index.php">Dashboard</a></li>
<li class="breadcrumb-item active">Localización</li>
</ol>
<div class="row">
<div class="col-xl-6">
<div class="card mb-4">
<div class="card-header">
<i class="fas fa-taxi me-1"></i>
Añadir o Actualizar Localización
</div>
<div class="card-body">
<form action="localizacion.php" method="POST">
<div class="form-floating mb-3">
<select class="form-select" id="selectTaxi" name="id_taxi" required>
<option value="">Seleccione un taxi</option>
<?php foreach ($taxis as $taxi): ?>
<option value="<?php echo $taxi['id']; ?>"><?php echo htmlspecialchars($taxi['matricula'] . ' - ' . $taxi['modelo']); ?></option>
<?php endforeach; ?>
</select>
<label for="selectTaxi">Taxi</label>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-floating mb-3">
<input class="form-control" id="inputLatitud" type="text" name="latitud" placeholder="Latitud" required />
<label for="inputLatitud">Latitud</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating mb-3">
<input class="form-control" id="inputLongitud" type="text" name="longitud" placeholder="Longitud" required />
<label for="inputLongitud">Longitud</label>
</div>
</div>
</div>
<div class="mt-4 mb-0">
<div class="d-grid">
<button type="submit" name="add_localizacion" class="btn btn-primary btn-block">Actualizar Localización</button>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="col-xl-6">
<div class="card mb-4">
<div class="card-header">
<i class="fas fa-plus me-1"></i>
Añadir Nuevo Taxi (para demo)
</div>
<div class="card-body">
<form action="localizacion.php" method="POST">
<div class="form-floating mb-3">
<input class="form-control" id="inputMatricula" type="text" name="matricula" placeholder="Matrícula" required />
<label for="inputMatricula">Matrícula</label>
</div>
<div class="form-floating mb-3">
<input class="form-control" id="inputModelo" type="text" name="modelo" placeholder="Modelo" />
<label for="inputModelo">Modelo</label>
</div>
<div class="mt-4 mb-0">
<div class="d-grid">
<button type="submit" name="add_taxi" class="btn btn-secondary btn-block">Añadir Taxi</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="card mb-4">
<div class="card-header">
<i class="fas fa-map-marker-alt me-1"></i>
Últimas Localizaciones Registradas
</div>
<div class="card-body">
<table id="datatablesSimple" class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Taxi</th>
<th>Latitud</th>
<th>Longitud</th>
<th>Última Actualización</th>
</tr>
</thead>
<tbody>
<?php if (!empty($localizaciones)):
foreach ($localizaciones as $localizacion):
?>
<tr>
<td><?php echo htmlspecialchars($localizacion['id']); ?></td>
<td><?php echo htmlspecialchars($localizacion['matricula'] . ' (' . $localizacion['modelo'] . ')'); ?></td>
<td><?php echo htmlspecialchars($localizacion['latitud']); ?></td>
<td><?php echo htmlspecialchars($localizacion['longitud']); ?></td>
<td><?php echo htmlspecialchars($localizacion['ultima_actualizacion']); ?></td>
</tr>
<?php
endforeach;
else:
?>
<tr>
<td colspan="5" class="text-center">No hay localizaciones registradas.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php
require_once 'footer.php';
?>