diff --git a/manager/phpExcel.php b/manager/phpExcel.php index 57d1d03..9453345 100755 --- a/manager/phpExcel.php +++ b/manager/phpExcel.php @@ -112,81 +112,75 @@ function xlsx_switch_lvl1($request, $answer){ /***************************************************************/ /* Importation des listes d'élèves de l'année en format Excel */ /***************************************************************/ - case 'import_userlist_group': + case 'import_inscrits': - if(isset($request->docPath)) { + // Récupération du nom du fichier + $filePath = __ROOT__.'/src/files/'.$_SESSION['identifiant'].'_import_mcc.xlsx'; + + // Chargement du fichier + $objPHPExcel = PHPExcel_IOFactory::load($filePath); + + // Placement du curseur sur la première case + $sheet = $objPHPExcel->getSheet(0); + $userlistData = $sheet->rangeToArray('B2:'.$sheet->getHighestColumn().''.$sheet->getHighestRow()); - // Récupération du nom du fichier - - $inputFileName = $request->docPath; - - // Chargement du fichier - $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); - - // Placement du curseur sur la première case - $sheet = $objPHPExcel->getSheet(0); - $userlistData = $sheet->rangeToArray('B2:'.$sheet->getHighestColumn().''.$sheet->getHighestRow()); - - // Variables stack pour la liste de élèves - $listeFormations = array(); + // Variables stack pour la liste de élèves + $listeFormations = array(); - // "IUT" | formation+ver. | formationCode | formationLibellé | Inscript. en cours | Redoublant | ident. | nom | prenom | sexe | naiss. | mail | sport + // "IUT" | formation+ver. | formationCode | formationLibellé | Inscript. en cours | Redoublant | ident. | nom | prenom | sexe | naiss. | mail | sport - $formationCodes = array(); + $formationCodes = array(); - // on parcourt toutes les lignes pour lesquelles il y a en 2ème cellule "IUT" - foreach($userlistData as $line){ if( $line[0] == 'IUT' ){ + // on parcourt toutes les lignes pour lesquelles il y a en 2ème cellule "IUT" + foreach($userlistData as $line){ if( $line[0] == 'IUT' ){ - /* [1] On récupère la formation (code, libellé) - ========================================================================*/ - if( $line[2] != null && $line[3] != null ){ // si aucune des cases ne sont vides - - if( !in_array($line[2], $formationCodes) ){ // si on n'a toujours pas créé cette formation - array_push( // on ajoute la formation à la liste - $listeFormations, - array( - 'nom' => $line[2], - 'libelle' => $line[3], - 'userlist' => array() // contiendra les étudiants de cette formation - ) - ); - - // on signale pour ne pas répéter - array_push($formationCodes, $line[2]); - } - - - // on récupère l'index de la formation dans le tableau de retour - $formIndex = array_search($line[2], $formationCodes); - - } - - - - /* [2] On ajoute l'élève courant dans la formation - ========================================================================*/ - if( $line[6] != null && $line[7] != null && $line[8] != null && $line[9] != null && $line[1] != null ){ - - array_push( - $listeFormations[$formIndex]['userlist'], array( - 'identifiant' => $line[6], - 'nom' => $line[7], - 'prenom' => $line[8], - 'sexe' => $line[9] == 'M', - 'mail' => $line[11] + /* [1] On récupère la formation (code, libellé) + ========================================================================*/ + if( $line[2] != null && $line[3] != null ){ // si aucune des cases ne sont vides + + if( !in_array($line[2], $formationCodes) ){ // si on n'a toujours pas créé cette formation + array_push( // on ajoute la formation à la liste + $listeFormations, + array( + 'nom' => $line[2], + 'libelle' => $line[3], + 'userlist' => array() // contiendra les étudiants de cette formation ) ); - + + // on signale pour ne pas répéter + array_push($formationCodes, $line[2]); } - - }} - $answer->formationList = $listeFormations; - $answer->request = 'success'; - - }else - $answer->request='param_error'; + + // on récupère l'index de la formation dans le tableau de retour + $formIndex = array_search($line[2], $formationCodes); + + } + + + + /* [2] On ajoute l'élève courant dans la formation + ========================================================================*/ + if( $line[6] != null && $line[7] != null && $line[8] != null && $line[9] != null && $line[1] != null ){ + + array_push( + $listeFormations[$formIndex]['userlist'], array( + 'identifiant' => $line[6], + 'nom' => $line[7], + 'prenom' => $line[8], + 'sexe' => $line[9] == 'M', + 'mail' => $line[11] + ) + ); + + } + + }} + + $answer->formationList = $listeFormations; + $answer->request = 'success'; break; diff --git a/page/_JS/groups.js b/page/_JS/groups.js index 38fec3d..4a424b7 100755 --- a/page/_JS/groups.js +++ b/page/_JS/groups.js @@ -149,4 +149,82 @@ for( var i = 0 ; i < selectList.length ; i++ ){ + + + + + + + + + + + + + + +/********************************/ +/* GESTION DE L'IMPORT DE LISTE */ +/********************************/ +var importInscrits = document.getElementById('import_inscrits'); +if( importInscrits != null ){ + + importInscrits.addEventListener('change', function(e){ + + var annee = parseInt( importInscrits.parentNode.dataset.year ); + var rang = parseInt( importInscrits.parentNode.parentNode.children[5].value ); + + console.log(annee); + console.log(rang); + + addClass( importInscrits.parentNode, 'loading' ); + + var file = importInscrits.files[0]; + + /* [1] IMPORTATION DU FICHIER + =======================================*/ + var fd = new FormData(); + fd.append('filename', 'import_inscrits'); + fd.append('file', file, file.name); + + var xhr = new XMLHttpRequest(); + + xhr.open('POST', 'manager/import.php', true); + + xhr.onreadystatechange = function(){ + if( xhr.readyState == 4 && [0, 200].indexOf(xhr.status) > -1 ) + if( xhr.responseText == 'success' ){ + + + /* [2] LECTURE DU FICHIER + =======================================*/ + var request = { level_0: 'phpExcel', level_1: 'import_inscrits' }; + API.send(request, function(e){ + if( e.request == 'success' ){ + + /* [3] INTÉGRATION À LA BDD + =======================================*/ + requestIntegration = { level_0: 'groups', level_1: 'addUserlist', rang: rang, annee: annee, formationList: e.formationList }; + API.send( requestIntegration, function(f){ + if( f.request == 'success' ){ + console.log('liste intégrée'); + reload(); + }else console.log('integration error'); + }); + + }else console.log('import error'); + }); + + } + + } + + xhr.send(fd); + + }, false); + +} + + + --> \ No newline at end of file diff --git a/page/groups.php b/page/groups.php index c96f4ce..5954708 100755 --- a/page/groups.php +++ b/page/groups.php @@ -662,9 +662,11 @@ if( permission('admin') ){ echo ""; } echo "
"; - echo "
"; + echo "
"; - echo "
Importer une liste
"; + // echo "
Importer une liste
"; + echo "
Importer une liste
"; + echo ""; diff --git a/src/files/admin_import_inscrits.xlsx b/src/files/admin_import_inscrits.xlsx new file mode 100644 index 0000000..bb8094e Binary files /dev/null and b/src/files/admin_import_inscrits.xlsx differ diff --git a/test.php b/test.php index 3743571..e9cb280 100755 --- a/test.php +++ b/test.php @@ -46,13 +46,13 @@ require_once __ROOT__.'/manager/security.php'; debug(); -// $_SESSION['annee'] = 2018; -/* +$_SESSION['annee'] = 2018; + require_once __ROOT__.'/manager/phpExcel.php'; require_once __ROOT__.'/manager/groups.php'; $r1 = new stdClass(); $a1 = new stdClass(); -$r1->level_1 = 'import_userlist_group'; +$r1->level_1 = 'import_inscrits'; $r1->docPath = __ROOT__.'/src/files/modele_import_inscrits.xlsx'; xlsx_switch_lvl1($r1, $a1); @@ -70,7 +70,7 @@ if( $a1->request == 'success' ){ var_dump( $a2 ); } -*/ +