| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- if (core::ifPost("from") and core::getPost("from") == "rh-import-excel") {
- if (isset($_FILES[core::getPost("from")]['error']) and $_FILES[core::getPost("from")]['error'] > 0) {
- switch ($_FILES[core::getPost("from")]['error']) {
- case 1: // UPLOAD_ERR_INI_SIZE
- alert::recError("Le fichier dépasse la limite autorisée par le serveur (fichier php.ini) !");
- break;
- case 2: // UPLOAD_ERR_FORM_SIZE
- alert::recError("Le fichier dépasse la limite autorisée dans le formulaire HTML !");
- break;
- case 3: // UPLOAD_ERR_PARTIAL
- alert::recError("L'envoi du fichier a été interrompu pendant le transfert !");
- break;
- case 4: // UPLOAD_ERR_NO_FILE
- alert::recError("Vous n'avez pas chargé de fichier");
- break;
- }
- } elseif ($_FILES[core::getPost("from")]['type'] != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") {
- alert::recError("Seuls les fichiers Excel au format xlsx sont acceptés");
- header("Location: /rh-upload-excel.html");
- exit();
- } else {
- if (file_exists($_FILES[core::getPost("from")]['tmp_name'])) {
- $data = array();
- // Vérification si le fichier est protégé par mot de passe
- $fileContent = file_get_contents($_FILES[core::getPost("from")]['tmp_name']);
- if (strpos($fileContent, 'EncryptedPackage') !== false || strpos($fileContent, 'encryption') !== false) {
- alert::recError("Le fichier Excel est protégé par un mot de passe. Veuillez retirer la protection avant de l'importer.");
- header("Location: /rh-upload-excel.html");
- exit();
- }
- $simpleXLSX = new simpleXLSX();
- $xlsx = $simpleXLSX->parse($_FILES[core::getPost("from")]['tmp_name']);
- if ($xlsx === false) {
- $errorMsg = simpleXLSX::parseError();
- // Détection spécifique des fichiers protégés par mot de passe
- if (stripos($errorMsg, 'encrypt') !== false || stripos($errorMsg, 'password') !== false) {
- alert::recError("Le fichier Excel est protégé par un mot de passe. Veuillez retirer la protection avant de l'importer.");
- } elseif ($errorMsg) {
- alert::recError("Erreur lors de la lecture du fichier Excel : " . $errorMsg);
- } else {
- alert::recError("Erreur lors de la lecture du fichier Excel : " . $_FILES[core::getPost("from")]['name']);
- }
- header("Location: /rh-upload-excel.html");
- exit();
- }
- $returnXlsx = $xlsx->rows();
- if (
- $returnXlsx[0][0] != "ID LOCAL"
- or $returnXlsx[0][1] != "NOM"
- or $returnXlsx[0][2] != "PRENOM"
- or $returnXlsx[0][3] != "SEXE"
- or $returnXlsx[0][4] != "STATUT ACTIVITE"
- or $returnXlsx[0][5] != "PREMIERE EMBAUCHE"
- or $returnXlsx[0][6] != "SOUS-DOMAINE DU PERSONNEL - TE"
- or $returnXlsx[0][7] != "LOGIN ID"
- ) {
- alert::recError("Le fichier " . $_FILES[core::getPost("from")]['name'] . " n'est pas un fichier RH.");
- ($returnXlsx[0][0] != "ID LOCAL") ? alert::recError("La 1er colonne doit se nommer ID LOCAL") : "";
- ($returnXlsx[0][1] != "NOM") ? alert::recError("La 2em colonne doit se nommer NOM") : "";
- ($returnXlsx[0][2] != "PRENOM") ? alert::recError("La 3em colonne doit se nommer PRENOM") : "";
- ($returnXlsx[0][3] != "SEXE") ? alert::recError("La 4em colonne doit se nommer SEXE") : "";
- ($returnXlsx[0][4] != "STATUT ACTIVITE") ? alert::recError("La 5em colonne doit se nommer STATUT ACTIVITE") : "";
- ($returnXlsx[0][5] != "PREMIERE EMBAUCHE") ? alert::recError("La 6em colonne doit se nommer PREMIERE EMBAUCHE") : "";
- ($returnXlsx[0][6] != "SOUS-DOMAINE DU PERSONNEL - TE") ? alert::recError("La 7em colonne doit se nommer SOUS-DOMAINE DU PERSONNEL - TE") : "";
- ($returnXlsx[0][7] != "LOGIN ID") ? alert::recError("La 8em colonne doit se nommer LOGIN ID") : "";
- header("Location: /rh-upload-excel.html");
- exit();
- }
- $data["md5File"] = file::record($_FILES[core::getPost("from")]);
- if ($data["md5File"] == FALSE) {
- header("Location: /rh-upload-excel.html");
- exit();
- }
- $data["nbSalaries"] = count($returnXlsx) - 1;
- $data["json"] = json_encode($returnXlsx);
- $data["date"] = core::getPost("date");
- if (salaries::insertExcel($data) == FALSE) {
- alert::recError("Erreur #submit sur l'import du fichier " . $_FILES[core::getPost("from")]['name']);
- header("Location: /rh-upload-excel.html");
- exit();
- }
- json::create("excel");
- historique::recRef("/rh-historique-excel.html");
- historique::add(array(
- "idType" => historique::getIdRef("ACTION"),
- "idUser" => session::getId(),
- "idPage" => historique::getIdRef("/rh-historique-excel.html"),
- "log" => "Import du fichier " . $_FILES[core::getPost("from")]['name']
- ));
- alert::recSuccess("Le fichier " . $_FILES[core::getPost("from")]['name'] . " a été chargé avec succès");
- header("Location: /rh-historique-excel.html");
- exit();
- } else {
- alert::recError("Erreur lors du chargement du fichier : " . $_FILES[core::getPost("from")]['name']);
- }
- }
- header("Location: /rh-upload-excel.html");
- exit();
- } else {
- header('HTTP/1.0 401 Unauthorized');
- exit();
- }
|