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 -2029 1.3.32.12.4 View file →
@@ -1,2029 +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"]) )
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 -
321 - return $mes;
322 -}
323 -
324 -function usces_get_conv_name($code){
325 - switch($code){
326 - case 'D001':
327 - case '010'://20101018ysk
328 - $name = 'セブンイレブン';
329 - break;
330 - case 'D002':
331 - case '020'://20101018ysk
332 - $name = 'ローソン';
333 - break;
334 - case 'D015':
335 - case '760'://20101018ysk
336 - $name = 'セイコーマート';
337 - break;
338 - case 'D405':
339 - $name = 'ペイジー';
340 - break;
341 - case 'D003':
342 - $name = 'サンクス';
343 - break;
344 - case 'D004':
345 - $name = 'サークルK';
346 - break;
347 - case 'D005':
348 - case '080'://20101018ysk
349 - $name = 'ミニストップ';
350 - break;
351 - case 'D010':
352 - $name = 'デイリーヤマザキ';
353 - break;
354 - case 'D011':
355 - $name = 'ヤマザキデイリーストア';
356 - break;
357 - case 'D030':
358 - case '030'://20101018ysk
359 - $name = 'ファミリーマート';
360 - break;
361 - case 'D401':
362 - $name = 'CyberEdy';
363 - break;
364 - case 'D404':
365 - $name = '楽天銀行';
366 - break;
367 - case 'D406':
368 - $name = 'ジャパネット銀行';
369 - break;
370 - case 'D451':
371 - $name = 'ウェブマネー';
372 - break;
373 - case 'D452':
374 - $name = 'ビットキャッシュ';
375 - break;
376 - case 'P901':
377 - $name = 'コンビニ払込票';
378 - break;
379 - case 'P902':
380 - $name = 'コンビニ払込票(郵便振替対応)';
381 - break;
382 -//20101018ysk start
383 - case '050':
384 - $name = 'デイリーヤマザキ・ヤマザキデイリーストア・タイムリー';
385 - break;
386 - case '060':
387 - $name = 'サークルK・サンクス';
388 - break;
389 - case '110':
390 - $name = 'am/pm';
391 - break;
392 -//20101018ysk end
393 - default:
394 - $name = '';
395 - }
396 - return $name;
397 -}
398 -
399 -function usces_get_remise_conv_return($code){
400 - switch($code){
401 - case 'D001': //セブンイレブン
402 - $html = '<tr><th>' . __('払込番号','usces') . '</th><td>' . esc_html($_REQUEST["X-PAY_NO1"]) . "</td></tr>\n";
403 - $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";
404 - break;
405 - case 'D002': //ローソン
406 - case 'D015': //セイコーマート
407 - case 'D405': //ペイジー
408 - $html = '<tr><th>' . __('受付番号','usces') . '</th><td>' . esc_html($_REQUEST["X-PAY_NO1"]) . "</td></tr>\n";
409 - $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";
410 - break;
411 - case 'D003': //サンクス
412 - case 'D004': //サークルK
413 - case 'D005': //ミニストップ
414 - case 'D010': //デイリーヤマザキ
415 - case 'D011': //ヤマザキデイリーストア
416 - $html = '<tr><th>' . __('決済番号','usces') . '</th><td>' . esc_html($_REQUEST["X-PAY_NO1"]) . "</td></tr>\n";
417 - $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";
418 - break;
419 - case 'D030': //ファミリーマート
420 - $html = '<tr><th>' . __('コード','usces') . '</th><td>' . esc_html($_REQUEST["X-PAY_NO1"]) . "</td></tr>\n";
421 - $html .= '<tr><th>'.__('注文番号', 'usces').'</th><td>'.esc_html($_REQUEST["X-PAY_NO2"])."</td></tr>\n";
422 - break;
423 - case 'D401': //CyberEdy
424 - case 'D404': //楽天銀行
425 - case 'D406': //ジャパネット銀行
426 - case 'D451': //ウェブマネー
427 - case 'D452': //ビットキャッシュ
428 - $html = '<tr><th>' . __('受付番号','usces') . '</th><td>' . esc_html($_REQUEST["X-PAY_NO1"]) . "</td></tr>\n";
429 - $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";
430 - break;
431 - case 'P901': //コンビニ払込票
432 - case 'P902': //コンビニ払込票(郵便振替対応)
433 - $html = '<tr><th>' . __('受付番号','usces') . '</th><td>' . esc_html($_REQUEST["X-PAY_NO1"]) . "</td></tr>\n";
434 - break;
435 - default:
436 - $html = '';
437 - }
438 - return $html;
439 -}
440 -
441 -function usces_payment_detail($usces_entries){
442 - $payments = usces_get_payments_by_name( $usces_entries['order']['payment_name'] );
443 - $acting_flag = ( 'acting' == $payments['settlement'] ) ? $payments['module'] : $payments['settlement'];
444 - $str = '';
445 - switch( $acting_flag ){
446 - case 'paypal.php':
447 - break;
448 -
449 - case 'epsilon.php':
450 - break;
451 -
452 - case 'acting_zeus_card':
453 - if( !isset($_REQUEST['cbrand']) || (isset($_REQUEST['howpay']) && '1' === $_REQUEST['howpay']) ){
454 - $str = ' 一括払い';
455 - }else{
456 - $div_name = 'div_' . $_REQUEST['cbrand'];
457 - switch($_REQUEST[$div_name]){
458 - case '01':
459 - $str = ' 一括払い';
460 - break;
461 - case '99':
462 - $str = ' 分割(リボ払い)';
463 - break;
464 - case '03':
465 - $str = ' 分割(3回)';
466 - break;
467 - case '05':
468 - $str = ' 分割(5回)';
469 - break;
470 - case '06':
471 - $str = ' 分割(6回)';
472 - break;
473 - case '10':
474 - $str = ' 分割(10回)';
475 - break;
476 - case '12':
477 - $str = ' 分割(12回)';
478 - break;
479 - case '15':
480 - $str = ' 分割(15回)';
481 - break;
482 - case '18':
483 - $str = ' 分割(18回)';
484 - break;
485 - case '20':
486 - $str = ' 分割(20回)';
487 - break;
488 - case '24':
489 - $str = ' 分割(24回)';
490 - break;
491 - }
492 - }
493 - break;
494 -
495 - case 'acting_zeus_bank':
496 - break;
497 -
498 - case 'acting_remise_card':
499 - if( isset( $_POST['div'] ) ){
500 - switch($_POST['div']){
501 - case '0':
502 - $str = ' 一括払い';
503 - break;
504 - case '1':
505 - $str = ' 分割(2回)';
506 - break;
507 - case '2':
508 - $str = ' 分割(リボ払い)';
509 - break;
510 - }
511 - }
512 - break;
513 -
514 - case 'acting_remise_conv':
515 - break;
516 - }
517 -
518 - $str = apply_filters('usces_filter_payment_detail', $str, $usces_entries);
519 - return $str;
520 -}
521 -
522 -//20100818ysk start
523 -function usces_filter_delivery_check_custom_order( $mes ) {
524 - global $usces;
525 -
526 - $meta = usces_has_custom_field_meta('order');
527 - foreach($meta as $key => $entry) {
528 - $essential = $entry['essential'];
529 - if($essential == 1) {
530 - $name = $entry['name'];
531 - $means = $entry['means'];
532 - if($means == 2) {//Text
533 - if( WCUtils::is_blank($_POST['custom_order'][$key]) )
534 - $mes .= __($name.'を入力してください。', 'usces')."<br />";
535 - } else {
536 - if(!isset($_POST['custom_order'][$key]) or $_POST['custom_order'][$key] == "#NONE#")
537 - $mes .= __($name.'を選択してください。', 'usces')."<br />";
538 - }
539 - }
540 - }
541 -
542 - return $mes;
543 -}
544 -
545 -function usces_filter_customer_check_custom_customer( $mes ) {
546 - global $usces;
547 -
548 - $meta = usces_has_custom_field_meta('customer');
549 - foreach($meta as $key => $entry) {
550 - $essential = $entry['essential'];
551 - if($essential == 1) {
552 - $name = $entry['name'];
553 - $means = $entry['means'];
554 - if($means == 2) {//Text
555 - if( WCUtils::is_blank($_POST['custom_customer'][$key]) )
556 - $mes .= __($name.'を入力してください。', 'usces')."<br />";
557 - } else {
558 - if(!isset($_POST['custom_customer'][$key]) or $_POST['custom_customer'][$key] == "#NONE#")
559 - $mes .= __($name.'を選択してください。', 'usces')."<br />";
560 - }
561 - }
562 - }
563 -
564 - return $mes;
565 -}
566 -
567 -function usces_filter_delivery_check_custom_delivery( $mes ) {
568 - global $usces;
569 -
570 - if( isset($_POST['delivery']['delivery_flag']) && $_POST['delivery']['delivery_flag'] == '1' ) {
571 - $meta = usces_has_custom_field_meta('delivery');
572 - foreach($meta as $key => $entry) {
573 - $essential = $entry['essential'];
574 - if($essential == 1) {
575 - $name = $entry['name'];
576 - $means = $entry['means'];
577 - if($means == 2) {//Text
578 - if( WCUtils::is_blank($_POST['custom_delivery'][$key]) )
579 - $mes .= __($name.'を入力してください。', 'usces')."<br />";
580 - } else {
581 - if(!isset($_POST['custom_delivery'][$key]) or $_POST['custom_delivery'][$key] == "#NONE#")
582 - $mes .= __($name.'を選択してください。', 'usces')."<br />";
583 - }
584 - }
585 - }
586 - }
587 -
588 - return $mes;
589 -}
590 -
591 -function usces_filter_member_check_custom_member( $mes ) {
592 - global $usces;
593 -
594 - unset($_SESSION['usces_member']['custom_member']);
595 - if(isset($_POST['custom_member'])) {
596 - foreach( $_POST['custom_member'] as $key => $value )
597 - if( is_array($value) ) {
598 - foreach( $value as $k => $v )
599 - $_SESSION['usces_member']['custom_member'][$key][trim($v)] = trim($v);
600 - } else {
601 - $_SESSION['usces_member']['custom_member'][$key] = trim($value);
602 - }
603 - }
604 -
605 - $meta = usces_has_custom_field_meta('member');
606 - foreach($meta as $key => $entry) {
607 - $essential = $entry['essential'];
608 - if($essential == 1) {
609 - $name = $entry['name'];
610 - $means = $entry['means'];
611 - if($means == 2) {//Text
612 - if( WCUtils::is_blank($_POST['custom_member'][$key]) )
613 - $mes .= __($name.'を入力してください。', 'usces')."<br />";
614 - } else {
615 - if(!isset($_POST['custom_member'][$key]) or $_POST['custom_member'][$key] == "#NONE#")
616 - $mes .= __($name.'を選択してください。', 'usces')."<br />";
617 - }
618 - }
619 - }
620 -
621 - return $mes;
622 -}
623 -//20100818ysk end
624 -function usces_dashboard_setup() {
625 - wp_add_dashboard_widget( 'usces_db_widget' , 'Welcart Information' , 'usces_db_widget');
626 -}
627 -
628 -function usces_admin_login_head() {
629 -?>
630 -<script type='text/javascript'>
631 -(function($) {
632 - usces = {
633 - settings: {
634 - url: 'http://www.welcart.com/varch/varch.php',
635 - type: 'POST',
636 - cache: false,
637 - success: function(data, dataType){
638 - },
639 - error: function(msg){
640 - }
641 - },
642 - varch : function() {
643 - var s = usces.settings;
644 - s.data = "action=varch_ajax&ID=usces_varch&ver=" + <?php echo $_SERVER['HTTP_HOST']; ?>;
645 - $.ajax( s );
646 - return false;
647 - }
648 - };
649 - usces.varch();
650 -})(jQuery);
651 -</script>
652 -<?php
653 -}
654 -
655 -//20100908ysk start
656 -// member list download
657 -function usces_download_member_list() {
658 - require_once( USCES_PLUGIN_DIR . "/classes/dataList.class.php" );
659 - global $wpdb, $usces;
660 -//20110411ysk start
661 - global $usces_settings;
662 -//20110411ysk end
663 -
664 - $ext = $_REQUEST['ftype'];
665 -/* if($ext == 'xls') {//HTML
666 - $table_h = "<table>";
667 - $table_f = "</table>";
668 - $tr_h = "<tr>";
669 - $tr_f = "</tr>";
670 - $th_h1 = "<th>";
671 - $th_h = "<th>";
672 - $th_f = "</th>";
673 - $td_h1 = "<td>";
674 - $td_h = "<td>";
675 - $td_f = "</td>";
676 - $lf = "\n";
677 -*/ if($ext == 'xls') {//TSV
678 - $table_h = "";
679 - $table_f = "";
680 - $tr_h = "";
681 - $tr_f = "";
682 - $th_h1 = '"';
683 - $th_h = "\t".'"';
684 - $th_f = '"';
685 - $td_h1 = '"';
686 - $td_h = "\t".'"';
687 - $td_f = '"';
688 - $lf = "\n";
689 - } elseif($ext == 'csv') {//CSV
690 - $table_h = "";
691 - $table_f = "";
692 - $tr_h = "";
693 - $tr_f = "";
694 -//20110201ysk start
695 - //$th_h1 = "";
696 - $th_h1 = '"';
697 - //$th_h = ",";
698 - $th_h = ',"';
699 - //$th_f = "";
700 - $th_f = '"';
701 - //$td_h1 = "";
702 - $td_h1 = '"';
703 - //$td_h = ",";
704 - $td_h = ',"';
705 - //$td_f = "";
706 - $td_f = '"';
707 -//20110201ysk end
708 - $lf = "\n";
709 - } else {
710 - exit();
711 - }
712 - $csmb_meta = usces_has_custom_field_meta('member');
713 -//20110411ysk start
714 - $applyform = usces_get_apply_addressform($usces->options['system']['addressform']);
715 -//20110411ysk end
716 -
717 - //==========================================================================
718 - $usces_opt_member = get_option('usces_opt_member');
719 - if(!is_array($usces_opt_member)){
720 - $usces_opt_member = array();
721 - }
722 - $usces_opt_member['ftype_mem'] = $ext;
723 - $chk_mem = array();
724 - $chk_mem['ID'] = 1;
725 - $chk_mem['email'] = (isset($_REQUEST['check']['email'])) ? 1 : 0;
726 - if(!empty($csmb_meta)) {
727 - foreach($csmb_meta as $key => $entry) {
728 - if($entry['position'] == 'name_pre') {
729 - $name = $entry['name'];
730 -//20110208ysk start
731 - $csmb_key = 'csmb_'.$key;
732 - //$chk_mem[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
733 - $chk_mem[$csmb_key] = (isset($_REQUEST['check'][$csmb_key])) ? 1 : 0;
734 -//20110208ysk end
735 - }
736 - }
737 - }
738 - $chk_mem['name'] = 1;
739 -//20110411ysk start
740 - if($applyform == 'JP') {
741 - $chk_mem['kana'] = (isset($_REQUEST['check']['kana'])) ? 1 : 0;
742 - }
743 -//20110411ysk end
744 - if(!empty($csmb_meta)) {
745 - foreach($csmb_meta as $key => $entry) {
746 - if($entry['position'] == 'name_after') {
747 - $name = $entry['name'];
748 -//20110208ysk start
749 - $csmb_key = 'csmb_'.$key;
750 - //$chk_mem[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
751 - $chk_mem[$csmb_key] = (isset($_REQUEST['check'][$csmb_key])) ? 1 : 0;
752 -//20110208ysk end
753 - }
754 - }
755 - }
756 - $chk_mem['zip'] = (isset($_REQUEST['check']['zip'])) ? 1 : 0;
757 -//20110411ysk start
758 - $chk_mem['country'] = 1;
759 -//20110411ysk end
760 - $chk_mem['pref'] = 1;
761 - $chk_mem['address1'] = 1;
762 - $chk_mem['address2'] = 1;
763 - $chk_mem['address3'] = 1;
764 - $chk_mem['tel'] = (isset($_REQUEST['check']['tel'])) ? 1 : 0;
765 - $chk_mem['fax'] = (isset($_REQUEST['check']['fax'])) ? 1 : 0;
766 - if(!empty($csmb_meta)) {
767 - foreach($csmb_meta as $key => $entry) {
768 - if($entry['position'] == 'fax_after') {
769 - $name = $entry['name'];
770 -//20110208ysk start
771 - $csmb_key = 'csmb_'.$key;
772 - //$chk_mem[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
773 - $chk_mem[$csmb_key] = (isset($_REQUEST['check'][$csmb_key])) ? 1 : 0;
774 -//20110208ysk end
775 - }
776 - }
777 - }
778 - $chk_mem['date'] = (isset($_REQUEST['check']['date'])) ? 1 : 0;
779 - $chk_mem['point'] = (isset($_REQUEST['check']['point'])) ? 1 : 0;
780 - $chk_mem['rank'] = (isset($_REQUEST['check']['rank'])) ? 1 : 0;
781 - $usces_opt_member['chk_mem'] = $chk_mem;
782 - update_option('usces_opt_member', $usces_opt_member);
783 - //==========================================================================
784 -
785 - $_REQUEST['searchIn'] = "searchIn";
786 - $tableName = $wpdb->prefix."usces_member";
787 - $arr_column = array(
788 - __('membership number', 'usces') => 'ID',
789 - __('name', 'usces') => 'name',
790 - __('Address', 'usces') => 'address',
791 - __('Phone number', 'usces') => 'tel',
792 - __('e-mail', 'usces') => 'email',
793 - __('Strated date', 'usces') => 'date',
794 - __('current point', 'usces') => 'point');
795 - $DT = new dataList($tableName, $arr_column);
796 -//20101202ysk start
797 - $DT->pageLimit = 'off';
798 -//20101202ysk end
799 - $res = $DT->MakeTable();
800 - $rows = $DT->rows;
801 -
802 - //==========================================================================
803 - $line = $table_h;
804 - $line .= $tr_h;
805 - $line .= $th_h1.__('membership number', 'usces').$th_f;
806 - if(isset($_REQUEST['check']['email'])) $line .= $th_h.__('e-mail', 'usces').$th_f;
807 - if(!empty($csmb_meta)) {
808 - foreach($csmb_meta as $key => $entry) {
809 - if($entry['position'] == 'name_pre') {
810 - $name = $entry['name'];
811 -//20110208ysk start
812 - $csmb_key = 'csmb_'.$key;
813 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
814 - if(isset($_REQUEST['check'][$csmb_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
815 -//20110208ysk end
816 - }
817 - }
818 - }
819 - $line .= $th_h.__('name', 'usces').$th_f;
820 -//20110411ysk start
821 - if($applyform == 'JP') {
822 - if(isset($_REQUEST['check']['kana'])) $line .= $th_h.__('furigana', 'usces').$th_f;
823 - }
824 -//20110411ysk end
825 - if(!empty($csmb_meta)) {
826 - foreach($csmb_meta as $key => $entry) {
827 - if($entry['position'] == 'name_after') {
828 - $name = $entry['name'];
829 -//20110208ysk start
830 - $csmb_key = 'csmb_'.$key;
831 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
832 - if(isset($_REQUEST['check'][$csmb_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
833 -//20110208ysk end
834 - }
835 - }
836 - }
837 -//20110411ysk start
838 - switch($applyform) {
839 - case 'JP':
840 - if(isset($_REQUEST['check']['zip'])) $line .= $th_h.__('Zip/Postal Code', 'usces').$th_f;
841 - $line .= $th_h.__('Country', 'usces').$th_f;
842 - $line .= $th_h.__('Province', 'usces').$th_f;
843 - $line .= $th_h.__('city', 'usces').$th_f;
844 - $line .= $th_h.__('numbers', 'usces').$th_f;
845 - $line .= $th_h.__('building name', 'usces').$th_f;
846 - if(isset($_REQUEST['check']['tel'])) $line .= $th_h.__('Phone number', 'usces').$th_f;
847 - if(isset($_REQUEST['check']['fax'])) $line .= $th_h.__('FAX number', 'usces').$th_f;
848 - break;
849 - case 'US':
850 - default:
851 - $line .= $th_h.__('Address Line1', 'usces').$th_f;
852 - $line .= $th_h.__('Address Line2', 'usces').$th_f;
853 - $line .= $th_h.__('city', 'usces').$th_f;
854 - $line .= $th_h.__('State', 'usces').$th_f;
855 - $line .= $th_h.__('Country', 'usces').$th_f;
856 - if(isset($_REQUEST['check']['zip'])) $line .= $th_h.__('Zip', 'usces').$th_f;
857 - if(isset($_REQUEST['check']['tel'])) $line .= $th_h.__('Phone number', 'usces').$th_f;
858 - if(isset($_REQUEST['check']['fax'])) $line .= $th_h.__('FAX number', 'usces').$th_f;
859 - break;
860 - }
861 -//20110411ysk end
862 - if(!empty($csmb_meta)) {
863 - foreach($csmb_meta as $key => $entry) {
864 - if($entry['position'] == 'fax_after') {
865 - $name = $entry['name'];
866 -//20110208ysk start
867 - $csmb_key = 'csmb_'.$key;
868 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
869 - if(isset($_REQUEST['check'][$csmb_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
870 -//20110208ysk end
871 - }
872 - }
873 - }
874 - if(isset($_REQUEST['check']['date'])) $line .= $th_h.__('Strated date', 'usces').$th_f;
875 - if(isset($_REQUEST['check']['point'])) $line .= $th_h.__('current point', 'usces').$th_f;
876 - if(isset($_REQUEST['check']['rank'])) $line .= $th_h.__('Rank', 'usces').$th_f;
877 - $line .= $tr_f.$lf;
878 - //==========================================================================
879 - foreach((array)$rows as $array) {
880 - $member_id = $array['ID'];
881 - $query = $wpdb->prepare("SELECT * FROM $tableName WHERE ID = %d", $member_id);
882 - $data = $wpdb->get_row( $query, ARRAY_A );
883 -
884 - $line .= $tr_h;
885 - $line .= $td_h1.$member_id.$td_f;
886 - if(isset($_REQUEST['check']['email'])) $line .= $td_h.usces_entity_decode($array['email'], $ext).$td_f;
887 - if(!empty($csmb_meta)) {
888 - foreach($csmb_meta as $key => $entry) {
889 - if($entry['position'] == 'name_pre') {
890 - $name = $entry['name'];
891 - $csmb_key = 'csmb_'.$key;
892 -//20110208ysk start
893 - //if(isset($_REQUEST['check'][$name])) {
894 - if(isset($_REQUEST['check'][$csmb_key])) {
895 -//20110208ysk end
896 - $value = maybe_unserialize($usces->get_member_meta_value($csmb_key, $member_id));
897 - if(empty($value)) {
898 - $value = '';
899 - } elseif(is_array($value)) {
900 - $concatval = '';
901 - $c = '';
902 - foreach($value as $v) {
903 - $concatval .= $c.$v;
904 - $c = ' ';
905 - }
906 - $value = $concatval;
907 - }
908 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
909 - }
910 - }
911 - }
912 - }
913 -//20110411ysk start
914 - switch($applyform) {
915 - case 'JP':
916 - $line .= $td_h.usces_entity_decode($data['mem_name1'].' '.$data['mem_name2'], $ext).$td_f;
917 - if(isset($_REQUEST['check']['kana'])) $line .= $td_h.usces_entity_decode($data['mem_name3'].' '.$data['mem_name4'], $ext).$td_f;
918 - break;
919 - case 'US':
920 - default:
921 - $line .= $td_h.usces_entity_decode($data['mem_name2'].' '.$data['mem_name1'], $ext).$td_f;
922 - break;
923 - }
924 -//20110411ysk end
925 - if(!empty($csmb_meta)) {
926 - foreach($csmb_meta as $key => $entry) {
927 - if($entry['position'] == 'name_after') {
928 - $name = $entry['name'];
929 - $csmb_key = 'csmb_'.$key;
930 -//20110208ysk start
931 - //if(isset($_REQUEST['check'][$name])) {
932 - if(isset($_REQUEST['check'][$csmb_key])) {
933 -//20110208ysk end
934 - $value = maybe_unserialize($usces->get_member_meta_value($csmb_key, $member_id));
935 - if(empty($value)) {
936 - $value = '';
937 - } elseif(is_array($value)) {
938 - $concatval = '';
939 - $c = '';
940 - foreach($value as $v) {
941 - $concatval .= $c.$v;
942 - $c = ' ';
943 - }
944 - $value = $concatval;
945 - }
946 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
947 - }
948 - }
949 - }
950 - }
951 -//20110411ysk start
952 - switch($applyform) {
953 - case 'JP':
954 - if(isset($_REQUEST['check']['zip'])) $line .= $td_h.usces_entity_decode($data['mem_zip'], $ext).$td_f;
955 - $line .= $td_h.$usces_settings['country'][$usces->get_member_meta_value('customer_country', $member_id)].$td_f;
956 - $line .= $td_h.usces_entity_decode($data['mem_pref'], $ext).$td_f;
957 - $line .= $td_h.usces_entity_decode($data['mem_address1'], $ext).$td_f;
958 - $line .= $td_h.usces_entity_decode($data['mem_address2'], $ext).$td_f;
959 - $line .= $td_h.usces_entity_decode($data['mem_address3'], $ext).$td_f;
960 - if(isset($_REQUEST['check']['tel'])) $line .= $td_h.usces_entity_decode($data['mem_tel'], $ext).$td_f;
961 - if(isset($_REQUEST['check']['fax'])) $line .= $td_h.usces_entity_decode($data['mem_fax'], $ext).$td_f;
962 - break;
963 - case 'US':
964 - default:
965 - $line .= $td_h.usces_entity_decode($data['mem_address2'], $ext).$td_f;
966 - $line .= $td_h.usces_entity_decode($data['mem_address3'], $ext).$td_f;
967 - $line .= $td_h.usces_entity_decode($data['mem_address1'], $ext).$td_f;
968 - $line .= $td_h.usces_entity_decode($data['mem_pref'], $ext).$td_f;
969 - $line .= $td_h.$usces_settings['country'][$usces->get_member_meta_value('customer_country', $member_id)].$td_f;
970 - if(isset($_REQUEST['check']['zip'])) $line .= $td_h.usces_entity_decode($data['mem_zip'], $ext).$td_f;
971 - if(isset($_REQUEST['check']['tel'])) $line .= $td_h.usces_entity_decode($data['mem_tel'], $ext).$td_f;
972 - if(isset($_REQUEST['check']['fax'])) $line .= $td_h.usces_entity_decode($data['mem_fax'], $ext).$td_f;
973 - break;
974 - }
975 -//20110411ysk end
976 - if(!empty($csmb_meta)) {
977 - foreach($csmb_meta as $key => $entry) {
978 - if($entry['position'] == 'fax_after') {
979 - $name = $entry['name'];
980 - $csmb_key = 'csmb_'.$key;
981 -//20110208ysk start
982 - //if(isset($_REQUEST['check'][$name])) {
983 - if(isset($_REQUEST['check'][$csmb_key])) {
984 -//20110208ysk end
985 - $value = maybe_unserialize($usces->get_member_meta_value($csmb_key, $member_id));
986 - if(empty($value)) {
987 - $value = '';
988 - } elseif(is_array($value)) {
989 - $concatval = '';
990 - $c = '';
991 - foreach($value as $v) {
992 - $concatval .= $c.$v;
993 - $c = ' ';
994 - }
995 - $value = $concatval;
996 - }
997 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
998 - }
999 - }
1000 - }
1001 - }
1002 - if(isset($_REQUEST['check']['date'])) $line .= $td_h.$data['mem_registered'].$td_f;
1003 - if(isset($_REQUEST['check']['point'])) $line .= $td_h.$data['mem_point'].$td_f;
1004 - if(isset($_REQUEST['check']['rank'])) {
1005 - $rank = '';
1006 - foreach((array)$usces->member_status as $rk => $rv) {
1007 - if($rk == $data['mem_status']) {
1008 - $rank = $rv;
1009 - break;
1010 - }
1011 - }
1012 - $line .= $td_h.$rank.$td_f;
1013 - }
1014 - $line .= $tr_f.$lf;
1015 - }
1016 - $line .= $table_f.$lf;
1017 - //==========================================================================
1018 -
1019 - if($ext == 'xls') {
1020 - header("Content-Type: application/vnd.ms-excel; charset=Shift-JIS");
1021 - } elseif($ext == 'csv') {
1022 - header("Content-Type: application/octet-stream");
1023 - }
1024 - header("Content-Disposition: attachment; filename=usces_member_list.".$ext);
1025 - mb_http_output('pass');
1026 - print(mb_convert_encoding($line, "SJIS-win", "UTF-8"));
1027 - exit();
1028 -}
1029 -
1030 -// product list download
1031 -function usces_download_product_list() {
1032 - require_once( USCES_PLUGIN_DIR . "/classes/orderList.class.php" );
1033 - global $wpdb, $usces;
1034 -
1035 - $ext = $_REQUEST['ftype'];
1036 -/* if($ext == 'xls') {//HTML
1037 - $table_h = "<table>";
1038 - $table_f = "</table>";
1039 - $tr_h = "<tr>";
1040 - $tr_f = "</tr>";
1041 - $th_h1 = "<th>";
1042 - $th_h = "<th>";
1043 - $th_f = "</th>";
1044 - $td_h1 = "<td>";
1045 - $td_h = "<td>";
1046 - $td_f = "</td>";
1047 - $sp = ":";
1048 - $nb = " ";
1049 - $lf = "\n";
1050 -*/ if($ext == 'xls') {//TSV
1051 - $table_h = "";
1052 - $table_f = "";
1053 - $tr_h = "";
1054 - $tr_f = "";
1055 - $th_h1 = '"';
1056 - $th_h = "\t".'"';
1057 - $th_f = '"';
1058 - $td_h1 = '"';
1059 - $td_h = "\t".'"';
1060 - $td_f = '"';
1061 - $sp = ":";
1062 - $nb = "\n";
1063 - $lf = "\n";
1064 - } elseif($ext == 'csv') {//CSV
1065 - $table_h = "";
1066 - $table_f = "";
1067 - $tr_h = "";
1068 - $tr_f = "";
1069 -//20110201ysk start
1070 - //$th_h1 = "";
1071 - $th_h1 = '"';
1072 - //$th_h = ",";
1073 - $th_h = ',"';
1074 - //$th_f = "";
1075 - $th_f = '"';
1076 - //$td_h1 = "";
1077 - $td_h1 = '"';
1078 - //$td_h = ",";
1079 - $td_h = ',"';
1080 - //$td_f = "";
1081 - $td_f = '"';
1082 -//20110201ysk end
1083 - $sp = ":";
1084 - $nb = " ";
1085 - $lf = "\n";
1086 - } else {
1087 - exit();
1088 - }
1089 -
1090 - //==========================================================================
1091 - $usces_opt_order = get_option('usces_opt_order');
1092 - if(!is_array($usces_opt_order)){
1093 - $usces_opt_order = array();
1094 - }
1095 - $usces_opt_order['ftype_pro'] = $ext;
1096 - $chk_pro = array();
1097 - $chk_pro['ID'] = 1;
1098 - $chk_pro['deco_id'] = 1;
1099 - $chk_pro['date'] = (isset($_REQUEST['check']['date'])) ? 1 : 0;
1100 - $chk_pro['mem_id'] = (isset($_REQUEST['check']['mem_id'])) ? 1 : 0;
1101 - $chk_pro['name'] = (isset($_REQUEST['check']['name'])) ? 1 : 0;
1102 - $chk_pro['delivery_method'] = (isset($_REQUEST['check']['delivery_method'])) ? 1 : 0;
1103 - $chk_pro['shipping_date'] = (isset($_REQUEST['check']['shipping_date'])) ? 1 : 0;
1104 - $chk_pro['item_code'] = 1;
1105 - $chk_pro['sku_code'] = 1;
1106 - $chk_pro['item_name'] = (isset($_REQUEST['check']['item_name'])) ? 1 : 0;
1107 - $chk_pro['sku_name'] = (isset($_REQUEST['check']['sku_name'])) ? 1 : 0;
1108 - $chk_pro['options'] = (isset($_REQUEST['check']['options'])) ? 1 : 0;
1109 - $chk_pro['quantity'] = 1;
1110 - $chk_pro['price'] = 1;
1111 - $chk_pro['unit'] = (isset($_REQUEST['check']['unit'])) ? 1 : 0;
1112 - $usces_opt_order['chk_pro'] = apply_filters( 'usces_filter_chk_pro', $chk_pro );
1113 - update_option('usces_opt_order', $usces_opt_order);
1114 - //==========================================================================
1115 -
1116 - $_REQUEST['searchIn'] = "searchIn";
1117 - $tableName = $wpdb->prefix."usces_order";
1118 - $arr_column = array(
1119 - __('ID', 'usces') => 'ID',
1120 - __('Order number', 'usces') => 'deco_id',
1121 - __('date', 'usces') => 'date',
1122 - __('membership number', 'usces') => 'mem_id',
1123 - __('name', 'usces') => 'name',
1124 - __('Region', 'usces') => 'pref',
1125 - __('shipping option', 'usces') => 'delivery_method',
1126 - __('Amount', 'usces') => 'total_price',
1127 - __('payment method', 'usces') => 'payment_name',
1128 - __('transfer statement', 'usces') => 'receipt_status',
1129 - __('Processing', 'usces') => 'order_status',
1130 - __('shpping date', 'usces') => 'order_modified');
1131 - $DT = new dataList($tableName, $arr_column);
1132 -//20101202ysk start
1133 - $DT->pageLimit = 'off';
1134 -//20101202ysk end
1135 - $res = $DT->MakeTable();
1136 - $rows = $DT->rows;
1137 -
1138 - //==========================================================================
1139 - $line = $table_h;
1140 - $line .= $tr_h;
1141 - $line .= $th_h1.__('ID', 'usces').$th_f;
1142 - $line .= $th_h.__('Order number', 'usces').$th_f;
1143 - if(isset($_REQUEST['check']['date'])) $line .= $th_h.__('order date', 'usces').$th_f;
1144 - if(isset($_REQUEST['check']['mem_id'])) $line .= $th_h.__('membership number', 'usces').$th_f;
1145 - if(isset($_REQUEST['check']['name'])) $line .= $th_h.__('name', 'usces').$th_f;
1146 - if(isset($_REQUEST['check']['delivery_method'])) $line .= $th_h.__('shipping option', 'usces').$th_f;
1147 - if(isset($_REQUEST['check']['shipping_date'])) $line .= $th_h.__('shpping date', 'usces').$th_f;
1148 - $line .= apply_filters( 'usces_filter_chk_pro_label_head', NULL, $usces_opt_order, $rows);
1149 - $line .= $th_h.__('item code', 'usces').$th_f;
1150 - $line .= $th_h.__('SKU code', 'usces').$th_f;
1151 - if(isset($_REQUEST['check']['item_name'])) $line .= $th_h.__('item name', 'usces').$th_f;
1152 - if(isset($_REQUEST['check']['sku_name'])) $line .= $th_h.__('SKU display name ', 'usces').$th_f;
1153 - if(isset($_REQUEST['check']['options'])) $line .= $th_h.__('options for items', 'usces').$th_f;
1154 - $line .= $th_h.__('Quantity', 'usces').$th_f;
1155 - $line .= $th_h.__('Unit price', 'usces').$th_f;
1156 - if(isset($_REQUEST['check']['unit'])) $line .= $th_h.__('unit', 'usces').$th_f;
1157 - $line .= apply_filters( 'usces_filter_chk_pro_label_detail', NULL, $usces_opt_order, $rows);
1158 - $line .= $tr_f.$lf;
1159 - //==========================================================================
1160 - foreach((array)$rows as $array) {
1161 - $order_id = $array['ID'];
1162 - $query = $wpdb->prepare("SELECT * FROM $tableName WHERE ID = %d", $order_id);
1163 - $data = $wpdb->get_row( $query, ARRAY_A );
1164 - //$cart = stripslashes_deep(unserialize($data['order_cart']));
1165 - $cart = unserialize($data['order_cart']);
1166 - //if(!empty($data)) {
1167 - // $data = stripslashes_deep($data);
1168 - //}
1169 - for($i = 0; $i < count($cart); $i++) {
1170 - $cart_row = $cart[$i];
1171 - $post_id = $cart_row['post_id'];
1172 - $sku = urldecode($cart_row['sku']);
1173 -
1174 - $line .= $tr_h;
1175 - $line .= $td_h1.$order_id.$td_f;
1176 - $line .= $td_h.$array['deco_id'].$td_f;
1177 - if(isset($_REQUEST['check']['date'])) $line .= $td_h.$array['date'].$td_f;
1178 - if(isset($_REQUEST['check']['mem_id'])) $line .= $td_h.$array['mem_id'].$td_f;
1179 - if(isset($_REQUEST['check']['name'])) $line .= $td_h.usces_entity_decode($data['order_name1'].$data['order_name2'], $ext).$td_f;
1180 - if(isset($_REQUEST['check']['delivery_method'])) {
1181 - $delivery_method = '';
1182 - if(strtoupper($data['order_delivery_method']) == '#NONE#') {
1183 - $delivery_method = __('No preference', 'usces');
1184 - } else {
1185 - foreach((array)$usces->options['delivery_method'] as $dkey => $delivery) {
1186 - if($delivery['id'] == $data['order_delivery_method']) {
1187 - $delivery_method = $delivery['name'];
1188 - break;
1189 - }
1190 - }
1191 - }
1192 - $line .= $td_h.$delivery_method.$td_f;
1193 - }
1194 - if(isset($_REQUEST['check']['shipping_date'])) $line .= $td_h.$data['order_modified'].$td_f;
1195 - $line .= apply_filters( 'usces_filter_chk_pro_data_head', NULL, $usces_opt_order, $data, $cart_row);
1196 -
1197 - $line .= $td_h.$usces->getItemCode($post_id).$td_f;
1198 - $line .= $td_h.$sku.$td_f;
1199 - if(isset($_REQUEST['check']['item_name'])) $line .= $td_h.usces_entity_decode($usces->getItemName($post_id), $ext).$td_f;
1200 - if(isset($_REQUEST['check']['sku_name'])) $line .= $td_h.usces_entity_decode($usces->getItemSkuDisp($post_id, $sku), $ext).$td_f;
1201 - if(isset($_REQUEST['check']['options'])) {
1202 - $options = $cart_row['options'];
1203 - $optstr = '';
1204 - if(is_array($options) && count($options) > 0) {
1205 - foreach((array)$options as $key => $value) {
1206 - if(!empty($key)) {
1207 - if(is_array($value)) {
1208 - foreach($value as $v) {
1209 - $optstr .= usces_entity_decode(urldecode($key), $ext).$sp;
1210 - foreach($value as $v) {
1211 - $optstr .= usces_entity_decode(urldecode($v), $ext).$nb;
1212 - }
1213 - }
1214 - } else {
1215 - //$optstr .= usces_entity_decode($key, $ext).$sp.usces_entity_decode($value, $ext).$nb;
1216 - $optstr .= usces_entity_decode(urldecode($key).$sp.urldecode($value), $ext).$nb;
1217 - }
1218 - }
1219 - }
1220 - }
1221 - $line .= $td_h.$optstr.$td_f;
1222 - }
1223 - $line .= $td_h.$cart_row['quantity'].$td_f;
1224 - $line .= $td_h.usces_crform($cart_row['price'], false, false, 'return', false).$td_f;
1225 - if(isset($_REQUEST['check']['unit'])) $line .= $td_h.usces_entity_decode($usces->getItemSkuUnit($post_id, $sku), $ext).$td_f;
1226 - $line .= apply_filters( 'usces_filter_chk_pro_data_detail', NULL, $usces_opt_order, $data, $cart_row);
1227 - $line .= $tr_f.$lf;
1228 - }
1229 - }
1230 - $line .= $table_f.$lf;
1231 - //==========================================================================
1232 -
1233 - if($ext == 'xls') {
1234 - header("Content-Type: application/vnd.ms-excel; charset=Shift-JIS");
1235 - } elseif($ext == 'csv') {
1236 - header("Content-Type: application/octet-stream");
1237 - }
1238 - header("Content-Disposition: attachment; filename=usces_product_list.".$ext);
1239 - mb_http_output('pass');
1240 - print(mb_convert_encoding($line, "SJIS-win", "UTF-8"));
1241 - exit();
1242 -}
1243 -
1244 -// order list download
1245 -function usces_download_order_list() {
1246 - require_once( USCES_PLUGIN_DIR . "/classes/orderList.class.php" );
1247 - global $wpdb, $usces;
1248 -//20110411ysk start
1249 - global $usces_settings;
1250 -//20110411ysk end
1251 -
1252 - $ext = $_REQUEST['ftype'];
1253 -/* if($ext == 'xls') {//HTML
1254 - $table_h = "<table>";
1255 - $table_f = "</table>";
1256 - $tr_h = "<tr>";
1257 - $tr_f = "</tr>";
1258 - $th_h1 = "<th>";
1259 - $th_h = "<th>";
1260 - $th_f = "</th>";
1261 - $td_h1 = "<td>";
1262 - $td_h = "<td>";
1263 - $td_f = "</td>";
1264 - $sp = ":";
1265 - $lf = "\n";
1266 -*/ if($ext == 'xls') {//TSV
1267 - $table_h = "";
1268 - $table_f = "";
1269 - $tr_h = "";
1270 - $tr_f = "";
1271 - $th_h1 = '"';
1272 - $th_h = "\t".'"';
1273 - $th_f = '"';
1274 - $td_h1 = '"';
1275 - $td_h = "\t".'"';
1276 - $td_f = '"';
1277 - $sp = ":";
1278 - $lf = "\n";
1279 - } elseif($ext == 'csv') {//CSV
1280 - $table_h = "";
1281 - $table_f = "";
1282 - $tr_h = "";
1283 - $tr_f = "";
1284 -//20110201ysk start
1285 - //$th_h1 = "";
1286 - $th_h1 = '"';
1287 - //$th_h = ",";
1288 - $th_h = ',"';
1289 - //$th_f = "";
1290 - $th_f = '"';
1291 - //$td_h1 = "";
1292 - $td_h1 = '"';
1293 - //$td_h = ",";
1294 - $td_h = ',"';
1295 - //$td_f = "";
1296 - $td_f = '"';
1297 -//20110201ysk end
1298 - $sp = ":";
1299 - $lf = "\n";
1300 - } else {
1301 - exit();
1302 - }
1303 - $csod_meta = usces_has_custom_field_meta('order');
1304 - $cscs_meta = usces_has_custom_field_meta('customer');
1305 - $csde_meta = usces_has_custom_field_meta('delivery');
1306 -//20110411ysk start
1307 - $applyform = usces_get_apply_addressform($usces->options['system']['addressform']);
1308 -//20110411ysk end
1309 -
1310 - //==========================================================================
1311 - $usces_opt_order = get_option('usces_opt_order');
1312 - if(!is_array($usces_opt_order)){
1313 - $usces_opt_order = array();
1314 - }
1315 - $usces_opt_order['ftype_ord'] = $ext;
1316 - $chk_ord = array();
1317 - $chk_ord['ID'] = 1;
1318 - $chk_ord['deco_id'] = 1;
1319 - $chk_ord['date'] = 1;
1320 - $chk_ord['mem_id'] = (isset($_REQUEST['check']['mem_id'])) ? 1 : 0;
1321 - $chk_ord['email'] = (isset($_REQUEST['check']['email'])) ? 1 : 0;
1322 - if(!empty($cscs_meta)) {
1323 - foreach($cscs_meta as $key => $entry) {
1324 - if($entry['position'] == 'name_pre') {
1325 - $name = $entry['name'];
1326 -//20110208ysk start
1327 - $cscs_key = 'cscs_'.$key;
1328 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1329 - $chk_ord[$cscs_key] = (isset($_REQUEST['check'][$cscs_key])) ? 1 : 0;
1330 -//20110208ysk end
1331 - }
1332 - }
1333 - }
1334 - $chk_ord['name'] = 1;
1335 -//20110411ysk start
1336 - if($applyform == 'JP') {
1337 - $chk_ord['kana'] = (isset($_REQUEST['check']['kana'])) ? 1 : 0;
1338 - }
1339 -//20110411ysk end
1340 - if(!empty($cscs_meta)) {
1341 - foreach($cscs_meta as $key => $entry) {
1342 - if($entry['position'] == 'name_after') {
1343 - $name = $entry['name'];
1344 -//20110208ysk start
1345 - $cscs_key = 'cscs_'.$key;
1346 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1347 - $chk_ord[$cscs_key] = (isset($_REQUEST['check'][$cscs_key])) ? 1 : 0;
1348 -//20110208ysk end
1349 - }
1350 - }
1351 - }
1352 - $chk_ord['zip'] = (isset($_REQUEST['check']['zip'])) ? 1 : 0;
1353 -//20110411ysk start
1354 - $chk_ord['country'] = (isset($_REQUEST['check']['country'])) ? 1 : 0;
1355 -//20110411ysk end
1356 - $chk_ord['pref'] = (isset($_REQUEST['check']['pref'])) ? 1 : 0;
1357 - $chk_ord['address1'] = (isset($_REQUEST['check']['address1'])) ? 1 : 0;
1358 - $chk_ord['address2'] = (isset($_REQUEST['check']['address2'])) ? 1 : 0;
1359 - $chk_ord['address3'] = (isset($_REQUEST['check']['address3'])) ? 1 : 0;
1360 - $chk_ord['tel'] = (isset($_REQUEST['check']['tel'])) ? 1 : 0;
1361 - $chk_ord['fax'] = (isset($_REQUEST['check']['fax'])) ? 1 : 0;
1362 - if(!empty($cscs_meta)) {
1363 - foreach($cscs_meta as $key => $entry) {
1364 - if($entry['position'] == 'fax_after') {
1365 - $name = $entry['name'];
1366 -//20110208ysk start
1367 - $cscs_key = 'cscs_'.$key;
1368 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1369 - $chk_ord[$cscs_key] = (isset($_REQUEST['check'][$cscs_key])) ? 1 : 0;
1370 -//20110208ysk end
1371 - }
1372 - }
1373 - }
1374 - //--------------------------------------------------------------------------
1375 - if(!empty($csde_meta)) {
1376 - foreach($csde_meta as $key => $entry) {
1377 - if($entry['position'] == 'name_pre') {
1378 - $name = $entry['name'];
1379 -//20110208ysk start
1380 - $csde_key = 'csde_'.$key;
1381 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1382 - $chk_ord[$csde_key] = (isset($_REQUEST['check'][$csde_key])) ? 1 : 0;
1383 -//20110208ysk end
1384 - }
1385 - }
1386 - }
1387 - $chk_ord['delivery_name'] = (isset($_REQUEST['check']['delivery_name'])) ? 1 : 0;
1388 -//20110411ysk start
1389 - if($applyform == 'JP') {
1390 - $chk_ord['delivery_kana'] = (isset($_REQUEST['check']['delivery_kana'])) ? 1 : 0;
1391 - }
1392 -//20110411ysk end
1393 - if(!empty($csde_meta)) {
1394 - foreach($csde_meta as $key => $entry) {
1395 - if($entry['position'] == 'name_after') {
1396 - $name = $entry['name'];
1397 -//20110208ysk start
1398 - $csde_key = 'csde_'.$key;
1399 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1400 - $chk_ord[$csde_key] = (isset($_REQUEST['check'][$csde_key])) ? 1 : 0;
1401 -//20110208ysk end
1402 - }
1403 - }
1404 - }
1405 - $chk_ord['delivery_zip'] = (isset($_REQUEST['check']['delivery_zip'])) ? 1 : 0;
1406 -//20110411ysk start
1407 - $chk_ord['delivery_country'] = (isset($_REQUEST['check']['delivery_country'])) ? 1 : 0;
1408 -//20110411ysk end
1409 - $chk_ord['delivery_pref'] = (isset($_REQUEST['check']['delivery_pref'])) ? 1 : 0;
1410 - $chk_ord['delivery_address1'] = (isset($_REQUEST['check']['delivery_address1'])) ? 1 : 0;
1411 - $chk_ord['delivery_address2'] = (isset($_REQUEST['check']['delivery_address2'])) ? 1 : 0;
1412 - $chk_ord['delivery_address3'] = (isset($_REQUEST['check']['delivery_address3'])) ? 1 : 0;
1413 - $chk_ord['delivery_tel'] = (isset($_REQUEST['check']['delivery_tel'])) ? 1 : 0;
1414 - $chk_ord['delivery_fax'] = (isset($_REQUEST['check']['delivery_fax'])) ? 1 : 0;
1415 - if(!empty($csde_meta)) {
1416 - foreach($csde_meta as $key => $entry) {
1417 - if($entry['position'] == 'fax_after') {
1418 - $name = $entry['name'];
1419 -//20110208ysk start
1420 - $csde_key = 'csde_'.$key;
1421 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1422 - $chk_ord[$csde_key] = (isset($_REQUEST['check'][$csde_key])) ? 1 : 0;
1423 -//20110208ysk end
1424 - }
1425 - }
1426 - }
1427 - //--------------------------------------------------------------------------
1428 - $chk_ord['shipping_date'] = (isset($_REQUEST['check']['shipping_date'])) ? 1 : 0;
1429 - $chk_ord['peyment_method'] = (isset($_REQUEST['check']['peyment_method'])) ? 1 : 0;
1430 - $chk_ord['delivery_method'] = (isset($_REQUEST['check']['delivery_method'])) ? 1 : 0;
1431 -//20101208ysk start
1432 - $chk_ord['delivery_date'] = (isset($_REQUEST['check']['delivery_date'])) ? 1 : 0;
1433 -//20101208ysk end
1434 - $chk_ord['delivery_time'] = (isset($_REQUEST['check']['delivery_time'])) ? 1 : 0;
1435 - $chk_ord['delidue_date'] = (isset($_REQUEST['check']['delidue_date'])) ? 1 : 0;
1436 - $chk_ord['status'] = (isset($_REQUEST['check']['status'])) ? 1 : 0;
1437 - $chk_ord['total_amount'] = 1;
1438 - $chk_ord['usedpoint'] = (isset($_REQUEST['check']['usedpoint'])) ? 1 : 0;
1439 - $chk_ord['discount'] = 1;
1440 - $chk_ord['shipping_charge'] = 1;
1441 - $chk_ord['cod_fee'] = 1;
1442 - $chk_ord['tax'] = 1;
1443 - $chk_ord['note'] = (isset($_REQUEST['check']['note'])) ? 1 : 0;
1444 - if(!empty($csod_meta)) {
1445 - foreach($csod_meta as $key => $entry) {
1446 - $name = $entry['name'];
1447 -//20110208ysk start
1448 - $csod_key = 'csod_'.$key;
1449 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1450 - $chk_ord[$csod_key] = (isset($_REQUEST['check'][$csod_key])) ? 1 : 0;
1451 -//20110208ysk end
1452 - }
1453 - }
1454 - $usces_opt_order['chk_ord'] = apply_filters( 'usces_filter_chk_ord', $chk_ord );
1455 - update_option('usces_opt_order', $usces_opt_order);
1456 - //==========================================================================
1457 -
1458 - if(isset($_REQUEST['check']['status'])) {
1459 - //$usces_management_status = get_option('usces_management_status');
1460 - $usces_management_status = apply_filters( 'usces_filter_management_status', get_option('usces_management_status') );//0000530
1461 - $usces_management_status['new'] = __('new order', 'usces');
1462 - }
1463 -
1464 - $_REQUEST['searchIn'] = "searchIn";
1465 - $tableName = $wpdb->prefix."usces_order";
1466 - $arr_column = array(
1467 - __('ID', 'usces') => 'ID',
1468 - __('Order number', 'usces') => 'deco_id',
1469 - __('date', 'usces') => 'date',
1470 - __('membership number', 'usces') => 'mem_id',
1471 - __('name', 'usces') => 'name',
1472 - __('Region', 'usces') => 'pref',
1473 - __('shipping option', 'usces') => 'delivery_method',
1474 - __('Amount', 'usces') => 'total_price',
1475 - __('payment method', 'usces') => 'payment_name',
1476 - __('transfer statement', 'usces') => 'receipt_status',
1477 - __('Processing', 'usces') => 'order_status',
1478 - __('shpping date', 'usces') => 'order_modified');
1479 - $DT = new dataList($tableName, $arr_column);
1480 -//20101202ysk start
1481 - $DT->pageLimit = 'off';
1482 -//20101202ysk end
1483 - $res = $DT->MakeTable();
1484 - $rows = $DT->rows;
1485 -
1486 - //==========================================================================
1487 - $line = $table_h;
1488 - $line .= $tr_h;
1489 - $line .= $th_h1.__('ID', 'usces').$th_f;
1490 - $line .= $th_h.__('Order number', 'usces').$th_f;
1491 - $line .= $th_h.__('order date', 'usces').$th_f;
1492 - if(isset($_REQUEST['check']['mem_id'])) $line .= $th_h.__('membership number', 'usces').$th_f;
1493 - if(isset($_REQUEST['check']['email'])) $line .= $th_h.__('e-mail', 'usces').$th_f;
1494 - if(!empty($cscs_meta)) {
1495 - foreach($cscs_meta as $key => $entry) {
1496 - if($entry['position'] == 'name_pre') {
1497 - $name = $entry['name'];
1498 -//20110208ysk start
1499 - $cscs_key = 'cscs_'.$key;
1500 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1501 - if(isset($_REQUEST['check'][$cscs_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1502 -//20110208ysk end
1503 - }
1504 - }
1505 - }
1506 - $line .= $th_h.__('name', 'usces').$th_f;
1507 -//20110411ysk start
1508 - if($applyform == 'JP') {
1509 - if(isset($_REQUEST['check']['kana'])) $line .= $th_h.__('furigana', 'usces').$th_f;
1510 - }
1511 -//20110411ysk end
1512 - if(!empty($cscs_meta)) {
1513 - foreach($cscs_meta as $key => $entry) {
1514 - if($entry['position'] == 'name_after') {
1515 - $name = $entry['name'];
1516 -//20110208ysk start
1517 - $cscs_key = 'cscs_'.$key;
1518 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1519 - if(isset($_REQUEST['check'][$cscs_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1520 -//20110208ysk end
1521 - }
1522 - }
1523 - }
1524 -//20110411ysk start
1525 - switch($applyform) {
1526 - case 'JP':
1527 - if(isset($_REQUEST['check']['zip'])) $line .= $th_h.__('Zip/Postal Code', 'usces').$th_f;
1528 - if(isset($_REQUEST['check']['country'])) $line .= $th_h.__('Country', 'usces').$th_f;
1529 - if(isset($_REQUEST['check']['pref'])) $line .= $th_h.__('Province', 'usces').$th_f;
1530 - if(isset($_REQUEST['check']['address1'])) $line .= $th_h.__('city', 'usces').$th_f;
1531 - if(isset($_REQUEST['check']['address2'])) $line .= $th_h.__('numbers', 'usces').$th_f;
1532 - if(isset($_REQUEST['check']['address3'])) $line .= $th_h.__('building name', 'usces').$th_f;
1533 - if(isset($_REQUEST['check']['tel'])) $line .= $th_h.__('Phone number', 'usces').$th_f;
1534 - if(isset($_REQUEST['check']['fax'])) $line .= $th_h.__('FAX number', 'usces').$th_f;
1535 - break;
1536 - case 'US':
1537 - default:
1538 - if(isset($_REQUEST['check']['address2'])) $line .= $th_h.__('Address Line1', 'usces').$th_f;
1539 - if(isset($_REQUEST['check']['address3'])) $line .= $th_h.__('Address Line2', 'usces').$th_f;
1540 - if(isset($_REQUEST['check']['address1'])) $line .= $th_h.__('city', 'usces').$th_f;
1541 - if(isset($_REQUEST['check']['pref'])) $line .= $th_h.__('State', 'usces').$th_f;
1542 - if(isset($_REQUEST['check']['country'])) $line .= $th_h.__('Country', 'usces').$th_f;
1543 - if(isset($_REQUEST['check']['zip'])) $line .= $th_h.__('Zip', 'usces').$th_f;
1544 - if(isset($_REQUEST['check']['tel'])) $line .= $th_h.__('Phone number', 'usces').$th_f;
1545 - if(isset($_REQUEST['check']['fax'])) $line .= $th_h.__('FAX number', 'usces').$th_f;
1546 - break;
1547 - }
1548 -//20110411ysk end
1549 - if(!empty($cscs_meta)) {
1550 - foreach($cscs_meta as $key => $entry) {
1551 - if($entry['position'] == 'fax_after') {
1552 - $name = $entry['name'];
1553 -//20110208ysk start
1554 - $cscs_key = 'cscs_'.$key;
1555 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1556 - if(isset($_REQUEST['check'][$cscs_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1557 -//20110208ysk end
1558 - }
1559 - }
1560 - }
1561 - $line .= apply_filters( 'usces_filter_chk_ord_label_customer', NULL, $usces_opt_order, $rows );
1562 -
1563 - //--------------------------------------------------------------------------
1564 - if(!empty($csde_meta)) {
1565 - foreach($csde_meta as $key => $entry) {
1566 - if($entry['position'] == 'name_pre') {
1567 - $name = $entry['name'];
1568 -//20110208ysk start
1569 - $csde_key = 'csde_'.$key;
1570 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1571 - if(isset($_REQUEST['check'][$csde_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1572 -//20110208ysk end
1573 - }
1574 - }
1575 - }
1576 - if(isset($_REQUEST['check']['delivery_name'])) $line .= $th_h.__('Shipping Name', 'usces').$th_f;
1577 -//20110411ysk start
1578 - if($applyform == 'JP') {
1579 - if(isset($_REQUEST['check']['delivery_kana'])) $line .= $th_h.__('Shipping Furigana', 'usces').$th_f;
1580 - }
1581 -//20110411ysk end
1582 - if(!empty($csde_meta)) {
1583 - foreach($csde_meta as $key => $entry) {
1584 - if($entry['position'] == 'name_after') {
1585 - $name = $entry['name'];
1586 -//20110208ysk start
1587 - $csde_key = 'csde_'.$key;
1588 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1589 - if(isset($_REQUEST['check'][$csde_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1590 -//20110208ysk end
1591 - }
1592 - }
1593 - }
1594 -//20110411ysk start
1595 - switch($applyform) {
1596 - case 'JP':
1597 - if(isset($_REQUEST['check']['delivery_zip'])) $line .= $th_h.__('Shipping Zip', 'usces').$th_f;
1598 - if(isset($_REQUEST['check']['delivery_country'])) $line .= $th_h.__('配送先国', 'usces').$th_f;
1599 - if(isset($_REQUEST['check']['delivery_pref'])) $line .= $th_h.__('Shipping State', 'usces').$th_f;
1600 - if(isset($_REQUEST['check']['delivery_address1'])) $line .= $th_h.__('Shipping City', 'usces').$th_f;
1601 - if(isset($_REQUEST['check']['delivery_address2'])) $line .= $th_h.__('Shipping Address1', 'usces').$th_f;
1602 - if(isset($_REQUEST['check']['delivery_address3'])) $line .= $th_h.__('Shipping Address2', 'usces').$th_f;
1603 - if(isset($_REQUEST['check']['delivery_tel'])) $line .= $th_h.__('Shipping Phone', 'usces').$th_f;
1604 - if(isset($_REQUEST['check']['delivery_fax'])) $line .= $th_h.__('Shipping FAX', 'usces').$th_f;
1605 - break;
1606 - case 'US':
1607 - default:
1608 - if(isset($_REQUEST['check']['delivery_address2'])) $line .= $th_h.__('Shipping Address1', 'usces').$th_f;
1609 - if(isset($_REQUEST['check']['delivery_address3'])) $line .= $th_h.__('Shipping Address2', 'usces').$th_f;
1610 - if(isset($_REQUEST['check']['delivery_address1'])) $line .= $th_h.__('Shipping City', 'usces').$th_f;
1611 - if(isset($_REQUEST['check']['delivery_pref'])) $line .= $th_h.__('Shipping State', 'usces').$th_f;
1612 - if(isset($_REQUEST['check']['delivery_country'])) $line .= $th_h.__('配送先国', 'usces').$th_f;
1613 - if(isset($_REQUEST['check']['delivery_zip'])) $line .= $th_h.__('Shipping Zip', 'usces').$th_f;
1614 - if(isset($_REQUEST['check']['delivery_tel'])) $line .= $th_h.__('Shipping Phone', 'usces').$th_f;
1615 - if(isset($_REQUEST['check']['delivery_fax'])) $line .= $th_h.__('Shipping FAX', 'usces').$th_f;
1616 - break;
1617 - }
1618 -//20110411ysk end
1619 - if(!empty($csde_meta)) {
1620 - foreach($csde_meta as $key => $entry) {
1621 - if($entry['position'] == 'fax_after') {
1622 - $name = $entry['name'];
1623 -//20110208ysk start
1624 - $csde_key = 'csde_'.$key;
1625 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1626 - if(isset($_REQUEST['check'][$csde_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1627 -//20110208ysk end
1628 - }
1629 - }
1630 - }
1631 - $line .= apply_filters( 'usces_filter_chk_ord_label_delivery', NULL, $usces_opt_order, $rows );
1632 - //--------------------------------------------------------------------------
1633 - if(isset($_REQUEST['check']['shipping_date'])) $line .= $th_h.__('shpping date', 'usces').$th_f;
1634 - if(isset($_REQUEST['check']['peyment_method'])) $line .= $th_h.__('payment method', 'usces').$th_f;
1635 - if(isset($_REQUEST['check']['delivery_method'])) $line .= $th_h.__('shipping option', 'usces').$th_f;
1636 -//20101208ysk start
1637 - if(isset($_REQUEST['check']['delivery_date'])) $line .= $th_h.__('Delivery date', 'usces').$th_f;
1638 -//20101208ysk end
1639 - if(isset($_REQUEST['check']['delivery_time'])) $line .= $th_h.__('delivery time', 'usces').$th_f;
1640 - if(isset($_REQUEST['check']['delidue_date'])) $line .= $th_h.__('Shipping date', 'usces').$th_f;
1641 - if(isset($_REQUEST['check']['status'])) $line .= $th_h.__('Status', 'usces').$th_f;
1642 - $line .= $th_h.__('Total Amount', 'usces').$th_f;
1643 - if(isset($_REQUEST['check']['usedpoint'])) $line .= $th_h.__('Used points', 'usces').$th_f;
1644 - $line .= $th_h.__('Disnount', 'usces').$th_f;
1645 - $line .= $th_h.__('Shipping', 'usces').$th_f;
1646 - $line .= $th_h.apply_filters('usces_filter_cod_label', __('COD fee', 'usces')).$th_f;
1647 - $line .= $th_h.__('consumption tax', 'usces').$th_f;
1648 - if(isset($_REQUEST['check']['note'])) $line .= $th_h.__('Notes', 'usces').$th_f;
1649 - if(!empty($csod_meta)) {
1650 - foreach($csod_meta as $key => $entry) {
1651 - $name = $entry['name'];
1652 -//20110208ysk start
1653 - $csod_key = 'csod_'.$key;
1654 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1655 - if(isset($_REQUEST['check'][$csod_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1656 -//20110208ysk end
1657 - }
1658 - }
1659 - $line .= apply_filters( 'usces_filter_chk_ord_label_order', NULL, $usces_opt_order, $rows );
1660 - $line .= $tr_f.$lf;
1661 - //==========================================================================
1662 - foreach((array)$rows as $array) {
1663 - $order_id = $array['ID'];
1664 - $query = $wpdb->prepare("SELECT * FROM $tableName WHERE ID = %d", $order_id);
1665 - $data = $wpdb->get_row( $query, ARRAY_A );
1666 - //$deli = stripslashes_deep(unserialize($data['order_delivery']));
1667 - $deli = unserialize($data['order_delivery']);
1668 - //if(!empty($data)) {
1669 - // $data = stripslashes_deep($data);
1670 - //}
1671 -
1672 - $line .= $tr_h;
1673 - $line .= $td_h1.$order_id.$td_f;
1674 - $line .= $td_h.usces_get_deco_order_id( $order_id ).$td_f;
1675 - $line .= $td_h.$data['order_date'].$td_f;
1676 - if(isset($_REQUEST['check']['mem_id'])) $line .= $td_h.$data['mem_id'].$td_f;
1677 - if(isset($_REQUEST['check']['email'])) $line .= $td_h.usces_entity_decode($data['order_email'], $ext).$td_f;
1678 - if(!empty($cscs_meta)) {
1679 - foreach($cscs_meta as $key => $entry) {
1680 - if($entry['position'] == 'name_pre') {
1681 - $name = $entry['name'];
1682 - $cscs_key = 'cscs_'.$key;
1683 -//20110208ysk start
1684 - //if(isset($_REQUEST['check'][$name])) {
1685 - if(isset($_REQUEST['check'][$cscs_key])) {
1686 -//20110208ysk end
1687 - $value = maybe_unserialize($usces->get_order_meta_value($cscs_key, $order_id));
1688 - if(empty($value)) {
1689 - $value = '';
1690 - } elseif(is_array($value)) {
1691 - $concatval = '';
1692 - $c = '';
1693 - foreach($value as $v) {
1694 - $concatval .= $c.$v;
1695 - $c = ' ';
1696 - }
1697 - $value = $concatval;
1698 - }
1699 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
1700 - }
1701 - }
1702 - }
1703 - }
1704 -//20110411ysk start
1705 - switch($applyform) {
1706 - case 'JP':
1707 - $line .= $td_h.usces_entity_decode($data['order_name1'].' '.$data['order_name2'], $ext).$td_f;
1708 - if(isset($_REQUEST['check']['kana'])) $line .= $td_h.usces_entity_decode($data['order_name3'].' '.$data['order_name4'], $ext).$td_f;
1709 - break;
1710 - case 'US':
1711 - default:
1712 - $line .= $td_h.usces_entity_decode($data['order_name2'].' '.$data['order_name1'], $ext).$td_f;
1713 - break;
1714 - }
1715 -//20110411ysk end
1716 - if(!empty($cscs_meta)) {
1717 - foreach($cscs_meta as $key => $entry) {
1718 - if($entry['position'] == 'name_after') {
1719 - $name = $entry['name'];
1720 - $cscs_key = 'cscs_'.$key;
1721 -//20110208ysk start
1722 - //if(isset($_REQUEST['check'][$name])) {
1723 - if(isset($_REQUEST['check'][$cscs_key])) {
1724 -//20110208ysk end
1725 - $value = maybe_unserialize($usces->get_order_meta_value($cscs_key, $order_id));
1726 - if(empty($value)) {
1727 - $value = '';
1728 - } elseif(is_array($value)) {
1729 - $concatval = '';
1730 - $c = '';
1731 - foreach($value as $v) {
1732 - $concatval .= $c.$v;
1733 - $c = ' ';
1734 - }
1735 - $value = $concatval;
1736 - }
1737 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
1738 - }
1739 - }
1740 - }
1741 - }
1742 -//20110411ysk start
1743 - $address_info = '';
1744 - switch($applyform) {
1745 - case 'JP':
1746 - if(isset($_REQUEST['check']['zip'])) $address_info .= $td_h.usces_entity_decode($data['order_zip'], $ext).$td_f;
1747 - if(isset($_REQUEST['check']['country'])) $address_info .= $td_h.$usces_settings['country'][$usces->get_order_meta_value('customer_country', $order_id)].$td_f;
1748 - if(isset($_REQUEST['check']['pref'])) $address_info .= $td_h.usces_entity_decode($data['order_pref'], $ext).$td_f;
1749 - if(isset($_REQUEST['check']['address1'])) $address_info .= $td_h.usces_entity_decode($data['order_address1'], $ext).$td_f;
1750 - if(isset($_REQUEST['check']['address2'])) $address_info .= $td_h.usces_entity_decode($data['order_address2'], $ext).$td_f;
1751 - if(isset($_REQUEST['check']['address3'])) $address_info .= $td_h.usces_entity_decode($data['order_address3'], $ext).$td_f;
1752 - if(isset($_REQUEST['check']['tel'])) $address_info .= $td_h.usces_entity_decode($data['order_tel'], $ext).$td_f;
1753 - if(isset($_REQUEST['check']['fax'])) $address_info .= $td_h.usces_entity_decode($data['order_fax'], $ext).$td_f;
1754 - break;
1755 - case 'US':
1756 - default:
1757 - if(isset($_REQUEST['check']['address2'])) $address_info .= $td_h.usces_entity_decode($data['order_address2'], $ext).$td_f;
1758 - if(isset($_REQUEST['check']['address3'])) $address_info .= $td_h.usces_entity_decode($data['order_address3'], $ext).$td_f;
1759 - if(isset($_REQUEST['check']['address1'])) $address_info .= $td_h.usces_entity_decode($data['order_address1'], $ext).$td_f;
1760 - if(isset($_REQUEST['check']['pref'])) $address_info .= $td_h.usces_entity_decode($data['order_pref'], $ext).$td_f;
1761 - if(isset($_REQUEST['check']['country'])) $address_info .= $td_h.$usces_settings['country'][$usces->get_order_meta_value('customer_country', $order_id)].$td_f;
1762 - if(isset($_REQUEST['check']['zip'])) $address_info .= $td_h.usces_entity_decode($data['order_zip'], $ext).$td_f;
1763 - if(isset($_REQUEST['check']['tel'])) $address_info .= $td_h.usces_entity_decode($data['order_tel'], $ext).$td_f;
1764 - if(isset($_REQUEST['check']['fax'])) $address_info .= $td_h.usces_entity_decode($data['order_fax'], $ext).$td_f;
1765 - break;
1766 - }
1767 - $address_info_args = compact('td_h', 'td_f', 'ext', 'order_id', 'applyform' );
1768 - $line .= apply_filters( 'usces_filter_ord_csv_address_info', $address_info, $data, $address_info_args);
1769 -//20110411ysk end
1770 - if(!empty($cscs_meta)) {
1771 - foreach($cscs_meta as $key => $entry) {
1772 - if($entry['position'] == 'fax_after') {
1773 - $name = $entry['name'];
1774 - $cscs_key = 'cscs_'.$key;
1775 -//20110208ysk start
1776 - //if(isset($_REQUEST['check'][$name])) {
1777 - if(isset($_REQUEST['check'][$cscs_key])) {
1778 -//20110208ysk end
1779 - $value = maybe_unserialize($usces->get_order_meta_value($cscs_key, $order_id));
1780 - if(empty($value)) {
1781 - $value = '';
1782 - } elseif(is_array($value)) {
1783 - $concatval = '';
1784 - $c = '';
1785 - foreach($value as $v) {
1786 - $concatval .= $c.$v;
1787 - $c = ' ';
1788 - }
1789 - $value = $concatval;
1790 - }
1791 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
1792 - }
1793 - }
1794 - }
1795 - }
1796 - $line .= apply_filters( 'usces_filter_chk_ord_data_customer', NULL, $usces_opt_order, $order_id, $entry );
1797 - //----------------------------------------------------------------------
1798 - if(!empty($csde_meta)) {
1799 - foreach($csde_meta as $key => $entry) {
1800 - if($entry['position'] == 'name_pre') {
1801 - $name = $entry['name'];
1802 - $csde_key = 'csde_'.$key;
1803 -//20110208ysk start
1804 - //if(isset($_REQUEST['check'][$name])) {
1805 - if(isset($_REQUEST['check'][$csde_key])) {
1806 -//20110208ysk end
1807 - $value = maybe_unserialize($usces->get_order_meta_value($csde_key, $order_id));
1808 - if(empty($value)) {
1809 - $value = '';
1810 - } elseif(is_array($value)) {
1811 - $concatval = '';
1812 - $c = '';
1813 - foreach($value as $v) {
1814 - $concatval .= $c.$v;
1815 - $c = ' ';
1816 - }
1817 - $value = $concatval;
1818 - }
1819 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
1820 - }
1821 - }
1822 - }
1823 - }
1824 -//20110411ysk start
1825 - switch($applyform) {
1826 - case 'JP':
1827 - if(isset($_REQUEST['check']['delivery_name'])) $line .= $td_h.usces_entity_decode($deli['name1'].' '.$deli['name2'], $ext).$td_f;
1828 - if(isset($_REQUEST['check']['delivery_kana'])) $line .= $td_h.usces_entity_decode($deli['name3'].' '.$deli['name4'], $ext).$td_f;
1829 - break;
1830 - case 'US':
1831 - default:
1832 - if(isset($_REQUEST['check']['delivery_name'])) $line .= $td_h.usces_entity_decode($deli['name2'].' '.$deli['name1'], $ext).$td_f;
1833 - break;
1834 - }
1835 -//20110411ysk end
1836 - if(!empty($csde_meta)) {
1837 - foreach($csde_meta as $key => $entry) {
1838 - if($entry['position'] == 'name_after') {
1839 - $name = $entry['name']."</td>";
1840 - $csde_key = 'csde_'.$key;
1841 -//20110208ysk start
1842 - //if(isset($_REQUEST['check'][$name])) {
1843 - if(isset($_REQUEST['check'][$csde_key])) {
1844 -//20110208ysk end
1845 - $value = maybe_unserialize($usces->get_order_meta_value($csde_key, $order_id));
1846 - if(empty($value)) {
1847 - $value = '';
1848 - } elseif(is_array($value)) {
1849 - $concatval = '';
1850 - $c = '';
1851 - foreach($value as $v) {
1852 - $concatval .= $c.$v;
1853 - $c = ' ';
1854 - }
1855 - $value = $concatval;
1856 - }
1857 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
1858 - }
1859 - }
1860 - }
1861 - }
1862 -//20110411ysk start
1863 - switch($applyform) {
1864 - case 'JP':
1865 - if(isset($_REQUEST['check']['delivery_zip'])) $line .= $td_h.usces_entity_decode($deli['zipcode'], $ext).$td_f;
1866 - if(isset($_REQUEST['check']['delivery_country'])) $line .= $td_h.$usces_settings['country'][$deli['country']].$td_f;
1867 - if(isset($_REQUEST['check']['delivery_pref'])) $line .= $td_h.usces_entity_decode($deli['pref'], $ext).$td_f;
1868 - if(isset($_REQUEST['check']['delivery_address1'])) $line .= $td_h.usces_entity_decode($deli['address1'], $ext).$td_f;
1869 - if(isset($_REQUEST['check']['delivery_address2'])) $line .= $td_h.usces_entity_decode($deli['address2'], $ext).$td_f;
1870 - if(isset($_REQUEST['check']['delivery_address3'])) $line .= $td_h.usces_entity_decode($deli['address3'], $ext).$td_f;
1871 - if(isset($_REQUEST['check']['delivery_tel'])) $line .= $td_h.usces_entity_decode($deli['tel'], $ext).$td_f;
1872 - if(isset($_REQUEST['check']['delivery_fax'])) $line .= $td_h.usces_entity_decode($deli['fax'], $ext).$td_f;
1873 - break;
1874 - case 'US':
1875 - default:
1876 - if(isset($_REQUEST['check']['delivery_address2'])) $line .= $td_h.usces_entity_decode($deli['address2'], $ext).$td_f;
1877 - if(isset($_REQUEST['check']['delivery_address3'])) $line .= $td_h.usces_entity_decode($deli['address3'], $ext).$td_f;
1878 - if(isset($_REQUEST['check']['delivery_address1'])) $line .= $td_h.usces_entity_decode($deli['address1'], $ext).$td_f;
1879 - if(isset($_REQUEST['check']['delivery_pref'])) $line .= $td_h.usces_entity_decode($deli['pref'], $ext).$td_f;
1880 - if(isset($_REQUEST['check']['delivery_country'])) $line .= $td_h.$usces_settings['country'][$deli['country']].$td_f;
1881 - if(isset($_REQUEST['check']['delivery_zip'])) $line .= $td_h.usces_entity_decode($deli['zipcode'], $ext).$td_f;
1882 - if(isset($_REQUEST['check']['delivery_tel'])) $line .= $td_h.usces_entity_decode($deli['tel'], $ext).$td_f;
1883 - if(isset($_REQUEST['check']['delivery_fax'])) $line .= $td_h.usces_entity_decode($deli['fax'], $ext).$td_f;
1884 - break;
1885 - }
1886 -//20110411ysk end
1887 - if(!empty($csde_meta)) {
1888 - foreach($csde_meta as $key => $entry) {
1889 - if($entry['position'] == 'fax_after') {
1890 - $name = $entry['name'];
1891 - $csde_key = 'csde_'.$key;
1892 -//20110208ysk start
1893 - //if(isset($_REQUEST['check'][$name])) {
1894 - if(isset($_REQUEST['check'][$csde_key])) {
1895 -//20110208ysk end
1896 - $value = maybe_unserialize($usces->get_order_meta_value($csde_key, $order_id));
1897 - if(empty($value)) {
1898 - $value = '';
1899 - } elseif(is_array($value)) {
1900 - $concatval = '';
1901 - $c = '';
1902 - foreach($value as $v) {
1903 - $concatval .= $c.$v;
1904 - $c = ' ';
1905 - }
1906 - $value = $concatval;
1907 - }
1908 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
1909 - }
1910 - }
1911 - }
1912 - }
1913 - $line .= apply_filters( 'usces_filter_chk_ord_data_delivery', NULL, $usces_opt_order, $order_id, $deli );
1914 - //----------------------------------------------------------------------
1915 - if(isset($_REQUEST['check']['shipping_date'])) $line .= $td_h.$data['order_modified'].$td_f;
1916 - if(isset($_REQUEST['check']['peyment_method'])) $line .= $td_h.$data['order_payment_name'].$td_f;
1917 - if(isset($_REQUEST['check']['delivery_method'])) {
1918 - $delivery_method = '';
1919 - if(strtoupper($data['order_delivery_method']) == '#NONE#') {
1920 - $delivery_method = __('No preference', 'usces');
1921 - } else {
1922 - foreach((array)$usces->options['delivery_method'] as $dkey => $delivery) {
1923 - if($delivery['id'] == $data['order_delivery_method']) {
1924 - $delivery_method = $delivery['name'];
1925 - break;
1926 - }
1927 - }
1928 - }
1929 - $line .= $td_h.$delivery_method.$td_f;
1930 - }
1931 -//20101208ysk start
1932 - if(isset($_REQUEST['check']['delivery_date'])) $line .= $td_h.$data['order_delivery_date'].$td_f;
1933 -//20101208ysk end
1934 - if(isset($_REQUEST['check']['delivery_time'])) $line .= $td_h.$data['order_delivery_time'].$td_f;
1935 - if(isset($_REQUEST['check']['delidue_date'])) {
1936 - $order_delidue_date = (strtoupper($data['order_delidue_date']) == '#NONE#') ? '' : $data['order_delidue_date'];
1937 - $line .= $td_h.$order_delidue_date.$td_f;
1938 - }
1939 - if(isset($_REQUEST['check']['status'])) {
1940 - $order_status = explode(',', $data['order_status']);
1941 - $status = '';
1942 - foreach( (array)$order_status as $os) {
1943 - if( isset($usces_management_status[$os]) )
1944 - $status .= $usces_management_status[$os].$sp;
1945 - }
1946 - $line .= $td_h.trim($status, $sp).$td_f;
1947 - }
1948 - $line .= $td_h.usces_crform($array['total_price'], false, false, 'return', false).$td_f;
1949 - if(isset($_REQUEST['check']['usedpoint'])) $line .= $td_h.$data['order_usedpoint'].$td_f;
1950 - $line .= $td_h.$data['order_discount'].$td_f;
1951 - $line .= $td_h.$data['order_shipping_charge'].$td_f;
1952 - $line .= $td_h.$data['order_cod_fee'].$td_f;
1953 - $line .= $td_h.$data['order_tax'].$td_f;
1954 - if(isset($_REQUEST['check']['note'])) $line .= $td_h.usces_entity_decode($data['order_note'], $ext).$td_f;
1955 - if(!empty($csod_meta)) {
1956 - foreach($csod_meta as $key => $entry) {
1957 - $name = $entry['name'];
1958 - $csod_key = 'csod_'.$key;
1959 -//20110208ysk start
1960 - //if(isset($_REQUEST['check'][$name])) {
1961 - if(isset($_REQUEST['check'][$csod_key])) {
1962 -//20110208ysk end
1963 - $value = maybe_unserialize($usces->get_order_meta_value($csod_key, $order_id));
1964 - if(empty($value)) {
1965 - $value = '';
1966 - } elseif(is_array($value)) {
1967 - $concatval = '';
1968 - $c = '';
1969 - foreach($value as $v) {
1970 - $concatval .= $c.$v;
1971 - $c = ' ';
1972 - }
1973 - $value = $concatval;
1974 - }
1975 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
1976 - }
1977 - }
1978 - }
1979 - $line .= apply_filters( 'usces_filter_chk_ord_data_order', NULL, $usces_opt_order, $order_id, $data );
1980 - $line .= $tr_f.$lf;
1981 - }
1982 - $line .= $table_f.$lf;
1983 - //==========================================================================
1984 -
1985 - if($ext == 'xls') {
1986 - header("Content-Type: application/vnd.ms-excel; charset=Shift-JIS");
1987 - } elseif($ext == 'csv') {
1988 - header("Content-Type: application/octet-stream");
1989 - }
1990 - header("Content-Disposition: attachment; filename=usces_order_list.".$ext);
1991 - mb_http_output('pass');
1992 - print(mb_convert_encoding($line, "SJIS-win", "UTF-8"));
1993 - exit();
1994 -}
1995 -
1996 -function usces_entity_decode($str, $ftype) {
1997 - $pos = strpos($str, '&');
1998 - if($pos !== false)
1999 - $str = htmlspecialchars_decode($str);
2000 -
2001 - if($ftype == 'csv')
2002 - $str = str_replace('"', '""', $str);
2003 -
2004 - return $str;
2005 -}
2006 -
2007 -function usces_is_entity($entity){
2008 - $temp = substr($entity, 0, 1);
2009 - $temp .= substr($entity, -1, 1);
2010 - if ($temp != '&;')
2011 - return false;
2012 - else
2013 - return true;
2014 -}
2015 -
2016 -function usces_p( $var ){
2017 - echo '<pre>' . print_r($var, true) . '</pre>';
2018 -}
2019 -
2020 -function usces_get_key( $digit ){
2021 - $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
2022 - $max = strlen($chars) - 1;
2023 - $str = '';
2024 - for($i=0; $i<$digit; $i++){
2025 - $str .= $chars[mt_rand(0, $max)];
2026 - }
2027 - return $str;
2028 -}
2029 -?>
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 +}