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 -2249 1.4.02.12.4 View file →
@@ -1,2249 +1,1835 @@
1 -<?php
2 -// Utility.php
3 -
4 -function usces_upgrade_14(){
5 - global $usces;
6 - $upgrade = (int)get_option('usces_upgrade2');
7 - if( $upgrade & USCES_UP14 )
8 - return false;
9 -
10 - global $wpdb;
11 - $rets = array();
12 -
13 - $options = get_option('usces');
14 - if(empty($options['tax_rate'])){
15 - $options['tax_mode'] = 'include';
16 - }else{
17 - $options['tax_mode'] = 'exclude';
18 - }
19 - $options['tax_target'] = 'all';
20 - update_option('usces', $options);
21 -
22 -
23 -
24 - $order_table = $wpdb->prefix . "usces_order";
25 - $cart_table = $wpdb->prefix . "usces_ordercart";
26 - $cart_meta_table = $wpdb->prefix . "usces_ordercart_meta";
27 -
28 - $query = "SELECT ID, order_cart, order_condition FROM $order_table";
29 - $results = $wpdb->get_results( $query );
30 - if( $results ){
31 - foreach( $results as $order ){
32 - $condition = maybe_unserialize($order->order_condition);
33 - if( !isset($condition['tax_mode']) ){
34 - $condition['tax_mode'] = $options['tax_mode'];
35 - }
36 - if( !isset($condition['tax_rate']) ){
37 - $condition['tax_rate'] = (int)$options['tax_rate'];
38 - }
39 - if( !isset($condition['tax_target']) ){
40 - $condition['tax_target'] = $options['tax_target'];
41 - }
42 -
43 -
44 - $cart = unserialize($order->order_cart);
45 - foreach( (array)$cart as $row_index => $value ){
46 - $item_code = get_post_meta( $value['post_id'], '_itemCode', true);
47 - $item_name = get_post_meta( $value['post_id'], '_itemName', true);
48 - $skus = $usces->get_skus($value['post_id'], 'code');
49 - $sku_code = urldecode($value['sku']);
50 - $sku_encoded = $value['sku'];
51 - $sku = isset($skus[$sku_code]) ? $skus[$sku_code] : array('name'=>'notfound', 'cprice'=>0, 'unit'=>'');
52 - if( empty($condition['tax_rate']) ){
53 - $tax = 0;
54 -
55 - }else{
56 - $tax = ($value['price'] * $value['quantity']) * $condition['tax_rate'] / 100;
57 - $cr = $usces->options['system']['currency'];
58 - $decimal = $usces_settings['currency'][$cr][1];
59 - $decipad = (int)str_pad( '1', $decimal+1, '0', STR_PAD_RIGHT );
60 - switch( $options['tax_method'] ){
61 - case 'cutting':
62 - $tax = floor($tax*$decipad)/$decipad;
63 - break;
64 - case 'bring':
65 - $tax = ceil($tax*$decipad)/$decipad;
66 - break;
67 - case 'rounding':
68 - if( 0 < $decimal ){
69 - $tax = round($tax, (int)$decimal);
70 - }else{
71 - $tax = round($tax);
72 - }
73 - break;
74 - }
75 - }
76 - $query = $wpdb->prepare("INSERT INTO $cart_table
77 - (
78 - order_id, group_id, row_index,
79 - post_id, item_code, item_name,
80 - sku_code, sku_name, cprice, price, quantity, unit,
81 - tax, destination_id, cart_serial
82 - ) VALUES (
83 - %d, %d, %d,
84 - %d, %s, %s,
85 - %s, %s, %f, %f, %d, %s,
86 - %f, %d, %s
87 - )",
88 - $order->ID, 0, $row_index,
89 - $value['post_id'], $item_code, $item_name,
90 - $sku_code, $sku['name'], $sku['cprice'], $value['price'], $value['quantity'], $sku['unit'],
91 - $tax, NULL, $value['serial']
92 - );
93 - $wpdb->query($query);
94 -
95 - $cart_id = $wpdb->insert_id ;
96 - if( $cart_id ){
97 - if($value['options']){
98 - foreach((array)$value['options'] as $okey => $ovalue){
99 - $okey = urldecode($okey);
100 - if( is_array($ovalue) ){
101 - $ovalue = serialize($ovalue);
102 - }else{
103 - $ovalue = urldecode($ovalue);
104 - }
105 - $oquery = $wpdb->prepare("INSERT INTO $cart_meta_table
106 - (
107 - cart_id, meta_type, meta_key, meta_value
108 - ) VALUES (
109 - %d, 'option', %s, %s
110 - )",
111 - $cart_id, $okey, $ovalue
112 - );
113 - $wpdb->query($oquery);
114 - }
115 - }
116 - if( $value['advance'] ) {
117 - foreach( (array)$value['advance'] as $akey => $avalue ) {
118 - $advance = maybe_unserialize( $avalue );
119 - if( is_array($advance) ) {
120 - $post_id = $value['post_id'];
121 - if( is_array( $advance[$post_id][$sku_encoded] ) ) {
122 - $akeys = array_keys( $advance[$post_id][$sku_encoded] );
123 - foreach( (array)$akeys as $akey ) {
124 - $avalue = serialize( $advance[$post_id][$sku_encoded][$akey] );
125 - $aquery = $wpdb->prepare("INSERT INTO $cart_meta_table
126 - (
127 - cart_id, meta_type, meta_key, meta_value
128 - ) VALUES (
129 - %d, 'advance', %s, %s
130 - )",
131 - $cart_id, $akey, $avalue
132 - );
133 - $wpdb->query( $aquery );
134 - }
135 - } else {
136 - $akeys = array_keys( $advance );
137 - $akey = ( empty($akeys[0]) ) ? 'advance' : $akeys[0];
138 - $avalue = serialize( $advance );
139 - $aquery = $wpdb->prepare("INSERT INTO $cart_meta_table
140 - (
141 - cart_id, meta_type, meta_key, meta_value
142 - ) VALUES (
143 - %d, 'advance', %s, %s
144 - )",
145 - $cart_id, $akey, $avalue
146 - );
147 - $wpdb->query( $aquery );
148 - }
149 - } else {
150 - $avalue = urldecode( $avalue );
151 - $aquery = $wpdb->prepare("INSERT INTO $cart_meta_table
152 - (
153 - cart_id, meta_type, meta_key, meta_value
154 - ) VALUES (
155 - %d, 'advance', 'advance', %s
156 - )",
157 - $cart_id, $avalue
158 - );
159 - $wpdb->query( $aquery );
160 - }
161 - }
162 - }
163 - }
164 - }
165 -
166 - $upquery = $wpdb->prepare("UPDATE $order_table SET order_condition = %s WHERE ID = %d",
167 - serialize($condition), $order->ID
168 - );
169 - $wpdb->query($upquery);
170 - }
171 - }
172 - usces_log('USCES_UP14 : Completed', 'db');
173 - $upgrade += USCES_UP14;
174 - update_option('usces_upgrade2', $upgrade);
175 -}
176 -
177 -function usces_upgrade_07(){
178 - $upgrade = (int)get_option('usces_upgrade');
179 - if( $upgrade & USCES_UP07 ) return false;
180 -
181 - global $wpdb;
182 - $rets = array();
183 -
184 - $tableName = $wpdb->prefix . "postmeta";
185 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'iopt_', '_iopt_') WHERE meta_key LIKE 'iopt_%'";
186 - if( $wpdb->query( $mquery ) )
187 - $rets[] = 1;
188 -
189 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'isku_', '_isku_') WHERE meta_key LIKE 'isku_%'";
190 - if( $wpdb->query( $mquery ) )
191 - $rets[] = 1;
192 -
193 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemCode', '_itemCode') WHERE meta_key LIKE 'itemCode'";
194 - if( $wpdb->query( $mquery ) )
195 - $rets[] = 1;
196 -
197 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemName', '_itemName') WHERE meta_key LIKE 'itemName'";
198 - if( $wpdb->query( $mquery ) )
199 - $rets[] = 1;
200 -
201 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemRestriction', '_itemRestriction') WHERE meta_key LIKE 'itemRestriction'";
202 - if( $wpdb->query( $mquery ) )
203 - $rets[] = 1;
204 -
205 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemPointrate', '_itemPointrate') WHERE meta_key LIKE 'itemPointrate'";
206 - if( $wpdb->query( $mquery ) )
207 - $rets[] = 1;
208 -
209 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemGpNum1', '_itemGpNum1') WHERE meta_key LIKE 'itemGpNum1'";
210 - if( $wpdb->query( $mquery ) )
211 - $rets[] = 1;
212 -
213 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemGpDis1', '_itemGpDis1') WHERE meta_key LIKE 'itemGpDis1'";
214 - if( $wpdb->query( $mquery ) )
215 - $rets[] = 1;
216 -
217 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemGpNum2', '_itemGpNum2') WHERE meta_key LIKE 'itemGpNum2'";
218 - if( $wpdb->query( $mquery ) )
219 - $rets[] = 1;
220 -
221 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemGpDis2', '_itemGpDis2') WHERE meta_key LIKE 'itemGpDis2'";
222 - if( $wpdb->query( $mquery ) )
223 - $rets[] = 1;
224 -
225 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemGpDis3', '_itemGpDis3') WHERE meta_key LIKE 'itemGpDis3'";
226 - if( $wpdb->query( $mquery ) )
227 - $rets[] = 1;
228 -
229 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemGpNum3', '_itemGpNum3') WHERE meta_key LIKE 'itemGpNum3'";
230 - if( $wpdb->query( $mquery ) )
231 - $rets[] = 1;
232 -
233 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemShipping', '_itemShipping') WHERE meta_key LIKE 'itemShipping'";
234 - if( $wpdb->query( $mquery ) )
235 - $rets[] = 1;
236 -
237 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemDeliveryMethod', '_itemDeliveryMethod') WHERE meta_key LIKE 'itemDeliveryMethod'";
238 - if( $wpdb->query( $mquery ) )
239 - $rets[] = 1;
240 -
241 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemShippingCharge', '_itemShippingCharge') WHERE meta_key LIKE 'itemShippingCharge'";
242 - if( $wpdb->query( $mquery ) )
243 - $rets[] = 1;
244 -
245 - $mquery = "UPDATE $tableName SET meta_key = REPLACE(meta_key, 'itemIndividualSCharge', '_itemIndividualSCharge') WHERE meta_key LIKE 'itemIndividualSCharge'";
246 - if( $wpdb->query( $mquery ) )
247 - $rets[] = 1;
248 -
249 - usces_log('USCES_UP07 : '.print_r($rets,true), 'db');
250 - $upgrade += USCES_UP07;
251 - update_option('usces_upgrade', $upgrade);
252 - return $rets;
253 -}
254 -
255 -function usces_upgrade_11(){
256 - $options = get_option('usces');
257 - $upgrade = (int)get_option('usces_upgrade');
258 -
259 - if( $upgrade & USCES_UP11 ) return false;
260 -
261 - global $wpdb;
262 - $rets = array();
263 -
264 - /* ITEM SKU DATA */
265 - $sort = (int)$options['system']['orderby_itemsku'];
266 - if( $sort ){
267 - $query = "SELECT * FROM $wpdb->postmeta WHERE meta_key <> '_isku_' AND meta_key LIKE '_isku_%' ORDER BY post_id, meta_key";
268 - }else{
269 - $query = "SELECT * FROM $wpdb->postmeta WHERE meta_key <> '_isku_' AND meta_key LIKE '_isku_%' ORDER BY post_id, meta_id";
270 - }
271 - $res = $wpdb->get_results($query, ARRAY_A);
272 -
273 - $conclusion = true;
274 - $pre_post_id = 0;
275 - $sort_id = 0;
276 - $check_code = array();
277 - $dep_num = array();
278 - foreach( (array)$res as $metarow ){
279 - $meta_value = unserialize($metarow['meta_value']);
280 - $newvalue = array();
281 - $newvalue['code'] = substr($metarow['meta_key'], 6);
282 - if( $pre_post_id == $metarow['post_id'] ){
283 - if( in_array( $newvalue['code'], $check_code ) ){
284 - $newvalue['code'] .= 'dupricate_' . (int)$dep_num[$newvalue['code']];
285 - $dep_num[$newvalue['code']]++;
286 - }
287 - }else{
288 - $check_code = array();
289 - $dep_num = array();
290 - $sort_id = 0;
291 - }
292 - foreach( (array)$meta_value as $k => $v ){
293 - switch ( $k ){
294 - case 'disp':
295 - $newvalue['name'] = $v;
296 - break;
297 - case 'cprice':
298 - $newvalue['cprice'] = $v;
299 - break;
300 - case 'price':
301 - $newvalue['price'] = $v;
302 - break;
303 - case 'unit':
304 - $newvalue['unit'] = $v;
305 - break;
306 - case 'zaikonum':
307 - $newvalue['stocknum'] = $v;
308 - break;
309 - case 'zaiko':
310 - $newvalue['stock'] = $v;
311 - break;
312 - case 'gptekiyo':
313 - $newvalue['gp'] = $v;
314 - break;
315 - case 'charging_type':
316 - break;
317 - default:
318 - $newvalue[$k] = $v;
319 - }
320 - }
321 - $newvalue['sort'] = $sort_id;
322 -
323 - $id = usces_add_sku($metarow['post_id'], $newvalue, false);
324 - $pre_post_id = $metarow['post_id'];
325 - $check_code[] = $newvalue['code'];
326 - $sort_id++;
327 -
328 - $res_key = $metarow['post_id'] . '_' . $newvalue['code'];
329 - if( $id ) {
330 - delete_post_meta($metarow['post_id'], $metarow['meta_key']);
331 - $rets['sku'][$res_key] = 1;
332 - }else{
333 - $rets['sku'][$res_key] = 0;
334 - usces_log('meta_id ' . $metarow['meta_id'] . ' : ' . __('This SKU-data has not been rebuilt.', 'usces'), 'database_error.log');
335 - }
336 - }
337 -
338 - /* ITEM OPTION DATA */
339 - $sort = (int)$options['system']['orderby_itemopt'];
340 - if( $sort ){
341 - $query = "SELECT * FROM $wpdb->postmeta WHERE meta_key <> '_iopt_' AND meta_key LIKE '_iopt_%' ORDER BY post_id, meta_key";
342 - }else{
343 - $query = "SELECT * FROM $wpdb->postmeta WHERE meta_key <> '_iopt_' AND meta_key LIKE '_iopt_%' ORDER BY post_id, meta_id";
344 - }
345 - $res = $wpdb->get_results($query, ARRAY_A);
346 -
347 - $conclusion = true;
348 - $pre_post_id = 0;
349 - $sort_id = 0;
350 - $check_code = array();
351 - $dep_num = array();
352 - foreach( (array)$res as $metarow ){
353 - $meta_value = unserialize($metarow['meta_value']);
354 - $newvalue = array();
355 - $newvalue['name'] = substr($metarow['meta_key'], 6);
356 - if( $pre_post_id == $metarow['post_id'] ){
357 - if( in_array( $newvalue['name'], $check_code ) ){
358 - $newvalue['name'] .= 'dupricate_' . (int)$dep_num[$newvalue['name']];
359 - $dep_num[$newvalue['name']]++;
360 - }
361 - }else{
362 - $check_code = array();
363 - $dep_num = array();
364 - $sort_id = 0;
365 - }
366 - foreach( (array)$meta_value as $k => $v ){
367 - switch ( $k ){
368 - case 'means':
369 - $newvalue['means'] = $v;
370 - break;
371 - case 'essential':
372 - $newvalue['essential'] = $v;
373 - break;
374 - case 'value':
375 - if( is_array($v) ){
376 - $nov = '';
377 - foreach((array)$v as $vs){
378 - if( !WCUtils::is_blank($vs) )
379 - //$nov .= str_replace('\\', '&yen;', trim( $vs )) . "\n";
380 - $nov .= $vs . "\n";
381 - }
382 - $newvalue['value'] = trim($nov);
383 - }else{
384 - $newvalue['value'] = trim($v);
385 - }
386 - break;
387 - default:
388 - $newvalue[$k] = trim($v);
389 - }
390 - }
391 - $newvalue['sort'] = $sort_id;
392 -
393 - $id = usces_add_opt($metarow['post_id'], $newvalue, false);
394 - $pre_post_id = $metarow['post_id'];
395 - $check_code[] = $newvalue['name'];
396 - $sort_id++;
397 -
398 - $res_key = $metarow['post_id'] . '_' . $newvalue['name'];
399 - if( $id ) {
400 - delete_post_meta($metarow['post_id'], $metarow['meta_key']);
401 - $rets['opt'][$res_key] = 1;
402 - }else{
403 - $rets['opt'][$res_key] = 0;
404 - usces_log('meta_id ' . $metarow['meta_id'] . ' : ' . __('This Item-Option-data has not been rebuilt.', 'usces'), 'database_error.log');
405 - }
406 - }
407 -
408 - /* PAYMENT METHOD DATA */
409 - $payment = get_option('usces_payment_method');
410 -//usces_log('payment : ' . print_r($payment,true), 'database_error.log');
411 - if( empty($payment) ) {
412 -
413 - $options = get_option('usces');
414 - $old_payment = isset($options['payment_method']) ? $options['payment_method'] : '';
415 - usces_log('old_payment : ' . print_r($old_payment,true), 'database_error.log');
416 - if( !empty($old_payment) && is_array($old_payment) ) {
417 - foreach( $old_payment as $key => $value ){
418 - $res_key = $key . '_' . $value['name'];
419 - $id = usces_add_system_option( 'usces_payment_method', $value );
420 - if( $id ) {
421 - $rets['payment'][$res_key] = 1;
422 - }else{
423 - $rets['payment'][$res_key] = 0;
424 - usces_log('payment_method ' . $value['name'] . ' : ' . __('This Payment-Method-data has not been rebuilt.', 'usces'), 'database_error.log');
425 - }
426 - }
427 - }
428 - }
429 -
430 - usces_log('USCES_UP11 : ' . print_r($rets,true), 'db');
431 -
432 - $upgrade += USCES_UP11;
433 - update_option('usces_upgrade', $upgrade);
434 - return $rets;
435 -}
436 -
437 -function usces_log($log, $file){
438 - global $usces;
439 -
440 - if( 'db' == $file ){
441 -
442 - global $wpdb;
443 - $table_name = $wpdb->prefix . 'usces_log';
444 - $query = $wpdb->prepare("INSERT INTO $table_name (datetime, log) VALUES(%s, %s)", current_time('mysql'), $log);
445 - $wpdb->query( $query );
446 -
447 - }else{
448 -
449 - $log = date('[Y-m-d H:i:s]', current_time('timestamp')) . "\t" . $log . "\n";
450 - $file_path = USCES_PLUGIN_DIR . '/logs/' . $file;
451 - if( is_dir($file_path) )
452 - return;
453 -
454 - $fp = fopen($file_path, 'a');
455 - if( false !== $fp ){
456 - fwrite($fp, $log);
457 - fclose($fp);
458 - }
459 - }
460 -}
461 -
462 -
463 -function usces_filter_delivery_secure_check( $mes ){
464 - global $usces;
465 - $usces_secure_link = get_option('usces_secure_link');
466 - $paymod_id = '';
467 - $settlement = '';
468 - $payments = usces_get_system_option( 'usces_payment_method', 'sort' );
469 -
470 - foreach ( (array)$payments as $id => $value ) {
471 - if( isset($_POST['offer']['payment_name']) && $value['name'] == $_POST['offer']['payment_name']){
472 - $settlement = $value['settlement'];
473 - break;
474 - }
475 - }
476 - switch( $settlement ){
477 - case 'acting_zeus_card':
478 - $cnum1 = trim($_POST["cnum1"]);
479 - $securecode = (isset($_POST["securecode"])) ? trim($_POST["securecode"]) : '';
480 - if ( !is_numeric($cnum1) )
481 - $mes .= __('カード番号が不正です', 'usces') . "<br />";
482 -
483 - if ( isset($_POST["securecode"]) && !is_numeric($securecode) )
484 - $mes .= __('セキュリティコードが不正です', 'usces') . "<br />";
485 -
486 - if ( WCUtils::is_blank($_POST["expyy"]) )
487 - $mes .= __('カードの有効年を選択してください', 'usces') . "<br />";
488 -
489 - if ( WCUtils::is_blank($_POST["expmm"]) )
490 - $mes .= __('カードの有効月を選択してください', 'usces') . "<br />";
491 -
492 - if ( WCUtils::is_blank($_POST["username_card"]) )
493 - $mes .= __('カード名義を入力してください', 'usces') . "<br />";
494 -
495 - if ( isset($_POST["howpay"]) && 0 == $_POST["howpay"] && WCUtils::is_blank($_POST["cbrand"]) )
496 - $mes .= __('カードブランドを選択してください', 'usces') . "<br />";
497 -
498 - if ( 'zeus' != $_POST['acting'] )
499 - $mes .= __('カード決済データが不正です!', 'usces');
500 -
501 - break;
502 -
503 - case 'acting_zeus_conv':
504 - if( WCUtils::is_blank($_POST['username_conv']) ) {
505 - $mes .= "お名前を入力してください。<br />";
506 - } elseif( !preg_match( "/^[ァ-ヶー]+$/u", $_POST['username_conv'] ) ) {
507 - $mes .= "お名前は全角カタカナで入力してください。<br />";
508 - }
509 - break;
510 - }
511 -
512 - return $mes;
513 -}
514 -
515 -function usces_get_conv_name($code){
516 - switch($code){
517 - case 'D001':
518 - case '010'://20101018ysk
519 - $name = 'セブンイレブン';
520 - break;
521 - case 'D002':
522 - case '020'://20101018ysk
523 - $name = 'ローソン';
524 - break;
525 - case 'D015':
526 - case '760'://20101018ysk
527 - $name = 'セイコーマート';
528 - break;
529 - case 'D405':
530 - $name = 'ペイジー';
531 - break;
532 - case 'D003':
533 - $name = 'サンクス';
534 - break;
535 - case 'D004':
536 - $name = 'サークルK';
537 - break;
538 - case 'D005':
539 - case '080'://20101018ysk
540 - case 'D050':
541 - $name = 'ミニストップ';
542 - break;
543 - case 'D010':
544 - case 'D060':
545 - $name = 'デイリーヤマザキ';
546 - break;
547 - case 'D011':
548 - $name = 'ヤマザキデイリーストア';
549 - break;
550 - case 'D030':
551 - case '030'://20101018ysk
552 - $name = 'ファミリーマート';
553 - break;
554 - case 'D401':
555 - $name = 'CyberEdy';
556 - break;
557 - case 'D404':
558 - $name = '楽天銀行';
559 - break;
560 - case 'D406':
561 - $name = 'ジャパネット銀行';
562 - break;
563 - case 'D451':
564 - $name = 'ウェブマネー';
565 - break;
566 - case 'D452':
567 - $name = 'ビットキャッシュ';
568 - break;
569 - case 'P901':
570 - $name = 'コンビニ払込票';
571 - break;
572 - case 'P902':
573 - $name = 'コンビニ払込票(郵便振替対応)';
574 - break;
575 -//20101018ysk start
576 - case '050':
577 - $name = 'デイリーヤマザキ・ヤマザキデイリーストア・タイムリー';
578 - break;
579 - case '060':
580 - $name = 'サークルK・サンクス';
581 - break;
582 - case '110':
583 - $name = 'am/pm';
584 - break;
585 -//20101018ysk end
586 - default:
587 - $name = '';
588 - }
589 - return $name;
590 -}
591 -
592 -function usces_get_remise_conv_return($code){
593 - switch($code){
594 - case 'D001': //セブンイレブン
595 - $html = '<tr><th>' . __('払込番号','usces') . '</th><td>' . esc_html($_REQUEST["X-PAY_NO1"]) . "</td></tr>\n";
596 - $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";
597 - break;
598 - case 'D002': //ローソン
599 - case 'D015': //セイコーマート
600 - case 'D405': //ペイジー
601 - $html = '<tr><th>' . __('受付番号','usces') . '</th><td>' . esc_html($_REQUEST["X-PAY_NO1"]) . "</td></tr>\n";
602 - $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";
603 - break;
604 - case 'D003': //サンクス
605 - case 'D004': //サークルK
606 - case 'D005': //ミニストップ
607 - case 'D010': //デイリーヤマザキ
608 - case 'D011': //ヤマザキデイリーストア
609 - $html = '<tr><th>' . __('決済番号','usces') . '</th><td>' . esc_html($_REQUEST["X-PAY_NO1"]) . "</td></tr>\n";
610 - $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";
611 - break;
612 - case 'D030': //ファミリーマート
613 - $html = '<tr><th>' . __('コード','usces') . '</th><td>' . esc_html($_REQUEST["X-PAY_NO1"]) . "</td></tr>\n";
614 - $html .= '<tr><th>'.__('注文番号', 'usces').'</th><td>'.esc_html($_REQUEST["X-PAY_NO2"])."</td></tr>\n";
615 - break;
616 - case 'D401': //CyberEdy
617 - case 'D404': //楽天銀行
618 - case 'D406': //ジャパネット銀行
619 - case 'D451': //ウェブマネー
620 - case 'D452': //ビットキャッシュ
621 - $html = '<tr><th>' . __('受付番号','usces') . '</th><td>' . esc_html($_REQUEST["X-PAY_NO1"]) . "</td></tr>\n";
622 - $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";
623 - break;
624 - case 'P901': //コンビニ払込票
625 - case 'P902': //コンビニ払込票(郵便振替対応)
626 - $html = '<tr><th>' . __('受付番号','usces') . '</th><td>' . esc_html($_REQUEST["X-PAY_NO1"]) . "</td></tr>\n";
627 - break;
628 - default:
629 - $html = '';
630 - }
631 - return $html;
632 -}
633 -
634 -function usces_payment_detail($usces_entries){
635 - $payments = usces_get_payments_by_name( $usces_entries['order']['payment_name'] );
636 - $acting_flag = ( 'acting' == $payments['settlement'] ) ? $payments['module'] : $payments['settlement'];
637 - $str = '';
638 - switch( $acting_flag ){
639 - case 'paypal.php':
640 - break;
641 -
642 - case 'epsilon.php':
643 - break;
644 -
645 - case 'acting_zeus_card':
646 - if( !isset($usces_entries['order']['cbrand']) || (isset($usces_entries['order']['howpay']) && '1' === $usces_entries['order']['howpay']) ){
647 - $str = ' 一括払い';
648 - }else{
649 - $div_name = 'div_' . $usces_entries['order']['cbrand'];
650 - switch($usces_entries['order'][$div_name]){
651 - case '01':
652 - $str = ' 一括払い';
653 - break;
654 - case '99':
655 - $str = ' 分割(リボ払い)';
656 - break;
657 - case '03':
658 - $str = ' 分割(3回)';
659 - break;
660 - case '05':
661 - $str = ' 分割(5回)';
662 - break;
663 - case '06':
664 - $str = ' 分割(6回)';
665 - break;
666 - case '10':
667 - $str = ' 分割(10回)';
668 - break;
669 - case '12':
670 - $str = ' 分割(12回)';
671 - break;
672 - case '15':
673 - $str = ' 分割(15回)';
674 - break;
675 - case '18':
676 - $str = ' 分割(18回)';
677 - break;
678 - case '20':
679 - $str = ' 分割(20回)';
680 - break;
681 - case '24':
682 - $str = ' 分割(24回)';
683 - break;
684 - }
685 - }
686 - break;
687 -
688 - case 'acting_zeus_bank':
689 - break;
690 -
691 - case 'acting_remise_card':
692 - if( isset( $usces_entries['order']['div'] ) ){
693 - switch($usces_entries['order']['div']){
694 - case '0':
695 - $str = ' 一括払い';
696 - break;
697 - case '1':
698 - $str = ' 分割(2回)';
699 - break;
700 - case '2':
701 - $str = ' 分割(リボ払い)';
702 - break;
703 - }
704 - }
705 - break;
706 -
707 - case 'acting_remise_conv':
708 - break;
709 - }
710 -
711 - $str = apply_filters('usces_filter_payment_detail', $str, $usces_entries);
712 - return $str;
713 -}
714 -
715 -//20100818ysk start
716 -function usces_filter_delivery_check_custom_order( $mes ) {
717 - global $usces;
718 -
719 - $meta = usces_has_custom_field_meta('order');
720 -//20140131ysk start 0000819
721 - if( is_array($meta) ) {
722 - unset( $_SESSION['usces_entry']['custom_order'] );
723 - if( isset($_POST['custom_order']) ) {
724 - foreach( $_POST['custom_order'] as $key => $value ) {
725 - if( is_array($value) ) {
726 - foreach( $value as $k => $v ) {
727 - $_SESSION['usces_entry']['custom_order'][$key][trim($v)] = trim($v);
728 - }
729 - } else {
730 - $_SESSION['usces_entry']['custom_order'][$key] = trim($value);
731 - }
732 - }
733 - }
734 - }
735 -//20140131ysk end
736 -
737 - foreach($meta as $key => $entry) {
738 - $essential = $entry['essential'];
739 - if($essential == 1) {
740 - $name = $entry['name'];
741 - $means = $entry['means'];
742 - if($means == 2) {//Text
743 - if( WCUtils::is_blank($_POST['custom_order'][$key]) )
744 - $mes .= __($name.'を入力してください。', 'usces')."<br />";
745 - } else {
746 - if(!isset($_POST['custom_order'][$key]) or $_POST['custom_order'][$key] == "#NONE#")
747 - $mes .= __($name.'を選択してください。', 'usces')."<br />";
748 - }
749 - }
750 - }
751 -
752 - return $mes;
753 -}
754 -
755 -function usces_filter_customer_check_custom_customer( $mes ) {
756 - global $usces;
757 -
758 - $meta = usces_has_custom_field_meta('customer');
759 - foreach($meta as $key => $entry) {
760 - $essential = $entry['essential'];
761 - if($essential == 1) {
762 - $name = $entry['name'];
763 - $means = $entry['means'];
764 - if($means == 2) {//Text
765 - if( WCUtils::is_blank($_POST['custom_customer'][$key]) )
766 - $mes .= __($name.'を入力してください。', 'usces')."<br />";
767 - } else {
768 - if(!isset($_POST['custom_customer'][$key]) or $_POST['custom_customer'][$key] == "#NONE#")
769 - $mes .= __($name.'を選択してください。', 'usces')."<br />";
770 - }
771 - }
772 - }
773 -
774 - return $mes;
775 -}
776 -
777 -function usces_filter_delivery_check_custom_delivery( $mes ) {
778 - global $usces;
779 -
780 - if( isset($_POST['delivery']['delivery_flag']) && $_POST['delivery']['delivery_flag'] == '1' ) {
781 - $meta = usces_has_custom_field_meta('delivery');
782 - foreach($meta as $key => $entry) {
783 - $essential = $entry['essential'];
784 - if($essential == 1) {
785 - $name = $entry['name'];
786 - $means = $entry['means'];
787 - if($means == 2) {//Text
788 - if( WCUtils::is_blank($_POST['custom_delivery'][$key]) )
789 - $mes .= __($name.'を入力してください。', 'usces')."<br />";
790 - } else {
791 - if(!isset($_POST['custom_delivery'][$key]) or $_POST['custom_delivery'][$key] == "#NONE#")
792 - $mes .= __($name.'を選択してください。', 'usces')."<br />";
793 - }
794 - }
795 - }
796 - }
797 -
798 - return $mes;
799 -}
800 -
801 -function usces_filter_member_check_custom_member( $mes ) {
802 - global $usces;
803 -
804 - unset($_SESSION['usces_member']['custom_member']);
805 - if(isset($_POST['custom_member'])) {
806 - foreach( $_POST['custom_member'] as $key => $value )
807 - if( is_array($value) ) {
808 - foreach( $value as $k => $v )
809 - $_SESSION['usces_member']['custom_member'][$key][trim($v)] = trim($v);
810 - } else {
811 - $_SESSION['usces_member']['custom_member'][$key] = trim($value);
812 - }
813 - }
814 -
815 - $meta = usces_has_custom_field_meta('member');
816 - foreach($meta as $key => $entry) {
817 - $essential = $entry['essential'];
818 - if($essential == 1) {
819 - $name = $entry['name'];
820 - $means = $entry['means'];
821 - if($means == 2) {//Text
822 - if( WCUtils::is_blank($_POST['custom_member'][$key]) )
823 - $mes .= __($name.'を入力してください。', 'usces')."<br />";
824 - } else {
825 - if(!isset($_POST['custom_member'][$key]) or $_POST['custom_member'][$key] == "#NONE#")
826 - $mes .= __($name.'を選択してください。', 'usces')."<br />";
827 - }
828 - }
829 - }
830 -
831 - return $mes;
832 -}
833 -//20100818ysk end
834 -function usces_dashboard_setup() {
835 - wp_add_dashboard_widget( 'usces_db_widget' , 'Welcart Information' , 'usces_db_widget');
836 -}
837 -
838 -function usces_admin_login_head() {
839 -?>
840 -<script type='text/javascript'>
841 -(function($) {
842 - usces = {
843 - settings: {
844 - url: 'http://www.welcart.com/varch/varch.php',
845 - type: 'POST',
846 - cache: false,
847 - success: function(data, dataType){
848 - },
849 - error: function(msg){
850 - }
851 - },
852 - varch : function() {
853 - var s = usces.settings;
854 - s.data = "action=varch_ajax&ID=usces_varch&ver=" + <?php echo $_SERVER['HTTP_HOST']; ?>;
855 - $.ajax( s );
856 - return false;
857 - }
858 - };
859 - usces.varch();
860 -})(jQuery);
861 -</script>
862 -<?php
863 -}
864 -
865 -//20100908ysk start
866 -// member list download
867 -function usces_download_member_list() {
868 - require_once( USCES_PLUGIN_DIR . "/classes/dataList.class.php" );
869 - global $wpdb, $usces;
870 -//20110411ysk start
871 - global $usces_settings;
872 -//20110411ysk end
873 -
874 - $ext = $_REQUEST['ftype'];
875 -/* if($ext == 'xls') {//HTML
876 - $table_h = "<table>";
877 - $table_f = "</table>";
878 - $tr_h = "<tr>";
879 - $tr_f = "</tr>";
880 - $th_h1 = "<th>";
881 - $th_h = "<th>";
882 - $th_f = "</th>";
883 - $td_h1 = "<td>";
884 - $td_h = "<td>";
885 - $td_f = "</td>";
886 - $lf = "\n";
887 -*/ if($ext == 'xls') {//TSV
888 - $table_h = "";
889 - $table_f = "";
890 - $tr_h = "";
891 - $tr_f = "";
892 - $th_h1 = '"';
893 - $th_h = "\t".'"';
894 - $th_f = '"';
895 - $td_h1 = '"';
896 - $td_h = "\t".'"';
897 - $td_f = '"';
898 - $lf = "\n";
899 - } elseif($ext == 'csv') {//CSV
900 - $table_h = "";
901 - $table_f = "";
902 - $tr_h = "";
903 - $tr_f = "";
904 -//20110201ysk start
905 - //$th_h1 = "";
906 - $th_h1 = '"';
907 - //$th_h = ",";
908 - $th_h = ',"';
909 - //$th_f = "";
910 - $th_f = '"';
911 - //$td_h1 = "";
912 - $td_h1 = '"';
913 - //$td_h = ",";
914 - $td_h = ',"';
915 - //$td_f = "";
916 - $td_f = '"';
917 -//20110201ysk end
918 - $lf = "\n";
919 - } else {
920 - exit();
921 - }
922 - $csmb_meta = usces_has_custom_field_meta('member');
923 -//20110411ysk start
924 - $applyform = usces_get_apply_addressform($usces->options['system']['addressform']);
925 -//20110411ysk end
926 -
927 - //==========================================================================
928 - $usces_opt_member = get_option('usces_opt_member');
929 - if(!is_array($usces_opt_member)){
930 - $usces_opt_member = array();
931 - }
932 - $usces_opt_member['ftype_mem'] = $ext;
933 - $chk_mem = array();
934 - $chk_mem['ID'] = 1;
935 - $chk_mem['email'] = (isset($_REQUEST['check']['email'])) ? 1 : 0;
936 - if(!empty($csmb_meta)) {
937 - foreach($csmb_meta as $key => $entry) {
938 - if($entry['position'] == 'name_pre') {
939 - $name = $entry['name'];
940 -//20110208ysk start
941 - $csmb_key = 'csmb_'.$key;
942 - //$chk_mem[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
943 - $chk_mem[$csmb_key] = (isset($_REQUEST['check'][$csmb_key])) ? 1 : 0;
944 -//20110208ysk end
945 - }
946 - }
947 - }
948 - $chk_mem['name'] = 1;
949 -//20110411ysk start
950 - if($applyform == 'JP') {
951 - $chk_mem['kana'] = (isset($_REQUEST['check']['kana'])) ? 1 : 0;
952 - }
953 -//20110411ysk end
954 - if(!empty($csmb_meta)) {
955 - foreach($csmb_meta as $key => $entry) {
956 - if($entry['position'] == 'name_after') {
957 - $name = $entry['name'];
958 -//20110208ysk start
959 - $csmb_key = 'csmb_'.$key;
960 - //$chk_mem[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
961 - $chk_mem[$csmb_key] = (isset($_REQUEST['check'][$csmb_key])) ? 1 : 0;
962 -//20110208ysk end
963 - }
964 - }
965 - }
966 - $chk_mem['zip'] = (isset($_REQUEST['check']['zip'])) ? 1 : 0;
967 -//20110411ysk start
968 - $chk_mem['country'] = 1;
969 -//20110411ysk end
970 - $chk_mem['pref'] = 1;
971 - $chk_mem['address1'] = 1;
972 - $chk_mem['address2'] = 1;
973 - $chk_mem['address3'] = 1;
974 - $chk_mem['tel'] = (isset($_REQUEST['check']['tel'])) ? 1 : 0;
975 - $chk_mem['fax'] = (isset($_REQUEST['check']['fax'])) ? 1 : 0;
976 - if(!empty($csmb_meta)) {
977 - foreach($csmb_meta as $key => $entry) {
978 - if($entry['position'] == 'fax_after') {
979 - $name = $entry['name'];
980 -//20110208ysk start
981 - $csmb_key = 'csmb_'.$key;
982 - //$chk_mem[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
983 - $chk_mem[$csmb_key] = (isset($_REQUEST['check'][$csmb_key])) ? 1 : 0;
984 -//20110208ysk end
985 - }
986 - }
987 - }
988 - $chk_mem['date'] = (isset($_REQUEST['check']['date'])) ? 1 : 0;
989 - $chk_mem['point'] = (isset($_REQUEST['check']['point'])) ? 1 : 0;
990 - $chk_mem['rank'] = (isset($_REQUEST['check']['rank'])) ? 1 : 0;
991 - $usces_opt_member['chk_mem'] = apply_filters( 'usces_filter_chk_mem', $chk_mem );
992 - update_option('usces_opt_member', $usces_opt_member);
993 - //==========================================================================
994 -
995 - $_REQUEST['searchIn'] = "searchIn";
996 - $tableName = $wpdb->prefix."usces_member";
997 - $arr_column = array(
998 - __('membership number', 'usces') => 'ID',
999 - __('name', 'usces') => 'name',
1000 - __('Address', 'usces') => 'address',
1001 - __('Phone number', 'usces') => 'tel',
1002 - __('e-mail', 'usces') => 'email',
1003 - __('Strated date', 'usces') => 'date',
1004 - __('current point', 'usces') => 'point');
1005 - $DT = new dataList($tableName, $arr_column);
1006 -//20101202ysk start
1007 - $DT->pageLimit = 'off';
1008 -//20101202ysk end
1009 - $res = $DT->MakeTable();
1010 - $rows = $DT->rows;
1011 -
1012 - //==========================================================================
1013 - $line = $table_h;
1014 - $line .= $tr_h;
1015 - $line .= $th_h1.__('membership number', 'usces').$th_f;
1016 - if(isset($_REQUEST['check']['email'])) $line .= $th_h.__('e-mail', 'usces').$th_f;
1017 - if(!empty($csmb_meta)) {
1018 - foreach($csmb_meta as $key => $entry) {
1019 - if($entry['position'] == 'name_pre') {
1020 - $name = $entry['name'];
1021 -//20110208ysk start
1022 - $csmb_key = 'csmb_'.$key;
1023 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1024 - if(isset($_REQUEST['check'][$csmb_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1025 -//20110208ysk end
1026 - }
1027 - }
1028 - }
1029 - $line .= $th_h.__('name', 'usces').$th_f;
1030 -//20110411ysk start
1031 - if($applyform == 'JP') {
1032 - if(isset($_REQUEST['check']['kana'])) $line .= $th_h.__('furigana', 'usces').$th_f;
1033 - }
1034 -//20110411ysk end
1035 - if(!empty($csmb_meta)) {
1036 - foreach($csmb_meta as $key => $entry) {
1037 - if($entry['position'] == 'name_after') {
1038 - $name = $entry['name'];
1039 -//20110208ysk start
1040 - $csmb_key = 'csmb_'.$key;
1041 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1042 - if(isset($_REQUEST['check'][$csmb_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1043 -//20110208ysk end
1044 - }
1045 - }
1046 - }
1047 -//20110411ysk start
1048 - switch($applyform) {
1049 - case 'JP':
1050 - if(isset($_REQUEST['check']['zip'])) $line .= $th_h.__('Zip/Postal Code', 'usces').$th_f;
1051 - $line .= $th_h.__('Country', 'usces').$th_f;
1052 - $line .= $th_h.__('Province', 'usces').$th_f;
1053 - $line .= $th_h.__('city', 'usces').$th_f;
1054 - $line .= $th_h.__('numbers', 'usces').$th_f;
1055 - $line .= $th_h.__('building name', 'usces').$th_f;
1056 - if(isset($_REQUEST['check']['tel'])) $line .= $th_h.__('Phone number', 'usces').$th_f;
1057 - if(isset($_REQUEST['check']['fax'])) $line .= $th_h.__('FAX number', 'usces').$th_f;
1058 - break;
1059 - case 'US':
1060 - default:
1061 - $line .= $th_h.__('Address Line1', 'usces').$th_f;
1062 - $line .= $th_h.__('Address Line2', 'usces').$th_f;
1063 - $line .= $th_h.__('city', 'usces').$th_f;
1064 - $line .= $th_h.__('State', 'usces').$th_f;
1065 - $line .= $th_h.__('Country', 'usces').$th_f;
1066 - if(isset($_REQUEST['check']['zip'])) $line .= $th_h.__('Zip', 'usces').$th_f;
1067 - if(isset($_REQUEST['check']['tel'])) $line .= $th_h.__('Phone number', 'usces').$th_f;
1068 - if(isset($_REQUEST['check']['fax'])) $line .= $th_h.__('FAX number', 'usces').$th_f;
1069 - break;
1070 - }
1071 -//20110411ysk end
1072 - if(!empty($csmb_meta)) {
1073 - foreach($csmb_meta as $key => $entry) {
1074 - if($entry['position'] == 'fax_after') {
1075 - $name = $entry['name'];
1076 -//20110208ysk start
1077 - $csmb_key = 'csmb_'.$key;
1078 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1079 - if(isset($_REQUEST['check'][$csmb_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1080 -//20110208ysk end
1081 - }
1082 - }
1083 - }
1084 - if(isset($_REQUEST['check']['date'])) $line .= $th_h.__('Strated date', 'usces').$th_f;
1085 - if(isset($_REQUEST['check']['point'])) $line .= $th_h.__('current point', 'usces').$th_f;
1086 - if(isset($_REQUEST['check']['rank'])) $line .= $th_h.__('Rank', 'usces').$th_f;
1087 - $line .= apply_filters( 'usces_filter_chk_mem_label', NULL, $usces_opt_member, $rows );
1088 - $line .= $tr_f.$lf;
1089 - //==========================================================================
1090 - foreach((array)$rows as $array) {
1091 - $member_id = $array['ID'];
1092 - $query = $wpdb->prepare("SELECT * FROM $tableName WHERE ID = %d", $member_id);
1093 - $data = $wpdb->get_row( $query, ARRAY_A );
1094 -
1095 - $line .= $tr_h;
1096 - $line .= $td_h1.$member_id.$td_f;
1097 - if(isset($_REQUEST['check']['email'])) $line .= $td_h.usces_entity_decode($array['email'], $ext).$td_f;
1098 - if(!empty($csmb_meta)) {
1099 - foreach($csmb_meta as $key => $entry) {
1100 - if($entry['position'] == 'name_pre') {
1101 - $name = $entry['name'];
1102 - $csmb_key = 'csmb_'.$key;
1103 -//20110208ysk start
1104 - //if(isset($_REQUEST['check'][$name])) {
1105 - if(isset($_REQUEST['check'][$csmb_key])) {
1106 -//20110208ysk end
1107 - $value = maybe_unserialize($usces->get_member_meta_value($csmb_key, $member_id));
1108 - if(empty($value)) {
1109 - $value = '';
1110 - } elseif(is_array($value)) {
1111 - $concatval = '';
1112 - $c = '';
1113 - foreach($value as $v) {
1114 - $concatval .= $c.$v;
1115 - $c = ' ';
1116 - }
1117 - $value = $concatval;
1118 - }
1119 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
1120 - }
1121 - }
1122 - }
1123 - }
1124 -//20110411ysk start
1125 - switch($applyform) {
1126 - case 'JP':
1127 - $line .= $td_h.usces_entity_decode($data['mem_name1'].' '.$data['mem_name2'], $ext).$td_f;
1128 - if(isset($_REQUEST['check']['kana'])) $line .= $td_h.usces_entity_decode($data['mem_name3'].' '.$data['mem_name4'], $ext).$td_f;
1129 - break;
1130 - case 'US':
1131 - default:
1132 - $line .= $td_h.usces_entity_decode($data['mem_name2'].' '.$data['mem_name1'], $ext).$td_f;
1133 - break;
1134 - }
1135 -//20110411ysk end
1136 - if(!empty($csmb_meta)) {
1137 - foreach($csmb_meta as $key => $entry) {
1138 - if($entry['position'] == 'name_after') {
1139 - $name = $entry['name'];
1140 - $csmb_key = 'csmb_'.$key;
1141 -//20110208ysk start
1142 - //if(isset($_REQUEST['check'][$name])) {
1143 - if(isset($_REQUEST['check'][$csmb_key])) {
1144 -//20110208ysk end
1145 - $value = maybe_unserialize($usces->get_member_meta_value($csmb_key, $member_id));
1146 - if(empty($value)) {
1147 - $value = '';
1148 - } elseif(is_array($value)) {
1149 - $concatval = '';
1150 - $c = '';
1151 - foreach($value as $v) {
1152 - $concatval .= $c.$v;
1153 - $c = ' ';
1154 - }
1155 - $value = $concatval;
1156 - }
1157 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
1158 - }
1159 - }
1160 - }
1161 - }
1162 -//20110411ysk start
1163 - $address_info = '';
1164 - switch($applyform) {
1165 - case 'JP':
1166 - if(isset($_REQUEST['check']['zip'])) $address_info .= $td_h.usces_entity_decode($data['mem_zip'], $ext).$td_f;
1167 - $address_info .= $td_h.$usces_settings['country'][$usces->get_member_meta_value('customer_country', $member_id)].$td_f;
1168 - $address_info .= $td_h.usces_entity_decode($data['mem_pref'], $ext).$td_f;
1169 - $address_info .= $td_h.usces_entity_decode($data['mem_address1'], $ext).$td_f;
1170 - $address_info .= $td_h.usces_entity_decode($data['mem_address2'], $ext).$td_f;
1171 - $address_info .= $td_h.usces_entity_decode($data['mem_address3'], $ext).$td_f;
1172 - if(isset($_REQUEST['check']['tel'])) $address_info .= $td_h.usces_entity_decode($data['mem_tel'], $ext).$td_f;
1173 - if(isset($_REQUEST['check']['fax'])) $address_info .= $td_h.usces_entity_decode($data['mem_fax'], $ext).$td_f;
1174 - break;
1175 - case 'US':
1176 - default:
1177 - $address_info .= $td_h.usces_entity_decode($data['mem_address2'], $ext).$td_f;
1178 - $address_info .= $td_h.usces_entity_decode($data['mem_address3'], $ext).$td_f;
1179 - $address_info .= $td_h.usces_entity_decode($data['mem_address1'], $ext).$td_f;
1180 - $address_info .= $td_h.usces_entity_decode($data['mem_pref'], $ext).$td_f;
1181 - $address_info .= $td_h.$usces_settings['country'][$usces->get_member_meta_value('customer_country', $member_id)].$td_f;
1182 - if(isset($_REQUEST['check']['zip'])) $address_info .= $td_h.usces_entity_decode($data['mem_zip'], $ext).$td_f;
1183 - if(isset($_REQUEST['check']['tel'])) $address_info .= $td_h.usces_entity_decode($data['mem_tel'], $ext).$td_f;
1184 - if(isset($_REQUEST['check']['fax'])) $address_info .= $td_h.usces_entity_decode($data['mem_fax'], $ext).$td_f;
1185 - break;
1186 - }
1187 - $address_info_args = compact( 'td_h', 'td_f', 'ext', 'member_id', 'applyform' );
1188 - $line .= apply_filters( 'usces_filter_mem_csv_address_info', $address_info, $data, $address_info_args );
1189 -//20110411ysk end
1190 - if(!empty($csmb_meta)) {
1191 - foreach($csmb_meta as $key => $entry) {
1192 - if($entry['position'] == 'fax_after') {
1193 - $name = $entry['name'];
1194 - $csmb_key = 'csmb_'.$key;
1195 -//20110208ysk start
1196 - //if(isset($_REQUEST['check'][$name])) {
1197 - if(isset($_REQUEST['check'][$csmb_key])) {
1198 -//20110208ysk end
1199 - $value = maybe_unserialize($usces->get_member_meta_value($csmb_key, $member_id));
1200 - if(empty($value)) {
1201 - $value = '';
1202 - } elseif(is_array($value)) {
1203 - $concatval = '';
1204 - $c = '';
1205 - foreach($value as $v) {
1206 - $concatval .= $c.$v;
1207 - $c = ' ';
1208 - }
1209 - $value = $concatval;
1210 - }
1211 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
1212 - }
1213 - }
1214 - }
1215 - }
1216 - if(isset($_REQUEST['check']['date'])) $line .= $td_h.$data['mem_registered'].$td_f;
1217 - if(isset($_REQUEST['check']['point'])) $line .= $td_h.$data['mem_point'].$td_f;
1218 - if(isset($_REQUEST['check']['rank'])) {
1219 - $rank = '';
1220 - foreach((array)$usces->member_status as $rk => $rv) {
1221 - if($rk == $data['mem_status']) {
1222 - $rank = $rv;
1223 - break;
1224 - }
1225 - }
1226 - $line .= $td_h.$rank.$td_f;
1227 - }
1228 - $line .= apply_filters( 'usces_filter_chk_mem_data', NULL, $usces_opt_member, $member_id, $data );
1229 - $line .= $tr_f.$lf;
1230 - }
1231 - $line .= $table_f.$lf;
1232 - //==========================================================================
1233 -
1234 - if($ext == 'xls') {
1235 - header("Content-Type: application/vnd.ms-excel; charset=Shift-JIS");
1236 - } elseif($ext == 'csv') {
1237 - header("Content-Type: application/octet-stream");
1238 - }
1239 - header("Content-Disposition: attachment; filename=usces_member_list.".$ext);
1240 - mb_http_output('pass');
1241 - print(mb_convert_encoding($line, "SJIS-win", "UTF-8"));
1242 - exit();
1243 -}
1244 -
1245 -// product list download
1246 -function usces_download_product_list() {
1247 - require_once( USCES_PLUGIN_DIR . "/classes/orderList.class.php" );
1248 - global $wpdb, $usces;
1249 -
1250 - $ext = $_REQUEST['ftype'];
1251 -/* if($ext == 'xls') {//HTML
1252 - $table_h = "<table>";
1253 - $table_f = "</table>";
1254 - $tr_h = "<tr>";
1255 - $tr_f = "</tr>";
1256 - $th_h1 = "<th>";
1257 - $th_h = "<th>";
1258 - $th_f = "</th>";
1259 - $td_h1 = "<td>";
1260 - $td_h = "<td>";
1261 - $td_f = "</td>";
1262 - $sp = ":";
1263 - $nb = " ";
1264 - $lf = "\n";
1265 -*/ if($ext == 'xls') {//TSV
1266 - $table_h = "";
1267 - $table_f = "";
1268 - $tr_h = "";
1269 - $tr_f = "";
1270 - $th_h1 = '"';
1271 - $th_h = "\t".'"';
1272 - $th_f = '"';
1273 - $td_h1 = '"';
1274 - $td_h = "\t".'"';
1275 - $td_f = '"';
1276 - $sp = ":";
1277 - $nb = "\n";
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 - $nb = " ";
1300 - $lf = "\n";
1301 - } else {
1302 - exit();
1303 - }
1304 -
1305 - //==========================================================================
1306 - $usces_opt_order = get_option('usces_opt_order');
1307 - if(!is_array($usces_opt_order)){
1308 - $usces_opt_order = array();
1309 - }
1310 - $usces_opt_order['ftype_pro'] = $ext;
1311 - $chk_pro = array();
1312 - $chk_pro['ID'] = 1;
1313 - $chk_pro['deco_id'] = 1;
1314 - $chk_pro['date'] = (isset($_REQUEST['check']['date'])) ? 1 : 0;
1315 - $chk_pro['mem_id'] = (isset($_REQUEST['check']['mem_id'])) ? 1 : 0;
1316 - $chk_pro['name'] = (isset($_REQUEST['check']['name'])) ? 1 : 0;
1317 - $chk_pro['delivery_method'] = (isset($_REQUEST['check']['delivery_method'])) ? 1 : 0;
1318 - $chk_pro['shipping_date'] = (isset($_REQUEST['check']['shipping_date'])) ? 1 : 0;
1319 - $chk_pro['item_code'] = 1;
1320 - $chk_pro['sku_code'] = 1;
1321 - $chk_pro['item_name'] = (isset($_REQUEST['check']['item_name'])) ? 1 : 0;
1322 - $chk_pro['sku_name'] = (isset($_REQUEST['check']['sku_name'])) ? 1 : 0;
1323 - $chk_pro['options'] = (isset($_REQUEST['check']['options'])) ? 1 : 0;
1324 - $chk_pro['quantity'] = 1;
1325 - $chk_pro['price'] = 1;
1326 - $chk_pro['unit'] = (isset($_REQUEST['check']['unit'])) ? 1 : 0;
1327 - $usces_opt_order['chk_pro'] = apply_filters( 'usces_filter_chk_pro', $chk_pro );
1328 - update_option('usces_opt_order', $usces_opt_order);
1329 - //==========================================================================
1330 -
1331 - $_REQUEST['searchIn'] = "searchIn";
1332 - $tableName = $wpdb->prefix."usces_order";
1333 - $arr_column = array(
1334 - __('ID', 'usces') => 'ID',
1335 - __('Order number', 'usces') => 'deco_id',
1336 - __('date', 'usces') => 'date',
1337 - __('membership number', 'usces') => 'mem_id',
1338 - __('name', 'usces') => 'name',
1339 - __('Region', 'usces') => 'pref',
1340 - __('shipping option', 'usces') => 'delivery_method',
1341 - __('Amount', 'usces') => 'total_price',
1342 - __('payment method', 'usces') => 'payment_name',
1343 - __('transfer statement', 'usces') => 'receipt_status',
1344 - __('Processing', 'usces') => 'order_status',
1345 - __('shpping date', 'usces') => 'order_modified');
1346 - $DT = new dataList($tableName, $arr_column);
1347 -//20101202ysk start
1348 - $DT->pageLimit = 'off';
1349 -//20101202ysk end
1350 - $res = $DT->MakeTable();
1351 - $rows = $DT->rows;
1352 -
1353 - //==========================================================================
1354 - $line = $table_h;
1355 - $line .= $tr_h;
1356 - $line .= $th_h1.__('ID', 'usces').$th_f;
1357 - $line .= $th_h.__('Order number', 'usces').$th_f;
1358 - if(isset($_REQUEST['check']['date'])) $line .= $th_h.__('order date', 'usces').$th_f;
1359 - if(isset($_REQUEST['check']['mem_id'])) $line .= $th_h.__('membership number', 'usces').$th_f;
1360 - if(isset($_REQUEST['check']['name'])) $line .= $th_h.__('name', 'usces').$th_f;
1361 - if(isset($_REQUEST['check']['delivery_method'])) $line .= $th_h.__('shipping option', 'usces').$th_f;
1362 - if(isset($_REQUEST['check']['shipping_date'])) $line .= $th_h.__('shpping date', 'usces').$th_f;
1363 - $line .= apply_filters( 'usces_filter_chk_pro_label_head', NULL, $usces_opt_order, $rows);
1364 - $line .= $th_h.__('item code', 'usces').$th_f;
1365 - $line .= $th_h.__('SKU code', 'usces').$th_f;
1366 - if(isset($_REQUEST['check']['item_name'])) $line .= $th_h.__('item name', 'usces').$th_f;
1367 - if(isset($_REQUEST['check']['sku_name'])) $line .= $th_h.__('SKU display name ', 'usces').$th_f;
1368 - if(isset($_REQUEST['check']['options'])) $line .= $th_h.__('options for items', 'usces').$th_f;
1369 - $line .= $th_h.__('Quantity', 'usces').$th_f;
1370 - $line .= $th_h.__('Unit price', 'usces').$th_f;
1371 - if(isset($_REQUEST['check']['unit'])) $line .= $th_h.__('unit', 'usces').$th_f;
1372 - $line .= apply_filters( 'usces_filter_chk_pro_label_detail', NULL, $usces_opt_order, $rows);
1373 - $line .= $tr_f.$lf;
1374 - //==========================================================================
1375 - foreach((array)$rows as $array) {
1376 - $order_id = $array['ID'];
1377 - $query = $wpdb->prepare("SELECT * FROM $tableName WHERE ID = %d", $order_id);
1378 - $data = $wpdb->get_row( $query, ARRAY_A );
1379 - //$cart = stripslashes_deep(unserialize($data['order_cart']));
1380 - $cart = unserialize($data['order_cart']);
1381 - //if(!empty($data)) {
1382 - // $data = stripslashes_deep($data);
1383 - //}
1384 - for($i = 0; $i < count($cart); $i++) {
1385 - $cart_row = $cart[$i];
1386 - $post_id = $cart_row['post_id'];
1387 - $sku = urldecode($cart_row['sku']);
1388 -
1389 - $line .= $tr_h;
1390 - $line .= $td_h1.$order_id.$td_f;
1391 - $line .= $td_h.$array['deco_id'].$td_f;
1392 - if(isset($_REQUEST['check']['date'])) $line .= $td_h.$array['date'].$td_f;
1393 - if(isset($_REQUEST['check']['mem_id'])) $line .= $td_h.$array['mem_id'].$td_f;
1394 - if(isset($_REQUEST['check']['name'])) $line .= $td_h.usces_entity_decode($data['order_name1'].$data['order_name2'], $ext).$td_f;
1395 - if(isset($_REQUEST['check']['delivery_method'])) {
1396 - $delivery_method = '';
1397 - if(strtoupper($data['order_delivery_method']) == '#NONE#') {
1398 - $delivery_method = __('No preference', 'usces');
1399 - } else {
1400 - foreach((array)$usces->options['delivery_method'] as $dkey => $delivery) {
1401 - if($delivery['id'] == $data['order_delivery_method']) {
1402 - $delivery_method = $delivery['name'];
1403 - break;
1404 - }
1405 - }
1406 - }
1407 - $line .= $td_h.$delivery_method.$td_f;
1408 - }
1409 - if(isset($_REQUEST['check']['shipping_date'])) $line .= $td_h.$data['order_modified'].$td_f;
1410 - $line .= apply_filters( 'usces_filter_chk_pro_data_head', NULL, $usces_opt_order, $data, $cart_row);
1411 -
1412 - $line .= $td_h.$usces->getItemCode($post_id).$td_f;
1413 - $line .= $td_h.$sku.$td_f;
1414 - if(isset($_REQUEST['check']['item_name'])) $line .= $td_h.usces_entity_decode($usces->getItemName($post_id), $ext).$td_f;
1415 - if(isset($_REQUEST['check']['sku_name'])) $line .= $td_h.usces_entity_decode($usces->getItemSkuDisp($post_id, $sku), $ext).$td_f;
1416 - if(isset($_REQUEST['check']['options'])) {
1417 - $options = $cart_row['options'];
1418 - $optstr = '';
1419 - if(is_array($options) && count($options) > 0) {
1420 - foreach((array)$options as $key => $value) {
1421 - if(!empty($key)) {
1422 - if(is_array($value)) {
1423 - foreach($value as $v) {
1424 - $optstr .= usces_entity_decode(urldecode($key), $ext).$sp;
1425 - foreach($value as $v) {
1426 - $optstr .= usces_entity_decode(urldecode($v), $ext).$nb;
1427 - }
1428 - }
1429 - } else {
1430 - //$optstr .= usces_entity_decode($key, $ext).$sp.usces_entity_decode($value, $ext).$nb;
1431 - $optstr .= usces_entity_decode(urldecode($key).$sp.urldecode($value), $ext).$nb;
1432 - }
1433 - }
1434 - }
1435 - }
1436 - $line .= $td_h.$optstr.$td_f;
1437 - }
1438 - $line .= $td_h.$cart_row['quantity'].$td_f;
1439 - $line .= $td_h.usces_crform($cart_row['price'], false, false, 'return', false).$td_f;
1440 - if(isset($_REQUEST['check']['unit'])) $line .= $td_h.usces_entity_decode($usces->getItemSkuUnit($post_id, $sku), $ext).$td_f;
1441 - $line .= apply_filters( 'usces_filter_chk_pro_data_detail', NULL, $usces_opt_order, $data, $cart_row);
1442 - $line .= $tr_f.$lf;
1443 - }
1444 - }
1445 - $line .= $table_f.$lf;
1446 - //==========================================================================
1447 -
1448 - if($ext == 'xls') {
1449 - header("Content-Type: application/vnd.ms-excel; charset=Shift-JIS");
1450 - } elseif($ext == 'csv') {
1451 - header("Content-Type: application/octet-stream");
1452 - }
1453 - header("Content-Disposition: attachment; filename=usces_product_list.".$ext);
1454 - mb_http_output('pass');
1455 - print(mb_convert_encoding($line, "SJIS-win", "UTF-8"));
1456 - exit();
1457 -}
1458 -
1459 -// order list download
1460 -function usces_download_order_list() {
1461 - require_once( USCES_PLUGIN_DIR . "/classes/orderList.class.php" );
1462 - global $wpdb, $usces;
1463 -//20110411ysk start
1464 - global $usces_settings;
1465 -//20110411ysk end
1466 -
1467 - $ext = $_REQUEST['ftype'];
1468 -/* if($ext == 'xls') {//HTML
1469 - $table_h = "<table>";
1470 - $table_f = "</table>";
1471 - $tr_h = "<tr>";
1472 - $tr_f = "</tr>";
1473 - $th_h1 = "<th>";
1474 - $th_h = "<th>";
1475 - $th_f = "</th>";
1476 - $td_h1 = "<td>";
1477 - $td_h = "<td>";
1478 - $td_f = "</td>";
1479 - $sp = ":";
1480 - $lf = "\n";
1481 -*/ if($ext == 'xls') {//TSV
1482 - $table_h = "";
1483 - $table_f = "";
1484 - $tr_h = "";
1485 - $tr_f = "";
1486 - $th_h1 = '"';
1487 - $th_h = "\t".'"';
1488 - $th_f = '"';
1489 - $td_h1 = '"';
1490 - $td_h = "\t".'"';
1491 - $td_f = '"';
1492 - $sp = ":";
1493 - $lf = "\n";
1494 - } elseif($ext == 'csv') {//CSV
1495 - $table_h = "";
1496 - $table_f = "";
1497 - $tr_h = "";
1498 - $tr_f = "";
1499 -//20110201ysk start
1500 - //$th_h1 = "";
1501 - $th_h1 = '"';
1502 - //$th_h = ",";
1503 - $th_h = ',"';
1504 - //$th_f = "";
1505 - $th_f = '"';
1506 - //$td_h1 = "";
1507 - $td_h1 = '"';
1508 - //$td_h = ",";
1509 - $td_h = ',"';
1510 - //$td_f = "";
1511 - $td_f = '"';
1512 -//20110201ysk end
1513 - $sp = ":";
1514 - $lf = "\n";
1515 - } else {
1516 - exit();
1517 - }
1518 - $csod_meta = usces_has_custom_field_meta('order');
1519 - $cscs_meta = usces_has_custom_field_meta('customer');
1520 - $csde_meta = usces_has_custom_field_meta('delivery');
1521 -//20110411ysk start
1522 - $applyform = usces_get_apply_addressform($usces->options['system']['addressform']);
1523 -//20110411ysk end
1524 -
1525 - //==========================================================================
1526 - $usces_opt_order = get_option('usces_opt_order');
1527 - if(!is_array($usces_opt_order)){
1528 - $usces_opt_order = array();
1529 - }
1530 - $usces_opt_order['ftype_ord'] = $ext;
1531 - $chk_ord = array();
1532 - $chk_ord['ID'] = 1;
1533 - $chk_ord['deco_id'] = 1;
1534 - $chk_ord['date'] = 1;
1535 - $chk_ord['mem_id'] = (isset($_REQUEST['check']['mem_id'])) ? 1 : 0;
1536 - $chk_ord['email'] = (isset($_REQUEST['check']['email'])) ? 1 : 0;
1537 - if(!empty($cscs_meta)) {
1538 - foreach($cscs_meta as $key => $entry) {
1539 - if($entry['position'] == 'name_pre') {
1540 - $name = $entry['name'];
1541 -//20110208ysk start
1542 - $cscs_key = 'cscs_'.$key;
1543 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1544 - $chk_ord[$cscs_key] = (isset($_REQUEST['check'][$cscs_key])) ? 1 : 0;
1545 -//20110208ysk end
1546 - }
1547 - }
1548 - }
1549 - $chk_ord['name'] = 1;
1550 -//20110411ysk start
1551 - if($applyform == 'JP') {
1552 - $chk_ord['kana'] = (isset($_REQUEST['check']['kana'])) ? 1 : 0;
1553 - }
1554 -//20110411ysk end
1555 - if(!empty($cscs_meta)) {
1556 - foreach($cscs_meta as $key => $entry) {
1557 - if($entry['position'] == 'name_after') {
1558 - $name = $entry['name'];
1559 -//20110208ysk start
1560 - $cscs_key = 'cscs_'.$key;
1561 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1562 - $chk_ord[$cscs_key] = (isset($_REQUEST['check'][$cscs_key])) ? 1 : 0;
1563 -//20110208ysk end
1564 - }
1565 - }
1566 - }
1567 - $chk_ord['zip'] = (isset($_REQUEST['check']['zip'])) ? 1 : 0;
1568 -//20110411ysk start
1569 - $chk_ord['country'] = (isset($_REQUEST['check']['country'])) ? 1 : 0;
1570 -//20110411ysk end
1571 - $chk_ord['pref'] = (isset($_REQUEST['check']['pref'])) ? 1 : 0;
1572 - $chk_ord['address1'] = (isset($_REQUEST['check']['address1'])) ? 1 : 0;
1573 - $chk_ord['address2'] = (isset($_REQUEST['check']['address2'])) ? 1 : 0;
1574 - $chk_ord['address3'] = (isset($_REQUEST['check']['address3'])) ? 1 : 0;
1575 - $chk_ord['tel'] = (isset($_REQUEST['check']['tel'])) ? 1 : 0;
1576 - $chk_ord['fax'] = (isset($_REQUEST['check']['fax'])) ? 1 : 0;
1577 - if(!empty($cscs_meta)) {
1578 - foreach($cscs_meta as $key => $entry) {
1579 - if($entry['position'] == 'fax_after') {
1580 - $name = $entry['name'];
1581 -//20110208ysk start
1582 - $cscs_key = 'cscs_'.$key;
1583 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1584 - $chk_ord[$cscs_key] = (isset($_REQUEST['check'][$cscs_key])) ? 1 : 0;
1585 -//20110208ysk end
1586 - }
1587 - }
1588 - }
1589 - //--------------------------------------------------------------------------
1590 - if(!empty($csde_meta)) {
1591 - foreach($csde_meta as $key => $entry) {
1592 - if($entry['position'] == 'name_pre') {
1593 - $name = $entry['name'];
1594 -//20110208ysk start
1595 - $csde_key = 'csde_'.$key;
1596 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1597 - $chk_ord[$csde_key] = (isset($_REQUEST['check'][$csde_key])) ? 1 : 0;
1598 -//20110208ysk end
1599 - }
1600 - }
1601 - }
1602 - $chk_ord['delivery_name'] = (isset($_REQUEST['check']['delivery_name'])) ? 1 : 0;
1603 -//20110411ysk start
1604 - if($applyform == 'JP') {
1605 - $chk_ord['delivery_kana'] = (isset($_REQUEST['check']['delivery_kana'])) ? 1 : 0;
1606 - }
1607 -//20110411ysk end
1608 - if(!empty($csde_meta)) {
1609 - foreach($csde_meta as $key => $entry) {
1610 - if($entry['position'] == 'name_after') {
1611 - $name = $entry['name'];
1612 -//20110208ysk start
1613 - $csde_key = 'csde_'.$key;
1614 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1615 - $chk_ord[$csde_key] = (isset($_REQUEST['check'][$csde_key])) ? 1 : 0;
1616 -//20110208ysk end
1617 - }
1618 - }
1619 - }
1620 - $chk_ord['delivery_zip'] = (isset($_REQUEST['check']['delivery_zip'])) ? 1 : 0;
1621 -//20110411ysk start
1622 - $chk_ord['delivery_country'] = (isset($_REQUEST['check']['delivery_country'])) ? 1 : 0;
1623 -//20110411ysk end
1624 - $chk_ord['delivery_pref'] = (isset($_REQUEST['check']['delivery_pref'])) ? 1 : 0;
1625 - $chk_ord['delivery_address1'] = (isset($_REQUEST['check']['delivery_address1'])) ? 1 : 0;
1626 - $chk_ord['delivery_address2'] = (isset($_REQUEST['check']['delivery_address2'])) ? 1 : 0;
1627 - $chk_ord['delivery_address3'] = (isset($_REQUEST['check']['delivery_address3'])) ? 1 : 0;
1628 - $chk_ord['delivery_tel'] = (isset($_REQUEST['check']['delivery_tel'])) ? 1 : 0;
1629 - $chk_ord['delivery_fax'] = (isset($_REQUEST['check']['delivery_fax'])) ? 1 : 0;
1630 - if(!empty($csde_meta)) {
1631 - foreach($csde_meta as $key => $entry) {
1632 - if($entry['position'] == 'fax_after') {
1633 - $name = $entry['name'];
1634 -//20110208ysk start
1635 - $csde_key = 'csde_'.$key;
1636 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1637 - $chk_ord[$csde_key] = (isset($_REQUEST['check'][$csde_key])) ? 1 : 0;
1638 -//20110208ysk end
1639 - }
1640 - }
1641 - }
1642 - //--------------------------------------------------------------------------
1643 - $chk_ord['shipping_date'] = (isset($_REQUEST['check']['shipping_date'])) ? 1 : 0;
1644 - $chk_ord['peyment_method'] = (isset($_REQUEST['check']['peyment_method'])) ? 1 : 0;
1645 - $chk_ord['delivery_method'] = (isset($_REQUEST['check']['delivery_method'])) ? 1 : 0;
1646 -//20101208ysk start
1647 - $chk_ord['delivery_date'] = (isset($_REQUEST['check']['delivery_date'])) ? 1 : 0;
1648 -//20101208ysk end
1649 - $chk_ord['delivery_time'] = (isset($_REQUEST['check']['delivery_time'])) ? 1 : 0;
1650 - $chk_ord['delidue_date'] = (isset($_REQUEST['check']['delidue_date'])) ? 1 : 0;
1651 - $chk_ord['status'] = (isset($_REQUEST['check']['status'])) ? 1 : 0;
1652 - $chk_ord['total_amount'] = 1;
1653 - $chk_ord['getpoint'] = (isset($_REQUEST['check']['getpoint'])) ? 1 : 0;
1654 - $chk_ord['usedpoint'] = (isset($_REQUEST['check']['usedpoint'])) ? 1 : 0;
1655 - $chk_ord['discount'] = 1;
1656 - $chk_ord['shipping_charge'] = 1;
1657 - $chk_ord['cod_fee'] = 1;
1658 - $chk_ord['tax'] = 1;
1659 - $chk_ord['note'] = (isset($_REQUEST['check']['note'])) ? 1 : 0;
1660 - if(!empty($csod_meta)) {
1661 - foreach($csod_meta as $key => $entry) {
1662 - $name = $entry['name'];
1663 -//20110208ysk start
1664 - $csod_key = 'csod_'.$key;
1665 - //$chk_ord[$name] = (isset($_REQUEST['check'][$name])) ? 1 : 0;
1666 - $chk_ord[$csod_key] = (isset($_REQUEST['check'][$csod_key])) ? 1 : 0;
1667 -//20110208ysk end
1668 - }
1669 - }
1670 - $usces_opt_order['chk_ord'] = apply_filters( 'usces_filter_chk_ord', $chk_ord );
1671 - update_option('usces_opt_order', $usces_opt_order);
1672 - //==========================================================================
1673 -
1674 - if(isset($_REQUEST['check']['status'])) {
1675 - //$usces_management_status = get_option('usces_management_status');
1676 - $usces_management_status = apply_filters( 'usces_filter_management_status', get_option('usces_management_status') );//0000530
1677 - $usces_management_status['new'] = __('new order', 'usces');
1678 - }
1679 -
1680 - $_REQUEST['searchIn'] = "searchIn";
1681 - $tableName = $wpdb->prefix."usces_order";
1682 - $arr_column = array(
1683 - __('ID', 'usces') => 'ID',
1684 - __('Order number', 'usces') => 'deco_id',
1685 - __('date', 'usces') => 'date',
1686 - __('membership number', 'usces') => 'mem_id',
1687 - __('name', 'usces') => 'name',
1688 - __('Region', 'usces') => 'pref',
1689 - __('shipping option', 'usces') => 'delivery_method',
1690 - __('Amount', 'usces') => 'total_price',
1691 - __('payment method', 'usces') => 'payment_name',
1692 - __('transfer statement', 'usces') => 'receipt_status',
1693 - __('Processing', 'usces') => 'order_status',
1694 - __('shpping date', 'usces') => 'order_modified');
1695 - $DT = new dataList($tableName, $arr_column);
1696 -//20101202ysk start
1697 - $DT->pageLimit = 'off';
1698 -//20101202ysk end
1699 - $res = $DT->MakeTable();
1700 - $rows = $DT->rows;
1701 -
1702 - //==========================================================================
1703 - $line = $table_h;
1704 - $line .= $tr_h;
1705 - $line .= $th_h1.__('ID', 'usces').$th_f;
1706 - $line .= $th_h.__('Order number', 'usces').$th_f;
1707 - $line .= $th_h.__('order date', 'usces').$th_f;
1708 - if(isset($_REQUEST['check']['mem_id'])) $line .= $th_h.__('membership number', 'usces').$th_f;
1709 - if(isset($_REQUEST['check']['email'])) $line .= $th_h.__('e-mail', 'usces').$th_f;
1710 - if(!empty($cscs_meta)) {
1711 - foreach($cscs_meta as $key => $entry) {
1712 - if($entry['position'] == 'name_pre') {
1713 - $name = $entry['name'];
1714 -//20110208ysk start
1715 - $cscs_key = 'cscs_'.$key;
1716 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1717 - if(isset($_REQUEST['check'][$cscs_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1718 -//20110208ysk end
1719 - }
1720 - }
1721 - }
1722 - $line .= $th_h.__('name', 'usces').$th_f;
1723 -//20110411ysk start
1724 - if($applyform == 'JP') {
1725 - if(isset($_REQUEST['check']['kana'])) $line .= $th_h.__('furigana', 'usces').$th_f;
1726 - }
1727 -//20110411ysk end
1728 - if(!empty($cscs_meta)) {
1729 - foreach($cscs_meta as $key => $entry) {
1730 - if($entry['position'] == 'name_after') {
1731 - $name = $entry['name'];
1732 -//20110208ysk start
1733 - $cscs_key = 'cscs_'.$key;
1734 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1735 - if(isset($_REQUEST['check'][$cscs_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1736 -//20110208ysk end
1737 - }
1738 - }
1739 - }
1740 -//20110411ysk start
1741 - switch($applyform) {
1742 - case 'JP':
1743 - if(isset($_REQUEST['check']['zip'])) $line .= $th_h.__('Zip/Postal Code', 'usces').$th_f;
1744 - if(isset($_REQUEST['check']['country'])) $line .= $th_h.__('Country', 'usces').$th_f;
1745 - if(isset($_REQUEST['check']['pref'])) $line .= $th_h.__('Province', 'usces').$th_f;
1746 - if(isset($_REQUEST['check']['address1'])) $line .= $th_h.__('city', 'usces').$th_f;
1747 - if(isset($_REQUEST['check']['address2'])) $line .= $th_h.__('numbers', 'usces').$th_f;
1748 - if(isset($_REQUEST['check']['address3'])) $line .= $th_h.__('building name', 'usces').$th_f;
1749 - if(isset($_REQUEST['check']['tel'])) $line .= $th_h.__('Phone number', 'usces').$th_f;
1750 - if(isset($_REQUEST['check']['fax'])) $line .= $th_h.__('FAX number', 'usces').$th_f;
1751 - break;
1752 - case 'US':
1753 - default:
1754 - if(isset($_REQUEST['check']['address2'])) $line .= $th_h.__('Address Line1', 'usces').$th_f;
1755 - if(isset($_REQUEST['check']['address3'])) $line .= $th_h.__('Address Line2', 'usces').$th_f;
1756 - if(isset($_REQUEST['check']['address1'])) $line .= $th_h.__('city', 'usces').$th_f;
1757 - if(isset($_REQUEST['check']['pref'])) $line .= $th_h.__('State', 'usces').$th_f;
1758 - if(isset($_REQUEST['check']['country'])) $line .= $th_h.__('Country', 'usces').$th_f;
1759 - if(isset($_REQUEST['check']['zip'])) $line .= $th_h.__('Zip', 'usces').$th_f;
1760 - if(isset($_REQUEST['check']['tel'])) $line .= $th_h.__('Phone number', 'usces').$th_f;
1761 - if(isset($_REQUEST['check']['fax'])) $line .= $th_h.__('FAX number', 'usces').$th_f;
1762 - break;
1763 - }
1764 -//20110411ysk end
1765 - if(!empty($cscs_meta)) {
1766 - foreach($cscs_meta as $key => $entry) {
1767 - if($entry['position'] == 'fax_after') {
1768 - $name = $entry['name'];
1769 -//20110208ysk start
1770 - $cscs_key = 'cscs_'.$key;
1771 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1772 - if(isset($_REQUEST['check'][$cscs_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1773 -//20110208ysk end
1774 - }
1775 - }
1776 - }
1777 - $line .= apply_filters( 'usces_filter_chk_ord_label_customer', NULL, $usces_opt_order, $rows );
1778 -
1779 - //--------------------------------------------------------------------------
1780 - if(!empty($csde_meta)) {
1781 - foreach($csde_meta as $key => $entry) {
1782 - if($entry['position'] == 'name_pre') {
1783 - $name = $entry['name'];
1784 -//20110208ysk start
1785 - $csde_key = 'csde_'.$key;
1786 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1787 - if(isset($_REQUEST['check'][$csde_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1788 -//20110208ysk end
1789 - }
1790 - }
1791 - }
1792 - if(isset($_REQUEST['check']['delivery_name'])) $line .= $th_h.__('Shipping Name', 'usces').$th_f;
1793 -//20110411ysk start
1794 - if($applyform == 'JP') {
1795 - if(isset($_REQUEST['check']['delivery_kana'])) $line .= $th_h.__('Shipping Furigana', 'usces').$th_f;
1796 - }
1797 -//20110411ysk end
1798 - if(!empty($csde_meta)) {
1799 - foreach($csde_meta as $key => $entry) {
1800 - if($entry['position'] == 'name_after') {
1801 - $name = $entry['name'];
1802 -//20110208ysk start
1803 - $csde_key = 'csde_'.$key;
1804 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1805 - if(isset($_REQUEST['check'][$csde_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1806 -//20110208ysk end
1807 - }
1808 - }
1809 - }
1810 -//20110411ysk start
1811 - switch($applyform) {
1812 - case 'JP':
1813 - if(isset($_REQUEST['check']['delivery_zip'])) $line .= $th_h.__('Shipping Zip', 'usces').$th_f;
1814 - if(isset($_REQUEST['check']['delivery_country'])) $line .= $th_h.__('Shipping Country', 'usces').$th_f;
1815 - if(isset($_REQUEST['check']['delivery_pref'])) $line .= $th_h.__('Shipping State', 'usces').$th_f;
1816 - if(isset($_REQUEST['check']['delivery_address1'])) $line .= $th_h.__('Shipping City', 'usces').$th_f;
1817 - if(isset($_REQUEST['check']['delivery_address2'])) $line .= $th_h.__('Shipping Address1', 'usces').$th_f;
1818 - if(isset($_REQUEST['check']['delivery_address3'])) $line .= $th_h.__('Shipping Address2', 'usces').$th_f;
1819 - if(isset($_REQUEST['check']['delivery_tel'])) $line .= $th_h.__('Shipping Phone', 'usces').$th_f;
1820 - if(isset($_REQUEST['check']['delivery_fax'])) $line .= $th_h.__('Shipping FAX', 'usces').$th_f;
1821 - break;
1822 - case 'US':
1823 - default:
1824 - if(isset($_REQUEST['check']['delivery_address2'])) $line .= $th_h.__('Shipping Address1', 'usces').$th_f;
1825 - if(isset($_REQUEST['check']['delivery_address3'])) $line .= $th_h.__('Shipping Address2', 'usces').$th_f;
1826 - if(isset($_REQUEST['check']['delivery_address1'])) $line .= $th_h.__('Shipping City', 'usces').$th_f;
1827 - if(isset($_REQUEST['check']['delivery_pref'])) $line .= $th_h.__('Shipping State', 'usces').$th_f;
1828 - if(isset($_REQUEST['check']['delivery_country'])) $line .= $th_h.__('Shipping Country', 'usces').$th_f;
1829 - if(isset($_REQUEST['check']['delivery_zip'])) $line .= $th_h.__('Shipping Zip', 'usces').$th_f;
1830 - if(isset($_REQUEST['check']['delivery_tel'])) $line .= $th_h.__('Shipping Phone', 'usces').$th_f;
1831 - if(isset($_REQUEST['check']['delivery_fax'])) $line .= $th_h.__('Shipping FAX', 'usces').$th_f;
1832 - break;
1833 - }
1834 -//20110411ysk end
1835 - if(!empty($csde_meta)) {
1836 - foreach($csde_meta as $key => $entry) {
1837 - if($entry['position'] == 'fax_after') {
1838 - $name = $entry['name'];
1839 -//20110208ysk start
1840 - $csde_key = 'csde_'.$key;
1841 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1842 - if(isset($_REQUEST['check'][$csde_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1843 -//20110208ysk end
1844 - }
1845 - }
1846 - }
1847 - $line .= apply_filters( 'usces_filter_chk_ord_label_delivery', NULL, $usces_opt_order, $rows );
1848 - //--------------------------------------------------------------------------
1849 - if(isset($_REQUEST['check']['shipping_date'])) $line .= $th_h.__('shpping date', 'usces').$th_f;
1850 - if(isset($_REQUEST['check']['peyment_method'])) $line .= $th_h.__('payment method', 'usces').$th_f;
1851 - if(isset($_REQUEST['check']['delivery_method'])) $line .= $th_h.__('shipping option', 'usces').$th_f;
1852 -//20101208ysk start
1853 - if(isset($_REQUEST['check']['delivery_date'])) $line .= $th_h.__('Delivery date', 'usces').$th_f;
1854 -//20101208ysk end
1855 - if(isset($_REQUEST['check']['delivery_time'])) $line .= $th_h.__('delivery time', 'usces').$th_f;
1856 - if(isset($_REQUEST['check']['delidue_date'])) $line .= $th_h.__('Shipping date', 'usces').$th_f;
1857 - if(isset($_REQUEST['check']['status'])) $line .= $th_h.__('Status', 'usces').$th_f;
1858 - $line .= $th_h.__('Total Amount', 'usces').$th_f;
1859 - if(isset($_REQUEST['check']['getpoint'])) $line .= $th_h.__('granted points', 'usces').$th_f;
1860 - if(isset($_REQUEST['check']['usedpoint'])) $line .= $th_h.__('Used points', 'usces').$th_f;
1861 - $line .= $th_h.__('Disnount', 'usces').$th_f;
1862 - $line .= $th_h.__('Shipping', 'usces').$th_f;
1863 - $line .= $th_h.apply_filters('usces_filter_cod_label', __('COD fee', 'usces')).$th_f;
1864 - $line .= $th_h.__('consumption tax', 'usces').$th_f;
1865 - if(isset($_REQUEST['check']['note'])) $line .= $th_h.__('Notes', 'usces').$th_f;
1866 - if(!empty($csod_meta)) {
1867 - foreach($csod_meta as $key => $entry) {
1868 - $name = $entry['name'];
1869 -//20110208ysk start
1870 - $csod_key = 'csod_'.$key;
1871 - //if(isset($_REQUEST['check'][$name])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1872 - if(isset($_REQUEST['check'][$csod_key])) $line .= $th_h.usces_entity_decode($name, $ext).$th_f;
1873 -//20110208ysk end
1874 - }
1875 - }
1876 - $line .= apply_filters( 'usces_filter_chk_ord_label_order', NULL, $usces_opt_order, $rows );
1877 - $line .= $tr_f.$lf;
1878 - //==========================================================================
1879 - foreach((array)$rows as $array) {
1880 - $order_id = $array['ID'];
1881 - $query = $wpdb->prepare("SELECT * FROM $tableName WHERE ID = %d", $order_id);
1882 - $data = $wpdb->get_row( $query, ARRAY_A );
1883 - //$deli = stripslashes_deep(unserialize($data['order_delivery']));
1884 - $deli = unserialize($data['order_delivery']);
1885 - //if(!empty($data)) {
1886 - // $data = stripslashes_deep($data);
1887 - //}
1888 -
1889 - $line .= $tr_h;
1890 - $line .= $td_h1.$order_id.$td_f;
1891 - $line .= $td_h.usces_get_deco_order_id( $order_id ).$td_f;
1892 - $line .= $td_h.$data['order_date'].$td_f;
1893 - if(isset($_REQUEST['check']['mem_id'])) $line .= $td_h.$data['mem_id'].$td_f;
1894 - if(isset($_REQUEST['check']['email'])) $line .= $td_h.usces_entity_decode($data['order_email'], $ext).$td_f;
1895 - if(!empty($cscs_meta)) {
1896 - foreach($cscs_meta as $key => $entry) {
1897 - if($entry['position'] == 'name_pre') {
1898 - $name = $entry['name'];
1899 - $cscs_key = 'cscs_'.$key;
1900 -//20110208ysk start
1901 - //if(isset($_REQUEST['check'][$name])) {
1902 - if(isset($_REQUEST['check'][$cscs_key])) {
1903 -//20110208ysk end
1904 - $value = maybe_unserialize($usces->get_order_meta_value($cscs_key, $order_id));
1905 - if(empty($value)) {
1906 - $value = '';
1907 - } elseif(is_array($value)) {
1908 - $concatval = '';
1909 - $c = '';
1910 - foreach($value as $v) {
1911 - $concatval .= $c.$v;
1912 - $c = ' ';
1913 - }
1914 - $value = $concatval;
1915 - }
1916 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
1917 - }
1918 - }
1919 - }
1920 - }
1921 -//20110411ysk start
1922 - switch($applyform) {
1923 - case 'JP':
1924 - $line .= $td_h.usces_entity_decode($data['order_name1'].' '.$data['order_name2'], $ext).$td_f;
1925 - if(isset($_REQUEST['check']['kana'])) $line .= $td_h.usces_entity_decode($data['order_name3'].' '.$data['order_name4'], $ext).$td_f;
1926 - break;
1927 - case 'US':
1928 - default:
1929 - $line .= $td_h.usces_entity_decode($data['order_name2'].' '.$data['order_name1'], $ext).$td_f;
1930 - break;
1931 - }
1932 -//20110411ysk end
1933 - if(!empty($cscs_meta)) {
1934 - foreach($cscs_meta as $key => $entry) {
1935 - if($entry['position'] == 'name_after') {
1936 - $name = $entry['name'];
1937 - $cscs_key = 'cscs_'.$key;
1938 -//20110208ysk start
1939 - //if(isset($_REQUEST['check'][$name])) {
1940 - if(isset($_REQUEST['check'][$cscs_key])) {
1941 -//20110208ysk end
1942 - $value = maybe_unserialize($usces->get_order_meta_value($cscs_key, $order_id));
1943 - if(empty($value)) {
1944 - $value = '';
1945 - } elseif(is_array($value)) {
1946 - $concatval = '';
1947 - $c = '';
1948 - foreach($value as $v) {
1949 - $concatval .= $c.$v;
1950 - $c = ' ';
1951 - }
1952 - $value = $concatval;
1953 - }
1954 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
1955 - }
1956 - }
1957 - }
1958 - }
1959 -//20110411ysk start
1960 - $address_info = '';
1961 - switch($applyform) {
1962 - case 'JP':
1963 - if(isset($_REQUEST['check']['zip'])) $address_info .= $td_h.usces_entity_decode($data['order_zip'], $ext).$td_f;
1964 - if(isset($_REQUEST['check']['country'])) $address_info .= $td_h.$usces_settings['country'][$usces->get_order_meta_value('customer_country', $order_id)].$td_f;
1965 - if(isset($_REQUEST['check']['pref'])) $address_info .= $td_h.usces_entity_decode($data['order_pref'], $ext).$td_f;
1966 - if(isset($_REQUEST['check']['address1'])) $address_info .= $td_h.usces_entity_decode($data['order_address1'], $ext).$td_f;
1967 - if(isset($_REQUEST['check']['address2'])) $address_info .= $td_h.usces_entity_decode($data['order_address2'], $ext).$td_f;
1968 - if(isset($_REQUEST['check']['address3'])) $address_info .= $td_h.usces_entity_decode($data['order_address3'], $ext).$td_f;
1969 - if(isset($_REQUEST['check']['tel'])) $address_info .= $td_h.usces_entity_decode($data['order_tel'], $ext).$td_f;
1970 - if(isset($_REQUEST['check']['fax'])) $address_info .= $td_h.usces_entity_decode($data['order_fax'], $ext).$td_f;
1971 - break;
1972 - case 'US':
1973 - default:
1974 - if(isset($_REQUEST['check']['address2'])) $address_info .= $td_h.usces_entity_decode($data['order_address2'], $ext).$td_f;
1975 - if(isset($_REQUEST['check']['address3'])) $address_info .= $td_h.usces_entity_decode($data['order_address3'], $ext).$td_f;
1976 - if(isset($_REQUEST['check']['address1'])) $address_info .= $td_h.usces_entity_decode($data['order_address1'], $ext).$td_f;
1977 - if(isset($_REQUEST['check']['pref'])) $address_info .= $td_h.usces_entity_decode($data['order_pref'], $ext).$td_f;
1978 - if(isset($_REQUEST['check']['country'])) $address_info .= $td_h.$usces_settings['country'][$usces->get_order_meta_value('customer_country', $order_id)].$td_f;
1979 - if(isset($_REQUEST['check']['zip'])) $address_info .= $td_h.usces_entity_decode($data['order_zip'], $ext).$td_f;
1980 - if(isset($_REQUEST['check']['tel'])) $address_info .= $td_h.usces_entity_decode($data['order_tel'], $ext).$td_f;
1981 - if(isset($_REQUEST['check']['fax'])) $address_info .= $td_h.usces_entity_decode($data['order_fax'], $ext).$td_f;
1982 - break;
1983 - }
1984 - $address_info_args = compact( 'td_h', 'td_f', 'ext', 'order_id', 'applyform' );
1985 - $line .= apply_filters( 'usces_filter_ord_csv_address_info', $address_info, $data, $address_info_args );
1986 -//20110411ysk end
1987 - if(!empty($cscs_meta)) {
1988 - foreach($cscs_meta as $key => $entry) {
1989 - if($entry['position'] == 'fax_after') {
1990 - $name = $entry['name'];
1991 - $cscs_key = 'cscs_'.$key;
1992 -//20110208ysk start
1993 - //if(isset($_REQUEST['check'][$name])) {
1994 - if(isset($_REQUEST['check'][$cscs_key])) {
1995 -//20110208ysk end
1996 - $value = maybe_unserialize($usces->get_order_meta_value($cscs_key, $order_id));
1997 - if(empty($value)) {
1998 - $value = '';
1999 - } elseif(is_array($value)) {
2000 - $concatval = '';
2001 - $c = '';
2002 - foreach($value as $v) {
2003 - $concatval .= $c.$v;
2004 - $c = ' ';
2005 - }
2006 - $value = $concatval;
2007 - }
2008 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
2009 - }
2010 - }
2011 - }
2012 - }
2013 - $line .= apply_filters( 'usces_filter_chk_ord_data_customer', NULL, $usces_opt_order, $order_id, $data );
2014 - //----------------------------------------------------------------------
2015 - if(!empty($csde_meta)) {
2016 - foreach($csde_meta as $key => $entry) {
2017 - if($entry['position'] == 'name_pre') {
2018 - $name = $entry['name'];
2019 - $csde_key = 'csde_'.$key;
2020 -//20110208ysk start
2021 - //if(isset($_REQUEST['check'][$name])) {
2022 - if(isset($_REQUEST['check'][$csde_key])) {
2023 -//20110208ysk end
2024 - $value = maybe_unserialize($usces->get_order_meta_value($csde_key, $order_id));
2025 - if(empty($value)) {
2026 - $value = '';
2027 - } elseif(is_array($value)) {
2028 - $concatval = '';
2029 - $c = '';
2030 - foreach($value as $v) {
2031 - $concatval .= $c.$v;
2032 - $c = ' ';
2033 - }
2034 - $value = $concatval;
2035 - }
2036 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
2037 - }
2038 - }
2039 - }
2040 - }
2041 -//20110411ysk start
2042 - switch($applyform) {
2043 - case 'JP':
2044 - if(isset($_REQUEST['check']['delivery_name'])) $line .= $td_h.usces_entity_decode($deli['name1'].' '.$deli['name2'], $ext).$td_f;
2045 - if(isset($_REQUEST['check']['delivery_kana'])) $line .= $td_h.usces_entity_decode($deli['name3'].' '.$deli['name4'], $ext).$td_f;
2046 - break;
2047 - case 'US':
2048 - default:
2049 - if(isset($_REQUEST['check']['delivery_name'])) $line .= $td_h.usces_entity_decode($deli['name2'].' '.$deli['name1'], $ext).$td_f;
2050 - break;
2051 - }
2052 -//20110411ysk end
2053 - if(!empty($csde_meta)) {
2054 - foreach($csde_meta as $key => $entry) {
2055 - if($entry['position'] == 'name_after') {
2056 - $name = $entry['name']."</td>";
2057 - $csde_key = 'csde_'.$key;
2058 -//20110208ysk start
2059 - //if(isset($_REQUEST['check'][$name])) {
2060 - if(isset($_REQUEST['check'][$csde_key])) {
2061 -//20110208ysk end
2062 - $value = maybe_unserialize($usces->get_order_meta_value($csde_key, $order_id));
2063 - if(empty($value)) {
2064 - $value = '';
2065 - } elseif(is_array($value)) {
2066 - $concatval = '';
2067 - $c = '';
2068 - foreach($value as $v) {
2069 - $concatval .= $c.$v;
2070 - $c = ' ';
2071 - }
2072 - $value = $concatval;
2073 - }
2074 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
2075 - }
2076 - }
2077 - }
2078 - }
2079 -//20110411ysk start
2080 - $address_info = '';
2081 - switch($applyform) {
2082 - case 'JP':
2083 - if(isset($_REQUEST['check']['delivery_zip'])) $address_info .= $td_h.usces_entity_decode($deli['zipcode'], $ext).$td_f;
2084 - if(isset($_REQUEST['check']['delivery_country'])) $address_info .= $td_h.$usces_settings['country'][$deli['country']].$td_f;
2085 - if(isset($_REQUEST['check']['delivery_pref'])) $address_info .= $td_h.usces_entity_decode($deli['pref'], $ext).$td_f;
2086 - if(isset($_REQUEST['check']['delivery_address1'])) $address_info .= $td_h.usces_entity_decode($deli['address1'], $ext).$td_f;
2087 - if(isset($_REQUEST['check']['delivery_address2'])) $address_info .= $td_h.usces_entity_decode($deli['address2'], $ext).$td_f;
2088 - if(isset($_REQUEST['check']['delivery_address3'])) $address_info .= $td_h.usces_entity_decode($deli['address3'], $ext).$td_f;
2089 - if(isset($_REQUEST['check']['delivery_tel'])) $address_info .= $td_h.usces_entity_decode($deli['tel'], $ext).$td_f;
2090 - if(isset($_REQUEST['check']['delivery_fax'])) $address_info .= $td_h.usces_entity_decode($deli['fax'], $ext).$td_f;
2091 - break;
2092 - case 'US':
2093 - default:
2094 - if(isset($_REQUEST['check']['delivery_address2'])) $address_info .= $td_h.usces_entity_decode($deli['address2'], $ext).$td_f;
2095 - if(isset($_REQUEST['check']['delivery_address3'])) $address_info .= $td_h.usces_entity_decode($deli['address3'], $ext).$td_f;
2096 - if(isset($_REQUEST['check']['delivery_address1'])) $address_info .= $td_h.usces_entity_decode($deli['address1'], $ext).$td_f;
2097 - if(isset($_REQUEST['check']['delivery_pref'])) $address_info .= $td_h.usces_entity_decode($deli['pref'], $ext).$td_f;
2098 - if(isset($_REQUEST['check']['delivery_country'])) $address_info .= $td_h.$usces_settings['country'][$deli['country']].$td_f;
2099 - if(isset($_REQUEST['check']['delivery_zip'])) $address_info .= $td_h.usces_entity_decode($deli['zipcode'], $ext).$td_f;
2100 - if(isset($_REQUEST['check']['delivery_tel'])) $address_info .= $td_h.usces_entity_decode($deli['tel'], $ext).$td_f;
2101 - if(isset($_REQUEST['check']['delivery_fax'])) $address_info .= $td_h.usces_entity_decode($deli['fax'], $ext).$td_f;
2102 - break;
2103 - }
2104 - $line .= apply_filters( 'usces_filter_ord_csv_delivery_address_info', $address_info, $deli, $address_info_args );
2105 -//20110411ysk end
2106 - if(!empty($csde_meta)) {
2107 - foreach($csde_meta as $key => $entry) {
2108 - if($entry['position'] == 'fax_after') {
2109 - $name = $entry['name'];
2110 - $csde_key = 'csde_'.$key;
2111 -//20110208ysk start
2112 - //if(isset($_REQUEST['check'][$name])) {
2113 - if(isset($_REQUEST['check'][$csde_key])) {
2114 -//20110208ysk end
2115 - $value = maybe_unserialize($usces->get_order_meta_value($csde_key, $order_id));
2116 - if(empty($value)) {
2117 - $value = '';
2118 - } elseif(is_array($value)) {
2119 - $concatval = '';
2120 - $c = '';
2121 - foreach($value as $v) {
2122 - $concatval .= $c.$v;
2123 - $c = ' ';
2124 - }
2125 - $value = $concatval;
2126 - }
2127 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
2128 - }
2129 - }
2130 - }
2131 - }
2132 - $line .= apply_filters( 'usces_filter_chk_ord_data_delivery', NULL, $usces_opt_order, $order_id, $deli );
2133 - //----------------------------------------------------------------------
2134 - if(isset($_REQUEST['check']['shipping_date'])) $line .= $td_h.$data['order_modified'].$td_f;
2135 - if(isset($_REQUEST['check']['peyment_method'])) $line .= $td_h.$data['order_payment_name'].$td_f;
2136 - if(isset($_REQUEST['check']['delivery_method'])) {
2137 - $delivery_method = '';
2138 - if(strtoupper($data['order_delivery_method']) == '#NONE#') {
2139 - $delivery_method = __('No preference', 'usces');
2140 - } else {
2141 - foreach((array)$usces->options['delivery_method'] as $dkey => $delivery) {
2142 - if($delivery['id'] == $data['order_delivery_method']) {
2143 - $delivery_method = $delivery['name'];
2144 - break;
2145 - }
2146 - }
2147 - }
2148 - $line .= $td_h.$delivery_method.$td_f;
2149 - }
2150 -//20101208ysk start
2151 - if(isset($_REQUEST['check']['delivery_date'])) $line .= $td_h.$data['order_delivery_date'].$td_f;
2152 -//20101208ysk end
2153 - if(isset($_REQUEST['check']['delivery_time'])) $line .= $td_h.$data['order_delivery_time'].$td_f;
2154 - if(isset($_REQUEST['check']['delidue_date'])) {
2155 - $order_delidue_date = (strtoupper($data['order_delidue_date']) == '#NONE#') ? '' : $data['order_delidue_date'];
2156 - $line .= $td_h.$order_delidue_date.$td_f;
2157 - }
2158 - if(isset($_REQUEST['check']['status'])) {
2159 - $order_status = explode(',', $data['order_status']);
2160 - $status = '';
2161 - foreach( (array)$order_status as $os) {
2162 - if( isset($usces_management_status[$os]) )
2163 - $status .= $usces_management_status[$os].$sp;
2164 - }
2165 - $line .= $td_h.trim($status, $sp).$td_f;
2166 - }
2167 - $line .= $td_h.usces_crform($array['total_price'], false, false, 'return', false).$td_f;
2168 - if(isset($_REQUEST['check']['getpoint'])) $line .= $td_h.$data['order_getpoint'].$td_f;
2169 - if(isset($_REQUEST['check']['usedpoint'])) $line .= $td_h.$data['order_usedpoint'].$td_f;
2170 - $line .= $td_h.$data['order_discount'].$td_f;
2171 - $line .= $td_h.$data['order_shipping_charge'].$td_f;
2172 - $line .= $td_h.$data['order_cod_fee'].$td_f;
2173 - $line .= $td_h.$data['order_tax'].$td_f;
2174 - if(isset($_REQUEST['check']['note'])) $line .= $td_h.usces_entity_decode($data['order_note'], $ext).$td_f;
2175 - if(!empty($csod_meta)) {
2176 - foreach($csod_meta as $key => $entry) {
2177 - $name = $entry['name'];
2178 - $csod_key = 'csod_'.$key;
2179 -//20110208ysk start
2180 - //if(isset($_REQUEST['check'][$name])) {
2181 - if(isset($_REQUEST['check'][$csod_key])) {
2182 -//20110208ysk end
2183 - $value = maybe_unserialize($usces->get_order_meta_value($csod_key, $order_id));
2184 - if(empty($value)) {
2185 - $value = '';
2186 - } elseif(is_array($value)) {
2187 - $concatval = '';
2188 - $c = '';
2189 - foreach($value as $v) {
2190 - $concatval .= $c.$v;
2191 - $c = ' ';
2192 - }
2193 - $value = $concatval;
2194 - }
2195 - $line .= $td_h.usces_entity_decode($value, $ext).$td_f;
2196 - }
2197 - }
2198 - }
2199 - $line .= apply_filters( 'usces_filter_chk_ord_data_order', NULL, $usces_opt_order, $order_id, $data );
2200 - $line .= $tr_f.$lf;
2201 - }
2202 - $line .= $table_f.$lf;
2203 - //==========================================================================
2204 -
2205 - if($ext == 'xls') {
2206 - header("Content-Type: application/vnd.ms-excel; charset=Shift-JIS");
2207 - } elseif($ext == 'csv') {
2208 - header("Content-Type: application/octet-stream");
2209 - }
2210 - header("Content-Disposition: attachment; filename=usces_order_list.".$ext);
2211 - mb_http_output('pass');
2212 - print(mb_convert_encoding($line, "SJIS-win", "UTF-8"));
2213 - exit();
2214 -}
2215 -
2216 -function usces_entity_decode($str, $ftype) {
2217 - $pos = strpos($str, '&');
2218 - if($pos !== false)
2219 - $str = htmlspecialchars_decode($str);
2220 -
2221 - if($ftype == 'csv')
2222 - $str = str_replace('"', '""', $str);
2223 -
2224 - return $str;
2225 -}
2226 -
2227 -function usces_is_entity($entity){
2228 - $temp = substr($entity, 0, 1);
2229 - $temp .= substr($entity, -1, 1);
2230 - if ($temp != '&;')
2231 - return false;
2232 - else
2233 - return true;
2234 -}
2235 -
2236 -function usces_p( $var ){
2237 - echo '<pre>' . print_r($var, true) . '</pre>';
2238 -}
2239 -
2240 -function usces_get_key( $digit ){
2241 - $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
2242 - $max = strlen($chars) - 1;
2243 - $str = '';
2244 - for($i=0; $i<$digit; $i++){
2245 - $str .= $chars[mt_rand(0, $max)];
2246 - }
2247 - return $str;
2248 -}
2249 -?>
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 +}