PluginProbe
Welcart e-Commerce / 2.11.30
Welcart e-Commerce v2.11.30
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
usc-e-shop / functions / function.php

function.php in Welcart e-Commerce 2.11.30, at functions/function.php

5,638 lines 217.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Functions
4 *
5 * @package Welcart
6 */
7
8 function usces_recovery_session_data() {
9 global $usces;
10
11 $absolute_trans_id = isset( $_REQUEST['absolute_trans_id'] ) ? $_REQUEST['absolute_trans_id'] : 0;
12
13 if ( ! $absolute_trans_id ) {
14 return;
15 }
16
17 $order_data = usces_get_acting_data( $absolute_trans_id );
18
19 if ( ! empty( $order_data['usces_entry'] ) ) {
20 $_SESSION['usces_member'] = $order_data['usces_member'];
21 $_SESSION['usces_cart'] = $order_data['usces_cart'];
22 $_SESSION['usces_entry'] = $order_data['usces_entry'];
23 }
24 }
25
26 function usces_reg_orderdata( $results = array() ) {
27 global $wpdb, $usces;
28
29 $options = get_option( 'usces', array() );
30 $cart = $usces->cart->get_cart();
31 $entry = $usces->cart->get_entry();
32
33 if ( empty( $cart ) ) {
34
35 // Trying to get back the entry data.
36 usces_recovery_session_data();
37 $cart = $usces->cart->get_cart();
38 $entry = $usces->cart->get_entry();
39
40 if ( empty( $cart ) ) {
41 $linkkey = usces_get_link_key( $results );
42 $log = array(
43 'acting' => 'reg_orderdata',
44 'key' => $linkkey,
45 'result' => 'SESSION EMPTY',
46 'data' => $_REQUEST,
47 );
48 usces_save_order_acting_error( $log );
49 return 0;
50 } else {
51 $log = array(
52 'acting' => 'reg_orderdata',
53 'key' => $_REQUEST['absolute_trans_id'],
54 'result' => 'OK SESSION RECOVERY',
55 'data' => $_REQUEST,
56 );
57 usces_save_order_acting_error( $log );
58
59 }
60 }
61
62 // Anti-spam.
63 if ( ( empty( $entry['customer']['name1'] ) && empty( $entry['customer']['name2'] ) ) || empty( $entry['customer']['mailaddress1'] ) || empty( $entry ) || empty( $cart ) ) {
64 $anti_spam = apply_filters( 'usces_filter_reg_orderdata_anti_spam', false, $entry, $cart );
65 if ( ! $anti_spam ) {
66 usces_log( 'reg_orderdata : Anti-spam', 'acting_transaction.log' );
67 return false;
68 }
69 }
70
71 $charging_type = $usces->getItemChargingType( $cart[0]['post_id'] );
72
73 $item_total_price = $usces->get_total_price( $cart );
74 $member = $usces->get_member();
75 $order_table_name = $wpdb->prefix . 'usces_order';
76 $order_table_meta_name = $wpdb->prefix . 'usces_order_meta';
77 $member_table_name = usces_get_tablename( 'usces_member' );
78 $set = $usces->getPayments( $entry['order']['payment_name'] );
79 $status = '';
80 $gmtdate = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) );
81 if ( 'continue' === $charging_type ) {
82 $order_modified = substr( $gmtdate, 0, 10 );
83 } else {
84 $noreceipt_status_table = apply_filters( 'usces_filter_noreceipt_status', get_option( 'usces_noreceipt_status' ) );
85
86 $status = ( in_array( $set['settlement'], $noreceipt_status_table ) ) ? 'noreceipt' : '';
87 $order_modified = NULL;
88 }
89
90 if ( 'paypal.php' === $set['module'] || 'acting_paypal_ec' === $set['settlement'] ) {
91 if ( ( isset( $results['payment_status'] ) && 'Completed' !== $results['payment_status'] ) || ( isset( $results['profile_status'] ) && 'ActiveProfile' !== $results['profile_status'] ) ) {
92 $status = 'pending';
93 }
94 }
95
96 $status = apply_filters( 'usces_filter_reg_orderdata_status', $status, $entry );
97 $order_date = ( isset( $results['order_date'] ) ) ? $results['order_date'] : $gmtdate;
98 $delidue_date = ( isset( $entry['order']['delidue_date'] ) ) ? $entry['order']['delidue_date'] : NULL;
99 $query = $wpdb->prepare(
100 "INSERT INTO $order_table_name (
101 `mem_id`, `order_email`, `order_name1`, `order_name2`, `order_name3`, `order_name4`,
102 `order_zip`, `order_pref`, `order_address1`, `order_address2`, `order_address3`,
103 `order_tel`, `order_fax`, `order_delivery`, `order_cart`, `order_note`, `order_delivery_method`, `order_delivery_date`, `order_delivery_time`,
104 `order_payment_name`, `order_condition`, `order_item_total_price`, `order_getpoint`, `order_usedpoint`, `order_discount`,
105 `order_shipping_charge`, `order_cod_fee`, `order_tax`, `order_date`, `order_modified`, `order_status`, `order_delidue_date` )
106 VALUES (%d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s, %s, %f, %d, %d, %f, %f, %f, %f, %s, %s, %s, %s)",
107 $member['ID'],
108 $entry['customer']['mailaddress1'],
109 $entry['customer']['name1'],
110 $entry['customer']['name2'],
111 $entry['customer']['name3'],
112 $entry['customer']['name4'],
113 $entry['customer']['zipcode'],
114 $entry['customer']['pref'],
115 $entry['customer']['address1'],
116 $entry['customer']['address2'],
117 $entry['customer']['address3'],
118 $entry['customer']['tel'],
119 $entry['customer']['fax'],
120 serialize( $entry['delivery'] ),
121 serialize( $cart ),
122 $entry['order']['note'],
123 $entry['order']['delivery_method'],
124 $entry['order']['delivery_date'],
125 $entry['order']['delivery_time'],
126 $entry['order']['payment_name'],
127 serialize( $entry['condition'] ),
128 $item_total_price,
129 $entry['order']['getpoint'],
130 $entry['order']['usedpoint'],
131 $entry['order']['discount'],
132 $entry['order']['shipping_charge'],
133 $entry['order']['cod_fee'],
134 $entry['order']['tax'],
135 $order_date,
136 $order_modified,
137 $status,
138 $delidue_date
139 );
140
141 $res = $wpdb->query( $query );
142
143 if ( false === $res ) {
144 $order_id = false;
145 usces_log( 'reg_orderdata : ' . $wpdb->last_error, 'database_error.log' );
146 } else {
147 $order_id = $wpdb->insert_id;
148 }
149
150 if ( ! $order_id ) {
151 usces_log( 'reg_error_entry : ' . print_r( $entry, true ), 'acting_transaction.log' );
152 return false;
153 }
154
155 $usces->cart->set_order_entry( array( 'ID' => $order_id ) );
156 $usces->set_order_meta_value( 'customer_country', $entry['customer']['country'], $order_id );
157
158 if ( usces_is_tax_display() && usces_is_reduced_taxrate() ) {
159 $usces_tax = Welcart_Tax::get_instance();
160 $materials = array(
161 'total_items_price' => $entry['order']['total_items_price'],
162 'discount' => ( isset( $entry['order']['discount'] ) ) ? $entry['order']['discount'] : 0,
163 'shipping_charge' => ( isset( $entry['order']['shipping_charge'] ) ) ? $entry['order']['shipping_charge'] : 0,
164 'cod_fee' => ( isset( $entry['order']['cod_fee'] ) ) ? $entry['order']['cod_fee'] : 0,
165 'use_point' => ( isset( $entry['order']['usedpoint'] ) ) ? $entry['order']['usedpoint'] : 0,
166 'carts' => $cart,
167 'condition' => $entry['condition'],
168 );
169 $usces_tax->get_order_tax( $materials );
170 $usces->set_order_meta_value( 'subtotal_standard', $usces_tax->subtotal_standard, $order_id );
171 $usces->set_order_meta_value( 'subtotal_reduced', $usces_tax->subtotal_reduced, $order_id );
172 $usces->set_order_meta_value( 'discount_standard', $usces_tax->discount_standard, $order_id );
173 $usces->set_order_meta_value( 'discount_reduced', $usces_tax->discount_reduced, $order_id );
174 if ( 'include' === $usces->options['tax_mode'] ) {
175 $usces->set_order_meta_value( 'tax_standard', 0, $order_id );
176 $usces->set_order_meta_value( 'tax_reduced', 0, $order_id );
177 } else {
178 $usces->set_order_meta_value( 'tax_standard', $usces_tax->tax_standard, $order_id );
179 $usces->set_order_meta_value( 'tax_reduced', $usces_tax->tax_reduced, $order_id );
180 }
181 }
182
183 if ( $member['ID'] && 'activate' === $options['membersystem_state'] && 'activate' === $options['membersystem_point'] ) {
184
185 $mquery = '';
186 if ( usces_is_complete_settlement( $entry['order']['payment_name'], $status ) ) {
187 if ( apply_filters( 'usces_action_acting_getpoint_switch', true, $order_id, true ) ) {
188 $mquery = $wpdb->prepare(
189 "UPDATE $member_table_name SET mem_point = (mem_point + %d - %d) WHERE ID = %d",
190 $entry['order']['getpoint'], $entry['order']['usedpoint'], $member['ID']
191 );
192 } else {
193 $mquery = $wpdb->prepare(
194 "UPDATE $member_table_name SET mem_point = (mem_point - %d) WHERE ID = %d",
195 $entry['order']['usedpoint'], $member['ID']
196 );
197 }
198 } elseif ( 0 < $entry['order']['usedpoint'] ) {
199 $mquery = $wpdb->prepare(
200 "UPDATE $member_table_name SET mem_point = (mem_point - %d) WHERE ID = %d",
201 $entry['order']['usedpoint'], $member['ID']
202 );
203 }
204 if ( $mquery ) {
205 $wpdb->query( $mquery );
206 $mquery = $wpdb->prepare( "SELECT mem_point FROM $member_table_name WHERE ID = %d", $member['ID'] );
207 $point = $wpdb->get_var( $mquery );
208 $_SESSION['usces_member']['point'] = $point;
209 }
210
211 }
212
213 if ( ! empty( $entry['reserve'] ) ) {
214 foreach ( $entry['reserve'] as $key => $value ) {
215 if ( is_array( $value ) ) {
216 $value = serialize( $value );
217 }
218 $usces->set_order_meta_value( $key, $value, $order_id );
219 }
220 }
221
222 if ( ! preg_match( '/pending|noreceipt/', $status ) ) {
223 $usces->set_order_meta_value( 'receipted_date', $gmtdate, $order_id );
224 }
225
226 if ( ! empty( $entry['custom_order'] ) ) {
227 foreach ( $entry['custom_order'] as $key => $value ) {
228 $csod_key = 'csod_' . $key;
229 $value = wel_safe_text_serialize( $value );
230 if ( is_array( $value ) ) {
231 $value = serialize( $value );
232 }
233 $usces->set_order_meta_value( $csod_key, $value, $order_id );
234 }
235 }
236 if ( ! empty( $entry['custom_customer'] ) ) {
237 foreach ( $entry['custom_customer'] as $key => $value ) {
238 $cscs_key = 'cscs_' . $key;
239 $value = wel_safe_text_serialize( $value );
240 if ( is_array( $value ) ) {
241 $value = serialize( $value );
242 }
243 $usces->set_order_meta_value( $cscs_key, $value, $order_id );
244 }
245 }
246 if ( ! empty( $entry['custom_delivery'] ) ) {
247 foreach ( $entry['custom_delivery'] as $key => $value ) {
248 $csde_key = 'csde_' . $key;
249 $value = wel_safe_text_serialize( $value );
250 if ( is_array( $value ) ) {
251 $value = serialize( $value );
252 }
253 $usces->set_order_meta_value( $csde_key, $value, $order_id );
254 }
255 }
256
257 $args = array(
258 'cart' => $cart,
259 'entry' => $entry,
260 'order_id' => $order_id,
261 'member_id' => $member['ID'],
262 'payments' => $set,
263 'charging_type' => $charging_type,
264 'results' => $results,
265 );
266 do_action( 'usces_action_reg_orderdata', $args );
267
268 return $order_id;
269 }
270
271 function usces_new_orderdata() {
272 global $wpdb, $usces;
273
274 $_POST = $usces->stripslashes_deep_post( $_POST );
275 $_POST['customer']['name3'] = isset( $_POST['customer']['name3'] ) ? $_POST['customer']['name3'] : '';
276 $_POST['customer']['name4'] = isset( $_POST['customer']['name4'] ) ? $_POST['customer']['name4'] : '';
277 $usces->cart->crear_cart();
278 $cart = $usces->cart->get_cart();
279 $item_total_price = $usces->get_total_price( $cart );
280 $entry = $usces->cart->get_entry();
281 $member_id = $usces->get_memberid_by_email( $_POST['customer']['mailaddress'] );
282 $order_table_name = $wpdb->prefix . 'usces_order';
283 $order_table_meta_name = $wpdb->prefix . 'usces_order_meta';
284 $member_table_name = usces_get_tablename( 'usces_member' );
285 $set = $usces->getPayments( $_POST['offer']['payment_name'] );
286 if ( isset( $_POST['offer']['receipt'] ) ) {
287 $status = $_POST['offer']['receipt'] . ',';
288 } else {
289 $noreceipt_status_table = apply_filters( 'usces_filter_noreceipt_status', get_option( 'usces_noreceipt_status' ) );
290 $status = ( in_array( $set['settlement'], $noreceipt_status_table ) ) ? 'noreceipt' : '';
291 }
292 $status .= ( ! WCUtils::is_blank( $_POST['offer']['taio'] ) && '#none#' !== $_POST['offer']['taio'] ) ? $_POST['offer']['taio'] . ',' : '';
293 $status .= $_POST['offer']['admin'];
294 $status = apply_filters( 'usces_filter_new_orderdata_status', $status, $entry );
295 $order_conditions = $usces->get_condition();
296 $gmtdate = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) );
297
298 $delivery_date = $_POST['offer']['delivery_date'];
299 if ( ! usces_is_date( $delivery_date ) ) {
300 $delivery_date = apply_filters( 'usces_filter_label_delivery_date_no_preference', __( 'Non-request', 'usces_dual' ) );
301 }
302
303 $query = $wpdb->prepare(
304 "INSERT INTO $order_table_name (
305 `mem_id`, `order_email`, `order_name1`, `order_name2`, `order_name3`, `order_name4`,
306 `order_zip`, `order_pref`, `order_address1`, `order_address2`, `order_address3`,
307 `order_tel`, `order_fax`, `order_delivery`, `order_cart`, `order_note`, `order_delivery_method`, `order_delivery_date`, `order_delivery_time`,
308 `order_payment_name`, `order_condition`, `order_item_total_price`, `order_getpoint`, `order_usedpoint`, `order_discount`,
309 `order_shipping_charge`, `order_cod_fee`, `order_tax`, `order_date`, `order_modified`, `order_status`, `order_delidue_date` )
310 VALUES (%d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s, %s, %f, %d, %d, %f, %f, %f, %f, %s, %s, %s, %s)",
311 $member_id,
312 $_POST['customer']['mailaddress'],
313 $_POST['customer']['name1'],
314 $_POST['customer']['name2'],
315 $_POST['customer']['name3'],
316 $_POST['customer']['name4'],
317 $_POST['customer']['zipcode'],
318 $_POST['customer']['pref'],
319 $_POST['customer']['address1'],
320 $_POST['customer']['address2'],
321 $_POST['customer']['address3'],
322 $_POST['customer']['tel'],
323 $_POST['customer']['fax'],
324 serialize( $_POST['delivery'] ),
325 serialize( $cart ),
326 $_POST['offer']['note'],
327 $_POST['offer']['delivery_method'],
328 $delivery_date,
329 $_POST['offer']['delivery_time'],
330 $_POST['offer']['payment_name'],
331 serialize( $order_conditions ),
332 $item_total_price,
333 $_POST['offer']['getpoint'],
334 $_POST['offer']['usedpoint'],
335 $_POST['offer']['discount'],
336 $_POST['offer']['shipping_charge'],
337 $_POST['offer']['cod_fee'],
338 $_POST['offer']['tax'],
339 $gmtdate,
340 null,
341 $status,
342 $_POST['offer']['delidue_date']
343 );
344
345 $res = $wpdb->query( $query );
346 $order_id = $wpdb->insert_id;
347 $_REQUEST['order_id'] = $wpdb->insert_id;
348
349 if ( ! $order_id ) {
350 return false;
351 }
352
353 $usces->set_order_meta_value( 'customer_country', $_POST['customer']['country'], $order_id );
354
355 if ( usces_is_tax_display() && usces_is_reduced_taxrate() ) {
356 $usces_tax = Welcart_Tax::get_instance();
357 $materials = array(
358 'total_items_price' => $item_total_price,
359 'discount' => $_POST['offer']['discount'],
360 'shipping_charge' => $_POST['offer']['shipping_charge'],
361 'cod_fee' => $_POST['offer']['cod_fee'],
362 'use_point' => $_POST['offer']['usedpoint'],
363 'carts' => $cart,
364 'condition' => $order_conditions,
365 );
366 $usces_tax->get_order_tax( $materials );
367 $usces->set_order_meta_value( 'subtotal_standard', $usces_tax->subtotal_standard, $order_id );
368 $usces->set_order_meta_value( 'subtotal_reduced', $usces_tax->subtotal_reduced, $order_id );
369 $usces->set_order_meta_value( 'discount_standard', $usces_tax->discount_standard, $order_id );
370 $usces->set_order_meta_value( 'discount_reduced', $usces_tax->discount_reduced, $order_id );
371 if ( 'include' === $usces->options['tax_mode'] ) {
372 $usces->set_order_meta_value( 'tax_standard', 0, $order_id );
373 $usces->set_order_meta_value( 'tax_reduced', 0, $order_id );
374 } else {
375 $usces->set_order_meta_value( 'tax_standard', $usces_tax->tax_standard, $order_id );
376 $usces->set_order_meta_value( 'tax_reduced', $usces_tax->tax_reduced, $order_id );
377 }
378 }
379
380 if ( ! empty( $_POST['custom_order'] ) ) {
381 foreach ( $_POST['custom_order'] as $key => $value ) {
382 $csod_key = 'csod_' . $key;
383 if ( is_array( $value ) ) {
384 $value = serialize( $value );
385 }
386 $usces->set_order_meta_value( $csod_key, $value, $order_id );
387 }
388 }
389 if ( ! empty( $_POST['custom_customer'] ) ) {
390 foreach ( $_POST['custom_customer'] as $key => $value ) {
391 $cscs_key = 'cscs_' . $key;
392 if ( is_array( $value ) ) {
393 $value = serialize( $value );
394 }
395 $usces->set_order_meta_value( $cscs_key, $value, $order_id );
396 }
397 }
398 if ( ! empty( $_POST['custom_delivery'] ) ) {
399 foreach ( $_POST['custom_delivery'] as $key => $value ) {
400 $csde_key = 'csde_' . $key;
401 if ( is_array( $value ) ) {
402 $value = serialize( $value );
403 }
404 $usces->set_order_meta_value( $csde_key, $value, $order_id );
405 }
406 }
407 if ( ! preg_match( '/pending|noreceipt/', $status ) ) {
408 $usces->set_order_meta_value( 'receipted_date', $gmtdate, $order_id );
409 }
410 $args = array(
411 'cart' => $cart,
412 'entry' => $entry,
413 'order_id' => $order_id,
414 'member_id' => $member_id,
415 'payments' => $set,
416 );
417 do_action( 'usces_action_reg_orderdata', $args );
418
419 $usces->cart->crear_cart();
420 return $res;
421 }
422
423 function usces_new_memberdata() {
424 global $wpdb, $usces;
425
426 $_POST = $usces->stripslashes_deep_post( $_POST );
427 $_POST['member']['name3'] = isset( $_POST['member']['name3'] ) ? $_POST['member']['name3'] : '';
428 $_POST['member']['name4'] = isset( $_POST['member']['name4'] ) ? $_POST['member']['name4'] : '';
429 $salt = usces_get_salt( '', 1 );
430 $pass = usces_get_hash( trim( $_POST['member']['password'] ), $salt, 1 );
431 $member_table_name = usces_get_tablename( 'usces_member' );
432 $member_table_meta_name = usces_get_tablename( 'usces_member_meta' );
433 $gmtdate = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) );
434 $query = $wpdb->prepare(
435 "INSERT INTO $member_table_name
436 (`mem_email`, `mem_pass`, `mem_status`, `mem_cookie`, `mem_point`,
437 `mem_name1`, `mem_name2`, `mem_name3`, `mem_name4`, `mem_zip`, `mem_pref`,
438 `mem_address1`, `mem_address2`, `mem_address3`, `mem_tel`, `mem_fax`,
439 `mem_delivery_flag`, `mem_delivery`, `mem_registered`, `mem_nicename`)
440 VALUES (%s, %s, %d, %s, %d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s)",
441 trim( $_POST['member']['email'] ),
442 $pass,
443 trim( $_POST['member']['status'] ),
444 '',
445 trim( $_POST['member']['point'] ),
446 trim( $_POST['member']['name1'] ),
447 trim( $_POST['member']['name2'] ),
448 trim( $_POST['member']['name3'] ),
449 trim( $_POST['member']['name4'] ),
450 trim( $_POST['member']['zipcode'] ),
451 trim( $_POST['member']['pref'] ),
452 trim( $_POST['member']['address1'] ),
453 trim( $_POST['member']['address2'] ),
454 trim( $_POST['member']['address3'] ),
455 trim( $_POST['member']['tel'] ),
456 trim( $_POST['member']['fax'] ),
457 '',
458 '',
459 $gmtdate,
460 ''
461 );
462 $res[0] = $wpdb->query( $query );
463
464 if ( false === $res[0] ) {
465 return false;
466 }
467
468 $member_id = $wpdb->insert_id;
469 $_REQUEST['member_id'] = $wpdb->insert_id;
470 if ( ! $member_id ) {
471 return false;
472 }
473
474 $usces->set_member_meta_value( 'customer_country', $_POST['member']['country'], $member_id );
475 $csmb_meta = usces_has_custom_field_meta( 'member' );
476 if ( is_array( $csmb_meta ) ) {
477 foreach ( $csmb_meta as $key => $entry ) {
478 if ( 4 === (int) $entry['means'] ) {
479 $usces->del_member_meta( 'csmb_' . $key, $member_id );
480 }
481 }
482 }
483 $admb_meta = usces_has_custom_field_meta( 'admin_member' );
484 if ( is_array( $admb_meta ) ) {
485 foreach ( $admb_meta as $key => $entry ) {
486 if ( 4 === (int) $entry['means'] ) {
487 $usces->del_member_meta( 'admb_' . $key, $member_id );
488 }
489 }
490 }
491 $i = 1;
492 if ( ! empty( $_POST['custom_member'] ) ) {
493 foreach ( $_POST['custom_member'] as $key => $value ) {
494 $csmb_key = 'csmb_' . $key;
495 if ( is_array( $value ) ) {
496 $value = serialize( $value );
497 }
498 $res[ $i ] = $usces->set_member_meta_value( $csmb_key, $value, $member_id );
499 if ( false === $res[ $i ] ) {
500 return false;
501 }
502 $i++;
503 }
504 }
505 if ( ! empty( $_POST['admin_custom_member'] ) ) {
506 foreach ( $_POST['admin_custom_member'] as $key => $value ) {
507 $admb_key = 'admb_' . $key;
508 if ( is_array( $value ) ) {
509 $value = serialize( $value );
510 }
511 $res[ $i ] = $usces->set_member_meta_value( $admb_key, $value, $member_id );
512 if ( false === $res[ $i ] ) {
513 return false;
514 }
515 $i++;
516 }
517 }
518 if ( ! empty( $salt ) ) {
519 $res[ $i ] = $usces->set_member_meta_value( 'mem_salt', $salt, $member_id );
520 $i++;
521 }
522 $result = ( 0 < array_sum( array_filter( $res, 'is_numeric' ) ) ) ? 1 : 0;
523
524 do_action( 'usces_action_post_new_memberdata', $member_id, $res[0] );
525
526 return $result;
527 }
528
529 function usces_delete_memberdata( $ID = 0 ) {
530 global $wpdb, $usces;
531
532 if ( 0 === (int) $ID ) {
533 if ( ! isset( $_REQUEST['member_id'] ) || WCUtils::is_blank( $_REQUEST['member_id'] ) ) {
534 return 0;
535 }
536 $ID = $_REQUEST['member_id'];
537 }
538 do_action( 'usces_action_pre_delete_memberdata', $ID );
539
540 $member_table_name = usces_get_tablename( 'usces_member' );
541 $member_table_meta_name = usces_get_tablename( 'usces_member_meta' );
542
543 $query = $wpdb->prepare( "DELETE FROM $member_table_name WHERE ID = %d", $ID );
544 $res = $wpdb->query( $query );
545 if ( $res ) {
546 $query = $wpdb->prepare( "DELETE FROM $member_table_meta_name WHERE member_id = %d", $ID );
547 $wpdb->query( $query );
548 }
549 do_action( 'usces_action_post_delete_memberdata', $res, $ID );
550
551 return $res;
552 }
553
554 function usces_update_memberdata() {
555 global $wpdb, $usces;
556
557 $_POST = $usces->stripslashes_deep_post( $_POST );
558
559 $member_table_name = usces_get_tablename( 'usces_member' );
560 $member_table_meta_name = usces_get_tablename( 'usces_member_meta' );
561
562 $ID = (int) $_REQUEST['member_id'];
563 $name3 = ( isset( $_POST['member']['name3'] ) ) ? trim( $_POST['member']['name3'] ) : '';
564 $name4 = ( isset( $_POST['member']['name4'] ) ) ? trim( $_POST['member']['name4'] ) : '';
565
566 $query = $wpdb->prepare(
567 "UPDATE $member_table_name SET
568 `mem_email`=%s, `mem_status`=%s, `mem_point`=%d, `mem_name1`=%s, `mem_name2`=%s,
569 `mem_name3`=%s, `mem_name4`=%s, `mem_zip`=%s, `mem_pref`=%s, `mem_address1`=%s,
570 `mem_address2`=%s, `mem_address3`=%s, `mem_tel`=%s, `mem_fax`=%s
571 WHERE ID = %d",
572 trim( $_POST['member']['email'] ),
573 trim( $_POST['member']['status'] ),
574 trim( $_POST['member']['point'] ),
575 trim( $_POST['member']['name1'] ),
576 trim( $_POST['member']['name2'] ),
577 $name3,
578 $name4,
579 trim( $_POST['member']['zipcode'] ),
580 trim( $_POST['member']['pref'] ),
581 trim( $_POST['member']['address1'] ),
582 trim( $_POST['member']['address2'] ),
583 trim( $_POST['member']['address3'] ),
584 trim( $_POST['member']['tel'] ),
585 trim( $_POST['member']['fax'] ),
586 $ID
587 );
588
589 do_action( 'usces_action_pre_update_memberdata', $ID );
590 $res[0] = $wpdb->query( $query );
591
592 do_action( 'usces_action_post_update_memberdata', $ID, $res[0] );
593
594 if ( false === $res[0] ) {
595 return false;
596 }
597
598 $usces->set_member_meta_value( 'customer_country', $_POST['member']['country'], $ID );
599 $csmb_meta = usces_has_custom_field_meta( 'member' );
600 if ( is_array( $csmb_meta ) ) {
601 foreach ( $csmb_meta as $key => $entry ) {
602 if ( 4 === (int) $entry['means'] ) {
603 $usces->del_member_meta( 'csmb_' . $key, $ID );
604 }
605 }
606 }
607 $admb_meta = usces_has_custom_field_meta( 'admin_member' );
608 if ( is_array( $admb_meta ) ) {
609 foreach ( $admb_meta as $key => $entry ) {
610 if ( 4 === (int) $entry['means'] ) {
611 $usces->del_member_meta( 'admb_' . $key, $ID );
612 }
613 }
614 }
615 $i = 1;
616 if ( ! empty( $_POST['custom_member'] ) ) {
617 foreach ( $_POST['custom_member'] as $key => $value ) {
618 $csmb_key = 'csmb_' . $key;
619 if ( is_array( $value ) ) {
620 $value = serialize( $value );
621 }
622 $res[ $i ] = $usces->set_member_meta_value( $csmb_key, $value, $ID );
623 if ( false === $res[ $i ] ) {
624 return false;
625 }
626 $i++;
627 }
628 }
629 if ( ! empty( $_POST['admin_custom_member'] ) ) {
630 foreach ( $_POST['admin_custom_member'] as $key => $value ) {
631 $admb_key = 'admb_' . $key;
632 if ( is_array( $value ) ) {
633 $value = serialize( $value );
634 }
635 $res[ $i ] = $usces->set_member_meta_value( $admb_key, $value, $ID );
636 if ( false === $res[ $i ] ) {
637 return false;
638 }
639 $i++;
640 }
641 }
642
643 do_action( 'usces_action_post_update_after_memberdata', $ID, $res );
644
645 $result = ( 0 < array_sum( array_filter( $res, 'is_numeric' ) ) ) ? 1 : 0;
646 return $result;
647 }
648
649 function usces_delete_orderdata() {
650 global $wpdb, $usces;
651
652 if ( ! isset( $_REQUEST['order_id'] ) || WCUtils::is_blank( $_REQUEST['order_id'] ) ) {
653 return 0;
654 }
655 $order_table = $wpdb->prefix . 'usces_order';
656 $order_meta_table = $wpdb->prefix . 'usces_order_meta';
657 $ID = $_REQUEST['order_id'];
658
659 $del = usces_delete_order_check( $ID );
660 if ( $del ) {
661
662 $query = $wpdb->prepare( "SELECT * FROM $order_table WHERE ID = %d", $ID );
663 $order_data = $wpdb->get_row( $query, OBJECT );
664 $point = 0;
665 if ( 'activate' === $usces->options['membersystem_state'] && 'activate' === $usces->options['membersystem_point'] && ! empty( $order_data->mem_id ) && ! $usces->is_status( 'cancel', $order_data->order_status ) ) {
666 if ( 0 < $order_data->order_getpoint ) {
667 if ( usces_is_complete_settlement( $order_data->order_payment_name, $order_data->order_status ) || $usces->is_status( 'receipted', $order_data->order_status) ) {
668 $point += $order_data->order_getpoint;
669 }
670 }
671 if ( 0 < $order_data->order_usedpoint ) {
672 $point -= $order_data->order_usedpoint;
673 }
674 }
675
676 $query = $wpdb->prepare( "DELETE FROM $order_table WHERE ID = %d", $ID );
677 $res = $wpdb->query( $query );
678
679 $args = compact( 'ID', 'point', 'res' );
680
681 if ( $res ) {
682
683 do_action( 'usces_action_del_orderdata', $order_data, $args );
684
685 $query = $wpdb->prepare( "DELETE FROM $order_meta_table WHERE order_id = %d", $ID );
686 $wpdb->query( $query );
687
688 usces_delete_ordercartdata( NULL, $ID );
689
690 if ( 0 != $point ) {
691 usces_restore_point( $order_data->mem_id, $point );
692 }
693 }
694
695 } else {
696 $res = true;
697 }
698
699 return $res;
700 }
701
702 function usces_update_serialized_cart() {
703 global $wpdb, $usces;
704
705 if ( ! isset( $_REQUEST['order_id'] ) || WCUtils::is_blank( $_REQUEST['order_id'] ) ) {
706 return 0;
707 }
708
709 $ID = $_REQUEST['order_id'];
710
711 $order_table_name = $wpdb->prefix . 'usces_order';
712 $usces->cart->crear_cart();
713 $usces->cart->upCart();
714 $cart = $usces->cart->get_cart();
715 if ( $cart && is_array( $cart ) && 0 < count( $cart ) ) {
716 // $idx = count( $cart ) - 1;
717 // $post_id = $cart[ $idx ]['post_id'];
718 // $sku = $cart[ $idx ]['sku'];
719 // $sku_code = esc_attr( urldecode( $sku ) );
720 // $cartItemName = $usces->getCartItemName( $post_id, $sku_code, false );
721 // $skuPrice = $cart[ $idx ]['price'];
722
723 $query = $wpdb->prepare(
724 "UPDATE $order_table_name SET `order_cart`=%s WHERE ID = %d",
725 serialize( $cart ),
726 $ID
727 );
728 $res = $wpdb->query( $query );
729
730 $usces->cart->crear_cart();
731 }
732 }
733
734 function usces_delete_serialized_cart() {
735 global $wpdb, $usces;
736
737 if ( ! isset( $_REQUEST['order_id'] ) || WCUtils::is_blank( $_REQUEST['order_id'] ) ) {
738 return 0;
739 }
740
741 $indexs = array_keys( $_POST['delButton'] );
742 $index = $indexs[0];
743 $ids = array_keys( $_POST['delButton'][ $index ] );
744 $post_id = $ids[0];
745 $skus = array_keys( $_POST['delButton'][ $index ][ $post_id ] );
746 $sku = $skus[0];
747
748 $usces->up_serialize( $index, $post_id, $sku );
749 do_action( 'usces_cart_del_row', $index );
750
751 if ( isset( $_SESSION['usces_cart'][ $usces->serial ] ) ) {
752 unset( $_SESSION['usces_cart'][ $usces->serial ] );
753 }
754
755 unset( $_SESSION['usces_entry']['order']['usedpoint'] );
756 }
757
758 function usces_get_serialized_cart( $order_id ) {
759 global $wpdb, $usces;
760
761 $order_table_name = $wpdb->prefix . 'usces_order';
762 $query = $wpdb->prepare( "SELECT order_cart FROM $order_table_name WHERE ID = %d", $order_id );
763 $order_cart = $wpdb->get_var( $query );
764 $cart = unserialize( $order_cart );
765 foreach ( $cart as $cart_index => $cart_row ) {
766 $options = array();
767 if ( ! empty( $cart_row['options'] ) ) {
768 foreach ( $cart_row['options'] as $key => $value ) {
769 $key = urldecode( $key );
770 if ( is_array( $value ) ) {
771 foreach ( $value as $vk => $vv ) {
772 $value[ $vk ] = urldecode( $vv );
773 }
774 $options[ $key ] = $value;
775 } else {
776 $options[ $key ] = urldecode( $value );
777 }
778 }
779 $cart_row['options'] = $options;
780 }
781 $cart[ $cart_index ] = $cart_row;
782 }
783 return $cart;
784 }
785
786 function usces_update_ordercart() {
787 $ordercart_table_name = $wpdb->prefix . 'usces_ordercart';
788 foreach ( $_POST['skuPrice'] as $cart_id => $price ) {
789 $quantity = $_POST['quant'][ $cart_id ];
790 $query = $wpdb->prepare(
791 "UPDATE $ordercart_table_name SET price = %f, quantity = %f WHERE cart_id = %d",
792 $price, $quantity, $cart_id
793 );
794 $wpdb->query( $query );
795 }
796
797 $ordercart_meta_table_name = $wpdb->prefix . 'usces_ordercart_meta';
798 foreach ( $_POST['itemOption'] as $cartmeta_id => $value ) {
799 if ( is_array( $value ) ) {
800 foreach ( $value as $v ) {
801 $opval[ $v ] = $v;
802 }
803 $value = serialize( $opval );
804 }
805 $query = $wpdb->prepare(
806 "UPDATE $ordercart_meta_table_name SET meta_value = %s WHERE cartmeta_id = %d",
807 $value, $cartmeta_id
808 );
809 $wpdb->query( $query );
810 }
811 // if ( false === $res ) {
812 // $res = "-1#usces#";
813 // } else {
814 // $res = $skuPrice . "#usces#" . $cartItemName;
815 // }
816 // //return $res;
817 }
818
819 function usces_update_ordercartdata( $order_id ) {
820 global $wpdb, $usces;
821
822 if ( ! isset( $_POST['skuPrice'] ) ) {
823 return;
824 }
825
826 $ordercart_table_name = $wpdb->prefix . 'usces_ordercart';
827 $ordercart_meta_table_name = $wpdb->prefix . 'usces_ordercart_meta';
828 foreach ( (array) $_POST['skuPrice'] as $cart_id => $price ) {
829 $quantity = $_POST['quant'][ $cart_id ];
830 $query = $wpdb->prepare(
831 "UPDATE $ordercart_table_name SET price = %f, quantity = %f WHERE cart_id = %d",
832 $price, $quantity, $cart_id
833 );
834 $wpdb->query( $query );
835
836 // itemOptionチェックボックスとラジオのチェック.
837 $cart = usces_get_ordercartdata_row( $cart_id );
838 $item_opts = usces_get_opts( $cart['post_id'], 'name', false );
839 foreach ( $item_opts as $key => $iopts ) {
840 if ( 3 === (int) $iopts['means'] || 4 === (int) $iopts['means'] ) {
841 $cart_meta = usces_get_ordercart_meta( 'option', $cart_id, $iopts['name'] );
842 $cart_meta_id = isset( $cart_meta[0]['cartmeta_id'] ) ? $cart_meta[0]['cartmeta_id'] : 'notfound';
843
844 // POSTが無ければmeta_valueをNULLに変更.
845 if ( ! isset( $_POST['itemOption'][ $cart_meta_id ] ) ) {
846 $query = $wpdb->prepare(
847 "UPDATE $ordercart_meta_table_name SET meta_value = %s WHERE cartmeta_id = %d",
848 NULL, $cart_meta_id
849 );
850 $wpdb->query( $query );
851 }
852 }
853 }
854 }
855
856 if ( ! isset( $_POST['itemOption'] ) ) {
857 return;
858 }
859
860 $ordercart_meta_table_name = $wpdb->prefix . 'usces_ordercart_meta';
861 foreach ( (array) $_POST['itemOption'] as $cartmeta_id => $value ) {
862 $post_id = usces_get_post_id_by_cartmeta_id( $cartmeta_id );
863 $option_fields = usces_get_opts( $post_id, 'name' );
864 $ordercart_metas = usces_get_ordercart_meta_by_id( $cartmeta_id );
865 $means = $option_fields[ $ordercart_metas['meta_key'] ]['means'];
866 if ( is_array( $value ) ) {
867 $opval = array();
868 if ( 4 === (int) $means ) {
869 foreach ( $value as $v ) {
870 $opval[] = urldecode( $v );
871 }
872 } else {
873 foreach ( $value as $v ) {
874 $opval[ $v ] = urldecode( $v );
875 }
876 }
877 $value = serialize( $opval );
878 } else {
879 if ( 3 === (int) $means ) {
880 $value = urldecode( $value );
881 }
882 }
883 $query = $wpdb->prepare(
884 "UPDATE $ordercart_meta_table_name SET meta_value = %s WHERE cartmeta_id = %d",
885 $value, $cartmeta_id
886 );
887 $wpdb->query( $query );
888 }
889 }
890
891 function usces_delete_ordercartdata( $cart_id, $order_id = NULL ) {
892 global $wpdb, $usces;
893
894 $ordercart_table_name = $wpdb->prefix . 'usces_ordercart';
895 $ordercart_meta_table_name = $wpdb->prefix . 'usces_ordercart_meta';
896
897 if ( NULL != $cart_id ) {
898
899 $query = $wpdb->prepare( "DELETE FROM $ordercart_table_name WHERE cart_id = %d", $cart_id );
900 $wpdb->query( $query );
901
902 $mquery = $wpdb->prepare( "DELETE FROM $ordercart_meta_table_name WHERE cart_id = %d", $cart_id );
903 $wpdb->query( $mquery );
904
905 } elseif ( NULL != $order_id ) {
906
907 $query = $wpdb->prepare( "SELECT cart_id FROM $ordercart_table_name WHERE order_id = %d", $order_id );
908 $cat_ids = $wpdb->get_col( $query );
909
910 $query = $wpdb->prepare( "DELETE FROM $ordercart_table_name WHERE order_id = %d", $order_id );
911 $wpdb->query( $query );
912
913 foreach ( $cat_ids as $id ) {
914 $mquery = $wpdb->prepare( "DELETE FROM $ordercart_meta_table_name WHERE cart_id = %d", $id );
915 $wpdb->query( $mquery );
916 }
917 }
918 }
919
920 function usces_get_ordercartdata_row( $cart_id ) {
921 global $usces, $wpdb;
922
923 $cart_table = $wpdb->prefix . 'usces_ordercart';
924
925 $query = $wpdb->prepare( "SELECT * FROM $cart_table WHERE cart_id = %d", $cart_id );
926 $cart = $wpdb->get_row( $query, ARRAY_A );
927 return $cart;
928 }
929
930 function usces_get_ordercartdata( $order_id ) {
931 global $usces, $wpdb;
932
933 $cart_table = $wpdb->prefix . 'usces_ordercart';
934 $cart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
935
936 $query = $wpdb->prepare( "SELECT * FROM $cart_table WHERE order_id = %d ORDER BY cart_id", $order_id );
937 $cart = $wpdb->get_results( $query, ARRAY_A );
938
939 foreach ( $cart as $key => $value ) {
940 $cart[ $key ]['sku'] = $value['sku_code'];
941 $query = $wpdb->prepare( "SELECT * FROM $cart_meta_table WHERE cart_id = %d ORDER BY cartmeta_id", $value['cart_id'] );
942 $results = $wpdb->get_results( $query, ARRAY_A );
943 foreach ( (array) $results as $value ) {
944 switch ( $value['meta_type'] ) {
945 case 'option':
946 $cart[ $key ]['options'][ $value['meta_key'] ] = $value['meta_value'];
947 break;
948 case 'advance':
949 $cart[ $key ]['advance'][ $value['meta_key'] ] = $value['meta_value'];
950 break;
951 }
952 }
953 if ( ! isset( $cart[ $key ]['options'] ) ) {
954 $cart[ $key ]['options'] = array();
955 }
956 if ( ! isset( $cart[ $key ]['advance'] ) ) {
957 $cart[ $key ]['advance'] = array();
958 }
959 }
960
961 return $cart;
962 }
963
964 function usces_update_ordercheck() {
965 global $wpdb;
966
967 $tableName = $wpdb->prefix . 'usces_order';
968 $order_id = $_POST['order_id'];
969 $checked = $_POST['checked'];
970 $logger = Logger::start( $order_id, 'orderedit', 'update' );
971
972 $query = $wpdb->prepare( "SELECT `order_check` FROM $tableName WHERE ID = %d", $order_id );
973 $res = $wpdb->get_var( $query );
974
975 $checkfield = ! empty( $res ) ? unserialize( $res ) : array();
976 if ( ! is_array( $checkfield ) ) {
977 $checkfield = array();
978 }
979 if ( ! isset( $checkfield[ $checked ] ) ) {
980 $checkfield[ $checked ] = $checked;
981 }
982 $query = $wpdb->prepare( "UPDATE $tableName SET `order_check` = %s WHERE ID = %d", serialize( $checkfield ), $order_id );
983 $res = $wpdb->query( $query );
984
985 if ( $res ) {
986 $logger->flush();
987 return $checked;
988 } else {
989 return 'error';
990 }
991 }
992
993 function usces_update_orderdata() {
994 global $wpdb, $usces;
995
996 $_POST = $usces->stripslashes_deep_post( $_POST );
997
998 $order_table_name = $wpdb->prefix . 'usces_order';
999 $order_table_meta_name = $wpdb->prefix . 'usces_order_meta';
1000 $member_table_name = usces_get_tablename( 'usces_member' );
1001
1002 $ID = $_REQUEST['order_id'];
1003 $old_cart = usces_get_ordercartdata( $ID );
1004
1005 $query = $wpdb->prepare( "SELECT * FROM $order_table_name WHERE ID = %d", $ID );
1006 $old_orderdata = $wpdb->get_row( $query );
1007 $old_status = $old_orderdata->order_status;
1008
1009 if ( isset( $_POST['delButtonAdmin'] ) ) {
1010 foreach ( $_POST['delButtonAdmin'] as $del_cart_id => $delvalue ) {
1011 do_action( 'usces_admin_delete_orderrow', $del_cart_id, $ID, $old_cart );
1012 usces_delete_ordercartdata( $del_cart_id, NULL );
1013 }
1014 } else {
1015 usces_update_ordercartdata( $ID );
1016 }
1017
1018 $new_cart = usces_get_ordercartdata( $ID );
1019 $gmtdate = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) );
1020
1021 $item_total_price = $usces->get_total_price( $new_cart );
1022 $taio = isset( $_POST['offer']['taio'] ) ? $_POST['offer']['taio'] : '';
1023 $receipt = isset( $_POST['offer']['receipt'] ) ? $_POST['offer']['receipt'] : '';
1024 $admin = isset( $_POST['offer']['admin'] ) ? $_POST['offer']['admin'] : '';
1025 $status = $usces->make_status( $taio, $receipt, $admin );
1026 if ( 'completion' === $taio || 'continuation' === $taio ) {
1027 if ( 'update' === $_POST['up_modified'] ) {
1028 $order_modified = substr( $gmtdate, 0, 10 );
1029 } else {
1030 $order_modified = $_POST['modified'];
1031 }
1032 } else {
1033 $order_modified = '';
1034 }
1035 $order_modified = apply_filters( 'usces_filter_update_orderdata_modified', $order_modified, $taio, $gmtdate, $old_orderdata );
1036 $ordercheck = isset( $_POST['check'] ) ? serialize( $_POST['check'] ) : '';
1037 $member_id = isset( $_POST['member_id'] ) ? $_POST['member_id'] : 0;
1038
1039 if ( 'cancel' === $taio ) {
1040 $query = $wpdb->prepare(
1041 "UPDATE $order_table_name SET `order_modified` = %s, `order_status` = %s WHERE ID = %d",
1042 $order_modified, $status, $ID
1043 );
1044 $res[0] = $wpdb->query( $query );
1045
1046 $query = $wpdb->prepare( "SELECT * FROM $order_table_name WHERE ID = %d", $ID );
1047 $new_orderdata = $wpdb->get_row( $query );
1048
1049 if ( 'activate' == $usces->options['membersystem_state'] && 'activate' === $usces->options['membersystem_point'] && ! empty( $member_id ) && ! $usces->is_status( 'cancel', $old_status ) ) {
1050 $point = 0;
1051 if ( 0 < $old_orderdata->order_getpoint ) {
1052 if ( usces_is_complete_settlement( $old_orderdata->order_payment_name, $old_orderdata->order_status ) || $usces->is_status( 'receipted', $old_orderdata->order_status ) ) {
1053 $point += $old_orderdata->order_getpoint;
1054 }
1055 }
1056 if ( 0 < $old_orderdata->order_usedpoint ) {
1057 $point -= $old_orderdata->order_usedpoint;
1058 }
1059 if ( 0 !== $point ) {
1060 usces_restore_point( $member_id, $point );
1061 }
1062 }
1063
1064 do_action( 'usces_action_update_orderdata', $new_orderdata, $old_status, $old_orderdata, $new_cart, $old_cart );
1065
1066 return 1;
1067 }
1068
1069 $old_deli = unserialize( $old_orderdata->order_delivery );
1070 foreach ( (array) $_POST['delivery'] as $dk => $dv ) {
1071 $old_deli[ $dk ] = $dv;
1072 }
1073 $delivery = serialize( $old_deli );
1074
1075 $delivery_date = ( isset( $_POST['offer']['delivery_date'] ) ) ? $_POST['offer']['delivery_date'] : '';
1076 if ( ! usces_is_date( $delivery_date ) ) {
1077 $delivery_date = apply_filters( 'usces_filter_label_delivery_date_no_preference', __( 'Non-request', 'usces_dual' ) );
1078 }
1079
1080 $query = $wpdb->prepare(
1081 "UPDATE $order_table_name SET
1082 `mem_id`=%d, `order_email`=%s, `order_name1`=%s, `order_name2`=%s, `order_name3`=%s, `order_name4`=%s,
1083 `order_zip`=%s, `order_pref`=%s, `order_address1`=%s, `order_address2`=%s, `order_address3`=%s,
1084 `order_tel`=%s, `order_fax`=%s, `order_delivery`=%s, `order_note`=%s,
1085 `order_delivery_method`=%d, `order_delivery_date`=%s, `order_delivery_time`=%s, `order_payment_name`=%s, `order_item_total_price`=%f, `order_getpoint`=%d, `order_usedpoint`=%d,
1086 `order_discount`=%f, `order_shipping_charge`=%f, `order_cod_fee`=%f, `order_tax`=%f, `order_modified`=%s,
1087 `order_status`=%s, `order_delidue_date`=%s, `order_check`=%s
1088 WHERE ID = %d",
1089 $member_id,
1090 $_POST['customer']['mailaddress'],
1091 $_POST['customer']['name1'],
1092 $_POST['customer']['name2'],
1093 ( isset( $_POST['customer']['name3'] ) ? $_POST['customer']['name3'] : '' ),
1094 ( isset( $_POST['customer']['name4'] ) ? $_POST['customer']['name4'] : '' ),
1095 $_POST['customer']['zipcode'],
1096 $_POST['customer']['pref'],
1097 $_POST['customer']['address1'],
1098 $_POST['customer']['address2'],
1099 $_POST['customer']['address3'],
1100 $_POST['customer']['tel'],
1101 $_POST['customer']['fax'],
1102 $delivery,
1103 $_POST['offer']['note'],
1104 $_POST['offer']['delivery_method'],
1105 $delivery_date,
1106 $_POST['offer']['delivery_time'],
1107 $_POST['offer']['payment_name'],
1108 $item_total_price,
1109 $_POST['offer']['getpoint'],
1110 $_POST['offer']['usedpoint'],
1111 $_POST['offer']['discount'],
1112 $_POST['offer']['shipping_charge'],
1113 $_POST['offer']['cod_fee'],
1114 $_POST['offer']['tax'],
1115 $order_modified,
1116 $status,
1117 $_POST['offer']['delidue_date'],
1118 $ordercheck,
1119 $ID
1120 );
1121
1122 $res[0] = $wpdb->query( $query );
1123 if ( false === $res[0] ) {
1124 return false;
1125 }
1126
1127 $usces->set_order_meta_value( 'customer_country', $_POST['customer']['country'], $ID );
1128
1129 if ( usces_is_tax_display() && usces_is_reduced_taxrate( $ID ) ) {
1130 $usces->del_order_meta( 'subtotal_standard', $ID );
1131 $usces->del_order_meta( 'subtotal_reduced', $ID );
1132 $usces->del_order_meta( 'discount_standard', $ID );
1133 $usces->del_order_meta( 'discount_reduced', $ID );
1134 $usces->del_order_meta( 'tax_standard', $ID );
1135 $usces->del_order_meta( 'tax_reduced', $ID );
1136 if ( isset( $_POST['order_subtotal_standard'] ) && isset( $_POST['order_subtotal_reduced'] ) && isset( $_POST['order_discount_standard'] ) && isset( $_POST['order_discount_reduced'] ) && isset( $_POST['order_tax_standard'] ) && isset( $_POST['order_tax_reduced'] ) ) {
1137 $usces->set_order_meta_value( 'subtotal_standard', $_POST['order_subtotal_standard'], $ID );
1138 $usces->set_order_meta_value( 'subtotal_reduced', $_POST['order_subtotal_reduced'], $ID );
1139 $usces->set_order_meta_value( 'discount_standard', $_POST['order_discount_standard'], $ID );
1140 $usces->set_order_meta_value( 'discount_reduced', $_POST['order_discount_reduced'], $ID );
1141 if ( 'include' === $usces->options['tax_mode'] ) {
1142 $usces->set_order_meta_value( 'tax_standard', 0, $ID );
1143 $usces->set_order_meta_value( 'tax_reduced', 0, $ID );
1144 } else {
1145 $usces->set_order_meta_value( 'tax_standard', $_POST['order_tax_standard'], $ID );
1146 $usces->set_order_meta_value( 'tax_reduced', $_POST['order_tax_reduced'], $ID );
1147 }
1148 } else {
1149 $usces_tax = Welcart_Tax::get_instance();
1150 $materials = array(
1151 'total_items_price' => $item_total_price,
1152 'discount' => $_POST['offer']['discount'],
1153 'shipping_charge' => $_POST['offer']['shipping_charge'],
1154 'cod_fee' => $_POST['offer']['cod_fee'],
1155 'use_point' => $_POST['offer']['usedpoint'],
1156 'carts' => $new_cart,
1157 'condition' => $old_orderdata->order_condition,
1158 );
1159 $usces_tax->get_order_tax( $materials );
1160 $usces->set_order_meta_value( 'subtotal_standard', $usces_tax->subtotal_standard, $ID );
1161 $usces->set_order_meta_value( 'subtotal_reduced', $usces_tax->subtotal_reduced, $ID );
1162 $usces->set_order_meta_value( 'discount_standard', $usces_tax->discount_standard, $ID );
1163 $usces->set_order_meta_value( 'discount_reduced', $usces_tax->discount_reduced, $ID );
1164 if ( 'include' === $usces->options['tax_mode'] ) {
1165 $usces->set_order_meta_value( 'tax_standard', 0, $ID );
1166 $usces->set_order_meta_value( 'tax_reduced', 0, $ID );
1167 } else {
1168 $usces->set_order_meta_value( 'tax_standard', $usces_tax->tax_standard, $ID );
1169 $usces->set_order_meta_value( 'tax_reduced', $usces_tax->tax_reduced, $ID );
1170 }
1171 }
1172 }
1173
1174 $csod_meta = usces_has_custom_field_meta( 'order' );
1175 if ( is_array( $csod_meta ) ) {
1176 foreach ( $csod_meta as $key => $entry ) {
1177 if ( 4 === (int) $entry['means'] ) {
1178 $usces->del_order_meta( 'csod_' . $key, $ID );
1179 }
1180 }
1181 }
1182 $cscs_meta = usces_has_custom_field_meta( 'customer' );
1183 if ( is_array( $cscs_meta ) ) {
1184 foreach ( $cscs_meta as $key => $entry ) {
1185 if ( 4 === (int) $entry['means'] ) {
1186 $usces->del_order_meta( 'cscs_' . $key, $ID );
1187 }
1188 }
1189 }
1190 $csde_meta = usces_has_custom_field_meta( 'delivery' );
1191 if ( is_array( $csde_meta ) ) {
1192 foreach ( $csde_meta as $key => $entry ) {
1193 if ( 4 === (int) $entry['means'] ) {
1194 $usces->del_order_meta( 'csde_' . $key, $ID );
1195 }
1196 }
1197 }
1198 $i = 1;
1199 if ( ! empty( $_POST['custom_order'] ) ) {
1200 foreach ( $_POST['custom_order'] as $key => $value ) {
1201 $csod_key = 'csod_' . $key;
1202 if ( is_array( $value ) ) {
1203 $value = serialize( $value );
1204 }
1205 $res[ $i ] = $usces->set_order_meta_value( $csod_key, $value, $ID );
1206 if ( false === $res[ $i ] ) {
1207 return false;
1208 }
1209 $i++;
1210 }
1211 }
1212 if ( ! empty ( $_POST['custom_customer'] ) ) {
1213 foreach ( $_POST['custom_customer'] as $key => $value ) {
1214 $cscs_key = 'cscs_' . $key;
1215 if ( is_array( $value ) ) {
1216 $value = serialize( $value );
1217 }
1218 $res[ $i ] = $usces->set_order_meta_value( $cscs_key, $value, $ID );
1219 if ( false === $res[ $i ] ) {
1220 return false;
1221 }
1222 $i++;
1223 }
1224 }
1225 if ( ! empty( $_POST['custom_delivery'] ) ) {
1226 foreach ( $_POST['custom_delivery'] as $key => $value ) {
1227 $csde_key = 'csde_' . $key;
1228 if ( is_array( $value ) ) {
1229 $value = serialize( $value );
1230 }
1231 $res[ $i ] = $usces->set_order_meta_value( $csde_key, $value, $ID );
1232 if ( false === $res[ $i ] ) {
1233 return false;
1234 }
1235 $i++;
1236 }
1237 }
1238
1239 if ( ! preg_match( '/pending|noreceipt/', $old_status ) && preg_match( '/pending|noreceipt/', $status ) ) {
1240 $rquery = $wpdb->prepare( "DELETE FROM $order_table_meta_name WHERE order_id = %d AND meta_key = %s", $ID, 'receipted_date' );
1241 $wpdb->query( $rquery );
1242 } elseif ( ! preg_match( '/pending|noreceipt/', $old_status ) && ! preg_match( '/pending|noreceipt/', $status ) ) {
1243 $query = $wpdb->prepare( "SELECT order_id FROM $order_table_meta_name WHERE order_id = %d AND meta_key = %s", $ID, 'receipted_date' );
1244 $varres = $wpdb->get_var( $query );
1245 if ( empty( $varres ) ) {
1246 $usces->set_order_meta_value( 'receipted_date', $gmtdate, $ID );
1247 }
1248 } elseif ( preg_match( '/pending|noreceipt/', $old_status ) && ! preg_match( '/pending|noreceipt/', $status ) ) {
1249 $usces->set_order_meta_value( 'receipted_date', $gmtdate, $ID );
1250 }
1251
1252 if ( 'activate' === $usces->options['membersystem_state'] && 'activate' === $usces->options['membersystem_point'] && ! empty( $member_id ) ) {
1253 $point = 0;
1254 $getpoint = ( ! empty( $_POST['offer']['getpoint'] ) ) ? (int) $_POST['offer']['getpoint'] : 0;
1255 $usedpoint = ( ! empty( $_POST['offer']['usedpoint'] ) ) ? (int) $_POST['offer']['usedpoint'] : 0;
1256 if ( $usces->is_status( 'cancel', $old_status ) && ! $usces->is_status( 'cancel', $status ) ) { // キャンセル→新規受付・取り寄せ中・発送済み.
1257 if ( 0 < $getpoint ) {
1258 if ( usces_is_complete_settlement( $_POST['offer']['payment_name'], $status ) || $usces->is_status( 'receipted', $status ) ) {
1259 $point -= $getpoint;
1260 }
1261 }
1262 if ( 0 < $usedpoint ) {
1263 $point += $usedpoint;
1264 }
1265 } else {
1266 if ( ! usces_is_complete_settlement( $_POST['offer']['payment_name'] ) ) {
1267 if ( ! preg_match( '/pending|noreceipt/', $old_status ) && preg_match( '/pending|noreceipt/', $status ) ) { // �
1268 �金→未�
1269 �金.
1270 $point += $getpoint; // ポイント取消.
1271 } elseif ( preg_match( '/pending|noreceipt/', $old_status ) && !preg_match( '/pending|noreceipt/', $status ) ) { // 未�
1272 �金→�
1273 �金.
1274 $point -= $getpoint; // ポイント追加.
1275 } elseif ( preg_match( '/pending|noreceipt/', $old_status ) && preg_match( '/pending|noreceipt/', $status ) ) { // 未�
1276 �金→未�
1277 �金.
1278 $point = 0; // ポイント追加.
1279 } else {
1280 if ( $old_orderdata->order_getpoint != $getpoint ) {
1281 $point += $old_orderdata->order_getpoint - $getpoint;
1282 }
1283 }
1284 } else {
1285 if ( $old_orderdata->order_getpoint != $getpoint ) {
1286 $point += $old_orderdata->order_getpoint - $getpoint;
1287 }
1288 }
1289 if ( $old_orderdata->order_usedpoint != $usedpoint ) {
1290 $point -= $old_orderdata->order_usedpoint - $usedpoint;
1291 }
1292 }
1293 if ( 0 != $point ) {
1294 usces_restore_point( $member_id, $point );
1295 }
1296 }
1297
1298 $result = ( 0 < array_sum( array_filter( $res, 'is_numeric' ) ) ) ? 1 : 0;
1299
1300 $query = $wpdb->prepare( "SELECT * FROM $order_table_name WHERE ID = %d", $ID );
1301 $new_orderdata = $wpdb->get_row( $query );
1302 do_action( 'usces_action_update_orderdata', $new_orderdata, $old_status, $old_orderdata, $new_cart, $old_cart );
1303 $usces->cart->crear_cart();
1304
1305 return $result;
1306 }
1307
1308 function usces_all_change_zaiko( &$obj ) {
1309 global $wpdb, $usces;
1310
1311 $ids = filter_input( INPUT_POST, 'listcheck', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
1312 $change = filter_input( INPUT_POST, 'change', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
1313 $zaiko = ( null !== $change && false !== $change ) ? (int) $change['word']['zaiko'] : 0;
1314 $status = true;
1315 foreach ( (array) $ids as $post_id ) {
1316 $skus = wel_get_skus( $post_id, 'sort', false );
1317 foreach ( (array) $skus as $sku ) {
1318 $res = usces_update_sku( $post_id, $sku['code'], 'stock', $zaiko );
1319 if ( ! $res ) {
1320 $status = false;
1321 }
1322 }
1323 }
1324
1325 if ( true === $status ) {
1326 $obj->set_action_status( 'success', __( 'I completed collective operation.', 'usces' ) );
1327 } elseif ( false === $status ) {
1328 $obj->set_action_status( 'error', __( 'ERROR: I was not able to complete collective operation', 'usces' ) );
1329 } else {
1330 $obj->set_action_status( 'none', '' );
1331 }
1332 }
1333
1334 function usces_all_change_itemdisplay( &$obj ) {
1335 global $wpdb;
1336
1337 $ids = $_POST['listcheck'];
1338 $post_status = $_POST['change']['word']['display_status'];
1339 $status = true;
1340 foreach ( (array) $ids as $post_id ) {
1341 $post_data = array( 'ID' => $post_id, 'post_status' => $post_status );
1342 $res = wp_update_post( $post_data );
1343 if ( 0 === $res ) {
1344 $status = false;
1345 }
1346 }
1347 if ( true === $status ) {
1348 $obj->set_action_status( 'success', __( 'I completed collective operation.', 'usces' ) );
1349 } elseif ( false === $status ) {
1350 $obj->set_action_status( 'error', __( 'ERROR: I was not able to complete collective operation', 'usces' ) );
1351 } else {
1352 $obj->set_action_status( 'none', '' );
1353 }
1354 }
1355
1356 function usces_all_change_order_reciept( &$obj ) {
1357 global $wpdb, $usces;
1358
1359 $tableName = $wpdb->prefix . 'usces_order';
1360 $ids = $_POST['listcheck'];
1361 if ( isset( $_REQUEST['change']['word'] ) && ! is_array( $_REQUEST['change']['word'] ) ) {
1362 $change_word = $_REQUEST['change']['word'];
1363 } elseif ( isset( $_REQUEST['change']['word']['order_reciept'] ) ) {
1364 $change_word = $_REQUEST['change']['word']['order_reciept'];
1365 } else {
1366 $change_word = '';
1367 }
1368 $status = true;
1369 foreach ( (array) $ids as $id ) {
1370 $logger = Logger::start( $id, 'orderlist', 'update' );
1371 $query = $wpdb->prepare( "SELECT order_status, mem_id, order_getpoint, order_payment_name FROM $tableName WHERE ID = %d", $id );
1372 $order_res = $wpdb->get_row( $query, ARRAY_A );
1373 $statusstr = $order_res['order_status'];
1374 $restore_point = false;
1375 $getpoint = $order_res['order_getpoint'];
1376 if ( false !== strpos( $statusstr, 'cancel' ) ) {
1377 continue;
1378 }
1379 if ( false === strpos( $statusstr, 'noreceipt' ) && false === strpos( $statusstr, 'receipted' ) ) {
1380 continue;
1381 }
1382 $old_status = $statusstr;
1383 if ( $change_word == 'receipted' ) {
1384 if ( false !== strpos( $statusstr, 'noreceipt' ) ) { // 未�
1385 �金→�
1386 �金.
1387 $statusstr = str_replace( 'noreceipt', 'receipted', $statusstr );
1388 if ( ! usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
1389 $restore_point = true;
1390 $getpoint = $getpoint * -1; // add point.
1391 }
1392 }
1393 } elseif ( $change_word == 'noreceipt' ) {
1394 if ( false !== strpos( $statusstr, 'receipted' ) ) { // �
1395 �金済み→未�
1396 �金.
1397 $statusstr = str_replace( 'receipted', 'noreceipt', $statusstr );
1398 if ( ! usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
1399 $restore_point = true;
1400 }
1401 }
1402 }
1403 $query = $wpdb->prepare( "UPDATE $tableName SET order_status = %s WHERE ID = %d", $statusstr, $id );
1404 $res = $wpdb->query( $query );
1405 if ( false === $res ) {
1406 $status = false;
1407 }
1408 if ( 'activate' === $usces->options['membersystem_state'] && 'activate' === $usces->options['membersystem_point'] ) {
1409 if ( ! empty( $order_res['mem_id'] ) && 0 < $order_res['order_getpoint'] ) {
1410 if ( $res && $restore_point ) {
1411 usces_restore_point( $order_res['mem_id'], $getpoint );
1412 }
1413 }
1414 }
1415 if ( $status ) {
1416 do_action( 'usces_action_collective_order_reciept_each', $id, $statusstr, $old_status );
1417 }
1418 if ( ! empty( $res ) ) {
1419 $logger->flush();
1420 }
1421 }
1422 if ( true === $status ) {
1423 $obj->set_action_status( 'success', __( 'I completed collective operation.', 'usces' ) );
1424 } elseif ( false === $status ) {
1425 $obj->set_action_status( 'error', __( 'ERROR: I was not able to complete collective operation', 'usces' ) );
1426 } else {
1427 $obj->set_action_status( 'none', '' );
1428 }
1429 do_action( 'usces_action_collective_order_reciept', array( &$obj ) );
1430 }
1431
1432 function usces_all_change_order_status( &$obj ) {
1433 global $wpdb, $usces;
1434
1435 $tableName = $wpdb->prefix . 'usces_order';
1436 $ids = $_POST['listcheck'];
1437 foreach ( (array) $ids as $id ) {
1438 $status = true;
1439 $query = $wpdb->prepare( "SELECT order_status, mem_id, order_getpoint, order_usedpoint, order_payment_name FROM $tableName WHERE ID = %d", $id );
1440 $order_res = $wpdb->get_row( $query, ARRAY_A );
1441 $statusstr = $order_res['order_status'];
1442 $restore_point = false;
1443 $getpoint = $order_res['order_getpoint'];
1444 $usedpoint = $order_res['order_usedpoint'];
1445 $old_status = $statusstr;
1446 if ( isset( $_REQUEST['change']['word'] ) && ! is_array( $_REQUEST['change']['word'] ) ) {
1447 $change_word = $_REQUEST['change']['word'];
1448 } elseif ( isset( $_REQUEST['change']['word']['order_reciept'] ) ) {
1449 $change_word = $_REQUEST['change']['word']['order_reciept'];
1450 } elseif ( isset( $_REQUEST['change']['word']['order_status'] ) ) {
1451 $change_word = $_REQUEST['change']['word']['order_status'];
1452 } else {
1453 $change_word = '';
1454 }
1455 $query = '';
1456 switch ( $change_word ) {
1457 case 'estimate':
1458 if ( false !== strpos( $statusstr, 'adminorder' ) ) {
1459 $statusstr = str_replace( 'adminorder', 'estimate', $statusstr );
1460 } elseif ( false === strpos( $statusstr, 'estimate' ) ) {
1461 if ( ',' !== substr( $statusstr, -1 ) ) {
1462 $statusstr .= ',';
1463 }
1464 $statusstr .= 'estimate,';
1465 }
1466 if ( false === strpos( $statusstr, 'cancel' ) ) {
1467 if ( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
1468 $restore_point = true;
1469 $usedpoint = $usedpoint * -1; // add point.
1470 } elseif ( $usces->is_status( 'receipted', $order_res['order_status'] ) ) {
1471 $restore_point = true;
1472 $usedpoint = $usedpoint * -1; // add point.
1473 }
1474 }
1475 $query = $wpdb->prepare( "UPDATE $tableName SET order_status = %s WHERE ID = %d", $statusstr, $id );
1476 break;
1477 case 'adminorder':
1478 if ( false !== strpos( $statusstr, 'estimate' ) ) {
1479 $statusstr = str_replace( 'estimate', 'adminorder', $statusstr );
1480 if ( false === strpos( $statusstr, 'cancel' ) ) {
1481 if ( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
1482 $restore_point = true;
1483 $getpoint = $getpoint * -1; // add point.
1484 } elseif ( $usces->is_status( 'receipted', $order_res['order_status'] ) ) {
1485 $restore_point = true;
1486 $getpoint = $getpoint * -1; //add point.
1487 }
1488 }
1489 } elseif ( false === strpos( $statusstr, 'adminorder' ) ) {
1490 if ( ',' !== substr( $statusstr, -1 ) ) {
1491 $statusstr .= ',';
1492 }
1493 $statusstr .= 'adminorder,';
1494 }
1495 $query = $wpdb->prepare( "UPDATE $tableName SET order_status = %s WHERE ID = %d", $statusstr, $id );
1496 break;
1497 case 'frontorder':
1498 if ( false !== strpos( $statusstr, 'estimate' ) ) {
1499 $statusstr = str_replace( 'estimate,', '', $statusstr );
1500 $statusstr = trim( $statusstr, ',' );
1501 if ( false === strpos( $statusstr, 'cancel' ) ) {
1502 if ( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
1503 $restore_point = true;
1504 $getpoint = $getpoint * -1; // add point.
1505 } elseif ( $usces->is_status( 'receipted', $order_res['order_status'] ) ) {
1506 $restore_point = true;
1507 $getpoint = $getpoint * -1; // add point.
1508 }
1509 }
1510 } elseif ( false !== strpos( $statusstr, 'adminorder' ) ) {
1511 $statusstr = str_replace( 'adminorder,', '', $statusstr );
1512 $statusstr = trim( $statusstr, ',' );
1513 }
1514 $query = $wpdb->prepare( "UPDATE $tableName SET order_status = %s WHERE ID = %d", $statusstr, $id );
1515 break;
1516 case 'duringorder':
1517 if ( false !== strpos( $statusstr, 'cancel' ) ) {
1518 $statusstr = str_replace( 'cancel', '', $statusstr );
1519 $statusstr = trim( $statusstr, ',' );
1520 if ( false === strpos( $statusstr, 'estimate' ) ) {
1521 if ( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
1522 $restore_point = true;
1523 $getpoint = $getpoint * -1; // add point.
1524 } elseif ( $usces->is_status( 'receipted', $order_res['order_status'] ) ) {
1525 $restore_point = true;
1526 $getpoint = $getpoint * -1; // add point.
1527 }
1528 }
1529 }
1530 if ( false !== strpos( $statusstr, 'completion' ) ) {
1531 $statusstr = str_replace( 'completion', '', $statusstr );
1532 $statusstr = trim( $statusstr, ',' );
1533 }
1534 if ( false !== strpos( $statusstr, 'new' ) ) {
1535 $statusstr = str_replace( 'new', '', $statusstr );
1536 $statusstr = trim( $statusstr, ',' );
1537 }
1538 if ( false === strpos( $statusstr, 'duringorder' ) ) {
1539 if ( ',' !== substr( $statusstr, -1 ) ) {
1540 $statusstr .= ',';
1541 }
1542 $statusstr .= 'duringorder,';
1543 }
1544 $query = $wpdb->prepare( "UPDATE $tableName SET order_status = %s WHERE ID = %d", $statusstr, $id );
1545 break;
1546 case 'cancel':
1547 if ( false !== strpos( $statusstr, 'completion' ) ) {
1548 $statusstr = str_replace( 'completion', '', $statusstr );
1549 $statusstr = trim( $statusstr, ',' );
1550 }
1551 if ( false !== strpos( $statusstr, 'new' ) ) {
1552 $statusstr = str_replace( 'new', '', $statusstr );
1553 $statusstr = trim( $statusstr, ',' );
1554 }
1555 if ( false !== strpos( $statusstr, 'duringorder' ) ) {
1556 $statusstr = str_replace( 'duringorder', '', $statusstr );
1557 $statusstr = trim( $statusstr, ',' );
1558 }
1559 if ( false === strpos( $statusstr, 'cancel' ) ) {
1560 if ( ',' !== substr( $statusstr, -1 ) ) {
1561 $statusstr .= ',';
1562 }
1563 $statusstr .= 'cancel,';
1564 }
1565 if ( false === strpos( $statusstr, 'estimate' ) ) {
1566 if ( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
1567 $restore_point = true;
1568 $usedpoint = $usedpoint * -1; // add point.
1569 } elseif ( $usces->is_status( 'receipted', $order_res['order_status'] ) ) {
1570 $restore_point = true;
1571 $usedpoint = $usedpoint * -1; // add point.
1572 }
1573 }
1574 $query = $wpdb->prepare( "UPDATE $tableName SET order_status = %s WHERE ID = %d", $statusstr, $id );
1575 break;
1576 case 'completion':
1577 if ( false !== strpos( $statusstr, 'new' ) ) {
1578 $statusstr = str_replace( 'new', '', $statusstr );
1579 $statusstr = trim( $statusstr, ',' );
1580 }
1581 if ( false !== strpos( $statusstr, 'duringorder' ) ) {
1582 $statusstr = str_replace( 'duringorder', '', $statusstr );
1583 $statusstr = trim( $statusstr, ',' );
1584 }
1585 if ( false !== strpos( $statusstr, 'cancel' ) ) {
1586 $statusstr = str_replace( 'cancel', '', $statusstr );
1587 $statusstr = trim( $statusstr, ',' );
1588 if ( false === strpos( $statusstr, 'estimate' ) ) {
1589 if ( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
1590 $restore_point = true;
1591 $getpoint = $getpoint * -1; // add point.
1592 } elseif ( $usces->is_status( 'receipted', $order_res['order_status'] ) ) {
1593 $restore_point = true;
1594 $getpoint = $getpoint * -1; // add point.
1595 }
1596 }
1597 }
1598 if ( false === strpos( $statusstr, 'completion' ) ) {
1599 if ( ',' !== substr( $statusstr, -1 ) ) {
1600 $statusstr .= ',';
1601 }
1602 $statusstr .= 'completion,';
1603 }
1604 $query = $wpdb->prepare( "UPDATE $tableName SET order_status = %s, order_modified = %s WHERE ID = %d", $statusstr, substr( current_time( 'mysql' ), 0, 10 ), $id );
1605 break;
1606 case 'new':
1607 case 'neworder':
1608 if ( false !== strpos( $statusstr, 'duringorder' ) ) {
1609 $statusstr = str_replace( 'duringorder,', '', $statusstr );
1610 $statusstr = trim( $statusstr, ',' );
1611 }
1612 if ( false !== strpos( $statusstr, 'completion' ) ) {
1613 $statusstr = str_replace( 'completion,', '', $statusstr );
1614 $statusstr = trim( $statusstr, ',' );
1615 }
1616 if ( false !== strpos( $statusstr, 'cancel' ) ) {
1617 $statusstr = str_replace( 'cancel,', '', $statusstr );
1618 $statusstr = trim( $statusstr, ',' );
1619 if ( false === strpos( $statusstr, 'estimate' ) ) {
1620 if ( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
1621 $restore_point = true;
1622 $getpoint = $getpoint * -1; // add point.
1623 } elseif ( $usces->is_status( 'receipted', $order_res['order_status'] ) ) {
1624 $restore_point = true;
1625 $getpoint = $getpoint * -1; // add point.
1626 }
1627 }
1628 }
1629 $query = $wpdb->prepare( "UPDATE $tableName SET order_status = %s WHERE ID = %d", $statusstr, $id );
1630 break;
1631 default:
1632 $query = apply_filters( 'usces_filter_collective_order_status_query', $query, $statusstr, $id );
1633 }
1634 if ( ! empty ( $query ) ) {
1635 $logger = Logger::start( $id, 'orderlist', 'update' );
1636 $res = $wpdb->query( $query );
1637 if ( false === $res ) {
1638 $status = false;
1639 }
1640 if ( 'activate' === $usces->options['membersystem_state'] && 'activate' === $usces->options['membersystem_point'] ) {
1641 if ( ! empty( $order_res['mem_id'] ) && ( 0 < $order_res['order_getpoint'] || 0 < $order_res['order_usedpoint'] ) ) {
1642 if ( $res && $restore_point ) {
1643 usces_restore_point( $order_res['mem_id'], $getpoint + $usedpoint );
1644 }
1645 }
1646 }
1647 if ( $status ) {
1648 do_action( 'usces_action_collective_order_status_each', $id, $statusstr, $old_status );
1649 $logger->flush();
1650 }
1651 }
1652 }
1653 if ( true === $status ) {
1654 $obj->set_action_status( 'success', __( 'I completed collective operation.', 'usces' ) );
1655 } elseif ( false === $status ) {
1656 $obj->set_action_status( 'error', __( 'ERROR: I was not able to complete collective operation', 'usces' ) );
1657 } else {
1658 $obj->set_action_status( 'none', '' );
1659 }
1660 do_action( 'usces_action_collective_order_status', array( &$obj ) );
1661 }
1662
1663 function usces_all_delete_order_data( &$obj ) {
1664 global $wpdb, $usces;
1665
1666 $tableName = $wpdb->prefix . 'usces_order';
1667 $tableMetaName = $wpdb->prefix . 'usces_order_meta';
1668 $ids = $_POST['listcheck'];
1669 $status = true;
1670 foreach ( (array) $ids as $id ) {
1671 $del = usces_delete_order_check( $id );
1672 if ( false === $del ) {
1673 continue;
1674 }
1675 $logger = Logger::start( $id, 'orderlist', 'delete' );
1676 $point = 0;
1677 $query = $wpdb->prepare( "SELECT * FROM $tableName WHERE ID = %d", $id );
1678 $order_res = $wpdb->get_row( $query, ARRAY_A );
1679 if ( 'activate' === $usces->options['membersystem_state'] && 'activate' === $usces->options['membersystem_point'] && ! empty( $order_res['mem_id'] ) && ! $usces->is_status( 'cancel', $order_res['order_status'] ) ) {
1680 if ( 0 < $order_res['order_getpoint'] ) {
1681 if ( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) || $usces->is_status( 'receipted', $order_res['order_status'] ) ) {
1682 $point += $order_res['order_getpoint'];
1683 }
1684 }
1685 if ( 0 < $order_res['order_usedpoint'] ) {
1686 $point -= $order_res['order_usedpoint'];
1687 }
1688 }
1689 $query = $wpdb->prepare( "DELETE FROM $tableName WHERE ID = %d", $id );
1690 $res = $wpdb->query( $query );
1691 if ( false === $res ) {
1692 $status = false;
1693 } else {
1694
1695 if ( 0 != $point ) {
1696 usces_restore_point( $order_res['mem_id'], $point );
1697 }
1698
1699 do_action( 'usces_action_collective_order_delete_each', $id, $order_res );
1700
1701 usces_delete_ordercartdata( NULL, $id );
1702
1703 $metaquery = $wpdb->prepare( "DELETE FROM $tableMetaName WHERE order_id = %d", $id );
1704 $metares = $wpdb->query( $metaquery );
1705 $logger->flush();
1706 }
1707 }
1708 if ( true === $status ) {
1709 $obj->set_action_status( 'success', __( 'I completed collective operation.', 'usces' ) );
1710 } elseif ( false === $status ) {
1711 $obj->set_action_status( 'error', __( 'ERROR: I was not able to complete collective operation', 'usces' ) );
1712 } else {
1713 $obj->set_action_status( 'none', '' );
1714 }
1715 do_action( 'usces_action_collective_order_delete', array( &$obj ) );
1716 }
1717
1718 function usces_all_change_member_rank( &$obj ) {
1719 global $wpdb, $usces;
1720
1721 $tableName = usces_get_tablename( 'usces_member' );
1722 $ids = $_POST['listcheck'];
1723 $status = true;
1724
1725 foreach ( (array) $ids as $id ) {
1726 $logger = Logger::start( $id, 'memberlist', 'update' );
1727 $value = isset( $_REQUEST['change']['word'] ) ? $_REQUEST['change']['word'] : '';
1728 $query = $wpdb->prepare( "UPDATE $tableName SET mem_status = %d WHERE ID = %d", $value, $id );
1729 $res = $wpdb->query( $query );
1730 if ( false === $res ) {
1731 $status = false;
1732 }
1733 if ( $status ) {
1734 do_action( 'usces_action_collective_member_rank_each', $id, $value );
1735 }
1736 $logger->flush();
1737 }
1738
1739 if ( true === $status ) {
1740 $obj->set_action_status( 'success', __( 'I completed collective operation.', 'usces' ) );
1741 } elseif ( false === $status ) {
1742 $obj->set_action_status( 'error', __( 'ERROR: I was not able to complete collective operation', 'usces' ) );
1743 } else {
1744 $obj->set_action_status( 'none', '' );
1745 }
1746 do_action( 'usces_action_collective_member_rank', array( &$obj ) );
1747 }
1748
1749 function usces_all_change_member_point( &$obj ) {
1750 global $wpdb, $usces;
1751
1752 $tableName = usces_get_tablename( 'usces_member' );
1753 $ids = $_POST['listcheck'];
1754 $status = true;
1755
1756 foreach ( (array) $ids as $id ) {
1757 $logger = Logger::start( $id, 'memberlist', 'update' );
1758 $value = isset( $_REQUEST['change']['word'] ) ? $_REQUEST['change']['word'] : '';
1759 $query = $wpdb->prepare( "UPDATE $tableName SET mem_point = %d WHERE ID = %d", $value, $id );
1760 $res = $wpdb->query( $query );
1761 if ( false === $res ) {
1762 $status = false;
1763 }
1764 if ( $status ) {
1765 do_action( 'usces_action_collective_member_point_each', $id, $value );
1766 }
1767 $logger->flush();
1768 }
1769
1770 if ( true === $status ) {
1771 $obj->set_action_status( 'success', __( 'I completed collective operation.', 'usces' ) );
1772 } elseif ( false === $status ) {
1773 $obj->set_action_status( 'error', __( 'ERROR: I was not able to complete collective operation', 'usces' ) );
1774 } else {
1775 $obj->set_action_status( 'none', '' );
1776 }
1777 do_action( 'usces_action_collective_member_point', array( &$obj ) );
1778 }
1779
1780 function usces_all_delete_member_data( &$obj ) {
1781 global $wpdb, $usces;
1782
1783 $ids = $_POST['listcheck'];
1784 $status = true;
1785
1786 foreach ( (array) $ids as $id ) {
1787 $del = usces_delete_member_check( $id );
1788 if ( false === $del ) {
1789 continue;
1790 }
1791 $logger = Logger::start( $id, 'memberlist', 'delete');
1792 $old_data = $usces->get_member_info( $id );
1793 $res = usces_delete_memberdata( $id );
1794 if ( false === $res ) {
1795 $status = false;
1796 do_action( 'usces_action_collective_member_delete_each', $id, $old_data );
1797 } else {
1798 $logger->flush();
1799 }
1800 }
1801
1802 if ( true === $status ) {
1803 $obj->set_action_status( 'success', __( 'I completed collective operation.', 'usces' ) );
1804 } elseif ( false === $status ) {
1805 $obj->set_action_status( 'error', __( 'ERROR: I was not able to complete collective operation', 'usces' ) );
1806 } else {
1807 $obj->set_action_status( 'none', '' );
1808 }
1809 do_action( 'usces_action_collective_member_delete', array( &$obj ) );
1810 }
1811
1812 function usces_check_acting_return() {
1813 global $usces;
1814
1815 $entry = $usces->cart->get_entry();
1816
1817 $acting = ( isset( $_GET['acting'] ) ) ? $_GET['acting'] : '';
1818 $results = array();
1819 switch ( $acting ) {
1820 case 'epsilon':
1821 if ( isset( $_GET['duplicate'] ) && $_GET['duplicate'] == 1 ) {
1822 $results[0] = 'duplicate';
1823 } elseif ( isset( $_GET['result'] ) ) {
1824 $results[0] = (int) $_GET['result'];
1825 $results['reg_order'] = true;
1826 } else {
1827 $str = explode( '?', $_GET['acting_return'] );
1828 if ( ! isset( $str[1] ) ) {
1829 $results[0] = 0;
1830 } else {
1831 parse_str( $str[1], $para );
1832 $results[0] = isset( $para['result'] ) ? (int) $para['result'] : 0;
1833 foreach ( $para as $key => $value ) {
1834 $results[ $key ] = $value;
1835 }
1836 }
1837 }
1838 $results['reg_order'] = true;
1839 break;
1840
1841 case 'paypal':
1842 usces_log( 'paypal in ', 'acting_transaction.log' );
1843 $paypal_file = $usces->options['settlement_path'] . 'paypal.php';
1844 if ( file_exists( $paypal_file ) ) {
1845 require_once( $paypal_file );
1846 $results = paypal_check( $usces_paypal_url );
1847 remove_action( 'shutdown', array( &$usces, 'lastprocessing' ) );
1848 $results['reg_order'] = true;
1849 } else {
1850 $results['reg_order'] = true;
1851 }
1852 break;
1853
1854 case 'remise_card':
1855 $results = $_POST;
1856 if ( $_REQUEST['acting_return'] && ( isset( $_REQUEST['X-ERRCODE'] ) && ' ' === $_REQUEST['X-ERRCODE'] ) ) {
1857 usces_log( 'remise card entry data : ' . print_r( $entry, true ), 'acting_transaction.log' );
1858 $results[0] = 1;
1859 }else{
1860 $results[0] = 0;
1861 }
1862 if ( isset( $_REQUEST['dlseller_update'] ) ) {
1863 $results['reg_order'] = false;
1864 } else {
1865 $results['reg_order'] = true;
1866 }
1867 break;
1868
1869 case 'remise_conv':
1870 $results = $_GET;
1871 if ( $_REQUEST['acting_return'] && isset( $_REQUEST['X-JOB_ID'] ) && '0:0000' === $_REQUEST['X-R_CODE'] ) {
1872 $results[0] = 1;
1873 } else {
1874 $results[0] = 0;
1875 }
1876 $results['reg_order'] = true;
1877 break;
1878
1879 case 'jpayment_card':
1880 $results = $_GET;
1881 $rst = ( isset( $_GET['rst'] ) ) ? (int) $_GET['rst'] : 0;
1882 if ( 2 === $rst ) {
1883 usces_log( 'jpayment card error : ' . print_r( $entry, true ), 'acting_transaction.log' );
1884 $cod = ( isset( $_GET['cod'] ) ) ? $_GET['cod'] : '';
1885 $log = array(
1886 'acting' => $acting,
1887 'key' => $cod,
1888 'result' => $rst,
1889 'data' => $_GET,
1890 );
1891 usces_save_order_acting_error( $log );
1892 }
1893 $results[0] = ( 1 === $rst ) ? 1 : 0;
1894 $results['reg_order'] = true;
1895 break;
1896
1897 case 'jpayment_conv':
1898 $results = $_GET;
1899 $rst = ( isset( $_GET['rst'] ) ) ? (int) $_GET['rst'] : 0;
1900 if ( 2 === $rst ) {
1901 usces_log( 'jpayment conv error : ' . print_r( $entry, true ), 'acting_transaction.log' );
1902 $cod = ( isset( $_GET['cod'] ) ) ? $_GET['cod'] : '';
1903 $log = array(
1904 'acting' => $acting,
1905 'key' => $cod,
1906 'result' => $rst,
1907 'data' => $_GET,
1908 );
1909 usces_save_order_acting_error( $log );
1910 }
1911 $results[0] = ( 1 === $rst && 'CPL_PRE' === $_GET['ap'] ) ? 1 : 0;
1912 $results['reg_order'] = true;
1913 break;
1914
1915 case 'jpayment_bank':
1916 $results = $_GET;
1917 $rst = ( isset( $_GET['rst'] ) ) ? (int) $_GET['rst'] : 0;
1918 if ( 2 === $rst ) {
1919 usces_log( 'jpayment bank error : ' . print_r( $entry, true ), 'acting_transaction.log' );
1920 $cod = ( isset( $_GET['cod'] ) ) ? $_GET['cod'] : '';
1921 $log = array(
1922 'acting' => $acting,
1923 'key' => $cod,
1924 'result' => $rst,
1925 'data' => $_GET,
1926 );
1927 usces_save_order_acting_error( $log );
1928 }
1929 $results[0] = ( 1 === $rst ) ? 1 : 0;
1930 $results['reg_order'] = true;
1931 break;
1932
1933 case 'paypal_ec':
1934 $results = $_GET;
1935
1936 // Build a second API request to PayPal, using the token as the ID to get the details on the payment authorization.
1937 $req_token = isset( $_REQUEST['token'] ) ? $_REQUEST['token'] : '0';
1938 $nvpstr = '&TOKEN=' . urlencode( $req_token );
1939
1940 $usces->paypal->setMethod( 'GetExpressCheckoutDetails' );
1941 $usces->paypal->setData( $nvpstr );
1942 $res = $usces->paypal->doExpressCheckout();
1943 $resArray = $usces->paypal->getResponse();
1944 $ack = strtoupper( $resArray['ACK'] );
1945 if ( 'SUCCESS' === $ack || 'SUCCESSWITHWARNING' === $ack ) {
1946 if ( usces_have_continue_charge() ) {
1947 $results[0] = 1;
1948 } else {
1949 $amt = floor( $resArray['AMT'] * 100 );
1950 $total_full_price = usces_crform( $entry['order']['total_full_price'], false, false, 'return', false );
1951 $total_full_price = floor( $total_full_price * 100 );
1952 if ( $amt != $total_full_price ) {
1953 usces_log( 'PayPal : AMT Error. AMT=' . $resArray['AMT'] . ', total_full_price=' . $entry['order']['total_full_price'], 'acting_transaction.log' );
1954 $results[0] = 0;
1955 } else {
1956 $results[0] = 1;
1957 }
1958 }
1959
1960 } else {
1961 // Display a user friendly Error on the page using any of the following error information returned by PayPal.
1962 $ErrorCode = urldecode( $resArray['L_ERRORCODE0'] );
1963 $ErrorShortMsg = urldecode( $resArray['L_SHORTMESSAGE0'] );
1964 $ErrorLongMsg = urldecode( $resArray['L_LONGMESSAGE0'] );
1965 $ErrorSeverityCode = urldecode( $resArray['L_SEVERITYCODE0'] );
1966 usces_log( 'PayPal : GetExpressCheckoutDetails API call failed. Error Code:[' . $ErrorCode . '] Error Severity Code:[' . $ErrorSeverityCode . '] Short Error Message:' . $ErrorShortMsg . ' Detailed Error Message:' . $ErrorLongMsg, 'acting_transaction.log' );
1967 $results[0] = 0;
1968 }
1969 $results['reg_order'] = true;
1970 break;
1971
1972 case 'telecom_card':
1973 $results = $_GET;
1974 if ( $_REQUEST['result'] ) {
1975 usces_log( $acting . ' entry data : ' . print_r( $entry, true ), 'acting_transaction.log' );
1976 $results[0] = 1;
1977 } else {
1978 usces_log( $acting . ' error : ' . print_r( $_REQUEST, true ), 'acting_transaction.log' );
1979 $results[0] = 0;
1980 }
1981 $results['reg_order'] = true;
1982 break;
1983
1984 case 'digitalcheck_card':
1985 $results = $_REQUEST;
1986 if ( isset( $_REQUEST['SID'] ) ) {
1987 $results[0] = 1;
1988 } else {
1989 $results[0] = 0;
1990 }
1991 $results['reg_order'] = true;
1992 break;
1993 case 'digitalcheck_conv':
1994 $results = $_REQUEST;
1995 $results[0] = 1;
1996 $results['reg_order'] = false;
1997 break;
1998
1999 case 'mizuho_card':
2000 case 'mizuho_conv':
2001 $results = $_GET;
2002 if ( isset( $_GET['rsltcd'] ) ) {
2003 if ( '000' === substr( $_GET['rsltcd'], 0, 3 ) ) {
2004 $results[0] = 1;
2005 $results['reg_order'] = true;
2006 } else {
2007 $results[0] = 0;
2008 $results['reg_order'] = false;
2009 }
2010 } else {
2011 $results[0] = 0;
2012 $results['reg_order'] = false;
2013 }
2014 break;
2015
2016 case 'anotherlane_card':
2017 $results[0] = 1;
2018 $results['reg_order'] = false;
2019 break;
2020
2021 case 'veritrans_card':
2022 case 'veritrans_conv':
2023 $results[0] = ( isset( $_GET['result'] ) ) ? (int) $_GET['result'] : 0;
2024 $results['reg_order'] = false;
2025 break;
2026
2027 case 'paypal_wpp':
2028 $results[0] = 1;
2029 $results['reg_order'] = false;
2030 break;
2031
2032 default:
2033 do_action( 'usces_action_check_acting_return_default' );
2034 $results = $_REQUEST;
2035 if ( isset( $_REQUEST['result'] ) && true == $_REQUEST['result'] ) {
2036 usces_log( $acting . ' entry data : ' . print_r( $entry, true ), 'acting_transaction.log' );
2037 $results[0] = 1;
2038 } else {
2039 // usces_log( $acting . ' error : ' . print_r( $_REQUEST, true ), 'acting_transaction.log' ); Not necessarily an error.
2040 $results[0] = 0;
2041 }
2042 $results['reg_order'] = true;
2043 $results = apply_filters( 'usces_filter_check_acting_return_results', $results );
2044 break;
2045 }
2046
2047 return $results;
2048 }
2049
2050 function usces_check_acting_return_duplicate( $results = array() ) {
2051 global $wpdb;
2052
2053 $acting = isset( $_GET['acting'] ) ? $_GET['acting'] : '';
2054
2055 switch( $acting ) {
2056 case 'epsilon':
2057 $trans_id = isset( $_REQUEST['trans_code'] ) ? $_REQUEST['trans_code'] : '';
2058 $_REQUEST['absolute_trans_id'] = $_REQUEST['order_number'];
2059 break;
2060 case 'paypal':
2061 $trans_id = isset( $results['txn_id'] ) ? $results['txn_id'] : '';
2062 $_REQUEST['absolute_trans_id'] = $trans_id;
2063 break;
2064 case 'paypal_ipn':
2065 $trans_id = isset( $_REQUEST['txn_id'] ) ? $_REQUEST['txn_id'] : '';
2066 $_REQUEST['absolute_trans_id'] = $trans_id;
2067 break;
2068 case 'paypal_ec':
2069 $trans_id = isset( $_REQUEST['token'] ) ? $_REQUEST['token'] : '';
2070 $_REQUEST['absolute_trans_id'] = $trans_id;
2071 break;
2072 case 'remise_card':
2073 $trans_id = isset( $_REQUEST['X-TRANID'] ) ? $_REQUEST['X-TRANID'] : '';
2074 $_REQUEST['absolute_trans_id'] = $_REQUEST['X-S_TORIHIKI_NO'];
2075 break;
2076 case 'remise_conv':
2077 $trans_id = isset( $_REQUEST['X-JOB_ID'] ) ? $_REQUEST['X-JOB_ID'] : '';
2078 $_REQUEST['absolute_trans_id'] = $_REQUEST['X-S_TORIHIKI_NO'];
2079 break;
2080 case 'jpayment_card':
2081 case 'jpayment_conv':
2082 case 'jpayment_bank':
2083 $trans_id = isset( $_REQUEST['gid'] ) ? $_REQUEST['gid'] : '';
2084 $_REQUEST['absolute_trans_id'] = $trans_id;
2085 break;
2086 case 'telecom_card':
2087 $trans_id = isset( $_REQUEST['option'] ) ? $_REQUEST['option'] : '';
2088 $_REQUEST['absolute_trans_id'] = isset( $_REQUEST['option'] ) ? $_REQUEST['option'] : $trans_id;
2089 break;
2090 case 'digitalcheck_card':
2091 case 'digitalcheck_conv':
2092 $trans_id = isset( $_REQUEST['SID'] ) ? $_REQUEST['SID'] : '';
2093 $_REQUEST['absolute_trans_id'] = $trans_id;
2094 break;
2095 case 'mizuho_card':
2096 case 'mizuho_conv':
2097 $trans_id = isset( $_REQUEST['stran'] ) ? $_REQUEST['stran'] : '';
2098 $_REQUEST['absolute_trans_id'] = $trans_id;
2099 break;
2100 default:
2101 $trans_id = apply_filters( 'usces_filter_check_acting_return_duplicate', '', $results );
2102 $_REQUEST['absolute_trans_id'] = $trans_id;
2103 }
2104 $order_id = usces_get_order_id_by_trans_id( $trans_id );
2105 if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
2106 $_REQUEST['remote_addr'] = $_SERVER['REMOTE_ADDR'];
2107 }
2108 if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
2109 $_REQUEST['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
2110 }
2111
2112 return $order_id;
2113 }
2114
2115 function usces_get_order_id_by_trans_id( $trans_id ) {
2116 global $wpdb;
2117
2118 if ( empty( $trans_id ) ) {
2119 return false;
2120 }
2121
2122 $table_meta_name = $wpdb->prefix . 'usces_order_meta';
2123 $query = $wpdb->prepare( "SELECT order_id FROM $table_meta_name WHERE meta_key = %s AND meta_value = %s", 'trans_id', $trans_id );
2124 $order_id = $wpdb->get_var( $query );
2125 return $order_id;
2126 }
2127
2128 function usces_dates_interconv( $date_str ) {
2129 $base_struc = array( 'd', 'm', 'Y' );
2130 $date_str_parts = preg_split( '[/.-]', $date_str );
2131 $date_elements = array();
2132
2133 $p_keys = array_keys( $base_struc );
2134 foreach ( $p_keys as $p_key ) {
2135 if ( ! empty( $date_str_parts[ $p_key ] ) ) {
2136 $date_elements[ $base_struc[ $p_key ] ] = $date_str_parts[ $p_key ];
2137 } else {
2138 return false;
2139 }
2140 }
2141 $dummy_ts = mktime( 0, 0, 0, $date_elements['m'], $date_elements['d'], $date_elements['Y'] );
2142 return date( 'Y-m-d', $dummy_ts );
2143 }
2144
2145 function usces_register_action( $handle, $type, $key, $value, $function ) {
2146 global $usces_action;
2147 $usces_action[ $handle ] = array(
2148 'type' => $type,
2149 'key' => $key,
2150 'value' => $value,
2151 'function' => $function,
2152 );
2153 }
2154
2155 function usces_deregister_action( $handle ) {
2156 global $usces_action;
2157 unset( $usces_action[ $handle ] );
2158 }
2159
2160 function usces_update_check_admin( $result ) {
2161 $result = true;
2162 return $result;
2163 }
2164
2165 function usces_setup_cod_ajax() {
2166 global $usces;
2167
2168 // Verify nonce for security.
2169 check_ajax_referer( 'admin_setup', 'wc_nonce' );
2170
2171 // Check user capability.
2172 if ( ! current_user_can( 'wel_manage_setting' ) ) {
2173 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'usces' ), 403 );
2174 }
2175
2176 $usces->options = get_option( 'usces' );
2177 $message = '';
2178 $_POST = $usces->stripslashes_deep_post( $_POST );
2179
2180 $usces->options['cod_type'] = isset( $_POST['cod_type'] ) ? $_POST['cod_type'] : 'fix';
2181 if ( isset( $_POST['cod_fee'] ) ) {
2182 $usces->options['cod_fee'] = (int) $_POST['cod_fee'];
2183 }
2184 if ( 'fix' == $usces->options['cod_type'] ) {
2185 if ( isset( $_POST['cod_limit_amount'] ) ) {
2186 $usces->options['cod_limit_amount'] = (int) $_POST['cod_limit_amount'];
2187 if ( ! WCUtils::is_blank( $_POST['cod_limit_amount'] ) && 0 === (int) $_POST['cod_limit_amount'] ) {
2188 $message = __( 'There is the item where a value is dirty.', 'usces' );
2189 }
2190 } // phpcs:ignore Squiz.WhiteSpace.ControlStructureSpacing.SpacingAfterOpen
2191
2192 } elseif ( 'change' == $usces->options['cod_type'] ) {
2193 if ( isset( $_POST['cod_first_amount'] ) ) {
2194 $usces->options['cod_first_amount'] = (int) $_POST['cod_first_amount'];
2195 if ( 0 === (int) $_POST['cod_first_amount'] ) {
2196 $message = __( 'There is the item where a value is dirty.', 'usces' );
2197 }
2198 }
2199 if ( isset( $_POST['cod_limit_amount'] ) ) {
2200 $usces->options['cod_limit_amount'] = (int) $_POST['cod_limit_amount'];
2201 if ( ! WCUtils::is_blank( $_POST['cod_limit_amount'] ) && 0 === (int) $_POST['cod_limit_amount'] ) {
2202 $message = __( 'There is the item where a value is dirty.', 'usces' );
2203 }
2204 }
2205 if ( isset( $_POST['cod_first_fee'] ) ) {
2206 $usces->options['cod_first_fee'] = (int) $_POST['cod_first_fee'];
2207 if ( 0 === (int) $_POST['cod_first_fee'] && '0' !== $_POST['cod_first_fee'] ) {
2208 $message = __( 'There is the item where a value is dirty.', 'usces' );
2209 }
2210 }
2211 if ( isset( $_POST['cod_end_fee'] ) ) {
2212 $usces->options['cod_end_fee'] = (int) $_POST['cod_end_fee'];
2213 if ( 0 === (int) $_POST['cod_end_fee'] && '0' !== $_POST['cod_end_fee'] ) {
2214 $message = __( 'There is the item where a value is dirty.', 'usces' );
2215 }
2216 }
2217
2218 unset( $usces->options['cod_amounts'], $usces->options['cod_fees'] );
2219 if ( isset( $_POST['cod_amounts'] ) ) {
2220 $cod_amounts_count = ( is_array( $_POST['cod_amounts'] ) ) ? count( $_POST['cod_amounts'] ) : 0;
2221 for ( $i = 0; $i < $cod_amounts_count; $i++ ) {
2222 $usces->options['cod_amounts'][ $i ] = (int) $_POST['cod_amounts'][ $i ];
2223 $usces->options['cod_fees'][ $i ] = (int) $_POST['cod_fees'][ $i ];
2224 if ( 0 === (int) $_POST['cod_amounts'][ $i ] || ( 0 === (int) $_POST['cod_fees'][ $i ] && '0' !== $_POST['cod_fees'][ $i ] ) ) {
2225 $message = __( 'There is the item where a value is dirty.', 'usces' );
2226 }
2227 }
2228 }
2229 }
2230
2231 if ( '' === $message ) {
2232 $r = 'success';
2233 update_option( 'usces', $usces->options );
2234 } else {
2235 $r = '<span style="color:red;">' . $message . '</span>';
2236 }
2237 die( $r );
2238 }
2239
2240 function usces_get_order_acting_data( $rand ) {
2241 global $wpdb;
2242
2243 $table_name = $wpdb->prefix . 'usces_access';
2244 $query = $wpdb->prepare( "SELECT acc_str1 AS `sesid`, acc_value AS `order_data` FROM $table_name WHERE acc_key = %s", $rand );
2245 $res = $wpdb->get_row( $query, ARRAY_A );
2246 if ( $res == NULL ) {
2247 return false;
2248 } else {
2249 return $res;
2250 }
2251 }
2252
2253 function usces_ordered_acting_data( $rand, $key = 'order_received' ) {
2254 global $usces, $wpdb;
2255
2256 $datas = usces_get_order_acting_data( $rand );
2257 $data = unserialize( $datas['order_data'] );
2258 usces_log( 'usces_ordered_acting_data', 'acting_transaction.log' );
2259 $data[ $key ] = 1;
2260
2261 $data = serialize( $data );
2262 $table_name = $wpdb->prefix . 'usces_access';
2263 $query = $wpdb->prepare(
2264 "UPDATE $table_name SET acc_value = %s WHERE acc_type = %s AND acc_key = %s",
2265 $data,
2266 'acting_data',
2267 $rand
2268 );
2269 $res = $wpdb->query( $query );
2270 }
2271
2272 function usces_delete_ordered_acting_data( $rand ) {
2273 global $wpdb;
2274
2275 $table_name = $wpdb->prefix . 'usces_access';
2276 $query = $wpdb->prepare( "DELETE FROM $table_name WHERE acc_type = %s AND acc_key = %s", 'acting_data', $rand );
2277 $res = $wpdb->query( $query );
2278 }
2279
2280 function usces_is_trusted_acting_data( $rand ) {
2281 global $usces, $wpdb;
2282
2283 $datas = usces_get_order_acting_data( $rand );
2284 $data = unserialize( $datas['order_data'] );
2285 usces_log( 'usces_is_trusted_acting_data', 'acting_transaction.log' );
2286 if ( isset( $data['propriety'] ) && $data['propriety'] && ! isset( $data['order_received'] ) ) {
2287 return true;
2288 } else {
2289 return false;
2290 }
2291 }
2292
2293 function usces_get_filename( $path ) {
2294 $res = array();
2295 if ( $handle = opendir( $path ) ) {
2296 while ( false !== ( $file = readdir( $handle ) ) ) {
2297 if ( '.' != $file && '..' != $file ) {
2298 $res[] = $file;
2299 }
2300 }
2301 closedir( $handle );
2302 }
2303 return $res;
2304 }
2305
2306 function usces_locales() {
2307 $res = array();
2308 if ( $handle = opendir( USCES_PLUGIN_DIR . '/languages/' ) ) {
2309 while ( false !== ( $file = readdir( $handle ) ) ) {
2310 if ( '.' != $file && '..' != $file && preg_match( '/^usces-(.+)\.mo$/', $file, $matches ) ) {
2311 $res[] = $matches[1];
2312 }
2313 }
2314 closedir( $handle );
2315 }
2316 return $res;
2317 }
2318
2319 function usces_get_local_language() {
2320 $locale = get_locale();
2321 switch ( $locale ) {
2322 case '':
2323 case 'en':
2324 case 'en_US':
2325 $front_lang = 'en';
2326 break;
2327 case 'ja':
2328 case 'ja_JP':
2329 $front_lang = 'ja';
2330 break;
2331 default:
2332 $front_lang = 'others';
2333 }
2334 return $front_lang;
2335 }
2336
2337 function usces_get_base_country() {
2338 global $usces_settings;
2339
2340 $wplang = defined( 'WPLANG' ) ? WPLANG : get_locale();
2341 $locale = empty( $wplang ) ? 'en' : $wplang;
2342 $base_country = ( array_key_exists( $locale, $usces_settings['lungage2country'] ) ) ? $usces_settings['lungage2country'][ $locale ] : 'US';
2343 $base_country = apply_filters( 'usces_filter_base_country', $base_country );
2344 return $base_country;
2345 }
2346
2347 function usces_get_local_addressform() {
2348 global $usces_settings;
2349
2350 $base = usces_get_base_country();
2351 $addressform = ( array_key_exists( $base, $usces_settings['addressform'] ) ) ? $usces_settings['addressform'][ $base ] : 'US';
2352 $addressform = apply_filters( 'usces_filter_addressform', $addressform );
2353 return $addressform;
2354 }
2355
2356 function usces_get_local_target_market() {
2357 $base = usces_get_base_country();
2358 return (array) $base;
2359 }
2360
2361 function usces_get_apply_addressform( $country ) {
2362 global $usces_settings;
2363 return $usces_settings['addressform'][ $country ];
2364 }
2365
2366 function usces_remove_filter() {
2367 global $usces, $post;
2368
2369 if ( is_single() && 'item' == $post->post_mime_type ) {
2370 remove_filter( 'the_content', array( &$usces, 'filter_itemPage' ) );
2371
2372 } elseif ( $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) || $usces->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
2373 remove_action( 'the_post', array( &$usces, 'action_cartFilter' ) );
2374 remove_filter( 'the_title', array( &$usces, 'filter_cartTitle' ) ,20 );
2375 remove_filter( 'the_content', array( &$usces, 'filter_cartContent' ), 20 );
2376
2377 } elseif ( $usces->is_member_page( $_SERVER['REQUEST_URI'] ) ) {
2378 remove_action( 'the_post', array( &$usces, 'action_memberFilter' ) );
2379 remove_filter( 'the_title', array( &$usces, 'filter_memberTitle' ), 20 );
2380 remove_filter( 'the_content', array( &$usces, 'filter_memberContent' ) ,20 );
2381
2382 } else {
2383 remove_action( 'the_post', array( &$usces, 'goDefaultPage' ) );
2384 }
2385 }
2386
2387 function usces_reset_filter() {
2388 global $usces, $post;
2389
2390 if ( is_single() && 'item' == $post->post_mime_type ) {
2391 add_filter( 'the_content', array( &$usces, 'filter_itemPage' ) );
2392
2393 } elseif ( $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) || $usces->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
2394 add_action( 'the_post', array( &$usces, 'action_cartFilter' ) );
2395 add_filter( 'the_title', array( &$usces, 'filter_cartTitle' ), 20 );
2396 add_filter( 'the_content', array( &$usces, 'filter_cartContent' ), 20 );
2397
2398 } elseif ( $usces->is_member_page( $_SERVER['REQUEST_URI'] ) ) {
2399 add_action( 'the_post', array( &$usces, 'action_memberFilter' ) );
2400 add_filter( 'the_title', array( &$usces, 'filter_memberTitle' ), 20 );
2401 add_filter( 'the_content', array( &$usces, 'filter_memberContent' ), 20 );
2402
2403 } else {
2404 add_action( 'the_post', array( &$usces, 'goDefaultPage' ) );
2405 }
2406 }
2407
2408 function usces_get_wcex() {
2409 $wcex = array();
2410 if ( defined( 'WCEX_DLSELLER_VERSION' ) ) {
2411 $wcex['DLSELLER'] = array(
2412 'name' => 'Dl Seller',
2413 'version' => WCEX_DLSELLER_VERSION,
2414 );
2415 }
2416 if ( defined( 'WCEX_ITEM_LIST_LAYOUT_VERSION' ) ) {
2417 $wcex['ITEM_LIST_LAYOUT'] = array(
2418 'name' => 'Item List Layout',
2419 'version' => WCEX_ITEM_LIST_LAYOUT_VERSION,
2420 );
2421 }
2422 if ( defined( 'WCEX_MOBILE_VERSION' ) ) {
2423 $wcex['MOBILE'] = array(
2424 'name' => 'Mobile',
2425 'version' => WCEX_MOBILE_VERSION,
2426 );
2427 }
2428 if ( defined( 'WCEX_MULTIPRICE_VERSION' ) ) {
2429 $wcex['MULTIPRICE'] = array(
2430 'name' => 'Multi Price',
2431 'version' => WCEX_MULTIPRICE_VERSION,
2432 );
2433 }
2434 if ( defined( 'WCEX_SLIDE_SHOWCASE_VERSION' ) ) {
2435 $wcex['SLIDE_SHOWCASE'] = array(
2436 'name' => 'Slide Showcase',
2437 'version' => WCEX_SLIDE_SHOWCASE_VERSION,
2438 );
2439 }
2440 if ( defined( 'WCEX_WIDGET_CART_VERSION' ) ) {
2441 $wcex['WIDGET_CART'] = array(
2442 'name' => 'Widget Cart',
2443 'version' => WCEX_WIDGET_CART_VERSION,
2444 );
2445 }
2446 return $wcex;
2447 }
2448
2449 function usces_trackPageview_cart( $push ) {
2450 $push = array();
2451 if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2452 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_cart'";
2453 } else {
2454 $push[] = "'_trackPageview','/wc_cart'";
2455 }
2456 return $push;
2457 }
2458
2459 function usces_trackPageview_customer( $push ) {
2460 $push = array();
2461 if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2462 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_customer'";
2463 } else {
2464 $push[] = "'_trackPageview','/wc_customer'";
2465 }
2466 return $push;
2467 }
2468
2469 function usces_trackPageview_delivery( $push ) {
2470 $push = array();
2471 if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2472 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_delivery'";
2473 } else {
2474 $push[] = "'_trackPageview','/wc_delivery'";
2475 }
2476 return $push;
2477 }
2478
2479 function usces_trackPageview_confirm( $push ) {
2480 $push = array();
2481 if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2482 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_confirm'";
2483 } else {
2484 $push[] = "'_trackPageview','/wc_confirm'";
2485 }
2486 return $push;
2487 }
2488
2489 function usces_trackPageview_ordercompletion( $push ) {
2490 global $usces;
2491
2492 if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2493 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_ordercompletion'";
2494 } else {
2495 $push[] = "'_trackPageview','/wc_ordercompletion'";
2496 }
2497
2498 $sesdata = $usces->cart->get_entry();
2499 if ( isset( $sesdata['order']['ID'] ) && ! empty( $sesdata['order']['ID'] ) ) {
2500 $order_id = $sesdata['order']['ID'];
2501 $data = $usces->get_order_data( $order_id, 'direct' );
2502 $cart = unserialize( $data['order_cart'] );
2503 $total_price = $usces->get_total_price( $cart ) + $data['order_discount'] - $data['order_usedpoint'];
2504 if ( $total_price < 0 ) {
2505 $total_price = 0;
2506 }
2507 $push[] = "'_addTrans', '" . $order_id . "', '" . html_entity_decode( get_option( 'blogname' ) ) . "', '" . $total_price . "', '" . $data['order_tax'] . "', '" . $data['order_shipping_charge'] . "', '" . $data['order_address1'].$data['order_address2'] . "', '" . $data['order_pref'] . "', '" . get_locale() . "'";
2508 $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
2509 for ( $i = 0; $i < $cart_count; $i++ ) {
2510 $cart_row = $cart[ $i ];
2511 $post_id = $cart_row['post_id'];
2512 $sku = urldecode( $cart_row['sku'] );
2513 $quantity = $cart_row['quantity'];
2514 $itemName = $usces->getItemName( $post_id );
2515 $skuPrice = $cart_row['price'];
2516 $cats = $usces->get_item_cat_genre_ids( $post_id );
2517 if ( is_array( $cats ) ) {
2518 sort( $cats );
2519 }
2520 $category = ( isset( $cats[0] ) ) ? get_cat_name( $cats[0] ) : '';
2521 $push[] = "'_addItem', '" . $order_id . "', '" . $sku . "', '" . $itemName . "', '" . $category . "', '" . $skuPrice . "', '" . $quantity . "'";
2522 }
2523 $push[] = "'_trackTrans'";
2524 }
2525
2526 return $push;
2527 }
2528
2529 function usces_trackPageview_error( $push ) {
2530 if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2531 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_error'";
2532 } else {
2533 $push[] = "'_trackPageview','/wc_error'";
2534 }
2535 return $push;
2536 }
2537
2538 function usces_trackPageview_member( $push ) {
2539 if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2540 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_member'";
2541 } else {
2542 $push[] = "'_trackPageview','/wc_member'";
2543 }
2544 return $push;
2545 }
2546
2547 function usces_trackPageview_login( $push ) {
2548 if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2549 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_login'";
2550 } else {
2551 $push[] = "'_trackPageview','/wc_login'";
2552 }
2553 return $push;
2554 }
2555
2556 function usces_trackPageview_editmemberform( $push ) {
2557 if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2558 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_editmemberform'";
2559 } else {
2560 $push[] = "'_trackPageview','/wc_editmemberform'";
2561 }
2562 return $push;
2563 }
2564
2565 function usces_trackPageview_newcompletion( $push ) {
2566 if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2567 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_newcompletion'";
2568 } else {
2569 $push[] = "'_trackPageview','/wc_newcompletion'";
2570 }
2571 return $push;
2572 }
2573
2574 function usces_trackPageview_newmemberform( $push ) {
2575 if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2576 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_newmemberform'";
2577 } else {
2578 $push[] = "'_trackPageview','/wc_newmemberform'";
2579 }
2580 return $push;
2581 }
2582
2583 function usces_trackPageview_deletemember( $push ) {
2584 if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2585 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_deletemember'";
2586 } else {
2587 $push[] = "'_trackPageview','/wc_deletemember'";
2588 }
2589 return $push;
2590 }
2591
2592 function usces_trackPageview_search_item( $push ) {
2593 if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2594 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_search_item'";
2595 } else {
2596 $push[] = "'_trackPageview','/wc_search_item'";
2597 }
2598 return $push;
2599 }
2600
2601 function usces_get_essential_mark( $fielde, $data = NULL ) {
2602 global $usces_essential_mark;
2603 do_action( 'usces_action_essential_mark', $data, $fielde );
2604 return $usces_essential_mark[ $fielde ];
2605 }
2606
2607 function uesces_get_admin_addressform( $type, $data, $customdata, $out = 'return' ) {
2608 global $usces, $usces_settings;
2609
2610 $options = get_option( 'usces', array() );
2611 $applyform = usces_get_apply_addressform( $options['system']['addressform'] );
2612 $formtag = '';
2613 switch ( $type ) {
2614 case 'member':
2615 $values = array(
2616 'name1' => $data['mem_name1'],
2617 'name2' => $data['mem_name2'],
2618 'name3' => $data['mem_name3'],
2619 'name4' => $data['mem_name4'],
2620 'zipcode' => $data['mem_zip'],
2621 'address1' => $data['mem_address1'],
2622 'address2' => $data['mem_address2'],
2623 'address3' => $data['mem_address3'],
2624 'tel' => $data['mem_tel'],
2625 'fax' => $data['mem_fax'],
2626 'pref' => $data['mem_pref'],
2627 );
2628 $country = $usces->get_member_meta_value( 'customer_country', $data['ID'] );
2629 $values['country'] = ! empty( $country ) ? $country : usces_get_local_addressform();
2630 break;
2631 case 'customer':
2632 $values = array(
2633 'name1' => $data['order_name1'],
2634 'name2' => $data['order_name2'],
2635 'name3' => $data['order_name3'],
2636 'name4' => $data['order_name4'],
2637 'zipcode' => $data['order_zip'],
2638 'address1' => $data['order_address1'],
2639 'address2' => $data['order_address2'],
2640 'address3' => $data['order_address3'],
2641 'tel' => $data['order_tel'],
2642 'fax' => $data['order_fax'],
2643 'pref' => $data['order_pref'],
2644 );
2645 $country = $usces->get_order_meta_value( 'customer_country', $data['ID'] );
2646 $values['country'] = ! empty( $country ) ? $country : usces_get_local_addressform();
2647 break;
2648 case 'delivery':
2649 $values = $data;
2650 break;
2651 }
2652
2653 switch ( $applyform ) {
2654
2655 case 'JP':
2656 $formtag .= usces_admin_custom_field_input( $customdata, $type, 'name_pre', 'return' );
2657 $formtag .= '
2658 <tr id="' . $type . '_name_row">
2659 <td class="label">' . __( 'name', 'usces' ) . '</td>
2660 <td class="col2 datafield"><input name="' . $type . '[name1]" type="text" class="text short" value="' . esc_attr( $values['name1'] ) . '" /><input name="' . $type . '[name2]" type="text" class="text short" value="' . esc_attr( $values['name2'] ) . '" /></td>
2661 </tr>
2662 <tr id="' . $type . 'furikana_row">
2663 <td class="label">' . __( 'furigana', 'usces' ) . '</td>
2664 <td class="col2 datafield"><input name="' . $type . '[name3]" type="text" class="text short" value="' . esc_attr( $values['name3'] ) . '" /><input name="' . $type . '[name4]" type="text" class="text short" value="' . esc_attr( $values['name4'] ) . '" /></td>
2665 </tr>';
2666 $formtag .= usces_admin_custom_field_input( $customdata, $type, 'name_after', 'return' );
2667 $formtag .= '
2668 <tr id="' . $type . 'zipcode_row">
2669 <td class="label">' . __( 'Zip/Postal Code', 'usces' ) . '</td>
2670 <td class="col2 datafield"><input name="' . $type . '[zipcode]" type="text" class="text short" value="' . esc_attr( $values['zipcode'] ) . '" />' . apply_filters( 'usces_filter_admin_addressform_zipcode', NULL, $type ) . '</td>
2671 </tr>
2672 <tr id="' . $type . '_country_row">
2673 <td class="label">' . __( 'Country', 'usces' ) . '</td>
2674 <td class="col2 datafield">' . uesces_get_target_market_form( $type, $values['country'] ) . '</td>
2675 </tr>
2676 <tr id="' . $type . '_states_row">
2677 <td class="label">' . __( 'Province', 'usces' ) . '</td>
2678 <td class="col2 datafield">';
2679
2680 $formtag .= usces_pref_select( $type, $values );
2681
2682 $formtag .= '</td>
2683 </tr>';
2684 $formtag .= '
2685 <tr id="' . $type . '_address1_row">
2686 <td class="label">' . __( 'city', 'usces' ) . '</td>
2687 <td class="col2 datafield"><input name="' . $type . '[address1]" type="text" class="text long" value="' . esc_attr( $values['address1'] ) . '" /></td>
2688 </tr>
2689 <tr id="' . $type . '_address2_row">
2690 <td class="label">' . __( 'numbers', 'usces' ) . '</td>
2691 <td class="col2 datafield"><input name="' . $type . '[address2]" type="text" class="text long" value="' . esc_attr( $values['address2'] ) . '" /></td>
2692 </tr>
2693 <tr id="' . $type . '_address3_row">
2694 <td class="label">' . __( 'building name', 'usces' ) . '</td>
2695 <td class="col2 datafield"><input name="' . $type . '[address3]" type="text" class="text long" value="' . esc_attr( $values['address3'] ) . '" /></td>
2696 </tr>
2697 <tr id="' . $type . '_tel_row">
2698 <td class="label">' . __( 'Phone number', 'usces' ) . '</td>
2699 <td class="col2 datafield"><input name="' . $type . '[tel]" type="text" class="text long" value="' . esc_attr( $values['tel'] ) . '" /></td>
2700 </tr>
2701 <tr id="' . $type . '_fax_row">
2702 <td class="label">' . __( 'FAX number', 'usces' ) . '</td>
2703 <td class="col2 datafield"><input name="' . $type . '[fax]" type="text" class="text long" value="' . esc_attr( $values['fax'] ) . '" /></td>
2704 </tr>';
2705 $formtag .= usces_admin_custom_field_input( $customdata, $type, 'fax_after', 'return' );
2706 break;
2707
2708 case 'CN':
2709 $formtag .= usces_admin_custom_field_input( $customdata, $type, 'name_pre', 'return' );
2710 $formtag .= '
2711 <tr>
2712 <td id="' . $type . 'name_row" class="label">' . __( 'name', 'usces' ) . '</td>
2713 <td class="col2 datafield"><input name="' . $type . '[name1]" type="text" class="text short" value="' . esc_attr( $values['name1'] ) . '" /><input name="' . $type . '[name2]" type="text" class="text short" value="' . esc_attr( $values['name2'] ) . '" /></td>
2714 </tr>';
2715 $formtag .= usces_admin_custom_field_input( $customdata, $type, 'name_after', 'return' );
2716 $formtag .= '
2717 <tr id="' . $type . '_country_row">
2718 <td class="label">' . __( 'Country', 'usces' ) . '</td>
2719 <td class="col2 datafield">' . uesces_get_target_market_form( $type, $values['country'] ) . '</td>
2720 </tr>
2721 <tr id="' . $type . '_states_row">
2722 <td class="label">' . __( 'State', 'usces' ) . '</td>
2723 <td class="col2 datafield">';
2724
2725 $formtag .= usces_pref_select( $type, $values );
2726
2727 $formtag .= '</td>
2728 </tr id="' . $type . '_address1_row">';
2729 $formtag .= '<tr>
2730 <td class="label">' . __( 'city', 'usces' ) . '</td>
2731 <td class="col2 datafield"><input name="' . $type . '[address1]" type="text" class="text long" value="' . esc_attr( $values['address1'] ) . '" /></td>
2732 </tr>
2733 <tr id="' . $type . '_address2_row">
2734 <td class="label">' . __( 'Address Line1', 'usces' ) . '</td>
2735 <td class="col2 datafield"><input name="' . $type . '[address2]" type="text" class="text long" value="' . esc_attr( $values['address2'] ) . '" /></td>
2736 </tr>
2737 <tr id="' . $type . '_address3_row">
2738 <td class="label">' . __( 'Address Line2', 'usces' ) . '</td>
2739 <td class="col2 datafield"><input name="' . $type . '[address3]" type="text" class="text long" value="' . esc_attr( $values['address3'] ) . '" /></td>
2740 </tr>
2741 <tr id="' . $type . 'zipcode_row">
2742 <td class="label">' . __( 'Zip', 'usces' ) . '</td>
2743 <td class="col2 datafield"><input name="' . $type . '[zipcode]" type="text" class="text short" value="' . esc_attr( $values['zipcode'] ) . '" /></td>
2744 </tr>
2745 <tr id="' . $type . '_tel_row">
2746 <td class="label">' . __( 'Phone number', 'usces' ) . '</td>
2747 <td class="col2 datafield"><input name="' . $type . '[tel]" type="text" class="text long" value="' . esc_attr( $values['tel'] ) . '" /></td>
2748 </tr>
2749 <tr id="' . $type . '_fax_row">
2750 <td class="label">' . __( 'FAX number', 'usces' ) . '</td>
2751 <td class="col2 datafield"><input name="' . $type . '[fax]" type="text" class="text long" value="' . esc_attr( $values['fax'] ) . '" /></td>
2752 </tr>';
2753 $formtag .= usces_admin_custom_field_input( $customdata, $type, 'fax_after', 'return' );
2754 break;
2755
2756 case 'US':
2757 default:
2758 $formtag .= usces_admin_custom_field_input( $customdata, $type, 'name_pre', 'return' );
2759 $formtag .= '
2760 <tr id="' . $type . 'name_row">
2761 <td class="label">' . __( 'name', 'usces' ) . '</td>
2762 <td class="col2 datafield"><input name="' . $type . '[name2]" type="text" class="text short" value="' . esc_attr( $values['name2'] ) . '" /><input name="' . $type . '[name1]" type="text" class="text short" value="' . esc_attr( $values['name1'] ) . '" /></td>
2763 </tr>';
2764 $formtag .= usces_admin_custom_field_input( $customdata, $type, 'name_after', 'return' );
2765 $formtag .= '
2766 <tr id="' . $type . '_address2_row">
2767 <td class="label">' . __( 'Address Line1', 'usces' ) . '</td>
2768 <td class="col2 datafield"><input name="' . $type . '[address2]" type="text" class="text long" value="' . esc_attr( $values['address2'] ) . '" /></td>
2769 </tr>
2770 <tr id="' . $type . '_address3_row">
2771 <td class="label">' . __( 'Address Line2', 'usces' ) . '</td>
2772 <td class="col2 datafield"><input name="' . $type . '[address3]" type="text" class="text long" value="' . esc_attr( $values['address3'] ) . '" /></td>
2773 </tr>
2774 <tr id="' . $type . '_address1_row">
2775 <td class="label">' . __( 'city', 'usces' ) . '</td>
2776 <td class="col2 datafield"><input name="' . $type . '[address1]" type="text" class="text long" value="' . esc_attr( $values['address1'] ) . '" /></td>
2777 </tr>
2778 <tr id="' . $type . '_states_row">
2779 <td class="label">' . __( 'State', 'usces' ) . '</td>
2780 <td class="col2 datafield">';
2781
2782 $formtag .= usces_pref_select( $type, $values );
2783
2784 $formtag .= '</td>
2785 </tr>';
2786 $formtag .= '
2787 <tr id="' . $type . '_country_row">
2788 <td class="label">' . __( 'Country', 'usces' ) . '</td>
2789 <td class="col2 datafield">' . uesces_get_target_market_form( $type, $values['country'] ) . '</td>
2790 </tr>
2791 <tr id="' . $type . 'zipcode_row">
2792 <td class="label">' . __( 'Zip', 'usces' ) . '</td>
2793 <td class="col2 datafield"><input name="' . $type . '[zipcode]" type="text" class="text short" value="' . esc_attr( $values['zipcode'] ) . '" /></td>
2794 </tr>
2795 <tr id="' . $type . '_tel_row">
2796 <td class="label">' . __( 'Phone number', 'usces' ) . '</td>
2797 <td class="col2 datafield"><input name="' . $type . '[tel]" type="text" class="text long" value="' . esc_attr( $values['tel'] ) . '" /></td>
2798 </tr>
2799 <tr id="' . $type . '_fax_row">
2800 <td class="label">' . __( 'FAX number', 'usces' ) . '</td>
2801 <td class="col2 datafield"><input name="' . $type . '[fax]" type="text" class="text long" value="' . esc_attr( $values['fax'] ) . '" /></td>
2802 </tr>';
2803 $formtag .= usces_admin_custom_field_input( $customdata, $type, 'fax_after', 'return' );
2804 break;
2805 }
2806 $res = apply_filters( 'usces_filter_apply_admin_addressform', $formtag, $type, $data, $customdata );
2807
2808 if ( 'return' === $out ) {
2809 return $res;
2810 } else {
2811 echo $res; // no escape due to filter.
2812 }
2813 }
2814
2815 function self_filter_apply_admin_addressform( $formtag, $type, $data, $customdata ) {
2816 if ( ! empty( $_SESSION['admin_admb_custom_field_member'] ) ) {
2817 $admb = $_SESSION['admin_admb_custom_field_member'];
2818 $formtag .= usces_admin_custom_field_input( $admb['data'], $admb['type'], 'fax_after', 'return' );
2819 unset( $_SESSION['admin_admb_custom_field_member'] );
2820 }
2821 return $formtag;
2822 }
2823
2824 function uesces_get_target_market_form( $type, $selected, $out = 'return' ) {
2825 global $usces_settings;
2826
2827 $options = get_option( 'usces', array() );
2828 $res = '<select name="' . $type . '[country]" id="' . $type . '_country">' . "\n";
2829 foreach ( $usces_settings['country'] as $key => $value ) {
2830 if ( in_array( $key, $options['system']['target_market'] ) ) {
2831 $res .= '<option value="' . $key . '"' . selected( $selected, $key, false ) . '>' . $value . "</option>\n";
2832 }
2833 }
2834 $res .= '</select>' . "\n";
2835
2836 if ( 'return' === $out ) {
2837 return wel_esc_script( $res );
2838 } else {
2839 wel_esc_script_e( $res );
2840 }
2841 }
2842
2843 function usces_pref_select( $type, $values, $out = 'return' ) {
2844 global $usces, $usces_states;
2845
2846 $country = empty( $values['country'] ) ? usces_get_base_country() : $values['country'];
2847 $options = get_option( 'usces', array() );
2848 if ( ! in_array( $country, $options['system']['target_market'] ) ) {
2849 $country = $options['system']['target_market'][0];
2850 }
2851
2852 $pref = ( isset( $values['pref'] ) ) ? $values['pref'] : '';
2853 $prefs = get_usces_states( $country );
2854 $html = '<select name="' . esc_attr( $type . '[pref]' ) . '" id="' . esc_attr( $type ) . '_pref" class="pref">';
2855 $prefs_count = count( $prefs );
2856 if ( 0 < $prefs_count ) {
2857 $select = __( '-- Select --', 'usces_dual' );
2858 $html .= "\t" . '<option value="' . esc_attr( $select ) . '">' . esc_html( $select ) . "</option>\n";
2859 for ( $i = 1; $i < $prefs_count; $i++ ) {
2860 $html .= "\t" . '<option value="' . esc_attr( $prefs[ $i ] ) . '"' . selected( $prefs[ $i ], $pref, false ) . '>' . esc_html( $prefs[ $i ] ) . "</option>\n";
2861 }
2862 }
2863 $html .= "</select>\n";
2864 $html = apply_filters( 'usces_filter_pref_field', $html, $type, $values, $country, $prefs );
2865
2866 if ( 'return' === $out ) {
2867 return $html;
2868 } else {
2869 echo $html; // no escape due to filter.
2870 }
2871 }
2872
2873 function usces_is_tax_display() {
2874 global $usces;
2875 if ( isset( $usces->options['tax_display'] ) && 'deactivate' === $usces->options['tax_display'] ) {
2876 return false;
2877 } else {
2878 return true;
2879 }
2880 }
2881
2882 function usces_get_tax_display() {
2883 global $usces;
2884 $tax_display = ( isset( $usces->options['tax_display'] ) ) ? $usces->options['tax_display'] : 'activate';
2885 return $tax_display;
2886 }
2887
2888 function usces_get_tax_mode() {
2889 global $usces;
2890 return $usces->options['tax_mode'];
2891 }
2892
2893 function usces_get_tax_target() {
2894 global $usces;
2895 return $usces->options['tax_target'];
2896 }
2897
2898 function usces_is_member_system() {
2899 global $usces;
2900 if ( 'activate' === $usces->options['membersystem_state'] ) {
2901 return true;
2902 } else {
2903 return false;
2904 }
2905 }
2906
2907 function usces_is_member_system_point() {
2908 global $usces;
2909 if ( 'activate' === $usces->options['membersystem_point'] ) {
2910 return true;
2911 } else {
2912 return false;
2913 }
2914 }
2915
2916 function usces_point_coverage() {
2917 global $usces;
2918 return $usces->options['point_coverage'];
2919 }
2920
2921 function usces_shipping_country_option( $selected, $out = '' ) {
2922 global $usces_settings;
2923
2924 $options = get_option( 'usces', array() );
2925 $res = '';
2926 foreach ( $usces_settings['country'] as $key => $value ) {
2927 if ( in_array( $key, $options['system']['target_market'], true ) ) {
2928 $res .= '<option value="' . $key . '"' . selected( $selected, $key, false ) . '>' . $value . "</option>\n";
2929 }
2930 }
2931 wel_esc_script_e( $res );
2932 }
2933
2934 function usces_get_cart_button( $out = '' ) {
2935 global $usces;
2936
2937 $res = '';
2938
2939 if ( $usces->use_js ) {
2940 $res .= '<input name="previous" type="button" id="previouscart" class="continue_shopping_button" value="' . __( 'continue shopping', 'usces' ) . '"' . apply_filters( 'usces_filter_cart_prebutton', ' onclick="uscesCart.previousCart();"' ) . ' />&nbsp;&nbsp;';
2941 if ( usces_is_cart() ) {
2942 $res .= '<input name="customerinfo" type="submit" class="to_customerinfo_button" value="' . __( ' Next ', 'usces' ) . '"' . apply_filters( 'usces_filter_cart_nextbutton', ' onclick="return uscesCart.cartNext();"' ) . ' />';
2943 }
2944 } else {
2945 $res .= '<a href="' . get_home_url() . '" class="continue_shopping_button">' . __( 'continue shopping', 'usces' ) . '</a>&nbsp;&nbsp;';
2946 if ( usces_is_cart() ) {
2947 $res .= '<input name="customerinfo" type="submit" class="to_customerinfo_button" value="' . __( ' Next ', 'usces' ) . '"' . apply_filters( 'usces_filter_cart_nextbutton', NULL ) . ' />';
2948 }
2949 }
2950 $res = apply_filters( 'usces_filter_get_cart_button', $res );
2951
2952 if ( 'return' === $out ) {
2953 return $res;
2954 } else {
2955 echo $res; // no escape due to filter.
2956 }
2957 }
2958
2959 function usces_get_customer_button( $out = '' ) {
2960 global $usces, $member_regmode;
2961
2962 $res = '<input name="backCart" type="submit" class="back_cart_button" value="' . __( 'Back', 'usces' ) . '"' . apply_filters( 'usces_filter_customerinfo_pre', NULL ) . ' " />&nbsp;&nbsp;';
2963
2964 $button = '<input name="deliveryinfo" type="submit" class="to_deliveryinfo_button" value="' . __( ' Next ', 'usces' ) . '"' . apply_filters( 'usces_filter_customerinfo_next', NULL ) . ' " />&nbsp;&nbsp;';
2965 $res .= apply_filters( 'usces_filter_customer_button', $button );
2966
2967 if ( usces_is_membersystem_state() && 'editmemberfromcart' !== $member_regmode && false === usces_is_login() ) {
2968 $res .= '<input name="reganddeliveryinfo" type="submit" class="to_reganddeliveryinfo_button" value="' . __( 'To the next while enrolling', 'usces' ) . '"' . apply_filters( 'usces_filter_customerinfo_prebutton', NULL ) . ' />';
2969 } elseif ( usces_is_membersystem_state() && 'editmemberfromcart' === $member_regmode ) {
2970 $res .= '<input name="reganddeliveryinfo" type="submit" class="to_reganddeliveryinfo_button" value="' . __( 'Revise member information, and to next', 'usces' ) . '"' . apply_filters( 'usces_filter_customerinfo_nextbutton', NULL ) . ' />';
2971 }
2972
2973 $res = apply_filters( 'usces_filter_get_customer_button', $res );
2974
2975 if ( 'return' === $out ) {
2976 return $res;
2977 } else {
2978 echo $res; // no escape due to filter.
2979 }
2980 }
2981
2982 function usces_delivery_secure_form( $out = '' ) {
2983 global $usces, $usces_entries, $usces_carts;
2984
2985 $html = '';
2986 include USCES_PLUGIN_DIR . '/includes/delivery_secure_form.php';
2987
2988 if ( 'return' === $out ) {
2989 return $html;
2990 } else {
2991 echo $html; // no escape due to filter.
2992 }
2993 }
2994
2995 function usces_delivery_info_script( $out ='' ) {
2996 return;
2997 }
2998
2999 function usces_delivery_info_scripts() {
3000 global $usces, $usces_entries, $usces_carts;
3001
3002 $html = '';
3003 if ( 'delivery' === $usces->page ) {
3004 include USCES_PLUGIN_DIR . '/includes/delivery_info_script.php';
3005 } elseif ( usces_is_cart_page() && usces_is_login() ) {
3006 $paypal_ec = false;
3007 $payments = usces_get_system_option( 'usces_payment_method', 'sort' );
3008 foreach ( (array) $payments as $id => $payment ) {
3009 if ( 'acting_paypal_ec' === $payment['settlement'] && 'activate' === $payment['use'] ) {
3010 $paypal_ec = true;
3011 break;
3012 }
3013 }
3014 if ( $paypal_ec ) {
3015 include USCES_PLUGIN_DIR . '/includes/delivery_info_script.php';
3016 }
3017 }
3018 echo $html; // no escape due to filter.
3019 }
3020
3021 function usces_get_entries() {
3022 global $usces, $usces_entries;
3023
3024 $usces_entries = $usces->cart->get_entry();
3025 if ( empty( $usces_entries['order']['ID'] ) && ! empty( $usces_entries['reserve']['pre_order_id'] ) ) {
3026 $usces_entries['order']['ID'] = $usces->get_order_id_by_pre_order_id( $usces_entries['reserve']['pre_order_id'] );
3027 $usces->cart->set_order_entry( array( 'ID' => $usces_entries['order']['ID'] ) );
3028 }
3029 }
3030
3031 function usces_get_carts() {
3032 global $usces, $usces_carts;
3033 $usces_carts = $usces->cart->get_cart();
3034 }
3035
3036 function usces_get_members() {
3037 global $usces, $usces_members;
3038 $usces_members = $usces->get_member();
3039 }
3040
3041 function usces_error_message( $out = '' ) {
3042 global $usces;
3043
3044 if ( 'return' === $out ) {
3045 return wel_esc_script( $usces->error_message );
3046 } else {
3047 wel_esc_script_e( $usces->error_message );
3048 }
3049 }
3050
3051 function usces_url( $type, $out = '' ) {
3052 global $usces;
3053
3054 switch ( $type ) {
3055 case 'cart':
3056 $url = USCES_CART_URL;
3057 break;
3058 case 'login':
3059 $url = USCES_LOGIN_URL;
3060 break;
3061 case 'member':
3062 $url = USCES_MEMBER_URL;
3063 break;
3064 case 'newmember':
3065 $url = USCES_NEWMEMBER_URL;
3066 break;
3067 case 'lostmemberpassword':
3068 $url = USCES_LOSTMEMBERPASSWORD_URL;
3069 break;
3070 case 'cartnonsession':
3071 $url = USCES_CART_NONSESSION_URL;
3072 break;
3073 }
3074
3075 if ( 'return' === $out ) {
3076 return $url;
3077 } else {
3078 echo esc_url( $url );
3079 }
3080 }
3081
3082 function usces_total_price( $out = '' ) {
3083 global $usces;
3084
3085 if ( 'return' === $out ) {
3086 return wel_esc_script( $usces->get_total_price() );
3087 } else {
3088 wel_esc_script_e( $usces->get_total_price() );
3089 }
3090 }
3091
3092 function usces_completion_settlement( $out ='' ) {
3093 global $usces, $usces_entries;
3094
3095 $html = '';
3096
3097 $template = apply_filters( 'usces_filter_completion_settlement', USCES_PLUGIN_DIR . '/includes/completion_settlement.php', $usces_entries );
3098 require( $template );
3099
3100 if ( 'return' === $out ) {
3101 return $html;
3102 } else {
3103 echo $html; // no escape due to filter.
3104 }
3105 }
3106
3107 function usces_purchase_button( $out ='' ) {
3108 global $usces, $usces_entries;
3109
3110 $html = '';
3111 include USCES_PLUGIN_DIR . '/includes/purchase_button.php';
3112
3113 if ( 'return' === $out ) {
3114 return $html;
3115 } else {
3116 echo $html; // no escape due to filter.
3117 }
3118 }
3119
3120 function usces_get_member_regmode() {
3121 global $member_regmode;
3122 $member_regmode = isset( $_SESSION['usces_entry']['member_regmode'] ) ? $_SESSION['usces_entry']['member_regmode'] : 'none';
3123 }
3124
3125 function uesces_get_error_settlement( $out = '' ) {
3126 $res = '';
3127 $res = apply_filters( 'usces_filter_get_error_settlement', $res );
3128 if ( empty( $res ) ) {
3129 $res = __( 'Sorry, If you have any questions, please contact the administrator of the site.', 'usces' );
3130 }
3131
3132 if ( 'return' === $out ) {
3133 return $res;
3134 } else {
3135 echo $res; // no escape due to filter.
3136 }
3137 }
3138
3139 function usces_page_name( $out = '' ) {
3140 global $usces;
3141
3142 $page = '';
3143
3144 if ( empty( $usces->page ) ) {
3145 if ( $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) ) {
3146 $page = 'cart';
3147 } elseif ( $usces->is_member_page( $_SERVER['REQUEST_URI'] ) ) {
3148 $page = 'member';
3149 }
3150 } else {
3151 $page = $usces->page;
3152 }
3153 $page = apply_filters( 'usces_filter_usces_page_name', $page );
3154
3155 if ( 'return' === $out ) {
3156 return esc_js( $page );
3157 } else {
3158 echo esc_html( $page );
3159 }
3160 }
3161
3162 function usces_post_reg_orderdata( $order_id, $results ) {
3163 global $usces, $wpdb;
3164
3165 $acting = isset( $_GET['acting'] ) ? $_GET['acting'] : '';
3166 $data = array();
3167
3168 if ( $order_id ) {
3169
3170 switch ( $acting ) {
3171 case 'epsilon':
3172 $trans_id = isset( $_REQUEST['trans_code'] ) ? $_REQUEST['trans_code'] : '';
3173 break;
3174 case 'paypal_ipn':
3175 $trans_id = isset( $_REQUEST['txn_id'] ) ? $_REQUEST['txn_id'] : '';
3176 break;
3177 case 'paypal':
3178 $trans_id = isset( $results['txn_id'] ) ? $results['txn_id'] : '';
3179 break;
3180 case 'paypal_ec':
3181 $trans_id = isset( $_REQUEST['token'] ) ? $_REQUEST['token'] : '';
3182 if ( isset( $results['settlement_id'] ) ) {
3183 $usces->set_order_meta_value( 'settlement_id', $results['settlement_id'], $order_id );
3184 }
3185 if ( isset( $results['profile_id'] ) ) {
3186 $usces->set_order_meta_value( 'profile_id', $results['profile_id'], $order_id );
3187 }
3188 break;
3189 case 'remise_card':
3190 $trans_id = isset( $_REQUEST['X-TRANID'] ) ? $_REQUEST['X-TRANID'] : '';
3191 break;
3192 case 'remise_conv':
3193 $trans_id = isset( $_REQUEST['X-JOB_ID'] ) ? $_REQUEST['X-JOB_ID'] : '';
3194 break;
3195 case 'jpayment_card':
3196 case 'jpayment_conv':
3197 case 'jpayment_bank':
3198 $trans_id = isset( $_REQUEST['gid'] ) ? $_REQUEST['gid'] : '';
3199 break;
3200 case 'telecom_card':
3201 $trans_id = isset( $_REQUEST['sendid'] ) ? $_REQUEST['sendid'] : '';
3202 break;
3203 case 'digitalcheck_card':
3204 case 'digitalcheck_conv':
3205 $trans_id = isset( $_REQUEST['SID'] ) ? $_REQUEST['SID'] : '';
3206 break;
3207 case 'mizuho_card':
3208 case 'mizuho_conv':
3209 $trans_id = isset( $_REQUEST['stran'] ) ? $_REQUEST['stran'] : '';
3210 break;
3211 default:
3212 if ( isset( $_REQUEST['FUKA'] ) && strstr( $_REQUEST['FUKA'], 'digitalcheck_card' ) ) {
3213 $trans_id = isset( $_REQUEST['SID'] ) ? $_REQUEST['SID'] : '';
3214 } else {
3215 $trans_id = '';
3216 }
3217 }
3218
3219 if ( ! empty( $trans_id ) ) {
3220 $usces->set_order_meta_value( 'trans_id', $trans_id, $order_id );
3221 }
3222 }
3223 }
3224
3225 function usces_paypal_doecp( &$results ) {
3226 global $usces;
3227
3228 $entry = $usces->cart->get_entry();
3229 $cart = $usces->cart->get_cart();
3230
3231 $post_id = $cart[0]['post_id'];
3232 $charging_type = $usces->getItemChargingType( $post_id );
3233 if ( 'continue' !== $charging_type ) {
3234 //通常購�
3235 �.
3236 //Format the other parameters that were stored in the session from the previous calls.
3237 $token = urlencode( $_REQUEST['token'] );
3238 $paymentType = apply_filters( 'usces_filter_paypal_ec_paymentaction', 'Sale' );
3239 $currencyCodeType = urlencode( $usces->get_currency_code() );
3240 $payerID = urlencode( $_REQUEST['PayerID'] );
3241 $serverName = urlencode( $_SERVER['SERVER_NAME'] );
3242 $nvpstr = '&TOKEN=' . $token . '&PAYERID=' . $payerID . '&PAYMENTREQUEST_0_PAYMENTACTION=' . $paymentType . '&PAYMENTREQUEST_0_CURRENCYCODE=' . $currencyCodeType . '&IPADDRESS=' . $serverName;
3243 $item_total_price = 0;
3244 $i = 0;
3245 foreach ( $cart as $cart_row ) {
3246 $nvpstr .=
3247 '&L_PAYMENTREQUEST_0_NAME' . $i . '=' . urlencode( $usces->getItemName( $cart_row['post_id'] ) ) .
3248 '&L_PAYMENTREQUEST_0_AMT' . $i . '=' . usces_crform( $cart_row['price'], false, false, 'return', false ) .
3249 '&L_PAYMENTREQUEST_0_NUMBER' . $i . '=' . urlencode( $usces->getItemCode( $cart_row['post_id'] ) ) . ' ' . $cart_row['sku'] .
3250 '&L_PAYMENTREQUEST_0_QTY' . $i . '=' . $cart_row['quantity'];
3251 $options = ( ! empty( $cart_row['options'] ) ) ? $cart_row['options'] : array();
3252 if ( is_array( $options ) && count( $options ) > 0 ) {
3253 $optstr = '';
3254 foreach ( $options as $key => $value ) {
3255 if ( ! empty( $key ) ) {
3256 $key = urldecode( $key );
3257 $value = maybe_unserialize( $value );
3258 if ( is_array( $value ) ) {
3259 $c = '';
3260 $optstr .= $key . ' : ';
3261 foreach ( $value as $v ) {
3262 $optstr .= $c.urldecode( $v );
3263 $c = ', ';
3264 }
3265 $optstr .= "\r\n";
3266 } else {
3267 $optstr .= $key . ' : ' . urldecode( $value ) . "\r\n";
3268 }
3269 }
3270 }
3271 if ( '' !== $optstr ) {
3272 if ( 60 < mb_strlen( $optstr, 'UTF-8' ) ) {
3273 $optstr = mb_substr( $optstr, 0, 60, 'UTF-8' ) . '...';
3274 }
3275 $nvpstr .= '&L_PAYMENTREQUEST_0_DESC' . $i . '=' . urlencode( $optstr );
3276 }
3277 }
3278 $item_total_price += ( $cart_row['price'] * $cart_row['quantity'] );
3279 $i++;
3280 }
3281 if ( ! empty( $entry['order']['discount'] ) ) {
3282 $nvpstr .=
3283 '&L_PAYMENTREQUEST_0_NAME' . $i . '=' . urlencode( __( 'Campaign discount', 'usces' ) ) .
3284 '&L_PAYMENTREQUEST_0_AMT' . $i . '=' . usces_crform( $entry['order']['discount'], false, false, 'return', false );
3285 $item_total_price += $entry['order']['discount'];
3286 $i++;
3287 }
3288 if ( ! empty( $entry['order']['usedpoint'] ) ) {
3289 $nvpstr .=
3290 '&L_PAYMENTREQUEST_0_NAME' . $i . '=' . urlencode( __( 'Used points', 'usces' ) ) .
3291 '&L_PAYMENTREQUEST_0_AMT' . $i . '=' . usces_crform( $entry['order']['usedpoint'] * (-1), false, false, 'return', false );
3292 $item_total_price -= $entry['order']['usedpoint'];
3293 $i++;
3294 }
3295 $nvpstr .=
3296 '&PAYMENTREQUEST_0_ITEMAMT=' . usces_crform( $item_total_price, false, false, 'return', false ) .
3297 '&PAYMENTREQUEST_0_SHIPPINGAMT=' . usces_crform( $entry['order']['shipping_charge'], false, false, 'return', false ) .
3298 '&PAYMENTREQUEST_0_AMT=' . usces_crform( $entry['order']['total_full_price'], false, false, 'return', false ) ;
3299 if ( ! empty( $entry['order']['cod_fee'] ) ) {
3300 $nvpstr .= '&PAYMENTREQUEST_0_HANDLINGAMT=' . usces_crform( $entry['order']['cod_fee'], false, false, 'return', false );
3301 }
3302 if ( ! empty( $entry['order']['tax'] ) ) {
3303 $nvpstr .= '&PAYMENTREQUEST_0_TAXAMT=' . usces_crform( $entry['order']['tax'], false, false, 'return', false );
3304 }
3305 $nvpstr .= '&PAYMENTREQUEST_0_AMT=' . usces_crform( $entry['order']['total_full_price'], false, false, 'return', false );
3306 $nvpstr = apply_filters( 'usces_filter_usces_paypal_doecp', $nvpstr, $charging_type );
3307 if ( 'shipped' === $usces->getItemDivision( $post_id ) ) {
3308 $name = urlencode( $entry['delivery']['name2'] . ' ' . $entry['delivery']['name1'] );
3309 $address2 = urlencode( $entry['delivery']['address2'] );
3310 $address3 = urlencode( $entry['delivery']['address3'] );
3311 $address1 = urlencode( $entry['delivery']['address1'] );
3312 $pref = urlencode( $entry['delivery']['pref'] );
3313 $country = ( ! empty( $entry['delivery']['country'] ) ) ? $entry['delivery']['country'] : usces_get_base_country();
3314 $country_code = apply_filters( 'usces_filter_paypalec_shiptocountrycode', $country );
3315 if ( 'TW' === $country_code ) {
3316 $city = $address1;
3317 $address1 = $pref;
3318 $pref = $city;
3319 }
3320 $zip = $entry['delivery']['zipcode'];
3321 $tel = ltrim( str_replace( '-', '', $entry['delivery']['tel'] ), '0' );
3322 if ( 'US' !== $country_code && 'CA' !== $country_code ) {
3323 $nvpstr .=
3324 '&PAYMENTREQUEST_0_SHIPTONAME=' . $name .
3325 '&PAYMENTREQUEST_0_SHIPTOSTREET=' . $address2 .
3326 '&PAYMENTREQUEST_0_SHIPTOSTREET2=' . $address3 .
3327 '&PAYMENTREQUEST_0_SHIPTOCITY=' . $address1 .
3328 '&PAYMENTREQUEST_0_SHIPTOSTATE=' . $pref .
3329 '&PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE=' . $country_code .
3330 '&PAYMENTREQUEST_0_SHIPTOZIP=' . $zip .
3331 '&PAYMENTREQUEST_0_SHIPTOPHONENUM=' . $tel;
3332 }
3333 }
3334 $usces->paypal->setMethod( 'DoExpressCheckoutPayment' );
3335 $usces->paypal->setData( $nvpstr );
3336 $res = $usces->paypal->doExpressCheckout();
3337 $resArray = $usces->paypal->getResponse();
3338 $ack = strtoupper( $resArray['ACK'] );
3339 if ( 'SUCCESS' === $ack || 'SUCCESSWITHWARNING' === $ack ) {
3340 $transactionId = $resArray['PAYMENTINFO_0_TRANSACTIONID']; // ' Unique transaction ID of the payment. Note: If the PaymentAction of the request was Authorization or Order, this value is your AuthorizationID for use with the Authorization & Capture APIs.
3341 $results['settlement_id'] = $transactionId;
3342 $results['payment_status'] = isset( $resArray['PAYMENTINFO_0_PAYMENTSTATUS'] ) ? $resArray['PAYMENTINFO_0_PAYMENTSTATUS'] : '';
3343 $results['pending_reason'] = isset( $resArray['PAYMENTINFO_0_PENDINGREASON'] ) ? $resArray['PAYMENTINFO_0_PENDINGREASON'] : '';
3344
3345 } else {
3346 //Display a user friendly Error on the page using any of the following error information returned by PayPal.
3347 $ErrorCode = urldecode( $resArray['L_ERRORCODE0'] );
3348 $ErrorShortMsg = urldecode( $resArray['L_SHORTMESSAGE0'] );
3349 $ErrorLongMsg = urldecode( $resArray['L_LONGMESSAGE0'] );
3350 $ErrorSeverityCode = urldecode( $resArray['L_SEVERITYCODE0'] );
3351 usces_log( 'PayPal : DoExpressCheckoutPayment API call failed. Error Code:[' . $ErrorCode . '] Error Severity Code:[' . $ErrorSeverityCode . '] Short Error Message:' . $ErrorShortMsg . ' Detailed Error Message:' . $ErrorLongMsg, 'acting_transaction.log' );
3352 if ( '10486' === $ErrorCode ) {
3353 $options = get_option( 'usces', array() );
3354 $acting_opts = $options['acting_settings']['paypal'];
3355 $query = http_build_query( $_REQUEST );
3356 $payPalURL = $acting_opts['paypal_url'] . '?cmd=_express-checkout&' . $query;
3357 header( 'Location: ' . $payPalURL );
3358 exit;
3359 }
3360 $log = array(
3361 'acting' => 'paypal_ec',
3362 'key' => '(empty key)',
3363 'result' => $ack,
3364 'data' => $resArray,
3365 );
3366 usces_save_order_acting_error( $log );
3367 return false;
3368 }
3369
3370 } else {
3371 if ( ! apply_filters( 'usces_pre_create_recurring_payments_profile', true ) ) {
3372 return false;
3373 }
3374
3375 //定期支払い.
3376 $paymentAmount = usces_crform( $entry['order']['total_full_price'], false, false, 'return', false );
3377 $token = urlencode( $_REQUEST['token'] );
3378 $currencyCodeType = urlencode( $usces->get_currency_code() );
3379 $profileStartDate = date( 'Y-m-d', dlseller_first_charging( $post_id, 'time' ) ) . 'T01:01:01Z';
3380 $billingPeriod = 'Month';// or "Day", "Week", "SemiMonth", "Year".
3381 $billingFreq = $usces->getItemFrequency( $post_id );
3382 $desc = urlencode( usces_make_agreement_description( $cart, $entry['order']['total_full_price'] ) );
3383 $totalBillingCycles = ( empty( $dlitem['dlseller_interval'] ) ) ? '' : '&TOTALBILLINGCYCLES=' . urlencode( $dlitem['dlseller_interval'] );
3384
3385 $nvpstr = '&TOKEN=' . $token . '&AMT=' . $paymentAmount . '&CURRENCYCODE=' . $currencyCodeType . '&PROFILESTARTDATE=' . $profileStartDate . '&BILLINGPERIOD=' . $billingPeriod . '&BILLINGFREQUENCY=' . $billingFreq . '&DESC=' . $desc . $totalBillingCycles;
3386 $nvpstr = apply_filters( 'usces_filter_usces_paypal_doecp', $nvpstr, $charging_type );
3387
3388 $usces->paypal->setMethod( 'CreateRecurringPaymentsProfile' );
3389 $usces->paypal->setData( $nvpstr );
3390 $res = $usces->paypal->doExpressCheckout();
3391 $resArray = $usces->paypal->getResponse();
3392 $ack = strtoupper( $resArray['ACK'] );
3393 if ( 'SUCCESS' === $ack || 'SUCCESSWITHWARNING' === $ack ) {
3394 $profileid = $resArray['PROFILEID'];
3395 $results['settlement_id'] = $profileid;
3396 $results['profile_id'] = $profileid;
3397 $results['profile_status'] = isset( $resArray['PROFILESTATUS'] ) ? $resArray['PROFILESTATUS'] : '';
3398
3399 } else {
3400 //Display a user friendly Error on the page using any of the following error information returned by PayPal.
3401 $ErrorCode = urldecode( $resArray['L_ERRORCODE0'] );
3402 $ErrorShortMsg = urldecode( $resArray['L_SHORTMESSAGE0'] );
3403 $ErrorLongMsg = urldecode( $resArray['L_LONGMESSAGE0'] );
3404 $ErrorSeverityCode = urldecode( $resArray['L_SEVERITYCODE0'] );
3405 usces_log( 'PayPal : CreateRecurringPaymentsProfile API call failed. Error Code:[' . $ErrorCode . '] Error Severity Code:[' . $ErrorSeverityCode . '] Short Error Message:' . $ErrorShortMsg .' Detailed Error Message:' . $ErrorLongMsg, 'acting_transaction.log' );
3406 $log = array(
3407 'acting' => 'paypal_ec',
3408 'key' => '(empty key)',
3409 'result' => $ack,
3410 'data' => $resArray,
3411 );
3412 usces_save_order_acting_error( $log );
3413 return false;
3414 }
3415 }
3416
3417 return true;
3418 }
3419
3420 function usces_make_agreement_description( $cart, $amt ) {
3421 global $usces;
3422
3423 $cart_row = $cart[0];
3424 $quantity = $cart_row['quantity'];
3425 $itemName = $usces->getItemName( $cart_row['post_id'] );
3426 if ( 50 < mb_strlen( $itemName, 'UTF-8' ) ) {
3427 $itemName = mb_substr( $itemName, 0, 50, 'UTF-8' ) . '...';
3428 }
3429 $amt = usces_crform( $amt, true, false, 'return', true );
3430 $desc = $itemName . ' ' . __( 'Quantity', 'usces' ) . ':' . $quantity . ' ' . $amt;
3431 return( $desc );
3432 }
3433
3434 function usces_get_send_out_date() {
3435 global $usces;
3436
3437 $bus_day_arr = ( isset( $usces->options['business_days'] ) ) ? $usces->options['business_days'] : false;
3438 $bus_day_arr = apply_filters( 'usces_filter_business_days_bus_day_arr', $bus_day_arr );
3439
3440 list( $today_year, $today_month, $today_day, $hour, $minute, $second ) = preg_split( '([^0-9])', current_time( 'mysql' ) );
3441 if ( ! is_array( $bus_day_arr ) ) {
3442 $today_bus_flag = 1;
3443 } else {
3444 $today_bus_flag = isset( $bus_day_arr[ (int) $today_year ][ (int) $today_month ][ (int) $today_day ] ) ? (int) $bus_day_arr[ (int) $today_year ][ (int) $today_month ][ (int) $today_day ] : 1;
3445 }
3446 // get the time limit addition.
3447 $limit_hour = ( ! empty( $usces->options['delivery_time_limit']['hour'] ) ) ? $usces->options['delivery_time_limit']['hour'] : false;
3448 $limit_min = ( ! empty( $usces->options['delivery_time_limit']['min'] ) ) ? $usces->options['delivery_time_limit']['min'] : false;
3449
3450 if ( false === $hour || false === $minute ) {
3451 $time_limit_addition = false;
3452 } elseif ( ( $hour . ':' . $minute . ':' . $second ) > ( $limit_hour . ':' . $limit_min . ':00' ) ) {
3453 $time_limit_addition = 1;
3454 } else {
3455 $time_limit_addition = 0;
3456 }
3457 // get the shipping indication in cart.
3458 $cart = $usces->cart->get_cart();
3459 $shipping_indication = apply_filters( 'usces_filter_shipping_indication', $usces->options['usces_shipping_indication'] );
3460 $shipping = 0;
3461 $indication_flag = true;
3462 $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
3463 $shipping_rule_ex = apply_filters( 'usces_filter_item_shipping_rule_ex', 9 );
3464 for ( $i = 0; $i < $cart_count; $i++ ) {
3465 $cart_row = $cart[ $i ];
3466 $post_id = $cart_row['post_id'];
3467 $itemShipping = (int) $usces->getItemShipping( $post_id );
3468 if ( 0 === $itemShipping || $shipping_rule_ex === $itemShipping ) {
3469 $indication_flag = false;
3470 break;
3471 }
3472 if ( $shipping < $itemShipping ) {
3473 $shipping = $itemShipping;
3474 }
3475 }
3476 $indication_incart = ( $indication_flag ) ? $shipping_indication[ $shipping ] : false;
3477 $indication_incart = apply_filters( 'usces_filter_indication_incart', $indication_incart, $shipping_indication, $shipping, $cart );
3478 // get the send out date.
3479 $sendout_num = 0;
3480 if ( $today_bus_flag ) {
3481 if ( $time_limit_addition ) {
3482 $sendout_num += 1;
3483 }
3484 if ( false !== $indication_incart ) {
3485 $sendout_num += $indication_incart;
3486 }
3487 } else {
3488 if ( false !== $indication_incart ) {
3489 $sendout_num += $indication_incart;
3490 }
3491 }
3492 $holiday = 0;
3493 for ( $i = 0; $i <= $sendout_num; $i++ ) {
3494 list( $yyyy, $mm, $dd ) = explode( '-', date( 'Y-m-d', mktime( 0, 0, 0, (int) $today_month, ( $today_day + $i ), (int) $today_year ) ) );
3495 if ( isset( $bus_day_arr[ (int) $yyyy ][ (int) $mm ][ (int) $dd ] ) && ! $bus_day_arr[ (int) $yyyy ][ (int) $mm ][ (int) $dd ] ) {
3496 $holiday++;
3497 $sendout_num++;
3498 }
3499 if ( 100 < $sendout_num ) {
3500 break;
3501 }
3502 }
3503 list( $send_y, $send_m, $send_d ) = explode( '-', date( 'Y-m-d', mktime( 0, 0, 0, (int) $today_month, ( $today_day + $sendout_num ), (int) $today_year ) ) );
3504
3505 $res = array(
3506 'today_bus_flag' => $today_bus_flag,
3507 'time_limit_addition' => $time_limit_addition,
3508 'indication_incart' => $indication_incart,
3509 'holiday' => $holiday,
3510 'sendout_num' => $sendout_num,
3511 'sendout_date' => array(
3512 'year' => $send_y,
3513 'month' => $send_m,
3514 'day' => $send_d,
3515 ),
3516 );
3517 return $res;
3518 }
3519
3520 function usces_action_footer_comment() {
3521 echo "<!-- Welcart version : v" . USCES_VERSION . " -->\n";
3522 }
3523
3524 function usces_set_acting_notification_time( $key ) {
3525 global $wpdb;
3526
3527 $tableName = $wpdb->prefix . 'usces_access';
3528 $query = $wpdb->prepare( "SELECT ID FROM $tableName WHERE acc_type = %s AND acc_key = %s", 'notification_time', $key );
3529 $res = $wpdb->get_var( $query );
3530 if ( $res ) {
3531 return;
3532 }
3533
3534 $query = $wpdb->prepare( "INSERT INTO $tableName (acc_key, acc_type, acc_num1) VALUES (%s, %s, %d)",
3535 $key, 'notification_time', time()
3536 );
3537 $res = $wpdb->query( $query );
3538 }
3539
3540 function usces_check_notification_time( $key, $time ) {
3541 global $wpdb;
3542
3543 $tableName = $wpdb->prefix . 'usces_access';
3544 $query = $wpdb->prepare( "SELECT acc_num1 FROM $tableName WHERE acc_type = %s AND acc_key = %s", 'notification_time', $key );
3545 $res = $wpdb->get_var( $query );
3546 if ( ! $res ) {
3547 return false;
3548 }
3549
3550 $past = time() - $res;
3551 if ( $time > $past ) {
3552 return true;
3553 } else {
3554 return false;
3555 }
3556 }
3557
3558 function usces_is_same_itemcode( $post_id, $item_code ) {
3559 global $wpdb, $usces;
3560
3561 $item_table = usces_get_tablename( 'usces_item' );
3562
3563 $res = $wpdb->get_col(
3564 $wpdb->prepare(
3565 "SELECT `post_id` FROM {$item_table}
3566 LEFT JOIN {$wpdb->posts} ON `ID` = `post_id`
3567 WHERE `itemCode` = %s AND `post_id` <> %d
3568 AND `post_status` IN ('pending', 'publish', 'draft', 'private', 'future')",
3569 $item_code,
3570 $post_id
3571 )
3572 );
3573
3574 if ( ! $res ) {
3575 return false;
3576 } else {
3577 return $res;
3578 }
3579 }
3580
3581 function usces_update_sku( $post_id, $sku_code, $fieldname, $value ) {
3582
3583 $sku = wel_get_sku( $post_id, $sku_code, false );
3584
3585 $sku[ $fieldname ] = $value;
3586 $meta_id = $sku['meta_id'];
3587
3588 $res = wel_update_sku_data_by_id( $meta_id, $post_id, $sku );
3589
3590 if ( ! $res ) {
3591 return false;
3592 } else {
3593 return true;
3594 }
3595 }
3596
3597 function usces_get_non_zerostoc_items() {
3598 global $wpdb, $usces;
3599
3600 $item_table = usces_get_tablename( 'usces_item' );
3601 $skus_table = usces_get_tablename( 'usces_skus' );
3602
3603 $res = $wpdb->get_results(
3604 $wpdb->prepare(
3605 "SELECT `ID`, `itemCode` AS `code`, `itemName` AS `name` FROM {$wpdb->posts} AS `post`
3606 LEFT JOIN {$item_table} AS `item` ON `ID` = item.post_id
3607 LEFT JOIN {$skus_table} AS `sku` ON `ID` = sku.post_id
3608 WHERE post_mime_type = %s AND post_type = %s AND post_status <> %s AND sku.stocknum = %s
3609 GROUP BY ID",
3610 'item',
3611 'post',
3612 'trash',
3613 '0'
3614 ),
3615 ARRAY_A
3616 );
3617
3618 return $res;
3619 }
3620
3621 function usces_get_stocs() {
3622 global $wpdb, $usces;
3623
3624 $status = array();
3625 $sku_table = $wpdb->prefix . 'usces_skus';
3626
3627 $stocks = $wpdb->get_col(
3628 $wpdb->prepare(
3629 "SELECT stock FROM {$wpdb->posts} LEFT JOIN {$sku_table} ON ID = post_id
3630 WHERE post_mime_type = %s AND post_type = %s AND post_status <> %s",
3631 'item',
3632 'post',
3633 'trash'
3634 )
3635 );
3636
3637 if ( ! $stocks ) {
3638 return $status;
3639 }
3640
3641 foreach ( (array) $stocks as $value ) {
3642 $status[] = (string) $value;
3643 }
3644
3645 return array_count_values( $status );
3646 }
3647
3648 function usces_get_deco_order_id( $order_id ) {
3649 global $usces;
3650
3651 $dec_order_id = $usces->get_order_meta_value( 'dec_order_id', $order_id );
3652 if ( ! $dec_order_id ) {
3653
3654 $options = get_option( 'usces', array() );
3655 $prefix = $options['system']['dec_orderID_prefix'];
3656 $prefix = apply_filters( 'usces_filter_get_deco_order_id_prefix', $prefix );
3657
3658 $dec_order_id = $prefix . usces_make_deco_order_id( $order_id );
3659 }
3660
3661 return $dec_order_id;
3662 }
3663
3664 function usces_make_deco_order_id( $order_id = null ) {
3665 global $wpdb;
3666
3667 $options = get_option( 'usces', array() );
3668
3669 if ( 0 === (int) $options['system']['dec_orderID_flag'] ) {
3670
3671 if ( ! $order_id ) {
3672 $dec_order_id = str_pad( 0, $options['system']['dec_orderID_digit'], '0', STR_PAD_LEFT );
3673 } else {
3674 $dec_order_id = str_pad( $order_id, $options['system']['dec_orderID_digit'], '0', STR_PAD_LEFT );
3675 }
3676
3677 } else {
3678
3679 $order_meta = usces_get_tablename( 'usces_order_meta' );
3680 $verify_time = apply_filters( 'usces_filter_deco_order_id_verify_time', 100 );
3681
3682 for ( $olimit = 0; $olimit <= $verify_time; $olimit++ ) {
3683
3684 $ukey = usces_get_key( $options['system']['dec_orderID_digit'] );
3685 $ores = $wpdb->get_var(
3686 $wpdb->prepare(
3687 "SELECT meta_key FROM {$order_meta} WHERE meta_key = %s AND meta_value = %s LIMIT 1",
3688 'dec_order_id',
3689 $ukey
3690 )
3691 );
3692
3693 if ( ! $ores ) {
3694 break;
3695 }
3696 }
3697
3698 $dec_order_id = $ukey;
3699 }
3700
3701 $dec_order_id = apply_filters( 'usces_filter_make_deco_order_id', $dec_order_id );
3702
3703 return $dec_order_id;
3704 }
3705
3706 function usces_get_gp_price( $post_id, $p, $quant ) {
3707 global $usces;
3708
3709 $GpN1 = $usces->getItemGpNum1( $post_id );
3710 $GpN2 = $usces->getItemGpNum2( $post_id );
3711 $GpN3 = $usces->getItemGpNum3( $post_id );
3712 $GpD1 = $usces->getItemGpDis1( $post_id );
3713 $GpD2 = $usces->getItemGpDis2( $post_id );
3714 $GpD3 = $usces->getItemGpDis3( $post_id );
3715
3716 if ( empty( $GpN1 ) || empty( $GpD1 ) ) {
3717
3718 $realprice = $p;
3719
3720 } elseif ( ( ! empty( $GpN1 ) && ! empty( $GpD1 ) ) && ( empty( $GpN2 ) || empty( $GpD2 ) ) ) {
3721
3722 if ( $quant >= $GpN1 ) {
3723 $realprice = wel_gp_price_discount( $p, $GpD1 );
3724 } else {
3725 $realprice = $p;
3726 }
3727
3728 } elseif ( ( ! empty( $GpN1 ) && ! empty( $GpD1 ) ) && ( ! empty( $GpN2 ) && ! empty( $GpD2 ) ) && ( empty( $GpN3 ) || empty( $GpD3 ) ) ) {
3729
3730 if ( $quant >= $GpN2 ) {
3731 $realprice = wel_gp_price_discount( $p, $GpD2 );
3732 } elseif ( $quant >= $GpN1 && $quant < $GpN2 ) {
3733 $realprice = wel_gp_price_discount( $p, $GpD1 );
3734 } else {
3735 $realprice = $p;
3736 }
3737
3738 } elseif ( ( ! empty( $GpN1 ) && ! empty( $GpD1 ) ) && ( ! empty( $GpN2 ) && ! empty( $GpD2 ) ) && ( ! empty( $GpN3 ) && ! empty( $GpD3 ) ) ) {
3739
3740 if ( $quant >= $GpN3 ) {
3741 $realprice = wel_gp_price_discount( $p, $GpD3 );
3742 } elseif ( $quant >= $GpN2 && $quant < $GpN3 ) {
3743 $realprice = wel_gp_price_discount( $p, $GpD2 );
3744 } elseif ( $quant >= $GpN1 && $quant < $GpN2 ) {
3745 $realprice = wel_gp_price_discount( $p, $GpD1 );
3746 } else {
3747 $realprice = $p;
3748 }
3749
3750 } else {
3751 $realprice = $p;
3752 }
3753
3754 $realprice = apply_filters( 'usces_filter_get_gp_price', $realprice, $post_id, $p, $quant );
3755 return $realprice;
3756 }
3757
3758 function usces_is_complete_settlement( $payment_name, $status = '' ) {
3759 $complete = false;
3760 $options = get_option( 'usces', array() );
3761 if ( 0 === (int) $options['point_assign'] ) {
3762 $complete = true;
3763 } else {
3764 $payments = usces_get_system_option( 'usces_payment_method', 'name' );
3765 if ( isset( $payments[ $payment_name ]['settlement'] ) ) {
3766 switch( $payments[ $payment_name ]['settlement'] ) {
3767 case 'acting':
3768 if ( false !== strpos( $status, 'pending' ) ) {
3769 break;
3770 }
3771 case 'acting_remise_card':
3772 case 'acting_jpayment_card':
3773 case 'acting_paypal_ec':
3774 case 'acting_telecom_card':
3775 case 'acting_digitalcheck_card':
3776 case 'acting_mizuho_card':
3777 case 'acting_anotherlane_card':
3778 case 'acting_veritrans_card':
3779 case 'COD':
3780 $complete = true;
3781 }
3782 }
3783 }
3784 $complete = apply_filters( 'usces_filter_is_complete_settlement', $complete, $payment_name, $status );
3785 return $complete;
3786 }
3787
3788 function usces_action_acting_getpoint( $order_id, $add = true ) {
3789 global $usces, $wpdb;
3790
3791 if ( ! apply_filters( 'usces_action_acting_getpoint_switch', true, $order_id, $add ) ) {
3792 return;
3793 }
3794
3795 $options = get_option( 'usces', array() );
3796 if ( 0 !== (int) $options['point_assign'] ) {
3797 if ( 'activate' === $usces->options['membersystem_state'] && 'activate' === $usces->options['membersystem_point'] ) {
3798 $table_name = $wpdb->prefix . 'usces_order';
3799 $mquery = $wpdb->prepare( "SELECT mem_id, order_getpoint FROM $table_name WHERE ID = %d", $order_id );
3800 $values = $wpdb->get_row( $mquery, ARRAY_A );
3801 $mem_id = $values['mem_id'];
3802 $getpoint = $values['order_getpoint'];
3803
3804 if ( ! empty( $mem_id ) && 0 < $getpoint ) {
3805 $calc = ( $add ) ? '+' : '-';
3806 $member_table_name = usces_get_tablename( 'usces_member' );
3807 $mquery = $wpdb->prepare( "UPDATE $member_table_name SET mem_point = (mem_point ".$calc." %d) WHERE ID = %d", $getpoint, $mem_id );
3808 $wpdb->query( $mquery );
3809
3810 if ( ! empty( $_SESSION['usces_member']['point'] ) ) {
3811 $mquery = $wpdb->prepare( "SELECT mem_point FROM $member_table_name WHERE ID = %d", $mem_id );
3812 $point = $wpdb->get_var( $mquery );
3813 $_SESSION['usces_member']['point'] = $point;
3814 }
3815 }
3816 }
3817 }
3818 do_action( 'usces_action_acting_getpoint', $order_id, $add );
3819 }
3820
3821 function usces_restore_point( $mem_id, $point ) {
3822 global $wpdb;
3823
3824 if ( ! apply_filters( 'usces_action_restore_point_switch', true, $mem_id, $point ) ) {
3825 return;
3826 }
3827
3828 $member_table_name = usces_get_tablename( 'usces_member' );
3829 $query = $wpdb->prepare( "UPDATE $member_table_name SET mem_point = (mem_point - %d) WHERE ID = %d", $point, $mem_id );
3830 $wpdb->query( $query );
3831 }
3832
3833 function usces_set_free_csv( $customer ) {
3834 $free_csv = "";
3835 if ( ! WCUtils::is_blank( $customer['name1'] ) ) {
3836 $free_csv = "LAST_NAME=" . mb_convert_encoding( $customer['name1'], 'SJIS', 'UTF-8' ) . ",FIRST_NAME=" . mb_convert_encoding( $customer['name2'], 'SJIS', 'UTF-8' ) . ",TEL=" . str_replace( "-", "", $customer['tel'] ) . ",MAIL=" . $customer['mailaddress1'];
3837 $free_csv = base64_encode( $free_csv );
3838 }
3839 return $free_csv;
3840 }
3841
3842 function usces_get_itemopt_filed( $post_id, $sku, $opt ) {
3843 global $usces;
3844
3845 $sku = urlencode( $sku );
3846 $optcode = urlencode( $opt['name'] );
3847 $name = $opt['name'];
3848 $means = (int) $opt['means'];
3849 $essential = (int) $opt['essential'];
3850 $session_value = isset( $_SESSION['usces_singleitem']['itemOption'][ $post_id ][ $sku ][ $optcode ] ) ? $_SESSION['usces_singleitem']['itemOption'][ $post_id ][ $sku ][ $optcode ] : NULL;
3851 $opt['value'] = usces_change_line_break( $opt['value'] );
3852
3853 $html = '';
3854 switch ( $means ) {
3855 case 0: //Single-select.
3856 case 1: //Multi-select.
3857 $selects = explode( "\n", $opt['value'] );
3858 $multiple = ( 0 === $means ) ? '' : ' multiple';
3859 $multiple_array = ( 0 === $means ) ? '' : '[]';
3860 $html .= "\n<select name='itemOption[{$post_id}][{$sku}][{$optcode}]{$multiple_array}' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_select'{$multiple} onKeyDown=\"if (event.keyCode == 13) {return false;}\">\n";
3861 if ( 1 === $essential ) {
3862 if ( '#NONE#' === $session_value || NULL === $session_value ) {
3863 $selected = ' selected="selected"';
3864 } else {
3865 $selected = '';
3866 }
3867 $html .= "\t<option value='#NONE#'{$selected}>" . __( 'Choose', 'usces' ) . "</option>\n";
3868 }
3869 $i = 0;
3870 foreach ( $selects as $v ) {
3871 if ( ( 0 === $i && 0 === $essential && NULL === $session_value ) || esc_attr( $v ) == $session_value ) {
3872 $selected = ' selected="selected"';
3873 } else {
3874 $selected = '';
3875 }
3876 $html .= "\t<option value='" . esc_attr( $v ) . "'{$selected}>" . esc_html( $v ) . "</option>\n";
3877 $i++;
3878 }
3879 $html .= "</select>\n";
3880 break;
3881 case 2: //Text.
3882 $html .= "\n<input name='itemOption[{$post_id}][{$sku}][{$optcode}]' type='text' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_text' onKeyDown=\"if (event.keyCode == 13) {return false;}\" value=\"" . esc_attr( $session_value ) . "\" />\n";
3883 break;
3884 case 3: //Radio-button.
3885 $selects = explode( "\n", $opt['value'] );
3886 $i = 0;
3887 foreach ( (array) $selects as $v ) {
3888 $v = trim( $v );
3889 if ( $v === $session_value ) {
3890 $checked = ' checked="checked"';
3891 } else {
3892 $checked = '';
3893 }
3894 $html .= "\t<label for='itemOption[{$post_id}][{$sku}][{$optcode}]{$i}' class='iopt_radio_label'><input name='itemOption[{$post_id}][{$sku}][{$optcode}]' id='itemOption[{$post_id}][{$sku}][{$optcode}]{$i}' class='iopt_radio' type='radio' value='" . urlencode( $v ) . "'{$checked} onKeyDown=\"if (event.keyCode == 13) {return false;}\">" . esc_html( $v ) . "</label>\n";
3895 $i++;
3896 }
3897 break;
3898 case 4: //Check-box.
3899 $selects = explode( "\n", $opt['value'] );
3900 $session_arr = is_array( $session_value ) ? $session_value : array();
3901 $i = 0;
3902 foreach ( (array) $selects as $v ) {
3903 $v = trim( $v );
3904 if ( in_array( $v, $session_arr, true ) ) {
3905 $checked = ' checked="checked"';
3906 } else {
3907 $checked = '';
3908 }
3909 $html .= "\t<label for='itemOption[{$post_id}][{$sku}][{$optcode}]{$i}' class='iopt_checkbox_label'><input name='itemOption[{$post_id}][{$sku}][{$optcode}][]' id='itemOption[{$post_id}][{$sku}][{$optcode}]{$i}' class='iopt_checkbox' type='checkbox' value='" . urlencode( $v ) . "'{$checked} onKeyDown=\"if (event.keyCode == 13) {return false;}\">" . esc_html( $v ) . "</label>\n";
3910 $i++;
3911 }
3912 break;
3913 case 5: //Text-area.
3914 $html .= "\n<textarea name='itemOption[{$post_id}][{$sku}][{$optcode}]' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_textarea'>" . esc_attr( $session_value ) . "</textarea>\n";
3915 break;
3916 }
3917
3918 $html = apply_filters( 'usces_get_itemopt_filed', $html, $post_id, $sku, $opt );
3919
3920 return $html;
3921 }
3922
3923 function usces_delete_order_check( $order_id ) {
3924 $res = apply_filters( 'usces_filter_delete_order_check', true, $order_id );
3925 return $res;
3926 }
3927
3928 function usces_delete_member_check( $member_id ) {
3929 $res = apply_filters( 'usces_filter_delete_member_check', true, $member_id );
3930 return $res;
3931 }
3932
3933 function usces_delete_member_check_front( $member_id ) {
3934 $res = apply_filters( 'usces_filter_delete_member_check_front', true, $member_id );
3935 return $res;
3936 }
3937
3938 function usces_itempage_admin_bar() {
3939 global $wp_admin_bar, $post;
3940
3941 if ( is_single() && usces_is_item() ) {
3942 $wp_admin_bar->remove_menu( 'edit' );
3943 $ref = urlencode( site_url() . '/wp-admin/admin.php?page=usces_itemedit' );
3944 $wp_admin_bar->add_menu( array(
3945 'id' => 'edit',
3946 'title' => __( 'Edit item', 'usces' ),
3947 'href' => site_url() . '/wp-admin/admin.php?page=usces_itemedit&action=edit&post=' . $post->ID . '&usces_referer=' . $ref
3948 ) );
3949 }
3950 }
3951
3952 function usces_rand( $digit = 10 ) {
3953 $num = str_repeat( '9', $digit );
3954 $rand = apply_filters( 'usces_filter_rand_value', sprintf( '%0' . $digit . 'd', mt_rand( 1, (int) $num ) ), $num );
3955 return $rand;
3956 }
3957
3958 function usces_get_cr_symbol() {
3959 global $usces, $usces_settings;
3960 $cr = $usces->options['system']['currency'];
3961 list( $code, $decimal, $point, $seperator, $symbol ) = $usces_settings['currency'][ $cr ];
3962 return $symbol;
3963 }
3964
3965 function usces_make_option_field( $materials, $cart ) {
3966 extract( $materials );
3967 /* $materials = compact( 'i', 'cart_row', 'post_id', 'sku', 'sku_code', 'quantity',
3968 'options', 'advance', 'itemCode', 'itemName', 'cartItemName',
3969 'skuPrice', 'stock', 'red', 'pictid', 'order_id' );
3970 */
3971 $option_fields = usces_get_opts( $post_id, 'sort' );
3972 $field = '<div>' . "\n";
3973 $field .= '<ul>' . "\n";
3974
3975 foreach ( (array) $option_fields as $field_data ) {
3976 $field .= '<li>' . usces_get_itemOption( $field_data, $materials, $label = '#default#' ) . '</li>' . "\n";
3977 foreach ( (array) $options as $op_key => $option ) {
3978 if ( $option['meta_key'] === $field_data['name'] ) {
3979 $options[ $op_key ]['flag'] = 1;
3980 }
3981 }
3982 }
3983
3984 foreach ( (array) $options as $option ) {
3985 if ( ! isset( $option['flag'] ) ) {
3986 $meta_value = maybe_unserialize( $option['meta_value'] );
3987 if ( ! is_array( $meta_value ) ) {
3988 $meta_value = (array) $meta_value;
3989 }
3990 $value_str = '';
3991 foreach ( $meta_value as $mv ) {
3992 $value_str .= $mv . ' & ';
3993 }
3994 $value_str = trim( $value_str, ' & ' );
3995 $field .= '<li>' . esc_html( $option['meta_key'] ) . ' : ' . esc_html( $value_str ) . '</li>' . "\n";
3996 }
3997 }
3998
3999 $field .= '</ul>' . "\n";
4000 $field .= '</div>' . "\n";
4001
4002 echo apply_filters( 'usces_filter_order_edit_form_row', $field, $cart, $materials );
4003 }
4004
4005 function usces_get_itemOption( $field_data, $materials, $label = '#default#' ) {
4006 global $usces;
4007
4008 extract( $materials );
4009 /* $materials = compact( 'i', 'cart_row', 'post_id', 'sku', 'sku_code', 'quantity',
4010 'options', 'advance', 'itemCode', 'itemName', 'cartItemName',
4011 'skuPrice', 'stock', 'red', 'pictid', 'order_id' );
4012 */
4013 $opt_value = array();
4014 foreach ( $options as $opt_value ) {
4015 if ( $field_data['name'] === $opt_value['meta_key'] ) {
4016 $cartmeta_id = $opt_value['cartmeta_id'];
4017 $name = $opt_value['meta_key'];
4018 $value = $opt_value['meta_value'];
4019 $means = (int) $field_data['means'];
4020 $essential = (int) $field_data['essential'];
4021 break;
4022 }
4023 }
4024 if ( ! $opt_value ) {
4025 return '';
4026 }
4027 if ( empty( $name ) ) {
4028 return '';
4029 }
4030
4031 if ( '#default#' === $label ) {
4032 $label = $name;
4033 }
4034
4035 $field_data['value'] = usces_change_line_break( $field_data['value'] );
4036
4037 $html = '';
4038 $name = esc_attr( $name );
4039 $label = esc_attr( $label );
4040 $html .= '<label for="itemOption[' . $cartmeta_id . ']" class="iopt_label">' . $label . '</label>' . "\n";
4041 switch ( $means ) {
4042 case 0: //Single-select.
4043 $selects = explode( "\n", $field_data['value'] );
4044 $value = maybe_unserialize( $value );
4045 $check_value = array();
4046 if ( ! is_array( $value ) ) {
4047 $check_value = (array) $value;
4048 }
4049 $diff = array_diff( $check_value, $selects );
4050
4051 if ( ! empty( $diff ) ) {
4052
4053 $value_str = '';
4054 foreach ( $check_value as $mv ) {
4055 $value_str .= $mv . ' & ';
4056 }
4057 $value_str = trim( $value_str, ' & ' );
4058 $html .= '<span>:' . esc_html( $value_str ) . '</span>' . "\n";
4059
4060 } else {
4061 $html .= '<select name="itemOption[' . $cartmeta_id . ']" id="itemOption[' . $cartmeta_id . ']" class="iopt_select" onKeyDown="if (event.keyCode == 13) {return false;}">' . "\n";
4062 if ( 1 === $essential ) {
4063 if ( '#NONE#' === $value || NULL === $value ) {
4064 $selected = ' selected="selected"';
4065 } else {
4066 $selected = '';
4067 }
4068 $html .= '<option value="#NONE#"' . $selected . '>' . __( 'Choose', 'usces' ) . '</option>' . "\n";
4069 }
4070 $i = 0;
4071 foreach ( $selects as $v ) {
4072 $v = trim( $v );
4073 if ( ( 0 === $i && 0 === $essential && NULL === $value ) || esc_attr( $v ) == esc_attr( $value ) ) {
4074 $selected = ' selected="selected"';
4075 } else {
4076 $selected = '';
4077 }
4078 $html .= '<option value="' . esc_attr( $v ) . '"' . $selected . '>' . esc_attr( $v ) . '</option>' . "\n";
4079 $i++;
4080 }
4081 $html .= '</select>' . "\n";
4082 }
4083 break;
4084 case 1: //Multi-select.
4085 $selects = explode( "\n", $field_data['value'] );
4086 $value = maybe_unserialize( $value );
4087 if ( ! is_array( $value ) ) {
4088 $value = (array) $value;
4089 }
4090 $diff = array_diff( (array) $value, $selects );
4091
4092 if ( ! empty( $diff ) ) {
4093
4094 $value_str = '';
4095 foreach ( $value as $mv ) {
4096 $value_str .= $mv . ' & ';
4097 }
4098 $value_str = trim( $value_str, ' & ' );
4099 $html .= '<span>:' . esc_html( $value_str ) . '</span>' . "\n";
4100
4101 } else {
4102 $html .= '<select name="itemOption[' . $cartmeta_id . '][]" id="itemOption[' . $cartmeta_id . ']" class="iopt_select" multiple onKeyDown="if (event.keyCode == 13) {return false;}">' . "\n";
4103 if ( 1 === $essential ) {
4104 if ( '#NONE#' === $value || NULL === $value ) {
4105 $selected = ' selected="selected"';
4106 } else {
4107 $selected = '';
4108 }
4109 $html .= '<option value="#NONE#"' . $selected . '>' . __( 'Choose', 'usces' ) . '</option>' . "\n";
4110 }
4111 $i = 0;
4112
4113 $value_arr = maybe_unserialize( $value );
4114
4115 foreach ( $selects as $v ) {
4116 $v = trim( $v );
4117 $opval = urlencode( $v );
4118 $val_str = isset( $value_arr[ $opval ] ) ? $value_arr[ $opval ] : '';
4119 if ( $v == $val_str ) {
4120 $selected = ' selected="selected"';
4121 } else {
4122 $selected = '';
4123 }
4124 $html .= '<option value="' . esc_attr( $opval ) . '"' . $selected . '>' . esc_attr( $v ) . '</option>' . "\n";
4125 $i++;
4126 }
4127 $html .= '</select>' . "\n";
4128 }
4129 break;
4130 case 2: //Text.
4131 $html .= '<input name="itemOption[' . $cartmeta_id . ']" type="text" id="itemOption[' . $cartmeta_id . ']" class="iopt_text" onKeyDown="if (event.keyCode == 13) {return false;}" value="' . esc_attr( $value ) . '" />' . "\n";
4132 break;
4133 case 3: //Radio-button.
4134 $selects = explode( "\n", $field_data['value'] );
4135 $value = maybe_unserialize( $value );
4136 if ( ! is_array( $value ) ) {
4137 $value = (array) $value;
4138 }
4139 $diff = array_diff( $value, $selects );
4140
4141 if ( ! empty( $diff ) && ! empty( $diff[0] ) ) {
4142
4143 $value_str = '';
4144 foreach ( $value as $mv ) {
4145 $value_str .= $mv . ' & ';
4146 }
4147 $value_str = trim( $value_str, ' & ' );
4148 $html .= '<span>:' . esc_html( $value_str ) . '</span>' . "\n";
4149
4150 } else {
4151 $i = 0;
4152 foreach ( $selects as $v ) {
4153 $v = trim( $v );
4154 $checked = '';
4155 foreach ( $value as $ov ) {
4156 if ( $v == $ov ) {
4157 $checked = ' checked="checked"';
4158 break;
4159 }
4160 }
4161 $html .= '<label for="itemOption[' . $cartmeta_id . ']' . $i . '" class="iopt_radio_label"><input name="itemOption[' . $cartmeta_id . ']" id="itemOption[' . $cartmeta_id . ']' . $i . '" class="iopt_radio" type="radio" value="' . urlencode( $v ) . '"' . $checked . ' onKeyDown="if (event.keyCode == 13) {return false;}">' . esc_html( $v ) . "</label>\n";
4162 $i++;
4163 }
4164 }
4165 break;
4166 case 4: //Check-box.
4167 $selects = explode( "\n", $field_data['value'] );
4168 $value = maybe_unserialize( $value );
4169 if ( ! is_array( $value ) ) {
4170 $value = (array) $value;
4171 }
4172 $diff = array_diff( (array) $value, $selects );
4173
4174 if ( isset( $diff[0] ) && ! empty( $diff[0] ) ) {
4175
4176 $value_str = '';
4177 foreach ( $value as $mv ) {
4178 $value_str .= $mv . ' & ';
4179 }
4180 $value_str = trim( $value_str, ' & ' );
4181 $html .= '<span>:' . esc_html( $value_str ) . '</span>' . "\n";
4182
4183 } else {
4184 $i = 0;
4185 foreach ( $selects as $v ) {
4186 $v = trim( $v );
4187 $opval = urlencode( $v );
4188 $val_str = isset( $value_arr[ $opval ] ) ? $value_arr[ $opval ] : '';
4189 if ( in_array( $v, (array) $value ) ) {
4190 $checked = ' checked="checked"';
4191 } else {
4192 $checked = '';
4193 }
4194 $html .= '<label for="itemOption[' . $cartmeta_id . ']' . $i . '" class="iopt_checkbox_label"><input name="itemOption[' . $cartmeta_id . '][]" id="itemOption[' . $cartmeta_id . ']' . $i . '" class="iopt_checkbox" type="checkbox" value="' . urlencode( $v ) . '"' . $checked . ' onKeyDown="if (event.keyCode == 13) {return false;}">' . esc_html( $v ) . "</label>\n";
4195 $i++;
4196 }
4197 }
4198 break;
4199 case 5: //Text-area.
4200 $html .= '<textarea name="itemOption[' . $cartmeta_id . ']" id="itemOption[' . $cartmeta_id . ']" class="iopt_textarea">' . esc_attr( $value ) . '</textarea>' . "\n";
4201 break;
4202 }
4203
4204 $html = apply_filters( 'usces_filter_get_itemOption', $html, $opt_value, $post_id );
4205
4206 return $html;
4207 }
4208
4209 function usces_update_ordercart_meta_value( $cartmeta_id, $value ) {
4210 global $wpdb;
4211
4212 if ( ! $cartmeta_id ) {
4213 return;
4214 }
4215
4216 $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
4217
4218 $query = $wpdb->prepare( "UPDATE $ordercart_meta_table SET meta_value = %s WHERE cartmeta_id = %d", $value, $cartmeta_id );
4219 $res = $wpdb->query( $query );
4220 return $res;
4221 }
4222
4223 function usces_set_ordercart_meta_value( $type, $cart_id, $key, $value ) {
4224 global $wpdb;
4225
4226 if ( ! $type || ! $cart_id || ! $key || ! $value ) {
4227 return;
4228 }
4229
4230 $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
4231
4232 $query = $wpdb->prepare(
4233 "SELECT cartmeta_id FROM $ordercart_meta_table
4234 WHERE cart_id = %d AND meta_type = %s AND meta_key = %s ",
4235 $cart_id, $type, $key
4236 );
4237 $res1 = $wpdb->get_var( $query );
4238
4239 if ( $res1 ) {
4240 $query = $wpdb->prepare(
4241 "UPDATE $ordercart_meta_table SET meta_value = %s
4242 WHERE cart_id = %d AND meta_type = %s AND meta_key = %s",
4243 $value, $cart_id, $type, $key
4244 );
4245 $res2 = $wpdb->query( $query );
4246 } else {
4247 $query = $wpdb->prepare(
4248 "INSERT INTO $ordercart_meta_table ( cart_id, meta_type, meta_key, meta_value ) VALUES ( %d, %s, %s, %s )",
4249 $cart_id, $type, $key, $value
4250 );
4251 $res2 = $wpdb->query( $query );
4252 }
4253 return $res2;
4254 }
4255
4256 function usces_get_ordercart_meta( $type, $cart_id, $key = '' ) {
4257 global $wpdb;
4258
4259 if ( ! $cart_id ) {
4260 return;
4261 }
4262
4263 $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
4264
4265 if ( '' !== $key ) {
4266 $query = $wpdb->prepare(
4267 "SELECT cartmeta_id, meta_key, meta_value
4268 FROM $ordercart_meta_table
4269 WHERE cart_id = %d AND meta_type = %s AND meta_key = %s
4270 ORDER BY cartmeta_id",
4271 $cart_id, $type, $key
4272 );
4273 } else {
4274 $query = $wpdb->prepare(
4275 "SELECT cartmeta_id, meta_key, meta_value
4276 FROM $ordercart_meta_table
4277 WHERE cart_id = %d AND meta_type = %s
4278 ORDER BY cartmeta_id",
4279 $cart_id, $type
4280 );
4281 }
4282 $res = $wpdb->get_results( $query, ARRAY_A );
4283 return $res;
4284 }
4285
4286 function usces_add_ordercart_meta_value( $type, $cart_id, $key, $value ) {
4287 global $wpdb;
4288
4289 if ( ! $type || ! $cart_id || ! $key || ! $value ) {
4290 return;
4291 }
4292
4293 $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
4294
4295 $query = $wpdb->prepare(
4296 "INSERT INTO $ordercart_meta_table
4297 ( cart_id, meta_type, meta_key, meta_value ) VALUES ( %d, %s, %s, %s )",
4298 $cart_id, $type, $key, $value
4299 );
4300 $res = $wpdb->query( $query );
4301 return $res;
4302 }
4303
4304 function usces_get_ordercart_meta_value( $type, $cart_id, $key = '' ) {
4305 global $wpdb;
4306
4307 if ( ! $cart_id ) {
4308 return;
4309 }
4310
4311 $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
4312
4313 if ( '' !== $key ) {
4314 $query = $wpdb->prepare(
4315 "SELECT meta_value
4316 FROM $ordercart_meta_table
4317 WHERE cart_id = %d AND meta_type = %s AND meta_key = %s
4318 ORDER BY cartmeta_id",
4319 $cart_id, $type, $key
4320 );
4321 } else {
4322 $query = $wpdb->prepare(
4323 "SELECT meta_value
4324 FROM $ordercart_meta_table
4325 WHERE cart_id = %d AND meta_type = %s
4326 ORDER BY cartmeta_id",
4327 $cart_id, $type
4328 );
4329 }
4330 $res = $wpdb->get_var( $query );
4331 return $res;
4332 }
4333
4334 function usces_get_ordercart_meta_by_id( $cartmeta_id ) {
4335 global $wpdb;
4336
4337 if ( ! $cartmeta_id ) {
4338 return;
4339 }
4340
4341 $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
4342
4343 $query = $wpdb->prepare( "SELECT * FROM $ordercart_meta_table WHERE cartmeta_id = %d", $cartmeta_id );
4344 $res = $wpdb->get_row( $query, ARRAY_A );
4345 return $res;
4346 }
4347
4348 function usces_get_post_id_by_cartmeta_id( $cartmeta_id ) {
4349 global $wpdb;
4350
4351 if ( ! $cartmeta_id ) {
4352 return 0;
4353 }
4354
4355 $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
4356 $ordercart_table = $wpdb->prefix . 'usces_ordercart';
4357
4358 $query = $wpdb->prepare( "SELECT cart_id FROM $ordercart_meta_table WHERE cartmeta_id = %d", $cartmeta_id );
4359 $cart_id = $wpdb->get_var( $query );
4360 if ( ! $cartmeta_id ) {
4361 return 0;
4362 }
4363
4364 $query = $wpdb->prepare( "SELECT post_id FROM $ordercart_table WHERE cart_id = %d", $cart_id );
4365 $post_id = $wpdb->get_var( $query );
4366
4367 return $post_id;
4368 }
4369
4370 function usces_delete_ordercart_meta_by_id( $cartmeta_id ) {
4371 global $wpdb;
4372
4373 if ( ! $cartmeta_id ) {
4374 return;
4375 }
4376
4377 $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
4378
4379 $query = $wpdb->prepare( "DELETE FROM $ordercart_meta_table WHERE cartmeta_id = %d", $cartmeta_id );
4380 $res = $wpdb->query( $query );
4381 return $res;
4382 }
4383
4384 function usces_make_advance_value( $advance, $cart_row ) {
4385 $value = '';
4386 $advance_value = array();
4387
4388 foreach ( $advance as $row ) {
4389 $advance_value[] = array( $row['meta_key'] => $row['meta_value'] );
4390 }
4391 $value = apply_filters( 'usces_filter_order_edit_form_row_advance_value', serialize( $advance_value ), $advance, $cart_row );
4392 return $value;
4393 }
4394
4395 function usces_get_ordercart_row( $order_id, $cart = array() ) {
4396 global $usces;
4397
4398 if ( empty( $cart ) ) {
4399 $cart = usces_get_ordercartdata( $order_id );
4400 }
4401 $reduced_taxrate = usces_is_reduced_taxrate( $order_id );
4402 if ( $reduced_taxrate ) {
4403 $usces_tax = Welcart_Tax::get_instance();
4404 }
4405
4406 ob_start();
4407 foreach ( $cart as $i => $cart_row ) {
4408 $ordercart_id = $cart_row['cart_id'];
4409 $post_id = $cart_row['post_id'];
4410 $sku = $cart_row['sku'];
4411 $sku_code = $cart_row['sku_code'];
4412 $quantity = $cart_row['quantity'];
4413 $options = usces_get_ordercart_meta( 'option', $ordercart_id );
4414 $advance = usces_get_ordercart_meta( 'advance', $ordercart_id );
4415 $applicable_taxrate = ( $reduced_taxrate ) ? $usces_tax->get_ordercart_applicable_taxrate( $ordercart_id, $post_id, $sku_code ) : '';
4416 if ( 'reduced' === $applicable_taxrate ) {
4417 $reduced_taxrate_mark = '<span class="reduced_taxrate_mark">' . $usces_tax->reduced_taxrate_mark.'</span>';
4418 } else {
4419 $reduced_taxrate_mark = '';
4420 }
4421 $itemCode = $cart_row['item_code'];
4422 $itemName = $cart_row['item_name'];
4423 $cartItemName = $usces->getCartItemName_byOrder( $cart_row );
4424 $skuPrice = $cart_row['price'];
4425 $stock = $usces->getItemZaiko( $post_id, $sku_code );
4426 $stockid = $usces->getItemZaikoStatusId( $post_id, $sku_code );
4427 $red = ( 1 < $stockid ) ? 'class="signal_red"' : '';
4428 $pictid = (int) $usces->get_mainpictid( $itemCode );
4429 $materials = compact( 'i', 'cart_row', 'post_id', 'sku', 'sku_code', 'quantity', 'options', 'advance',
4430 'itemCode', 'itemName', 'cartItemName', 'skuPrice', 'stock', 'red', 'pictid', 'order_id' );
4431 $advance_value = usces_make_advance_value( $advance, $cart_row );
4432 $cart_thumbnail = ( ! empty( $pictid ) ) ? wp_get_attachment_image( $pictid, array( 80, 80 ), true ) : usces_get_attachment_noimage( array( 80, 80 ), $itemCode );
4433 $cart_thumbnail = apply_filters( 'usces_filter_cart_thumbnail', $cart_thumbnail, $post_id, $pictid, $i, $cart_row );
4434 $index_column = apply_filters( 'usces_filter_admin_cart_index', ( $i + 1 ), $materials );
4435 $post_status = get_post_status( $post_id );
4436 if ( $post_status && in_array( $post_status, array( 'publish', 'draft', 'private' ), true ) ) {
4437 $item_editpage = admin_url( 'admin.php?page=usces_itemedit&action=edit&post=' . $post_id . '&usces_referer=' . urlencode( site_url() . '/wp-admin/admin.php?page=usces_orderlist&order_action=edit&order_id=' . $order_id ) );
4438 } else {
4439 $item_editpage = '';
4440 }
4441 ?>
4442 <tr>
4443 <td><?php wel_esc_script_e( $index_column ); ?></td>
4444 <td><?php wel_esc_script_e( $cart_thumbnail ); ?></td>
4445 <td class="aleft">
4446 <?php if ( ! empty( $item_editpage ) ) : ?><a href="<?php echo esc_url( $item_editpage ); ?>" title="<?php esc_attr_e( 'To the edit screen for this product.', 'usces' ); ?>" ><?php endif; ?>
4447 <?php echo apply_filters( 'usces_filter_admin_cart_item_name', esc_html( $cartItemName ), $materials ); ?>
4448 <?php if ( ! empty( $item_editpage ) ) : ?></a><?php endif; ?>
4449 <?php wel_esc_script_e( $reduced_taxrate_mark ); ?><?php do_action( 'usces_admin_order_item_name', $order_id, $i ); ?><?php usces_make_option_field( $materials, $cart ); ?></td>
4450 <td><input name="skuPrice[<?php echo esc_attr( $ordercart_id ); ?>]" class="text price" type="text" value="<?php echo esc_attr( usces_crform( $skuPrice, false, false, 'return', false ) ); ?>" /><?php do_action( 'usces_admin_order_cart_after_price', $materials ); ?></td>
4451 <td><input name="quant[<?php echo esc_attr( $ordercart_id ); ?>]" class="text quantity" type="text" value="<?php echo esc_attr( $cart_row['quantity'] ); ?>" /></td>
4452 <td><p id="sub_total[<?php echo esc_attr( $ordercart_id ); ?>]" class="aright">&nbsp;</p><?php do_action( 'usces_admin_order_cart_after_sub_total', $materials ); ?></td>
4453 <td <?php wel_esc_script_e( $red ); ?>><?php echo esc_html( $stock ); ?></td>
4454 <td>
4455 <input name="postId[<?php echo esc_attr( $ordercart_id ); ?>]" type="hidden" value="<?php echo esc_attr( $post_id ); ?>" />
4456 <input name="advance[<?php echo esc_attr( $ordercart_id ); ?>]" type="hidden" value="<?php echo esc_attr( $advance_value ); ?>" />
4457 <?php if ( $reduced_taxrate ) : ?>
4458 <input name="applicable_taxrate[<?php echo esc_attr( $ordercart_id ); ?>]" type="hidden" value="<?php echo esc_attr( $applicable_taxrate ); ?>" />
4459 <?php endif; ?>
4460 <input name="delButtonAdmin[<?php echo esc_attr( $ordercart_id ); ?>]" class="button delCartButton" type="submit" value="<?php esc_html_e( 'Delete', 'usces' ); ?>" />
4461 <?php do_action( 'usces_admin_order_cart_button', $order_id, $i ); ?>
4462 </td>
4463 </tr>
4464 <?php
4465 }
4466 $row = ob_get_contents();
4467 ob_end_clean();
4468
4469 return apply_filters( 'usces_filter_get_ordercart_row', $row, $order_id, $cart );
4470 }
4471
4472 /**
4473 * Add capabilities to the roles.
4474 *
4475 * return void
4476 */
4477 function usces_add_capabilites() {
4478 $admin_role = get_role( 'administrator' );
4479 $admin_role->add_cap( 'wel_publish_products' );
4480 $admin_role->add_cap( 'wel_others_products' );
4481 $admin_role->add_cap( 'wel_manage_order' );
4482 $admin_role->add_cap( 'wel_manage_setting' );
4483
4484 $editor_role = get_role( 'editor' );
4485 $editor_role->add_cap( 'wel_publish_products' );
4486 $editor_role->add_cap( 'wel_others_products' );
4487 $editor_role->add_cap( 'wel_manage_order' );
4488 $editor_role->add_cap( 'wel_manage_setting' );
4489
4490 $wc_management_role = get_role( 'wc_management' );
4491 $wc_management_role->add_cap( 'wel_publish_products' );
4492 $wc_management_role->add_cap( 'wel_others_products' );
4493 $wc_management_role->add_cap( 'wel_manage_order' );
4494
4495 $wc_author_role = get_role( 'wc_author' );
4496 $wc_author_role->add_cap( 'wel_publish_products' );
4497 $wc_author_role->add_cap( 'wel_others_products' );
4498
4499 $author_role = get_role( 'author' );
4500 $author_role->add_cap( 'wel_publish_products' );
4501 }
4502
4503 function usces_add_role() {
4504
4505 if ( ! get_role( 'wc_author' ) ) {
4506 $capabilities = array(
4507 'moderate_comments' => 1,
4508 'manage_categories' => 1,
4509 'manage_links' => 1,
4510 'upload_files' => 1,
4511 'unfiltered_html' => 1,
4512 'edit_posts' => 1,
4513 'edit_others_posts' => 1,
4514 'edit_published_posts' => 1,
4515 'publish_posts' => 1,
4516 'edit_pages' => 1,
4517 'read' => 1,
4518 'level_4' => 1,
4519 'level_3' => 1,
4520 'level_2' => 1,
4521 'level_1' => 1,
4522 'level_0' => 1,
4523 'edit_others_pages' => 1,
4524 'edit_published_pages' => 1,
4525 'publish_pages' => 1,
4526 'delete_pages' => 1,
4527 'delete_others_pages' => 1,
4528 'delete_published_pages' => 1,
4529 'delete_posts' => 1,
4530 'delete_others_posts' => 1,
4531 'delete_published_posts' => 1,
4532 'delete_private_posts' => 1,
4533 'edit_private_posts' => 1,
4534 'read_private_posts' => 1,
4535 'delete_private_pages' => 1,
4536 'edit_private_pages' => 1,
4537 'read_private_pages' => 1,
4538 );
4539 add_role( 'wc_author', __( 'Editor (no management authority)', 'usces' ), $capabilities );
4540 }
4541
4542 if ( ! get_role( 'wc_management' ) ) {
4543 $capabilities = array(
4544 'moderate_comments' => 1,
4545 'manage_categories' => 1,
4546 'manage_links' => 1,
4547 'upload_files' => 1,
4548 'unfiltered_html' => 1,
4549 'edit_posts' => 1,
4550 'edit_others_posts' => 1,
4551 'edit_published_posts' => 1,
4552 'publish_posts' => 1,
4553 'edit_pages' => 1,
4554 'read' => 1,
4555 'level_5' => 1,
4556 'level_4' => 1,
4557 'level_3' => 1,
4558 'level_2' => 1,
4559 'level_1' => 1,
4560 'level_0' => 1,
4561 'edit_others_pages' => 1,
4562 'edit_published_pages' => 1,
4563 'publish_pages' => 1,
4564 'delete_pages' => 1,
4565 'delete_others_pages' => 1,
4566 'delete_published_pages' => 1,
4567 'delete_posts' => 1,
4568 'delete_others_posts' => 1,
4569 'delete_published_posts' => 1,
4570 'delete_private_posts' => 1,
4571 'edit_private_posts' => 1,
4572 'read_private_posts' => 1,
4573 'delete_private_pages' => 1,
4574 'edit_private_pages' => 1,
4575 'read_private_pages' => 1,
4576 );
4577 add_role( 'wc_management', __( 'Editor (no setting authority)', 'usces' ), $capabilities );
4578 }
4579
4580 remove_role( 'wpsc_anonymous' );
4581 }
4582
4583 function usces_get_admin_user_level() {
4584 global $current_user;
4585
4586 wp_get_current_user();
4587 $levels = array();
4588 foreach ( $current_user->allcaps as $key => $value ) {
4589 $parts = explode( '_', $key );
4590 if ( 'level' == $parts[0] ) {
4591 $levels[] = $parts[1];
4592 }
4593 }
4594 if ( empty( $levels ) ) {
4595 return 0;
4596 } else {
4597 rsort( $levels );
4598 return $levels[0];
4599 }
4600 }
4601
4602 function usces_make_lost_key() {
4603 return uniqid( 'wc' , true );
4604 }
4605
4606 function usces_store_lostmail_key( $lost_mail, $lost_key ) {
4607 global $wpdb;
4608
4609 $date = substr( current_time( 'mysql' ), 0, 10 );
4610 $table = $wpdb->prefix . 'usces_access';
4611 $query = $wpdb->prepare( "INSERT INTO {$table} (acc_key, acc_type, acc_value, acc_date) VALUES (%s, %s, %s, %s)", $lost_mail, 'lostkey', $lost_key, $date );
4612 $res = $wpdb->query( $query );
4613 return $res;
4614 }
4615
4616 function usces_remove_lostmail_key( $lost_mail, $lost_key ) {
4617 global $wpdb;
4618
4619 $table = $wpdb->prefix . 'usces_access';
4620 $query = $wpdb->prepare( "DELETE FROM {$table} WHERE acc_key = %s AND acc_type = %s AND acc_value = %s", $lost_mail, 'lostkey', $lost_key );
4621 $res = $wpdb->query( $query );
4622 return $res;
4623 }
4624
4625 function usces_check_lostkey( $lost_mail, $lost_key ) {
4626 global $wpdb;
4627
4628 $table = $wpdb->prefix . 'usces_access';
4629 $query = $wpdb->prepare( "SELECT ID FROM {$table} WHERE acc_key = %s AND acc_type = %s AND acc_value = %s", $lost_mail, 'lostkey', $lost_key );
4630 $res = $wpdb->get_col( $query );
4631 return $res;
4632 }
4633
4634 function usces_clearup_lostkey() {
4635 global $wpdb;
4636
4637 $table = $wpdb->prefix . 'usces_access';
4638 $date = date( 'Y-m-d', current_time( 'timestamp' ) );
4639 $query = $wpdb->prepare( "DELETE FROM {$table} WHERE acc_type = %s AND acc_date < %s", 'lostkey', $date );
4640 $res = $wpdb->query( $query );
4641 do_action( 'usces_clearup_lostkey', $res );
4642 return $res;
4643 }
4644
4645 function usces_clearup_acting_data() {
4646 global $wpdb;
4647
4648 $table = $wpdb->prefix . 'usces_access';
4649 $date = date( 'Y-m-d', ( current_time( 'timestamp' ) - 86400 * 30 ) );
4650 $query = $wpdb->prepare( "DELETE FROM {$table} WHERE acc_type = %s AND acc_date < %s", 'acting_data', $date );
4651 $res = $wpdb->query( $query );
4652 do_action( 'usces_clearup_acting_data', $res );
4653 return $res;
4654 }
4655
4656 function usces_clearup_acting_log() {
4657 global $usces, $wpdb;
4658
4659 $table = $wpdb->prefix . 'usces_log';
4660 $date = date( 'Y-m-d 00:00:00', ( current_time( 'timestamp' ) - 86400 * 30 ) );
4661 $query = $wpdb->prepare( "DELETE FROM {$table} WHERE ( log_type = %s OR log_type = %s ) AND datetime < %s", 'acting_data', 'acting_error', $date );
4662 $res = $wpdb->query( $query );
4663 do_action( 'usces_clearup_acting_log', $res );
4664 }
4665
4666 function usces_acting_key() {
4667 global $usces;
4668 $acting_key = usces_rand();
4669 return $acting_key;
4670 }
4671
4672 function usces_change_order_receipt( $order_id, $flag ) {
4673 global $wpdb, $usces;
4674
4675 $table_name = $wpdb->prefix . 'usces_order';
4676
4677 if ( 'receipted' === $flag ) {
4678
4679 $mquery = $wpdb->prepare(
4680 "UPDATE $table_name SET order_status =
4681 CASE
4682 WHEN LOCATE('noreceipt', order_status) > 0 THEN REPLACE(order_status, 'noreceipt', 'receipted')
4683 WHEN LOCATE('receipted', order_status) > 0 THEN order_status
4684 ELSE CONCAT('receipted,', order_status )
4685 END
4686 WHERE ID = %d",
4687 $order_id
4688 );
4689 $res = $wpdb->query( $mquery );
4690
4691 $gmtdate = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) );
4692 $usces->set_order_meta_value( 'receipted_date', $gmtdate, $order_id );
4693
4694 } elseif ( 'noreceipt' === $flag ) {
4695
4696 $mquery = $wpdb->prepare(
4697 "UPDATE $table_name SET order_status =
4698 CASE
4699 WHEN LOCATE('receipted', order_status) > 0 THEN REPLACE(order_status, 'receipted', 'noreceipt')
4700 WHEN LOCATE('noreceipt', order_status) > 0 THEN order_status
4701 ELSE CONCAT('noreceipt,', order_status )
4702 END
4703 WHERE ID = %d",
4704 $order_id
4705 );
4706 $res = $wpdb->query( $mquery );
4707
4708 $usces->del_order_meta( 'receipted_date', $order_id );
4709 }
4710 return $res;
4711 }
4712
4713 function usces_localized_name( $familly_name, $given_name, $out = '' ) {
4714 global $usces_settings, $usces;
4715
4716 $familly_name = preg_replace( '/[\r\n]/', '', $familly_name );
4717 $given_name = preg_replace( '/[\r\n]/', '', $given_name );
4718
4719 $options = get_option( 'usces', array() );
4720 $form = $options['system']['addressform'];
4721 if ( $usces_settings['nameform'][ $form ] ) {
4722 $res = $given_name . ' ' . $familly_name;
4723 } else {
4724 $res = $familly_name . ' ' . $given_name;
4725 }
4726
4727 if ( 'return' === $out ) {
4728 return esc_html( $res );
4729 } else {
4730 echo esc_html( $res );
4731 }
4732 }
4733
4734 function usces_get_hash( $str, $salt = NULL, $type = 0 ) {
4735 //$hash = md5( trim( $str ) );
4736 $hash_algos = ( defined( 'USCES_HASH_ALGOS' ) ) ? USCES_HASH_ALGOS : 'md5';
4737 $secret_key = ( defined( 'USCES_SECRET_KEY' ) ) ? USCES_SECRET_KEY : '';
4738 if ( $secret_key ) {
4739 $hash = hash_hmac( $hash_algos, $str.$salt, $secret_key );
4740 } else {
4741 $hash = hash( $hash_algos, $str.$salt );
4742 }
4743 $args = compact( 'str', 'salt', 'type' );
4744 return apply_filters( 'usces_filter_get_hash', $hash, $args );
4745 }
4746
4747 function usces_get_salt( $mem_key, $type = 0 ) {
4748 global $wpdb;
4749
4750 $salt = '';
4751 if ( defined( 'USCES_SALT' ) && '1' === USCES_SALT ) {
4752 if ( 1 === $type ) {
4753 $salt = uniqid();
4754 } else {
4755 if ( ! empty( $mem_key ) ) {
4756 $member_table = usces_get_tablename( 'usces_member' );
4757 $member_meta_table = usces_get_tablename( 'usces_member_meta' );
4758 if ( is_numeric( $mem_key ) ) {
4759 $salt = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $member_meta_table WHERE member_id = %d AND meta_key = %s", $mem_key, 'mem_salt' ) );
4760 } else {
4761 $salt = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $member_table AS `member` INNER JOIN $member_meta_table AS `meta` ON member.ID = meta.member_id AND meta.meta_key = %s WHERE mem_email = %s", 'mem_salt', $mem_key ) );
4762 }
4763 }
4764 }
4765 }
4766 $args = compact( 'mem_key', 'type' );
4767 return apply_filters( 'usces_filter_get_salt', $salt, $args );
4768 }
4769
4770 function usces_get_member_reinforcement() {
4771 if ( defined( 'WCEX_DLSELLER' ) ) {
4772 $dlseller_options = get_option( 'dlseller' );
4773 if ( isset( $dlseller_options['dlseller_member_reinforcement'] ) && 'on' === $dlseller_options['dlseller_member_reinforcement'] ) {
4774 return true;
4775 }
4776 }
4777 return false;
4778 }
4779
4780 function usces_have_shipped( $cart = NULL ) {
4781 global $usces;
4782
4783 if ( empty( $cart ) ) {
4784 $cart = $usces->cart->get_cart();
4785 }
4786
4787 $division = '';
4788 foreach ( (array) $cart as $cart_row ) {
4789 if ( 'shipped' === $usces->getItemDivision( $cart_row['post_id'] ) ) {
4790 $division = 'shipped';
4791 break;
4792 }
4793 }
4794 if ( 'shipped' === $division ) {
4795 return true;
4796 } else {
4797 return false;
4798 }
4799 }
4800
4801 function usces_have_continue_charge( $cart = NULL ) {
4802 global $usces;
4803
4804 if ( empty( $cart ) ) {
4805 $cart = $usces->cart->get_cart();
4806 }
4807
4808 $charging_type = 'once';
4809 foreach ( (array) $cart as $cart_row ) {
4810 if ( 'continue' === $usces->getItemChargingType( $cart_row['post_id'] ) ) {
4811 $charging_type = 'continue';
4812 break;
4813 }
4814 }
4815 if ( 'continue' === $charging_type ) {
4816 return true;
4817 } else {
4818 return false;
4819 }
4820 }
4821
4822 function usces_have_regular_order() {
4823 if ( defined( 'WCEX_AUTO_DELIVERY' ) ) {
4824 return wcad_have_regular_order();
4825 }
4826 return false;
4827 }
4828
4829 function usces_have_member_regular_order( $member_id ) {
4830 if ( defined( 'WCEX_AUTO_DELIVERY' ) ) {
4831 return wcad_have_member_regular_order( $member_id );
4832 }
4833 return false;
4834 }
4835
4836 function usces_have_member_continue_order( $member_id ) {
4837 if ( defined( 'WCEX_DLSELLER' ) && function_exists( 'dlseller_have_member_continue_order' ) ) {
4838 return dlseller_have_member_continue_order( $member_id );
4839 }
4840 return false;
4841 }
4842
4843 function usces_is_available_point() {
4844 global $usces;
4845
4846 $res = true;
4847
4848 if ( defined( 'WCEX_DLSELLER' ) && function_exists( 'dlseller_have_continue_charge' ) ) {
4849 if ( dlseller_have_continue_charge() ) {
4850 $res = false;
4851 }
4852 }
4853
4854 return $res;
4855 }
4856
4857 function usces_get_link_key( $results ) {
4858 global $usces;
4859
4860 $linkkey = '(empty key)';
4861 if ( isset( $_REQUEST['X-S_TORIHIKI_NO'] ) ) {
4862 $linkkey = $_REQUEST['S_TORIHIKI_NO']; //remise.
4863 } elseif ( isset( $_REQUEST['acting'] ) && ( 'jpayment_card' === $_REQUEST['acting'] || 'jpayment_conv' === $_REQUEST['acting'] || 'jpayment_bank' === $_REQUEST['acting'] ) && isset( $_REQUEST['cod'] ) ) {
4864 $linkkey = $_REQUEST['cod']; //ROBOT PAYMENT (Cloud Payment,J-Payment).
4865 } elseif ( isset( $_REQUEST['txn_type'] ) && 'pro_hosted' === $_REQUEST['txn_type'] && isset( $_REQUEST['custom'] ) ) {
4866 $linkkey = $_REQUEST['custom']; //PayPal Webpayment Plus.
4867 } elseif ( isset( $_REQUEST['SID'] ) && isset( $_REQUEST['FUKA'] ) ) {
4868 $linkkey = $_REQUEST['SID']; //Payment for (MetapsPayment,paydesign,digitalcheck).
4869 } elseif ( isset( $_REQUEST['acting'] ) && ( 'mizuho_card' === $_REQUEST['acting'] || 'mizuho_conv' === $_REQUEST['acting'] ) && isset( $_REQUEST['stran'] ) ) {
4870 $linkkey = $_REQUEST['stran']; //mizuho.
4871 } elseif ( isset( $_REQUEST['SiteId'] ) && $usces->options['acting_settings']['anotherlane']['siteid'] === $_REQUEST['SiteId'] && isset( $_REQUEST['TransactionId'] ) ) {
4872 $linkkey = $_REQUEST['TransactionId']; //AnotherLane.
4873 } elseif ( isset( $_REQUEST['acting'] ) && ( 'veritrans_card' === $_REQUEST['acting'] || 'veritrans_conv' === $_REQUEST['acting'] ) && isset( $_REQUEST['orderId'] ) ) {
4874 $linkkey = $_REQUEST['orderId']; //Veritrans.
4875 } elseif ( isset( $_REQUEST['acting'] ) && 'telecom_card' === $_REQUEST['acting'] && isset( $_REQUEST['acting_return'] ) && isset( $_REQUEST['option'] ) ) {
4876 $linkkey = $_REQUEST['option']; //telecom credit.
4877 } elseif ( isset( $_REQUEST['acting'] ) && 'epsilon' === $_REQUEST['acting'] && isset( $_REQUEST['acting_return'] ) && isset( $_REQUEST['order_number'] ) ) {
4878 $linkkey = $_REQUEST['order_number']; //epsilon.
4879 }
4880 $linkkey = apply_filters( 'usces_filter_get_link_key', $linkkey, $results );
4881 return $linkkey;
4882 }
4883
4884 function usces_erase_emoji( $str ) {
4885 if ( $str ) {
4886 $newstr = preg_replace( '/[\xF0-\xF7][\x80-\xBF][\x80-\xBF][\x80-\xBF]/', '', $str );
4887 $str = apply_filters( 'usces_filter_erase_emoji', $newstr, $str );
4888 }
4889 return $str;
4890 }
4891
4892 function usces_is_reduced_taxrate( $order_id = '' ) {
4893 global $usces;
4894
4895 if ( empty( $order_id ) ) {
4896 $reduced = $usces->is_reduced_taxrate();
4897 } else {
4898 $condition = usces_get_order_condition( $order_id );
4899 $reduced = ( isset( $condition['applicable_taxrate'] ) && 'reduced' === $condition['applicable_taxrate'] ) ? true : false;
4900 }
4901 return $reduced;
4902 }
4903
4904 function usces_get_order_condition( $order_id ) {
4905 global $wpdb;
4906 $order_condition = $wpdb->get_var( $wpdb->prepare( "SELECT order_condition FROM {$wpdb->prefix}usces_order WHERE ID = %d", $order_id ) );
4907 return maybe_unserialize( $order_condition );
4908 }
4909
4910 function usces_tax_rounding_off( $tax, $tax_method = '' ) {
4911 global $usces;
4912
4913 if ( empty( $tax_method ) ) {
4914 $tax_method = $usces->options['tax_method'];
4915 }
4916 $decimal = $usces->get_currency_decimal();
4917 $decipad = (int) str_pad( '1', $decimal + 1, '0', STR_PAD_RIGHT );
4918 switch ( $tax_method ) {
4919 case 'cutting':
4920 if ( 0 < $tax ) {
4921 $tax = floor( (float) $tax * $decipad ) / $decipad;
4922 }
4923 break;
4924 case 'bring':
4925 if ( 0 < $tax ) {
4926 $tax = ceil( floatval( ( $tax . '' ) ) * $decipad ) / $decipad;
4927 }
4928 break;
4929 case 'rounding':
4930 if ( 0 < $decimal ) {
4931 if ( 0 < $tax ) {
4932 $tax = round( (float) $tax, $decimal );
4933 }
4934 } else {
4935 if ( 0 < $tax ) {
4936 $tax = round( (float) $tax );
4937 }
4938 }
4939 break;
4940 }
4941 return $tax;
4942 }
4943
4944 function usces_is_required_field( $name ) {
4945 global $usces_essential_mark;
4946
4947 $usces_essential_mark = apply_filters( 'usces_filter_essential_mark', $usces_essential_mark );
4948 if ( empty( $usces_essential_mark[ $name ] ) ) {
4949 return false;
4950 } else {
4951 return true;
4952 }
4953 }
4954
4955 function usces_get_tablename( $target ) {
4956 global $wpdb;
4957
4958 $prefix = '';
4959 if ( defined( 'WELCART_DB_PREFIX' ) ) {
4960 $prefix = WELCART_DB_PREFIX;
4961 }
4962 if ( ! $prefix ) {
4963 $prefix = $wpdb->prefix;
4964 }
4965 $tablename = $prefix . $target;
4966
4967 $tablename = apply_filters( 'usces_filter_get_tablename', $tablename, $target );
4968
4969 return $tablename;
4970 }
4971
4972 function usces_convert_zipcode( $zipcode ) {
4973 $zipcode = mb_convert_kana( $zipcode, 'a' );
4974 $zipcode = str_replace( '', '-', $zipcode );
4975 $zipcode = str_replace( '', '-', $zipcode );
4976 $zipcode = str_replace( '', '-', $zipcode );
4977 return $zipcode;
4978 }
4979
4980 function usces_get_sku( $post_id, $sku_code ) {
4981 global $usces;
4982 $skus = $usces->get_skus( $post_id, 'code' );
4983 $sku = isset( $skus[ $sku_code ] ) ? $skus[ $sku_code ] : array();
4984 return $sku;
4985 }
4986
4987 function usces_get_wp_environment() {
4988 global $wp_version, $wpdb;
4989
4990 $permalink_structure = get_option( 'permalink_structure' );
4991 // WP memory limit.
4992 $wp_memory_limit = usces_let_to_num( WP_MEMORY_LIMIT );
4993 if ( function_exists( 'memory_get_usage' ) ) {
4994 $wp_memory_limit = max( $wp_memory_limit, usces_let_to_num( @ini_get( 'memory_limit' ) ) ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
4995 }
4996 return array(
4997 'environment' => array(
4998 'wp_version' => $wp_version,
4999 'home_url' => get_option( 'home' ),
5000 'site_url' => get_option( 'siteurl' ),
5001 'site_language' => get_bloginfo( 'language' ),
5002 'timezone' => get_option( 'timezone_string' ),
5003 'number_of_media' => array_sum( (array) wp_count_attachments( array( 'image/jpeg', 'image/gif', 'image/png' ) ) ),
5004 'number_of_post' => get_option( 'posts_per_page' ),
5005 'blog_public' => get_option( 'blog_public' ),
5006 'thumbnail_size' => array(
5007 'width' => get_option( 'thumbnail_size_w' ),
5008 'height' => get_option( 'thumbnail_size_h' ),
5009 ),
5010 'medium_size' => array(
5011 'width' => get_option( 'medium_size_w' ),
5012 'height' => get_option( 'medium_size_h' ),
5013 ),
5014 'large_size' => array(
5015 'width' => get_option( 'large_size_w' ),
5016 'height' => get_option( 'large_size_h' ),
5017 ),
5018 'permalinks' => ( empty( $permalink_structure ) ) ? __( 'Plain', 'usces' ) : __( 'Custom structure', 'usces' ) . " ( {$permalink_structure} )",
5019 'wp_multisite' => is_multisite(),
5020 'wp_memory_limit' => $wp_memory_limit,
5021 'wp_debug_mode' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ),
5022 'server' => $_SERVER['SERVER_SOFTWARE'],
5023 'php_version' => phpversion(),
5024 'php_post_max_size' => ini_get( 'post_max_size' ),
5025 'php_max_execution_time' => ini_get( 'max_execution_time' ),
5026 'php_max_input_vars' => ini_get( 'max_input_vars' ),
5027 'curl_version' => curl_version(),
5028 'mysql_version' => $wpdb->dbh->server_info,
5029 'upload_max_filesize' => ini_get( 'upload_max_filesize' ),
5030 ),
5031 'theme' => usces_get_theme_info(),
5032 'active_plugins' => usces_get_active_plugins(),
5033 'inactive_plugins' => usces_get_inactive_plugins(),
5034 );
5035 }
5036
5037 /**
5038 * Get a list of plugins active on the site.
5039 *
5040 * @return array
5041 */
5042 function usces_get_active_plugins() {
5043 if ( ! function_exists( 'get_plugin_data' ) ) {
5044 return array();
5045 }
5046
5047 $active_plugins = (array) get_option( 'active_plugins', array() );
5048 if ( is_multisite() ) {
5049 $network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) );
5050 $active_plugins = array_merge( $active_plugins, $network_activated_plugins );
5051 }
5052
5053 $active_plugins_data = array();
5054
5055 foreach ( $active_plugins as $plugin ) {
5056 $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
5057 $active_plugins_data[] = usces_format_plugin_data( $plugin, $data );
5058 }
5059
5060 return $active_plugins_data;
5061 }
5062
5063 /**
5064 * Get a list of inplugins active on the site.
5065 *
5066 * @return array
5067 */
5068 function usces_get_inactive_plugins() {
5069 if ( ! function_exists( 'get_plugins' ) ) {
5070 return array();
5071 }
5072
5073 $plugins = get_plugins();
5074 $active_plugins = (array) get_option( 'active_plugins', array() );
5075
5076 if ( is_multisite() ) {
5077 $network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) );
5078 $active_plugins = array_merge( $active_plugins, $network_activated_plugins );
5079 }
5080
5081 $plugins_data = array();
5082
5083 foreach ( $plugins as $plugin => $data ) {
5084 if ( in_array( $plugin, $active_plugins, true ) ) {
5085 continue;
5086 }
5087 $plugins_data[] = usces_format_plugin_data( $plugin, $data );
5088 }
5089
5090 return $plugins_data;
5091 }
5092
5093 /**
5094 * Format plugin data, including data on updates, into a standard format.
5095 *
5096 * @since 3.6.0
5097 * @param string $plugin Plugin directory/file.
5098 * @param array $data Plugin data from WP.
5099 * @return array Formatted data.
5100 */
5101 function usces_format_plugin_data( $plugin, $data ) {
5102 if ( ! function_exists( 'get_plugin_updates' ) ) {
5103 return array();
5104 }
5105 $available_updates = get_plugin_updates();
5106
5107 $version_latest = $data['Version'];
5108
5109 // Find latest version.
5110 if ( isset( $available_updates[ $plugin ]->update->new_version ) ) {
5111 $version_latest = $available_updates[ $plugin ]->update->new_version;
5112 }
5113
5114 return array(
5115 'plugin' => $plugin,
5116 'name' => $data['Name'],
5117 'version' => $data['Version'],
5118 'version_latest' => $version_latest,
5119 'url' => $data['PluginURI'],
5120 'author_name' => $data['AuthorName'],
5121 'author_url' => esc_url_raw( $data['AuthorURI'] ),
5122 'network_activated' => $data['Network'],
5123 );
5124 }
5125
5126 /**
5127 * Get info on the current active theme, info on parent theme (if presnet)
5128 * and a list of template overrides.
5129 *
5130 * @return array
5131 */
5132 function usces_get_theme_info() {
5133 $active_theme = wp_get_theme();
5134
5135 $themes_update = get_site_transient( 'update_themes' );
5136
5137 if ( is_child_theme() ) {
5138 $parent_theme = wp_get_theme( $active_theme->template );
5139 $parent_theme_info = array(
5140 'parent_name' => $parent_theme->name,
5141 'parent_version' => $parent_theme->version,
5142 'parent_version_latest' => ( isset( $themes_update->response[ $parent_theme->get_stylesheet() ]['new_version'] ) ) ? $themes_update->response[ $parent_theme->get_stylesheet() ]['new_version'] : false,
5143 'parent_author_url' => $parent_theme->{'Author URI'},
5144 );
5145 } else {
5146 $parent_theme_info = array(
5147 'parent_name' => '',
5148 'parent_version' => '',
5149 'parent_version_latest' => '',
5150 'parent_author_url' => '',
5151 );
5152 }
5153
5154 $active_theme_info = array(
5155 'name' => $active_theme->name,
5156 'version' => $active_theme->version,
5157 'version_latest' => ( isset( $themes_update->response[ $active_theme->get_stylesheet() ]['new_version'] ) ) ? $themes_update->response[ $active_theme->get_stylesheet() ]['new_version'] : false,
5158 'author_url' => esc_url_raw( $active_theme->{'Author URI'} ),
5159 'is_child_theme' => is_child_theme(),
5160 );
5161
5162 return array_merge( $active_theme_info, $parent_theme_info );
5163 }
5164
5165 /**
5166 * Notation to numbers.
5167 *
5168 * This function transforms the php.ini notation for numbers (like '2M') to an integer.
5169 *
5170 * @param string $size Size value.
5171 * @return int
5172 */
5173 function usces_let_to_num( $size ) {
5174 $l = substr( $size, -1 );
5175 $ret = (int) substr( $size, 0, -1 );
5176 switch ( strtoupper( $l ) ) {
5177 case 'P':
5178 $ret *= 1024;
5179 // No break.
5180 case 'T':
5181 $ret *= 1024;
5182 // No break.
5183 case 'G':
5184 $ret *= 1024;
5185 // No break.
5186 case 'M':
5187 $ret *= 1024;
5188 // No break.
5189 case 'K':
5190 $ret *= 1024;
5191 // No break.
5192 }
5193 return $ret;
5194 }
5195
5196 function usces_get_total_orders() {
5197 global $wpdb;
5198
5199 $order_table_name = $wpdb->prefix . 'usces_order';
5200 $sql = "SELECT COUNT(*) AS total FROM $order_table_name";
5201 $result = $wpdb->get_row( $sql );
5202 return $result->total;
5203 }
5204
5205 function usces_get_total_members() {
5206 global $wpdb;
5207
5208 $member_table_name = usces_get_tablename( 'usces_member' );
5209 $sql = "SELECT COUNT(*) AS total FROM $member_table_name";
5210 $result = $wpdb->get_row( $sql );
5211 return $result->total;
5212 }
5213
5214 function get_welcart_system_information() {
5215 global $usces, $usces_settings;
5216
5217 $options = get_option( 'usces', array() );
5218 $options_ex = get_option( 'usces_ex', array() );
5219 $indi_item_name_text = array(
5220 'item_name' => 'item name',
5221 'item_code' => 'item code',
5222 'sku_name' => 'SKU name',
5223 'sku_code' => 'SKU code',
5224 );
5225 return array(
5226 'version' => USCES_VERSION,
5227 'total_items' => $usces->get_items_num(),
5228 'total_sku' => array_sum( usces_get_stocs() ),
5229 'maintenance_mode' => ( isset( $options['display_mode'] ) && $options['display_mode'] == 'Maintenancemode' ) ? true : false,
5230 'campaign_schedule' => $options['campaign_schedule'],
5231 'order_mail' => $options['order_mail'],
5232 'sender_mail' => $options['sender_mail'],
5233 'postage_privilege' => $options['postage_privilege'], // free ship condition.
5234 'purchase_limit' => $options['purchase_limit'],
5235 'shipping_rule' => $options['shipping_rule'],
5236 'shipping_rule_text' => get_option( 'usces_shipping_rule' ),
5237 'tax_mode' => $options['tax_mode'],
5238 'tax_target' => $options['tax_target'],
5239 'applicable_taxrate' => $options['applicable_taxrate'],
5240 'tax_rate' => $options['tax_rate'],
5241 'reduced_tax_rate' => $options['tax_rate_reduced'],
5242 'tax_method' => $options['tax_method'],
5243 'membership_system' => $options['membersystem_state'],
5244 'membership_point' => $options['membersystem_point'],
5245 'point_coverage' => $options['point_coverage'],
5246 'point_assign' => $options['point_assign'],
5247 'payment_methods' => usces_get_system_option( 'usces_payment_method', 'sort' ),
5248 'payment_structure' => $usces->payment_structure,
5249 'common_options' => usces_get_opts( USCES_CART_NUMBER ),
5250 'common_options_type' => get_option( 'usces_item_option_select' ),
5251 'shipping_methods' => $options['delivery_method'],
5252 'shipping_charge' => $options['shipping_charge'],
5253 'delivery_days' => $options['delivery_days'],
5254 'delivery_method' => $options['delivery_method'],
5255 'delivery_time_limit' => $options['delivery_time_limit'],
5256 'shortest_delivery_time' => $options['shortest_delivery_time'],
5257 'delivery_after_days' => $options['delivery_after_days'],
5258 'newmem_admin_mail' => $options['newmem_admin_mail'],
5259 'updmem_admin_mail' => $options['updmem_admin_mail'],
5260 'updmem_customer_mail' => $options['updmem_customer_mail'],
5261 'delmem_admin_mail' => $options['delmem_admin_mail'],
5262 'delmem_customer_mail' => $options['delmem_customer_mail'],
5263 'put_customer_name' => $options['put_customer_name'],
5264 'email_attach_feature' => $options['email_attach_feature'],
5265 'email_attach_file_extension' => $options['email_attach_file_extension'],
5266 'email_attach_file_size' => $options['email_attach_file_size'],
5267 'add_html_email_option' => $options['add_html_email_option'],
5268 'indi_item_name' => $options['indi_item_name'],
5269 'indi_item_name_text' => $indi_item_name_text,
5270 'pos_item_name' => $options['pos_item_name'],
5271 'divide_item' => $options['divide_item'],
5272 'itemimg_anchor_rel' => $options['itemimg_anchor_rel'],
5273 'fukugo_category_orderby' => $options['fukugo_category_orderby'],
5274 'fukugo_category_order' => $options['fukugo_category_order'],
5275 'use_ssl' => $options['use_ssl'],
5276 'inquiry_id' => $options['inquiry_id'],
5277 'no_cart_css' => $options['system']['no_cart_css'],
5278 'subimage_rule' => $options['system']['subimage_rule'],
5279 'pdf_delivery' => $options['system']['pdf_delivery'],
5280 'csv_encode_type' => $options['system']['csv_encode_type'],
5281 'csv_category_format' => $options['system']['csv_category_format'],
5282 'settlement_backup' => $options['system']['settlement_backup'],
5283 'settlement_notice' => $options['system']['settlement_notice'],
5284 'country' => $usces_settings['country'],
5285 'front_lang' => $options['system']['front_lang'],
5286 'currency' => $options['system']['currency'],
5287 'addressform' => $options['system']['addressform'],
5288 'target_market' => $options['system']['target_market'],
5289 'ganbare_activate_flag' => $options_ex['system']['ganbare']['activate_flag'],
5290 'stocklink_orderedit_flag' => $options_ex['system']['stocklink']['orderedit_flag'],
5291 'stocklink_collective_flag' => $options_ex['system']['stocklink']['collective_flag'],
5292 'datalistup_orderlist_flag' => $options_ex['system']['datalistup']['orderlist_flag'],
5293 'datalistup_memberlist_flag' => $options_ex['system']['datalistup']['memberlist_flag'],
5294 'verifyemail_switch_flag' => $options_ex['system']['verifyemail']['switch_flag'],
5295 'verifyemail_edit_flag' => $options_ex['system']['verifyemail']['edit_flag'],
5296 'verifyemail_login_notify' => $options_ex['system']['verifyemail']['login_notify'],
5297 'number_of_orders' => usces_get_total_orders(),
5298 'number_of_members' => usces_get_total_members(),
5299 'settlement_selected' => get_option( 'usces_settlement_selected', array() ),
5300 'available_settlement' => get_option( 'usces_available_settlement', array() ),
5301 'brute_force_status' => $options_ex['system']['brute_force']['status'],
5302 'google_recaptcha_status' => $options_ex['system']['google_recaptcha']['status'],
5303 'structured_data_product_status' => $options_ex['system']['structured_data_product']['status'],
5304 'fee_subject' => $usces->options['fee_subject'],
5305 'newproductimage_switch_flag' => $options_ex['system']['newproductimage']['switch_flag'],
5306 'operation_log_switch_flag' => $options_ex['system']['operation_log']['status'],
5307 'credit_security' => $options_ex['system']['credit_security']['active'],
5308 );
5309 }
5310
5311 function usces_generate_system_information_text( $environment, $theme, $active_plugins, $inactive_plugins, $welcart_information, $loaded_extensions, $ini_confs ) {
5312 $data = '### ' . __( 'WordPress Settings', 'usces' ) . " ###\r\n\r\n";
5313
5314 $data .= __( 'WordPress Address (URL)', 'usces' ) . ' : ' . esc_html( $environment['site_url'] ) . "\r\n";
5315 $data .= __( 'Site Address (URL)', 'usces' ) . ' : ' . esc_html( $environment['home_url'] ) . "\r\n";
5316 $data .= __( 'WordPress Version', 'usces' ) . ' : ' . esc_html( $environment['wp_version'] ) . "\r\n";
5317 $data .= __( 'Site Language', 'usces' ) . ' : ' . esc_html( $environment['site_language'] ) . "\r\n";
5318 $data .= __( 'Timezone', 'usces' ) . ' : ' . esc_html( $environment['timezone'] ) . "\r\n";
5319 $data .= __( 'Number of media files', 'usces' ) . ' : ' . esc_html( $environment['number_of_media'] ) . "\r\n";
5320 $data .= __( 'Blog pages show at most', 'usces' ) . ' : ' . esc_html( $environment['number_of_post'] ) . "\r\n";
5321 $data .= __( 'Search engine visibility', 'usces' ) . ' : ' . ( ( $environment['blog_public'] ) ? '' : __( 'Discourage search engines from indexing this site', 'usces' ) ) . "\r\n";
5322 $data .= __( 'Thumbnail size', 'usces' ) . ' : ' . __( 'Width', 'usces' ) . ' ' . esc_html( $environment['thumbnail_size']['width'] ) . ' ' . __( 'Height', 'usces' ) . ' ' . esc_html( $environment['thumbnail_size']['height'] ) . "\r\n";
5323 $data .= __( 'Image medium size', 'usces' ) . ' : ' . __( 'Width', 'usces' ) . ' ' . esc_html( $environment['medium_size']['width'] ) . ' ' . __( 'Height', 'usces' ) . ' ' . esc_html( $environment['medium_size']['height'] ) . "\r\n";
5324 $data .= __( 'Image large size', 'usces' ) . ' : ' . __( 'Width', 'usces' ) . ' ' . esc_html( $environment['large_size']['width'] ) . ' ' . __( 'Height', 'usces' ) . ' ' . esc_html( $environment['large_size']['height'] ) . "\r\n";
5325 $data .= __( 'Permalink Settings', 'usces' ) . ' : ' . esc_html( $environment['permalinks'] ) . "\r\n";
5326 $data .= __( 'WordPress Multisite', 'usces' ) . ' : ' . ( ( $environment['wp_multisite'] ) ? __( 'ON', 'usces' ) : '' ) . "\r\n";
5327 $data .= __( 'WordPress Memory Limit', 'usces' ) . ' : ' . esc_html( $environment['wp_memory_limit'] ) . "\r\n";
5328 $data .= __( 'WordPress Debug Mode', 'usces' ) . ' : ' . ( ( $environment['wp_debug_mode'] ) ? __( 'ON', 'usces' ) : __( 'OFF', 'usces' ) ) . "\r\n";
5329
5330 $data .= "\r\n" . '### ' . __( 'Theme', 'usces' ) . " ###\r\n\r\n";
5331 $data .= __( 'Theme name', 'usces' ) . ' : ' . esc_html( $theme['name'] ) . "\r\n";
5332 $data .= __( 'Theme version', 'usces' ) . ' : ' . esc_html( $theme['version'] ) . "\r\n";
5333 $data .= __( 'Author URL', 'usces' ) . ' : ' . esc_html( $theme['author_url'] ) . "\r\n";
5334 if ( isset( $theme['is_child_theme'] ) && $theme['is_child_theme'] ) {
5335 $data .= __( 'Parent theme name', 'usces' ) . ' : ' . esc_html( $theme['parent_name'] ) . "\r\n";
5336 $data .= __( 'Parent theme version', 'usces' ) . ' : ' . esc_html( $theme['parent_version'] ) . "\r\n";
5337 $data .= __( 'Parent author URL', 'usces' ) . ' : ' . esc_html( $theme['parent_author_url'] ) . "\r\n";
5338 }
5339
5340 $data .= "\r\n" . '### ' . __( 'Active Plugins', 'usces' ) . " ###\r\n\r\n";
5341 foreach ( $active_plugins as $plugin ) {
5342 $data .= esc_html( $plugin['name'] ) . ' : ' . __( 'by', 'usces' ) . ' ' . esc_html( $plugin['author_name'] ) . ' - ' . esc_html( $plugin['version'] ) .
5343 esc_html( ( $plugin['version'] != $plugin['version_latest'] ) ? sprintf( __( '( Update to version %1$s is available. )', 'usces' ), $plugin['version_latest'] ) : '' ) . "\r\n";
5344 }
5345
5346 $data .= "\r\n" . '### ' . __( 'Inactive Plugins', 'usces' ) . " ###\r\n\r\n";
5347 foreach ( $inactive_plugins as $plugin ) {
5348 $data .= esc_html( $plugin['name'] ) . ' : ' . __( 'by', 'usces' ) . ' ' . esc_html( $plugin['author_name'] ) . ' - ' . esc_html( $plugin['version'] ) .
5349 esc_html( ( $plugin['version'] != $plugin['version_latest'] ) ? sprintf( __( '( Update to version %1$s is available. )', 'usces' ), $plugin['version_latest'] ) : '' ) . "\r\n";
5350 }
5351 $data .= "\r\n" . '### ' . __( 'General Setting', 'usces' ) . " ###\r\n\r\n";
5352 $data .= __( 'Welcart Version', 'usces' ) . ' : ' . esc_html( $welcart_information['version'] ) . "\r\n";
5353 $data .= __( 'number of item', 'usces' ) . ' : ' . esc_html( $welcart_information['total_items'] ) . "\r\n";
5354 $data .= __( 'SKU total number', 'usces' ) . ' : ' . esc_html( $welcart_information['total_sku'] ) . "\r\n";
5355 $data .= __( 'Display mode', 'usces' ) . ' : ' . ( ( $welcart_information['maintenance_mode'] ) ? __( 'Under Maintenance', 'usces' ) : __( 'Normal business', 'usces' ) ) . "\r\n";
5356 $data .= __( 'Campaign Schedule', 'usces' ) . ' : ' . __( 'starting time', 'usces' ) . ': ';
5357 foreach ( $welcart_information['campaign_schedule']['start'] as $key => $value ) {
5358 $data .= esc_html( $value ) . ' ' . __( $key, 'usces' );
5359 }
5360 $data .= '. ' . __( 'date and time of termination', 'usces' ) . ': ';
5361 foreach ( $welcart_information['campaign_schedule']['end'] as $key => $value ) {
5362 $data .= esc_html( $value ) . ' ' . __( $key, 'usces' ) . ' ';
5363 }
5364 $data .= "\r\n";
5365
5366 $data .= __( 'E-mail address for ordering', 'usces' ) . ' : ' . esc_html( $welcart_information['order_mail'] ) . "\r\n";
5367 $data .= __( 'Sender\'s e-mail address', 'usces' ) . ' : ' . esc_html( $welcart_information['sender_mail'] ) . "\r\n";
5368 $data .= __( 'Conditions for free shipping', 'usces' ) . ' : ' . ( ( ! empty( $welcart_information['postage_privilege'] ) ) ? esc_html( $welcart_information['postage_privilege'] ) . __( 'Above', 'usces' ) : '' ) . "\r\n";
5369 $data .= __( 'default limitation number of purchase', 'usces' ) . ' : ' . ( ( ! empty( $welcart_information['purchase_limit'] ) ) ? esc_html( $welcart_information['purchase_limit'] ) . __( 'maximum amount', 'usces' ) : '' ) . "\r\n";
5370 $data .= __( 'initial value of date of sending out.', 'usces' ) . ' : ' . ( ( isset( $welcart_information['shipping_rule_text'][ $welcart_information['shipping_rule'] ] ) ) ? esc_html( $welcart_information['shipping_rule_text'][ $welcart_information['shipping_rule'] ] ) : '' ) . "\r\n";
5371 $data .= __( 'Tax treatment', 'usces' ) . ' : ' . ( ( $welcart_information['tax_mode'] == 'include' ) ? __( 'Included', 'usces' ) : __( 'Excluded', 'usces' ) ) . "\r\n";
5372 $data .= __( 'Tax target', 'usces' ) . ' : ' . ( ( $welcart_information['tax_target'] == 'products' ) ? __( 'Only Products', 'usces' ) : __( 'All Amount', 'usces' ) ) . "\r\n";
5373 $data .= __( 'Applicable tax rate', 'usces' ) . ' : ' . ( ( $welcart_information['applicable_taxrate'] == 'standard' ) ? __( 'Standard tax rate', 'usces' ) : __( 'Reduced tax rate', 'usces' ) ) . "\r\n";
5374 $data .= __( 'Percentage of Consumption tax', 'usces' ) . ' : ' . esc_html( ucfirst( $welcart_information['tax_rate'] ) ) . ' %' . "\r\n";
5375 $data .= __( 'Reduced tax rate', 'usces' ) . ' : ' . esc_html( $welcart_information['reduced_tax_rate'] ) . ' %' . "\r\n";
5376 $data .= __( 'method of Calculation of the tax', 'usces' ) . ' : ';
5377 switch ( $welcart_information['tax_method'] ) {
5378 case 'cutting':
5379 $data .= __( 'drop fractions', 'usces' ) . "\r\n";
5380 break;
5381 case 'bring':
5382 $data .= __( 'raise to a unit', 'usces' ) . "\r\n";
5383 break;
5384 case 'rounding':
5385 $data .= __( 'round up numbers of five and above and round down anything under', 'usces' ) . "\r\n";
5386 break;
5387 default:
5388 break;
5389 }
5390
5391 $data .= __( 'Subject to fees', 'usces' ) . ' : ' . ( ( $welcart_information['fee_subject'] == 'products' ) ? __( 'Only Products', 'usces' ) : __( 'All Amount', 'usces' ) ) . "\r\n";
5392 $data .= __( 'membership syetem', 'usces' ) . ' : ' . ( ( $welcart_information['membership_system'] == 'activate' ) ? __( 'to use', 'usces' ) : __( 'not to use', 'usces' ) ) . "\r\n";
5393 $data .= __( 'membership points', 'usces' ) . ' : ' . ( ( $welcart_information['membership_point'] == 'activate' ) ? __( 'to grant', 'usces' ) : __( 'not to grant', 'usces' ) ) . "\r\n";
5394 $data .= __( 'Areas of Point Redemption', 'usces' ) . ' : ' . ( ( $welcart_information['point_coverage'] ) ? __( 'Applicable to Total Merchandise Price and Handling Fee', 'usces' ) : __( 'Limited Only to Total Merchandise Price', 'usces' ) ) . "\r\n";
5395 $data .= __( 'Timing point of grant', 'usces' ) . ' : ' . ( ( $welcart_information['point_assign'] ) ? __( 'Payment at the time', 'usces' ) : __( 'Immediately', 'usces' ) ) . "\r\n";
5396
5397 $data .= "\r\n" . '### ' . __( 'payment method', 'usces' ) . " ###\r\n\r\n";
5398 foreach ( $welcart_information['payment_methods'] as $payment ) {
5399 $data .= esc_html( $payment['name'] ) . ' - ' . ( ( isset( $welcart_information['payment_structure'][ $payment['settlement'] ] ) ) ? ( esc_html( $welcart_information['payment_structure'][ $payment['settlement'] ] ) ) : '' ) . ' - ' . ( ( $payment['use'] == 'activate' ) ? __( 'Activate', 'usces' ) : __( 'Deactivate', 'usces' ) ) . "\r\n";
5400 }
5401
5402 $data .= "\r\n" . '### ' . __( 'Common Options', 'usces' ) . " ###\r\n\r\n";
5403 foreach ( $welcart_information['common_options'] as $common_options ) {
5404 $data .= __( 'option name', 'usces' ) . ' : ' . esc_html( $common_options['name'] ) . "\r\n";
5405 $data .= __( 'selected amount', 'usces' ) . ' : ' . ( str_replace( "\n", ' ', $common_options['value'] ) ) . "\r\n";
5406 $data .= __( 'Type of option', 'usces' ) . ' : ' . esc_html( ( isset( $welcart_information['common_options_type'][ $common_options['means'] ] ) ) ? ( esc_html( $welcart_information['common_options_type'][ $common_options['means'] ] ) ) : '' ) . "\r\n";
5407 $data .= __( 'Required', 'usces' ) . ' : ' . ( ( 1 === (int) $common_options['essential'] ) ? __( 'Essential', 'usces' ) : '' ) . "\r\n\r\n";
5408 }
5409
5410 $data .= "\r\n" . '### ' . __( 'shipping option', 'usces' ) . " ###\r\n\r\n";
5411 foreach ( $welcart_information['shipping_methods'] as $shipping ) {
5412 $charge = '';
5413 $delivery_day = '';
5414 if ( -1 === $shipping['charge'] ) {
5415 $charge = esc_html__( 'Not fixing shipping.', 'usces' );
5416 } else {
5417 foreach ( $welcart_information['shipping_charge'] as $shipping_charge ) {
5418 if ( $shipping['charge'] == $shipping_charge['id'] ) {
5419 $charge = $shipping_charge['name'];
5420 break;
5421 }
5422 }
5423 }
5424 if ( -1 === $shipping['days'] ) {
5425 $delivery_day = esc_html__( 'Delivery Date Not Specified', 'usces' );
5426 } else {
5427 foreach ( $welcart_information['delivery_days'] as $day ) {
5428 if ( $shipping['days'] == $day['id'] ) {
5429 $delivery_day = $day['name'];
5430 break;
5431 }
5432 }
5433 }
5434 $data .= esc_html( $shipping['name'] ) . ' - ' . ( str_replace( "\n", ' ', $shipping['time'] ) ) . ' - ' . ( ( $shipping['intl'] ) ? __( 'International Shipment', 'usces' ) : __( 'Domestic Shipment', 'usces' ) ) . ' - ';
5435 $data .= esc_html( $charge ) . ' - ' . esc_html( $delivery_day ) . ( ( $shipping['nocod'] ) ? ' - ' . __( 'No COD', 'usces' ) : '' ) . "\r\n";
5436 }
5437
5438 $data .= "\r\n" . '### ' . __( 'Shipping', 'usces' ) . " ###\r\n\r\n";
5439 foreach ( $welcart_information['shipping_charge'] as $shipping_charge ) {
5440 $data .= esc_html( $shipping_charge['name'] ) . "\r\n";
5441 }
5442
5443 $data .= "\r\n" . '### ' . __( 'Mail Options', 'usces' ) . " ###\r\n\r\n";
5444 $data .= __( 'New sign-in completion email', 'usces' ) . ' : ' . ( ( $welcart_information['newmem_admin_mail'] ) ? __( 'Send', 'usces' ) : __( 'Don\'t send', 'usces' ) ) . "\r\n";
5445 $data .= __( 'Member update completion email to admin', 'usces' ) . ' : ' . ( ( $welcart_information['updmem_admin_mail'] ) ? __( 'Send', 'usces' ) : __( 'Don\'t send', 'usces' ) ) . "\r\n";
5446 $data .= __( 'Member update completion email to customer', 'usces' ) . ' : ' . ( ( $welcart_information['updmem_customer_mail'] ) ? __( 'Send', 'usces' ) : __( 'Don\'t send', 'usces' ) ) . "\r\n";
5447 $data .= __( 'Member removal completion email to admin', 'usces' ) . ' : ' . ( ( $welcart_information['delmem_admin_mail'] ) ? __( 'Send', 'usces' ) : __( 'Don\'t send', 'usces' ) ) . "\r\n";
5448 $data .= __( 'Member removal completion email to customer', 'usces' ) . ' : ' . ( ( $welcart_information['delmem_customer_mail'] ) ? __( 'Send', 'usces' ) : __( 'Don\'t send', 'usces' ) ) . "\r\n";
5449 $data .= __( 'Customer name', 'usces' ) . ' : ' . ( ( $welcart_information['put_customer_name'] ) ? __( 'Indication', 'usces' ) : __( 'Non-indication', 'usces' ) ) . "\r\n";
5450 $data .= __( 'Attachment file for administrator email', 'usces' ) . ' : ' . ( ( $welcart_information['email_attach_feature'] ) ? __( 'Use', 'usces' ) : __( 'Do not Use', 'usces' ) ) . "\r\n";
5451 if ( $welcart_information['email_attach_feature'] ) {
5452 $data .= __( 'Extensions of attachments', 'usces' ) . ' : ' . esc_html( $welcart_information['email_attach_file_extension'] ) . "\r\n";
5453 $data .= __( 'Maximum size of email attachment', 'usces' ) . ' : ' . esc_html( $welcart_information['email_attach_file_size'] ) . " Mb\r\n";
5454 }
5455 $data .= __( 'HTML mail format', 'usces' ) . ' : ' . ( ( $welcart_information['add_html_email_option'] ) ? __( 'Use', 'usces' ) : __( 'Do not Use', 'usces' ) ) . "\r\n";
5456
5457 $data .= "\r\n" . '### ' . __( 'Rule of the column for a item name', 'usces' ) . " ###\r\n\r\n";
5458 foreach ( $welcart_information['indi_item_name'] as $key => $value ) {
5459 $data .= __( "Indication of {$welcart_information['indi_item_name_text'][ $key ]}", 'usces' ) . ' : ' . ( ( $value ) ? __( 'Show', 'usces' ) : '' ) . "\r\n";
5460 $data .= __( "Position of {$welcart_information['indi_item_name_text'][ $key ]}", 'usces' ) . ' : ' . esc_html( $welcart_information['pos_item_name'][ $key ] ) . "\r\n";
5461 }
5462 $data .= "\r\n" . '### ' . __( 'System Setting', 'usces' ) . " ###\r\n\r\n";
5463 $data .= __( 'Display Modes', 'usces' ) . ' : ' . ( ( $welcart_information['divide_item'] ) ? __( 'Not display an article in blog', 'usces' ) : '' ) . "\r\n";
5464 $data .= __( 'rel attribute', 'usces' ) . ' : ' . ( ( $welcart_information['itemimg_anchor_rel'] ) ? $welcart_information['itemimg_anchor_rel'] : '' ) . "\r\n";
5465 $data .= __( 'compound category sort item', 'usces' ) . ' : ' . ( ( 'name' == $welcart_information['fukugo_category_orderby'] ) ? __( 'category name', 'usces' ) : __( 'category ID', 'usces' ) ) . "\r\n";
5466 $data .= __( 'compound category sort order', 'usces' ) . ' : ' . ( ( 'DESC' == $welcart_information['fukugo_category_order'] ) ? __( 'Descendin', 'usces' ) : __( 'Ascending', 'usces' ) ) . "\r\n";
5467 $data .= __( 'Switching SSL', 'usces' ) . ' : ' . ( ( $welcart_information['use_ssl'] ) ? __( 'Switching', 'usces' ) : '' ) . "\r\n";
5468 $data .= __( 'The page_id of the inquiry-form', 'usces' ) . ' : ' . esc_html( $welcart_information['inquiry_id'] ) . "\r\n";
5469 $data .= __( 'To disable usces_cart.css', 'usces' ) . ' : ' . ( ( $welcart_information['no_cart_css'] ) ? __( 'To disable', 'usces' ) : '' ) . "\r\n";
5470 $data .= __( 'Product sub-image rule', 'usces' ) . ' : ' . ( ( $welcart_information['subimage_rule'] ) ? __( 'Put two _ (underscores) between the product code and the sequential number', 'usces' ) : __( 'Product Code Forward Matching', 'usces' ) ) . "\r\n";
5471 $data .= __( 'Described method of invoice', 'usces' ) . ' : ' . ( ( $welcart_information['pdf_delivery'] ) ? __( 'To address the shipping information', 'usces' ) : __( 'To address the purchaser information', 'usces' ) ) . "\r\n";
5472 $data .= __( 'Character code in the CSV file', 'usces' ) . ' : ' . ( ( $welcart_information['csv_encode_type'] ) ? __( 'UTF-8', 'usces' ) : __( 'Shift_JIS', 'usces' ) ) . "\r\n";
5473 $data .= __( "'Category' of CSV product data file", 'usces' ) . ' : ' . ( ( $welcart_information['csv_category_format'] ) ? __( 'slug (slug)', 'usces' ) : __( 'ID (tag_ID)', 'usces' ) ) . "\r\n";
5474 $data .= __( 'Order data re-created from the settlement log', 'usces' ) . ' : ' . ( ( $welcart_information['settlement_backup'] ) ? __( 'Use', 'usces' ) : __( 'Do not Use', 'usces' ) ) . "\r\n";
5475 $data .= __( 'Settlement error message', 'usces' ) . ' : ' . ( ( $welcart_information['settlement_notice'] ) ? __( 'Display', 'usces' ) : __( 'Do not display', 'usces' ) ) . "\r\n";
5476 $data .= __( 'The language of the front-end', 'usces' ) . ' : ' . esc_html( $welcart_information['front_lang'] ) . "\r\n";
5477 $data .= __( 'Currencies', 'usces' ) . ' : ' . ( ( isset( $welcart_information['country'][ $welcart_information['currency'] ] ) ) ? esc_html( $welcart_information['country'][ $welcart_information['currency'] ] ) : esc_html( $welcart_information['currency'] ) ) . "\r\n";
5478 $data .= __( 'The name and address form', 'usces' ) . ' : ' . ( ( isset( $welcart_information['country'][ $welcart_information['addressform'] ] ) ) ? esc_html( $welcart_information['country'][ $welcart_information['addressform'] ] ) : esc_html( $welcart_information['currency'] ) ) . "\r\n";
5479
5480 $target_market_country = array();
5481 foreach ( $welcart_information['target_market'] as $key => $value ) {
5482 if ( isset( $welcart_information['country'][ $value ] ) ) {
5483 $target_market_country[] = $welcart_information['country'][ $value ];
5484 }
5485 }
5486 $data .= __( 'Target Market', 'usces' ) . ' : ' . esc_html( implode( ', ', $target_market_country ) ) . "\r\n";
5487
5488 $data .= "\r\n" . '### ' . __( 'System extension', 'usces' ) . " ###\r\n\r\n";
5489 $data .= __( 'Ganbare Tencho', 'usces' ) . ' : ' . ( ( $welcart_information['ganbare_activate_flag'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5490 $data .= __( 'Linkage Order Upadate', 'usces' ) . ' : ' . ( ( $welcart_information['stocklink_orderedit_flag'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5491 $data .= __( 'Linkage Order Collective Upadate', 'usces' ) . ' : ' . ( ( $welcart_information['stocklink_collective_flag'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5492 $data .= __( '[New] Order List', 'usces' ) . ' : ' . ( ( $welcart_information['datalistup_orderlist_flag'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5493 $data .= __( '[New] Member List', 'usces' ) . ' : ' . ( ( $welcart_information['datalistup_memberlist_flag'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5494 $data .= __( 'Email verification for new registration', 'usces' ) . ' : ' . ( ( $welcart_information['verifyemail_switch_flag'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5495 $data .= __( 'Email verification for editing information', 'usces' ) . ' : ' . ( ( $welcart_information['verifyemail_edit_flag'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5496 $data .= __( 'Login Notification', 'usces' ) . ' : ' . ( ( $welcart_information['verifyemail_login_notify'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5497 $data .= __( 'Google reCAPTCHA v3', 'usces' ) . ' : ' . ( ( $welcart_information['google_recaptcha_status'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5498 $data .= __( 'Brute-force attack countermeasures', 'usces' ) . ' : ' . ( ( $welcart_information['brute_force_status'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5499 $data .= __( 'Structured data measures', 'usces' ) . ' : ' . ( ( $welcart_information['structured_data_product_status'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5500 $data .= __( 'New product image registration', 'usces' ) . ' : ' . ( ( $welcart_information['newproductimage_switch_flag'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5501 $data .= __( 'Operation Log', 'usces' ) . ' : ' . ( ( $welcart_information['operation_log_switch_flag'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5502 $data .= __( 'Credit Card Security Measures', 'usces' ) . ' : ' . ( ( $welcart_information['credit_security'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5503
5504 $data .= "\r\n" . '### ' . __( 'Settlement Setting', 'usces' ) . " ###\r\n\r\n";
5505 $settlement_selected_text = array();
5506 if ( is_array( $welcart_information['settlement_selected'] ) ) {
5507 foreach ( $welcart_information['settlement_selected'] as $key => $value ) {
5508 if ( isset( $welcart_information['available_settlement'][ $value ] ) ) {
5509 $settlement_selected_text[] = esc_html__( $welcart_information['available_settlement'][ $value ], 'usces' );
5510 }
5511 }
5512 }
5513 $data .= __( 'Settlement modules in use', 'usces' ) . ' : ' . esc_html( implode( ', ', $settlement_selected_text ) ) . "\r\n";
5514
5515 $data .= "\r\n" . '### ' . __( 'Management Information', 'usces' ) . " ###\r\n\r\n";
5516 $data .= __( 'Number of orders', 'usces' ) . ' : ' . esc_html( $welcart_information['number_of_orders'] ) . "\r\n";
5517 $data .= __( 'Number of members', 'usces' ) . ' : ' . esc_html( $welcart_information['number_of_members'] ) . "\r\n";
5518
5519 $data .= "\r\n" . '### ' . __( 'Server environment', 'usces' ) . " ###\r\n\r\n";
5520 $data .= __( 'Server', 'usces' ) . ' : ' . esc_html( $environment['server'] ) . "\r\n";
5521 $data .= __( 'PHP version', 'usces' ) . ' : ' . esc_html( $environment['php_version'] ) . "\r\n";
5522 $data .= __( 'PHP global memory', 'usces' ) . ' : ' . esc_html( $ini_confs['memory_limit']['global_value'] ) . "\r\n";
5523 $data .= __( 'PHP locale memory', 'usces' ) . ' : ' . esc_html( $ini_confs['memory_limit']['local_value'] ) . "\r\n";
5524 $data .= __( 'PHP post max size', 'usces' ) . ' : ' . esc_html( $environment['php_post_max_size'] ) . "\r\n";
5525 $data .= __( 'PHP time limit', 'usces' ) . ' : ' . esc_html( $environment['php_max_execution_time'] ) . "\r\n";
5526 $data .= __( 'PHP Max Input Vars', 'usces' ) . ' : ' . esc_html( $environment['php_max_input_vars'] ) . "\r\n";
5527 $data .= __( 'cURL', 'usces' ) . ' : ' . ( in_array( 'curl', $loaded_extensions ) ? 'ON' : '-' ) . "\r\n";
5528 $data .= __( 'cURL version', 'usces' ) . ' : ' . ( esc_html( $environment['curl_version']['version'] . ' ' . $environment['curl_version']['host'] ) ) . "\r\n";
5529 $data .= __( 'MySQL version', 'usces' ) . ' : ' . esc_html( $environment['mysql_version'] ) . "\r\n";
5530 $data .= __( 'Maximum upload size', 'usces' ) . ' : ' . esc_html( $environment['upload_max_filesize'] ) . "\r\n";
5531 $data .= __( 'SimpleXML', 'usces' ) . ' : ' . ( in_array( 'SimpleXML', $loaded_extensions ) ? 'ON' : '-' ) . "\r\n";
5532 $data .= __( 'gd', 'usces' ) . ' : ' . ( in_array( 'gd', $loaded_extensions ) ? 'ON' : '-' ) . "\r\n";
5533 $data .= __( 'json', 'usces' ) . ' : ' . ( in_array( 'json', $loaded_extensions ) ? 'ON' : '-' ) . "\r\n";
5534 $data .= __( 'mbstring', 'usces' ) . ' : ' . ( in_array( 'mbstring', $loaded_extensions ) ? 'ON' : '-' ) . "\r\n";
5535 $data .= __( 'openssl', 'usces' ) . ' : ' . ( in_array( 'openssl', $loaded_extensions ) ? 'ON' : '-' ) . "\r\n";
5536
5537 return $data;
5538 }
5539
5540 function usces_download_system_information() {
5541
5542 check_ajax_referer( 'admin_system' );
5543 if ( ! current_user_can( 'wel_manage_setting' ) ) {
5544 wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
5545 }
5546
5547 $filename = 'welcart_information_' . date_i18n( 'YmdHis' ) . '.txt';
5548 $wp_environment = usces_get_wp_environment();
5549 $environment = $wp_environment['environment'];
5550 $theme = $wp_environment['theme'];
5551 $active_plugins = $wp_environment['active_plugins'];
5552 $inactive_plugins = $wp_environment['inactive_plugins'];
5553 $welcart_information = get_welcart_system_information();
5554 $loaded_extensions = get_loaded_extensions();
5555 $ini_confs = ini_get_all();
5556 $data = usces_generate_system_information_text( $environment, $theme, $active_plugins, $inactive_plugins, $welcart_information, $loaded_extensions, $ini_confs );
5557 $result = array(
5558 'status' => true,
5559 'data' => $data,
5560 'filename' => $filename,
5561 );
5562 echo json_encode( $result );
5563 wp_die();
5564 }
5565
5566 /**
5567 * List Download Authority.
5568 *
5569 * @return boolean
5570 */
5571 function usces_admin_user_can_download_list() {
5572 $admin_user = array( 'administrator', 'wc_management' );
5573 $custom_user = apply_filters( 'usces_filter_admin_user_can_download_list', array() );
5574 if ( is_array( $custom_user ) && ! empty( $custom_user ) ) {
5575 $admin_user = array_merge( $admin_user, $custom_user );
5576 }
5577 $can_dl = false;
5578 foreach ( $admin_user as $user ) {
5579 if ( current_user_can( $user ) ) {
5580 $can_dl = true;
5581 break;
5582 }
5583 }
5584 return $can_dl;
5585 }
5586
5587 /**
5588 * Filter content wp_editor preview.
5589 */
5590 function usces_filter_content_wp_editor_preview() {
5591 global $usces;
5592
5593 $_POST = $usces->stripslashes_deep_post( $_POST );
5594
5595 if ( ! current_user_can( 'wel_manage_order' ) ) { // This preview is also used in order_edit_form.
5596 wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
5597 }
5598
5599 $nonce = isset( $_POST['wc_nonce'] ) ? wp_unslash( $_POST['wc_nonce'] ) : '';
5600 if ( ! wp_verify_nonce( $nonce, 'wc_preview_editor_nonce' ) ) {
5601 $error_msg = array( 'message' => 'Your request is not valid.' );
5602 wp_send_json_error( $error_msg, 403 );
5603 }
5604 $mode = $_POST['mode'];
5605 $res = array(
5606 'status' => false,
5607 );
5608 switch ( $mode ) {
5609 case 'preview_email':
5610 $content_header = isset( $_POST['content_header'] ) ? $_POST['content_header'] : '';
5611 $content_footer = isset( $_POST['content_footer'] ) ? $_POST['content_footer'] : '';
5612 $res['status'] = true;
5613 $res['content_header'] = wpautop( $content_header );
5614 $res['content_footer'] = wpautop( $content_footer );
5615 break;
5616 case 'preview_email_order_detail':
5617 $content = isset( $_POST['content'] ) ? $_POST['content'] : '';
5618 $res['status'] = true;
5619 $res['content'] = wpautop( $content );
5620 break;
5621 }
5622 wp_send_json( $res );
5623 }
5624
5625 /**
5626 * 手数料対象金額
5627 * -'all' 送料を含む�
5628 �額
5629 * -'products' 商品代金のみ
5630 *
5631 * @return string
5632 */
5633 function usces_is_fee_subject() {
5634 global $usces;
5635 $fee_subject = ( ! empty( $usces->options['fee_subject'] ) ) ? $usces->options['fee_subject'] : 'all';
5636 return $fee_subject;
5637 }
5638