<?php 
session_start(); // Start session
require_once("../dbconnect.php");

// Check if user is logged in
if(!isset($_SESSION['USER_LOGIN']) || $_SESSION['USER_LOGIN'] != 'yes'){
    header("location: login.php");
    exit;
}

// Fetch the video data
if(isset($_GET['video_id'])){
    $video_id = mysqli_real_escape_string($con, $_GET['video_id']);
    $result = mysqli_query($con, "SELECT * FROM course_video WHERE id = '$video_id'");

    if(mysqli_num_rows($result) > 0){
        $video = mysqli_fetch_assoc($result);
    } else {
        echo "Video not found!";
        exit;
    }
} else {
    echo "No video selected.";
    exit;
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>View Video</title>
</head>
<body>
    <h2><?php echo $video['video_title']; ?></h2>
    <video controls>
        <source src="<?php echo $video['video_link']; ?>" type="video/mp4">
        Your browser does not support the video tag.
    </video>
</body>
</html>
