<?php
declare(strict_types=1);
require __DIR__ . '/_common.php';
ec_require_coordinator();
$PAGE_TITLE = 'Planner';
$ACTIVE = 'planner';
list($scopeSql, $scopeParams) = coord_branch_scope('b');

$items = qall($mysqli, "
  SELECT DISTINCT a.id, a.title, a.available_from, a.due_at, a.release_at
  FROM lms_assessments a
  JOIN lms_assessment_batches ab ON ab.assessment_id=a.id
  JOIN batches b ON b.id=ab.batch_id
  WHERE $scopeSql
  ORDER BY COALESCE(a.available_from,NOW()) ASC
", $scopeParams, str_repeat('i', count($scopeParams)));
?>
<!doctype html><html lang="en"><head>
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>Planner</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet">
</head><body>
<div class="ec-shell">
  <?php include __DIR__ . '/partials/sidebar.php'; ?>
  <div class="ec-content">
    <?php include __DIR__ . '/partials/topbar.php'; ?>
    <div class="wrap container-fluid">
      <div class="card section-card">
        <div class="card-header bg-white"><strong>Schedule</strong></div>
        <div class="card-body p-0">
          <div class="table-responsive">
            <table class="table table-hover mb-0">
              <thead class="table-light"><tr><th>Assessment</th><th>Open</th><th>Due</th><th>Release</th></tr></thead>
              <tbody>
                <?php if (!$items): ?>
                  <tr><td colspan="4" class="text-center text-muted py-4">No items.</td></tr>
                <?php else: foreach($items as $r): ?>
                  <tr>
                    <td class="fw-semibold"><?php echo h($r['title']); ?></td>
                    <td><?php echo h($r['available_from']); ?></td>
                    <td><?php echo h($r['due_at']); ?></td>
                    <td><?php echo h($r['release_at']); ?></td>
                  </tr>
                <?php endforeach; endif; ?>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
</body></html>
