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
|
<?php $page_settings = array( 'formid' => 'Approval', // for permission 'section' => 'Master', // parent/page title 'subsection' => 'Approval List', // page title 'domain' => 'approval_list', // table/model name 'access' => 'GNr', // for permission );
require_once "check_login.php";
// output headers so that the file is downloaded rather than displayed header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=tutor_list.csv'); header("Pragma: no-cache"); header("Expires: 0");
echo "\xEF\xBB\xBF"; // create a file pointer connected to the output stream $output = fopen('php://output', 'w'); // output the column headings
fputcsv($output, array('編號', '狀態', '中文姓名', '英文姓名', '原暱稱', '新暱稱', '性別', '電子郵件', '手提電話', '任教樂器'));
// fetch the data $sql = "select * from tutor_main where deleted = 0 order by id ASC"; $result = bind_pdo($sql, array(), "selectall");
foreach ($result as $row) { $status = ""; if($row{"status"} == 1){ $status = "剛註冊"; }else if($row{"status"} == 2){ $status = "完成電郵驗證"; }else if($row{"status"} == 3){ $status = "等待審核"; }else if($row{"status"} == 4){ $status = "正式導師"; }
$new_nickname = ""; $token = explode(" ", $row{"name_en"});
$last_name = ""; if($row{"gender"}=="m"){ $new_nickname = "Mr. ".ucfirst(strtolower($token[0])); }else if($row{"gender"}=="f"){ $new_nickname = "Ms. ".ucfirst(strtolower($token[0])); }
$row_content = array( '="' . $row{"tutor_no"} . '"', '="' . $status . '"', '="' . $row{"name_en"} . '"', '="' . $row{"name_cn"} . '"', '="' . $row{"nickname"} . '"', '="' . $new_nickname . '"', '="' . ($row{"gender"} == "m" ? "男" : "女") . '"', '="' . aes_crypt($row{'email'}, 2) . '"', '="' . aes_crypt($row{'mobno'}, 2) . '"', );
$sql2 = "select master_type_code.name_cn from tutor_charge inner join master_type_code on master_type_code.id = tutor_charge.mas_instrument where tutor_charge.tutormain_id = ?"; $parameters2 = array($row{"id"}); $result2 = bind_pdo($sql2, $parameters2, "selectall");
if(!empty($result2)){ foreach ($result2 as $row2){ $row_content[] = '="' . $row2{'name_cn'} . '"'; } } fputcsv($output, $row_content); }
fclose($output);
|