1 | <?php |
---|
2 | /** |
---|
3 | * @copyright 2005-2008 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 isSecure() |
---|
10 | { |
---|
11 | session_cache_limiter('public'); |
---|
12 | return true; |
---|
13 | } |
---|
14 | |
---|
15 | function handleError($errors) |
---|
16 | { |
---|
17 | admin_client_redirect('csv_download', array_shift($errors)); |
---|
18 | } |
---|
19 | |
---|
20 | function execute($requests) |
---|
21 | { |
---|
22 | $start_id = $requests['start_id']; |
---|
23 | $end_id = $requests['end_id']; |
---|
24 | $allflag = $requests['allflag']; |
---|
25 | |
---|
26 | $errors = array(); |
---|
27 | if (!$allflag && ($start_id < 1 || $end_id < 1)) { |
---|
28 | $errors[] = '範囲指定のメンバーIDは1以上の整数値で入力してください'; |
---|
29 | } |
---|
30 | if (!$allflag && $start_id > $end_id) { |
---|
31 | $errors[] = '開始メンバーIDは終了メンバーIDより大きい値で入力してください。'; |
---|
32 | } |
---|
33 | if ($errors) { |
---|
34 | $this->handleError($errors); |
---|
35 | } |
---|
36 | |
---|
37 | $member_key_string = $this->get_key_list(); |
---|
38 | $c_member_list = $this->db_get_c_member_list($start_id, $end_id); |
---|
39 | if (!$c_member_list) { |
---|
40 | $this->handleError(array('該当するメンバーの情報がありません。')); |
---|
41 | } |
---|
42 | |
---|
43 | $member_csv_data = $this->create_csv_data($member_key_string, $c_member_list); |
---|
44 | //IE以外の場合、キャッシュをさせないヘッダを出力 |
---|
45 | if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') === false) { |
---|
46 | send_nocache_headers(true); |
---|
47 | } |
---|
48 | header("Content-Type: application/octet-stream"); |
---|
49 | header("Content-Disposition: attachment; filename=member.csv"); |
---|
50 | echo $member_csv_data; |
---|
51 | exit; |
---|
52 | } |
---|
53 | |
---|
54 | /** |
---|
55 | * メンバーリスト取得 |
---|
56 | */ |
---|
57 | function db_get_c_member_list($start_id, $end_id) |
---|
58 | { |
---|
59 | $params = array(); |
---|
60 | $sql = 'SELECT c_member_id FROM c_member'; |
---|
61 | $wheres = array(); |
---|
62 | if ($start_id > 1) { |
---|
63 | $wheres[] = 'c_member_id >= ?'; |
---|
64 | $params[] = $start_id; |
---|
65 | } |
---|
66 | if ($end_id > 0) { |
---|
67 | $wheres[] = 'c_member_id <= ?'; |
---|
68 | $params[] = $end_id; |
---|
69 | } |
---|
70 | if ($wheres) { |
---|
71 | $where = ' WHERE ' . implode(' AND ', $wheres); |
---|
72 | } else { |
---|
73 | $where = ''; |
---|
74 | } |
---|
75 | $sql .= $where; |
---|
76 | $sql .= ' ORDER BY c_member_id'; |
---|
77 | $ids = db_get_col($sql, $params); |
---|
78 | |
---|
79 | $c_member_list = array(); |
---|
80 | foreach ($ids as $id) { |
---|
81 | $tmp_c_member = array(); |
---|
82 | $_tmp_c_member = db_member_c_member4c_member_id($id, true, false, 'private'); |
---|
83 | |
---|
84 | $tmp_c_member['c_member_id'] = $_tmp_c_member['c_member_id']; |
---|
85 | if(OPENPNE_AUTH_MODE == 'pneid') { |
---|
86 | $tmp_c_member['username'] = $_tmp_c_member['username']; |
---|
87 | } |
---|
88 | $tmp_c_member['nickname'] = $_tmp_c_member['nickname']; |
---|
89 | if (OPENPNE_USE_POINT_RANK) { |
---|
90 | $tmp_c_member['rank'] = ''; |
---|
91 | $tmp_c_member['PNE_POINT'] = ''; |
---|
92 | } |
---|
93 | $tmp_c_member['access_date'] = $_tmp_c_member['access_date']; |
---|
94 | $tmp_c_member['r_date'] = $_tmp_c_member['r_date']; |
---|
95 | $tmp_c_member['c_member_id_invite'] = $_tmp_c_member['c_member_id_invite']; |
---|
96 | $tmp_c_member['image_filename_1'] = $_tmp_c_member['image_filename_1']; |
---|
97 | $tmp_c_member['image_filename_2'] = $_tmp_c_member['image_filename_2']; |
---|
98 | $tmp_c_member['image_filename_3'] = $_tmp_c_member['image_filename_3']; |
---|
99 | $tmp_c_member['birth_year'] = $_tmp_c_member['birth_year']; |
---|
100 | $tmp_c_member['birth_month'] = $_tmp_c_member['birth_month']; |
---|
101 | $tmp_c_member['birth_day'] = $_tmp_c_member['birth_day']; |
---|
102 | |
---|
103 | $tmp_profile_list = db_member_c_member_profile_list4c_member_id($id, 'private'); |
---|
104 | $c_profile_list = db_member_c_profile_list4null(); |
---|
105 | foreach ($c_profile_list as $key => $tmp_profile) { |
---|
106 | if (is_array($tmp_profile_list[$tmp_profile['name']]['value'])){ |
---|
107 | foreach ($tmp_profile_list[$tmp_profile['name']]['value'] as $itm){ |
---|
108 | $tmp_c_member[$tmp_profile['name']] .= $itm . " "; |
---|
109 | } |
---|
110 | } else { |
---|
111 | $tmp_c_member[$tmp_profile['name']] = $tmp_profile_list[$tmp_profile['name']]['value']; |
---|
112 | } |
---|
113 | } |
---|
114 | if (OPENPNE_USE_POINT_RANK) { |
---|
115 | if (!OPENPNE_IS_POINT_ADMIN && $id == 1) { |
---|
116 | $tmp_c_member['PNE_POINT'] = '-'; |
---|
117 | $tmp_c_member['rank'] = '-'; |
---|
118 | } else { |
---|
119 | $tmp_c_member['PNE_POINT'] = (int)$tmp_c_member['PNE_POINT']; |
---|
120 | $rank = db_point_get_rank4point($tmp_c_member['PNE_POINT']); |
---|
121 | $tmp_c_member['rank'] = $rank['name']; |
---|
122 | } |
---|
123 | } else { |
---|
124 | unset($tmp_c_member['PNE_POINT']); |
---|
125 | } |
---|
126 | |
---|
127 | $tmp_c_member['pc_address'] = $_tmp_c_member['secure']['pc_address']; |
---|
128 | $tmp_c_member['ktai_address'] = $_tmp_c_member['secure']['ktai_address']; |
---|
129 | $tmp_c_member['regist_address'] = $_tmp_c_member['secure']['regist_address']; |
---|
130 | |
---|
131 | $c_member_list[]=$tmp_c_member; |
---|
132 | } |
---|
133 | |
---|
134 | return $c_member_list; |
---|
135 | } |
---|
136 | |
---|
137 | function get_key_list() |
---|
138 | { |
---|
139 | $c_profile_list = db_member_c_profile_list4null(); |
---|
140 | |
---|
141 | $ley_list[]="メンバーID"; |
---|
142 | if (OPENPNE_AUTH_MODE == 'pneid') { |
---|
143 | $ley_list[] = "ログインID"; |
---|
144 | } |
---|
145 | $ley_list[]=WORD_NICKNAME; |
---|
146 | if (OPENPNE_USE_POINT_RANK) { |
---|
147 | $ley_list[] = 'ランク'; |
---|
148 | $ley_list[] = 'ポイント'; |
---|
149 | } |
---|
150 | $ley_list[]="最終ログイン"; |
---|
151 | $ley_list[]="登録日"; |
---|
152 | $ley_list[]="招待者ID"; |
---|
153 | $ley_list[]="画像1"; |
---|
154 | $ley_list[]="画像2"; |
---|
155 | $ley_list[]="画像3"; |
---|
156 | $ley_list[]="誕生年"; |
---|
157 | $ley_list[]="誕生月"; |
---|
158 | $ley_list[]="誕生日"; |
---|
159 | foreach ($c_profile_list as $profile) { |
---|
160 | if ($profile['name'] != 'PNE_POINT') { |
---|
161 | $ley_list[]= $profile['caption']; |
---|
162 | } |
---|
163 | } |
---|
164 | $ley_list[]="PCメールアドレス"; |
---|
165 | $ley_list[]="携帯メールアドレス"; |
---|
166 | $ley_list[]="登録時メールアドレス"; |
---|
167 | |
---|
168 | return $ley_list; |
---|
169 | } |
---|
170 | |
---|
171 | function create_csv_data($key_string, $value_list) |
---|
172 | { |
---|
173 | $csv = ""; |
---|
174 | foreach ($key_string as $each_key) { |
---|
175 | if ($csv != "") { |
---|
176 | $csv .= ","; |
---|
177 | } |
---|
178 | $csv .= '"' . mb_convert_encoding($each_key, 'SJIS', 'UTF-8') . '"'; |
---|
179 | } |
---|
180 | $csv .= "\n"; |
---|
181 | |
---|
182 | foreach ($value_list as $key => $value) { |
---|
183 | $temp = ""; |
---|
184 | foreach ($value as $key2 => $value2) { |
---|
185 | $value2 = mb_convert_encoding($value2, 'SJIS', 'UTF-8'); |
---|
186 | if ($value2 != null) $value2 = str_replace('"', '""', $value2);//クォート |
---|
187 | if ($value2 != null) $value2 = str_replace("\r","",$value2);//改行コードを変換 |
---|
188 | $temp .= '"' . $value2 . '",'; |
---|
189 | } |
---|
190 | $csv .= $temp . "\n"; |
---|
191 | } |
---|
192 | return $csv; |
---|
193 | } |
---|
194 | } |
---|
195 | |
---|
196 | ?> |
---|