2019-09-12 18:10:30 +00:00
|
|
|
<?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 {
|
2019-09-12 22:11:41 +00:00
|
|
|
$new_video->makeVerifications();
|
2019-09-12 18:10:30 +00:00
|
|
|
$new_video->uploadVideo();
|
|
|
|
} catch (AssertionError $e) {
|
|
|
|
$has_error = true;
|
|
|
|
$error_message = $e->getMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class NewVideo
|
|
|
|
{
|
2019-09-18 22:31:53 +00:00
|
|
|
public $link;
|
|
|
|
private $valid_link;
|
|
|
|
private $no_change;
|
2019-09-12 18:10:30 +00:00
|
|
|
|
|
|
|
public function __construct($data)
|
|
|
|
{
|
2019-09-18 22:31:53 +00:00
|
|
|
foreach ($data as $key => $value)
|
|
|
|
$this->$key = $value;
|
2019-09-12 18:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function makeVerifications()
|
|
|
|
{
|
2019-09-16 22:04:45 +00:00
|
|
|
ensure(preg_match("#(https?\:\/\/|)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?#", $this->link), "Ce n'est pas une URL valide.");
|
|
|
|
$this->link = preg_replace('/^(?!https?:\/\/)/', 'https://', $this->link);
|
2019-09-18 22:31:53 +00:00
|
|
|
ensure($this->valid_link != null, "Vous devez confirmer que le lien est valide.");
|
|
|
|
ensure($this->no_change != null, "Vous devez vous engager à ne pas changer le contenu du lien et de la vidéo.");
|
2019-09-12 22:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function uploadVideo()
|
|
|
|
{
|
|
|
|
global $DB, $YEAR, $team;
|
2019-09-12 18:10:30 +00:00
|
|
|
|
2019-09-12 22:11:41 +00:00
|
|
|
$req = $DB->prepare("INSERT INTO `videos`(`team`, `problem`, `link`, `reason`, `year`) VALUES (?, ?, ?, ?, ?)");
|
|
|
|
$req->execute([$team->getId(), $team->getProblem(), $this->link, "SOLUTION", $YEAR]);
|
2019-09-18 22:31:53 +00:00
|
|
|
|
|
|
|
Mailer::sendNewVideo($this, $team);
|
2019-09-12 18:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-16 22:04:45 +00:00
|
|
|
$video = Video::getVideo(Reason::SOLUTION, $team);
|
2019-09-18 22:31:53 +00:00
|
|
|
$video_validated = Video::getVideo(Reason::SOLUTION, $team, Video::ACCEPTED);
|
2019-09-12 22:11:41 +00:00
|
|
|
|
2019-09-12 18:10:30 +00:00
|
|
|
require_once "server_files/views/envoyer_video.php";
|