PluginProbe
Welcart e-Commerce / 2.12.3
Welcart e-Commerce v2.12.3
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 1.4.13 All 291 releases
usc-e-shop / functions / function.php

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

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