index.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. require_once "libs/fnMain.php";
  3. /**************************
  4. * VALIDATION DES DONNEES
  5. **************************/
  6. $isClassementValid = isset($_GET["classement"]) && (int) $_GET["classement"] !== 0;
  7. /**************************
  8. * Affichage du formulaire
  9. **************************/
  10. ?>
  11. <!doctype html>
  12. <html lang="fr">
  13. <head>
  14. <meta charset="UTF-8">
  15. <meta name="viewport"
  16. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  17. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  18. <title>RangLimier</title>
  19. <link rel="stylesheet" href="assets/bootstrap.min.css">
  20. <link rel="stylesheet" href="assets/divers.css">
  21. </head>
  22. <body>
  23. <h1>RangLimier</h1>
  24. <p>Cet outil permet, en entrant un classement (réel ou supposé), de voir les choix disponibles à ce classement.</p>
  25. <form action="index.php" method="get">
  26. <label for="classement">Veuillez entrer le classement (réel ou supposé) à tester : </label> <br>
  27. <input type="text" name="classement" <?= ($isClassementValid === TRUE) ? 'value='.(int) $_GET["classement"] : "" ?>>
  28. <button type="submit" class="btn btn-info">Envoyer</button>
  29. </form>
  30. <?php
  31. if ($isClassementValid) {
  32. $html = "<hr><h1>Tableau de classement</h1>";
  33. // On va récupérer tous les rangs limited dispo triés par idChoix
  34. $reqRL = $db->query("SELECT idChoix, annee, rangLimite FROM dataset");
  35. $rangLimites = $reqRL->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
  36. // var_dump($rangLimites);
  37. // Récupération des datasets
  38. $specialityDatasetAbrev = getCsvToArrayKeyValue($_SETTINGS["datasetFolder"]."/liste_specialites_abrev.csv");
  39. $specialityDataset = getCsvToArrayKeyValue($_SETTINGS["datasetFolder"]."/liste_specialites.csv");
  40. $cityDataset = getCsvToArrayKeyValue($_SETTINGS["datasetFolder"]."/liste_villes.csv");
  41. $inputClassement = (int) $_GET["classement"];
  42. // Calcul et affichage des données
  43. // Affichage de la 1ère ligne = Titre des colonnes
  44. $html .= "<table><thead><tr><th></th>";
  45. foreach ($specialityDatasetAbrev as $specialityName) {
  46. $html .= "<th scope='col'>".$specialityName."</th>";
  47. }
  48. $html .= "</tr></thead><tbody>";
  49. // Affichage de la suite du tableau avec le calcul
  50. foreach ($cityDataset as $cityId => $cityName) {
  51. $html .= "<tr><th scope='row'>".$cityName."</th>";
  52. foreach ($specialityDatasetAbrev AS $specialityId => $specialityName) {
  53. $idChoice = "0".$cityId.$specialityId;
  54. if (!isset($rangLimites[$idChoice])) {
  55. $nbAnneePropose = 0;
  56. $nbPossibleAnneePropose = 0;
  57. } else {
  58. $nbAnneePropose = count($rangLimites[$idChoice]);
  59. $nbPossibleAnneePropose = 0;
  60. foreach ($rangLimites[$idChoice] as $rangLimite) {
  61. if ((int) $rangLimite["rangLimite"] >= $inputClassement) {$nbPossibleAnneePropose++;}
  62. }
  63. }
  64. // Affichage de la cellule
  65. $html .= "<td class=\"";
  66. switch (TRUE) {
  67. case ($nbPossibleAnneePropose === 0 && $nbAnneePropose === 0):
  68. $html .= "never-available";
  69. break;
  70. case ($nbPossibleAnneePropose === 0):
  71. $html .= "no-choice";
  72. break;
  73. case ($nbAnneePropose > $nbPossibleAnneePropose && $nbPossibleAnneePropose === 1):
  74. $html .= "last-choice";
  75. break;
  76. case ($nbAnneePropose > $nbPossibleAnneePropose && $nbPossibleAnneePropose !== 1):
  77. $html .= "half-choices";
  78. break;
  79. case ($nbAnneePropose === $nbPossibleAnneePropose):
  80. $html .= "all-choices";
  81. break;
  82. }
  83. $html .= "\">";
  84. if ($nbPossibleAnneePropose > 0) {
  85. $html .= $nbPossibleAnneePropose;
  86. }
  87. $html .= "</td>";
  88. }
  89. $html .= "</tr>";
  90. }
  91. $html .= "</tbody></table><br>";
  92. echo $html;
  93. ?>
  94. <table>
  95. <thead>
  96. <th colspan="5">Légende (sur toutes les années)</th>
  97. </thead>
  98. <tbody>
  99. <tr>
  100. <td>Jamais proposé</td>
  101. <td class="no-choice">Aucun choix</td>
  102. <td class="last-choice">Une seule année</td>
  103. <td class="half-choices">Plusieurs choix</td>
  104. <td class="all-choices">Tous les choix</td>
  105. </tr>
  106. </tbody>
  107. </table>
  108. <br>
  109. <table>
  110. </table>
  111. <?php
  112. }
  113. ?>
  114. </body>
  115. </html>