<?php include '../config/koneksi.php'; session_start(); if(!isset($_SESSION['admin_id'])){ header('Location: login.php'); exit; } ?>
<!DOCTYPE html>
<html>
<head>
    <title>Kontak - 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">
        <h2 style="text-align:center;">Kontak</h2>
        <table>
            <tr>
                <th>Nama User</th>
                <th>Pesan</th>
                <th>Balasan Admin</th>
                <th>Action</th>
            </tr>
            <?php
            $q = mysqli_query($conn, "SELECT * FROM kontak ORDER BY id DESC");
            while($k = mysqli_fetch_assoc($q)){
                echo '<tr>';
                echo '<td>'.htmlspecialchars($k['nama_user']).'</td>';
                echo '<td><i>'.htmlspecialchars($k['pesan']).'</i></td>';
                echo '<td>'.($k['balasan'] ? '<b>'.$k['balasan'].'</b>' : '-').'</td>';
                echo '<td>';
                echo '<form method="post" style="margin:0;">';
                echo '<input type="hidden" name="id" value="'.$k['id'].'">';
                echo '<input type="text" name="balasan" placeholder="Balas..." style="width:120px;">';
                echo '<button type="submit" name="balas" class="btn">Balas</button>';
                echo '</form>';
                echo '</td>';
                echo '</tr>';
            }
            ?>
        </table>
        <?php
        if(isset($_POST['balas'])){
            $id = (int)$_POST['id'];
            $balasan = mysqli_real_escape_string($conn, $_POST['balasan']);
            mysqli_query($conn, "UPDATE kontak SET balasan='$balasan' WHERE id=$id");
            echo '<div class="alert">Pesan dibalas!</div><meta http-equiv="refresh" content="1;url=kontak.php">';
        }
        ?>
    </div>
</div>
<?php include 'footer.php'; ?>
</body>
</html> 