Commit 2767f89e authored by Stephane Crozat's avatar Stephane Crozat

Ajout de la fonction d'export CSV (en JS)

parent c2e35acb
......@@ -15,9 +15,7 @@ else {
$view->printHtmlBegin($admin);
$view->printUser($db->isResp($_SESSION['utclogin']), $db->isAdmin($_SESSION['utclogin']));
$view->apiStudents($db->apiStudents($_SESSION['utclogin'],$_GET['api']));
}
?>
function download_csv(students) {
var csv = '';
students.forEach(function(row) {
csv += row.join(',');
csv += "\n";
});
console.log(csv);
var a = document.getElementById('csvlink');
a.href = 'data:text/csv;charset=utf-8,' + encodeURI(csv);
a.target = '_blank';
a.download = 'people.csv';
a.click();
}
......@@ -179,16 +179,26 @@ class Views {
public function apiStudents($students) {
echo "<hr/>";
if (isset($students[0])) {
// Api Title
echo '<h2>'.$this->printApi($students[0]).'</h2>';
// Api mailing list
$mailinglist='mailto:';
foreach ($students as $s) {
$mailinglist = $mailinglist."$s[email],";
}
echo "<div class='menu'><a href='$mailinglist'>[Mailing list]</a></div>";
// Api CSV data (for JavaScript function)
echo '<script src="js/main.js"></script>';
echo "<script>var csvstudents = [['Nom','Prénom','Niveau','Mail','Login'],";
foreach ($students as $s) {
echo "['$s[surname]','$s[firstname]','$s[level]','$s[email]','$s[utclogin]'],";
}
echo "];</script>";
// Api Menu
echo "<div class='menu'><a href='$mailinglist'>[Mailing list]</a> <a id='csvlink' onclick='download_csv(csvstudents)' href=''>[Fichier CSV]</a></div>";
echo "<hr/>";
}
else {
echo '<h2>Aucun inscrit</h2>';
echo '<h2>Aucun inscrit validé</h2>';
}
foreach ($students as $s) {
echo "<div class='student'>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment