From 786ed300423ec75e606ffa178a18b0474c0c2d69 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Mon, 24 Nov 2025 23:41:00 +0000 Subject: [PATCH] Auto commit: 2025-11-24T23:41:00.323Z --- api.php | 2 +- citas.php | 298 +++++++++++------- consultas.php | 227 +++++++------ departamentos.php | 216 ++++++++----- documents.php | 219 +++++++++++-- drivers.php | 194 ++++++------ horarios.php | 175 ++++++++++ index.php | 204 ++++++++++-- localizacion.php | 64 ++-- ...a-06d6de8c-48da-44b5-96b3-48d6e76a99ab.pdf | Bin 0 -> 1649 bytes ...a-06d6de8c-48da-44b5-96b3-48d6e76a99ab.pdf | Bin 0 -> 1649 bytes ...a-06d6de8c-48da-44b5-96b3-48d6e76a99ab.pdf | Bin 0 -> 1649 bytes 12 files changed, 1129 insertions(+), 470 deletions(-) create mode 100644 horarios.php create mode 100644 uploads/6924e23acfc77-6924d9955d1da-06d6de8c-48da-44b5-96b3-48d6e76a99ab.pdf create mode 100644 uploads/6924e34b03fd5-6924d9955d1da-06d6de8c-48da-44b5-96b3-48d6e76a99ab.pdf create mode 100644 uploads/6924e4d09fb71-6924d9955d1da-06d6de8c-48da-44b5-96b3-48d6e76a99ab.pdf diff --git a/api.php b/api.php index 642adda..37fbddd 100644 --- a/api.php +++ b/api.php @@ -27,7 +27,7 @@ try { case 'get_current_locations': default: $stmt = $pdo->query( - "SELECT t.matricula, t.modelo, lt.latitud, lt.longitud, lt.ultima_actualizacion " . + "SELECT t.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" diff --git a/citas.php b/citas.php index 6653581..43f92a8 100644 --- a/citas.php +++ b/citas.php @@ -2,167 +2,253 @@ require_once 'db/config.php'; require_once 'header.php'; +$message = ''; +$message_type = ''; + +// --- DB Schema and Data Fetching --- try { $pdo = db(); - // Create table if it doesn't exist + // Add id_conductor to citas table $pdo->exec("CREATE TABLE IF NOT EXISTS citas ( id INT AUTO_INCREMENT PRIMARY KEY, - fecha DATE NOT NULL, - hora TIME NOT NULL, + title VARCHAR(255) NOT NULL, + start_event DATETIME NOT NULL, + end_event DATETIME NOT NULL, id_departamento INT NOT NULL, + id_conductor INT, lugar VARCHAR(255), usuarios TEXT, estado VARCHAR(50) DEFAULT 'Pendiente', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - FOREIGN KEY (id_departamento) REFERENCES departamentos(id) + FOREIGN KEY (id_departamento) REFERENCES departamentos(id) ON DELETE CASCADE, + FOREIGN KEY (id_conductor) REFERENCES taxis(id) ON DELETE SET NULL )"); + + // Check if id_conductor column exists and add it if not + $stmt = $pdo->query("SHOW COLUMNS FROM citas LIKE 'id_conductor'"); + if ($stmt->rowCount() == 0) { + $pdo->exec("ALTER TABLE citas ADD COLUMN id_conductor INT NULL AFTER id_departamento, ADD FOREIGN KEY (id_conductor) REFERENCES taxis(id) ON DELETE SET NULL;"); + } + + + // Fetch departments and conductors + $departamentos = $pdo->query("SELECT id, nombre FROM departamentos ORDER BY nombre")->fetchAll(PDO::FETCH_ASSOC); + $conductores = $pdo->query("SELECT id, matricula FROM taxis ORDER BY matricula")->fetchAll(PDO::FETCH_ASSOC); + + // Get selected filters + $selected_depto_id = $_GET['id_departamento'] ?? null; + $selected_conductor_id = $_GET['id_conductor'] ?? null; // Handle form submission if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_cita'])) { + $title = $_POST['title']; $fecha = $_POST['fecha']; - $hora = $_POST['hora']; + $hora_inicio = $_POST['hora_inicio']; + $hora_fin = $_POST['hora_fin']; $id_departamento = $_POST['id_departamento']; + $id_conductor = $_POST['id_conductor'] ?: null; $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 ''; + if (!empty($title) && !empty($fecha) && !empty($hora_inicio) && !empty($hora_fin) && !empty($id_departamento)) { + $start_event = $fecha . ' ' . $hora_inicio; + $end_event = $fecha . ' ' . $hora_fin; + + $stmt = $pdo->prepare("INSERT INTO citas (title, start_event, end_event, id_departamento, id_conductor, lugar, usuarios, estado) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); + $stmt->execute([$title, $start_event, $end_event, $id_departamento, $id_conductor, $lugar, $usuarios, $estado]); + $message = '
Cita añadida con éxito.
'; } else { - echo ''; + $message = '
Título, fecha, horas y departamento son obligatorios.
'; } } - // 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 citas for the calendar and list + $events = []; + $citas_list = []; + + $sql = "SELECT c.id, c.title, c.start_event as start, c.end_event as end, c.estado, c.lugar, c.usuarios, c.created_at, t.matricula as conductor_nombre + FROM citas c + LEFT JOIN taxis t ON c.id_conductor = t.id + WHERE 1=1"; + $params = []; + if ($selected_depto_id) { + $sql .= " AND c.id_departamento = ?"; + $params[] = $selected_depto_id; + } + if ($selected_conductor_id) { + $sql .= " AND c.id_conductor = ?"; + $params[] = $selected_conductor_id; + } + $sql .= " ORDER BY c.start_event DESC"; + + $stmt = $pdo->prepare($sql); + $stmt->execute($params); + $citas_list = $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); + // Format for FullCalendar + foreach($citas_list as $cita) { + $events[] = [ + 'title' => $cita['title'], + 'start' => $cita['start'], + 'end' => $cita['end'], + 'extendedProps' => [ + 'estado' => $cita['estado'], + 'conductor' => $cita['conductor_nombre'] ?? 'N/A' + ] + ]; + } } catch (PDOException $e) { - die("Error de base de datos: " . $e->getMessage()); + $message = "Error de base de datos: " . $e->getMessage(); + $message_type = 'danger'; } ?> + + +
-

Citas

+

Calendario de Citas

+ + + +
-
- - Añadir Nueva Cita -
+
Filtros
-
-
+ +
-
- - -
+
-
- - -
-
-
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
- - -
-
-
- +
-
-
- - Lista de Citas + +
+
+
+
-
- - - - - - - - - - - - - + +
+
Listado de Citas
+
+
IDFecha y HoraDepartamentoLugarUsuariosEstado
+ + + + + - - - + + + + + - - - - - - - -
TítuloConductorInicioFinEstadoLugarUsuarios
No hay citas para los filtros seleccionados.
No hay citas registradas.
+ + + +
+
+ +
Por favor, seleccione un departamento o conductor para ver el calendario y las citas.
+ + +
+
Añadir Nueva Cita
+
+
+
+ + +
+
+
+
+
+
+
+
+
+
+
+ + +
+
+ + +
+
+
+
+ + + + +?> \ No newline at end of file diff --git a/consultas.php b/consultas.php index 6a12016..778bd9a 100644 --- a/consultas.php +++ b/consultas.php @@ -2,53 +2,82 @@ require_once 'db/config.php'; require_once 'header.php'; +$message = ''; +$message_type = ''; + +// --- DB Schema and Data Fetching --- try { $pdo = db(); - // Create table if it doesn't exist + // Create/update consultas table $pdo->exec("CREATE TABLE IF NOT EXISTS consultas ( id INT AUTO_INCREMENT PRIMARY KEY, - id_taxista INT NOT NULL, + id_conductor INT NOT NULL, id_departamento INT NOT NULL, + asunto VARCHAR(255) NOT NULL, resultado TEXT, + status VARCHAR(50) DEFAULT 'Pendiente', fecha_consulta TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - FOREIGN KEY (id_taxista) REFERENCES drivers(id), - FOREIGN KEY (id_departamento) REFERENCES departamentos(id) + FOREIGN KEY (id_conductor) REFERENCES taxis(id) ON DELETE CASCADE, + FOREIGN KEY (id_departamento) REFERENCES departamentos(id) ON DELETE CASCADE )"); + // Fetch departments for dropdowns + $departamentos = $pdo->query("SELECT id, nombre FROM departamentos ORDER BY nombre")->fetchAll(PDO::FETCH_ASSOC); + + // Fetch taxis/conductores for dropdowns + $conductores = $pdo->query("SELECT id, matricula FROM taxis ORDER BY matricula")->fetchAll(PDO::FETCH_ASSOC); + + // Get selected department for filtering + $selected_depto_id = $_GET['id_departamento'] ?? null; + // Handle form submission if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_consulta'])) { - $id_taxista = $_POST['id_taxista']; + $id_conductor = $_POST['id_conductor']; $id_departamento = $_POST['id_departamento']; + $asunto = trim($_POST['asunto']); $resultado = trim($_POST['resultado']); + $status = $_POST['status']; - 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 ''; + if (!empty($id_conductor) && !empty($id_departamento) && !empty($asunto)) { + $stmt = $pdo->prepare("INSERT INTO consultas (id_conductor, id_departamento, asunto, resultado, status) VALUES (?, ?, ?, ?, ?)"); + $stmt->execute([$id_conductor, $id_departamento, $asunto, $resultado, $status]); + $message = '
Consulta añadida con éxito.
'; } else { - echo ''; + $message = '
Conductor, departamento y asunto son obligatorios.
'; } } - // 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 consultations + $filter_status = $_GET['status'] ?? null; + $sql = "SELECT c.id, t.matricula as conductor_nombre, dep.nombre as departamento_nombre, c.asunto, c.resultado, c.status, c.fecha_consulta + FROM consultas c + JOIN taxis t ON c.id_conductor = t.id + JOIN departamentos dep ON c.id_departamento = dep.id"; + + $conditions = []; + $params = []; + if ($filter_status) { + $conditions[] = "c.status = :status"; + $params[':status'] = $filter_status; + } + if ($selected_depto_id) { + $conditions[] = "c.id_departamento = :id_departamento"; + $params[':id_departamento'] = $selected_depto_id; + } - // 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"); + if (count($conditions) > 0) { + $sql .= " WHERE " . implode(' AND ', $conditions); + } + + $sql .= " ORDER BY c.fecha_consulta DESC"; + $stmt = $pdo->prepare($sql); + $stmt->execute($params); $consultas = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { - die("Error de base de datos: " . $e->getMessage()); + $message = "Error de base de datos: " . $e->getMessage(); + $message_type = 'danger'; } ?> @@ -59,85 +88,101 @@ try { + + + +
-
- - Añadir Nueva Consulta -
+
Filtro por Departamento
-
-
-
-
- - -
-
-
-
- - -
-
-
-
- - -
-
-
- -
+ +
+ + + + + Limpiar
-
- - Lista de Consultas -
+
Añadir Nueva Consulta
- - - - - - - - - - + +
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ +
+ + + + +
+
Lista de Consultas
+
+
IDTaxistaDepartamentoResultadoFecha
+ - - - - - - - - - + + + - + + + + + + - +
ConductorDepartamentoAsuntoResultadoEstadoFecha
No hay consultas.
No hay consultas registradas.
diff --git a/departamentos.php b/departamentos.php index 6e0b2d5..440b869 100644 --- a/departamentos.php +++ b/departamentos.php @@ -1,114 +1,160 @@ 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 - )"); + nombre VARCHAR(255) NOT NULL UNIQUE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"); - // 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 ''; - } else { - echo ''; + $message = ''; + // Handle POST requests + if ($_SERVER['REQUEST_METHOD'] === 'POST') { + // Add new + if (isset($_POST['add_departamento'])) { + $nombre = trim($_POST['nombre']); + if (!empty($nombre)) { + $stmt = $pdo->prepare("INSERT INTO departamentos (nombre) VALUES (?)"); + $stmt->execute([$nombre]); + $message = '
Departamento añadido.
'; + } else { + $message = '
El nombre no puede estar vacío.
'; + } + } + // Update + elseif (isset($_POST['update_departamento'])) { + $id = $_POST['id']; + $nombre = trim($_POST['nombre']); + if (!empty($nombre)) { + $stmt = $pdo->prepare("UPDATE departamentos SET nombre = ? WHERE id = ?"); + $stmt->execute([$nombre, $id]); + $message = '
Departamento actualizado.
'; + } else { + $message = '
El nombre no puede estar vacío.
'; + } + } + // Delete + elseif (isset($_POST['delete_departamento'])) { + $id = $_POST['id']; + $stmt = $pdo->prepare("DELETE FROM departamentos WHERE id = ?"); + $stmt->execute([$id]); + $message = '
Departamento eliminado.
'; } } // 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); + $departamentos = $pdo->query("SELECT * FROM departamentos ORDER BY nombre")->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { - die("Error de base de datos: " . $e->getMessage()); + die("DB ERROR: " . $e->getMessage()); } + +include 'header.php'; ?>
-

Departamentos

+

Gestión de Departamentos

-
-
- - Añadir Nuevo Departamento -
-
-
-
-
-
- - -
-
-
-
- - -
-
-
-
-
- -
-
-
-
-
+ -
-
- - Lista de Departamentos +
+ +
+
+
+ + Añadir Nuevo Departamento +
+
+
+
+ + +
+
+ +
+
+
+
-
- - - - - - - - - - - - - - - - - - - - - - - - - -
IDNombreColorFecha de Creación
No hay departamentos registrados.
+ + +
+
+
+ + Listado de Departamentos +
+
+
+ + + + + + + + + + + + + + + + + + + + + + +
NombreAcciones
No hay departamentos.
+ +
+ + +
+
+
+
+
- + \ No newline at end of file diff --git a/documents.php b/documents.php index 07fc04b..6ec3992 100644 --- a/documents.php +++ b/documents.php @@ -4,61 +4,125 @@ require_once 'db/config.php'; // --- DB Schema Setup --- try { $pdo = db(); - // Create documents table + // Create documents table with new fields $pdo->exec("CREATE TABLE IF NOT EXISTS documents ( id INT AUTO_INCREMENT PRIMARY KEY, + id_conductor INT, + tipo_documento VARCHAR(255), 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 + uploaded_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (id_conductor) REFERENCES taxis(id) ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"); + + // Add columns if they don't exist (for existing tables) + $check_columns = $pdo->query("SHOW COLUMNS FROM documents LIKE 'id_conductor'"); + if ($check_columns->rowCount() == 0) { + $pdo->exec("ALTER TABLE documents ADD COLUMN id_conductor INT, ADD FOREIGN KEY (id_conductor) REFERENCES taxis(id) ON DELETE SET NULL;"); + } + $check_columns = $pdo->query("SHOW COLUMNS FROM documents LIKE 'tipo_documento'"); + if ($check_columns->rowCount() == 0) { + $pdo->exec("ALTER TABLE documents ADD COLUMN tipo_documento VARCHAR(255);"); + } + } catch (PDOException $e) { die("DB ERROR: " . $e->getMessage()); } -// --- File Upload Logic --- +// --- File Upload & Update Logic --- $upload_dir = 'uploads/'; $message = ''; -if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['document'])) { - if (!is_dir($upload_dir)) { - mkdir($upload_dir, 0755, true); +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $pdo = db(); + // Handle Update + if (isset($_POST['update_document'])) { + $id = $_POST['document_id']; + $title = $_POST['title']; + $description = $_POST['description']; + $id_conductor = $_POST['id_conductor']; + $tipo_documento = $_POST['tipo_documento']; + + try { + $stmt = $pdo->prepare("UPDATE documents SET title = ?, description = ?, id_conductor = ?, tipo_documento = ? WHERE id = ?"); + $stmt->execute([$title, $description, $id_conductor, $tipo_documento, $id]); + $message = '
Documento actualizado con éxito.
'; + } catch (PDOException $e) { + $message = '
Error al actualizar: ' . $e->getMessage() . '
'; + } } + // Handle Upload + elseif (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']; + $title = $_POST['title'] ?? 'Sin Título'; + $description = $_POST['description'] ?? ''; + $id_conductor = $_POST['id_conductor'] ?? null; + $tipo_documento = $_POST['tipo_documento'] ?? ''; + $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 ($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 = '
Documento subido con éxito.
'; - } catch (PDOException $e) { - $message = '
Error al guardar en la base de datos: ' . $e->getMessage() . '
'; + if (move_uploaded_file($file_tmp, $file_path)) { + try { + $stmt = $pdo->prepare("INSERT INTO documents (title, description, id_conductor, tipo_documento, file_name, file_path) VALUES (?, ?, ?, ?, ?, ?)"); + $stmt->execute([$title, $description, $id_conductor, $tipo_documento, $file_name, $file_path]); + $message = '
Documento subido con éxito.
'; + } catch (PDOException $e) { + $message = '
Error al guardar en la base de datos: ' . $e->getMessage() . '
'; + } + } else { + $message = '
Error al mover el fichero subido.
'; } } else { - $message = '
Error al mover el fichero subido.
'; + $message = '
Error en la subida del fichero: ' . $file_error . '
'; } - } else { - $message = '
Error en la subida del fichero: ' . $file_error . '
'; } } -// --- Fetch Documents --- +// --- Fetch Data --- $documents = []; +$conductores = []; try { - $stmt = $pdo->query("SELECT id, title, description, file_name, file_path, uploaded_at FROM documents ORDER BY uploaded_at DESC"); + $pdo = db(); + + // Fetch drivers (taxis) + $conductores = $pdo->query("SELECT id, matricula, modelo FROM taxis ORDER BY matricula")->fetchAll(PDO::FETCH_ASSOC); + + // Fetch documents with driver info + $sort_column = $_GET['sort'] ?? 'uploaded_at'; + $sort_order = $_GET['order'] ?? 'DESC'; + $valid_columns = ['title', 'tipo_documento', 'conductor', 'uploaded_at']; + if (!in_array($sort_column, $valid_columns)) { + $sort_column = 'uploaded_at'; + } + + $sql = "SELECT d.id, d.title, d.description, d.file_name, d.file_path, d.uploaded_at, d.tipo_documento, t.matricula as conductor, d.id_conductor + FROM documents d + LEFT JOIN taxis t ON d.id_conductor = t.id + ORDER BY $sort_column $sort_order"; + + $stmt = $pdo->query($sql); $documents = $stmt->fetchAll(PDO::FETCH_ASSOC); + } catch (PDOException $e) { - $message .= '
Error al obtener los documentos: ' . $e->getMessage() . '
'; + $message .= '
Error al obtener los datos: ' . $e->getMessage() . '
'; +} + +function get_sort_link($column, $display) { + $sort_column = $_GET['sort'] ?? 'uploaded_at'; + $sort_order = $_GET['order'] ?? 'DESC'; + $order = ($sort_column == $column && $sort_order == 'ASC') ? 'DESC' : 'ASC'; + $icon = $sort_column == $column ? ($sort_order == 'ASC' ? 'bi-sort-up' : 'bi-sort-down') : 'bi-arrow-down-up-square'; + return '' . $display . ' '; } include 'header.php'; @@ -79,29 +143,42 @@ include 'header.php'; - + + + - + - + + + @@ -123,12 +200,25 @@ include 'header.php'; - + + + + + + \ No newline at end of file diff --git a/drivers.php b/drivers.php index 7126ad6..fe48dff 100644 --- a/drivers.php +++ b/drivers.php @@ -1,146 +1,136 @@ exec("CREATE TABLE IF NOT EXISTS drivers ( - id INT AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(100) NOT NULL, - license_number VARCHAR(50) NOT NULL, - phone VARCHAR(20) NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP - );"); -} catch (PDOException $e) { - // die("DB error: " . $e->getMessage()); // Avoid dying on production - $message = 'Error de conexión con la base de datos.'; - $message_type = 'danger'; -} + // Add department FK to taxis table + $check_column = $pdo->query("SHOW COLUMNS FROM taxis LIKE 'id_departamento'"); + if ($check_column->rowCount() == 0) { + $pdo->exec("ALTER TABLE taxis ADD COLUMN id_departamento INT, ADD FOREIGN KEY (id_departamento) REFERENCES departamentos(id) ON DELETE SET NULL;"); + } -// Handle POST request to add a new driver -if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_driver'])) { - $name = trim($_POST['name']); - $license_number = trim($_POST['license_number']); - $phone = trim($_POST['phone']); + // Handle POST requests + if ($_SERVER['REQUEST_METHOD'] === 'POST') { + // Add new taxi + if (isset($_POST['add_taxi'])) { + $matricula = trim($_POST['matricula']); + $modelo = trim($_POST['modelo']); + $id_departamento = $_POST['id_departamento'] ?: null; - if (!empty($name) && !empty($license_number) && !empty($phone)) { - try { - $sql = "INSERT INTO drivers (name, license_number, phone) VALUES (:name, :license_number, :phone)"; - $stmt = $pdo->prepare($sql); - $stmt->execute([ - ':name' => $name, - ':license_number' => $license_number, - ':phone' => $phone - ]); - $message = 'Conductor añadido exitosamente.'; - $message_type = 'success'; - } catch (PDOException $e) { - $message = 'Error al añadir conductor: ' . $e->getMessage(); - $message_type = 'danger'; + if (!empty($matricula)) { + $sql = "INSERT INTO taxis (matricula, modelo, id_departamento) VALUES (?, ?, ?)"; + $pdo->prepare($sql)->execute([$matricula, $modelo, $id_departamento]); + $message = 'Taxi/Conductor añadido exitosamente.'; + $message_type = 'success'; + } else { + $message = 'La matrícula es obligatoria.'; + $message_type = 'warning'; + } } - } else { - $message = 'Por favor, complete todos los campos.'; - $message_type = 'warning'; } -} -// Fetch all drivers -$drivers = []; -if(isset($pdo)) { - try { - $stmt = $pdo->query("SELECT id, name, license_number, phone, created_at FROM drivers ORDER BY id DESC"); - $drivers = $stmt->fetchAll(PDO::FETCH_ASSOC); - } catch (PDOException $e) { - $message = 'Error al obtener los conductores: ' . $e->getMessage(); - $message_type = 'danger'; - } + // Fetch departments for dropdown + $departamentos = $pdo->query("SELECT id, nombre FROM departamentos ORDER BY nombre")->fetchAll(PDO::FETCH_ASSOC); + + // Fetch all taxis with department info + $taxis = $pdo->query( + "SELECT t.*, d.nombre as departamento_nombre + FROM taxis t + LEFT JOIN departamentos d ON t.id_departamento = d.id + ORDER BY t.matricula ASC" + )->fetchAll(PDO::FETCH_ASSOC); + +} catch (PDOException $e) { + $message = 'Error de base de datos: ' . $e->getMessage(); + $message_type = 'danger'; } ?> -
-

Gestión de Conductores

- -
+
+
+

Gestión de Taxis/Conductores

+ +
- - - + + + -
-
-
-
Título Descripción FicheroFecha de Subida Acciones
No hay documentos todavía.No hay documentos todavía.
- Descargar + +
- - - - - - - - - - - +
+
+
+
IDNombreNº LicenciaTeléfonoFecha de Registro
+ - + + + + - - - - - - - - - - - - -
No hay conductores registrados.MatrículaModeloDepartamentoFecha de Registro
+ + + + No hay taxis registrados. + + + + + + + + + + + + +
- -