correction-ulysse #2
@@ -1,23 +1,45 @@
|
|||||||
<?php
|
<?php
|
||||||
include 'include/controller.php';
|
include_once 'include/controller.php';
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
|
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
|
||||||
/>
|
/>
|
||||||
<link rel="stylesheet" href="./css/style.css">
|
<link rel="stylesheet" href="./css/style.css">
|
||||||
|
<title>Exercice 5</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
<h3>Conjugaison</h3>
|
||||||
|
|
||||||
<title></title>
|
<?php if ($messageErreur !== '') : ?>
|
||||||
</head>
|
<p><?php echo htmlspecialchars($messageErreur, ENT_QUOTES, 'UTF-8'); ?></p>
|
||||||
<body>
|
<?php else : ?>
|
||||||
<main>
|
<p>
|
||||||
|
Verbe :
|
||||||
|
<?php echo htmlspecialchars($verbe, ENT_QUOTES, 'UTF-8'); ?>
|
||||||
|
</p>
|
||||||
|
|
||||||
</main>
|
<?php foreach ($conjugaisons as $conjugaison) : ?>
|
||||||
</body>
|
<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>
|
</html>
|
||||||
|
|||||||
@@ -1,12 +1,64 @@
|
|||||||
<?php
|
<?php
|
||||||
$terminaisons = array(
|
$terminaisons = array(
|
||||||
"present"=>array("e","es","e","ons","ez","ent"),
|
'present' => array('e', 'es', 'e', 'ons', 'ez', 'ent'),
|
||||||
"futur"=>array("erai","eras","era","erons","erez","eront"),
|
'futur' => array('erai', 'eras', 'era', 'erons', 'erez', 'eront'),
|
||||||
"imparfait"=>array("ais","ais","ait","ions","iez","aient")
|
'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);
|
$pronoms = array('je', 'tu', 'il', 'nous', 'vous', 'ils');
|
||||||
$radical = substr($verbe,0,strlen($verbe)-2);
|
|
||||||
|
$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.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user