function creerFormEtudiants($n) { global $etudiants; $grp = $etudiants[$n - 1]; $form = ''; for ($i = 0; $i < count($grp); $i++) { $form .= "<div><label for='etu{$i}'>Etudiant " . $grp[$i] . " </label>" . "<input type='text' name='etu{$i}' id='etu{$i}' /></div>\n"; } return "<form action='notesEntrees.php' method='post'><fieldset>\n" . $form . "<input type='hidden' name='grp' value='{$n}' />\n" . "<input type='submit' />\n</fieldset></form>\n"; } echo entete("Saisir Notes"); echo "<body>\n"; if (empty($_GET)) { echo creerForm(); } else { if (isset($_GET['etu_id'])) { $num = intval($_GET['etu_id']); if (!$num) { echo '<div>Le groupe ne peut etre nul</div>'; echo creerForm(); } else { if ($num > MAX_ID) { echo '<div>Numero de groupe trop grand</div>'; echo creerForm(); } else { echo creerFormEtudiants($num); } } } } echo "</body>\n</html>";
$nom = $_POST['nom']; $groupe = $_POST['num_groupe']; } else { $nom = ''; $groupe = ''; } function moyenne($notes) { $somme = 0; foreach ($notes as $note) { $somme += $note; } return $somme / count($notes); } if (!empty($_POST["notes"])) { $result = notesValides($_POST["notes"]); } $title = "Gestion de note"; if (count($result) == count($_POST["notes"])) { echo entete($title); echo "<body><h1>", $title, "</h1>"; echo "<div>Moyenne obtenue : ", moyenne($result), "</div>"; } else { $r = creerFormEtudiants($nom, $groupe, $result); if (!$r) { $r = "Pas de groupe"; $title = "Erreur: {$title}"; } echo entete($title), "<body><h1>", $title, "</h1>", $r; } echo "</body></html>\n";