<?php
session_start();
if (empty($_SESSION['csrf_token'])) {
    $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
include 'conexion.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $titulo = $_POST['titulo'];
    $stmt = $conexion->prepare("INSERT INTO proyectos (titulo) VALUES (?)");
    $stmt->bind_param("s", $titulo);
    $stmt->execute();
    header("Location: index.php"); // Cambia a 'proyectos.php' si prefieres
    exit;
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Crear Proyecto</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">
<div class="container py-5">
    <div class="row justify-content-center">
        <div class="col-md-6 col-lg-5">
            <div class="card shadow-sm">
                <div class="card-body">
                    <h4 class="card-title mb-4 text-center">Nuevo Proyecto</h4>
                    <form method="post">
                        <div class="mb-3">
                            <label for="titulo" class="form-label">Título del proyecto</label>
                            <input type="text" class="form-control" id="titulo" name="titulo" required>
                        </div>
                        <button type="submit" class="btn btn-primary w-100">Crear Proyecto</button>
                        <a href="index.php" class="btn btn-outline-secondary w-100 mt-2">Cancelar</a>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
