<?php 
session_start();
if (!isset($_SESSION['nombre'])) {
    header("Location: login.php");
    exit();
}
$id = $_SESSION['id'];
$nombre = $_SESSION["nombre"];
$email = $_SESSION["email"];
$numero = $_SESSION["numero"];

include 'include/conexion.php';


if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $name = $_POST["nombre"];
    $correo = $_POST["email"];
    $numero = $_POST["numero"];
    $asunto= $_POST["asunto"];
    
    $consulta = $conexion->prepare("INSERT INTO contactos (nombre, email, numero, asunto)  
    VALUES('$name', '$correo', '$numero', '$asunto')");
    $consulta->execute();
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/contactanos.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit@3.18.3/dist/css/uikit.min.css" />
    <script src="https://cdn.jsdelivr.net/npm/uikit@3.18.3/dist/js/uikit.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/uikit@3.18.3/dist/js/uikit-icons.min.js"></script>
    <title>Contactos</title>
</head>
<body>
<?php 
        include("include/img.php");
        include("include/navbar.php");
        ?>
        <div class="uk-background-cover" style="height: 100vh;" data-src="<?php echo $path . $img['backs'][0]['backs']; ?>" uk-img>
        <?php
        include("include/contactos.php");
        include("include/footer.php");
        include("include/offcanvas.php");
    ?>
    </div>
<script>
    function validaciond() {
        let nombre = document.getElementById('nombre').value;
        let email = document.getElementById('email').value;
        let numero = document.getElementById('numero').value;
        let asunto = document.getElementById('asunto').value;

        if (nombre.length === 0) {
            alert('Nombre esta vacio');
            return false;
        }
        if (email.length === 0) {
            alert('email esta vacio');
            return false;
        }
        if (numero.length !== 9) {
            alert('el campo numero debe tener 9 digitos');
            return false;
        }
        if (asunto.length <= 2) {
            alert('Escriba mas caracteres');
            return false;
        }

        alert('Se envio su asunto');
        return true;
    }
</script>
</body>
</html>