<?php
// Retired: program pages now play media directly from S3, and the Laravel site
// serves project pages. Permanently redirect old embed links to the project page.
if (isset($_GET['vidid']) && ctype_digit((string) $_GET['vidid'])) {
    header('Location: /student-project/' . $_GET['vidid'], true, 301);
    exit;
}

$target = '/student-work';

if (isset($_GET['vidlink']) && $_GET['vidlink'] !== '') {
    $path = $_SERVER['DOCUMENT_ROOT'];
    require_once($path . '/Library/key/db_conn.php');

    $stmt = mysqli_prepare($connGodaddy, 'SELECT VidID FROM videos WHERE VidLink = ? LIMIT 1');
    if ($stmt) {
        $vidlink = (string) $_GET['vidlink'];
        mysqli_stmt_bind_param($stmt, 's', $vidlink);
        mysqli_stmt_execute($stmt);
        mysqli_stmt_bind_result($stmt, $vidId);
        if (mysqli_stmt_fetch($stmt) && $vidId) {
            $target = '/student-project/' . (int) $vidId;
        }
        mysqli_stmt_close($stmt);
    }
}

header('Location: ' . $target, true, 301);
exit;
