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