mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2024-12-26 19:02:21 +00:00
67 lines
2.2 KiB
PHP
67 lines
2.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 || Phase::getCurrentPhase() != Phase::PHASE4)
|
|
require_once "server_files/403.php";
|
|
|
|
if (isset($_POST["upload_answer"])) {
|
|
$new_video = new NewAnswer($_POST);
|
|
try {
|
|
$new_video->makeVerifications();
|
|
$new_video->uploadVideo();
|
|
} catch (AssertionError $e) {
|
|
$has_error = true;
|
|
$error_message = $e->getMessage();
|
|
}
|
|
}
|
|
|
|
class NewAnswer
|
|
{
|
|
public $link;
|
|
public $team;
|
|
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(preg_match("#[1|2]#", $this->team), "L'équipe n'a pas été trouvée.");
|
|
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, "ANSWER" . $this->team, $YEAR]);
|
|
|
|
Mailer::sendNewAnswer($this, $team);
|
|
}
|
|
}
|
|
|
|
$team1 = Team::fromId($team->getVideoTeamIds()[0]);
|
|
$sol1 = Video::getVideo(Reason::SOLUTION, $team1);
|
|
$answer1 = Video::getVideo(Reason::ANSWER1, $team);
|
|
$answer1_validated = Video::getVideo(Reason::ANSWER1, $team, Video::ACCEPTED);
|
|
$team2 = Team::fromId($team->getVideoTeamIds()[1]);
|
|
$sol2 = Video::getVideo(Reason::SOLUTION, $team2);
|
|
$answer2 = Video::getVideo(Reason::ANSWER2, $team);
|
|
$answer2_validated = Video::getVideo(Reason::ANSWER2, $team, Video::ACCEPTED);
|
|
|
|
$teams = [$team1, $team2];
|
|
$sols = [$sol1, $sol2];
|
|
$answers = [$answer1, $answer2];
|
|
$answers_validated = [$answer1_validated, $answer2_validated];
|
|
|
|
require_once "server_files/views/commenter_echange.php"; |