67 lines
1.9 KiB
PHP
67 lines
1.9 KiB
PHP
<?php
|
|
|
|
if (!isset($_SESSION["user_id"]) || $_SESSION["role"] != Role::PARTICIPANT && $_SESSION["role"] != Role::ENCADRANT)
|
|
require_once "server_files/403.php";
|
|
|
|
/**
|
|
* @var User $user
|
|
* @var Team $team
|
|
*/
|
|
$user = $_SESSION["user"];
|
|
;$team = $user->getRole() == Role::PARTICIPANT ? $_SESSION["team"] : Team::fromTrigram($_GET["trigram"]);
|
|
|
|
if ($team == null)
|
|
require_once "server_files/404.php";
|
|
|
|
if ($team->getEncadrantId() != $user->getId() || $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
|
|
{
|
|
public $link;
|
|
private $valid_link;
|
|
private $no_change;
|
|
|
|
public function __construct($data)
|
|
{
|
|
foreach ($data as $key => $value)
|
|
$this->$key = $value;
|
|
}
|
|
|
|
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.");
|
|
$this->link = preg_replace('/^(?!https?:\/\/)/', 'https://', $this->link);
|
|
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.");
|
|
}
|
|
|
|
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, Reason::getName(Reason::SOLUTION), $YEAR]);
|
|
|
|
Mailer::sendNewVideo($this, $team);
|
|
}
|
|
}
|
|
|
|
$video = Video::getVideo(Reason::SOLUTION, $team);
|
|
$video_validated = Video::getVideo(Reason::SOLUTION, $team, Video::ACCEPTED);
|
|
|
|
require_once "server_files/views/envoyer_video.php"; |