index.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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, initial-scale=1.0">
  17. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  18. <title>RangLimier</title>
  19. <link rel="icon" type="image/png" href="assets/favicon.png">
  20. <link rel="stylesheet" href="assets/fonts/material-icons.min.css">
  21. <link rel="stylesheet" href="assets/bootstrap.min.css">
  22. <link rel="stylesheet" href="assets/divers.css">
  23. <!-- Font Awesome icons (free version)-->
  24. <script src="https://use.fontawesome.com/releases/v5.15.1/js/all.js" crossorigin="anonymous"></script>
  25. <!-- Google fonts-->
  26. <link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css" />
  27. <link href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic" rel="stylesheet" type="text/css" />
  28. </head>
  29. <body>
  30. <div id="navbar">
  31. <nav id="mainNav" class="navbar navbar-expand-lg text-uppercase sticky-top">
  32. <div class="container">
  33. <a href="https://asclepia.io/" class="navbar-brand">
  34. <div class="text-lowercase" style="font-family: no-name;">asclepia</div>
  35. </a>
  36. <button type="button" data-toggle="collapse" data-target="#navbarResponsive"
  37. aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation"
  38. class="navbar-toggler navbar-toggler-right text-uppercase font-weight-bold bg-primary text-white rounded collapsed">
  39. Menu
  40. <svg class="svg-inline--fa fa-bars fa-w-14" aria-hidden="true" focusable="false"
  41. data-prefix="fas" data-icon="bars" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"
  42. data-fa-i2svg="">
  43. <path fill="currentColor"
  44. d="M16 132h416c8.837 0 16-7.163 16-16V76c0-8.837-7.163-16-16-16H16C7.163 60 0 67.163 0 76v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16z"></path>
  45. </svg>
  46. </button>
  47. <div id="navbarResponsive" class="navbar-collapse collapse" style="">
  48. <ul class="navbar-nav ml-auto">
  49. <li class="nav-item mx-0 mx-lg-1">
  50. <a href="https://asclepia.io/utilisateur" class="nav-link py-3 px-0 px-lg-3 rounded js-scroll-trigger">Se connecter</a>
  51. </li>
  52. <li class="nav-item mx-0 mx-lg-1">
  53. <a href="https://asclepia.io/inscription" class="nav-link py-3 px-0 px-lg-3 rounded js-scroll-trigger">Découvrir</a>
  54. </li>
  55. </ul>
  56. </div>
  57. </div>
  58. </nav>
  59. </div>
  60. <div id="rangLimier">
  61. <h1>RangLimier</h1>
  62. <p>Cet outil permet, en entrant un classement (réel ou supposé), de voir les choix disponibles à ce classement. <br>
  63. <i>Attention : Cet outil est à but purement indicatif, les variations entre chaque année sont imprévisibles. Cela vous sert à avoir une vision globale des choix possible</i>
  64. </p>
  65. <form action="index.php" method="get">
  66. <label for="classement">Veuillez entrer le classement (réel ou supposé) à tester : </label> <br>
  67. <input type="text" name="classement" <?= ($isClassementValid === TRUE) ? 'value='.(int) $_GET["classement"] : "" ?>>
  68. <button type="submit" class="btn btn-info">Envoyer</button>
  69. </form>
  70. <?php if ($isClassementValid) : ?>
  71. <hr><h1>Tableau de classement</h1>
  72. <h2>Légende</h2>
  73. <table>
  74. <thead>
  75. <th colspan="5" style="text-align: center;">Légende (sur toutes les années)</th>
  76. </thead>
  77. <tbody>
  78. <tr>
  79. <td class="never-available">Jamais proposé</td>
  80. <td class="no-choice">Aucun choix</td>
  81. <td class="last-choice">Une seule année</td>
  82. <td class="half-choices">Plusieurs choix</td>
  83. <td class="all-choices">Tous les choix</td>
  84. </tr>
  85. </tbody>
  86. </table>
  87. <p>
  88. Chaque nombre dans chaque case correspond au nombre d'années où ce choix était dispo au classement rentré <br>
  89. </p>
  90. <?php
  91. $html = "<h2>Résultats</h2>";
  92. // On va récupérer tous les rangs limited dispo triés par idChoix
  93. //Mysql
  94. $reqRL = $db->query('SELECT idChoix, annee, rangLimite FROM dataset');
  95. //pgsql
  96. // $reqRL = $db->query('SELECT dataset."idChoix", annee, dataset."rangLimite" FROM dataset');
  97. $rangLimites = $reqRL->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
  98. // Récupération des datasets
  99. $specialityDatasetAbrev = getCsvToArrayKeyValue($_SETTINGS["datasetFolder"]."/liste_specialites_abrev.csv");
  100. $specialityDataset = getCsvToArrayKeyValue($_SETTINGS["datasetFolder"]."/liste_specialites.csv");
  101. $cityDataset = getCsvToArrayKeyValue($_SETTINGS["datasetFolder"]."/liste_villes.csv");
  102. $inputClassement = (int) $_GET["classement"];
  103. // Calcul et affichage des données
  104. // Affichage de la 1ère ligne = Titre des colonnes
  105. $html .= "<table><thead><tr><th></th>";
  106. foreach ($specialityDatasetAbrev as $specialityName) {
  107. $html .= "<th scope='col'>".$specialityName."</th>";
  108. }
  109. $html .= "</tr></thead><tbody>";
  110. // Affichage de la suite du tableau avec le calcul
  111. foreach ($cityDataset as $cityId => $cityName) {
  112. // On gère la séparation des différentes régions entre elles (représentées dans le csv villes par les lignes XX_:XX)
  113. // La notation des lignes de séparation est sous forme XX_x car si on laissait XX, la fonction getCsvToArrayKeyValue
  114. // ne retourne la position que pour la 1ère occurence de XX;XX
  115. // La manière de fix ça de manière la plus opti et sale, c'est de faire un substr et de tester les 2 premiers charactères
  116. // si ils sont égaux à XX, on fait une séparation
  117. // TODO : Faire un parseur csv qui prend en compte chaque ligne du csv dans l'ordre du fichier
  118. if (strpos($cityId, "XX") !== FALSE) {
  119. $html .= "<tr><th></th>";
  120. foreach ($specialityDatasetAbrev as $specialityName) {
  121. $html .= "<th scope='col'>".$specialityName."</th>";
  122. }
  123. $html .= "</th>";
  124. continue;
  125. }
  126. $html .= "<tr><th scope='row'>".$cityName."</th>";
  127. foreach ($specialityDatasetAbrev AS $specialityId => $specialityName) {
  128. $idChoice = "0".$cityId.$specialityId;
  129. if (!isset($rangLimites[$idChoice])) {
  130. $nbAnneePropose = 0;
  131. $nbPossibleAnneePropose = 0;
  132. } else {
  133. $nbAnneePropose = count($rangLimites[$idChoice]);
  134. $nbPossibleAnneePropose = 0;
  135. foreach ($rangLimites[$idChoice] as $rangLimite) {
  136. if ((int) $rangLimite["rangLimite"] >= $inputClassement) {$nbPossibleAnneePropose++;}
  137. }
  138. }
  139. // Affichage de la cellule
  140. $html .= "<td class=\"";
  141. switch (TRUE) {
  142. case ($nbPossibleAnneePropose === 0 && $nbAnneePropose === 0):
  143. $html .= "never-available";
  144. break;
  145. case ($nbPossibleAnneePropose === 0):
  146. $html .= "no-choice";
  147. break;
  148. case ($nbAnneePropose > $nbPossibleAnneePropose && $nbPossibleAnneePropose === 1):
  149. $html .= "last-choice";
  150. break;
  151. case ($nbAnneePropose > $nbPossibleAnneePropose && $nbPossibleAnneePropose !== 1):
  152. $html .= "half-choices";
  153. break;
  154. case ($nbAnneePropose === $nbPossibleAnneePropose):
  155. $html .= "all-choices";
  156. break;
  157. }
  158. $html .= "\">";
  159. if ($nbPossibleAnneePropose > 0) {
  160. $html .= $nbPossibleAnneePropose;
  161. } else if ($nbPossibleAnneePropose === 0 && $nbAnneePropose !== 0) {
  162. $html .= "0";
  163. }
  164. $html .= "</td>";
  165. }
  166. $html .= "</tr>";
  167. }
  168. $html .= "</tbody></table><br>";
  169. echo $html;
  170. ?>
  171. <table>
  172. </table>
  173. <?php endif;?>
  174. </div>
  175. <!-- Bootstrap core JS-->
  176. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  177. <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js"></script>
  178. </body>
  179. </html>