<?php

session_start();

if (!isset($_SESSION['user_id'])) {

    echo '<p class="text-danger">Unauthorized access</p>';

    exit;

}



require_once '../config.php';

$conn = getDBConnection();



$action = $_GET['action'] ?? '';

$id = intval($_GET['id'] ?? 0);



if ($action === 'view' && $id > 0) {

    $result = $conn->query("SELECT * FROM sms_logs WHERE id = $id");

    $sms = $result ? $result->fetch_assoc() : null;

    

    if ($sms) {

        ?>

        <div class="container-fluid">

            <div class="row mb-3">

                <div class="col-md-4"><strong>Date:</strong></div>

                <div class="col-md-8"><?php echo date('d M Y H:i:s', strtotime($sms['created_at'])); ?></div>

            </div>

            <div class="row mb-3">

                <div class="col-md-4"><strong>Phone Number:</strong></div>

                <div class="col-md-8"><?php echo htmlspecialchars($sms['phone']); ?></div>

            </div>

            <div class="row mb-3">

                <div class="col-md-4"><strong>Status:</strong></div>

                <div class="col-md-8">

                    <span class="badge bg-<?php echo $sms['status'] === 'Success' ? 'success' : 'danger'; ?>">

                        <?php echo htmlspecialchars($sms['status']); ?>

                    </span>

                </div>

            </div>

            <div class="row mb-3">

                <div class="col-md-4"><strong>Full Message:</strong></div>

                <div class="col-md-8">

                    <div class="p-3 bg-light rounded">

                        <?php echo nl2br(htmlspecialchars($sms['message'])); ?>

                    </div>

                </div>

            </div>

        </div>

        <?php

    } else {

        echo '<p class="text-danger">SMS record not found</p>';

    }

} else {

    echo '<p class="text-danger">Invalid request</p>';

}



$conn->close();

?>