PluginProbe
Welcart e-Commerce / 2.12.2
Welcart e-Commerce v2.12.2
2.12.4 2.12.3 2.11.35 2.12.2 2.12.1 2.11.34 2.11.33 2.11.32 2.11.31 2.11.30 1.3.16 1.3.17 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 All 292 releases
usc-e-shop / classes / usceshop.class.php

usceshop.class.php in Welcart e-Commerce 2.12.2, at classes/usceshop.class.php

10,507 lines 409.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Welcart Main Class
4 *
5 * @package Welcart
6 */
7 class usc_e_shop {
8
9 /**
10 * Page action.
11 *
12 * @var string
13 */
14 public $page;
15
16 /**
17 * Cart object.
18 *
19 * @var array
20 */
21 public $cart;
22
23 /**
24 * SSL flag.
25 *
26 * @var int
27 */
28 public $use_ssl;
29
30 public $action;
31 public $action_status;
32 public $error_status;
33 public $action_message;
34 public $error_message;
35 public $itemskus;
36 public $itemsku;
37 public $current_itemsku;
38 public $itemopts;
39 public $itemopt;
40 public $current_itemopt;
41 public $item;
42 public $zaiko_status;
43 public $payment_structure;
44 public $display_mode;
45 public $shipping_rule;
46 public $nonacting_settlements;
47 public $member_status;
48 public $options;
49 public $mail_para;
50 public $login_mail;
51 public $current_member;
52 public $member_form;
53 public $payment_results;
54 public $log_flg;
55 public $delim;
56 public $use_js;
57 public $user_level;
58 public $previous_url;
59
60 /**
61 * PayPal object.
62 *
63 * @var object
64 */
65 public $paypal;
66
67 /**
68 * Settlement object.
69 *
70 * @var array
71 */
72 public $settlement;
73
74 /**
75 * Settlement notice.
76 *
77 * @var string
78 */
79 public $settlement_notice;
80
81 /**
82 * Cart object for Multiple Shipping.
83 *
84 * @var array
85 */
86 public $msacart;
87
88 /**
89 * Constructor.
90 */
91 public function __construct() {
92 global $wpdb, $post, $usces_settings, $usces_states;
93
94 usces_add_role();
95 usces_add_capabilites();
96
97 do_action( 'usces_construct' );
98
99 add_action( 'init', array( $this, 'init' ), 1 );
100
101 $locales = usces_locales();
102 foreach ( $locales as $l ) {
103 $usces_settings['language'][ $l ] = $l;
104 }
105
106 $this->options = get_option( 'usces', array() );
107 if ( ! isset( $this->options['smtp_hostname'] ) || empty( $this->options['smtp_hostname'] ) ) {
108 $this->options['smtp_hostname'] = 'localhost';
109 }
110 if ( ! isset( $this->options['delivery_method'] ) || ! is_array( $this->options['delivery_method'] ) ) {
111 $this->options['delivery_method'] = array();
112 }
113 if ( ! isset( $this->options['shipping_charge'] ) || ! is_array( $this->options['shipping_charge'] ) ) {
114 $this->options['shipping_charge'] = array();
115 }
116 if ( ! isset( $this->options['membersystem_state'] ) ) {
117 $this->options['membersystem_state'] = 'activate';
118 }
119 if ( ! isset( $this->options['membersystem_point'] ) ) {
120 $this->options['membersystem_point'] = 'activate';
121 }
122 if ( ! isset( $this->options['use_ssl'] ) ) {
123 $this->options['use_ssl'] = 0;
124 }
125 if ( ! isset( $this->options['point_coverage'] ) ) {
126 $this->options['point_coverage'] = 0;
127 }
128 if ( ! isset( $this->options['use_javascript'] ) ) {
129 $this->options['use_javascript'] = 1;
130 }
131 if ( ! isset( $this->options['privilege_discount'] ) ) {
132 $this->options['privilege_discount'] = '';
133 }
134 if ( ! isset( $this->options['privilege_point'] ) ) {
135 $this->options['privilege_point'] = '';
136 }
137 if ( ! isset( $this->options['campaign_privilege'] ) ) {
138 $this->options['campaign_privilege'] = '';
139 }
140 if ( ! isset( $this->options['campaign_category'] ) ) {
141 $this->options['campaign_category'] = 0;
142 }
143 if ( ! isset( $this->options['campaign_schedule']['start'] ) ) {
144 $this->options['campaign_schedule']['start'] = array();
145 }
146 if ( ! isset( $this->options['campaign_schedule']['end'] ) ) {
147 $this->options['campaign_schedule']['end'] = array();
148 }
149 if ( ! isset( $this->options['purchase_limit'] ) ) {
150 $this->options['purchase_limit'] = '';
151 }
152 if ( ! isset( $this->options['point_rate'] ) ) {
153 $this->options['point_rate'] = '';
154 }
155 if ( ! isset( $this->options['shipping_rule'] ) ) {
156 $this->options['shipping_rule'] = '';
157 }
158 if ( ! isset( $this->options['company_name'] ) ) {
159 $this->options['company_name'] = '';
160 }
161 if ( ! isset( $this->options['address1'] ) ) {
162 $this->options['address1'] = '';
163 }
164 if ( ! isset( $this->options['address2'] ) ) {
165 $this->options['address2'] = '';
166 }
167 if ( ! isset( $this->options['zip_code'] ) ) {
168 $this->options['zip_code'] = '';
169 }
170 if ( ! isset( $this->options['tel_number'] ) ) {
171 $this->options['tel_number'] = '';
172 }
173 if ( ! isset( $this->options['fax_number'] ) ) {
174 $this->options['fax_number'] = '';
175 }
176 if ( ! isset( $this->options['order_mail'] ) ) {
177 $this->options['order_mail'] = '';
178 }
179 if ( ! isset( $this->options['inquiry_mail'] ) ) {
180 $this->options['inquiry_mail'] = '';
181 }
182 if ( ! isset( $this->options['sender_mail'] ) ) {
183 $this->options['sender_mail'] = '';
184 }
185 if ( ! isset( $this->options['error_mail'] ) ) {
186 $this->options['error_mail'] = '';
187 }
188 if ( ! isset( $this->options['copyright'] ) ) {
189 $this->options['copyright'] = '';
190 }
191 if ( ! isset( $this->options['business_registration_number'] ) ) {
192 $this->options['business_registration_number'] = '';
193 }
194 if ( ! isset( $this->options['postage_privilege'] ) ) {
195 $this->options['postage_privilege'] = '';
196 }
197 if ( ! isset( $this->options['shipping_rule'] ) ) {
198 $this->options['shipping_rule'] = '';
199 }
200 if ( ! isset( $this->options['tax_display'] ) ) {
201 $this->options['tax_display'] = 'activate';
202 }
203 if ( ! isset( $this->options['applicable_taxrate'] ) || empty( $this->options['applicable_taxrate'] ) ) {
204 $this->options['applicable_taxrate'] = 'standard';
205 }
206 if ( ! isset( $this->options['tax_rate'] ) ) {
207 $this->options['tax_rate'] = '';
208 $this->options['tax_method'] = 'cutting';
209 $this->options['tax_mode'] = 'include';
210 $this->options['tax_target'] = 'products';
211 } else {
212 if ( ! isset( $this->options['tax_mode'] ) ) {
213 $this->options['tax_mode'] = empty( $this->options['tax_rate'] ) ? 'include' : 'exclude';
214 }
215 if ( ! isset( $this->options['tax_target'] ) ) {
216 $this->options['tax_target'] = 'all';
217 }
218 }
219 if ( ! isset( $this->options['tax_rate_reduced'] ) ) {
220 $this->options['tax_rate_reduced'] = '';
221 }
222 if ( ! isset( $this->options['transferee'] ) ) {
223 $this->options['transferee'] = '';
224 }
225 if ( ! isset( $this->options['tatransfer_limit'] ) ) {
226 $this->options['tatransfer_limit'] = '';
227 }
228 if ( ! isset( $this->options['membersystem_state'] ) ) {
229 $this->options['membersystem_state'] = 'activate';
230 }
231 if ( ! isset( $this->options['membersystem_point'] ) ) {
232 $this->options['membersystem_point'] = '';
233 }
234 if ( ! isset( $this->options['point_rate'] ) ) {
235 $this->options['point_rate'] = '';
236 }
237 if ( ! isset( $this->options['start_point'] ) ) {
238 $this->options['start_point'] = '';
239 }
240 if ( ! isset( $this->options['point_coverage'] ) ) {
241 $this->options['point_coverage'] = 1;
242 }
243 if ( ! isset( $this->options['point_assign'] ) ) {
244 $this->options['point_assign'] = 1;
245 }
246 if ( ! isset( $this->options['cod_type'] ) ) {
247 $this->options['cod_type'] = 'fix';
248 }
249 if ( ! isset( $this->options['fee_subject'] ) ) {
250 $this->options['fee_subject'] = 'all';
251 }
252 if ( ! isset( $this->options['address_search'] ) ) {
253 $this->options['address_search'] = 'deactivate';
254 }
255 if ( ! isset( $this->options['newmem_admin_mail'] ) ) {
256 $this->options['newmem_admin_mail'] = 0;
257 }
258 if ( ! isset( $this->options['updmem_admin_mail'] ) ) {
259 $this->options['updmem_admin_mail'] = 0;
260 }
261 if ( ! isset( $this->options['updmem_customer_mail'] ) ) {
262 $this->options['updmem_customer_mail'] = 0;
263 }
264 if ( ! isset( $this->options['delmem_admin_mail'] ) ) {
265 $this->options['delmem_admin_mail'] = 1;
266 }
267 if ( ! isset( $this->options['delmem_customer_mail'] ) ) {
268 $this->options['delmem_customer_mail'] = 1;
269 }
270 if ( ! isset( $this->options['put_customer_name'] ) ) {
271 $this->options['put_customer_name'] = '0';
272 }
273 if ( ! isset( $this->options['email_attach_feature'] ) ) {
274 $this->options['email_attach_feature'] = '0';
275 }
276 if ( ! isset( $this->options['email_attach_file_extension'] ) ) {
277 $this->options['email_attach_file_extension'] = 'jpg,png,pdf';
278 }
279 if ( ! isset( $this->options['email_attach_file_size'] ) ) {
280 $this->options['email_attach_file_size'] = 3;
281 }
282 if ( ! isset( $this->options['add_html_email_option'] ) ) {
283 $this->options['add_html_email_option'] = 0;
284 }
285 if ( ! isset( $this->options['mail_data']['title'] ) ) {
286 $this->options['mail_data']['title'] = array(
287 'thankyou' => '',
288 'order' => '',
289 'inquiry' => '',
290 'returninq' => '',
291 'membercomp' => '',
292 'completionmail' => '',
293 'ordermail' => '',
294 'changemail' => '',
295 'receiptmail' => '',
296 'mitumorimail' => '',
297 'cancelmail' => '',
298 'othermail' => '',
299 );
300 }
301 if ( ! isset( $this->options['mail_data']['header'] ) ) {
302 $this->options['mail_data']['header'] = array(
303 'thankyou' => '',
304 'order' => '',
305 'inquiry' => '',
306 'returninq' => '',
307 'membercomp' => '',
308 'completionmail' => '',
309 'ordermail' => '',
310 'changemail' => '',
311 'receiptmail' => '',
312 'mitumorimail' => '',
313 'cancelmail' => '',
314 'othermail' => '',
315 );
316 }
317 if ( ! isset( $this->options['mail_data']['footer'] ) ) {
318 $this->options['mail_data']['footer'] = array(
319 'thankyou' => '',
320 'order' => '',
321 'inquiry' => '',
322 'returninq' => '',
323 'membercomp' => '',
324 'completionmail' => '',
325 'ordermail' => '',
326 'changemail' => '',
327 'receiptmail' => '',
328 'mitumorimail' => '',
329 'cancelmail' => '',
330 'othermail' => '',
331 );
332 }
333 if ( ! isset( $this->options['cart_page_data']['header'] ) ) {
334 $this->options['cart_page_data']['header'] = array(
335 'cart' => '',
336 'customer' => '',
337 'delivery' => '',
338 'confirm' => '',
339 'completion' => '',
340 );
341 }
342 if ( ! isset( $this->options['cart_page_data']['footer'] ) ) {
343 $this->options['cart_page_data']['footer'] = array(
344 'cart' => '',
345 'customer' => '',
346 'delivery' => '',
347 'confirm' => '',
348 'completion' => '',
349 );
350 }
351 if ( ! isset( $this->options['cart_page_data']['confirm_notes'] ) ) {
352 $this->options['cart_page_data']['confirm_notes'] = '';
353 }
354 if ( ! isset( $this->options['member_page_data']['header'] ) ) {
355 $this->options['member_page_data']['header'] = array(
356 'login' => '',
357 'newmember' => '',
358 'newpass' => '',
359 'changepass' => '',
360 'memberinfo' => '',
361 'completion' => '',
362 );
363 }
364 if ( ! isset( $this->options['member_page_data']['footer'] ) ) {
365 $this->options['member_page_data']['footer'] = array(
366 'login' => '',
367 'newmember' => '',
368 'newpass' => '',
369 'changepass' => '',
370 'memberinfo' => '',
371 'completion' => '',
372 );
373 }
374 if ( ! isset( $this->options['member_page_data']['agree_member_exp'] ) ) {
375 $this->options['member_page_data']['agree_member_exp'] = '';
376 }
377 if ( ! isset( $this->options['member_page_data']['agree_member_cont'] ) ) {
378 $this->options['member_page_data']['agree_member_cont'] = '';
379 }
380 if ( ! isset( $this->options['agree_member'] ) ) {
381 $this->options['agree_member'] = '';
382 }
383 if ( ! isset( $this->options['shortest_delivery_time'] ) ) {
384 $this->options['shortest_delivery_time'] = '0';
385 }
386 if ( ! isset( $this->options['delivery_after_days'] ) ) {
387 $this->options['delivery_after_days'] = 15;
388 }
389 if ( ! isset( $this->options['delivery_days'] ) ) {
390 $this->options['delivery_days'] = array();
391 }
392 if ( ! isset( $this->options['delivery_time_limit']['hour'] ) ) {
393 $this->options['delivery_time_limit']['hour'] = '00';
394 }
395 if ( ! isset( $this->options['delivery_time_limit']['min'] ) ) {
396 $this->options['delivery_time_limit']['min'] = '00';
397 }
398
399 if ( ! isset( $this->options['divide_item'] ) ) {
400 $this->options['divide_item'] = 0;
401 }
402 if ( ! isset( $this->options['itemimg_anchor_rel'] ) ) {
403 $this->options['itemimg_anchor_rel'] = '';
404 }
405 if ( ! isset( $this->options['fukugo_category_orderby'] ) ) {
406 $this->options['fukugo_category_orderby'] = 'ID';
407 }
408 if ( ! isset( $this->options['fukugo_category_order'] ) ) {
409 $this->options['fukugo_category_order'] = 'ASC';
410 }
411 if ( ! isset( $this->options['settlement_path'] ) ) {
412 $this->options['settlement_path'] = USCES_PLUGIN_DIR . 'settlement/';
413 }
414 if ( ! isset( $this->options['logs_path'] ) ) {
415 $this->options['logs_path'] = '';
416 }
417 if ( ! isset( $this->options['use_ssl'] ) ) {
418 $this->options['use_ssl'] = 0;
419 }
420 if ( ! isset( $this->options['ssl_url'] ) ) {
421 $this->options['ssl_url'] = '';
422 }
423 if ( ! isset( $this->options['ssl_url_admin'] ) ) {
424 $this->options['ssl_url_admin'] = '';
425 }
426 if ( ! isset( $this->options['inquiry_id'] ) ) {
427 $this->options['inquiry_id'] = '';
428 }
429 if ( ! isset( $this->options['system']['orderby_itemsku'] ) ) {
430 $this->options['system']['orderby_itemsku'] = 0;
431 }
432 if ( ! isset( $this->options['system']['orderby_itemopt'] ) ) {
433 $this->options['system']['orderby_itemopt'] = 0;
434 }
435 if ( ! isset( $this->options['system']['front_lang'] ) ) {
436 $this->options['system']['front_lang'] = usces_get_local_language();
437 }
438 if ( ! isset( $this->options['system']['currency'] ) ) {
439 $this->options['system']['currency'] = usces_get_base_country();
440 }
441 if ( ! isset( $this->options['system']['addressform'] ) ) {
442 $this->options['system']['addressform'] = usces_get_local_addressform();
443 }
444 if ( ! isset( $this->options['system']['target_market'] ) ) {
445 $this->options['system']['target_market'] = usces_get_local_target_market();
446 }
447 if ( ! isset( $this->options['system']['no_cart_css'] ) ) {
448 $this->options['system']['no_cart_css'] = 0;
449 }
450 if ( ! isset( $this->options['system']['dec_orderID_flag'] ) ) {
451 $this->options['system']['dec_orderID_flag'] = 0;
452 }
453 if ( ! isset( $this->options['system']['dec_orderID_prefix'] ) ) {
454 $this->options['system']['dec_orderID_prefix'] = '';
455 }
456 if ( ! isset( $this->options['system']['dec_orderID_digit'] ) ) {
457 $this->options['system']['dec_orderID_digit'] = 8;
458 }
459 if ( ! isset( $this->options['system']['subimage_rule'] ) ) {
460 $this->options['system']['subimage_rule'] = 1;
461 }
462 if ( ! isset( $this->options['system']['pdf_delivery'] ) ) {
463 $this->options['system']['pdf_delivery'] = 0;
464 }
465 if ( ! isset( $this->options['system']['member_pass_rule_min'] ) || empty( $this->options['system']['member_pass_rule_min'] ) ) {
466 $this->options['system']['member_pass_rule_min'] = 6;
467 }
468 if ( ! isset( $this->options['system']['member_pass_rule_max'] ) || empty( $this->options['system']['member_pass_rule_max'] ) ) {
469 $this->options['system']['member_pass_rule_max'] = 30;
470 }
471 if ( ! isset( $this->options['system']['member_pass_rule_upercase'] ) || empty( $this->options['system']['member_pass_rule_upercase'] ) ) {
472 $this->options['system']['member_pass_rule_upercase'] = false;
473 }
474 if ( ! isset( $this->options['system']['csv_encode_type'] ) ) {
475 $this->options['system']['csv_encode_type'] = 0;
476 }
477 if ( ! isset( $this->options['system']['csv_category_format'] ) ) {
478 $this->options['system']['csv_category_format'] = 0;
479 }
480 if ( ! isset( $this->options['system']['settlement_backup'] ) ) {
481 $this->options['system']['settlement_backup'] = 0;
482 }
483 if ( ! isset( $this->options['system']['settlement_notice'] ) ) {
484 $this->options['system']['settlement_notice'] = 0;
485 }
486 if ( ! isset( $this->options['system']['order_list_delete_link'] ) ) {
487 $this->options['system']['order_list_delete_link'] = 0;
488 }
489 if ( ! isset( $this->options['system']['member_list_delete_link'] ) ) {
490 $this->options['system']['member_list_delete_link'] = 0;
491 }
492
493 $this->options['system']['base_country'] = usces_get_base_country();
494 if ( ! isset( $this->options['province'] ) ) {
495 $this->options['province'][ $this->options['system']['base_country'] ] = $usces_states[ $this->options['system']['base_country'] ];
496 }
497 if ( ! isset( $this->options['system']['pointreduction'] ) ) {
498 $this->options['system']['pointreduction'] = usces_get_pointreduction( $this->options['system']['currency'] );
499 }
500 if ( ! isset( $this->options['indi_item_name'] ) ) {
501 $this->options['indi_item_name']['item_name'] = 1;
502 $this->options['indi_item_name']['item_code'] = 1;
503 $this->options['indi_item_name']['sku_name'] = 1;
504 $this->options['indi_item_name']['sku_code'] = 1;
505 $this->options['pos_item_name']['item_name'] = 1;
506 $this->options['pos_item_name']['item_code'] = 2;
507 $this->options['pos_item_name']['sku_name'] = 3;
508 $this->options['pos_item_name']['sku_code'] = 4;
509 }
510 update_option( 'usces', $this->options );
511
512 $this->check_display_mode();
513 $this->error_message = '';
514 $this->login_mail = '';
515 // $this->get_current_member();
516 $this->page = '';
517 $this->payment_results = array();
518 $this->use_js = $this->options['use_javascript'];
519
520 // admin_ssl options.
521 $this->use_ssl = $this->options['use_ssl'];
522
523 define( 'USCES_CART_NUMBER', get_option( 'usces_cart_number' ) );
524 define( 'USCES_MEMBER_NUMBER', get_option( 'usces_member_number' ) );
525
526 if ( $this->use_ssl ) {
527 $ssl_url = $this->options['ssl_url'];
528 $ssl_url_admin = $this->options['ssl_url_admin'];
529 if ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
530 define( 'USCES_FRONT_PLUGIN_URL', $ssl_url_admin . '/wp-content/plugins/' . USCES_PLUGIN_FOLDER );
531 define( 'USCES_COOKIEPATH', preg_replace( '|https?://[^/]+|i', '', $ssl_url . '/' ) );
532 } else {
533 define( 'USCES_FRONT_PLUGIN_URL', USCES_WP_CONTENT_URL . '/plugins/' . USCES_PLUGIN_FOLDER );
534 define( 'USCES_COOKIEPATH', COOKIEPATH );
535 }
536 define( 'USCES_SSL_URL', $ssl_url );
537 define( 'USCES_SSL_URL_ADMIN', $ssl_url_admin );
538 } else {
539 define( 'USCES_FRONT_PLUGIN_URL', USCES_WP_CONTENT_URL . '/plugins/' . USCES_PLUGIN_FOLDER );
540 define( 'USCES_SSL_URL', home_url() );
541 define( 'USCES_SSL_URL_ADMIN', site_url() );
542 define( 'USCES_COOKIEPATH', COOKIEPATH );
543 }
544 define( 'USCES_ITEM_CAT_PARENT_ID', get_option( 'usces_item_cat_parent_id' ) );
545
546 $this->nonacting_settlements = array( 'COD', 'installment', 'transferAdvance', 'transferDeferred' );
547 $this->zaiko_status = get_option( 'usces_zaiko_status' );
548 $this->member_status = get_option( 'usces_customer_status' );
549 $this->payment_structure = get_option( 'usces_payment_structure' );
550 $this->display_mode = get_option( 'usces_display_mode' );
551 define( 'USCES_MYSQL_VERSION', $wpdb->db_version() );
552 define( 'USCES_JP', ( 'ja' === get_locale() ? true : false ) );
553
554 $this->settlement = new usces_settlement();
555
556 $this->settlement_notice = get_option( 'usces_settlement_notice' );
557
558 $this->usces_session_start();
559 }
560
561 /**
562 * Init.
563 */
564 public function init() {
565 global $usces_settings;
566
567 if ( ! isset( $usces_settings['language']['others'] ) ) {
568 $usces_settings['language']['others'] = __( 'Follow config.php', 'usces' );
569 }
570 if ( ! isset( $this->options['order_acceptable_label'] ) ) {
571 $this->options['order_acceptable_label'] = __( 'Order acceptable', 'usces' );
572 update_option( 'usces', $this->options );
573 }
574 $this->get_current_member();
575 }
576
577 public function get_default_post_to_edit30( $post_type = 'post', $create_in_db = false ) {
578 global $wpdb;
579
580 $post_title = '';
581 if ( ! empty( $_REQUEST['post_title'] ) ) {
582 $post_title = esc_html( stripslashes( $_REQUEST['post_title'] ) );
583 }
584 $post_content = '';
585 if ( ! empty( $_REQUEST['content'] ) ) {
586 $post_content = esc_html( stripslashes( $_REQUEST['content'] ) );
587 }
588 $post_excerpt = '';
589 if ( ! empty( $_REQUEST['excerpt'] ) ) {
590 $post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ) );
591 }
592 if ( $create_in_db ) {
593 // Cleanup old auto-drafts more than 7 days old.
594 $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" );
595 foreach ( (array) $old_posts as $delete ) {
596 wp_delete_post( $delete, true ); // Force delete.
597 }
598 $post = get_post(
599 wp_insert_post(
600 array(
601 'post_title' => __( 'Auto Draft' ),
602 'post_type' => $post_type,
603 'post_status' => 'auto-draft',
604 )
605 )
606 );
607 } else {
608 $post->ID = 0;
609 $post->post_author = '';
610 $post->post_date = '';
611 $post->post_date_gmt = '';
612 $post->post_password = '';
613 $post->post_type = $post_type;
614 $post->post_status = 'draft';
615 $post->to_ping = '';
616 $post->pinged = '';
617 $post->comment_status = get_option( 'default_comment_status' );
618 $post->ping_status = get_option( 'default_ping_status' );
619 $post->post_pingback = get_option( 'default_pingback_flag' );
620 $post->post_category = get_option( 'default_category' );
621 $post->page_template = 'default';
622 $post->post_parent = 0;
623 $post->menu_order = 0;
624 }
625
626 $post->post_content = apply_filters( 'default_content', $post_content, $post );
627 $post->post_title = apply_filters( 'default_title', $post_title, $post );
628 $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt, $post );
629 $post->post_name = '';
630
631 return $post;
632 }
633
634 public function get_default_post_to_edit() {
635 global $post;
636
637 $post_title = '';
638 if ( ! empty( $_REQUEST['post_title'] ) ) {
639 $post_title = esc_html( stripslashes( $_REQUEST['post_title'] ) );
640 }
641 $post_content = '';
642 if ( ! empty( $_REQUEST['content'] ) ) {
643 $post_content = esc_html( stripslashes( $_REQUEST['content'] ) );
644 }
645 $post_excerpt = '';
646 if ( ! empty( $_REQUEST['excerpt'] ) ) {
647 $post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ) );
648 }
649 $post->ID = 0;
650 $post->post_name = '';
651 $post->post_author = '';
652 $post->post_date = '';
653 $post->post_date_gmt = '';
654 $post->post_password = '';
655 $post->post_status = 'draft';
656 $post->post_type = 'post';
657 $post->to_ping = '';
658 $post->pinged = '';
659 $post->comment_status = get_option( 'default_comment_status' );
660 $post->ping_status = get_option( 'default_ping_status' );
661 $post->post_pingback = get_option( 'default_pingback_flag' );
662 $post->post_category = get_option( 'default_category' );
663 $post->post_content = apply_filters( 'default_content', $post_content );
664 $post->post_title = apply_filters( 'default_title', $post_title );
665 $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt );
666 $post->page_template = 'default';
667 $post->post_parent = 0;
668 $post->menu_order = 0;
669
670 return $post;
671 }
672
673 public function is_cart_or_member_page( $link ) {
674 $search = array(
675 ( 'page_id=' . USCES_CART_NUMBER ),
676 '/usces-cart',
677 ( 'page_id=' . USCES_MEMBER_NUMBER ),
678 '/usces-member',
679 );
680 $flag = false;
681 foreach ( $search as $value ) {
682 $parts = array();
683 if ( false !== strpos( $link, $value ) ) {
684 if ( $value == ( 'page_id=' . USCES_CART_NUMBER ) || $value == ( 'page_id=' . USCES_MEMBER_NUMBER ) ) {
685 $parts = parse_url( $link );
686 parse_str( $parts['query'], $query );
687 if ( isset( $query['page_id'] ) && ( $query['page_id'] == USCES_CART_NUMBER || $query['page_id'] == USCES_MEMBER_NUMBER ) ) {
688 $flag = true;
689 }
690 } else {
691 $flag = true;
692 }
693 }
694 }
695 return $flag;
696 }
697
698 public function is_cart_page( $link ) {
699 $search = array(
700 ( 'page_id=' . USCES_CART_NUMBER ),
701 '/usces-cart',
702 );
703 $flag = false;
704 foreach ( $search as $value ) {
705 if ( false !== strpos( $link, $value ) ) {
706 if ( $value == ( 'page_id=' . USCES_CART_NUMBER ) ) {
707 $parts = parse_url( $link );
708 parse_str( $parts['query'], $query );
709 if ( isset( $query['page_id'] ) && $query['page_id'] == USCES_CART_NUMBER ) {
710 $flag = true;
711 }
712 } else {
713 $flag = true;
714 }
715 }
716 }
717 return $flag;
718 }
719
720 public function is_member_page( $link ) {
721 $search = array(
722 ( 'page_id=' . USCES_MEMBER_NUMBER ),
723 '/usces-member',
724 );
725 $flag = false;
726 foreach ( $search as $value ) {
727 if ( false !== strpos( $link, $value ) ) {
728 if ( $value == ( 'page_id=' . USCES_MEMBER_NUMBER ) ) {
729 $parts = parse_url( $link );
730 parse_str( $parts['query'], $query );
731 if ( $query['page_id'] == USCES_MEMBER_NUMBER ) {
732 $flag = true;
733 }
734 } else {
735 $flag = true;
736 }
737 }
738 }
739 return $flag;
740 }
741
742 public function is_inquiry_page( $link ) {
743 if ( empty( $this->options['inquiry_id'] ) ) {
744 return false;
745 }
746 $search = array(
747 ( 'page_id=' . $this->options['inquiry_id'] ),
748 '/usces-inquiry',
749 );
750 $flag = false;
751 foreach ( $search as $value ) {
752 if ( false !== strpos( $link, $value ) ) {
753 if ( $value == ( 'page_id=' . $this->options['inquiry_id'] ) ) {
754 $parts = parse_url( $link );
755 parse_str( $parts['query'], $query );
756 if ( $query['page_id'] == $this->options['inquiry_id'] ) {
757 $flag = true;
758 }
759 } else {
760 $flag = true;
761 }
762 }
763 }
764 return $flag;
765 }
766
767 public function usces_ssl_page_link( $link ) {
768 $parts = parse_url( $link );
769
770 if ( isset( $parts['query'] ) ) {
771 parse_str( $parts['query'], $query );
772 }
773
774 if ( false !== strpos( $link, '/usces-cart' ) || ( isset( $query['page_id'] ) && $query['page_id'] == USCES_CART_NUMBER ) ) {
775 $link = USCES_CART_URL;
776
777 } elseif ( false !== strpos( $link, '/usces-member' ) || ( isset( $query['page_id'] ) && $query['page_id'] == USCES_MEMBER_NUMBER ) ) {
778 $link = USCES_MEMBER_URL;
779
780 } elseif ( ! empty( $this->options['inquiry_id'] ) && ( false !== strpos( $link, '/usces-inquiry' ) || ( isset( $query['page_id'] ) && $query['page_id'] == $this->options['inquiry_id'] ) ) ) {
781 $link = USCES_INQUIRY_URL;
782
783 } else {
784 $link = str_replace( 'https://', 'http://', $link );
785 $link = apply_filters( 'usces_ssl_page_link', $link );
786 }
787
788 return $link;
789 }
790
791 public function usces_ssl_contents_link( $link ) {
792 if ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
793 $req = explode( '/wp-content/', $link );
794 $link = USCES_SSL_URL_ADMIN . '/wp-content/' . $req[1];
795 } else {
796 $link = apply_filters( 'usces_ssl_contents_link', $link );
797 }
798 return $link;
799 }
800
801 public function ssl_admin_ajax_url() {
802 $path = '/wp-admin/admin-ajax.php';
803 if ( $this->use_ssl && ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) ) {
804 $link = USCES_SSL_URL_ADMIN . '/wp-admin/admin-ajax.php';
805 } else {
806 $link = site_url( $path );
807 }
808 $link = apply_filters( 'ssl_admin_ajax_url', $link );
809 return $link;
810 }
811
812 public function usces_ssl_attachment_link( $link ) {
813 if ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
814 $link = str_replace( site_url(), USCES_SSL_URL_ADMIN, $link );
815 } else {
816 $link = apply_filters( 'usces_ssl_attachment_link', $link );
817 }
818 return $link;
819 }
820
821 public function usces_ssl_icon_dir_uri( $uri ) {
822 if ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
823 $uri = USCES_SSL_URL_ADMIN . '/' . WPINC . '/images/crystal';
824 } else {
825 $uri = apply_filters( 'usces_ssl_icon_dir_uri', $uri );
826 }
827 return $uri;
828 }
829
830 public function usces_ssl_script_link( $link ) {
831 if ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
832 if ( strpos( $link, '/wp-content/' ) !== false ) {
833 $req = explode( '/wp-content/', $link, 2 );
834 $link = USCES_SSL_URL_ADMIN . '/wp-content/' . $req[1];
835 } elseif ( strpos( $link, '/wp-includes/' ) !== false ) {
836 $req = explode( '/wp-includes/', $link, 2 );
837 $link = USCES_SSL_URL_ADMIN . '/wp-includes/' . $req[1];
838 } elseif ( strpos( $link, '/wp-admin/') !== false ) {
839 $req = explode( '/wp-admin/', $link, 2 );
840 $link = USCES_SSL_URL_ADMIN . '/wp-admin/' . $req[1];
841 }
842 } else {
843 $link = apply_filters( 'usces_ssl_script_link', $link );
844 }
845 return $link;
846 }
847
848 public function set_action_status( $status, $message ) {
849 $this->action_status = $status;
850 $this->action_message = $message;
851 }
852
853 public function add_pages() {
854 add_menu_page( 'Welcart Shop', 'Welcart Shop', 'wel_publish_products', USCES_PLUGIN_BASENAME, array( $this, 'admin_top_page' ), 'dashicons-cart', '3.0011060' );
855 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'Home', 'usces' ), __( 'Home', 'usces' ), 'wel_publish_products', USCES_PLUGIN_BASENAME, array( $this, 'admin_top_page' ) );
856 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'Master Items', 'usces' ), __( 'Master Items', 'usces' ), 'wel_publish_products', 'usces_itemedit', array( $this, 'item_master_page' ) );
857 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'Add New Item', 'usces' ), __( 'Add New Item', 'usces' ), 'wel_publish_products', 'usces_itemnew', array( $this, 'item_master_page' ) );
858 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'General Setting', 'usces' ), __( 'General Setting', 'usces' ), 'wel_manage_setting', 'usces_initial', array( $this, 'admin_setup_page' ) );
859 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'Business Days Setting', 'usces' ), __( 'Business Days Setting', 'usces' ), 'wel_manage_setting', 'usces_schedule', array( $this, 'admin_schedule_page' ) );
860 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'Shipping Setting', 'usces' ), __( 'Shipping Setting', 'usces' ), 'wel_manage_setting', 'usces_delivery', array( $this, 'admin_delivery_page' ) );
861 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'E-mail Setting', 'usces' ), __( 'E-mail Setting', 'usces' ), 'wel_manage_setting', 'usces_mail', array( $this, 'admin_mail_page' ) );
862 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'Cart Page Setting', 'usces' ), __( 'Cart Page Setting', 'usces' ), 'wel_manage_setting', 'usces_cart', array( $this, 'admin_cart_page' ) );
863 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'Member Page Setting', 'usces' ), __( 'Member Page Setting', 'usces' ), 'wel_manage_setting', 'usces_member', array( $this, 'admin_member_page' ) );
864 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'System Setting', 'usces' ), __( 'System Setting', 'usces' ), 'wel_manage_setting', 'usces_system', array( $this, 'admin_system_page' ) );
865 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'Settlement Setting', 'usces' ), __( 'Settlement Setting', 'usces' ), 'wel_manage_setting', 'usces_settlement', array( $this, 'admin_settlement_page' ) );
866 do_action( 'usces_action_shop_admin_menue' );
867
868 add_menu_page( 'Welcart Management', 'Welcart Management', 'wel_manage_order', 'usces_orderlist', array( $this, 'order_list_page' ), 'dashicons-cart', '3.0011070' );
869 add_submenu_page( 'usces_orderlist', __( 'Order List', 'usces' ), __( 'Order List', 'usces' ), 'wel_manage_order', 'usces_orderlist', array( $this, 'order_list_page' ) );
870 add_submenu_page( 'usces_orderlist', __( 'New Order or Estimate', 'usces' ), __( 'New Order or Estimate', 'usces' ), 'wel_manage_order', 'usces_ordernew', array( $this, 'order_list_page' ) );
871 add_submenu_page( 'usces_orderlist', __( 'List of Members', 'usces' ), __( 'List of Members', 'usces' ), 'wel_manage_order', 'usces_memberlist', array( $this, 'member_list_page' ) );
872 add_submenu_page( 'usces_orderlist', __( 'New Membership Registration', 'usces' ), __( 'New Membership Registration', 'usces' ), 'wel_manage_order', 'usces_membernew', array( $this, 'member_list_page' ) );
873 Log_List_Table::add_submenu_page();
874 do_action( 'usces_action_management_admin_menue' );
875 }
876
877 /**
878 * Item Master Page.
879 */
880 public function item_master_page() {
881 global $wpdb, $wp_locale;
882 global $wp_query;
883
884 if ( empty( $this->action_message ) || WCUtils::is_blank( $this->action_message ) ) {
885 $this->action_status = 'none';
886 $this->action_message = '';
887 }
888
889 if ( 'usces_itemnew' == $_REQUEST['page'] ) {
890 $action = 'new';
891 } else {
892 $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
893 }
894 do_action( 'usces_action_item_master_page', $action );
895 switch ( $action ) {
896 case 'dlitemlist':
897 usces_download_item_list();
898 break;
899 case 'upload_register':
900 require_once USCES_PLUGIN_DIR . '/includes/usces_item_master_upload_register.php';
901 break;
902 case 'delete':
903 case 'new':
904 case 'editpost':
905 case 'edit':
906 global $current_user;
907 require_once USCES_PLUGIN_DIR . '/includes/usces_item_master_edit.php';
908 break;
909 default:
910 require_once USCES_PLUGIN_DIR . '/includes/usces_item_master_list.php';
911 break;
912 }
913 }
914
915 /**
916 * Order list page.
917 */
918 public function order_list_page() {
919 $order_edit_form = apply_filters( 'usces_admin_order_edit_form', USCES_PLUGIN_DIR . '/includes/order_edit_form.php' );
920 $order_list = apply_filters( 'usces_admin_order_list', USCES_PLUGIN_DIR . '/includes/order_list.php' );
921
922 if ( empty( $this->action_message ) || WCUtils::is_blank( $this->action_message ) ) {
923 $this->action_status = 'none';
924 $this->action_message = '';
925 }
926 if ( 'usces_ordernew' == $_REQUEST['page'] ) {
927 $order_action = 'new';
928 } else {
929 $order_action = isset( $_REQUEST['order_action'] ) ? $_REQUEST['order_action'] : '';
930 }
931 do_action( 'usces_action_order_list_page', $order_action );
932 Log_List_Table::add_order_meta_box( $order_action );
933 switch ( $order_action ) {
934 case 'dlproductlist':
935 check_admin_referer( 'order_list', 'wc_nonce' );
936 usces_download_product_list();
937 break;
938 case 'dlorderlist':
939 check_admin_referer( 'order_list', 'wc_nonce' );
940 usces_download_order_list();
941 break;
942 case 'dlsettlementerrorlog':
943 check_admin_referer( 'order_list', 'wc_nonce' );
944 usces_download_settlement_error_log();
945 break;
946 case 'editpost':
947 check_admin_referer( 'order_edit', 'wc_nonce' );
948 $logger = Logger::start( $_REQUEST['order_id'], 'orderedit', 'update' );
949 do_action( 'usces_pre_update_orderdata', $_REQUEST['order_id'] );
950 $res = usces_update_orderdata();
951 if ( 1 === $res ) {
952 $backtolist = ( empty( $_POST['usces_referer'] ) || false !== strpos( $_POST['usces_referer'], 'order_action=editpost' ) ) ? admin_url( 'admin.php?page=usces_orderlist&returnList=1&wc_nonce=' . wp_create_nonce( 'order_list' ) ) : esc_url( stripslashes( $_POST['usces_referer'] ) );
953 $this->set_action_status( 'success', __( 'order date is updated', 'usces' ) . ' <a href="' . $backtolist . '">' . __( 'back to the summary', 'usces' ) . '</a>' );
954 } elseif ( 0 === $res ) {
955 $this->set_action_status( 'none', '' );
956 } else {
957 $this->set_action_status( 'error', 'ERROR : ' . __( 'failure in update', 'usces' ) );
958 }
959 $logger->flush();
960 do_action( 'usces_after_update_orderdata', $_REQUEST['order_id'], $res );
961 require_once $order_edit_form;
962 break;
963 case 'newpost':
964 check_admin_referer( 'order_edit', 'wc_nonce' );
965 do_action( 'usces_pre_new_orderdata' );
966 $res = usces_new_orderdata();
967 if ( 1 === $res ) {
968 $this->set_action_status( 'success', __( 'New date is add', 'usces' ) );
969 Logger::start( $_REQUEST['order_id'], 'ordernew', 'create' )->flush();
970 } elseif ( 0 === $res ) {
971 $this->set_action_status( 'none', '' );
972 } else {
973 $this->set_action_status( 'error', 'ERROR : ' . __( 'failure in addition', 'usces' ) );
974 }
975 do_action( 'usces_after_new_orderdata', $res );
976 $_REQUEST['order_action'] = 'edit';
977 $order_action = $_REQUEST['order_action'];
978 require_once $order_edit_form;
979 break;
980 case 'new':
981 case 'edit':
982 require_once $order_edit_form;
983 break;
984 case 'load_rich_editor':
985 wp_enqueue_style( 'colors' );
986 require_once USCES_PLUGIN_DIR . '/includes/order_detail_rich_editor.php';
987 break;
988 case 'delete':
989 check_admin_referer( 'order_list', 'wc_nonce' );
990 do_action( 'usces_pre_delete_orderdata', $_REQUEST['order_id'] );
991 $logger = Logger::start( $_REQUEST['order_id'], 'orderlist', 'delete' );
992 $res = usces_delete_orderdata();
993 if ( 1 === $res ) {
994 $this->set_action_status( 'success', __( 'the order date is deleted', 'usces' ) );
995 $logger->flush();
996 } elseif ( 0 === $res ) {
997 $this->set_action_status( 'none', '' );
998 } else {
999 $this->set_action_status( 'error', 'ERROR : ' . __( 'failure in delete', 'usces' ) );
1000 }
1001 do_action( 'usces_after_delete_orderdata', $_REQUEST['order_id'], $res );
1002 default:
1003 require_once $order_list;
1004 }
1005 }
1006
1007 /**
1008 * Member list page.
1009 */
1010 public function member_list_page() {
1011 $member_edit_form = apply_filters( 'usces_admin_member_edit_form', USCES_PLUGIN_DIR . '/includes/member_edit_form.php' );
1012 $member_list = apply_filters( 'usces_admin_member_list', USCES_PLUGIN_DIR . '/includes/member_list.php' );
1013 if ( empty( $this->action_message ) || WCUtils::is_blank( $this->action_message ) ) {
1014 $this->action_status = 'none';
1015 $this->action_message = '';
1016 }
1017 if ( 'usces_membernew' == $_REQUEST['page'] ) {
1018 $member_action = isset( $_REQUEST['member_action'] ) ? $_REQUEST['member_action'] : 'new';
1019 } else {
1020 $member_action = isset( $_REQUEST['member_action'] ) ? $_REQUEST['member_action'] : '';
1021 }
1022 do_action( 'usces_action_member_list_page', $member_action );
1023 Log_List_Table::add_member_meta_box( $member_action );
1024 switch ( $member_action ) {
1025 case 'dlmemberlist':
1026 check_admin_referer( 'post_member', 'wc_nonce' );
1027 usces_download_member_list();
1028 break;
1029 case 'editpost':
1030 check_admin_referer( 'post_member', 'wc_nonce' );
1031 $logger = Logger::start( $_REQUEST['member_id'], 'memberedit', 'update' );
1032 $this->error_message = $this->admin_member_check();
1033 if ( WCUtils::is_blank( $this->error_message ) ) {
1034 $res = usces_update_memberdata();
1035 if ( 1 === $res ) {
1036 $this->set_action_status( 'success', __( 'Membership information is updated', 'usces' ) );
1037 $logger->flush();
1038 } elseif ( 0 === $res ) {
1039 $this->set_action_status( 'none', '' );
1040 } else {
1041 $this->set_action_status( 'error', 'ERROR : ' . __( 'failure in update', 'usces' ) );
1042 }
1043 } else {
1044 $this->set_action_status( 'error', 'ERROR : ' . $this->error_message );
1045 }
1046 require_once $member_edit_form;
1047 break;
1048 case 'newpost':
1049 check_admin_referer( 'post_member', 'wc_nonce' );
1050 $this->error_message = $this->admin_new_member_check();
1051 if ( WCUtils::is_blank( $this->error_message ) ) {
1052 $res = usces_new_memberdata();
1053 if ( 1 === $res ) {
1054 $this->set_action_status( 'success', __( 'New member registration is complete.', 'usces' ) );
1055 $_REQUEST['member_action'] = 'edit';
1056 $member_action = $_REQUEST['member_action'];
1057 Logger::start( $_REQUEST['member_id'], 'membernew', 'create' )->flush();
1058 } elseif ( 0 === $res ) {
1059 $this->set_action_status( 'none', '' );
1060 } else {
1061 $this->set_action_status( 'error', 'ERROR : ' . __( 'Failed to new member registration.', 'usces' ) );
1062 }
1063 } else {
1064 $this->set_action_status( 'error', $this->error_message );
1065 $member_action = 'new';
1066 }
1067 require_once $member_edit_form;
1068 break;
1069 case 'new':
1070 require_once $member_edit_form;
1071 break;
1072 case 'edit':
1073 check_admin_referer( 'member_list', 'wc_nonce' );
1074 require_once $member_edit_form;
1075 break;
1076 case 'delete':
1077 check_admin_referer( 'delete_member', 'wc_nonce' );
1078 if ( ! isset( $_REQUEST['member_id'] ) || WCUtils::is_blank( $_REQUEST['member_id'] ) ) {
1079 $this->set_action_status( 'error', 'ERROR : ' . __( 'failure in delete', 'usces' ) );
1080 } else {
1081 $logger = Logger::start( $_REQUEST['member_id'], 'memberlist', 'delete' );
1082 $member_id = $_REQUEST['member_id'];
1083 $del = usces_delete_member_check( $member_id );
1084 if ( $del ) {
1085 $res = usces_delete_memberdata( $member_id );
1086 if ( 1 === $res ) {
1087 $this->set_action_status( 'success', __( 'The member data is deleted', 'usces' ) );
1088 } elseif ( 0 === $res ) {
1089 $this->set_action_status( 'none', '' );
1090 } else {
1091 $this->set_action_status( 'error', 'ERROR : ' . __( 'failure in delete', 'usces' ) );
1092 }
1093 $logger->flush();
1094 } else {
1095 $this->set_action_status( 'error', 'ERROR : ' . __( 'failure in delete', 'usces' ) );
1096 }
1097 }
1098 default:
1099 require_once $member_list;
1100 }
1101 }
1102
1103 /**
1104 * Shop Top Page.
1105 */
1106 public function admin_top_page() {
1107 $action = filter_input( INPUT_GET, 'wel_action', FILTER_DEFAULT, FILTER_REQUIRE_SCALAR );
1108 if ( ! wel_need_to_update_db() ) {
1109 $action = '';
1110 }
1111 switch ( $action ) {
1112 case 'update_db':
1113 if ( ! current_user_can( 'wel_manage_setting' ) ) {
1114 wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
1115 }
1116 check_admin_referer( 'wel_update_database', '_welnonce' );
1117 require_once USCES_PLUGIN_DIR . '/includes/database/db-progress-screen.php';
1118 break;
1119 default:
1120 $path = apply_filters( 'usces_filter_admin_top_page', USCES_PLUGIN_DIR . '/includes/admin_top.php' );
1121 require_once $path;
1122 }
1123 }
1124
1125 /**
1126 * Shop Setup Page.
1127 */
1128 public function admin_setup_page() {
1129 $this->options = get_option( 'usces' );
1130 if ( isset( $_POST['usces_option_update'] ) ) {
1131
1132 check_admin_referer( 'admin_setup', 'wc_nonce' );
1133
1134 $_POST = $this->stripslashes_deep_post( $_POST );
1135
1136 $order_mail = '';
1137 if ( isset( $_POST['order_mail'] ) ) {
1138 $order_mails = array_map( 'trim', explode( ',', $_POST['order_mail'] ) );
1139 $valid_mails = array();
1140 foreach ( $order_mails as $mail ) {
1141 if ( is_email( $mail ) ) {
1142 $valid_mails[] = $mail;
1143 }
1144 }
1145 $order_mail = implode( ',', $valid_mails );
1146 } else {
1147 $order_mail = '';
1148 }
1149
1150 $this->options['display_mode'] = isset( $_POST['display_mode'] ) ? trim( $_POST['display_mode'] ) : '';
1151 $this->options['campaign_category'] = empty( $_POST['cat'] ) ? USCES_ITEM_CAT_PARENT_ID : $_POST['cat'];
1152 $this->options['campaign_privilege'] = isset( $_POST['cat_privilege'] ) ? trim( $_POST['cat_privilege'] ) : '';
1153 $this->options['privilege_point'] = isset( $_POST['point_num'] ) ? (int) $_POST['point_num'] : '';
1154 $this->options['privilege_discount'] = isset( $_POST['discount_num'] ) ? (int) $_POST['discount_num'] : '';
1155 $this->options['company_name'] = isset( $_POST['company_name'] ) ? trim( $_POST['company_name'] ) : '';
1156 $this->options['zip_code'] = isset( $_POST['zip_code'] ) ? trim( $_POST['zip_code'] ) : '';
1157 $this->options['address1'] = isset( $_POST['address1'] ) ? trim( $_POST['address1'] ) : '';
1158 $this->options['address2'] = isset( $_POST['address2'] ) ? trim( $_POST['address2'] ) : '';
1159 $this->options['tel_number'] = isset( $_POST['tel_number'] ) ? trim( $_POST['tel_number'] ) : '';
1160 $this->options['fax_number'] = isset( $_POST['fax_number'] ) ? trim( $_POST['fax_number'] ) : '';
1161 $this->options['order_mail'] = $order_mail;
1162 $this->options['inquiry_mail'] = isset( $_POST['inquiry_mail'] ) && is_email( trim( $_POST['inquiry_mail'] ) ) ? trim( $_POST['inquiry_mail'] ) : '';
1163 $this->options['sender_mail'] = isset( $_POST['sender_mail'] ) && is_email( trim( $_POST['sender_mail'] ) ) ? trim( $_POST['sender_mail'] ) : '';
1164 $this->options['error_mail'] = isset( $_POST['error_mail'] ) && is_email( trim( $_POST['error_mail'] ) ) ? trim( $_POST['error_mail'] ) : '';
1165 $this->options['postage_privilege'] = isset( $_POST['postage_privilege'] ) ? trim( $_POST['postage_privilege'] ) : '';
1166 $this->options['purchase_limit'] = isset( $_POST['purchase_limit'] ) ? trim( $_POST['purchase_limit'] ) : '';
1167 $this->options['point_rate'] = isset( $_POST['point_rate'] ) ? (int) $_POST['point_rate'] : 1;
1168 $this->options['start_point'] = isset( $_POST['start_point'] ) ? (int) $_POST['start_point'] : '';
1169 $this->options['shipping_rule'] = isset( $_POST['shipping_rule'] ) ? trim( $_POST['shipping_rule'] ) : '';
1170 $this->options['tax_display'] = isset( $_POST['tax_display'] ) ? trim( $_POST['tax_display'] ) : 'activate';
1171 $this->options['tax_mode'] = isset( $_POST['tax_mode'] ) ? trim( $_POST['tax_mode'] ) : 'include';
1172 $this->options['tax_target'] = isset( $_POST['tax_target'] ) ? trim( $_POST['tax_target'] ) : 'products';
1173 $this->options['tax_rate'] = isset( $_POST['tax_rate'] ) ? (int) $_POST['tax_rate'] : '';
1174 $this->options['tax_method'] = isset( $_POST['tax_method'] ) ? trim( $_POST['tax_method'] ) : '';
1175 $this->options['applicable_taxrate'] = ( isset( $_POST['applicable_taxrate'] ) ) ? $_POST['applicable_taxrate'] : 'standard';
1176 $this->options['tax_rate_reduced'] = ( isset( $_POST['tax_rate_reduced'] ) ) ? (int) $_POST['tax_rate_reduced'] : '';
1177 $this->options['cod_type'] = isset( $this->options['cod_type'] ) ? $this->options['cod_type'] : 'fix';
1178 $this->options['fee_subject'] = ( isset( $_POST['fee_subject'] ) ) ? trim( $_POST['fee_subject'] ) : 'all';
1179 $this->options['transferee'] = isset( $_POST['transferee'] ) ? trim( $_POST['transferee'] ) : '';
1180 $this->options['tatransfer_limit'] = isset( $_POST['tatransfer_limit'] ) ? trim( $_POST['tatransfer_limit'] ) : '';
1181 $this->options['copyright'] = isset( $_POST['copyright'] ) ? trim( $_POST['copyright'] ) : '';
1182 $this->options['business_registration_number'] = ( isset( $_POST['business_registration_number'] ) ) ? trim( $_POST['business_registration_number'] ) : '';
1183 $this->options['membersystem_state'] = isset( $_POST['membersystem_state'] ) ? trim( $_POST['membersystem_state'] ) : '';
1184 $this->options['membersystem_point'] = isset( $_POST['membersystem_point'] ) ? trim( $_POST['membersystem_point'] ) : '';
1185 $this->options['point_coverage'] = isset( $_POST['point_coverage'] ) ? (int) $_POST['point_coverage'] : 0;
1186 $this->options['point_assign'] = isset( $_POST['point_assign'] ) ? (int) $_POST['point_assign'] : 1;
1187 $this->options['address_search'] = isset( $_POST['address_search'] ) ? trim( $_POST['address_search'] ) : 'deactivate';
1188 $this->options['stock_status_label'] = ( isset( $_POST['stock_status_label'] ) ) ? $_POST['stock_status_label'] : array();
1189 $this->options['order_acceptable_label'] = ( isset( $_POST['order_acceptable_label'] ) ) ? trim( $_POST['order_acceptable_label'] ) : '';
1190
1191 $this->options = apply_filters( 'usces_filter_admin_setup_options', $this->options );
1192
1193 update_option( 'usces', $this->options );
1194
1195 $this->action_status = 'success';
1196 $this->action_message = __( 'options are updated', 'usces' );
1197
1198 } else {
1199 $this->action_status = 'none';
1200 $this->action_message = '';
1201 }
1202
1203 require_once USCES_PLUGIN_DIR . '/includes/admin_setup.php';
1204 }
1205
1206 /**
1207 * Shop Schedule Page
1208 */
1209 public function admin_schedule_page() {
1210 $this->options = get_option( 'usces' );
1211
1212 if ( isset( $_POST['usces_option_update'] ) ) {
1213
1214 check_admin_referer( 'admin_schedule', 'wc_nonce' );
1215
1216 $_POST = $this->stripslashes_deep_post( $_POST );
1217
1218 $this->options['campaign_schedule'] = isset( $_POST['campaign_schedule'] ) ? $_POST['campaign_schedule'] : '0';
1219 if ( isset( $_POST['business_days'] ) ) {
1220 $this->options['business_days'] = $_POST['business_days'];
1221 }
1222 update_option( 'usces', $this->options );
1223
1224 do_action( 'usces_action_admin_schedule_update' );
1225
1226 $this->action_status = 'success';
1227 $this->action_message = __( 'options are updated', 'usces' );
1228 } else {
1229 $this->action_status = 'none';
1230 $this->action_message = '';
1231 }
1232
1233 require_once USCES_PLUGIN_DIR . '/includes/admin_schedule.php';
1234 }
1235
1236 /**
1237 * Shop Delivery Page.
1238 */
1239 public function admin_delivery_page() {
1240 $this->options = get_option( 'usces' );
1241
1242 if ( isset( $_POST['usces_option_update'] ) ) {
1243
1244 check_admin_referer( 'admin_delivery', 'wc_nonce' );
1245
1246 $_POST = $this->stripslashes_deep_post( $_POST );
1247
1248 if ( isset( $_POST['delivery_time_limit'] ) ) {
1249 $this->options['delivery_time_limit'] = $_POST['delivery_time_limit'];
1250 }
1251 if ( isset( $_POST['shortest_delivery_time'] ) ) {
1252 $this->options['shortest_delivery_time'] = $_POST['shortest_delivery_time'];
1253 }
1254 if ( isset( $_POST['delivery_after_days'] ) ) {
1255 $this->options['delivery_after_days'] = $_POST['delivery_after_days'];
1256 }
1257 $this->options = apply_filters( 'usces_filter_admin_delivery_options', $this->options );
1258
1259 update_option( 'usces', $this->options );
1260
1261 $this->action_status = 'success';
1262 $this->action_message = __( 'options are updated', 'usces' );
1263 } else {
1264 $this->action_status = 'none';
1265 $this->action_message = '';
1266 }
1267
1268 require_once USCES_PLUGIN_DIR . '/includes/admin_delivery.php';
1269 }
1270
1271 /**
1272 * Shop Mail Page.
1273 */
1274 public function admin_mail_page() {
1275 global $allowedposttags;
1276
1277 if ( isset( $_POST['usces_option_update'] ) ) {
1278 check_admin_referer( 'admin_mail', 'wc_nonce' );
1279 $_POST = $this->stripslashes_deep_post( $_POST );
1280
1281 $mail_othermail = get_option( 'usces_mail_othermail', array() );
1282 foreach ( $_POST['title'] as $key => $value ) {
1283 $value = wel_esc_script( $value );
1284 if ( 'othermail' == $key ) {
1285 if ( WCUtils::is_blank( $value ) ) {
1286 if ( empty( $mail_othermail['title'] ) && isset( $this->options['mail_default']['title'][ $key ] ) ) {
1287 $mail_othermail['title'] = $this->options['mail_default']['title'][ $key ];
1288 $this->options['mail_data']['title'][ $key ] = $mail_othermail['title'];
1289 }
1290 } else {
1291 $mail_othermail['title'] = trim( $value );
1292 $this->options['mail_data']['title'][ $key ] = $mail_othermail['title'];
1293 }
1294 } else {
1295 if ( WCUtils::is_blank( $value ) ) {
1296 $this->options['mail_data']['title'][ $key ] = isset( $this->options['mail_default']['title'][ $key ] ) ? $this->options['mail_default']['title'][ $key ] : '';
1297 } else {
1298 $this->options['mail_data']['title'][ $key ] = trim( $value );
1299 }
1300 }
1301 }
1302 foreach ( $_POST['header'] as $key => $value ) {
1303 $value = wel_esc_script( $value );
1304 if ( 'othermail' == $key ) {
1305 if ( WCUtils::is_blank( $value ) ) {
1306 if ( empty( $mail_othermail['header'] ) && isset( $this->options['mail_default']['header'][ $key ] ) ) {
1307 $mail_othermail['header'] = $this->options['mail_default']['header'][ $key ];
1308 $this->options['mail_data']['header'][ $key ] = $mail_othermail['header'];
1309 }
1310 } else {
1311 $mail_othermail['header'] = $value;
1312 $this->options['mail_data']['header'][ $key ] = $mail_othermail['header'];
1313 }
1314 } else {
1315 if ( WCUtils::is_blank( $value ) ) {
1316 $this->options['mail_data']['header'][ $key ] = isset( $this->options['mail_default']['header'][ $key ] ) ? $this->options['mail_default']['header'][ $key ] : '';
1317 } else {
1318 $this->options['mail_data']['header'][ $key ] = $value;
1319 }
1320 }
1321 }
1322 foreach ( $_POST['footer'] as $key => $value ) {
1323 $value = wel_esc_script( $value );
1324 if ( 'othermail' == $key ) {
1325 if ( WCUtils::is_blank( $value ) ) {
1326 if ( empty( $mail_othermail['footer'] ) && isset( $this->options['mail_default']['footer'][ $key ] ) ) {
1327 $mail_othermail['footer'] = $this->options['mail_default']['footer'][ $key ];
1328 $this->options['mail_data']['footer'][ $key ] = $mail_othermail['footer'];
1329 }
1330 } else {
1331 $mail_othermail['footer'] = $value;
1332 $this->options['mail_data']['footer'][ $key ] = $mail_othermail['footer'];
1333 }
1334 } else {
1335 if ( WCUtils::is_blank( $value ) ) {
1336 $this->options['mail_data']['footer'][ $key ] = isset( $this->options['mail_default']['footer'][ $key ] ) ? $this->options['mail_default']['footer'][ $key ] : '';
1337 } else {
1338 $this->options['mail_data']['footer'][ $key ] = $value;
1339 }
1340 }
1341 }
1342 update_option( 'usces', $this->options );
1343 update_option( 'usces_mail_othermail', $mail_othermail );
1344
1345 $this->action_status = 'success';
1346 $this->action_message = __( 'options are updated', 'usces' );
1347
1348 } elseif ( isset( $_POST['usces_option_update_top'] ) ) {
1349 check_admin_referer( 'admin_mail', 'wc_nonce' );
1350 $_POST = $this->stripslashes_deep_post( $_POST );
1351
1352 $email_attach_file_extension = wel_email_attach_file_extension( explode( ',', trim( wel_esc_script( $_POST['email_attach_file_extension'] ) ) ) );
1353
1354 $this->options['smtp_hostname'] = esc_html( trim( $_POST['smtp_hostname'] ) );
1355 $this->options['newmem_admin_mail'] = (int) $_POST['newmem_admin_mail'];
1356 $this->options['updmem_admin_mail'] = (int) $_POST['updmem_admin_mail'];
1357 $this->options['updmem_customer_mail'] = (int) $_POST['updmem_customer_mail'];
1358 $this->options['delmem_admin_mail'] = (int) $_POST['delmem_admin_mail'];
1359 $this->options['delmem_customer_mail'] = (int) $_POST['delmem_customer_mail'];
1360 $this->options['put_customer_name'] = (int) $_POST['put_customer_name'];
1361 $this->options['email_attach_feature'] = (int) $_POST['email_attach_feature'];
1362 $this->options['email_attach_file_extension'] = implode( ',', $email_attach_file_extension );
1363 $this->options['email_attach_file_size'] = (int) $_POST['email_attach_file_size'];
1364 $this->options['add_html_email_option'] = (int) $_POST['add_html_email_option'];
1365 update_option( 'usces', $this->options );
1366
1367 $this->action_status = 'success';
1368 $this->action_message = __( 'options are updated', 'usces' );
1369
1370 } elseif ( isset( $_POST['usces_option_update_auto'] ) ) {
1371 check_admin_referer( 'admin_mail', 'wc_nonce' );
1372 $_POST = $this->stripslashes_deep_post( $_POST );
1373
1374 $mail_thankyou = get_option( 'usces_mail_thankyou', array() );
1375 if ( WCUtils::is_blank( $_POST['title']['thankyou'] ) ) {
1376 if ( empty( $mail_thankyou['title'] ) && isset( $this->options['mail_default']['title']['thankyou'] ) ) {
1377 $mail_thankyou['title'] = $this->options['mail_default']['title']['thankyou'];
1378 $this->options['mail_data']['title']['thankyou'] = $mail_thankyou['title'];
1379 }
1380 } else {
1381 $mail_thankyou['title'] = trim( wel_esc_script( $_POST['title']['thankyou'] ) );
1382 $this->options['mail_data']['title']['thankyou'] = $mail_thankyou['title'];
1383 }
1384 if ( WCUtils::is_blank( $_POST['header']['thankyou'] ) ) {
1385 if ( empty( $mail_thankyou['header'] ) && isset( $this->options['mail_default']['header']['thankyou'] ) ) {
1386 $mail_thankyou['header'] = $this->options['mail_default']['header']['thankyou'];
1387 $this->options['mail_data']['header']['thankyou'] = $mail_thankyou['header'];
1388 }
1389 } else {
1390 $mail_thankyou['header'] = trim( wel_esc_script( $_POST['header']['thankyou'] ) );
1391 $this->options['mail_data']['header']['thankyou'] = $mail_thankyou['header'];
1392 }
1393 if ( WCUtils::is_blank( $_POST['footer']['thankyou'] ) ) {
1394 if ( empty( $mail_thankyou['footer'] ) && isset( $this->options['mail_default']['footer']['thankyou'] ) ) {
1395 $mail_thankyou['footer'] = $this->options['mail_default']['footer']['thankyou'];
1396 $this->options['mail_data']['footer']['thankyou'] = $mail_thankyou['footer'];
1397 }
1398 } else {
1399 $mail_thankyou['footer'] = trim( wel_esc_script( $_POST['footer']['thankyou'] ) );
1400 $this->options['mail_data']['footer']['thankyou'] = $mail_thankyou['footer'];
1401 }
1402 update_option( 'usces_mail_thankyou', $mail_thankyou );
1403
1404 $mail_order = get_option( 'usces_mail_order', array() );
1405 if ( WCUtils::is_blank( $_POST['title']['order'] ) ) {
1406 if ( empty( $mail_order['title'] ) && isset( $this->options['mail_default']['title']['order'] ) ) {
1407 $mail_order['title'] = $this->options['mail_default']['title']['order'];
1408 $this->options['mail_data']['title']['order'] = $mail_order['title'];
1409 }
1410 } else {
1411 $mail_order['title'] = trim( wel_esc_script( $_POST['title']['order'] ) );
1412 $this->options['mail_data']['title']['order'] = $mail_order['title'];
1413 }
1414 if ( WCUtils::is_blank( $_POST['header']['order'] ) ) {
1415 if ( empty( $mail_order['header'] ) && isset( $this->options['mail_default']['header']['order'] ) ) {
1416 $mail_order['header'] = $this->options['mail_default']['header']['order'];
1417 $this->options['mail_data']['header']['order'] = $mail_order['header'];
1418 }
1419 } else {
1420 $mail_order['header'] = trim( wel_esc_script( $_POST['header']['order'] ) );
1421 $this->options['mail_data']['header']['order'] = $mail_order['header'];
1422 }
1423 if ( WCUtils::is_blank( $_POST['footer']['order'] ) ) {
1424 if ( empty( $mail_order['footer'] ) && isset( $this->options['mail_default']['footer']['order'] ) ) {
1425 $mail_order['footer'] = $this->options['mail_default']['footer']['order'];
1426 $this->options['mail_data']['footer']['order'] = $mail_order['footer'];
1427 }
1428 } else {
1429 $mail_order['footer'] = trim( wel_esc_script( $_POST['footer']['order'] ) );
1430 $this->options['mail_data']['footer']['order'] = $mail_order['footer'];
1431 }
1432 update_option( 'usces_mail_order', $mail_order );
1433
1434 $mail_inquiry = get_option( 'usces_mail_inquiry', array() );
1435 if ( WCUtils::is_blank( $_POST['title']['inquiry'] ) ) {
1436 if ( empty( $mail_inquiry['title'] ) && isset( $this->options['mail_default']['title']['inquiry'] ) ) {
1437 $mail_inquiry['title'] = $this->options['mail_default']['title']['inquiry'];
1438 $this->options['mail_data']['title']['inquiry'] = $mail_inquiry['title'];
1439 }
1440 } else {
1441 $mail_inquiry['title'] = trim( wel_esc_script( $_POST['title']['inquiry'] ) );
1442 $this->options['mail_data']['title']['inquiry'] = $mail_inquiry['title'];
1443 }
1444 if ( WCUtils::is_blank( $_POST['header']['inquiry'] ) ) {
1445 if ( empty( $mail_inquiry['header'] ) && isset( $this->options['mail_default']['header']['inquiry'] ) ) {
1446 $mail_inquiry['header'] = $this->options['mail_default']['header']['inquiry'];
1447 $this->options['mail_data']['header']['inquiry'] = $mail_inquiry['header'];
1448 }
1449 } else {
1450 $mail_inquiry['header'] = trim( wel_esc_script( $_POST['header']['inquiry'] ) );
1451 $this->options['mail_data']['header']['inquiry'] = $mail_inquiry['header'];
1452 }
1453 if ( WCUtils::is_blank( $_POST['footer']['inquiry'] ) ) {
1454 if ( empty( $mail_inquiry['footer'] ) && isset( $this->options['mail_default']['footer']['inquiry'] ) ) {
1455 $mail_inquiry['footer'] = $this->options['mail_default']['footer']['inquiry'];
1456 $this->options['mail_data']['footer']['inquiry'] = $mail_inquiry['footer'];
1457 }
1458 } else {
1459 $mail_inquiry['footer'] = trim( wel_esc_script( $_POST['footer']['inquiry'] ) );
1460 $this->options['mail_data']['footer']['inquiry'] = $mail_inquiry['footer'];
1461 }
1462 update_option( 'usces_mail_inquiry', $mail_inquiry );
1463
1464 $mail_membercomp = get_option( 'usces_mail_membercomp', array() );
1465 if ( WCUtils::is_blank( $_POST['title']['membercomp'] ) ) {
1466 if ( empty( $mail_membercomp['title'] ) && isset( $this->options['mail_default']['title']['membercomp'] ) ) {
1467 $mail_membercomp['title'] = $this->options['mail_default']['title']['membercomp'];
1468 $this->options['mail_data']['title']['membercomp'] = $mail_membercomp['title'];
1469 }
1470 } else {
1471 $mail_membercomp['title'] = trim( wel_esc_script( $_POST['title']['membercomp'] ) );
1472 $this->options['mail_data']['title']['membercomp'] = $mail_membercomp['title'];
1473 }
1474 if ( WCUtils::is_blank( wel_esc_script( $_POST['header']['membercomp'] ) ) ) {
1475 if ( empty( $mail_membercomp['header'] ) && isset( $this->options['mail_default']['header']['membercomp'] ) ) {
1476 $mail_membercomp['header'] = $this->options['mail_default']['header']['membercomp'];
1477 $this->options['mail_data']['header']['membercomp'] = $mail_membercomp['header'];
1478 }
1479 } else {
1480 $mail_membercomp['header'] = trim( wel_esc_script( $_POST['header']['membercomp'] ) );
1481 $this->options['mail_data']['header']['membercomp'] = $mail_membercomp['header'];
1482 }
1483 if ( WCUtils::is_blank( $_POST['footer']['membercomp'] ) ) {
1484 if ( empty( $mail_membercomp['footer'] ) && isset( $this->options['mail_default']['footer']['membercomp'] ) ) {
1485 $mail_membercomp['footer'] = $this->options['mail_default']['footer']['membercomp'];
1486 $this->options['mail_data']['footer']['membercomp'] = $mail_membercomp['footer'];
1487 }
1488 } else {
1489 $mail_membercomp['footer'] = trim( wel_esc_script( $_POST['footer']['membercomp'] ) );
1490 $this->options['mail_data']['footer']['membercomp'] = $mail_membercomp['footer'];
1491 }
1492 update_option( 'usces_mail_membercomp', $mail_membercomp );
1493
1494 $this->action_status = 'success';
1495 $this->action_message = __( 'options are updated', 'usces' );
1496
1497 } elseif ( isset( $_POST['usces_option_update_manual'] ) ) {
1498 check_admin_referer( 'admin_mail', 'wc_nonce' );
1499 $_POST = $this->stripslashes_deep_post( $_POST );
1500
1501 $mail_completionmail = get_option( 'usces_mail_completionmail', array() );
1502 if ( WCUtils::is_blank( $_POST['title']['completionmail'] ) ) {
1503 if ( empty( $mail_completionmail['title'] ) && isset( $this->options['mail_default']['title']['completionmail'] ) ) {
1504 $mail_completionmail['title'] = $this->options['mail_default']['title']['completionmail'];
1505 $this->options['mail_data']['title']['completionmail'] = $mail_completionmail['title'];
1506 }
1507 } else {
1508 $mail_completionmail['title'] = trim( wel_esc_script( $_POST['title']['completionmail'] ) );
1509 $this->options['mail_data']['title']['completionmail'] = $mail_completionmail['title'];
1510 }
1511 if ( WCUtils::is_blank( $_POST['header']['completionmail'] ) ) {
1512 if ( empty( $mail_completionmail['header'] ) && isset( $this->options['mail_default']['header']['completionmail'] ) ) {
1513 $mail_completionmail['header'] = $this->options['mail_default']['header']['completionmail'];
1514 $this->options['mail_data']['header']['completionmail'] = $mail_completionmail['header'];
1515 }
1516 } else {
1517 $mail_completionmail['header'] = trim( wel_esc_script( $_POST['header']['completionmail'] ) );
1518 $this->options['mail_data']['header']['completionmail'] = $mail_completionmail['header'];
1519 }
1520 if ( WCUtils::is_blank( $_POST['footer']['completionmail'] ) ) {
1521 if ( empty( $mail_completionmail['footer'] ) && isset( $this->options['mail_default']['footer']['completionmail'] ) ) {
1522 $mail_completionmail['footer'] = $this->options['mail_default']['footer']['completionmail'];
1523 $this->options['mail_data']['footer']['completionmail'] = $mail_completionmail['footer'];
1524 }
1525 } else {
1526 $mail_completionmail['footer'] = trim( wel_esc_script( $_POST['footer']['completionmail'] ) );
1527 $this->options['mail_data']['footer']['completionmail'] = $mail_completionmail['footer'];
1528 }
1529 update_option( 'usces_mail_completionmail', $mail_completionmail );
1530
1531 $mail_ordermail = get_option( 'usces_mail_ordermail', array() );
1532 if ( WCUtils::is_blank( $_POST['title']['ordermail'] ) ) {
1533 if ( empty( $mail_ordermail['title'] ) && isset( $this->options['mail_default']['title']['ordermail'] ) ) {
1534 $mail_ordermail['title'] = $this->options['mail_default']['title']['ordermail'];
1535 $this->options['mail_data']['title']['ordermail'] = $mail_ordermail['title'];
1536 }
1537 } else {
1538 $mail_ordermail['title'] = trim( wel_esc_script( $_POST['title']['ordermail'] ) );
1539 $this->options['mail_data']['title']['ordermail'] = $mail_ordermail['title'];
1540 }
1541 if ( WCUtils::is_blank( $_POST['header']['ordermail'] ) ) {
1542 if ( empty( $mail_ordermail['header'] ) && isset( $this->options['mail_default']['header']['ordermail'] ) ) {
1543 $mail_ordermail['header'] = $this->options['mail_default']['header']['ordermail'];
1544 $this->options['mail_data']['header']['ordermail'] = $mail_ordermail['header'];
1545 }
1546 } else {
1547 $mail_ordermail['header'] = trim( wel_esc_script( $_POST['header']['ordermail'] ) );
1548 $this->options['mail_data']['header']['ordermail'] = $mail_ordermail['header'];
1549 }
1550 if ( WCUtils::is_blank( $_POST['footer']['ordermail'] ) ) {
1551 if ( empty( $mail_ordermail['footer'] ) && isset( $this->options['mail_default']['footer']['ordermail'] ) ) {
1552 $mail_ordermail['footer'] = $this->options['mail_default']['footer']['ordermail'];
1553 $this->options['mail_data']['footer']['ordermail'] = $mail_ordermail['footer'];
1554 }
1555 } else {
1556 $mail_ordermail['footer'] = trim( wel_esc_script( $_POST['footer']['ordermail'] ) );
1557 $this->options['mail_data']['footer']['ordermail'] = $mail_ordermail['footer'];
1558 }
1559 update_option( 'usces_mail_ordermail', $mail_ordermail );
1560
1561 $mail_changemail = get_option( 'usces_mail_changemail', array() );
1562 if ( WCUtils::is_blank( $_POST['title']['changemail'] ) ) {
1563 if ( empty( $mail_changemail['title'] ) && isset( $this->options['mail_default']['title']['changemail'] ) ) {
1564 $mail_changemail['title'] = $this->options['mail_default']['title']['changemail'];
1565 $this->options['mail_data']['title']['changemail'] = $mail_changemail['title'];
1566 }
1567 } else {
1568 $mail_changemail['title'] = trim( wel_esc_script( $_POST['title']['changemail'] ) );
1569 $this->options['mail_data']['title']['changemail'] = $mail_changemail['title'];
1570 }
1571 if ( WCUtils::is_blank( $_POST['header']['changemail'] ) ) {
1572 if ( empty( $mail_changemail['header'] ) && isset( $this->options['mail_default']['header']['changemail'] ) ) {
1573 $mail_changemail['header'] = $this->options['mail_default']['header']['changemail'];
1574 $this->options['mail_data']['header']['changemail'] = $mail_changemail['header'];
1575 }
1576 } else {
1577 $mail_changemail['header'] = trim( wel_esc_script( $_POST['header']['changemail'] ) );
1578 $this->options['mail_data']['header']['changemail'] = $mail_changemail['header'];
1579 }
1580 if ( WCUtils::is_blank( $_POST['footer']['changemail'] ) ) {
1581 if ( empty( $mail_changemail['footer'] ) && isset( $this->options['mail_default']['footer']['changemail'] ) ) {
1582 $mail_changemail['footer'] = $this->options['mail_default']['footer']['changemail'];
1583 $this->options['mail_data']['footer']['changemail'] = $mail_changemail['footer'];
1584 }
1585 } else {
1586 $mail_changemail['footer'] = trim( wel_esc_script( $_POST['footer']['changemail'] ) );
1587 $this->options['mail_data']['footer']['changemail'] = $mail_changemail['footer'];
1588 }
1589 update_option( 'usces_mail_changemail', $mail_changemail );
1590
1591 $mail_receiptmail = get_option( 'usces_mail_receiptmail', array() );
1592 if ( WCUtils::is_blank( $_POST['title']['receiptmail'] ) ) {
1593 if ( empty( $mail_receiptmail['title'] ) && isset( $this->options['mail_default']['title']['receiptmail'] ) ) {
1594 $mail_receiptmail['title'] = $this->options['mail_default']['title']['receiptmail'];
1595 $this->options['mail_data']['title']['receiptmail'] = $mail_receiptmail['title'];
1596 }
1597 } else {
1598 $mail_receiptmail['title'] = trim( wel_esc_script( $_POST['title']['receiptmail'] ) );
1599 $this->options['mail_data']['title']['receiptmail'] = $mail_receiptmail['title'];
1600 }
1601 if ( WCUtils::is_blank( $_POST['header']['receiptmail'] ) ) {
1602 if ( empty( $mail_receiptmail['header'] ) && isset( $this->options['mail_default']['header']['receiptmail'] ) ) {
1603 $mail_receiptmail['header'] = $this->options['mail_default']['header']['receiptmail'];
1604 $this->options['mail_data']['header']['receiptmail'] = $mail_receiptmail['header'];
1605 }
1606 } else {
1607 $mail_receiptmail['header'] = trim( wel_esc_script( $_POST['header']['receiptmail'] ) );
1608 $this->options['mail_data']['header']['receiptmail'] = $mail_receiptmail['header'];
1609 }
1610 if ( WCUtils::is_blank( $_POST['footer']['receiptmail'] ) ) {
1611 if ( empty( $mail_receiptmail['footer'] ) && isset( $this->options['mail_default']['footer']['receiptmail'] ) ) {
1612 $mail_receiptmail['footer'] = $this->options['mail_default']['footer']['receiptmail'];
1613 $this->options['mail_data']['footer']['receiptmail'] = $mail_receiptmail['footer'];
1614 }
1615 } else {
1616 $mail_receiptmail['footer'] = trim( wel_esc_script( $_POST['footer']['receiptmail'] ) );
1617 $this->options['mail_data']['footer']['receiptmail'] = $mail_receiptmail['footer'];
1618 }
1619 update_option( 'usces_mail_receiptmail', $mail_receiptmail );
1620
1621 $mail_mitumorimail = get_option( 'usces_mail_mitumorimail', array() );
1622 if ( WCUtils::is_blank( $_POST['title']['mitumorimail'] ) ) {
1623 if ( empty( $mail_mitumorimail['title'] ) && isset( $this->options['mail_default']['title']['mitumorimail'] ) ) {
1624 $mail_mitumorimail['title'] = $this->options['mail_default']['title']['mitumorimail'];
1625 $this->options['mail_data']['title']['mitumorimail'] = $mail_mitumorimail['title'];
1626 }
1627 } else {
1628 $mail_mitumorimail['title'] = trim( wel_esc_script( $_POST['title']['mitumorimail'] ) );
1629 $this->options['mail_data']['title']['mitumorimail'] = $mail_mitumorimail['title'];
1630 }
1631 if ( WCUtils::is_blank( $_POST['header']['mitumorimail'] ) ) {
1632 if ( empty( $mail_mitumorimail['header'] ) && isset( $this->options['mail_default']['header']['mitumorimail'] ) ) {
1633 $mail_mitumorimail['header'] = $this->options['mail_default']['header']['mitumorimail'];
1634 $this->options['mail_data']['header']['mitumorimail'] = $mail_mitumorimail['header'];
1635 }
1636 } else {
1637 $mail_mitumorimail['header'] = trim( wel_esc_script( $_POST['header']['mitumorimail'] ) );
1638 $this->options['mail_data']['header']['mitumorimail'] = $mail_mitumorimail['header'];
1639 }
1640 if ( WCUtils::is_blank( $_POST['footer']['mitumorimail'] ) ) {
1641 if ( empty( $mail_mitumorimail['footer'] ) && isset( $this->options['mail_default']['footer']['mitumorimail'] ) ) {
1642 $mail_mitumorimail['footer'] = $this->options['mail_default']['footer']['mitumorimail'];
1643 $this->options['mail_data']['footer']['mitumorimail'] = $mail_mitumorimail['footer'];
1644 }
1645 } else {
1646 $mail_mitumorimail['footer'] = trim( wel_esc_script( $_POST['footer']['mitumorimail'] ) );
1647 $this->options['mail_data']['footer']['mitumorimail'] = $mail_mitumorimail['footer'];
1648 }
1649 update_option( 'usces_mail_mitumorimail', $mail_mitumorimail );
1650
1651 $mail_cancelmail = get_option( 'usces_mail_cancelmail', array() );
1652 if ( WCUtils::is_blank( $_POST['title']['cancelmail'] ) ) {
1653 if ( empty( $mail_cancelmail['title'] ) && isset( $this->options['mail_default']['title']['cancelmail'] ) ) {
1654 $mail_cancelmail['title'] = $this->options['mail_default']['title']['cancelmail'];
1655 $this->options['mail_data']['title']['cancelmail'] = $mail_cancelmail['title'];
1656 }
1657 } else {
1658 $mail_cancelmail['title'] = trim( wel_esc_script( $_POST['title']['cancelmail'] ) );
1659 $this->options['mail_data']['title']['cancelmail'] = $mail_cancelmail['title'];
1660 }
1661 if ( WCUtils::is_blank( $_POST['header']['cancelmail'] ) ) {
1662 if ( empty( $mail_cancelmail['header'] ) && isset( $this->options['mail_default']['header']['cancelmail'] ) ) {
1663 $mail_cancelmail['header'] = $this->options['mail_default']['header']['cancelmail'];
1664 $this->options['mail_data']['header']['cancelmail'] = $mail_cancelmail['header'];
1665 }
1666 } else {
1667 $mail_cancelmail['header'] = trim( wel_esc_script( $_POST['header']['cancelmail'] ) );
1668 $this->options['mail_data']['header']['cancelmail'] = $mail_cancelmail['header'];
1669 }
1670 if ( WCUtils::is_blank( $_POST['footer']['cancelmail'] ) ) {
1671 if ( empty( $mail_cancelmail['footer'] ) && isset( $this->options['mail_default']['footer']['cancelmail'] ) ) {
1672 $mail_cancelmail['footer'] = $this->options['mail_default']['footer']['cancelmail'];
1673 $this->options['mail_data']['footer']['cancelmail'] = $mail_cancelmail['footer'];
1674 }
1675 } else {
1676 $mail_cancelmail['footer'] = trim( wel_esc_script( $_POST['footer']['cancelmail'] ) );
1677 $this->options['mail_data']['footer']['cancelmail'] = $mail_cancelmail['footer'];
1678 }
1679 update_option( 'usces_mail_cancelmail', $mail_cancelmail );
1680
1681 $this->action_status = 'success';
1682 $this->action_message = __( 'options are updated', 'usces' );
1683
1684 } else {
1685 $this->action_status = 'none';
1686 $this->action_message = '';
1687 }
1688
1689 do_action( 'usces_action_admin_mail_page' );
1690
1691 if ( isset( $this->options['add_html_email_option'] ) && 1 == $this->options['add_html_email_option'] ) {
1692 wp_enqueue_script( 'jquery-ui-dialog' );
1693 }
1694
1695 require_once USCES_PLUGIN_DIR . '/includes/admin_mail.php';
1696 }
1697
1698 /**
1699 * Admin Cart Page.
1700 */
1701 public function admin_cart_page() {
1702 global $allowedposttags;
1703 $this->options = get_option( 'usces' );
1704
1705 if ( isset( $_POST['usces_option_update'] ) ) {
1706
1707 check_admin_referer( 'admin_cart', 'wc_nonce' );
1708
1709 $_POST = $this->stripslashes_deep_post( $_POST );
1710
1711 foreach ( $this->options['indi_item_name'] as $key => $value ) {
1712 $this->options['indi_item_name'][ $key ] = isset( $_POST['indication'][ $key ] ) ? 1 : 0;
1713 }
1714 foreach ( $_POST['position'] as $key => $value ) {
1715 $this->options['pos_item_name'][ $key ] = $value;
1716 }
1717 foreach ( $_POST['header'] as $key => $value ) {
1718 $this->options['cart_page_data']['header'][ $key ] = wp_kses( $value, $allowedposttags );
1719 }
1720 foreach ( $_POST['footer'] as $key => $value ) {
1721 $this->options['cart_page_data']['footer'][ $key ] = wp_kses( $value, $allowedposttags );
1722 }
1723 if ( isset( $_POST['confirm_notes'] ) ) {
1724 $this->options['cart_page_data']['confirm_notes'] = wp_kses( $_POST['confirm_notes'], $allowedposttags );
1725 }
1726 update_option( 'usces', $this->options );
1727
1728 $this->action_status = 'success';
1729 $this->action_message = __( 'options are updated', 'usces' );
1730
1731 } else {
1732 $this->action_status = 'none';
1733 $this->action_message = '';
1734 }
1735
1736 require_once USCES_PLUGIN_DIR . '/includes/admin_cart.php';
1737 }
1738
1739 /**
1740 * Admin Member Page.
1741 */
1742 public function admin_member_page() {
1743 global $allowedposttags;
1744 $this->options = get_option( 'usces' );
1745
1746 if ( isset( $_POST['usces_option_update'] ) ) {
1747
1748 check_admin_referer( 'admin_member', 'wc_nonce' );
1749
1750 $_POST = $this->stripslashes_deep_post( $_POST );
1751
1752 foreach ( $_POST['header'] as $key => $value ) {
1753 $this->options['member_page_data']['header'][ $key ] = wp_kses( $value, $allowedposttags );
1754 }
1755 foreach ( $_POST['footer'] as $key => $value ) {
1756 $this->options['member_page_data']['footer'][ $key ] = wp_kses( $value, $allowedposttags );
1757 }
1758 $this->options['member_page_data']['agree_member_exp'] = isset( $_POST['agree_member_exp'] ) ? $_POST['agree_member_exp'] : '';
1759 $this->options['member_page_data']['agree_member_cont'] = isset( $_POST['agree_member_cont'] ) ? $_POST['agree_member_cont'] : '';
1760
1761 $this->options['agree_member'] = isset( $_POST['agree_member'] ) ? $_POST['agree_member'] : 'deactivate';
1762
1763 update_option( 'usces', $this->options );
1764
1765 $this->action_status = 'success';
1766 $this->action_message = __( 'options are updated', 'usces' );
1767
1768 } else {
1769 $this->action_status = 'none';
1770 $this->action_message = '';
1771 }
1772
1773 require_once USCES_PLUGIN_DIR . '/includes/admin_member.php';
1774 }
1775
1776 /**
1777 * Admin System Page.
1778 */
1779 public function admin_system_page() {
1780 global $usces_states;
1781 $action_status = '';
1782
1783 $this->options = get_option( 'usces' );
1784
1785 if ( isset( $_POST['usces_system_option_update'] ) ) {
1786
1787 check_admin_referer( 'admin_system', 'wc_nonce' );
1788 $_POST = $this->stripslashes_deep_post( $_POST );
1789
1790 $this->options['divide_item'] = isset( $_POST['divide_item'] ) ? 1 : 0;
1791 $this->options['itemimg_anchor_rel'] = isset( $_POST['itemimg_anchor_rel'] ) ? trim( $_POST['itemimg_anchor_rel'] ) : '';
1792 $this->options['fukugo_category_orderby'] = isset( $_POST['fukugo_category_orderby'] ) ? $_POST['fukugo_category_orderby'] : '';
1793 $this->options['fukugo_category_order'] = isset( $_POST['fukugo_category_order'] ) ? $_POST['fukugo_category_order'] : '';
1794 $this->options['settlement_path'] = isset( $_POST['settlement_path'] ) ? $_POST['settlement_path'] : '';
1795 if ( WCUtils::is_blank( $this->options['settlement_path'] ) ) {
1796 $this->options['settlement_path'] = USCES_PLUGIN_DIR . 'settlement/';
1797 }
1798 $sl = substr( $this->options['settlement_path'], -1 );
1799 if ( '/' != $sl && '\\' != $sl ) {
1800 $this->options['settlement_path'] .= '/';
1801 }
1802 $this->options['logs_path'] = isset( $_POST['logs_path'] ) ? $_POST['logs_path'] : '';
1803 if ( ! WCUtils::is_blank( $this->options['logs_path'] ) ) {
1804 $sl = substr( $this->options['logs_path'], -1 );
1805 if ( '/' == $sl || '\\' == $sl ) {
1806 $this->options['logs_path'] = substr( $this->options['logs_path'], 0, -1 );
1807 }
1808 }
1809 $this->options['use_ssl'] = isset( $_POST['use_ssl'] ) ? 1 : 0;
1810 $this->options['ssl_url'] = isset( $_POST['ssl_url'] ) ? rtrim( $_POST['ssl_url'], '/' ) : '';
1811 $this->options['ssl_url_admin'] = isset( $_POST['ssl_url_admin'] ) ? rtrim( $_POST['ssl_url_admin'], '/' ) : '';
1812 if ( WCUtils::is_blank( $this->options['ssl_url'] ) || WCUtils::is_blank( $this->options['ssl_url_admin'] ) ) {
1813 $this->options['use_ssl'] = 0;
1814 }
1815 $this->options['inquiry_id'] = isset( $_POST['inquiry_id'] ) ? esc_html( rtrim( $_POST['inquiry_id'] ) ) : '';
1816 $this->options['use_javascript'] = isset( $_POST['use_javascript'] ) ? (int) $_POST['use_javascript'] : 1;
1817
1818 $this->options['system']['no_cart_css'] = isset( $_POST['no_cart_css'] ) ? 1 : 0;
1819 $this->options['system']['dec_orderID_flag'] = isset( $_POST['dec_orderID_flag'] ) ? (int) $_POST['dec_orderID_flag'] : 0;
1820 $this->options['system']['dec_orderID_prefix'] = isset( $_POST['dec_orderID_prefix'] ) ? esc_html( rtrim( $_POST['dec_orderID_prefix'] ) ) : '';
1821
1822 if ( isset( $_POST['dec_orderID_digit'] ) ) {
1823 $dec_orderid_digit = (int) rtrim( $_POST['dec_orderID_digit'] );
1824 if ( 6 > $dec_orderid_digit ) {
1825 $this->options['system']['dec_orderID_digit'] = 6;
1826 } else {
1827 $this->options['system']['dec_orderID_digit'] = $dec_orderid_digit;
1828 }
1829 } else {
1830 $this->options['system']['dec_orderID_digit'] = 6;
1831 }
1832
1833 $this->options['system']['subimage_rule'] = isset( $_POST['subimage_rule'] ) ? (int) $_POST['subimage_rule'] : 0;
1834 $this->options['system']['pdf_delivery'] = isset( $_POST['pdf_delivery'] ) ? (int) $_POST['pdf_delivery'] : 0;
1835 $this->options['system']['member_pass_rule_min'] = isset( $_POST['member_pass_rule_min'] ) ? (int) $_POST['member_pass_rule_min'] : 6;
1836 $this->options['system']['member_pass_rule_max'] = isset( $_POST['member_pass_rule_max'] ) && ! empty( $_POST['member_pass_rule_max'] ) ? (int) $_POST['member_pass_rule_max'] : 30;
1837 $this->options['system']['member_pass_rule_upercase'] = isset( $_POST['member_pass_rule_upercase'] ) ? 1 : 0;
1838 $this->options['system']['member_pass_rule_lowercase'] = isset( $_POST['member_pass_rule_lowercase'] ) ? 1 : 0;
1839 $this->options['system']['member_pass_rule_digit'] = isset( $_POST['member_pass_rule_digit'] ) ? 1 : 0;
1840 $this->options['system']['member_pass_rule_symbols'] = isset( $_POST['member_pass_rule_symbols'] ) ? 1 : 0;
1841 $this->options['system']['member_pass_rule_number'] = isset( $_POST['member_pass_rule_number'] ) ? 1 : 0;
1842 $this->options['system']['member_pass_rule_symbol'] = isset( $_POST['member_pass_rule_symbol'] ) ? 1 : 0;
1843 $this->options['system']['csv_encode_type'] = isset( $_POST['csv_encode_type'] ) ? (int) $_POST['csv_encode_type'] : 0;
1844 $this->options['system']['csv_category_format'] = ( isset( $_POST['csv_category_format'] ) ) ? (int) $_POST['csv_category_format'] : 0;
1845 $this->options['system']['settlement_backup'] = ( isset( $_POST['settlement_backup'] ) ) ? (int) $_POST['settlement_backup'] : 0;
1846 $this->options['system']['settlement_notice'] = ( isset( $_POST['settlement_notice'] ) ) ? (int) $_POST['settlement_notice'] : 0;
1847 $this->options['system']['order_list_delete_link'] = ( isset( $_POST['order_list_delete_link'] ) ) ? (int) $_POST['order_list_delete_link'] : 0;
1848 $this->options['system']['member_list_delete_link'] = ( isset( $_POST['member_list_delete_link'] ) ) ? (int) $_POST['member_list_delete_link'] : 0;
1849
1850 if ( '' != $action_status ) {
1851 $this->action_status = 'error';
1852 $this->action_message = __( 'Data have deficiency.', 'usces' );
1853 } else {
1854 $this->action_status = 'success';
1855 $this->action_message = __( 'options are updated', 'usces' );
1856 }
1857 } elseif ( isset( $_POST['usces_locale_option_update'] ) ) {
1858
1859 check_admin_referer( 'admin_system', 'wc_nonce' );
1860 $_POST = $this->stripslashes_deep_post( $_POST );
1861
1862 $this->options['system']['front_lang'] = ( isset( $_POST['front_lang'] ) && 'others' != $_POST['front_lang'] ) ? $_POST['front_lang'] : usces_get_local_language();
1863 $this->options['system']['currency'] = ( isset( $_POST['currency'] ) && 'others' != $_POST['currency'] ) ? $_POST['currency'] : usces_get_base_country();
1864 $this->options['system']['addressform'] = ( isset( $_POST['addressform'] ) ) ? $_POST['addressform'] : usces_get_local_addressform();
1865 $this->options['system']['target_market'] = ( isset( $_POST['target_market'] ) ) ? $_POST['target_market'] : usces_get_local_target_market();
1866
1867 unset ( $this->options['province'] );
1868 foreach ( (array) $this->options['system']['target_market'] as $target_market ) {
1869 $province = array();
1870 if ( ! empty( $_POST[ 'province_' . $target_market ] ) ) {
1871 $_province = usces_change_line_break( $_POST[ 'province_' . $target_market ] );
1872 $temp_pref = explode( "\n", $_province );
1873 $province[] = '-- Select --';
1874 foreach ( $temp_pref as $pref ) {
1875 if ( ! WCUtils::is_blank( $pref ) ) {
1876 $validated = wel_validate_prefecture_name( wp_unslash( $pref ) );
1877 if ( '' !== $validated ) {
1878 $province[] = esc_html( $validated );
1879 }
1880 }
1881 }
1882 if ( 1 == count( $province ) ) {
1883 $action_status = 'error';
1884 }
1885 } else {
1886 if ( isset( $usces_states[ $target_market ] ) && is_array( $usces_states[ $target_market ] ) ) {
1887 $province = $usces_states[ $target_market ];
1888 } else {
1889 $action_status = 'error';
1890 }
1891 }
1892 $this->options['province'][ $target_market ] = $province;
1893 }
1894
1895 if ( '' != $action_status ) {
1896 $this->action_status = 'error';
1897 $this->action_message = __( 'Data have deficiency.', 'usces' );
1898 } else {
1899 $this->action_status = 'success';
1900 $this->action_message = __( 'options are updated', 'usces' );
1901 }
1902 } else {
1903
1904 if ( ! isset( $this->options['province'] ) || empty( $this->options['province'] ) ) {
1905 $this->options['province'][ $this->options['system']['base_country'] ] = $usces_states[ $this->options['system']['base_country'] ];
1906 }
1907 $this->action_status = 'none';
1908 $this->action_message = '';
1909 }
1910
1911 if ( 'error' != $action_status ) {
1912 update_option( 'usces', $this->options );
1913 }
1914
1915 require_once USCES_PLUGIN_DIR . '/includes/admin_system.php';
1916 }
1917
1918 /**
1919 * Settlement Setting Page.
1920 */
1921 public function admin_settlement_page() {
1922
1923 $this->action_status = 'none';
1924 $this->action_message = '';
1925
1926 $options = get_option( 'usces' );
1927 $mes = '';
1928
1929 if ( isset( $_POST['usces_option_update'] ) ) {
1930
1931 check_admin_referer( 'admin_settlement', 'wc_nonce' );
1932
1933 $_POST = $this->stripslashes_deep_post( $_POST );
1934
1935 switch ( $_POST['acting'] ) {
1936 case 'settlement_selected':
1937 if ( isset( $_POST['settlement_selected'] ) ) {
1938 $settlement_selected = explode( ',', sanitize_text_field( wp_unslash( $_POST['settlement_selected'] ) ) );
1939 $payments = usces_get_system_option( 'usces_payment_method', 'settlement' );
1940 $acting_payments = array();
1941 foreach ( (array) $payments as $key => $payment ) {
1942 if ( 'activate' == $payment['use'] && false !== strpos( $key, 'acting_' ) ) {
1943 $acting = explode( '_', $key );
1944 if ( ! empty( $acting[1] ) && 'paypal' == $acting[1] ) {
1945 $acting_payments[] = $acting[1] . '_cp';
1946 } else {
1947 $acting_payments[] = apply_filters( 'usces_filter_acting_payment_slug', $acting[1], $acting );
1948 }
1949 }
1950 }
1951 $acting_payments = array_unique( $acting_payments );
1952 $available_settlement = get_option( 'usces_available_settlement', array() );
1953 $available = array_keys( $available_settlement );
1954 foreach ( (array) $settlement_selected as $settlement ) {
1955 if ( ! empty( $settlement ) && ! in_array( $settlement, $available ) ) {
1956 $mes .= __( '* Failed to update payment module.', 'usces' ) . '<br />';
1957 }
1958 }
1959 foreach ( (array) $acting_payments as $payment ) {
1960 if ( ! in_array( $payment, $settlement_selected ) && isset( $available_settlement[ $payment ] ) ) {
1961 $settlement_name = $available_settlement[ $payment ];
1962 $mes .= sprintf( __( '* %s can not be unselected. Please "delete" or "stop" the payment method.', 'usces' ), $settlement_name ) . '<br />';
1963 }
1964 }
1965 if ( WCUtils::is_blank( $mes ) ) {
1966 $unavailable_activate = 0;
1967 $unavailable_payments = apply_filters( 'usces_filter_unavailable_payments', get_option( 'usces_unavailable_settlement', array() ) );
1968 foreach ( (array) $unavailable_payments as $payment ) {
1969 if ( in_array( $payment, $settlement_selected ) ) {
1970 $unavailable_activate++;
1971 }
1972 }
1973 if ( 1 < $unavailable_activate ) {
1974 $mes .= __( '* Settlement that can not be used together is activated.', 'usces' ) . '<br />';
1975 }
1976 }
1977
1978 if ( WCUtils::is_blank( $mes ) ) {
1979 update_option( 'usces_settlement_selected', $settlement_selected );
1980 $this->settlement->setup();
1981 $this->action_status = 'success';
1982 $this->action_message = __( 'Updated.', 'usces' );
1983 } else {
1984 $this->action_status = 'error';
1985 $this->action_message = __( 'Update failed.', 'usces' );
1986 }
1987 }
1988 break;
1989 }
1990 do_action( 'usces_action_admin_settlement_update', $mes );
1991 }
1992
1993 $this->options = get_option( 'usces' );
1994
1995 require_once USCES_PLUGIN_DIR . '/includes/admin_settlement.php';
1996 }
1997
1998 public function selected( $selected, $current ) {
1999 if ( $selected == $current ) {
2000 echo ' selected="selected"';
2001 }
2002 }
2003
2004 public function usces_session_start() {
2005 $options = get_option( 'usces' );
2006 if ( ! isset( $options['usces_key'] ) || empty( $options['usces_key'] ) ) {
2007 $options['usces_key'] = uniqid( 'uk' );
2008 update_option( 'usces', $options );
2009 }
2010
2011 if ( defined( 'USCES_KEY' ) ) {
2012 if ( is_admin() || preg_match( '/\/wp-login\.php/', $_SERVER['REQUEST_URI'] ) ) {
2013 @session_name( 'adm' . USCES_KEY );
2014 } else {
2015 @session_name( USCES_KEY );
2016 }
2017 } else {
2018 if ( is_admin() || preg_match( '/\/wp-login\.php/', $_SERVER['REQUEST_URI'] ) ) {
2019 @session_name( 'adm' . $options['usces_key'] );
2020 } else {
2021 @session_name( $options['usces_key'] );
2022 }
2023 }
2024
2025 // A1 (Layer 3 / uscesid removal): uscesid によるセッションID設定を撤廃。
2026 // かつては GET uscesid を uscesdc() で復号し session_id() に渡していたが、これがセッション
2027 // 固定の温床だった(会員乗っ取り・Mantis #0005562)。決済通知のセッション復元は取引キーの
2028 // DBストア(A3)/同一オリジンの uk cookie 再開(A2/A5/A6)へ移行済みのため撤廃する。
2029 // See .docs/welcart2.x/security-remediation_uscesid-layer3-a1c-teardown-design.md .
2030
2031 do_action( 'usces_action_session_start' );
2032
2033 $httponly = true;
2034 $sitescheme = substr( get_option( 'siteurl' ), 0, 5 );
2035 $homescheme = substr( get_option( 'home' ), 0, 5 );
2036 if ( 'https' == $sitescheme && 'https' == $homescheme ) {
2037 $sslonly = true;
2038 $samesite = 'None';
2039 } else {
2040 $sslonly = false;
2041 $samesite = '';
2042 }
2043
2044 if ( version_compare( PHP_VERSION, '7.3.0', '>=' ) ) {
2045 $cookie_options = array(
2046 'lifetime' => 0,
2047 'path' => USCES_COOKIEPATH,
2048 'domain' => '',
2049 'secure' => $sslonly,
2050 'httponly' => $httponly,
2051 'samesite' => $samesite,
2052 );
2053 session_set_cookie_params( $cookie_options );
2054 } else {
2055 session_set_cookie_params( 0, USCES_COOKIEPATH, '', $sslonly, $httponly );
2056 }
2057
2058 @session_start();
2059
2060 if ( ! isset( $_SESSION['usces_member'] ) || 'activate' != $options['membersystem_state'] ) {
2061 $_SESSION['usces_member'] = array();
2062 }
2063
2064 if ( ! isset( $_SESSION['usces_checked_business_days'] ) ) {
2065 $this->update_business_days();
2066 }
2067 }
2068
2069 public function usces_cookie() {
2070 if ( is_admin() ) {
2071 return;
2072 }
2073
2074 // A1/C (Layer 3 / uscesid removal): 旧「GET uscesid を復号して addr='acting' を判定」ブロックを撤廃。
2075 // uscesid 機構撤廃に伴い addr 判定は成立しない。以降は旧SSL同期デッドコード(A7 で撤去済)で return.
2076 if ( apply_filters( 'usces_filter_cookie', false ) ) {
2077 return;
2078 }
2079
2080 // NOTE (Layer 3 / uscesid removal, A7): the legacy "common domain + separate SSL domain"
2081 // cookie-sync block that used to follow here was already unreachable (an unconditional
2082 // return above) and relied on the old SSL/uscesid scheme. Removed during the uscesid
2083 // mechanism teardown. See .docs/welcart2.x/security-remediation_uscesid-session-fixation.md 4.3.A A7.
2084 return;
2085 }
2086
2087 public function set_cookie( $values, $key = 'usces_cookie' ) {
2088 // A1/C (Layer 3 / uscesid removal): 旧実装は uscesid 付きリクエストで再生成をスキップしていたが、
2089 // uscesid 機構を撤廃したため常に再生成する(=uscesid 以前のオーガニック挙動に一致)。
2090 // 決済のセッション継続は取引キーDBストア(A3)/uk cookie(A2/A5/A6)で担保.
2091 session_regenerate_id( true );
2092 $value = usces_serialize( $values );
2093 $timeout = time()+7*86400;
2094 $timeout = apply_filters( 'usces_filter_set_cookie_timeout', $timeout, $values, $key );
2095 $domain = $_SERVER['SERVER_NAME'];
2096
2097 $httponly = true;
2098 $sitescheme = substr( get_option( 'siteurl' ), 0, 5 );
2099 $homescheme = substr( get_option( 'home' ), 0, 5 );
2100 if ( 'https' == $sitescheme && 'https' == $homescheme ) {
2101 $sslonly = true;
2102 $samesite = 'None';
2103 } else {
2104 $sslonly = false;
2105 $samesite = '';
2106 }
2107
2108 if ( version_compare( PHP_VERSION, '7.3.0', '>=' ) ) {
2109 $cookie_options = array(
2110 'expires' => $timeout,
2111 'path' => USCES_COOKIEPATH,
2112 'domain' => $domain,
2113 'secure' => $sslonly,
2114 'httponly' => $httponly,
2115 'samesite' => $samesite,
2116 );
2117 $res = setcookie( $key, $value, $cookie_options );
2118 } else {
2119 $res = setcookie( $key, $value, $timeout, USCES_COOKIEPATH, $domain, true, true );
2120 }
2121 }
2122
2123 public function get_cookie( $key = 'usces_cookie' ) {
2124 $values = isset( $_COOKIE[ $key ] ) ? usces_unserialize( stripslashes( $_COOKIE[ $key ] ) ) : null;
2125 return $values;
2126 }
2127
2128 public function get_access( $key, $type, $date ) {
2129 global $wpdb;
2130 $table_name = $wpdb->prefix . 'usces_access';
2131
2132 $query = $wpdb->prepare( "SELECT acc_value FROM $table_name WHERE acc_key = %s AND acc_type = %s AND acc_date = %s", $key, $type, $date );
2133 $value = $wpdb->get_var( $query );
2134 if ( ! $value ) {
2135 $res = null;
2136 } else {
2137 $res = wel_safe_unserialize( $value );
2138 }
2139
2140 return $res;
2141 }
2142
2143 public function get_access_piriod( $key, $type, $startday, $endday ) {
2144 global $wpdb;
2145 $table_name = $wpdb->prefix . 'usces_access';
2146 $query = $wpdb->prepare( "SELECT acc_type, acc_value, acc_date FROM $table_name WHERE acc_key = %s AND acc_type = %s AND (acc_date >= %s AND acc_date <= %s)", $key, $type, $startday, $endday );
2147 $res = $wpdb->get_results( $query, ARRAY_A );
2148
2149 return $res;
2150 }
2151
2152 public function update_access( $array ) {
2153 global $wpdb;
2154 $table_name = $wpdb->prefix . 'usces_access';
2155
2156 $query = $wpdb->prepare( "SELECT ID FROM $table_name WHERE acc_key = %s AND acc_type = %s AND acc_date = %s", $array['acc_key'], $array['acc_type'], $array['acc_date'] );
2157 $res = $wpdb->get_var( $query );
2158 if ( empty( $res ) ) {
2159 $query = $wpdb->prepare( "INSERT INTO $table_name (acc_key, acc_type, acc_value, acc_date) VALUES(%s, %s, %s, %s)", $array['acc_key'], $array['acc_type'], serialize( $array['acc_value'] ), $array['acc_date'] );
2160 $wpdb->query( $query );
2161 } else {
2162 $query = $wpdb->prepare( "UPDATE $table_name SET acc_value = %s WHERE acc_key = %s AND acc_type = %s AND acc_date = %s", serialize( $array['acc_value'] ), $array['acc_key'], $array['acc_type'], $array['acc_date'] );
2163 $wpdb->query( $query );
2164 }
2165 }
2166
2167 /**
2168 * @deprecated A1/C (Layer 3 / uscesid removal). uscesid 機構は撤廃済み(A1)。本体はこの関数を
2169 * セッション設定にもURL/nonce生成にも使わない。現状 acting_data の acc_str1 マーカー(save_order_acting_data)
2170 * と、未移行の拡張・クライアントの後方互換のためだけに残置している。**全拡張・全クライアント移行後に
2171 * uscescv()/uscesdc() ともども削除する**(最終クリーンアップ)。
2172 */
2173 public function get_uscesid( $flag = true ) {
2174 $sessname = session_name();
2175 $sessid = session_id();
2176 $sessid = $this->uscescv( $sessid, $flag );
2177 return $sessid;
2178 }
2179
2180 /**
2181 * Session-bound nonce action key for shop-member forms (uscesid-free).
2182 *
2183 * Welcart shop members are not WordPress users (uid=0, empty WP session token), so a
2184 * per-session component is mixed into the nonce action string to keep nonces scoped to
2185 * the individual shop session. This replaces the legacy `$action . get_uscesid(false)`
2186 * (which encoded the same session id via the uscesid obfuscation). The session id is
2187 * used only as a server-side hash input — it is never output to the client or a URL.
2188 *
2189 * @param string $action Base action (e.g. 'post_member' / 'use_point' / 'wc_purchase_nonce').
2190 * @return string
2191 */
2192 public function member_nonce_key( $action ) {
2193 return $action . session_id();
2194 }
2195
2196 /**
2197 * Create a shop-member nonce bound to the current session.
2198 *
2199 * @param string $action Base action.
2200 * @return string
2201 */
2202 public function create_member_nonce( $action ) {
2203 return wp_create_nonce( $this->member_nonce_key( $action ) );
2204 }
2205
2206 /**
2207 * Verify a shop-member nonce.
2208 *
2209 * A1/C (Layer 3 / uscesid removal): 移行期の後方互換だった「旧 uscesid ベースキーの二重受理」を撤廃。
2210 * 以降はセッション束縛の新方式キー(member_nonce_key)のみ受理する。未移行の拡張・テーマの
2211 * フォーム(旧キー生成)は新方式へ移行するまで nonce 不一致になる(協調リリースで同時展開)。
2212 *
2213 * @param string $nonce Nonce value from the request.
2214 * @param string $action Base action.
2215 * @return int|false 1|2 on success, false on failure.
2216 */
2217 public function verify_member_nonce( $nonce, $action ) {
2218 return wp_verify_nonce( $nonce, $this->member_nonce_key( $action ) );
2219 }
2220
2221 public function shop_head() {
2222 global $post;
2223 $this->item = $post;
2224 if ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) ) {
2225 echo "<meta name='robots' content='noindex,nofollow' />\n";
2226 }
2227 }
2228
2229 /**
2230 * Caught by wp_footer action hook
2231 */
2232 public function shop_foot() {
2233 global $current_user;
2234
2235 $item = $this->item;
2236 if ( empty( $item ) ) {
2237 $item = new stdClass;
2238 $item->ID = 0;
2239 $item->post_mime_type = '';
2240 }
2241
2242 wp_get_current_user();
2243
2244 // usces_cart.js is not used.
2245 if ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
2246 $javascript_url = USCES_FRONT_PLUGIN_URL . '/js/usces_cart.js';
2247 } else {
2248 $javascript_url = USCES_WP_CONTENT_URL . '/plugins/' . USCES_PLUGIN_FOLDER . '/js/usces_cart.js';
2249 }
2250
2251 $this->previous_url = isset( $_SESSION['usces_previous_url'] ) ? $_SESSION['usces_previous_url'] : get_home_url();
2252
2253 // If the product object does't exists.
2254 if ( $this->use_js && empty( $this->item ) ) {
2255 ?>
2256 <script type='text/javascript'>
2257 uscesL10n = {
2258 <?php echo apply_filters( 'usces_filter_uscesL10n', null, $item->ID ); ?>
2259
2260 'ajaxurl': "<?php echo esc_url( $this->ssl_admin_ajax_url() ); ?>"
2261 }
2262 </script>
2263 <?php
2264
2265 // If the product object exists.
2266 } elseif ( $this->use_js && ! empty( $this->item ) ) {
2267
2268 $ioptkeys = $this->get_itemOptionKey( $item->ID );
2269 $mes_opts_str = '';
2270 $key_opts_str = '';
2271 $opt_means = '';
2272 $opt_esse = '';
2273 if ( $ioptkeys ) {
2274 foreach ( $ioptkeys as $key => $value ) {
2275 $optValues = $this->get_itemOptions( $value, $item->ID );
2276 if ( false === $optValues ) {
2277 continue;
2278 }
2279 if ( $optValues['means'] < 2 || 3 == $optValues['means'] || 4 == $optValues['means'] ) {
2280 $mes_opts_str .= "'" . sprintf( __( 'Chose the %s', 'usces' ), esc_js( apply_filters( 'usces_filter_uscesL10n_option_name', $value, $optValues ) ) ) . "',";
2281 } else {
2282 $mes_opts_str .= "'" . sprintf( __( 'Input the %s', 'usces' ), esc_js( apply_filters( 'usces_filter_uscesL10n_option_name', $value, $optValues ) ) ) . "',";
2283 }
2284 $key_opts_str .= "'" . urlencode( esc_js( $value ) ) . "',";
2285 $opt_means .= "'" . esc_js( $optValues['means'] ) . "',";
2286 $opt_esse .= "'" . esc_js( $optValues['essential'] ) . "',";
2287 }
2288 $mes_opts_str = rtrim( $mes_opts_str, ',' );
2289 $key_opts_str = rtrim( $key_opts_str, ',' );
2290 $opt_means = rtrim( $opt_means, ',' );
2291 $opt_esse = rtrim( $opt_esse, ',' );
2292 }
2293
2294 $product = wel_get_product( $item->ID );
2295 $itemRestriction = isset( $product['itemRestriction'] ) ? $product['itemRestriction'] : '';
2296 $wcpage = usces_page_name( 'return' );
2297 $nonce_action = 'wc_confirm';
2298 $itemOrderAcceptable = $this->getItemOrderAcceptable( $item->ID );
2299 ?>
2300 <script type='text/javascript'>
2301 uscesL10n = {
2302 <?php echo apply_filters( 'usces_filter_uscesL10n', null, $item->ID ); ?>
2303
2304 'ajaxurl': "<?php echo esc_url( $this->ssl_admin_ajax_url() ); ?>",
2305 'loaderurl': "<?php echo USCES_PLUGIN_URL . 'images/loading.gif'; ?>",
2306 'post_id': "<?php echo esc_js( $item->ID ); ?>",
2307 'cart_number': "<?php echo get_option( 'usces_cart_number' ); ?>",
2308 'is_cart_row': <?php echo ( ( 0 < $this->cart->num_row() ) ? 'true' : 'false' ); ?>,
2309 'opt_esse': new Array( <?php wel_esc_script_e( $opt_esse ); ?> ),
2310 'opt_means': new Array( <?php wel_esc_script_e( $opt_means ); ?> ),
2311 'mes_opts': new Array( <?php wel_esc_script_e( $mes_opts_str ); ?> ),
2312 'key_opts': new Array( <?php wel_esc_script_e( $key_opts_str ); ?> ),
2313 'previous_url': "<?php echo esc_url( $this->previous_url ); ?>",
2314 'itemRestriction': "<?php echo esc_js( $itemRestriction ); ?>",
2315 'itemOrderAcceptable': "<?php echo esc_js( $itemOrderAcceptable ); ?>",
2316 'uscespage': "<?php echo esc_js( $wcpage ); ?>",
2317 <?php // A1/C (Layer 3 / uscesid removal): JS グローバル uscesL10n.uscesid の供給を撤廃。消費側は uk cookie 依存へ移行. ?>
2318 'wc_nonce': "<?php echo wp_create_nonce( $nonce_action ); ?>"
2319 }
2320 </script>
2321 <script type='text/javascript' src='<?php echo esc_url( $javascript_url ); ?>'></script>
2322 <?php
2323 }
2324
2325 ob_start();
2326
2327 // If it's Product Details page.
2328 if ( $this->use_js && ( is_singular() && 'item' == $item->post_mime_type ) ) {
2329 ?>
2330 <script type='text/javascript'>
2331 (function($) {
2332 uscesCart = {
2333 intoCart : function (post_id, sku) {
2334 var zaikonum = $("[id='zaikonum["+post_id+"]["+sku+"]']").val();
2335 var zaiko = $("[id='zaiko["+post_id+"]["+sku+"]']").val();
2336 if( <?php echo apply_filters( 'usces_intoCart_zaiko_check_js', "( uscesL10n.itemOrderAcceptable != '1' && zaiko != '0' && zaiko != '1' ) || ( uscesL10n.itemOrderAcceptable != '1' && parseInt(zaikonum) == 0 )" ); ?> ){
2337 alert('<?php _e( 'temporaly out of stock now', 'usces' ); ?>');
2338 return false;
2339 }
2340
2341 var mes = '';
2342 if( $("[id='quant["+post_id+"]["+sku+"]']").length ){
2343 var quant = $("[id='quant["+post_id+"]["+sku+"]']").val();
2344 if( quant == '0' || quant == '' || !(uscesCart.isNum(quant))){
2345 mes += "<?php _e( 'enter the correct amount', 'usces' ); ?>\n";
2346 }
2347 var checknum = '';
2348 var checkmode = '';
2349 if( parseInt(uscesL10n.itemRestriction) <= parseInt(zaikonum) && uscesL10n.itemRestriction != '' && uscesL10n.itemRestriction != '0' && zaikonum != '' ) {
2350 checknum = uscesL10n.itemRestriction;
2351 checkmode ='rest';
2352 } else if( uscesL10n.itemOrderAcceptable != '1' && parseInt(uscesL10n.itemRestriction) > parseInt(zaikonum) && uscesL10n.itemRestriction != '' && uscesL10n.itemRestriction != '0' && zaikonum != '' ) {
2353 checknum = zaikonum;
2354 checkmode ='zaiko';
2355 } else if( uscesL10n.itemOrderAcceptable != '1' && (uscesL10n.itemRestriction == '' || uscesL10n.itemRestriction == '0') && zaikonum != '' ) {
2356 checknum = zaikonum;
2357 checkmode ='zaiko';
2358 } else if( uscesL10n.itemRestriction != '' && uscesL10n.itemRestriction != '0' && ( zaikonum == '' || zaikonum == '0' || parseInt(uscesL10n.itemRestriction) > parseInt(zaikonum) ) ) {
2359 checknum = uscesL10n.itemRestriction;
2360 checkmode ='rest';
2361 }
2362
2363 if( parseInt(quant) > parseInt(checknum) && checknum != '' ){
2364 if(checkmode == 'rest'){
2365 mes += <?php _e( "'This article is limited by '+checknum+' at a time.'", 'usces' ); ?>+"\n";
2366 }else{
2367 mes += <?php _e( "'Stock is remainder '+checknum+'.'", 'usces' ); ?>+"\n";
2368 }
2369 }
2370 }
2371 for(i=0; i<uscesL10n.key_opts.length; i++){
2372 if( uscesL10n.opt_esse[i] == '1' ){
2373 var skuob = $("[id='itemOption["+post_id+"]["+sku+"]["+uscesL10n.key_opts[i]+"]']");
2374 var itemOption = "itemOption["+post_id+"]["+sku+"]["+uscesL10n.key_opts[i]+"]";
2375 var opt_obj_radio = $(":radio[name*='"+itemOption+"']");
2376 var opt_obj_checkbox = $(":checkbox[name*='"+itemOption+"']:checked");
2377
2378 if( uscesL10n.opt_means[i] == '3' ){
2379
2380 if( !opt_obj_radio.is(':checked') ){
2381 mes += uscesL10n.mes_opts[i]+"\n";
2382 }
2383
2384 }else if( uscesL10n.opt_means[i] == '4' ){
2385
2386 if( !opt_obj_checkbox.length ){
2387 mes += uscesL10n.mes_opts[i]+"\n";
2388 }
2389
2390 }else{
2391
2392 if( skuob.length ){
2393 if( uscesL10n.opt_means[i] == 0 && skuob.val() == '#NONE#' ){
2394 mes += uscesL10n.mes_opts[i]+"\n";
2395 }else if( uscesL10n.opt_means[i] == 1 && ( skuob.val() == '' || skuob.val() == '#NONE#' ) ){
2396 mes += uscesL10n.mes_opts[i]+"\n";
2397 }else if( uscesL10n.opt_means[i] >= 2 && skuob.val() == '' ){
2398 mes += uscesL10n.mes_opts[i]+"\n";
2399 }
2400 }
2401 }
2402 }
2403 }
2404
2405 <?php apply_filters( 'usces_filter_inCart_js_check', $item->ID ); // Unavailable. ?>
2406 <?php do_action( 'usces_action_inCart_js_check', $item->ID ); ?>
2407
2408 if( mes != '' ){
2409 alert( mes );
2410 return false;
2411 }else{
2412 <?php echo apply_filters( 'usces_filter_js_intoCart', "return true;\n", $item->ID, null ); ?>
2413 }
2414 },
2415
2416 isNum : function (num) {
2417 if (num.match(/[^0-9]/g)) {
2418 return false;
2419 }
2420 return true;
2421 }
2422 };
2423 })(jQuery);
2424 </script>
2425 <?php
2426 // If it's Product Details page.
2427 } elseif ( $this->use_js && ( is_page( USCES_CART_NUMBER ) || $this->is_cart_page( $_SERVER['REQUEST_URI'] ) ) ) {
2428 ?>
2429 <script type='text/javascript'>
2430 (function($) {
2431 uscesCart = {
2432 upCart : function () {
2433
2434 var zaikoob = $("input[name*='zaikonum']");
2435 var quantob = $("input[name*='quant']");
2436 var postidob = $("input[name*='itempostid']");
2437 var skuob = $("input[name*='itemsku']");
2438
2439 var zaikonum = '';
2440 var zaiko = '';
2441 var quant = '';
2442 var mes = '';
2443 var checknum = '';
2444 var post_id = '';
2445 var sku = '';
2446 var itemRestriction = '';
2447 var itemOrderAcceptable = '';
2448
2449 var ct = zaikoob.length;
2450 for(var i=0; i< ct; i++){
2451 post_id = postidob[i].value;
2452 sku = skuob[i].value;
2453 itemRestriction = $("input[name='itemRestriction\[" + i + "\]']").val();
2454 itemOrderAcceptable = $("input[name='itemOrderAcceptable\[" + i + "\]']").val();
2455 zaikonum = $("input[name='zaikonum\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").val();
2456
2457 quant = $("*[name='quant\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").val();
2458 if( $("*[name='quant\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").length ){
2459 if( quant == '0' || quant == '' || !(uscesCart.isNum(quant))){
2460 mes += <?php _e( "'enter the correct amount for the No.' + (i+1) + ' item'", 'usces' ); ?>+"\n";
2461 }
2462 var checknum = '';
2463 var checkmode = '';
2464 if( parseInt(itemRestriction) <= parseInt(zaikonum) && itemRestriction != '' && itemRestriction != '0' && zaikonum != '' ) {
2465 checknum = itemRestriction;
2466 checkmode ='rest';
2467 } else if( itemOrderAcceptable != '1' && parseInt(itemRestriction) > parseInt(zaikonum) && itemRestriction != '' && itemRestriction != '0' && zaikonum != '' ) {
2468 checknum = zaikonum;
2469 checkmode ='zaiko';
2470 } else if( itemOrderAcceptable != '1' && (itemRestriction == '' || itemRestriction == '0') && zaikonum != '' ) {
2471 checknum = zaikonum;
2472 checkmode ='zaiko';
2473 } else if( itemRestriction != '' && itemRestriction != '0' && ( zaikonum == '' || zaikonum == '0' || parseInt(itemRestriction) > parseInt(zaikonum) ) ) {
2474 checknum = itemRestriction;
2475 checkmode ='rest';
2476 }
2477 if( parseInt(quant) > parseInt(checknum) && checknum != '' ){
2478 if(checkmode == 'rest'){
2479 mes += <?php _e( "'This article is limited by '+checknum+' at a time for the No.' + (i+1) + ' item.'", 'usces' ); ?>+"\n";
2480 }else{
2481 mes += <?php _e( "'Stock of No.' + (i+1) + ' item is remainder '+checknum+'.'", 'usces' ); ?>+"\n";
2482 }
2483 }
2484 }
2485 }
2486
2487 <?php apply_filters( 'usces_filter_upCart_js_check', $item->ID ); // Unavailable. ?>
2488 <?php do_action( 'usces_action_upCart_js_check', $item->ID ); ?>
2489
2490 if( mes != '' ){
2491 alert( mes );
2492 return false;
2493 }else{
2494 <?php echo apply_filters( 'usces_filter_js_upCart', "return true;\n", $item->ID, null ); ?>
2495 }
2496 },
2497
2498 cartNext : function () {
2499
2500 var zaikoob = $("input[name*='zaikonum']");
2501 var quantob = $("input[name*='quant']");
2502 var postidob = $("input[name*='itempostid']");
2503 var skuob = $("input[name*='itemsku']");
2504
2505 var zaikonum = '';
2506 var zaiko = '';
2507 var quant = '';
2508 var mes = '';
2509 var checknum = '';
2510 var post_id = '';
2511 var sku = '';
2512 var itemRestriction = '';
2513 var itemOrderAcceptable = '';
2514
2515 var ct = zaikoob.length;
2516 for(var i=0; i< ct; i++){
2517 post_id = postidob[i].value;
2518 sku = skuob[i].value;
2519 itemRestriction = $("input[name='itemRestriction\[" + i + "\]']").val();
2520 itemOrderAcceptable = $("input[name='itemOrderAcceptable\[" + i + "\]']").val();
2521 zaikonum = $("input[name='zaikonum\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").val();
2522
2523 quant = $("*[name='quant\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").val();
2524 if( $("*[name='quant\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").length ){
2525 if( quant == '0' || quant == '' || !(uscesCart.isNum(quant))){
2526 mes += <?php _e( "'enter the correct amount for the No.' + (i+1) + ' item'", 'usces' ); ?>+"\n";
2527 }
2528 var checknum = '';
2529 var checkmode = '';
2530 if( parseInt(itemRestriction) <= parseInt(zaikonum) && itemRestriction != '' && itemRestriction != '0' && zaikonum != '' ) {
2531 checknum = itemRestriction;
2532 checkmode ='rest';
2533 } else if( itemOrderAcceptable != '1' && parseInt(itemRestriction) > parseInt(zaikonum) && itemRestriction != '' && itemRestriction != '0' && zaikonum != '' ) {
2534 checknum = zaikonum;
2535 checkmode ='zaiko';
2536 } else if( itemOrderAcceptable != '1' && (itemRestriction == '' || itemRestriction == '0') && zaikonum != '' ) {
2537 checknum = zaikonum;
2538 checkmode ='zaiko';
2539 } else if( itemRestriction != '' && itemRestriction != '0' && ( zaikonum == '' || zaikonum == '0' || parseInt(itemRestriction) > parseInt(zaikonum) ) ) {
2540 checknum = itemRestriction;
2541 checkmode ='rest';
2542 }
2543
2544 if( parseInt(quant) > parseInt(checknum) && checknum != '' ){
2545 if(checkmode == 'rest'){
2546 mes += <?php _e( "'This article is limited by '+checknum+' at a time for the No.' + (i+1) + ' item.'", 'usces' ); ?>+"\n";
2547 }else{
2548 mes += <?php _e( "'Stock of No.' + (i+1) + ' item is remainder '+checknum+'.'", 'usces' ); ?>+"\n";
2549 }
2550 }
2551 }
2552 }
2553
2554 <?php do_action( 'usces_action_nextCart_js_check', $item->ID ); ?>
2555
2556 if( mes != '' ){
2557 alert( mes );
2558 return false;
2559 }else{
2560 return true;
2561 }
2562 },
2563
2564 customerNext : function () {
2565 <?php do_action( 'usces_action_customerNext_js_check', $item->ID ); ?>
2566 },
2567
2568 customerPre : function () {
2569 <?php do_action( 'usces_action_customerPre_js_check', $item->ID ); ?>
2570 },
2571
2572 previousCart : function () {
2573 location.href = uscesL10n.previous_url;
2574 },
2575
2576 settings: {
2577 url: uscesL10n.ajaxurl,
2578 type: 'POST',
2579 cache: false
2580 },
2581
2582 changeStates : function( country ) {
2583 var s = this.settings;
2584 s.data = "action=change_states_ajax&country=" + country;
2585 $.ajax( s ).done(function(data, dataType){
2586
2587 if( 'error' == data ){
2588 alert('error');
2589 }else{
2590 $("select#pref").html( data );
2591 }
2592 }).fail(function(msg){
2593 alert("error");
2594 });
2595 return false;
2596 },
2597
2598 isNum : function (num) {
2599 if (num.match(/[^0-9]/g)) {
2600 return false;
2601 }
2602 return true;
2603 },
2604 purchase : 0
2605 };
2606 $("#country").change(function () {
2607 var country = $("#country option:selected").val();
2608 $("#newcharging_type option:selected").val()
2609 uscesCart.changeStates( country );
2610 });
2611 $("#purchase_form").submit(function () {
2612 if( 0 == uscesCart.purchase ){
2613 uscesCart.purchase = 1;
2614 return true;
2615 }else{
2616 $("#purchase_button").prop("disabled", true);
2617 $("#back_button").prop("disabled", true);
2618 return false;
2619 }
2620 });
2621
2622 })(jQuery);
2623 </script>
2624 <?php
2625 }
2626
2627 usces_states_form_js();
2628 $js = apply_filters( 'usces_filter_shop_foot_js', ob_get_contents() );
2629 ob_end_clean();
2630 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2631 echo $js;
2632 }
2633
2634 public function admin_head() {
2635 global $wp_version;
2636 $wcex_str = '';
2637 $wcex = usces_get_wcex();
2638 foreach ( (array) $wcex as $key => $values ) {
2639 $wcex_str .= "'" . esc_js( $key ) . '-' . esc_js( $values['version'] ) . "', ";
2640 }
2641 $wcex_str = rtrim( $wcex_str, ', ' );
2642 $theme_ob = wp_get_theme();
2643 if ( $theme_ob ) {
2644 $theme = array(
2645 'Name' => esc_js( $theme_ob->get( 'Name' ) ),
2646 'Version' => esc_js( $theme_ob->get( 'Version' ) ),
2647 );
2648 } else {
2649 $theme = array( 'Name' => '', 'Version' => '' );
2650 }
2651 $message = usces_get_admin_script_message();
2652 ?>
2653 <link href="<?php echo USCES_PLUGIN_URL; ?>/css/admin_style.css" rel="stylesheet" type="text/css" media="all" />
2654 <script type='text/javascript'>
2655 /* <![CDATA[ */
2656 uscesL10n = {
2657 <?php echo apply_filters( 'usces_filter_admin_uscesL10n', null ); ?>
2658 'requestFile': "<?php echo site_url(); ?>/wp-admin/admin-ajax.php",
2659 'USCES_PLUGIN_URL': "<?php echo USCES_PLUGIN_URL; ?>",
2660 'version': "<?php echo USCES_VERSION; ?>",
2661 'wcid': "<?php echo get_option( 'usces_wcid' ); ?>",
2662 'locale': '<?php echo get_locale(); ?>',
2663 'cart_number': "<?php echo get_option( 'usces_cart_number' ); ?>",
2664 'purchase_limit': "<?php echo esc_js( $this->options['purchase_limit'] ); ?>",
2665 'point_rate': "<?php echo esc_js( $this->options['point_rate'] ); ?>",
2666 'shipping_rule': "<?php echo esc_js( $this->options['shipping_rule'] ); ?>",
2667 'theme': "<?php echo esc_html( $theme['Name'] . '-' . $theme['Version'] ); ?>",
2668 'wcex': new Array( <?php wel_esc_script_e( $wcex_str ); ?> ),
2669 'message': new Array( <?php wel_esc_script_e( $message ); ?> ),
2670 'now_loading': "<?php _e( 'now loading', 'usces' ); ?>"
2671 };
2672 /* ]]> */
2673 </script>
2674 <script type='text/javascript' src='<?php echo USCES_PLUGIN_URL; ?>/js/usces_admin.js?ver=<?php echo USCES_VERSION; ?>'></script>
2675 <?php
2676 if ( 'edit' == $this->action_status || 'editpost' == $this->action_status ) {
2677 ?>
2678 <link rel='stylesheet' href='<?php echo site_url(); ?>/wp-includes/js/thickbox/thickbox.css' type='text/css' media='all' />
2679 <?php
2680 }
2681 if ( isset( $_REQUEST['page'] ) ) {
2682 switch ( $_REQUEST['page'] ) {
2683 case 'usces_initial':
2684 $cod_type = ( 'change' == $this->options['cod_type'] ) ? 'change' : 'fix';
2685 ?>
2686 <script type='text/javascript'>
2687 /* <![CDATA[ */
2688 usces_ini = {
2689 'cod_type': "<?php echo esc_js( $cod_type ); ?>",
2690 'cod_type_fix': "<?php echo esc_js( __( 'Fixation C.O.D.', 'usces' ) ); ?>",
2691 'cod_type_change': "<?php echo esc_js( __( 'Variable C.O.D.', 'usces' ) ); ?>",
2692 'cod_unit': "<?php echo esc_js( __( 'dollars', 'usces' ) ); ?>",
2693 'cod_failure': "<?php echo esc_js( __( 'failure in update', 'usces' ) ); ?>",
2694 'cod_updated': "<?php echo esc_js( __( 'options are updated', 'usces' ) ); ?>",
2695 'cod_limit': "<?php echo esc_js( __( 'A value of the amount of upper limit is incorrect.', 'usces' ) ); ?>",
2696 'cod_label_close': "<?php echo esc_js( __( 'Close', 'usces' ) ); ?>",
2697 'cod_label_update': "<?php echo esc_js( __( 'Update', 'usces' ) ); ?>"
2698 };
2699 /* ]]> */
2700 </script>
2701 <?php
2702 break;
2703 case 'usces_itemnew':
2704 case 'usces_itemedit':
2705 ?>
2706 <style type="text/css">
2707 <!--
2708 #usces_mess {
2709 color: #FF0000;
2710 font-weight: bold;
2711 }
2712 -->
2713 </style>
2714 <?php
2715 break;
2716 }
2717 }
2718
2719 if ( is_admin() && ( ( isset( $_GET['order_action'] ) && 'newpost' == $_GET['order_action'] )
2720 || ( isset( $_GET['page'] ) && 'usces_ordernew' == $_GET['page'] )
2721 || ( isset( $_GET['order_action'] ) && 'edit' == $_GET['order_action'] )
2722 || ( isset( $_GET['order_action'] ) && 'editpost' == $_GET['order_action'] )
2723 || ( isset( $_GET['page'] ) && 'usces_membernew' == $_GET['page'] )
2724 || ( isset( $_GET['member_action'] ) && 'edit' == $_GET['member_action'] )
2725 || ( isset( $_GET['member_action'] ) && 'editpost' == $_GET['member_action'] ) ) ) :
2726 switch ( $_GET['page'] ) {
2727 case 'usces_ordernew':
2728 case 'usces_orderlist':
2729 $admin_page = 'order';
2730 break;
2731 case 'usces_membernew':
2732 case 'usces_memberlist':
2733 $admin_page = 'member';
2734 break;
2735 }
2736 ?>
2737 <script type='text/javascript'>
2738 jQuery(function($) {
2739 uscesForm = {
2740 settings: {
2741 url: uscesL10n.requestFile,
2742 type: 'POST',
2743 cache: false
2744 },
2745
2746 changeStates : function( country, type ) {
2747 var s = this.settings;
2748 s.data = "action=change_states_ajax&country=" + country;
2749 $.ajax( s ).done(function(data, dataType){
2750 if( 'error' == data ){
2751 alert('error');
2752 }else{
2753 $("select#" + type + "_pref").html( data );
2754 if( customercountry == country && 'customer' == type ){
2755 $("#" + type + "_pref").prop({selectedIndex:customerstate});
2756 }else if( deliverycountry == country && 'delivery' == type ){
2757 $("#" + type + "_pref").prop({selectedIndex:deliverystate});
2758 }else if( customercountry == country && 'member' == type ){
2759 $("#" + type + "_pref").prop({selectedIndex:customerstate});
2760 }
2761 }
2762 }).fail(function(msg){
2763 alert("error");
2764 });
2765 return false;
2766 },
2767
2768 isNum : function (num) {
2769 if (num.match(/[^0-9]/g)) {
2770 return false;
2771 }
2772 return true;
2773 }
2774 };
2775 <?php
2776 if ( 'order' == $admin_page ) {
2777 ?>
2778 if( undefined != $("#customer_pref").get(0) && undefined != $("#delivery_country").get(0) ) {
2779 var customerstate = $("#customer_pref").get(0).selectedIndex;
2780 var customercountry = $("#customer_country").val();
2781 var deliverystate = $("#delivery_pref").get(0).selectedIndex;
2782 var deliverycountry = $("#delivery_country").val();
2783
2784 $("#customer_country").change(function () {
2785 var country = $("#customer_country option:selected").val();
2786 uscesForm.changeStates( country, 'customer' );
2787 });
2788 $("#delivery_country").change(function () {
2789 var country = $("#delivery_country option:selected").val();
2790 uscesForm.changeStates( country, 'delivery' );
2791 });
2792 }
2793 <?php
2794 } elseif ( 'member' == $admin_page ) {
2795 ?>
2796 if( undefined != $("#member_pref").get(0) ) {
2797 var customerstate = $("#member_pref").get(0).selectedIndex;
2798 var customercountry = $("#member_country").val();
2799 var deliverystate = '';
2800 var deliverycountry = '';
2801
2802 $("#member_country").change(function () {
2803 var country = $("#member_country option:selected").val();
2804 uscesForm.changeStates( country, 'member' );
2805 });
2806 }
2807 <?php
2808 }
2809 ?>
2810 });
2811 </script>
2812 <?php
2813 endif;
2814 }
2815
2816 /**
2817 * Main Process.
2818 */
2819 public function main() {
2820 global $wpdb, $wp_locale, $wp_version, $post_ID;
2821 global $wp_query, $usces_action, $post, $action, $editing;
2822
2823 update_option( 'usces_shipping_rule', apply_filters( 'usces_filter_shipping_rule', get_option( 'usces_shipping_rule' ) ) );
2824 $this->shipping_rule = get_option( 'usces_shipping_rule' );
2825
2826 if ( ! is_admin() ) {
2827 $this->usces_cookie();
2828 } else {
2829 $this->user_level = usces_get_admin_user_level();
2830 }
2831 $this->make_url();
2832
2833 add_filter( 'cron_schedules', 'usces_schedules_intervals' );
2834 add_action( 'wp', 'usces_wevent' );
2835 do_action( 'usces_main' );
2836 $this->update_table();
2837
2838 require_once USCES_PLUGIN_DIR . '/classes/cart.class.php';
2839 $this->cart = new usces_cart();
2840
2841 do_action( 'usces_after_cart_instant' );
2842
2843 if ( isset( $_REQUEST['page'] ) && 'usces_itemedit' == $_REQUEST['page'] && isset( $_REQUEST['action'] ) && 'duplicate' == $_REQUEST['action'] ) {
2844 $post_id = (int) $_GET['post'];
2845 $new_id = usces_item_duplicate( $post_id );
2846 $ref = isset( $_REQUEST['usces_referer'] ) ? urlencode( esc_url( $_REQUEST['usces_referer'] ) ) : '';
2847 $url = USCES_ADMIN_URL . '?page=usces_itemedit&action=edit&post=' . $new_id . '&usces_referer=' . $ref;
2848 wp_redirect( $url );
2849 exit;
2850 } elseif ( isset( $_REQUEST['page'] ) && 'usces_itemedit' == $_REQUEST['page'] && isset( $_REQUEST['action'] ) && 'itemcsv' == $_REQUEST['action'] ) {
2851 // $filename = usces_item_uploadcsv();
2852 // $mode = ( isset( $_REQUEST['upload_mode'] ) ) ? $_REQUEST['upload_mode'] : 'all';
2853 // $url = USCES_ADMIN_URL . '?page=usces_itemedit&usces_status=none&usces_message=&action=upload_register&mode=' . $mode . '&regfile=' . $filename;
2854 // wp_redirect( $url );
2855 // exit;
2856 }
2857
2858 $this->ad_controller();
2859
2860 if ( isset( $_GET['page'] ) && 'usces_itemnew' == $_GET['page'] ) {
2861 $itemnew = 'new';
2862 } else {
2863 $itemnew = '';
2864 }
2865
2866 wp_enqueue_script( 'jquery' );
2867
2868 if ( is_admin() && isset( $_REQUEST['page'] ) && ( ( isset( $_REQUEST['action'] ) && 'edit' == $_REQUEST['action'] ) || 'new' == $itemnew || ( isset( $_REQUEST['action'] ) && 'editpost' == $_REQUEST['action'] ) ) ) {
2869
2870 if ( isset( $_REQUEST['action'] ) && 'editpost' != $_REQUEST['action'] && 'new' == $itemnew ) {
2871 if ( version_compare( $wp_version, '3.0-beta', '>' ) ) {
2872 if ( ! isset( $_GET['post_type'] ) ) {
2873 $post_type = 'post';
2874 } elseif ( in_array( $_GET['post_type'], get_post_types( array( 'public' => true ) ) ) ) {
2875 $post_type = $_GET['post_type'];
2876 } else {
2877 wp_die( __( 'Invalid post type' ) );
2878 }
2879 $post_type_object = get_post_type_object( $post_type );
2880 $editing = true;
2881 $post = $this->get_default_post_to_edit30( $post_type, true );
2882 $post_ID = $post->ID;
2883 } else {
2884 $post = $this->get_default_post_to_edit();
2885 }
2886 } else {
2887 if ( version_compare( $wp_version, '3.0-beta', '>' ) ) {
2888 if ( isset( $_GET['post'] ) ) {
2889 $post_id = (int) $_GET['post'];
2890 } elseif ( isset( $_POST['post_ID'] ) ) {
2891 $post_id = (int) $_POST['post_ID'];
2892 } else {
2893 $post_id = 0;
2894 }
2895 $post_ID = $post_id;
2896 $post = null;
2897 $post_type_object = null;
2898 $post_type = null;
2899 if ( $post_id ) {
2900 $product = wel_get_product( $post_id );
2901 $post = $product['_pst'];
2902 if ( $post ) {
2903 $post_type_object = get_post_type_object( $post->post_type );
2904 if ( $post_type_object ) {
2905 $post_type = $post->post_type;
2906 if ( ! isset( $current_screen ) ) {
2907 $current_screen = new stdClass();
2908 }
2909 $current_screen->post_type = $post->post_type;
2910 $current_screen->id = $current_screen->post_type;
2911 }
2912 }
2913 } elseif ( isset( $_POST['post_type'] ) ) {
2914 $post_type_object = get_post_type_object( $_POST['post_type'] );
2915 if ( $post_type_object ) {
2916 $post_type = $post_type_object->name;
2917 $current_screen->post_type = $post_type;
2918 $current_screen->id = $current_screen->post_type;
2919 }
2920 }
2921 } else {
2922 if ( isset( $_GET['post'] ) ) {
2923 $post_ID = (int) $_GET['post'];
2924 $product = wel_get_product( $post_ID );
2925 $post = $product['_pst'];
2926 } else {
2927 $post_ID = isset( $_REQUEST['post_ID'] ) ? (int) $_REQUEST['post_ID'] : 0;
2928 if ( ! empty( $post_ID ) ) {
2929 $product = wel_get_product( $post_ID );
2930 $post = $product['_pst'];
2931 }
2932 }
2933 }
2934 }
2935
2936 $editing = true;
2937 wp_enqueue_script( 'autosave' );
2938 wp_enqueue_script( 'post' );
2939 add_thickbox();
2940 wp_enqueue_script( 'media-upload' );
2941 wp_enqueue_script( 'word-count' );
2942 wp_enqueue_script( 'admin-comments' );
2943
2944 if ( version_compare( $wp_version, '3.3', '<' ) ) {
2945 add_action( 'admin_print_footer_scripts', 'wp_tiny_mce', 25 );
2946 }
2947 wp_enqueue_script( 'quicktags' );
2948 }
2949
2950 if ( is_admin() && isset( $_REQUEST['page'] ) ) {
2951
2952 wp_enqueue_script( 'jquery-color' );
2953
2954 switch ( $_REQUEST['page'] ) {
2955 case 'usces_initial':
2956 $js = USCES_FRONT_PLUGIN_URL . '/js/usces_initial.js';
2957 wp_enqueue_script( 'usces_initial.js', $js, array( 'jquery-ui-dialog', 'jquery-ui-sortable' ) );
2958 break;
2959 case 'usces_settlement':
2960 wp_enqueue_script( 'jquery-ui-tabs', array( 'jquery-ui-core' ) );
2961 $jquery_cookie_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/jquery-cookie.js';
2962 wp_enqueue_script( 'jquery-cookie', $jquery_cookie_url, array( 'jquery' ) );
2963 $jquery_color_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/color/jscolor.js';
2964 wp_enqueue_script( 'jquery-jscolor', $jquery_color_url, array( 'jquery-color' ) );
2965 wp_enqueue_script( 'jquery-ui-sortable' );
2966 wp_enqueue_script( 'jquery-ui-dialog' );
2967 break;
2968 case 'usces_cart':
2969 wp_enqueue_script( 'jquery-ui-tabs', array( 'jquery-ui-core' ) );
2970 $jquery_cookie_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/jquery-cookie.js';
2971 wp_enqueue_script( 'jquery-cookie', $jquery_cookie_url, array( 'jquery' ) );
2972 break;
2973 case 'usces_member':
2974 wp_enqueue_script( 'jquery-ui-tabs', array( 'jquery-ui-core' ) );
2975 $jquery_cookie_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/jquery-cookie.js';
2976 wp_enqueue_script( 'jquery-cookie', $jquery_cookie_url, array( 'jquery' ) );
2977 break;
2978 case 'usces_orderlist':
2979 case 'usces_ordernew':
2980 wp_enqueue_script( 'jquery-ui-datepicker' );
2981 wp_enqueue_script( 'jquery-ui-dialog' );
2982 break;
2983 case 'usces_memberlist':
2984 wp_enqueue_script( 'jquery-ui-dialog' );
2985 break;
2986 case 'usces_itemnew':
2987 wp_enqueue_script( 'jquery-ui-sortable' );
2988 break;
2989 case 'usces_itemedit':
2990 $jquery_cookie_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/jquery-cookie.js';
2991 wp_enqueue_script( 'jquery-cookie', $jquery_cookie_url, array( 'jquery' ) );
2992 if ( isset( $_REQUEST['action'] ) && 'upload_register' == $_REQUEST['action'] ) {
2993 // $upload_registerUrl = USCES_FRONT_PLUGIN_URL . '/js/usces-item-upload.js';
2994 // wp_enqueue_script( 'upload_register', $upload_registerUrl, array( 'jquery' ), USCES_VERSION, true );
2995 // @ob_end_clean();
2996 // ob_start();
2997 } else {
2998 wp_enqueue_script( 'jquery-ui-sortable' );
2999 wp_enqueue_script( 'jquery-ui-dialog' );
3000 }
3001 break;
3002 case 'usces_delivery':
3003 wp_enqueue_script( 'jquery-ui-tabs', array( 'jquery-ui-core' ) );
3004 $jquery_cookie_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/jquery-cookie.js';
3005 wp_enqueue_script( 'jquery-cookie', $jquery_cookie_url, array( 'jquery' ) );
3006 break;
3007 case 'usces_system':
3008 wp_enqueue_script( 'jquery-ui-tabs', array( 'jquery-ui-core' ) );
3009 $jquery_cookie_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/jquery-cookie.js';
3010 wp_enqueue_script( 'jquery-cookie', $jquery_cookie_url, array( 'jquery' ) );
3011 break;
3012 case 'usces_mail':
3013 wp_enqueue_script( 'jquery-ui-tabs', array( 'jquery-ui-core' ) );
3014 $jquery_cookie_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/jquery-cookie.js';
3015 wp_enqueue_script( 'jquery-cookie', $jquery_cookie_url, array( 'jquery' ) );
3016 break;
3017 }
3018 }
3019
3020 if ( isset( $_REQUEST['order_action'] ) && 'pdfout' == $_REQUEST['order_action'] ) {
3021 check_admin_referer( 'order_edit', 'wc_nonce' );
3022
3023 $oid = filter_input( INPUT_GET, 'order_id' );
3024 if ( ! is_user_logged_in() ) {
3025 $this->get_current_member();
3026 $mid = $this->current_member['id'];
3027 if ( 0 === (int) $mid || ! $this->is_order( $mid, $oid ) ) {
3028 die( 'No permission' );
3029 }
3030 }
3031 if ( ( isset( $this->options['tax_display'] ) && 'activate' == $this->options['tax_display'] ) && usces_is_reduced_taxrate( $oid ) ) {
3032 require_once( apply_filters( 'usces_filter_orderpdf_path_ex', USCES_PLUGIN_DIR . '/includes/order_print_ex.php' ) );
3033 } else {
3034 require_once( apply_filters( 'usces_filter_orderpdf_path', USCES_PLUGIN_DIR . '/includes/order_print.php' ) );
3035 }
3036 }
3037
3038 if ( ! empty( $this->settlement_notice ) &&
3039 ( 1 === (int) $this->options['system']['settlement_notice'] || defined( 'WCEX_DLSELLER' ) || defined( 'WCEX_AUTO_DELIVERY' ) ) ) {
3040 add_action( 'admin_notices', 'usces_display_settlement_notice' );
3041 }
3042
3043 do_action( 'usces_after_main' );
3044 }
3045
3046 public function stripslashes_deep_post( $array ) {
3047 $res = array();
3048 foreach ( $array as $key => $value ) {
3049 $key = stripslashes( $key );
3050 if ( is_array( $value ) ) {
3051 $value = $this->stripslashes_deep_post( $value );
3052 } else {
3053 $value = is_null( $value ) ? $value : usces_erase_emoji( stripslashes( $value ) );
3054 }
3055 $res[ $key ] = $value;
3056 }
3057 return $res;
3058 }
3059
3060 public function make_url() {
3061 $permalink_structure = get_option( 'permalink_structure' );
3062 if ( $this->use_ssl ) {
3063 if ( $permalink_structure ) {
3064 $this->delim = '&';
3065 $home_perse = parse_url( get_option( 'home' ) );
3066 $home_perse_path = isset( $home_perse['path'] ) ? $home_perse['path'] : '';
3067 $home_path = $home_perse['host'] . $home_perse_path;
3068 $ssl_perse = parse_url( $this->options['ssl_url'] );
3069 $ssl_perse_path = isset( $ssl_perse['path'] ) ? $ssl_perse['path'] : '';
3070 $ssl_path = $ssl_perse['host'] . $ssl_perse_path;
3071 if ( $home_perse_path != $ssl_perse_path ) {
3072 if ( ! defined( 'USCES_CUSTOMER_URL' ) ) {
3073 define( 'USCES_CUSTOMER_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_CART_NUMBER . '&customerinfo=1' );
3074 }
3075 if ( ! defined( 'USCES_CART_URL' ) ) {
3076 define( 'USCES_CART_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_CART_NUMBER );
3077 }
3078 if ( ! defined( 'USCES_LOSTMEMBERPASSWORD_URL' ) ) {
3079 define( 'USCES_LOSTMEMBERPASSWORD_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=lostmemberpassword' );
3080 }
3081 if ( ! defined( 'USCES_NEWMEMBER_URL' ) ) {
3082 define( 'USCES_NEWMEMBER_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=newmember' );
3083 }
3084 if ( ! defined( 'USCES_LOGIN_URL' ) ) {
3085 define( 'USCES_LOGIN_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=login' );
3086 }
3087 if ( ! defined( 'USCES_LOGOUT_URL' ) ) {
3088 define( 'USCES_LOGOUT_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=logout' );
3089 }
3090 if ( ! defined( 'USCES_MEMBER_URL' ) ) {
3091 define( 'USCES_MEMBER_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_MEMBER_NUMBER );
3092 }
3093 $inquiry_url = empty( $this->options['inquiry_id'] ) ? '' : $this->options['ssl_url'] . '/index.php?page_id=' . $this->options['inquiry_id'];
3094 if ( ! defined( 'USCES_INQUIRY_URL' ) ) {
3095 define( 'USCES_INQUIRY_URL', $inquiry_url );
3096 }
3097 if ( ! defined( 'USCES_CART_NONSESSION_URL' ) ) {
3098 define( 'USCES_CART_NONSESSION_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_CART_NUMBER );
3099 }
3100 if ( ! defined( 'USCES_PAYPAL_NOTIFY_URL' ) ) {
3101 define( 'USCES_PAYPAL_NOTIFY_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_CART_NUMBER . '&acting=paypal_ipn' );
3102 }
3103 } else {
3104 $ssl_plink_cart = str_replace( 'http://','https://', str_replace( $home_path, $ssl_path, get_page_link( USCES_CART_NUMBER ) ) );
3105 $ssl_plink_member = str_replace( 'http://','https://', str_replace( $home_path, $ssl_path, get_page_link( USCES_MEMBER_NUMBER ) ) );
3106 if ( ! defined( 'USCES_CUSTOMER_URL' ) ) {
3107 define( 'USCES_CUSTOMER_URL', $ssl_plink_cart . '?customerinfo=1' );
3108 }
3109 if ( ! defined( 'USCES_CART_URL' ) ) {
3110 define( 'USCES_CART_URL', $ssl_plink_cart );
3111 }
3112 if ( ! defined( 'USCES_LOSTMEMBERPASSWORD_URL' ) ) {
3113 define( 'USCES_LOSTMEMBERPASSWORD_URL', $ssl_plink_member . '?usces_page=lostmemberpassword' );
3114 }
3115 if ( ! defined( 'USCES_NEWMEMBER_URL' ) ) {
3116 define( 'USCES_NEWMEMBER_URL', $ssl_plink_member . '?usces_page=newmember' );
3117 }
3118 if ( ! defined( 'USCES_LOGIN_URL' ) ) {
3119 define( 'USCES_LOGIN_URL', $ssl_plink_member . '?usces_page=login' );
3120 }
3121 if ( ! defined( 'USCES_LOGOUT_URL' ) ) {
3122 define( 'USCES_LOGOUT_URL', $ssl_plink_member . '?usces_page=logout' );
3123 }
3124 if ( ! defined( 'USCES_MEMBER_URL' ) ) {
3125 define( 'USCES_MEMBER_URL', $ssl_plink_member );
3126 }
3127 if ( ! isset( $this->options['inquiry_id'] ) || ! ( (int) $this->options['inquiry_id'] ) ) {
3128 $inquiry_url = get_home_url();
3129 } else {
3130 $ssl_plink_inquiry = str_replace( 'http://', 'https://', str_replace( $home_path, $ssl_path, get_page_link( $this->options['inquiry_id'] ) ) );
3131 $inquiry_url = empty( $this->options['inquiry_id'] ) ? '' : $ssl_plink_inquiry;
3132 }
3133 if ( ! defined( 'USCES_INQUIRY_URL' ) ) {
3134 define( 'USCES_INQUIRY_URL', $inquiry_url );
3135 }
3136 if ( ! defined( 'USCES_CART_NONSESSION_URL' ) ) {
3137 define( 'USCES_CART_NONSESSION_URL', $ssl_plink_cart );
3138 }
3139 if ( ! defined( 'USCES_PAYPAL_NOTIFY_URL' ) ) {
3140 define( 'USCES_PAYPAL_NOTIFY_URL', $ssl_plink_cart . '?acting=paypal_ipn' );
3141 }
3142 }
3143 } else {
3144 $this->delim = '&';
3145 if ( ! defined( 'USCES_CUSTOMER_URL' ) ) {
3146 define( 'USCES_CUSTOMER_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_CART_NUMBER . '&customerinfo=1' );
3147 }
3148 if ( ! defined( 'USCES_CART_URL' ) ) {
3149 define( 'USCES_CART_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_CART_NUMBER );
3150 }
3151 if ( ! defined( 'USCES_LOSTMEMBERPASSWORD_URL' ) ) {
3152 define( 'USCES_LOSTMEMBERPASSWORD_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=lostmemberpassword' );
3153 }
3154 if ( ! defined( 'USCES_NEWMEMBER_URL' ) ) {
3155 define( 'USCES_NEWMEMBER_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=newmember' );
3156 }
3157 if ( ! defined( 'USCES_LOGIN_URL' ) ) {
3158 define( 'USCES_LOGIN_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=login' );
3159 }
3160 if ( ! defined( 'USCES_LOGOUT_URL' ) ) {
3161 define( 'USCES_LOGOUT_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=logout' );
3162 }
3163 if ( ! defined( 'USCES_MEMBER_URL' ) ) {
3164 define( 'USCES_MEMBER_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_MEMBER_NUMBER );
3165 }
3166 $inquiry_url = empty( $this->options['inquiry_id'] ) ? '' : $this->options['ssl_url'] . '/?page_id=' . $this->options['inquiry_id'];
3167 if ( ! defined( 'USCES_INQUIRY_URL' ) ) {
3168 define( 'USCES_INQUIRY_URL', $inquiry_url );
3169 }
3170 if ( ! defined( 'USCES_CART_NONSESSION_URL' ) ) {
3171 define( 'USCES_CART_NONSESSION_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_CART_NUMBER );
3172 }
3173 if ( ! defined( 'USCES_PAYPAL_NOTIFY_URL' ) ) {
3174 define( 'USCES_PAYPAL_NOTIFY_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_CART_NUMBER . '&acting=paypal_ipn' );
3175 }
3176 }
3177 if ( ! is_admin() ) {
3178 add_filter( 'home_url', array( $this, 'usces_ssl_page_link' ) );
3179 add_filter( 'wp_get_attachment_url', array( $this, 'usces_ssl_attachment_link' ) );
3180 add_filter( 'icon_dir_uri', array( $this, 'usces_ssl_icon_dir_uri' ) );
3181 add_filter( 'stylesheet_directory_uri', array( $this, 'usces_ssl_contents_link' ) );
3182 add_filter( 'template_directory_uri', array( $this, 'usces_ssl_contents_link' ) );
3183 add_filter( 'script_loader_src', array( $this, 'usces_ssl_script_link' ) );
3184 add_filter( 'style_loader_src', array( $this, 'usces_ssl_script_link' ) );
3185 }
3186 } else {
3187 if ( $permalink_structure ) {
3188 $this->delim = '?';
3189 if ( ! defined( 'USCES_CUSTOMER_URL' ) ) {
3190 define( 'USCES_CUSTOMER_URL', get_page_link( USCES_CART_NUMBER ) . '?customerinfo=1' );
3191 }
3192 if ( ! defined( 'USCES_CART_URL' ) ) {
3193 define( 'USCES_CART_URL', get_page_link( USCES_CART_NUMBER ) );
3194 }
3195 if ( ! defined( 'USCES_LOSTMEMBERPASSWORD_URL' ) ) {
3196 define( 'USCES_LOSTMEMBERPASSWORD_URL', get_page_link( USCES_MEMBER_NUMBER ) . '?usces_page=lostmemberpassword' );
3197 }
3198 if ( ! defined( 'USCES_NEWMEMBER_URL' ) ) {
3199 define( 'USCES_NEWMEMBER_URL', get_page_link( USCES_MEMBER_NUMBER ) . '?usces_page=newmember' );
3200 }
3201 if ( ! defined( 'USCES_LOGIN_URL' ) ) {
3202 define( 'USCES_LOGIN_URL', get_page_link( USCES_MEMBER_NUMBER ) . '?usces_page=login' );
3203 }
3204 if ( ! defined( 'USCES_LOGOUT_URL' ) ) {
3205 define( 'USCES_LOGOUT_URL', get_page_link( USCES_MEMBER_NUMBER ) . '?usces_page=logout' );
3206 }
3207 if ( ! defined( 'USCES_MEMBER_URL' ) ) {
3208 define( 'USCES_MEMBER_URL', get_page_link( USCES_MEMBER_NUMBER ) );
3209 }
3210 $inquiry_url = ( ! isset( $this->options['inquiry_id'] ) || ! ( (int) $this->options['inquiry_id'] ) ) ? get_home_url() : get_page_link( $this->options['inquiry_id'] );
3211 if ( ! defined( 'USCES_INQUIRY_URL' ) ) {
3212 define( 'USCES_INQUIRY_URL', $inquiry_url );
3213 }
3214 if ( ! defined( 'USCES_CART_NONSESSION_URL' ) ) {
3215 define( 'USCES_CART_NONSESSION_URL', get_page_link( USCES_CART_NUMBER ) );
3216 }
3217 if ( ! defined( 'USCES_PAYPAL_NOTIFY_URL' ) ) {
3218 define( 'USCES_PAYPAL_NOTIFY_URL', get_page_link( USCES_CART_NUMBER ) . '?acting=paypal_ipn' );
3219 }
3220 } else {
3221 $this->delim = '&';
3222 if ( ! defined( 'USCES_CUSTOMER_URL' ) ) {
3223 define( 'USCES_CUSTOMER_URL', get_option( 'home' ) . '/?page_id=' . USCES_CART_NUMBER . '&customerinfo=1' );
3224 }
3225 if ( ! defined( 'USCES_CART_URL' ) ) {
3226 define( 'USCES_CART_URL', get_option( 'home' ) . '/?page_id=' . USCES_CART_NUMBER );
3227 }
3228 if ( ! defined( 'USCES_LOSTMEMBERPASSWORD_URL' ) ) {
3229 define( 'USCES_LOSTMEMBERPASSWORD_URL', get_option( 'home' ) . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=lostmemberpassword' );
3230 }
3231 if ( ! defined( 'USCES_NEWMEMBER_URL' ) ) {
3232 define( 'USCES_NEWMEMBER_URL', get_option( 'home' ) . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=newmember' );
3233 }
3234 if ( ! defined( 'USCES_LOGIN_URL' ) ) {
3235 define( 'USCES_LOGIN_URL', get_option( 'home' ) . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=login' );
3236 }
3237 if ( ! defined( 'USCES_LOGOUT_URL' ) ) {
3238 define( 'USCES_LOGOUT_URL', get_option( 'home' ) . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=logout' );
3239 }
3240 if ( ! defined( 'USCES_CART_NONSESSION_URL' ) ) {
3241 define( 'USCES_CART_NONSESSION_URL', get_option( 'home' ) . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=logout' );
3242 }
3243 if ( ! defined( 'USCES_MEMBER_URL' ) ) {
3244 define( 'USCES_MEMBER_URL', get_option( 'home' ) . '/?page_id=' . USCES_MEMBER_NUMBER );
3245 }
3246 $inquiry_url = empty( $this->options['inquiry_id'] ) ? '' : get_option( 'home' ) . '/?page_id=' . $this->options['inquiry_id'];
3247 if ( ! defined( 'USCES_INQUIRY_URL' ) ) {
3248 define( 'USCES_INQUIRY_URL', $inquiry_url );
3249 }
3250 if ( ! defined( 'USCES_CART_NONSESSION_URL' ) ) {
3251 define( 'USCES_CART_NONSESSION_URL', get_option( 'home' ) . '/?page_id=' . USCES_CART_NUMBER );
3252 }
3253 if ( ! defined( 'USCES_PAYPAL_NOTIFY_URL' ) ) {
3254 define( 'USCES_PAYPAL_NOTIFY_URL', get_option( 'home' ) . '/?page_id=' . USCES_CART_NUMBER . '&acting=paypal_ipn' );
3255 }
3256 }
3257 }
3258 }
3259
3260 public function regist_action() {
3261 usces_register_action( 'inCart', 'post', 'inCart', null, 'inCart' );
3262 usces_register_action( 'upButton', 'post', 'upButton', null, 'upButton' );
3263 usces_register_action( 'delButton', 'post', 'delButton', null, 'delButton' );
3264 usces_register_action( 'backCart', 'post', 'backCart', null, 'backCart' );
3265 usces_register_action( 'customerinfo', 'request', 'customerinfo', null, 'customerinfo' );
3266 usces_register_action( 'backCustomer', 'post', 'backCustomer', null, 'backCustomer' );
3267 usces_register_action( 'customerlogin', 'post', 'customerlogin', null, 'customerlogin' );
3268 usces_register_action( 'reganddeliveryinfo', 'post', 'reganddeliveryinfo', null, 'reganddeliveryinfo' );
3269 usces_register_action( 'deliveryinfo', 'post', 'deliveryinfo', null, 'deliveryinfo' );
3270 usces_register_action( 'backDelivery', 'request', 'backDelivery', null, 'backDelivery' );
3271 usces_register_action( 'confirm', 'request', 'confirm', null, 'confirm' );
3272 usces_register_action( 'use_point', 'post', 'use_point', null, 'use_point' );
3273 usces_register_action( 'backConfirm', 'post', 'backConfirm', null, 'backConfirm' );
3274 usces_register_action( 'purchase', 'request', 'purchase', null, 'purchase' );
3275 usces_register_action( 'acting_return', 'request', 'acting_return', null, 'acting_return' );
3276 usces_register_action( 'settlement_epsilon', 'request', 'settlement', 'epsilon', 'settlement_epsilon' );
3277 usces_register_action( 'inquiry_button', 'post', 'inquiry_button', null, 'inquiry_button' );
3278 usces_register_action( 'member_login', 'request', 'member_login', null, 'member_login_page' );
3279 usces_register_action( 'regmember', 'request', 'regmember', null, 'regmember' );
3280 usces_register_action( 'editmember', 'request', 'editmember', null, 'editmember' );
3281 usces_register_action( 'deletemember', 'request', 'deletemember', null, 'deletemember' );
3282 usces_register_action( 'page_login', 'get', 'usces_page', 'login', 'member_login_page' );
3283 usces_register_action( 'page_logout', 'get', 'usces_page', 'logout', 'page_logout' );
3284 usces_register_action( 'page_lostmemberpassword', 'get', 'usces_page', 'lostmemberpassword', 'page_lostmemberpassword' );
3285 usces_register_action( 'lostpassword', 'request', 'lostpassword', null, 'lostpassword' );
3286 usces_register_action( 'uscesmode_changepassword', 'request', 'uscesmode', 'changepassword', 'uscesmode_changepassword' );
3287 usces_register_action( 'changepassword', 'request', 'changepassword', null, 'changepassword_page' );
3288 usces_register_action( 'page_newmember', 'get', 'usces_page', 'newmember', 'page_newmember' );
3289 usces_register_action( 'page_search_item', 'get', 'usces_page', 'search_item', 'page_search_item' );
3290 usces_register_action( 'front_ajax', 'post', 'usces_ajax_action', null, 'front_ajax' );
3291 }
3292
3293 public function ad_controller() {
3294 global $usces_action;
3295 ksort( $usces_action );
3296 if ( $this->is_maintenance() && ! is_user_logged_in() ) {
3297 $this->maintenance();
3298 } else {
3299 $action_array = array(
3300 'inCart', 'upButton', 'delButton', 'backCart', 'customerinfo', 'backCustomer',
3301 'customerlogin', 'reganddeliveryinfo', 'deliveryinfo', 'backDelivery', 'confirm', 'use_point',
3302 'backConfirm', 'purchase', 'acting_return', 'settlement_epsilon', 'inquiry_button', 'member_login',
3303 'regmember', 'editmember', 'deletemember', 'page_login', 'page_logout', 'page_lostmemberpassword', 'lostpassword',
3304 'uscesmode_changepassword', 'changepassword', 'page_newmember',
3305 'page_search_item', 'front_ajax',
3306 );
3307
3308 $action_array = apply_filters( 'usces_filter_action_array', $action_array );
3309
3310 $flg = 0;
3311 $res = true;
3312 foreach ( $usces_action as $handle => $action ) {
3313 extract( $action );
3314 switch ( $type ) {
3315 case 'post':
3316 if ( empty( $value ) ) {
3317 if ( isset( $_POST[ $key ] ) ) {
3318 if ( in_array( $handle, $action_array ) ) {
3319 $res = call_user_func( array( $this, $function ) );
3320 } else {
3321 $res = call_user_func( $function );
3322 }
3323 $flg = 1;
3324 }
3325 } else {
3326 if ( isset( $_POST[ $key ] ) && $_POST[ $key ] == $value ) {
3327 if ( in_array( $handle, $action_array ) ) {
3328 $res = call_user_func( array( $this, $function ) );
3329 } else {
3330 $res = call_user_func( $function );
3331 }
3332 $flg = 1;
3333 }
3334 }
3335 break;
3336 case 'get':
3337 if ( empty( $value ) ) {
3338 if ( isset( $_GET[ $key ] ) ) {
3339 if ( in_array( $handle, $action_array ) ) {
3340 $res = call_user_func( array( $this, $function ) );
3341 } else {
3342 $res = call_user_func( $function );
3343 }
3344 $flg = 1;
3345 }
3346 } else {
3347 if ( isset( $_GET[ $key ] ) && $_GET[ $key ] == $value ) {
3348 if ( in_array( $handle, $action_array ) ) {
3349 $res = call_user_func( array( $this, $function ) );
3350 } else {
3351 $res = call_user_func( $function );
3352 }
3353 $flg = 1;
3354 }
3355 }
3356 break;
3357 case 'request':
3358 if ( empty( $value ) ) {
3359 if ( isset( $_REQUEST[ $key ] ) ) {
3360 if ( in_array( $handle, $action_array ) ) {
3361 $res = call_user_func( array( $this, $function ) );
3362 } else {
3363 $res = call_user_func( $function );
3364 }
3365 $flg = 1;
3366 }
3367 } else {
3368 if ( isset( $_REQUEST[ $key ] ) && $_REQUEST[ $key ] == $value ) {
3369 if ( in_array( $handle, $action_array ) ) {
3370 $res = call_user_func( array( $this, $function ) );
3371 } else {
3372 $res = call_user_func( $function );
3373 }
3374 $flg = 1;
3375 }
3376 }
3377 break;
3378 }
3379 if ( ! $res ) {
3380 break;
3381 }
3382 }
3383 if ( ! $flg ) {
3384 $this->default_page();
3385 }
3386 }
3387 }
3388
3389 /**
3390 * Action function.
3391 */
3392 public function front_ajax() {
3393 switch ( $_POST['usces_ajax_action'] ) {
3394 case 'change_states':
3395 change_states_ajax();
3396 break;
3397 }
3398 do_action( 'usces_front_ajax' );
3399 }
3400
3401 public function maintenance() {
3402 $this->page = 'maintenance';
3403 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3404 }
3405
3406 public function inCart() {
3407 global $wp_query;
3408 $this->page = 'cart';
3409 $this->incart_check();
3410 $this->cart->inCart();
3411 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3412 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3413 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3414 }
3415
3416 public function upButton() {
3417 global $wp_query;
3418 $this->page = 'cart';
3419 $this->error_message = $this->cart->upCart();
3420 if ( empty( $this->error_message ) ) {
3421 $this->error_message = $this->zaiko_check();
3422 }
3423 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3424 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3425 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3426 }
3427
3428 public function delButton() {
3429 global $wp_query;
3430 $this->page = 'cart';
3431 $this->cart->del_row();
3432 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3433 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3434 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3435 }
3436
3437 public function backCart() {
3438 global $wp_query;
3439 $this->page = 'cart';
3440 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3441 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3442 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3443 }
3444
3445 public function customerinfo() {
3446 global $wp_query;
3447 if ( false === $this->cart->num_row() ) {
3448 header( 'location: ' . get_option( 'home' ) );
3449 exit;
3450 }
3451 do_action( 'usces_action_customerinfo' );
3452 $this->cart->entry();
3453 $this->error_message = $this->zaiko_check();
3454 $this->error_message = apply_filters( 'usces_filter_cart_check', $this->error_message );
3455 if ( WCUtils::is_blank( $this->error_message ) ) {
3456 if ( $this->is_member_logged_in() ) {
3457 $this->error_message = has_custom_customer_field_essential();
3458 $this->page = ( WCUtils::is_blank( $this->error_message ) ) ? 'delivery' : 'customer';
3459 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_delivery' );
3460 } else {
3461 $this->page = 'customer';
3462 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_customer' );
3463 }
3464 } else {
3465 $this->page = 'cart';
3466 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3467 }
3468 if ( ! $this->cart->is_order_condition() ) {
3469 $order_conditions = $this->get_condition();
3470 $this->cart->set_order_condition( $order_conditions );
3471 }
3472 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3473 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3474 }
3475
3476 public function backCustomer() {
3477 global $wp_query;
3478 if ( false === $this->cart->num_row() ) {
3479 header( 'location: ' . get_option( 'home' ) );
3480 exit;
3481 }
3482 $this->page = apply_filters( 'usces_filter_backCustomer_page', 'customer' );
3483 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3484 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_customer' );
3485 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3486 }
3487
3488 public function customerlogin() {
3489 global $wp_query;
3490 if ( false === $this->cart->num_row() ) {
3491 header( 'location: ' . get_option( 'home' ) );
3492 exit;
3493 }
3494 if ( 'member' == $this->member_login() ) {
3495 do_action( 'usces_action_member_customer_logined' );
3496 $this->cart->entry();
3497 // $this->error_message = has_custom_customer_field_essential();
3498 if ( WCUtils::is_blank( $this->error_message ) ) {
3499 $this->page = 'delivery';
3500 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_delivery' );
3501 } else {
3502 $this->page = 'customer';
3503 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_customer' );
3504 }
3505 } else {
3506 $this->cart->entry();
3507 $this->page = 'customer';
3508 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_customer' );
3509 }
3510 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3511 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3512 }
3513
3514 public function reganddeliveryinfo() {
3515 global $wp_query;
3516 if ( false === $this->cart->num_row() ) {
3517 header( 'location: ' . get_option( 'home' ) );
3518 exit;
3519 }
3520
3521 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
3522 if ( ! $this->verify_member_nonce( $nonce, 'post_member' ) && ! $this->is_member_logged_in() ) {
3523 die( 'Security check2' );
3524 }
3525 $check_verify_recaptcha = $this->verifyGoogleRecapcha();
3526 if ( $check_verify_recaptcha ) {
3527 $this->cart->entry();
3528 if ( empty( $_POST['member_regmode'] ) || 'editmemberfromcart' != $_POST['member_regmode'] ) {
3529 $_POST['member_regmode'] = 'newmemberfromcart';
3530 }
3531 $res = $this->regist_member();
3532 } else {
3533 // return back page register and show message.
3534 $this->error_message = apply_filters( 'usces_filter_check_verify_recaptcha_message', __( 'Failed to register member. Please try again.', 'usces' ), 'reganddeliveryinfo' );
3535 $res = trim( $_POST['member_regmode'] );
3536 }
3537
3538 if ( 'newcompletion' == $res ) {
3539 $this->page = 'delivery';
3540 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_delivery' );
3541 } elseif ( 'cartverifying' == $res ) {
3542 $this->page = 'cartverifying';
3543 } else {
3544 $this->page = 'customer';
3545 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_customer' );
3546 }
3547 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3548 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3549 }
3550
3551 public function deliveryinfo() {
3552 global $wp_query;
3553 if ( false === $this->cart->num_row() ) {
3554 header( 'location: ' . get_option( 'home' ) );
3555 exit;
3556 }
3557 $check_verify_recaptcha = $this->verifyGoogleRecapcha();
3558 if ( $check_verify_recaptcha ) {
3559 // continue process.
3560 $this->cart->entry();
3561 $this->error_message = $this->customer_check();
3562 } else {
3563 // return back page register and show message.
3564 $this->error_message = apply_filters( 'usces_filter_check_verify_recaptcha_message', __( 'Could not send successfully. Please try again.', 'usces' ), 'deliveryinfo' );
3565 }
3566
3567 if ( WCUtils::is_blank( $this->error_message ) ) {
3568 $this->page = 'delivery';
3569 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_delivery' );
3570 } else {
3571 $this->page = 'customer';
3572 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_customer' );
3573 }
3574 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3575 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3576 }
3577
3578 public function backDelivery() {
3579 global $wp_query;
3580 if ( false === $this->cart->num_row() ) {
3581 header( 'location: ' . get_option( 'home' ) );
3582 exit;
3583 }
3584 $this->page = 'delivery';
3585 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_delivery' );
3586 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3587 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3588 }
3589
3590 public function confirm() {
3591 global $wpdb, $wp_query;
3592 if ( false === $this->cart->num_row() ) {
3593 header( 'location: ' . get_option( 'home' ) );
3594 exit;
3595 }
3596
3597 $check_verify_recaptcha = $this->verifyGoogleRecapcha();
3598 if ( $check_verify_recaptcha ) {
3599 // continue process.
3600 $this->cart->entry();
3601 $this->error_message = $this->zaiko_check();
3602 } else {
3603 // return back page register and show message.
3604 $this->error_message = apply_filters( 'usces_filter_check_verify_recaptcha_message', __( 'Could not send successfully. Please try again.', 'usces' ), 'confirm' );
3605 }
3606
3607 if ( '' != $this->error_message ) {
3608 $this->page = 'cart';
3609 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3610 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3611 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3612 return;
3613 }
3614 /*
3615 $referrer = wp_get_referer();
3616 $site_url = parse_url( home_url(), PHP_URL_HOST );
3617 $referrer_host = parse_url( $referrer, PHP_URL_HOST );
3618 if ( false === $referrer || $referrer_host !== $site_url ) {
3619 $this->page = 'cart';
3620 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3621 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3622 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3623 return;
3624 }
3625 */
3626 $this->set_reserve_pre_order_id();
3627 if ( isset( $_POST['confirm'] ) ) {
3628 $this->error_message = $this->delivery_check();
3629 }
3630 $this->page = ( WCUtils::is_blank( $this->error_message ) ) ? 'confirm' : 'delivery';
3631 if ( WCUtils::is_blank( $this->error_message ) ) {
3632 if ( usces_is_member_system() && usces_is_member_system_point() && $this->is_member_logged_in() ) {
3633 $member_table = usces_get_tablename( 'usces_member' );
3634 $query = $wpdb->prepare( "SELECT mem_point FROM $member_table WHERE ID = %d", $_SESSION['usces_member']['ID'] );
3635 $mem_point = $wpdb->get_var( $query );
3636 $_SESSION['usces_member']['point'] = $mem_point;
3637 }
3638 $this->page = 'confirm';
3639 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_confirm' );
3640 } else {
3641 $this->page = apply_filters( 'usces_filter_delivery_check_error_page', 'delivery', $this->error_message );
3642 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_delivery' );
3643 }
3644 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3645 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3646 }
3647
3648 public function use_point() {
3649 global $wp_query, $usces;
3650 if ( ! isset( $_REQUEST['wc_nonce'] ) || ! $usces->verify_member_nonce( $_REQUEST['wc_nonce'], 'use_point' ) ) {
3651 die( 'Security check1' );
3652 }
3653
3654 $this->error_message = $this->point_check( $this->cart->get_entry() );
3655 if ( empty( $this->error_message ) ) {
3656 $this->cart->entry();
3657 }
3658 $this->page = 'confirm';
3659 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_confirm' );
3660 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3661 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3662 }
3663
3664 public function backConfirm() {
3665 global $wp_query;
3666 if ( false === $this->cart->num_row() ) {
3667 header( 'location: ' . get_option( 'home' ) );
3668 exit;
3669 }
3670 $this->page = 'confirm';
3671 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_confirm' );
3672 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3673 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3674 }
3675
3676 /**
3677 * Purchase
3678 */
3679 public function purchase() {
3680 global $wp_query;
3681 do_action( 'usces_pre_purchase' );
3682 if ( false === $this->cart->num_row() ) {
3683 header( 'location: ' . get_option( 'home' ) );
3684 exit;
3685 }
3686
3687 if ( isset( $_POST['wc_purchase_nonce'] ) ) {
3688 if ( ! wp_verify_nonce( $_POST['wc_purchase_nonce'], 'wc_purchase_nonce' ) ) {
3689 $this->error_message = __( 'Security check failed. Please try again.', 'usces' );
3690 $this->page = 'confirm';
3691 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3692 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3693 return;
3694 }
3695 }
3696
3697 if ( ! apply_filters( 'usces_purchase_check', true ) ) {
3698 return;
3699 }
3700
3701 do_action( 'usces_purchase_validate' );
3702
3703 $entry = $this->cart->get_entry();
3704 $this->error_message = $this->zaiko_check();
3705 if ( WCUtils::is_blank( $this->error_message ) && 0 < $this->cart->num_row() ) {
3706 $acting_status = '';
3707 $payments = $this->getPayments( $entry['order']['payment_name'] );
3708 if ( null === $payments['id'] && 0 < $entry['order']['total_full_price'] ) {
3709 header( 'HTTP/1.0 400 Bad request' );
3710 die();
3711 }
3712 $payment_settlement = $payments['settlement'] ?? '';
3713 if ( substr( $payment_settlement, 0, 6 ) == 'acting' && $entry['order']['total_full_price'] > 0 ) {
3714 $acting_flg = ( 'acting' == $payment_settlement ) ? $payments['module'] : $payment_settlement;
3715 unset( $_POST['purchase'] );
3716 $post_query = '&' . http_build_query( $_POST );
3717 $acting_status = $this->acting_processing( $acting_flg, $post_query, $acting_status );
3718 }
3719
3720 if ( 'error' == $acting_status ) {
3721 $this->page = 'error';
3722 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_error' );
3723 } else {
3724 $res = $this->order_processing();
3725 if ( 'ordercompletion' == $res ) {
3726 $this->page = 'ordercompletion';
3727 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_ordercompletion' );
3728 } else {
3729 $this->page = 'error';
3730 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_error' );
3731 }
3732 }
3733 } else {
3734 $this->page = 'cart';
3735 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3736 if ( ! $this->is_cart_page( $_SERVER['REQUEST_URI'] ) ) {
3737 wp_redirect( USCES_CART_URL );
3738 exit;
3739 }
3740 }
3741 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3742 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3743 }
3744
3745 public function acting_return() {
3746 global $wp_query;
3747
3748 do_action( 'usces_pre_acting_return' );
3749
3750 $entry = $this->cart->get_entry();
3751 if ( isset( $_GET['acting'] ) && 'anotherlane_card' != $_GET['acting'] ) {
3752 if ( false === $this->cart->num_row() && ( 'paypal' != $_GET['acting'] && 1 !== (int) $_GET['acting_return'] ) ) {
3753 header( 'location: ' . get_option( 'home' ) );
3754 exit;
3755 }
3756 }
3757
3758 $this->payment_results = usces_check_acting_return();
3759
3760 if ( isset( $this->payment_results[0] ) && 'duplicate' === $this->payment_results[0] ) {
3761
3762 header( 'location: ' . get_option( 'home' ) );
3763 exit;
3764
3765 } elseif ( isset( $this->payment_results[0] ) && $this->payment_results[0] ) { // result OK.
3766
3767 if ( ! $this->payment_results['reg_order'] ) { // without Registration Order.
3768 $this->page = 'ordercompletion';
3769 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_ordercompletion' );
3770
3771 } else {
3772 $res = $this->order_processing( $this->payment_results );
3773
3774 if ( 'ordercompletion' == $res ) {
3775 $this->page = 'ordercompletion';
3776 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_ordercompletion' );
3777 } else {
3778 $this->page = 'error';
3779 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_error' );
3780 }
3781 }
3782
3783 } else { // result NG.
3784 $this->page = 'error';
3785 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_error' );
3786 }
3787
3788 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3789 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3790 }
3791
3792 public function settlement_epsilon() {
3793 global $wp_query;
3794 require_once $this->options['settlement_path'] . 'epsilon.php';
3795 }
3796
3797 public function inquiry_button() {
3798 if ( ( isset( $_POST['kakuninyou'] ) && empty( $_POST['kakuninyou'] ) ) && isset( $_POST['inq_name'] ) && ! WCUtils::is_blank( $_POST['inq_name'] ) && isset( $_POST['inq_mailaddress'] ) && is_email( trim( $_POST['inq_mailaddress'] ) ) && ! WCUtils::is_blank( $_POST['inq_contents'] ) ) {
3799 $res = $this->inquiry_processing();
3800 } else {
3801 $res = 'deficiency';
3802 }
3803
3804 $this->page = $res;
3805 }
3806
3807 public function member_login_page() {
3808 global $wp_query;
3809 if ( ! class_exists( 'RateLimiter' ) ) {
3810 require USCES_PLUGIN_DIR . '/classes/rateLimiter.class.php';
3811 }
3812 $rateLimiter = new RateLimiter();
3813 if ( $rateLimiter->checkBlockIP() ) {
3814 $wp_query->set_403();
3815 status_header( 403 );
3816 exit();
3817 }
3818
3819 if ( isset( $_GET['redirect_to'] ) ) {
3820 $_SESSION['redirect_to'] = $_GET['redirect_to'];
3821 }
3822
3823 $res = $this->member_login();
3824 if ( 'member' == $res ) {
3825 $this->page = 'member';
3826 do_action( 'usces_action_member_logined' );
3827
3828 if ( isset( $_SESSION['redirect_to'] ) ) {
3829 if ( wp_safe_redirect( esc_url( $_SESSION['redirect_to'] ) ) ) {
3830 unset( $_SESSION['redirect_to'] );
3831 exit;
3832 }
3833 }
3834
3835 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_member' );
3836 } elseif ( 'login' == $res ) {
3837 $this->page = 'login';
3838 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_login' );
3839 }
3840 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3841 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3842 }
3843
3844 public function regmember() {
3845 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
3846 if ( ! $this->verify_member_nonce( $nonce, 'post_member' ) ) {
3847 die( 'Security check2' );
3848 }
3849
3850 $check_verify_recaptcha = $this->verifyGoogleRecapcha();
3851 if ( $check_verify_recaptcha ) {
3852 // continue register form.
3853 global $wp_query;
3854 $res = $this->regist_member();
3855 } else {
3856 // return back page register and show message.
3857 $this->error_message = apply_filters( 'usces_filter_check_verify_recaptcha_message', __( 'Failed to register member. Please try again.', 'usces' ), 'regmember' );
3858 $res = trim( $_POST['member_regmode'] );
3859 }
3860
3861 if ( 'editmemberform' == $res ) {
3862 $this->page = 'editmemberform';
3863 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_editmemberform' );
3864 } elseif ( 'newcompletion' == $res ) {
3865 $this->page = 'newcompletion';
3866 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_newcompletion' );
3867 } else {
3868 $this->page = $res;
3869 }
3870 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3871 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3872 }
3873
3874 public function editmember() {
3875 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
3876 if ( ! $this->verify_member_nonce( $nonce, 'post_member' ) ) {
3877 die( 'Security check3' );
3878 }
3879
3880 global $wp_query;
3881 $res = $this->regist_member();
3882 if ( 'editmemberform' == $res ) {
3883 $this->page = 'editmemberform';
3884 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_editmemberform' );
3885 } elseif ( 'newcompletion' == $res ) {
3886 $this->page = 'newcompletion';
3887 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_newcompletion' );
3888 } elseif ( 'updatememberform' == $res ) {
3889 $this->page = 'member_edit';
3890 } else {
3891 $this->page = $res;
3892 }
3893 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3894 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3895 }
3896
3897 public function deletemember() {
3898 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
3899 if ( ! $this->verify_member_nonce( $nonce, 'post_member' ) ) {
3900 die( 'Security check4' );
3901 }
3902
3903 $res = $this->delete_member();
3904 if ( $res ) {
3905 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_deletemember' );
3906 $this->member_logout();
3907 } else {
3908 $this->page = 'editmemberform';
3909 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3910 }
3911 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3912 }
3913
3914 public function page_logout() {
3915 global $wp_query;
3916 $this->member_logout();
3917 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3918 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3919 }
3920
3921 public function page_lostmemberpassword() {
3922 global $wp_query;
3923 $this->page = 'lostmemberpassword';
3924 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3925 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3926 }
3927
3928 public function lostpassword() {
3929 global $usces, $wp_query;
3930
3931 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
3932 if ( ! $usces->verify_member_nonce( $nonce, 'post_member' ) ) {
3933 $wp_query->set_403();
3934 status_header( 403 );
3935 exit();
3936 }
3937
3938 $this->error_message = $this->lostpass_mailaddcheck();
3939 if ( '' != $this->error_message ) {
3940 $this->page = 'lostmemberpassword';
3941 } else {
3942 $res = $this->lostmail();
3943 $this->page = $res; // 'lostcompletion';.
3944 }
3945 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3946 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3947 }
3948
3949 public function uscesmode_changepassword() {
3950 global $wp_query;
3951
3952 if ( ! isset( $_REQUEST['mem'] ) || ! isset( $_REQUEST['key'] ) ) {
3953 die( 'Invalid request 1' );
3954 }
3955
3956 $mem_mail = $_REQUEST['mem'];
3957 $lostkey = $_REQUEST['key'];
3958 $res = usces_check_lostkey( $mem_mail, $lostkey );
3959 if ( empty( $res ) ) {
3960 die( 'Invalid request 2' );
3961 }
3962
3963 $this->page = 'changepassword';
3964 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3965 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3966 }
3967
3968 public function changepassword_page() {
3969 global $usces;
3970
3971 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
3972 if ( ! $usces->verify_member_nonce( $nonce, 'post_member' ) ) {
3973 die( 'Security check6' );
3974 }
3975
3976 $lostmail = $_POST['mem'];
3977 $lostkey = $_POST['key'];
3978 $res = usces_check_lostkey( $lostmail, $lostkey );
3979 if ( empty( $res ) ) {
3980 die( 'Invalid request 7' );
3981 }
3982
3983 global $wp_query;
3984 $this->error_message = $this->changepass_check();
3985 if ( '' != $this->error_message ) {
3986 $this->page = 'changepassword';
3987 } else {
3988 $res = $this->changepassword();
3989 $this->page = $res; // 'changepasscompletion';.
3990 }
3991 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3992 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3993 }
3994
3995 public function page_newmember() {
3996 global $wp_query;
3997 $this->page = 'newmemberform';
3998 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_newmemberform' );
3999 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
4000 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
4001 }
4002
4003 public function page_search_item() {
4004 global $wp_query;
4005 $this->page = 'search_item';
4006 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
4007 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
4008 }
4009
4010 public function default_page() {
4011 global $wp_query;
4012 add_action( 'the_post', array( $this, 'goDefaultPage' ) );
4013 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
4014 }
4015
4016 public function verifyGoogleRecapcha() {
4017 // check google re-captcha v3.
4018 $option = get_option( 'usces_ex' );
4019 $is_human = true;
4020 if ( isset( $option['system']['google_recaptcha']['status'] ) && $option['system']['google_recaptcha']['status'] && ! ( empty( $option['system']['google_recaptcha']['site_key'] ) ) && ! ( empty( $option['system']['google_recaptcha']['secret_key'] ) ) ) {
4021 if ( isset( $_POST['recaptcha_response'] ) ) {
4022 $secret = isset( $option['system']['google_recaptcha']['secret_key'] ) ? $option['system']['google_recaptcha']['secret_key'] : '';
4023 $token = trim( $_POST['recaptcha_response'] );
4024 $is_human = $this->google_recaptcha_v3_response( $token, $secret );
4025 }
4026 }
4027 return $is_human;
4028 }
4029
4030 /**
4031 * Handle check google recaptcha v3 response.
4032 *
4033 * @param string $token string token.
4034 * @param string $secret string secret key config.
4035 *
4036 * @return boolean $is_human.
4037 */
4038 public function google_recaptcha_v3_response( $token, $secret ) {
4039 $is_human = true;
4040 if ( empty( $token ) || empty( $secret ) ) {
4041 return $is_human;
4042 }
4043 $option = get_option( 'usces_ex' );
4044 $threshold = isset( $option['system']['google_recaptcha']['score'] ) ? $option['system']['google_recaptcha']['score'] : 0.5;
4045
4046 $endpoint = 'https://www.google.com/recaptcha/api/siteverify';
4047 $request = array(
4048 'body' => array(
4049 'secret' => $secret,
4050 'response' => $token,
4051 ),
4052 );
4053
4054 $response = wp_remote_post( esc_url_raw( $endpoint ), $request );
4055
4056 if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
4057 update_option( 'usces_recaptcha_condition', 'response_NG' );
4058 return $is_human;
4059 } else {
4060 update_option( 'usces_recaptcha_condition', 'response_OK' );
4061 }
4062
4063 $response_body = wp_remote_retrieve_body( $response );
4064 $response_body = json_decode( $response_body, true );
4065
4066 $action = isset( $response_body['action'] ) ? $response_body['action'] : '';
4067 $actions = array(
4068 'create_new_member',
4069 'customer_order_page',
4070 'delivery_order_page',
4071 'member_register_settlement',
4072 'member_update_settlement',
4073 );
4074 if ( ! $response_body['success'] || ! in_array( $action, $actions ) ) {
4075 update_option( 'usces_recaptcha_condition', 'response_ERROR' );
4076 return $is_human;
4077 } else {
4078 update_option( 'usces_recaptcha_condition', 'response_OK' );
4079 }
4080 $score = isset( $response_body['score'] ) ? $response_body['score'] : 0;
4081 $is_human = $threshold <= $score;
4082 return $is_human;
4083 }
4084
4085 public function goDefaultPage() {
4086 global $post;
4087
4088 if ( is_object( $post ) && null !== $post && (int) $post->ID === (int) USCES_CART_NUMBER ) {
4089
4090 $this->page = 'cart';
4091 add_filter( 'the_content', array( $this, 'filter_cartContent' ), 20 );
4092
4093 } elseif ( is_object( $post ) && null !== $post && (int) $post->ID === (int) USCES_MEMBER_NUMBER ) {
4094
4095 $this->page = 'member';
4096
4097 if ( $this->is_member_logged_in() ) {
4098 $this->get_current_member();
4099 $this->set_member_session_data( $this->current_member['id'] );
4100 $this->page = 'member';
4101 } else {
4102 $this->page = 'login';
4103 }
4104 add_filter( 'the_content', array( $this, 'filter_memberContent' ), 20 );
4105 add_filter( 'the_title', array( $this, 'filter_memberTitle' ), 20 );
4106
4107 } elseif ( ! is_singular() ) {
4108 $this->page = 'wp_search';
4109 add_filter( 'the_excerpt', array( $this, 'filter_cartContent' ), 20 );
4110 add_filter( 'the_content', array( $this, 'filter_cartContent' ), 20 );
4111
4112 } else {
4113 add_filter( 'the_content', array( &$this, 'filter_itemPage' ) );
4114 }
4115 }
4116
4117 public function template_redirect() {
4118 global $wpdb, $wp_version, $post, $usces_entries, $usces_carts, $usces_members, $usces_gp, $member_regmode;
4119
4120 if ( version_compare( $wp_version, '4.4-beta', '>' ) && is_embed() ) {
4121 return;
4122 }
4123
4124 if ( $this->is_cart_page( $_SERVER['REQUEST_URI'] ) ) {
4125 if ( '' == $this->page && empty( $this->error_message ) ) {
4126 $this->error_message = $this->zaiko_check();
4127 if ( $this->error_message ) {
4128 $this->page = 'cart';
4129 }
4130 }
4131 }
4132
4133 if ( apply_filters( 'usces_action_template_redirect', false ) ) {
4134 return; // Deprecated.
4135 }
4136 if ( apply_filters( 'usces_filter_template_redirect', false ) ) {
4137 return;
4138 }
4139
4140 $parent_path = get_template_directory() . '/wc_templates';
4141 $child_path = get_stylesheet_directory() . '/wc_templates';
4142
4143 if ( is_single() && is_object( $post ) && 'item' === $post->post_mime_type ) {
4144
4145 if ( file_exists( $child_path . '/wc_item_single.php' ) ) {
4146 if ( ! post_password_required( $post ) ) {
4147 include $child_path . '/wc_item_single.php';
4148 exit;
4149 }
4150 } elseif ( file_exists( $parent_path . '/wc_item_single.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4151 if ( ! post_password_required( $post ) ) {
4152 include $parent_path . '/wc_item_single.php';
4153 exit;
4154 }
4155 }
4156
4157 } elseif ( isset( $_REQUEST['usces_page'] ) && ( 'search_item' == $_REQUEST['usces_page'] || 'usces_search' == $_REQUEST['usces_page'] ) && $this->is_cart_page( $_SERVER['REQUEST_URI'] ) ) {
4158
4159 if ( file_exists( $child_path . '/wc_search_page.php' ) ) {
4160 include $child_path . '/wc_search_page.php';
4161 exit;
4162 } elseif ( file_exists( $parent_path . '/wc_search_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4163 include $parent_path . '/wc_search_page.php';
4164 exit;
4165 }
4166
4167 } elseif ( $this->is_cart_page( $_SERVER['REQUEST_URI'] ) ) {
4168
4169 switch ( $this->page ) {
4170
4171 case 'customer':
4172 if ( file_exists( $child_path . '/cart/wc_customer_page.php' ) ) {
4173 usces_get_entries();
4174 usces_get_member_regmode();
4175 include $child_path . '/cart/wc_customer_page.php';
4176 exit;
4177 } elseif ( file_exists( $parent_path . '/cart/wc_customer_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4178 usces_get_entries();
4179 usces_get_member_regmode();
4180 include $parent_path . '/cart/wc_customer_page.php';
4181 exit;
4182 }
4183 break;
4184
4185 case 'delivery':
4186 if ( file_exists( $child_path . '/cart/wc_delivery_page.php' ) ) {
4187 usces_get_entries();
4188 usces_get_carts();
4189 include $child_path . '/cart/wc_delivery_page.php';
4190 exit;
4191 } elseif ( file_exists( $parent_path . '/cart/wc_delivery_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4192 usces_get_entries();
4193 usces_get_carts();
4194 include $parent_path . '/cart/wc_delivery_page.php';
4195 exit;
4196 }
4197 break;
4198
4199 case 'confirm':
4200 if ( file_exists( $child_path . '/cart/wc_confirm_page.php' ) ) {
4201 usces_get_entries();
4202 usces_get_carts();
4203 usces_get_members();
4204 include $child_path . '/cart/wc_confirm_page.php';
4205 exit;
4206 } elseif ( file_exists( $parent_path . '/cart/wc_confirm_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4207 usces_get_entries();
4208 usces_get_carts();
4209 usces_get_members();
4210 include $parent_path . '/cart/wc_confirm_page.php';
4211 exit;
4212 }
4213 break;
4214
4215 case 'ordercompletion':
4216 if ( file_exists( $child_path . '/cart/wc_completion_page.php' ) ) {
4217 usces_get_entries();
4218 usces_get_carts();
4219 include $child_path . '/cart/wc_completion_page.php';
4220 exit;
4221 } elseif ( file_exists( $parent_path . '/cart/wc_completion_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4222 usces_get_entries();
4223 usces_get_carts();
4224 include $parent_path . '/cart/wc_completion_page.php';
4225 exit;
4226 }
4227 break;
4228
4229 case 'error':
4230 if ( file_exists( $child_path . '/cart/wc_cart_error_page.php' ) ) {
4231 include $child_path . '/cart/wc_cart_error_page.php';
4232 exit;
4233 } elseif ( file_exists( $parent_path . '/cart/wc_cart_error_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4234 include $parent_path . '/cart/wc_cart_error_page.php';
4235 exit;
4236 }
4237 break;
4238
4239 case 'cart':
4240 default:
4241 $this->page = 'cart';
4242 if ( file_exists( $child_path . '/cart/wc_cart_page.php' ) ) {
4243 include $child_path . '/cart/wc_cart_page.php';
4244 exit;
4245 } elseif ( file_exists( $parent_path . '/cart/wc_cart_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4246 include $parent_path . '/cart/wc_cart_page.php';
4247 exit;
4248 }
4249 }
4250
4251 } elseif ( $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
4252
4253 } elseif ( $this->is_member_page( $_SERVER['REQUEST_URI'] ) ) {
4254 if ( 'activate' != $this->options['membersystem_state'] ) {
4255 return;
4256 }
4257
4258 if ( $this->is_member_logged_in() ) {
4259
4260 if ( isset( $_SESSION['usces_member'] ) ) {
4261 $member_table_name = usces_get_tablename( 'usces_member' );
4262 $this->get_current_member();
4263 $query = $wpdb->prepare( "SELECT mem_point FROM $member_table_name WHERE ID = %d", $this->current_member['id'] );
4264 $point = $wpdb->get_var( $query );
4265 $_SESSION['usces_member']['point'] = $point;
4266 }
4267
4268 $member_regmode = 'editmemberform';
4269 if ( file_exists( $child_path . '/member/wc_member_page.php' ) ) {
4270 include $child_path . '/member/wc_member_page.php';
4271 exit;
4272 } elseif ( file_exists( $parent_path . '/member/wc_member_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4273 include $parent_path . '/member/wc_member_page.php';
4274 exit;
4275 }
4276
4277 } else {
4278
4279 switch ( $this->page ) {
4280
4281 case 'login':
4282 if ( file_exists( $child_path . '/member/wc_login_page.php' ) ) {
4283 include $child_path . '/member/wc_login_page.php';
4284 exit;
4285 } elseif ( file_exists( $parent_path . '/member/wc_login_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4286 include $parent_path . '/member/wc_login_page.php';
4287 exit;
4288 }
4289 break;
4290
4291 case 'newmemberform':
4292 if ( file_exists( $child_path . '/member/wc_new_member_page.php' ) ) {
4293 $member_regmode = 'newmemberform';
4294 include $child_path . '/member/wc_new_member_page.php';
4295 exit;
4296 } elseif ( file_exists( $parent_path . '/member/wc_new_member_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4297 $member_regmode = 'newmemberform';
4298 include $parent_path . '/member/wc_new_member_page.php';
4299 exit;
4300 }
4301 break;
4302
4303 case 'lostmemberpassword':
4304 if ( file_exists( $child_path . '/member/wc_lostpassword_page.php' ) ) {
4305 include $child_path . '/member/wc_lostpassword_page.php';
4306 exit;
4307 } elseif ( file_exists( $parent_path . '/member/wc_lostpassword_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4308 include $parent_path . '/member/wc_lostpassword_page.php';
4309 exit;
4310 }
4311 break;
4312
4313 case 'changepassword':
4314 if ( file_exists( $child_path . '/member/wc_changepassword_page.php' ) ) {
4315 include $child_path . '/member/wc_changepassword_page.php';
4316 exit;
4317 } elseif ( file_exists( $parent_path . '/member/wc_changepassword_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4318 include $parent_path . '/member/wc_changepassword_page.php';
4319 exit;
4320 }
4321 break;
4322
4323 case 'newcompletion':
4324 case 'editcompletion':
4325 case 'lostcompletion':
4326 case 'changepasscompletion':
4327 if ( file_exists( $child_path . '/member/wc_member_completion_page.php' ) ) {
4328 include $child_path . '/member/wc_member_completion_page.php';
4329 exit;
4330 } elseif ( file_exists( $parent_path . '/member/wc_member_completion_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4331 include $parent_path . '/member/wc_member_completion_page.php';
4332 exit;
4333 }
4334 break;
4335
4336 default:
4337 $this->page = 'login';
4338 if ( file_exists( $child_path . '/member/wc_login_page.php' ) ) {
4339 include $child_path . '/member/wc_login_page.php';
4340 exit;
4341 } elseif ( file_exists( $parent_path . '/member/wc_login_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4342 include $parent_path . '/member/wc_login_page.php';
4343 exit;
4344 }
4345 }
4346 }
4347 }
4348 }
4349
4350 public function changepassword() {
4351 global $wpdb;
4352
4353 $lostmail = $_POST['mem'];
4354 $lost_key = $_POST['key'];
4355
4356 $member_table = usces_get_tablename( 'usces_member' );
4357 // $hash = usces_get_hash(trim($_POST['loginpass1']));
4358 $salt = usces_get_salt( $lostmail );
4359 $hash = usces_get_hash( trim( $_POST['loginpass1'] ), $salt );
4360 $query = $wpdb->prepare( "UPDATE $member_table SET mem_pass = %s WHERE mem_email = %s",
4361 $hash, $lostmail
4362 );
4363 $res = $wpdb->query( $query );
4364
4365 if ( $res === false ) {
4366 $this->error_message = __( 'Error: failure in updating password', 'usces' );
4367 return 'login';
4368 } else {
4369 usces_remove_lostmail_key( $lostmail, $lost_key );
4370 return 'changepasscompletion';
4371 }
4372 }
4373
4374 public function lostmail() {
4375 $delim = apply_filters( 'usces_filter_delim', $this->delim );
4376
4377 $lostmail = trim( $_POST['loginmail'] );
4378 if ( ! $this->is_member( $lostmail ) ) {
4379 return 'lostcompletion';
4380 }
4381
4382 $lost_key = usces_make_lost_key();
4383 usces_store_lostmail_key( $lostmail, $lost_key );
4384
4385 $uri = USCES_MEMBER_URL . $delim . 'uscesmode=changepassword&mem=' . urlencode( $lostmail ) . '&key=' . urlencode( $lost_key );
4386
4387 $res = usces_lostmail( $uri );
4388 return $res;
4389 }
4390
4391 public function regist_member() {
4392 global $wpdb;
4393
4394 $_POST = $this->stripslashes_deep_post( $_POST );
4395
4396 $member = $this->get_member();
4397 $mode = $_POST['member_regmode'];
4398 $member_table = usces_get_tablename( 'usces_member' );
4399 $member_meta_table = usces_get_tablename( 'usces_member_meta' );
4400
4401 $error_mes = ( 'newmemberfromcart' == $_POST['member_regmode'] || 'editmemberfromcart' == $_POST['member_regmode'] ) ? $this->member_check_fromcart() : $this->member_check();
4402
4403 if ( '' != $error_mes ) {
4404
4405 $this->error_message = $error_mes;
4406 return $mode;
4407
4408 } elseif ( 'editmemberform' == $_POST['member_regmode'] || 'updatememberform' == $_POST['member_regmode'] ) {
4409
4410 $this->get_current_member();
4411 $mem_id = $this->current_member['id'];
4412
4413 // $query = $wpdb->prepare("SELECT ID FROM $member_table WHERE mem_email = %s", trim($_POST['member']['mailaddress1']));
4414 // $id = $wpdb->get_var( $query );
4415 $id = $this->check_member_email( $_POST['member']['mailaddress1'] );
4416 if ( ! empty( $id ) && $id != $mem_id ) {
4417 // $this->error_message = __( 'This e-mail address has been already registered.', 'usces' );
4418 $this->error_message = __( 'This e-mail address can not be registered.', 'usces' );
4419 return $mode;
4420 }
4421
4422 do_action( 'usces_action_pre_edit_memberdata', $_POST['member'], $mem_id );
4423
4424 $query = $wpdb->prepare( "SELECT mem_pass FROM $member_table WHERE ID = %d", $mem_id );
4425 $pass = $wpdb->get_var( $query );
4426 // $password = ( !empty( $_POST['member']['password1']) && trim($_POST['member']['password1']) == trim($_POST['member']['password2']) ) ? usces_get_hash(trim($_POST['member']['password1'])) : $pass;
4427 if ( ! empty( $_POST['member']['password1'] ) && trim( $_POST['member']['password1'] ) == trim( $_POST['member']['password2'] ) ) {
4428 $salt = usces_get_salt( $mem_id );
4429 $password = usces_get_hash( trim( $_POST['member']['password1'] ), $salt );
4430 } else {
4431 $password = $pass;
4432 }
4433 $name1 = ( isset( $_POST['member']['name1'] ) ) ? trim( $_POST['member']['name1'] ) : '';
4434 $name2 = ( isset( $_POST['member']['name2'] ) ) ? trim( $_POST['member']['name2'] ) : '';
4435 $name3 = ( isset( $_POST['member']['name3'] ) ) ? trim( $_POST['member']['name3'] ) : '';
4436 $name4 = ( isset( $_POST['member']['name4'] ) ) ? trim( $_POST['member']['name4'] ) : '';
4437 $zipcode = ( isset( $_POST['member']['zipcode'] ) ) ? usces_convert_zipcode( trim( $_POST['member']['zipcode'] ) ) : '';
4438 $pref = ( isset( $_POST['member']['pref'] ) ) ? trim( $_POST['member']['pref'] ) : '';
4439 $address1 = ( isset( $_POST['member']['address1'] ) ) ? trim( $_POST['member']['address1'] ) : '';
4440 $address2 = ( isset( $_POST['member']['address2'] ) ) ? trim( $_POST['member']['address2'] ) : '';
4441 $address3 = ( isset( $_POST['member']['address3'] ) ) ? trim( $_POST['member']['address3'] ) : '';
4442 $tel = ( isset( $_POST['member']['tel'] ) ) ? trim( $_POST['member']['tel'] ) : '';
4443 $fax = ( isset( $_POST['member']['fax'] ) ) ? trim( $_POST['member']['fax'] ) : '';
4444 $country = ( isset( $_POST['member']['country'] ) ) ? trim( $_POST['member']['country'] ) : '';
4445
4446 $query = $wpdb->prepare(
4447 "UPDATE $member_table SET
4448 mem_pass = %s, mem_name1 = %s, mem_name2 = %s, mem_name3 = %s, mem_name4 = %s,
4449 mem_zip = %s, mem_pref = %s, mem_address1 = %s, mem_address2 = %s,
4450 mem_address3 = %s, mem_tel = %s, mem_fax = %s, mem_email = %s WHERE ID = %d",
4451 $password,
4452 $name1,
4453 $name2,
4454 $name3,
4455 $name4,
4456 $zipcode,
4457 $pref,
4458 $address1,
4459 $address2,
4460 $address3,
4461 $tel,
4462 $fax,
4463 trim( $_POST['member']['mailaddress1'] ),
4464 $mem_id
4465 );
4466 $res = $wpdb->query( $query );
4467
4468 if ( false !== $res ) {
4469 $this->set_member_meta_value( 'customer_country', $country, $mem_id );
4470 $res = $this->reg_custom_member( $mem_id );
4471 unset( $_SESSION['usces_entry']['custom_customer'] );
4472 $this->cart->entry();
4473 do_action( 'usces_action_edit_memberdata', $_POST['member'], $mem_id );
4474 $meta_keys = apply_filters( 'usces_filter_delete_member_pcid', "'remise_pcid', 'digitalcheck_ip_user_id'" );
4475 $query = $wpdb->prepare( "DELETE FROM $member_meta_table WHERE member_id = %d AND meta_key IN( $meta_keys )",
4476 $mem_id
4477 );
4478 $res = $wpdb->query( $query );
4479
4480 $user = $_POST['member'];
4481 $user['ID'] = $mem_id;
4482 usces_send_updmembermail( $user );
4483
4484 $this->get_current_member();
4485 // return 'editmemberform';
4486 return $mode;
4487
4488 } else {
4489 $this->error_message = __( 'Error:failure in update', 'usces' );
4490 return $mode;
4491 }
4492
4493 } elseif ( 'newmemberform' == $_POST['member_regmode'] ) {
4494 // $query = $wpdb->prepare("SELECT ID FROM $member_table WHERE mem_email = %s", trim( $_POST['member']['mailaddress1']));
4495 // $id = $wpdb->get_var( $query );
4496 $id = $this->check_member_email( $_POST['member']['mailaddress1'] );
4497 if ( ! empty( $id ) ) {
4498 // $this->error_message = __( 'This e-mail address has been already registered.', 'usces' );
4499 $this->error_message = __( 'This e-mail address can not be registered.', 'usces' );
4500 return $mode;
4501 } else {
4502 $point = $this->options['start_point'];
4503 // $pass = usces_get_hash(trim($_POST['member']['password1']));
4504 $salt = usces_get_salt( '', 1 );
4505 $pass = usces_get_hash( trim( $_POST['member']['password1'] ), $salt );
4506 $name1 = ( isset( $_POST['member']['name1'] ) ) ? trim( $_POST['member']['name1'] ) : '';
4507 $name2 = ( isset( $_POST['member']['name2'] ) ) ? trim( $_POST['member']['name2'] ) : '';
4508 $name3 = ( isset( $_POST['member']['name3'] ) ) ? trim( $_POST['member']['name3'] ) : '';
4509 $name4 = ( isset( $_POST['member']['name4'] ) ) ? trim( $_POST['member']['name4'] ) : '';
4510 $zipcode = ( isset( $_POST['member']['zipcode'] ) ) ? usces_convert_zipcode( trim( $_POST['member']['zipcode'] ) ) : '';
4511 $pref = ( isset( $_POST['member']['pref'] ) ) ? trim( $_POST['member']['pref'] ) : '';
4512 $address1 = ( isset( $_POST['member']['address1'] ) ) ? trim( $_POST['member']['address1'] ) : '';
4513 $address2 = ( isset( $_POST['member']['address2'] ) ) ? trim( $_POST['member']['address2'] ) : '';
4514 $address3 = ( isset( $_POST['member']['address3'] ) ) ? trim( $_POST['member']['address3'] ) : '';
4515 $tel = ( isset( $_POST['member']['tel'] ) ) ? trim( $_POST['member']['tel'] ) : '';
4516 $fax = ( isset( $_POST['member']['fax'] ) ) ? trim( $_POST['member']['fax'] ) : '';
4517 $country = ( isset( $_POST['member']['country'] ) ) ? trim( $_POST['member']['country'] ) : '';
4518
4519 $query = $wpdb->prepare(
4520 "INSERT INTO $member_table
4521 (mem_email, mem_pass, mem_status, mem_cookie, mem_point,
4522 mem_name1, mem_name2, mem_name3, mem_name4, mem_zip, mem_pref,
4523 mem_address1, mem_address2, mem_address3, mem_tel, mem_fax,
4524 mem_delivery_flag, mem_delivery, mem_registered, mem_nicename)
4525 VALUES (%s, %s, %d, %s, %d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s)",
4526 trim( $_POST['member']['mailaddress1'] ),
4527 $pass,
4528 0,
4529 '',
4530 $point,
4531 $name1,
4532 $name2,
4533 $name3,
4534 $name4,
4535 $zipcode,
4536 $pref,
4537 $address1,
4538 $address2,
4539 $address3,
4540 $tel,
4541 $fax,
4542 '',
4543 '',
4544 get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ),
4545 ''
4546 );
4547 $res = $wpdb->query( $query );
4548
4549 if ( false !== $res ) {
4550 $user = $_POST['member'];
4551 $user['ID'] = $wpdb->insert_id;
4552 $this->set_member_meta_value( 'customer_country', $country, $user['ID'] );
4553
4554 if ( ! empty( $salt ) ) {
4555 $this->set_member_meta_value( 'mem_salt', $salt, $user['ID'] );
4556 }
4557
4558 $res = $this->reg_custom_member( $user['ID'] );
4559
4560 if ( apply_filters( 'usces_filter_veirfyemail_newmemberform', false, $user ) ) {
4561 return 'memberverifying';
4562 }
4563
4564 do_action( 'usces_action_member_registered', $_POST['member'], $user['ID'] );
4565 unset( $_SESSION['usces_member'] );
4566 usces_send_regmembermail( $user );
4567 return 'newcompletion';
4568
4569 } else {
4570 $this->error_message = __( 'Error:failure in update', 'usces' );
4571 return $mode;
4572 }
4573 }
4574
4575 } elseif ( 'newmemberfromcart' == $_POST['member_regmode'] ) {
4576
4577 // $query = $wpdb->prepare("SELECT ID FROM $member_table WHERE mem_email = %s", trim($_POST['customer']['mailaddress1']));
4578 // $id = $wpdb->get_var( $query );
4579 $id = $this->check_member_email( $_POST['customer']['mailaddress1'] );
4580 if ( ! empty( $id ) ) {
4581 // $this->error_message = __( 'This e-mail address has been already registered.', 'usces' );
4582 $this->error_message = __( 'This e-mail address can not be registered.', 'usces' );
4583 return $mode;
4584 } else {
4585 $point = $this->options['start_point'];
4586 // $pass = usces_get_hash(trim( $_POST['customer']['password1']));
4587 $salt = usces_get_salt( '', 1 );
4588 $pass = usces_get_hash( trim( $_POST['customer']['password1'] ), $salt );
4589 $name1 = ( isset( $_POST['customer']['name1'] ) ) ? trim( $_POST['customer']['name1'] ) : '';
4590 $name2 = ( isset( $_POST['customer']['name2'] ) ) ? trim( $_POST['customer']['name2'] ) : '';
4591 $name3 = ( isset( $_POST['customer']['name3'] ) ) ? trim( $_POST['customer']['name3'] ) : '';
4592 $name4 = ( isset( $_POST['customer']['name4'] ) ) ? trim( $_POST['customer']['name4'] ) : '';
4593 $zipcode = ( isset( $_POST['customer']['zipcode'] ) ) ? usces_convert_zipcode( trim( $_POST['customer']['zipcode'] ) ) : '';
4594 $pref = ( isset( $_POST['customer']['pref'] ) ) ? trim( $_POST['customer']['pref'] ) : '';
4595 $address1 = ( isset( $_POST['customer']['address1'] ) ) ? trim( $_POST['customer']['address1'] ) : '';
4596 $address2 = ( isset( $_POST['customer']['address2'] ) ) ? trim( $_POST['customer']['address2'] ) : '';
4597 $address3 = ( isset( $_POST['customer']['address3'] ) ) ? trim( $_POST['customer']['address3'] ) : '';
4598 $tel = ( isset( $_POST['customer']['tel'] ) ) ? trim( $_POST['customer']['tel'] ) : '';
4599 $fax = ( isset( $_POST['customer']['fax'] ) ) ? trim( $_POST['customer']['fax'] ) : '';
4600 $country = ( isset( $_POST['customer']['country'] ) ) ? trim( $_POST['customer']['country'] ) : '';
4601
4602 $query = $wpdb->prepare(
4603 "INSERT INTO $member_table
4604 (mem_email, mem_pass, mem_status, mem_cookie, mem_point,
4605 mem_name1, mem_name2, mem_name3, mem_name4, mem_zip, mem_pref,
4606 mem_address1, mem_address2, mem_address3, mem_tel, mem_fax,
4607 mem_delivery_flag, mem_delivery, mem_registered, mem_nicename)
4608 VALUES (%s, %s, %d, %s, %d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s)",
4609 trim( $_POST['customer']['mailaddress1'] ),
4610 $pass,
4611 0,
4612 '',
4613 $point,
4614 $name1,
4615 $name2,
4616 $name3,
4617 $name4,
4618 $zipcode,
4619 $pref,
4620 $address1,
4621 $address2,
4622 $address3,
4623 $tel,
4624 $fax,
4625 '',
4626 '',
4627 get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ),
4628 ''
4629 );
4630 $res = $wpdb->query( $query );
4631
4632 if ( false !== $res ) {
4633 $member_id = $wpdb->insert_id;
4634 $user = $_POST['customer'];
4635 $user['ID'] = $member_id;
4636 $this->set_member_meta_value( 'customer_country', $country, $member_id );
4637
4638 if ( ! empty( $salt ) ) {
4639 $this->set_member_meta_value( 'mem_salt', $salt, $member_id );
4640 }
4641
4642 $res = $this->reg_custom_member( $member_id );
4643
4644 if ( apply_filters( 'usces_filter_veirfyemail_newmemberfromcart', false, $user ) ) {
4645 return 'cartverifying';
4646 }
4647
4648 do_action( 'usces_action_member_registered', $_POST['customer'], $member_id );
4649 usces_send_regmembermail( $user );
4650 $_POST['loginmail'] = trim( $_POST['customer']['mailaddress1'] );
4651 $_POST['loginpass'] = trim( $_POST['customer']['password1'] );
4652 if ( 'member' == $this->member_login() ) {
4653 $_SESSION['usces_entry']['member_regmode'] = 'editmemberfromcart';
4654 return 'newcompletion';
4655 }
4656
4657 } else {
4658 $this->error_message = __( 'Error:failure in update', 'usces' );
4659 return $mode;
4660 }
4661 }
4662
4663 } elseif ( 'editmemberfromcart' == $_POST['member_regmode'] ) {
4664
4665 $this->get_current_member();
4666 $mem_id = $this->current_member['id'];
4667
4668 // $query = $wpdb->prepare("SELECT ID FROM $member_table WHERE mem_email = %s", trim( $_POST['customer']['mailaddress1']));
4669 // $id = $wpdb->get_var( $query );
4670 $id = $this->check_member_email( $_POST['customer']['mailaddress1'] );
4671 if ( ! empty( $id ) && $id != $mem_id ) {
4672 // $this->error_message = __( 'This e-mail address has been already registered.', 'usces' );
4673 $this->error_message = __( 'This e-mail address can not be registered.', 'usces' );
4674 return $mode;
4675 }
4676
4677 do_action( 'usces_action_pre_edit_memberdata', $_POST['customer'], $mem_id );
4678
4679 $query = $wpdb->prepare( "SELECT mem_pass FROM $member_table WHERE ID = %d", $mem_id );
4680 $pass = $wpdb->get_var( $query );
4681 // $password = ( !empty( $_POST['customer']['password1']) && trim($_POST['customer']['password1']) == trim($_POST['customer']['password2']) ) ? usces_get_hash(trim($_POST['customer']['password1'])) : $pass;
4682 if ( ! empty( $_POST['customer']['password1'] ) && trim( $_POST['customer']['password1'] ) == trim( $_POST['customer']['password2'] ) ) {
4683 $salt = usces_get_salt( $mem_id );
4684 $password = usces_get_hash( trim( $_POST['customer']['password1'] ), $salt );
4685 } else {
4686 $password = $pass;
4687 }
4688 $name1 = ( isset( $_POST['customer']['name1'] ) ) ? trim( $_POST['customer']['name1'] ) : '';
4689 $name2 = ( isset( $_POST['customer']['name2'] ) ) ? trim( $_POST['customer']['name2'] ) : '';
4690 $name3 = ( isset( $_POST['customer']['name3'] ) ) ? trim( $_POST['customer']['name3'] ) : '';
4691 $name4 = ( isset( $_POST['customer']['name4'] ) ) ? trim( $_POST['customer']['name4'] ) : '';
4692 $zipcode = ( isset( $_POST['customer']['zipcode'] ) ) ? usces_convert_zipcode( trim( $_POST['customer']['zipcode'] ) ) : '';
4693 $pref = ( isset( $_POST['customer']['pref'] ) ) ? trim( $_POST['customer']['pref'] ) : '';
4694 $address1 = ( isset( $_POST['customer']['address1'] ) ) ? trim( $_POST['customer']['address1'] ) : '';
4695 $address2 = ( isset( $_POST['customer']['address2'] ) ) ? trim( $_POST['customer']['address2'] ) : '';
4696 $address3 = ( isset( $_POST['customer']['address3'] ) ) ? trim( $_POST['customer']['address3'] ) : '';
4697 $tel = ( isset( $_POST['customer']['tel'] ) ) ? trim( $_POST['customer']['tel'] ) : '';
4698 $fax = ( isset( $_POST['customer']['fax'] ) ) ? trim( $_POST['customer']['fax'] ) : '';
4699 $country = ( isset( $_POST['customer']['country'] ) ) ? trim( $_POST['customer']['country'] ) : '';
4700
4701 $query = $wpdb->prepare(
4702 "UPDATE $member_table SET
4703 mem_pass = %s, mem_name1 = %s, mem_name2 = %s, mem_name3 = %s, mem_name4 = %s,
4704 mem_zip = %s, mem_pref = %s, mem_address1 = %s, mem_address2 = %s,
4705 mem_address3 = %s, mem_tel = %s, mem_fax = %s, mem_email = %s WHERE ID = %d",
4706 $password,
4707 $name1,
4708 $name2,
4709 $name3,
4710 $name4,
4711 $zipcode,
4712 $pref,
4713 $address1,
4714 $address2,
4715 $address3,
4716 $tel,
4717 $fax,
4718 trim( $_POST['customer']['mailaddress1'] ),
4719 $mem_id
4720 );
4721 $res = $wpdb->query( $query );
4722 if ( false !== $res ) {
4723 $this->set_member_meta_value( 'customer_country', $country, $mem_id );
4724 $res = $this->reg_custom_member( $mem_id );
4725 do_action( 'usces_action_edit_memberdata', $_POST['customer'], $mem_id );
4726 unset( $_SESSION['usces_member'] );
4727 $this->member_just_login( trim( $_POST['customer']['mailaddress1'] ), trim( $_POST['customer']['password1'] ) );
4728 return 'newcompletion';
4729
4730 } else {
4731 $this->error_message = __( 'Error:failure in update', 'usces' );
4732 return $mode;
4733 }
4734 }
4735 }
4736
4737 public function delete_member() {
4738 $res = false;
4739
4740 if ( ! $this->is_member_logged_in() ) {
4741 return $res;
4742 }
4743 $mem = $this->get_member();
4744 if ( ! $mem['ID'] ) {
4745 return $res;
4746 }
4747
4748 $del = usces_delete_member_check_front( $mem['ID'] );
4749 if ( $del ) {
4750 $res = usces_delete_memberdata( $mem['ID'] );
4751 if ( $res ) {
4752 usces_send_delmembermail( $mem );
4753 }
4754 }
4755
4756 return $res;
4757 }
4758
4759 public function is_member_logged_in( $id = false ) {
4760 if ( false === $id ) {
4761 if ( ! empty( $_SESSION['usces_member']['ID'] ) ) {
4762 return true;
4763 } else {
4764 return false;
4765 }
4766 } else {
4767 if ( ! empty( $_SESSION['usces_member']['ID'] ) && $_SESSION['usces_member']['ID'] == $id ) {
4768 return true;
4769 } else {
4770 return false;
4771 }
4772 }
4773 }
4774
4775 public function is_member( $email ) {
4776 global $wpdb;
4777
4778 $member_table = usces_get_tablename( 'usces_member' );
4779 $query = $wpdb->prepare( "SELECT mem_email FROM $member_table WHERE mem_email = %s", $email );
4780 $member = $wpdb->get_row( $query, ARRAY_A );
4781 if ( empty( $member ) ) {
4782 return false;
4783 } else {
4784 return true;
4785 }
4786 }
4787
4788 public function member_login() {
4789 global $wpdb;
4790 $_POST = $this->stripslashes_deep_post( $_POST );
4791
4792 $cookie = $this->get_cookie();
4793 $metatable_name = usces_get_tablename( 'usces_member_meta' );
4794 $member_table = usces_get_tablename( 'usces_member' );
4795 if ( ! class_exists( 'RateLimiter' ) ) {
4796 require USCES_PLUGIN_DIR . '/classes/rateLimiter.class.php';
4797 }
4798 $rateLimiter = new RateLimiter();
4799
4800 if ( isset( $cookie['rme'] ) && 'forever' == $cookie['rme'] && ! isset( $_POST['rememberme'] ) && ! isset( $_POST['loginmail'] ) ) {
4801
4802 $_forever = isset( $cookie['name'] ) ? $cookie['name'] : '';
4803 if ( $_forever ) {
4804 $query = $wpdb->prepare( "SELECT member_id FROM $metatable_name WHERE meta_value = %s AND meta_key = %s",
4805 $_forever, '_forever'
4806 );
4807 $id = $wpdb->get_var( $query );
4808 } else {
4809 $id = '';
4810 }
4811
4812 if ( ! $id ) {
4813 $cookie['name'] = '';
4814 $cookie['rme'] = '';
4815 $this->set_cookie( $cookie );
4816 $rateLimiter->saveLoginFailed();
4817 do_action( 'usces_action_member_login_failed', '', 'auto_login' );
4818 return 'login';
4819 } else {
4820 $query = $wpdb->prepare( "SELECT * FROM $member_table WHERE ID = %s", $id );
4821 $member = $wpdb->get_row( $query, ARRAY_A );
4822 if ( empty( $member ) ) {
4823 $rateLimiter->saveLoginFailed();
4824 do_action( 'usces_action_member_login_failed', '', 'auto_login' );
4825 $this->error_message = __( '<b>Error:</b> Your E-mail or password is incorrect.', 'usces' );
4826 return 'login';
4827 } else {
4828 $_SESSION['usces_member']['ID'] = $member['ID'];
4829 $_SESSION['usces_member']['mailaddress1'] = $member['mem_email'];
4830 $_SESSION['usces_member']['mailaddress2'] = $member['mem_email'];
4831 $_SESSION['usces_member']['point'] = $member['mem_point'];
4832 $_SESSION['usces_member']['name1'] = $member['mem_name1'];
4833 $_SESSION['usces_member']['name2'] = $member['mem_name2'];
4834 $_SESSION['usces_member']['name3'] = $member['mem_name3'];
4835 $_SESSION['usces_member']['name4'] = $member['mem_name4'];
4836 $_SESSION['usces_member']['zipcode'] = $member['mem_zip'];
4837 $_SESSION['usces_member']['pref'] = $member['mem_pref'];
4838 $_SESSION['usces_member']['address1'] = $member['mem_address1'];
4839 $_SESSION['usces_member']['address2'] = $member['mem_address2'];
4840 $_SESSION['usces_member']['address3'] = $member['mem_address3'];
4841 $_SESSION['usces_member']['tel'] = $member['mem_tel'];
4842 $_SESSION['usces_member']['fax'] = $member['mem_fax'];
4843 $_SESSION['usces_member']['delivery_flag'] = $member['mem_delivery_flag'];
4844 $_SESSION['usces_member']['delivery'] = ! empty( $member['mem_delivery'] ) ? wel_safe_unserialize( $member['mem_delivery'] ) : '';
4845 $_SESSION['usces_member']['registered'] = $member['mem_registered'];
4846 $_SESSION['usces_member']['nicename'] = $member['mem_nicename'];
4847 $_SESSION['usces_member']['country'] = $this->get_member_meta_value( 'customer_country', $member['ID'] );
4848 $_SESSION['usces_member']['status'] = $member['mem_status'];
4849 $this->set_session_custom_member( $member['ID'] );
4850 $this->get_current_member();
4851
4852 do_action( 'usces_action_after_login' );
4853 $this->set_cookie( $cookie );
4854 return apply_filters( 'usces_filter_member_login', 'member', $member );
4855 }
4856 }
4857 } elseif ( isset( $_POST['loginmail'] ) && WCUtils::is_blank( $_POST['loginmail'] ) && isset( $_POST['loginpass'] ) && WCUtils::is_blank( $_POST['loginpass'] ) && isset( $cookie['rme'] ) && 'forever' != $cookie['rme'] ) {
4858 $rateLimiter->saveLoginFailed();
4859 do_action( 'usces_action_member_login_failed', '', 'empty_credentials' );
4860 return 'login';
4861 } elseif ( isset( $_POST['loginmail'] ) && WCUtils::is_blank( $_POST['loginpass'] ) && isset( $cookie['rme'] ) && 'forever' != $cookie['rme'] ) {
4862 $rateLimiter->saveLoginFailed();
4863 do_action( 'usces_action_member_login_failed', trim( $_POST['loginmail'] ), 'empty_password' );
4864 $this->error_message = __( '<b>Error:</b> Enter the password.', 'usces' );
4865 return 'login';
4866 } elseif ( ! isset( $_POST['loginmail'] ) ) {
4867 if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) {
4868 $rateLimiter->saveLoginFailed();
4869 do_action( 'usces_action_member_login_failed', '', 'no_login_id' );
4870 }
4871 return 'login';
4872 } else {
4873
4874 if ( isset( $_POST['loginmail'] ) ) {
4875 $nonce = isset( $_REQUEST['wel_nonce'] ) ? $_REQUEST['wel_nonce'] : '';
4876 if ( ! $nonce ) {
4877 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
4878 }
4879 if ( ! $this->verify_member_nonce( $nonce, 'post_member' ) && ! $this->is_member_logged_in() ) {
4880 $rateLimiter->saveLoginFailed();
4881 do_action( 'usces_action_member_login_failed', trim( $_POST['loginmail'] ), 'invalid_nonce' );
4882 die( 'Security check4' );
4883 }
4884 }
4885
4886 $email = isset( $_POST['loginmail'] ) ? trim( $_POST['loginmail'] ) : '';
4887 // $pass = isset( $_POST['loginpass']) ? usces_get_hash(trim( $_POST['loginpass'])) : '';
4888 $salt = usces_get_salt( $email );
4889 $pass = usces_get_hash( trim( $_POST['loginpass'] ), $salt );
4890 $member_table = usces_get_tablename( 'usces_member' );
4891
4892 $query = $wpdb->prepare( "SELECT * FROM $member_table WHERE mem_email = %s AND mem_pass = %s", $email, $pass );
4893 $query = apply_filters( 'usces_filter_member_login_query', $query, $email, $pass );
4894 $member = $wpdb->get_row( $query, ARRAY_A );
4895
4896 if ( empty( $member ) ) {
4897 $rateLimiter->saveLoginFailed();
4898 do_action( 'usces_action_member_login_failed', $email, 'invalid_credentials' );
4899 $this->current_member['email'] = htmlspecialchars( $email, ENT_COMPAT );
4900 $this->error_message = __( '<b>Error:</b> Your E-mail or password is incorrect.', 'usces' );
4901 return 'login';
4902 } else {
4903
4904 if ( USCES_VERIFY_MEMBERS_EMAIL::$opts['switch_flag'] ) {
4905 $verify_flag = $this->get_member_meta_value( '_verifying', $member['ID'] );
4906 } else {
4907 $verify_flag = '';
4908 }
4909 if ( ! empty( $verify_flag ) ) {
4910 $rateLimiter->saveLoginFailed();
4911 do_action( 'usces_action_member_login_failed', $email, 'unverified_email' );
4912 $this->error_message = __( '<b>Error:</b> Membership registration is not complete.', 'usces' );
4913 return 'login';
4914 }
4915
4916 $_SESSION['usces_member']['ID'] = $member['ID'];
4917 $_SESSION['usces_member']['mailaddress1'] = $member['mem_email'];
4918 $_SESSION['usces_member']['mailaddress2'] = $member['mem_email'];
4919 $_SESSION['usces_member']['point'] = $member['mem_point'];
4920 $_SESSION['usces_member']['name1'] = $member['mem_name1'];
4921 $_SESSION['usces_member']['name2'] = $member['mem_name2'];
4922 $_SESSION['usces_member']['name3'] = $member['mem_name3'];
4923 $_SESSION['usces_member']['name4'] = $member['mem_name4'];
4924 $_SESSION['usces_member']['zipcode'] = $member['mem_zip'];
4925 $_SESSION['usces_member']['pref'] = $member['mem_pref'];
4926 $_SESSION['usces_member']['address1'] = $member['mem_address1'];
4927 $_SESSION['usces_member']['address2'] = $member['mem_address2'];
4928 $_SESSION['usces_member']['address3'] = $member['mem_address3'];
4929 $_SESSION['usces_member']['tel'] = $member['mem_tel'];
4930 $_SESSION['usces_member']['fax'] = $member['mem_fax'];
4931 $_SESSION['usces_member']['delivery_flag'] = $member['mem_delivery_flag'];
4932 $_SESSION['usces_member']['delivery'] = ! empty( $member['mem_delivery'] ) ? wel_safe_unserialize( $member['mem_delivery'] ) : '';
4933 $_SESSION['usces_member']['registered'] = $member['mem_registered'];
4934 $_SESSION['usces_member']['nicename'] = $member['mem_nicename'];
4935 $_SESSION['usces_member']['country'] = $this->get_member_meta_value( 'customer_country', $member['ID'] );
4936 $_SESSION['usces_member']['status'] = $member['mem_status'];
4937 $this->set_session_custom_member( $member['ID'] );
4938 $this->get_current_member();
4939 $rateLimiter->clear_login_failed();
4940
4941 if ( isset( $_POST['rememberme'] ) ) {
4942 $_forever = $this->set_login_forever( $member['ID'] );
4943 $cookie['name'] = $_forever;
4944 $cookie['rme'] = 'forever';
4945 $this->set_cookie( $cookie );
4946 } else {
4947 $cookie['name'] = '';
4948 $cookie['rme'] = '';
4949 $this->set_cookie( $cookie );
4950 }
4951
4952 do_action( 'usces_action_after_login' );
4953 return apply_filters( 'usces_filter_member_login', 'member', $member );
4954 }
4955 }
4956 }
4957
4958 public function set_login_forever( $member_id ) {
4959 if ( ! $member_id ) {
4960 return false;
4961 }
4962
4963 $_forever = wp_generate_password( 32, false, false );
4964 $this->set_member_meta_value( '_forever', $_forever, $member_id );
4965 return $_forever;
4966 }
4967
4968 public function set_member_session_data( $member_id ) {
4969 global $wpdb;
4970
4971 $member_table = usces_get_tablename( 'usces_member' );
4972 $query = $wpdb->prepare( "SELECT * FROM $member_table WHERE ID = %s", $member_id );
4973 $member = $wpdb->get_row( $query, ARRAY_A );
4974 if ( ! empty( $member ) ) {
4975 $_SESSION['usces_member']['ID'] = $member['ID'];
4976 $_SESSION['usces_member']['mailaddress1'] = $member['mem_email'];
4977 $_SESSION['usces_member']['mailaddress2'] = $member['mem_email'];
4978 $_SESSION['usces_member']['point'] = $member['mem_point'];
4979 $_SESSION['usces_member']['name1'] = $member['mem_name1'];
4980 $_SESSION['usces_member']['name2'] = $member['mem_name2'];
4981 $_SESSION['usces_member']['name3'] = $member['mem_name3'];
4982 $_SESSION['usces_member']['name4'] = $member['mem_name4'];
4983 $_SESSION['usces_member']['zipcode'] = $member['mem_zip'];
4984 $_SESSION['usces_member']['pref'] = $member['mem_pref'];
4985 $_SESSION['usces_member']['address1'] = $member['mem_address1'];
4986 $_SESSION['usces_member']['address2'] = $member['mem_address2'];
4987 $_SESSION['usces_member']['address3'] = $member['mem_address3'];
4988 $_SESSION['usces_member']['tel'] = $member['mem_tel'];
4989 $_SESSION['usces_member']['fax'] = $member['mem_fax'];
4990 $_SESSION['usces_member']['delivery_flag'] = $member['mem_delivery_flag'];
4991 $_SESSION['usces_member']['delivery'] = ! empty( $member['mem_delivery'] ) ? wel_safe_unserialize( $member['mem_delivery'] ) : '';
4992 $_SESSION['usces_member']['registered'] = $member['mem_registered'];
4993 $_SESSION['usces_member']['nicename'] = $member['mem_nicename'];
4994 $_SESSION['usces_member']['country'] = $this->get_member_meta_value( 'customer_country', $member['ID'] );
4995 $_SESSION['usces_member']['status'] = $member['mem_status'];
4996 $this->set_session_custom_member( $member['ID'] );
4997 $this->get_current_member();
4998 }
4999 return;
5000 }
5001
5002 public function member_just_login( $email, $pass ) {
5003 global $wpdb;
5004 // $pass = usces_get_hash($pass);
5005 $salt = usces_get_salt( $email );
5006 $pass = usces_get_hash( $pass, $salt );
5007 $member_table = usces_get_tablename( 'usces_member' );
5008
5009 $query = $wpdb->prepare( "SELECT * FROM $member_table WHERE mem_email = %s AND mem_pass = %s", $email, $pass );
5010 $member = $wpdb->get_row( $query, ARRAY_A );
5011 if ( empty( $member ) ) {
5012 $this->current_member['email'] = htmlspecialchars( $email, ENT_COMPAT );
5013 $this->error_message = __( '<b>Error:</b> Password is not correct.', 'usces' );
5014 return 'login';
5015 } else {
5016 $_SESSION['usces_member']['ID'] = $member['ID'];
5017 $_SESSION['usces_member']['mailaddress1'] = $member['mem_email'];
5018 $_SESSION['usces_member']['mailaddress2'] = $member['mem_email'];
5019 $_SESSION['usces_member']['point'] = $member['mem_point'];
5020 $_SESSION['usces_member']['name1'] = $member['mem_name1'];
5021 $_SESSION['usces_member']['name2'] = $member['mem_name2'];
5022 $_SESSION['usces_member']['name3'] = $member['mem_name3'];
5023 $_SESSION['usces_member']['name4'] = $member['mem_name4'];
5024 $_SESSION['usces_member']['zipcode'] = $member['mem_zip'];
5025 $_SESSION['usces_member']['pref'] = $member['mem_pref'];
5026 $_SESSION['usces_member']['address1'] = $member['mem_address1'];
5027 $_SESSION['usces_member']['address2'] = $member['mem_address2'];
5028 $_SESSION['usces_member']['address3'] = $member['mem_address3'];
5029 $_SESSION['usces_member']['tel'] = $member['mem_tel'];
5030 $_SESSION['usces_member']['fax'] = $member['mem_fax'];
5031 $_SESSION['usces_member']['delivery_flag'] = $member['mem_delivery_flag'];
5032 $_SESSION['usces_member']['delivery'] = ! empty( $member['mem_delivery'] ) ? wel_safe_unserialize( $member['mem_delivery'] ) : '';
5033 $_SESSION['usces_member']['registered'] = $member['mem_registered'];
5034 $_SESSION['usces_member']['nicename'] = $member['mem_nicename'];
5035 $_SESSION['usces_member']['country'] = $this->get_member_meta_value( 'customer_country', $member['ID'] );
5036 $_SESSION['usces_member']['status'] = $member['mem_status'];
5037 $this->set_session_custom_member( $member['ID'] );
5038 $this->get_current_member();
5039
5040 do_action( 'usces_action_after_login' );
5041 return apply_filters( 'usces_filter_member_login', 'member', $member );
5042 }
5043 }
5044
5045 public function member_logout() {
5046 do_action( 'usces_action_before_logout' );
5047 $cookie = $this->get_cookie();
5048 $cookie['name'] = '';
5049 $cookie['rme'] = '';
5050 $options = get_option( 'usces' );
5051
5052 $this->set_cookie( $cookie );
5053
5054 $fcookie = $this->get_cookie( $options['usces_key'] );
5055
5056 unset( $_SESSION['usces_member'], $_SESSION['usces_entry'] );
5057 do_action( 'usces_action_member_logout' );
5058 }
5059
5060 public function get_current_member() {
5061 if ( isset( $_SESSION['usces_member']['ID'] ) ) {
5062 $this->current_member['id'] = $_SESSION['usces_member']['ID'];
5063 $this->current_member['name'] = usces_localized_name( $_SESSION['usces_member']['name1'], $_SESSION['usces_member']['name2'], 'return' );
5064 } else {
5065 $this->current_member['id'] = 0;
5066 $this->current_member['name'] = __( 'guest', 'usces' );
5067 }
5068 }
5069
5070 public function get_member() {
5071 $res = array(
5072 'ID' => '',
5073 'registered' => '',
5074 'mailaddress1' => '',
5075 'mailaddress2' => '',
5076 'password1' => '',
5077 'password2' => '',
5078 'point' => '',
5079 'name1' => '',
5080 'name2' => '',
5081 'name3' => '',
5082 'name4' => '',
5083 'zipcode' => '',
5084 'address1' => '',
5085 'address2' => '',
5086 'address3' => '',
5087 'tel' => '',
5088 'fax' => '',
5089 'country' => '',
5090 'pref' => '',
5091 'status' => '',
5092 );
5093 if ( ! empty( $_SESSION['usces_member'] ) ) {
5094 foreach ( $_SESSION['usces_member'] as $key => $value ) {
5095 if ( is_array( $_SESSION['usces_member'][ $key ] ) ) {
5096 $res[ $key ] = stripslashes_deep( $value );
5097 } else {
5098 $res[ $key ] = null !== $value ? stripslashes( $value ) : '';
5099 }
5100 }
5101 }
5102 return $res;
5103 }
5104
5105 public function get_member_info( $mid ) {
5106 global $wpdb;
5107 $infos = array();
5108 $table = usces_get_tablename( 'usces_member' );
5109 $query = $wpdb->prepare( "SELECT * FROM $table WHERE ID = %d", $mid );
5110 $datas = $wpdb->get_results( $query, ARRAY_A );
5111 if ( $datas ) {
5112 $infos = $datas[0];
5113
5114 $table = usces_get_tablename( 'usces_member_meta' );
5115 $query = $wpdb->prepare( "SELECT meta_key, meta_value FROM $table WHERE member_id = %d", $mid );
5116 $metas = $wpdb->get_results( $query, ARRAY_A );
5117
5118 foreach ( $metas as $meta ) {
5119 $infos[ $meta['meta_key'] ] = wel_safe_maybe_unserialize( $meta['meta_value'] );
5120 }
5121 }
5122 return $infos;
5123 }
5124
5125 public function set_member_info( $data = array(), $mid = '' ) {
5126 global $wpdb;
5127
5128 $table = usces_get_tablename( 'usces_member' );
5129 $res = $wpdb->update( $table, $data, array( 'ID' => $mid ), null, array( '%d' ) );
5130 return $res;
5131 }
5132
5133 public function check_member_email( $email ) {
5134 global $wpdb;
5135
5136 $member_table_name = usces_get_tablename( 'usces_member' );
5137 $query = $wpdb->prepare( "SELECT ID FROM $member_table_name WHERE mem_email = %s", trim( $email ) );
5138 $id = $wpdb->get_var( $query );
5139 return $id;
5140 }
5141
5142 public function is_order( $mid, $oid ) {
5143 global $wpdb;
5144
5145 $mid = (int) $mid;
5146 $oid = (int) $oid;
5147
5148 $table = $wpdb->prefix . 'usces_order';
5149 $query = $wpdb->prepare( "SELECT ID FROM $table WHERE ID = %d AND mem_id = %d", $oid, $mid );
5150 $mem_id = $wpdb->get_var( $query );
5151 if ( empty( $mem_id ) ) {
5152 return false;
5153 } else {
5154 return true;
5155 }
5156 }
5157
5158 public function is_purchased_item( $mid, $post_id, $sku = null, $order_id = null ) {
5159 global $wpdb;
5160 $res = false;
5161
5162 if ( empty( $order_id ) ) {
5163 $history = $this->get_member_history( $mid, true );
5164 foreach ( $history as $umhs ) {
5165 $cart = $umhs['cart'];
5166 $status = $umhs['order_status'];
5167 $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
5168 for ( $i = 0; $i < $cart_count; $i++ ) {
5169 $cart_row = $cart[ $i ];
5170 $sku_code = urldecode( $cart_row['sku'] );
5171 if ( empty( $sku ) ) {
5172 if ( $cart_row['post_id'] == $post_id && ( false === strpos( $status, 'noreceipt' ) && false === strpos( $status, 'pending' ) ) ) {
5173 $res = true;
5174 break 2;
5175 } elseif ( $cart_row['post_id'] == $post_id && ( false !== strpos( $status, 'noreceipt' ) || false !== strpos( $status, 'pending' ) ) ) {
5176 $res = 'noreceipt';
5177 break 2;
5178 }
5179 } else {
5180 if ( $cart_row['post_id'] == $post_id && $sku_code == $sku && ( false === strpos( $status, 'noreceipt' ) && false === strpos( $status, 'pending' ) ) ) {
5181 $res = true;
5182 break 2;
5183 } elseif ( $cart_row['post_id'] == $post_id && $sku_code == $sku && (false !== strpos( $status, 'noreceipt' ) || false !== strpos( $status, 'pending' ) ) ) {
5184 $res = 'noreceipt';
5185 break 2;
5186 }
5187 }
5188 }
5189 }
5190 } else {
5191 $order_table_name = $wpdb->prefix . 'usces_order';
5192 $query = $wpdb->prepare( "SELECT order_status FROM $order_table_name WHERE ID = %d AND mem_id = %d",
5193 $order_id, $mid
5194 );
5195 $order = $wpdb->get_row( $query );
5196 if ( is_null( $order ) ) { // 該当の受注データが一件も見つからなかった場合、購入していないと判断する.
5197 $res = false;
5198 } else { // 該当の受注データが見つかった場合には受注ステータスを確認する処理を行う.
5199 $status = $order->order_status;
5200 $cart = usces_get_ordercartdata( $order_id );
5201 foreach ( $cart as $cart_row ) {
5202 $sku_code = urldecode( $cart_row['sku'] );
5203 if ( empty( $sku ) ) {
5204 if ( $cart_row['post_id'] == $post_id && ( false === strpos( $status, 'noreceipt' ) && false === strpos( $status, 'pending' ) && false === strpos( $status, 'cancel' ) ) ) {
5205 $res = true;
5206 break;
5207 } elseif ( $cart_row['post_id'] == $post_id && ( false !== strpos( $status, 'noreceipt' ) || false !== strpos( $status, 'pending' ) || false !== strpos( $status, 'cancel' ) ) ) {
5208 $res = 'noreceipt';
5209 break;
5210 }
5211 } else {
5212 if ( $cart_row['post_id'] == $post_id && $sku_code == $sku && ( false === strpos( $status, 'noreceipt' ) && false === strpos( $status, 'pending' ) && false === strpos( $status, 'cancel' ) ) ) {
5213 $res = true;
5214 break;
5215 } elseif ( $cart_row['post_id'] == $post_id && $sku_code == $sku && ( false !== strpos( $status, 'noreceipt' ) || false !== strpos( $status, 'pending' ) || false !== strpos( $status, 'cancel' ) ) ) {
5216 $res = 'noreceipt';
5217 break;
5218 }
5219 }
5220 }
5221 }
5222 }
5223
5224 return apply_filters( 'usces_filter_is_purchased_item', $res, $mid, $post_id, $sku, $order_id );
5225 }
5226
5227 public function get_order_data( $order_id, $mode = '' ) {
5228 global $wpdb;
5229 $order_table = $wpdb->prefix . 'usces_order';
5230
5231 $query = $wpdb->prepare( "SELECT * FROM $order_table WHERE ID = %d", $order_id );
5232
5233 if ( 'direct' == $mode ) {
5234 $value = $wpdb->get_row( $query, ARRAY_A );
5235 return $value;
5236 }
5237
5238 $value = $wpdb->get_row( $query );
5239
5240 if ( null == $value ) {
5241 return false;
5242 } else {
5243 $res = array();
5244 }
5245 if ( strpos( $value->order_status, 'cancel' ) !== false || strpos( $value->order_status, 'estimate' ) !== false ) {
5246 return false;
5247 }
5248
5249 $total_price = $value->order_item_total_price - $value->order_usedpoint + $value->order_discount + $value->order_shipping_charge + $value->order_cod_fee + $value->order_tax;
5250 if ( $total_price < 0 ) {
5251 $total_price = 0;
5252 }
5253 $res = array(
5254 'ID' => $value->ID,
5255 'mem_id' => $value->mem_id,
5256 'cart' => wel_safe_unserialize( $value->order_cart ),
5257 'condition' => wel_safe_unserialize( $value->order_condition ),
5258 'getpoint' => $value->order_getpoint,
5259 'usedpoint' => $value->order_usedpoint,
5260 'discount' => $value->order_discount,
5261 'payment_name' => $value->order_payment_name,
5262 'shipping_charge' => $value->order_shipping_charge,
5263 'cod_fee' => $value->order_cod_fee,
5264 'tax' => $value->order_tax,
5265 'end_price' => $total_price,
5266 'status' => $value->order_status,
5267 'date' => mysql2date( __( 'Y/m/d' ), $value->order_date ),
5268 'modified' => mysql2date( __( 'Y/m/d' ), $value->order_modified ),
5269 );
5270
5271 return $res;
5272 }
5273
5274 public function get_orderIDs_by_postID( $mem_id, $post_id ) {
5275 global $wpdb;
5276 $order_table = $wpdb->prefix . 'usces_order';
5277
5278 $query = $wpdb->prepare( "SELECT ID, order_cart, order_status FROM $order_table WHERE mem_id = %d ORDER BY order_modified DESC, order_date DESC", $mem_id );
5279 $rows = $wpdb->get_query( $query, ARRAY_A );
5280
5281 if ( null == $value ) {
5282 return false;
5283 } else {
5284 foreach ( $rows as $row ) {
5285 if ( strpos( $row['order_status'], 'cancel' ) !== false || strpos( $row['order_status'], 'estimate' ) !== false ) {
5286 continue;
5287 } else {
5288 $carts = wel_safe_unserialize( $row['order_cart'] );
5289 foreach ( $carts as $cart ) {
5290 if ( $post_id == $cart['post_id'] ) {
5291 $res[] = $row['ID'];
5292 break;
5293 }
5294 }
5295 }
5296 }
5297 }
5298 return $res;
5299 }
5300
5301 public function incart_check() {
5302 $mes = array();
5303
5304 $ids = array_keys( $_POST['inCart'] );
5305 $post_id = $ids[0];
5306 $skus = array_keys( $_POST['inCart'][ $post_id ] );
5307 $sku = $skus[0];
5308 $sku_code = urldecode( $sku );
5309 $quant = isset( $_POST['quant'][ $post_id ][ $sku ] ) ? (int) $_POST['quant'][ $post_id ][ $sku ] : 1;
5310 $stock = $this->getItemZaikoNum( $post_id, $sku );
5311 $zaiko_id = (int) $this->getItemZaikoStatusId( $post_id, $sku );
5312 $product = wel_get_product( $post_id );
5313 $itemRestriction = isset( $product['itemRestriction'] ) ? $product['itemRestriction'] : '';
5314 $itemOrderAcceptable = $this->getItemOrderAcceptable( $post_id );
5315
5316 if ( 1 > $quant ) {
5317 $mes[ $post_id ][ $sku ] = __( 'enter the correct amount', 'usces' ) . '<br />';
5318 } elseif ( $quant > (int) $itemRestriction && ! WCUtils::is_blank( $itemRestriction ) && ! WCUtils::is_zero( $itemRestriction ) ) {
5319 $mes[ $post_id ][ $sku ] = sprintf( __( 'This article is limited by %d at a time.', 'usces' ), $itemRestriction ) . '<br />';
5320 } elseif ( 1 != $itemOrderAcceptable && $quant > (int) $stock && ! WCUtils::is_blank( $stock ) ) {
5321 $mes[ $post_id ][ $sku ] = __( 'Sorry, stock is insufficient.', 'usces' ) . ' ' . __( 'Current stock', 'usces' ) . $stock . '<br />';
5322 } elseif ( 1 != $itemOrderAcceptable && !$this->is_item_zaiko( $post_id, $sku_code ) ) {
5323 $mes[ $post_id ][ $sku ] = __( 'Sorry, this item is sold out.', 'usces' ) . '<br />';
5324 } else {
5325 $mes[ $post_id ][ $sku ] = '';
5326 }
5327
5328 $ioptkeys = $this->get_itemOptionKey( $post_id, true );
5329 if ( $ioptkeys ) {
5330 foreach ( $ioptkeys as $key => $value ) {
5331 $optValues = $this->get_itemOptions( urldecode( $value ), $post_id );
5332 if ( 0 == $optValues['means'] ) { // case of select.
5333 if ( $optValues['essential'] && '#NONE#' == $_POST['itemOption'][ $post_id ][ $sku ][ $value ] ) {
5334 $mes[ $post_id ][ $sku ] .= sprintf( __( 'Chose the %s', 'usces' ), urldecode( $value ) ) . '<br />';
5335 }
5336 } elseif ( 1 == $optValues['means'] ) { // case of multiselect.
5337 if ( $optValues['essential'] ) {
5338 $mselect = 0;
5339 foreach ( (array) $_POST['itemOption'][ $post_id ][ $sku ][ $value ] as $mvalue ) {
5340 if ( ! empty( $mvalue ) && '#NONE#' != $mvalue ) {
5341 $mselect++;
5342 }
5343 }
5344 if ( $mselect == 0 ) {
5345 $mes[ $post_id ][ $sku ] .= sprintf( __( 'Chose the %s', 'usces' ), urldecode( $value ) ) . '<br />';
5346 }
5347 }
5348 } elseif ( in_array( $optValues['means'], array( 3, 4 ) ) ) { // case of radio & checkbox.
5349 if ( $optValues['essential'] ) {
5350 if ( ! isset( $_POST['itemOption'][ $post_id ][ $sku ][ $value ] ) ) {
5351 $mes[ $post_id ][ $sku ] .= sprintf( __( 'Chose the %s', 'usces' ), urldecode( $value ) ) . '<br />';
5352 }
5353 }
5354 } else { // case of text.
5355 if ( $optValues['essential'] && WCUtils::is_blank( $_POST['itemOption'][ $post_id ][ $sku ][ $value ] ) ) {
5356 $mes[ $post_id ][ $sku ] .= sprintf( __( 'Input the %s', 'usces' ), urldecode( $value ) ) . '<br />';
5357 }
5358 }
5359 }
5360 }
5361
5362 $mes = apply_filters( 'usces_filter_incart_check', $mes, $post_id, $sku );
5363
5364 if ( isset( $mes[ $post_id ] ) && is_array( $mes[ $post_id ] ) ) {
5365 $rembr = array();
5366 foreach ( $mes[ $post_id ] as $skukey => $skuvalue ) {
5367 if ( ! empty( $skuvalue ) ) {
5368 $rembr[ $post_id ][ $skukey ] = preg_replace( '/<br\s*\/?>\s*$/', '', $skuvalue );
5369 }
5370 }
5371 $mes = $rembr;
5372 }
5373
5374 if ( ! empty( $mes ) ) {
5375 $_SESSION['usces_singleitem']['itemOption'] = isset( $_POST['itemOption'] ) ? $_POST['itemOption'] : array();
5376 $_SESSION['usces_singleitem']['quant'] = isset( $_POST['quant'] ) ? (int) $_POST['quant'] : 1;
5377 $_SESSION['usces_singleitem']['error_message'] = $mes;
5378 if ( false === strpos( $_POST['usces_referer'], 'http' ) ) {
5379 $parse_url = parse_url( get_home_url() );
5380 $port = '';
5381 if ( isset( $parse_url['port'] ) && ! empty( $parse_url['port'] ) ) {
5382 $port = ':' . $parse_url['port'];
5383 }
5384 header( 'location: ' . $parse_url['scheme'] . '://' . $parse_url['host'] . $port . esc_url( $_POST['usces_referer'] ) . apply_filters( 'usces_filter_incart_redirect', '#cart_button', $post_id, $sku ) );
5385 } else {
5386 header( 'location: ' . esc_url( $_POST['usces_referer'] ) . apply_filters( 'usces_filter_incart_redirect', '#cart_button', $post_id, $sku ) );
5387 }
5388 exit;
5389 }
5390
5391 do_action( 'usces_action_incart_checked', $mes, $post_id, $sku );
5392 }
5393
5394 public function zaiko_check() {
5395
5396 $logged_in_member = $this->get_member();
5397 if ( ! empty( $logged_in_member['ID'] ) ) {
5398 if ( ! $this->member_exists( $logged_in_member['ID'] ) ) {
5399 $mes = __( 'Your membership information could not be verified.', 'usces' );
5400 $this->error_message = $mes;
5401 $this->member_logout();
5402 return $mes;
5403 }
5404 }
5405
5406 $mes = '';
5407 $cart = $this->cart->get_cart();
5408 $stocks = array();
5409
5410 $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
5411 for ( $i = 0; $i < $cart_count; $i++ ) {
5412 $cart_row = $cart[ $i ];
5413 $post_id = $cart_row['post_id'];
5414 $sku = $cart_row['sku'];
5415 $sku_code = urldecode( $cart_row['sku'] );
5416
5417 $quant = ( isset( $_POST['quant'][ $i ][ $post_id ][ $sku ] ) ) ? trim( $_POST['quant'][ $i ][ $post_id ][ $sku ] ) : $cart_row['quantity'];
5418 $zaiko_id = (int) $this->getItemZaikoStatusId( $post_id, $sku_code );
5419 $stock = $this->getItemZaikoNum( $post_id, $sku_code );
5420 if ( ! isset( $stocks[ $post_id ][ $sku ] ) ) {
5421 if ( ! WCUtils::is_blank( $stock ) ) {
5422 $stocks[ $post_id ][ $sku ] = $stock;
5423 } else {
5424 $stocks[ $post_id ][ $sku ] = null;
5425 }
5426 }
5427 $checkstock = $stocks[ $post_id ][ $sku ];
5428 $stocks[ $post_id ][ $sku ] = $stocks[ $post_id ][ $sku ] - $quant;
5429 $product = wel_get_product( $post_id );
5430 $itemRestriction = isset( $product['itemRestriction'] ) ? $product['itemRestriction'] : '';
5431 $itemOrderAcceptable = $this->getItemOrderAcceptable( $post_id );
5432 $post_status = get_post_status( $post_id );
5433
5434 if ( 1 > (int) $quant ) {
5435 $mes .= sprintf( __( 'Enter the correct amount for the No.%d item.', 'usces' ), ( $i + 1 ) ) . '<br />';
5436 } elseif ( ! $this->is_item_zaiko( $post_id, $sku_code ) || ( 1 != $itemOrderAcceptable && WCUtils::is_zero( $stock ) ) || 'publish' != $post_status ) {
5437 $mes .= sprintf( __( 'Sorry, No.%d item is sold out.', 'usces' ), ( $i + 1 ) ) . '<br />';
5438 } elseif ( $quant > (int) $itemRestriction && ! WCUtils::is_blank( $itemRestriction ) && ! WCUtils::is_zero( $itemRestriction ) ) {
5439 $mes .= sprintf( __( 'This article is limited by %1$d at a time for the No.%2$d item.', 'usces' ), $itemRestriction, ( $i + 1 ) ) . '<br />';
5440 } elseif ( 1 != $itemOrderAcceptable && 0 > $stocks[ $post_id ][ $sku ] && ! WCUtils::is_blank( $stock ) ) {
5441 $mes .= sprintf( __( 'Stock of No.%1$d item is remainder %2$d.', 'usces' ), ( $i + 1 ), $checkstock ) . '<br />';
5442 }
5443 }
5444 $mes = apply_filters( 'usces_filter_zaiko_check', $mes, $cart);
5445 return $mes;
5446 }
5447
5448 /**
5449 * Check if the member exists in the database or not.
5450 *
5451 * @param integer $member_id The id of the member.
5452 * @return boolean true/false
5453 */
5454 public function member_exists( $member_id ) {
5455 $member_info = $this->get_member_info( $member_id );
5456 if ( empty( $member_info ) ) {
5457 return false;
5458 } else {
5459 return true;
5460 }
5461 }
5462
5463 public function get_pwd_errors( $password ) {
5464 if ( WCUtils::is_blank( $password ) ) {
5465 return __( 'Please enter a password.', 'usces' ) . '<br />';
5466 }
5467
5468 $ret = '';
5469 $system_option = $this->options['system'];
5470 $pwd_rule_min = $system_option['member_pass_rule_min'];
5471 $pwd_rule_max = empty( $system_option['member_pass_rule_max'] ) ? 30 : $system_option['member_pass_rule_max'];
5472 if ( strlen( $password ) < $pwd_rule_min || strlen( $password ) > $pwd_rule_max ) {
5473 if ( $pwd_rule_min === $pwd_rule_max ) {
5474 $rule = sprintf( __( '%s characters long', 'usces' ), $pwd_rule_min );
5475 } else {
5476 $rule = sprintf( __( '%1$s characters and no more than %2$s characters', 'usces' ), $pwd_rule_min, $pwd_rule_max );
5477 }
5478 $ret .= sprintf( __( 'Password must be at least %s.', 'usces' ), $rule ) . '<br />';
5479 }
5480 if ( ! empty( $system_option['member_pass_rule_upercase'] ) && ! preg_match( '@[A-Z]@', $password ) ) {
5481 $ret .= __( 'Password must contain at least one upper-case alphabetics character.', 'usces' ) . '<br />';
5482 }
5483 if ( ! empty( $system_option['member_pass_rule_lowercase'] ) && ! preg_match( '@[a-z]@', $password ) ) {
5484 $ret .= __( 'Password must contain at least one lower-case alphabetics character.', 'usces' ) . '<br />';
5485 }
5486 if ( ! empty( $system_option['member_pass_rule_digit'] ) && ! preg_match( '@[0-9]@', $password ) ) {
5487 $ret .= __( 'Password must contain at least one numeric character.', 'usces' ) . '<br />';
5488 }
5489 if ( ! empty( $system_option['member_pass_rule_symbol'] ) && ! preg_match( '@[\W]@', $password ) ) {
5490 $ret .= __( 'Password must contain at least one symbolic character.', 'usces' ) . '<br />';
5491 }
5492
5493 return $ret;
5494 }
5495
5496 public function member_check() {
5497 do_action( 'usces_action_before_member_check' );
5498
5499 $mes = '';
5500 $usces_member_old = $_SESSION['usces_member'];
5501 foreach ( $_POST['member'] as $key => $vlue ) {
5502 if ( 'password1' !== $key && 'password2' !== $key && 'mailaddress2' !== $key ) {
5503 $_SESSION['usces_member'][ $key ] = trim( $vlue );
5504 }
5505 }
5506
5507 if ( 'newmemberform' == $_POST['member_regmode'] ||
5508 ( 'editmemberform' === $_POST['member_regmode'] && ! ( WCUtils::is_blank( $_POST['member']['password1'] ) && WCUtils::is_blank( $_POST['member']['password2'] ) ) ) ||
5509 ( 'updatememberform' === $_POST['member_regmode'] && ! ( WCUtils::is_blank( $_POST['member']['password1'] ) && WCUtils::is_blank( $_POST['member']['password2'] ) ) ) ) {
5510 $mes = $this->get_pwd_errors( $_POST['member']['password1'] );
5511 }
5512
5513 if ( 'editmemberform' == $_POST['member_regmode'] || 'updatememberform' == $_POST['member_regmode'] ) {
5514 if ( trim( $_POST['member']['password1'] ) != trim( $_POST['member']['password2'] ) ) {
5515 $mes .= __( 'Password confirm does not match.', 'usces' ) . '<br />';
5516 }
5517 if ( ! is_email( $_POST['member']['mailaddress1'] ) || WCUtils::is_blank( $_POST['member']['mailaddress1'] ) ) {
5518 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5519 } else {
5520 $this->get_current_member();
5521 $mem_id = $this->current_member['id'];
5522 $id = $this->check_member_email( $_POST['member']['mailaddress1'] );
5523 if ( ! empty( $id ) && $id != $mem_id ) {
5524 $mes .= __( 'This e-mail address can not be registered.', 'usces' ) . '<br />';
5525 } else {
5526 if ( isset( $_POST['member']['mailaddress2'] ) ) {
5527 if ( WCUtils::is_blank( $_POST['member']['mailaddress2'] ) ) {
5528 if ( $usces_member_old['mailaddress1'] !== $_POST['member']['mailaddress1'] ) {
5529 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5530 }
5531 } else {
5532 if ( trim( $_POST['member']['mailaddress1'] ) != trim( $_POST['member']['mailaddress2'] ) ) {
5533 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5534 }
5535 }
5536 }
5537 }
5538 }
5539 } elseif ( 'newmemberform' == $_POST['member_regmode'] ) {
5540 if ( trim( $_POST['member']['password1'] ) != trim( $_POST['member']['password2'] ) ) {
5541 $mes .= __( 'Password confirm does not match.', 'usces' ) . '<br />';
5542 }
5543 if ( ! is_email( $_POST['member']['mailaddress1'] ) || WCUtils::is_blank( $_POST['member']['mailaddress1'] ) || WCUtils::is_blank( $_POST['member']['mailaddress2'] ) || trim( $_POST['member']['mailaddress1'] ) != trim( $_POST['member']['mailaddress2'] ) ) {
5544 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5545 } else {
5546 $id = $this->check_member_email( $_POST['member']['mailaddress1'] );
5547 if ( ! empty( $id ) ) {
5548 $mes .= __( 'This e-mail address can not be registered.', 'usces' ) . '<br />';
5549 }
5550 }
5551 } else {
5552 $mes .= __( 'ERROR: I was not able to complete collective operation', 'usces' ) . '<br />';
5553 }
5554 if ( WCUtils::is_blank( $_POST['member']['name1'] ) ) {
5555 $mes .= __( 'Name is not correct', 'usces' ) . '<br />';
5556 }
5557
5558 $zip_check = false;
5559 $addressform = $this->options['system']['addressform'];
5560 $applyform = usces_get_apply_addressform( $addressform );
5561 if ( 'JP' === $applyform ) {
5562 if ( isset( $_POST['member']['country'] ) ) {
5563 if ( 'JP' === $_POST['member']['country'] ) {
5564 $zip_check = true;
5565 }
5566 } else {
5567 $base = usces_get_base_country();
5568 if ( 'JP' === $base ) {
5569 $zip_check = true;
5570 }
5571 }
5572 }
5573 $zip_check = apply_filters( 'usces_filter_zipcode_check', $zip_check );
5574 if ( WCUtils::is_blank( $_POST['member']['zipcode'] ) ) {
5575 if ( usces_is_required_field('zipcode') ) {
5576 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5577 }
5578 } else {
5579 if ( $zip_check ) {
5580 if ( ! preg_match( '/^[a-zA-Z0-9]+$/', $_POST['member']['zipcode'] ) ) {
5581 $_SESSION['usces_member']['zipcode'] = usces_convert_zipcode( $_POST['member']['zipcode'] );
5582 }
5583 if ( ! preg_match( '/^(([0-9]{3}-[0-9]{4})|([0-9]{7}))$/', $_SESSION['usces_member']['zipcode'] ) ) {
5584 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5585 }
5586 }
5587 }
5588 if ( __( '-- Select --', 'usces_dual' ) == $_POST['member']['pref'] && usces_is_required_field( 'states' ) ) {
5589 $mes .= __( 'enter the prefecture', 'usces' ) . '<br />';
5590 }
5591 if ( WCUtils::is_blank( $_POST['member']['address1'] ) && usces_is_required_field( 'address1' ) ) {
5592 $mes .= __( 'enter the city name', 'usces' ) . '<br />';
5593 }
5594 if ( WCUtils::is_blank( $_POST['member']['address2'] ) && usces_is_required_field( 'address2' ) ) {
5595 $mes .= __( 'enter house numbers', 'usces' ) . '<br />';
5596 }
5597 if ( WCUtils::is_blank( $_POST['member']['tel'] ) && usces_is_required_field( 'tel' ) ) {
5598 $mes .= __( 'enter phone numbers', 'usces' ) . '<br />';
5599 }
5600 if ( ! WCUtils::is_blank( $_POST['member']['tel'] ) && preg_match( '/[^\d\-+]/', trim( $_POST['member']['tel'] ) ) && usces_is_required_field( 'tel' ) ) {
5601 $mes .= __( 'Please input a phone number with a half size number.', 'usces' ) . '<br />';
5602 }
5603
5604 if ( 'editmemberform' !== $_POST['member_regmode'] && 'updatememberform' !== $_POST['member_regmode'] && isset( $this->options['agree_member'] ) && 'activate' === $this->options['agree_member'] ) {
5605 if ( ! isset( $_POST['agree_member_check'] ) ) {
5606 $mes .= __( 'Please accept the membership agreement.', 'usces' ) . '<br />';
5607 }
5608 }
5609
5610 $mes = apply_filters( 'usces_filter_member_check', $mes );
5611
5612 if ( ( 'editmemberform' == $_POST['member_regmode'] || 'updatememberform' == $_POST['member_regmode'] ) && '' != $mes ) {
5613 $_SESSION['usces_member'] = $usces_member_old;
5614 }
5615
5616 return $mes;
5617 }
5618
5619 public function member_check_fromcart() {
5620
5621 do_action( 'usces_action_before_member_check_fromcart' );
5622
5623 $mes = $this->get_pwd_errors( $_POST['customer']['password1'] );
5624
5625 if ( trim( $_POST['customer']['password1'] ) != trim( $_POST['customer']['password2'] ) ) {
5626 $mes .= __( 'Password confirm does not match.', 'usces' ) . '<br />';
5627 }
5628 if ( ! is_email( $_POST['customer']['mailaddress1'] ) || WCUtils::is_blank( $_POST['customer']['mailaddress1'] ) || WCUtils::is_blank( $_POST['customer']['mailaddress2'] ) || trim( $_POST['customer']['mailaddress1'] ) != trim( $_POST['customer']['mailaddress2'] ) ) {
5629 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5630 }
5631 if ( WCUtils::is_blank( $_POST['customer']['name1'] ) ) {
5632 $mes .= __( 'Name is not correct', 'usces' ) . '<br />';
5633 }
5634 $zip_check = false;
5635 $addressform = $this->options['system']['addressform'];
5636 $applyform = usces_get_apply_addressform( $addressform );
5637 if ( 'JP' === $applyform ) {
5638 if ( isset( $_POST['customer']['country'] ) ) {
5639 if ( 'JP' === $_POST['customer']['country'] ) {
5640 $zip_check = true;
5641 }
5642 } else {
5643 $base = usces_get_base_country();
5644 if ( 'JP' === $base ) {
5645 $zip_check = true;
5646 }
5647 }
5648 }
5649 $zip_check = apply_filters( 'usces_filter_zipcode_check', $zip_check );
5650 if ( WCUtils::is_blank( $_POST['customer']['zipcode'] ) ) {
5651 if ( usces_is_required_field( 'zipcode' ) ) {
5652 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5653 }
5654 } else {
5655 if ( $zip_check ) {
5656 if ( ! preg_match( '/^[a-zA-Z0-9]+$/', $_POST['customer']['zipcode'] ) ) {
5657 $_SESSION['usces_entry']['customer']['zipcode'] = usces_convert_zipcode( $_POST['customer']['zipcode'] );
5658 }
5659 if ( ! preg_match( '/^(([0-9]{3}-[0-9]{4})|([0-9]{7}))$/', $_SESSION['usces_entry']['customer']['zipcode'] ) ) {
5660 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5661 }
5662 }
5663 }
5664 if ( ( __( '-- Select --', 'usces' ) == $_POST['customer']['pref'] || '-- Select --' == $_POST['customer']['pref'] ) && usces_is_required_field( 'states' ) ) {
5665 $mes .= __( 'enter the prefecture', 'usces' ) . '<br />';
5666 }
5667 if ( WCUtils::is_blank( $_POST['customer']['address1'] ) && usces_is_required_field( 'address1' ) ) {
5668 $mes .= __( 'enter the city name', 'usces' ) . '<br />';
5669 }
5670 if ( WCUtils::is_blank( $_POST['customer']['address2'] ) && usces_is_required_field( 'address2' ) ) {
5671 $mes .= __( 'enter house numbers', 'usces' ) . '<br />';
5672 }
5673 if ( WCUtils::is_blank( $_POST['customer']['tel'] ) && usces_is_required_field( 'tel' ) ) {
5674 $mes .= __( 'enter phone numbers', 'usces' ) . '<br />';
5675 }
5676 if ( ! WCUtils::is_blank( $_POST['customer']['tel'] ) && preg_match( '/[^\d\-+]/', trim( $_POST['customer']['tel'] ) ) && usces_is_required_field( 'tel' ) ) {
5677 $mes .= __( 'Please input a phone number with a half size number.', 'usces' ) . '<br />';
5678 }
5679
5680 if ( isset( $this->options['agree_member'] ) && 'activate' === $this->options['agree_member'] ) {
5681 if ( ! isset( $_POST['agree_member_check'] ) ) {
5682 $mes .= __( 'Please accept the membership agreement.', 'usces' ) . '<br />';
5683 }
5684 }
5685
5686 $mes = apply_filters( 'usces_filter_member_check_fromcart', $mes );
5687
5688 return $mes;
5689 }
5690
5691 public function admin_member_check() {
5692 global $wpdb;
5693 $mes = '';
5694 if ( ! is_email( trim( $_POST['member']['email'] ) ) ) {
5695 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5696 } else {
5697 $member_table = usces_get_tablename( 'usces_member' );
5698 $mem_email = $wpdb->get_var( $wpdb->prepare( "SELECT mem_email FROM $member_table WHERE ID = %d LIMIT 1", trim( $_POST['member_id'] ) ) );
5699 if ( trim( $_POST['member']['email'] ) != $mem_email ) {
5700 $mem_ID = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $member_table WHERE mem_email = %s LIMIT 1", trim( $_POST['member']['email'] ) ) );
5701 if ( ! empty( $mem_ID ) ) {
5702 $mes .= __( 'This e-mail address has been already registered.', 'usces' ) . '<br />';
5703 }
5704 }
5705 }
5706 if ( WCUtils::is_blank( $_POST['member']['name1'] ) ) {
5707 $mes .= __( 'Name is not correct', 'usces' ) . '<br />';
5708 }
5709 if ( ! WCUtils::is_blank( $_POST['member']['tel'] ) && preg_match( '/[^\d\-+]/', trim( $_POST['member']['tel'] ) ) ) {
5710 $mes .= __( 'Please input a phone number with a half size number.', 'usces' ) . '<br />';
5711 }
5712 $mes = apply_filters( 'usces_filter_admin_member_check', $mes );
5713
5714 return $mes;
5715 }
5716
5717 public function customer_check() {
5718
5719 do_action( 'usces_action_before_customer_check' );
5720
5721 $mes = '';
5722 if ( ! is_email( $_POST['customer']['mailaddress1'] ) || WCUtils::is_blank( $_POST['customer']['mailaddress1'] ) || WCUtils::is_blank( $_POST['customer']['mailaddress2'] ) || trim( $_POST['customer']['mailaddress1'] ) != trim( $_POST['customer']['mailaddress2'] ) ) {
5723 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5724 }
5725 if ( WCUtils::is_blank( $_POST['customer']['name1'] ) ) {
5726 $mes .= __( 'Name is not correct', 'usces' ) . '<br />';
5727 }
5728 $zip_check = false;
5729 $addressform = $this->options['system']['addressform'];
5730 $applyform = usces_get_apply_addressform( $addressform );
5731 if ( 'JP' === $applyform ) {
5732 if ( isset( $_POST['customer']['country'] ) ) {
5733 if ( 'JP' === $_POST['customer']['country'] ) {
5734 $zip_check = true;
5735 }
5736 } else {
5737 $base = usces_get_base_country();
5738 if ( 'JP' === $base ) {
5739 $zip_check = true;
5740 }
5741 }
5742 }
5743 $zip_check = apply_filters( 'usces_filter_zipcode_check', $zip_check );
5744 if ( WCUtils::is_blank( $_POST['customer']['zipcode'] ) ) {
5745 if ( usces_is_required_field( 'zipcode' ) ) {
5746 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5747 }
5748 } else {
5749 if ( $zip_check ) {
5750 if ( ! preg_match( '/^[a-zA-Z0-9]+$/', $_POST['customer']['zipcode'] ) ) {
5751 $_SESSION['usces_entry']['customer']['zipcode'] = usces_convert_zipcode( $_POST['customer']['zipcode'] );
5752 }
5753 if ( ! preg_match( '/^(([0-9]{3}-[0-9]{4})|([0-9]{7}))$/', $_SESSION['usces_entry']['customer']['zipcode'] ) ) {
5754 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5755 }
5756 }
5757 }
5758 if ( ( __( '-- Select --', 'usces' ) == $_POST['customer']['pref'] || '-- Select --' == $_POST['customer']['pref'] ) && usces_is_required_field( 'states' ) ) {
5759 $mes .= __( 'enter the prefecture', 'usces' ) . '<br />';
5760 }
5761 if ( WCUtils::is_blank( $_POST['customer']['address1'] ) && usces_is_required_field( 'address1' ) ) {
5762 $mes .= __( 'enter the city name', 'usces' ) . '<br />';
5763 }
5764 if ( WCUtils::is_blank( $_POST['customer']['address2'] ) && usces_is_required_field( 'address2' ) ) {
5765 $mes .= __( 'enter house numbers', 'usces' ) . '<br />';
5766 }
5767 if ( WCUtils::is_blank( $_POST['customer']['tel'] ) && usces_is_required_field( 'tel' ) ) {
5768 $mes .= __( 'enter phone numbers', 'usces' ) . '<br />';
5769 }
5770 if ( ! WCUtils::is_blank( $_POST['customer']['tel'] ) && preg_match( '/[^\d\-+]/', trim( $_POST['customer']['tel'] ) ) && usces_is_required_field( 'tel' ) ) {
5771 $mes .= __( 'Please input a phone number with a half size number.', 'usces' ) . '<br />';
5772 }
5773
5774 $mes = apply_filters( 'usces_filter_customer_check', $mes );
5775
5776 return $mes;
5777 }
5778
5779 public function admin_new_member_check() {
5780 global $wpdb;
5781
5782 $mes = $this->get_pwd_errors( $_POST['member']['password'] );
5783
5784 if ( ! is_email( trim( $_POST['member']['email'] ) ) ) {
5785 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5786 } else {
5787 $member_table = usces_get_tablename( 'usces_member' );
5788 $mem_email = $wpdb->get_var( $wpdb->prepare( "SELECT mem_email FROM $member_table WHERE ID = %d LIMIT 1", trim( $_POST['member_id'] ) ) );
5789 if ( trim( $_POST['member']['email'] ) != $mem_email ) {
5790 $mem_ID = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $member_table WHERE mem_email = %s LIMIT 1", trim( $_POST['member']['email'] ) ) );
5791 if ( ! empty( $mem_ID ) ) {
5792 $mes .= __( 'This e-mail address has been already registered.', 'usces' ) . '<br />';
5793 }
5794 }
5795 }
5796
5797 if ( WCUtils::is_blank( $_POST['member']['name1'] ) ) {
5798 $mes .= __( 'Name is not correct', 'usces' ) . '<br />';
5799 }
5800 if ( ! WCUtils::is_blank( $_POST['member']['tel'] ) && preg_match( '/[^\d\-+]/', trim( $_POST['member']['tel'] ) ) ) {
5801 $mes .= __( 'Please input a phone number with a half size number.', 'usces' ) . '<br />';
5802 }
5803 $mes = apply_filters( 'usces_filter_admin_member_check', $mes );
5804
5805 return $mes;
5806 }
5807
5808 public function delivery_check() {
5809 global $usces_settings;
5810
5811 do_action( 'usces_action_before_delivery_check' );
5812
5813 $mes = '';
5814 if ( isset( $_POST['delivery']['delivery_flag'] ) && 1 === (int) $_POST['delivery']['delivery_flag'] ) {
5815 if ( WCUtils::is_blank( $_POST['delivery']['name1'] ) ) {
5816 $mes .= __( 'Name is not correct', 'usces' ) . '<br />';
5817 }
5818 $zip_check = false;
5819 $addressform = $this->options['system']['addressform'];
5820 $applyform = usces_get_apply_addressform( $addressform );
5821 if ( 'JP' === $applyform ) {
5822 if ( isset( $_POST['delivery']['country'] ) ) {
5823 if ( 'JP' === $_POST['delivery']['country'] ) {
5824 $zip_check = true;
5825 }
5826 } else {
5827 $base = usces_get_base_country();
5828 if ( 'JP' === $base ) {
5829 $zip_check = true;
5830 }
5831 }
5832 }
5833 $zip_check = apply_filters( 'usces_filter_zipcode_check', $zip_check );
5834 if ( WCUtils::is_blank( $_POST['delivery']['zipcode'] ) ) {
5835 if ( usces_is_required_field( 'zipcode' ) ) {
5836 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5837 }
5838 } else {
5839 if ( $zip_check ) {
5840 if ( ! preg_match( '/^[a-zA-Z0-9]+$/', $_POST['delivery']['zipcode'] ) ) {
5841 $_SESSION['usces_entry']['delivery']['zipcode'] = usces_convert_zipcode( $_POST['delivery']['zipcode'] );
5842 }
5843 if ( ! preg_match( '/^(([0-9]{3}-[0-9]{4})|([0-9]{7}))$/', $_SESSION['usces_entry']['delivery']['zipcode'] ) ) {
5844 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5845 }
5846 }
5847 }
5848 if ( ( __( '-- Select --', 'usces' ) == $_POST['delivery']['pref'] || '-- Select --' == $_POST['delivery']['pref'] ) && usces_is_required_field( 'states' ) ) {
5849 $mes .= __( 'enter the prefecture', 'usces' ) . '<br />';
5850 }
5851 if ( WCUtils::is_blank( $_POST['delivery']['address1'] ) && usces_is_required_field( 'address1' ) ) {
5852 $mes .= __( 'enter the city name', 'usces' ) . '<br />';
5853 }
5854 if ( WCUtils::is_blank( $_POST['delivery']['address2'] ) && usces_is_required_field( 'address2' ) ) {
5855 $mes .= __( 'enter house numbers', 'usces' ) . '<br />';
5856 }
5857 if ( WCUtils::is_blank( $_POST['delivery']['tel'] ) && usces_is_required_field( 'tel' ) ) {
5858 $mes .= __( 'enter phone numbers', 'usces' ) . '<br />';
5859 }
5860 if ( ! WCUtils::is_blank( $_POST['delivery']['tel'] ) && preg_match( '/[^\d\-+]/', trim( $_POST['delivery']['tel'] ) ) && usces_is_required_field( 'tel' ) ) {
5861 $mes .= __( 'Please input a phone number with a half size number.', 'usces' ) . '<br />';
5862 }
5863 $post_offer = filter_input( INPUT_POST, 'offer', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
5864 if ( ! empty( $post_offer['delivery_date'] ) && usces_is_date( $post_offer['delivery_date'] ) && isset( $post_offer['delivery_method'] ) ) {
5865 $post_delivery = filter_input( INPUT_POST, 'delivery', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
5866 $deli_method_index = $this->get_delivery_method_index( $post_offer['delivery_method'] );
5867 $delivery_days_id = isset( $this->options['delivery_method'][ $deli_method_index ]['days'] ) ? $this->options['delivery_method'][ $deli_method_index ]['days'] : -1;
5868 if ( 0 <= $delivery_days_id ) {
5869 $delivery_days_list = $this->options['delivery_days'];
5870 $delivery_days = 0;
5871 foreach ( (array) $delivery_days_list as $delivery_days_value ) {
5872 if ( (int) $delivery_days_value['id'] === (int) $delivery_days_id ) {
5873 $delivery_days = (int) $delivery_days_value[ $applyform ][ $post_delivery['pref'] ];
5874 }
5875 }
5876 $sendout = usces_get_send_out_date();
5877 $sendout_date = implode( '-', $sendout['sendout_date'] );
5878 $arrival_date = new DateTime( $sendout_date );
5879 $arrival_date->modify( '+' . $delivery_days . ' days' );
5880 $offer_deli_date = new DateTime( $post_offer['delivery_date'] );
5881 if ( $offer_deli_date < $arrival_date ) {
5882 $mes .= __( 'Please re-specify the desired arrival date.', 'usces' ) . '<br />';
5883 }
5884 } else {
5885 $mes .= __( 'Please re-specify the desired arrival date.', 'usces' ) . '<br />';
5886 }
5887 }
5888 }
5889 if ( ! isset( $_POST['offer']['delivery_method'] ) || ( empty( $_POST['offer']['delivery_method'] ) && ! WCUtils::is_zero( $_POST['offer']['delivery_method'] ) ) ) {
5890 $mes .= __( 'chose one from delivery method.', 'usces' ) . '<br />';
5891 } else {
5892 $d_method_index = $this->get_delivery_method_index( (int) $_POST['offer']['delivery_method'] );
5893 if ( 0 > $d_method_index ) {
5894 $mes .= __( 'chose one from delivery method.', 'usces' ) . '<br />';
5895 } elseif ( isset( $_SESSION['usces_entry']['delivery']['country'] ) ) {
5896 $country = $_SESSION['usces_entry']['delivery']['country'];
5897 $current_locate = get_locale();
5898 $wplang = get_option( 'WPLANG', $current_locate );
5899 $local_country = $usces_settings['lungage2country'][ $wplang ];
5900
5901 if ( $country == $local_country ) {
5902 if ( 1 == $this->options['delivery_method'][ $d_method_index ]['intl'] ) {
5903 $mes .= __( 'Delivery method is incorrect. Can not specify an international flight.', 'usces' ) . '<br />';
5904 }
5905 } else {
5906 if ( WCUtils::is_zero( $this->options['delivery_method'][ $d_method_index ]['intl'] ) ) {
5907 $mes .= __( 'Delivery method is incorrect. Specify the international flights.', 'usces' ) . '<br />';
5908 }
5909 }
5910 }
5911 }
5912 if ( ! isset( $_POST['offer']['payment_name'] ) ) {
5913 $mes .= __( 'chose one from payment options.', 'usces' ) . '<br />';
5914 } else {
5915 $payments = $this->getPayments( $_POST['offer']['payment_name'] );
5916 if ( 'COD' == $payments['settlement'] ) {
5917 $total_items_price = $this->get_total_price();
5918 $usces_entries = $this->cart->get_entry();
5919 $materials = array(
5920 'total_items_price' => $usces_entries['order']['total_items_price'],
5921 'discount' => ( isset( $usces_entries['order']['discount'] ) ) ? $usces_entries['order']['discount'] : 0,
5922 'shipping_charge' => $usces_entries['order']['shipping_charge'],
5923 'cod_fee' => $usces_entries['order']['cod_fee'],
5924 'use_point' => ( isset( $usces_entries['order']['use_point'] ) ) ? $usces_entries['order']['use_point'] : 0,
5925 );
5926 $tax = $this->getTax( $total_items_price, $materials );
5927 $total_items_price = $total_items_price + $tax;
5928 $cod_limit_amount = ( isset( $this->options['cod_limit_amount'] ) && 0 < (int) $this->options['cod_limit_amount'] ) ? $this->options['cod_limit_amount'] : 0;
5929 if ( 0 < $cod_limit_amount && $total_items_price > $cod_limit_amount ) {
5930 $mes .= sprintf( __( 'A total products amount of money surpasses the upper limit(%s) that I can purchase in C.O.D.', 'usces' ), usces_crform( $this->options['cod_limit_amount'], true, false, 'return' ) ) . '<br />';
5931 }
5932 }
5933 }
5934 if ( isset( $d_method_index ) && isset( $payments ) ) {
5935 if ( 1 == $this->options['delivery_method'][ $d_method_index ]['nocod'] ) {
5936 if ( 'COD' == $payments['settlement'] ) {
5937 $mes .= __( 'COD is not available.', 'usces' ) . '<br />';
5938 }
5939 }
5940 }
5941 $mes = apply_filters( 'usces_filter_delivery_check', $mes );
5942 return $mes;
5943 }
5944
5945 public function point_check( $entries ) {
5946 $member = $this->get_member();
5947 $this->set_cart_fees( $member, $entries );
5948
5949 $mes = '';
5950 if ( isset( $_POST['offer']['usedpoint'] ) ) {
5951 if ( WCUtils::is_blank( $_POST['offer']['usedpoint'] ) || ! preg_match( '/^[0-9]+$/', $_POST['offer']['usedpoint'] ) || (int) $_POST['offer']['usedpoint'] < 0 ) {
5952 $mes .= __( 'Invalid value. Please enter in the numbers.', 'usces' ) . '<br />';
5953
5954 } else {
5955 $payments = $this->getPayments( $entries['order']['payment_name'] );
5956 $usedpoint = (int) trim( $_POST['offer']['usedpoint'] );
5957 if ( $usedpoint > $member['point'] ) {
5958 $mes .= __( 'You have exceeded the maximum available.', 'usces' ) . ' ' . __( 'Max', 'usces' ) . ' ' . $member['point'] . ' ' . __( 'points', 'usces' ) . '<br />';
5959
5960 } elseif ( 'acting_paypal_ec' == $payments['settlement'] ) {
5961 $target_full_price = $entries['order']['total_items_price'] + $entries['order']['discount'] + $entries['order']['shipping_charge'] + $entries['order']['cod_fee'] + $entries['order']['tax'];
5962 $target_item_price = $entries['order']['total_items_price'] + $entries['order']['discount'];
5963 if ( 1 == $this->options['point_coverage'] && $usedpoint >= $target_full_price ) {
5964 $target_item_price = $target_full_price;
5965 } elseif ( 'products' == $this->options['tax_target'] ) {
5966 $target_item_price += $entries['order']['tax'];
5967 }
5968 if ( $usedpoint > $target_item_price ) {
5969 $mes .= __( "In the case of settlement method you choose, the upper limit of the point you'll find that will change. If you became a settlement error, please reduce the point that you want to use.", 'usces' ) . '<br />';
5970 }
5971
5972 } else {
5973 if ( 1 == $this->options['point_coverage'] ) {
5974 $target_full_price = $entries['order']['total_items_price'] + $entries['order']['discount'] + $entries['order']['shipping_charge'] + $entries['order']['cod_fee'] + $entries['order']['tax'];
5975 if ( $usedpoint > $target_full_price ) {
5976 $mes .= __( 'You have exceeded the maximum available.', 'usces' ) . ' ' . __( 'Max', 'usces' ) . ' ' . $target_full_price . ' ' . __( 'points', 'usces' ) . '<br />';
5977 }
5978 } else {
5979 $target_item_price = $entries['order']['total_items_price'] + $entries['order']['discount'];
5980 if ( 'products' == $this->options['tax_target'] ) {
5981 $target_item_price += $entries['order']['tax'];
5982 }
5983 if ( $usedpoint > $target_item_price ) {
5984 $mes .= __( 'You have exceeded the maximum available.', 'usces' ) . ' ' . __( 'Max', 'usces' ) . ' ' . $target_item_price . ' ' . __( 'points', 'usces' ) . '<br />';
5985 }
5986 }
5987 }
5988 $mes = apply_filters( 'usces_filter_point_check', $mes );
5989 if ( '' != $mes ) {
5990 $_POST['offer']['usedpoint'] = 0;
5991 $array = array(
5992 'usedpoint' => 0,
5993 );
5994 $this->cart->set_order_entry( $array );
5995 }
5996 }
5997 }
5998 $mes = apply_filters( 'usces_filter_point_check_last', $mes );
5999 return $mes;
6000 }
6001
6002 public function lostpass_mailaddcheck() {
6003 $mes = '';
6004 if ( ! is_email( $_POST['loginmail'] ) || WCUtils::is_blank( $_POST['loginmail'] ) ) {
6005 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
6006 }
6007
6008 return $mes;
6009 }
6010
6011 public function changepass_check() {
6012 $mes = $this->get_pwd_errors( $_POST['loginpass1'] );
6013
6014 if ( trim( $_POST['loginpass1'] ) != trim( $_POST['loginpass2'] ) ) {
6015 $mes .= __( 'Password confirm does not match.', 'usces' ) . '<br />';
6016 }
6017
6018 return $mes;
6019 }
6020
6021 public function get_page() {
6022 return $this->page;
6023 }
6024
6025 public function check_display_mode() {
6026 $options = get_option( 'usces' );
6027 if ( isset( $options['display_mode'] ) && 'Maintenancemode' == $options['display_mode'] ) {
6028 return;
6029 }
6030
6031 $start['hour'] = empty( $options['campaign_schedule']['start']['hour'] ) ? 0 : $options['campaign_schedule']['start']['hour'];
6032 $start['min'] = empty( $options['campaign_schedule']['start']['min'] ) ? 0 : $options['campaign_schedule']['start']['min'];
6033 $start['month'] = empty( $options['campaign_schedule']['start']['month'] ) ? 0 : $options['campaign_schedule']['start']['month'];
6034 $start['day'] = empty( $options['campaign_schedule']['start']['day'] ) ? 0 : $options['campaign_schedule']['start']['day'];
6035 $start['year'] = empty( $options['campaign_schedule']['start']['year'] ) ? 0 : $options['campaign_schedule']['start']['year'];
6036 $end['hour'] = empty( $options['campaign_schedule']['end']['hour'] ) ? 0 : $options['campaign_schedule']['end']['hour'];
6037 $end['min'] = empty( $options['campaign_schedule']['end']['min'] ) ? 0 : $options['campaign_schedule']['end']['min'];
6038 $end['month'] = empty( $options['campaign_schedule']['end']['month'] ) ? 0 : $options['campaign_schedule']['end']['month'];
6039 $end['day'] = empty( $options['campaign_schedule']['end']['day'] ) ? 0 : $options['campaign_schedule']['end']['day'];
6040 $end['year'] = empty( $options['campaign_schedule']['end']['year'] ) ? 0 : $options['campaign_schedule']['end']['year'];
6041 $starttime = mktime( $start['hour'], $start['min'], 0, $start['month'], $start['day'], $start['year'] );
6042 $endtime = mktime( $end['hour'], $end['min'], 0, $end['month'], $end['day'], $end['year'] );
6043 $current_time = current_time( 'timestamp' );
6044
6045 if ( ( $current_time >= $starttime ) && ( $current_time <= $endtime ) ) {
6046 $options['display_mode'] = 'Promotionsale';
6047 } else {
6048 $options['display_mode'] = 'Usualsale';
6049 }
6050 update_option( 'usces', $options );
6051 }
6052
6053 public function update_business_days() {
6054 $options = get_option( 'usces' );
6055 $datetimestr = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) );
6056 $dhour = (int) substr( $datetimestr, 11, 2 );
6057 $dminute = (int) substr( $datetimestr, 14, 2 );
6058 $dsecond = (int) substr( $datetimestr, 17, 2 );
6059 $dmonth = (int) substr( $datetimestr, 5, 2 );
6060 $dday = (int) substr( $datetimestr, 8, 2 );
6061 $dyear = (int) substr( $datetimestr, 0, 4 );
6062 $dtimestamp = mktime( $dhour, $dminute, $dsecond, $dmonth, $dday, $dyear );
6063 $datenow = getdate( $dtimestamp );
6064 list( $year, $mon, $mday ) = getBeforeMonth( $datenow['year'], $datenow['mon'], 1, 1 );
6065
6066 if ( isset( $options['business_days'][ $year ][ $mon ][1] ) ) {
6067 unset( $options['business_days'][ $year ][ $mon ] );
6068 }
6069
6070 for ( $i = 0; $i < 12; $i++ ) {
6071 list( $year, $mon, $mday ) = getAfterMonth( $datenow['year'], $datenow['mon'], 1, $i );
6072 $last = getLastDay( $year, $mon );
6073 for ( $j = 1; $j <= $last; $j++ ) {
6074 if ( ! isset( $options['business_days'][ $year ][ $mon ][ $j ] ) ) {
6075 $options['business_days'][ $year ][ $mon ][ $j ] = 1;
6076 }
6077 }
6078 }
6079 update_option( 'usces', $options );
6080 $this->options = get_option( 'usces' );
6081 $_SESSION['usces_checked_business_days'] = '';
6082 }
6083
6084 public function display_cart() {
6085 if ( $this->cart->num_row() > 0 ) {
6086 // include (USCES_PLUGIN_DIR . '/includes/cart_table.php');
6087 } else {
6088 echo "<div class='no_cart'>" . __( 'There are no items in your cart.', 'usces' ) . "</div>\n";
6089 }
6090 }
6091
6092 public function display_cart_confirm() {
6093 if ( $this->cart->num_row() > 0 ) {
6094 // include (USCES_PLUGIN_DIR . '/includes/cart_confirm.php');
6095 } else {
6096 echo "<div class='no_cart'>" . __( 'There are no items in your cart.', 'usces' ) . "</div>\n";
6097 }
6098 }
6099
6100 public function set_initial() {
6101 $this->set_default_page();
6102 $this->set_default_categories();
6103 $this->create_table();
6104 $this->update_table();
6105 $rets07 = usces_upgrade_07();
6106 if ( $rets07 ) {
6107 $rets11 = usces_upgrade_11();
6108 }
6109 if ( $rets11 ) {
6110 $rets14 = usces_upgrade_14();
6111 }
6112 if ( $rets14 ) {
6113 $rets141 = usces_upgrade_141();
6114 }
6115 if ( $rets141 ) {
6116 $rets143 = usces_upgrade_143();
6117 }
6118 $this->update_options();
6119 usces_schedule_event();
6120 do_action( 'usces_on_plugin_activate' );
6121 }
6122
6123 public function deactivate() {
6124 wp_clear_scheduled_hook( 'wc_cron' );
6125 wp_clear_scheduled_hook( 'wc_cron_w' );
6126 usces_wcsite_deactivate();
6127 }
6128
6129 public function create_table() {
6130 global $wpdb;
6131
6132 if ( ! empty( $wpdb->charset ) ) {
6133 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
6134 }
6135 if ( ! empty( $wpdb->collate ) ) {
6136 $charset_collate .= " COLLATE $wpdb->collate";
6137 }
6138 $access_table = $wpdb->prefix . 'usces_access';
6139 $member_table = $wpdb->prefix . 'usces_member';
6140 $member_meta_table = $wpdb->prefix . 'usces_member_meta';
6141 $order_table = $wpdb->prefix . 'usces_order';
6142 $order_meta_table = $wpdb->prefix . 'usces_order_meta';
6143 $ordercart_table = $wpdb->prefix . 'usces_ordercart';
6144 $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
6145 $log_table = $wpdb->prefix . 'usces_log';
6146 $acting_log_table = $wpdb->prefix . 'usces_acting_log';
6147 $item_table = $wpdb->prefix . 'usces_item';
6148 $sku_table = $wpdb->prefix . 'usces_skus';
6149 $opt_table = $wpdb->prefix . 'usces_opts';
6150 $admin_log_table = $wpdb->prefix . 'usces_admin_log';
6151
6152 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6153
6154 if ( $wpdb->get_var( "SHOW TABLES LIKE '$access_table'" ) != $access_table ) {
6155 $sql = 'CREATE TABLE ' . $access_table . " (
6156 ID BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT,
6157 acc_key VARCHAR( 50 ) NOT NULL ,
6158 acc_type VARCHAR( 50 ) NULL ,
6159 acc_value LONGTEXT NULL ,
6160 acc_date DATE NOT NULL DEFAULT '0000-00-00',
6161 acc_num1 INT( 11 ) NOT NULL DEFAULT 0,
6162 acc_num2 INT( 11 ) NOT NULL DEFAULT 0,
6163 acc_str1 VARCHAR( 200 ) NULL ,
6164 acc_str2 VARCHAR( 200 ) NULL ,
6165 PRIMARY KEY (`ID`),
6166 KEY acc_key ( acc_key ),
6167 KEY acc_type ( acc_type ),
6168 KEY acc_date ( acc_date ),
6169 KEY acc_num1 ( acc_num1 ),
6170 KEY acc_num2 ( acc_num2 )
6171 ) AUTO_INCREMENT=0 $charset_collate;";
6172 dbDelta( $sql );
6173 add_option( 'usces_db_access', USCES_DB_ACCESS );
6174 }
6175
6176 if ( $wpdb->get_var( "SHOW TABLES LIKE '$member_table'" ) != $member_table ) {
6177 $sql = 'CREATE TABLE ' . $member_table . " (
6178 ID BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT,
6179 mem_email VARCHAR( 100 ) NOT NULL ,
6180 mem_pass VARCHAR( 64 ) NOT NULL ,
6181 mem_status INT( 11 ) NOT NULL DEFAULT '0',
6182 mem_cookie VARCHAR( 13 ) NULL ,
6183 mem_point INT( 11 ) NOT NULL DEFAULT '0',
6184 mem_name1 VARCHAR( 100 ) NOT NULL ,
6185 mem_name2 VARCHAR( 100 ) NULL ,
6186 mem_name3 VARCHAR( 100 ) NULL ,
6187 mem_name4 VARCHAR( 100 ) NULL ,
6188 mem_zip VARCHAR( 50 ) NULL ,
6189 mem_pref VARCHAR( 100 ) NOT NULL ,
6190 mem_address1 VARCHAR( 100 ) NOT NULL ,
6191 mem_address2 VARCHAR( 100 ) NULL ,
6192 mem_address3 VARCHAR( 100 ) NULL ,
6193 mem_tel VARCHAR( 100 ) NOT NULL ,
6194 mem_fax VARCHAR( 100 ) NULL ,
6195 mem_delivery_flag TINYINT ( 1 ) NULL ,
6196 mem_delivery LONGTEXT,
6197 mem_registered DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6198 mem_nicename VARCHAR( 50 ) NULL ,
6199 PRIMARY KEY (`ID`),
6200 KEY mem_email ( mem_email ) ,
6201 KEY mem_pass ( mem_pass )
6202 ) AUTO_INCREMENT=1000 $charset_collate;";
6203 dbDelta( $sql );
6204 add_option( 'usces_db_member', USCES_DB_MEMBER );
6205 }
6206
6207 if ( $wpdb->get_var( "SHOW TABLES LIKE '$member_meta_table'" ) != $member_meta_table ) {
6208 $sql = 'CREATE TABLE ' . $member_meta_table . " (
6209 mmeta_id bigint(20) NOT NULL auto_increment,
6210 member_id bigint(20) NOT NULL default '0',
6211 meta_key varchar(255) default NULL,
6212 meta_value longtext,
6213 PRIMARY KEY (mmeta_id),
6214 KEY order_id (member_id),
6215 KEY meta_key (meta_key(191))
6216 ) $charset_collate;";
6217 dbDelta( $sql );
6218 add_option( 'usces_db_member_meta', USCES_DB_MEMBER_META );
6219 }
6220
6221 if ( $wpdb->get_var( "SHOW TABLES LIKE '$order_table'" ) != $order_table ) {
6222 $sql = 'CREATE TABLE ' . $order_table . " (
6223 ID BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT,
6224 mem_id BIGINT( 20 ) UNSIGNED NULL ,
6225 order_email VARCHAR( 100 ) NOT NULL ,
6226 order_name1 VARCHAR( 100 ) NOT NULL ,
6227 order_name2 VARCHAR( 100 ) NULL ,
6228 order_name3 VARCHAR( 100 ) NULL ,
6229 order_name4 VARCHAR( 100 ) NULL ,
6230 order_zip VARCHAR( 50 ) NULL ,
6231 order_pref VARCHAR( 100 ) NOT NULL ,
6232 order_address1 VARCHAR( 100 ) NOT NULL ,
6233 order_address2 VARCHAR( 100 ) NULL ,
6234 order_address3 VARCHAR( 100 ) NULL ,
6235 order_tel VARCHAR( 100 ) NOT NULL ,
6236 order_fax VARCHAR( 100 ) NULL ,
6237 order_delivery LONGTEXT,
6238 order_cart LONGTEXT,
6239 order_note TEXT,
6240 order_delivery_time VARCHAR( 100 ) NOT NULL ,
6241 order_payment_name VARCHAR( 100 ) NOT NULL ,
6242 order_condition TEXT,
6243 order_item_total_price DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
6244 order_getpoint INT( 10 ) NOT NULL DEFAULT '0',
6245 order_usedpoint INT( 10 ) NOT NULL DEFAULT '0',
6246 order_discount DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
6247 order_shipping_charge DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
6248 order_cod_fee DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
6249 order_tax DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
6250 order_date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6251 order_modified VARCHAR( 20 ) NULL ,
6252 order_status VARCHAR( 255 ) NULL ,
6253 order_check TEXT NULL ,
6254 order_delidue_date VARCHAR( 30 ) NULL ,
6255 order_delivery_method INT( 10 ) NOT NULL DEFAULT -1,
6256 order_delivery_date VARCHAR( 100 ) NULL,
6257 PRIMARY KEY (`ID`),
6258 KEY order_email ( order_email ) ,
6259 KEY order_name1 ( order_name1 ) ,
6260 KEY order_name2 ( order_name2 ) ,
6261 KEY order_pref ( order_pref ) ,
6262 KEY order_address1 ( order_address1 ) ,
6263 KEY order_tel ( order_tel ) ,
6264 KEY mem_id ( mem_id ) ,
6265 KEY order_date ( order_date )
6266 ) AUTO_INCREMENT=1000 $charset_collate;";
6267 dbDelta( $sql );
6268 add_option( 'usces_db_order', USCES_DB_ORDER );
6269 }
6270
6271 if ( $wpdb->get_var( "SHOW TABLES LIKE '$order_meta_table'" ) != $order_meta_table ) {
6272 $sql = 'CREATE TABLE ' . $order_meta_table . " (
6273 ometa_id bigint(20) NOT NULL auto_increment,
6274 order_id bigint(20) NOT NULL default '0',
6275 meta_key varchar(255) default NULL,
6276 meta_value longtext,
6277 PRIMARY KEY (ometa_id),
6278 KEY order_id (order_id),
6279 KEY meta_key (meta_key(191))
6280 ) $charset_collate;";
6281 dbDelta( $sql );
6282 add_option( 'usces_db_order_meta', USCES_DB_ORDER_META );
6283 }
6284
6285 if ( $wpdb->get_var( "SHOW TABLES LIKE '$ordercart_table'" ) != $ordercart_table ) {
6286 $sql = 'CREATE TABLE ' . $ordercart_table . " (
6287 `cart_id` bigint( 20 ) unsigned NOT NULL AUTO_INCREMENT ,
6288 `order_id` bigint( 20 ) NOT NULL ,
6289 `group_id` int( 3 ) NOT NULL DEFAULT '0',
6290 `row_index` int( 3 ) NOT NULL ,
6291 `post_id` bigint( 20 ) NOT NULL ,
6292 `item_code` varchar( 100 ) NOT NULL ,
6293 `item_name` varchar( 250 ) NOT NULL ,
6294 `cprice` decimal( 12, 0 ) DEFAULT NULL ,
6295 `sku_code` varchar( 100 ) NOT NULL ,
6296 `sku_name` varchar( 250 ) DEFAULT NULL ,
6297 `price` decimal( 12, 0 ) NOT NULL ,
6298 `quantity` float NOT NULL ,
6299 `unit` varchar( 50 ) DEFAULT NULL ,
6300 `tax` decimal( 10, 0 ) DEFAULT NULL ,
6301 `destination_id` int( 10 ) DEFAULT NULL ,
6302 `cart_serial` text,
6303 PRIMARY KEY ( `cart_id` ) ,
6304 UNIQUE KEY `row` ( `row_index` , `destination_id` , `order_id` ) ,
6305 KEY `order_id` ( `order_id` ) ,
6306 KEY `post_id` ( `post_id` ) ,
6307 KEY `item_code` ( `item_code` ) ,
6308 KEY `item_name` ( `item_name`(191) ) ,
6309 KEY `sku_code` ( `sku_code` ) ,
6310 KEY `sku_name` ( `sku_name`(191) )
6311 ) AUTO_INCREMENT=1000 $charset_collate;";
6312 dbDelta( $sql );
6313 add_option( 'usces_db_ordercart', USCES_DB_ORDERCART );
6314 }
6315
6316 if ( $wpdb->get_var( "SHOW TABLES LIKE '$ordercart_meta_table'" ) != $ordercart_meta_table ) {
6317 $sql = 'CREATE TABLE ' . $ordercart_meta_table . " (
6318 `cartmeta_id` bigint( 20 ) NOT NULL AUTO_INCREMENT ,
6319 `cart_id` bigint( 20 ) NOT NULL DEFAULT '0',
6320 `meta_type` varchar( 100 ) NOT NULL ,
6321 `meta_key` varchar( 255 ) DEFAULT NULL ,
6322 `meta_value` longtext,
6323 PRIMARY KEY ( `cartmeta_id` ) ,
6324 KEY `cart_id` ( `cart_id` ) ,
6325 KEY `meta_key` ( `meta_key`(191) )
6326 ) $charset_collate;";
6327 dbDelta( $sql );
6328 add_option( 'usces_db_ordercart_meta', USCES_DB_ORDERCART_META );
6329 }
6330
6331 if ( $wpdb->get_var( "SHOW TABLES LIKE '$log_table'") != $log_table ) {
6332 $sql = 'CREATE TABLE ' . $log_table . " (
6333 ID BIGINT( 20 ) NOT NULL AUTO_INCREMENT,
6334 datetime DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6335 log LONGTEXT NULL,
6336 log_type VARCHAR( 100 ) DEFAULT NULL,
6337 log_key VARCHAR( 255 ) DEFAULT NULL,
6338 PRIMARY KEY ( ID ) ,
6339 KEY datetime ( datetime ),
6340 KEY log_type ( log_type ),
6341 KEY log_key ( log_key(191) )
6342 ) $charset_collate;";
6343 dbDelta( $sql );
6344 add_option( 'usces_db_log', USCES_DB_LOG );
6345 }
6346
6347 if ( $wpdb->get_var( "SHOW TABLES LIKE '$acting_log_table'" ) != $acting_log_table ) {
6348 $sql = 'CREATE TABLE ' . $acting_log_table . " (
6349 `ID` BIGINT(20) NOT NULL AUTO_INCREMENT,
6350 `datetime` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6351 `log` LONGTEXT NULL,
6352 `acting` CHAR(32) DEFAULT NULL,
6353 `status` CHAR(32) DEFAULT NULL,
6354 `result` CHAR(32) DEFAULT NULL,
6355 `amount` DECIMAL( 10, 2 ) DEFAULT NULL,
6356 `order_id` BIGINT(20) NOT NULL,
6357 `tracking_id` CHAR(32) DEFAULT NULL,
6358 PRIMARY KEY (`ID`),
6359 KEY `datetime` (`datetime`),
6360 KEY `order_id` (`order_id`),
6361 KEY `tracking_id` (`tracking_id`),
6362 KEY `history_key` (`order_id`,`tracking_id`)
6363 ) $charset_collate;";
6364 dbDelta( $sql );
6365 add_option( 'usces_db_acting_log', USCES_DB_ACTING_LOG );
6366 }
6367
6368 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$item_table}'" ) !== $item_table ) {
6369 $sql = 'CREATE TABLE ' . $item_table . ' (
6370 post_id BIGINT( 20 ) UNSIGNED NOT NULL,
6371 itemCode VARCHAR( 200 ) NULL ,
6372 itemName VARCHAR( 250 ) NULL ,
6373 itemRestriction VARCHAR( 20 ) NULL ,
6374 itemPointrate VARCHAR( 20 ) NULL ,
6375 itemGpNum1 VARCHAR( 20 ) NULL ,
6376 itemGpNum2 VARCHAR( 20 ) NULL ,
6377 itemGpNum3 VARCHAR( 20 ) NULL ,
6378 itemGpDis1 VARCHAR( 20 ) NULL ,
6379 itemGpDis2 VARCHAR( 20 ) NULL ,
6380 itemGpDis3 VARCHAR( 20 ) NULL ,
6381 itemOrderAcceptable INT( 2 ) NULL ,
6382 itemShipping INT( 3 ) NULL ,
6383 itemDeliveryMethod LONGTEXT ,
6384 itemShippingCharge VARCHAR( 200 ) NULL ,
6385 itemIndividualSCharge VARCHAR( 20 ) NULL ,
6386 item_charging_type INT( 3 ) NULL ,
6387 item_division VARCHAR( 50 ) NULL ,
6388 dlseller_date VARCHAR( 100 ) NULL ,
6389 dlseller_file VARCHAR( 200 ) NULL ,
6390 dlseller_interval VARCHAR( 20 ) NULL ,
6391 dlseller_validity VARCHAR( 20 ) NULL ,
6392 dlseller_version VARCHAR( 100 ) NULL ,
6393 dlseller_author VARCHAR( 200 ) NULL ,
6394 dlseller_purchases VARCHAR( 20 ) NULL ,
6395 dlseller_downloads VARCHAR( 20 ) NULL ,
6396 item_chargingday VARCHAR( 20 ) NULL ,
6397 item_frequency VARCHAR( 20 ) NULL ,
6398 wcad_regular_unit VARCHAR( 20 ) NULL ,
6399 wcad_regular_interval INT( 10 ) NULL ,
6400 wcad_regular_frequency INT( 10 ) NULL ,
6401 select_sku_switch INT( 10 ) NULL ,
6402 select_sku_display INT( 10 ) NULL ,
6403 select_sku LONGTEXT ,
6404 atobarai_propriety INT( 5 ) NULL ,
6405 atodene_propriety INT( 5 ) NULL ,
6406 structuredDataSku VARCHAR( 200 ) NULL ,
6407 lower_limit INT( 10 ) NULL ,
6408 popularity INT( 10 ) NULL ,
6409 main_price DECIMAL( 10, 2 ) NULL ,
6410 itemPicts TEXT NULL ,
6411 itemAdvanced LONGTEXT NULL ,
6412 PRIMARY KEY (`post_id`),
6413 KEY itemCode ( itemCode ) ,
6414 KEY itemName ( itemName )
6415 ) ' . $charset_collate . ';';
6416 dbDelta( $sql );
6417 add_option( 'usces_db_item', USCES_DB_ITEM );
6418 }
6419
6420 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$sku_table}'" ) !== $sku_table ) {
6421 $sql = 'CREATE TABLE ' . $sku_table . ' (
6422 meta_id BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT,
6423 post_id BIGINT( 20 ) UNSIGNED NOT NULL ,
6424 code VARCHAR( 200 ) NULL ,
6425 name VARCHAR( 250 ) NULL ,
6426 cprice DECIMAL( 10, 2 ) NULL ,
6427 price DECIMAL( 10, 2 ) NULL ,
6428 unit TEXT NULL ,
6429 stocknum VARCHAR( 50 ) NULL ,
6430 stock INT( 5 ) NULL ,
6431 gp INT( 2 ) NULL ,
6432 taxrate VARCHAR( 20 ) NULL ,
6433 size VARCHAR( 20 ) NULL ,
6434 weight VARCHAR( 20 ) NULL ,
6435 pict_id VARCHAR( 20 ) NULL ,
6436 advance LONGTEXT ,
6437 paternkey VARCHAR( 100 ) NULL ,
6438 sort INT( 5 ) NULL ,
6439 PRIMARY KEY (`meta_id`),
6440 KEY post_id ( post_id ) ,
6441 KEY code ( code ) ,
6442 KEY name ( name ) ,
6443 KEY price ( price ) ,
6444 KEY paternkey ( paternkey )
6445 ) ' . $charset_collate . ';';
6446 dbDelta( $sql );
6447 add_option( 'usces_db_skus', USCES_DB_SKUS );
6448 }
6449
6450 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$opt_table}'" ) !== $opt_table ) {
6451 $sql = 'CREATE TABLE ' . $opt_table . ' (
6452 meta_id BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT,
6453 post_id BIGINT( 20 ) UNSIGNED NOT NULL ,
6454 code VARCHAR( 200 ) NULL ,
6455 name VARCHAR( 250 ) NULL ,
6456 means INT( 3 ) NULL ,
6457 essential INT( 3 ) NULL ,
6458 value TEXT ,
6459 sort INT( 5 ) NULL ,
6460 PRIMARY KEY (`meta_id`),
6461 KEY post_id ( post_id ) ,
6462 KEY code ( code ) ,
6463 KEY name ( name )
6464 ) ' . $charset_collate . ';';
6465 dbDelta( $sql );
6466 add_option( 'usces_db_opts', USCES_DB_OPTS );
6467 }
6468
6469 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$admin_log_table}'" ) !== $admin_log_table ) {
6470 $sql = "CREATE TABLE {$admin_log_table} (
6471 `ID` int(11) NOT NULL AUTO_INCREMENT,
6472 `author` varchar(64) NOT NULL,
6473 `message` longtext NOT NULL,
6474 `screen` varchar(64) NOT NULL,
6475 `entity_id` varchar(64) DEFAULT NULL,
6476 `action` varchar(64) NOT NULL,
6477 `data` longblob DEFAULT NULL,
6478 `datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
6479 PRIMARY KEY (`ID`),
6480 KEY entity_id ( entity_id )
6481 ) " . $charset_collate . ';';
6482 dbDelta( $sql );
6483 add_option( 'usces_db_admin_log', USCES_DB_ADMIN_LOG );
6484 }
6485
6486 do_action( 'usces_action_create_table' );
6487 }
6488
6489 public function update_table() {
6490 global $wpdb;
6491 $access_table = $wpdb->prefix . 'usces_access';
6492 $member_table = $wpdb->prefix . 'usces_member';
6493 $member_meta_table = $wpdb->prefix . 'usces_member_meta';
6494 $order_table = $wpdb->prefix . 'usces_order';
6495 $order_meta_table = $wpdb->prefix . 'usces_order_meta';
6496 $ordercart_table = $wpdb->prefix . 'usces_ordercart';
6497 $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
6498 $log_table = $wpdb->prefix . 'usces_log';
6499 $acting_log_table = $wpdb->prefix . 'usces_acting_log';
6500 $item_table = $wpdb->prefix . 'usces_item';
6501 $sku_table = $wpdb->prefix . 'usces_skus';
6502 $opt_table = $wpdb->prefix . 'usces_opts';
6503 $admin_log_table = $wpdb->prefix . 'usces_admin_log';
6504
6505 $access_ver = get_option( 'usces_db_access' );
6506 $member_ver = get_option( 'usces_db_member' );
6507 $member_meta_ver = get_option( 'usces_db_member_meta' );
6508 $order_ver = get_option( 'usces_db_order' );
6509 $order_meta_ver = get_option( 'usces_db_order_meta' );
6510 $ordercart_ver = get_option( 'usces_db_ordercart' );
6511 $ordercart_meta_ver = get_option( 'usces_db_ordercart_meta' );
6512 $log_ver = get_option( 'usces_db_log' );
6513 $acting_log_ver = get_option( 'usces_db_acting_log' );
6514 $db_item = get_option( 'usces_db_item' );
6515 $db_skus = get_option( 'usces_db_skus' );
6516 $db_opts = get_option( 'usces_db_opts' );
6517 $db_admin_log = get_option( 'usces_db_admin_log' );
6518
6519 if ( $access_ver != USCES_DB_ACCESS ) {
6520 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6521 $sql = 'CREATE TABLE ' . $access_table . " (
6522 ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
6523 acc_key VARCHAR(50) NOT NULL ,
6524 acc_type VARCHAR(50) NULL ,
6525 acc_value LONGTEXT NULL ,
6526 acc_date DATE NOT NULL DEFAULT '0000-00-00',
6527 acc_num1 INT(11) NOT NULL DEFAULT 0,
6528 acc_num2 INT(11) NOT NULL DEFAULT 0,
6529 acc_str1 VARCHAR(200) NULL ,
6530 acc_str2 VARCHAR(200) NULL ,
6531 PRIMARY KEY (`ID`),
6532 KEY acc_key (acc_key),
6533 KEY acc_type (acc_type),
6534 KEY acc_date (acc_date),
6535 KEY acc_num1 (acc_num1),
6536 KEY acc_num2 (acc_num2)
6537 );";
6538 dbDelta( $sql );
6539 update_option( 'usces_db_access', USCES_DB_ACCESS );
6540 }
6541
6542 if ( USCES_DB_MEMBER != $member_ver ) {
6543 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6544 $sql = 'CREATE TABLE ' . $member_table . " (
6545 ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
6546 mem_email VARCHAR(100) NOT NULL ,
6547 mem_pass VARCHAR(64) NOT NULL ,
6548 mem_status INT(11) NOT NULL DEFAULT '0',
6549 mem_cookie VARCHAR(13) NULL ,
6550 mem_point INT(11) NOT NULL DEFAULT '0',
6551 mem_name1 VARCHAR(100) NOT NULL ,
6552 mem_name2 VARCHAR(100) NULL ,
6553 mem_name3 VARCHAR(100) NULL ,
6554 mem_name4 VARCHAR(100) NULL ,
6555 mem_zip VARCHAR(50) NULL ,
6556 mem_pref VARCHAR(100) NOT NULL ,
6557 mem_address1 VARCHAR(100) NOT NULL ,
6558 mem_address2 VARCHAR(100) NULL ,
6559 mem_address3 VARCHAR(100) NULL ,
6560 mem_tel VARCHAR(100) NOT NULL ,
6561 mem_fax VARCHAR(100) NULL ,
6562 mem_delivery_flag TINYINT (1) NULL ,
6563 mem_delivery LONGTEXT,
6564 mem_registered DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6565 mem_nicename VARCHAR(50) NULL ,
6566 PRIMARY KEY (`ID`),
6567 KEY mem_email (mem_email) ,
6568 KEY mem_pass (mem_pass)
6569 );";
6570 dbDelta( $sql );
6571 update_option( 'usces_db_member', USCES_DB_MEMBER );
6572 }
6573
6574 if ( USCES_DB_MEMBER_META != $member_meta_ver ) {
6575 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6576 $sql = 'CREATE TABLE ' . $member_meta_table . " (
6577 mmeta_id bigint(20) NOT NULL auto_increment,
6578 member_id bigint(20) NOT NULL default '0',
6579 meta_key varchar(255) default NULL,
6580 meta_value longtext,
6581 PRIMARY KEY (`mmeta_id`),
6582 KEY order_id (member_id),
6583 KEY meta_key (meta_key(191))
6584 );";
6585 dbDelta( $sql );
6586 update_option( 'usces_db_member_meta', USCES_DB_MEMBER_META );
6587 }
6588
6589 if ( USCES_DB_ORDER != $order_ver ) {
6590 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6591 $sql = 'CREATE TABLE ' . $order_table . " (
6592 ID bigint(20) unsigned NOT NULL auto_increment,
6593 mem_id BIGINT(20) UNSIGNED NULL,
6594 order_email VARCHAR(100) NOT NULL,
6595 order_name1 VARCHAR(100) NOT NULL,
6596 order_name2 VARCHAR(100) NULL,
6597 order_name3 VARCHAR(100) NULL,
6598 order_name4 VARCHAR(100) NULL,
6599 order_zip VARCHAR(50) NULL,
6600 order_pref VARCHAR(100) NOT NULL,
6601 order_address1 VARCHAR(100) NOT NULL,
6602 order_address2 VARCHAR(100) NULL,
6603 order_address3 VARCHAR(100) NULL,
6604 order_tel VARCHAR(100) NOT NULL,
6605 order_fax VARCHAR(100) NULL,
6606 order_delivery LONGTEXT,
6607 order_cart LONGTEXT,
6608 order_note TEXT,
6609 order_delivery_time VARCHAR(100) NOT NULL,
6610 order_payment_name VARCHAR(100) NOT NULL,
6611 order_condition TEXT,
6612 order_item_total_price DECIMAL(10,2) NOT NULL DEFAULT '0.00',
6613 order_getpoint INT(10) NOT NULL DEFAULT '0',
6614 order_usedpoint INT(10) NOT NULL DEFAULT '0',
6615 order_discount DECIMAL(10,2) NOT NULL DEFAULT '0.00',
6616 order_shipping_charge DECIMAL(10,2) NOT NULL DEFAULT '0.00',
6617 order_cod_fee DECIMAL(10,2) NOT NULL DEFAULT '0.00',
6618 order_tax DECIMAL(10,2) NOT NULL DEFAULT '0.00',
6619 order_date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6620 order_modified VARCHAR(20) NULL,
6621 order_status VARCHAR(255) NULL,
6622 order_check TEXT NULL,
6623 order_delidue_date VARCHAR(30) NULL,
6624 order_delivery_method INT(10) NOT NULL DEFAULT -1,
6625 order_delivery_date VARCHAR(100) NULL,
6626 PRIMARY KEY (`ID`),
6627 KEY order_email (order_email),
6628 KEY order_name1 (order_name1),
6629 KEY order_name2 (order_name2),
6630 KEY order_pref (order_pref),
6631 KEY order_address1 (order_address1),
6632 KEY order_tel (order_tel),
6633 KEY mem_id ( mem_id ) ,
6634 KEY order_date (order_date)
6635 );";
6636 dbDelta( $sql );
6637 update_option( 'usces_db_order', USCES_DB_ORDER );
6638 }
6639
6640 if ( USCES_DB_ORDER_META != $order_meta_ver ) {
6641 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6642 $sql = 'CREATE TABLE ' . $order_meta_table . " (
6643 ometa_id bigint(20) NOT NULL auto_increment,
6644 order_id bigint(20) NOT NULL default '0',
6645 meta_key varchar(255) default NULL,
6646 meta_value longtext,
6647 PRIMARY KEY (`ometa_id`),
6648 KEY order_id (order_id),
6649 KEY meta_key (meta_key)
6650 );";
6651 dbDelta( $sql );
6652 update_option( 'usces_db_order_meta', USCES_DB_ORDER_META );
6653 }
6654
6655 if ( USCES_DB_ORDERCART != $ordercart_ver ) {
6656 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6657 $sql = 'CREATE TABLE ' . $ordercart_table . " (
6658 cart_id bigint(20) unsigned NOT NULL AUTO_INCREMENT ,
6659 order_id bigint(20) NOT NULL ,
6660 group_id int(3) NOT NULL DEFAULT '0',
6661 row_index int(3) NOT NULL ,
6662 post_id bigint(20) NOT NULL ,
6663 item_code varchar(100) NOT NULL ,
6664 item_name varchar(250) NOT NULL ,
6665 cprice decimal(12,0) DEFAULT NULL ,
6666 sku_code varchar(100) NOT NULL ,
6667 sku_name varchar(250) DEFAULT NULL ,
6668 price decimal(12,0) NOT NULL ,
6669 quantity float NOT NULL ,
6670 unit varchar(50) DEFAULT NULL ,
6671 tax decimal(10,0) DEFAULT NULL ,
6672 destination_id int(10) DEFAULT NULL ,
6673 cart_serial text,
6674 UNIQUE KEY row (row_index,destination_id,order_id) ,
6675 PRIMARY KEY (`cart_id`),
6676 KEY order_id (order_id) ,
6677 KEY post_id (post_id) ,
6678 KEY item_code (item_code) ,
6679 KEY item_name (item_name(191)) ,
6680 KEY sku_code (sku_code) ,
6681 KEY sku_name (sku_name(191))
6682 );";
6683 dbDelta( $sql );
6684 update_option( 'usces_db_ordercart', USCES_DB_ORDERCART );
6685 }
6686
6687 if ( USCES_DB_ORDERCART_META != $ordercart_meta_ver ) {
6688 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6689 $sql = 'CREATE TABLE ' . $ordercart_meta_table . " (
6690 cartmeta_id bigint(20) NOT NULL AUTO_INCREMENT,
6691 cart_id bigint(20) NOT NULL DEFAULT '0',
6692 meta_type varchar(100) NOT NULL ,
6693 meta_key varchar(255) DEFAULT NULL ,
6694 meta_value longtext,
6695 PRIMARY KEY (`cartmeta_id`),
6696 KEY cart_id (cart_id) ,
6697 KEY meta_key (meta_key(191))
6698 );";
6699 dbDelta( $sql );
6700 update_option( 'usces_db_ordercart_meta', USCES_DB_ORDERCART_META );
6701 }
6702
6703 if ( USCES_DB_LOG != $log_ver ) {
6704 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6705 $sql = 'CREATE TABLE ' . $log_table . " (
6706 ID bigint(20) NOT NULL AUTO_INCREMENT,
6707 datetime DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6708 log LONGTEXT NULL,
6709 log_type VARCHAR(100) DEFAULT NULL,
6710 log_key VARCHAR(255) DEFAULT NULL,
6711 PRIMARY KEY (`ID`),
6712 KEY datetime (datetime),
6713 KEY log_type (log_type),
6714 KEY log_key (log_key(191))
6715 );";
6716 dbDelta( $sql );
6717 update_option( 'usces_db_log', USCES_DB_LOG );
6718 }
6719
6720 if ( USCES_DB_ACTING_LOG != $acting_log_ver ) {
6721 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6722 $sql = 'CREATE TABLE ' . $acting_log_table . " (
6723 `ID` BIGINT(20) NOT NULL AUTO_INCREMENT,
6724 `datetime` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6725 `log` LONGTEXT NULL,
6726 `acting` CHAR(32) DEFAULT NULL,
6727 `status` CHAR(32) DEFAULT NULL,
6728 `result` CHAR(32) DEFAULT NULL,
6729 `amount` DECIMAL( 10, 2 ) DEFAULT NULL,
6730 `order_id` BIGINT(20) NOT NULL,
6731 `tracking_id` CHAR(32) DEFAULT NULL,
6732 PRIMARY KEY (`ID`),
6733 KEY `datetime` (`datetime`),
6734 KEY `order_id` (`order_id`),
6735 KEY `tracking_id` (`tracking_id`),
6736 KEY `history_key` (`order_id`,`tracking_id`)
6737 );";
6738 dbDelta( $sql );
6739 update_option( 'usces_db_acting_log', USCES_DB_ACTING_LOG );
6740 }
6741
6742 if ( USCES_DB_ITEM != $db_item ) {
6743 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6744 $sql = 'CREATE TABLE ' . $item_table . ' (
6745 post_id BIGINT( 20 ) UNSIGNED NOT NULL ,
6746 itemCode VARCHAR( 200 ) NULL ,
6747 itemName VARCHAR( 250 ) NULL ,
6748 itemRestriction VARCHAR( 20 ) NULL ,
6749 itemPointrate VARCHAR( 20 ) NULL ,
6750 itemGpNum1 VARCHAR( 20 ) NULL ,
6751 itemGpNum2 VARCHAR( 20 ) NULL ,
6752 itemGpNum3 VARCHAR( 20 ) NULL ,
6753 itemGpDis1 VARCHAR( 20 ) NULL ,
6754 itemGpDis2 VARCHAR( 20 ) NULL ,
6755 itemGpDis3 VARCHAR( 20 ) NULL ,
6756 itemOrderAcceptable INT( 2 ) NULL ,
6757 itemShipping INT( 3 ) NULL ,
6758 itemDeliveryMethod LONGTEXT ,
6759 itemShippingCharge VARCHAR( 200 ) NULL ,
6760 itemIndividualSCharge VARCHAR( 20 ) NULL ,
6761 item_charging_type INT( 3 ) NULL ,
6762 item_division VARCHAR( 50 ) NULL ,
6763 dlseller_date VARCHAR( 100 ) NULL ,
6764 dlseller_file VARCHAR( 200 ) NULL ,
6765 dlseller_interval VARCHAR( 20 ) NULL ,
6766 dlseller_validity VARCHAR( 20 ) NULL ,
6767 dlseller_version VARCHAR( 100 ) NULL ,
6768 dlseller_author VARCHAR( 200 ) NULL ,
6769 dlseller_purchases VARCHAR( 20 ) NULL ,
6770 dlseller_downloads VARCHAR( 20 ) NULL ,
6771 item_chargingday VARCHAR( 20 ) NULL ,
6772 item_frequency VARCHAR( 20 ) NULL ,
6773 wcad_regular_unit VARCHAR( 20 ) NULL ,
6774 wcad_regular_interval INT( 10 ) NULL ,
6775 wcad_regular_frequency INT( 10 ) NULL ,
6776 select_sku_switch INT( 10 ) NULL ,
6777 select_sku_display INT( 10 ) NULL ,
6778 select_sku LONGTEXT ,
6779 atobarai_propriety INT( 5 ) NULL ,
6780 atodene_propriety INT( 5 ) NULL ,
6781 structuredDataSku VARCHAR( 200 ) NULL ,
6782 lower_limit INT( 10 ) NULL ,
6783 popularity INT( 10 ) NULL ,
6784 main_price DECIMAL( 10, 2 ) NULL ,
6785 itemPicts TEXT NULL ,
6786 itemAdvanced LONGTEXT NULL ,
6787 PRIMARY KEY (`post_id`),
6788 KEY itemCode ( itemCode ) ,
6789 KEY itemName ( itemName )
6790 );';
6791 dbDelta( $sql );
6792 update_option( 'usces_db_item', USCES_DB_ITEM );
6793 }
6794
6795 if ( USCES_DB_SKUS != $db_skus ) {
6796 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6797 $sql = 'CREATE TABLE ' . $sku_table . ' (
6798 meta_id BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
6799 post_id BIGINT( 20 ) UNSIGNED NOT NULL ,
6800 code VARCHAR( 200 ) NULL ,
6801 name VARCHAR( 250 ) NULL ,
6802 cprice DECIMAL( 10, 2 ) NULL ,
6803 price DECIMAL( 10, 2 ) NULL ,
6804 unit TEXT NULL ,
6805 stocknum VARCHAR( 50 ) NULL ,
6806 stock INT( 5 ) NULL ,
6807 gp INT( 2 ) NULL ,
6808 taxrate VARCHAR( 20 ) NULL ,
6809 size VARCHAR( 20 ) NULL ,
6810 weight VARCHAR( 20 ) NULL ,
6811 pict_id VARCHAR( 20 ) NULL ,
6812 advance LONGTEXT ,
6813 paternkey VARCHAR( 100 ) NULL ,
6814 sort INT( 5 ) NULL ,
6815 PRIMARY KEY (`meta_id`),
6816 KEY post_id ( post_id ) ,
6817 KEY code ( code ) ,
6818 KEY name ( name ) ,
6819 KEY price ( price ) ,
6820 KEY paternkey ( paternkey )
6821 );';
6822 dbDelta( $sql );
6823 update_option( 'usces_db_skus', USCES_DB_SKUS );
6824 }
6825
6826 if ( USCES_DB_OPTS != $db_opts ) {
6827 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6828 $sql = 'CREATE TABLE ' . $opt_table . ' (
6829 meta_id BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
6830 post_id BIGINT( 20 ) UNSIGNED NOT NULL ,
6831 code VARCHAR( 200 ) NULL ,
6832 name VARCHAR( 250 ) NULL ,
6833 means INT( 3 ) NULL ,
6834 essential INT( 3 ) NULL ,
6835 value TEXT ,
6836 sort INT( 5 ) NULL ,
6837 PRIMARY KEY (`meta_id`),
6838 KEY post_id ( post_id ) ,
6839 KEY code ( code ) ,
6840 KEY name ( name )
6841 );';
6842 dbDelta( $sql );
6843 update_option( 'usces_db_opts', USCES_DB_OPTS );
6844 }
6845
6846 if ( USCES_DB_ADMIN_LOG != $db_admin_log ) {
6847 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6848 $sql = "CREATE TABLE {$admin_log_table} (
6849 `ID` int(11) NOT NULL AUTO_INCREMENT,
6850 `author` varchar(64) NOT NULL,
6851 `message` longtext NOT NULL,
6852 `screen` varchar(64) NOT NULL,
6853 `entity_id` varchar(64) DEFAULT NULL,
6854 `action` varchar(64) NOT NULL,
6855 `data` longblob DEFAULT NULL,
6856 `datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
6857 PRIMARY KEY (`ID`),
6858 KEY entity_id ( entity_id )
6859 );";
6860 dbDelta( $sql );
6861 update_option( 'usces_db_admin_log', USCES_DB_ADMIN_LOG );
6862 }
6863
6864 do_action( 'usces_action_update_table' );
6865 }
6866
6867 public function dir_copy( $source, $dest ) {
6868 if ( $res = opendir( $source ) ) {
6869 while ( ( $file = readdir( $res ) ) !== false ) {
6870 $sorce_path = $source . '/' . $file;
6871 $dest_path = $dest . '/' . $file;
6872 $filetype = @filetype( $sorce_path );
6873 if ( 'file' == $filetype ) {
6874 copy( $sorce_path, $dest_path );
6875 } elseif ( 'dir' == $filetype && '..' != $file && '.' != $file ) {
6876 mkdir( $dest_path );
6877 $this->dir_copy( $sorce_path, $dest_path );
6878 }
6879 }
6880 closedir( $res );
6881 }
6882 }
6883
6884 public function set_default_page() {
6885 global $wpdb;
6886
6887 $datetime = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) );
6888 $datetime_gmt = gmdate( 'Y-m-d H:i:s', time() );
6889
6890 // cart_page.
6891 $query = $wpdb->prepare( "SELECT ID from $wpdb->posts where post_name = %s", USCES_CART_FOLDER );
6892 $cart_number = $wpdb->get_var( $query );
6893 if ( null === $cart_number ) {
6894 $query = $wpdb->prepare(
6895 "INSERT INTO $wpdb->posts
6896 (post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status,
6897 comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt,
6898 post_content_filtered, post_parent, guid, menu_order, post_type, post_mime_type, comment_count)
6899 VALUES (%d, %s, %s, %s, %s, %s, %s,
6900 %s, %s, %s, %s, %s, %s, %s, %s,
6901 %s, %d, %s, %d, %s, %s, %d)",
6902 1, $datetime, $datetime_gmt, '', __( 'Cart', 'usces' ), '', 'publish',
6903 'closed', 'closed', '', USCES_CART_FOLDER, '', '', $datetime, $datetime_gmt,
6904 '', 0, '', 0, 'page', '', 0
6905 );
6906 $wpdb->query( $query );
6907 $cart_number = $wpdb->insert_id;
6908 if ( null !== $cart_number ) {
6909 $query = $wpdb->prepare(
6910 "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) VALUES (%d, %s, %s)",
6911 $cart_number, '_wp_page_template', 'uscescart.php'
6912 );
6913 $wpdb->query( $query );
6914 }
6915 }
6916 update_option( 'usces_cart_number', $cart_number );
6917
6918 // member_page.
6919 $query = $wpdb->prepare( "SELECT ID from $wpdb->posts where post_name = %s", USCES_MEMBER_FOLDER );
6920 $member_number = $wpdb->get_var( $query );
6921 if ( null === $member_number ) {
6922 $query = $wpdb->prepare(
6923 "INSERT INTO $wpdb->posts
6924 (post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status,
6925 comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt,
6926 post_content_filtered, post_parent, guid, menu_order, post_type, post_mime_type, comment_count)
6927 VALUES (%d, %s, %s, %s, %s, %s, %s,
6928 %s, %s, %s, %s, %s, %s, %s, %s,
6929 %s, %d, %s, %d, %s, %s, %d)",
6930 1, $datetime, $datetime_gmt, '', __( 'Membership', 'usces' ), '', 'publish',
6931 'closed', 'closed', '', USCES_MEMBER_FOLDER, '', '', $datetime, $datetime_gmt,
6932 '', 0, '', 0, 'page', '', 0
6933 );
6934 $wpdb->query( $query );
6935 $member_number = $wpdb->insert_id;
6936 if ( null !== $member_number ) {
6937 $query = $wpdb->prepare(
6938 "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) VALUES (%d, %s, %s)",
6939 $member_number, '_wp_page_template', 'uscesmember.php'
6940 );
6941 $wpdb->query( $query );
6942 }
6943 }
6944 update_option( 'usces_member_number', $member_number );
6945 }
6946
6947 public function set_default_categories() {
6948 global $wpdb;
6949
6950 $item_category_slug = apply_filters( 'usces_item_category_slug', 'item' );
6951
6952 $idObj = get_category_by_slug( $item_category_slug );
6953 if ( empty( $idObj ) ) {
6954 $item_cat = array(
6955 'cat_name' => __( 'Items', 'usces' ),
6956 'category_description' => '',
6957 'category_nicename' => $item_category_slug,
6958 'category_parent' => 0,
6959 );
6960 $item_cat_id = wp_insert_category( $item_cat );
6961 update_option( 'usces_item_cat_parent_id', $item_cat_id );
6962 }
6963
6964 $idObj = get_category_by_slug( 'itemreco' );
6965 if ( empty( $idObj ) && isset( $item_cat_id ) ) {
6966 $itemreco_cat = array(
6967 'cat_name' => __( 'Items recommended', 'usces' ),
6968 'category_description' => '',
6969 'category_nicename' => 'itemreco',
6970 'category_parent' => $item_cat_id,
6971 );
6972 $itemreco_cat_id = wp_insert_category( $itemreco_cat );
6973 }
6974
6975 $idObj = get_category_by_slug( 'itemnew' );
6976 if ( empty( $idObj ) && isset( $item_cat_id ) ) {
6977 $itemnew_cat = array(
6978 'cat_name' => __( 'New items', 'usces' ),
6979 'category_description' => '',
6980 'category_nicename' => 'itemnew',
6981 'category_parent' => $item_cat_id,
6982 );
6983 $itemnew_cat_id = wp_insert_category( $itemnew_cat );
6984 }
6985
6986 $idObj = get_category_by_slug( 'itemgenre' );
6987 if ( empty( $idObj ) && isset( $item_cat_id ) ) {
6988 $itemgenre_cat = array(
6989 'cat_name' => __( 'Item genre', 'usces' ),
6990 'category_description' => '',
6991 'category_nicename' => 'itemgenre',
6992 'category_parent' => $item_cat_id,
6993 );
6994 $itemgenre_cat_id = wp_insert_category( $itemgenre_cat );
6995 }
6996 }
6997
6998 public function update_options() {
6999 $target_market = $this->options['system']['target_market'];
7000
7001 $update_shipping_charge = false;
7002 $shipping_charge = isset( $this->options['shipping_charge'] ) ? $this->options['shipping_charge'] : array();
7003 $shipping_charge_count = ( $shipping_charge && is_array( $shipping_charge ) ) ? count( $shipping_charge ) : 0;
7004 foreach ( (array) $target_market as $tm ) {
7005 for ( $i = 0; $i < $shipping_charge_count; $i++ ) {
7006 if ( isset( $shipping_charge[ $i ]['country'] ) && $shipping_charge[ $i ]['country'] == $tm ) {
7007 foreach ( $shipping_charge[ $i ]['value'] as $pref => $value ) {
7008 $shipping_charge[ $i ][ $tm ][ $pref ] = $value;
7009 }
7010 unset( $shipping_charge[ $i ]['country'] );
7011 unset( $shipping_charge[ $i ]['value'] );
7012 $update_shipping_charge = true;
7013 }
7014 }
7015 }
7016 if ( $update_shipping_charge ) {
7017 $this->options['shipping_charge'] = $shipping_charge;
7018 }
7019
7020 $update_delivery_days = false;
7021 $delivery_days = isset( $this->options['delivery_days'] ) ? $this->options['delivery_days'] : array();
7022 $delivery_days_count = ( $delivery_days && is_array( $delivery_days ) ) ? count( $delivery_days ) : 0;
7023 foreach ( (array) $target_market as $tm ) {
7024 for ( $i = 0; $i < $delivery_days_count; $i++ ) {
7025 if ( isset( $delivery_days[ $i ]['country'] ) && $delivery_days[ $i ]['country'] == $tm ) {
7026 foreach ( $delivery_days[ $i ]['value'] as $pref => $value ) {
7027 $delivery_days[ $i ][ $tm ][ $pref ] = $value;
7028 }
7029 unset( $delivery_days[ $i ]['country'] );
7030 unset( $delivery_days[ $i ]['value'] );
7031 $update_delivery_days = true;
7032 }
7033 }
7034 }
7035 if ( $update_delivery_days ) {
7036 $this->options['delivery_days'] = $delivery_days;
7037 }
7038
7039 if ( $update_shipping_charge || $update_delivery_days ) {
7040 update_option( 'usces', $this->options );
7041 }
7042 }
7043
7044 public function get_item_cat_ids() {
7045 $ids = array();
7046 $args = array(
7047 'child_of' => USCES_ITEM_CAT_PARENT_ID,
7048 'hide_empty' => 0,
7049 'hierarchical' => 0,
7050 );
7051 $categories = get_categories( $args );
7052 foreach ( (array) $categories as $category ) {
7053 $ids[] = $category->term_id;
7054 }
7055 return $ids;
7056 }
7057
7058 public function get_item_post_ids() {
7059 global $wpdb;
7060 $query = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_mime_type = %s", 'item' );
7061 $ids = $wpdb->get_col( $query );
7062
7063 return $ids;
7064 }
7065
7066 public function get_item_cat_genre_ids( $post_id ) {
7067 $ids = array();
7068 $all_ids = array();
7069 $genre = get_category_by_slug( 'itemgenre' );
7070 if ( ! empty( $genre->term_id ) ) {
7071 $genre_id = $genre->term_id;
7072 $args = array(
7073 'child_of' => $genre_id,
7074 'hide_empty' => 0,
7075 'hierarchical' => 0,
7076 );
7077 $categories = get_categories( $args );
7078 foreach ( (array) $categories as $category ) {
7079 $ids[] = $category->term_id;
7080 }
7081 $allcats = get_the_category( $post_id );
7082 foreach ( (array) $allcats as $cat ) {
7083 $all_ids[] = $cat->term_id;
7084 }
7085 $results = array_intersect( $ids, $all_ids );
7086 } else {
7087 $results = array();
7088 }
7089 return $results;
7090 }
7091
7092 public function set_item_mime( $post_id, $str ) {
7093 global $wpdb;
7094 if ( WCUtils::is_blank( $str ) ) {
7095 return;
7096 }
7097 $query = $wpdb->prepare( "UPDATE $wpdb->posts SET post_mime_type = %s WHERE ID = %s", $str, $post_id );
7098 $results = $wpdb->query( $query );
7099 return $results;
7100 }
7101
7102 public function isAdnminSSL() {
7103 $plugins = get_option( 'active_plugins' );
7104 foreach ( $plugins as $plugin ) {
7105 if ( false !== strpos( $plugin, USCES_ADMIN_SSL_BASE_NAME ) ) {
7106 return true;
7107 }
7108 }
7109 return false;
7110 }
7111
7112 public function getGuidTax() {
7113 if ( isset( $this->options['tax_display'] ) && 'deactivate' == $this->options['tax_display'] ) {
7114 $str = '';
7115 } else {
7116 $tax_rate = (int) $this->options['tax_rate'];
7117
7118 if ( isset( $this->options['tax_mode'] ) ) {
7119 if ( 'exclude' == $this->options['tax_mode'] ) {
7120 $str = '<em class="tax">' . __( '(Excl. Tax)', 'usces' ) . '</em>';
7121 } else {
7122 $str = '<em class="tax">' . __( '(Incl. Tax)', 'usces' ) . '</em>';
7123 }
7124 } else {
7125 if ( 0 < $tax_rate ) {
7126 $str = '<em class="tax">' . __( '(Excl. Tax)', 'usces' ) . '</em>';
7127 } else {
7128 $str = '<em class="tax">' . __( '(Incl. Tax)', 'usces' ) . '</em>';
7129 }
7130 }
7131 $str = apply_filters( 'usces_filter_tax_guid', $str, $tax_rate );
7132 }
7133 return $str;
7134 }
7135
7136 public function getItemCode( $post_id, $cache = true ) {
7137 $product = wel_get_product( $post_id, $cache );
7138 $itemCode = isset( $product['itemCode'] ) ? $product['itemCode'] : null;
7139 return $itemCode;
7140 }
7141
7142 public function getItemName( $post_id, $cache = true ) {
7143 $product = wel_get_product( $post_id, $cache );
7144 $itemName = isset( $product['itemName'] ) ? $product['itemName'] : null;
7145 return $itemName;
7146 }
7147
7148 public function getItemRestriction( $post_id, $cache = true ) {
7149 $product = wel_get_product( $post_id, $cache );
7150 $itemRestriction = isset( $product['itemRestriction'] ) ? $product['itemRestriction'] : null;
7151 return $itemRestriction;
7152 }
7153
7154 public function getItemOrderAcceptable( $post_id, $cache = true ) {
7155 $product = wel_get_product( $post_id, $cache );
7156 $value = ( ! empty( $product['itemOrderAcceptable'] ) ) ? (int) $product['itemOrderAcceptable'] : 0;
7157 return $value;
7158 }
7159
7160 public function getItemPointrate( $post_id, $cache = true ) {
7161 $product = wel_get_product( $post_id, $cache );
7162 $itemPointrate = isset( $product['itemPointrate'] ) ? $product['itemPointrate'] : null;
7163 return $itemPointrate;
7164 }
7165
7166 public function getItemShipping( $post_id, $cache = true ) {
7167 $product = wel_get_product( $post_id, $cache );
7168 $itemShipping = isset( $product['itemShipping'] ) ? $product['itemShipping'] : null;
7169 return $itemShipping;
7170 }
7171
7172 public function getItemShippingCharge( $post_id, $cache = true ) {
7173 $product = wel_get_product( $post_id, $cache );
7174 $itemShippingCharge = isset( $product['itemShippingCharge'] ) ? (float) $product['itemShippingCharge'] : null;
7175 return $itemShippingCharge;
7176 }
7177
7178 public function getItemDeliveryMethod( $post_id, $cache = true ) {
7179 $product = wel_get_product( $post_id, $cache );
7180 if ( empty( $product['itemDeliveryMethod'] ) ) {
7181 return array();
7182 } else {
7183 return $product['itemDeliveryMethod'];
7184 }
7185 }
7186
7187 public function getItemIndividualSCharge( $post_id, $cache = true ) {
7188 $product = wel_get_product( $post_id, $cache );
7189 $itemIndividualSCharge = isset( $product['itemIndividualSCharge'] ) ? $product['itemIndividualSCharge'] : null;
7190 return $itemIndividualSCharge;
7191 }
7192
7193 public function getItemGpNum1( $post_id, $cache = true ) {
7194 $product = wel_get_product( $post_id, $cache );
7195 $itemGpNum1 = isset( $product['itemGpNum1'] ) ? $product['itemGpNum1'] : null;
7196 return $itemGpNum1;
7197 }
7198
7199 public function getItemGpNum2( $post_id, $cache = true ) {
7200 $product = wel_get_product( $post_id, $cache );
7201 $itemGpNum2 = isset( $product['itemGpNum2'] ) ? $product['itemGpNum2'] : null;
7202 return $itemGpNum2;
7203 }
7204
7205 public function getItemGpNum3( $post_id, $cache = true ) {
7206 $product = wel_get_product( $post_id, $cache );
7207 $itemGpNum3 = isset( $product['itemGpNum3'] ) ? $product['itemGpNum3'] : null;
7208 return $itemGpNum3;
7209 }
7210
7211 public function getItemGpDis1( $post_id, $cache = true ) {
7212 $product = wel_get_product( $post_id, $cache );
7213 $itemGpDis1 = isset( $product['itemGpDis1'] ) ? $product['itemGpDis1'] : null;
7214 return $itemGpDis1;
7215 }
7216
7217 public function getItemGpDis2( $post_id, $cache = true ) {
7218 $product = wel_get_product( $post_id, $cache );
7219 $itemGpDis2 = isset( $product['itemGpDis2'] ) ? $product['itemGpDis2'] : null;
7220 return $itemGpDis2;
7221 }
7222
7223 public function getItemGpDis3( $post_id, $cache = true ) {
7224 $product = wel_get_product( $post_id, $cache );
7225 $itemGpDis3 = isset( $product['itemGpDis3'] ) ? $product['itemGpDis3'] : null;
7226 return $itemGpDis3;
7227 }
7228
7229 /**
7230 * Unused function
7231 */
7232 public function getItemSku( $post_id, $index = '', $cache = true ) {
7233 $array = array();
7234 $skus = $this->get_skus( $post_id, 'sort', $cache );
7235 foreach ( (array) $skus as $sku ) {
7236 $array[] = $sku['code'];
7237 }
7238 if ( ! $array ) {
7239 return false;
7240 }
7241 if ( '' == $index ) {
7242 return $array;
7243 } elseif ( isset( $array[ $index ] ) ) {
7244 return $array[ $index ];
7245 } else {
7246 return false;
7247 }
7248 }
7249
7250 public function getItemPrice( $post_id, $skukey = '', $cache = true ) {
7251 $array = array();
7252 $skus = wel_get_skus( $post_id, 'code', $cache );
7253 foreach ( (array) $skus as $key => $sku ) {
7254 $array[ $key ] = (float) str_replace( ',', '', $sku['price'] );
7255 }
7256 $array = apply_filters( 'usces_filter_get_item_price', $array, $post_id, $skukey, $skus );
7257 if ( ! $array ) {
7258 return false;
7259 }
7260 if ( '' === $skukey ) {
7261 return $array;
7262 } elseif ( isset( $array[ $skukey ] ) ) {
7263 return $array[ $skukey ];
7264 } else {
7265 return false;
7266 }
7267 }
7268
7269 public function getItemDiscount( $post_id, $skukey = '', $cache = true ) {
7270 $display_mode = $this->options['display_mode'];
7271 $decimal = $this->get_currency_decimal();
7272 $array = array();
7273
7274 $skus = wel_get_skus( $post_id, 'code', $cache );
7275 $discount = 0;
7276 foreach ( (array) $skus as $key => $sku ) {
7277 $price = (float) str_replace( ',', '', $sku['price'] );
7278 if ( 'Promotionsale' == $display_mode ) {
7279 if ( 'discount' === $this->options['campaign_privilege'] ) {
7280 if ( 0 === (int) $this->options['campaign_category'] || in_category( (int) $this->options['campaign_category'], $post_id ) ) {
7281 $discount = (float) sprintf( '%.3f', $price * $this->options['privilege_discount'] / 100 );
7282 } else {
7283 $discount = 0;
7284 }
7285 } elseif ( 'point' === $this->options['campaign_privilege'] ) {
7286 $discount = 0;
7287 }
7288 }
7289 if ( 0 != $discount ) {
7290 if ( 0 == $decimal ) {
7291 $discount = ceil( $discount );
7292 } else {
7293 $decipad = (int) str_pad( '1', $decimal + 1, '0', STR_PAD_RIGHT );
7294 $discount = ceil( $discount * $decipad ) / $decipad;
7295 }
7296 }
7297 $discount = apply_filters( 'usces_filter_getItemDiscount', $discount, $price, $post_id, $sku, $display_mode );
7298 $array[ $key ] = $discount;
7299 }
7300 if ( ! $array ) {
7301 return false;
7302 }
7303 if ( '' === $skukey ) {
7304 return $array;
7305 } elseif ( isset( $array[ $skukey ] ) ) {
7306 return $array[ $skukey ];
7307 } else {
7308 return false;
7309 }
7310 }
7311
7312 public function getItemZaiko( $post_id, $skukey = '', $cache = true ) {
7313 $itemOrderAcceptable = $this->getItemOrderAcceptable( $post_id );
7314 $array = array();
7315
7316 $skus = wel_get_skus( $post_id, 'code', $cache );
7317 foreach ( (array) $skus as $key => $sku ) {
7318 $num = $sku['stock'];
7319 if ( 1 != $itemOrderAcceptable || WCUtils::is_blank( $sku['stocknum'] ) ) {
7320 $array[ $key ] = $this->zaiko_status[ $num ];
7321 } else {
7322 if ( 2 > $num && 0 >= (int) $sku['stocknum'] ) {
7323 $array[ $key ] = ( ! empty( $this->options['order_acceptable_label'] ) ) ? $this->options['order_acceptable_label'] : __( 'Order acceptable', 'usces' );
7324 } else {
7325 $array[ $key ] = $this->zaiko_status[ $num ];
7326 }
7327 }
7328 }
7329 if ( ! $array ) {
7330 return false;
7331 }
7332 if ( '' === $skukey ) {
7333 return $array;
7334 } elseif ( isset( $array[ $skukey ] ) ) {
7335 return $array[ $skukey ];
7336 } else {
7337 return false;
7338 }
7339 }
7340
7341 public function getItemZaikoStatusId( $post_id, $skukey = '', $cache = true ) {
7342 $array = array();
7343 $skus = wel_get_skus( $post_id, 'code', $cache );
7344 foreach ( (array) $skus as $key => $sku ) {
7345 $num = $sku['stock'];
7346 $array[ $key ] = $num;
7347 }
7348 if ( ! $array ) {
7349 return false;
7350 }
7351 if ( '' === $skukey ) {
7352 return $array;
7353 } elseif ( isset( $array[ $skukey ] ) ) {
7354 return $array[ $skukey ];
7355 } else {
7356 return false;
7357 }
7358 }
7359
7360 public function updateItemZaiko( $post_id, $skucode, $value ) {
7361 $res = usces_update_sku( $post_id, $skucode, 'stock', $value );
7362 if ( ! $res ) {
7363 return false;
7364 } else {
7365 return true;
7366 }
7367 }
7368
7369 public function getItemZaikoNum( $post_id, $skukey = '', $cache = true ) {
7370 $array = array();
7371 $skus = wel_get_skus( $post_id, 'code', $cache );
7372 foreach ( (array) $skus as $key => $sku ) {
7373 $array[ $key ] = $sku['stocknum'];
7374 }
7375 if ( ! $array ) {
7376 return false;
7377 }
7378 if ( '' === $skukey ) {
7379 return $array;
7380 } elseif ( isset( $array[ $skukey ] ) ) {
7381 return $array[ $skukey ];
7382 } else {
7383 return false;
7384 }
7385 }
7386
7387 public function updateItemZaikoNum( $post_id, $skucode, $value ) {
7388 $res = usces_update_sku( $post_id, $skucode, 'stocknum', $value );
7389 if ( ! $res ) {
7390 return false;
7391 } else {
7392 return true;
7393 }
7394 }
7395
7396 public function getItemDivision( $post_id, $cache = true ) {
7397 if ( usces_is_item( $post_id ) ) {
7398 $product = wel_get_product( $post_id, $cache );
7399 $item_division = $product['item_division'];
7400 $division = empty( $item_division ) ? 'shipped' : $item_division;
7401 } else {
7402 $division = null;
7403 }
7404 return $division;
7405 }
7406
7407 public function getItemChargingType( $post_id, $cart = array(), $cache = true ) {
7408 if ( usces_is_item( $post_id ) ) {
7409 $product = wel_get_product( $post_id, $cache );
7410 $charging = $product['item_charging_type'];
7411 if ( ! defined( 'WCEX_DLSELLER' ) && ! defined( 'WCEX_AUTO_DELIVERY' ) ) {
7412 $charging = null;
7413 }
7414 } else {
7415 $charging = null;
7416 }
7417 switch ( $charging ) {
7418 case 0:
7419 $type = 'once';
7420 break;
7421 case 1:
7422 $type = 'continue';
7423 break;
7424 case 2:
7425 $type = 'regular';
7426 if ( ! empty( $cart ) ) {
7427 if ( empty( $cart['advance'] ) ) {
7428 $type = 'once';
7429 } else {
7430 if ( is_array( $cart['advance'] ) && array_key_exists( 'regular', $cart['advance'] ) ) {
7431 $regular = wel_safe_maybe_unserialize( $cart['advance']['regular'] );
7432 } else {
7433 $advance = $this->cart->wc_unserialize( $cart['advance'] );
7434 $sku = urldecode( $cart['sku'] );
7435 $sku_encoded = $cart['sku'];
7436 $regular = $advance[ $post_id ][ $sku_encoded ]['regular'];
7437 }
7438 $unit = isset( $regular['unit'] ) ? $regular['unit'] : '';
7439 $interval = isset( $regular['interval'] ) ? (int) $regular['interval'] : 0;
7440 /* Treated as normal billing */
7441 if ( empty( $unit ) || 1 > $interval ) {
7442 $type = 'once';
7443 }
7444 }
7445 }
7446 break;
7447 default:
7448 $type = null;
7449 }
7450 return $type;
7451 }
7452
7453 public function getItemFrequency( $post_id, $cache = true ) {
7454 $product = wel_get_product( $post_id, $cache );
7455 return $product['item_frequency'];
7456 }
7457
7458 public function getItemChargingDay( $post_id, $cache = true ) {
7459 $product = wel_get_product( $post_id, $cache );
7460 $day = (int) $product['item_chargingday'];
7461
7462 $chargingday = empty( $day ) ? 1 : $day;
7463 return $chargingday;
7464 }
7465
7466 public function getItemSkuDisp( $post_id, $skukey = '', $cache = true ) {
7467 $array = array();
7468 $skus = wel_get_skus( $post_id, 'code', $cache );
7469 foreach ( (array) $skus as $key => $sku ) {
7470 $array[ $key ] = $sku['name'];
7471 }
7472 if ( ! $array ) {
7473 return false;
7474 }
7475 if ( '' === $skukey ) {
7476 return $array;
7477 } elseif ( isset( $array[ $skukey ] ) ) {
7478 return $array[ $skukey ];
7479 } else {
7480 return false;
7481 }
7482 }
7483
7484 public function getItemSkuUnit( $post_id, $skukey = '', $cache = true ) {
7485 $array = array();
7486 $skus = wel_get_skus( $post_id, 'code', $cache );
7487 foreach ( (array) $skus as $key => $sku ) {
7488 $array[ $key ] = $sku['unit'];
7489 }
7490 if ( ! $array ) {
7491 return false;
7492 }
7493 if ( '' === $skukey ) {
7494 return $array;
7495 } elseif ( isset( $array[ $skukey ] ) ) {
7496 return $array[ $skukey ];
7497 } else {
7498 return false;
7499 }
7500 }
7501
7502 public function getItemSkuAdvance( $post_id, $skukey = '', $cache = true ) {
7503 $array = array();
7504 $skus = wel_get_skus( $post_id, 'code', $cache );
7505 foreach ( (array) $skus as $key => $sku ) {
7506 $array[ $key ] = $sku['advance'];
7507 }
7508 if ( ! $array ) {
7509 return false;
7510 }
7511 if ( '' === $skukey ) {
7512 return $array;
7513 } elseif ( isset( $array[ $skukey ] ) ) {
7514 return $array[ $skukey ];
7515 } else {
7516 return false;
7517 }
7518 }
7519
7520 public function get_item( $post_id, $cache = true ) {
7521 return wel_get_product( $post_id, $cache );
7522 }
7523
7524 public function get_itemOptionKey( $post_id, $enc = false, $cache = true ) {
7525 $opts = usces_get_opts( $post_id, 'sort', $cache );
7526 if ( empty( $opts ) ) {
7527 return;
7528 }
7529
7530 $res = array();
7531 foreach ( (array) $opts as $opt ) {
7532 if ( $enc ) {
7533 $res[] = urlencode( $opt['name'] );
7534 } else {
7535 $res[] = $opt['name'];
7536 }
7537 }
7538 return $res;
7539 }
7540
7541 public function get_itemOptions( $key, $post_id, $cache = true ) {
7542 $opts = wel_get_opts( $post_id, 'name', $cache );
7543 if ( ! isset( $opts[ $key ] ) ) {
7544 return false;
7545 } else {
7546 return $opts[ $key ];
7547 }
7548 }
7549
7550 public function get_postIDbyCode( $item_code, $cache = true ) {
7551 if ( null === $item_code ) {
7552 return false;
7553 }
7554
7555 $post_id = wel_get_id_by_item_code( $item_code, $cache );
7556
7557 return $post_id;
7558 }
7559
7560 public function get_itemByCode( $item_code, $cache = true ) {
7561 if ( null === $item_code ) {
7562 return false;
7563 }
7564
7565 $product = wel_get_product_by_code( $item_code, $cache );
7566
7567 return $product;
7568 }
7569
7570 public function get_pictids( $item_code, $cache = true ) {
7571 return wel_get_sub_pict_ids_by_code( $item_code, $cache );
7572 }
7573
7574 public function get_mainpictid( $item_code, $cache = true ) {
7575 return wel_get_main_pict_id_by_code( $item_code, $cache );
7576 }
7577
7578 public function get_subpictid( $sku_code, $cache = true ) {
7579 global $wpdb;
7580 if ( empty( $sku_code) ) {
7581 return 0;
7582 }
7583 $query = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type = 'attachment' LIMIT 1", $sku_code );
7584 $id = $wpdb->get_var( $query );
7585 $id = apply_filters( 'usces_filter_get_subpictid', $id, $sku_code );
7586 return $id;
7587 }
7588
7589 public function get_skus( $post_id, $keyflag = 'sort', $cache = true ) {
7590 if ( null === $post_id ) {
7591 return false;
7592 }
7593
7594 $skus = wel_get_skus( $post_id, $keyflag, $cache );
7595
7596 return $skus;
7597 }
7598
7599 public function is_item( $post ) {
7600 if ( 'item' == $post->post_mime_type ) {
7601 return true;
7602 } else {
7603 return false;
7604 }
7605 }
7606
7607 public function getItemIds( $end_type ) {
7608 global $wpdb;
7609
7610 $cache_key = 'wel_item_ids_' . $end_type;
7611
7612 $ids = wp_cache_get( $cache_key );
7613 if ( false === $ids ) {
7614
7615 if ( 'front' == $end_type ) {
7616 $query = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_status = %s AND post_mime_type = %s", 'publish', 'item' );
7617 }
7618 if ( 'back' == $end_type ) {
7619 $query = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_mime_type = %s", 'item' );
7620 }
7621 $ids = $wpdb->get_col( $query );
7622
7623 if ( null !== $ids ) {
7624 wp_cache_set( $cache_key, $ids );
7625 }
7626 }
7627
7628 if ( null === $ids ) {
7629 return array();
7630 } else {
7631 return $ids;
7632 }
7633 }
7634
7635 public function getNotItemIds() {
7636 global $wpdb;
7637 $query = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_status = %s AND post_mime_type <> %s", 'publish', 'item' );
7638 $ids = $wpdb->get_col( $query );
7639 if ( empty( $ids ) ) {
7640 $ids = array();
7641 }
7642 return $ids;
7643 }
7644
7645 public function getPaymentMethod( $name ) {
7646 $res = array();
7647 $payments = $this->options['payment_method'];
7648 foreach ( (array) $payments as $payment ) {
7649 if ( $name == $payment['name'] ) {
7650 $res = $payment;
7651 break;
7652 }
7653 }
7654 return $res;
7655 }
7656
7657 public function order_processing( $results = array() ) {
7658 do_action( 'usces_pre_reg_orderdata' );
7659 $acting = isset( $_REQUEST['acting'] ) ? $_REQUEST['acting'] : '';
7660 global $usces;
7661 $usces_entries = $this->cart->get_entry();
7662 $payments = $this->getPayments( $usces_entries['order']['payment_name'] );
7663 $nonacting_settlements = apply_filters( 'usces_filter_nonacting_settlements', $this->nonacting_settlements );
7664
7665 $res = usces_check_acting_return_duplicate( $results );
7666 if ( $res != null && ! in_array( $payments['settlement'], $nonacting_settlements ) ) {
7667 usces_log( 'order processing duplicate : acting=' . $acting . ', order_id=' . $res, 'acting_transaction.log' );
7668 return 'ordercompletion';
7669 }
7670 if ( isset( $_REQUEST['acting'] ) && ( 'jpayment_card' == $_REQUEST['acting'] || 'jpayment_conv' == $_REQUEST['acting'] || 'jpayment_bank' == $_REQUEST['acting'] ) ) {
7671 usces_log( $_REQUEST['acting'] . ' transaction : ' . $_REQUEST['gid'], 'acting_transaction.log' ); // OK.
7672 }
7673 if ( isset( $_REQUEST['acting'] ) && ( 'paypal_ec' == $_REQUEST['acting'] ) ) {
7674 if ( ! usces_paypal_doecp( $results ) ) {
7675 return 'error';
7676 }
7677 }
7678 $order_id = usces_reg_orderdata( $results );
7679 do_action( 'usces_post_reg_orderdata', $order_id, $results );
7680
7681 if ( $order_id ) {
7682 // mail(function.php).
7683 $mail_res = usces_send_ordermail( $order_id );
7684 return 'ordercompletion';
7685
7686 } else {
7687 return 'error';
7688 }
7689 }
7690
7691 /**
7692 * 決済処理
7693 *
7694 * @param string $acting_flg Payment type.
7695 * @param array $post_query Post data.
7696 * @param string $acting_status Status.
7697 * @return mixed
7698 */
7699 public function acting_processing( $acting_flg, $post_query, $acting_status ) {
7700 global $wpdb;
7701
7702 $entry = $this->cart->get_entry();
7703 $delim = apply_filters( 'usces_filter_delim', $this->delim );
7704 $acting_flg = trim( $acting_flg );
7705
7706 if ( empty( $acting_flg ) ) {
7707 return 'error';
7708 }
7709
7710 if ( 'paypal.php' == $acting_flg ) {
7711
7712 } elseif ( 'epsilon.php' == $acting_flg ) {
7713
7714 } elseif ( 'acting_paypal_ec' == $acting_flg ) {
7715 $acting_opts = $this->options['acting_settings']['paypal'];
7716 $addroverride = '1';
7717 if ( isset( $_POST['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] ) ) {
7718 if ( 'US' == $_POST['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] || 'CA' == $_POST['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] ) {
7719 $addroverride = '0';
7720 }
7721 } else {
7722 $addroverride = '0';
7723 }
7724 $rand = ( isset( $_POST['PAYMENTREQUEST_0_CUSTOM'] ) ) ? $_POST['PAYMENTREQUEST_0_CUSTOM'] : '(empty key)';
7725
7726 $nvpstr = $post_query;
7727 $nvpstr .= '&ADDROVERRIDE=' . $addroverride;
7728 $nvpstr .= '&PAYMENTREQUEST_0_PAYMENTACTION=' . apply_filters( 'usces_filter_paypal_ec_paymentaction', 'Sale' );
7729
7730 // The returnURL is the location where buyers return to when a payment has been succesfully authorized.
7731 $nvpstr .= '&RETURNURL=' . urlencode( USCES_CART_URL . $delim . 'acting=paypal_ec&acting_return=1' );
7732
7733 // The cancelURL is the location buyers are sent to when they hit the cancel button during authorization of payment during the PayPal flow.
7734 $cancelurl = urlencode( USCES_CART_URL . $delim . 'confirm=1' );
7735 $pos = strpos( $post_query, 'paypal_from_cart' );
7736 if ( false !== $pos ) {
7737 $cancelurl = urlencode( USCES_CART_URL );
7738 }
7739 $nvpstr .= '&CANCELURL=' . apply_filters( 'usces_filter_paypal_ec_cancelurl', $cancelurl, $post_query );
7740
7741 $nvpstr .= '&PAYMENTREQUEST_0_NOTIFYURL=' . urlencode( USCES_PAYPAL_NOTIFY_URL );
7742
7743 // Seamless checkout.
7744 if ( isset( $_SESSION['liwpp']['token'] ) && ! empty( $_SESSION['liwpp']['token'] ) ) {
7745 $nvpstr .= '&IDENTITYACCESSTOKEN=' . $_SESSION['liwpp']['token'];
7746 }
7747
7748 $this->paypal->setMethod( 'SetExpressCheckout' );
7749 $this->paypal->setData( $nvpstr );
7750 $res = $this->paypal->doExpressCheckout();
7751 $resArray = $this->paypal->getResponse();
7752 $ack = strtoupper( $resArray['ACK'] );
7753 if ( 'SUCCESS' == $ack || 'SUCCESSWITHWARNING' == $ack ) {
7754 $token = urldecode( $resArray['TOKEN'] );
7755 $payPalURL = $acting_opts['paypal_url'] . '?cmd=_express-checkout&token=' . $token . '&useraction=commit';
7756 header( 'Location: ' . $payPalURL );
7757
7758 } else {
7759 // Display a user friendly Error on the page using any of the following error information returned by PayPal.
7760 $ErrorCode = urldecode( $resArray['L_ERRORCODE0'] );
7761 $ErrorShortMsg = urldecode( $resArray['L_SHORTMESSAGE0'] );
7762 $ErrorLongMsg = urldecode( $resArray['L_LONGMESSAGE0'] );
7763 $ErrorSeverityCode = urldecode( $resArray['L_SEVERITYCODE0'] );
7764 usces_log( 'PayPal : SetExpressCheckout API call failed. Error Code:[' . $ErrorCode . '] Error Severity Code:[' . $ErrorSeverityCode . '] Short Error Message:' . $ErrorShortMsg . ' Detailed Error Message:' . $ErrorLongMsg, 'acting_transaction.log' );
7765 $log = array(
7766 'acting' => 'paypal_ec',
7767 'key' => $rand,
7768 'result' => $ack,
7769 'data' => $resArray,
7770 );
7771 usces_save_order_acting_error( $log );
7772 header( 'Location: ' . USCES_CART_URL . $delim . 'acting=paypal_ec&acting_return=0' );
7773 }
7774 exit;
7775
7776 } elseif ( 'acting_telecom_edy' == $acting_flg ) { /* テレコムクレジット Edy決済 */
7777 $table_meta_name = $wpdb->prefix . 'usces_order_meta';
7778 $value = array();
7779 $value['usces_cart'] = $_SESSION['usces_cart'];
7780 $value['usces_entry'] = $_SESSION['usces_entry'];
7781 $value['usces_member'] = $_SESSION['usces_member'];
7782 $mvalue = serialize( $value );
7783 $mquery = $wpdb->prepare( "INSERT INTO $table_meta_name (order_id, meta_key, meta_value) VALUES (%d, %s, %s)", $_POST['option'], $_POST['option'], $mvalue );
7784 $res = $wpdb->query( $mquery );
7785
7786 unset( $_SESSION['usces_cart'] );
7787 unset( $_SESSION['usces_entry'] );
7788
7789 $acting_opts = $this->options['acting_settings']['telecom'];
7790 header( 'location: ' . $acting_opts['send_url_edy'] . '?acting=telecom_edy' . $post_query );
7791 exit;
7792
7793 } elseif ( 'acting_digitalcheck_card' == $acting_flg ) { /* ペイメントフォー カード決済(旧メタップスペイメント、旧デジタルチェック、旧ペイデザイン) */
7794 $acting_opts = $this->options['acting_settings']['digitalcheck'];
7795 $interface = parse_url( $acting_opts['send_url_user_id'] );
7796 $kakutei = ( empty( $acting_opts['card_kakutei'] ) ) ? '0' : $acting_opts['card_kakutei'];
7797
7798 $params = array(
7799 'IP' => $acting_opts['card_ip'],
7800 'PASS' => $acting_opts['card_pass'],
7801 'SID' => $_POST['SID'],
7802 'IP_USER_ID' => $_POST['IP_USER_ID'],
7803 'N1' => $_POST['N1'],
7804 'K1' => $_POST['K1'],
7805 'FUKA' => $acting_flg,
7806 'KAKUTEI' => $kakutei,
7807 );
7808 $vars = http_build_query( $params );
7809
7810 $header = 'POST ' . $interface['path'] . " HTTP/1.1\r\n";
7811 $header .= 'Host: ' . $interface['host'] . "\r\n";
7812 $header .= "User-Agent: PHP Script\r\n";
7813 $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
7814 $header .= 'Content-Length: ' . strlen( $vars ) . "\r\n";
7815 $header .= "Connection: close\r\n\r\n";
7816 $header .= $vars;
7817
7818 $fp = @stream_socket_client( 'tlsv1.2://' . $interface['host'] . ':443', $errno, $errstr, 30 );
7819 if ( ! $fp ) {
7820 // usces_log( 'digitalcheck card : TLS(v1.2) Error', 'acting_transaction.log' );
7821 $log = array(
7822 'acting' => 'digitalcheck_card',
7823 'key' => $_POST['SID'],
7824 'result' => 'SSL/TLS ERROR (' . $errno . ')',
7825 'data' => array( $errstr ),
7826 );
7827 usces_save_order_acting_error( $log );
7828 wp_redirect(
7829 add_query_arg(
7830 array(
7831 'acting' => 'digitalcheck_card',
7832 'acting_return' => 0,
7833 ),
7834 USCES_CART_URL
7835 )
7836 );
7837 exit();
7838 }
7839
7840 if ( $fp ) {
7841 fwrite( $fp, $header );
7842 $headerdone = false;
7843 $page = '';
7844 while ( ! feof( $fp ) ) {
7845 $line = fgets( $fp, 1024 );
7846 if ( 0 == strcmp( $line, "\r\n" ) ) {
7847 $headerdone = true;
7848 } elseif ( $headerdone ) {
7849 $page .= $line;
7850 }
7851 }
7852 fclose( $fp );
7853 $lines = explode( "\n", $page );
7854 if ( false !== strpos( $lines[0], 'OK' ) ) {
7855 // usces_log( 'digitalcheck card entry data (acting_processing) : ' . print_r( $entry, true ), 'acting_transaction.log');
7856 wp_redirect(
7857 add_query_arg(
7858 array(
7859 'acting' => 'digitalcheck_card',
7860 'acting_return' => 1,
7861 'SID' => $_POST['SID'],
7862 'FUKA' => $acting_flg,
7863 ),
7864 USCES_CART_URL
7865 )
7866 );
7867 exit();
7868 } else {
7869 // usces_log( 'digitalcheck card : Certification Error : ' . $page, 'acting_transaction.log' );
7870 $log = array(
7871 'acting' => 'digitalcheck_card',
7872 'key' => $_POST['SID'],
7873 'result' => 'CERTIFICATION ERROR',
7874 'data' => $lines,
7875 );
7876 usces_save_order_acting_error( $log );
7877 wp_redirect(
7878 add_query_arg(
7879 array(
7880 'acting' => 'digitalcheck_card',
7881 'acting_return' => 0,
7882 ),
7883 USCES_CART_URL
7884 )
7885 );
7886 exit();
7887 }
7888 }
7889 exit();
7890
7891 } elseif ( 'acting_digitalcheck_conv' == $acting_flg ) { /* ペイメントフォー コンビニ決済(旧メタップスペイメント、旧デジタルチェック、旧ペイデザイン) */
7892 if ( isset( $_REQUEST['STORE'] ) && '99' != $_REQUEST['STORE'] ) {
7893 $res = $this->order_processing();
7894 if ( 'ordercompletion' == $res ) {
7895 $table_meta_name = $wpdb->prefix . 'usces_order_meta';
7896 $mquery = $wpdb->prepare( "SELECT order_id FROM $table_meta_name WHERE meta_key = %s AND meta_value = %s", 'SID', $_REQUEST['SID'] );
7897 $order_id = $wpdb->get_var( $mquery );
7898 if ( $order_id ) {
7899 $data = array(
7900 'settltment_status' => __( 'Failure', 'usces' ),
7901 'settltment_errmsg' => __( 'Settlement was not completed.', 'usces' ),
7902 );
7903 $this->set_order_meta_value( 'acting_digitalcheck_conv', serialize( $data ), $order_id );
7904 $this->set_order_meta_value( 'wc_trans_id', $_REQUEST['SID'], $order_id );
7905 }
7906 $this->cart->crear_cart();
7907 $acting_opts = $this->options['acting_settings']['digitalcheck'];
7908 header( 'location: ' . $acting_opts['send_url_conv'] . '?acting=digitalcheck_conv' . $post_query );
7909 exit;
7910 } else {
7911 // usces_log( 'digitalcheck conv : order processing error', 'acting_transaction.log' );
7912 $log = array(
7913 'acting' => 'digitalcheck_conv',
7914 'key' => $_REQUEST['SID'],
7915 'result' => 'ORDER DATA REGISTERED ERROR',
7916 'data' => $_REQUEST,
7917 );
7918 usces_save_order_acting_error( $log );
7919 header( 'location: ' . USCES_CART_URL . $delim . 'acting=digitalcheck_conv&acting_return=0' );
7920 exit;
7921 }
7922 } else {
7923 $acting_opts = $this->options['acting_settings']['digitalcheck'];
7924 header( 'location: ' . $acting_opts['send_url_conv'] . '?acting=digitalcheck_conv' . $post_query );
7925 exit;
7926 }
7927
7928 } elseif ( 'acting_veritrans_card' == $acting_flg || 'acting_veritrans_conv' == $acting_flg ) { /* ベリトランス カード決済・コンビニ決済 */
7929 $acting_opts = $this->options['acting_settings']['veritrans'];
7930 $acting = substr( $acting_flg, 7 );
7931 $dummy_payment_flag = ( 'public' == $acting_opts['ope'] ) ? '0' : '1';
7932 $order_id = isset( $_POST['ORDER_ID'] ) ? $_POST['ORDER_ID'] : '';
7933 $regist_url = ( defined( 'VERITRANS_SHA2_TEST' ) ) ? 'https://sair.veritrans.co.jp/web/commodityRegist.action' : $acting_opts['regist_url'];
7934 $url = parse_url( $regist_url );
7935 $path = empty( $url['path'] ) ? '/' : $url['path'];
7936
7937 $postdata = $post_query;
7938 if ( 'acting_veritrans_card' == $acting_flg ) {
7939 $card_capture_flag = ( 'capture' == $acting_opts['card_capture_flag'] ) ? '1' : '0';
7940 $postdata .= '&CARD_CAPTURE_FLAG=' . $card_capture_flag;
7941 }
7942 if ( 'acting_veritrans_conv' == $acting_flg ) {
7943 $postdata .= '&NAME1=' . urlencode( mb_substr( mb_convert_kana( $entry['customer']['name1'], 'ASKV', 'UTF-8' ), 0, 10, 'UTF-8' ) );
7944 $postdata .= '&NAME2=' . urlencode( mb_substr( mb_convert_kana( $entry['customer']['name2'], 'ASKV', 'UTF-8' ), 0, 10, 'UTF-8' ) );
7945 if ( ! empty( $entry['customer']['name3'] ) ) {
7946 $kana1 = mb_substr( mb_convert_kana( $entry['customer']['name3'], 'ASKV', 'UTF-8' ), 0, 10, 'UTF-8' );
7947 mb_regex_encoding( 'UTF-8' );
7948 if ( mb_ereg( "^[ア-ン゛゜ァ-ォャ-ョー]+$", $kana1 ) ) {
7949 $postdata .= '&KANA1=' . urlencode( $kana1 );
7950 }
7951 }
7952 if ( ! empty( $entry['customer']['name4'] ) ) {
7953 $kana2 = mb_substr( mb_convert_kana( $entry['customer']['name4'], 'ASKV', 'UTF-8' ), 0, 10, 'UTF-8' );
7954 mb_regex_encoding( 'UTF-8' );
7955 if ( mb_ereg( "^[ア-ン゛゜ァ-ォャ-ョー]+$", $kana2 ) ) {
7956 $postdata .= '&KANA2=' . urlencode( $kana2 );
7957 }
7958 }
7959 $postdata .= '&TELEPHONE_NO=' . str_replace( '-', '', $entry['customer']['tel'] );
7960 if ( 1 < (int) $acting_opts['conv_timelimit'] && (int) $acting_opts['conv_timelimit'] <= 60 ) {
7961 $timelimit = date( 'Ymd', strtotime( '+' . $acting_opts['conv_timelimit'] . ' days' ) );
7962 $postdata .= '&TIMELIMIT_OF_PAYMENT=' . $timelimit;
7963 }
7964 }
7965 if ( 'on' == $acting_opts['mailaddress'] ) {
7966 $postdata .= '&MAILADDRESS=' . $entry['customer']['mailaddress1'];
7967 }
7968 $postdata .= '&MERCHANT_ID=' . $acting_opts['merchant_id'];
7969 $postdata .= '&SESSION_ID=' . session_id();
7970 $postdata .= '&FINISH_PAYMENT_RETURN_URL=' . urlencode( USCES_CART_URL . $delim . 'acting=' . $acting . '&acting_return=1&result=1' );
7971 $postdata .= '&UNFINISH_PAYMENT_RETURN_URL=' . urlencode( USCES_CART_URL . $delim . 'acting=' . $acting . '&confirm=1' );
7972 $postdata .= '&ERROR_PAYMENT_RETURN_URL=' . urlencode( USCES_CART_URL . $delim . 'acting=' . $acting . '&acting_return=0' );
7973 $postdata .= '&FINISH_PAYMENT_ACCESS_URL=' . urlencode( USCES_CART_URL . $delim . 'acting=' . $acting );
7974 $postdata .= '&DUMMY_PAYMENT_FLAG=' . $dummy_payment_flag;
7975
7976 $postlength = strlen( $postdata );
7977
7978 $request = 'POST ' . $path . ' HTTP/1.1' . "\r\n";
7979 $request .= 'Host: ' . $url['host'] . "\r\n";
7980 $request .= 'User-Agent: HttpRequest Powered by ' . phpversion() . "\r\n";
7981 $request .= 'Connection: close' . "\r\n";
7982 $request .= 'Accept-Language: ja' . "\r\n";
7983 $request .= 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
7984 $request .= 'Content-Length: ' . $postlength . "\r\n\r\n";
7985 $request .= $postdata;
7986
7987 $code = 0;
7988 $resBody = '';
7989 $con = @stream_socket_client( 'tlsv1.2://' . $url['host'] . ':443', $errno, $errstr, 30 );
7990 if ( ! $con ) {
7991 usces_log( 'Veritrans : TLS(v1.2) Error', 'acting_transaction.log' );
7992 $con = @fsockopen( 'ssl://' . $url['host'], 443, $errno, $errstr, 30 );
7993 if ( ! $con ) {
7994 usces_log( 'Veritrans : SSL Error', 'acting_transaction.log' );
7995 $log = array(
7996 'acting' => $acting,
7997 'key' => $order_id,
7998 'result' => 'SSL/TLS ERROR (' . $errno . ')',
7999 'data' => array( $errstr ),
8000 );
8001 usces_save_order_acting_error( $log );
8002 header( 'location: ' . USCES_CART_URL . $delim . 'acting=' . $acting_flg . '&acting_return=0' );
8003 exit;
8004 }
8005 }
8006
8007 if ( $con ) {
8008 $ret = fwrite( $con, $request );
8009 if ( $ret == strlen( $request ) ) {
8010 $res = $this->readResponse( $con );
8011 $code = $res['Code'];
8012 $resBody = $res['Body'];
8013
8014 } else {
8015 usces_log( 'Veritrans Write NG: Sent:' . strlen( $request ) . ' Send:' . $ret, 'acting_transaction.log' );
8016 }
8017 fclose( $con );
8018 }
8019
8020 // 正常終了(200 OK)が返ったか.
8021 if ( 200 == intval( $code ) ) {
8022 $merchantKey = null;
8023 $browserKey = null;
8024 $scd = null;
8025 $error_message = null;
8026
8027 // レスポンスデータからマーチャントキー、ブラウザキーを取得.
8028 $bodyLine = explode( "\n", $resBody );
8029 foreach ( $bodyLine as $line ) {
8030 if ( preg_match( '/^MERCHANT_ENCRYPTION_KEY=(.+)/', $line, $match ) ) {
8031 $merchantKey = $match[1];
8032 } elseif ( preg_match( '/^BROWSER_ENCRYPTION_KEY=(.+)/', $line, $match ) ) {
8033 $browserKey = $match[1];
8034 } elseif ( preg_match('/^SCD=(.+)/', $line, $match ) ) {
8035 $scd = $match[1];
8036 } elseif ( preg_match( '/^ERROR_MESSAGE=(.+)/', $line, $match ) ) {
8037 $error_message = $match[1];
8038 }
8039 }
8040
8041 // 両方取れたらOK。SCDはカードでセキュリティコードが入力された場合のみ.
8042 if ( ! is_null( $merchantKey ) && ! is_null( $browserKey ) ) {
8043 $getdata = '?MERCHANT_ID=' . $acting_opts['merchant_id'];
8044 $getdata .= '&ORDER_ID=' . $order_id;
8045 $getdata .= '&BROWSER_ENCRYPTION_KEY=' . urlencode( $browserKey );
8046 $payment_url = ( defined( 'VERITRANS_SHA2_TEST' ) ) ? 'https://sair.veritrans.co.jp/web/paymentStart.action' : $acting_opts['payment_url'];
8047 header( 'location: ' . $payment_url . $getdata );
8048
8049 } else {
8050 if ( ! is_null( $error_message ) ) {
8051 usces_log( 'Veritrans AWeb:' . $error_message, 'acting_transaction.log' );
8052 $log = array(
8053 'acting' => $acting,
8054 'key' => $order_id,
8055 'result' => $code,
8056 'data' => $bodyLine,
8057 );
8058 usces_save_order_acting_error( $log );
8059 }
8060 header( 'location: ' . USCES_CART_URL . $delim . 'acting=' . $acting_flg . '&acting_return=0' );
8061 }
8062
8063 } else {
8064 usces_log( 'Veritrans Response NG: ' . $resBody, 'acting_transaction.log' );
8065 $bodyLine = explode( "\n", $resBody );
8066 $log = array(
8067 'acting' => $acting,
8068 'key' => $order_id,
8069 'result' => $code,
8070 'data' => $bodyLine,
8071 );
8072 usces_save_order_acting_error( $log );
8073 header( 'location: ' . USCES_CART_URL . $delim . 'acting=' . $acting_flg . '&acting_return=0' );
8074 }
8075 exit;
8076 }
8077
8078 do_action( 'usces_action_acting_processing', $acting_flg, $post_query );
8079 $acting_status = apply_filters( 'usces_filter_acting_processing', $acting_flg, $post_query, $acting_status );
8080 return $acting_status;
8081 }
8082
8083 private function readResponse( $fp ) {
8084 $res = array(
8085 'Status' => '',
8086 'Version' => '',
8087 'Code' => 0,
8088 'Message' => '',
8089 'Headers' => array(),
8090 'Body' => '',
8091 );
8092
8093 // HTTPステータスの読み込み.
8094 $line = $this->readLine( $fp );
8095 if ( 0 == preg_match( '/^(HTTP\/1\.[0-9x]+)\s+([0-9]+)\s+(.+)/i', $line, $match ) ) {
8096 return $res;
8097 }
8098 $res['Status'] = $line;
8099 $res['Version'] = $match[1];
8100 $res['Code'] = $match[2];
8101 $res['Message'] = $match[3];
8102
8103 // レスポンスヘッダの読み込み.
8104 while ( ! feof( $fp ) ) {
8105 $line = $this->readLine( $fp );
8106 if ( '' != $line ) {
8107 list( $hname, $hvalue ) = explode( ':', $line, 2 );
8108 $res['Headers'][ strtolower( $hname ) ] = ltrim( $hvalue );
8109 } else {
8110 break;
8111 }
8112 }
8113 // レスポンスデータの読み込み.
8114 while ( ! feof( $fp ) ) {
8115 $data = $this->readLine( $fp ) . "\n";
8116 if ( '' == $data ) {
8117 break;
8118 }
8119 $res['Body'] .= $data;
8120 }
8121 return $res;
8122 }
8123
8124 private function readLine( $fp ) {
8125 if ( ! $fp ) {
8126 return '';
8127 }
8128 // レスポンスデータを受信.
8129 $line = null;
8130 while ( ! feof( $fp ) ) {
8131 $line .= @fgets( $fp, 4096 );
8132 if ( "\n" == substr( $line, -1 ) ) {
8133 return rtrim( $line, "\r\n" );
8134 }
8135 }
8136 return $line;
8137 }
8138
8139 public function inquiry_processing() {
8140 $mail_res = usces_send_inquirymail();
8141
8142 if ( $mail_res ) {
8143 return 'inquiry_comp';
8144 } else {
8145 return 'inquiry_error';
8146 }
8147 }
8148
8149 public function lastprocessing() {
8150 if ( 'ordercompletion' == $this->page ) {
8151 $this->cart->crear_cart();
8152 }
8153 do_action( 'usces_action_lastprocessing' );
8154
8155 unset( $_SESSION['usces_singleitem'] );
8156 }
8157
8158 public function is_item_zaiko( $post_id, $sku_code ) {
8159 $res = false;
8160 $status_num = false;
8161 $zaiko_num = false;
8162 if ( ! empty( $post_id ) ) {
8163 $sku_code = (string) $sku_code;
8164 $status_num = $this->getItemZaikoStatusId( $post_id, $sku_code );
8165 $zaiko_num = $this->getItemZaikoNum( $post_id, $sku_code );
8166 $itemOrderAcceptable = $this->getItemOrderAcceptable( $post_id );
8167 if ( 1 != $itemOrderAcceptable ) {
8168 if ( false !== $zaiko_num
8169 && ( 0 < (int) $zaiko_num || WCUtils::is_blank( $zaiko_num ) )
8170 && false !== $status_num
8171 && 2 > (int) $status_num ) {
8172 $res = true;
8173 } else {
8174 $res = false;
8175 }
8176 } else {
8177 if ( false !== $status_num
8178 && 2 > (int) $status_num ) {
8179 $res = true;
8180 } else {
8181 $res = false;
8182 }
8183 }
8184 }
8185 return apply_filters( 'usces_is_item_zaiko', $res, $post_id, $sku_code, $status_num, $zaiko_num );
8186 }
8187
8188 public function get_total_price( $cart = array() ) {
8189 if ( empty( $cart ) ) {
8190 $cart = $this->cart->get_cart();
8191 }
8192 $total_price = 0;
8193
8194 if ( ! empty( $cart ) ) {
8195 $cart_count = ( is_array( $cart ) ) ? count( $cart ) : 0;
8196 for ( $i = 0; $i < $cart_count; $i++ ) {
8197 $quantity = (float) $cart[ $i ]['quantity'];
8198 $skuPrice = (float) $cart[ $i ]['price'];
8199
8200 $total_price += ( $skuPrice * $quantity );
8201 }
8202 }
8203 return apply_filters( 'usces_filter_get_total_price', $total_price, $cart );
8204 }
8205
8206 public function get_total_quantity( $cart = array() ) {
8207 if ( empty( $cart ) ) {
8208 $cart = $this->cart->get_cart();
8209 }
8210 $total_quantity = 0;
8211
8212 if ( ! empty( $cart ) ) {
8213 $cart_count = ( is_array( $cart ) ) ? count( $cart ) : 0;
8214 for ( $i = 0; $i < $cart_count; $i++ ) {
8215 $total_quantity += (float) $cart[ $i ]['quantity'];
8216 }
8217 }
8218 return $total_quantity;
8219 }
8220
8221 public function get_order_point( $mem_id = '', $display_mode = '', $cart = array() ) {
8222 if ( '' == $mem_id || 'deactivate' == $this->options['membersystem_state'] || 'deactivate' == $this->options['membersystem_point'] ) {
8223 return 0;
8224 }
8225
8226 if ( empty( $cart ) ) {
8227 $cart = $this->cart->get_cart();
8228 }
8229 if ( empty( $display_mode ) ) {
8230 $display_mode = $this->options['display_mode'];
8231 }
8232 $point = 0;
8233 $total = $this->get_total_price( $cart );
8234 if ( 'Promotionsale' == $display_mode ) {
8235 if ( 'discount' == $this->options['campaign_privilege'] ) {
8236 foreach ( $cart as $rows ) {
8237 $cats = $this->get_post_term_ids( $rows['post_id'], 'category' );
8238 if ( ! in_array( $this->options['campaign_category'], $cats ) ) {
8239 $product = wel_get_product( $rows['post_id'] );
8240 $rate = (float) $product['itemPointrate'];
8241 $price = (float) $rows['price'] * (float) $rows['quantity'];
8242 $point = (float) sprintf( '%.3f', $point + ( $price * $rate / 100 ) );
8243 }
8244 }
8245 } elseif ( 'point' == $this->options['campaign_privilege'] ) {
8246 foreach ( $cart as $rows ) {
8247 $product = wel_get_product( $rows['post_id'] );
8248 $rate = (float) $product['itemPointrate'];
8249 $price = (float) $rows['price'] * (float) $rows['quantity'];
8250 $cats = $this->get_post_term_ids( $rows['post_id'], 'category' );
8251 if ( in_array( $this->options['campaign_category'], $cats ) ) {
8252 $point = (float) sprintf( '%.3f', $point + ( $price * $rate / 100 * (float) $this->options['privilege_point'] ) );
8253 } else {
8254 $point = (float) sprintf( '%.3f', $point + ( $price * $rate / 100 ) );
8255 }
8256 }
8257 }
8258 } else {
8259 foreach ( $cart as $rows ) {
8260 $product = wel_get_product( $rows['post_id'] );
8261 $rate = (float) $product['itemPointrate'];
8262 $price = (float) $rows['price'] * (float) $rows['quantity'];
8263 $point = (float) sprintf( '%.3f', $point + ( $price * $rate / 100 ) );
8264 }
8265 }
8266
8267 $entry = $this->cart->get_entry();
8268 $use_point = isset( $entry['order']['usedpoint'] ) ? (int) $entry['order']['usedpoint'] : 0;
8269 if ( 0 < $use_point && 0 < $total ) {
8270 $point = (float) sprintf( '%.3f', $point - ( $point * $use_point / $total ) );
8271 $point = ceil( $point );
8272 if ( 0 > $point ) {
8273 $point = 0;
8274 }
8275 } else {
8276 if ( 0 < $point ) {
8277 $point = ceil( $point );
8278 }
8279 }
8280
8281 return apply_filters( 'usces_filter_get_order_point', $point, $mem_id, $display_mode, $cart );
8282 }
8283
8284 public function get_order_discount( $display_mode = '', $cart = array() ) {
8285 if ( empty( $cart ) ) {
8286 $cart = $this->cart->get_cart();
8287 }
8288 if ( empty( $display_mode ) ) {
8289 $display_mode = $this->options['display_mode'];
8290 }
8291 $discount = 0;
8292 if ( 'Promotionsale' == $display_mode ) {
8293 if ( 'discount' == $this->options['campaign_privilege'] ) {
8294 if ( 0 === (int) $this->options['campaign_category'] ) {
8295 $total = $this->get_total_price( $cart );
8296 $discount = (float) sprintf( '%.3f', $total * (float) $this->options['privilege_discount'] / 100 );
8297 } else {
8298 foreach ( $cart as $cart_row ) {
8299 if ( in_category( (int) $this->options['campaign_category'], $cart_row['post_id'] ) ) {
8300 $discount += (float) sprintf( '%.3f', (float) $cart_row['price'] * (float) $cart_row['quantity'] * (float) $this->options['privilege_discount'] / 100 );
8301 }
8302 }
8303 }
8304 if ( 0 != $discount ) {
8305 $decimal = $this->get_currency_decimal();
8306 if ( 0 == $decimal ) {
8307 $discount = ceil( $discount );
8308 } else {
8309 $decipad = (int) str_pad( '1', $decimal + 1, '0', STR_PAD_RIGHT );
8310 $discount = ceil( $discount * $decipad ) / $decipad;
8311 }
8312 $discount = $discount * -1;
8313 }
8314 } elseif ( 'point' == $this->options['campaign_privilege'] ) {
8315 $discount = 0;
8316 }
8317 }
8318 $discount = apply_filters( 'usces_order_discount', $discount, $cart );
8319 return $discount;
8320 }
8321
8322 public function getShippingCharge( $pref, $cart = array(), $entry = array() ) {
8323 if ( empty( $cart ) ) {
8324 $cart = $this->cart->get_cart();
8325 }
8326 if ( empty( $entry ) ) {
8327 $entry = $this->cart->get_entry();
8328 }
8329 if ( function_exists( 'dlseller_have_shipped' ) && ! dlseller_have_shipped() ) {
8330 $charge = 0;
8331 $charge = apply_filters( 'usces_filter_getShippingCharge', $charge, $cart, $entry );
8332 return $charge;
8333 }
8334
8335 // 配送方法ID.
8336 $d_method_id = $entry['order']['delivery_method'];
8337 // 配送方法index.
8338 $d_method_index = $this->get_delivery_method_index( $d_method_id );
8339 // 送料ID.
8340 $fixed_charge_id = ( isset( $this->options['delivery_method'][ $d_method_index ]['charge'] ) ) ? $this->options['delivery_method'][ $d_method_index ]['charge'] : -1;
8341 $individual_quant = 0;
8342 $total_quant = 0;
8343 $charges = array();
8344 $individual_charges = array();
8345 $country = ( isset( $entry['delivery']['country'] ) && ! empty( $entry['delivery']['country'] ) ) ? $entry['delivery']['country'] : $entry['customer']['country'];
8346
8347 foreach ( $cart as $rows ) {
8348
8349 if ( 'shipped' !== $this->getItemDivision( $rows['post_id'] ) ) {
8350 continue;
8351 }
8352
8353 if ( -1 == $fixed_charge_id ) {
8354 // 商品送料ID.
8355 $s_charge_id = $this->getItemShippingCharge( $rows['post_id'] );
8356 // 商品送料index.
8357 $s_charge_index = $this->get_shipping_charge_index( $s_charge_id );
8358 $s_charge = isset( $this->options['shipping_charge'][ $s_charge_index ][ $country ][ $pref ] ) ? (float) $this->options['shipping_charge'][ $s_charge_index ][ $country ][ $pref ] : 0;
8359 } else {
8360 $s_charge_index = $this->get_shipping_charge_index( $fixed_charge_id );
8361 $s_charge = isset( $this->options['shipping_charge'][ $s_charge_index ][ $country ][ $pref ] ) ? (float) $this->options['shipping_charge'][ $s_charge_index ][ $country ][ $pref ] : 0;
8362 }
8363
8364 if ( $this->getItemIndividualSCharge( $rows['post_id'] ) ) {
8365 $individual_quant += (float) $rows['quantity'];
8366 $individual_charges[] = (float) $rows['quantity'] * $s_charge;
8367 } else {
8368 $charges[] = $s_charge;
8369 }
8370 $total_quant += $rows['quantity'];
8371 }
8372
8373 if ( count( $charges ) > 0 ) {
8374 rsort( $charges );
8375 $max_charge = $charges[0];
8376 $charge = $max_charge + array_sum( array_filter( $individual_charges, 'is_numeric' ) );
8377 } else {
8378 $charge = array_sum( array_filter( $individual_charges, 'is_numeric' ) );
8379 }
8380
8381 $charge = apply_filters( 'usces_filter_getShippingCharge', $charge, $cart, $entry );
8382
8383 return $charge;
8384 }
8385
8386 public function getCODFee( $payment_name, $amount_by_cod, $current_entries ) {
8387 global $usces_entries;
8388
8389 $payments = $this->getPayments( $payment_name );
8390 if ( ! isset( $payments['settlement'] ) || 'COD' != $payments['settlement'] ) {
8391 $fee = 0;
8392
8393 } elseif ( 'change' != $this->options['cod_type'] ) {
8394 $fee = isset( $this->options['cod_fee'] ) ? $this->options['cod_fee'] : 0;
8395
8396 } else {
8397 $materials = array(
8398 'total_items_price' => $current_entries['order']['total_items_price'],
8399 'discount' => ( isset( $current_entries['order']['discount'] ) ) ? $current_entries['order']['discount'] : 0,
8400 'shipping_charge' => ( isset( $current_entries['order']['shipping_charge'] ) ) ? $current_entries['order']['shipping_charge'] : 0,
8401 'cod_fee' => 0,
8402 'use_point' => 0,
8403 );
8404 $price = $amount_by_cod + $this->getTax( $amount_by_cod, $materials );
8405 if ( $price <= $this->options['cod_first_amount'] ) {
8406 $fee = $this->options['cod_first_fee'];
8407
8408 } elseif ( isset( $this->options['cod_amounts'] ) ) {
8409 $last = count( $this->options['cod_amounts'] ) - 1;
8410 if ( $price > $this->options['cod_amounts'][ $last ] ) {
8411 $fee = $this->options['cod_end_fee'];
8412
8413 } else {
8414 $fee = 0;
8415 foreach ( $this->options['cod_amounts'] as $key => $value ) {
8416 if ( $price <= $value ) {
8417 $fee = $this->options['cod_fees'][ $key ];
8418 break;
8419 }
8420 }
8421 }
8422 } else {
8423 $fee = $this->options['cod_end_fee'];
8424 }
8425 }
8426 $fee = apply_filters( 'usces_filter_getCODFee', $fee, $payment_name, $amount_by_cod, $current_entries );
8427 return $fee;
8428 }
8429
8430 public function getTax( $total, $materials = array() ) {
8431 global $usces_settings;
8432
8433 if ( isset( $this->options['tax_display'] ) && 'deactivate' == $this->options['tax_display'] ) {
8434 return 0;
8435 }
8436 if ( empty( $this->options['tax_rate'] ) ) {
8437 return 0;
8438 }
8439 // if ( ! empty( $materials ) ) {
8440 // extract( $materials );//need( 'total_items_price', 'shipping_charge', 'discount', 'cod_fee', 'use_point' )
8441 // }
8442
8443 if ( $this->is_reduced_taxrate() ) {
8444 if ( 'include' == $this->options['tax_mode'] ) {
8445 return 0;
8446 }
8447 if ( ! empty( $materials ) ) {
8448 extract( $materials );
8449 if ( empty( $carts ) ) {
8450 $carts = array();
8451 $materials = compact( 'total_items_price', 'shipping_charge', 'discount', 'cod_fee', 'use_point', 'carts' );
8452 }
8453 }
8454
8455 $usces_tax = Welcart_Tax::get_instance();
8456 $usces_tax->get_order_tax( $materials );
8457 $tax = apply_filters( 'usces_filter_getTax', $usces_tax->tax, $materials );
8458
8459 } else {
8460
8461 if ( empty( $materials ) ) {
8462
8463 if ( 'include' == $this->options['tax_mode'] ) {
8464 $tax = (float) sprintf( '%.3f', (float) $total * (float) $this->options['tax_rate'] / ( 100 + (float) $this->options['tax_rate'] ) );
8465 } else {
8466 $tax = (float) sprintf( '%.3f', (float) $total * (float) $this->options['tax_rate'] / 100 );
8467 }
8468
8469 } else {
8470 if ( 'include' == $this->options['tax_mode'] ) {
8471 return 0;
8472 }
8473
8474 extract( $materials ); // need( 'total_items_price', 'shipping_charge', 'discount', 'cod_fee', 'use_point' ).
8475
8476 if ( 1 == $this->options['point_coverage'] ) {
8477 if ( 'products' == $this->options['tax_target'] ) {
8478 $total = (float) $total_items_price + (float) $discount;
8479 } else {
8480 $total = (float) $total_items_price + (float) $discount + (float) $shipping_charge + (float) $cod_fee;
8481 }
8482 } else {
8483 if ( 'products' == $this->options['tax_target'] ) {
8484 $total = (float) $total_items_price + (float) $discount;
8485 } else {
8486 if ( empty( $use_point ) ) {
8487 $use_point = 0;
8488 }
8489 $total = (float) $total_items_price + (float) $discount - (int) $use_point + (float) $shipping_charge + (float) $cod_fee;
8490 }
8491 }
8492 $total = apply_filters( 'usces_filter_getTax_total', $total, $materials );
8493
8494 $tax = (float) sprintf( '%.3f', (float) $total * (float) $this->options['tax_rate'] / 100 );
8495 }
8496
8497 $tax = usces_tax_rounding_off( $tax );
8498 $tax = apply_filters( 'usces_filter_getTax', $tax, $materials );
8499 }
8500
8501 return $tax;
8502 }
8503
8504 public function set_cart_fees( $member, $entries ) {
8505 global $usces_entries;
8506
8507 $carts = $this->cart->get_cart();
8508 $entries = $this->cart->get_entry();
8509 $total_items_price = $this->get_total_price();
8510 $entries['order']['total_items_price'] = $total_items_price;
8511
8512 if ( empty( $this->options['postage_privilege'] ) || $total_items_price < $this->options['postage_privilege'] ) {
8513 $shipping_charge = $this->getShippingCharge( $entries['delivery']['pref'], $carts, $entries );
8514 } else {
8515 $shipping_charge = 0;
8516 }
8517 $shipping_charge = apply_filters( 'usces_filter_set_cart_fees_shipping_charge', $shipping_charge, $carts, $entries );
8518 $entries['order']['shipping_charge'] = $shipping_charge;
8519
8520 $payments = $this->getPayments( $entries['order']['payment_name'] );
8521 $use_point = ( isset( $entries['order']['usedpoint'] ) ) ? (int) $entries['order']['usedpoint'] : 0;
8522 if ( $this->is_reduced_taxrate() ) {
8523 $usces_tax = Welcart_Tax::get_instance();
8524 $discount = $usces_tax->get_order_discount( $carts );
8525 $entries['order']['discount'] = $discount;
8526 $amount_by_cod = $total_items_price - $use_point + $discount;
8527 if ( 'all' == usces_is_fee_subject() ) {
8528 $amount_by_cod += $shipping_charge;
8529 }
8530 $amount_by_cod = apply_filters( 'usces_filter_set_cart_fees_amount_by_cod', $amount_by_cod, $entries, $total_items_price, $use_point, $discount, $shipping_charge );
8531 $cod_fee = $this->getCODFee( $entries['order']['payment_name'], $amount_by_cod, $entries );
8532 $cod_fee = apply_filters( 'usces_filter_set_cart_fees_cod', $cod_fee, $entries, $total_items_price, $use_point, $discount, $shipping_charge, $amount_by_cod );
8533 $entries['order']['cod_fee'] = $cod_fee;
8534
8535 if ( 'include' == $this->options['tax_mode'] ) {
8536 $tax = 0;
8537 } else {
8538 $materials = compact( 'member', 'entries', 'carts', 'total_items_price', 'shipping_charge', 'payments', 'discount', 'cod_fee', 'use_point' );
8539 $usces_tax->get_order_tax( $materials );
8540 $tax = apply_filters( 'usces_filter_getTax', $usces_tax->tax, $materials );
8541 }
8542
8543 $total_price = $total_items_price - $use_point + $discount + $shipping_charge + $cod_fee;
8544 if ( $total_price < 0 ) {
8545 $total_price = 0;
8546 }
8547 $total_price = apply_filters( 'usces_filter_set_cart_fees_total_price', $total_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee );
8548
8549 } else {
8550 $discount = $this->get_order_discount( null, $carts );
8551 $entries['order']['discount'] = $discount;
8552 $amount_by_cod = $total_items_price - $use_point + $discount;
8553 if ( 'all' == usces_is_fee_subject() ) {
8554 $amount_by_cod += $shipping_charge;
8555 }
8556 $amount_by_cod = apply_filters( 'usces_filter_set_cart_fees_amount_by_cod', $amount_by_cod, $entries, $total_items_price, $use_point, $discount, $shipping_charge );
8557 $cod_fee = $this->getCODFee( $entries['order']['payment_name'], $amount_by_cod, $entries );
8558 $cod_fee = apply_filters( 'usces_filter_set_cart_fees_cod', $cod_fee, $entries, $total_items_price, $use_point, $discount, $shipping_charge, $amount_by_cod );
8559 $entries['order']['cod_fee'] = $cod_fee;
8560
8561 $total_price = $total_items_price - $use_point + $discount + $shipping_charge + $cod_fee;
8562 if ( $total_price < 0 ) {
8563 $total_price = 0;
8564 }
8565 $total_price = apply_filters( 'usces_filter_set_cart_fees_total_price', $total_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee );
8566
8567 $materials = compact( 'member', 'entries', 'carts', 'total_items_price', 'shipping_charge', 'payments', 'discount', 'cod_fee', 'use_point' );
8568 $tax = $this->getTax( $total_price, $materials );
8569 }
8570 $entries['order']['total_price'] = $total_price;
8571 $entries['order']['tax'] = $tax;
8572
8573 if ( 'exclude' == $this->options['tax_mode'] ) {
8574 if ( 0 < $use_point ) {
8575 $total_full_price = $total_items_price - $use_point + $discount + $shipping_charge + $cod_fee + $tax;
8576 if ( $total_full_price < 0 ) {
8577 $total_full_price = 0;
8578 }
8579 } else {
8580 $total_full_price = $total_price + $tax;
8581 }
8582 } else {
8583 $total_full_price = $total_price;
8584 }
8585
8586 $total_full_price = apply_filters( 'usces_filter_set_cart_fees_total_full_price', $total_full_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee );
8587 $entries['order']['total_full_price'] = $total_full_price;
8588
8589 $mem_id = isset( $member['ID'] ) ? $member['ID'] : null;
8590 $get_point = $this->get_order_point( $mem_id );
8591 $get_point = apply_filters( 'usces_filter_set_get_point', $get_point, $entries, $carts );
8592
8593 $array = array(
8594 'total_items_price' => $total_items_price,
8595 'total_price' => $total_price,
8596 'total_full_price' => $total_full_price,
8597 'getpoint' => $get_point,
8598 'usedpoint' => $use_point,
8599 'discount' => $discount,
8600 'shipping_charge' => $shipping_charge,
8601 'cod_fee' => $cod_fee,
8602 'tax' => $tax,
8603 );
8604 $this->cart->set_order_entry( $array );
8605 $usces_entries = $this->cart->get_entry();
8606 }
8607
8608 public function getPayments( $payment_name ) {
8609 $init = array(
8610 'id' => null,
8611 'name' => null,
8612 'explanation' => null,
8613 'settlement' => null,
8614 'module' => null,
8615 'sort' => null,
8616 'use' => null,
8617 );
8618
8619 if ( '#none#' == $payment_name ) {
8620 return $init;
8621 }
8622 $payments = usces_get_system_option( 'usces_payment_method', 'name' );
8623 if ( isset( $payments[ $payment_name ] ) ) {
8624 return $payments[ $payment_name ];
8625 }
8626 return $init;
8627 }
8628
8629 public function is_maintenance() {
8630 if ( 'Maintenancemode' == $this->options['display_mode'] ) {
8631 return true;
8632 } else {
8633 return false;
8634 }
8635 }
8636
8637 public function get_member_history( $mem_id, $allow_filter = false ) {
8638 global $wpdb;
8639 $order_table = $wpdb->prefix . 'usces_order';
8640
8641 if ( is_user_logged_in() && is_admin() ) {
8642
8643 $query = $wpdb->prepare( "SELECT * FROM $order_table WHERE mem_id = %d ORDER BY order_date DESC", $mem_id );
8644 $query = apply_filters( 'usces_filter_member_history_query', $query, $mem_id, $allow_filter );
8645 $results = $wpdb->get_results( $query );
8646
8647 } elseif ( ! is_admin() ) {
8648
8649 $cancel_query = '%cancel%';
8650 $estimate_query = '%estimate%';
8651 $exclude_cancel = $this->usces_get_member_cookies( 'ord_ex_cancel' );
8652 if ( $allow_filter && 'on' === (string) $exclude_cancel ) {
8653 $condition = ' ( order_status NOT LIKE %s AND order_status NOT LIKE %s ) ';
8654 } else {
8655 $condition = ' ( order_status LIKE %s OR order_status NOT LIKE %s ) ';
8656 }
8657
8658 $pur_date = $this->usces_get_member_cookies( 'pur-date' );
8659 if ( $allow_filter && $pur_date ) {
8660 $now = current_time( 'timestamp' );
8661 $type_filter = 'date';
8662 if ( false !== strpos( $pur_date, 'y_' ) ) {
8663 $type_filter = 'year';
8664 } elseif ( false !== strpos( $pur_date, 'm_' ) ) {
8665 $type_filter = 'month';
8666 }
8667 if ( 'year' === $type_filter ) {
8668 $purchase_year = (int) str_replace( 'y_', '', $pur_date );
8669 } elseif ( 'month' === $type_filter ) {
8670 $month_ago = (int) str_replace( 'm_', '', $pur_date );
8671 $first_day_of_previous_months = strtotime( "first day of -{$month_ago} months", $now );
8672 $last_day_of_previous_months = strtotime( "last day of -{$month_ago} months", $now );
8673 $purchase_date_from_string = date( 'Y-m-d 00:00:00', $first_day_of_previous_months );
8674 $purchase_date_to_string = date( 'Y-m-d 23:59:59', $last_day_of_previous_months );
8675 } else {
8676 $pur_date_val = (int) str_replace( 'd_', '', $pur_date );
8677 $previous_date = strtotime( "-{$pur_date_val} days", $now );
8678 $purchase_date_string = date( 'Y-m-d 00:00:00', $previous_date );
8679 }
8680 if ( 'year' === $type_filter ) {
8681 $query = $wpdb->prepare(
8682 "SELECT * FROM $order_table WHERE mem_id = %d AND YEAR(order_date) = %d AND {$condition} ORDER BY order_date DESC",
8683 $mem_id,
8684 $purchase_year,
8685 $cancel_query,
8686 $estimate_query
8687 );
8688 } elseif ( 'month' === $type_filter ) {
8689 $query = $wpdb->prepare(
8690 "SELECT * FROM $order_table WHERE mem_id = %d AND order_date >= %s AND order_date <= %s AND {$condition} ORDER BY order_date DESC",
8691 $mem_id,
8692 $purchase_date_from_string,
8693 $purchase_date_to_string,
8694 $cancel_query,
8695 $estimate_query
8696 );
8697 } else {
8698 $query = $wpdb->prepare(
8699 "SELECT * FROM $order_table WHERE mem_id = %d AND order_date >= %s AND {$condition} ORDER BY order_date DESC",
8700 $mem_id,
8701 $purchase_date_string,
8702 $cancel_query,
8703 $estimate_query
8704 );
8705 }
8706 } else {
8707 $query = $wpdb->prepare(
8708 "SELECT * FROM $order_table WHERE mem_id = %d AND {$condition} ORDER BY order_date DESC",
8709 $mem_id,
8710 $cancel_query,
8711 $estimate_query
8712 );
8713 }
8714
8715 $query = apply_filters( 'usces_filter_member_history_query_front', $query, $mem_id, $allow_filter );
8716 $results = $wpdb->get_results( $query );
8717 }
8718
8719 $i = 0;
8720 $res = array();
8721
8722 foreach ( $results as $value ) {
8723 $cart = usces_get_ordercartdata( $value->ID );
8724 $total_items_price = $this->get_total_price( $cart );
8725
8726 $data = array(
8727 'ID' => $value->ID,
8728 'cart' => $cart,
8729 'condition' => wel_safe_unserialize( $value->order_condition ),
8730 'getpoint' => $value->order_getpoint,
8731 'usedpoint' => $value->order_usedpoint,
8732 'discount' => $value->order_discount,
8733 'shipping_charge' => $value->order_shipping_charge,
8734 'payment_name' => $value->order_payment_name,
8735 'cod_fee' => $value->order_cod_fee,
8736 'tax' => $value->order_tax,
8737 'total_items_price' => $total_items_price,
8738 'order_status' => $value->order_status,
8739 'date' => mysql2date( __( 'Y/m/d' ), $value->order_date ),
8740 'order_date' => $value->order_date,
8741 'order_delidue_date' => $value->order_delidue_date,
8742 'order_delivery_method' => $value->order_delivery_method,
8743 'order_delivery_method_name' => usces_delivery_method_name( $value->order_delivery_method, 'return' ),
8744 'order_delivery_date' => $value->order_delivery_date,
8745 'order_modified' => $value->order_modified,
8746 );
8747 $res[] = apply_filters( 'usces_filter_member_history_data', $data, $mem_id, $value, $cart, $total_items_price );
8748 }
8749
8750 return $res;
8751 }
8752
8753 public function get_post_term_ids( $post_id, $taxonomy ) {
8754 global $wpdb;
8755 $query = $wpdb->prepare(
8756 "SELECT tt.term_id FROM $wpdb->term_relationships AS `tr`
8757 INNER JOIN $wpdb->term_taxonomy AS `tt` ON tt.term_taxonomy_id = tr.term_taxonomy_id
8758 WHERE tt.taxonomy = %s AND tr.object_id = %d",
8759 $taxonomy, $post_id
8760 );
8761 $ids = $wpdb->get_col( $query );
8762
8763 return $ids;
8764 }
8765
8766 public function get_tag_names( $post_id ) {
8767 global $wpdb;
8768 $tag = 'post_tag';
8769 $query = $wpdb->prepare(
8770 "SELECT t.name FROM $wpdb->term_relationships AS `tr`
8771 INNER JOIN $wpdb->term_taxonomy AS `tt` ON tt.term_taxonomy_id = tr.term_taxonomy_id
8772 INNER JOIN $wpdb->terms AS `t` ON t.term_id = tt.term_id
8773 WHERE tt.taxonomy = %s AND tr.object_id = %d",
8774 $tag, $post_id
8775 );
8776 $names = $wpdb->get_col( $query );
8777
8778 return apply_filters( 'usces_filter_get_tag_names', $names, $post_id );
8779 }
8780
8781 public function get_ID_byItemName( $item_code, $status = 'publish' ) {
8782 global $wpdb;
8783
8784 $table = usces_get_tablename( 'usces_item' );
8785 $id = $wpdb->get_var(
8786 $wpdb->prepare(
8787 "SELECT p.ID FROM {$wpdb->posts} AS `p`
8788 INNER JOIN {$table} AS `item` ON p.ID = item.post_id
8789 WHERE p.post_status = %s AND item.itemCode = %s",
8790 $status,
8791 $item_code
8792 )
8793 );
8794
8795 return $id;
8796 }
8797
8798 /**
8799 * @deprecated A1/C (Layer 3 / uscesid removal). uscesid 難読化生成。本体は不使用。未移行の拡張・
8800 * クライアント後方互換のためのみ残置。全消費側移行後に get_uscesid()/uscesdc() ともども削除する。
8801 */
8802 public function uscescv( $sessid, $flag ) {
8803 $chars = '';
8804 $i = 0;
8805 $h = 0;
8806 $usces_cookie = $this->get_cookie();
8807 if ( isset( $usces_cookie['id'] ) && ! empty( $usces_cookie['id'] ) ) {
8808 $cid = $usces_cookie['id'];
8809 } elseif ( isset( $_SESSION['usces_cookieid'] ) && ! empty( $_SESSION['usces_cookieid'] ) ) {
8810 $cid = $_SESSION['usces_cookieid'];
8811 } else {
8812 $cid = 0;
8813 }
8814 while ( $h < strlen( $sessid ) ) {
8815 if ( 0 == $i % 3 ) {
8816 $chars .= substr( $i, -1 );
8817 } else {
8818 $chars .= substr( $sessid, $h, 1 );
8819 $h++;
8820 }
8821 $i++;
8822 }
8823 if ( $flag ) {
8824 $postfix = ( isset( $_SERVER['REMOTE_ADDR'] ) && ! empty( $_SERVER['REMOTE_ADDR'] ) ) ? $_SERVER['REMOTE_ADDR'] : 'REMOTE_ADDR';
8825 $postfix = apply_filters( 'usces_sessid_force', $postfix );
8826 $sessid = $chars . '_' . $postfix . '_' . $cid . '_A';
8827 } else {
8828 $sessid = $chars . '_' . apply_filters( 'usces_sessid_flag', 'acting' ) . '_' . $cid . '_A';
8829 }
8830 $sessid = urlencode( base64_encode( $sessid ) );
8831
8832 return $sessid;
8833 }
8834
8835 /**
8836 * @deprecated A1/C (Layer 3 / uscesid removal). uscesid 復号。本体は不使用(A1 で唯一の呼び出しを撤去)。
8837 * 未移行の拡張・クライアント(直接 uscesdc()→session_id() する nopriv AJAX)後方互換のためのみ残置。
8838 * 全消費側移行後に get_uscesid()/uscescv() ともども削除する。
8839 */
8840 public function uscesdc( $sessid ) {
8841 $sessid = base64_decode( urldecode( $sessid ) );
8842 list( $sess, $addr, $cookieid, $none ) = explode( '_', $sessid, 4 );
8843 $postfix = ( isset( $_SERVER['REMOTE_ADDR'] ) && ! empty( $_SERVER['REMOTE_ADDR'] ) ) ? $_SERVER['REMOTE_ADDR'] : 'REMOTE_ADDR';
8844 $postfix = apply_filters( 'usces_sessid_force', $postfix );
8845 if ( 'acting' !== $addr && 'mobile' !== $addr && $postfix !== $addr ) {
8846 $sessid = '';
8847 return null;
8848 }
8849 $chars = '';
8850 $h = 0;
8851 while ( $h < strlen( $sess ) ) {
8852 if ( 0 != $h % 3 ) {
8853 $chars .= substr( $sess, $h, 1 );
8854 }
8855 $h++;
8856 }
8857 $sessid = $chars;
8858
8859 return $sessid;
8860 }
8861
8862 public function get_visiter( $period ) {
8863 global $wpdb;
8864 $datestr = substr( get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ), 0, 10 );
8865 $yearstr = substr( $datestr, 0, 4 );
8866 $monthstr = substr( $datestr, 5, 2 );
8867 $daystr = substr( $datestr, 8, 2 );
8868 if ( 'today' == $period ) {
8869 $date = $datestr;
8870 $today = $datestr;
8871 } elseif ( 'thismonth' == $period ) {
8872 $date = date( 'Y-m-01' );
8873 $today = $datestr;
8874 } elseif ( 'lastyear' == $period ) {
8875 $date = date( 'Y-m-01', mktime( 0, 0, 0, (int) $monthstr, 1, (int) $yearstr-1 ) );
8876 $today = date( 'Y-m-01', mktime( 0, 0, 0, (int) $monthstr, (int) $daystr, (int) $yearstr-1 ) );
8877 }
8878 $table_name = $wpdb->prefix . 'usces_access';
8879
8880 $query = $wpdb->prepare( "SELECT SUM(acc_num1) AS `ct1`, SUM(acc_num2) AS `ct2` FROM $table_name WHERE acc_date >= %s AND acc_date <= %s", $date, $today );
8881 $res = $wpdb->get_row( $query, ARRAY_A );
8882
8883 if ( null == $res ) {
8884 return 0;
8885 } else {
8886 return $res['ct1'] + $res['ct2'];
8887 }
8888 }
8889
8890 public function get_fvisiter( $period ) {
8891 global $wpdb;
8892 $datestr = substr( get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ), 0, 10 );
8893 $yearstr = substr( $datestr, 0, 4 );
8894 $monthstr = substr( $datestr, 5, 2 );
8895 $daystr = substr( $datestr, 8, 2 );
8896 if ( 'today' == $period ) {
8897 $date = $datestr;
8898 $today = $datestr;
8899 } elseif ( 'thismonth' == $period ) {
8900 $date = date( 'Y-m-01' );
8901 $today = $datestr;
8902 } elseif ( 'lastyear' == $period ) {
8903 $date = date( 'Y-m-01', mktime( 0, 0, 0, (int) $monthstr, 1, (int) $yearstr - 1 ) );
8904 $today = date( 'Y-m-01', mktime( 0, 0, 0, (int) $monthstr, (int) $daystr, (int) $yearstr - 1 ) );
8905 }
8906 $table_name = $wpdb->prefix . 'usces_access';
8907
8908 $query = $wpdb->prepare( "SELECT SUM(acc_num2) AS `ct` FROM $table_name WHERE acc_date >= %s AND acc_date <= %s", $date, $today );
8909 $res = $wpdb->get_var( $query );
8910
8911 if ( null == $res ) {
8912 return 0;
8913 } else {
8914 return $res;
8915 }
8916 }
8917
8918 public function get_order_num( $period ) {
8919 global $wpdb;
8920 $datestr = substr( get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ), 0, 10 );
8921 $yearstr = substr( $datestr, 0, 4 );
8922 $monthstr = substr( $datestr, 5, 2 );
8923 $daystr = substr( $datestr, 8, 2 );
8924 if ( 'today' == $period ) {
8925 $date = date( 'Y-m-d 00:00:00', current_time( 'timestamp' ) );
8926 $today = date( 'Y-m-d 23:59:59', current_time( 'timestamp' ) );
8927 } elseif ( 'thismonth' == $period ) {
8928 $date = date( 'Y-m-01 00:00:00', current_time( 'timestamp' ) );
8929 $today = date( 'Y-m-d 23:59:59', current_time( 'timestamp' ) );
8930 } elseif ( 'lastyear' == $period ) {
8931 $date = date( 'Y-m-01 00:00:00', mktime( 0, 0, 0, (int) $monthstr, 1, (int) $yearstr - 1 ) );
8932 $today = date( 'Y-m-d 23:59:59', mktime( 0, 0, 0, (int) $monthstr + 1, 0, (int) $yearstr - 1 ) );
8933 }
8934 $table_name = $wpdb->prefix . 'usces_order';
8935
8936 $query = $wpdb->prepare( "SELECT COUNT(ID) AS `ct` FROM $table_name WHERE order_date >= %s AND order_date <= %s AND 0 = LOCATE(%s, order_status) AND 0 = LOCATE(%s, order_status)", $date, $today, 'cancel', 'estimate' );
8937 $res = $wpdb->get_var( $query );
8938
8939 if ( null == $res ) {
8940 return 0;
8941 } else {
8942 return $res;
8943 }
8944 }
8945
8946 public function get_order_amount( $period ) {
8947 global $wpdb;
8948
8949 $cache_key = 'wel_order_amount_period_' . $period;
8950
8951 $res = wp_cache_get( $cache_key );
8952 if ( false === $res ) {
8953
8954 $datestr = substr( get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ), 0, 10 );
8955 $yearstr = substr( $datestr, 0, 4 );
8956 $monthstr = substr( $datestr, 5, 2 );
8957 $daystr = substr( $datestr, 8, 2 );
8958 if ( 'today' == $period ) {
8959 $date = date( 'Y-m-d 00:00:00', current_time( 'timestamp' ) );
8960 $today = date( 'Y-m-d 23:59:59', current_time( 'timestamp' ) );
8961 } elseif ( 'thismonth' == $period ) {
8962 $date = date( 'Y-m-01 00:00:00', current_time( 'timestamp' ) );
8963 $today = date( 'Y-m-d 23:59:59', current_time( 'timestamp' ) );
8964 } elseif ( 'lastyear' == $period ) {
8965 $date = date( 'Y-m-01 00:00:00', mktime( 0, 0, 0, (int) $monthstr, 1, (int) $yearstr - 1 ) );
8966 $today = date( 'Y-m-d 23:59:59', mktime( 0, 0, 0, (int) $monthstr + 1, 0, (int) $yearstr - 1 ) );
8967 }
8968 $table_name = $wpdb->prefix . 'usces_order';
8969
8970 $query = $wpdb->prepare(
8971 "SELECT
8972 SUM(order_item_total_price) AS `price`,
8973 SUM(order_usedpoint) AS `point`,
8974 SUM(order_discount) AS `discount`,
8975 SUM(order_shipping_charge) AS `shipping`,
8976 SUM(order_cod_fee) AS `cod`,
8977 SUM(order_tax) AS `tax`
8978 FROM $table_name WHERE order_date >= %s AND order_date <= %s AND 0 = LOCATE(%s, order_status) AND 0 = LOCATE(%s, order_status)",
8979 $date, $today, 'cancel', 'estimate'
8980 );
8981 $res = $wpdb->get_row( $query, ARRAY_A );
8982
8983 if ( null !== $res ) {
8984 wp_cache_set( $cache_key, $res );
8985 }
8986 }
8987
8988 if ( null == $res ) {
8989 return 0;
8990 } else {
8991 return $res['price'] - $res['point'] + $res['discount'] + $res['shipping'] + $res['cod'] + $res['tax'];
8992 }
8993 }
8994
8995 public function is_status( $need, $str ) {
8996 if ( ! is_string( $str ) || empty( $str ) ) {
8997 $array = array();
8998 } else {
8999 $array = explode( ',', $str );
9000 }
9001 return in_array( $need, $array );
9002 }
9003
9004 public function make_status( $taio = '', $receipt = '', $admin = '' ) {
9005 $str = '';
9006 if ( '' != $taio && '#none#' != $taio ) {
9007 $str .= $taio . ',';
9008 }
9009 if ( '' != $receipt && '#none#' != $receipt ) {
9010 $str .= $receipt . ',';
9011 }
9012 if ( '' != $admin && '#none#' != $admin ) {
9013 $str .= $admin . ',';
9014 }
9015 return $str;
9016 }
9017
9018 public function get_memberid_by_email( $email ) {
9019 global $wpdb;
9020 $table_name = usces_get_tablename( 'usces_member' );
9021 $query = $wpdb->prepare( "SELECT ID FROM $table_name WHERE mem_email = %s", $email );
9022 $res = $wpdb->get_var( $query );
9023 return $res;
9024 }
9025
9026 public function get_condition() {
9027 $order_conditions = array(
9028 'display_mode' => $this->options['display_mode'],
9029 'campaign_privilege' => $this->options['campaign_privilege'],
9030 'campaign_category' => $this->options['campaign_category'],
9031 'privilege_point' => $this->options['privilege_point'],
9032 'privilege_discount' => $this->options['privilege_discount'],
9033 'tax_display' => ( isset( $this->options['tax_display'] ) ) ? $this->options['tax_display'] : 'activate',
9034 'tax_mode' => $this->options['tax_mode'],
9035 'tax_target' => $this->options['tax_target'],
9036 'tax_rate' => $this->options['tax_rate'],
9037 'tax_method' => $this->options['tax_method'],
9038 'applicable_taxrate' => ( isset( $this->options['applicable_taxrate'] ) ) ? $this->options['applicable_taxrate'] : 'standard',
9039 'tax_rate_reduced' => ( isset( $this->options['tax_rate_reduced'] ) ) ? $this->options['tax_rate_reduced'] : $this->options['tax_rate'],
9040 'membersystem_state' => $this->options['membersystem_state'],
9041 'membersystem_point' => $this->options['membersystem_point'],
9042 'point_coverage' => $this->options['point_coverage'],
9043 );
9044 return $order_conditions;
9045 }
9046
9047 public function get_bestseller_ids( $days = '' ) {
9048 global $wpdb;
9049
9050 $datestr = substr( get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ), 0, 10 );
9051 $yearstr = substr( $datestr, 0, 4 );
9052 $monthstr = substr( $datestr, 5, 2 );
9053 $daystr = substr( $datestr, 8, 2 );
9054
9055 $res = array();
9056 $order_table_name = $wpdb->prefix . 'usces_order';
9057 $where = '';
9058 if ( empty( $days ) ) {
9059 $days = 30;
9060 }
9061 $order_date = date( 'Y-m-d H:i:s', mktime( 0, 0, 0, (int) $monthstr, ( (int) $daystr - $days), (int) $yearstr ) );
9062 $where = " WHERE order_date >= '{$order_date}'";
9063 $query = "SELECT order_cart FROM {$order_table_name}" . $where;
9064 $dbres = $wpdb->get_col( $query );
9065 if ( ! $dbres ) {
9066 return false;
9067 }
9068
9069 foreach ( (array) $dbres as $carts ) {
9070 $rows = wel_safe_unserialize( $carts );
9071 foreach ( (array) $rows as $carts ) {
9072 if ( 'publish' != get_post_status( $carts['post_id'] ) ) {
9073 continue;
9074 }
9075 $id = $carts['post_id'];
9076 $qu = $carts['quantity'];
9077 if ( array_key_exists( $id, $res ) ) {
9078 $res[ $id ] = $res[ $id ] + $qu;
9079 } else {
9080 $res[ $id ] = $qu;
9081 }
9082 }
9083 }
9084 arsort( $res );
9085 $results = array_keys( $res );
9086 return $results;
9087 }
9088
9089 public function get_items_num() {
9090 global $wpdb;
9091 $res = $wpdb->get_var(
9092 $wpdb->prepare(
9093 "SELECT COUNT(ID) AS `ct` FROM {$wpdb->posts}
9094 WHERE post_mime_type = %s AND post_type = %s AND post_status <> %s",
9095 'item',
9096 'post',
9097 'trash'
9098 )
9099 );
9100
9101 return $res;
9102 }
9103
9104 public function is_gptekiyo( $post_id, $sku, $quant ) {
9105 $skus = $this->get_skus( $post_id, 'code' );
9106 if ( ! isset( $skus[ $sku ]['gp'] ) || ! $skus[ $sku ]['gp'] ) {
9107 return false;
9108 }
9109
9110 $GpN1 = $this->getItemGpNum1( $post_id );
9111 $GpN2 = $this->getItemGpNum2( $post_id );
9112 $GpN3 = $this->getItemGpNum3( $post_id );
9113
9114 if ( empty( $GpN1 ) ) {
9115
9116 return false;
9117
9118 } elseif ( ! empty( $GpN1 ) && empty( $GpN2 ) ) {
9119
9120 if ( $quant >= $GpN1 ) {
9121 return true;
9122 } else {
9123 return false;
9124 }
9125
9126 } elseif ( ! empty( $GpN1 ) && ! empty( $GpN2 ) && empty( $GpN3 ) ) {
9127
9128 if ( $quant >= $GpN2 ) {
9129 return true;
9130 } elseif ( $quant >= $GpN1 && $quant < $GpN2 ) {
9131 return true;
9132 } else {
9133 return false;
9134 }
9135
9136 } elseif ( ! empty( $GpN1 ) && ! empty( $GpN2 ) && ! empty( $GpN3 ) ) {
9137
9138 if ( $quant >= $GpN3 ) {
9139 return true;
9140 } elseif ( $quant >= $GpN2 && $quant < $GpN3 ) {
9141 return true;
9142 } elseif ( $quant >= $GpN1 && $quant < $GpN2 ) {
9143 return true;
9144 } else{
9145 return false;
9146 }
9147 }
9148 }
9149
9150 public function get_available_delivery_method() {
9151 if ( $this->cart->num_row() > 0 ) {
9152 $cart = $this->cart->get_cart();
9153 $before_deli = array();
9154 $intersect = array();
9155 $integration = array();
9156 $temp = array();
9157 $in = 0;
9158 foreach ( $cart as $key => $row ) {
9159 $deli = $this->getItemDeliveryMethod( $row['post_id'] );
9160 if ( empty( $deli ) ) {
9161 continue;
9162 }
9163 if ( 0 === $in ) {
9164 $intersect = $deli;
9165 }
9166 $intersect = array_intersect( $deli, $intersect );
9167 $before_deli = $deli;
9168 foreach ( $deli as $value ) {
9169 $integration[] = $value;
9170 }
9171 $in++;
9172 }
9173 $integration = array_unique( $integration );
9174 foreach ( $integration as $id ) {
9175 $index = $this->get_delivery_method_index( $id );
9176 if ( 0 <= $index ) {
9177 $temp[ $index ] = $id;
9178 }
9179 }
9180 ksort( $temp );
9181 $force = array( array_shift( $temp ) );
9182
9183 if ( empty( $intersect ) ) {
9184 return $force;
9185 } else {
9186 return $intersect;
9187 }
9188 }
9189 return array();
9190 }
9191
9192 public function get_delivery_method_index( $id ) {
9193 $index = false;
9194 $delivery_method_count = ( $this->options['delivery_method'] && is_array( $this->options['delivery_method'] ) ) ? count( $this->options['delivery_method'] ) : 0;
9195 for ( $i = 0; $i < $delivery_method_count; $i++ ) {
9196 if ( isset( $this->options['delivery_method'][ $i ]['id'] ) && $this->options['delivery_method'][ $i ]['id'] === (int) $id ) {
9197 $index = $i;
9198 }
9199 }
9200 if ( false === $index ) {
9201 return -1;
9202 } else {
9203 return $index;
9204 }
9205 }
9206
9207 public function get_shipping_charge_index( $id ) {
9208 $index = false;
9209 $shipping_charge_count = ( $this->options['shipping_charge'] && is_array( $this->options['shipping_charge'] ) ) ? count( $this->options['shipping_charge'] ) : 0;
9210 for ( $i = 0; $i < $shipping_charge_count; $i++ ) {
9211 if ( isset( $this->options['shipping_charge'][ $i ] ) && (int) $this->options['shipping_charge'][ $i ]['id'] == (int) $id ) {
9212 $index = $i;
9213 }
9214 }
9215 if ( false === $index ) {
9216 return -1;
9217 } else {
9218 return $index;
9219 }
9220 }
9221
9222 public function get_initial_data( $xml ) {
9223 $buf = file_get_contents( $xml );
9224 preg_match_all( '@<page>.*?<post_title>(.*?)</post_title>.*?<post_status>(.*?)</post_status>.*?<post_name>(.*?)</post_name>.*?<post_content>(.*?)</post_content>.*?</page>@s', $buf, $match, PREG_SET_ORDER );
9225 return $match;
9226 }
9227
9228 public function getCurrencySymbol() {
9229 global $usces_settings;
9230 $cr = $this->options['system']['currency'];
9231 list( $code, $decimal, $point, $seperator, $symbol ) = $usces_settings['currency'][ $cr ];
9232 return $symbol;
9233 }
9234
9235 public function getCartItemName( $post_id, $sku ) {
9236 $name_arr = array();
9237 $name_str = '';
9238
9239 foreach ( $this->options['indi_item_name'] as $key => $value ) {
9240 if ( $value ) {
9241 $pos = (int) $this->options['pos_item_name'][ $key ];
9242 $ind = ( 0 === $pos ) ? 'A' : $pos;
9243 switch ( $key ) {
9244 case 'item_name':
9245 $name_arr[ $ind ][ $key ] = $this->getItemName( $post_id );
9246 break;
9247 case 'item_code':
9248 $name_arr[ $ind ][ $key ] = $this->getItemCode( $post_id );
9249 break;
9250 case 'sku_name':
9251 $name_arr[ $ind ][ $key ] = $this->getItemSkuDisp( $post_id, $sku );
9252 break;
9253 case 'sku_code':
9254 $name_arr[ $ind ][ $key ] = $sku;
9255 break;
9256 }
9257 }
9258 }
9259 ksort( $name_arr );
9260 foreach ( $name_arr as $vals ) {
9261 foreach ( $vals as $key => $value ) {
9262 $name_str .= $value . ' ';
9263 }
9264 }
9265
9266 $name_str = apply_filters( 'usces_admin_order_item_name_filter', $name_str, $post_id, $sku );
9267
9268 return trim( $name_str );
9269 }
9270
9271 public function getCartItemName_byOrder( $cart_row ) {
9272 $name_arr = array();
9273 $name_str = '';
9274
9275 foreach ( $this->options['indi_item_name'] as $key => $value ) {
9276 if ( $value ) {
9277 $pos = (int) $this->options['pos_item_name'][ $key ];
9278 $ind = ( 0 === $pos ) ? 'A' : $pos;
9279 switch ( $key ) {
9280 case 'item_name':
9281 $name_arr[ $ind ][ $key ] = $cart_row['item_name'];
9282 break;
9283 case 'item_code':
9284 $name_arr[ $ind ][ $key ] = $cart_row['item_code'];
9285 break;
9286 case 'sku_name':
9287 $name_arr[ $ind ][ $key ] = $cart_row['sku_name'];
9288 break;
9289 case 'sku_code':
9290 $name_arr[ $ind ][ $key ] = $cart_row['sku_code'];
9291 break;
9292 }
9293 }
9294 }
9295 ksort( $name_arr );
9296 foreach ( $name_arr as $vals ) {
9297 foreach ( $vals as $key => $value ) {
9298 $name_str .= $value . ' ';
9299 }
9300 }
9301
9302 $name_str = apply_filters( 'usces_filter_item_mame_by_order', $name_str, $cart_row );
9303
9304 return trim( $name_str );
9305 }
9306
9307 public function set_reserve_pre_order_id() {
9308 $entry = $this->cart->get_entry();
9309 $id = ( isset( $entry['reserve']['pre_order_id'] ) && ! empty( $entry['reserve']['pre_order_id'] ) ) ? $entry['reserve']['pre_order_id'] : uniqid( '' );
9310 $this->cart->set_pre_order_id( $id );
9311 }
9312
9313 public function get_current_pre_order_id() {
9314 $entry = $this->cart->get_entry();
9315 $id = ( isset( $entry['reserve']['pre_order_id'] ) && ! empty( $entry['reserve']['pre_order_id'] ) ) ? $entry['reserve']['pre_order_id'] : null;
9316 return $id;
9317 }
9318
9319 public function get_order_id_by_pre_order_id( $pre_order_id ) {
9320 global $wpdb;
9321 $query = $wpdb->prepare( "SELECT order_id FROM {$wpdb->prefix}usces_order_meta WHERE meta_key = %s AND meta_value = %s", 'pre_order_id', $pre_order_id );
9322 $order_id = $wpdb->get_var( $query );
9323 return $order_id;
9324 }
9325
9326 public function get_reserve( $order_id, $key ) {
9327 global $wpdb;
9328 $order_meta_table_name = $wpdb->prefix . 'usces_order_meta';
9329 $query = $wpdb->prepare( "SELECT meta_value FROM $order_meta_table_name WHERE order_id = %d AND meta_key = %s", $order_id, $key );
9330 $res = $wpdb->get_var( $query );
9331 return $res;
9332 }
9333
9334 public function get_order_meta_value( $key, $order_id ) {
9335 global $wpdb;
9336 $order_meta_table_name = $wpdb->prefix . 'usces_order_meta';
9337 $query = $wpdb->prepare( "SELECT meta_value FROM $order_meta_table_name WHERE order_id = %d AND meta_key = %s", $order_id, $key );
9338 $res = $wpdb->get_var( $query );
9339 return $res;
9340 }
9341
9342 public function set_order_meta_value( $key, $meta_value, $order_id, $check = 1 ) {
9343 global $wpdb;
9344
9345 if ( empty( $order_id ) ) {
9346 return;
9347 }
9348
9349 $order_id = (int) $order_id;
9350 if ( $check ) {
9351 $order = $this->get_order_data( $order_id, 'direct' );
9352 if ( null === $order ) {
9353 return;
9354 }
9355 }
9356
9357 $table_name = $wpdb->prefix . 'usces_order_meta';
9358 $query = $wpdb->prepare(
9359 "SELECT count(*) FROM $table_name WHERE order_id = %d AND meta_key = %s",
9360 $order_id, $key
9361 );
9362 $res = $wpdb->get_var( $query );
9363 if ( 0 < $res ) {
9364 $query = $wpdb->prepare(
9365 "UPDATE $table_name SET meta_value = %s WHERE order_id = %d AND meta_key = %s",
9366 $meta_value,
9367 $order_id,
9368 $key
9369 );
9370 $res2 = $wpdb->query( $query );
9371 } else {
9372 $query = $wpdb->prepare(
9373 "INSERT INTO $table_name (order_id, meta_key, meta_value)
9374 VALUES(%d, %s, %s)",
9375 $order_id,
9376 $key,
9377 $meta_value
9378 );
9379 $res2 = $wpdb->query( $query );
9380 }
9381 return $res2;
9382 }
9383
9384 public function del_order_meta( $key, $order_id ) {
9385 global $wpdb;
9386 $table_name = $wpdb->prefix . 'usces_order_meta';
9387 $query = $wpdb->prepare( "DELETE FROM $table_name WHERE order_id = %d AND meta_key = %s", $order_id, $key );
9388 $res = $wpdb->query( $query );
9389 return $res;
9390 }
9391
9392 public function set_session_custom_member( $member_id ) {
9393 unset( $_SESSION['usces_member']['custom_member'] );
9394 $meta = usces_has_custom_field_meta( 'member' );
9395 if ( is_array( $meta ) ) {
9396 $keys = array_keys( $meta );
9397 foreach ( $keys as $key ) {
9398 $csmb_key = 'csmb_' . $key;
9399 $_SESSION['usces_member']['custom_member'][ $key ] = wel_safe_maybe_unserialize( $this->get_member_meta_value( $csmb_key, $member_id ) );
9400 }
9401 }
9402 }
9403
9404 public function reg_custom_member( $member_id ) {
9405 $csmb_meta = usces_has_custom_field_meta( 'member' );
9406 if ( is_array( $csmb_meta ) ) {
9407 foreach ( $csmb_meta as $key => $entry ) {
9408 if ( '4' == $entry['means'] ) {
9409 $this->del_member_meta( 'csmb_' . $key, $member_id );
9410 }
9411 }
9412 }
9413 if ( ! empty( $_POST['custom_member'] ) ) {
9414 foreach ( $_POST['custom_member'] as $key => $value ) {
9415 $csmb_key = 'csmb_' . $key;
9416 $value = wel_safe_text_serialize( $value );
9417 if ( is_array( $value ) ) {
9418 $value = serialize( $value );
9419 }
9420 $res = $this->set_member_meta_value( $csmb_key, $value, $member_id );
9421 if ( false === $res ) {
9422 return false;
9423 }
9424 }
9425 } elseif ( isset( $_POST['custom_customer'] ) ) {
9426 foreach ( $_POST['custom_customer'] as $key => $value ) {
9427 $csmb_key = 'csmb_' . $key;
9428 $value = wel_safe_text_serialize( $value );
9429 if ( is_array( $value ) ) {
9430 $value = serialize( $value );
9431 }
9432 $res = $this->set_member_meta_value( $csmb_key, $value, $member_id );
9433 if ( false === $res ) {
9434 return false;
9435 }
9436 }
9437 }
9438 }
9439
9440 public function save_order_acting_data( $rand ) {
9441 global $wpdb;
9442 $data = serialize(
9443 array(
9444 'cart' => $this->cart->get_cart(),
9445 'entry' => $this->cart->get_entry(),
9446 )
9447 );
9448 $table_name = $wpdb->prefix . 'usces_access';
9449 $query = $wpdb->prepare(
9450 "INSERT INTO $table_name (acc_type, acc_str1, acc_date, acc_key, acc_value)
9451 VALUES(%s, %s, now(), %s, %s)",
9452 'acting_data',
9453 $this->get_uscesid(false),
9454 $rand,
9455 $data
9456 );
9457 $res = $wpdb->query( $query );
9458 return $res;
9459 }
9460
9461 public function set_member_meta_value( $key, $meta_value, $member_id = '' ) {
9462 global $wpdb;
9463
9464 if ( WCUtils::is_blank( $member_id ) ) {
9465 if ( ! $this->is_member_logged_in() ) {
9466 return;
9467 }
9468 $member = $this->get_member();
9469 $member_id = $member['ID'];
9470 }
9471
9472 $table_name = usces_get_tablename( 'usces_member_meta' );
9473 $query = $wpdb->prepare( "SELECT count(*) FROM $table_name WHERE member_id = %d AND meta_key = %s", $member_id, $key );
9474 $res = $wpdb->get_var( $query );
9475 if ( 0 < $res ) {
9476 $query = $wpdb->prepare(
9477 "UPDATE $table_name SET meta_value = %s WHERE member_id = %d AND meta_key = %s",
9478 $meta_value,
9479 $member_id,
9480 $key
9481 );
9482 $res2 = $wpdb->query( $query );
9483 } else {
9484 $query = $wpdb->prepare(
9485 "INSERT INTO $table_name (member_id, meta_key, meta_value)
9486 VALUES(%d, %s, %s)",
9487 $member_id,
9488 $key,
9489 $meta_value
9490 );
9491 $res2 = $wpdb->query( $query );
9492 }
9493 return $res2;
9494 }
9495
9496 public function get_member_meta_value( $key, $member_id ) {
9497 global $wpdb;
9498 $table_name = usces_get_tablename( 'usces_member_meta' );
9499 $query = $wpdb->prepare( "SELECT meta_value FROM $table_name WHERE member_id = %d AND meta_key = %s", $member_id, $key );
9500 $res = $wpdb->get_var( $query );
9501 return $res;
9502 }
9503
9504 public function del_member_meta( $key, $member_id ) {
9505 global $wpdb;
9506 $table_name = usces_get_tablename( 'usces_member_meta' );
9507 $query = $wpdb->prepare( "DELETE FROM $table_name WHERE member_id = %d AND meta_key = %s", $member_id, $key );
9508 $res = $wpdb->query( $query );
9509 return $res;
9510 }
9511
9512 public function get_member_meta( $member_id ) {
9513 global $wpdb;
9514 $table_name = usces_get_tablename( 'usces_member_meta' );
9515 $query = $wpdb->prepare( "SELECT * FROM $table_name WHERE member_id = %d AND meta_key <> 'customer_country' AND meta_key NOT LIKE %s", $member_id, 'csmb_%' );
9516 $res = $wpdb->get_results( $query, ARRAY_A );
9517 return $res;
9518 }
9519
9520 public function get_settle_info_field( $order_id ) {
9521 global $wpdb;
9522 $fields = array();
9523 $table_name = $wpdb->prefix . 'usces_order_meta';
9524 $meta_keys = apply_filters( 'usces_filter_settle_info_field_meta_keys', array( 'settlement_id', 'order_number', 'res_tracking_id', 'SID', 'TransactionId' ) );
9525 $query = $wpdb->prepare( "SELECT meta_key, meta_value FROM $table_name WHERE order_id = %d AND ( meta_key LIKE %s OR meta_key IN( %s ) )", $order_id, 'acting_%', implode( "','", $meta_keys ) );
9526 $query = stripslashes( $query );
9527 $res = $wpdb->get_results( $query, ARRAY_A );
9528 if ( ! $res ) {
9529 return $fields;
9530 }
9531 foreach ( $res as $value ) {
9532 if ( in_array( $value['meta_key'], $meta_keys ) ) {
9533 $meta_key = $value['meta_key'];
9534 if ( 'settlement_id' == $meta_key ) {
9535 $meta_values = wel_safe_maybe_unserialize( $value['meta_value'] );
9536 if ( is_array( $meta_values ) ) {
9537 foreach ( $meta_values as $key => $meta_value ) {
9538 $fields[ $key ] = $meta_value;
9539 }
9540 } else {
9541 $fields['settlement_id'] = $meta_values;
9542 }
9543 } else {
9544 $fields[ $meta_key ] = $value['meta_value'];
9545 }
9546 } elseif ( 'acting_' == substr( $value['meta_key'], 0, 7 ) ) {
9547 $meta_values = usces_unserialize( $value['meta_value'] );
9548 if ( is_array( $meta_values ) ) {
9549 foreach ( $meta_values as $key => $meta_value ) {
9550 $fields[ $key ] = $meta_value;
9551 }
9552 } else {
9553 $meta_values = wel_safe_maybe_unserialize( $value['meta_value'] );
9554 if ( is_array( $meta_values ) ) {
9555 foreach ( $meta_values as $key => $meta_value ) {
9556 $fields[ $key ] = $meta_value;
9557 }
9558 }
9559 }
9560 }
9561 }
9562 return $fields;
9563 }
9564
9565 public function get_post_custom( $post_id, $orderby = 'meta_id', $order = 'ASC' ) {
9566 global $wpdb;
9567 $table = $wpdb->prefix . 'postmeta';
9568 $meta_list = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM $table WHERE post_id = %d ORDER BY $orderby $order", $post_id ), ARRAY_A );
9569
9570 if ( ! empty( $meta_list ) ) {
9571 foreach ( $meta_list as $metarow ) {
9572 $mkey = $metarow['meta_key'];
9573 $mval = $metarow['meta_value'];
9574 $res[ $mkey ][] = $mval;
9575 }
9576 }
9577 return $res;
9578 }
9579
9580 public function get_post_user_custom( $post_id, $orderby = 'meta_id', $order = 'ASC' ) {
9581 global $wpdb;
9582 $res = array();
9583 $table = $wpdb->prefix . 'postmeta';
9584 $meta_list = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM $table WHERE post_id = %d ORDER BY $orderby $order", $post_id ), ARRAY_A );
9585
9586 if ( ! empty( $meta_list ) ) {
9587 foreach ( $meta_list as $metarow ) {
9588 if ( 0 === strpos( $metarow['meta_key'], '_' ) ) {
9589 continue;
9590 }
9591 $mkey = $metarow['meta_key'];
9592 $mval = $metarow['meta_value'];
9593 if ( array_key_exists( $mkey, $res ) ) {
9594 $cval = $res[ $mkey ];
9595 $cval = (array) $cval;
9596 $cval[] = $mval;
9597 $res[ $mkey ] = $cval;
9598 } else {
9599 $res[ $mkey ] = $mval;
9600 }
9601 }
9602 }
9603 $res = apply_filters( 'usces_filter_get_post_user_custom', $res, $meta_list, $post_id, $orderby, $order );
9604 return $res;
9605 }
9606
9607 public function get_currency( $amount, $symbol_pre = false, $symbol_post = false, $seperator_flag = true ) {
9608 global $usces_settings;
9609 $cr = $this->options['system']['currency'];
9610 list( $code, $decimal, $point, $seperator, $symbol ) = $usces_settings['currency'][ $cr ];
9611 if ( ! $seperator_flag ) {
9612 $seperator = '';
9613 }
9614 $price = number_format( (double) $amount, $decimal, $point, $seperator );
9615
9616 if ( $symbol_pre ) {
9617 $price = ( usces_is_entity( $symbol ) ? mb_convert_encoding( $symbol, 'UTF-8', 'HTML-ENTITIES' ) : $symbol ) . $price;
9618 }
9619 if ( $symbol_post ) {
9620 $price = $price . __( $code, 'usces' );
9621 }
9622 $price = apply_filters( 'usces_filter_get_currency', $price, $amount, $symbol_pre, $symbol_post, $seperator_flag );
9623 return $price;
9624 }
9625
9626 public function get_currency_code() {
9627 global $usces_settings;
9628 $cr = $this->options['system']['currency'];
9629 list( $code, $decimal, $point, $seperator, $symbol ) = $usces_settings['currency'][ $cr ];
9630 return $code;
9631 }
9632
9633 public function get_currency_decimal() {
9634 global $usces_settings;
9635 $cr = $this->options['system']['currency'];
9636 list( $code, $decimal, $point, $seperator, $symbol ) = $usces_settings['currency'][ $cr ];
9637 return $decimal;
9638 }
9639
9640 public function get_next_page_uri( $type, $current ) {
9641 global $wpdb;
9642
9643 $table = $wpdb->prefix . 'usces_' . $type;
9644 if ( ! isset( $_COOKIE[ $table ] ) ) {
9645 return false;
9646 }
9647
9648 $cookie = ( isset( $_COOKIE[ $table ] ) ) ? json_decode( str_replace( "\'", "'", str_replace( '\"', '"', $_COOKIE[ $table ] ) ), true ) : array();
9649 if ( ! isset( $cookie['currentPageIds'] ) ) {
9650 return false;
9651 }
9652
9653 $ids = $cookie['currentPageIds'];
9654 foreach ( $ids as $key => $id ) {
9655 if ( $id == $current ) {
9656 $next = isset( $ids[ ( $key + 1 ) ] ) ? $ids[ ( $key + 1 ) ] : '';
9657 break;
9658 }
9659 }
9660
9661 if ( empty( $next ) ) {
9662 $uri = '';
9663 } else {
9664 $uri = USCES_ADMIN_URL . "?page=usces_{$type}list&{$type}_action=edit&{$type}_id=" . $next;
9665 }
9666
9667 return esc_url( $uri );
9668 }
9669
9670 public function get_prev_page_uri( $type, $current ) {
9671 global $wpdb;
9672
9673 $table = $wpdb->prefix . 'usces_' . $type;
9674 if ( ! isset( $_COOKIE[ $table ] ) ) {
9675 return false;
9676 }
9677
9678 $cookie = ( isset( $_COOKIE[ $table ] ) ) ? json_decode( str_replace( "\'", "'", str_replace( '\"', '"', $_COOKIE[ $table ] ) ), true ) : array();
9679 if ( ! isset( $cookie['currentPageIds'] ) ) {
9680 return false;
9681 }
9682
9683 $ids = $cookie['currentPageIds'];
9684 foreach ( $ids as $key => $id ) {
9685 if ( $id == $current ) {
9686 $prev = isset( $ids[ ( $key - 1 ) ] ) ? $ids[ ( $key - 1 ) ] : '';
9687 break;
9688 }
9689 }
9690
9691 if ( empty( $prev ) ) {
9692 $uri = '';
9693 } else {
9694 $uri = USCES_ADMIN_URL . "?page=usces_{$type}list&{$type}_action=edit&{$type}_id=" . $prev;
9695 }
9696
9697 return esc_url( $uri );
9698 }
9699
9700 public function is_reduced_taxrate() {
9701
9702 $reduced = ( isset( $this->options['applicable_taxrate'] ) && 'reduced' == $this->options['applicable_taxrate'] ) ? true : false;
9703 return $reduced;
9704 }
9705
9706 public function sc_company_name() {
9707 return htmlspecialchars( $this->options['company_name'], ENT_COMPAT );
9708 }
9709
9710 public function sc_zip_code() {
9711 return htmlspecialchars( $this->options['zip_code'], ENT_COMPAT );
9712 }
9713
9714 public function sc_address1() {
9715 return htmlspecialchars( $this->options['address1'], ENT_COMPAT );
9716 }
9717
9718 public function sc_address2() {
9719 return htmlspecialchars( $this->options['address2'], ENT_COMPAT );
9720 }
9721
9722 public function sc_tel_number() {
9723 return htmlspecialchars( $this->options['tel_number'], ENT_COMPAT );
9724 }
9725
9726 public function sc_fax_number() {
9727 return htmlspecialchars( $this->options['fax_number'], ENT_COMPAT );
9728 }
9729
9730 public function sc_inquiry_mail() {
9731 return htmlspecialchars( $this->options['inquiry_mail'], ENT_COMPAT );
9732 }
9733
9734 public function sc_payment() {
9735 $payments = usces_get_system_option( 'usces_payment_method', 'sort' );
9736 $htm = "<ul>\n";
9737 foreach ( (array) $payments as $payment ) {
9738 $htm .= '<li>' . htmlspecialchars( $payment['name'], ENT_COMPAT ) . "<br />\n";
9739 $htm .= nl2br( htmlspecialchars( $payment['explanation'], ENT_COMPAT ) ) . "</li>\n";
9740 }
9741 $htm .= "</ul>\n";
9742 return $htm;
9743 }
9744
9745 public function sc_payment_title() {
9746 $payments = $this->options['payment_method'];
9747 $htm = "<ul>\n";
9748 foreach ( (array) $payments as $payment ) {
9749 $htm .= '<li>' . esc_html( $payment['name'] ) . "</li>\n";
9750 }
9751 $htm .= "</ul>\n";
9752 return $htm;
9753 }
9754
9755 public function sc_cod_fee() {
9756 return number_format( $this->options['cod_fee'] );
9757 }
9758
9759 public function sc_start_point() {
9760 return number_format( $this->options['start_point'] );
9761 }
9762
9763 public function sc_postage_privilege() {
9764 if ( empty( $this->options['postage_privilege'] ) ) {
9765 return;
9766 }
9767 return number_format( $this->options['postage_privilege'] );
9768 }
9769
9770 public function sc_shipping_charge() {
9771 $entry = $this->cart->get_entry();
9772 $country = ( isset( $entry['delivery']['country'] ) && ! empty( $entry['delivery']['country'] ) ) ? $entry['delivery']['country'] : $entry['customer']['country'];
9773 $arr = array();
9774 foreach ( (array) $this->options['shipping_charge'] as $charges ) {
9775 foreach ( (array) $charges[ $country ] as $value ) {
9776 $arr[] = $value;
9777 }
9778 }
9779 sort( $arr );
9780 $min = $arr[0];
9781 rsort( $arr );
9782 $max = $arr[0];
9783 if ( $min == $max ) {
9784 $res = number_format( $min );
9785 } else {
9786 $res = number_format( $min ) . __( ' - ', 'usces' ) . number_format( $max );
9787 }
9788 return $res;
9789 }
9790
9791 public function sc_site_url() {
9792 return get_option( 'home' );
9793 }
9794
9795 public function sc_button_to_cart( $atts ) {
9796 extract(
9797 shortcode_atts(
9798 array(
9799 'item' => '',
9800 'sku' => '',
9801 'value' => __( 'to the cart', 'usces' ),
9802 'force' => 0,
9803 'quant' => 0,
9804 'opt' => 1,
9805 ),
9806 $atts
9807 )
9808 );
9809
9810 $post_id = $this->get_ID_byItemName( $item );
9811 $datas = $this->get_skus( $post_id, 'code' );
9812 $zaikonum = ( isset( $datas[ $sku ]['stocknum'] ) ) ? $datas[ $sku ]['stocknum'] : null;
9813 $zaiko = ( isset( $datas[ $sku ]['stock'] ) ) ? $datas[ $sku ]['stock'] : 2;
9814 $gptekiyo = ( isset( $datas[ $sku ]['gp'] ) ) ? $datas[ $sku ]['gp'] : null;
9815 $skuPrice = ( isset( $datas[ $sku ]['price'] ) ) ? $datas[ $sku ]['price'] : 0;
9816 $sku_enc = urlencode( $sku );
9817 $options = usces_get_opts( $post_id, 'sort' );
9818 $mats = compact( 'item', 'sku', 'value', 'force', 'quant', 'post_id', 'datas', 'zaikonum', 'zaiko', 'gptekiyo', 'skuPrice', 'sku_enc' );
9819 if ( ! $this->is_item_zaiko( $post_id, $sku ) ) {
9820 return '<div class="button_status">' . esc_html( $this->zaiko_status[ $zaiko ] ) . '</div>';
9821 }
9822
9823 $html = "<form action=\"" . USCES_CART_URL . "\" method=\"post\">\n";
9824 $html .= "<input name=\"zaikonum[{$post_id}][{$sku_enc}]\" type=\"hidden\" id=\"zaikonum[{$post_id}][{$sku_enc}]\" value=\"" . esc_attr( $zaikonum ) . "\" />\n";
9825 $html .= "<input name=\"zaiko[{$post_id}][{$sku_enc}]\" type=\"hidden\" id=\"zaiko[{$post_id}][{$sku_enc}]\" value=\"" . esc_attr( $zaiko ) . "\" />\n";
9826 $html .= "<input name=\"gptekiyo[{$post_id}][{$sku_enc}]\" type=\"hidden\" id=\"gptekiyo[{$post_id}][{$sku_enc}]\" value=\"" . esc_attr( $gptekiyo ) . "\" />\n";
9827 $html .= "<input name=\"skuPrice[{$post_id}][{$sku_enc}]\" type=\"hidden\" id=\"skuPrice[{$post_id}][{$sku_enc}]\" value=\"" . esc_attr( $skuPrice ) . "\" />\n";
9828 if ( 1 == $opt ) {
9829 $html .= usces_item_option_fileds( $post_id, $sku, 1, 'return' );
9830 } elseif ( 2 == $opt ) {
9831 $html .= usces_item_option_fileds( $post_id, $sku, 0, 'return' );
9832 }
9833 if ( $quant ) {
9834 $quant_field = "<input name=\"quant[{$post_id}][" . $sku_enc . "]\" type=\"text\" id=\"quant[{$post_id}][" . $sku_enc . "]\" class=\"skuquantity\" value=\"\" onKeyDown=\"if (event.keyCode == 13) {return false;}\" />";
9835 $html .= apply_filters( 'usces_filter_sc_itemQuant', $quant_field, $mats );
9836 }
9837 $html .= "<input name=\"inCart[{$post_id}][{$sku_enc}]\" type=\"submit\" id=\"inCart[{$post_id}][{$sku_enc}]\" class=\"skubutton\" value=\"" . esc_attr( $value ) . "\" " . apply_filters( 'usces_filter_direct_intocart_button', null, $post_id, $sku, $force, $options ) . ' />';
9838 $html .= "<input name=\"usces_referer\" type=\"hidden\" value=\"" . esc_url( $_SERVER['REQUEST_URI'] ) . "\" />\n";
9839 if ( $force ) {
9840 $html .= "<input name=\"usces_force\" type=\"hidden\" value=\"incart\" />\n";
9841 }
9842 $html = apply_filters( 'usces_filter_single_item_inform', $html );
9843 $html .= '</form>';
9844 $html .= '<div class="error_message">' . usces_singleitem_error_message( $post_id, $sku, 'return' ) . '</div>' . "\n";
9845
9846 return $html;
9847 }
9848
9849 public function filter_itemPage( $content ) {
9850 global $post;
9851 $html = '';
9852
9853 if ( ( 'item' != $post->post_mime_type || ! is_single() ) ) {
9854 return $content;
9855 }
9856 if ( post_password_required( $post ) ) {
9857 return $content;
9858 }
9859
9860 $temp_path = apply_filters( 'usces_template_path_single_item', USCES_PLUGIN_DIR . '/templates/single_item.php' );
9861 include $temp_path;
9862
9863 $content = apply_filters( 'usces_filter_itemPage', $html, $post->ID );
9864
9865 return $content;
9866 }
9867
9868 public function filter_cartContent( $content ) {
9869 global $post;
9870 $html = '';
9871 switch ( $this->page ) {
9872 case 'cart':
9873 $temp_path = apply_filters( 'usces_template_path_cart', USCES_PLUGIN_DIR . '/templates/cart/cart.php' );
9874 include $temp_path;
9875 break;
9876 case 'customer':
9877 $temp_path = apply_filters( 'usces_template_path_customer', USCES_PLUGIN_DIR . '/templates/cart/customer_info.php' );
9878 include $temp_path;
9879 break;
9880 case 'delivery':
9881 $temp_path = apply_filters( 'usces_template_path_delivery', USCES_PLUGIN_DIR . '/templates/cart/delivery_info.php' );
9882 include $temp_path;
9883 break;
9884 case 'confirm':
9885 $temp_path = apply_filters( 'usces_template_path_confirm', USCES_PLUGIN_DIR . '/templates/cart/confirm.php' );
9886 include $temp_path;
9887 break;
9888 case 'ordercompletion':
9889 $temp_path = apply_filters( 'usces_template_path_ordercompletion', USCES_PLUGIN_DIR . '/templates/cart/completion.php' );
9890 include $temp_path;
9891 break;
9892 case 'cartverifying':
9893 $temp_path = apply_filters( 'usces_template_path_cartverifying', USCES_PLUGIN_DIR . '/templates/cart/verifying.php' );
9894 include $temp_path;
9895 break;
9896 case 'cartverified':
9897 $temp_path = apply_filters( 'usces_template_path_cartverified', USCES_PLUGIN_DIR . '/templates/cart/verified.php' );
9898 include $temp_path;
9899 break;
9900 case 'error':
9901 $temp_path = apply_filters( 'usces_template_path_carterror', USCES_PLUGIN_DIR . '/templates/cart/error.php' );
9902 include $temp_path;
9903 break;
9904 case 'maintenance':
9905 $temp_path = apply_filters( 'usces_template_path_maintenance', USCES_PLUGIN_DIR . '/templates/cart/maintenance.php' );
9906 include $temp_path;
9907 break;
9908 case 'search_item':
9909 $temp_path = apply_filters( 'usces_template_path_search_item', USCES_PLUGIN_DIR . '/templates/search_item.php' );
9910 include $temp_path;
9911 break;
9912 case 'wp_search':
9913 if ( 'item' == $post->post_mime_type ) {
9914 $temp_path = apply_filters( 'usces_template_path_wp_search', USCES_PLUGIN_DIR . '/templates/wp_search_item.php' );
9915 include $temp_path;
9916 } else {
9917 $html = $content;
9918 }
9919 break;
9920 default:
9921 $html = $content;
9922 }
9923
9924 if ( $this->use_ssl && ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) ) {
9925 $html = str_replace( 'src="' . site_url(), 'src="' . USCES_SSL_URL_ADMIN, $html );
9926 }
9927
9928 $html = apply_filters( 'usces_filter_cartContent', $html );
9929
9930 $content = $html;
9931
9932 remove_filter( 'the_title', array( $this, 'filter_cartTitle' ) );
9933
9934 return $content;
9935 }
9936
9937 public function filter_cartTitle( $title ) {
9938 if ( is_admin() ) {
9939 return $title;
9940 }
9941
9942 if ( 'Cart' == $title || __( 'Cart', 'usces' ) == $title ) {
9943 switch ( $this->page ) {
9944 case 'cart':
9945 $newtitle = apply_filters( 'usces_filter_title_cart', __( 'In the cart', 'usces' ) );
9946 break;
9947 case 'customer':
9948 $newtitle = apply_filters( 'usces_filter_title_customer', __( 'Customer Information', 'usces' ) );
9949 break;
9950 case 'delivery':
9951 $newtitle = apply_filters( 'usces_filter_title_delivery', __( 'Shipping / Payment options', 'usces' ) );
9952 break;
9953 case 'confirm':
9954 $newtitle = apply_filters( 'usces_filter_title_confirm', __( 'Confirmation', 'usces' ) );
9955 break;
9956 case 'ordercompletion':
9957 $newtitle = apply_filters( 'usces_filter_title_ordercompletion', __( 'Completion', 'usces' ) );
9958 break;
9959 case 'error':
9960 $newtitle = apply_filters( 'usces_filter_title_carterror', __( 'Error', 'usces' ) );
9961 break;
9962 case 'cartverified':
9963 $newtitle = apply_filters( 'usces_filter_title_cartverified', __( 'Member registration complete', 'usces' ) );
9964 break;
9965 case 'search_item':
9966 $newtitle = apply_filters( 'usces_filter_title_search_item', __( "'AND' search by categories", 'usces' ) );
9967 break;
9968 case 'maintenance':
9969 $newtitle = apply_filters( 'usces_filter_title_maintenance', __( 'Under Maintenance', 'usces' ) );
9970 break;
9971 case 'login':
9972 $newtitle = apply_filters( 'usces_filter_title_login', __( 'Log-in for members', 'usces' ) );
9973 break;
9974 default:
9975 $newtitle = apply_filters( 'usces_filter_title_cart_default', $title );
9976 }
9977 } else {
9978 $newtitle = $title;
9979 }
9980
9981 $newtitle = apply_filters( 'usces_filter_cartTitle', $newtitle );
9982 return $newtitle;
9983 }
9984
9985 public function action_cartFilter() {
9986 add_filter( 'the_title', array( $this, 'filter_cartTitle' ), 20 );
9987 add_filter( 'the_content', array( $this, 'filter_cartContent' ), 20 );
9988 }
9989
9990 public function action_search_item() {
9991 include get_template_directory() . '/page.php';
9992 exit;
9993 }
9994
9995 public function filter_memberContent( $content ) {
9996 global $post;
9997 $html = '';
9998
9999 if ( 'activate' == $this->options['membersystem_state'] ) {
10000
10001 if ( $this->is_member_logged_in() ) {
10002
10003 $member_regmode = 'editmemberform';
10004 $temp_path = apply_filters( 'usces_template_path_member', USCES_PLUGIN_DIR . '/templates/member/member.php' );
10005 include $temp_path;
10006
10007 } else {
10008
10009 switch ( $this->page ) {
10010 case 'login':
10011 $temp_path = apply_filters( 'usces_template_path_login', USCES_PLUGIN_DIR . '/templates/member/login.php' );
10012 include $temp_path;
10013 break;
10014 case 'lostmemberpassword':
10015 $temp_path = apply_filters( 'usces_template_path_lostpassword', USCES_PLUGIN_DIR . '/templates/member/lostpassword.php' );
10016 include $temp_path;
10017 break;
10018 case 'changepassword':
10019 $temp_path = apply_filters( 'usces_template_path_changepassword', USCES_PLUGIN_DIR . '/templates/member/changepassword.php' );
10020 include $temp_path;
10021 break;
10022 case 'newcompletion':
10023 case 'editcompletion':
10024 case 'lostcompletion':
10025 case 'changepasscompletion':
10026 $temp_path = apply_filters( 'usces_template_path_membercompletion', USCES_PLUGIN_DIR . '/templates/member/completion.php' );
10027 include $temp_path;
10028 break;
10029 case 'memberverifying':
10030 $temp_path = apply_filters( 'usces_template_path_memberverifying', USCES_PLUGIN_DIR . '/templates/member/verifying.php' );
10031 include $temp_path;
10032 break;
10033 // case 'memberverified':
10034 // $temp_path = apply_filters('usces_template_path_memberverified', USCES_PLUGIN_DIR . '/templates/member/member_verified.php');
10035 // include $temp_path;
10036 // break;
10037 case 'newmemberform':
10038 $member_form_title = apply_filters( 'usces_filter_title_newmemberform', __( 'New enrollment form', 'usces' ) );
10039 $member_regmode = 'newmemberform';
10040 $temp_path = apply_filters( 'usces_template_path_member_form', USCES_PLUGIN_DIR . '/templates/member/member_form.php' );
10041 include $temp_path;
10042 break;
10043 default:
10044 $temp_path = apply_filters( 'usces_template_path_login', USCES_PLUGIN_DIR . '/templates/member/login.php' );
10045 include $temp_path;
10046 }
10047 }
10048 } else {
10049 $html .= '<p>' . __( 'Member Services is not running currently.', 'usces' ) . '</p>';
10050 }
10051
10052 $content = $html;
10053
10054 remove_filter( 'the_title', array( $this, 'filter_memberTitle' ), 20 );
10055
10056 return $content;
10057 }
10058
10059 public function filter_memberTitle( $title ) {
10060 if ( is_admin() ) {
10061 return $title;
10062 }
10063
10064 if ( 'activate' == $this->options['membersystem_state'] && $this->is_member_page( $_SERVER['REQUEST_URI'] ) ) {
10065 switch ( $this->page ) {
10066 case 'login':
10067 $newtitle = apply_filters( 'usces_filter_title_login', __( 'Log-in for members', 'usces' ) );
10068 break;
10069 case 'newmemberform':
10070 $newtitle = apply_filters( 'usces_filter_title_newmemberform', __( 'New enrollment form', 'usces' ) );
10071 break;
10072 case 'lostmemberpassword':
10073 $newtitle = apply_filters( 'usces_filter_title_lostmemberpassword', __( 'The new password acquisition', 'usces' ) );
10074 break;
10075 case 'changepassword':
10076 $newtitle = apply_filters( 'usces_filter_title_changepassword', __( 'Change password', 'usces' ) );
10077 break;
10078 case 'newcompletion':
10079 case 'editcompletion':
10080 case 'lostcompletion':
10081 case 'changepasscompletion':
10082 $newtitle = apply_filters( 'usces_filter_title_changepasscompletion', __( 'Completion', 'usces' ) );
10083 break;
10084 case 'memberverifying':
10085 $newtitle = apply_filters( 'usces_filter_title_memberverifying', __( 'Verifying', 'usces' ) );
10086 break;
10087 case 'error':
10088 $newtitle = apply_filters( 'usces_filter_title_membererror', __( 'Error', 'usces' ) );
10089 break;
10090 default:
10091 $newtitle = apply_filters( 'usces_filter_title_member_default', $title );
10092 }
10093 } else {
10094 $newtitle = $title;
10095 }
10096
10097 $newtitle = apply_filters( 'usces_filter_memberTitle', $newtitle );
10098 return $newtitle;
10099 }
10100
10101 public function action_memberFilter() {
10102 add_filter( 'the_title', array( $this, 'filter_memberTitle' ), 20 );
10103 add_filter( 'the_content', array( $this, 'filter_memberContent' ), 20 );
10104 }
10105
10106 public function filter_usces_cart_css() {
10107 $path = get_stylesheet_directory_uri() . '/usces_cart.css';
10108 return $path;
10109 }
10110
10111 public function filter_divide_item() {
10112 global $wp_query;
10113
10114 if ( ( $this->options['divide_item'] && ! is_category() && ! is_search() && ! is_singular() && ! is_admin() ) ) {
10115 $ids = $this->getItemIds( 'front' );
10116 if ( isset( $wp_query->query_vars['post__not_in'] ) ) {
10117 $wp_query->query_vars['post__not_in'] = $ids;
10118 }
10119 }
10120 if ( is_admin() ) {
10121 $ids = $this->getItemIds( 'back' );
10122 if ( isset( $wp_query->query_vars['post__not_in'] ) ) {
10123 $wp_query->query_vars['post__not_in'] = $ids;
10124 }
10125 }
10126 do_action( 'usces_action_divide_item' );
10127 }
10128
10129 public function load_upload_template() {
10130 $post_id = $_POST['post_id'];
10131 $file = 'upload_template01.php';
10132 include get_template_directory() . '/' . $file;
10133 exit;
10134 }
10135
10136 public function filter_itemimg_anchor_rel( $html ) {
10137 if ( is_single() ) {
10138 $str = ' rel="' . $this->options['itemimg_anchor_rel'] . '"';
10139 } else {
10140 $str = '';
10141 }
10142 return $html . $str;
10143 }
10144
10145 public function filter_permalink( $link ) {
10146 if ( false !== strpos( '?page_id=4', $link ) || false !== strpos( '?page_id=3', $link ) || false !== strpos( 'usces-cart', $link ) || false !== strpos( 'usces-member', $link ) ) {
10147 $link = str_replace( 'http://', 'https://', $link );
10148 }
10149 return $link;
10150 }
10151
10152 public function filter_cart_page_header( $html ) {
10153 if ( ! empty( $this->options['cart_page_data']['header']['cart'] ) ) {
10154 $html = $this->options['cart_page_data']['header']['cart'];
10155 }
10156 return do_shortcode( stripslashes( nl2br( $html ) ) );
10157 }
10158
10159 public function filter_cart_page_footer( $html ) {
10160 if ( ! empty( $this->options['cart_page_data']['footer']['cart'] ) ) {
10161 $html = $this->options['cart_page_data']['footer']['cart'];
10162 }
10163 return do_shortcode( stripslashes( nl2br( $html ) ) );
10164 }
10165
10166 public function filter_customer_page_header( $html ) {
10167 if ( ! empty( $this->options['cart_page_data']['header']['customer'] ) ) {
10168 $html = $this->options['cart_page_data']['header']['customer'];
10169 }
10170 return do_shortcode( stripslashes( nl2br( $html ) ) );
10171 }
10172
10173 public function filter_customer_page_footer( $html ) {
10174 if ( ! empty( $this->options['cart_page_data']['footer']['customer'] ) ) {
10175 $html = $this->options['cart_page_data']['footer']['customer'];
10176 }
10177 return do_shortcode( stripslashes( nl2br( $html ) ) );
10178 }
10179
10180 public function filter_delivery_page_header( $html ) {
10181 if ( ! empty( $this->options['cart_page_data']['header']['delivery'] ) ) {
10182 $html = $this->options['cart_page_data']['header']['delivery'];
10183 }
10184 return do_shortcode( stripslashes( nl2br( $html ) ) );
10185 }
10186
10187 public function filter_delivery_page_footer( $html ) {
10188 if ( ! empty( $this->options['cart_page_data']['footer']['delivery'] ) ) {
10189 $html = $this->options['cart_page_data']['footer']['delivery'];
10190 }
10191 return do_shortcode( stripslashes( nl2br( $html ) ) );
10192 }
10193
10194 public function filter_confirm_page_header( $html ) {
10195 if ( ! empty( $this->options['cart_page_data']['header']['confirm'] ) ) {
10196 $html = $this->options['cart_page_data']['header']['confirm'];
10197 }
10198 return do_shortcode( stripslashes( nl2br( $html ) ) );
10199 }
10200
10201 public function filter_confirm_page_footer( $html ) {
10202 if ( ! empty( $this->options['cart_page_data']['footer']['confirm'] ) ) {
10203 $html = $this->options['cart_page_data']['footer']['confirm'];
10204 }
10205 return do_shortcode( stripslashes( nl2br( $html ) ) );
10206 }
10207
10208 public function filter_cartcompletion_page_header( $html ) {
10209 if ( ! empty( $this->options['cart_page_data']['header']['completion'] ) ) {
10210 $html = $this->options['cart_page_data']['header']['completion'];
10211 }
10212 return do_shortcode( stripslashes( nl2br( $html ) ) );
10213 }
10214
10215 public function filter_cartcompletion_page_footer( $html ) {
10216 if ( ! empty( $this->options['cart_page_data']['footer']['completion'] ) ) {
10217 $html = $this->options['cart_page_data']['footer']['completion'];
10218 }
10219 return do_shortcode( stripslashes( nl2br( $html ) ) );
10220 }
10221
10222 public function filter_login_page_header( $html ) {
10223 if ( ! empty( $this->options['member_page_data']['header']['login'] ) ) {
10224 $html = $this->options['member_page_data']['header']['login'];
10225 }
10226 return do_shortcode( stripslashes( nl2br( $html ) ) );
10227 }
10228
10229 public function filter_login_page_footer( $html ) {
10230 if ( ! empty( $this->options['member_page_data']['footer']['login'] ) ) {
10231 $html = $this->options['member_page_data']['footer']['login'];
10232 }
10233 return do_shortcode( stripslashes( nl2br( $html ) ) );
10234 }
10235
10236 public function filter_newmember_page_header( $html ) {
10237 if ( ! empty( $this->options['member_page_data']['header']['newmember'] ) ) {
10238 $html = $this->options['member_page_data']['header']['newmember'];
10239 }
10240 return do_shortcode( stripslashes( nl2br( $html ) ) );
10241 }
10242
10243 public function filter_newmember_page_footer( $html ) {
10244 if ( ! empty( $this->options['member_page_data']['footer']['newmember'] ) ) {
10245 $html = $this->options['member_page_data']['footer']['newmember'];
10246 }
10247 return do_shortcode( stripslashes( nl2br( $html ) ) );
10248 }
10249
10250 public function filter_newpass_page_header( $html ) {
10251 if ( ! empty( $this->options['member_page_data']['header']['newpass'] ) ) {
10252 $html = $this->options['member_page_data']['header']['newpass'];
10253 }
10254 return do_shortcode( stripslashes( nl2br( $html ) ) );
10255 }
10256
10257 public function filter_newpass_page_footer( $html ) {
10258 if ( ! empty( $this->options['member_page_data']['footer']['newpass'] ) ) {
10259 $html = $this->options['member_page_data']['footer']['newpass'];
10260 }
10261 return do_shortcode( stripslashes( nl2br( $html ) ) );
10262 }
10263
10264 public function filter_changepass_page_header( $html ) {
10265 if ( ! empty( $this->options['member_page_data']['header']['changepass'] ) ) {
10266 $html = $this->options['member_page_data']['header']['changepass'];
10267 }
10268 return do_shortcode( stripslashes( nl2br( $html ) ) );
10269 }
10270
10271 public function filter_changepass_page_footer( $html ) {
10272 if ( ! empty( $this->options['member_page_data']['footer']['changepass'] ) ) {
10273 $html = $this->options['member_page_data']['footer']['changepass'];
10274 }
10275 return do_shortcode( stripslashes( nl2br( $html ) ) );
10276 }
10277
10278 public function filter_memberinfo_page_header( $html ) {
10279 if ( ! empty( $this->options['member_page_data']['header']['memberinfo'] ) ) {
10280 $html = $this->options['member_page_data']['header']['memberinfo'];
10281 }
10282 return do_shortcode( stripslashes( nl2br( $html ) ) );
10283 }
10284
10285 public function filter_memberinfo_page_footer( $html ) {
10286 if ( ! empty( $this->options['member_page_data']['footer']['memberinfo'] ) ) {
10287 $html = $this->options['member_page_data']['footer']['memberinfo'];
10288 }
10289 return do_shortcode( stripslashes( nl2br( $html ) ) );
10290 }
10291
10292 public function filter_membercompletion_page_header( $html ) {
10293 if ( ! empty( $this->options['member_page_data']['header']['completion'] ) ) {
10294 $html = $this->options['member_page_data']['header']['completion'];
10295 }
10296 return do_shortcode( stripslashes( nl2br( $html ) ) );
10297 }
10298
10299 public function filter_membercompletion_page_footer( $html ) {
10300 if ( ! empty( $this->options['member_page_data']['footer']['completion'] ) ) {
10301 $html = $this->options['member_page_data']['footer']['completion'];
10302 }
10303 return do_shortcode( stripslashes( nl2br( $html ) ) );
10304 }
10305
10306 public function action_cart_page_header() {
10307 if ( ! empty( $this->options['cart_page_data']['header']['cart'] ) ) {
10308 $html = $this->options['cart_page_data']['header']['cart'];
10309 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10310 }
10311 }
10312
10313 public function action_cart_page_footer() {
10314 if ( ! empty( $this->options['cart_page_data']['footer']['cart'] ) ) {
10315 $html = $this->options['cart_page_data']['footer']['cart'];
10316 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10317 }
10318 }
10319
10320 public function action_customer_page_header() {
10321 if ( ! empty( $this->options['cart_page_data']['header']['customer'] ) ) {
10322 $html = $this->options['cart_page_data']['header']['customer'];
10323 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10324 }
10325 }
10326
10327 public function action_customer_page_footer() {
10328 if ( ! empty( $this->options['cart_page_data']['footer']['customer'] ) ) {
10329 $html = $this->options['cart_page_data']['footer']['customer'];
10330 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10331 }
10332 }
10333
10334 public function action_delivery_page_header() {
10335 if ( ! empty( $this->options['cart_page_data']['header']['delivery'] ) ) {
10336 $html = $this->options['cart_page_data']['header']['delivery'];
10337 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10338 }
10339 }
10340
10341 public function action_delivery_page_footer() {
10342 if ( ! empty( $this->options['cart_page_data']['footer']['delivery'] ) ) {
10343 $html = $this->options['cart_page_data']['footer']['delivery'];
10344 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10345 }
10346 }
10347
10348 public function action_confirm_page_header() {
10349 if ( ! empty( $this->options['cart_page_data']['header']['confirm'] ) ) {
10350 $html = $this->options['cart_page_data']['header']['confirm'];
10351 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10352 }
10353 }
10354
10355 public function action_confirm_page_footer() {
10356 if ( ! empty( $this->options['cart_page_data']['footer']['confirm'] ) ) {
10357 $html = $this->options['cart_page_data']['footer']['confirm'];
10358 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10359 }
10360 }
10361
10362 public function action_cartcompletion_page_header() {
10363 if ( ! empty( $this->options['cart_page_data']['header']['completion'] ) ) {
10364 $html = $this->options['cart_page_data']['header']['completion'];
10365 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10366 }
10367 }
10368
10369 public function action_cartcompletion_page_footer() {
10370 if ( ! empty( $this->options['cart_page_data']['footer']['completion'] ) ) {
10371 $html = $this->options['cart_page_data']['footer']['completion'];
10372 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10373 }
10374 }
10375
10376 public function action_login_page_header() {
10377 if ( ! empty( $this->options['member_page_data']['header']['login'] ) ) {
10378 $html = $this->options['member_page_data']['header']['login'];
10379 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10380 }
10381 }
10382
10383 public function action_login_page_footer() {
10384 if ( ! empty( $this->options['member_page_data']['footer']['login'] ) ) {
10385 $html = $this->options['member_page_data']['footer']['login'];
10386 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10387 }
10388 }
10389
10390 public function action_newmember_page_header() {
10391 if ( ! empty( $this->options['member_page_data']['header']['newmember'] ) ) {
10392 $html = $this->options['member_page_data']['header']['newmember'];
10393 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10394 }
10395 }
10396
10397 public function action_newmember_page_footer() {
10398 if ( ! empty( $this->options['member_page_data']['footer']['newmember'] ) ) {
10399 $html = $this->options['member_page_data']['footer']['newmember'];
10400 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10401 }
10402 }
10403
10404 public function action_newpass_page_header() {
10405 if ( ! empty( $this->options['member_page_data']['header']['newpass'] ) ) {
10406 $html = $this->options['member_page_data']['header']['newpass'];
10407 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10408 }
10409 }
10410
10411 public function action_newpass_page_footer() {
10412 if ( ! empty( $this->options['member_page_data']['footer']['newpass'] ) ) {
10413 $html = $this->options['member_page_data']['footer']['newpass'];
10414 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10415 }
10416 }
10417
10418 public function action_changepass_page_header() {
10419 if ( ! empty( $this->options['member_page_data']['header']['changepass'] ) ) {
10420 $html = $this->options['member_page_data']['header']['changepass'];
10421 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10422 }
10423 }
10424
10425 public function action_changepass_page_footer() {
10426 if ( ! empty( $this->options['member_page_data']['footer']['changepass'] ) ) {
10427 $html = $this->options['member_page_data']['footer']['changepass'];
10428 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10429 }
10430 }
10431
10432 public function action_memberinfo_page_header() {
10433 if ( ! empty( $this->options['member_page_data']['header']['memberinfo'] ) ) {
10434 $html = $this->options['member_page_data']['header']['memberinfo'];
10435 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10436 }
10437 }
10438
10439 public function action_memberinfo_page_footer() {
10440 if ( ! empty( $this->options['member_page_data']['footer']['memberinfo'] ) ) {
10441 $html = $this->options['member_page_data']['footer']['memberinfo'];
10442 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10443 }
10444 }
10445
10446 public function action_membercompletion_page_header() {
10447 if ( ! empty( $this->options['member_page_data']['header']['completion'] ) ) {
10448 $html = $this->options['member_page_data']['header']['completion'];
10449 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10450 }
10451 }
10452
10453 public function action_membercompletion_page_footer() {
10454 if ( ! empty( $this->options['member_page_data']['footer']['completion'] ) ) {
10455 $html = $this->options['member_page_data']['footer']['completion'];
10456 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10457 }
10458 }
10459
10460 public function filter_confirm_page_notes( $html ) {
10461 if ( ! empty( $this->options['cart_page_data']['confirm_notes'] ) ) {
10462 $html = '<div class="wc_confirm_notes_area">' . $this->options['cart_page_data']['confirm_notes'] . '</div>';
10463 }
10464 return stripslashes( nl2br( $html ) );
10465 }
10466
10467 public function action_confirm_page_notes() {
10468 if ( ! empty( $this->options['cart_page_data']['confirm_notes'] ) ) {
10469 $html = '<div class="wc_confirm_notes_area">' . $this->options['cart_page_data']['confirm_notes'] . '</div>';
10470 echo stripslashes( nl2br( $html ) );
10471 }
10472 }
10473
10474 /**
10475 * Get member cookies.
10476 *
10477 * @param string $key string cookies key.
10478 *
10479 * @return string
10480 */
10481 public function usces_get_member_cookies( $key ) {
10482 $result = '';
10483 switch ( $key ) {
10484 case 'ord_ex_cancel':
10485 $ex_cancel = filter_input( INPUT_GET, 'ord_ex_cancel' );
10486 if ( $ex_cancel ) {
10487 $result = ( 'on' === $ex_cancel ) ? 'on' : 'off';
10488 } else {
10489 $cookie = $this->get_cookie( 'usces_front' );
10490 $result = isset( $cookie['ord_ex_cancel'] ) ? $cookie['ord_ex_cancel'] : 'on';
10491 $result = apply_filters( 'usces_filter_ord_ex_cancel_init', $result );
10492 }
10493 break;
10494 case 'pur-date':
10495 $result = filter_input( INPUT_GET, 'pur-date' );
10496 if ( null === $result ) {
10497 $cookie = $this->get_cookie( 'usces_front' );
10498 $result = isset( $cookie['usces_purdate'] ) ? $cookie['usces_purdate'] : 'd_30';
10499 $result = apply_filters( 'usces_filter_ord_purdate_init', $result );
10500 }
10501 break;
10502 }
10503 return $result;
10504 }
10505
10506 }
10507