forked from boombuler/piraten_map_server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.php
More file actions
36 lines (32 loc) · 1.23 KB
/
export.php
File metadata and controls
36 lines (32 loc) · 1.23 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
<?php
include_once('library/System.php');
System::init();
require("includes.php");
if (!$loginok && !System::getCurrentUser()) {
header("location: index.php");
die;
}
if (!filter_input(INPUT_GET, 'city', FILTER_SANITIZE_STRING))
die('Bitte gib eine Stadt ein.');
$filename = '/tmp/' . md5(gmmktime()) . '.csv';
$result = System::query('SELECT COUNT(p.id) plakate, street, type, comment '
. 'FROM ' . System::getConfig('tbl_prefix') . 'felder f '
. 'JOIN ' . System::getConfig('tbl_prefix') . 'plakat p ON p.actual_id=f.id WHERE p.del !=1 AND f.city LIKE ? GROUP BY street, type, comment', array(filter_input(INPUT_GET, 'city', FILTER_SANITIZE_STRING)));
$file = fopen($filename, 'w');
if (!$file)
die('could not open file');
fputcsv($file, array('Anzahl', 'street', 'type', 'comment'), ';');
while ($row = $result->fetch_assoc()) {
fputcsv($file, $row, ';');
}
fclose($file);
header('Content-Description: File Transfer');
header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename=plakate.csv');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Content-Length: ' . filesize($filename));
ob_clean();
flush();
readfile($filename);
unlink($filename);