ajout git

This commit is contained in:
Alexis HADJEM--BRANCHER 2024-06-16 17:25:59 +02:00
parent c9d69f8df5
commit a7e2b23690
2 changed files with 114 additions and 136 deletions

View File

@ -47,9 +47,13 @@ $commentaire=mysqli_fetch_all($req,MYSQLI_ASSOC);
<?php <?php
echo '<div id="article">' echo '<div id="event">'
. '<h3>'. $event['title'] .'</h3>' . '<h3>'. $event['Nom'] .'</h3>'
. '<div id="content">' . $event['description'] . '</div>'; . '<div id="content">' . $event['Description'] . '</div>';
echo "<br> Sport:". $event['Sport'];
echo "<br> Lieu:". $event['Lieux'];
echo "<br> Date:". $event['Date'];
echo "<br> Nombre de participant:". $event['NbInscrit'];
echo '<h5 class="_bb1">Commentaires</h5>'; echo '<h5 class="_bb1">Commentaires</h5>';
if (empty($commentaire)) { if (empty($commentaire)) {
@ -57,37 +61,35 @@ if (empty($commentaire)) {
} else { } else {
foreach ($commentaire as $com) { foreach ($commentaire as $com) {
echo '<section class="alert-box">'; echo '<section class="alert-box">';
echo "<b class='_ts2'>".$com['title']."</b>" echo "<b class='_ts2'>".$com['login']."</b>"
. (isset($_SESSION['user']['id']) && $com['id_user'] == $_SESSION['user']['id'] ? . (isset($_SESSION['login']) && $com['login'] == $_SESSION['login'] ?
' <a href="comment_create.php?id_article=' . $com['id_article'] ' <a href="créer_commentaire.php?id_event=' . $com['id_event']
. '&amp;id_comment=' . $com['id'] . '" title="'. $com['title'] . '&amp;id_comment=' . $com['id_comment'] . '" login="'. $com['login']
. '">Modifier ce commentaire</a>' : . '">Modifier ce commentaire</a>' :
'') '')
. '<p class="_ts2">' . $comment['content'] ."</p>" . '<p class="_ts2">' . $com['contenu'] ."</p>";
. "<p><span class='tag-box -warning'><a href=\"".$comment['url']."\">".$comment['login']."</a></p>"; //. "<p><span class='tag-box -warning'><a href=\"".$com['url']."\">".$com['login']."</a></p>";
echo "</section>"; echo "</section>";
} }
} }
echo "</div>"; echo "</div>";
if (empty($_SESSION['user'])) { if (empty($_SESSION['login'])) {
echo '<p>Il faut être identifié pour poster un commentaire.</p>'; echo '<p>Il faut être identifié pour poster un commentaire.</p>';
} else { } else {
if ($article['closed']) {
echo "<p>Article fermé, non modifiable.</p>"; echo '<p> <a href="créer_commentaire.php?id_event='. $event['id']
} else { .'">Ajouter un commentaire</a> avec votre compte : ' . $_SESSION['login']
echo '<p> <a href="comment_create.php?id_article='. $article['id'] .' </p>';
.'">Ajouter un commentaire</a> avec votre compte : ' . $_SESSION['user']['name']
.' </p>';
} }
}
?> ?>
<p> <a href="article_list.php">Retour à la liste des articles</a> </p> <p> <a href="evenement.php">Retour à la liste des evenement</a> </p>
<footer>
<?php <?php
include 'footer.php'; include 'footer.php';
?> ?>
</footer>
</body> </body>
</html> </html>

View File

@ -1,129 +1,105 @@
<html lang="fr" > <?php
require_once 'common.php';
session_start();
$db = initDatabase();
// Populate initial data if table is empty
$vide = mysqli_query($db, "SELECT * FROM user");
if (mysqli_num_rows($vide) == 0) {
$hello = password_hash('hello', PASSWORD_DEFAULT);
mysqli_query($db, "INSERT INTO user (login, email, last_name, first_name, gender, password, role) VALUES ('toto','toto@gmail.com','Dufour','Michel','homme','$hello','athlete')");
mysqli_query($db, "INSERT INTO user (login, email, last_name, first_name, gender, password, role) VALUES ('commun','commun@gmail.com','Hello','World','autre','$hello','organizer')");
mysqli_query($db, "INSERT INTO user (login, email, last_name, first_name, gender, password, role) VALUES ('Marie','Marie@gmail.com','Monro','Mariline','femme','$hello','spectator')");
}
if (!empty($_POST['login']) && !empty($_POST['password'])) {
$login = htmlspecialchars($_POST['login'], ENT_QUOTES, 'UTF-8');
$password = htmlspecialchars($_POST['password'], ENT_QUOTES, 'UTF-8');
$role = htmlspecialchars($_POST['role'], ENT_QUOTES, 'UTF-8');
$mail = htmlspecialchars($_POST['mail'], ENT_QUOTES, 'UTF-8');
$nom = htmlspecialchars($_POST['nom'], ENT_QUOTES, 'UTF-8');
$prenom = htmlspecialchars($_POST['prenom'], ENT_QUOTES, 'UTF-8');
$genre = htmlspecialchars($_POST['genre'], ENT_QUOTES, 'UTF-8');
$password_hash = password_hash($password, PASSWORD_DEFAULT);
// Check for existing user with same login or email
$stmt = $db->prepare("SELECT * FROM user WHERE login = ? OR mail = ?");
$stmt->bind_param("ss", $login, $mail);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows == 0) {
$stmt = $db->prepare("INSERT INTO user (login, mail, nom, prenom, genre, mdp, Role) VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssssss", $login, $mail, $nom, $prenom, $genre, $password_hash, $role);
if ($stmt->execute()) {
header('Location: connexion.php');
exit();
} else {
die("Erreur : " . $stmt->error);
}
} else {
$existant = $result->fetch_assoc();
if ($existant['login'] == $login) {
$error_verif = "Ce login est déjà utilisé";
} else if ($existant['mail'] == $mail) {
$error_verif2 = "Cette adresse mail est déjà utilisée";
}
}
$stmt->close();
}
?>
<!DOCTYPE html>
<html lang="fr">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<link rel="icon" href="../img/jo2024.jpg" > <link rel="icon" href="../img/jo2024.jpg">
<link rel="stylesheet" href="../css/style.css"> <link rel="stylesheet" href="../css/style.css">
<title>Inscription - Jeux Olympiques</title> <title>Inscription - Jeux Olympiques</title>
</head> </head>
<body > <body>
<header>
<h1 class='Hello'>Page d'inscription</h1>
<?php <nav>
<a href="../" class="categorie">Page d'accueil</a>
// Informations de connexion à la base de données </nav>
require_once 'common.php'; </header>
session_start(); <div class="inscription" id="inscription">
$db = initDatabase(); <u><i><h2>Inscription</h2></i></u> <br>
$vide = mysqli_query($db,"SELECT * FROM user"); <form action="" method="post">
if (mysqli_num_rows($vide)==0) { <label for="login">Login :</label><br>
$hello=password_hash('hello', PASSWORD_DEFAULT); <input type="text" id="login" name="login" required><br>
<?php if (isset($error_verif)) {echo "<div class='error-message'>$error_verif</div>";} ?>
mysqli_query($db,"INSERT INTO user VALUES ('toto','toto@gmail.com','Dufour','Michel','homme','$hello','athlete')"); <br><br><label for="mail">Adresse mail :</label><br>
mysqli_query($db,"INSERT INTO user VALUES ('commun','commun@gmail.com','Hello','World','autre','$hello','organizer')"); <input type="email" id="mail" name="mail" placeholder="username@example.com" required><br>
mysqli_query($db,"INSERT INTO user VALUES ('Marie','Marie@gmail.com','Monro','Mariline','femme','$hello','spectator')"); <?php if (isset($error_verif2)) {echo "<div class='error-message'>$error_verif2</div>";} ?>
} <br><br><label for="nom">Nom :</label><br>
if (!empty($_REQUEST['login']) && !empty($_REQUEST['password'])) { <input type="text" id="nom" name="nom" required><br>
<br><br><label for="prenom">Prenom :</label><br>
$login = $_POST['login']; <input type="text" id="prenom" name="prenom" required><br>
$password = $_POST['password']; <br><br> <label for="genre"> Genre: </label> <br>
$role = $_POST['role'];
$mail = $_POST['mail'];
$nom = $_POST['nom'];
$prenom = $_POST['prenom'];
$genre = $_POST['genre'];
$password_hash = password_hash($password, PASSWORD_DEFAULT);
$verif=mysqli_query($db,"SELECT * FROM user WHERE login = '$login' ");
$verif2=mysqli_query($db,"SELECT * FROM user WHERE mail = '$mail' ");
$result="INSERT INTO user VALUES('$login','$mail','$nom','$prenom','$genre','$password_hash','$role')";
if (mysqli_num_rows($verif) == 0) {
if (mysqli_num_rows($verif2) == 0) {
if (mysqli_query($db,$result)) {
header('Location: connexion.php');
exit();
}
else {
die("erreur");
}
}
else {
$error_verif2 = "Cette adresse mail est déjà utilisé";
}
}
else {
$error_verif = "Ce login est déjà utilisé";
}
}
// Récupération des données du formulaire
?>
<header>
<h1 class='Hello'> Page d'inscription </h1>
<nav>
<a href="../" class="categorie">Page d'accueil</a>
</nav>
</header>
<div class="inscription" id="inscription">
<u><i><h2>Inscription</h2></i></u> <br>
<form action="" method="post">
<label for="login">Login :</label><br>
<input type="text" id="login" name="login" required ><br>
<?php if (isset($error_verif)) {echo "<div class='error-message'>$error_verif</div>";} ?>
<br><br><label for="mail">Adresse mail :</label><br>
<input type="email" id="mail" name="mail" placeholder="username@example.com" required><br>
<?php if (isset($error_verif2)) {echo "<div class='error-message'>$error_verif2</div>";} ?>
<br><br><label for="nom">Nom :</label><br>
<input type="text" id="nom" name="nom" required><br>
<br><br><label for="prenom">Prenom :</label><br>
<input type="text" id="prenom" name="prenom" required><br>
<br><br> <label for ="genre"> Genre: </label> <br>
<select id="genre" name="genre" required> <select id="genre" name="genre" required>
<option value="">-- Please choose an option --</option> <option value="">-- Please choose an option --</option>
<option value="homme">Homme</option> <option value="homme">Homme</option>
<option value="femme">Femme</option> <option value="femme">Femme</option>
<option value="autre">Autre</option> <option value="autre">Autre</option>
</select><br> </select><br>
<br><br><label for="password">Mot de passe :</label><br>
<input type="password" id="password" name="password" placeholder="••••••••" required><br>
<br><br><label for="password">Mot de passe :</label><br> <br><br><label for="role">Role :</label><br>
<input type="password" id="password" name="password" placeholder="••••••••" required><br> <select id="role" name="role" required>
<option value="">-- Please choose an option --</option>
<option value="spectator">Spectator</option>
<br><br><label for="role">Role :</label><br> <option value="athlete">Athlete</option>
<select id="role" name="role" required> <option value="organizer">Organizer</option>
<option value="">-- Please choose an option --</option> </select><br><br>
<option value="spectator">Spectator</option> <br><button type="submit" class="submit">Créer un compte</button>
<option value="athlete">Athlete</option> </form>
<option value="organizer">Organizer</option> <p class="compteUser">Vous possédez déjà un compte ? <br><a href="connexion.php">Connectez-vous !</a></p>
</select><br><br>
<br><button type="submit" class="submit">Créer une compte </button>
</form>
<p class="compteUser">Vous possédez déjà un compte ? <br><a href="connexion.php">Connectez-vous !</a></p>
</div> </div>
<footer> <footer>
<?php require_once('footer.php'); ?> <?php require_once('footer.php'); ?>
</footer> </footer>
</body> </body>
</html> </html>