-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexportcsv.php
More file actions
executable file
·44 lines (36 loc) · 1.16 KB
/
Copy pathexportcsv.php
File metadata and controls
executable file
·44 lines (36 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
require_once dirname(__FILE__) . '/inc.php';
$courseid = required_param('courseid', PARAM_INT);
$quizid = required_param('id', PARAM_INT);
$correct = optional_param('correct', 0, PARAM_INT);
require_login($courseid);
$context = get_context_instance(CONTEXT_SYSTEM);
$quiz = $DB->get_record('quiz', array('id' => $quizid));
if(!block_rk_fragesystem_check_owner($quizid))
error('No permission to do this');
$sql = "SELECT q.*" .
" FROM {$CFG->prefix}question q" .
" WHERE q.id IN ($quiz->questions)";
if (!$questions = $DB->get_records_sql($sql)) {
error('No questions found');
}
header("Content-type: text/x-csv; charset=utf-8");
header("Content-Disposition: attachment; filename=".$quiz->name.".csv");
header("Pragma: no-cache");
header("Expires: 0");
foreach ($questions as $question) {
$answers = $DB->get_records('question_answers', array('question' => $question->id));
if ($answers) {
echo utf8_decode($question->questiontext).";";
foreach($answers as $answer) {
echo utf8_decode($answer->answer).";";
if($correct==1) {
if($answer->fraction > 0)
echo "t;";
else
echo "f;";
}
}
echo "\n";
}
}