cms.lottery-import-inscription.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. $temp["id_salarie"] = $salarie["id"];
  49. $temp["id_presta"] = $ligne[0];
  50. $temp["id_dossier"] = $ligne[1];
  51. $temp["login"] = $salarie["loginId"];
  52. $temp["prenom"] = $salarie["prenom"];
  53. $temp["nom"] = $salarie["nom"];
  54. $temp["valide"] = $salarie["actif"];
  55. } else {
  56. $temp["id_salarie"] = NULL;
  57. $temp["id_presta"] = $ligne[0];
  58. $temp["id_dossier"] = $ligne[1];
  59. $temp["login"] = $ligne[2];
  60. $temp["prenom"] = $ligne[3];
  61. $temp["nom"] = $ligne[4];
  62. $temp["valide"] = 0;
  63. }
  64. $verifDossierLottery = lottery::searchDossier($temp["id_dossier"]);
  65. if($verifDossierLottery != core::getPost("lottery")){
  66. alert::recError("ERREUR TECHNIQUE : ". $temp["prenom"] . " " . $temp["nom"] . " est déjà inscrit sur un autre tirage au sort");
  67. }
  68. else if($verifDossierLottery == NULL){
  69. if(lottery::insertInscription($temp) == TRUE){
  70. if($temp["valide"] == 1) {
  71. alert::recSuccess("Inscription éligible de " . $temp["prenom"] . " " . $temp["nom"]);
  72. } else {
  73. alert::recWarning("Inscription non éligible de " . $temp["prenom"] . " " . $temp["nom"]);
  74. }
  75. } else {
  76. alert::recError("ERREUR TECHNIQUE : ".$temp["prenom"] . " " . $temp["nom"] . " n'a pas pu être importé");
  77. }
  78. }
  79. else{
  80. if(lottery::updateInscription($temp) == TRUE){
  81. if($temp["valide"] == 1) {
  82. alert::recSuccess("Mise à jour de l'inscription de " . $temp["prenom"] . " " . $temp["nom"]);
  83. } else {
  84. alert::recWarning("Mise à jour de l'inscription non éligible de " . $temp["prenom"] . " " . $temp["nom"]);
  85. }
  86. } else {
  87. alert::recError("ERREUR TECHNIQUE : Mise à jour de l'inscription de " . $temp["prenom"] . " " . $temp["nom"]);
  88. }
  89. }
  90. }
  91. }
  92. header("Location: /lottery-".core::getPost("lottery").".html");
  93. exit();
  94. } else {
  95. alert::recError("Erreur lors du chargement du fichier : " . $_FILES[core::getPost("from")]['name']);
  96. }
  97. }
  98. header("Location: /lottery-".core::getPost("lottery").".html");
  99. exit();
  100. } else {
  101. header('HTTP/1.0 401 Unauthorized');
  102. exit();
  103. }