tdphp/td5/persos.php

114 lines
5 KiB
PHP
Raw Normal View History

2023-03-22 08:13:04 +01:00
<?php
session_start();
if ($_SESSION["user"] == null) {
header("Location: connexion.php");
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Monsite</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Mon Site</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav me-auto mb-2 mb-md-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="index.php">Accueil</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="persos.php">Personnages Historiques</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container p-5">
<div class="row g-5">
<?php
if ($_SESSION["user"]["role"] == "admin") {
?>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#nouveauPerso" data-bs-whatever="@new">Nouveau personnage</button>
<?php
}
$personnages = json_decode(file_get_contents("personnages.json"), true);
foreach ($personnages["historicalFigures"] as $perso) {
?>
<div class="col col-3">
<div class="card">
<img src="<?= $perso["image"] ?>" class="card-img-top" alt="Photo de <?= $perso["name"] ?>">
<div class="card-body">
<h5 class="card-title"><?= $perso["name"] ?></h5>
<p class="text-muted"><?= $perso["birthDate"] ?> - <?= $perso["deathDate"] ?></p>
<p class="card-text"><?= $perso["description"] ?></p>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
<div class="modal fade" id="nouveauPerso" tabindex="-1" aria-labelledby="nouveauPersoLabel" aria-hidden="true">
<div class="modal-dialog">
<form method="POST" action="action/new.php">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="nouveauPersoLabel">Nouveau personnage historique
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label class="col-form-label">Nom :</label>
<input type="text" class="form-control" name="nom" required>
</div>
<div class="mb-3">
<label class="col-form-label">Lien vers l'image :</label>
<input type="url" class="form-control" name="imgurl" required>
</div>
<div class="mb-3">
<label class="col-form-label">Date de naissance :</label>
<input type="text" class="form-control" name="bdate" required>
</div>
<div class="mb-3">
<label class="col-form-label">Date de décès :</label>
<input type="text" class="form-control" name="ddate" required>
</div>
<div class="mb-3">
<label class="col-form-label">Description :</label>
<textarea class="form-control" name="description" required></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fermer</button>
<input type="submit" class="btn btn-primary" value="Ajouter">
</div>
</div>
<input type="text" value="valider" name="valide" hidden>
</form>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
</body>
</html>