PluginProbe
Welcart e-Commerce / 2.11.33
Welcart e-Commerce v2.11.33
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.11.33, at classes/usceshop.class.php

10,526 lines 409.0 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 if ( isset( $_GET['uscesid'] ) && ! WCUtils::is_blank( $_GET['uscesid'] ) ) {
2026 $sessid = $_GET['uscesid'];
2027 $sessid = $this->uscesdc( $sessid );
2028 session_id( $sessid );
2029 }
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 $actionflag = false;
2075 $sess = null;
2076 $addr = null;
2077 $rckid = null;
2078 $none = null;
2079 $cookie = $this->get_cookie();
2080
2081 if ( isset( $_GET['uscesid'] ) && ! WCUtils::is_blank( $_GET['uscesid'] ) ) {
2082 $sessid = base64_decode( urldecode( $_GET['uscesid'] ) );
2083 list( $sess, $addr, $rckid, $none ) = explode( '_', $sessid, 4 );
2084 }
2085 if ( 'acting' == $addr ) {
2086 return;
2087 }
2088 if ( apply_filters( 'usces_filter_cookie', false ) ) {
2089 return;
2090 }
2091
2092 // We need to consider.
2093 return;
2094
2095 if ( $this->use_ssl && ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) ) {
2096
2097 $refer = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : null;
2098 $sslid = isset( $cookie['sslid'] ) ? $cookie['sslid'] : null;
2099 $option = get_option( 'usces' );
2100 $parsed = parse_url( get_option( 'home' ) );
2101 $home = $parsed['host'] . ( isset( $parsed['path'] ) ? $parsed['path'] : '' );
2102 $parsed = parse_url( $option['ssl_url'] );
2103 $sslhome = $parsed['host'] . ( isset( $parsed['path'] ) ? $parsed['path'] : '' );
2104
2105 if ( empty( $refer ) || ( false === strpos( $refer, $home ) && false === strpos( $refer, $sslhome ) ) ) {
2106 if ( ! empty( $sslid ) && ! empty( $rckid ) && $sslid === $rckid ) {
2107 $actionflag = true;
2108 } else {
2109 $actionflag = false;
2110 }
2111 } else {
2112 if ( ! empty( $sslid ) && $sslid !== $rckid ) {
2113 $actionflag = false;
2114 } else {
2115 $actionflag = true;
2116 }
2117 }
2118
2119 if ( $actionflag ) {
2120 $values = array(
2121 'id' => $rckid,
2122 'sslid' => $rckid,
2123 'name' => '',
2124 'rme' => '',
2125 );
2126 if ( 'acting' !== $rckid ) {
2127 $this->set_cookie( $values );
2128 }
2129 } else {
2130 if ( 'acting' !== $rckid ) {
2131 unset( $_SESSION['usces_member'], $_SESSION['usces_cart'], $_SESSION['usces_entry'] );
2132 wp_redirect( 'http://' . $home );
2133 }
2134 }
2135 } else {
2136 if ( ! isset( $cookie['id'] ) || WCUtils::is_blank( $cookie['id'] ) ) {
2137 $values = array(
2138 'id' => md5( uniqid( rand(), true ) ),
2139 'name' => '',
2140 'rme' => '',
2141 );
2142 $this->set_cookie( $values );
2143 $_SESSION['usces_cookieid'] = $values['id'];
2144 } else {
2145 if ( ! isset( $_SESSION['usces_cookieid'] ) || $_SESSION['usces_cookieid'] != $cookie['id'] ) {
2146 $_SESSION['usces_cookieid'] = $cookie['id'];
2147 }
2148 }
2149
2150 $actionflag = true;
2151 }
2152 }
2153
2154 public function set_cookie( $values, $key = 'usces_cookie' ) {
2155 if ( ! isset( $_GET['uscesid'] ) || WCUtils::is_blank( $_GET['uscesid'] ) ) {
2156 session_regenerate_id( true );
2157 }
2158 $value = usces_serialize( $values );
2159 $timeout = time()+7*86400;
2160 $timeout = apply_filters( 'usces_filter_set_cookie_timeout', $timeout, $values, $key );
2161 $domain = $_SERVER['SERVER_NAME'];
2162
2163 $httponly = true;
2164 $sitescheme = substr( get_option( 'siteurl' ), 0, 5 );
2165 $homescheme = substr( get_option( 'home' ), 0, 5 );
2166 if ( 'https' == $sitescheme && 'https' == $homescheme ) {
2167 $sslonly = true;
2168 $samesite = 'None';
2169 } else {
2170 $sslonly = false;
2171 $samesite = '';
2172 }
2173
2174 if ( version_compare( PHP_VERSION, '7.3.0', '>=' ) ) {
2175 $cookie_options = array(
2176 'expires' => $timeout,
2177 'path' => USCES_COOKIEPATH,
2178 'domain' => $domain,
2179 'secure' => $sslonly,
2180 'httponly' => $httponly,
2181 'samesite' => $samesite,
2182 );
2183 $res = setcookie( $key, $value, $cookie_options );
2184 } else {
2185 $res = setcookie( $key, $value, $timeout, USCES_COOKIEPATH, $domain, true, true );
2186 }
2187 }
2188
2189 public function get_cookie( $key = 'usces_cookie' ) {
2190 $values = isset( $_COOKIE[ $key ] ) ? usces_unserialize( stripslashes( $_COOKIE[ $key ] ) ) : null;
2191 return $values;
2192 }
2193
2194 public function get_access( $key, $type, $date ) {
2195 global $wpdb;
2196 $table_name = $wpdb->prefix . 'usces_access';
2197
2198 $query = $wpdb->prepare( "SELECT acc_value FROM $table_name WHERE acc_key = %s AND acc_type = %s AND acc_date = %s", $key, $type, $date );
2199 $value = $wpdb->get_var( $query );
2200 if ( ! $value ) {
2201 $res = null;
2202 } else {
2203 $res = @unserialize( $value );
2204 }
2205
2206 return $res;
2207 }
2208
2209 public function get_access_piriod( $key, $type, $startday, $endday ) {
2210 global $wpdb;
2211 $table_name = $wpdb->prefix . 'usces_access';
2212 $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 );
2213 $res = $wpdb->get_results( $query, ARRAY_A );
2214
2215 return $res;
2216 }
2217
2218 public function update_access( $array ) {
2219 global $wpdb;
2220 $table_name = $wpdb->prefix . 'usces_access';
2221
2222 $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'] );
2223 $res = $wpdb->get_var( $query );
2224 if ( empty( $res ) ) {
2225 $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'] );
2226 $wpdb->query( $query );
2227 } else {
2228 $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'] );
2229 $wpdb->query( $query );
2230 }
2231 }
2232
2233 public function get_uscesid( $flag = true ) {
2234 $sessname = session_name();
2235 $sessid = session_id();
2236 $sessid = $this->uscescv( $sessid, $flag );
2237 return $sessid;
2238 }
2239
2240 public function shop_head() {
2241 global $post;
2242 $this->item = $post;
2243 if ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) ) {
2244 echo "<meta name='robots' content='noindex,nofollow' />\n";
2245 }
2246 }
2247
2248 /**
2249 * Caught by wp_footer action hook
2250 */
2251 public function shop_foot() {
2252 global $current_user;
2253
2254 $item = $this->item;
2255 if ( empty( $item ) ) {
2256 $item = new stdClass;
2257 $item->ID = 0;
2258 $item->post_mime_type = '';
2259 }
2260
2261 wp_get_current_user();
2262
2263 // usces_cart.js is not used.
2264 if ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
2265 $javascript_url = USCES_FRONT_PLUGIN_URL . '/js/usces_cart.js';
2266 } else {
2267 $javascript_url = USCES_WP_CONTENT_URL . '/plugins/' . USCES_PLUGIN_FOLDER . '/js/usces_cart.js';
2268 }
2269
2270 $this->previous_url = isset( $_SESSION['usces_previous_url'] ) ? $_SESSION['usces_previous_url'] : get_home_url();
2271
2272 // If the product object does't exists.
2273 if ( $this->use_js && empty( $this->item ) ) {
2274 ?>
2275 <script type='text/javascript'>
2276 uscesL10n = {
2277 <?php echo apply_filters( 'usces_filter_uscesL10n', null, $item->ID ); ?>
2278
2279 'ajaxurl': "<?php echo esc_url( $this->ssl_admin_ajax_url() ); ?>"
2280 }
2281 </script>
2282 <?php
2283
2284 // If the product object exists.
2285 } elseif ( $this->use_js && ! empty( $this->item ) ) {
2286
2287 $ioptkeys = $this->get_itemOptionKey( $item->ID );
2288 $mes_opts_str = '';
2289 $key_opts_str = '';
2290 $opt_means = '';
2291 $opt_esse = '';
2292 if ( $ioptkeys ) {
2293 foreach ( $ioptkeys as $key => $value ) {
2294 $optValues = $this->get_itemOptions( $value, $item->ID );
2295 if ( false === $optValues ) {
2296 continue;
2297 }
2298 if ( $optValues['means'] < 2 || 3 == $optValues['means'] || 4 == $optValues['means'] ) {
2299 $mes_opts_str .= "'" . sprintf( __( 'Chose the %s', 'usces' ), esc_js( apply_filters( 'usces_filter_uscesL10n_option_name', $value, $optValues ) ) ) . "',";
2300 } else {
2301 $mes_opts_str .= "'" . sprintf( __( 'Input the %s', 'usces' ), esc_js( apply_filters( 'usces_filter_uscesL10n_option_name', $value, $optValues ) ) ) . "',";
2302 }
2303 $key_opts_str .= "'" . urlencode( esc_js( $value ) ) . "',";
2304 $opt_means .= "'" . esc_js( $optValues['means'] ) . "',";
2305 $opt_esse .= "'" . esc_js( $optValues['essential'] ) . "',";
2306 }
2307 $mes_opts_str = rtrim( $mes_opts_str, ',' );
2308 $key_opts_str = rtrim( $key_opts_str, ',' );
2309 $opt_means = rtrim( $opt_means, ',' );
2310 $opt_esse = rtrim( $opt_esse, ',' );
2311 }
2312
2313 $product = wel_get_product( $item->ID );
2314 $itemRestriction = isset( $product['itemRestriction'] ) ? $product['itemRestriction'] : '';
2315 $wcpage = usces_page_name( 'return' );
2316 $nonce_action = 'wc_confirm';
2317 $itemOrderAcceptable = $this->getItemOrderAcceptable( $item->ID );
2318 ?>
2319 <script type='text/javascript'>
2320 uscesL10n = {
2321 <?php echo apply_filters( 'usces_filter_uscesL10n', null, $item->ID ); ?>
2322
2323 'ajaxurl': "<?php echo esc_url( $this->ssl_admin_ajax_url() ); ?>",
2324 'loaderurl': "<?php echo USCES_PLUGIN_URL . 'images/loading.gif'; ?>",
2325 'post_id': "<?php echo esc_js( $item->ID ); ?>",
2326 'cart_number': "<?php echo get_option( 'usces_cart_number' ); ?>",
2327 'is_cart_row': <?php echo ( ( 0 < $this->cart->num_row() ) ? 'true' : 'false' ); ?>,
2328 'opt_esse': new Array( <?php wel_esc_script_e( $opt_esse ); ?> ),
2329 'opt_means': new Array( <?php wel_esc_script_e( $opt_means ); ?> ),
2330 'mes_opts': new Array( <?php wel_esc_script_e( $mes_opts_str ); ?> ),
2331 'key_opts': new Array( <?php wel_esc_script_e( $key_opts_str ); ?> ),
2332 'previous_url': "<?php echo esc_url( $this->previous_url ); ?>",
2333 'itemRestriction': "<?php echo esc_js( $itemRestriction ); ?>",
2334 'itemOrderAcceptable': "<?php echo esc_js( $itemOrderAcceptable ); ?>",
2335 'uscespage': "<?php echo esc_js( $wcpage ); ?>",
2336 'uscesid': "<?php echo esc_js( $this->get_uscesid( false ) ); ?>",
2337 'wc_nonce': "<?php echo wp_create_nonce( $nonce_action ); ?>"
2338 }
2339 </script>
2340 <script type='text/javascript' src='<?php echo esc_url( $javascript_url ); ?>'></script>
2341 <?php
2342 }
2343
2344 ob_start();
2345
2346 // If it's Product Details page.
2347 if ( $this->use_js && ( is_singular() && 'item' == $item->post_mime_type ) ) {
2348 ?>
2349 <script type='text/javascript'>
2350 (function($) {
2351 uscesCart = {
2352 intoCart : function (post_id, sku) {
2353 var zaikonum = $("[id='zaikonum["+post_id+"]["+sku+"]']").val();
2354 var zaiko = $("[id='zaiko["+post_id+"]["+sku+"]']").val();
2355 if( <?php echo apply_filters( 'usces_intoCart_zaiko_check_js', "( uscesL10n.itemOrderAcceptable != '1' && zaiko != '0' && zaiko != '1' ) || ( uscesL10n.itemOrderAcceptable != '1' && parseInt(zaikonum) == 0 )" ); ?> ){
2356 alert('<?php _e( 'temporaly out of stock now', 'usces' ); ?>');
2357 return false;
2358 }
2359
2360 var mes = '';
2361 if( $("[id='quant["+post_id+"]["+sku+"]']").length ){
2362 var quant = $("[id='quant["+post_id+"]["+sku+"]']").val();
2363 if( quant == '0' || quant == '' || !(uscesCart.isNum(quant))){
2364 mes += "<?php _e( 'enter the correct amount', 'usces' ); ?>\n";
2365 }
2366 var checknum = '';
2367 var checkmode = '';
2368 if( parseInt(uscesL10n.itemRestriction) <= parseInt(zaikonum) && uscesL10n.itemRestriction != '' && uscesL10n.itemRestriction != '0' && zaikonum != '' ) {
2369 checknum = uscesL10n.itemRestriction;
2370 checkmode ='rest';
2371 } else if( uscesL10n.itemOrderAcceptable != '1' && parseInt(uscesL10n.itemRestriction) > parseInt(zaikonum) && uscesL10n.itemRestriction != '' && uscesL10n.itemRestriction != '0' && zaikonum != '' ) {
2372 checknum = zaikonum;
2373 checkmode ='zaiko';
2374 } else if( uscesL10n.itemOrderAcceptable != '1' && (uscesL10n.itemRestriction == '' || uscesL10n.itemRestriction == '0') && zaikonum != '' ) {
2375 checknum = zaikonum;
2376 checkmode ='zaiko';
2377 } else if( uscesL10n.itemRestriction != '' && uscesL10n.itemRestriction != '0' && ( zaikonum == '' || zaikonum == '0' || parseInt(uscesL10n.itemRestriction) > parseInt(zaikonum) ) ) {
2378 checknum = uscesL10n.itemRestriction;
2379 checkmode ='rest';
2380 }
2381
2382 if( parseInt(quant) > parseInt(checknum) && checknum != '' ){
2383 if(checkmode == 'rest'){
2384 mes += <?php _e( "'This article is limited by '+checknum+' at a time.'", 'usces' ); ?>+"\n";
2385 }else{
2386 mes += <?php _e( "'Stock is remainder '+checknum+'.'", 'usces' ); ?>+"\n";
2387 }
2388 }
2389 }
2390 for(i=0; i<uscesL10n.key_opts.length; i++){
2391 if( uscesL10n.opt_esse[i] == '1' ){
2392 var skuob = $("[id='itemOption["+post_id+"]["+sku+"]["+uscesL10n.key_opts[i]+"]']");
2393 var itemOption = "itemOption["+post_id+"]["+sku+"]["+uscesL10n.key_opts[i]+"]";
2394 var opt_obj_radio = $(":radio[name*='"+itemOption+"']");
2395 var opt_obj_checkbox = $(":checkbox[name*='"+itemOption+"']:checked");
2396
2397 if( uscesL10n.opt_means[i] == '3' ){
2398
2399 if( !opt_obj_radio.is(':checked') ){
2400 mes += uscesL10n.mes_opts[i]+"\n";
2401 }
2402
2403 }else if( uscesL10n.opt_means[i] == '4' ){
2404
2405 if( !opt_obj_checkbox.length ){
2406 mes += uscesL10n.mes_opts[i]+"\n";
2407 }
2408
2409 }else{
2410
2411 if( skuob.length ){
2412 if( uscesL10n.opt_means[i] == 0 && skuob.val() == '#NONE#' ){
2413 mes += uscesL10n.mes_opts[i]+"\n";
2414 }else if( uscesL10n.opt_means[i] == 1 && ( skuob.val() == '' || skuob.val() == '#NONE#' ) ){
2415 mes += uscesL10n.mes_opts[i]+"\n";
2416 }else if( uscesL10n.opt_means[i] >= 2 && skuob.val() == '' ){
2417 mes += uscesL10n.mes_opts[i]+"\n";
2418 }
2419 }
2420 }
2421 }
2422 }
2423
2424 <?php apply_filters( 'usces_filter_inCart_js_check', $item->ID ); // Unavailable. ?>
2425 <?php do_action( 'usces_action_inCart_js_check', $item->ID ); ?>
2426
2427 if( mes != '' ){
2428 alert( mes );
2429 return false;
2430 }else{
2431 <?php echo apply_filters( 'usces_filter_js_intoCart', "return true;\n", $item->ID, null ); ?>
2432 }
2433 },
2434
2435 isNum : function (num) {
2436 if (num.match(/[^0-9]/g)) {
2437 return false;
2438 }
2439 return true;
2440 }
2441 };
2442 })(jQuery);
2443 </script>
2444 <?php
2445 // If it's Product Details page.
2446 } elseif ( $this->use_js && ( is_page( USCES_CART_NUMBER ) || $this->is_cart_page( $_SERVER['REQUEST_URI'] ) ) ) {
2447 ?>
2448 <script type='text/javascript'>
2449 (function($) {
2450 uscesCart = {
2451 upCart : function () {
2452
2453 var zaikoob = $("input[name*='zaikonum']");
2454 var quantob = $("input[name*='quant']");
2455 var postidob = $("input[name*='itempostid']");
2456 var skuob = $("input[name*='itemsku']");
2457
2458 var zaikonum = '';
2459 var zaiko = '';
2460 var quant = '';
2461 var mes = '';
2462 var checknum = '';
2463 var post_id = '';
2464 var sku = '';
2465 var itemRestriction = '';
2466 var itemOrderAcceptable = '';
2467
2468 var ct = zaikoob.length;
2469 for(var i=0; i< ct; i++){
2470 post_id = postidob[i].value;
2471 sku = skuob[i].value;
2472 itemRestriction = $("input[name='itemRestriction\[" + i + "\]']").val();
2473 itemOrderAcceptable = $("input[name='itemOrderAcceptable\[" + i + "\]']").val();
2474 zaikonum = $("input[name='zaikonum\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").val();
2475
2476 quant = $("*[name='quant\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").val();
2477 if( $("*[name='quant\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").length ){
2478 if( quant == '0' || quant == '' || !(uscesCart.isNum(quant))){
2479 mes += <?php _e( "'enter the correct amount for the No.' + (i+1) + ' item'", 'usces' ); ?>+"\n";
2480 }
2481 var checknum = '';
2482 var checkmode = '';
2483 if( parseInt(itemRestriction) <= parseInt(zaikonum) && itemRestriction != '' && itemRestriction != '0' && zaikonum != '' ) {
2484 checknum = itemRestriction;
2485 checkmode ='rest';
2486 } else if( itemOrderAcceptable != '1' && parseInt(itemRestriction) > parseInt(zaikonum) && itemRestriction != '' && itemRestriction != '0' && zaikonum != '' ) {
2487 checknum = zaikonum;
2488 checkmode ='zaiko';
2489 } else if( itemOrderAcceptable != '1' && (itemRestriction == '' || itemRestriction == '0') && zaikonum != '' ) {
2490 checknum = zaikonum;
2491 checkmode ='zaiko';
2492 } else if( itemRestriction != '' && itemRestriction != '0' && ( zaikonum == '' || zaikonum == '0' || parseInt(itemRestriction) > parseInt(zaikonum) ) ) {
2493 checknum = itemRestriction;
2494 checkmode ='rest';
2495 }
2496 if( parseInt(quant) > parseInt(checknum) && checknum != '' ){
2497 if(checkmode == 'rest'){
2498 mes += <?php _e( "'This article is limited by '+checknum+' at a time for the No.' + (i+1) + ' item.'", 'usces' ); ?>+"\n";
2499 }else{
2500 mes += <?php _e( "'Stock of No.' + (i+1) + ' item is remainder '+checknum+'.'", 'usces' ); ?>+"\n";
2501 }
2502 }
2503 }
2504 }
2505
2506 <?php apply_filters( 'usces_filter_upCart_js_check', $item->ID ); // Unavailable. ?>
2507 <?php do_action( 'usces_action_upCart_js_check', $item->ID ); ?>
2508
2509 if( mes != '' ){
2510 alert( mes );
2511 return false;
2512 }else{
2513 <?php echo apply_filters( 'usces_filter_js_upCart', "return true;\n", $item->ID, null ); ?>
2514 }
2515 },
2516
2517 cartNext : function () {
2518
2519 var zaikoob = $("input[name*='zaikonum']");
2520 var quantob = $("input[name*='quant']");
2521 var postidob = $("input[name*='itempostid']");
2522 var skuob = $("input[name*='itemsku']");
2523
2524 var zaikonum = '';
2525 var zaiko = '';
2526 var quant = '';
2527 var mes = '';
2528 var checknum = '';
2529 var post_id = '';
2530 var sku = '';
2531 var itemRestriction = '';
2532 var itemOrderAcceptable = '';
2533
2534 var ct = zaikoob.length;
2535 for(var i=0; i< ct; i++){
2536 post_id = postidob[i].value;
2537 sku = skuob[i].value;
2538 itemRestriction = $("input[name='itemRestriction\[" + i + "\]']").val();
2539 itemOrderAcceptable = $("input[name='itemOrderAcceptable\[" + i + "\]']").val();
2540 zaikonum = $("input[name='zaikonum\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").val();
2541
2542 quant = $("*[name='quant\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").val();
2543 if( $("*[name='quant\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").length ){
2544 if( quant == '0' || quant == '' || !(uscesCart.isNum(quant))){
2545 mes += <?php _e( "'enter the correct amount for the No.' + (i+1) + ' item'", 'usces' ); ?>+"\n";
2546 }
2547 var checknum = '';
2548 var checkmode = '';
2549 if( parseInt(itemRestriction) <= parseInt(zaikonum) && itemRestriction != '' && itemRestriction != '0' && zaikonum != '' ) {
2550 checknum = itemRestriction;
2551 checkmode ='rest';
2552 } else if( itemOrderAcceptable != '1' && parseInt(itemRestriction) > parseInt(zaikonum) && itemRestriction != '' && itemRestriction != '0' && zaikonum != '' ) {
2553 checknum = zaikonum;
2554 checkmode ='zaiko';
2555 } else if( itemOrderAcceptable != '1' && (itemRestriction == '' || itemRestriction == '0') && zaikonum != '' ) {
2556 checknum = zaikonum;
2557 checkmode ='zaiko';
2558 } else if( itemRestriction != '' && itemRestriction != '0' && ( zaikonum == '' || zaikonum == '0' || parseInt(itemRestriction) > parseInt(zaikonum) ) ) {
2559 checknum = itemRestriction;
2560 checkmode ='rest';
2561 }
2562
2563 if( parseInt(quant) > parseInt(checknum) && checknum != '' ){
2564 if(checkmode == 'rest'){
2565 mes += <?php _e( "'This article is limited by '+checknum+' at a time for the No.' + (i+1) + ' item.'", 'usces' ); ?>+"\n";
2566 }else{
2567 mes += <?php _e( "'Stock of No.' + (i+1) + ' item is remainder '+checknum+'.'", 'usces' ); ?>+"\n";
2568 }
2569 }
2570 }
2571 }
2572
2573 <?php do_action( 'usces_action_nextCart_js_check', $item->ID ); ?>
2574
2575 if( mes != '' ){
2576 alert( mes );
2577 return false;
2578 }else{
2579 return true;
2580 }
2581 },
2582
2583 customerNext : function () {
2584 <?php do_action( 'usces_action_customerNext_js_check', $item->ID ); ?>
2585 },
2586
2587 customerPre : function () {
2588 <?php do_action( 'usces_action_customerPre_js_check', $item->ID ); ?>
2589 },
2590
2591 previousCart : function () {
2592 location.href = uscesL10n.previous_url;
2593 },
2594
2595 settings: {
2596 url: uscesL10n.ajaxurl,
2597 type: 'POST',
2598 cache: false
2599 },
2600
2601 changeStates : function( country ) {
2602 var s = this.settings;
2603 s.data = "action=change_states_ajax&country=" + country;
2604 $.ajax( s ).done(function(data, dataType){
2605
2606 if( 'error' == data ){
2607 alert('error');
2608 }else{
2609 $("select#pref").html( data );
2610 }
2611 }).fail(function(msg){
2612 alert("error");
2613 });
2614 return false;
2615 },
2616
2617 isNum : function (num) {
2618 if (num.match(/[^0-9]/g)) {
2619 return false;
2620 }
2621 return true;
2622 },
2623 purchase : 0
2624 };
2625 $("#country").change(function () {
2626 var country = $("#country option:selected").val();
2627 $("#newcharging_type option:selected").val()
2628 uscesCart.changeStates( country );
2629 });
2630 $("#purchase_form").submit(function () {
2631 if( 0 == uscesCart.purchase ){
2632 uscesCart.purchase = 1;
2633 return true;
2634 }else{
2635 $("#purchase_button").prop("disabled", true);
2636 $("#back_button").prop("disabled", true);
2637 return false;
2638 }
2639 });
2640
2641 })(jQuery);
2642 </script>
2643 <?php
2644 }
2645
2646 usces_states_form_js();
2647 $js = apply_filters( 'usces_filter_shop_foot_js', ob_get_contents() );
2648 ob_end_clean();
2649 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2650 echo $js;
2651 }
2652
2653 public function admin_head() {
2654 global $wp_version;
2655 $wcex_str = '';
2656 $wcex = usces_get_wcex();
2657 foreach ( (array) $wcex as $key => $values ) {
2658 $wcex_str .= "'" . esc_js( $key ) . '-' . esc_js( $values['version'] ) . "', ";
2659 }
2660 $wcex_str = rtrim( $wcex_str, ', ' );
2661 $theme_ob = wp_get_theme();
2662 if ( $theme_ob ) {
2663 $theme = array(
2664 'Name' => esc_js( $theme_ob->get( 'Name' ) ),
2665 'Version' => esc_js( $theme_ob->get( 'Version' ) ),
2666 );
2667 } else {
2668 $theme = array( 'Name' => '', 'Version' => '' );
2669 }
2670 $message = usces_get_admin_script_message();
2671 ?>
2672 <link href="<?php echo USCES_PLUGIN_URL; ?>/css/admin_style.css" rel="stylesheet" type="text/css" media="all" />
2673 <script type='text/javascript'>
2674 /* <![CDATA[ */
2675 uscesL10n = {
2676 <?php echo apply_filters( 'usces_filter_admin_uscesL10n', null ); ?>
2677 'requestFile': "<?php echo site_url(); ?>/wp-admin/admin-ajax.php",
2678 'USCES_PLUGIN_URL': "<?php echo USCES_PLUGIN_URL; ?>",
2679 'version': "<?php echo USCES_VERSION; ?>",
2680 'wcid': "<?php echo get_option( 'usces_wcid' ); ?>",
2681 'locale': '<?php echo get_locale(); ?>',
2682 'cart_number': "<?php echo get_option( 'usces_cart_number' ); ?>",
2683 'purchase_limit': "<?php echo esc_js( $this->options['purchase_limit'] ); ?>",
2684 'point_rate': "<?php echo esc_js( $this->options['point_rate'] ); ?>",
2685 'shipping_rule': "<?php echo esc_js( $this->options['shipping_rule'] ); ?>",
2686 'theme': "<?php echo esc_html( $theme['Name'] . '-' . $theme['Version'] ); ?>",
2687 'wcex': new Array( <?php wel_esc_script_e( $wcex_str ); ?> ),
2688 'message': new Array( <?php wel_esc_script_e( $message ); ?> ),
2689 'now_loading': "<?php _e( 'now loading', 'usces' ); ?>"
2690 };
2691 /* ]]> */
2692 </script>
2693 <script type='text/javascript' src='<?php echo USCES_PLUGIN_URL; ?>/js/usces_admin.js?ver=<?php echo USCES_VERSION; ?>'></script>
2694 <?php
2695 if ( 'edit' == $this->action_status || 'editpost' == $this->action_status ) {
2696 ?>
2697 <link rel='stylesheet' href='<?php echo site_url(); ?>/wp-includes/js/thickbox/thickbox.css' type='text/css' media='all' />
2698 <?php
2699 }
2700 if ( isset( $_REQUEST['page'] ) ) {
2701 switch ( $_REQUEST['page'] ) {
2702 case 'usces_initial':
2703 $cod_type = ( 'change' == $this->options['cod_type'] ) ? 'change' : 'fix';
2704 ?>
2705 <script type='text/javascript'>
2706 /* <![CDATA[ */
2707 usces_ini = {
2708 'cod_type': "<?php echo esc_js( $cod_type ); ?>",
2709 'cod_type_fix': "<?php echo esc_js( __( 'Fixation C.O.D.', 'usces' ) ); ?>",
2710 'cod_type_change': "<?php echo esc_js( __( 'Variable C.O.D.', 'usces' ) ); ?>",
2711 'cod_unit': "<?php echo esc_js( __( 'dollars', 'usces' ) ); ?>",
2712 'cod_failure': "<?php echo esc_js( __( 'failure in update', 'usces' ) ); ?>",
2713 'cod_updated': "<?php echo esc_js( __( 'options are updated', 'usces' ) ); ?>",
2714 'cod_limit': "<?php echo esc_js( __( 'A value of the amount of upper limit is incorrect.', 'usces' ) ); ?>",
2715 'cod_label_close': "<?php echo esc_js( __( 'Close', 'usces' ) ); ?>",
2716 'cod_label_update': "<?php echo esc_js( __( 'Update', 'usces' ) ); ?>"
2717 };
2718 /* ]]> */
2719 </script>
2720 <?php
2721 break;
2722 case 'usces_itemnew':
2723 case 'usces_itemedit':
2724 ?>
2725 <style type="text/css">
2726 <!--
2727 #usces_mess {
2728 color: #FF0000;
2729 font-weight: bold;
2730 }
2731 -->
2732 </style>
2733 <?php
2734 break;
2735 }
2736 }
2737
2738 if ( is_admin() && ( ( isset( $_GET['order_action'] ) && 'newpost' == $_GET['order_action'] )
2739 || ( isset( $_GET['page'] ) && 'usces_ordernew' == $_GET['page'] )
2740 || ( isset( $_GET['order_action'] ) && 'edit' == $_GET['order_action'] )
2741 || ( isset( $_GET['order_action'] ) && 'editpost' == $_GET['order_action'] )
2742 || ( isset( $_GET['page'] ) && 'usces_membernew' == $_GET['page'] )
2743 || ( isset( $_GET['member_action'] ) && 'edit' == $_GET['member_action'] )
2744 || ( isset( $_GET['member_action'] ) && 'editpost' == $_GET['member_action'] ) ) ) :
2745 switch ( $_GET['page'] ) {
2746 case 'usces_ordernew':
2747 case 'usces_orderlist':
2748 $admin_page = 'order';
2749 break;
2750 case 'usces_membernew':
2751 case 'usces_memberlist':
2752 $admin_page = 'member';
2753 break;
2754 }
2755 ?>
2756 <script type='text/javascript'>
2757 jQuery(function($) {
2758 uscesForm = {
2759 settings: {
2760 url: uscesL10n.requestFile,
2761 type: 'POST',
2762 cache: false
2763 },
2764
2765 changeStates : function( country, type ) {
2766 var s = this.settings;
2767 s.data = "action=change_states_ajax&country=" + country;
2768 $.ajax( s ).done(function(data, dataType){
2769 if( 'error' == data ){
2770 alert('error');
2771 }else{
2772 $("select#" + type + "_pref").html( data );
2773 if( customercountry == country && 'customer' == type ){
2774 $("#" + type + "_pref").prop({selectedIndex:customerstate});
2775 }else if( deliverycountry == country && 'delivery' == type ){
2776 $("#" + type + "_pref").prop({selectedIndex:deliverystate});
2777 }else if( customercountry == country && 'member' == type ){
2778 $("#" + type + "_pref").prop({selectedIndex:customerstate});
2779 }
2780 }
2781 }).fail(function(msg){
2782 alert("error");
2783 });
2784 return false;
2785 },
2786
2787 isNum : function (num) {
2788 if (num.match(/[^0-9]/g)) {
2789 return false;
2790 }
2791 return true;
2792 }
2793 };
2794 <?php
2795 if ( 'order' == $admin_page ) {
2796 ?>
2797 if( undefined != $("#customer_pref").get(0) && undefined != $("#delivery_country").get(0) ) {
2798 var customerstate = $("#customer_pref").get(0).selectedIndex;
2799 var customercountry = $("#customer_country").val();
2800 var deliverystate = $("#delivery_pref").get(0).selectedIndex;
2801 var deliverycountry = $("#delivery_country").val();
2802
2803 $("#customer_country").change(function () {
2804 var country = $("#customer_country option:selected").val();
2805 uscesForm.changeStates( country, 'customer' );
2806 });
2807 $("#delivery_country").change(function () {
2808 var country = $("#delivery_country option:selected").val();
2809 uscesForm.changeStates( country, 'delivery' );
2810 });
2811 }
2812 <?php
2813 } elseif ( 'member' == $admin_page ) {
2814 ?>
2815 if( undefined != $("#member_pref").get(0) ) {
2816 var customerstate = $("#member_pref").get(0).selectedIndex;
2817 var customercountry = $("#member_country").val();
2818 var deliverystate = '';
2819 var deliverycountry = '';
2820
2821 $("#member_country").change(function () {
2822 var country = $("#member_country option:selected").val();
2823 uscesForm.changeStates( country, 'member' );
2824 });
2825 }
2826 <?php
2827 }
2828 ?>
2829 });
2830 </script>
2831 <?php
2832 endif;
2833 }
2834
2835 /**
2836 * Main Process.
2837 */
2838 public function main() {
2839 global $wpdb, $wp_locale, $wp_version, $post_ID;
2840 global $wp_query, $usces_action, $post, $action, $editing;
2841
2842 update_option( 'usces_shipping_rule', apply_filters( 'usces_filter_shipping_rule', get_option( 'usces_shipping_rule' ) ) );
2843 $this->shipping_rule = get_option( 'usces_shipping_rule' );
2844
2845 if ( ! is_admin() ) {
2846 $this->usces_cookie();
2847 } else {
2848 $this->user_level = usces_get_admin_user_level();
2849 }
2850 $this->make_url();
2851
2852 add_filter( 'cron_schedules', 'usces_schedules_intervals' );
2853 add_action( 'wp', 'usces_wevent' );
2854 do_action( 'usces_main' );
2855 $this->update_table();
2856
2857 require_once USCES_PLUGIN_DIR . '/classes/cart.class.php';
2858 $this->cart = new usces_cart();
2859
2860 do_action( 'usces_after_cart_instant' );
2861
2862 if ( isset( $_REQUEST['page'] ) && 'usces_itemedit' == $_REQUEST['page'] && isset( $_REQUEST['action'] ) && 'duplicate' == $_REQUEST['action'] ) {
2863 $post_id = (int) $_GET['post'];
2864 $new_id = usces_item_duplicate( $post_id );
2865 $ref = isset( $_REQUEST['usces_referer'] ) ? urlencode( esc_url( $_REQUEST['usces_referer'] ) ) : '';
2866 $url = USCES_ADMIN_URL . '?page=usces_itemedit&action=edit&post=' . $new_id . '&usces_referer=' . $ref;
2867 wp_redirect( $url );
2868 exit;
2869 } elseif ( isset( $_REQUEST['page'] ) && 'usces_itemedit' == $_REQUEST['page'] && isset( $_REQUEST['action'] ) && 'itemcsv' == $_REQUEST['action'] ) {
2870 // $filename = usces_item_uploadcsv();
2871 // $mode = ( isset( $_REQUEST['upload_mode'] ) ) ? $_REQUEST['upload_mode'] : 'all';
2872 // $url = USCES_ADMIN_URL . '?page=usces_itemedit&usces_status=none&usces_message=&action=upload_register&mode=' . $mode . '&regfile=' . $filename;
2873 // wp_redirect( $url );
2874 // exit;
2875 }
2876
2877 $this->ad_controller();
2878
2879 if ( isset( $_GET['page'] ) && 'usces_itemnew' == $_GET['page'] ) {
2880 $itemnew = 'new';
2881 } else {
2882 $itemnew = '';
2883 }
2884
2885 wp_enqueue_script( 'jquery' );
2886
2887 if ( is_admin() && isset( $_REQUEST['page'] ) && ( ( isset( $_REQUEST['action'] ) && 'edit' == $_REQUEST['action'] ) || 'new' == $itemnew || ( isset( $_REQUEST['action'] ) && 'editpost' == $_REQUEST['action'] ) ) ) {
2888
2889 if ( isset( $_REQUEST['action'] ) && 'editpost' != $_REQUEST['action'] && 'new' == $itemnew ) {
2890 if ( version_compare( $wp_version, '3.0-beta', '>' ) ) {
2891 if ( ! isset( $_GET['post_type'] ) ) {
2892 $post_type = 'post';
2893 } elseif ( in_array( $_GET['post_type'], get_post_types( array( 'public' => true ) ) ) ) {
2894 $post_type = $_GET['post_type'];
2895 } else {
2896 wp_die( __( 'Invalid post type' ) );
2897 }
2898 $post_type_object = get_post_type_object( $post_type );
2899 $editing = true;
2900 $post = $this->get_default_post_to_edit30( $post_type, true );
2901 $post_ID = $post->ID;
2902 } else {
2903 $post = $this->get_default_post_to_edit();
2904 }
2905 } else {
2906 if ( version_compare( $wp_version, '3.0-beta', '>' ) ) {
2907 if ( isset( $_GET['post'] ) ) {
2908 $post_id = (int) $_GET['post'];
2909 } elseif ( isset( $_POST['post_ID'] ) ) {
2910 $post_id = (int) $_POST['post_ID'];
2911 } else {
2912 $post_id = 0;
2913 }
2914 $post_ID = $post_id;
2915 $post = null;
2916 $post_type_object = null;
2917 $post_type = null;
2918 if ( $post_id ) {
2919 $product = wel_get_product( $post_id );
2920 $post = $product['_pst'];
2921 if ( $post ) {
2922 $post_type_object = get_post_type_object( $post->post_type );
2923 if ( $post_type_object ) {
2924 $post_type = $post->post_type;
2925 if ( ! isset( $current_screen ) ) {
2926 $current_screen = new stdClass();
2927 }
2928 $current_screen->post_type = $post->post_type;
2929 $current_screen->id = $current_screen->post_type;
2930 }
2931 }
2932 } elseif ( isset( $_POST['post_type'] ) ) {
2933 $post_type_object = get_post_type_object( $_POST['post_type'] );
2934 if ( $post_type_object ) {
2935 $post_type = $post_type_object->name;
2936 $current_screen->post_type = $post_type;
2937 $current_screen->id = $current_screen->post_type;
2938 }
2939 }
2940 } else {
2941 if ( isset( $_GET['post'] ) ) {
2942 $post_ID = (int) $_GET['post'];
2943 $product = wel_get_product( $post_ID );
2944 $post = $product['_pst'];
2945 } else {
2946 $post_ID = isset( $_REQUEST['post_ID'] ) ? (int) $_REQUEST['post_ID'] : 0;
2947 if ( ! empty( $post_ID ) ) {
2948 $product = wel_get_product( $post_ID );
2949 $post = $product['_pst'];
2950 }
2951 }
2952 }
2953 }
2954
2955 $editing = true;
2956 wp_enqueue_script( 'autosave' );
2957 wp_enqueue_script( 'post' );
2958 add_thickbox();
2959 wp_enqueue_script( 'media-upload' );
2960 wp_enqueue_script( 'word-count' );
2961 wp_enqueue_script( 'admin-comments' );
2962
2963 if ( version_compare( $wp_version, '3.3', '<' ) ) {
2964 add_action( 'admin_print_footer_scripts', 'wp_tiny_mce', 25 );
2965 }
2966 wp_enqueue_script( 'quicktags' );
2967 }
2968
2969 if ( is_admin() && isset( $_REQUEST['page'] ) ) {
2970
2971 wp_enqueue_script( 'jquery-color' );
2972
2973 switch ( $_REQUEST['page'] ) {
2974 case 'usces_initial':
2975 $js = USCES_FRONT_PLUGIN_URL . '/js/usces_initial.js';
2976 wp_enqueue_script( 'usces_initial.js', $js, array( 'jquery-ui-dialog', 'jquery-ui-sortable' ) );
2977 break;
2978 case 'usces_settlement':
2979 wp_enqueue_script( 'jquery-ui-tabs', array( 'jquery-ui-core' ) );
2980 $jquery_cookie_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/jquery-cookie.js';
2981 wp_enqueue_script( 'jquery-cookie', $jquery_cookie_url, array( 'jquery' ) );
2982 $jquery_color_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/color/jscolor.js';
2983 wp_enqueue_script( 'jquery-jscolor', $jquery_color_url, array( 'jquery-color' ) );
2984 wp_enqueue_script( 'jquery-ui-sortable' );
2985 wp_enqueue_script( 'jquery-ui-dialog' );
2986 break;
2987 case 'usces_cart':
2988 wp_enqueue_script( 'jquery-ui-tabs', array( 'jquery-ui-core' ) );
2989 $jquery_cookie_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/jquery-cookie.js';
2990 wp_enqueue_script( 'jquery-cookie', $jquery_cookie_url, array( 'jquery' ) );
2991 break;
2992 case 'usces_member':
2993 wp_enqueue_script( 'jquery-ui-tabs', array( 'jquery-ui-core' ) );
2994 $jquery_cookie_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/jquery-cookie.js';
2995 wp_enqueue_script( 'jquery-cookie', $jquery_cookie_url, array( 'jquery' ) );
2996 break;
2997 case 'usces_orderlist':
2998 case 'usces_ordernew':
2999 wp_enqueue_script( 'jquery-ui-datepicker' );
3000 wp_enqueue_script( 'jquery-ui-dialog' );
3001 break;
3002 case 'usces_memberlist':
3003 wp_enqueue_script( 'jquery-ui-dialog' );
3004 break;
3005 case 'usces_itemnew':
3006 wp_enqueue_script( 'jquery-ui-sortable' );
3007 break;
3008 case 'usces_itemedit':
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 if ( isset( $_REQUEST['action'] ) && 'upload_register' == $_REQUEST['action'] ) {
3012 // $upload_registerUrl = USCES_FRONT_PLUGIN_URL . '/js/usces-item-upload.js';
3013 // wp_enqueue_script( 'upload_register', $upload_registerUrl, array( 'jquery' ), USCES_VERSION, true );
3014 // @ob_end_clean();
3015 // ob_start();
3016 } else {
3017 wp_enqueue_script( 'jquery-ui-sortable' );
3018 wp_enqueue_script( 'jquery-ui-dialog' );
3019 }
3020 break;
3021 case 'usces_delivery':
3022 wp_enqueue_script( 'jquery-ui-tabs', array( 'jquery-ui-core' ) );
3023 $jquery_cookie_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/jquery-cookie.js';
3024 wp_enqueue_script( 'jquery-cookie', $jquery_cookie_url, array( 'jquery' ) );
3025 break;
3026 case 'usces_system':
3027 wp_enqueue_script( 'jquery-ui-tabs', array( 'jquery-ui-core' ) );
3028 $jquery_cookie_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/jquery-cookie.js';
3029 wp_enqueue_script( 'jquery-cookie', $jquery_cookie_url, array( 'jquery' ) );
3030 break;
3031 case 'usces_mail':
3032 wp_enqueue_script( 'jquery-ui-tabs', array( 'jquery-ui-core' ) );
3033 $jquery_cookie_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/jquery-cookie.js';
3034 wp_enqueue_script( 'jquery-cookie', $jquery_cookie_url, array( 'jquery' ) );
3035 break;
3036 }
3037 }
3038
3039 if ( isset( $_REQUEST['order_action'] ) && 'pdfout' == $_REQUEST['order_action'] ) {
3040 check_admin_referer( 'order_edit', 'wc_nonce' );
3041
3042 $oid = filter_input( INPUT_GET, 'order_id' );
3043 if ( ! is_user_logged_in() ) {
3044 $this->get_current_member();
3045 $mid = $this->current_member['id'];
3046 if ( 0 === (int) $mid || ! $this->is_order( $mid, $oid ) ) {
3047 die( 'No permission' );
3048 }
3049 }
3050 if ( ( isset( $this->options['tax_display'] ) && 'activate' == $this->options['tax_display'] ) && usces_is_reduced_taxrate( $oid ) ) {
3051 require_once( apply_filters( 'usces_filter_orderpdf_path_ex', USCES_PLUGIN_DIR . '/includes/order_print_ex.php' ) );
3052 } else {
3053 require_once( apply_filters( 'usces_filter_orderpdf_path', USCES_PLUGIN_DIR . '/includes/order_print.php' ) );
3054 }
3055 }
3056
3057 if ( ! empty( $this->settlement_notice ) &&
3058 ( 1 === (int) $this->options['system']['settlement_notice'] || defined( 'WCEX_DLSELLER' ) || defined( 'WCEX_AUTO_DELIVERY' ) ) ) {
3059 add_action( 'admin_notices', 'usces_display_settlement_notice' );
3060 }
3061
3062 do_action( 'usces_after_main' );
3063 }
3064
3065 public function stripslashes_deep_post( $array ) {
3066 $res = array();
3067 foreach ( $array as $key => $value ) {
3068 $key = stripslashes( $key );
3069 if ( is_array( $value ) ) {
3070 $value = $this->stripslashes_deep_post( $value );
3071 } else {
3072 $value = is_null( $value ) ? $value : usces_erase_emoji( stripslashes( $value ) );
3073 }
3074 $res[ $key ] = $value;
3075 }
3076 return $res;
3077 }
3078
3079 public function make_url() {
3080 $permalink_structure = get_option( 'permalink_structure' );
3081 if ( $this->use_ssl ) {
3082 if ( $permalink_structure ) {
3083 $this->delim = '&';
3084 $home_perse = parse_url( get_option( 'home' ) );
3085 $home_perse_path = isset( $home_perse['path'] ) ? $home_perse['path'] : '';
3086 $home_path = $home_perse['host'] . $home_perse_path;
3087 $ssl_perse = parse_url( $this->options['ssl_url'] );
3088 $ssl_perse_path = isset( $ssl_perse['path'] ) ? $ssl_perse['path'] : '';
3089 $ssl_path = $ssl_perse['host'] . $ssl_perse_path;
3090 if ( $home_perse_path != $ssl_perse_path ) {
3091 if ( ! defined( 'USCES_CUSTOMER_URL' ) ) {
3092 define( 'USCES_CUSTOMER_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_CART_NUMBER . '&customerinfo=1&uscesid=' . $this->get_uscesid() );
3093 }
3094 if ( ! defined( 'USCES_CART_URL' ) ) {
3095 define( 'USCES_CART_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_CART_NUMBER . '&uscesid=' . $this->get_uscesid() );
3096 }
3097 if ( ! defined( 'USCES_LOSTMEMBERPASSWORD_URL' ) ) {
3098 define( 'USCES_LOSTMEMBERPASSWORD_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_MEMBER_NUMBER . '&uscesid=' . $this->get_uscesid() . '&usces_page=lostmemberpassword' );
3099 }
3100 if ( ! defined( 'USCES_NEWMEMBER_URL' ) ) {
3101 define( 'USCES_NEWMEMBER_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_MEMBER_NUMBER . '&uscesid=' . $this->get_uscesid() . '&usces_page=newmember' );
3102 }
3103 if ( ! defined( 'USCES_LOGIN_URL' ) ) {
3104 define( 'USCES_LOGIN_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_MEMBER_NUMBER . '&uscesid=' . $this->get_uscesid() . '&usces_page=login' );
3105 }
3106 if ( ! defined( 'USCES_LOGOUT_URL' ) ) {
3107 define( 'USCES_LOGOUT_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_MEMBER_NUMBER . '&uscesid=' . $this->get_uscesid() . '&usces_page=logout' );
3108 }
3109 if ( ! defined( 'USCES_MEMBER_URL' ) ) {
3110 define( 'USCES_MEMBER_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_MEMBER_NUMBER . '&uscesid=' . $this->get_uscesid() );
3111 }
3112 $inquiry_url = empty( $this->options['inquiry_id'] ) ? '' : $this->options['ssl_url'] . '/index.php?page_id=' . $this->options['inquiry_id'] . '&uscesid=' . $this->get_uscesid();
3113 if ( ! defined( 'USCES_INQUIRY_URL' ) ) {
3114 define( 'USCES_INQUIRY_URL', $inquiry_url );
3115 }
3116 if ( ! defined( 'USCES_CART_NONSESSION_URL' ) ) {
3117 define( 'USCES_CART_NONSESSION_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_CART_NUMBER );
3118 }
3119 if ( ! defined( 'USCES_PAYPAL_NOTIFY_URL' ) ) {
3120 define( 'USCES_PAYPAL_NOTIFY_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_CART_NUMBER . '&acting=paypal_ipn&uscesid=' . $this->get_uscesid( false ) );
3121 }
3122 } else {
3123 $ssl_plink_cart = str_replace( 'http://','https://', str_replace( $home_path, $ssl_path, get_page_link( USCES_CART_NUMBER ) ) );
3124 $ssl_plink_member = str_replace( 'http://','https://', str_replace( $home_path, $ssl_path, get_page_link( USCES_MEMBER_NUMBER ) ) );
3125 if ( ! defined( 'USCES_CUSTOMER_URL' ) ) {
3126 define( 'USCES_CUSTOMER_URL', $ssl_plink_cart . '?uscesid=' . $this->get_uscesid() . '&customerinfo=1' );
3127 }
3128 if ( ! defined( 'USCES_CART_URL' ) ) {
3129 define( 'USCES_CART_URL', $ssl_plink_cart . '?uscesid=' . $this->get_uscesid() );
3130 }
3131 if ( ! defined( 'USCES_LOSTMEMBERPASSWORD_URL' ) ) {
3132 define( 'USCES_LOSTMEMBERPASSWORD_URL', $ssl_plink_member . '?uscesid=' . $this->get_uscesid() . '&usces_page=lostmemberpassword' );
3133 }
3134 if ( ! defined( 'USCES_NEWMEMBER_URL' ) ) {
3135 define( 'USCES_NEWMEMBER_URL', $ssl_plink_member . '?uscesid=' . $this->get_uscesid() . '&usces_page=newmember' );
3136 }
3137 if ( ! defined( 'USCES_LOGIN_URL' ) ) {
3138 define( 'USCES_LOGIN_URL', $ssl_plink_member . '?uscesid=' . $this->get_uscesid() . '&usces_page=login' );
3139 }
3140 if ( ! defined( 'USCES_LOGOUT_URL' ) ) {
3141 define( 'USCES_LOGOUT_URL', $ssl_plink_member . '?uscesid=' . $this->get_uscesid() . '&usces_page=logout' );
3142 }
3143 if ( ! defined( 'USCES_MEMBER_URL' ) ) {
3144 define( 'USCES_MEMBER_URL', $ssl_plink_member . '?uscesid=' . $this->get_uscesid() );
3145 }
3146 if ( ! isset( $this->options['inquiry_id'] ) || ! ( (int) $this->options['inquiry_id'] ) ) {
3147 $inquiry_url = get_home_url();
3148 } else {
3149 $ssl_plink_inquiry = str_replace( 'http://', 'https://', str_replace( $home_path, $ssl_path, get_page_link( $this->options['inquiry_id'] ) ) );
3150 $inquiry_url = empty( $this->options['inquiry_id'] ) ? '' : $ssl_plink_inquiry . '?uscesid=' . $this->get_uscesid();
3151 }
3152 if ( ! defined( 'USCES_INQUIRY_URL' ) ) {
3153 define( 'USCES_INQUIRY_URL', $inquiry_url );
3154 }
3155 if ( ! defined( 'USCES_CART_NONSESSION_URL' ) ) {
3156 define( 'USCES_CART_NONSESSION_URL', $ssl_plink_cart );
3157 }
3158 if ( ! defined( 'USCES_PAYPAL_NOTIFY_URL' ) ) {
3159 define( 'USCES_PAYPAL_NOTIFY_URL', $ssl_plink_cart . '?acting=paypal_ipn&uscesid=' . $this->get_uscesid( false ) );
3160 }
3161 }
3162 } else {
3163 $this->delim = '&';
3164 if ( ! defined( 'USCES_CUSTOMER_URL' ) ) {
3165 define( 'USCES_CUSTOMER_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_CART_NUMBER . '&customerinfo=1&uscesid=' . $this->get_uscesid() );
3166 }
3167 if ( ! defined( 'USCES_CART_URL' ) ) {
3168 define( 'USCES_CART_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_CART_NUMBER . '&uscesid=' . $this->get_uscesid() );
3169 }
3170 if ( ! defined( 'USCES_LOSTMEMBERPASSWORD_URL' ) ) {
3171 define( 'USCES_LOSTMEMBERPASSWORD_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_MEMBER_NUMBER . '&uscesid=' . $this->get_uscesid() . '&usces_page=lostmemberpassword' );
3172 }
3173 if ( ! defined( 'USCES_NEWMEMBER_URL' ) ) {
3174 define( 'USCES_NEWMEMBER_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_MEMBER_NUMBER . '&uscesid=' . $this->get_uscesid() . '&usces_page=newmember' );
3175 }
3176 if ( ! defined( 'USCES_LOGIN_URL' ) ) {
3177 define( 'USCES_LOGIN_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_MEMBER_NUMBER . '&uscesid=' . $this->get_uscesid() . '&usces_page=login' );
3178 }
3179 if ( ! defined( 'USCES_LOGOUT_URL' ) ) {
3180 define( 'USCES_LOGOUT_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_MEMBER_NUMBER . '&uscesid=' . $this->get_uscesid() . '&usces_page=logout' );
3181 }
3182 if ( ! defined( 'USCES_MEMBER_URL' ) ) {
3183 define( 'USCES_MEMBER_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_MEMBER_NUMBER . '&uscesid=' . $this->get_uscesid() );
3184 }
3185 $inquiry_url = empty( $this->options['inquiry_id'] ) ? '' : $this->options['ssl_url'] . '/?page_id=' . $this->options['inquiry_id'] . '&uscesid=' . $this->get_uscesid();
3186 if ( ! defined( 'USCES_INQUIRY_URL' ) ) {
3187 define( 'USCES_INQUIRY_URL', $inquiry_url );
3188 }
3189 if ( ! defined( 'USCES_CART_NONSESSION_URL' ) ) {
3190 define( 'USCES_CART_NONSESSION_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_CART_NUMBER );
3191 }
3192 if ( ! defined( 'USCES_PAYPAL_NOTIFY_URL' ) ) {
3193 define( 'USCES_PAYPAL_NOTIFY_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_CART_NUMBER . '&acting=paypal_ipn&uscesid=' . $this->get_uscesid( false ) );
3194 }
3195 }
3196 if ( ! is_admin() ) {
3197 add_filter( 'home_url', array( $this, 'usces_ssl_page_link' ) );
3198 add_filter( 'wp_get_attachment_url', array( $this, 'usces_ssl_attachment_link' ) );
3199 add_filter( 'icon_dir_uri', array( $this, 'usces_ssl_icon_dir_uri' ) );
3200 add_filter( 'stylesheet_directory_uri', array( $this, 'usces_ssl_contents_link' ) );
3201 add_filter( 'template_directory_uri', array( $this, 'usces_ssl_contents_link' ) );
3202 add_filter( 'script_loader_src', array( $this, 'usces_ssl_script_link' ) );
3203 add_filter( 'style_loader_src', array( $this, 'usces_ssl_script_link' ) );
3204 }
3205 } else {
3206 if ( $permalink_structure ) {
3207 $this->delim = '?';
3208 if ( ! defined( 'USCES_CUSTOMER_URL' ) ) {
3209 define( 'USCES_CUSTOMER_URL', get_page_link( USCES_CART_NUMBER ) . '?customerinfo=1' );
3210 }
3211 if ( ! defined( 'USCES_CART_URL' ) ) {
3212 define( 'USCES_CART_URL', get_page_link( USCES_CART_NUMBER ) );
3213 }
3214 if ( ! defined( 'USCES_LOSTMEMBERPASSWORD_URL' ) ) {
3215 define( 'USCES_LOSTMEMBERPASSWORD_URL', get_page_link( USCES_MEMBER_NUMBER ) . '?usces_page=lostmemberpassword' );
3216 }
3217 if ( ! defined( 'USCES_NEWMEMBER_URL' ) ) {
3218 define( 'USCES_NEWMEMBER_URL', get_page_link( USCES_MEMBER_NUMBER ) . '?usces_page=newmember' );
3219 }
3220 if ( ! defined( 'USCES_LOGIN_URL' ) ) {
3221 define( 'USCES_LOGIN_URL', get_page_link( USCES_MEMBER_NUMBER ) . '?usces_page=login' );
3222 }
3223 if ( ! defined( 'USCES_LOGOUT_URL' ) ) {
3224 define( 'USCES_LOGOUT_URL', get_page_link( USCES_MEMBER_NUMBER ) . '?usces_page=logout' );
3225 }
3226 if ( ! defined( 'USCES_MEMBER_URL' ) ) {
3227 define( 'USCES_MEMBER_URL', get_page_link( USCES_MEMBER_NUMBER ) );
3228 }
3229 $inquiry_url = ( ! isset( $this->options['inquiry_id'] ) || ! ( (int) $this->options['inquiry_id'] ) ) ? get_home_url() : get_page_link( $this->options['inquiry_id'] );
3230 if ( ! defined( 'USCES_INQUIRY_URL' ) ) {
3231 define( 'USCES_INQUIRY_URL', $inquiry_url );
3232 }
3233 if ( ! defined( 'USCES_CART_NONSESSION_URL' ) ) {
3234 define( 'USCES_CART_NONSESSION_URL', get_page_link( USCES_CART_NUMBER ) );
3235 }
3236 if ( ! defined( 'USCES_PAYPAL_NOTIFY_URL' ) ) {
3237 define( 'USCES_PAYPAL_NOTIFY_URL', get_page_link( USCES_CART_NUMBER ) . '?acting=paypal_ipn&uscesid=' . $this->get_uscesid( false ) );
3238 }
3239 } else {
3240 $this->delim = '&';
3241 if ( ! defined( 'USCES_CUSTOMER_URL' ) ) {
3242 define( 'USCES_CUSTOMER_URL', get_option( 'home' ) . '/?page_id=' . USCES_CART_NUMBER . '&customerinfo=1' );
3243 }
3244 if ( ! defined( 'USCES_CART_URL' ) ) {
3245 define( 'USCES_CART_URL', get_option( 'home' ) . '/?page_id=' . USCES_CART_NUMBER );
3246 }
3247 if ( ! defined( 'USCES_LOSTMEMBERPASSWORD_URL' ) ) {
3248 define( 'USCES_LOSTMEMBERPASSWORD_URL', get_option( 'home' ) . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=lostmemberpassword' );
3249 }
3250 if ( ! defined( 'USCES_NEWMEMBER_URL' ) ) {
3251 define( 'USCES_NEWMEMBER_URL', get_option( 'home' ) . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=newmember' );
3252 }
3253 if ( ! defined( 'USCES_LOGIN_URL' ) ) {
3254 define( 'USCES_LOGIN_URL', get_option( 'home' ) . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=login' );
3255 }
3256 if ( ! defined( 'USCES_LOGOUT_URL' ) ) {
3257 define( 'USCES_LOGOUT_URL', get_option( 'home' ) . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=logout' );
3258 }
3259 if ( ! defined( 'USCES_CART_NONSESSION_URL' ) ) {
3260 define( 'USCES_CART_NONSESSION_URL', get_option( 'home' ) . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=logout' );
3261 }
3262 if ( ! defined( 'USCES_MEMBER_URL' ) ) {
3263 define( 'USCES_MEMBER_URL', get_option( 'home' ) . '/?page_id=' . USCES_MEMBER_NUMBER );
3264 }
3265 $inquiry_url = empty( $this->options['inquiry_id'] ) ? '' : get_option( 'home' ) . '/?page_id=' . $this->options['inquiry_id'];
3266 if ( ! defined( 'USCES_INQUIRY_URL' ) ) {
3267 define( 'USCES_INQUIRY_URL', $inquiry_url );
3268 }
3269 if ( ! defined( 'USCES_CART_NONSESSION_URL' ) ) {
3270 define( 'USCES_CART_NONSESSION_URL', get_option( 'home' ) . '/?page_id=' . USCES_CART_NUMBER );
3271 }
3272 if ( ! defined( 'USCES_PAYPAL_NOTIFY_URL' ) ) {
3273 define( 'USCES_PAYPAL_NOTIFY_URL', get_option( 'home' ) . '/?page_id=' . USCES_CART_NUMBER . '&acting=paypal_ipn&uscesid=' . $this->get_uscesid( false ) );
3274 }
3275 }
3276 }
3277 }
3278
3279 public function regist_action() {
3280 usces_register_action( 'inCart', 'post', 'inCart', null, 'inCart' );
3281 usces_register_action( 'upButton', 'post', 'upButton', null, 'upButton' );
3282 usces_register_action( 'delButton', 'post', 'delButton', null, 'delButton' );
3283 usces_register_action( 'backCart', 'post', 'backCart', null, 'backCart' );
3284 usces_register_action( 'customerinfo', 'request', 'customerinfo', null, 'customerinfo' );
3285 usces_register_action( 'backCustomer', 'post', 'backCustomer', null, 'backCustomer' );
3286 usces_register_action( 'customerlogin', 'post', 'customerlogin', null, 'customerlogin' );
3287 usces_register_action( 'reganddeliveryinfo', 'post', 'reganddeliveryinfo', null, 'reganddeliveryinfo' );
3288 usces_register_action( 'deliveryinfo', 'post', 'deliveryinfo', null, 'deliveryinfo' );
3289 usces_register_action( 'backDelivery', 'request', 'backDelivery', null, 'backDelivery' );
3290 usces_register_action( 'confirm', 'request', 'confirm', null, 'confirm' );
3291 usces_register_action( 'use_point', 'post', 'use_point', null, 'use_point' );
3292 usces_register_action( 'backConfirm', 'post', 'backConfirm', null, 'backConfirm' );
3293 usces_register_action( 'purchase', 'request', 'purchase', null, 'purchase' );
3294 usces_register_action( 'acting_return', 'request', 'acting_return', null, 'acting_return' );
3295 usces_register_action( 'settlement_epsilon', 'request', 'settlement', 'epsilon', 'settlement_epsilon' );
3296 usces_register_action( 'inquiry_button', 'post', 'inquiry_button', null, 'inquiry_button' );
3297 usces_register_action( 'member_login', 'request', 'member_login', null, 'member_login_page' );
3298 usces_register_action( 'regmember', 'request', 'regmember', null, 'regmember' );
3299 usces_register_action( 'editmember', 'request', 'editmember', null, 'editmember' );
3300 usces_register_action( 'deletemember', 'request', 'deletemember', null, 'deletemember' );
3301 usces_register_action( 'page_login', 'get', 'usces_page', 'login', 'member_login_page' );
3302 usces_register_action( 'page_logout', 'get', 'usces_page', 'logout', 'page_logout' );
3303 usces_register_action( 'page_lostmemberpassword', 'get', 'usces_page', 'lostmemberpassword', 'page_lostmemberpassword' );
3304 usces_register_action( 'lostpassword', 'request', 'lostpassword', null, 'lostpassword' );
3305 usces_register_action( 'uscesmode_changepassword', 'request', 'uscesmode', 'changepassword', 'uscesmode_changepassword' );
3306 usces_register_action( 'changepassword', 'request', 'changepassword', null, 'changepassword_page' );
3307 usces_register_action( 'page_newmember', 'get', 'usces_page', 'newmember', 'page_newmember' );
3308 usces_register_action( 'page_search_item', 'get', 'usces_page', 'search_item', 'page_search_item' );
3309 usces_register_action( 'front_ajax', 'post', 'usces_ajax_action', null, 'front_ajax' );
3310 }
3311
3312 public function ad_controller() {
3313 global $usces_action;
3314 ksort( $usces_action );
3315 if ( $this->is_maintenance() && ! is_user_logged_in() ) {
3316 $this->maintenance();
3317 } else {
3318 $action_array = array(
3319 'inCart', 'upButton', 'delButton', 'backCart', 'customerinfo', 'backCustomer',
3320 'customerlogin', 'reganddeliveryinfo', 'deliveryinfo', 'backDelivery', 'confirm', 'use_point',
3321 'backConfirm', 'purchase', 'acting_return', 'settlement_epsilon', 'inquiry_button', 'member_login',
3322 'regmember', 'editmember', 'deletemember', 'page_login', 'page_logout', 'page_lostmemberpassword', 'lostpassword',
3323 'uscesmode_changepassword', 'changepassword', 'page_newmember',
3324 'page_search_item', 'front_ajax',
3325 );
3326
3327 $action_array = apply_filters( 'usces_filter_action_array', $action_array );
3328
3329 $flg = 0;
3330 $res = true;
3331 foreach ( $usces_action as $handle => $action ) {
3332 extract( $action );
3333 switch ( $type ) {
3334 case 'post':
3335 if ( empty( $value ) ) {
3336 if ( isset( $_POST[ $key ] ) ) {
3337 if ( in_array( $handle, $action_array ) ) {
3338 $res = call_user_func( array( $this, $function ) );
3339 } else {
3340 $res = call_user_func( $function );
3341 }
3342 $flg = 1;
3343 }
3344 } else {
3345 if ( isset( $_POST[ $key ] ) && $_POST[ $key ] == $value ) {
3346 if ( in_array( $handle, $action_array ) ) {
3347 $res = call_user_func( array( $this, $function ) );
3348 } else {
3349 $res = call_user_func( $function );
3350 }
3351 $flg = 1;
3352 }
3353 }
3354 break;
3355 case 'get':
3356 if ( empty( $value ) ) {
3357 if ( isset( $_GET[ $key ] ) ) {
3358 if ( in_array( $handle, $action_array ) ) {
3359 $res = call_user_func( array( $this, $function ) );
3360 } else {
3361 $res = call_user_func( $function );
3362 }
3363 $flg = 1;
3364 }
3365 } else {
3366 if ( isset( $_GET[ $key ] ) && $_GET[ $key ] == $value ) {
3367 if ( in_array( $handle, $action_array ) ) {
3368 $res = call_user_func( array( $this, $function ) );
3369 } else {
3370 $res = call_user_func( $function );
3371 }
3372 $flg = 1;
3373 }
3374 }
3375 break;
3376 case 'request':
3377 if ( empty( $value ) ) {
3378 if ( isset( $_REQUEST[ $key ] ) ) {
3379 if ( in_array( $handle, $action_array ) ) {
3380 $res = call_user_func( array( $this, $function ) );
3381 } else {
3382 $res = call_user_func( $function );
3383 }
3384 $flg = 1;
3385 }
3386 } else {
3387 if ( isset( $_REQUEST[ $key ] ) && $_REQUEST[ $key ] == $value ) {
3388 if ( in_array( $handle, $action_array ) ) {
3389 $res = call_user_func( array( $this, $function ) );
3390 } else {
3391 $res = call_user_func( $function );
3392 }
3393 $flg = 1;
3394 }
3395 }
3396 break;
3397 }
3398 if ( ! $res ) {
3399 break;
3400 }
3401 }
3402 if ( ! $flg ) {
3403 $this->default_page();
3404 }
3405 }
3406 }
3407
3408 /**
3409 * Action function.
3410 */
3411 public function front_ajax() {
3412 switch ( $_POST['usces_ajax_action'] ) {
3413 case 'change_states':
3414 change_states_ajax();
3415 break;
3416 }
3417 do_action( 'usces_front_ajax' );
3418 }
3419
3420 public function maintenance() {
3421 $this->page = 'maintenance';
3422 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3423 }
3424
3425 public function inCart() {
3426 global $wp_query;
3427 $this->page = 'cart';
3428 $this->incart_check();
3429 $this->cart->inCart();
3430 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3431 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3432 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3433 }
3434
3435 public function upButton() {
3436 global $wp_query;
3437 $this->page = 'cart';
3438 $this->error_message = $this->cart->upCart();
3439 if ( empty( $this->error_message ) ) {
3440 $this->error_message = $this->zaiko_check();
3441 }
3442 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3443 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3444 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3445 }
3446
3447 public function delButton() {
3448 global $wp_query;
3449 $this->page = 'cart';
3450 $this->cart->del_row();
3451 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3452 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3453 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3454 }
3455
3456 public function backCart() {
3457 global $wp_query;
3458 $this->page = 'cart';
3459 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3460 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3461 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3462 }
3463
3464 public function customerinfo() {
3465 global $wp_query;
3466 if ( false === $this->cart->num_row() ) {
3467 header( 'location: ' . get_option( 'home' ) );
3468 exit;
3469 }
3470 do_action( 'usces_action_customerinfo' );
3471 $this->cart->entry();
3472 $this->error_message = $this->zaiko_check();
3473 $this->error_message = apply_filters( 'usces_filter_cart_check', $this->error_message );
3474 if ( WCUtils::is_blank( $this->error_message ) ) {
3475 if ( $this->is_member_logged_in() ) {
3476 $this->error_message = has_custom_customer_field_essential();
3477 $this->page = ( WCUtils::is_blank( $this->error_message ) ) ? 'delivery' : 'customer';
3478 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_delivery' );
3479 } else {
3480 $this->page = 'customer';
3481 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_customer' );
3482 }
3483 } else {
3484 $this->page = 'cart';
3485 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3486 }
3487 if ( ! $this->cart->is_order_condition() ) {
3488 $order_conditions = $this->get_condition();
3489 $this->cart->set_order_condition( $order_conditions );
3490 }
3491 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3492 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3493 }
3494
3495 public function backCustomer() {
3496 global $wp_query;
3497 if ( false === $this->cart->num_row() ) {
3498 header( 'location: ' . get_option( 'home' ) );
3499 exit;
3500 }
3501 $this->page = apply_filters( 'usces_filter_backCustomer_page', 'customer' );
3502 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3503 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_customer' );
3504 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3505 }
3506
3507 public function customerlogin() {
3508 global $wp_query;
3509 if ( false === $this->cart->num_row() ) {
3510 header( 'location: ' . get_option( 'home' ) );
3511 exit;
3512 }
3513 if ( 'member' == $this->member_login() ) {
3514 do_action( 'usces_action_member_customer_logined' );
3515 $this->cart->entry();
3516 // $this->error_message = has_custom_customer_field_essential();
3517 if ( WCUtils::is_blank( $this->error_message ) ) {
3518 $this->page = 'delivery';
3519 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_delivery' );
3520 } else {
3521 $this->page = 'customer';
3522 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_customer' );
3523 }
3524 } else {
3525 $this->cart->entry();
3526 $this->page = 'customer';
3527 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_customer' );
3528 }
3529 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3530 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3531 }
3532
3533 public function reganddeliveryinfo() {
3534 global $wp_query;
3535 if ( false === $this->cart->num_row() ) {
3536 header( 'location: ' . get_option( 'home' ) );
3537 exit;
3538 }
3539
3540 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
3541 $noncekey = 'post_member' . $this->get_uscesid( false );
3542 if ( ! wp_verify_nonce( $nonce, $noncekey ) && ! $this->is_member_logged_in() ) {
3543 die( 'Security check2' );
3544 }
3545 $check_verify_recaptcha = $this->verifyGoogleRecapcha();
3546 if ( $check_verify_recaptcha ) {
3547 $this->cart->entry();
3548 if ( empty( $_POST['member_regmode'] ) || 'editmemberfromcart' != $_POST['member_regmode'] ) {
3549 $_POST['member_regmode'] = 'newmemberfromcart';
3550 }
3551 $res = $this->regist_member();
3552 } else {
3553 // return back page register and show message.
3554 $this->error_message = apply_filters( 'usces_filter_check_verify_recaptcha_message', __( 'Failed to register member. Please try again.', 'usces' ), 'reganddeliveryinfo' );
3555 $res = trim( $_POST['member_regmode'] );
3556 }
3557
3558 if ( 'newcompletion' == $res ) {
3559 $this->page = 'delivery';
3560 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_delivery' );
3561 } elseif ( 'cartverifying' == $res ) {
3562 $this->page = 'cartverifying';
3563 } else {
3564 $this->page = 'customer';
3565 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_customer' );
3566 }
3567 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3568 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3569 }
3570
3571 public function deliveryinfo() {
3572 global $wp_query;
3573 if ( false === $this->cart->num_row() ) {
3574 header( 'location: ' . get_option( 'home' ) );
3575 exit;
3576 }
3577 $check_verify_recaptcha = $this->verifyGoogleRecapcha();
3578 if ( $check_verify_recaptcha ) {
3579 // continue process.
3580 $this->cart->entry();
3581 $this->error_message = $this->customer_check();
3582 } else {
3583 // return back page register and show message.
3584 $this->error_message = apply_filters( 'usces_filter_check_verify_recaptcha_message', __( 'Could not send successfully. Please try again.', 'usces' ), 'deliveryinfo' );
3585 }
3586
3587 if ( WCUtils::is_blank( $this->error_message ) ) {
3588 $this->page = 'delivery';
3589 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_delivery' );
3590 } else {
3591 $this->page = 'customer';
3592 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_customer' );
3593 }
3594 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3595 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3596 }
3597
3598 public function backDelivery() {
3599 global $wp_query;
3600 if ( false === $this->cart->num_row() ) {
3601 header( 'location: ' . get_option( 'home' ) );
3602 exit;
3603 }
3604 $this->page = 'delivery';
3605 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_delivery' );
3606 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3607 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3608 }
3609
3610 public function confirm() {
3611 global $wpdb, $wp_query;
3612 if ( false === $this->cart->num_row() ) {
3613 header( 'location: ' . get_option( 'home' ) );
3614 exit;
3615 }
3616
3617 $check_verify_recaptcha = $this->verifyGoogleRecapcha();
3618 if ( $check_verify_recaptcha ) {
3619 // continue process.
3620 $this->cart->entry();
3621 $this->error_message = $this->zaiko_check();
3622 } else {
3623 // return back page register and show message.
3624 $this->error_message = apply_filters( 'usces_filter_check_verify_recaptcha_message', __( 'Could not send successfully. Please try again.', 'usces' ), 'confirm' );
3625 }
3626
3627 if ( '' != $this->error_message ) {
3628 $this->page = 'cart';
3629 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3630 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3631 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3632 return;
3633 }
3634 /*
3635 $referrer = wp_get_referer();
3636 $site_url = parse_url( home_url(), PHP_URL_HOST );
3637 $referrer_host = parse_url( $referrer, PHP_URL_HOST );
3638 if ( false === $referrer || $referrer_host !== $site_url ) {
3639 $this->page = 'cart';
3640 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3641 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3642 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3643 return;
3644 }
3645 */
3646 $this->set_reserve_pre_order_id();
3647 if ( isset( $_POST['confirm'] ) ) {
3648 $this->error_message = $this->delivery_check();
3649 }
3650 $this->page = ( WCUtils::is_blank( $this->error_message ) ) ? 'confirm' : 'delivery';
3651 if ( WCUtils::is_blank( $this->error_message ) ) {
3652 if ( usces_is_member_system() && usces_is_member_system_point() && $this->is_member_logged_in() ) {
3653 $member_table = usces_get_tablename( 'usces_member' );
3654 $query = $wpdb->prepare( "SELECT mem_point FROM $member_table WHERE ID = %d", $_SESSION['usces_member']['ID'] );
3655 $mem_point = $wpdb->get_var( $query );
3656 $_SESSION['usces_member']['point'] = $mem_point;
3657 }
3658 $this->page = 'confirm';
3659 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_confirm' );
3660 } else {
3661 $this->page = apply_filters( 'usces_filter_delivery_check_error_page', 'delivery', $this->error_message );
3662 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_delivery' );
3663 }
3664 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3665 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3666 }
3667
3668 public function use_point() {
3669 global $wp_query, $usces;
3670 $noncekey = 'use_point' . $usces->get_uscesid( false );
3671
3672 if ( ! isset( $_REQUEST['wc_nonce'] ) || ! wp_verify_nonce( $_REQUEST['wc_nonce'], $noncekey ) ) {
3673 die( 'Security check1' );
3674 }
3675
3676 $this->error_message = $this->point_check( $this->cart->get_entry() );
3677 if ( empty( $this->error_message ) ) {
3678 $this->cart->entry();
3679 }
3680 $this->page = 'confirm';
3681 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_confirm' );
3682 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3683 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3684 }
3685
3686 public function backConfirm() {
3687 global $wp_query;
3688 if ( false === $this->cart->num_row() ) {
3689 header( 'location: ' . get_option( 'home' ) );
3690 exit;
3691 }
3692 $this->page = 'confirm';
3693 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_confirm' );
3694 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3695 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3696 }
3697
3698 /**
3699 * Purchase
3700 */
3701 public function purchase() {
3702 global $wp_query;
3703 do_action( 'usces_pre_purchase' );
3704 if ( false === $this->cart->num_row() ) {
3705 header( 'location: ' . get_option( 'home' ) );
3706 exit;
3707 }
3708
3709 if ( isset( $_POST['wc_purchase_nonce'] ) ) {
3710 if ( ! wp_verify_nonce( $_POST['wc_purchase_nonce'], 'wc_purchase_nonce' ) ) {
3711 $this->error_message = __( 'Security check failed. Please try again.', 'usces' );
3712 $this->page = 'confirm';
3713 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3714 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3715 return;
3716 }
3717 }
3718
3719 if ( ! apply_filters( 'usces_purchase_check', true ) ) {
3720 return;
3721 }
3722
3723 do_action( 'usces_purchase_validate' );
3724
3725 $entry = $this->cart->get_entry();
3726 $this->error_message = $this->zaiko_check();
3727 if ( WCUtils::is_blank( $this->error_message ) && 0 < $this->cart->num_row() ) {
3728 $acting_status = '';
3729 $payments = $this->getPayments( $entry['order']['payment_name'] );
3730 if ( null === $payments['id'] && 0 < $entry['order']['total_full_price'] ) {
3731 header( 'HTTP/1.0 400 Bad request' );
3732 die();
3733 }
3734 $payment_settlement = $payments['settlement'] ?? '';
3735 if ( substr( $payment_settlement, 0, 6 ) == 'acting' && $entry['order']['total_full_price'] > 0 ) {
3736 $acting_flg = ( 'acting' == $payment_settlement ) ? $payments['module'] : $payment_settlement;
3737 unset( $_POST['purchase'] );
3738 $post_query = '&' . http_build_query( $_POST );
3739 $acting_status = $this->acting_processing( $acting_flg, $post_query, $acting_status );
3740 }
3741
3742 if ( 'error' == $acting_status ) {
3743 $this->page = 'error';
3744 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_error' );
3745 } else {
3746 $res = $this->order_processing();
3747 if ( 'ordercompletion' == $res ) {
3748 $this->page = 'ordercompletion';
3749 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_ordercompletion' );
3750 } else {
3751 $this->page = 'error';
3752 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_error' );
3753 }
3754 }
3755 } else {
3756 $this->page = 'cart';
3757 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3758 if ( ! $this->is_cart_page( $_SERVER['REQUEST_URI'] ) ) {
3759 wp_redirect( USCES_CART_URL );
3760 exit;
3761 }
3762 }
3763 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3764 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3765 }
3766
3767 public function acting_return() {
3768 global $wp_query;
3769
3770 do_action( 'usces_pre_acting_return' );
3771
3772 $entry = $this->cart->get_entry();
3773 if ( isset( $_GET['acting'] ) && 'anotherlane_card' != $_GET['acting'] ) {
3774 if ( false === $this->cart->num_row() && ( 'paypal' != $_GET['acting'] && 1 !== (int) $_GET['acting_return'] ) ) {
3775 header( 'location: ' . get_option( 'home' ) );
3776 exit;
3777 }
3778 }
3779
3780 $this->payment_results = usces_check_acting_return();
3781
3782 if ( isset( $this->payment_results[0] ) && 'duplicate' === $this->payment_results[0] ) {
3783
3784 header( 'location: ' . get_option( 'home' ) );
3785 exit;
3786
3787 } elseif ( isset( $this->payment_results[0] ) && $this->payment_results[0] ) { // result OK.
3788
3789 if ( ! $this->payment_results['reg_order'] ) { // without Registration Order.
3790 $this->page = 'ordercompletion';
3791 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_ordercompletion' );
3792
3793 } else {
3794 $res = $this->order_processing( $this->payment_results );
3795
3796 if ( 'ordercompletion' == $res ) {
3797 $this->page = 'ordercompletion';
3798 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_ordercompletion' );
3799 } else {
3800 $this->page = 'error';
3801 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_error' );
3802 }
3803 }
3804
3805 } else { // result NG.
3806 $this->page = 'error';
3807 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_error' );
3808 }
3809
3810 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3811 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3812 }
3813
3814 public function settlement_epsilon() {
3815 global $wp_query;
3816 require_once $this->options['settlement_path'] . 'epsilon.php';
3817 }
3818
3819 public function inquiry_button() {
3820 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'] ) ) {
3821 $res = $this->inquiry_processing();
3822 } else {
3823 $res = 'deficiency';
3824 }
3825
3826 $this->page = $res;
3827 }
3828
3829 public function member_login_page() {
3830 global $wp_query;
3831 if ( ! class_exists( 'RateLimiter' ) ) {
3832 require USCES_PLUGIN_DIR . '/classes/rateLimiter.class.php';
3833 }
3834 $rateLimiter = new RateLimiter();
3835 if ( $rateLimiter->checkBlockIP() ) {
3836 $wp_query->set_403();
3837 status_header( 403 );
3838 exit();
3839 }
3840
3841 if ( isset( $_GET['redirect_to'] ) ) {
3842 $_SESSION['redirect_to'] = $_GET['redirect_to'];
3843 }
3844
3845 $res = $this->member_login();
3846 if ( 'member' == $res ) {
3847 $this->page = 'member';
3848 do_action( 'usces_action_member_logined' );
3849
3850 if ( isset( $_SESSION['redirect_to'] ) ) {
3851 if ( wp_safe_redirect( esc_url( $_SESSION['redirect_to'] ) ) ) {
3852 unset( $_SESSION['redirect_to'] );
3853 exit;
3854 }
3855 }
3856
3857 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_member' );
3858 } elseif ( 'login' == $res ) {
3859 $this->page = 'login';
3860 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_login' );
3861 }
3862 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3863 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3864 }
3865
3866 public function regmember() {
3867 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
3868 $noncekey = 'post_member' . $this->get_uscesid( false );
3869 if ( ! wp_verify_nonce( $nonce, $noncekey ) ) {
3870 die( 'Security check2' );
3871 }
3872
3873 $check_verify_recaptcha = $this->verifyGoogleRecapcha();
3874 if ( $check_verify_recaptcha ) {
3875 // continue register form.
3876 global $wp_query;
3877 $res = $this->regist_member();
3878 } else {
3879 // return back page register and show message.
3880 $this->error_message = apply_filters( 'usces_filter_check_verify_recaptcha_message', __( 'Failed to register member. Please try again.', 'usces' ), 'regmember' );
3881 $res = trim( $_POST['member_regmode'] );
3882 }
3883
3884 if ( 'editmemberform' == $res ) {
3885 $this->page = 'editmemberform';
3886 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_editmemberform' );
3887 } elseif ( 'newcompletion' == $res ) {
3888 $this->page = 'newcompletion';
3889 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_newcompletion' );
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 editmember() {
3898 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
3899 $noncekey = 'post_member' . $this->get_uscesid( false );
3900 if ( ! wp_verify_nonce( $nonce, $noncekey ) ) {
3901 die( 'Security check3' );
3902 }
3903
3904 global $wp_query;
3905 $res = $this->regist_member();
3906 if ( 'editmemberform' == $res ) {
3907 $this->page = 'editmemberform';
3908 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_editmemberform' );
3909 } elseif ( 'newcompletion' == $res ) {
3910 $this->page = 'newcompletion';
3911 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_newcompletion' );
3912 } elseif ( 'updatememberform' == $res ) {
3913 $this->page = 'member_edit';
3914 } else {
3915 $this->page = $res;
3916 }
3917 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3918 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3919 }
3920
3921 public function deletemember() {
3922 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
3923 $noncekey = 'post_member' . $this->get_uscesid( false );
3924 if ( ! wp_verify_nonce( $nonce, $noncekey ) ) {
3925 die( 'Security check4' );
3926 }
3927
3928 $res = $this->delete_member();
3929 if ( $res ) {
3930 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_deletemember' );
3931 $this->member_logout();
3932 } else {
3933 $this->page = 'editmemberform';
3934 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3935 }
3936 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3937 }
3938
3939 public function page_logout() {
3940 global $wp_query;
3941 $this->member_logout();
3942 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3943 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3944 }
3945
3946 public function page_lostmemberpassword() {
3947 global $wp_query;
3948 $this->page = 'lostmemberpassword';
3949 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3950 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3951 }
3952
3953 public function lostpassword() {
3954 global $usces, $wp_query;
3955
3956 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
3957 $noncekey = 'post_member' . $usces->get_uscesid( false );
3958 if ( ! wp_verify_nonce( $nonce, $noncekey ) ) {
3959 $wp_query->set_403();
3960 status_header( 403 );
3961 exit();
3962 }
3963
3964 $this->error_message = $this->lostpass_mailaddcheck();
3965 if ( '' != $this->error_message ) {
3966 $this->page = 'lostmemberpassword';
3967 } else {
3968 $res = $this->lostmail();
3969 $this->page = $res; // 'lostcompletion';.
3970 }
3971 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3972 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3973 }
3974
3975 public function uscesmode_changepassword() {
3976 global $wp_query;
3977
3978 if ( ! isset( $_REQUEST['mem'] ) || ! isset( $_REQUEST['key'] ) ) {
3979 die( 'Invalid request 1' );
3980 }
3981
3982 $mem_mail = $_REQUEST['mem'];
3983 $lostkey = $_REQUEST['key'];
3984 $res = usces_check_lostkey( $mem_mail, $lostkey );
3985 if ( empty( $res ) ) {
3986 die( 'Invalid request 2' );
3987 }
3988
3989 $this->page = 'changepassword';
3990 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3991 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3992 }
3993
3994 public function changepassword_page() {
3995 global $usces;
3996
3997 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
3998 $noncekey = 'post_member' . $usces->get_uscesid( false );
3999 if ( ! wp_verify_nonce( $nonce, $noncekey ) ) {
4000 die( 'Security check6' );
4001 }
4002
4003 $lostmail = $_POST['mem'];
4004 $lostkey = $_POST['key'];
4005 $res = usces_check_lostkey( $lostmail, $lostkey );
4006 if ( empty( $res ) ) {
4007 die( 'Invalid request 7' );
4008 }
4009
4010 global $wp_query;
4011 $this->error_message = $this->changepass_check();
4012 if ( '' != $this->error_message ) {
4013 $this->page = 'changepassword';
4014 } else {
4015 $res = $this->changepassword();
4016 $this->page = $res; // 'changepasscompletion';.
4017 }
4018 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
4019 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
4020 }
4021
4022 public function page_newmember() {
4023 global $wp_query;
4024 $this->page = 'newmemberform';
4025 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_newmemberform' );
4026 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
4027 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
4028 }
4029
4030 public function page_search_item() {
4031 global $wp_query;
4032 $this->page = 'search_item';
4033 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
4034 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
4035 }
4036
4037 public function default_page() {
4038 global $wp_query;
4039 add_action( 'the_post', array( $this, 'goDefaultPage' ) );
4040 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
4041 }
4042
4043 public function verifyGoogleRecapcha() {
4044 // check google re-captcha v3.
4045 $option = get_option( 'usces_ex' );
4046 $is_human = true;
4047 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'] ) ) ) {
4048 if ( isset( $_POST['recaptcha_response'] ) ) {
4049 $secret = isset( $option['system']['google_recaptcha']['secret_key'] ) ? $option['system']['google_recaptcha']['secret_key'] : '';
4050 $token = trim( $_POST['recaptcha_response'] );
4051 $is_human = $this->google_recaptcha_v3_response( $token, $secret );
4052 }
4053 }
4054 return $is_human;
4055 }
4056
4057 /**
4058 * Handle check google recaptcha v3 response.
4059 *
4060 * @param string $token string token.
4061 * @param string $secret string secret key config.
4062 *
4063 * @return boolean $is_human.
4064 */
4065 public function google_recaptcha_v3_response( $token, $secret ) {
4066 $is_human = true;
4067 if ( empty( $token ) || empty( $secret ) ) {
4068 return $is_human;
4069 }
4070 $option = get_option( 'usces_ex' );
4071 $threshold = isset( $option['system']['google_recaptcha']['score'] ) ? $option['system']['google_recaptcha']['score'] : 0.5;
4072
4073 $endpoint = 'https://www.google.com/recaptcha/api/siteverify';
4074 $request = array(
4075 'body' => array(
4076 'secret' => $secret,
4077 'response' => $token,
4078 ),
4079 );
4080
4081 $response = wp_remote_post( esc_url_raw( $endpoint ), $request );
4082
4083 if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
4084 update_option( 'usces_recaptcha_condition', 'response_NG' );
4085 return $is_human;
4086 } else {
4087 update_option( 'usces_recaptcha_condition', 'response_OK' );
4088 }
4089
4090 $response_body = wp_remote_retrieve_body( $response );
4091 $response_body = json_decode( $response_body, true );
4092
4093 $action = isset( $response_body['action'] ) ? $response_body['action'] : '';
4094 $actions = array(
4095 'create_new_member',
4096 'customer_order_page',
4097 'delivery_order_page',
4098 'member_register_settlement',
4099 'member_update_settlement',
4100 );
4101 if ( ! $response_body['success'] || ! in_array( $action, $actions ) ) {
4102 update_option( 'usces_recaptcha_condition', 'response_ERROR' );
4103 return $is_human;
4104 } else {
4105 update_option( 'usces_recaptcha_condition', 'response_OK' );
4106 }
4107 $score = isset( $response_body['score'] ) ? $response_body['score'] : 0;
4108 $is_human = $threshold <= $score;
4109 return $is_human;
4110 }
4111
4112 public function goDefaultPage() {
4113 global $post;
4114
4115 if ( is_object( $post ) && null !== $post && (int) $post->ID === (int) USCES_CART_NUMBER ) {
4116
4117 $this->page = 'cart';
4118 add_filter( 'the_content', array( $this, 'filter_cartContent' ), 20 );
4119
4120 } elseif ( is_object( $post ) && null !== $post && (int) $post->ID === (int) USCES_MEMBER_NUMBER ) {
4121
4122 $this->page = 'member';
4123
4124 if ( $this->is_member_logged_in() ) {
4125 $this->get_current_member();
4126 $this->set_member_session_data( $this->current_member['id'] );
4127 $this->page = 'member';
4128 } else {
4129 $this->page = 'login';
4130 }
4131 add_filter( 'the_content', array( $this, 'filter_memberContent' ), 20 );
4132 add_filter( 'the_title', array( $this, 'filter_memberTitle' ), 20 );
4133
4134 } elseif ( ! is_singular() ) {
4135 $this->page = 'wp_search';
4136 add_filter( 'the_excerpt', array( $this, 'filter_cartContent' ), 20 );
4137 add_filter( 'the_content', array( $this, 'filter_cartContent' ), 20 );
4138
4139 } else {
4140 add_filter( 'the_content', array( &$this, 'filter_itemPage' ) );
4141 }
4142 }
4143
4144 public function template_redirect() {
4145 global $wpdb, $wp_version, $post, $usces_entries, $usces_carts, $usces_members, $usces_gp, $member_regmode;
4146
4147 if ( version_compare( $wp_version, '4.4-beta', '>' ) && is_embed() ) {
4148 return;
4149 }
4150
4151 if ( $this->is_cart_page( $_SERVER['REQUEST_URI'] ) ) {
4152 if ( '' == $this->page && empty( $this->error_message ) ) {
4153 $this->error_message = $this->zaiko_check();
4154 if ( $this->error_message ) {
4155 $this->page = 'cart';
4156 }
4157 }
4158 }
4159
4160 if ( apply_filters( 'usces_action_template_redirect', false ) ) {
4161 return; // Deprecated.
4162 }
4163 if ( apply_filters( 'usces_filter_template_redirect', false ) ) {
4164 return;
4165 }
4166
4167 $parent_path = get_template_directory() . '/wc_templates';
4168 $child_path = get_stylesheet_directory() . '/wc_templates';
4169
4170 if ( is_single() && is_object( $post ) && 'item' === $post->post_mime_type ) {
4171
4172 if ( file_exists( $child_path . '/wc_item_single.php' ) ) {
4173 if ( ! post_password_required( $post ) ) {
4174 include $child_path . '/wc_item_single.php';
4175 exit;
4176 }
4177 } elseif ( file_exists( $parent_path . '/wc_item_single.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4178 if ( ! post_password_required( $post ) ) {
4179 include $parent_path . '/wc_item_single.php';
4180 exit;
4181 }
4182 }
4183
4184 } elseif ( isset( $_REQUEST['usces_page'] ) && ( 'search_item' == $_REQUEST['usces_page'] || 'usces_search' == $_REQUEST['usces_page'] ) && $this->is_cart_page( $_SERVER['REQUEST_URI'] ) ) {
4185
4186 if ( file_exists( $child_path . '/wc_search_page.php' ) ) {
4187 include $child_path . '/wc_search_page.php';
4188 exit;
4189 } elseif ( file_exists( $parent_path . '/wc_search_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4190 include $parent_path . '/wc_search_page.php';
4191 exit;
4192 }
4193
4194 } elseif ( $this->is_cart_page( $_SERVER['REQUEST_URI'] ) ) {
4195
4196 switch ( $this->page ) {
4197
4198 case 'customer':
4199 if ( file_exists( $child_path . '/cart/wc_customer_page.php' ) ) {
4200 usces_get_entries();
4201 usces_get_member_regmode();
4202 include $child_path . '/cart/wc_customer_page.php';
4203 exit;
4204 } elseif ( file_exists( $parent_path . '/cart/wc_customer_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4205 usces_get_entries();
4206 usces_get_member_regmode();
4207 include $parent_path . '/cart/wc_customer_page.php';
4208 exit;
4209 }
4210 break;
4211
4212 case 'delivery':
4213 if ( file_exists( $child_path . '/cart/wc_delivery_page.php' ) ) {
4214 usces_get_entries();
4215 usces_get_carts();
4216 include $child_path . '/cart/wc_delivery_page.php';
4217 exit;
4218 } elseif ( file_exists( $parent_path . '/cart/wc_delivery_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4219 usces_get_entries();
4220 usces_get_carts();
4221 include $parent_path . '/cart/wc_delivery_page.php';
4222 exit;
4223 }
4224 break;
4225
4226 case 'confirm':
4227 if ( file_exists( $child_path . '/cart/wc_confirm_page.php' ) ) {
4228 usces_get_entries();
4229 usces_get_carts();
4230 usces_get_members();
4231 include $child_path . '/cart/wc_confirm_page.php';
4232 exit;
4233 } elseif ( file_exists( $parent_path . '/cart/wc_confirm_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4234 usces_get_entries();
4235 usces_get_carts();
4236 usces_get_members();
4237 include $parent_path . '/cart/wc_confirm_page.php';
4238 exit;
4239 }
4240 break;
4241
4242 case 'ordercompletion':
4243 if ( file_exists( $child_path . '/cart/wc_completion_page.php' ) ) {
4244 usces_get_entries();
4245 usces_get_carts();
4246 include $child_path . '/cart/wc_completion_page.php';
4247 exit;
4248 } elseif ( file_exists( $parent_path . '/cart/wc_completion_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4249 usces_get_entries();
4250 usces_get_carts();
4251 include $parent_path . '/cart/wc_completion_page.php';
4252 exit;
4253 }
4254 break;
4255
4256 case 'error':
4257 if ( file_exists( $child_path . '/cart/wc_cart_error_page.php' ) ) {
4258 include $child_path . '/cart/wc_cart_error_page.php';
4259 exit;
4260 } elseif ( file_exists( $parent_path . '/cart/wc_cart_error_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4261 include $parent_path . '/cart/wc_cart_error_page.php';
4262 exit;
4263 }
4264 break;
4265
4266 case 'cart':
4267 default:
4268 $this->page = 'cart';
4269 if ( file_exists( $child_path . '/cart/wc_cart_page.php' ) ) {
4270 include $child_path . '/cart/wc_cart_page.php';
4271 exit;
4272 } elseif ( file_exists( $parent_path . '/cart/wc_cart_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4273 include $parent_path . '/cart/wc_cart_page.php';
4274 exit;
4275 }
4276 }
4277
4278 } elseif ( $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
4279
4280 } elseif ( $this->is_member_page( $_SERVER['REQUEST_URI'] ) ) {
4281 if ( 'activate' != $this->options['membersystem_state'] ) {
4282 return;
4283 }
4284
4285 if ( $this->is_member_logged_in() ) {
4286
4287 if ( isset( $_SESSION['usces_member'] ) ) {
4288 $member_table_name = usces_get_tablename( 'usces_member' );
4289 $this->get_current_member();
4290 $query = $wpdb->prepare( "SELECT mem_point FROM $member_table_name WHERE ID = %d", $this->current_member['id'] );
4291 $point = $wpdb->get_var( $query );
4292 $_SESSION['usces_member']['point'] = $point;
4293 }
4294
4295 $member_regmode = 'editmemberform';
4296 if ( file_exists( $child_path . '/member/wc_member_page.php' ) ) {
4297 include $child_path . '/member/wc_member_page.php';
4298 exit;
4299 } elseif ( file_exists( $parent_path . '/member/wc_member_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4300 include $parent_path . '/member/wc_member_page.php';
4301 exit;
4302 }
4303
4304 } else {
4305
4306 switch ( $this->page ) {
4307
4308 case 'login':
4309 if ( file_exists( $child_path . '/member/wc_login_page.php' ) ) {
4310 include $child_path . '/member/wc_login_page.php';
4311 exit;
4312 } elseif ( file_exists( $parent_path . '/member/wc_login_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4313 include $parent_path . '/member/wc_login_page.php';
4314 exit;
4315 }
4316 break;
4317
4318 case 'newmemberform':
4319 if ( file_exists( $child_path . '/member/wc_new_member_page.php' ) ) {
4320 $member_regmode = 'newmemberform';
4321 include $child_path . '/member/wc_new_member_page.php';
4322 exit;
4323 } elseif ( file_exists( $parent_path . '/member/wc_new_member_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4324 $member_regmode = 'newmemberform';
4325 include $parent_path . '/member/wc_new_member_page.php';
4326 exit;
4327 }
4328 break;
4329
4330 case 'lostmemberpassword':
4331 if ( file_exists( $child_path . '/member/wc_lostpassword_page.php' ) ) {
4332 include $child_path . '/member/wc_lostpassword_page.php';
4333 exit;
4334 } elseif ( file_exists( $parent_path . '/member/wc_lostpassword_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4335 include $parent_path . '/member/wc_lostpassword_page.php';
4336 exit;
4337 }
4338 break;
4339
4340 case 'changepassword':
4341 if ( file_exists( $child_path . '/member/wc_changepassword_page.php' ) ) {
4342 include $child_path . '/member/wc_changepassword_page.php';
4343 exit;
4344 } elseif ( file_exists( $parent_path . '/member/wc_changepassword_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4345 include $parent_path . '/member/wc_changepassword_page.php';
4346 exit;
4347 }
4348 break;
4349
4350 case 'newcompletion':
4351 case 'editcompletion':
4352 case 'lostcompletion':
4353 case 'changepasscompletion':
4354 if ( file_exists( $child_path . '/member/wc_member_completion_page.php' ) ) {
4355 include $child_path . '/member/wc_member_completion_page.php';
4356 exit;
4357 } elseif ( file_exists( $parent_path . '/member/wc_member_completion_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4358 include $parent_path . '/member/wc_member_completion_page.php';
4359 exit;
4360 }
4361 break;
4362
4363 default:
4364 $this->page = 'login';
4365 if ( file_exists( $child_path . '/member/wc_login_page.php' ) ) {
4366 include $child_path . '/member/wc_login_page.php';
4367 exit;
4368 } elseif ( file_exists( $parent_path . '/member/wc_login_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4369 include $parent_path . '/member/wc_login_page.php';
4370 exit;
4371 }
4372 }
4373 }
4374 }
4375 }
4376
4377 public function changepassword() {
4378 global $wpdb;
4379
4380 $lostmail = $_POST['mem'];
4381 $lost_key = $_POST['key'];
4382
4383 $member_table = usces_get_tablename( 'usces_member' );
4384 // $hash = usces_get_hash(trim($_POST['loginpass1']));
4385 $salt = usces_get_salt( $lostmail );
4386 $hash = usces_get_hash( trim( $_POST['loginpass1'] ), $salt );
4387 $query = $wpdb->prepare( "UPDATE $member_table SET mem_pass = %s WHERE mem_email = %s",
4388 $hash, $lostmail
4389 );
4390 $res = $wpdb->query( $query );
4391
4392 if ( $res === false ) {
4393 $this->error_message = __( 'Error: failure in updating password', 'usces' );
4394 return 'login';
4395 } else {
4396 usces_remove_lostmail_key( $lostmail, $lost_key );
4397 return 'changepasscompletion';
4398 }
4399 }
4400
4401 public function lostmail() {
4402 $delim = apply_filters( 'usces_filter_delim', $this->delim );
4403
4404 $lostmail = trim( $_POST['loginmail'] );
4405 if ( ! $this->is_member( $lostmail ) ) {
4406 return 'lostcompletion';
4407 }
4408
4409 $lost_key = usces_make_lost_key();
4410 usces_store_lostmail_key( $lostmail, $lost_key );
4411
4412 $uri = USCES_MEMBER_URL . $delim . 'uscesmode=changepassword&mem=' . urlencode( $lostmail ) . '&key=' . urlencode( $lost_key );
4413
4414 $res = usces_lostmail( $uri );
4415 return $res;
4416 }
4417
4418 public function regist_member() {
4419 global $wpdb;
4420
4421 $_POST = $this->stripslashes_deep_post( $_POST );
4422
4423 $member = $this->get_member();
4424 $mode = $_POST['member_regmode'];
4425 $member_table = usces_get_tablename( 'usces_member' );
4426 $member_meta_table = usces_get_tablename( 'usces_member_meta' );
4427
4428 $error_mes = ( 'newmemberfromcart' == $_POST['member_regmode'] || 'editmemberfromcart' == $_POST['member_regmode'] ) ? $this->member_check_fromcart() : $this->member_check();
4429
4430 if ( '' != $error_mes ) {
4431
4432 $this->error_message = $error_mes;
4433 return $mode;
4434
4435 } elseif ( 'editmemberform' == $_POST['member_regmode'] || 'updatememberform' == $_POST['member_regmode'] ) {
4436
4437 $this->get_current_member();
4438 $mem_id = $this->current_member['id'];
4439
4440 // $query = $wpdb->prepare("SELECT ID FROM $member_table WHERE mem_email = %s", trim($_POST['member']['mailaddress1']));
4441 // $id = $wpdb->get_var( $query );
4442 $id = $this->check_member_email( $_POST['member']['mailaddress1'] );
4443 if ( ! empty( $id ) && $id != $mem_id ) {
4444 // $this->error_message = __( 'This e-mail address has been already registered.', 'usces' );
4445 $this->error_message = __( 'This e-mail address can not be registered.', 'usces' );
4446 return $mode;
4447 }
4448
4449 do_action( 'usces_action_pre_edit_memberdata', $_POST['member'], $mem_id );
4450
4451 $query = $wpdb->prepare( "SELECT mem_pass FROM $member_table WHERE ID = %d", $mem_id );
4452 $pass = $wpdb->get_var( $query );
4453 // $password = ( !empty( $_POST['member']['password1']) && trim($_POST['member']['password1']) == trim($_POST['member']['password2']) ) ? usces_get_hash(trim($_POST['member']['password1'])) : $pass;
4454 if ( ! empty( $_POST['member']['password1'] ) && trim( $_POST['member']['password1'] ) == trim( $_POST['member']['password2'] ) ) {
4455 $salt = usces_get_salt( $mem_id );
4456 $password = usces_get_hash( trim( $_POST['member']['password1'] ), $salt );
4457 } else {
4458 $password = $pass;
4459 }
4460 $name1 = ( isset( $_POST['member']['name1'] ) ) ? trim( $_POST['member']['name1'] ) : '';
4461 $name2 = ( isset( $_POST['member']['name2'] ) ) ? trim( $_POST['member']['name2'] ) : '';
4462 $name3 = ( isset( $_POST['member']['name3'] ) ) ? trim( $_POST['member']['name3'] ) : '';
4463 $name4 = ( isset( $_POST['member']['name4'] ) ) ? trim( $_POST['member']['name4'] ) : '';
4464 $zipcode = ( isset( $_POST['member']['zipcode'] ) ) ? usces_convert_zipcode( trim( $_POST['member']['zipcode'] ) ) : '';
4465 $pref = ( isset( $_POST['member']['pref'] ) ) ? trim( $_POST['member']['pref'] ) : '';
4466 $address1 = ( isset( $_POST['member']['address1'] ) ) ? trim( $_POST['member']['address1'] ) : '';
4467 $address2 = ( isset( $_POST['member']['address2'] ) ) ? trim( $_POST['member']['address2'] ) : '';
4468 $address3 = ( isset( $_POST['member']['address3'] ) ) ? trim( $_POST['member']['address3'] ) : '';
4469 $tel = ( isset( $_POST['member']['tel'] ) ) ? trim( $_POST['member']['tel'] ) : '';
4470 $fax = ( isset( $_POST['member']['fax'] ) ) ? trim( $_POST['member']['fax'] ) : '';
4471 $country = ( isset( $_POST['member']['country'] ) ) ? trim( $_POST['member']['country'] ) : '';
4472
4473 $query = $wpdb->prepare(
4474 "UPDATE $member_table SET
4475 mem_pass = %s, mem_name1 = %s, mem_name2 = %s, mem_name3 = %s, mem_name4 = %s,
4476 mem_zip = %s, mem_pref = %s, mem_address1 = %s, mem_address2 = %s,
4477 mem_address3 = %s, mem_tel = %s, mem_fax = %s, mem_email = %s WHERE ID = %d",
4478 $password,
4479 $name1,
4480 $name2,
4481 $name3,
4482 $name4,
4483 $zipcode,
4484 $pref,
4485 $address1,
4486 $address2,
4487 $address3,
4488 $tel,
4489 $fax,
4490 trim( $_POST['member']['mailaddress1'] ),
4491 $mem_id
4492 );
4493 $res = $wpdb->query( $query );
4494
4495 if ( false !== $res ) {
4496 $this->set_member_meta_value( 'customer_country', $country, $mem_id );
4497 $res = $this->reg_custom_member( $mem_id );
4498 unset( $_SESSION['usces_entry']['custom_customer'] );
4499 $this->cart->entry();
4500 do_action( 'usces_action_edit_memberdata', $_POST['member'], $mem_id );
4501 $meta_keys = apply_filters( 'usces_filter_delete_member_pcid', "'remise_pcid', 'digitalcheck_ip_user_id'" );
4502 $query = $wpdb->prepare( "DELETE FROM $member_meta_table WHERE member_id = %d AND meta_key IN( $meta_keys )",
4503 $mem_id
4504 );
4505 $res = $wpdb->query( $query );
4506
4507 $user = $_POST['member'];
4508 $user['ID'] = $mem_id;
4509 usces_send_updmembermail( $user );
4510
4511 $this->get_current_member();
4512 // return 'editmemberform';
4513 return $mode;
4514
4515 } else {
4516 $this->error_message = __( 'Error:failure in update', 'usces' );
4517 return $mode;
4518 }
4519
4520 } elseif ( 'newmemberform' == $_POST['member_regmode'] ) {
4521 // $query = $wpdb->prepare("SELECT ID FROM $member_table WHERE mem_email = %s", trim( $_POST['member']['mailaddress1']));
4522 // $id = $wpdb->get_var( $query );
4523 $id = $this->check_member_email( $_POST['member']['mailaddress1'] );
4524 if ( ! empty( $id ) ) {
4525 // $this->error_message = __( 'This e-mail address has been already registered.', 'usces' );
4526 $this->error_message = __( 'This e-mail address can not be registered.', 'usces' );
4527 return $mode;
4528 } else {
4529 $point = $this->options['start_point'];
4530 // $pass = usces_get_hash(trim($_POST['member']['password1']));
4531 $salt = usces_get_salt( '', 1 );
4532 $pass = usces_get_hash( trim( $_POST['member']['password1'] ), $salt );
4533 $name1 = ( isset( $_POST['member']['name1'] ) ) ? trim( $_POST['member']['name1'] ) : '';
4534 $name2 = ( isset( $_POST['member']['name2'] ) ) ? trim( $_POST['member']['name2'] ) : '';
4535 $name3 = ( isset( $_POST['member']['name3'] ) ) ? trim( $_POST['member']['name3'] ) : '';
4536 $name4 = ( isset( $_POST['member']['name4'] ) ) ? trim( $_POST['member']['name4'] ) : '';
4537 $zipcode = ( isset( $_POST['member']['zipcode'] ) ) ? usces_convert_zipcode( trim( $_POST['member']['zipcode'] ) ) : '';
4538 $pref = ( isset( $_POST['member']['pref'] ) ) ? trim( $_POST['member']['pref'] ) : '';
4539 $address1 = ( isset( $_POST['member']['address1'] ) ) ? trim( $_POST['member']['address1'] ) : '';
4540 $address2 = ( isset( $_POST['member']['address2'] ) ) ? trim( $_POST['member']['address2'] ) : '';
4541 $address3 = ( isset( $_POST['member']['address3'] ) ) ? trim( $_POST['member']['address3'] ) : '';
4542 $tel = ( isset( $_POST['member']['tel'] ) ) ? trim( $_POST['member']['tel'] ) : '';
4543 $fax = ( isset( $_POST['member']['fax'] ) ) ? trim( $_POST['member']['fax'] ) : '';
4544 $country = ( isset( $_POST['member']['country'] ) ) ? trim( $_POST['member']['country'] ) : '';
4545
4546 $query = $wpdb->prepare(
4547 "INSERT INTO $member_table
4548 (mem_email, mem_pass, mem_status, mem_cookie, mem_point,
4549 mem_name1, mem_name2, mem_name3, mem_name4, mem_zip, mem_pref,
4550 mem_address1, mem_address2, mem_address3, mem_tel, mem_fax,
4551 mem_delivery_flag, mem_delivery, mem_registered, mem_nicename)
4552 VALUES (%s, %s, %d, %s, %d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s)",
4553 trim( $_POST['member']['mailaddress1'] ),
4554 $pass,
4555 0,
4556 '',
4557 $point,
4558 $name1,
4559 $name2,
4560 $name3,
4561 $name4,
4562 $zipcode,
4563 $pref,
4564 $address1,
4565 $address2,
4566 $address3,
4567 $tel,
4568 $fax,
4569 '',
4570 '',
4571 get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ),
4572 ''
4573 );
4574 $res = $wpdb->query( $query );
4575
4576 if ( false !== $res ) {
4577 $user = $_POST['member'];
4578 $user['ID'] = $wpdb->insert_id;
4579 $this->set_member_meta_value( 'customer_country', $country, $user['ID'] );
4580
4581 if ( ! empty( $salt ) ) {
4582 $this->set_member_meta_value( 'mem_salt', $salt, $user['ID'] );
4583 }
4584
4585 $res = $this->reg_custom_member( $user['ID'] );
4586
4587 if ( apply_filters( 'usces_filter_veirfyemail_newmemberform', false, $user ) ) {
4588 return 'memberverifying';
4589 }
4590
4591 do_action( 'usces_action_member_registered', $_POST['member'], $user['ID'] );
4592 unset( $_SESSION['usces_member'] );
4593 usces_send_regmembermail( $user );
4594 return 'newcompletion';
4595
4596 } else {
4597 $this->error_message = __( 'Error:failure in update', 'usces' );
4598 return $mode;
4599 }
4600 }
4601
4602 } elseif ( 'newmemberfromcart' == $_POST['member_regmode'] ) {
4603
4604 // $query = $wpdb->prepare("SELECT ID FROM $member_table WHERE mem_email = %s", trim($_POST['customer']['mailaddress1']));
4605 // $id = $wpdb->get_var( $query );
4606 $id = $this->check_member_email( $_POST['customer']['mailaddress1'] );
4607 if ( ! empty( $id ) ) {
4608 // $this->error_message = __( 'This e-mail address has been already registered.', 'usces' );
4609 $this->error_message = __( 'This e-mail address can not be registered.', 'usces' );
4610 return $mode;
4611 } else {
4612 $point = $this->options['start_point'];
4613 // $pass = usces_get_hash(trim( $_POST['customer']['password1']));
4614 $salt = usces_get_salt( '', 1 );
4615 $pass = usces_get_hash( trim( $_POST['customer']['password1'] ), $salt );
4616 $name1 = ( isset( $_POST['customer']['name1'] ) ) ? trim( $_POST['customer']['name1'] ) : '';
4617 $name2 = ( isset( $_POST['customer']['name2'] ) ) ? trim( $_POST['customer']['name2'] ) : '';
4618 $name3 = ( isset( $_POST['customer']['name3'] ) ) ? trim( $_POST['customer']['name3'] ) : '';
4619 $name4 = ( isset( $_POST['customer']['name4'] ) ) ? trim( $_POST['customer']['name4'] ) : '';
4620 $zipcode = ( isset( $_POST['customer']['zipcode'] ) ) ? usces_convert_zipcode( trim( $_POST['customer']['zipcode'] ) ) : '';
4621 $pref = ( isset( $_POST['customer']['pref'] ) ) ? trim( $_POST['customer']['pref'] ) : '';
4622 $address1 = ( isset( $_POST['customer']['address1'] ) ) ? trim( $_POST['customer']['address1'] ) : '';
4623 $address2 = ( isset( $_POST['customer']['address2'] ) ) ? trim( $_POST['customer']['address2'] ) : '';
4624 $address3 = ( isset( $_POST['customer']['address3'] ) ) ? trim( $_POST['customer']['address3'] ) : '';
4625 $tel = ( isset( $_POST['customer']['tel'] ) ) ? trim( $_POST['customer']['tel'] ) : '';
4626 $fax = ( isset( $_POST['customer']['fax'] ) ) ? trim( $_POST['customer']['fax'] ) : '';
4627 $country = ( isset( $_POST['customer']['country'] ) ) ? trim( $_POST['customer']['country'] ) : '';
4628
4629 $query = $wpdb->prepare(
4630 "INSERT INTO $member_table
4631 (mem_email, mem_pass, mem_status, mem_cookie, mem_point,
4632 mem_name1, mem_name2, mem_name3, mem_name4, mem_zip, mem_pref,
4633 mem_address1, mem_address2, mem_address3, mem_tel, mem_fax,
4634 mem_delivery_flag, mem_delivery, mem_registered, mem_nicename)
4635 VALUES (%s, %s, %d, %s, %d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s)",
4636 trim( $_POST['customer']['mailaddress1'] ),
4637 $pass,
4638 0,
4639 '',
4640 $point,
4641 $name1,
4642 $name2,
4643 $name3,
4644 $name4,
4645 $zipcode,
4646 $pref,
4647 $address1,
4648 $address2,
4649 $address3,
4650 $tel,
4651 $fax,
4652 '',
4653 '',
4654 get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ),
4655 ''
4656 );
4657 $res = $wpdb->query( $query );
4658
4659 if ( false !== $res ) {
4660 $member_id = $wpdb->insert_id;
4661 $user = $_POST['customer'];
4662 $user['ID'] = $member_id;
4663 $this->set_member_meta_value( 'customer_country', $country, $member_id );
4664
4665 if ( ! empty( $salt ) ) {
4666 $this->set_member_meta_value( 'mem_salt', $salt, $member_id );
4667 }
4668
4669 $res = $this->reg_custom_member( $member_id );
4670
4671 if ( apply_filters( 'usces_filter_veirfyemail_newmemberfromcart', false, $user ) ) {
4672 return 'cartverifying';
4673 }
4674
4675 do_action( 'usces_action_member_registered', $_POST['customer'], $member_id );
4676 usces_send_regmembermail( $user );
4677 $_POST['loginmail'] = trim( $_POST['customer']['mailaddress1'] );
4678 $_POST['loginpass'] = trim( $_POST['customer']['password1'] );
4679 if ( 'member' == $this->member_login() ) {
4680 $_SESSION['usces_entry']['member_regmode'] = 'editmemberfromcart';
4681 return 'newcompletion';
4682 }
4683
4684 } else {
4685 $this->error_message = __( 'Error:failure in update', 'usces' );
4686 return $mode;
4687 }
4688 }
4689
4690 } elseif ( 'editmemberfromcart' == $_POST['member_regmode'] ) {
4691
4692 $this->get_current_member();
4693 $mem_id = $this->current_member['id'];
4694
4695 // $query = $wpdb->prepare("SELECT ID FROM $member_table WHERE mem_email = %s", trim( $_POST['customer']['mailaddress1']));
4696 // $id = $wpdb->get_var( $query );
4697 $id = $this->check_member_email( $_POST['customer']['mailaddress1'] );
4698 if ( ! empty( $id ) && $id != $mem_id ) {
4699 // $this->error_message = __( 'This e-mail address has been already registered.', 'usces' );
4700 $this->error_message = __( 'This e-mail address can not be registered.', 'usces' );
4701 return $mode;
4702 }
4703
4704 do_action( 'usces_action_pre_edit_memberdata', $_POST['customer'], $mem_id );
4705
4706 $query = $wpdb->prepare( "SELECT mem_pass FROM $member_table WHERE ID = %d", $mem_id );
4707 $pass = $wpdb->get_var( $query );
4708 // $password = ( !empty( $_POST['customer']['password1']) && trim($_POST['customer']['password1']) == trim($_POST['customer']['password2']) ) ? usces_get_hash(trim($_POST['customer']['password1'])) : $pass;
4709 if ( ! empty( $_POST['customer']['password1'] ) && trim( $_POST['customer']['password1'] ) == trim( $_POST['customer']['password2'] ) ) {
4710 $salt = usces_get_salt( $mem_id );
4711 $password = usces_get_hash( trim( $_POST['customer']['password1'] ), $salt );
4712 } else {
4713 $password = $pass;
4714 }
4715 $name1 = ( isset( $_POST['customer']['name1'] ) ) ? trim( $_POST['customer']['name1'] ) : '';
4716 $name2 = ( isset( $_POST['customer']['name2'] ) ) ? trim( $_POST['customer']['name2'] ) : '';
4717 $name3 = ( isset( $_POST['customer']['name3'] ) ) ? trim( $_POST['customer']['name3'] ) : '';
4718 $name4 = ( isset( $_POST['customer']['name4'] ) ) ? trim( $_POST['customer']['name4'] ) : '';
4719 $zipcode = ( isset( $_POST['customer']['zipcode'] ) ) ? usces_convert_zipcode( trim( $_POST['customer']['zipcode'] ) ) : '';
4720 $pref = ( isset( $_POST['customer']['pref'] ) ) ? trim( $_POST['customer']['pref'] ) : '';
4721 $address1 = ( isset( $_POST['customer']['address1'] ) ) ? trim( $_POST['customer']['address1'] ) : '';
4722 $address2 = ( isset( $_POST['customer']['address2'] ) ) ? trim( $_POST['customer']['address2'] ) : '';
4723 $address3 = ( isset( $_POST['customer']['address3'] ) ) ? trim( $_POST['customer']['address3'] ) : '';
4724 $tel = ( isset( $_POST['customer']['tel'] ) ) ? trim( $_POST['customer']['tel'] ) : '';
4725 $fax = ( isset( $_POST['customer']['fax'] ) ) ? trim( $_POST['customer']['fax'] ) : '';
4726 $country = ( isset( $_POST['customer']['country'] ) ) ? trim( $_POST['customer']['country'] ) : '';
4727
4728 $query = $wpdb->prepare(
4729 "UPDATE $member_table SET
4730 mem_pass = %s, mem_name1 = %s, mem_name2 = %s, mem_name3 = %s, mem_name4 = %s,
4731 mem_zip = %s, mem_pref = %s, mem_address1 = %s, mem_address2 = %s,
4732 mem_address3 = %s, mem_tel = %s, mem_fax = %s, mem_email = %s WHERE ID = %d",
4733 $password,
4734 $name1,
4735 $name2,
4736 $name3,
4737 $name4,
4738 $zipcode,
4739 $pref,
4740 $address1,
4741 $address2,
4742 $address3,
4743 $tel,
4744 $fax,
4745 trim( $_POST['customer']['mailaddress1'] ),
4746 $mem_id
4747 );
4748 $res = $wpdb->query( $query );
4749 if ( false !== $res ) {
4750 $this->set_member_meta_value( 'customer_country', $country, $mem_id );
4751 $res = $this->reg_custom_member( $mem_id );
4752 do_action( 'usces_action_edit_memberdata', $_POST['customer'], $mem_id );
4753 unset( $_SESSION['usces_member'] );
4754 $this->member_just_login( trim( $_POST['customer']['mailaddress1'] ), trim( $_POST['customer']['password1'] ) );
4755 return 'newcompletion';
4756
4757 } else {
4758 $this->error_message = __( 'Error:failure in update', 'usces' );
4759 return $mode;
4760 }
4761 }
4762 }
4763
4764 public function delete_member() {
4765 $res = false;
4766
4767 if ( ! $this->is_member_logged_in() ) {
4768 return $res;
4769 }
4770 $mem = $this->get_member();
4771 if ( ! $mem['ID'] ) {
4772 return $res;
4773 }
4774
4775 $del = usces_delete_member_check_front( $mem['ID'] );
4776 if ( $del ) {
4777 $res = usces_delete_memberdata( $mem['ID'] );
4778 if ( $res ) {
4779 usces_send_delmembermail( $mem );
4780 }
4781 }
4782
4783 return $res;
4784 }
4785
4786 public function is_member_logged_in( $id = false ) {
4787 if ( false === $id ) {
4788 if ( ! empty( $_SESSION['usces_member']['ID'] ) ) {
4789 return true;
4790 } else {
4791 return false;
4792 }
4793 } else {
4794 if ( ! empty( $_SESSION['usces_member']['ID'] ) && $_SESSION['usces_member']['ID'] == $id ) {
4795 return true;
4796 } else {
4797 return false;
4798 }
4799 }
4800 }
4801
4802 public function is_member( $email ) {
4803 global $wpdb;
4804
4805 $member_table = usces_get_tablename( 'usces_member' );
4806 $query = $wpdb->prepare( "SELECT mem_email FROM $member_table WHERE mem_email = %s", $email );
4807 $member = $wpdb->get_row( $query, ARRAY_A );
4808 if ( empty( $member ) ) {
4809 return false;
4810 } else {
4811 return true;
4812 }
4813 }
4814
4815 public function member_login() {
4816 global $wpdb;
4817 $_POST = $this->stripslashes_deep_post( $_POST );
4818
4819 $cookie = $this->get_cookie();
4820 $metatable_name = usces_get_tablename( 'usces_member_meta' );
4821 $member_table = usces_get_tablename( 'usces_member' );
4822 if ( ! class_exists( 'RateLimiter' ) ) {
4823 require USCES_PLUGIN_DIR . '/classes/rateLimiter.class.php';
4824 }
4825 $rateLimiter = new RateLimiter();
4826
4827 if ( isset( $cookie['rme'] ) && 'forever' == $cookie['rme'] && ! isset( $_POST['rememberme'] ) && ! isset( $_POST['loginmail'] ) ) {
4828
4829 $_forever = isset( $cookie['name'] ) ? $cookie['name'] : '';
4830 if ( $_forever ) {
4831 $query = $wpdb->prepare( "SELECT member_id FROM $metatable_name WHERE meta_value = %s AND meta_key = %s",
4832 $_forever, '_forever'
4833 );
4834 $id = $wpdb->get_var( $query );
4835 } else {
4836 $id = '';
4837 }
4838
4839 if ( ! $id ) {
4840 $cookie['name'] = '';
4841 $cookie['rme'] = '';
4842 $this->set_cookie( $cookie );
4843 $rateLimiter->saveLoginFailed();
4844 do_action( 'usces_action_member_login_failed', '', 'auto_login' );
4845 return 'login';
4846 } else {
4847 $query = $wpdb->prepare( "SELECT * FROM $member_table WHERE ID = %s", $id );
4848 $member = $wpdb->get_row( $query, ARRAY_A );
4849 if ( empty( $member ) ) {
4850 $rateLimiter->saveLoginFailed();
4851 do_action( 'usces_action_member_login_failed', '', 'auto_login' );
4852 $this->error_message = __( '<b>Error:</b> Your E-mail or password is incorrect.', 'usces' );
4853 return 'login';
4854 } else {
4855 $_SESSION['usces_member']['ID'] = $member['ID'];
4856 $_SESSION['usces_member']['mailaddress1'] = $member['mem_email'];
4857 $_SESSION['usces_member']['mailaddress2'] = $member['mem_email'];
4858 $_SESSION['usces_member']['point'] = $member['mem_point'];
4859 $_SESSION['usces_member']['name1'] = $member['mem_name1'];
4860 $_SESSION['usces_member']['name2'] = $member['mem_name2'];
4861 $_SESSION['usces_member']['name3'] = $member['mem_name3'];
4862 $_SESSION['usces_member']['name4'] = $member['mem_name4'];
4863 $_SESSION['usces_member']['zipcode'] = $member['mem_zip'];
4864 $_SESSION['usces_member']['pref'] = $member['mem_pref'];
4865 $_SESSION['usces_member']['address1'] = $member['mem_address1'];
4866 $_SESSION['usces_member']['address2'] = $member['mem_address2'];
4867 $_SESSION['usces_member']['address3'] = $member['mem_address3'];
4868 $_SESSION['usces_member']['tel'] = $member['mem_tel'];
4869 $_SESSION['usces_member']['fax'] = $member['mem_fax'];
4870 $_SESSION['usces_member']['delivery_flag'] = $member['mem_delivery_flag'];
4871 $_SESSION['usces_member']['delivery'] = ! empty( $member['mem_delivery'] ) ? unserialize( $member['mem_delivery'] ) : '';
4872 $_SESSION['usces_member']['registered'] = $member['mem_registered'];
4873 $_SESSION['usces_member']['nicename'] = $member['mem_nicename'];
4874 $_SESSION['usces_member']['country'] = $this->get_member_meta_value( 'customer_country', $member['ID'] );
4875 $_SESSION['usces_member']['status'] = $member['mem_status'];
4876 $this->set_session_custom_member( $member['ID'] );
4877 $this->get_current_member();
4878
4879 do_action( 'usces_action_after_login' );
4880 $this->set_cookie( $cookie );
4881 return apply_filters( 'usces_filter_member_login', 'member', $member );
4882 }
4883 }
4884 } elseif ( isset( $_POST['loginmail'] ) && WCUtils::is_blank( $_POST['loginmail'] ) && isset( $_POST['loginpass'] ) && WCUtils::is_blank( $_POST['loginpass'] ) && isset( $cookie['rme'] ) && 'forever' != $cookie['rme'] ) {
4885 $rateLimiter->saveLoginFailed();
4886 do_action( 'usces_action_member_login_failed', '', 'empty_credentials' );
4887 return 'login';
4888 } elseif ( isset( $_POST['loginmail'] ) && WCUtils::is_blank( $_POST['loginpass'] ) && isset( $cookie['rme'] ) && 'forever' != $cookie['rme'] ) {
4889 $rateLimiter->saveLoginFailed();
4890 do_action( 'usces_action_member_login_failed', trim( $_POST['loginmail'] ), 'empty_password' );
4891 $this->error_message = __( '<b>Error:</b> Enter the password.', 'usces' );
4892 return 'login';
4893 } elseif ( ! isset( $_POST['loginmail'] ) ) {
4894 if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) {
4895 $rateLimiter->saveLoginFailed();
4896 do_action( 'usces_action_member_login_failed', '', 'no_login_id' );
4897 }
4898 return 'login';
4899 } else {
4900
4901 if ( isset( $_POST['loginmail'] ) ) {
4902 $nonce = isset( $_REQUEST['wel_nonce'] ) ? $_REQUEST['wel_nonce'] : '';
4903 if ( ! $nonce ) {
4904 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
4905 }
4906 $noncekey = 'post_member' . $this->get_uscesid( false );
4907 if ( ! wp_verify_nonce( $nonce, $noncekey ) && ! $this->is_member_logged_in() ) {
4908 $rateLimiter->saveLoginFailed();
4909 do_action( 'usces_action_member_login_failed', trim( $_POST['loginmail'] ), 'invalid_nonce' );
4910 die( 'Security check4' );
4911 }
4912 }
4913
4914 $email = isset( $_POST['loginmail'] ) ? trim( $_POST['loginmail'] ) : '';
4915 // $pass = isset( $_POST['loginpass']) ? usces_get_hash(trim( $_POST['loginpass'])) : '';
4916 $salt = usces_get_salt( $email );
4917 $pass = usces_get_hash( trim( $_POST['loginpass'] ), $salt );
4918 $member_table = usces_get_tablename( 'usces_member' );
4919
4920 $query = $wpdb->prepare( "SELECT * FROM $member_table WHERE mem_email = %s AND mem_pass = %s", $email, $pass );
4921 $query = apply_filters( 'usces_filter_member_login_query', $query, $email, $pass );
4922 $member = $wpdb->get_row( $query, ARRAY_A );
4923
4924 if ( empty( $member ) ) {
4925 $rateLimiter->saveLoginFailed();
4926 do_action( 'usces_action_member_login_failed', $email, 'invalid_credentials' );
4927 $this->current_member['email'] = htmlspecialchars( $email, ENT_COMPAT );
4928 $this->error_message = __( '<b>Error:</b> Your E-mail or password is incorrect.', 'usces' );
4929 return 'login';
4930 } else {
4931
4932 if ( USCES_VERIFY_MEMBERS_EMAIL::$opts['switch_flag'] ) {
4933 $verify_flag = $this->get_member_meta_value( '_verifying', $member['ID'] );
4934 } else {
4935 $verify_flag = '';
4936 }
4937 if ( ! empty( $verify_flag ) ) {
4938 $rateLimiter->saveLoginFailed();
4939 do_action( 'usces_action_member_login_failed', $email, 'unverified_email' );
4940 $this->error_message = __( '<b>Error:</b> Membership registration is not complete.', 'usces' );
4941 return 'login';
4942 }
4943
4944 $_SESSION['usces_member']['ID'] = $member['ID'];
4945 $_SESSION['usces_member']['mailaddress1'] = $member['mem_email'];
4946 $_SESSION['usces_member']['mailaddress2'] = $member['mem_email'];
4947 $_SESSION['usces_member']['point'] = $member['mem_point'];
4948 $_SESSION['usces_member']['name1'] = $member['mem_name1'];
4949 $_SESSION['usces_member']['name2'] = $member['mem_name2'];
4950 $_SESSION['usces_member']['name3'] = $member['mem_name3'];
4951 $_SESSION['usces_member']['name4'] = $member['mem_name4'];
4952 $_SESSION['usces_member']['zipcode'] = $member['mem_zip'];
4953 $_SESSION['usces_member']['pref'] = $member['mem_pref'];
4954 $_SESSION['usces_member']['address1'] = $member['mem_address1'];
4955 $_SESSION['usces_member']['address2'] = $member['mem_address2'];
4956 $_SESSION['usces_member']['address3'] = $member['mem_address3'];
4957 $_SESSION['usces_member']['tel'] = $member['mem_tel'];
4958 $_SESSION['usces_member']['fax'] = $member['mem_fax'];
4959 $_SESSION['usces_member']['delivery_flag'] = $member['mem_delivery_flag'];
4960 $_SESSION['usces_member']['delivery'] = ! empty( $member['mem_delivery'] ) ? unserialize( $member['mem_delivery'] ) : '';
4961 $_SESSION['usces_member']['registered'] = $member['mem_registered'];
4962 $_SESSION['usces_member']['nicename'] = $member['mem_nicename'];
4963 $_SESSION['usces_member']['country'] = $this->get_member_meta_value( 'customer_country', $member['ID'] );
4964 $_SESSION['usces_member']['status'] = $member['mem_status'];
4965 $this->set_session_custom_member( $member['ID'] );
4966 $this->get_current_member();
4967 $rateLimiter->clear_login_failed();
4968
4969 if ( isset( $_POST['rememberme'] ) ) {
4970 $_forever = $this->set_login_forever( $member['ID'] );
4971 $cookie['name'] = $_forever;
4972 $cookie['rme'] = 'forever';
4973 $this->set_cookie( $cookie );
4974 } else {
4975 $cookie['name'] = '';
4976 $cookie['rme'] = '';
4977 $this->set_cookie( $cookie );
4978 }
4979
4980 do_action( 'usces_action_after_login' );
4981 return apply_filters( 'usces_filter_member_login', 'member', $member );
4982 }
4983 }
4984 }
4985
4986 public function set_login_forever( $member_id ) {
4987 if ( ! $member_id ) {
4988 return false;
4989 }
4990
4991 $_forever = wp_generate_password( 32, false, false );
4992 $this->set_member_meta_value( '_forever', $_forever, $member_id );
4993 return $_forever;
4994 }
4995
4996 public function set_member_session_data( $member_id ) {
4997 global $wpdb;
4998
4999 $member_table = usces_get_tablename( 'usces_member' );
5000 $query = $wpdb->prepare( "SELECT * FROM $member_table WHERE ID = %s", $member_id );
5001 $member = $wpdb->get_row( $query, ARRAY_A );
5002 if ( ! empty( $member ) ) {
5003 $_SESSION['usces_member']['ID'] = $member['ID'];
5004 $_SESSION['usces_member']['mailaddress1'] = $member['mem_email'];
5005 $_SESSION['usces_member']['mailaddress2'] = $member['mem_email'];
5006 $_SESSION['usces_member']['point'] = $member['mem_point'];
5007 $_SESSION['usces_member']['name1'] = $member['mem_name1'];
5008 $_SESSION['usces_member']['name2'] = $member['mem_name2'];
5009 $_SESSION['usces_member']['name3'] = $member['mem_name3'];
5010 $_SESSION['usces_member']['name4'] = $member['mem_name4'];
5011 $_SESSION['usces_member']['zipcode'] = $member['mem_zip'];
5012 $_SESSION['usces_member']['pref'] = $member['mem_pref'];
5013 $_SESSION['usces_member']['address1'] = $member['mem_address1'];
5014 $_SESSION['usces_member']['address2'] = $member['mem_address2'];
5015 $_SESSION['usces_member']['address3'] = $member['mem_address3'];
5016 $_SESSION['usces_member']['tel'] = $member['mem_tel'];
5017 $_SESSION['usces_member']['fax'] = $member['mem_fax'];
5018 $_SESSION['usces_member']['delivery_flag'] = $member['mem_delivery_flag'];
5019 $_SESSION['usces_member']['delivery'] = ! empty( $member['mem_delivery'] ) ? unserialize( $member['mem_delivery'] ) : '';
5020 $_SESSION['usces_member']['registered'] = $member['mem_registered'];
5021 $_SESSION['usces_member']['nicename'] = $member['mem_nicename'];
5022 $_SESSION['usces_member']['country'] = $this->get_member_meta_value( 'customer_country', $member['ID'] );
5023 $_SESSION['usces_member']['status'] = $member['mem_status'];
5024 $this->set_session_custom_member( $member['ID'] );
5025 $this->get_current_member();
5026 }
5027 return;
5028 }
5029
5030 public function member_just_login( $email, $pass ) {
5031 global $wpdb;
5032 // $pass = usces_get_hash($pass);
5033 $salt = usces_get_salt( $email );
5034 $pass = usces_get_hash( $pass, $salt );
5035 $member_table = usces_get_tablename( 'usces_member' );
5036
5037 $query = $wpdb->prepare( "SELECT * FROM $member_table WHERE mem_email = %s AND mem_pass = %s", $email, $pass );
5038 $member = $wpdb->get_row( $query, ARRAY_A );
5039 if ( empty( $member ) ) {
5040 $this->current_member['email'] = htmlspecialchars( $email, ENT_COMPAT );
5041 $this->error_message = __( '<b>Error:</b> Password is not correct.', 'usces' );
5042 return 'login';
5043 } else {
5044 $_SESSION['usces_member']['ID'] = $member['ID'];
5045 $_SESSION['usces_member']['mailaddress1'] = $member['mem_email'];
5046 $_SESSION['usces_member']['mailaddress2'] = $member['mem_email'];
5047 $_SESSION['usces_member']['point'] = $member['mem_point'];
5048 $_SESSION['usces_member']['name1'] = $member['mem_name1'];
5049 $_SESSION['usces_member']['name2'] = $member['mem_name2'];
5050 $_SESSION['usces_member']['name3'] = $member['mem_name3'];
5051 $_SESSION['usces_member']['name4'] = $member['mem_name4'];
5052 $_SESSION['usces_member']['zipcode'] = $member['mem_zip'];
5053 $_SESSION['usces_member']['pref'] = $member['mem_pref'];
5054 $_SESSION['usces_member']['address1'] = $member['mem_address1'];
5055 $_SESSION['usces_member']['address2'] = $member['mem_address2'];
5056 $_SESSION['usces_member']['address3'] = $member['mem_address3'];
5057 $_SESSION['usces_member']['tel'] = $member['mem_tel'];
5058 $_SESSION['usces_member']['fax'] = $member['mem_fax'];
5059 $_SESSION['usces_member']['delivery_flag'] = $member['mem_delivery_flag'];
5060 $_SESSION['usces_member']['delivery'] = ! empty( $member['mem_delivery'] ) ? unserialize( $member['mem_delivery'] ) : '';
5061 $_SESSION['usces_member']['registered'] = $member['mem_registered'];
5062 $_SESSION['usces_member']['nicename'] = $member['mem_nicename'];
5063 $_SESSION['usces_member']['country'] = $this->get_member_meta_value( 'customer_country', $member['ID'] );
5064 $_SESSION['usces_member']['status'] = $member['mem_status'];
5065 $this->set_session_custom_member( $member['ID'] );
5066 $this->get_current_member();
5067
5068 do_action( 'usces_action_after_login' );
5069 return apply_filters( 'usces_filter_member_login', 'member', $member );
5070 }
5071 }
5072
5073 public function member_logout() {
5074 do_action( 'usces_action_before_logout' );
5075 $cookie = $this->get_cookie();
5076 $cookie['name'] = '';
5077 $cookie['rme'] = '';
5078 $options = get_option( 'usces' );
5079
5080 $this->set_cookie( $cookie );
5081
5082 $fcookie = $this->get_cookie( $options['usces_key'] );
5083
5084 unset( $_SESSION['usces_member'], $_SESSION['usces_entry'] );
5085 do_action( 'usces_action_member_logout' );
5086 }
5087
5088 public function get_current_member() {
5089 if ( isset( $_SESSION['usces_member']['ID'] ) ) {
5090 $this->current_member['id'] = $_SESSION['usces_member']['ID'];
5091 $this->current_member['name'] = usces_localized_name( $_SESSION['usces_member']['name1'], $_SESSION['usces_member']['name2'], 'return' );
5092 } else {
5093 $this->current_member['id'] = 0;
5094 $this->current_member['name'] = __( 'guest', 'usces' );
5095 }
5096 }
5097
5098 public function get_member() {
5099 $res = array(
5100 'ID' => '',
5101 'registered' => '',
5102 'mailaddress1' => '',
5103 'mailaddress2' => '',
5104 'password1' => '',
5105 'password2' => '',
5106 'point' => '',
5107 'name1' => '',
5108 'name2' => '',
5109 'name3' => '',
5110 'name4' => '',
5111 'zipcode' => '',
5112 'address1' => '',
5113 'address2' => '',
5114 'address3' => '',
5115 'tel' => '',
5116 'fax' => '',
5117 'country' => '',
5118 'pref' => '',
5119 'status' => '',
5120 );
5121 if ( ! empty( $_SESSION['usces_member'] ) ) {
5122 foreach ( $_SESSION['usces_member'] as $key => $value ) {
5123 if ( is_array( $_SESSION['usces_member'][ $key ] ) ) {
5124 $res[ $key ] = stripslashes_deep( $value );
5125 } else {
5126 $res[ $key ] = null !== $value ? stripslashes( $value ) : '';
5127 }
5128 }
5129 }
5130 return $res;
5131 }
5132
5133 public function get_member_info( $mid ) {
5134 global $wpdb;
5135 $infos = array();
5136 $table = usces_get_tablename( 'usces_member' );
5137 $query = $wpdb->prepare( "SELECT * FROM $table WHERE ID = %d", $mid );
5138 $datas = $wpdb->get_results( $query, ARRAY_A );
5139 if ( $datas ) {
5140 $infos = $datas[0];
5141
5142 $table = usces_get_tablename( 'usces_member_meta' );
5143 $query = $wpdb->prepare( "SELECT meta_key, meta_value FROM $table WHERE member_id = %d", $mid );
5144 $metas = $wpdb->get_results( $query, ARRAY_A );
5145
5146 foreach ( $metas as $meta ) {
5147 $infos[ $meta['meta_key'] ] = maybe_unserialize( $meta['meta_value'] );
5148 }
5149 }
5150 return $infos;
5151 }
5152
5153 public function set_member_info( $data = array(), $mid = '' ) {
5154 global $wpdb;
5155
5156 $table = usces_get_tablename( 'usces_member' );
5157 $res = $wpdb->update( $table, $data, array( 'ID' => $mid ), null, array( '%d' ) );
5158 return $res;
5159 }
5160
5161 public function check_member_email( $email ) {
5162 global $wpdb;
5163
5164 $member_table_name = usces_get_tablename( 'usces_member' );
5165 $query = $wpdb->prepare( "SELECT ID FROM $member_table_name WHERE mem_email = %s", trim( $email ) );
5166 $id = $wpdb->get_var( $query );
5167 return $id;
5168 }
5169
5170 public function is_order( $mid, $oid ) {
5171 global $wpdb;
5172
5173 $mid = (int) $mid;
5174 $oid = (int) $oid;
5175
5176 $table = $wpdb->prefix . 'usces_order';
5177 $query = $wpdb->prepare( "SELECT ID FROM $table WHERE ID = %d AND mem_id = %d", $oid, $mid );
5178 $mem_id = $wpdb->get_var( $query );
5179 if ( empty( $mem_id ) ) {
5180 return false;
5181 } else {
5182 return true;
5183 }
5184 }
5185
5186 public function is_purchased_item( $mid, $post_id, $sku = null, $order_id = null ) {
5187 global $wpdb;
5188 $res = false;
5189
5190 if ( empty( $order_id ) ) {
5191 $history = $this->get_member_history( $mid, true );
5192 foreach ( $history as $umhs ) {
5193 $cart = $umhs['cart'];
5194 $status = $umhs['order_status'];
5195 $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
5196 for ( $i = 0; $i < $cart_count; $i++ ) {
5197 $cart_row = $cart[ $i ];
5198 $sku_code = urldecode( $cart_row['sku'] );
5199 if ( empty( $sku ) ) {
5200 if ( $cart_row['post_id'] == $post_id && ( false === strpos( $status, 'noreceipt' ) && false === strpos( $status, 'pending' ) ) ) {
5201 $res = true;
5202 break 2;
5203 } elseif ( $cart_row['post_id'] == $post_id && ( false !== strpos( $status, 'noreceipt' ) || false !== strpos( $status, 'pending' ) ) ) {
5204 $res = 'noreceipt';
5205 break 2;
5206 }
5207 } else {
5208 if ( $cart_row['post_id'] == $post_id && $sku_code == $sku && ( false === strpos( $status, 'noreceipt' ) && false === strpos( $status, 'pending' ) ) ) {
5209 $res = true;
5210 break 2;
5211 } elseif ( $cart_row['post_id'] == $post_id && $sku_code == $sku && (false !== strpos( $status, 'noreceipt' ) || false !== strpos( $status, 'pending' ) ) ) {
5212 $res = 'noreceipt';
5213 break 2;
5214 }
5215 }
5216 }
5217 }
5218 } else {
5219 $order_table_name = $wpdb->prefix . 'usces_order';
5220 $query = $wpdb->prepare( "SELECT order_status FROM $order_table_name WHERE ID = %d AND mem_id = %d",
5221 $order_id, $mid
5222 );
5223 $order = $wpdb->get_row( $query );
5224 if ( is_null( $order ) ) { // 該当の受注データが一件も見つからなかった場合、購入していないと判断する.
5225 $res = false;
5226 } else { // 該当の受注データが見つかった場合には受注ステータスを確認する処理を行う.
5227 $status = $order->order_status;
5228 $cart = usces_get_ordercartdata( $order_id );
5229 foreach ( $cart as $cart_row ) {
5230 $sku_code = urldecode( $cart_row['sku'] );
5231 if ( empty( $sku ) ) {
5232 if ( $cart_row['post_id'] == $post_id && ( false === strpos( $status, 'noreceipt' ) && false === strpos( $status, 'pending' ) && false === strpos( $status, 'cancel' ) ) ) {
5233 $res = true;
5234 break;
5235 } elseif ( $cart_row['post_id'] == $post_id && ( false !== strpos( $status, 'noreceipt' ) || false !== strpos( $status, 'pending' ) || false !== strpos( $status, 'cancel' ) ) ) {
5236 $res = 'noreceipt';
5237 break;
5238 }
5239 } else {
5240 if ( $cart_row['post_id'] == $post_id && $sku_code == $sku && ( false === strpos( $status, 'noreceipt' ) && false === strpos( $status, 'pending' ) && false === strpos( $status, 'cancel' ) ) ) {
5241 $res = true;
5242 break;
5243 } elseif ( $cart_row['post_id'] == $post_id && $sku_code == $sku && ( false !== strpos( $status, 'noreceipt' ) || false !== strpos( $status, 'pending' ) || false !== strpos( $status, 'cancel' ) ) ) {
5244 $res = 'noreceipt';
5245 break;
5246 }
5247 }
5248 }
5249 }
5250 }
5251
5252 return apply_filters( 'usces_filter_is_purchased_item', $res, $mid, $post_id, $sku, $order_id );
5253 }
5254
5255 public function get_order_data( $order_id, $mode = '' ) {
5256 global $wpdb;
5257 $order_table = $wpdb->prefix . 'usces_order';
5258
5259 $query = $wpdb->prepare( "SELECT * FROM $order_table WHERE ID = %d", $order_id );
5260
5261 if ( 'direct' == $mode ) {
5262 $value = $wpdb->get_row( $query, ARRAY_A );
5263 return $value;
5264 }
5265
5266 $value = $wpdb->get_row( $query );
5267
5268 if ( null == $value ) {
5269 return false;
5270 } else {
5271 $res = array();
5272 }
5273 if ( strpos( $value->order_status, 'cancel' ) !== false || strpos( $value->order_status, 'estimate' ) !== false ) {
5274 return false;
5275 }
5276
5277 $total_price = $value->order_item_total_price - $value->order_usedpoint + $value->order_discount + $value->order_shipping_charge + $value->order_cod_fee + $value->order_tax;
5278 if ( $total_price < 0 ) {
5279 $total_price = 0;
5280 }
5281 $res = array(
5282 'ID' => $value->ID,
5283 'mem_id' => $value->mem_id,
5284 'cart' => unserialize( $value->order_cart ),
5285 'condition' => unserialize( $value->order_condition ),
5286 'getpoint' => $value->order_getpoint,
5287 'usedpoint' => $value->order_usedpoint,
5288 'discount' => $value->order_discount,
5289 'payment_name' => $value->order_payment_name,
5290 'shipping_charge' => $value->order_shipping_charge,
5291 'cod_fee' => $value->order_cod_fee,
5292 'tax' => $value->order_tax,
5293 'end_price' => $total_price,
5294 'status' => $value->order_status,
5295 'date' => mysql2date( __( 'Y/m/d' ), $value->order_date ),
5296 'modified' => mysql2date( __( 'Y/m/d' ), $value->order_modified ),
5297 );
5298
5299 return $res;
5300 }
5301
5302 public function get_orderIDs_by_postID( $mem_id, $post_id ) {
5303 global $wpdb;
5304 $order_table = $wpdb->prefix . 'usces_order';
5305
5306 $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 );
5307 $rows = $wpdb->get_query( $query, ARRAY_A );
5308
5309 if ( null == $value ) {
5310 return false;
5311 } else {
5312 foreach ( $rows as $row ) {
5313 if ( strpos( $row['order_status'], 'cancel' ) !== false || strpos( $row['order_status'], 'estimate' ) !== false ) {
5314 continue;
5315 } else {
5316 $carts = unserialize( $row['order_cart'] );
5317 foreach ( $carts as $cart ) {
5318 if ( $post_id == $cart['post_id'] ) {
5319 $res[] = $row['ID'];
5320 break;
5321 }
5322 }
5323 }
5324 }
5325 }
5326 return $res;
5327 }
5328
5329 public function incart_check() {
5330 $mes = array();
5331
5332 $ids = array_keys( $_POST['inCart'] );
5333 $post_id = $ids[0];
5334 $skus = array_keys( $_POST['inCart'][ $post_id ] );
5335 $sku = $skus[0];
5336 $sku_code = urldecode( $sku );
5337 $quant = isset( $_POST['quant'][ $post_id ][ $sku ] ) ? (int) $_POST['quant'][ $post_id ][ $sku ] : 1;
5338 $stock = $this->getItemZaikoNum( $post_id, $sku );
5339 $zaiko_id = (int) $this->getItemZaikoStatusId( $post_id, $sku );
5340 $product = wel_get_product( $post_id );
5341 $itemRestriction = isset( $product['itemRestriction'] ) ? $product['itemRestriction'] : '';
5342 $itemOrderAcceptable = $this->getItemOrderAcceptable( $post_id );
5343
5344 if ( 1 > $quant ) {
5345 $mes[ $post_id ][ $sku ] = __( 'enter the correct amount', 'usces' ) . '<br />';
5346 } elseif ( $quant > (int) $itemRestriction && ! WCUtils::is_blank( $itemRestriction ) && ! WCUtils::is_zero( $itemRestriction ) ) {
5347 $mes[ $post_id ][ $sku ] = sprintf( __( 'This article is limited by %d at a time.', 'usces' ), $itemRestriction ) . '<br />';
5348 } elseif ( 1 != $itemOrderAcceptable && $quant > (int) $stock && ! WCUtils::is_blank( $stock ) ) {
5349 $mes[ $post_id ][ $sku ] = __( 'Sorry, stock is insufficient.', 'usces' ) . ' ' . __( 'Current stock', 'usces' ) . $stock . '<br />';
5350 } elseif ( 1 != $itemOrderAcceptable && !$this->is_item_zaiko( $post_id, $sku_code ) ) {
5351 $mes[ $post_id ][ $sku ] = __( 'Sorry, this item is sold out.', 'usces' ) . '<br />';
5352 } else {
5353 $mes[ $post_id ][ $sku ] = '';
5354 }
5355
5356 $ioptkeys = $this->get_itemOptionKey( $post_id, true );
5357 if ( $ioptkeys ) {
5358 foreach ( $ioptkeys as $key => $value ) {
5359 $optValues = $this->get_itemOptions( urldecode( $value ), $post_id );
5360 if ( 0 == $optValues['means'] ) { // case of select.
5361 if ( $optValues['essential'] && '#NONE#' == $_POST['itemOption'][ $post_id ][ $sku ][ $value ] ) {
5362 $mes[ $post_id ][ $sku ] .= sprintf( __( 'Chose the %s', 'usces' ), urldecode( $value ) ) . '<br />';
5363 }
5364 } elseif ( 1 == $optValues['means'] ) { // case of multiselect.
5365 if ( $optValues['essential'] ) {
5366 $mselect = 0;
5367 foreach ( (array) $_POST['itemOption'][ $post_id ][ $sku ][ $value ] as $mvalue ) {
5368 if ( ! empty( $mvalue ) && '#NONE#' != $mvalue ) {
5369 $mselect++;
5370 }
5371 }
5372 if ( $mselect == 0 ) {
5373 $mes[ $post_id ][ $sku ] .= sprintf( __( 'Chose the %s', 'usces' ), urldecode( $value ) ) . '<br />';
5374 }
5375 }
5376 } elseif ( in_array( $optValues['means'], array( 3, 4 ) ) ) { // case of radio & checkbox.
5377 if ( $optValues['essential'] ) {
5378 if ( ! isset( $_POST['itemOption'][ $post_id ][ $sku ][ $value ] ) ) {
5379 $mes[ $post_id ][ $sku ] .= sprintf( __( 'Chose the %s', 'usces' ), urldecode( $value ) ) . '<br />';
5380 }
5381 }
5382 } else { // case of text.
5383 if ( $optValues['essential'] && WCUtils::is_blank( $_POST['itemOption'][ $post_id ][ $sku ][ $value ] ) ) {
5384 $mes[ $post_id ][ $sku ] .= sprintf( __( 'Input the %s', 'usces' ), urldecode( $value ) ) . '<br />';
5385 }
5386 }
5387 }
5388 }
5389
5390 $mes = apply_filters( 'usces_filter_incart_check', $mes, $post_id, $sku );
5391
5392 if ( isset( $mes[ $post_id ] ) && is_array( $mes[ $post_id ] ) ) {
5393 $rembr = array();
5394 foreach ( $mes[ $post_id ] as $skukey => $skuvalue ) {
5395 if ( ! empty( $skuvalue ) ) {
5396 $rembr[ $post_id ][ $skukey ] = preg_replace( '/<br\s*\/?>\s*$/', '', $skuvalue );
5397 }
5398 }
5399 $mes = $rembr;
5400 }
5401
5402 if ( ! empty( $mes ) ) {
5403 $_SESSION['usces_singleitem']['itemOption'] = isset( $_POST['itemOption'] ) ? $_POST['itemOption'] : array();
5404 $_SESSION['usces_singleitem']['quant'] = isset( $_POST['quant'] ) ? (int) $_POST['quant'] : 1;
5405 $_SESSION['usces_singleitem']['error_message'] = $mes;
5406 if ( false === strpos( $_POST['usces_referer'], 'http' ) ) {
5407 $parse_url = parse_url( get_home_url() );
5408 $port = '';
5409 if ( isset( $parse_url['port'] ) && ! empty( $parse_url['port'] ) ) {
5410 $port = ':' . $parse_url['port'];
5411 }
5412 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 ) );
5413 } else {
5414 header( 'location: ' . esc_url( $_POST['usces_referer'] ) . apply_filters( 'usces_filter_incart_redirect', '#cart_button', $post_id, $sku ) );
5415 }
5416 exit;
5417 }
5418
5419 do_action( 'usces_action_incart_checked', $mes, $post_id, $sku );
5420 }
5421
5422 public function zaiko_check() {
5423
5424 $logged_in_member = $this->get_member();
5425 if ( ! empty( $logged_in_member['ID'] ) ) {
5426 if ( ! $this->member_exists( $logged_in_member['ID'] ) ) {
5427 $mes = __( 'Your membership information could not be verified.', 'usces' );
5428 $this->error_message = $mes;
5429 $this->member_logout();
5430 return $mes;
5431 }
5432 }
5433
5434 $mes = '';
5435 $cart = $this->cart->get_cart();
5436 $stocks = array();
5437
5438 $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
5439 for ( $i = 0; $i < $cart_count; $i++ ) {
5440 $cart_row = $cart[ $i ];
5441 $post_id = $cart_row['post_id'];
5442 $sku = $cart_row['sku'];
5443 $sku_code = urldecode( $cart_row['sku'] );
5444
5445 $quant = ( isset( $_POST['quant'][ $i ][ $post_id ][ $sku ] ) ) ? trim( $_POST['quant'][ $i ][ $post_id ][ $sku ] ) : $cart_row['quantity'];
5446 $zaiko_id = (int) $this->getItemZaikoStatusId( $post_id, $sku_code );
5447 $stock = $this->getItemZaikoNum( $post_id, $sku_code );
5448 if ( ! isset( $stocks[ $post_id ][ $sku ] ) ) {
5449 if ( ! WCUtils::is_blank( $stock ) ) {
5450 $stocks[ $post_id ][ $sku ] = $stock;
5451 } else {
5452 $stocks[ $post_id ][ $sku ] = null;
5453 }
5454 }
5455 $checkstock = $stocks[ $post_id ][ $sku ];
5456 $stocks[ $post_id ][ $sku ] = $stocks[ $post_id ][ $sku ] - $quant;
5457 $product = wel_get_product( $post_id );
5458 $itemRestriction = isset( $product['itemRestriction'] ) ? $product['itemRestriction'] : '';
5459 $itemOrderAcceptable = $this->getItemOrderAcceptable( $post_id );
5460 $post_status = get_post_status( $post_id );
5461
5462 if ( 1 > (int) $quant ) {
5463 $mes .= sprintf( __( 'Enter the correct amount for the No.%d item.', 'usces' ), ( $i + 1 ) ) . '<br />';
5464 } elseif ( ! $this->is_item_zaiko( $post_id, $sku_code ) || ( 1 != $itemOrderAcceptable && WCUtils::is_zero( $stock ) ) || 'publish' != $post_status ) {
5465 $mes .= sprintf( __( 'Sorry, No.%d item is sold out.', 'usces' ), ( $i + 1 ) ) . '<br />';
5466 } elseif ( $quant > (int) $itemRestriction && ! WCUtils::is_blank( $itemRestriction ) && ! WCUtils::is_zero( $itemRestriction ) ) {
5467 $mes .= sprintf( __( 'This article is limited by %1$d at a time for the No.%2$d item.', 'usces' ), $itemRestriction, ( $i + 1 ) ) . '<br />';
5468 } elseif ( 1 != $itemOrderAcceptable && 0 > $stocks[ $post_id ][ $sku ] && ! WCUtils::is_blank( $stock ) ) {
5469 $mes .= sprintf( __( 'Stock of No.%1$d item is remainder %2$d.', 'usces' ), ( $i + 1 ), $checkstock ) . '<br />';
5470 }
5471 }
5472 $mes = apply_filters( 'usces_filter_zaiko_check', $mes, $cart);
5473 return $mes;
5474 }
5475
5476 /**
5477 * Check if the member exists in the database or not.
5478 *
5479 * @param integer $member_id The id of the member.
5480 * @return boolean true/false
5481 */
5482 public function member_exists( $member_id ) {
5483 $member_info = $this->get_member_info( $member_id );
5484 if ( empty( $member_info ) ) {
5485 return false;
5486 } else {
5487 return true;
5488 }
5489 }
5490
5491 public function get_pwd_errors( $password ) {
5492 if ( WCUtils::is_blank( $password ) ) {
5493 return __( 'Please enter a password.', 'usces' ) . '<br />';
5494 }
5495
5496 $ret = '';
5497 $system_option = $this->options['system'];
5498 $pwd_rule_min = $system_option['member_pass_rule_min'];
5499 $pwd_rule_max = empty( $system_option['member_pass_rule_max'] ) ? 30 : $system_option['member_pass_rule_max'];
5500 if ( strlen( $password ) < $pwd_rule_min || strlen( $password ) > $pwd_rule_max ) {
5501 if ( $pwd_rule_min === $pwd_rule_max ) {
5502 $rule = sprintf( __( '%s characters long', 'usces' ), $pwd_rule_min );
5503 } else {
5504 $rule = sprintf( __( '%1$s characters and no more than %2$s characters', 'usces' ), $pwd_rule_min, $pwd_rule_max );
5505 }
5506 $ret .= sprintf( __( 'Password must be at least %s.', 'usces' ), $rule ) . '<br />';
5507 }
5508 if ( ! empty( $system_option['member_pass_rule_upercase'] ) && ! preg_match( '@[A-Z]@', $password ) ) {
5509 $ret .= __( 'Password must contain at least one upper-case alphabetics character.', 'usces' ) . '<br />';
5510 }
5511 if ( ! empty( $system_option['member_pass_rule_lowercase'] ) && ! preg_match( '@[a-z]@', $password ) ) {
5512 $ret .= __( 'Password must contain at least one lower-case alphabetics character.', 'usces' ) . '<br />';
5513 }
5514 if ( ! empty( $system_option['member_pass_rule_digit'] ) && ! preg_match( '@[0-9]@', $password ) ) {
5515 $ret .= __( 'Password must contain at least one numeric character.', 'usces' ) . '<br />';
5516 }
5517 if ( ! empty( $system_option['member_pass_rule_symbol'] ) && ! preg_match( '@[\W]@', $password ) ) {
5518 $ret .= __( 'Password must contain at least one symbolic character.', 'usces' ) . '<br />';
5519 }
5520
5521 return $ret;
5522 }
5523
5524 public function member_check() {
5525 do_action( 'usces_action_before_member_check' );
5526
5527 $mes = '';
5528 $usces_member_old = $_SESSION['usces_member'];
5529 foreach ( $_POST['member'] as $key => $vlue ) {
5530 if ( 'password1' !== $key && 'password2' !== $key && 'mailaddress2' !== $key ) {
5531 $_SESSION['usces_member'][ $key ] = trim( $vlue );
5532 }
5533 }
5534
5535 if ( 'newmemberform' == $_POST['member_regmode'] ||
5536 ( 'editmemberform' === $_POST['member_regmode'] && ! ( WCUtils::is_blank( $_POST['member']['password1'] ) && WCUtils::is_blank( $_POST['member']['password2'] ) ) ) ||
5537 ( 'updatememberform' === $_POST['member_regmode'] && ! ( WCUtils::is_blank( $_POST['member']['password1'] ) && WCUtils::is_blank( $_POST['member']['password2'] ) ) ) ) {
5538 $mes = $this->get_pwd_errors( $_POST['member']['password1'] );
5539 }
5540
5541 if ( 'editmemberform' == $_POST['member_regmode'] || 'updatememberform' == $_POST['member_regmode'] ) {
5542 if ( trim( $_POST['member']['password1'] ) != trim( $_POST['member']['password2'] ) ) {
5543 $mes .= __( 'Password confirm does not match.', 'usces' ) . '<br />';
5544 }
5545 if ( ! is_email( $_POST['member']['mailaddress1'] ) || WCUtils::is_blank( $_POST['member']['mailaddress1'] ) ) {
5546 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5547 } else {
5548 $this->get_current_member();
5549 $mem_id = $this->current_member['id'];
5550 $id = $this->check_member_email( $_POST['member']['mailaddress1'] );
5551 if ( ! empty( $id ) && $id != $mem_id ) {
5552 $mes .= __( 'This e-mail address can not be registered.', 'usces' ) . '<br />';
5553 } else {
5554 if ( isset( $_POST['member']['mailaddress2'] ) ) {
5555 if ( WCUtils::is_blank( $_POST['member']['mailaddress2'] ) ) {
5556 if ( $usces_member_old['mailaddress1'] !== $_POST['member']['mailaddress1'] ) {
5557 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5558 }
5559 } else {
5560 if ( trim( $_POST['member']['mailaddress1'] ) != trim( $_POST['member']['mailaddress2'] ) ) {
5561 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5562 }
5563 }
5564 }
5565 }
5566 }
5567 } elseif ( 'newmemberform' == $_POST['member_regmode'] ) {
5568 if ( trim( $_POST['member']['password1'] ) != trim( $_POST['member']['password2'] ) ) {
5569 $mes .= __( 'Password confirm does not match.', 'usces' ) . '<br />';
5570 }
5571 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'] ) ) {
5572 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5573 } else {
5574 $id = $this->check_member_email( $_POST['member']['mailaddress1'] );
5575 if ( ! empty( $id ) ) {
5576 $mes .= __( 'This e-mail address can not be registered.', 'usces' ) . '<br />';
5577 }
5578 }
5579 } else {
5580 $mes .= __( 'ERROR: I was not able to complete collective operation', 'usces' ) . '<br />';
5581 }
5582 if ( WCUtils::is_blank( $_POST['member']['name1'] ) ) {
5583 $mes .= __( 'Name is not correct', 'usces' ) . '<br />';
5584 }
5585
5586 $zip_check = false;
5587 $addressform = $this->options['system']['addressform'];
5588 $applyform = usces_get_apply_addressform( $addressform );
5589 if ( 'JP' === $applyform ) {
5590 if ( isset( $_POST['member']['country'] ) ) {
5591 if ( 'JP' === $_POST['member']['country'] ) {
5592 $zip_check = true;
5593 }
5594 } else {
5595 $base = usces_get_base_country();
5596 if ( 'JP' === $base ) {
5597 $zip_check = true;
5598 }
5599 }
5600 }
5601 $zip_check = apply_filters( 'usces_filter_zipcode_check', $zip_check );
5602 if ( WCUtils::is_blank( $_POST['member']['zipcode'] ) ) {
5603 if ( usces_is_required_field('zipcode') ) {
5604 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5605 }
5606 } else {
5607 if ( $zip_check ) {
5608 if ( ! preg_match( '/^[a-zA-Z0-9]+$/', $_POST['member']['zipcode'] ) ) {
5609 $_SESSION['usces_member']['zipcode'] = usces_convert_zipcode( $_POST['member']['zipcode'] );
5610 }
5611 if ( ! preg_match( '/^(([0-9]{3}-[0-9]{4})|([0-9]{7}))$/', $_SESSION['usces_member']['zipcode'] ) ) {
5612 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5613 }
5614 }
5615 }
5616 if ( __( '-- Select --', 'usces_dual' ) == $_POST['member']['pref'] && usces_is_required_field( 'states' ) ) {
5617 $mes .= __( 'enter the prefecture', 'usces' ) . '<br />';
5618 }
5619 if ( WCUtils::is_blank( $_POST['member']['address1'] ) && usces_is_required_field( 'address1' ) ) {
5620 $mes .= __( 'enter the city name', 'usces' ) . '<br />';
5621 }
5622 if ( WCUtils::is_blank( $_POST['member']['address2'] ) && usces_is_required_field( 'address2' ) ) {
5623 $mes .= __( 'enter house numbers', 'usces' ) . '<br />';
5624 }
5625 if ( WCUtils::is_blank( $_POST['member']['tel'] ) && usces_is_required_field( 'tel' ) ) {
5626 $mes .= __( 'enter phone numbers', 'usces' ) . '<br />';
5627 }
5628 if ( ! WCUtils::is_blank( $_POST['member']['tel'] ) && preg_match( '/[^\d\-+]/', trim( $_POST['member']['tel'] ) ) && usces_is_required_field( 'tel' ) ) {
5629 $mes .= __( 'Please input a phone number with a half size number.', 'usces' ) . '<br />';
5630 }
5631
5632 if ( 'editmemberform' !== $_POST['member_regmode'] && 'updatememberform' !== $_POST['member_regmode'] && isset( $this->options['agree_member'] ) && 'activate' === $this->options['agree_member'] ) {
5633 if ( ! isset( $_POST['agree_member_check'] ) ) {
5634 $mes .= __( 'Please accept the membership agreement.', 'usces' ) . '<br />';
5635 }
5636 }
5637
5638 $mes = apply_filters( 'usces_filter_member_check', $mes );
5639
5640 if ( ( 'editmemberform' == $_POST['member_regmode'] || 'updatememberform' == $_POST['member_regmode'] ) && '' != $mes ) {
5641 $_SESSION['usces_member'] = $usces_member_old;
5642 }
5643
5644 return $mes;
5645 }
5646
5647 public function member_check_fromcart() {
5648
5649 do_action( 'usces_action_before_member_check_fromcart' );
5650
5651 $mes = $this->get_pwd_errors( $_POST['customer']['password1'] );
5652
5653 if ( trim( $_POST['customer']['password1'] ) != trim( $_POST['customer']['password2'] ) ) {
5654 $mes .= __( 'Password confirm does not match.', 'usces' ) . '<br />';
5655 }
5656 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'] ) ) {
5657 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5658 }
5659 if ( WCUtils::is_blank( $_POST['customer']['name1'] ) ) {
5660 $mes .= __( 'Name is not correct', 'usces' ) . '<br />';
5661 }
5662 $zip_check = false;
5663 $addressform = $this->options['system']['addressform'];
5664 $applyform = usces_get_apply_addressform( $addressform );
5665 if ( 'JP' === $applyform ) {
5666 if ( isset( $_POST['customer']['country'] ) ) {
5667 if ( 'JP' === $_POST['customer']['country'] ) {
5668 $zip_check = true;
5669 }
5670 } else {
5671 $base = usces_get_base_country();
5672 if ( 'JP' === $base ) {
5673 $zip_check = true;
5674 }
5675 }
5676 }
5677 $zip_check = apply_filters( 'usces_filter_zipcode_check', $zip_check );
5678 if ( WCUtils::is_blank( $_POST['customer']['zipcode'] ) ) {
5679 if ( usces_is_required_field( 'zipcode' ) ) {
5680 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5681 }
5682 } else {
5683 if ( $zip_check ) {
5684 if ( ! preg_match( '/^[a-zA-Z0-9]+$/', $_POST['customer']['zipcode'] ) ) {
5685 $_SESSION['usces_entry']['customer']['zipcode'] = usces_convert_zipcode( $_POST['customer']['zipcode'] );
5686 }
5687 if ( ! preg_match( '/^(([0-9]{3}-[0-9]{4})|([0-9]{7}))$/', $_SESSION['usces_entry']['customer']['zipcode'] ) ) {
5688 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5689 }
5690 }
5691 }
5692 if ( ( __( '-- Select --', 'usces' ) == $_POST['customer']['pref'] || '-- Select --' == $_POST['customer']['pref'] ) && usces_is_required_field( 'states' ) ) {
5693 $mes .= __( 'enter the prefecture', 'usces' ) . '<br />';
5694 }
5695 if ( WCUtils::is_blank( $_POST['customer']['address1'] ) && usces_is_required_field( 'address1' ) ) {
5696 $mes .= __( 'enter the city name', 'usces' ) . '<br />';
5697 }
5698 if ( WCUtils::is_blank( $_POST['customer']['address2'] ) && usces_is_required_field( 'address2' ) ) {
5699 $mes .= __( 'enter house numbers', 'usces' ) . '<br />';
5700 }
5701 if ( WCUtils::is_blank( $_POST['customer']['tel'] ) && usces_is_required_field( 'tel' ) ) {
5702 $mes .= __( 'enter phone numbers', 'usces' ) . '<br />';
5703 }
5704 if ( ! WCUtils::is_blank( $_POST['customer']['tel'] ) && preg_match( '/[^\d\-+]/', trim( $_POST['customer']['tel'] ) ) && usces_is_required_field( 'tel' ) ) {
5705 $mes .= __( 'Please input a phone number with a half size number.', 'usces' ) . '<br />';
5706 }
5707
5708 if ( isset( $this->options['agree_member'] ) && 'activate' === $this->options['agree_member'] ) {
5709 if ( ! isset( $_POST['agree_member_check'] ) ) {
5710 $mes .= __( 'Please accept the membership agreement.', 'usces' ) . '<br />';
5711 }
5712 }
5713
5714 $mes = apply_filters( 'usces_filter_member_check_fromcart', $mes );
5715
5716 return $mes;
5717 }
5718
5719 public function admin_member_check() {
5720 global $wpdb;
5721 $mes = '';
5722 if ( ! is_email( trim( $_POST['member']['email'] ) ) ) {
5723 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5724 } else {
5725 $member_table = usces_get_tablename( 'usces_member' );
5726 $mem_email = $wpdb->get_var( $wpdb->prepare( "SELECT mem_email FROM $member_table WHERE ID = %d LIMIT 1", trim( $_POST['member_id'] ) ) );
5727 if ( trim( $_POST['member']['email'] ) != $mem_email ) {
5728 $mem_ID = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $member_table WHERE mem_email = %s LIMIT 1", trim( $_POST['member']['email'] ) ) );
5729 if ( ! empty( $mem_ID ) ) {
5730 $mes .= __( 'This e-mail address has been already registered.', 'usces' ) . '<br />';
5731 }
5732 }
5733 }
5734 if ( WCUtils::is_blank( $_POST['member']['name1'] ) ) {
5735 $mes .= __( 'Name is not correct', 'usces' ) . '<br />';
5736 }
5737 if ( ! WCUtils::is_blank( $_POST['member']['tel'] ) && preg_match( '/[^\d\-+]/', trim( $_POST['member']['tel'] ) ) ) {
5738 $mes .= __( 'Please input a phone number with a half size number.', 'usces' ) . '<br />';
5739 }
5740 $mes = apply_filters( 'usces_filter_admin_member_check', $mes );
5741
5742 return $mes;
5743 }
5744
5745 public function customer_check() {
5746
5747 do_action( 'usces_action_before_customer_check' );
5748
5749 $mes = '';
5750 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'] ) ) {
5751 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5752 }
5753 if ( WCUtils::is_blank( $_POST['customer']['name1'] ) ) {
5754 $mes .= __( 'Name is not correct', 'usces' ) . '<br />';
5755 }
5756 $zip_check = false;
5757 $addressform = $this->options['system']['addressform'];
5758 $applyform = usces_get_apply_addressform( $addressform );
5759 if ( 'JP' === $applyform ) {
5760 if ( isset( $_POST['customer']['country'] ) ) {
5761 if ( 'JP' === $_POST['customer']['country'] ) {
5762 $zip_check = true;
5763 }
5764 } else {
5765 $base = usces_get_base_country();
5766 if ( 'JP' === $base ) {
5767 $zip_check = true;
5768 }
5769 }
5770 }
5771 $zip_check = apply_filters( 'usces_filter_zipcode_check', $zip_check );
5772 if ( WCUtils::is_blank( $_POST['customer']['zipcode'] ) ) {
5773 if ( usces_is_required_field( 'zipcode' ) ) {
5774 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5775 }
5776 } else {
5777 if ( $zip_check ) {
5778 if ( ! preg_match( '/^[a-zA-Z0-9]+$/', $_POST['customer']['zipcode'] ) ) {
5779 $_SESSION['usces_entry']['customer']['zipcode'] = usces_convert_zipcode( $_POST['customer']['zipcode'] );
5780 }
5781 if ( ! preg_match( '/^(([0-9]{3}-[0-9]{4})|([0-9]{7}))$/', $_SESSION['usces_entry']['customer']['zipcode'] ) ) {
5782 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5783 }
5784 }
5785 }
5786 if ( ( __( '-- Select --', 'usces' ) == $_POST['customer']['pref'] || '-- Select --' == $_POST['customer']['pref'] ) && usces_is_required_field( 'states' ) ) {
5787 $mes .= __( 'enter the prefecture', 'usces' ) . '<br />';
5788 }
5789 if ( WCUtils::is_blank( $_POST['customer']['address1'] ) && usces_is_required_field( 'address1' ) ) {
5790 $mes .= __( 'enter the city name', 'usces' ) . '<br />';
5791 }
5792 if ( WCUtils::is_blank( $_POST['customer']['address2'] ) && usces_is_required_field( 'address2' ) ) {
5793 $mes .= __( 'enter house numbers', 'usces' ) . '<br />';
5794 }
5795 if ( WCUtils::is_blank( $_POST['customer']['tel'] ) && usces_is_required_field( 'tel' ) ) {
5796 $mes .= __( 'enter phone numbers', 'usces' ) . '<br />';
5797 }
5798 if ( ! WCUtils::is_blank( $_POST['customer']['tel'] ) && preg_match( '/[^\d\-+]/', trim( $_POST['customer']['tel'] ) ) && usces_is_required_field( 'tel' ) ) {
5799 $mes .= __( 'Please input a phone number with a half size number.', 'usces' ) . '<br />';
5800 }
5801
5802 $mes = apply_filters( 'usces_filter_customer_check', $mes );
5803
5804 return $mes;
5805 }
5806
5807 public function admin_new_member_check() {
5808 global $wpdb;
5809
5810 $mes = $this->get_pwd_errors( $_POST['member']['password'] );
5811
5812 if ( ! is_email( trim( $_POST['member']['email'] ) ) ) {
5813 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5814 } else {
5815 $member_table = usces_get_tablename( 'usces_member' );
5816 $mem_email = $wpdb->get_var( $wpdb->prepare( "SELECT mem_email FROM $member_table WHERE ID = %d LIMIT 1", trim( $_POST['member_id'] ) ) );
5817 if ( trim( $_POST['member']['email'] ) != $mem_email ) {
5818 $mem_ID = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $member_table WHERE mem_email = %s LIMIT 1", trim( $_POST['member']['email'] ) ) );
5819 if ( ! empty( $mem_ID ) ) {
5820 $mes .= __( 'This e-mail address has been already registered.', 'usces' ) . '<br />';
5821 }
5822 }
5823 }
5824
5825 if ( WCUtils::is_blank( $_POST['member']['name1'] ) ) {
5826 $mes .= __( 'Name is not correct', 'usces' ) . '<br />';
5827 }
5828 if ( ! WCUtils::is_blank( $_POST['member']['tel'] ) && preg_match( '/[^\d\-+]/', trim( $_POST['member']['tel'] ) ) ) {
5829 $mes .= __( 'Please input a phone number with a half size number.', 'usces' ) . '<br />';
5830 }
5831 $mes = apply_filters( 'usces_filter_admin_member_check', $mes );
5832
5833 return $mes;
5834 }
5835
5836 public function delivery_check() {
5837 global $usces_settings;
5838
5839 do_action( 'usces_action_before_delivery_check' );
5840
5841 $mes = '';
5842 if ( isset( $_POST['delivery']['delivery_flag'] ) && 1 === (int) $_POST['delivery']['delivery_flag'] ) {
5843 if ( WCUtils::is_blank( $_POST['delivery']['name1'] ) ) {
5844 $mes .= __( 'Name is not correct', 'usces' ) . '<br />';
5845 }
5846 $zip_check = false;
5847 $addressform = $this->options['system']['addressform'];
5848 $applyform = usces_get_apply_addressform( $addressform );
5849 if ( 'JP' === $applyform ) {
5850 if ( isset( $_POST['delivery']['country'] ) ) {
5851 if ( 'JP' === $_POST['delivery']['country'] ) {
5852 $zip_check = true;
5853 }
5854 } else {
5855 $base = usces_get_base_country();
5856 if ( 'JP' === $base ) {
5857 $zip_check = true;
5858 }
5859 }
5860 }
5861 $zip_check = apply_filters( 'usces_filter_zipcode_check', $zip_check );
5862 if ( WCUtils::is_blank( $_POST['delivery']['zipcode'] ) ) {
5863 if ( usces_is_required_field( 'zipcode' ) ) {
5864 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5865 }
5866 } else {
5867 if ( $zip_check ) {
5868 if ( ! preg_match( '/^[a-zA-Z0-9]+$/', $_POST['delivery']['zipcode'] ) ) {
5869 $_SESSION['usces_entry']['delivery']['zipcode'] = usces_convert_zipcode( $_POST['delivery']['zipcode'] );
5870 }
5871 if ( ! preg_match( '/^(([0-9]{3}-[0-9]{4})|([0-9]{7}))$/', $_SESSION['usces_entry']['delivery']['zipcode'] ) ) {
5872 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5873 }
5874 }
5875 }
5876 if ( ( __( '-- Select --', 'usces' ) == $_POST['delivery']['pref'] || '-- Select --' == $_POST['delivery']['pref'] ) && usces_is_required_field( 'states' ) ) {
5877 $mes .= __( 'enter the prefecture', 'usces' ) . '<br />';
5878 }
5879 if ( WCUtils::is_blank( $_POST['delivery']['address1'] ) && usces_is_required_field( 'address1' ) ) {
5880 $mes .= __( 'enter the city name', 'usces' ) . '<br />';
5881 }
5882 if ( WCUtils::is_blank( $_POST['delivery']['address2'] ) && usces_is_required_field( 'address2' ) ) {
5883 $mes .= __( 'enter house numbers', 'usces' ) . '<br />';
5884 }
5885 if ( WCUtils::is_blank( $_POST['delivery']['tel'] ) && usces_is_required_field( 'tel' ) ) {
5886 $mes .= __( 'enter phone numbers', 'usces' ) . '<br />';
5887 }
5888 if ( ! WCUtils::is_blank( $_POST['delivery']['tel'] ) && preg_match( '/[^\d\-+]/', trim( $_POST['delivery']['tel'] ) ) && usces_is_required_field( 'tel' ) ) {
5889 $mes .= __( 'Please input a phone number with a half size number.', 'usces' ) . '<br />';
5890 }
5891 $post_offer = filter_input( INPUT_POST, 'offer', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
5892 if ( ! empty( $post_offer['delivery_date'] ) && usces_is_date( $post_offer['delivery_date'] ) && isset( $post_offer['delivery_method'] ) ) {
5893 $post_delivery = filter_input( INPUT_POST, 'delivery', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
5894 $deli_method_index = $this->get_delivery_method_index( $post_offer['delivery_method'] );
5895 $delivery_days_id = isset( $this->options['delivery_method'][ $deli_method_index ]['days'] ) ? $this->options['delivery_method'][ $deli_method_index ]['days'] : -1;
5896 if ( 0 <= $delivery_days_id ) {
5897 $delivery_days_list = $this->options['delivery_days'];
5898 $delivery_days = 0;
5899 foreach ( (array) $delivery_days_list as $delivery_days_value ) {
5900 if ( (int) $delivery_days_value['id'] === (int) $delivery_days_id ) {
5901 $delivery_days = (int) $delivery_days_value[ $applyform ][ $post_delivery['pref'] ];
5902 }
5903 }
5904 $sendout = usces_get_send_out_date();
5905 $sendout_date = implode( '-', $sendout['sendout_date'] );
5906 $arrival_date = new DateTime( $sendout_date );
5907 $arrival_date->modify( '+' . $delivery_days . ' days' );
5908 $offer_deli_date = new DateTime( $post_offer['delivery_date'] );
5909 if ( $offer_deli_date < $arrival_date ) {
5910 $mes .= __( 'Please re-specify the desired arrival date.', 'usces' ) . '<br />';
5911 }
5912 } else {
5913 $mes .= __( 'Please re-specify the desired arrival date.', 'usces' ) . '<br />';
5914 }
5915 }
5916 }
5917 if ( ! isset( $_POST['offer']['delivery_method'] ) || ( empty( $_POST['offer']['delivery_method'] ) && ! WCUtils::is_zero( $_POST['offer']['delivery_method'] ) ) ) {
5918 $mes .= __( 'chose one from delivery method.', 'usces' ) . '<br />';
5919 } else {
5920 $d_method_index = $this->get_delivery_method_index( (int) $_POST['offer']['delivery_method'] );
5921 if ( 0 > $d_method_index ) {
5922 $mes .= __( 'chose one from delivery method.', 'usces' ) . '<br />';
5923 } elseif ( isset( $_SESSION['usces_entry']['delivery']['country'] ) ) {
5924 $country = $_SESSION['usces_entry']['delivery']['country'];
5925 $current_locate = get_locale();
5926 $wplang = get_option( 'WPLANG', $current_locate );
5927 $local_country = $usces_settings['lungage2country'][ $wplang ];
5928
5929 if ( $country == $local_country ) {
5930 if ( 1 == $this->options['delivery_method'][ $d_method_index ]['intl'] ) {
5931 $mes .= __( 'Delivery method is incorrect. Can not specify an international flight.', 'usces' ) . '<br />';
5932 }
5933 } else {
5934 if ( WCUtils::is_zero( $this->options['delivery_method'][ $d_method_index ]['intl'] ) ) {
5935 $mes .= __( 'Delivery method is incorrect. Specify the international flights.', 'usces' ) . '<br />';
5936 }
5937 }
5938 }
5939 }
5940 if ( ! isset( $_POST['offer']['payment_name'] ) ) {
5941 $mes .= __( 'chose one from payment options.', 'usces' ) . '<br />';
5942 } else {
5943 $payments = $this->getPayments( $_POST['offer']['payment_name'] );
5944 if ( 'COD' == $payments['settlement'] ) {
5945 $total_items_price = $this->get_total_price();
5946 $usces_entries = $this->cart->get_entry();
5947 $materials = array(
5948 'total_items_price' => $usces_entries['order']['total_items_price'],
5949 'discount' => ( isset( $usces_entries['order']['discount'] ) ) ? $usces_entries['order']['discount'] : 0,
5950 'shipping_charge' => $usces_entries['order']['shipping_charge'],
5951 'cod_fee' => $usces_entries['order']['cod_fee'],
5952 'use_point' => ( isset( $usces_entries['order']['use_point'] ) ) ? $usces_entries['order']['use_point'] : 0,
5953 );
5954 $tax = $this->getTax( $total_items_price, $materials );
5955 $total_items_price = $total_items_price + $tax;
5956 $cod_limit_amount = ( isset( $this->options['cod_limit_amount'] ) && 0 < (int) $this->options['cod_limit_amount'] ) ? $this->options['cod_limit_amount'] : 0;
5957 if ( 0 < $cod_limit_amount && $total_items_price > $cod_limit_amount ) {
5958 $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 />';
5959 }
5960 }
5961 }
5962 if ( isset( $d_method_index ) && isset( $payments ) ) {
5963 if ( 1 == $this->options['delivery_method'][ $d_method_index ]['nocod'] ) {
5964 if ( 'COD' == $payments['settlement'] ) {
5965 $mes .= __( 'COD is not available.', 'usces' ) . '<br />';
5966 }
5967 }
5968 }
5969 $mes = apply_filters( 'usces_filter_delivery_check', $mes );
5970 return $mes;
5971 }
5972
5973 public function point_check( $entries ) {
5974 $member = $this->get_member();
5975 $this->set_cart_fees( $member, $entries );
5976
5977 $mes = '';
5978 if ( isset( $_POST['offer']['usedpoint'] ) ) {
5979 if ( WCUtils::is_blank( $_POST['offer']['usedpoint'] ) || ! preg_match( '/^[0-9]+$/', $_POST['offer']['usedpoint'] ) || (int) $_POST['offer']['usedpoint'] < 0 ) {
5980 $mes .= __( 'Invalid value. Please enter in the numbers.', 'usces' ) . '<br />';
5981
5982 } else {
5983 $payments = $this->getPayments( $entries['order']['payment_name'] );
5984 $usedpoint = (int) trim( $_POST['offer']['usedpoint'] );
5985 if ( $usedpoint > $member['point'] ) {
5986 $mes .= __( 'You have exceeded the maximum available.', 'usces' ) . ' ' . __( 'Max', 'usces' ) . ' ' . $member['point'] . ' ' . __( 'points', 'usces' ) . '<br />';
5987
5988 } elseif ( 'acting_paypal_ec' == $payments['settlement'] ) {
5989 $target_full_price = $entries['order']['total_items_price'] + $entries['order']['discount'] + $entries['order']['shipping_charge'] + $entries['order']['cod_fee'] + $entries['order']['tax'];
5990 $target_item_price = $entries['order']['total_items_price'] + $entries['order']['discount'];
5991 if ( 1 == $this->options['point_coverage'] && $usedpoint >= $target_full_price ) {
5992 $target_item_price = $target_full_price;
5993 } elseif ( 'products' == $this->options['tax_target'] ) {
5994 $target_item_price += $entries['order']['tax'];
5995 }
5996 if ( $usedpoint > $target_item_price ) {
5997 $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 />';
5998 }
5999
6000 } else {
6001 if ( 1 == $this->options['point_coverage'] ) {
6002 $target_full_price = $entries['order']['total_items_price'] + $entries['order']['discount'] + $entries['order']['shipping_charge'] + $entries['order']['cod_fee'] + $entries['order']['tax'];
6003 if ( $usedpoint > $target_full_price ) {
6004 $mes .= __( 'You have exceeded the maximum available.', 'usces' ) . ' ' . __( 'Max', 'usces' ) . ' ' . $target_full_price . ' ' . __( 'points', 'usces' ) . '<br />';
6005 }
6006 } else {
6007 $target_item_price = $entries['order']['total_items_price'] + $entries['order']['discount'];
6008 if ( 'products' == $this->options['tax_target'] ) {
6009 $target_item_price += $entries['order']['tax'];
6010 }
6011 if ( $usedpoint > $target_item_price ) {
6012 $mes .= __( 'You have exceeded the maximum available.', 'usces' ) . ' ' . __( 'Max', 'usces' ) . ' ' . $target_item_price . ' ' . __( 'points', 'usces' ) . '<br />';
6013 }
6014 }
6015 }
6016 $mes = apply_filters( 'usces_filter_point_check', $mes );
6017 if ( '' != $mes ) {
6018 $_POST['offer']['usedpoint'] = 0;
6019 $array = array(
6020 'usedpoint' => 0,
6021 );
6022 $this->cart->set_order_entry( $array );
6023 }
6024 }
6025 }
6026 $mes = apply_filters( 'usces_filter_point_check_last', $mes );
6027 return $mes;
6028 }
6029
6030 public function lostpass_mailaddcheck() {
6031 $mes = '';
6032 if ( ! is_email( $_POST['loginmail'] ) || WCUtils::is_blank( $_POST['loginmail'] ) ) {
6033 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
6034 }
6035
6036 return $mes;
6037 }
6038
6039 public function changepass_check() {
6040 $mes = $this->get_pwd_errors( $_POST['loginpass1'] );
6041
6042 if ( trim( $_POST['loginpass1'] ) != trim( $_POST['loginpass2'] ) ) {
6043 $mes .= __( 'Password confirm does not match.', 'usces' ) . '<br />';
6044 }
6045
6046 return $mes;
6047 }
6048
6049 public function get_page() {
6050 return $this->page;
6051 }
6052
6053 public function check_display_mode() {
6054 $options = get_option( 'usces' );
6055 if ( isset( $options['display_mode'] ) && 'Maintenancemode' == $options['display_mode'] ) {
6056 return;
6057 }
6058
6059 $start['hour'] = empty( $options['campaign_schedule']['start']['hour'] ) ? 0 : $options['campaign_schedule']['start']['hour'];
6060 $start['min'] = empty( $options['campaign_schedule']['start']['min'] ) ? 0 : $options['campaign_schedule']['start']['min'];
6061 $start['month'] = empty( $options['campaign_schedule']['start']['month'] ) ? 0 : $options['campaign_schedule']['start']['month'];
6062 $start['day'] = empty( $options['campaign_schedule']['start']['day'] ) ? 0 : $options['campaign_schedule']['start']['day'];
6063 $start['year'] = empty( $options['campaign_schedule']['start']['year'] ) ? 0 : $options['campaign_schedule']['start']['year'];
6064 $end['hour'] = empty( $options['campaign_schedule']['end']['hour'] ) ? 0 : $options['campaign_schedule']['end']['hour'];
6065 $end['min'] = empty( $options['campaign_schedule']['end']['min'] ) ? 0 : $options['campaign_schedule']['end']['min'];
6066 $end['month'] = empty( $options['campaign_schedule']['end']['month'] ) ? 0 : $options['campaign_schedule']['end']['month'];
6067 $end['day'] = empty( $options['campaign_schedule']['end']['day'] ) ? 0 : $options['campaign_schedule']['end']['day'];
6068 $end['year'] = empty( $options['campaign_schedule']['end']['year'] ) ? 0 : $options['campaign_schedule']['end']['year'];
6069 $starttime = mktime( $start['hour'], $start['min'], 0, $start['month'], $start['day'], $start['year'] );
6070 $endtime = mktime( $end['hour'], $end['min'], 0, $end['month'], $end['day'], $end['year'] );
6071 $current_time = current_time( 'timestamp' );
6072
6073 if ( ( $current_time >= $starttime ) && ( $current_time <= $endtime ) ) {
6074 $options['display_mode'] = 'Promotionsale';
6075 } else {
6076 $options['display_mode'] = 'Usualsale';
6077 }
6078 update_option( 'usces', $options );
6079 }
6080
6081 public function update_business_days() {
6082 $options = get_option( 'usces' );
6083 $datetimestr = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) );
6084 $dhour = (int) substr( $datetimestr, 11, 2 );
6085 $dminute = (int) substr( $datetimestr, 14, 2 );
6086 $dsecond = (int) substr( $datetimestr, 17, 2 );
6087 $dmonth = (int) substr( $datetimestr, 5, 2 );
6088 $dday = (int) substr( $datetimestr, 8, 2 );
6089 $dyear = (int) substr( $datetimestr, 0, 4 );
6090 $dtimestamp = mktime( $dhour, $dminute, $dsecond, $dmonth, $dday, $dyear );
6091 $datenow = getdate( $dtimestamp );
6092 list( $year, $mon, $mday ) = getBeforeMonth( $datenow['year'], $datenow['mon'], 1, 1 );
6093
6094 if ( isset( $options['business_days'][ $year ][ $mon ][1] ) ) {
6095 unset( $options['business_days'][ $year ][ $mon ] );
6096 }
6097
6098 for ( $i = 0; $i < 12; $i++ ) {
6099 list( $year, $mon, $mday ) = getAfterMonth( $datenow['year'], $datenow['mon'], 1, $i );
6100 $last = getLastDay( $year, $mon );
6101 for ( $j = 1; $j <= $last; $j++ ) {
6102 if ( ! isset( $options['business_days'][ $year ][ $mon ][ $j ] ) ) {
6103 $options['business_days'][ $year ][ $mon ][ $j ] = 1;
6104 }
6105 }
6106 }
6107 update_option( 'usces', $options );
6108 $this->options = get_option( 'usces' );
6109 $_SESSION['usces_checked_business_days'] = '';
6110 }
6111
6112 public function display_cart() {
6113 if ( $this->cart->num_row() > 0 ) {
6114 // include (USCES_PLUGIN_DIR . '/includes/cart_table.php');
6115 } else {
6116 echo "<div class='no_cart'>" . __( 'There are no items in your cart.', 'usces' ) . "</div>\n";
6117 }
6118 }
6119
6120 public function display_cart_confirm() {
6121 if ( $this->cart->num_row() > 0 ) {
6122 // include (USCES_PLUGIN_DIR . '/includes/cart_confirm.php');
6123 } else {
6124 echo "<div class='no_cart'>" . __( 'There are no items in your cart.', 'usces' ) . "</div>\n";
6125 }
6126 }
6127
6128 public function set_initial() {
6129 $this->set_default_page();
6130 $this->set_default_categories();
6131 $this->create_table();
6132 $this->update_table();
6133 $rets07 = usces_upgrade_07();
6134 if ( $rets07 ) {
6135 $rets11 = usces_upgrade_11();
6136 }
6137 if ( $rets11 ) {
6138 $rets14 = usces_upgrade_14();
6139 }
6140 if ( $rets14 ) {
6141 $rets141 = usces_upgrade_141();
6142 }
6143 if ( $rets141 ) {
6144 $rets143 = usces_upgrade_143();
6145 }
6146 $this->update_options();
6147 usces_schedule_event();
6148 do_action( 'usces_on_plugin_activate' );
6149 }
6150
6151 public function deactivate() {
6152 wp_clear_scheduled_hook( 'wc_cron' );
6153 wp_clear_scheduled_hook( 'wc_cron_w' );
6154 usces_wcsite_deactivate();
6155 }
6156
6157 public function create_table() {
6158 global $wpdb;
6159
6160 if ( ! empty( $wpdb->charset ) ) {
6161 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
6162 }
6163 if ( ! empty( $wpdb->collate ) ) {
6164 $charset_collate .= " COLLATE $wpdb->collate";
6165 }
6166 $access_table = $wpdb->prefix . 'usces_access';
6167 $member_table = $wpdb->prefix . 'usces_member';
6168 $member_meta_table = $wpdb->prefix . 'usces_member_meta';
6169 $order_table = $wpdb->prefix . 'usces_order';
6170 $order_meta_table = $wpdb->prefix . 'usces_order_meta';
6171 $ordercart_table = $wpdb->prefix . 'usces_ordercart';
6172 $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
6173 $log_table = $wpdb->prefix . 'usces_log';
6174 $acting_log_table = $wpdb->prefix . 'usces_acting_log';
6175 $item_table = $wpdb->prefix . 'usces_item';
6176 $sku_table = $wpdb->prefix . 'usces_skus';
6177 $opt_table = $wpdb->prefix . 'usces_opts';
6178 $admin_log_table = $wpdb->prefix . 'usces_admin_log';
6179
6180 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6181
6182 if ( $wpdb->get_var( "SHOW TABLES LIKE '$access_table'" ) != $access_table ) {
6183 $sql = 'CREATE TABLE ' . $access_table . " (
6184 ID BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT,
6185 acc_key VARCHAR( 50 ) NOT NULL ,
6186 acc_type VARCHAR( 50 ) NULL ,
6187 acc_value LONGTEXT NULL ,
6188 acc_date DATE NOT NULL DEFAULT '0000-00-00',
6189 acc_num1 INT( 11 ) NOT NULL DEFAULT 0,
6190 acc_num2 INT( 11 ) NOT NULL DEFAULT 0,
6191 acc_str1 VARCHAR( 200 ) NULL ,
6192 acc_str2 VARCHAR( 200 ) NULL ,
6193 PRIMARY KEY (`ID`),
6194 KEY acc_key ( acc_key ),
6195 KEY acc_type ( acc_type ),
6196 KEY acc_date ( acc_date ),
6197 KEY acc_num1 ( acc_num1 ),
6198 KEY acc_num2 ( acc_num2 )
6199 ) AUTO_INCREMENT=0 $charset_collate;";
6200 dbDelta( $sql );
6201 add_option( 'usces_db_access', USCES_DB_ACCESS );
6202 }
6203
6204 if ( $wpdb->get_var( "SHOW TABLES LIKE '$member_table'" ) != $member_table ) {
6205 $sql = 'CREATE TABLE ' . $member_table . " (
6206 ID BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT,
6207 mem_email VARCHAR( 100 ) NOT NULL ,
6208 mem_pass VARCHAR( 64 ) NOT NULL ,
6209 mem_status INT( 11 ) NOT NULL DEFAULT '0',
6210 mem_cookie VARCHAR( 13 ) NULL ,
6211 mem_point INT( 11 ) NOT NULL DEFAULT '0',
6212 mem_name1 VARCHAR( 100 ) NOT NULL ,
6213 mem_name2 VARCHAR( 100 ) NULL ,
6214 mem_name3 VARCHAR( 100 ) NULL ,
6215 mem_name4 VARCHAR( 100 ) NULL ,
6216 mem_zip VARCHAR( 50 ) NULL ,
6217 mem_pref VARCHAR( 100 ) NOT NULL ,
6218 mem_address1 VARCHAR( 100 ) NOT NULL ,
6219 mem_address2 VARCHAR( 100 ) NULL ,
6220 mem_address3 VARCHAR( 100 ) NULL ,
6221 mem_tel VARCHAR( 100 ) NOT NULL ,
6222 mem_fax VARCHAR( 100 ) NULL ,
6223 mem_delivery_flag TINYINT ( 1 ) NULL ,
6224 mem_delivery LONGTEXT,
6225 mem_registered DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6226 mem_nicename VARCHAR( 50 ) NULL ,
6227 PRIMARY KEY (`ID`),
6228 KEY mem_email ( mem_email ) ,
6229 KEY mem_pass ( mem_pass )
6230 ) AUTO_INCREMENT=1000 $charset_collate;";
6231 dbDelta( $sql );
6232 add_option( 'usces_db_member', USCES_DB_MEMBER );
6233 }
6234
6235 if ( $wpdb->get_var( "SHOW TABLES LIKE '$member_meta_table'" ) != $member_meta_table ) {
6236 $sql = 'CREATE TABLE ' . $member_meta_table . " (
6237 mmeta_id bigint(20) NOT NULL auto_increment,
6238 member_id bigint(20) NOT NULL default '0',
6239 meta_key varchar(255) default NULL,
6240 meta_value longtext,
6241 PRIMARY KEY (mmeta_id),
6242 KEY order_id (member_id),
6243 KEY meta_key (meta_key(191))
6244 ) $charset_collate;";
6245 dbDelta( $sql );
6246 add_option( 'usces_db_member_meta', USCES_DB_MEMBER_META );
6247 }
6248
6249 if ( $wpdb->get_var( "SHOW TABLES LIKE '$order_table'" ) != $order_table ) {
6250 $sql = 'CREATE TABLE ' . $order_table . " (
6251 ID BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT,
6252 mem_id BIGINT( 20 ) UNSIGNED NULL ,
6253 order_email VARCHAR( 100 ) NOT NULL ,
6254 order_name1 VARCHAR( 100 ) NOT NULL ,
6255 order_name2 VARCHAR( 100 ) NULL ,
6256 order_name3 VARCHAR( 100 ) NULL ,
6257 order_name4 VARCHAR( 100 ) NULL ,
6258 order_zip VARCHAR( 50 ) NULL ,
6259 order_pref VARCHAR( 100 ) NOT NULL ,
6260 order_address1 VARCHAR( 100 ) NOT NULL ,
6261 order_address2 VARCHAR( 100 ) NULL ,
6262 order_address3 VARCHAR( 100 ) NULL ,
6263 order_tel VARCHAR( 100 ) NOT NULL ,
6264 order_fax VARCHAR( 100 ) NULL ,
6265 order_delivery LONGTEXT,
6266 order_cart LONGTEXT,
6267 order_note TEXT,
6268 order_delivery_time VARCHAR( 100 ) NOT NULL ,
6269 order_payment_name VARCHAR( 100 ) NOT NULL ,
6270 order_condition TEXT,
6271 order_item_total_price DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
6272 order_getpoint INT( 10 ) NOT NULL DEFAULT '0',
6273 order_usedpoint INT( 10 ) NOT NULL DEFAULT '0',
6274 order_discount DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
6275 order_shipping_charge DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
6276 order_cod_fee DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
6277 order_tax DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
6278 order_date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6279 order_modified VARCHAR( 20 ) NULL ,
6280 order_status VARCHAR( 255 ) NULL ,
6281 order_check TEXT NULL ,
6282 order_delidue_date VARCHAR( 30 ) NULL ,
6283 order_delivery_method INT( 10 ) NOT NULL DEFAULT -1,
6284 order_delivery_date VARCHAR( 100 ) NULL,
6285 PRIMARY KEY (`ID`),
6286 KEY order_email ( order_email ) ,
6287 KEY order_name1 ( order_name1 ) ,
6288 KEY order_name2 ( order_name2 ) ,
6289 KEY order_pref ( order_pref ) ,
6290 KEY order_address1 ( order_address1 ) ,
6291 KEY order_tel ( order_tel ) ,
6292 KEY mem_id ( mem_id ) ,
6293 KEY order_date ( order_date )
6294 ) AUTO_INCREMENT=1000 $charset_collate;";
6295 dbDelta( $sql );
6296 add_option( 'usces_db_order', USCES_DB_ORDER );
6297 }
6298
6299 if ( $wpdb->get_var( "SHOW TABLES LIKE '$order_meta_table'" ) != $order_meta_table ) {
6300 $sql = 'CREATE TABLE ' . $order_meta_table . " (
6301 ometa_id bigint(20) NOT NULL auto_increment,
6302 order_id bigint(20) NOT NULL default '0',
6303 meta_key varchar(255) default NULL,
6304 meta_value longtext,
6305 PRIMARY KEY (ometa_id),
6306 KEY order_id (order_id),
6307 KEY meta_key (meta_key(191))
6308 ) $charset_collate;";
6309 dbDelta( $sql );
6310 add_option( 'usces_db_order_meta', USCES_DB_ORDER_META );
6311 }
6312
6313 if ( $wpdb->get_var( "SHOW TABLES LIKE '$ordercart_table'" ) != $ordercart_table ) {
6314 $sql = 'CREATE TABLE ' . $ordercart_table . " (
6315 `cart_id` bigint( 20 ) unsigned NOT NULL AUTO_INCREMENT ,
6316 `order_id` bigint( 20 ) NOT NULL ,
6317 `group_id` int( 3 ) NOT NULL DEFAULT '0',
6318 `row_index` int( 3 ) NOT NULL ,
6319 `post_id` bigint( 20 ) NOT NULL ,
6320 `item_code` varchar( 100 ) NOT NULL ,
6321 `item_name` varchar( 250 ) NOT NULL ,
6322 `cprice` decimal( 12, 0 ) DEFAULT NULL ,
6323 `sku_code` varchar( 100 ) NOT NULL ,
6324 `sku_name` varchar( 250 ) DEFAULT NULL ,
6325 `price` decimal( 12, 0 ) NOT NULL ,
6326 `quantity` float NOT NULL ,
6327 `unit` varchar( 50 ) DEFAULT NULL ,
6328 `tax` decimal( 10, 0 ) DEFAULT NULL ,
6329 `destination_id` int( 10 ) DEFAULT NULL ,
6330 `cart_serial` text,
6331 PRIMARY KEY ( `cart_id` ) ,
6332 UNIQUE KEY `row` ( `row_index` , `destination_id` , `order_id` ) ,
6333 KEY `order_id` ( `order_id` ) ,
6334 KEY `post_id` ( `post_id` ) ,
6335 KEY `item_code` ( `item_code` ) ,
6336 KEY `item_name` ( `item_name`(191) ) ,
6337 KEY `sku_code` ( `sku_code` ) ,
6338 KEY `sku_name` ( `sku_name`(191) )
6339 ) AUTO_INCREMENT=1000 $charset_collate;";
6340 dbDelta( $sql );
6341 add_option( 'usces_db_ordercart', USCES_DB_ORDERCART );
6342 }
6343
6344 if ( $wpdb->get_var( "SHOW TABLES LIKE '$ordercart_meta_table'" ) != $ordercart_meta_table ) {
6345 $sql = 'CREATE TABLE ' . $ordercart_meta_table . " (
6346 `cartmeta_id` bigint( 20 ) NOT NULL AUTO_INCREMENT ,
6347 `cart_id` bigint( 20 ) NOT NULL DEFAULT '0',
6348 `meta_type` varchar( 100 ) NOT NULL ,
6349 `meta_key` varchar( 255 ) DEFAULT NULL ,
6350 `meta_value` longtext,
6351 PRIMARY KEY ( `cartmeta_id` ) ,
6352 KEY `cart_id` ( `cart_id` ) ,
6353 KEY `meta_key` ( `meta_key`(191) )
6354 ) $charset_collate;";
6355 dbDelta( $sql );
6356 add_option( 'usces_db_ordercart_meta', USCES_DB_ORDERCART_META );
6357 }
6358
6359 if ( $wpdb->get_var( "SHOW TABLES LIKE '$log_table'") != $log_table ) {
6360 $sql = 'CREATE TABLE ' . $log_table . " (
6361 ID BIGINT( 20 ) NOT NULL AUTO_INCREMENT,
6362 datetime DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6363 log LONGTEXT NULL,
6364 log_type VARCHAR( 100 ) DEFAULT NULL,
6365 log_key VARCHAR( 255 ) DEFAULT NULL,
6366 PRIMARY KEY ( ID ) ,
6367 KEY datetime ( datetime ),
6368 KEY log_type ( log_type ),
6369 KEY log_key ( log_key(191) )
6370 ) $charset_collate;";
6371 dbDelta( $sql );
6372 add_option( 'usces_db_log', USCES_DB_LOG );
6373 }
6374
6375 if ( $wpdb->get_var( "SHOW TABLES LIKE '$acting_log_table'" ) != $acting_log_table ) {
6376 $sql = 'CREATE TABLE ' . $acting_log_table . " (
6377 `ID` BIGINT(20) NOT NULL AUTO_INCREMENT,
6378 `datetime` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6379 `log` LONGTEXT NULL,
6380 `acting` CHAR(32) DEFAULT NULL,
6381 `status` CHAR(32) DEFAULT NULL,
6382 `result` CHAR(32) DEFAULT NULL,
6383 `amount` DECIMAL( 10, 2 ) DEFAULT NULL,
6384 `order_id` BIGINT(20) NOT NULL,
6385 `tracking_id` CHAR(32) DEFAULT NULL,
6386 PRIMARY KEY (`ID`),
6387 KEY `datetime` (`datetime`),
6388 KEY `order_id` (`order_id`),
6389 KEY `tracking_id` (`tracking_id`),
6390 KEY `history_key` (`order_id`,`tracking_id`)
6391 ) $charset_collate;";
6392 dbDelta( $sql );
6393 add_option( 'usces_db_acting_log', USCES_DB_ACTING_LOG );
6394 }
6395
6396 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$item_table}'" ) !== $item_table ) {
6397 $sql = 'CREATE TABLE ' . $item_table . ' (
6398 post_id BIGINT( 20 ) UNSIGNED NOT NULL,
6399 itemCode VARCHAR( 200 ) NULL ,
6400 itemName VARCHAR( 250 ) NULL ,
6401 itemRestriction VARCHAR( 20 ) NULL ,
6402 itemPointrate VARCHAR( 20 ) NULL ,
6403 itemGpNum1 VARCHAR( 20 ) NULL ,
6404 itemGpNum2 VARCHAR( 20 ) NULL ,
6405 itemGpNum3 VARCHAR( 20 ) NULL ,
6406 itemGpDis1 VARCHAR( 20 ) NULL ,
6407 itemGpDis2 VARCHAR( 20 ) NULL ,
6408 itemGpDis3 VARCHAR( 20 ) NULL ,
6409 itemOrderAcceptable INT( 2 ) NULL ,
6410 itemShipping INT( 3 ) NULL ,
6411 itemDeliveryMethod LONGTEXT ,
6412 itemShippingCharge VARCHAR( 200 ) NULL ,
6413 itemIndividualSCharge VARCHAR( 20 ) NULL ,
6414 item_charging_type INT( 3 ) NULL ,
6415 item_division VARCHAR( 50 ) NULL ,
6416 dlseller_date VARCHAR( 100 ) NULL ,
6417 dlseller_file VARCHAR( 200 ) NULL ,
6418 dlseller_interval VARCHAR( 20 ) NULL ,
6419 dlseller_validity VARCHAR( 20 ) NULL ,
6420 dlseller_version VARCHAR( 100 ) NULL ,
6421 dlseller_author VARCHAR( 200 ) NULL ,
6422 dlseller_purchases VARCHAR( 20 ) NULL ,
6423 dlseller_downloads VARCHAR( 20 ) NULL ,
6424 item_chargingday VARCHAR( 20 ) NULL ,
6425 item_frequency VARCHAR( 20 ) NULL ,
6426 wcad_regular_unit VARCHAR( 20 ) NULL ,
6427 wcad_regular_interval INT( 10 ) NULL ,
6428 wcad_regular_frequency INT( 10 ) NULL ,
6429 select_sku_switch INT( 10 ) NULL ,
6430 select_sku_display INT( 10 ) NULL ,
6431 select_sku LONGTEXT ,
6432 atobarai_propriety INT( 5 ) NULL ,
6433 atodene_propriety INT( 5 ) NULL ,
6434 structuredDataSku VARCHAR( 200 ) NULL ,
6435 lower_limit INT( 10 ) NULL ,
6436 popularity INT( 10 ) NULL ,
6437 main_price DECIMAL( 10, 2 ) NULL ,
6438 itemPicts TEXT NULL ,
6439 itemAdvanced LONGTEXT NULL ,
6440 PRIMARY KEY (`post_id`),
6441 KEY itemCode ( itemCode ) ,
6442 KEY itemName ( itemName )
6443 ) ' . $charset_collate . ';';
6444 dbDelta( $sql );
6445 add_option( 'usces_db_item', USCES_DB_ITEM );
6446 }
6447
6448 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$sku_table}'" ) !== $sku_table ) {
6449 $sql = 'CREATE TABLE ' . $sku_table . ' (
6450 meta_id BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT,
6451 post_id BIGINT( 20 ) UNSIGNED NOT NULL ,
6452 code VARCHAR( 200 ) NULL ,
6453 name VARCHAR( 250 ) NULL ,
6454 cprice DECIMAL( 10, 2 ) NULL ,
6455 price DECIMAL( 10, 2 ) NULL ,
6456 unit TEXT NULL ,
6457 stocknum VARCHAR( 50 ) NULL ,
6458 stock INT( 5 ) NULL ,
6459 gp INT( 2 ) NULL ,
6460 taxrate VARCHAR( 20 ) NULL ,
6461 size VARCHAR( 20 ) NULL ,
6462 weight VARCHAR( 20 ) NULL ,
6463 pict_id VARCHAR( 20 ) NULL ,
6464 advance LONGTEXT ,
6465 paternkey VARCHAR( 100 ) NULL ,
6466 sort INT( 5 ) NULL ,
6467 PRIMARY KEY (`meta_id`),
6468 KEY post_id ( post_id ) ,
6469 KEY code ( code ) ,
6470 KEY name ( name ) ,
6471 KEY price ( price ) ,
6472 KEY paternkey ( paternkey )
6473 ) ' . $charset_collate . ';';
6474 dbDelta( $sql );
6475 add_option( 'usces_db_skus', USCES_DB_SKUS );
6476 }
6477
6478 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$opt_table}'" ) !== $opt_table ) {
6479 $sql = 'CREATE TABLE ' . $opt_table . ' (
6480 meta_id BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT,
6481 post_id BIGINT( 20 ) UNSIGNED NOT NULL ,
6482 code VARCHAR( 200 ) NULL ,
6483 name VARCHAR( 250 ) NULL ,
6484 means INT( 3 ) NULL ,
6485 essential INT( 3 ) NULL ,
6486 value TEXT ,
6487 sort INT( 5 ) NULL ,
6488 PRIMARY KEY (`meta_id`),
6489 KEY post_id ( post_id ) ,
6490 KEY code ( code ) ,
6491 KEY name ( name )
6492 ) ' . $charset_collate . ';';
6493 dbDelta( $sql );
6494 add_option( 'usces_db_opts', USCES_DB_OPTS );
6495 }
6496
6497 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$admin_log_table}'" ) !== $admin_log_table ) {
6498 $sql = "CREATE TABLE {$admin_log_table} (
6499 `ID` int(11) NOT NULL AUTO_INCREMENT,
6500 `author` varchar(64) NOT NULL,
6501 `message` longtext NOT NULL,
6502 `screen` varchar(64) NOT NULL,
6503 `entity_id` varchar(64) DEFAULT NULL,
6504 `action` varchar(64) NOT NULL,
6505 `data` longblob DEFAULT NULL,
6506 `datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
6507 PRIMARY KEY (`ID`),
6508 KEY entity_id ( entity_id )
6509 ) " . $charset_collate . ';';
6510 dbDelta( $sql );
6511 add_option( 'usces_db_admin_log', USCES_DB_ADMIN_LOG );
6512 }
6513
6514 do_action( 'usces_action_create_table' );
6515 }
6516
6517 public function update_table() {
6518 global $wpdb;
6519 $access_table = $wpdb->prefix . 'usces_access';
6520 $member_table = $wpdb->prefix . 'usces_member';
6521 $member_meta_table = $wpdb->prefix . 'usces_member_meta';
6522 $order_table = $wpdb->prefix . 'usces_order';
6523 $order_meta_table = $wpdb->prefix . 'usces_order_meta';
6524 $ordercart_table = $wpdb->prefix . 'usces_ordercart';
6525 $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
6526 $log_table = $wpdb->prefix . 'usces_log';
6527 $acting_log_table = $wpdb->prefix . 'usces_acting_log';
6528 $item_table = $wpdb->prefix . 'usces_item';
6529 $sku_table = $wpdb->prefix . 'usces_skus';
6530 $opt_table = $wpdb->prefix . 'usces_opts';
6531 $admin_log_table = $wpdb->prefix . 'usces_admin_log';
6532
6533 $access_ver = get_option( 'usces_db_access' );
6534 $member_ver = get_option( 'usces_db_member' );
6535 $member_meta_ver = get_option( 'usces_db_member_meta' );
6536 $order_ver = get_option( 'usces_db_order' );
6537 $order_meta_ver = get_option( 'usces_db_order_meta' );
6538 $ordercart_ver = get_option( 'usces_db_ordercart' );
6539 $ordercart_meta_ver = get_option( 'usces_db_ordercart_meta' );
6540 $log_ver = get_option( 'usces_db_log' );
6541 $acting_log_ver = get_option( 'usces_db_acting_log' );
6542 $db_item = get_option( 'usces_db_item' );
6543 $db_skus = get_option( 'usces_db_skus' );
6544 $db_opts = get_option( 'usces_db_opts' );
6545 $db_admin_log = get_option( 'usces_db_admin_log' );
6546
6547 if ( $access_ver != USCES_DB_ACCESS ) {
6548 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6549 $sql = 'CREATE TABLE ' . $access_table . " (
6550 ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
6551 acc_key VARCHAR(50) NOT NULL ,
6552 acc_type VARCHAR(50) NULL ,
6553 acc_value LONGTEXT NULL ,
6554 acc_date DATE NOT NULL DEFAULT '0000-00-00',
6555 acc_num1 INT(11) NOT NULL DEFAULT 0,
6556 acc_num2 INT(11) NOT NULL DEFAULT 0,
6557 acc_str1 VARCHAR(200) NULL ,
6558 acc_str2 VARCHAR(200) NULL ,
6559 PRIMARY KEY (`ID`),
6560 KEY acc_key (acc_key),
6561 KEY acc_type (acc_type),
6562 KEY acc_date (acc_date),
6563 KEY acc_num1 (acc_num1),
6564 KEY acc_num2 (acc_num2)
6565 );";
6566 dbDelta( $sql );
6567 update_option( 'usces_db_access', USCES_DB_ACCESS );
6568 }
6569
6570 if ( USCES_DB_MEMBER != $member_ver ) {
6571 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6572 $sql = 'CREATE TABLE ' . $member_table . " (
6573 ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
6574 mem_email VARCHAR(100) NOT NULL ,
6575 mem_pass VARCHAR(64) NOT NULL ,
6576 mem_status INT(11) NOT NULL DEFAULT '0',
6577 mem_cookie VARCHAR(13) NULL ,
6578 mem_point INT(11) NOT NULL DEFAULT '0',
6579 mem_name1 VARCHAR(100) NOT NULL ,
6580 mem_name2 VARCHAR(100) NULL ,
6581 mem_name3 VARCHAR(100) NULL ,
6582 mem_name4 VARCHAR(100) NULL ,
6583 mem_zip VARCHAR(50) NULL ,
6584 mem_pref VARCHAR(100) NOT NULL ,
6585 mem_address1 VARCHAR(100) NOT NULL ,
6586 mem_address2 VARCHAR(100) NULL ,
6587 mem_address3 VARCHAR(100) NULL ,
6588 mem_tel VARCHAR(100) NOT NULL ,
6589 mem_fax VARCHAR(100) NULL ,
6590 mem_delivery_flag TINYINT (1) NULL ,
6591 mem_delivery LONGTEXT,
6592 mem_registered DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6593 mem_nicename VARCHAR(50) NULL ,
6594 PRIMARY KEY (`ID`),
6595 KEY mem_email (mem_email) ,
6596 KEY mem_pass (mem_pass)
6597 );";
6598 dbDelta( $sql );
6599 update_option( 'usces_db_member', USCES_DB_MEMBER );
6600 }
6601
6602 if ( USCES_DB_MEMBER_META != $member_meta_ver ) {
6603 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6604 $sql = 'CREATE TABLE ' . $member_meta_table . " (
6605 mmeta_id bigint(20) NOT NULL auto_increment,
6606 member_id bigint(20) NOT NULL default '0',
6607 meta_key varchar(255) default NULL,
6608 meta_value longtext,
6609 PRIMARY KEY (`mmeta_id`),
6610 KEY order_id (member_id),
6611 KEY meta_key (meta_key(191))
6612 );";
6613 dbDelta( $sql );
6614 update_option( 'usces_db_member_meta', USCES_DB_MEMBER_META );
6615 }
6616
6617 if ( USCES_DB_ORDER != $order_ver ) {
6618 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6619 $sql = 'CREATE TABLE ' . $order_table . " (
6620 ID bigint(20) unsigned NOT NULL auto_increment,
6621 mem_id BIGINT(20) UNSIGNED NULL,
6622 order_email VARCHAR(100) NOT NULL,
6623 order_name1 VARCHAR(100) NOT NULL,
6624 order_name2 VARCHAR(100) NULL,
6625 order_name3 VARCHAR(100) NULL,
6626 order_name4 VARCHAR(100) NULL,
6627 order_zip VARCHAR(50) NULL,
6628 order_pref VARCHAR(100) NOT NULL,
6629 order_address1 VARCHAR(100) NOT NULL,
6630 order_address2 VARCHAR(100) NULL,
6631 order_address3 VARCHAR(100) NULL,
6632 order_tel VARCHAR(100) NOT NULL,
6633 order_fax VARCHAR(100) NULL,
6634 order_delivery LONGTEXT,
6635 order_cart LONGTEXT,
6636 order_note TEXT,
6637 order_delivery_time VARCHAR(100) NOT NULL,
6638 order_payment_name VARCHAR(100) NOT NULL,
6639 order_condition TEXT,
6640 order_item_total_price DECIMAL(10,2) NOT NULL DEFAULT '0.00',
6641 order_getpoint INT(10) NOT NULL DEFAULT '0',
6642 order_usedpoint INT(10) NOT NULL DEFAULT '0',
6643 order_discount DECIMAL(10,2) NOT NULL DEFAULT '0.00',
6644 order_shipping_charge DECIMAL(10,2) NOT NULL DEFAULT '0.00',
6645 order_cod_fee DECIMAL(10,2) NOT NULL DEFAULT '0.00',
6646 order_tax DECIMAL(10,2) NOT NULL DEFAULT '0.00',
6647 order_date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6648 order_modified VARCHAR(20) NULL,
6649 order_status VARCHAR(255) NULL,
6650 order_check TEXT NULL,
6651 order_delidue_date VARCHAR(30) NULL,
6652 order_delivery_method INT(10) NOT NULL DEFAULT -1,
6653 order_delivery_date VARCHAR(100) NULL,
6654 PRIMARY KEY (`ID`),
6655 KEY order_email (order_email),
6656 KEY order_name1 (order_name1),
6657 KEY order_name2 (order_name2),
6658 KEY order_pref (order_pref),
6659 KEY order_address1 (order_address1),
6660 KEY order_tel (order_tel),
6661 KEY mem_id ( mem_id ) ,
6662 KEY order_date (order_date)
6663 );";
6664 dbDelta( $sql );
6665 update_option( 'usces_db_order', USCES_DB_ORDER );
6666 }
6667
6668 if ( USCES_DB_ORDER_META != $order_meta_ver ) {
6669 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6670 $sql = 'CREATE TABLE ' . $order_meta_table . " (
6671 ometa_id bigint(20) NOT NULL auto_increment,
6672 order_id bigint(20) NOT NULL default '0',
6673 meta_key varchar(255) default NULL,
6674 meta_value longtext,
6675 PRIMARY KEY (`ometa_id`),
6676 KEY order_id (order_id),
6677 KEY meta_key (meta_key)
6678 );";
6679 dbDelta( $sql );
6680 update_option( 'usces_db_order_meta', USCES_DB_ORDER_META );
6681 }
6682
6683 if ( USCES_DB_ORDERCART != $ordercart_ver ) {
6684 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6685 $sql = 'CREATE TABLE ' . $ordercart_table . " (
6686 cart_id bigint(20) unsigned NOT NULL AUTO_INCREMENT ,
6687 order_id bigint(20) NOT NULL ,
6688 group_id int(3) NOT NULL DEFAULT '0',
6689 row_index int(3) NOT NULL ,
6690 post_id bigint(20) NOT NULL ,
6691 item_code varchar(100) NOT NULL ,
6692 item_name varchar(250) NOT NULL ,
6693 cprice decimal(12,0) DEFAULT NULL ,
6694 sku_code varchar(100) NOT NULL ,
6695 sku_name varchar(250) DEFAULT NULL ,
6696 price decimal(12,0) NOT NULL ,
6697 quantity float NOT NULL ,
6698 unit varchar(50) DEFAULT NULL ,
6699 tax decimal(10,0) DEFAULT NULL ,
6700 destination_id int(10) DEFAULT NULL ,
6701 cart_serial text,
6702 UNIQUE KEY row (row_index,destination_id,order_id) ,
6703 PRIMARY KEY (`cart_id`),
6704 KEY order_id (order_id) ,
6705 KEY post_id (post_id) ,
6706 KEY item_code (item_code) ,
6707 KEY item_name (item_name(191)) ,
6708 KEY sku_code (sku_code) ,
6709 KEY sku_name (sku_name(191))
6710 );";
6711 dbDelta( $sql );
6712 update_option( 'usces_db_ordercart', USCES_DB_ORDERCART );
6713 }
6714
6715 if ( USCES_DB_ORDERCART_META != $ordercart_meta_ver ) {
6716 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6717 $sql = 'CREATE TABLE ' . $ordercart_meta_table . " (
6718 cartmeta_id bigint(20) NOT NULL AUTO_INCREMENT,
6719 cart_id bigint(20) NOT NULL DEFAULT '0',
6720 meta_type varchar(100) NOT NULL ,
6721 meta_key varchar(255) DEFAULT NULL ,
6722 meta_value longtext,
6723 PRIMARY KEY (`cartmeta_id`),
6724 KEY cart_id (cart_id) ,
6725 KEY meta_key (meta_key(191))
6726 );";
6727 dbDelta( $sql );
6728 update_option( 'usces_db_ordercart_meta', USCES_DB_ORDERCART_META );
6729 }
6730
6731 if ( USCES_DB_LOG != $log_ver ) {
6732 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6733 $sql = 'CREATE TABLE ' . $log_table . " (
6734 ID bigint(20) NOT NULL AUTO_INCREMENT,
6735 datetime DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6736 log LONGTEXT NULL,
6737 log_type VARCHAR(100) DEFAULT NULL,
6738 log_key VARCHAR(255) DEFAULT NULL,
6739 PRIMARY KEY (`ID`),
6740 KEY datetime (datetime),
6741 KEY log_type (log_type),
6742 KEY log_key (log_key(191))
6743 );";
6744 dbDelta( $sql );
6745 update_option( 'usces_db_log', USCES_DB_LOG );
6746 }
6747
6748 if ( USCES_DB_ACTING_LOG != $acting_log_ver ) {
6749 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6750 $sql = 'CREATE TABLE ' . $acting_log_table . " (
6751 `ID` BIGINT(20) NOT NULL AUTO_INCREMENT,
6752 `datetime` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6753 `log` LONGTEXT NULL,
6754 `acting` CHAR(32) DEFAULT NULL,
6755 `status` CHAR(32) DEFAULT NULL,
6756 `result` CHAR(32) DEFAULT NULL,
6757 `amount` DECIMAL( 10, 2 ) DEFAULT NULL,
6758 `order_id` BIGINT(20) NOT NULL,
6759 `tracking_id` CHAR(32) DEFAULT NULL,
6760 PRIMARY KEY (`ID`),
6761 KEY `datetime` (`datetime`),
6762 KEY `order_id` (`order_id`),
6763 KEY `tracking_id` (`tracking_id`),
6764 KEY `history_key` (`order_id`,`tracking_id`)
6765 );";
6766 dbDelta( $sql );
6767 update_option( 'usces_db_acting_log', USCES_DB_ACTING_LOG );
6768 }
6769
6770 if ( USCES_DB_ITEM != $db_item ) {
6771 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6772 $sql = 'CREATE TABLE ' . $item_table . ' (
6773 post_id BIGINT( 20 ) UNSIGNED NOT NULL ,
6774 itemCode VARCHAR( 200 ) NULL ,
6775 itemName VARCHAR( 250 ) NULL ,
6776 itemRestriction VARCHAR( 20 ) NULL ,
6777 itemPointrate VARCHAR( 20 ) NULL ,
6778 itemGpNum1 VARCHAR( 20 ) NULL ,
6779 itemGpNum2 VARCHAR( 20 ) NULL ,
6780 itemGpNum3 VARCHAR( 20 ) NULL ,
6781 itemGpDis1 VARCHAR( 20 ) NULL ,
6782 itemGpDis2 VARCHAR( 20 ) NULL ,
6783 itemGpDis3 VARCHAR( 20 ) NULL ,
6784 itemOrderAcceptable INT( 2 ) NULL ,
6785 itemShipping INT( 3 ) NULL ,
6786 itemDeliveryMethod LONGTEXT ,
6787 itemShippingCharge VARCHAR( 200 ) NULL ,
6788 itemIndividualSCharge VARCHAR( 20 ) NULL ,
6789 item_charging_type INT( 3 ) NULL ,
6790 item_division VARCHAR( 50 ) NULL ,
6791 dlseller_date VARCHAR( 100 ) NULL ,
6792 dlseller_file VARCHAR( 200 ) NULL ,
6793 dlseller_interval VARCHAR( 20 ) NULL ,
6794 dlseller_validity VARCHAR( 20 ) NULL ,
6795 dlseller_version VARCHAR( 100 ) NULL ,
6796 dlseller_author VARCHAR( 200 ) NULL ,
6797 dlseller_purchases VARCHAR( 20 ) NULL ,
6798 dlseller_downloads VARCHAR( 20 ) NULL ,
6799 item_chargingday VARCHAR( 20 ) NULL ,
6800 item_frequency VARCHAR( 20 ) NULL ,
6801 wcad_regular_unit VARCHAR( 20 ) NULL ,
6802 wcad_regular_interval INT( 10 ) NULL ,
6803 wcad_regular_frequency INT( 10 ) NULL ,
6804 select_sku_switch INT( 10 ) NULL ,
6805 select_sku_display INT( 10 ) NULL ,
6806 select_sku LONGTEXT ,
6807 atobarai_propriety INT( 5 ) NULL ,
6808 atodene_propriety INT( 5 ) NULL ,
6809 structuredDataSku VARCHAR( 200 ) NULL ,
6810 lower_limit INT( 10 ) NULL ,
6811 popularity INT( 10 ) NULL ,
6812 main_price DECIMAL( 10, 2 ) NULL ,
6813 itemPicts TEXT NULL ,
6814 itemAdvanced LONGTEXT NULL ,
6815 PRIMARY KEY (`post_id`),
6816 KEY itemCode ( itemCode ) ,
6817 KEY itemName ( itemName )
6818 );';
6819 dbDelta( $sql );
6820 update_option( 'usces_db_item', USCES_DB_ITEM );
6821 }
6822
6823 if ( USCES_DB_SKUS != $db_skus ) {
6824 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6825 $sql = 'CREATE TABLE ' . $sku_table . ' (
6826 meta_id BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
6827 post_id BIGINT( 20 ) UNSIGNED NOT NULL ,
6828 code VARCHAR( 200 ) NULL ,
6829 name VARCHAR( 250 ) NULL ,
6830 cprice DECIMAL( 10, 2 ) NULL ,
6831 price DECIMAL( 10, 2 ) NULL ,
6832 unit TEXT NULL ,
6833 stocknum VARCHAR( 50 ) NULL ,
6834 stock INT( 5 ) NULL ,
6835 gp INT( 2 ) NULL ,
6836 taxrate VARCHAR( 20 ) NULL ,
6837 size VARCHAR( 20 ) NULL ,
6838 weight VARCHAR( 20 ) NULL ,
6839 pict_id VARCHAR( 20 ) NULL ,
6840 advance LONGTEXT ,
6841 paternkey VARCHAR( 100 ) NULL ,
6842 sort INT( 5 ) NULL ,
6843 PRIMARY KEY (`meta_id`),
6844 KEY post_id ( post_id ) ,
6845 KEY code ( code ) ,
6846 KEY name ( name ) ,
6847 KEY price ( price ) ,
6848 KEY paternkey ( paternkey )
6849 );';
6850 dbDelta( $sql );
6851 update_option( 'usces_db_skus', USCES_DB_SKUS );
6852 }
6853
6854 if ( USCES_DB_OPTS != $db_opts ) {
6855 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6856 $sql = 'CREATE TABLE ' . $opt_table . ' (
6857 meta_id BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
6858 post_id BIGINT( 20 ) UNSIGNED NOT NULL ,
6859 code VARCHAR( 200 ) NULL ,
6860 name VARCHAR( 250 ) NULL ,
6861 means INT( 3 ) NULL ,
6862 essential INT( 3 ) NULL ,
6863 value TEXT ,
6864 sort INT( 5 ) NULL ,
6865 PRIMARY KEY (`meta_id`),
6866 KEY post_id ( post_id ) ,
6867 KEY code ( code ) ,
6868 KEY name ( name )
6869 );';
6870 dbDelta( $sql );
6871 update_option( 'usces_db_opts', USCES_DB_OPTS );
6872 }
6873
6874 if ( USCES_DB_ADMIN_LOG != $db_admin_log ) {
6875 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6876 $sql = "CREATE TABLE {$admin_log_table} (
6877 `ID` int(11) NOT NULL AUTO_INCREMENT,
6878 `author` varchar(64) NOT NULL,
6879 `message` longtext NOT NULL,
6880 `screen` varchar(64) NOT NULL,
6881 `entity_id` varchar(64) DEFAULT NULL,
6882 `action` varchar(64) NOT NULL,
6883 `data` longblob DEFAULT NULL,
6884 `datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
6885 PRIMARY KEY (`ID`),
6886 KEY entity_id ( entity_id )
6887 );";
6888 dbDelta( $sql );
6889 update_option( 'usces_db_admin_log', USCES_DB_ADMIN_LOG );
6890 }
6891
6892 do_action( 'usces_action_update_table' );
6893 }
6894
6895 public function dir_copy( $source, $dest ) {
6896 if ( $res = opendir( $source ) ) {
6897 while ( ( $file = readdir( $res ) ) !== false ) {
6898 $sorce_path = $source . '/' . $file;
6899 $dest_path = $dest . '/' . $file;
6900 $filetype = @filetype( $sorce_path );
6901 if ( 'file' == $filetype ) {
6902 copy( $sorce_path, $dest_path );
6903 } elseif ( 'dir' == $filetype && '..' != $file && '.' != $file ) {
6904 mkdir( $dest_path );
6905 $this->dir_copy( $sorce_path, $dest_path );
6906 }
6907 }
6908 closedir( $res );
6909 }
6910 }
6911
6912 public function set_default_page() {
6913 global $wpdb;
6914
6915 $datetime = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) );
6916 $datetime_gmt = gmdate( 'Y-m-d H:i:s', time() );
6917
6918 // cart_page.
6919 $query = $wpdb->prepare( "SELECT ID from $wpdb->posts where post_name = %s", USCES_CART_FOLDER );
6920 $cart_number = $wpdb->get_var( $query );
6921 if ( null === $cart_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, '', __( 'Cart', 'usces' ), '', 'publish',
6931 'closed', 'closed', '', USCES_CART_FOLDER, '', '', $datetime, $datetime_gmt,
6932 '', 0, '', 0, 'page', '', 0
6933 );
6934 $wpdb->query( $query );
6935 $cart_number = $wpdb->insert_id;
6936 if ( null !== $cart_number ) {
6937 $query = $wpdb->prepare(
6938 "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) VALUES (%d, %s, %s)",
6939 $cart_number, '_wp_page_template', 'uscescart.php'
6940 );
6941 $wpdb->query( $query );
6942 }
6943 }
6944 update_option( 'usces_cart_number', $cart_number );
6945
6946 // member_page.
6947 $query = $wpdb->prepare( "SELECT ID from $wpdb->posts where post_name = %s", USCES_MEMBER_FOLDER );
6948 $member_number = $wpdb->get_var( $query );
6949 if ( null === $member_number ) {
6950 $query = $wpdb->prepare(
6951 "INSERT INTO $wpdb->posts
6952 (post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status,
6953 comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt,
6954 post_content_filtered, post_parent, guid, menu_order, post_type, post_mime_type, comment_count)
6955 VALUES (%d, %s, %s, %s, %s, %s, %s,
6956 %s, %s, %s, %s, %s, %s, %s, %s,
6957 %s, %d, %s, %d, %s, %s, %d)",
6958 1, $datetime, $datetime_gmt, '', __( 'Membership', 'usces' ), '', 'publish',
6959 'closed', 'closed', '', USCES_MEMBER_FOLDER, '', '', $datetime, $datetime_gmt,
6960 '', 0, '', 0, 'page', '', 0
6961 );
6962 $wpdb->query( $query );
6963 $member_number = $wpdb->insert_id;
6964 if ( null !== $member_number ) {
6965 $query = $wpdb->prepare(
6966 "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) VALUES (%d, %s, %s)",
6967 $member_number, '_wp_page_template', 'uscesmember.php'
6968 );
6969 $wpdb->query( $query );
6970 }
6971 }
6972 update_option( 'usces_member_number', $member_number );
6973 }
6974
6975 public function set_default_categories() {
6976 global $wpdb;
6977
6978 $item_category_slug = apply_filters( 'usces_item_category_slug', 'item' );
6979
6980 $idObj = get_category_by_slug( $item_category_slug );
6981 if ( empty( $idObj ) ) {
6982 $item_cat = array(
6983 'cat_name' => __( 'Items', 'usces' ),
6984 'category_description' => '',
6985 'category_nicename' => $item_category_slug,
6986 'category_parent' => 0,
6987 );
6988 $item_cat_id = wp_insert_category( $item_cat );
6989 update_option( 'usces_item_cat_parent_id', $item_cat_id );
6990 }
6991
6992 $idObj = get_category_by_slug( 'itemreco' );
6993 if ( empty( $idObj ) && isset( $item_cat_id ) ) {
6994 $itemreco_cat = array(
6995 'cat_name' => __( 'Items recommended', 'usces' ),
6996 'category_description' => '',
6997 'category_nicename' => 'itemreco',
6998 'category_parent' => $item_cat_id,
6999 );
7000 $itemreco_cat_id = wp_insert_category( $itemreco_cat );
7001 }
7002
7003 $idObj = get_category_by_slug( 'itemnew' );
7004 if ( empty( $idObj ) && isset( $item_cat_id ) ) {
7005 $itemnew_cat = array(
7006 'cat_name' => __( 'New items', 'usces' ),
7007 'category_description' => '',
7008 'category_nicename' => 'itemnew',
7009 'category_parent' => $item_cat_id,
7010 );
7011 $itemnew_cat_id = wp_insert_category( $itemnew_cat );
7012 }
7013
7014 $idObj = get_category_by_slug( 'itemgenre' );
7015 if ( empty( $idObj ) && isset( $item_cat_id ) ) {
7016 $itemgenre_cat = array(
7017 'cat_name' => __( 'Item genre', 'usces' ),
7018 'category_description' => '',
7019 'category_nicename' => 'itemgenre',
7020 'category_parent' => $item_cat_id,
7021 );
7022 $itemgenre_cat_id = wp_insert_category( $itemgenre_cat );
7023 }
7024 }
7025
7026 public function update_options() {
7027 $target_market = $this->options['system']['target_market'];
7028
7029 $update_shipping_charge = false;
7030 $shipping_charge = isset( $this->options['shipping_charge'] ) ? $this->options['shipping_charge'] : array();
7031 $shipping_charge_count = ( $shipping_charge && is_array( $shipping_charge ) ) ? count( $shipping_charge ) : 0;
7032 foreach ( (array) $target_market as $tm ) {
7033 for ( $i = 0; $i < $shipping_charge_count; $i++ ) {
7034 if ( isset( $shipping_charge[ $i ]['country'] ) && $shipping_charge[ $i ]['country'] == $tm ) {
7035 foreach ( $shipping_charge[ $i ]['value'] as $pref => $value ) {
7036 $shipping_charge[ $i ][ $tm ][ $pref ] = $value;
7037 }
7038 unset( $shipping_charge[ $i ]['country'] );
7039 unset( $shipping_charge[ $i ]['value'] );
7040 $update_shipping_charge = true;
7041 }
7042 }
7043 }
7044 if ( $update_shipping_charge ) {
7045 $this->options['shipping_charge'] = $shipping_charge;
7046 }
7047
7048 $update_delivery_days = false;
7049 $delivery_days = isset( $this->options['delivery_days'] ) ? $this->options['delivery_days'] : array();
7050 $delivery_days_count = ( $delivery_days && is_array( $delivery_days ) ) ? count( $delivery_days ) : 0;
7051 foreach ( (array) $target_market as $tm ) {
7052 for ( $i = 0; $i < $delivery_days_count; $i++ ) {
7053 if ( isset( $delivery_days[ $i ]['country'] ) && $delivery_days[ $i ]['country'] == $tm ) {
7054 foreach ( $delivery_days[ $i ]['value'] as $pref => $value ) {
7055 $delivery_days[ $i ][ $tm ][ $pref ] = $value;
7056 }
7057 unset( $delivery_days[ $i ]['country'] );
7058 unset( $delivery_days[ $i ]['value'] );
7059 $update_delivery_days = true;
7060 }
7061 }
7062 }
7063 if ( $update_delivery_days ) {
7064 $this->options['delivery_days'] = $delivery_days;
7065 }
7066
7067 if ( $update_shipping_charge || $update_delivery_days ) {
7068 update_option( 'usces', $this->options );
7069 }
7070 }
7071
7072 public function get_item_cat_ids() {
7073 $ids = array();
7074 $args = array(
7075 'child_of' => USCES_ITEM_CAT_PARENT_ID,
7076 'hide_empty' => 0,
7077 'hierarchical' => 0,
7078 );
7079 $categories = get_categories( $args );
7080 foreach ( (array) $categories as $category ) {
7081 $ids[] = $category->term_id;
7082 }
7083 return $ids;
7084 }
7085
7086 public function get_item_post_ids() {
7087 global $wpdb;
7088 $query = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_mime_type = %s", 'item' );
7089 $ids = $wpdb->get_col( $query );
7090
7091 return $ids;
7092 }
7093
7094 public function get_item_cat_genre_ids( $post_id ) {
7095 $ids = array();
7096 $all_ids = array();
7097 $genre = get_category_by_slug( 'itemgenre' );
7098 if ( ! empty( $genre->term_id ) ) {
7099 $genre_id = $genre->term_id;
7100 $args = array(
7101 'child_of' => $genre_id,
7102 'hide_empty' => 0,
7103 'hierarchical' => 0,
7104 );
7105 $categories = get_categories( $args );
7106 foreach ( (array) $categories as $category ) {
7107 $ids[] = $category->term_id;
7108 }
7109 $allcats = get_the_category( $post_id );
7110 foreach ( (array) $allcats as $cat ) {
7111 $all_ids[] = $cat->term_id;
7112 }
7113 $results = array_intersect( $ids, $all_ids );
7114 } else {
7115 $results = array();
7116 }
7117 return $results;
7118 }
7119
7120 public function set_item_mime( $post_id, $str ) {
7121 global $wpdb;
7122 if ( WCUtils::is_blank( $str ) ) {
7123 return;
7124 }
7125 $query = $wpdb->prepare( "UPDATE $wpdb->posts SET post_mime_type = %s WHERE ID = %s", $str, $post_id );
7126 $results = $wpdb->query( $query );
7127 return $results;
7128 }
7129
7130 public function isAdnminSSL() {
7131 $plugins = get_option( 'active_plugins' );
7132 foreach ( $plugins as $plugin ) {
7133 if ( false !== strpos( $plugin, USCES_ADMIN_SSL_BASE_NAME ) ) {
7134 return true;
7135 }
7136 }
7137 return false;
7138 }
7139
7140 public function getGuidTax() {
7141 if ( isset( $this->options['tax_display'] ) && 'deactivate' == $this->options['tax_display'] ) {
7142 $str = '';
7143 } else {
7144 $tax_rate = (int) $this->options['tax_rate'];
7145
7146 if ( isset( $this->options['tax_mode'] ) ) {
7147 if ( 'exclude' == $this->options['tax_mode'] ) {
7148 $str = '<em class="tax">' . __( '(Excl. Tax)', 'usces' ) . '</em>';
7149 } else {
7150 $str = '<em class="tax">' . __( '(Incl. Tax)', 'usces' ) . '</em>';
7151 }
7152 } else {
7153 if ( 0 < $tax_rate ) {
7154 $str = '<em class="tax">' . __( '(Excl. Tax)', 'usces' ) . '</em>';
7155 } else {
7156 $str = '<em class="tax">' . __( '(Incl. Tax)', 'usces' ) . '</em>';
7157 }
7158 }
7159 $str = apply_filters( 'usces_filter_tax_guid', $str, $tax_rate );
7160 }
7161 return $str;
7162 }
7163
7164 public function getItemCode( $post_id, $cache = true ) {
7165 $product = wel_get_product( $post_id, $cache );
7166 $itemCode = isset( $product['itemCode'] ) ? $product['itemCode'] : null;
7167 return $itemCode;
7168 }
7169
7170 public function getItemName( $post_id, $cache = true ) {
7171 $product = wel_get_product( $post_id, $cache );
7172 $itemName = isset( $product['itemName'] ) ? $product['itemName'] : null;
7173 return $itemName;
7174 }
7175
7176 public function getItemRestriction( $post_id, $cache = true ) {
7177 $product = wel_get_product( $post_id, $cache );
7178 $itemRestriction = isset( $product['itemRestriction'] ) ? $product['itemRestriction'] : null;
7179 return $itemRestriction;
7180 }
7181
7182 public function getItemOrderAcceptable( $post_id, $cache = true ) {
7183 $product = wel_get_product( $post_id, $cache );
7184 $value = ( ! empty( $product['itemOrderAcceptable'] ) ) ? (int) $product['itemOrderAcceptable'] : 0;
7185 return $value;
7186 }
7187
7188 public function getItemPointrate( $post_id, $cache = true ) {
7189 $product = wel_get_product( $post_id, $cache );
7190 $itemPointrate = isset( $product['itemPointrate'] ) ? $product['itemPointrate'] : null;
7191 return $itemPointrate;
7192 }
7193
7194 public function getItemShipping( $post_id, $cache = true ) {
7195 $product = wel_get_product( $post_id, $cache );
7196 $itemShipping = isset( $product['itemShipping'] ) ? $product['itemShipping'] : null;
7197 return $itemShipping;
7198 }
7199
7200 public function getItemShippingCharge( $post_id, $cache = true ) {
7201 $product = wel_get_product( $post_id, $cache );
7202 $itemShippingCharge = isset( $product['itemShippingCharge'] ) ? (float) $product['itemShippingCharge'] : null;
7203 return $itemShippingCharge;
7204 }
7205
7206 public function getItemDeliveryMethod( $post_id, $cache = true ) {
7207 $product = wel_get_product( $post_id, $cache );
7208 if ( empty( $product['itemDeliveryMethod'] ) ) {
7209 return array();
7210 } else {
7211 return $product['itemDeliveryMethod'];
7212 }
7213 }
7214
7215 public function getItemIndividualSCharge( $post_id, $cache = true ) {
7216 $product = wel_get_product( $post_id, $cache );
7217 $itemIndividualSCharge = isset( $product['itemIndividualSCharge'] ) ? $product['itemIndividualSCharge'] : null;
7218 return $itemIndividualSCharge;
7219 }
7220
7221 public function getItemGpNum1( $post_id, $cache = true ) {
7222 $product = wel_get_product( $post_id, $cache );
7223 $itemGpNum1 = isset( $product['itemGpNum1'] ) ? $product['itemGpNum1'] : null;
7224 return $itemGpNum1;
7225 }
7226
7227 public function getItemGpNum2( $post_id, $cache = true ) {
7228 $product = wel_get_product( $post_id, $cache );
7229 $itemGpNum2 = isset( $product['itemGpNum2'] ) ? $product['itemGpNum2'] : null;
7230 return $itemGpNum2;
7231 }
7232
7233 public function getItemGpNum3( $post_id, $cache = true ) {
7234 $product = wel_get_product( $post_id, $cache );
7235 $itemGpNum3 = isset( $product['itemGpNum3'] ) ? $product['itemGpNum3'] : null;
7236 return $itemGpNum3;
7237 }
7238
7239 public function getItemGpDis1( $post_id, $cache = true ) {
7240 $product = wel_get_product( $post_id, $cache );
7241 $itemGpDis1 = isset( $product['itemGpDis1'] ) ? $product['itemGpDis1'] : null;
7242 return $itemGpDis1;
7243 }
7244
7245 public function getItemGpDis2( $post_id, $cache = true ) {
7246 $product = wel_get_product( $post_id, $cache );
7247 $itemGpDis2 = isset( $product['itemGpDis2'] ) ? $product['itemGpDis2'] : null;
7248 return $itemGpDis2;
7249 }
7250
7251 public function getItemGpDis3( $post_id, $cache = true ) {
7252 $product = wel_get_product( $post_id, $cache );
7253 $itemGpDis3 = isset( $product['itemGpDis3'] ) ? $product['itemGpDis3'] : null;
7254 return $itemGpDis3;
7255 }
7256
7257 /**
7258 * Unused function
7259 */
7260 public function getItemSku( $post_id, $index = '', $cache = true ) {
7261 $array = array();
7262 $skus = $this->get_skus( $post_id, 'sort', $cache );
7263 foreach ( (array) $skus as $sku ) {
7264 $array[] = $sku['code'];
7265 }
7266 if ( ! $array ) {
7267 return false;
7268 }
7269 if ( '' == $index ) {
7270 return $array;
7271 } elseif ( isset( $array[ $index ] ) ) {
7272 return $array[ $index ];
7273 } else {
7274 return false;
7275 }
7276 }
7277
7278 public function getItemPrice( $post_id, $skukey = '', $cache = true ) {
7279 $array = array();
7280 $skus = wel_get_skus( $post_id, 'code', $cache );
7281 foreach ( (array) $skus as $key => $sku ) {
7282 $array[ $key ] = (float) str_replace( ',', '', $sku['price'] );
7283 }
7284 $array = apply_filters( 'usces_filter_get_item_price', $array, $post_id, $skukey, $skus );
7285 if ( ! $array ) {
7286 return false;
7287 }
7288 if ( '' === $skukey ) {
7289 return $array;
7290 } elseif ( isset( $array[ $skukey ] ) ) {
7291 return $array[ $skukey ];
7292 } else {
7293 return false;
7294 }
7295 }
7296
7297 public function getItemDiscount( $post_id, $skukey = '', $cache = true ) {
7298 $display_mode = $this->options['display_mode'];
7299 $decimal = $this->get_currency_decimal();
7300 $array = array();
7301
7302 $skus = wel_get_skus( $post_id, 'code', $cache );
7303 $discount = 0;
7304 foreach ( (array) $skus as $key => $sku ) {
7305 $price = (float) str_replace( ',', '', $sku['price'] );
7306 if ( 'Promotionsale' == $display_mode ) {
7307 if ( 'discount' === $this->options['campaign_privilege'] ) {
7308 if ( 0 === (int) $this->options['campaign_category'] || in_category( (int) $this->options['campaign_category'], $post_id ) ) {
7309 $discount = (float) sprintf( '%.3f', $price * $this->options['privilege_discount'] / 100 );
7310 } else {
7311 $discount = 0;
7312 }
7313 } elseif ( 'point' === $this->options['campaign_privilege'] ) {
7314 $discount = 0;
7315 }
7316 }
7317 if ( 0 != $discount ) {
7318 if ( 0 == $decimal ) {
7319 $discount = ceil( $discount );
7320 } else {
7321 $decipad = (int) str_pad( '1', $decimal + 1, '0', STR_PAD_RIGHT );
7322 $discount = ceil( $discount * $decipad ) / $decipad;
7323 }
7324 }
7325 $discount = apply_filters( 'usces_filter_getItemDiscount', $discount, $price, $post_id, $sku, $display_mode );
7326 $array[ $key ] = $discount;
7327 }
7328 if ( ! $array ) {
7329 return false;
7330 }
7331 if ( '' === $skukey ) {
7332 return $array;
7333 } elseif ( isset( $array[ $skukey ] ) ) {
7334 return $array[ $skukey ];
7335 } else {
7336 return false;
7337 }
7338 }
7339
7340 public function getItemZaiko( $post_id, $skukey = '', $cache = true ) {
7341 $itemOrderAcceptable = $this->getItemOrderAcceptable( $post_id );
7342 $array = array();
7343
7344 $skus = wel_get_skus( $post_id, 'code', $cache );
7345 foreach ( (array) $skus as $key => $sku ) {
7346 $num = $sku['stock'];
7347 if ( 1 != $itemOrderAcceptable || WCUtils::is_blank( $sku['stocknum'] ) ) {
7348 $array[ $key ] = $this->zaiko_status[ $num ];
7349 } else {
7350 if ( 2 > $num && 0 >= (int) $sku['stocknum'] ) {
7351 $array[ $key ] = ( ! empty( $this->options['order_acceptable_label'] ) ) ? $this->options['order_acceptable_label'] : __( 'Order acceptable', 'usces' );
7352 } else {
7353 $array[ $key ] = $this->zaiko_status[ $num ];
7354 }
7355 }
7356 }
7357 if ( ! $array ) {
7358 return false;
7359 }
7360 if ( '' === $skukey ) {
7361 return $array;
7362 } elseif ( isset( $array[ $skukey ] ) ) {
7363 return $array[ $skukey ];
7364 } else {
7365 return false;
7366 }
7367 }
7368
7369 public function getItemZaikoStatusId( $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 $num = $sku['stock'];
7374 $array[ $key ] = $num;
7375 }
7376 if ( ! $array ) {
7377 return false;
7378 }
7379 if ( '' === $skukey ) {
7380 return $array;
7381 } elseif ( isset( $array[ $skukey ] ) ) {
7382 return $array[ $skukey ];
7383 } else {
7384 return false;
7385 }
7386 }
7387
7388 public function updateItemZaiko( $post_id, $skucode, $value ) {
7389 $res = usces_update_sku( $post_id, $skucode, 'stock', $value );
7390 if ( ! $res ) {
7391 return false;
7392 } else {
7393 return true;
7394 }
7395 }
7396
7397 public function getItemZaikoNum( $post_id, $skukey = '', $cache = true ) {
7398 $array = array();
7399 $skus = wel_get_skus( $post_id, 'code', $cache );
7400 foreach ( (array) $skus as $key => $sku ) {
7401 $array[ $key ] = $sku['stocknum'];
7402 }
7403 if ( ! $array ) {
7404 return false;
7405 }
7406 if ( '' === $skukey ) {
7407 return $array;
7408 } elseif ( isset( $array[ $skukey ] ) ) {
7409 return $array[ $skukey ];
7410 } else {
7411 return false;
7412 }
7413 }
7414
7415 public function updateItemZaikoNum( $post_id, $skucode, $value ) {
7416 $res = usces_update_sku( $post_id, $skucode, 'stocknum', $value );
7417 if ( ! $res ) {
7418 return false;
7419 } else {
7420 return true;
7421 }
7422 }
7423
7424 public function getItemDivision( $post_id, $cache = true ) {
7425 if ( usces_is_item( $post_id ) ) {
7426 $product = wel_get_product( $post_id, $cache );
7427 $item_division = $product['item_division'];
7428 $division = empty( $item_division ) ? 'shipped' : $item_division;
7429 } else {
7430 $division = null;
7431 }
7432 return $division;
7433 }
7434
7435 public function getItemChargingType( $post_id, $cart = array(), $cache = true ) {
7436 if ( usces_is_item( $post_id ) ) {
7437 $product = wel_get_product( $post_id, $cache );
7438 $charging = $product['item_charging_type'];
7439 if ( ! defined( 'WCEX_DLSELLER' ) && ! defined( 'WCEX_AUTO_DELIVERY' ) ) {
7440 $charging = null;
7441 }
7442 } else {
7443 $charging = null;
7444 }
7445 switch ( $charging ) {
7446 case 0:
7447 $type = 'once';
7448 break;
7449 case 1:
7450 $type = 'continue';
7451 break;
7452 case 2:
7453 $type = 'regular';
7454 if ( ! empty( $cart ) ) {
7455 if ( empty( $cart['advance'] ) ) {
7456 $type = 'once';
7457 } else {
7458 if ( is_array( $cart['advance'] ) && array_key_exists( 'regular', $cart['advance'] ) ) {
7459 $regular = maybe_unserialize( $cart['advance']['regular'] );
7460 } else {
7461 $advance = $this->cart->wc_unserialize( $cart['advance'] );
7462 $sku = urldecode( $cart['sku'] );
7463 $sku_encoded = $cart['sku'];
7464 $regular = $advance[ $post_id ][ $sku_encoded ]['regular'];
7465 }
7466 $unit = isset( $regular['unit'] ) ? $regular['unit'] : '';
7467 $interval = isset( $regular['interval'] ) ? (int) $regular['interval'] : 0;
7468 /* Treated as normal billing */
7469 if ( empty( $unit ) || 1 > $interval ) {
7470 $type = 'once';
7471 }
7472 }
7473 }
7474 break;
7475 default:
7476 $type = null;
7477 }
7478 return $type;
7479 }
7480
7481 public function getItemFrequency( $post_id, $cache = true ) {
7482 $product = wel_get_product( $post_id, $cache );
7483 return $product['item_frequency'];
7484 }
7485
7486 public function getItemChargingDay( $post_id, $cache = true ) {
7487 $product = wel_get_product( $post_id, $cache );
7488 $day = (int) $product['item_chargingday'];
7489
7490 $chargingday = empty( $day ) ? 1 : $day;
7491 return $chargingday;
7492 }
7493
7494 public function getItemSkuDisp( $post_id, $skukey = '', $cache = true ) {
7495 $array = array();
7496 $skus = wel_get_skus( $post_id, 'code', $cache );
7497 foreach ( (array) $skus as $key => $sku ) {
7498 $array[ $key ] = $sku['name'];
7499 }
7500 if ( ! $array ) {
7501 return false;
7502 }
7503 if ( '' === $skukey ) {
7504 return $array;
7505 } elseif ( isset( $array[ $skukey ] ) ) {
7506 return $array[ $skukey ];
7507 } else {
7508 return false;
7509 }
7510 }
7511
7512 public function getItemSkuUnit( $post_id, $skukey = '', $cache = true ) {
7513 $array = array();
7514 $skus = wel_get_skus( $post_id, 'code', $cache );
7515 foreach ( (array) $skus as $key => $sku ) {
7516 $array[ $key ] = $sku['unit'];
7517 }
7518 if ( ! $array ) {
7519 return false;
7520 }
7521 if ( '' === $skukey ) {
7522 return $array;
7523 } elseif ( isset( $array[ $skukey ] ) ) {
7524 return $array[ $skukey ];
7525 } else {
7526 return false;
7527 }
7528 }
7529
7530 public function getItemSkuAdvance( $post_id, $skukey = '', $cache = true ) {
7531 $array = array();
7532 $skus = wel_get_skus( $post_id, 'code', $cache );
7533 foreach ( (array) $skus as $key => $sku ) {
7534 $array[ $key ] = $sku['advance'];
7535 }
7536 if ( ! $array ) {
7537 return false;
7538 }
7539 if ( '' === $skukey ) {
7540 return $array;
7541 } elseif ( isset( $array[ $skukey ] ) ) {
7542 return $array[ $skukey ];
7543 } else {
7544 return false;
7545 }
7546 }
7547
7548 public function get_item( $post_id, $cache = true ) {
7549 return wel_get_product( $post_id, $cache );
7550 }
7551
7552 public function get_itemOptionKey( $post_id, $enc = false, $cache = true ) {
7553 $opts = usces_get_opts( $post_id, 'sort', $cache );
7554 if ( empty( $opts ) ) {
7555 return;
7556 }
7557
7558 $res = array();
7559 foreach ( (array) $opts as $opt ) {
7560 if ( $enc ) {
7561 $res[] = urlencode( $opt['name'] );
7562 } else {
7563 $res[] = $opt['name'];
7564 }
7565 }
7566 return $res;
7567 }
7568
7569 public function get_itemOptions( $key, $post_id, $cache = true ) {
7570 $opts = wel_get_opts( $post_id, 'name', $cache );
7571 if ( ! isset( $opts[ $key ] ) ) {
7572 return false;
7573 } else {
7574 return $opts[ $key ];
7575 }
7576 }
7577
7578 public function get_postIDbyCode( $item_code, $cache = true ) {
7579 if ( null === $item_code ) {
7580 return false;
7581 }
7582
7583 $post_id = wel_get_id_by_item_code( $item_code, $cache );
7584
7585 return $post_id;
7586 }
7587
7588 public function get_itemByCode( $item_code, $cache = true ) {
7589 if ( null === $item_code ) {
7590 return false;
7591 }
7592
7593 $product = wel_get_product_by_code( $item_code, $cache );
7594
7595 return $product;
7596 }
7597
7598 public function get_pictids( $item_code, $cache = true ) {
7599 return wel_get_sub_pict_ids_by_code( $item_code, $cache );
7600 }
7601
7602 public function get_mainpictid( $item_code, $cache = true ) {
7603 return wel_get_main_pict_id_by_code( $item_code, $cache );
7604 }
7605
7606 public function get_subpictid( $sku_code, $cache = true ) {
7607 global $wpdb;
7608 if ( empty( $sku_code) ) {
7609 return 0;
7610 }
7611 $query = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type = 'attachment' LIMIT 1", $sku_code );
7612 $id = $wpdb->get_var( $query );
7613 $id = apply_filters( 'usces_filter_get_subpictid', $id, $sku_code );
7614 return $id;
7615 }
7616
7617 public function get_skus( $post_id, $keyflag = 'sort', $cache = true ) {
7618 if ( null === $post_id ) {
7619 return false;
7620 }
7621
7622 $skus = wel_get_skus( $post_id, $keyflag, $cache );
7623
7624 return $skus;
7625 }
7626
7627 public function is_item( $post ) {
7628 if ( 'item' == $post->post_mime_type ) {
7629 return true;
7630 } else {
7631 return false;
7632 }
7633 }
7634
7635 public function getItemIds( $end_type ) {
7636 global $wpdb;
7637
7638 $cache_key = 'wel_item_ids_' . $end_type;
7639
7640 $ids = wp_cache_get( $cache_key );
7641 if ( false === $ids ) {
7642
7643 if ( 'front' == $end_type ) {
7644 $query = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_status = %s AND post_mime_type = %s", 'publish', 'item' );
7645 }
7646 if ( 'back' == $end_type ) {
7647 $query = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_mime_type = %s", 'item' );
7648 }
7649 $ids = $wpdb->get_col( $query );
7650
7651 if ( null !== $ids ) {
7652 wp_cache_set( $cache_key, $ids );
7653 }
7654 }
7655
7656 if ( null === $ids ) {
7657 return array();
7658 } else {
7659 return $ids;
7660 }
7661 }
7662
7663 public function getNotItemIds() {
7664 global $wpdb;
7665 $query = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_status = %s AND post_mime_type <> %s", 'publish', 'item' );
7666 $ids = $wpdb->get_col( $query );
7667 if ( empty( $ids ) ) {
7668 $ids = array();
7669 }
7670 return $ids;
7671 }
7672
7673 public function getPaymentMethod( $name ) {
7674 $res = array();
7675 $payments = $this->options['payment_method'];
7676 foreach ( (array) $payments as $payment ) {
7677 if ( $name == $payment['name'] ) {
7678 $res = $payment;
7679 break;
7680 }
7681 }
7682 return $res;
7683 }
7684
7685 public function order_processing( $results = array() ) {
7686 do_action( 'usces_pre_reg_orderdata' );
7687 $acting = isset( $_REQUEST['acting'] ) ? $_REQUEST['acting'] : '';
7688 global $usces;
7689 $usces_entries = $this->cart->get_entry();
7690 $payments = $this->getPayments( $usces_entries['order']['payment_name'] );
7691 $nonacting_settlements = apply_filters( 'usces_filter_nonacting_settlements', $this->nonacting_settlements );
7692
7693 $res = usces_check_acting_return_duplicate( $results );
7694 if ( $res != null && ! in_array( $payments['settlement'], $nonacting_settlements ) ) {
7695 usces_log( 'order processing duplicate : acting=' . $acting . ', order_id=' . $res, 'acting_transaction.log' );
7696 return 'ordercompletion';
7697 }
7698 if ( isset( $_REQUEST['acting'] ) && ( 'jpayment_card' == $_REQUEST['acting'] || 'jpayment_conv' == $_REQUEST['acting'] || 'jpayment_bank' == $_REQUEST['acting'] ) ) {
7699 usces_log( $_REQUEST['acting'] . ' transaction : ' . $_REQUEST['gid'], 'acting_transaction.log' ); // OK.
7700 }
7701 if ( isset( $_REQUEST['acting'] ) && ( 'paypal_ec' == $_REQUEST['acting'] ) ) {
7702 if ( ! usces_paypal_doecp( $results ) ) {
7703 return 'error';
7704 }
7705 }
7706 $order_id = usces_reg_orderdata( $results );
7707 do_action( 'usces_post_reg_orderdata', $order_id, $results );
7708
7709 if ( $order_id ) {
7710 // mail(function.php).
7711 $mail_res = usces_send_ordermail( $order_id );
7712 return 'ordercompletion';
7713
7714 } else {
7715 return 'error';
7716 }
7717 }
7718
7719 /**
7720 * 決済処理
7721 *
7722 * @param string $acting_flg Payment type.
7723 * @param array $post_query Post data.
7724 * @param string $acting_status Status.
7725 * @return mixed
7726 */
7727 public function acting_processing( $acting_flg, $post_query, $acting_status ) {
7728 global $wpdb;
7729
7730 $entry = $this->cart->get_entry();
7731 $delim = apply_filters( 'usces_filter_delim', $this->delim );
7732 $acting_flg = trim( $acting_flg );
7733
7734 if ( empty( $acting_flg ) ) {
7735 return 'error';
7736 }
7737
7738 if ( 'paypal.php' == $acting_flg ) {
7739
7740 } elseif ( 'epsilon.php' == $acting_flg ) {
7741
7742 } elseif ( 'acting_paypal_ec' == $acting_flg ) {
7743 $acting_opts = $this->options['acting_settings']['paypal'];
7744 $addroverride = '1';
7745 if ( isset( $_POST['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] ) ) {
7746 if ( 'US' == $_POST['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] || 'CA' == $_POST['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] ) {
7747 $addroverride = '0';
7748 }
7749 } else {
7750 $addroverride = '0';
7751 }
7752 $rand = ( isset( $_POST['PAYMENTREQUEST_0_CUSTOM'] ) ) ? $_POST['PAYMENTREQUEST_0_CUSTOM'] : '(empty key)';
7753
7754 $nvpstr = $post_query;
7755 $nvpstr .= '&ADDROVERRIDE=' . $addroverride;
7756 $nvpstr .= '&PAYMENTREQUEST_0_PAYMENTACTION=' . apply_filters( 'usces_filter_paypal_ec_paymentaction', 'Sale' );
7757
7758 // The returnURL is the location where buyers return to when a payment has been succesfully authorized.
7759 $nvpstr .= '&RETURNURL=' . urlencode( USCES_CART_URL . $delim . 'acting=paypal_ec&acting_return=1' );
7760
7761 // The cancelURL is the location buyers are sent to when they hit the cancel button during authorization of payment during the PayPal flow.
7762 $cancelurl = urlencode( USCES_CART_URL . $delim . 'confirm=1' );
7763 $pos = strpos( $post_query, 'paypal_from_cart' );
7764 if ( false !== $pos ) {
7765 $cancelurl = urlencode( USCES_CART_URL );
7766 }
7767 $nvpstr .= '&CANCELURL=' . apply_filters( 'usces_filter_paypal_ec_cancelurl', $cancelurl, $post_query );
7768
7769 $nvpstr .= '&PAYMENTREQUEST_0_NOTIFYURL=' . urlencode( USCES_PAYPAL_NOTIFY_URL );
7770
7771 // Seamless checkout.
7772 if ( isset( $_SESSION['liwpp']['token'] ) && ! empty( $_SESSION['liwpp']['token'] ) ) {
7773 $nvpstr .= '&IDENTITYACCESSTOKEN=' . $_SESSION['liwpp']['token'];
7774 }
7775
7776 $this->paypal->setMethod( 'SetExpressCheckout' );
7777 $this->paypal->setData( $nvpstr );
7778 $res = $this->paypal->doExpressCheckout();
7779 $resArray = $this->paypal->getResponse();
7780 $ack = strtoupper( $resArray['ACK'] );
7781 if ( 'SUCCESS' == $ack || 'SUCCESSWITHWARNING' == $ack ) {
7782 $token = urldecode( $resArray['TOKEN'] );
7783 $payPalURL = $acting_opts['paypal_url'] . '?cmd=_express-checkout&token=' . $token . '&useraction=commit';
7784 header( 'Location: ' . $payPalURL );
7785
7786 } else {
7787 // Display a user friendly Error on the page using any of the following error information returned by PayPal.
7788 $ErrorCode = urldecode( $resArray['L_ERRORCODE0'] );
7789 $ErrorShortMsg = urldecode( $resArray['L_SHORTMESSAGE0'] );
7790 $ErrorLongMsg = urldecode( $resArray['L_LONGMESSAGE0'] );
7791 $ErrorSeverityCode = urldecode( $resArray['L_SEVERITYCODE0'] );
7792 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' );
7793 $log = array(
7794 'acting' => 'paypal_ec',
7795 'key' => $rand,
7796 'result' => $ack,
7797 'data' => $resArray,
7798 );
7799 usces_save_order_acting_error( $log );
7800 header( 'Location: ' . USCES_CART_URL . $delim . 'acting=paypal_ec&acting_return=0' );
7801 }
7802 exit;
7803
7804 } elseif ( 'acting_telecom_edy' == $acting_flg ) { /* テレコムクレジット Edy決済 */
7805 $table_meta_name = $wpdb->prefix . 'usces_order_meta';
7806 $value = array();
7807 $value['usces_cart'] = $_SESSION['usces_cart'];
7808 $value['usces_entry'] = $_SESSION['usces_entry'];
7809 $value['usces_member'] = $_SESSION['usces_member'];
7810 $mvalue = serialize( $value );
7811 $mquery = $wpdb->prepare( "INSERT INTO $table_meta_name (order_id, meta_key, meta_value) VALUES (%d, %s, %s)", $_POST['option'], $_POST['option'], $mvalue );
7812 $res = $wpdb->query( $mquery );
7813
7814 unset( $_SESSION['usces_cart'] );
7815 unset( $_SESSION['usces_entry'] );
7816
7817 $acting_opts = $this->options['acting_settings']['telecom'];
7818 header( 'location: ' . $acting_opts['send_url_edy'] . '?acting=telecom_edy' . $post_query );
7819 exit;
7820
7821 } elseif ( 'acting_digitalcheck_card' == $acting_flg ) { /* ペイメントフォー カード決済(旧メタップスペイメント、旧デジタルチェック、旧ペイデザイン) */
7822 $acting_opts = $this->options['acting_settings']['digitalcheck'];
7823 $interface = parse_url( $acting_opts['send_url_user_id'] );
7824 $kakutei = ( empty( $acting_opts['card_kakutei'] ) ) ? '0' : $acting_opts['card_kakutei'];
7825
7826 $params = array(
7827 'IP' => $acting_opts['card_ip'],
7828 'PASS' => $acting_opts['card_pass'],
7829 'SID' => $_POST['SID'],
7830 'IP_USER_ID' => $_POST['IP_USER_ID'],
7831 'N1' => $_POST['N1'],
7832 'K1' => $_POST['K1'],
7833 'FUKA' => $acting_flg,
7834 'KAKUTEI' => $kakutei,
7835 );
7836 $vars = http_build_query( $params );
7837
7838 $header = 'POST ' . $interface['path'] . " HTTP/1.1\r\n";
7839 $header .= 'Host: ' . $interface['host'] . "\r\n";
7840 $header .= "User-Agent: PHP Script\r\n";
7841 $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
7842 $header .= 'Content-Length: ' . strlen( $vars ) . "\r\n";
7843 $header .= "Connection: close\r\n\r\n";
7844 $header .= $vars;
7845
7846 $fp = @stream_socket_client( 'tlsv1.2://' . $interface['host'] . ':443', $errno, $errstr, 30 );
7847 if ( ! $fp ) {
7848 // usces_log( 'digitalcheck card : TLS(v1.2) Error', 'acting_transaction.log' );
7849 $log = array(
7850 'acting' => 'digitalcheck_card',
7851 'key' => $_POST['SID'],
7852 'result' => 'SSL/TLS ERROR (' . $errno . ')',
7853 'data' => array( $errstr ),
7854 );
7855 usces_save_order_acting_error( $log );
7856 wp_redirect(
7857 add_query_arg(
7858 array(
7859 'acting' => 'digitalcheck_card',
7860 'acting_return' => 0,
7861 ),
7862 USCES_CART_URL
7863 )
7864 );
7865 exit();
7866 }
7867
7868 if ( $fp ) {
7869 fwrite( $fp, $header );
7870 $headerdone = false;
7871 $page = '';
7872 while ( ! feof( $fp ) ) {
7873 $line = fgets( $fp, 1024 );
7874 if ( 0 == strcmp( $line, "\r\n" ) ) {
7875 $headerdone = true;
7876 } elseif ( $headerdone ) {
7877 $page .= $line;
7878 }
7879 }
7880 fclose( $fp );
7881 $lines = explode( "\n", $page );
7882 if ( false !== strpos( $lines[0], 'OK' ) ) {
7883 // usces_log( 'digitalcheck card entry data (acting_processing) : ' . print_r( $entry, true ), 'acting_transaction.log');
7884 wp_redirect(
7885 add_query_arg(
7886 array(
7887 'acting' => 'digitalcheck_card',
7888 'acting_return' => 1,
7889 'SID' => $_POST['SID'],
7890 'FUKA' => $acting_flg,
7891 ),
7892 USCES_CART_URL
7893 )
7894 );
7895 exit();
7896 } else {
7897 // usces_log( 'digitalcheck card : Certification Error : ' . $page, 'acting_transaction.log' );
7898 $log = array(
7899 'acting' => 'digitalcheck_card',
7900 'key' => $_POST['SID'],
7901 'result' => 'CERTIFICATION ERROR',
7902 'data' => $lines,
7903 );
7904 usces_save_order_acting_error( $log );
7905 wp_redirect(
7906 add_query_arg(
7907 array(
7908 'acting' => 'digitalcheck_card',
7909 'acting_return' => 0,
7910 ),
7911 USCES_CART_URL
7912 )
7913 );
7914 exit();
7915 }
7916 }
7917 exit();
7918
7919 } elseif ( 'acting_digitalcheck_conv' == $acting_flg ) { /* ペイメントフォー コンビニ決済(旧メタップスペイメント、旧デジタルチェック、旧ペイデザイン) */
7920 if ( isset( $_REQUEST['STORE'] ) && '99' != $_REQUEST['STORE'] ) {
7921 $res = $this->order_processing();
7922 if ( 'ordercompletion' == $res ) {
7923 $table_meta_name = $wpdb->prefix . 'usces_order_meta';
7924 $mquery = $wpdb->prepare( "SELECT order_id FROM $table_meta_name WHERE meta_key = %s AND meta_value = %s", 'SID', $_REQUEST['SID'] );
7925 $order_id = $wpdb->get_var( $mquery );
7926 if ( $order_id ) {
7927 $data = array(
7928 'settltment_status' => __( 'Failure', 'usces' ),
7929 'settltment_errmsg' => __( 'Settlement was not completed.', 'usces' ),
7930 );
7931 $this->set_order_meta_value( 'acting_digitalcheck_conv', serialize( $data ), $order_id );
7932 $this->set_order_meta_value( 'wc_trans_id', $_REQUEST['SID'], $order_id );
7933 }
7934 $this->cart->crear_cart();
7935 $acting_opts = $this->options['acting_settings']['digitalcheck'];
7936 header( 'location: ' . $acting_opts['send_url_conv'] . '?acting=digitalcheck_conv' . $post_query );
7937 exit;
7938 } else {
7939 // usces_log( 'digitalcheck conv : order processing error', 'acting_transaction.log' );
7940 $log = array(
7941 'acting' => 'digitalcheck_conv',
7942 'key' => $_REQUEST['SID'],
7943 'result' => 'ORDER DATA REGISTERED ERROR',
7944 'data' => $_REQUEST,
7945 );
7946 usces_save_order_acting_error( $log );
7947 header( 'location: ' . USCES_CART_URL . $delim . 'acting=digitalcheck_conv&acting_return=0' );
7948 exit;
7949 }
7950 } else {
7951 $acting_opts = $this->options['acting_settings']['digitalcheck'];
7952 header( 'location: ' . $acting_opts['send_url_conv'] . '?acting=digitalcheck_conv' . $post_query );
7953 exit;
7954 }
7955
7956 } elseif ( 'acting_veritrans_card' == $acting_flg || 'acting_veritrans_conv' == $acting_flg ) { /* ベリトランス カード決済・コンビニ決済 */
7957 $acting_opts = $this->options['acting_settings']['veritrans'];
7958 $acting = substr( $acting_flg, 7 );
7959 $dummy_payment_flag = ( 'public' == $acting_opts['ope'] ) ? '0' : '1';
7960 $order_id = isset( $_POST['ORDER_ID'] ) ? $_POST['ORDER_ID'] : '';
7961 $regist_url = ( defined( 'VERITRANS_SHA2_TEST' ) ) ? 'https://sair.veritrans.co.jp/web/commodityRegist.action' : $acting_opts['regist_url'];
7962 $url = parse_url( $regist_url );
7963 $path = empty( $url['path'] ) ? '/' : $url['path'];
7964
7965 $postdata = $post_query;
7966 if ( 'acting_veritrans_card' == $acting_flg ) {
7967 $card_capture_flag = ( 'capture' == $acting_opts['card_capture_flag'] ) ? '1' : '0';
7968 $postdata .= '&CARD_CAPTURE_FLAG=' . $card_capture_flag;
7969 }
7970 if ( 'acting_veritrans_conv' == $acting_flg ) {
7971 $postdata .= '&NAME1=' . urlencode( mb_substr( mb_convert_kana( $entry['customer']['name1'], 'ASKV', 'UTF-8' ), 0, 10, 'UTF-8' ) );
7972 $postdata .= '&NAME2=' . urlencode( mb_substr( mb_convert_kana( $entry['customer']['name2'], 'ASKV', 'UTF-8' ), 0, 10, 'UTF-8' ) );
7973 if ( ! empty( $entry['customer']['name3'] ) ) {
7974 $kana1 = mb_substr( mb_convert_kana( $entry['customer']['name3'], 'ASKV', 'UTF-8' ), 0, 10, 'UTF-8' );
7975 mb_regex_encoding( 'UTF-8' );
7976 if ( mb_ereg( "^[ア-ン゛゜ァ-ォャ-ョー]+$", $kana1 ) ) {
7977 $postdata .= '&KANA1=' . urlencode( $kana1 );
7978 }
7979 }
7980 if ( ! empty( $entry['customer']['name4'] ) ) {
7981 $kana2 = mb_substr( mb_convert_kana( $entry['customer']['name4'], 'ASKV', 'UTF-8' ), 0, 10, 'UTF-8' );
7982 mb_regex_encoding( 'UTF-8' );
7983 if ( mb_ereg( "^[ア-ン゛゜ァ-ォャ-ョー]+$", $kana2 ) ) {
7984 $postdata .= '&KANA2=' . urlencode( $kana2 );
7985 }
7986 }
7987 $postdata .= '&TELEPHONE_NO=' . str_replace( '-', '', $entry['customer']['tel'] );
7988 if ( 1 < (int) $acting_opts['conv_timelimit'] && (int) $acting_opts['conv_timelimit'] <= 60 ) {
7989 $timelimit = date( 'Ymd', strtotime( '+' . $acting_opts['conv_timelimit'] . ' days' ) );
7990 $postdata .= '&TIMELIMIT_OF_PAYMENT=' . $timelimit;
7991 }
7992 }
7993 if ( 'on' == $acting_opts['mailaddress'] ) {
7994 $postdata .= '&MAILADDRESS=' . $entry['customer']['mailaddress1'];
7995 }
7996 $postdata .= '&MERCHANT_ID=' . $acting_opts['merchant_id'];
7997 $postdata .= '&SESSION_ID=' . session_id();
7998 $postdata .= '&FINISH_PAYMENT_RETURN_URL=' . urlencode( USCES_CART_URL . $delim . 'acting=' . $acting . '&acting_return=1&result=1' );
7999 $postdata .= '&UNFINISH_PAYMENT_RETURN_URL=' . urlencode( USCES_CART_URL . $delim . 'acting=' . $acting . '&confirm=1' );
8000 $postdata .= '&ERROR_PAYMENT_RETURN_URL=' . urlencode( USCES_CART_URL . $delim . 'acting=' . $acting . '&acting_return=0' );
8001 $postdata .= '&FINISH_PAYMENT_ACCESS_URL=' . urlencode( USCES_CART_URL . $delim . 'acting=' . $acting );
8002 $postdata .= '&DUMMY_PAYMENT_FLAG=' . $dummy_payment_flag;
8003
8004 $postlength = strlen( $postdata );
8005
8006 $request = 'POST ' . $path . ' HTTP/1.1' . "\r\n";
8007 $request .= 'Host: ' . $url['host'] . "\r\n";
8008 $request .= 'User-Agent: HttpRequest Powered by ' . phpversion() . "\r\n";
8009 $request .= 'Connection: close' . "\r\n";
8010 $request .= 'Accept-Language: ja' . "\r\n";
8011 $request .= 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
8012 $request .= 'Content-Length: ' . $postlength . "\r\n\r\n";
8013 $request .= $postdata;
8014
8015 $code = 0;
8016 $resBody = '';
8017 $con = @stream_socket_client( 'tlsv1.2://' . $url['host'] . ':443', $errno, $errstr, 30 );
8018 if ( ! $con ) {
8019 usces_log( 'Veritrans : TLS(v1.2) Error', 'acting_transaction.log' );
8020 $con = @fsockopen( 'ssl://' . $url['host'], 443, $errno, $errstr, 30 );
8021 if ( ! $con ) {
8022 usces_log( 'Veritrans : SSL Error', 'acting_transaction.log' );
8023 $log = array(
8024 'acting' => $acting,
8025 'key' => $order_id,
8026 'result' => 'SSL/TLS ERROR (' . $errno . ')',
8027 'data' => array( $errstr ),
8028 );
8029 usces_save_order_acting_error( $log );
8030 header( 'location: ' . USCES_CART_URL . $delim . 'acting=' . $acting_flg . '&acting_return=0' );
8031 exit;
8032 }
8033 }
8034
8035 if ( $con ) {
8036 $ret = fwrite( $con, $request );
8037 if ( $ret == strlen( $request ) ) {
8038 $res = $this->readResponse( $con );
8039 $code = $res['Code'];
8040 $resBody = $res['Body'];
8041
8042 } else {
8043 usces_log( 'Veritrans Write NG: Sent:' . strlen( $request ) . ' Send:' . $ret, 'acting_transaction.log' );
8044 }
8045 fclose( $con );
8046 }
8047
8048 // 正常終了(200 OK)が返ったか.
8049 if ( 200 == intval( $code ) ) {
8050 $merchantKey = null;
8051 $browserKey = null;
8052 $scd = null;
8053 $error_message = null;
8054
8055 // レスポンスデータからマーチャントキー、ブラウザキーを取得.
8056 $bodyLine = explode( "\n", $resBody );
8057 foreach ( $bodyLine as $line ) {
8058 if ( preg_match( '/^MERCHANT_ENCRYPTION_KEY=(.+)/', $line, $match ) ) {
8059 $merchantKey = $match[1];
8060 } elseif ( preg_match( '/^BROWSER_ENCRYPTION_KEY=(.+)/', $line, $match ) ) {
8061 $browserKey = $match[1];
8062 } elseif ( preg_match('/^SCD=(.+)/', $line, $match ) ) {
8063 $scd = $match[1];
8064 } elseif ( preg_match( '/^ERROR_MESSAGE=(.+)/', $line, $match ) ) {
8065 $error_message = $match[1];
8066 }
8067 }
8068
8069 // 両方取れたらOK。SCDはカードでセキュリティコードが入力された場合のみ.
8070 if ( ! is_null( $merchantKey ) && ! is_null( $browserKey ) ) {
8071 $getdata = '?MERCHANT_ID=' . $acting_opts['merchant_id'];
8072 $getdata .= '&ORDER_ID=' . $order_id;
8073 $getdata .= '&BROWSER_ENCRYPTION_KEY=' . urlencode( $browserKey );
8074 $payment_url = ( defined( 'VERITRANS_SHA2_TEST' ) ) ? 'https://sair.veritrans.co.jp/web/paymentStart.action' : $acting_opts['payment_url'];
8075 header( 'location: ' . $payment_url . $getdata );
8076
8077 } else {
8078 if ( ! is_null( $error_message ) ) {
8079 usces_log( 'Veritrans AWeb:' . $error_message, 'acting_transaction.log' );
8080 $log = array(
8081 'acting' => $acting,
8082 'key' => $order_id,
8083 'result' => $code,
8084 'data' => $bodyLine,
8085 );
8086 usces_save_order_acting_error( $log );
8087 }
8088 header( 'location: ' . USCES_CART_URL . $delim . 'acting=' . $acting_flg . '&acting_return=0' );
8089 }
8090
8091 } else {
8092 usces_log( 'Veritrans Response NG: ' . $resBody, 'acting_transaction.log' );
8093 $bodyLine = explode( "\n", $resBody );
8094 $log = array(
8095 'acting' => $acting,
8096 'key' => $order_id,
8097 'result' => $code,
8098 'data' => $bodyLine,
8099 );
8100 usces_save_order_acting_error( $log );
8101 header( 'location: ' . USCES_CART_URL . $delim . 'acting=' . $acting_flg . '&acting_return=0' );
8102 }
8103 exit;
8104 }
8105
8106 do_action( 'usces_action_acting_processing', $acting_flg, $post_query );
8107 $acting_status = apply_filters( 'usces_filter_acting_processing', $acting_flg, $post_query, $acting_status );
8108 return $acting_status;
8109 }
8110
8111 private function readResponse( $fp ) {
8112 $res = array(
8113 'Status' => '',
8114 'Version' => '',
8115 'Code' => 0,
8116 'Message' => '',
8117 'Headers' => array(),
8118 'Body' => '',
8119 );
8120
8121 // HTTPステータスの読み込み.
8122 $line = $this->readLine( $fp );
8123 if ( 0 == preg_match( '/^(HTTP\/1\.[0-9x]+)\s+([0-9]+)\s+(.+)/i', $line, $match ) ) {
8124 return $res;
8125 }
8126 $res['Status'] = $line;
8127 $res['Version'] = $match[1];
8128 $res['Code'] = $match[2];
8129 $res['Message'] = $match[3];
8130
8131 // レスポンスヘッダの読み込み.
8132 while ( ! feof( $fp ) ) {
8133 $line = $this->readLine( $fp );
8134 if ( '' != $line ) {
8135 list( $hname, $hvalue ) = explode( ':', $line, 2 );
8136 $res['Headers'][ strtolower( $hname ) ] = ltrim( $hvalue );
8137 } else {
8138 break;
8139 }
8140 }
8141 // レスポンスデータの読み込み.
8142 while ( ! feof( $fp ) ) {
8143 $data = $this->readLine( $fp ) . "\n";
8144 if ( '' == $data ) {
8145 break;
8146 }
8147 $res['Body'] .= $data;
8148 }
8149 return $res;
8150 }
8151
8152 private function readLine( $fp ) {
8153 if ( ! $fp ) {
8154 return '';
8155 }
8156 // レスポンスデータを受信.
8157 $line = null;
8158 while ( ! feof( $fp ) ) {
8159 $line .= @fgets( $fp, 4096 );
8160 if ( "\n" == substr( $line, -1 ) ) {
8161 return rtrim( $line, "\r\n" );
8162 }
8163 }
8164 return $line;
8165 }
8166
8167 public function inquiry_processing() {
8168 $mail_res = usces_send_inquirymail();
8169
8170 if ( $mail_res ) {
8171 return 'inquiry_comp';
8172 } else {
8173 return 'inquiry_error';
8174 }
8175 }
8176
8177 public function lastprocessing() {
8178 if ( 'ordercompletion' == $this->page ) {
8179 $this->cart->crear_cart();
8180 }
8181 do_action( 'usces_action_lastprocessing' );
8182
8183 unset( $_SESSION['usces_singleitem'] );
8184 }
8185
8186 public function is_item_zaiko( $post_id, $sku_code ) {
8187 $res = false;
8188 $status_num = false;
8189 $zaiko_num = false;
8190 if ( ! empty( $post_id ) ) {
8191 $sku_code = (string) $sku_code;
8192 $status_num = $this->getItemZaikoStatusId( $post_id, $sku_code );
8193 $zaiko_num = $this->getItemZaikoNum( $post_id, $sku_code );
8194 $itemOrderAcceptable = $this->getItemOrderAcceptable( $post_id );
8195 if ( 1 != $itemOrderAcceptable ) {
8196 if ( false !== $zaiko_num
8197 && ( 0 < (int) $zaiko_num || WCUtils::is_blank( $zaiko_num ) )
8198 && false !== $status_num
8199 && 2 > (int) $status_num ) {
8200 $res = true;
8201 } else {
8202 $res = false;
8203 }
8204 } else {
8205 if ( false !== $status_num
8206 && 2 > (int) $status_num ) {
8207 $res = true;
8208 } else {
8209 $res = false;
8210 }
8211 }
8212 }
8213 return apply_filters( 'usces_is_item_zaiko', $res, $post_id, $sku_code, $status_num, $zaiko_num );
8214 }
8215
8216 public function get_total_price( $cart = array() ) {
8217 if ( empty( $cart ) ) {
8218 $cart = $this->cart->get_cart();
8219 }
8220 $total_price = 0;
8221
8222 if ( ! empty( $cart ) ) {
8223 $cart_count = ( is_array( $cart ) ) ? count( $cart ) : 0;
8224 for ( $i = 0; $i < $cart_count; $i++ ) {
8225 $quantity = (float) $cart[ $i ]['quantity'];
8226 $skuPrice = (float) $cart[ $i ]['price'];
8227
8228 $total_price += ( $skuPrice * $quantity );
8229 }
8230 }
8231 return apply_filters( 'usces_filter_get_total_price', $total_price, $cart );
8232 }
8233
8234 public function get_total_quantity( $cart = array() ) {
8235 if ( empty( $cart ) ) {
8236 $cart = $this->cart->get_cart();
8237 }
8238 $total_quantity = 0;
8239
8240 if ( ! empty( $cart ) ) {
8241 $cart_count = ( is_array( $cart ) ) ? count( $cart ) : 0;
8242 for ( $i = 0; $i < $cart_count; $i++ ) {
8243 $total_quantity += (float) $cart[ $i ]['quantity'];
8244 }
8245 }
8246 return $total_quantity;
8247 }
8248
8249 public function get_order_point( $mem_id = '', $display_mode = '', $cart = array() ) {
8250 if ( '' == $mem_id || 'deactivate' == $this->options['membersystem_state'] || 'deactivate' == $this->options['membersystem_point'] ) {
8251 return 0;
8252 }
8253
8254 if ( empty( $cart ) ) {
8255 $cart = $this->cart->get_cart();
8256 }
8257 if ( empty( $display_mode ) ) {
8258 $display_mode = $this->options['display_mode'];
8259 }
8260 $point = 0;
8261 $total = $this->get_total_price( $cart );
8262 if ( 'Promotionsale' == $display_mode ) {
8263 if ( 'discount' == $this->options['campaign_privilege'] ) {
8264 foreach ( $cart as $rows ) {
8265 $cats = $this->get_post_term_ids( $rows['post_id'], 'category' );
8266 if ( ! in_array( $this->options['campaign_category'], $cats ) ) {
8267 $product = wel_get_product( $rows['post_id'] );
8268 $rate = (float) $product['itemPointrate'];
8269 $price = (float) $rows['price'] * (float) $rows['quantity'];
8270 $point = (float) sprintf( '%.3f', $point + ( $price * $rate / 100 ) );
8271 }
8272 }
8273 } elseif ( 'point' == $this->options['campaign_privilege'] ) {
8274 foreach ( $cart as $rows ) {
8275 $product = wel_get_product( $rows['post_id'] );
8276 $rate = (float) $product['itemPointrate'];
8277 $price = (float) $rows['price'] * (float) $rows['quantity'];
8278 $cats = $this->get_post_term_ids( $rows['post_id'], 'category' );
8279 if ( in_array( $this->options['campaign_category'], $cats ) ) {
8280 $point = (float) sprintf( '%.3f', $point + ( $price * $rate / 100 * (float) $this->options['privilege_point'] ) );
8281 } else {
8282 $point = (float) sprintf( '%.3f', $point + ( $price * $rate / 100 ) );
8283 }
8284 }
8285 }
8286 } else {
8287 foreach ( $cart as $rows ) {
8288 $product = wel_get_product( $rows['post_id'] );
8289 $rate = (float) $product['itemPointrate'];
8290 $price = (float) $rows['price'] * (float) $rows['quantity'];
8291 $point = (float) sprintf( '%.3f', $point + ( $price * $rate / 100 ) );
8292 }
8293 }
8294
8295 $entry = $this->cart->get_entry();
8296 $use_point = isset( $entry['order']['usedpoint'] ) ? (int) $entry['order']['usedpoint'] : 0;
8297 if ( 0 < $use_point && 0 < $total ) {
8298 $point = (float) sprintf( '%.3f', $point - ( $point * $use_point / $total ) );
8299 $point = ceil( $point );
8300 if ( 0 > $point ) {
8301 $point = 0;
8302 }
8303 } else {
8304 if ( 0 < $point ) {
8305 $point = ceil( $point );
8306 }
8307 }
8308
8309 return apply_filters( 'usces_filter_get_order_point', $point, $mem_id, $display_mode, $cart );
8310 }
8311
8312 public function get_order_discount( $display_mode = '', $cart = array() ) {
8313 if ( empty( $cart ) ) {
8314 $cart = $this->cart->get_cart();
8315 }
8316 if ( empty( $display_mode ) ) {
8317 $display_mode = $this->options['display_mode'];
8318 }
8319 $discount = 0;
8320 if ( 'Promotionsale' == $display_mode ) {
8321 if ( 'discount' == $this->options['campaign_privilege'] ) {
8322 if ( 0 === (int) $this->options['campaign_category'] ) {
8323 $total = $this->get_total_price( $cart );
8324 $discount = (float) sprintf( '%.3f', $total * (float) $this->options['privilege_discount'] / 100 );
8325 } else {
8326 foreach ( $cart as $cart_row ) {
8327 if ( in_category( (int) $this->options['campaign_category'], $cart_row['post_id'] ) ) {
8328 $discount += (float) sprintf( '%.3f', (float) $cart_row['price'] * (float) $cart_row['quantity'] * (float) $this->options['privilege_discount'] / 100 );
8329 }
8330 }
8331 }
8332 if ( 0 != $discount ) {
8333 $decimal = $this->get_currency_decimal();
8334 if ( 0 == $decimal ) {
8335 $discount = ceil( $discount );
8336 } else {
8337 $decipad = (int) str_pad( '1', $decimal + 1, '0', STR_PAD_RIGHT );
8338 $discount = ceil( $discount * $decipad ) / $decipad;
8339 }
8340 $discount = $discount * -1;
8341 }
8342 } elseif ( 'point' == $this->options['campaign_privilege'] ) {
8343 $discount = 0;
8344 }
8345 }
8346 $discount = apply_filters( 'usces_order_discount', $discount, $cart );
8347 return $discount;
8348 }
8349
8350 public function getShippingCharge( $pref, $cart = array(), $entry = array() ) {
8351 if ( empty( $cart ) ) {
8352 $cart = $this->cart->get_cart();
8353 }
8354 if ( empty( $entry ) ) {
8355 $entry = $this->cart->get_entry();
8356 }
8357 if ( function_exists( 'dlseller_have_shipped' ) && ! dlseller_have_shipped() ) {
8358 $charge = 0;
8359 $charge = apply_filters( 'usces_filter_getShippingCharge', $charge, $cart, $entry );
8360 return $charge;
8361 }
8362
8363 // 配送方法ID.
8364 $d_method_id = $entry['order']['delivery_method'];
8365 // 配送方法index.
8366 $d_method_index = $this->get_delivery_method_index( $d_method_id );
8367 // 送料ID.
8368 $fixed_charge_id = ( isset( $this->options['delivery_method'][ $d_method_index ]['charge'] ) ) ? $this->options['delivery_method'][ $d_method_index ]['charge'] : -1;
8369 $individual_quant = 0;
8370 $total_quant = 0;
8371 $charges = array();
8372 $individual_charges = array();
8373 $country = ( isset( $entry['delivery']['country'] ) && ! empty( $entry['delivery']['country'] ) ) ? $entry['delivery']['country'] : $entry['customer']['country'];
8374
8375 foreach ( $cart as $rows ) {
8376
8377 if ( 'shipped' !== $this->getItemDivision( $rows['post_id'] ) ) {
8378 continue;
8379 }
8380
8381 if ( -1 == $fixed_charge_id ) {
8382 // 商品送料ID.
8383 $s_charge_id = $this->getItemShippingCharge( $rows['post_id'] );
8384 // 商品送料index.
8385 $s_charge_index = $this->get_shipping_charge_index( $s_charge_id );
8386 $s_charge = isset( $this->options['shipping_charge'][ $s_charge_index ][ $country ][ $pref ] ) ? (float) $this->options['shipping_charge'][ $s_charge_index ][ $country ][ $pref ] : 0;
8387 } else {
8388 $s_charge_index = $this->get_shipping_charge_index( $fixed_charge_id );
8389 $s_charge = isset( $this->options['shipping_charge'][ $s_charge_index ][ $country ][ $pref ] ) ? (float) $this->options['shipping_charge'][ $s_charge_index ][ $country ][ $pref ] : 0;
8390 }
8391
8392 if ( $this->getItemIndividualSCharge( $rows['post_id'] ) ) {
8393 $individual_quant += (float) $rows['quantity'];
8394 $individual_charges[] = (float) $rows['quantity'] * $s_charge;
8395 } else {
8396 $charges[] = $s_charge;
8397 }
8398 $total_quant += $rows['quantity'];
8399 }
8400
8401 if ( count( $charges ) > 0 ) {
8402 rsort( $charges );
8403 $max_charge = $charges[0];
8404 $charge = $max_charge + array_sum( array_filter( $individual_charges, 'is_numeric' ) );
8405 } else {
8406 $charge = array_sum( array_filter( $individual_charges, 'is_numeric' ) );
8407 }
8408
8409 $charge = apply_filters( 'usces_filter_getShippingCharge', $charge, $cart, $entry );
8410
8411 return $charge;
8412 }
8413
8414 public function getCODFee( $payment_name, $amount_by_cod, $current_entries ) {
8415 global $usces_entries;
8416
8417 $payments = $this->getPayments( $payment_name );
8418 if ( ! isset( $payments['settlement'] ) || 'COD' != $payments['settlement'] ) {
8419 $fee = 0;
8420
8421 } elseif ( 'change' != $this->options['cod_type'] ) {
8422 $fee = isset( $this->options['cod_fee'] ) ? $this->options['cod_fee'] : 0;
8423
8424 } else {
8425 $materials = array(
8426 'total_items_price' => $current_entries['order']['total_items_price'],
8427 'discount' => ( isset( $current_entries['order']['discount'] ) ) ? $current_entries['order']['discount'] : 0,
8428 'shipping_charge' => ( isset( $current_entries['order']['shipping_charge'] ) ) ? $current_entries['order']['shipping_charge'] : 0,
8429 'cod_fee' => 0,
8430 'use_point' => 0,
8431 );
8432 $price = $amount_by_cod + $this->getTax( $amount_by_cod, $materials );
8433 if ( $price <= $this->options['cod_first_amount'] ) {
8434 $fee = $this->options['cod_first_fee'];
8435
8436 } elseif ( isset( $this->options['cod_amounts'] ) ) {
8437 $last = count( $this->options['cod_amounts'] ) - 1;
8438 if ( $price > $this->options['cod_amounts'][ $last ] ) {
8439 $fee = $this->options['cod_end_fee'];
8440
8441 } else {
8442 $fee = 0;
8443 foreach ( $this->options['cod_amounts'] as $key => $value ) {
8444 if ( $price <= $value ) {
8445 $fee = $this->options['cod_fees'][ $key ];
8446 break;
8447 }
8448 }
8449 }
8450 } else {
8451 $fee = $this->options['cod_end_fee'];
8452 }
8453 }
8454 $fee = apply_filters( 'usces_filter_getCODFee', $fee, $payment_name, $amount_by_cod, $current_entries );
8455 return $fee;
8456 }
8457
8458 public function getTax( $total, $materials = array() ) {
8459 global $usces_settings;
8460
8461 if ( isset( $this->options['tax_display'] ) && 'deactivate' == $this->options['tax_display'] ) {
8462 return 0;
8463 }
8464 if ( empty( $this->options['tax_rate'] ) ) {
8465 return 0;
8466 }
8467 // if ( ! empty( $materials ) ) {
8468 // extract( $materials );//need( 'total_items_price', 'shipping_charge', 'discount', 'cod_fee', 'use_point' )
8469 // }
8470
8471 if ( $this->is_reduced_taxrate() ) {
8472 if ( 'include' == $this->options['tax_mode'] ) {
8473 return 0;
8474 }
8475 if ( ! empty( $materials ) ) {
8476 extract( $materials );
8477 if ( empty( $carts ) ) {
8478 $carts = array();
8479 $materials = compact( 'total_items_price', 'shipping_charge', 'discount', 'cod_fee', 'use_point', 'carts' );
8480 }
8481 }
8482
8483 $usces_tax = Welcart_Tax::get_instance();
8484 $usces_tax->get_order_tax( $materials );
8485 $tax = apply_filters( 'usces_filter_getTax', $usces_tax->tax, $materials );
8486
8487 } else {
8488
8489 if ( empty( $materials ) ) {
8490
8491 if ( 'include' == $this->options['tax_mode'] ) {
8492 $tax = (float) sprintf( '%.3f', (float) $total * (float) $this->options['tax_rate'] / ( 100 + (float) $this->options['tax_rate'] ) );
8493 } else {
8494 $tax = (float) sprintf( '%.3f', (float) $total * (float) $this->options['tax_rate'] / 100 );
8495 }
8496
8497 } else {
8498 if ( 'include' == $this->options['tax_mode'] ) {
8499 return 0;
8500 }
8501
8502 extract( $materials ); // need( 'total_items_price', 'shipping_charge', 'discount', 'cod_fee', 'use_point' ).
8503
8504 if ( 1 == $this->options['point_coverage'] ) {
8505 if ( 'products' == $this->options['tax_target'] ) {
8506 $total = (float) $total_items_price + (float) $discount;
8507 } else {
8508 $total = (float) $total_items_price + (float) $discount + (float) $shipping_charge + (float) $cod_fee;
8509 }
8510 } else {
8511 if ( 'products' == $this->options['tax_target'] ) {
8512 $total = (float) $total_items_price + (float) $discount;
8513 } else {
8514 if ( empty( $use_point ) ) {
8515 $use_point = 0;
8516 }
8517 $total = (float) $total_items_price + (float) $discount - (int) $use_point + (float) $shipping_charge + (float) $cod_fee;
8518 }
8519 }
8520 $total = apply_filters( 'usces_filter_getTax_total', $total, $materials );
8521
8522 $tax = (float) sprintf( '%.3f', (float) $total * (float) $this->options['tax_rate'] / 100 );
8523 }
8524
8525 $tax = usces_tax_rounding_off( $tax );
8526 $tax = apply_filters( 'usces_filter_getTax', $tax, $materials );
8527 }
8528
8529 return $tax;
8530 }
8531
8532 public function set_cart_fees( $member, $entries ) {
8533 global $usces_entries;
8534
8535 $carts = $this->cart->get_cart();
8536 $entries = $this->cart->get_entry();
8537 $total_items_price = $this->get_total_price();
8538 $entries['order']['total_items_price'] = $total_items_price;
8539
8540 if ( empty( $this->options['postage_privilege'] ) || $total_items_price < $this->options['postage_privilege'] ) {
8541 $shipping_charge = $this->getShippingCharge( $entries['delivery']['pref'], $carts, $entries );
8542 } else {
8543 $shipping_charge = 0;
8544 }
8545 $shipping_charge = apply_filters( 'usces_filter_set_cart_fees_shipping_charge', $shipping_charge, $carts, $entries );
8546 $entries['order']['shipping_charge'] = $shipping_charge;
8547
8548 $payments = $this->getPayments( $entries['order']['payment_name'] );
8549 $use_point = ( isset( $entries['order']['usedpoint'] ) ) ? (int) $entries['order']['usedpoint'] : 0;
8550 if ( $this->is_reduced_taxrate() ) {
8551 $usces_tax = Welcart_Tax::get_instance();
8552 $discount = $usces_tax->get_order_discount( $carts );
8553 $entries['order']['discount'] = $discount;
8554 $amount_by_cod = $total_items_price - $use_point + $discount;
8555 if ( 'all' == usces_is_fee_subject() ) {
8556 $amount_by_cod += $shipping_charge;
8557 }
8558 $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 );
8559 $cod_fee = $this->getCODFee( $entries['order']['payment_name'], $amount_by_cod, $entries );
8560 $cod_fee = apply_filters( 'usces_filter_set_cart_fees_cod', $cod_fee, $entries, $total_items_price, $use_point, $discount, $shipping_charge, $amount_by_cod );
8561 $entries['order']['cod_fee'] = $cod_fee;
8562
8563 if ( 'include' == $this->options['tax_mode'] ) {
8564 $tax = 0;
8565 } else {
8566 $materials = compact( 'member', 'entries', 'carts', 'total_items_price', 'shipping_charge', 'payments', 'discount', 'cod_fee', 'use_point' );
8567 $usces_tax->get_order_tax( $materials );
8568 $tax = apply_filters( 'usces_filter_getTax', $usces_tax->tax, $materials );
8569 }
8570
8571 $total_price = $total_items_price - $use_point + $discount + $shipping_charge + $cod_fee;
8572 if ( $total_price < 0 ) {
8573 $total_price = 0;
8574 }
8575 $total_price = apply_filters( 'usces_filter_set_cart_fees_total_price', $total_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee );
8576
8577 } else {
8578 $discount = $this->get_order_discount( null, $carts );
8579 $entries['order']['discount'] = $discount;
8580 $amount_by_cod = $total_items_price - $use_point + $discount;
8581 if ( 'all' == usces_is_fee_subject() ) {
8582 $amount_by_cod += $shipping_charge;
8583 }
8584 $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 );
8585 $cod_fee = $this->getCODFee( $entries['order']['payment_name'], $amount_by_cod, $entries );
8586 $cod_fee = apply_filters( 'usces_filter_set_cart_fees_cod', $cod_fee, $entries, $total_items_price, $use_point, $discount, $shipping_charge, $amount_by_cod );
8587 $entries['order']['cod_fee'] = $cod_fee;
8588
8589 $total_price = $total_items_price - $use_point + $discount + $shipping_charge + $cod_fee;
8590 if ( $total_price < 0 ) {
8591 $total_price = 0;
8592 }
8593 $total_price = apply_filters( 'usces_filter_set_cart_fees_total_price', $total_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee );
8594
8595 $materials = compact( 'member', 'entries', 'carts', 'total_items_price', 'shipping_charge', 'payments', 'discount', 'cod_fee', 'use_point' );
8596 $tax = $this->getTax( $total_price, $materials );
8597 }
8598 $entries['order']['total_price'] = $total_price;
8599 $entries['order']['tax'] = $tax;
8600
8601 if ( 'exclude' == $this->options['tax_mode'] ) {
8602 if ( 0 < $use_point ) {
8603 $total_full_price = $total_items_price - $use_point + $discount + $shipping_charge + $cod_fee + $tax;
8604 if ( $total_full_price < 0 ) {
8605 $total_full_price = 0;
8606 }
8607 } else {
8608 $total_full_price = $total_price + $tax;
8609 }
8610 } else {
8611 $total_full_price = $total_price;
8612 }
8613
8614 $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 );
8615 $entries['order']['total_full_price'] = $total_full_price;
8616
8617 $mem_id = isset( $member['ID'] ) ? $member['ID'] : null;
8618 $get_point = $this->get_order_point( $mem_id );
8619 $get_point = apply_filters( 'usces_filter_set_get_point', $get_point, $entries, $carts );
8620
8621 $array = array(
8622 'total_items_price' => $total_items_price,
8623 'total_price' => $total_price,
8624 'total_full_price' => $total_full_price,
8625 'getpoint' => $get_point,
8626 'usedpoint' => $use_point,
8627 'discount' => $discount,
8628 'shipping_charge' => $shipping_charge,
8629 'cod_fee' => $cod_fee,
8630 'tax' => $tax,
8631 );
8632 $this->cart->set_order_entry( $array );
8633 $usces_entries = $this->cart->get_entry();
8634 }
8635
8636 public function getPayments( $payment_name ) {
8637 $init = array(
8638 'id' => null,
8639 'name' => null,
8640 'explanation' => null,
8641 'settlement' => null,
8642 'module' => null,
8643 'sort' => null,
8644 'use' => null,
8645 );
8646
8647 if ( '#none#' == $payment_name ) {
8648 return $init;
8649 }
8650 $payments = usces_get_system_option( 'usces_payment_method', 'name' );
8651 if ( isset( $payments[ $payment_name ] ) ) {
8652 return $payments[ $payment_name ];
8653 }
8654 return $init;
8655 }
8656
8657 public function is_maintenance() {
8658 if ( 'Maintenancemode' == $this->options['display_mode'] ) {
8659 return true;
8660 } else {
8661 return false;
8662 }
8663 }
8664
8665 public function get_member_history( $mem_id, $allow_filter = false ) {
8666 global $wpdb;
8667 $order_table = $wpdb->prefix . 'usces_order';
8668
8669 if ( is_user_logged_in() && is_admin() ) {
8670
8671 $query = $wpdb->prepare( "SELECT * FROM $order_table WHERE mem_id = %d ORDER BY order_date DESC", $mem_id );
8672 $query = apply_filters( 'usces_filter_member_history_query', $query, $mem_id, $allow_filter );
8673 $results = $wpdb->get_results( $query );
8674
8675 } elseif ( ! is_admin() ) {
8676
8677 $cancel_query = '%cancel%';
8678 $estimate_query = '%estimate%';
8679 $exclude_cancel = $this->usces_get_member_cookies( 'ord_ex_cancel' );
8680 if ( $allow_filter && 'on' === (string) $exclude_cancel ) {
8681 $condition = ' ( order_status NOT LIKE %s AND order_status NOT LIKE %s ) ';
8682 } else {
8683 $condition = ' ( order_status LIKE %s OR order_status NOT LIKE %s ) ';
8684 }
8685
8686 $pur_date = $this->usces_get_member_cookies( 'pur-date' );
8687 if ( $allow_filter && $pur_date ) {
8688 $now = current_time( 'timestamp' );
8689 $type_filter = 'date';
8690 if ( false !== strpos( $pur_date, 'y_' ) ) {
8691 $type_filter = 'year';
8692 } elseif ( false !== strpos( $pur_date, 'm_' ) ) {
8693 $type_filter = 'month';
8694 }
8695 if ( 'year' === $type_filter ) {
8696 $purchase_year = (int) str_replace( 'y_', '', $pur_date );
8697 } elseif ( 'month' === $type_filter ) {
8698 $month_ago = (int) str_replace( 'm_', '', $pur_date );
8699 $first_day_of_previous_months = strtotime( "first day of -{$month_ago} months", $now );
8700 $last_day_of_previous_months = strtotime( "last day of -{$month_ago} months", $now );
8701 $purchase_date_from_string = date( 'Y-m-d 00:00:00', $first_day_of_previous_months );
8702 $purchase_date_to_string = date( 'Y-m-d 23:59:59', $last_day_of_previous_months );
8703 } else {
8704 $pur_date_val = (int) str_replace( 'd_', '', $pur_date );
8705 $previous_date = strtotime( "-{$pur_date_val} days", $now );
8706 $purchase_date_string = date( 'Y-m-d 00:00:00', $previous_date );
8707 }
8708 if ( 'year' === $type_filter ) {
8709 $query = $wpdb->prepare(
8710 "SELECT * FROM $order_table WHERE mem_id = %d AND YEAR(order_date) = %d AND {$condition} ORDER BY order_date DESC",
8711 $mem_id,
8712 $purchase_year,
8713 $cancel_query,
8714 $estimate_query
8715 );
8716 } elseif ( 'month' === $type_filter ) {
8717 $query = $wpdb->prepare(
8718 "SELECT * FROM $order_table WHERE mem_id = %d AND order_date >= %s AND order_date <= %s AND {$condition} ORDER BY order_date DESC",
8719 $mem_id,
8720 $purchase_date_from_string,
8721 $purchase_date_to_string,
8722 $cancel_query,
8723 $estimate_query
8724 );
8725 } else {
8726 $query = $wpdb->prepare(
8727 "SELECT * FROM $order_table WHERE mem_id = %d AND order_date >= %s AND {$condition} ORDER BY order_date DESC",
8728 $mem_id,
8729 $purchase_date_string,
8730 $cancel_query,
8731 $estimate_query
8732 );
8733 }
8734 } else {
8735 $query = $wpdb->prepare(
8736 "SELECT * FROM $order_table WHERE mem_id = %d AND {$condition} ORDER BY order_date DESC",
8737 $mem_id,
8738 $cancel_query,
8739 $estimate_query
8740 );
8741 }
8742
8743 $query = apply_filters( 'usces_filter_member_history_query_front', $query, $mem_id, $allow_filter );
8744 $results = $wpdb->get_results( $query );
8745 }
8746
8747 $i = 0;
8748 $res = array();
8749
8750 foreach ( $results as $value ) {
8751 $cart = usces_get_ordercartdata( $value->ID );
8752 $total_items_price = $this->get_total_price( $cart );
8753
8754 $data = array(
8755 'ID' => $value->ID,
8756 'cart' => $cart,
8757 'condition' => unserialize( $value->order_condition ),
8758 'getpoint' => $value->order_getpoint,
8759 'usedpoint' => $value->order_usedpoint,
8760 'discount' => $value->order_discount,
8761 'shipping_charge' => $value->order_shipping_charge,
8762 'payment_name' => $value->order_payment_name,
8763 'cod_fee' => $value->order_cod_fee,
8764 'tax' => $value->order_tax,
8765 'total_items_price' => $total_items_price,
8766 'order_status' => $value->order_status,
8767 'date' => mysql2date( __( 'Y/m/d' ), $value->order_date ),
8768 'order_date' => $value->order_date,
8769 'order_delidue_date' => $value->order_delidue_date,
8770 'order_delivery_method' => $value->order_delivery_method,
8771 'order_delivery_method_name' => usces_delivery_method_name( $value->order_delivery_method, 'return' ),
8772 'order_delivery_date' => $value->order_delivery_date,
8773 'order_modified' => $value->order_modified,
8774 );
8775 $res[] = apply_filters( 'usces_filter_member_history_data', $data, $mem_id, $value, $cart, $total_items_price );
8776 }
8777
8778 return $res;
8779 }
8780
8781 public function get_post_term_ids( $post_id, $taxonomy ) {
8782 global $wpdb;
8783 $query = $wpdb->prepare(
8784 "SELECT tt.term_id FROM $wpdb->term_relationships AS `tr`
8785 INNER JOIN $wpdb->term_taxonomy AS `tt` ON tt.term_taxonomy_id = tr.term_taxonomy_id
8786 WHERE tt.taxonomy = %s AND tr.object_id = %d",
8787 $taxonomy, $post_id
8788 );
8789 $ids = $wpdb->get_col( $query );
8790
8791 return $ids;
8792 }
8793
8794 public function get_tag_names( $post_id ) {
8795 global $wpdb;
8796 $tag = 'post_tag';
8797 $query = $wpdb->prepare(
8798 "SELECT t.name FROM $wpdb->term_relationships AS `tr`
8799 INNER JOIN $wpdb->term_taxonomy AS `tt` ON tt.term_taxonomy_id = tr.term_taxonomy_id
8800 INNER JOIN $wpdb->terms AS `t` ON t.term_id = tt.term_id
8801 WHERE tt.taxonomy = %s AND tr.object_id = %d",
8802 $tag, $post_id
8803 );
8804 $names = $wpdb->get_col( $query );
8805
8806 return apply_filters( 'usces_filter_get_tag_names', $names, $post_id );
8807 }
8808
8809 public function get_ID_byItemName( $item_code, $status = 'publish' ) {
8810 global $wpdb;
8811
8812 $table = usces_get_tablename( 'usces_item' );
8813 $id = $wpdb->get_var(
8814 $wpdb->prepare(
8815 "SELECT p.ID FROM {$wpdb->posts} AS `p`
8816 INNER JOIN {$table} AS `item` ON p.ID = item.post_id
8817 WHERE p.post_status = %s AND item.itemCode = %s",
8818 $status,
8819 $item_code
8820 )
8821 );
8822
8823 return $id;
8824 }
8825
8826 public function uscescv( $sessid, $flag ) {
8827 $chars = '';
8828 $i = 0;
8829 $h = 0;
8830 $usces_cookie = $this->get_cookie();
8831 if ( isset( $usces_cookie['id'] ) && ! empty( $usces_cookie['id'] ) ) {
8832 $cid = $usces_cookie['id'];
8833 } elseif ( isset( $_SESSION['usces_cookieid'] ) && ! empty( $_SESSION['usces_cookieid'] ) ) {
8834 $cid = $_SESSION['usces_cookieid'];
8835 } else {
8836 $cid = 0;
8837 }
8838 while ( $h < strlen( $sessid ) ) {
8839 if ( 0 == $i % 3 ) {
8840 $chars .= substr( $i, -1 );
8841 } else {
8842 $chars .= substr( $sessid, $h, 1 );
8843 $h++;
8844 }
8845 $i++;
8846 }
8847 if ( $flag ) {
8848 $postfix = ( isset( $_SERVER['REMOTE_ADDR'] ) && ! empty( $_SERVER['REMOTE_ADDR'] ) ) ? $_SERVER['REMOTE_ADDR'] : 'REMOTE_ADDR';
8849 $postfix = apply_filters( 'usces_sessid_force', $postfix );
8850 $sessid = $chars . '_' . $postfix . '_' . $cid . '_A';
8851 } else {
8852 $sessid = $chars . '_' . apply_filters( 'usces_sessid_flag', 'acting' ) . '_' . $cid . '_A';
8853 }
8854 $sessid = urlencode( base64_encode( $sessid ) );
8855
8856 return $sessid;
8857 }
8858
8859 public function uscesdc( $sessid ) {
8860 $sessid = base64_decode( urldecode( $sessid ) );
8861 list( $sess, $addr, $cookieid, $none ) = explode( '_', $sessid, 4 );
8862 $postfix = ( isset( $_SERVER['REMOTE_ADDR'] ) && ! empty( $_SERVER['REMOTE_ADDR'] ) ) ? $_SERVER['REMOTE_ADDR'] : 'REMOTE_ADDR';
8863 $postfix = apply_filters( 'usces_sessid_force', $postfix );
8864 if ( 'acting' !== $addr && 'mobile' !== $addr && $postfix !== $addr ) {
8865 $sessid = '';
8866 return null;
8867 }
8868 $chars = '';
8869 $h = 0;
8870 while ( $h < strlen( $sess ) ) {
8871 if ( 0 != $h % 3 ) {
8872 $chars .= substr( $sess, $h, 1 );
8873 }
8874 $h++;
8875 }
8876 $sessid = $chars;
8877
8878 return $sessid;
8879 }
8880
8881 public function get_visiter( $period ) {
8882 global $wpdb;
8883 $datestr = substr( get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ), 0, 10 );
8884 $yearstr = substr( $datestr, 0, 4 );
8885 $monthstr = substr( $datestr, 5, 2 );
8886 $daystr = substr( $datestr, 8, 2 );
8887 if ( 'today' == $period ) {
8888 $date = $datestr;
8889 $today = $datestr;
8890 } elseif ( 'thismonth' == $period ) {
8891 $date = date( 'Y-m-01' );
8892 $today = $datestr;
8893 } elseif ( 'lastyear' == $period ) {
8894 $date = date( 'Y-m-01', mktime( 0, 0, 0, (int) $monthstr, 1, (int) $yearstr-1 ) );
8895 $today = date( 'Y-m-01', mktime( 0, 0, 0, (int) $monthstr, (int) $daystr, (int) $yearstr-1 ) );
8896 }
8897 $table_name = $wpdb->prefix . 'usces_access';
8898
8899 $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 );
8900 $res = $wpdb->get_row( $query, ARRAY_A );
8901
8902 if ( null == $res ) {
8903 return 0;
8904 } else {
8905 return $res['ct1'] + $res['ct2'];
8906 }
8907 }
8908
8909 public function get_fvisiter( $period ) {
8910 global $wpdb;
8911 $datestr = substr( get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ), 0, 10 );
8912 $yearstr = substr( $datestr, 0, 4 );
8913 $monthstr = substr( $datestr, 5, 2 );
8914 $daystr = substr( $datestr, 8, 2 );
8915 if ( 'today' == $period ) {
8916 $date = $datestr;
8917 $today = $datestr;
8918 } elseif ( 'thismonth' == $period ) {
8919 $date = date( 'Y-m-01' );
8920 $today = $datestr;
8921 } elseif ( 'lastyear' == $period ) {
8922 $date = date( 'Y-m-01', mktime( 0, 0, 0, (int) $monthstr, 1, (int) $yearstr - 1 ) );
8923 $today = date( 'Y-m-01', mktime( 0, 0, 0, (int) $monthstr, (int) $daystr, (int) $yearstr - 1 ) );
8924 }
8925 $table_name = $wpdb->prefix . 'usces_access';
8926
8927 $query = $wpdb->prepare( "SELECT SUM(acc_num2) AS `ct` FROM $table_name WHERE acc_date >= %s AND acc_date <= %s", $date, $today );
8928 $res = $wpdb->get_var( $query );
8929
8930 if ( null == $res ) {
8931 return 0;
8932 } else {
8933 return $res;
8934 }
8935 }
8936
8937 public function get_order_num( $period ) {
8938 global $wpdb;
8939 $datestr = substr( get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ), 0, 10 );
8940 $yearstr = substr( $datestr, 0, 4 );
8941 $monthstr = substr( $datestr, 5, 2 );
8942 $daystr = substr( $datestr, 8, 2 );
8943 if ( 'today' == $period ) {
8944 $date = date( 'Y-m-d 00:00:00', current_time( 'timestamp' ) );
8945 $today = date( 'Y-m-d 23:59:59', current_time( 'timestamp' ) );
8946 } elseif ( 'thismonth' == $period ) {
8947 $date = date( 'Y-m-01 00:00:00', current_time( 'timestamp' ) );
8948 $today = date( 'Y-m-d 23:59:59', current_time( 'timestamp' ) );
8949 } elseif ( 'lastyear' == $period ) {
8950 $date = date( 'Y-m-01 00:00:00', mktime( 0, 0, 0, (int) $monthstr, 1, (int) $yearstr - 1 ) );
8951 $today = date( 'Y-m-d 23:59:59', mktime( 0, 0, 0, (int) $monthstr + 1, 0, (int) $yearstr - 1 ) );
8952 }
8953 $table_name = $wpdb->prefix . 'usces_order';
8954
8955 $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' );
8956 $res = $wpdb->get_var( $query );
8957
8958 if ( null == $res ) {
8959 return 0;
8960 } else {
8961 return $res;
8962 }
8963 }
8964
8965 public function get_order_amount( $period ) {
8966 global $wpdb;
8967
8968 $cache_key = 'wel_order_amount_period_' . $period;
8969
8970 $res = wp_cache_get( $cache_key );
8971 if ( false === $res ) {
8972
8973 $datestr = substr( get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ), 0, 10 );
8974 $yearstr = substr( $datestr, 0, 4 );
8975 $monthstr = substr( $datestr, 5, 2 );
8976 $daystr = substr( $datestr, 8, 2 );
8977 if ( 'today' == $period ) {
8978 $date = date( 'Y-m-d 00:00:00', current_time( 'timestamp' ) );
8979 $today = date( 'Y-m-d 23:59:59', current_time( 'timestamp' ) );
8980 } elseif ( 'thismonth' == $period ) {
8981 $date = date( 'Y-m-01 00:00:00', current_time( 'timestamp' ) );
8982 $today = date( 'Y-m-d 23:59:59', current_time( 'timestamp' ) );
8983 } elseif ( 'lastyear' == $period ) {
8984 $date = date( 'Y-m-01 00:00:00', mktime( 0, 0, 0, (int) $monthstr, 1, (int) $yearstr - 1 ) );
8985 $today = date( 'Y-m-d 23:59:59', mktime( 0, 0, 0, (int) $monthstr + 1, 0, (int) $yearstr - 1 ) );
8986 }
8987 $table_name = $wpdb->prefix . 'usces_order';
8988
8989 $query = $wpdb->prepare(
8990 "SELECT
8991 SUM(order_item_total_price) AS `price`,
8992 SUM(order_usedpoint) AS `point`,
8993 SUM(order_discount) AS `discount`,
8994 SUM(order_shipping_charge) AS `shipping`,
8995 SUM(order_cod_fee) AS `cod`,
8996 SUM(order_tax) AS `tax`
8997 FROM $table_name WHERE order_date >= %s AND order_date <= %s AND 0 = LOCATE(%s, order_status) AND 0 = LOCATE(%s, order_status)",
8998 $date, $today, 'cancel', 'estimate'
8999 );
9000 $res = $wpdb->get_row( $query, ARRAY_A );
9001
9002 if ( null !== $res ) {
9003 wp_cache_set( $cache_key, $res );
9004 }
9005 }
9006
9007 if ( null == $res ) {
9008 return 0;
9009 } else {
9010 return $res['price'] - $res['point'] + $res['discount'] + $res['shipping'] + $res['cod'] + $res['tax'];
9011 }
9012 }
9013
9014 public function is_status( $need, $str ) {
9015 if ( ! is_string( $str ) || empty( $str ) ) {
9016 $array = array();
9017 } else {
9018 $array = explode( ',', $str );
9019 }
9020 return in_array( $need, $array );
9021 }
9022
9023 public function make_status( $taio = '', $receipt = '', $admin = '' ) {
9024 $str = '';
9025 if ( '' != $taio && '#none#' != $taio ) {
9026 $str .= $taio . ',';
9027 }
9028 if ( '' != $receipt && '#none#' != $receipt ) {
9029 $str .= $receipt . ',';
9030 }
9031 if ( '' != $admin && '#none#' != $admin ) {
9032 $str .= $admin . ',';
9033 }
9034 return $str;
9035 }
9036
9037 public function get_memberid_by_email( $email ) {
9038 global $wpdb;
9039 $table_name = usces_get_tablename( 'usces_member' );
9040 $query = $wpdb->prepare( "SELECT ID FROM $table_name WHERE mem_email = %s", $email );
9041 $res = $wpdb->get_var( $query );
9042 return $res;
9043 }
9044
9045 public function get_condition() {
9046 $order_conditions = array(
9047 'display_mode' => $this->options['display_mode'],
9048 'campaign_privilege' => $this->options['campaign_privilege'],
9049 'campaign_category' => $this->options['campaign_category'],
9050 'privilege_point' => $this->options['privilege_point'],
9051 'privilege_discount' => $this->options['privilege_discount'],
9052 'tax_display' => ( isset( $this->options['tax_display'] ) ) ? $this->options['tax_display'] : 'activate',
9053 'tax_mode' => $this->options['tax_mode'],
9054 'tax_target' => $this->options['tax_target'],
9055 'tax_rate' => $this->options['tax_rate'],
9056 'tax_method' => $this->options['tax_method'],
9057 'applicable_taxrate' => ( isset( $this->options['applicable_taxrate'] ) ) ? $this->options['applicable_taxrate'] : 'standard',
9058 'tax_rate_reduced' => ( isset( $this->options['tax_rate_reduced'] ) ) ? $this->options['tax_rate_reduced'] : $this->options['tax_rate'],
9059 'membersystem_state' => $this->options['membersystem_state'],
9060 'membersystem_point' => $this->options['membersystem_point'],
9061 'point_coverage' => $this->options['point_coverage'],
9062 );
9063 return $order_conditions;
9064 }
9065
9066 public function get_bestseller_ids( $days = '' ) {
9067 global $wpdb;
9068
9069 $datestr = substr( get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ), 0, 10 );
9070 $yearstr = substr( $datestr, 0, 4 );
9071 $monthstr = substr( $datestr, 5, 2 );
9072 $daystr = substr( $datestr, 8, 2 );
9073
9074 $res = array();
9075 $order_table_name = $wpdb->prefix . 'usces_order';
9076 $where = '';
9077 if ( empty( $days ) ) {
9078 $days = 30;
9079 }
9080 $order_date = date( 'Y-m-d H:i:s', mktime( 0, 0, 0, (int) $monthstr, ( (int) $daystr - $days), (int) $yearstr ) );
9081 $where = " WHERE order_date >= '{$order_date}'";
9082 $query = "SELECT order_cart FROM {$order_table_name}" . $where;
9083 $dbres = $wpdb->get_col( $query );
9084 if ( ! $dbres ) {
9085 return false;
9086 }
9087
9088 foreach ( (array) $dbres as $carts ) {
9089 $rows = unserialize( $carts );
9090 foreach ( (array) $rows as $carts ) {
9091 if ( 'publish' != get_post_status( $carts['post_id'] ) ) {
9092 continue;
9093 }
9094 $id = $carts['post_id'];
9095 $qu = $carts['quantity'];
9096 if ( array_key_exists( $id, $res ) ) {
9097 $res[ $id ] = $res[ $id ] + $qu;
9098 } else {
9099 $res[ $id ] = $qu;
9100 }
9101 }
9102 }
9103 arsort( $res );
9104 $results = array_keys( $res );
9105 return $results;
9106 }
9107
9108 public function get_items_num() {
9109 global $wpdb;
9110 $res = $wpdb->get_var(
9111 $wpdb->prepare(
9112 "SELECT COUNT(ID) AS `ct` FROM {$wpdb->posts}
9113 WHERE post_mime_type = %s AND post_type = %s AND post_status <> %s",
9114 'item',
9115 'post',
9116 'trash'
9117 )
9118 );
9119
9120 return $res;
9121 }
9122
9123 public function is_gptekiyo( $post_id, $sku, $quant ) {
9124 $skus = $this->get_skus( $post_id, 'code' );
9125 if ( ! isset( $skus[ $sku ]['gp'] ) || ! $skus[ $sku ]['gp'] ) {
9126 return false;
9127 }
9128
9129 $GpN1 = $this->getItemGpNum1( $post_id );
9130 $GpN2 = $this->getItemGpNum2( $post_id );
9131 $GpN3 = $this->getItemGpNum3( $post_id );
9132
9133 if ( empty( $GpN1 ) ) {
9134
9135 return false;
9136
9137 } elseif ( ! empty( $GpN1 ) && empty( $GpN2 ) ) {
9138
9139 if ( $quant >= $GpN1 ) {
9140 return true;
9141 } else {
9142 return false;
9143 }
9144
9145 } elseif ( ! empty( $GpN1 ) && ! empty( $GpN2 ) && empty( $GpN3 ) ) {
9146
9147 if ( $quant >= $GpN2 ) {
9148 return true;
9149 } elseif ( $quant >= $GpN1 && $quant < $GpN2 ) {
9150 return true;
9151 } else {
9152 return false;
9153 }
9154
9155 } elseif ( ! empty( $GpN1 ) && ! empty( $GpN2 ) && ! empty( $GpN3 ) ) {
9156
9157 if ( $quant >= $GpN3 ) {
9158 return true;
9159 } elseif ( $quant >= $GpN2 && $quant < $GpN3 ) {
9160 return true;
9161 } elseif ( $quant >= $GpN1 && $quant < $GpN2 ) {
9162 return true;
9163 } else{
9164 return false;
9165 }
9166 }
9167 }
9168
9169 public function get_available_delivery_method() {
9170 if ( $this->cart->num_row() > 0 ) {
9171 $cart = $this->cart->get_cart();
9172 $before_deli = array();
9173 $intersect = array();
9174 $integration = array();
9175 $temp = array();
9176 $in = 0;
9177 foreach ( $cart as $key => $row ) {
9178 $deli = $this->getItemDeliveryMethod( $row['post_id'] );
9179 if ( empty( $deli ) ) {
9180 continue;
9181 }
9182 if ( 0 === $in ) {
9183 $intersect = $deli;
9184 }
9185 $intersect = array_intersect( $deli, $intersect );
9186 $before_deli = $deli;
9187 foreach ( $deli as $value ) {
9188 $integration[] = $value;
9189 }
9190 $in++;
9191 }
9192 $integration = array_unique( $integration );
9193 foreach ( $integration as $id ) {
9194 $index = $this->get_delivery_method_index( $id );
9195 if ( 0 <= $index ) {
9196 $temp[ $index ] = $id;
9197 }
9198 }
9199 ksort( $temp );
9200 $force = array( array_shift( $temp ) );
9201
9202 if ( empty( $intersect ) ) {
9203 return $force;
9204 } else {
9205 return $intersect;
9206 }
9207 }
9208 return array();
9209 }
9210
9211 public function get_delivery_method_index( $id ) {
9212 $index = false;
9213 $delivery_method_count = ( $this->options['delivery_method'] && is_array( $this->options['delivery_method'] ) ) ? count( $this->options['delivery_method'] ) : 0;
9214 for ( $i = 0; $i < $delivery_method_count; $i++ ) {
9215 if ( isset( $this->options['delivery_method'][ $i ]['id'] ) && $this->options['delivery_method'][ $i ]['id'] === (int) $id ) {
9216 $index = $i;
9217 }
9218 }
9219 if ( false === $index ) {
9220 return -1;
9221 } else {
9222 return $index;
9223 }
9224 }
9225
9226 public function get_shipping_charge_index( $id ) {
9227 $index = false;
9228 $shipping_charge_count = ( $this->options['shipping_charge'] && is_array( $this->options['shipping_charge'] ) ) ? count( $this->options['shipping_charge'] ) : 0;
9229 for ( $i = 0; $i < $shipping_charge_count; $i++ ) {
9230 if ( isset( $this->options['shipping_charge'][ $i ] ) && (int) $this->options['shipping_charge'][ $i ]['id'] == (int) $id ) {
9231 $index = $i;
9232 }
9233 }
9234 if ( false === $index ) {
9235 return -1;
9236 } else {
9237 return $index;
9238 }
9239 }
9240
9241 public function get_initial_data( $xml ) {
9242 $buf = file_get_contents( $xml );
9243 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 );
9244 return $match;
9245 }
9246
9247 public function getCurrencySymbol() {
9248 global $usces_settings;
9249 $cr = $this->options['system']['currency'];
9250 list( $code, $decimal, $point, $seperator, $symbol ) = $usces_settings['currency'][ $cr ];
9251 return $symbol;
9252 }
9253
9254 public function getCartItemName( $post_id, $sku ) {
9255 $name_arr = array();
9256 $name_str = '';
9257
9258 foreach ( $this->options['indi_item_name'] as $key => $value ) {
9259 if ( $value ) {
9260 $pos = (int) $this->options['pos_item_name'][ $key ];
9261 $ind = ( 0 === $pos ) ? 'A' : $pos;
9262 switch ( $key ) {
9263 case 'item_name':
9264 $name_arr[ $ind ][ $key ] = $this->getItemName( $post_id );
9265 break;
9266 case 'item_code':
9267 $name_arr[ $ind ][ $key ] = $this->getItemCode( $post_id );
9268 break;
9269 case 'sku_name':
9270 $name_arr[ $ind ][ $key ] = $this->getItemSkuDisp( $post_id, $sku );
9271 break;
9272 case 'sku_code':
9273 $name_arr[ $ind ][ $key ] = $sku;
9274 break;
9275 }
9276 }
9277 }
9278 ksort( $name_arr );
9279 foreach ( $name_arr as $vals ) {
9280 foreach ( $vals as $key => $value ) {
9281 $name_str .= $value . ' ';
9282 }
9283 }
9284
9285 $name_str = apply_filters( 'usces_admin_order_item_name_filter', $name_str, $post_id, $sku );
9286
9287 return trim( $name_str );
9288 }
9289
9290 public function getCartItemName_byOrder( $cart_row ) {
9291 $name_arr = array();
9292 $name_str = '';
9293
9294 foreach ( $this->options['indi_item_name'] as $key => $value ) {
9295 if ( $value ) {
9296 $pos = (int) $this->options['pos_item_name'][ $key ];
9297 $ind = ( 0 === $pos ) ? 'A' : $pos;
9298 switch ( $key ) {
9299 case 'item_name':
9300 $name_arr[ $ind ][ $key ] = $cart_row['item_name'];
9301 break;
9302 case 'item_code':
9303 $name_arr[ $ind ][ $key ] = $cart_row['item_code'];
9304 break;
9305 case 'sku_name':
9306 $name_arr[ $ind ][ $key ] = $cart_row['sku_name'];
9307 break;
9308 case 'sku_code':
9309 $name_arr[ $ind ][ $key ] = $cart_row['sku_code'];
9310 break;
9311 }
9312 }
9313 }
9314 ksort( $name_arr );
9315 foreach ( $name_arr as $vals ) {
9316 foreach ( $vals as $key => $value ) {
9317 $name_str .= $value . ' ';
9318 }
9319 }
9320
9321 $name_str = apply_filters( 'usces_filter_item_mame_by_order', $name_str, $cart_row );
9322
9323 return trim( $name_str );
9324 }
9325
9326 public function set_reserve_pre_order_id() {
9327 $entry = $this->cart->get_entry();
9328 $id = ( isset( $entry['reserve']['pre_order_id'] ) && ! empty( $entry['reserve']['pre_order_id'] ) ) ? $entry['reserve']['pre_order_id'] : uniqid( '' );
9329 $this->cart->set_pre_order_id( $id );
9330 }
9331
9332 public function get_current_pre_order_id() {
9333 $entry = $this->cart->get_entry();
9334 $id = ( isset( $entry['reserve']['pre_order_id'] ) && ! empty( $entry['reserve']['pre_order_id'] ) ) ? $entry['reserve']['pre_order_id'] : null;
9335 return $id;
9336 }
9337
9338 public function get_order_id_by_pre_order_id( $pre_order_id ) {
9339 global $wpdb;
9340 $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 );
9341 $order_id = $wpdb->get_var( $query );
9342 return $order_id;
9343 }
9344
9345 public function get_reserve( $order_id, $key ) {
9346 global $wpdb;
9347 $order_meta_table_name = $wpdb->prefix . 'usces_order_meta';
9348 $query = $wpdb->prepare( "SELECT meta_value FROM $order_meta_table_name WHERE order_id = %d AND meta_key = %s", $order_id, $key );
9349 $res = $wpdb->get_var( $query );
9350 return $res;
9351 }
9352
9353 public function get_order_meta_value( $key, $order_id ) {
9354 global $wpdb;
9355 $order_meta_table_name = $wpdb->prefix . 'usces_order_meta';
9356 $query = $wpdb->prepare( "SELECT meta_value FROM $order_meta_table_name WHERE order_id = %d AND meta_key = %s", $order_id, $key );
9357 $res = $wpdb->get_var( $query );
9358 return $res;
9359 }
9360
9361 public function set_order_meta_value( $key, $meta_value, $order_id, $check = 1 ) {
9362 global $wpdb;
9363
9364 if ( empty( $order_id ) ) {
9365 return;
9366 }
9367
9368 $order_id = (int) $order_id;
9369 if ( $check ) {
9370 $order = $this->get_order_data( $order_id, 'direct' );
9371 if ( null === $order ) {
9372 return;
9373 }
9374 }
9375
9376 $table_name = $wpdb->prefix . 'usces_order_meta';
9377 $query = $wpdb->prepare(
9378 "SELECT count(*) FROM $table_name WHERE order_id = %d AND meta_key = %s",
9379 $order_id, $key
9380 );
9381 $res = $wpdb->get_var( $query );
9382 if ( 0 < $res ) {
9383 $query = $wpdb->prepare(
9384 "UPDATE $table_name SET meta_value = %s WHERE order_id = %d AND meta_key = %s",
9385 $meta_value,
9386 $order_id,
9387 $key
9388 );
9389 $res2 = $wpdb->query( $query );
9390 } else {
9391 $query = $wpdb->prepare(
9392 "INSERT INTO $table_name (order_id, meta_key, meta_value)
9393 VALUES(%d, %s, %s)",
9394 $order_id,
9395 $key,
9396 $meta_value
9397 );
9398 $res2 = $wpdb->query( $query );
9399 }
9400 return $res2;
9401 }
9402
9403 public function del_order_meta( $key, $order_id ) {
9404 global $wpdb;
9405 $table_name = $wpdb->prefix . 'usces_order_meta';
9406 $query = $wpdb->prepare( "DELETE FROM $table_name WHERE order_id = %d AND meta_key = %s", $order_id, $key );
9407 $res = $wpdb->query( $query );
9408 return $res;
9409 }
9410
9411 public function set_session_custom_member( $member_id ) {
9412 unset( $_SESSION['usces_member']['custom_member'] );
9413 $meta = usces_has_custom_field_meta( 'member' );
9414 if ( is_array( $meta ) ) {
9415 $keys = array_keys( $meta );
9416 foreach ( $keys as $key ) {
9417 $csmb_key = 'csmb_' . $key;
9418 $_SESSION['usces_member']['custom_member'][ $key ] = maybe_unserialize( $this->get_member_meta_value( $csmb_key, $member_id ) );
9419 }
9420 }
9421 }
9422
9423 public function reg_custom_member( $member_id ) {
9424 $csmb_meta = usces_has_custom_field_meta( 'member' );
9425 if ( is_array( $csmb_meta ) ) {
9426 foreach ( $csmb_meta as $key => $entry ) {
9427 if ( '4' == $entry['means'] ) {
9428 $this->del_member_meta( 'csmb_' . $key, $member_id );
9429 }
9430 }
9431 }
9432 if ( ! empty( $_POST['custom_member'] ) ) {
9433 foreach ( $_POST['custom_member'] as $key => $value ) {
9434 $csmb_key = 'csmb_' . $key;
9435 $value = wel_safe_text_serialize( $value );
9436 if ( is_array( $value ) ) {
9437 $value = serialize( $value );
9438 }
9439 $res = $this->set_member_meta_value( $csmb_key, $value, $member_id );
9440 if ( false === $res ) {
9441 return false;
9442 }
9443 }
9444 } elseif ( isset( $_POST['custom_customer'] ) ) {
9445 foreach ( $_POST['custom_customer'] as $key => $value ) {
9446 $csmb_key = 'csmb_' . $key;
9447 $value = wel_safe_text_serialize( $value );
9448 if ( is_array( $value ) ) {
9449 $value = serialize( $value );
9450 }
9451 $res = $this->set_member_meta_value( $csmb_key, $value, $member_id );
9452 if ( false === $res ) {
9453 return false;
9454 }
9455 }
9456 }
9457 }
9458
9459 public function save_order_acting_data( $rand ) {
9460 global $wpdb;
9461 $data = serialize(
9462 array(
9463 'cart' => $this->cart->get_cart(),
9464 'entry' => $this->cart->get_entry(),
9465 )
9466 );
9467 $table_name = $wpdb->prefix . 'usces_access';
9468 $query = $wpdb->prepare(
9469 "INSERT INTO $table_name (acc_type, acc_str1, acc_date, acc_key, acc_value)
9470 VALUES(%s, %s, now(), %s, %s)",
9471 'acting_data',
9472 $this->get_uscesid(false),
9473 $rand,
9474 $data
9475 );
9476 $res = $wpdb->query( $query );
9477 return $res;
9478 }
9479
9480 public function set_member_meta_value( $key, $meta_value, $member_id = '' ) {
9481 global $wpdb;
9482
9483 if ( WCUtils::is_blank( $member_id ) ) {
9484 if ( ! $this->is_member_logged_in() ) {
9485 return;
9486 }
9487 $member = $this->get_member();
9488 $member_id = $member['ID'];
9489 }
9490
9491 $table_name = usces_get_tablename( 'usces_member_meta' );
9492 $query = $wpdb->prepare( "SELECT count(*) FROM $table_name WHERE member_id = %d AND meta_key = %s", $member_id, $key );
9493 $res = $wpdb->get_var( $query );
9494 if ( 0 < $res ) {
9495 $query = $wpdb->prepare(
9496 "UPDATE $table_name SET meta_value = %s WHERE member_id = %d AND meta_key = %s",
9497 $meta_value,
9498 $member_id,
9499 $key
9500 );
9501 $res2 = $wpdb->query( $query );
9502 } else {
9503 $query = $wpdb->prepare(
9504 "INSERT INTO $table_name (member_id, meta_key, meta_value)
9505 VALUES(%d, %s, %s)",
9506 $member_id,
9507 $key,
9508 $meta_value
9509 );
9510 $res2 = $wpdb->query( $query );
9511 }
9512 return $res2;
9513 }
9514
9515 public function get_member_meta_value( $key, $member_id ) {
9516 global $wpdb;
9517 $table_name = usces_get_tablename( 'usces_member_meta' );
9518 $query = $wpdb->prepare( "SELECT meta_value FROM $table_name WHERE member_id = %d AND meta_key = %s", $member_id, $key );
9519 $res = $wpdb->get_var( $query );
9520 return $res;
9521 }
9522
9523 public function del_member_meta( $key, $member_id ) {
9524 global $wpdb;
9525 $table_name = usces_get_tablename( 'usces_member_meta' );
9526 $query = $wpdb->prepare( "DELETE FROM $table_name WHERE member_id = %d AND meta_key = %s", $member_id, $key );
9527 $res = $wpdb->query( $query );
9528 return $res;
9529 }
9530
9531 public function get_member_meta( $member_id ) {
9532 global $wpdb;
9533 $table_name = usces_get_tablename( 'usces_member_meta' );
9534 $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_%' );
9535 $res = $wpdb->get_results( $query, ARRAY_A );
9536 return $res;
9537 }
9538
9539 public function get_settle_info_field( $order_id ) {
9540 global $wpdb;
9541 $fields = array();
9542 $table_name = $wpdb->prefix . 'usces_order_meta';
9543 $meta_keys = apply_filters( 'usces_filter_settle_info_field_meta_keys', array( 'settlement_id', 'order_number', 'res_tracking_id', 'SID', 'TransactionId' ) );
9544 $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 ) );
9545 $query = stripslashes( $query );
9546 $res = $wpdb->get_results( $query, ARRAY_A );
9547 if ( ! $res ) {
9548 return $fields;
9549 }
9550 foreach ( $res as $value ) {
9551 if ( in_array( $value['meta_key'], $meta_keys ) ) {
9552 $meta_key = $value['meta_key'];
9553 if ( 'settlement_id' == $meta_key ) {
9554 $meta_values = maybe_unserialize( $value['meta_value'] );
9555 if ( is_array( $meta_values ) ) {
9556 foreach ( $meta_values as $key => $meta_value ) {
9557 $fields[ $key ] = $meta_value;
9558 }
9559 } else {
9560 $fields['settlement_id'] = $meta_values;
9561 }
9562 } else {
9563 $fields[ $meta_key ] = $value['meta_value'];
9564 }
9565 } elseif ( 'acting_' == substr( $value['meta_key'], 0, 7 ) ) {
9566 $meta_values = usces_unserialize( $value['meta_value'] );
9567 if ( is_array( $meta_values ) ) {
9568 foreach ( $meta_values as $key => $meta_value ) {
9569 $fields[ $key ] = $meta_value;
9570 }
9571 } else {
9572 $meta_values = maybe_unserialize( $value['meta_value'] );
9573 if ( is_array( $meta_values ) ) {
9574 foreach ( $meta_values as $key => $meta_value ) {
9575 $fields[ $key ] = $meta_value;
9576 }
9577 }
9578 }
9579 }
9580 }
9581 return $fields;
9582 }
9583
9584 public function get_post_custom( $post_id, $orderby = 'meta_id', $order = 'ASC' ) {
9585 global $wpdb;
9586 $table = $wpdb->prefix . 'postmeta';
9587 $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 );
9588
9589 if ( ! empty( $meta_list ) ) {
9590 foreach ( $meta_list as $metarow ) {
9591 $mkey = $metarow['meta_key'];
9592 $mval = $metarow['meta_value'];
9593 $res[ $mkey ][] = $mval;
9594 }
9595 }
9596 return $res;
9597 }
9598
9599 public function get_post_user_custom( $post_id, $orderby = 'meta_id', $order = 'ASC' ) {
9600 global $wpdb;
9601 $res = array();
9602 $table = $wpdb->prefix . 'postmeta';
9603 $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 );
9604
9605 if ( ! empty( $meta_list ) ) {
9606 foreach ( $meta_list as $metarow ) {
9607 if ( 0 === strpos( $metarow['meta_key'], '_' ) ) {
9608 continue;
9609 }
9610 $mkey = $metarow['meta_key'];
9611 $mval = $metarow['meta_value'];
9612 if ( array_key_exists( $mkey, $res ) ) {
9613 $cval = $res[ $mkey ];
9614 $cval = (array) $cval;
9615 $cval[] = $mval;
9616 $res[ $mkey ] = $cval;
9617 } else {
9618 $res[ $mkey ] = $mval;
9619 }
9620 }
9621 }
9622 $res = apply_filters( 'usces_filter_get_post_user_custom', $res, $meta_list, $post_id, $orderby, $order );
9623 return $res;
9624 }
9625
9626 public function get_currency( $amount, $symbol_pre = false, $symbol_post = false, $seperator_flag = true ) {
9627 global $usces_settings;
9628 $cr = $this->options['system']['currency'];
9629 list( $code, $decimal, $point, $seperator, $symbol ) = $usces_settings['currency'][ $cr ];
9630 if ( ! $seperator_flag ) {
9631 $seperator = '';
9632 }
9633 $price = number_format( (double) $amount, $decimal, $point, $seperator );
9634
9635 if ( $symbol_pre ) {
9636 $price = ( usces_is_entity( $symbol ) ? mb_convert_encoding( $symbol, 'UTF-8', 'HTML-ENTITIES' ) : $symbol ) . $price;
9637 }
9638 if ( $symbol_post ) {
9639 $price = $price . __( $code, 'usces' );
9640 }
9641 $price = apply_filters( 'usces_filter_get_currency', $price, $amount, $symbol_pre, $symbol_post, $seperator_flag );
9642 return $price;
9643 }
9644
9645 public function get_currency_code() {
9646 global $usces_settings;
9647 $cr = $this->options['system']['currency'];
9648 list( $code, $decimal, $point, $seperator, $symbol ) = $usces_settings['currency'][ $cr ];
9649 return $code;
9650 }
9651
9652 public function get_currency_decimal() {
9653 global $usces_settings;
9654 $cr = $this->options['system']['currency'];
9655 list( $code, $decimal, $point, $seperator, $symbol ) = $usces_settings['currency'][ $cr ];
9656 return $decimal;
9657 }
9658
9659 public function get_next_page_uri( $type, $current ) {
9660 global $wpdb;
9661
9662 $table = $wpdb->prefix . 'usces_' . $type;
9663 if ( ! isset( $_COOKIE[ $table ] ) ) {
9664 return false;
9665 }
9666
9667 $cookie = ( isset( $_COOKIE[ $table ] ) ) ? json_decode( str_replace( "\'", "'", str_replace( '\"', '"', $_COOKIE[ $table ] ) ), true ) : array();
9668 if ( ! isset( $cookie['currentPageIds'] ) ) {
9669 return false;
9670 }
9671
9672 $ids = $cookie['currentPageIds'];
9673 foreach ( $ids as $key => $id ) {
9674 if ( $id == $current ) {
9675 $next = isset( $ids[ ( $key + 1 ) ] ) ? $ids[ ( $key + 1 ) ] : '';
9676 break;
9677 }
9678 }
9679
9680 if ( empty( $next ) ) {
9681 $uri = '';
9682 } else {
9683 $uri = USCES_ADMIN_URL . "?page=usces_{$type}list&{$type}_action=edit&{$type}_id=" . $next;
9684 }
9685
9686 return esc_url( $uri );
9687 }
9688
9689 public function get_prev_page_uri( $type, $current ) {
9690 global $wpdb;
9691
9692 $table = $wpdb->prefix . 'usces_' . $type;
9693 if ( ! isset( $_COOKIE[ $table ] ) ) {
9694 return false;
9695 }
9696
9697 $cookie = ( isset( $_COOKIE[ $table ] ) ) ? json_decode( str_replace( "\'", "'", str_replace( '\"', '"', $_COOKIE[ $table ] ) ), true ) : array();
9698 if ( ! isset( $cookie['currentPageIds'] ) ) {
9699 return false;
9700 }
9701
9702 $ids = $cookie['currentPageIds'];
9703 foreach ( $ids as $key => $id ) {
9704 if ( $id == $current ) {
9705 $prev = isset( $ids[ ( $key - 1 ) ] ) ? $ids[ ( $key - 1 ) ] : '';
9706 break;
9707 }
9708 }
9709
9710 if ( empty( $prev ) ) {
9711 $uri = '';
9712 } else {
9713 $uri = USCES_ADMIN_URL . "?page=usces_{$type}list&{$type}_action=edit&{$type}_id=" . $prev;
9714 }
9715
9716 return esc_url( $uri );
9717 }
9718
9719 public function is_reduced_taxrate() {
9720
9721 $reduced = ( isset( $this->options['applicable_taxrate'] ) && 'reduced' == $this->options['applicable_taxrate'] ) ? true : false;
9722 return $reduced;
9723 }
9724
9725 public function sc_company_name() {
9726 return htmlspecialchars( $this->options['company_name'], ENT_COMPAT );
9727 }
9728
9729 public function sc_zip_code() {
9730 return htmlspecialchars( $this->options['zip_code'], ENT_COMPAT );
9731 }
9732
9733 public function sc_address1() {
9734 return htmlspecialchars( $this->options['address1'], ENT_COMPAT );
9735 }
9736
9737 public function sc_address2() {
9738 return htmlspecialchars( $this->options['address2'], ENT_COMPAT );
9739 }
9740
9741 public function sc_tel_number() {
9742 return htmlspecialchars( $this->options['tel_number'], ENT_COMPAT );
9743 }
9744
9745 public function sc_fax_number() {
9746 return htmlspecialchars( $this->options['fax_number'], ENT_COMPAT );
9747 }
9748
9749 public function sc_inquiry_mail() {
9750 return htmlspecialchars( $this->options['inquiry_mail'], ENT_COMPAT );
9751 }
9752
9753 public function sc_payment() {
9754 $payments = usces_get_system_option( 'usces_payment_method', 'sort' );
9755 $htm = "<ul>\n";
9756 foreach ( (array) $payments as $payment ) {
9757 $htm .= '<li>' . htmlspecialchars( $payment['name'], ENT_COMPAT ) . "<br />\n";
9758 $htm .= nl2br( htmlspecialchars( $payment['explanation'], ENT_COMPAT ) ) . "</li>\n";
9759 }
9760 $htm .= "</ul>\n";
9761 return $htm;
9762 }
9763
9764 public function sc_payment_title() {
9765 $payments = $this->options['payment_method'];
9766 $htm = "<ul>\n";
9767 foreach ( (array) $payments as $payment ) {
9768 $htm .= '<li>' . esc_html( $payment['name'] ) . "</li>\n";
9769 }
9770 $htm .= "</ul>\n";
9771 return $htm;
9772 }
9773
9774 public function sc_cod_fee() {
9775 return number_format( $this->options['cod_fee'] );
9776 }
9777
9778 public function sc_start_point() {
9779 return number_format( $this->options['start_point'] );
9780 }
9781
9782 public function sc_postage_privilege() {
9783 if ( empty( $this->options['postage_privilege'] ) ) {
9784 return;
9785 }
9786 return number_format( $this->options['postage_privilege'] );
9787 }
9788
9789 public function sc_shipping_charge() {
9790 $entry = $this->cart->get_entry();
9791 $country = ( isset( $entry['delivery']['country'] ) && ! empty( $entry['delivery']['country'] ) ) ? $entry['delivery']['country'] : $entry['customer']['country'];
9792 $arr = array();
9793 foreach ( (array) $this->options['shipping_charge'] as $charges ) {
9794 foreach ( (array) $charges[ $country ] as $value ) {
9795 $arr[] = $value;
9796 }
9797 }
9798 sort( $arr );
9799 $min = $arr[0];
9800 rsort( $arr );
9801 $max = $arr[0];
9802 if ( $min == $max ) {
9803 $res = number_format( $min );
9804 } else {
9805 $res = number_format( $min ) . __( ' - ', 'usces' ) . number_format( $max );
9806 }
9807 return $res;
9808 }
9809
9810 public function sc_site_url() {
9811 return get_option( 'home' );
9812 }
9813
9814 public function sc_button_to_cart( $atts ) {
9815 extract(
9816 shortcode_atts(
9817 array(
9818 'item' => '',
9819 'sku' => '',
9820 'value' => __( 'to the cart', 'usces' ),
9821 'force' => 0,
9822 'quant' => 0,
9823 'opt' => 1,
9824 ),
9825 $atts
9826 )
9827 );
9828
9829 $post_id = $this->get_ID_byItemName( $item );
9830 $datas = $this->get_skus( $post_id, 'code' );
9831 $zaikonum = ( isset( $datas[ $sku ]['stocknum'] ) ) ? $datas[ $sku ]['stocknum'] : null;
9832 $zaiko = ( isset( $datas[ $sku ]['stock'] ) ) ? $datas[ $sku ]['stock'] : 2;
9833 $gptekiyo = ( isset( $datas[ $sku ]['gp'] ) ) ? $datas[ $sku ]['gp'] : null;
9834 $skuPrice = ( isset( $datas[ $sku ]['price'] ) ) ? $datas[ $sku ]['price'] : 0;
9835 $sku_enc = urlencode( $sku );
9836 $options = usces_get_opts( $post_id, 'sort' );
9837 $mats = compact( 'item', 'sku', 'value', 'force', 'quant', 'post_id', 'datas', 'zaikonum', 'zaiko', 'gptekiyo', 'skuPrice', 'sku_enc' );
9838 if ( ! $this->is_item_zaiko( $post_id, $sku ) ) {
9839 return '<div class="button_status">' . esc_html( $this->zaiko_status[ $zaiko ] ) . '</div>';
9840 }
9841
9842 $html = "<form action=\"" . USCES_CART_URL . "\" method=\"post\">\n";
9843 $html .= "<input name=\"zaikonum[{$post_id}][{$sku_enc}]\" type=\"hidden\" id=\"zaikonum[{$post_id}][{$sku_enc}]\" value=\"" . esc_attr( $zaikonum ) . "\" />\n";
9844 $html .= "<input name=\"zaiko[{$post_id}][{$sku_enc}]\" type=\"hidden\" id=\"zaiko[{$post_id}][{$sku_enc}]\" value=\"" . esc_attr( $zaiko ) . "\" />\n";
9845 $html .= "<input name=\"gptekiyo[{$post_id}][{$sku_enc}]\" type=\"hidden\" id=\"gptekiyo[{$post_id}][{$sku_enc}]\" value=\"" . esc_attr( $gptekiyo ) . "\" />\n";
9846 $html .= "<input name=\"skuPrice[{$post_id}][{$sku_enc}]\" type=\"hidden\" id=\"skuPrice[{$post_id}][{$sku_enc}]\" value=\"" . esc_attr( $skuPrice ) . "\" />\n";
9847 if ( 1 == $opt ) {
9848 $html .= usces_item_option_fileds( $post_id, $sku, 1, 'return' );
9849 } elseif ( 2 == $opt ) {
9850 $html .= usces_item_option_fileds( $post_id, $sku, 0, 'return' );
9851 }
9852 if ( $quant ) {
9853 $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;}\" />";
9854 $html .= apply_filters( 'usces_filter_sc_itemQuant', $quant_field, $mats );
9855 }
9856 $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 ) . ' />';
9857 $html .= "<input name=\"usces_referer\" type=\"hidden\" value=\"" . esc_url( $_SERVER['REQUEST_URI'] ) . "\" />\n";
9858 if ( $force ) {
9859 $html .= "<input name=\"usces_force\" type=\"hidden\" value=\"incart\" />\n";
9860 }
9861 $html = apply_filters( 'usces_filter_single_item_inform', $html );
9862 $html .= '</form>';
9863 $html .= '<div class="error_message">' . usces_singleitem_error_message( $post_id, $sku, 'return' ) . '</div>' . "\n";
9864
9865 return $html;
9866 }
9867
9868 public function filter_itemPage( $content ) {
9869 global $post;
9870 $html = '';
9871
9872 if ( ( 'item' != $post->post_mime_type || ! is_single() ) ) {
9873 return $content;
9874 }
9875 if ( post_password_required( $post ) ) {
9876 return $content;
9877 }
9878
9879 $temp_path = apply_filters( 'usces_template_path_single_item', USCES_PLUGIN_DIR . '/templates/single_item.php' );
9880 include $temp_path;
9881
9882 $content = apply_filters( 'usces_filter_itemPage', $html, $post->ID );
9883
9884 return $content;
9885 }
9886
9887 public function filter_cartContent( $content ) {
9888 global $post;
9889 $html = '';
9890 switch ( $this->page ) {
9891 case 'cart':
9892 $temp_path = apply_filters( 'usces_template_path_cart', USCES_PLUGIN_DIR . '/templates/cart/cart.php' );
9893 include $temp_path;
9894 break;
9895 case 'customer':
9896 $temp_path = apply_filters( 'usces_template_path_customer', USCES_PLUGIN_DIR . '/templates/cart/customer_info.php' );
9897 include $temp_path;
9898 break;
9899 case 'delivery':
9900 $temp_path = apply_filters( 'usces_template_path_delivery', USCES_PLUGIN_DIR . '/templates/cart/delivery_info.php' );
9901 include $temp_path;
9902 break;
9903 case 'confirm':
9904 $temp_path = apply_filters( 'usces_template_path_confirm', USCES_PLUGIN_DIR . '/templates/cart/confirm.php' );
9905 include $temp_path;
9906 break;
9907 case 'ordercompletion':
9908 $temp_path = apply_filters( 'usces_template_path_ordercompletion', USCES_PLUGIN_DIR . '/templates/cart/completion.php' );
9909 include $temp_path;
9910 break;
9911 case 'cartverifying':
9912 $temp_path = apply_filters( 'usces_template_path_cartverifying', USCES_PLUGIN_DIR . '/templates/cart/verifying.php' );
9913 include $temp_path;
9914 break;
9915 case 'cartverified':
9916 $temp_path = apply_filters( 'usces_template_path_cartverified', USCES_PLUGIN_DIR . '/templates/cart/verified.php' );
9917 include $temp_path;
9918 break;
9919 case 'error':
9920 $temp_path = apply_filters( 'usces_template_path_carterror', USCES_PLUGIN_DIR . '/templates/cart/error.php' );
9921 include $temp_path;
9922 break;
9923 case 'maintenance':
9924 $temp_path = apply_filters( 'usces_template_path_maintenance', USCES_PLUGIN_DIR . '/templates/cart/maintenance.php' );
9925 include $temp_path;
9926 break;
9927 case 'search_item':
9928 $temp_path = apply_filters( 'usces_template_path_search_item', USCES_PLUGIN_DIR . '/templates/search_item.php' );
9929 include $temp_path;
9930 break;
9931 case 'wp_search':
9932 if ( 'item' == $post->post_mime_type ) {
9933 $temp_path = apply_filters( 'usces_template_path_wp_search', USCES_PLUGIN_DIR . '/templates/wp_search_item.php' );
9934 include $temp_path;
9935 } else {
9936 $html = $content;
9937 }
9938 break;
9939 default:
9940 $html = $content;
9941 }
9942
9943 if ( $this->use_ssl && ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) ) {
9944 $html = str_replace( 'src="' . site_url(), 'src="' . USCES_SSL_URL_ADMIN, $html );
9945 }
9946
9947 $html = apply_filters( 'usces_filter_cartContent', $html );
9948
9949 $content = $html;
9950
9951 remove_filter( 'the_title', array( $this, 'filter_cartTitle' ) );
9952
9953 return $content;
9954 }
9955
9956 public function filter_cartTitle( $title ) {
9957 if ( is_admin() ) {
9958 return $title;
9959 }
9960
9961 if ( 'Cart' == $title || __( 'Cart', 'usces' ) == $title ) {
9962 switch ( $this->page ) {
9963 case 'cart':
9964 $newtitle = apply_filters( 'usces_filter_title_cart', __( 'In the cart', 'usces' ) );
9965 break;
9966 case 'customer':
9967 $newtitle = apply_filters( 'usces_filter_title_customer', __( 'Customer Information', 'usces' ) );
9968 break;
9969 case 'delivery':
9970 $newtitle = apply_filters( 'usces_filter_title_delivery', __( 'Shipping / Payment options', 'usces' ) );
9971 break;
9972 case 'confirm':
9973 $newtitle = apply_filters( 'usces_filter_title_confirm', __( 'Confirmation', 'usces' ) );
9974 break;
9975 case 'ordercompletion':
9976 $newtitle = apply_filters( 'usces_filter_title_ordercompletion', __( 'Completion', 'usces' ) );
9977 break;
9978 case 'error':
9979 $newtitle = apply_filters( 'usces_filter_title_carterror', __( 'Error', 'usces' ) );
9980 break;
9981 case 'cartverified':
9982 $newtitle = apply_filters( 'usces_filter_title_cartverified', __( 'Member registration complete', 'usces' ) );
9983 break;
9984 case 'search_item':
9985 $newtitle = apply_filters( 'usces_filter_title_search_item', __( "'AND' search by categories", 'usces' ) );
9986 break;
9987 case 'maintenance':
9988 $newtitle = apply_filters( 'usces_filter_title_maintenance', __( 'Under Maintenance', 'usces' ) );
9989 break;
9990 case 'login':
9991 $newtitle = apply_filters( 'usces_filter_title_login', __( 'Log-in for members', 'usces' ) );
9992 break;
9993 default:
9994 $newtitle = apply_filters( 'usces_filter_title_cart_default', $title );
9995 }
9996 } else {
9997 $newtitle = $title;
9998 }
9999
10000 $newtitle = apply_filters( 'usces_filter_cartTitle', $newtitle );
10001 return $newtitle;
10002 }
10003
10004 public function action_cartFilter() {
10005 add_filter( 'the_title', array( $this, 'filter_cartTitle' ), 20 );
10006 add_filter( 'the_content', array( $this, 'filter_cartContent' ), 20 );
10007 }
10008
10009 public function action_search_item() {
10010 include get_template_directory() . '/page.php';
10011 exit;
10012 }
10013
10014 public function filter_memberContent( $content ) {
10015 global $post;
10016 $html = '';
10017
10018 if ( 'activate' == $this->options['membersystem_state'] ) {
10019
10020 if ( $this->is_member_logged_in() ) {
10021
10022 $member_regmode = 'editmemberform';
10023 $temp_path = apply_filters( 'usces_template_path_member', USCES_PLUGIN_DIR . '/templates/member/member.php' );
10024 include $temp_path;
10025
10026 } else {
10027
10028 switch ( $this->page ) {
10029 case 'login':
10030 $temp_path = apply_filters( 'usces_template_path_login', USCES_PLUGIN_DIR . '/templates/member/login.php' );
10031 include $temp_path;
10032 break;
10033 case 'lostmemberpassword':
10034 $temp_path = apply_filters( 'usces_template_path_lostpassword', USCES_PLUGIN_DIR . '/templates/member/lostpassword.php' );
10035 include $temp_path;
10036 break;
10037 case 'changepassword':
10038 $temp_path = apply_filters( 'usces_template_path_changepassword', USCES_PLUGIN_DIR . '/templates/member/changepassword.php' );
10039 include $temp_path;
10040 break;
10041 case 'newcompletion':
10042 case 'editcompletion':
10043 case 'lostcompletion':
10044 case 'changepasscompletion':
10045 $temp_path = apply_filters( 'usces_template_path_membercompletion', USCES_PLUGIN_DIR . '/templates/member/completion.php' );
10046 include $temp_path;
10047 break;
10048 case 'memberverifying':
10049 $temp_path = apply_filters( 'usces_template_path_memberverifying', USCES_PLUGIN_DIR . '/templates/member/verifying.php' );
10050 include $temp_path;
10051 break;
10052 // case 'memberverified':
10053 // $temp_path = apply_filters('usces_template_path_memberverified', USCES_PLUGIN_DIR . '/templates/member/member_verified.php');
10054 // include $temp_path;
10055 // break;
10056 case 'newmemberform':
10057 $member_form_title = apply_filters( 'usces_filter_title_newmemberform', __( 'New enrollment form', 'usces' ) );
10058 $member_regmode = 'newmemberform';
10059 $temp_path = apply_filters( 'usces_template_path_member_form', USCES_PLUGIN_DIR . '/templates/member/member_form.php' );
10060 include $temp_path;
10061 break;
10062 default:
10063 $temp_path = apply_filters( 'usces_template_path_login', USCES_PLUGIN_DIR . '/templates/member/login.php' );
10064 include $temp_path;
10065 }
10066 }
10067 } else {
10068 $html .= '<p>' . __( 'Member Services is not running currently.', 'usces' ) . '</p>';
10069 }
10070
10071 $content = $html;
10072
10073 remove_filter( 'the_title', array( $this, 'filter_memberTitle' ), 20 );
10074
10075 return $content;
10076 }
10077
10078 public function filter_memberTitle( $title ) {
10079 if ( is_admin() ) {
10080 return $title;
10081 }
10082
10083 if ( 'activate' == $this->options['membersystem_state'] && $this->is_member_page( $_SERVER['REQUEST_URI'] ) ) {
10084 switch ( $this->page ) {
10085 case 'login':
10086 $newtitle = apply_filters( 'usces_filter_title_login', __( 'Log-in for members', 'usces' ) );
10087 break;
10088 case 'newmemberform':
10089 $newtitle = apply_filters( 'usces_filter_title_newmemberform', __( 'New enrollment form', 'usces' ) );
10090 break;
10091 case 'lostmemberpassword':
10092 $newtitle = apply_filters( 'usces_filter_title_lostmemberpassword', __( 'The new password acquisition', 'usces' ) );
10093 break;
10094 case 'changepassword':
10095 $newtitle = apply_filters( 'usces_filter_title_changepassword', __( 'Change password', 'usces' ) );
10096 break;
10097 case 'newcompletion':
10098 case 'editcompletion':
10099 case 'lostcompletion':
10100 case 'changepasscompletion':
10101 $newtitle = apply_filters( 'usces_filter_title_changepasscompletion', __( 'Completion', 'usces' ) );
10102 break;
10103 case 'memberverifying':
10104 $newtitle = apply_filters( 'usces_filter_title_memberverifying', __( 'Verifying', 'usces' ) );
10105 break;
10106 case 'error':
10107 $newtitle = apply_filters( 'usces_filter_title_membererror', __( 'Error', 'usces' ) );
10108 break;
10109 default:
10110 $newtitle = apply_filters( 'usces_filter_title_member_default', $title );
10111 }
10112 } else {
10113 $newtitle = $title;
10114 }
10115
10116 $newtitle = apply_filters( 'usces_filter_memberTitle', $newtitle );
10117 return $newtitle;
10118 }
10119
10120 public function action_memberFilter() {
10121 add_filter( 'the_title', array( $this, 'filter_memberTitle' ), 20 );
10122 add_filter( 'the_content', array( $this, 'filter_memberContent' ), 20 );
10123 }
10124
10125 public function filter_usces_cart_css() {
10126 $path = get_stylesheet_directory_uri() . '/usces_cart.css';
10127 return $path;
10128 }
10129
10130 public function filter_divide_item() {
10131 global $wp_query;
10132
10133 if ( ( $this->options['divide_item'] && ! is_category() && ! is_search() && ! is_singular() && ! is_admin() ) ) {
10134 $ids = $this->getItemIds( 'front' );
10135 if ( isset( $wp_query->query_vars['post__not_in'] ) ) {
10136 $wp_query->query_vars['post__not_in'] = $ids;
10137 }
10138 }
10139 if ( is_admin() ) {
10140 $ids = $this->getItemIds( 'back' );
10141 if ( isset( $wp_query->query_vars['post__not_in'] ) ) {
10142 $wp_query->query_vars['post__not_in'] = $ids;
10143 }
10144 }
10145 do_action( 'usces_action_divide_item' );
10146 }
10147
10148 public function load_upload_template() {
10149 $post_id = $_POST['post_id'];
10150 $file = 'upload_template01.php';
10151 include get_template_directory() . '/' . $file;
10152 exit;
10153 }
10154
10155 public function filter_itemimg_anchor_rel( $html ) {
10156 if ( is_single() ) {
10157 $str = ' rel="' . $this->options['itemimg_anchor_rel'] . '"';
10158 } else {
10159 $str = '';
10160 }
10161 return $html . $str;
10162 }
10163
10164 public function filter_permalink( $link ) {
10165 if ( false !== strpos( '?page_id=4', $link ) || false !== strpos( '?page_id=3', $link ) || false !== strpos( 'usces-cart', $link ) || false !== strpos( 'usces-member', $link ) ) {
10166 $link = str_replace( 'http://', 'https://', $link );
10167 }
10168 return $link;
10169 }
10170
10171 public function filter_cart_page_header( $html ) {
10172 if ( ! empty( $this->options['cart_page_data']['header']['cart'] ) ) {
10173 $html = $this->options['cart_page_data']['header']['cart'];
10174 }
10175 return do_shortcode( stripslashes( nl2br( $html ) ) );
10176 }
10177
10178 public function filter_cart_page_footer( $html ) {
10179 if ( ! empty( $this->options['cart_page_data']['footer']['cart'] ) ) {
10180 $html = $this->options['cart_page_data']['footer']['cart'];
10181 }
10182 return do_shortcode( stripslashes( nl2br( $html ) ) );
10183 }
10184
10185 public function filter_customer_page_header( $html ) {
10186 if ( ! empty( $this->options['cart_page_data']['header']['customer'] ) ) {
10187 $html = $this->options['cart_page_data']['header']['customer'];
10188 }
10189 return do_shortcode( stripslashes( nl2br( $html ) ) );
10190 }
10191
10192 public function filter_customer_page_footer( $html ) {
10193 if ( ! empty( $this->options['cart_page_data']['footer']['customer'] ) ) {
10194 $html = $this->options['cart_page_data']['footer']['customer'];
10195 }
10196 return do_shortcode( stripslashes( nl2br( $html ) ) );
10197 }
10198
10199 public function filter_delivery_page_header( $html ) {
10200 if ( ! empty( $this->options['cart_page_data']['header']['delivery'] ) ) {
10201 $html = $this->options['cart_page_data']['header']['delivery'];
10202 }
10203 return do_shortcode( stripslashes( nl2br( $html ) ) );
10204 }
10205
10206 public function filter_delivery_page_footer( $html ) {
10207 if ( ! empty( $this->options['cart_page_data']['footer']['delivery'] ) ) {
10208 $html = $this->options['cart_page_data']['footer']['delivery'];
10209 }
10210 return do_shortcode( stripslashes( nl2br( $html ) ) );
10211 }
10212
10213 public function filter_confirm_page_header( $html ) {
10214 if ( ! empty( $this->options['cart_page_data']['header']['confirm'] ) ) {
10215 $html = $this->options['cart_page_data']['header']['confirm'];
10216 }
10217 return do_shortcode( stripslashes( nl2br( $html ) ) );
10218 }
10219
10220 public function filter_confirm_page_footer( $html ) {
10221 if ( ! empty( $this->options['cart_page_data']['footer']['confirm'] ) ) {
10222 $html = $this->options['cart_page_data']['footer']['confirm'];
10223 }
10224 return do_shortcode( stripslashes( nl2br( $html ) ) );
10225 }
10226
10227 public function filter_cartcompletion_page_header( $html ) {
10228 if ( ! empty( $this->options['cart_page_data']['header']['completion'] ) ) {
10229 $html = $this->options['cart_page_data']['header']['completion'];
10230 }
10231 return do_shortcode( stripslashes( nl2br( $html ) ) );
10232 }
10233
10234 public function filter_cartcompletion_page_footer( $html ) {
10235 if ( ! empty( $this->options['cart_page_data']['footer']['completion'] ) ) {
10236 $html = $this->options['cart_page_data']['footer']['completion'];
10237 }
10238 return do_shortcode( stripslashes( nl2br( $html ) ) );
10239 }
10240
10241 public function filter_login_page_header( $html ) {
10242 if ( ! empty( $this->options['member_page_data']['header']['login'] ) ) {
10243 $html = $this->options['member_page_data']['header']['login'];
10244 }
10245 return do_shortcode( stripslashes( nl2br( $html ) ) );
10246 }
10247
10248 public function filter_login_page_footer( $html ) {
10249 if ( ! empty( $this->options['member_page_data']['footer']['login'] ) ) {
10250 $html = $this->options['member_page_data']['footer']['login'];
10251 }
10252 return do_shortcode( stripslashes( nl2br( $html ) ) );
10253 }
10254
10255 public function filter_newmember_page_header( $html ) {
10256 if ( ! empty( $this->options['member_page_data']['header']['newmember'] ) ) {
10257 $html = $this->options['member_page_data']['header']['newmember'];
10258 }
10259 return do_shortcode( stripslashes( nl2br( $html ) ) );
10260 }
10261
10262 public function filter_newmember_page_footer( $html ) {
10263 if ( ! empty( $this->options['member_page_data']['footer']['newmember'] ) ) {
10264 $html = $this->options['member_page_data']['footer']['newmember'];
10265 }
10266 return do_shortcode( stripslashes( nl2br( $html ) ) );
10267 }
10268
10269 public function filter_newpass_page_header( $html ) {
10270 if ( ! empty( $this->options['member_page_data']['header']['newpass'] ) ) {
10271 $html = $this->options['member_page_data']['header']['newpass'];
10272 }
10273 return do_shortcode( stripslashes( nl2br( $html ) ) );
10274 }
10275
10276 public function filter_newpass_page_footer( $html ) {
10277 if ( ! empty( $this->options['member_page_data']['footer']['newpass'] ) ) {
10278 $html = $this->options['member_page_data']['footer']['newpass'];
10279 }
10280 return do_shortcode( stripslashes( nl2br( $html ) ) );
10281 }
10282
10283 public function filter_changepass_page_header( $html ) {
10284 if ( ! empty( $this->options['member_page_data']['header']['changepass'] ) ) {
10285 $html = $this->options['member_page_data']['header']['changepass'];
10286 }
10287 return do_shortcode( stripslashes( nl2br( $html ) ) );
10288 }
10289
10290 public function filter_changepass_page_footer( $html ) {
10291 if ( ! empty( $this->options['member_page_data']['footer']['changepass'] ) ) {
10292 $html = $this->options['member_page_data']['footer']['changepass'];
10293 }
10294 return do_shortcode( stripslashes( nl2br( $html ) ) );
10295 }
10296
10297 public function filter_memberinfo_page_header( $html ) {
10298 if ( ! empty( $this->options['member_page_data']['header']['memberinfo'] ) ) {
10299 $html = $this->options['member_page_data']['header']['memberinfo'];
10300 }
10301 return do_shortcode( stripslashes( nl2br( $html ) ) );
10302 }
10303
10304 public function filter_memberinfo_page_footer( $html ) {
10305 if ( ! empty( $this->options['member_page_data']['footer']['memberinfo'] ) ) {
10306 $html = $this->options['member_page_data']['footer']['memberinfo'];
10307 }
10308 return do_shortcode( stripslashes( nl2br( $html ) ) );
10309 }
10310
10311 public function filter_membercompletion_page_header( $html ) {
10312 if ( ! empty( $this->options['member_page_data']['header']['completion'] ) ) {
10313 $html = $this->options['member_page_data']['header']['completion'];
10314 }
10315 return do_shortcode( stripslashes( nl2br( $html ) ) );
10316 }
10317
10318 public function filter_membercompletion_page_footer( $html ) {
10319 if ( ! empty( $this->options['member_page_data']['footer']['completion'] ) ) {
10320 $html = $this->options['member_page_data']['footer']['completion'];
10321 }
10322 return do_shortcode( stripslashes( nl2br( $html ) ) );
10323 }
10324
10325 public function action_cart_page_header() {
10326 if ( ! empty( $this->options['cart_page_data']['header']['cart'] ) ) {
10327 $html = $this->options['cart_page_data']['header']['cart'];
10328 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10329 }
10330 }
10331
10332 public function action_cart_page_footer() {
10333 if ( ! empty( $this->options['cart_page_data']['footer']['cart'] ) ) {
10334 $html = $this->options['cart_page_data']['footer']['cart'];
10335 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10336 }
10337 }
10338
10339 public function action_customer_page_header() {
10340 if ( ! empty( $this->options['cart_page_data']['header']['customer'] ) ) {
10341 $html = $this->options['cart_page_data']['header']['customer'];
10342 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10343 }
10344 }
10345
10346 public function action_customer_page_footer() {
10347 if ( ! empty( $this->options['cart_page_data']['footer']['customer'] ) ) {
10348 $html = $this->options['cart_page_data']['footer']['customer'];
10349 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10350 }
10351 }
10352
10353 public function action_delivery_page_header() {
10354 if ( ! empty( $this->options['cart_page_data']['header']['delivery'] ) ) {
10355 $html = $this->options['cart_page_data']['header']['delivery'];
10356 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10357 }
10358 }
10359
10360 public function action_delivery_page_footer() {
10361 if ( ! empty( $this->options['cart_page_data']['footer']['delivery'] ) ) {
10362 $html = $this->options['cart_page_data']['footer']['delivery'];
10363 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10364 }
10365 }
10366
10367 public function action_confirm_page_header() {
10368 if ( ! empty( $this->options['cart_page_data']['header']['confirm'] ) ) {
10369 $html = $this->options['cart_page_data']['header']['confirm'];
10370 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10371 }
10372 }
10373
10374 public function action_confirm_page_footer() {
10375 if ( ! empty( $this->options['cart_page_data']['footer']['confirm'] ) ) {
10376 $html = $this->options['cart_page_data']['footer']['confirm'];
10377 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10378 }
10379 }
10380
10381 public function action_cartcompletion_page_header() {
10382 if ( ! empty( $this->options['cart_page_data']['header']['completion'] ) ) {
10383 $html = $this->options['cart_page_data']['header']['completion'];
10384 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10385 }
10386 }
10387
10388 public function action_cartcompletion_page_footer() {
10389 if ( ! empty( $this->options['cart_page_data']['footer']['completion'] ) ) {
10390 $html = $this->options['cart_page_data']['footer']['completion'];
10391 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10392 }
10393 }
10394
10395 public function action_login_page_header() {
10396 if ( ! empty( $this->options['member_page_data']['header']['login'] ) ) {
10397 $html = $this->options['member_page_data']['header']['login'];
10398 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10399 }
10400 }
10401
10402 public function action_login_page_footer() {
10403 if ( ! empty( $this->options['member_page_data']['footer']['login'] ) ) {
10404 $html = $this->options['member_page_data']['footer']['login'];
10405 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10406 }
10407 }
10408
10409 public function action_newmember_page_header() {
10410 if ( ! empty( $this->options['member_page_data']['header']['newmember'] ) ) {
10411 $html = $this->options['member_page_data']['header']['newmember'];
10412 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10413 }
10414 }
10415
10416 public function action_newmember_page_footer() {
10417 if ( ! empty( $this->options['member_page_data']['footer']['newmember'] ) ) {
10418 $html = $this->options['member_page_data']['footer']['newmember'];
10419 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10420 }
10421 }
10422
10423 public function action_newpass_page_header() {
10424 if ( ! empty( $this->options['member_page_data']['header']['newpass'] ) ) {
10425 $html = $this->options['member_page_data']['header']['newpass'];
10426 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10427 }
10428 }
10429
10430 public function action_newpass_page_footer() {
10431 if ( ! empty( $this->options['member_page_data']['footer']['newpass'] ) ) {
10432 $html = $this->options['member_page_data']['footer']['newpass'];
10433 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10434 }
10435 }
10436
10437 public function action_changepass_page_header() {
10438 if ( ! empty( $this->options['member_page_data']['header']['changepass'] ) ) {
10439 $html = $this->options['member_page_data']['header']['changepass'];
10440 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10441 }
10442 }
10443
10444 public function action_changepass_page_footer() {
10445 if ( ! empty( $this->options['member_page_data']['footer']['changepass'] ) ) {
10446 $html = $this->options['member_page_data']['footer']['changepass'];
10447 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10448 }
10449 }
10450
10451 public function action_memberinfo_page_header() {
10452 if ( ! empty( $this->options['member_page_data']['header']['memberinfo'] ) ) {
10453 $html = $this->options['member_page_data']['header']['memberinfo'];
10454 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10455 }
10456 }
10457
10458 public function action_memberinfo_page_footer() {
10459 if ( ! empty( $this->options['member_page_data']['footer']['memberinfo'] ) ) {
10460 $html = $this->options['member_page_data']['footer']['memberinfo'];
10461 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10462 }
10463 }
10464
10465 public function action_membercompletion_page_header() {
10466 if ( ! empty( $this->options['member_page_data']['header']['completion'] ) ) {
10467 $html = $this->options['member_page_data']['header']['completion'];
10468 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10469 }
10470 }
10471
10472 public function action_membercompletion_page_footer() {
10473 if ( ! empty( $this->options['member_page_data']['footer']['completion'] ) ) {
10474 $html = $this->options['member_page_data']['footer']['completion'];
10475 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10476 }
10477 }
10478
10479 public function filter_confirm_page_notes( $html ) {
10480 if ( ! empty( $this->options['cart_page_data']['confirm_notes'] ) ) {
10481 $html = '<div class="wc_confirm_notes_area">' . $this->options['cart_page_data']['confirm_notes'] . '</div>';
10482 }
10483 return stripslashes( nl2br( $html ) );
10484 }
10485
10486 public function action_confirm_page_notes() {
10487 if ( ! empty( $this->options['cart_page_data']['confirm_notes'] ) ) {
10488 $html = '<div class="wc_confirm_notes_area">' . $this->options['cart_page_data']['confirm_notes'] . '</div>';
10489 echo stripslashes( nl2br( $html ) );
10490 }
10491 }
10492
10493 /**
10494 * Get member cookies.
10495 *
10496 * @param string $key string cookies key.
10497 *
10498 * @return string
10499 */
10500 public function usces_get_member_cookies( $key ) {
10501 $result = '';
10502 switch ( $key ) {
10503 case 'ord_ex_cancel':
10504 $ex_cancel = filter_input( INPUT_GET, 'ord_ex_cancel' );
10505 if ( $ex_cancel ) {
10506 $result = ( 'on' === $ex_cancel ) ? 'on' : 'off';
10507 } else {
10508 $cookie = $this->get_cookie( 'usces_front' );
10509 $result = isset( $cookie['ord_ex_cancel'] ) ? $cookie['ord_ex_cancel'] : 'on';
10510 $result = apply_filters( 'usces_filter_ord_ex_cancel_init', $result );
10511 }
10512 break;
10513 case 'pur-date':
10514 $result = filter_input( INPUT_GET, 'pur-date' );
10515 if ( null === $result ) {
10516 $cookie = $this->get_cookie( 'usces_front' );
10517 $result = isset( $cookie['usces_purdate'] ) ? $cookie['usces_purdate'] : 'd_30';
10518 $result = apply_filters( 'usces_filter_ord_purdate_init', $result );
10519 }
10520 break;
10521 }
10522 return $result;
10523 }
10524
10525 }
10526