cms.lottery-import-inscription.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. if (core::ifPost("from") AND core::getPost("from") == "lottery-import-inscription") {
  3. if(lottery::getCloture(core::getPost("lottery"))["sortDate"] != NULL){
  4. alert::recError("Action annulée car le tirage au sort a déjà été réalisé.");
  5. header("Location: /lottery-".core::getPost("lottery").".html");
  6. exit();
  7. }
  8. if (isset($_FILES[core::getPost("from")]['error']) AND $_FILES[core::getPost("from")]['error'] > 0) {
  9. switch ($_FILES[core::getPost("from")]['error']) {
  10. case 1: // UPLOAD_ERR_INI_SIZE
  11. alert::recError("Le fichier dépasse la limite autorisée par le serveur (fichier php.ini) !");
  12. break;
  13. case 2: // UPLOAD_ERR_FORM_SIZE
  14. alert::recError("Le fichier dépasse la limite autorisée dans le formulaire HTML !");
  15. break;
  16. case 3: // UPLOAD_ERR_PARTIAL
  17. alert::recError("L'envoi du fichier a été interrompu pendant le transfert !");
  18. break;
  19. case 4: // UPLOAD_ERR_NO_FILE
  20. alert::recError("Vous n'avez pas chargé de fichier");
  21. break;
  22. }
  23. } elseif ($_FILES[core::getPost("from")]['type'] != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") {
  24. alert::recError("Seuls les fichiers Excel au format xlsx sont acceptés (".$_FILES[core::getPost("from")]['type'].")");
  25. header("Location: /lottery-".core::getPost("lottery").".html");
  26. exit();
  27. } else {
  28. if (file_exists($_FILES[core::getPost("from")]['tmp_name'])) {
  29. $simpleXLSX = new simpleXLSX();
  30. $xlsx = $simpleXLSX->parse($_FILES[core::getPost("from")]['tmp_name']);
  31. $returnXlsx = $xlsx->rows();
  32. if( $returnXlsx[0][0] != "prest_id"
  33. OR $returnXlsx[0][1] != "doss_id"
  34. OR $returnXlsx[0][2] != "od_matricule"
  35. OR $returnXlsx[0][3] != "od_prenom"
  36. OR $returnXlsx[0][4] != "od_nom"
  37. OR $returnXlsx[0][5] != "od_email_prof"
  38. ){ echo "error";
  39. alert::recError("Le fichier " . $_FILES[core::getPost("from")]['name'] . " n'est pas un fichier d'inscription à un tirage au sort.");
  40. header("Location: /lottery-".core::getPost("lottery").".html");
  41. exit();
  42. }
  43. $nbSalaries = count($returnXlsx) - 1;
  44. foreach ($returnXlsx as $key => $ligne) {
  45. if($key > 0){
  46. $salarie = salaries::get_salarieByLoginId(strtoupper($ligne[2]));
  47. if(isset($salarie["id"])){
  48. $tmp_id_salarie = $salarie["id"];
  49. $tmp_id_presta = $ligne[0];
  50. $tmp_id_dossier = $ligne[1];
  51. $tmp_login = $salarie["loginId"];
  52. $tmp_prenom = $salarie["prenom"];
  53. $tmp_nom = $salarie["nom"];
  54. $tmp_valide = $salarie["actif"];
  55. } else {
  56. $tmp_id_salarie = NULL;
  57. $tmp_id_presta = $ligne[0];
  58. $tmp_id_dossier = $ligne[1];
  59. $tmp_login = $ligne[2];
  60. $tmp_prenom = $ligne[3];
  61. $tmp_nom = $ligne[4];
  62. $tmp_valide = 0;
  63. }
  64. db::query("INSERT INTO " . DB_T_LOTTERY_INSCRITS . "
  65. (
  66. id_lottery,
  67. id_salarie,
  68. id_presta,
  69. id_dossier,
  70. login,
  71. prenom,
  72. nom,
  73. valide,
  74. id_user
  75. )
  76. VALUES
  77. (
  78. :id_lottery,
  79. :id_salarie,
  80. :id_presta,
  81. :id_dossier,
  82. :login,
  83. :prenom,
  84. :nom,
  85. :valide,
  86. :id_user
  87. )
  88. ON DUPLICATE KEY UPDATE
  89. id_salarie = :id_salarie,
  90. login = :login,
  91. prenom = :prenom,
  92. nom = :nom,
  93. valide = :valide");
  94. db::bind(':id_lottery', core::getPost("lottery"));
  95. db::bind(':id_salarie', $tmp_id_salarie);
  96. db::bind(':id_presta', $tmp_id_presta);
  97. db::bind(':id_dossier', $tmp_id_dossier);
  98. db::bind(':login', $tmp_login);
  99. db::bind(':prenom', $tmp_prenom);
  100. db::bind(':nom', $tmp_nom);
  101. db::bind(':valide', $tmp_valide);
  102. db::bind(':id_user', session::getId());
  103. try {
  104. db::execute();
  105. if($tmp_valide == 1) {
  106. alert::recSuccess("Inscription éligible de " . $tmp_prenom . " " . $tmp_nom);
  107. } else {
  108. alert::recError("Inscription non éligible de " . $tmp_prenom . " " . $tmp_nom);
  109. }
  110. } catch (Exception $ex) {
  111. alert::recError("ERREUR TECHNIQUE : ".$tmp_prenom . " " . $tmp_nom . " n'a pas pu être importé");
  112. }
  113. }
  114. }
  115. header("Location: /lottery-".core::getPost("lottery").".html");
  116. exit();
  117. } else {
  118. alert::recError("Erreur lors du chargement du fichier : " . $_FILES[core::getPost("from")]['name']);
  119. }
  120. }
  121. header("Location: /lottery-".core::getPost("lottery").".html");
  122. exit();
  123. } else {
  124. header('HTTP/1.0 401 Unauthorized');
  125. exit();
  126. }