cms.compte-upload.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. if (core::ifPost("from") AND core::getPost("from") == "compte-upload") {
  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'] != "text/csv") {
  19. alert::recError("Seuls les fichiers CSV sont acceptés (".$_FILES[core::getPost("from")]['type'].")");
  20. header("Location: /p=compte-upload&add=".core::getPost("add"));
  21. exit();
  22. } else {
  23. if (file_exists($_FILES[core::getPost("from")]['tmp_name'])) {
  24. if(banque::numberAccountCreditMutuel(core::getPost("compte"), $_FILES[core::getPost("from")]['name']) == FALSE){
  25. alert::recError("Ce CSV " . $_FILES[core::getPost("from")]['name'] . " n'est semble pas correspondre au bon fichier de compte.");
  26. header("Location: /?p=compte-upload&add=".core::getPost("add"));
  27. exit();
  28. }
  29. $csvValue = banque::readCompte($_FILES[core::getPost("from")]);
  30. if($csvValue == FALSE){
  31. historique::recRef("/compte-".core::getPost("add").".html");
  32. historique::add(array(
  33. "idType" => historique::getIdRef("ERROR"),
  34. "idUser" => session::getId(),
  35. "idPage" => historique::getIdRef("/compte-".core::getPost("add").".html"),
  36. "log" => "Erreur lors du chargement du fichier : " . $_FILES[core::getPost("from")]['name']
  37. ));
  38. historique::recordAlert("ERROR");
  39. header("Location: /compte-".core::getPost("add").".html");
  40. exit();
  41. }
  42. $data["md5File"] = file::record($_FILES[core::getPost("from")]);
  43. if($data["md5File"] == FALSE){
  44. alert::recError("Ce CSV " . $_FILES[core::getPost("from")]['name'] . " a déjà été importé.");
  45. header("Location: /compte-historique-csv.html");
  46. exit();
  47. }
  48. // Backup
  49. (backup::create()) ? alert::recSuccess("Backup des données OK") : alert::recError("Backup des données KO");
  50. banque::addMd5CSV($data["md5File"], core::getPost("add"));
  51. // Création du CSV
  52. json::create("banque-csv");
  53. $nbLignes = banque::recordLignes($csvValue, core::getPost("add"));
  54. if($nbLignes == 0){
  55. $log = "Aucune ligne n'a été extraite du fichier : " . $_FILES[core::getPost("from")]['name'];
  56. } elseif($nbLignes == 1){
  57. $log = "Une seule ligne a été extraite du fichier : " . $_FILES[core::getPost("from")]['name'];
  58. } else {
  59. $log = $nbLignes . " lignes ont été extraites du fichier : " . $_FILES[core::getPost("from")]['name'];
  60. }
  61. historique::recRef("/compte-".core::getPost("add").".html");
  62. historique::add(array(
  63. "idType" => historique::getIdRef("ACTION"),
  64. "idUser" => session::getId(),
  65. "idPage" => historique::getIdRef("/compte-".core::getPost("add").".html"),
  66. "log" => $log
  67. ));
  68. historique::recordAlert("SUCCESS");
  69. alert::recSuccess($log);
  70. // Création du CSV
  71. json::create("banque-lignes-".core::getPost("add"));
  72. header("Location: /compte-".core::getPost("add").".html");
  73. exit();
  74. } else {
  75. historique::recRef("/compte-".core::getPost("add").".html");
  76. historique::add(array(
  77. "idType" => historique::getIdRef("ERROR"),
  78. "idUser" => session::getId(),
  79. "idPage" => historique::getIdRef("/compte-".core::getPost("add").".html"),
  80. "log" => "Erreur lors du chargement du fichier : " . $_FILES[core::getPost("from")]['name']
  81. ));
  82. historique::recordAlert("ERROR");
  83. alert::recError("Erreur lors du chargement du fichier : " . $_FILES[core::getPost("from")]['name']);
  84. }
  85. }
  86. header("Location: /compte-".core::getPost("add").".html");
  87. exit();
  88. } else {
  89. header('HTTP/1.0 401 Unauthorized');
  90. exit();
  91. }