<?php
include("./include/config.php");

if (!isset($_SESSION['a_user'])) {
    header("Location: index.php");
} else {
    include("./include/sidebar.php");
    ?>

    <div class="col-xs-12">
        <div class="box-content">
            <h4 class="box-title">User Details</h4>
            <div class="table-responsive">
                <table class="table">
                    <tbody>
                        <?php
                        $id = $_GET['id'];

                        // Fetch user details from the database for the given ID
                        $sql = "SELECT * FROM data WHERE application_no = $id";
                        $result = mysqli_query($conn, $sql);

                        $row = mysqli_fetch_assoc($result);
                        // Loop through user details and display them in a linear table format
                        foreach($row as $key => $value) {
                            echo '<tr>';
                            echo '<td>' . ucfirst(str_replace("_", " ", $key)) . '</td>'; // Convert column names to title case
                            echo '<td>' . $value . '</td>';
                            echo '</tr>';
                        }
                        $mobileid = $row['phone'];
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <div class="col-xs-12">
        <div class="box-content">
            <h4 class="box-title">View SMS</h4>
            <!--<a href="delete_all_sms.php" class="margin-bottom-10 btn waves-effect waves-light btn-primary btn-xs">Delete All</a>-->
            <!--<a href="#" id="delete-selected" class="margin-bottom-10 btn waves-effect waves-light btn-primary btn-xs">Delete Selected</a>-->

            <div class="row">
                <?php
                $i = 0;
                $sql = "SELECT * FROM `sms` WHERE mobile_id = '$id'  ORDER BY id DESC";
                $sql_res = mysqli_query($conn, $sql);

                while ($row = mysqli_fetch_assoc($sql_res)) {
                ?>
                <div class="col-md-4">
                    <div class="card" style="border: 1px solid black; border-radius: 10px; padding: 10px; margin: 10px">
                        <div class="card-body">
                            <h5 class="card-title">Sender ID: <?php echo $row['sender_id'] ?></h5>
                            <p class="card-text">Message: <?php echo $row['msg'] ?></p>
                            <p class="card-text">Date Time: <?php echo $row['date'] ?></p>
                        </div>
                    </div>
                </div>
                <?php
                }
                ?>
            </div>
        </div>
    </div>

    <?php
}

include("./include/footer.php");
?>
