<?php
session_start(); 
$u_uname = '';
if (isset($_COOKIE['auth_token'])) {
    $u_uname = $_COOKIE['auth_token'];
} else {
    header("location:login.php");
    exit; 
}
?>

<?php include 'include/header.php'; ?>
<?php include 'include/aside.php'; ?>
<?php include 'include/connection.php'; ?>

<!--start page wrapper -->
<div class="page-wrapper">
    <div class="page-content">
        <h6 class="mb-0 text-uppercase">Complete Support History</h6>
        <hr/>

        <div class="card">
            <div class="card-body">
                <div class="table-responsive">
                    <table id="example2" class="table table-striped table-bordered">
                        <thead>
                            <tr>
                                <th>SR. No</th>
                                <th>User ID</th>
                                <th>Email</th>
                                <th>Subject</th>
                                <th>Complaint Id</th>
                                <th>Comment</th>
                                <th>Status</th>
                                <th>Date</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $sql = "SELECT * FROM  support where status='1' order by id desc";
                            $result = $link->query($sql);
                            $sr = 1; // Initialize serial number
                            
                            if ($result->num_rows > 0) {
                                // Output data of each row
                                while($row = $result->fetch_assoc()) {
                                    ?>
                                    
                                    <tr>
                                    <td><?php echo  $sr ?></td>
                                    <td><?php echo$row['userid'] ?></td>
                                    <td><?php echo $row['email'] ?></td>
                                    <td><?php echo $row['subject'] ?></td>
                                    <td><?php echo $row['complaint_id'] ?></td>
                                    <td><?php echo $row['comment'] ?></td>
                                    <td>
    <?php  

    if ($row['status'] == '1') {
        ?>
        <span class="badge bg-success text-white rounded-pill">Success</span>
        <?php
    } 
    
    ?>
</td>
                                    <td><?php echo  $row['date'] ?></td>
                                    </tr>
                                    <?php
                                    $sr++; 
                                }
                            } else {
                                echo "<tr><td colspan='8'>No data available</td></tr>";
                            }
                            ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<?php include 'include/footer.php'; ?>