<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>index</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
  <link href="css/styles.css" rel="stylesheet">
</head>
<body  >
  <div class="container bg2 ">
  <header class="">
  <div class="row align-items-center">
    <div class="col-6 text-start">
    <a href="admin.php"> <img src="images/lpt-left-logo.png" class="img-fluid" alt="Left logo"></a>
    </div>
    <div class="col-6 text-end">
      <img src="images/topmenu-logo.png" class="img-fluid" alt="Topmenu logo">
    </div>
  </div>
</header>
  
<div class="content   mt-3">

<?php
session_start();

// Database connection
$host = 'localhost';
$dbUser = 'root';
$dbPass = '';
$dbName = 'lpt_db';
$conn = new mysqli($host, $dbUser, $dbPass, $dbName);
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

// Ensure user is logged in
if (!isset($_SESSION['user_id'])) {
  echo "<script>alert('Unauthorized access! Please login.'); window.location.href='login.php';</script>";
  exit;
}

$asmUserId = $_SESSION['user_id'];  

// Fetch only camp registrations added by this user
$sql = "
  SELECT cr.* 
  FROM camp_registration cr
  JOIN usermaster mr ON cr.created_by = mr.userid
  WHERE mr.manager_id = ?
  ORDER BY cr.camp_date DESC
";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $asmUserId);
$stmt->execute();
$result = $stmt->get_result();
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My Camp Tracker</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">
  <div class="container py-5">
<div class="row">
<div class="col-2">
  <div class="button2">Detailed Report</div>
</div>

    <h2 class="mb-4">Area Camp Registration</h2>
    <div class="table-responsive">
      <table class="table table-bordered table-striped">
        <thead class="table-dark">
          <tr>
            <th>ID</th>
            <th>Date</th>
            <th>OCE ID</th>
            <th>Doctor Name</th>
            <th>Clinic Address</th>
            <th>City</th>
            <th>State</th>
            <th>Patients Screened</th>
            <th>Created At</th>
          </tr>
        </thead>
        <tbody>
          <?php if ($result && $result->num_rows > 0): ?>
            <?php while ($row = $result->fetch_assoc()): ?>
              <tr>
                <td><?= htmlspecialchars($row['id']) ?></td>
                <td><?= htmlspecialchars($row['camp_date']) ?></td>
                <td><?= htmlspecialchars($row['oce_id']) ?></td>
                <td><?= htmlspecialchars($row['doctor_name']) ?></td>
                <td><?= htmlspecialchars($row['clinic_address']) ?></td>
                <td><?= htmlspecialchars($row['city']) ?></td>
                <td><?= htmlspecialchars($row['state']) ?></td>
                <td><?= htmlspecialchars($row['patients_screened']) ?></td>
                <td><?= htmlspecialchars($row['created_at']) ?></td>
              </tr>
            <?php endwhile; ?>
          <?php else: ?>
            <tr><td colspan="9" class="text-center">No camp registrations found for your account.</td></tr>
          <?php endif; ?>
        </tbody>
      </table>
    </div>
  </div>

</div>
 

<footer>

  <div class="row">
  
    <div class="col-6 col-md-6 padding-zero text-center" style="background:#ECE9F8"><img src="images/disclaimer.png" class="img-fluid"> </div>
    <div class="col-6 col-md-6 padding-zero contact-us text-center" style="background:#54308E"><img src="images/contact-us.png" class="img-fluid"> </div>
  
</div>
</footer>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>