PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/pages/supprimer.php

https://bitbucket.org/mw4rf/ajpsc-annuaire
PHP | 112 lines | 79 code | 14 blank | 19 comment | 13 complexity | 66f3d998da91e16f58cb3e3ba8ea1af7 MD5 | raw file
  1. <?php
  2. // Annuaire Alumnii
  3. // Base de données et annuaire d'anciens étudiants.
  4. // Copyright (C) <2006> <Guillaume Florimond>
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. // Première phase: on demande confirmation
  16. if($op == "phase1")
  17. {
  18. ?>
  19. <div align="center">
  20. <?php
  21. if(isadmin()) {
  22. $urlsp = "index.php?action=action_supprimer&op=phase3&id=$id";
  23. } else {
  24. $urlsp = "index.php?action=action_supprimer&op=phase2&id=$id";
  25. }
  26. ?>
  27. <a href = "<?php echo $urlsp; ?>">
  28. <?php
  29. dire("conf-sup");
  30. ?>
  31. </a>
  32. </div>
  33. <?php
  34. }
  35. // Deuxième phase: on demande la réponse à la question secrète...
  36. else if($op == "phase2")
  37. {
  38. connexion();
  39. $sql = "SELECT secret_question FROM utilisateur WHERE id='$id'";
  40. $req = mysql_query($sql) or die('Erreur');
  41. $dat = mysql_fetch_assoc($req);
  42. $question = $dat["secret_question"];
  43. ?>
  44. <form name="supprimer" method="post" action="index.php?action=action_supprimer&op=phase3&id=<?php echo $id; ?>">
  45. <table width="50%" border="0" align="center" cellpadding="2" cellspacing="2">
  46. <tr>
  47. <td colspan="2" align="center">&nbsp;</td>
  48. </tr>
  49. <tr>
  50. <td class="question"><?php dire("s1"); ?></td>
  51. <td><?php echo $question; ?></td>
  52. </tr>
  53. <tr>
  54. <td class="question"><?php dire("s2"); ?></td>
  55. <td>
  56. <input type="text" name="secret_reponse" size="60" />
  57. </td>
  58. </tr>
  59. <tr>
  60. <td colspan="2" align="center">&nbsp;</td>
  61. </tr>
  62. <tr>
  63. <td colspan="2" align="center">
  64. <input type="submit" name="Submit" value="<?php dire("menu2d"); ?>" />
  65. </td>
  66. </tr>
  67. </table>
  68. </form>
  69. <?php
  70. }
  71. // Troisième phase: on supprime l'enregistrement
  72. else if($op == "phase3")
  73. {
  74. //Premier cas: administrateur => procédure rapide
  75. if(isadmin())
  76. {
  77. supprimer($id);
  78. message("ok-sup");
  79. return;
  80. }
  81. //Deuxième cas: utilisateur normal => procédure normale
  82. // On vérifie que la réponse donnée à la phase 2 est exacte.
  83. connexion();
  84. $sql = "SELECT secret_reponse FROM utilisateur WHERE id='$id'";
  85. $req = mysql_query($sql) or die('Erreur');
  86. $dat = mysql_fetch_assoc($req);
  87. if($dat["secret_reponse"] != sha1($_POST["secret_reponse"]))
  88. {
  89. message("sr");
  90. return; // Si cela ne correspond pas, on sort. Sinon, on continue.
  91. }
  92. else
  93. {
  94. supprimer($id);
  95. message("ok-sup");
  96. }
  97. }
  98. ?>