<?php
include 'koneksi.php';
session_start();
if (!isset($_SESSION['login_admin'])) {
    header('Location: dashboard.php');
    exit;
}

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $judul = mysqli_real_escape_string($host, $_POST['judul']);
    $deskripsi = mysqli_real_escape_string($host, $_POST['deskripsi']);
    $tanggal = date('Y-m-d H:i:s');
    $kategori = 'post';
    $jenis = 'video';
    $iframe = mysqli_real_escape_string($host, $_POST['iframe']);

    if (!empty($iframe)) {
        $query = "INSERT INTO tb_post (iframe, judul_post, deskripsi, tanggal, kategori, jenis, gambar) VALUES ('$iframe', '$judul', '$deskripsi', '$tanggal', '$kategori', '$jenis', '')";
        if (mysqli_query($host, $query)) {
            echo "<script>alert('Video galeri berhasil ditambahkan!'); window.location.href='manage_galeri.php';</script>";
        } else {
            echo "<script>alert('Error: " . mysqli_error($host) . "');</script>";
        }
    } else {
        echo "<script>alert('Iframe harus diisi!');</script>";
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head><link rel="icon" href="upload/bn2.png" type="image/png">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Tambah Galeri | SMK Budiniah 2</title>
    <link rel="stylesheet" href="style_admin.css">
    <style>
        body {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            font-family: 'Arial', sans-serif;
            margin: 0;
            padding: 0;
            min-height: 100vh;
        }
        .container {
            max-width: 800px;
            margin: 50px auto;
            padding: 30px;
            background: #fff;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.2);
        }
        h1 {
            text-align: center;
            color: #0037fd;
            margin-bottom: 30px;
            font-size: 28px;
            font-weight: bold;
        }
        .form-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            color: #333;
            font-weight: bold;
        }
        input[type="text"], textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 14px;
        }
        textarea {
            height: 100px;
            resize: vertical;
        }
        .btn {
            background: linear-gradient(135deg, #0037fd, #5b8cffff);
            color: #fff;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 16px;
            font-weight: bold;
            transition: all 0.3s ease;
        }
        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0,55,253,0.4);
        }
        .btn-secondary {
            background: #6c757d;
            margin-left: 10px;
        }
        .btn-secondary:hover {
            background: #5a6268;
        }
        .form-actions {
            text-align: center;
            margin-top: 30px;
        }
        @media (max-width: 768px) {
            .container {
                max-width: 600px;
                padding: 20px;
                margin: 20px 20px 0 15%;
            }
            h1 {
                font-size: 24px;
                margin-bottom: 20px;
            }
            .form-group {
                margin-bottom: 15px;
            }
            label {
                font-size: 14px;
            }
            input[type="text"], textarea {
                padding: 8px;
                font-size: 13px;
            }
            textarea {
                height: 80px;
            }
            .btn {
                padding: 10px 15px;
                font-size: 14px;
            }
            .form-actions {
                margin-top: 20px;
            }
        }
        @media (max-width: 480px) {
            .container {
                max-width: 600px;
                padding: 15px;
                margin: 20px 20px 0 15%;
            }
            h1 {
                font-size: 20px;
                margin-bottom: 15px;
            }
            .form-group {
                margin-bottom: 10px;
            }
            label {
                font-size: 14px;
            }
            input[type="text"], textarea {
                padding: 6px;
                font-size: 12px;
            }
            textarea {
                height: 60px;
            }
            .btn {
                padding: 8px 12px;
                font-size: 12px;
                width: 100%;
                margin-bottom: 10px;
            }
            .form-actions {
                margin-top: 15px;
            }
        }
    </style>
</head>
<body>
    <?php include 'navbar_admin.php'; ?>
    <div class="container">
        <h1>Tambah Video Galeri</h1>
        <form method="POST">
            <div class="form-group">
                <label for="judul">Judul Video:</label>
                <input type="text" id="judul" name="judul" placeholder="optional">
            </div>
            <div class="form-group">
                <label for="deskripsi">Deskripsi:</label>
                <textarea id="deskripsi" name="deskripsi" placeholder="optional"></textarea>
            </div>
            <div class="form-group">
                <label for="iframe">Iframe Video (YouTube):</label>
                <textarea id="iframe" name="iframe" placeholder="Masukkan kode iframe video YouTube di sini" required></textarea>
            </div>
            <div class="form-actions">
                <button type="submit" class="btn">Tambah Galeri</button>
                <a href="manage_galeri.php" class="btn btn-secondary">Batal</a>
            </div>
        </form>
    </div>
</body>
</html>

