This commit is contained in:
Cedric 2015-11-18 09:48:36 +01:00
parent 5695586a90
commit a45904c751
2 changed files with 77 additions and 43 deletions

View File

@ -0,0 +1,69 @@
<?php
function xlsx_switch_lvl1($request, $answer){
//inclusion des classes de PHPExcel et des fichiers necessaires
require_once __ROOT__.DIRECTORY_SEPARATOR.join(DIRECTORY_SEPARATOR, array("src", "phpexcel", "Classes", "PHPExcel.php"));
require_once __ROOT__.DIRECTORY_SEPARATOR.join(DIRECTORY_SEPARATOR, array("src", "phpexcel", "Classes", "PHPExcel", "Writer", "Excel2007.php"));
//TABLE DE ROUTAGE DE LA FONCTION
switch ($request->level_1) {
//EXPORTATION DES LISTE D'ELEVE DE L'ANNEEE EN FORMAT EXCEL
case 'export_userlist_group':
//On crée une instance du fichier xls, ainsi que de la feuille active
$workbook = new PHPExcel();
$sheet = $workbook->getActiveSheet();
$writer = new PHPExcel_Writer_Excel2007($workbook);
//on prépare le tableau
$sheet->setCellValue('A1', 'IAE Etape');
$sheet->setCellValue('B1', 'Nom');
$sheet->setCellValue('C1', 'Prénom');
$sheet->setCellValue('D1', 'Identifiant');
$sheet->setCellValue('E1', 'Sexe');
$sheet->setCellValue('F1', 'Mail étudiant');
//on récupère l'ensemble des étudiants
$req = new stdClass();
$ans = new stdClass();
$req->level_1 = 'grouplistForYear';
$req->annee = $_SESSION['annee'];
groups_switch_level_1($req, $ans);
//Si l'execution s'est proprement effectuée
$index = 2;
if($ans->req == 'success') {
foreach ($ans->grouplist as $group) {
$groupeName = $group['nom'];
foreach ($group->userlist as $student) {
$sheet->setCellValue('A'.$index, $groupeName);
$sheet->setCellValue('B'.$index, $student['nom']);
$sheet->setCellValue('C'.$index, $student['prenom']);
$sheet->setCellValue('D'.$index, $student['identifiant']);
//$sheet->setCellValue('E'.$index, $student['sexe']);
$sheet->setCellValue('F'.$index, $student['mail']);
$index++;
}
}
}
//On lance le téléchargement du fichier
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="file.xls"');
$writer->save('php://output');
}
break;
default:
# code...
break;
}
}
?>

View File

@ -544,53 +544,18 @@ if( permission('admin') ){ // si l'utilisateur est connecté et que c'est un adm
/*********************************/ /*********************************/
/*** IMPORTATION FICHIER EXCEL ***/ /*** IMPORTATION FICHIER EXCEL ***/
/*********************************/ /*********************************/
// if( permission('admin') ){ if( permission('admin') ){
// echo "<section name='importexcel' title='Importation/Export' class='basic'>";
// //inclusion des classes de PHPExcel require_once __ROOT__.DIRECTORY_SEPARATOR.join(DIRECTORY_SEPARATOR, array("manager", "xlsx.php"));
// include __ROOT__.DIRECTORY_SEPARATOR.join(DIRECTORY_SEPARATOR, array("src", "phpexcel", "Classes", "PHPExcel.php"));
// include __ROOT__.DIRECTORY_SEPARATOR.join(DIRECTORY_SEPARATOR, array("src", "phpexcel", "Classes", "PHPExcel", "Writer", "Excel2007.php"));
// //On crée une instance du fichier xls, ainsi que de la feuille active echo "<section name='importexcel' title='Importation/Export' class='basic'>";
// $workbook = new PHPExcel();
// $sheet = $workbook->getActiveSheet();
// $writer = new PHPExcel_Writer_Excel2007($workbook);
// //on prépare le tableau $answer = new stdClass();
// $sheet->setCellValue('A1', 'IAE Etape'); $request = new stdClass();
// $sheet->setCellValue('B1', 'Nom');
// $sheet->setCellValue('C1', 'Prénom');
// $sheet->setCellValue('D1', 'Identifiant');
// $sheet->setCellValue('E1', 'Sexe');
// $sheet->setCellValue('F1', 'Mail étudiant');
$request->level_1 = 'export_userlist_group';
// //on récupère l'ensemble des étudiants xlsx_switch_lvl1($request, $answer);
// $request = new stdClass();
// $answer = new stdClass();
// $request->level_1 = 'grouplistForYear'; }
// $request->annee = $_SESSION['annee'];
// groups_switch_level_1($request, $answer);
// //Si l'execution s'est proprement effectuée
// $index = 2;
// if($answer->request == 'success') {
// foreach ($answer->grouplist as $group) {
// $groupeName = $group['nom'];
// foreach ($group->userlist as $student) {
// $sheet->setCellValue('A'.$index, $groupeName);
// $sheet->setCellValue('B'.$index, $student['nom']);
// $sheet->setCellValue('C'.$index, $student['prenom']);
// $sheet->setCellValue('D'.$index, $student['identifiant']);
// //$sheet->setCellValue('E'.$index, $student['sexe']);
// $sheet->setCellValue('F'.$index, $student['mail']);
// $index++;
// }
// }
// }
// //On enregistre le fichier
// $writer->save('test.xlsx');
// }
?> ?>