diff --git a/citas.php b/citas.php new file mode 100644 index 0000000..6653581 --- /dev/null +++ b/citas.php @@ -0,0 +1,168 @@ +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 ''; + } else { + echo ''; + } + } + + // 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()); +} +?> + +
+

Citas

+ + +
+
+ + Añadir Nueva Cita +
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+ +
+
+
+
+
+ +
+
+ + Lista de Citas +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDFecha y HoraDepartamentoLugarUsuariosEstado
No hay citas registradas.
+
+
+
+ + diff --git a/consultas.php b/consultas.php new file mode 100644 index 0000000..6a12016 --- /dev/null +++ b/consultas.php @@ -0,0 +1,149 @@ +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 ''; + } else { + echo ''; + } + } + + // 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()); +} +?> + +
+

Consultas

+ + +
+
+ + Añadir Nueva Consulta +
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+
+
+ +
+
+ + Lista de Consultas +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
IDTaxistaDepartamentoResultadoFecha
No hay consultas registradas.
+
+
+
+ + diff --git a/departamentos.php b/departamentos.php new file mode 100644 index 0000000..6e0b2d5 --- /dev/null +++ b/departamentos.php @@ -0,0 +1,114 @@ +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 ''; + } else { + echo ''; + } + } + + // 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()); +} +?> + +
+

Departamentos

+ + +
+
+ + Añadir Nuevo Departamento +
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+ +
+
+
+
+
+ +
+
+ + Lista de Departamentos +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
IDNombreColorFecha de Creación
No hay departamentos registrados.
+
+
+
+ + diff --git a/documents.php b/documents.php new file mode 100644 index 0000000..07fc04b --- /dev/null +++ b/documents.php @@ -0,0 +1,147 @@ +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 = '
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 en la subida del fichero: ' . $file_error . '
'; + } +} + +// --- 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 .= '
Error al obtener los documentos: ' . $e->getMessage() . '
'; +} + +include 'header.php'; +?> + +
+

Gestor de Documentos

+ +
+ + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
TítuloDescripciónFicheroFecha de SubidaAcciones
No hay documentos todavía.
+ + Descargar + +
+
+
+
+ + + + + diff --git a/header.php b/header.php index a2e2354..9cddfa3 100644 --- a/header.php +++ b/header.php @@ -52,6 +52,21 @@ + + + + + diff --git a/localizacion.php b/localizacion.php new file mode 100644 index 0000000..435909c --- /dev/null +++ b/localizacion.php @@ -0,0 +1,197 @@ +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 ''; + } else { + echo ''; + } + } + + // 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()); +} +?> + +
+

Localización de Taxis

+ + +
+
+
+
+ + Añadir o Actualizar Localización +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+ + Añadir Nuevo Taxi (para demo) +
+
+
+
+ + +
+
+ + +
+
+
+ +
+
+
+
+
+
+
+ +
+
+ + Últimas Localizaciones Registradas +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
IDTaxiLatitudLongitudÚltima Actualización
No hay localizaciones registradas.
+
+
+
+ + diff --git a/uploads/6924d9955d1da-06d6de8c-48da-44b5-96b3-48d6e76a99ab.pdf b/uploads/6924d9955d1da-06d6de8c-48da-44b5-96b3-48d6e76a99ab.pdf new file mode 100644 index 0000000..6b6251f Binary files /dev/null and b/uploads/6924d9955d1da-06d6de8c-48da-44b5-96b3-48d6e76a99ab.pdf differ