2
0

cms.rh-import-excel.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. if (core::ifPost("from") AND core::getPost("from") == "rh-import-excel") {
  3. if (isset($_FILES[core::getPost("from")]['error']) AND $_FILES[core::getPost("from")]['error'] > 0) {
  4. switch ($_FILES[core::getPost("from")]['error']) {
  5. case 1: // UPLOAD_ERR_INI_SIZE
  6. alert::recError("Le fichier dépasse la limite autorisée par le serveur (fichier php.ini) !");
  7. break;
  8. case 2: // UPLOAD_ERR_FORM_SIZE
  9. alert::recError("Le fichier dépasse la limite autorisée dans le formulaire HTML !");
  10. break;
  11. case 3: // UPLOAD_ERR_PARTIAL
  12. alert::recError("L'envoi du fichier a été interrompu pendant le transfert !");
  13. break;
  14. case 4: // UPLOAD_ERR_NO_FILE
  15. alert::recError("Vous n'avez pas chargé de fichier");
  16. break;
  17. }
  18. } elseif ($_FILES[core::getPost("from")]['type'] != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") {
  19. alert::recError("Seuls les fichiers Excel au format xlsx sont acceptés");
  20. header("Location: /rh-upload-excel.html");
  21. exit();
  22. } else {
  23. if (file_exists($_FILES[core::getPost("from")]['tmp_name'])) {
  24. $data = array();
  25. $simpleXLSX = new simpleXLSX();
  26. $xlsx = $simpleXLSX->parse($_FILES[core::getPost("from")]['tmp_name']);
  27. $returnXlsx = $xlsx->rows();
  28. if( $returnXlsx[0][0] != "ID LOCAL"
  29. OR $returnXlsx[0][1] != "NOM"
  30. OR $returnXlsx[0][2] != "PRENOM"
  31. OR $returnXlsx[0][3] != "SEXE"
  32. OR $returnXlsx[0][4] != "STATUT ACTIVITE"
  33. OR $returnXlsx[0][5] != "PREMIERE EMBAUCHE"
  34. OR $returnXlsx[0][6] != "SOUS-DOMAINE DU PERSONNEL - TE"
  35. OR $returnXlsx[0][7] != "LOGIN ID"){
  36. alert::recError("Le fichier " . $_FILES[core::getPost("from")]['name'] . " n'est pas un fichier RH.");
  37. ($returnXlsx[0][0] != "ID LOCAL") ? alert::recError("La 1er colonne doit se nommer ID LOCAL") : "";
  38. ($returnXlsx[0][1] != "NOM") ? alert::recError("La 2em colonne doit se nommer NOM") : "";
  39. ($returnXlsx[0][2] != "PRENOM") ? alert::recError("La 3em colonne doit se nommer PRENOM") : "";
  40. ($returnXlsx[0][3] != "SEXE") ? alert::recError("La 4em colonne doit se nommer SEXE") : "";
  41. ($returnXlsx[0][4] != "STATUT ACTIVITE") ? alert::recError("La 5em colonne doit se nommer STATUT ACTIVITE") : "";
  42. ($returnXlsx[0][5] != "PREMIERE EMBAUCHE") ? alert::recError("La 6em colonne doit se nommer PREMIERE EMBAUCHE") : "";
  43. ($returnXlsx[0][6] != "SOUS-DOMAINE DU PERSONNEL - TE") ? alert::recError("La 7em colonne doit se nommer SOUS-DOMAINE DU PERSONNEL - TE") : "";
  44. ($returnXlsx[0][7] != "LOGIN ID") ? alert::recError("La 8em colonne doit se nommer LOGIN ID") : "";
  45. header("Location: /rh-upload-excel.html");
  46. exit();
  47. }
  48. $data["md5File"] = file::record($_FILES[core::getPost("from")]);
  49. if($data["md5File"] == FALSE){
  50. header("Location: /rh-upload-excel.html");
  51. exit();
  52. }
  53. $data["nbSalaries"] = count($returnXlsx) - 1;
  54. $data["json"] = json_encode($returnXlsx);
  55. $data["date"] = core::getPost("date");
  56. if(salaries::insertExcel($data) == FALSE){
  57. alert::recError("Erreur #submit sur l'import du fichier " . $_FILES[core::getPost("from")]['name']);
  58. header("Location: /rh-upload-excel.html");
  59. exit();
  60. }
  61. json::create("excel");
  62. alert::recSuccess("Le fichier " . $_FILES[core::getPost("from")]['name'] . " a été chargé avec succès");
  63. header("Location: /rh-historique-excel.html");
  64. exit();
  65. } else {
  66. alert::recError("Erreur lors du chargement du fichier : " . $_FILES[core::getPost("from")]['name']);
  67. }
  68. }
  69. header("Location: /rh-upload-excel.html");
  70. exit();
  71. } else {
  72. header('HTTP/1.0 401 Unauthorized');
  73. exit();
  74. }