<?php
if (session_status() === PHP_SESSION_NONE) { session_start(); }
require_once __DIR__ . '/../../includes/auth.php';
require_role(['super_admin','branch_admin']);

require_once __DIR__ . '/../../includes/helpers.php';
require_once __DIR__ . '/../../includes/db.php';
require_once __DIR__ . '/../../includes/scope.php';

$course_id = filter_input(INPUT_GET, 'course_id', FILTER_VALIDATE_INT) ?: 0;
if ($course_id <= 0) { http_response_code(400); exit('Missing course_id'); }

$labelCol = column_exists_local('courses','course_name') ? 'course_name'
          : (column_exists_local('courses','name') ? 'name'
          : (column_exists_local('courses','title') ? 'title' : 'id'));

$stmt = $mysqli->prepare("SELECT id, $labelCol AS label FROM courses WHERE id=?");
$stmt->bind_param('i', $course_id);
$stmt->execute();
$COURSE = $stmt->get_result()->fetch_assoc();
$stmt->close();

if (!$COURSE) { http_response_code(404); exit('Course not found'); }

$PAGE_TITLE  = 'Releases';
$ACTIVE_MENU = 'courses';

// open layout
$__layoutOpened=false;
foreach(['admin_layout_top.php','layout_top.php','admin_header.php','header_admin.php'] as $f){
  $p=__DIR__.'/../../includes/'.$f; if(is_file($p)){require_once $p; $__layoutOpened=true; break;}
}
if(!$__layoutOpened) echo '<div class="container-fluid p-3">';
?>
<div class="d-flex align-items-center justify-content-between mb-3">
  <h1 class="h5 m-0"><?= esc($PAGE_TITLE) ?> — <span class="text-muted"><?= esc($COURSE['label']) ?></span></h1>
  <a href="index.php" class="btn btn-outline-secondary btn-sm">← Back to Courses</a>
</div>

<!-- Your releases/scheduling UI goes here -->

<?php
$__layoutClosed=false;
foreach(['admin_layout_bottom.php','layout_bottom.php','admin_footer.php','footer_admin.php'] as $f){
  $p=__DIR__.'/../../includes/'.$f; if(is_file($p)){require_once $p; $__layoutClosed=true; break;}
}
if(!$__layoutClosed) echo '</div>';
