
<?php
include "../include/config.php"; // Database connection
session_start();
$school= $_SESSION['school'];
// Fetch data from the sms_logs table
$query = "SELECT * FROM sms_logs where message LIKE '%$school%' ORDER BY sent_time DESC";
$result = mysqli_query($conn, $query);

if (!$result) {
    die("Failed to retrieve SMS logs: " . mysqli_error($conn));
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SMS Scheduler</title>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <style>
        table {
            border-collapse: collapse;
            width: 100%;
            margin-top: 20px;
        }
        table, th, td {
            border: 1px solid #ddd;
        }
        th, td {
            padding: 10px;
            text-align: left;
        }
        th {
            background-color: #f4f4f4;
        }
        tr:hover {
            background-color: #f1f1f1;
        }
    </style>
</head>
<body>
<?php include "../include/nav.php";?>
  <div class="content" style="background:white;"> 
      <br><br><br><br>
    <h1 style="margin-left:15px ">SMS Logs</h1>
    <?php if (mysqli_num_rows($result) > 0): ?>
        <div class="scroll" style="background:white; border:none;padding:15px; margin-top:5px; margin-bottom:5px; border-radius:4px;">
    <table id="myTable" class="table table-striped table-bordered table-responsive table-hover" >  
    
            <thead>
                <tr>
                    
                    <th>Session</th>
                    
                    <th>Term</th>
                    
                    <th>Sent Time</th>
                    <th>Student Name</th>
                    <th>Phone</th>
                    <th>Message</th>
                </tr>
            </thead>
            <tbody>
                <?php while ($row = mysqli_fetch_assoc($result)): ?>
                    <tr>
                        
                        <td><?php echo $row['session']; ?> <?php echo $row['class']; ?></td>
                        
                        <td><?php echo $row['term']; ?>-<?php echo $row['year']; ?></td>
                        
                        <td><?php echo $row['sent_time']; ?></td>
                        <td><?php echo htmlspecialchars($row['student_name']); ?></td>
                        <td><?php echo htmlspecialchars($row['phone']); ?></td>
                        <td><?php echo htmlspecialchars($row['message']); ?></td>
                    </tr>
                <?php endwhile; ?>
            </tbody>
        </table>
    <?php else: ?>
        <p>No SMS logs found.</p>
    <?php endif; ?>

    <?php mysqli_close($conn); ?>
</body>
</html>