Antoine JOURDAIN 1 year ago
commit 0c7688cba1

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 MiB

@ -9,7 +9,7 @@ use gateway\VocabularyListGateway;
use model\MdlStudent;
use model\VocabularyList;
abstract class AbsController
class AbsController
{
public function showAccountInfos(): void {
@ -64,7 +64,7 @@ abstract class AbsController
global $twig;
try{
$idVoc = Validation::filter_int($match['params']['id'] ?? null);
$idVoc = Validation::filter_int($match['id'] ?? null);
$wordList = (new \gateway\TranslationGateway)->findByIdVoc($idVoc);
$wordShuffle = array();
@ -92,14 +92,40 @@ abstract class AbsController
throw new Exception("Erreur");
}
}
public function quiz(): void
public function quiz($match): void
{
global $twig;
$vocabId = $_GET['vocabID'];
$vocabId = Validation::filter_int($match['id'] ?? null);
$mdl = new TranslationGateway();
$allTranslation = $mdl->findByIdVoc($vocabId);
$shuffle = $allTranslation;
shuffle($shuffle);
echo $twig->render('quizzView.html', ['translations' => $allTranslation, 'randomtranslations']);
echo $twig->render('quizzView.html', ['translations' => $allTranslation, 'randomtranslations' => $shuffle]);
}
public function login(): void {
global $twig;
echo $twig->render('login.html');
}
public function confirmLogin(): void {
$model = new MdlStudent();
$login = strip_tags($_POST['logemail']);
$password = strip_tags($_POST['logpass']);
if (!$this->checkLoginExist($login)) throw new Exception(("login invalide"));
$user = $model->connection($login, $password);
if ($user == null) throw new Exception("mot de passe invalide");
$this->home();
}
public function checkLoginExist(string $login): bool {
$mdl = new MdlStudent();
return $mdl->checkLoginExist($login);
}
public function disconnect(): void {
$mdl = new MdlStudent();
$mdl->deconnection();
$this->home();
}
}

@ -19,11 +19,14 @@ class FrontController
$router = new \AltoRouter();
$router->setBasePath($altorouterPath);
$router->map('GET', '/', 'AppController');
$router->map('GET|POST', '/[a:action]?/[i:id]?', 'NULL');
$router->map('GET', '/', 'FrontController');
$router->map('GET|POST', '/admin/[i:id]/[a:action]?', 'Admin');
$router->map('GET|POST', '/teacher/[i:id]/[a:action]?', 'Teacher');
$router->map('GET|POST', '/student/[i:id]/[a:action]?', 'Student');
$router->map('GET|POST', '/abs/[a:action]?', 'Abs');
$router->map('GET|POST', '/abs/[a:action]/[i:id]', 'Abs');
$twig->addGlobal('base', $altorouterPath);
$match = $router->match();
@ -35,57 +38,45 @@ class FrontController
$action = Validation::val_action($match['params']['action'] ?? null);
$id = $match['params']['id'] ?? null;
switch ($action) {
case null:
$this->home();
break;
case 'memory':
AbsController::memory($match);
break;
case 'login':
$this->login();
break;
if ($target == 'Abs') {
$abs = new AbsController();
if (is_callable(array($abs, $action)))
call_user_func_array(array($abs, $action), array($match['params']));
}
else {
switch ($action) {
case null:
$this->home();
break;
case 'confirmLogin':
$this->confirmLogin();
break;
default :
if ($id != null && !$this->checkIdExist($id)) throw new Exception("identifiant invalide");
if ($target == null) throw new Exception("pas de target");
case 'disconnect':
$this->disconnect();
break;
if (isset($_SESSION['login']) && isset($_SESSION['roles'])) {
case 'quiz':
$this->quiz();
break;
$_SESSION['login'] = strip_tags($_SESSION['login']);
for ($i=0 ; $i<count($_SESSION['roles']) ; $i++) $_SESSION['roles'][$i] = strip_tags($_SESSION['roles'][$i]);
default :
if ($target == null) throw new Exception("pas de target");
$mdl = '\\model\\Mdl' . $target;
$mdl = new $mdl;
if (isset($_SESSION['login']) && isset($_SESSION['roles'])) {
if (is_callable(array($mdl, 'is'))) {
$user = call_user_func_array(array($mdl, 'is'), array($_SESSION['login'], $_SESSION['roles']));
$_SESSION['login'] = strip_tags($_SESSION['login']);
for ($i=0 ; $i<count($_SESSION['roles']) ; $i++) $_SESSION['roles'][$i] = strip_tags($_SESSION['roles'][$i]);
if (!$user || $user->getId() != $id) throw new Exception("erreur 403 permission denied");
}
$mdl = '\\model\\Mdl' . $target;
$mdl = new $mdl;
$controller = '\\controller\\' . $target . 'Controller';
$controller = new $controller;
if (is_callable(array($mdl, 'is'))) {
$user = call_user_func_array(array($mdl, 'is'), array($_SESSION['login'], $_SESSION['roles']));
if (is_callable(array($controller, $action)))
call_user_func_array(array($controller, $action), array($match['params']));
if (!$user || $user->getId() != $id) throw new Exception("erreur 403 permission denied");
break;
}
$controller = '\\controller\\' . $target . 'Controller';
$controller = new $controller;
if (is_callable(array($controller, $action)))
call_user_func_array(array($controller, $action), array($match['params']));
break;
}
else $this->login();
else (new AbsController())->login();
}
}
}
}
@ -96,40 +87,9 @@ class FrontController
}
}
public function home(): void {
global $twig;
echo $twig->render('home.html');
var_dump($_SESSION['roles']);
}
public function login(): void {
global $twig;
echo $twig->render('login.html');
}
public function confirmLogin(): void {
$model = new MdlStudent();
$login = strip_tags($_POST['logemail']);
$password = strip_tags($_POST['logpass']);
if (!$this->checkLoginExist($login)) throw new Exception(("login invalide"));
$user = $model->connection($login, $password);
if ($user == null) throw new Exception("mot de passe invalide");
$this->home();
}
public function checkLoginExist(string $login): bool {
$mdl = new MdlStudent();
return $mdl->checkLoginExist($login);
}
public function disconnect(): void {
$mdl = new MdlStudent();
$mdl->deconnection();
$this->home();
}
public function quiz(){
$ctrl = new StudentController();
$ctrl->quiz();
}
}

@ -35,25 +35,4 @@ class StudentController
$vocab = $mdl->getVocabByName($name);
echo $twig->render('manageVocabView.html', ['vocabularies' => $vocab]);
}
public function quiz(): void
{
global $twig;
$vocabId = $_GET['vocabID'];
$mdl = new TranslationGateway();
$allTranslation = $mdl->findByIdVoc($vocabId);
$shuffle = $allTranslation;
shuffle($shuffle);
echo $twig->render('quizzView.html', ['translations' => $allTranslation, 'randomtranslations']);
}
/*
public function flashcard(VocabularyList $v) {
$idVoc = $v->getId();
$mdl = new TranslationGateway();
$allTranslation = $mdl->findByIdVoc($idVoc);
while(1) {
}
}
}*/
}

@ -34,7 +34,7 @@
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="#game">Game</a></li>
<li class="nav-item"><a class="nav-link" href="#download">Download</a></li>
<li class="nav-item"><a class="nav-link" href="login">My account</a></li>
<li class="nav-item"><a class="nav-link" href="{{base}}/abs/login">My account</a></li>
</ul>
</div>
</div>

@ -5,12 +5,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://unicons.iconscout.com/release/v2.1.9/css/unicons.css" rel="stylesheet"/>
<link href="css/login.css" rel="stylesheet" />
<link href="../css/login.css" rel="stylesheet" />
<title>Login</title>
</head>
<body>
<div class="section">
<a href="."><img src="assets/img/home.png"></a>
<a href="{{base}}/"><img src="../assets/img/home.png"></a>
<div class="container">
<div class="row full-height justify-content-center">
<div class="col-12 text-center align-self-center py-5">
@ -24,7 +24,7 @@
<div class="center-wrap">
<div class="section text-center">
<h4 class="mb-4 pb-3">Log In</h4>
<form action="confirmLogin" method="POST">
<form action="{{base}}/abs/confirmLogin" method="POST">
<div class="form-group">
<input type="email" name="logemail" class="form-style" placeholder="Your Email" id="logemail" autocomplete="off">
<i class="input-icon uil uil-at"></i>

@ -5,24 +5,51 @@
<title>Manage groups</title><!-- Vos liens de styles et de scripts -->
</head>
<body>
<section>
<section id="quiz">
<h1>Quiz</h1>
{% if translations is defined %}
{% for translation in translations %}
<h2>{{ translation.word1 }}</h2>
{% set correctAnswer = translation.word2 %}
{% set otherTranslations = [translation.word2, translations[0].word2, translations[1].word2, translations[2].word2] %}
<input type="radio" name="answer" value="{{ correctAnswer }}"> {{ correctAnswer }}<br>
{% for otherTranslation in otherTranslations %}
{% if otherTranslation != correctAnswer %}
<input type="radio" name="answer" value="{{ otherAnswer }}"> {{ otherAnswer }}<br>
<div id="questionContainer">
{% if translations is defined %}
{% for translation in translations %}
<h2 id="question">{{ translation.word1 }}</h2>
{% set correctAnswer = translation.word2 %}
{% if randomtranslations is defined %}
{% set otherTranslations = [correctAnswer] %}
{% for randomtranslation in randomtranslations %}
{% if randomtranslation.word2 != correctAnswer and otherTranslations|length <= 3 %}
{% set otherTranslations = otherTranslations|merge([randomtranslation.word2]) %}
{% endif %}
{% endfor %}
{% endfor %}
{% endif %}
<input type="submit" value="Submit" name="submitForm">
{% endfor %}
<form id="quizForm" method="post">
<div id="answers">
<input type="radio" name="answer" value="{{ correctAnswer }}"> {{ correctAnswer }}<br>
</div>
{% for otherTranslation in otherTranslations %}
<input type="radio" name="wrong" value="{{ otherTranslation }}"> {{ otherTranslation }}<br>
{% endfor %}
<input type="hidden" name="action" value="test">
<button value="submit" type="submit" >soumettre</button>
</form>
</div>
<script>
$(document).ready(function() {
$('#quizForm').submit(function(event) {
event.preventDefault();
$.ajax({
type: 'POST',
url: '/../controller/AbsController.php',
data: $(this).serialize(),
success: function(response) {
$('#result').html(response);
}
});
});
});
</script>
{% endif %}
{% endfor %}
{% endif %}
{% if submitted %}
{% if isCorrect %}
<p>Correct answer!</p>
@ -45,4 +72,64 @@
</form>
</section>
</body>
</html>
</html>
<script>
const questions = [
{
question: "Question 2?",
answers: ["Answer A", "Answer B", "Answer C"],
correctAnswer: "Answer B"
},
// Ajoutez d'autres questions ici
];
let currentQuestion = 0;
const questionContainer = document.getElementById('questionContainer');
const questionElement = document.getElementById('question');
const answersElement = document.getElementById('answers');
const resultElement = document.getElementById('result');
function showQuestion() {
const question = questions[currentQuestion];
questionElement.textContent = question.question;
answersElement.innerHTML = '';
question.answers.forEach(answer => {
const label = document.createElement('label');
const input = document.createElement('input');
input.type = 'radio';
input.name = 'answer';
input.value = answer;
label.appendChild(input);
label.appendChild(document.createTextNode(answer));
answersElement.appendChild(label);
answersElement.appendChild(document.createElement('br'));
});
}
function checkAnswer(event) {
event.preventDefault();
const selectedAnswer = document.querySelector('input[name="answer"]:checked');
if (!selectedAnswer) {
resultElement.textContent = 'Please select an answer.';
return;
}
if (selectedAnswer.value === questions[currentQuestion].correctAnswer) {
resultElement.textContent = 'Correct answer!';
} else {
resultElement.textContent = 'Wrong answer!';
}
currentQuestion++;
if (currentQuestion < questions.length) {
showQuestion();
} else {
questionContainer.style.display = 'none';
}
}
document.getElementById('quizForm').addEventListener('submit', checkAnswer);
showQuestion();
</script>

@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/styles.css" rel="stylesheet" />
<title>Félicitations!</title>
<style>
body {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background: url('../assets/img/points.png') center/cover no-repeat;
background-color: lightslategray;
}
.container {
text-align: center;
padding-left: 40vh;
padding-right: 40vh;
background-color: #7464a1;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.message {
color: black;
font-size: 36px;
font-family: 'Comic Sans MS', cursive, sans-serif;
font-weight: bold;
margin-bottom: 20px;
}
.celebration-image {
width: 100%;
max-width: 300px;
border-radius: var(--bs-border-radius);
}
</style>
</head>
<body>
<div class="container">
<div class="message">
Bravo ! Vous avez gagné 125 points !!
</div>
<img class="celebration-image" src="../assets/img/celeb.png" alt="Célébration">
</div>
</body>
</html>
Loading…
Cancel
Save