correction-ulysse (#2)

# Correction pour les TP1 TP2 et TP3

Je n'ai pas testé la connexion à la DB pour le moment car je ne peux pas me co sur https://dwarves.iut-fbleau.fr/phpmyadmin

Co-authored-by: JARNOUEN DE VILLARTAY Ulysse (SAFRAN AIRCRAFT ENGINES) <ulysse.jarnouen-de-villartay@safrangroup.com>
Reviewed-on: monnerat/web_2025#2
This commit is contained in:
2026-04-15 15:34:46 +02:00
parent 045ec81ae2
commit a4580652f8
22 changed files with 692 additions and 215 deletions
+18 -17
View File
@@ -1,26 +1,27 @@
<?php
include 'include/controller.php';
include_once 'include/controller.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<html lang="fr">
<head>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="./css/style.css">
<meta charset="UTF-8" />
<title></title>
</head>
<body>
<main>
<ul>
<?php
echo "<li>$prenom $nom</li>";
echo "<li><i class='fa-brands $icon fa-2x'></i></li>";
?>
</ul>
</main>
</body>
<link rel="stylesheet" href="./css/style.css">
<meta charset="UTF-8" />
<title>Exercice 1</title>
</head>
<body>
<main>
<ul>
<?php
echo '<li>' . htmlspecialchars($prenom . ' ' . $nom, ENT_QUOTES, 'UTF-8') . '</li>';
echo '<li>' . htmlspecialchars($systeme, ENT_QUOTES, 'UTF-8') . " <i class='fa-brands $icon fa-2x'></i></li>";
?>
</ul>
</main>
</body>
</html>
+26 -1
View File
@@ -1,2 +1,27 @@
<?php
// TODO
$nom = '';
$prenom = '';
$systeme = '';
$icon = 'fa-circle-question';
$systemes = [
1 => ['nom' => 'Linux', 'icon' => 'fa-linux'],
2 => ['nom' => 'Windows', 'icon' => 'fa-windows'],
3 => ['nom' => 'macOS', 'icon' => 'fa-apple'],
4 => ['nom' => 'Android', 'icon' => 'fa-android'],
];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$nomSaisi = trim((string) filter_input(INPUT_POST, 'nom', FILTER_UNSAFE_RAW));
$prenomSaisi = trim((string) filter_input(INPUT_POST, 'prenom', FILTER_UNSAFE_RAW));
$os = filter_input(INPUT_POST, 'os', FILTER_VALIDATE_INT);
$nom = ucfirst(strtolower($nomSaisi));
$prenom = ucfirst(strtolower($prenomSaisi));
if (isset($systemes[$os])) {
$systeme = $systemes[$os]['nom'];
$icon = $systemes[$os]['icon'];
}
}
+17 -1
View File
@@ -1,2 +1,18 @@
<?php
// TODO
$table = filter_input(INPUT_GET, 'table', FILTER_VALIDATE_INT);
$lignes = [];
$messageErreur = '';
if ($table === false || $table === null) {
$messageErreur = 'Veuillez saisir un entier valide.';
} else {
for ($multiplicateur = 1; $multiplicateur <= 10; $multiplicateur++) {
$lignes[] = [
'multiplicateur' => $multiplicateur,
'resultat' => $table * $multiplicateur,
];
}
}
+43 -19
View File
@@ -1,23 +1,47 @@
<?php
include 'include/controller.php';
include_once 'include/controller.php';
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
/>
<link rel="stylesheet" href="./css/style.css">
</head>
<body>
<main>
<h4>Table de multiplication</h4>
<form method="GET">
<input type=number name="table" placeholder="table">
<button type="submit">ENVOYER</button>
</form>
</main>
</body>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
/>
<link rel="stylesheet" href="./css/style.css">
<title>Exercice 2</title>
</head>
<body>
<main>
<h4>Table de multiplication</h4>
<form method="GET">
<input
type="number"
name="table"
placeholder="table"
value="<?php echo htmlspecialchars($table, ENT_QUOTES, 'UTF-8'); ?>"
>
<button type="submit">ENVOYER</button>
</form>
<?php if ($messageErreur !== '') : ?>
<p><?php echo htmlspecialchars($messageErreur, ENT_QUOTES, 'UTF-8'); ?></p>
<?php endif; ?>
<?php if ($table !== false && $table !== null) : ?>
<ul>
<?php foreach ($lignes as $ligne) : ?>
<li>
<?php echo htmlspecialchars((string) $table, ENT_QUOTES, 'UTF-8'); ?>
x
<?php echo htmlspecialchars((string) $ligne['multiplicateur'], ENT_QUOTES, 'UTF-8'); ?>
=
<?php echo htmlspecialchars((string) $ligne['resultat'], ENT_QUOTES, 'UTF-8'); ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</main>
</body>
</html>
+53 -28
View File
@@ -1,34 +1,59 @@
<?php
include 'include/controller.php';
include_once 'include/controller.php';
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<title></title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
/>
<link rel="stylesheet" href="./css/style.css">
</head>
<body>
<main class="container">
<h3>Calculatrice</h3>
<form method="POST">
<div class="grid">
<input placeholder="un nombre" type="number" step="any" name="op1" value ="" required>
<select name="operation" required>
<option value="+">+</option>
<option value="-">-</option>
<option value="x">x</option>
<option value="/">/</option>
</select>
<input placeholder="un nombre" type="number" step="any" name="op2" required>
<button type="submit" name="soumis"> Calculer</button>
</grid>
</form>
</main>
</body>
<head>
<meta charset="UTF-8" />
<title>Exercice 3</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico.min.css"
/>
<link rel="stylesheet" href="./css/style.css">
</head>
<body>
<main class="container">
<h3>Calculatrice</h3>
<form method="POST">
<div class="grid">
<input
placeholder="un nombre"
type="number"
step="any"
name="op1"
value="<?php echo htmlspecialchars($valeurOp1, ENT_QUOTES, 'UTF-8'); ?>"
required
>
<select name="operation" required>
<option value="+" <?php echo $operation === '+' ? 'selected' : ''; ?>>+</option>
<option value="-" <?php echo $operation === '-' ? 'selected' : ''; ?>>-</option>
<option value="x" <?php echo $operation === 'x' ? 'selected' : ''; ?>>x</option>
<option value="/" <?php echo $operation === '/' ? 'selected' : ''; ?>>/</option>
</select>
<input
placeholder="un nombre"
type="number"
step="any"
name="op2"
value="<?php echo htmlspecialchars($valeurOp2, ENT_QUOTES, 'UTF-8'); ?>"
required
>
<button type="submit" name="soumis">Calculer</button>
</div>
</form>
<?php if ($messageErreur !== '') : ?>
<p><?php echo htmlspecialchars($messageErreur, ENT_QUOTES, 'UTF-8'); ?></p>
<?php endif; ?>
<?php if ($aCalcule) : ?>
<p>
Résultat :
<?php echo htmlspecialchars($valeurOp1, ENT_QUOTES, 'UTF-8'); ?>
</p>
<?php endif; ?>
</main>
</body>
</html>
+55 -1
View File
@@ -1,2 +1,56 @@
<?php
//TODO
$op1Saisi = filter_input(INPUT_POST, 'op1', FILTER_UNSAFE_RAW);
$op2Saisi = filter_input(INPUT_POST, 'op2', FILTER_UNSAFE_RAW);
$operationSaisie = filter_input(INPUT_POST, 'operation', FILTER_UNSAFE_RAW);
$op1Saisi = is_string($op1Saisi) ? trim($op1Saisi) : '';
$op2Saisi = is_string($op2Saisi) ? trim($op2Saisi) : '';
$operationSaisie = is_string($operationSaisie) ? trim($operationSaisie) : '+';
$operationsAutorisees = ['+', '-', 'x', '/'];
$operation = in_array($operationSaisie, $operationsAutorisees, true) ? $operationSaisie : '+';
$resultat = null;
$messageErreur = '';
$aCalcule = false;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$op1 = filter_var($op1Saisi, FILTER_VALIDATE_FLOAT);
$op2 = filter_var($op2Saisi, FILTER_VALIDATE_FLOAT);
if ($op1 === false || $op2 === false) {
$messageErreur = 'Veuillez saisir deux nombres valides.';
} elseif (!in_array($operation, $operationsAutorisees, true)) {
$messageErreur = 'Veuillez choisir une opération valide.';
} elseif ($operation === '/' && (float) $op2 == 0.0) {
$messageErreur = 'La division par zéro est impossible.';
} else {
$aCalcule = true;
switch ($operation) {
case '+':
$resultat = $op1 + $op2;
break;
case '-':
$resultat = $op1 - $op2;
break;
case 'x':
$resultat = $op1 * $op2;
break;
case '/':
$resultat = $op1 / $op2;
break;
default:
$messageErreur = 'Veuillez choisir une opération valide.';
$aCalcule = false;
}
}
}
$valeurOp1 = $aCalcule ? (string) $resultat : $op1Saisi;
$valeurOp2 = $op2Saisi;
+10
View File
@@ -2,3 +2,13 @@ button{
float:right;
}
.bonne-reponse {
color: #1b7f3a;
font-weight: 700;
}
.mauvaise-reponse {
color: #c62828;
font-weight: 700;
}
+79 -15
View File
@@ -1,17 +1,81 @@
<?php
$nombreQuestions = 0;
$score = 0;
$questionsTraitees = 0;
$message = 'Aucun resultat a afficher.';
$resultatsParQuestion = [];
$nombreQuestionsSaisi = filter_input(INPUT_POST, 'nbq', FILTER_VALIDATE_INT);
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $nombreQuestionsSaisi !== false && $nombreQuestionsSaisi !== null) {
$nombreQuestions = $nombreQuestionsSaisi;
$message = '';
for ($index = 1; $index <= $nombreQuestions; $index++) {
$reponse = filter_input(INPUT_POST, 'question' . $index, FILTER_UNSAFE_RAW);
if ($reponse !== null) {
$questionsTraitees++;
}
if ($reponse === 'vrai') {
$score++;
$resultatsParQuestion[] = [
'numero' => $index,
'classe' => 'bonne-reponse',
'message' => 'Bonne reponse',
];
} else {
$resultatsParQuestion[] = [
'numero' => $index,
'classe' => 'mauvaise-reponse',
'message' => 'Mauvaise reponse',
];
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="./css/style.css">
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
/>
<title></title>
</head>
<body>
<main>
<h4>Réponses</h4>
</div>
</main>
</body>
<html lang="fr">
<head>
<link rel="stylesheet" href="./css/style.css">
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
/>
<meta charset="UTF-8" />
<title>Exercice 4</title>
</head>
<body>
<main>
<h4>Resultat du quizz</h4>
<?php if ($message !== '') : ?>
<p><?php echo htmlspecialchars($message, ENT_QUOTES, 'UTF-8'); ?></p>
<?php else : ?>
<p>
Vous avez obtenu
<?php echo htmlspecialchars((string) $score, ENT_QUOTES, 'UTF-8'); ?>
bonne(s) reponse(s) sur
<?php echo htmlspecialchars((string) $nombreQuestions, ENT_QUOTES, 'UTF-8'); ?>.
</p>
<p>
Questions repondues :
<?php echo htmlspecialchars((string) $questionsTraitees, ENT_QUOTES, 'UTF-8'); ?>.
</p>
<ul>
<?php foreach ($resultatsParQuestion as $resultatQuestion) : ?>
<li>
Question <?php echo htmlspecialchars((string) $resultatQuestion['numero'], ENT_QUOTES, 'UTF-8'); ?> :
<span class="<?php echo htmlspecialchars($resultatQuestion['classe'], ENT_QUOTES, 'UTF-8'); ?>">
<?php echo htmlspecialchars($resultatQuestion['message'], ENT_QUOTES, 'UTF-8'); ?>
</span>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<p>
<a href="quizz.html">Revenir au quizz</a>
</p>
</main>
</body>
</html>
+37 -15
View File
@@ -1,23 +1,45 @@
<?php
include 'include/controller.php';
include_once 'include/controller.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
/>
<link rel="stylesheet" href="./css/style.css">
<html lang="fr">
<head>
<meta charset="UTF-8" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
/>
<link rel="stylesheet" href="./css/style.css">
<title>Exercice 5</title>
</head>
<body>
<main>
<h3>Conjugaison</h3>
<title></title>
</head>
<body>
<main>
<?php if ($messageErreur !== '') : ?>
<p><?php echo htmlspecialchars($messageErreur, ENT_QUOTES, 'UTF-8'); ?></p>
<?php else : ?>
<p>
Verbe :
<?php echo htmlspecialchars($verbe, ENT_QUOTES, 'UTF-8'); ?>
</p>
</main>
</body>
<?php foreach ($conjugaisons as $conjugaison) : ?>
<section>
<h4><?php echo htmlspecialchars($conjugaison['temps'], ENT_QUOTES, 'UTF-8'); ?></h4>
<ul>
<?php foreach ($conjugaison['formes'] as $forme) : ?>
<li><?php echo htmlspecialchars($forme, ENT_QUOTES, 'UTF-8'); ?></li>
<?php endforeach; ?>
</ul>
</section>
<?php endforeach; ?>
<?php endif; ?>
<p>
<a href="ex5.html">Retour au formulaire</a>
</p>
</main>
</body>
</html>
+58 -6
View File
@@ -1,12 +1,64 @@
<?php
$terminaisons = array(
"present"=>array("e","es","e","ons","ez","ent"),
"futur"=>array("erai","eras","era","erons","erez","eront"),
"imparfait"=>array("ais","ais","ait","ions","iez","aient")
'present' => array('e', 'es', 'e', 'ons', 'ez', 'ent'),
'futur' => array('erai', 'eras', 'era', 'erons', 'erez', 'eront'),
'imparfait' => array('ais', 'ais', 'ait', 'ions', 'iez', 'aient')
);
$pronoms=array("je","tu","il","nous","vous","ils");
$libellesTemps = array(
'present' => 'Present',
'futur' => 'Futur',
'imparfait' => 'Imparfait'
);
$verbe = filter_input(INPUT_POST,"verbe",FILTER_SANITIZE_STRING);
$radical = substr($verbe,0,strlen($verbe)-2);
$pronoms = array('je', 'tu', 'il', 'nous', 'vous', 'ils');
$verbeSaisi = filter_input(INPUT_POST, 'verbe', FILTER_UNSAFE_RAW);
$verbeSaisi = is_string($verbeSaisi) ? trim($verbeSaisi) : '';
$verbe = strtolower($verbeSaisi);
$tempsChoisis = filter_input(INPUT_POST, 'temps', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
$tempsChoisis = is_array($tempsChoisis) ? $tempsChoisis : array();
$messageErreur = '';
$conjugaisons = array();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ($verbe === '') {
$messageErreur = 'Veuillez saisir un verbe.';
} elseif (strlen($verbe) < 3 || substr($verbe, -2) !== 'er') {
$messageErreur = 'Veuillez saisir un verbe du premier groupe.';
} elseif ($tempsChoisis === array()) {
$messageErreur = 'Veuillez choisir au moins un temps.';
} else {
$radical = substr($verbe, 0, strlen($verbe) - 2);
foreach ($tempsChoisis as $temps) {
if (!isset($terminaisons[$temps], $libellesTemps[$temps])) {
continue;
}
$formes = array();
foreach ($pronoms as $index => $pronom) {
$forme = $radical . $terminaisons[$temps][$index];
if ($pronom === 'je' && preg_match('/^[aeiouh]/', $forme) === 1) {
$formes[] = "j'" . $forme;
} else {
$formes[] = $pronom . ' ' . $forme;
}
}
$conjugaisons[] = array(
'temps' => $libellesTemps[$temps],
'formes' => $formes
);
}
if ($conjugaisons === array()) {
$messageErreur = 'Aucun temps valide n a ete transmis.';
}
}
}