| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- if (core::ifPost("from") AND core::getPost("from") == "lottery-import-inscription") {
- if(lottery::getCloture(core::getPost("lottery"))["sortDate"] != NULL){
- alert::recError("Action annulée car le tirage au sort a déjà été réalisé.");
- header("Location: /lottery-".core::getPost("lottery").".html");
- exit();
- }
- 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 (".$_FILES[core::getPost("from")]['type'].")");
- header("Location: /lottery-".core::getPost("lottery").".html");
- exit();
- } else {
- if (file_exists($_FILES[core::getPost("from")]['tmp_name'])) {
- $simpleXLSX = new simpleXLSX();
- $xlsx = $simpleXLSX->parse($_FILES[core::getPost("from")]['tmp_name']);
- $returnXlsx = $xlsx->rows();
- if( $returnXlsx[0][0] != "prest_id"
- OR $returnXlsx[0][1] != "doss_id"
- OR $returnXlsx[0][2] != "od_matricule"
- OR $returnXlsx[0][3] != "od_prenom"
- OR $returnXlsx[0][4] != "od_nom"
- OR $returnXlsx[0][5] != "od_email_prof"
- ){ echo "error";
- alert::recError("Le fichier " . $_FILES[core::getPost("from")]['name'] . " n'est pas un fichier d'inscription à un tirage au sort.");
- ($excelValues[0] != "prest_id") ? alert::recError("La 1er colonne doit se nommer prest_id") : "";
- ($excelValues[1] != "doss_id") ? alert::recError("La 2em colonne doit se nommer doss_id") : "";
- ($excelValues[2] != "od_matricule") ? alert::recError("La 3em colonne doit se nommer od_matricule") : "";
- ($excelValues[3] != "od_prenom") ? alert::recError("La 4em colonne doit se nommer od_prenom") : "";
- ($excelValues[4] != "od_nom") ? alert::recError("La 5em colonne doit se nommer od_nom") : "";
- ($excelValues[5] != "od_email_prof") ? alert::recError("La 6em colonne doit se nommer od_email_prof") : "";
-
- header("Location: /lottery-".core::getPost("lottery").".html");
- exit();
- }
- $nbSalaries = count($returnXlsx) - 1;
-
- foreach ($returnXlsx as $key => $ligne) {
- if($key > 0){
- $salarie = salaries::getSalarieByLoginId(strtoupper($ligne[2]));
- if(isset($salarie["id"])){
- $temp["id_salarie"] = $salarie["id"];
- $temp["id_presta"] = $ligne[0];
- $temp["id_dossier"] = $ligne[1];
- $temp["login"] = $salarie["loginId"];
- $temp["prenom"] = $salarie["prenom"];
- $temp["nom"] = $salarie["nom"];
- $temp["valide"] = $salarie["actif"];
- } else {
- $temp["id_salarie"] = NULL;
- $temp["id_presta"] = $ligne[0];
- $temp["id_dossier"] = $ligne[1];
- $temp["login"] = $ligne[2];
- $temp["prenom"] = $ligne[3];
- $temp["nom"] = $ligne[4];
- $temp["valide"] = 0;
- }
- $verifDossierLottery = lottery::searchDossier($temp["id_dossier"]);
- if($verifDossierLottery != core::getPost("lottery") AND $verifDossierLottery != NULL){
- alert::recError("ERREUR TECHNIQUE : ". $temp["prenom"] . " " . $temp["nom"] . " est déjà inscrit sur un autre tirage au sort");
- }
- else if($verifDossierLottery == NULL){
- if(lottery::insertInscription($temp) == TRUE){
- if($temp["valide"] == 1) {
- alert::recSuccess("Inscription éligible de " . $temp["prenom"] . " " . $temp["nom"]);
- } else {
- alert::recWarning("Inscription non éligible de " . $temp["prenom"] . " " . $temp["nom"]);
- }
- } else {
- alert::recError("ERREUR TECHNIQUE : ".$temp["prenom"] . " " . $temp["nom"] . " n'a pas pu être importé");
- }
- }
- else{
- if(lottery::updateInscription($temp) == TRUE){
- if($temp["valide"] == 1) {
- alert::recSuccess("Mise à jour de l'inscription de " . $temp["prenom"] . " " . $temp["nom"]);
- } else {
- alert::recWarning("Mise à jour de l'inscription non éligible de " . $temp["prenom"] . " " . $temp["nom"]);
- }
- } else {
- alert::recError("ERREUR TECHNIQUE : Mise à jour de l'inscription de " . $temp["prenom"] . " " . $temp["nom"]);
- }
- }
- }
- }
-
- header("Location: /lottery-".core::getPost("lottery").".html");
- exit();
- } else {
- alert::recError("Erreur lors du chargement du fichier : " . $_FILES[core::getPost("from")]['name']);
- }
- }
- header("Location: /lottery-".core::getPost("lottery").".html");
- exit();
- } else {
- header('HTTP/1.0 401 Unauthorized');
- exit();
- }
|