mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2024-12-25 19:42:22 +00:00
48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
|
|
/** @var Team $team */
|
|
$team = $_SESSION["team"];
|
|
|
|
if (!isset($_SESSION["user_id"]) || $_SESSION["role"] != Role::PARTICIPANT && $_SESSION["role"] != Role::ENCADRANT || $team == null || $team->getValidationStatus() != ValidationStatus::VALIDATED)
|
|
require_once "server_files/403.php";
|
|
|
|
$has_error = false;
|
|
$error_message = null;
|
|
|
|
if (isset($_POST["upload"])) {
|
|
$new_video = new NewVideo($_POST);
|
|
try {
|
|
$new_video->makeVerifications();
|
|
$new_video->uploadVideo();
|
|
} catch (AssertionError $e) {
|
|
$has_error = true;
|
|
$error_message = $e->getMessage();
|
|
}
|
|
}
|
|
|
|
class NewVideo
|
|
{
|
|
private $link;
|
|
|
|
public function __construct($data)
|
|
{
|
|
$this->link = $data["link"];
|
|
}
|
|
|
|
public function makeVerifications()
|
|
{
|
|
ensure(preg_match("#(https?)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?#", $this->link), "Ce n'est pas une URL valide.");
|
|
}
|
|
|
|
public function uploadVideo()
|
|
{
|
|
global $DB, $YEAR, $team;
|
|
|
|
$req = $DB->prepare("INSERT INTO `videos`(`team`, `problem`, `link`, `reason`, `year`) VALUES (?, ?, ?, ?, ?)");
|
|
$req->execute([$team->getId(), $team->getProblem(), $this->link, "SOLUTION", $YEAR]);
|
|
}
|
|
}
|
|
|
|
$videos_req = $DB->query("SELECT * FROM `videos` WHERE `year` = $YEAR;");
|
|
|
|
require_once "server_files/views/envoyer_video.php"; |