PluginProbe
Welcart e-Commerce / 2.12.4
Welcart e-Commerce v2.12.4
2.12.4 2.12.3 2.11.35 2.12.2 2.12.1 2.11.34 2.11.33 2.11.32 2.11.31 2.11.30 1.3.16 1.3.17 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 All 292 releases
← All changes | functions/utility.php +1835 -2066 1.3.172.12.4 View file →
@@ -1,2066 +1,1835 @@
1 -<?php
2 -// Utility.php
3 -
4 -function usces_upgrade_07(){
5 - $upgrade = (int)get_option('usces_upgrade');
6 - if( $upgrade & USCES_UP07 ) return false;
7 -
8 - global $wpdb;
9 - $rets = array();
10 -
11 - $tableName = $wpdb->prefix . "postmeta";
12 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'iopt_', '_iopt_') WHERE meta_key LIKE 'iopt_%'";
13 - if( $wpdb->query( $mquery ) )
14 - $rets[] = 1;
15 -
16 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'isku_', '_isku_') WHERE meta_key LIKE 'isku_%'";
17 - if( $wpdb->query( $mquery ) )
18 - $rets[] = 1;
19 -
20 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemCode', '_itemCode') WHERE meta_key LIKE 'itemCode'";
21 - if( $wpdb->query( $mquery ) )
22 - $rets[] = 1;
23 -
24 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemName', '_itemName') WHERE meta_key LIKE 'itemName'";
25 - if( $wpdb->query( $mquery ) )
26 - $rets[] = 1;
27 -
28 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemRestriction', '_itemRestriction') WHERE meta_key LIKE 'itemRestriction'";
29 - if( $wpdb->query( $mquery ) )
30 - $rets[] = 1;
31 -
32 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemPointrate', '_itemPointrate') WHERE meta_key LIKE 'itemPointrate'";
33 - if( $wpdb->query( $mquery ) )
34 - $rets[] = 1;
35 -
36 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemGpNum1', '_itemGpNum1') WHERE meta_key LIKE 'itemGpNum1'";
37 - if( $wpdb->query( $mquery ) )
38 - $rets[] = 1;
39 -
40 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemGpDis1', '_itemGpDis1') WHERE meta_key LIKE 'itemGpDis1'";
41 - if( $wpdb->query( $mquery ) )
42 - $rets[] = 1;
43 -
44 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemGpNum2', '_itemGpNum2') WHERE meta_key LIKE 'itemGpNum2'";
45 - if( $wpdb->query( $mquery ) )
46 - $rets[] = 1;
47 -
48 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemGpDis2', '_itemGpDis2') WHERE meta_key LIKE 'itemGpDis2'";
49 - if( $wpdb->query( $mquery ) )
50 - $rets[] = 1;
51 -
52 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemGpDis3', '_itemGpDis3') WHERE meta_key LIKE 'itemGpDis3'";
53 - if( $wpdb->query( $mquery ) )
54 - $rets[] = 1;
55 -
56 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemGpNum3', '_itemGpNum3') WHERE meta_key LIKE 'itemGpNum3'";
57 - if( $wpdb->query( $mquery ) )
58 - $rets[] = 1;
59 -
60 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemShipping', '_itemShipping') WHERE meta_key LIKE 'itemShipping'";
61 - if( $wpdb->query( $mquery ) )
62 - $rets[] = 1;
63 -
64 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemDeliveryMethod', '_itemDeliveryMethod') WHERE meta_key LIKE 'itemDeliveryMethod'";
65 - if( $wpdb->query( $mquery ) )
66 - $rets[] = 1;
67 -
68 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemShippingCharge', '_itemShippingCharge') WHERE meta_key LIKE 'itemShippingCharge'";
69 - if( $wpdb->query( $mquery ) )
70 - $rets[] = 1;
71 -
72 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemIndividualSCharge', '_itemIndividualSCharge') WHERE meta_key LIKE 'itemIndividualSCharge'";
73 - if( $wpdb->query( $mquery ) )
74 - $rets[] = 1;
75 -
76 - usces_log('USCES_UP07 : '.print_r($rets,true), 'database_error.log');
77 - $upgrade += USCES_UP07;
78 - update_option('usces_upgrade', $upgrade);
79 - return $rets;
80 -}
81 -
82 -function usces_upgrade_11(){
83 - $options = get_option('usces');
84 - $upgrade = (int)get_option('usces_upgrade');
85 -
86 - if( $upgrade & USCES_UP11 ) return false;
87 -
88 - global $wpdb;
89 - $rets = array();
90 -
91 - /* ITEM SKU DATA */
92 - $sort = (int)$options['system']['orderby_itemsku'];
93 - if( $sort ){
94 - $query = "SELECT * FROM $wpdb->postmeta WHERE meta_key <> '_isku_' AND meta_key LIKE '_isku_%' ORDER BY post_id, meta_key";
95 - }else{
96 - $query = "SELECT * FROM $wpdb->postmeta WHERE meta_key <> '_isku_' AND meta_key LIKE '_isku_%' ORDER BY post_id, meta_id";
97 - }
98 - $res = $wpdb->get_results($query, ARRAY_A);
99 -
100 - $conclusion = true;
101 - $pre_post_id = 0;
102 - $sort_id = 0;
103 - $check_code = array();
104 - $dep_num = array();
105 - foreach( (array)$res as $metarow ){
106 - $meta_value = unserialize($metarow['meta_value']);
107 - $newvalue = array();
108 - $newvalue['code'] = substr($metarow['meta_key'], 6);
109 - if( $pre_post_id == $metarow['post_id'] ){
110 - if( in_array( $newvalue['code'], $check_code ) ){
111 - $newvalue['code'] .= 'dupricate_' . (int)$dep_num[$newvalue['code']];
112 - $dep_num[$newvalue['code']]++;
113 - }
114 - }else{
115 - $check_code = array();
116 - $dep_num = array();
117 - $sort_id = 0;
118 - }
119 - foreach( (array)$meta_value as $k => $v ){
120 - switch ( $k ){
121 - case 'disp':
122 - $newvalue['name'] = $v;
123 - break;
124 - case 'cprice':
125 - $newvalue['cprice'] = $v;
126 - break;
127 - case 'price':
128 - $newvalue['price'] = $v;
129 - break;
130 - case 'unit':
131 - $newvalue['unit'] = $v;
132 - break;
133 - case 'zaikonum':
134 - $newvalue['stocknum'] = $v;
135 - break;
136 - case 'zaiko':
137 - $newvalue['stock'] = $v;
138 - break;
139 - case 'gptekiyo':
140 - $newvalue['gp'] = $v;
141 - break;
142 - case 'charging_type':
143 - break;
144 - default:
145 - $newvalue[$k] = $v;
146 - }
147 - }
148 - $newvalue['sort'] = $sort_id;
149 -
150 - $id = usces_add_sku($metarow['post_id'], $newvalue, false);
151 - $pre_post_id = $metarow['post_id'];
152 - $check_code[] = $newvalue['code'];
153 - $sort_id++;
154 -
155 - $res_key = $metarow['post_id'] . '_' . $newvalue['code'];
156 - if( $id ) {
157 - delete_post_meta($metarow['post_id'], $metarow['meta_key']);
158 - $rets['sku'][$res_key] = 1;
159 - }else{
160 - $rets['sku'][$res_key] = 0;
161 - usces_log('meta_id ' . $metarow['meta_id'] . ' : ' . __('This SKU-data has not been rebuilt.', 'usces'), 'database_error.log');
162 - }
163 - }
164 -
165 - /* ITEM OPTION DATA */
166 - $sort = (int)$options['system']['orderby_itemopt'];
167 - if( $sort ){
168 - $query = "SELECT * FROM $wpdb->postmeta WHERE meta_key <> '_iopt_' AND meta_key LIKE '_iopt_%' ORDER BY post_id, meta_key";
169 - }else{
170 - $query = "SELECT * FROM $wpdb->postmeta WHERE meta_key <> '_iopt_' AND meta_key LIKE '_iopt_%' ORDER BY post_id, meta_id";
171 - }
172 - $res = $wpdb->get_results($query, ARRAY_A);
173 -
174 - $conclusion = true;
175 - $pre_post_id = 0;
176 - $sort_id = 0;
177 - $check_code = array();
178 - $dep_num = array();
179 - foreach( (array)$res as $metarow ){
180 - $meta_value = unserialize($metarow['meta_value']);
181 - $newvalue = array();
182 - $newvalue['name'] = substr($metarow['meta_key'], 6);
183 - if( $pre_post_id == $metarow['post_id'] ){
184 - if( in_array( $newvalue['name'], $check_code ) ){
185 - $newvalue['name'] .= 'dupricate_' . (int)$dep_num[$newvalue['name']];
186 - $dep_num[$newvalue['name']]++;
187 - }
188 - }else{
189 - $check_code = array();
190 - $dep_num = array();
191 - $sort_id = 0;
192 - }
193 - foreach( (array)$meta_value as $k => $v ){
194 - switch ( $k ){
195 - case 'means':
196 - $newvalue['means'] = $v;
197 - break;
198 - case 'essential':
199 - $newvalue['essential'] = $v;
200 - break;
201 - case 'value':
202 - if( is_array($v) ){
203 - $nov = '';
204 - foreach((array)$v as $vs){
205 - if( !WCUtils::is_blank($vs) )
206 - //$nov .= str_replace('\\', '&yen;', trim( $vs )) . "\n";
207 - $nov .= $vs . "\n";
208 - }
209 - $newvalue['value'] = trim($nov);
210 - }else{
211 - $newvalue['value'] = trim($v);
212 - }
213 - break;
214 - default:
215 - $newvalue[$k] = trim($v);
216 - }
217 - }
218 - $newvalue['sort'] = $sort_id;
219 -
220 - $id = usces_add_opt($metarow['post_id'], $newvalue, false);
221 - $pre_post_id = $metarow['post_id'];
222 - $check_code[] = $newvalue['name'];
223 - $sort_id++;
224 -
225 - $res_key = $metarow['post_id'] . '_' . $newvalue['name'];
226 - if( $id ) {
227 - delete_post_meta($metarow['post_id'], $metarow['meta_key']);
228 - $rets['opt'][$res_key] = 1;
229 - }else{
230 - $rets['opt'][$res_key] = 0;
231 - usces_log('meta_id ' . $metarow['meta_id'] . ' : ' . __('This Item-Option-data has not been rebuilt.', 'usces'), 'database_error.log');
232 - }
233 - }
234 -
235 - /* PAYMENT METHOD DATA */
236 - $payment = get_option('usces_payment_method');
237 -//usces_log('payment : ' . print_r($payment,true), 'database_error.log');
238 - if( empty($payment) ) {
239 -
240 - $options = get_option('usces');
241 - $old_payment = isset($options['payment_method']) ? $options['payment_method'] : '';
242 - usces_log('old_payment : ' . print_r($old_payment,true), 'database_error.log');
243 - if( !empty($old_payment) && is_array($old_payment) ) {
244 - foreach( $old_payment as $key => $value ){
245 - $res_key = $key . '_' . $value['name'];
246 - $id = usces_add_system_option( 'usces_payment_method', $value );
247 - if( $id ) {
248 - $rets['payment'][$res_key] = 1;
249 - }else{
250 - $rets['payment'][$res_key] = 0;
251 - usces_log('payment_method ' . $value['name'] . ' : ' . __('This Payment-Method-data has not been rebuilt.', 'usces'), 'database_error.log');
252 - }
253 - }
254 - }
255 - }
256 -
257 - usces_log('USCES_UP11 : ' . print_r($rets,true), 'database_error.log');
258 -
259 -// $upgrade += USCES_UP11;
260 -// update_option('usces_upgrade', $upgrade);
261 - return $rets;
262 -}
263 -
264 -function usces_log($log, $file){
265 - global $usces;
266 -
267 - $log = date('[Y-m-d H:i:s]', current_time('timestamp')) . "\t" . $log . "\n";
268 - $file_path = USCES_PLUGIN_DIR . '/logs/' . $file;
269 - if( is_dir($file_path) )
270 - return;
271 -
272 - $fp = fopen($file_path, 'a');
273 - if( false !== $fp ){
274 - fwrite($fp, $log);
275 - fclose($fp);
276 - }
277 -}
278 -
279 -
280 -function usces_filter_delivery_secure_check( $mes ){
281 - global $usces;
282 - $usces_secure_link = get_option('usces_secure_link');
283 - $paymod_id = '';
284 - $settlement = '';
285 - $payments = usces_get_system_option( 'usces_payment_method', 'sort' );
286 -
287 - foreach ( (array)$payments as $id => $value ) {
288 - if( isset($_POST['offer']['payment_name']) && $value['name'] == $_POST['offer']['payment_name']){
289 - $settlement = $value['settlement'];
290 - break;
291 - }
292 - }
293 - switch( $settlement ){
294 - case 'acting_zeus_card':
295 - $cnum1 = trim($_POST["cnum1"]);
296 - $securecode = (isset($_POST["securecode"])) ? trim($_POST["securecode"]) : '';
297 - if ( !is_numeric($cnum1) )
298 - $mes .= __('カード番号が不正です', 'usces') . "<br />";
299 -
300 - if ( isset($_POST["securecode"]) && !is_numeric($securecode) )
301 - $mes .= __('セキュリティコードが不正です', 'usces') . "<br />";
302 -
303 - if ( WCUtils::is_blank($_POST["expyy"]) )
304 - $mes .= __('カードの有効年を選択してください', 'usces') . "<br />";
305 -
306 - if ( WCUtils::is_blank($_POST["expmm"]) )
307 - $mes .= __('カードの有効月を選択してください', 'usces') . "<br />";
308 -
309 - if ( WCUtils::is_blank($_POST["username_card"]) )
310 - $mes .= __('カード名義を入力してください', 'usces') . "<br />";
311 -
312 - if ( isset($_POST["howpay"]) && 0 == $_POST["howpay"] && WCUtils::is_blank($_POST["cbrand"]) )
313 - $mes .= __('カードブランドを選択してください', 'usces') . "<br />";
314 -
315 - if ( 'zeus' != $_POST['acting'] )
316 - $mes .= __('カード決済データが不正です!', 'usces');
317 -
318 - break;
319 -
320 - case 'acting_zeus_conv':
321 - if( WCUtils::is_blank($_POST['username_conv']) ) {
322 - $mes .= "お名前を入力してください。<br />";
323 - } elseif( !preg_match( "/^[ァ-ヶー]+$/u", $_POST['username_conv'] ) ) {
324 - $mes .= "お名前は全角カタカナで入力してください。<br />";
325 - }
326 - break;
327 - }
328 -
329 - return $mes;
330 -}
331 -
332 -function usces_get_conv_name($code){
333 - switch($code){
334 - case 'D001':
335 - case '010'://20101018ysk
336 - $name = 'セブンイレブン';
337 - break;
338 - case 'D002':
339 - case '020'://20101018ysk
340 - $name = 'ローソン';
341 - break;
342 - case 'D015':
343 - case '760'://20101018ysk
344 - $name = 'セイコーマート';
345 - break;
346 - case 'D405':
347 - $name = 'ペイジー';
348 - break;
349 - case 'D003':
350 - $name = 'サンクス';
351 - break;
352 - case 'D004':
353 - $name = 'サークルK';
354 - break;
355 - case 'D005':
356 - case '080'://20101018ysk
357 - case 'D050':
358 - $name = 'ミニストップ';
359 - break;
360 - case 'D010':
361 - case 'D060':
362 - $name = 'デイリーヤマザキ';
363 - break;
364 - case 'D011':
365 - $name = 'ヤマザキデイリーストア';
366 - break;
367 - case 'D030':
368 - case '030'://20101018ysk
369 - $name = 'ファミリーマート';
370 - break;
371 - case 'D401':
372 - $name = 'CyberEdy';
373 - break;
374 - case 'D404':
375 - $name = '楽天銀行';
376 - break;
377 - case 'D406':
378 - $name = 'ジャパネット銀行';
379 - break;
380 - case 'D451':
381 - $name = 'ウェブマネー';
382 - break;
383 - case 'D452':
384 - $name = 'ビットキャッシュ';
385 - break;
386 - case 'P901':
387 - $name = 'コンビニ払込票';
388 - break;
389 - case 'P902':
390 - $name = 'コンビニ払込票(郵便振替対応)';
391 - break;
392 -//20101018ysk start
393 - case '050':
394 - $name = 'デイリーヤマザキ・ヤマザキデイリーストア・タイムリー';
395 - break;
396 - case '060':
397 - $name = 'サークルK・サンクス';
398 - break;
399 - case '110':
400 - $name = 'am/pm';
401 - break;
402 -//20101018ysk end
403 - default:
404 - $name = '';
405 - }
406 - return $name;
407 -}
408 -
409 -function usces_get_remise_conv_return($code){
410 - switch($code){
411 - case 'D001': //セブンイレブン
412 - $html = '<tr><th>' . __('払込番号','usces') . '</th><td>' . esc_html($_REQUEST["X-PAY_NO1"]) . "</td></tr>\n";
413 - $html .= '<tr><th>'.__('払込票のURL', 'usces').'</th><td><a href="'.esc_html($_REQUEST["X-PAY_NO2"]).'" target="_blank">'.esc_html($_REQUEST["X-PAY_NO2"])."</a></td></tr>\n";
414 - break;
415 - case 'D002': //ローソン
416 - case 'D015': //セイコーマート
417 - case 'D405': //ペイジー
418 - $html = '<tr><th>' . __('受付番号','usces') . '</th><td>' . esc_html($_REQUEST["X-PAY_NO1"]) . "</td></tr>\n";
419 - $html .= '<tr><th>'.__('支払方法案内URL', 'usces').'</th><td><a href="'.esc_html($_REQUEST["X-PAY_NO2"]).'" target="_blank">'.esc_html($_REQUEST["X-PAY_NO2"])."</a></td></tr>\n";
420 - break;
421 - case 'D003': //サンクス
422 - case 'D004': //サークルK
423 - case 'D005': //ミニストップ
424 - case 'D010': //デイリーヤマザキ
425 - case 'D011': //ヤマザキデイリーストア
426 - $html = '<tr><th>' . __('決済番号','usces') . '</th><td>' . esc_html($_REQUEST["X-PAY_NO1"]) . "</td></tr>\n";
427 - $html .= '<tr><th>'.__('支払方法案内URL', 'usces').'</th><td><a href="'.esc_html($_REQUEST["X-PAY_NO2"]).'" target="_blank">'.esc_html($_REQUEST["X-PAY_NO2"])."</a></td></tr>\n";
428 - break;
429 - case 'D030': //ファミリーマート
430 - $html = '<tr><th>' . __('コード','usces') . '</th><td>' . esc_html($_REQUEST["X-PAY_NO1"]) . "</td></tr>\n";
431 - $html .= '<tr><th>'.__('注文番号', 'usces').'</th><td>'.esc_html($_REQUEST["X-PAY_NO2"])."</td></tr>\n";
432 - break;
433 - case 'D401': //CyberEdy
434 - case 'D404': //楽天銀行
435 - case 'D406': //ジャパネット銀行
436 - case 'D451': //ウェブマネー
437 - case 'D452': //ビットキャッシュ
438 - $html = '<tr><th>' . __('受付番号','usces') . '</th><td>' . esc_html($_REQUEST["X-PAY_NO1"]) . "</td></tr>\n";
439 - $html .= '<tr><th>'.__('支払手続URL', 'usces').'</th><td><a href="'.esc_html($_REQUEST["X-PAY_NO2"]).'" target="_blank">'.esc_html($_REQUEST["X-PAY_NO2"])."</a></td></tr>\n";
440 - break;
441 - case 'P901': //コンビニ払込票
442 - case 'P902': //コンビニ払込票(郵便振替対応)
443 - $html = '<tr><th>' . __('受付番号','usces') . '</th><td>' . esc_html($_REQUEST["X-PAY_NO1"]) . "</td></tr>\n";
444 - break;
445 - default:
446 - $html = '';
447 - }
448 - return $html;
449 -}
450 -
451 -function usces_payment_detail($usces_entries){
452 - $payments = usces_get_payments_by_name( $usces_entries['order']['payment_name'] );
453 - $acting_flag = ( 'acting' == $payments['settlement'] ) ? $payments['module'] : $payments['settlement'];
454 - $str = '';
455 - switch( $acting_flag ){
456 - case 'paypal.php':
457 - break;
458 -
459 - case 'epsilon.php':
460 - break;
461 -
462 - case 'acting_zeus_card':
463 - if( !isset($usces_entries['order']['cbrand']) || (isset($usces_entries['order']['howpay']) && '1' === $usces_entries['order']['howpay']) ){
464 - $str = ' 一括払い';
465 - }else{
466 - $div_name = 'div_' . $usces_entries['order']['cbrand'];
467 - switch($usces_entries['order'][$div_name]){
468 - case '01':
469 - $str = ' 一括払い';
470 - break;
471 - case '99':
472 - $str = ' 分割(リボ払い)';
473 - break;
474 - case '03':
475 - $str = ' 分割(3回)';
476 - break;
477 - case '05':
478 - $str = ' 分割(5回)';
479 - break;
480 - case '06':
481 - $str = ' 分割(6回)';
482 - break;
483 - case '10':
484 - $str = ' 分割(10回)';
485 - break;
486 - case '12':
487 - $str = ' 分割(12回)';
488 - break;
489 - case '15':
490 - $str = ' 分割(15回)';
491 - break;
492 - case '18':
493 - $str = ' 分割(18回)';
494 - break;
495 - case '20':
496 - $str = ' 分割(20回)';
497 - break;
498 - case '24':
499 - $str = ' 分割(24回)';
500 - break;
501 - }
502 - }
503 - break;
504 -
505 - case 'acting_zeus_bank':
506 - break;
507 -
508 - case 'acting_remise_card':
509 - if( isset( $usces_entries['order']['div'] ) ){
510 - switch($usces_entries['order']['div']){
511 - case '0':
512 - $str = ' 一括払い';
513 - break;
514 - case '1':
515 - $str = ' 分割(2回)';
516 - break;
517 - case '2':
518 - $str = ' 分割(リボ払い)';
519 - break;
520 - }
521 - }
522 - break;
523 -
524 - case 'acting_remise_conv':
525 - break;
526 - }
527 -
528 - $str = apply_filters('usces_filter_payment_detail', $str, $usces_entries);
529 - return $str;
530 -}
531 -
532 -//20100818ysk start
533 -function usces_filter_delivery_check_custom_order( $mes ) {
534 - global $usces;
535 -
536 - $meta = usces_has_custom_field_meta('order');
537 -//20140131ysk start 0000819
538 - if( is_array($meta) ) {
539 - unset( $_SESSION['usces_entry']['custom_order'] );
540 - if( isset($_POST['custom_order']) ) {
541 - foreach( $_POST['custom_order'] as $key => $value ) {
542 - if( is_array($value) ) {
543 - foreach( $value as $k => $v ) {
544 - $_SESSION['usces_entry']['custom_order'][$key][trim($v)] = trim($v);
545 - }
546 - } else {
547 - $_SESSION['usces_entry']['custom_order'][$key] = trim($value);
548 - }
549 - }
550 - }
551 - }
552 -//20140131ysk end
553 -
554 - foreach($meta as $key => $entry) {
555 - $essential = $entry['essential'];
556 - if($essential == 1) {
557 - $name = $entry['name'];
558 - $means = $entry['means'];
559 - if($means == 2) {//Text
560 - if( WCUtils::is_blank($_POST['custom_order'][$key]) )
561 - $mes .= __($name.'を入力してください。', 'usces')."<br />";
562 - } else {
563 - if(!isset($_POST['custom_order'][$key]) or $_POST['custom_order'][$key] == "#NONE#")
564 - $mes .= __($name.'を選択してください。', 'usces')."<br />";
565 - }
566 - }
567 - }
568 -
569 - return $mes;
570 -}
571 -
572 -function usces_filter_customer_check_custom_customer( $mes ) {
573 - global $usces;
574 -
575 - $meta = usces_has_custom_field_meta('customer');
576 - foreach($meta as $key => $entry) {
577 - $essential = $entry['essential'];
578 - if($essential == 1) {
579 - $name = $entry['name'];
580 - $means = $entry['means'];
581 - if($means == 2) {//Text
582 - if( WCUtils::is_blank($_POST['custom_customer'][$key]) )
583 - $mes .= __($name.'を入力してください。', 'usces')."<br />";
584 - } else {
585 - if(!isset($_POST['custom_customer'][$key]) or $_POST['custom_customer'][$key] == "#NONE#")
586 - $mes .= __($name.'を選択してください。', 'usces')."<br />";
587 - }
588 - }
589 - }
590 -
591 - return $mes;
592 -}
593 -
594 -function usces_filter_delivery_check_custom_delivery( $mes ) {
595 - global $usces;
596 -
597 - if( isset($_POST['delivery']['delivery_flag']) && $_POST['delivery']['delivery_flag'] == '1' ) {
598 - $meta = usces_has_custom_field_meta('delivery');
599 - foreach($meta as $key => $entry) {
600 - $essential = $entry['essential'];
601 - if($essential == 1) {
602 - $name = $entry['name'];
603 - $means = $entry['means'];
604 - if($means == 2) {//Text
605 - if( WCUtils::is_blank($_POST['custom_delivery'][$key]) )
606 - $mes .= __($name.'を入力してください。', 'usces')."<br />";
607 - } else {
608 - if(!isset($_POST['custom_delivery'][$key]) or $_POST['custom_delivery'][$key] == "#NONE#")
609 - $mes .= __($name.'を選択してください。', 'usces')."<br />";
610 - }
611 - }
612 - }
613 - }
614 -
615 - return $mes;
616 -}
617 -
618 -function usces_filter_member_check_custom_member( $mes ) {
619 - global $usces;
620 -
621 - unset($_SESSION['usces_member']['custom_member']);
622 - if(isset($_POST['custom_member'])) {
623 - foreach( $_POST['custom_member'] as $key => $value )
624 - if( is_array($value) ) {
625 - foreach( $value as $k => $v )
626 - $_SESSION['usces_member']['custom_member'][$key][trim($v)] = trim($v);
627 - } else {
628 - $_SESSION['usces_member']['custom_member'][$key] = trim($value);
629 - }
630 - }
631 -
632 - $meta = usces_has_custom_field_meta('member');
633 - foreach($meta as $key => $entry) {
634 - $essential = $entry['essential'];
635 - if($essential == 1) {
636 - $name = $entry['name'];
637 - $means = $entry['means'];
638 - if($means == 2) {//Text
639 - if( WCUtils::is_blank($_POST['custom_member'][$key]) )
640 - $mes .= __($name.'を入力してください。', 'usces')."<br />";
641 - } else {
642 - if(!isset($_POST['custom_member'][$key]) or $_POST['custom_member'][$key] == "#NONE#")
643 - $mes .= __($name.'を選択してください。', 'usces')."<br />";
644 - }
645 - }
646 - }
647 -
648 - return $mes;
649 -}
650 -//20100818ysk end
651 -function usces_dashboard_setup() {
652 - wp_add_dashboard_widget( 'usces_db_widget' , 'Welcart Information' , 'usces_db_widget');
653 -}
654 -
655 -function usces_admin_login_head() {
656 -?>
657 -<script type='text/javascript'>
658 -(function($) {
659 - usces = {
660 - settings: {
661 - url: 'http://www.welcart.com/varch/varch.php',
662 - type: 'POST',
663 - cache: false,
664 - success: function(data, dataType){
665 - },
666 - error: function(msg){
667 - }
668 - },
669 - varch : function() {
670 - var s = usces.settings;
671 - s.data = "action=varch_ajax&ID=usces_varch&ver=" + <?php echo $_SERVER['HTTP_HOST']; ?>;
672 - $.ajax( s );
673 - return false;
674 - }
675 - };
676 - usces.varch();
677 -})(jQuery);
678 -</script>
679 -<?php
680 -}
681 -
682 -//20100908ysk start
683 -// member list download
684 -function usces_download_member_list() {
685 - require_once( USCES_PLUGIN_DIR . "/classes/dataList.class.php" );
686 - global $wpdb, $usces;
687 -//20110411ysk start
688 - global $usces_settings;
689 -//20110411ysk end
690 -
691 - $ext = $_REQUEST['ftype'];
692 -/* if($ext == 'xls') {//HTML
693 - $table_h = "<table>";
694 - $table_f = "</table>";
695 - $tr_h = "<tr>";
696 - $tr_f = "</tr>";
697 - $th_h1 = "<th>";
698 - $th_h = "<th>";
699 - $th_f = "</th>";
700 - $td_h1 = "<td>";
701 - $td_h = "<td>";
702 - $td_f = "</td>";
703 - $lf = "\n";
704 -*/ if($ext == 'xls') {//TSV
705 - $table_h = "";
706 - $table_f = "";
707 - $tr_h = "";
708 - $tr_f = "";
709 - $th_h1 = '"';
710 - $th_h = "\t".'"';
711 - $th_f = '"';
712 - $td_h1 = '"';
713 - $td_h = "\t".'"';
714 - $td_f = '"';
715 - $lf = "\n";
716 - } elseif($ext == 'csv') {//CSV
717 - $table_h = "";
718 - $table_f = "";
719 - $tr_h = "";
720 - $tr_f = "";
721 -//20110201ysk start
722 - //$th_h1 = "";
723 - $th_h1 = '"';
724 - //$th_h = ",";
725 - $th_h = ',"';
726 - //$th_f = "";
727 - $th_f = '"';
728 - //$td_h1 = "";
729 - $td_h1 = '"';
730 - //$td_h = ",";
731 - $td_h = ',"';
732 - //$td_f = "";
733 - $td_f = '"';
734 -//20110201ysk end
735 - $lf = "\n";
736 - } else {
737 - exit();
738 - }
739 - $csmb_meta = usces_has_custom_field_meta('member');
740 -//20110411ysk start
741 - $applyform = usces_get_apply_addressform($usces->options['system']['addressform']);
742 -//20110411ysk end
743 -
744 - //==========================================================================
745 - $usces_opt_member = get_option('usces_opt_member');
746 - if(!is_array($usces_opt_member)){
747 - $usces_opt_member = array();
748 - }
749 - $usces_opt_member['ftype_mem'] = $ext;
750 - $chk_mem = array();
751 - $chk_mem['ID'] = 1;
752 - $chk_mem['email'] = (isset($_REQUEST['check']['email'])) ? 1 : 0;
753 - if(!empty($csmb_meta)) {
754 - foreach($csmb_meta as $key => $entry) {
755 - if($entry['position'] == 'name_pre') {
756 - $name = $entry['name'];
757 -//20110208ysk start
758 - $csmb_key = 'csmb_'.$key;
759 - //$chk_mem[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
760 - $chk_mem[$csmb_key] = (isset($_REQUEST['check'][$csmb_key])) ? 1 : 0;
761 -//20110208ysk end
762 - }
763 - }
764 - }
765 - $chk_mem['name'] = 1;
766 -//20110411ysk start
767 - if($applyform == 'JP') {
768 - $chk_mem['kana'] = (isset($_REQUEST['check']['kana'])) ? 1 : 0;
769 - }
770 -//20110411ysk end
771 - if(!empty($csmb_meta)) {
772 - foreach($csmb_meta as $key => $entry) {
773 - if($entry['position'] == 'name_after') {
774 - $name = $entry['name'];
775 -//20110208ysk start
776 - $csmb_key = 'csmb_'.$key;
777 - //$chk_mem[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
778 - $chk_mem[$csmb_key] = (isset($_REQUEST['check'][$csmb_key])) ? 1 : 0;
779 -//20110208ysk end
780 - }
781 - }
782 - }
783 - $chk_mem['zip'] = (isset($_REQUEST['check']['zip'])) ? 1 : 0;
784 -//20110411ysk start
785 - $chk_mem['country'] = 1;
786 -//20110411ysk end
787 - $chk_mem['pref'] = 1;
788 - $chk_mem['address1'] = 1;
789 - $chk_mem['address2'] = 1;
790 - $chk_mem['address3'] = 1;
791 - $chk_mem['tel'] = (isset($_REQUEST['check']['tel'])) ? 1 : 0;
792 - $chk_mem['fax'] = (isset($_REQUEST['check']['fax'])) ? 1 : 0;
793 - if(!empty($csmb_meta)) {
794 - foreach($csmb_meta as $key => $entry) {
795 - if($entry['position'] == 'fax_after') {
796 - $name = $entry['name'];
797 -//20110208ysk start
798 - $csmb_key = 'csmb_'.$key;
799 - //$chk_mem[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
800 - $chk_mem[$csmb_key] = (isset($_REQUEST['check'][$csmb_key])) ? 1 : 0;
801 -//20110208ysk end
802 - }
803 - }
804 - }
805 - $chk_mem['date'] = (isset($_REQUEST['check']['date'])) ? 1 : 0;
806 - $chk_mem['point'] = (isset($_REQUEST['check']['point'])) ? 1 : 0;
807 - $chk_mem['rank'] = (isset($_REQUEST['check']['rank'])) ? 1 : 0;
808 - $usces_opt_member['chk_mem'] = apply_filters( 'usces_filter_chk_mem', $chk_mem );
809 - update_option('usces_opt_member', $usces_opt_member);
810 - //==========================================================================
811 -
812 - $_REQUEST['searchIn'] = "searchIn";
813 - $tableName = $wpdb->prefix."usces_member";
814 - $arr_column = array(
815 - __('membership number', 'usces') => 'ID',
816 - __('name', 'usces') => 'name',
817 - __('Address', 'usces') => 'address',
818 - __('Phone number', 'usces') => 'tel',
819 - __('e-mail', 'usces') => 'email',
820 - __('Strated date', 'usces') => 'date',
821 - __('current point', 'usces') => 'point');
822 - $DT = new dataList($tableName, $arr_column);
823 -//20101202ysk start
824 - $DT->pageLimit = 'off';
825 -//20101202ysk end
826 - $res = $DT->MakeTable();
827 - $rows = $DT->rows;
828 -
829 - //==========================================================================
830 - $line = $table_h;
831 - $line .= $tr_h;
832 - $line .= $th_h1.__('membership number', 'usces').$th_f;
833 - if(isset($_REQUEST['check']['email'])) $line .= $th_h.__('e-mail', 'usces').$th_f;
834 - if(!empty($csmb_meta)) {
835 - foreach($csmb_meta as $key => $entry) {
836 - if($entry['position'] == 'name_pre') {
837 - $name = $entry['name'];
838 -//20110208ysk start
839 - $csmb_key = 'csmb_'.$key;
840 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
841 - if(isset($_REQUEST['check'][$csmb_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
842 -//20110208ysk end
843 - }
844 - }
845 - }
846 - $line .= $th_h.__('name', 'usces').$th_f;
847 -//20110411ysk start
848 - if($applyform == 'JP') {
849 - if(isset($_REQUEST['check']['kana'])) $line .= $th_h.__('furigana', 'usces').$th_f;
850 - }
851 -//20110411ysk end
852 - if(!empty($csmb_meta)) {
853 - foreach($csmb_meta as $key => $entry) {
854 - if($entry['position'] == 'name_after') {
855 - $name = $entry['name'];
856 -//20110208ysk start
857 - $csmb_key = 'csmb_'.$key;
858 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
859 - if(isset($_REQUEST['check'][$csmb_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
860 -//20110208ysk end
861 - }
862 - }
863 - }
864 -//20110411ysk start
865 - switch($applyform) {
866 - case 'JP':
867 - if(isset($_REQUEST['check']['zip'])) $line .= $th_h.__('Zip/Postal Code', 'usces').$th_f;
868 - $line .= $th_h.__('Country', 'usces').$th_f;
869 - $line .= $th_h.__('Province', 'usces').$th_f;
870 - $line .= $th_h.__('city', 'usces').$th_f;
871 - $line .= $th_h.__('numbers', 'usces').$th_f;
872 - $line .= $th_h.__('building name', 'usces').$th_f;
873 - if(isset($_REQUEST['check']['tel'])) $line .= $th_h.__('Phone number', 'usces').$th_f;
874 - if(isset($_REQUEST['check']['fax'])) $line .= $th_h.__('FAX number', 'usces').$th_f;
875 - break;
876 - case 'US':
877 - default:
878 - $line .= $th_h.__('Address Line1', 'usces').$th_f;
879 - $line .= $th_h.__('Address Line2', 'usces').$th_f;
880 - $line .= $th_h.__('city', 'usces').$th_f;
881 - $line .= $th_h.__('State', 'usces').$th_f;
882 - $line .= $th_h.__('Country', 'usces').$th_f;
883 - if(isset($_REQUEST['check']['zip'])) $line .= $th_h.__('Zip', 'usces').$th_f;
884 - if(isset($_REQUEST['check']['tel'])) $line .= $th_h.__('Phone number', 'usces').$th_f;
885 - if(isset($_REQUEST['check']['fax'])) $line .= $th_h.__('FAX number', 'usces').$th_f;
886 - break;
887 - }
888 -//20110411ysk end
889 - if(!empty($csmb_meta)) {
890 - foreach($csmb_meta as $key => $entry) {
891 - if($entry['position'] == 'fax_after') {
892 - $name = $entry['name'];
893 -//20110208ysk start
894 - $csmb_key = 'csmb_'.$key;
895 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
896 - if(isset($_REQUEST['check'][$csmb_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
897 -//20110208ysk end
898 - }
899 - }
900 - }
901 - if(isset($_REQUEST['check']['date'])) $line .= $th_h.__('Strated date', 'usces').$th_f;
902 - if(isset($_REQUEST['check']['point'])) $line .= $th_h.__('current point', 'usces').$th_f;
903 - if(isset($_REQUEST['check']['rank'])) $line .= $th_h.__('Rank', 'usces').$th_f;
904 - $line .= apply_filters( 'usces_filter_chk_mem_label', NULL, $usces_opt_member, $rows );
905 - $line .= $tr_f.$lf;
906 - //==========================================================================
907 - foreach((array)$rows as $array) {
908 - $member_id = $array['ID'];
909 - $query = $wpdb->prepare("SELECT * FROM $tableName WHERE ID = %d", $member_id);
910 - $data = $wpdb->get_row( $query, ARRAY_A );
911 -
912 - $line .= $tr_h;
913 - $line .= $td_h1.$member_id.$td_f;
914 - if(isset($_REQUEST['check']['email'])) $line .= $td_h.usces_entity_decode($array['email'], $ext).$td_f;
915 - if(!empty($csmb_meta)) {
916 - foreach($csmb_meta as $key => $entry) {
917 - if($entry['position'] == 'name_pre') {
918 - $name = $entry['name'];
919 - $csmb_key = 'csmb_'.$key;
920 -//20110208ysk start
921 - //if(isset($_REQUEST['check'][$name])) {
922 - if(isset($_REQUEST['check'][$csmb_key])) {
923 -//20110208ysk end
924 - $value = maybe_unserialize($usces->get_member_meta_value($csmb_key, $member_id));
925 - if(empty($value)) {
926 - $value = '';
927 - } elseif(is_array($value)) {
928 - $concatval = '';
929 - $c = '';
930 - foreach($value as $v) {
931 - $concatval .= $c.$v;
932 - $c = ' ';
933 - }
934 - $value = $concatval;
935 - }
936 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
937 - }
938 - }
939 - }
940 - }
941 -//20110411ysk start
942 - switch($applyform) {
943 - case 'JP':
944 - $line .= $td_h.usces_entity_decode($data['mem_name1'].' '.$data['mem_name2'], $ext).$td_f;
945 - if(isset($_REQUEST['check']['kana'])) $line .= $td_h.usces_entity_decode($data['mem_name3'].' '.$data['mem_name4'], $ext).$td_f;
946 - break;
947 - case 'US':
948 - default:
949 - $line .= $td_h.usces_entity_decode($data['mem_name2'].' '.$data['mem_name1'], $ext).$td_f;
950 - break;
951 - }
952 -//20110411ysk end
953 - if(!empty($csmb_meta)) {
954 - foreach($csmb_meta as $key => $entry) {
955 - if($entry['position'] == 'name_after') {
956 - $name = $entry['name'];
957 - $csmb_key = 'csmb_'.$key;
958 -//20110208ysk start
959 - //if(isset($_REQUEST['check'][$name])) {
960 - if(isset($_REQUEST['check'][$csmb_key])) {
961 -//20110208ysk end
962 - $value = maybe_unserialize($usces->get_member_meta_value($csmb_key, $member_id));
963 - if(empty($value)) {
964 - $value = '';
965 - } elseif(is_array($value)) {
966 - $concatval = '';
967 - $c = '';
968 - foreach($value as $v) {
969 - $concatval .= $c.$v;
970 - $c = ' ';
971 - }
972 - $value = $concatval;
973 - }
974 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
975 - }
976 - }
977 - }
978 - }
979 -//20110411ysk start
980 - $address_info = '';
981 - switch($applyform) {
982 - case 'JP':
983 - if(isset($_REQUEST['check']['zip'])) $address_info .= $td_h.usces_entity_decode($data['mem_zip'], $ext).$td_f;
984 - $address_info .= $td_h.$usces_settings['country'][$usces->get_member_meta_value('customer_country', $member_id)].$td_f;
985 - $address_info .= $td_h.usces_entity_decode($data['mem_pref'], $ext).$td_f;
986 - $address_info .= $td_h.usces_entity_decode($data['mem_address1'], $ext).$td_f;
987 - $address_info .= $td_h.usces_entity_decode($data['mem_address2'], $ext).$td_f;
988 - $address_info .= $td_h.usces_entity_decode($data['mem_address3'], $ext).$td_f;
989 - if(isset($_REQUEST['check']['tel'])) $address_info .= $td_h.usces_entity_decode($data['mem_tel'], $ext).$td_f;
990 - if(isset($_REQUEST['check']['fax'])) $address_info .= $td_h.usces_entity_decode($data['mem_fax'], $ext).$td_f;
991 - break;
992 - case 'US':
993 - default:
994 - $address_info .= $td_h.usces_entity_decode($data['mem_address2'], $ext).$td_f;
995 - $address_info .= $td_h.usces_entity_decode($data['mem_address3'], $ext).$td_f;
996 - $address_info .= $td_h.usces_entity_decode($data['mem_address1'], $ext).$td_f;
997 - $address_info .= $td_h.usces_entity_decode($data['mem_pref'], $ext).$td_f;
998 - $address_info .= $td_h.$usces_settings['country'][$usces->get_member_meta_value('customer_country', $member_id)].$td_f;
999 - if(isset($_REQUEST['check']['zip'])) $address_info .= $td_h.usces_entity_decode($data['mem_zip'], $ext).$td_f;
1000 - if(isset($_REQUEST['check']['tel'])) $address_info .= $td_h.usces_entity_decode($data['mem_tel'], $ext).$td_f;
1001 - if(isset($_REQUEST['check']['fax'])) $address_info .= $td_h.usces_entity_decode($data['mem_fax'], $ext).$td_f;
1002 - break;
1003 - }
1004 - $address_info_args = compact( 'td_h', 'td_f', 'ext', 'member_id', 'applyform' );
1005 - $line .= apply_filters( 'usces_filter_mem_csv_address_info', $address_info, $data, $address_info_args );
1006 -//20110411ysk end
1007 - if(!empty($csmb_meta)) {
1008 - foreach($csmb_meta as $key => $entry) {
1009 - if($entry['position'] == 'fax_after') {
1010 - $name = $entry['name'];
1011 - $csmb_key = 'csmb_'.$key;
1012 -//20110208ysk start
1013 - //if(isset($_REQUEST['check'][$name])) {
1014 - if(isset($_REQUEST['check'][$csmb_key])) {
1015 -//20110208ysk end
1016 - $value = maybe_unserialize($usces->get_member_meta_value($csmb_key, $member_id));
1017 - if(empty($value)) {
1018 - $value = '';
1019 - } elseif(is_array($value)) {
1020 - $concatval = '';
1021 - $c = '';
1022 - foreach($value as $v) {
1023 - $concatval .= $c.$v;
1024 - $c = ' ';
1025 - }
1026 - $value = $concatval;
1027 - }
1028 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
1029 - }
1030 - }
1031 - }
1032 - }
1033 - if(isset($_REQUEST['check']['date'])) $line .= $td_h.$data['mem_registered'].$td_f;
1034 - if(isset($_REQUEST['check']['point'])) $line .= $td_h.$data['mem_point'].$td_f;
1035 - if(isset($_REQUEST['check']['rank'])) {
1036 - $rank = '';
1037 - foreach((array)$usces->member_status as $rk => $rv) {
1038 - if($rk == $data['mem_status']) {
1039 - $rank = $rv;
1040 - break;
1041 - }
1042 - }
1043 - $line .= $td_h.$rank.$td_f;
1044 - }
1045 - $line .= apply_filters( 'usces_filter_chk_mem_data', NULL, $usces_opt_member, $member_id, $data );
1046 - $line .= $tr_f.$lf;
1047 - }
1048 - $line .= $table_f.$lf;
1049 - //==========================================================================
1050 -
1051 - if($ext == 'xls') {
1052 - header("Content-Type: application/vnd.ms-excel; charset=Shift-JIS");
1053 - } elseif($ext == 'csv') {
1054 - header("Content-Type: application/octet-stream");
1055 - }
1056 - header("Content-Disposition: attachment; filename=usces_member_list.".$ext);
1057 - mb_http_output('pass');
1058 - print(mb_convert_encoding($line, "SJIS-win", "UTF-8"));
1059 - exit();
1060 -}
1061 -
1062 -// product list download
1063 -function usces_download_product_list() {
1064 - require_once( USCES_PLUGIN_DIR . "/classes/orderList.class.php" );
1065 - global $wpdb, $usces;
1066 -
1067 - $ext = $_REQUEST['ftype'];
1068 -/* if($ext == 'xls') {//HTML
1069 - $table_h = "<table>";
1070 - $table_f = "</table>";
1071 - $tr_h = "<tr>";
1072 - $tr_f = "</tr>";
1073 - $th_h1 = "<th>";
1074 - $th_h = "<th>";
1075 - $th_f = "</th>";
1076 - $td_h1 = "<td>";
1077 - $td_h = "<td>";
1078 - $td_f = "</td>";
1079 - $sp = ":";
1080 - $nb = " ";
1081 - $lf = "\n";
1082 -*/ if($ext == 'xls') {//TSV
1083 - $table_h = "";
1084 - $table_f = "";
1085 - $tr_h = "";
1086 - $tr_f = "";
1087 - $th_h1 = '"';
1088 - $th_h = "\t".'"';
1089 - $th_f = '"';
1090 - $td_h1 = '"';
1091 - $td_h = "\t".'"';
1092 - $td_f = '"';
1093 - $sp = ":";
1094 - $nb = "\n";
1095 - $lf = "\n";
1096 - } elseif($ext == 'csv') {//CSV
1097 - $table_h = "";
1098 - $table_f = "";
1099 - $tr_h = "";
1100 - $tr_f = "";
1101 -//20110201ysk start
1102 - //$th_h1 = "";
1103 - $th_h1 = '"';
1104 - //$th_h = ",";
1105 - $th_h = ',"';
1106 - //$th_f = "";
1107 - $th_f = '"';
1108 - //$td_h1 = "";
1109 - $td_h1 = '"';
1110 - //$td_h = ",";
1111 - $td_h = ',"';
1112 - //$td_f = "";
1113 - $td_f = '"';
1114 -//20110201ysk end
1115 - $sp = ":";
1116 - $nb = " ";
1117 - $lf = "\n";
1118 - } else {
1119 - exit();
1120 - }
1121 -
1122 - //==========================================================================
1123 - $usces_opt_order = get_option('usces_opt_order');
1124 - if(!is_array($usces_opt_order)){
1125 - $usces_opt_order = array();
1126 - }
1127 - $usces_opt_order['ftype_pro'] = $ext;
1128 - $chk_pro = array();
1129 - $chk_pro['ID'] = 1;
1130 - $chk_pro['deco_id'] = 1;
1131 - $chk_pro['date'] = (isset($_REQUEST['check']['date'])) ? 1 : 0;
1132 - $chk_pro['mem_id'] = (isset($_REQUEST['check']['mem_id'])) ? 1 : 0;
1133 - $chk_pro['name'] = (isset($_REQUEST['check']['name'])) ? 1 : 0;
1134 - $chk_pro['delivery_method'] = (isset($_REQUEST['check']['delivery_method'])) ? 1 : 0;
1135 - $chk_pro['shipping_date'] = (isset($_REQUEST['check']['shipping_date'])) ? 1 : 0;
1136 - $chk_pro['item_code'] = 1;
1137 - $chk_pro['sku_code'] = 1;
1138 - $chk_pro['item_name'] = (isset($_REQUEST['check']['item_name'])) ? 1 : 0;
1139 - $chk_pro['sku_name'] = (isset($_REQUEST['check']['sku_name'])) ? 1 : 0;
1140 - $chk_pro['options'] = (isset($_REQUEST['check']['options'])) ? 1 : 0;
1141 - $chk_pro['quantity'] = 1;
1142 - $chk_pro['price'] = 1;
1143 - $chk_pro['unit'] = (isset($_REQUEST['check']['unit'])) ? 1 : 0;
1144 - $usces_opt_order['chk_pro'] = apply_filters( 'usces_filter_chk_pro', $chk_pro );
1145 - update_option('usces_opt_order', $usces_opt_order);
1146 - //==========================================================================
1147 -
1148 - $_REQUEST['searchIn'] = "searchIn";
1149 - $tableName = $wpdb->prefix."usces_order";
1150 - $arr_column = array(
1151 - __('ID', 'usces') => 'ID',
1152 - __('Order number', 'usces') => 'deco_id',
1153 - __('date', 'usces') => 'date',
1154 - __('membership number', 'usces') => 'mem_id',
1155 - __('name', 'usces') => 'name',
1156 - __('Region', 'usces') => 'pref',
1157 - __('shipping option', 'usces') => 'delivery_method',
1158 - __('Amount', 'usces') => 'total_price',
1159 - __('payment method', 'usces') => 'payment_name',
1160 - __('transfer statement', 'usces') => 'receipt_status',
1161 - __('Processing', 'usces') => 'order_status',
1162 - __('shpping date', 'usces') => 'order_modified');
1163 - $DT = new dataList($tableName, $arr_column);
1164 -//20101202ysk start
1165 - $DT->pageLimit = 'off';
1166 -//20101202ysk end
1167 - $res = $DT->MakeTable();
1168 - $rows = $DT->rows;
1169 -
1170 - //==========================================================================
1171 - $line = $table_h;
1172 - $line .= $tr_h;
1173 - $line .= $th_h1.__('ID', 'usces').$th_f;
1174 - $line .= $th_h.__('Order number', 'usces').$th_f;
1175 - if(isset($_REQUEST['check']['date'])) $line .= $th_h.__('order date', 'usces').$th_f;
1176 - if(isset($_REQUEST['check']['mem_id'])) $line .= $th_h.__('membership number', 'usces').$th_f;
1177 - if(isset($_REQUEST['check']['name'])) $line .= $th_h.__('name', 'usces').$th_f;
1178 - if(isset($_REQUEST['check']['delivery_method'])) $line .= $th_h.__('shipping option', 'usces').$th_f;
1179 - if(isset($_REQUEST['check']['shipping_date'])) $line .= $th_h.__('shpping date', 'usces').$th_f;
1180 - $line .= apply_filters( 'usces_filter_chk_pro_label_head', NULL, $usces_opt_order, $rows);
1181 - $line .= $th_h.__('item code', 'usces').$th_f;
1182 - $line .= $th_h.__('SKU code', 'usces').$th_f;
1183 - if(isset($_REQUEST['check']['item_name'])) $line .= $th_h.__('item name', 'usces').$th_f;
1184 - if(isset($_REQUEST['check']['sku_name'])) $line .= $th_h.__('SKU display name ', 'usces').$th_f;
1185 - if(isset($_REQUEST['check']['options'])) $line .= $th_h.__('options for items', 'usces').$th_f;
1186 - $line .= $th_h.__('Quantity', 'usces').$th_f;
1187 - $line .= $th_h.__('Unit price', 'usces').$th_f;
1188 - if(isset($_REQUEST['check']['unit'])) $line .= $th_h.__('unit', 'usces').$th_f;
1189 - $line .= apply_filters( 'usces_filter_chk_pro_label_detail', NULL, $usces_opt_order, $rows);
1190 - $line .= $tr_f.$lf;
1191 - //==========================================================================
1192 - foreach((array)$rows as $array) {
1193 - $order_id = $array['ID'];
1194 - $query = $wpdb->prepare("SELECT * FROM $tableName WHERE ID = %d", $order_id);
1195 - $data = $wpdb->get_row( $query, ARRAY_A );
1196 - //$cart = stripslashes_deep(unserialize($data['order_cart']));
1197 - $cart = unserialize($data['order_cart']);
1198 - //if(!empty($data)) {
1199 - // $data = stripslashes_deep($data);
1200 - //}
1201 - for($i = 0; $i < count($cart); $i++) {
1202 - $cart_row = $cart[$i];
1203 - $post_id = $cart_row['post_id'];
1204 - $sku = urldecode($cart_row['sku']);
1205 -
1206 - $line .= $tr_h;
1207 - $line .= $td_h1.$order_id.$td_f;
1208 - $line .= $td_h.$array['deco_id'].$td_f;
1209 - if(isset($_REQUEST['check']['date'])) $line .= $td_h.$array['date'].$td_f;
1210 - if(isset($_REQUEST['check']['mem_id'])) $line .= $td_h.$array['mem_id'].$td_f;
1211 - if(isset($_REQUEST['check']['name'])) $line .= $td_h.usces_entity_decode($data['order_name1'].$data['order_name2'], $ext).$td_f;
1212 - if(isset($_REQUEST['check']['delivery_method'])) {
1213 - $delivery_method = '';
1214 - if(strtoupper($data['order_delivery_method']) == '#NONE#') {
1215 - $delivery_method = __('No preference', 'usces');
1216 - } else {
1217 - foreach((array)$usces->options['delivery_method'] as $dkey => $delivery) {
1218 - if($delivery['id'] == $data['order_delivery_method']) {
1219 - $delivery_method = $delivery['name'];
1220 - break;
1221 - }
1222 - }
1223 - }
1224 - $line .= $td_h.$delivery_method.$td_f;
1225 - }
1226 - if(isset($_REQUEST['check']['shipping_date'])) $line .= $td_h.$data['order_modified'].$td_f;
1227 - $line .= apply_filters( 'usces_filter_chk_pro_data_head', NULL, $usces_opt_order, $data, $cart_row);
1228 -
1229 - $line .= $td_h.$usces->getItemCode($post_id).$td_f;
1230 - $line .= $td_h.$sku.$td_f;
1231 - if(isset($_REQUEST['check']['item_name'])) $line .= $td_h.usces_entity_decode($usces->getItemName($post_id), $ext).$td_f;
1232 - if(isset($_REQUEST['check']['sku_name'])) $line .= $td_h.usces_entity_decode($usces->getItemSkuDisp($post_id, $sku), $ext).$td_f;
1233 - if(isset($_REQUEST['check']['options'])) {
1234 - $options = $cart_row['options'];
1235 - $optstr = '';
1236 - if(is_array($options) && count($options) > 0) {
1237 - foreach((array)$options as $key => $value) {
1238 - if(!empty($key)) {
1239 - if(is_array($value)) {
1240 - foreach($value as $v) {
1241 - $optstr .= usces_entity_decode(urldecode($key), $ext).$sp;
1242 - foreach($value as $v) {
1243 - $optstr .= usces_entity_decode(urldecode($v), $ext).$nb;
1244 - }
1245 - }
1246 - } else {
1247 - //$optstr .= usces_entity_decode($key, $ext).$sp.usces_entity_decode($value, $ext).$nb;
1248 - $optstr .= usces_entity_decode(urldecode($key).$sp.urldecode($value), $ext).$nb;
1249 - }
1250 - }
1251 - }
1252 - }
1253 - $line .= $td_h.$optstr.$td_f;
1254 - }
1255 - $line .= $td_h.$cart_row['quantity'].$td_f;
1256 - $line .= $td_h.usces_crform($cart_row['price'], false, false, 'return', false).$td_f;
1257 - if(isset($_REQUEST['check']['unit'])) $line .= $td_h.usces_entity_decode($usces->getItemSkuUnit($post_id, $sku), $ext).$td_f;
1258 - $line .= apply_filters( 'usces_filter_chk_pro_data_detail', NULL, $usces_opt_order, $data, $cart_row);
1259 - $line .= $tr_f.$lf;
1260 - }
1261 - }
1262 - $line .= $table_f.$lf;
1263 - //==========================================================================
1264 -
1265 - if($ext == 'xls') {
1266 - header("Content-Type: application/vnd.ms-excel; charset=Shift-JIS");
1267 - } elseif($ext == 'csv') {
1268 - header("Content-Type: application/octet-stream");
1269 - }
1270 - header("Content-Disposition: attachment; filename=usces_product_list.".$ext);
1271 - mb_http_output('pass');
1272 - print(mb_convert_encoding($line, "SJIS-win", "UTF-8"));
1273 - exit();
1274 -}
1275 -
1276 -// order list download
1277 -function usces_download_order_list() {
1278 - require_once( USCES_PLUGIN_DIR . "/classes/orderList.class.php" );
1279 - global $wpdb, $usces;
1280 -//20110411ysk start
1281 - global $usces_settings;
1282 -//20110411ysk end
1283 -
1284 - $ext = $_REQUEST['ftype'];
1285 -/* if($ext == 'xls') {//HTML
1286 - $table_h = "<table>";
1287 - $table_f = "</table>";
1288 - $tr_h = "<tr>";
1289 - $tr_f = "</tr>";
1290 - $th_h1 = "<th>";
1291 - $th_h = "<th>";
1292 - $th_f = "</th>";
1293 - $td_h1 = "<td>";
1294 - $td_h = "<td>";
1295 - $td_f = "</td>";
1296 - $sp = ":";
1297 - $lf = "\n";
1298 -*/ if($ext == 'xls') {//TSV
1299 - $table_h = "";
1300 - $table_f = "";
1301 - $tr_h = "";
1302 - $tr_f = "";
1303 - $th_h1 = '"';
1304 - $th_h = "\t".'"';
1305 - $th_f = '"';
1306 - $td_h1 = '"';
1307 - $td_h = "\t".'"';
1308 - $td_f = '"';
1309 - $sp = ":";
1310 - $lf = "\n";
1311 - } elseif($ext == 'csv') {//CSV
1312 - $table_h = "";
1313 - $table_f = "";
1314 - $tr_h = "";
1315 - $tr_f = "";
1316 -//20110201ysk start
1317 - //$th_h1 = "";
1318 - $th_h1 = '"';
1319 - //$th_h = ",";
1320 - $th_h = ',"';
1321 - //$th_f = "";
1322 - $th_f = '"';
1323 - //$td_h1 = "";
1324 - $td_h1 = '"';
1325 - //$td_h = ",";
1326 - $td_h = ',"';
1327 - //$td_f = "";
1328 - $td_f = '"';
1329 -//20110201ysk end
1330 - $sp = ":";
1331 - $lf = "\n";
1332 - } else {
1333 - exit();
1334 - }
1335 - $csod_meta = usces_has_custom_field_meta('order');
1336 - $cscs_meta = usces_has_custom_field_meta('customer');
1337 - $csde_meta = usces_has_custom_field_meta('delivery');
1338 -//20110411ysk start
1339 - $applyform = usces_get_apply_addressform($usces->options['system']['addressform']);
1340 -//20110411ysk end
1341 -
1342 - //==========================================================================
1343 - $usces_opt_order = get_option('usces_opt_order');
1344 - if(!is_array($usces_opt_order)){
1345 - $usces_opt_order = array();
1346 - }
1347 - $usces_opt_order['ftype_ord'] = $ext;
1348 - $chk_ord = array();
1349 - $chk_ord['ID'] = 1;
1350 - $chk_ord['deco_id'] = 1;
1351 - $chk_ord['date'] = 1;
1352 - $chk_ord['mem_id'] = (isset($_REQUEST['check']['mem_id'])) ? 1 : 0;
1353 - $chk_ord['email'] = (isset($_REQUEST['check']['email'])) ? 1 : 0;
1354 - if(!empty($cscs_meta)) {
1355 - foreach($cscs_meta as $key => $entry) {
1356 - if($entry['position'] == 'name_pre') {
1357 - $name = $entry['name'];
1358 -//20110208ysk start
1359 - $cscs_key = 'cscs_'.$key;
1360 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1361 - $chk_ord[$cscs_key] = (isset($_REQUEST['check'][$cscs_key])) ? 1 : 0;
1362 -//20110208ysk end
1363 - }
1364 - }
1365 - }
1366 - $chk_ord['name'] = 1;
1367 -//20110411ysk start
1368 - if($applyform == 'JP') {
1369 - $chk_ord['kana'] = (isset($_REQUEST['check']['kana'])) ? 1 : 0;
1370 - }
1371 -//20110411ysk end
1372 - if(!empty($cscs_meta)) {
1373 - foreach($cscs_meta as $key => $entry) {
1374 - if($entry['position'] == 'name_after') {
1375 - $name = $entry['name'];
1376 -//20110208ysk start
1377 - $cscs_key = 'cscs_'.$key;
1378 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1379 - $chk_ord[$cscs_key] = (isset($_REQUEST['check'][$cscs_key])) ? 1 : 0;
1380 -//20110208ysk end
1381 - }
1382 - }
1383 - }
1384 - $chk_ord['zip'] = (isset($_REQUEST['check']['zip'])) ? 1 : 0;
1385 -//20110411ysk start
1386 - $chk_ord['country'] = (isset($_REQUEST['check']['country'])) ? 1 : 0;
1387 -//20110411ysk end
1388 - $chk_ord['pref'] = (isset($_REQUEST['check']['pref'])) ? 1 : 0;
1389 - $chk_ord['address1'] = (isset($_REQUEST['check']['address1'])) ? 1 : 0;
1390 - $chk_ord['address2'] = (isset($_REQUEST['check']['address2'])) ? 1 : 0;
1391 - $chk_ord['address3'] = (isset($_REQUEST['check']['address3'])) ? 1 : 0;
1392 - $chk_ord['tel'] = (isset($_REQUEST['check']['tel'])) ? 1 : 0;
1393 - $chk_ord['fax'] = (isset($_REQUEST['check']['fax'])) ? 1 : 0;
1394 - if(!empty($cscs_meta)) {
1395 - foreach($cscs_meta as $key => $entry) {
1396 - if($entry['position'] == 'fax_after') {
1397 - $name = $entry['name'];
1398 -//20110208ysk start
1399 - $cscs_key = 'cscs_'.$key;
1400 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1401 - $chk_ord[$cscs_key] = (isset($_REQUEST['check'][$cscs_key])) ? 1 : 0;
1402 -//20110208ysk end
1403 - }
1404 - }
1405 - }
1406 - //--------------------------------------------------------------------------
1407 - if(!empty($csde_meta)) {
1408 - foreach($csde_meta as $key => $entry) {
1409 - if($entry['position'] == 'name_pre') {
1410 - $name = $entry['name'];
1411 -//20110208ysk start
1412 - $csde_key = 'csde_'.$key;
1413 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1414 - $chk_ord[$csde_key] = (isset($_REQUEST['check'][$csde_key])) ? 1 : 0;
1415 -//20110208ysk end
1416 - }
1417 - }
1418 - }
1419 - $chk_ord['delivery_name'] = (isset($_REQUEST['check']['delivery_name'])) ? 1 : 0;
1420 -//20110411ysk start
1421 - if($applyform == 'JP') {
1422 - $chk_ord['delivery_kana'] = (isset($_REQUEST['check']['delivery_kana'])) ? 1 : 0;
1423 - }
1424 -//20110411ysk end
1425 - if(!empty($csde_meta)) {
1426 - foreach($csde_meta as $key => $entry) {
1427 - if($entry['position'] == 'name_after') {
1428 - $name = $entry['name'];
1429 -//20110208ysk start
1430 - $csde_key = 'csde_'.$key;
1431 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1432 - $chk_ord[$csde_key] = (isset($_REQUEST['check'][$csde_key])) ? 1 : 0;
1433 -//20110208ysk end
1434 - }
1435 - }
1436 - }
1437 - $chk_ord['delivery_zip'] = (isset($_REQUEST['check']['delivery_zip'])) ? 1 : 0;
1438 -//20110411ysk start
1439 - $chk_ord['delivery_country'] = (isset($_REQUEST['check']['delivery_country'])) ? 1 : 0;
1440 -//20110411ysk end
1441 - $chk_ord['delivery_pref'] = (isset($_REQUEST['check']['delivery_pref'])) ? 1 : 0;
1442 - $chk_ord['delivery_address1'] = (isset($_REQUEST['check']['delivery_address1'])) ? 1 : 0;
1443 - $chk_ord['delivery_address2'] = (isset($_REQUEST['check']['delivery_address2'])) ? 1 : 0;
1444 - $chk_ord['delivery_address3'] = (isset($_REQUEST['check']['delivery_address3'])) ? 1 : 0;
1445 - $chk_ord['delivery_tel'] = (isset($_REQUEST['check']['delivery_tel'])) ? 1 : 0;
1446 - $chk_ord['delivery_fax'] = (isset($_REQUEST['check']['delivery_fax'])) ? 1 : 0;
1447 - if(!empty($csde_meta)) {
1448 - foreach($csde_meta as $key => $entry) {
1449 - if($entry['position'] == 'fax_after') {
1450 - $name = $entry['name'];
1451 -//20110208ysk start
1452 - $csde_key = 'csde_'.$key;
1453 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1454 - $chk_ord[$csde_key] = (isset($_REQUEST['check'][$csde_key])) ? 1 : 0;
1455 -//20110208ysk end
1456 - }
1457 - }
1458 - }
1459 - //--------------------------------------------------------------------------
1460 - $chk_ord['shipping_date'] = (isset($_REQUEST['check']['shipping_date'])) ? 1 : 0;
1461 - $chk_ord['peyment_method'] = (isset($_REQUEST['check']['peyment_method'])) ? 1 : 0;
1462 - $chk_ord['delivery_method'] = (isset($_REQUEST['check']['delivery_method'])) ? 1 : 0;
1463 -//20101208ysk start
1464 - $chk_ord['delivery_date'] = (isset($_REQUEST['check']['delivery_date'])) ? 1 : 0;
1465 -//20101208ysk end
1466 - $chk_ord['delivery_time'] = (isset($_REQUEST['check']['delivery_time'])) ? 1 : 0;
1467 - $chk_ord['delidue_date'] = (isset($_REQUEST['check']['delidue_date'])) ? 1 : 0;
1468 - $chk_ord['status'] = (isset($_REQUEST['check']['status'])) ? 1 : 0;
1469 - $chk_ord['total_amount'] = 1;
1470 - $chk_ord['getpoint'] = (isset($_REQUEST['check']['getpoint'])) ? 1 : 0;
1471 - $chk_ord['usedpoint'] = (isset($_REQUEST['check']['usedpoint'])) ? 1 : 0;
1472 - $chk_ord['discount'] = 1;
1473 - $chk_ord['shipping_charge'] = 1;
1474 - $chk_ord['cod_fee'] = 1;
1475 - $chk_ord['tax'] = 1;
1476 - $chk_ord['note'] = (isset($_REQUEST['check']['note'])) ? 1 : 0;
1477 - if(!empty($csod_meta)) {
1478 - foreach($csod_meta as $key => $entry) {
1479 - $name = $entry['name'];
1480 -//20110208ysk start
1481 - $csod_key = 'csod_'.$key;
1482 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1483 - $chk_ord[$csod_key] = (isset($_REQUEST['check'][$csod_key])) ? 1 : 0;
1484 -//20110208ysk end
1485 - }
1486 - }
1487 - $usces_opt_order['chk_ord'] = apply_filters( 'usces_filter_chk_ord', $chk_ord );
1488 - update_option('usces_opt_order', $usces_opt_order);
1489 - //==========================================================================
1490 -
1491 - if(isset($_REQUEST['check']['status'])) {
1492 - //$usces_management_status = get_option('usces_management_status');
1493 - $usces_management_status = apply_filters( 'usces_filter_management_status', get_option('usces_management_status') );//0000530
1494 - $usces_management_status['new'] = __('new order', 'usces');
1495 - }
1496 -
1497 - $_REQUEST['searchIn'] = "searchIn";
1498 - $tableName = $wpdb->prefix."usces_order";
1499 - $arr_column = array(
1500 - __('ID', 'usces') => 'ID',
1501 - __('Order number', 'usces') => 'deco_id',
1502 - __('date', 'usces') => 'date',
1503 - __('membership number', 'usces') => 'mem_id',
1504 - __('name', 'usces') => 'name',
1505 - __('Region', 'usces') => 'pref',
1506 - __('shipping option', 'usces') => 'delivery_method',
1507 - __('Amount', 'usces') => 'total_price',
1508 - __('payment method', 'usces') => 'payment_name',
1509 - __('transfer statement', 'usces') => 'receipt_status',
1510 - __('Processing', 'usces') => 'order_status',
1511 - __('shpping date', 'usces') => 'order_modified');
1512 - $DT = new dataList($tableName, $arr_column);
1513 -//20101202ysk start
1514 - $DT->pageLimit = 'off';
1515 -//20101202ysk end
1516 - $res = $DT->MakeTable();
1517 - $rows = $DT->rows;
1518 -
1519 - //==========================================================================
1520 - $line = $table_h;
1521 - $line .= $tr_h;
1522 - $line .= $th_h1.__('ID', 'usces').$th_f;
1523 - $line .= $th_h.__('Order number', 'usces').$th_f;
1524 - $line .= $th_h.__('order date', 'usces').$th_f;
1525 - if(isset($_REQUEST['check']['mem_id'])) $line .= $th_h.__('membership number', 'usces').$th_f;
1526 - if(isset($_REQUEST['check']['email'])) $line .= $th_h.__('e-mail', 'usces').$th_f;
1527 - if(!empty($cscs_meta)) {
1528 - foreach($cscs_meta as $key => $entry) {
1529 - if($entry['position'] == 'name_pre') {
1530 - $name = $entry['name'];
1531 -//20110208ysk start
1532 - $cscs_key = 'cscs_'.$key;
1533 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1534 - if(isset($_REQUEST['check'][$cscs_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1535 -//20110208ysk end
1536 - }
1537 - }
1538 - }
1539 - $line .= $th_h.__('name', 'usces').$th_f;
1540 -//20110411ysk start
1541 - if($applyform == 'JP') {
1542 - if(isset($_REQUEST['check']['kana'])) $line .= $th_h.__('furigana', 'usces').$th_f;
1543 - }
1544 -//20110411ysk end
1545 - if(!empty($cscs_meta)) {
1546 - foreach($cscs_meta as $key => $entry) {
1547 - if($entry['position'] == 'name_after') {
1548 - $name = $entry['name'];
1549 -//20110208ysk start
1550 - $cscs_key = 'cscs_'.$key;
1551 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1552 - if(isset($_REQUEST['check'][$cscs_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1553 -//20110208ysk end
1554 - }
1555 - }
1556 - }
1557 -//20110411ysk start
1558 - switch($applyform) {
1559 - case 'JP':
1560 - if(isset($_REQUEST['check']['zip'])) $line .= $th_h.__('Zip/Postal Code', 'usces').$th_f;
1561 - if(isset($_REQUEST['check']['country'])) $line .= $th_h.__('Country', 'usces').$th_f;
1562 - if(isset($_REQUEST['check']['pref'])) $line .= $th_h.__('Province', 'usces').$th_f;
1563 - if(isset($_REQUEST['check']['address1'])) $line .= $th_h.__('city', 'usces').$th_f;
1564 - if(isset($_REQUEST['check']['address2'])) $line .= $th_h.__('numbers', 'usces').$th_f;
1565 - if(isset($_REQUEST['check']['address3'])) $line .= $th_h.__('building name', 'usces').$th_f;
1566 - if(isset($_REQUEST['check']['tel'])) $line .= $th_h.__('Phone number', 'usces').$th_f;
1567 - if(isset($_REQUEST['check']['fax'])) $line .= $th_h.__('FAX number', 'usces').$th_f;
1568 - break;
1569 - case 'US':
1570 - default:
1571 - if(isset($_REQUEST['check']['address2'])) $line .= $th_h.__('Address Line1', 'usces').$th_f;
1572 - if(isset($_REQUEST['check']['address3'])) $line .= $th_h.__('Address Line2', 'usces').$th_f;
1573 - if(isset($_REQUEST['check']['address1'])) $line .= $th_h.__('city', 'usces').$th_f;
1574 - if(isset($_REQUEST['check']['pref'])) $line .= $th_h.__('State', 'usces').$th_f;
1575 - if(isset($_REQUEST['check']['country'])) $line .= $th_h.__('Country', 'usces').$th_f;
1576 - if(isset($_REQUEST['check']['zip'])) $line .= $th_h.__('Zip', 'usces').$th_f;
1577 - if(isset($_REQUEST['check']['tel'])) $line .= $th_h.__('Phone number', 'usces').$th_f;
1578 - if(isset($_REQUEST['check']['fax'])) $line .= $th_h.__('FAX number', 'usces').$th_f;
1579 - break;
1580 - }
1581 -//20110411ysk end
1582 - if(!empty($cscs_meta)) {
1583 - foreach($cscs_meta as $key => $entry) {
1584 - if($entry['position'] == 'fax_after') {
1585 - $name = $entry['name'];
1586 -//20110208ysk start
1587 - $cscs_key = 'cscs_'.$key;
1588 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1589 - if(isset($_REQUEST['check'][$cscs_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1590 -//20110208ysk end
1591 - }
1592 - }
1593 - }
1594 - $line .= apply_filters( 'usces_filter_chk_ord_label_customer', NULL, $usces_opt_order, $rows );
1595 -
1596 - //--------------------------------------------------------------------------
1597 - if(!empty($csde_meta)) {
1598 - foreach($csde_meta as $key => $entry) {
1599 - if($entry['position'] == 'name_pre') {
1600 - $name = $entry['name'];
1601 -//20110208ysk start
1602 - $csde_key = 'csde_'.$key;
1603 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1604 - if(isset($_REQUEST['check'][$csde_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1605 -//20110208ysk end
1606 - }
1607 - }
1608 - }
1609 - if(isset($_REQUEST['check']['delivery_name'])) $line .= $th_h.__('Shipping Name', 'usces').$th_f;
1610 -//20110411ysk start
1611 - if($applyform == 'JP') {
1612 - if(isset($_REQUEST['check']['delivery_kana'])) $line .= $th_h.__('Shipping Furigana', 'usces').$th_f;
1613 - }
1614 -//20110411ysk end
1615 - if(!empty($csde_meta)) {
1616 - foreach($csde_meta as $key => $entry) {
1617 - if($entry['position'] == 'name_after') {
1618 - $name = $entry['name'];
1619 -//20110208ysk start
1620 - $csde_key = 'csde_'.$key;
1621 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1622 - if(isset($_REQUEST['check'][$csde_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1623 -//20110208ysk end
1624 - }
1625 - }
1626 - }
1627 -//20110411ysk start
1628 - switch($applyform) {
1629 - case 'JP':
1630 - if(isset($_REQUEST['check']['delivery_zip'])) $line .= $th_h.__('Shipping Zip', 'usces').$th_f;
1631 - if(isset($_REQUEST['check']['delivery_country'])) $line .= $th_h.__('Shipping Country', 'usces').$th_f;
1632 - if(isset($_REQUEST['check']['delivery_pref'])) $line .= $th_h.__('Shipping State', 'usces').$th_f;
1633 - if(isset($_REQUEST['check']['delivery_address1'])) $line .= $th_h.__('Shipping City', 'usces').$th_f;
1634 - if(isset($_REQUEST['check']['delivery_address2'])) $line .= $th_h.__('Shipping Address1', 'usces').$th_f;
1635 - if(isset($_REQUEST['check']['delivery_address3'])) $line .= $th_h.__('Shipping Address2', 'usces').$th_f;
1636 - if(isset($_REQUEST['check']['delivery_tel'])) $line .= $th_h.__('Shipping Phone', 'usces').$th_f;
1637 - if(isset($_REQUEST['check']['delivery_fax'])) $line .= $th_h.__('Shipping FAX', 'usces').$th_f;
1638 - break;
1639 - case 'US':
1640 - default:
1641 - if(isset($_REQUEST['check']['delivery_address2'])) $line .= $th_h.__('Shipping Address1', 'usces').$th_f;
1642 - if(isset($_REQUEST['check']['delivery_address3'])) $line .= $th_h.__('Shipping Address2', 'usces').$th_f;
1643 - if(isset($_REQUEST['check']['delivery_address1'])) $line .= $th_h.__('Shipping City', 'usces').$th_f;
1644 - if(isset($_REQUEST['check']['delivery_pref'])) $line .= $th_h.__('Shipping State', 'usces').$th_f;
1645 - if(isset($_REQUEST['check']['delivery_country'])) $line .= $th_h.__('Shipping Country', 'usces').$th_f;
1646 - if(isset($_REQUEST['check']['delivery_zip'])) $line .= $th_h.__('Shipping Zip', 'usces').$th_f;
1647 - if(isset($_REQUEST['check']['delivery_tel'])) $line .= $th_h.__('Shipping Phone', 'usces').$th_f;
1648 - if(isset($_REQUEST['check']['delivery_fax'])) $line .= $th_h.__('Shipping FAX', 'usces').$th_f;
1649 - break;
1650 - }
1651 -//20110411ysk end
1652 - if(!empty($csde_meta)) {
1653 - foreach($csde_meta as $key => $entry) {
1654 - if($entry['position'] == 'fax_after') {
1655 - $name = $entry['name'];
1656 -//20110208ysk start
1657 - $csde_key = 'csde_'.$key;
1658 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1659 - if(isset($_REQUEST['check'][$csde_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1660 -//20110208ysk end
1661 - }
1662 - }
1663 - }
1664 - $line .= apply_filters( 'usces_filter_chk_ord_label_delivery', NULL, $usces_opt_order, $rows );
1665 - //--------------------------------------------------------------------------
1666 - if(isset($_REQUEST['check']['shipping_date'])) $line .= $th_h.__('shpping date', 'usces').$th_f;
1667 - if(isset($_REQUEST['check']['peyment_method'])) $line .= $th_h.__('payment method', 'usces').$th_f;
1668 - if(isset($_REQUEST['check']['delivery_method'])) $line .= $th_h.__('shipping option', 'usces').$th_f;
1669 -//20101208ysk start
1670 - if(isset($_REQUEST['check']['delivery_date'])) $line .= $th_h.__('Delivery date', 'usces').$th_f;
1671 -//20101208ysk end
1672 - if(isset($_REQUEST['check']['delivery_time'])) $line .= $th_h.__('delivery time', 'usces').$th_f;
1673 - if(isset($_REQUEST['check']['delidue_date'])) $line .= $th_h.__('Shipping date', 'usces').$th_f;
1674 - if(isset($_REQUEST['check']['status'])) $line .= $th_h.__('Status', 'usces').$th_f;
1675 - $line .= $th_h.__('Total Amount', 'usces').$th_f;
1676 - if(isset($_REQUEST['check']['getpoint'])) $line .= $th_h.__('granted points', 'usces').$th_f;
1677 - if(isset($_REQUEST['check']['usedpoint'])) $line .= $th_h.__('Used points', 'usces').$th_f;
1678 - $line .= $th_h.__('Disnount', 'usces').$th_f;
1679 - $line .= $th_h.__('Shipping', 'usces').$th_f;
1680 - $line .= $th_h.apply_filters('usces_filter_cod_label', __('COD fee', 'usces')).$th_f;
1681 - $line .= $th_h.__('consumption tax', 'usces').$th_f;
1682 - if(isset($_REQUEST['check']['note'])) $line .= $th_h.__('Notes', 'usces').$th_f;
1683 - if(!empty($csod_meta)) {
1684 - foreach($csod_meta as $key => $entry) {
1685 - $name = $entry['name'];
1686 -//20110208ysk start
1687 - $csod_key = 'csod_'.$key;
1688 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1689 - if(isset($_REQUEST['check'][$csod_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1690 -//20110208ysk end
1691 - }
1692 - }
1693 - $line .= apply_filters( 'usces_filter_chk_ord_label_order', NULL, $usces_opt_order, $rows );
1694 - $line .= $tr_f.$lf;
1695 - //==========================================================================
1696 - foreach((array)$rows as $array) {
1697 - $order_id = $array['ID'];
1698 - $query = $wpdb->prepare("SELECT * FROM $tableName WHERE ID = %d", $order_id);
1699 - $data = $wpdb->get_row( $query, ARRAY_A );
1700 - //$deli = stripslashes_deep(unserialize($data['order_delivery']));
1701 - $deli = unserialize($data['order_delivery']);
1702 - //if(!empty($data)) {
1703 - // $data = stripslashes_deep($data);
1704 - //}
1705 -
1706 - $line .= $tr_h;
1707 - $line .= $td_h1.$order_id.$td_f;
1708 - $line .= $td_h.usces_get_deco_order_id( $order_id ).$td_f;
1709 - $line .= $td_h.$data['order_date'].$td_f;
1710 - if(isset($_REQUEST['check']['mem_id'])) $line .= $td_h.$data['mem_id'].$td_f;
1711 - if(isset($_REQUEST['check']['email'])) $line .= $td_h.usces_entity_decode($data['order_email'], $ext).$td_f;
1712 - if(!empty($cscs_meta)) {
1713 - foreach($cscs_meta as $key => $entry) {
1714 - if($entry['position'] == 'name_pre') {
1715 - $name = $entry['name'];
1716 - $cscs_key = 'cscs_'.$key;
1717 -//20110208ysk start
1718 - //if(isset($_REQUEST['check'][$name])) {
1719 - if(isset($_REQUEST['check'][$cscs_key])) {
1720 -//20110208ysk end
1721 - $value = maybe_unserialize($usces->get_order_meta_value($cscs_key, $order_id));
1722 - if(empty($value)) {
1723 - $value = '';
1724 - } elseif(is_array($value)) {
1725 - $concatval = '';
1726 - $c = '';
1727 - foreach($value as $v) {
1728 - $concatval .= $c.$v;
1729 - $c = ' ';
1730 - }
1731 - $value = $concatval;
1732 - }
1733 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
1734 - }
1735 - }
1736 - }
1737 - }
1738 -//20110411ysk start
1739 - switch($applyform) {
1740 - case 'JP':
1741 - $line .= $td_h.usces_entity_decode($data['order_name1'].' '.$data['order_name2'], $ext).$td_f;
1742 - if(isset($_REQUEST['check']['kana'])) $line .= $td_h.usces_entity_decode($data['order_name3'].' '.$data['order_name4'], $ext).$td_f;
1743 - break;
1744 - case 'US':
1745 - default:
1746 - $line .= $td_h.usces_entity_decode($data['order_name2'].' '.$data['order_name1'], $ext).$td_f;
1747 - break;
1748 - }
1749 -//20110411ysk end
1750 - if(!empty($cscs_meta)) {
1751 - foreach($cscs_meta as $key => $entry) {
1752 - if($entry['position'] == 'name_after') {
1753 - $name = $entry['name'];
1754 - $cscs_key = 'cscs_'.$key;
1755 -//20110208ysk start
1756 - //if(isset($_REQUEST['check'][$name])) {
1757 - if(isset($_REQUEST['check'][$cscs_key])) {
1758 -//20110208ysk end
1759 - $value = maybe_unserialize($usces->get_order_meta_value($cscs_key, $order_id));
1760 - if(empty($value)) {
1761 - $value = '';
1762 - } elseif(is_array($value)) {
1763 - $concatval = '';
1764 - $c = '';
1765 - foreach($value as $v) {
1766 - $concatval .= $c.$v;
1767 - $c = ' ';
1768 - }
1769 - $value = $concatval;
1770 - }
1771 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
1772 - }
1773 - }
1774 - }
1775 - }
1776 -//20110411ysk start
1777 - $address_info = '';
1778 - switch($applyform) {
1779 - case 'JP':
1780 - if(isset($_REQUEST['check']['zip'])) $address_info .= $td_h.usces_entity_decode($data['order_zip'], $ext).$td_f;
1781 - if(isset($_REQUEST['check']['country'])) $address_info .= $td_h.$usces_settings['country'][$usces->get_order_meta_value('customer_country', $order_id)].$td_f;
1782 - if(isset($_REQUEST['check']['pref'])) $address_info .= $td_h.usces_entity_decode($data['order_pref'], $ext).$td_f;
1783 - if(isset($_REQUEST['check']['address1'])) $address_info .= $td_h.usces_entity_decode($data['order_address1'], $ext).$td_f;
1784 - if(isset($_REQUEST['check']['address2'])) $address_info .= $td_h.usces_entity_decode($data['order_address2'], $ext).$td_f;
1785 - if(isset($_REQUEST['check']['address3'])) $address_info .= $td_h.usces_entity_decode($data['order_address3'], $ext).$td_f;
1786 - if(isset($_REQUEST['check']['tel'])) $address_info .= $td_h.usces_entity_decode($data['order_tel'], $ext).$td_f;
1787 - if(isset($_REQUEST['check']['fax'])) $address_info .= $td_h.usces_entity_decode($data['order_fax'], $ext).$td_f;
1788 - break;
1789 - case 'US':
1790 - default:
1791 - if(isset($_REQUEST['check']['address2'])) $address_info .= $td_h.usces_entity_decode($data['order_address2'], $ext).$td_f;
1792 - if(isset($_REQUEST['check']['address3'])) $address_info .= $td_h.usces_entity_decode($data['order_address3'], $ext).$td_f;
1793 - if(isset($_REQUEST['check']['address1'])) $address_info .= $td_h.usces_entity_decode($data['order_address1'], $ext).$td_f;
1794 - if(isset($_REQUEST['check']['pref'])) $address_info .= $td_h.usces_entity_decode($data['order_pref'], $ext).$td_f;
1795 - if(isset($_REQUEST['check']['country'])) $address_info .= $td_h.$usces_settings['country'][$usces->get_order_meta_value('customer_country', $order_id)].$td_f;
1796 - if(isset($_REQUEST['check']['zip'])) $address_info .= $td_h.usces_entity_decode($data['order_zip'], $ext).$td_f;
1797 - if(isset($_REQUEST['check']['tel'])) $address_info .= $td_h.usces_entity_decode($data['order_tel'], $ext).$td_f;
1798 - if(isset($_REQUEST['check']['fax'])) $address_info .= $td_h.usces_entity_decode($data['order_fax'], $ext).$td_f;
1799 - break;
1800 - }
1801 - $address_info_args = compact( 'td_h', 'td_f', 'ext', 'order_id', 'applyform' );
1802 - $line .= apply_filters( 'usces_filter_ord_csv_address_info', $address_info, $data, $address_info_args );
1803 -//20110411ysk end
1804 - if(!empty($cscs_meta)) {
1805 - foreach($cscs_meta as $key => $entry) {
1806 - if($entry['position'] == 'fax_after') {
1807 - $name = $entry['name'];
1808 - $cscs_key = 'cscs_'.$key;
1809 -//20110208ysk start
1810 - //if(isset($_REQUEST['check'][$name])) {
1811 - if(isset($_REQUEST['check'][$cscs_key])) {
1812 -//20110208ysk end
1813 - $value = maybe_unserialize($usces->get_order_meta_value($cscs_key, $order_id));
1814 - if(empty($value)) {
1815 - $value = '';
1816 - } elseif(is_array($value)) {
1817 - $concatval = '';
1818 - $c = '';
1819 - foreach($value as $v) {
1820 - $concatval .= $c.$v;
1821 - $c = ' ';
1822 - }
1823 - $value = $concatval;
1824 - }
1825 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
1826 - }
1827 - }
1828 - }
1829 - }
1830 - $line .= apply_filters( 'usces_filter_chk_ord_data_customer', NULL, $usces_opt_order, $order_id, $data );
1831 - //----------------------------------------------------------------------
1832 - if(!empty($csde_meta)) {
1833 - foreach($csde_meta as $key => $entry) {
1834 - if($entry['position'] == 'name_pre') {
1835 - $name = $entry['name'];
1836 - $csde_key = 'csde_'.$key;
1837 -//20110208ysk start
1838 - //if(isset($_REQUEST['check'][$name])) {
1839 - if(isset($_REQUEST['check'][$csde_key])) {
1840 -//20110208ysk end
1841 - $value = maybe_unserialize($usces->get_order_meta_value($csde_key, $order_id));
1842 - if(empty($value)) {
1843 - $value = '';
1844 - } elseif(is_array($value)) {
1845 - $concatval = '';
1846 - $c = '';
1847 - foreach($value as $v) {
1848 - $concatval .= $c.$v;
1849 - $c = ' ';
1850 - }
1851 - $value = $concatval;
1852 - }
1853 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
1854 - }
1855 - }
1856 - }
1857 - }
1858 -//20110411ysk start
1859 - switch($applyform) {
1860 - case 'JP':
1861 - if(isset($_REQUEST['check']['delivery_name'])) $line .= $td_h.usces_entity_decode($deli['name1'].' '.$deli['name2'], $ext).$td_f;
1862 - if(isset($_REQUEST['check']['delivery_kana'])) $line .= $td_h.usces_entity_decode($deli['name3'].' '.$deli['name4'], $ext).$td_f;
1863 - break;
1864 - case 'US':
1865 - default:
1866 - if(isset($_REQUEST['check']['delivery_name'])) $line .= $td_h.usces_entity_decode($deli['name2'].' '.$deli['name1'], $ext).$td_f;
1867 - break;
1868 - }
1869 -//20110411ysk end
1870 - if(!empty($csde_meta)) {
1871 - foreach($csde_meta as $key => $entry) {
1872 - if($entry['position'] == 'name_after') {
1873 - $name = $entry['name']."</td>";
1874 - $csde_key = 'csde_'.$key;
1875 -//20110208ysk start
1876 - //if(isset($_REQUEST['check'][$name])) {
1877 - if(isset($_REQUEST['check'][$csde_key])) {
1878 -//20110208ysk end
1879 - $value = maybe_unserialize($usces->get_order_meta_value($csde_key, $order_id));
1880 - if(empty($value)) {
1881 - $value = '';
1882 - } elseif(is_array($value)) {
1883 - $concatval = '';
1884 - $c = '';
1885 - foreach($value as $v) {
1886 - $concatval .= $c.$v;
1887 - $c = ' ';
1888 - }
1889 - $value = $concatval;
1890 - }
1891 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
1892 - }
1893 - }
1894 - }
1895 - }
1896 -//20110411ysk start
1897 - $address_info = '';
1898 - switch($applyform) {
1899 - case 'JP':
1900 - if(isset($_REQUEST['check']['delivery_zip'])) $address_info .= $td_h.usces_entity_decode($deli['zipcode'], $ext).$td_f;
1901 - if(isset($_REQUEST['check']['delivery_country'])) $address_info .= $td_h.$usces_settings['country'][$deli['country']].$td_f;
1902 - if(isset($_REQUEST['check']['delivery_pref'])) $address_info .= $td_h.usces_entity_decode($deli['pref'], $ext).$td_f;
1903 - if(isset($_REQUEST['check']['delivery_address1'])) $address_info .= $td_h.usces_entity_decode($deli['address1'], $ext).$td_f;
1904 - if(isset($_REQUEST['check']['delivery_address2'])) $address_info .= $td_h.usces_entity_decode($deli['address2'], $ext).$td_f;
1905 - if(isset($_REQUEST['check']['delivery_address3'])) $address_info .= $td_h.usces_entity_decode($deli['address3'], $ext).$td_f;
1906 - if(isset($_REQUEST['check']['delivery_tel'])) $address_info .= $td_h.usces_entity_decode($deli['tel'], $ext).$td_f;
1907 - if(isset($_REQUEST['check']['delivery_fax'])) $address_info .= $td_h.usces_entity_decode($deli['fax'], $ext).$td_f;
1908 - break;
1909 - case 'US':
1910 - default:
1911 - if(isset($_REQUEST['check']['delivery_address2'])) $address_info .= $td_h.usces_entity_decode($deli['address2'], $ext).$td_f;
1912 - if(isset($_REQUEST['check']['delivery_address3'])) $address_info .= $td_h.usces_entity_decode($deli['address3'], $ext).$td_f;
1913 - if(isset($_REQUEST['check']['delivery_address1'])) $address_info .= $td_h.usces_entity_decode($deli['address1'], $ext).$td_f;
1914 - if(isset($_REQUEST['check']['delivery_pref'])) $address_info .= $td_h.usces_entity_decode($deli['pref'], $ext).$td_f;
1915 - if(isset($_REQUEST['check']['delivery_country'])) $address_info .= $td_h.$usces_settings['country'][$deli['country']].$td_f;
1916 - if(isset($_REQUEST['check']['delivery_zip'])) $address_info .= $td_h.usces_entity_decode($deli['zipcode'], $ext).$td_f;
1917 - if(isset($_REQUEST['check']['delivery_tel'])) $address_info .= $td_h.usces_entity_decode($deli['tel'], $ext).$td_f;
1918 - if(isset($_REQUEST['check']['delivery_fax'])) $address_info .= $td_h.usces_entity_decode($deli['fax'], $ext).$td_f;
1919 - break;
1920 - }
1921 - $line .= apply_filters( 'usces_filter_ord_csv_delivery_address_info', $address_info, $deli, $address_info_args );
1922 -//20110411ysk end
1923 - if(!empty($csde_meta)) {
1924 - foreach($csde_meta as $key => $entry) {
1925 - if($entry['position'] == 'fax_after') {
1926 - $name = $entry['name'];
1927 - $csde_key = 'csde_'.$key;
1928 -//20110208ysk start
1929 - //if(isset($_REQUEST['check'][$name])) {
1930 - if(isset($_REQUEST['check'][$csde_key])) {
1931 -//20110208ysk end
1932 - $value = maybe_unserialize($usces->get_order_meta_value($csde_key, $order_id));
1933 - if(empty($value)) {
1934 - $value = '';
1935 - } elseif(is_array($value)) {
1936 - $concatval = '';
1937 - $c = '';
1938 - foreach($value as $v) {
1939 - $concatval .= $c.$v;
1940 - $c = ' ';
1941 - }
1942 - $value = $concatval;
1943 - }
1944 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
1945 - }
1946 - }
1947 - }
1948 - }
1949 - $line .= apply_filters( 'usces_filter_chk_ord_data_delivery', NULL, $usces_opt_order, $order_id, $deli );
1950 - //----------------------------------------------------------------------
1951 - if(isset($_REQUEST['check']['shipping_date'])) $line .= $td_h.$data['order_modified'].$td_f;
1952 - if(isset($_REQUEST['check']['peyment_method'])) $line .= $td_h.$data['order_payment_name'].$td_f;
1953 - if(isset($_REQUEST['check']['delivery_method'])) {
1954 - $delivery_method = '';
1955 - if(strtoupper($data['order_delivery_method']) == '#NONE#') {
1956 - $delivery_method = __('No preference', 'usces');
1957 - } else {
1958 - foreach((array)$usces->options['delivery_method'] as $dkey => $delivery) {
1959 - if($delivery['id'] == $data['order_delivery_method']) {
1960 - $delivery_method = $delivery['name'];
1961 - break;
1962 - }
1963 - }
1964 - }
1965 - $line .= $td_h.$delivery_method.$td_f;
1966 - }
1967 -//20101208ysk start
1968 - if(isset($_REQUEST['check']['delivery_date'])) $line .= $td_h.$data['order_delivery_date'].$td_f;
1969 -//20101208ysk end
1970 - if(isset($_REQUEST['check']['delivery_time'])) $line .= $td_h.$data['order_delivery_time'].$td_f;
1971 - if(isset($_REQUEST['check']['delidue_date'])) {
1972 - $order_delidue_date = (strtoupper($data['order_delidue_date']) == '#NONE#') ? '' : $data['order_delidue_date'];
1973 - $line .= $td_h.$order_delidue_date.$td_f;
1974 - }
1975 - if(isset($_REQUEST['check']['status'])) {
1976 - $order_status = explode(',', $data['order_status']);
1977 - $status = '';
1978 - foreach( (array)$order_status as $os) {
1979 - if( isset($usces_management_status[$os]) )
1980 - $status .= $usces_management_status[$os].$sp;
1981 - }
1982 - $line .= $td_h.trim($status, $sp).$td_f;
1983 - }
1984 - $line .= $td_h.usces_crform($array['total_price'], false, false, 'return', false).$td_f;
1985 - if(isset($_REQUEST['check']['getpoint'])) $line .= $td_h.$data['order_getpoint'].$td_f;
1986 - if(isset($_REQUEST['check']['usedpoint'])) $line .= $td_h.$data['order_usedpoint'].$td_f;
1987 - $line .= $td_h.$data['order_discount'].$td_f;
1988 - $line .= $td_h.$data['order_shipping_charge'].$td_f;
1989 - $line .= $td_h.$data['order_cod_fee'].$td_f;
1990 - $line .= $td_h.$data['order_tax'].$td_f;
1991 - if(isset($_REQUEST['check']['note'])) $line .= $td_h.usces_entity_decode($data['order_note'], $ext).$td_f;
1992 - if(!empty($csod_meta)) {
1993 - foreach($csod_meta as $key => $entry) {
1994 - $name = $entry['name'];
1995 - $csod_key = 'csod_'.$key;
1996 -//20110208ysk start
1997 - //if(isset($_REQUEST['check'][$name])) {
1998 - if(isset($_REQUEST['check'][$csod_key])) {
1999 -//20110208ysk end
2000 - $value = maybe_unserialize($usces->get_order_meta_value($csod_key, $order_id));
2001 - if(empty($value)) {
2002 - $value = '';
2003 - } elseif(is_array($value)) {
2004 - $concatval = '';
2005 - $c = '';
2006 - foreach($value as $v) {
2007 - $concatval .= $c.$v;
2008 - $c = ' ';
2009 - }
2010 - $value = $concatval;
2011 - }
2012 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
2013 - }
2014 - }
2015 - }
2016 - $line .= apply_filters( 'usces_filter_chk_ord_data_order', NULL, $usces_opt_order, $order_id, $data );
2017 - $line .= $tr_f.$lf;
2018 - }
2019 - $line .= $table_f.$lf;
2020 - //==========================================================================
2021 -
2022 - if($ext == 'xls') {
2023 - header("Content-Type: application/vnd.ms-excel; charset=Shift-JIS");
2024 - } elseif($ext == 'csv') {
2025 - header("Content-Type: application/octet-stream");
2026 - }
2027 - header("Content-Disposition: attachment; filename=usces_order_list.".$ext);
2028 - mb_http_output('pass');
2029 - print(mb_convert_encoding($line, "SJIS-win", "UTF-8"));
2030 - exit();
2031 -}
2032 -
2033 -function usces_entity_decode($str, $ftype) {
2034 - $pos = strpos($str, '&');
2035 - if($pos !== false)
2036 - $str = htmlspecialchars_decode($str);
2037 -
2038 - if($ftype == 'csv')
2039 - $str = str_replace('"', '""', $str);
2040 -
2041 - return $str;
2042 -}
2043 -
2044 -function usces_is_entity($entity){
2045 - $temp = substr($entity, 0, 1);
2046 - $temp .= substr($entity, -1, 1);
2047 - if ($temp != '&;')
2048 - return false;
2049 - else
2050 - return true;
2051 -}
2052 -
2053 -function usces_p( $var ){
2054 - echo '<pre>' . print_r($var, true) . '</pre>';
2055 -}
2056 -
2057 -function usces_get_key( $digit ){
2058 - $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
2059 - $max = strlen($chars) - 1;
2060 - $str = '';
2061 - for($i=0; $i<$digit; $i++){
2062 - $str .= $chars[mt_rand(0, $max)];
2063 - }
2064 - return $str;
2065 -}
2066 -?>
1 +<?php
2 +/**
3 + * Utility
4 + *
5 + * @package Welcart
6 + */
7 +
8 +// phpcs:disable WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL
9 +// phpcs:disable WordPress.PHP.DevelopmentFunctions, WordPress.PHP.NoSilencedErrors
10 +
11 +/**
12 + * Upgrade 143
13 + *
14 + * @return bool
15 + */
16 +function usces_upgrade_143() {
17 +
18 + $upgrade = (int) get_option( 'usces_upgrade3' );
19 + if ( 0 !== $upgrade ) {
20 + return true;
21 + }
22 +
23 + global $wpdb;
24 + $table = $wpdb->prefix . 'usces_ordercart';
25 + $wpdb->query( "ALTER TABLE $table CHANGE `cprice` `cprice` DECIMAL( 15, 2 ) NULL DEFAULT NULL" );
26 + $wpdb->query( "ALTER TABLE $table CHANGE `price` `price` DECIMAL( 15, 2 ) NULL DEFAULT NULL" );
27 + $wpdb->query( "ALTER TABLE $table CHANGE `tax` `tax` DECIMAL( 13, 2 ) NULL DEFAULT NULL" );
28 +
29 + $upgrade += USCES_UP143;
30 + update_option( 'usces_upgrade3', $upgrade );
31 + usces_log( 'USCES_UP143 : Completed', 'db' );
32 +
33 + return true;
34 +}
35 +
36 +/**
37 + * Upgrade 141
38 + *
39 + * @return bool
40 + */
41 +function usces_upgrade_141() {
42 +
43 + $upgrade = (int) get_option( 'usces_upgrade2' );
44 + if ( 3 !== $upgrade ) {
45 + return true;
46 + }
47 +
48 + global $wpdb, $usces;
49 + $rets = array();
50 +
51 + $options = get_option( 'usces', array() );
52 + if ( empty( $options['tax_rate'] ) ) {
53 + $options['tax_mode'] = 'include';
54 + } else {
55 + $options['tax_mode'] = 'exclude';
56 + }
57 + $options['tax_target'] = 'all';
58 + update_option( 'usces', $options );
59 +
60 + $order_table = $wpdb->prefix . 'usces_order';
61 + $cart_table = $wpdb->prefix . 'usces_ordercart';
62 + $cart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
63 +
64 + $query = "SELECT ID, order_cart, order_condition FROM $order_table";
65 + $results = $wpdb->get_results( $query );
66 + if ( $results ) {
67 + foreach ( $results as $order ) {
68 +
69 + $query = $wpdb->prepare( "SELECT order_id FROM $cart_table WHERE order_id = %d", $order->ID );
70 + $order_id = $wpdb->get_var( $query );
71 + if ( $order_id == $order->ID ) {
72 + continue;
73 + }
74 + $condition = wel_safe_maybe_unserialize( $order->order_condition );
75 + if ( ! isset( $condition['tax_mode'] ) ) {
76 + $condition['tax_mode'] = $options['tax_mode'];
77 + }
78 + if ( ! isset( $condition['tax_rate'] ) ) {
79 + $condition['tax_rate'] = (int) $options['tax_rate'];
80 + }
81 + if ( ! isset( $condition['tax_target'] ) ) {
82 + $condition['tax_target'] = $options['tax_target'];
83 + }
84 +
85 + $cart = wel_safe_unserialize( $order->order_cart );
86 + foreach ( (array) $cart as $row_index => $value ) {
87 + $product = wel_get_product( $value['post_id'] );
88 + $item_code = $product['itemCode'];
89 + $item_name = $product['itemName'];
90 + $skus = $usces->get_skus( $value['post_id'], 'code' );
91 + $sku_code = urldecode( $value['sku'] );
92 + $sku_encoded = $value['sku'];
93 + $sku = isset( $skus[ $sku_code ] ) ? $skus[ $sku_code ] : array( 'name' => 'notfound', 'cprice' => 0, 'unit' => '' );
94 + $tax = 0;
95 + $query = $wpdb->prepare(
96 + "INSERT INTO $cart_table
97 + (
98 + order_id, group_id, row_index,
99 + post_id, item_code, item_name,
100 + sku_code, sku_name, cprice, price, quantity, unit,
101 + tax, destination_id, cart_serial
102 + ) VALUES (
103 + %d, %d, %d,
104 + %d, %s, %s,
105 + %s, %s, %f, %f, %d, %s,
106 + %f, %d, %s
107 + )",
108 + $order->ID, 0, $row_index,
109 + $value['post_id'], $item_code, $item_name,
110 + $sku_code, $sku['name'], $sku['cprice'], $value['price'], $value['quantity'], $sku['unit'],
111 + $tax, NULL, $value['serial']
112 + );
113 + $wpdb->query( $query );
114 +
115 + $cart_id = $wpdb->insert_id;
116 + if ( $cart_id ) {
117 + if ( $value['options'] ) {
118 + foreach ( (array) $value['options'] as $okey => $ovalue ) {
119 + $okey = urldecode( $okey );
120 + if ( is_array( $ovalue ) ) {
121 + $ovalue = serialize( $ovalue );
122 + } else {
123 + $ovalue = urldecode( $ovalue );
124 + }
125 + $oquery = $wpdb->prepare(
126 + "INSERT INTO $cart_meta_table
127 + (
128 + cart_id, meta_type, meta_key, meta_value
129 + ) VALUES (
130 + %d, 'option', %s, %s
131 + )",
132 + $cart_id, $okey, $ovalue
133 + );
134 + $wpdb->query( $oquery );
135 + }
136 + }
137 + if ( $value['advance'] ) {
138 + foreach ( (array) $value['advance'] as $akey => $avalue ) {
139 + $advance = wel_safe_maybe_unserialize( $avalue );
140 + if ( is_array( $advance ) ) {
141 + $post_id = $value['post_id'];
142 + if ( is_array( $advance[ $post_id ][ $sku_encoded ] ) ) {
143 + $akeys = array_keys( $advance[ $post_id ][ $sku_encoded ] );
144 + foreach ( (array) $akeys as $akey ) {
145 + $avalue = serialize( $advance[ $post_id ][ $sku_encoded ][ $akey ] );
146 + $aquery = $wpdb->prepare(
147 + "INSERT INTO $cart_meta_table
148 + (
149 + cart_id, meta_type, meta_key, meta_value
150 + ) VALUES (
151 + %d, 'advance', %s, %s
152 + )",
153 + $cart_id, $akey, $avalue
154 + );
155 + $wpdb->query( $aquery );
156 + }
157 + } else {
158 + $akeys = array_keys( $advance );
159 + $akey = ( empty( $akeys[0] ) ) ? 'advance' : $akeys[0];
160 + $avalue = serialize( $advance );
161 + $aquery = $wpdb->prepare(
162 + "INSERT INTO $cart_meta_table
163 + (
164 + cart_id, meta_type, meta_key, meta_value
165 + ) VALUES (
166 + %d, 'advance', %s, %s
167 + )",
168 + $cart_id, $akey, $avalue
169 + );
170 + $wpdb->query( $aquery );
171 + }
172 + } else {
173 + $avalue = urldecode( $avalue );
174 + $aquery = $wpdb->prepare(
175 + "INSERT INTO $cart_meta_table
176 + (
177 + cart_id, meta_type, meta_key, meta_value
178 + ) VALUES (
179 + %d, 'advance', 'advance', %s
180 + )",
181 + $cart_id, $avalue
182 + );
183 + $wpdb->query( $aquery );
184 + }
185 + }
186 + }
187 + }
188 + }
189 +
190 + $upquery = $wpdb->prepare(
191 + "UPDATE $order_table SET order_condition = %s WHERE ID = %d",
192 + serialize( $condition ), $order->ID
193 + );
194 + $wpdb->query( $upquery );
195 + }
196 + }
197 + usces_log( 'USCES_UP141 : Completed : from ' . $upgrade, 'db' );
198 + $upgrade += USCES_UP141;
199 + update_option( 'usces_upgrade2', $upgrade );
200 +
201 + return true;
202 +}
203 +
204 +/**
205 + * Upgrade 14
206 + *
207 + * @return bool
208 + */
209 +function usces_upgrade_14() {
210 +
211 + $upgrade = (int) get_option( 'usces_upgrade2' );
212 + if ( 0 < $upgrade ) {
213 + return true;
214 + }
215 +
216 + global $wpdb, $usces;
217 + $rets = array();
218 +
219 + $options = get_option( 'usces', array() );
220 + if ( empty( $options['tax_rate'] ) ) {
221 + $options['tax_mode'] = 'include';
222 + } else {
223 + $options['tax_mode'] = 'exclude';
224 + }
225 + $options['tax_target'] = 'all';
226 + update_option( 'usces', $options );
227 +
228 + $order_table = $wpdb->prefix . 'usces_order';
229 + $cart_table = $wpdb->prefix . 'usces_ordercart';
230 + $cart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
231 +
232 + $query = "SELECT ID, order_cart, order_condition FROM $order_table";
233 + $results = $wpdb->get_results( $query );
234 + if ( $results ) {
235 + foreach ( $results as $order ) {
236 + $condition = wel_safe_maybe_unserialize( $order->order_condition );
237 + if ( ! isset( $condition['tax_mode'] ) ) {
238 + $condition['tax_mode'] = $options['tax_mode'];
239 + }
240 + if ( ! isset( $condition['tax_rate'] ) ) {
241 + $condition['tax_rate'] = (int) $options['tax_rate'];
242 + }
243 + if ( ! isset( $condition['tax_target'] ) ) {
244 + $condition['tax_target'] = $options['tax_target'];
245 + }
246 +
247 + $cart = wel_safe_unserialize( $order->order_cart );
248 + foreach ( (array) $cart as $row_index => $value ) {
249 + $product = wel_get_product( $value['post_id'] );
250 + $item_code = $product['itemCode'];
251 + $item_name = $product['itemName'];
252 + $skus = $usces->get_skus( $value['post_id'], 'code' );
253 + $sku_code = urldecode( $value['sku'] );
254 + $sku_encoded = $value['sku'];
255 + $sku = isset( $skus[ $sku_code ] ) ? $skus[ $sku_code ] : array( 'name' => 'notfound', 'cprice' => 0, 'unit' => '' );
256 + $tax = 0;
257 + $query = $wpdb->prepare(
258 + "INSERT INTO $cart_table
259 + (
260 + order_id, group_id, row_index,
261 + post_id, item_code, item_name,
262 + sku_code, sku_name, cprice, price, quantity, unit,
263 + tax, destination_id, cart_serial
264 + ) VALUES (
265 + %d, %d, %d,
266 + %d, %s, %s,
267 + %s, %s, %f, %f, %d, %s,
268 + %f, %d, %s
269 + )",
270 + $order->ID, 0, $row_index,
271 + $value['post_id'], $item_code, $item_name,
272 + $sku_code, $sku['name'], $sku['cprice'], $value['price'], $value['quantity'], $sku['unit'],
273 + $tax, NULL, $value['serial']
274 + );
275 + $wpdb->query( $query );
276 +
277 + $cart_id = $wpdb->insert_id;
278 + if ( $cart_id ) {
279 + if ( $value['options'] ) {
280 + foreach ( (array) $value['options'] as $okey => $ovalue ) {
281 + $okey = urldecode( $okey );
282 + if ( is_array( $ovalue ) ) {
283 + $ovalue = serialize( $ovalue );
284 + } else {
285 + $ovalue = urldecode( $ovalue );
286 + }
287 + $oquery = $wpdb->prepare(
288 + "INSERT INTO $cart_meta_table
289 + (
290 + cart_id, meta_type, meta_key, meta_value
291 + ) VALUES (
292 + %d, 'option', %s, %s
293 + )",
294 + $cart_id, $okey, $ovalue
295 + );
296 + $wpdb->query( $oquery );
297 + }
298 + }
299 + if ( $value['advance'] ) {
300 + foreach ( (array) $value['advance'] as $akey => $avalue ) {
301 + $advance = wel_safe_maybe_unserialize( $avalue );
302 + if ( is_array( $advance ) ) {
303 + $post_id = $value['post_id'];
304 + if ( is_array( $advance[ $post_id ][ $sku_encoded ] ) ) {
305 + $akeys = array_keys( $advance[ $post_id ][ $sku_encoded ] );
306 + foreach ( (array) $akeys as $akey ) {
307 + $avalue = serialize( $advance[ $post_id ][ $sku_encoded ][ $akey ] );
308 + $aquery = $wpdb->prepare(
309 + "INSERT INTO $cart_meta_table
310 + (
311 + cart_id, meta_type, meta_key, meta_value
312 + ) VALUES (
313 + %d, 'advance', %s, %s
314 + )",
315 + $cart_id, $akey, $avalue
316 + );
317 + $wpdb->query( $aquery );
318 + }
319 + } else {
320 + $akeys = array_keys( $advance );
321 + $akey = ( empty( $akeys[0] ) ) ? 'advance' : $akeys[0];
322 + $avalue = serialize( $advance );
323 + $aquery = $wpdb->prepare(
324 + "INSERT INTO $cart_meta_table
325 + (
326 + cart_id, meta_type, meta_key, meta_value
327 + ) VALUES (
328 + %d, 'advance', %s, %s
329 + )",
330 + $cart_id, $akey, $avalue
331 + );
332 + $wpdb->query( $aquery );
333 + }
334 + } else {
335 + $avalue = urldecode( $avalue );
336 + $aquery = $wpdb->prepare(
337 + "INSERT INTO $cart_meta_table
338 + (
339 + cart_id, meta_type, meta_key, meta_value
340 + ) VALUES (
341 + %d, 'advance', 'advance', %s
342 + )",
343 + $cart_id, $avalue
344 + );
345 + $wpdb->query( $aquery );
346 + }
347 + }
348 + }
349 + }
350 + }
351 +
352 + $upquery = $wpdb->prepare(
353 + "UPDATE $order_table SET order_condition = %s WHERE ID = %d",
354 + serialize( $condition ), $order->ID
355 + );
356 + $wpdb->query( $upquery );
357 + }
358 + }
359 + usces_log( 'USCES_UP14 : Completed : from ' . $upgrade, 'db' );
360 + $upgrade += USCES_UP14;
361 + update_option( 'usces_upgrade2', $upgrade );
362 +
363 + return true;
364 +}
365 +
366 +/**
367 + * Upgrade 07
368 + *
369 + * @return bool
370 + */
371 +function usces_upgrade_07() {
372 +
373 + $upgrade = (int) get_option( 'usces_upgrade' );
374 + if ( 0 !== $upgrade ) {
375 + return true;
376 + }
377 +
378 + global $wpdb;
379 + $rets = array();
380 +
381 + $tablename = $wpdb->prefix . 'postmeta';
382 + $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'iopt_', '_iopt_') WHERE meta_key LIKE 'iopt_%'";
383 + if ( $wpdb->query( $mquery ) ) {
384 + $rets[] = 1;
385 + }
386 + $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'isku_', '_isku_') WHERE meta_key LIKE 'isku_%'";
387 + if ( $wpdb->query( $mquery ) ) {
388 + $rets[] = 1;
389 + }
390 + $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemCode', '_itemCode') WHERE meta_key LIKE 'itemCode'";
391 + if( $wpdb->query( $mquery ) )
392 + $rets[] = 1;
393 +
394 + $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemName', '_itemName') WHERE meta_key LIKE 'itemName'";
395 + if ( $wpdb->query( $mquery ) ) {
396 + $rets[] = 1;
397 + }
398 + $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemRestriction', '_itemRestriction') WHERE meta_key LIKE 'itemRestriction'";
399 + if ( $wpdb->query( $mquery ) ) {
400 + $rets[] = 1;
401 + }
402 + $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemPointrate', '_itemPointrate') WHERE meta_key LIKE 'itemPointrate'";
403 + if ( $wpdb->query( $mquery ) ) {
404 + $rets[] = 1;
405 + }
406 + $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemGpNum1', '_itemGpNum1') WHERE meta_key LIKE 'itemGpNum1'";
407 + if ( $wpdb->query( $mquery ) ) {
408 + $rets[] = 1;
409 + }
410 + $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemGpDis1', '_itemGpDis1') WHERE meta_key LIKE 'itemGpDis1'";
411 + if ( $wpdb->query( $mquery ) ) {
412 + $rets[] = 1;
413 + }
414 + $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemGpNum2', '_itemGpNum2') WHERE meta_key LIKE 'itemGpNum2'";
415 + if ( $wpdb->query( $mquery ) ) {
416 + $rets[] = 1;
417 + }
418 + $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemGpDis2', '_itemGpDis2') WHERE meta_key LIKE 'itemGpDis2'";
419 + if ( $wpdb->query( $mquery ) ) {
420 + $rets[] = 1;
421 + }
422 + $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemGpDis3', '_itemGpDis3') WHERE meta_key LIKE 'itemGpDis3'";
423 + if ( $wpdb->query( $mquery ) ) {
424 + $rets[] = 1;
425 + }
426 + $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemGpNum3', '_itemGpNum3') WHERE meta_key LIKE 'itemGpNum3'";
427 + if ( $wpdb->query( $mquery ) ) {
428 + $rets[] = 1;
429 + }
430 + $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemShipping', '_itemShipping') WHERE meta_key LIKE 'itemShipping'";
431 + if ( $wpdb->query( $mquery ) ) {
432 + $rets[] = 1;
433 + }
434 + $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemDeliveryMethod', '_itemDeliveryMethod') WHERE meta_key LIKE 'itemDeliveryMethod'";
435 + if ( $wpdb->query( $mquery ) ) {
436 + $rets[] = 1;
437 + }
438 + $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemShippingCharge', '_itemShippingCharge') WHERE meta_key LIKE 'itemShippingCharge'";
439 + if ( $wpdb->query( $mquery ) ) {
440 + $rets[] = 1;
441 + }
442 + $mquery = "UPDATE $tablename SET meta_key = REPLACE(meta_key, 'itemIndividualSCharge', '_itemIndividualSCharge') WHERE meta_key LIKE 'itemIndividualSCharge'";
443 + if ( $wpdb->query( $mquery ) ) {
444 + $rets[] = 1;
445 + }
446 + usces_log( 'USCES_UP07 : ' . print_r( $rets, true ), 'db' );
447 + $upgrade += USCES_UP07;
448 + update_option( 'usces_upgrade', $upgrade );
449 + return true;
450 +}
451 +
452 +/**
453 + * Upgrade 11
454 + *
455 + * @return bool
456 + */
457 +function usces_upgrade_11() {
458 +
459 + $options = get_option( 'usces', array() );
460 + $upgrade = (int) get_option( 'usces_upgrade' );
461 + if ( 1 !== $upgrade ) {
462 + return true;
463 + }
464 +
465 + global $wpdb;
466 + $rets = array();
467 +
468 + /* ITEM SKU DATA */
469 + $sort = (int) $options['system']['orderby_itemsku'];
470 + if ( $sort ) {
471 + $query = "SELECT * FROM $wpdb->postmeta WHERE meta_key <> '_isku_' AND meta_key LIKE '_isku_%' ORDER BY post_id, meta_key";
472 + } else {
473 + $query = "SELECT * FROM $wpdb->postmeta WHERE meta_key <> '_isku_' AND meta_key LIKE '_isku_%' ORDER BY post_id, meta_id";
474 + }
475 + $res = $wpdb->get_results( $query, ARRAY_A );
476 +
477 + $conclusion = true;
478 + $pre_post_id = 0;
479 + $sort_id = 0;
480 + $check_code = array();
481 + $dep_num = array();
482 + foreach ( (array) $res as $metarow ) {
483 + $meta_value = wel_safe_unserialize( $metarow['meta_value'] );
484 + $newvalue = array();
485 + $newvalue['code'] = substr( $metarow['meta_key'], 6 );
486 + if ( $pre_post_id == $metarow['post_id'] ) {
487 + if ( in_array( $newvalue['code'], $check_code ) ) {
488 + $newvalue['code'] .= 'dupricate_' . (int) $dep_num[ $newvalue['code'] ];
489 + $dep_num[ $newvalue['code'] ]++;
490 + }
491 + } else {
492 + $check_code = array();
493 + $dep_num = array();
494 + $sort_id = 0;
495 + }
496 + foreach ( (array) $meta_value as $k => $v ) {
497 + switch ( $k ) {
498 + case 'disp':
499 + $newvalue['name'] = $v;
500 + break;
501 + case 'cprice':
502 + $newvalue['cprice'] = $v;
503 + break;
504 + case 'price':
505 + $newvalue['price'] = $v;
506 + break;
507 + case 'unit':
508 + $newvalue['unit'] = $v;
509 + break;
510 + case 'zaikonum':
511 + $newvalue['stocknum'] = $v;
512 + break;
513 + case 'zaiko':
514 + $newvalue['stock'] = $v;
515 + break;
516 + case 'gptekiyo':
517 + $newvalue['gp'] = $v;
518 + break;
519 + case 'charging_type':
520 + break;
521 + default:
522 + $newvalue[ $k ] = $v;
523 + }
524 + }
525 + $newvalue['sort'] = $sort_id;
526 +
527 + $id = usces_add_sku( $metarow['post_id'], $newvalue, false );
528 + $pre_post_id = $metarow['post_id'];
529 + $check_code[] = $newvalue['code'];
530 + $sort_id++;
531 +
532 + $res_key = $metarow['post_id'] . '_' . $newvalue['code'];
533 + if ( $id ) {
534 + delete_post_meta( $metarow['post_id'], $metarow['meta_key'] );
535 + $rets['sku'][ $res_key ] = 1;
536 + } else {
537 + $rets['sku'][ $res_key ] = 0;
538 + usces_log( 'meta_id ' . $metarow['meta_id'] . ' : ' . __( 'This SKU-data has not been rebuilt.', 'usces' ), 'database_error.log' );
539 + }
540 + }
541 +
542 + /* ITEM OPTION DATA */
543 + $sort = (int) $options['system']['orderby_itemopt'];
544 + if ( $sort ) {
545 + $query = "SELECT * FROM $wpdb->postmeta WHERE meta_key <> '_iopt_' AND meta_key LIKE '_iopt_%' ORDER BY post_id, meta_key";
546 + } else {
547 + $query = "SELECT * FROM $wpdb->postmeta WHERE meta_key <> '_iopt_' AND meta_key LIKE '_iopt_%' ORDER BY post_id, meta_id";
548 + }
549 + $res = $wpdb->get_results( $query, ARRAY_A );
550 +
551 + $conclusion = true;
552 + $pre_post_id = 0;
553 + $sort_id = 0;
554 + $check_code = array();
555 + $dep_num = array();
556 + foreach ( (array) $res as $metarow ) {
557 + $meta_value = wel_safe_unserialize( $metarow['meta_value'] );
558 + $newvalue = array();
559 + $newvalue['name'] = substr( $metarow['meta_key'], 6 );
560 + if ( $pre_post_id == $metarow['post_id'] ) {
561 + if ( in_array( $newvalue['name'], $check_code ) ) {
562 + $newvalue['name'] .= 'dupricate_' . (int) $dep_num[ $newvalue['name'] ];
563 + $dep_num[ $newvalue['name'] ]++;
564 + }
565 + } else {
566 + $check_code = array();
567 + $dep_num = array();
568 + $sort_id = 0;
569 + }
570 + foreach ( (array) $meta_value as $k => $v ) {
571 + switch ( $k ) {
572 + case 'means':
573 + $newvalue['means'] = $v;
574 + break;
575 + case 'essential':
576 + $newvalue['essential'] = $v;
577 + break;
578 + case 'value':
579 + if ( is_array( $v ) ) {
580 + $nov = '';
581 + foreach ( (array) $v as $vs ) {
582 + if ( ! WCUtils::is_blank( $vs ) ) {
583 + $nov .= $vs . "\n";
584 + }
585 + }
586 + $newvalue['value'] = trim( $nov );
587 + } else {
588 + $newvalue['value'] = trim( $v );
589 + }
590 + break;
591 + default:
592 + $newvalue[ $k ] = trim( $v );
593 + }
594 + }
595 + $newvalue['sort'] = $sort_id;
596 +
597 + $id = usces_add_opt( $metarow['post_id'], $newvalue, false );
598 + $pre_post_id = $metarow['post_id'];
599 + $check_code[] = $newvalue['name'];
600 + $sort_id++;
601 +
602 + $res_key = $metarow['post_id'] . '_' . $newvalue['name'];
603 + if ( $id ) {
604 + delete_post_meta( $metarow['post_id'], $metarow['meta_key'] );
605 + $rets['opt'][ $res_key ] = 1;
606 + } else {
607 + $rets['opt'][ $res_key ] = 0;
608 + usces_log( 'meta_id ' . $metarow['meta_id'] . ' : ' . __( 'This Item-Option-data has not been rebuilt.', 'usces' ), 'database_error.log' );
609 + }
610 + }
611 +
612 + /* PAYMENT METHOD DATA */
613 + $payment = get_option( 'usces_payment_method' );
614 + if ( empty( $payment ) ) {
615 +
616 + $options = get_option( 'usces', array() );
617 + $old_payment = isset( $options['payment_method'] ) ? $options['payment_method'] : '';
618 + usces_log( 'old_payment : ' . print_r( $old_payment, true ), 'database_error.log' );
619 + if ( ! empty( $old_payment ) && is_array( $old_payment ) ) {
620 + foreach ( $old_payment as $key => $value ) {
621 + $res_key = $key . '_' . $value['name'];
622 + $id = usces_add_system_option( 'usces_payment_method', $value );
623 + if ( $id ) {
624 + $rets['payment'][ $res_key ] = 1;
625 + } else {
626 + $rets['payment'][ $res_key ] = 0;
627 + usces_log( 'payment_method ' . $value['name'] . ' : ' . __( 'This Payment-Method-data has not been rebuilt.', 'usces' ), 'database_error.log' );
628 + }
629 + }
630 + }
631 + }
632 +
633 + usces_log( 'USCES_UP11 : ' . print_r( $rets, true ), 'db' );
634 +
635 + $upgrade += USCES_UP11;
636 + update_option( 'usces_upgrade', $upgrade );
637 +
638 + return true;
639 +}
640 +
641 +/**
642 + * Output log data.
643 + *
644 + * @param mixed $log Log.
645 + * @param string $file Output.
646 + * @param string $type Type.
647 + * @param string $key Key.
648 + */
649 +function usces_log( $log, $file, $type = '', $key = '' ) {
650 + global $wpdb;
651 +
652 + if ( 'db' == $file ) {
653 +
654 + $table_name = $wpdb->prefix . 'usces_log';
655 + $query = $wpdb->prepare( "INSERT INTO $table_name ( datetime, log, log_type, log_key ) VALUES( %s, %s, %s, %s )", current_time( 'mysql' ), $log, $type, $key );
656 + $wpdb->query( $query );
657 +
658 + } else {
659 +
660 + $logdir = USCES_PLUGIN_DIR . '/logs';
661 + $file_path = $logdir . '/' . $file;
662 + if ( is_dir( $file_path ) ) {
663 + return;
664 + }
665 +
666 + $htaccess_path = $logdir . '/.htaccess';
667 + if ( ! file_exists( $htaccess_path ) ) {
668 + if ( $ht = @fopen( $htaccess_path, 'w' ) ) {
669 + fwrite( $ht, 'Order deny,allow' . "\n" );
670 + fwrite( $ht, 'Deny from all' . "\n" );
671 + fclose( $ht );
672 + }
673 + }
674 +
675 + if ( is_writable( $file_path ) || ( 'db' != $file && 'test' == $type ) ) {
676 + $log = date( '[Y-m-d H:i:s]', current_time( 'timestamp' ) ) . "\t" . $log . "\n";
677 + if ( $fp = @fopen( $file_path, 'a' ) ) {
678 + fwrite( $fp, $log );
679 + fclose( $fp );
680 + }
681 + } else {
682 +
683 + $type = 'unwritable';
684 + $key = $file;
685 + $table_name = $wpdb->prefix . 'usces_log';
686 + $query = $wpdb->prepare( "INSERT INTO $table_name ( datetime, log, log_type, log_key ) VALUES( %s, %s, %s, %s )", current_time( 'mysql' ), $log, $type, $key );
687 + $wpdb->query( $query );
688 +
689 + }
690 + }
691 +}
692 +
693 +/**
694 + * Convenience store name
695 + *
696 + * @param string $code Convenience store code.
697 + * @return string
698 + */
699 +function usces_get_conv_name( $code ) {
700 + switch ( $code ) {
701 + case 'D001':
702 + $name = 'セブン-イレブン';
703 + break;
704 + case '010':
705 + $name = 'セブンイレブン';
706 + break;
707 + case 'D002':
708 + case '020':
709 + $name = 'ローソン';
710 + break;
711 + case 'D015':
712 + case '760':
713 + $name = 'セイコーマート';
714 + break;
715 + case 'D405':
716 + $name = 'ペイジー';
717 + break;
718 + case 'D003':
719 + $name = 'サンクス';
720 + break;
721 + case 'D004':
722 + $name = 'サークルK';
723 + break;
724 + case 'D040':
725 + $name = 'サークルKサンクス';
726 + break;
727 + case 'D005':
728 + case '080':
729 + case 'D050':
730 + $name = 'ミニストップ';
731 + break;
732 + case 'D010':
733 + case 'D060':
734 + $name = 'デイリーヤマザキ';
735 + break;
736 + case 'D011':
737 + $name = 'ヤマザキデイリーストア';
738 + break;
739 + case 'D030':
740 + case '030':
741 + $name = 'ファミリーマート';
742 + break;
743 + case 'D401':
744 + $name = '楽天Edy';
745 + break;
746 + case 'D404':
747 + $name = '楽天銀行';
748 + break;
749 + case 'D406':
750 + $name = 'ジャパネット銀行';
751 + break;
752 + case 'D407':
753 + $name = 'Suicaインターネットサービス';
754 + break;
755 + case 'D451':
756 + $name = 'ウェブマネー';
757 + break;
758 + case 'D452':
759 + $name = 'ビットキャッシュ';
760 + break;
761 + case 'D453':
762 + $name = 'JCBプレモカード';
763 + break;
764 + case 'P901':
765 + $name = 'コンビニ払込票';
766 + break;
767 + case 'P902':
768 + $name = 'コンビニ払込票(郵便振替対応)';
769 + break;
770 + case '050':
771 + $name = 'デイリーヤマザキ・ヤマザキデイリーストア・タイムリー';
772 + break;
773 + case '060':
774 + $name = 'サークルK・サンクス';
775 + break;
776 + case '110':
777 + $name = 'am/pm';
778 + break;
779 + default:
780 + $name = '';
781 + }
782 + return $name;
783 +}
784 +
785 +/**
786 + * Payment Method Details
787 + *
788 + * @param array $usces_entries Entry data.
789 + * @return string
790 + */
791 +function usces_payment_detail( $usces_entries ) {
792 + global $usces;
793 +
794 + $payments = usces_get_payments_by_name( $usces_entries['order']['payment_name'] );
795 + $acting_flag = ( 'acting' == $payments['settlement'] ) ? $payments['module'] : $payments['settlement'];
796 + $str = '';
797 + switch ( $acting_flag ) {
798 + case 'paypal.php':
799 + break;
800 +
801 + case 'epsilon.php':
802 + break;
803 +
804 + case 'acting_remise_card':
805 + if ( isset( $usces_entries['order']['div'] ) ) {
806 + switch ( $usces_entries['order']['div'] ) {
807 + case '0':
808 + $str = ' 一括払い';
809 + break;
810 + case '1':
811 + $str = ' 分割(2回)';
812 + break;
813 + case '2':
814 + $str = ' 分割(リボ払い)';
815 + break;
816 + }
817 + }
818 + break;
819 +
820 + case 'acting_remise_conv':
821 + break;
822 +
823 + case 'transferAdvance':
824 + if ( ! empty( $usces->options['tatransfer_limit'] ) ) {
825 + $payment_detail = __( '(', 'usces' ) . sprintf( __( 'Payment is valid for %s days from the date of order.', 'usces' ), $usces->options['tatransfer_limit'] ) . __( ')', 'usces' );
826 + $str = apply_filters( 'usces_filter_transferAdvance_payment_limit', $payment_detail, $usces->options['tatransfer_limit'] );
827 + }
828 + break;
829 +
830 + case 'transferDeferred':
831 + if ( ! empty( $usces->options['tatransfer_limit'] ) ) {
832 + $payment_detail = __( '(', 'usces' ) . sprintf( __( 'Payment is valid for %s days from after the item arrives.', 'usces' ), $usces->options['tatransfer_limit'] ) . __( ')', 'usces' );
833 + $str = apply_filters( 'usces_filter_transferDeferred_payment_limit', $payment_detail, $usces->options['tatransfer_limit'] );
834 + }
835 + break;
836 + }
837 +
838 + $str = apply_filters( 'usces_filter_payment_detail', $str, $usces_entries );
839 + return $str;
840 +}
841 +
842 +/**
843 + * Payment Method Details
844 + *
845 + * @param array $order_data Order data.
846 + * @return string
847 + */
848 +function usces_payment_detail_confirm( $order_data ) {
849 + global $usces;
850 +
851 + $payments = usces_get_payments_by_name( $order_data['order_payment_name'] );
852 + $acting_flag = ( 'acting' == $payments['settlement'] ) ? $payments['module'] : $payments['settlement'];
853 + $str = '';
854 + switch ( $acting_flag ) {
855 + case 'paypal.php':
856 + break;
857 + case 'epsilon.php':
858 + break;
859 + case 'acting_remise_card':
860 + break;
861 + case 'acting_remise_conv':
862 + break;
863 +
864 + case 'transferAdvance':
865 + if ( ! empty( $usces->options['tatransfer_limit'] ) && $usces->is_status( 'noreceipt', $order_data['order_status'] ) ) {
866 + $payment_detail = "\n" . sprintf( __( 'Payment is valid for %s days from the date of order.', 'usces' ), $usces->options['tatransfer_limit'] );
867 + $str = apply_filters( 'usces_filter_transferAdvance_payment_limit_confirm', $payment_detail, $usces->options['tatransfer_limit'] );
868 + }
869 + break;
870 +
871 + case 'transferDeferred':
872 + if ( ! empty( $usces->options['tatransfer_limit'] ) && $usces->is_status( 'noreceipt', $order_data['order_status'] ) ) {
873 + $payment_detail = "\n" . sprintf( __( 'Payment is valid for %s days from after the item arrives.', 'usces' ), $usces->options['tatransfer_limit'] );
874 + $str = apply_filters( 'usces_filter_transferDeferred_payment_limit_confirm', $payment_detail, $usces->options['tatransfer_limit'] );
875 + }
876 + break;
877 + }
878 +
879 + $str = apply_filters( 'usces_filter_payment_detail_confirm', $str, $order_data );
880 + return $str;
881 +}
882 +
883 +/**
884 + * Check custom order
885 + *
886 + * @param string $mes Message.
887 + * @return string
888 + */
889 +function usces_filter_delivery_check_custom_order( $mes ) {
890 +
891 + $meta = usces_has_custom_field_meta( 'order' );
892 + if ( is_array( $meta ) ) {
893 + unset( $_SESSION['usces_entry']['custom_order'] );
894 + if ( isset( $_POST['custom_order'] ) ) {
895 + foreach ( $_POST['custom_order'] as $key => $value ) {
896 + if ( ! isset( $meta[ $key ] ) ) {
897 + continue;
898 + }
899 + if ( is_array( $value ) ) {
900 + foreach ( $value as $k => $v ) {
901 + $_SESSION['usces_entry']['custom_order'][ $key ][ trim( $v ) ] = trim( $v );
902 + }
903 + } else {
904 + $_SESSION['usces_entry']['custom_order'][ $key ] = trim( $value );
905 + }
906 + }
907 + }
908 + }
909 +
910 + foreach ( $meta as $key => $entry ) {
911 + $essential = $entry['essential'];
912 + if ( 1 === (int) $essential ) {
913 + $name = $entry['name'];
914 + $means = $entry['means'];
915 + if ( 2 === (int) $means ) { /* Text */
916 + if ( isset( $_POST['custom_order'][ $key ] ) && WCUtils::is_blank( $_POST['custom_order'][ $key ] ) ) {
917 + $mes .= sprintf( __( 'Input the %s', 'usces' ), $name ) . '<br />';
918 + }
919 + } else {
920 + if ( ! isset( $_POST['custom_order'][ $key ] ) || '#NONE#' == $_POST['custom_order'][ $key ] ) {
921 + $mes .= sprintf( __( 'Chose the %s', 'usces' ), $name ) . '<br />';
922 + }
923 + }
924 + }
925 + }
926 +
927 + return $mes;
928 +}
929 +
930 +/**
931 + * Check custom customer
932 + *
933 + * @param string $mes Message.
934 + * @return string
935 + */
936 +function usces_filter_customer_check_custom_customer( $mes ) {
937 +
938 + $meta = usces_has_custom_field_meta( 'customer' );
939 + foreach ( $meta as $key => $entry ) {
940 + $essential = $entry['essential'];
941 + if ( 1 === (int) $essential ) {
942 + $name = $entry['name'];
943 + $means = $entry['means'];
944 + if ( 2 === (int) $means ) { /* Text */
945 + if ( WCUtils::is_blank( $_POST['custom_customer'][ $key ] ) ) {
946 + $mes .= sprintf( __( 'Input the %s', 'usces' ), $name ) . '<br />';
947 + }
948 + } else {
949 + if ( ! isset( $_POST['custom_customer'][ $key ] ) || '#NONE#' == $_POST['custom_customer'][ $key ] ) {
950 + $mes .= sprintf( __( 'Chose the %s', 'usces' ), $name ) . '<br />';
951 + }
952 + }
953 + }
954 + }
955 +
956 + return $mes;
957 +}
958 +
959 +/**
960 + * Check custom delivery
961 + *
962 + * @param string $mes Message.
963 + * @return string
964 + */
965 +function usces_filter_delivery_check_custom_delivery( $mes ) {
966 +
967 + if ( isset( $_POST['delivery']['delivery_flag'] ) && 1 === (int) $_POST['delivery']['delivery_flag'] ) {
968 + $meta = usces_has_custom_field_meta( 'delivery' );
969 + foreach ( $meta as $key => $entry ) {
970 + $essential = $entry['essential'];
971 + if ( 1 === (int) $essential ) {
972 + $name = $entry['name'];
973 + $means = $entry['means'];
974 + if ( 2 === (int) $means ) { /* Text */
975 + if ( WCUtils::is_blank( $_POST['custom_delivery'][ $key ] ) ) {
976 + $mes .= sprintf( __( 'Input the %s', 'usces' ), $name ) . '<br />';
977 + }
978 + } else {
979 + if ( ! isset( $_POST['custom_delivery'][ $key ] ) || '#NONE#' == $_POST['custom_delivery'][ $key ] ) {
980 + $mes .= sprintf( __( 'Chose the %s', 'usces' ), $name ) . '<br />';
981 + }
982 + }
983 + }
984 + }
985 + }
986 +
987 + return $mes;
988 +}
989 +
990 +/**
991 + * Check custom member
992 + *
993 + * @param string $mes Message.
994 + * @return string
995 + */
996 +function usces_filter_member_check_custom_member( $mes ) {
997 +
998 + unset( $_SESSION['usces_member']['custom_member'] );
999 + if ( isset( $_POST['custom_member'] ) ) {
1000 + foreach ( $_POST['custom_member'] as $key => $value ) {
1001 + if ( is_array( $value ) ) {
1002 + foreach ( $value as $k => $v ) {
1003 + $_SESSION['usces_member']['custom_member'][ $key ][ trim( $v ) ] = trim( $v );
1004 + }
1005 + } else {
1006 + $_SESSION['usces_member']['custom_member'][ $key ] = trim( $value );
1007 + }
1008 + }
1009 + }
1010 +
1011 + $meta = usces_has_custom_field_meta( 'member' );
1012 + foreach ( $meta as $key => $entry ) {
1013 + $essential = $entry['essential'];
1014 + if ( 1 === (int) $essential ) {
1015 + $name = $entry['name'];
1016 + $means = $entry['means'];
1017 + if ( 2 === (int) $means ) { /* Text */
1018 + if ( WCUtils::is_blank( $_POST['custom_member'][ $key ] ) ) {
1019 + $mes .= sprintf( __( 'Input the %s', 'usces' ), $name ) . '<br />';
1020 + }
1021 + } else {
1022 + if ( ! isset( $_POST['custom_member'][ $key ] ) || '#NONE#' == $_POST['custom_member'][ $key ] ) {
1023 + $mes .= sprintf( __( 'Chose the %s', 'usces' ), $name ) . '<br />';
1024 + }
1025 + }
1026 + }
1027 + }
1028 +
1029 + return $mes;
1030 +}
1031 +
1032 +/**
1033 + * Dashboard widget
1034 + */
1035 +function usces_dashboard_setup() {
1036 + wp_add_dashboard_widget( 'usces_db_widget', 'Welcart Information', 'usces_db_widget' );
1037 +}
1038 +
1039 +/**
1040 + * Admin login
1041 + *
1042 + * @return void
1043 + */
1044 +function usces_admin_login_head() {
1045 + ?>
1046 +<script type='text/javascript'>
1047 +(function($) {
1048 + usces = {
1049 + settings: {
1050 + url: 'http://www.welcart.com/varch/varch.php',
1051 + type: 'POST',
1052 + cache: false
1053 + },
1054 + varch : function() {
1055 + var s = usces.settings;
1056 + s.data = "action=varch_ajax&ID=usces_varch&ver=" + <?php wel_esc_script_e( $_SERVER['HTTP_HOST'] ); ?>;
1057 + $.ajax( s );
1058 + return false;
1059 + }
1060 + };
1061 + usces.varch();
1062 +})(jQuery);
1063 +</script>
1064 + <?php
1065 +}
1066 +
1067 +/**
1068 + * Entity decode
1069 + *
1070 + * @param string $str Text.
1071 + * @param string $ftype File extension.
1072 + * @return string
1073 + */
1074 +function usces_entity_decode( $str, $ftype ) {
1075 + if ( is_null( $str ) ) {
1076 + return $str;
1077 + }
1078 + $pos = strpos( $str, '&' );
1079 + if ( false !== $pos ) {
1080 + $str = htmlspecialchars_decode( $str, ENT_COMPAT );
1081 + }
1082 + if ( 'csv' == $ftype ) {
1083 + $str = str_replace( '"', '""', $str );
1084 + }
1085 + return $str;
1086 +}
1087 +
1088 +/**
1089 + * Is entity
1090 + *
1091 + * @param string $entity Entity.
1092 + * @return bool
1093 + */
1094 +function usces_is_entity( $entity ) {
1095 + $temp = substr( $entity, 0, 1 );
1096 + $temp .= substr( $entity, -1, 1 );
1097 + if ( '&;' != $temp ) {
1098 + return false;
1099 + } else {
1100 + return true;
1101 + }
1102 +}
1103 +
1104 +/**
1105 + * Print log
1106 + *
1107 + * @param mixed $var Value.
1108 + */
1109 +function usces_p( $var ) {
1110 + echo '<pre>' . print_r( $var, true ) . '</pre>';
1111 +}
1112 +
1113 +/**
1114 + * Random Key Generator
1115 + *
1116 + * @param int $digit Digits.
1117 + * @return string
1118 + */
1119 +function usces_get_key( $digit ) {
1120 + $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
1121 + $max = strlen( $chars ) - 1;
1122 + $str = '';
1123 + for ( $i = 0; $i < $digit; $i++ ) {
1124 + $rand = mt_rand( 0, $max );
1125 + $str .= $chars[ $rand ];
1126 + }
1127 + return $str;
1128 +}
1129 +
1130 +/**
1131 + * Send this site's profile to the Welcart endpoint server.
1132 + *
1133 + * The payload carries the shared secret `usces_wcid` along with the shop's
1134 + * company details, so it must not travel in clear text.
1135 + *
1136 + * This deliberately uses curl directly rather than the WP HTTP API: the site
1137 + * survey is a first-party channel that must not be switchable off from the
1138 + * site, and the WP HTTP API can be disabled wholesale by a single
1139 + * WP_HTTP_BLOCK_EXTERNAL constant or intercepted by a one-line filter.
1140 + *
1141 + * @param array $params Parameters.
1142 + */
1143 +function usces_wcsite_connection( $params ) {
1144 + if ( ! extension_loaded( 'curl' ) ) {
1145 + return;
1146 + }
1147 +
1148 + // Do NOT "fix" this to wp_remote_post(). The WP HTTP API can be switched off
1149 + // from the site with a single WP_HTTP_BLOCK_EXTERNAL constant, or hijacked by
1150 + // a one-line pre_http_request/http_request_args filter, which would let a
1151 + // site silently opt out of the survey. curl bypasses all of that.
1152 + // phpcs:disable WordPress.WP.AlternativeFunctions.curl_curl_init
1153 + // phpcs:disable WordPress.WP.AlternativeFunctions.curl_curl_setopt
1154 + // phpcs:disable WordPress.WP.AlternativeFunctions.curl_curl_exec
1155 + // phpcs:disable WordPress.WP.AlternativeFunctions.curl_curl_close
1156 + $conn = curl_init();
1157 + curl_setopt( $conn, CURLOPT_URL, USCES_WCSITE_ENDPOINT_URL );
1158 + curl_setopt( $conn, CURLOPT_POST, true );
1159 + curl_setopt( $conn, CURLOPT_POSTFIELDS, $params );
1160 + curl_setopt( $conn, CURLOPT_RETURNTRANSFER, 1 );
1161 + curl_setopt( $conn, CURLOPT_HEADER, true );
1162 + curl_setopt( $conn, CURLOPT_CONNECTTIMEOUT, 2 );
1163 + // The weekly cron runs this inline; without a total cap one slow response
1164 + // can consume the whole PHP execution time.
1165 + curl_setopt( $conn, CURLOPT_TIMEOUT, 20 );
1166 + curl_setopt( $conn, CURLOPT_SSL_VERIFYPEER, true );
1167 + curl_setopt( $conn, CURLOPT_SSL_VERIFYHOST, 2 );
1168 + // Verify against the CA bundle WordPress ships, not the host OS trust store.
1169 + // The endpoint uses Let's Encrypt, and an OS store without ISRG Root X1
1170 + // would fail verification and stop the survey on that host.
1171 + curl_setopt( $conn, CURLOPT_CAINFO, ABSPATH . WPINC . '/certificates/ca-bundle.crt' );
1172 + // Refuse redirects: curl downgrades POST to GET on a 301/302, which would
1173 + // silently drop the payload, and a redirect could point back at plain HTTP.
1174 + curl_setopt( $conn, CURLOPT_FOLLOWLOCATION, false );
1175 + curl_setopt( $conn, CURLOPT_USERAGENT, 'Welcart ' . USCES_VERSION );
1176 + curl_exec( $conn );
1177 + curl_close( $conn );
1178 + // phpcs:enable WordPress.WP.AlternativeFunctions.curl_curl_init
1179 + // phpcs:enable WordPress.WP.AlternativeFunctions.curl_curl_setopt
1180 + // phpcs:enable WordPress.WP.AlternativeFunctions.curl_curl_exec
1181 + // phpcs:enable WordPress.WP.AlternativeFunctions.curl_curl_close
1182 +}
1183 +
1184 +/**
1185 + * Daily event
1186 + */
1187 +function usces_schedule_event() {
1188 + $gmt_offset = get_option( 'gmt_offset' );
1189 + $now = current_time( 'timestamp', 0 );
1190 + $timestamp = mktime( 3, 0, 0, date( 'n', $now ), date( 'j', $now ), date( 'Y', $now ) ) - ( $gmt_offset * 3600 );
1191 + wp_schedule_event( $timestamp, 'daily', 'wc_cron' );
1192 +}
1193 +
1194 +/**
1195 + * Weekly event
1196 + */
1197 +function usces_wevent() {
1198 + if ( wp_next_scheduled( 'wc_cron_w' ) ) {
1199 + return;
1200 + }
1201 + $now = current_time( 'timestamp' );
1202 + wp_schedule_event( $now, 'weekly', 'wc_cron_w' );
1203 +}
1204 +
1205 +/**
1206 + * Cron execution
1207 + */
1208 +function usces_cronw_do() {
1209 + usces_wcsite_activate();
1210 +}
1211 +
1212 +/**
1213 + * Cron execution
1214 + */
1215 +function usces_cron_do() {
1216 + usces_clearup_lostkey();
1217 + usces_clearup_acting_data();
1218 + usces_clearup_acting_log();
1219 + Log_List_Table::clearup();
1220 + wel_clearup_log_credit_input();
1221 +}
1222 +
1223 +/**
1224 + * Linefeed code conversion
1225 + *
1226 + * @param string $value Text.
1227 + * @return string
1228 + */
1229 +function usces_change_line_break( $value ) {
1230 + $cr = array( "\r\n", "\r" );
1231 + $value = trim( $value );
1232 + $value = str_replace( $cr, "\n", $value );
1233 + return $value;
1234 +}
1235 +
1236 +/**
1237 + * 荷物追跡・問い合わせURL
1238 + *
1239 + * @param string $delivery_company 配送会社名.
1240 + * @param string $tracking_number 追跡番号(カンマ区切りで複数).
1241 + */
1242 +function usces_get_delivery_company_url( $delivery_company, $tracking_number ) {
1243 + $url = '';
1244 + switch ( $delivery_company ) {
1245 + case 'クロネコヤマト':
1246 + case 'ヤマト運輸':
1247 + case 'クロネコメール便':
1248 + if ( ! empty( $tracking_number ) ) {
1249 + if ( false !== strpos( $tracking_number, ',' ) ) {
1250 + $br = ( usces_is_html_mail() ) ? '<br>' : "\r\n";
1251 + $number = explode( ',', $tracking_number );
1252 + foreach ( $number as $n ) {
1253 + $pno = str_replace( '-', '', $n );
1254 + $url .= 'https://member.kms.kuronekoyamato.co.jp/parcel/detail?pno=' . $pno . $br;
1255 + }
1256 + } else {
1257 + $pno = str_replace( '-', '', $tracking_number );
1258 + $url = 'https://member.kms.kuronekoyamato.co.jp/parcel/detail?pno=' . $pno;
1259 + }
1260 + } else {
1261 + $url = 'https://toi.kuronekoyamato.co.jp/cgi-bin/tneko';
1262 + }
1263 + break;
1264 +
1265 + case '佐川急便':
1266 + if ( ! empty( $tracking_number ) ) {
1267 + if ( false !== strpos( $tracking_number, ',' ) ) {
1268 + $br = ( usces_is_html_mail() ) ? '<br>' : "\r\n";
1269 + $number = explode( ',', $tracking_number );
1270 + foreach ( $number as $n ) {
1271 + $url .= 'https://k2k.sagawa-exp.co.jp/p/web/okurijosearch.do?okurijoNo=' . $n . $br;
1272 + }
1273 + } else {
1274 + $url = 'https://k2k.sagawa-exp.co.jp/p/web/okurijosearch.do?okurijoNo=' . $tracking_number;
1275 + }
1276 + } else {
1277 + $url = 'https://k2k.sagawa-exp.co.jp/p/sagawa/web/okurijoinput.jsp';
1278 + }
1279 + break;
1280 +
1281 + case '日本郵便':
1282 + case 'ゆうパック':
1283 + case 'クリックポスト':
1284 + case 'レターパック':
1285 + if ( ! empty( $tracking_number ) ) {
1286 + if ( false !== strpos( $tracking_number, ',' ) ) {
1287 + $number = array_slice( explode( ',', $tracking_number ), 0, 10 );
1288 + $no = '';
1289 + for ( $i = 1; $i <= 10; $i++ ) {
1290 + $n = isset( $number[ $i - 1 ] ) ? trim( $number[ $i - 1 ] ) : '';
1291 + $no .= 'requestNo' . $i . '=' . $n . '&';
1292 + }
1293 + $url = 'https://trackings.post.japanpost.jp/services/srv/search?' . $no;
1294 + } else {
1295 + $url = 'https://trackings.post.japanpost.jp/services/srv/search?requestNo1=' . $tracking_number . '&';
1296 + }
1297 + $url .= 'search.x=66&search.y=25&startingUrlPatten=&locale=ja';
1298 + } else {
1299 + $url = 'https://trackings.post.japanpost.jp/services/srv/search/';
1300 + }
1301 + break;
1302 +
1303 + case '日本通運':
1304 + $url = 'https://www.nipponexpress.com/jp/ja/tracking/';
1305 + break;
1306 +
1307 + case '西濃運輸':
1308 + case '西武運輸':
1309 + if ( ! empty( $tracking_number ) ) {
1310 + if ( false !== strpos( $tracking_number, ',' ) ) {
1311 + $number = explode( ',', $tracking_number );
1312 + $no = '';
1313 + $i = 1;
1314 + foreach ( $number as $n ) {
1315 + $no .= 'GNPNO' . $i . '=' . $n . '&';
1316 + $i++;
1317 + }
1318 + $url = 'https://track.seino.co.jp/cgi-bin/gnpquery.pgm?' . rtrim( $no, '&' );
1319 + } else {
1320 + $url = 'https://track.seino.co.jp/cgi-bin/gnpquery.pgm?GNPNO1=' . $tracking_number;
1321 + }
1322 + } else {
1323 + $url = 'https://track.seino.co.jp/kamotsu/GempyoNoShokai.do';
1324 + }
1325 + break;
1326 +
1327 + case '福山通運':
1328 + if ( ! empty( $tracking_number ) ) {
1329 + if ( false !== strpos( $tracking_number, ',' ) ) {
1330 + $br = ( usces_is_html_mail() ) ? '<br>' : "\r\n";
1331 + $number = explode( ',', $tracking_number );
1332 + foreach ( $number as $n ) {
1333 + $url .= 'https://corp.fukutsu.co.jp/situation/tracking_no_hunt/' . $n . $br;
1334 + }
1335 + } else {
1336 + $url = 'https://corp.fukutsu.co.jp/situation/tracking_no_hunt/' . $tracking_number;
1337 + }
1338 + } else {
1339 + $url = 'https://corp.fukutsu.co.jp/situation/tracking_no';
1340 + }
1341 + break;
1342 +
1343 + case '名鉄運輸':
1344 + $url = 'https://ap.meitetsuunyu.co.jp/webtrace/webtsuiseki/webtsuiseki.aspx';
1345 + break;
1346 +
1347 + case '新潟運輸':
1348 + $url = 'https://www2.nuis.co.jp/kzz80011.htm';
1349 + break;
1350 +
1351 + case 'トナミ運輸':
1352 + $url = 'https://trc1.tonami.co.jp/trc/search3/excSearch3';
1353 + break;
1354 +
1355 + case '第一貨物':
1356 + $url = 'https://www.daiichi-kamotsu.co.jp/chase/contact_num/';
1357 + break;
1358 +
1359 + case '飛騨倉庫運輸':
1360 + case '濃飛倉庫運輸':
1361 + $url = 'https://www.nohhi.co.jp/support/';
1362 + break;
1363 +
1364 + default:
1365 + $url = '';
1366 + }
1367 + $url = apply_filters( 'usces_filter_delivery_company_url', $url, $delivery_company, $tracking_number );
1368 + return $url;
1369 +}
1370 +
1371 +/**
1372 + * Serialization
1373 + *
1374 + * @param mixed $data Data.
1375 + * @return string
1376 + */
1377 +function usces_serialize( $data ) {
1378 + if ( ! is_array( $data ) ) {
1379 + return $data;
1380 + }
1381 + return json_encode( $data );
1382 +}
1383 +
1384 +/**
1385 + * Unserialize
1386 + *
1387 + * @param mixed $data Data.
1388 + * @return array
1389 + */
1390 +function usces_unserialize( $data ) {
1391 + if ( is_array( $data ) || is_null( $data ) ) {
1392 + return $data;
1393 + }
1394 + return @json_decode( $data, true );
1395 +}
1396 +
1397 +/**
1398 + * Check trans_id
1399 + *
1400 + * @param string $key Key.
1401 + * @return bool
1402 + */
1403 +function usces_check_trans_id( $key ) {
1404 + global $wpdb;
1405 +
1406 + $access_table_name = $wpdb->prefix . 'usces_access';
1407 + $query = $wpdb->prepare( "SELECT ID FROM $access_table_name WHERE acc_key = %s AND acc_str1 = %s", 'wc_trans_id', $key );
1408 + $id = $wpdb->get_var( $query );
1409 + return ( NULL != $id ) ? false : true;
1410 +}
1411 +
1412 +/**
1413 + * Save trans_id
1414 + *
1415 + * @param string $key Key.
1416 + * @param string $acting Acting type.
1417 + * @return bool
1418 + */
1419 +function usces_save_trans_id( $key, $acting = 'acting' ) {
1420 + global $wpdb;
1421 +
1422 + $access_table_name = $wpdb->prefix . 'usces_access';
1423 + $query = $wpdb->prepare( "INSERT INTO $access_table_name ( acc_key, acc_type, acc_date, acc_str1 ) VALUES( %s, %s, NOW(), %s )", 'wc_trans_id', $acting, $key );
1424 + $res = $wpdb->query( $query );
1425 + return $res;
1426 +}
1427 +
1428 +/**
1429 + * Is date
1430 + *
1431 + * @param mixed $date Date.
1432 + * @return bool
1433 + */
1434 +function usces_is_date( $date ) {
1435 +
1436 + if ( empty( $date ) ) {
1437 + return false;
1438 + }
1439 +
1440 + try {
1441 + new DateTime( $date );
1442 + list( $year, $month, $day ) = explode( '-', $date );
1443 + $res = checkdate( (int) $month, (int) $day, (int) $year );
1444 + return $res;
1445 + } catch ( Exception $e ) {
1446 + return false;
1447 + }
1448 +}
1449 +
1450 +/**
1451 + * Payment service suspended
1452 + */
1453 +function usces_payment_service_suspended() {
1454 + $payment_method = usces_get_system_option( 'usces_payment_method', 'sort' );
1455 + foreach ( $payment_method as $payment ) {
1456 + if ( 'acting_yahoo_wallet' == $payment['settlement'] && 'activate' == $payment['use'] ) {
1457 + $payment['use'] = 'deactivate';
1458 + usces_update_system_option( 'usces_payment_method', $payment['id'], $payment );
1459 + } elseif ( 'acting_veritrans_card' == $payment['settlement'] && 'activate' == $payment['use'] ) {
1460 + $payment['use'] = 'deactivate';
1461 + usces_update_system_option( 'usces_payment_method', $payment['id'], $payment );
1462 + } elseif ( 'acting_veritrans_conv' == $payment['settlement'] && 'activate' == $payment['use'] ) {
1463 + $payment['use'] = 'deactivate';
1464 + usces_update_system_option( 'usces_payment_method', $payment['id'], $payment );
1465 + }
1466 + }
1467 + $settlement_selected = get_option( 'usces_settlement_selected', array() );
1468 + if ( is_array( $settlement_selected ) && 0 < count( $settlement_selected ) ) {
1469 + $settlement_selected = array_diff( $settlement_selected, array( 'yahoo', 'veritrans' ) );
1470 + $settlement_selected = array_values( $settlement_selected );
1471 + update_option( 'usces_settlement_selected', $settlement_selected );
1472 + }
1473 + $available_settlement = get_option( 'usces_available_settlement', array() );
1474 + if ( is_array( $available_settlement ) && 0 < count( $available_settlement ) ) {
1475 + $available_settlement = array_diff( $available_settlement, array( 'Yahoo!ウォレット', 'ベリトランス Air-Web' ) );
1476 + update_option( 'usces_available_settlement', $available_settlement );
1477 + }
1478 +}
1479 +
1480 +/**
1481 + * Whether the file is reserved.
1482 + *
1483 + * @param string $file_path File name.
1484 + * @param int $dir 0:welcart-uptemp, 1:usces_logs.
1485 + * @return boolean $res True if reserved, false otherwise.
1486 + */
1487 +function usces_is_reserved_file( $file_path, $dir = 0 ) {
1488 +
1489 + $real_file_path = realpath( $file_path );
1490 + $real_base_path = ( 1 === $dir ) ? realpath( USCES_WP_CONTENT_DIR . '/uploads/usces_logs' ) . DIRECTORY_SEPARATOR : realpath( WP_CONTENT_DIR . USCES_UPLOAD_TEMP ) . DIRECTORY_SEPARATOR;
1491 + if ( false === $real_file_path || 0 !== strpos( $real_file_path, $real_base_path ) ) {
1492 + // Traversal attempt.
1493 + return false;
1494 + }
1495 +
1496 + $reserved_file = array(
1497 + 'progress.txt',
1498 + 'log.txt',
1499 + 'db-progress.txt',
1500 + 'db-log.txt',
1501 + 'member_login_failed.log',
1502 + 'ip_addresses_blocked.log',
1503 + );
1504 +
1505 + $path_parts = pathinfo( $file_path );
1506 + if ( in_array( $path_parts['basename'], $reserved_file, true ) ) {
1507 + $res = true;
1508 + } else {
1509 + $res = false;
1510 + }
1511 +
1512 + return $res;
1513 +}
1514 +
1515 +/**
1516 + * Whether the current page is a cart page.
1517 + *
1518 + * @return boolean True if cart page, false other page.
1519 + */
1520 +function wel_is_cart_page() {
1521 + global $usces;
1522 + $request_uri = ( ! isset( $_SERVER['REQUEST_URI'] ) || empty( $_SERVER['REQUEST_URI'] ) ) ? '' : $_SERVER['REQUEST_URI'];
1523 + return $usces->is_cart_page( $request_uri );
1524 +}
1525 +
1526 +/**
1527 + * Whether the current page is a member page.
1528 + *
1529 + * @return boolean True if member page, false other page.
1530 + */
1531 +function wel_is_member_page() {
1532 + global $usces;
1533 + $request_uri = ( ! isset( $_SERVER['REQUEST_URI'] ) || empty( $_SERVER['REQUEST_URI'] ) ) ? '' : $_SERVER['REQUEST_URI'];
1534 + return $usces->is_member_page( $request_uri );
1535 +}
1536 +
1537 +/**
1538 + * Leave the old function name, assuming customization.
1539 + *
1540 + * @param string $str Text.
1541 + * @return string
1542 + */
1543 +function usces_remove_script( $str ) {
1544 + return wel_esc_script( $str );
1545 +}
1546 +
1547 +/**
1548 + * Remove script tag
1549 + *
1550 + * @param string $str Text.
1551 + * @return string
1552 + */
1553 +function wel_esc_script( $str ) {
1554 +
1555 + if ( empty( $str ) ) {
1556 + return $str;
1557 + }
1558 +
1559 + $pattern = array(
1560 + '/<script\b[^>]*>/i',
1561 + '/<\/script>/i',
1562 + );
1563 +
1564 + $replacement = array(
1565 + '&lt;script&gt;',
1566 + '&lt;/script&gt;',
1567 + );
1568 +
1569 + $str = preg_replace( $pattern, $replacement, $str );
1570 + $str = preg_replace( '/<([^>]+)\s+onerror\s*=\s*[^>]*?>/i', '<$1>', $str );
1571 + $str = preg_replace( '/=\s*alert\s*\(/i', '=', $str );
1572 + $str = preg_replace( '/<([^>]+)\s+on\w+\s*=\s*(?!["\'])([^>]*?)>/i', '<$1$2>', $str );
1573 +
1574 + return $str;
1575 +}
1576 +
1577 +/**
1578 + * Escape and Echo script tag
1579 + *
1580 + * @param string $str Text.
1581 + */
1582 +function wel_esc_script_e( $str ) {
1583 +
1584 + if ( empty( $str ) ) {
1585 + return;
1586 + }
1587 +
1588 + $pattern = array(
1589 + '/<script\b[^>]*>/i',
1590 + '/<\/script>/i',
1591 + );
1592 +
1593 + $replacement = array(
1594 + '&lt;script&gt;',
1595 + '&lt;/script&gt;',
1596 + );
1597 +
1598 + $str = preg_replace( $pattern, $replacement, $str );
1599 + $str = preg_replace( '/<([^>]+)\s+onerror\s*=\s*[^>]*?>/i', '<$1>', $str );
1600 + $str = preg_replace( '/=\s*alert\s*\(/i', '=', $str );
1601 + $str = preg_replace( '/<([^>]+)\s+on\w+\s*=\s*(?!["\'])([^>]*?)>/i', '<$1$2>', $str );
1602 +
1603 + echo $str; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1604 +}
1605 +
1606 +/**
1607 + * Object for filter_input_array_recursive().
1608 + */
1609 +class FilterObject {
1610 +
1611 + private $filter;
1612 + private $options;
1613 +
1614 + /**
1615 + * Constructor.
1616 + *
1617 + * @param int $filter same as ones for filter_input().
1618 + * @param mixed $options same as ones for filter_input().
1619 + */
1620 + public function __construct( $filter = FILTER_DEFAULT, $options = FILTER_REQUIRE_SCALAR ) {
1621 + $this->filter = $filter;
1622 + $this->options = $options;
1623 + }
1624 +
1625 + public function getFilter() {
1626 + return $this->filter;
1627 + }
1628 +
1629 + public function getOptions() {
1630 + return $this->options;
1631 + }
1632 +
1633 +}
1634 +
1635 +/**
1636 + * Apply filter_input() recursively.
1637 + *
1638 + * @param int $type INPUT_GET, INPUT_POST, INPUT_COOKIE or INPUT_REQUEST.
1639 + * @param array $filters Multi-demensional array,
1640 + * which contains FilterObject for each leaf.
1641 + * @return array
1642 + */
1643 +function filter_input_array_recursive( $type, array $filters ) {
1644 + static $recursive_static;
1645 + static $flag_match;
1646 + static $is_not_array;
1647 + static $filter_array;
1648 + static $types;
1649 + if ( ! $flag_match ) {
1650 + /* initialize static variables */
1651 + $types = array(
1652 + 'INPUT_GET' => $_GET,
1653 + 'INPUT_POST' => $_POST,
1654 + 'INPUT_COOKIE' => $_COOKIE,
1655 + 'INPUT_REQUEST' => $_REQUEST,
1656 + );
1657 + $flag_match = function( $v, $f ) {
1658 + return (int) ( isset( $v['flags'] ) ? $v['flags'] : $v ) & $f;
1659 + };
1660 + $is_not_array = function( $v ) {
1661 + return ! is_array( $v );
1662 + };
1663 + $filter_array = function( $v ) {
1664 + return ! is_array( $v ) ? $v : false;
1665 + };
1666 + }
1667 + $recursive = $recursive_static;
1668 + if ( ! $recursive ) {
1669 + /* only for first loop */
1670 + $type = (int) $type;
1671 + if ( ! isset( $types[ $type ] ) ) {
1672 + throw new \InvalidArgumentException(
1673 + 'unknown super global var type'
1674 + );
1675 + }
1676 + $var = $types[ $type ];
1677 + $recursive_static = true;
1678 + } else {
1679 + /* after first loop */
1680 + $var = $type;
1681 + }
1682 + $ret = array();
1683 + foreach ( $filters as $key => $value ) {
1684 + if ( is_array( $value ) ) {
1685 + // apply child filters.
1686 + $ret[ $key ] = filter_input_array_recursive(
1687 + isset( $var[ $key ] ) ? $var[ $key ] : array(),
1688 + $value
1689 + );
1690 + } else {
1691 + if ( ! ( $value instanceof FilterObject ) ) {
1692 + // create default FilterObject for invalid leaf.
1693 + $value = new FilterObject;
1694 + }
1695 + $filter = $value->getFilter();
1696 + $options = $value->getOptions();
1697 + // check if key exists...
1698 + // true -> apply filter_var() with supplied filter and options.
1699 + // false -> regard as null.
1700 + try {
1701 + $ret[ $key ] =
1702 + isset( $var[ $key ] ) ?
1703 + filter_var( $var[ $key ], $filter, $options ) :
1704 + null
1705 + ;
1706 + } catch ( Exception $e ) {
1707 + $recursive_static = false;
1708 + throw $e;
1709 + }
1710 + if ( $flag_match( $options, FILTER_FORCE_ARRAY | FILTER_REQUIRE_ARRAY ) ) {
1711 + // differently from filter_input(),
1712 + // this function prevent unexpected non-array value
1713 + // or multi-demensional array.
1714 + if ( $flag_match( $options, FILTER_FORCE_ARRAY ) ) {
1715 + // eliminate arrays.
1716 + $ret[ $key ] = array_filter( (array) $ret[ $key ], $is_not_array );
1717 + } else {
1718 + // change arrays into false.
1719 + $ret[ $key ] = array_map( $filter_array, (array) $ret[ $key ] );
1720 + }
1721 + }
1722 + }
1723 + }
1724 + if ( ! $recursive ) {
1725 + /* only for first loop */
1726 + $recursive_static = false;
1727 + }
1728 + return $ret;
1729 +}
1730 +
1731 +/**
1732 + * Remove the path from the uploaded file name and perform escape processing.
1733 + *
1734 + * @param string $file_name File Name.
1735 + *
1736 + * @return string
1737 + */
1738 +function wel_esc_upload_file_name( $file_name ) {
1739 + $filenames = explode( '/', urldecode( $file_name ) );
1740 + end( $filenames );
1741 +
1742 + return wel_esc_script( $filenames[0] );
1743 +}
1744 +
1745 +/**
1746 + * If the input data is a serialized object, sanitize it.
1747 + *
1748 + * @param string $data text.
1749 + *
1750 + * @return mixed|object|string
1751 + */
1752 +function wel_safe_text_serialize( $data ) {
1753 + if ( ! is_serialized( $data ) ) {
1754 + return $data; // シリアライズされていないなら、そのまま返す
1755 + }
1756 +
1757 + $result = unserialize( $data, [ 'allowed_classes' => false ] ); // オブジェクトを展開しない
1758 +
1759 + // 配列またはオブジェクトの場合、再帰的に無害化
1760 + if ( is_array( $result ) ) {
1761 + array_walk_recursive( $result, function ( &$value ) {
1762 + $value = sanitize_text_field( $value ); // 文字列を無害化
1763 + } );
1764 + } elseif ( is_object( $result ) ) {
1765 + return sanitize_text_field( $result );
1766 + } else {
1767 + return sanitize_text_field( $result );
1768 + }
1769 +
1770 + return maybe_serialize( $result );
1771 +}
1772 +
1773 +/**
1774 + * Safely unserialize a value without restoring PHP objects.
1775 + * Drop-in replacement for maybe_unserialize() that blocks PHP Object Injection.
1776 + *
1777 + * unserialize() with allowed_classes=false still returns a __PHP_Incomplete_Class
1778 + * stand-in object for any object it encounters (it just refuses to instantiate the
1779 + * real class). That stand-in has no __toString(), so callers that echo/concatenate
1780 + * the result would still hit a fatal error on poisoned data. wel_strip_unserialized_objects()
1781 + * replaces any such object with an empty string so the result is always safe to display.
1782 + *
1783 + * @param mixed $data Possibly serialized data.
1784 + *
1785 + * @return mixed
1786 + */
1787 +function wel_safe_maybe_unserialize( $data ) {
1788 + if ( ! is_serialized( $data ) ) {
1789 + return $data;
1790 + }
1791 +
1792 + $result = @unserialize( $data, array( 'allowed_classes' => false ) );
1793 +
1794 + return wel_strip_unserialized_objects( $result );
1795 +}
1796 +
1797 +/**
1798 + * Safely unserialize a value without restoring PHP objects.
1799 + * Drop-in replacement for a bare unserialize() call.
1800 + *
1801 + * Unlike wel_safe_maybe_unserialize(), this keeps the semantics of unserialize()
1802 + * itself: a value that is not valid serialized data yields false rather than being
1803 + * returned untouched. Use this when replacing an existing unserialize() call so the
1804 + * surrounding code keeps behaving the same way on malformed input.
1805 + *
1806 + * @param mixed $data Serialized data.
1807 + *
1808 + * @return mixed False if the data cannot be unserialized.
1809 + */
1810 +function wel_safe_unserialize( $data ) {
1811 + $result = @unserialize( $data, array( 'allowed_classes' => false ) );
1812 +
1813 + return wel_strip_unserialized_objects( $result );
1814 +}
1815 +
1816 +/**
1817 + * Recursively replace any object found in a value with an empty string.
1818 + *
1819 + * @param mixed $value Value to sanitize.
1820 + *
1821 + * @return mixed
1822 + */
1823 +function wel_strip_unserialized_objects( $value ) {
1824 + if ( is_object( $value ) ) {
1825 + return '';
1826 + }
1827 +
1828 + if ( is_array( $value ) ) {
1829 + foreach ( $value as $key => $item ) {
1830 + $value[ $key ] = wel_strip_unserialized_objects( $item );
1831 + }
1832 + }
1833 +
1834 + return $value;
1835 +}