forked from elzup/cps_stay
/
out.php
executable file
·77 lines (70 loc) · 2.33 KB
/
out.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
require_once('./modules/functions.php');
$univ_id = @$_GET['univ_id'];
$user_id = @$_GET['user_id'];
$year = @$_GET['y'];
$month = @$_GET['m'];
$room = @$_GET['room_id'];
$teacher = @$_GET['teacher_id'];
$room_codes_r = array(
'8011107B0' => 'cps',
'801140600' => 'crl',
'804051600' => 'crl',
);
$lab = @$room_codes_r[$room] ?: $room;
$is_cache = @$_GET['is_cache'];
if (!$univ_id || !$year || !$room || !$teacher || !isset($month)) {
header("location: ./?e");
exit();
}
if ($is_cache) {
setcookie("univ_id" , $univ_id);
setcookie("user_id" , $user_id);
setcookie("room_id" , $room);
setcookie("teacher_id" , $teacher);
}
if ($month != 0) {
$days = $_GET['day'];
$csv = generate_csv($univ_id, $user_id, $year, $month, $room, substr($room, 0, 3), $teacher, $days);
$filename = "demand_{$year}_{$month}_{$user_id}_{$lab}.CSV";
header('Cache-Control: public');
header('Pragma: public');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'. $filename);
echo $csv;
} else {
$tmp_dir = './tmp/';
$dir_name = "demand_{$univ_id}_{$year}_{$lab}";
// ./tmp/hoge_2014
$tmp_zip_dir = $tmp_dir . $dir_name . "/";
@mkdir($tmp_zip_dir);
// zip module
$zip = new ZipArchive();
$zipname = $dir_name . '.zip';
$zip_path = $tmp_zip_dir . $zipname;
$filenames = array();
if (!file_exists($zip_path)) {
if ($zip->open($zip_path, ZipArchive::CREATE) !==TRUE) {
die('cannot open zipobj');
}
$filenames = array();
$start = 1;
if ($year == date('Y')) {
$start = date('m');
}
foreach (range($start, 12) as $m) {
$csv = generate_csv($univ_id, $user_id, $year, $m, $room, substr($room, 0, 3), $teacher);
$filename = "{$dir_name}/demand_{$year}_{$m}_{$user_id}_{$lab}.CSV";
$tmpfilename = $tmp_zip_dir . $m . '.CSV';
$filenames[] = $tmpfilename;
file_put_contents($tmpfilename, $csv);
$zip->addFile($tmpfilename, $filename);
}
$zip->close();
}
header('Pragma: public');
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=" . $zipname);
readfile($zip_path);
}
//@rmdir($tmp_zip_dir);