1 | <?php |
---|
2 | /** |
---|
3 | * @copyright 2005-2007 OpenPNE Project |
---|
4 | * @license http://www.php.net/license/3_01.txt PHP License 3.01 |
---|
5 | */ |
---|
6 | |
---|
7 | class admin_do_csv_member extends OpenPNE_Action |
---|
8 | { |
---|
9 | function handleError($errors) |
---|
10 | { |
---|
11 | admin_client_redirect('csv_download', array_shift($errors)); |
---|
12 | } |
---|
13 | |
---|
14 | function execute($requests) |
---|
15 | { |
---|
16 | $start_id = $requests['start_id']; |
---|
17 | $end_id = $requests['end_id']; |
---|
18 | $allflag = $requests['allflag']; |
---|
19 | |
---|
20 | if (!is_int($start_id) || !is_int($end_id) || !$allflag && ($start_id < 1 || $end_id < 1)) { |
---|
21 | $errors[] = '範囲指定のメンバーIDは1以上の整数値で入力してください'; |
---|
22 | } |
---|
23 | if ($errors) { |
---|
24 | $this->handleError($errors); |
---|
25 | } |
---|
26 | |
---|
27 | $member_key_string = $this->get_key_list(); |
---|
28 | $c_member_list = $this->db_get_c_member_list($start_id,$end_id); |
---|
29 | $member_csv_data = $this->create_csv_data($member_key_string, $c_member_list); |
---|
30 | |
---|
31 | header("Content-Type: application/octet-stream"); |
---|
32 | header("Content-Disposition: attachment; filename=member.csv"); |
---|
33 | echo $member_csv_data; |
---|
34 | exit; |
---|
35 | } |
---|
36 | |
---|
37 | /** |
---|
38 | * メンバーリスト取得 |
---|
39 | */ |
---|
40 | function db_get_c_member_list($start_id,$end_id) |
---|
41 | { |
---|
42 | $params = array(); |
---|
43 | $sql = 'SELECT c_member_id FROM c_member '; |
---|
44 | $sql .= ' WHERE true ' ; |
---|
45 | if ($start_id > 1) { |
---|
46 | $sql .= ' AND c_member_id >= ? '; |
---|
47 | $params[] = $start_id; |
---|
48 | } |
---|
49 | if ($end_id > 0) { |
---|
50 | $sql .= ' AND c_member_id <= ? '; |
---|
51 | $params[] = $end_id; |
---|
52 | } |
---|
53 | $sql .= ' ORDER BY c_member_id'; |
---|
54 | $ids = db_get_col($sql, $params); |
---|
55 | |
---|
56 | $c_member_list = array(); |
---|
57 | foreach ($ids as $id) { |
---|
58 | $tmp_c_member = array(); |
---|
59 | $_tmp_c_member = db_member_c_member4c_member_id($id, false, false, 'private'); |
---|
60 | |
---|
61 | $tmp_c_member['c_member_id'] = $_tmp_c_member['c_member_id']; |
---|
62 | $tmp_c_member['nickname'] = $_tmp_c_member['nickname']; |
---|
63 | if (OPENPNE_USE_POINT_RANK) { |
---|
64 | $tmp_c_member['rank'] = ''; |
---|
65 | $tmp_c_member['PNE_POINT'] = ''; |
---|
66 | } |
---|
67 | $tmp_c_member['access_date'] = $_tmp_c_member['access_date']; |
---|
68 | $tmp_c_member['r_date'] = $_tmp_c_member['r_date']; |
---|
69 | $tmp_c_member['c_member_id_invite'] = $_tmp_c_member['c_member_id_invite']; |
---|
70 | $tmp_c_member['image_filename_1'] = $_tmp_c_member['image_filename_1']; |
---|
71 | $tmp_c_member['image_filename_2'] = $_tmp_c_member['image_filename_2']; |
---|
72 | $tmp_c_member['image_filename_3'] = $_tmp_c_member['image_filename_3']; |
---|
73 | $tmp_c_member['birth_year'] = $_tmp_c_member['birth_year']; |
---|
74 | $tmp_c_member['birth_month'] = $_tmp_c_member['birth_month']; |
---|
75 | $tmp_c_member['birth_day'] = $_tmp_c_member['birth_day']; |
---|
76 | |
---|
77 | $tmp_profile_list = db_member_c_member_profile_list4c_member_id($id, 'private'); |
---|
78 | $c_profile_list = db_member_c_profile_list4null(); |
---|
79 | foreach ($c_profile_list as $key => $tmp_profile) { |
---|
80 | if (is_array($tmp_profile_list[$tmp_profile['name']]['value'])){ |
---|
81 | foreach ($tmp_profile_list[$tmp_profile['name']]['value'] as $itm){ |
---|
82 | $tmp_c_member[$tmp_profile['name']] .= $itm . " "; |
---|
83 | } |
---|
84 | } else { |
---|
85 | $tmp_c_member[$tmp_profile['name']] = $tmp_profile_list[$tmp_profile['name']]['value']; |
---|
86 | } |
---|
87 | } |
---|
88 | if (OPENPNE_USE_POINT_RANK) { |
---|
89 | if (!OPENPNE_IS_POINT_ADMIN && $id == 1) { |
---|
90 | $tmp_c_member['PNE_POINT'] = '-'; |
---|
91 | $tmp_c_member['rank'] = '-'; |
---|
92 | } else { |
---|
93 | $tmp_c_member['PNE_POINT'] = (int)$tmp_c_member['PNE_POINT']; |
---|
94 | $rank = db_point_get_rank4point($tmp_c_member['PNE_POINT']); |
---|
95 | $tmp_c_member['rank'] = $rank['name']; |
---|
96 | } |
---|
97 | } else { |
---|
98 | unset($tmp_c_member['PNE_POINT']); |
---|
99 | } |
---|
100 | |
---|
101 | $tmp_secure = db_member_c_member_secure4c_member_id($id); |
---|
102 | $tmp_c_member['pc_address'] = $tmp_secure['pc_address']; |
---|
103 | $tmp_c_member['ktai_address'] = $tmp_secure['ktai_address']; |
---|
104 | $tmp_c_member['regist_address'] = $tmp_secure['regist_address']; |
---|
105 | |
---|
106 | $c_member_list[]=$tmp_c_member; |
---|
107 | } |
---|
108 | |
---|
109 | return $c_member_list; |
---|
110 | } |
---|
111 | |
---|
112 | function get_key_list() |
---|
113 | { |
---|
114 | $c_profile_list = db_member_c_profile_list4null(); |
---|
115 | |
---|
116 | $ley_list[]="メンバーID"; |
---|
117 | $ley_list[]="ニックネーム"; |
---|
118 | if (OPENPNE_USE_POINT_RANK) { |
---|
119 | $ley_list[] = 'ランク'; |
---|
120 | $ley_list[] = 'ポイント'; |
---|
121 | } |
---|
122 | $ley_list[]="最終ログイン"; |
---|
123 | $ley_list[]="登録日"; |
---|
124 | $ley_list[]="招待者ID"; |
---|
125 | $ley_list[]="画像1"; |
---|
126 | $ley_list[]="画像2"; |
---|
127 | $ley_list[]="画像3"; |
---|
128 | $ley_list[]="誕生年"; |
---|
129 | $ley_list[]="誕生月"; |
---|
130 | $ley_list[]="誕生日"; |
---|
131 | foreach ($c_profile_list as $profile) { |
---|
132 | if ($profile['name'] != 'PNE_POINT') { |
---|
133 | $ley_list[]= $profile['caption']; |
---|
134 | } |
---|
135 | } |
---|
136 | $ley_list[]="PCアドレス"; |
---|
137 | $ley_list[]="携帯アドレス"; |
---|
138 | $ley_list[]="登録時アドレス"; |
---|
139 | |
---|
140 | return $ley_list; |
---|
141 | } |
---|
142 | |
---|
143 | function create_csv_data($key_string, $value_list) |
---|
144 | { |
---|
145 | $csv = ""; |
---|
146 | foreach ($key_string as $each_key) { |
---|
147 | if ($csv != "") { |
---|
148 | $csv .= ","; |
---|
149 | } |
---|
150 | $csv .= '"' . mb_convert_encoding($each_key, 'SJIS', 'auto') . '"'; |
---|
151 | } |
---|
152 | $csv .= "\n"; |
---|
153 | |
---|
154 | foreach ($value_list as $key => $value) { |
---|
155 | $temp = ""; |
---|
156 | foreach ($value as $key2 => $value2) { |
---|
157 | $value2 = mb_convert_encoding($value2, 'SJIS', 'auto'); |
---|
158 | if ($value2 != null) $value2 = str_replace('"', '""', $value2);//クォート |
---|
159 | if ($value2 != null) $value2 = str_replace("\r","",$value2);//改行コードを変換 |
---|
160 | $temp .= '"' . $value2 . '",'; |
---|
161 | } |
---|
162 | $csv .= $temp . "\n"; |
---|
163 | } |
---|
164 | return $csv; |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | ?> |
---|