<?php include '../config/koneksi.php'; session_start(); if(!isset($_SESSION['admin_id'])){ header('Location: login.php'); exit; } ?>
<?php
if(isset($_POST['simpan'])){
    $tipe = mysqli_real_escape_string($conn, $_POST['tipe']);
    $jumlah = (int)$_POST['jumlah'];
    $harga = (int)$_POST['harga'];
    $deskripsi = mysqli_real_escape_string($conn, $_POST['deskripsi']);
    $status = 'tersedia';
    $gambar = '';
    if(isset($_FILES['gambar']) && $_FILES['gambar']['tmp_name'] != ''){
        $ext = pathinfo($_FILES['gambar']['name'], PATHINFO_EXTENSION);
        $gambar = 'kamar_'.time().'.'.$ext;
        move_uploaded_file($_FILES['gambar']['tmp_name'], '../assets/images/'.$gambar);
    }
    for($i=0;$i<$jumlah;$i++){
        mysqli_query($conn, "INSERT INTO kamar (tipe, harga, deskripsi, status, gambar) VALUES ('$tipe', $harga, '$deskripsi', '$status', '$gambar')");
    }
    echo '<div class="alert">Perubahan kamar berhasil disimpan!</div>';
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>Input Kamar - Admin</title>
    <link rel="stylesheet" type="text/css" href="style_admin.css">
</head>
<body>
<?php include 'header.php'; ?>
<?php include 'sidebar.php'; ?>
<div class="content">
    <div class="box" style="max-width:500px;margin:auto;">
        <h2 style="text-align:center;">Input Kamar</h2>
        <form method="post" enctype="multipart/form-data">
            <label>Tipe</label><br>
            <select name="tipe" required>
                <option value="">--Pilih--</option>
                <option value="Superior">Superior</option>
                <option value="Deluxe">Deluxe</option>
            </select><br>
            <label>Jumlah</label><br>
            <input type="number" name="jumlah" min="1" value="1" required><br>
            <label>Harga</label><br>
            <input type="number" name="harga" min="0" required><br>
            <label>Deskripsi</label><br>
            <textarea name="deskripsi" rows="3"></textarea><br>
            <label>Gambar</label><br>
            <input type="file" name="gambar" accept="image/*"><br><br>
            <button type="submit" name="simpan" class="btn">Simpan</button>
        </form>
    </div>
</div>
<?php include 'footer.php'; ?>
</body>
</html> 