<?php include '../config/koneksi.php'; ?>
<!DOCTYPE html>
<html>
<head>
    <title>Registrasi - Ang Mansion</title>
    <link rel="stylesheet" type="text/css" href="../assets/style_user.css">
</head>
<body>
<div class="header">
    <div class="logo">
        <img src="../assets/images/LogoAngMansion-Putih.png" alt="Logo" /> AngMansion
    </div>
    <div class="navbar">
        <a href="index.php">Beranda</a>
        <a href="kamar.php">Kamar</a>
        <a href="register.php" class="active">Daftar</a>
        <a href="login.php">Login</a>
    </div>
</div>
<div class="form-auth-container">
    <h2 class="text-center mb-4" style="color:#1e2a78;font-weight:700;">Registrasi User</h2>
    <?php
    if(isset($_POST['register'])){
        $nama = mysqli_real_escape_string($conn, $_POST['nama']);
        $email = mysqli_real_escape_string($conn, $_POST['email']);
        $password = password_hash($_POST['password'], PASSWORD_DEFAULT);
        $alamat = mysqli_real_escape_string($conn, $_POST['alamat']);
        $telepon = mysqli_real_escape_string($conn, $_POST['telepon']);
        $cek = mysqli_query($conn, "SELECT * FROM user WHERE email='$email'");
        if(mysqli_num_rows($cek) == 0){
            $q = mysqli_query($conn, "INSERT INTO user (nama,email,password,alamat,telepon) VALUES ('$nama','$email','$password','$alamat','$telepon')");
            if($q){
                header('Location: login.php?register=success');
                exit;
            } else {
                echo '<div class="alert alert-danger text-center">Registrasi gagal!</div>';
            }
        } else {
            echo '<div class="alert alert-danger text-center">Email sudah terdaftar!</div>';
        }
    }
    ?>
    <form method="post">
        <div class="form-auth-row">
            <label for="nama" class="form-label">Nama Lengkap</label>
            <input type="text" class="form-control" id="nama" name="nama" placeholder="Nama Lengkap" required>
        </div>
        <div class="form-auth-row">
            <label for="email" class="form-label">Email</label>
            <input type="email" class="form-control" id="email" name="email" placeholder="Email" required>
        </div>
        <div class="form-auth-row">
            <label for="password" class="form-label">Password</label>
            <input type="password" class="form-control" id="password" name="password" placeholder="Password" required>
        </div>
        <div class="form-auth-row">
            <label for="alamat" class="form-label">Alamat</label>
            <input type="text" class="form-control" id="alamat" name="alamat" placeholder="Alamat" required>
        </div>
        <div class="form-auth-row">
            <label for="telepon" class="form-label">Telepon</label>
            <input type="text" class="form-control" id="telepon" name="telepon" placeholder="Telepon" required>
        </div>
        <button type="submit" class="btn btn-primary w-100" name="register">Daftar</button>
    </form>
</div>
</body>
</html> 