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

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

10,506 lines 409.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Welcart Main Class
4 *
5 * @package Welcart
6 */
7 class usc_e_shop {
8
9 /**
10 * Page action.
11 *
12 * @var string
13 */
14 public $page;
15
16 /**
17 * Cart object.
18 *
19 * @var array
20 */
21 public $cart;
22
23 /**
24 * SSL flag.
25 *
26 * @var int
27 */
28 public $use_ssl;
29
30 public $action;
31 public $action_status;
32 public $error_status;
33 public $action_message;
34 public $error_message;
35 public $itemskus;
36 public $itemsku;
37 public $current_itemsku;
38 public $itemopts;
39 public $itemopt;
40 public $current_itemopt;
41 public $item;
42 public $zaiko_status;
43 public $payment_structure;
44 public $display_mode;
45 public $shipping_rule;
46 public $nonacting_settlements;
47 public $member_status;
48 public $options;
49 public $mail_para;
50 public $login_mail;
51 public $current_member;
52 public $member_form;
53 public $payment_results;
54 public $log_flg;
55 public $delim;
56 public $use_js;
57 public $user_level;
58 public $previous_url;
59
60 /**
61 * PayPal object.
62 *
63 * @var object
64 */
65 public $paypal;
66
67 /**
68 * Settlement object.
69 *
70 * @var array
71 */
72 public $settlement;
73
74 /**
75 * Settlement notice.
76 *
77 * @var string
78 */
79 public $settlement_notice;
80
81 /**
82 * Cart object for Multiple Shipping.
83 *
84 * @var array
85 */
86 public $msacart;
87
88 /**
89 * Constructor.
90 */
91 public function __construct() {
92 global $wpdb, $post, $usces_settings, $usces_states;
93
94 usces_add_role();
95 usces_add_capabilites();
96
97 do_action( 'usces_construct' );
98
99 add_action( 'init', array( $this, 'init' ), 1 );
100
101 $locales = usces_locales();
102 foreach ( $locales as $l ) {
103 $usces_settings['language'][ $l ] = $l;
104 }
105
106 $this->options = get_option( 'usces', array() );
107 if ( ! isset( $this->options['smtp_hostname'] ) || empty( $this->options['smtp_hostname'] ) ) {
108 $this->options['smtp_hostname'] = 'localhost';
109 }
110 if ( ! isset( $this->options['delivery_method'] ) || ! is_array( $this->options['delivery_method'] ) ) {
111 $this->options['delivery_method'] = array();
112 }
113 if ( ! isset( $this->options['shipping_charge'] ) || ! is_array( $this->options['shipping_charge'] ) ) {
114 $this->options['shipping_charge'] = array();
115 }
116 if ( ! isset( $this->options['membersystem_state'] ) ) {
117 $this->options['membersystem_state'] = 'activate';
118 }
119 if ( ! isset( $this->options['membersystem_point'] ) ) {
120 $this->options['membersystem_point'] = 'activate';
121 }
122 if ( ! isset( $this->options['use_ssl'] ) ) {
123 $this->options['use_ssl'] = 0;
124 }
125 if ( ! isset( $this->options['point_coverage'] ) ) {
126 $this->options['point_coverage'] = 0;
127 }
128 if ( ! isset( $this->options['use_javascript'] ) ) {
129 $this->options['use_javascript'] = 1;
130 }
131 if ( ! isset( $this->options['privilege_discount'] ) ) {
132 $this->options['privilege_discount'] = '';
133 }
134 if ( ! isset( $this->options['privilege_point'] ) ) {
135 $this->options['privilege_point'] = '';
136 }
137 if ( ! isset( $this->options['campaign_privilege'] ) ) {
138 $this->options['campaign_privilege'] = '';
139 }
140 if ( ! isset( $this->options['campaign_category'] ) ) {
141 $this->options['campaign_category'] = 0;
142 }
143 if ( ! isset( $this->options['campaign_schedule']['start'] ) ) {
144 $this->options['campaign_schedule']['start'] = array();
145 }
146 if ( ! isset( $this->options['campaign_schedule']['end'] ) ) {
147 $this->options['campaign_schedule']['end'] = array();
148 }
149 if ( ! isset( $this->options['purchase_limit'] ) ) {
150 $this->options['purchase_limit'] = '';
151 }
152 if ( ! isset( $this->options['point_rate'] ) ) {
153 $this->options['point_rate'] = '';
154 }
155 if ( ! isset( $this->options['shipping_rule'] ) ) {
156 $this->options['shipping_rule'] = '';
157 }
158 if ( ! isset( $this->options['company_name'] ) ) {
159 $this->options['company_name'] = '';
160 }
161 if ( ! isset( $this->options['address1'] ) ) {
162 $this->options['address1'] = '';
163 }
164 if ( ! isset( $this->options['address2'] ) ) {
165 $this->options['address2'] = '';
166 }
167 if ( ! isset( $this->options['zip_code'] ) ) {
168 $this->options['zip_code'] = '';
169 }
170 if ( ! isset( $this->options['tel_number'] ) ) {
171 $this->options['tel_number'] = '';
172 }
173 if ( ! isset( $this->options['fax_number'] ) ) {
174 $this->options['fax_number'] = '';
175 }
176 if ( ! isset( $this->options['order_mail'] ) ) {
177 $this->options['order_mail'] = '';
178 }
179 if ( ! isset( $this->options['inquiry_mail'] ) ) {
180 $this->options['inquiry_mail'] = '';
181 }
182 if ( ! isset( $this->options['sender_mail'] ) ) {
183 $this->options['sender_mail'] = '';
184 }
185 if ( ! isset( $this->options['error_mail'] ) ) {
186 $this->options['error_mail'] = '';
187 }
188 if ( ! isset( $this->options['copyright'] ) ) {
189 $this->options['copyright'] = '';
190 }
191 if ( ! isset( $this->options['business_registration_number'] ) ) {
192 $this->options['business_registration_number'] = '';
193 }
194 if ( ! isset( $this->options['postage_privilege'] ) ) {
195 $this->options['postage_privilege'] = '';
196 }
197 if ( ! isset( $this->options['shipping_rule'] ) ) {
198 $this->options['shipping_rule'] = '';
199 }
200 if ( ! isset( $this->options['tax_display'] ) ) {
201 $this->options['tax_display'] = 'activate';
202 }
203 if ( ! isset( $this->options['applicable_taxrate'] ) || empty( $this->options['applicable_taxrate'] ) ) {
204 $this->options['applicable_taxrate'] = 'standard';
205 }
206 if ( ! isset( $this->options['tax_rate'] ) ) {
207 $this->options['tax_rate'] = '';
208 $this->options['tax_method'] = 'cutting';
209 $this->options['tax_mode'] = 'include';
210 $this->options['tax_target'] = 'products';
211 } else {
212 if ( ! isset( $this->options['tax_mode'] ) ) {
213 $this->options['tax_mode'] = empty( $this->options['tax_rate'] ) ? 'include' : 'exclude';
214 }
215 if ( ! isset( $this->options['tax_target'] ) ) {
216 $this->options['tax_target'] = 'all';
217 }
218 }
219 if ( ! isset( $this->options['tax_rate_reduced'] ) ) {
220 $this->options['tax_rate_reduced'] = '';
221 }
222 if ( ! isset( $this->options['transferee'] ) ) {
223 $this->options['transferee'] = '';
224 }
225 if ( ! isset( $this->options['tatransfer_limit'] ) ) {
226 $this->options['tatransfer_limit'] = '';
227 }
228 if ( ! isset( $this->options['membersystem_state'] ) ) {
229 $this->options['membersystem_state'] = 'activate';
230 }
231 if ( ! isset( $this->options['membersystem_point'] ) ) {
232 $this->options['membersystem_point'] = '';
233 }
234 if ( ! isset( $this->options['point_rate'] ) ) {
235 $this->options['point_rate'] = '';
236 }
237 if ( ! isset( $this->options['start_point'] ) ) {
238 $this->options['start_point'] = '';
239 }
240 if ( ! isset( $this->options['point_coverage'] ) ) {
241 $this->options['point_coverage'] = 1;
242 }
243 if ( ! isset( $this->options['point_assign'] ) ) {
244 $this->options['point_assign'] = 1;
245 }
246 if ( ! isset( $this->options['cod_type'] ) ) {
247 $this->options['cod_type'] = 'fix';
248 }
249 if ( ! isset( $this->options['fee_subject'] ) ) {
250 $this->options['fee_subject'] = 'all';
251 }
252 if ( ! isset( $this->options['address_search'] ) ) {
253 $this->options['address_search'] = 'deactivate';
254 }
255 if ( ! isset( $this->options['newmem_admin_mail'] ) ) {
256 $this->options['newmem_admin_mail'] = 0;
257 }
258 if ( ! isset( $this->options['updmem_admin_mail'] ) ) {
259 $this->options['updmem_admin_mail'] = 0;
260 }
261 if ( ! isset( $this->options['updmem_customer_mail'] ) ) {
262 $this->options['updmem_customer_mail'] = 0;
263 }
264 if ( ! isset( $this->options['delmem_admin_mail'] ) ) {
265 $this->options['delmem_admin_mail'] = 1;
266 }
267 if ( ! isset( $this->options['delmem_customer_mail'] ) ) {
268 $this->options['delmem_customer_mail'] = 1;
269 }
270 if ( ! isset( $this->options['put_customer_name'] ) ) {
271 $this->options['put_customer_name'] = '0';
272 }
273 if ( ! isset( $this->options['email_attach_feature'] ) ) {
274 $this->options['email_attach_feature'] = '0';
275 }
276 if ( ! isset( $this->options['email_attach_file_extension'] ) ) {
277 $this->options['email_attach_file_extension'] = 'jpg,png,pdf';
278 }
279 if ( ! isset( $this->options['email_attach_file_size'] ) ) {
280 $this->options['email_attach_file_size'] = 3;
281 }
282 if ( ! isset( $this->options['add_html_email_option'] ) ) {
283 $this->options['add_html_email_option'] = 0;
284 }
285 if ( ! isset( $this->options['mail_data']['title'] ) ) {
286 $this->options['mail_data']['title'] = array(
287 'thankyou' => '',
288 'order' => '',
289 'inquiry' => '',
290 'returninq' => '',
291 'membercomp' => '',
292 'completionmail' => '',
293 'ordermail' => '',
294 'changemail' => '',
295 'receiptmail' => '',
296 'mitumorimail' => '',
297 'cancelmail' => '',
298 'othermail' => '',
299 );
300 }
301 if ( ! isset( $this->options['mail_data']['header'] ) ) {
302 $this->options['mail_data']['header'] = array(
303 'thankyou' => '',
304 'order' => '',
305 'inquiry' => '',
306 'returninq' => '',
307 'membercomp' => '',
308 'completionmail' => '',
309 'ordermail' => '',
310 'changemail' => '',
311 'receiptmail' => '',
312 'mitumorimail' => '',
313 'cancelmail' => '',
314 'othermail' => '',
315 );
316 }
317 if ( ! isset( $this->options['mail_data']['footer'] ) ) {
318 $this->options['mail_data']['footer'] = array(
319 'thankyou' => '',
320 'order' => '',
321 'inquiry' => '',
322 'returninq' => '',
323 'membercomp' => '',
324 'completionmail' => '',
325 'ordermail' => '',
326 'changemail' => '',
327 'receiptmail' => '',
328 'mitumorimail' => '',
329 'cancelmail' => '',
330 'othermail' => '',
331 );
332 }
333 if ( ! isset( $this->options['cart_page_data']['header'] ) ) {
334 $this->options['cart_page_data']['header'] = array(
335 'cart' => '',
336 'customer' => '',
337 'delivery' => '',
338 'confirm' => '',
339 'completion' => '',
340 );
341 }
342 if ( ! isset( $this->options['cart_page_data']['footer'] ) ) {
343 $this->options['cart_page_data']['footer'] = array(
344 'cart' => '',
345 'customer' => '',
346 'delivery' => '',
347 'confirm' => '',
348 'completion' => '',
349 );
350 }
351 if ( ! isset( $this->options['cart_page_data']['confirm_notes'] ) ) {
352 $this->options['cart_page_data']['confirm_notes'] = '';
353 }
354 if ( ! isset( $this->options['member_page_data']['header'] ) ) {
355 $this->options['member_page_data']['header'] = array(
356 'login' => '',
357 'newmember' => '',
358 'newpass' => '',
359 'changepass' => '',
360 'memberinfo' => '',
361 'completion' => '',
362 );
363 }
364 if ( ! isset( $this->options['member_page_data']['footer'] ) ) {
365 $this->options['member_page_data']['footer'] = array(
366 'login' => '',
367 'newmember' => '',
368 'newpass' => '',
369 'changepass' => '',
370 'memberinfo' => '',
371 'completion' => '',
372 );
373 }
374 if ( ! isset( $this->options['member_page_data']['agree_member_exp'] ) ) {
375 $this->options['member_page_data']['agree_member_exp'] = '';
376 }
377 if ( ! isset( $this->options['member_page_data']['agree_member_cont'] ) ) {
378 $this->options['member_page_data']['agree_member_cont'] = '';
379 }
380 if ( ! isset( $this->options['agree_member'] ) ) {
381 $this->options['agree_member'] = '';
382 }
383 if ( ! isset( $this->options['shortest_delivery_time'] ) ) {
384 $this->options['shortest_delivery_time'] = '0';
385 }
386 if ( ! isset( $this->options['delivery_after_days'] ) ) {
387 $this->options['delivery_after_days'] = 15;
388 }
389 if ( ! isset( $this->options['delivery_days'] ) ) {
390 $this->options['delivery_days'] = array();
391 }
392 if ( ! isset( $this->options['delivery_time_limit']['hour'] ) ) {
393 $this->options['delivery_time_limit']['hour'] = '00';
394 }
395 if ( ! isset( $this->options['delivery_time_limit']['min'] ) ) {
396 $this->options['delivery_time_limit']['min'] = '00';
397 }
398
399 if ( ! isset( $this->options['divide_item'] ) ) {
400 $this->options['divide_item'] = 0;
401 }
402 if ( ! isset( $this->options['itemimg_anchor_rel'] ) ) {
403 $this->options['itemimg_anchor_rel'] = '';
404 }
405 if ( ! isset( $this->options['fukugo_category_orderby'] ) ) {
406 $this->options['fukugo_category_orderby'] = 'ID';
407 }
408 if ( ! isset( $this->options['fukugo_category_order'] ) ) {
409 $this->options['fukugo_category_order'] = 'ASC';
410 }
411 if ( ! isset( $this->options['settlement_path'] ) ) {
412 $this->options['settlement_path'] = USCES_PLUGIN_DIR . 'settlement/';
413 }
414 if ( ! isset( $this->options['logs_path'] ) ) {
415 $this->options['logs_path'] = '';
416 }
417 if ( ! isset( $this->options['use_ssl'] ) ) {
418 $this->options['use_ssl'] = 0;
419 }
420 if ( ! isset( $this->options['ssl_url'] ) ) {
421 $this->options['ssl_url'] = '';
422 }
423 if ( ! isset( $this->options['ssl_url_admin'] ) ) {
424 $this->options['ssl_url_admin'] = '';
425 }
426 if ( ! isset( $this->options['inquiry_id'] ) ) {
427 $this->options['inquiry_id'] = '';
428 }
429 if ( ! isset( $this->options['system']['orderby_itemsku'] ) ) {
430 $this->options['system']['orderby_itemsku'] = 0;
431 }
432 if ( ! isset( $this->options['system']['orderby_itemopt'] ) ) {
433 $this->options['system']['orderby_itemopt'] = 0;
434 }
435 if ( ! isset( $this->options['system']['front_lang'] ) ) {
436 $this->options['system']['front_lang'] = usces_get_local_language();
437 }
438 if ( ! isset( $this->options['system']['currency'] ) ) {
439 $this->options['system']['currency'] = usces_get_base_country();
440 }
441 if ( ! isset( $this->options['system']['addressform'] ) ) {
442 $this->options['system']['addressform'] = usces_get_local_addressform();
443 }
444 if ( ! isset( $this->options['system']['target_market'] ) ) {
445 $this->options['system']['target_market'] = usces_get_local_target_market();
446 }
447 if ( ! isset( $this->options['system']['no_cart_css'] ) ) {
448 $this->options['system']['no_cart_css'] = 0;
449 }
450 if ( ! isset( $this->options['system']['dec_orderID_flag'] ) ) {
451 $this->options['system']['dec_orderID_flag'] = 0;
452 }
453 if ( ! isset( $this->options['system']['dec_orderID_prefix'] ) ) {
454 $this->options['system']['dec_orderID_prefix'] = '';
455 }
456 if ( ! isset( $this->options['system']['dec_orderID_digit'] ) ) {
457 $this->options['system']['dec_orderID_digit'] = 8;
458 }
459 if ( ! isset( $this->options['system']['subimage_rule'] ) ) {
460 $this->options['system']['subimage_rule'] = 1;
461 }
462 if ( ! isset( $this->options['system']['pdf_delivery'] ) ) {
463 $this->options['system']['pdf_delivery'] = 0;
464 }
465 if ( ! isset( $this->options['system']['member_pass_rule_min'] ) || empty( $this->options['system']['member_pass_rule_min'] ) ) {
466 $this->options['system']['member_pass_rule_min'] = 6;
467 }
468 if ( ! isset( $this->options['system']['member_pass_rule_max'] ) || empty( $this->options['system']['member_pass_rule_max'] ) ) {
469 $this->options['system']['member_pass_rule_max'] = 30;
470 }
471 if ( ! isset( $this->options['system']['member_pass_rule_upercase'] ) || empty( $this->options['system']['member_pass_rule_upercase'] ) ) {
472 $this->options['system']['member_pass_rule_upercase'] = false;
473 }
474 if ( ! isset( $this->options['system']['csv_encode_type'] ) ) {
475 $this->options['system']['csv_encode_type'] = 0;
476 }
477 if ( ! isset( $this->options['system']['csv_category_format'] ) ) {
478 $this->options['system']['csv_category_format'] = 0;
479 }
480 if ( ! isset( $this->options['system']['settlement_backup'] ) ) {
481 $this->options['system']['settlement_backup'] = 0;
482 }
483 if ( ! isset( $this->options['system']['settlement_notice'] ) ) {
484 $this->options['system']['settlement_notice'] = 0;
485 }
486 if ( ! isset( $this->options['system']['order_list_delete_link'] ) ) {
487 $this->options['system']['order_list_delete_link'] = 0;
488 }
489 if ( ! isset( $this->options['system']['member_list_delete_link'] ) ) {
490 $this->options['system']['member_list_delete_link'] = 0;
491 }
492
493 $this->options['system']['base_country'] = usces_get_base_country();
494 if ( ! isset( $this->options['province'] ) ) {
495 $this->options['province'][ $this->options['system']['base_country'] ] = $usces_states[ $this->options['system']['base_country'] ];
496 }
497 if ( ! isset( $this->options['system']['pointreduction'] ) ) {
498 $this->options['system']['pointreduction'] = usces_get_pointreduction( $this->options['system']['currency'] );
499 }
500 if ( ! isset( $this->options['indi_item_name'] ) ) {
501 $this->options['indi_item_name']['item_name'] = 1;
502 $this->options['indi_item_name']['item_code'] = 1;
503 $this->options['indi_item_name']['sku_name'] = 1;
504 $this->options['indi_item_name']['sku_code'] = 1;
505 $this->options['pos_item_name']['item_name'] = 1;
506 $this->options['pos_item_name']['item_code'] = 2;
507 $this->options['pos_item_name']['sku_name'] = 3;
508 $this->options['pos_item_name']['sku_code'] = 4;
509 }
510 update_option( 'usces', $this->options );
511
512 $this->check_display_mode();
513 $this->error_message = '';
514 $this->login_mail = '';
515 // $this->get_current_member();
516 $this->page = '';
517 $this->payment_results = array();
518 $this->use_js = $this->options['use_javascript'];
519
520 // admin_ssl options.
521 $this->use_ssl = $this->options['use_ssl'];
522
523 define( 'USCES_CART_NUMBER', get_option( 'usces_cart_number' ) );
524 define( 'USCES_MEMBER_NUMBER', get_option( 'usces_member_number' ) );
525
526 if ( $this->use_ssl ) {
527 $ssl_url = $this->options['ssl_url'];
528 $ssl_url_admin = $this->options['ssl_url_admin'];
529 if ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
530 define( 'USCES_FRONT_PLUGIN_URL', $ssl_url_admin . '/wp-content/plugins/' . USCES_PLUGIN_FOLDER );
531 define( 'USCES_COOKIEPATH', preg_replace( '|https?://[^/]+|i', '', $ssl_url . '/' ) );
532 } else {
533 define( 'USCES_FRONT_PLUGIN_URL', USCES_WP_CONTENT_URL . '/plugins/' . USCES_PLUGIN_FOLDER );
534 define( 'USCES_COOKIEPATH', COOKIEPATH );
535 }
536 define( 'USCES_SSL_URL', $ssl_url );
537 define( 'USCES_SSL_URL_ADMIN', $ssl_url_admin );
538 } else {
539 define( 'USCES_FRONT_PLUGIN_URL', USCES_WP_CONTENT_URL . '/plugins/' . USCES_PLUGIN_FOLDER );
540 define( 'USCES_SSL_URL', home_url() );
541 define( 'USCES_SSL_URL_ADMIN', site_url() );
542 define( 'USCES_COOKIEPATH', COOKIEPATH );
543 }
544 define( 'USCES_ITEM_CAT_PARENT_ID', get_option( 'usces_item_cat_parent_id' ) );
545
546 $this->nonacting_settlements = array( 'COD', 'installment', 'transferAdvance', 'transferDeferred' );
547 $this->zaiko_status = get_option( 'usces_zaiko_status' );
548 $this->member_status = get_option( 'usces_customer_status' );
549 $this->payment_structure = get_option( 'usces_payment_structure' );
550 $this->display_mode = get_option( 'usces_display_mode' );
551 define( 'USCES_MYSQL_VERSION', $wpdb->db_version() );
552 define( 'USCES_JP', ( 'ja' === get_locale() ? true : false ) );
553
554 $this->settlement = new usces_settlement();
555
556 $this->settlement_notice = get_option( 'usces_settlement_notice' );
557
558 $this->usces_session_start();
559 }
560
561 /**
562 * Init.
563 */
564 public function init() {
565 global $usces_settings;
566
567 if ( ! isset( $usces_settings['language']['others'] ) ) {
568 $usces_settings['language']['others'] = __( 'Follow config.php', 'usces' );
569 }
570 if ( ! isset( $this->options['order_acceptable_label'] ) ) {
571 $this->options['order_acceptable_label'] = __( 'Order acceptable', 'usces' );
572 update_option( 'usces', $this->options );
573 }
574 $this->get_current_member();
575 }
576
577 public function get_default_post_to_edit30( $post_type = 'post', $create_in_db = false ) {
578 global $wpdb;
579
580 $post_title = '';
581 if ( ! empty( $_REQUEST['post_title'] ) ) {
582 $post_title = esc_html( stripslashes( $_REQUEST['post_title'] ) );
583 }
584 $post_content = '';
585 if ( ! empty( $_REQUEST['content'] ) ) {
586 $post_content = esc_html( stripslashes( $_REQUEST['content'] ) );
587 }
588 $post_excerpt = '';
589 if ( ! empty( $_REQUEST['excerpt'] ) ) {
590 $post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ) );
591 }
592 if ( $create_in_db ) {
593 // Cleanup old auto-drafts more than 7 days old.
594 $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" );
595 foreach ( (array) $old_posts as $delete ) {
596 wp_delete_post( $delete, true ); // Force delete.
597 }
598 $post = get_post(
599 wp_insert_post(
600 array(
601 'post_title' => __( 'Auto Draft' ),
602 'post_type' => $post_type,
603 'post_status' => 'auto-draft',
604 )
605 )
606 );
607 } else {
608 $post->ID = 0;
609 $post->post_author = '';
610 $post->post_date = '';
611 $post->post_date_gmt = '';
612 $post->post_password = '';
613 $post->post_type = $post_type;
614 $post->post_status = 'draft';
615 $post->to_ping = '';
616 $post->pinged = '';
617 $post->comment_status = get_option( 'default_comment_status' );
618 $post->ping_status = get_option( 'default_ping_status' );
619 $post->post_pingback = get_option( 'default_pingback_flag' );
620 $post->post_category = get_option( 'default_category' );
621 $post->page_template = 'default';
622 $post->post_parent = 0;
623 $post->menu_order = 0;
624 }
625
626 $post->post_content = apply_filters( 'default_content', $post_content, $post );
627 $post->post_title = apply_filters( 'default_title', $post_title, $post );
628 $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt, $post );
629 $post->post_name = '';
630
631 return $post;
632 }
633
634 public function get_default_post_to_edit() {
635 global $post;
636
637 $post_title = '';
638 if ( ! empty( $_REQUEST['post_title'] ) ) {
639 $post_title = esc_html( stripslashes( $_REQUEST['post_title'] ) );
640 }
641 $post_content = '';
642 if ( ! empty( $_REQUEST['content'] ) ) {
643 $post_content = esc_html( stripslashes( $_REQUEST['content'] ) );
644 }
645 $post_excerpt = '';
646 if ( ! empty( $_REQUEST['excerpt'] ) ) {
647 $post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ) );
648 }
649 $post->ID = 0;
650 $post->post_name = '';
651 $post->post_author = '';
652 $post->post_date = '';
653 $post->post_date_gmt = '';
654 $post->post_password = '';
655 $post->post_status = 'draft';
656 $post->post_type = 'post';
657 $post->to_ping = '';
658 $post->pinged = '';
659 $post->comment_status = get_option( 'default_comment_status' );
660 $post->ping_status = get_option( 'default_ping_status' );
661 $post->post_pingback = get_option( 'default_pingback_flag' );
662 $post->post_category = get_option( 'default_category' );
663 $post->post_content = apply_filters( 'default_content', $post_content );
664 $post->post_title = apply_filters( 'default_title', $post_title );
665 $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt );
666 $post->page_template = 'default';
667 $post->post_parent = 0;
668 $post->menu_order = 0;
669
670 return $post;
671 }
672
673 public function is_cart_or_member_page( $link ) {
674 $search = array(
675 ( 'page_id=' . USCES_CART_NUMBER ),
676 '/usces-cart',
677 ( 'page_id=' . USCES_MEMBER_NUMBER ),
678 '/usces-member',
679 );
680 $flag = false;
681 foreach ( $search as $value ) {
682 $parts = array();
683 if ( false !== strpos( $link, $value ) ) {
684 if ( $value == ( 'page_id=' . USCES_CART_NUMBER ) || $value == ( 'page_id=' . USCES_MEMBER_NUMBER ) ) {
685 $parts = parse_url( $link );
686 parse_str( $parts['query'], $query );
687 if ( isset( $query['page_id'] ) && ( $query['page_id'] == USCES_CART_NUMBER || $query['page_id'] == USCES_MEMBER_NUMBER ) ) {
688 $flag = true;
689 }
690 } else {
691 $flag = true;
692 }
693 }
694 }
695 return $flag;
696 }
697
698 public function is_cart_page( $link ) {
699 $search = array(
700 ( 'page_id=' . USCES_CART_NUMBER ),
701 '/usces-cart',
702 );
703 $flag = false;
704 foreach ( $search as $value ) {
705 if ( false !== strpos( $link, $value ) ) {
706 if ( $value == ( 'page_id=' . USCES_CART_NUMBER ) ) {
707 $parts = parse_url( $link );
708 parse_str( $parts['query'], $query );
709 if ( isset( $query['page_id'] ) && $query['page_id'] == USCES_CART_NUMBER ) {
710 $flag = true;
711 }
712 } else {
713 $flag = true;
714 }
715 }
716 }
717 return $flag;
718 }
719
720 public function is_member_page( $link ) {
721 $search = array(
722 ( 'page_id=' . USCES_MEMBER_NUMBER ),
723 '/usces-member',
724 );
725 $flag = false;
726 foreach ( $search as $value ) {
727 if ( false !== strpos( $link, $value ) ) {
728 if ( $value == ( 'page_id=' . USCES_MEMBER_NUMBER ) ) {
729 $parts = parse_url( $link );
730 parse_str( $parts['query'], $query );
731 if ( $query['page_id'] == USCES_MEMBER_NUMBER ) {
732 $flag = true;
733 }
734 } else {
735 $flag = true;
736 }
737 }
738 }
739 return $flag;
740 }
741
742 public function is_inquiry_page( $link ) {
743 if ( empty( $this->options['inquiry_id'] ) ) {
744 return false;
745 }
746 $search = array(
747 ( 'page_id=' . $this->options['inquiry_id'] ),
748 '/usces-inquiry',
749 );
750 $flag = false;
751 foreach ( $search as $value ) {
752 if ( false !== strpos( $link, $value ) ) {
753 if ( $value == ( 'page_id=' . $this->options['inquiry_id'] ) ) {
754 $parts = parse_url( $link );
755 parse_str( $parts['query'], $query );
756 if ( $query['page_id'] == $this->options['inquiry_id'] ) {
757 $flag = true;
758 }
759 } else {
760 $flag = true;
761 }
762 }
763 }
764 return $flag;
765 }
766
767 public function usces_ssl_page_link( $link ) {
768 $parts = parse_url( $link );
769
770 if ( isset( $parts['query'] ) ) {
771 parse_str( $parts['query'], $query );
772 }
773
774 if ( false !== strpos( $link, '/usces-cart' ) || ( isset( $query['page_id'] ) && $query['page_id'] == USCES_CART_NUMBER ) ) {
775 $link = USCES_CART_URL;
776
777 } elseif ( false !== strpos( $link, '/usces-member' ) || ( isset( $query['page_id'] ) && $query['page_id'] == USCES_MEMBER_NUMBER ) ) {
778 $link = USCES_MEMBER_URL;
779
780 } elseif ( ! empty( $this->options['inquiry_id'] ) && ( false !== strpos( $link, '/usces-inquiry' ) || ( isset( $query['page_id'] ) && $query['page_id'] == $this->options['inquiry_id'] ) ) ) {
781 $link = USCES_INQUIRY_URL;
782
783 } else {
784 $link = str_replace( 'https://', 'http://', $link );
785 $link = apply_filters( 'usces_ssl_page_link', $link );
786 }
787
788 return $link;
789 }
790
791 public function usces_ssl_contents_link( $link ) {
792 if ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
793 $req = explode( '/wp-content/', $link );
794 $link = USCES_SSL_URL_ADMIN . '/wp-content/' . $req[1];
795 } else {
796 $link = apply_filters( 'usces_ssl_contents_link', $link );
797 }
798 return $link;
799 }
800
801 public function ssl_admin_ajax_url() {
802 $path = '/wp-admin/admin-ajax.php';
803 if ( $this->use_ssl && ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) ) {
804 $link = USCES_SSL_URL_ADMIN . '/wp-admin/admin-ajax.php';
805 } else {
806 $link = site_url( $path );
807 }
808 $link = apply_filters( 'ssl_admin_ajax_url', $link );
809 return $link;
810 }
811
812 public function usces_ssl_attachment_link( $link ) {
813 if ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
814 $link = str_replace( site_url(), USCES_SSL_URL_ADMIN, $link );
815 } else {
816 $link = apply_filters( 'usces_ssl_attachment_link', $link );
817 }
818 return $link;
819 }
820
821 public function usces_ssl_icon_dir_uri( $uri ) {
822 if ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
823 $uri = USCES_SSL_URL_ADMIN . '/' . WPINC . '/images/crystal';
824 } else {
825 $uri = apply_filters( 'usces_ssl_icon_dir_uri', $uri );
826 }
827 return $uri;
828 }
829
830 public function usces_ssl_script_link( $link ) {
831 if ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
832 if ( strpos( $link, '/wp-content/' ) !== false ) {
833 $req = explode( '/wp-content/', $link, 2 );
834 $link = USCES_SSL_URL_ADMIN . '/wp-content/' . $req[1];
835 } elseif ( strpos( $link, '/wp-includes/' ) !== false ) {
836 $req = explode( '/wp-includes/', $link, 2 );
837 $link = USCES_SSL_URL_ADMIN . '/wp-includes/' . $req[1];
838 } elseif ( strpos( $link, '/wp-admin/') !== false ) {
839 $req = explode( '/wp-admin/', $link, 2 );
840 $link = USCES_SSL_URL_ADMIN . '/wp-admin/' . $req[1];
841 }
842 } else {
843 $link = apply_filters( 'usces_ssl_script_link', $link );
844 }
845 return $link;
846 }
847
848 public function set_action_status( $status, $message ) {
849 $this->action_status = $status;
850 $this->action_message = $message;
851 }
852
853 public function add_pages() {
854 add_menu_page( 'Welcart Shop', 'Welcart Shop', 'wel_publish_products', USCES_PLUGIN_BASENAME, array( $this, 'admin_top_page' ), 'dashicons-cart', '3.0011060' );
855 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'Home', 'usces' ), __( 'Home', 'usces' ), 'wel_publish_products', USCES_PLUGIN_BASENAME, array( $this, 'admin_top_page' ) );
856 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'Master Items', 'usces' ), __( 'Master Items', 'usces' ), 'wel_publish_products', 'usces_itemedit', array( $this, 'item_master_page' ) );
857 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'Add New Item', 'usces' ), __( 'Add New Item', 'usces' ), 'wel_publish_products', 'usces_itemnew', array( $this, 'item_master_page' ) );
858 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'General Setting', 'usces' ), __( 'General Setting', 'usces' ), 'wel_manage_setting', 'usces_initial', array( $this, 'admin_setup_page' ) );
859 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'Business Days Setting', 'usces' ), __( 'Business Days Setting', 'usces' ), 'wel_manage_setting', 'usces_schedule', array( $this, 'admin_schedule_page' ) );
860 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'Shipping Setting', 'usces' ), __( 'Shipping Setting', 'usces' ), 'wel_manage_setting', 'usces_delivery', array( $this, 'admin_delivery_page' ) );
861 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'E-mail Setting', 'usces' ), __( 'E-mail Setting', 'usces' ), 'wel_manage_setting', 'usces_mail', array( $this, 'admin_mail_page' ) );
862 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'Cart Page Setting', 'usces' ), __( 'Cart Page Setting', 'usces' ), 'wel_manage_setting', 'usces_cart', array( $this, 'admin_cart_page' ) );
863 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'Member Page Setting', 'usces' ), __( 'Member Page Setting', 'usces' ), 'wel_manage_setting', 'usces_member', array( $this, 'admin_member_page' ) );
864 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'System Setting', 'usces' ), __( 'System Setting', 'usces' ), 'wel_manage_setting', 'usces_system', array( $this, 'admin_system_page' ) );
865 add_submenu_page( USCES_PLUGIN_BASENAME, __( 'Settlement Setting', 'usces' ), __( 'Settlement Setting', 'usces' ), 'wel_manage_setting', 'usces_settlement', array( $this, 'admin_settlement_page' ) );
866 do_action( 'usces_action_shop_admin_menue' );
867
868 add_menu_page( 'Welcart Management', 'Welcart Management', 'wel_manage_order', 'usces_orderlist', array( $this, 'order_list_page' ), 'dashicons-cart', '3.0011070' );
869 add_submenu_page( 'usces_orderlist', __( 'Order List', 'usces' ), __( 'Order List', 'usces' ), 'wel_manage_order', 'usces_orderlist', array( $this, 'order_list_page' ) );
870 add_submenu_page( 'usces_orderlist', __( 'New Order or Estimate', 'usces' ), __( 'New Order or Estimate', 'usces' ), 'wel_manage_order', 'usces_ordernew', array( $this, 'order_list_page' ) );
871 add_submenu_page( 'usces_orderlist', __( 'List of Members', 'usces' ), __( 'List of Members', 'usces' ), 'wel_manage_order', 'usces_memberlist', array( $this, 'member_list_page' ) );
872 add_submenu_page( 'usces_orderlist', __( 'New Membership Registration', 'usces' ), __( 'New Membership Registration', 'usces' ), 'wel_manage_order', 'usces_membernew', array( $this, 'member_list_page' ) );
873 Log_List_Table::add_submenu_page();
874 do_action( 'usces_action_management_admin_menue' );
875 }
876
877 /**
878 * Item Master Page.
879 */
880 public function item_master_page() {
881 global $wpdb, $wp_locale;
882 global $wp_query;
883
884 if ( empty( $this->action_message ) || WCUtils::is_blank( $this->action_message ) ) {
885 $this->action_status = 'none';
886 $this->action_message = '';
887 }
888
889 if ( 'usces_itemnew' == $_REQUEST['page'] ) {
890 $action = 'new';
891 } else {
892 $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
893 }
894 do_action( 'usces_action_item_master_page', $action );
895 switch ( $action ) {
896 case 'dlitemlist':
897 usces_download_item_list();
898 break;
899 case 'upload_register':
900 require_once USCES_PLUGIN_DIR . '/includes/usces_item_master_upload_register.php';
901 break;
902 case 'delete':
903 case 'new':
904 case 'editpost':
905 case 'edit':
906 global $current_user;
907 require_once USCES_PLUGIN_DIR . '/includes/usces_item_master_edit.php';
908 break;
909 default:
910 require_once USCES_PLUGIN_DIR . '/includes/usces_item_master_list.php';
911 break;
912 }
913 }
914
915 /**
916 * Order list page.
917 */
918 public function order_list_page() {
919 $order_edit_form = apply_filters( 'usces_admin_order_edit_form', USCES_PLUGIN_DIR . '/includes/order_edit_form.php' );
920 $order_list = apply_filters( 'usces_admin_order_list', USCES_PLUGIN_DIR . '/includes/order_list.php' );
921
922 if ( empty( $this->action_message ) || WCUtils::is_blank( $this->action_message ) ) {
923 $this->action_status = 'none';
924 $this->action_message = '';
925 }
926 if ( 'usces_ordernew' == $_REQUEST['page'] ) {
927 $order_action = 'new';
928 } else {
929 $order_action = isset( $_REQUEST['order_action'] ) ? $_REQUEST['order_action'] : '';
930 }
931 do_action( 'usces_action_order_list_page', $order_action );
932 Log_List_Table::add_order_meta_box( $order_action );
933 switch ( $order_action ) {
934 case 'dlproductlist':
935 check_admin_referer( 'order_list', 'wc_nonce' );
936 usces_download_product_list();
937 break;
938 case 'dlorderlist':
939 check_admin_referer( 'order_list', 'wc_nonce' );
940 usces_download_order_list();
941 break;
942 case 'dlsettlementerrorlog':
943 check_admin_referer( 'order_list', 'wc_nonce' );
944 usces_download_settlement_error_log();
945 break;
946 case 'editpost':
947 check_admin_referer( 'order_edit', 'wc_nonce' );
948 $logger = Logger::start( $_REQUEST['order_id'], 'orderedit', 'update' );
949 do_action( 'usces_pre_update_orderdata', $_REQUEST['order_id'] );
950 $res = usces_update_orderdata();
951 if ( 1 === $res ) {
952 $backtolist = ( empty( $_POST['usces_referer'] ) || false !== strpos( $_POST['usces_referer'], 'order_action=editpost' ) ) ? admin_url( 'admin.php?page=usces_orderlist&returnList=1&wc_nonce=' . wp_create_nonce( 'order_list' ) ) : esc_url( stripslashes( $_POST['usces_referer'] ) );
953 $this->set_action_status( 'success', __( 'order date is updated', 'usces' ) . ' <a href="' . $backtolist . '">' . __( 'back to the summary', 'usces' ) . '</a>' );
954 } elseif ( 0 === $res ) {
955 $this->set_action_status( 'none', '' );
956 } else {
957 $this->set_action_status( 'error', 'ERROR : ' . __( 'failure in update', 'usces' ) );
958 }
959 $logger->flush();
960 do_action( 'usces_after_update_orderdata', $_REQUEST['order_id'], $res );
961 require_once $order_edit_form;
962 break;
963 case 'newpost':
964 check_admin_referer( 'order_edit', 'wc_nonce' );
965 do_action( 'usces_pre_new_orderdata' );
966 $res = usces_new_orderdata();
967 if ( 1 === $res ) {
968 $this->set_action_status( 'success', __( 'New date is add', 'usces' ) );
969 Logger::start( $_REQUEST['order_id'], 'ordernew', 'create' )->flush();
970 } elseif ( 0 === $res ) {
971 $this->set_action_status( 'none', '' );
972 } else {
973 $this->set_action_status( 'error', 'ERROR : ' . __( 'failure in addition', 'usces' ) );
974 }
975 do_action( 'usces_after_new_orderdata', $res );
976 $_REQUEST['order_action'] = 'edit';
977 $order_action = $_REQUEST['order_action'];
978 require_once $order_edit_form;
979 break;
980 case 'new':
981 case 'edit':
982 require_once $order_edit_form;
983 break;
984 case 'load_rich_editor':
985 wp_enqueue_style( 'colors' );
986 require_once USCES_PLUGIN_DIR . '/includes/order_detail_rich_editor.php';
987 break;
988 case 'delete':
989 check_admin_referer( 'order_list', 'wc_nonce' );
990 do_action( 'usces_pre_delete_orderdata', $_REQUEST['order_id'] );
991 $logger = Logger::start( $_REQUEST['order_id'], 'orderlist', 'delete' );
992 $res = usces_delete_orderdata();
993 if ( 1 === $res ) {
994 $this->set_action_status( 'success', __( 'the order date is deleted', 'usces' ) );
995 $logger->flush();
996 } elseif ( 0 === $res ) {
997 $this->set_action_status( 'none', '' );
998 } else {
999 $this->set_action_status( 'error', 'ERROR : ' . __( 'failure in delete', 'usces' ) );
1000 }
1001 do_action( 'usces_after_delete_orderdata', $_REQUEST['order_id'], $res );
1002 default:
1003 require_once $order_list;
1004 }
1005 }
1006
1007 /**
1008 * Member list page.
1009 */
1010 public function member_list_page() {
1011 $member_edit_form = apply_filters( 'usces_admin_member_edit_form', USCES_PLUGIN_DIR . '/includes/member_edit_form.php' );
1012 $member_list = apply_filters( 'usces_admin_member_list', USCES_PLUGIN_DIR . '/includes/member_list.php' );
1013 if ( empty( $this->action_message ) || WCUtils::is_blank( $this->action_message ) ) {
1014 $this->action_status = 'none';
1015 $this->action_message = '';
1016 }
1017 if ( 'usces_membernew' == $_REQUEST['page'] ) {
1018 $member_action = isset( $_REQUEST['member_action'] ) ? $_REQUEST['member_action'] : 'new';
1019 } else {
1020 $member_action = isset( $_REQUEST['member_action'] ) ? $_REQUEST['member_action'] : '';
1021 }
1022 do_action( 'usces_action_member_list_page', $member_action );
1023 Log_List_Table::add_member_meta_box( $member_action );
1024 switch ( $member_action ) {
1025 case 'dlmemberlist':
1026 check_admin_referer( 'post_member', 'wc_nonce' );
1027 usces_download_member_list();
1028 break;
1029 case 'editpost':
1030 check_admin_referer( 'post_member', 'wc_nonce' );
1031 $logger = Logger::start( $_REQUEST['member_id'], 'memberedit', 'update' );
1032 $this->error_message = $this->admin_member_check();
1033 if ( WCUtils::is_blank( $this->error_message ) ) {
1034 $res = usces_update_memberdata();
1035 if ( 1 === $res ) {
1036 $this->set_action_status( 'success', __( 'Membership information is updated', 'usces' ) );
1037 $logger->flush();
1038 } elseif ( 0 === $res ) {
1039 $this->set_action_status( 'none', '' );
1040 } else {
1041 $this->set_action_status( 'error', 'ERROR : ' . __( 'failure in update', 'usces' ) );
1042 }
1043 } else {
1044 $this->set_action_status( 'error', 'ERROR : ' . $this->error_message );
1045 }
1046 require_once $member_edit_form;
1047 break;
1048 case 'newpost':
1049 check_admin_referer( 'post_member', 'wc_nonce' );
1050 $this->error_message = $this->admin_new_member_check();
1051 if ( WCUtils::is_blank( $this->error_message ) ) {
1052 $res = usces_new_memberdata();
1053 if ( 1 === $res ) {
1054 $this->set_action_status( 'success', __( 'New member registration is complete.', 'usces' ) );
1055 $_REQUEST['member_action'] = 'edit';
1056 $member_action = $_REQUEST['member_action'];
1057 Logger::start( $_REQUEST['member_id'], 'membernew', 'create' )->flush();
1058 } elseif ( 0 === $res ) {
1059 $this->set_action_status( 'none', '' );
1060 } else {
1061 $this->set_action_status( 'error', 'ERROR : ' . __( 'Failed to new member registration.', 'usces' ) );
1062 }
1063 } else {
1064 $this->set_action_status( 'error', $this->error_message );
1065 $member_action = 'new';
1066 }
1067 require_once $member_edit_form;
1068 break;
1069 case 'new':
1070 require_once $member_edit_form;
1071 break;
1072 case 'edit':
1073 check_admin_referer( 'member_list', 'wc_nonce' );
1074 require_once $member_edit_form;
1075 break;
1076 case 'delete':
1077 check_admin_referer( 'delete_member', 'wc_nonce' );
1078 if ( ! isset( $_REQUEST['member_id'] ) || WCUtils::is_blank( $_REQUEST['member_id'] ) ) {
1079 $this->set_action_status( 'error', 'ERROR : ' . __( 'failure in delete', 'usces' ) );
1080 } else {
1081 $logger = Logger::start( $_REQUEST['member_id'], 'memberlist', 'delete' );
1082 $member_id = $_REQUEST['member_id'];
1083 $del = usces_delete_member_check( $member_id );
1084 if ( $del ) {
1085 $res = usces_delete_memberdata( $member_id );
1086 if ( 1 === $res ) {
1087 $this->set_action_status( 'success', __( 'The member data is deleted', 'usces' ) );
1088 } elseif ( 0 === $res ) {
1089 $this->set_action_status( 'none', '' );
1090 } else {
1091 $this->set_action_status( 'error', 'ERROR : ' . __( 'failure in delete', 'usces' ) );
1092 }
1093 $logger->flush();
1094 } else {
1095 $this->set_action_status( 'error', 'ERROR : ' . __( 'failure in delete', 'usces' ) );
1096 }
1097 }
1098 default:
1099 require_once $member_list;
1100 }
1101 }
1102
1103 /**
1104 * Shop Top Page.
1105 */
1106 public function admin_top_page() {
1107 $action = filter_input( INPUT_GET, 'wel_action', FILTER_DEFAULT, FILTER_REQUIRE_SCALAR );
1108 if ( ! wel_need_to_update_db() ) {
1109 $action = '';
1110 }
1111 switch ( $action ) {
1112 case 'update_db':
1113 if ( ! current_user_can( 'wel_manage_setting' ) ) {
1114 wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
1115 }
1116 check_admin_referer( 'wel_update_database', '_welnonce' );
1117 require_once USCES_PLUGIN_DIR . '/includes/database/db-progress-screen.php';
1118 break;
1119 default:
1120 $path = apply_filters( 'usces_filter_admin_top_page', USCES_PLUGIN_DIR . '/includes/admin_top.php' );
1121 require_once $path;
1122 }
1123 }
1124
1125 /**
1126 * Shop Setup Page.
1127 */
1128 public function admin_setup_page() {
1129 $this->options = get_option( 'usces' );
1130 if ( isset( $_POST['usces_option_update'] ) ) {
1131
1132 check_admin_referer( 'admin_setup', 'wc_nonce' );
1133
1134 $_POST = $this->stripslashes_deep_post( $_POST );
1135
1136 $order_mail = '';
1137 if ( isset( $_POST['order_mail'] ) ) {
1138 $order_mails = array_map( 'trim', explode( ',', $_POST['order_mail'] ) );
1139 $valid_mails = array();
1140 foreach ( $order_mails as $mail ) {
1141 if ( is_email( $mail ) ) {
1142 $valid_mails[] = $mail;
1143 }
1144 }
1145 $order_mail = implode( ',', $valid_mails );
1146 } else {
1147 $order_mail = '';
1148 }
1149
1150 $this->options['display_mode'] = isset( $_POST['display_mode'] ) ? trim( $_POST['display_mode'] ) : '';
1151 $this->options['campaign_category'] = empty( $_POST['cat'] ) ? USCES_ITEM_CAT_PARENT_ID : $_POST['cat'];
1152 $this->options['campaign_privilege'] = isset( $_POST['cat_privilege'] ) ? trim( $_POST['cat_privilege'] ) : '';
1153 $this->options['privilege_point'] = isset( $_POST['point_num'] ) ? (int) $_POST['point_num'] : '';
1154 $this->options['privilege_discount'] = isset( $_POST['discount_num'] ) ? (int) $_POST['discount_num'] : '';
1155 $this->options['company_name'] = isset( $_POST['company_name'] ) ? trim( $_POST['company_name'] ) : '';
1156 $this->options['zip_code'] = isset( $_POST['zip_code'] ) ? trim( $_POST['zip_code'] ) : '';
1157 $this->options['address1'] = isset( $_POST['address1'] ) ? trim( $_POST['address1'] ) : '';
1158 $this->options['address2'] = isset( $_POST['address2'] ) ? trim( $_POST['address2'] ) : '';
1159 $this->options['tel_number'] = isset( $_POST['tel_number'] ) ? trim( $_POST['tel_number'] ) : '';
1160 $this->options['fax_number'] = isset( $_POST['fax_number'] ) ? trim( $_POST['fax_number'] ) : '';
1161 $this->options['order_mail'] = $order_mail;
1162 $this->options['inquiry_mail'] = isset( $_POST['inquiry_mail'] ) && is_email( trim( $_POST['inquiry_mail'] ) ) ? trim( $_POST['inquiry_mail'] ) : '';
1163 $this->options['sender_mail'] = isset( $_POST['sender_mail'] ) && is_email( trim( $_POST['sender_mail'] ) ) ? trim( $_POST['sender_mail'] ) : '';
1164 $this->options['error_mail'] = isset( $_POST['error_mail'] ) && is_email( trim( $_POST['error_mail'] ) ) ? trim( $_POST['error_mail'] ) : '';
1165 $this->options['postage_privilege'] = isset( $_POST['postage_privilege'] ) ? trim( $_POST['postage_privilege'] ) : '';
1166 $this->options['purchase_limit'] = isset( $_POST['purchase_limit'] ) ? trim( $_POST['purchase_limit'] ) : '';
1167 $this->options['point_rate'] = isset( $_POST['point_rate'] ) ? (int) $_POST['point_rate'] : 1;
1168 $this->options['start_point'] = isset( $_POST['start_point'] ) ? (int) $_POST['start_point'] : '';
1169 $this->options['shipping_rule'] = isset( $_POST['shipping_rule'] ) ? trim( $_POST['shipping_rule'] ) : '';
1170 $this->options['tax_display'] = isset( $_POST['tax_display'] ) ? trim( $_POST['tax_display'] ) : 'activate';
1171 $this->options['tax_mode'] = isset( $_POST['tax_mode'] ) ? trim( $_POST['tax_mode'] ) : 'include';
1172 $this->options['tax_target'] = isset( $_POST['tax_target'] ) ? trim( $_POST['tax_target'] ) : 'products';
1173 $this->options['tax_rate'] = isset( $_POST['tax_rate'] ) ? (int) $_POST['tax_rate'] : '';
1174 $this->options['tax_method'] = isset( $_POST['tax_method'] ) ? trim( $_POST['tax_method'] ) : '';
1175 $this->options['applicable_taxrate'] = ( isset( $_POST['applicable_taxrate'] ) ) ? $_POST['applicable_taxrate'] : 'standard';
1176 $this->options['tax_rate_reduced'] = ( isset( $_POST['tax_rate_reduced'] ) ) ? (int) $_POST['tax_rate_reduced'] : '';
1177 $this->options['cod_type'] = isset( $this->options['cod_type'] ) ? $this->options['cod_type'] : 'fix';
1178 $this->options['fee_subject'] = ( isset( $_POST['fee_subject'] ) ) ? trim( $_POST['fee_subject'] ) : 'all';
1179 $this->options['transferee'] = isset( $_POST['transferee'] ) ? trim( $_POST['transferee'] ) : '';
1180 $this->options['tatransfer_limit'] = isset( $_POST['tatransfer_limit'] ) ? trim( $_POST['tatransfer_limit'] ) : '';
1181 $this->options['copyright'] = isset( $_POST['copyright'] ) ? trim( $_POST['copyright'] ) : '';
1182 $this->options['business_registration_number'] = ( isset( $_POST['business_registration_number'] ) ) ? trim( $_POST['business_registration_number'] ) : '';
1183 $this->options['membersystem_state'] = isset( $_POST['membersystem_state'] ) ? trim( $_POST['membersystem_state'] ) : '';
1184 $this->options['membersystem_point'] = isset( $_POST['membersystem_point'] ) ? trim( $_POST['membersystem_point'] ) : '';
1185 $this->options['point_coverage'] = isset( $_POST['point_coverage'] ) ? (int) $_POST['point_coverage'] : 0;
1186 $this->options['point_assign'] = isset( $_POST['point_assign'] ) ? (int) $_POST['point_assign'] : 1;
1187 $this->options['address_search'] = isset( $_POST['address_search'] ) ? trim( $_POST['address_search'] ) : 'deactivate';
1188 $this->options['stock_status_label'] = ( isset( $_POST['stock_status_label'] ) ) ? $_POST['stock_status_label'] : array();
1189 $this->options['order_acceptable_label'] = ( isset( $_POST['order_acceptable_label'] ) ) ? trim( $_POST['order_acceptable_label'] ) : '';
1190
1191 $this->options = apply_filters( 'usces_filter_admin_setup_options', $this->options );
1192
1193 update_option( 'usces', $this->options );
1194
1195 $this->action_status = 'success';
1196 $this->action_message = __( 'options are updated', 'usces' );
1197
1198 } else {
1199 $this->action_status = 'none';
1200 $this->action_message = '';
1201 }
1202
1203 require_once USCES_PLUGIN_DIR . '/includes/admin_setup.php';
1204 }
1205
1206 /**
1207 * Shop Schedule Page
1208 */
1209 public function admin_schedule_page() {
1210 $this->options = get_option( 'usces' );
1211
1212 if ( isset( $_POST['usces_option_update'] ) ) {
1213
1214 check_admin_referer( 'admin_schedule', 'wc_nonce' );
1215
1216 $_POST = $this->stripslashes_deep_post( $_POST );
1217
1218 $this->options['campaign_schedule'] = isset( $_POST['campaign_schedule'] ) ? $_POST['campaign_schedule'] : '0';
1219 if ( isset( $_POST['business_days'] ) ) {
1220 $this->options['business_days'] = $_POST['business_days'];
1221 }
1222 update_option( 'usces', $this->options );
1223
1224 do_action( 'usces_action_admin_schedule_update' );
1225
1226 $this->action_status = 'success';
1227 $this->action_message = __( 'options are updated', 'usces' );
1228 } else {
1229 $this->action_status = 'none';
1230 $this->action_message = '';
1231 }
1232
1233 require_once USCES_PLUGIN_DIR . '/includes/admin_schedule.php';
1234 }
1235
1236 /**
1237 * Shop Delivery Page.
1238 */
1239 public function admin_delivery_page() {
1240 $this->options = get_option( 'usces' );
1241
1242 if ( isset( $_POST['usces_option_update'] ) ) {
1243
1244 check_admin_referer( 'admin_delivery', 'wc_nonce' );
1245
1246 $_POST = $this->stripslashes_deep_post( $_POST );
1247
1248 if ( isset( $_POST['delivery_time_limit'] ) ) {
1249 $this->options['delivery_time_limit'] = $_POST['delivery_time_limit'];
1250 }
1251 if ( isset( $_POST['shortest_delivery_time'] ) ) {
1252 $this->options['shortest_delivery_time'] = $_POST['shortest_delivery_time'];
1253 }
1254 if ( isset( $_POST['delivery_after_days'] ) ) {
1255 $this->options['delivery_after_days'] = $_POST['delivery_after_days'];
1256 }
1257 $this->options = apply_filters( 'usces_filter_admin_delivery_options', $this->options );
1258
1259 update_option( 'usces', $this->options );
1260
1261 $this->action_status = 'success';
1262 $this->action_message = __( 'options are updated', 'usces' );
1263 } else {
1264 $this->action_status = 'none';
1265 $this->action_message = '';
1266 }
1267
1268 require_once USCES_PLUGIN_DIR . '/includes/admin_delivery.php';
1269 }
1270
1271 /**
1272 * Shop Mail Page.
1273 */
1274 public function admin_mail_page() {
1275 global $allowedposttags;
1276
1277 if ( isset( $_POST['usces_option_update'] ) ) {
1278 check_admin_referer( 'admin_mail', 'wc_nonce' );
1279 $_POST = $this->stripslashes_deep_post( $_POST );
1280
1281 $mail_othermail = get_option( 'usces_mail_othermail', array() );
1282 foreach ( $_POST['title'] as $key => $value ) {
1283 $value = wel_esc_script( $value );
1284 if ( 'othermail' == $key ) {
1285 if ( WCUtils::is_blank( $value ) ) {
1286 if ( empty( $mail_othermail['title'] ) && isset( $this->options['mail_default']['title'][ $key ] ) ) {
1287 $mail_othermail['title'] = $this->options['mail_default']['title'][ $key ];
1288 $this->options['mail_data']['title'][ $key ] = $mail_othermail['title'];
1289 }
1290 } else {
1291 $mail_othermail['title'] = trim( $value );
1292 $this->options['mail_data']['title'][ $key ] = $mail_othermail['title'];
1293 }
1294 } else {
1295 if ( WCUtils::is_blank( $value ) ) {
1296 $this->options['mail_data']['title'][ $key ] = isset( $this->options['mail_default']['title'][ $key ] ) ? $this->options['mail_default']['title'][ $key ] : '';
1297 } else {
1298 $this->options['mail_data']['title'][ $key ] = trim( $value );
1299 }
1300 }
1301 }
1302 foreach ( $_POST['header'] as $key => $value ) {
1303 $value = wel_esc_script( $value );
1304 if ( 'othermail' == $key ) {
1305 if ( WCUtils::is_blank( $value ) ) {
1306 if ( empty( $mail_othermail['header'] ) && isset( $this->options['mail_default']['header'][ $key ] ) ) {
1307 $mail_othermail['header'] = $this->options['mail_default']['header'][ $key ];
1308 $this->options['mail_data']['header'][ $key ] = $mail_othermail['header'];
1309 }
1310 } else {
1311 $mail_othermail['header'] = $value;
1312 $this->options['mail_data']['header'][ $key ] = $mail_othermail['header'];
1313 }
1314 } else {
1315 if ( WCUtils::is_blank( $value ) ) {
1316 $this->options['mail_data']['header'][ $key ] = isset( $this->options['mail_default']['header'][ $key ] ) ? $this->options['mail_default']['header'][ $key ] : '';
1317 } else {
1318 $this->options['mail_data']['header'][ $key ] = $value;
1319 }
1320 }
1321 }
1322 foreach ( $_POST['footer'] as $key => $value ) {
1323 $value = wel_esc_script( $value );
1324 if ( 'othermail' == $key ) {
1325 if ( WCUtils::is_blank( $value ) ) {
1326 if ( empty( $mail_othermail['footer'] ) && isset( $this->options['mail_default']['footer'][ $key ] ) ) {
1327 $mail_othermail['footer'] = $this->options['mail_default']['footer'][ $key ];
1328 $this->options['mail_data']['footer'][ $key ] = $mail_othermail['footer'];
1329 }
1330 } else {
1331 $mail_othermail['footer'] = $value;
1332 $this->options['mail_data']['footer'][ $key ] = $mail_othermail['footer'];
1333 }
1334 } else {
1335 if ( WCUtils::is_blank( $value ) ) {
1336 $this->options['mail_data']['footer'][ $key ] = isset( $this->options['mail_default']['footer'][ $key ] ) ? $this->options['mail_default']['footer'][ $key ] : '';
1337 } else {
1338 $this->options['mail_data']['footer'][ $key ] = $value;
1339 }
1340 }
1341 }
1342 update_option( 'usces', $this->options );
1343 update_option( 'usces_mail_othermail', $mail_othermail );
1344
1345 $this->action_status = 'success';
1346 $this->action_message = __( 'options are updated', 'usces' );
1347
1348 } elseif ( isset( $_POST['usces_option_update_top'] ) ) {
1349 check_admin_referer( 'admin_mail', 'wc_nonce' );
1350 $_POST = $this->stripslashes_deep_post( $_POST );
1351
1352 $email_attach_file_extension = wel_email_attach_file_extension( explode( ',', trim( wel_esc_script( $_POST['email_attach_file_extension'] ) ) ) );
1353
1354 $this->options['smtp_hostname'] = esc_html( trim( $_POST['smtp_hostname'] ) );
1355 $this->options['newmem_admin_mail'] = (int) $_POST['newmem_admin_mail'];
1356 $this->options['updmem_admin_mail'] = (int) $_POST['updmem_admin_mail'];
1357 $this->options['updmem_customer_mail'] = (int) $_POST['updmem_customer_mail'];
1358 $this->options['delmem_admin_mail'] = (int) $_POST['delmem_admin_mail'];
1359 $this->options['delmem_customer_mail'] = (int) $_POST['delmem_customer_mail'];
1360 $this->options['put_customer_name'] = (int) $_POST['put_customer_name'];
1361 $this->options['email_attach_feature'] = (int) $_POST['email_attach_feature'];
1362 $this->options['email_attach_file_extension'] = implode( ',', $email_attach_file_extension );
1363 $this->options['email_attach_file_size'] = (int) $_POST['email_attach_file_size'];
1364 $this->options['add_html_email_option'] = (int) $_POST['add_html_email_option'];
1365 update_option( 'usces', $this->options );
1366
1367 $this->action_status = 'success';
1368 $this->action_message = __( 'options are updated', 'usces' );
1369
1370 } elseif ( isset( $_POST['usces_option_update_auto'] ) ) {
1371 check_admin_referer( 'admin_mail', 'wc_nonce' );
1372 $_POST = $this->stripslashes_deep_post( $_POST );
1373
1374 $mail_thankyou = get_option( 'usces_mail_thankyou', array() );
1375 if ( WCUtils::is_blank( $_POST['title']['thankyou'] ) ) {
1376 if ( empty( $mail_thankyou['title'] ) && isset( $this->options['mail_default']['title']['thankyou'] ) ) {
1377 $mail_thankyou['title'] = $this->options['mail_default']['title']['thankyou'];
1378 $this->options['mail_data']['title']['thankyou'] = $mail_thankyou['title'];
1379 }
1380 } else {
1381 $mail_thankyou['title'] = trim( wel_esc_script( $_POST['title']['thankyou'] ) );
1382 $this->options['mail_data']['title']['thankyou'] = $mail_thankyou['title'];
1383 }
1384 if ( WCUtils::is_blank( $_POST['header']['thankyou'] ) ) {
1385 if ( empty( $mail_thankyou['header'] ) && isset( $this->options['mail_default']['header']['thankyou'] ) ) {
1386 $mail_thankyou['header'] = $this->options['mail_default']['header']['thankyou'];
1387 $this->options['mail_data']['header']['thankyou'] = $mail_thankyou['header'];
1388 }
1389 } else {
1390 $mail_thankyou['header'] = trim( wel_esc_script( $_POST['header']['thankyou'] ) );
1391 $this->options['mail_data']['header']['thankyou'] = $mail_thankyou['header'];
1392 }
1393 if ( WCUtils::is_blank( $_POST['footer']['thankyou'] ) ) {
1394 if ( empty( $mail_thankyou['footer'] ) && isset( $this->options['mail_default']['footer']['thankyou'] ) ) {
1395 $mail_thankyou['footer'] = $this->options['mail_default']['footer']['thankyou'];
1396 $this->options['mail_data']['footer']['thankyou'] = $mail_thankyou['footer'];
1397 }
1398 } else {
1399 $mail_thankyou['footer'] = trim( wel_esc_script( $_POST['footer']['thankyou'] ) );
1400 $this->options['mail_data']['footer']['thankyou'] = $mail_thankyou['footer'];
1401 }
1402 update_option( 'usces_mail_thankyou', $mail_thankyou );
1403
1404 $mail_order = get_option( 'usces_mail_order', array() );
1405 if ( WCUtils::is_blank( $_POST['title']['order'] ) ) {
1406 if ( empty( $mail_order['title'] ) && isset( $this->options['mail_default']['title']['order'] ) ) {
1407 $mail_order['title'] = $this->options['mail_default']['title']['order'];
1408 $this->options['mail_data']['title']['order'] = $mail_order['title'];
1409 }
1410 } else {
1411 $mail_order['title'] = trim( wel_esc_script( $_POST['title']['order'] ) );
1412 $this->options['mail_data']['title']['order'] = $mail_order['title'];
1413 }
1414 if ( WCUtils::is_blank( $_POST['header']['order'] ) ) {
1415 if ( empty( $mail_order['header'] ) && isset( $this->options['mail_default']['header']['order'] ) ) {
1416 $mail_order['header'] = $this->options['mail_default']['header']['order'];
1417 $this->options['mail_data']['header']['order'] = $mail_order['header'];
1418 }
1419 } else {
1420 $mail_order['header'] = trim( wel_esc_script( $_POST['header']['order'] ) );
1421 $this->options['mail_data']['header']['order'] = $mail_order['header'];
1422 }
1423 if ( WCUtils::is_blank( $_POST['footer']['order'] ) ) {
1424 if ( empty( $mail_order['footer'] ) && isset( $this->options['mail_default']['footer']['order'] ) ) {
1425 $mail_order['footer'] = $this->options['mail_default']['footer']['order'];
1426 $this->options['mail_data']['footer']['order'] = $mail_order['footer'];
1427 }
1428 } else {
1429 $mail_order['footer'] = trim( wel_esc_script( $_POST['footer']['order'] ) );
1430 $this->options['mail_data']['footer']['order'] = $mail_order['footer'];
1431 }
1432 update_option( 'usces_mail_order', $mail_order );
1433
1434 $mail_inquiry = get_option( 'usces_mail_inquiry', array() );
1435 if ( WCUtils::is_blank( $_POST['title']['inquiry'] ) ) {
1436 if ( empty( $mail_inquiry['title'] ) && isset( $this->options['mail_default']['title']['inquiry'] ) ) {
1437 $mail_inquiry['title'] = $this->options['mail_default']['title']['inquiry'];
1438 $this->options['mail_data']['title']['inquiry'] = $mail_inquiry['title'];
1439 }
1440 } else {
1441 $mail_inquiry['title'] = trim( wel_esc_script( $_POST['title']['inquiry'] ) );
1442 $this->options['mail_data']['title']['inquiry'] = $mail_inquiry['title'];
1443 }
1444 if ( WCUtils::is_blank( $_POST['header']['inquiry'] ) ) {
1445 if ( empty( $mail_inquiry['header'] ) && isset( $this->options['mail_default']['header']['inquiry'] ) ) {
1446 $mail_inquiry['header'] = $this->options['mail_default']['header']['inquiry'];
1447 $this->options['mail_data']['header']['inquiry'] = $mail_inquiry['header'];
1448 }
1449 } else {
1450 $mail_inquiry['header'] = trim( wel_esc_script( $_POST['header']['inquiry'] ) );
1451 $this->options['mail_data']['header']['inquiry'] = $mail_inquiry['header'];
1452 }
1453 if ( WCUtils::is_blank( $_POST['footer']['inquiry'] ) ) {
1454 if ( empty( $mail_inquiry['footer'] ) && isset( $this->options['mail_default']['footer']['inquiry'] ) ) {
1455 $mail_inquiry['footer'] = $this->options['mail_default']['footer']['inquiry'];
1456 $this->options['mail_data']['footer']['inquiry'] = $mail_inquiry['footer'];
1457 }
1458 } else {
1459 $mail_inquiry['footer'] = trim( wel_esc_script( $_POST['footer']['inquiry'] ) );
1460 $this->options['mail_data']['footer']['inquiry'] = $mail_inquiry['footer'];
1461 }
1462 update_option( 'usces_mail_inquiry', $mail_inquiry );
1463
1464 $mail_membercomp = get_option( 'usces_mail_membercomp', array() );
1465 if ( WCUtils::is_blank( $_POST['title']['membercomp'] ) ) {
1466 if ( empty( $mail_membercomp['title'] ) && isset( $this->options['mail_default']['title']['membercomp'] ) ) {
1467 $mail_membercomp['title'] = $this->options['mail_default']['title']['membercomp'];
1468 $this->options['mail_data']['title']['membercomp'] = $mail_membercomp['title'];
1469 }
1470 } else {
1471 $mail_membercomp['title'] = trim( wel_esc_script( $_POST['title']['membercomp'] ) );
1472 $this->options['mail_data']['title']['membercomp'] = $mail_membercomp['title'];
1473 }
1474 if ( WCUtils::is_blank( wel_esc_script( $_POST['header']['membercomp'] ) ) ) {
1475 if ( empty( $mail_membercomp['header'] ) && isset( $this->options['mail_default']['header']['membercomp'] ) ) {
1476 $mail_membercomp['header'] = $this->options['mail_default']['header']['membercomp'];
1477 $this->options['mail_data']['header']['membercomp'] = $mail_membercomp['header'];
1478 }
1479 } else {
1480 $mail_membercomp['header'] = trim( wel_esc_script( $_POST['header']['membercomp'] ) );
1481 $this->options['mail_data']['header']['membercomp'] = $mail_membercomp['header'];
1482 }
1483 if ( WCUtils::is_blank( $_POST['footer']['membercomp'] ) ) {
1484 if ( empty( $mail_membercomp['footer'] ) && isset( $this->options['mail_default']['footer']['membercomp'] ) ) {
1485 $mail_membercomp['footer'] = $this->options['mail_default']['footer']['membercomp'];
1486 $this->options['mail_data']['footer']['membercomp'] = $mail_membercomp['footer'];
1487 }
1488 } else {
1489 $mail_membercomp['footer'] = trim( wel_esc_script( $_POST['footer']['membercomp'] ) );
1490 $this->options['mail_data']['footer']['membercomp'] = $mail_membercomp['footer'];
1491 }
1492 update_option( 'usces_mail_membercomp', $mail_membercomp );
1493
1494 $this->action_status = 'success';
1495 $this->action_message = __( 'options are updated', 'usces' );
1496
1497 } elseif ( isset( $_POST['usces_option_update_manual'] ) ) {
1498 check_admin_referer( 'admin_mail', 'wc_nonce' );
1499 $_POST = $this->stripslashes_deep_post( $_POST );
1500
1501 $mail_completionmail = get_option( 'usces_mail_completionmail', array() );
1502 if ( WCUtils::is_blank( $_POST['title']['completionmail'] ) ) {
1503 if ( empty( $mail_completionmail['title'] ) && isset( $this->options['mail_default']['title']['completionmail'] ) ) {
1504 $mail_completionmail['title'] = $this->options['mail_default']['title']['completionmail'];
1505 $this->options['mail_data']['title']['completionmail'] = $mail_completionmail['title'];
1506 }
1507 } else {
1508 $mail_completionmail['title'] = trim( wel_esc_script( $_POST['title']['completionmail'] ) );
1509 $this->options['mail_data']['title']['completionmail'] = $mail_completionmail['title'];
1510 }
1511 if ( WCUtils::is_blank( $_POST['header']['completionmail'] ) ) {
1512 if ( empty( $mail_completionmail['header'] ) && isset( $this->options['mail_default']['header']['completionmail'] ) ) {
1513 $mail_completionmail['header'] = $this->options['mail_default']['header']['completionmail'];
1514 $this->options['mail_data']['header']['completionmail'] = $mail_completionmail['header'];
1515 }
1516 } else {
1517 $mail_completionmail['header'] = trim( wel_esc_script( $_POST['header']['completionmail'] ) );
1518 $this->options['mail_data']['header']['completionmail'] = $mail_completionmail['header'];
1519 }
1520 if ( WCUtils::is_blank( $_POST['footer']['completionmail'] ) ) {
1521 if ( empty( $mail_completionmail['footer'] ) && isset( $this->options['mail_default']['footer']['completionmail'] ) ) {
1522 $mail_completionmail['footer'] = $this->options['mail_default']['footer']['completionmail'];
1523 $this->options['mail_data']['footer']['completionmail'] = $mail_completionmail['footer'];
1524 }
1525 } else {
1526 $mail_completionmail['footer'] = trim( wel_esc_script( $_POST['footer']['completionmail'] ) );
1527 $this->options['mail_data']['footer']['completionmail'] = $mail_completionmail['footer'];
1528 }
1529 update_option( 'usces_mail_completionmail', $mail_completionmail );
1530
1531 $mail_ordermail = get_option( 'usces_mail_ordermail', array() );
1532 if ( WCUtils::is_blank( $_POST['title']['ordermail'] ) ) {
1533 if ( empty( $mail_ordermail['title'] ) && isset( $this->options['mail_default']['title']['ordermail'] ) ) {
1534 $mail_ordermail['title'] = $this->options['mail_default']['title']['ordermail'];
1535 $this->options['mail_data']['title']['ordermail'] = $mail_ordermail['title'];
1536 }
1537 } else {
1538 $mail_ordermail['title'] = trim( wel_esc_script( $_POST['title']['ordermail'] ) );
1539 $this->options['mail_data']['title']['ordermail'] = $mail_ordermail['title'];
1540 }
1541 if ( WCUtils::is_blank( $_POST['header']['ordermail'] ) ) {
1542 if ( empty( $mail_ordermail['header'] ) && isset( $this->options['mail_default']['header']['ordermail'] ) ) {
1543 $mail_ordermail['header'] = $this->options['mail_default']['header']['ordermail'];
1544 $this->options['mail_data']['header']['ordermail'] = $mail_ordermail['header'];
1545 }
1546 } else {
1547 $mail_ordermail['header'] = trim( wel_esc_script( $_POST['header']['ordermail'] ) );
1548 $this->options['mail_data']['header']['ordermail'] = $mail_ordermail['header'];
1549 }
1550 if ( WCUtils::is_blank( $_POST['footer']['ordermail'] ) ) {
1551 if ( empty( $mail_ordermail['footer'] ) && isset( $this->options['mail_default']['footer']['ordermail'] ) ) {
1552 $mail_ordermail['footer'] = $this->options['mail_default']['footer']['ordermail'];
1553 $this->options['mail_data']['footer']['ordermail'] = $mail_ordermail['footer'];
1554 }
1555 } else {
1556 $mail_ordermail['footer'] = trim( wel_esc_script( $_POST['footer']['ordermail'] ) );
1557 $this->options['mail_data']['footer']['ordermail'] = $mail_ordermail['footer'];
1558 }
1559 update_option( 'usces_mail_ordermail', $mail_ordermail );
1560
1561 $mail_changemail = get_option( 'usces_mail_changemail', array() );
1562 if ( WCUtils::is_blank( $_POST['title']['changemail'] ) ) {
1563 if ( empty( $mail_changemail['title'] ) && isset( $this->options['mail_default']['title']['changemail'] ) ) {
1564 $mail_changemail['title'] = $this->options['mail_default']['title']['changemail'];
1565 $this->options['mail_data']['title']['changemail'] = $mail_changemail['title'];
1566 }
1567 } else {
1568 $mail_changemail['title'] = trim( wel_esc_script( $_POST['title']['changemail'] ) );
1569 $this->options['mail_data']['title']['changemail'] = $mail_changemail['title'];
1570 }
1571 if ( WCUtils::is_blank( $_POST['header']['changemail'] ) ) {
1572 if ( empty( $mail_changemail['header'] ) && isset( $this->options['mail_default']['header']['changemail'] ) ) {
1573 $mail_changemail['header'] = $this->options['mail_default']['header']['changemail'];
1574 $this->options['mail_data']['header']['changemail'] = $mail_changemail['header'];
1575 }
1576 } else {
1577 $mail_changemail['header'] = trim( wel_esc_script( $_POST['header']['changemail'] ) );
1578 $this->options['mail_data']['header']['changemail'] = $mail_changemail['header'];
1579 }
1580 if ( WCUtils::is_blank( $_POST['footer']['changemail'] ) ) {
1581 if ( empty( $mail_changemail['footer'] ) && isset( $this->options['mail_default']['footer']['changemail'] ) ) {
1582 $mail_changemail['footer'] = $this->options['mail_default']['footer']['changemail'];
1583 $this->options['mail_data']['footer']['changemail'] = $mail_changemail['footer'];
1584 }
1585 } else {
1586 $mail_changemail['footer'] = trim( wel_esc_script( $_POST['footer']['changemail'] ) );
1587 $this->options['mail_data']['footer']['changemail'] = $mail_changemail['footer'];
1588 }
1589 update_option( 'usces_mail_changemail', $mail_changemail );
1590
1591 $mail_receiptmail = get_option( 'usces_mail_receiptmail', array() );
1592 if ( WCUtils::is_blank( $_POST['title']['receiptmail'] ) ) {
1593 if ( empty( $mail_receiptmail['title'] ) && isset( $this->options['mail_default']['title']['receiptmail'] ) ) {
1594 $mail_receiptmail['title'] = $this->options['mail_default']['title']['receiptmail'];
1595 $this->options['mail_data']['title']['receiptmail'] = $mail_receiptmail['title'];
1596 }
1597 } else {
1598 $mail_receiptmail['title'] = trim( wel_esc_script( $_POST['title']['receiptmail'] ) );
1599 $this->options['mail_data']['title']['receiptmail'] = $mail_receiptmail['title'];
1600 }
1601 if ( WCUtils::is_blank( $_POST['header']['receiptmail'] ) ) {
1602 if ( empty( $mail_receiptmail['header'] ) && isset( $this->options['mail_default']['header']['receiptmail'] ) ) {
1603 $mail_receiptmail['header'] = $this->options['mail_default']['header']['receiptmail'];
1604 $this->options['mail_data']['header']['receiptmail'] = $mail_receiptmail['header'];
1605 }
1606 } else {
1607 $mail_receiptmail['header'] = trim( wel_esc_script( $_POST['header']['receiptmail'] ) );
1608 $this->options['mail_data']['header']['receiptmail'] = $mail_receiptmail['header'];
1609 }
1610 if ( WCUtils::is_blank( $_POST['footer']['receiptmail'] ) ) {
1611 if ( empty( $mail_receiptmail['footer'] ) && isset( $this->options['mail_default']['footer']['receiptmail'] ) ) {
1612 $mail_receiptmail['footer'] = $this->options['mail_default']['footer']['receiptmail'];
1613 $this->options['mail_data']['footer']['receiptmail'] = $mail_receiptmail['footer'];
1614 }
1615 } else {
1616 $mail_receiptmail['footer'] = trim( wel_esc_script( $_POST['footer']['receiptmail'] ) );
1617 $this->options['mail_data']['footer']['receiptmail'] = $mail_receiptmail['footer'];
1618 }
1619 update_option( 'usces_mail_receiptmail', $mail_receiptmail );
1620
1621 $mail_mitumorimail = get_option( 'usces_mail_mitumorimail', array() );
1622 if ( WCUtils::is_blank( $_POST['title']['mitumorimail'] ) ) {
1623 if ( empty( $mail_mitumorimail['title'] ) && isset( $this->options['mail_default']['title']['mitumorimail'] ) ) {
1624 $mail_mitumorimail['title'] = $this->options['mail_default']['title']['mitumorimail'];
1625 $this->options['mail_data']['title']['mitumorimail'] = $mail_mitumorimail['title'];
1626 }
1627 } else {
1628 $mail_mitumorimail['title'] = trim( wel_esc_script( $_POST['title']['mitumorimail'] ) );
1629 $this->options['mail_data']['title']['mitumorimail'] = $mail_mitumorimail['title'];
1630 }
1631 if ( WCUtils::is_blank( $_POST['header']['mitumorimail'] ) ) {
1632 if ( empty( $mail_mitumorimail['header'] ) && isset( $this->options['mail_default']['header']['mitumorimail'] ) ) {
1633 $mail_mitumorimail['header'] = $this->options['mail_default']['header']['mitumorimail'];
1634 $this->options['mail_data']['header']['mitumorimail'] = $mail_mitumorimail['header'];
1635 }
1636 } else {
1637 $mail_mitumorimail['header'] = trim( wel_esc_script( $_POST['header']['mitumorimail'] ) );
1638 $this->options['mail_data']['header']['mitumorimail'] = $mail_mitumorimail['header'];
1639 }
1640 if ( WCUtils::is_blank( $_POST['footer']['mitumorimail'] ) ) {
1641 if ( empty( $mail_mitumorimail['footer'] ) && isset( $this->options['mail_default']['footer']['mitumorimail'] ) ) {
1642 $mail_mitumorimail['footer'] = $this->options['mail_default']['footer']['mitumorimail'];
1643 $this->options['mail_data']['footer']['mitumorimail'] = $mail_mitumorimail['footer'];
1644 }
1645 } else {
1646 $mail_mitumorimail['footer'] = trim( wel_esc_script( $_POST['footer']['mitumorimail'] ) );
1647 $this->options['mail_data']['footer']['mitumorimail'] = $mail_mitumorimail['footer'];
1648 }
1649 update_option( 'usces_mail_mitumorimail', $mail_mitumorimail );
1650
1651 $mail_cancelmail = get_option( 'usces_mail_cancelmail', array() );
1652 if ( WCUtils::is_blank( $_POST['title']['cancelmail'] ) ) {
1653 if ( empty( $mail_cancelmail['title'] ) && isset( $this->options['mail_default']['title']['cancelmail'] ) ) {
1654 $mail_cancelmail['title'] = $this->options['mail_default']['title']['cancelmail'];
1655 $this->options['mail_data']['title']['cancelmail'] = $mail_cancelmail['title'];
1656 }
1657 } else {
1658 $mail_cancelmail['title'] = trim( wel_esc_script( $_POST['title']['cancelmail'] ) );
1659 $this->options['mail_data']['title']['cancelmail'] = $mail_cancelmail['title'];
1660 }
1661 if ( WCUtils::is_blank( $_POST['header']['cancelmail'] ) ) {
1662 if ( empty( $mail_cancelmail['header'] ) && isset( $this->options['mail_default']['header']['cancelmail'] ) ) {
1663 $mail_cancelmail['header'] = $this->options['mail_default']['header']['cancelmail'];
1664 $this->options['mail_data']['header']['cancelmail'] = $mail_cancelmail['header'];
1665 }
1666 } else {
1667 $mail_cancelmail['header'] = trim( wel_esc_script( $_POST['header']['cancelmail'] ) );
1668 $this->options['mail_data']['header']['cancelmail'] = $mail_cancelmail['header'];
1669 }
1670 if ( WCUtils::is_blank( $_POST['footer']['cancelmail'] ) ) {
1671 if ( empty( $mail_cancelmail['footer'] ) && isset( $this->options['mail_default']['footer']['cancelmail'] ) ) {
1672 $mail_cancelmail['footer'] = $this->options['mail_default']['footer']['cancelmail'];
1673 $this->options['mail_data']['footer']['cancelmail'] = $mail_cancelmail['footer'];
1674 }
1675 } else {
1676 $mail_cancelmail['footer'] = trim( wel_esc_script( $_POST['footer']['cancelmail'] ) );
1677 $this->options['mail_data']['footer']['cancelmail'] = $mail_cancelmail['footer'];
1678 }
1679 update_option( 'usces_mail_cancelmail', $mail_cancelmail );
1680
1681 $this->action_status = 'success';
1682 $this->action_message = __( 'options are updated', 'usces' );
1683
1684 } else {
1685 $this->action_status = 'none';
1686 $this->action_message = '';
1687 }
1688
1689 do_action( 'usces_action_admin_mail_page' );
1690
1691 if ( isset( $this->options['add_html_email_option'] ) && 1 == $this->options['add_html_email_option'] ) {
1692 wp_enqueue_script( 'jquery-ui-dialog' );
1693 }
1694
1695 require_once USCES_PLUGIN_DIR . '/includes/admin_mail.php';
1696 }
1697
1698 /**
1699 * Admin Cart Page.
1700 */
1701 public function admin_cart_page() {
1702 global $allowedposttags;
1703 $this->options = get_option( 'usces' );
1704
1705 if ( isset( $_POST['usces_option_update'] ) ) {
1706
1707 check_admin_referer( 'admin_cart', 'wc_nonce' );
1708
1709 $_POST = $this->stripslashes_deep_post( $_POST );
1710
1711 foreach ( $this->options['indi_item_name'] as $key => $value ) {
1712 $this->options['indi_item_name'][ $key ] = isset( $_POST['indication'][ $key ] ) ? 1 : 0;
1713 }
1714 foreach ( $_POST['position'] as $key => $value ) {
1715 $this->options['pos_item_name'][ $key ] = $value;
1716 }
1717 foreach ( $_POST['header'] as $key => $value ) {
1718 $this->options['cart_page_data']['header'][ $key ] = wp_kses( $value, $allowedposttags );
1719 }
1720 foreach ( $_POST['footer'] as $key => $value ) {
1721 $this->options['cart_page_data']['footer'][ $key ] = wp_kses( $value, $allowedposttags );
1722 }
1723 if ( isset( $_POST['confirm_notes'] ) ) {
1724 $this->options['cart_page_data']['confirm_notes'] = wp_kses( $_POST['confirm_notes'], $allowedposttags );
1725 }
1726 update_option( 'usces', $this->options );
1727
1728 $this->action_status = 'success';
1729 $this->action_message = __( 'options are updated', 'usces' );
1730
1731 } else {
1732 $this->action_status = 'none';
1733 $this->action_message = '';
1734 }
1735
1736 require_once USCES_PLUGIN_DIR . '/includes/admin_cart.php';
1737 }
1738
1739 /**
1740 * Admin Member Page.
1741 */
1742 public function admin_member_page() {
1743 global $allowedposttags;
1744 $this->options = get_option( 'usces' );
1745
1746 if ( isset( $_POST['usces_option_update'] ) ) {
1747
1748 check_admin_referer( 'admin_member', 'wc_nonce' );
1749
1750 $_POST = $this->stripslashes_deep_post( $_POST );
1751
1752 foreach ( $_POST['header'] as $key => $value ) {
1753 $this->options['member_page_data']['header'][ $key ] = wp_kses( $value, $allowedposttags );
1754 }
1755 foreach ( $_POST['footer'] as $key => $value ) {
1756 $this->options['member_page_data']['footer'][ $key ] = wp_kses( $value, $allowedposttags );
1757 }
1758 $this->options['member_page_data']['agree_member_exp'] = isset( $_POST['agree_member_exp'] ) ? $_POST['agree_member_exp'] : '';
1759 $this->options['member_page_data']['agree_member_cont'] = isset( $_POST['agree_member_cont'] ) ? $_POST['agree_member_cont'] : '';
1760
1761 $this->options['agree_member'] = isset( $_POST['agree_member'] ) ? $_POST['agree_member'] : 'deactivate';
1762
1763 update_option( 'usces', $this->options );
1764
1765 $this->action_status = 'success';
1766 $this->action_message = __( 'options are updated', 'usces' );
1767
1768 } else {
1769 $this->action_status = 'none';
1770 $this->action_message = '';
1771 }
1772
1773 require_once USCES_PLUGIN_DIR . '/includes/admin_member.php';
1774 }
1775
1776 /**
1777 * Admin System Page.
1778 */
1779 public function admin_system_page() {
1780 global $usces_states;
1781 $action_status = '';
1782
1783 $this->options = get_option( 'usces' );
1784
1785 if ( isset( $_POST['usces_system_option_update'] ) ) {
1786
1787 check_admin_referer( 'admin_system', 'wc_nonce' );
1788 $_POST = $this->stripslashes_deep_post( $_POST );
1789
1790 $this->options['divide_item'] = isset( $_POST['divide_item'] ) ? 1 : 0;
1791 $this->options['itemimg_anchor_rel'] = isset( $_POST['itemimg_anchor_rel'] ) ? trim( $_POST['itemimg_anchor_rel'] ) : '';
1792 $this->options['fukugo_category_orderby'] = isset( $_POST['fukugo_category_orderby'] ) ? $_POST['fukugo_category_orderby'] : '';
1793 $this->options['fukugo_category_order'] = isset( $_POST['fukugo_category_order'] ) ? $_POST['fukugo_category_order'] : '';
1794 $this->options['settlement_path'] = isset( $_POST['settlement_path'] ) ? $_POST['settlement_path'] : '';
1795 if ( WCUtils::is_blank( $this->options['settlement_path'] ) ) {
1796 $this->options['settlement_path'] = USCES_PLUGIN_DIR . 'settlement/';
1797 }
1798 $sl = substr( $this->options['settlement_path'], -1 );
1799 if ( '/' != $sl && '\\' != $sl ) {
1800 $this->options['settlement_path'] .= '/';
1801 }
1802 $this->options['logs_path'] = isset( $_POST['logs_path'] ) ? $_POST['logs_path'] : '';
1803 if ( ! WCUtils::is_blank( $this->options['logs_path'] ) ) {
1804 $sl = substr( $this->options['logs_path'], -1 );
1805 if ( '/' == $sl || '\\' == $sl ) {
1806 $this->options['logs_path'] = substr( $this->options['logs_path'], 0, -1 );
1807 }
1808 }
1809 $this->options['use_ssl'] = isset( $_POST['use_ssl'] ) ? 1 : 0;
1810 $this->options['ssl_url'] = isset( $_POST['ssl_url'] ) ? rtrim( $_POST['ssl_url'], '/' ) : '';
1811 $this->options['ssl_url_admin'] = isset( $_POST['ssl_url_admin'] ) ? rtrim( $_POST['ssl_url_admin'], '/' ) : '';
1812 if ( WCUtils::is_blank( $this->options['ssl_url'] ) || WCUtils::is_blank( $this->options['ssl_url_admin'] ) ) {
1813 $this->options['use_ssl'] = 0;
1814 }
1815 $this->options['inquiry_id'] = isset( $_POST['inquiry_id'] ) ? esc_html( rtrim( $_POST['inquiry_id'] ) ) : '';
1816 $this->options['use_javascript'] = isset( $_POST['use_javascript'] ) ? (int) $_POST['use_javascript'] : 1;
1817
1818 $this->options['system']['no_cart_css'] = isset( $_POST['no_cart_css'] ) ? 1 : 0;
1819 $this->options['system']['dec_orderID_flag'] = isset( $_POST['dec_orderID_flag'] ) ? (int) $_POST['dec_orderID_flag'] : 0;
1820 $this->options['system']['dec_orderID_prefix'] = isset( $_POST['dec_orderID_prefix'] ) ? esc_html( rtrim( $_POST['dec_orderID_prefix'] ) ) : '';
1821
1822 if ( isset( $_POST['dec_orderID_digit'] ) ) {
1823 $dec_orderid_digit = (int) rtrim( $_POST['dec_orderID_digit'] );
1824 if ( 6 > $dec_orderid_digit ) {
1825 $this->options['system']['dec_orderID_digit'] = 6;
1826 } else {
1827 $this->options['system']['dec_orderID_digit'] = $dec_orderid_digit;
1828 }
1829 } else {
1830 $this->options['system']['dec_orderID_digit'] = 6;
1831 }
1832
1833 $this->options['system']['subimage_rule'] = isset( $_POST['subimage_rule'] ) ? (int) $_POST['subimage_rule'] : 0;
1834 $this->options['system']['pdf_delivery'] = isset( $_POST['pdf_delivery'] ) ? (int) $_POST['pdf_delivery'] : 0;
1835 $this->options['system']['member_pass_rule_min'] = isset( $_POST['member_pass_rule_min'] ) ? (int) $_POST['member_pass_rule_min'] : 6;
1836 $this->options['system']['member_pass_rule_max'] = isset( $_POST['member_pass_rule_max'] ) && ! empty( $_POST['member_pass_rule_max'] ) ? (int) $_POST['member_pass_rule_max'] : 30;
1837 $this->options['system']['member_pass_rule_upercase'] = isset( $_POST['member_pass_rule_upercase'] ) ? 1 : 0;
1838 $this->options['system']['member_pass_rule_lowercase'] = isset( $_POST['member_pass_rule_lowercase'] ) ? 1 : 0;
1839 $this->options['system']['member_pass_rule_digit'] = isset( $_POST['member_pass_rule_digit'] ) ? 1 : 0;
1840 $this->options['system']['member_pass_rule_symbols'] = isset( $_POST['member_pass_rule_symbols'] ) ? 1 : 0;
1841 $this->options['system']['member_pass_rule_number'] = isset( $_POST['member_pass_rule_number'] ) ? 1 : 0;
1842 $this->options['system']['member_pass_rule_symbol'] = isset( $_POST['member_pass_rule_symbol'] ) ? 1 : 0;
1843 $this->options['system']['csv_encode_type'] = isset( $_POST['csv_encode_type'] ) ? (int) $_POST['csv_encode_type'] : 0;
1844 $this->options['system']['csv_category_format'] = ( isset( $_POST['csv_category_format'] ) ) ? (int) $_POST['csv_category_format'] : 0;
1845 $this->options['system']['settlement_backup'] = ( isset( $_POST['settlement_backup'] ) ) ? (int) $_POST['settlement_backup'] : 0;
1846 $this->options['system']['settlement_notice'] = ( isset( $_POST['settlement_notice'] ) ) ? (int) $_POST['settlement_notice'] : 0;
1847 $this->options['system']['order_list_delete_link'] = ( isset( $_POST['order_list_delete_link'] ) ) ? (int) $_POST['order_list_delete_link'] : 0;
1848 $this->options['system']['member_list_delete_link'] = ( isset( $_POST['member_list_delete_link'] ) ) ? (int) $_POST['member_list_delete_link'] : 0;
1849
1850 if ( '' != $action_status ) {
1851 $this->action_status = 'error';
1852 $this->action_message = __( 'Data have deficiency.', 'usces' );
1853 } else {
1854 $this->action_status = 'success';
1855 $this->action_message = __( 'options are updated', 'usces' );
1856 }
1857 } elseif ( isset( $_POST['usces_locale_option_update'] ) ) {
1858
1859 check_admin_referer( 'admin_system', 'wc_nonce' );
1860 $_POST = $this->stripslashes_deep_post( $_POST );
1861
1862 $this->options['system']['front_lang'] = ( isset( $_POST['front_lang'] ) && 'others' != $_POST['front_lang'] ) ? $_POST['front_lang'] : usces_get_local_language();
1863 $this->options['system']['currency'] = ( isset( $_POST['currency'] ) && 'others' != $_POST['currency'] ) ? $_POST['currency'] : usces_get_base_country();
1864 $this->options['system']['addressform'] = ( isset( $_POST['addressform'] ) ) ? $_POST['addressform'] : usces_get_local_addressform();
1865 $this->options['system']['target_market'] = ( isset( $_POST['target_market'] ) ) ? $_POST['target_market'] : usces_get_local_target_market();
1866
1867 unset ( $this->options['province'] );
1868 foreach ( (array) $this->options['system']['target_market'] as $target_market ) {
1869 $province = array();
1870 if ( ! empty( $_POST[ 'province_' . $target_market ] ) ) {
1871 $_province = usces_change_line_break( $_POST[ 'province_' . $target_market ] );
1872 $temp_pref = explode( "\n", $_province );
1873 $province[] = '-- Select --';
1874 foreach ( $temp_pref as $pref ) {
1875 if ( ! WCUtils::is_blank( $pref ) ) {
1876 $validated = wel_validate_prefecture_name( wp_unslash( $pref ) );
1877 if ( '' !== $validated ) {
1878 $province[] = esc_html( $validated );
1879 }
1880 }
1881 }
1882 if ( 1 == count( $province ) ) {
1883 $action_status = 'error';
1884 }
1885 } else {
1886 if ( isset( $usces_states[ $target_market ] ) && is_array( $usces_states[ $target_market ] ) ) {
1887 $province = $usces_states[ $target_market ];
1888 } else {
1889 $action_status = 'error';
1890 }
1891 }
1892 $this->options['province'][ $target_market ] = $province;
1893 }
1894
1895 if ( '' != $action_status ) {
1896 $this->action_status = 'error';
1897 $this->action_message = __( 'Data have deficiency.', 'usces' );
1898 } else {
1899 $this->action_status = 'success';
1900 $this->action_message = __( 'options are updated', 'usces' );
1901 }
1902 } else {
1903
1904 if ( ! isset( $this->options['province'] ) || empty( $this->options['province'] ) ) {
1905 $this->options['province'][ $this->options['system']['base_country'] ] = $usces_states[ $this->options['system']['base_country'] ];
1906 }
1907 $this->action_status = 'none';
1908 $this->action_message = '';
1909 }
1910
1911 if ( 'error' != $action_status ) {
1912 update_option( 'usces', $this->options );
1913 }
1914
1915 require_once USCES_PLUGIN_DIR . '/includes/admin_system.php';
1916 }
1917
1918 /**
1919 * Settlement Setting Page.
1920 */
1921 public function admin_settlement_page() {
1922
1923 $this->action_status = 'none';
1924 $this->action_message = '';
1925
1926 $options = get_option( 'usces' );
1927 $mes = '';
1928
1929 if ( isset( $_POST['usces_option_update'] ) ) {
1930
1931 check_admin_referer( 'admin_settlement', 'wc_nonce' );
1932
1933 $_POST = $this->stripslashes_deep_post( $_POST );
1934
1935 switch ( $_POST['acting'] ) {
1936 case 'settlement_selected':
1937 if ( isset( $_POST['settlement_selected'] ) ) {
1938 $settlement_selected = explode( ',', sanitize_text_field( wp_unslash( $_POST['settlement_selected'] ) ) );
1939 $payments = usces_get_system_option( 'usces_payment_method', 'settlement' );
1940 $acting_payments = array();
1941 foreach ( (array) $payments as $key => $payment ) {
1942 if ( 'activate' == $payment['use'] && false !== strpos( $key, 'acting_' ) ) {
1943 $acting = explode( '_', $key );
1944 if ( ! empty( $acting[1] ) && 'paypal' == $acting[1] ) {
1945 $acting_payments[] = $acting[1] . '_cp';
1946 } else {
1947 $acting_payments[] = apply_filters( 'usces_filter_acting_payment_slug', $acting[1], $acting );
1948 }
1949 }
1950 }
1951 $acting_payments = array_unique( $acting_payments );
1952 $available_settlement = get_option( 'usces_available_settlement', array() );
1953 $available = array_keys( $available_settlement );
1954 foreach ( (array) $settlement_selected as $settlement ) {
1955 if ( ! empty( $settlement ) && ! in_array( $settlement, $available ) ) {
1956 $mes .= __( '* Failed to update payment module.', 'usces' ) . '<br />';
1957 }
1958 }
1959 foreach ( (array) $acting_payments as $payment ) {
1960 if ( ! in_array( $payment, $settlement_selected ) && isset( $available_settlement[ $payment ] ) ) {
1961 $settlement_name = $available_settlement[ $payment ];
1962 $mes .= sprintf( __( '* %s can not be unselected. Please "delete" or "stop" the payment method.', 'usces' ), $settlement_name ) . '<br />';
1963 }
1964 }
1965 if ( WCUtils::is_blank( $mes ) ) {
1966 $unavailable_activate = 0;
1967 $unavailable_payments = apply_filters( 'usces_filter_unavailable_payments', get_option( 'usces_unavailable_settlement', array() ) );
1968 foreach ( (array) $unavailable_payments as $payment ) {
1969 if ( in_array( $payment, $settlement_selected ) ) {
1970 $unavailable_activate++;
1971 }
1972 }
1973 if ( 1 < $unavailable_activate ) {
1974 $mes .= __( '* Settlement that can not be used together is activated.', 'usces' ) . '<br />';
1975 }
1976 }
1977
1978 if ( WCUtils::is_blank( $mes ) ) {
1979 update_option( 'usces_settlement_selected', $settlement_selected );
1980 $this->settlement->setup();
1981 $this->action_status = 'success';
1982 $this->action_message = __( 'Updated.', 'usces' );
1983 } else {
1984 $this->action_status = 'error';
1985 $this->action_message = __( 'Update failed.', 'usces' );
1986 }
1987 }
1988 break;
1989 }
1990 do_action( 'usces_action_admin_settlement_update', $mes );
1991 }
1992
1993 $this->options = get_option( 'usces' );
1994
1995 require_once USCES_PLUGIN_DIR . '/includes/admin_settlement.php';
1996 }
1997
1998 public function selected( $selected, $current ) {
1999 if ( $selected == $current ) {
2000 echo ' selected="selected"';
2001 }
2002 }
2003
2004 public function usces_session_start() {
2005 $options = get_option( 'usces' );
2006 if ( ! isset( $options['usces_key'] ) || empty( $options['usces_key'] ) ) {
2007 $options['usces_key'] = uniqid( 'uk' );
2008 update_option( 'usces', $options );
2009 }
2010
2011 if ( defined( 'USCES_KEY' ) ) {
2012 if ( is_admin() || preg_match( '/\/wp-login\.php/', $_SERVER['REQUEST_URI'] ) ) {
2013 @session_name( 'adm' . USCES_KEY );
2014 } else {
2015 @session_name( USCES_KEY );
2016 }
2017 } else {
2018 if ( is_admin() || preg_match( '/\/wp-login\.php/', $_SERVER['REQUEST_URI'] ) ) {
2019 @session_name( 'adm' . $options['usces_key'] );
2020 } else {
2021 @session_name( $options['usces_key'] );
2022 }
2023 }
2024
2025 // A1 (Layer 3 / uscesid removal): uscesid によるセッションID設定を撤廃。
2026 // かつては GET uscesid を uscesdc() で復号し session_id() に渡していたが、これがセッション
2027 // 固定の温床だった(会員乗っ取り・Mantis #0005562)。決済通知のセッション復元は取引キーの
2028 // DBストア(A3)/同一オリジンの uk cookie 再開(A2/A5/A6)へ移行済みのため撤廃する。
2029 // See .docs/welcart2.x/security-remediation_uscesid-layer3-a1c-teardown-design.md .
2030
2031 do_action( 'usces_action_session_start' );
2032
2033 $httponly = true;
2034 $sitescheme = substr( get_option( 'siteurl' ), 0, 5 );
2035 $homescheme = substr( get_option( 'home' ), 0, 5 );
2036 if ( 'https' == $sitescheme && 'https' == $homescheme ) {
2037 $sslonly = true;
2038 $samesite = 'None';
2039 } else {
2040 $sslonly = false;
2041 $samesite = '';
2042 }
2043
2044 if ( version_compare( PHP_VERSION, '7.3.0', '>=' ) ) {
2045 $cookie_options = array(
2046 'lifetime' => 0,
2047 'path' => USCES_COOKIEPATH,
2048 'domain' => '',
2049 'secure' => $sslonly,
2050 'httponly' => $httponly,
2051 'samesite' => $samesite,
2052 );
2053 session_set_cookie_params( $cookie_options );
2054 } else {
2055 session_set_cookie_params( 0, USCES_COOKIEPATH, '', $sslonly, $httponly );
2056 }
2057
2058 @session_start();
2059
2060 if ( ! isset( $_SESSION['usces_member'] ) || 'activate' != $options['membersystem_state'] ) {
2061 $_SESSION['usces_member'] = array();
2062 }
2063
2064 if ( ! isset( $_SESSION['usces_checked_business_days'] ) ) {
2065 $this->update_business_days();
2066 }
2067 }
2068
2069 public function usces_cookie() {
2070 if ( is_admin() ) {
2071 return;
2072 }
2073
2074 // A1/C (Layer 3 / uscesid removal): 旧「GET uscesid を復号して addr='acting' を判定」ブロックを撤廃。
2075 // uscesid 機構撤廃に伴い addr 判定は成立しない。以降は旧SSL同期デッドコード(A7 で撤去済)で return.
2076 if ( apply_filters( 'usces_filter_cookie', false ) ) {
2077 return;
2078 }
2079
2080 // NOTE (Layer 3 / uscesid removal, A7): the legacy "common domain + separate SSL domain"
2081 // cookie-sync block that used to follow here was already unreachable (an unconditional
2082 // return above) and relied on the old SSL/uscesid scheme. Removed during the uscesid
2083 // mechanism teardown. See .docs/welcart2.x/security-remediation_uscesid-session-fixation.md 4.3.A A7.
2084 return;
2085 }
2086
2087 public function set_cookie( $values, $key = 'usces_cookie' ) {
2088 // A1/C (Layer 3 / uscesid removal): 旧実装は uscesid 付きリクエストで再生成をスキップしていたが、
2089 // uscesid 機構を撤廃したため常に再生成する(=uscesid 以前のオーガニック挙動に一致)。
2090 // 決済のセッション継続は取引キーDBストア(A3)/uk cookie(A2/A5/A6)で担保.
2091 session_regenerate_id( true );
2092 $value = usces_serialize( $values );
2093 $timeout = time()+7*86400;
2094 $timeout = apply_filters( 'usces_filter_set_cookie_timeout', $timeout, $values, $key );
2095 $domain = $_SERVER['SERVER_NAME'];
2096
2097 $httponly = true;
2098 $sitescheme = substr( get_option( 'siteurl' ), 0, 5 );
2099 $homescheme = substr( get_option( 'home' ), 0, 5 );
2100 if ( 'https' == $sitescheme && 'https' == $homescheme ) {
2101 $sslonly = true;
2102 $samesite = 'None';
2103 } else {
2104 $sslonly = false;
2105 $samesite = '';
2106 }
2107
2108 if ( version_compare( PHP_VERSION, '7.3.0', '>=' ) ) {
2109 $cookie_options = array(
2110 'expires' => $timeout,
2111 'path' => USCES_COOKIEPATH,
2112 'domain' => $domain,
2113 'secure' => $sslonly,
2114 'httponly' => $httponly,
2115 'samesite' => $samesite,
2116 );
2117 $res = setcookie( $key, $value, $cookie_options );
2118 } else {
2119 $res = setcookie( $key, $value, $timeout, USCES_COOKIEPATH, $domain, true, true );
2120 }
2121 }
2122
2123 public function get_cookie( $key = 'usces_cookie' ) {
2124 $values = isset( $_COOKIE[ $key ] ) ? usces_unserialize( stripslashes( $_COOKIE[ $key ] ) ) : null;
2125 return $values;
2126 }
2127
2128 public function get_access( $key, $type, $date ) {
2129 global $wpdb;
2130 $table_name = $wpdb->prefix . 'usces_access';
2131
2132 $query = $wpdb->prepare( "SELECT acc_value FROM $table_name WHERE acc_key = %s AND acc_type = %s AND acc_date = %s", $key, $type, $date );
2133 $value = $wpdb->get_var( $query );
2134 if ( ! $value ) {
2135 $res = null;
2136 } else {
2137 $res = wel_safe_unserialize( $value );
2138 }
2139
2140 return $res;
2141 }
2142
2143 public function get_access_piriod( $key, $type, $startday, $endday ) {
2144 global $wpdb;
2145 $table_name = $wpdb->prefix . 'usces_access';
2146 $query = $wpdb->prepare( "SELECT acc_type, acc_value, acc_date FROM $table_name WHERE acc_key = %s AND acc_type = %s AND (acc_date >= %s AND acc_date <= %s)", $key, $type, $startday, $endday );
2147 $res = $wpdb->get_results( $query, ARRAY_A );
2148
2149 return $res;
2150 }
2151
2152 public function update_access( $array ) {
2153 global $wpdb;
2154 $table_name = $wpdb->prefix . 'usces_access';
2155
2156 $query = $wpdb->prepare( "SELECT ID FROM $table_name WHERE acc_key = %s AND acc_type = %s AND acc_date = %s", $array['acc_key'], $array['acc_type'], $array['acc_date'] );
2157 $res = $wpdb->get_var( $query );
2158 if ( empty( $res ) ) {
2159 $query = $wpdb->prepare( "INSERT INTO $table_name (acc_key, acc_type, acc_value, acc_date) VALUES(%s, %s, %s, %s)", $array['acc_key'], $array['acc_type'], serialize( $array['acc_value'] ), $array['acc_date'] );
2160 $wpdb->query( $query );
2161 } else {
2162 $query = $wpdb->prepare( "UPDATE $table_name SET acc_value = %s WHERE acc_key = %s AND acc_type = %s AND acc_date = %s", serialize( $array['acc_value'] ), $array['acc_key'], $array['acc_type'], $array['acc_date'] );
2163 $wpdb->query( $query );
2164 }
2165 }
2166
2167 /**
2168 * @deprecated A1/C (Layer 3 / uscesid removal). uscesid 機構は撤廃済み(A1)。本体はこの関数を
2169 * セッション設定にもURL/nonce生成にも使わない。現状 acting_data の acc_str1 マーカー(save_order_acting_data)
2170 * と、未移行の拡張・クライアントの後方互換のためだけに残置している。**全拡張・全クライアント移行後に
2171 * uscescv()/uscesdc() ともども削除する**(最終クリーンアップ)。
2172 */
2173 public function get_uscesid( $flag = true ) {
2174 $sessname = session_name();
2175 $sessid = session_id();
2176 $sessid = $this->uscescv( $sessid, $flag );
2177 return $sessid;
2178 }
2179
2180 /**
2181 * Session-bound nonce action key for shop-member forms (uscesid-free).
2182 *
2183 * Welcart shop members are not WordPress users (uid=0, empty WP session token), so a
2184 * per-session component is mixed into the nonce action string to keep nonces scoped to
2185 * the individual shop session. This replaces the legacy `$action . get_uscesid(false)`
2186 * (which encoded the same session id via the uscesid obfuscation). The session id is
2187 * used only as a server-side hash input — it is never output to the client or a URL.
2188 *
2189 * @param string $action Base action (e.g. 'post_member' / 'use_point' / 'wc_purchase_nonce').
2190 * @return string
2191 */
2192 public function member_nonce_key( $action ) {
2193 return $action . session_id();
2194 }
2195
2196 /**
2197 * Create a shop-member nonce bound to the current session.
2198 *
2199 * @param string $action Base action.
2200 * @return string
2201 */
2202 public function create_member_nonce( $action ) {
2203 return wp_create_nonce( $this->member_nonce_key( $action ) );
2204 }
2205
2206 /**
2207 * Verify a shop-member nonce.
2208 *
2209 * A1/C (Layer 3 / uscesid removal): 移行期の後方互換だった「旧 uscesid ベースキーの二重受理」を撤廃。
2210 * 以降はセッション束縛の新方式キー(member_nonce_key)のみ受理する。未移行の拡張・テーマの
2211 * フォーム(旧キー生成)は新方式へ移行するまで nonce 不一致になる(協調リリースで同時展開)。
2212 *
2213 * @param string $nonce Nonce value from the request.
2214 * @param string $action Base action.
2215 * @return int|false 1|2 on success, false on failure.
2216 */
2217 public function verify_member_nonce( $nonce, $action ) {
2218 return wp_verify_nonce( $nonce, $this->member_nonce_key( $action ) );
2219 }
2220
2221 public function shop_head() {
2222 global $post;
2223 $this->item = $post;
2224 if ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) ) {
2225 echo "<meta name='robots' content='noindex,nofollow' />\n";
2226 }
2227 }
2228
2229 /**
2230 * Caught by wp_footer action hook
2231 */
2232 public function shop_foot() {
2233 global $current_user;
2234
2235 $item = $this->item;
2236 if ( empty( $item ) ) {
2237 $item = new stdClass;
2238 $item->ID = 0;
2239 $item->post_mime_type = '';
2240 }
2241
2242 wp_get_current_user();
2243
2244 // usces_cart.js is not used.
2245 if ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
2246 $javascript_url = USCES_FRONT_PLUGIN_URL . '/js/usces_cart.js';
2247 } else {
2248 $javascript_url = USCES_WP_CONTENT_URL . '/plugins/' . USCES_PLUGIN_FOLDER . '/js/usces_cart.js';
2249 }
2250
2251 $this->previous_url = isset( $_SESSION['usces_previous_url'] ) ? $_SESSION['usces_previous_url'] : get_home_url();
2252
2253 // If the product object does't exists.
2254 if ( $this->use_js && empty( $this->item ) ) {
2255 ?>
2256 <script type='text/javascript'>
2257 uscesL10n = {
2258 <?php echo apply_filters( 'usces_filter_uscesL10n', null, $item->ID ); ?>
2259
2260 'ajaxurl': "<?php echo esc_url( $this->ssl_admin_ajax_url() ); ?>"
2261 }
2262 </script>
2263 <?php
2264
2265 // If the product object exists.
2266 } elseif ( $this->use_js && ! empty( $this->item ) ) {
2267
2268 $ioptkeys = $this->get_itemOptionKey( $item->ID );
2269 $mes_opts_str = '';
2270 $key_opts_str = '';
2271 $opt_means = '';
2272 $opt_esse = '';
2273 if ( $ioptkeys ) {
2274 foreach ( $ioptkeys as $key => $value ) {
2275 $optValues = $this->get_itemOptions( $value, $item->ID );
2276 if ( false === $optValues ) {
2277 continue;
2278 }
2279 if ( $optValues['means'] < 2 || 3 == $optValues['means'] || 4 == $optValues['means'] ) {
2280 $mes_opts_str .= "'" . sprintf( __( 'Chose the %s', 'usces' ), esc_js( apply_filters( 'usces_filter_uscesL10n_option_name', $value, $optValues ) ) ) . "',";
2281 } else {
2282 $mes_opts_str .= "'" . sprintf( __( 'Input the %s', 'usces' ), esc_js( apply_filters( 'usces_filter_uscesL10n_option_name', $value, $optValues ) ) ) . "',";
2283 }
2284 $key_opts_str .= "'" . urlencode( esc_js( $value ) ) . "',";
2285 $opt_means .= "'" . esc_js( $optValues['means'] ) . "',";
2286 $opt_esse .= "'" . esc_js( $optValues['essential'] ) . "',";
2287 }
2288 $mes_opts_str = rtrim( $mes_opts_str, ',' );
2289 $key_opts_str = rtrim( $key_opts_str, ',' );
2290 $opt_means = rtrim( $opt_means, ',' );
2291 $opt_esse = rtrim( $opt_esse, ',' );
2292 }
2293
2294 $product = wel_get_product( $item->ID );
2295 $itemRestriction = isset( $product['itemRestriction'] ) ? $product['itemRestriction'] : '';
2296 $wcpage = usces_page_name( 'return' );
2297 $nonce_action = 'wc_confirm';
2298 $itemOrderAcceptable = $this->getItemOrderAcceptable( $item->ID );
2299 ?>
2300 <script type='text/javascript'>
2301 uscesL10n = {
2302 <?php echo apply_filters( 'usces_filter_uscesL10n', null, $item->ID ); ?>
2303
2304 'ajaxurl': "<?php echo esc_url( $this->ssl_admin_ajax_url() ); ?>",
2305 'loaderurl': "<?php echo USCES_PLUGIN_URL . 'images/loading.gif'; ?>",
2306 'post_id': "<?php echo esc_js( $item->ID ); ?>",
2307 'cart_number': "<?php echo get_option( 'usces_cart_number' ); ?>",
2308 'is_cart_row': <?php echo ( ( 0 < $this->cart->num_row() ) ? 'true' : 'false' ); ?>,
2309 'opt_esse': new Array( <?php wel_esc_script_e( $opt_esse ); ?> ),
2310 'opt_means': new Array( <?php wel_esc_script_e( $opt_means ); ?> ),
2311 'mes_opts': new Array( <?php wel_esc_script_e( $mes_opts_str ); ?> ),
2312 'key_opts': new Array( <?php wel_esc_script_e( $key_opts_str ); ?> ),
2313 'previous_url': "<?php echo esc_url( $this->previous_url ); ?>",
2314 'itemRestriction': "<?php echo esc_js( $itemRestriction ); ?>",
2315 'itemOrderAcceptable': "<?php echo esc_js( $itemOrderAcceptable ); ?>",
2316 'uscespage': "<?php echo esc_js( $wcpage ); ?>",
2317 <?php // A1/C (Layer 3 / uscesid removal): JS グローバル uscesL10n.uscesid の供給を撤廃。消費側は uk cookie 依存へ移行. ?>
2318 'wc_nonce': "<?php echo wp_create_nonce( $nonce_action ); ?>"
2319 }
2320 </script>
2321 <script type='text/javascript' src='<?php echo esc_url( $javascript_url ); ?>'></script>
2322 <?php
2323 }
2324
2325 ob_start();
2326
2327 // If it's Product Details page.
2328 if ( $this->use_js && ( is_singular() && 'item' == $item->post_mime_type ) ) {
2329 ?>
2330 <script type='text/javascript'>
2331 (function($) {
2332 uscesCart = {
2333 intoCart : function (post_id, sku) {
2334 var zaikonum = $("[id='zaikonum["+post_id+"]["+sku+"]']").val();
2335 var zaiko = $("[id='zaiko["+post_id+"]["+sku+"]']").val();
2336 if( <?php echo apply_filters( 'usces_intoCart_zaiko_check_js', "( uscesL10n.itemOrderAcceptable != '1' && zaiko != '0' && zaiko != '1' ) || ( uscesL10n.itemOrderAcceptable != '1' && parseInt(zaikonum) == 0 )" ); ?> ){
2337 alert('<?php _e( 'temporaly out of stock now', 'usces' ); ?>');
2338 return false;
2339 }
2340
2341 var mes = '';
2342 if( $("[id='quant["+post_id+"]["+sku+"]']").length ){
2343 var quant = $("[id='quant["+post_id+"]["+sku+"]']").val();
2344 if( quant == '0' || quant == '' || !(uscesCart.isNum(quant))){
2345 mes += "<?php _e( 'enter the correct amount', 'usces' ); ?>\n";
2346 }
2347 var checknum = '';
2348 var checkmode = '';
2349 if( parseInt(uscesL10n.itemRestriction) <= parseInt(zaikonum) && uscesL10n.itemRestriction != '' && uscesL10n.itemRestriction != '0' && zaikonum != '' ) {
2350 checknum = uscesL10n.itemRestriction;
2351 checkmode ='rest';
2352 } else if( uscesL10n.itemOrderAcceptable != '1' && parseInt(uscesL10n.itemRestriction) > parseInt(zaikonum) && uscesL10n.itemRestriction != '' && uscesL10n.itemRestriction != '0' && zaikonum != '' ) {
2353 checknum = zaikonum;
2354 checkmode ='zaiko';
2355 } else if( uscesL10n.itemOrderAcceptable != '1' && (uscesL10n.itemRestriction == '' || uscesL10n.itemRestriction == '0') && zaikonum != '' ) {
2356 checknum = zaikonum;
2357 checkmode ='zaiko';
2358 } else if( uscesL10n.itemRestriction != '' && uscesL10n.itemRestriction != '0' && ( zaikonum == '' || zaikonum == '0' || parseInt(uscesL10n.itemRestriction) > parseInt(zaikonum) ) ) {
2359 checknum = uscesL10n.itemRestriction;
2360 checkmode ='rest';
2361 }
2362
2363 if( parseInt(quant) > parseInt(checknum) && checknum != '' ){
2364 if(checkmode == 'rest'){
2365 mes += <?php _e( "'This article is limited by '+checknum+' at a time.'", 'usces' ); ?>+"\n";
2366 }else{
2367 mes += <?php _e( "'Stock is remainder '+checknum+'.'", 'usces' ); ?>+"\n";
2368 }
2369 }
2370 }
2371 for(i=0; i<uscesL10n.key_opts.length; i++){
2372 if( uscesL10n.opt_esse[i] == '1' ){
2373 var skuob = $("[id='itemOption["+post_id+"]["+sku+"]["+uscesL10n.key_opts[i]+"]']");
2374 var itemOption = "itemOption["+post_id+"]["+sku+"]["+uscesL10n.key_opts[i]+"]";
2375 var opt_obj_radio = $(":radio[name*='"+itemOption+"']");
2376 var opt_obj_checkbox = $(":checkbox[name*='"+itemOption+"']:checked");
2377
2378 if( uscesL10n.opt_means[i] == '3' ){
2379
2380 if( !opt_obj_radio.is(':checked') ){
2381 mes += uscesL10n.mes_opts[i]+"\n";
2382 }
2383
2384 }else if( uscesL10n.opt_means[i] == '4' ){
2385
2386 if( !opt_obj_checkbox.length ){
2387 mes += uscesL10n.mes_opts[i]+"\n";
2388 }
2389
2390 }else{
2391
2392 if( skuob.length ){
2393 if( uscesL10n.opt_means[i] == 0 && skuob.val() == '#NONE#' ){
2394 mes += uscesL10n.mes_opts[i]+"\n";
2395 }else if( uscesL10n.opt_means[i] == 1 && ( skuob.val() == '' || skuob.val() == '#NONE#' ) ){
2396 mes += uscesL10n.mes_opts[i]+"\n";
2397 }else if( uscesL10n.opt_means[i] >= 2 && skuob.val() == '' ){
2398 mes += uscesL10n.mes_opts[i]+"\n";
2399 }
2400 }
2401 }
2402 }
2403 }
2404
2405 <?php apply_filters( 'usces_filter_inCart_js_check', $item->ID ); // Unavailable. ?>
2406 <?php do_action( 'usces_action_inCart_js_check', $item->ID ); ?>
2407
2408 if( mes != '' ){
2409 alert( mes );
2410 return false;
2411 }else{
2412 <?php echo apply_filters( 'usces_filter_js_intoCart', "return true;\n", $item->ID, null ); ?>
2413 }
2414 },
2415
2416 isNum : function (num) {
2417 if (num.match(/[^0-9]/g)) {
2418 return false;
2419 }
2420 return true;
2421 }
2422 };
2423 })(jQuery);
2424 </script>
2425 <?php
2426 // If it's Product Details page.
2427 } elseif ( $this->use_js && ( is_page( USCES_CART_NUMBER ) || $this->is_cart_page( $_SERVER['REQUEST_URI'] ) ) ) {
2428 ?>
2429 <script type='text/javascript'>
2430 (function($) {
2431 uscesCart = {
2432 upCart : function () {
2433
2434 var zaikoob = $("input[name*='zaikonum']");
2435 var quantob = $("input[name*='quant']");
2436 var postidob = $("input[name*='itempostid']");
2437 var skuob = $("input[name*='itemsku']");
2438
2439 var zaikonum = '';
2440 var zaiko = '';
2441 var quant = '';
2442 var mes = '';
2443 var checknum = '';
2444 var post_id = '';
2445 var sku = '';
2446 var itemRestriction = '';
2447 var itemOrderAcceptable = '';
2448
2449 var ct = zaikoob.length;
2450 for(var i=0; i< ct; i++){
2451 post_id = postidob[i].value;
2452 sku = skuob[i].value;
2453 itemRestriction = $("input[name='itemRestriction\[" + i + "\]']").val();
2454 itemOrderAcceptable = $("input[name='itemOrderAcceptable\[" + i + "\]']").val();
2455 zaikonum = $("input[name='zaikonum\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").val();
2456
2457 quant = $("*[name='quant\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").val();
2458 if( $("*[name='quant\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").length ){
2459 if( quant == '0' || quant == '' || !(uscesCart.isNum(quant))){
2460 mes += <?php _e( "'enter the correct amount for the No.' + (i+1) + ' item'", 'usces' ); ?>+"\n";
2461 }
2462 var checknum = '';
2463 var checkmode = '';
2464 if( parseInt(itemRestriction) <= parseInt(zaikonum) && itemRestriction != '' && itemRestriction != '0' && zaikonum != '' ) {
2465 checknum = itemRestriction;
2466 checkmode ='rest';
2467 } else if( itemOrderAcceptable != '1' && parseInt(itemRestriction) > parseInt(zaikonum) && itemRestriction != '' && itemRestriction != '0' && zaikonum != '' ) {
2468 checknum = zaikonum;
2469 checkmode ='zaiko';
2470 } else if( itemOrderAcceptable != '1' && (itemRestriction == '' || itemRestriction == '0') && zaikonum != '' ) {
2471 checknum = zaikonum;
2472 checkmode ='zaiko';
2473 } else if( itemRestriction != '' && itemRestriction != '0' && ( zaikonum == '' || zaikonum == '0' || parseInt(itemRestriction) > parseInt(zaikonum) ) ) {
2474 checknum = itemRestriction;
2475 checkmode ='rest';
2476 }
2477 if( parseInt(quant) > parseInt(checknum) && checknum != '' ){
2478 if(checkmode == 'rest'){
2479 mes += <?php _e( "'This article is limited by '+checknum+' at a time for the No.' + (i+1) + ' item.'", 'usces' ); ?>+"\n";
2480 }else{
2481 mes += <?php _e( "'Stock of No.' + (i+1) + ' item is remainder '+checknum+'.'", 'usces' ); ?>+"\n";
2482 }
2483 }
2484 }
2485 }
2486
2487 <?php apply_filters( 'usces_filter_upCart_js_check', $item->ID ); // Unavailable. ?>
2488 <?php do_action( 'usces_action_upCart_js_check', $item->ID ); ?>
2489
2490 if( mes != '' ){
2491 alert( mes );
2492 return false;
2493 }else{
2494 <?php echo apply_filters( 'usces_filter_js_upCart', "return true;\n", $item->ID, null ); ?>
2495 }
2496 },
2497
2498 cartNext : function () {
2499
2500 var zaikoob = $("input[name*='zaikonum']");
2501 var quantob = $("input[name*='quant']");
2502 var postidob = $("input[name*='itempostid']");
2503 var skuob = $("input[name*='itemsku']");
2504
2505 var zaikonum = '';
2506 var zaiko = '';
2507 var quant = '';
2508 var mes = '';
2509 var checknum = '';
2510 var post_id = '';
2511 var sku = '';
2512 var itemRestriction = '';
2513 var itemOrderAcceptable = '';
2514
2515 var ct = zaikoob.length;
2516 for(var i=0; i< ct; i++){
2517 post_id = postidob[i].value;
2518 sku = skuob[i].value;
2519 itemRestriction = $("input[name='itemRestriction\[" + i + "\]']").val();
2520 itemOrderAcceptable = $("input[name='itemOrderAcceptable\[" + i + "\]']").val();
2521 zaikonum = $("input[name='zaikonum\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").val();
2522
2523 quant = $("*[name='quant\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").val();
2524 if( $("*[name='quant\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").length ){
2525 if( quant == '0' || quant == '' || !(uscesCart.isNum(quant))){
2526 mes += <?php _e( "'enter the correct amount for the No.' + (i+1) + ' item'", 'usces' ); ?>+"\n";
2527 }
2528 var checknum = '';
2529 var checkmode = '';
2530 if( parseInt(itemRestriction) <= parseInt(zaikonum) && itemRestriction != '' && itemRestriction != '0' && zaikonum != '' ) {
2531 checknum = itemRestriction;
2532 checkmode ='rest';
2533 } else if( itemOrderAcceptable != '1' && parseInt(itemRestriction) > parseInt(zaikonum) && itemRestriction != '' && itemRestriction != '0' && zaikonum != '' ) {
2534 checknum = zaikonum;
2535 checkmode ='zaiko';
2536 } else if( itemOrderAcceptable != '1' && (itemRestriction == '' || itemRestriction == '0') && zaikonum != '' ) {
2537 checknum = zaikonum;
2538 checkmode ='zaiko';
2539 } else if( itemRestriction != '' && itemRestriction != '0' && ( zaikonum == '' || zaikonum == '0' || parseInt(itemRestriction) > parseInt(zaikonum) ) ) {
2540 checknum = itemRestriction;
2541 checkmode ='rest';
2542 }
2543
2544 if( parseInt(quant) > parseInt(checknum) && checknum != '' ){
2545 if(checkmode == 'rest'){
2546 mes += <?php _e( "'This article is limited by '+checknum+' at a time for the No.' + (i+1) + ' item.'", 'usces' ); ?>+"\n";
2547 }else{
2548 mes += <?php _e( "'Stock of No.' + (i+1) + ' item is remainder '+checknum+'.'", 'usces' ); ?>+"\n";
2549 }
2550 }
2551 }
2552 }
2553
2554 <?php do_action( 'usces_action_nextCart_js_check', $item->ID ); ?>
2555
2556 if( mes != '' ){
2557 alert( mes );
2558 return false;
2559 }else{
2560 return true;
2561 }
2562 },
2563
2564 customerNext : function () {
2565 <?php do_action( 'usces_action_customerNext_js_check', $item->ID ); ?>
2566 },
2567
2568 customerPre : function () {
2569 <?php do_action( 'usces_action_customerPre_js_check', $item->ID ); ?>
2570 },
2571
2572 previousCart : function () {
2573 location.href = uscesL10n.previous_url;
2574 },
2575
2576 settings: {
2577 url: uscesL10n.ajaxurl,
2578 type: 'POST',
2579 cache: false
2580 },
2581
2582 changeStates : function( country ) {
2583 var s = this.settings;
2584 s.data = "action=change_states_ajax&country=" + country;
2585 $.ajax( s ).done(function(data, dataType){
2586
2587 if( 'error' == data ){
2588 alert('error');
2589 }else{
2590 $("select#pref").html( data );
2591 }
2592 }).fail(function(msg){
2593 alert("error");
2594 });
2595 return false;
2596 },
2597
2598 isNum : function (num) {
2599 if (num.match(/[^0-9]/g)) {
2600 return false;
2601 }
2602 return true;
2603 },
2604 purchase : 0
2605 };
2606 $("#country").change(function () {
2607 var country = $("#country option:selected").val();
2608 $("#newcharging_type option:selected").val()
2609 uscesCart.changeStates( country );
2610 });
2611 $("#purchase_form").submit(function () {
2612 if( 0 == uscesCart.purchase ){
2613 uscesCart.purchase = 1;
2614 return true;
2615 }else{
2616 $("#purchase_button").prop("disabled", true);
2617 $("#back_button").prop("disabled", true);
2618 return false;
2619 }
2620 });
2621
2622 })(jQuery);
2623 </script>
2624 <?php
2625 }
2626
2627 usces_states_form_js();
2628 $js = apply_filters( 'usces_filter_shop_foot_js', ob_get_contents() );
2629 ob_end_clean();
2630 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2631 echo $js;
2632 }
2633
2634 public function admin_head() {
2635 global $wp_version;
2636 $wcex_str = '';
2637 $wcex = usces_get_wcex();
2638 foreach ( (array) $wcex as $key => $values ) {
2639 $wcex_str .= "'" . esc_js( $key ) . '-' . esc_js( $values['version'] ) . "', ";
2640 }
2641 $wcex_str = rtrim( $wcex_str, ', ' );
2642 $theme_ob = wp_get_theme();
2643 if ( $theme_ob ) {
2644 $theme = array(
2645 'Name' => esc_js( $theme_ob->get( 'Name' ) ),
2646 'Version' => esc_js( $theme_ob->get( 'Version' ) ),
2647 );
2648 } else {
2649 $theme = array( 'Name' => '', 'Version' => '' );
2650 }
2651 $message = usces_get_admin_script_message();
2652 ?>
2653 <link href="<?php echo USCES_PLUGIN_URL; ?>/css/admin_style.css" rel="stylesheet" type="text/css" media="all" />
2654 <script type='text/javascript'>
2655 /* <![CDATA[ */
2656 uscesL10n = {
2657 <?php echo apply_filters( 'usces_filter_admin_uscesL10n', null ); ?>
2658 'requestFile': "<?php echo site_url(); ?>/wp-admin/admin-ajax.php",
2659 'USCES_PLUGIN_URL': "<?php echo USCES_PLUGIN_URL; ?>",
2660 'version': "<?php echo USCES_VERSION; ?>",
2661 'locale': '<?php echo get_locale(); ?>',
2662 'cart_number': "<?php echo get_option( 'usces_cart_number' ); ?>",
2663 'purchase_limit': "<?php echo esc_js( $this->options['purchase_limit'] ); ?>",
2664 'point_rate': "<?php echo esc_js( $this->options['point_rate'] ); ?>",
2665 'shipping_rule': "<?php echo esc_js( $this->options['shipping_rule'] ); ?>",
2666 'theme': "<?php echo esc_html( $theme['Name'] . '-' . $theme['Version'] ); ?>",
2667 'wcex': new Array( <?php wel_esc_script_e( $wcex_str ); ?> ),
2668 'message': new Array( <?php wel_esc_script_e( $message ); ?> ),
2669 'now_loading': "<?php _e( 'now loading', 'usces' ); ?>"
2670 };
2671 /* ]]> */
2672 </script>
2673 <script type='text/javascript' src='<?php echo USCES_PLUGIN_URL; ?>/js/usces_admin.js?ver=<?php echo USCES_VERSION; ?>'></script>
2674 <?php
2675 if ( 'edit' == $this->action_status || 'editpost' == $this->action_status ) {
2676 ?>
2677 <link rel='stylesheet' href='<?php echo site_url(); ?>/wp-includes/js/thickbox/thickbox.css' type='text/css' media='all' />
2678 <?php
2679 }
2680 if ( isset( $_REQUEST['page'] ) ) {
2681 switch ( $_REQUEST['page'] ) {
2682 case 'usces_initial':
2683 $cod_type = ( 'change' == $this->options['cod_type'] ) ? 'change' : 'fix';
2684 ?>
2685 <script type='text/javascript'>
2686 /* <![CDATA[ */
2687 usces_ini = {
2688 'cod_type': "<?php echo esc_js( $cod_type ); ?>",
2689 'cod_type_fix': "<?php echo esc_js( __( 'Fixation C.O.D.', 'usces' ) ); ?>",
2690 'cod_type_change': "<?php echo esc_js( __( 'Variable C.O.D.', 'usces' ) ); ?>",
2691 'cod_unit': "<?php echo esc_js( __( 'dollars', 'usces' ) ); ?>",
2692 'cod_failure': "<?php echo esc_js( __( 'failure in update', 'usces' ) ); ?>",
2693 'cod_updated': "<?php echo esc_js( __( 'options are updated', 'usces' ) ); ?>",
2694 'cod_limit': "<?php echo esc_js( __( 'A value of the amount of upper limit is incorrect.', 'usces' ) ); ?>",
2695 'cod_label_close': "<?php echo esc_js( __( 'Close', 'usces' ) ); ?>",
2696 'cod_label_update': "<?php echo esc_js( __( 'Update', 'usces' ) ); ?>"
2697 };
2698 /* ]]> */
2699 </script>
2700 <?php
2701 break;
2702 case 'usces_itemnew':
2703 case 'usces_itemedit':
2704 ?>
2705 <style type="text/css">
2706 <!--
2707 #usces_mess {
2708 color: #FF0000;
2709 font-weight: bold;
2710 }
2711 -->
2712 </style>
2713 <?php
2714 break;
2715 }
2716 }
2717
2718 if ( is_admin() && ( ( isset( $_GET['order_action'] ) && 'newpost' == $_GET['order_action'] )
2719 || ( isset( $_GET['page'] ) && 'usces_ordernew' == $_GET['page'] )
2720 || ( isset( $_GET['order_action'] ) && 'edit' == $_GET['order_action'] )
2721 || ( isset( $_GET['order_action'] ) && 'editpost' == $_GET['order_action'] )
2722 || ( isset( $_GET['page'] ) && 'usces_membernew' == $_GET['page'] )
2723 || ( isset( $_GET['member_action'] ) && 'edit' == $_GET['member_action'] )
2724 || ( isset( $_GET['member_action'] ) && 'editpost' == $_GET['member_action'] ) ) ) :
2725 switch ( $_GET['page'] ) {
2726 case 'usces_ordernew':
2727 case 'usces_orderlist':
2728 $admin_page = 'order';
2729 break;
2730 case 'usces_membernew':
2731 case 'usces_memberlist':
2732 $admin_page = 'member';
2733 break;
2734 }
2735 ?>
2736 <script type='text/javascript'>
2737 jQuery(function($) {
2738 uscesForm = {
2739 settings: {
2740 url: uscesL10n.requestFile,
2741 type: 'POST',
2742 cache: false
2743 },
2744
2745 changeStates : function( country, type ) {
2746 var s = this.settings;
2747 s.data = "action=change_states_ajax&country=" + country;
2748 $.ajax( s ).done(function(data, dataType){
2749 if( 'error' == data ){
2750 alert('error');
2751 }else{
2752 $("select#" + type + "_pref").html( data );
2753 if( customercountry == country && 'customer' == type ){
2754 $("#" + type + "_pref").prop({selectedIndex:customerstate});
2755 }else if( deliverycountry == country && 'delivery' == type ){
2756 $("#" + type + "_pref").prop({selectedIndex:deliverystate});
2757 }else if( customercountry == country && 'member' == type ){
2758 $("#" + type + "_pref").prop({selectedIndex:customerstate});
2759 }
2760 }
2761 }).fail(function(msg){
2762 alert("error");
2763 });
2764 return false;
2765 },
2766
2767 isNum : function (num) {
2768 if (num.match(/[^0-9]/g)) {
2769 return false;
2770 }
2771 return true;
2772 }
2773 };
2774 <?php
2775 if ( 'order' == $admin_page ) {
2776 ?>
2777 if( undefined != $("#customer_pref").get(0) && undefined != $("#delivery_country").get(0) ) {
2778 var customerstate = $("#customer_pref").get(0).selectedIndex;
2779 var customercountry = $("#customer_country").val();
2780 var deliverystate = $("#delivery_pref").get(0).selectedIndex;
2781 var deliverycountry = $("#delivery_country").val();
2782
2783 $("#customer_country").change(function () {
2784 var country = $("#customer_country option:selected").val();
2785 uscesForm.changeStates( country, 'customer' );
2786 });
2787 $("#delivery_country").change(function () {
2788 var country = $("#delivery_country option:selected").val();
2789 uscesForm.changeStates( country, 'delivery' );
2790 });
2791 }
2792 <?php
2793 } elseif ( 'member' == $admin_page ) {
2794 ?>
2795 if( undefined != $("#member_pref").get(0) ) {
2796 var customerstate = $("#member_pref").get(0).selectedIndex;
2797 var customercountry = $("#member_country").val();
2798 var deliverystate = '';
2799 var deliverycountry = '';
2800
2801 $("#member_country").change(function () {
2802 var country = $("#member_country option:selected").val();
2803 uscesForm.changeStates( country, 'member' );
2804 });
2805 }
2806 <?php
2807 }
2808 ?>
2809 });
2810 </script>
2811 <?php
2812 endif;
2813 }
2814
2815 /**
2816 * Main Process.
2817 */
2818 public function main() {
2819 global $wpdb, $wp_locale, $wp_version, $post_ID;
2820 global $wp_query, $usces_action, $post, $action, $editing;
2821
2822 update_option( 'usces_shipping_rule', apply_filters( 'usces_filter_shipping_rule', get_option( 'usces_shipping_rule' ) ) );
2823 $this->shipping_rule = get_option( 'usces_shipping_rule' );
2824
2825 if ( ! is_admin() ) {
2826 $this->usces_cookie();
2827 } else {
2828 $this->user_level = usces_get_admin_user_level();
2829 }
2830 $this->make_url();
2831
2832 add_filter( 'cron_schedules', 'usces_schedules_intervals' );
2833 add_action( 'wp', 'usces_wevent' );
2834 do_action( 'usces_main' );
2835 $this->update_table();
2836
2837 require_once USCES_PLUGIN_DIR . '/classes/cart.class.php';
2838 $this->cart = new usces_cart();
2839
2840 do_action( 'usces_after_cart_instant' );
2841
2842 if ( isset( $_REQUEST['page'] ) && 'usces_itemedit' == $_REQUEST['page'] && isset( $_REQUEST['action'] ) && 'duplicate' == $_REQUEST['action'] ) {
2843 $post_id = (int) $_GET['post'];
2844 $new_id = usces_item_duplicate( $post_id );
2845 $ref = isset( $_REQUEST['usces_referer'] ) ? urlencode( esc_url( $_REQUEST['usces_referer'] ) ) : '';
2846 $url = USCES_ADMIN_URL . '?page=usces_itemedit&action=edit&post=' . $new_id . '&usces_referer=' . $ref;
2847 wp_redirect( $url );
2848 exit;
2849 } elseif ( isset( $_REQUEST['page'] ) && 'usces_itemedit' == $_REQUEST['page'] && isset( $_REQUEST['action'] ) && 'itemcsv' == $_REQUEST['action'] ) {
2850 // $filename = usces_item_uploadcsv();
2851 // $mode = ( isset( $_REQUEST['upload_mode'] ) ) ? $_REQUEST['upload_mode'] : 'all';
2852 // $url = USCES_ADMIN_URL . '?page=usces_itemedit&usces_status=none&usces_message=&action=upload_register&mode=' . $mode . '&regfile=' . $filename;
2853 // wp_redirect( $url );
2854 // exit;
2855 }
2856
2857 $this->ad_controller();
2858
2859 if ( isset( $_GET['page'] ) && 'usces_itemnew' == $_GET['page'] ) {
2860 $itemnew = 'new';
2861 } else {
2862 $itemnew = '';
2863 }
2864
2865 wp_enqueue_script( 'jquery' );
2866
2867 if ( is_admin() && isset( $_REQUEST['page'] ) && ( ( isset( $_REQUEST['action'] ) && 'edit' == $_REQUEST['action'] ) || 'new' == $itemnew || ( isset( $_REQUEST['action'] ) && 'editpost' == $_REQUEST['action'] ) ) ) {
2868
2869 if ( isset( $_REQUEST['action'] ) && 'editpost' != $_REQUEST['action'] && 'new' == $itemnew ) {
2870 if ( version_compare( $wp_version, '3.0-beta', '>' ) ) {
2871 if ( ! isset( $_GET['post_type'] ) ) {
2872 $post_type = 'post';
2873 } elseif ( in_array( $_GET['post_type'], get_post_types( array( 'public' => true ) ) ) ) {
2874 $post_type = $_GET['post_type'];
2875 } else {
2876 wp_die( __( 'Invalid post type' ) );
2877 }
2878 $post_type_object = get_post_type_object( $post_type );
2879 $editing = true;
2880 $post = $this->get_default_post_to_edit30( $post_type, true );
2881 $post_ID = $post->ID;
2882 } else {
2883 $post = $this->get_default_post_to_edit();
2884 }
2885 } else {
2886 if ( version_compare( $wp_version, '3.0-beta', '>' ) ) {
2887 if ( isset( $_GET['post'] ) ) {
2888 $post_id = (int) $_GET['post'];
2889 } elseif ( isset( $_POST['post_ID'] ) ) {
2890 $post_id = (int) $_POST['post_ID'];
2891 } else {
2892 $post_id = 0;
2893 }
2894 $post_ID = $post_id;
2895 $post = null;
2896 $post_type_object = null;
2897 $post_type = null;
2898 if ( $post_id ) {
2899 $product = wel_get_product( $post_id );
2900 $post = $product['_pst'];
2901 if ( $post ) {
2902 $post_type_object = get_post_type_object( $post->post_type );
2903 if ( $post_type_object ) {
2904 $post_type = $post->post_type;
2905 if ( ! isset( $current_screen ) ) {
2906 $current_screen = new stdClass();
2907 }
2908 $current_screen->post_type = $post->post_type;
2909 $current_screen->id = $current_screen->post_type;
2910 }
2911 }
2912 } elseif ( isset( $_POST['post_type'] ) ) {
2913 $post_type_object = get_post_type_object( $_POST['post_type'] );
2914 if ( $post_type_object ) {
2915 $post_type = $post_type_object->name;
2916 $current_screen->post_type = $post_type;
2917 $current_screen->id = $current_screen->post_type;
2918 }
2919 }
2920 } else {
2921 if ( isset( $_GET['post'] ) ) {
2922 $post_ID = (int) $_GET['post'];
2923 $product = wel_get_product( $post_ID );
2924 $post = $product['_pst'];
2925 } else {
2926 $post_ID = isset( $_REQUEST['post_ID'] ) ? (int) $_REQUEST['post_ID'] : 0;
2927 if ( ! empty( $post_ID ) ) {
2928 $product = wel_get_product( $post_ID );
2929 $post = $product['_pst'];
2930 }
2931 }
2932 }
2933 }
2934
2935 $editing = true;
2936 wp_enqueue_script( 'autosave' );
2937 wp_enqueue_script( 'post' );
2938 add_thickbox();
2939 wp_enqueue_script( 'media-upload' );
2940 wp_enqueue_script( 'word-count' );
2941 wp_enqueue_script( 'admin-comments' );
2942
2943 if ( version_compare( $wp_version, '3.3', '<' ) ) {
2944 add_action( 'admin_print_footer_scripts', 'wp_tiny_mce', 25 );
2945 }
2946 wp_enqueue_script( 'quicktags' );
2947 }
2948
2949 if ( is_admin() && isset( $_REQUEST['page'] ) ) {
2950
2951 wp_enqueue_script( 'jquery-color' );
2952
2953 switch ( $_REQUEST['page'] ) {
2954 case 'usces_initial':
2955 $js = USCES_FRONT_PLUGIN_URL . '/js/usces_initial.js';
2956 wp_enqueue_script( 'usces_initial.js', $js, array( 'jquery-ui-dialog', 'jquery-ui-sortable' ) );
2957 break;
2958 case 'usces_settlement':
2959 wp_enqueue_script( 'jquery-ui-tabs', array( 'jquery-ui-core' ) );
2960 $jquery_cookie_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/jquery-cookie.js';
2961 wp_enqueue_script( 'jquery-cookie', $jquery_cookie_url, array( 'jquery' ) );
2962 $jquery_color_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/color/jscolor.js';
2963 wp_enqueue_script( 'jquery-jscolor', $jquery_color_url, array( 'jquery-color' ) );
2964 wp_enqueue_script( 'jquery-ui-sortable' );
2965 wp_enqueue_script( 'jquery-ui-dialog' );
2966 break;
2967 case 'usces_cart':
2968 wp_enqueue_script( 'jquery-ui-tabs', array( 'jquery-ui-core' ) );
2969 $jquery_cookie_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/jquery-cookie.js';
2970 wp_enqueue_script( 'jquery-cookie', $jquery_cookie_url, array( 'jquery' ) );
2971 break;
2972 case 'usces_member':
2973 wp_enqueue_script( 'jquery-ui-tabs', array( 'jquery-ui-core' ) );
2974 $jquery_cookie_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/jquery-cookie.js';
2975 wp_enqueue_script( 'jquery-cookie', $jquery_cookie_url, array( 'jquery' ) );
2976 break;
2977 case 'usces_orderlist':
2978 case 'usces_ordernew':
2979 wp_enqueue_script( 'jquery-ui-datepicker' );
2980 wp_enqueue_script( 'jquery-ui-dialog' );
2981 break;
2982 case 'usces_memberlist':
2983 wp_enqueue_script( 'jquery-ui-dialog' );
2984 break;
2985 case 'usces_itemnew':
2986 wp_enqueue_script( 'jquery-ui-sortable' );
2987 break;
2988 case 'usces_itemedit':
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 if ( isset( $_REQUEST['action'] ) && 'upload_register' == $_REQUEST['action'] ) {
2992 // $upload_registerUrl = USCES_FRONT_PLUGIN_URL . '/js/usces-item-upload.js';
2993 // wp_enqueue_script( 'upload_register', $upload_registerUrl, array( 'jquery' ), USCES_VERSION, true );
2994 // @ob_end_clean();
2995 // ob_start();
2996 } else {
2997 wp_enqueue_script( 'jquery-ui-sortable' );
2998 wp_enqueue_script( 'jquery-ui-dialog' );
2999 }
3000 break;
3001 case 'usces_delivery':
3002 wp_enqueue_script( 'jquery-ui-tabs', array( 'jquery-ui-core' ) );
3003 $jquery_cookie_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/jquery-cookie.js';
3004 wp_enqueue_script( 'jquery-cookie', $jquery_cookie_url, array( 'jquery' ) );
3005 break;
3006 case 'usces_system':
3007 wp_enqueue_script( 'jquery-ui-tabs', array( 'jquery-ui-core' ) );
3008 $jquery_cookie_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/jquery-cookie.js';
3009 wp_enqueue_script( 'jquery-cookie', $jquery_cookie_url, array( 'jquery' ) );
3010 break;
3011 case 'usces_mail':
3012 wp_enqueue_script( 'jquery-ui-tabs', array( 'jquery-ui-core' ) );
3013 $jquery_cookie_url = USCES_FRONT_PLUGIN_URL . '/js/jquery/jquery-cookie.js';
3014 wp_enqueue_script( 'jquery-cookie', $jquery_cookie_url, array( 'jquery' ) );
3015 break;
3016 }
3017 }
3018
3019 if ( isset( $_REQUEST['order_action'] ) && 'pdfout' == $_REQUEST['order_action'] ) {
3020 check_admin_referer( 'order_edit', 'wc_nonce' );
3021
3022 $oid = filter_input( INPUT_GET, 'order_id' );
3023 if ( ! is_user_logged_in() ) {
3024 $this->get_current_member();
3025 $mid = $this->current_member['id'];
3026 if ( 0 === (int) $mid || ! $this->is_order( $mid, $oid ) ) {
3027 die( 'No permission' );
3028 }
3029 }
3030 if ( ( isset( $this->options['tax_display'] ) && 'activate' == $this->options['tax_display'] ) && usces_is_reduced_taxrate( $oid ) ) {
3031 require_once( apply_filters( 'usces_filter_orderpdf_path_ex', USCES_PLUGIN_DIR . '/includes/order_print_ex.php' ) );
3032 } else {
3033 require_once( apply_filters( 'usces_filter_orderpdf_path', USCES_PLUGIN_DIR . '/includes/order_print.php' ) );
3034 }
3035 }
3036
3037 if ( ! empty( $this->settlement_notice ) &&
3038 ( 1 === (int) $this->options['system']['settlement_notice'] || defined( 'WCEX_DLSELLER' ) || defined( 'WCEX_AUTO_DELIVERY' ) ) ) {
3039 add_action( 'admin_notices', 'usces_display_settlement_notice' );
3040 }
3041
3042 do_action( 'usces_after_main' );
3043 }
3044
3045 public function stripslashes_deep_post( $array ) {
3046 $res = array();
3047 foreach ( $array as $key => $value ) {
3048 $key = stripslashes( $key );
3049 if ( is_array( $value ) ) {
3050 $value = $this->stripslashes_deep_post( $value );
3051 } else {
3052 $value = is_null( $value ) ? $value : usces_erase_emoji( stripslashes( $value ) );
3053 }
3054 $res[ $key ] = $value;
3055 }
3056 return $res;
3057 }
3058
3059 public function make_url() {
3060 $permalink_structure = get_option( 'permalink_structure' );
3061 if ( $this->use_ssl ) {
3062 if ( $permalink_structure ) {
3063 $this->delim = '&';
3064 $home_perse = parse_url( get_option( 'home' ) );
3065 $home_perse_path = isset( $home_perse['path'] ) ? $home_perse['path'] : '';
3066 $home_path = $home_perse['host'] . $home_perse_path;
3067 $ssl_perse = parse_url( $this->options['ssl_url'] );
3068 $ssl_perse_path = isset( $ssl_perse['path'] ) ? $ssl_perse['path'] : '';
3069 $ssl_path = $ssl_perse['host'] . $ssl_perse_path;
3070 if ( $home_perse_path != $ssl_perse_path ) {
3071 if ( ! defined( 'USCES_CUSTOMER_URL' ) ) {
3072 define( 'USCES_CUSTOMER_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_CART_NUMBER . '&customerinfo=1' );
3073 }
3074 if ( ! defined( 'USCES_CART_URL' ) ) {
3075 define( 'USCES_CART_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_CART_NUMBER );
3076 }
3077 if ( ! defined( 'USCES_LOSTMEMBERPASSWORD_URL' ) ) {
3078 define( 'USCES_LOSTMEMBERPASSWORD_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=lostmemberpassword' );
3079 }
3080 if ( ! defined( 'USCES_NEWMEMBER_URL' ) ) {
3081 define( 'USCES_NEWMEMBER_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=newmember' );
3082 }
3083 if ( ! defined( 'USCES_LOGIN_URL' ) ) {
3084 define( 'USCES_LOGIN_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=login' );
3085 }
3086 if ( ! defined( 'USCES_LOGOUT_URL' ) ) {
3087 define( 'USCES_LOGOUT_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=logout' );
3088 }
3089 if ( ! defined( 'USCES_MEMBER_URL' ) ) {
3090 define( 'USCES_MEMBER_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_MEMBER_NUMBER );
3091 }
3092 $inquiry_url = empty( $this->options['inquiry_id'] ) ? '' : $this->options['ssl_url'] . '/index.php?page_id=' . $this->options['inquiry_id'];
3093 if ( ! defined( 'USCES_INQUIRY_URL' ) ) {
3094 define( 'USCES_INQUIRY_URL', $inquiry_url );
3095 }
3096 if ( ! defined( 'USCES_CART_NONSESSION_URL' ) ) {
3097 define( 'USCES_CART_NONSESSION_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_CART_NUMBER );
3098 }
3099 if ( ! defined( 'USCES_PAYPAL_NOTIFY_URL' ) ) {
3100 define( 'USCES_PAYPAL_NOTIFY_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_CART_NUMBER . '&acting=paypal_ipn' );
3101 }
3102 } else {
3103 $ssl_plink_cart = str_replace( 'http://','https://', str_replace( $home_path, $ssl_path, get_page_link( USCES_CART_NUMBER ) ) );
3104 $ssl_plink_member = str_replace( 'http://','https://', str_replace( $home_path, $ssl_path, get_page_link( USCES_MEMBER_NUMBER ) ) );
3105 if ( ! defined( 'USCES_CUSTOMER_URL' ) ) {
3106 define( 'USCES_CUSTOMER_URL', $ssl_plink_cart . '?customerinfo=1' );
3107 }
3108 if ( ! defined( 'USCES_CART_URL' ) ) {
3109 define( 'USCES_CART_URL', $ssl_plink_cart );
3110 }
3111 if ( ! defined( 'USCES_LOSTMEMBERPASSWORD_URL' ) ) {
3112 define( 'USCES_LOSTMEMBERPASSWORD_URL', $ssl_plink_member . '?usces_page=lostmemberpassword' );
3113 }
3114 if ( ! defined( 'USCES_NEWMEMBER_URL' ) ) {
3115 define( 'USCES_NEWMEMBER_URL', $ssl_plink_member . '?usces_page=newmember' );
3116 }
3117 if ( ! defined( 'USCES_LOGIN_URL' ) ) {
3118 define( 'USCES_LOGIN_URL', $ssl_plink_member . '?usces_page=login' );
3119 }
3120 if ( ! defined( 'USCES_LOGOUT_URL' ) ) {
3121 define( 'USCES_LOGOUT_URL', $ssl_plink_member . '?usces_page=logout' );
3122 }
3123 if ( ! defined( 'USCES_MEMBER_URL' ) ) {
3124 define( 'USCES_MEMBER_URL', $ssl_plink_member );
3125 }
3126 if ( ! isset( $this->options['inquiry_id'] ) || ! ( (int) $this->options['inquiry_id'] ) ) {
3127 $inquiry_url = get_home_url();
3128 } else {
3129 $ssl_plink_inquiry = str_replace( 'http://', 'https://', str_replace( $home_path, $ssl_path, get_page_link( $this->options['inquiry_id'] ) ) );
3130 $inquiry_url = empty( $this->options['inquiry_id'] ) ? '' : $ssl_plink_inquiry;
3131 }
3132 if ( ! defined( 'USCES_INQUIRY_URL' ) ) {
3133 define( 'USCES_INQUIRY_URL', $inquiry_url );
3134 }
3135 if ( ! defined( 'USCES_CART_NONSESSION_URL' ) ) {
3136 define( 'USCES_CART_NONSESSION_URL', $ssl_plink_cart );
3137 }
3138 if ( ! defined( 'USCES_PAYPAL_NOTIFY_URL' ) ) {
3139 define( 'USCES_PAYPAL_NOTIFY_URL', $ssl_plink_cart . '?acting=paypal_ipn' );
3140 }
3141 }
3142 } else {
3143 $this->delim = '&';
3144 if ( ! defined( 'USCES_CUSTOMER_URL' ) ) {
3145 define( 'USCES_CUSTOMER_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_CART_NUMBER . '&customerinfo=1' );
3146 }
3147 if ( ! defined( 'USCES_CART_URL' ) ) {
3148 define( 'USCES_CART_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_CART_NUMBER );
3149 }
3150 if ( ! defined( 'USCES_LOSTMEMBERPASSWORD_URL' ) ) {
3151 define( 'USCES_LOSTMEMBERPASSWORD_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=lostmemberpassword' );
3152 }
3153 if ( ! defined( 'USCES_NEWMEMBER_URL' ) ) {
3154 define( 'USCES_NEWMEMBER_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=newmember' );
3155 }
3156 if ( ! defined( 'USCES_LOGIN_URL' ) ) {
3157 define( 'USCES_LOGIN_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=login' );
3158 }
3159 if ( ! defined( 'USCES_LOGOUT_URL' ) ) {
3160 define( 'USCES_LOGOUT_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=logout' );
3161 }
3162 if ( ! defined( 'USCES_MEMBER_URL' ) ) {
3163 define( 'USCES_MEMBER_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_MEMBER_NUMBER );
3164 }
3165 $inquiry_url = empty( $this->options['inquiry_id'] ) ? '' : $this->options['ssl_url'] . '/?page_id=' . $this->options['inquiry_id'];
3166 if ( ! defined( 'USCES_INQUIRY_URL' ) ) {
3167 define( 'USCES_INQUIRY_URL', $inquiry_url );
3168 }
3169 if ( ! defined( 'USCES_CART_NONSESSION_URL' ) ) {
3170 define( 'USCES_CART_NONSESSION_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_CART_NUMBER );
3171 }
3172 if ( ! defined( 'USCES_PAYPAL_NOTIFY_URL' ) ) {
3173 define( 'USCES_PAYPAL_NOTIFY_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_CART_NUMBER . '&acting=paypal_ipn' );
3174 }
3175 }
3176 if ( ! is_admin() ) {
3177 add_filter( 'home_url', array( $this, 'usces_ssl_page_link' ) );
3178 add_filter( 'wp_get_attachment_url', array( $this, 'usces_ssl_attachment_link' ) );
3179 add_filter( 'icon_dir_uri', array( $this, 'usces_ssl_icon_dir_uri' ) );
3180 add_filter( 'stylesheet_directory_uri', array( $this, 'usces_ssl_contents_link' ) );
3181 add_filter( 'template_directory_uri', array( $this, 'usces_ssl_contents_link' ) );
3182 add_filter( 'script_loader_src', array( $this, 'usces_ssl_script_link' ) );
3183 add_filter( 'style_loader_src', array( $this, 'usces_ssl_script_link' ) );
3184 }
3185 } else {
3186 if ( $permalink_structure ) {
3187 $this->delim = '?';
3188 if ( ! defined( 'USCES_CUSTOMER_URL' ) ) {
3189 define( 'USCES_CUSTOMER_URL', get_page_link( USCES_CART_NUMBER ) . '?customerinfo=1' );
3190 }
3191 if ( ! defined( 'USCES_CART_URL' ) ) {
3192 define( 'USCES_CART_URL', get_page_link( USCES_CART_NUMBER ) );
3193 }
3194 if ( ! defined( 'USCES_LOSTMEMBERPASSWORD_URL' ) ) {
3195 define( 'USCES_LOSTMEMBERPASSWORD_URL', get_page_link( USCES_MEMBER_NUMBER ) . '?usces_page=lostmemberpassword' );
3196 }
3197 if ( ! defined( 'USCES_NEWMEMBER_URL' ) ) {
3198 define( 'USCES_NEWMEMBER_URL', get_page_link( USCES_MEMBER_NUMBER ) . '?usces_page=newmember' );
3199 }
3200 if ( ! defined( 'USCES_LOGIN_URL' ) ) {
3201 define( 'USCES_LOGIN_URL', get_page_link( USCES_MEMBER_NUMBER ) . '?usces_page=login' );
3202 }
3203 if ( ! defined( 'USCES_LOGOUT_URL' ) ) {
3204 define( 'USCES_LOGOUT_URL', get_page_link( USCES_MEMBER_NUMBER ) . '?usces_page=logout' );
3205 }
3206 if ( ! defined( 'USCES_MEMBER_URL' ) ) {
3207 define( 'USCES_MEMBER_URL', get_page_link( USCES_MEMBER_NUMBER ) );
3208 }
3209 $inquiry_url = ( ! isset( $this->options['inquiry_id'] ) || ! ( (int) $this->options['inquiry_id'] ) ) ? get_home_url() : get_page_link( $this->options['inquiry_id'] );
3210 if ( ! defined( 'USCES_INQUIRY_URL' ) ) {
3211 define( 'USCES_INQUIRY_URL', $inquiry_url );
3212 }
3213 if ( ! defined( 'USCES_CART_NONSESSION_URL' ) ) {
3214 define( 'USCES_CART_NONSESSION_URL', get_page_link( USCES_CART_NUMBER ) );
3215 }
3216 if ( ! defined( 'USCES_PAYPAL_NOTIFY_URL' ) ) {
3217 define( 'USCES_PAYPAL_NOTIFY_URL', get_page_link( USCES_CART_NUMBER ) . '?acting=paypal_ipn' );
3218 }
3219 } else {
3220 $this->delim = '&';
3221 if ( ! defined( 'USCES_CUSTOMER_URL' ) ) {
3222 define( 'USCES_CUSTOMER_URL', get_option( 'home' ) . '/?page_id=' . USCES_CART_NUMBER . '&customerinfo=1' );
3223 }
3224 if ( ! defined( 'USCES_CART_URL' ) ) {
3225 define( 'USCES_CART_URL', get_option( 'home' ) . '/?page_id=' . USCES_CART_NUMBER );
3226 }
3227 if ( ! defined( 'USCES_LOSTMEMBERPASSWORD_URL' ) ) {
3228 define( 'USCES_LOSTMEMBERPASSWORD_URL', get_option( 'home' ) . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=lostmemberpassword' );
3229 }
3230 if ( ! defined( 'USCES_NEWMEMBER_URL' ) ) {
3231 define( 'USCES_NEWMEMBER_URL', get_option( 'home' ) . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=newmember' );
3232 }
3233 if ( ! defined( 'USCES_LOGIN_URL' ) ) {
3234 define( 'USCES_LOGIN_URL', get_option( 'home' ) . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=login' );
3235 }
3236 if ( ! defined( 'USCES_LOGOUT_URL' ) ) {
3237 define( 'USCES_LOGOUT_URL', get_option( 'home' ) . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=logout' );
3238 }
3239 if ( ! defined( 'USCES_CART_NONSESSION_URL' ) ) {
3240 define( 'USCES_CART_NONSESSION_URL', get_option( 'home' ) . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces_page=logout' );
3241 }
3242 if ( ! defined( 'USCES_MEMBER_URL' ) ) {
3243 define( 'USCES_MEMBER_URL', get_option( 'home' ) . '/?page_id=' . USCES_MEMBER_NUMBER );
3244 }
3245 $inquiry_url = empty( $this->options['inquiry_id'] ) ? '' : get_option( 'home' ) . '/?page_id=' . $this->options['inquiry_id'];
3246 if ( ! defined( 'USCES_INQUIRY_URL' ) ) {
3247 define( 'USCES_INQUIRY_URL', $inquiry_url );
3248 }
3249 if ( ! defined( 'USCES_CART_NONSESSION_URL' ) ) {
3250 define( 'USCES_CART_NONSESSION_URL', get_option( 'home' ) . '/?page_id=' . USCES_CART_NUMBER );
3251 }
3252 if ( ! defined( 'USCES_PAYPAL_NOTIFY_URL' ) ) {
3253 define( 'USCES_PAYPAL_NOTIFY_URL', get_option( 'home' ) . '/?page_id=' . USCES_CART_NUMBER . '&acting=paypal_ipn' );
3254 }
3255 }
3256 }
3257 }
3258
3259 public function regist_action() {
3260 usces_register_action( 'inCart', 'post', 'inCart', null, 'inCart' );
3261 usces_register_action( 'upButton', 'post', 'upButton', null, 'upButton' );
3262 usces_register_action( 'delButton', 'post', 'delButton', null, 'delButton' );
3263 usces_register_action( 'backCart', 'post', 'backCart', null, 'backCart' );
3264 usces_register_action( 'customerinfo', 'request', 'customerinfo', null, 'customerinfo' );
3265 usces_register_action( 'backCustomer', 'post', 'backCustomer', null, 'backCustomer' );
3266 usces_register_action( 'customerlogin', 'post', 'customerlogin', null, 'customerlogin' );
3267 usces_register_action( 'reganddeliveryinfo', 'post', 'reganddeliveryinfo', null, 'reganddeliveryinfo' );
3268 usces_register_action( 'deliveryinfo', 'post', 'deliveryinfo', null, 'deliveryinfo' );
3269 usces_register_action( 'backDelivery', 'request', 'backDelivery', null, 'backDelivery' );
3270 usces_register_action( 'confirm', 'request', 'confirm', null, 'confirm' );
3271 usces_register_action( 'use_point', 'post', 'use_point', null, 'use_point' );
3272 usces_register_action( 'backConfirm', 'post', 'backConfirm', null, 'backConfirm' );
3273 usces_register_action( 'purchase', 'request', 'purchase', null, 'purchase' );
3274 usces_register_action( 'acting_return', 'request', 'acting_return', null, 'acting_return' );
3275 usces_register_action( 'settlement_epsilon', 'request', 'settlement', 'epsilon', 'settlement_epsilon' );
3276 usces_register_action( 'inquiry_button', 'post', 'inquiry_button', null, 'inquiry_button' );
3277 usces_register_action( 'member_login', 'request', 'member_login', null, 'member_login_page' );
3278 usces_register_action( 'regmember', 'request', 'regmember', null, 'regmember' );
3279 usces_register_action( 'editmember', 'request', 'editmember', null, 'editmember' );
3280 usces_register_action( 'deletemember', 'request', 'deletemember', null, 'deletemember' );
3281 usces_register_action( 'page_login', 'get', 'usces_page', 'login', 'member_login_page' );
3282 usces_register_action( 'page_logout', 'get', 'usces_page', 'logout', 'page_logout' );
3283 usces_register_action( 'page_lostmemberpassword', 'get', 'usces_page', 'lostmemberpassword', 'page_lostmemberpassword' );
3284 usces_register_action( 'lostpassword', 'request', 'lostpassword', null, 'lostpassword' );
3285 usces_register_action( 'uscesmode_changepassword', 'request', 'uscesmode', 'changepassword', 'uscesmode_changepassword' );
3286 usces_register_action( 'changepassword', 'request', 'changepassword', null, 'changepassword_page' );
3287 usces_register_action( 'page_newmember', 'get', 'usces_page', 'newmember', 'page_newmember' );
3288 usces_register_action( 'page_search_item', 'get', 'usces_page', 'search_item', 'page_search_item' );
3289 usces_register_action( 'front_ajax', 'post', 'usces_ajax_action', null, 'front_ajax' );
3290 }
3291
3292 public function ad_controller() {
3293 global $usces_action;
3294 ksort( $usces_action );
3295 if ( $this->is_maintenance() && ! is_user_logged_in() ) {
3296 $this->maintenance();
3297 } else {
3298 $action_array = array(
3299 'inCart', 'upButton', 'delButton', 'backCart', 'customerinfo', 'backCustomer',
3300 'customerlogin', 'reganddeliveryinfo', 'deliveryinfo', 'backDelivery', 'confirm', 'use_point',
3301 'backConfirm', 'purchase', 'acting_return', 'settlement_epsilon', 'inquiry_button', 'member_login',
3302 'regmember', 'editmember', 'deletemember', 'page_login', 'page_logout', 'page_lostmemberpassword', 'lostpassword',
3303 'uscesmode_changepassword', 'changepassword', 'page_newmember',
3304 'page_search_item', 'front_ajax',
3305 );
3306
3307 $action_array = apply_filters( 'usces_filter_action_array', $action_array );
3308
3309 $flg = 0;
3310 $res = true;
3311 foreach ( $usces_action as $handle => $action ) {
3312 extract( $action );
3313 switch ( $type ) {
3314 case 'post':
3315 if ( empty( $value ) ) {
3316 if ( isset( $_POST[ $key ] ) ) {
3317 if ( in_array( $handle, $action_array ) ) {
3318 $res = call_user_func( array( $this, $function ) );
3319 } else {
3320 $res = call_user_func( $function );
3321 }
3322 $flg = 1;
3323 }
3324 } else {
3325 if ( isset( $_POST[ $key ] ) && $_POST[ $key ] == $value ) {
3326 if ( in_array( $handle, $action_array ) ) {
3327 $res = call_user_func( array( $this, $function ) );
3328 } else {
3329 $res = call_user_func( $function );
3330 }
3331 $flg = 1;
3332 }
3333 }
3334 break;
3335 case 'get':
3336 if ( empty( $value ) ) {
3337 if ( isset( $_GET[ $key ] ) ) {
3338 if ( in_array( $handle, $action_array ) ) {
3339 $res = call_user_func( array( $this, $function ) );
3340 } else {
3341 $res = call_user_func( $function );
3342 }
3343 $flg = 1;
3344 }
3345 } else {
3346 if ( isset( $_GET[ $key ] ) && $_GET[ $key ] == $value ) {
3347 if ( in_array( $handle, $action_array ) ) {
3348 $res = call_user_func( array( $this, $function ) );
3349 } else {
3350 $res = call_user_func( $function );
3351 }
3352 $flg = 1;
3353 }
3354 }
3355 break;
3356 case 'request':
3357 if ( empty( $value ) ) {
3358 if ( isset( $_REQUEST[ $key ] ) ) {
3359 if ( in_array( $handle, $action_array ) ) {
3360 $res = call_user_func( array( $this, $function ) );
3361 } else {
3362 $res = call_user_func( $function );
3363 }
3364 $flg = 1;
3365 }
3366 } else {
3367 if ( isset( $_REQUEST[ $key ] ) && $_REQUEST[ $key ] == $value ) {
3368 if ( in_array( $handle, $action_array ) ) {
3369 $res = call_user_func( array( $this, $function ) );
3370 } else {
3371 $res = call_user_func( $function );
3372 }
3373 $flg = 1;
3374 }
3375 }
3376 break;
3377 }
3378 if ( ! $res ) {
3379 break;
3380 }
3381 }
3382 if ( ! $flg ) {
3383 $this->default_page();
3384 }
3385 }
3386 }
3387
3388 /**
3389 * Action function.
3390 */
3391 public function front_ajax() {
3392 switch ( $_POST['usces_ajax_action'] ) {
3393 case 'change_states':
3394 change_states_ajax();
3395 break;
3396 }
3397 do_action( 'usces_front_ajax' );
3398 }
3399
3400 public function maintenance() {
3401 $this->page = 'maintenance';
3402 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3403 }
3404
3405 public function inCart() {
3406 global $wp_query;
3407 $this->page = 'cart';
3408 $this->incart_check();
3409 $this->cart->inCart();
3410 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3411 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3412 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3413 }
3414
3415 public function upButton() {
3416 global $wp_query;
3417 $this->page = 'cart';
3418 $this->error_message = $this->cart->upCart();
3419 if ( empty( $this->error_message ) ) {
3420 $this->error_message = $this->zaiko_check();
3421 }
3422 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3423 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3424 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3425 }
3426
3427 public function delButton() {
3428 global $wp_query;
3429 $this->page = 'cart';
3430 $this->cart->del_row();
3431 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3432 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3433 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3434 }
3435
3436 public function backCart() {
3437 global $wp_query;
3438 $this->page = 'cart';
3439 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3440 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3441 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3442 }
3443
3444 public function customerinfo() {
3445 global $wp_query;
3446 if ( false === $this->cart->num_row() ) {
3447 header( 'location: ' . get_option( 'home' ) );
3448 exit;
3449 }
3450 do_action( 'usces_action_customerinfo' );
3451 $this->cart->entry();
3452 $this->error_message = $this->zaiko_check();
3453 $this->error_message = apply_filters( 'usces_filter_cart_check', $this->error_message );
3454 if ( WCUtils::is_blank( $this->error_message ) ) {
3455 if ( $this->is_member_logged_in() ) {
3456 $this->error_message = has_custom_customer_field_essential();
3457 $this->page = ( WCUtils::is_blank( $this->error_message ) ) ? 'delivery' : 'customer';
3458 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_delivery' );
3459 } else {
3460 $this->page = 'customer';
3461 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_customer' );
3462 }
3463 } else {
3464 $this->page = 'cart';
3465 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3466 }
3467 if ( ! $this->cart->is_order_condition() ) {
3468 $order_conditions = $this->get_condition();
3469 $this->cart->set_order_condition( $order_conditions );
3470 }
3471 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3472 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3473 }
3474
3475 public function backCustomer() {
3476 global $wp_query;
3477 if ( false === $this->cart->num_row() ) {
3478 header( 'location: ' . get_option( 'home' ) );
3479 exit;
3480 }
3481 $this->page = apply_filters( 'usces_filter_backCustomer_page', 'customer' );
3482 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3483 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_customer' );
3484 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3485 }
3486
3487 public function customerlogin() {
3488 global $wp_query;
3489 if ( false === $this->cart->num_row() ) {
3490 header( 'location: ' . get_option( 'home' ) );
3491 exit;
3492 }
3493 if ( 'member' == $this->member_login() ) {
3494 do_action( 'usces_action_member_customer_logined' );
3495 $this->cart->entry();
3496 // $this->error_message = has_custom_customer_field_essential();
3497 if ( WCUtils::is_blank( $this->error_message ) ) {
3498 $this->page = 'delivery';
3499 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_delivery' );
3500 } else {
3501 $this->page = 'customer';
3502 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_customer' );
3503 }
3504 } else {
3505 $this->cart->entry();
3506 $this->page = 'customer';
3507 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_customer' );
3508 }
3509 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3510 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3511 }
3512
3513 public function reganddeliveryinfo() {
3514 global $wp_query;
3515 if ( false === $this->cart->num_row() ) {
3516 header( 'location: ' . get_option( 'home' ) );
3517 exit;
3518 }
3519
3520 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
3521 if ( ! $this->verify_member_nonce( $nonce, 'post_member' ) && ! $this->is_member_logged_in() ) {
3522 die( 'Security check2' );
3523 }
3524 $check_verify_recaptcha = $this->verifyGoogleRecapcha();
3525 if ( $check_verify_recaptcha ) {
3526 $this->cart->entry();
3527 if ( empty( $_POST['member_regmode'] ) || 'editmemberfromcart' != $_POST['member_regmode'] ) {
3528 $_POST['member_regmode'] = 'newmemberfromcart';
3529 }
3530 $res = $this->regist_member();
3531 } else {
3532 // return back page register and show message.
3533 $this->error_message = apply_filters( 'usces_filter_check_verify_recaptcha_message', __( 'Failed to register member. Please try again.', 'usces' ), 'reganddeliveryinfo' );
3534 $res = trim( $_POST['member_regmode'] );
3535 }
3536
3537 if ( 'newcompletion' == $res ) {
3538 $this->page = 'delivery';
3539 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_delivery' );
3540 } elseif ( 'cartverifying' == $res ) {
3541 $this->page = 'cartverifying';
3542 } else {
3543 $this->page = 'customer';
3544 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_customer' );
3545 }
3546 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3547 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3548 }
3549
3550 public function deliveryinfo() {
3551 global $wp_query;
3552 if ( false === $this->cart->num_row() ) {
3553 header( 'location: ' . get_option( 'home' ) );
3554 exit;
3555 }
3556 $check_verify_recaptcha = $this->verifyGoogleRecapcha();
3557 if ( $check_verify_recaptcha ) {
3558 // continue process.
3559 $this->cart->entry();
3560 $this->error_message = $this->customer_check();
3561 } else {
3562 // return back page register and show message.
3563 $this->error_message = apply_filters( 'usces_filter_check_verify_recaptcha_message', __( 'Could not send successfully. Please try again.', 'usces' ), 'deliveryinfo' );
3564 }
3565
3566 if ( WCUtils::is_blank( $this->error_message ) ) {
3567 $this->page = 'delivery';
3568 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_delivery' );
3569 } else {
3570 $this->page = 'customer';
3571 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_customer' );
3572 }
3573 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3574 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3575 }
3576
3577 public function backDelivery() {
3578 global $wp_query;
3579 if ( false === $this->cart->num_row() ) {
3580 header( 'location: ' . get_option( 'home' ) );
3581 exit;
3582 }
3583 $this->page = 'delivery';
3584 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_delivery' );
3585 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3586 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3587 }
3588
3589 public function confirm() {
3590 global $wpdb, $wp_query;
3591 if ( false === $this->cart->num_row() ) {
3592 header( 'location: ' . get_option( 'home' ) );
3593 exit;
3594 }
3595
3596 $check_verify_recaptcha = $this->verifyGoogleRecapcha();
3597 if ( $check_verify_recaptcha ) {
3598 // continue process.
3599 $this->cart->entry();
3600 $this->error_message = $this->zaiko_check();
3601 } else {
3602 // return back page register and show message.
3603 $this->error_message = apply_filters( 'usces_filter_check_verify_recaptcha_message', __( 'Could not send successfully. Please try again.', 'usces' ), 'confirm' );
3604 }
3605
3606 if ( '' != $this->error_message ) {
3607 $this->page = 'cart';
3608 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3609 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3610 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3611 return;
3612 }
3613 /*
3614 $referrer = wp_get_referer();
3615 $site_url = parse_url( home_url(), PHP_URL_HOST );
3616 $referrer_host = parse_url( $referrer, PHP_URL_HOST );
3617 if ( false === $referrer || $referrer_host !== $site_url ) {
3618 $this->page = 'cart';
3619 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3620 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3621 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3622 return;
3623 }
3624 */
3625 $this->set_reserve_pre_order_id();
3626 if ( isset( $_POST['confirm'] ) ) {
3627 $this->error_message = $this->delivery_check();
3628 }
3629 $this->page = ( WCUtils::is_blank( $this->error_message ) ) ? 'confirm' : 'delivery';
3630 if ( WCUtils::is_blank( $this->error_message ) ) {
3631 if ( usces_is_member_system() && usces_is_member_system_point() && $this->is_member_logged_in() ) {
3632 $member_table = usces_get_tablename( 'usces_member' );
3633 $query = $wpdb->prepare( "SELECT mem_point FROM $member_table WHERE ID = %d", $_SESSION['usces_member']['ID'] );
3634 $mem_point = $wpdb->get_var( $query );
3635 $_SESSION['usces_member']['point'] = $mem_point;
3636 }
3637 $this->page = 'confirm';
3638 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_confirm' );
3639 } else {
3640 $this->page = apply_filters( 'usces_filter_delivery_check_error_page', 'delivery', $this->error_message );
3641 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_delivery' );
3642 }
3643 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3644 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3645 }
3646
3647 public function use_point() {
3648 global $wp_query, $usces;
3649 if ( ! isset( $_REQUEST['wc_nonce'] ) || ! $usces->verify_member_nonce( $_REQUEST['wc_nonce'], 'use_point' ) ) {
3650 die( 'Security check1' );
3651 }
3652
3653 $this->error_message = $this->point_check( $this->cart->get_entry() );
3654 if ( empty( $this->error_message ) ) {
3655 $this->cart->entry();
3656 }
3657 $this->page = 'confirm';
3658 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_confirm' );
3659 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3660 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3661 }
3662
3663 public function backConfirm() {
3664 global $wp_query;
3665 if ( false === $this->cart->num_row() ) {
3666 header( 'location: ' . get_option( 'home' ) );
3667 exit;
3668 }
3669 $this->page = 'confirm';
3670 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_confirm' );
3671 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3672 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3673 }
3674
3675 /**
3676 * Purchase
3677 */
3678 public function purchase() {
3679 global $wp_query;
3680 do_action( 'usces_pre_purchase' );
3681 if ( false === $this->cart->num_row() ) {
3682 header( 'location: ' . get_option( 'home' ) );
3683 exit;
3684 }
3685
3686 if ( isset( $_POST['wc_purchase_nonce'] ) ) {
3687 if ( ! wp_verify_nonce( $_POST['wc_purchase_nonce'], 'wc_purchase_nonce' ) ) {
3688 $this->error_message = __( 'Security check failed. Please try again.', 'usces' );
3689 $this->page = 'confirm';
3690 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3691 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3692 return;
3693 }
3694 }
3695
3696 if ( ! apply_filters( 'usces_purchase_check', true ) ) {
3697 return;
3698 }
3699
3700 do_action( 'usces_purchase_validate' );
3701
3702 $entry = $this->cart->get_entry();
3703 $this->error_message = $this->zaiko_check();
3704 if ( WCUtils::is_blank( $this->error_message ) && 0 < $this->cart->num_row() ) {
3705 $acting_status = '';
3706 $payments = $this->getPayments( $entry['order']['payment_name'] );
3707 if ( null === $payments['id'] && 0 < $entry['order']['total_full_price'] ) {
3708 header( 'HTTP/1.0 400 Bad request' );
3709 die();
3710 }
3711 $payment_settlement = $payments['settlement'] ?? '';
3712 if ( substr( $payment_settlement, 0, 6 ) == 'acting' && $entry['order']['total_full_price'] > 0 ) {
3713 $acting_flg = ( 'acting' == $payment_settlement ) ? $payments['module'] : $payment_settlement;
3714 unset( $_POST['purchase'] );
3715 $post_query = '&' . http_build_query( $_POST );
3716 $acting_status = $this->acting_processing( $acting_flg, $post_query, $acting_status );
3717 }
3718
3719 if ( 'error' == $acting_status ) {
3720 $this->page = 'error';
3721 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_error' );
3722 } else {
3723 $res = $this->order_processing();
3724 if ( 'ordercompletion' == $res ) {
3725 $this->page = 'ordercompletion';
3726 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_ordercompletion' );
3727 } else {
3728 $this->page = 'error';
3729 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_error' );
3730 }
3731 }
3732 } else {
3733 $this->page = 'cart';
3734 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_cart' );
3735 if ( ! $this->is_cart_page( $_SERVER['REQUEST_URI'] ) ) {
3736 wp_redirect( USCES_CART_URL );
3737 exit;
3738 }
3739 }
3740 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3741 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3742 }
3743
3744 public function acting_return() {
3745 global $wp_query;
3746
3747 do_action( 'usces_pre_acting_return' );
3748
3749 $entry = $this->cart->get_entry();
3750 if ( isset( $_GET['acting'] ) && 'anotherlane_card' != $_GET['acting'] ) {
3751 if ( false === $this->cart->num_row() && ( 'paypal' != $_GET['acting'] && 1 !== (int) $_GET['acting_return'] ) ) {
3752 header( 'location: ' . get_option( 'home' ) );
3753 exit;
3754 }
3755 }
3756
3757 $this->payment_results = usces_check_acting_return();
3758
3759 if ( isset( $this->payment_results[0] ) && 'duplicate' === $this->payment_results[0] ) {
3760
3761 header( 'location: ' . get_option( 'home' ) );
3762 exit;
3763
3764 } elseif ( isset( $this->payment_results[0] ) && $this->payment_results[0] ) { // result OK.
3765
3766 if ( ! $this->payment_results['reg_order'] ) { // without Registration Order.
3767 $this->page = 'ordercompletion';
3768 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_ordercompletion' );
3769
3770 } else {
3771 $res = $this->order_processing( $this->payment_results );
3772
3773 if ( 'ordercompletion' == $res ) {
3774 $this->page = 'ordercompletion';
3775 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_ordercompletion' );
3776 } else {
3777 $this->page = 'error';
3778 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_error' );
3779 }
3780 }
3781
3782 } else { // result NG.
3783 $this->page = 'error';
3784 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_error' );
3785 }
3786
3787 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
3788 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3789 }
3790
3791 public function settlement_epsilon() {
3792 global $wp_query;
3793 require_once $this->options['settlement_path'] . 'epsilon.php';
3794 }
3795
3796 public function inquiry_button() {
3797 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'] ) ) {
3798 $res = $this->inquiry_processing();
3799 } else {
3800 $res = 'deficiency';
3801 }
3802
3803 $this->page = $res;
3804 }
3805
3806 public function member_login_page() {
3807 global $wp_query;
3808 if ( ! class_exists( 'RateLimiter' ) ) {
3809 require USCES_PLUGIN_DIR . '/classes/rateLimiter.class.php';
3810 }
3811 $rateLimiter = new RateLimiter();
3812 if ( $rateLimiter->checkBlockIP() ) {
3813 $wp_query->set_403();
3814 status_header( 403 );
3815 exit();
3816 }
3817
3818 if ( isset( $_GET['redirect_to'] ) ) {
3819 $_SESSION['redirect_to'] = $_GET['redirect_to'];
3820 }
3821
3822 $res = $this->member_login();
3823 if ( 'member' == $res ) {
3824 $this->page = 'member';
3825 do_action( 'usces_action_member_logined' );
3826
3827 if ( isset( $_SESSION['redirect_to'] ) ) {
3828 if ( wp_safe_redirect( esc_url( $_SESSION['redirect_to'] ) ) ) {
3829 unset( $_SESSION['redirect_to'] );
3830 exit;
3831 }
3832 }
3833
3834 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_member' );
3835 } elseif ( 'login' == $res ) {
3836 $this->page = 'login';
3837 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_login' );
3838 }
3839 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3840 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3841 }
3842
3843 public function regmember() {
3844 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
3845 if ( ! $this->verify_member_nonce( $nonce, 'post_member' ) ) {
3846 die( 'Security check2' );
3847 }
3848
3849 $check_verify_recaptcha = $this->verifyGoogleRecapcha();
3850 if ( $check_verify_recaptcha ) {
3851 // continue register form.
3852 global $wp_query;
3853 $res = $this->regist_member();
3854 } else {
3855 // return back page register and show message.
3856 $this->error_message = apply_filters( 'usces_filter_check_verify_recaptcha_message', __( 'Failed to register member. Please try again.', 'usces' ), 'regmember' );
3857 $res = trim( $_POST['member_regmode'] );
3858 }
3859
3860 if ( 'editmemberform' == $res ) {
3861 $this->page = 'editmemberform';
3862 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_editmemberform' );
3863 } elseif ( 'newcompletion' == $res ) {
3864 $this->page = 'newcompletion';
3865 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_newcompletion' );
3866 } else {
3867 $this->page = $res;
3868 }
3869 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3870 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3871 }
3872
3873 public function editmember() {
3874 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
3875 if ( ! $this->verify_member_nonce( $nonce, 'post_member' ) ) {
3876 die( 'Security check3' );
3877 }
3878
3879 global $wp_query;
3880 $res = $this->regist_member();
3881 if ( 'editmemberform' == $res ) {
3882 $this->page = 'editmemberform';
3883 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_editmemberform' );
3884 } elseif ( 'newcompletion' == $res ) {
3885 $this->page = 'newcompletion';
3886 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_newcompletion' );
3887 } elseif ( 'updatememberform' == $res ) {
3888 $this->page = 'member_edit';
3889 } else {
3890 $this->page = $res;
3891 }
3892 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3893 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3894 }
3895
3896 public function deletemember() {
3897 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
3898 if ( ! $this->verify_member_nonce( $nonce, 'post_member' ) ) {
3899 die( 'Security check4' );
3900 }
3901
3902 $res = $this->delete_member();
3903 if ( $res ) {
3904 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_deletemember' );
3905 $this->member_logout();
3906 } else {
3907 $this->page = 'editmemberform';
3908 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3909 }
3910 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3911 }
3912
3913 public function page_logout() {
3914 global $wp_query;
3915 $this->member_logout();
3916 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3917 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3918 }
3919
3920 public function page_lostmemberpassword() {
3921 global $wp_query;
3922 $this->page = 'lostmemberpassword';
3923 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3924 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3925 }
3926
3927 public function lostpassword() {
3928 global $usces, $wp_query;
3929
3930 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
3931 if ( ! $usces->verify_member_nonce( $nonce, 'post_member' ) ) {
3932 $wp_query->set_403();
3933 status_header( 403 );
3934 exit();
3935 }
3936
3937 $this->error_message = $this->lostpass_mailaddcheck();
3938 if ( '' != $this->error_message ) {
3939 $this->page = 'lostmemberpassword';
3940 } else {
3941 $res = $this->lostmail();
3942 $this->page = $res; // 'lostcompletion';.
3943 }
3944 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3945 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3946 }
3947
3948 public function uscesmode_changepassword() {
3949 global $wp_query;
3950
3951 if ( ! isset( $_REQUEST['mem'] ) || ! isset( $_REQUEST['key'] ) ) {
3952 die( 'Invalid request 1' );
3953 }
3954
3955 $mem_mail = $_REQUEST['mem'];
3956 $lostkey = $_REQUEST['key'];
3957 $res = usces_check_lostkey( $mem_mail, $lostkey );
3958 if ( empty( $res ) ) {
3959 die( 'Invalid request 2' );
3960 }
3961
3962 $this->page = 'changepassword';
3963 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3964 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3965 }
3966
3967 public function changepassword_page() {
3968 global $usces;
3969
3970 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
3971 if ( ! $usces->verify_member_nonce( $nonce, 'post_member' ) ) {
3972 die( 'Security check6' );
3973 }
3974
3975 $lostmail = $_POST['mem'];
3976 $lostkey = $_POST['key'];
3977 $res = usces_check_lostkey( $lostmail, $lostkey );
3978 if ( empty( $res ) ) {
3979 die( 'Invalid request 7' );
3980 }
3981
3982 global $wp_query;
3983 $this->error_message = $this->changepass_check();
3984 if ( '' != $this->error_message ) {
3985 $this->page = 'changepassword';
3986 } else {
3987 $res = $this->changepassword();
3988 $this->page = $res; // 'changepasscompletion';.
3989 }
3990 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3991 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
3992 }
3993
3994 public function page_newmember() {
3995 global $wp_query;
3996 $this->page = 'newmemberform';
3997 add_filter( 'yoast-ga-push-after-pageview', 'usces_trackPageview_newmemberform' );
3998 add_action( 'the_post', array( $this, 'action_memberFilter' ) );
3999 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
4000 }
4001
4002 public function page_search_item() {
4003 global $wp_query;
4004 $this->page = 'search_item';
4005 add_action( 'the_post', array( $this, 'action_cartFilter' ) );
4006 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
4007 }
4008
4009 public function default_page() {
4010 global $wp_query;
4011 add_action( 'the_post', array( $this, 'goDefaultPage' ) );
4012 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
4013 }
4014
4015 public function verifyGoogleRecapcha() {
4016 // check google re-captcha v3.
4017 $option = get_option( 'usces_ex' );
4018 $is_human = true;
4019 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'] ) ) ) {
4020 if ( isset( $_POST['recaptcha_response'] ) ) {
4021 $secret = isset( $option['system']['google_recaptcha']['secret_key'] ) ? $option['system']['google_recaptcha']['secret_key'] : '';
4022 $token = trim( $_POST['recaptcha_response'] );
4023 $is_human = $this->google_recaptcha_v3_response( $token, $secret );
4024 }
4025 }
4026 return $is_human;
4027 }
4028
4029 /**
4030 * Handle check google recaptcha v3 response.
4031 *
4032 * @param string $token string token.
4033 * @param string $secret string secret key config.
4034 *
4035 * @return boolean $is_human.
4036 */
4037 public function google_recaptcha_v3_response( $token, $secret ) {
4038 $is_human = true;
4039 if ( empty( $token ) || empty( $secret ) ) {
4040 return $is_human;
4041 }
4042 $option = get_option( 'usces_ex' );
4043 $threshold = isset( $option['system']['google_recaptcha']['score'] ) ? $option['system']['google_recaptcha']['score'] : 0.5;
4044
4045 $endpoint = 'https://www.google.com/recaptcha/api/siteverify';
4046 $request = array(
4047 'body' => array(
4048 'secret' => $secret,
4049 'response' => $token,
4050 ),
4051 );
4052
4053 $response = wp_remote_post( esc_url_raw( $endpoint ), $request );
4054
4055 if ( 200 !== wp_remote_retrieve_response_code( $response ) ) {
4056 update_option( 'usces_recaptcha_condition', 'response_NG' );
4057 return $is_human;
4058 } else {
4059 update_option( 'usces_recaptcha_condition', 'response_OK' );
4060 }
4061
4062 $response_body = wp_remote_retrieve_body( $response );
4063 $response_body = json_decode( $response_body, true );
4064
4065 $action = isset( $response_body['action'] ) ? $response_body['action'] : '';
4066 $actions = array(
4067 'create_new_member',
4068 'customer_order_page',
4069 'delivery_order_page',
4070 'member_register_settlement',
4071 'member_update_settlement',
4072 );
4073 if ( ! $response_body['success'] || ! in_array( $action, $actions ) ) {
4074 update_option( 'usces_recaptcha_condition', 'response_ERROR' );
4075 return $is_human;
4076 } else {
4077 update_option( 'usces_recaptcha_condition', 'response_OK' );
4078 }
4079 $score = isset( $response_body['score'] ) ? $response_body['score'] : 0;
4080 $is_human = $threshold <= $score;
4081 return $is_human;
4082 }
4083
4084 public function goDefaultPage() {
4085 global $post;
4086
4087 if ( is_object( $post ) && null !== $post && (int) $post->ID === (int) USCES_CART_NUMBER ) {
4088
4089 $this->page = 'cart';
4090 add_filter( 'the_content', array( $this, 'filter_cartContent' ), 20 );
4091
4092 } elseif ( is_object( $post ) && null !== $post && (int) $post->ID === (int) USCES_MEMBER_NUMBER ) {
4093
4094 $this->page = 'member';
4095
4096 if ( $this->is_member_logged_in() ) {
4097 $this->get_current_member();
4098 $this->set_member_session_data( $this->current_member['id'] );
4099 $this->page = 'member';
4100 } else {
4101 $this->page = 'login';
4102 }
4103 add_filter( 'the_content', array( $this, 'filter_memberContent' ), 20 );
4104 add_filter( 'the_title', array( $this, 'filter_memberTitle' ), 20 );
4105
4106 } elseif ( ! is_singular() ) {
4107 $this->page = 'wp_search';
4108 add_filter( 'the_excerpt', array( $this, 'filter_cartContent' ), 20 );
4109 add_filter( 'the_content', array( $this, 'filter_cartContent' ), 20 );
4110
4111 } else {
4112 add_filter( 'the_content', array( &$this, 'filter_itemPage' ) );
4113 }
4114 }
4115
4116 public function template_redirect() {
4117 global $wpdb, $wp_version, $post, $usces_entries, $usces_carts, $usces_members, $usces_gp, $member_regmode;
4118
4119 if ( version_compare( $wp_version, '4.4-beta', '>' ) && is_embed() ) {
4120 return;
4121 }
4122
4123 if ( $this->is_cart_page( $_SERVER['REQUEST_URI'] ) ) {
4124 if ( '' == $this->page && empty( $this->error_message ) ) {
4125 $this->error_message = $this->zaiko_check();
4126 if ( $this->error_message ) {
4127 $this->page = 'cart';
4128 }
4129 }
4130 }
4131
4132 if ( apply_filters( 'usces_action_template_redirect', false ) ) {
4133 return; // Deprecated.
4134 }
4135 if ( apply_filters( 'usces_filter_template_redirect', false ) ) {
4136 return;
4137 }
4138
4139 $parent_path = get_template_directory() . '/wc_templates';
4140 $child_path = get_stylesheet_directory() . '/wc_templates';
4141
4142 if ( is_single() && is_object( $post ) && 'item' === $post->post_mime_type ) {
4143
4144 if ( file_exists( $child_path . '/wc_item_single.php' ) ) {
4145 if ( ! post_password_required( $post ) ) {
4146 include $child_path . '/wc_item_single.php';
4147 exit;
4148 }
4149 } elseif ( file_exists( $parent_path . '/wc_item_single.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4150 if ( ! post_password_required( $post ) ) {
4151 include $parent_path . '/wc_item_single.php';
4152 exit;
4153 }
4154 }
4155
4156 } elseif ( isset( $_REQUEST['usces_page'] ) && ( 'search_item' == $_REQUEST['usces_page'] || 'usces_search' == $_REQUEST['usces_page'] ) && $this->is_cart_page( $_SERVER['REQUEST_URI'] ) ) {
4157
4158 if ( file_exists( $child_path . '/wc_search_page.php' ) ) {
4159 include $child_path . '/wc_search_page.php';
4160 exit;
4161 } elseif ( file_exists( $parent_path . '/wc_search_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4162 include $parent_path . '/wc_search_page.php';
4163 exit;
4164 }
4165
4166 } elseif ( $this->is_cart_page( $_SERVER['REQUEST_URI'] ) ) {
4167
4168 switch ( $this->page ) {
4169
4170 case 'customer':
4171 if ( file_exists( $child_path . '/cart/wc_customer_page.php' ) ) {
4172 usces_get_entries();
4173 usces_get_member_regmode();
4174 include $child_path . '/cart/wc_customer_page.php';
4175 exit;
4176 } elseif ( file_exists( $parent_path . '/cart/wc_customer_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4177 usces_get_entries();
4178 usces_get_member_regmode();
4179 include $parent_path . '/cart/wc_customer_page.php';
4180 exit;
4181 }
4182 break;
4183
4184 case 'delivery':
4185 if ( file_exists( $child_path . '/cart/wc_delivery_page.php' ) ) {
4186 usces_get_entries();
4187 usces_get_carts();
4188 include $child_path . '/cart/wc_delivery_page.php';
4189 exit;
4190 } elseif ( file_exists( $parent_path . '/cart/wc_delivery_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4191 usces_get_entries();
4192 usces_get_carts();
4193 include $parent_path . '/cart/wc_delivery_page.php';
4194 exit;
4195 }
4196 break;
4197
4198 case 'confirm':
4199 if ( file_exists( $child_path . '/cart/wc_confirm_page.php' ) ) {
4200 usces_get_entries();
4201 usces_get_carts();
4202 usces_get_members();
4203 include $child_path . '/cart/wc_confirm_page.php';
4204 exit;
4205 } elseif ( file_exists( $parent_path . '/cart/wc_confirm_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4206 usces_get_entries();
4207 usces_get_carts();
4208 usces_get_members();
4209 include $parent_path . '/cart/wc_confirm_page.php';
4210 exit;
4211 }
4212 break;
4213
4214 case 'ordercompletion':
4215 if ( file_exists( $child_path . '/cart/wc_completion_page.php' ) ) {
4216 usces_get_entries();
4217 usces_get_carts();
4218 include $child_path . '/cart/wc_completion_page.php';
4219 exit;
4220 } elseif ( file_exists( $parent_path . '/cart/wc_completion_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4221 usces_get_entries();
4222 usces_get_carts();
4223 include $parent_path . '/cart/wc_completion_page.php';
4224 exit;
4225 }
4226 break;
4227
4228 case 'error':
4229 if ( file_exists( $child_path . '/cart/wc_cart_error_page.php' ) ) {
4230 include $child_path . '/cart/wc_cart_error_page.php';
4231 exit;
4232 } elseif ( file_exists( $parent_path . '/cart/wc_cart_error_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4233 include $parent_path . '/cart/wc_cart_error_page.php';
4234 exit;
4235 }
4236 break;
4237
4238 case 'cart':
4239 default:
4240 $this->page = 'cart';
4241 if ( file_exists( $child_path . '/cart/wc_cart_page.php' ) ) {
4242 include $child_path . '/cart/wc_cart_page.php';
4243 exit;
4244 } elseif ( file_exists( $parent_path . '/cart/wc_cart_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4245 include $parent_path . '/cart/wc_cart_page.php';
4246 exit;
4247 }
4248 }
4249
4250 } elseif ( $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
4251
4252 } elseif ( $this->is_member_page( $_SERVER['REQUEST_URI'] ) ) {
4253 if ( 'activate' != $this->options['membersystem_state'] ) {
4254 return;
4255 }
4256
4257 if ( $this->is_member_logged_in() ) {
4258
4259 if ( isset( $_SESSION['usces_member'] ) ) {
4260 $member_table_name = usces_get_tablename( 'usces_member' );
4261 $this->get_current_member();
4262 $query = $wpdb->prepare( "SELECT mem_point FROM $member_table_name WHERE ID = %d", $this->current_member['id'] );
4263 $point = $wpdb->get_var( $query );
4264 $_SESSION['usces_member']['point'] = $point;
4265 }
4266
4267 $member_regmode = 'editmemberform';
4268 if ( file_exists( $child_path . '/member/wc_member_page.php' ) ) {
4269 include $child_path . '/member/wc_member_page.php';
4270 exit;
4271 } elseif ( file_exists( $parent_path . '/member/wc_member_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4272 include $parent_path . '/member/wc_member_page.php';
4273 exit;
4274 }
4275
4276 } else {
4277
4278 switch ( $this->page ) {
4279
4280 case 'login':
4281 if ( file_exists( $child_path . '/member/wc_login_page.php' ) ) {
4282 include $child_path . '/member/wc_login_page.php';
4283 exit;
4284 } elseif ( file_exists( $parent_path . '/member/wc_login_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4285 include $parent_path . '/member/wc_login_page.php';
4286 exit;
4287 }
4288 break;
4289
4290 case 'newmemberform':
4291 if ( file_exists( $child_path . '/member/wc_new_member_page.php' ) ) {
4292 $member_regmode = 'newmemberform';
4293 include $child_path . '/member/wc_new_member_page.php';
4294 exit;
4295 } elseif ( file_exists( $parent_path . '/member/wc_new_member_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4296 $member_regmode = 'newmemberform';
4297 include $parent_path . '/member/wc_new_member_page.php';
4298 exit;
4299 }
4300 break;
4301
4302 case 'lostmemberpassword':
4303 if ( file_exists( $child_path . '/member/wc_lostpassword_page.php' ) ) {
4304 include $child_path . '/member/wc_lostpassword_page.php';
4305 exit;
4306 } elseif ( file_exists( $parent_path . '/member/wc_lostpassword_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4307 include $parent_path . '/member/wc_lostpassword_page.php';
4308 exit;
4309 }
4310 break;
4311
4312 case 'changepassword':
4313 if ( file_exists( $child_path . '/member/wc_changepassword_page.php' ) ) {
4314 include $child_path . '/member/wc_changepassword_page.php';
4315 exit;
4316 } elseif ( file_exists( $parent_path . '/member/wc_changepassword_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4317 include $parent_path . '/member/wc_changepassword_page.php';
4318 exit;
4319 }
4320 break;
4321
4322 case 'newcompletion':
4323 case 'editcompletion':
4324 case 'lostcompletion':
4325 case 'changepasscompletion':
4326 if ( file_exists( $child_path . '/member/wc_member_completion_page.php' ) ) {
4327 include $child_path . '/member/wc_member_completion_page.php';
4328 exit;
4329 } elseif ( file_exists( $parent_path . '/member/wc_member_completion_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4330 include $parent_path . '/member/wc_member_completion_page.php';
4331 exit;
4332 }
4333 break;
4334
4335 default:
4336 $this->page = 'login';
4337 if ( file_exists( $child_path . '/member/wc_login_page.php' ) ) {
4338 include $child_path . '/member/wc_login_page.php';
4339 exit;
4340 } elseif ( file_exists( $parent_path . '/member/wc_login_page.php' ) && ! defined( 'USCES_PARENT_LOAD' ) ) {
4341 include $parent_path . '/member/wc_login_page.php';
4342 exit;
4343 }
4344 }
4345 }
4346 }
4347 }
4348
4349 public function changepassword() {
4350 global $wpdb;
4351
4352 $lostmail = $_POST['mem'];
4353 $lost_key = $_POST['key'];
4354
4355 $member_table = usces_get_tablename( 'usces_member' );
4356 // $hash = usces_get_hash(trim($_POST['loginpass1']));
4357 $salt = usces_get_salt( $lostmail );
4358 $hash = usces_get_hash( trim( $_POST['loginpass1'] ), $salt );
4359 $query = $wpdb->prepare( "UPDATE $member_table SET mem_pass = %s WHERE mem_email = %s",
4360 $hash, $lostmail
4361 );
4362 $res = $wpdb->query( $query );
4363
4364 if ( $res === false ) {
4365 $this->error_message = __( 'Error: failure in updating password', 'usces' );
4366 return 'login';
4367 } else {
4368 usces_remove_lostmail_key( $lostmail, $lost_key );
4369 return 'changepasscompletion';
4370 }
4371 }
4372
4373 public function lostmail() {
4374 $delim = apply_filters( 'usces_filter_delim', $this->delim );
4375
4376 $lostmail = trim( $_POST['loginmail'] );
4377 if ( ! $this->is_member( $lostmail ) ) {
4378 return 'lostcompletion';
4379 }
4380
4381 $lost_key = usces_make_lost_key();
4382 usces_store_lostmail_key( $lostmail, $lost_key );
4383
4384 $uri = USCES_MEMBER_URL . $delim . 'uscesmode=changepassword&mem=' . urlencode( $lostmail ) . '&key=' . urlencode( $lost_key );
4385
4386 $res = usces_lostmail( $uri );
4387 return $res;
4388 }
4389
4390 public function regist_member() {
4391 global $wpdb;
4392
4393 $_POST = $this->stripslashes_deep_post( $_POST );
4394
4395 $member = $this->get_member();
4396 $mode = $_POST['member_regmode'];
4397 $member_table = usces_get_tablename( 'usces_member' );
4398 $member_meta_table = usces_get_tablename( 'usces_member_meta' );
4399
4400 $error_mes = ( 'newmemberfromcart' == $_POST['member_regmode'] || 'editmemberfromcart' == $_POST['member_regmode'] ) ? $this->member_check_fromcart() : $this->member_check();
4401
4402 if ( '' != $error_mes ) {
4403
4404 $this->error_message = $error_mes;
4405 return $mode;
4406
4407 } elseif ( 'editmemberform' == $_POST['member_regmode'] || 'updatememberform' == $_POST['member_regmode'] ) {
4408
4409 $this->get_current_member();
4410 $mem_id = $this->current_member['id'];
4411
4412 // $query = $wpdb->prepare("SELECT ID FROM $member_table WHERE mem_email = %s", trim($_POST['member']['mailaddress1']));
4413 // $id = $wpdb->get_var( $query );
4414 $id = $this->check_member_email( $_POST['member']['mailaddress1'] );
4415 if ( ! empty( $id ) && $id != $mem_id ) {
4416 // $this->error_message = __( 'This e-mail address has been already registered.', 'usces' );
4417 $this->error_message = __( 'This e-mail address can not be registered.', 'usces' );
4418 return $mode;
4419 }
4420
4421 do_action( 'usces_action_pre_edit_memberdata', $_POST['member'], $mem_id );
4422
4423 $query = $wpdb->prepare( "SELECT mem_pass FROM $member_table WHERE ID = %d", $mem_id );
4424 $pass = $wpdb->get_var( $query );
4425 // $password = ( !empty( $_POST['member']['password1']) && trim($_POST['member']['password1']) == trim($_POST['member']['password2']) ) ? usces_get_hash(trim($_POST['member']['password1'])) : $pass;
4426 if ( ! empty( $_POST['member']['password1'] ) && trim( $_POST['member']['password1'] ) == trim( $_POST['member']['password2'] ) ) {
4427 $salt = usces_get_salt( $mem_id );
4428 $password = usces_get_hash( trim( $_POST['member']['password1'] ), $salt );
4429 } else {
4430 $password = $pass;
4431 }
4432 $name1 = ( isset( $_POST['member']['name1'] ) ) ? trim( $_POST['member']['name1'] ) : '';
4433 $name2 = ( isset( $_POST['member']['name2'] ) ) ? trim( $_POST['member']['name2'] ) : '';
4434 $name3 = ( isset( $_POST['member']['name3'] ) ) ? trim( $_POST['member']['name3'] ) : '';
4435 $name4 = ( isset( $_POST['member']['name4'] ) ) ? trim( $_POST['member']['name4'] ) : '';
4436 $zipcode = ( isset( $_POST['member']['zipcode'] ) ) ? usces_convert_zipcode( trim( $_POST['member']['zipcode'] ) ) : '';
4437 $pref = ( isset( $_POST['member']['pref'] ) ) ? trim( $_POST['member']['pref'] ) : '';
4438 $address1 = ( isset( $_POST['member']['address1'] ) ) ? trim( $_POST['member']['address1'] ) : '';
4439 $address2 = ( isset( $_POST['member']['address2'] ) ) ? trim( $_POST['member']['address2'] ) : '';
4440 $address3 = ( isset( $_POST['member']['address3'] ) ) ? trim( $_POST['member']['address3'] ) : '';
4441 $tel = ( isset( $_POST['member']['tel'] ) ) ? trim( $_POST['member']['tel'] ) : '';
4442 $fax = ( isset( $_POST['member']['fax'] ) ) ? trim( $_POST['member']['fax'] ) : '';
4443 $country = ( isset( $_POST['member']['country'] ) ) ? trim( $_POST['member']['country'] ) : '';
4444
4445 $query = $wpdb->prepare(
4446 "UPDATE $member_table SET
4447 mem_pass = %s, mem_name1 = %s, mem_name2 = %s, mem_name3 = %s, mem_name4 = %s,
4448 mem_zip = %s, mem_pref = %s, mem_address1 = %s, mem_address2 = %s,
4449 mem_address3 = %s, mem_tel = %s, mem_fax = %s, mem_email = %s WHERE ID = %d",
4450 $password,
4451 $name1,
4452 $name2,
4453 $name3,
4454 $name4,
4455 $zipcode,
4456 $pref,
4457 $address1,
4458 $address2,
4459 $address3,
4460 $tel,
4461 $fax,
4462 trim( $_POST['member']['mailaddress1'] ),
4463 $mem_id
4464 );
4465 $res = $wpdb->query( $query );
4466
4467 if ( false !== $res ) {
4468 $this->set_member_meta_value( 'customer_country', $country, $mem_id );
4469 $res = $this->reg_custom_member( $mem_id );
4470 unset( $_SESSION['usces_entry']['custom_customer'] );
4471 $this->cart->entry();
4472 do_action( 'usces_action_edit_memberdata', $_POST['member'], $mem_id );
4473 $meta_keys = apply_filters( 'usces_filter_delete_member_pcid', "'remise_pcid', 'digitalcheck_ip_user_id'" );
4474 $query = $wpdb->prepare( "DELETE FROM $member_meta_table WHERE member_id = %d AND meta_key IN( $meta_keys )",
4475 $mem_id
4476 );
4477 $res = $wpdb->query( $query );
4478
4479 $user = $_POST['member'];
4480 $user['ID'] = $mem_id;
4481 usces_send_updmembermail( $user );
4482
4483 $this->get_current_member();
4484 // return 'editmemberform';
4485 return $mode;
4486
4487 } else {
4488 $this->error_message = __( 'Error:failure in update', 'usces' );
4489 return $mode;
4490 }
4491
4492 } elseif ( 'newmemberform' == $_POST['member_regmode'] ) {
4493 // $query = $wpdb->prepare("SELECT ID FROM $member_table WHERE mem_email = %s", trim( $_POST['member']['mailaddress1']));
4494 // $id = $wpdb->get_var( $query );
4495 $id = $this->check_member_email( $_POST['member']['mailaddress1'] );
4496 if ( ! empty( $id ) ) {
4497 // $this->error_message = __( 'This e-mail address has been already registered.', 'usces' );
4498 $this->error_message = __( 'This e-mail address can not be registered.', 'usces' );
4499 return $mode;
4500 } else {
4501 $point = $this->options['start_point'];
4502 // $pass = usces_get_hash(trim($_POST['member']['password1']));
4503 $salt = usces_get_salt( '', 1 );
4504 $pass = usces_get_hash( trim( $_POST['member']['password1'] ), $salt );
4505 $name1 = ( isset( $_POST['member']['name1'] ) ) ? trim( $_POST['member']['name1'] ) : '';
4506 $name2 = ( isset( $_POST['member']['name2'] ) ) ? trim( $_POST['member']['name2'] ) : '';
4507 $name3 = ( isset( $_POST['member']['name3'] ) ) ? trim( $_POST['member']['name3'] ) : '';
4508 $name4 = ( isset( $_POST['member']['name4'] ) ) ? trim( $_POST['member']['name4'] ) : '';
4509 $zipcode = ( isset( $_POST['member']['zipcode'] ) ) ? usces_convert_zipcode( trim( $_POST['member']['zipcode'] ) ) : '';
4510 $pref = ( isset( $_POST['member']['pref'] ) ) ? trim( $_POST['member']['pref'] ) : '';
4511 $address1 = ( isset( $_POST['member']['address1'] ) ) ? trim( $_POST['member']['address1'] ) : '';
4512 $address2 = ( isset( $_POST['member']['address2'] ) ) ? trim( $_POST['member']['address2'] ) : '';
4513 $address3 = ( isset( $_POST['member']['address3'] ) ) ? trim( $_POST['member']['address3'] ) : '';
4514 $tel = ( isset( $_POST['member']['tel'] ) ) ? trim( $_POST['member']['tel'] ) : '';
4515 $fax = ( isset( $_POST['member']['fax'] ) ) ? trim( $_POST['member']['fax'] ) : '';
4516 $country = ( isset( $_POST['member']['country'] ) ) ? trim( $_POST['member']['country'] ) : '';
4517
4518 $query = $wpdb->prepare(
4519 "INSERT INTO $member_table
4520 (mem_email, mem_pass, mem_status, mem_cookie, mem_point,
4521 mem_name1, mem_name2, mem_name3, mem_name4, mem_zip, mem_pref,
4522 mem_address1, mem_address2, mem_address3, mem_tel, mem_fax,
4523 mem_delivery_flag, mem_delivery, mem_registered, mem_nicename)
4524 VALUES (%s, %s, %d, %s, %d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s)",
4525 trim( $_POST['member']['mailaddress1'] ),
4526 $pass,
4527 0,
4528 '',
4529 $point,
4530 $name1,
4531 $name2,
4532 $name3,
4533 $name4,
4534 $zipcode,
4535 $pref,
4536 $address1,
4537 $address2,
4538 $address3,
4539 $tel,
4540 $fax,
4541 '',
4542 '',
4543 get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ),
4544 ''
4545 );
4546 $res = $wpdb->query( $query );
4547
4548 if ( false !== $res ) {
4549 $user = $_POST['member'];
4550 $user['ID'] = $wpdb->insert_id;
4551 $this->set_member_meta_value( 'customer_country', $country, $user['ID'] );
4552
4553 if ( ! empty( $salt ) ) {
4554 $this->set_member_meta_value( 'mem_salt', $salt, $user['ID'] );
4555 }
4556
4557 $res = $this->reg_custom_member( $user['ID'] );
4558
4559 if ( apply_filters( 'usces_filter_veirfyemail_newmemberform', false, $user ) ) {
4560 return 'memberverifying';
4561 }
4562
4563 do_action( 'usces_action_member_registered', $_POST['member'], $user['ID'] );
4564 unset( $_SESSION['usces_member'] );
4565 usces_send_regmembermail( $user );
4566 return 'newcompletion';
4567
4568 } else {
4569 $this->error_message = __( 'Error:failure in update', 'usces' );
4570 return $mode;
4571 }
4572 }
4573
4574 } elseif ( 'newmemberfromcart' == $_POST['member_regmode'] ) {
4575
4576 // $query = $wpdb->prepare("SELECT ID FROM $member_table WHERE mem_email = %s", trim($_POST['customer']['mailaddress1']));
4577 // $id = $wpdb->get_var( $query );
4578 $id = $this->check_member_email( $_POST['customer']['mailaddress1'] );
4579 if ( ! empty( $id ) ) {
4580 // $this->error_message = __( 'This e-mail address has been already registered.', 'usces' );
4581 $this->error_message = __( 'This e-mail address can not be registered.', 'usces' );
4582 return $mode;
4583 } else {
4584 $point = $this->options['start_point'];
4585 // $pass = usces_get_hash(trim( $_POST['customer']['password1']));
4586 $salt = usces_get_salt( '', 1 );
4587 $pass = usces_get_hash( trim( $_POST['customer']['password1'] ), $salt );
4588 $name1 = ( isset( $_POST['customer']['name1'] ) ) ? trim( $_POST['customer']['name1'] ) : '';
4589 $name2 = ( isset( $_POST['customer']['name2'] ) ) ? trim( $_POST['customer']['name2'] ) : '';
4590 $name3 = ( isset( $_POST['customer']['name3'] ) ) ? trim( $_POST['customer']['name3'] ) : '';
4591 $name4 = ( isset( $_POST['customer']['name4'] ) ) ? trim( $_POST['customer']['name4'] ) : '';
4592 $zipcode = ( isset( $_POST['customer']['zipcode'] ) ) ? usces_convert_zipcode( trim( $_POST['customer']['zipcode'] ) ) : '';
4593 $pref = ( isset( $_POST['customer']['pref'] ) ) ? trim( $_POST['customer']['pref'] ) : '';
4594 $address1 = ( isset( $_POST['customer']['address1'] ) ) ? trim( $_POST['customer']['address1'] ) : '';
4595 $address2 = ( isset( $_POST['customer']['address2'] ) ) ? trim( $_POST['customer']['address2'] ) : '';
4596 $address3 = ( isset( $_POST['customer']['address3'] ) ) ? trim( $_POST['customer']['address3'] ) : '';
4597 $tel = ( isset( $_POST['customer']['tel'] ) ) ? trim( $_POST['customer']['tel'] ) : '';
4598 $fax = ( isset( $_POST['customer']['fax'] ) ) ? trim( $_POST['customer']['fax'] ) : '';
4599 $country = ( isset( $_POST['customer']['country'] ) ) ? trim( $_POST['customer']['country'] ) : '';
4600
4601 $query = $wpdb->prepare(
4602 "INSERT INTO $member_table
4603 (mem_email, mem_pass, mem_status, mem_cookie, mem_point,
4604 mem_name1, mem_name2, mem_name3, mem_name4, mem_zip, mem_pref,
4605 mem_address1, mem_address2, mem_address3, mem_tel, mem_fax,
4606 mem_delivery_flag, mem_delivery, mem_registered, mem_nicename)
4607 VALUES (%s, %s, %d, %s, %d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s)",
4608 trim( $_POST['customer']['mailaddress1'] ),
4609 $pass,
4610 0,
4611 '',
4612 $point,
4613 $name1,
4614 $name2,
4615 $name3,
4616 $name4,
4617 $zipcode,
4618 $pref,
4619 $address1,
4620 $address2,
4621 $address3,
4622 $tel,
4623 $fax,
4624 '',
4625 '',
4626 get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ),
4627 ''
4628 );
4629 $res = $wpdb->query( $query );
4630
4631 if ( false !== $res ) {
4632 $member_id = $wpdb->insert_id;
4633 $user = $_POST['customer'];
4634 $user['ID'] = $member_id;
4635 $this->set_member_meta_value( 'customer_country', $country, $member_id );
4636
4637 if ( ! empty( $salt ) ) {
4638 $this->set_member_meta_value( 'mem_salt', $salt, $member_id );
4639 }
4640
4641 $res = $this->reg_custom_member( $member_id );
4642
4643 if ( apply_filters( 'usces_filter_veirfyemail_newmemberfromcart', false, $user ) ) {
4644 return 'cartverifying';
4645 }
4646
4647 do_action( 'usces_action_member_registered', $_POST['customer'], $member_id );
4648 usces_send_regmembermail( $user );
4649 $_POST['loginmail'] = trim( $_POST['customer']['mailaddress1'] );
4650 $_POST['loginpass'] = trim( $_POST['customer']['password1'] );
4651 if ( 'member' == $this->member_login() ) {
4652 $_SESSION['usces_entry']['member_regmode'] = 'editmemberfromcart';
4653 return 'newcompletion';
4654 }
4655
4656 } else {
4657 $this->error_message = __( 'Error:failure in update', 'usces' );
4658 return $mode;
4659 }
4660 }
4661
4662 } elseif ( 'editmemberfromcart' == $_POST['member_regmode'] ) {
4663
4664 $this->get_current_member();
4665 $mem_id = $this->current_member['id'];
4666
4667 // $query = $wpdb->prepare("SELECT ID FROM $member_table WHERE mem_email = %s", trim( $_POST['customer']['mailaddress1']));
4668 // $id = $wpdb->get_var( $query );
4669 $id = $this->check_member_email( $_POST['customer']['mailaddress1'] );
4670 if ( ! empty( $id ) && $id != $mem_id ) {
4671 // $this->error_message = __( 'This e-mail address has been already registered.', 'usces' );
4672 $this->error_message = __( 'This e-mail address can not be registered.', 'usces' );
4673 return $mode;
4674 }
4675
4676 do_action( 'usces_action_pre_edit_memberdata', $_POST['customer'], $mem_id );
4677
4678 $query = $wpdb->prepare( "SELECT mem_pass FROM $member_table WHERE ID = %d", $mem_id );
4679 $pass = $wpdb->get_var( $query );
4680 // $password = ( !empty( $_POST['customer']['password1']) && trim($_POST['customer']['password1']) == trim($_POST['customer']['password2']) ) ? usces_get_hash(trim($_POST['customer']['password1'])) : $pass;
4681 if ( ! empty( $_POST['customer']['password1'] ) && trim( $_POST['customer']['password1'] ) == trim( $_POST['customer']['password2'] ) ) {
4682 $salt = usces_get_salt( $mem_id );
4683 $password = usces_get_hash( trim( $_POST['customer']['password1'] ), $salt );
4684 } else {
4685 $password = $pass;
4686 }
4687 $name1 = ( isset( $_POST['customer']['name1'] ) ) ? trim( $_POST['customer']['name1'] ) : '';
4688 $name2 = ( isset( $_POST['customer']['name2'] ) ) ? trim( $_POST['customer']['name2'] ) : '';
4689 $name3 = ( isset( $_POST['customer']['name3'] ) ) ? trim( $_POST['customer']['name3'] ) : '';
4690 $name4 = ( isset( $_POST['customer']['name4'] ) ) ? trim( $_POST['customer']['name4'] ) : '';
4691 $zipcode = ( isset( $_POST['customer']['zipcode'] ) ) ? usces_convert_zipcode( trim( $_POST['customer']['zipcode'] ) ) : '';
4692 $pref = ( isset( $_POST['customer']['pref'] ) ) ? trim( $_POST['customer']['pref'] ) : '';
4693 $address1 = ( isset( $_POST['customer']['address1'] ) ) ? trim( $_POST['customer']['address1'] ) : '';
4694 $address2 = ( isset( $_POST['customer']['address2'] ) ) ? trim( $_POST['customer']['address2'] ) : '';
4695 $address3 = ( isset( $_POST['customer']['address3'] ) ) ? trim( $_POST['customer']['address3'] ) : '';
4696 $tel = ( isset( $_POST['customer']['tel'] ) ) ? trim( $_POST['customer']['tel'] ) : '';
4697 $fax = ( isset( $_POST['customer']['fax'] ) ) ? trim( $_POST['customer']['fax'] ) : '';
4698 $country = ( isset( $_POST['customer']['country'] ) ) ? trim( $_POST['customer']['country'] ) : '';
4699
4700 $query = $wpdb->prepare(
4701 "UPDATE $member_table SET
4702 mem_pass = %s, mem_name1 = %s, mem_name2 = %s, mem_name3 = %s, mem_name4 = %s,
4703 mem_zip = %s, mem_pref = %s, mem_address1 = %s, mem_address2 = %s,
4704 mem_address3 = %s, mem_tel = %s, mem_fax = %s, mem_email = %s WHERE ID = %d",
4705 $password,
4706 $name1,
4707 $name2,
4708 $name3,
4709 $name4,
4710 $zipcode,
4711 $pref,
4712 $address1,
4713 $address2,
4714 $address3,
4715 $tel,
4716 $fax,
4717 trim( $_POST['customer']['mailaddress1'] ),
4718 $mem_id
4719 );
4720 $res = $wpdb->query( $query );
4721 if ( false !== $res ) {
4722 $this->set_member_meta_value( 'customer_country', $country, $mem_id );
4723 $res = $this->reg_custom_member( $mem_id );
4724 do_action( 'usces_action_edit_memberdata', $_POST['customer'], $mem_id );
4725 unset( $_SESSION['usces_member'] );
4726 $this->member_just_login( trim( $_POST['customer']['mailaddress1'] ), trim( $_POST['customer']['password1'] ) );
4727 return 'newcompletion';
4728
4729 } else {
4730 $this->error_message = __( 'Error:failure in update', 'usces' );
4731 return $mode;
4732 }
4733 }
4734 }
4735
4736 public function delete_member() {
4737 $res = false;
4738
4739 if ( ! $this->is_member_logged_in() ) {
4740 return $res;
4741 }
4742 $mem = $this->get_member();
4743 if ( ! $mem['ID'] ) {
4744 return $res;
4745 }
4746
4747 $del = usces_delete_member_check_front( $mem['ID'] );
4748 if ( $del ) {
4749 $res = usces_delete_memberdata( $mem['ID'] );
4750 if ( $res ) {
4751 usces_send_delmembermail( $mem );
4752 }
4753 }
4754
4755 return $res;
4756 }
4757
4758 public function is_member_logged_in( $id = false ) {
4759 if ( false === $id ) {
4760 if ( ! empty( $_SESSION['usces_member']['ID'] ) ) {
4761 return true;
4762 } else {
4763 return false;
4764 }
4765 } else {
4766 if ( ! empty( $_SESSION['usces_member']['ID'] ) && $_SESSION['usces_member']['ID'] == $id ) {
4767 return true;
4768 } else {
4769 return false;
4770 }
4771 }
4772 }
4773
4774 public function is_member( $email ) {
4775 global $wpdb;
4776
4777 $member_table = usces_get_tablename( 'usces_member' );
4778 $query = $wpdb->prepare( "SELECT mem_email FROM $member_table WHERE mem_email = %s", $email );
4779 $member = $wpdb->get_row( $query, ARRAY_A );
4780 if ( empty( $member ) ) {
4781 return false;
4782 } else {
4783 return true;
4784 }
4785 }
4786
4787 public function member_login() {
4788 global $wpdb;
4789 $_POST = $this->stripslashes_deep_post( $_POST );
4790
4791 $cookie = $this->get_cookie();
4792 $metatable_name = usces_get_tablename( 'usces_member_meta' );
4793 $member_table = usces_get_tablename( 'usces_member' );
4794 if ( ! class_exists( 'RateLimiter' ) ) {
4795 require USCES_PLUGIN_DIR . '/classes/rateLimiter.class.php';
4796 }
4797 $rateLimiter = new RateLimiter();
4798
4799 if ( isset( $cookie['rme'] ) && 'forever' == $cookie['rme'] && ! isset( $_POST['rememberme'] ) && ! isset( $_POST['loginmail'] ) ) {
4800
4801 $_forever = isset( $cookie['name'] ) ? $cookie['name'] : '';
4802 if ( $_forever ) {
4803 $query = $wpdb->prepare( "SELECT member_id FROM $metatable_name WHERE meta_value = %s AND meta_key = %s",
4804 $_forever, '_forever'
4805 );
4806 $id = $wpdb->get_var( $query );
4807 } else {
4808 $id = '';
4809 }
4810
4811 if ( ! $id ) {
4812 $cookie['name'] = '';
4813 $cookie['rme'] = '';
4814 $this->set_cookie( $cookie );
4815 $rateLimiter->saveLoginFailed();
4816 do_action( 'usces_action_member_login_failed', '', 'auto_login' );
4817 return 'login';
4818 } else {
4819 $query = $wpdb->prepare( "SELECT * FROM $member_table WHERE ID = %s", $id );
4820 $member = $wpdb->get_row( $query, ARRAY_A );
4821 if ( empty( $member ) ) {
4822 $rateLimiter->saveLoginFailed();
4823 do_action( 'usces_action_member_login_failed', '', 'auto_login' );
4824 $this->error_message = __( '<b>Error:</b> Your E-mail or password is incorrect.', 'usces' );
4825 return 'login';
4826 } else {
4827 $_SESSION['usces_member']['ID'] = $member['ID'];
4828 $_SESSION['usces_member']['mailaddress1'] = $member['mem_email'];
4829 $_SESSION['usces_member']['mailaddress2'] = $member['mem_email'];
4830 $_SESSION['usces_member']['point'] = $member['mem_point'];
4831 $_SESSION['usces_member']['name1'] = $member['mem_name1'];
4832 $_SESSION['usces_member']['name2'] = $member['mem_name2'];
4833 $_SESSION['usces_member']['name3'] = $member['mem_name3'];
4834 $_SESSION['usces_member']['name4'] = $member['mem_name4'];
4835 $_SESSION['usces_member']['zipcode'] = $member['mem_zip'];
4836 $_SESSION['usces_member']['pref'] = $member['mem_pref'];
4837 $_SESSION['usces_member']['address1'] = $member['mem_address1'];
4838 $_SESSION['usces_member']['address2'] = $member['mem_address2'];
4839 $_SESSION['usces_member']['address3'] = $member['mem_address3'];
4840 $_SESSION['usces_member']['tel'] = $member['mem_tel'];
4841 $_SESSION['usces_member']['fax'] = $member['mem_fax'];
4842 $_SESSION['usces_member']['delivery_flag'] = $member['mem_delivery_flag'];
4843 $_SESSION['usces_member']['delivery'] = ! empty( $member['mem_delivery'] ) ? wel_safe_unserialize( $member['mem_delivery'] ) : '';
4844 $_SESSION['usces_member']['registered'] = $member['mem_registered'];
4845 $_SESSION['usces_member']['nicename'] = $member['mem_nicename'];
4846 $_SESSION['usces_member']['country'] = $this->get_member_meta_value( 'customer_country', $member['ID'] );
4847 $_SESSION['usces_member']['status'] = $member['mem_status'];
4848 $this->set_session_custom_member( $member['ID'] );
4849 $this->get_current_member();
4850
4851 do_action( 'usces_action_after_login' );
4852 $this->set_cookie( $cookie );
4853 return apply_filters( 'usces_filter_member_login', 'member', $member );
4854 }
4855 }
4856 } elseif ( isset( $_POST['loginmail'] ) && WCUtils::is_blank( $_POST['loginmail'] ) && isset( $_POST['loginpass'] ) && WCUtils::is_blank( $_POST['loginpass'] ) && isset( $cookie['rme'] ) && 'forever' != $cookie['rme'] ) {
4857 $rateLimiter->saveLoginFailed();
4858 do_action( 'usces_action_member_login_failed', '', 'empty_credentials' );
4859 return 'login';
4860 } elseif ( isset( $_POST['loginmail'] ) && WCUtils::is_blank( $_POST['loginpass'] ) && isset( $cookie['rme'] ) && 'forever' != $cookie['rme'] ) {
4861 $rateLimiter->saveLoginFailed();
4862 do_action( 'usces_action_member_login_failed', trim( $_POST['loginmail'] ), 'empty_password' );
4863 $this->error_message = __( '<b>Error:</b> Enter the password.', 'usces' );
4864 return 'login';
4865 } elseif ( ! isset( $_POST['loginmail'] ) ) {
4866 if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) {
4867 $rateLimiter->saveLoginFailed();
4868 do_action( 'usces_action_member_login_failed', '', 'no_login_id' );
4869 }
4870 return 'login';
4871 } else {
4872
4873 if ( isset( $_POST['loginmail'] ) ) {
4874 $nonce = isset( $_REQUEST['wel_nonce'] ) ? $_REQUEST['wel_nonce'] : '';
4875 if ( ! $nonce ) {
4876 $nonce = isset( $_REQUEST['wc_nonce'] ) ? $_REQUEST['wc_nonce'] : '';
4877 }
4878 if ( ! $this->verify_member_nonce( $nonce, 'post_member' ) && ! $this->is_member_logged_in() ) {
4879 $rateLimiter->saveLoginFailed();
4880 do_action( 'usces_action_member_login_failed', trim( $_POST['loginmail'] ), 'invalid_nonce' );
4881 die( 'Security check4' );
4882 }
4883 }
4884
4885 $email = isset( $_POST['loginmail'] ) ? trim( $_POST['loginmail'] ) : '';
4886 // $pass = isset( $_POST['loginpass']) ? usces_get_hash(trim( $_POST['loginpass'])) : '';
4887 $salt = usces_get_salt( $email );
4888 $pass = usces_get_hash( trim( $_POST['loginpass'] ), $salt );
4889 $member_table = usces_get_tablename( 'usces_member' );
4890
4891 $query = $wpdb->prepare( "SELECT * FROM $member_table WHERE mem_email = %s AND mem_pass = %s", $email, $pass );
4892 $query = apply_filters( 'usces_filter_member_login_query', $query, $email, $pass );
4893 $member = $wpdb->get_row( $query, ARRAY_A );
4894
4895 if ( empty( $member ) ) {
4896 $rateLimiter->saveLoginFailed();
4897 do_action( 'usces_action_member_login_failed', $email, 'invalid_credentials' );
4898 $this->current_member['email'] = htmlspecialchars( $email, ENT_COMPAT );
4899 $this->error_message = __( '<b>Error:</b> Your E-mail or password is incorrect.', 'usces' );
4900 return 'login';
4901 } else {
4902
4903 if ( USCES_VERIFY_MEMBERS_EMAIL::$opts['switch_flag'] ) {
4904 $verify_flag = $this->get_member_meta_value( '_verifying', $member['ID'] );
4905 } else {
4906 $verify_flag = '';
4907 }
4908 if ( ! empty( $verify_flag ) ) {
4909 $rateLimiter->saveLoginFailed();
4910 do_action( 'usces_action_member_login_failed', $email, 'unverified_email' );
4911 $this->error_message = __( '<b>Error:</b> Membership registration is not complete.', 'usces' );
4912 return 'login';
4913 }
4914
4915 $_SESSION['usces_member']['ID'] = $member['ID'];
4916 $_SESSION['usces_member']['mailaddress1'] = $member['mem_email'];
4917 $_SESSION['usces_member']['mailaddress2'] = $member['mem_email'];
4918 $_SESSION['usces_member']['point'] = $member['mem_point'];
4919 $_SESSION['usces_member']['name1'] = $member['mem_name1'];
4920 $_SESSION['usces_member']['name2'] = $member['mem_name2'];
4921 $_SESSION['usces_member']['name3'] = $member['mem_name3'];
4922 $_SESSION['usces_member']['name4'] = $member['mem_name4'];
4923 $_SESSION['usces_member']['zipcode'] = $member['mem_zip'];
4924 $_SESSION['usces_member']['pref'] = $member['mem_pref'];
4925 $_SESSION['usces_member']['address1'] = $member['mem_address1'];
4926 $_SESSION['usces_member']['address2'] = $member['mem_address2'];
4927 $_SESSION['usces_member']['address3'] = $member['mem_address3'];
4928 $_SESSION['usces_member']['tel'] = $member['mem_tel'];
4929 $_SESSION['usces_member']['fax'] = $member['mem_fax'];
4930 $_SESSION['usces_member']['delivery_flag'] = $member['mem_delivery_flag'];
4931 $_SESSION['usces_member']['delivery'] = ! empty( $member['mem_delivery'] ) ? wel_safe_unserialize( $member['mem_delivery'] ) : '';
4932 $_SESSION['usces_member']['registered'] = $member['mem_registered'];
4933 $_SESSION['usces_member']['nicename'] = $member['mem_nicename'];
4934 $_SESSION['usces_member']['country'] = $this->get_member_meta_value( 'customer_country', $member['ID'] );
4935 $_SESSION['usces_member']['status'] = $member['mem_status'];
4936 $this->set_session_custom_member( $member['ID'] );
4937 $this->get_current_member();
4938 $rateLimiter->clear_login_failed();
4939
4940 if ( isset( $_POST['rememberme'] ) ) {
4941 $_forever = $this->set_login_forever( $member['ID'] );
4942 $cookie['name'] = $_forever;
4943 $cookie['rme'] = 'forever';
4944 $this->set_cookie( $cookie );
4945 } else {
4946 $cookie['name'] = '';
4947 $cookie['rme'] = '';
4948 $this->set_cookie( $cookie );
4949 }
4950
4951 do_action( 'usces_action_after_login' );
4952 return apply_filters( 'usces_filter_member_login', 'member', $member );
4953 }
4954 }
4955 }
4956
4957 public function set_login_forever( $member_id ) {
4958 if ( ! $member_id ) {
4959 return false;
4960 }
4961
4962 $_forever = wp_generate_password( 32, false, false );
4963 $this->set_member_meta_value( '_forever', $_forever, $member_id );
4964 return $_forever;
4965 }
4966
4967 public function set_member_session_data( $member_id ) {
4968 global $wpdb;
4969
4970 $member_table = usces_get_tablename( 'usces_member' );
4971 $query = $wpdb->prepare( "SELECT * FROM $member_table WHERE ID = %s", $member_id );
4972 $member = $wpdb->get_row( $query, ARRAY_A );
4973 if ( ! empty( $member ) ) {
4974 $_SESSION['usces_member']['ID'] = $member['ID'];
4975 $_SESSION['usces_member']['mailaddress1'] = $member['mem_email'];
4976 $_SESSION['usces_member']['mailaddress2'] = $member['mem_email'];
4977 $_SESSION['usces_member']['point'] = $member['mem_point'];
4978 $_SESSION['usces_member']['name1'] = $member['mem_name1'];
4979 $_SESSION['usces_member']['name2'] = $member['mem_name2'];
4980 $_SESSION['usces_member']['name3'] = $member['mem_name3'];
4981 $_SESSION['usces_member']['name4'] = $member['mem_name4'];
4982 $_SESSION['usces_member']['zipcode'] = $member['mem_zip'];
4983 $_SESSION['usces_member']['pref'] = $member['mem_pref'];
4984 $_SESSION['usces_member']['address1'] = $member['mem_address1'];
4985 $_SESSION['usces_member']['address2'] = $member['mem_address2'];
4986 $_SESSION['usces_member']['address3'] = $member['mem_address3'];
4987 $_SESSION['usces_member']['tel'] = $member['mem_tel'];
4988 $_SESSION['usces_member']['fax'] = $member['mem_fax'];
4989 $_SESSION['usces_member']['delivery_flag'] = $member['mem_delivery_flag'];
4990 $_SESSION['usces_member']['delivery'] = ! empty( $member['mem_delivery'] ) ? wel_safe_unserialize( $member['mem_delivery'] ) : '';
4991 $_SESSION['usces_member']['registered'] = $member['mem_registered'];
4992 $_SESSION['usces_member']['nicename'] = $member['mem_nicename'];
4993 $_SESSION['usces_member']['country'] = $this->get_member_meta_value( 'customer_country', $member['ID'] );
4994 $_SESSION['usces_member']['status'] = $member['mem_status'];
4995 $this->set_session_custom_member( $member['ID'] );
4996 $this->get_current_member();
4997 }
4998 return;
4999 }
5000
5001 public function member_just_login( $email, $pass ) {
5002 global $wpdb;
5003 // $pass = usces_get_hash($pass);
5004 $salt = usces_get_salt( $email );
5005 $pass = usces_get_hash( $pass, $salt );
5006 $member_table = usces_get_tablename( 'usces_member' );
5007
5008 $query = $wpdb->prepare( "SELECT * FROM $member_table WHERE mem_email = %s AND mem_pass = %s", $email, $pass );
5009 $member = $wpdb->get_row( $query, ARRAY_A );
5010 if ( empty( $member ) ) {
5011 $this->current_member['email'] = htmlspecialchars( $email, ENT_COMPAT );
5012 $this->error_message = __( '<b>Error:</b> Password is not correct.', 'usces' );
5013 return 'login';
5014 } else {
5015 $_SESSION['usces_member']['ID'] = $member['ID'];
5016 $_SESSION['usces_member']['mailaddress1'] = $member['mem_email'];
5017 $_SESSION['usces_member']['mailaddress2'] = $member['mem_email'];
5018 $_SESSION['usces_member']['point'] = $member['mem_point'];
5019 $_SESSION['usces_member']['name1'] = $member['mem_name1'];
5020 $_SESSION['usces_member']['name2'] = $member['mem_name2'];
5021 $_SESSION['usces_member']['name3'] = $member['mem_name3'];
5022 $_SESSION['usces_member']['name4'] = $member['mem_name4'];
5023 $_SESSION['usces_member']['zipcode'] = $member['mem_zip'];
5024 $_SESSION['usces_member']['pref'] = $member['mem_pref'];
5025 $_SESSION['usces_member']['address1'] = $member['mem_address1'];
5026 $_SESSION['usces_member']['address2'] = $member['mem_address2'];
5027 $_SESSION['usces_member']['address3'] = $member['mem_address3'];
5028 $_SESSION['usces_member']['tel'] = $member['mem_tel'];
5029 $_SESSION['usces_member']['fax'] = $member['mem_fax'];
5030 $_SESSION['usces_member']['delivery_flag'] = $member['mem_delivery_flag'];
5031 $_SESSION['usces_member']['delivery'] = ! empty( $member['mem_delivery'] ) ? wel_safe_unserialize( $member['mem_delivery'] ) : '';
5032 $_SESSION['usces_member']['registered'] = $member['mem_registered'];
5033 $_SESSION['usces_member']['nicename'] = $member['mem_nicename'];
5034 $_SESSION['usces_member']['country'] = $this->get_member_meta_value( 'customer_country', $member['ID'] );
5035 $_SESSION['usces_member']['status'] = $member['mem_status'];
5036 $this->set_session_custom_member( $member['ID'] );
5037 $this->get_current_member();
5038
5039 do_action( 'usces_action_after_login' );
5040 return apply_filters( 'usces_filter_member_login', 'member', $member );
5041 }
5042 }
5043
5044 public function member_logout() {
5045 do_action( 'usces_action_before_logout' );
5046 $cookie = $this->get_cookie();
5047 $cookie['name'] = '';
5048 $cookie['rme'] = '';
5049 $options = get_option( 'usces' );
5050
5051 $this->set_cookie( $cookie );
5052
5053 $fcookie = $this->get_cookie( $options['usces_key'] );
5054
5055 unset( $_SESSION['usces_member'], $_SESSION['usces_entry'] );
5056 do_action( 'usces_action_member_logout' );
5057 }
5058
5059 public function get_current_member() {
5060 if ( isset( $_SESSION['usces_member']['ID'] ) ) {
5061 $this->current_member['id'] = $_SESSION['usces_member']['ID'];
5062 $this->current_member['name'] = usces_localized_name( $_SESSION['usces_member']['name1'], $_SESSION['usces_member']['name2'], 'return' );
5063 } else {
5064 $this->current_member['id'] = 0;
5065 $this->current_member['name'] = __( 'guest', 'usces' );
5066 }
5067 }
5068
5069 public function get_member() {
5070 $res = array(
5071 'ID' => '',
5072 'registered' => '',
5073 'mailaddress1' => '',
5074 'mailaddress2' => '',
5075 'password1' => '',
5076 'password2' => '',
5077 'point' => '',
5078 'name1' => '',
5079 'name2' => '',
5080 'name3' => '',
5081 'name4' => '',
5082 'zipcode' => '',
5083 'address1' => '',
5084 'address2' => '',
5085 'address3' => '',
5086 'tel' => '',
5087 'fax' => '',
5088 'country' => '',
5089 'pref' => '',
5090 'status' => '',
5091 );
5092 if ( ! empty( $_SESSION['usces_member'] ) ) {
5093 foreach ( $_SESSION['usces_member'] as $key => $value ) {
5094 if ( is_array( $_SESSION['usces_member'][ $key ] ) ) {
5095 $res[ $key ] = stripslashes_deep( $value );
5096 } else {
5097 $res[ $key ] = null !== $value ? stripslashes( $value ) : '';
5098 }
5099 }
5100 }
5101 return $res;
5102 }
5103
5104 public function get_member_info( $mid ) {
5105 global $wpdb;
5106 $infos = array();
5107 $table = usces_get_tablename( 'usces_member' );
5108 $query = $wpdb->prepare( "SELECT * FROM $table WHERE ID = %d", $mid );
5109 $datas = $wpdb->get_results( $query, ARRAY_A );
5110 if ( $datas ) {
5111 $infos = $datas[0];
5112
5113 $table = usces_get_tablename( 'usces_member_meta' );
5114 $query = $wpdb->prepare( "SELECT meta_key, meta_value FROM $table WHERE member_id = %d", $mid );
5115 $metas = $wpdb->get_results( $query, ARRAY_A );
5116
5117 foreach ( $metas as $meta ) {
5118 $infos[ $meta['meta_key'] ] = wel_safe_maybe_unserialize( $meta['meta_value'] );
5119 }
5120 }
5121 return $infos;
5122 }
5123
5124 public function set_member_info( $data = array(), $mid = '' ) {
5125 global $wpdb;
5126
5127 $table = usces_get_tablename( 'usces_member' );
5128 $res = $wpdb->update( $table, $data, array( 'ID' => $mid ), null, array( '%d' ) );
5129 return $res;
5130 }
5131
5132 public function check_member_email( $email ) {
5133 global $wpdb;
5134
5135 $member_table_name = usces_get_tablename( 'usces_member' );
5136 $query = $wpdb->prepare( "SELECT ID FROM $member_table_name WHERE mem_email = %s", trim( $email ) );
5137 $id = $wpdb->get_var( $query );
5138 return $id;
5139 }
5140
5141 public function is_order( $mid, $oid ) {
5142 global $wpdb;
5143
5144 $mid = (int) $mid;
5145 $oid = (int) $oid;
5146
5147 $table = $wpdb->prefix . 'usces_order';
5148 $query = $wpdb->prepare( "SELECT ID FROM $table WHERE ID = %d AND mem_id = %d", $oid, $mid );
5149 $mem_id = $wpdb->get_var( $query );
5150 if ( empty( $mem_id ) ) {
5151 return false;
5152 } else {
5153 return true;
5154 }
5155 }
5156
5157 public function is_purchased_item( $mid, $post_id, $sku = null, $order_id = null ) {
5158 global $wpdb;
5159 $res = false;
5160
5161 if ( empty( $order_id ) ) {
5162 $history = $this->get_member_history( $mid, true );
5163 foreach ( $history as $umhs ) {
5164 $cart = $umhs['cart'];
5165 $status = $umhs['order_status'];
5166 $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
5167 for ( $i = 0; $i < $cart_count; $i++ ) {
5168 $cart_row = $cart[ $i ];
5169 $sku_code = urldecode( $cart_row['sku'] );
5170 if ( empty( $sku ) ) {
5171 if ( $cart_row['post_id'] == $post_id && ( false === strpos( $status, 'noreceipt' ) && false === strpos( $status, 'pending' ) ) ) {
5172 $res = true;
5173 break 2;
5174 } elseif ( $cart_row['post_id'] == $post_id && ( false !== strpos( $status, 'noreceipt' ) || false !== strpos( $status, 'pending' ) ) ) {
5175 $res = 'noreceipt';
5176 break 2;
5177 }
5178 } else {
5179 if ( $cart_row['post_id'] == $post_id && $sku_code == $sku && ( false === strpos( $status, 'noreceipt' ) && false === strpos( $status, 'pending' ) ) ) {
5180 $res = true;
5181 break 2;
5182 } elseif ( $cart_row['post_id'] == $post_id && $sku_code == $sku && (false !== strpos( $status, 'noreceipt' ) || false !== strpos( $status, 'pending' ) ) ) {
5183 $res = 'noreceipt';
5184 break 2;
5185 }
5186 }
5187 }
5188 }
5189 } else {
5190 $order_table_name = $wpdb->prefix . 'usces_order';
5191 $query = $wpdb->prepare( "SELECT order_status FROM $order_table_name WHERE ID = %d AND mem_id = %d",
5192 $order_id, $mid
5193 );
5194 $order = $wpdb->get_row( $query );
5195 if ( is_null( $order ) ) { // 該当の受注データが一件も見つからなかった場合、購入していないと判断する.
5196 $res = false;
5197 } else { // 該当の受注データが見つかった場合には受注ステータスを確認する処理を行う.
5198 $status = $order->order_status;
5199 $cart = usces_get_ordercartdata( $order_id );
5200 foreach ( $cart as $cart_row ) {
5201 $sku_code = urldecode( $cart_row['sku'] );
5202 if ( empty( $sku ) ) {
5203 if ( $cart_row['post_id'] == $post_id && ( false === strpos( $status, 'noreceipt' ) && false === strpos( $status, 'pending' ) && false === strpos( $status, 'cancel' ) ) ) {
5204 $res = true;
5205 break;
5206 } elseif ( $cart_row['post_id'] == $post_id && ( false !== strpos( $status, 'noreceipt' ) || false !== strpos( $status, 'pending' ) || false !== strpos( $status, 'cancel' ) ) ) {
5207 $res = 'noreceipt';
5208 break;
5209 }
5210 } else {
5211 if ( $cart_row['post_id'] == $post_id && $sku_code == $sku && ( false === strpos( $status, 'noreceipt' ) && false === strpos( $status, 'pending' ) && false === strpos( $status, 'cancel' ) ) ) {
5212 $res = true;
5213 break;
5214 } elseif ( $cart_row['post_id'] == $post_id && $sku_code == $sku && ( false !== strpos( $status, 'noreceipt' ) || false !== strpos( $status, 'pending' ) || false !== strpos( $status, 'cancel' ) ) ) {
5215 $res = 'noreceipt';
5216 break;
5217 }
5218 }
5219 }
5220 }
5221 }
5222
5223 return apply_filters( 'usces_filter_is_purchased_item', $res, $mid, $post_id, $sku, $order_id );
5224 }
5225
5226 public function get_order_data( $order_id, $mode = '' ) {
5227 global $wpdb;
5228 $order_table = $wpdb->prefix . 'usces_order';
5229
5230 $query = $wpdb->prepare( "SELECT * FROM $order_table WHERE ID = %d", $order_id );
5231
5232 if ( 'direct' == $mode ) {
5233 $value = $wpdb->get_row( $query, ARRAY_A );
5234 return $value;
5235 }
5236
5237 $value = $wpdb->get_row( $query );
5238
5239 if ( null == $value ) {
5240 return false;
5241 } else {
5242 $res = array();
5243 }
5244 if ( strpos( $value->order_status, 'cancel' ) !== false || strpos( $value->order_status, 'estimate' ) !== false ) {
5245 return false;
5246 }
5247
5248 $total_price = $value->order_item_total_price - $value->order_usedpoint + $value->order_discount + $value->order_shipping_charge + $value->order_cod_fee + $value->order_tax;
5249 if ( $total_price < 0 ) {
5250 $total_price = 0;
5251 }
5252 $res = array(
5253 'ID' => $value->ID,
5254 'mem_id' => $value->mem_id,
5255 'cart' => wel_safe_unserialize( $value->order_cart ),
5256 'condition' => wel_safe_unserialize( $value->order_condition ),
5257 'getpoint' => $value->order_getpoint,
5258 'usedpoint' => $value->order_usedpoint,
5259 'discount' => $value->order_discount,
5260 'payment_name' => $value->order_payment_name,
5261 'shipping_charge' => $value->order_shipping_charge,
5262 'cod_fee' => $value->order_cod_fee,
5263 'tax' => $value->order_tax,
5264 'end_price' => $total_price,
5265 'status' => $value->order_status,
5266 'date' => mysql2date( __( 'Y/m/d' ), $value->order_date ),
5267 'modified' => mysql2date( __( 'Y/m/d' ), $value->order_modified ),
5268 );
5269
5270 return $res;
5271 }
5272
5273 public function get_orderIDs_by_postID( $mem_id, $post_id ) {
5274 global $wpdb;
5275 $order_table = $wpdb->prefix . 'usces_order';
5276
5277 $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 );
5278 $rows = $wpdb->get_query( $query, ARRAY_A );
5279
5280 if ( null == $value ) {
5281 return false;
5282 } else {
5283 foreach ( $rows as $row ) {
5284 if ( strpos( $row['order_status'], 'cancel' ) !== false || strpos( $row['order_status'], 'estimate' ) !== false ) {
5285 continue;
5286 } else {
5287 $carts = wel_safe_unserialize( $row['order_cart'] );
5288 foreach ( $carts as $cart ) {
5289 if ( $post_id == $cart['post_id'] ) {
5290 $res[] = $row['ID'];
5291 break;
5292 }
5293 }
5294 }
5295 }
5296 }
5297 return $res;
5298 }
5299
5300 public function incart_check() {
5301 $mes = array();
5302
5303 $ids = array_keys( $_POST['inCart'] );
5304 $post_id = $ids[0];
5305 $skus = array_keys( $_POST['inCart'][ $post_id ] );
5306 $sku = $skus[0];
5307 $sku_code = urldecode( $sku );
5308 $quant = isset( $_POST['quant'][ $post_id ][ $sku ] ) ? (int) $_POST['quant'][ $post_id ][ $sku ] : 1;
5309 $stock = $this->getItemZaikoNum( $post_id, $sku );
5310 $zaiko_id = (int) $this->getItemZaikoStatusId( $post_id, $sku );
5311 $product = wel_get_product( $post_id );
5312 $itemRestriction = isset( $product['itemRestriction'] ) ? $product['itemRestriction'] : '';
5313 $itemOrderAcceptable = $this->getItemOrderAcceptable( $post_id );
5314
5315 if ( 1 > $quant ) {
5316 $mes[ $post_id ][ $sku ] = __( 'enter the correct amount', 'usces' ) . '<br />';
5317 } elseif ( $quant > (int) $itemRestriction && ! WCUtils::is_blank( $itemRestriction ) && ! WCUtils::is_zero( $itemRestriction ) ) {
5318 $mes[ $post_id ][ $sku ] = sprintf( __( 'This article is limited by %d at a time.', 'usces' ), $itemRestriction ) . '<br />';
5319 } elseif ( 1 != $itemOrderAcceptable && $quant > (int) $stock && ! WCUtils::is_blank( $stock ) ) {
5320 $mes[ $post_id ][ $sku ] = __( 'Sorry, stock is insufficient.', 'usces' ) . ' ' . __( 'Current stock', 'usces' ) . $stock . '<br />';
5321 } elseif ( 1 != $itemOrderAcceptable && !$this->is_item_zaiko( $post_id, $sku_code ) ) {
5322 $mes[ $post_id ][ $sku ] = __( 'Sorry, this item is sold out.', 'usces' ) . '<br />';
5323 } else {
5324 $mes[ $post_id ][ $sku ] = '';
5325 }
5326
5327 $ioptkeys = $this->get_itemOptionKey( $post_id, true );
5328 if ( $ioptkeys ) {
5329 foreach ( $ioptkeys as $key => $value ) {
5330 $optValues = $this->get_itemOptions( urldecode( $value ), $post_id );
5331 if ( 0 == $optValues['means'] ) { // case of select.
5332 if ( $optValues['essential'] && '#NONE#' == $_POST['itemOption'][ $post_id ][ $sku ][ $value ] ) {
5333 $mes[ $post_id ][ $sku ] .= sprintf( __( 'Chose the %s', 'usces' ), urldecode( $value ) ) . '<br />';
5334 }
5335 } elseif ( 1 == $optValues['means'] ) { // case of multiselect.
5336 if ( $optValues['essential'] ) {
5337 $mselect = 0;
5338 foreach ( (array) $_POST['itemOption'][ $post_id ][ $sku ][ $value ] as $mvalue ) {
5339 if ( ! empty( $mvalue ) && '#NONE#' != $mvalue ) {
5340 $mselect++;
5341 }
5342 }
5343 if ( $mselect == 0 ) {
5344 $mes[ $post_id ][ $sku ] .= sprintf( __( 'Chose the %s', 'usces' ), urldecode( $value ) ) . '<br />';
5345 }
5346 }
5347 } elseif ( in_array( $optValues['means'], array( 3, 4 ) ) ) { // case of radio & checkbox.
5348 if ( $optValues['essential'] ) {
5349 if ( ! isset( $_POST['itemOption'][ $post_id ][ $sku ][ $value ] ) ) {
5350 $mes[ $post_id ][ $sku ] .= sprintf( __( 'Chose the %s', 'usces' ), urldecode( $value ) ) . '<br />';
5351 }
5352 }
5353 } else { // case of text.
5354 if ( $optValues['essential'] && WCUtils::is_blank( $_POST['itemOption'][ $post_id ][ $sku ][ $value ] ) ) {
5355 $mes[ $post_id ][ $sku ] .= sprintf( __( 'Input the %s', 'usces' ), urldecode( $value ) ) . '<br />';
5356 }
5357 }
5358 }
5359 }
5360
5361 $mes = apply_filters( 'usces_filter_incart_check', $mes, $post_id, $sku );
5362
5363 if ( isset( $mes[ $post_id ] ) && is_array( $mes[ $post_id ] ) ) {
5364 $rembr = array();
5365 foreach ( $mes[ $post_id ] as $skukey => $skuvalue ) {
5366 if ( ! empty( $skuvalue ) ) {
5367 $rembr[ $post_id ][ $skukey ] = preg_replace( '/<br\s*\/?>\s*$/', '', $skuvalue );
5368 }
5369 }
5370 $mes = $rembr;
5371 }
5372
5373 if ( ! empty( $mes ) ) {
5374 $_SESSION['usces_singleitem']['itemOption'] = isset( $_POST['itemOption'] ) ? $_POST['itemOption'] : array();
5375 $_SESSION['usces_singleitem']['quant'] = isset( $_POST['quant'] ) ? (int) $_POST['quant'] : 1;
5376 $_SESSION['usces_singleitem']['error_message'] = $mes;
5377 if ( false === strpos( $_POST['usces_referer'], 'http' ) ) {
5378 $parse_url = parse_url( get_home_url() );
5379 $port = '';
5380 if ( isset( $parse_url['port'] ) && ! empty( $parse_url['port'] ) ) {
5381 $port = ':' . $parse_url['port'];
5382 }
5383 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 ) );
5384 } else {
5385 header( 'location: ' . esc_url( $_POST['usces_referer'] ) . apply_filters( 'usces_filter_incart_redirect', '#cart_button', $post_id, $sku ) );
5386 }
5387 exit;
5388 }
5389
5390 do_action( 'usces_action_incart_checked', $mes, $post_id, $sku );
5391 }
5392
5393 public function zaiko_check() {
5394
5395 $logged_in_member = $this->get_member();
5396 if ( ! empty( $logged_in_member['ID'] ) ) {
5397 if ( ! $this->member_exists( $logged_in_member['ID'] ) ) {
5398 $mes = __( 'Your membership information could not be verified.', 'usces' );
5399 $this->error_message = $mes;
5400 $this->member_logout();
5401 return $mes;
5402 }
5403 }
5404
5405 $mes = '';
5406 $cart = $this->cart->get_cart();
5407 $stocks = array();
5408
5409 $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
5410 for ( $i = 0; $i < $cart_count; $i++ ) {
5411 $cart_row = $cart[ $i ];
5412 $post_id = $cart_row['post_id'];
5413 $sku = $cart_row['sku'];
5414 $sku_code = urldecode( $cart_row['sku'] );
5415
5416 $quant = ( isset( $_POST['quant'][ $i ][ $post_id ][ $sku ] ) ) ? trim( $_POST['quant'][ $i ][ $post_id ][ $sku ] ) : $cart_row['quantity'];
5417 $zaiko_id = (int) $this->getItemZaikoStatusId( $post_id, $sku_code );
5418 $stock = $this->getItemZaikoNum( $post_id, $sku_code );
5419 if ( ! isset( $stocks[ $post_id ][ $sku ] ) ) {
5420 if ( ! WCUtils::is_blank( $stock ) ) {
5421 $stocks[ $post_id ][ $sku ] = $stock;
5422 } else {
5423 $stocks[ $post_id ][ $sku ] = null;
5424 }
5425 }
5426 $checkstock = $stocks[ $post_id ][ $sku ];
5427 $stocks[ $post_id ][ $sku ] = $stocks[ $post_id ][ $sku ] - $quant;
5428 $product = wel_get_product( $post_id );
5429 $itemRestriction = isset( $product['itemRestriction'] ) ? $product['itemRestriction'] : '';
5430 $itemOrderAcceptable = $this->getItemOrderAcceptable( $post_id );
5431 $post_status = get_post_status( $post_id );
5432
5433 if ( 1 > (int) $quant ) {
5434 $mes .= sprintf( __( 'Enter the correct amount for the No.%d item.', 'usces' ), ( $i + 1 ) ) . '<br />';
5435 } elseif ( ! $this->is_item_zaiko( $post_id, $sku_code ) || ( 1 != $itemOrderAcceptable && WCUtils::is_zero( $stock ) ) || 'publish' != $post_status ) {
5436 $mes .= sprintf( __( 'Sorry, No.%d item is sold out.', 'usces' ), ( $i + 1 ) ) . '<br />';
5437 } elseif ( $quant > (int) $itemRestriction && ! WCUtils::is_blank( $itemRestriction ) && ! WCUtils::is_zero( $itemRestriction ) ) {
5438 $mes .= sprintf( __( 'This article is limited by %1$d at a time for the No.%2$d item.', 'usces' ), $itemRestriction, ( $i + 1 ) ) . '<br />';
5439 } elseif ( 1 != $itemOrderAcceptable && 0 > $stocks[ $post_id ][ $sku ] && ! WCUtils::is_blank( $stock ) ) {
5440 $mes .= sprintf( __( 'Stock of No.%1$d item is remainder %2$d.', 'usces' ), ( $i + 1 ), $checkstock ) . '<br />';
5441 }
5442 }
5443 $mes = apply_filters( 'usces_filter_zaiko_check', $mes, $cart);
5444 return $mes;
5445 }
5446
5447 /**
5448 * Check if the member exists in the database or not.
5449 *
5450 * @param integer $member_id The id of the member.
5451 * @return boolean true/false
5452 */
5453 public function member_exists( $member_id ) {
5454 $member_info = $this->get_member_info( $member_id );
5455 if ( empty( $member_info ) ) {
5456 return false;
5457 } else {
5458 return true;
5459 }
5460 }
5461
5462 public function get_pwd_errors( $password ) {
5463 if ( WCUtils::is_blank( $password ) ) {
5464 return __( 'Please enter a password.', 'usces' ) . '<br />';
5465 }
5466
5467 $ret = '';
5468 $system_option = $this->options['system'];
5469 $pwd_rule_min = $system_option['member_pass_rule_min'];
5470 $pwd_rule_max = empty( $system_option['member_pass_rule_max'] ) ? 30 : $system_option['member_pass_rule_max'];
5471 if ( strlen( $password ) < $pwd_rule_min || strlen( $password ) > $pwd_rule_max ) {
5472 if ( $pwd_rule_min === $pwd_rule_max ) {
5473 $rule = sprintf( __( '%s characters long', 'usces' ), $pwd_rule_min );
5474 } else {
5475 $rule = sprintf( __( '%1$s characters and no more than %2$s characters', 'usces' ), $pwd_rule_min, $pwd_rule_max );
5476 }
5477 $ret .= sprintf( __( 'Password must be at least %s.', 'usces' ), $rule ) . '<br />';
5478 }
5479 if ( ! empty( $system_option['member_pass_rule_upercase'] ) && ! preg_match( '@[A-Z]@', $password ) ) {
5480 $ret .= __( 'Password must contain at least one upper-case alphabetics character.', 'usces' ) . '<br />';
5481 }
5482 if ( ! empty( $system_option['member_pass_rule_lowercase'] ) && ! preg_match( '@[a-z]@', $password ) ) {
5483 $ret .= __( 'Password must contain at least one lower-case alphabetics character.', 'usces' ) . '<br />';
5484 }
5485 if ( ! empty( $system_option['member_pass_rule_digit'] ) && ! preg_match( '@[0-9]@', $password ) ) {
5486 $ret .= __( 'Password must contain at least one numeric character.', 'usces' ) . '<br />';
5487 }
5488 if ( ! empty( $system_option['member_pass_rule_symbol'] ) && ! preg_match( '@[\W]@', $password ) ) {
5489 $ret .= __( 'Password must contain at least one symbolic character.', 'usces' ) . '<br />';
5490 }
5491
5492 return $ret;
5493 }
5494
5495 public function member_check() {
5496 do_action( 'usces_action_before_member_check' );
5497
5498 $mes = '';
5499 $usces_member_old = $_SESSION['usces_member'];
5500 foreach ( $_POST['member'] as $key => $vlue ) {
5501 if ( 'password1' !== $key && 'password2' !== $key && 'mailaddress2' !== $key ) {
5502 $_SESSION['usces_member'][ $key ] = trim( $vlue );
5503 }
5504 }
5505
5506 if ( 'newmemberform' == $_POST['member_regmode'] ||
5507 ( 'editmemberform' === $_POST['member_regmode'] && ! ( WCUtils::is_blank( $_POST['member']['password1'] ) && WCUtils::is_blank( $_POST['member']['password2'] ) ) ) ||
5508 ( 'updatememberform' === $_POST['member_regmode'] && ! ( WCUtils::is_blank( $_POST['member']['password1'] ) && WCUtils::is_blank( $_POST['member']['password2'] ) ) ) ) {
5509 $mes = $this->get_pwd_errors( $_POST['member']['password1'] );
5510 }
5511
5512 if ( 'editmemberform' == $_POST['member_regmode'] || 'updatememberform' == $_POST['member_regmode'] ) {
5513 if ( trim( $_POST['member']['password1'] ) != trim( $_POST['member']['password2'] ) ) {
5514 $mes .= __( 'Password confirm does not match.', 'usces' ) . '<br />';
5515 }
5516 if ( ! is_email( $_POST['member']['mailaddress1'] ) || WCUtils::is_blank( $_POST['member']['mailaddress1'] ) ) {
5517 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5518 } else {
5519 $this->get_current_member();
5520 $mem_id = $this->current_member['id'];
5521 $id = $this->check_member_email( $_POST['member']['mailaddress1'] );
5522 if ( ! empty( $id ) && $id != $mem_id ) {
5523 $mes .= __( 'This e-mail address can not be registered.', 'usces' ) . '<br />';
5524 } else {
5525 if ( isset( $_POST['member']['mailaddress2'] ) ) {
5526 if ( WCUtils::is_blank( $_POST['member']['mailaddress2'] ) ) {
5527 if ( $usces_member_old['mailaddress1'] !== $_POST['member']['mailaddress1'] ) {
5528 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5529 }
5530 } else {
5531 if ( trim( $_POST['member']['mailaddress1'] ) != trim( $_POST['member']['mailaddress2'] ) ) {
5532 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5533 }
5534 }
5535 }
5536 }
5537 }
5538 } elseif ( 'newmemberform' == $_POST['member_regmode'] ) {
5539 if ( trim( $_POST['member']['password1'] ) != trim( $_POST['member']['password2'] ) ) {
5540 $mes .= __( 'Password confirm does not match.', 'usces' ) . '<br />';
5541 }
5542 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'] ) ) {
5543 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5544 } else {
5545 $id = $this->check_member_email( $_POST['member']['mailaddress1'] );
5546 if ( ! empty( $id ) ) {
5547 $mes .= __( 'This e-mail address can not be registered.', 'usces' ) . '<br />';
5548 }
5549 }
5550 } else {
5551 $mes .= __( 'ERROR: I was not able to complete collective operation', 'usces' ) . '<br />';
5552 }
5553 if ( WCUtils::is_blank( $_POST['member']['name1'] ) ) {
5554 $mes .= __( 'Name is not correct', 'usces' ) . '<br />';
5555 }
5556
5557 $zip_check = false;
5558 $addressform = $this->options['system']['addressform'];
5559 $applyform = usces_get_apply_addressform( $addressform );
5560 if ( 'JP' === $applyform ) {
5561 if ( isset( $_POST['member']['country'] ) ) {
5562 if ( 'JP' === $_POST['member']['country'] ) {
5563 $zip_check = true;
5564 }
5565 } else {
5566 $base = usces_get_base_country();
5567 if ( 'JP' === $base ) {
5568 $zip_check = true;
5569 }
5570 }
5571 }
5572 $zip_check = apply_filters( 'usces_filter_zipcode_check', $zip_check );
5573 if ( WCUtils::is_blank( $_POST['member']['zipcode'] ) ) {
5574 if ( usces_is_required_field('zipcode') ) {
5575 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5576 }
5577 } else {
5578 if ( $zip_check ) {
5579 if ( ! preg_match( '/^[a-zA-Z0-9]+$/', $_POST['member']['zipcode'] ) ) {
5580 $_SESSION['usces_member']['zipcode'] = usces_convert_zipcode( $_POST['member']['zipcode'] );
5581 }
5582 if ( ! preg_match( '/^(([0-9]{3}-[0-9]{4})|([0-9]{7}))$/', $_SESSION['usces_member']['zipcode'] ) ) {
5583 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5584 }
5585 }
5586 }
5587 if ( __( '-- Select --', 'usces_dual' ) == $_POST['member']['pref'] && usces_is_required_field( 'states' ) ) {
5588 $mes .= __( 'enter the prefecture', 'usces' ) . '<br />';
5589 }
5590 if ( WCUtils::is_blank( $_POST['member']['address1'] ) && usces_is_required_field( 'address1' ) ) {
5591 $mes .= __( 'enter the city name', 'usces' ) . '<br />';
5592 }
5593 if ( WCUtils::is_blank( $_POST['member']['address2'] ) && usces_is_required_field( 'address2' ) ) {
5594 $mes .= __( 'enter house numbers', 'usces' ) . '<br />';
5595 }
5596 if ( WCUtils::is_blank( $_POST['member']['tel'] ) && usces_is_required_field( 'tel' ) ) {
5597 $mes .= __( 'enter phone numbers', 'usces' ) . '<br />';
5598 }
5599 if ( ! WCUtils::is_blank( $_POST['member']['tel'] ) && preg_match( '/[^\d\-+]/', trim( $_POST['member']['tel'] ) ) && usces_is_required_field( 'tel' ) ) {
5600 $mes .= __( 'Please input a phone number with a half size number.', 'usces' ) . '<br />';
5601 }
5602
5603 if ( 'editmemberform' !== $_POST['member_regmode'] && 'updatememberform' !== $_POST['member_regmode'] && isset( $this->options['agree_member'] ) && 'activate' === $this->options['agree_member'] ) {
5604 if ( ! isset( $_POST['agree_member_check'] ) ) {
5605 $mes .= __( 'Please accept the membership agreement.', 'usces' ) . '<br />';
5606 }
5607 }
5608
5609 $mes = apply_filters( 'usces_filter_member_check', $mes );
5610
5611 if ( ( 'editmemberform' == $_POST['member_regmode'] || 'updatememberform' == $_POST['member_regmode'] ) && '' != $mes ) {
5612 $_SESSION['usces_member'] = $usces_member_old;
5613 }
5614
5615 return $mes;
5616 }
5617
5618 public function member_check_fromcart() {
5619
5620 do_action( 'usces_action_before_member_check_fromcart' );
5621
5622 $mes = $this->get_pwd_errors( $_POST['customer']['password1'] );
5623
5624 if ( trim( $_POST['customer']['password1'] ) != trim( $_POST['customer']['password2'] ) ) {
5625 $mes .= __( 'Password confirm does not match.', 'usces' ) . '<br />';
5626 }
5627 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'] ) ) {
5628 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5629 }
5630 if ( WCUtils::is_blank( $_POST['customer']['name1'] ) ) {
5631 $mes .= __( 'Name is not correct', 'usces' ) . '<br />';
5632 }
5633 $zip_check = false;
5634 $addressform = $this->options['system']['addressform'];
5635 $applyform = usces_get_apply_addressform( $addressform );
5636 if ( 'JP' === $applyform ) {
5637 if ( isset( $_POST['customer']['country'] ) ) {
5638 if ( 'JP' === $_POST['customer']['country'] ) {
5639 $zip_check = true;
5640 }
5641 } else {
5642 $base = usces_get_base_country();
5643 if ( 'JP' === $base ) {
5644 $zip_check = true;
5645 }
5646 }
5647 }
5648 $zip_check = apply_filters( 'usces_filter_zipcode_check', $zip_check );
5649 if ( WCUtils::is_blank( $_POST['customer']['zipcode'] ) ) {
5650 if ( usces_is_required_field( 'zipcode' ) ) {
5651 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5652 }
5653 } else {
5654 if ( $zip_check ) {
5655 if ( ! preg_match( '/^[a-zA-Z0-9]+$/', $_POST['customer']['zipcode'] ) ) {
5656 $_SESSION['usces_entry']['customer']['zipcode'] = usces_convert_zipcode( $_POST['customer']['zipcode'] );
5657 }
5658 if ( ! preg_match( '/^(([0-9]{3}-[0-9]{4})|([0-9]{7}))$/', $_SESSION['usces_entry']['customer']['zipcode'] ) ) {
5659 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5660 }
5661 }
5662 }
5663 if ( ( __( '-- Select --', 'usces' ) == $_POST['customer']['pref'] || '-- Select --' == $_POST['customer']['pref'] ) && usces_is_required_field( 'states' ) ) {
5664 $mes .= __( 'enter the prefecture', 'usces' ) . '<br />';
5665 }
5666 if ( WCUtils::is_blank( $_POST['customer']['address1'] ) && usces_is_required_field( 'address1' ) ) {
5667 $mes .= __( 'enter the city name', 'usces' ) . '<br />';
5668 }
5669 if ( WCUtils::is_blank( $_POST['customer']['address2'] ) && usces_is_required_field( 'address2' ) ) {
5670 $mes .= __( 'enter house numbers', 'usces' ) . '<br />';
5671 }
5672 if ( WCUtils::is_blank( $_POST['customer']['tel'] ) && usces_is_required_field( 'tel' ) ) {
5673 $mes .= __( 'enter phone numbers', 'usces' ) . '<br />';
5674 }
5675 if ( ! WCUtils::is_blank( $_POST['customer']['tel'] ) && preg_match( '/[^\d\-+]/', trim( $_POST['customer']['tel'] ) ) && usces_is_required_field( 'tel' ) ) {
5676 $mes .= __( 'Please input a phone number with a half size number.', 'usces' ) . '<br />';
5677 }
5678
5679 if ( isset( $this->options['agree_member'] ) && 'activate' === $this->options['agree_member'] ) {
5680 if ( ! isset( $_POST['agree_member_check'] ) ) {
5681 $mes .= __( 'Please accept the membership agreement.', 'usces' ) . '<br />';
5682 }
5683 }
5684
5685 $mes = apply_filters( 'usces_filter_member_check_fromcart', $mes );
5686
5687 return $mes;
5688 }
5689
5690 public function admin_member_check() {
5691 global $wpdb;
5692 $mes = '';
5693 if ( ! is_email( trim( $_POST['member']['email'] ) ) ) {
5694 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5695 } else {
5696 $member_table = usces_get_tablename( 'usces_member' );
5697 $mem_email = $wpdb->get_var( $wpdb->prepare( "SELECT mem_email FROM $member_table WHERE ID = %d LIMIT 1", trim( $_POST['member_id'] ) ) );
5698 if ( trim( $_POST['member']['email'] ) != $mem_email ) {
5699 $mem_ID = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $member_table WHERE mem_email = %s LIMIT 1", trim( $_POST['member']['email'] ) ) );
5700 if ( ! empty( $mem_ID ) ) {
5701 $mes .= __( 'This e-mail address has been already registered.', 'usces' ) . '<br />';
5702 }
5703 }
5704 }
5705 if ( WCUtils::is_blank( $_POST['member']['name1'] ) ) {
5706 $mes .= __( 'Name is not correct', 'usces' ) . '<br />';
5707 }
5708 if ( ! WCUtils::is_blank( $_POST['member']['tel'] ) && preg_match( '/[^\d\-+]/', trim( $_POST['member']['tel'] ) ) ) {
5709 $mes .= __( 'Please input a phone number with a half size number.', 'usces' ) . '<br />';
5710 }
5711 $mes = apply_filters( 'usces_filter_admin_member_check', $mes );
5712
5713 return $mes;
5714 }
5715
5716 public function customer_check() {
5717
5718 do_action( 'usces_action_before_customer_check' );
5719
5720 $mes = '';
5721 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'] ) ) {
5722 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5723 }
5724 if ( WCUtils::is_blank( $_POST['customer']['name1'] ) ) {
5725 $mes .= __( 'Name is not correct', 'usces' ) . '<br />';
5726 }
5727 $zip_check = false;
5728 $addressform = $this->options['system']['addressform'];
5729 $applyform = usces_get_apply_addressform( $addressform );
5730 if ( 'JP' === $applyform ) {
5731 if ( isset( $_POST['customer']['country'] ) ) {
5732 if ( 'JP' === $_POST['customer']['country'] ) {
5733 $zip_check = true;
5734 }
5735 } else {
5736 $base = usces_get_base_country();
5737 if ( 'JP' === $base ) {
5738 $zip_check = true;
5739 }
5740 }
5741 }
5742 $zip_check = apply_filters( 'usces_filter_zipcode_check', $zip_check );
5743 if ( WCUtils::is_blank( $_POST['customer']['zipcode'] ) ) {
5744 if ( usces_is_required_field( 'zipcode' ) ) {
5745 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5746 }
5747 } else {
5748 if ( $zip_check ) {
5749 if ( ! preg_match( '/^[a-zA-Z0-9]+$/', $_POST['customer']['zipcode'] ) ) {
5750 $_SESSION['usces_entry']['customer']['zipcode'] = usces_convert_zipcode( $_POST['customer']['zipcode'] );
5751 }
5752 if ( ! preg_match( '/^(([0-9]{3}-[0-9]{4})|([0-9]{7}))$/', $_SESSION['usces_entry']['customer']['zipcode'] ) ) {
5753 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5754 }
5755 }
5756 }
5757 if ( ( __( '-- Select --', 'usces' ) == $_POST['customer']['pref'] || '-- Select --' == $_POST['customer']['pref'] ) && usces_is_required_field( 'states' ) ) {
5758 $mes .= __( 'enter the prefecture', 'usces' ) . '<br />';
5759 }
5760 if ( WCUtils::is_blank( $_POST['customer']['address1'] ) && usces_is_required_field( 'address1' ) ) {
5761 $mes .= __( 'enter the city name', 'usces' ) . '<br />';
5762 }
5763 if ( WCUtils::is_blank( $_POST['customer']['address2'] ) && usces_is_required_field( 'address2' ) ) {
5764 $mes .= __( 'enter house numbers', 'usces' ) . '<br />';
5765 }
5766 if ( WCUtils::is_blank( $_POST['customer']['tel'] ) && usces_is_required_field( 'tel' ) ) {
5767 $mes .= __( 'enter phone numbers', 'usces' ) . '<br />';
5768 }
5769 if ( ! WCUtils::is_blank( $_POST['customer']['tel'] ) && preg_match( '/[^\d\-+]/', trim( $_POST['customer']['tel'] ) ) && usces_is_required_field( 'tel' ) ) {
5770 $mes .= __( 'Please input a phone number with a half size number.', 'usces' ) . '<br />';
5771 }
5772
5773 $mes = apply_filters( 'usces_filter_customer_check', $mes );
5774
5775 return $mes;
5776 }
5777
5778 public function admin_new_member_check() {
5779 global $wpdb;
5780
5781 $mes = $this->get_pwd_errors( $_POST['member']['password'] );
5782
5783 if ( ! is_email( trim( $_POST['member']['email'] ) ) ) {
5784 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
5785 } else {
5786 $member_table = usces_get_tablename( 'usces_member' );
5787 $mem_email = $wpdb->get_var( $wpdb->prepare( "SELECT mem_email FROM $member_table WHERE ID = %d LIMIT 1", trim( $_POST['member_id'] ) ) );
5788 if ( trim( $_POST['member']['email'] ) != $mem_email ) {
5789 $mem_ID = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $member_table WHERE mem_email = %s LIMIT 1", trim( $_POST['member']['email'] ) ) );
5790 if ( ! empty( $mem_ID ) ) {
5791 $mes .= __( 'This e-mail address has been already registered.', 'usces' ) . '<br />';
5792 }
5793 }
5794 }
5795
5796 if ( WCUtils::is_blank( $_POST['member']['name1'] ) ) {
5797 $mes .= __( 'Name is not correct', 'usces' ) . '<br />';
5798 }
5799 if ( ! WCUtils::is_blank( $_POST['member']['tel'] ) && preg_match( '/[^\d\-+]/', trim( $_POST['member']['tel'] ) ) ) {
5800 $mes .= __( 'Please input a phone number with a half size number.', 'usces' ) . '<br />';
5801 }
5802 $mes = apply_filters( 'usces_filter_admin_member_check', $mes );
5803
5804 return $mes;
5805 }
5806
5807 public function delivery_check() {
5808 global $usces_settings;
5809
5810 do_action( 'usces_action_before_delivery_check' );
5811
5812 $mes = '';
5813 if ( isset( $_POST['delivery']['delivery_flag'] ) && 1 === (int) $_POST['delivery']['delivery_flag'] ) {
5814 if ( WCUtils::is_blank( $_POST['delivery']['name1'] ) ) {
5815 $mes .= __( 'Name is not correct', 'usces' ) . '<br />';
5816 }
5817 $zip_check = false;
5818 $addressform = $this->options['system']['addressform'];
5819 $applyform = usces_get_apply_addressform( $addressform );
5820 if ( 'JP' === $applyform ) {
5821 if ( isset( $_POST['delivery']['country'] ) ) {
5822 if ( 'JP' === $_POST['delivery']['country'] ) {
5823 $zip_check = true;
5824 }
5825 } else {
5826 $base = usces_get_base_country();
5827 if ( 'JP' === $base ) {
5828 $zip_check = true;
5829 }
5830 }
5831 }
5832 $zip_check = apply_filters( 'usces_filter_zipcode_check', $zip_check );
5833 if ( WCUtils::is_blank( $_POST['delivery']['zipcode'] ) ) {
5834 if ( usces_is_required_field( 'zipcode' ) ) {
5835 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5836 }
5837 } else {
5838 if ( $zip_check ) {
5839 if ( ! preg_match( '/^[a-zA-Z0-9]+$/', $_POST['delivery']['zipcode'] ) ) {
5840 $_SESSION['usces_entry']['delivery']['zipcode'] = usces_convert_zipcode( $_POST['delivery']['zipcode'] );
5841 }
5842 if ( ! preg_match( '/^(([0-9]{3}-[0-9]{4})|([0-9]{7}))$/', $_SESSION['usces_entry']['delivery']['zipcode'] ) ) {
5843 $mes .= __( 'postal code is not correct', 'usces' ) . '<br />';
5844 }
5845 }
5846 }
5847 if ( ( __( '-- Select --', 'usces' ) == $_POST['delivery']['pref'] || '-- Select --' == $_POST['delivery']['pref'] ) && usces_is_required_field( 'states' ) ) {
5848 $mes .= __( 'enter the prefecture', 'usces' ) . '<br />';
5849 }
5850 if ( WCUtils::is_blank( $_POST['delivery']['address1'] ) && usces_is_required_field( 'address1' ) ) {
5851 $mes .= __( 'enter the city name', 'usces' ) . '<br />';
5852 }
5853 if ( WCUtils::is_blank( $_POST['delivery']['address2'] ) && usces_is_required_field( 'address2' ) ) {
5854 $mes .= __( 'enter house numbers', 'usces' ) . '<br />';
5855 }
5856 if ( WCUtils::is_blank( $_POST['delivery']['tel'] ) && usces_is_required_field( 'tel' ) ) {
5857 $mes .= __( 'enter phone numbers', 'usces' ) . '<br />';
5858 }
5859 if ( ! WCUtils::is_blank( $_POST['delivery']['tel'] ) && preg_match( '/[^\d\-+]/', trim( $_POST['delivery']['tel'] ) ) && usces_is_required_field( 'tel' ) ) {
5860 $mes .= __( 'Please input a phone number with a half size number.', 'usces' ) . '<br />';
5861 }
5862 $post_offer = filter_input( INPUT_POST, 'offer', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
5863 if ( ! empty( $post_offer['delivery_date'] ) && usces_is_date( $post_offer['delivery_date'] ) && isset( $post_offer['delivery_method'] ) ) {
5864 $post_delivery = filter_input( INPUT_POST, 'delivery', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
5865 $deli_method_index = $this->get_delivery_method_index( $post_offer['delivery_method'] );
5866 $delivery_days_id = isset( $this->options['delivery_method'][ $deli_method_index ]['days'] ) ? $this->options['delivery_method'][ $deli_method_index ]['days'] : -1;
5867 if ( 0 <= $delivery_days_id ) {
5868 $delivery_days_list = $this->options['delivery_days'];
5869 $delivery_days = 0;
5870 foreach ( (array) $delivery_days_list as $delivery_days_value ) {
5871 if ( (int) $delivery_days_value['id'] === (int) $delivery_days_id ) {
5872 $delivery_days = (int) $delivery_days_value[ $applyform ][ $post_delivery['pref'] ];
5873 }
5874 }
5875 $sendout = usces_get_send_out_date();
5876 $sendout_date = implode( '-', $sendout['sendout_date'] );
5877 $arrival_date = new DateTime( $sendout_date );
5878 $arrival_date->modify( '+' . $delivery_days . ' days' );
5879 $offer_deli_date = new DateTime( $post_offer['delivery_date'] );
5880 if ( $offer_deli_date < $arrival_date ) {
5881 $mes .= __( 'Please re-specify the desired arrival date.', 'usces' ) . '<br />';
5882 }
5883 } else {
5884 $mes .= __( 'Please re-specify the desired arrival date.', 'usces' ) . '<br />';
5885 }
5886 }
5887 }
5888 if ( ! isset( $_POST['offer']['delivery_method'] ) || ( empty( $_POST['offer']['delivery_method'] ) && ! WCUtils::is_zero( $_POST['offer']['delivery_method'] ) ) ) {
5889 $mes .= __( 'chose one from delivery method.', 'usces' ) . '<br />';
5890 } else {
5891 $d_method_index = $this->get_delivery_method_index( (int) $_POST['offer']['delivery_method'] );
5892 if ( 0 > $d_method_index ) {
5893 $mes .= __( 'chose one from delivery method.', 'usces' ) . '<br />';
5894 } elseif ( isset( $_SESSION['usces_entry']['delivery']['country'] ) ) {
5895 $country = $_SESSION['usces_entry']['delivery']['country'];
5896 $current_locate = get_locale();
5897 $wplang = get_option( 'WPLANG', $current_locate );
5898 $local_country = $usces_settings['lungage2country'][ $wplang ];
5899
5900 if ( $country == $local_country ) {
5901 if ( 1 == $this->options['delivery_method'][ $d_method_index ]['intl'] ) {
5902 $mes .= __( 'Delivery method is incorrect. Can not specify an international flight.', 'usces' ) . '<br />';
5903 }
5904 } else {
5905 if ( WCUtils::is_zero( $this->options['delivery_method'][ $d_method_index ]['intl'] ) ) {
5906 $mes .= __( 'Delivery method is incorrect. Specify the international flights.', 'usces' ) . '<br />';
5907 }
5908 }
5909 }
5910 }
5911 if ( ! isset( $_POST['offer']['payment_name'] ) ) {
5912 $mes .= __( 'chose one from payment options.', 'usces' ) . '<br />';
5913 } else {
5914 $payments = $this->getPayments( $_POST['offer']['payment_name'] );
5915 if ( 'COD' == $payments['settlement'] ) {
5916 $total_items_price = $this->get_total_price();
5917 $usces_entries = $this->cart->get_entry();
5918 $materials = array(
5919 'total_items_price' => $usces_entries['order']['total_items_price'],
5920 'discount' => ( isset( $usces_entries['order']['discount'] ) ) ? $usces_entries['order']['discount'] : 0,
5921 'shipping_charge' => $usces_entries['order']['shipping_charge'],
5922 'cod_fee' => $usces_entries['order']['cod_fee'],
5923 'use_point' => ( isset( $usces_entries['order']['use_point'] ) ) ? $usces_entries['order']['use_point'] : 0,
5924 );
5925 $tax = $this->getTax( $total_items_price, $materials );
5926 $total_items_price = $total_items_price + $tax;
5927 $cod_limit_amount = ( isset( $this->options['cod_limit_amount'] ) && 0 < (int) $this->options['cod_limit_amount'] ) ? $this->options['cod_limit_amount'] : 0;
5928 if ( 0 < $cod_limit_amount && $total_items_price > $cod_limit_amount ) {
5929 $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 />';
5930 }
5931 }
5932 }
5933 if ( isset( $d_method_index ) && isset( $payments ) ) {
5934 if ( 1 == $this->options['delivery_method'][ $d_method_index ]['nocod'] ) {
5935 if ( 'COD' == $payments['settlement'] ) {
5936 $mes .= __( 'COD is not available.', 'usces' ) . '<br />';
5937 }
5938 }
5939 }
5940 $mes = apply_filters( 'usces_filter_delivery_check', $mes );
5941 return $mes;
5942 }
5943
5944 public function point_check( $entries ) {
5945 $member = $this->get_member();
5946 $this->set_cart_fees( $member, $entries );
5947
5948 $mes = '';
5949 if ( isset( $_POST['offer']['usedpoint'] ) ) {
5950 if ( WCUtils::is_blank( $_POST['offer']['usedpoint'] ) || ! preg_match( '/^[0-9]+$/', $_POST['offer']['usedpoint'] ) || (int) $_POST['offer']['usedpoint'] < 0 ) {
5951 $mes .= __( 'Invalid value. Please enter in the numbers.', 'usces' ) . '<br />';
5952
5953 } else {
5954 $payments = $this->getPayments( $entries['order']['payment_name'] );
5955 $usedpoint = (int) trim( $_POST['offer']['usedpoint'] );
5956 if ( $usedpoint > $member['point'] ) {
5957 $mes .= __( 'You have exceeded the maximum available.', 'usces' ) . ' ' . __( 'Max', 'usces' ) . ' ' . $member['point'] . ' ' . __( 'points', 'usces' ) . '<br />';
5958
5959 } elseif ( 'acting_paypal_ec' == $payments['settlement'] ) {
5960 $target_full_price = $entries['order']['total_items_price'] + $entries['order']['discount'] + $entries['order']['shipping_charge'] + $entries['order']['cod_fee'] + $entries['order']['tax'];
5961 $target_item_price = $entries['order']['total_items_price'] + $entries['order']['discount'];
5962 if ( 1 == $this->options['point_coverage'] && $usedpoint >= $target_full_price ) {
5963 $target_item_price = $target_full_price;
5964 } elseif ( 'products' == $this->options['tax_target'] ) {
5965 $target_item_price += $entries['order']['tax'];
5966 }
5967 if ( $usedpoint > $target_item_price ) {
5968 $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 />';
5969 }
5970
5971 } else {
5972 if ( 1 == $this->options['point_coverage'] ) {
5973 $target_full_price = $entries['order']['total_items_price'] + $entries['order']['discount'] + $entries['order']['shipping_charge'] + $entries['order']['cod_fee'] + $entries['order']['tax'];
5974 if ( $usedpoint > $target_full_price ) {
5975 $mes .= __( 'You have exceeded the maximum available.', 'usces' ) . ' ' . __( 'Max', 'usces' ) . ' ' . $target_full_price . ' ' . __( 'points', 'usces' ) . '<br />';
5976 }
5977 } else {
5978 $target_item_price = $entries['order']['total_items_price'] + $entries['order']['discount'];
5979 if ( 'products' == $this->options['tax_target'] ) {
5980 $target_item_price += $entries['order']['tax'];
5981 }
5982 if ( $usedpoint > $target_item_price ) {
5983 $mes .= __( 'You have exceeded the maximum available.', 'usces' ) . ' ' . __( 'Max', 'usces' ) . ' ' . $target_item_price . ' ' . __( 'points', 'usces' ) . '<br />';
5984 }
5985 }
5986 }
5987 $mes = apply_filters( 'usces_filter_point_check', $mes );
5988 if ( '' != $mes ) {
5989 $_POST['offer']['usedpoint'] = 0;
5990 $array = array(
5991 'usedpoint' => 0,
5992 );
5993 $this->cart->set_order_entry( $array );
5994 }
5995 }
5996 }
5997 $mes = apply_filters( 'usces_filter_point_check_last', $mes );
5998 return $mes;
5999 }
6000
6001 public function lostpass_mailaddcheck() {
6002 $mes = '';
6003 if ( ! is_email( $_POST['loginmail'] ) || WCUtils::is_blank( $_POST['loginmail'] ) ) {
6004 $mes .= __( 'e-mail address is not correct', 'usces' ) . '<br />';
6005 }
6006
6007 return $mes;
6008 }
6009
6010 public function changepass_check() {
6011 $mes = $this->get_pwd_errors( $_POST['loginpass1'] );
6012
6013 if ( trim( $_POST['loginpass1'] ) != trim( $_POST['loginpass2'] ) ) {
6014 $mes .= __( 'Password confirm does not match.', 'usces' ) . '<br />';
6015 }
6016
6017 return $mes;
6018 }
6019
6020 public function get_page() {
6021 return $this->page;
6022 }
6023
6024 public function check_display_mode() {
6025 $options = get_option( 'usces' );
6026 if ( isset( $options['display_mode'] ) && 'Maintenancemode' == $options['display_mode'] ) {
6027 return;
6028 }
6029
6030 $start['hour'] = empty( $options['campaign_schedule']['start']['hour'] ) ? 0 : $options['campaign_schedule']['start']['hour'];
6031 $start['min'] = empty( $options['campaign_schedule']['start']['min'] ) ? 0 : $options['campaign_schedule']['start']['min'];
6032 $start['month'] = empty( $options['campaign_schedule']['start']['month'] ) ? 0 : $options['campaign_schedule']['start']['month'];
6033 $start['day'] = empty( $options['campaign_schedule']['start']['day'] ) ? 0 : $options['campaign_schedule']['start']['day'];
6034 $start['year'] = empty( $options['campaign_schedule']['start']['year'] ) ? 0 : $options['campaign_schedule']['start']['year'];
6035 $end['hour'] = empty( $options['campaign_schedule']['end']['hour'] ) ? 0 : $options['campaign_schedule']['end']['hour'];
6036 $end['min'] = empty( $options['campaign_schedule']['end']['min'] ) ? 0 : $options['campaign_schedule']['end']['min'];
6037 $end['month'] = empty( $options['campaign_schedule']['end']['month'] ) ? 0 : $options['campaign_schedule']['end']['month'];
6038 $end['day'] = empty( $options['campaign_schedule']['end']['day'] ) ? 0 : $options['campaign_schedule']['end']['day'];
6039 $end['year'] = empty( $options['campaign_schedule']['end']['year'] ) ? 0 : $options['campaign_schedule']['end']['year'];
6040 $starttime = mktime( $start['hour'], $start['min'], 0, $start['month'], $start['day'], $start['year'] );
6041 $endtime = mktime( $end['hour'], $end['min'], 0, $end['month'], $end['day'], $end['year'] );
6042 $current_time = current_time( 'timestamp' );
6043
6044 if ( ( $current_time >= $starttime ) && ( $current_time <= $endtime ) ) {
6045 $options['display_mode'] = 'Promotionsale';
6046 } else {
6047 $options['display_mode'] = 'Usualsale';
6048 }
6049 update_option( 'usces', $options );
6050 }
6051
6052 public function update_business_days() {
6053 $options = get_option( 'usces' );
6054 $datetimestr = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) );
6055 $dhour = (int) substr( $datetimestr, 11, 2 );
6056 $dminute = (int) substr( $datetimestr, 14, 2 );
6057 $dsecond = (int) substr( $datetimestr, 17, 2 );
6058 $dmonth = (int) substr( $datetimestr, 5, 2 );
6059 $dday = (int) substr( $datetimestr, 8, 2 );
6060 $dyear = (int) substr( $datetimestr, 0, 4 );
6061 $dtimestamp = mktime( $dhour, $dminute, $dsecond, $dmonth, $dday, $dyear );
6062 $datenow = getdate( $dtimestamp );
6063 list( $year, $mon, $mday ) = getBeforeMonth( $datenow['year'], $datenow['mon'], 1, 1 );
6064
6065 if ( isset( $options['business_days'][ $year ][ $mon ][1] ) ) {
6066 unset( $options['business_days'][ $year ][ $mon ] );
6067 }
6068
6069 for ( $i = 0; $i < 12; $i++ ) {
6070 list( $year, $mon, $mday ) = getAfterMonth( $datenow['year'], $datenow['mon'], 1, $i );
6071 $last = getLastDay( $year, $mon );
6072 for ( $j = 1; $j <= $last; $j++ ) {
6073 if ( ! isset( $options['business_days'][ $year ][ $mon ][ $j ] ) ) {
6074 $options['business_days'][ $year ][ $mon ][ $j ] = 1;
6075 }
6076 }
6077 }
6078 update_option( 'usces', $options );
6079 $this->options = get_option( 'usces' );
6080 $_SESSION['usces_checked_business_days'] = '';
6081 }
6082
6083 public function display_cart() {
6084 if ( $this->cart->num_row() > 0 ) {
6085 // include (USCES_PLUGIN_DIR . '/includes/cart_table.php');
6086 } else {
6087 echo "<div class='no_cart'>" . __( 'There are no items in your cart.', 'usces' ) . "</div>\n";
6088 }
6089 }
6090
6091 public function display_cart_confirm() {
6092 if ( $this->cart->num_row() > 0 ) {
6093 // include (USCES_PLUGIN_DIR . '/includes/cart_confirm.php');
6094 } else {
6095 echo "<div class='no_cart'>" . __( 'There are no items in your cart.', 'usces' ) . "</div>\n";
6096 }
6097 }
6098
6099 public function set_initial() {
6100 $this->set_default_page();
6101 $this->set_default_categories();
6102 $this->create_table();
6103 $this->update_table();
6104 $rets07 = usces_upgrade_07();
6105 if ( $rets07 ) {
6106 $rets11 = usces_upgrade_11();
6107 }
6108 if ( $rets11 ) {
6109 $rets14 = usces_upgrade_14();
6110 }
6111 if ( $rets14 ) {
6112 $rets141 = usces_upgrade_141();
6113 }
6114 if ( $rets141 ) {
6115 $rets143 = usces_upgrade_143();
6116 }
6117 $this->update_options();
6118 usces_schedule_event();
6119 do_action( 'usces_on_plugin_activate' );
6120 }
6121
6122 public function deactivate() {
6123 wp_clear_scheduled_hook( 'wc_cron' );
6124 wp_clear_scheduled_hook( 'wc_cron_w' );
6125 usces_wcsite_deactivate();
6126 }
6127
6128 public function create_table() {
6129 global $wpdb;
6130
6131 if ( ! empty( $wpdb->charset ) ) {
6132 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
6133 }
6134 if ( ! empty( $wpdb->collate ) ) {
6135 $charset_collate .= " COLLATE $wpdb->collate";
6136 }
6137 $access_table = $wpdb->prefix . 'usces_access';
6138 $member_table = $wpdb->prefix . 'usces_member';
6139 $member_meta_table = $wpdb->prefix . 'usces_member_meta';
6140 $order_table = $wpdb->prefix . 'usces_order';
6141 $order_meta_table = $wpdb->prefix . 'usces_order_meta';
6142 $ordercart_table = $wpdb->prefix . 'usces_ordercart';
6143 $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
6144 $log_table = $wpdb->prefix . 'usces_log';
6145 $acting_log_table = $wpdb->prefix . 'usces_acting_log';
6146 $item_table = $wpdb->prefix . 'usces_item';
6147 $sku_table = $wpdb->prefix . 'usces_skus';
6148 $opt_table = $wpdb->prefix . 'usces_opts';
6149 $admin_log_table = $wpdb->prefix . 'usces_admin_log';
6150
6151 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6152
6153 if ( $wpdb->get_var( "SHOW TABLES LIKE '$access_table'" ) != $access_table ) {
6154 $sql = 'CREATE TABLE ' . $access_table . " (
6155 ID BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT,
6156 acc_key VARCHAR( 50 ) NOT NULL ,
6157 acc_type VARCHAR( 50 ) NULL ,
6158 acc_value LONGTEXT NULL ,
6159 acc_date DATE NOT NULL DEFAULT '0000-00-00',
6160 acc_num1 INT( 11 ) NOT NULL DEFAULT 0,
6161 acc_num2 INT( 11 ) NOT NULL DEFAULT 0,
6162 acc_str1 VARCHAR( 200 ) NULL ,
6163 acc_str2 VARCHAR( 200 ) NULL ,
6164 PRIMARY KEY (`ID`),
6165 KEY acc_key ( acc_key ),
6166 KEY acc_type ( acc_type ),
6167 KEY acc_date ( acc_date ),
6168 KEY acc_num1 ( acc_num1 ),
6169 KEY acc_num2 ( acc_num2 )
6170 ) AUTO_INCREMENT=0 $charset_collate;";
6171 dbDelta( $sql );
6172 add_option( 'usces_db_access', USCES_DB_ACCESS );
6173 }
6174
6175 if ( $wpdb->get_var( "SHOW TABLES LIKE '$member_table'" ) != $member_table ) {
6176 $sql = 'CREATE TABLE ' . $member_table . " (
6177 ID BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT,
6178 mem_email VARCHAR( 100 ) NOT NULL ,
6179 mem_pass VARCHAR( 64 ) NOT NULL ,
6180 mem_status INT( 11 ) NOT NULL DEFAULT '0',
6181 mem_cookie VARCHAR( 13 ) NULL ,
6182 mem_point INT( 11 ) NOT NULL DEFAULT '0',
6183 mem_name1 VARCHAR( 100 ) NOT NULL ,
6184 mem_name2 VARCHAR( 100 ) NULL ,
6185 mem_name3 VARCHAR( 100 ) NULL ,
6186 mem_name4 VARCHAR( 100 ) NULL ,
6187 mem_zip VARCHAR( 50 ) NULL ,
6188 mem_pref VARCHAR( 100 ) NOT NULL ,
6189 mem_address1 VARCHAR( 100 ) NOT NULL ,
6190 mem_address2 VARCHAR( 100 ) NULL ,
6191 mem_address3 VARCHAR( 100 ) NULL ,
6192 mem_tel VARCHAR( 100 ) NOT NULL ,
6193 mem_fax VARCHAR( 100 ) NULL ,
6194 mem_delivery_flag TINYINT ( 1 ) NULL ,
6195 mem_delivery LONGTEXT,
6196 mem_registered DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6197 mem_nicename VARCHAR( 50 ) NULL ,
6198 PRIMARY KEY (`ID`),
6199 KEY mem_email ( mem_email ) ,
6200 KEY mem_pass ( mem_pass )
6201 ) AUTO_INCREMENT=1000 $charset_collate;";
6202 dbDelta( $sql );
6203 add_option( 'usces_db_member', USCES_DB_MEMBER );
6204 }
6205
6206 if ( $wpdb->get_var( "SHOW TABLES LIKE '$member_meta_table'" ) != $member_meta_table ) {
6207 $sql = 'CREATE TABLE ' . $member_meta_table . " (
6208 mmeta_id bigint(20) NOT NULL auto_increment,
6209 member_id bigint(20) NOT NULL default '0',
6210 meta_key varchar(255) default NULL,
6211 meta_value longtext,
6212 PRIMARY KEY (mmeta_id),
6213 KEY order_id (member_id),
6214 KEY meta_key (meta_key(191))
6215 ) $charset_collate;";
6216 dbDelta( $sql );
6217 add_option( 'usces_db_member_meta', USCES_DB_MEMBER_META );
6218 }
6219
6220 if ( $wpdb->get_var( "SHOW TABLES LIKE '$order_table'" ) != $order_table ) {
6221 $sql = 'CREATE TABLE ' . $order_table . " (
6222 ID BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT,
6223 mem_id BIGINT( 20 ) UNSIGNED NULL ,
6224 order_email VARCHAR( 100 ) NOT NULL ,
6225 order_name1 VARCHAR( 100 ) NOT NULL ,
6226 order_name2 VARCHAR( 100 ) NULL ,
6227 order_name3 VARCHAR( 100 ) NULL ,
6228 order_name4 VARCHAR( 100 ) NULL ,
6229 order_zip VARCHAR( 50 ) NULL ,
6230 order_pref VARCHAR( 100 ) NOT NULL ,
6231 order_address1 VARCHAR( 100 ) NOT NULL ,
6232 order_address2 VARCHAR( 100 ) NULL ,
6233 order_address3 VARCHAR( 100 ) NULL ,
6234 order_tel VARCHAR( 100 ) NOT NULL ,
6235 order_fax VARCHAR( 100 ) NULL ,
6236 order_delivery LONGTEXT,
6237 order_cart LONGTEXT,
6238 order_note TEXT,
6239 order_delivery_time VARCHAR( 100 ) NOT NULL ,
6240 order_payment_name VARCHAR( 100 ) NOT NULL ,
6241 order_condition TEXT,
6242 order_item_total_price DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
6243 order_getpoint INT( 10 ) NOT NULL DEFAULT '0',
6244 order_usedpoint INT( 10 ) NOT NULL DEFAULT '0',
6245 order_discount DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
6246 order_shipping_charge DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
6247 order_cod_fee DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
6248 order_tax DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
6249 order_date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6250 order_modified VARCHAR( 20 ) NULL ,
6251 order_status VARCHAR( 255 ) NULL ,
6252 order_check TEXT NULL ,
6253 order_delidue_date VARCHAR( 30 ) NULL ,
6254 order_delivery_method INT( 10 ) NOT NULL DEFAULT -1,
6255 order_delivery_date VARCHAR( 100 ) NULL,
6256 PRIMARY KEY (`ID`),
6257 KEY order_email ( order_email ) ,
6258 KEY order_name1 ( order_name1 ) ,
6259 KEY order_name2 ( order_name2 ) ,
6260 KEY order_pref ( order_pref ) ,
6261 KEY order_address1 ( order_address1 ) ,
6262 KEY order_tel ( order_tel ) ,
6263 KEY mem_id ( mem_id ) ,
6264 KEY order_date ( order_date )
6265 ) AUTO_INCREMENT=1000 $charset_collate;";
6266 dbDelta( $sql );
6267 add_option( 'usces_db_order', USCES_DB_ORDER );
6268 }
6269
6270 if ( $wpdb->get_var( "SHOW TABLES LIKE '$order_meta_table'" ) != $order_meta_table ) {
6271 $sql = 'CREATE TABLE ' . $order_meta_table . " (
6272 ometa_id bigint(20) NOT NULL auto_increment,
6273 order_id bigint(20) NOT NULL default '0',
6274 meta_key varchar(255) default NULL,
6275 meta_value longtext,
6276 PRIMARY KEY (ometa_id),
6277 KEY order_id (order_id),
6278 KEY meta_key (meta_key(191))
6279 ) $charset_collate;";
6280 dbDelta( $sql );
6281 add_option( 'usces_db_order_meta', USCES_DB_ORDER_META );
6282 }
6283
6284 if ( $wpdb->get_var( "SHOW TABLES LIKE '$ordercart_table'" ) != $ordercart_table ) {
6285 $sql = 'CREATE TABLE ' . $ordercart_table . " (
6286 `cart_id` bigint( 20 ) unsigned NOT NULL AUTO_INCREMENT ,
6287 `order_id` bigint( 20 ) NOT NULL ,
6288 `group_id` int( 3 ) NOT NULL DEFAULT '0',
6289 `row_index` int( 3 ) NOT NULL ,
6290 `post_id` bigint( 20 ) NOT NULL ,
6291 `item_code` varchar( 100 ) NOT NULL ,
6292 `item_name` varchar( 250 ) NOT NULL ,
6293 `cprice` decimal( 12, 0 ) DEFAULT NULL ,
6294 `sku_code` varchar( 100 ) NOT NULL ,
6295 `sku_name` varchar( 250 ) DEFAULT NULL ,
6296 `price` decimal( 12, 0 ) NOT NULL ,
6297 `quantity` float NOT NULL ,
6298 `unit` varchar( 50 ) DEFAULT NULL ,
6299 `tax` decimal( 10, 0 ) DEFAULT NULL ,
6300 `destination_id` int( 10 ) DEFAULT NULL ,
6301 `cart_serial` text,
6302 PRIMARY KEY ( `cart_id` ) ,
6303 UNIQUE KEY `row` ( `row_index` , `destination_id` , `order_id` ) ,
6304 KEY `order_id` ( `order_id` ) ,
6305 KEY `post_id` ( `post_id` ) ,
6306 KEY `item_code` ( `item_code` ) ,
6307 KEY `item_name` ( `item_name`(191) ) ,
6308 KEY `sku_code` ( `sku_code` ) ,
6309 KEY `sku_name` ( `sku_name`(191) )
6310 ) AUTO_INCREMENT=1000 $charset_collate;";
6311 dbDelta( $sql );
6312 add_option( 'usces_db_ordercart', USCES_DB_ORDERCART );
6313 }
6314
6315 if ( $wpdb->get_var( "SHOW TABLES LIKE '$ordercart_meta_table'" ) != $ordercart_meta_table ) {
6316 $sql = 'CREATE TABLE ' . $ordercart_meta_table . " (
6317 `cartmeta_id` bigint( 20 ) NOT NULL AUTO_INCREMENT ,
6318 `cart_id` bigint( 20 ) NOT NULL DEFAULT '0',
6319 `meta_type` varchar( 100 ) NOT NULL ,
6320 `meta_key` varchar( 255 ) DEFAULT NULL ,
6321 `meta_value` longtext,
6322 PRIMARY KEY ( `cartmeta_id` ) ,
6323 KEY `cart_id` ( `cart_id` ) ,
6324 KEY `meta_key` ( `meta_key`(191) )
6325 ) $charset_collate;";
6326 dbDelta( $sql );
6327 add_option( 'usces_db_ordercart_meta', USCES_DB_ORDERCART_META );
6328 }
6329
6330 if ( $wpdb->get_var( "SHOW TABLES LIKE '$log_table'") != $log_table ) {
6331 $sql = 'CREATE TABLE ' . $log_table . " (
6332 ID BIGINT( 20 ) NOT NULL AUTO_INCREMENT,
6333 datetime DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6334 log LONGTEXT NULL,
6335 log_type VARCHAR( 100 ) DEFAULT NULL,
6336 log_key VARCHAR( 255 ) DEFAULT NULL,
6337 PRIMARY KEY ( ID ) ,
6338 KEY datetime ( datetime ),
6339 KEY log_type ( log_type ),
6340 KEY log_key ( log_key(191) )
6341 ) $charset_collate;";
6342 dbDelta( $sql );
6343 add_option( 'usces_db_log', USCES_DB_LOG );
6344 }
6345
6346 if ( $wpdb->get_var( "SHOW TABLES LIKE '$acting_log_table'" ) != $acting_log_table ) {
6347 $sql = 'CREATE TABLE ' . $acting_log_table . " (
6348 `ID` BIGINT(20) NOT NULL AUTO_INCREMENT,
6349 `datetime` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6350 `log` LONGTEXT NULL,
6351 `acting` CHAR(32) DEFAULT NULL,
6352 `status` CHAR(32) DEFAULT NULL,
6353 `result` CHAR(32) DEFAULT NULL,
6354 `amount` DECIMAL( 10, 2 ) DEFAULT NULL,
6355 `order_id` BIGINT(20) NOT NULL,
6356 `tracking_id` CHAR(32) DEFAULT NULL,
6357 PRIMARY KEY (`ID`),
6358 KEY `datetime` (`datetime`),
6359 KEY `order_id` (`order_id`),
6360 KEY `tracking_id` (`tracking_id`),
6361 KEY `history_key` (`order_id`,`tracking_id`)
6362 ) $charset_collate;";
6363 dbDelta( $sql );
6364 add_option( 'usces_db_acting_log', USCES_DB_ACTING_LOG );
6365 }
6366
6367 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$item_table}'" ) !== $item_table ) {
6368 $sql = 'CREATE TABLE ' . $item_table . ' (
6369 post_id BIGINT( 20 ) UNSIGNED NOT NULL,
6370 itemCode VARCHAR( 200 ) NULL ,
6371 itemName VARCHAR( 250 ) NULL ,
6372 itemRestriction VARCHAR( 20 ) NULL ,
6373 itemPointrate VARCHAR( 20 ) NULL ,
6374 itemGpNum1 VARCHAR( 20 ) NULL ,
6375 itemGpNum2 VARCHAR( 20 ) NULL ,
6376 itemGpNum3 VARCHAR( 20 ) NULL ,
6377 itemGpDis1 VARCHAR( 20 ) NULL ,
6378 itemGpDis2 VARCHAR( 20 ) NULL ,
6379 itemGpDis3 VARCHAR( 20 ) NULL ,
6380 itemOrderAcceptable INT( 2 ) NULL ,
6381 itemShipping INT( 3 ) NULL ,
6382 itemDeliveryMethod LONGTEXT ,
6383 itemShippingCharge VARCHAR( 200 ) NULL ,
6384 itemIndividualSCharge VARCHAR( 20 ) NULL ,
6385 item_charging_type INT( 3 ) NULL ,
6386 item_division VARCHAR( 50 ) NULL ,
6387 dlseller_date VARCHAR( 100 ) NULL ,
6388 dlseller_file VARCHAR( 200 ) NULL ,
6389 dlseller_interval VARCHAR( 20 ) NULL ,
6390 dlseller_validity VARCHAR( 20 ) NULL ,
6391 dlseller_version VARCHAR( 100 ) NULL ,
6392 dlseller_author VARCHAR( 200 ) NULL ,
6393 dlseller_purchases VARCHAR( 20 ) NULL ,
6394 dlseller_downloads VARCHAR( 20 ) NULL ,
6395 item_chargingday VARCHAR( 20 ) NULL ,
6396 item_frequency VARCHAR( 20 ) NULL ,
6397 wcad_regular_unit VARCHAR( 20 ) NULL ,
6398 wcad_regular_interval INT( 10 ) NULL ,
6399 wcad_regular_frequency INT( 10 ) NULL ,
6400 select_sku_switch INT( 10 ) NULL ,
6401 select_sku_display INT( 10 ) NULL ,
6402 select_sku LONGTEXT ,
6403 atobarai_propriety INT( 5 ) NULL ,
6404 atodene_propriety INT( 5 ) NULL ,
6405 structuredDataSku VARCHAR( 200 ) NULL ,
6406 lower_limit INT( 10 ) NULL ,
6407 popularity INT( 10 ) NULL ,
6408 main_price DECIMAL( 10, 2 ) NULL ,
6409 itemPicts TEXT NULL ,
6410 itemAdvanced LONGTEXT NULL ,
6411 PRIMARY KEY (`post_id`),
6412 KEY itemCode ( itemCode ) ,
6413 KEY itemName ( itemName )
6414 ) ' . $charset_collate . ';';
6415 dbDelta( $sql );
6416 add_option( 'usces_db_item', USCES_DB_ITEM );
6417 }
6418
6419 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$sku_table}'" ) !== $sku_table ) {
6420 $sql = 'CREATE TABLE ' . $sku_table . ' (
6421 meta_id BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT,
6422 post_id BIGINT( 20 ) UNSIGNED NOT NULL ,
6423 code VARCHAR( 200 ) NULL ,
6424 name VARCHAR( 250 ) NULL ,
6425 cprice DECIMAL( 10, 2 ) NULL ,
6426 price DECIMAL( 10, 2 ) NULL ,
6427 unit TEXT NULL ,
6428 stocknum VARCHAR( 50 ) NULL ,
6429 stock INT( 5 ) NULL ,
6430 gp INT( 2 ) NULL ,
6431 taxrate VARCHAR( 20 ) NULL ,
6432 size VARCHAR( 20 ) NULL ,
6433 weight VARCHAR( 20 ) NULL ,
6434 pict_id VARCHAR( 20 ) NULL ,
6435 advance LONGTEXT ,
6436 paternkey VARCHAR( 100 ) NULL ,
6437 sort INT( 5 ) NULL ,
6438 PRIMARY KEY (`meta_id`),
6439 KEY post_id ( post_id ) ,
6440 KEY code ( code ) ,
6441 KEY name ( name ) ,
6442 KEY price ( price ) ,
6443 KEY paternkey ( paternkey )
6444 ) ' . $charset_collate . ';';
6445 dbDelta( $sql );
6446 add_option( 'usces_db_skus', USCES_DB_SKUS );
6447 }
6448
6449 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$opt_table}'" ) !== $opt_table ) {
6450 $sql = 'CREATE TABLE ' . $opt_table . ' (
6451 meta_id BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT,
6452 post_id BIGINT( 20 ) UNSIGNED NOT NULL ,
6453 code VARCHAR( 200 ) NULL ,
6454 name VARCHAR( 250 ) NULL ,
6455 means INT( 3 ) NULL ,
6456 essential INT( 3 ) NULL ,
6457 value TEXT ,
6458 sort INT( 5 ) NULL ,
6459 PRIMARY KEY (`meta_id`),
6460 KEY post_id ( post_id ) ,
6461 KEY code ( code ) ,
6462 KEY name ( name )
6463 ) ' . $charset_collate . ';';
6464 dbDelta( $sql );
6465 add_option( 'usces_db_opts', USCES_DB_OPTS );
6466 }
6467
6468 if ( $wpdb->get_var( "SHOW TABLES LIKE '{$admin_log_table}'" ) !== $admin_log_table ) {
6469 $sql = "CREATE TABLE {$admin_log_table} (
6470 `ID` int(11) NOT NULL AUTO_INCREMENT,
6471 `author` varchar(64) NOT NULL,
6472 `message` longtext NOT NULL,
6473 `screen` varchar(64) NOT NULL,
6474 `entity_id` varchar(64) DEFAULT NULL,
6475 `action` varchar(64) NOT NULL,
6476 `data` longblob DEFAULT NULL,
6477 `datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
6478 PRIMARY KEY (`ID`),
6479 KEY entity_id ( entity_id )
6480 ) " . $charset_collate . ';';
6481 dbDelta( $sql );
6482 add_option( 'usces_db_admin_log', USCES_DB_ADMIN_LOG );
6483 }
6484
6485 do_action( 'usces_action_create_table' );
6486 }
6487
6488 public function update_table() {
6489 global $wpdb;
6490 $access_table = $wpdb->prefix . 'usces_access';
6491 $member_table = $wpdb->prefix . 'usces_member';
6492 $member_meta_table = $wpdb->prefix . 'usces_member_meta';
6493 $order_table = $wpdb->prefix . 'usces_order';
6494 $order_meta_table = $wpdb->prefix . 'usces_order_meta';
6495 $ordercart_table = $wpdb->prefix . 'usces_ordercart';
6496 $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
6497 $log_table = $wpdb->prefix . 'usces_log';
6498 $acting_log_table = $wpdb->prefix . 'usces_acting_log';
6499 $item_table = $wpdb->prefix . 'usces_item';
6500 $sku_table = $wpdb->prefix . 'usces_skus';
6501 $opt_table = $wpdb->prefix . 'usces_opts';
6502 $admin_log_table = $wpdb->prefix . 'usces_admin_log';
6503
6504 $access_ver = get_option( 'usces_db_access' );
6505 $member_ver = get_option( 'usces_db_member' );
6506 $member_meta_ver = get_option( 'usces_db_member_meta' );
6507 $order_ver = get_option( 'usces_db_order' );
6508 $order_meta_ver = get_option( 'usces_db_order_meta' );
6509 $ordercart_ver = get_option( 'usces_db_ordercart' );
6510 $ordercart_meta_ver = get_option( 'usces_db_ordercart_meta' );
6511 $log_ver = get_option( 'usces_db_log' );
6512 $acting_log_ver = get_option( 'usces_db_acting_log' );
6513 $db_item = get_option( 'usces_db_item' );
6514 $db_skus = get_option( 'usces_db_skus' );
6515 $db_opts = get_option( 'usces_db_opts' );
6516 $db_admin_log = get_option( 'usces_db_admin_log' );
6517
6518 if ( $access_ver != USCES_DB_ACCESS ) {
6519 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6520 $sql = 'CREATE TABLE ' . $access_table . " (
6521 ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
6522 acc_key VARCHAR(50) NOT NULL ,
6523 acc_type VARCHAR(50) NULL ,
6524 acc_value LONGTEXT NULL ,
6525 acc_date DATE NOT NULL DEFAULT '0000-00-00',
6526 acc_num1 INT(11) NOT NULL DEFAULT 0,
6527 acc_num2 INT(11) NOT NULL DEFAULT 0,
6528 acc_str1 VARCHAR(200) NULL ,
6529 acc_str2 VARCHAR(200) NULL ,
6530 PRIMARY KEY (`ID`),
6531 KEY acc_key (acc_key),
6532 KEY acc_type (acc_type),
6533 KEY acc_date (acc_date),
6534 KEY acc_num1 (acc_num1),
6535 KEY acc_num2 (acc_num2)
6536 );";
6537 dbDelta( $sql );
6538 update_option( 'usces_db_access', USCES_DB_ACCESS );
6539 }
6540
6541 if ( USCES_DB_MEMBER != $member_ver ) {
6542 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6543 $sql = 'CREATE TABLE ' . $member_table . " (
6544 ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
6545 mem_email VARCHAR(100) NOT NULL ,
6546 mem_pass VARCHAR(64) NOT NULL ,
6547 mem_status INT(11) NOT NULL DEFAULT '0',
6548 mem_cookie VARCHAR(13) NULL ,
6549 mem_point INT(11) NOT NULL DEFAULT '0',
6550 mem_name1 VARCHAR(100) NOT NULL ,
6551 mem_name2 VARCHAR(100) NULL ,
6552 mem_name3 VARCHAR(100) NULL ,
6553 mem_name4 VARCHAR(100) NULL ,
6554 mem_zip VARCHAR(50) NULL ,
6555 mem_pref VARCHAR(100) NOT NULL ,
6556 mem_address1 VARCHAR(100) NOT NULL ,
6557 mem_address2 VARCHAR(100) NULL ,
6558 mem_address3 VARCHAR(100) NULL ,
6559 mem_tel VARCHAR(100) NOT NULL ,
6560 mem_fax VARCHAR(100) NULL ,
6561 mem_delivery_flag TINYINT (1) NULL ,
6562 mem_delivery LONGTEXT,
6563 mem_registered DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6564 mem_nicename VARCHAR(50) NULL ,
6565 PRIMARY KEY (`ID`),
6566 KEY mem_email (mem_email) ,
6567 KEY mem_pass (mem_pass)
6568 );";
6569 dbDelta( $sql );
6570 update_option( 'usces_db_member', USCES_DB_MEMBER );
6571 }
6572
6573 if ( USCES_DB_MEMBER_META != $member_meta_ver ) {
6574 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6575 $sql = 'CREATE TABLE ' . $member_meta_table . " (
6576 mmeta_id bigint(20) NOT NULL auto_increment,
6577 member_id bigint(20) NOT NULL default '0',
6578 meta_key varchar(255) default NULL,
6579 meta_value longtext,
6580 PRIMARY KEY (`mmeta_id`),
6581 KEY order_id (member_id),
6582 KEY meta_key (meta_key(191))
6583 );";
6584 dbDelta( $sql );
6585 update_option( 'usces_db_member_meta', USCES_DB_MEMBER_META );
6586 }
6587
6588 if ( USCES_DB_ORDER != $order_ver ) {
6589 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6590 $sql = 'CREATE TABLE ' . $order_table . " (
6591 ID bigint(20) unsigned NOT NULL auto_increment,
6592 mem_id BIGINT(20) UNSIGNED NULL,
6593 order_email VARCHAR(100) NOT NULL,
6594 order_name1 VARCHAR(100) NOT NULL,
6595 order_name2 VARCHAR(100) NULL,
6596 order_name3 VARCHAR(100) NULL,
6597 order_name4 VARCHAR(100) NULL,
6598 order_zip VARCHAR(50) NULL,
6599 order_pref VARCHAR(100) NOT NULL,
6600 order_address1 VARCHAR(100) NOT NULL,
6601 order_address2 VARCHAR(100) NULL,
6602 order_address3 VARCHAR(100) NULL,
6603 order_tel VARCHAR(100) NOT NULL,
6604 order_fax VARCHAR(100) NULL,
6605 order_delivery LONGTEXT,
6606 order_cart LONGTEXT,
6607 order_note TEXT,
6608 order_delivery_time VARCHAR(100) NOT NULL,
6609 order_payment_name VARCHAR(100) NOT NULL,
6610 order_condition TEXT,
6611 order_item_total_price DECIMAL(10,2) NOT NULL DEFAULT '0.00',
6612 order_getpoint INT(10) NOT NULL DEFAULT '0',
6613 order_usedpoint INT(10) NOT NULL DEFAULT '0',
6614 order_discount DECIMAL(10,2) NOT NULL DEFAULT '0.00',
6615 order_shipping_charge DECIMAL(10,2) NOT NULL DEFAULT '0.00',
6616 order_cod_fee DECIMAL(10,2) NOT NULL DEFAULT '0.00',
6617 order_tax DECIMAL(10,2) NOT NULL DEFAULT '0.00',
6618 order_date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6619 order_modified VARCHAR(20) NULL,
6620 order_status VARCHAR(255) NULL,
6621 order_check TEXT NULL,
6622 order_delidue_date VARCHAR(30) NULL,
6623 order_delivery_method INT(10) NOT NULL DEFAULT -1,
6624 order_delivery_date VARCHAR(100) NULL,
6625 PRIMARY KEY (`ID`),
6626 KEY order_email (order_email),
6627 KEY order_name1 (order_name1),
6628 KEY order_name2 (order_name2),
6629 KEY order_pref (order_pref),
6630 KEY order_address1 (order_address1),
6631 KEY order_tel (order_tel),
6632 KEY mem_id ( mem_id ) ,
6633 KEY order_date (order_date)
6634 );";
6635 dbDelta( $sql );
6636 update_option( 'usces_db_order', USCES_DB_ORDER );
6637 }
6638
6639 if ( USCES_DB_ORDER_META != $order_meta_ver ) {
6640 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6641 $sql = 'CREATE TABLE ' . $order_meta_table . " (
6642 ometa_id bigint(20) NOT NULL auto_increment,
6643 order_id bigint(20) NOT NULL default '0',
6644 meta_key varchar(255) default NULL,
6645 meta_value longtext,
6646 PRIMARY KEY (`ometa_id`),
6647 KEY order_id (order_id),
6648 KEY meta_key (meta_key)
6649 );";
6650 dbDelta( $sql );
6651 update_option( 'usces_db_order_meta', USCES_DB_ORDER_META );
6652 }
6653
6654 if ( USCES_DB_ORDERCART != $ordercart_ver ) {
6655 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6656 $sql = 'CREATE TABLE ' . $ordercart_table . " (
6657 cart_id bigint(20) unsigned NOT NULL AUTO_INCREMENT ,
6658 order_id bigint(20) NOT NULL ,
6659 group_id int(3) NOT NULL DEFAULT '0',
6660 row_index int(3) NOT NULL ,
6661 post_id bigint(20) NOT NULL ,
6662 item_code varchar(100) NOT NULL ,
6663 item_name varchar(250) NOT NULL ,
6664 cprice decimal(12,0) DEFAULT NULL ,
6665 sku_code varchar(100) NOT NULL ,
6666 sku_name varchar(250) DEFAULT NULL ,
6667 price decimal(12,0) NOT NULL ,
6668 quantity float NOT NULL ,
6669 unit varchar(50) DEFAULT NULL ,
6670 tax decimal(10,0) DEFAULT NULL ,
6671 destination_id int(10) DEFAULT NULL ,
6672 cart_serial text,
6673 UNIQUE KEY row (row_index,destination_id,order_id) ,
6674 PRIMARY KEY (`cart_id`),
6675 KEY order_id (order_id) ,
6676 KEY post_id (post_id) ,
6677 KEY item_code (item_code) ,
6678 KEY item_name (item_name(191)) ,
6679 KEY sku_code (sku_code) ,
6680 KEY sku_name (sku_name(191))
6681 );";
6682 dbDelta( $sql );
6683 update_option( 'usces_db_ordercart', USCES_DB_ORDERCART );
6684 }
6685
6686 if ( USCES_DB_ORDERCART_META != $ordercart_meta_ver ) {
6687 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6688 $sql = 'CREATE TABLE ' . $ordercart_meta_table . " (
6689 cartmeta_id bigint(20) NOT NULL AUTO_INCREMENT,
6690 cart_id bigint(20) NOT NULL DEFAULT '0',
6691 meta_type varchar(100) NOT NULL ,
6692 meta_key varchar(255) DEFAULT NULL ,
6693 meta_value longtext,
6694 PRIMARY KEY (`cartmeta_id`),
6695 KEY cart_id (cart_id) ,
6696 KEY meta_key (meta_key(191))
6697 );";
6698 dbDelta( $sql );
6699 update_option( 'usces_db_ordercart_meta', USCES_DB_ORDERCART_META );
6700 }
6701
6702 if ( USCES_DB_LOG != $log_ver ) {
6703 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6704 $sql = 'CREATE TABLE ' . $log_table . " (
6705 ID bigint(20) NOT NULL AUTO_INCREMENT,
6706 datetime DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6707 log LONGTEXT NULL,
6708 log_type VARCHAR(100) DEFAULT NULL,
6709 log_key VARCHAR(255) DEFAULT NULL,
6710 PRIMARY KEY (`ID`),
6711 KEY datetime (datetime),
6712 KEY log_type (log_type),
6713 KEY log_key (log_key(191))
6714 );";
6715 dbDelta( $sql );
6716 update_option( 'usces_db_log', USCES_DB_LOG );
6717 }
6718
6719 if ( USCES_DB_ACTING_LOG != $acting_log_ver ) {
6720 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6721 $sql = 'CREATE TABLE ' . $acting_log_table . " (
6722 `ID` BIGINT(20) NOT NULL AUTO_INCREMENT,
6723 `datetime` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
6724 `log` LONGTEXT NULL,
6725 `acting` CHAR(32) DEFAULT NULL,
6726 `status` CHAR(32) DEFAULT NULL,
6727 `result` CHAR(32) DEFAULT NULL,
6728 `amount` DECIMAL( 10, 2 ) DEFAULT NULL,
6729 `order_id` BIGINT(20) NOT NULL,
6730 `tracking_id` CHAR(32) DEFAULT NULL,
6731 PRIMARY KEY (`ID`),
6732 KEY `datetime` (`datetime`),
6733 KEY `order_id` (`order_id`),
6734 KEY `tracking_id` (`tracking_id`),
6735 KEY `history_key` (`order_id`,`tracking_id`)
6736 );";
6737 dbDelta( $sql );
6738 update_option( 'usces_db_acting_log', USCES_DB_ACTING_LOG );
6739 }
6740
6741 if ( USCES_DB_ITEM != $db_item ) {
6742 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6743 $sql = 'CREATE TABLE ' . $item_table . ' (
6744 post_id BIGINT( 20 ) UNSIGNED NOT NULL ,
6745 itemCode VARCHAR( 200 ) NULL ,
6746 itemName VARCHAR( 250 ) NULL ,
6747 itemRestriction VARCHAR( 20 ) NULL ,
6748 itemPointrate VARCHAR( 20 ) NULL ,
6749 itemGpNum1 VARCHAR( 20 ) NULL ,
6750 itemGpNum2 VARCHAR( 20 ) NULL ,
6751 itemGpNum3 VARCHAR( 20 ) NULL ,
6752 itemGpDis1 VARCHAR( 20 ) NULL ,
6753 itemGpDis2 VARCHAR( 20 ) NULL ,
6754 itemGpDis3 VARCHAR( 20 ) NULL ,
6755 itemOrderAcceptable INT( 2 ) NULL ,
6756 itemShipping INT( 3 ) NULL ,
6757 itemDeliveryMethod LONGTEXT ,
6758 itemShippingCharge VARCHAR( 200 ) NULL ,
6759 itemIndividualSCharge VARCHAR( 20 ) NULL ,
6760 item_charging_type INT( 3 ) NULL ,
6761 item_division VARCHAR( 50 ) NULL ,
6762 dlseller_date VARCHAR( 100 ) NULL ,
6763 dlseller_file VARCHAR( 200 ) NULL ,
6764 dlseller_interval VARCHAR( 20 ) NULL ,
6765 dlseller_validity VARCHAR( 20 ) NULL ,
6766 dlseller_version VARCHAR( 100 ) NULL ,
6767 dlseller_author VARCHAR( 200 ) NULL ,
6768 dlseller_purchases VARCHAR( 20 ) NULL ,
6769 dlseller_downloads VARCHAR( 20 ) NULL ,
6770 item_chargingday VARCHAR( 20 ) NULL ,
6771 item_frequency VARCHAR( 20 ) NULL ,
6772 wcad_regular_unit VARCHAR( 20 ) NULL ,
6773 wcad_regular_interval INT( 10 ) NULL ,
6774 wcad_regular_frequency INT( 10 ) NULL ,
6775 select_sku_switch INT( 10 ) NULL ,
6776 select_sku_display INT( 10 ) NULL ,
6777 select_sku LONGTEXT ,
6778 atobarai_propriety INT( 5 ) NULL ,
6779 atodene_propriety INT( 5 ) NULL ,
6780 structuredDataSku VARCHAR( 200 ) NULL ,
6781 lower_limit INT( 10 ) NULL ,
6782 popularity INT( 10 ) NULL ,
6783 main_price DECIMAL( 10, 2 ) NULL ,
6784 itemPicts TEXT NULL ,
6785 itemAdvanced LONGTEXT NULL ,
6786 PRIMARY KEY (`post_id`),
6787 KEY itemCode ( itemCode ) ,
6788 KEY itemName ( itemName )
6789 );';
6790 dbDelta( $sql );
6791 update_option( 'usces_db_item', USCES_DB_ITEM );
6792 }
6793
6794 if ( USCES_DB_SKUS != $db_skus ) {
6795 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6796 $sql = 'CREATE TABLE ' . $sku_table . ' (
6797 meta_id BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
6798 post_id BIGINT( 20 ) UNSIGNED NOT NULL ,
6799 code VARCHAR( 200 ) NULL ,
6800 name VARCHAR( 250 ) NULL ,
6801 cprice DECIMAL( 10, 2 ) NULL ,
6802 price DECIMAL( 10, 2 ) NULL ,
6803 unit TEXT NULL ,
6804 stocknum VARCHAR( 50 ) NULL ,
6805 stock INT( 5 ) NULL ,
6806 gp INT( 2 ) NULL ,
6807 taxrate VARCHAR( 20 ) NULL ,
6808 size VARCHAR( 20 ) NULL ,
6809 weight VARCHAR( 20 ) NULL ,
6810 pict_id VARCHAR( 20 ) NULL ,
6811 advance LONGTEXT ,
6812 paternkey VARCHAR( 100 ) NULL ,
6813 sort INT( 5 ) NULL ,
6814 PRIMARY KEY (`meta_id`),
6815 KEY post_id ( post_id ) ,
6816 KEY code ( code ) ,
6817 KEY name ( name ) ,
6818 KEY price ( price ) ,
6819 KEY paternkey ( paternkey )
6820 );';
6821 dbDelta( $sql );
6822 update_option( 'usces_db_skus', USCES_DB_SKUS );
6823 }
6824
6825 if ( USCES_DB_OPTS != $db_opts ) {
6826 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6827 $sql = 'CREATE TABLE ' . $opt_table . ' (
6828 meta_id BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
6829 post_id BIGINT( 20 ) UNSIGNED NOT NULL ,
6830 code VARCHAR( 200 ) NULL ,
6831 name VARCHAR( 250 ) NULL ,
6832 means INT( 3 ) NULL ,
6833 essential INT( 3 ) NULL ,
6834 value TEXT ,
6835 sort INT( 5 ) NULL ,
6836 PRIMARY KEY (`meta_id`),
6837 KEY post_id ( post_id ) ,
6838 KEY code ( code ) ,
6839 KEY name ( name )
6840 );';
6841 dbDelta( $sql );
6842 update_option( 'usces_db_opts', USCES_DB_OPTS );
6843 }
6844
6845 if ( USCES_DB_ADMIN_LOG != $db_admin_log ) {
6846 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
6847 $sql = "CREATE TABLE {$admin_log_table} (
6848 `ID` int(11) NOT NULL AUTO_INCREMENT,
6849 `author` varchar(64) NOT NULL,
6850 `message` longtext NOT NULL,
6851 `screen` varchar(64) NOT NULL,
6852 `entity_id` varchar(64) DEFAULT NULL,
6853 `action` varchar(64) NOT NULL,
6854 `data` longblob DEFAULT NULL,
6855 `datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
6856 PRIMARY KEY (`ID`),
6857 KEY entity_id ( entity_id )
6858 );";
6859 dbDelta( $sql );
6860 update_option( 'usces_db_admin_log', USCES_DB_ADMIN_LOG );
6861 }
6862
6863 do_action( 'usces_action_update_table' );
6864 }
6865
6866 public function dir_copy( $source, $dest ) {
6867 if ( $res = opendir( $source ) ) {
6868 while ( ( $file = readdir( $res ) ) !== false ) {
6869 $sorce_path = $source . '/' . $file;
6870 $dest_path = $dest . '/' . $file;
6871 $filetype = @filetype( $sorce_path );
6872 if ( 'file' == $filetype ) {
6873 copy( $sorce_path, $dest_path );
6874 } elseif ( 'dir' == $filetype && '..' != $file && '.' != $file ) {
6875 mkdir( $dest_path );
6876 $this->dir_copy( $sorce_path, $dest_path );
6877 }
6878 }
6879 closedir( $res );
6880 }
6881 }
6882
6883 public function set_default_page() {
6884 global $wpdb;
6885
6886 $datetime = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) );
6887 $datetime_gmt = gmdate( 'Y-m-d H:i:s', time() );
6888
6889 // cart_page.
6890 $query = $wpdb->prepare( "SELECT ID from $wpdb->posts where post_name = %s", USCES_CART_FOLDER );
6891 $cart_number = $wpdb->get_var( $query );
6892 if ( null === $cart_number ) {
6893 $query = $wpdb->prepare(
6894 "INSERT INTO $wpdb->posts
6895 (post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status,
6896 comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt,
6897 post_content_filtered, post_parent, guid, menu_order, post_type, post_mime_type, comment_count)
6898 VALUES (%d, %s, %s, %s, %s, %s, %s,
6899 %s, %s, %s, %s, %s, %s, %s, %s,
6900 %s, %d, %s, %d, %s, %s, %d)",
6901 1, $datetime, $datetime_gmt, '', __( 'Cart', 'usces' ), '', 'publish',
6902 'closed', 'closed', '', USCES_CART_FOLDER, '', '', $datetime, $datetime_gmt,
6903 '', 0, '', 0, 'page', '', 0
6904 );
6905 $wpdb->query( $query );
6906 $cart_number = $wpdb->insert_id;
6907 if ( null !== $cart_number ) {
6908 $query = $wpdb->prepare(
6909 "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) VALUES (%d, %s, %s)",
6910 $cart_number, '_wp_page_template', 'uscescart.php'
6911 );
6912 $wpdb->query( $query );
6913 }
6914 }
6915 update_option( 'usces_cart_number', $cart_number );
6916
6917 // member_page.
6918 $query = $wpdb->prepare( "SELECT ID from $wpdb->posts where post_name = %s", USCES_MEMBER_FOLDER );
6919 $member_number = $wpdb->get_var( $query );
6920 if ( null === $member_number ) {
6921 $query = $wpdb->prepare(
6922 "INSERT INTO $wpdb->posts
6923 (post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status,
6924 comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt,
6925 post_content_filtered, post_parent, guid, menu_order, post_type, post_mime_type, comment_count)
6926 VALUES (%d, %s, %s, %s, %s, %s, %s,
6927 %s, %s, %s, %s, %s, %s, %s, %s,
6928 %s, %d, %s, %d, %s, %s, %d)",
6929 1, $datetime, $datetime_gmt, '', __( 'Membership', 'usces' ), '', 'publish',
6930 'closed', 'closed', '', USCES_MEMBER_FOLDER, '', '', $datetime, $datetime_gmt,
6931 '', 0, '', 0, 'page', '', 0
6932 );
6933 $wpdb->query( $query );
6934 $member_number = $wpdb->insert_id;
6935 if ( null !== $member_number ) {
6936 $query = $wpdb->prepare(
6937 "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) VALUES (%d, %s, %s)",
6938 $member_number, '_wp_page_template', 'uscesmember.php'
6939 );
6940 $wpdb->query( $query );
6941 }
6942 }
6943 update_option( 'usces_member_number', $member_number );
6944 }
6945
6946 public function set_default_categories() {
6947 global $wpdb;
6948
6949 $item_category_slug = apply_filters( 'usces_item_category_slug', 'item' );
6950
6951 $idObj = get_category_by_slug( $item_category_slug );
6952 if ( empty( $idObj ) ) {
6953 $item_cat = array(
6954 'cat_name' => __( 'Items', 'usces' ),
6955 'category_description' => '',
6956 'category_nicename' => $item_category_slug,
6957 'category_parent' => 0,
6958 );
6959 $item_cat_id = wp_insert_category( $item_cat );
6960 update_option( 'usces_item_cat_parent_id', $item_cat_id );
6961 }
6962
6963 $idObj = get_category_by_slug( 'itemreco' );
6964 if ( empty( $idObj ) && isset( $item_cat_id ) ) {
6965 $itemreco_cat = array(
6966 'cat_name' => __( 'Items recommended', 'usces' ),
6967 'category_description' => '',
6968 'category_nicename' => 'itemreco',
6969 'category_parent' => $item_cat_id,
6970 );
6971 $itemreco_cat_id = wp_insert_category( $itemreco_cat );
6972 }
6973
6974 $idObj = get_category_by_slug( 'itemnew' );
6975 if ( empty( $idObj ) && isset( $item_cat_id ) ) {
6976 $itemnew_cat = array(
6977 'cat_name' => __( 'New items', 'usces' ),
6978 'category_description' => '',
6979 'category_nicename' => 'itemnew',
6980 'category_parent' => $item_cat_id,
6981 );
6982 $itemnew_cat_id = wp_insert_category( $itemnew_cat );
6983 }
6984
6985 $idObj = get_category_by_slug( 'itemgenre' );
6986 if ( empty( $idObj ) && isset( $item_cat_id ) ) {
6987 $itemgenre_cat = array(
6988 'cat_name' => __( 'Item genre', 'usces' ),
6989 'category_description' => '',
6990 'category_nicename' => 'itemgenre',
6991 'category_parent' => $item_cat_id,
6992 );
6993 $itemgenre_cat_id = wp_insert_category( $itemgenre_cat );
6994 }
6995 }
6996
6997 public function update_options() {
6998 $target_market = $this->options['system']['target_market'];
6999
7000 $update_shipping_charge = false;
7001 $shipping_charge = isset( $this->options['shipping_charge'] ) ? $this->options['shipping_charge'] : array();
7002 $shipping_charge_count = ( $shipping_charge && is_array( $shipping_charge ) ) ? count( $shipping_charge ) : 0;
7003 foreach ( (array) $target_market as $tm ) {
7004 for ( $i = 0; $i < $shipping_charge_count; $i++ ) {
7005 if ( isset( $shipping_charge[ $i ]['country'] ) && $shipping_charge[ $i ]['country'] == $tm ) {
7006 foreach ( $shipping_charge[ $i ]['value'] as $pref => $value ) {
7007 $shipping_charge[ $i ][ $tm ][ $pref ] = $value;
7008 }
7009 unset( $shipping_charge[ $i ]['country'] );
7010 unset( $shipping_charge[ $i ]['value'] );
7011 $update_shipping_charge = true;
7012 }
7013 }
7014 }
7015 if ( $update_shipping_charge ) {
7016 $this->options['shipping_charge'] = $shipping_charge;
7017 }
7018
7019 $update_delivery_days = false;
7020 $delivery_days = isset( $this->options['delivery_days'] ) ? $this->options['delivery_days'] : array();
7021 $delivery_days_count = ( $delivery_days && is_array( $delivery_days ) ) ? count( $delivery_days ) : 0;
7022 foreach ( (array) $target_market as $tm ) {
7023 for ( $i = 0; $i < $delivery_days_count; $i++ ) {
7024 if ( isset( $delivery_days[ $i ]['country'] ) && $delivery_days[ $i ]['country'] == $tm ) {
7025 foreach ( $delivery_days[ $i ]['value'] as $pref => $value ) {
7026 $delivery_days[ $i ][ $tm ][ $pref ] = $value;
7027 }
7028 unset( $delivery_days[ $i ]['country'] );
7029 unset( $delivery_days[ $i ]['value'] );
7030 $update_delivery_days = true;
7031 }
7032 }
7033 }
7034 if ( $update_delivery_days ) {
7035 $this->options['delivery_days'] = $delivery_days;
7036 }
7037
7038 if ( $update_shipping_charge || $update_delivery_days ) {
7039 update_option( 'usces', $this->options );
7040 }
7041 }
7042
7043 public function get_item_cat_ids() {
7044 $ids = array();
7045 $args = array(
7046 'child_of' => USCES_ITEM_CAT_PARENT_ID,
7047 'hide_empty' => 0,
7048 'hierarchical' => 0,
7049 );
7050 $categories = get_categories( $args );
7051 foreach ( (array) $categories as $category ) {
7052 $ids[] = $category->term_id;
7053 }
7054 return $ids;
7055 }
7056
7057 public function get_item_post_ids() {
7058 global $wpdb;
7059 $query = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_mime_type = %s", 'item' );
7060 $ids = $wpdb->get_col( $query );
7061
7062 return $ids;
7063 }
7064
7065 public function get_item_cat_genre_ids( $post_id ) {
7066 $ids = array();
7067 $all_ids = array();
7068 $genre = get_category_by_slug( 'itemgenre' );
7069 if ( ! empty( $genre->term_id ) ) {
7070 $genre_id = $genre->term_id;
7071 $args = array(
7072 'child_of' => $genre_id,
7073 'hide_empty' => 0,
7074 'hierarchical' => 0,
7075 );
7076 $categories = get_categories( $args );
7077 foreach ( (array) $categories as $category ) {
7078 $ids[] = $category->term_id;
7079 }
7080 $allcats = get_the_category( $post_id );
7081 foreach ( (array) $allcats as $cat ) {
7082 $all_ids[] = $cat->term_id;
7083 }
7084 $results = array_intersect( $ids, $all_ids );
7085 } else {
7086 $results = array();
7087 }
7088 return $results;
7089 }
7090
7091 public function set_item_mime( $post_id, $str ) {
7092 global $wpdb;
7093 if ( WCUtils::is_blank( $str ) ) {
7094 return;
7095 }
7096 $query = $wpdb->prepare( "UPDATE $wpdb->posts SET post_mime_type = %s WHERE ID = %s", $str, $post_id );
7097 $results = $wpdb->query( $query );
7098 return $results;
7099 }
7100
7101 public function isAdnminSSL() {
7102 $plugins = get_option( 'active_plugins' );
7103 foreach ( $plugins as $plugin ) {
7104 if ( false !== strpos( $plugin, USCES_ADMIN_SSL_BASE_NAME ) ) {
7105 return true;
7106 }
7107 }
7108 return false;
7109 }
7110
7111 public function getGuidTax() {
7112 if ( isset( $this->options['tax_display'] ) && 'deactivate' == $this->options['tax_display'] ) {
7113 $str = '';
7114 } else {
7115 $tax_rate = (int) $this->options['tax_rate'];
7116
7117 if ( isset( $this->options['tax_mode'] ) ) {
7118 if ( 'exclude' == $this->options['tax_mode'] ) {
7119 $str = '<em class="tax">' . __( '(Excl. Tax)', 'usces' ) . '</em>';
7120 } else {
7121 $str = '<em class="tax">' . __( '(Incl. Tax)', 'usces' ) . '</em>';
7122 }
7123 } else {
7124 if ( 0 < $tax_rate ) {
7125 $str = '<em class="tax">' . __( '(Excl. Tax)', 'usces' ) . '</em>';
7126 } else {
7127 $str = '<em class="tax">' . __( '(Incl. Tax)', 'usces' ) . '</em>';
7128 }
7129 }
7130 $str = apply_filters( 'usces_filter_tax_guid', $str, $tax_rate );
7131 }
7132 return $str;
7133 }
7134
7135 public function getItemCode( $post_id, $cache = true ) {
7136 $product = wel_get_product( $post_id, $cache );
7137 $itemCode = isset( $product['itemCode'] ) ? $product['itemCode'] : null;
7138 return $itemCode;
7139 }
7140
7141 public function getItemName( $post_id, $cache = true ) {
7142 $product = wel_get_product( $post_id, $cache );
7143 $itemName = isset( $product['itemName'] ) ? $product['itemName'] : null;
7144 return $itemName;
7145 }
7146
7147 public function getItemRestriction( $post_id, $cache = true ) {
7148 $product = wel_get_product( $post_id, $cache );
7149 $itemRestriction = isset( $product['itemRestriction'] ) ? $product['itemRestriction'] : null;
7150 return $itemRestriction;
7151 }
7152
7153 public function getItemOrderAcceptable( $post_id, $cache = true ) {
7154 $product = wel_get_product( $post_id, $cache );
7155 $value = ( ! empty( $product['itemOrderAcceptable'] ) ) ? (int) $product['itemOrderAcceptable'] : 0;
7156 return $value;
7157 }
7158
7159 public function getItemPointrate( $post_id, $cache = true ) {
7160 $product = wel_get_product( $post_id, $cache );
7161 $itemPointrate = isset( $product['itemPointrate'] ) ? $product['itemPointrate'] : null;
7162 return $itemPointrate;
7163 }
7164
7165 public function getItemShipping( $post_id, $cache = true ) {
7166 $product = wel_get_product( $post_id, $cache );
7167 $itemShipping = isset( $product['itemShipping'] ) ? $product['itemShipping'] : null;
7168 return $itemShipping;
7169 }
7170
7171 public function getItemShippingCharge( $post_id, $cache = true ) {
7172 $product = wel_get_product( $post_id, $cache );
7173 $itemShippingCharge = isset( $product['itemShippingCharge'] ) ? (float) $product['itemShippingCharge'] : null;
7174 return $itemShippingCharge;
7175 }
7176
7177 public function getItemDeliveryMethod( $post_id, $cache = true ) {
7178 $product = wel_get_product( $post_id, $cache );
7179 if ( empty( $product['itemDeliveryMethod'] ) ) {
7180 return array();
7181 } else {
7182 return $product['itemDeliveryMethod'];
7183 }
7184 }
7185
7186 public function getItemIndividualSCharge( $post_id, $cache = true ) {
7187 $product = wel_get_product( $post_id, $cache );
7188 $itemIndividualSCharge = isset( $product['itemIndividualSCharge'] ) ? $product['itemIndividualSCharge'] : null;
7189 return $itemIndividualSCharge;
7190 }
7191
7192 public function getItemGpNum1( $post_id, $cache = true ) {
7193 $product = wel_get_product( $post_id, $cache );
7194 $itemGpNum1 = isset( $product['itemGpNum1'] ) ? $product['itemGpNum1'] : null;
7195 return $itemGpNum1;
7196 }
7197
7198 public function getItemGpNum2( $post_id, $cache = true ) {
7199 $product = wel_get_product( $post_id, $cache );
7200 $itemGpNum2 = isset( $product['itemGpNum2'] ) ? $product['itemGpNum2'] : null;
7201 return $itemGpNum2;
7202 }
7203
7204 public function getItemGpNum3( $post_id, $cache = true ) {
7205 $product = wel_get_product( $post_id, $cache );
7206 $itemGpNum3 = isset( $product['itemGpNum3'] ) ? $product['itemGpNum3'] : null;
7207 return $itemGpNum3;
7208 }
7209
7210 public function getItemGpDis1( $post_id, $cache = true ) {
7211 $product = wel_get_product( $post_id, $cache );
7212 $itemGpDis1 = isset( $product['itemGpDis1'] ) ? $product['itemGpDis1'] : null;
7213 return $itemGpDis1;
7214 }
7215
7216 public function getItemGpDis2( $post_id, $cache = true ) {
7217 $product = wel_get_product( $post_id, $cache );
7218 $itemGpDis2 = isset( $product['itemGpDis2'] ) ? $product['itemGpDis2'] : null;
7219 return $itemGpDis2;
7220 }
7221
7222 public function getItemGpDis3( $post_id, $cache = true ) {
7223 $product = wel_get_product( $post_id, $cache );
7224 $itemGpDis3 = isset( $product['itemGpDis3'] ) ? $product['itemGpDis3'] : null;
7225 return $itemGpDis3;
7226 }
7227
7228 /**
7229 * Unused function
7230 */
7231 public function getItemSku( $post_id, $index = '', $cache = true ) {
7232 $array = array();
7233 $skus = $this->get_skus( $post_id, 'sort', $cache );
7234 foreach ( (array) $skus as $sku ) {
7235 $array[] = $sku['code'];
7236 }
7237 if ( ! $array ) {
7238 return false;
7239 }
7240 if ( '' == $index ) {
7241 return $array;
7242 } elseif ( isset( $array[ $index ] ) ) {
7243 return $array[ $index ];
7244 } else {
7245 return false;
7246 }
7247 }
7248
7249 public function getItemPrice( $post_id, $skukey = '', $cache = true ) {
7250 $array = array();
7251 $skus = wel_get_skus( $post_id, 'code', $cache );
7252 foreach ( (array) $skus as $key => $sku ) {
7253 $array[ $key ] = (float) str_replace( ',', '', $sku['price'] );
7254 }
7255 $array = apply_filters( 'usces_filter_get_item_price', $array, $post_id, $skukey, $skus );
7256 if ( ! $array ) {
7257 return false;
7258 }
7259 if ( '' === $skukey ) {
7260 return $array;
7261 } elseif ( isset( $array[ $skukey ] ) ) {
7262 return $array[ $skukey ];
7263 } else {
7264 return false;
7265 }
7266 }
7267
7268 public function getItemDiscount( $post_id, $skukey = '', $cache = true ) {
7269 $display_mode = $this->options['display_mode'];
7270 $decimal = $this->get_currency_decimal();
7271 $array = array();
7272
7273 $skus = wel_get_skus( $post_id, 'code', $cache );
7274 $discount = 0;
7275 foreach ( (array) $skus as $key => $sku ) {
7276 $price = (float) str_replace( ',', '', $sku['price'] );
7277 if ( 'Promotionsale' == $display_mode ) {
7278 if ( 'discount' === $this->options['campaign_privilege'] ) {
7279 if ( 0 === (int) $this->options['campaign_category'] || in_category( (int) $this->options['campaign_category'], $post_id ) ) {
7280 $discount = (float) sprintf( '%.3f', $price * $this->options['privilege_discount'] / 100 );
7281 } else {
7282 $discount = 0;
7283 }
7284 } elseif ( 'point' === $this->options['campaign_privilege'] ) {
7285 $discount = 0;
7286 }
7287 }
7288 if ( 0 != $discount ) {
7289 if ( 0 == $decimal ) {
7290 $discount = ceil( $discount );
7291 } else {
7292 $decipad = (int) str_pad( '1', $decimal + 1, '0', STR_PAD_RIGHT );
7293 $discount = ceil( $discount * $decipad ) / $decipad;
7294 }
7295 }
7296 $discount = apply_filters( 'usces_filter_getItemDiscount', $discount, $price, $post_id, $sku, $display_mode );
7297 $array[ $key ] = $discount;
7298 }
7299 if ( ! $array ) {
7300 return false;
7301 }
7302 if ( '' === $skukey ) {
7303 return $array;
7304 } elseif ( isset( $array[ $skukey ] ) ) {
7305 return $array[ $skukey ];
7306 } else {
7307 return false;
7308 }
7309 }
7310
7311 public function getItemZaiko( $post_id, $skukey = '', $cache = true ) {
7312 $itemOrderAcceptable = $this->getItemOrderAcceptable( $post_id );
7313 $array = array();
7314
7315 $skus = wel_get_skus( $post_id, 'code', $cache );
7316 foreach ( (array) $skus as $key => $sku ) {
7317 $num = $sku['stock'];
7318 if ( 1 != $itemOrderAcceptable || WCUtils::is_blank( $sku['stocknum'] ) ) {
7319 $array[ $key ] = $this->zaiko_status[ $num ];
7320 } else {
7321 if ( 2 > $num && 0 >= (int) $sku['stocknum'] ) {
7322 $array[ $key ] = ( ! empty( $this->options['order_acceptable_label'] ) ) ? $this->options['order_acceptable_label'] : __( 'Order acceptable', 'usces' );
7323 } else {
7324 $array[ $key ] = $this->zaiko_status[ $num ];
7325 }
7326 }
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 getItemZaikoStatusId( $post_id, $skukey = '', $cache = true ) {
7341 $array = array();
7342 $skus = wel_get_skus( $post_id, 'code', $cache );
7343 foreach ( (array) $skus as $key => $sku ) {
7344 $num = $sku['stock'];
7345 $array[ $key ] = $num;
7346 }
7347 if ( ! $array ) {
7348 return false;
7349 }
7350 if ( '' === $skukey ) {
7351 return $array;
7352 } elseif ( isset( $array[ $skukey ] ) ) {
7353 return $array[ $skukey ];
7354 } else {
7355 return false;
7356 }
7357 }
7358
7359 public function updateItemZaiko( $post_id, $skucode, $value ) {
7360 $res = usces_update_sku( $post_id, $skucode, 'stock', $value );
7361 if ( ! $res ) {
7362 return false;
7363 } else {
7364 return true;
7365 }
7366 }
7367
7368 public function getItemZaikoNum( $post_id, $skukey = '', $cache = true ) {
7369 $array = array();
7370 $skus = wel_get_skus( $post_id, 'code', $cache );
7371 foreach ( (array) $skus as $key => $sku ) {
7372 $array[ $key ] = $sku['stocknum'];
7373 }
7374 if ( ! $array ) {
7375 return false;
7376 }
7377 if ( '' === $skukey ) {
7378 return $array;
7379 } elseif ( isset( $array[ $skukey ] ) ) {
7380 return $array[ $skukey ];
7381 } else {
7382 return false;
7383 }
7384 }
7385
7386 public function updateItemZaikoNum( $post_id, $skucode, $value ) {
7387 $res = usces_update_sku( $post_id, $skucode, 'stocknum', $value );
7388 if ( ! $res ) {
7389 return false;
7390 } else {
7391 return true;
7392 }
7393 }
7394
7395 public function getItemDivision( $post_id, $cache = true ) {
7396 if ( usces_is_item( $post_id ) ) {
7397 $product = wel_get_product( $post_id, $cache );
7398 $item_division = $product['item_division'];
7399 $division = empty( $item_division ) ? 'shipped' : $item_division;
7400 } else {
7401 $division = null;
7402 }
7403 return $division;
7404 }
7405
7406 public function getItemChargingType( $post_id, $cart = array(), $cache = true ) {
7407 if ( usces_is_item( $post_id ) ) {
7408 $product = wel_get_product( $post_id, $cache );
7409 $charging = $product['item_charging_type'];
7410 if ( ! defined( 'WCEX_DLSELLER' ) && ! defined( 'WCEX_AUTO_DELIVERY' ) ) {
7411 $charging = null;
7412 }
7413 } else {
7414 $charging = null;
7415 }
7416 switch ( $charging ) {
7417 case 0:
7418 $type = 'once';
7419 break;
7420 case 1:
7421 $type = 'continue';
7422 break;
7423 case 2:
7424 $type = 'regular';
7425 if ( ! empty( $cart ) ) {
7426 if ( empty( $cart['advance'] ) ) {
7427 $type = 'once';
7428 } else {
7429 if ( is_array( $cart['advance'] ) && array_key_exists( 'regular', $cart['advance'] ) ) {
7430 $regular = wel_safe_maybe_unserialize( $cart['advance']['regular'] );
7431 } else {
7432 $advance = $this->cart->wc_unserialize( $cart['advance'] );
7433 $sku = urldecode( $cart['sku'] );
7434 $sku_encoded = $cart['sku'];
7435 $regular = $advance[ $post_id ][ $sku_encoded ]['regular'];
7436 }
7437 $unit = isset( $regular['unit'] ) ? $regular['unit'] : '';
7438 $interval = isset( $regular['interval'] ) ? (int) $regular['interval'] : 0;
7439 /* Treated as normal billing */
7440 if ( empty( $unit ) || 1 > $interval ) {
7441 $type = 'once';
7442 }
7443 }
7444 }
7445 break;
7446 default:
7447 $type = null;
7448 }
7449 return $type;
7450 }
7451
7452 public function getItemFrequency( $post_id, $cache = true ) {
7453 $product = wel_get_product( $post_id, $cache );
7454 return $product['item_frequency'];
7455 }
7456
7457 public function getItemChargingDay( $post_id, $cache = true ) {
7458 $product = wel_get_product( $post_id, $cache );
7459 $day = (int) $product['item_chargingday'];
7460
7461 $chargingday = empty( $day ) ? 1 : $day;
7462 return $chargingday;
7463 }
7464
7465 public function getItemSkuDisp( $post_id, $skukey = '', $cache = true ) {
7466 $array = array();
7467 $skus = wel_get_skus( $post_id, 'code', $cache );
7468 foreach ( (array) $skus as $key => $sku ) {
7469 $array[ $key ] = $sku['name'];
7470 }
7471 if ( ! $array ) {
7472 return false;
7473 }
7474 if ( '' === $skukey ) {
7475 return $array;
7476 } elseif ( isset( $array[ $skukey ] ) ) {
7477 return $array[ $skukey ];
7478 } else {
7479 return false;
7480 }
7481 }
7482
7483 public function getItemSkuUnit( $post_id, $skukey = '', $cache = true ) {
7484 $array = array();
7485 $skus = wel_get_skus( $post_id, 'code', $cache );
7486 foreach ( (array) $skus as $key => $sku ) {
7487 $array[ $key ] = $sku['unit'];
7488 }
7489 if ( ! $array ) {
7490 return false;
7491 }
7492 if ( '' === $skukey ) {
7493 return $array;
7494 } elseif ( isset( $array[ $skukey ] ) ) {
7495 return $array[ $skukey ];
7496 } else {
7497 return false;
7498 }
7499 }
7500
7501 public function getItemSkuAdvance( $post_id, $skukey = '', $cache = true ) {
7502 $array = array();
7503 $skus = wel_get_skus( $post_id, 'code', $cache );
7504 foreach ( (array) $skus as $key => $sku ) {
7505 $array[ $key ] = $sku['advance'];
7506 }
7507 if ( ! $array ) {
7508 return false;
7509 }
7510 if ( '' === $skukey ) {
7511 return $array;
7512 } elseif ( isset( $array[ $skukey ] ) ) {
7513 return $array[ $skukey ];
7514 } else {
7515 return false;
7516 }
7517 }
7518
7519 public function get_item( $post_id, $cache = true ) {
7520 return wel_get_product( $post_id, $cache );
7521 }
7522
7523 public function get_itemOptionKey( $post_id, $enc = false, $cache = true ) {
7524 $opts = usces_get_opts( $post_id, 'sort', $cache );
7525 if ( empty( $opts ) ) {
7526 return;
7527 }
7528
7529 $res = array();
7530 foreach ( (array) $opts as $opt ) {
7531 if ( $enc ) {
7532 $res[] = urlencode( $opt['name'] );
7533 } else {
7534 $res[] = $opt['name'];
7535 }
7536 }
7537 return $res;
7538 }
7539
7540 public function get_itemOptions( $key, $post_id, $cache = true ) {
7541 $opts = wel_get_opts( $post_id, 'name', $cache );
7542 if ( ! isset( $opts[ $key ] ) ) {
7543 return false;
7544 } else {
7545 return $opts[ $key ];
7546 }
7547 }
7548
7549 public function get_postIDbyCode( $item_code, $cache = true ) {
7550 if ( null === $item_code ) {
7551 return false;
7552 }
7553
7554 $post_id = wel_get_id_by_item_code( $item_code, $cache );
7555
7556 return $post_id;
7557 }
7558
7559 public function get_itemByCode( $item_code, $cache = true ) {
7560 if ( null === $item_code ) {
7561 return false;
7562 }
7563
7564 $product = wel_get_product_by_code( $item_code, $cache );
7565
7566 return $product;
7567 }
7568
7569 public function get_pictids( $item_code, $cache = true ) {
7570 return wel_get_sub_pict_ids_by_code( $item_code, $cache );
7571 }
7572
7573 public function get_mainpictid( $item_code, $cache = true ) {
7574 return wel_get_main_pict_id_by_code( $item_code, $cache );
7575 }
7576
7577 public function get_subpictid( $sku_code, $cache = true ) {
7578 global $wpdb;
7579 if ( empty( $sku_code) ) {
7580 return 0;
7581 }
7582 $query = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type = 'attachment' LIMIT 1", $sku_code );
7583 $id = $wpdb->get_var( $query );
7584 $id = apply_filters( 'usces_filter_get_subpictid', $id, $sku_code );
7585 return $id;
7586 }
7587
7588 public function get_skus( $post_id, $keyflag = 'sort', $cache = true ) {
7589 if ( null === $post_id ) {
7590 return false;
7591 }
7592
7593 $skus = wel_get_skus( $post_id, $keyflag, $cache );
7594
7595 return $skus;
7596 }
7597
7598 public function is_item( $post ) {
7599 if ( 'item' == $post->post_mime_type ) {
7600 return true;
7601 } else {
7602 return false;
7603 }
7604 }
7605
7606 public function getItemIds( $end_type ) {
7607 global $wpdb;
7608
7609 $cache_key = 'wel_item_ids_' . $end_type;
7610
7611 $ids = wp_cache_get( $cache_key );
7612 if ( false === $ids ) {
7613
7614 if ( 'front' == $end_type ) {
7615 $query = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_status = %s AND post_mime_type = %s", 'publish', 'item' );
7616 }
7617 if ( 'back' == $end_type ) {
7618 $query = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_mime_type = %s", 'item' );
7619 }
7620 $ids = $wpdb->get_col( $query );
7621
7622 if ( null !== $ids ) {
7623 wp_cache_set( $cache_key, $ids );
7624 }
7625 }
7626
7627 if ( null === $ids ) {
7628 return array();
7629 } else {
7630 return $ids;
7631 }
7632 }
7633
7634 public function getNotItemIds() {
7635 global $wpdb;
7636 $query = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_status = %s AND post_mime_type <> %s", 'publish', 'item' );
7637 $ids = $wpdb->get_col( $query );
7638 if ( empty( $ids ) ) {
7639 $ids = array();
7640 }
7641 return $ids;
7642 }
7643
7644 public function getPaymentMethod( $name ) {
7645 $res = array();
7646 $payments = $this->options['payment_method'];
7647 foreach ( (array) $payments as $payment ) {
7648 if ( $name == $payment['name'] ) {
7649 $res = $payment;
7650 break;
7651 }
7652 }
7653 return $res;
7654 }
7655
7656 public function order_processing( $results = array() ) {
7657 do_action( 'usces_pre_reg_orderdata' );
7658 $acting = isset( $_REQUEST['acting'] ) ? $_REQUEST['acting'] : '';
7659 global $usces;
7660 $usces_entries = $this->cart->get_entry();
7661 $payments = $this->getPayments( $usces_entries['order']['payment_name'] );
7662 $nonacting_settlements = apply_filters( 'usces_filter_nonacting_settlements', $this->nonacting_settlements );
7663
7664 $res = usces_check_acting_return_duplicate( $results );
7665 if ( $res != null && ! in_array( $payments['settlement'], $nonacting_settlements ) ) {
7666 usces_log( 'order processing duplicate : acting=' . $acting . ', order_id=' . $res, 'acting_transaction.log' );
7667 return 'ordercompletion';
7668 }
7669 if ( isset( $_REQUEST['acting'] ) && ( 'jpayment_card' == $_REQUEST['acting'] || 'jpayment_conv' == $_REQUEST['acting'] || 'jpayment_bank' == $_REQUEST['acting'] ) ) {
7670 usces_log( $_REQUEST['acting'] . ' transaction : ' . $_REQUEST['gid'], 'acting_transaction.log' ); // OK.
7671 }
7672 if ( isset( $_REQUEST['acting'] ) && ( 'paypal_ec' == $_REQUEST['acting'] ) ) {
7673 if ( ! usces_paypal_doecp( $results ) ) {
7674 return 'error';
7675 }
7676 }
7677 $order_id = usces_reg_orderdata( $results );
7678 do_action( 'usces_post_reg_orderdata', $order_id, $results );
7679
7680 if ( $order_id ) {
7681 // mail(function.php).
7682 $mail_res = usces_send_ordermail( $order_id );
7683 return 'ordercompletion';
7684
7685 } else {
7686 return 'error';
7687 }
7688 }
7689
7690 /**
7691 * 決済処理
7692 *
7693 * @param string $acting_flg Payment type.
7694 * @param array $post_query Post data.
7695 * @param string $acting_status Status.
7696 * @return mixed
7697 */
7698 public function acting_processing( $acting_flg, $post_query, $acting_status ) {
7699 global $wpdb;
7700
7701 $entry = $this->cart->get_entry();
7702 $delim = apply_filters( 'usces_filter_delim', $this->delim );
7703 $acting_flg = trim( $acting_flg );
7704
7705 if ( empty( $acting_flg ) ) {
7706 return 'error';
7707 }
7708
7709 if ( 'paypal.php' == $acting_flg ) {
7710
7711 } elseif ( 'epsilon.php' == $acting_flg ) {
7712
7713 } elseif ( 'acting_paypal_ec' == $acting_flg ) {
7714 $acting_opts = $this->options['acting_settings']['paypal'];
7715 $addroverride = '1';
7716 if ( isset( $_POST['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] ) ) {
7717 if ( 'US' == $_POST['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] || 'CA' == $_POST['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] ) {
7718 $addroverride = '0';
7719 }
7720 } else {
7721 $addroverride = '0';
7722 }
7723 $rand = ( isset( $_POST['PAYMENTREQUEST_0_CUSTOM'] ) ) ? $_POST['PAYMENTREQUEST_0_CUSTOM'] : '(empty key)';
7724
7725 $nvpstr = $post_query;
7726 $nvpstr .= '&ADDROVERRIDE=' . $addroverride;
7727 $nvpstr .= '&PAYMENTREQUEST_0_PAYMENTACTION=' . apply_filters( 'usces_filter_paypal_ec_paymentaction', 'Sale' );
7728
7729 // The returnURL is the location where buyers return to when a payment has been succesfully authorized.
7730 $nvpstr .= '&RETURNURL=' . urlencode( USCES_CART_URL . $delim . 'acting=paypal_ec&acting_return=1' );
7731
7732 // The cancelURL is the location buyers are sent to when they hit the cancel button during authorization of payment during the PayPal flow.
7733 $cancelurl = urlencode( USCES_CART_URL . $delim . 'confirm=1' );
7734 $pos = strpos( $post_query, 'paypal_from_cart' );
7735 if ( false !== $pos ) {
7736 $cancelurl = urlencode( USCES_CART_URL );
7737 }
7738 $nvpstr .= '&CANCELURL=' . apply_filters( 'usces_filter_paypal_ec_cancelurl', $cancelurl, $post_query );
7739
7740 $nvpstr .= '&PAYMENTREQUEST_0_NOTIFYURL=' . urlencode( USCES_PAYPAL_NOTIFY_URL );
7741
7742 // Seamless checkout.
7743 if ( isset( $_SESSION['liwpp']['token'] ) && ! empty( $_SESSION['liwpp']['token'] ) ) {
7744 $nvpstr .= '&IDENTITYACCESSTOKEN=' . $_SESSION['liwpp']['token'];
7745 }
7746
7747 $this->paypal->setMethod( 'SetExpressCheckout' );
7748 $this->paypal->setData( $nvpstr );
7749 $res = $this->paypal->doExpressCheckout();
7750 $resArray = $this->paypal->getResponse();
7751 $ack = strtoupper( $resArray['ACK'] );
7752 if ( 'SUCCESS' == $ack || 'SUCCESSWITHWARNING' == $ack ) {
7753 $token = urldecode( $resArray['TOKEN'] );
7754 $payPalURL = $acting_opts['paypal_url'] . '?cmd=_express-checkout&token=' . $token . '&useraction=commit';
7755 header( 'Location: ' . $payPalURL );
7756
7757 } else {
7758 // Display a user friendly Error on the page using any of the following error information returned by PayPal.
7759 $ErrorCode = urldecode( $resArray['L_ERRORCODE0'] );
7760 $ErrorShortMsg = urldecode( $resArray['L_SHORTMESSAGE0'] );
7761 $ErrorLongMsg = urldecode( $resArray['L_LONGMESSAGE0'] );
7762 $ErrorSeverityCode = urldecode( $resArray['L_SEVERITYCODE0'] );
7763 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' );
7764 $log = array(
7765 'acting' => 'paypal_ec',
7766 'key' => $rand,
7767 'result' => $ack,
7768 'data' => $resArray,
7769 );
7770 usces_save_order_acting_error( $log );
7771 header( 'Location: ' . USCES_CART_URL . $delim . 'acting=paypal_ec&acting_return=0' );
7772 }
7773 exit;
7774
7775 } elseif ( 'acting_telecom_edy' == $acting_flg ) { /* テレコムクレジット Edy決済 */
7776 $table_meta_name = $wpdb->prefix . 'usces_order_meta';
7777 $value = array();
7778 $value['usces_cart'] = $_SESSION['usces_cart'];
7779 $value['usces_entry'] = $_SESSION['usces_entry'];
7780 $value['usces_member'] = $_SESSION['usces_member'];
7781 $mvalue = serialize( $value );
7782 $mquery = $wpdb->prepare( "INSERT INTO $table_meta_name (order_id, meta_key, meta_value) VALUES (%d, %s, %s)", $_POST['option'], $_POST['option'], $mvalue );
7783 $res = $wpdb->query( $mquery );
7784
7785 unset( $_SESSION['usces_cart'] );
7786 unset( $_SESSION['usces_entry'] );
7787
7788 $acting_opts = $this->options['acting_settings']['telecom'];
7789 header( 'location: ' . $acting_opts['send_url_edy'] . '?acting=telecom_edy' . $post_query );
7790 exit;
7791
7792 } elseif ( 'acting_digitalcheck_card' == $acting_flg ) { /* ペイメントフォー カード決済(旧メタップスペイメント、旧デジタルチェック、旧ペイデザイン) */
7793 $acting_opts = $this->options['acting_settings']['digitalcheck'];
7794 $interface = parse_url( $acting_opts['send_url_user_id'] );
7795 $kakutei = ( empty( $acting_opts['card_kakutei'] ) ) ? '0' : $acting_opts['card_kakutei'];
7796
7797 $params = array(
7798 'IP' => $acting_opts['card_ip'],
7799 'PASS' => $acting_opts['card_pass'],
7800 'SID' => $_POST['SID'],
7801 'IP_USER_ID' => $_POST['IP_USER_ID'],
7802 'N1' => $_POST['N1'],
7803 'K1' => $_POST['K1'],
7804 'FUKA' => $acting_flg,
7805 'KAKUTEI' => $kakutei,
7806 );
7807 $vars = http_build_query( $params );
7808
7809 $header = 'POST ' . $interface['path'] . " HTTP/1.1\r\n";
7810 $header .= 'Host: ' . $interface['host'] . "\r\n";
7811 $header .= "User-Agent: PHP Script\r\n";
7812 $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
7813 $header .= 'Content-Length: ' . strlen( $vars ) . "\r\n";
7814 $header .= "Connection: close\r\n\r\n";
7815 $header .= $vars;
7816
7817 $fp = @stream_socket_client( 'tlsv1.2://' . $interface['host'] . ':443', $errno, $errstr, 30 );
7818 if ( ! $fp ) {
7819 // usces_log( 'digitalcheck card : TLS(v1.2) Error', 'acting_transaction.log' );
7820 $log = array(
7821 'acting' => 'digitalcheck_card',
7822 'key' => $_POST['SID'],
7823 'result' => 'SSL/TLS ERROR (' . $errno . ')',
7824 'data' => array( $errstr ),
7825 );
7826 usces_save_order_acting_error( $log );
7827 wp_redirect(
7828 add_query_arg(
7829 array(
7830 'acting' => 'digitalcheck_card',
7831 'acting_return' => 0,
7832 ),
7833 USCES_CART_URL
7834 )
7835 );
7836 exit();
7837 }
7838
7839 if ( $fp ) {
7840 fwrite( $fp, $header );
7841 $headerdone = false;
7842 $page = '';
7843 while ( ! feof( $fp ) ) {
7844 $line = fgets( $fp, 1024 );
7845 if ( 0 == strcmp( $line, "\r\n" ) ) {
7846 $headerdone = true;
7847 } elseif ( $headerdone ) {
7848 $page .= $line;
7849 }
7850 }
7851 fclose( $fp );
7852 $lines = explode( "\n", $page );
7853 if ( false !== strpos( $lines[0], 'OK' ) ) {
7854 // usces_log( 'digitalcheck card entry data (acting_processing) : ' . print_r( $entry, true ), 'acting_transaction.log');
7855 wp_redirect(
7856 add_query_arg(
7857 array(
7858 'acting' => 'digitalcheck_card',
7859 'acting_return' => 1,
7860 'SID' => $_POST['SID'],
7861 'FUKA' => $acting_flg,
7862 ),
7863 USCES_CART_URL
7864 )
7865 );
7866 exit();
7867 } else {
7868 // usces_log( 'digitalcheck card : Certification Error : ' . $page, 'acting_transaction.log' );
7869 $log = array(
7870 'acting' => 'digitalcheck_card',
7871 'key' => $_POST['SID'],
7872 'result' => 'CERTIFICATION ERROR',
7873 'data' => $lines,
7874 );
7875 usces_save_order_acting_error( $log );
7876 wp_redirect(
7877 add_query_arg(
7878 array(
7879 'acting' => 'digitalcheck_card',
7880 'acting_return' => 0,
7881 ),
7882 USCES_CART_URL
7883 )
7884 );
7885 exit();
7886 }
7887 }
7888 exit();
7889
7890 } elseif ( 'acting_digitalcheck_conv' == $acting_flg ) { /* ペイメントフォー コンビニ決済(旧メタップスペイメント、旧デジタルチェック、旧ペイデザイン) */
7891 if ( isset( $_REQUEST['STORE'] ) && '99' != $_REQUEST['STORE'] ) {
7892 $res = $this->order_processing();
7893 if ( 'ordercompletion' == $res ) {
7894 $table_meta_name = $wpdb->prefix . 'usces_order_meta';
7895 $mquery = $wpdb->prepare( "SELECT order_id FROM $table_meta_name WHERE meta_key = %s AND meta_value = %s", 'SID', $_REQUEST['SID'] );
7896 $order_id = $wpdb->get_var( $mquery );
7897 if ( $order_id ) {
7898 $data = array(
7899 'settltment_status' => __( 'Failure', 'usces' ),
7900 'settltment_errmsg' => __( 'Settlement was not completed.', 'usces' ),
7901 );
7902 $this->set_order_meta_value( 'acting_digitalcheck_conv', serialize( $data ), $order_id );
7903 $this->set_order_meta_value( 'wc_trans_id', $_REQUEST['SID'], $order_id );
7904 }
7905 $this->cart->crear_cart();
7906 $acting_opts = $this->options['acting_settings']['digitalcheck'];
7907 header( 'location: ' . $acting_opts['send_url_conv'] . '?acting=digitalcheck_conv' . $post_query );
7908 exit;
7909 } else {
7910 // usces_log( 'digitalcheck conv : order processing error', 'acting_transaction.log' );
7911 $log = array(
7912 'acting' => 'digitalcheck_conv',
7913 'key' => $_REQUEST['SID'],
7914 'result' => 'ORDER DATA REGISTERED ERROR',
7915 'data' => $_REQUEST,
7916 );
7917 usces_save_order_acting_error( $log );
7918 header( 'location: ' . USCES_CART_URL . $delim . 'acting=digitalcheck_conv&acting_return=0' );
7919 exit;
7920 }
7921 } else {
7922 $acting_opts = $this->options['acting_settings']['digitalcheck'];
7923 header( 'location: ' . $acting_opts['send_url_conv'] . '?acting=digitalcheck_conv' . $post_query );
7924 exit;
7925 }
7926
7927 } elseif ( 'acting_veritrans_card' == $acting_flg || 'acting_veritrans_conv' == $acting_flg ) { /* ベリトランス カード決済・コンビニ決済 */
7928 $acting_opts = $this->options['acting_settings']['veritrans'];
7929 $acting = substr( $acting_flg, 7 );
7930 $dummy_payment_flag = ( 'public' == $acting_opts['ope'] ) ? '0' : '1';
7931 $order_id = isset( $_POST['ORDER_ID'] ) ? $_POST['ORDER_ID'] : '';
7932 $regist_url = ( defined( 'VERITRANS_SHA2_TEST' ) ) ? 'https://sair.veritrans.co.jp/web/commodityRegist.action' : $acting_opts['regist_url'];
7933 $url = parse_url( $regist_url );
7934 $path = empty( $url['path'] ) ? '/' : $url['path'];
7935
7936 $postdata = $post_query;
7937 if ( 'acting_veritrans_card' == $acting_flg ) {
7938 $card_capture_flag = ( 'capture' == $acting_opts['card_capture_flag'] ) ? '1' : '0';
7939 $postdata .= '&CARD_CAPTURE_FLAG=' . $card_capture_flag;
7940 }
7941 if ( 'acting_veritrans_conv' == $acting_flg ) {
7942 $postdata .= '&NAME1=' . urlencode( mb_substr( mb_convert_kana( $entry['customer']['name1'], 'ASKV', 'UTF-8' ), 0, 10, 'UTF-8' ) );
7943 $postdata .= '&NAME2=' . urlencode( mb_substr( mb_convert_kana( $entry['customer']['name2'], 'ASKV', 'UTF-8' ), 0, 10, 'UTF-8' ) );
7944 if ( ! empty( $entry['customer']['name3'] ) ) {
7945 $kana1 = mb_substr( mb_convert_kana( $entry['customer']['name3'], 'ASKV', 'UTF-8' ), 0, 10, 'UTF-8' );
7946 mb_regex_encoding( 'UTF-8' );
7947 if ( mb_ereg( "^[ア-ン゛゜ァ-ォャ-ョー]+$", $kana1 ) ) {
7948 $postdata .= '&KANA1=' . urlencode( $kana1 );
7949 }
7950 }
7951 if ( ! empty( $entry['customer']['name4'] ) ) {
7952 $kana2 = mb_substr( mb_convert_kana( $entry['customer']['name4'], 'ASKV', 'UTF-8' ), 0, 10, 'UTF-8' );
7953 mb_regex_encoding( 'UTF-8' );
7954 if ( mb_ereg( "^[ア-ン゛゜ァ-ォャ-ョー]+$", $kana2 ) ) {
7955 $postdata .= '&KANA2=' . urlencode( $kana2 );
7956 }
7957 }
7958 $postdata .= '&TELEPHONE_NO=' . str_replace( '-', '', $entry['customer']['tel'] );
7959 if ( 1 < (int) $acting_opts['conv_timelimit'] && (int) $acting_opts['conv_timelimit'] <= 60 ) {
7960 $timelimit = date( 'Ymd', strtotime( '+' . $acting_opts['conv_timelimit'] . ' days' ) );
7961 $postdata .= '&TIMELIMIT_OF_PAYMENT=' . $timelimit;
7962 }
7963 }
7964 if ( 'on' == $acting_opts['mailaddress'] ) {
7965 $postdata .= '&MAILADDRESS=' . $entry['customer']['mailaddress1'];
7966 }
7967 $postdata .= '&MERCHANT_ID=' . $acting_opts['merchant_id'];
7968 $postdata .= '&SESSION_ID=' . session_id();
7969 $postdata .= '&FINISH_PAYMENT_RETURN_URL=' . urlencode( USCES_CART_URL . $delim . 'acting=' . $acting . '&acting_return=1&result=1' );
7970 $postdata .= '&UNFINISH_PAYMENT_RETURN_URL=' . urlencode( USCES_CART_URL . $delim . 'acting=' . $acting . '&confirm=1' );
7971 $postdata .= '&ERROR_PAYMENT_RETURN_URL=' . urlencode( USCES_CART_URL . $delim . 'acting=' . $acting . '&acting_return=0' );
7972 $postdata .= '&FINISH_PAYMENT_ACCESS_URL=' . urlencode( USCES_CART_URL . $delim . 'acting=' . $acting );
7973 $postdata .= '&DUMMY_PAYMENT_FLAG=' . $dummy_payment_flag;
7974
7975 $postlength = strlen( $postdata );
7976
7977 $request = 'POST ' . $path . ' HTTP/1.1' . "\r\n";
7978 $request .= 'Host: ' . $url['host'] . "\r\n";
7979 $request .= 'User-Agent: HttpRequest Powered by ' . phpversion() . "\r\n";
7980 $request .= 'Connection: close' . "\r\n";
7981 $request .= 'Accept-Language: ja' . "\r\n";
7982 $request .= 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
7983 $request .= 'Content-Length: ' . $postlength . "\r\n\r\n";
7984 $request .= $postdata;
7985
7986 $code = 0;
7987 $resBody = '';
7988 $con = @stream_socket_client( 'tlsv1.2://' . $url['host'] . ':443', $errno, $errstr, 30 );
7989 if ( ! $con ) {
7990 usces_log( 'Veritrans : TLS(v1.2) Error', 'acting_transaction.log' );
7991 $con = @fsockopen( 'ssl://' . $url['host'], 443, $errno, $errstr, 30 );
7992 if ( ! $con ) {
7993 usces_log( 'Veritrans : SSL Error', 'acting_transaction.log' );
7994 $log = array(
7995 'acting' => $acting,
7996 'key' => $order_id,
7997 'result' => 'SSL/TLS ERROR (' . $errno . ')',
7998 'data' => array( $errstr ),
7999 );
8000 usces_save_order_acting_error( $log );
8001 header( 'location: ' . USCES_CART_URL . $delim . 'acting=' . $acting_flg . '&acting_return=0' );
8002 exit;
8003 }
8004 }
8005
8006 if ( $con ) {
8007 $ret = fwrite( $con, $request );
8008 if ( $ret == strlen( $request ) ) {
8009 $res = $this->readResponse( $con );
8010 $code = $res['Code'];
8011 $resBody = $res['Body'];
8012
8013 } else {
8014 usces_log( 'Veritrans Write NG: Sent:' . strlen( $request ) . ' Send:' . $ret, 'acting_transaction.log' );
8015 }
8016 fclose( $con );
8017 }
8018
8019 // 正常終了(200 OK)が返ったか.
8020 if ( 200 == intval( $code ) ) {
8021 $merchantKey = null;
8022 $browserKey = null;
8023 $scd = null;
8024 $error_message = null;
8025
8026 // レスポンスデータからマーチャントキー、ブラウザキーを取得.
8027 $bodyLine = explode( "\n", $resBody );
8028 foreach ( $bodyLine as $line ) {
8029 if ( preg_match( '/^MERCHANT_ENCRYPTION_KEY=(.+)/', $line, $match ) ) {
8030 $merchantKey = $match[1];
8031 } elseif ( preg_match( '/^BROWSER_ENCRYPTION_KEY=(.+)/', $line, $match ) ) {
8032 $browserKey = $match[1];
8033 } elseif ( preg_match('/^SCD=(.+)/', $line, $match ) ) {
8034 $scd = $match[1];
8035 } elseif ( preg_match( '/^ERROR_MESSAGE=(.+)/', $line, $match ) ) {
8036 $error_message = $match[1];
8037 }
8038 }
8039
8040 // 両方取れたらOK。SCDはカードでセキュリティコードが入力された場合のみ.
8041 if ( ! is_null( $merchantKey ) && ! is_null( $browserKey ) ) {
8042 $getdata = '?MERCHANT_ID=' . $acting_opts['merchant_id'];
8043 $getdata .= '&ORDER_ID=' . $order_id;
8044 $getdata .= '&BROWSER_ENCRYPTION_KEY=' . urlencode( $browserKey );
8045 $payment_url = ( defined( 'VERITRANS_SHA2_TEST' ) ) ? 'https://sair.veritrans.co.jp/web/paymentStart.action' : $acting_opts['payment_url'];
8046 header( 'location: ' . $payment_url . $getdata );
8047
8048 } else {
8049 if ( ! is_null( $error_message ) ) {
8050 usces_log( 'Veritrans AWeb:' . $error_message, 'acting_transaction.log' );
8051 $log = array(
8052 'acting' => $acting,
8053 'key' => $order_id,
8054 'result' => $code,
8055 'data' => $bodyLine,
8056 );
8057 usces_save_order_acting_error( $log );
8058 }
8059 header( 'location: ' . USCES_CART_URL . $delim . 'acting=' . $acting_flg . '&acting_return=0' );
8060 }
8061
8062 } else {
8063 usces_log( 'Veritrans Response NG: ' . $resBody, 'acting_transaction.log' );
8064 $bodyLine = explode( "\n", $resBody );
8065 $log = array(
8066 'acting' => $acting,
8067 'key' => $order_id,
8068 'result' => $code,
8069 'data' => $bodyLine,
8070 );
8071 usces_save_order_acting_error( $log );
8072 header( 'location: ' . USCES_CART_URL . $delim . 'acting=' . $acting_flg . '&acting_return=0' );
8073 }
8074 exit;
8075 }
8076
8077 do_action( 'usces_action_acting_processing', $acting_flg, $post_query );
8078 $acting_status = apply_filters( 'usces_filter_acting_processing', $acting_flg, $post_query, $acting_status );
8079 return $acting_status;
8080 }
8081
8082 private function readResponse( $fp ) {
8083 $res = array(
8084 'Status' => '',
8085 'Version' => '',
8086 'Code' => 0,
8087 'Message' => '',
8088 'Headers' => array(),
8089 'Body' => '',
8090 );
8091
8092 // HTTPステータスの読み込み.
8093 $line = $this->readLine( $fp );
8094 if ( 0 == preg_match( '/^(HTTP\/1\.[0-9x]+)\s+([0-9]+)\s+(.+)/i', $line, $match ) ) {
8095 return $res;
8096 }
8097 $res['Status'] = $line;
8098 $res['Version'] = $match[1];
8099 $res['Code'] = $match[2];
8100 $res['Message'] = $match[3];
8101
8102 // レスポンスヘッダの読み込み.
8103 while ( ! feof( $fp ) ) {
8104 $line = $this->readLine( $fp );
8105 if ( '' != $line ) {
8106 list( $hname, $hvalue ) = explode( ':', $line, 2 );
8107 $res['Headers'][ strtolower( $hname ) ] = ltrim( $hvalue );
8108 } else {
8109 break;
8110 }
8111 }
8112 // レスポンスデータの読み込み.
8113 while ( ! feof( $fp ) ) {
8114 $data = $this->readLine( $fp ) . "\n";
8115 if ( '' == $data ) {
8116 break;
8117 }
8118 $res['Body'] .= $data;
8119 }
8120 return $res;
8121 }
8122
8123 private function readLine( $fp ) {
8124 if ( ! $fp ) {
8125 return '';
8126 }
8127 // レスポンスデータを受信.
8128 $line = null;
8129 while ( ! feof( $fp ) ) {
8130 $line .= @fgets( $fp, 4096 );
8131 if ( "\n" == substr( $line, -1 ) ) {
8132 return rtrim( $line, "\r\n" );
8133 }
8134 }
8135 return $line;
8136 }
8137
8138 public function inquiry_processing() {
8139 $mail_res = usces_send_inquirymail();
8140
8141 if ( $mail_res ) {
8142 return 'inquiry_comp';
8143 } else {
8144 return 'inquiry_error';
8145 }
8146 }
8147
8148 public function lastprocessing() {
8149 if ( 'ordercompletion' == $this->page ) {
8150 $this->cart->crear_cart();
8151 }
8152 do_action( 'usces_action_lastprocessing' );
8153
8154 unset( $_SESSION['usces_singleitem'] );
8155 }
8156
8157 public function is_item_zaiko( $post_id, $sku_code ) {
8158 $res = false;
8159 $status_num = false;
8160 $zaiko_num = false;
8161 if ( ! empty( $post_id ) ) {
8162 $sku_code = (string) $sku_code;
8163 $status_num = $this->getItemZaikoStatusId( $post_id, $sku_code );
8164 $zaiko_num = $this->getItemZaikoNum( $post_id, $sku_code );
8165 $itemOrderAcceptable = $this->getItemOrderAcceptable( $post_id );
8166 if ( 1 != $itemOrderAcceptable ) {
8167 if ( false !== $zaiko_num
8168 && ( 0 < (int) $zaiko_num || WCUtils::is_blank( $zaiko_num ) )
8169 && false !== $status_num
8170 && 2 > (int) $status_num ) {
8171 $res = true;
8172 } else {
8173 $res = false;
8174 }
8175 } else {
8176 if ( false !== $status_num
8177 && 2 > (int) $status_num ) {
8178 $res = true;
8179 } else {
8180 $res = false;
8181 }
8182 }
8183 }
8184 return apply_filters( 'usces_is_item_zaiko', $res, $post_id, $sku_code, $status_num, $zaiko_num );
8185 }
8186
8187 public function get_total_price( $cart = array() ) {
8188 if ( empty( $cart ) ) {
8189 $cart = $this->cart->get_cart();
8190 }
8191 $total_price = 0;
8192
8193 if ( ! empty( $cart ) ) {
8194 $cart_count = ( is_array( $cart ) ) ? count( $cart ) : 0;
8195 for ( $i = 0; $i < $cart_count; $i++ ) {
8196 $quantity = (float) $cart[ $i ]['quantity'];
8197 $skuPrice = (float) $cart[ $i ]['price'];
8198
8199 $total_price += ( $skuPrice * $quantity );
8200 }
8201 }
8202 return apply_filters( 'usces_filter_get_total_price', $total_price, $cart );
8203 }
8204
8205 public function get_total_quantity( $cart = array() ) {
8206 if ( empty( $cart ) ) {
8207 $cart = $this->cart->get_cart();
8208 }
8209 $total_quantity = 0;
8210
8211 if ( ! empty( $cart ) ) {
8212 $cart_count = ( is_array( $cart ) ) ? count( $cart ) : 0;
8213 for ( $i = 0; $i < $cart_count; $i++ ) {
8214 $total_quantity += (float) $cart[ $i ]['quantity'];
8215 }
8216 }
8217 return $total_quantity;
8218 }
8219
8220 public function get_order_point( $mem_id = '', $display_mode = '', $cart = array() ) {
8221 if ( '' == $mem_id || 'deactivate' == $this->options['membersystem_state'] || 'deactivate' == $this->options['membersystem_point'] ) {
8222 return 0;
8223 }
8224
8225 if ( empty( $cart ) ) {
8226 $cart = $this->cart->get_cart();
8227 }
8228 if ( empty( $display_mode ) ) {
8229 $display_mode = $this->options['display_mode'];
8230 }
8231 $point = 0;
8232 $total = $this->get_total_price( $cart );
8233 if ( 'Promotionsale' == $display_mode ) {
8234 if ( 'discount' == $this->options['campaign_privilege'] ) {
8235 foreach ( $cart as $rows ) {
8236 $cats = $this->get_post_term_ids( $rows['post_id'], 'category' );
8237 if ( ! in_array( $this->options['campaign_category'], $cats ) ) {
8238 $product = wel_get_product( $rows['post_id'] );
8239 $rate = (float) $product['itemPointrate'];
8240 $price = (float) $rows['price'] * (float) $rows['quantity'];
8241 $point = (float) sprintf( '%.3f', $point + ( $price * $rate / 100 ) );
8242 }
8243 }
8244 } elseif ( 'point' == $this->options['campaign_privilege'] ) {
8245 foreach ( $cart as $rows ) {
8246 $product = wel_get_product( $rows['post_id'] );
8247 $rate = (float) $product['itemPointrate'];
8248 $price = (float) $rows['price'] * (float) $rows['quantity'];
8249 $cats = $this->get_post_term_ids( $rows['post_id'], 'category' );
8250 if ( in_array( $this->options['campaign_category'], $cats ) ) {
8251 $point = (float) sprintf( '%.3f', $point + ( $price * $rate / 100 * (float) $this->options['privilege_point'] ) );
8252 } else {
8253 $point = (float) sprintf( '%.3f', $point + ( $price * $rate / 100 ) );
8254 }
8255 }
8256 }
8257 } else {
8258 foreach ( $cart as $rows ) {
8259 $product = wel_get_product( $rows['post_id'] );
8260 $rate = (float) $product['itemPointrate'];
8261 $price = (float) $rows['price'] * (float) $rows['quantity'];
8262 $point = (float) sprintf( '%.3f', $point + ( $price * $rate / 100 ) );
8263 }
8264 }
8265
8266 $entry = $this->cart->get_entry();
8267 $use_point = isset( $entry['order']['usedpoint'] ) ? (int) $entry['order']['usedpoint'] : 0;
8268 if ( 0 < $use_point && 0 < $total ) {
8269 $point = (float) sprintf( '%.3f', $point - ( $point * $use_point / $total ) );
8270 $point = ceil( $point );
8271 if ( 0 > $point ) {
8272 $point = 0;
8273 }
8274 } else {
8275 if ( 0 < $point ) {
8276 $point = ceil( $point );
8277 }
8278 }
8279
8280 return apply_filters( 'usces_filter_get_order_point', $point, $mem_id, $display_mode, $cart );
8281 }
8282
8283 public function get_order_discount( $display_mode = '', $cart = array() ) {
8284 if ( empty( $cart ) ) {
8285 $cart = $this->cart->get_cart();
8286 }
8287 if ( empty( $display_mode ) ) {
8288 $display_mode = $this->options['display_mode'];
8289 }
8290 $discount = 0;
8291 if ( 'Promotionsale' == $display_mode ) {
8292 if ( 'discount' == $this->options['campaign_privilege'] ) {
8293 if ( 0 === (int) $this->options['campaign_category'] ) {
8294 $total = $this->get_total_price( $cart );
8295 $discount = (float) sprintf( '%.3f', $total * (float) $this->options['privilege_discount'] / 100 );
8296 } else {
8297 foreach ( $cart as $cart_row ) {
8298 if ( in_category( (int) $this->options['campaign_category'], $cart_row['post_id'] ) ) {
8299 $discount += (float) sprintf( '%.3f', (float) $cart_row['price'] * (float) $cart_row['quantity'] * (float) $this->options['privilege_discount'] / 100 );
8300 }
8301 }
8302 }
8303 if ( 0 != $discount ) {
8304 $decimal = $this->get_currency_decimal();
8305 if ( 0 == $decimal ) {
8306 $discount = ceil( $discount );
8307 } else {
8308 $decipad = (int) str_pad( '1', $decimal + 1, '0', STR_PAD_RIGHT );
8309 $discount = ceil( $discount * $decipad ) / $decipad;
8310 }
8311 $discount = $discount * -1;
8312 }
8313 } elseif ( 'point' == $this->options['campaign_privilege'] ) {
8314 $discount = 0;
8315 }
8316 }
8317 $discount = apply_filters( 'usces_order_discount', $discount, $cart );
8318 return $discount;
8319 }
8320
8321 public function getShippingCharge( $pref, $cart = array(), $entry = array() ) {
8322 if ( empty( $cart ) ) {
8323 $cart = $this->cart->get_cart();
8324 }
8325 if ( empty( $entry ) ) {
8326 $entry = $this->cart->get_entry();
8327 }
8328 if ( function_exists( 'dlseller_have_shipped' ) && ! dlseller_have_shipped() ) {
8329 $charge = 0;
8330 $charge = apply_filters( 'usces_filter_getShippingCharge', $charge, $cart, $entry );
8331 return $charge;
8332 }
8333
8334 // 配送方法ID.
8335 $d_method_id = $entry['order']['delivery_method'];
8336 // 配送方法index.
8337 $d_method_index = $this->get_delivery_method_index( $d_method_id );
8338 // 送料ID.
8339 $fixed_charge_id = ( isset( $this->options['delivery_method'][ $d_method_index ]['charge'] ) ) ? $this->options['delivery_method'][ $d_method_index ]['charge'] : -1;
8340 $individual_quant = 0;
8341 $total_quant = 0;
8342 $charges = array();
8343 $individual_charges = array();
8344 $country = ( isset( $entry['delivery']['country'] ) && ! empty( $entry['delivery']['country'] ) ) ? $entry['delivery']['country'] : $entry['customer']['country'];
8345
8346 foreach ( $cart as $rows ) {
8347
8348 if ( 'shipped' !== $this->getItemDivision( $rows['post_id'] ) ) {
8349 continue;
8350 }
8351
8352 if ( -1 == $fixed_charge_id ) {
8353 // 商品送料ID.
8354 $s_charge_id = $this->getItemShippingCharge( $rows['post_id'] );
8355 // 商品送料index.
8356 $s_charge_index = $this->get_shipping_charge_index( $s_charge_id );
8357 $s_charge = isset( $this->options['shipping_charge'][ $s_charge_index ][ $country ][ $pref ] ) ? (float) $this->options['shipping_charge'][ $s_charge_index ][ $country ][ $pref ] : 0;
8358 } else {
8359 $s_charge_index = $this->get_shipping_charge_index( $fixed_charge_id );
8360 $s_charge = isset( $this->options['shipping_charge'][ $s_charge_index ][ $country ][ $pref ] ) ? (float) $this->options['shipping_charge'][ $s_charge_index ][ $country ][ $pref ] : 0;
8361 }
8362
8363 if ( $this->getItemIndividualSCharge( $rows['post_id'] ) ) {
8364 $individual_quant += (float) $rows['quantity'];
8365 $individual_charges[] = (float) $rows['quantity'] * $s_charge;
8366 } else {
8367 $charges[] = $s_charge;
8368 }
8369 $total_quant += $rows['quantity'];
8370 }
8371
8372 if ( count( $charges ) > 0 ) {
8373 rsort( $charges );
8374 $max_charge = $charges[0];
8375 $charge = $max_charge + array_sum( array_filter( $individual_charges, 'is_numeric' ) );
8376 } else {
8377 $charge = array_sum( array_filter( $individual_charges, 'is_numeric' ) );
8378 }
8379
8380 $charge = apply_filters( 'usces_filter_getShippingCharge', $charge, $cart, $entry );
8381
8382 return $charge;
8383 }
8384
8385 public function getCODFee( $payment_name, $amount_by_cod, $current_entries ) {
8386 global $usces_entries;
8387
8388 $payments = $this->getPayments( $payment_name );
8389 if ( ! isset( $payments['settlement'] ) || 'COD' != $payments['settlement'] ) {
8390 $fee = 0;
8391
8392 } elseif ( 'change' != $this->options['cod_type'] ) {
8393 $fee = isset( $this->options['cod_fee'] ) ? $this->options['cod_fee'] : 0;
8394
8395 } else {
8396 $materials = array(
8397 'total_items_price' => $current_entries['order']['total_items_price'],
8398 'discount' => ( isset( $current_entries['order']['discount'] ) ) ? $current_entries['order']['discount'] : 0,
8399 'shipping_charge' => ( isset( $current_entries['order']['shipping_charge'] ) ) ? $current_entries['order']['shipping_charge'] : 0,
8400 'cod_fee' => 0,
8401 'use_point' => 0,
8402 );
8403 $price = $amount_by_cod + $this->getTax( $amount_by_cod, $materials );
8404 if ( $price <= $this->options['cod_first_amount'] ) {
8405 $fee = $this->options['cod_first_fee'];
8406
8407 } elseif ( isset( $this->options['cod_amounts'] ) ) {
8408 $last = count( $this->options['cod_amounts'] ) - 1;
8409 if ( $price > $this->options['cod_amounts'][ $last ] ) {
8410 $fee = $this->options['cod_end_fee'];
8411
8412 } else {
8413 $fee = 0;
8414 foreach ( $this->options['cod_amounts'] as $key => $value ) {
8415 if ( $price <= $value ) {
8416 $fee = $this->options['cod_fees'][ $key ];
8417 break;
8418 }
8419 }
8420 }
8421 } else {
8422 $fee = $this->options['cod_end_fee'];
8423 }
8424 }
8425 $fee = apply_filters( 'usces_filter_getCODFee', $fee, $payment_name, $amount_by_cod, $current_entries );
8426 return $fee;
8427 }
8428
8429 public function getTax( $total, $materials = array() ) {
8430 global $usces_settings;
8431
8432 if ( isset( $this->options['tax_display'] ) && 'deactivate' == $this->options['tax_display'] ) {
8433 return 0;
8434 }
8435 if ( empty( $this->options['tax_rate'] ) ) {
8436 return 0;
8437 }
8438 // if ( ! empty( $materials ) ) {
8439 // extract( $materials );//need( 'total_items_price', 'shipping_charge', 'discount', 'cod_fee', 'use_point' )
8440 // }
8441
8442 if ( $this->is_reduced_taxrate() ) {
8443 if ( 'include' == $this->options['tax_mode'] ) {
8444 return 0;
8445 }
8446 if ( ! empty( $materials ) ) {
8447 extract( $materials );
8448 if ( empty( $carts ) ) {
8449 $carts = array();
8450 $materials = compact( 'total_items_price', 'shipping_charge', 'discount', 'cod_fee', 'use_point', 'carts' );
8451 }
8452 }
8453
8454 $usces_tax = Welcart_Tax::get_instance();
8455 $usces_tax->get_order_tax( $materials );
8456 $tax = apply_filters( 'usces_filter_getTax', $usces_tax->tax, $materials );
8457
8458 } else {
8459
8460 if ( empty( $materials ) ) {
8461
8462 if ( 'include' == $this->options['tax_mode'] ) {
8463 $tax = (float) sprintf( '%.3f', (float) $total * (float) $this->options['tax_rate'] / ( 100 + (float) $this->options['tax_rate'] ) );
8464 } else {
8465 $tax = (float) sprintf( '%.3f', (float) $total * (float) $this->options['tax_rate'] / 100 );
8466 }
8467
8468 } else {
8469 if ( 'include' == $this->options['tax_mode'] ) {
8470 return 0;
8471 }
8472
8473 extract( $materials ); // need( 'total_items_price', 'shipping_charge', 'discount', 'cod_fee', 'use_point' ).
8474
8475 if ( 1 == $this->options['point_coverage'] ) {
8476 if ( 'products' == $this->options['tax_target'] ) {
8477 $total = (float) $total_items_price + (float) $discount;
8478 } else {
8479 $total = (float) $total_items_price + (float) $discount + (float) $shipping_charge + (float) $cod_fee;
8480 }
8481 } else {
8482 if ( 'products' == $this->options['tax_target'] ) {
8483 $total = (float) $total_items_price + (float) $discount;
8484 } else {
8485 if ( empty( $use_point ) ) {
8486 $use_point = 0;
8487 }
8488 $total = (float) $total_items_price + (float) $discount - (int) $use_point + (float) $shipping_charge + (float) $cod_fee;
8489 }
8490 }
8491 $total = apply_filters( 'usces_filter_getTax_total', $total, $materials );
8492
8493 $tax = (float) sprintf( '%.3f', (float) $total * (float) $this->options['tax_rate'] / 100 );
8494 }
8495
8496 $tax = usces_tax_rounding_off( $tax );
8497 $tax = apply_filters( 'usces_filter_getTax', $tax, $materials );
8498 }
8499
8500 return $tax;
8501 }
8502
8503 public function set_cart_fees( $member, $entries ) {
8504 global $usces_entries;
8505
8506 $carts = $this->cart->get_cart();
8507 $entries = $this->cart->get_entry();
8508 $total_items_price = $this->get_total_price();
8509 $entries['order']['total_items_price'] = $total_items_price;
8510
8511 if ( empty( $this->options['postage_privilege'] ) || $total_items_price < $this->options['postage_privilege'] ) {
8512 $shipping_charge = $this->getShippingCharge( $entries['delivery']['pref'], $carts, $entries );
8513 } else {
8514 $shipping_charge = 0;
8515 }
8516 $shipping_charge = apply_filters( 'usces_filter_set_cart_fees_shipping_charge', $shipping_charge, $carts, $entries );
8517 $entries['order']['shipping_charge'] = $shipping_charge;
8518
8519 $payments = $this->getPayments( $entries['order']['payment_name'] );
8520 $use_point = ( isset( $entries['order']['usedpoint'] ) ) ? (int) $entries['order']['usedpoint'] : 0;
8521 if ( $this->is_reduced_taxrate() ) {
8522 $usces_tax = Welcart_Tax::get_instance();
8523 $discount = $usces_tax->get_order_discount( $carts );
8524 $entries['order']['discount'] = $discount;
8525 $amount_by_cod = $total_items_price - $use_point + $discount;
8526 if ( 'all' == usces_is_fee_subject() ) {
8527 $amount_by_cod += $shipping_charge;
8528 }
8529 $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 );
8530 $cod_fee = $this->getCODFee( $entries['order']['payment_name'], $amount_by_cod, $entries );
8531 $cod_fee = apply_filters( 'usces_filter_set_cart_fees_cod', $cod_fee, $entries, $total_items_price, $use_point, $discount, $shipping_charge, $amount_by_cod );
8532 $entries['order']['cod_fee'] = $cod_fee;
8533
8534 if ( 'include' == $this->options['tax_mode'] ) {
8535 $tax = 0;
8536 } else {
8537 $materials = compact( 'member', 'entries', 'carts', 'total_items_price', 'shipping_charge', 'payments', 'discount', 'cod_fee', 'use_point' );
8538 $usces_tax->get_order_tax( $materials );
8539 $tax = apply_filters( 'usces_filter_getTax', $usces_tax->tax, $materials );
8540 }
8541
8542 $total_price = $total_items_price - $use_point + $discount + $shipping_charge + $cod_fee;
8543 if ( $total_price < 0 ) {
8544 $total_price = 0;
8545 }
8546 $total_price = apply_filters( 'usces_filter_set_cart_fees_total_price', $total_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee );
8547
8548 } else {
8549 $discount = $this->get_order_discount( null, $carts );
8550 $entries['order']['discount'] = $discount;
8551 $amount_by_cod = $total_items_price - $use_point + $discount;
8552 if ( 'all' == usces_is_fee_subject() ) {
8553 $amount_by_cod += $shipping_charge;
8554 }
8555 $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 );
8556 $cod_fee = $this->getCODFee( $entries['order']['payment_name'], $amount_by_cod, $entries );
8557 $cod_fee = apply_filters( 'usces_filter_set_cart_fees_cod', $cod_fee, $entries, $total_items_price, $use_point, $discount, $shipping_charge, $amount_by_cod );
8558 $entries['order']['cod_fee'] = $cod_fee;
8559
8560 $total_price = $total_items_price - $use_point + $discount + $shipping_charge + $cod_fee;
8561 if ( $total_price < 0 ) {
8562 $total_price = 0;
8563 }
8564 $total_price = apply_filters( 'usces_filter_set_cart_fees_total_price', $total_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee );
8565
8566 $materials = compact( 'member', 'entries', 'carts', 'total_items_price', 'shipping_charge', 'payments', 'discount', 'cod_fee', 'use_point' );
8567 $tax = $this->getTax( $total_price, $materials );
8568 }
8569 $entries['order']['total_price'] = $total_price;
8570 $entries['order']['tax'] = $tax;
8571
8572 if ( 'exclude' == $this->options['tax_mode'] ) {
8573 if ( 0 < $use_point ) {
8574 $total_full_price = $total_items_price - $use_point + $discount + $shipping_charge + $cod_fee + $tax;
8575 if ( $total_full_price < 0 ) {
8576 $total_full_price = 0;
8577 }
8578 } else {
8579 $total_full_price = $total_price + $tax;
8580 }
8581 } else {
8582 $total_full_price = $total_price;
8583 }
8584
8585 $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 );
8586 $entries['order']['total_full_price'] = $total_full_price;
8587
8588 $mem_id = isset( $member['ID'] ) ? $member['ID'] : null;
8589 $get_point = $this->get_order_point( $mem_id );
8590 $get_point = apply_filters( 'usces_filter_set_get_point', $get_point, $entries, $carts );
8591
8592 $array = array(
8593 'total_items_price' => $total_items_price,
8594 'total_price' => $total_price,
8595 'total_full_price' => $total_full_price,
8596 'getpoint' => $get_point,
8597 'usedpoint' => $use_point,
8598 'discount' => $discount,
8599 'shipping_charge' => $shipping_charge,
8600 'cod_fee' => $cod_fee,
8601 'tax' => $tax,
8602 );
8603 $this->cart->set_order_entry( $array );
8604 $usces_entries = $this->cart->get_entry();
8605 }
8606
8607 public function getPayments( $payment_name ) {
8608 $init = array(
8609 'id' => null,
8610 'name' => null,
8611 'explanation' => null,
8612 'settlement' => null,
8613 'module' => null,
8614 'sort' => null,
8615 'use' => null,
8616 );
8617
8618 if ( '#none#' == $payment_name ) {
8619 return $init;
8620 }
8621 $payments = usces_get_system_option( 'usces_payment_method', 'name' );
8622 if ( isset( $payments[ $payment_name ] ) ) {
8623 return $payments[ $payment_name ];
8624 }
8625 return $init;
8626 }
8627
8628 public function is_maintenance() {
8629 if ( 'Maintenancemode' == $this->options['display_mode'] ) {
8630 return true;
8631 } else {
8632 return false;
8633 }
8634 }
8635
8636 public function get_member_history( $mem_id, $allow_filter = false ) {
8637 global $wpdb;
8638 $order_table = $wpdb->prefix . 'usces_order';
8639
8640 if ( is_user_logged_in() && is_admin() ) {
8641
8642 $query = $wpdb->prepare( "SELECT * FROM $order_table WHERE mem_id = %d ORDER BY order_date DESC", $mem_id );
8643 $query = apply_filters( 'usces_filter_member_history_query', $query, $mem_id, $allow_filter );
8644 $results = $wpdb->get_results( $query );
8645
8646 } elseif ( ! is_admin() ) {
8647
8648 $cancel_query = '%cancel%';
8649 $estimate_query = '%estimate%';
8650 $exclude_cancel = $this->usces_get_member_cookies( 'ord_ex_cancel' );
8651 if ( $allow_filter && 'on' === (string) $exclude_cancel ) {
8652 $condition = ' ( order_status NOT LIKE %s AND order_status NOT LIKE %s ) ';
8653 } else {
8654 $condition = ' ( order_status LIKE %s OR order_status NOT LIKE %s ) ';
8655 }
8656
8657 $pur_date = $this->usces_get_member_cookies( 'pur-date' );
8658 if ( $allow_filter && $pur_date ) {
8659 $now = current_time( 'timestamp' );
8660 $type_filter = 'date';
8661 if ( false !== strpos( $pur_date, 'y_' ) ) {
8662 $type_filter = 'year';
8663 } elseif ( false !== strpos( $pur_date, 'm_' ) ) {
8664 $type_filter = 'month';
8665 }
8666 if ( 'year' === $type_filter ) {
8667 $purchase_year = (int) str_replace( 'y_', '', $pur_date );
8668 } elseif ( 'month' === $type_filter ) {
8669 $month_ago = (int) str_replace( 'm_', '', $pur_date );
8670 $first_day_of_previous_months = strtotime( "first day of -{$month_ago} months", $now );
8671 $last_day_of_previous_months = strtotime( "last day of -{$month_ago} months", $now );
8672 $purchase_date_from_string = date( 'Y-m-d 00:00:00', $first_day_of_previous_months );
8673 $purchase_date_to_string = date( 'Y-m-d 23:59:59', $last_day_of_previous_months );
8674 } else {
8675 $pur_date_val = (int) str_replace( 'd_', '', $pur_date );
8676 $previous_date = strtotime( "-{$pur_date_val} days", $now );
8677 $purchase_date_string = date( 'Y-m-d 00:00:00', $previous_date );
8678 }
8679 if ( 'year' === $type_filter ) {
8680 $query = $wpdb->prepare(
8681 "SELECT * FROM $order_table WHERE mem_id = %d AND YEAR(order_date) = %d AND {$condition} ORDER BY order_date DESC",
8682 $mem_id,
8683 $purchase_year,
8684 $cancel_query,
8685 $estimate_query
8686 );
8687 } elseif ( 'month' === $type_filter ) {
8688 $query = $wpdb->prepare(
8689 "SELECT * FROM $order_table WHERE mem_id = %d AND order_date >= %s AND order_date <= %s AND {$condition} ORDER BY order_date DESC",
8690 $mem_id,
8691 $purchase_date_from_string,
8692 $purchase_date_to_string,
8693 $cancel_query,
8694 $estimate_query
8695 );
8696 } else {
8697 $query = $wpdb->prepare(
8698 "SELECT * FROM $order_table WHERE mem_id = %d AND order_date >= %s AND {$condition} ORDER BY order_date DESC",
8699 $mem_id,
8700 $purchase_date_string,
8701 $cancel_query,
8702 $estimate_query
8703 );
8704 }
8705 } else {
8706 $query = $wpdb->prepare(
8707 "SELECT * FROM $order_table WHERE mem_id = %d AND {$condition} ORDER BY order_date DESC",
8708 $mem_id,
8709 $cancel_query,
8710 $estimate_query
8711 );
8712 }
8713
8714 $query = apply_filters( 'usces_filter_member_history_query_front', $query, $mem_id, $allow_filter );
8715 $results = $wpdb->get_results( $query );
8716 }
8717
8718 $i = 0;
8719 $res = array();
8720
8721 foreach ( $results as $value ) {
8722 $cart = usces_get_ordercartdata( $value->ID );
8723 $total_items_price = $this->get_total_price( $cart );
8724
8725 $data = array(
8726 'ID' => $value->ID,
8727 'cart' => $cart,
8728 'condition' => wel_safe_unserialize( $value->order_condition ),
8729 'getpoint' => $value->order_getpoint,
8730 'usedpoint' => $value->order_usedpoint,
8731 'discount' => $value->order_discount,
8732 'shipping_charge' => $value->order_shipping_charge,
8733 'payment_name' => $value->order_payment_name,
8734 'cod_fee' => $value->order_cod_fee,
8735 'tax' => $value->order_tax,
8736 'total_items_price' => $total_items_price,
8737 'order_status' => $value->order_status,
8738 'date' => mysql2date( __( 'Y/m/d' ), $value->order_date ),
8739 'order_date' => $value->order_date,
8740 'order_delidue_date' => $value->order_delidue_date,
8741 'order_delivery_method' => $value->order_delivery_method,
8742 'order_delivery_method_name' => usces_delivery_method_name( $value->order_delivery_method, 'return' ),
8743 'order_delivery_date' => $value->order_delivery_date,
8744 'order_modified' => $value->order_modified,
8745 );
8746 $res[] = apply_filters( 'usces_filter_member_history_data', $data, $mem_id, $value, $cart, $total_items_price );
8747 }
8748
8749 return $res;
8750 }
8751
8752 public function get_post_term_ids( $post_id, $taxonomy ) {
8753 global $wpdb;
8754 $query = $wpdb->prepare(
8755 "SELECT tt.term_id FROM $wpdb->term_relationships AS `tr`
8756 INNER JOIN $wpdb->term_taxonomy AS `tt` ON tt.term_taxonomy_id = tr.term_taxonomy_id
8757 WHERE tt.taxonomy = %s AND tr.object_id = %d",
8758 $taxonomy, $post_id
8759 );
8760 $ids = $wpdb->get_col( $query );
8761
8762 return $ids;
8763 }
8764
8765 public function get_tag_names( $post_id ) {
8766 global $wpdb;
8767 $tag = 'post_tag';
8768 $query = $wpdb->prepare(
8769 "SELECT t.name FROM $wpdb->term_relationships AS `tr`
8770 INNER JOIN $wpdb->term_taxonomy AS `tt` ON tt.term_taxonomy_id = tr.term_taxonomy_id
8771 INNER JOIN $wpdb->terms AS `t` ON t.term_id = tt.term_id
8772 WHERE tt.taxonomy = %s AND tr.object_id = %d",
8773 $tag, $post_id
8774 );
8775 $names = $wpdb->get_col( $query );
8776
8777 return apply_filters( 'usces_filter_get_tag_names', $names, $post_id );
8778 }
8779
8780 public function get_ID_byItemName( $item_code, $status = 'publish' ) {
8781 global $wpdb;
8782
8783 $table = usces_get_tablename( 'usces_item' );
8784 $id = $wpdb->get_var(
8785 $wpdb->prepare(
8786 "SELECT p.ID FROM {$wpdb->posts} AS `p`
8787 INNER JOIN {$table} AS `item` ON p.ID = item.post_id
8788 WHERE p.post_status = %s AND item.itemCode = %s",
8789 $status,
8790 $item_code
8791 )
8792 );
8793
8794 return $id;
8795 }
8796
8797 /**
8798 * @deprecated A1/C (Layer 3 / uscesid removal). uscesid 難読化生成。本体は不使用。未移行の拡張・
8799 * クライアント後方互換のためのみ残置。全消費側移行後に get_uscesid()/uscesdc() ともども削除する。
8800 */
8801 public function uscescv( $sessid, $flag ) {
8802 $chars = '';
8803 $i = 0;
8804 $h = 0;
8805 $usces_cookie = $this->get_cookie();
8806 if ( isset( $usces_cookie['id'] ) && ! empty( $usces_cookie['id'] ) ) {
8807 $cid = $usces_cookie['id'];
8808 } elseif ( isset( $_SESSION['usces_cookieid'] ) && ! empty( $_SESSION['usces_cookieid'] ) ) {
8809 $cid = $_SESSION['usces_cookieid'];
8810 } else {
8811 $cid = 0;
8812 }
8813 while ( $h < strlen( $sessid ) ) {
8814 if ( 0 == $i % 3 ) {
8815 $chars .= substr( $i, -1 );
8816 } else {
8817 $chars .= substr( $sessid, $h, 1 );
8818 $h++;
8819 }
8820 $i++;
8821 }
8822 if ( $flag ) {
8823 $postfix = ( isset( $_SERVER['REMOTE_ADDR'] ) && ! empty( $_SERVER['REMOTE_ADDR'] ) ) ? $_SERVER['REMOTE_ADDR'] : 'REMOTE_ADDR';
8824 $postfix = apply_filters( 'usces_sessid_force', $postfix );
8825 $sessid = $chars . '_' . $postfix . '_' . $cid . '_A';
8826 } else {
8827 $sessid = $chars . '_' . apply_filters( 'usces_sessid_flag', 'acting' ) . '_' . $cid . '_A';
8828 }
8829 $sessid = urlencode( base64_encode( $sessid ) );
8830
8831 return $sessid;
8832 }
8833
8834 /**
8835 * @deprecated A1/C (Layer 3 / uscesid removal). uscesid 復号。本体は不使用(A1 で唯一の呼び出しを撤去)。
8836 * 未移行の拡張・クライアント(直接 uscesdc()→session_id() する nopriv AJAX)後方互換のためのみ残置。
8837 * 全消費側移行後に get_uscesid()/uscescv() ともども削除する。
8838 */
8839 public function uscesdc( $sessid ) {
8840 $sessid = base64_decode( urldecode( $sessid ) );
8841 list( $sess, $addr, $cookieid, $none ) = explode( '_', $sessid, 4 );
8842 $postfix = ( isset( $_SERVER['REMOTE_ADDR'] ) && ! empty( $_SERVER['REMOTE_ADDR'] ) ) ? $_SERVER['REMOTE_ADDR'] : 'REMOTE_ADDR';
8843 $postfix = apply_filters( 'usces_sessid_force', $postfix );
8844 if ( 'acting' !== $addr && 'mobile' !== $addr && $postfix !== $addr ) {
8845 $sessid = '';
8846 return null;
8847 }
8848 $chars = '';
8849 $h = 0;
8850 while ( $h < strlen( $sess ) ) {
8851 if ( 0 != $h % 3 ) {
8852 $chars .= substr( $sess, $h, 1 );
8853 }
8854 $h++;
8855 }
8856 $sessid = $chars;
8857
8858 return $sessid;
8859 }
8860
8861 public function get_visiter( $period ) {
8862 global $wpdb;
8863 $datestr = substr( get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ), 0, 10 );
8864 $yearstr = substr( $datestr, 0, 4 );
8865 $monthstr = substr( $datestr, 5, 2 );
8866 $daystr = substr( $datestr, 8, 2 );
8867 if ( 'today' == $period ) {
8868 $date = $datestr;
8869 $today = $datestr;
8870 } elseif ( 'thismonth' == $period ) {
8871 $date = date( 'Y-m-01' );
8872 $today = $datestr;
8873 } elseif ( 'lastyear' == $period ) {
8874 $date = date( 'Y-m-01', mktime( 0, 0, 0, (int) $monthstr, 1, (int) $yearstr-1 ) );
8875 $today = date( 'Y-m-01', mktime( 0, 0, 0, (int) $monthstr, (int) $daystr, (int) $yearstr-1 ) );
8876 }
8877 $table_name = $wpdb->prefix . 'usces_access';
8878
8879 $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 );
8880 $res = $wpdb->get_row( $query, ARRAY_A );
8881
8882 if ( null == $res ) {
8883 return 0;
8884 } else {
8885 return $res['ct1'] + $res['ct2'];
8886 }
8887 }
8888
8889 public function get_fvisiter( $period ) {
8890 global $wpdb;
8891 $datestr = substr( get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ), 0, 10 );
8892 $yearstr = substr( $datestr, 0, 4 );
8893 $monthstr = substr( $datestr, 5, 2 );
8894 $daystr = substr( $datestr, 8, 2 );
8895 if ( 'today' == $period ) {
8896 $date = $datestr;
8897 $today = $datestr;
8898 } elseif ( 'thismonth' == $period ) {
8899 $date = date( 'Y-m-01' );
8900 $today = $datestr;
8901 } elseif ( 'lastyear' == $period ) {
8902 $date = date( 'Y-m-01', mktime( 0, 0, 0, (int) $monthstr, 1, (int) $yearstr - 1 ) );
8903 $today = date( 'Y-m-01', mktime( 0, 0, 0, (int) $monthstr, (int) $daystr, (int) $yearstr - 1 ) );
8904 }
8905 $table_name = $wpdb->prefix . 'usces_access';
8906
8907 $query = $wpdb->prepare( "SELECT SUM(acc_num2) AS `ct` FROM $table_name WHERE acc_date >= %s AND acc_date <= %s", $date, $today );
8908 $res = $wpdb->get_var( $query );
8909
8910 if ( null == $res ) {
8911 return 0;
8912 } else {
8913 return $res;
8914 }
8915 }
8916
8917 public function get_order_num( $period ) {
8918 global $wpdb;
8919 $datestr = substr( get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ), 0, 10 );
8920 $yearstr = substr( $datestr, 0, 4 );
8921 $monthstr = substr( $datestr, 5, 2 );
8922 $daystr = substr( $datestr, 8, 2 );
8923 if ( 'today' == $period ) {
8924 $date = date( 'Y-m-d 00:00:00', current_time( 'timestamp' ) );
8925 $today = date( 'Y-m-d 23:59:59', current_time( 'timestamp' ) );
8926 } elseif ( 'thismonth' == $period ) {
8927 $date = date( 'Y-m-01 00:00:00', current_time( 'timestamp' ) );
8928 $today = date( 'Y-m-d 23:59:59', current_time( 'timestamp' ) );
8929 } elseif ( 'lastyear' == $period ) {
8930 $date = date( 'Y-m-01 00:00:00', mktime( 0, 0, 0, (int) $monthstr, 1, (int) $yearstr - 1 ) );
8931 $today = date( 'Y-m-d 23:59:59', mktime( 0, 0, 0, (int) $monthstr + 1, 0, (int) $yearstr - 1 ) );
8932 }
8933 $table_name = $wpdb->prefix . 'usces_order';
8934
8935 $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' );
8936 $res = $wpdb->get_var( $query );
8937
8938 if ( null == $res ) {
8939 return 0;
8940 } else {
8941 return $res;
8942 }
8943 }
8944
8945 public function get_order_amount( $period ) {
8946 global $wpdb;
8947
8948 $cache_key = 'wel_order_amount_period_' . $period;
8949
8950 $res = wp_cache_get( $cache_key );
8951 if ( false === $res ) {
8952
8953 $datestr = substr( get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ), 0, 10 );
8954 $yearstr = substr( $datestr, 0, 4 );
8955 $monthstr = substr( $datestr, 5, 2 );
8956 $daystr = substr( $datestr, 8, 2 );
8957 if ( 'today' == $period ) {
8958 $date = date( 'Y-m-d 00:00:00', current_time( 'timestamp' ) );
8959 $today = date( 'Y-m-d 23:59:59', current_time( 'timestamp' ) );
8960 } elseif ( 'thismonth' == $period ) {
8961 $date = date( 'Y-m-01 00:00:00', current_time( 'timestamp' ) );
8962 $today = date( 'Y-m-d 23:59:59', current_time( 'timestamp' ) );
8963 } elseif ( 'lastyear' == $period ) {
8964 $date = date( 'Y-m-01 00:00:00', mktime( 0, 0, 0, (int) $monthstr, 1, (int) $yearstr - 1 ) );
8965 $today = date( 'Y-m-d 23:59:59', mktime( 0, 0, 0, (int) $monthstr + 1, 0, (int) $yearstr - 1 ) );
8966 }
8967 $table_name = $wpdb->prefix . 'usces_order';
8968
8969 $query = $wpdb->prepare(
8970 "SELECT
8971 SUM(order_item_total_price) AS `price`,
8972 SUM(order_usedpoint) AS `point`,
8973 SUM(order_discount) AS `discount`,
8974 SUM(order_shipping_charge) AS `shipping`,
8975 SUM(order_cod_fee) AS `cod`,
8976 SUM(order_tax) AS `tax`
8977 FROM $table_name WHERE order_date >= %s AND order_date <= %s AND 0 = LOCATE(%s, order_status) AND 0 = LOCATE(%s, order_status)",
8978 $date, $today, 'cancel', 'estimate'
8979 );
8980 $res = $wpdb->get_row( $query, ARRAY_A );
8981
8982 if ( null !== $res ) {
8983 wp_cache_set( $cache_key, $res );
8984 }
8985 }
8986
8987 if ( null == $res ) {
8988 return 0;
8989 } else {
8990 return $res['price'] - $res['point'] + $res['discount'] + $res['shipping'] + $res['cod'] + $res['tax'];
8991 }
8992 }
8993
8994 public function is_status( $need, $str ) {
8995 if ( ! is_string( $str ) || empty( $str ) ) {
8996 $array = array();
8997 } else {
8998 $array = explode( ',', $str );
8999 }
9000 return in_array( $need, $array );
9001 }
9002
9003 public function make_status( $taio = '', $receipt = '', $admin = '' ) {
9004 $str = '';
9005 if ( '' != $taio && '#none#' != $taio ) {
9006 $str .= $taio . ',';
9007 }
9008 if ( '' != $receipt && '#none#' != $receipt ) {
9009 $str .= $receipt . ',';
9010 }
9011 if ( '' != $admin && '#none#' != $admin ) {
9012 $str .= $admin . ',';
9013 }
9014 return $str;
9015 }
9016
9017 public function get_memberid_by_email( $email ) {
9018 global $wpdb;
9019 $table_name = usces_get_tablename( 'usces_member' );
9020 $query = $wpdb->prepare( "SELECT ID FROM $table_name WHERE mem_email = %s", $email );
9021 $res = $wpdb->get_var( $query );
9022 return $res;
9023 }
9024
9025 public function get_condition() {
9026 $order_conditions = array(
9027 'display_mode' => $this->options['display_mode'],
9028 'campaign_privilege' => $this->options['campaign_privilege'],
9029 'campaign_category' => $this->options['campaign_category'],
9030 'privilege_point' => $this->options['privilege_point'],
9031 'privilege_discount' => $this->options['privilege_discount'],
9032 'tax_display' => ( isset( $this->options['tax_display'] ) ) ? $this->options['tax_display'] : 'activate',
9033 'tax_mode' => $this->options['tax_mode'],
9034 'tax_target' => $this->options['tax_target'],
9035 'tax_rate' => $this->options['tax_rate'],
9036 'tax_method' => $this->options['tax_method'],
9037 'applicable_taxrate' => ( isset( $this->options['applicable_taxrate'] ) ) ? $this->options['applicable_taxrate'] : 'standard',
9038 'tax_rate_reduced' => ( isset( $this->options['tax_rate_reduced'] ) ) ? $this->options['tax_rate_reduced'] : $this->options['tax_rate'],
9039 'membersystem_state' => $this->options['membersystem_state'],
9040 'membersystem_point' => $this->options['membersystem_point'],
9041 'point_coverage' => $this->options['point_coverage'],
9042 );
9043 return $order_conditions;
9044 }
9045
9046 public function get_bestseller_ids( $days = '' ) {
9047 global $wpdb;
9048
9049 $datestr = substr( get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) ), 0, 10 );
9050 $yearstr = substr( $datestr, 0, 4 );
9051 $monthstr = substr( $datestr, 5, 2 );
9052 $daystr = substr( $datestr, 8, 2 );
9053
9054 $res = array();
9055 $order_table_name = $wpdb->prefix . 'usces_order';
9056 $where = '';
9057 if ( empty( $days ) ) {
9058 $days = 30;
9059 }
9060 $order_date = date( 'Y-m-d H:i:s', mktime( 0, 0, 0, (int) $monthstr, ( (int) $daystr - $days), (int) $yearstr ) );
9061 $where = " WHERE order_date >= '{$order_date}'";
9062 $query = "SELECT order_cart FROM {$order_table_name}" . $where;
9063 $dbres = $wpdb->get_col( $query );
9064 if ( ! $dbres ) {
9065 return false;
9066 }
9067
9068 foreach ( (array) $dbres as $carts ) {
9069 $rows = wel_safe_unserialize( $carts );
9070 foreach ( (array) $rows as $carts ) {
9071 if ( 'publish' != get_post_status( $carts['post_id'] ) ) {
9072 continue;
9073 }
9074 $id = $carts['post_id'];
9075 $qu = $carts['quantity'];
9076 if ( array_key_exists( $id, $res ) ) {
9077 $res[ $id ] = $res[ $id ] + $qu;
9078 } else {
9079 $res[ $id ] = $qu;
9080 }
9081 }
9082 }
9083 arsort( $res );
9084 $results = array_keys( $res );
9085 return $results;
9086 }
9087
9088 public function get_items_num() {
9089 global $wpdb;
9090 $res = $wpdb->get_var(
9091 $wpdb->prepare(
9092 "SELECT COUNT(ID) AS `ct` FROM {$wpdb->posts}
9093 WHERE post_mime_type = %s AND post_type = %s AND post_status <> %s",
9094 'item',
9095 'post',
9096 'trash'
9097 )
9098 );
9099
9100 return $res;
9101 }
9102
9103 public function is_gptekiyo( $post_id, $sku, $quant ) {
9104 $skus = $this->get_skus( $post_id, 'code' );
9105 if ( ! isset( $skus[ $sku ]['gp'] ) || ! $skus[ $sku ]['gp'] ) {
9106 return false;
9107 }
9108
9109 $GpN1 = $this->getItemGpNum1( $post_id );
9110 $GpN2 = $this->getItemGpNum2( $post_id );
9111 $GpN3 = $this->getItemGpNum3( $post_id );
9112
9113 if ( empty( $GpN1 ) ) {
9114
9115 return false;
9116
9117 } elseif ( ! empty( $GpN1 ) && empty( $GpN2 ) ) {
9118
9119 if ( $quant >= $GpN1 ) {
9120 return true;
9121 } else {
9122 return false;
9123 }
9124
9125 } elseif ( ! empty( $GpN1 ) && ! empty( $GpN2 ) && empty( $GpN3 ) ) {
9126
9127 if ( $quant >= $GpN2 ) {
9128 return true;
9129 } elseif ( $quant >= $GpN1 && $quant < $GpN2 ) {
9130 return true;
9131 } else {
9132 return false;
9133 }
9134
9135 } elseif ( ! empty( $GpN1 ) && ! empty( $GpN2 ) && ! empty( $GpN3 ) ) {
9136
9137 if ( $quant >= $GpN3 ) {
9138 return true;
9139 } elseif ( $quant >= $GpN2 && $quant < $GpN3 ) {
9140 return true;
9141 } elseif ( $quant >= $GpN1 && $quant < $GpN2 ) {
9142 return true;
9143 } else{
9144 return false;
9145 }
9146 }
9147 }
9148
9149 public function get_available_delivery_method() {
9150 if ( $this->cart->num_row() > 0 ) {
9151 $cart = $this->cart->get_cart();
9152 $before_deli = array();
9153 $intersect = array();
9154 $integration = array();
9155 $temp = array();
9156 $in = 0;
9157 foreach ( $cart as $key => $row ) {
9158 $deli = $this->getItemDeliveryMethod( $row['post_id'] );
9159 if ( empty( $deli ) ) {
9160 continue;
9161 }
9162 if ( 0 === $in ) {
9163 $intersect = $deli;
9164 }
9165 $intersect = array_intersect( $deli, $intersect );
9166 $before_deli = $deli;
9167 foreach ( $deli as $value ) {
9168 $integration[] = $value;
9169 }
9170 $in++;
9171 }
9172 $integration = array_unique( $integration );
9173 foreach ( $integration as $id ) {
9174 $index = $this->get_delivery_method_index( $id );
9175 if ( 0 <= $index ) {
9176 $temp[ $index ] = $id;
9177 }
9178 }
9179 ksort( $temp );
9180 $force = array( array_shift( $temp ) );
9181
9182 if ( empty( $intersect ) ) {
9183 return $force;
9184 } else {
9185 return $intersect;
9186 }
9187 }
9188 return array();
9189 }
9190
9191 public function get_delivery_method_index( $id ) {
9192 $index = false;
9193 $delivery_method_count = ( $this->options['delivery_method'] && is_array( $this->options['delivery_method'] ) ) ? count( $this->options['delivery_method'] ) : 0;
9194 for ( $i = 0; $i < $delivery_method_count; $i++ ) {
9195 if ( isset( $this->options['delivery_method'][ $i ]['id'] ) && $this->options['delivery_method'][ $i ]['id'] === (int) $id ) {
9196 $index = $i;
9197 }
9198 }
9199 if ( false === $index ) {
9200 return -1;
9201 } else {
9202 return $index;
9203 }
9204 }
9205
9206 public function get_shipping_charge_index( $id ) {
9207 $index = false;
9208 $shipping_charge_count = ( $this->options['shipping_charge'] && is_array( $this->options['shipping_charge'] ) ) ? count( $this->options['shipping_charge'] ) : 0;
9209 for ( $i = 0; $i < $shipping_charge_count; $i++ ) {
9210 if ( isset( $this->options['shipping_charge'][ $i ] ) && (int) $this->options['shipping_charge'][ $i ]['id'] == (int) $id ) {
9211 $index = $i;
9212 }
9213 }
9214 if ( false === $index ) {
9215 return -1;
9216 } else {
9217 return $index;
9218 }
9219 }
9220
9221 public function get_initial_data( $xml ) {
9222 $buf = file_get_contents( $xml );
9223 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 );
9224 return $match;
9225 }
9226
9227 public function getCurrencySymbol() {
9228 global $usces_settings;
9229 $cr = $this->options['system']['currency'];
9230 list( $code, $decimal, $point, $seperator, $symbol ) = $usces_settings['currency'][ $cr ];
9231 return $symbol;
9232 }
9233
9234 public function getCartItemName( $post_id, $sku ) {
9235 $name_arr = array();
9236 $name_str = '';
9237
9238 foreach ( $this->options['indi_item_name'] as $key => $value ) {
9239 if ( $value ) {
9240 $pos = (int) $this->options['pos_item_name'][ $key ];
9241 $ind = ( 0 === $pos ) ? 'A' : $pos;
9242 switch ( $key ) {
9243 case 'item_name':
9244 $name_arr[ $ind ][ $key ] = $this->getItemName( $post_id );
9245 break;
9246 case 'item_code':
9247 $name_arr[ $ind ][ $key ] = $this->getItemCode( $post_id );
9248 break;
9249 case 'sku_name':
9250 $name_arr[ $ind ][ $key ] = $this->getItemSkuDisp( $post_id, $sku );
9251 break;
9252 case 'sku_code':
9253 $name_arr[ $ind ][ $key ] = $sku;
9254 break;
9255 }
9256 }
9257 }
9258 ksort( $name_arr );
9259 foreach ( $name_arr as $vals ) {
9260 foreach ( $vals as $key => $value ) {
9261 $name_str .= $value . ' ';
9262 }
9263 }
9264
9265 $name_str = apply_filters( 'usces_admin_order_item_name_filter', $name_str, $post_id, $sku );
9266
9267 return trim( $name_str );
9268 }
9269
9270 public function getCartItemName_byOrder( $cart_row ) {
9271 $name_arr = array();
9272 $name_str = '';
9273
9274 foreach ( $this->options['indi_item_name'] as $key => $value ) {
9275 if ( $value ) {
9276 $pos = (int) $this->options['pos_item_name'][ $key ];
9277 $ind = ( 0 === $pos ) ? 'A' : $pos;
9278 switch ( $key ) {
9279 case 'item_name':
9280 $name_arr[ $ind ][ $key ] = $cart_row['item_name'];
9281 break;
9282 case 'item_code':
9283 $name_arr[ $ind ][ $key ] = $cart_row['item_code'];
9284 break;
9285 case 'sku_name':
9286 $name_arr[ $ind ][ $key ] = $cart_row['sku_name'];
9287 break;
9288 case 'sku_code':
9289 $name_arr[ $ind ][ $key ] = $cart_row['sku_code'];
9290 break;
9291 }
9292 }
9293 }
9294 ksort( $name_arr );
9295 foreach ( $name_arr as $vals ) {
9296 foreach ( $vals as $key => $value ) {
9297 $name_str .= $value . ' ';
9298 }
9299 }
9300
9301 $name_str = apply_filters( 'usces_filter_item_mame_by_order', $name_str, $cart_row );
9302
9303 return trim( $name_str );
9304 }
9305
9306 public function set_reserve_pre_order_id() {
9307 $entry = $this->cart->get_entry();
9308 $id = ( isset( $entry['reserve']['pre_order_id'] ) && ! empty( $entry['reserve']['pre_order_id'] ) ) ? $entry['reserve']['pre_order_id'] : uniqid( '' );
9309 $this->cart->set_pre_order_id( $id );
9310 }
9311
9312 public function get_current_pre_order_id() {
9313 $entry = $this->cart->get_entry();
9314 $id = ( isset( $entry['reserve']['pre_order_id'] ) && ! empty( $entry['reserve']['pre_order_id'] ) ) ? $entry['reserve']['pre_order_id'] : null;
9315 return $id;
9316 }
9317
9318 public function get_order_id_by_pre_order_id( $pre_order_id ) {
9319 global $wpdb;
9320 $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 );
9321 $order_id = $wpdb->get_var( $query );
9322 return $order_id;
9323 }
9324
9325 public function get_reserve( $order_id, $key ) {
9326 global $wpdb;
9327 $order_meta_table_name = $wpdb->prefix . 'usces_order_meta';
9328 $query = $wpdb->prepare( "SELECT meta_value FROM $order_meta_table_name WHERE order_id = %d AND meta_key = %s", $order_id, $key );
9329 $res = $wpdb->get_var( $query );
9330 return $res;
9331 }
9332
9333 public function get_order_meta_value( $key, $order_id ) {
9334 global $wpdb;
9335 $order_meta_table_name = $wpdb->prefix . 'usces_order_meta';
9336 $query = $wpdb->prepare( "SELECT meta_value FROM $order_meta_table_name WHERE order_id = %d AND meta_key = %s", $order_id, $key );
9337 $res = $wpdb->get_var( $query );
9338 return $res;
9339 }
9340
9341 public function set_order_meta_value( $key, $meta_value, $order_id, $check = 1 ) {
9342 global $wpdb;
9343
9344 if ( empty( $order_id ) ) {
9345 return;
9346 }
9347
9348 $order_id = (int) $order_id;
9349 if ( $check ) {
9350 $order = $this->get_order_data( $order_id, 'direct' );
9351 if ( null === $order ) {
9352 return;
9353 }
9354 }
9355
9356 $table_name = $wpdb->prefix . 'usces_order_meta';
9357 $query = $wpdb->prepare(
9358 "SELECT count(*) FROM $table_name WHERE order_id = %d AND meta_key = %s",
9359 $order_id, $key
9360 );
9361 $res = $wpdb->get_var( $query );
9362 if ( 0 < $res ) {
9363 $query = $wpdb->prepare(
9364 "UPDATE $table_name SET meta_value = %s WHERE order_id = %d AND meta_key = %s",
9365 $meta_value,
9366 $order_id,
9367 $key
9368 );
9369 $res2 = $wpdb->query( $query );
9370 } else {
9371 $query = $wpdb->prepare(
9372 "INSERT INTO $table_name (order_id, meta_key, meta_value)
9373 VALUES(%d, %s, %s)",
9374 $order_id,
9375 $key,
9376 $meta_value
9377 );
9378 $res2 = $wpdb->query( $query );
9379 }
9380 return $res2;
9381 }
9382
9383 public function del_order_meta( $key, $order_id ) {
9384 global $wpdb;
9385 $table_name = $wpdb->prefix . 'usces_order_meta';
9386 $query = $wpdb->prepare( "DELETE FROM $table_name WHERE order_id = %d AND meta_key = %s", $order_id, $key );
9387 $res = $wpdb->query( $query );
9388 return $res;
9389 }
9390
9391 public function set_session_custom_member( $member_id ) {
9392 unset( $_SESSION['usces_member']['custom_member'] );
9393 $meta = usces_has_custom_field_meta( 'member' );
9394 if ( is_array( $meta ) ) {
9395 $keys = array_keys( $meta );
9396 foreach ( $keys as $key ) {
9397 $csmb_key = 'csmb_' . $key;
9398 $_SESSION['usces_member']['custom_member'][ $key ] = wel_safe_maybe_unserialize( $this->get_member_meta_value( $csmb_key, $member_id ) );
9399 }
9400 }
9401 }
9402
9403 public function reg_custom_member( $member_id ) {
9404 $csmb_meta = usces_has_custom_field_meta( 'member' );
9405 if ( is_array( $csmb_meta ) ) {
9406 foreach ( $csmb_meta as $key => $entry ) {
9407 if ( '4' == $entry['means'] ) {
9408 $this->del_member_meta( 'csmb_' . $key, $member_id );
9409 }
9410 }
9411 }
9412 if ( ! empty( $_POST['custom_member'] ) ) {
9413 foreach ( $_POST['custom_member'] as $key => $value ) {
9414 $csmb_key = 'csmb_' . $key;
9415 $value = wel_safe_text_serialize( $value );
9416 if ( is_array( $value ) ) {
9417 $value = serialize( $value );
9418 }
9419 $res = $this->set_member_meta_value( $csmb_key, $value, $member_id );
9420 if ( false === $res ) {
9421 return false;
9422 }
9423 }
9424 } elseif ( isset( $_POST['custom_customer'] ) ) {
9425 foreach ( $_POST['custom_customer'] as $key => $value ) {
9426 $csmb_key = 'csmb_' . $key;
9427 $value = wel_safe_text_serialize( $value );
9428 if ( is_array( $value ) ) {
9429 $value = serialize( $value );
9430 }
9431 $res = $this->set_member_meta_value( $csmb_key, $value, $member_id );
9432 if ( false === $res ) {
9433 return false;
9434 }
9435 }
9436 }
9437 }
9438
9439 public function save_order_acting_data( $rand ) {
9440 global $wpdb;
9441 $data = serialize(
9442 array(
9443 'cart' => $this->cart->get_cart(),
9444 'entry' => $this->cart->get_entry(),
9445 )
9446 );
9447 $table_name = $wpdb->prefix . 'usces_access';
9448 $query = $wpdb->prepare(
9449 "INSERT INTO $table_name (acc_type, acc_str1, acc_date, acc_key, acc_value)
9450 VALUES(%s, %s, now(), %s, %s)",
9451 'acting_data',
9452 $this->get_uscesid(false),
9453 $rand,
9454 $data
9455 );
9456 $res = $wpdb->query( $query );
9457 return $res;
9458 }
9459
9460 public function set_member_meta_value( $key, $meta_value, $member_id = '' ) {
9461 global $wpdb;
9462
9463 if ( WCUtils::is_blank( $member_id ) ) {
9464 if ( ! $this->is_member_logged_in() ) {
9465 return;
9466 }
9467 $member = $this->get_member();
9468 $member_id = $member['ID'];
9469 }
9470
9471 $table_name = usces_get_tablename( 'usces_member_meta' );
9472 $query = $wpdb->prepare( "SELECT count(*) FROM $table_name WHERE member_id = %d AND meta_key = %s", $member_id, $key );
9473 $res = $wpdb->get_var( $query );
9474 if ( 0 < $res ) {
9475 $query = $wpdb->prepare(
9476 "UPDATE $table_name SET meta_value = %s WHERE member_id = %d AND meta_key = %s",
9477 $meta_value,
9478 $member_id,
9479 $key
9480 );
9481 $res2 = $wpdb->query( $query );
9482 } else {
9483 $query = $wpdb->prepare(
9484 "INSERT INTO $table_name (member_id, meta_key, meta_value)
9485 VALUES(%d, %s, %s)",
9486 $member_id,
9487 $key,
9488 $meta_value
9489 );
9490 $res2 = $wpdb->query( $query );
9491 }
9492 return $res2;
9493 }
9494
9495 public function get_member_meta_value( $key, $member_id ) {
9496 global $wpdb;
9497 $table_name = usces_get_tablename( 'usces_member_meta' );
9498 $query = $wpdb->prepare( "SELECT meta_value FROM $table_name WHERE member_id = %d AND meta_key = %s", $member_id, $key );
9499 $res = $wpdb->get_var( $query );
9500 return $res;
9501 }
9502
9503 public function del_member_meta( $key, $member_id ) {
9504 global $wpdb;
9505 $table_name = usces_get_tablename( 'usces_member_meta' );
9506 $query = $wpdb->prepare( "DELETE FROM $table_name WHERE member_id = %d AND meta_key = %s", $member_id, $key );
9507 $res = $wpdb->query( $query );
9508 return $res;
9509 }
9510
9511 public function get_member_meta( $member_id ) {
9512 global $wpdb;
9513 $table_name = usces_get_tablename( 'usces_member_meta' );
9514 $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_%' );
9515 $res = $wpdb->get_results( $query, ARRAY_A );
9516 return $res;
9517 }
9518
9519 public function get_settle_info_field( $order_id ) {
9520 global $wpdb;
9521 $fields = array();
9522 $table_name = $wpdb->prefix . 'usces_order_meta';
9523 $meta_keys = apply_filters( 'usces_filter_settle_info_field_meta_keys', array( 'settlement_id', 'order_number', 'res_tracking_id', 'SID', 'TransactionId' ) );
9524 $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 ) );
9525 $query = stripslashes( $query );
9526 $res = $wpdb->get_results( $query, ARRAY_A );
9527 if ( ! $res ) {
9528 return $fields;
9529 }
9530 foreach ( $res as $value ) {
9531 if ( in_array( $value['meta_key'], $meta_keys ) ) {
9532 $meta_key = $value['meta_key'];
9533 if ( 'settlement_id' == $meta_key ) {
9534 $meta_values = wel_safe_maybe_unserialize( $value['meta_value'] );
9535 if ( is_array( $meta_values ) ) {
9536 foreach ( $meta_values as $key => $meta_value ) {
9537 $fields[ $key ] = $meta_value;
9538 }
9539 } else {
9540 $fields['settlement_id'] = $meta_values;
9541 }
9542 } else {
9543 $fields[ $meta_key ] = $value['meta_value'];
9544 }
9545 } elseif ( 'acting_' == substr( $value['meta_key'], 0, 7 ) ) {
9546 $meta_values = usces_unserialize( $value['meta_value'] );
9547 if ( is_array( $meta_values ) ) {
9548 foreach ( $meta_values as $key => $meta_value ) {
9549 $fields[ $key ] = $meta_value;
9550 }
9551 } else {
9552 $meta_values = wel_safe_maybe_unserialize( $value['meta_value'] );
9553 if ( is_array( $meta_values ) ) {
9554 foreach ( $meta_values as $key => $meta_value ) {
9555 $fields[ $key ] = $meta_value;
9556 }
9557 }
9558 }
9559 }
9560 }
9561 return $fields;
9562 }
9563
9564 public function get_post_custom( $post_id, $orderby = 'meta_id', $order = 'ASC' ) {
9565 global $wpdb;
9566 $table = $wpdb->prefix . 'postmeta';
9567 $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 );
9568
9569 if ( ! empty( $meta_list ) ) {
9570 foreach ( $meta_list as $metarow ) {
9571 $mkey = $metarow['meta_key'];
9572 $mval = $metarow['meta_value'];
9573 $res[ $mkey ][] = $mval;
9574 }
9575 }
9576 return $res;
9577 }
9578
9579 public function get_post_user_custom( $post_id, $orderby = 'meta_id', $order = 'ASC' ) {
9580 global $wpdb;
9581 $res = array();
9582 $table = $wpdb->prefix . 'postmeta';
9583 $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 );
9584
9585 if ( ! empty( $meta_list ) ) {
9586 foreach ( $meta_list as $metarow ) {
9587 if ( 0 === strpos( $metarow['meta_key'], '_' ) ) {
9588 continue;
9589 }
9590 $mkey = $metarow['meta_key'];
9591 $mval = $metarow['meta_value'];
9592 if ( array_key_exists( $mkey, $res ) ) {
9593 $cval = $res[ $mkey ];
9594 $cval = (array) $cval;
9595 $cval[] = $mval;
9596 $res[ $mkey ] = $cval;
9597 } else {
9598 $res[ $mkey ] = $mval;
9599 }
9600 }
9601 }
9602 $res = apply_filters( 'usces_filter_get_post_user_custom', $res, $meta_list, $post_id, $orderby, $order );
9603 return $res;
9604 }
9605
9606 public function get_currency( $amount, $symbol_pre = false, $symbol_post = false, $seperator_flag = true ) {
9607 global $usces_settings;
9608 $cr = $this->options['system']['currency'];
9609 list( $code, $decimal, $point, $seperator, $symbol ) = $usces_settings['currency'][ $cr ];
9610 if ( ! $seperator_flag ) {
9611 $seperator = '';
9612 }
9613 $price = number_format( (double) $amount, $decimal, $point, $seperator );
9614
9615 if ( $symbol_pre ) {
9616 $price = ( usces_is_entity( $symbol ) ? mb_convert_encoding( $symbol, 'UTF-8', 'HTML-ENTITIES' ) : $symbol ) . $price;
9617 }
9618 if ( $symbol_post ) {
9619 $price = $price . __( $code, 'usces' );
9620 }
9621 $price = apply_filters( 'usces_filter_get_currency', $price, $amount, $symbol_pre, $symbol_post, $seperator_flag );
9622 return $price;
9623 }
9624
9625 public function get_currency_code() {
9626 global $usces_settings;
9627 $cr = $this->options['system']['currency'];
9628 list( $code, $decimal, $point, $seperator, $symbol ) = $usces_settings['currency'][ $cr ];
9629 return $code;
9630 }
9631
9632 public function get_currency_decimal() {
9633 global $usces_settings;
9634 $cr = $this->options['system']['currency'];
9635 list( $code, $decimal, $point, $seperator, $symbol ) = $usces_settings['currency'][ $cr ];
9636 return $decimal;
9637 }
9638
9639 public function get_next_page_uri( $type, $current ) {
9640 global $wpdb;
9641
9642 $table = $wpdb->prefix . 'usces_' . $type;
9643 if ( ! isset( $_COOKIE[ $table ] ) ) {
9644 return false;
9645 }
9646
9647 $cookie = ( isset( $_COOKIE[ $table ] ) ) ? json_decode( str_replace( "\'", "'", str_replace( '\"', '"', $_COOKIE[ $table ] ) ), true ) : array();
9648 if ( ! isset( $cookie['currentPageIds'] ) ) {
9649 return false;
9650 }
9651
9652 $ids = $cookie['currentPageIds'];
9653 foreach ( $ids as $key => $id ) {
9654 if ( $id == $current ) {
9655 $next = isset( $ids[ ( $key + 1 ) ] ) ? $ids[ ( $key + 1 ) ] : '';
9656 break;
9657 }
9658 }
9659
9660 if ( empty( $next ) ) {
9661 $uri = '';
9662 } else {
9663 $uri = USCES_ADMIN_URL . "?page=usces_{$type}list&{$type}_action=edit&{$type}_id=" . $next;
9664 }
9665
9666 return esc_url( $uri );
9667 }
9668
9669 public function get_prev_page_uri( $type, $current ) {
9670 global $wpdb;
9671
9672 $table = $wpdb->prefix . 'usces_' . $type;
9673 if ( ! isset( $_COOKIE[ $table ] ) ) {
9674 return false;
9675 }
9676
9677 $cookie = ( isset( $_COOKIE[ $table ] ) ) ? json_decode( str_replace( "\'", "'", str_replace( '\"', '"', $_COOKIE[ $table ] ) ), true ) : array();
9678 if ( ! isset( $cookie['currentPageIds'] ) ) {
9679 return false;
9680 }
9681
9682 $ids = $cookie['currentPageIds'];
9683 foreach ( $ids as $key => $id ) {
9684 if ( $id == $current ) {
9685 $prev = isset( $ids[ ( $key - 1 ) ] ) ? $ids[ ( $key - 1 ) ] : '';
9686 break;
9687 }
9688 }
9689
9690 if ( empty( $prev ) ) {
9691 $uri = '';
9692 } else {
9693 $uri = USCES_ADMIN_URL . "?page=usces_{$type}list&{$type}_action=edit&{$type}_id=" . $prev;
9694 }
9695
9696 return esc_url( $uri );
9697 }
9698
9699 public function is_reduced_taxrate() {
9700
9701 $reduced = ( isset( $this->options['applicable_taxrate'] ) && 'reduced' == $this->options['applicable_taxrate'] ) ? true : false;
9702 return $reduced;
9703 }
9704
9705 public function sc_company_name() {
9706 return htmlspecialchars( $this->options['company_name'], ENT_COMPAT );
9707 }
9708
9709 public function sc_zip_code() {
9710 return htmlspecialchars( $this->options['zip_code'], ENT_COMPAT );
9711 }
9712
9713 public function sc_address1() {
9714 return htmlspecialchars( $this->options['address1'], ENT_COMPAT );
9715 }
9716
9717 public function sc_address2() {
9718 return htmlspecialchars( $this->options['address2'], ENT_COMPAT );
9719 }
9720
9721 public function sc_tel_number() {
9722 return htmlspecialchars( $this->options['tel_number'], ENT_COMPAT );
9723 }
9724
9725 public function sc_fax_number() {
9726 return htmlspecialchars( $this->options['fax_number'], ENT_COMPAT );
9727 }
9728
9729 public function sc_inquiry_mail() {
9730 return htmlspecialchars( $this->options['inquiry_mail'], ENT_COMPAT );
9731 }
9732
9733 public function sc_payment() {
9734 $payments = usces_get_system_option( 'usces_payment_method', 'sort' );
9735 $htm = "<ul>\n";
9736 foreach ( (array) $payments as $payment ) {
9737 $htm .= '<li>' . htmlspecialchars( $payment['name'], ENT_COMPAT ) . "<br />\n";
9738 $htm .= nl2br( htmlspecialchars( $payment['explanation'], ENT_COMPAT ) ) . "</li>\n";
9739 }
9740 $htm .= "</ul>\n";
9741 return $htm;
9742 }
9743
9744 public function sc_payment_title() {
9745 $payments = $this->options['payment_method'];
9746 $htm = "<ul>\n";
9747 foreach ( (array) $payments as $payment ) {
9748 $htm .= '<li>' . esc_html( $payment['name'] ) . "</li>\n";
9749 }
9750 $htm .= "</ul>\n";
9751 return $htm;
9752 }
9753
9754 public function sc_cod_fee() {
9755 return number_format( $this->options['cod_fee'] );
9756 }
9757
9758 public function sc_start_point() {
9759 return number_format( $this->options['start_point'] );
9760 }
9761
9762 public function sc_postage_privilege() {
9763 if ( empty( $this->options['postage_privilege'] ) ) {
9764 return;
9765 }
9766 return number_format( $this->options['postage_privilege'] );
9767 }
9768
9769 public function sc_shipping_charge() {
9770 $entry = $this->cart->get_entry();
9771 $country = ( isset( $entry['delivery']['country'] ) && ! empty( $entry['delivery']['country'] ) ) ? $entry['delivery']['country'] : $entry['customer']['country'];
9772 $arr = array();
9773 foreach ( (array) $this->options['shipping_charge'] as $charges ) {
9774 foreach ( (array) $charges[ $country ] as $value ) {
9775 $arr[] = $value;
9776 }
9777 }
9778 sort( $arr );
9779 $min = $arr[0];
9780 rsort( $arr );
9781 $max = $arr[0];
9782 if ( $min == $max ) {
9783 $res = number_format( $min );
9784 } else {
9785 $res = number_format( $min ) . __( ' - ', 'usces' ) . number_format( $max );
9786 }
9787 return $res;
9788 }
9789
9790 public function sc_site_url() {
9791 return get_option( 'home' );
9792 }
9793
9794 public function sc_button_to_cart( $atts ) {
9795 extract(
9796 shortcode_atts(
9797 array(
9798 'item' => '',
9799 'sku' => '',
9800 'value' => __( 'to the cart', 'usces' ),
9801 'force' => 0,
9802 'quant' => 0,
9803 'opt' => 1,
9804 ),
9805 $atts
9806 )
9807 );
9808
9809 $post_id = $this->get_ID_byItemName( $item );
9810 $datas = $this->get_skus( $post_id, 'code' );
9811 $zaikonum = ( isset( $datas[ $sku ]['stocknum'] ) ) ? $datas[ $sku ]['stocknum'] : null;
9812 $zaiko = ( isset( $datas[ $sku ]['stock'] ) ) ? $datas[ $sku ]['stock'] : 2;
9813 $gptekiyo = ( isset( $datas[ $sku ]['gp'] ) ) ? $datas[ $sku ]['gp'] : null;
9814 $skuPrice = ( isset( $datas[ $sku ]['price'] ) ) ? $datas[ $sku ]['price'] : 0;
9815 $sku_enc = urlencode( $sku );
9816 $options = usces_get_opts( $post_id, 'sort' );
9817 $mats = compact( 'item', 'sku', 'value', 'force', 'quant', 'post_id', 'datas', 'zaikonum', 'zaiko', 'gptekiyo', 'skuPrice', 'sku_enc' );
9818 if ( ! $this->is_item_zaiko( $post_id, $sku ) ) {
9819 return '<div class="button_status">' . esc_html( $this->zaiko_status[ $zaiko ] ) . '</div>';
9820 }
9821
9822 $html = "<form action=\"" . USCES_CART_URL . "\" method=\"post\">\n";
9823 $html .= "<input name=\"zaikonum[{$post_id}][{$sku_enc}]\" type=\"hidden\" id=\"zaikonum[{$post_id}][{$sku_enc}]\" value=\"" . esc_attr( $zaikonum ) . "\" />\n";
9824 $html .= "<input name=\"zaiko[{$post_id}][{$sku_enc}]\" type=\"hidden\" id=\"zaiko[{$post_id}][{$sku_enc}]\" value=\"" . esc_attr( $zaiko ) . "\" />\n";
9825 $html .= "<input name=\"gptekiyo[{$post_id}][{$sku_enc}]\" type=\"hidden\" id=\"gptekiyo[{$post_id}][{$sku_enc}]\" value=\"" . esc_attr( $gptekiyo ) . "\" />\n";
9826 $html .= "<input name=\"skuPrice[{$post_id}][{$sku_enc}]\" type=\"hidden\" id=\"skuPrice[{$post_id}][{$sku_enc}]\" value=\"" . esc_attr( $skuPrice ) . "\" />\n";
9827 if ( 1 == $opt ) {
9828 $html .= usces_item_option_fileds( $post_id, $sku, 1, 'return' );
9829 } elseif ( 2 == $opt ) {
9830 $html .= usces_item_option_fileds( $post_id, $sku, 0, 'return' );
9831 }
9832 if ( $quant ) {
9833 $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;}\" />";
9834 $html .= apply_filters( 'usces_filter_sc_itemQuant', $quant_field, $mats );
9835 }
9836 $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 ) . ' />';
9837 $html .= "<input name=\"usces_referer\" type=\"hidden\" value=\"" . esc_url( $_SERVER['REQUEST_URI'] ) . "\" />\n";
9838 if ( $force ) {
9839 $html .= "<input name=\"usces_force\" type=\"hidden\" value=\"incart\" />\n";
9840 }
9841 $html = apply_filters( 'usces_filter_single_item_inform', $html );
9842 $html .= '</form>';
9843 $html .= '<div class="error_message">' . usces_singleitem_error_message( $post_id, $sku, 'return' ) . '</div>' . "\n";
9844
9845 return $html;
9846 }
9847
9848 public function filter_itemPage( $content ) {
9849 global $post;
9850 $html = '';
9851
9852 if ( ( 'item' != $post->post_mime_type || ! is_single() ) ) {
9853 return $content;
9854 }
9855 if ( post_password_required( $post ) ) {
9856 return $content;
9857 }
9858
9859 $temp_path = apply_filters( 'usces_template_path_single_item', USCES_PLUGIN_DIR . '/templates/single_item.php' );
9860 include $temp_path;
9861
9862 $content = apply_filters( 'usces_filter_itemPage', $html, $post->ID );
9863
9864 return $content;
9865 }
9866
9867 public function filter_cartContent( $content ) {
9868 global $post;
9869 $html = '';
9870 switch ( $this->page ) {
9871 case 'cart':
9872 $temp_path = apply_filters( 'usces_template_path_cart', USCES_PLUGIN_DIR . '/templates/cart/cart.php' );
9873 include $temp_path;
9874 break;
9875 case 'customer':
9876 $temp_path = apply_filters( 'usces_template_path_customer', USCES_PLUGIN_DIR . '/templates/cart/customer_info.php' );
9877 include $temp_path;
9878 break;
9879 case 'delivery':
9880 $temp_path = apply_filters( 'usces_template_path_delivery', USCES_PLUGIN_DIR . '/templates/cart/delivery_info.php' );
9881 include $temp_path;
9882 break;
9883 case 'confirm':
9884 $temp_path = apply_filters( 'usces_template_path_confirm', USCES_PLUGIN_DIR . '/templates/cart/confirm.php' );
9885 include $temp_path;
9886 break;
9887 case 'ordercompletion':
9888 $temp_path = apply_filters( 'usces_template_path_ordercompletion', USCES_PLUGIN_DIR . '/templates/cart/completion.php' );
9889 include $temp_path;
9890 break;
9891 case 'cartverifying':
9892 $temp_path = apply_filters( 'usces_template_path_cartverifying', USCES_PLUGIN_DIR . '/templates/cart/verifying.php' );
9893 include $temp_path;
9894 break;
9895 case 'cartverified':
9896 $temp_path = apply_filters( 'usces_template_path_cartverified', USCES_PLUGIN_DIR . '/templates/cart/verified.php' );
9897 include $temp_path;
9898 break;
9899 case 'error':
9900 $temp_path = apply_filters( 'usces_template_path_carterror', USCES_PLUGIN_DIR . '/templates/cart/error.php' );
9901 include $temp_path;
9902 break;
9903 case 'maintenance':
9904 $temp_path = apply_filters( 'usces_template_path_maintenance', USCES_PLUGIN_DIR . '/templates/cart/maintenance.php' );
9905 include $temp_path;
9906 break;
9907 case 'search_item':
9908 $temp_path = apply_filters( 'usces_template_path_search_item', USCES_PLUGIN_DIR . '/templates/search_item.php' );
9909 include $temp_path;
9910 break;
9911 case 'wp_search':
9912 if ( 'item' == $post->post_mime_type ) {
9913 $temp_path = apply_filters( 'usces_template_path_wp_search', USCES_PLUGIN_DIR . '/templates/wp_search_item.php' );
9914 include $temp_path;
9915 } else {
9916 $html = $content;
9917 }
9918 break;
9919 default:
9920 $html = $content;
9921 }
9922
9923 if ( $this->use_ssl && ( $this->is_cart_or_member_page( $_SERVER['REQUEST_URI'] ) || $this->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) ) {
9924 $html = str_replace( 'src="' . site_url(), 'src="' . USCES_SSL_URL_ADMIN, $html );
9925 }
9926
9927 $html = apply_filters( 'usces_filter_cartContent', $html );
9928
9929 $content = $html;
9930
9931 remove_filter( 'the_title', array( $this, 'filter_cartTitle' ) );
9932
9933 return $content;
9934 }
9935
9936 public function filter_cartTitle( $title ) {
9937 if ( is_admin() ) {
9938 return $title;
9939 }
9940
9941 if ( 'Cart' == $title || __( 'Cart', 'usces' ) == $title ) {
9942 switch ( $this->page ) {
9943 case 'cart':
9944 $newtitle = apply_filters( 'usces_filter_title_cart', __( 'In the cart', 'usces' ) );
9945 break;
9946 case 'customer':
9947 $newtitle = apply_filters( 'usces_filter_title_customer', __( 'Customer Information', 'usces' ) );
9948 break;
9949 case 'delivery':
9950 $newtitle = apply_filters( 'usces_filter_title_delivery', __( 'Shipping / Payment options', 'usces' ) );
9951 break;
9952 case 'confirm':
9953 $newtitle = apply_filters( 'usces_filter_title_confirm', __( 'Confirmation', 'usces' ) );
9954 break;
9955 case 'ordercompletion':
9956 $newtitle = apply_filters( 'usces_filter_title_ordercompletion', __( 'Completion', 'usces' ) );
9957 break;
9958 case 'error':
9959 $newtitle = apply_filters( 'usces_filter_title_carterror', __( 'Error', 'usces' ) );
9960 break;
9961 case 'cartverified':
9962 $newtitle = apply_filters( 'usces_filter_title_cartverified', __( 'Member registration complete', 'usces' ) );
9963 break;
9964 case 'search_item':
9965 $newtitle = apply_filters( 'usces_filter_title_search_item', __( "'AND' search by categories", 'usces' ) );
9966 break;
9967 case 'maintenance':
9968 $newtitle = apply_filters( 'usces_filter_title_maintenance', __( 'Under Maintenance', 'usces' ) );
9969 break;
9970 case 'login':
9971 $newtitle = apply_filters( 'usces_filter_title_login', __( 'Log-in for members', 'usces' ) );
9972 break;
9973 default:
9974 $newtitle = apply_filters( 'usces_filter_title_cart_default', $title );
9975 }
9976 } else {
9977 $newtitle = $title;
9978 }
9979
9980 $newtitle = apply_filters( 'usces_filter_cartTitle', $newtitle );
9981 return $newtitle;
9982 }
9983
9984 public function action_cartFilter() {
9985 add_filter( 'the_title', array( $this, 'filter_cartTitle' ), 20 );
9986 add_filter( 'the_content', array( $this, 'filter_cartContent' ), 20 );
9987 }
9988
9989 public function action_search_item() {
9990 include get_template_directory() . '/page.php';
9991 exit;
9992 }
9993
9994 public function filter_memberContent( $content ) {
9995 global $post;
9996 $html = '';
9997
9998 if ( 'activate' == $this->options['membersystem_state'] ) {
9999
10000 if ( $this->is_member_logged_in() ) {
10001
10002 $member_regmode = 'editmemberform';
10003 $temp_path = apply_filters( 'usces_template_path_member', USCES_PLUGIN_DIR . '/templates/member/member.php' );
10004 include $temp_path;
10005
10006 } else {
10007
10008 switch ( $this->page ) {
10009 case 'login':
10010 $temp_path = apply_filters( 'usces_template_path_login', USCES_PLUGIN_DIR . '/templates/member/login.php' );
10011 include $temp_path;
10012 break;
10013 case 'lostmemberpassword':
10014 $temp_path = apply_filters( 'usces_template_path_lostpassword', USCES_PLUGIN_DIR . '/templates/member/lostpassword.php' );
10015 include $temp_path;
10016 break;
10017 case 'changepassword':
10018 $temp_path = apply_filters( 'usces_template_path_changepassword', USCES_PLUGIN_DIR . '/templates/member/changepassword.php' );
10019 include $temp_path;
10020 break;
10021 case 'newcompletion':
10022 case 'editcompletion':
10023 case 'lostcompletion':
10024 case 'changepasscompletion':
10025 $temp_path = apply_filters( 'usces_template_path_membercompletion', USCES_PLUGIN_DIR . '/templates/member/completion.php' );
10026 include $temp_path;
10027 break;
10028 case 'memberverifying':
10029 $temp_path = apply_filters( 'usces_template_path_memberverifying', USCES_PLUGIN_DIR . '/templates/member/verifying.php' );
10030 include $temp_path;
10031 break;
10032 // case 'memberverified':
10033 // $temp_path = apply_filters('usces_template_path_memberverified', USCES_PLUGIN_DIR . '/templates/member/member_verified.php');
10034 // include $temp_path;
10035 // break;
10036 case 'newmemberform':
10037 $member_form_title = apply_filters( 'usces_filter_title_newmemberform', __( 'New enrollment form', 'usces' ) );
10038 $member_regmode = 'newmemberform';
10039 $temp_path = apply_filters( 'usces_template_path_member_form', USCES_PLUGIN_DIR . '/templates/member/member_form.php' );
10040 include $temp_path;
10041 break;
10042 default:
10043 $temp_path = apply_filters( 'usces_template_path_login', USCES_PLUGIN_DIR . '/templates/member/login.php' );
10044 include $temp_path;
10045 }
10046 }
10047 } else {
10048 $html .= '<p>' . __( 'Member Services is not running currently.', 'usces' ) . '</p>';
10049 }
10050
10051 $content = $html;
10052
10053 remove_filter( 'the_title', array( $this, 'filter_memberTitle' ), 20 );
10054
10055 return $content;
10056 }
10057
10058 public function filter_memberTitle( $title ) {
10059 if ( is_admin() ) {
10060 return $title;
10061 }
10062
10063 if ( 'activate' == $this->options['membersystem_state'] && $this->is_member_page( $_SERVER['REQUEST_URI'] ) ) {
10064 switch ( $this->page ) {
10065 case 'login':
10066 $newtitle = apply_filters( 'usces_filter_title_login', __( 'Log-in for members', 'usces' ) );
10067 break;
10068 case 'newmemberform':
10069 $newtitle = apply_filters( 'usces_filter_title_newmemberform', __( 'New enrollment form', 'usces' ) );
10070 break;
10071 case 'lostmemberpassword':
10072 $newtitle = apply_filters( 'usces_filter_title_lostmemberpassword', __( 'The new password acquisition', 'usces' ) );
10073 break;
10074 case 'changepassword':
10075 $newtitle = apply_filters( 'usces_filter_title_changepassword', __( 'Change password', 'usces' ) );
10076 break;
10077 case 'newcompletion':
10078 case 'editcompletion':
10079 case 'lostcompletion':
10080 case 'changepasscompletion':
10081 $newtitle = apply_filters( 'usces_filter_title_changepasscompletion', __( 'Completion', 'usces' ) );
10082 break;
10083 case 'memberverifying':
10084 $newtitle = apply_filters( 'usces_filter_title_memberverifying', __( 'Verifying', 'usces' ) );
10085 break;
10086 case 'error':
10087 $newtitle = apply_filters( 'usces_filter_title_membererror', __( 'Error', 'usces' ) );
10088 break;
10089 default:
10090 $newtitle = apply_filters( 'usces_filter_title_member_default', $title );
10091 }
10092 } else {
10093 $newtitle = $title;
10094 }
10095
10096 $newtitle = apply_filters( 'usces_filter_memberTitle', $newtitle );
10097 return $newtitle;
10098 }
10099
10100 public function action_memberFilter() {
10101 add_filter( 'the_title', array( $this, 'filter_memberTitle' ), 20 );
10102 add_filter( 'the_content', array( $this, 'filter_memberContent' ), 20 );
10103 }
10104
10105 public function filter_usces_cart_css() {
10106 $path = get_stylesheet_directory_uri() . '/usces_cart.css';
10107 return $path;
10108 }
10109
10110 public function filter_divide_item() {
10111 global $wp_query;
10112
10113 if ( ( $this->options['divide_item'] && ! is_category() && ! is_search() && ! is_singular() && ! is_admin() ) ) {
10114 $ids = $this->getItemIds( 'front' );
10115 if ( isset( $wp_query->query_vars['post__not_in'] ) ) {
10116 $wp_query->query_vars['post__not_in'] = $ids;
10117 }
10118 }
10119 if ( is_admin() ) {
10120 $ids = $this->getItemIds( 'back' );
10121 if ( isset( $wp_query->query_vars['post__not_in'] ) ) {
10122 $wp_query->query_vars['post__not_in'] = $ids;
10123 }
10124 }
10125 do_action( 'usces_action_divide_item' );
10126 }
10127
10128 public function load_upload_template() {
10129 $post_id = $_POST['post_id'];
10130 $file = 'upload_template01.php';
10131 include get_template_directory() . '/' . $file;
10132 exit;
10133 }
10134
10135 public function filter_itemimg_anchor_rel( $html ) {
10136 if ( is_single() ) {
10137 $str = ' rel="' . $this->options['itemimg_anchor_rel'] . '"';
10138 } else {
10139 $str = '';
10140 }
10141 return $html . $str;
10142 }
10143
10144 public function filter_permalink( $link ) {
10145 if ( false !== strpos( '?page_id=4', $link ) || false !== strpos( '?page_id=3', $link ) || false !== strpos( 'usces-cart', $link ) || false !== strpos( 'usces-member', $link ) ) {
10146 $link = str_replace( 'http://', 'https://', $link );
10147 }
10148 return $link;
10149 }
10150
10151 public function filter_cart_page_header( $html ) {
10152 if ( ! empty( $this->options['cart_page_data']['header']['cart'] ) ) {
10153 $html = $this->options['cart_page_data']['header']['cart'];
10154 }
10155 return do_shortcode( stripslashes( nl2br( $html ) ) );
10156 }
10157
10158 public function filter_cart_page_footer( $html ) {
10159 if ( ! empty( $this->options['cart_page_data']['footer']['cart'] ) ) {
10160 $html = $this->options['cart_page_data']['footer']['cart'];
10161 }
10162 return do_shortcode( stripslashes( nl2br( $html ) ) );
10163 }
10164
10165 public function filter_customer_page_header( $html ) {
10166 if ( ! empty( $this->options['cart_page_data']['header']['customer'] ) ) {
10167 $html = $this->options['cart_page_data']['header']['customer'];
10168 }
10169 return do_shortcode( stripslashes( nl2br( $html ) ) );
10170 }
10171
10172 public function filter_customer_page_footer( $html ) {
10173 if ( ! empty( $this->options['cart_page_data']['footer']['customer'] ) ) {
10174 $html = $this->options['cart_page_data']['footer']['customer'];
10175 }
10176 return do_shortcode( stripslashes( nl2br( $html ) ) );
10177 }
10178
10179 public function filter_delivery_page_header( $html ) {
10180 if ( ! empty( $this->options['cart_page_data']['header']['delivery'] ) ) {
10181 $html = $this->options['cart_page_data']['header']['delivery'];
10182 }
10183 return do_shortcode( stripslashes( nl2br( $html ) ) );
10184 }
10185
10186 public function filter_delivery_page_footer( $html ) {
10187 if ( ! empty( $this->options['cart_page_data']['footer']['delivery'] ) ) {
10188 $html = $this->options['cart_page_data']['footer']['delivery'];
10189 }
10190 return do_shortcode( stripslashes( nl2br( $html ) ) );
10191 }
10192
10193 public function filter_confirm_page_header( $html ) {
10194 if ( ! empty( $this->options['cart_page_data']['header']['confirm'] ) ) {
10195 $html = $this->options['cart_page_data']['header']['confirm'];
10196 }
10197 return do_shortcode( stripslashes( nl2br( $html ) ) );
10198 }
10199
10200 public function filter_confirm_page_footer( $html ) {
10201 if ( ! empty( $this->options['cart_page_data']['footer']['confirm'] ) ) {
10202 $html = $this->options['cart_page_data']['footer']['confirm'];
10203 }
10204 return do_shortcode( stripslashes( nl2br( $html ) ) );
10205 }
10206
10207 public function filter_cartcompletion_page_header( $html ) {
10208 if ( ! empty( $this->options['cart_page_data']['header']['completion'] ) ) {
10209 $html = $this->options['cart_page_data']['header']['completion'];
10210 }
10211 return do_shortcode( stripslashes( nl2br( $html ) ) );
10212 }
10213
10214 public function filter_cartcompletion_page_footer( $html ) {
10215 if ( ! empty( $this->options['cart_page_data']['footer']['completion'] ) ) {
10216 $html = $this->options['cart_page_data']['footer']['completion'];
10217 }
10218 return do_shortcode( stripslashes( nl2br( $html ) ) );
10219 }
10220
10221 public function filter_login_page_header( $html ) {
10222 if ( ! empty( $this->options['member_page_data']['header']['login'] ) ) {
10223 $html = $this->options['member_page_data']['header']['login'];
10224 }
10225 return do_shortcode( stripslashes( nl2br( $html ) ) );
10226 }
10227
10228 public function filter_login_page_footer( $html ) {
10229 if ( ! empty( $this->options['member_page_data']['footer']['login'] ) ) {
10230 $html = $this->options['member_page_data']['footer']['login'];
10231 }
10232 return do_shortcode( stripslashes( nl2br( $html ) ) );
10233 }
10234
10235 public function filter_newmember_page_header( $html ) {
10236 if ( ! empty( $this->options['member_page_data']['header']['newmember'] ) ) {
10237 $html = $this->options['member_page_data']['header']['newmember'];
10238 }
10239 return do_shortcode( stripslashes( nl2br( $html ) ) );
10240 }
10241
10242 public function filter_newmember_page_footer( $html ) {
10243 if ( ! empty( $this->options['member_page_data']['footer']['newmember'] ) ) {
10244 $html = $this->options['member_page_data']['footer']['newmember'];
10245 }
10246 return do_shortcode( stripslashes( nl2br( $html ) ) );
10247 }
10248
10249 public function filter_newpass_page_header( $html ) {
10250 if ( ! empty( $this->options['member_page_data']['header']['newpass'] ) ) {
10251 $html = $this->options['member_page_data']['header']['newpass'];
10252 }
10253 return do_shortcode( stripslashes( nl2br( $html ) ) );
10254 }
10255
10256 public function filter_newpass_page_footer( $html ) {
10257 if ( ! empty( $this->options['member_page_data']['footer']['newpass'] ) ) {
10258 $html = $this->options['member_page_data']['footer']['newpass'];
10259 }
10260 return do_shortcode( stripslashes( nl2br( $html ) ) );
10261 }
10262
10263 public function filter_changepass_page_header( $html ) {
10264 if ( ! empty( $this->options['member_page_data']['header']['changepass'] ) ) {
10265 $html = $this->options['member_page_data']['header']['changepass'];
10266 }
10267 return do_shortcode( stripslashes( nl2br( $html ) ) );
10268 }
10269
10270 public function filter_changepass_page_footer( $html ) {
10271 if ( ! empty( $this->options['member_page_data']['footer']['changepass'] ) ) {
10272 $html = $this->options['member_page_data']['footer']['changepass'];
10273 }
10274 return do_shortcode( stripslashes( nl2br( $html ) ) );
10275 }
10276
10277 public function filter_memberinfo_page_header( $html ) {
10278 if ( ! empty( $this->options['member_page_data']['header']['memberinfo'] ) ) {
10279 $html = $this->options['member_page_data']['header']['memberinfo'];
10280 }
10281 return do_shortcode( stripslashes( nl2br( $html ) ) );
10282 }
10283
10284 public function filter_memberinfo_page_footer( $html ) {
10285 if ( ! empty( $this->options['member_page_data']['footer']['memberinfo'] ) ) {
10286 $html = $this->options['member_page_data']['footer']['memberinfo'];
10287 }
10288 return do_shortcode( stripslashes( nl2br( $html ) ) );
10289 }
10290
10291 public function filter_membercompletion_page_header( $html ) {
10292 if ( ! empty( $this->options['member_page_data']['header']['completion'] ) ) {
10293 $html = $this->options['member_page_data']['header']['completion'];
10294 }
10295 return do_shortcode( stripslashes( nl2br( $html ) ) );
10296 }
10297
10298 public function filter_membercompletion_page_footer( $html ) {
10299 if ( ! empty( $this->options['member_page_data']['footer']['completion'] ) ) {
10300 $html = $this->options['member_page_data']['footer']['completion'];
10301 }
10302 return do_shortcode( stripslashes( nl2br( $html ) ) );
10303 }
10304
10305 public function action_cart_page_header() {
10306 if ( ! empty( $this->options['cart_page_data']['header']['cart'] ) ) {
10307 $html = $this->options['cart_page_data']['header']['cart'];
10308 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10309 }
10310 }
10311
10312 public function action_cart_page_footer() {
10313 if ( ! empty( $this->options['cart_page_data']['footer']['cart'] ) ) {
10314 $html = $this->options['cart_page_data']['footer']['cart'];
10315 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10316 }
10317 }
10318
10319 public function action_customer_page_header() {
10320 if ( ! empty( $this->options['cart_page_data']['header']['customer'] ) ) {
10321 $html = $this->options['cart_page_data']['header']['customer'];
10322 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10323 }
10324 }
10325
10326 public function action_customer_page_footer() {
10327 if ( ! empty( $this->options['cart_page_data']['footer']['customer'] ) ) {
10328 $html = $this->options['cart_page_data']['footer']['customer'];
10329 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10330 }
10331 }
10332
10333 public function action_delivery_page_header() {
10334 if ( ! empty( $this->options['cart_page_data']['header']['delivery'] ) ) {
10335 $html = $this->options['cart_page_data']['header']['delivery'];
10336 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10337 }
10338 }
10339
10340 public function action_delivery_page_footer() {
10341 if ( ! empty( $this->options['cart_page_data']['footer']['delivery'] ) ) {
10342 $html = $this->options['cart_page_data']['footer']['delivery'];
10343 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10344 }
10345 }
10346
10347 public function action_confirm_page_header() {
10348 if ( ! empty( $this->options['cart_page_data']['header']['confirm'] ) ) {
10349 $html = $this->options['cart_page_data']['header']['confirm'];
10350 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10351 }
10352 }
10353
10354 public function action_confirm_page_footer() {
10355 if ( ! empty( $this->options['cart_page_data']['footer']['confirm'] ) ) {
10356 $html = $this->options['cart_page_data']['footer']['confirm'];
10357 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10358 }
10359 }
10360
10361 public function action_cartcompletion_page_header() {
10362 if ( ! empty( $this->options['cart_page_data']['header']['completion'] ) ) {
10363 $html = $this->options['cart_page_data']['header']['completion'];
10364 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10365 }
10366 }
10367
10368 public function action_cartcompletion_page_footer() {
10369 if ( ! empty( $this->options['cart_page_data']['footer']['completion'] ) ) {
10370 $html = $this->options['cart_page_data']['footer']['completion'];
10371 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10372 }
10373 }
10374
10375 public function action_login_page_header() {
10376 if ( ! empty( $this->options['member_page_data']['header']['login'] ) ) {
10377 $html = $this->options['member_page_data']['header']['login'];
10378 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10379 }
10380 }
10381
10382 public function action_login_page_footer() {
10383 if ( ! empty( $this->options['member_page_data']['footer']['login'] ) ) {
10384 $html = $this->options['member_page_data']['footer']['login'];
10385 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10386 }
10387 }
10388
10389 public function action_newmember_page_header() {
10390 if ( ! empty( $this->options['member_page_data']['header']['newmember'] ) ) {
10391 $html = $this->options['member_page_data']['header']['newmember'];
10392 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10393 }
10394 }
10395
10396 public function action_newmember_page_footer() {
10397 if ( ! empty( $this->options['member_page_data']['footer']['newmember'] ) ) {
10398 $html = $this->options['member_page_data']['footer']['newmember'];
10399 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10400 }
10401 }
10402
10403 public function action_newpass_page_header() {
10404 if ( ! empty( $this->options['member_page_data']['header']['newpass'] ) ) {
10405 $html = $this->options['member_page_data']['header']['newpass'];
10406 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10407 }
10408 }
10409
10410 public function action_newpass_page_footer() {
10411 if ( ! empty( $this->options['member_page_data']['footer']['newpass'] ) ) {
10412 $html = $this->options['member_page_data']['footer']['newpass'];
10413 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10414 }
10415 }
10416
10417 public function action_changepass_page_header() {
10418 if ( ! empty( $this->options['member_page_data']['header']['changepass'] ) ) {
10419 $html = $this->options['member_page_data']['header']['changepass'];
10420 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10421 }
10422 }
10423
10424 public function action_changepass_page_footer() {
10425 if ( ! empty( $this->options['member_page_data']['footer']['changepass'] ) ) {
10426 $html = $this->options['member_page_data']['footer']['changepass'];
10427 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10428 }
10429 }
10430
10431 public function action_memberinfo_page_header() {
10432 if ( ! empty( $this->options['member_page_data']['header']['memberinfo'] ) ) {
10433 $html = $this->options['member_page_data']['header']['memberinfo'];
10434 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10435 }
10436 }
10437
10438 public function action_memberinfo_page_footer() {
10439 if ( ! empty( $this->options['member_page_data']['footer']['memberinfo'] ) ) {
10440 $html = $this->options['member_page_data']['footer']['memberinfo'];
10441 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10442 }
10443 }
10444
10445 public function action_membercompletion_page_header() {
10446 if ( ! empty( $this->options['member_page_data']['header']['completion'] ) ) {
10447 $html = $this->options['member_page_data']['header']['completion'];
10448 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10449 }
10450 }
10451
10452 public function action_membercompletion_page_footer() {
10453 if ( ! empty( $this->options['member_page_data']['footer']['completion'] ) ) {
10454 $html = $this->options['member_page_data']['footer']['completion'];
10455 echo do_shortcode( stripslashes( nl2br( $html ) ) );
10456 }
10457 }
10458
10459 public function filter_confirm_page_notes( $html ) {
10460 if ( ! empty( $this->options['cart_page_data']['confirm_notes'] ) ) {
10461 $html = '<div class="wc_confirm_notes_area">' . $this->options['cart_page_data']['confirm_notes'] . '</div>';
10462 }
10463 return stripslashes( nl2br( $html ) );
10464 }
10465
10466 public function action_confirm_page_notes() {
10467 if ( ! empty( $this->options['cart_page_data']['confirm_notes'] ) ) {
10468 $html = '<div class="wc_confirm_notes_area">' . $this->options['cart_page_data']['confirm_notes'] . '</div>';
10469 echo stripslashes( nl2br( $html ) );
10470 }
10471 }
10472
10473 /**
10474 * Get member cookies.
10475 *
10476 * @param string $key string cookies key.
10477 *
10478 * @return string
10479 */
10480 public function usces_get_member_cookies( $key ) {
10481 $result = '';
10482 switch ( $key ) {
10483 case 'ord_ex_cancel':
10484 $ex_cancel = filter_input( INPUT_GET, 'ord_ex_cancel' );
10485 if ( $ex_cancel ) {
10486 $result = ( 'on' === $ex_cancel ) ? 'on' : 'off';
10487 } else {
10488 $cookie = $this->get_cookie( 'usces_front' );
10489 $result = isset( $cookie['ord_ex_cancel'] ) ? $cookie['ord_ex_cancel'] : 'on';
10490 $result = apply_filters( 'usces_filter_ord_ex_cancel_init', $result );
10491 }
10492 break;
10493 case 'pur-date':
10494 $result = filter_input( INPUT_GET, 'pur-date' );
10495 if ( null === $result ) {
10496 $cookie = $this->get_cookie( 'usces_front' );
10497 $result = isset( $cookie['usces_purdate'] ) ? $cookie['usces_purdate'] : 'd_30';
10498 $result = apply_filters( 'usces_filter_ord_purdate_init', $result );
10499 }
10500 break;
10501 }
10502 return $result;
10503 }
10504
10505 }
10506