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

$query = "SELECT * FROM tb_alamat LIMIT 1";
$result = mysqli_query($host, $query);
$row = mysqli_fetch_assoc($result);

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $alamat = mysqli_real_escape_string($host, $_POST['alamat']);
    $nomor_sekolah = mysqli_real_escape_string($host, $_POST['nomor_sekolah']);
    $nomor_whatsapp = mysqli_real_escape_string($host, $_POST['nomor_whatsapp']);
    $email = mysqli_real_escape_string($host, $_POST['email']);
    $link_instagram = mysqli_real_escape_string($host, $_POST['link_instagram']);
    $link_youtube = mysqli_real_escape_string($host, $_POST['link_youtube']);
    $iframe = mysqli_real_escape_string($host, $_POST['iframe']);

    $update_query = "UPDATE tb_alamat SET
        alamat = '$alamat',
        nomor_sekolahh = '$nomor_sekolah',
        nomor_whatsapp = '$nomor_whatsapp',
        email = '$email',
        link_instagram = '$link_instagram',
        link_youtube = '$link_youtube',
        iframe = '$iframe'
        WHERE id_alamat = " . $row['id_alamat'];

    if (mysqli_query($host, $update_query)) {
        echo "<script>alert('Informasi berhasil diupdate!'); window.location.href='manage_informasi.php';</script>";
    } else {
        echo "<script>alert('Error: " . mysqli_error($host) . "');</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>Edit Informasi Alamat | 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"], input[type="url"], 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: 12px 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 40px 15%;
            }
            h1 {
                font-size: 24px;
                margin-bottom: 20px;
            }
            .form-group {
                margin-bottom: 15px;
            }
            label {
                font-size: 14px;
            }
            input[type="text"], input[type="url"], 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 40px 15%;
            }
            h1 {
                font-size: 20px;
                margin-bottom: 15px;
            }
            .form-group {
                margin-bottom: 12px;
            }
            label {
                font-size: 12px;
            }
            input[type="text"], input[type="url"], textarea {
                padding: 6px;
                font-size: 12px;
            }
            textarea {
                height: 60px;
            }
            .btn {
                padding: 8px 12px;
                font-size: 12px;
                width: 100%;
                margin-bottom: 10px;
            }
            .btn-secondary {
                margin-left: 0;
            }
            .form-actions {
                margin-top: 15px;
                text-align: left;
            }
        }
    </style>
</head>
<body>
    <?php include 'navbar_admin.php'; ?>
    <div class="container">
        <h1>Edit Informasi Alamat</h1>
        <form method="POST">
            <div class="form-group">
                <label for="alamat">Alamat:</label>
                <textarea id="alamat" name="alamat" required><?php echo htmlspecialchars($row['alamat']); ?></textarea>
            </div>
            
            <div class="form-group">
                <label for="nomor_sekolah">Nomor Sekolah:</label>
                <input type="text" id="nomor_sekolah" name="nomor_sekolah" value="<?php echo htmlspecialchars($row['nomor_sekolahh']); ?>" required>
            </div>
            
            <div class="form-group">
                <label for="nomor_whatsapp">Nomor WhatsApp:</label>
                <input type="text" id="nomor_whatsapp" name="nomor_whatsapp" value="<?php echo htmlspecialchars($row['nomor_whatsapp']); ?>" required>
            </div>
            
            <div class="form-group">
                <label for="email">Email:</label>
                <input type="email" id="email" name="email" value="<?php echo htmlspecialchars($row['email']); ?>" required>
            </div>
            
            <div class="form-group">
                <label for="link_instagram">Link Instagram:</label>
                <input type="url" id="link_instagram" name="link_instagram" value="<?php echo htmlspecialchars($row['link_instagram']); ?>" required>
            </div>
            
            <div class="form-group">
                <label for="link_youtube">Link YouTube:</label>
                <input type="url" id="link_youtube" name="link_youtube" value="<?php echo htmlspecialchars($row['link_youtube']); ?>" required>
            </div>
            
            <div class="form-group">
                <label for="iframe">Iframe Peta:</label>
                <textarea id="iframe" name="iframe" required><?php echo htmlspecialchars($row['iframe']); ?></textarea>
            </div>
            
            <div class="form-actions">
                <button type="submit" class="btn">Update Informasi</button>
                <a href="manage_informasi.php" class="btn btn-secondary">Batal</a>
            </div>
        </form>
    </div>
</body>
</html>

