Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Stephane Crozat
apisub
Commits
2767f89e
Commit
2767f89e
authored
Feb 08, 2019
by
Stephane Crozat
Browse files
Ajout de la fonction d'export CSV (en JS)
parent
c2e35acb
Changes
3
Hide whitespace changes
Inline
Side-by-side
api.php
View file @
2767f89e
...
...
@@ -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'
]));
}
?>
js/main.js
0 → 100644
View file @
2767f89e
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
();
}
lib/views.php
View file @
2767f89e
...
...
@@ -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'>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment