forked from jurajlapcak/WEBTECH2-final-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsvExport.php
More file actions
44 lines (36 loc) · 1.4 KB
/
Copy pathcsvExport.php
File metadata and controls
44 lines (36 loc) · 1.4 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(__DIR__ . "/classes/controllers/TestLogsController.php");
require_once(__DIR__ . "/classes/controllers/TestController.php");
require_once(__DIR__ . "/classes/controllers/StudentController.php");
if (isset($_GET["id"])) {
$id = $_GET["id"];
$testLogsController = new TestLogsController();
$studentController = new StudentController();
$testController = new TestController();
$tests = $testLogsController->getTestDetail($id);
} else {
header("Location: index.php?role=professor");
die();
}
$code = $testController->getCodeById($id);
$delimiter = ",";
$filename = "hodnotenie_" . $code . ".csv";
//create a file pointer
$f = fopen('php://memory', 'w');
//set column headers
$fields = array('ID', 'Meno', 'Priezvisko', 'Hodnotenie');
fputcsv($f, $fields, $delimiter);
//output each row of the data, format line as csv and write to file pointer
foreach ($tests as $test) {
$student = $studentController->getNameById($test["student_id"]);
$lineData = array($test["student_id"], $student['name'], $student['surname'], $test["evaluation_sum"]);
fputcsv($f, $lineData, $delimiter);
}
//move back to beginning of file
fseek($f, 0);
//set headers to download file rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="' . $filename . '";');
//output all remaining data on a file pointer
fpassthru($f);
exit;