<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
include "../include/config.php";

$userlogin = $_SESSION['studentid'];
$intake = $_SESSION['intake'];
$pro = $_SESSION['program'];

if (isset($_SESSION['studentid'])) { ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Videos</title>
<link rel="stylesheet" href="../../boostrap/1.css">
<link rel="stylesheet" href="../../boostrap/2.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="res/bootstrap@5.2.0.min.css">
<link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro&display=swap" rel="stylesheet">

<style>
body { font-family: 'Source Sans Pro', sans-serif; padding: 0; margin: 0; background: #f5f5f5; }
.content { margin-left: 210px; padding: 20px; }
.video-item { display: flex; align-items: center; background: #fff; border-radius: 10px; padding: 10px; margin-bottom: 12px; box-shadow: 0 2px 6px rgba(0,0,0,0.08); }
.video-item img { width: 120px; height: 80px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.video-item .info { flex: 1; margin-left: 12px; }
.video-item .info h4 { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.3; color: #202342; }
.video-item .info small { color: #888; font-size: 12px; }
.video-item button { background: #d03f4d; color: white; border: none; padding: 6px 12px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.content{
    padding:15px
}
</style>
</head>
<body>

<?php include "../include/nav.php"; ?>

<div class="content" style="padding:20px;">
    <div style="margin-bottom: 20px; text-align: ;">
        <h2 style="font-weight:700; color:#d03f4d;">Student Learning Videos</h2>
        <p style="color: #555; font-size: 14px;">Browse and watch the latest videos for your program and intake.</p>
    </div>

    <h3 style="font-weight:700; color:#202342; margin:10px 0;">Learning Videos</h3>

    <?php
    $query = mysqli_query($conn, "SELECT * FROM videos WHERE program='$pro' AND intake='$intake' ORDER BY date DESC LIMIT 6");
    while ($row = mysqli_fetch_array($query)) {
        $thumbnail = !empty($row['thumbnail']) ? "../video_image/" . $row['thumbnail'] : "https://via.placeholder.com/120x80?text=No+Image";
    ?>
    <div class="video-item">
        <img src="<?php echo $thumbnail; ?>" alt="<?php echo $row['title']; ?>">

        <div class="info">
            <h4><?php echo $row['title']; ?></h4>
            <small><?php echo date("M d, Y", strtotime($row['date'])); ?></small>
        </div>

        <a href="viewvideo.php?id=<?php echo $row['id']; ?>">
            <button>Watch</button>
        </a>
    </div>
    <?php } ?>
</div>


</body>
</html>
<?php
} else {
    header("location:../index.php");
}
?>
