PageRenderTime 61ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/inscription_ajouter.php

https://bitbucket.org/mw4rf/ajpsc-annuaire
PHP | 105 lines | 57 code | 25 blank | 23 comment | 4 complexity | 4f0c15b860f0e4c4841df48f255b4ded 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. //error_reporting(E_ALL);
  16. session_start();
  17. include('includes/config.inc.php');
  18. include('includes/phrases.php');
  19. include('includes/fonctions.inc.php');
  20. include('includes/header.inc.php');
  21. if(!empty($_POST)){
  22. // Connexion
  23. $db = mysql_connect($_config["host"], $_config["user"], $_config["passwd"]);
  24. mysql_select_db($_config["base"],$db);
  25. /* Collecte des données depuis le formulaire */
  26. /* Cela permettra de manipuler ces données, p. ex. pour contrôler leur conformité */
  27. $data["nom"] = addslashes(texte_vers_html(formater_nom($_POST["nom"])));
  28. $data["prenom"] = addslashes(texte_vers_html(formater_nom($_POST["prenom"])));
  29. $data["promotion"] = addslashes(texte_vers_html($_POST["promotion"]));
  30. $data["nationalite"] = addslashes(texte_vers_html($_POST["nationalite"]));
  31. $data["naissance"] = addslashes(texte_vers_html(formater_date($_POST["naissance"])));
  32. $data["adresse"] = addslashes(texte_vers_html($_POST["adresse"]));
  33. $data["email"] = addslashes(texte_vers_html($_POST["email"]));
  34. $data["q1"] = addslashes(texte_vers_html($_POST["q1"]));
  35. $data["q2"] = addslashes(texte_vers_html($_POST["q2"]));
  36. $data["q3"] = addslashes(texte_vers_html($_POST["q3"]));
  37. $data["q4"] = addslashes(texte_vers_html($_POST["q4"]));
  38. $data["q5"] = addslashes(texte_vers_html($_POST["q5"]));
  39. $data["q6"] = addslashes(texte_vers_html($_POST["q6"]));
  40. $data["q7"] = addslashes(texte_vers_html($_POST["q7"]));
  41. $data["secret_question"] = rand() + "--" + rand() + "--" + rand() + "--" + rand() + "--" + rand();
  42. $data["secret_reponse"] = sha1(rand() + "--" + rand() + "--" + rand() + "--" + rand() + "--" + rand());
  43. /* Le champ "modif" représente la date de la dernière modification de la fiche, aujourd'hui*/
  44. $modif = date("Y-m-d");
  45. /* Formulation de la requête */
  46. $sql = "INSERT INTO utilisateur (nom, prenom, promotion, nationalite, naissance, adresse, email, q1, q2, q3, q4, q5, q6, q7, secret_question, secret_reponse, modif) VALUES ('".$data["nom"]."', '".$data["prenom"]."', '".$data["promotion"]."', '".$data["nationalite"]."', '".$data["naissance"]."', '".$data["adresse"]."', '".$data["email"]."', '".$data["q1"]."', '".$data["q2"]."', '".$data["q3"]."', '".$data["q4"]."', '".$data["q5"]."', '".$data["q6"]."', '".$data["q7"]."', '".$data["secret_question"]."', '".$data["secret_reponse"]."', '$modif');";
  47. /* Exécution de la requête */
  48. @mysql_query($sql);
  49. /* Récupération de l'id de l'enregistrement créé */
  50. $sql = "SELECT id FROM utilisateur ORDER BY id DESC";
  51. $req = @mysql_query($sql);
  52. while($data = mysql_fetch_assoc($req))
  53. $id = $data['id'];
  54. //echo "id debug: $id";
  55. /* Photo */
  56. if(!empty($_FILES['image']) and is_numeric($id)) {
  57. @list($width, $height, $imgtype, $strtag) = getimagesize($_FILES['image']['tmp_name']);
  58. switch($imgtype)
  59. {
  60. case 1: $ext = 'gif'; break;
  61. case 2: $ext = 'jpeg'; break;
  62. case 3: $ext = 'png'; break;
  63. default: $ext = false; break;
  64. }
  65. $imgdata = file_get_contents($_FILES['image']['tmp_name']);
  66. $imgdata = addslashes($imgdata); // mysql_real_escape_string seems broken on some configurations...
  67. if(!empty($imgdata)) {
  68. $sql = "INSERT INTO photo SET id='', user_id='$id', photo='$imgdata', extension='$ext', height='$height', width='$width'";
  69. @mysql_query($sql);
  70. }
  71. }
  72. ?>
  73. <div id="corps">Votre fiche a bien &eacute;t&eacute; enregistr&eacute;e, merci !</div>
  74. <?php
  75. } else {
  76. ?>
  77. Vous ne pouvez pas appeler cette page directement.
  78. <?php
  79. }
  80. ?>