cms.lottery-import-inscription.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. ($excelValues[0] != "prest_id") ? alert::recError("La 1er colonne doit se nommer prest_id") : "";
  41. ($excelValues[1] != "doss_id") ? alert::recError("La 2em colonne doit se nommer doss_id") : "";
  42. ($excelValues[2] != "od_matricule") ? alert::recError("La 3em colonne doit se nommer od_matricule") : "";
  43. ($excelValues[3] != "od_prenom") ? alert::recError("La 4em colonne doit se nommer od_prenom") : "";
  44. ($excelValues[4] != "od_nom") ? alert::recError("La 5em colonne doit se nommer od_nom") : "";
  45. ($excelValues[5] != "od_email_prof") ? alert::recError("La 6em colonne doit se nommer od_email_prof") : "";
  46. header("Location: /lottery-".core::getPost("lottery").".html");
  47. exit();
  48. }
  49. $nbSalaries = count($returnXlsx) - 1;
  50. foreach ($returnXlsx as $key => $ligne) {
  51. if($key > 0){
  52. $salarie = salaries::getSalarieByLoginId(strtoupper($ligne[2]));
  53. if(isset($salarie["id"])){
  54. $temp["id_salarie"] = $salarie["id"];
  55. $temp["id_presta"] = $ligne[0];
  56. $temp["id_dossier"] = $ligne[1];
  57. $temp["login"] = $salarie["loginId"];
  58. $temp["prenom"] = $salarie["prenom"];
  59. $temp["nom"] = $salarie["nom"];
  60. $temp["valide"] = $salarie["actif"];
  61. } else {
  62. $temp["id_salarie"] = NULL;
  63. $temp["id_presta"] = $ligne[0];
  64. $temp["id_dossier"] = $ligne[1];
  65. $temp["login"] = $ligne[2];
  66. $temp["prenom"] = $ligne[3];
  67. $temp["nom"] = $ligne[4];
  68. $temp["valide"] = 0;
  69. }
  70. $verifDossierLottery = lottery::searchDossier($temp["id_dossier"]);
  71. if($verifDossierLottery != core::getPost("lottery") AND $verifDossierLottery != NULL){
  72. alert::recError("ERREUR TECHNIQUE : ". $temp["prenom"] . " " . $temp["nom"] . " est déjà inscrit sur un autre tirage au sort");
  73. }
  74. else if($verifDossierLottery == NULL){
  75. if(lottery::insertInscription($temp) == TRUE){
  76. if($temp["valide"] == 1) {
  77. alert::recSuccess("Inscription éligible de " . $temp["prenom"] . " " . $temp["nom"]);
  78. } else {
  79. alert::recWarning("Inscription non éligible de " . $temp["prenom"] . " " . $temp["nom"]);
  80. }
  81. } else {
  82. alert::recError("ERREUR TECHNIQUE : ".$temp["prenom"] . " " . $temp["nom"] . " n'a pas pu être importé");
  83. }
  84. }
  85. else{
  86. if(lottery::updateInscription($temp) == TRUE){
  87. if($temp["valide"] == 1) {
  88. alert::recSuccess("Mise à jour de l'inscription de " . $temp["prenom"] . " " . $temp["nom"]);
  89. } else {
  90. alert::recWarning("Mise à jour de l'inscription non éligible de " . $temp["prenom"] . " " . $temp["nom"]);
  91. }
  92. } else {
  93. alert::recError("ERREUR TECHNIQUE : Mise à jour de l'inscription de " . $temp["prenom"] . " " . $temp["nom"]);
  94. }
  95. }
  96. }
  97. }
  98. header("Location: /lottery-".core::getPost("lottery").".html");
  99. exit();
  100. } else {
  101. alert::recError("Erreur lors du chargement du fichier : " . $_FILES[core::getPost("from")]['name']);
  102. }
  103. }
  104. header("Location: /lottery-".core::getPost("lottery").".html");
  105. exit();
  106. } else {
  107. header('HTTP/1.0 401 Unauthorized');
  108. exit();
  109. }