Possibilité d'accéder à la vue d'une autre personne sur la plateforme en tant qu'administrateur

This commit is contained in:
Yohann 2019-10-22 00:10:46 +02:00
parent b5f3c4ac58
commit b99e7586db
4 changed files with 42 additions and 5 deletions

View File

@ -41,6 +41,14 @@ if (isset($_POST["attribute_team"])) {
}
}
if (isset($_POST["view_as"]) && $_SESSION["role"] == Role::ADMIN) {
if (!isset($_SESSION["admin"]))
$_SESSION["admin"] = $_SESSION["user_id"];
$_SESSION["user_id"] = $user->getId();
header("Location: /");
exit();
}
class AttributeTeam
{
private $team_id;

View File

@ -19,6 +19,15 @@ function loadUserValues()
if ($user->getTeamId() !== null)
$_SESSION["team"] = Team::fromId($user->getTeamId());
}
if (isset($_GET["view-as-admin"])) {
if (isset($_SESSION["admin"])) {
$_SESSION["user_id"] = $_SESSION["admin"];
unset($_SESSION["admin"]);
}
header("Location: /");
exit();
}
}
function quitTeam($user_id = -1)
@ -277,17 +286,23 @@ function exportProblemsData() {
function displayVideo($link)
{
if (preg_match("#(https?\://|)(www\.|)youtube\.com\/watch\?v=(.*)#", $link, $matches)) {
if (preg_match("#(https?://|)(www\.|)youtube\.com/watch\?v=(.*)#", $link, $matches)) {
$code = $matches[3];
echo "<center><iframe width=\"854px\" height=\"480px\" src=\"https://www.youtube.com/embed/$code\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe></center><br />\n";
/** @noinspection HtmlDeprecatedAttribute */
/** @noinspection HtmlDeprecatedTag */
echo "<center><iframe width=\"854px\" height=\"480px\" src=\"https://www.youtube.com/embed/$code\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe></center><br />\n";
}
elseif (preg_match("#(https?\://|)(www\.|)vimeo\.com/([0-9]*)#", $link, $matches)) {
elseif (preg_match("#(https?://|)(www\.|)vimeo\.com/([0-9]*)#", $link, $matches)) {
$code = $matches[3];
echo "<center><iframe src=\"https://player.vimeo.com/video/$code?color=3be6c3\" width=\"853\" height=\"480\" frameborder=\"0\" allow=\"autoplay; fullscreen\" allowfullscreen></iframe></center>";
/** @noinspection HtmlDeprecatedAttribute */
/** @noinspection HtmlDeprecatedTag */
echo "<center><iframe src=\"https://player.vimeo.com/video/$code?color=3be6c3\" width=\"853\" height=\"480\" frameborder=\"0\" allow=\"autoplay; fullscreen\" allowfullscreen></iframe></center>";
}
elseif (preg_match("#(https?\://|)(www\.|)dailymotion\.com/video/(.*)#", $link, $matches)) {
elseif (preg_match("#(https?://|)(www\.|)dailymotion\.com/video/(.*)#", $link, $matches)) {
$code = $matches[3];
/** @noinspection HtmlDeprecatedAttribute */
/** @noinspection HtmlDeprecatedTag */
echo "<center><iframe frameborder=\"0\" width=\"853\" height=\"480\" src=\"https://www.dailymotion.com/embed/video/$code\" allowfullscreen allow=\"autoplay\"></iframe></center>";
}
}

View File

@ -96,6 +96,11 @@
</ul>
<ul class="navbar-nav">
<?php if (isset($_SESSION["admin"])) { ?>
<li class="nav-item active">
<a class="nav-link" href="/?view-as-admin">Retourner en vue administrateur</a>
</li>
<?php } ?>
<?php if (isset($_SESSION["user_id"])) { ?>
<li class="nav-item active">
<a class="nav-link" href="/deconnexion">Déconnexion</a>

View File

@ -98,4 +98,13 @@ if (!$has_error) {
printDocuments($documents);
}
if ($_SESSION["role"] == Role::ADMIN && $_SESSION["user_id"] != $user->getId()) { ?>
<hr />
<form method="POST">
<input type="submit" name="view_as" class="btn btn-secondary btn-lg btn-block" style="background-color: #ff2e34"
value="Afficher le site en tant que <?= $user->getFirstName() . " " . $user->getSurname() ?>" />
</form>
<?php }
require_once "footer.php";