<?php
require "config.php";
session_start();

$teacher_id = $_SESSION['teacher_id'] ?? null;
if(!$teacher_id){ exit("Unauthorized"); }

$id = $_POST['id'] ?? null;
// $type = $_POST['type'] ?? null;
$time = $_POST['set_time_minutes'] ?? null;

if(!$id || !$time){ exit("Missing fields"); }

$stmt = $dbh->prepare("UPDATE exams SET set_time_minutes=:tm WHERE id=:id AND teacher_id=:tid");
$ok = $stmt->execute([':tm'=>$time, ':id'=>$id, ':tid'=>$teacher_id]);

echo $ok ? "Exam updated successfully." : "Failed to update exam.";
