-
Notifications
You must be signed in to change notification settings - Fork 1
/
csv_export.php
58 lines (50 loc) · 1.77 KB
/
csv_export.php
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
// HSTS aktivieren
header("Strict-Transport-Security:max-age=31536000; includeSubdomains");
// Sicherstellen das die Seite über HTTPS aufgerufen wird
function isSSL(){
if($_SERVER['https'] == 1) /* Apache */ {
return TRUE;
} elseif ($_SERVER['https'] == 'on') /* IIS */ {
return TRUE;
} elseif ($_SERVER['SERVER_PORT'] == 443) /* others */ {
return TRUE;
} elseif (!empty($_SERVER['HTTPS'])) {
return TRUE;
} else {
return FALSE; /* just using http */
}
}
if (!isSSL()) {
header('location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
exit();
}
include("src/config.php");
include("src/crypto_helper.php");
$pdo = new PDO('mysql:host='.$host.':'.$port.';dbname='.$dbname, $dbuser, $dbpw);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$privkey = base64_decode($_POST['privkey']);
// get entries
$statement = $pdo->prepare("SELECT `Nachname`,`Email`,`Telefonnummer`,`Anreise`,`Abreise` FROM ".$tablename);
$statement->execute();
$entries = array();
while($row = $statement->fetch(PDO::FETCH_ASSOC)) {
$entries[] = $row;
}
$decentries = array();
loadSPK();
foreach ($entries as $encrypted) {
$decentries[] = [decryptdata($encrypted["Nachname"], $privkey), decryptdata($encrypted["Email"], $privkey), decryptdata($encrypted["Telefonnummer"], $privkey), $encrypted["Anreise"], $encrypted["Abreise"] ?? "0000-00-00 00:00:00"];
}
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=db_export_'.date('Y-m-d').'.csv');
$output = fopen('php://output', 'w');
fputcsv($output, array('Nachname', 'Email', 'Telefonnummer', 'Anreise', 'Abreise'));
foreach ($decentries as $row) {
fputcsv($output, $row);
}
unloadKeys();
unset($privkey);
unset($decentries);
}
?>