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