diff --git a/R3.01/tp/tp1/ex1/hello-world.php b/R3.01/tp/tp1/ex1/hello-world.php index 11a784f..183c053 100644 --- a/R3.01/tp/tp1/ex1/hello-world.php +++ b/R3.01/tp/tp1/ex1/hello-world.php @@ -1,9 +1,9 @@ - - hello world !!!"; - //phpinfo(); - ?> - + + hello world !!!"; + phpinfo(); + ?> + diff --git a/R3.01/tp/tp1/ex2/index.php b/R3.01/tp/tp1/ex2/index.php index 90e8baa..83fc42a 100644 --- a/R3.01/tp/tp1/ex2/index.php +++ b/R3.01/tp/tp1/ex2/index.php @@ -1,17 +1,19 @@ "Paul", - 2 =>"Martin", - "Arnaud" +$clients = [ + "Luc", + 7 => "Paul", + 2 =>"Martin", + "Arnaud" ]; +var_dump($clients); + $produits = [ - 20 => "Chemise", - 3 => "Pantalon", - 10 => "Jupe", - "Veste", - "Blouson" + 20 => "Chemise", + 3 => "Pantalon", + 10 => "Jupe", + "Veste", + "Blouson" ]; $array = ["a","b","c"]; $array[] = "d"; @@ -23,4 +25,27 @@ print_r($clients); print_r($produits); print_r($array); echo ""; + +// Exercice 2.1 +$tab = []; +$somme = 0; +for ($i = 0; $i < 10; $i++) { + $somme += $i; // somme des entiers de 0 à i + $tab[$i] = $somme; // la clé i contient cette somme +} +print_r($tab); + + +// Exercice 2.2 +for ($debut = 1; $debut <= 50; $debut += 10) { + echo "

"; + for ($i = $debut; $i < $debut + 10; $i++) { + if ($i % 2 === 0) { + echo "$i "; + } else { + echo "$i "; + } + } + echo "

"; +} ?> diff --git a/R3.01/tp/tp1/ex3/index.php b/R3.01/tp/tp1/ex3/index.php index f031367..1dd90cd 100644 --- a/R3.01/tp/tp1/ex3/index.php +++ b/R3.01/tp/tp1/ex3/index.php @@ -1,38 +1,55 @@ - - - - tp1 - ex3 - - - - -
-

Exercice 3 : IMC

- - - - - - - - - - - - + + + + tp1 - ex3 + + + + +
+

Exercice 3 : IMC

+
NomPrénomEmailTaillePoidsIMC
+ + + + + + + + + + + + + + - - -
NomPrénomEmailTaillePoidsIMC
-
- + $imc = null; + if ($tailleM > 0) { + $imc = $poids / ($tailleM * $tailleM); + } + ?> + + + + + + + + + + + + + diff --git a/R3.01/tp/tp1/ex4/index.php b/R3.01/tp/tp1/ex4/index.php index 1db7b37..18c1bbf 100644 --- a/R3.01/tp/tp1/ex4/index.php +++ b/R3.01/tp/tp1/ex4/index.php @@ -1,3 +1,19 @@ + 'dice-six-faces-one.svg', + 2 => 'dice-six-faces-two.svg', + 3 => 'dice-six-faces-three.svg', + 4 => 'dice-six-faces-four.svg', + 5 => 'dice-six-faces-five.svg', + 6 => 'dice-six-faces-six.svg', +]; +?> @@ -13,12 +29,12 @@
-
Tirage aléatoire
+
Tirage aléatoire
- - + Dé 1 : <?= $die1 ?> + Dé 2 : <?= $die2 ?>
-
Somme =
+
Somme =
diff --git a/R3.01/tp/tp1/ex5/index.php b/R3.01/tp/tp1/ex5/index.php index 2fa8b9b..d37bc41 100644 --- a/R3.01/tp/tp1/ex5/index.php +++ b/R3.01/tp/tp1/ex5/index.php @@ -1,5 +1,5 @@ @@ -17,7 +17,7 @@ include './include/favoris.inc.php';

- Exercice 4 : Favoris + Exercice 4 : Favoris

diff --git a/R3.01/tp/tp1/ex6/include/fonction.php b/R3.01/tp/tp1/ex6/include/fonction.php index 10aaf04..2c0856b 100644 --- a/R3.01/tp/tp1/ex6/include/fonction.php +++ b/R3.01/tp/tp1/ex6/include/fonction.php @@ -1,7 +1,7 @@ diff --git a/R3.01/tp/tp1/ex6/index.php b/R3.01/tp/tp1/ex6/index.php index b0fd03c..ee47f8d 100644 --- a/R3.01/tp/tp1/ex6/index.php +++ b/R3.01/tp/tp1/ex6/index.php @@ -1,5 +1,5 @@ diff --git a/R3.01/tp/tp2/ex1/ex1.php b/R3.01/tp/tp2/ex1/ex1.php index 351ce8a..c28dd0f 100644 --- a/R3.01/tp/tp2/ex1/ex1.php +++ b/R3.01/tp/tp2/ex1/ex1.php @@ -1,26 +1,27 @@ - - + + + - - - - - -
- -
- + + + Exercice 1 + + +
+ +
+ diff --git a/R3.01/tp/tp2/ex1/include/controller.php b/R3.01/tp/tp2/ex1/include/controller.php index d8e50ed..07d5eab 100644 --- a/R3.01/tp/tp2/ex1/include/controller.php +++ b/R3.01/tp/tp2/ex1/include/controller.php @@ -1,2 +1,27 @@ ['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']; + } +} diff --git a/R3.01/tp/tp2/ex2/include/controller.php b/R3.01/tp/tp2/ex2/include/controller.php index d8e50ed..d0752bb 100644 --- a/R3.01/tp/tp2/ex2/include/controller.php +++ b/R3.01/tp/tp2/ex2/include/controller.php @@ -1,2 +1,18 @@ $multiplicateur, + 'resultat' => $table * $multiplicateur, + ]; + } +} + diff --git a/R3.01/tp/tp2/ex2/multiplication.php b/R3.01/tp/tp2/ex2/multiplication.php index ef95e58..96c39d9 100644 --- a/R3.01/tp/tp2/ex2/multiplication.php +++ b/R3.01/tp/tp2/ex2/multiplication.php @@ -1,23 +1,47 @@ - - - - - - - -
-

Table de multiplication

-
- - -
-
- + + + + + + Exercice 2 + + +
+

Table de multiplication

+
+ + +
+ + +

+ + + + + +
+ diff --git a/R3.01/tp/tp2/ex3/calculatrice.php b/R3.01/tp/tp2/ex3/calculatrice.php index 5b9b228..2796fd1 100644 --- a/R3.01/tp/tp2/ex3/calculatrice.php +++ b/R3.01/tp/tp2/ex3/calculatrice.php @@ -1,34 +1,59 @@ - - - - - - - -
-

Calculatrice

-
-
- - - - - - -
- + + + Exercice 3 + + + + +
+

Calculatrice

+
+
+ + + + +
+
+ + +

+ + + +

+ Résultat : + +

+ +
+ diff --git a/R3.01/tp/tp2/ex3/include/controller.php b/R3.01/tp/tp2/ex3/include/controller.php index e8fd322..266ba36 100644 --- a/R3.01/tp/tp2/ex3/include/controller.php +++ b/R3.01/tp/tp2/ex3/include/controller.php @@ -1,2 +1,56 @@ $index, + 'classe' => 'bonne-reponse', + 'message' => 'Bonne reponse', + ]; + } else { + $resultatsParQuestion[] = [ + 'numero' => $index, + 'classe' => 'mauvaise-reponse', + 'message' => 'Mauvaise reponse', + ]; + } + } +} +?> - - - - - - - -
-

Réponses

- -
- + + + + + + Exercice 4 + + +
+

Resultat du quizz

+ +

+ +

+ Vous avez obtenu + + bonne(s) reponse(s) sur + . +

+

+ Questions repondues : + . +

+ + +

+ Revenir au quizz +

+
+ diff --git a/R3.01/tp/tp2/ex5/conjuguer.php b/R3.01/tp/tp2/ex5/conjuguer.php index 507d322..e51405d 100644 --- a/R3.01/tp/tp2/ex5/conjuguer.php +++ b/R3.01/tp/tp2/ex5/conjuguer.php @@ -1,23 +1,45 @@ - - - - - + + + + + + Exercice 5 + + +
+

Conjugaison

- - - -
+ +

+ +

+ Verbe : + +

-
- + +
+

+
    + +
  • + +
+
+ + +

+ Retour au formulaire +

+
+ diff --git a/R3.01/tp/tp2/ex5/include/controller.php b/R3.01/tp/tp2/ex5/include/controller.php index f35c02d..f1f8309 100644 --- a/R3.01/tp/tp2/ex5/include/controller.php +++ b/R3.01/tp/tp2/ex5/include/controller.php @@ -1,12 +1,64 @@ 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.'; + } + } +} diff --git a/R3.01/tp/tp3/chifoumi/css/style.css b/R3.01/tp/tp3/chifoumi/css/style.css index 51fbf56..cd05b20 100644 --- a/R3.01/tp/tp3/chifoumi/css/style.css +++ b/R3.01/tp/tp3/chifoumi/css/style.css @@ -8,3 +8,6 @@ color:#2E8B57; .Loss{ color:#FF6347; } +.Draw{ +color:#DAA520; +} diff --git a/R3.01/tp/tp3/chifoumi/index.php b/R3.01/tp/tp3/chifoumi/index.php index 7845b33..7df181a 100644 --- a/R3.01/tp/tp3/chifoumi/index.php +++ b/R3.01/tp/tp3/chifoumi/index.php @@ -1,20 +1,35 @@ [$ROCK => "Draw", $PAPER => "Loss", $SCISSORS => "Win"], + $PAPER => [$ROCK => "Win", $PAPER => "Draw", $SCISSORS => "Loss"], + $SCISSORS => [$ROCK => "Loss", $PAPER => "Win", $SCISSORS => "Draw"], +]; -$message = "Win"; -$class = "Win"; +$playerChoice = filter_input( + INPUT_GET, + 'choice', + FILTER_VALIDATE_INT, + ['options' => ['min_range' => 0, 'max_range' => 2]] +); -$imagePlayer = $images[$playerChoice]; -$imageComputer = $images[$computerChoice]; +$isPlaying = ($playerChoice !== null && $playerChoice !== false); -include './views/header.php'; -if ($isPlaying){ - include './views/game.php'; - include './views/message.php'; +if ($isPlaying) { + $computerChoice = mt_rand(0, 2); + $message = $rules[$playerChoice][$computerChoice]; + $class = $message; + $imagePlayer = $images[$playerChoice]; + $imageComputer = $images[$computerChoice]; } -include './views/footer.php'; -?> + +include_once './views/header.php'; +if ($isPlaying) { + include_once './views/game.php'; + include_once './views/message.php'; +} +include_once './views/footer.php'; diff --git a/R3.01/tp/tp3/cinema/src/films.php b/R3.01/tp/tp3/cinema/src/films.php index b9563da..f85002d 100644 --- a/R3.01/tp/tp3/cinema/src/films.php +++ b/R3.01/tp/tp3/cinema/src/films.php @@ -1,14 +1,37 @@ ['min_range' => 1]] +); + +if ($currentPage === null || $currentPage === false) { + $currentPage = 1; +} + +$perPage = 10; +$data = getFilms($currentPage, $perPage); +$films = $data['films']; +$errorMessage = $data['error']; +$totalFilms = $data['total']; +$totalPages = max(1, (int) ceil($totalFilms / $perPage)); + +if ($currentPage > $totalPages && $totalFilms > 0) { + $currentPage = $totalPages; + $data = getFilms($currentPage, $perPage); + $films = $data['films']; + $errorMessage = $data['error']; + $totalFilms = $data['total']; +} // -// on "charge" la vue +// on "charge" la vue // -include './vues/header.php'; -include './vues/vueFilms.php'; -include './vues/footer.php'; -?> +include_once './vues/header.php'; +include_once './vues/vueFilms.php'; +include_once './vues/footer.php'; diff --git a/R3.01/tp/tp3/cinema/src/modeles/modeleFilms.php b/R3.01/tp/tp3/cinema/src/modeles/modeleFilms.php index 1ca9f2e..34e9e25 100644 --- a/R3.01/tp/tp3/cinema/src/modeles/modeleFilms.php +++ b/R3.01/tp/tp3/cinema/src/modeles/modeleFilms.php @@ -1,16 +1,69 @@ [], + 'total' => 0, + 'error' => 'Connexion MySQL impossible.', + ]; + } + + $page = max(1, (int) $page); + $perPage = max(1, (int) $perPage); + $offset = ($page - 1) * $perPage; + + $sql = "SELECT SQL_CALC_FOUND_ROWS + F.idFilm, + F.titre, + F.annee, + G.code AS genre, + A.prenom, + A.nom + FROM Film AS F + INNER JOIN Artiste AS A ON F.idMes = A.idArtiste + INNER JOIN Genre AS G ON F.genre = G.code + ORDER BY F.titre ASC + LIMIT {$offset}, {$perPage}"; + + $result = mysqli_query($conn, $sql); + if ($result === false) { + return [ + 'films' => [], + 'total' => 0, + 'error' => 'Exécution de la requête impossible.', + ]; + } + + $films = mysqli_fetch_all($result, MYSQLI_ASSOC); + + $totalResult = mysqli_query($conn, 'SELECT FOUND_ROWS() AS total'); + $totalRow = $totalResult ? mysqli_fetch_assoc($totalResult) : ['total' => 0]; + $total = isset($totalRow['total']) ? (int) $totalRow['total'] : 0; + + return [ + 'films' => $films, + 'total' => $total, + 'error' => null, + ]; } -?> diff --git a/R3.01/tp/tp3/cinema/src/vues/vueFilms.php b/R3.01/tp/tp3/cinema/src/vues/vueFilms.php index 6d40687..93f70dd 100644 --- a/R3.01/tp/tp3/cinema/src/vues/vueFilms.php +++ b/R3.01/tp/tp3/cinema/src/vues/vueFilms.php @@ -1,32 +1,64 @@ -

Films

+ +
+ - - - - - - - - - + + + + + + + + + - - - - - "; +foreach ($films as $film) { + $titre = htmlspecialchars($film['titre'], ENT_QUOTES, 'UTF-8'); + $annee = htmlspecialchars((string) $film['annee'], ENT_QUOTES, 'UTF-8'); + $genre = htmlspecialchars($film['genre'], ENT_QUOTES, 'UTF-8'); + $realisateur = htmlspecialchars($film['prenom'] . ' ' . $film['nom'], ENT_QUOTES, 'UTF-8'); + echo " + + + + + + "; } ?> - +
TitreAnnéeGenreRéalisateur
TitreAnnéeGenreRéalisateur
{$film['titre']}{$film['annee']}{$film['genre']}{$film['prenom']} {$film['nom']}
{$titre}{$annee}{$genre}{$realisateur}
+ 1) { ?> + + +