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
← All changes | functions/function.php +5633 -4416 1.3.162.12.4 View file →
@@ -1,4416 +1,5633 @@
1 -<?php
2 -
3 -function usces_ajax_send_mail() {
4 - global $wpdb, $usces;
5 -
6 - $_POST = $usces->stripslashes_deep_post($_POST);
7 - $order_para = array(
8 - 'to_name' => sprintf(__('Mr/Mrs %s', 'usces'), trim(urldecode($_POST['name']))),
9 - 'to_address' => trim($_POST['mailaddress']),
10 - 'from_name' => get_option('blogname'),
11 - 'from_address' => $usces->options['sender_mail'],
12 - 'return_path' => $usces->options['sender_mail'],
13 - 'subject' => trim(urldecode($_POST['subject'])),
14 - 'message' => trim(urldecode($_POST['message']))
15 - );
16 -
17 - $order_para = apply_filters( 'usces_ajax_send_mail_para_to_customer', $order_para);
18 - $res = usces_send_mail( $order_para );
19 - if($res){
20 - $tableName = $wpdb->prefix . "usces_order";
21 - $order_id = $_POST['order_id'];
22 - $checked = $_POST['checked'];
23 -
24 - $query = $wpdb->prepare("SELECT `order_check` FROM $tableName WHERE ID = %d", $order_id);
25 - $res = $wpdb->get_var( $query );
26 -
27 - $checkfield = unserialize($res);
28 - if( !isset($checkfield[$checked]) ) $checkfield[$checked] = $checked;
29 - //$checkfield = 'OK';
30 - $query = $wpdb->prepare("UPDATE $tableName SET `order_check`=%s WHERE ID = %d", serialize($checkfield), $order_id);
31 - $wpdb->query( $query );
32 -
33 - $bcc_para = array(
34 - 'to_name' => 'Shop Admin',
35 - 'to_address' => $usces->options['order_mail'],
36 - 'from_name' => 'Welcart Auto BCC',
37 - 'from_address' => $usces->options['sender_mail'],
38 - 'return_path' => $usces->options['sender_mail'],
39 - 'subject' => trim(urldecode($_POST['subject'])) . ' to ' . sprintf(__('Mr/Mrs %s', 'usces'), trim(urldecode($_POST['name']))),
40 - 'message' => trim(urldecode($_POST['message']))
41 - );
42 -
43 - $bcc_para = apply_filters( 'usces_ajax_send_mail_para_to_manager', $bcc_para);
44 - usces_send_mail( $bcc_para );
45 -
46 - return 'success';
47 - }else{
48 - return 'error';
49 - }
50 -}
51 -
52 -function usces_order_confirm_message($order_id) {
53 - global $usces, $wpdb, $usces_settings;
54 -
55 - $tableName = $wpdb->prefix . "usces_order";
56 - $query = $wpdb->prepare("SELECT * FROM $tableName WHERE ID = %d", $order_id);
57 - $data = $wpdb->get_row( $query, ARRAY_A );
58 - $deli = unserialize($data['order_delivery']);
59 - $cart = unserialize($data['order_cart']);
60 - $country = $usces->get_order_meta_value('customer_country', $order_id);
61 - $customer = array(
62 - 'name1' => $data['order_name1'],
63 - 'name2' => $data['order_name2'],
64 - 'name3' => $data['order_name3'],
65 - 'name4' => $data['order_name4'],
66 - 'zipcode' => $data['order_zip'],
67 - 'country' => $country,
68 - 'pref' => $data['order_pref'],
69 - 'address1' => $data['order_address1'],
70 - 'address2' => $data['order_address2'],
71 - 'address3' => $data['order_address3'],
72 - 'tel' => $data['order_tel'],
73 - 'fax' => $data['order_fax'],
74 - );
75 - $condition = unserialize($data['order_condition']);
76 -
77 - $total_full_price = $data['order_item_total_price'] - $data['order_usedpoint'] + $data['order_discount'] + $data['order_shipping_charge'] + $data['order_cod_fee'] + $data['order_tax'];
78 -
79 -
80 - $mail_data = $usces->options['mail_data'];
81 - $payment = $usces->getPayments( $data['order_payment_name'] );
82 - $res = false;
83 -
84 - if($_POST['mode'] == 'mitumoriConfirmMail'){
85 - $msg_body = "\r\n\r\n\r\n" . __('Estimate','usces') . "\r\n";
86 - $msg_body .= usces_mail_line( 1, $data['order_email'] );//********************
87 - $msg_body .= apply_filters('usces_filter_order_confirm_mail_first', NULL, $data);
88 - $msg_body .= uesces_get_mail_addressform( 'admin_mail_customer', $customer, $order_id );
89 - $msg_body .= __('estimate number','usces') . " : " . $order_id . "\r\n";
90 - }else{
91 - $msg_body = "\r\n\r\n\r\n" . __('** Article order contents **','usces') . "\r\n";
92 - $msg_body .= usces_mail_line( 1, $data['order_email'] );//********************
93 - $msg_body .= apply_filters('usces_filter_order_confirm_mail_first', NULL, $data);
94 - $msg_body .= uesces_get_mail_addressform( 'admin_mail_customer', $customer, $order_id );
95 - $msg_body .= __('Order number','usces') . " : " . usces_get_deco_order_id( $order_id ) . "\r\n";
96 -//20131129_kitamu_start
97 - $msg_body .= __( 'order date','usces' ) . " : " . $data['order_date'] . "\r\n";
98 -//20131129_kitamu end
99 - }
100 -
101 - $meisai = __('Items','usces') . " : \r\n";
102 - foreach ( (array)$cart as $cart_row ) {
103 - $post_id = $cart_row['post_id'];
104 - $sku = urldecode($cart_row['sku']);
105 - $quantity = $cart_row['quantity'];
106 - $options = $cart_row['options'];
107 - $itemCode = $usces->getItemCode($post_id);
108 - $itemName = $usces->getItemName($post_id);
109 - $cartItemName = $usces->getCartItemName($post_id, $sku);
110 - $skuPrice = $cart_row['price'];
111 -// $pictids = $usces->get_pictids($itemCode);
112 - if (!empty($options)) {
113 -// $optstr = implode(',', $options);
114 - } else {
115 - $optstr = '';
116 - $options = array();
117 - }
118 -
119 - $meisai .= usces_mail_line( 2, $data['order_email'] );//--------------------
120 - $meisai .= "$cartItemName \r\n";
121 - if( is_array($options) && count($options) > 0 ){
122 - $optstr = '';
123 - foreach($options as $key => $value){
124 -//20110629ysk start 0000190
125 - //if( !empty($key) )
126 - // $meisai .= $key . ' : ' . urldecode($value) . "\r\n";
127 - if( !empty($key) ) {
128 - $key = urldecode($key);
129 - if(is_array($value)) {
130 - $c = '';
131 - $optstr .= $key . ' : ';
132 - foreach($value as $v) {
133 - $optstr .= $c.urldecode($v);
134 - $c = ', ';
135 - }
136 - $optstr .= "\r\n";
137 - } else {
138 - $optstr .= $key . ' : ' . urldecode($value) . "\r\n";
139 - }
140 - }
141 -//20110629ysk end
142 - }
143 - $meisai .= apply_filters( 'usces_filter_option_adminmail', $optstr, $options);
144 - }
145 - $meisai .= __('Unit price','usces') . " ".usces_crform( $skuPrice, true, false, 'return' ) . __(' * ','usces') . $cart_row['quantity'] . "\r\n";
146 - }
147 -
148 - $meisai .= usces_mail_line( 3, $data['order_email'] );//====================
149 - $meisai .= __('total items','usces') . " : " . usces_crform( $data['order_item_total_price'], true, false, 'return' ) . "\r\n";
150 -
151 - if ( $data['order_usedpoint'] != 0 )
152 - $meisai .= __('use of points','usces') . " : " . number_format($data['order_usedpoint']) . __('Points','usces') . "\r\n";
153 - if ( $data['order_discount'] != 0 )
154 - $meisai .= apply_filters('usces_confirm_discount_label', __('Campaign disnount', 'usces'), $order_id) . " : " . usces_crform( $data['order_discount'], true, false, 'return' ) . "\r\n";
155 - $meisai .= __('Shipping','usces') . " : " . usces_crform( $data['order_shipping_charge'], true, false, 'return' ) . "\r\n";
156 - if ( $payment['settlement'] == 'COD' )
157 - $meisai .= apply_filters('usces_filter_cod_label', __('COD fee', 'usces')) . " : " . usces_crform( $data['order_cod_fee'], true, false, 'return' ) . "\r\n";
158 - if ( !empty($usces->options['tax_rate']) )
159 - $meisai .= __('consumption tax','usces') . " : " . usces_crform( $data['order_tax'], true, false, 'return' ) . "\r\n";
160 - $meisai .= usces_mail_line( 2, $data['order_email'] );//--------------------
161 - $meisai .= __('Payment amount','usces') . " : " . usces_crform( $total_full_price, true, false, 'return' ) . "\r\n";
162 - $meisai .= usces_mail_line( 2, $data['order_email'] );//--------------------
163 - $meisai .= "(" . __('Currency', 'usces') . ' : ' . __(usces_crcode( 'return' ), 'usces') . ")\r\n\r\n";
164 -
165 - $msg_body .= apply_filters('usces_filter_order_confirm_mail_meisai', $meisai, $data, $cart);
166 -
167 -
168 -
169 - $msg_shipping = __('** A shipping address **','usces') . "\r\n";
170 - $msg_shipping .= usces_mail_line( 1, $data['order_email'] );//********************
171 -
172 - $msg_shipping .= uesces_get_mail_addressform( 'admin_mail', $deli, $order_id );
173 -
174 -//20101208ysk start
175 - //$msg_shipping .= __('Delivery Time','usces') . " : " . $data['order_delivery_time'] . "\r\n";
176 - if ( $data['order_delidue_date'] == NULL || $data['order_delidue_date'] == '#none#' ) {
177 - $msg_shipping .= "\r\n";
178 - }else{
179 - $msg_shipping .= __('Shipping date', 'usces') . " : " . $data['order_delidue_date'] . "\r\n";
180 - $msg_shipping .= __("* A shipment due date is a day to ship an article, and it's not the arrival day.", 'usces') . "\r\n";
181 - $msg_shipping .= "\r\n";
182 - }
183 - $deli_meth = (int)$data['order_delivery_method'];
184 - if( 0 <= $deli_meth ){
185 - $deli_index = $usces->get_delivery_method_index($deli_meth);
186 - if( 0 <= $deli_index ) $msg_shipping .= __('Delivery Method','usces') . " : " . $usces->options['delivery_method'][$deli_index]['name'] . "\r\n";
187 - }
188 - $msg_shipping .= __('Delivery date','usces') . " : " . $data['order_delivery_date'] . "\r\n";
189 - $msg_shipping .= __('Delivery Time','usces') . " : " . $data['order_delivery_time'] . "\r\n";
190 -//20101208ysk end
191 - $msg_shipping .= "\r\n";
192 - $msg_body .= apply_filters('usces_filter_order_confirm_mail_shipping', $msg_shipping, $data);
193 -
194 -// $msg_body .= __('** For some region, to deliver the items in the morning is not possible.','usces') . "\r\n";
195 -// $msg_body .= __('** WE may not always be able to deliver the items on time which you desire.','usces') . " \r\n";
196 -// $msg_body .= usces_mail_line( 2, $data['order_email'] )."\r\n";
197 -
198 - $msg_payment = __('** Payment method **','usces') . "\r\n";
199 - $msg_payment .= usces_mail_line( 1, $data['order_email'] );//********************
200 - $msg_payment .= $payment['name']. "\r\n\r\n";
201 - if( 'orderConfirmMail' == $_POST['mode'] || 'changeConfirmMail' == $_POST['mode'] || 'mitumoriConfirmMail' == $_POST['mode'] || 'otherConfirmMail' == $_POST['mode'] ) {//20130514ysk start 0000524
202 - if ( $payment['settlement'] == 'transferAdvance' || $payment['settlement'] == 'transferDeferred' ) {
203 - $transferee = __('Transfer','usces') . " : \r\n";
204 - $transferee .= $usces->options['transferee'] . "\r\n";
205 - $msg_payment .= apply_filters('usces_filter_mail_transferee', $transferee, $payment);
206 - $msg_payment .= "\r\n".usces_mail_line( 2, $data['order_email'] )."\r\n";//--------------------
207 -//20101018ysk start
208 - } elseif($payment['settlement'] == 'acting_jpayment_conv') {
209 - $args = maybe_unserialize($usces->get_order_meta_value($payment['settlement'], $order_id));
210 - $msg_payment .= __('決済番号', 'usces').' : '.$args['gid']."\r\n";
211 - $msg_payment .= __('決済金額', 'usces').' : '.number_format($args['ta']).__('dollars','usces')."\r\n";
212 - $msg_payment .= __('お支払先', 'usces').' : '.usces_get_conv_name($args['cv'])."\r\n";
213 - $msg_payment .= __('コンビニ受付番号','usces').' : '.$args['no']."\r\n";
214 - if($args['cv'] != '030') {//ファミリーマート以外
215 - $msg_payment .= __('コンビニ受付番号情報URL', 'usces').' : '.$args['cu']."\r\n";
216 - }
217 - $msg_payment .= "\r\n".usces_mail_line( 2, $data['order_email'] )."\r\n";//--------------------
218 - } elseif($payment['settlement'] == 'acting_jpayment_bank') {
219 - $args = maybe_unserialize($usces->get_order_meta_value($payment['settlement'], $order_id));
220 - $msg_payment .= __('決済番号', 'usces').' : '.$args['gid']."\r\n";
221 - $msg_payment .= __('決済金額', 'usces').' : '.number_format($args['ta']).__('dollars','usces')."\r\n";
222 - $bank = explode('.', $args['bank']);
223 - $msg_payment .= __('銀行コード','usces').' : '.$bank[0]."\r\n";
224 - $msg_payment .= __('銀行名','usces').' : '.$bank[1]."\r\n";
225 - $msg_payment .= __('支店コード','usces').' : '.$bank[2]."\r\n";
226 - $msg_payment .= __('支店名','usces').' : '.$bank[3]."\r\n";
227 - $msg_payment .= __('口座種別','usces').' : '.$bank[4]."\r\n";
228 - $msg_payment .= __('口座番号','usces').' : '.$bank[5]."\r\n";
229 - $msg_payment .= __('口座名義','usces').' : '.$bank[6]."\r\n";
230 - $msg_payment .= __('支払期限','usces').' : '.substr($args['exp'], 0, 4).'年'.substr($args['exp'], 4, 2).'月'.substr($args['exp'], 6, 2)."日\r\n";
231 - $msg_payment .= "\r\n".usces_mail_line( 2, $data['order_email'] )."\r\n";//--------------------
232 -//20101018ysk end
233 - }
234 - }//20130514ysk end
235 -
236 - $msg_body .= apply_filters('usces_filter_order_confirm_mail_payment', $msg_payment, $order_id, $payment, $cart, $data);
237 -
238 -//20100818ysk start
239 - $msg_body .= usces_mail_custom_field_info( 'order', '', $order_id, $data['order_email'] );
240 -//20100818ysk end
241 -
242 - $msg_body .= "\r\n";
243 - $msg_body .= __('** Others / a demand **','usces') . "\r\n";
244 - $msg_body .= usces_mail_line( 1, $data['order_email'] );//********************
245 - $msg_body .= $data['order_note'] . "\r\n\r\n";
246 -// $msg_body .= usces_mail_line( 2, $data['order_email'] )."\r\n";//--------------------
247 -// $msg_body .= "\r\n";
248 -
249 -// $msg_body .= __('Please inform it of any questions from [an inquiry].','usces') . "\r\n";
250 -// $msg_body .= usces_mail_line( 2, $data['order_email'] )."\r\n";//--------------------
251 -
252 - $msg_body .= apply_filters('usces_filter_order_confirm_mail_body', NULL, $data);
253 - $msg_body = apply_filters('usces_filter_order_confirm_mail_bodyall', $msg_body, $data);
254 -
255 - switch ( $_POST['mode'] ) {
256 - case 'completionMail':
257 - $message = do_shortcode($mail_data['header']['completionmail']) . apply_filters('usces_filter_order_confirm_mail_body_after', $msg_body, $data) . do_shortcode($mail_data['footer']['completionmail']);
258 - break;
259 - case 'orderConfirmMail':
260 - $message = do_shortcode($mail_data['header']['ordermail']) . apply_filters('usces_filter_order_confirm_mail_body_after', $msg_body, $data) . do_shortcode($mail_data['footer']['ordermail']);
261 - break;
262 - case 'changeConfirmMail':
263 - $message = do_shortcode($mail_data['header']['changemail']) . apply_filters('usces_filter_order_confirm_mail_body_after', $msg_body, $data) . do_shortcode($mail_data['footer']['changemail']);
264 - break;
265 - case 'receiptConfirmMail':
266 - $message = do_shortcode($mail_data['header']['receiptmail']) . apply_filters('usces_filter_order_confirm_mail_body_after', $msg_body, $data) . do_shortcode($mail_data['footer']['receiptmail']);
267 - break;
268 - case 'mitumoriConfirmMail':
269 - $message = do_shortcode($mail_data['header']['mitumorimail']) . apply_filters('usces_filter_order_confirm_mail_body_after', $msg_body, $data) . do_shortcode($mail_data['footer']['mitumorimail']);
270 - break;
271 - case 'cancelConfirmMail':
272 - $message = do_shortcode($mail_data['header']['cancelmail']) . apply_filters('usces_filter_order_confirm_mail_body_after', $msg_body, $data) . do_shortcode($mail_data['footer']['cancelmail']);
273 - break;
274 - case 'otherConfirmMail':
275 - $message = do_shortcode($mail_data['header']['othermail']) . apply_filters('usces_filter_order_confirm_mail_body_after', $msg_body, $data) . do_shortcode($mail_data['footer']['othermail']);
276 - break;
277 - default:
278 - $message = apply_filters( 'usces_filter_order_confirm_mail_body_after', $msg_body, $data );
279 - }
280 - return apply_filters('usces_filter_order_confirm_mail_message', $message, $data);
281 -
282 -}
283 -
284 -function usces_send_ordermail($order_id) {
285 - global $usces, $wpdb;
286 -
287 - $tableName = $wpdb->prefix . "usces_order";
288 - $query = $wpdb->prepare("SELECT * FROM $tableName WHERE ID = %d", $order_id);
289 - $data = $wpdb->get_row( $query, ARRAY_A );
290 -
291 - $cart = $usces->cart->get_cart();
292 - $entry = $usces->cart->get_entry();
293 - $mail_data = $usces->options['mail_data'];
294 - $payment = $usces->getPayments( $entry['order']['payment_name'] );
295 - $res = false;
296 -
297 - $msg_body = "\r\n\r\n\r\n" . __('** content of ordered items **','usces') . "\r\n";
298 - $msg_body .= usces_mail_line( 1, $entry['customer']['mailaddress1'] );//********************
299 - $msg_body .= apply_filters('usces_filter_send_order_mail_first', NULL, $data);
300 -//20110118ysk start
301 - //$msg_body .= usces_mail_custom_field_info( 'customer', 'name_pre', $order_id );
302 -//20110118ysk end
303 - //$msg_body .= __('Buyer','usces') . " : " . sprintf(__('Mr/Mrs %s', 'usces'), usces_localized_name( $entry['customer']['name1'], $entry['customer']['name2'], 'return' )) . "\r\n";
304 - $msg_body .= uesces_get_mail_addressform( 'order_mail_customer', $entry, $order_id );
305 -//20110118ysk start
306 - //$msg_body .= usces_mail_custom_field_info( 'customer', 'name_after', $order_id );
307 -//20110118ysk end
308 - $msg_body .= __('Order number','usces') . " : " . usces_get_deco_order_id( $order_id ) . "\r\n";
309 -
310 - $meisai = __('Items','usces') . " : \r\n";
311 -//20131129_kitamu start
312 - $msg_body .= __( 'order date','usces' ) . " : " . $data['order_date'] . "\r\n";
313 -//20131129_kitamu end
314 - foreach ( $cart as $cart_row ) {
315 - $post_id = $cart_row['post_id'];
316 - $sku = urldecode($cart_row['sku']);
317 - $quantity = $cart_row['quantity'];
318 - $options = $cart_row['options'];
319 - $itemCode = $usces->getItemCode($post_id);
320 - $itemName = $usces->getItemName($post_id);
321 - $cartItemName = $usces->getCartItemName($post_id, $sku);
322 - $skuPrice = $cart_row['price'];
323 -// $pictids = $usces->get_pictids($itemCode);
324 - if (!empty($options)) {
325 -// $optstr = implode(',', $options);
326 - } else {
327 - $optstr = '';
328 - $options = array();
329 - }
330 -
331 - $meisai .= usces_mail_line( 2, $entry['customer']['mailaddress1'] );//--------------------
332 - $meisai .= "$cartItemName \r\n";
333 - if( is_array($options) && count($options) > 0 ){
334 - $optstr = '';
335 - foreach($options as $key => $value){
336 -//20110629ysk start 0000190
337 - //if( !empty($key) )
338 - // $meisai .= $key . ' : ' . urldecode($value) . "\r\n";
339 - if( !empty($key) ) {
340 - $key = urldecode($key);
341 - if(is_array($value)) {
342 - $c = '';
343 - $optstr .= $key. ' : ';
344 - foreach($value as $v) {
345 - $optstr .= $c.urldecode($v);
346 - $c = ', ';
347 - }
348 - $optstr .= "\r\n";
349 - } else {
350 - $optstr .= $key . ' : ' . urldecode($value) . "\r\n";
351 - }
352 - }
353 -//20110629ysk end
354 - }
355 - $meisai .= apply_filters( 'usces_filter_option_ordermail', $optstr, $options);
356 - }
357 - $meisai .= __('Unit price','usces') . " ".usces_crform( $skuPrice, true, false, 'return' ) . __(' * ','usces') . $cart_row['quantity'] . "\r\n";
358 - }
359 - $meisai .= usces_mail_line( 3, $entry['customer']['mailaddress1'] );//====================
360 - $meisai .= __('total items','usces') . " : " . usces_crform( $entry['order']['total_items_price'], true, false, 'return' ) . "\r\n";
361 -
362 - if ( $entry['order']['usedpoint'] != 0 )
363 - $meisai .= __('use of points','usces') . " : " . number_format($entry['order']['usedpoint']) . __('Points','usces') . "\r\n";
364 -//20120308ysk start 0000433
365 - //if ( $data['order_discount'] != 0 )
366 - if ( $entry['order']['discount'] != 0 )
367 -//20120308ysk end
368 - $meisai .= apply_filters('usces_confirm_discount_label', __('Campaign disnount', 'usces'), $order_id) . " : " . usces_crform( $entry['order']['discount'], true, false, 'return' ) . "\r\n";
369 - $meisai .= __('Shipping','usces') . " : " . usces_crform( $entry['order']['shipping_charge'], true, false, 'return' ) . "\r\n";
370 - if ( $payment['settlement'] == 'COD' )
371 - $meisai .= apply_filters('usces_filter_cod_label', __('COD fee', 'usces')) . " : " . usces_crform( $entry['order']['cod_fee'], true, false, 'return' ) . "\r\n";
372 - if ( !empty($usces->options['tax_rate']) )
373 - $meisai .= __('consumption tax','usces') . " : " . usces_crform( $entry['order']['tax'], true, false, 'return' ) . "\r\n";
374 - $meisai .= usces_mail_line( 2, $entry['customer']['mailaddress1'] );//--------------------
375 - $meisai .= __('Payment amount','usces') . " : " . usces_crform( $entry['order']['total_full_price'], true, false, 'return' ) . "\r\n";
376 - $meisai .= usces_mail_line( 2, $entry['customer']['mailaddress1'] );//--------------------
377 - $meisai .= "(" . __('Currency', 'usces') . ' : ' . __(usces_crcode( 'return' ), 'usces') . ")\r\n\r\n";
378 -
379 -//20120308ysk start 0000433
380 - //$msg_body .= apply_filters('usces_filter_send_order_mail_meisai', $meisai, $data);
381 - $msg_body .= apply_filters('usces_filter_send_order_mail_meisai', $meisai, $data, $cart, $entry);
382 -//20120308ysk end
383 -
384 -
385 - $msg_shipping = __('** A shipping address **','usces') . "\r\n";
386 - $msg_shipping .= usces_mail_line( 1, $entry['customer']['mailaddress1'] );//********************
387 -
388 - $msg_shipping .= uesces_get_mail_addressform( 'order_mail', $entry, $order_id );
389 -
390 -//20101208ysk start
391 - //$msg_shipping .= __('Delivery Time','usces') . " : " . $entry['order']['delivery_time'] . "\r\n";
392 - $deli_meth = (int)$entry['order']['delivery_method'];
393 - if( 0 <= $deli_meth ){
394 - $deli_index = $usces->get_delivery_method_index($deli_meth);
395 - if( 0 <= $deli_index ) $msg_shipping .= __('Delivery Method','usces') . " : " . $usces->options['delivery_method'][$deli_index]['name'] . "\r\n";
396 - }
397 - $msg_shipping .= __('Delivery date','usces') . " : " . $entry['order']['delivery_date'] . "\r\n";
398 - $msg_shipping .= __('Delivery Time','usces') . " : " . $entry['order']['delivery_time'] . "\r\n";
399 -//20101208ysk end
400 -// $msg_body .= usces_mail_line( 2, $entry['customer']['mailaddress1'] );//--------------------
401 -// $msg_body .= __('** For some region, to deliver the items in the morning is not possible.','usces') . "\r\n";
402 -// $msg_body .= " " . __('** WE may not always be able to deliver the items on time which you desire.','usces') . "\r\n";
403 -// $msg_body .= usces_mail_line( 2, $entry['customer']['mailaddress1'] )."\r\n";//--------------------
404 - $msg_shipping .= "\r\n";
405 - $msg_body .= apply_filters('usces_filter_send_order_mail_shipping', $msg_shipping, $data);
406 -
407 - $msg_payment = __('** Payment method **','usces') . "\r\n";
408 - $msg_payment .= usces_mail_line( 1, $entry['customer']['mailaddress1'] );//********************
409 - $msg_payment .= $payment['name'] . usces_payment_detail($entry) . "\r\n\r\n";
410 - if ( $payment['settlement'] == 'transferAdvance' || $payment['settlement'] == 'transferDeferred' ) {
411 - $transferee = __('Transfer','usces') . " : \r\n";
412 - $transferee .= $usces->options['transferee'] . "\r\n";
413 - $msg_payment .= apply_filters('usces_filter_mail_transferee', $transferee, $payment);
414 - $msg_payment .= "\r\n".usces_mail_line( 2, $entry['customer']['mailaddress1'] )."\r\n";//--------------------
415 -//20101018ysk start
416 - } elseif($payment['settlement'] == 'acting_jpayment_conv') {
417 - $args = maybe_unserialize($usces->get_order_meta_value($payment['settlement'], $order_id));
418 - $msg_payment .= __('決済番号', 'usces').' : '.$args['gid']."\r\n";
419 - $msg_payment .= __('決済金額', 'usces').' : '.number_format($args['ta']).__('dollars','usces')."\r\n";
420 - $msg_payment .= __('お支払先', 'usces').' : '.usces_get_conv_name($args['cv'])."\r\n";
421 - $msg_payment .= __('コンビニ受付番号','usces').' : '.$args['no']."\r\n";
422 - if($args['cv'] != '030') {//ファミリーマート以外
423 - $msg_payment .= __('コンビニ受付番号情報URL', 'usces').' : '.$args['cu']."\r\n";
424 - }
425 - $msg_payment .= "\r\n".usces_mail_line( 2, $entry['customer']['mailaddress1'] )."\r\n";//--------------------
426 - } elseif($payment['settlement'] == 'acting_jpayment_bank') {
427 - $args = maybe_unserialize($usces->get_order_meta_value($payment['settlement'], $order_id));
428 - $msg_payment .= __('決済番号', 'usces').' : '.$args['gid']."\r\n";
429 - $msg_payment .= __('決済金額', 'usces').' : '.number_format($args['ta']).__('dollars','usces')."\r\n";
430 - $bank = explode('.', $args['bank']);
431 - $msg_payment .= __('銀行コード','usces').' : '.$bank[0]."\r\n";
432 - $msg_payment .= __('銀行名','usces').' : '.$bank[1]."\r\n";
433 - $msg_payment .= __('支店コード','usces').' : '.$bank[2]."\r\n";
434 - $msg_payment .= __('支店名','usces').' : '.$bank[3]."\r\n";
435 - $msg_payment .= __('口座種別','usces').' : '.$bank[4]."\r\n";
436 - $msg_payment .= __('口座番号','usces').' : '.$bank[5]."\r\n";
437 - $msg_payment .= __('口座名義','usces').' : '.$bank[6]."\r\n";
438 - $msg_payment .= __('支払期限','usces').' : '.substr($args['exp'], 0, 4).'年'.substr($args['exp'], 4, 2).'月'.substr($args['exp'], 6, 2)."日\r\n";
439 - $msg_payment .= "\r\n".usces_mail_line( 2, $entry['customer']['mailaddress1'] )."\r\n";//--------------------
440 -//20101018ysk end
441 - }
442 -
443 - $msg_body .= apply_filters('usces_filter_send_order_mail_payment', $msg_payment, $order_id, $payment, $cart, $entry, $data);
444 -
445 -//20100818ysk start
446 - $msg_body .= usces_mail_custom_field_info( 'order', '', $order_id );
447 -//20100818ysk end
448 -
449 - $msg_body .= "\r\n";
450 - $msg_body .= __('** Others / a demand **','usces') . "\r\n";
451 - $msg_body .= usces_mail_line( 1, $entry['customer']['mailaddress1'] );//********************
452 - $msg_body .= $entry['order']['note'] . "\r\n\r\n";
453 -// $msg_body .= usces_mail_line( 2, $entry['customer']['mailaddress1'] )."\r\n";//--------------------
454 -// $msg_body .= "\r\n";
455 -
456 -// $msg_body .= __('I will inform it of shipment completion by an email.','usces') . "\r\n";
457 -// $msg_body .= __('Please inform it of any questions from [an inquiry].','usces') . "\r\n";
458 -// $msg_body .= usces_mail_line( 2, $entry['customer']['mailaddress1'] )."\r\n";//--------------------
459 -
460 - $msg_body .= apply_filters('usces_filter_send_order_mail_body', NULL, $data);
461 - $msg_body = apply_filters('usces_filter_send_order_mail_bodyall', $msg_body, $data);
462 -
463 - $subject = apply_filters('usces_filter_send_order_mail_subject_thankyou', $mail_data['title']['thankyou'], $data);
464 - $message = do_shortcode($mail_data['header']['thankyou']) . $msg_body . do_shortcode($mail_data['footer']['thankyou']);
465 -//var_dump($msg_body);exit;
466 - $confirm_para = array(
467 - 'to_name' => sprintf(__('Mr/Mrs %s', 'usces'), ($entry["customer"]["name1"] . ' ' . $entry["customer"]["name2"])),
468 - 'to_address' => $entry['customer']['mailaddress1'],
469 - 'from_name' => get_option('blogname'),
470 - 'from_address' => $usces->options['sender_mail'],
471 - 'return_path' => $usces->options['sender_mail'],
472 - 'subject' => $subject,
473 - 'message' => $message
474 - );
475 - $confirm_para = apply_filters( 'usces_send_ordermail_para_to_customer', $confirm_para, $entry, $data);
476 -
477 - //if ( usces_send_mail( $confirm_para ) ) {
478 - usces_send_mail( $confirm_para );
479 -
480 - $subject = apply_filters('usces_filter_send_order_mail_subject_order', $mail_data['title']['order'], $data);
481 - $message = do_shortcode($mail_data['header']['order']) . $msg_body
482 - . $mail_data['footer']['order']
483 - . "\n----------------------------------------------------\n"
484 - . "REMOTE_ADDR : " . $_SERVER['REMOTE_ADDR']
485 - . "\n----------------------------------------------------\n";
486 -
487 - $order_para = array(
488 - 'to_name' => __('An order email','usces'),
489 - 'to_address' => $usces->options['order_mail'],
490 - 'from_name' => sprintf(__('Mr/Mrs %s', 'usces'), ($entry["customer"]["name1"] . ' ' . $entry["customer"]["name2"])),
491 - 'from_address' => $entry['customer']['mailaddress1'],
492 - 'return_path' => $usces->options['error_mail'],
493 - 'subject' => $subject,
494 - 'message' => $message
495 - );
496 -
497 - $order_para = apply_filters( 'usces_send_ordermail_para_to_manager', $order_para, $entry, $data);
498 - $res = usces_send_mail( $order_para );
499 -
500 -// }
501 -
502 - return $res;
503 -
504 -}
505 -
506 -
507 -function usces_send_inquirymail() {
508 - global $usces;
509 - $_POST = $usces->stripslashes_deep_post($_POST);
510 - $res = false;
511 - $mail_data = $usces->options['mail_data'];
512 - $inq_name = trim($_POST["inq_name"]);
513 - $inq_contents = trim($_POST["inq_contents"]);
514 - $inq_mailaddress = trim($_POST["inq_mailaddress"]);
515 - $reserve = '';
516 - if(isset($_POST['reserve'])){
517 - foreach($_POST['reserve'] as $key => $value){
518 - $reserve .= $key . " : " . $value . "\r\n";
519 - }
520 - }
521 - $mats = compact('inq_name','inq_contents','inq_mailaddress','reserve','mail_data');
522 - $subject = apply_filters( 'usces_filter_inquiry_subject_to_customer', $mail_data['title']['inquiry'],$mats);
523 - $message = apply_filters( 'usces_filter_inquiry_header', $mail_data['header']['inquiry'], $inq_name, $inq_mailaddress ) . "\r\n\r\n";
524 - $message .= apply_filters( 'usces_filter_inquiry_reserve', $reserve, $inq_name, $inq_mailaddress );
525 - $message .= apply_filters( 'usces_filter_inq_contents', $inq_contents, $inq_name, $inq_mailaddress ) . "\r\n\r\n";
526 - $message .= apply_filters( 'usces_filter_inq_footer', $mail_data['footer']['inquiry'], $inq_name, $inq_mailaddress );
527 - do_action( 'usces_action_presend_inquiry_mail', $message, $inq_name, $inq_mailaddress );
528 -
529 - $para1 = array(
530 - 'to_name' => sprintf(__('Mr/Mrs %s', 'usces'), $inq_name),
531 - 'to_address' => $inq_mailaddress,
532 - 'from_name' => get_option('blogname'),
533 - 'from_address' => $usces->options['sender_mail'],
534 - 'return_path' => $usces->options['sender_mail'],
535 - 'subject' => $subject,
536 - 'message' => do_shortcode($message),
537 - );
538 -
539 - $res0 = usces_send_mail( $para1 );
540 - if ( $res0 ) {
541 -
542 - $subject = apply_filters( 'usces_filter_inquiry_subject_to_manager', __('** An inquiry **','usces').'('.$inq_name.')',$mats);
543 - $message = $reserve . $_POST['inq_contents'] . "\r\n"
544 - . "\n----------------------------------------------------\n"
545 - . "REMOTE_ADDR : " . $_SERVER['REMOTE_ADDR']
546 - . "\n----------------------------------------------------\n";
547 -
548 - $para2 = array(
549 - 'to_name' => __('An inquiry email','usces'),
550 - 'to_address' => $usces->options['inquiry_mail'],
551 - 'from_name' => sprintf(__('Mr/Mrs %s', 'usces'), $inq_name),
552 - 'from_address' => $inq_mailaddress,
553 - 'return_path' => $usces->options['error_mail'],
554 - 'subject' => $subject,
555 - 'message' => do_shortcode($message),
556 - );
557 - sleep(1);
558 - $res = usces_send_mail( $para2 );
559 -
560 - }
561 -
562 - return $res;
563 -
564 -}
565 -
566 -function usces_send_regmembermail($user) {
567 - global $usces;
568 - $res = false;
569 - $mail_data = $usces->options['mail_data'];
570 - $newmem_admin_mail = $usces->options['newmem_admin_mail'];
571 - $name = usces_localized_name(trim($user['name1']), trim($user['name2']), 'return');
572 - $mailaddress1 = trim($user['mailaddress1']);
573 -
574 - $subject = $mail_data['title']['membercomp'];
575 - $message = $mail_data['header']['membercomp'];
576 - $message .= __('Registration contents', 'usces')."\r\n";
577 - $message .= '--------------------------------'."\r\n";
578 - $message .= __('Member ID', 'usces') . ' : ' . $user['ID'] . "\r\n";
579 - $message .= __('Name', 'usces') . ' : ' . sprintf(__('Mr/Mrs %s', 'usces'), $name) . "\r\n";
580 - $message .= __('e-mail adress', 'usces') . ' : ' . $mailaddress1."\r\n";
581 - $message .= '--------------------------------'."\r\n\r\n";
582 - $message .= $mail_data['footer']['membercomp'];
583 - $message = apply_filters('usces_filter_send_regmembermail_message', $message, $user);
584 -
585 - $para1 = array(
586 - 'to_name' => sprintf(__('Mr/Mrs %s', 'usces'), $name),
587 - 'to_address' => $mailaddress1,
588 - 'from_name' => get_option('blogname'),
589 - 'from_address' => $usces->options['sender_mail'],
590 - 'return_path' => $usces->options['sender_mail'],
591 - 'subject' => $subject,
592 - 'message' => do_shortcode($message),
593 - );
594 - $para1 = apply_filters( 'usces_filter_send_regmembermail_para1', $para1 );
595 - $res = usces_send_mail( $para1 );
596 -
597 - if($newmem_admin_mail){
598 -
599 - $subject = __('New sign-in processing was completed.', 'usces');
600 - $message = __('New sign-in processing was completed.', 'usces') . "\r\n\r\n";
601 - $message .= __('Registration contents', 'usces')."\r\n";
602 - $message .= '--------------------------------'."\r\n";
603 - $message .= __('Member ID', 'usces') . ' : ' . $user['ID'] . "\r\n";
604 - $message .= __('Name', 'usces') . ' : ' . sprintf(__('Mr/Mrs %s', 'usces'), $name) . "\r\n";
605 - $message .= __('e-mail adress', 'usces') . ' : ' . $mailaddress1."\r\n";
606 - $message .= '--------------------------------'."\r\n\r\n";
607 - $message = apply_filters('usces_filter_send_regmembermail_notice', $message, $user);
608 -
609 - $para2 = array(
610 - 'to_name' => __('Notice of new sign-in', 'usces'),
611 - 'to_address' => $usces->options['order_mail'],
612 - 'from_name' => get_option('blogname'),
613 - 'from_address' => $usces->options['sender_mail'],
614 - 'return_path' => $usces->options['sender_mail'],
615 - 'subject' => $subject,
616 - 'message' => do_shortcode($message),
617 - );
618 - $para2 = apply_filters( 'usces_filter_send_regmembermail_para2', $para2 );
619 - usces_send_mail( $para2 );
620 - }
621 -
622 - return $res;
623 -
624 -}
625 -
626 -function usces_send_delmembermail( $user ) {
627 - global $usces;
628 - $res = true;
629 - $mail_data = $usces->options['mail_data'];
630 - $delmem_admin_mail = $usces->options['delmem_admin_mail'];
631 - $delmem_customer_mail = $usces->options['delmem_customer_mail'];
632 - $name = usces_localized_name(trim($user['name1']), trim($user['name2']), 'return');
633 - $mailaddress1 = trim($user['mailaddress1']);
634 - $subject = apply_filters( 'usces_filter_send_delmembermail_subject', __('Member removal processing was completed.', 'usces'), $user );
635 -
636 - if( $delmem_customer_mail ) {
637 - $message = $subject."\r\n\r\n";
638 - $message .= __('Registration contents', 'usces')."\r\n";
639 - $message .= '--------------------------------'."\r\n";
640 - $message .= __('Member ID', 'usces').' : '.$user['ID']."\r\n";
641 - $message .= __('Name', 'usces').' : '.sprintf(__('Mr/Mrs %s', 'usces'), $name)."\r\n";
642 - $message .= __('e-mail adress', 'usces').' : '.$mailaddress1."\r\n";
643 - $message .= '--------------------------------'."\r\n\r\n";
644 - $message .= $mail_data['footer']['membercomp'];
645 - $message = apply_filters( 'usces_filter_send_delmembermail_message', $message, $user );
646 -
647 - $para1 = array(
648 - 'to_name' => sprintf(__('Mr/Mrs %s', 'usces'), $name),
649 - 'to_address' => $mailaddress1,
650 - 'from_name' => get_option('blogname'),
651 - 'from_address' => $usces->options['sender_mail'],
652 - 'return_path' => $usces->options['sender_mail'],
653 - 'subject' => $subject,
654 - 'message' => do_shortcode($message),
655 - );
656 - $para1 = apply_filters( 'usces_filter_send_delmembermail_para1', $para1 );
657 - $res = usces_send_mail( $para1 );
658 - }
659 -
660 - if( $delmem_admin_mail ) {
661 - $message = $subject."\r\n\r\n";
662 - $message .= __('Registration contents', 'usces')."\r\n";
663 - $message .= '--------------------------------'."\r\n";
664 - $message .= __('Member ID', 'usces').' : '.$user['ID']."\r\n";
665 - $message .= __('Name', 'usces').' : '.sprintf(__('Mr/Mrs %s', 'usces'), $name)."\r\n";
666 - $message .= __('e-mail adress', 'usces') . ' : '.$mailaddress1."\r\n";
667 - $message .= '--------------------------------'."\r\n\r\n";
668 - $message = apply_filters( 'usces_filter_send_delmembermail_notice', $message, $user );
669 -
670 - $para2 = array(
671 - 'to_name' => __('Notice of new sign-in', 'usces'),
672 - 'to_address' => $usces->options['order_mail'],
673 - 'from_name' => get_option('blogname'),
674 - 'from_address' => $usces->options['sender_mail'],
675 - 'return_path' => $usces->options['sender_mail'],
676 - 'subject' => $subject,
677 - 'message' => do_shortcode($message),
678 - );
679 - $para2 = apply_filters( 'usces_filter_send_delmembermail_para2', $para2 );
680 - $res = usces_send_mail( $para2 );
681 - }
682 - return $res;
683 -}
684 -
685 -function usces_lostmail($url) {
686 - global $usces;
687 - $res = false;
688 -
689 - $mail_data = $usces->options['mail_data'];
690 - $subject = apply_filters( 'usces_filter_lostmail_subject', __('Change password','usces') );
691 - $message = __('Please, click the following URL, and please change a password.','usces') . "\n\r\n\r\n\r"
692 - . $url . "\n\r\n\r\n\r"
693 - . "-----------------------------------------------------\n\r"
694 - . __('If you have not requested this email please kindly ignore and delete it.','usces') . "\n\r"
695 - . "-----------------------------------------------------\n\r\n\r\n\r";
696 - $message = apply_filters( 'usces_filter_lostmail_message', $message, $url );
697 - $message .= apply_filters( 'usces_filter_lostmail_footer', $mail_data['footer']['othermail'] );
698 -
699 -
700 - $para1 = array(
701 - 'to_name' => sprintf(__('Mr/Mrs %s', 'usces'), $_SESSION["usces_lostmail"]),
702 - 'to_address' => $_SESSION["usces_lostmail"],
703 - 'from_name' => get_option('blogname'),
704 - 'from_address' => $usces->options['sender_mail'],
705 - 'return_path' => $usces->options['sender_mail'],
706 - 'subject' => $subject,
707 - 'message' => do_shortcode($message),
708 - );
709 -
710 - $para1 = apply_filters( 'usces_filter_send_lostmail_para1', $para1 );
711 - $res = usces_send_mail( $para1 );
712 -
713 - if($res === false) {
714 - $usces->error_message = __('Error: I was not able to transmit an email.','usces');
715 - $page = 'lostmemberpassword';
716 - } else {
717 - $page = 'lostcompletion';
718 - }
719 -
720 - return $page;
721 -
722 -}
723 -
724 -//20100818ysk start
725 -//function usces_mail_custom_field_info( $custom_field, $position, $id ) {
726 -function usces_mail_custom_field_info( $custom_field, $position, $id, $mailaddress = '' ) {
727 - global $usces;
728 -
729 - $msg_body = '';
730 - switch($custom_field) {
731 - case 'order':
732 - $field = 'usces_custom_order_field';
733 - $cs = 'csod_';
734 - break;
735 - case 'customer':
736 - $field = 'usces_custom_customer_field';
737 - $cs = 'cscs_';
738 - break;
739 - case 'delivery':
740 - $field = 'usces_custom_delivery_field';
741 - $cs = 'csde_';
742 - break;
743 - case 'member':
744 - $field = 'usces_custom_member_field';
745 - $cs = 'csmb_';
746 - break;
747 - default:
748 - return $msg_body;
749 - }
750 -
751 - $meta = usces_has_custom_field_meta($custom_field);
752 -
753 - if(!empty($meta) and is_array($meta)) {
754 - $keys = array_keys($meta);
755 - switch($custom_field) {
756 - case 'order':
757 - $msg_body .= "\r\n";
758 - $msg_body .= usces_mail_line( 1, $mailaddress );
759 - foreach($keys as $key) {
760 - $value = maybe_unserialize($usces->get_order_meta_value($cs.$key, $id));
761 - if(is_array($value)) {
762 - $concatval = '';
763 - $c = '';
764 - foreach($value as $v) {
765 - $concatval .= $c.$v;
766 - $c = ', ';
767 - }
768 - $value = $concatval;
769 - }
770 - $msg_body .= $meta[$key]['name']." : ".$value."\r\n";
771 - }
772 - $msg_body .= usces_mail_line( 1, $mailaddress );
773 - break;
774 -
775 - case 'customer':
776 - case 'delivery':
777 - foreach($keys as $key) {
778 - if($meta[$key]['position'] == $position) {
779 - $value = maybe_unserialize($usces->get_order_meta_value($cs.$key, $id));
780 - if(is_array($value)) {
781 - $concatval = '';
782 - $c = '';
783 - foreach($value as $v) {
784 - $concatval .= $c.$v;
785 - $c = ', ';
786 - }
787 - $value = $concatval;
788 - }
789 - $msg_body .= $meta[$key]['name']." : ".$value."\r\n";
790 - }
791 - }
792 - break;
793 -
794 - case 'member':
795 - foreach($keys as $key) {
796 - if($meta[$key]['position'] == $position) {
797 - $value = maybe_unserialize($usces->get_member_meta_value($cs.$key, $id));
798 - if(is_array($value)) {
799 - $concatval = '';
800 - $c = '';
801 - foreach($value as $v) {
802 - $concatval .= $c.$v;
803 - $c = ', ';
804 - }
805 - $value = $concatval;
806 - }
807 - $msg_body .= $meta[$key]['name']." : ".$value."\r\n";
808 - }
809 - }
810 - break;
811 - }
812 - }
813 - $msg_body = apply_filters('usces_filter_mail_custom_field_info', $msg_body, $custom_field, $position, $id, $mailaddress);
814 - return $msg_body;
815 -}
816 -//20100818ysk end
817 -
818 -//function usces_send_receipted_mail( $order_id, $acting ) {
819 -// global $usces;
820 -// $res = false;
821 -//
822 -// $subject = __('Change password','usces');
823 -// $message = __('Please, click the following URL, and please change a password.','usces') . "\n\r\n\r\n\r"
824 -// . $url . "\n\r\n\r\n\r"
825 -// . "-----------------------------------------------------\n\r"
826 -// . __('I seem to have you cancel it when the body does not have memorizing to this email.','usces') . "\n\r"
827 -// . "-----------------------------------------------------\n\r\n\r\n\r"
828 -// . $usces->options['mail_data']['footer']['footerlogo'];
829 -//
830 -// $para1 = array(
831 -// 'to_name' => sprintf(__('Mr/Mrs %s', 'usces'), $_SESSION["usces_lostmail"]),
832 -// 'to_address' => $_SESSION["usces_lostmail"],
833 -// 'from_name' => get_bloginfo('name'),
834 -// 'from_address' => $usces->options['sender_mail'],
835 -// 'return_path' => $usces->options['error_mail'],
836 -// 'subject' => $subject,
837 -// 'message' => $message
838 -// );
839 -//
840 -// $res = usces_send_mail( $para1 );
841 -//
842 -// if($res === false) {
843 -// $usces->error_message = __('Error: I was not able to transmit an email.','usces');
844 -// $page = 'lostmemberpassword';
845 -// } else {
846 -// $page = 'lostcompletion';
847 -// }
848 -//
849 -// return $page;
850 -//
851 -//}
852 -
853 -function usces_send_mail( $para ) {
854 - global $usces;
855 -
856 - $from_name = $para['from_name'];
857 - $from_address = $para['from_address'];
858 - if (strpos($para['from_address'], '..') !== false || strpos($para['from_address'], '.@') !== false) {
859 - $fname = str_replace(strstr($para['from_address'], '@'), '', $para['from_address']);
860 - if( '"' != substr($fname, 0, 1) && '"' != substr($fname, -1) ){
861 - $para['from_address'] = str_replace($fname, '"RFC_violation"', $para['from_address']);
862 - $from_name = $para['from_name'] . '(' . $from_address . ')';
863 - }
864 - }
865 - $from = htmlspecialchars(html_entity_decode($from_name, ENT_QUOTES)) . " <{$para['from_address']}>";
866 - $header = "From: " . apply_filters('usces_filter_send_mail_from', $from, $para) . "\r\n";
867 - $header .= "Return-Path: {$para['return_path']}\r\n";
868 -
869 - $subject = html_entity_decode($para['subject'], ENT_QUOTES);
870 - $message = $para['message'];
871 -
872 - ini_set( "SMTP", "{$usces->options['smtp_hostname']}" );
873 - if( !ini_get( "smtp_port" ) ){
874 - ini_set( "smtp_port", apply_filters('usces_filter_send_mail_port', 25, $para) );
875 - }
876 - ini_set( "sendmail_from", "" );
877 -
878 - $mails = explode( ',', $para['to_address'] );
879 - $to_mailes = array();
880 - foreach( $mails as $mail ){
881 - if (strpos($mail, '..') !== false || strpos($mail, '.@') !== false) {
882 - $name = str_replace(strstr($mail, '@'), '', $mail);
883 - if( '"' != substr($name, 0, 1) && '"' != substr($name, -1) ){
884 - $to_mailes[] = str_replace($name, '"'.$name.'"', $mail);
885 - }else{
886 - $to_mailes[] = $mail;
887 - }
888 - }elseif( is_email( trim($mail) ) ){
889 - $to_mailes[] = $mail;
890 - }else{
891 - $to_mailes[] = NULL;
892 - }
893 - }
894 -
895 - if( !empty( $to_mailes ) ){
896 - $res = @wp_mail( $to_mailes , $subject , $message, $header );
897 - }else{
898 - $res = false;
899 - }
900 -
901 - return $res;
902 -
903 -}
904 -
905 -function usces_send_mail2( $para ) {
906 - global $usces;
907 -
908 - $usces->mail_para = $para;
909 - add_action('phpmailer_init','usces_send_mail_init', 11);
910 -
911 -// $from = htmlspecialchars(html_entity_decode($para['from_name'], ENT_QUOTES)) . " <{$para['from_address']}>";
912 -// $header = "From: " . apply_filters('usces_filter_send_mail_from', $from, $para) . "\r\n";
913 -// $header .= "Return-Path: {$para['return_path']}\r\n";
914 -
915 - $subject = html_entity_decode($para['subject'], ENT_QUOTES);
916 - $message = $para['message'];
917 -
918 -// ini_set( "SMTP", "{$usces->options['smtp_hostname']}" );
919 -// if( !ini_get( "smtp_port" ) ){
920 -// ini_set( "smtp_port", apply_filters('usces_filter_send_mail_port', 25, $para) );
921 -// }
922 -// ini_set( "sendmail_from", "" );
923 -
924 - $mails = explode( ',', $para['to_address'] );
925 - $to_mailes = array();
926 - foreach( $mails as $mail ){
927 - if( is_email( trim($mail) ) ){
928 - $to_mailes[] = $mail;
929 - }
930 - }
931 - if( !empty( $to_mailes ) ){
932 - $res = @wp_mail( $to_mailes , $subject , $message );
933 - }else{
934 - $res = false;
935 - }
936 -//usces_log('mail : '.print_r($res, true), 'acting_transaction.log');
937 -
938 - remove_action('phpmailer_init','usces_send_mail_init', 11);
939 - $usces->mail_para = array();
940 - return $res;
941 -
942 -}
943 -
944 -function usces_send_mail_init($phpmailer){
945 - global $usces;
946 -
947 - $phpmailer->Mailer = 'mail';
948 - $phpmailer->From = $usces->mail_para['from_address'];
949 - $phpmailer->FromName = apply_filters('usces_filter_send_mail_from', $usces->mail_para['from_name'], $usces->mail_para);
950 - $phpmailer->Sender = $usces->mail_para['from_address'];
951 -
952 -// $phpmailer->Mailer = 'smtp';
953 -// $phpmailer->SMTPSecure = '';
954 -// $phpmailer->Host = 'sample.com';
955 -// $phpmailer->Port = 25;
956 -// $phpmailer->SMTPAuth = true;
957 -// $phpmailer->Username = 'sample@sample.com';
958 -// $phpmailer->Password = 'password';
959 -
960 - do_action('usces_filter_phpmailer_init', array( &$phpmailer ));
961 -}
962 -
963 -function usces_reg_orderdata( $results = array() ) {
964 - global $wpdb, $usces;
965 -// $wpdb->show_errors();
966 -
967 - $options = get_option('usces');
968 - $cart = $usces->cart->get_cart();
969 - $entry = $usces->cart->get_entry();
970 - if( empty($cart) ){
971 - usces_log('reg_orderdata : Session is empty.', 'database_error.log');
972 - return 0;
973 - }
974 - if( (empty($entry['customer']['name1']) && empty($entry['customer']['name2'])) || empty($entry['customer']['mailaddress1']) || empty($entry) || empty($cart) ) return '1';//20131121ysk
975 -
976 - $charging_type = $usces->getItemChargingType($cart[0]['post_id']);
977 -
978 - $item_total_price = $usces->get_total_price( $cart );
979 - $member = $usces->get_member();
980 - $order_table_name = $wpdb->prefix . "usces_order";
981 - $order_table_meta_name = $wpdb->prefix . "usces_order_meta";
982 - $member_table_name = $wpdb->prefix . "usces_member";
983 - $set = $usces->getPayments( $entry['order']['payment_name'] );
984 - $status = '';
985 - if( 'continue' == $charging_type ){
986 - $order_modified = substr(get_date_from_gmt(gmdate('Y-m-d H:i:s', time())), 0, 10);
987 - }else{
988 -//20131121ysk start
989 - //$status = ( $set['settlement'] == 'transferAdvance' || $set['settlement'] == 'transferDeferred' || $set['settlement'] == 'acting_remise_conv' || $set['settlement'] == 'acting_zeus_bank' || $set['settlement'] == 'acting_zeus_conv' || $set['settlement'] == 'acting_jpayment_conv' || $set['settlement'] == 'acting_jpayment_bank' || $set['settlement'] == 'acting_sbps_conv' || $set['settlement'] == 'acting_sbps_payeasy' || $set['settlement'] == 'acting_digitalcheck_conv' || $set['settlement'] == 'acting_mizuho_conv1' || $set['settlement'] == 'acting_mizuho_conv2' ) ? 'noreceipt' : '';
990 - $noreceipt_status_table = apply_filters( 'usces_filter_noreceipt_status', array( 'transferAdvance', 'transferDeferred', 'acting_remise_conv', 'acting_zeus_bank', 'acting_zeus_conv', 'acting_jpayment_conv', 'acting_jpayment_bank', 'acting_sbps_conv', 'acting_sbps_payeasy', 'acting_digitalcheck_conv', 'acting_mizuho_conv1', 'acting_mizuho_conv2', 'acting_veritrans_conv' ) );
991 - $status = ( in_array( $set['settlement'], $noreceipt_status_table ) ) ? 'noreceipt' : '';
992 - $order_modified = NULL;
993 - }
994 - //$payments = $usces->getPayments($entry['order']['payment_name']);
995 - //if( isset($results['payment_status']) && $results['payment_status'] != 'Completed' && $payments['module'] == 'paypal.php') $status = 'pending';
996 - if( $set['module'] == 'paypal.php' || $set['settlement'] == 'acting_paypal_ec' ) {
997 - if( ( isset($results['payment_status']) && $results['payment_status'] != 'Completed' ) || ( isset($results['profile_status']) && $results['profile_status'] != 'ActiveProfile' ) ) {
998 - $status = 'pending';
999 - }
1000 - }
1001 - //if( (empty($entry['customer']['name1']) && empty($entry['customer']['name2'])) || empty($entry['customer']['mailaddress1']) || empty($entry) || empty($cart) ) return '1';
1002 - $status = apply_filters( 'usces_filter_reg_orderdata_status', $status, $entry );
1003 -//20131121ysk end
1004 - $delidue_date = ( isset($entry['order']['delidue_date']) ) ? $entry['order']['delidue_date'] : NULL;
1005 -//20101208ysk start
1006 - $query = $wpdb->prepare(
1007 - "INSERT INTO $order_table_name (
1008 - `mem_id`, `order_email`, `order_name1`, `order_name2`, `order_name3`, `order_name4`,
1009 - `order_zip`, `order_pref`, `order_address1`, `order_address2`, `order_address3`,
1010 - `order_tel`, `order_fax`, `order_delivery`, `order_cart`, `order_note`, `order_delivery_method`, `order_delivery_date`, `order_delivery_time`,
1011 - `order_payment_name`, `order_condition`, `order_item_total_price`, `order_getpoint`, `order_usedpoint`, `order_discount`,
1012 - `order_shipping_charge`, `order_cod_fee`, `order_tax`, `order_date`, `order_modified`, `order_status`, `order_delidue_date` )
1013 - VALUES (%d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s, %s, %f, %d, %d, %f, %f, %f, %f, %s, %s, %s, %s)",
1014 - $member['ID'],
1015 - $entry['customer']['mailaddress1'],
1016 - $entry['customer']['name1'],
1017 - $entry['customer']['name2'],
1018 - $entry['customer']['name3'],
1019 - $entry['customer']['name4'],
1020 - $entry['customer']['zipcode'],
1021 - $entry['customer']['pref'],
1022 - $entry['customer']['address1'],
1023 - $entry['customer']['address2'],
1024 - $entry['customer']['address3'],
1025 - $entry['customer']['tel'],
1026 - $entry['customer']['fax'],
1027 - serialize($entry['delivery']),
1028 - serialize($cart),
1029 - $entry['order']['note'],
1030 - $entry['order']['delivery_method'],
1031 - $entry['order']['delivery_date'],
1032 - $entry['order']['delivery_time'],
1033 - $entry['order']['payment_name'],
1034 - serialize($entry['condition']),
1035 - $item_total_price,
1036 - $entry['order']['getpoint'],
1037 - $entry['order']['usedpoint'],
1038 - $entry['order']['discount'],
1039 - $entry['order']['shipping_charge'],
1040 - $entry['order']['cod_fee'],
1041 - $entry['order']['tax'],
1042 - get_date_from_gmt(gmdate('Y-m-d H:i:s', time())),
1043 - $order_modified,
1044 - $status,
1045 - $delidue_date
1046 - );
1047 -//20101208ysk end
1048 -
1049 - $res = $wpdb->query( $query );
1050 - usces_log('reg_orderdata : ' . $wpdb->last_error, 'database_error.log');
1051 -
1052 - if( $res === false){
1053 - $order_id = false;
1054 - }else{
1055 - $order_id = $wpdb->insert_id;
1056 - }
1057 -
1058 - if ( !$order_id ) :
1059 -
1060 - usces_log('reg_error_entry : '.print_r($entry, true), 'acting_transaction.log');
1061 - return false;
1062 -
1063 - else :
1064 -
1065 - $usces->cart->set_order_entry( array('ID' => $order_id) );
1066 - $usces->set_order_meta_value('customer_country', $entry['customer']['country'], $order_id);
1067 -
1068 - if ( $member['ID'] && 'activate' == $options['membersystem_state'] && 'activate' == $options['membersystem_point'] ) {
1069 -
1070 - $mquery = '';
1071 - if( usces_is_complete_settlement( $entry['order']['payment_name'], $status ) ) {//20120306ysk 0000324
1072 - if( apply_filters( 'usces_action_acting_getpoint_switch', true, $order_id, true) ){
1073 - $mquery = $wpdb->prepare(
1074 - "UPDATE $member_table_name SET mem_point = (mem_point + %d - %d) WHERE ID = %d",
1075 - $entry['order']['getpoint'], $entry['order']['usedpoint'], $member['ID']);
1076 - }else{
1077 - $mquery = $wpdb->prepare(
1078 - "UPDATE $member_table_name SET mem_point = (mem_point - %d) WHERE ID = %d",
1079 - $entry['order']['usedpoint'], $member['ID']);
1080 - }
1081 - } elseif( 0 < $entry['order']['usedpoint'] ) {
1082 - $mquery = $wpdb->prepare(
1083 - "UPDATE $member_table_name SET mem_point = (mem_point - %d) WHERE ID = %d",
1084 - $entry['order']['usedpoint'], $member['ID']);
1085 - }
1086 - if( $mquery ) {
1087 - $wpdb->query( $mquery );
1088 - $mquery = $wpdb->prepare("SELECT mem_point FROM $member_table_name WHERE ID = %d", $member['ID']);
1089 - $point = $wpdb->get_var( $mquery );
1090 - $_SESSION['usces_member']['point'] = $point;
1091 - }
1092 -
1093 - }
1094 -
1095 - if ( !empty($entry['reserve']) ) {
1096 - foreach ( $entry['reserve'] as $key => $value ) {
1097 - if ( is_array($value) )
1098 - $value = serialize($value);
1099 - $usces->set_order_meta_value($key, $value, $order_id);
1100 - }
1101 - }
1102 -
1103 - if ( !preg_match('/pending|noreceipt/', $status) ) {
1104 - $value = get_date_from_gmt(gmdate('Y-m-d H:i:s', time()));
1105 - $usces->set_order_meta_value('receipted_date', $value, $order_id);
1106 - }
1107 -
1108 -//20100818ysk start
1109 - if( !empty($entry['custom_order']) ) {
1110 - foreach( $entry['custom_order'] as $key => $value ) {
1111 - $csod_key = 'csod_'.$key;
1112 - if( is_array($value) )
1113 - $value = serialize($value);
1114 - $usces->set_order_meta_value($csod_key, $value, $order_id);
1115 - }
1116 - }
1117 - if( !empty($entry['custom_customer']) ) {
1118 - foreach( $entry['custom_customer'] as $key => $value ) {
1119 - $cscs_key = 'cscs_'.$key;
1120 - if( is_array($value) )
1121 - $value = serialize($value);
1122 - $usces->set_order_meta_value($cscs_key, $value, $order_id);
1123 - }
1124 - }
1125 - if( !empty($entry['custom_delivery']) ) {
1126 - foreach( $entry['custom_delivery'] as $key => $value ) {
1127 - $csde_key = 'csde_'.$key;
1128 - if( is_array($value) )
1129 - $value = serialize($value);
1130 - $usces->set_order_meta_value($csde_key, $value, $order_id);
1131 - }
1132 - }
1133 -//20100818ysk end
1134 -
1135 - if ( isset($_REQUEST['X-S_TORIHIKI_NO']) ) {
1136 - $usces->set_order_meta_value('settlement_id', $_REQUEST['X-S_TORIHIKI_NO'], $order_id);
1137 - if ( isset($_REQUEST['X-AC_MEMBERID']) ) {
1138 - $usces->set_order_meta_value($_REQUEST['X-AC_MEMBERID'], 'continuation', $order_id);
1139 - //$usces->set_member_meta_value('continue_memberid', $_REQUEST['X-AC_MEMBERID']);
1140 - $usces->set_member_meta_value('continue_memberid_'.$order_id, $_REQUEST['X-AC_MEMBERID']);
1141 - }
1142 - }
1143 -
1144 - if(isset($_REQUEST['acting']) && ('jpayment_card' == $_REQUEST['acting'] || 'jpayment_conv' == $_REQUEST['acting'] || 'jpayment_bank' == $_REQUEST['acting'])) {
1145 - $usces->set_order_meta_value('settlement_id', $_GET['cod'], $order_id);
1146 - foreach($_GET as $key => $value) {
1147 - if( 'purchase_jpayment' != $key)
1148 - $data[$key] = esc_sql($value);
1149 - }
1150 - $usces->set_order_meta_value('acting_'.$_REQUEST['acting'], serialize($data), $order_id);
1151 - }
1152 - if( isset($_REQUEST['acting']) && isset($_REQUEST['acting_return']) && isset($_REQUEST['trans_code']) && 'epsilon' == $_REQUEST['acting'] ) {
1153 - //$usces->set_order_meta_value('settlement_id', $_GET['trans_code'], $order_id);//20130523ysk 0000711
1154 - $usces->set_order_meta_value('settlement_id', $_GET['order_number'], $order_id);
1155 - }
1156 - if( isset($_REQUEST['res_tracking_id']) ) {
1157 - $usces->set_order_meta_value('res_tracking_id', $_REQUEST['res_tracking_id'], $order_id);
1158 - }
1159 -//20121206ysk start
1160 - if( isset($_REQUEST['SID']) && isset($_REQUEST['FUKA']) ) {
1161 - if( substr($_REQUEST['FUKA'], 0, 24) == 'acting_digitalcheck_card' ) {
1162 - $data['SID'] = esc_sql($_REQUEST['SID']);
1163 - $usces->set_order_meta_value( $_REQUEST['FUKA'], serialize($data), $order_id );
1164 - }
1165 - $usces->set_order_meta_value( 'SID', $_REQUEST['SID'], $order_id );
1166 - }
1167 -//20121206ysk end
1168 -//20130225ysk start
1169 - if( isset($_REQUEST['acting']) && 'mizuho_card' == $_REQUEST['acting'] ) {
1170 - $data['stran'] = esc_sql($_REQUEST['stran']);
1171 - $data['mbtran'] = esc_sql($_REQUEST['mbtran']);
1172 - $usces->set_order_meta_value( 'acting_'.$_REQUEST['acting'], serialize($data), $order_id );
1173 - } elseif( isset($_REQUEST['acting']) && 'mizuho_conv' == $_REQUEST['acting'] ) {
1174 - $data['stran'] = esc_sql($_REQUEST['stran']);
1175 - $data['mbtran'] = esc_sql($_REQUEST['mbtran']);
1176 - $data['bktrans'] = esc_sql($_REQUEST['bktrans']);
1177 - $data['tranid'] = esc_sql($_REQUEST['tranid']);
1178 - $usces->set_order_meta_value( 'stran', $data['stran'], $order_id );
1179 - $usces->set_order_meta_value( 'acting_'.$_REQUEST['acting'], serialize($data), $order_id );
1180 - }
1181 -//20130225ysk end
1182 -//20131220ysk start
1183 - if( isset($_REQUEST['SiteId']) and $usces->options['acting_settings']['anotherlane']['siteid'] == $_REQUEST['SiteId'] and isset($_REQUEST['TransactionId']) ) {
1184 - $usces->set_order_meta_value( 'TransactionId', $_REQUEST['TransactionId'], $order_id );
1185 - }
1186 -//20131220ysk end
1187 -//20140206ysk start
1188 - if( isset($_GET['acting']) and 'veritrans_card' == $_GET['acting'] and isset($_POST['orderId']) ) {
1189 - $usces->set_order_meta_value( 'orderId', $_POST['orderId'], $order_id );
1190 - $usces->set_order_meta_value( 'acting_'.$_GET['acting'], serialize($_POST), $order_id );
1191 - } elseif( isset($_GET['acting']) and 'veritrans_conv' == $_GET['acting'] and isset($_POST['orderId']) ) {
1192 - $usces->set_order_meta_value( 'orderId', $_POST['orderId'], $order_id );
1193 - $data['mStatus'] = mysql_real_escape_string( $_POST['mStatus'] );
1194 - $data['vResultCode'] = mysql_real_escape_string( $_POST['vResultCode'] );
1195 - $data['orderId'] = mysql_real_escape_string( $_POST['orderId'] );
1196 - $usces->set_order_meta_value( 'acting_'.$_GET['acting'], serialize($data), $order_id );
1197 - }
1198 -//20140206ysk end
1199 -
1200 - //$args = array('cart'=>$cart, 'entry'=>$entry, 'order_id'=>$order_id, 'member_id'=>$member['ID'], 'payments'=>$payments, 'charging_type'=>$charging_type);
1201 - $args = array('cart'=>$cart, 'entry'=>$entry, 'order_id'=>$order_id, 'member_id'=>$member['ID'], 'payments'=>$set, 'charging_type'=>$charging_type);//20131121ysk
1202 - do_action('usces_action_reg_orderdata', $args);
1203 -
1204 - endif;
1205 -
1206 - return $order_id;
1207 -
1208 -}
1209 -
1210 -function usces_new_orderdata() {
1211 - global $wpdb, $usces;
1212 - $_POST = $usces->stripslashes_deep_post($_POST);
1213 -
1214 - $usces->cart->crear_cart();
1215 - $cart = $usces->cart->get_cart();
1216 - $item_total_price = $usces->get_total_price( $cart );
1217 - $entry = $usces->cart->get_entry();
1218 - $member_id = $usces->get_memberid_by_email($_POST['customer']['mailaddress']);
1219 - $order_table_name = $wpdb->prefix . "usces_order";
1220 - $order_table_meta_name = $wpdb->prefix . "usces_order_meta";
1221 - $member_table_name = $wpdb->prefix . "usces_member";
1222 - $set = $usces->getPayments( $_POST['offer']['payment_name'] );
1223 - if( isset($_POST['offer']['receipt']) ) {
1224 - $status = $_POST['offer']['receipt'].',';
1225 - } else {
1226 -//20131121ysk start
1227 - //$status = ( $set['settlement'] == 'transferAdvance' || $set['settlement'] == 'transferDeferred' || $set['settlement'] == 'acting_remise_conv' || $set['settlement'] == 'acting_zeus_bank' || $set['settlement'] == 'acting_zeus_conv' || $set['settlement'] == 'acting_jpayment_conv' || $set['settlement'] == 'acting_jpayment_bank' || $set['settlement'] == 'acting_sbps_conv' || $set['settlement'] == 'acting_sbps_payeasy' || $set['settlement'] == 'acting_digitalcheck_conv' ) ? 'noreceipt' : '';
1228 - $noreceipt_status_table = apply_filters( 'usces_filter_noreceipt_status', array( 'transferAdvance', 'transferDeferred', 'acting_remise_conv', 'acting_zeus_bank', 'acting_zeus_conv', 'acting_jpayment_conv', 'acting_jpayment_bank', 'acting_sbps_conv', 'acting_sbps_payeasy', 'acting_digitalcheck_conv', 'acting_mizuho_conv1', 'acting_mizuho_conv2' ) );
1229 - $status = ( in_array( $set['settlement'], $noreceipt_status_table ) ) ? 'noreceipt' : '';
1230 -//20131121ysk end
1231 - }
1232 - $status .= ( !WCUtils::is_blank($_POST['offer']['taio']) && $_POST['offer']['taio'] != '#none#' ) ? $_POST['offer']['taio'].',' : '';
1233 - $status .= $_POST['offer']['admin'];
1234 - $status = apply_filters( 'usces_filter_new_orderdata_status', $status, $entry );
1235 - $order_conditions = $usces->get_condition();
1236 -
1237 -//20101208ysk start
1238 - $query = $wpdb->prepare(
1239 - "INSERT INTO $order_table_name (
1240 - `mem_id`, `order_email`, `order_name1`, `order_name2`, `order_name3`, `order_name4`,
1241 - `order_zip`, `order_pref`, `order_address1`, `order_address2`, `order_address3`,
1242 - `order_tel`, `order_fax`, `order_delivery`, `order_cart`, `order_note`, `order_delivery_method`, `order_delivery_date`, `order_delivery_time`,
1243 - `order_payment_name`, `order_condition`, `order_item_total_price`, `order_getpoint`, `order_usedpoint`, `order_discount`,
1244 - `order_shipping_charge`, `order_cod_fee`, `order_tax`, `order_date`, `order_modified`, `order_status`, `order_delidue_date` )
1245 - VALUES (%d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s, %s, %f, %d, %d, %f, %f, %f, %f, %s, %s, %s, %s)",
1246 - $member_id,
1247 - $_POST['customer']['mailaddress'],
1248 - $_POST['customer']['name1'],
1249 - $_POST['customer']['name2'],
1250 - $_POST['customer']['name3'],
1251 - $_POST['customer']['name4'],
1252 - $_POST['customer']['zipcode'],
1253 - $_POST['customer']['pref'],
1254 - $_POST['customer']['address1'],
1255 - $_POST['customer']['address2'],
1256 - $_POST['customer']['address3'],
1257 - $_POST['customer']['tel'],
1258 - $_POST['customer']['fax'],
1259 - serialize($_POST['delivery']),
1260 - serialize($cart),
1261 - $_POST['offer']['note'],
1262 - $_POST['offer']['delivery_method'],
1263 - $_POST['offer']['delivery_date'],
1264 - $_POST['offer']['delivery_time'],
1265 - $_POST['offer']['payment_name'],
1266 - serialize($order_conditions),
1267 - $item_total_price,
1268 - $_POST['offer']['getpoint'],
1269 - $_POST['offer']['usedpoint'],
1270 - $_POST['offer']['discount'],
1271 - $_POST['offer']['shipping_charge'],
1272 - $_POST['offer']['cod_fee'],
1273 - $_POST['offer']['tax'],
1274 - get_date_from_gmt(gmdate('Y-m-d H:i:s', time())),
1275 - null,
1276 - $status,
1277 - $_POST['offer']['delidue_date']
1278 - );
1279 -//20101208ysk end
1280 -
1281 - $res = $wpdb->query( $query );
1282 -// $wpdb->print_error();
1283 -// echo $query;
1284 -// exit;
1285 - $order_id = $wpdb->insert_id;
1286 - $_REQUEST['order_id'] = $wpdb->insert_id;
1287 -
1288 -//20100818ysk start
1289 - if( !$order_id ) :
1290 -
1291 - return false;
1292 -
1293 - else :
1294 - $usces->set_order_meta_value('customer_country', $_POST['customer']['country'], $order_id);
1295 -
1296 - if( !empty($_POST['custom_order']) ) {
1297 - foreach( $_POST['custom_order'] as $key => $value ) {
1298 - $csod_key = 'csod_'.$key;
1299 - if( is_array($value) )
1300 - $value = serialize($value);
1301 - $usces->set_order_meta_value($csod_key, $value, $order_id);
1302 - }
1303 - }
1304 - if( !empty($_POST['custom_customer']) ) {
1305 - foreach( $_POST['custom_customer'] as $key => $value ) {
1306 - $cscs_key = 'cscs_'.$key;
1307 - if( is_array($value) )
1308 - $value = serialize($value);
1309 - $usces->set_order_meta_value($cscs_key, $value, $order_id);
1310 - }
1311 - }
1312 - if( !empty($_POST['custom_delivery']) ) {
1313 - foreach( $_POST['custom_delivery'] as $key => $value ) {
1314 - $csde_key = 'csde_'.$key;
1315 - if( is_array($value) )
1316 - $value = serialize($value);
1317 - $usces->set_order_meta_value($csde_key, $value, $order_id);
1318 - }
1319 - }
1320 - if ( !preg_match('/pending|noreceipt/', $status) ) {
1321 - $value = get_date_from_gmt(gmdate('Y-m-d H:i:s', time()));
1322 - $usces->set_order_meta_value('receipted_date', $value, $order_id);
1323 - }
1324 -//20120314ysk start 0000435
1325 -//20131121ysk start
1326 - //$args = array('cart'=>$cart, 'entry'=>$entry, 'order_id'=>$order_id, 'member_id'=>$member_id);
1327 - $args = array('cart'=>$cart, 'entry'=>$entry, 'order_id'=>$order_id, 'member_id'=>$member_id, 'payments'=>$set);
1328 -//20131121ysk end
1329 - do_action('usces_action_reg_orderdata', $args);
1330 -//20120314ysk end
1331 - endif;
1332 -//20100818ysk end
1333 -
1334 - $usces->cart->crear_cart();
1335 - return $res;
1336 -
1337 -}
1338 -
1339 -function usces_delete_memberdata( $ID = 0 ) {
1340 - global $wpdb, $usces;
1341 -
1342 - if( 0 === $ID ){
1343 - if(!isset($_REQUEST['member_id']) || WCUtils::is_blank($_REQUEST['member_id']) )
1344 - return 0;
1345 - $ID = $_REQUEST['member_id'];
1346 - }
1347 - do_action('usces_action_pre_delete_memberdata', $ID);
1348 -
1349 - $member_table_name = $wpdb->prefix . "usces_member";
1350 -//20100818ysk start
1351 - $member_table_meta_name = $wpdb->prefix . "usces_member_meta";
1352 -//20100818ysk end
1353 -
1354 - $query = $wpdb->prepare("DELETE FROM $member_table_name WHERE ID = %d", $ID);
1355 - $res = $wpdb->query( $query );
1356 -//20100818ysk start
1357 - if($res) {
1358 - $query = $wpdb->prepare("DELETE FROM $member_table_meta_name WHERE member_id = %d", $ID);
1359 - $wpdb->query( $query );
1360 - }
1361 -//20100818ysk end
1362 - do_action('usces_action_post_delete_memberdata', $res, $ID);
1363 -
1364 - return $res;
1365 -}
1366 -
1367 -function usces_update_memberdata() {
1368 - global $wpdb, $usces;
1369 - $_POST = $usces->stripslashes_deep_post($_POST);
1370 -
1371 - $member_table_name = $wpdb->prefix . "usces_member";
1372 -//20100818ysk start
1373 - $member_table_meta_name = $wpdb->prefix . "usces_member_meta";
1374 -//20100818ysk end
1375 -
1376 - $ID = (int)$_REQUEST['member_id'];
1377 -
1378 -//$wpdb->show_errors();
1379 - $query = $wpdb->prepare(
1380 - "UPDATE $member_table_name SET
1381 - `mem_email`=%s, `mem_status`=%s, `mem_point`=%d, `mem_name1`=%s, `mem_name2`=%s,
1382 - `mem_name3`=%s, `mem_name4`=%s, `mem_zip`=%s, `mem_pref`=%s, `mem_address1`=%s,
1383 - `mem_address2`=%s, `mem_address3`=%s, `mem_tel`=%s, `mem_fax`=%s
1384 - WHERE ID = %d",
1385 - $_POST['member']['email'],
1386 - $_POST['member']['status'],
1387 - $_POST['member']['point'],
1388 - $_POST['member']['name1'],
1389 - $_POST['member']['name2'],
1390 - $_POST['member']['name3'],
1391 - $_POST['member']['name4'],
1392 - $_POST['member']['zipcode'],
1393 - $_POST['member']['pref'],
1394 - $_POST['member']['address1'],
1395 - $_POST['member']['address2'],
1396 - $_POST['member']['address3'],
1397 - $_POST['member']['tel'],
1398 - $_POST['member']['fax'],
1399 - $ID
1400 - );
1401 -
1402 - do_action('usces_action_pre_update_memberdata', $ID);
1403 -//20100818ysk start
1404 - //$res = $wpdb->query( $query );
1405 - $res[0] = $wpdb->query( $query );
1406 -
1407 - do_action( 'usces_action_post_update_memberdata', $ID, $res[0]);
1408 -
1409 - if(false === $res[0])
1410 - return false;
1411 -
1412 - $usces->set_member_meta_value('customer_country', $_POST['member']['country'], $ID);
1413 -//20130524ysk start 0000712
1414 - $csmb_meta = usces_has_custom_field_meta( 'member' );
1415 - if( is_array($csmb_meta) ) {
1416 - foreach( $csmb_meta as $key => $entry ) {
1417 - if( '4' == $entry['means'] ) {
1418 - $usces->del_member_meta( 'csmb_'.$key, $ID );
1419 - }
1420 - }
1421 - }
1422 -//20130524ysk end
1423 - $i = 1;
1424 - if( !empty($_POST['custom_member']) ) {
1425 - foreach( $_POST['custom_member'] as $key => $value ) {
1426 - $csmb_key = 'csmb_'.$key;
1427 - if( is_array($value) )
1428 - $value = serialize($value);
1429 - $res[$i] = $usces->set_member_meta_value($csmb_key, $value, $ID);
1430 - if(false === $res[$i])
1431 - return false;
1432 - $i++;
1433 - }
1434 - }
1435 -
1436 -
1437 - //$meta_keys = apply_filters( 'usces_filter_delete_member_pcid', "'zeus_pcid', 'remise_pcid', 'digitalcheck_ip_user_id'" );
1438 - $meta_keys = apply_filters( 'usces_filter_delete_member_pcid', "'remise_pcid', 'digitalcheck_ip_user_id'" );
1439 - $query = $wpdb->prepare("DELETE FROM $member_table_meta_name WHERE member_id = %d AND meta_key IN( $meta_keys )",
1440 - $_POST['member_id']
1441 - );
1442 - $res[$i] = $wpdb->query( $query );
1443 -
1444 - $result = ( 0 < array_sum($res) ) ? 1 : 0;
1445 - //return $res;
1446 - return $result;
1447 -//20100818ysk end
1448 -}
1449 -
1450 -function usces_delete_orderdata() {
1451 - global $wpdb, $usces;
1452 - if(!isset($_REQUEST['order_id']) || WCUtils::is_blank($_REQUEST['order_id']) ) return 0;
1453 - $order_table = $wpdb->prefix . "usces_order";
1454 - $order_meta_table = $wpdb->prefix . "usces_order_meta";
1455 - $ID = $_REQUEST['order_id'];
1456 -
1457 - $del = usces_delete_order_check( $ID );
1458 - if( $del ) {
1459 -
1460 - $query = $wpdb->prepare("SELECT * FROM $order_table WHERE ID = %d", $ID);
1461 - $order_data = $wpdb->get_row( $query, OBJECT );
1462 -//20130625ysk start 0000721
1463 -//20120306ysk start 0000324
1464 - //$order_res = $wpdb->get_row( $query, ARRAY_A );
1465 - //$restore_point = false;
1466 - $point = 0;
1467 - if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] && !empty($order_data->mem_id) && !$usces->is_status('cancel', $order_data->order_status) ) {
1468 - if( 0 < $order_data->order_getpoint ) {
1469 - //if( $usces->is_status('completion', $order_data->order_status) ) {
1470 - // //$restore_point = true;
1471 - // $point += $order_data->order_getpoint;
1472 - //} else {
1473 - if( usces_is_complete_settlement( $order_data->order_payment_name, $order_data->order_status ) || $usces->is_status('receipted', $order_data->order_status) ) {
1474 - //$restore_point = true;
1475 - $point += $order_data->order_getpoint;
1476 - }
1477 - //}
1478 - }
1479 - if( 0 < $order_data->order_usedpoint ) {
1480 - $point -= $order_data->order_usedpoint;
1481 - }
1482 - }
1483 -//20120306ysk end
1484 -
1485 - $query = $wpdb->prepare("DELETE FROM $order_table WHERE ID = %d", $ID);
1486 - $res = $wpdb->query( $query );
1487 -
1488 - $args = compact( 'ID', 'point', 'res' );
1489 -
1490 - if($res){
1491 -
1492 - do_action('usces_action_del_orderdata', $order_data, $args);
1493 -
1494 - $query = $wpdb->prepare("DELETE FROM $order_meta_table WHERE order_id = %d", $ID);
1495 - $wpdb->query( $query );
1496 -
1497 -//20120306ysk start 0000324
1498 - //if( $restore_point ) usces_restore_point( $order_res['mem_id'], $order_res['order_getpoint'] );
1499 - if( 0 != $point ) usces_restore_point( $order_data->mem_id, $point );
1500 -//20120306ysk end
1501 -//20130625ysk end
1502 - }
1503 -
1504 - } else {
1505 - $res = true;
1506 - }
1507 -
1508 - return $res;
1509 -}
1510 -
1511 -function usces_update_ordercart() {
1512 - global $wpdb, $usces;
1513 - if(!isset($_REQUEST['order_id']) || WCUtils::is_blank($_REQUEST['order_id']) ) return 0;
1514 - $order_table_name = $wpdb->prefix . "usces_order";
1515 - $ID = $_REQUEST['order_id'];
1516 - $usces->cart->crear_cart();
1517 - $usces->cart->upCart();
1518 - $cart = $usces->cart->get_cart();
1519 -//20120613ysk start 0000500
1520 - $idx = count($cart)-1;
1521 - $post_id = $cart[$idx]['post_id'];
1522 - $sku = $cart[$idx]['sku'];
1523 - $sku_code = esc_attr(urldecode($sku));
1524 - $cartItemName = $usces->getCartItemName($post_id, $sku_code);
1525 - $skuPrice = $cart[$idx]['price'];
1526 -//20120613ysk end
1527 -
1528 - $query = $wpdb->prepare("UPDATE $order_table_name SET `order_cart`=%s WHERE ID = %d", serialize($cart), $ID);
1529 - $res = $wpdb->query( $query );
1530 -
1531 - $usces->cart->crear_cart();
1532 -//20120613ysk start 0000500
1533 - if( $res === false ) {
1534 - $res = "-1#usces#";
1535 - } else {
1536 - $res = $skuPrice."#usces#".$cartItemName;
1537 - }
1538 -//20120613ysk end
1539 - return $res;
1540 -}
1541 -
1542 -function usces_update_ordercheck() {
1543 - global $wpdb, $usces;
1544 -
1545 - $tableName = $wpdb->prefix . "usces_order";
1546 - $order_id = $_POST['order_id'];
1547 - $checked = $_POST['checked'];
1548 -
1549 - $query = $wpdb->prepare("SELECT `order_check` FROM $tableName WHERE ID = %d", $order_id);
1550 - $res = $wpdb->get_var( $query );
1551 -
1552 - $checkfield = unserialize($res);
1553 - if( !isset($checkfield[$checked]) ) $checkfield[$checked] = $checked;
1554 - //$checkfield = 'OK';
1555 - $query = $wpdb->prepare("UPDATE $tableName SET `order_check`=%s WHERE ID = %d", serialize($checkfield), $order_id);
1556 - $res = $wpdb->query( $query );
1557 -
1558 - if($res)
1559 - return $checked;
1560 - else
1561 - return 'error';
1562 -}
1563 -function usces_update_orderdata() {
1564 - global $wpdb, $usces;
1565 - $_POST = $usces->stripslashes_deep_post($_POST);
1566 -
1567 - $order_table_name = $wpdb->prefix . "usces_order";
1568 - $order_table_meta_name = $wpdb->prefix . "usces_order_meta";
1569 - $member_table_name = $wpdb->prefix . "usces_member";
1570 -
1571 - $ID = $_REQUEST['order_id'];
1572 -
1573 - $query = $wpdb->prepare("SELECT * FROM $order_table_name WHERE ID = %d", $ID);
1574 - $old_orderdata = $wpdb->get_row( $query );
1575 - $old_status = $old_orderdata->order_status;
1576 -
1577 - $usces->cart->crear_cart();
1578 - $usces->cart->upCart();
1579 - if(isset($_POST['delButton'])) {
1580 - $usces->cart->del_row();
1581 - $indexs = array_keys($_POST['delButton']);
1582 - $index = $indexs[0];
1583 - do_action('usces_admin_delete_orderrow', $ID, $index );
1584 - }
1585 - $cart = $usces->cart->get_cart();
1586 - $usces->cart->entry();
1587 - $entry = $usces->cart->get_entry();
1588 -
1589 - $item_total_price = $usces->get_total_price( $cart );
1590 - //$set = $usces->getPayments( $entry['order']['payment_name'] );
1591 - $taio = isset($entry['order']['taio']) ? $entry['order']['taio'] : '';
1592 - $receipt = isset($entry['order']['receipt']) ? $entry['order']['receipt'] : '';
1593 - $admin = isset($entry['order']['admin']) ? $entry['order']['admin'] : '';
1594 - $status = $usces->make_status( $taio, $receipt, $admin );
1595 - if( $taio == 'completion' || $taio == 'continuation' ){
1596 - if( 'update' == $_POST['up_modified'] ){
1597 - $order_modified = substr(get_date_from_gmt(gmdate('Y-m-d H:i:s', time())), 0, 10);
1598 - }else{
1599 - $order_modified = $_POST['modified'];
1600 - }
1601 - }else{
1602 - $order_modified = '';
1603 - }
1604 - $ordercheck = isset($_POST['check']) ? serialize($_POST['check']) : '';
1605 - $member_id = isset($_POST['member_id']) ? $_POST['member_id'] : 0;
1606 - //$member_id = $usces->get_memberid_by_email($_POST['customer']['mailaddress']);
1607 -
1608 - if( 'cancel' == $taio ){
1609 - $query = $wpdb->prepare(
1610 - "UPDATE $order_table_name SET `order_modified`=%s, `order_status`=%s WHERE ID = %d",
1611 - $order_modified, $status, $ID
1612 - );
1613 - $res[0] = $wpdb->query( $query );
1614 -
1615 - $query = $wpdb->prepare("SELECT * FROM $order_table_name WHERE ID = %d", $ID);
1616 - $new_orderdata = $wpdb->get_row( $query );
1617 -
1618 -//20131101ysk start 0000751
1619 - if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] && !empty($member_id) && !$usces->is_status('cancel', $old_status) ) {
1620 - $point = 0;
1621 - if( 0 < $old_orderdata->order_getpoint ) {
1622 - if( usces_is_complete_settlement( $old_orderdata->order_payment_name, $old_orderdata->order_status ) || $usces->is_status('receipted', $old_orderdata->order_status) ) {
1623 - $point += $old_orderdata->order_getpoint;
1624 - }
1625 - }
1626 - if( 0 < $old_orderdata->order_usedpoint ) {
1627 - $point -= $old_orderdata->order_usedpoint;
1628 - }
1629 - if( 0 != $point ) usces_restore_point( $member_id, $point );
1630 - }
1631 -//20131101ysk end
1632 -
1633 - do_action('usces_action_update_orderdata', $new_orderdata, $old_status, $old_orderdata);
1634 - $usces->cart->crear_cart();
1635 -
1636 - return 1;
1637 - }
1638 -
1639 -//$wpdb->show_errors();
1640 -//20101208ysk start
1641 - $query = $wpdb->prepare(
1642 - "UPDATE $order_table_name SET
1643 - `mem_id`=%d, `order_email`=%s, `order_name1`=%s, `order_name2`=%s, `order_name3`=%s, `order_name4`=%s,
1644 - `order_zip`=%s, `order_pref`=%s, `order_address1`=%s, `order_address2`=%s, `order_address3`=%s,
1645 - `order_tel`=%s, `order_fax`=%s, `order_delivery`=%s, `order_cart`=%s, `order_note`=%s,
1646 - `order_delivery_method`=%d, `order_delivery_date`=%s, `order_delivery_time`=%s, `order_payment_name`=%s, `order_item_total_price`=%f, `order_getpoint`=%d, `order_usedpoint`=%d,
1647 - `order_discount`=%f, `order_shipping_charge`=%f, `order_cod_fee`=%f, `order_tax`=%f, `order_modified`=%s,
1648 - `order_status`=%s, `order_delidue_date`=%s, `order_check`=%s
1649 - WHERE ID = %d",
1650 - $member_id,
1651 - $_POST['customer']['mailaddress'],
1652 - $_POST['customer']['name1'],
1653 - $_POST['customer']['name2'],
1654 - $_POST['customer']['name3'],
1655 - $_POST['customer']['name4'],
1656 - $_POST['customer']['zipcode'],
1657 - $_POST['customer']['pref'],
1658 - $_POST['customer']['address1'],
1659 - $_POST['customer']['address2'],
1660 - $_POST['customer']['address3'],
1661 - $_POST['customer']['tel'],
1662 - $_POST['customer']['fax'],
1663 - serialize($_POST['delivery']),
1664 - serialize($cart),
1665 - $_POST['offer']['note'],
1666 - $_POST['offer']['delivery_method'],
1667 - $_POST['offer']['delivery_date'],
1668 - $_POST['offer']['delivery_time'],
1669 - $_POST['offer']['payment_name'],
1670 - $item_total_price,
1671 - $_POST['offer']['getpoint'],
1672 - $_POST['offer']['usedpoint'],
1673 - $_POST['offer']['discount'],
1674 - $_POST['offer']['shipping_charge'],
1675 - $_POST['offer']['cod_fee'],
1676 - $_POST['offer']['tax'],
1677 - $order_modified,
1678 - $status,
1679 - $_POST['offer']['delidue_date'],
1680 - $ordercheck,
1681 - $ID
1682 - );
1683 -//20101208ysk end
1684 -
1685 -//20100818ysk start
1686 - //$res = $wpdb->query( $query );
1687 - $res[0] = $wpdb->query( $query );
1688 - if(false === $res[0])
1689 - return false;
1690 -
1691 - $usces->set_order_meta_value('customer_country', $_POST['customer']['country'], $ID);
1692 -//20130524ysk start 0000712
1693 - $csod_meta = usces_has_custom_field_meta( 'order' );
1694 - if( is_array($csod_meta) ) {
1695 - foreach( $csod_meta as $key => $entry ) {
1696 - if( '4' == $entry['means'] ) {
1697 - $usces->del_order_meta( 'csod_'.$key, $ID );
1698 - }
1699 - }
1700 - }
1701 - $cscs_meta = usces_has_custom_field_meta( 'customer' );
1702 - if( is_array($cscs_meta) ) {
1703 - foreach( $cscs_meta as $key => $entry ) {
1704 - if( '4' == $entry['means'] ) {
1705 - $usces->del_order_meta( 'cscs_'.$key, $ID );
1706 - }
1707 - }
1708 - }
1709 - $csde_meta = usces_has_custom_field_meta( 'delivery' );
1710 - if( is_array($csde_meta) ) {
1711 - foreach( $csde_meta as $key => $entry ) {
1712 - if( '4' == $entry['means'] ) {
1713 - $usces->del_order_meta( 'csde_'.$key, $ID );
1714 - }
1715 - }
1716 - }
1717 -//20130524ysk end
1718 - $i = 1;
1719 - if( !empty($_POST['custom_order']) ) {
1720 - foreach( $_POST['custom_order'] as $key => $value ) {
1721 - $csod_key = 'csod_'.$key;
1722 - if( is_array($value) )
1723 - $value = serialize($value);
1724 - $res[$i] = $usces->set_order_meta_value($csod_key, $value, $ID);
1725 - if(false === $res[$i])
1726 - return false;
1727 - $i++;
1728 - }
1729 - }
1730 - if( !empty($_POST['custom_customer']) ) {
1731 - foreach( $_POST['custom_customer'] as $key => $value ) {
1732 - $cscs_key = 'cscs_'.$key;
1733 - if( is_array($value) )
1734 - $value = serialize($value);
1735 - $res[$i] = $usces->set_order_meta_value($cscs_key, $value, $ID);
1736 - if(false === $res[$i])
1737 - return false;
1738 - $i++;
1739 - }
1740 - }
1741 - if( !empty($_POST['custom_delivery']) ) {
1742 - foreach( $_POST['custom_delivery'] as $key => $value ) {
1743 - $csde_key = 'csde_'.$key;
1744 - if( is_array($value) )
1745 - $value = serialize($value);
1746 - $res[$i] = $usces->set_order_meta_value($csde_key, $value, $ID);
1747 - if(false === $res[$i])
1748 - return false;
1749 - $i++;
1750 - }
1751 - }
1752 - $value = get_date_from_gmt(gmdate('Y-m-d H:i:s', time()));
1753 - if ( !preg_match('/pending|noreceipt/', $old_status) && preg_match('/pending|noreceipt/', $status) ) {
1754 - $rquery = $wpdb->prepare("DELETE FROM $order_table_meta_name WHERE order_id = %d AND meta_key = %s", $ID, 'receipted_date');
1755 - $wpdb->query( $rquery );
1756 - }else if ( !preg_match('/pending|noreceipt/', $old_status) && !preg_match('/pending|noreceipt/', $status) ) {
1757 - $query = $wpdb->prepare("SELECT order_id FROM $order_table_meta_name WHERE order_id = %d AND meta_key = %s", $ID, 'receipted_date');
1758 - $varres = $wpdb->get_var( $query );
1759 - if( empty($varres) ){
1760 - $usces->set_order_meta_value('receipted_date', $value, $ID);
1761 - }
1762 - }else if ( preg_match('/pending|noreceipt/', $old_status) && !preg_match('/pending|noreceipt/', $status) ) {
1763 - $usces->set_order_meta_value('receipted_date', $value, $ID);
1764 - }
1765 -
1766 -//20131101ysk start 0000751
1767 - //if( !usces_is_complete_settlement( $_POST['offer']['payment_name'] ) ) {
1768 - // if( !preg_match('/pending|noreceipt/', $old_status) && preg_match('/pending|noreceipt/', $status) ) {//入金→未入金
1769 - // usces_action_acting_getpoint( $ID, false );//ポイント取消
1770 - // } else if( preg_match('/pending|noreceipt/', $old_status) && !preg_match('/pending|noreceipt/', $status) ) {//未入金→入金
1771 - // usces_action_acting_getpoint( $ID );//ポイント追加
1772 - // }
1773 - //}
1774 - if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] && !empty($member_id) ) {
1775 - $point = 0;
1776 - $getpoint = $_POST['offer']['getpoint'];
1777 - $usedpoint = $_POST['offer']['usedpoint'];
1778 - if( $usces->is_status('cancel', $old_status) && !$usces->is_status('cancel', $status) ) {//キャンセル→新規受付・取り寄せ中・発送済み
1779 - if( 0 < $getpoint ) {
1780 - if( usces_is_complete_settlement( $_POST['offer']['payment_name'], $status ) || $usces->is_status('receipted', $status) ) {
1781 - $point -= $getpoint;
1782 - }
1783 - }
1784 - if( 0 < $usedpoint ) {
1785 - $point += $usedpoint;
1786 - }
1787 - } else {
1788 - if( !usces_is_complete_settlement( $_POST['offer']['payment_name'] ) ) {
1789 - if( !preg_match('/pending|noreceipt/', $old_status) && preg_match('/pending|noreceipt/', $status) ) {//入金→未入金
1790 - $point += $getpoint;//ポイント取消
1791 - } else if( preg_match('/pending|noreceipt/', $old_status) && !preg_match('/pending|noreceipt/', $status) ) {//未入金→入金
1792 - $point -= $getpoint;//ポイント追加
1793 - } else {
1794 - if( $old_orderdata->order_getpoint != $getpoint ) {
1795 - $point += $old_orderdata->order_getpoint - $getpoint;
1796 - }
1797 - }
1798 - } else {
1799 - if( $old_orderdata->order_getpoint != $getpoint ) {
1800 - $point += $old_orderdata->order_getpoint - $getpoint;
1801 - }
1802 - }
1803 - if( $old_orderdata->order_usedpoint != $usedpoint ) {
1804 - $point -= $old_orderdata->order_usedpoint - $usedpoint;
1805 - }
1806 - }
1807 - if( 0 != $point ) usces_restore_point( $member_id, $point );
1808 - }
1809 -//20131101ysk end
1810 -
1811 - $result = ( 0 < array_sum($res) ) ? 1 : 0;
1812 -//20100818ysk end
1813 -
1814 - $query = $wpdb->prepare("SELECT * FROM $order_table_name WHERE ID = %d", $ID);
1815 - $new_orderdata = $wpdb->get_row( $query );
1816 -//20120612ysk start 0000501
1817 - //do_action('usces_action_update_orderdata', $new_orderdata);
1818 - do_action('usces_action_update_orderdata', $new_orderdata, $old_status, $old_orderdata);
1819 -//20120612ysk end
1820 - $usces->cart->crear_cart();
1821 -
1822 -return $result;
1823 -
1824 -// else :
1825 -//
1826 -// if ( $member['ID'] ) {
1827 -//
1828 -// $mquery = $wpdb->prepare(
1829 -// "UPDATE $member_table_name SET mem_point = (mem_point + %d - %d) WHERE ID = %d",
1830 -// $entry['order']['getpoint'], $entry['order']['usedpoint'], $member['ID']);
1831 -//
1832 -// $wpdb->query( $mquery );
1833 -// $mquery = $wpdb->prepare("SELECT mem_point FROM $member_table_name WHERE ID = %d", $member['ID']);
1834 -// $point = $wpdb->get_var( $mquery );
1835 -// $_SESSION['usces_member']['point'] = $point;
1836 -// }
1837 -//
1838 -// if ( !empty($entry['reserve']) ) {
1839 -// foreach ( $entry['reserve'] as $key => $value ) {
1840 -// if ( is_array($value) )
1841 -// $value = serialize($value);
1842 -// $mquery = $wpdb->prepare("INSERT INTO $order_table_meta_name ( order_id, meta_key, meta_value )
1843 -// VALUES (%d, %s, %s, %s)", $order_id, $key, $value);
1844 -// $wpdb->query( $mquery );
1845 -// }
1846 -// }
1847 -//
1848 -// endif;
1849 -//
1850 -// //zaiko
1851 -// foreach($cart as $cartrow){
1852 -// $zaikonum = $usces->getItemZaikoNum( $cartrow['post_id'], $cartrow['sku'] );
1853 -// if($zaikonum == '') continue;
1854 -// $zaikonum = $zaikonum - $cartrow['quantity'];
1855 -// $usces->updateItemZaikoNum( $cartrow['post_id'], $cartrow['sku'], $zaikonum );
1856 -// if($zaikonum <= 0) $usces->updateItemZaiko( $cartrow['post_id'], $cartrow['sku'], 2 );
1857 -// }
1858 -//
1859 -// return $order_id;
1860 -
1861 -}
1862 -
1863 -
1864 -
1865 -function usces_export_xml() {
1866 - $options = get_option('usces');
1867 - echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '"?' . ">\n";
1868 -?>
1869 - <usces><?php echo serialize($options); ?></usces>
1870 - <usces_management_status><?php echo serialize(get_option('usces_management_status')); ?></usces_management_status>
1871 - <usces_zaiko_status><?php echo serialize(get_option('usces_zaiko_status')); ?></usces_zaiko_status>
1872 - <usces_customer_status><?php echo serialize(get_option('usces_customer_status')); ?></usces_customer_status>
1873 - <usces_payment_structure><?php echo serialize(get_option('usces_payment_structure')); ?></usces_payment_structure>
1874 - <usces_display_mode><?php echo serialize(get_option('usces_display_mode')); ?></usces_display_mode>
1875 -<!--20110331ysk start-->
1876 -<!-- <usces_pref><?php //echo serialize(get_option('usces_pref')); ?></usces_pref>-->
1877 -<!--20110331ysk end-->
1878 - <usces_shipping_rule><?php echo serialize(get_option('usces_shipping_rule')); ?></usces_shipping_rule>
1879 -
1880 -<?php
1881 -}
1882 -
1883 -function usces_all_change_zaiko(&$obj) {
1884 - global $wpdb, $usces;
1885 -
1886 - $ids = $_POST['listcheck'];
1887 - $status = true;
1888 - foreach ( (array)$ids as $post_id ){
1889 - $skus = $usces->get_skus($post_id);
1890 - foreach ( (array)$skus as $sku ){
1891 - $res = usces_update_sku( $post_id, $sku['code'], 'stock', (int)$_POST['change']['word']['zaiko'] );
1892 - if( !$res ){
1893 - $status = false;
1894 - }
1895 - }
1896 - }
1897 - if ( true === $status ) {
1898 - $obj->set_action_status('success', __('I completed collective operation.','usces'));
1899 - } elseif ( false === $status ) {
1900 - $obj->set_action_status('error', __('ERROR: I was not able to complete collective operation','usces'));
1901 - } else {
1902 - $obj->set_action_status('none', '');
1903 - }
1904 -}
1905 -
1906 -function usces_all_change_itemdisplay(&$obj){
1907 - global $wpdb;
1908 -
1909 - $ids = $_POST['listcheck'];
1910 - $post_status = $_POST['change']['word']['display_status'];
1911 - $status = true;
1912 - foreach ( (array)$ids as $post_id ):
1913 -// $query = $wpdb->prepare("UPDATE $wpdb->posts SET post_status = %s WHERE ID = %d", $post_status, $post_id);
1914 -// $res = $wpdb->query( $query );
1915 - $post_data = array('ID'=>$post_id, 'post_status'=>$post_status);
1916 - $res = wp_update_post( $post_data );
1917 -
1918 - if( $res == 0 ) {
1919 - $status = false;
1920 - }
1921 - endforeach;
1922 - if ( true === $status ) {
1923 - $obj->set_action_status('success', __('I completed collective operation.','usces'));
1924 - } elseif ( false === $status ) {
1925 - $obj->set_action_status('error', __('ERROR: I was not able to complete collective operation','usces'));
1926 - } else {
1927 - $obj->set_action_status('none', '');
1928 - }
1929 -}
1930 -
1931 -function usces_all_change_order_reciept(&$obj){
1932 - global $wpdb, $usces;
1933 -
1934 - $tableName = $wpdb->prefix . "usces_order";
1935 - $ids = $_POST['listcheck'];
1936 - $status = true;
1937 - foreach ( (array)$ids as $id ):
1938 -//20120306ysk start 0000324
1939 - //$query = $wpdb->prepare("SELECT order_status FROM $tableName WHERE ID = %d", $id);
1940 - //$statusstr = $wpdb->get_var( $query );
1941 - $query = $wpdb->prepare("SELECT order_status, mem_id, order_getpoint FROM $tableName WHERE ID = %d", $id);
1942 - $order_res = $wpdb->get_row( $query, ARRAY_A );
1943 - $statusstr = $order_res['order_status'];
1944 - $restore_point = false;
1945 - $getpoint = $order_res['order_getpoint'];
1946 - if( strpos($statusstr, 'cancel') !== false ) continue;//20131101ysk 0000751
1947 -//20120306ysk end
1948 - if(strpos($statusstr, 'noreceipt') === false && strpos($statusstr, 'receipted') === false) continue;
1949 - $old_status = $statusstr;//20120612ysk 0000501
1950 - if($_REQUEST['change']['word']['order_reciept'] == 'receipted') {
1951 -//20120306ysk start 0000324
1952 - //if(strpos($statusstr, 'noreceipt') !== false)
1953 - if(strpos($statusstr, 'noreceipt') !== false) {
1954 - $statusstr = str_replace('noreceipt', 'receipted', $statusstr);
1955 - //if( !$usces->is_status('completion', $order_res['order_status']) ) {
1956 - $restore_point = true;
1957 - $getpoint = $getpoint * -1;//add point
1958 - //}
1959 - }
1960 -//20120306ysk end
1961 - }elseif($_REQUEST['change']['word']['order_reciept'] == 'noreceipt') {
1962 -//20120306ysk start 0000324
1963 - //if(strpos($statusstr, 'receipted') !== false)
1964 - if(strpos($statusstr, 'receipted') !== false) {
1965 - $statusstr = str_replace('receipted', 'noreceipt', $statusstr);
1966 - //if( !$usces->is_status('completion', $order_res['order_status']) )
1967 - $restore_point = true;
1968 - }
1969 -//20120306ysk end
1970 - }
1971 - $query = $wpdb->prepare("UPDATE $tableName SET order_status = %s WHERE ID = %d", $statusstr, $id);
1972 - $res = $wpdb->query( $query );
1973 - if( $res === false ) {
1974 - $status = false;
1975 - }
1976 -//20120306ysk start 0000324
1977 - if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] ) {
1978 - if( !empty($order_res['mem_id']) && 0 < $order_res['order_getpoint'] ) {
1979 - if( $res && $restore_point ) usces_restore_point( $order_res['mem_id'], $getpoint );
1980 - }
1981 - }
1982 -//20120306ysk end
1983 - if( $status ) {
1984 - do_action( 'usces_action_collective_order_reciept_each', $id, $statusstr, $old_status );
1985 - }
1986 - endforeach;
1987 - if ( true === $status ) {
1988 - $obj->set_action_status('success', __('I completed collective operation.','usces'));
1989 - } elseif ( false === $status ) {
1990 - $obj->set_action_status('error', __('ERROR: I was not able to complete collective operation','usces'));
1991 - } else {
1992 - $obj->set_action_status('none', '');
1993 - }
1994 - do_action('usces_action_collective_order_reciept', array(&$obj));
1995 -}
1996 -
1997 -function usces_all_change_order_status(&$obj){
1998 - global $wpdb, $usces;
1999 -
2000 - $tableName = $wpdb->prefix . "usces_order";
2001 - $ids = $_POST['listcheck'];
2002 - foreach ( (array)$ids as $id ):
2003 - $status = true;
2004 -//20120306ysk start 0000324
2005 - //$query = $wpdb->prepare("SELECT order_status FROM $tableName WHERE ID = %d", $id);
2006 - //$statusstr = $wpdb->get_var( $query );
2007 - $query = $wpdb->prepare("SELECT order_status, mem_id, order_getpoint, order_usedpoint, order_payment_name FROM $tableName WHERE ID = %d", $id);
2008 - $order_res = $wpdb->get_row( $query, ARRAY_A );
2009 - $statusstr = $order_res['order_status'];
2010 - $restore_point = false;
2011 - $getpoint = $order_res['order_getpoint'];
2012 - $usedpoint = $order_res['order_usedpoint'];
2013 -//20120306ysk end
2014 - $old_status = $statusstr;//20120612ysk 0000501
2015 - switch ($_REQUEST['change']['word']['order_status']) {
2016 - case 'estimate':
2017 - if(strpos($statusstr, 'adminorder') !== false) {
2018 - $statusstr = str_replace('adminorder', 'estimate', $statusstr);
2019 - }else if(strpos($statusstr, 'estimate') === false) {
2020 - $statusstr .= 'estimate,';
2021 - }
2022 - break;
2023 - case 'adminorder':
2024 - if(strpos($statusstr, 'estimate') !== false) {
2025 - $statusstr = str_replace('estimate', 'adminorder', $statusstr);
2026 - }else if(strpos($statusstr, 'adminorder') === false) {
2027 - $statusstr .= 'adminorder,';
2028 - }
2029 - break;
2030 - case 'duringorder':
2031 - if(strpos($statusstr, 'cancel') !== false) {
2032 - $statusstr = str_replace('cancel', 'duringorder', $statusstr);
2033 -//20120919ysk start 0000573
2034 - if( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
2035 - $restore_point = true;
2036 - $getpoint = $getpoint * -1;//add point
2037 - } elseif( $usces->is_status('receipted', $order_res['order_status']) ) {
2038 - $restore_point = true;
2039 - $getpoint = $getpoint * -1;//add point
2040 - }
2041 -//20120919ysk end
2042 - }else if(strpos($statusstr, 'completion') !== false) {
2043 - $statusstr = str_replace('completion', 'duringorder', $statusstr);
2044 -//20120306ysk start 0000324
2045 - //if( !usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) && !$usces->is_status('receipted', $order_res['order_status']) )
2046 - // $restore_point = true;
2047 -//20120306ysk end
2048 - }else if(strpos($statusstr, 'new') !== false) {
2049 - $statusstr = str_replace('new', 'duringorder', $statusstr);
2050 - }else if(strpos($statusstr, 'duringorder') === false) {
2051 - $statusstr .= 'duringorder,';
2052 - }
2053 - break;
2054 - case 'cancel':
2055 - if(strpos($statusstr, 'completion') !== false) {
2056 - $statusstr = str_replace('completion', 'cancel', $statusstr);
2057 -//20120306ysk start 0000324
2058 - //if( !usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) && !$usces->is_status('receipted', $order_res['order_status']) )
2059 - // $restore_point = true;
2060 -//20120306ysk end
2061 - }else if(strpos($statusstr, 'new') !== false) {
2062 - $statusstr = str_replace('new', 'cancel', $statusstr);
2063 - }else if(strpos($statusstr, 'duringorder') !== false) {
2064 - $statusstr = str_replace('duringorder', 'cancel', $statusstr);
2065 - }else if(strpos($statusstr, 'cancel') === false) {
2066 - $statusstr .= 'cancel,';
2067 - }
2068 -//20120919ysk start 0000573
2069 - if( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
2070 - $restore_point = true;
2071 - $usedpoint = $usedpoint * -1;//add point
2072 - } elseif( $usces->is_status('receipted', $order_res['order_status']) ) {
2073 - $restore_point = true;
2074 - $usedpoint = $usedpoint * -1;//add point
2075 - }
2076 -//20120919ysk end
2077 - break;
2078 - case 'completion':
2079 - if(strpos($statusstr, 'new') !== false) {
2080 - $statusstr = str_replace('new', 'completion', $statusstr);
2081 - }else if(strpos($statusstr, 'duringorder') !== false) {
2082 - $statusstr = str_replace('duringorder', 'completion', $statusstr);
2083 - }else if(strpos($statusstr, 'cancel') !== false) {
2084 - $statusstr = str_replace('cancel', 'completion', $statusstr);
2085 -//20120919ysk start 0000573
2086 - if( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
2087 - $restore_point = true;
2088 - $getpoint = $getpoint * -1;//add point
2089 - } elseif( $usces->is_status('receipted', $order_res['order_status']) ) {
2090 - $restore_point = true;
2091 - $getpoint = $getpoint * -1;//add point
2092 - }
2093 -//20120919ysk end
2094 - }else if(strpos($statusstr, 'completion') === false) {
2095 - $statusstr .= 'completion,';
2096 - }
2097 -//20120306ysk start 0000324
2098 - //if( !usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) && !$usces->is_status('receipted', $order_res['order_status']) ) {
2099 - // $restore_point = true;
2100 - // $getpoint = $getpoint * -1;//add point
2101 - //}
2102 -//20120306ysk end
2103 - break;
2104 - case 'new':
2105 - if(strpos($statusstr, 'duringorder') !== false) {
2106 - $statusstr = str_replace('duringorder,', '', $statusstr);
2107 - }else if(strpos($statusstr, 'completion') !== false) {
2108 - $statusstr = str_replace('completion,', '', $statusstr);
2109 -//20120306ysk start 0000324
2110 - //if( !usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) && !$usces->is_status('receipted', $order_res['order_status']) )
2111 - // $restore_point = true;
2112 -//20120306ysk end
2113 - }else if(strpos($statusstr, 'cancel') !== false) {
2114 - $statusstr = str_replace('cancel,', '', $statusstr);
2115 -//20120919ysk start 0000573
2116 - if( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
2117 - $restore_point = true;
2118 - $getpoint = $getpoint * -1;//add point
2119 - } elseif( $usces->is_status('receipted', $order_res['order_status']) ) {
2120 - $restore_point = true;
2121 - $getpoint = $getpoint * -1;//add point
2122 - }
2123 -//20120919ysk end
2124 - }
2125 - break;
2126 - }
2127 - $query = $wpdb->prepare("UPDATE $tableName SET order_status = %s WHERE ID = %d", $statusstr, $id);
2128 - $res = $wpdb->query( $query );
2129 - if( $res === false ) {
2130 - $status = false;
2131 - }
2132 -//20120306ysk start 0000324
2133 - if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] ) {
2134 - if( !empty($order_res['mem_id']) && ( 0 < $order_res['order_getpoint'] || 0 < $order_res['order_usedpoint'] ) ) {
2135 - if( $res && $restore_point ) usces_restore_point( $order_res['mem_id'], $getpoint + $usedpoint );
2136 - }
2137 - }
2138 -//20120306ysk end
2139 -//20120612ysk 0000501 start
2140 - if( $status ) {
2141 - do_action('usces_action_collective_order_status_each', $id, $statusstr, $old_status);
2142 - }
2143 -//20120612ysk end
2144 - endforeach;
2145 - if ( true === $status ) {
2146 - $obj->set_action_status('success', __('I completed collective operation.','usces'));
2147 - } elseif ( false === $status ) {
2148 - $obj->set_action_status('error', __('ERROR: I was not able to complete collective operation','usces'));
2149 - } else {
2150 - $obj->set_action_status('none', '');
2151 - }
2152 - do_action('usces_action_collective_order_status', array(&$obj));
2153 -}
2154 -
2155 -function usces_all_delete_order_data(&$obj){
2156 - global $wpdb, $usces;
2157 -
2158 - $tableName = $wpdb->prefix . "usces_order";
2159 - $tableMetaName = $wpdb->prefix . "usces_order_meta";
2160 - $ids = $_POST['listcheck'];
2161 - $status = true;
2162 - foreach ( (array)$ids as $id ):
2163 - $del = usces_delete_order_check( $id );
2164 - if( $del === false ) continue;
2165 -//20130625ysk start 0000721
2166 -//20120306ysk start 0000324
2167 - //$restore_point = false;
2168 - $point = 0;
2169 - $query = $wpdb->prepare("SELECT * FROM $tableName WHERE ID = %d", $id);
2170 - $order_res = $wpdb->get_row( $query, ARRAY_A );
2171 - if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] && !empty($order_res['mem_id']) && !$usces->is_status('cancel', $order_res['order_status']) ) {
2172 - //$query = $wpdb->prepare("SELECT * FROM $tableName WHERE ID = %d", $id);
2173 - //$order_res = $wpdb->get_row( $query, ARRAY_A );
2174 - if( 0 < $order_res['order_getpoint'] ) {
2175 - //if( $usces->is_status('completion', $order_res['order_status']) ) {
2176 - // $restore_point = true;
2177 - //} else {
2178 - if( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) || $usces->is_status('receipted', $order_res['order_status']) )
2179 - //$restore_point = true;
2180 - $point += $order_res['order_getpoint'];
2181 - //}
2182 - }
2183 - if( 0 < $order_res['order_usedpoint'] ) {
2184 - $point -= $order_res['order_usedpoint'];
2185 - }
2186 - }
2187 -//20120306ysk end
2188 - $query = $wpdb->prepare("DELETE FROM $tableName WHERE ID = %d", $id);
2189 - $res = $wpdb->query( $query );
2190 - if( $res === false ) {
2191 - $status = false;
2192 - }else{
2193 -
2194 - if( 0 != $point ) usces_restore_point( $order_res['mem_id'], $point );
2195 -
2196 - do_action('usces_action_collective_order_delete_each', $id, $order_res);
2197 -
2198 - $metaquery = $wpdb->prepare("DELETE FROM $tableMetaName WHERE order_id = %d", $id);//0000427
2199 - $metares = $wpdb->query( $metaquery );
2200 - }
2201 - endforeach;
2202 - if ( true === $status ) {
2203 - $obj->set_action_status('success', __('I completed collective operation.','usces'));
2204 - } elseif ( false === $status ) {
2205 - $obj->set_action_status('error', __('ERROR: I was not able to complete collective operation','usces'));
2206 - } else {
2207 - $obj->set_action_status('none', '');
2208 - }
2209 - do_action('usces_action_collective_order_delete', array(&$obj));
2210 -}
2211 -
2212 -function usces_check_acting_return() {
2213 - global $usces;
2214 - $entry = $usces->cart->get_entry();
2215 -
2216 - $acting = $_GET['acting'];
2217 - $results = array();
2218 - switch ( $acting ) {
2219 - case 'epsilon':
2220 - if(isset($_GET['duplicate']) && $_GET['duplicate'] == 1){
2221 - $results[0] = 'duplicate';
2222 - }else if(isset($_GET['result'])){
2223 - $results[0] = (int)$_GET['result'];
2224 - $results['reg_order'] = true;
2225 - }else{
2226 - $str = explode('?', $_GET['acting_return']);
2227 - if(!isset($str[1])) {
2228 - $results[0] = 0;
2229 - }else{
2230 - $para = parse_str($str[1]);
2231 - $results[0] = isset($para['result']) ? (int)$para['result'] : 0;
2232 - foreach($para as $key => $value){
2233 - $results[$key] = $value;
2234 - }
2235 - }
2236 -
2237 - }
2238 - $results['reg_order'] = true;
2239 - break;
2240 -
2241 - case 'paypal':
2242 - usces_log('paypal in ', 'acting_transaction.log');
2243 - require_once($usces->options['settlement_path'] . "paypal.php");
2244 - $results = paypal_check($usces_paypal_url);
2245 - remove_action( 'wp_footer', array(&$usces, 'lastprocessing'));
2246 - $results['reg_order'] = true;
2247 - break;
2248 -
2249 - case 'zeus_card':
2250 - $results = $_REQUEST;
2251 - if( $_REQUEST['acting_return'] && isset($_REQUEST['wctid']) && usces_is_trusted_acting_data($_REQUEST['wctid']) ){
2252 - $results[0] = 1;
2253 - }else{
2254 - $results[0] = 0;
2255 - }
2256 - $results['reg_order'] = true;
2257 - break;
2258 -
2259 - case 'zeus_conv':
2260 - $results = $_GET;
2261 - if( $_REQUEST['acting_return'] ){
2262 - $results[0] = 1;
2263 - }else{
2264 - $results[0] = 0;
2265 - }
2266 - $results['reg_order'] = false;
2267 - break;
2268 -
2269 - case 'remise_card':
2270 - $results = $_POST;
2271 - if( $_REQUEST['acting_return'] && ( isset($_REQUEST['X-ERRCODE']) && ' ' === $_REQUEST['X-ERRCODE'] ) ){
2272 - usces_log('remise card entry data : '.print_r($entry, true), 'acting_transaction.log');
2273 - $results[0] = 1;
2274 - }else{
2275 - $results[0] = 0;
2276 - }
2277 - if( isset($_REQUEST['dlseller_update']) ){
2278 - $results['reg_order'] = false;
2279 - }else{
2280 - $results['reg_order'] = true;
2281 - }
2282 - break;
2283 -
2284 - case 'remise_conv':
2285 - $results = $_GET;
2286 - if( $_REQUEST['acting_return'] && isset($_REQUEST['X-JOB_ID']) && '0:0000' === $_REQUEST['X-R_CODE']){
2287 - //usces_log('remise conv entry data : '.print_r($entry, true), 'acting_transaction.log');
2288 - $results[0] = 1;
2289 - }else{
2290 - $results[0] = 0;
2291 - }
2292 - $results['reg_order'] = true;
2293 - break;
2294 -
2295 -//20101018ysk start
2296 - case 'jpayment_card':
2297 - $results = $_GET;
2298 - if($_GET['rst'] == 2) {
2299 - usces_log('jpayment card error : '.print_r($entry, true), 'acting_transaction.log');
2300 - }
2301 - $results[0] = ($_GET['rst'] == 1) ? 1 : 0;
2302 - $results['reg_order'] = true;
2303 - break;
2304 -
2305 - case 'jpayment_conv':
2306 - $results = $_GET;
2307 - if($_GET['rst'] == 2) {
2308 - usces_log('jpayment conv error : '.print_r($entry, true), 'acting_transaction.log');
2309 - }
2310 - $results[0] = ($_GET['rst'] == 1 and $_GET['ap'] == 'CPL_PRE') ? 1 : 0;
2311 - $results['reg_order'] = true;
2312 - break;
2313 -
2314 - case 'jpayment_bank':
2315 - $results = $_GET;
2316 - if($_GET['rst'] == 2) {
2317 - usces_log('jpayment bank error : '.print_r($entry, true), 'acting_transaction.log');
2318 - }
2319 - $results[0] = ($_GET['rst'] == 1) ? 1 : 0;
2320 - $results['reg_order'] = true;
2321 - break;
2322 -//20101018ysk end
2323 -//20110208ysk start
2324 - case 'paypal_ec':
2325 - $results = $_GET;
2326 -
2327 - //Build a second API request to PayPal, using the token as the ID to get the details on the payment authorization
2328 - $req_token = isset($_REQUEST['token']) ? $_REQUEST['token'] : '0';
2329 - $nvpstr = "&TOKEN=".urlencode($req_token);
2330 -
2331 - $usces->paypal->setMethod('GetExpressCheckoutDetails');
2332 - $usces->paypal->setData($nvpstr);
2333 - $res = $usces->paypal->doExpressCheckout();
2334 - $resArray = $usces->paypal->getResponse();
2335 - $ack = strtoupper($resArray["ACK"]);
2336 - if($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
2337 -//20121009ysk start 0000587
2338 -//20121225ysk start 000634
2339 - $cart = $usces->cart->get_cart();
2340 - $charging_type = $usces->getItemChargingType($cart[0]['post_id'], $cart);
2341 - if( 'continue' == $charging_type ) {
2342 - $results[0] = 1;
2343 - } else {
2344 -//20121225ysk end
2345 - if( (float)$resArray["AMT"] != (float)$entry['order']['total_full_price'] ) {
2346 - usces_log('PayPal : AMT Error. AMT='.$resArray["AMT"].', total_full_price='.$entry['order']['total_full_price'], 'acting_transaction.log');
2347 - $results[0] = 0;
2348 - } else {
2349 - $results[0] = 1;
2350 - }
2351 - }
2352 -//20121009ysk end
2353 -
2354 - } else {
2355 - //Display a user friendly Error on the page using any of the following error information returned by PayPal
2356 - $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
2357 - $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
2358 - $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
2359 - $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
2360 - usces_log('PayPal : GetExpressCheckoutDetails API call failed. Error Code:['.$ErrorCode.'] Error Severity Code:['.$ErrorSeverityCode.'] Short Error Message:'.$ErrorShortMsg.' Detailed Error Message:'.$ErrorLongMsg, 'acting_transaction.log');
2361 - $results[0] = 0;
2362 - }
2363 - $results['reg_order'] = true;
2364 - break;
2365 -//20110208ysk end
2366 -//20120413ysk start
2367 - case 'sbps_card':
2368 - case 'sbps_wallet':
2369 - case 'sbps_mobile':
2370 -/* if( isset($_REQUEST['cancel']) ) {
2371 - $results[0] = 0;
2372 - $results['reg_order'] = false;
2373 -
2374 - } else {
2375 - if( isset($_REQUEST['res_result']) and 'OK' == $_REQUEST['res_result'] ) {
2376 - usces_log($acting.' entry data : '.print_r($entry, true), 'acting_transaction.log');
2377 - $results[0] = 1;
2378 - } else {
2379 - usces_log($acting.' error : '.print_r($_REQUEST,true), 'acting_transaction.log');
2380 - $results[0] = 0;
2381 - }
2382 - $results['reg_order'] = true;
2383 - }
2384 - break;*/
2385 - case 'sbps_conv':
2386 - case 'sbps_payeasy':
2387 - if( isset($_REQUEST['cancel']) ) {
2388 - $results[0] = 0;
2389 - $results['reg_order'] = false;
2390 -
2391 - } else {
2392 - if( isset($_REQUEST['res_result']) and 'OK' == $_REQUEST['res_result'] ) {
2393 - $results[0] = 1;
2394 - } else {
2395 - //usces_log($acting.' error : '.print_r($_REQUEST,true), 'acting_transaction.log');
2396 - $results[0] = 0;
2397 - }
2398 - $results['reg_order'] = false;
2399 - }
2400 - break;
2401 -//20120413ysk end
2402 -//20120618ysk start
2403 - case 'telecom_card':
2404 - $results = $_GET;
2405 - if( $_REQUEST['result'] ){
2406 - usces_log($acting.' entry data : '.print_r($entry, true), 'acting_transaction.log');
2407 - $results[0] = 1;
2408 - }else{
2409 - usces_log($acting.' error : '.print_r($_REQUEST,true), 'acting_transaction.log');
2410 - $results[0] = 0;
2411 - }
2412 - $results['reg_order'] = true;
2413 - break;
2414 -//20120618ysk end
2415 -//20121206ysk start
2416 - case 'digitalcheck_card':
2417 - $results = $_REQUEST;
2418 - if( isset($_REQUEST['SID']) ) {
2419 - $results[0] = 1;
2420 - } else {
2421 - $results[0] = 0;
2422 - }
2423 - $results['reg_order'] = true;
2424 - break;
2425 - case 'digitalcheck_conv':
2426 - $results = $_REQUEST;
2427 - //if( isset($_REQUEST['SID']) ) {
2428 - $results[0] = 1;
2429 - //} else {
2430 - // $results[0] = 0;
2431 - //}
2432 - $results['reg_order'] = false;
2433 - break;
2434 -//20121206ysk end
2435 -//20130225ysk start
2436 - case 'mizuho_card':
2437 - case 'mizuho_conv':
2438 - $results = $_GET;
2439 - if( isset($_GET['rsltcd']) ) {
2440 - if( '000' == substr($_GET['rsltcd'], 0, 3) ) {
2441 - $results[0] = 1;
2442 - $results['reg_order'] = true;
2443 - } else {
2444 - $results[0] = 0;
2445 - $results['reg_order'] = false;
2446 - }
2447 - } else {
2448 - $results[0] = 0;
2449 - $results['reg_order'] = false;
2450 - }
2451 - break;
2452 -//20130225ysk end
2453 -//20131220ysk start
2454 - case 'anotherlane_card':
2455 - $results[0] = 1;
2456 - $results['reg_order'] = false;
2457 - break;
2458 -//20131220ysk end
2459 -//20140206ysk start
2460 - case 'veritrans_card':
2461 - case 'veritrans_conv':
2462 - $results[0] = ( isset($_GET['result']) ) ? $_GET['result'] : 0;
2463 - $results['reg_order'] = false;
2464 - break;
2465 -//20140206ysk end
2466 -
2467 - default:
2468 - do_action( 'usces_action_check_acting_return_default' );
2469 - $results = $_REQUEST;//20140227ysk
2470 - if( isset($_REQUEST['result']) and true == $_REQUEST['result'] ) {
2471 - usces_log($acting.' entry data : '.print_r($entry, true), 'acting_transaction.log');
2472 - $results[0] = 1;
2473 - }else{
2474 - usces_log($acting.' error : '.print_r($_REQUEST, true), 'acting_transaction.log');
2475 - $results[0] = 0;
2476 - }
2477 -//20110310ysk start
2478 - //$results['reg_order'] = false;
2479 - $results['reg_order'] = true;
2480 -//20110310ysk end
2481 - $results = apply_filters( 'usces_filter_check_acting_return_results', $results );//20140227ysk
2482 - break;
2483 - }
2484 -
2485 - return $results;
2486 -}
2487 -//20110203ysk start
2488 -function usces_check_acting_return_duplicate( $results = array() ) {
2489 - global $wpdb;
2490 - $acting = isset($_GET['acting']) ? $_GET['acting'] : '';
2491 -// usces_log('$_REQUEST : '.print_r($_REQUEST,true), 'acting_transaction.log');
2492 -// usces_log('$results : '.print_r($results,true), 'acting_transaction.log');
2493 -
2494 - switch($acting) {
2495 - case 'epsilon':
2496 - $trans_id = isset($_REQUEST['trans_code']) ? $_REQUEST['trans_code'] : '';
2497 - break;
2498 -//20110208ysk start
2499 - case 'paypal':
2500 - $trans_id = isset($results['txn_id']) ? $results['txn_id'] : '';
2501 - break;
2502 -//20110208ysk end
2503 - case 'paypal_ipn':
2504 - $trans_id = isset($_REQUEST['txn_id']) ? $_REQUEST['txn_id'] : '';
2505 - break;
2506 -//20110208ysk start
2507 - case 'paypal_ec':
2508 - $trans_id = isset($_REQUEST['token']) ? $_REQUEST['token'] : '';
2509 - break;
2510 -//20110208ysk end
2511 - case 'zeus_card':
2512 - $trans_id = isset($_REQUEST['ordd']) ? $_REQUEST['ordd'] : '';
2513 - break;
2514 - case 'zeus_conv':
2515 - case 'zeus_bank':
2516 - $trans_id = isset($_REQUEST['order_no']) ? $_REQUEST['order_no'] : '';
2517 - break;
2518 - case 'remise_card':
2519 - $trans_id = isset($_REQUEST['X-TRANID']) ? $_REQUEST['X-TRANID'] : '';
2520 - break;
2521 - case 'remise_conv':
2522 - $trans_id = isset($_REQUEST['X-JOB_ID']) ? $_REQUEST['X-JOB_ID'] : '';
2523 - break;
2524 - case 'jpayment_card':
2525 - case 'jpayment_conv':
2526 - case 'jpayment_bank':
2527 - $trans_id = isset($_REQUEST['gid']) ? $_REQUEST['gid'] : '';
2528 - break;
2529 -//20120413ysk start
2530 - case 'sbps_card':
2531 - case 'sbps_conv':
2532 - case 'sbps_payeasy':
2533 - case 'sbps_wallet':
2534 - case 'sbps_mobile':
2535 - $trans_id = isset($_REQUEST['order_id']) ? $_REQUEST['order_id'] : '';
2536 - break;
2537 -//20120413ysk end
2538 -//20120618ysk start
2539 - case 'telecom_card':
2540 - $trans_id = isset($_REQUEST['sendid']) ? $_REQUEST['sendid'] : '';
2541 - break;
2542 -//20120618ysk end
2543 -//20121206ysk start
2544 - case 'digitalcheck_card':
2545 - case 'digitalcheck_conv':
2546 - $trans_id = isset($_REQUEST['SID']) ? $_REQUEST['SID'] : '';
2547 - break;
2548 -//20121206ysk end
2549 -//20130225ysk start
2550 - case 'mizuho_card':
2551 - case 'mizuho_conv':
2552 - $trans_id = isset($_REQUEST['stran']) ? $_REQUEST['stran'] : '';
2553 - break;
2554 -//20130225ysk end
2555 - default:
2556 - $trans_id = '';
2557 - }
2558 - $table_meta_name = $wpdb->prefix.'usces_order_meta';
2559 - $query = $wpdb->prepare("SELECT order_id FROM $table_meta_name WHERE meta_key = %s AND meta_value = %s", 'trans_id', $trans_id);
2560 - $order_id = $wpdb->get_var($query);
2561 - return $order_id;
2562 -}
2563 -//20110203ysk end
2564 -
2565 -//20111111ysk start
2566 -function usces_dates_interconv( $date_str ) {
2567 - $base_struc = preg_split('[/.-]', 'd/m/Y' );
2568 - $date_str_parts = preg_split('[/.-]', $date_str );
2569 - $date_elements = array();
2570 -
2571 - $p_keys = array_keys( $base_struc );
2572 - foreach( $p_keys as $p_key ) {
2573 - if( !empty( $date_str_parts[$p_key] )) {
2574 - $date_elements[$base_struc[$p_key]] = $date_str_parts[$p_key];
2575 - } else {
2576 - return false;
2577 - }
2578 - }
2579 - $dummy_ts = mktime( 0,0,0, $date_elements['m'],$date_elements['d'],$date_elements['Y']);
2580 - return date( 'Y-m-d', $dummy_ts );
2581 -}
2582 -//20101111ysk end
2583 -
2584 -function usces_register_action($handle, $type, $key, $value, $function){
2585 - global $usces_action;
2586 - $usces_action[$handle] = array('type'=>$type, 'key'=>$key, 'value'=>$value, 'function'=>$function);
2587 -}
2588 -
2589 -function usces_deregister_action($handle){
2590 - global $usces_action;
2591 - unset($usces_action[$handle]);
2592 -}
2593 -
2594 -function usces_get_wcexp($post_id, $name=''){
2595 - $wcexp = get_post_meta($post_id, '_wcexp', true);
2596 - if( empty($name) ){
2597 - $value = ( $wcexp !== false ) ? $wcexp : '';
2598 - }else{
2599 - $value = ($wcexp !== false && isset($wcexp[$name])) ? $wcexp[$name] : '';
2600 - }
2601 - return $value;
2602 -}
2603 -
2604 -function usces_update_check_admin($result){
2605 - $result = true;
2606 - return $result;
2607 -}
2608 -
2609 -function usces_setup_cod_ajax(){
2610 - global $usces;
2611 - $usces->options = get_option('usces');
2612 - $message = '';
2613 - $_POST = $usces->stripslashes_deep_post($_POST);
2614 -
2615 - $usces->options['cod_type'] = isset($_POST['cod_type']) ? $_POST['cod_type'] : 'fix';
2616 - if( isset($_POST['cod_fee']) )
2617 - $usces->options['cod_fee'] = (int)$_POST['cod_fee'];
2618 -
2619 - if( 'fix' == $usces->options['cod_type'] ){
2620 - if( isset($_POST['cod_limit_amount']) ){
2621 - $usces->options['cod_limit_amount'] = (int)$_POST['cod_limit_amount'];
2622 - if( !WCUtils::is_blank($_POST['cod_limit_amount']) && 0 === (int)$_POST['cod_limit_amount'] )
2623 - $message = __('There is the item where a value is dirty.', 'usces');
2624 - }
2625 -
2626 - }elseif( 'change' == $usces->options['cod_type'] ){
2627 - if( isset($_POST['cod_first_amount']) ){
2628 - $usces->options['cod_first_amount'] = (int)$_POST['cod_first_amount'];
2629 - if( 0 === (int)$_POST['cod_first_amount'] )
2630 - $message = __('There is the item where a value is dirty.', 'usces');
2631 - }
2632 - if( isset($_POST['cod_limit_amount']) ){
2633 - $usces->options['cod_limit_amount'] = (int)$_POST['cod_limit_amount'];
2634 - if( !WCUtils::is_blank($_POST['cod_limit_amount']) && 0 === (int)$_POST['cod_limit_amount'] )
2635 - $message = __('There is the item where a value is dirty.', 'usces');
2636 - }
2637 - if( isset($_POST['cod_first_fee']) ){
2638 - $usces->options['cod_first_fee'] = (int)$_POST['cod_first_fee'];
2639 - if( 0 === (int)$_POST['cod_first_fee'] && '0' !== $_POST['cod_first_fee'])
2640 - $message = __('There is the item where a value is dirty.', 'usces');
2641 - }
2642 - if( isset($_POST['cod_end_fee']) ){
2643 - $usces->options['cod_end_fee'] = (int)$_POST['cod_end_fee'];
2644 - if( 0 === (int)$_POST['cod_end_fee'] && '0' !== $_POST['cod_end_fee'] )
2645 - $message = __('There is the item where a value is dirty.', 'usces');
2646 - }
2647 -
2648 - unset($usces->options['cod_amounts'], $usces->options['cod_fees']);
2649 - if( isset($_POST['cod_amounts']) ){
2650 - for($i=0; $i<count((array)$_POST['cod_amounts']); $i++){
2651 - $usces->options['cod_amounts'][$i] = (int)$_POST['cod_amounts'][$i];
2652 - $usces->options['cod_fees'][$i] = (int)$_POST['cod_fees'][$i];
2653 - if( 0 === (int)$_POST['cod_amounts'][$i] || (0 === (int)$_POST['cod_fees'][$i] && '0' !== $_POST['cod_fees'][$i]) )
2654 - $message = __('There is the item where a value is dirty.', 'usces');
2655 - }
2656 - }
2657 - }
2658 -
2659 -
2660 - if( '' == $message ){
2661 - $r = 'success';
2662 - update_option('usces', $usces->options);
2663 - }else{
2664 - $r = '<span style="color:red;">' . $message . '</span>';
2665 - }
2666 - die( $r );
2667 -}
2668 -
2669 -function usces_get_order_acting_data($rand){
2670 - global $wpdb;
2671 -
2672 - $table_name = $wpdb->prefix . "usces_access";
2673 - $query = $wpdb->prepare("SELECT acc_str1 AS sesid, acc_value AS order_data FROM $table_name WHERE acc_key = %s", $rand);
2674 - $res = $wpdb->get_row($query, ARRAY_A);
2675 - if($res == NULL){
2676 - return false;
2677 - }else{
2678 - return $res;
2679 - }
2680 -}
2681 -
2682 -function usces_auth_order_acting_data($rand){
2683 - global $usces, $wpdb;
2684 - $datas = usces_get_order_acting_data($rand);
2685 - $data = unserialize($datas['order_data']);
2686 - usces_log('usces_auth_order_acting_data', 'acting_transaction.log');
2687 - $data['propriety'] = 1;
2688 -
2689 - $data = serialize($data);
2690 - $table_name = $wpdb->prefix . "usces_access";
2691 - $query = $wpdb->prepare("UPDATE $table_name SET acc_value = %s WHERE acc_type = %s AND acc_key = %s",
2692 - $data,
2693 - 'acting_data',
2694 - $rand
2695 - );
2696 - $res = $wpdb->query($query);
2697 -}
2698 -
2699 -function usces_ordered_acting_data($rand){
2700 - global $usces, $wpdb;
2701 - $datas = usces_get_order_acting_data($rand);
2702 - $data = unserialize($datas['order_data']);
2703 - usces_log('usces_ordered_acting_data', 'acting_transaction.log');
2704 - $data['order_received'] = 1;
2705 -
2706 - $data = serialize($data);
2707 - $table_name = $wpdb->prefix . "usces_access";
2708 - $query = $wpdb->prepare("UPDATE $table_name SET acc_value = %s WHERE acc_type = %s AND acc_key = %s",
2709 - $data,
2710 - 'acting_data',
2711 - $rand
2712 - );
2713 - $res = $wpdb->query($query);
2714 -}
2715 -
2716 -function usces_is_trusted_acting_data($rand){
2717 - global $usces, $wpdb;
2718 - $datas = usces_get_order_acting_data($rand);
2719 - $data = unserialize($datas['order_data']);
2720 - usces_log('usces_is_trusted_acting_data', 'acting_transaction.log');
2721 - if( isset($data['propriety']) && $data['propriety'] && !isset($data['order_received']) )
2722 - return true;
2723 - else
2724 - return false;
2725 -}
2726 -
2727 -function usces_get_filename( $path ){
2728 - $res = array();
2729 - if ( $handle = opendir($path) ) {
2730 - while (false !== ($file = readdir($handle))) {
2731 - if( '.' != $file && '..' != $file )
2732 - $res[] = $file;
2733 - }
2734 - closedir($handle);
2735 - }
2736 - return $res;
2737 -}
2738 -
2739 -function usces_locales(){
2740 - $res = array();
2741 - if ( $handle = opendir(USCES_PLUGIN_DIR.'/languages/') ) {
2742 - while (false !== ($file = readdir($handle))) {
2743 - if( '.' != $file && '..' != $file && preg_match('/^usces-(.+)\.mo$/', $file, $matches) ){
2744 - $res[] = $matches[1];
2745 - }
2746 - }
2747 - closedir($handle);
2748 - }
2749 - return $res;
2750 -}
2751 -
2752 -function usces_get_local_language(){
2753 - $locale = get_locale();
2754 - switch( $locale ){
2755 - case '':
2756 - case 'en':
2757 - case 'en_US':
2758 - $front_lang = 'en';
2759 - break;
2760 - case 'ja':
2761 - case 'ja_JP':
2762 - $front_lang = 'ja';
2763 - break;
2764 - default:
2765 - $front_lang = 'others';
2766 - }
2767 - return $front_lang;
2768 -}
2769 -
2770 -function usces_get_base_country(){
2771 - global $usces_settings;
2772 -// $locale = get_locale();
2773 - $wplang = defined('WPLANG') ? WPLANG : '';
2774 - $locale = empty( $wplang ) ? 'en' : $wplang;
2775 - if( array_key_exists($locale, $usces_settings['lungage2country']) )
2776 - return $usces_settings['lungage2country'][$locale];
2777 - else
2778 - return 'US';
2779 -}
2780 -
2781 -function usces_get_local_addressform(){
2782 - global $usces_settings;
2783 - $base = usces_get_base_country();
2784 - if( array_key_exists($base, $usces_settings['addressform']) )
2785 - return $usces_settings['addressform'][$base];
2786 - else
2787 - return 'US';
2788 -}
2789 -
2790 -function usces_get_local_target_market(){
2791 - $base = usces_get_base_country();
2792 - return (array)$base;
2793 -}
2794 -
2795 -function usces_get_apply_addressform($country){
2796 - global $usces_settings;
2797 - return $usces_settings['addressform'][$country];
2798 -}
2799 -
2800 -function usces_remove_filter(){
2801 - global $usces, $post;
2802 -
2803 - if( is_single() && 'item' == $post->post_mime_type ) {
2804 - remove_filter('the_content', array(&$usces, 'filter_itemPage'));
2805 -
2806 - }else if( $usces->is_cart_page($_SERVER['REQUEST_URI']) || $usces->is_inquiry_page($_SERVER['REQUEST_URI']) ){
2807 - remove_action('the_post', array(&$usces, 'action_cartFilter'));
2808 - remove_filter('the_title', array(&$usces, 'filter_cartTitle'),20);
2809 - remove_filter('the_content', array(&$usces, 'filter_cartContent'),20);
2810 -
2811 - }else if( $usces->is_member_page($_SERVER['REQUEST_URI']) ){
2812 - remove_action('the_post', array(&$usces, 'action_memberFilter'));
2813 - remove_filter('the_title', array(&$usces, 'filter_memberTitle'),20);
2814 - remove_filter('the_content', array(&$usces, 'filter_memberContent'),20);
2815 -
2816 - }else{
2817 - remove_action('the_post', array(&$usces, 'goDefaultPage'));
2818 - }
2819 -}
2820 -
2821 -function usces_reset_filter(){
2822 - global $usces, $post;
2823 -
2824 - if( is_single() && 'item' == $post->post_mime_type ) {
2825 - add_filter('the_content', array(&$usces, 'filter_itemPage'));
2826 -
2827 - }else if( $usces->is_cart_page($_SERVER['REQUEST_URI']) || $usces->is_inquiry_page($_SERVER['REQUEST_URI']) ){
2828 - add_action('the_post', array(&$usces, 'action_cartFilter'));
2829 - add_filter('the_title', array(&$usces, 'filter_cartTitle'),20);
2830 - add_filter('the_content', array(&$usces, 'filter_cartContent'),20);
2831 -
2832 - }else if( $usces->is_member_page($_SERVER['REQUEST_URI']) ){
2833 - add_action('the_post', array(&$usces, 'action_memberFilter'));
2834 - add_filter('the_title', array(&$usces, 'filter_memberTitle'),20);
2835 - add_filter('the_content', array(&$usces, 'filter_memberContent'),20);
2836 -
2837 - }else{
2838 - add_action('the_post', array(&$usces, 'goDefaultPage'));
2839 - }
2840 -}
2841 -
2842 -
2843 -function usces_get_wcex(){
2844 - $wcex = array();
2845 - if( defined('WCEX_DLSELLER_VERSION'))
2846 - $wcex['DLSELLER'] = array('name'=>'Dl Seller', 'version'=>WCEX_DLSELLER_VERSION);
2847 - if( defined('WCEX_ITEM_LIST_LAYOUT_VERSION'))
2848 - $wcex['ITEM_LIST_LAYOUT'] = array('name'=>'Item List Layout', 'version'=>WCEX_ITEM_LIST_LAYOUT_VERSION);
2849 - if( defined('WCEX_MOBILE_VERSION'))
2850 - $wcex['MOBILE'] = array('name'=>'Mobile', 'version'=>WCEX_MOBILE_VERSION);
2851 - if( defined('WCEX_MULTIPRICE_VERSION'))
2852 - $wcex['MULTIPRICE'] = array('name'=>'Multi Price', 'version'=>WCEX_MULTIPRICE_VERSION);
2853 - if( defined('WCEX_SLIDE_SHOWCASE_VERSION'))
2854 - $wcex['SLIDE_SHOWCASE'] = array('name'=>'Slide Showcase', 'version'=>WCEX_SLIDE_SHOWCASE_VERSION);
2855 - if( defined('WCEX_WIDGET_CART_VERSION'))
2856 - $wcex['WIDGET_CART'] = array('name'=>'Widget Cart', 'version'=>WCEX_WIDGET_CART_VERSION);
2857 -
2858 - return $wcex;
2859 -}
2860 -
2861 -function usces_trackPageview_cart($push){
2862 - $push = array();
2863 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2864 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_cart'";
2865 - }else{
2866 - $push[] = "'_trackPageview','/wc_cart'";
2867 - }
2868 - return $push;
2869 -}
2870 -
2871 -function usces_trackPageview_customer($push){
2872 - $push = array();
2873 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2874 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_customer'";
2875 - }else{
2876 - $push[] = "'_trackPageview','/wc_customer'";
2877 - }
2878 - return $push;
2879 -}
2880 -
2881 -function usces_trackPageview_delivery($push){
2882 - $push = array();
2883 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2884 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_delivery'";
2885 - }else{
2886 - $push[] = "'_trackPageview','/wc_delivery'";
2887 - }
2888 - return $push;
2889 -}
2890 -
2891 -function usces_trackPageview_confirm($push){
2892 - $push = array();
2893 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2894 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_confirm'";
2895 - }else{
2896 - $push[] = "'_trackPageview','/wc_confirm'";
2897 - }
2898 - return $push;
2899 -}
2900 -
2901 -function usces_trackPageview_ordercompletion($push){
2902 - global $usces;
2903 - $sesdata = $usces->cart->get_entry();
2904 - $order_id = $sesdata['order']['ID'];
2905 - $data = $usces->get_order_data($order_id, 'direct');
2906 - $cart = unserialize($data['order_cart']);
2907 - $total_price = $usces->get_total_price( $cart ) - $data['order_discount'];
2908 -
2909 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2910 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_ordercompletion'";
2911 - }else{
2912 - $push[] = "'_trackPageview','/wc_ordercompletion'";
2913 - }
2914 - $push[] = "'_addTrans', '" . $order_id . "', '" . get_option('blogname') . "', '" . $total_price . "', '" . $data['order_tax'] . "', '" . $data['order_shipping_charge'] . "', '" . $data['order_address1'].$data['order_address2'] . "', '" . $data['order_pref'] . "', '" . get_locale() . "'";
2915 - for($i=0; $i<count($cart); $i++) {
2916 - $cart_row = $cart[$i];
2917 - $post_id = $cart_row['post_id'];
2918 - $sku = urldecode($cart_row['sku']);
2919 - $quantity = $cart_row['quantity'];
2920 -// $options = $cart_row['options'];
2921 -// $advance = $usces->cart->wc_serialize($cart_row['advance']);
2922 -// $itemCode = $usces->getItemCode($post_id);
2923 - $itemName = $usces->getItemName($post_id);
2924 -// $cartItemName = $usces->getCartItemName($post_id, $sku);
2925 - $skuPrice = $cart_row['price'];
2926 - $cats = $usces->get_item_cat_genre_ids( $post_id );
2927 - if( is_array($cats) )
2928 - sort($cats);
2929 - $category = get_cat_name( $cats[0] );
2930 - $push[] = "'_addItem', '" . $order_id . "', '" . $sku . "', '" . $itemName . "', '" . $category . "', '" . $skuPrice . "', '" . $quantity . "'";
2931 - }
2932 - $push[] = "'_trackTrans'";
2933 -
2934 - return $push;
2935 -}
2936 -
2937 -function usces_trackPageview_error($push){
2938 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2939 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_error'";
2940 - }else{
2941 - $push[] = "'_trackPageview','/wc_error'";
2942 - }
2943 - return $push;
2944 -}
2945 -
2946 -function usces_trackPageview_member($push){
2947 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2948 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_member'";
2949 - }else{
2950 - $push[] = "'_trackPageview','/wc_member'";
2951 - }
2952 - return $push;
2953 -}
2954 -
2955 -function usces_trackPageview_login($push){
2956 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2957 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_login'";
2958 - }else{
2959 - $push[] = "'_trackPageview','/wc_login'";
2960 - }
2961 - return $push;
2962 -}
2963 -
2964 -function usces_trackPageview_editmemberform($push){
2965 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2966 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_editmemberform'";
2967 - }else{
2968 - $push[] = "'_trackPageview','/wc_editmemberform'";
2969 - }
2970 - return $push;
2971 -}
2972 -
2973 -function usces_trackPageview_newcompletion($push){
2974 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2975 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_newcompletion'";
2976 - }else{
2977 - $push[] = "'_trackPageview','/wc_newcompletion'";
2978 - }
2979 - return $push;
2980 -}
2981 -
2982 -function usces_trackPageview_newmemberform($push){
2983 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2984 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_newmemberform'";
2985 - }else{
2986 - $push[] = "'_trackPageview','/wc_newmemberform'";
2987 - }
2988 - return $push;
2989 -}
2990 -
2991 -function usces_trackPageview_deletemember($push){
2992 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2993 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_deletemember'";
2994 - }else{
2995 - $push[] = "'_trackPageview','/wc_deletemember'";
2996 - }
2997 - return $push;
2998 -}
2999 -
3000 -function usces_get_essential_mark( $fielde, $data = NULL ){
3001 - global $usces_essential_mark;
3002 - do_action('usces_action_essential_mark', $data, $fielde);
3003 - return $usces_essential_mark[$fielde];
3004 -}
3005 -
3006 -function uesces_get_admin_addressform( $type, $data, $customdata, $out = 'return' ){
3007 - global $usces, $usces_settings;
3008 - $options = get_option('usces');
3009 - $applyform = usces_get_apply_addressform($options['system']['addressform']);
3010 - $formtag = '';
3011 - switch( $type ){
3012 - case 'member':
3013 - $values = array('name1'=>$data['mem_name1'], 'name2'=>$data['mem_name2'], 'name3'=>$data['mem_name3'], 'name4'=>$data['mem_name4'], 'zipcode'=>$data['mem_zip'], 'address1'=>$data['mem_address1'], 'address2'=>$data['mem_address2'], 'address3'=>$data['mem_address3'], 'tel'=>$data['mem_tel'], 'fax'=>$data['mem_fax'], 'pref'=>$data['mem_pref']);
3014 - $country = $usces->get_member_meta_value('customer_country', $data['ID']);
3015 - $values['country'] = !empty($country) ? $country : usces_get_local_addressform();
3016 - break;
3017 - case 'customer':
3018 - $values = array('name1'=>$data['order_name1'], 'name2'=>$data['order_name2'], 'name3'=>$data['order_name3'], 'name4'=>$data['order_name4'], 'zipcode'=>$data['order_zip'], 'address1'=>$data['order_address1'], 'address2'=>$data['order_address2'], 'address3'=>$data['order_address3'], 'tel'=>$data['order_tel'], 'fax'=>$data['order_fax'], 'pref'=>$data['order_pref']);
3019 - $country = $usces->get_order_meta_value('customer_country', $data['ID']);
3020 - $values['country'] = !empty($country) ? $country : usces_get_local_addressform();
3021 - break;
3022 - case 'delivery':
3023 - $values = $data;
3024 - break;
3025 - }
3026 -
3027 - switch ($applyform){
3028 -
3029 - case 'JP':
3030 - //20100818ysk start
3031 - $formtag .= usces_admin_custom_field_input($customdata, $type, 'name_pre', 'return');
3032 - //20100818ysk end
3033 - $formtag .= '
3034 - <tr>
3035 - <td class="label">' . __('name', 'usces') . '</td>
3036 - <td class="col2"><input name="' . $type . '[name1]" type="text" class="text short" value="' . esc_attr($values['name1']) . '" /><input name="' . $type . '[name2]" type="text" class="text short" value="' . esc_attr($values['name2']) . '" /></td>
3037 - </tr>
3038 - <tr>
3039 - <td class="label">' . __('furigana', 'usces') . '</td>
3040 - <td class="col2"><input name="' . $type . '[name3]" type="text" class="text short" value="' . esc_attr($values['name3']) . '" /><input name="' . $type . '[name4]" type="text" class="text short" value="' . esc_attr($values['name4']) . '" /></td>
3041 - </tr>';
3042 - //20100818ysk start
3043 - $formtag .= usces_admin_custom_field_input($customdata, $type, 'name_after', 'return');
3044 - //20100818ysk end
3045 - $formtag .= '
3046 - <tr>
3047 - <td class="label">' . __('Zip/Postal Code', 'usces') . '</td>
3048 - <td class="col2"><input name="' . $type . '[zipcode]" type="text" class="text short" value="' . esc_attr($values['zipcode']) . '" />'.apply_filters('usces_filter_admin_addressform_zipcode', NULL, $type).'</td>
3049 - </tr>
3050 - <tr>
3051 - <td class="label">' . __('Country', 'usces') . '</td>
3052 - <td class="col2">' . uesces_get_target_market_form( $type, $values['country'] ) . '</td>
3053 - </tr>
3054 - <tr>
3055 - <td class="label">' . __('Province', 'usces') . '</td>
3056 - <td class="col2">';
3057 -
3058 - $formtag .= usces_pref_select( $type, $values );
3059 -
3060 - $formtag .= '</td>
3061 - </tr>';
3062 - $formtag .= '
3063 - <tr>
3064 - <td class="label">' . __('city', 'usces') . '</td>
3065 - <td class="col2"><input name="' . $type . '[address1]" type="text" class="text long" value="' . esc_attr($values['address1']) . '" /></td>
3066 - </tr>
3067 - <tr>
3068 - <td class="label">' . __('numbers', 'usces') . '</td>
3069 - <td class="col2"><input name="' . $type . '[address2]" type="text" class="text long" value="' . esc_attr($values['address2']) . '" /></td>
3070 - </tr>
3071 - <tr>
3072 - <td class="label">' . __('building name', 'usces') . '</td>
3073 - <td class="col2"><input name="' . $type . '[address3]" type="text" class="text long" value="' . esc_attr($values['address3']) . '" /></td>
3074 - </tr>
3075 - <tr>
3076 - <td class="label">' . __('Phone number', 'usces') . '</td>
3077 - <td class="col2"><input name="' . $type . '[tel]" type="text" class="text long" value="' . esc_attr($values['tel']) . '" /></td>
3078 - </tr>
3079 - <tr>
3080 - <td class="label">' . __('FAX number', 'usces') . '</td>
3081 - <td class="col2"><input name="' . $type . '[fax]" type="text" class="text long" value="' . esc_attr($values['fax']) . '" /></td>
3082 - </tr>';
3083 - //20100818ysk start
3084 - $formtag .= usces_admin_custom_field_input($customdata, $type, 'fax_after', 'return');
3085 - //20100818ysk end
3086 - break;
3087 -
3088 - case 'CN':
3089 - $formtag .= usces_admin_custom_field_input($customdata, $type, 'name_pre', 'return');
3090 - $formtag .= '
3091 - <tr>
3092 - <td class="label">' . __('name', 'usces') . '</td>
3093 - <td class="col2"><input name="' . $type . '[name1]" type="text" class="text short" value="' . esc_attr($values['name1']) . '" /><input name="' . $type . '[name2]" type="text" class="text short" value="' . esc_attr($values['name2']) . '" /></td>
3094 - </tr>';
3095 - $formtag .= usces_admin_custom_field_input($customdata, $type, 'name_after', 'return');
3096 - $formtag .= '
3097 - <tr>
3098 - <td class="label">' . __('Country', 'usces') . '</td>
3099 - <td class="col2">' . uesces_get_target_market_form( $type, $values['country'] ) . '</td>
3100 - </tr>
3101 - <tr>
3102 - <td class="label">' . __('State', 'usces') . '</td>
3103 - <td class="col2">';
3104 -
3105 - $formtag .= usces_pref_select( $type, $values );
3106 -
3107 - $formtag .= '</td>
3108 - </tr>';
3109 - $formtag .= '<tr>
3110 - <td class="label">' . __('city', 'usces') . '</td>
3111 - <td class="col2"><input name="' . $type . '[address1]" type="text" class="text long" value="' . esc_attr($values['address1']) . '" /></td>
3112 - </tr>
3113 - <tr>
3114 - <td class="label">' . __('Address Line1', 'usces') . '</td>
3115 - <td class="col2"><input name="' . $type . '[address2]" type="text" class="text long" value="' . esc_attr($values['address2']) . '" /></td>
3116 - </tr>
3117 - <tr>
3118 - <td class="label">' . __('Address Line2', 'usces') . '</td>
3119 - <td class="col2"><input name="' . $type . '[address3]" type="text" class="text long" value="' . esc_attr($values['address3']) . '" /></td>
3120 - </tr>
3121 - <tr>
3122 - <td class="label">' . __('Zip', 'usces') . '</td>
3123 - <td class="col2"><input name="' . $type . '[zipcode]" type="text" class="text short" value="' . esc_attr($values['zipcode']) . '" /></td>
3124 - </tr>
3125 - <tr>
3126 - <td class="label">' . __('Phone number', 'usces') . '</td>
3127 - <td class="col2"><input name="' . $type . '[tel]" type="text" class="text long" value="' . esc_attr($values['tel']) . '" /></td>
3128 - </tr>
3129 - <tr>
3130 - <td class="label">' . __('FAX number', 'usces') . '</td>
3131 - <td class="col2"><input name="' . $type . '[fax]" type="text" class="text long" value="' . esc_attr($values['fax']) . '" /></td>
3132 - </tr>';
3133 - $formtag .= usces_admin_custom_field_input($customdata, $type, 'fax_after', 'return');
3134 - break;
3135 -
3136 - case 'US':
3137 - default:
3138 - //20100818ysk start
3139 - $formtag .= usces_admin_custom_field_input($customdata, $type, 'name_pre', 'return');
3140 - //20100818ysk end
3141 - $formtag .= '
3142 - <tr>
3143 - <td class="label">' . __('name', 'usces') . '</td>
3144 - <td class="col2"><input name="' . $type . '[name2]" type="text" class="text short" value="' . esc_attr($values['name2']) . '" /><input name="' . $type . '[name1]" type="text" class="text short" value="' . esc_attr($values['name1']) . '" /></td>
3145 - </tr>';
3146 - //20100818ysk start
3147 - $formtag .= usces_admin_custom_field_input($customdata, $type, 'name_after', 'return');
3148 - //20100818ysk end
3149 - $formtag .= '
3150 - <tr>
3151 - <td class="label">' . __('Address Line1', 'usces') . '</td>
3152 - <td class="col2"><input name="' . $type . '[address2]" type="text" class="text long" value="' . esc_attr($values['address2']) . '" /></td>
3153 - </tr>
3154 - <tr>
3155 - <td class="label">' . __('Address Line2', 'usces') . '</td>
3156 - <td class="col2"><input name="' . $type . '[address3]" type="text" class="text long" value="' . esc_attr($values['address3']) . '" /></td>
3157 - </tr>
3158 - <tr>
3159 - <td class="label">' . __('city', 'usces') . '</td>
3160 - <td class="col2"><input name="' . $type . '[address1]" type="text" class="text long" value="' . esc_attr($values['address1']) . '" /></td>
3161 - </tr>
3162 - <tr>
3163 - <td class="label">' . __('State', 'usces') . '</td>
3164 - <td class="col2">';
3165 -
3166 - $formtag .= usces_pref_select( $type, $values );
3167 -
3168 - $formtag .= '</td>
3169 - </tr>';
3170 - $formtag .= '
3171 - <tr>
3172 - <td class="label">' . __('Country', 'usces') . '</td>
3173 - <td class="col2">' . uesces_get_target_market_form( $type, $values['country'] ) . '</td>
3174 - </tr>
3175 - <tr>
3176 - <td class="label">' . __('Zip', 'usces') . '</td>
3177 - <td class="col2"><input name="' . $type . '[zipcode]" type="text" class="text short" value="' . esc_attr($values['zipcode']) . '" /></td>
3178 - </tr>
3179 - <tr>
3180 - <td class="label">' . __('Phone number', 'usces') . '</td>
3181 - <td class="col2"><input name="' . $type . '[tel]" type="text" class="text long" value="' . esc_attr($values['tel']) . '" /></td>
3182 - </tr>
3183 - <tr>
3184 - <td class="label">' . __('FAX number', 'usces') . '</td>
3185 - <td class="col2"><input name="' . $type . '[fax]" type="text" class="text long" value="' . esc_attr($values['fax']) . '" /></td>
3186 - </tr>';
3187 - //20100818ysk start
3188 - $formtag .= usces_admin_custom_field_input($customdata, $type, 'fax_after', 'return');
3189 - //20100818ysk end
3190 - break;
3191 - }
3192 - $res = apply_filters('usces_filter_apply_admin_addressform', $formtag, $type, $data, $customdata);
3193 -
3194 -
3195 - if($out == 'return') {
3196 - return $res;
3197 - } else {
3198 - echo $res;
3199 - }
3200 -}
3201 -
3202 -function uesces_get_mail_addressform( $type, $data, $order_id, $out = 'return' ){
3203 - global $wpdb, $usces, $usces_settings;
3204 - $options = get_option('usces');
3205 - $applyform = usces_get_apply_addressform($options['system']['addressform']);
3206 - $formtag = '';
3207 - switch( $type ){
3208 - case 'admin_mail_customer':
3209 - $values = $data;
3210 - $values['country'] = !empty($values['country']) ? $values['country'] : usces_get_local_addressform();
3211 - $mode = 'customer';
3212 - $name_label = __('Buyer','usces');
3213 - break;
3214 - case 'admin_mail':
3215 - $values = $data;
3216 - $values['country'] = !empty($values['country']) ? $values['country'] : usces_get_local_addressform();
3217 - $mode = 'delivery';
3218 - $name_label = __('A destination name','usces');
3219 - break;
3220 - case 'order_mail_customer':
3221 - $values = $data['customer'];
3222 - $values['country'] = !empty($values['country']) ? $values['country'] : usces_get_local_addressform();
3223 - $mode = 'customer';
3224 - $name_label = __('Buyer','usces');
3225 - break;
3226 - case 'order_mail':
3227 - $values = $data['delivery'];
3228 - $values['country'] = !empty($values['country']) ? $values['country'] : usces_get_local_addressform();
3229 - $mode = 'delivery';
3230 - $name_label = __('A destination name','usces');
3231 - break;
3232 - }
3233 -
3234 - switch ($applyform){
3235 -
3236 - case 'JP':
3237 - //20110118ysk start
3238 - $formtag .= usces_mail_custom_field_info( $mode, 'name_pre', $order_id );
3239 - //20110118ysk end
3240 - //20131129_kitamu_start
3241 - if( $type == 'order_mail_customer' or $type == 'admin_mail_customer' ){
3242 - $usces_order_table = $wpdb->prefix . "usces_order";
3243 - $order_data = $wpdb->get_results( $wpdb->prepare("SELECT mem_id,order_email FROM $usces_order_table WHERE ID = %d LIMIT 1", $order_id ) );
3244 - $mem_id = $order_data[0]->mem_id;
3245 - $order_email = $order_data[0]->order_email;
3246 -
3247 - $formtag .= ( !empty( $mem_id ) ) ? __( 'membership number', 'usces' ) . "\t\t: " . $mem_id . "\r\n" : '';
3248 - $formtag .= ( !empty( $order_email ) ) ? __( 'e-mail adress', 'usces' ) . "\t\t: " . $order_email . "\r\n" : '';
3249 - }
3250 - //20131129_kitamu_end
3251 - $formtag .= $name_label . "\t\t: " . sprintf(__('Mr/Mrs %s', 'usces'), ($values['name1'] . ' ' . $values['name2'])) . " \r\n";
3252 - if( !empty($values['name3']) || !empty($values['name4']) ) {
3253 - $formtag .= __('furigana','usces') . "\t\t: " . $values['name3'] . ' ' . $values['name4'] . " \r\n";
3254 - }
3255 - //20110118ysk start
3256 - $formtag .= usces_mail_custom_field_info( $mode, 'name_after', $order_id );
3257 - //20110118ysk end
3258 - //20131213_kitamu_start
3259 - if( count( $options['system']['target_market'] ) != 1 ){
3260 - $formtag .= __('Country','usces') . "\t\t\t: " . $usces_settings['country'][$values['country']] . "\r\n";
3261 - }
3262 - //20131213_kitamu_end
3263 - $formtag .= __('Zip/Postal Code','usces') . "\t\t: " . $values['zipcode'] . "\r\n";
3264 - $formtag .= __('Address','usces') . "\t\t\t: " . $values['pref'] . $values['address1'] . $values['address2'] . " " . $values['address3'] . "\r\n";
3265 - $formtag .= __('Phone number','usces') . "\t\t: " . $values['tel'] . "\r\n";
3266 - $formtag .= __('FAX number','usces') . "\t\t: " . $values['fax'] . "\r\n";
3267 - //20110118ysk start
3268 - $formtag .= usces_mail_custom_field_info( $mode, 'fax_after', $order_id );
3269 - //20110118ysk end
3270 - break;
3271 -
3272 - case 'CN':
3273 - //20110118ysk start
3274 - $formtag .= usces_mail_custom_field_info( $mode, 'name_pre', $order_id );
3275 - //20110118ysk end
3276 - //20131129_kitamu_start
3277 - if( $type == 'order_mail_customer' or $type == 'admin_mail_customer' ){
3278 - $usces_order_table = $wpdb->prefix . "usces_order";
3279 - $order_data = $wpdb->get_results( $wpdb->prepare("SELECT mem_id,order_email FROM $usces_order_table WHERE ID = %d LIMIT 1", $order_id ) );
3280 - $mem_id = $order_data[0]->mem_id;
3281 - $order_email = $order_data[0]->order_email;
3282 -
3283 - $formtag .= ( !empty( $mem_id ) ) ? __( 'membership number', 'usces' ) . "\t\t: " . $mem_id . "\r\n" : '';
3284 - $formtag .= ( !empty( $order_email ) ) ? __( 'e-mail adress', 'usces' ) . "\t\t: " . $order_email . "\r\n" : '';
3285 - }
3286 - //20131129_kitamu_end
3287 - $formtag .= $name_label . "\t\t: " . sprintf(__('Mr/Mrs %s', 'usces'), ($values['name1'] . ' ' . $values['name2'])) . " \r\n";
3288 - //20110118ysk start
3289 - $formtag .= usces_mail_custom_field_info( $mode, 'name_after', $order_id );
3290 - //20110118ysk end
3291 - //20131213_kitamu_start
3292 - if( count( $options['system']['target_market'] ) != 1 ){
3293 - $formtag .= __('Country','usces') . " : " . $usces_settings['country'][$values['country']] . "\r\n";
3294 - }
3295 - //20131213_kitamu_end
3296 - $formtag .= __('State','usces') . " : " . $values['pref'] . "\r\n";
3297 - $formtag .= __('City','usces') . " : " . $values['address1'] . "\r\n";
3298 - $formtag .= __('Address','usces') . " : " . $values['address2'] . " " . $values['address3'] . "\r\n";
3299 - $formtag .= __('Zip/Postal Code','usces') . " : " . $values['zipcode'] . "\r\n";
3300 - $formtag .= __('Phone number','usces') . " : " . $values['tel'] . "\r\n";
3301 - $formtag .= __('FAX number','usces') . " : " . $values['fax'] . "\r\n";
3302 - //20110118ysk start
3303 - $formtag .= usces_mail_custom_field_info( $mode, 'fax_after', $order_id );
3304 - //20110118ysk end
3305 - break;
3306 -
3307 - case 'US':
3308 - default:
3309 - //20110118ysk start
3310 - $formtag .= usces_mail_custom_field_info( $mode, 'name_pre', $order_id );
3311 - //20110118ysk end
3312 - //20131129_kitamu_start
3313 - if( $type == 'order_mail_customer' or $type == 'admin_mail_customer' ){
3314 - $usces_order_table = $wpdb->prefix . "usces_order";
3315 - $order_data = $wpdb->get_results( $wpdb->prepare("SELECT mem_id,order_email FROM $usces_order_table WHERE ID = %d LIMIT 1", $order_id ) );
3316 - $mem_id = $order_data[0]->mem_id;
3317 - $order_email = $order_data[0]->order_email;
3318 -
3319 - $formtag .= ( !empty( $mem_id ) ) ? __( 'membership number', 'usces' ) . "\t\t: " . $mem_id . "\r\n" : '';
3320 - $formtag .= ( !empty( $order_email ) ) ? __( 'e-mail adress', 'usces' ) . "\t\t: " . $order_email . "\r\n" : '';
3321 - }
3322 - //20131129_kitamu_end
3323 - $formtag .= $name_label . " : " . sprintf(__('Mr/Mrs %s', 'usces'), ($values['name2'] . ' ' . $values['name1'])) . " \r\n";
3324 - //20110118ysk start
3325 - $formtag .= usces_mail_custom_field_info( $mode, 'name_after', $order_id );
3326 - //20110118ysk end
3327 - $formtag .= __('Address','usces') . " : " . $values['address2'] . " " . $values['address3'] . "\r\n";
3328 - $formtag .= __('City','usces') . " : " . $values['address1'] . "\r\n";
3329 - $formtag .= __('State','usces') . " : " . $values['pref'] . "\r\n";
3330 -
3331 - //20131213_kitamu_start
3332 - if( count( $options['system']['target_market'] ) != 1 ){
3333 - $formtag .= __('Country','usces') . " : " . $usces_settings['country'][$values['country']] . "\r\n";
3334 - }
3335 - //20131213_kitamu_end
3336 - $formtag .= __('Zip/Postal Code','usces') . " : " . $values['zipcode'] . "\r\n";
3337 - $formtag .= __('Phone number','usces') . " : " . $values['tel'] . "\r\n";
3338 - $formtag .= __('FAX number','usces') . " : " . $values['fax'] . "\r\n";
3339 - //20110118ysk start
3340 - $formtag .= usces_mail_custom_field_info( $mode, 'fax_after', $order_id );
3341 - //20110118ysk end
3342 - break;
3343 - }
3344 - $res = apply_filters('usces_filter_apply_mail_addressform', $formtag, $type, $data, $order_id);
3345 -
3346 -
3347 - if($out == 'return') {
3348 - return $res;
3349 - } else {
3350 - echo $res;
3351 - }
3352 -}
3353 -
3354 -function uesces_get_target_market_form( $type, $selected, $out = 'return' ){
3355 - global $usces_settings;
3356 - $options = get_option('usces');
3357 - $res = '<select name="' . $type . '[country]" id="' . $type . '_country">'."\n";
3358 - foreach ( $usces_settings['country'] as $key => $value ){
3359 - if( in_array($key, $options['system']['target_market']) )
3360 - $res .= '<option value="' . $key . '"' . ($selected == $key ? ' selected="selected"' : '') . '>' . $value . "</option>\n";
3361 - }
3362 - $res .= '</select>'."\n";
3363 -
3364 - if($out == 'return') {
3365 - return $res;
3366 - } else {
3367 - echo $res;
3368 - }
3369 -}
3370 -
3371 -function usces_pref_select( $type, $values, $out = 'return' ){
3372 - global $usces, $usces_states;
3373 -
3374 -//20110513ysk start
3375 - //$country = empty($values['country']) ? usces_get_local_addressform() : $values['country'];
3376 - $country = empty($values['country']) ? usces_get_base_country() : $values['country'];
3377 - $options = get_option('usces');
3378 - if( !in_array($country, $options['system']['target_market']) )
3379 - $country = $options['system']['target_market'][0];
3380 -//20110513ysk end
3381 -//20110331ysk start
3382 - //$prefs = $usces_states[$country];
3383 - $prefs = get_usces_states($country);
3384 -//20110331ysk end
3385 - $html = '<select name="' . esc_attr($type . '[pref]') . '" id="' . esc_attr($type) . '_pref" class="pref">';
3386 -//20120123ysk start 0000386
3387 - //foreach((array)$prefs as $pref)
3388 - // $html .= "\t".'<option value="' . esc_attr($pref) . '"' . ($pref == $values['pref'] ? ' selected="selected"' : '') . '>' . esc_html($pref) . "</option>\n";
3389 - $prefs_count = count($prefs);
3390 - if($prefs_count > 0) {
3391 - $select = __('-- Select --', 'usces');
3392 - $html .= "\t".'<option value="' . esc_attr($select) . '">' . esc_html($select) . "</option>\n";
3393 - for($i = 1; $i < $prefs_count; $i++)
3394 - $html .= "\t".'<option value="' . esc_attr($prefs[$i]) . '"' . ($prefs[$i] == $values['pref'] ? ' selected="selected"' : '') . '>' . esc_html($prefs[$i]) . "</option>\n";
3395 - }
3396 -//20120123ysk end
3397 - $html .= "</select>\n";
3398 -
3399 - if( $out == 'return' ){
3400 - return $html;
3401 - }else{
3402 - echo $html;
3403 - }
3404 -}
3405 -
3406 -function usces_is_member_system(){
3407 - global $usces;
3408 - if($usces->options['membersystem_state'] == 'activate')
3409 - return true;
3410 - else
3411 - return false;
3412 -}
3413 -
3414 -function usces_is_member_system_point(){
3415 - global $usces;
3416 - if($usces->options['membersystem_point'] == 'activate')
3417 - return true;
3418 - else
3419 - return false;
3420 -}
3421 -
3422 -function usces_shipping_country_option( $selected, $out = '' ){
3423 - global $usces_settings;
3424 - $options = get_option('usces');
3425 - $res = '';
3426 - foreach ( $usces_settings['country'] as $key => $value ){
3427 - if( in_array($key, $options['system']['target_market']) )
3428 - $res .= '<option value="' . $key . '"' . ($selected == $key ? ' selected="selected"' : '') . '>' . $value . "</option>\n";
3429 - }
3430 -//20110317ysk start
3431 - //$res .= '<option value="world_wide"' . ($selected == $key ? ' selected="selected"' : '') . '>World Wide' . "</option>\n";
3432 -//20110317ysk end
3433 - echo $res;
3434 -}
3435 -
3436 -function usces_get_cart_button( $out = '' ) {
3437 - global $usces;
3438 - $res = '';
3439 -
3440 - if($usces->use_js){
3441 - $res .= '<input name="previous" type="button" id="previouscart" class="continue_shopping_button" value="' . __('continue shopping','usces') . '"' . apply_filters('usces_filter_cart_prebutton', ' onclick="uscesCart.previousCart();"') . ' />&nbsp;&nbsp;';
3442 - if( usces_is_cart() ) {
3443 - $res .= '<input name="customerinfo" type="submit" class="to_customerinfo_button" value="' . __(' Next ','usces') . '"' . apply_filters('usces_filter_cart_nextbutton', ' onclick="return uscesCart.cartNext();"') . ' />';
3444 - }
3445 - }else{
3446 - $res .= '<a href="' . get_home_url() . '" class="continue_shopping_button">' . __('continue shopping','usces') . '</a>&nbsp;&nbsp;';
3447 - if( usces_is_cart() ) {
3448 - $res .= '<input name="customerinfo" type="submit" class="to_customerinfo_button" value="' . __(' Next ','usces') . '"' . apply_filters('usces_filter_cart_nextbutton', NULL) . ' />';
3449 - }
3450 - }
3451 - $res = apply_filters('usces_filter_get_cart_button', $res);
3452 -
3453 - if($out == 'return'){
3454 - return $res;
3455 - }else{
3456 - echo $res;
3457 - }
3458 -}
3459 -
3460 -function usces_get_customer_button( $out = '' ) {
3461 - global $usces, $member_regmode;
3462 - $res = '';
3463 -
3464 - $res = '<input name="backCart" type="submit" class="back_cart_button" value="'.__('Back', 'usces').'" />&nbsp;&nbsp;';
3465 -
3466 - $button = '<input name="deliveryinfo" type="submit" class="to_deliveryinfo_button" value="'.__(' Next ', 'usces').'" />&nbsp;&nbsp;';
3467 - $res .= apply_filters('usces_filter_customer_button', $button);
3468 -
3469 - if(usces_is_membersystem_state() && $member_regmode != 'editmemberfromcart' && usces_is_login() == false ){
3470 - $res .= '<input name="reganddeliveryinfo" type="submit" class="to_reganddeliveryinfo_button" value="'.__('To the next while enrolling', 'usces').'"' . apply_filters('usces_filter_customerinfo_prebutton', NULL) . ' />';
3471 - }elseif(usces_is_membersystem_state() && $member_regmode == 'editmemberfromcart' ){
3472 - $res .= '<input name="reganddeliveryinfo" type="submit" class="to_reganddeliveryinfo_button" value="'.__('Revise member information, and to next', 'usces').'"' . apply_filters('usces_filter_customerinfo_nextbutton', NULL) . ' />';
3473 - }
3474 -
3475 - $res = apply_filters('usces_filter_get_customer_button', $res);
3476 -
3477 - if($out == 'return'){
3478 - return $res;
3479 - }else{
3480 - echo $res;
3481 - }
3482 -}
3483 -
3484 -function usces_delivery_secure_form( $out = '' ) {
3485 - global $usces, $usces_entries, $usces_carts;
3486 - $html = '';
3487 - include( USCES_PLUGIN_DIR . "/includes/delivery_secure_form.php");
3488 -
3489 - if($out == 'return'){
3490 - return $html;
3491 - }else{
3492 - echo $html;
3493 - }
3494 -}
3495 -
3496 -function usces_delivery_info_script( $out ='' ){
3497 - global $usces, $usces_entries, $usces_carts;
3498 - $html = '';
3499 - include( USCES_PLUGIN_DIR . "/includes/delivery_info_script.php");
3500 -
3501 - if($out == 'return'){
3502 - return $html;
3503 - }else{
3504 - echo $html;
3505 - }
3506 -}
3507 -
3508 -function usces_get_entries(){
3509 - global $usces, $usces_entries;
3510 - $usces_entries = $usces->cart->get_entry();
3511 -}
3512 -
3513 -function usces_get_carts(){
3514 - global $usces, $usces_carts;
3515 - $usces_carts = $usces->cart->get_cart();
3516 -}
3517 -
3518 -function usces_get_members(){
3519 - global $usces, $usces_members;
3520 - $usces_members = $usces->get_member();
3521 -}
3522 -
3523 -function usces_error_message( $out = ''){
3524 - global $usces;
3525 -
3526 - if($out == 'return'){
3527 - return $usces->error_message;
3528 - }else{
3529 - echo $usces->error_message;
3530 - }
3531 -}
3532 -
3533 -function usces_url( $type, $out = ''){
3534 - global $usces;
3535 -
3536 - switch ( $type ){
3537 - case 'cart':
3538 - $url = USCES_CART_URL;
3539 - break;
3540 - case 'login':
3541 - $url = USCES_LOGIN_URL;
3542 - break;
3543 - case 'member':
3544 - $url = USCES_MEMBER_URL;
3545 - break;
3546 - case 'newmember':
3547 - $url = USCES_NEWMEMBER_URL;
3548 - break;
3549 - case 'lostmemberpassword':
3550 - $url = USCES_LOSTMEMBERPASSWORD_URL;
3551 - break;
3552 - case 'cartnonsession':
3553 - $url = USCES_CART_NONSESSION_URL;
3554 - break;
3555 - }
3556 -
3557 - if($out == 'return'){
3558 - return $url;
3559 - }else{
3560 - echo $url;
3561 - }
3562 -}
3563 -
3564 -function usces_total_price( $out = ''){
3565 - global $usces;
3566 -
3567 - if($out == 'return'){
3568 - return $usces->get_total_price();
3569 - }else{
3570 - echo $usces->get_total_price();
3571 - }
3572 -}
3573 -
3574 -function usces_completion_settlement( $out ='' ){
3575 - global $usces, $usces_entries;
3576 - $html = '';
3577 -
3578 - $template = apply_filters( 'usces_filter_completion_settlement', USCES_PLUGIN_DIR . "/includes/completion_settlement.php", $usces_entries );
3579 - require( $template );
3580 -
3581 - if($out == 'return'){
3582 - return $html;
3583 - }else{
3584 - echo $html;
3585 - }
3586 -}
3587 -
3588 -function usces_purchase_button( $out ='' ){
3589 - global $usces, $usces_entries;
3590 - $html = '';
3591 - include( USCES_PLUGIN_DIR . "/includes/purchase_button.php");
3592 -
3593 - if($out == 'return'){
3594 - return $html;
3595 - }else{
3596 - echo $html;
3597 - }
3598 -}
3599 -
3600 -function usces_get_member_regmode(){
3601 - global $member_regmode;
3602 - $member_regmode = isset( $_SESSION['usces_entry']['member_regmode'] ) ? $_SESSION['usces_entry']['member_regmode'] : 'none';
3603 -}
3604 -
3605 -function uesces_get_error_settlement( $out = '' ) {
3606 - $res = '';
3607 - if( isset($_REQUEST['acting']) && ('zeus_conv' == $_REQUEST['acting'] || 'zeus_card' == $_REQUEST['acting'] || 'zeus_bank' == $_REQUEST['acting'] ) ){ //ZEUS
3608 - $res .= '<div class="support_box">';
3609 - if( isset($_GET['code']) ){
3610 - $res .= ' <br />エラーコード:' . esc_html($_GET['code']);
3611 - if( in_array($_GET['code'], array('02130514', '02130517', '02130619', '02130620', '02130621', '02130640')) ){
3612 - $res .= '<br />カード番号が正しくないようです。';
3613 - }elseif( in_array($_GET['code'], array('02130714', '02130717', '02130725', '02130814', '02130817', '02130825')) ){
3614 - $res .= '<br />カードの有効期限が正しくないようです。';
3615 - }elseif( in_array($_GET['code'], array('02130922')) ){
3616 - $res .= '<br />カードの有効期限が切れているようです。';
3617 - }elseif( in_array($_GET['code'], array('02131117', '02131123', '02131124')) ){
3618 - $res .= '<br />カードの名義が正しくないようです。';
3619 - }elseif( in_array($_GET['code'], array('02131414', '02131417', '02131437')) ){
3620 - $res .= '<br />お客様情報の電話番号が正しくないようです。';
3621 - }elseif( in_array($_GET['code'], array('02131527', '02131528', '02131529', '02131537')) ){
3622 - $res .= '<br />お客様情報のEメールアドレスが正しくないようです。';
3623 - }
3624 - $res .= ' <br />
3625 -  <br />
3626 - <a href="' . USCES_CUSTOMER_URL . '">もう一度決済を行う>></a><br />';
3627 - }else{
3628 - $res .= ' <br />エラーコード:' . esc_html($_GET['err_code']);
3629 - $res .= ' <br />
3630 - カード番号を再入力する場合はこちらをクリックしてください。<br />
3631 -  <br />
3632 - <a href="' . USCES_CUSTOMER_URL . '&re-enter=1">カード番号の再入力>></a><br />';
3633 - }
3634 - $res .= ' <br />
3635 - ゼウス・カスタマーサポート(24時間365日)<br />
3636 - 電話番号:0570-02-3939(つながらないときは 03-4334-0500)<br />
3637 - E-mail:support@cardservice.co.jp
3638 - </div>'."\n";
3639 - }
3640 - $res = apply_filters( 'usces_filter_get_error_settlement', $res );
3641 -
3642 - if($out == 'return'){
3643 - return $res;
3644 - }else{
3645 - echo $res;
3646 - }
3647 -}
3648 -
3649 -function usces_page_name( $out = '') {
3650 - global $usces;
3651 - $page = '';
3652 -
3653 - if( empty($usces->page) ){
3654 - if( $usces->is_cart_page($_SERVER['REQUEST_URI']) ){
3655 - $page = 'cart';
3656 - }elseif( $usces->is_member_page($_SERVER['REQUEST_URI']) ){
3657 - $page = 'member';
3658 - }
3659 - }else{
3660 - $page = $usces->page;
3661 - }
3662 -
3663 - if($out == 'return'){
3664 - return $page;
3665 - }else{
3666 - echo $page;
3667 - }
3668 -}
3669 -
3670 -function usces_post_reg_orderdata($order_id, $results){
3671 - global $usces, $wpdb;
3672 - $acting = isset($_GET['acting']) ? $_GET['acting'] : '';
3673 - $data = array();
3674 -
3675 - if( $order_id ){
3676 -
3677 - switch ( $acting ) {
3678 - case 'epsilon':
3679 - $trans_id = isset($_REQUEST['trans_code']) ? $_REQUEST['trans_code'] : '';
3680 - break;
3681 - case 'paypal_ipn':
3682 - $trans_id = isset($_REQUEST['txn_id']) ? $_REQUEST['txn_id'] : '';
3683 - break;
3684 - case 'paypal':
3685 - $trans_id = isset($results['txn_id']) ? $results['txn_id'] : '';
3686 - break;
3687 -//20110208ysk start
3688 - case 'paypal_ec':
3689 - $trans_id = isset($_REQUEST['token']) ? $_REQUEST['token'] : '';
3690 -//20110621ysk start 0000184
3691 - if(isset($results['settlement_id']))
3692 - $usces->set_order_meta_value('settlement_id', $results['settlement_id'], $order_id);
3693 - if(isset($results['profile_id']))
3694 - $usces->set_order_meta_value('profile_id', $results['profile_id'], $order_id);
3695 -//20110621ysk end
3696 - break;
3697 -//20110208ysk end
3698 - case 'zeus_card':
3699 - $acting_opts = $usces->options['acting_settings']['zeus'];
3700 - if( isset($_GET['zeussuffix']) ){
3701 - $entry = $usces->cart->get_entry();//20110621ysk 0000184
3702 - $data['acting'] = 'zeus_card Secure API';
3703 - $data['order_number'] = $_GET['zeusordd'];
3704 - $data['howpay'] = $entry['order']['howpay'];
3705 -
3706 - $usces->set_order_meta_value('acting_'.$acting, serialize($data), $order_id);
3707 - if( $usces->is_member_logged_in() ){
3708 - //if( 2 == $acting_opts['security'] && 'on' == $acting_opts['quickcharge']){
3709 - if( 'on' == $acting_opts['quickcharge']){
3710 - $usces->set_member_meta_value('zeus_pcid', '8888888888888888');
3711 - }
3712 - $usces->set_member_meta_value('zeus_partofcard', $_GET['zeussuffix']);
3713 - $usces->set_member_meta_value('zeus_limitofcard', ($_GET['zeusyear'].'/'.$_GET['zeusmonth']));
3714 - }
3715 - }else{
3716 - $trans_id = isset($_REQUEST['ordd']) ? $_REQUEST['ordd'] : '';
3717 - //foreach($_GET as $key => $value) {
3718 - // $data[$key] = esc_sql($value);
3719 - //}
3720 - //$usces->set_order_meta_value('acting_'.$acting, serialize($data), $order_id);
3721 - if( !empty($_REQUEST['order_number']) ) {
3722 - $usces->set_order_meta_value( 'order_number', $_REQUEST['order_number'], $order_id );
3723 - }
3724 - if( $usces->is_member_logged_in() ) {
3725 - if( 'on' == $acting_opts['quickcharge'] ) {
3726 - $usces->set_member_meta_value('zeus_pcid', '8888888888888888');
3727 - }
3728 - }
3729 - }
3730 - if(empty($usces)){
3731 - usces_log('zeus card transaction : No Session', 'acting_transaction.log');
3732 - }else{
3733 - usces_log('zeus card transaction : OK', 'acting_transaction.log');
3734 - }
3735 - break;
3736 - case 'zeus_conv':
3737 - $trans_id = isset($_REQUEST['order_no']) ? $_REQUEST['sendpoint'] : '';
3738 - $zeus_convs = array(
3739 - 'acting' => 'zeus_conv',
3740 - 'pay_cvs' => isset($_REQUEST['pay_cvs']) ? $_REQUEST['pay_cvs'] : '',
3741 - 'order_no' => isset($_REQUEST['order_no']) ? $_REQUEST['order_no'] : '',
3742 - 'money' => isset($_REQUEST['money']) ? $_REQUEST['money'] : '',
3743 - 'pay_no1' => isset($_REQUEST['pay_no1']) ? $_REQUEST['pay_no1'] : '',
3744 - 'pay_no2' => isset($_REQUEST['pay_no2']) ? $_REQUEST['pay_no2'] : '',
3745 - 'pay_limit' => isset($_REQUEST['pay_limit']) ? $_REQUEST['pay_limit'] : '',
3746 - 'status' => isset($_REQUEST['status']) ? $_REQUEST['status'] : '',
3747 - 'error_code' => isset($_REQUEST['error_code']) ? $_REQUEST['error_code'] : ''
3748 - );
3749 - $usces->set_order_meta_value('acting_'.(isset($_REQUEST['sendpoint']) ? $_REQUEST['sendpoint'] : ''), serialize($zeus_convs), $order_id);
3750 - break;
3751 - case 'zeus_bank':
3752 - $trans_id = isset($_REQUEST['order_no']) ? $_REQUEST['order_no'] : '';
3753 - break;
3754 - case 'remise_card':
3755 - $trans_id = isset($_REQUEST['X-TRANID']) ? $_REQUEST['X-TRANID'] : '';
3756 - break;
3757 - case 'remise_conv':
3758 - $trans_id = isset($_REQUEST['X-JOB_ID']) ? $_REQUEST['X-JOB_ID'] : '';
3759 - break;
3760 - case 'jpayment_card':
3761 - case 'jpayment_conv':
3762 - case 'jpayment_bank':
3763 - $trans_id = isset($_REQUEST['gid']) ? $_REQUEST['gid'] : '';
3764 - break;
3765 -//20120413ysk start
3766 - case 'sbps_card':
3767 - case 'sbps_conv':
3768 - case 'sbps_payeasy':
3769 - case 'sbps_wallet':
3770 - case 'sbps_mobile':
3771 - $trans_id = isset($_REQUEST['order_id']) ? $_REQUEST['order_id'] : '';
3772 - break;
3773 -//20120413ysk end
3774 -//20120618ysk start
3775 - case 'telecom_card':
3776 - $trans_id = isset($_REQUEST['sendid']) ? $_REQUEST['sendid'] : '';
3777 - break;
3778 -//20120618ysk end
3779 -//20121206ysk start
3780 - case 'digitalcheck_card':
3781 - case 'digitalcheck_conv':
3782 - $trans_id = isset($_REQUEST['SID']) ? $_REQUEST['SID'] : '';
3783 - break;
3784 -//20121206ysk end
3785 -//20130225ysk start
3786 - case 'mizuho_card':
3787 - case 'mizuho_conv':
3788 - $trans_id = isset($_REQUEST['stran']) ? $_REQUEST['stran'] : '';
3789 - break;
3790 -//20130225ysk end
3791 - default:
3792 - if( isset($_REQUEST['FUKA']) && strstr($_REQUEST['FUKA'], "digitalcheck_card") ) {
3793 - $trans_id = isset($_REQUEST['SID']) ? $_REQUEST['SID'] : '';
3794 - } else {
3795 - $trans_id = '';
3796 - }
3797 - }
3798 -
3799 - if(!empty($trans_id)) {
3800 - $usces->set_order_meta_value('trans_id', $trans_id, $order_id);
3801 - }
3802 - }
3803 -
3804 -}
3805 -
3806 -//20110621ysk start 0000184
3807 -function usces_paypal_doecp( &$results ) {
3808 - global $usces;
3809 - $entry = $usces->cart->get_entry();
3810 - $cart = $usces->cart->get_cart();
3811 -
3812 - $post_id = $cart[0]['post_id'];
3813 - $charging_type = $usces->getItemChargingType( $post_id );
3814 - if( 'continue' != $charging_type ) {
3815 - //通常購入
3816 - //Format the other parameters that were stored in the session from the previous calls
3817 - $paymentAmount = usces_crform($entry['order']['total_full_price'], false, false, 'return', false);
3818 - $token = urlencode($_REQUEST['token']);
3819 - $paymentType = urlencode("Sale");
3820 - $currencyCodeType = urlencode($usces->get_currency_code());
3821 - $payerID = urlencode($_REQUEST['PayerID']);
3822 - $serverName = urlencode($_SERVER['SERVER_NAME']);
3823 -
3824 - $nvpstr = '&TOKEN='.$token.'&PAYERID='.$payerID.'&PAYMENTACTION='.$paymentType.'&AMT='.$paymentAmount.'&CURRENCYCODE='.$currencyCodeType.'&IPADDRESS='.$serverName;
3825 - $nvpstr = apply_filters( 'usces_filter_usces_paypal_doecp', $nvpstr, $charging_type );
3826 -//20131121ysk start 0000771
3827 - if( 'shipped' == $usces->getItemDivision( $post_id ) ) {
3828 - $country = ( !empty($entry['delivery']['country']) ) ? $entry['delivery']['country'] : usces_get_base_country();
3829 - if( 'US' != $country and 'CA' != $country ) {//20140207ysk 0000771
3830 - $nvpstr .= '&SHIPTONAME='.$entry['delivery']['name2'].' '.$entry['delivery']['name1'].
3831 - '&SHIPTOSTREET='.$entry['delivery']['address2'].
3832 - '&SHIPTOSTREET2='.$entry['delivery']['address3'].
3833 - '&SHIPTOCITY='.$entry['delivery']['address1'].
3834 - '&SHIPTOSTATE='.$entry['delivery']['pref'].
3835 - '&SHIPTOZIP='.$entry['delivery']['zipcode'].
3836 - '&SHIPTOCOUNTRYCODE='.$country.
3837 - '&SHIPTOPHONENUM='.ltrim( str_replace( '-', '', $entry['delivery']['tel'] ), '0' );
3838 - }
3839 - }
3840 -//20131121ysk end
3841 - $usces->paypal->setMethod('DoExpressCheckoutPayment');
3842 - $usces->paypal->setData($nvpstr);
3843 - $res = $usces->paypal->doExpressCheckout();
3844 - $resArray = $usces->paypal->getResponse();
3845 - $ack = strtoupper($resArray["ACK"]);
3846 - if( $ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING" ) {
3847 - $transactionId = $resArray["TRANSACTIONID"]; // ' Unique transaction ID of the payment. Note: If the PaymentAction of the request was Authorization or Order, this value is your AuthorizationID for use with the Authorization & Capture APIs.
3848 - //$usces->set_order_meta_value('settlement_id', $transactionId, $order_id);
3849 - $results['settlement_id'] = $transactionId;
3850 - $results['payment_status'] = isset( $resArray["PAYMENTSTATUS"] ) ? $resArray["PAYMENTSTATUS"] : '';
3851 - $results['pending_reason'] = isset( $resArray["PENDINGREASON"] ) ? $resArray["PENDINGREASON"] : '';
3852 -
3853 - } else {
3854 - //Display a user friendly Error on the page using any of the following error information returned by PayPal
3855 - $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
3856 - $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
3857 - $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
3858 - $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
3859 - usces_log('PayPal : DoExpressCheckoutPayment API call failed. Error Code:['.$ErrorCode.'] Error Severity Code:['.$ErrorSeverityCode.'] Short Error Message:'.$ErrorShortMsg.' Detailed Error Message:'.$ErrorLongMsg, 'acting_transaction.log');
3860 - return false;
3861 - }
3862 -
3863 - } else {
3864 - if( !apply_filters( 'usces_pre_create_recurring_payments_profile', true ) ) return false;
3865 -
3866 - //定期支払い
3867 - $paymentAmount = usces_crform($entry['order']['total_full_price'], false, false, 'return', false);//20111129ysk 0000320
3868 - $token = urlencode($_REQUEST['token']);
3869 - $currencyCodeType = urlencode($usces->get_currency_code());
3870 - //$nextdate = get_date_from_gmt(gmdate('Y-m-d H:i:s', time()));
3871 - //$profileStartDate = date('Y-m-d', mktime(0,0,0,substr($nextdate, 5, 2)+1,$usces->getItemChargingDay($post_id),substr($nextdate, 0, 4))).'T01:01:01Z';
3872 - $profileStartDate = date('Y-m-d', dlseller_first_charging($post_id, 'time')).'T01:01:01Z';
3873 - $billingPeriod = "Month";// or "Day", "Week", "SemiMonth", "Year"
3874 - $billingFreq = $usces->getItemFrequency($post_id);
3875 - $desc = urlencode(usces_make_agreement_description($cart, $entry['order']['total_full_price']));//20111125ysk 0000320
3876 - $totalBillingCycles = (empty($dlitem['dlseller_interval'])) ? '' : '&TOTALBILLINGCYCLES='.urlencode($dlitem['dlseller_interval']);
3877 - //$totalBillingCycles = ( dlseller_auto_stop() ) ? '&TOTALBILLINGCYCLES='.dlseller_cycles( $post_id ) : '';
3878 -
3879 - //$nvpstr = '&TOKEN='.$token.'&AMT='.$paymentAmount.'&CURRENCYCODE='.$currencyCodeType.'&PROFILESTARTDATE='.$profileStartDate.'&BILLINGPERIOD='.$billingPeriod.'&BILLINGFREQUENCY='.$billingFreq.'&DESC='.$desc;
3880 - $nvpstr = '&TOKEN='.$token.'&AMT='.$paymentAmount.'&CURRENCYCODE='.$currencyCodeType.'&PROFILESTARTDATE='.$profileStartDate.'&BILLINGPERIOD='.$billingPeriod.'&BILLINGFREQUENCY='.$billingFreq.'&DESC='.$desc.$totalBillingCycles;
3881 - $nvpstr = apply_filters( 'usces_filter_usces_paypal_doecp', $nvpstr, $charging_type );
3882 -
3883 - $usces->paypal->setMethod('CreateRecurringPaymentsProfile');
3884 - $usces->paypal->setData($nvpstr);
3885 - $res = $usces->paypal->doExpressCheckout();
3886 - $resArray = $usces->paypal->getResponse();
3887 - $ack = strtoupper($resArray["ACK"]);
3888 - if( $ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING" ) {
3889 - $profileid = $resArray["PROFILEID"];
3890 - //$usces->set_order_meta_value('profile_id', $profileid, $order_id);
3891 - $results['settlement_id'] = $profileid;
3892 - $results['profile_id'] = $profileid;
3893 - $results['profile_status'] = isset( $resArray["PROFILESTATUS"] ) ? $resArray["PROFILESTATUS"] : '';
3894 -
3895 - } else {
3896 - //Display a user friendly Error on the page using any of the following error information returned by PayPal
3897 - $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
3898 - $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
3899 - $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
3900 - $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
3901 - usces_log('PayPal : CreateRecurringPaymentsProfile API call failed. Error Code:['.$ErrorCode.'] Error Severity Code:['.$ErrorSeverityCode.'] Short Error Message:'.$ErrorShortMsg.' Detailed Error Message:'.$ErrorLongMsg, 'acting_transaction.log');
3902 - return false;
3903 - }
3904 - }
3905 -
3906 - return true;
3907 -}
3908 -//20110621ysk end
3909 -//20110421ysk start
3910 -function usces_make_agreement_description($cart, $amt) {
3911 - global $usces;
3912 -
3913 - $cart_row = $cart[0];
3914 - $quantity = $cart_row['quantity'];
3915 - $itemName = $usces->getItemName($cart_row['post_id']);
3916 - //if(1 < count($cart)) $itemName .= ','.__('Others', 'usces');
3917 - if(50 < mb_strlen($itemName)) $itemName = mb_substr($itemName, 0, 50).'...';
3918 - $amt = usces_crform($amt, true, false, 'return', true);
3919 - $desc = $itemName.' '.__('Quantity','usces').':'.$quantity.' '.$amt;
3920 - return($desc);
3921 -}
3922 -//20110421ysk end
3923 -
3924 -function usces_get_send_out_date(){
3925 - global $usces;
3926 -
3927 - $bus_day_arr = (isset($usces->options['business_days'])) ? $usces->options['business_days'] : false;
3928 - list( $today_year, $today_month, $today_day, $hour, $minute, $second ) = preg_split( '([^0-9])', current_time('mysql') );
3929 - if( !is_array($bus_day_arr) ){
3930 - $today_bus_flag = 1;
3931 - }else{
3932 - $today_bus_flag = isset($bus_day_arr[(int)$today_year][(int)$today_month][(int)$today_day]) ? (int)$bus_day_arr[(int)$today_year][(int)$today_month][(int)$today_day] : 1;
3933 - }
3934 - // get the time limit addition
3935 - $limit_hour = (!empty($usces->options['delivery_time_limit']['hour'])) ? $usces->options['delivery_time_limit']['hour'] : false;
3936 - $limit_min = (!empty($usces->options['delivery_time_limit']['min'])) ? $usces->options['delivery_time_limit']['min'] : false;
3937 -
3938 - if( false === $hour || false === $minute ){
3939 - $time_limit_addition = false;
3940 - }elseif( ($hour.':'.$minute.':'.$second) > ($limit_hour.':'.$limit_min.':00') ){
3941 - $time_limit_addition = 1;
3942 - }else{
3943 - $time_limit_addition = 0;
3944 - }
3945 - // get the shipping indication in cart
3946 - $cart = $usces->cart->get_cart();
3947 - $shipping_indication = apply_filters('usces_filter_shipping_indication', $usces->options['usces_shipping_indication']);
3948 - $shipping = 0;
3949 - $indication_flag = true;
3950 - for($i = 0; $i < count($cart); $i++) {
3951 - $cart_row = $cart[$i];
3952 - $post_id = $cart_row['post_id'];
3953 - $itemShipping = (int)$usces->getItemShipping($post_id);
3954 - if($itemShipping === 0 or $itemShipping === 9) {
3955 - $indication_flag = false;
3956 - break;
3957 - }
3958 - if($shipping < $itemShipping) $shipping = $itemShipping;
3959 - }
3960 - $indication_incart = ( $indication_flag ) ? $shipping_indication[$shipping] : false;
3961 - // get the send out date
3962 - $sendout_num = 0;
3963 - if( $today_bus_flag ){
3964 - if( $time_limit_addition ){
3965 - $sendout_num += 1;
3966 - }
3967 - if( false !== $indication_incart ){
3968 - $sendout_num += $indication_incart;
3969 - }
3970 - }else{
3971 - if( false !== $indication_incart ){
3972 - $sendout_num += $indication_incart;
3973 - }
3974 - }
3975 - $holiday = 0;
3976 - for( $i=0; $i<=$sendout_num; $i++ ){
3977 - list($yyyy, $mm, $dd) = explode('-', date('Y-m-d', mktime(0,0,0,(int)$today_month,($today_day + $i),(int)$today_year)));
3978 - if( isset($bus_day_arr[(int)$yyyy][(int)$mm][(int)$dd]) && !$bus_day_arr[(int)$yyyy][(int)$mm][(int)$dd] ){
3979 - $holiday++;
3980 - $sendout_num++;
3981 - }
3982 - if( 100 < $sendout_num ) break;
3983 - }
3984 - list($send_y, $send_m, $send_d) = explode('-', date('Y-m-d', mktime(0,0,0,(int)$today_month,($today_day + $sendout_num),(int)$today_year)));
3985 -
3986 - $res = array(
3987 - 'today_bus_flag' => $today_bus_flag,
3988 - 'time_limit_addition'=> $time_limit_addition,
3989 - 'indication_incart' => $indication_incart,
3990 - 'holiday' => $holiday,
3991 - 'sendout_num' => $sendout_num,
3992 - 'sendout_date' => array('year' => $send_y, 'month' => $send_m, 'day' => $send_d)
3993 - );
3994 - return $res;
3995 -}
3996 -
3997 -function usces_action_footer_comment(){
3998 - echo "<!-- Welcart version : v".USCES_VERSION." -->\n";
3999 -}
4000 -
4001 -function usces_set_acting_notification_time( $key ){
4002 - global $wpdb;
4003 - $tableName = $wpdb->prefix . "usces_access";
4004 - $query = $wpdb->prepare("SELECT ID FROM $tableName WHERE acc_type = %s AND acc_key = %s", 'notification_time', $key);
4005 - $res = $wpdb->get_var( $query );
4006 - if( $res )
4007 - return;
4008 -
4009 - $query = $wpdb->prepare("INSERT INTO $tableName (acc_key, acc_type, acc_num1) VALUES (%s, %s, %d)",
4010 - $key, 'notification_time', time());
4011 - $res = $wpdb->query( $query );
4012 -}
4013 -
4014 -function usces_check_notification_time( $key, $time ){
4015 - global $wpdb;
4016 - $tableName = $wpdb->prefix . "usces_access";
4017 - $query = $wpdb->prepare("SELECT acc_num1 FROM $tableName WHERE acc_type = %s AND acc_key = %s", 'notification_time', $key);
4018 - $res = $wpdb->get_var( $query );
4019 - if( !$res )
4020 - return false;
4021 -
4022 - $past = time() - $res;
4023 - if( $time > $past )
4024 - return true;
4025 - else
4026 - return false;
4027 -}
4028 -
4029 -function usces_is_same_itemcode( $post_id, $item_code ){
4030 - global $wpdb, $usces;
4031 -
4032 - $query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE post_id <> %d AND meta_key = %s AND meta_value = %s", $post_id, '_itemCode', $item_code);
4033 - $ids = $wpdb->get_col( $query );
4034 -// usces_log('ids : '.print_r($query,true), 'acting_transaction.log');
4035 -// usces_log('ids : '.print_r($ids,true), 'acting_transaction.log');
4036 - if( !$ids ){
4037 - return false;
4038 - }
4039 - $id_str = implode(',', $ids);
4040 - $query = "SELECT ID FROM $wpdb->posts WHERE ID IN({$id_str}) AND post_status = 'publish'";
4041 - $res = $wpdb->get_col( $query );
4042 -// usces_log('res : '.print_r($res,true), 'acting_transaction.log');
4043 -// usces_log('res : '.print_r($query,true), 'acting_transaction.log');
4044 - if( !$res ){
4045 - return false;
4046 - }
4047 -
4048 - return $res;
4049 -}
4050 -
4051 -function usces_update_sku( $post_id, $skucode, $fieldname, $value ){
4052 - global $wpdb;
4053 - $metas = usces_get_post_meta($post_id, '_isku_');
4054 - if( ! $metas )
4055 - return false;
4056 -
4057 - $meta_id = '';
4058 - foreach( $metas as $meta ){
4059 - $sku = unserialize($meta['meta_value']);
4060 - if( $skucode == $sku['code'] ){
4061 - $meta_id = $meta['meta_id'];
4062 - $sku[$fieldname] = $value;
4063 - break;
4064 - }
4065 - }
4066 - $serialized_values = serialize($sku);
4067 - if( !empty($meta_id) ) $res = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $serialized_values, $meta_id) );
4068 - if( !$res ){
4069 - return false;
4070 - }else{
4071 - return true;
4072 - }
4073 -}
4074 -
4075 -function usces_get_items_skus() {
4076 - global $wpdb, $usces;
4077 - $res = array();
4078 - $item_codes = array();
4079 - $item_names = array();
4080 - $status = array();
4081 -
4082 - $query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts}
4083 - WHERE post_mime_type = %s AND post_status = %s", 'item', 'publish');
4084 - $IDs = $wpdb->get_col($query);
4085 - if( !$IDs )
4086 - return $res;
4087 -
4088 - //wp_cache_set( 'item_ids', $IDs );
4089 -
4090 - $key = 0;
4091 - foreach((array)$IDs as $post_id){
4092 - $item_codes[$post_id] = $usces->getItemCode($post_id);
4093 - $item_names[$post_id] = $usces->getItemName($post_id);
4094 -
4095 - //$skus = $usces->get_skus($post_id);
4096 - $metas = usces_get_post_meta($post_id, '_isku_');
4097 - foreach( (array)$metas as $mkey => $rows ){
4098 - $metas[$mkey]['meta_value'] = unserialize($rows['meta_value']);
4099 - $allmetas[] = $metas;
4100 -// $sku_post_id[] = $post_id;
4101 -// $sku_code[] = $values['code'];
4102 -// $sku_stocknum[] = $values['stocknum'];
4103 - $status[] = $metas[$mkey]['meta_value']['stock'];
4104 - $key++;
4105 - }
4106 - //usces_log('implode : '.strlen(explode(',', $res)), 'acting_transaction.log');
4107 - }
4108 -// wp_cache_set( 'item_ids', $IDs );
4109 -// wp_cache_set( 'item_codes', $item_codes );
4110 -// wp_cache_set( 'item_names', $item_names );
4111 -// wp_cache_set( 'sku_data', $res );
4112 -// wp_cache_set( 'stock_ct', array_count_values($status) );
4113 -
4114 -}
4115 -function usces_get_non_zerostoc_items() {
4116 - global $wpdb, $usces;
4117 -
4118 - $query = $wpdb->prepare("SELECT ID, code.meta_value AS code, name.meta_value AS name FROM {$wpdb->posts}
4119 - LEFT JOIN {$wpdb->postmeta} AS code ON ID = code.post_id AND '_itemCode' = code.meta_key
4120 - LEFT JOIN {$wpdb->postmeta} AS name ON ID = name.post_id AND '_itemName' = name.meta_key
4121 - LEFT JOIN {$wpdb->postmeta} AS sku ON ID = sku.post_id AND '_isku_' = sku.meta_key
4122 - WHERE post_mime_type = %s AND post_type = %s AND post_status <> %s AND (sku.meta_value LIKE %s OR sku.meta_value LIKE %s)
4123 - GROUP BY ID",
4124 - 'item', 'post', 'trush', '%"stocknum";i:0%', '%"stocknum";s:1:"0"%');
4125 - $res = $wpdb->get_results($query, ARRAY_A);
4126 -
4127 - return $res;
4128 -
4129 -// $key = 0;
4130 -// foreach((array)$items as $item){
4131 -//// $ItemCode = $usces->getItemCode($item['ID']);
4132 -//// $ItemName = $usces->getItemName($item['ID']);
4133 -//
4134 -// //$skus = $usces->get_skus($post_id);
4135 -// $metas = usces_get_post_meta($item['ID'], '_isku_');
4136 -// foreach( (array)$metas as $rows ){
4137 -// $meta_value = unserialize($rows['meta_value']);
4138 -// if( "" != $meta_value['stocknum'] && 0 === (int)$meta_value['stocknum'] ){
4139 -// $res[$key]['ID'] = $item['ID'];
4140 -// $res[$key]['code'] = $item['code'];
4141 -// $res[$key]['name'] = $item['name'];
4142 -// $res[$key]['sku'] = $meta_value['code'];
4143 -// }
4144 -// $key++;
4145 -// }
4146 -// }
4147 -// return $res;
4148 -}
4149 -function usces_get_stocs() {
4150 - global $wpdb, $usces;
4151 - $status = array();
4152 -
4153 - $query = $wpdb->prepare("SELECT m.meta_value FROM {$wpdb->posts} AS p
4154 - LEFT JOIN {$wpdb->postmeta} AS m ON p.ID = m.post_id AND m.meta_key = %s
4155 - WHERE post_mime_type = %s AND post_type = %s AND post_status <> %s"
4156 - , '_isku_', 'item', 'post', 'trush');
4157 - $values = $wpdb->get_col($query);
4158 - if( !$values )
4159 - return $status;
4160 -
4161 - foreach((array)$values as $value){
4162 - $meta_value = unserialize($value);
4163 - $status[] = (string)$meta_value['stock'];
4164 - }
4165 - return array_count_values($status);
4166 -}
4167 -
4168 -function usces_get_deco_order_id( $order_id ) {
4169 - global $usces;
4170 -
4171 - $dec_order_id = $usces->get_order_meta_value( 'dec_order_id', $order_id);
4172 - if( !$dec_order_id ){
4173 - $dec_order_id = str_pad($order_id, $usces->options['system']['dec_orderID_digit'], "0", STR_PAD_LEFT);
4174 - }
4175 - return $dec_order_id;
4176 -}
4177 -
4178 -function usces_mail_line( $type, $email = '' ) {
4179 - $line = '';
4180 -
4181 - switch( $type ) {
4182 - case 1:
4183 - $line = "******************************************************************";
4184 - break;
4185 - case 2:
4186 - $line = "------------------------------------------------------------------";
4187 - break;
4188 - case 3:
4189 - $line = "==================================================================";
4190 - break;
4191 - }
4192 -
4193 - $line = apply_filters( 'usces_filter_mail_line', $line, $type, $email );
4194 -
4195 - return $line."\r\n";
4196 -}
4197 -
4198 -function usces_get_gp_price($post_id, $p, $quant){
4199 - global $usces;
4200 - $GpN1 = $usces->getItemGpNum1($post_id);
4201 - $GpN2 = $usces->getItemGpNum2($post_id);
4202 - $GpN3 = $usces->getItemGpNum3($post_id);
4203 - $GpD1 = $usces->getItemGpDis1($post_id);
4204 - $GpD2 = $usces->getItemGpDis2($post_id);
4205 - $GpD3 = $usces->getItemGpDis3($post_id);
4206 -
4207 - if( empty($GpN1) || empty($GpD1) ) {
4208 -
4209 - $realprice = $p;
4210 -
4211 - }else if( (!empty($GpN1) && !empty($GpD1)) && (empty($GpN2) || empty($GpD2)) ) {
4212 -
4213 - if( $quant >= $GpN1 ) {
4214 - $realprice = round($p * (100 - $GpD1) / 100);
4215 - }else{
4216 - $realprice = $p;
4217 - }
4218 -
4219 - }else if( (!empty($GpN1) && !empty($GpD1)) && (!empty($GpN2) && !empty($GpD2)) && (empty($GpN3) || empty($GpD3)) ) {
4220 -
4221 - if( $quant >= $GpN2 ) {
4222 - $realprice = round($p * (100 - $GpD2) / 100);
4223 - }else if( $quant >= $GpN1 && $quant < $GpN2 ) {
4224 - $realprice = round($p * (100 - $GpD1) / 100);
4225 - }else{
4226 - $realprice = $p;
4227 - }
4228 -
4229 - }else if( (!empty($GpN1) && !empty($GpD1)) && (!empty($GpN2) && !empty($GpD2)) && (!empty($GpN3) && !empty($GpD3)) ) {
4230 -
4231 - if( $quant >= $GpN3 ) {
4232 - $realprice = round($p * (100 - $GpD3) / 100);
4233 - }else if( $quant >= $GpN2 && $quant < $GpN3 ) {
4234 - $realprice = round($p * (100 - $GpD2) / 100);
4235 - }else if( $quant >= $GpN1 && $quant < $GpN2 ) {
4236 - $realprice = round($p * (100 - $GpD1) / 100);
4237 - }else{
4238 - $realprice = $p;
4239 - }
4240 -
4241 - }else{
4242 - $realprice = $p;
4243 - }
4244 -
4245 - $realprice = apply_filters('usces_filter_get_gp_price', $realprice, $post_id, $p, $quant);
4246 - return $realprice;
4247 -}
4248 -//20120306ysk start 0000324
4249 -function usces_is_complete_settlement( $payment_name, $status = '' ) {
4250 - $complete = false;
4251 -//20120919ysk start 0000573
4252 - $options = get_option('usces');
4253 - if( $options['point_assign'] == 0 ) {
4254 - $complete = true;
4255 -//20120919ysk end
4256 - } else {
4257 - $payments = usces_get_system_option( 'usces_payment_method', 'name' );
4258 - if( isset($payments[$payment_name]['settlement']) ) {
4259 - switch( $payments[$payment_name]['settlement'] ) {
4260 - case 'acting':
4261 - if( false !== strpos( $status, 'pending' ) ) break;
4262 - case 'acting_zeus_card':
4263 - case 'acting_remise_card':
4264 - case 'acting_jpayment_card':
4265 - case 'acting_paypal_ec':
4266 - case 'acting_sbps_card':
4267 - case 'acting_telecom_card':
4268 - case 'acting_digitalcheck_card':
4269 - case 'acting_mizuho_card':
4270 - case 'acting_anotherlane_card':
4271 - case 'acting_veritrans_card':
4272 - case 'COD':
4273 - $complete = true;
4274 - }
4275 - }
4276 - }
4277 - $complete = apply_filters( 'usces_filter_is_complete_settlement', $complete, $payment_name, $status );
4278 - return $complete;
4279 -}
4280 -
4281 -function usces_action_acting_getpoint( $order_id, $add = true ) {
4282 - global $usces, $wpdb;
4283 -
4284 - if( !apply_filters( 'usces_action_acting_getpoint_switch', true, $order_id, $add) )
4285 - return;
4286 -
4287 -//20120919ysk start 0000573
4288 - $options = get_option('usces');
4289 - if( $options['point_assign'] != 0 ) {
4290 -//20120919ysk end
4291 - if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] ) {
4292 - $table_name = $wpdb->prefix . "usces_order";
4293 - $mquery = $wpdb->prepare("SELECT mem_id, order_getpoint FROM $table_name WHERE ID = %d", $order_id);
4294 - $values = $wpdb->get_row( $mquery, ARRAY_A );
4295 - $mem_id = $values['mem_id'];
4296 - $getpoint = $values['order_getpoint'];
4297 -
4298 - if( !empty($mem_id) && 0 < $getpoint ) {
4299 - $calc = ($add) ? '+' : '-';
4300 - $member_table_name = $wpdb->prefix . "usces_member";
4301 - $mquery = $wpdb->prepare("UPDATE $member_table_name SET mem_point = (mem_point ".$calc." %d) WHERE ID = %d", $getpoint, $mem_id);
4302 - $wpdb->query( $mquery );
4303 -
4304 - if( !empty($_SESSION['usces_member']['point']) ) {
4305 - $mquery = $wpdb->prepare("SELECT mem_point FROM $member_table_name WHERE ID = %d", $mem_id);
4306 - $point = $wpdb->get_var( $mquery );
4307 - $_SESSION['usces_member']['point'] = $point;
4308 - }
4309 - }
4310 - }
4311 - }
4312 - do_action( 'usces_action_acting_getpoint', $order_id, $add );
4313 -}
4314 -
4315 -function usces_restore_point( $mem_id, $point ) {
4316 - global $wpdb;
4317 -
4318 - if( !apply_filters( 'usces_action_restore_point_switch', true, $mem_id, $point) )
4319 - return;
4320 -
4321 - $member_table_name = $wpdb->prefix . "usces_member";
4322 - $query = $wpdb->prepare( "UPDATE $member_table_name SET mem_point = (mem_point - %d) WHERE ID = %d", $point, $mem_id );
4323 - $wpdb->query( $query );
4324 -}
4325 -//20120306ysk end
4326 -//20120413ysk start
4327 -function usces_set_free_csv( $customer ){
4328 - $free_csv = "";
4329 - if( !WCUtils::is_blank($customer['name1']) ) {
4330 - $free_csv = "LAST_NAME=".mb_convert_encoding($customer['name1'],'SJIS','UTF-8').",FIRST_NAME=".mb_convert_encoding($customer['name2'],'SJIS','UTF-8').",TEL=".str_replace("-","",$customer['tel']).",MAIL=".$customer['mailaddress1'];
4331 - $free_csv = base64_encode( $free_csv );
4332 - }
4333 - return $free_csv;
4334 -}
4335 -//20120413ysk end
4336 -
4337 -function usces_get_itemopt_filed($post_id, $sku, $opt){
4338 - global $usces;
4339 - $sku = urlencode($sku);
4340 - $optcode = urlencode($opt['name']);
4341 - $name = $opt['name'];
4342 - $means = (int)$opt['means'];
4343 - $essential = (int)$opt['essential'];
4344 - $session_value = isset( $_SESSION['usces_singleitem']['itemOption'][$post_id][$sku][$optcode] ) ? $_SESSION['usces_singleitem']['itemOption'][$post_id][$sku][$optcode] : NULL;
4345 -
4346 - $html = '';
4347 - switch($means) {
4348 - case 0://Single-select
4349 - case 1://Multi-select
4350 - $selects = explode("\n", $opt['value']);
4351 - $multiple = ($means === 0) ? '' : ' multiple';
4352 - $multiple_array = ($means == 0) ? '' : '[]';
4353 - $html .= "\n<select name='itemOption[{$post_id}][{$sku}][{$optcode}]{$multiple_array}' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_select'{$multiple} onKeyDown=\"if (event.keyCode == 13) {return false;}\">\n";
4354 - if($essential == 1){
4355 - if( '#NONE#' == $session_value || NULL == $session_value )
4356 - $selected = ' selected="selected"';
4357 - else
4358 - $selected = '';
4359 - $html .= "\t<option value='#NONE#'{$selected}>" . __('Choose','usces') . "</option>\n";
4360 - }
4361 - $i=0;
4362 - foreach($selects as $v) {
4363 - if( ($i == 0 && $essential == 0 && NULL == $session_value) || esc_attr($v) == $session_value )
4364 - $selected = ' selected="selected"';
4365 - else
4366 - $selected = '';
4367 - $html .= "\t<option value='" . esc_attr($v) . "'{$selected}>" . esc_html($v) . "</option>\n";
4368 - $i++;
4369 - }
4370 - $html .= "</select>\n";
4371 - break;
4372 - case 2://Text
4373 - $html .= "\n<input name='itemOption[{$post_id}][{$sku}][{$optcode}]' type='text' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_text' onKeyDown=\"if (event.keyCode == 13) {return false;}\" value=\"" . esc_attr($session_value) . "\" />\n";
4374 - break;
4375 - case 5://Text-area
4376 - $html .= "\n<textarea name='itemOption[{$post_id}][{$sku}][{$optcode}]' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_textarea'>" . esc_attr($session_value) . "</textarea>\n";
4377 - break;
4378 - }
4379 -
4380 - $html = apply_filters('usces_get_itemopt_filed', $html, $post_id, $sku, $opt);
4381 -
4382 - return $html;
4383 -}
4384 -
4385 -function usces_delete_order_check( $order_id ) {
4386 - $res = apply_filters( 'usces_filter_delete_order_check', true, $order_id );
4387 - return $res;
4388 -}
4389 -
4390 -function usces_itempage_admin_bar() {
4391 - global $wp_admin_bar, $post;
4392 - if( is_single() && usces_is_item() ){
4393 - $wp_admin_bar->remove_menu('edit');
4394 - $ref = urlencode(site_url() . '/wp-admin/admin.php?page=usces_itemedit');
4395 - $wp_admin_bar->add_menu( array(
4396 - 'id' => 'edit',
4397 - 'title' => __('Edit item', 'usces'),
4398 - 'href' => site_url() . '/wp-admin/admin.php?page=usces_itemedit&action=edit&post=' . $post->ID . '&usces_referer=' . $ref
4399 - ) );
4400 - }
4401 -}
4402 -
4403 -function usces_rand( $digit = 10 ) {
4404 - $num = str_repeat( "9", $digit );
4405 - $rand = apply_filters( 'usces_filter_rand_value', sprintf( '%0'.$digit.'d', mt_rand( 1, (int)$num ) ), $num );
4406 - return $rand;
4407 -}
4408 -
4409 -function usces_get_cr_symbol() {
4410 - global $usces, $usces_settings;
4411 - $cr = $usces->options['system']['currency'];
4412 - list( $code, $decimal, $point, $seperator, $symbol ) = $usces_settings['currency'][$cr];
4413 - return $symbol;
4414 -}
4415 -
4416 -?>
1 +<?php
2 +/**
3 + * Functions
4 + *
5 + * @package Welcart
6 + */
7 +
8 +function usces_recovery_session_data() {
9 + global $usces;
10 +
11 + $absolute_trans_id = isset( $_REQUEST['absolute_trans_id'] ) ? $_REQUEST['absolute_trans_id'] : 0;
12 +
13 + if ( ! $absolute_trans_id ) {
14 + return;
15 + }
16 +
17 + $order_data = usces_get_acting_data( $absolute_trans_id );
18 +
19 + if ( ! empty( $order_data['usces_entry'] ) ) {
20 + $_SESSION['usces_member'] = $order_data['usces_member'];
21 + $_SESSION['usces_cart'] = $order_data['usces_cart'];
22 + $_SESSION['usces_entry'] = $order_data['usces_entry'];
23 + }
24 +}
25 +
26 +function usces_reg_orderdata( $results = array() ) {
27 + global $wpdb, $usces;
28 +
29 + $options = get_option( 'usces', array() );
30 + $cart = $usces->cart->get_cart();
31 + $entry = $usces->cart->get_entry();
32 +
33 + if ( empty( $cart ) ) {
34 +
35 + // Trying to get back the entry data.
36 + usces_recovery_session_data();
37 + $cart = $usces->cart->get_cart();
38 + $entry = $usces->cart->get_entry();
39 +
40 + if ( empty( $cart ) ) {
41 + $linkkey = usces_get_link_key( $results );
42 + $log = array(
43 + 'acting' => 'reg_orderdata',
44 + 'key' => $linkkey,
45 + 'result' => 'SESSION EMPTY',
46 + 'data' => $_REQUEST,
47 + );
48 + usces_save_order_acting_error( $log );
49 + return 0;
50 + } else {
51 + $log = array(
52 + 'acting' => 'reg_orderdata',
53 + 'key' => $_REQUEST['absolute_trans_id'],
54 + 'result' => 'OK SESSION RECOVERY',
55 + 'data' => $_REQUEST,
56 + );
57 + usces_save_order_acting_error( $log );
58 +
59 + }
60 + }
61 +
62 + // Anti-spam.
63 + if ( ( empty( $entry['customer']['name1'] ) && empty( $entry['customer']['name2'] ) ) || empty( $entry['customer']['mailaddress1'] ) || empty( $entry ) || empty( $cart ) ) {
64 + $anti_spam = apply_filters( 'usces_filter_reg_orderdata_anti_spam', false, $entry, $cart );
65 + if ( ! $anti_spam ) {
66 + usces_log( 'reg_orderdata : Anti-spam', 'acting_transaction.log' );
67 + return false;
68 + }
69 + }
70 +
71 + $charging_type = $usces->getItemChargingType( $cart[0]['post_id'] );
72 +
73 + $item_total_price = $usces->get_total_price( $cart );
74 + $member = $usces->get_member();
75 + $order_table_name = $wpdb->prefix . 'usces_order';
76 + $order_table_meta_name = $wpdb->prefix . 'usces_order_meta';
77 + $member_table_name = usces_get_tablename( 'usces_member' );
78 + $set = $usces->getPayments( $entry['order']['payment_name'] );
79 + $status = '';
80 + $gmtdate = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) );
81 + if ( 'continue' === $charging_type ) {
82 + $order_modified = substr( $gmtdate, 0, 10 );
83 + } else {
84 + $noreceipt_status_table = apply_filters( 'usces_filter_noreceipt_status', get_option( 'usces_noreceipt_status' ) );
85 +
86 + $status = ( in_array( $set['settlement'], $noreceipt_status_table ) ) ? 'noreceipt' : '';
87 + $order_modified = NULL;
88 + }
89 +
90 + if ( 'paypal.php' === $set['module'] || 'acting_paypal_ec' === $set['settlement'] ) {
91 + if ( ( isset( $results['payment_status'] ) && 'Completed' !== $results['payment_status'] ) || ( isset( $results['profile_status'] ) && 'ActiveProfile' !== $results['profile_status'] ) ) {
92 + $status = 'pending';
93 + }
94 + }
95 +
96 + $status = apply_filters( 'usces_filter_reg_orderdata_status', $status, $entry );
97 + $order_date = ( isset( $results['order_date'] ) ) ? $results['order_date'] : $gmtdate;
98 + $delidue_date = ( isset( $entry['order']['delidue_date'] ) ) ? $entry['order']['delidue_date'] : NULL;
99 + $query = $wpdb->prepare(
100 + "INSERT INTO $order_table_name (
101 + `mem_id`, `order_email`, `order_name1`, `order_name2`, `order_name3`, `order_name4`,
102 + `order_zip`, `order_pref`, `order_address1`, `order_address2`, `order_address3`,
103 + `order_tel`, `order_fax`, `order_delivery`, `order_cart`, `order_note`, `order_delivery_method`, `order_delivery_date`, `order_delivery_time`,
104 + `order_payment_name`, `order_condition`, `order_item_total_price`, `order_getpoint`, `order_usedpoint`, `order_discount`,
105 + `order_shipping_charge`, `order_cod_fee`, `order_tax`, `order_date`, `order_modified`, `order_status`, `order_delidue_date` )
106 + VALUES (%d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s, %s, %f, %d, %d, %f, %f, %f, %f, %s, %s, %s, %s)",
107 + $member['ID'],
108 + $entry['customer']['mailaddress1'],
109 + $entry['customer']['name1'],
110 + $entry['customer']['name2'],
111 + $entry['customer']['name3'],
112 + $entry['customer']['name4'],
113 + $entry['customer']['zipcode'],
114 + $entry['customer']['pref'],
115 + $entry['customer']['address1'],
116 + $entry['customer']['address2'],
117 + $entry['customer']['address3'],
118 + $entry['customer']['tel'],
119 + $entry['customer']['fax'],
120 + serialize( $entry['delivery'] ),
121 + serialize( $cart ),
122 + $entry['order']['note'],
123 + $entry['order']['delivery_method'],
124 + $entry['order']['delivery_date'],
125 + $entry['order']['delivery_time'],
126 + $entry['order']['payment_name'],
127 + serialize( $entry['condition'] ),
128 + $item_total_price,
129 + $entry['order']['getpoint'],
130 + $entry['order']['usedpoint'],
131 + $entry['order']['discount'],
132 + $entry['order']['shipping_charge'],
133 + $entry['order']['cod_fee'],
134 + $entry['order']['tax'],
135 + $order_date,
136 + $order_modified,
137 + $status,
138 + $delidue_date
139 + );
140 +
141 + $res = $wpdb->query( $query );
142 +
143 + if ( false === $res ) {
144 + $order_id = false;
145 + usces_log( 'reg_orderdata : ' . $wpdb->last_error, 'database_error.log' );
146 + } else {
147 + $order_id = $wpdb->insert_id;
148 + }
149 +
150 + if ( ! $order_id ) {
151 + usces_log( 'reg_error_entry : ' . print_r( $entry, true ), 'acting_transaction.log' );
152 + return false;
153 + }
154 +
155 + $usces->cart->set_order_entry( array( 'ID' => $order_id ) );
156 + $usces->set_order_meta_value( 'customer_country', $entry['customer']['country'], $order_id );
157 +
158 + if ( usces_is_tax_display() && usces_is_reduced_taxrate() ) {
159 + $usces_tax = Welcart_Tax::get_instance();
160 + $materials = array(
161 + 'total_items_price' => $entry['order']['total_items_price'],
162 + 'discount' => ( isset( $entry['order']['discount'] ) ) ? $entry['order']['discount'] : 0,
163 + 'shipping_charge' => ( isset( $entry['order']['shipping_charge'] ) ) ? $entry['order']['shipping_charge'] : 0,
164 + 'cod_fee' => ( isset( $entry['order']['cod_fee'] ) ) ? $entry['order']['cod_fee'] : 0,
165 + 'use_point' => ( isset( $entry['order']['usedpoint'] ) ) ? $entry['order']['usedpoint'] : 0,
166 + 'carts' => $cart,
167 + 'condition' => $entry['condition'],
168 + );
169 + $usces_tax->get_order_tax( $materials );
170 + $usces->set_order_meta_value( 'subtotal_standard', $usces_tax->subtotal_standard, $order_id );
171 + $usces->set_order_meta_value( 'subtotal_reduced', $usces_tax->subtotal_reduced, $order_id );
172 + $usces->set_order_meta_value( 'discount_standard', $usces_tax->discount_standard, $order_id );
173 + $usces->set_order_meta_value( 'discount_reduced', $usces_tax->discount_reduced, $order_id );
174 + if ( 'include' === $usces->options['tax_mode'] ) {
175 + $usces->set_order_meta_value( 'tax_standard', 0, $order_id );
176 + $usces->set_order_meta_value( 'tax_reduced', 0, $order_id );
177 + } else {
178 + $usces->set_order_meta_value( 'tax_standard', $usces_tax->tax_standard, $order_id );
179 + $usces->set_order_meta_value( 'tax_reduced', $usces_tax->tax_reduced, $order_id );
180 + }
181 + }
182 +
183 + if ( $member['ID'] && 'activate' === $options['membersystem_state'] && 'activate' === $options['membersystem_point'] ) {
184 +
185 + $mquery = '';
186 + if ( usces_is_complete_settlement( $entry['order']['payment_name'], $status ) ) {
187 + if ( apply_filters( 'usces_action_acting_getpoint_switch', true, $order_id, true ) ) {
188 + $mquery = $wpdb->prepare(
189 + "UPDATE $member_table_name SET mem_point = (mem_point + %d - %d) WHERE ID = %d",
190 + $entry['order']['getpoint'], $entry['order']['usedpoint'], $member['ID']
191 + );
192 + } else {
193 + $mquery = $wpdb->prepare(
194 + "UPDATE $member_table_name SET mem_point = (mem_point - %d) WHERE ID = %d",
195 + $entry['order']['usedpoint'], $member['ID']
196 + );
197 + }
198 + } elseif ( 0 < $entry['order']['usedpoint'] ) {
199 + $mquery = $wpdb->prepare(
200 + "UPDATE $member_table_name SET mem_point = (mem_point - %d) WHERE ID = %d",
201 + $entry['order']['usedpoint'], $member['ID']
202 + );
203 + }
204 + if ( $mquery ) {
205 + $wpdb->query( $mquery );
206 + $mquery = $wpdb->prepare( "SELECT mem_point FROM $member_table_name WHERE ID = %d", $member['ID'] );
207 + $point = $wpdb->get_var( $mquery );
208 + $_SESSION['usces_member']['point'] = $point;
209 + }
210 +
211 + }
212 +
213 + if ( ! empty( $entry['reserve'] ) ) {
214 + foreach ( $entry['reserve'] as $key => $value ) {
215 + if ( is_array( $value ) ) {
216 + $value = serialize( $value );
217 + }
218 + $usces->set_order_meta_value( $key, $value, $order_id );
219 + }
220 + }
221 +
222 + if ( ! preg_match( '/pending|noreceipt/', $status ) ) {
223 + $usces->set_order_meta_value( 'receipted_date', $gmtdate, $order_id );
224 + }
225 +
226 + if ( ! empty( $entry['custom_order'] ) ) {
227 + foreach ( $entry['custom_order'] as $key => $value ) {
228 + $csod_key = 'csod_' . $key;
229 + $value = wel_safe_text_serialize( $value );
230 + if ( is_array( $value ) ) {
231 + $value = serialize( $value );
232 + }
233 + $usces->set_order_meta_value( $csod_key, $value, $order_id );
234 + }
235 + }
236 + if ( ! empty( $entry['custom_customer'] ) ) {
237 + foreach ( $entry['custom_customer'] as $key => $value ) {
238 + $cscs_key = 'cscs_' . $key;
239 + $value = wel_safe_text_serialize( $value );
240 + if ( is_array( $value ) ) {
241 + $value = serialize( $value );
242 + }
243 + $usces->set_order_meta_value( $cscs_key, $value, $order_id );
244 + }
245 + }
246 + if ( ! empty( $entry['custom_delivery'] ) ) {
247 + foreach ( $entry['custom_delivery'] as $key => $value ) {
248 + $csde_key = 'csde_' . $key;
249 + $value = wel_safe_text_serialize( $value );
250 + if ( is_array( $value ) ) {
251 + $value = serialize( $value );
252 + }
253 + $usces->set_order_meta_value( $csde_key, $value, $order_id );
254 + }
255 + }
256 +
257 + $args = array(
258 + 'cart' => $cart,
259 + 'entry' => $entry,
260 + 'order_id' => $order_id,
261 + 'member_id' => $member['ID'],
262 + 'payments' => $set,
263 + 'charging_type' => $charging_type,
264 + 'results' => $results,
265 + );
266 + do_action( 'usces_action_reg_orderdata', $args );
267 +
268 + return $order_id;
269 +}
270 +
271 +function usces_new_orderdata() {
272 + global $wpdb, $usces;
273 +
274 + $_POST = $usces->stripslashes_deep_post( $_POST );
275 + $_POST['customer']['name3'] = isset( $_POST['customer']['name3'] ) ? $_POST['customer']['name3'] : '';
276 + $_POST['customer']['name4'] = isset( $_POST['customer']['name4'] ) ? $_POST['customer']['name4'] : '';
277 + $usces->cart->crear_cart();
278 + $cart = $usces->cart->get_cart();
279 + $item_total_price = $usces->get_total_price( $cart );
280 + $entry = $usces->cart->get_entry();
281 + $member_id = $usces->get_memberid_by_email( $_POST['customer']['mailaddress'] );
282 + $order_table_name = $wpdb->prefix . 'usces_order';
283 + $order_table_meta_name = $wpdb->prefix . 'usces_order_meta';
284 + $member_table_name = usces_get_tablename( 'usces_member' );
285 + $set = $usces->getPayments( $_POST['offer']['payment_name'] );
286 + if ( isset( $_POST['offer']['receipt'] ) ) {
287 + $status = $_POST['offer']['receipt'] . ',';
288 + } else {
289 + $noreceipt_status_table = apply_filters( 'usces_filter_noreceipt_status', get_option( 'usces_noreceipt_status' ) );
290 + $status = ( in_array( $set['settlement'], $noreceipt_status_table ) ) ? 'noreceipt' : '';
291 + }
292 + $status .= ( ! WCUtils::is_blank( $_POST['offer']['taio'] ) && '#none#' !== $_POST['offer']['taio'] ) ? $_POST['offer']['taio'] . ',' : '';
293 + $status .= $_POST['offer']['admin'];
294 + $status = apply_filters( 'usces_filter_new_orderdata_status', $status, $entry );
295 + $order_conditions = $usces->get_condition();
296 + $gmtdate = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) );
297 +
298 + $delivery_date = $_POST['offer']['delivery_date'];
299 + if ( ! usces_is_date( $delivery_date ) ) {
300 + $delivery_date = apply_filters( 'usces_filter_label_delivery_date_no_preference', __( 'Non-request', 'usces_dual' ) );
301 + }
302 +
303 + $query = $wpdb->prepare(
304 + "INSERT INTO $order_table_name (
305 + `mem_id`, `order_email`, `order_name1`, `order_name2`, `order_name3`, `order_name4`,
306 + `order_zip`, `order_pref`, `order_address1`, `order_address2`, `order_address3`,
307 + `order_tel`, `order_fax`, `order_delivery`, `order_cart`, `order_note`, `order_delivery_method`, `order_delivery_date`, `order_delivery_time`,
308 + `order_payment_name`, `order_condition`, `order_item_total_price`, `order_getpoint`, `order_usedpoint`, `order_discount`,
309 + `order_shipping_charge`, `order_cod_fee`, `order_tax`, `order_date`, `order_modified`, `order_status`, `order_delidue_date` )
310 + VALUES (%d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s, %s, %f, %d, %d, %f, %f, %f, %f, %s, %s, %s, %s)",
311 + $member_id,
312 + $_POST['customer']['mailaddress'],
313 + $_POST['customer']['name1'],
314 + $_POST['customer']['name2'],
315 + $_POST['customer']['name3'],
316 + $_POST['customer']['name4'],
317 + $_POST['customer']['zipcode'],
318 + $_POST['customer']['pref'],
319 + $_POST['customer']['address1'],
320 + $_POST['customer']['address2'],
321 + $_POST['customer']['address3'],
322 + $_POST['customer']['tel'],
323 + $_POST['customer']['fax'],
324 + serialize( $_POST['delivery'] ),
325 + serialize( $cart ),
326 + $_POST['offer']['note'],
327 + $_POST['offer']['delivery_method'],
328 + $delivery_date,
329 + $_POST['offer']['delivery_time'],
330 + $_POST['offer']['payment_name'],
331 + serialize( $order_conditions ),
332 + $item_total_price,
333 + $_POST['offer']['getpoint'],
334 + $_POST['offer']['usedpoint'],
335 + $_POST['offer']['discount'],
336 + $_POST['offer']['shipping_charge'],
337 + $_POST['offer']['cod_fee'],
338 + $_POST['offer']['tax'],
339 + $gmtdate,
340 + null,
341 + $status,
342 + $_POST['offer']['delidue_date']
343 + );
344 +
345 + $res = $wpdb->query( $query );
346 + $order_id = $wpdb->insert_id;
347 + $_REQUEST['order_id'] = $wpdb->insert_id;
348 +
349 + if ( ! $order_id ) {
350 + return false;
351 + }
352 +
353 + $usces->set_order_meta_value( 'customer_country', $_POST['customer']['country'], $order_id );
354 +
355 + if ( usces_is_tax_display() && usces_is_reduced_taxrate() ) {
356 + $usces_tax = Welcart_Tax::get_instance();
357 + $materials = array(
358 + 'total_items_price' => $item_total_price,
359 + 'discount' => $_POST['offer']['discount'],
360 + 'shipping_charge' => $_POST['offer']['shipping_charge'],
361 + 'cod_fee' => $_POST['offer']['cod_fee'],
362 + 'use_point' => $_POST['offer']['usedpoint'],
363 + 'carts' => $cart,
364 + 'condition' => $order_conditions,
365 + );
366 + $usces_tax->get_order_tax( $materials );
367 + $usces->set_order_meta_value( 'subtotal_standard', $usces_tax->subtotal_standard, $order_id );
368 + $usces->set_order_meta_value( 'subtotal_reduced', $usces_tax->subtotal_reduced, $order_id );
369 + $usces->set_order_meta_value( 'discount_standard', $usces_tax->discount_standard, $order_id );
370 + $usces->set_order_meta_value( 'discount_reduced', $usces_tax->discount_reduced, $order_id );
371 + if ( 'include' === $usces->options['tax_mode'] ) {
372 + $usces->set_order_meta_value( 'tax_standard', 0, $order_id );
373 + $usces->set_order_meta_value( 'tax_reduced', 0, $order_id );
374 + } else {
375 + $usces->set_order_meta_value( 'tax_standard', $usces_tax->tax_standard, $order_id );
376 + $usces->set_order_meta_value( 'tax_reduced', $usces_tax->tax_reduced, $order_id );
377 + }
378 + }
379 +
380 + if ( ! empty( $_POST['custom_order'] ) ) {
381 + $csod_meta = usces_has_custom_field_meta( 'order' );
382 + foreach ( $_POST['custom_order'] as $key => $value ) {
383 + if ( ! is_array( $csod_meta ) || ! isset( $csod_meta[ $key ] ) ) {
384 + continue;
385 + }
386 + $csod_key = 'csod_' . $key;
387 + if ( is_array( $value ) ) {
388 + $value = serialize( $value );
389 + }
390 + $usces->set_order_meta_value( $csod_key, $value, $order_id );
391 + }
392 + }
393 + if ( ! empty( $_POST['custom_customer'] ) ) {
394 + foreach ( $_POST['custom_customer'] as $key => $value ) {
395 + $cscs_key = 'cscs_' . $key;
396 + if ( is_array( $value ) ) {
397 + $value = serialize( $value );
398 + }
399 + $usces->set_order_meta_value( $cscs_key, $value, $order_id );
400 + }
401 + }
402 + if ( ! empty( $_POST['custom_delivery'] ) ) {
403 + foreach ( $_POST['custom_delivery'] as $key => $value ) {
404 + $csde_key = 'csde_' . $key;
405 + if ( is_array( $value ) ) {
406 + $value = serialize( $value );
407 + }
408 + $usces->set_order_meta_value( $csde_key, $value, $order_id );
409 + }
410 + }
411 + if ( ! preg_match( '/pending|noreceipt/', $status ) ) {
412 + $usces->set_order_meta_value( 'receipted_date', $gmtdate, $order_id );
413 + }
414 + $args = array(
415 + 'cart' => $cart,
416 + 'entry' => $entry,
417 + 'order_id' => $order_id,
418 + 'member_id' => $member_id,
419 + 'payments' => $set,
420 + );
421 + do_action( 'usces_action_reg_orderdata', $args );
422 +
423 + $usces->cart->crear_cart();
424 + return $res;
425 +}
426 +
427 +function usces_new_memberdata() {
428 + global $wpdb, $usces;
429 +
430 + $_POST = $usces->stripslashes_deep_post( $_POST );
431 + $_POST['member']['name3'] = isset( $_POST['member']['name3'] ) ? $_POST['member']['name3'] : '';
432 + $_POST['member']['name4'] = isset( $_POST['member']['name4'] ) ? $_POST['member']['name4'] : '';
433 + $salt = usces_get_salt( '', 1 );
434 + $pass = usces_get_hash( trim( $_POST['member']['password'] ), $salt, 1 );
435 + $member_table_name = usces_get_tablename( 'usces_member' );
436 + $member_table_meta_name = usces_get_tablename( 'usces_member_meta' );
437 + $gmtdate = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) );
438 + $query = $wpdb->prepare(
439 + "INSERT INTO $member_table_name
440 + (`mem_email`, `mem_pass`, `mem_status`, `mem_cookie`, `mem_point`,
441 + `mem_name1`, `mem_name2`, `mem_name3`, `mem_name4`, `mem_zip`, `mem_pref`,
442 + `mem_address1`, `mem_address2`, `mem_address3`, `mem_tel`, `mem_fax`,
443 + `mem_delivery_flag`, `mem_delivery`, `mem_registered`, `mem_nicename`)
444 + VALUES (%s, %s, %d, %s, %d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s)",
445 + trim( $_POST['member']['email'] ),
446 + $pass,
447 + trim( $_POST['member']['status'] ),
448 + '',
449 + trim( $_POST['member']['point'] ),
450 + trim( $_POST['member']['name1'] ),
451 + trim( $_POST['member']['name2'] ),
452 + trim( $_POST['member']['name3'] ),
453 + trim( $_POST['member']['name4'] ),
454 + trim( $_POST['member']['zipcode'] ),
455 + trim( $_POST['member']['pref'] ),
456 + trim( $_POST['member']['address1'] ),
457 + trim( $_POST['member']['address2'] ),
458 + trim( $_POST['member']['address3'] ),
459 + trim( $_POST['member']['tel'] ),
460 + trim( $_POST['member']['fax'] ),
461 + '',
462 + '',
463 + $gmtdate,
464 + ''
465 + );
466 + $res[0] = $wpdb->query( $query );
467 +
468 + if ( false === $res[0] ) {
469 + return false;
470 + }
471 +
472 + $member_id = $wpdb->insert_id;
473 + $_REQUEST['member_id'] = $wpdb->insert_id;
474 + if ( ! $member_id ) {
475 + return false;
476 + }
477 +
478 + $usces->set_member_meta_value( 'customer_country', $_POST['member']['country'], $member_id );
479 + $csmb_meta = usces_has_custom_field_meta( 'member' );
480 + if ( is_array( $csmb_meta ) ) {
481 + foreach ( $csmb_meta as $key => $entry ) {
482 + if ( 4 === (int) $entry['means'] ) {
483 + $usces->del_member_meta( 'csmb_' . $key, $member_id );
484 + }
485 + }
486 + }
487 + $admb_meta = usces_has_custom_field_meta( 'admin_member' );
488 + if ( is_array( $admb_meta ) ) {
489 + foreach ( $admb_meta as $key => $entry ) {
490 + if ( 4 === (int) $entry['means'] ) {
491 + $usces->del_member_meta( 'admb_' . $key, $member_id );
492 + }
493 + }
494 + }
495 + $i = 1;
496 + if ( ! empty( $_POST['custom_member'] ) ) {
497 + foreach ( $_POST['custom_member'] as $key => $value ) {
498 + $csmb_key = 'csmb_' . $key;
499 + if ( is_array( $value ) ) {
500 + $value = serialize( $value );
501 + }
502 + $res[ $i ] = $usces->set_member_meta_value( $csmb_key, $value, $member_id );
503 + if ( false === $res[ $i ] ) {
504 + return false;
505 + }
506 + $i++;
507 + }
508 + }
509 + if ( ! empty( $_POST['admin_custom_member'] ) ) {
510 + foreach ( $_POST['admin_custom_member'] as $key => $value ) {
511 + $admb_key = 'admb_' . $key;
512 + if ( is_array( $value ) ) {
513 + $value = serialize( $value );
514 + }
515 + $res[ $i ] = $usces->set_member_meta_value( $admb_key, $value, $member_id );
516 + if ( false === $res[ $i ] ) {
517 + return false;
518 + }
519 + $i++;
520 + }
521 + }
522 + if ( ! empty( $salt ) ) {
523 + $res[ $i ] = $usces->set_member_meta_value( 'mem_salt', $salt, $member_id );
524 + $i++;
525 + }
526 + $result = ( 0 < array_sum( array_filter( $res, 'is_numeric' ) ) ) ? 1 : 0;
527 +
528 + do_action( 'usces_action_post_new_memberdata', $member_id, $res[0] );
529 +
530 + return $result;
531 +}
532 +
533 +function usces_delete_memberdata( $ID = 0 ) {
534 + global $wpdb, $usces;
535 +
536 + if ( 0 === (int) $ID ) {
537 + if ( ! isset( $_REQUEST['member_id'] ) || WCUtils::is_blank( $_REQUEST['member_id'] ) ) {
538 + return 0;
539 + }
540 + $ID = $_REQUEST['member_id'];
541 + }
542 + do_action( 'usces_action_pre_delete_memberdata', $ID );
543 +
544 + $member_table_name = usces_get_tablename( 'usces_member' );
545 + $member_table_meta_name = usces_get_tablename( 'usces_member_meta' );
546 +
547 + $query = $wpdb->prepare( "DELETE FROM $member_table_name WHERE ID = %d", $ID );
548 + $res = $wpdb->query( $query );
549 + if ( $res ) {
550 + $query = $wpdb->prepare( "DELETE FROM $member_table_meta_name WHERE member_id = %d", $ID );
551 + $wpdb->query( $query );
552 + }
553 + do_action( 'usces_action_post_delete_memberdata', $res, $ID );
554 +
555 + return $res;
556 +}
557 +
558 +function usces_update_memberdata() {
559 + global $wpdb, $usces;
560 +
561 + $_POST = $usces->stripslashes_deep_post( $_POST );
562 +
563 + $member_table_name = usces_get_tablename( 'usces_member' );
564 + $member_table_meta_name = usces_get_tablename( 'usces_member_meta' );
565 +
566 + $ID = (int) $_REQUEST['member_id'];
567 + $name3 = ( isset( $_POST['member']['name3'] ) ) ? trim( $_POST['member']['name3'] ) : '';
568 + $name4 = ( isset( $_POST['member']['name4'] ) ) ? trim( $_POST['member']['name4'] ) : '';
569 +
570 + $query = $wpdb->prepare(
571 + "UPDATE $member_table_name SET
572 + `mem_email`=%s, `mem_status`=%s, `mem_point`=%d, `mem_name1`=%s, `mem_name2`=%s,
573 + `mem_name3`=%s, `mem_name4`=%s, `mem_zip`=%s, `mem_pref`=%s, `mem_address1`=%s,
574 + `mem_address2`=%s, `mem_address3`=%s, `mem_tel`=%s, `mem_fax`=%s
575 + WHERE ID = %d",
576 + trim( $_POST['member']['email'] ),
577 + trim( $_POST['member']['status'] ),
578 + trim( $_POST['member']['point'] ),
579 + trim( $_POST['member']['name1'] ),
580 + trim( $_POST['member']['name2'] ),
581 + $name3,
582 + $name4,
583 + trim( $_POST['member']['zipcode'] ),
584 + trim( $_POST['member']['pref'] ),
585 + trim( $_POST['member']['address1'] ),
586 + trim( $_POST['member']['address2'] ),
587 + trim( $_POST['member']['address3'] ),
588 + trim( $_POST['member']['tel'] ),
589 + trim( $_POST['member']['fax'] ),
590 + $ID
591 + );
592 +
593 + do_action( 'usces_action_pre_update_memberdata', $ID );
594 + $res[0] = $wpdb->query( $query );
595 +
596 + do_action( 'usces_action_post_update_memberdata', $ID, $res[0] );
597 +
598 + if ( false === $res[0] ) {
599 + return false;
600 + }
601 +
602 + $usces->set_member_meta_value( 'customer_country', $_POST['member']['country'], $ID );
603 + $csmb_meta = usces_has_custom_field_meta( 'member' );
604 + if ( is_array( $csmb_meta ) ) {
605 + foreach ( $csmb_meta as $key => $entry ) {
606 + if ( 4 === (int) $entry['means'] ) {
607 + $usces->del_member_meta( 'csmb_' . $key, $ID );
608 + }
609 + }
610 + }
611 + $admb_meta = usces_has_custom_field_meta( 'admin_member' );
612 + if ( is_array( $admb_meta ) ) {
613 + foreach ( $admb_meta as $key => $entry ) {
614 + if ( 4 === (int) $entry['means'] ) {
615 + $usces->del_member_meta( 'admb_' . $key, $ID );
616 + }
617 + }
618 + }
619 + $i = 1;
620 + if ( ! empty( $_POST['custom_member'] ) ) {
621 + foreach ( $_POST['custom_member'] as $key => $value ) {
622 + $csmb_key = 'csmb_' . $key;
623 + if ( is_array( $value ) ) {
624 + $value = serialize( $value );
625 + }
626 + $res[ $i ] = $usces->set_member_meta_value( $csmb_key, $value, $ID );
627 + if ( false === $res[ $i ] ) {
628 + return false;
629 + }
630 + $i++;
631 + }
632 + }
633 + if ( ! empty( $_POST['admin_custom_member'] ) ) {
634 + foreach ( $_POST['admin_custom_member'] as $key => $value ) {
635 + $admb_key = 'admb_' . $key;
636 + if ( is_array( $value ) ) {
637 + $value = serialize( $value );
638 + }
639 + $res[ $i ] = $usces->set_member_meta_value( $admb_key, $value, $ID );
640 + if ( false === $res[ $i ] ) {
641 + return false;
642 + }
643 + $i++;
644 + }
645 + }
646 +
647 + do_action( 'usces_action_post_update_after_memberdata', $ID, $res );
648 +
649 + $result = ( 0 < array_sum( array_filter( $res, 'is_numeric' ) ) ) ? 1 : 0;
650 + return $result;
651 +}
652 +
653 +function usces_delete_orderdata() {
654 + global $wpdb, $usces;
655 +
656 + if ( ! isset( $_REQUEST['order_id'] ) || WCUtils::is_blank( $_REQUEST['order_id'] ) ) {
657 + return 0;
658 + }
659 + $order_table = $wpdb->prefix . 'usces_order';
660 + $order_meta_table = $wpdb->prefix . 'usces_order_meta';
661 + $ID = $_REQUEST['order_id'];
662 +
663 + $del = usces_delete_order_check( $ID );
664 + if ( $del ) {
665 +
666 + $query = $wpdb->prepare( "SELECT * FROM $order_table WHERE ID = %d", $ID );
667 + $order_data = $wpdb->get_row( $query, OBJECT );
668 + $point = 0;
669 + if ( 'activate' === $usces->options['membersystem_state'] && 'activate' === $usces->options['membersystem_point'] && ! empty( $order_data->mem_id ) && ! $usces->is_status( 'cancel', $order_data->order_status ) ) {
670 + if ( 0 < $order_data->order_getpoint ) {
671 + if ( usces_is_complete_settlement( $order_data->order_payment_name, $order_data->order_status ) || $usces->is_status( 'receipted', $order_data->order_status) ) {
672 + $point += $order_data->order_getpoint;
673 + }
674 + }
675 + if ( 0 < $order_data->order_usedpoint ) {
676 + $point -= $order_data->order_usedpoint;
677 + }
678 + }
679 +
680 + $query = $wpdb->prepare( "DELETE FROM $order_table WHERE ID = %d", $ID );
681 + $res = $wpdb->query( $query );
682 +
683 + $args = compact( 'ID', 'point', 'res' );
684 +
685 + if ( $res ) {
686 +
687 + do_action( 'usces_action_del_orderdata', $order_data, $args );
688 +
689 + $query = $wpdb->prepare( "DELETE FROM $order_meta_table WHERE order_id = %d", $ID );
690 + $wpdb->query( $query );
691 +
692 + usces_delete_ordercartdata( NULL, $ID );
693 +
694 + if ( 0 != $point ) {
695 + usces_restore_point( $order_data->mem_id, $point );
696 + }
697 + }
698 +
699 + } else {
700 + $res = true;
701 + }
702 +
703 + return $res;
704 +}
705 +
706 +function usces_update_serialized_cart() {
707 + global $wpdb, $usces;
708 +
709 + if ( ! isset( $_REQUEST['order_id'] ) || WCUtils::is_blank( $_REQUEST['order_id'] ) ) {
710 + return 0;
711 + }
712 +
713 + $ID = $_REQUEST['order_id'];
714 +
715 + $order_table_name = $wpdb->prefix . 'usces_order';
716 + $usces->cart->crear_cart();
717 + $usces->cart->upCart();
718 + $cart = $usces->cart->get_cart();
719 + if ( $cart && is_array( $cart ) && 0 < count( $cart ) ) {
720 + // $idx = count( $cart ) - 1;
721 + // $post_id = $cart[ $idx ]['post_id'];
722 + // $sku = $cart[ $idx ]['sku'];
723 + // $sku_code = esc_attr( urldecode( $sku ) );
724 + // $cartItemName = $usces->getCartItemName( $post_id, $sku_code, false );
725 + // $skuPrice = $cart[ $idx ]['price'];
726 +
727 + $query = $wpdb->prepare(
728 + "UPDATE $order_table_name SET `order_cart`=%s WHERE ID = %d",
729 + serialize( $cart ),
730 + $ID
731 + );
732 + $res = $wpdb->query( $query );
733 +
734 + $usces->cart->crear_cart();
735 + }
736 +}
737 +
738 +function usces_delete_serialized_cart() {
739 + global $wpdb, $usces;
740 +
741 + if ( ! isset( $_REQUEST['order_id'] ) || WCUtils::is_blank( $_REQUEST['order_id'] ) ) {
742 + return 0;
743 + }
744 +
745 + $indexs = array_keys( $_POST['delButton'] );
746 + $index = $indexs[0];
747 + $ids = array_keys( $_POST['delButton'][ $index ] );
748 + $post_id = $ids[0];
749 + $skus = array_keys( $_POST['delButton'][ $index ][ $post_id ] );
750 + $sku = $skus[0];
751 +
752 + $usces->up_serialize( $index, $post_id, $sku );
753 + do_action( 'usces_cart_del_row', $index );
754 +
755 + if ( isset( $_SESSION['usces_cart'][ $usces->serial ] ) ) {
756 + unset( $_SESSION['usces_cart'][ $usces->serial ] );
757 + }
758 +
759 + unset( $_SESSION['usces_entry']['order']['usedpoint'] );
760 +}
761 +
762 +function usces_get_serialized_cart( $order_id ) {
763 + global $wpdb, $usces;
764 +
765 + $order_table_name = $wpdb->prefix . 'usces_order';
766 + $query = $wpdb->prepare( "SELECT order_cart FROM $order_table_name WHERE ID = %d", $order_id );
767 + $order_cart = $wpdb->get_var( $query );
768 + $cart = wel_safe_unserialize( $order_cart );
769 + foreach ( $cart as $cart_index => $cart_row ) {
770 + $options = array();
771 + if ( ! empty( $cart_row['options'] ) ) {
772 + foreach ( $cart_row['options'] as $key => $value ) {
773 + $key = urldecode( $key );
774 + if ( is_array( $value ) ) {
775 + foreach ( $value as $vk => $vv ) {
776 + $value[ $vk ] = urldecode( $vv );
777 + }
778 + $options[ $key ] = $value;
779 + } else {
780 + $options[ $key ] = urldecode( $value );
781 + }
782 + }
783 + $cart_row['options'] = $options;
784 + }
785 + $cart[ $cart_index ] = $cart_row;
786 + }
787 + return $cart;
788 +}
789 +
790 +function usces_update_ordercart() {
791 + $ordercart_table_name = $wpdb->prefix . 'usces_ordercart';
792 + foreach ( $_POST['skuPrice'] as $cart_id => $price ) {
793 + $quantity = $_POST['quant'][ $cart_id ];
794 + $query = $wpdb->prepare(
795 + "UPDATE $ordercart_table_name SET price = %f, quantity = %f WHERE cart_id = %d",
796 + $price, $quantity, $cart_id
797 + );
798 + $wpdb->query( $query );
799 + }
800 +
801 + $ordercart_meta_table_name = $wpdb->prefix . 'usces_ordercart_meta';
802 + foreach ( $_POST['itemOption'] as $cartmeta_id => $value ) {
803 + if ( is_array( $value ) ) {
804 + foreach ( $value as $v ) {
805 + $opval[ $v ] = $v;
806 + }
807 + $value = serialize( $opval );
808 + }
809 + $query = $wpdb->prepare(
810 + "UPDATE $ordercart_meta_table_name SET meta_value = %s WHERE cartmeta_id = %d",
811 + $value, $cartmeta_id
812 + );
813 + $wpdb->query( $query );
814 + }
815 + // if ( false === $res ) {
816 + // $res = "-1#usces#";
817 + // } else {
818 + // $res = $skuPrice . "#usces#" . $cartItemName;
819 + // }
820 + // //return $res;
821 +}
822 +
823 +function usces_update_ordercartdata( $order_id ) {
824 + global $wpdb, $usces;
825 +
826 + if ( ! isset( $_POST['skuPrice'] ) ) {
827 + return;
828 + }
829 +
830 + $ordercart_table_name = $wpdb->prefix . 'usces_ordercart';
831 + $ordercart_meta_table_name = $wpdb->prefix . 'usces_ordercart_meta';
832 + foreach ( (array) $_POST['skuPrice'] as $cart_id => $price ) {
833 + $quantity = $_POST['quant'][ $cart_id ];
834 + $query = $wpdb->prepare(
835 + "UPDATE $ordercart_table_name SET price = %f, quantity = %f WHERE cart_id = %d",
836 + $price, $quantity, $cart_id
837 + );
838 + $wpdb->query( $query );
839 +
840 + // itemOptionチェックボックスとラジオのチェック.
841 + $cart = usces_get_ordercartdata_row( $cart_id );
842 + $item_opts = usces_get_opts( $cart['post_id'], 'name', false );
843 + foreach ( $item_opts as $key => $iopts ) {
844 + if ( 3 === (int) $iopts['means'] || 4 === (int) $iopts['means'] ) {
845 + $cart_meta = usces_get_ordercart_meta( 'option', $cart_id, $iopts['name'] );
846 + $cart_meta_id = isset( $cart_meta[0]['cartmeta_id'] ) ? $cart_meta[0]['cartmeta_id'] : 'notfound';
847 +
848 + // POSTが無ければmeta_valueをNULLに変更.
849 + if ( ! isset( $_POST['itemOption'][ $cart_meta_id ] ) ) {
850 + $query = $wpdb->prepare(
851 + "UPDATE $ordercart_meta_table_name SET meta_value = %s WHERE cartmeta_id = %d",
852 + NULL, $cart_meta_id
853 + );
854 + $wpdb->query( $query );
855 + }
856 + }
857 + }
858 + }
859 +
860 + if ( ! isset( $_POST['itemOption'] ) ) {
861 + return;
862 + }
863 +
864 + $ordercart_meta_table_name = $wpdb->prefix . 'usces_ordercart_meta';
865 + foreach ( (array) $_POST['itemOption'] as $cartmeta_id => $value ) {
866 + $post_id = usces_get_post_id_by_cartmeta_id( $cartmeta_id );
867 + $option_fields = usces_get_opts( $post_id, 'name' );
868 + $ordercart_metas = usces_get_ordercart_meta_by_id( $cartmeta_id );
869 + $means = $option_fields[ $ordercart_metas['meta_key'] ]['means'];
870 + if ( is_array( $value ) ) {
871 + $opval = array();
872 + if ( 4 === (int) $means ) {
873 + foreach ( $value as $v ) {
874 + $opval[] = urldecode( $v );
875 + }
876 + } else {
877 + foreach ( $value as $v ) {
878 + $opval[ $v ] = urldecode( $v );
879 + }
880 + }
881 + $value = serialize( $opval );
882 + } else {
883 + if ( 3 === (int) $means ) {
884 + $value = urldecode( $value );
885 + }
886 + }
887 + $query = $wpdb->prepare(
888 + "UPDATE $ordercart_meta_table_name SET meta_value = %s WHERE cartmeta_id = %d",
889 + $value, $cartmeta_id
890 + );
891 + $wpdb->query( $query );
892 + }
893 +}
894 +
895 +function usces_delete_ordercartdata( $cart_id, $order_id = NULL ) {
896 + global $wpdb, $usces;
897 +
898 + $ordercart_table_name = $wpdb->prefix . 'usces_ordercart';
899 + $ordercart_meta_table_name = $wpdb->prefix . 'usces_ordercart_meta';
900 +
901 + if ( NULL != $cart_id ) {
902 +
903 + $query = $wpdb->prepare( "DELETE FROM $ordercart_table_name WHERE cart_id = %d", $cart_id );
904 + $wpdb->query( $query );
905 +
906 + $mquery = $wpdb->prepare( "DELETE FROM $ordercart_meta_table_name WHERE cart_id = %d", $cart_id );
907 + $wpdb->query( $mquery );
908 +
909 + } elseif ( NULL != $order_id ) {
910 +
911 + $query = $wpdb->prepare( "SELECT cart_id FROM $ordercart_table_name WHERE order_id = %d", $order_id );
912 + $cat_ids = $wpdb->get_col( $query );
913 +
914 + $query = $wpdb->prepare( "DELETE FROM $ordercart_table_name WHERE order_id = %d", $order_id );
915 + $wpdb->query( $query );
916 +
917 + foreach ( $cat_ids as $id ) {
918 + $mquery = $wpdb->prepare( "DELETE FROM $ordercart_meta_table_name WHERE cart_id = %d", $id );
919 + $wpdb->query( $mquery );
920 + }
921 + }
922 +}
923 +
924 +function usces_get_ordercartdata_row( $cart_id ) {
925 + global $usces, $wpdb;
926 +
927 + $cart_table = $wpdb->prefix . 'usces_ordercart';
928 +
929 + $query = $wpdb->prepare( "SELECT * FROM $cart_table WHERE cart_id = %d", $cart_id );
930 + $cart = $wpdb->get_row( $query, ARRAY_A );
931 + return $cart;
932 +}
933 +
934 +function usces_get_ordercartdata( $order_id ) {
935 + global $usces, $wpdb;
936 +
937 + $cart_table = $wpdb->prefix . 'usces_ordercart';
938 + $cart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
939 +
940 + $query = $wpdb->prepare( "SELECT * FROM $cart_table WHERE order_id = %d ORDER BY cart_id", $order_id );
941 + $cart = $wpdb->get_results( $query, ARRAY_A );
942 +
943 + foreach ( $cart as $key => $value ) {
944 + $cart[ $key ]['sku'] = $value['sku_code'];
945 + $query = $wpdb->prepare( "SELECT * FROM $cart_meta_table WHERE cart_id = %d ORDER BY cartmeta_id", $value['cart_id'] );
946 + $results = $wpdb->get_results( $query, ARRAY_A );
947 + foreach ( (array) $results as $value ) {
948 + switch ( $value['meta_type'] ) {
949 + case 'option':
950 + $cart[ $key ]['options'][ $value['meta_key'] ] = $value['meta_value'];
951 + break;
952 + case 'advance':
953 + $cart[ $key ]['advance'][ $value['meta_key'] ] = $value['meta_value'];
954 + break;
955 + }
956 + }
957 + if ( ! isset( $cart[ $key ]['options'] ) ) {
958 + $cart[ $key ]['options'] = array();
959 + }
960 + if ( ! isset( $cart[ $key ]['advance'] ) ) {
961 + $cart[ $key ]['advance'] = array();
962 + }
963 + }
964 +
965 + return $cart;
966 +}
967 +
968 +function usces_update_ordercheck() {
969 + global $wpdb;
970 +
971 + $tableName = $wpdb->prefix . 'usces_order';
972 + $order_id = $_POST['order_id'];
973 + $checked = $_POST['checked'];
974 + $logger = Logger::start( $order_id, 'orderedit', 'update' );
975 +
976 + $query = $wpdb->prepare( "SELECT `order_check` FROM $tableName WHERE ID = %d", $order_id );
977 + $res = $wpdb->get_var( $query );
978 +
979 + $checkfield = ! empty( $res ) ? wel_safe_unserialize( $res ) : array();
980 + if ( ! is_array( $checkfield ) ) {
981 + $checkfield = array();
982 + }
983 + if ( ! isset( $checkfield[ $checked ] ) ) {
984 + $checkfield[ $checked ] = $checked;
985 + }
986 + $query = $wpdb->prepare( "UPDATE $tableName SET `order_check` = %s WHERE ID = %d", serialize( $checkfield ), $order_id );
987 + $res = $wpdb->query( $query );
988 +
989 + if ( $res ) {
990 + $logger->flush();
991 + return $checked;
992 + } else {
993 + return 'error';
994 + }
995 +}
996 +
997 +function usces_update_orderdata() {
998 + global $wpdb, $usces;
999 +
1000 + $_POST = $usces->stripslashes_deep_post( $_POST );
1001 +
1002 + $order_table_name = $wpdb->prefix . 'usces_order';
1003 + $order_table_meta_name = $wpdb->prefix . 'usces_order_meta';
1004 + $member_table_name = usces_get_tablename( 'usces_member' );
1005 +
1006 + $ID = $_REQUEST['order_id'];
1007 + $old_cart = usces_get_ordercartdata( $ID );
1008 +
1009 + $query = $wpdb->prepare( "SELECT * FROM $order_table_name WHERE ID = %d", $ID );
1010 + $old_orderdata = $wpdb->get_row( $query );
1011 + $old_status = $old_orderdata->order_status;
1012 +
1013 + if ( isset( $_POST['delButtonAdmin'] ) ) {
1014 + foreach ( $_POST['delButtonAdmin'] as $del_cart_id => $delvalue ) {
1015 + do_action( 'usces_admin_delete_orderrow', $del_cart_id, $ID, $old_cart );
1016 + usces_delete_ordercartdata( $del_cart_id, NULL );
1017 + }
1018 + } else {
1019 + usces_update_ordercartdata( $ID );
1020 + }
1021 +
1022 + $new_cart = usces_get_ordercartdata( $ID );
1023 + $gmtdate = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) );
1024 +
1025 + $item_total_price = $usces->get_total_price( $new_cart );
1026 + $taio = isset( $_POST['offer']['taio'] ) ? $_POST['offer']['taio'] : '';
1027 + $receipt = isset( $_POST['offer']['receipt'] ) ? $_POST['offer']['receipt'] : '';
1028 + $admin = isset( $_POST['offer']['admin'] ) ? $_POST['offer']['admin'] : '';
1029 + $status = $usces->make_status( $taio, $receipt, $admin );
1030 + if ( 'completion' === $taio || 'continuation' === $taio ) {
1031 + if ( 'update' === $_POST['up_modified'] ) {
1032 + $order_modified = substr( $gmtdate, 0, 10 );
1033 + } else {
1034 + $order_modified = $_POST['modified'];
1035 + }
1036 + } else {
1037 + $order_modified = '';
1038 + }
1039 + $order_modified = apply_filters( 'usces_filter_update_orderdata_modified', $order_modified, $taio, $gmtdate, $old_orderdata );
1040 + $ordercheck = isset( $_POST['check'] ) ? serialize( $_POST['check'] ) : '';
1041 + $member_id = isset( $_POST['member_id'] ) ? $_POST['member_id'] : 0;
1042 +
1043 + if ( 'cancel' === $taio ) {
1044 + $query = $wpdb->prepare(
1045 + "UPDATE $order_table_name SET `order_modified` = %s, `order_status` = %s WHERE ID = %d",
1046 + $order_modified, $status, $ID
1047 + );
1048 + $res[0] = $wpdb->query( $query );
1049 +
1050 + $query = $wpdb->prepare( "SELECT * FROM $order_table_name WHERE ID = %d", $ID );
1051 + $new_orderdata = $wpdb->get_row( $query );
1052 +
1053 + if ( 'activate' == $usces->options['membersystem_state'] && 'activate' === $usces->options['membersystem_point'] && ! empty( $member_id ) && ! $usces->is_status( 'cancel', $old_status ) ) {
1054 + $point = 0;
1055 + if ( 0 < $old_orderdata->order_getpoint ) {
1056 + if ( usces_is_complete_settlement( $old_orderdata->order_payment_name, $old_orderdata->order_status ) || $usces->is_status( 'receipted', $old_orderdata->order_status ) ) {
1057 + $point += $old_orderdata->order_getpoint;
1058 + }
1059 + }
1060 + if ( 0 < $old_orderdata->order_usedpoint ) {
1061 + $point -= $old_orderdata->order_usedpoint;
1062 + }
1063 + if ( 0 !== $point ) {
1064 + usces_restore_point( $member_id, $point );
1065 + }
1066 + }
1067 +
1068 + do_action( 'usces_action_update_orderdata', $new_orderdata, $old_status, $old_orderdata, $new_cart, $old_cart );
1069 +
1070 + return 1;
1071 + }
1072 +
1073 + $old_deli = wel_safe_unserialize( $old_orderdata->order_delivery );
1074 + foreach ( (array) $_POST['delivery'] as $dk => $dv ) {
1075 + $old_deli[ $dk ] = $dv;
1076 + }
1077 + $delivery = serialize( $old_deli );
1078 +
1079 + $delivery_date = ( isset( $_POST['offer']['delivery_date'] ) ) ? $_POST['offer']['delivery_date'] : '';
1080 + if ( ! usces_is_date( $delivery_date ) ) {
1081 + $delivery_date = apply_filters( 'usces_filter_label_delivery_date_no_preference', __( 'Non-request', 'usces_dual' ) );
1082 + }
1083 +
1084 + $query = $wpdb->prepare(
1085 + "UPDATE $order_table_name SET
1086 + `mem_id`=%d, `order_email`=%s, `order_name1`=%s, `order_name2`=%s, `order_name3`=%s, `order_name4`=%s,
1087 + `order_zip`=%s, `order_pref`=%s, `order_address1`=%s, `order_address2`=%s, `order_address3`=%s,
1088 + `order_tel`=%s, `order_fax`=%s, `order_delivery`=%s, `order_note`=%s,
1089 + `order_delivery_method`=%d, `order_delivery_date`=%s, `order_delivery_time`=%s, `order_payment_name`=%s, `order_item_total_price`=%f, `order_getpoint`=%d, `order_usedpoint`=%d,
1090 + `order_discount`=%f, `order_shipping_charge`=%f, `order_cod_fee`=%f, `order_tax`=%f, `order_modified`=%s,
1091 + `order_status`=%s, `order_delidue_date`=%s, `order_check`=%s
1092 + WHERE ID = %d",
1093 + $member_id,
1094 + $_POST['customer']['mailaddress'],
1095 + $_POST['customer']['name1'],
1096 + $_POST['customer']['name2'],
1097 + ( isset( $_POST['customer']['name3'] ) ? $_POST['customer']['name3'] : '' ),
1098 + ( isset( $_POST['customer']['name4'] ) ? $_POST['customer']['name4'] : '' ),
1099 + $_POST['customer']['zipcode'],
1100 + $_POST['customer']['pref'],
1101 + $_POST['customer']['address1'],
1102 + $_POST['customer']['address2'],
1103 + $_POST['customer']['address3'],
1104 + $_POST['customer']['tel'],
1105 + $_POST['customer']['fax'],
1106 + $delivery,
1107 + $_POST['offer']['note'],
1108 + $_POST['offer']['delivery_method'],
1109 + $delivery_date,
1110 + $_POST['offer']['delivery_time'],
1111 + $_POST['offer']['payment_name'],
1112 + $item_total_price,
1113 + $_POST['offer']['getpoint'],
1114 + $_POST['offer']['usedpoint'],
1115 + $_POST['offer']['discount'],
1116 + $_POST['offer']['shipping_charge'],
1117 + $_POST['offer']['cod_fee'],
1118 + $_POST['offer']['tax'],
1119 + $order_modified,
1120 + $status,
1121 + $_POST['offer']['delidue_date'],
1122 + $ordercheck,
1123 + $ID
1124 + );
1125 +
1126 + $res[0] = $wpdb->query( $query );
1127 + if ( false === $res[0] ) {
1128 + return false;
1129 + }
1130 +
1131 + $usces->set_order_meta_value( 'customer_country', $_POST['customer']['country'], $ID );
1132 +
1133 + if ( usces_is_tax_display() && usces_is_reduced_taxrate( $ID ) ) {
1134 + $usces->del_order_meta( 'subtotal_standard', $ID );
1135 + $usces->del_order_meta( 'subtotal_reduced', $ID );
1136 + $usces->del_order_meta( 'discount_standard', $ID );
1137 + $usces->del_order_meta( 'discount_reduced', $ID );
1138 + $usces->del_order_meta( 'tax_standard', $ID );
1139 + $usces->del_order_meta( 'tax_reduced', $ID );
1140 + if ( isset( $_POST['order_subtotal_standard'] ) && isset( $_POST['order_subtotal_reduced'] ) && isset( $_POST['order_discount_standard'] ) && isset( $_POST['order_discount_reduced'] ) && isset( $_POST['order_tax_standard'] ) && isset( $_POST['order_tax_reduced'] ) ) {
1141 + $usces->set_order_meta_value( 'subtotal_standard', $_POST['order_subtotal_standard'], $ID );
1142 + $usces->set_order_meta_value( 'subtotal_reduced', $_POST['order_subtotal_reduced'], $ID );
1143 + $usces->set_order_meta_value( 'discount_standard', $_POST['order_discount_standard'], $ID );
1144 + $usces->set_order_meta_value( 'discount_reduced', $_POST['order_discount_reduced'], $ID );
1145 + if ( 'include' === $usces->options['tax_mode'] ) {
1146 + $usces->set_order_meta_value( 'tax_standard', 0, $ID );
1147 + $usces->set_order_meta_value( 'tax_reduced', 0, $ID );
1148 + } else {
1149 + $usces->set_order_meta_value( 'tax_standard', $_POST['order_tax_standard'], $ID );
1150 + $usces->set_order_meta_value( 'tax_reduced', $_POST['order_tax_reduced'], $ID );
1151 + }
1152 + } else {
1153 + $usces_tax = Welcart_Tax::get_instance();
1154 + $materials = array(
1155 + 'total_items_price' => $item_total_price,
1156 + 'discount' => $_POST['offer']['discount'],
1157 + 'shipping_charge' => $_POST['offer']['shipping_charge'],
1158 + 'cod_fee' => $_POST['offer']['cod_fee'],
1159 + 'use_point' => $_POST['offer']['usedpoint'],
1160 + 'carts' => $new_cart,
1161 + 'condition' => $old_orderdata->order_condition,
1162 + );
1163 + $usces_tax->get_order_tax( $materials );
1164 + $usces->set_order_meta_value( 'subtotal_standard', $usces_tax->subtotal_standard, $ID );
1165 + $usces->set_order_meta_value( 'subtotal_reduced', $usces_tax->subtotal_reduced, $ID );
1166 + $usces->set_order_meta_value( 'discount_standard', $usces_tax->discount_standard, $ID );
1167 + $usces->set_order_meta_value( 'discount_reduced', $usces_tax->discount_reduced, $ID );
1168 + if ( 'include' === $usces->options['tax_mode'] ) {
1169 + $usces->set_order_meta_value( 'tax_standard', 0, $ID );
1170 + $usces->set_order_meta_value( 'tax_reduced', 0, $ID );
1171 + } else {
1172 + $usces->set_order_meta_value( 'tax_standard', $usces_tax->tax_standard, $ID );
1173 + $usces->set_order_meta_value( 'tax_reduced', $usces_tax->tax_reduced, $ID );
1174 + }
1175 + }
1176 + }
1177 +
1178 + $csod_meta = usces_has_custom_field_meta( 'order' );
1179 + if ( is_array( $csod_meta ) ) {
1180 + foreach ( $csod_meta as $key => $entry ) {
1181 + if ( 4 === (int) $entry['means'] ) {
1182 + $usces->del_order_meta( 'csod_' . $key, $ID );
1183 + }
1184 + }
1185 + }
1186 + $cscs_meta = usces_has_custom_field_meta( 'customer' );
1187 + if ( is_array( $cscs_meta ) ) {
1188 + foreach ( $cscs_meta as $key => $entry ) {
1189 + if ( 4 === (int) $entry['means'] ) {
1190 + $usces->del_order_meta( 'cscs_' . $key, $ID );
1191 + }
1192 + }
1193 + }
1194 + $csde_meta = usces_has_custom_field_meta( 'delivery' );
1195 + if ( is_array( $csde_meta ) ) {
1196 + foreach ( $csde_meta as $key => $entry ) {
1197 + if ( 4 === (int) $entry['means'] ) {
1198 + $usces->del_order_meta( 'csde_' . $key, $ID );
1199 + }
1200 + }
1201 + }
1202 + $i = 1;
1203 + if ( ! empty( $_POST['custom_order'] ) ) {
1204 + $csod_meta = usces_has_custom_field_meta( 'order' );
1205 + foreach ( $_POST['custom_order'] as $key => $value ) {
1206 + if ( ! is_array( $csod_meta ) || ! isset( $csod_meta[ $key ] ) ) {
1207 + continue;
1208 + }
1209 + $csod_key = 'csod_' . $key;
1210 + if ( is_array( $value ) ) {
1211 + $value = serialize( $value );
1212 + }
1213 + $res[ $i ] = $usces->set_order_meta_value( $csod_key, $value, $ID );
1214 + if ( false === $res[ $i ] ) {
1215 + return false;
1216 + }
1217 + $i++;
1218 + }
1219 + }
1220 + if ( ! empty ( $_POST['custom_customer'] ) ) {
1221 + foreach ( $_POST['custom_customer'] as $key => $value ) {
1222 + $cscs_key = 'cscs_' . $key;
1223 + if ( is_array( $value ) ) {
1224 + $value = serialize( $value );
1225 + }
1226 + $res[ $i ] = $usces->set_order_meta_value( $cscs_key, $value, $ID );
1227 + if ( false === $res[ $i ] ) {
1228 + return false;
1229 + }
1230 + $i++;
1231 + }
1232 + }
1233 + if ( ! empty( $_POST['custom_delivery'] ) ) {
1234 + foreach ( $_POST['custom_delivery'] as $key => $value ) {
1235 + $csde_key = 'csde_' . $key;
1236 + if ( is_array( $value ) ) {
1237 + $value = serialize( $value );
1238 + }
1239 + $res[ $i ] = $usces->set_order_meta_value( $csde_key, $value, $ID );
1240 + if ( false === $res[ $i ] ) {
1241 + return false;
1242 + }
1243 + $i++;
1244 + }
1245 + }
1246 +
1247 + if ( ! preg_match( '/pending|noreceipt/', $old_status ) && preg_match( '/pending|noreceipt/', $status ) ) {
1248 + $rquery = $wpdb->prepare( "DELETE FROM $order_table_meta_name WHERE order_id = %d AND meta_key = %s", $ID, 'receipted_date' );
1249 + $wpdb->query( $rquery );
1250 + } elseif ( ! preg_match( '/pending|noreceipt/', $old_status ) && ! preg_match( '/pending|noreceipt/', $status ) ) {
1251 + $query = $wpdb->prepare( "SELECT order_id FROM $order_table_meta_name WHERE order_id = %d AND meta_key = %s", $ID, 'receipted_date' );
1252 + $varres = $wpdb->get_var( $query );
1253 + if ( empty( $varres ) ) {
1254 + $usces->set_order_meta_value( 'receipted_date', $gmtdate, $ID );
1255 + }
1256 + } elseif ( preg_match( '/pending|noreceipt/', $old_status ) && ! preg_match( '/pending|noreceipt/', $status ) ) {
1257 + $usces->set_order_meta_value( 'receipted_date', $gmtdate, $ID );
1258 + }
1259 +
1260 + if ( 'activate' === $usces->options['membersystem_state'] && 'activate' === $usces->options['membersystem_point'] && ! empty( $member_id ) ) {
1261 + $point = 0;
1262 + $getpoint = ( ! empty( $_POST['offer']['getpoint'] ) ) ? (int) $_POST['offer']['getpoint'] : 0;
1263 + $usedpoint = ( ! empty( $_POST['offer']['usedpoint'] ) ) ? (int) $_POST['offer']['usedpoint'] : 0;
1264 + if ( $usces->is_status( 'cancel', $old_status ) && ! $usces->is_status( 'cancel', $status ) ) { // キャンセル→新規受付・取り寄せ中・発送済み.
1265 + if ( 0 < $getpoint ) {
1266 + if ( usces_is_complete_settlement( $_POST['offer']['payment_name'], $status ) || $usces->is_status( 'receipted', $status ) ) {
1267 + $point -= $getpoint;
1268 + }
1269 + }
1270 + if ( 0 < $usedpoint ) {
1271 + $point += $usedpoint;
1272 + }
1273 + } else {
1274 + if ( ! usces_is_complete_settlement( $_POST['offer']['payment_name'] ) ) {
1275 + if ( ! preg_match( '/pending|noreceipt/', $old_status ) && preg_match( '/pending|noreceipt/', $status ) ) { // 入金→未入金.
1276 + $point += $getpoint; // ポイント取消.
1277 + } elseif ( preg_match( '/pending|noreceipt/', $old_status ) && !preg_match( '/pending|noreceipt/', $status ) ) { // 未入金→入金.
1278 + $point -= $getpoint; // ポイント追加.
1279 + } elseif ( preg_match( '/pending|noreceipt/', $old_status ) && preg_match( '/pending|noreceipt/', $status ) ) { // 未入金→未入金.
1280 + $point = 0; // ポイント追加.
1281 + } else {
1282 + if ( $old_orderdata->order_getpoint != $getpoint ) {
1283 + $point += $old_orderdata->order_getpoint - $getpoint;
1284 + }
1285 + }
1286 + } else {
1287 + if ( $old_orderdata->order_getpoint != $getpoint ) {
1288 + $point += $old_orderdata->order_getpoint - $getpoint;
1289 + }
1290 + }
1291 + if ( $old_orderdata->order_usedpoint != $usedpoint ) {
1292 + $point -= $old_orderdata->order_usedpoint - $usedpoint;
1293 + }
1294 + }
1295 + if ( 0 != $point ) {
1296 + usces_restore_point( $member_id, $point );
1297 + }
1298 + }
1299 +
1300 + $result = ( 0 < array_sum( array_filter( $res, 'is_numeric' ) ) ) ? 1 : 0;
1301 +
1302 + $query = $wpdb->prepare( "SELECT * FROM $order_table_name WHERE ID = %d", $ID );
1303 + $new_orderdata = $wpdb->get_row( $query );
1304 + do_action( 'usces_action_update_orderdata', $new_orderdata, $old_status, $old_orderdata, $new_cart, $old_cart );
1305 + $usces->cart->crear_cart();
1306 +
1307 + return $result;
1308 +}
1309 +
1310 +function usces_all_change_zaiko( &$obj ) {
1311 + global $wpdb, $usces;
1312 +
1313 + $ids = filter_input( INPUT_POST, 'listcheck', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
1314 + $change = filter_input( INPUT_POST, 'change', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
1315 + $zaiko = ( null !== $change && false !== $change ) ? (int) $change['word']['zaiko'] : 0;
1316 + $status = true;
1317 + foreach ( (array) $ids as $post_id ) {
1318 + $skus = wel_get_skus( $post_id, 'sort', false );
1319 + foreach ( (array) $skus as $sku ) {
1320 + $res = usces_update_sku( $post_id, $sku['code'], 'stock', $zaiko );
1321 + if ( ! $res ) {
1322 + $status = false;
1323 + }
1324 + }
1325 + }
1326 +
1327 + if ( true === $status ) {
1328 + $obj->set_action_status( 'success', __( 'I completed collective operation.', 'usces' ) );
1329 + } elseif ( false === $status ) {
1330 + $obj->set_action_status( 'error', __( 'ERROR: I was not able to complete collective operation', 'usces' ) );
1331 + } else {
1332 + $obj->set_action_status( 'none', '' );
1333 + }
1334 +}
1335 +
1336 +function usces_all_change_itemdisplay( &$obj ) {
1337 + global $wpdb;
1338 +
1339 + $ids = $_POST['listcheck'];
1340 + $post_status = $_POST['change']['word']['display_status'];
1341 + $status = true;
1342 + foreach ( (array) $ids as $post_id ) {
1343 + $post_data = array( 'ID' => $post_id, 'post_status' => $post_status );
1344 + $res = wp_update_post( $post_data );
1345 + if ( 0 === $res ) {
1346 + $status = false;
1347 + }
1348 + }
1349 + if ( true === $status ) {
1350 + $obj->set_action_status( 'success', __( 'I completed collective operation.', 'usces' ) );
1351 + } elseif ( false === $status ) {
1352 + $obj->set_action_status( 'error', __( 'ERROR: I was not able to complete collective operation', 'usces' ) );
1353 + } else {
1354 + $obj->set_action_status( 'none', '' );
1355 + }
1356 +}
1357 +
1358 +function usces_all_change_order_reciept( &$obj ) {
1359 + global $wpdb, $usces;
1360 +
1361 + $tableName = $wpdb->prefix . 'usces_order';
1362 + $ids = $_POST['listcheck'];
1363 + if ( isset( $_REQUEST['change']['word'] ) && ! is_array( $_REQUEST['change']['word'] ) ) {
1364 + $change_word = $_REQUEST['change']['word'];
1365 + } elseif ( isset( $_REQUEST['change']['word']['order_reciept'] ) ) {
1366 + $change_word = $_REQUEST['change']['word']['order_reciept'];
1367 + } else {
1368 + $change_word = '';
1369 + }
1370 + $status = true;
1371 + foreach ( (array) $ids as $id ) {
1372 + $logger = Logger::start( $id, 'orderlist', 'update' );
1373 + $query = $wpdb->prepare( "SELECT order_status, mem_id, order_getpoint, order_payment_name FROM $tableName WHERE ID = %d", $id );
1374 + $order_res = $wpdb->get_row( $query, ARRAY_A );
1375 + $statusstr = $order_res['order_status'];
1376 + $restore_point = false;
1377 + $getpoint = $order_res['order_getpoint'];
1378 + if ( false !== strpos( $statusstr, 'cancel' ) ) {
1379 + continue;
1380 + }
1381 + if ( false === strpos( $statusstr, 'noreceipt' ) && false === strpos( $statusstr, 'receipted' ) ) {
1382 + continue;
1383 + }
1384 + $old_status = $statusstr;
1385 + if ( $change_word == 'receipted' ) {
1386 + if ( false !== strpos( $statusstr, 'noreceipt' ) ) { // 未入金→入金.
1387 + $statusstr = str_replace( 'noreceipt', 'receipted', $statusstr );
1388 + if ( ! usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
1389 + $restore_point = true;
1390 + $getpoint = $getpoint * -1; // add point.
1391 + }
1392 + }
1393 + } elseif ( $change_word == 'noreceipt' ) {
1394 + if ( false !== strpos( $statusstr, 'receipted' ) ) { // 入金済み→未入金.
1395 + $statusstr = str_replace( 'receipted', 'noreceipt', $statusstr );
1396 + if ( ! usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
1397 + $restore_point = true;
1398 + }
1399 + }
1400 + }
1401 + $query = $wpdb->prepare( "UPDATE $tableName SET order_status = %s WHERE ID = %d", $statusstr, $id );
1402 + $res = $wpdb->query( $query );
1403 + if ( false === $res ) {
1404 + $status = false;
1405 + }
1406 + if ( 'activate' === $usces->options['membersystem_state'] && 'activate' === $usces->options['membersystem_point'] ) {
1407 + if ( ! empty( $order_res['mem_id'] ) && 0 < $order_res['order_getpoint'] ) {
1408 + if ( $res && $restore_point ) {
1409 + usces_restore_point( $order_res['mem_id'], $getpoint );
1410 + }
1411 + }
1412 + }
1413 + if ( $status ) {
1414 + do_action( 'usces_action_collective_order_reciept_each', $id, $statusstr, $old_status );
1415 + }
1416 + if ( ! empty( $res ) ) {
1417 + $logger->flush();
1418 + }
1419 + }
1420 + if ( true === $status ) {
1421 + $obj->set_action_status( 'success', __( 'I completed collective operation.', 'usces' ) );
1422 + } elseif ( false === $status ) {
1423 + $obj->set_action_status( 'error', __( 'ERROR: I was not able to complete collective operation', 'usces' ) );
1424 + } else {
1425 + $obj->set_action_status( 'none', '' );
1426 + }
1427 + do_action( 'usces_action_collective_order_reciept', array( &$obj ) );
1428 +}
1429 +
1430 +function usces_all_change_order_status( &$obj ) {
1431 + global $wpdb, $usces;
1432 +
1433 + $tableName = $wpdb->prefix . 'usces_order';
1434 + $ids = $_POST['listcheck'];
1435 + foreach ( (array) $ids as $id ) {
1436 + $status = true;
1437 + $query = $wpdb->prepare( "SELECT order_status, mem_id, order_getpoint, order_usedpoint, order_payment_name FROM $tableName WHERE ID = %d", $id );
1438 + $order_res = $wpdb->get_row( $query, ARRAY_A );
1439 + $statusstr = $order_res['order_status'];
1440 + $restore_point = false;
1441 + $getpoint = $order_res['order_getpoint'];
1442 + $usedpoint = $order_res['order_usedpoint'];
1443 + $old_status = $statusstr;
1444 + if ( isset( $_REQUEST['change']['word'] ) && ! is_array( $_REQUEST['change']['word'] ) ) {
1445 + $change_word = $_REQUEST['change']['word'];
1446 + } elseif ( isset( $_REQUEST['change']['word']['order_reciept'] ) ) {
1447 + $change_word = $_REQUEST['change']['word']['order_reciept'];
1448 + } elseif ( isset( $_REQUEST['change']['word']['order_status'] ) ) {
1449 + $change_word = $_REQUEST['change']['word']['order_status'];
1450 + } else {
1451 + $change_word = '';
1452 + }
1453 + $query = '';
1454 + switch ( $change_word ) {
1455 + case 'estimate':
1456 + if ( false !== strpos( $statusstr, 'adminorder' ) ) {
1457 + $statusstr = str_replace( 'adminorder', 'estimate', $statusstr );
1458 + } elseif ( false === strpos( $statusstr, 'estimate' ) ) {
1459 + if ( ',' !== substr( $statusstr, -1 ) ) {
1460 + $statusstr .= ',';
1461 + }
1462 + $statusstr .= 'estimate,';
1463 + }
1464 + if ( false === strpos( $statusstr, 'cancel' ) ) {
1465 + if ( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
1466 + $restore_point = true;
1467 + $usedpoint = $usedpoint * -1; // add point.
1468 + } elseif ( $usces->is_status( 'receipted', $order_res['order_status'] ) ) {
1469 + $restore_point = true;
1470 + $usedpoint = $usedpoint * -1; // add point.
1471 + }
1472 + }
1473 + $query = $wpdb->prepare( "UPDATE $tableName SET order_status = %s WHERE ID = %d", $statusstr, $id );
1474 + break;
1475 + case 'adminorder':
1476 + if ( false !== strpos( $statusstr, 'estimate' ) ) {
1477 + $statusstr = str_replace( 'estimate', 'adminorder', $statusstr );
1478 + if ( false === strpos( $statusstr, 'cancel' ) ) {
1479 + if ( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
1480 + $restore_point = true;
1481 + $getpoint = $getpoint * -1; // add point.
1482 + } elseif ( $usces->is_status( 'receipted', $order_res['order_status'] ) ) {
1483 + $restore_point = true;
1484 + $getpoint = $getpoint * -1; //add point.
1485 + }
1486 + }
1487 + } elseif ( false === strpos( $statusstr, 'adminorder' ) ) {
1488 + if ( ',' !== substr( $statusstr, -1 ) ) {
1489 + $statusstr .= ',';
1490 + }
1491 + $statusstr .= 'adminorder,';
1492 + }
1493 + $query = $wpdb->prepare( "UPDATE $tableName SET order_status = %s WHERE ID = %d", $statusstr, $id );
1494 + break;
1495 + case 'frontorder':
1496 + if ( false !== strpos( $statusstr, 'estimate' ) ) {
1497 + $statusstr = str_replace( 'estimate,', '', $statusstr );
1498 + $statusstr = trim( $statusstr, ',' );
1499 + if ( false === strpos( $statusstr, 'cancel' ) ) {
1500 + if ( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
1501 + $restore_point = true;
1502 + $getpoint = $getpoint * -1; // add point.
1503 + } elseif ( $usces->is_status( 'receipted', $order_res['order_status'] ) ) {
1504 + $restore_point = true;
1505 + $getpoint = $getpoint * -1; // add point.
1506 + }
1507 + }
1508 + } elseif ( false !== strpos( $statusstr, 'adminorder' ) ) {
1509 + $statusstr = str_replace( 'adminorder,', '', $statusstr );
1510 + $statusstr = trim( $statusstr, ',' );
1511 + }
1512 + $query = $wpdb->prepare( "UPDATE $tableName SET order_status = %s WHERE ID = %d", $statusstr, $id );
1513 + break;
1514 + case 'duringorder':
1515 + if ( false !== strpos( $statusstr, 'cancel' ) ) {
1516 + $statusstr = str_replace( 'cancel', '', $statusstr );
1517 + $statusstr = trim( $statusstr, ',' );
1518 + if ( false === strpos( $statusstr, 'estimate' ) ) {
1519 + if ( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
1520 + $restore_point = true;
1521 + $getpoint = $getpoint * -1; // add point.
1522 + } elseif ( $usces->is_status( 'receipted', $order_res['order_status'] ) ) {
1523 + $restore_point = true;
1524 + $getpoint = $getpoint * -1; // add point.
1525 + }
1526 + }
1527 + }
1528 + if ( false !== strpos( $statusstr, 'completion' ) ) {
1529 + $statusstr = str_replace( 'completion', '', $statusstr );
1530 + $statusstr = trim( $statusstr, ',' );
1531 + }
1532 + if ( false !== strpos( $statusstr, 'new' ) ) {
1533 + $statusstr = str_replace( 'new', '', $statusstr );
1534 + $statusstr = trim( $statusstr, ',' );
1535 + }
1536 + if ( false === strpos( $statusstr, 'duringorder' ) ) {
1537 + if ( ',' !== substr( $statusstr, -1 ) ) {
1538 + $statusstr .= ',';
1539 + }
1540 + $statusstr .= 'duringorder,';
1541 + }
1542 + $query = $wpdb->prepare( "UPDATE $tableName SET order_status = %s WHERE ID = %d", $statusstr, $id );
1543 + break;
1544 + case 'cancel':
1545 + if ( false !== strpos( $statusstr, 'completion' ) ) {
1546 + $statusstr = str_replace( 'completion', '', $statusstr );
1547 + $statusstr = trim( $statusstr, ',' );
1548 + }
1549 + if ( false !== strpos( $statusstr, 'new' ) ) {
1550 + $statusstr = str_replace( 'new', '', $statusstr );
1551 + $statusstr = trim( $statusstr, ',' );
1552 + }
1553 + if ( false !== strpos( $statusstr, 'duringorder' ) ) {
1554 + $statusstr = str_replace( 'duringorder', '', $statusstr );
1555 + $statusstr = trim( $statusstr, ',' );
1556 + }
1557 + if ( false === strpos( $statusstr, 'cancel' ) ) {
1558 + if ( ',' !== substr( $statusstr, -1 ) ) {
1559 + $statusstr .= ',';
1560 + }
1561 + $statusstr .= 'cancel,';
1562 + }
1563 + if ( false === strpos( $statusstr, 'estimate' ) ) {
1564 + if ( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
1565 + $restore_point = true;
1566 + $usedpoint = $usedpoint * -1; // add point.
1567 + } elseif ( $usces->is_status( 'receipted', $order_res['order_status'] ) ) {
1568 + $restore_point = true;
1569 + $usedpoint = $usedpoint * -1; // add point.
1570 + }
1571 + }
1572 + $query = $wpdb->prepare( "UPDATE $tableName SET order_status = %s WHERE ID = %d", $statusstr, $id );
1573 + break;
1574 + case 'completion':
1575 + if ( false !== strpos( $statusstr, 'new' ) ) {
1576 + $statusstr = str_replace( 'new', '', $statusstr );
1577 + $statusstr = trim( $statusstr, ',' );
1578 + }
1579 + if ( false !== strpos( $statusstr, 'duringorder' ) ) {
1580 + $statusstr = str_replace( 'duringorder', '', $statusstr );
1581 + $statusstr = trim( $statusstr, ',' );
1582 + }
1583 + if ( false !== strpos( $statusstr, 'cancel' ) ) {
1584 + $statusstr = str_replace( 'cancel', '', $statusstr );
1585 + $statusstr = trim( $statusstr, ',' );
1586 + if ( false === strpos( $statusstr, 'estimate' ) ) {
1587 + if ( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
1588 + $restore_point = true;
1589 + $getpoint = $getpoint * -1; // add point.
1590 + } elseif ( $usces->is_status( 'receipted', $order_res['order_status'] ) ) {
1591 + $restore_point = true;
1592 + $getpoint = $getpoint * -1; // add point.
1593 + }
1594 + }
1595 + }
1596 + if ( false === strpos( $statusstr, 'completion' ) ) {
1597 + if ( ',' !== substr( $statusstr, -1 ) ) {
1598 + $statusstr .= ',';
1599 + }
1600 + $statusstr .= 'completion,';
1601 + }
1602 + $query = $wpdb->prepare( "UPDATE $tableName SET order_status = %s, order_modified = %s WHERE ID = %d", $statusstr, substr( current_time( 'mysql' ), 0, 10 ), $id );
1603 + break;
1604 + case 'new':
1605 + case 'neworder':
1606 + if ( false !== strpos( $statusstr, 'duringorder' ) ) {
1607 + $statusstr = str_replace( 'duringorder,', '', $statusstr );
1608 + $statusstr = trim( $statusstr, ',' );
1609 + }
1610 + if ( false !== strpos( $statusstr, 'completion' ) ) {
1611 + $statusstr = str_replace( 'completion,', '', $statusstr );
1612 + $statusstr = trim( $statusstr, ',' );
1613 + }
1614 + if ( false !== strpos( $statusstr, 'cancel' ) ) {
1615 + $statusstr = str_replace( 'cancel,', '', $statusstr );
1616 + $statusstr = trim( $statusstr, ',' );
1617 + if ( false === strpos( $statusstr, 'estimate' ) ) {
1618 + if ( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
1619 + $restore_point = true;
1620 + $getpoint = $getpoint * -1; // add point.
1621 + } elseif ( $usces->is_status( 'receipted', $order_res['order_status'] ) ) {
1622 + $restore_point = true;
1623 + $getpoint = $getpoint * -1; // add point.
1624 + }
1625 + }
1626 + }
1627 + $query = $wpdb->prepare( "UPDATE $tableName SET order_status = %s WHERE ID = %d", $statusstr, $id );
1628 + break;
1629 + default:
1630 + $query = apply_filters( 'usces_filter_collective_order_status_query', $query, $statusstr, $id );
1631 + }
1632 + if ( ! empty ( $query ) ) {
1633 + $logger = Logger::start( $id, 'orderlist', 'update' );
1634 + $res = $wpdb->query( $query );
1635 + if ( false === $res ) {
1636 + $status = false;
1637 + }
1638 + if ( 'activate' === $usces->options['membersystem_state'] && 'activate' === $usces->options['membersystem_point'] ) {
1639 + if ( ! empty( $order_res['mem_id'] ) && ( 0 < $order_res['order_getpoint'] || 0 < $order_res['order_usedpoint'] ) ) {
1640 + if ( $res && $restore_point ) {
1641 + usces_restore_point( $order_res['mem_id'], $getpoint + $usedpoint );
1642 + }
1643 + }
1644 + }
1645 + if ( $status ) {
1646 + do_action( 'usces_action_collective_order_status_each', $id, $statusstr, $old_status );
1647 + $logger->flush();
1648 + }
1649 + }
1650 + }
1651 + if ( true === $status ) {
1652 + $obj->set_action_status( 'success', __( 'I completed collective operation.', 'usces' ) );
1653 + } elseif ( false === $status ) {
1654 + $obj->set_action_status( 'error', __( 'ERROR: I was not able to complete collective operation', 'usces' ) );
1655 + } else {
1656 + $obj->set_action_status( 'none', '' );
1657 + }
1658 + do_action( 'usces_action_collective_order_status', array( &$obj ) );
1659 +}
1660 +
1661 +function usces_all_delete_order_data( &$obj ) {
1662 + global $wpdb, $usces;
1663 +
1664 + $tableName = $wpdb->prefix . 'usces_order';
1665 + $tableMetaName = $wpdb->prefix . 'usces_order_meta';
1666 + $ids = $_POST['listcheck'];
1667 + $status = true;
1668 + foreach ( (array) $ids as $id ) {
1669 + $del = usces_delete_order_check( $id );
1670 + if ( false === $del ) {
1671 + continue;
1672 + }
1673 + $logger = Logger::start( $id, 'orderlist', 'delete' );
1674 + $point = 0;
1675 + $query = $wpdb->prepare( "SELECT * FROM $tableName WHERE ID = %d", $id );
1676 + $order_res = $wpdb->get_row( $query, ARRAY_A );
1677 + if ( 'activate' === $usces->options['membersystem_state'] && 'activate' === $usces->options['membersystem_point'] && ! empty( $order_res['mem_id'] ) && ! $usces->is_status( 'cancel', $order_res['order_status'] ) ) {
1678 + if ( 0 < $order_res['order_getpoint'] ) {
1679 + if ( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) || $usces->is_status( 'receipted', $order_res['order_status'] ) ) {
1680 + $point += $order_res['order_getpoint'];
1681 + }
1682 + }
1683 + if ( 0 < $order_res['order_usedpoint'] ) {
1684 + $point -= $order_res['order_usedpoint'];
1685 + }
1686 + }
1687 + $query = $wpdb->prepare( "DELETE FROM $tableName WHERE ID = %d", $id );
1688 + $res = $wpdb->query( $query );
1689 + if ( false === $res ) {
1690 + $status = false;
1691 + } else {
1692 +
1693 + if ( 0 != $point ) {
1694 + usces_restore_point( $order_res['mem_id'], $point );
1695 + }
1696 +
1697 + do_action( 'usces_action_collective_order_delete_each', $id, $order_res );
1698 +
1699 + usces_delete_ordercartdata( NULL, $id );
1700 +
1701 + $metaquery = $wpdb->prepare( "DELETE FROM $tableMetaName WHERE order_id = %d", $id );
1702 + $metares = $wpdb->query( $metaquery );
1703 + $logger->flush();
1704 + }
1705 + }
1706 + if ( true === $status ) {
1707 + $obj->set_action_status( 'success', __( 'I completed collective operation.', 'usces' ) );
1708 + } elseif ( false === $status ) {
1709 + $obj->set_action_status( 'error', __( 'ERROR: I was not able to complete collective operation', 'usces' ) );
1710 + } else {
1711 + $obj->set_action_status( 'none', '' );
1712 + }
1713 + do_action( 'usces_action_collective_order_delete', array( &$obj ) );
1714 +}
1715 +
1716 +function usces_all_change_member_rank( &$obj ) {
1717 + global $wpdb, $usces;
1718 +
1719 + $tableName = usces_get_tablename( 'usces_member' );
1720 + $ids = $_POST['listcheck'];
1721 + $status = true;
1722 +
1723 + foreach ( (array) $ids as $id ) {
1724 + $logger = Logger::start( $id, 'memberlist', 'update' );
1725 + $value = isset( $_REQUEST['change']['word'] ) ? $_REQUEST['change']['word'] : '';
1726 + $query = $wpdb->prepare( "UPDATE $tableName SET mem_status = %d WHERE ID = %d", $value, $id );
1727 + $res = $wpdb->query( $query );
1728 + if ( false === $res ) {
1729 + $status = false;
1730 + }
1731 + if ( $status ) {
1732 + do_action( 'usces_action_collective_member_rank_each', $id, $value );
1733 + }
1734 + $logger->flush();
1735 + }
1736 +
1737 + if ( true === $status ) {
1738 + $obj->set_action_status( 'success', __( 'I completed collective operation.', 'usces' ) );
1739 + } elseif ( false === $status ) {
1740 + $obj->set_action_status( 'error', __( 'ERROR: I was not able to complete collective operation', 'usces' ) );
1741 + } else {
1742 + $obj->set_action_status( 'none', '' );
1743 + }
1744 + do_action( 'usces_action_collective_member_rank', array( &$obj ) );
1745 +}
1746 +
1747 +function usces_all_change_member_point( &$obj ) {
1748 + global $wpdb, $usces;
1749 +
1750 + $tableName = usces_get_tablename( 'usces_member' );
1751 + $ids = $_POST['listcheck'];
1752 + $status = true;
1753 +
1754 + foreach ( (array) $ids as $id ) {
1755 + $logger = Logger::start( $id, 'memberlist', 'update' );
1756 + $value = isset( $_REQUEST['change']['word'] ) ? $_REQUEST['change']['word'] : '';
1757 + $query = $wpdb->prepare( "UPDATE $tableName SET mem_point = %d WHERE ID = %d", $value, $id );
1758 + $res = $wpdb->query( $query );
1759 + if ( false === $res ) {
1760 + $status = false;
1761 + }
1762 + if ( $status ) {
1763 + do_action( 'usces_action_collective_member_point_each', $id, $value );
1764 + }
1765 + $logger->flush();
1766 + }
1767 +
1768 + if ( true === $status ) {
1769 + $obj->set_action_status( 'success', __( 'I completed collective operation.', 'usces' ) );
1770 + } elseif ( false === $status ) {
1771 + $obj->set_action_status( 'error', __( 'ERROR: I was not able to complete collective operation', 'usces' ) );
1772 + } else {
1773 + $obj->set_action_status( 'none', '' );
1774 + }
1775 + do_action( 'usces_action_collective_member_point', array( &$obj ) );
1776 +}
1777 +
1778 +function usces_all_delete_member_data( &$obj ) {
1779 + global $wpdb, $usces;
1780 +
1781 + $ids = $_POST['listcheck'];
1782 + $status = true;
1783 +
1784 + foreach ( (array) $ids as $id ) {
1785 + $del = usces_delete_member_check( $id );
1786 + if ( false === $del ) {
1787 + continue;
1788 + }
1789 + $logger = Logger::start( $id, 'memberlist', 'delete');
1790 + $old_data = $usces->get_member_info( $id );
1791 + $res = usces_delete_memberdata( $id );
1792 + if ( false === $res ) {
1793 + $status = false;
1794 + do_action( 'usces_action_collective_member_delete_each', $id, $old_data );
1795 + } else {
1796 + $logger->flush();
1797 + }
1798 + }
1799 +
1800 + if ( true === $status ) {
1801 + $obj->set_action_status( 'success', __( 'I completed collective operation.', 'usces' ) );
1802 + } elseif ( false === $status ) {
1803 + $obj->set_action_status( 'error', __( 'ERROR: I was not able to complete collective operation', 'usces' ) );
1804 + } else {
1805 + $obj->set_action_status( 'none', '' );
1806 + }
1807 + do_action( 'usces_action_collective_member_delete', array( &$obj ) );
1808 +}
1809 +
1810 +function usces_check_acting_return() {
1811 + global $usces;
1812 +
1813 + $entry = $usces->cart->get_entry();
1814 +
1815 + $acting = ( isset( $_GET['acting'] ) ) ? $_GET['acting'] : '';
1816 + $results = array();
1817 + switch ( $acting ) {
1818 + case 'epsilon':
1819 + if ( isset( $_GET['duplicate'] ) && $_GET['duplicate'] == 1 ) {
1820 + $results[0] = 'duplicate';
1821 + } elseif ( isset( $_GET['result'] ) ) {
1822 + $results[0] = (int) $_GET['result'];
1823 + $results['reg_order'] = true;
1824 + } else {
1825 + $str = explode( '?', $_GET['acting_return'] );
1826 + if ( ! isset( $str[1] ) ) {
1827 + $results[0] = 0;
1828 + } else {
1829 + parse_str( $str[1], $para );
1830 + $results[0] = isset( $para['result'] ) ? (int) $para['result'] : 0;
1831 + foreach ( $para as $key => $value ) {
1832 + $results[ $key ] = $value;
1833 + }
1834 + }
1835 + }
1836 + $results['reg_order'] = true;
1837 + break;
1838 +
1839 + case 'paypal':
1840 + usces_log( 'paypal in ', 'acting_transaction.log' );
1841 + $paypal_file = $usces->options['settlement_path'] . 'paypal.php';
1842 + if ( file_exists( $paypal_file ) ) {
1843 + require_once( $paypal_file );
1844 + $results = paypal_check( $usces_paypal_url );
1845 + remove_action( 'shutdown', array( &$usces, 'lastprocessing' ) );
1846 + $results['reg_order'] = true;
1847 + } else {
1848 + $results['reg_order'] = true;
1849 + }
1850 + break;
1851 +
1852 + case 'remise_card':
1853 + $results = $_POST;
1854 + if ( $_REQUEST['acting_return'] && ( isset( $_REQUEST['X-ERRCODE'] ) && ' ' === $_REQUEST['X-ERRCODE'] ) ) {
1855 + usces_log( 'remise card entry data : ' . print_r( $entry, true ), 'acting_transaction.log' );
1856 + $results[0] = 1;
1857 + }else{
1858 + $results[0] = 0;
1859 + }
1860 + if ( isset( $_REQUEST['dlseller_update'] ) ) {
1861 + $results['reg_order'] = false;
1862 + } else {
1863 + $results['reg_order'] = true;
1864 + }
1865 + break;
1866 +
1867 + case 'remise_conv':
1868 + $results = $_GET;
1869 + if ( $_REQUEST['acting_return'] && isset( $_REQUEST['X-JOB_ID'] ) && '0:0000' === $_REQUEST['X-R_CODE'] ) {
1870 + $results[0] = 1;
1871 + } else {
1872 + $results[0] = 0;
1873 + }
1874 + $results['reg_order'] = true;
1875 + break;
1876 +
1877 + case 'jpayment_card':
1878 + $results = $_GET;
1879 + $rst = ( isset( $_GET['rst'] ) ) ? (int) $_GET['rst'] : 0;
1880 + if ( 2 === $rst ) {
1881 + usces_log( 'jpayment card error : ' . print_r( $entry, true ), 'acting_transaction.log' );
1882 + $cod = ( isset( $_GET['cod'] ) ) ? $_GET['cod'] : '';
1883 + $log = array(
1884 + 'acting' => $acting,
1885 + 'key' => $cod,
1886 + 'result' => $rst,
1887 + 'data' => $_GET,
1888 + );
1889 + usces_save_order_acting_error( $log );
1890 + }
1891 + $results[0] = ( 1 === $rst ) ? 1 : 0;
1892 + $results['reg_order'] = true;
1893 + break;
1894 +
1895 + case 'jpayment_conv':
1896 + $results = $_GET;
1897 + $rst = ( isset( $_GET['rst'] ) ) ? (int) $_GET['rst'] : 0;
1898 + if ( 2 === $rst ) {
1899 + usces_log( 'jpayment conv error : ' . print_r( $entry, true ), 'acting_transaction.log' );
1900 + $cod = ( isset( $_GET['cod'] ) ) ? $_GET['cod'] : '';
1901 + $log = array(
1902 + 'acting' => $acting,
1903 + 'key' => $cod,
1904 + 'result' => $rst,
1905 + 'data' => $_GET,
1906 + );
1907 + usces_save_order_acting_error( $log );
1908 + }
1909 + $results[0] = ( 1 === $rst && 'CPL_PRE' === $_GET['ap'] ) ? 1 : 0;
1910 + $results['reg_order'] = true;
1911 + break;
1912 +
1913 + case 'jpayment_bank':
1914 + $results = $_GET;
1915 + $rst = ( isset( $_GET['rst'] ) ) ? (int) $_GET['rst'] : 0;
1916 + if ( 2 === $rst ) {
1917 + usces_log( 'jpayment bank error : ' . print_r( $entry, true ), 'acting_transaction.log' );
1918 + $cod = ( isset( $_GET['cod'] ) ) ? $_GET['cod'] : '';
1919 + $log = array(
1920 + 'acting' => $acting,
1921 + 'key' => $cod,
1922 + 'result' => $rst,
1923 + 'data' => $_GET,
1924 + );
1925 + usces_save_order_acting_error( $log );
1926 + }
1927 + $results[0] = ( 1 === $rst ) ? 1 : 0;
1928 + $results['reg_order'] = true;
1929 + break;
1930 +
1931 + case 'paypal_ec':
1932 + $results = $_GET;
1933 +
1934 + // Build a second API request to PayPal, using the token as the ID to get the details on the payment authorization.
1935 + $req_token = isset( $_REQUEST['token'] ) ? $_REQUEST['token'] : '0';
1936 + $nvpstr = '&TOKEN=' . urlencode( $req_token );
1937 +
1938 + $usces->paypal->setMethod( 'GetExpressCheckoutDetails' );
1939 + $usces->paypal->setData( $nvpstr );
1940 + $res = $usces->paypal->doExpressCheckout();
1941 + $resArray = $usces->paypal->getResponse();
1942 + $ack = strtoupper( $resArray['ACK'] );
1943 + if ( 'SUCCESS' === $ack || 'SUCCESSWITHWARNING' === $ack ) {
1944 + if ( usces_have_continue_charge() ) {
1945 + $results[0] = 1;
1946 + } else {
1947 + $amt = floor( $resArray['AMT'] * 100 );
1948 + $total_full_price = usces_crform( $entry['order']['total_full_price'], false, false, 'return', false );
1949 + $total_full_price = floor( $total_full_price * 100 );
1950 + if ( $amt != $total_full_price ) {
1951 + usces_log( 'PayPal : AMT Error. AMT=' . $resArray['AMT'] . ', total_full_price=' . $entry['order']['total_full_price'], 'acting_transaction.log' );
1952 + $results[0] = 0;
1953 + } else {
1954 + $results[0] = 1;
1955 + }
1956 + }
1957 +
1958 + } else {
1959 + // Display a user friendly Error on the page using any of the following error information returned by PayPal.
1960 + $ErrorCode = urldecode( $resArray['L_ERRORCODE0'] );
1961 + $ErrorShortMsg = urldecode( $resArray['L_SHORTMESSAGE0'] );
1962 + $ErrorLongMsg = urldecode( $resArray['L_LONGMESSAGE0'] );
1963 + $ErrorSeverityCode = urldecode( $resArray['L_SEVERITYCODE0'] );
1964 + usces_log( 'PayPal : GetExpressCheckoutDetails API call failed. Error Code:[' . $ErrorCode . '] Error Severity Code:[' . $ErrorSeverityCode . '] Short Error Message:' . $ErrorShortMsg . ' Detailed Error Message:' . $ErrorLongMsg, 'acting_transaction.log' );
1965 + $results[0] = 0;
1966 + }
1967 + $results['reg_order'] = true;
1968 + break;
1969 +
1970 + case 'telecom_card':
1971 + $results = $_GET;
1972 + if ( $_REQUEST['result'] ) {
1973 + usces_log( $acting . ' entry data : ' . print_r( $entry, true ), 'acting_transaction.log' );
1974 + $results[0] = 1;
1975 + } else {
1976 + usces_log( $acting . ' error : ' . print_r( $_REQUEST, true ), 'acting_transaction.log' );
1977 + $results[0] = 0;
1978 + }
1979 + $results['reg_order'] = true;
1980 + break;
1981 +
1982 + case 'digitalcheck_card':
1983 + $results = $_REQUEST;
1984 + if ( isset( $_REQUEST['SID'] ) ) {
1985 + $results[0] = 1;
1986 + } else {
1987 + $results[0] = 0;
1988 + }
1989 + $results['reg_order'] = true;
1990 + break;
1991 + case 'digitalcheck_conv':
1992 + $results = $_REQUEST;
1993 + $results[0] = 1;
1994 + $results['reg_order'] = false;
1995 + break;
1996 +
1997 + case 'mizuho_card':
1998 + case 'mizuho_conv':
1999 + $results = $_GET;
2000 + if ( isset( $_GET['rsltcd'] ) ) {
2001 + if ( '000' === substr( $_GET['rsltcd'], 0, 3 ) ) {
2002 + $results[0] = 1;
2003 + $results['reg_order'] = true;
2004 + } else {
2005 + $results[0] = 0;
2006 + $results['reg_order'] = false;
2007 + }
2008 + } else {
2009 + $results[0] = 0;
2010 + $results['reg_order'] = false;
2011 + }
2012 + break;
2013 +
2014 + case 'anotherlane_card':
2015 + $results[0] = 1;
2016 + $results['reg_order'] = false;
2017 + break;
2018 +
2019 + case 'veritrans_card':
2020 + case 'veritrans_conv':
2021 + $results[0] = ( isset( $_GET['result'] ) ) ? (int) $_GET['result'] : 0;
2022 + $results['reg_order'] = false;
2023 + break;
2024 +
2025 + case 'paypal_wpp':
2026 + $results[0] = 1;
2027 + $results['reg_order'] = false;
2028 + break;
2029 +
2030 + default:
2031 + do_action( 'usces_action_check_acting_return_default' );
2032 + $results = $_REQUEST;
2033 + if ( isset( $_REQUEST['result'] ) && true == $_REQUEST['result'] ) {
2034 + usces_log( $acting . ' entry data : ' . print_r( $entry, true ), 'acting_transaction.log' );
2035 + $results[0] = 1;
2036 + } else {
2037 + // usces_log( $acting . ' error : ' . print_r( $_REQUEST, true ), 'acting_transaction.log' ); Not necessarily an error.
2038 + $results[0] = 0;
2039 + }
2040 + $results['reg_order'] = true;
2041 + $results = apply_filters( 'usces_filter_check_acting_return_results', $results );
2042 + break;
2043 + }
2044 +
2045 + return $results;
2046 +}
2047 +
2048 +function usces_check_acting_return_duplicate( $results = array() ) {
2049 + global $wpdb;
2050 +
2051 + $acting = isset( $_GET['acting'] ) ? $_GET['acting'] : '';
2052 +
2053 + switch( $acting ) {
2054 + case 'epsilon':
2055 + $trans_id = isset( $_REQUEST['trans_code'] ) ? $_REQUEST['trans_code'] : '';
2056 + $_REQUEST['absolute_trans_id'] = $_REQUEST['order_number'];
2057 + break;
2058 + case 'paypal':
2059 + $trans_id = isset( $results['txn_id'] ) ? $results['txn_id'] : '';
2060 + $_REQUEST['absolute_trans_id'] = $trans_id;
2061 + break;
2062 + case 'paypal_ipn':
2063 + $trans_id = isset( $_REQUEST['txn_id'] ) ? $_REQUEST['txn_id'] : '';
2064 + $_REQUEST['absolute_trans_id'] = $trans_id;
2065 + break;
2066 + case 'paypal_ec':
2067 + $trans_id = isset( $_REQUEST['token'] ) ? $_REQUEST['token'] : '';
2068 + $_REQUEST['absolute_trans_id'] = $trans_id;
2069 + break;
2070 + case 'remise_card':
2071 + $trans_id = isset( $_REQUEST['X-TRANID'] ) ? $_REQUEST['X-TRANID'] : '';
2072 + $_REQUEST['absolute_trans_id'] = $_REQUEST['X-S_TORIHIKI_NO'];
2073 + break;
2074 + case 'remise_conv':
2075 + $trans_id = isset( $_REQUEST['X-JOB_ID'] ) ? $_REQUEST['X-JOB_ID'] : '';
2076 + $_REQUEST['absolute_trans_id'] = $_REQUEST['X-S_TORIHIKI_NO'];
2077 + break;
2078 + case 'jpayment_card':
2079 + case 'jpayment_conv':
2080 + case 'jpayment_bank':
2081 + $trans_id = isset( $_REQUEST['gid'] ) ? $_REQUEST['gid'] : '';
2082 + $_REQUEST['absolute_trans_id'] = $trans_id;
2083 + break;
2084 + case 'telecom_card':
2085 + $trans_id = isset( $_REQUEST['option'] ) ? $_REQUEST['option'] : '';
2086 + $_REQUEST['absolute_trans_id'] = isset( $_REQUEST['option'] ) ? $_REQUEST['option'] : $trans_id;
2087 + break;
2088 + case 'digitalcheck_card':
2089 + case 'digitalcheck_conv':
2090 + $trans_id = isset( $_REQUEST['SID'] ) ? $_REQUEST['SID'] : '';
2091 + $_REQUEST['absolute_trans_id'] = $trans_id;
2092 + break;
2093 + case 'mizuho_card':
2094 + case 'mizuho_conv':
2095 + $trans_id = isset( $_REQUEST['stran'] ) ? $_REQUEST['stran'] : '';
2096 + $_REQUEST['absolute_trans_id'] = $trans_id;
2097 + break;
2098 + default:
2099 + $trans_id = apply_filters( 'usces_filter_check_acting_return_duplicate', '', $results );
2100 + $_REQUEST['absolute_trans_id'] = $trans_id;
2101 + }
2102 + $order_id = usces_get_order_id_by_trans_id( $trans_id );
2103 + if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
2104 + $_REQUEST['remote_addr'] = $_SERVER['REMOTE_ADDR'];
2105 + }
2106 + if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
2107 + $_REQUEST['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
2108 + }
2109 +
2110 + return $order_id;
2111 +}
2112 +
2113 +function usces_get_order_id_by_trans_id( $trans_id ) {
2114 + global $wpdb;
2115 +
2116 + if ( empty( $trans_id ) ) {
2117 + return false;
2118 + }
2119 +
2120 + $table_meta_name = $wpdb->prefix . 'usces_order_meta';
2121 + $query = $wpdb->prepare( "SELECT order_id FROM $table_meta_name WHERE meta_key = %s AND meta_value = %s", 'trans_id', $trans_id );
2122 + $order_id = $wpdb->get_var( $query );
2123 + return $order_id;
2124 +}
2125 +
2126 +function usces_dates_interconv( $date_str ) {
2127 + $base_struc = array( 'd', 'm', 'Y' );
2128 + $date_str_parts = preg_split( '[/.-]', $date_str );
2129 + $date_elements = array();
2130 +
2131 + $p_keys = array_keys( $base_struc );
2132 + foreach ( $p_keys as $p_key ) {
2133 + if ( ! empty( $date_str_parts[ $p_key ] ) ) {
2134 + $date_elements[ $base_struc[ $p_key ] ] = $date_str_parts[ $p_key ];
2135 + } else {
2136 + return false;
2137 + }
2138 + }
2139 + $dummy_ts = mktime( 0, 0, 0, $date_elements['m'], $date_elements['d'], $date_elements['Y'] );
2140 + return date( 'Y-m-d', $dummy_ts );
2141 +}
2142 +
2143 +function usces_register_action( $handle, $type, $key, $value, $function ) {
2144 + global $usces_action;
2145 + $usces_action[ $handle ] = array(
2146 + 'type' => $type,
2147 + 'key' => $key,
2148 + 'value' => $value,
2149 + 'function' => $function,
2150 + );
2151 +}
2152 +
2153 +function usces_deregister_action( $handle ) {
2154 + global $usces_action;
2155 + unset( $usces_action[ $handle ] );
2156 +}
2157 +
2158 +function usces_update_check_admin( $result ) {
2159 + $result = true;
2160 + return $result;
2161 +}
2162 +
2163 +function usces_setup_cod_ajax() {
2164 + global $usces;
2165 +
2166 + // Verify nonce for security.
2167 + check_ajax_referer( 'admin_setup', 'wc_nonce' );
2168 +
2169 + // Check user capability.
2170 + if ( ! current_user_can( 'wel_manage_setting' ) ) {
2171 + wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'usces' ), 403 );
2172 + }
2173 +
2174 + $usces->options = get_option( 'usces' );
2175 + $message = '';
2176 + $_POST = $usces->stripslashes_deep_post( $_POST );
2177 +
2178 + $usces->options['cod_type'] = isset( $_POST['cod_type'] ) ? $_POST['cod_type'] : 'fix';
2179 + if ( isset( $_POST['cod_fee'] ) ) {
2180 + $usces->options['cod_fee'] = (int) $_POST['cod_fee'];
2181 + }
2182 + if ( 'fix' == $usces->options['cod_type'] ) {
2183 + if ( isset( $_POST['cod_limit_amount'] ) ) {
2184 + $usces->options['cod_limit_amount'] = (int) $_POST['cod_limit_amount'];
2185 + if ( ! WCUtils::is_blank( $_POST['cod_limit_amount'] ) && 0 === (int) $_POST['cod_limit_amount'] ) {
2186 + $message = __( 'There is the item where a value is dirty.', 'usces' );
2187 + }
2188 + } // phpcs:ignore Squiz.WhiteSpace.ControlStructureSpacing.SpacingAfterOpen
2189 +
2190 + } elseif ( 'change' == $usces->options['cod_type'] ) {
2191 + if ( isset( $_POST['cod_first_amount'] ) ) {
2192 + $usces->options['cod_first_amount'] = (int) $_POST['cod_first_amount'];
2193 + if ( 0 === (int) $_POST['cod_first_amount'] ) {
2194 + $message = __( 'There is the item where a value is dirty.', 'usces' );
2195 + }
2196 + }
2197 + if ( isset( $_POST['cod_limit_amount'] ) ) {
2198 + $usces->options['cod_limit_amount'] = (int) $_POST['cod_limit_amount'];
2199 + if ( ! WCUtils::is_blank( $_POST['cod_limit_amount'] ) && 0 === (int) $_POST['cod_limit_amount'] ) {
2200 + $message = __( 'There is the item where a value is dirty.', 'usces' );
2201 + }
2202 + }
2203 + if ( isset( $_POST['cod_first_fee'] ) ) {
2204 + $usces->options['cod_first_fee'] = (int) $_POST['cod_first_fee'];
2205 + if ( 0 === (int) $_POST['cod_first_fee'] && '0' !== $_POST['cod_first_fee'] ) {
2206 + $message = __( 'There is the item where a value is dirty.', 'usces' );
2207 + }
2208 + }
2209 + if ( isset( $_POST['cod_end_fee'] ) ) {
2210 + $usces->options['cod_end_fee'] = (int) $_POST['cod_end_fee'];
2211 + if ( 0 === (int) $_POST['cod_end_fee'] && '0' !== $_POST['cod_end_fee'] ) {
2212 + $message = __( 'There is the item where a value is dirty.', 'usces' );
2213 + }
2214 + }
2215 +
2216 + unset( $usces->options['cod_amounts'], $usces->options['cod_fees'] );
2217 + if ( isset( $_POST['cod_amounts'] ) ) {
2218 + $cod_amounts_count = ( is_array( $_POST['cod_amounts'] ) ) ? count( $_POST['cod_amounts'] ) : 0;
2219 + for ( $i = 0; $i < $cod_amounts_count; $i++ ) {
2220 + $usces->options['cod_amounts'][ $i ] = (int) $_POST['cod_amounts'][ $i ];
2221 + $usces->options['cod_fees'][ $i ] = (int) $_POST['cod_fees'][ $i ];
2222 + if ( 0 === (int) $_POST['cod_amounts'][ $i ] || ( 0 === (int) $_POST['cod_fees'][ $i ] && '0' !== $_POST['cod_fees'][ $i ] ) ) {
2223 + $message = __( 'There is the item where a value is dirty.', 'usces' );
2224 + }
2225 + }
2226 + }
2227 + }
2228 +
2229 + if ( '' === $message ) {
2230 + $r = 'success';
2231 + update_option( 'usces', $usces->options );
2232 + } else {
2233 + $r = '<span style="color:red;">' . $message . '</span>';
2234 + }
2235 + die( $r );
2236 +}
2237 +
2238 +function usces_get_order_acting_data( $rand ) {
2239 + global $wpdb;
2240 +
2241 + $table_name = $wpdb->prefix . 'usces_access';
2242 + $query = $wpdb->prepare( "SELECT acc_str1 AS `sesid`, acc_value AS `order_data` FROM $table_name WHERE acc_key = %s", $rand );
2243 + $res = $wpdb->get_row( $query, ARRAY_A );
2244 + if ( $res == NULL ) {
2245 + return false;
2246 + } else {
2247 + return $res;
2248 + }
2249 +}
2250 +
2251 +function usces_ordered_acting_data( $rand, $key = 'order_received' ) {
2252 + global $usces, $wpdb;
2253 +
2254 + $datas = usces_get_order_acting_data( $rand );
2255 + $data = wel_safe_unserialize( $datas['order_data'] );
2256 + usces_log( 'usces_ordered_acting_data', 'acting_transaction.log' );
2257 + $data[ $key ] = 1;
2258 +
2259 + $data = serialize( $data );
2260 + $table_name = $wpdb->prefix . 'usces_access';
2261 + $query = $wpdb->prepare(
2262 + "UPDATE $table_name SET acc_value = %s WHERE acc_type = %s AND acc_key = %s",
2263 + $data,
2264 + 'acting_data',
2265 + $rand
2266 + );
2267 + $res = $wpdb->query( $query );
2268 +}
2269 +
2270 +function usces_delete_ordered_acting_data( $rand ) {
2271 + global $wpdb;
2272 +
2273 + $table_name = $wpdb->prefix . 'usces_access';
2274 + $query = $wpdb->prepare( "DELETE FROM $table_name WHERE acc_type = %s AND acc_key = %s", 'acting_data', $rand );
2275 + $res = $wpdb->query( $query );
2276 +}
2277 +
2278 +function usces_is_trusted_acting_data( $rand ) {
2279 + global $usces, $wpdb;
2280 +
2281 + $datas = usces_get_order_acting_data( $rand );
2282 + $data = wel_safe_unserialize( $datas['order_data'] );
2283 + usces_log( 'usces_is_trusted_acting_data', 'acting_transaction.log' );
2284 + if ( isset( $data['propriety'] ) && $data['propriety'] && ! isset( $data['order_received'] ) ) {
2285 + return true;
2286 + } else {
2287 + return false;
2288 + }
2289 +}
2290 +
2291 +function usces_get_filename( $path ) {
2292 + $res = array();
2293 + if ( $handle = opendir( $path ) ) {
2294 + while ( false !== ( $file = readdir( $handle ) ) ) {
2295 + if ( '.' != $file && '..' != $file ) {
2296 + $res[] = $file;
2297 + }
2298 + }
2299 + closedir( $handle );
2300 + }
2301 + return $res;
2302 +}
2303 +
2304 +function usces_locales() {
2305 + $res = array();
2306 + if ( $handle = opendir( USCES_PLUGIN_DIR . '/languages/' ) ) {
2307 + while ( false !== ( $file = readdir( $handle ) ) ) {
2308 + if ( '.' != $file && '..' != $file && preg_match( '/^usces-(.+)\.mo$/', $file, $matches ) ) {
2309 + $res[] = $matches[1];
2310 + }
2311 + }
2312 + closedir( $handle );
2313 + }
2314 + return $res;
2315 +}
2316 +
2317 +function usces_get_local_language() {
2318 + $locale = get_locale();
2319 + switch ( $locale ) {
2320 + case '':
2321 + case 'en':
2322 + case 'en_US':
2323 + $front_lang = 'en';
2324 + break;
2325 + case 'ja':
2326 + case 'ja_JP':
2327 + $front_lang = 'ja';
2328 + break;
2329 + default:
2330 + $front_lang = 'others';
2331 + }
2332 + return $front_lang;
2333 +}
2334 +
2335 +function usces_get_base_country() {
2336 + global $usces_settings;
2337 +
2338 + $wplang = defined( 'WPLANG' ) ? WPLANG : get_locale();
2339 + $locale = empty( $wplang ) ? 'en' : $wplang;
2340 + $base_country = ( array_key_exists( $locale, $usces_settings['lungage2country'] ) ) ? $usces_settings['lungage2country'][ $locale ] : 'US';
2341 + $base_country = apply_filters( 'usces_filter_base_country', $base_country );
2342 + return $base_country;
2343 +}
2344 +
2345 +function usces_get_local_addressform() {
2346 + global $usces_settings;
2347 +
2348 + $base = usces_get_base_country();
2349 + $addressform = ( array_key_exists( $base, $usces_settings['addressform'] ) ) ? $usces_settings['addressform'][ $base ] : 'US';
2350 + $addressform = apply_filters( 'usces_filter_addressform', $addressform );
2351 + return $addressform;
2352 +}
2353 +
2354 +function usces_get_local_target_market() {
2355 + $base = usces_get_base_country();
2356 + return (array) $base;
2357 +}
2358 +
2359 +function usces_get_apply_addressform( $country ) {
2360 + global $usces_settings;
2361 + return $usces_settings['addressform'][ $country ];
2362 +}
2363 +
2364 +function usces_remove_filter() {
2365 + global $usces, $post;
2366 +
2367 + if ( is_single() && 'item' == $post->post_mime_type ) {
2368 + remove_filter( 'the_content', array( &$usces, 'filter_itemPage' ) );
2369 +
2370 + } elseif ( $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) || $usces->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
2371 + remove_action( 'the_post', array( &$usces, 'action_cartFilter' ) );
2372 + remove_filter( 'the_title', array( &$usces, 'filter_cartTitle' ) ,20 );
2373 + remove_filter( 'the_content', array( &$usces, 'filter_cartContent' ), 20 );
2374 +
2375 + } elseif ( $usces->is_member_page( $_SERVER['REQUEST_URI'] ) ) {
2376 + remove_action( 'the_post', array( &$usces, 'action_memberFilter' ) );
2377 + remove_filter( 'the_title', array( &$usces, 'filter_memberTitle' ), 20 );
2378 + remove_filter( 'the_content', array( &$usces, 'filter_memberContent' ) ,20 );
2379 +
2380 + } else {
2381 + remove_action( 'the_post', array( &$usces, 'goDefaultPage' ) );
2382 + }
2383 +}
2384 +
2385 +function usces_reset_filter() {
2386 + global $usces, $post;
2387 +
2388 + if ( is_single() && 'item' == $post->post_mime_type ) {
2389 + add_filter( 'the_content', array( &$usces, 'filter_itemPage' ) );
2390 +
2391 + } elseif ( $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) || $usces->is_inquiry_page( $_SERVER['REQUEST_URI'] ) ) {
2392 + add_action( 'the_post', array( &$usces, 'action_cartFilter' ) );
2393 + add_filter( 'the_title', array( &$usces, 'filter_cartTitle' ), 20 );
2394 + add_filter( 'the_content', array( &$usces, 'filter_cartContent' ), 20 );
2395 +
2396 + } elseif ( $usces->is_member_page( $_SERVER['REQUEST_URI'] ) ) {
2397 + add_action( 'the_post', array( &$usces, 'action_memberFilter' ) );
2398 + add_filter( 'the_title', array( &$usces, 'filter_memberTitle' ), 20 );
2399 + add_filter( 'the_content', array( &$usces, 'filter_memberContent' ), 20 );
2400 +
2401 + } else {
2402 + add_action( 'the_post', array( &$usces, 'goDefaultPage' ) );
2403 + }
2404 +}
2405 +
2406 +function usces_get_wcex() {
2407 + $wcex = array();
2408 + if ( defined( 'WCEX_DLSELLER_VERSION' ) ) {
2409 + $wcex['DLSELLER'] = array(
2410 + 'name' => 'Dl Seller',
2411 + 'version' => WCEX_DLSELLER_VERSION,
2412 + );
2413 + }
2414 + if ( defined( 'WCEX_ITEM_LIST_LAYOUT_VERSION' ) ) {
2415 + $wcex['ITEM_LIST_LAYOUT'] = array(
2416 + 'name' => 'Item List Layout',
2417 + 'version' => WCEX_ITEM_LIST_LAYOUT_VERSION,
2418 + );
2419 + }
2420 + if ( defined( 'WCEX_MOBILE_VERSION' ) ) {
2421 + $wcex['MOBILE'] = array(
2422 + 'name' => 'Mobile',
2423 + 'version' => WCEX_MOBILE_VERSION,
2424 + );
2425 + }
2426 + if ( defined( 'WCEX_MULTIPRICE_VERSION' ) ) {
2427 + $wcex['MULTIPRICE'] = array(
2428 + 'name' => 'Multi Price',
2429 + 'version' => WCEX_MULTIPRICE_VERSION,
2430 + );
2431 + }
2432 + if ( defined( 'WCEX_SLIDE_SHOWCASE_VERSION' ) ) {
2433 + $wcex['SLIDE_SHOWCASE'] = array(
2434 + 'name' => 'Slide Showcase',
2435 + 'version' => WCEX_SLIDE_SHOWCASE_VERSION,
2436 + );
2437 + }
2438 + if ( defined( 'WCEX_WIDGET_CART_VERSION' ) ) {
2439 + $wcex['WIDGET_CART'] = array(
2440 + 'name' => 'Widget Cart',
2441 + 'version' => WCEX_WIDGET_CART_VERSION,
2442 + );
2443 + }
2444 + return $wcex;
2445 +}
2446 +
2447 +function usces_trackPageview_cart( $push ) {
2448 + $push = array();
2449 + if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2450 + $push[] = "'_trackPageview','/" . USCES_KEY . "wc_cart'";
2451 + } else {
2452 + $push[] = "'_trackPageview','/wc_cart'";
2453 + }
2454 + return $push;
2455 +}
2456 +
2457 +function usces_trackPageview_customer( $push ) {
2458 + $push = array();
2459 + if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2460 + $push[] = "'_trackPageview','/" . USCES_KEY . "wc_customer'";
2461 + } else {
2462 + $push[] = "'_trackPageview','/wc_customer'";
2463 + }
2464 + return $push;
2465 +}
2466 +
2467 +function usces_trackPageview_delivery( $push ) {
2468 + $push = array();
2469 + if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2470 + $push[] = "'_trackPageview','/" . USCES_KEY . "wc_delivery'";
2471 + } else {
2472 + $push[] = "'_trackPageview','/wc_delivery'";
2473 + }
2474 + return $push;
2475 +}
2476 +
2477 +function usces_trackPageview_confirm( $push ) {
2478 + $push = array();
2479 + if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2480 + $push[] = "'_trackPageview','/" . USCES_KEY . "wc_confirm'";
2481 + } else {
2482 + $push[] = "'_trackPageview','/wc_confirm'";
2483 + }
2484 + return $push;
2485 +}
2486 +
2487 +function usces_trackPageview_ordercompletion( $push ) {
2488 + global $usces;
2489 +
2490 + if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2491 + $push[] = "'_trackPageview','/" . USCES_KEY . "wc_ordercompletion'";
2492 + } else {
2493 + $push[] = "'_trackPageview','/wc_ordercompletion'";
2494 + }
2495 +
2496 + $sesdata = $usces->cart->get_entry();
2497 + if ( isset( $sesdata['order']['ID'] ) && ! empty( $sesdata['order']['ID'] ) ) {
2498 + $order_id = $sesdata['order']['ID'];
2499 + $data = $usces->get_order_data( $order_id, 'direct' );
2500 + $cart = wel_safe_unserialize( $data['order_cart'] );
2501 + $total_price = $usces->get_total_price( $cart ) + $data['order_discount'] - $data['order_usedpoint'];
2502 + if ( $total_price < 0 ) {
2503 + $total_price = 0;
2504 + }
2505 + $push[] = "'_addTrans', '" . $order_id . "', '" . esc_js( get_option( 'blogname' ) ) . "', '" . $total_price . "', '" . $data['order_tax'] . "', '" . $data['order_shipping_charge'] . "', '" . esc_js( $data['order_address1'] . $data['order_address2'] ) . "', '" . esc_js( $data['order_pref'] ) . "', '" . get_locale() . "'";
2506 + $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
2507 + for ( $i = 0; $i < $cart_count; $i++ ) {
2508 + $cart_row = $cart[ $i ];
2509 + $post_id = $cart_row['post_id'];
2510 + $sku = urldecode( $cart_row['sku'] );
2511 + $quantity = $cart_row['quantity'];
2512 + $itemName = $usces->getItemName( $post_id );
2513 + $skuPrice = $cart_row['price'];
2514 + $cats = $usces->get_item_cat_genre_ids( $post_id );
2515 + if ( is_array( $cats ) ) {
2516 + sort( $cats );
2517 + }
2518 + $category = ( isset( $cats[0] ) ) ? get_cat_name( $cats[0] ) : '';
2519 + $push[] = "'_addItem', '" . $order_id . "', '" . esc_js( $sku ) . "', '" . esc_js( $itemName ) . "', '" . esc_js( $category ) . "', '" . $skuPrice . "', '" . $quantity . "'";
2520 + }
2521 + $push[] = "'_trackTrans'";
2522 + }
2523 +
2524 + return $push;
2525 +}
2526 +
2527 +function usces_trackPageview_error( $push ) {
2528 + if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2529 + $push[] = "'_trackPageview','/" . USCES_KEY . "wc_error'";
2530 + } else {
2531 + $push[] = "'_trackPageview','/wc_error'";
2532 + }
2533 + return $push;
2534 +}
2535 +
2536 +function usces_trackPageview_member( $push ) {
2537 + if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2538 + $push[] = "'_trackPageview','/" . USCES_KEY . "wc_member'";
2539 + } else {
2540 + $push[] = "'_trackPageview','/wc_member'";
2541 + }
2542 + return $push;
2543 +}
2544 +
2545 +function usces_trackPageview_login( $push ) {
2546 + if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2547 + $push[] = "'_trackPageview','/" . USCES_KEY . "wc_login'";
2548 + } else {
2549 + $push[] = "'_trackPageview','/wc_login'";
2550 + }
2551 + return $push;
2552 +}
2553 +
2554 +function usces_trackPageview_editmemberform( $push ) {
2555 + if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2556 + $push[] = "'_trackPageview','/" . USCES_KEY . "wc_editmemberform'";
2557 + } else {
2558 + $push[] = "'_trackPageview','/wc_editmemberform'";
2559 + }
2560 + return $push;
2561 +}
2562 +
2563 +function usces_trackPageview_newcompletion( $push ) {
2564 + if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2565 + $push[] = "'_trackPageview','/" . USCES_KEY . "wc_newcompletion'";
2566 + } else {
2567 + $push[] = "'_trackPageview','/wc_newcompletion'";
2568 + }
2569 + return $push;
2570 +}
2571 +
2572 +function usces_trackPageview_newmemberform( $push ) {
2573 + if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2574 + $push[] = "'_trackPageview','/" . USCES_KEY . "wc_newmemberform'";
2575 + } else {
2576 + $push[] = "'_trackPageview','/wc_newmemberform'";
2577 + }
2578 + return $push;
2579 +}
2580 +
2581 +function usces_trackPageview_deletemember( $push ) {
2582 + if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2583 + $push[] = "'_trackPageview','/" . USCES_KEY . "wc_deletemember'";
2584 + } else {
2585 + $push[] = "'_trackPageview','/wc_deletemember'";
2586 + }
2587 + return $push;
2588 +}
2589 +
2590 +function usces_trackPageview_search_item( $push ) {
2591 + if ( defined( 'USCES_KEY' ) && defined( 'USCES_MULTI' ) && true == USCES_MULTI ) {
2592 + $push[] = "'_trackPageview','/" . USCES_KEY . "wc_search_item'";
2593 + } else {
2594 + $push[] = "'_trackPageview','/wc_search_item'";
2595 + }
2596 + return $push;
2597 +}
2598 +
2599 +function usces_get_essential_mark( $fielde, $data = NULL ) {
2600 + global $usces_essential_mark;
2601 + do_action( 'usces_action_essential_mark', $data, $fielde );
2602 + return $usces_essential_mark[ $fielde ];
2603 +}
2604 +
2605 +function uesces_get_admin_addressform( $type, $data, $customdata, $out = 'return' ) {
2606 + global $usces, $usces_settings;
2607 +
2608 + $options = get_option( 'usces', array() );
2609 + $applyform = usces_get_apply_addressform( $options['system']['addressform'] );
2610 + $formtag = '';
2611 + switch ( $type ) {
2612 + case 'member':
2613 + $values = array(
2614 + 'name1' => $data['mem_name1'],
2615 + 'name2' => $data['mem_name2'],
2616 + 'name3' => $data['mem_name3'],
2617 + 'name4' => $data['mem_name4'],
2618 + 'zipcode' => $data['mem_zip'],
2619 + 'address1' => $data['mem_address1'],
2620 + 'address2' => $data['mem_address2'],
2621 + 'address3' => $data['mem_address3'],
2622 + 'tel' => $data['mem_tel'],
2623 + 'fax' => $data['mem_fax'],
2624 + 'pref' => $data['mem_pref'],
2625 + );
2626 + $country = $usces->get_member_meta_value( 'customer_country', $data['ID'] );
2627 + $values['country'] = ! empty( $country ) ? $country : usces_get_local_addressform();
2628 + break;
2629 + case 'customer':
2630 + $values = array(
2631 + 'name1' => $data['order_name1'],
2632 + 'name2' => $data['order_name2'],
2633 + 'name3' => $data['order_name3'],
2634 + 'name4' => $data['order_name4'],
2635 + 'zipcode' => $data['order_zip'],
2636 + 'address1' => $data['order_address1'],
2637 + 'address2' => $data['order_address2'],
2638 + 'address3' => $data['order_address3'],
2639 + 'tel' => $data['order_tel'],
2640 + 'fax' => $data['order_fax'],
2641 + 'pref' => $data['order_pref'],
2642 + );
2643 + $country = $usces->get_order_meta_value( 'customer_country', $data['ID'] );
2644 + $values['country'] = ! empty( $country ) ? $country : usces_get_local_addressform();
2645 + break;
2646 + case 'delivery':
2647 + $values = $data;
2648 + break;
2649 + }
2650 +
2651 + switch ( $applyform ) {
2652 +
2653 + case 'JP':
2654 + $formtag .= usces_admin_custom_field_input( $customdata, $type, 'name_pre', 'return' );
2655 + $formtag .= '
2656 + <tr id="' . $type . '_name_row">
2657 + <td class="label">' . __( 'name', 'usces' ) . '</td>
2658 + <td class="col2 datafield"><input name="' . $type . '[name1]" type="text" class="text short" value="' . esc_attr( $values['name1'] ) . '" /><input name="' . $type . '[name2]" type="text" class="text short" value="' . esc_attr( $values['name2'] ) . '" /></td>
2659 + </tr>
2660 + <tr id="' . $type . 'furikana_row">
2661 + <td class="label">' . __( 'furigana', 'usces' ) . '</td>
2662 + <td class="col2 datafield"><input name="' . $type . '[name3]" type="text" class="text short" value="' . esc_attr( $values['name3'] ) . '" /><input name="' . $type . '[name4]" type="text" class="text short" value="' . esc_attr( $values['name4'] ) . '" /></td>
2663 + </tr>';
2664 + $formtag .= usces_admin_custom_field_input( $customdata, $type, 'name_after', 'return' );
2665 + $formtag .= '
2666 + <tr id="' . $type . 'zipcode_row">
2667 + <td class="label">' . __( 'Zip/Postal Code', 'usces' ) . '</td>
2668 + <td class="col2 datafield"><input name="' . $type . '[zipcode]" type="text" class="text short" value="' . esc_attr( $values['zipcode'] ) . '" />' . apply_filters( 'usces_filter_admin_addressform_zipcode', NULL, $type ) . '</td>
2669 + </tr>
2670 + <tr id="' . $type . '_country_row">
2671 + <td class="label">' . __( 'Country', 'usces' ) . '</td>
2672 + <td class="col2 datafield">' . uesces_get_target_market_form( $type, $values['country'] ) . '</td>
2673 + </tr>
2674 + <tr id="' . $type . '_states_row">
2675 + <td class="label">' . __( 'Province', 'usces' ) . '</td>
2676 + <td class="col2 datafield">';
2677 +
2678 + $formtag .= usces_pref_select( $type, $values );
2679 +
2680 + $formtag .= '</td>
2681 + </tr>';
2682 + $formtag .= '
2683 + <tr id="' . $type . '_address1_row">
2684 + <td class="label">' . __( 'city', 'usces' ) . '</td>
2685 + <td class="col2 datafield"><input name="' . $type . '[address1]" type="text" class="text long" value="' . esc_attr( $values['address1'] ) . '" /></td>
2686 + </tr>
2687 + <tr id="' . $type . '_address2_row">
2688 + <td class="label">' . __( 'numbers', 'usces' ) . '</td>
2689 + <td class="col2 datafield"><input name="' . $type . '[address2]" type="text" class="text long" value="' . esc_attr( $values['address2'] ) . '" /></td>
2690 + </tr>
2691 + <tr id="' . $type . '_address3_row">
2692 + <td class="label">' . __( 'building name', 'usces' ) . '</td>
2693 + <td class="col2 datafield"><input name="' . $type . '[address3]" type="text" class="text long" value="' . esc_attr( $values['address3'] ) . '" /></td>
2694 + </tr>
2695 + <tr id="' . $type . '_tel_row">
2696 + <td class="label">' . __( 'Phone number', 'usces' ) . '</td>
2697 + <td class="col2 datafield"><input name="' . $type . '[tel]" type="text" class="text long" value="' . esc_attr( $values['tel'] ) . '" /></td>
2698 + </tr>
2699 + <tr id="' . $type . '_fax_row">
2700 + <td class="label">' . __( 'FAX number', 'usces' ) . '</td>
2701 + <td class="col2 datafield"><input name="' . $type . '[fax]" type="text" class="text long" value="' . esc_attr( $values['fax'] ) . '" /></td>
2702 + </tr>';
2703 + $formtag .= usces_admin_custom_field_input( $customdata, $type, 'fax_after', 'return' );
2704 + break;
2705 +
2706 + case 'CN':
2707 + $formtag .= usces_admin_custom_field_input( $customdata, $type, 'name_pre', 'return' );
2708 + $formtag .= '
2709 + <tr>
2710 + <td id="' . $type . 'name_row" class="label">' . __( 'name', 'usces' ) . '</td>
2711 + <td class="col2 datafield"><input name="' . $type . '[name1]" type="text" class="text short" value="' . esc_attr( $values['name1'] ) . '" /><input name="' . $type . '[name2]" type="text" class="text short" value="' . esc_attr( $values['name2'] ) . '" /></td>
2712 + </tr>';
2713 + $formtag .= usces_admin_custom_field_input( $customdata, $type, 'name_after', 'return' );
2714 + $formtag .= '
2715 + <tr id="' . $type . '_country_row">
2716 + <td class="label">' . __( 'Country', 'usces' ) . '</td>
2717 + <td class="col2 datafield">' . uesces_get_target_market_form( $type, $values['country'] ) . '</td>
2718 + </tr>
2719 + <tr id="' . $type . '_states_row">
2720 + <td class="label">' . __( 'State', 'usces' ) . '</td>
2721 + <td class="col2 datafield">';
2722 +
2723 + $formtag .= usces_pref_select( $type, $values );
2724 +
2725 + $formtag .= '</td>
2726 + </tr id="' . $type . '_address1_row">';
2727 + $formtag .= '<tr>
2728 + <td class="label">' . __( 'city', 'usces' ) . '</td>
2729 + <td class="col2 datafield"><input name="' . $type . '[address1]" type="text" class="text long" value="' . esc_attr( $values['address1'] ) . '" /></td>
2730 + </tr>
2731 + <tr id="' . $type . '_address2_row">
2732 + <td class="label">' . __( 'Address Line1', 'usces' ) . '</td>
2733 + <td class="col2 datafield"><input name="' . $type . '[address2]" type="text" class="text long" value="' . esc_attr( $values['address2'] ) . '" /></td>
2734 + </tr>
2735 + <tr id="' . $type . '_address3_row">
2736 + <td class="label">' . __( 'Address Line2', 'usces' ) . '</td>
2737 + <td class="col2 datafield"><input name="' . $type . '[address3]" type="text" class="text long" value="' . esc_attr( $values['address3'] ) . '" /></td>
2738 + </tr>
2739 + <tr id="' . $type . 'zipcode_row">
2740 + <td class="label">' . __( 'Zip', 'usces' ) . '</td>
2741 + <td class="col2 datafield"><input name="' . $type . '[zipcode]" type="text" class="text short" value="' . esc_attr( $values['zipcode'] ) . '" /></td>
2742 + </tr>
2743 + <tr id="' . $type . '_tel_row">
2744 + <td class="label">' . __( 'Phone number', 'usces' ) . '</td>
2745 + <td class="col2 datafield"><input name="' . $type . '[tel]" type="text" class="text long" value="' . esc_attr( $values['tel'] ) . '" /></td>
2746 + </tr>
2747 + <tr id="' . $type . '_fax_row">
2748 + <td class="label">' . __( 'FAX number', 'usces' ) . '</td>
2749 + <td class="col2 datafield"><input name="' . $type . '[fax]" type="text" class="text long" value="' . esc_attr( $values['fax'] ) . '" /></td>
2750 + </tr>';
2751 + $formtag .= usces_admin_custom_field_input( $customdata, $type, 'fax_after', 'return' );
2752 + break;
2753 +
2754 + case 'US':
2755 + default:
2756 + $formtag .= usces_admin_custom_field_input( $customdata, $type, 'name_pre', 'return' );
2757 + $formtag .= '
2758 + <tr id="' . $type . 'name_row">
2759 + <td class="label">' . __( 'name', 'usces' ) . '</td>
2760 + <td class="col2 datafield"><input name="' . $type . '[name2]" type="text" class="text short" value="' . esc_attr( $values['name2'] ) . '" /><input name="' . $type . '[name1]" type="text" class="text short" value="' . esc_attr( $values['name1'] ) . '" /></td>
2761 + </tr>';
2762 + $formtag .= usces_admin_custom_field_input( $customdata, $type, 'name_after', 'return' );
2763 + $formtag .= '
2764 + <tr id="' . $type . '_address2_row">
2765 + <td class="label">' . __( 'Address Line1', 'usces' ) . '</td>
2766 + <td class="col2 datafield"><input name="' . $type . '[address2]" type="text" class="text long" value="' . esc_attr( $values['address2'] ) . '" /></td>
2767 + </tr>
2768 + <tr id="' . $type . '_address3_row">
2769 + <td class="label">' . __( 'Address Line2', 'usces' ) . '</td>
2770 + <td class="col2 datafield"><input name="' . $type . '[address3]" type="text" class="text long" value="' . esc_attr( $values['address3'] ) . '" /></td>
2771 + </tr>
2772 + <tr id="' . $type . '_address1_row">
2773 + <td class="label">' . __( 'city', 'usces' ) . '</td>
2774 + <td class="col2 datafield"><input name="' . $type . '[address1]" type="text" class="text long" value="' . esc_attr( $values['address1'] ) . '" /></td>
2775 + </tr>
2776 + <tr id="' . $type . '_states_row">
2777 + <td class="label">' . __( 'State', 'usces' ) . '</td>
2778 + <td class="col2 datafield">';
2779 +
2780 + $formtag .= usces_pref_select( $type, $values );
2781 +
2782 + $formtag .= '</td>
2783 + </tr>';
2784 + $formtag .= '
2785 + <tr id="' . $type . '_country_row">
2786 + <td class="label">' . __( 'Country', 'usces' ) . '</td>
2787 + <td class="col2 datafield">' . uesces_get_target_market_form( $type, $values['country'] ) . '</td>
2788 + </tr>
2789 + <tr id="' . $type . 'zipcode_row">
2790 + <td class="label">' . __( 'Zip', 'usces' ) . '</td>
2791 + <td class="col2 datafield"><input name="' . $type . '[zipcode]" type="text" class="text short" value="' . esc_attr( $values['zipcode'] ) . '" /></td>
2792 + </tr>
2793 + <tr id="' . $type . '_tel_row">
2794 + <td class="label">' . __( 'Phone number', 'usces' ) . '</td>
2795 + <td class="col2 datafield"><input name="' . $type . '[tel]" type="text" class="text long" value="' . esc_attr( $values['tel'] ) . '" /></td>
2796 + </tr>
2797 + <tr id="' . $type . '_fax_row">
2798 + <td class="label">' . __( 'FAX number', 'usces' ) . '</td>
2799 + <td class="col2 datafield"><input name="' . $type . '[fax]" type="text" class="text long" value="' . esc_attr( $values['fax'] ) . '" /></td>
2800 + </tr>';
2801 + $formtag .= usces_admin_custom_field_input( $customdata, $type, 'fax_after', 'return' );
2802 + break;
2803 + }
2804 + $res = apply_filters( 'usces_filter_apply_admin_addressform', $formtag, $type, $data, $customdata );
2805 +
2806 + if ( 'return' === $out ) {
2807 + return $res;
2808 + } else {
2809 + echo $res; // no escape due to filter.
2810 + }
2811 +}
2812 +
2813 +function self_filter_apply_admin_addressform( $formtag, $type, $data, $customdata ) {
2814 + if ( ! empty( $_SESSION['admin_admb_custom_field_member'] ) ) {
2815 + $admb = $_SESSION['admin_admb_custom_field_member'];
2816 + $formtag .= usces_admin_custom_field_input( $admb['data'], $admb['type'], 'fax_after', 'return' );
2817 + unset( $_SESSION['admin_admb_custom_field_member'] );
2818 + }
2819 + return $formtag;
2820 +}
2821 +
2822 +function uesces_get_target_market_form( $type, $selected, $out = 'return' ) {
2823 + global $usces_settings;
2824 +
2825 + $options = get_option( 'usces', array() );
2826 + $res = '<select name="' . $type . '[country]" id="' . $type . '_country">' . "\n";
2827 + foreach ( $usces_settings['country'] as $key => $value ) {
2828 + if ( in_array( $key, $options['system']['target_market'] ) ) {
2829 + $res .= '<option value="' . $key . '"' . selected( $selected, $key, false ) . '>' . $value . "</option>\n";
2830 + }
2831 + }
2832 + $res .= '</select>' . "\n";
2833 +
2834 + if ( 'return' === $out ) {
2835 + return wel_esc_script( $res );
2836 + } else {
2837 + wel_esc_script_e( $res );
2838 + }
2839 +}
2840 +
2841 +function usces_pref_select( $type, $values, $out = 'return' ) {
2842 + global $usces, $usces_states;
2843 +
2844 + $country = empty( $values['country'] ) ? usces_get_base_country() : $values['country'];
2845 + $options = get_option( 'usces', array() );
2846 + if ( ! in_array( $country, $options['system']['target_market'] ) ) {
2847 + $country = $options['system']['target_market'][0];
2848 + }
2849 +
2850 + $pref = ( isset( $values['pref'] ) ) ? $values['pref'] : '';
2851 + $prefs = get_usces_states( $country );
2852 + $html = '<select name="' . esc_attr( $type . '[pref]' ) . '" id="' . esc_attr( $type ) . '_pref" class="pref">';
2853 + $prefs_count = count( $prefs );
2854 + if ( 0 < $prefs_count ) {
2855 + $select = __( '-- Select --', 'usces_dual' );
2856 + $html .= "\t" . '<option value="' . esc_attr( $select ) . '">' . esc_html( $select ) . "</option>\n";
2857 + for ( $i = 1; $i < $prefs_count; $i++ ) {
2858 + $html .= "\t" . '<option value="' . esc_attr( $prefs[ $i ] ) . '"' . selected( $prefs[ $i ], $pref, false ) . '>' . esc_html( $prefs[ $i ] ) . "</option>\n";
2859 + }
2860 + }
2861 + $html .= "</select>\n";
2862 + $html = apply_filters( 'usces_filter_pref_field', $html, $type, $values, $country, $prefs );
2863 +
2864 + if ( 'return' === $out ) {
2865 + return $html;
2866 + } else {
2867 + echo $html; // no escape due to filter.
2868 + }
2869 +}
2870 +
2871 +function usces_is_tax_display() {
2872 + global $usces;
2873 + if ( isset( $usces->options['tax_display'] ) && 'deactivate' === $usces->options['tax_display'] ) {
2874 + return false;
2875 + } else {
2876 + return true;
2877 + }
2878 +}
2879 +
2880 +function usces_get_tax_display() {
2881 + global $usces;
2882 + $tax_display = ( isset( $usces->options['tax_display'] ) ) ? $usces->options['tax_display'] : 'activate';
2883 + return $tax_display;
2884 +}
2885 +
2886 +function usces_get_tax_mode() {
2887 + global $usces;
2888 + return $usces->options['tax_mode'];
2889 +}
2890 +
2891 +function usces_get_tax_target() {
2892 + global $usces;
2893 + return $usces->options['tax_target'];
2894 +}
2895 +
2896 +function usces_is_member_system() {
2897 + global $usces;
2898 + if ( 'activate' === $usces->options['membersystem_state'] ) {
2899 + return true;
2900 + } else {
2901 + return false;
2902 + }
2903 +}
2904 +
2905 +function usces_is_member_system_point() {
2906 + global $usces;
2907 + if ( 'activate' === $usces->options['membersystem_point'] ) {
2908 + return true;
2909 + } else {
2910 + return false;
2911 + }
2912 +}
2913 +
2914 +function usces_point_coverage() {
2915 + global $usces;
2916 + return $usces->options['point_coverage'];
2917 +}
2918 +
2919 +function usces_shipping_country_option( $selected, $out = '' ) {
2920 + global $usces_settings;
2921 +
2922 + $options = get_option( 'usces', array() );
2923 + $res = '';
2924 + foreach ( $usces_settings['country'] as $key => $value ) {
2925 + if ( in_array( $key, $options['system']['target_market'], true ) ) {
2926 + $res .= '<option value="' . $key . '"' . selected( $selected, $key, false ) . '>' . $value . "</option>\n";
2927 + }
2928 + }
2929 + wel_esc_script_e( $res );
2930 +}
2931 +
2932 +function usces_get_cart_button( $out = '' ) {
2933 + global $usces;
2934 +
2935 + $res = '';
2936 +
2937 + if ( $usces->use_js ) {
2938 + $res .= '<input name="previous" type="button" id="previouscart" class="continue_shopping_button" value="' . __( 'continue shopping', 'usces' ) . '"' . apply_filters( 'usces_filter_cart_prebutton', ' onclick="uscesCart.previousCart();"' ) . ' />&nbsp;&nbsp;';
2939 + if ( usces_is_cart() ) {
2940 + $res .= '<input name="customerinfo" type="submit" class="to_customerinfo_button" value="' . __( ' Next ', 'usces' ) . '"' . apply_filters( 'usces_filter_cart_nextbutton', ' onclick="return uscesCart.cartNext();"' ) . ' />';
2941 + }
2942 + } else {
2943 + $res .= '<a href="' . get_home_url() . '" class="continue_shopping_button">' . __( 'continue shopping', 'usces' ) . '</a>&nbsp;&nbsp;';
2944 + if ( usces_is_cart() ) {
2945 + $res .= '<input name="customerinfo" type="submit" class="to_customerinfo_button" value="' . __( ' Next ', 'usces' ) . '"' . apply_filters( 'usces_filter_cart_nextbutton', NULL ) . ' />';
2946 + }
2947 + }
2948 + $res = apply_filters( 'usces_filter_get_cart_button', $res );
2949 +
2950 + if ( 'return' === $out ) {
2951 + return $res;
2952 + } else {
2953 + echo $res; // no escape due to filter.
2954 + }
2955 +}
2956 +
2957 +function usces_get_customer_button( $out = '' ) {
2958 + global $usces, $member_regmode;
2959 +
2960 + $res = '<input name="backCart" type="submit" class="back_cart_button" value="' . __( 'Back', 'usces' ) . '"' . apply_filters( 'usces_filter_customerinfo_pre', NULL ) . ' " />&nbsp;&nbsp;';
2961 +
2962 + $button = '<input name="deliveryinfo" type="submit" class="to_deliveryinfo_button" value="' . __( ' Next ', 'usces' ) . '"' . apply_filters( 'usces_filter_customerinfo_next', NULL ) . ' " />&nbsp;&nbsp;';
2963 + $res .= apply_filters( 'usces_filter_customer_button', $button );
2964 +
2965 + if ( usces_is_membersystem_state() && 'editmemberfromcart' !== $member_regmode && false === usces_is_login() ) {
2966 + $res .= '<input name="reganddeliveryinfo" type="submit" class="to_reganddeliveryinfo_button" value="' . __( 'To the next while enrolling', 'usces' ) . '"' . apply_filters( 'usces_filter_customerinfo_prebutton', NULL ) . ' />';
2967 + } elseif ( usces_is_membersystem_state() && 'editmemberfromcart' === $member_regmode ) {
2968 + $res .= '<input name="reganddeliveryinfo" type="submit" class="to_reganddeliveryinfo_button" value="' . __( 'Revise member information, and to next', 'usces' ) . '"' . apply_filters( 'usces_filter_customerinfo_nextbutton', NULL ) . ' />';
2969 + }
2970 +
2971 + $res = apply_filters( 'usces_filter_get_customer_button', $res );
2972 +
2973 + if ( 'return' === $out ) {
2974 + return $res;
2975 + } else {
2976 + echo $res; // no escape due to filter.
2977 + }
2978 +}
2979 +
2980 +function usces_delivery_secure_form( $out = '' ) {
2981 + global $usces, $usces_entries, $usces_carts;
2982 +
2983 + $html = '';
2984 + include USCES_PLUGIN_DIR . '/includes/delivery_secure_form.php';
2985 +
2986 + if ( 'return' === $out ) {
2987 + return $html;
2988 + } else {
2989 + echo $html; // no escape due to filter.
2990 + }
2991 +}
2992 +
2993 +function usces_delivery_info_script( $out ='' ) {
2994 + return;
2995 +}
2996 +
2997 +function usces_delivery_info_scripts() {
2998 + global $usces, $usces_entries, $usces_carts;
2999 +
3000 + $html = '';
3001 + if ( 'delivery' === $usces->page ) {
3002 + include USCES_PLUGIN_DIR . '/includes/delivery_info_script.php';
3003 + } elseif ( usces_is_cart_page() && usces_is_login() ) {
3004 + $paypal_ec = false;
3005 + $payments = usces_get_system_option( 'usces_payment_method', 'sort' );
3006 + foreach ( (array) $payments as $id => $payment ) {
3007 + if ( 'acting_paypal_ec' === $payment['settlement'] && 'activate' === $payment['use'] ) {
3008 + $paypal_ec = true;
3009 + break;
3010 + }
3011 + }
3012 + if ( $paypal_ec ) {
3013 + include USCES_PLUGIN_DIR . '/includes/delivery_info_script.php';
3014 + }
3015 + }
3016 + echo $html; // no escape due to filter.
3017 +}
3018 +
3019 +function usces_get_entries() {
3020 + global $usces, $usces_entries;
3021 +
3022 + $usces_entries = $usces->cart->get_entry();
3023 + if ( empty( $usces_entries['order']['ID'] ) && ! empty( $usces_entries['reserve']['pre_order_id'] ) ) {
3024 + $usces_entries['order']['ID'] = $usces->get_order_id_by_pre_order_id( $usces_entries['reserve']['pre_order_id'] );
3025 + $usces->cart->set_order_entry( array( 'ID' => $usces_entries['order']['ID'] ) );
3026 + }
3027 +}
3028 +
3029 +function usces_get_carts() {
3030 + global $usces, $usces_carts;
3031 + $usces_carts = $usces->cart->get_cart();
3032 +}
3033 +
3034 +function usces_get_members() {
3035 + global $usces, $usces_members;
3036 + $usces_members = $usces->get_member();
3037 +}
3038 +
3039 +function usces_error_message( $out = '' ) {
3040 + global $usces;
3041 +
3042 + if ( 'return' === $out ) {
3043 + return wel_esc_script( $usces->error_message );
3044 + } else {
3045 + wel_esc_script_e( $usces->error_message );
3046 + }
3047 +}
3048 +
3049 +function usces_url( $type, $out = '' ) {
3050 + global $usces;
3051 +
3052 + switch ( $type ) {
3053 + case 'cart':
3054 + $url = USCES_CART_URL;
3055 + break;
3056 + case 'login':
3057 + $url = USCES_LOGIN_URL;
3058 + break;
3059 + case 'member':
3060 + $url = USCES_MEMBER_URL;
3061 + break;
3062 + case 'newmember':
3063 + $url = USCES_NEWMEMBER_URL;
3064 + break;
3065 + case 'lostmemberpassword':
3066 + $url = USCES_LOSTMEMBERPASSWORD_URL;
3067 + break;
3068 + case 'cartnonsession':
3069 + $url = USCES_CART_NONSESSION_URL;
3070 + break;
3071 + }
3072 +
3073 + if ( 'return' === $out ) {
3074 + return $url;
3075 + } else {
3076 + echo esc_url( $url );
3077 + }
3078 +}
3079 +
3080 +function usces_total_price( $out = '' ) {
3081 + global $usces;
3082 +
3083 + if ( 'return' === $out ) {
3084 + return wel_esc_script( $usces->get_total_price() );
3085 + } else {
3086 + wel_esc_script_e( $usces->get_total_price() );
3087 + }
3088 +}
3089 +
3090 +function usces_completion_settlement( $out ='' ) {
3091 + global $usces, $usces_entries;
3092 +
3093 + $html = '';
3094 +
3095 + $template = apply_filters( 'usces_filter_completion_settlement', USCES_PLUGIN_DIR . '/includes/completion_settlement.php', $usces_entries );
3096 + require( $template );
3097 +
3098 + if ( 'return' === $out ) {
3099 + return $html;
3100 + } else {
3101 + echo $html; // no escape due to filter.
3102 + }
3103 +}
3104 +
3105 +function usces_purchase_button( $out ='' ) {
3106 + global $usces, $usces_entries;
3107 +
3108 + $html = '';
3109 + include USCES_PLUGIN_DIR . '/includes/purchase_button.php';
3110 +
3111 + if ( 'return' === $out ) {
3112 + return $html;
3113 + } else {
3114 + echo $html; // no escape due to filter.
3115 + }
3116 +}
3117 +
3118 +function usces_get_member_regmode() {
3119 + global $member_regmode;
3120 + $member_regmode = isset( $_SESSION['usces_entry']['member_regmode'] ) ? $_SESSION['usces_entry']['member_regmode'] : 'none';
3121 +}
3122 +
3123 +function uesces_get_error_settlement( $out = '' ) {
3124 + $res = '';
3125 + $res = apply_filters( 'usces_filter_get_error_settlement', $res );
3126 + if ( empty( $res ) ) {
3127 + $res = __( 'Sorry, If you have any questions, please contact the administrator of the site.', 'usces' );
3128 + }
3129 +
3130 + if ( 'return' === $out ) {
3131 + return $res;
3132 + } else {
3133 + echo $res; // no escape due to filter.
3134 + }
3135 +}
3136 +
3137 +function usces_page_name( $out = '' ) {
3138 + global $usces;
3139 +
3140 + $page = '';
3141 +
3142 + if ( empty( $usces->page ) ) {
3143 + if ( $usces->is_cart_page( $_SERVER['REQUEST_URI'] ) ) {
3144 + $page = 'cart';
3145 + } elseif ( $usces->is_member_page( $_SERVER['REQUEST_URI'] ) ) {
3146 + $page = 'member';
3147 + }
3148 + } else {
3149 + $page = $usces->page;
3150 + }
3151 + $page = apply_filters( 'usces_filter_usces_page_name', $page );
3152 +
3153 + if ( 'return' === $out ) {
3154 + return esc_js( $page );
3155 + } else {
3156 + echo esc_html( $page );
3157 + }
3158 +}
3159 +
3160 +function usces_post_reg_orderdata( $order_id, $results ) {
3161 + global $usces, $wpdb;
3162 +
3163 + $acting = isset( $_GET['acting'] ) ? $_GET['acting'] : '';
3164 + $data = array();
3165 +
3166 + if ( $order_id ) {
3167 +
3168 + switch ( $acting ) {
3169 + case 'epsilon':
3170 + $trans_id = isset( $_REQUEST['trans_code'] ) ? $_REQUEST['trans_code'] : '';
3171 + break;
3172 + case 'paypal_ipn':
3173 + $trans_id = isset( $_REQUEST['txn_id'] ) ? $_REQUEST['txn_id'] : '';
3174 + break;
3175 + case 'paypal':
3176 + $trans_id = isset( $results['txn_id'] ) ? $results['txn_id'] : '';
3177 + break;
3178 + case 'paypal_ec':
3179 + $trans_id = isset( $_REQUEST['token'] ) ? $_REQUEST['token'] : '';
3180 + if ( isset( $results['settlement_id'] ) ) {
3181 + $usces->set_order_meta_value( 'settlement_id', $results['settlement_id'], $order_id );
3182 + }
3183 + if ( isset( $results['profile_id'] ) ) {
3184 + $usces->set_order_meta_value( 'profile_id', $results['profile_id'], $order_id );
3185 + }
3186 + break;
3187 + case 'remise_card':
3188 + $trans_id = isset( $_REQUEST['X-TRANID'] ) ? $_REQUEST['X-TRANID'] : '';
3189 + break;
3190 + case 'remise_conv':
3191 + $trans_id = isset( $_REQUEST['X-JOB_ID'] ) ? $_REQUEST['X-JOB_ID'] : '';
3192 + break;
3193 + case 'jpayment_card':
3194 + case 'jpayment_conv':
3195 + case 'jpayment_bank':
3196 + $trans_id = isset( $_REQUEST['gid'] ) ? $_REQUEST['gid'] : '';
3197 + break;
3198 + case 'telecom_card':
3199 + $trans_id = isset( $_REQUEST['sendid'] ) ? $_REQUEST['sendid'] : '';
3200 + break;
3201 + case 'digitalcheck_card':
3202 + case 'digitalcheck_conv':
3203 + $trans_id = isset( $_REQUEST['SID'] ) ? $_REQUEST['SID'] : '';
3204 + break;
3205 + case 'mizuho_card':
3206 + case 'mizuho_conv':
3207 + $trans_id = isset( $_REQUEST['stran'] ) ? $_REQUEST['stran'] : '';
3208 + break;
3209 + default:
3210 + if ( isset( $_REQUEST['FUKA'] ) && strstr( $_REQUEST['FUKA'], 'digitalcheck_card' ) ) {
3211 + $trans_id = isset( $_REQUEST['SID'] ) ? $_REQUEST['SID'] : '';
3212 + } else {
3213 + $trans_id = '';
3214 + }
3215 + }
3216 +
3217 + if ( ! empty( $trans_id ) ) {
3218 + $usces->set_order_meta_value( 'trans_id', $trans_id, $order_id );
3219 + }
3220 + }
3221 +}
3222 +
3223 +function usces_paypal_doecp( &$results ) {
3224 + global $usces;
3225 +
3226 + $entry = $usces->cart->get_entry();
3227 + $cart = $usces->cart->get_cart();
3228 +
3229 + $post_id = $cart[0]['post_id'];
3230 + $charging_type = $usces->getItemChargingType( $post_id );
3231 + if ( 'continue' !== $charging_type ) {
3232 + //通常購入.
3233 + //Format the other parameters that were stored in the session from the previous calls.
3234 + $token = urlencode( $_REQUEST['token'] );
3235 + $paymentType = apply_filters( 'usces_filter_paypal_ec_paymentaction', 'Sale' );
3236 + $currencyCodeType = urlencode( $usces->get_currency_code() );
3237 + $payerID = urlencode( $_REQUEST['PayerID'] );
3238 + $serverName = urlencode( $_SERVER['SERVER_NAME'] );
3239 + $nvpstr = '&TOKEN=' . $token . '&PAYERID=' . $payerID . '&PAYMENTREQUEST_0_PAYMENTACTION=' . $paymentType . '&PAYMENTREQUEST_0_CURRENCYCODE=' . $currencyCodeType . '&IPADDRESS=' . $serverName;
3240 + $item_total_price = 0;
3241 + $i = 0;
3242 + foreach ( $cart as $cart_row ) {
3243 + $nvpstr .=
3244 + '&L_PAYMENTREQUEST_0_NAME' . $i . '=' . urlencode( $usces->getItemName( $cart_row['post_id'] ) ) .
3245 + '&L_PAYMENTREQUEST_0_AMT' . $i . '=' . usces_crform( $cart_row['price'], false, false, 'return', false ) .
3246 + '&L_PAYMENTREQUEST_0_NUMBER' . $i . '=' . urlencode( $usces->getItemCode( $cart_row['post_id'] ) ) . ' ' . $cart_row['sku'] .
3247 + '&L_PAYMENTREQUEST_0_QTY' . $i . '=' . $cart_row['quantity'];
3248 + $options = ( ! empty( $cart_row['options'] ) ) ? $cart_row['options'] : array();
3249 + if ( is_array( $options ) && count( $options ) > 0 ) {
3250 + $optstr = '';
3251 + foreach ( $options as $key => $value ) {
3252 + if ( ! empty( $key ) ) {
3253 + $key = urldecode( $key );
3254 + $value = wel_safe_maybe_unserialize( $value );
3255 + if ( is_array( $value ) ) {
3256 + $c = '';
3257 + $optstr .= $key . ' : ';
3258 + foreach ( $value as $v ) {
3259 + $optstr .= $c.urldecode( $v );
3260 + $c = ', ';
3261 + }
3262 + $optstr .= "\r\n";
3263 + } else {
3264 + $optstr .= $key . ' : ' . urldecode( $value ) . "\r\n";
3265 + }
3266 + }
3267 + }
3268 + if ( '' !== $optstr ) {
3269 + if ( 60 < mb_strlen( $optstr, 'UTF-8' ) ) {
3270 + $optstr = mb_substr( $optstr, 0, 60, 'UTF-8' ) . '...';
3271 + }
3272 + $nvpstr .= '&L_PAYMENTREQUEST_0_DESC' . $i . '=' . urlencode( $optstr );
3273 + }
3274 + }
3275 + $item_total_price += ( $cart_row['price'] * $cart_row['quantity'] );
3276 + $i++;
3277 + }
3278 + if ( ! empty( $entry['order']['discount'] ) ) {
3279 + $nvpstr .=
3280 + '&L_PAYMENTREQUEST_0_NAME' . $i . '=' . urlencode( __( 'Campaign discount', 'usces' ) ) .
3281 + '&L_PAYMENTREQUEST_0_AMT' . $i . '=' . usces_crform( $entry['order']['discount'], false, false, 'return', false );
3282 + $item_total_price += $entry['order']['discount'];
3283 + $i++;
3284 + }
3285 + if ( ! empty( $entry['order']['usedpoint'] ) ) {
3286 + $nvpstr .=
3287 + '&L_PAYMENTREQUEST_0_NAME' . $i . '=' . urlencode( __( 'Used points', 'usces' ) ) .
3288 + '&L_PAYMENTREQUEST_0_AMT' . $i . '=' . usces_crform( $entry['order']['usedpoint'] * (-1), false, false, 'return', false );
3289 + $item_total_price -= $entry['order']['usedpoint'];
3290 + $i++;
3291 + }
3292 + $nvpstr .=
3293 + '&PAYMENTREQUEST_0_ITEMAMT=' . usces_crform( $item_total_price, false, false, 'return', false ) .
3294 + '&PAYMENTREQUEST_0_SHIPPINGAMT=' . usces_crform( $entry['order']['shipping_charge'], false, false, 'return', false ) .
3295 + '&PAYMENTREQUEST_0_AMT=' . usces_crform( $entry['order']['total_full_price'], false, false, 'return', false ) ;
3296 + if ( ! empty( $entry['order']['cod_fee'] ) ) {
3297 + $nvpstr .= '&PAYMENTREQUEST_0_HANDLINGAMT=' . usces_crform( $entry['order']['cod_fee'], false, false, 'return', false );
3298 + }
3299 + if ( ! empty( $entry['order']['tax'] ) ) {
3300 + $nvpstr .= '&PAYMENTREQUEST_0_TAXAMT=' . usces_crform( $entry['order']['tax'], false, false, 'return', false );
3301 + }
3302 + $nvpstr .= '&PAYMENTREQUEST_0_AMT=' . usces_crform( $entry['order']['total_full_price'], false, false, 'return', false );
3303 + $nvpstr = apply_filters( 'usces_filter_usces_paypal_doecp', $nvpstr, $charging_type );
3304 + if ( 'shipped' === $usces->getItemDivision( $post_id ) ) {
3305 + $name = urlencode( $entry['delivery']['name2'] . ' ' . $entry['delivery']['name1'] );
3306 + $address2 = urlencode( $entry['delivery']['address2'] );
3307 + $address3 = urlencode( $entry['delivery']['address3'] );
3308 + $address1 = urlencode( $entry['delivery']['address1'] );
3309 + $pref = urlencode( $entry['delivery']['pref'] );
3310 + $country = ( ! empty( $entry['delivery']['country'] ) ) ? $entry['delivery']['country'] : usces_get_base_country();
3311 + $country_code = apply_filters( 'usces_filter_paypalec_shiptocountrycode', $country );
3312 + if ( 'TW' === $country_code ) {
3313 + $city = $address1;
3314 + $address1 = $pref;
3315 + $pref = $city;
3316 + }
3317 + $zip = $entry['delivery']['zipcode'];
3318 + $tel = ltrim( str_replace( '-', '', $entry['delivery']['tel'] ), '0' );
3319 + if ( 'US' !== $country_code && 'CA' !== $country_code ) {
3320 + $nvpstr .=
3321 + '&PAYMENTREQUEST_0_SHIPTONAME=' . $name .
3322 + '&PAYMENTREQUEST_0_SHIPTOSTREET=' . $address2 .
3323 + '&PAYMENTREQUEST_0_SHIPTOSTREET2=' . $address3 .
3324 + '&PAYMENTREQUEST_0_SHIPTOCITY=' . $address1 .
3325 + '&PAYMENTREQUEST_0_SHIPTOSTATE=' . $pref .
3326 + '&PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE=' . $country_code .
3327 + '&PAYMENTREQUEST_0_SHIPTOZIP=' . $zip .
3328 + '&PAYMENTREQUEST_0_SHIPTOPHONENUM=' . $tel;
3329 + }
3330 + }
3331 + $usces->paypal->setMethod( 'DoExpressCheckoutPayment' );
3332 + $usces->paypal->setData( $nvpstr );
3333 + $res = $usces->paypal->doExpressCheckout();
3334 + $resArray = $usces->paypal->getResponse();
3335 + $ack = strtoupper( $resArray['ACK'] );
3336 + if ( 'SUCCESS' === $ack || 'SUCCESSWITHWARNING' === $ack ) {
3337 + $transactionId = $resArray['PAYMENTINFO_0_TRANSACTIONID']; // ' Unique transaction ID of the payment. Note: If the PaymentAction of the request was Authorization or Order, this value is your AuthorizationID for use with the Authorization & Capture APIs.
3338 + $results['settlement_id'] = $transactionId;
3339 + $results['payment_status'] = isset( $resArray['PAYMENTINFO_0_PAYMENTSTATUS'] ) ? $resArray['PAYMENTINFO_0_PAYMENTSTATUS'] : '';
3340 + $results['pending_reason'] = isset( $resArray['PAYMENTINFO_0_PENDINGREASON'] ) ? $resArray['PAYMENTINFO_0_PENDINGREASON'] : '';
3341 +
3342 + } else {
3343 + //Display a user friendly Error on the page using any of the following error information returned by PayPal.
3344 + $ErrorCode = urldecode( $resArray['L_ERRORCODE0'] );
3345 + $ErrorShortMsg = urldecode( $resArray['L_SHORTMESSAGE0'] );
3346 + $ErrorLongMsg = urldecode( $resArray['L_LONGMESSAGE0'] );
3347 + $ErrorSeverityCode = urldecode( $resArray['L_SEVERITYCODE0'] );
3348 + usces_log( 'PayPal : DoExpressCheckoutPayment API call failed. Error Code:[' . $ErrorCode . '] Error Severity Code:[' . $ErrorSeverityCode . '] Short Error Message:' . $ErrorShortMsg . ' Detailed Error Message:' . $ErrorLongMsg, 'acting_transaction.log' );
3349 + if ( '10486' === $ErrorCode ) {
3350 + $options = get_option( 'usces', array() );
3351 + $acting_opts = $options['acting_settings']['paypal'];
3352 + $query = http_build_query( $_REQUEST );
3353 + $payPalURL = $acting_opts['paypal_url'] . '?cmd=_express-checkout&' . $query;
3354 + header( 'Location: ' . $payPalURL );
3355 + exit;
3356 + }
3357 + $log = array(
3358 + 'acting' => 'paypal_ec',
3359 + 'key' => '(empty key)',
3360 + 'result' => $ack,
3361 + 'data' => $resArray,
3362 + );
3363 + usces_save_order_acting_error( $log );
3364 + return false;
3365 + }
3366 +
3367 + } else {
3368 + if ( ! apply_filters( 'usces_pre_create_recurring_payments_profile', true ) ) {
3369 + return false;
3370 + }
3371 +
3372 + //定期支払い.
3373 + $paymentAmount = usces_crform( $entry['order']['total_full_price'], false, false, 'return', false );
3374 + $token = urlencode( $_REQUEST['token'] );
3375 + $currencyCodeType = urlencode( $usces->get_currency_code() );
3376 + $profileStartDate = date( 'Y-m-d', dlseller_first_charging( $post_id, 'time' ) ) . 'T01:01:01Z';
3377 + $billingPeriod = 'Month';// or "Day", "Week", "SemiMonth", "Year".
3378 + $billingFreq = $usces->getItemFrequency( $post_id );
3379 + $desc = urlencode( usces_make_agreement_description( $cart, $entry['order']['total_full_price'] ) );
3380 + $totalBillingCycles = ( empty( $dlitem['dlseller_interval'] ) ) ? '' : '&TOTALBILLINGCYCLES=' . urlencode( $dlitem['dlseller_interval'] );
3381 +
3382 + $nvpstr = '&TOKEN=' . $token . '&AMT=' . $paymentAmount . '&CURRENCYCODE=' . $currencyCodeType . '&PROFILESTARTDATE=' . $profileStartDate . '&BILLINGPERIOD=' . $billingPeriod . '&BILLINGFREQUENCY=' . $billingFreq . '&DESC=' . $desc . $totalBillingCycles;
3383 + $nvpstr = apply_filters( 'usces_filter_usces_paypal_doecp', $nvpstr, $charging_type );
3384 +
3385 + $usces->paypal->setMethod( 'CreateRecurringPaymentsProfile' );
3386 + $usces->paypal->setData( $nvpstr );
3387 + $res = $usces->paypal->doExpressCheckout();
3388 + $resArray = $usces->paypal->getResponse();
3389 + $ack = strtoupper( $resArray['ACK'] );
3390 + if ( 'SUCCESS' === $ack || 'SUCCESSWITHWARNING' === $ack ) {
3391 + $profileid = $resArray['PROFILEID'];
3392 + $results['settlement_id'] = $profileid;
3393 + $results['profile_id'] = $profileid;
3394 + $results['profile_status'] = isset( $resArray['PROFILESTATUS'] ) ? $resArray['PROFILESTATUS'] : '';
3395 +
3396 + } else {
3397 + //Display a user friendly Error on the page using any of the following error information returned by PayPal.
3398 + $ErrorCode = urldecode( $resArray['L_ERRORCODE0'] );
3399 + $ErrorShortMsg = urldecode( $resArray['L_SHORTMESSAGE0'] );
3400 + $ErrorLongMsg = urldecode( $resArray['L_LONGMESSAGE0'] );
3401 + $ErrorSeverityCode = urldecode( $resArray['L_SEVERITYCODE0'] );
3402 + usces_log( 'PayPal : CreateRecurringPaymentsProfile API call failed. Error Code:[' . $ErrorCode . '] Error Severity Code:[' . $ErrorSeverityCode . '] Short Error Message:' . $ErrorShortMsg .' Detailed Error Message:' . $ErrorLongMsg, 'acting_transaction.log' );
3403 + $log = array(
3404 + 'acting' => 'paypal_ec',
3405 + 'key' => '(empty key)',
3406 + 'result' => $ack,
3407 + 'data' => $resArray,
3408 + );
3409 + usces_save_order_acting_error( $log );
3410 + return false;
3411 + }
3412 + }
3413 +
3414 + return true;
3415 +}
3416 +
3417 +function usces_make_agreement_description( $cart, $amt ) {
3418 + global $usces;
3419 +
3420 + $cart_row = $cart[0];
3421 + $quantity = $cart_row['quantity'];
3422 + $itemName = $usces->getItemName( $cart_row['post_id'] );
3423 + if ( 50 < mb_strlen( $itemName, 'UTF-8' ) ) {
3424 + $itemName = mb_substr( $itemName, 0, 50, 'UTF-8' ) . '...';
3425 + }
3426 + $amt = usces_crform( $amt, true, false, 'return', true );
3427 + $desc = $itemName . ' ' . __( 'Quantity', 'usces' ) . ':' . $quantity . ' ' . $amt;
3428 + return( $desc );
3429 +}
3430 +
3431 +function usces_get_send_out_date() {
3432 + global $usces;
3433 +
3434 + $bus_day_arr = ( isset( $usces->options['business_days'] ) ) ? $usces->options['business_days'] : false;
3435 + $bus_day_arr = apply_filters( 'usces_filter_business_days_bus_day_arr', $bus_day_arr );
3436 +
3437 + list( $today_year, $today_month, $today_day, $hour, $minute, $second ) = preg_split( '([^0-9])', current_time( 'mysql' ) );
3438 + if ( ! is_array( $bus_day_arr ) ) {
3439 + $today_bus_flag = 1;
3440 + } else {
3441 + $today_bus_flag = isset( $bus_day_arr[ (int) $today_year ][ (int) $today_month ][ (int) $today_day ] ) ? (int) $bus_day_arr[ (int) $today_year ][ (int) $today_month ][ (int) $today_day ] : 1;
3442 + }
3443 + // get the time limit addition.
3444 + $limit_hour = ( ! empty( $usces->options['delivery_time_limit']['hour'] ) ) ? $usces->options['delivery_time_limit']['hour'] : false;
3445 + $limit_min = ( ! empty( $usces->options['delivery_time_limit']['min'] ) ) ? $usces->options['delivery_time_limit']['min'] : false;
3446 +
3447 + if ( false === $hour || false === $minute ) {
3448 + $time_limit_addition = false;
3449 + } elseif ( ( $hour . ':' . $minute . ':' . $second ) > ( $limit_hour . ':' . $limit_min . ':00' ) ) {
3450 + $time_limit_addition = 1;
3451 + } else {
3452 + $time_limit_addition = 0;
3453 + }
3454 + // get the shipping indication in cart.
3455 + $cart = $usces->cart->get_cart();
3456 + $shipping_indication = apply_filters( 'usces_filter_shipping_indication', $usces->options['usces_shipping_indication'] );
3457 + $shipping = 0;
3458 + $indication_flag = true;
3459 + $cart_count = ( $cart && is_array( $cart ) ) ? count( $cart ) : 0;
3460 + $shipping_rule_ex = apply_filters( 'usces_filter_item_shipping_rule_ex', 9 );
3461 + for ( $i = 0; $i < $cart_count; $i++ ) {
3462 + $cart_row = $cart[ $i ];
3463 + $post_id = $cart_row['post_id'];
3464 + $itemShipping = (int) $usces->getItemShipping( $post_id );
3465 + if ( 0 === $itemShipping || $shipping_rule_ex === $itemShipping ) {
3466 + $indication_flag = false;
3467 + break;
3468 + }
3469 + if ( $shipping < $itemShipping ) {
3470 + $shipping = $itemShipping;
3471 + }
3472 + }
3473 + $indication_incart = ( $indication_flag ) ? $shipping_indication[ $shipping ] : false;
3474 + $indication_incart = apply_filters( 'usces_filter_indication_incart', $indication_incart, $shipping_indication, $shipping, $cart );
3475 + // get the send out date.
3476 + $sendout_num = 0;
3477 + if ( $today_bus_flag ) {
3478 + if ( $time_limit_addition ) {
3479 + $sendout_num += 1;
3480 + }
3481 + if ( false !== $indication_incart ) {
3482 + $sendout_num += $indication_incart;
3483 + }
3484 + } else {
3485 + if ( false !== $indication_incart ) {
3486 + $sendout_num += $indication_incart;
3487 + }
3488 + }
3489 + $holiday = 0;
3490 + for ( $i = 0; $i <= $sendout_num; $i++ ) {
3491 + list( $yyyy, $mm, $dd ) = explode( '-', date( 'Y-m-d', mktime( 0, 0, 0, (int) $today_month, ( $today_day + $i ), (int) $today_year ) ) );
3492 + if ( isset( $bus_day_arr[ (int) $yyyy ][ (int) $mm ][ (int) $dd ] ) && ! $bus_day_arr[ (int) $yyyy ][ (int) $mm ][ (int) $dd ] ) {
3493 + $holiday++;
3494 + $sendout_num++;
3495 + }
3496 + if ( 100 < $sendout_num ) {
3497 + break;
3498 + }
3499 + }
3500 + list( $send_y, $send_m, $send_d ) = explode( '-', date( 'Y-m-d', mktime( 0, 0, 0, (int) $today_month, ( $today_day + $sendout_num ), (int) $today_year ) ) );
3501 +
3502 + $res = array(
3503 + 'today_bus_flag' => $today_bus_flag,
3504 + 'time_limit_addition' => $time_limit_addition,
3505 + 'indication_incart' => $indication_incart,
3506 + 'holiday' => $holiday,
3507 + 'sendout_num' => $sendout_num,
3508 + 'sendout_date' => array(
3509 + 'year' => $send_y,
3510 + 'month' => $send_m,
3511 + 'day' => $send_d,
3512 + ),
3513 + );
3514 + return $res;
3515 +}
3516 +
3517 +function usces_action_footer_comment() {
3518 + echo "<!-- Welcart version : v" . USCES_VERSION . " -->\n";
3519 +}
3520 +
3521 +function usces_set_acting_notification_time( $key ) {
3522 + global $wpdb;
3523 +
3524 + $tableName = $wpdb->prefix . 'usces_access';
3525 + $query = $wpdb->prepare( "SELECT ID FROM $tableName WHERE acc_type = %s AND acc_key = %s", 'notification_time', $key );
3526 + $res = $wpdb->get_var( $query );
3527 + if ( $res ) {
3528 + return;
3529 + }
3530 +
3531 + $query = $wpdb->prepare( "INSERT INTO $tableName (acc_key, acc_type, acc_num1) VALUES (%s, %s, %d)",
3532 + $key, 'notification_time', time()
3533 + );
3534 + $res = $wpdb->query( $query );
3535 +}
3536 +
3537 +function usces_check_notification_time( $key, $time ) {
3538 + global $wpdb;
3539 +
3540 + $tableName = $wpdb->prefix . 'usces_access';
3541 + $query = $wpdb->prepare( "SELECT acc_num1 FROM $tableName WHERE acc_type = %s AND acc_key = %s", 'notification_time', $key );
3542 + $res = $wpdb->get_var( $query );
3543 + if ( ! $res ) {
3544 + return false;
3545 + }
3546 +
3547 + $past = time() - $res;
3548 + if ( $time > $past ) {
3549 + return true;
3550 + } else {
3551 + return false;
3552 + }
3553 +}
3554 +
3555 +function usces_is_same_itemcode( $post_id, $item_code ) {
3556 + global $wpdb, $usces;
3557 +
3558 + $item_table = usces_get_tablename( 'usces_item' );
3559 +
3560 + $res = $wpdb->get_col(
3561 + $wpdb->prepare(
3562 + "SELECT `post_id` FROM {$item_table}
3563 + LEFT JOIN {$wpdb->posts} ON `ID` = `post_id`
3564 + WHERE `itemCode` = %s AND `post_id` <> %d
3565 + AND `post_status` IN ('pending', 'publish', 'draft', 'private', 'future')",
3566 + $item_code,
3567 + $post_id
3568 + )
3569 + );
3570 +
3571 + if ( ! $res ) {
3572 + return false;
3573 + } else {
3574 + return $res;
3575 + }
3576 +}
3577 +
3578 +function usces_update_sku( $post_id, $sku_code, $fieldname, $value ) {
3579 +
3580 + $sku = wel_get_sku( $post_id, $sku_code, false );
3581 +
3582 + $sku[ $fieldname ] = $value;
3583 + $meta_id = $sku['meta_id'];
3584 +
3585 + $res = wel_update_sku_data_by_id( $meta_id, $post_id, $sku );
3586 +
3587 + if ( ! $res ) {
3588 + return false;
3589 + } else {
3590 + return true;
3591 + }
3592 +}
3593 +
3594 +function usces_get_non_zerostoc_items() {
3595 + global $wpdb, $usces;
3596 +
3597 + $item_table = usces_get_tablename( 'usces_item' );
3598 + $skus_table = usces_get_tablename( 'usces_skus' );
3599 +
3600 + $res = $wpdb->get_results(
3601 + $wpdb->prepare(
3602 + "SELECT `ID`, `itemCode` AS `code`, `itemName` AS `name` FROM {$wpdb->posts} AS `post`
3603 + LEFT JOIN {$item_table} AS `item` ON `ID` = item.post_id
3604 + LEFT JOIN {$skus_table} AS `sku` ON `ID` = sku.post_id
3605 + WHERE post_mime_type = %s AND post_type = %s AND post_status <> %s AND sku.stocknum = %s
3606 + GROUP BY ID",
3607 + 'item',
3608 + 'post',
3609 + 'trash',
3610 + '0'
3611 + ),
3612 + ARRAY_A
3613 + );
3614 +
3615 + return $res;
3616 +}
3617 +
3618 +function usces_get_stocs() {
3619 + global $wpdb, $usces;
3620 +
3621 + $status = array();
3622 + $sku_table = $wpdb->prefix . 'usces_skus';
3623 +
3624 + $stocks = $wpdb->get_col(
3625 + $wpdb->prepare(
3626 + "SELECT stock FROM {$wpdb->posts} LEFT JOIN {$sku_table} ON ID = post_id
3627 + WHERE post_mime_type = %s AND post_type = %s AND post_status <> %s",
3628 + 'item',
3629 + 'post',
3630 + 'trash'
3631 + )
3632 + );
3633 +
3634 + if ( ! $stocks ) {
3635 + return $status;
3636 + }
3637 +
3638 + foreach ( (array) $stocks as $value ) {
3639 + $status[] = (string) $value;
3640 + }
3641 +
3642 + return array_count_values( $status );
3643 +}
3644 +
3645 +function usces_get_deco_order_id( $order_id ) {
3646 + global $usces;
3647 +
3648 + $dec_order_id = $usces->get_order_meta_value( 'dec_order_id', $order_id );
3649 + if ( ! $dec_order_id ) {
3650 +
3651 + $options = get_option( 'usces', array() );
3652 + $prefix = $options['system']['dec_orderID_prefix'];
3653 + $prefix = apply_filters( 'usces_filter_get_deco_order_id_prefix', $prefix );
3654 +
3655 + $dec_order_id = $prefix . usces_make_deco_order_id( $order_id );
3656 + }
3657 +
3658 + return $dec_order_id;
3659 +}
3660 +
3661 +function usces_make_deco_order_id( $order_id = null ) {
3662 + global $wpdb;
3663 +
3664 + $options = get_option( 'usces', array() );
3665 +
3666 + if ( 0 === (int) $options['system']['dec_orderID_flag'] ) {
3667 +
3668 + if ( ! $order_id ) {
3669 + $dec_order_id = str_pad( 0, $options['system']['dec_orderID_digit'], '0', STR_PAD_LEFT );
3670 + } else {
3671 + $dec_order_id = str_pad( $order_id, $options['system']['dec_orderID_digit'], '0', STR_PAD_LEFT );
3672 + }
3673 +
3674 + } else {
3675 +
3676 + $order_meta = usces_get_tablename( 'usces_order_meta' );
3677 + $verify_time = apply_filters( 'usces_filter_deco_order_id_verify_time', 100 );
3678 +
3679 + for ( $olimit = 0; $olimit <= $verify_time; $olimit++ ) {
3680 +
3681 + $ukey = usces_get_key( $options['system']['dec_orderID_digit'] );
3682 + $ores = $wpdb->get_var(
3683 + $wpdb->prepare(
3684 + "SELECT meta_key FROM {$order_meta} WHERE meta_key = %s AND meta_value = %s LIMIT 1",
3685 + 'dec_order_id',
3686 + $ukey
3687 + )
3688 + );
3689 +
3690 + if ( ! $ores ) {
3691 + break;
3692 + }
3693 + }
3694 +
3695 + $dec_order_id = $ukey;
3696 + }
3697 +
3698 + $dec_order_id = apply_filters( 'usces_filter_make_deco_order_id', $dec_order_id );
3699 +
3700 + return $dec_order_id;
3701 +}
3702 +
3703 +function usces_get_gp_price( $post_id, $p, $quant ) {
3704 + global $usces;
3705 +
3706 + $GpN1 = $usces->getItemGpNum1( $post_id );
3707 + $GpN2 = $usces->getItemGpNum2( $post_id );
3708 + $GpN3 = $usces->getItemGpNum3( $post_id );
3709 + $GpD1 = $usces->getItemGpDis1( $post_id );
3710 + $GpD2 = $usces->getItemGpDis2( $post_id );
3711 + $GpD3 = $usces->getItemGpDis3( $post_id );
3712 +
3713 + if ( empty( $GpN1 ) || empty( $GpD1 ) ) {
3714 +
3715 + $realprice = $p;
3716 +
3717 + } elseif ( ( ! empty( $GpN1 ) && ! empty( $GpD1 ) ) && ( empty( $GpN2 ) || empty( $GpD2 ) ) ) {
3718 +
3719 + if ( $quant >= $GpN1 ) {
3720 + $realprice = wel_gp_price_discount( $p, $GpD1 );
3721 + } else {
3722 + $realprice = $p;
3723 + }
3724 +
3725 + } elseif ( ( ! empty( $GpN1 ) && ! empty( $GpD1 ) ) && ( ! empty( $GpN2 ) && ! empty( $GpD2 ) ) && ( empty( $GpN3 ) || empty( $GpD3 ) ) ) {
3726 +
3727 + if ( $quant >= $GpN2 ) {
3728 + $realprice = wel_gp_price_discount( $p, $GpD2 );
3729 + } elseif ( $quant >= $GpN1 && $quant < $GpN2 ) {
3730 + $realprice = wel_gp_price_discount( $p, $GpD1 );
3731 + } else {
3732 + $realprice = $p;
3733 + }
3734 +
3735 + } elseif ( ( ! empty( $GpN1 ) && ! empty( $GpD1 ) ) && ( ! empty( $GpN2 ) && ! empty( $GpD2 ) ) && ( ! empty( $GpN3 ) && ! empty( $GpD3 ) ) ) {
3736 +
3737 + if ( $quant >= $GpN3 ) {
3738 + $realprice = wel_gp_price_discount( $p, $GpD3 );
3739 + } elseif ( $quant >= $GpN2 && $quant < $GpN3 ) {
3740 + $realprice = wel_gp_price_discount( $p, $GpD2 );
3741 + } elseif ( $quant >= $GpN1 && $quant < $GpN2 ) {
3742 + $realprice = wel_gp_price_discount( $p, $GpD1 );
3743 + } else {
3744 + $realprice = $p;
3745 + }
3746 +
3747 + } else {
3748 + $realprice = $p;
3749 + }
3750 +
3751 + $realprice = apply_filters( 'usces_filter_get_gp_price', $realprice, $post_id, $p, $quant );
3752 + return $realprice;
3753 +}
3754 +
3755 +function usces_is_complete_settlement( $payment_name, $status = '' ) {
3756 + $complete = false;
3757 + $options = get_option( 'usces', array() );
3758 + if ( 0 === (int) $options['point_assign'] ) {
3759 + $complete = true;
3760 + } else {
3761 + $payments = usces_get_system_option( 'usces_payment_method', 'name' );
3762 + if ( isset( $payments[ $payment_name ]['settlement'] ) ) {
3763 + switch( $payments[ $payment_name ]['settlement'] ) {
3764 + case 'acting':
3765 + if ( false !== strpos( $status, 'pending' ) ) {
3766 + break;
3767 + }
3768 + case 'acting_remise_card':
3769 + case 'acting_jpayment_card':
3770 + case 'acting_paypal_ec':
3771 + case 'acting_telecom_card':
3772 + case 'acting_digitalcheck_card':
3773 + case 'acting_mizuho_card':
3774 + case 'acting_anotherlane_card':
3775 + case 'acting_veritrans_card':
3776 + case 'COD':
3777 + $complete = true;
3778 + }
3779 + }
3780 + }
3781 + $complete = apply_filters( 'usces_filter_is_complete_settlement', $complete, $payment_name, $status );
3782 + return $complete;
3783 +}
3784 +
3785 +function usces_action_acting_getpoint( $order_id, $add = true ) {
3786 + global $usces, $wpdb;
3787 +
3788 + if ( ! apply_filters( 'usces_action_acting_getpoint_switch', true, $order_id, $add ) ) {
3789 + return;
3790 + }
3791 +
3792 + $options = get_option( 'usces', array() );
3793 + if ( 0 !== (int) $options['point_assign'] ) {
3794 + if ( 'activate' === $usces->options['membersystem_state'] && 'activate' === $usces->options['membersystem_point'] ) {
3795 + $table_name = $wpdb->prefix . 'usces_order';
3796 + $mquery = $wpdb->prepare( "SELECT mem_id, order_getpoint FROM $table_name WHERE ID = %d", $order_id );
3797 + $values = $wpdb->get_row( $mquery, ARRAY_A );
3798 + $mem_id = $values['mem_id'];
3799 + $getpoint = $values['order_getpoint'];
3800 +
3801 + if ( ! empty( $mem_id ) && 0 < $getpoint ) {
3802 + $calc = ( $add ) ? '+' : '-';
3803 + $member_table_name = usces_get_tablename( 'usces_member' );
3804 + $mquery = $wpdb->prepare( "UPDATE $member_table_name SET mem_point = (mem_point ".$calc." %d) WHERE ID = %d", $getpoint, $mem_id );
3805 + $wpdb->query( $mquery );
3806 +
3807 + if ( ! empty( $_SESSION['usces_member']['point'] ) ) {
3808 + $mquery = $wpdb->prepare( "SELECT mem_point FROM $member_table_name WHERE ID = %d", $mem_id );
3809 + $point = $wpdb->get_var( $mquery );
3810 + $_SESSION['usces_member']['point'] = $point;
3811 + }
3812 + }
3813 + }
3814 + }
3815 + do_action( 'usces_action_acting_getpoint', $order_id, $add );
3816 +}
3817 +
3818 +function usces_restore_point( $mem_id, $point ) {
3819 + global $wpdb;
3820 +
3821 + if ( ! apply_filters( 'usces_action_restore_point_switch', true, $mem_id, $point ) ) {
3822 + return;
3823 + }
3824 +
3825 + $member_table_name = usces_get_tablename( 'usces_member' );
3826 + $query = $wpdb->prepare( "UPDATE $member_table_name SET mem_point = (mem_point - %d) WHERE ID = %d", $point, $mem_id );
3827 + $wpdb->query( $query );
3828 +}
3829 +
3830 +function usces_set_free_csv( $customer ) {
3831 + $free_csv = "";
3832 + if ( ! WCUtils::is_blank( $customer['name1'] ) ) {
3833 + $free_csv = "LAST_NAME=" . mb_convert_encoding( $customer['name1'], 'SJIS', 'UTF-8' ) . ",FIRST_NAME=" . mb_convert_encoding( $customer['name2'], 'SJIS', 'UTF-8' ) . ",TEL=" . str_replace( "-", "", $customer['tel'] ) . ",MAIL=" . $customer['mailaddress1'];
3834 + $free_csv = base64_encode( $free_csv );
3835 + }
3836 + return $free_csv;
3837 +}
3838 +
3839 +function usces_get_itemopt_filed( $post_id, $sku, $opt ) {
3840 + global $usces;
3841 +
3842 + $sku = urlencode( $sku );
3843 + $optcode = urlencode( $opt['name'] );
3844 + $name = $opt['name'];
3845 + $means = (int) $opt['means'];
3846 + $essential = (int) $opt['essential'];
3847 + $session_value = isset( $_SESSION['usces_singleitem']['itemOption'][ $post_id ][ $sku ][ $optcode ] ) ? $_SESSION['usces_singleitem']['itemOption'][ $post_id ][ $sku ][ $optcode ] : NULL;
3848 + $opt['value'] = usces_change_line_break( $opt['value'] );
3849 +
3850 + $html = '';
3851 + switch ( $means ) {
3852 + case 0: //Single-select.
3853 + case 1: //Multi-select.
3854 + $selects = explode( "\n", $opt['value'] );
3855 + $multiple = ( 0 === $means ) ? '' : ' multiple';
3856 + $multiple_array = ( 0 === $means ) ? '' : '[]';
3857 + $html .= "\n<select name='itemOption[{$post_id}][{$sku}][{$optcode}]{$multiple_array}' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_select'{$multiple} onKeyDown=\"if (event.keyCode == 13) {return false;}\">\n";
3858 + if ( 1 === $essential ) {
3859 + if ( '#NONE#' === $session_value || NULL === $session_value ) {
3860 + $selected = ' selected="selected"';
3861 + } else {
3862 + $selected = '';
3863 + }
3864 + $html .= "\t<option value='#NONE#'{$selected}>" . __( 'Choose', 'usces' ) . "</option>\n";
3865 + }
3866 + $i = 0;
3867 + foreach ( $selects as $v ) {
3868 + if ( ( 0 === $i && 0 === $essential && NULL === $session_value ) || esc_attr( $v ) == $session_value ) {
3869 + $selected = ' selected="selected"';
3870 + } else {
3871 + $selected = '';
3872 + }
3873 + $html .= "\t<option value='" . esc_attr( $v ) . "'{$selected}>" . esc_html( $v ) . "</option>\n";
3874 + $i++;
3875 + }
3876 + $html .= "</select>\n";
3877 + break;
3878 + case 2: //Text.
3879 + $html .= "\n<input name='itemOption[{$post_id}][{$sku}][{$optcode}]' type='text' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_text' onKeyDown=\"if (event.keyCode == 13) {return false;}\" value=\"" . esc_attr( $session_value ) . "\" />\n";
3880 + break;
3881 + case 3: //Radio-button.
3882 + $selects = explode( "\n", $opt['value'] );
3883 + $i = 0;
3884 + foreach ( (array) $selects as $v ) {
3885 + $v = trim( $v );
3886 + if ( $v === $session_value ) {
3887 + $checked = ' checked="checked"';
3888 + } else {
3889 + $checked = '';
3890 + }
3891 + $html .= "\t<label for='itemOption[{$post_id}][{$sku}][{$optcode}]{$i}' class='iopt_radio_label'><input name='itemOption[{$post_id}][{$sku}][{$optcode}]' id='itemOption[{$post_id}][{$sku}][{$optcode}]{$i}' class='iopt_radio' type='radio' value='" . urlencode( $v ) . "'{$checked} onKeyDown=\"if (event.keyCode == 13) {return false;}\">" . esc_html( $v ) . "</label>\n";
3892 + $i++;
3893 + }
3894 + break;
3895 + case 4: //Check-box.
3896 + $selects = explode( "\n", $opt['value'] );
3897 + $session_arr = is_array( $session_value ) ? $session_value : array();
3898 + $i = 0;
3899 + foreach ( (array) $selects as $v ) {
3900 + $v = trim( $v );
3901 + if ( in_array( $v, $session_arr, true ) ) {
3902 + $checked = ' checked="checked"';
3903 + } else {
3904 + $checked = '';
3905 + }
3906 + $html .= "\t<label for='itemOption[{$post_id}][{$sku}][{$optcode}]{$i}' class='iopt_checkbox_label'><input name='itemOption[{$post_id}][{$sku}][{$optcode}][]' id='itemOption[{$post_id}][{$sku}][{$optcode}]{$i}' class='iopt_checkbox' type='checkbox' value='" . urlencode( $v ) . "'{$checked} onKeyDown=\"if (event.keyCode == 13) {return false;}\">" . esc_html( $v ) . "</label>\n";
3907 + $i++;
3908 + }
3909 + break;
3910 + case 5: //Text-area.
3911 + $html .= "\n<textarea name='itemOption[{$post_id}][{$sku}][{$optcode}]' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_textarea'>" . esc_attr( $session_value ) . "</textarea>\n";
3912 + break;
3913 + }
3914 +
3915 + $html = apply_filters( 'usces_get_itemopt_filed', $html, $post_id, $sku, $opt );
3916 +
3917 + return $html;
3918 +}
3919 +
3920 +function usces_delete_order_check( $order_id ) {
3921 + $res = apply_filters( 'usces_filter_delete_order_check', true, $order_id );
3922 + return $res;
3923 +}
3924 +
3925 +function usces_delete_member_check( $member_id ) {
3926 + $res = apply_filters( 'usces_filter_delete_member_check', true, $member_id );
3927 + return $res;
3928 +}
3929 +
3930 +function usces_delete_member_check_front( $member_id ) {
3931 + $res = apply_filters( 'usces_filter_delete_member_check_front', true, $member_id );
3932 + return $res;
3933 +}
3934 +
3935 +function usces_itempage_admin_bar() {
3936 + global $wp_admin_bar, $post;
3937 +
3938 + if ( is_single() && usces_is_item() ) {
3939 + $wp_admin_bar->remove_menu( 'edit' );
3940 + $ref = urlencode( site_url() . '/wp-admin/admin.php?page=usces_itemedit' );
3941 + $wp_admin_bar->add_menu( array(
3942 + 'id' => 'edit',
3943 + 'title' => __( 'Edit item', 'usces' ),
3944 + 'href' => site_url() . '/wp-admin/admin.php?page=usces_itemedit&action=edit&post=' . $post->ID . '&usces_referer=' . $ref
3945 + ) );
3946 + }
3947 +}
3948 +
3949 +function usces_rand( $digit = 10 ) {
3950 + $num = str_repeat( '9', $digit );
3951 + $rand = apply_filters( 'usces_filter_rand_value', sprintf( '%0' . $digit . 'd', mt_rand( 1, (int) $num ) ), $num );
3952 + return $rand;
3953 +}
3954 +
3955 +function usces_get_cr_symbol() {
3956 + global $usces, $usces_settings;
3957 + $cr = $usces->options['system']['currency'];
3958 + list( $code, $decimal, $point, $seperator, $symbol ) = $usces_settings['currency'][ $cr ];
3959 + return $symbol;
3960 +}
3961 +
3962 +function usces_make_option_field( $materials, $cart ) {
3963 + extract( $materials );
3964 + /* $materials = compact( 'i', 'cart_row', 'post_id', 'sku', 'sku_code', 'quantity',
3965 + 'options', 'advance', 'itemCode', 'itemName', 'cartItemName',
3966 + 'skuPrice', 'stock', 'red', 'pictid', 'order_id' );
3967 + */
3968 + $option_fields = usces_get_opts( $post_id, 'sort' );
3969 + $field = '<div>' . "\n";
3970 + $field .= '<ul>' . "\n";
3971 +
3972 + foreach ( (array) $option_fields as $field_data ) {
3973 + $field .= '<li>' . usces_get_itemOption( $field_data, $materials, $label = '#default#' ) . '</li>' . "\n";
3974 + foreach ( (array) $options as $op_key => $option ) {
3975 + if ( $option['meta_key'] === $field_data['name'] ) {
3976 + $options[ $op_key ]['flag'] = 1;
3977 + }
3978 + }
3979 + }
3980 +
3981 + foreach ( (array) $options as $option ) {
3982 + if ( ! isset( $option['flag'] ) ) {
3983 + $meta_value = wel_safe_maybe_unserialize( $option['meta_value'] );
3984 + if ( ! is_array( $meta_value ) ) {
3985 + $meta_value = (array) $meta_value;
3986 + }
3987 + $value_str = '';
3988 + foreach ( $meta_value as $mv ) {
3989 + $value_str .= $mv . ' & ';
3990 + }
3991 + $value_str = trim( $value_str, ' & ' );
3992 + $field .= '<li>' . esc_html( $option['meta_key'] ) . ' : ' . esc_html( $value_str ) . '</li>' . "\n";
3993 + }
3994 + }
3995 +
3996 + $field .= '</ul>' . "\n";
3997 + $field .= '</div>' . "\n";
3998 +
3999 + echo apply_filters( 'usces_filter_order_edit_form_row', $field, $cart, $materials );
4000 +}
4001 +
4002 +function usces_get_itemOption( $field_data, $materials, $label = '#default#' ) {
4003 + global $usces;
4004 +
4005 + extract( $materials );
4006 + /* $materials = compact( 'i', 'cart_row', 'post_id', 'sku', 'sku_code', 'quantity',
4007 + 'options', 'advance', 'itemCode', 'itemName', 'cartItemName',
4008 + 'skuPrice', 'stock', 'red', 'pictid', 'order_id' );
4009 + */
4010 + $opt_value = array();
4011 + foreach ( $options as $opt_value ) {
4012 + if ( $field_data['name'] === $opt_value['meta_key'] ) {
4013 + $cartmeta_id = $opt_value['cartmeta_id'];
4014 + $name = $opt_value['meta_key'];
4015 + $value = $opt_value['meta_value'];
4016 + $means = (int) $field_data['means'];
4017 + $essential = (int) $field_data['essential'];
4018 + break;
4019 + }
4020 + }
4021 + if ( ! $opt_value ) {
4022 + return '';
4023 + }
4024 + if ( empty( $name ) ) {
4025 + return '';
4026 + }
4027 +
4028 + if ( '#default#' === $label ) {
4029 + $label = $name;
4030 + }
4031 +
4032 + $field_data['value'] = usces_change_line_break( $field_data['value'] );
4033 +
4034 + $html = '';
4035 + $name = esc_attr( $name );
4036 + $label = esc_attr( $label );
4037 + $html .= '<label for="itemOption[' . $cartmeta_id . ']" class="iopt_label">' . $label . '</label>' . "\n";
4038 + switch ( $means ) {
4039 + case 0: //Single-select.
4040 + $selects = explode( "\n", $field_data['value'] );
4041 + $value = wel_safe_maybe_unserialize( $value );
4042 + $check_value = array();
4043 + if ( ! is_array( $value ) ) {
4044 + $check_value = (array) $value;
4045 + }
4046 + $diff = array_diff( $check_value, $selects );
4047 +
4048 + if ( ! empty( $diff ) ) {
4049 +
4050 + $value_str = '';
4051 + foreach ( $check_value as $mv ) {
4052 + $value_str .= $mv . ' & ';
4053 + }
4054 + $value_str = trim( $value_str, ' & ' );
4055 + $html .= '<span>:' . esc_html( $value_str ) . '</span>' . "\n";
4056 +
4057 + } else {
4058 + $html .= '<select name="itemOption[' . $cartmeta_id . ']" id="itemOption[' . $cartmeta_id . ']" class="iopt_select" onKeyDown="if (event.keyCode == 13) {return false;}">' . "\n";
4059 + if ( 1 === $essential ) {
4060 + if ( '#NONE#' === $value || NULL === $value ) {
4061 + $selected = ' selected="selected"';
4062 + } else {
4063 + $selected = '';
4064 + }
4065 + $html .= '<option value="#NONE#"' . $selected . '>' . __( 'Choose', 'usces' ) . '</option>' . "\n";
4066 + }
4067 + $i = 0;
4068 + foreach ( $selects as $v ) {
4069 + $v = trim( $v );
4070 + if ( ( 0 === $i && 0 === $essential && NULL === $value ) || esc_attr( $v ) == esc_attr( $value ) ) {
4071 + $selected = ' selected="selected"';
4072 + } else {
4073 + $selected = '';
4074 + }
4075 + $html .= '<option value="' . esc_attr( $v ) . '"' . $selected . '>' . esc_attr( $v ) . '</option>' . "\n";
4076 + $i++;
4077 + }
4078 + $html .= '</select>' . "\n";
4079 + }
4080 + break;
4081 + case 1: //Multi-select.
4082 + $selects = explode( "\n", $field_data['value'] );
4083 + $value = wel_safe_maybe_unserialize( $value );
4084 + if ( ! is_array( $value ) ) {
4085 + $value = (array) $value;
4086 + }
4087 + $diff = array_diff( (array) $value, $selects );
4088 +
4089 + if ( ! empty( $diff ) ) {
4090 +
4091 + $value_str = '';
4092 + foreach ( $value as $mv ) {
4093 + $value_str .= $mv . ' & ';
4094 + }
4095 + $value_str = trim( $value_str, ' & ' );
4096 + $html .= '<span>:' . esc_html( $value_str ) . '</span>' . "\n";
4097 +
4098 + } else {
4099 + $html .= '<select name="itemOption[' . $cartmeta_id . '][]" id="itemOption[' . $cartmeta_id . ']" class="iopt_select" multiple onKeyDown="if (event.keyCode == 13) {return false;}">' . "\n";
4100 + if ( 1 === $essential ) {
4101 + if ( '#NONE#' === $value || NULL === $value ) {
4102 + $selected = ' selected="selected"';
4103 + } else {
4104 + $selected = '';
4105 + }
4106 + $html .= '<option value="#NONE#"' . $selected . '>' . __( 'Choose', 'usces' ) . '</option>' . "\n";
4107 + }
4108 + $i = 0;
4109 +
4110 + $value_arr = wel_safe_maybe_unserialize( $value );
4111 +
4112 + foreach ( $selects as $v ) {
4113 + $v = trim( $v );
4114 + $opval = urlencode( $v );
4115 + $val_str = isset( $value_arr[ $opval ] ) ? $value_arr[ $opval ] : '';
4116 + if ( $v == $val_str ) {
4117 + $selected = ' selected="selected"';
4118 + } else {
4119 + $selected = '';
4120 + }
4121 + $html .= '<option value="' . esc_attr( $opval ) . '"' . $selected . '>' . esc_attr( $v ) . '</option>' . "\n";
4122 + $i++;
4123 + }
4124 + $html .= '</select>' . "\n";
4125 + }
4126 + break;
4127 + case 2: //Text.
4128 + $html .= '<input name="itemOption[' . $cartmeta_id . ']" type="text" id="itemOption[' . $cartmeta_id . ']" class="iopt_text" onKeyDown="if (event.keyCode == 13) {return false;}" value="' . esc_attr( $value ) . '" />' . "\n";
4129 + break;
4130 + case 3: //Radio-button.
4131 + $selects = explode( "\n", $field_data['value'] );
4132 + $value = wel_safe_maybe_unserialize( $value );
4133 + if ( ! is_array( $value ) ) {
4134 + $value = (array) $value;
4135 + }
4136 + $diff = array_diff( $value, $selects );
4137 +
4138 + if ( ! empty( $diff ) && ! empty( $diff[0] ) ) {
4139 +
4140 + $value_str = '';
4141 + foreach ( $value as $mv ) {
4142 + $value_str .= $mv . ' & ';
4143 + }
4144 + $value_str = trim( $value_str, ' & ' );
4145 + $html .= '<span>:' . esc_html( $value_str ) . '</span>' . "\n";
4146 +
4147 + } else {
4148 + $i = 0;
4149 + foreach ( $selects as $v ) {
4150 + $v = trim( $v );
4151 + $checked = '';
4152 + foreach ( $value as $ov ) {
4153 + if ( $v == $ov ) {
4154 + $checked = ' checked="checked"';
4155 + break;
4156 + }
4157 + }
4158 + $html .= '<label for="itemOption[' . $cartmeta_id . ']' . $i . '" class="iopt_radio_label"><input name="itemOption[' . $cartmeta_id . ']" id="itemOption[' . $cartmeta_id . ']' . $i . '" class="iopt_radio" type="radio" value="' . urlencode( $v ) . '"' . $checked . ' onKeyDown="if (event.keyCode == 13) {return false;}">' . esc_html( $v ) . "</label>\n";
4159 + $i++;
4160 + }
4161 + }
4162 + break;
4163 + case 4: //Check-box.
4164 + $selects = explode( "\n", $field_data['value'] );
4165 + $value = wel_safe_maybe_unserialize( $value );
4166 + if ( ! is_array( $value ) ) {
4167 + $value = (array) $value;
4168 + }
4169 + $diff = array_diff( (array) $value, $selects );
4170 +
4171 + if ( isset( $diff[0] ) && ! empty( $diff[0] ) ) {
4172 +
4173 + $value_str = '';
4174 + foreach ( $value as $mv ) {
4175 + $value_str .= $mv . ' & ';
4176 + }
4177 + $value_str = trim( $value_str, ' & ' );
4178 + $html .= '<span>:' . esc_html( $value_str ) . '</span>' . "\n";
4179 +
4180 + } else {
4181 + $i = 0;
4182 + foreach ( $selects as $v ) {
4183 + $v = trim( $v );
4184 + $opval = urlencode( $v );
4185 + $val_str = isset( $value_arr[ $opval ] ) ? $value_arr[ $opval ] : '';
4186 + if ( in_array( $v, (array) $value ) ) {
4187 + $checked = ' checked="checked"';
4188 + } else {
4189 + $checked = '';
4190 + }
4191 + $html .= '<label for="itemOption[' . $cartmeta_id . ']' . $i . '" class="iopt_checkbox_label"><input name="itemOption[' . $cartmeta_id . '][]" id="itemOption[' . $cartmeta_id . ']' . $i . '" class="iopt_checkbox" type="checkbox" value="' . urlencode( $v ) . '"' . $checked . ' onKeyDown="if (event.keyCode == 13) {return false;}">' . esc_html( $v ) . "</label>\n";
4192 + $i++;
4193 + }
4194 + }
4195 + break;
4196 + case 5: //Text-area.
4197 + $html .= '<textarea name="itemOption[' . $cartmeta_id . ']" id="itemOption[' . $cartmeta_id . ']" class="iopt_textarea">' . esc_attr( $value ) . '</textarea>' . "\n";
4198 + break;
4199 + }
4200 +
4201 + $html = apply_filters( 'usces_filter_get_itemOption', $html, $opt_value, $post_id );
4202 +
4203 + return $html;
4204 +}
4205 +
4206 +function usces_update_ordercart_meta_value( $cartmeta_id, $value ) {
4207 + global $wpdb;
4208 +
4209 + if ( ! $cartmeta_id ) {
4210 + return;
4211 + }
4212 +
4213 + $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
4214 +
4215 + $query = $wpdb->prepare( "UPDATE $ordercart_meta_table SET meta_value = %s WHERE cartmeta_id = %d", $value, $cartmeta_id );
4216 + $res = $wpdb->query( $query );
4217 + return $res;
4218 +}
4219 +
4220 +function usces_set_ordercart_meta_value( $type, $cart_id, $key, $value ) {
4221 + global $wpdb;
4222 +
4223 + if ( ! $type || ! $cart_id || ! $key || ! $value ) {
4224 + return;
4225 + }
4226 +
4227 + $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
4228 +
4229 + $query = $wpdb->prepare(
4230 + "SELECT cartmeta_id FROM $ordercart_meta_table
4231 + WHERE cart_id = %d AND meta_type = %s AND meta_key = %s ",
4232 + $cart_id, $type, $key
4233 + );
4234 + $res1 = $wpdb->get_var( $query );
4235 +
4236 + if ( $res1 ) {
4237 + $query = $wpdb->prepare(
4238 + "UPDATE $ordercart_meta_table SET meta_value = %s
4239 + WHERE cart_id = %d AND meta_type = %s AND meta_key = %s",
4240 + $value, $cart_id, $type, $key
4241 + );
4242 + $res2 = $wpdb->query( $query );
4243 + } else {
4244 + $query = $wpdb->prepare(
4245 + "INSERT INTO $ordercart_meta_table ( cart_id, meta_type, meta_key, meta_value ) VALUES ( %d, %s, %s, %s )",
4246 + $cart_id, $type, $key, $value
4247 + );
4248 + $res2 = $wpdb->query( $query );
4249 + }
4250 + return $res2;
4251 +}
4252 +
4253 +function usces_get_ordercart_meta( $type, $cart_id, $key = '' ) {
4254 + global $wpdb;
4255 +
4256 + if ( ! $cart_id ) {
4257 + return;
4258 + }
4259 +
4260 + $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
4261 +
4262 + if ( '' !== $key ) {
4263 + $query = $wpdb->prepare(
4264 + "SELECT cartmeta_id, meta_key, meta_value
4265 + FROM $ordercart_meta_table
4266 + WHERE cart_id = %d AND meta_type = %s AND meta_key = %s
4267 + ORDER BY cartmeta_id",
4268 + $cart_id, $type, $key
4269 + );
4270 + } else {
4271 + $query = $wpdb->prepare(
4272 + "SELECT cartmeta_id, meta_key, meta_value
4273 + FROM $ordercart_meta_table
4274 + WHERE cart_id = %d AND meta_type = %s
4275 + ORDER BY cartmeta_id",
4276 + $cart_id, $type
4277 + );
4278 + }
4279 + $res = $wpdb->get_results( $query, ARRAY_A );
4280 + return $res;
4281 +}
4282 +
4283 +function usces_add_ordercart_meta_value( $type, $cart_id, $key, $value ) {
4284 + global $wpdb;
4285 +
4286 + if ( ! $type || ! $cart_id || ! $key || ! $value ) {
4287 + return;
4288 + }
4289 +
4290 + $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
4291 +
4292 + $query = $wpdb->prepare(
4293 + "INSERT INTO $ordercart_meta_table
4294 + ( cart_id, meta_type, meta_key, meta_value ) VALUES ( %d, %s, %s, %s )",
4295 + $cart_id, $type, $key, $value
4296 + );
4297 + $res = $wpdb->query( $query );
4298 + return $res;
4299 +}
4300 +
4301 +function usces_get_ordercart_meta_value( $type, $cart_id, $key = '' ) {
4302 + global $wpdb;
4303 +
4304 + if ( ! $cart_id ) {
4305 + return;
4306 + }
4307 +
4308 + $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
4309 +
4310 + if ( '' !== $key ) {
4311 + $query = $wpdb->prepare(
4312 + "SELECT meta_value
4313 + FROM $ordercart_meta_table
4314 + WHERE cart_id = %d AND meta_type = %s AND meta_key = %s
4315 + ORDER BY cartmeta_id",
4316 + $cart_id, $type, $key
4317 + );
4318 + } else {
4319 + $query = $wpdb->prepare(
4320 + "SELECT meta_value
4321 + FROM $ordercart_meta_table
4322 + WHERE cart_id = %d AND meta_type = %s
4323 + ORDER BY cartmeta_id",
4324 + $cart_id, $type
4325 + );
4326 + }
4327 + $res = $wpdb->get_var( $query );
4328 + return $res;
4329 +}
4330 +
4331 +function usces_get_ordercart_meta_by_id( $cartmeta_id ) {
4332 + global $wpdb;
4333 +
4334 + if ( ! $cartmeta_id ) {
4335 + return;
4336 + }
4337 +
4338 + $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
4339 +
4340 + $query = $wpdb->prepare( "SELECT * FROM $ordercart_meta_table WHERE cartmeta_id = %d", $cartmeta_id );
4341 + $res = $wpdb->get_row( $query, ARRAY_A );
4342 + return $res;
4343 +}
4344 +
4345 +function usces_get_post_id_by_cartmeta_id( $cartmeta_id ) {
4346 + global $wpdb;
4347 +
4348 + if ( ! $cartmeta_id ) {
4349 + return 0;
4350 + }
4351 +
4352 + $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
4353 + $ordercart_table = $wpdb->prefix . 'usces_ordercart';
4354 +
4355 + $query = $wpdb->prepare( "SELECT cart_id FROM $ordercart_meta_table WHERE cartmeta_id = %d", $cartmeta_id );
4356 + $cart_id = $wpdb->get_var( $query );
4357 + if ( ! $cartmeta_id ) {
4358 + return 0;
4359 + }
4360 +
4361 + $query = $wpdb->prepare( "SELECT post_id FROM $ordercart_table WHERE cart_id = %d", $cart_id );
4362 + $post_id = $wpdb->get_var( $query );
4363 +
4364 + return $post_id;
4365 +}
4366 +
4367 +function usces_delete_ordercart_meta_by_id( $cartmeta_id ) {
4368 + global $wpdb;
4369 +
4370 + if ( ! $cartmeta_id ) {
4371 + return;
4372 + }
4373 +
4374 + $ordercart_meta_table = $wpdb->prefix . 'usces_ordercart_meta';
4375 +
4376 + $query = $wpdb->prepare( "DELETE FROM $ordercart_meta_table WHERE cartmeta_id = %d", $cartmeta_id );
4377 + $res = $wpdb->query( $query );
4378 + return $res;
4379 +}
4380 +
4381 +function usces_make_advance_value( $advance, $cart_row ) {
4382 + $value = '';
4383 + $advance_value = array();
4384 +
4385 + foreach ( $advance as $row ) {
4386 + $advance_value[] = array( $row['meta_key'] => $row['meta_value'] );
4387 + }
4388 + $value = apply_filters( 'usces_filter_order_edit_form_row_advance_value', serialize( $advance_value ), $advance, $cart_row );
4389 + return $value;
4390 +}
4391 +
4392 +function usces_get_ordercart_row( $order_id, $cart = array() ) {
4393 + global $usces;
4394 +
4395 + if ( empty( $cart ) ) {
4396 + $cart = usces_get_ordercartdata( $order_id );
4397 + }
4398 + $reduced_taxrate = usces_is_reduced_taxrate( $order_id );
4399 + if ( $reduced_taxrate ) {
4400 + $usces_tax = Welcart_Tax::get_instance();
4401 + }
4402 +
4403 + ob_start();
4404 + foreach ( $cart as $i => $cart_row ) {
4405 + $ordercart_id = $cart_row['cart_id'];
4406 + $post_id = $cart_row['post_id'];
4407 + $sku = $cart_row['sku'];
4408 + $sku_code = $cart_row['sku_code'];
4409 + $quantity = $cart_row['quantity'];
4410 + $options = usces_get_ordercart_meta( 'option', $ordercart_id );
4411 + $advance = usces_get_ordercart_meta( 'advance', $ordercart_id );
4412 + $applicable_taxrate = ( $reduced_taxrate ) ? $usces_tax->get_ordercart_applicable_taxrate( $ordercart_id, $post_id, $sku_code ) : '';
4413 + if ( 'reduced' === $applicable_taxrate ) {
4414 + $reduced_taxrate_mark = '<span class="reduced_taxrate_mark">' . $usces_tax->reduced_taxrate_mark.'</span>';
4415 + } else {
4416 + $reduced_taxrate_mark = '';
4417 + }
4418 + $itemCode = $cart_row['item_code'];
4419 + $itemName = $cart_row['item_name'];
4420 + $cartItemName = $usces->getCartItemName_byOrder( $cart_row );
4421 + $skuPrice = $cart_row['price'];
4422 + $stock = $usces->getItemZaiko( $post_id, $sku_code );
4423 + $stockid = $usces->getItemZaikoStatusId( $post_id, $sku_code );
4424 + $red = ( 1 < $stockid ) ? 'class="signal_red"' : '';
4425 + $pictid = (int) $usces->get_mainpictid( $itemCode );
4426 + $materials = compact( 'i', 'cart_row', 'post_id', 'sku', 'sku_code', 'quantity', 'options', 'advance',
4427 + 'itemCode', 'itemName', 'cartItemName', 'skuPrice', 'stock', 'red', 'pictid', 'order_id' );
4428 + $advance_value = usces_make_advance_value( $advance, $cart_row );
4429 + $cart_thumbnail = ( ! empty( $pictid ) ) ? wp_get_attachment_image( $pictid, array( 80, 80 ), true ) : usces_get_attachment_noimage( array( 80, 80 ), $itemCode );
4430 + $cart_thumbnail = apply_filters( 'usces_filter_cart_thumbnail', $cart_thumbnail, $post_id, $pictid, $i, $cart_row );
4431 + $index_column = apply_filters( 'usces_filter_admin_cart_index', ( $i + 1 ), $materials );
4432 + $post_status = get_post_status( $post_id );
4433 + if ( $post_status && in_array( $post_status, array( 'publish', 'draft', 'private' ), true ) ) {
4434 + $item_editpage = admin_url( 'admin.php?page=usces_itemedit&action=edit&post=' . $post_id . '&usces_referer=' . urlencode( site_url() . '/wp-admin/admin.php?page=usces_orderlist&order_action=edit&order_id=' . $order_id ) );
4435 + } else {
4436 + $item_editpage = '';
4437 + }
4438 + ?>
4439 + <tr>
4440 + <td><?php wel_esc_script_e( $index_column ); ?></td>
4441 + <td><?php wel_esc_script_e( $cart_thumbnail ); ?></td>
4442 + <td class="aleft">
4443 + <?php if ( ! empty( $item_editpage ) ) : ?><a href="<?php echo esc_url( $item_editpage ); ?>" title="<?php esc_attr_e( 'To the edit screen for this product.', 'usces' ); ?>" ><?php endif; ?>
4444 + <?php echo apply_filters( 'usces_filter_admin_cart_item_name', esc_html( $cartItemName ), $materials ); ?>
4445 + <?php if ( ! empty( $item_editpage ) ) : ?></a><?php endif; ?>
4446 + <?php wel_esc_script_e( $reduced_taxrate_mark ); ?><?php do_action( 'usces_admin_order_item_name', $order_id, $i ); ?><?php usces_make_option_field( $materials, $cart ); ?></td>
4447 + <td><input name="skuPrice[<?php echo esc_attr( $ordercart_id ); ?>]" class="text price" type="text" value="<?php echo esc_attr( usces_crform( $skuPrice, false, false, 'return', false ) ); ?>" /><?php do_action( 'usces_admin_order_cart_after_price', $materials ); ?></td>
4448 + <td><input name="quant[<?php echo esc_attr( $ordercart_id ); ?>]" class="text quantity" type="text" value="<?php echo esc_attr( $cart_row['quantity'] ); ?>" /></td>
4449 + <td><p id="sub_total[<?php echo esc_attr( $ordercart_id ); ?>]" class="aright">&nbsp;</p><?php do_action( 'usces_admin_order_cart_after_sub_total', $materials ); ?></td>
4450 + <td <?php wel_esc_script_e( $red ); ?>><?php echo esc_html( $stock ); ?></td>
4451 + <td>
4452 + <input name="postId[<?php echo esc_attr( $ordercart_id ); ?>]" type="hidden" value="<?php echo esc_attr( $post_id ); ?>" />
4453 + <input name="advance[<?php echo esc_attr( $ordercart_id ); ?>]" type="hidden" value="<?php echo esc_attr( $advance_value ); ?>" />
4454 + <?php if ( $reduced_taxrate ) : ?>
4455 + <input name="applicable_taxrate[<?php echo esc_attr( $ordercart_id ); ?>]" type="hidden" value="<?php echo esc_attr( $applicable_taxrate ); ?>" />
4456 + <?php endif; ?>
4457 + <input name="delButtonAdmin[<?php echo esc_attr( $ordercart_id ); ?>]" class="button delCartButton" type="submit" value="<?php esc_html_e( 'Delete', 'usces' ); ?>" />
4458 + <?php do_action( 'usces_admin_order_cart_button', $order_id, $i ); ?>
4459 + </td>
4460 + </tr>
4461 + <?php
4462 + }
4463 + $row = ob_get_contents();
4464 + ob_end_clean();
4465 +
4466 + return apply_filters( 'usces_filter_get_ordercart_row', $row, $order_id, $cart );
4467 +}
4468 +
4469 +/**
4470 + * Add capabilities to the roles.
4471 + *
4472 + * return void
4473 + */
4474 +function usces_add_capabilites() {
4475 + $admin_role = get_role( 'administrator' );
4476 + $admin_role->add_cap( 'wel_publish_products' );
4477 + $admin_role->add_cap( 'wel_others_products' );
4478 + $admin_role->add_cap( 'wel_manage_order' );
4479 + $admin_role->add_cap( 'wel_manage_setting' );
4480 +
4481 + $editor_role = get_role( 'editor' );
4482 + $editor_role->add_cap( 'wel_publish_products' );
4483 + $editor_role->add_cap( 'wel_others_products' );
4484 + $editor_role->add_cap( 'wel_manage_order' );
4485 + $editor_role->add_cap( 'wel_manage_setting' );
4486 +
4487 + $wc_management_role = get_role( 'wc_management' );
4488 + $wc_management_role->add_cap( 'wel_publish_products' );
4489 + $wc_management_role->add_cap( 'wel_others_products' );
4490 + $wc_management_role->add_cap( 'wel_manage_order' );
4491 +
4492 + $wc_author_role = get_role( 'wc_author' );
4493 + $wc_author_role->add_cap( 'wel_publish_products' );
4494 + $wc_author_role->add_cap( 'wel_others_products' );
4495 +
4496 + $author_role = get_role( 'author' );
4497 + $author_role->add_cap( 'wel_publish_products' );
4498 +}
4499 +
4500 +function usces_add_role() {
4501 +
4502 + if ( ! get_role( 'wc_author' ) ) {
4503 + $capabilities = array(
4504 + 'moderate_comments' => 1,
4505 + 'manage_categories' => 1,
4506 + 'manage_links' => 1,
4507 + 'upload_files' => 1,
4508 + 'unfiltered_html' => 1,
4509 + 'edit_posts' => 1,
4510 + 'edit_others_posts' => 1,
4511 + 'edit_published_posts' => 1,
4512 + 'publish_posts' => 1,
4513 + 'edit_pages' => 1,
4514 + 'read' => 1,
4515 + 'level_4' => 1,
4516 + 'level_3' => 1,
4517 + 'level_2' => 1,
4518 + 'level_1' => 1,
4519 + 'level_0' => 1,
4520 + 'edit_others_pages' => 1,
4521 + 'edit_published_pages' => 1,
4522 + 'publish_pages' => 1,
4523 + 'delete_pages' => 1,
4524 + 'delete_others_pages' => 1,
4525 + 'delete_published_pages' => 1,
4526 + 'delete_posts' => 1,
4527 + 'delete_others_posts' => 1,
4528 + 'delete_published_posts' => 1,
4529 + 'delete_private_posts' => 1,
4530 + 'edit_private_posts' => 1,
4531 + 'read_private_posts' => 1,
4532 + 'delete_private_pages' => 1,
4533 + 'edit_private_pages' => 1,
4534 + 'read_private_pages' => 1,
4535 + );
4536 + add_role( 'wc_author', __( 'Editor (no management authority)', 'usces' ), $capabilities );
4537 + }
4538 +
4539 + if ( ! get_role( 'wc_management' ) ) {
4540 + $capabilities = array(
4541 + 'moderate_comments' => 1,
4542 + 'manage_categories' => 1,
4543 + 'manage_links' => 1,
4544 + 'upload_files' => 1,
4545 + 'unfiltered_html' => 1,
4546 + 'edit_posts' => 1,
4547 + 'edit_others_posts' => 1,
4548 + 'edit_published_posts' => 1,
4549 + 'publish_posts' => 1,
4550 + 'edit_pages' => 1,
4551 + 'read' => 1,
4552 + 'level_5' => 1,
4553 + 'level_4' => 1,
4554 + 'level_3' => 1,
4555 + 'level_2' => 1,
4556 + 'level_1' => 1,
4557 + 'level_0' => 1,
4558 + 'edit_others_pages' => 1,
4559 + 'edit_published_pages' => 1,
4560 + 'publish_pages' => 1,
4561 + 'delete_pages' => 1,
4562 + 'delete_others_pages' => 1,
4563 + 'delete_published_pages' => 1,
4564 + 'delete_posts' => 1,
4565 + 'delete_others_posts' => 1,
4566 + 'delete_published_posts' => 1,
4567 + 'delete_private_posts' => 1,
4568 + 'edit_private_posts' => 1,
4569 + 'read_private_posts' => 1,
4570 + 'delete_private_pages' => 1,
4571 + 'edit_private_pages' => 1,
4572 + 'read_private_pages' => 1,
4573 + );
4574 + add_role( 'wc_management', __( 'Editor (no setting authority)', 'usces' ), $capabilities );
4575 + }
4576 +
4577 + remove_role( 'wpsc_anonymous' );
4578 +}
4579 +
4580 +function usces_get_admin_user_level() {
4581 + global $current_user;
4582 +
4583 + wp_get_current_user();
4584 + $levels = array();
4585 + foreach ( $current_user->allcaps as $key => $value ) {
4586 + $parts = explode( '_', $key );
4587 + if ( 'level' == $parts[0] ) {
4588 + $levels[] = $parts[1];
4589 + }
4590 + }
4591 + if ( empty( $levels ) ) {
4592 + return 0;
4593 + } else {
4594 + rsort( $levels );
4595 + return $levels[0];
4596 + }
4597 +}
4598 +
4599 +function usces_make_lost_key() {
4600 + return uniqid( 'wc' , true );
4601 +}
4602 +
4603 +function usces_store_lostmail_key( $lost_mail, $lost_key ) {
4604 + global $wpdb;
4605 +
4606 + $date = substr( current_time( 'mysql' ), 0, 10 );
4607 + $table = $wpdb->prefix . 'usces_access';
4608 + $query = $wpdb->prepare( "INSERT INTO {$table} (acc_key, acc_type, acc_value, acc_date) VALUES (%s, %s, %s, %s)", $lost_mail, 'lostkey', $lost_key, $date );
4609 + $res = $wpdb->query( $query );
4610 + return $res;
4611 +}
4612 +
4613 +function usces_remove_lostmail_key( $lost_mail, $lost_key ) {
4614 + global $wpdb;
4615 +
4616 + $table = $wpdb->prefix . 'usces_access';
4617 + $query = $wpdb->prepare( "DELETE FROM {$table} WHERE acc_key = %s AND acc_type = %s AND acc_value = %s", $lost_mail, 'lostkey', $lost_key );
4618 + $res = $wpdb->query( $query );
4619 + return $res;
4620 +}
4621 +
4622 +function usces_check_lostkey( $lost_mail, $lost_key ) {
4623 + global $wpdb;
4624 +
4625 + $table = $wpdb->prefix . 'usces_access';
4626 + $query = $wpdb->prepare( "SELECT ID FROM {$table} WHERE acc_key = %s AND acc_type = %s AND acc_value = %s", $lost_mail, 'lostkey', $lost_key );
4627 + $res = $wpdb->get_col( $query );
4628 + return $res;
4629 +}
4630 +
4631 +function usces_clearup_lostkey() {
4632 + global $wpdb;
4633 +
4634 + $table = $wpdb->prefix . 'usces_access';
4635 + $date = date( 'Y-m-d', current_time( 'timestamp' ) );
4636 + $query = $wpdb->prepare( "DELETE FROM {$table} WHERE acc_type = %s AND acc_date < %s", 'lostkey', $date );
4637 + $res = $wpdb->query( $query );
4638 + do_action( 'usces_clearup_lostkey', $res );
4639 + return $res;
4640 +}
4641 +
4642 +function usces_clearup_acting_data() {
4643 + global $wpdb;
4644 +
4645 + $table = $wpdb->prefix . 'usces_access';
4646 + $date = date( 'Y-m-d', ( current_time( 'timestamp' ) - 86400 * 30 ) );
4647 + $query = $wpdb->prepare( "DELETE FROM {$table} WHERE acc_type = %s AND acc_date < %s", 'acting_data', $date );
4648 + $res = $wpdb->query( $query );
4649 + do_action( 'usces_clearup_acting_data', $res );
4650 + return $res;
4651 +}
4652 +
4653 +function usces_clearup_acting_log() {
4654 + global $usces, $wpdb;
4655 +
4656 + $table = $wpdb->prefix . 'usces_log';
4657 + $date = date( 'Y-m-d 00:00:00', ( current_time( 'timestamp' ) - 86400 * 30 ) );
4658 + $query = $wpdb->prepare( "DELETE FROM {$table} WHERE ( log_type = %s OR log_type = %s ) AND datetime < %s", 'acting_data', 'acting_error', $date );
4659 + $res = $wpdb->query( $query );
4660 + do_action( 'usces_clearup_acting_log', $res );
4661 +}
4662 +
4663 +function usces_acting_key() {
4664 + global $usces;
4665 + $acting_key = usces_rand();
4666 + return $acting_key;
4667 +}
4668 +
4669 +function usces_change_order_receipt( $order_id, $flag ) {
4670 + global $wpdb, $usces;
4671 +
4672 + $table_name = $wpdb->prefix . 'usces_order';
4673 +
4674 + if ( 'receipted' === $flag ) {
4675 +
4676 + $mquery = $wpdb->prepare(
4677 + "UPDATE $table_name SET order_status =
4678 + CASE
4679 + WHEN LOCATE('noreceipt', order_status) > 0 THEN REPLACE(order_status, 'noreceipt', 'receipted')
4680 + WHEN LOCATE('receipted', order_status) > 0 THEN order_status
4681 + ELSE CONCAT('receipted,', order_status )
4682 + END
4683 + WHERE ID = %d",
4684 + $order_id
4685 + );
4686 + $res = $wpdb->query( $mquery );
4687 +
4688 + $gmtdate = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', time() ) );
4689 + $usces->set_order_meta_value( 'receipted_date', $gmtdate, $order_id );
4690 +
4691 + } elseif ( 'noreceipt' === $flag ) {
4692 +
4693 + $mquery = $wpdb->prepare(
4694 + "UPDATE $table_name SET order_status =
4695 + CASE
4696 + WHEN LOCATE('receipted', order_status) > 0 THEN REPLACE(order_status, 'receipted', 'noreceipt')
4697 + WHEN LOCATE('noreceipt', order_status) > 0 THEN order_status
4698 + ELSE CONCAT('noreceipt,', order_status )
4699 + END
4700 + WHERE ID = %d",
4701 + $order_id
4702 + );
4703 + $res = $wpdb->query( $mquery );
4704 +
4705 + $usces->del_order_meta( 'receipted_date', $order_id );
4706 + }
4707 + return $res;
4708 +}
4709 +
4710 +function usces_localized_name( $familly_name, $given_name, $out = '' ) {
4711 + global $usces_settings, $usces;
4712 +
4713 + $familly_name = preg_replace( '/[\r\n]/', '', $familly_name );
4714 + $given_name = preg_replace( '/[\r\n]/', '', $given_name );
4715 +
4716 + $options = get_option( 'usces', array() );
4717 + $form = $options['system']['addressform'];
4718 + if ( $usces_settings['nameform'][ $form ] ) {
4719 + $res = $given_name . ' ' . $familly_name;
4720 + } else {
4721 + $res = $familly_name . ' ' . $given_name;
4722 + }
4723 +
4724 + if ( 'return' === $out ) {
4725 + return esc_html( $res );
4726 + } else {
4727 + echo esc_html( $res );
4728 + }
4729 +}
4730 +
4731 +function usces_get_hash( $str, $salt = NULL, $type = 0 ) {
4732 + //$hash = md5( trim( $str ) );
4733 + $hash_algos = ( defined( 'USCES_HASH_ALGOS' ) ) ? USCES_HASH_ALGOS : 'md5';
4734 + $secret_key = ( defined( 'USCES_SECRET_KEY' ) ) ? USCES_SECRET_KEY : '';
4735 + if ( $secret_key ) {
4736 + $hash = hash_hmac( $hash_algos, $str.$salt, $secret_key );
4737 + } else {
4738 + $hash = hash( $hash_algos, $str.$salt );
4739 + }
4740 + $args = compact( 'str', 'salt', 'type' );
4741 + return apply_filters( 'usces_filter_get_hash', $hash, $args );
4742 +}
4743 +
4744 +function usces_get_salt( $mem_key, $type = 0 ) {
4745 + global $wpdb;
4746 +
4747 + $salt = '';
4748 + if ( defined( 'USCES_SALT' ) && '1' === USCES_SALT ) {
4749 + if ( 1 === $type ) {
4750 + $salt = uniqid();
4751 + } else {
4752 + if ( ! empty( $mem_key ) ) {
4753 + $member_table = usces_get_tablename( 'usces_member' );
4754 + $member_meta_table = usces_get_tablename( 'usces_member_meta' );
4755 + if ( is_numeric( $mem_key ) ) {
4756 + $salt = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $member_meta_table WHERE member_id = %d AND meta_key = %s", $mem_key, 'mem_salt' ) );
4757 + } else {
4758 + $salt = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $member_table AS `member` INNER JOIN $member_meta_table AS `meta` ON member.ID = meta.member_id AND meta.meta_key = %s WHERE mem_email = %s", 'mem_salt', $mem_key ) );
4759 + }
4760 + }
4761 + }
4762 + }
4763 + $args = compact( 'mem_key', 'type' );
4764 + return apply_filters( 'usces_filter_get_salt', $salt, $args );
4765 +}
4766 +
4767 +function usces_get_member_reinforcement() {
4768 + if ( defined( 'WCEX_DLSELLER' ) ) {
4769 + $dlseller_options = get_option( 'dlseller' );
4770 + if ( isset( $dlseller_options['dlseller_member_reinforcement'] ) && 'on' === $dlseller_options['dlseller_member_reinforcement'] ) {
4771 + return true;
4772 + }
4773 + }
4774 + return false;
4775 +}
4776 +
4777 +function usces_have_shipped( $cart = NULL ) {
4778 + global $usces;
4779 +
4780 + if ( empty( $cart ) ) {
4781 + $cart = $usces->cart->get_cart();
4782 + }
4783 +
4784 + $division = '';
4785 + foreach ( (array) $cart as $cart_row ) {
4786 + if ( 'shipped' === $usces->getItemDivision( $cart_row['post_id'] ) ) {
4787 + $division = 'shipped';
4788 + break;
4789 + }
4790 + }
4791 + if ( 'shipped' === $division ) {
4792 + return true;
4793 + } else {
4794 + return false;
4795 + }
4796 +}
4797 +
4798 +function usces_have_continue_charge( $cart = NULL ) {
4799 + global $usces;
4800 +
4801 + if ( empty( $cart ) ) {
4802 + $cart = $usces->cart->get_cart();
4803 + }
4804 +
4805 + $charging_type = 'once';
4806 + foreach ( (array) $cart as $cart_row ) {
4807 + if ( 'continue' === $usces->getItemChargingType( $cart_row['post_id'] ) ) {
4808 + $charging_type = 'continue';
4809 + break;
4810 + }
4811 + }
4812 + if ( 'continue' === $charging_type ) {
4813 + return true;
4814 + } else {
4815 + return false;
4816 + }
4817 +}
4818 +
4819 +function usces_have_regular_order() {
4820 + if ( defined( 'WCEX_AUTO_DELIVERY' ) ) {
4821 + return wcad_have_regular_order();
4822 + }
4823 + return false;
4824 +}
4825 +
4826 +function usces_have_member_regular_order( $member_id ) {
4827 + if ( defined( 'WCEX_AUTO_DELIVERY' ) ) {
4828 + return wcad_have_member_regular_order( $member_id );
4829 + }
4830 + return false;
4831 +}
4832 +
4833 +function usces_have_member_continue_order( $member_id ) {
4834 + if ( defined( 'WCEX_DLSELLER' ) && function_exists( 'dlseller_have_member_continue_order' ) ) {
4835 + return dlseller_have_member_continue_order( $member_id );
4836 + }
4837 + return false;
4838 +}
4839 +
4840 +function usces_is_available_point() {
4841 + global $usces;
4842 +
4843 + $res = true;
4844 +
4845 + if ( defined( 'WCEX_DLSELLER' ) && function_exists( 'dlseller_have_continue_charge' ) ) {
4846 + if ( dlseller_have_continue_charge() ) {
4847 + $res = false;
4848 + }
4849 + }
4850 +
4851 + return $res;
4852 +}
4853 +
4854 +function usces_get_link_key( $results ) {
4855 + global $usces;
4856 +
4857 + $linkkey = '(empty key)';
4858 + if ( isset( $_REQUEST['X-S_TORIHIKI_NO'] ) ) {
4859 + $linkkey = $_REQUEST['S_TORIHIKI_NO']; //remise.
4860 + } elseif ( isset( $_REQUEST['acting'] ) && ( 'jpayment_card' === $_REQUEST['acting'] || 'jpayment_conv' === $_REQUEST['acting'] || 'jpayment_bank' === $_REQUEST['acting'] ) && isset( $_REQUEST['cod'] ) ) {
4861 + $linkkey = $_REQUEST['cod']; //ROBOT PAYMENT (Cloud Payment,J-Payment).
4862 + } elseif ( isset( $_REQUEST['txn_type'] ) && 'pro_hosted' === $_REQUEST['txn_type'] && isset( $_REQUEST['custom'] ) ) {
4863 + $linkkey = $_REQUEST['custom']; //PayPal Webpayment Plus.
4864 + } elseif ( isset( $_REQUEST['SID'] ) && isset( $_REQUEST['FUKA'] ) ) {
4865 + $linkkey = $_REQUEST['SID']; //Payment for (MetapsPayment,paydesign,digitalcheck).
4866 + } elseif ( isset( $_REQUEST['acting'] ) && ( 'mizuho_card' === $_REQUEST['acting'] || 'mizuho_conv' === $_REQUEST['acting'] ) && isset( $_REQUEST['stran'] ) ) {
4867 + $linkkey = $_REQUEST['stran']; //mizuho.
4868 + } elseif ( isset( $_REQUEST['SiteId'] ) && $usces->options['acting_settings']['anotherlane']['siteid'] === $_REQUEST['SiteId'] && isset( $_REQUEST['TransactionId'] ) ) {
4869 + $linkkey = $_REQUEST['TransactionId']; //AnotherLane.
4870 + } elseif ( isset( $_REQUEST['acting'] ) && ( 'veritrans_card' === $_REQUEST['acting'] || 'veritrans_conv' === $_REQUEST['acting'] ) && isset( $_REQUEST['orderId'] ) ) {
4871 + $linkkey = $_REQUEST['orderId']; //Veritrans.
4872 + } elseif ( isset( $_REQUEST['acting'] ) && 'telecom_card' === $_REQUEST['acting'] && isset( $_REQUEST['acting_return'] ) && isset( $_REQUEST['option'] ) ) {
4873 + $linkkey = $_REQUEST['option']; //telecom credit.
4874 + } elseif ( isset( $_REQUEST['acting'] ) && 'epsilon' === $_REQUEST['acting'] && isset( $_REQUEST['acting_return'] ) && isset( $_REQUEST['order_number'] ) ) {
4875 + $linkkey = $_REQUEST['order_number']; //epsilon.
4876 + }
4877 + $linkkey = apply_filters( 'usces_filter_get_link_key', $linkkey, $results );
4878 + return $linkkey;
4879 +}
4880 +
4881 +function usces_erase_emoji( $str ) {
4882 + if ( $str ) {
4883 + $newstr = preg_replace( '/[\xF0-\xF7][\x80-\xBF][\x80-\xBF][\x80-\xBF]/', '', $str );
4884 + $str = apply_filters( 'usces_filter_erase_emoji', $newstr, $str );
4885 + }
4886 + return $str;
4887 +}
4888 +
4889 +function usces_is_reduced_taxrate( $order_id = '' ) {
4890 + global $usces;
4891 +
4892 + if ( empty( $order_id ) ) {
4893 + $reduced = $usces->is_reduced_taxrate();
4894 + } else {
4895 + $condition = usces_get_order_condition( $order_id );
4896 + $reduced = ( isset( $condition['applicable_taxrate'] ) && 'reduced' === $condition['applicable_taxrate'] ) ? true : false;
4897 + }
4898 + return $reduced;
4899 +}
4900 +
4901 +function usces_get_order_condition( $order_id ) {
4902 + global $wpdb;
4903 + $order_condition = $wpdb->get_var( $wpdb->prepare( "SELECT order_condition FROM {$wpdb->prefix}usces_order WHERE ID = %d", $order_id ) );
4904 + return wel_safe_maybe_unserialize( $order_condition );
4905 +}
4906 +
4907 +function usces_tax_rounding_off( $tax, $tax_method = '' ) {
4908 + global $usces;
4909 +
4910 + if ( empty( $tax_method ) ) {
4911 + $tax_method = $usces->options['tax_method'];
4912 + }
4913 + $decimal = $usces->get_currency_decimal();
4914 + $decipad = (int) str_pad( '1', $decimal + 1, '0', STR_PAD_RIGHT );
4915 + switch ( $tax_method ) {
4916 + case 'cutting':
4917 + if ( 0 < $tax ) {
4918 + $tax = floor( (float) $tax * $decipad ) / $decipad;
4919 + }
4920 + break;
4921 + case 'bring':
4922 + if ( 0 < $tax ) {
4923 + $tax = ceil( floatval( ( $tax . '' ) ) * $decipad ) / $decipad;
4924 + }
4925 + break;
4926 + case 'rounding':
4927 + if ( 0 < $decimal ) {
4928 + if ( 0 < $tax ) {
4929 + $tax = round( (float) $tax, $decimal );
4930 + }
4931 + } else {
4932 + if ( 0 < $tax ) {
4933 + $tax = round( (float) $tax );
4934 + }
4935 + }
4936 + break;
4937 + }
4938 + return $tax;
4939 +}
4940 +
4941 +function usces_is_required_field( $name ) {
4942 + global $usces_essential_mark;
4943 +
4944 + $usces_essential_mark = apply_filters( 'usces_filter_essential_mark', $usces_essential_mark );
4945 + if ( empty( $usces_essential_mark[ $name ] ) ) {
4946 + return false;
4947 + } else {
4948 + return true;
4949 + }
4950 +}
4951 +
4952 +function usces_get_tablename( $target ) {
4953 + global $wpdb;
4954 +
4955 + $prefix = '';
4956 + if ( defined( 'WELCART_DB_PREFIX' ) ) {
4957 + $prefix = WELCART_DB_PREFIX;
4958 + }
4959 + if ( ! $prefix ) {
4960 + $prefix = $wpdb->prefix;
4961 + }
4962 + $tablename = $prefix . $target;
4963 +
4964 + $tablename = apply_filters( 'usces_filter_get_tablename', $tablename, $target );
4965 +
4966 + return $tablename;
4967 +}
4968 +
4969 +function usces_convert_zipcode( $zipcode ) {
4970 + $zipcode = mb_convert_kana( $zipcode, 'a' );
4971 + $zipcode = str_replace( 'ー', '-', $zipcode );
4972 + $zipcode = str_replace( '―', '-', $zipcode );
4973 + $zipcode = str_replace( '-', '-', $zipcode );
4974 + return $zipcode;
4975 +}
4976 +
4977 +function usces_get_sku( $post_id, $sku_code ) {
4978 + global $usces;
4979 + $skus = $usces->get_skus( $post_id, 'code' );
4980 + $sku = isset( $skus[ $sku_code ] ) ? $skus[ $sku_code ] : array();
4981 + return $sku;
4982 +}
4983 +
4984 +function usces_get_wp_environment() {
4985 + global $wp_version, $wpdb;
4986 +
4987 + $permalink_structure = get_option( 'permalink_structure' );
4988 + // WP memory limit.
4989 + $wp_memory_limit = usces_let_to_num( WP_MEMORY_LIMIT );
4990 + if ( function_exists( 'memory_get_usage' ) ) {
4991 + $wp_memory_limit = max( $wp_memory_limit, usces_let_to_num( @ini_get( 'memory_limit' ) ) ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
4992 + }
4993 + return array(
4994 + 'environment' => array(
4995 + 'wp_version' => $wp_version,
4996 + 'home_url' => get_option( 'home' ),
4997 + 'site_url' => get_option( 'siteurl' ),
4998 + 'site_language' => get_bloginfo( 'language' ),
4999 + 'timezone' => get_option( 'timezone_string' ),
5000 + 'number_of_media' => array_sum( (array) wp_count_attachments( array( 'image/jpeg', 'image/gif', 'image/png' ) ) ),
5001 + 'number_of_post' => get_option( 'posts_per_page' ),
5002 + 'blog_public' => get_option( 'blog_public' ),
5003 + 'thumbnail_size' => array(
5004 + 'width' => get_option( 'thumbnail_size_w' ),
5005 + 'height' => get_option( 'thumbnail_size_h' ),
5006 + ),
5007 + 'medium_size' => array(
5008 + 'width' => get_option( 'medium_size_w' ),
5009 + 'height' => get_option( 'medium_size_h' ),
5010 + ),
5011 + 'large_size' => array(
5012 + 'width' => get_option( 'large_size_w' ),
5013 + 'height' => get_option( 'large_size_h' ),
5014 + ),
5015 + 'permalinks' => ( empty( $permalink_structure ) ) ? __( 'Plain', 'usces' ) : __( 'Custom structure', 'usces' ) . " ( {$permalink_structure} )",
5016 + 'wp_multisite' => is_multisite(),
5017 + 'wp_memory_limit' => $wp_memory_limit,
5018 + 'wp_debug_mode' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ),
5019 + 'server' => $_SERVER['SERVER_SOFTWARE'],
5020 + 'php_version' => phpversion(),
5021 + 'php_post_max_size' => ini_get( 'post_max_size' ),
5022 + 'php_max_execution_time' => ini_get( 'max_execution_time' ),
5023 + 'php_max_input_vars' => ini_get( 'max_input_vars' ),
5024 + 'curl_version' => curl_version(),
5025 + 'mysql_version' => $wpdb->dbh->server_info,
5026 + 'upload_max_filesize' => ini_get( 'upload_max_filesize' ),
5027 + ),
5028 + 'theme' => usces_get_theme_info(),
5029 + 'active_plugins' => usces_get_active_plugins(),
5030 + 'inactive_plugins' => usces_get_inactive_plugins(),
5031 + );
5032 +}
5033 +
5034 +/**
5035 + * Get a list of plugins active on the site.
5036 + *
5037 + * @return array
5038 + */
5039 +function usces_get_active_plugins() {
5040 + if ( ! function_exists( 'get_plugin_data' ) ) {
5041 + return array();
5042 + }
5043 +
5044 + $active_plugins = (array) get_option( 'active_plugins', array() );
5045 + if ( is_multisite() ) {
5046 + $network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) );
5047 + $active_plugins = array_merge( $active_plugins, $network_activated_plugins );
5048 + }
5049 +
5050 + $active_plugins_data = array();
5051 +
5052 + foreach ( $active_plugins as $plugin ) {
5053 + $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
5054 + $active_plugins_data[] = usces_format_plugin_data( $plugin, $data );
5055 + }
5056 +
5057 + return $active_plugins_data;
5058 +}
5059 +
5060 +/**
5061 + * Get a list of inplugins active on the site.
5062 + *
5063 + * @return array
5064 + */
5065 +function usces_get_inactive_plugins() {
5066 + if ( ! function_exists( 'get_plugins' ) ) {
5067 + return array();
5068 + }
5069 +
5070 + $plugins = get_plugins();
5071 + $active_plugins = (array) get_option( 'active_plugins', array() );
5072 +
5073 + if ( is_multisite() ) {
5074 + $network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) );
5075 + $active_plugins = array_merge( $active_plugins, $network_activated_plugins );
5076 + }
5077 +
5078 + $plugins_data = array();
5079 +
5080 + foreach ( $plugins as $plugin => $data ) {
5081 + if ( in_array( $plugin, $active_plugins, true ) ) {
5082 + continue;
5083 + }
5084 + $plugins_data[] = usces_format_plugin_data( $plugin, $data );
5085 + }
5086 +
5087 + return $plugins_data;
5088 +}
5089 +
5090 +/**
5091 + * Format plugin data, including data on updates, into a standard format.
5092 + *
5093 + * @since 3.6.0
5094 + * @param string $plugin Plugin directory/file.
5095 + * @param array $data Plugin data from WP.
5096 + * @return array Formatted data.
5097 + */
5098 +function usces_format_plugin_data( $plugin, $data ) {
5099 + if ( ! function_exists( 'get_plugin_updates' ) ) {
5100 + return array();
5101 + }
5102 + $available_updates = get_plugin_updates();
5103 +
5104 + $version_latest = $data['Version'];
5105 +
5106 + // Find latest version.
5107 + if ( isset( $available_updates[ $plugin ]->update->new_version ) ) {
5108 + $version_latest = $available_updates[ $plugin ]->update->new_version;
5109 + }
5110 +
5111 + return array(
5112 + 'plugin' => $plugin,
5113 + 'name' => $data['Name'],
5114 + 'version' => $data['Version'],
5115 + 'version_latest' => $version_latest,
5116 + 'url' => $data['PluginURI'],
5117 + 'author_name' => $data['AuthorName'],
5118 + 'author_url' => esc_url_raw( $data['AuthorURI'] ),
5119 + 'network_activated' => $data['Network'],
5120 + );
5121 +}
5122 +
5123 +/**
5124 + * Get info on the current active theme, info on parent theme (if presnet)
5125 + * and a list of template overrides.
5126 + *
5127 + * @return array
5128 + */
5129 +function usces_get_theme_info() {
5130 + $active_theme = wp_get_theme();
5131 +
5132 + $themes_update = get_site_transient( 'update_themes' );
5133 +
5134 + if ( is_child_theme() ) {
5135 + $parent_theme = wp_get_theme( $active_theme->template );
5136 + $parent_theme_info = array(
5137 + 'parent_name' => $parent_theme->name,
5138 + 'parent_version' => $parent_theme->version,
5139 + 'parent_version_latest' => ( isset( $themes_update->response[ $parent_theme->get_stylesheet() ]['new_version'] ) ) ? $themes_update->response[ $parent_theme->get_stylesheet() ]['new_version'] : false,
5140 + 'parent_author_url' => $parent_theme->{'Author URI'},
5141 + );
5142 + } else {
5143 + $parent_theme_info = array(
5144 + 'parent_name' => '',
5145 + 'parent_version' => '',
5146 + 'parent_version_latest' => '',
5147 + 'parent_author_url' => '',
5148 + );
5149 + }
5150 +
5151 + $active_theme_info = array(
5152 + 'name' => $active_theme->name,
5153 + 'version' => $active_theme->version,
5154 + 'version_latest' => ( isset( $themes_update->response[ $active_theme->get_stylesheet() ]['new_version'] ) ) ? $themes_update->response[ $active_theme->get_stylesheet() ]['new_version'] : false,
5155 + 'author_url' => esc_url_raw( $active_theme->{'Author URI'} ),
5156 + 'is_child_theme' => is_child_theme(),
5157 + );
5158 +
5159 + return array_merge( $active_theme_info, $parent_theme_info );
5160 +}
5161 +
5162 +/**
5163 + * Notation to numbers.
5164 + *
5165 + * This function transforms the php.ini notation for numbers (like '2M') to an integer.
5166 + *
5167 + * @param string $size Size value.
5168 + * @return int
5169 + */
5170 +function usces_let_to_num( $size ) {
5171 + $l = substr( $size, -1 );
5172 + $ret = (int) substr( $size, 0, -1 );
5173 + switch ( strtoupper( $l ) ) {
5174 + case 'P':
5175 + $ret *= 1024;
5176 + // No break.
5177 + case 'T':
5178 + $ret *= 1024;
5179 + // No break.
5180 + case 'G':
5181 + $ret *= 1024;
5182 + // No break.
5183 + case 'M':
5184 + $ret *= 1024;
5185 + // No break.
5186 + case 'K':
5187 + $ret *= 1024;
5188 + // No break.
5189 + }
5190 + return $ret;
5191 +}
5192 +
5193 +function usces_get_total_orders() {
5194 + global $wpdb;
5195 +
5196 + $order_table_name = $wpdb->prefix . 'usces_order';
5197 + $sql = "SELECT COUNT(*) AS total FROM $order_table_name";
5198 + $result = $wpdb->get_row( $sql );
5199 + return $result->total;
5200 +}
5201 +
5202 +function usces_get_total_members() {
5203 + global $wpdb;
5204 +
5205 + $member_table_name = usces_get_tablename( 'usces_member' );
5206 + $sql = "SELECT COUNT(*) AS total FROM $member_table_name";
5207 + $result = $wpdb->get_row( $sql );
5208 + return $result->total;
5209 +}
5210 +
5211 +function get_welcart_system_information() {
5212 + global $usces, $usces_settings;
5213 +
5214 + $options = get_option( 'usces', array() );
5215 + $options_ex = get_option( 'usces_ex', array() );
5216 + $indi_item_name_text = array(
5217 + 'item_name' => 'item name',
5218 + 'item_code' => 'item code',
5219 + 'sku_name' => 'SKU name',
5220 + 'sku_code' => 'SKU code',
5221 + );
5222 + return array(
5223 + 'version' => USCES_VERSION,
5224 + 'total_items' => $usces->get_items_num(),
5225 + 'total_sku' => array_sum( usces_get_stocs() ),
5226 + 'maintenance_mode' => ( isset( $options['display_mode'] ) && $options['display_mode'] == 'Maintenancemode' ) ? true : false,
5227 + 'campaign_schedule' => $options['campaign_schedule'],
5228 + 'order_mail' => $options['order_mail'],
5229 + 'sender_mail' => $options['sender_mail'],
5230 + 'postage_privilege' => $options['postage_privilege'], // free ship condition.
5231 + 'purchase_limit' => $options['purchase_limit'],
5232 + 'shipping_rule' => $options['shipping_rule'],
5233 + 'shipping_rule_text' => get_option( 'usces_shipping_rule' ),
5234 + 'tax_mode' => $options['tax_mode'],
5235 + 'tax_target' => $options['tax_target'],
5236 + 'applicable_taxrate' => $options['applicable_taxrate'],
5237 + 'tax_rate' => $options['tax_rate'],
5238 + 'reduced_tax_rate' => $options['tax_rate_reduced'],
5239 + 'tax_method' => $options['tax_method'],
5240 + 'membership_system' => $options['membersystem_state'],
5241 + 'membership_point' => $options['membersystem_point'],
5242 + 'point_coverage' => $options['point_coverage'],
5243 + 'point_assign' => $options['point_assign'],
5244 + 'payment_methods' => usces_get_system_option( 'usces_payment_method', 'sort' ),
5245 + 'payment_structure' => $usces->payment_structure,
5246 + 'common_options' => usces_get_opts( USCES_CART_NUMBER ),
5247 + 'common_options_type' => get_option( 'usces_item_option_select' ),
5248 + 'shipping_methods' => $options['delivery_method'],
5249 + 'shipping_charge' => $options['shipping_charge'],
5250 + 'delivery_days' => $options['delivery_days'],
5251 + 'delivery_method' => $options['delivery_method'],
5252 + 'delivery_time_limit' => $options['delivery_time_limit'],
5253 + 'shortest_delivery_time' => $options['shortest_delivery_time'],
5254 + 'delivery_after_days' => $options['delivery_after_days'],
5255 + 'newmem_admin_mail' => $options['newmem_admin_mail'],
5256 + 'updmem_admin_mail' => $options['updmem_admin_mail'],
5257 + 'updmem_customer_mail' => $options['updmem_customer_mail'],
5258 + 'delmem_admin_mail' => $options['delmem_admin_mail'],
5259 + 'delmem_customer_mail' => $options['delmem_customer_mail'],
5260 + 'put_customer_name' => $options['put_customer_name'],
5261 + 'email_attach_feature' => $options['email_attach_feature'],
5262 + 'email_attach_file_extension' => $options['email_attach_file_extension'],
5263 + 'email_attach_file_size' => $options['email_attach_file_size'],
5264 + 'add_html_email_option' => $options['add_html_email_option'],
5265 + 'indi_item_name' => $options['indi_item_name'],
5266 + 'indi_item_name_text' => $indi_item_name_text,
5267 + 'pos_item_name' => $options['pos_item_name'],
5268 + 'divide_item' => $options['divide_item'],
5269 + 'itemimg_anchor_rel' => $options['itemimg_anchor_rel'],
5270 + 'fukugo_category_orderby' => $options['fukugo_category_orderby'],
5271 + 'fukugo_category_order' => $options['fukugo_category_order'],
5272 + 'use_ssl' => $options['use_ssl'],
5273 + 'inquiry_id' => $options['inquiry_id'],
5274 + 'no_cart_css' => $options['system']['no_cart_css'],
5275 + 'subimage_rule' => $options['system']['subimage_rule'],
5276 + 'pdf_delivery' => $options['system']['pdf_delivery'],
5277 + 'csv_encode_type' => $options['system']['csv_encode_type'],
5278 + 'csv_category_format' => $options['system']['csv_category_format'],
5279 + 'settlement_backup' => $options['system']['settlement_backup'],
5280 + 'settlement_notice' => $options['system']['settlement_notice'],
5281 + 'country' => $usces_settings['country'],
5282 + 'front_lang' => $options['system']['front_lang'],
5283 + 'currency' => $options['system']['currency'],
5284 + 'addressform' => $options['system']['addressform'],
5285 + 'target_market' => $options['system']['target_market'],
5286 + 'ganbare_activate_flag' => $options_ex['system']['ganbare']['activate_flag'],
5287 + 'stocklink_orderedit_flag' => $options_ex['system']['stocklink']['orderedit_flag'],
5288 + 'stocklink_collective_flag' => $options_ex['system']['stocklink']['collective_flag'],
5289 + 'datalistup_orderlist_flag' => $options_ex['system']['datalistup']['orderlist_flag'],
5290 + 'datalistup_memberlist_flag' => $options_ex['system']['datalistup']['memberlist_flag'],
5291 + 'verifyemail_switch_flag' => $options_ex['system']['verifyemail']['switch_flag'],
5292 + 'verifyemail_edit_flag' => $options_ex['system']['verifyemail']['edit_flag'],
5293 + 'verifyemail_login_notify' => $options_ex['system']['verifyemail']['login_notify'],
5294 + 'number_of_orders' => usces_get_total_orders(),
5295 + 'number_of_members' => usces_get_total_members(),
5296 + 'settlement_selected' => get_option( 'usces_settlement_selected', array() ),
5297 + 'available_settlement' => get_option( 'usces_available_settlement', array() ),
5298 + 'brute_force_status' => $options_ex['system']['brute_force']['status'],
5299 + 'google_recaptcha_status' => $options_ex['system']['google_recaptcha']['status'],
5300 + 'structured_data_product_status' => $options_ex['system']['structured_data_product']['status'],
5301 + 'fee_subject' => $usces->options['fee_subject'],
5302 + 'newproductimage_switch_flag' => $options_ex['system']['newproductimage']['switch_flag'],
5303 + 'operation_log_switch_flag' => $options_ex['system']['operation_log']['status'],
5304 + 'credit_security' => $options_ex['system']['credit_security']['active'],
5305 + );
5306 +}
5307 +
5308 +function usces_generate_system_information_text( $environment, $theme, $active_plugins, $inactive_plugins, $welcart_information, $loaded_extensions, $ini_confs ) {
5309 + $data = '### ' . __( 'WordPress Settings', 'usces' ) . " ###\r\n\r\n";
5310 +
5311 + $data .= __( 'WordPress Address (URL)', 'usces' ) . ' : ' . esc_html( $environment['site_url'] ) . "\r\n";
5312 + $data .= __( 'Site Address (URL)', 'usces' ) . ' : ' . esc_html( $environment['home_url'] ) . "\r\n";
5313 + $data .= __( 'WordPress Version', 'usces' ) . ' : ' . esc_html( $environment['wp_version'] ) . "\r\n";
5314 + $data .= __( 'Site Language', 'usces' ) . ' : ' . esc_html( $environment['site_language'] ) . "\r\n";
5315 + $data .= __( 'Timezone', 'usces' ) . ' : ' . esc_html( $environment['timezone'] ) . "\r\n";
5316 + $data .= __( 'Number of media files', 'usces' ) . ' : ' . esc_html( $environment['number_of_media'] ) . "\r\n";
5317 + $data .= __( 'Blog pages show at most', 'usces' ) . ' : ' . esc_html( $environment['number_of_post'] ) . "\r\n";
5318 + $data .= __( 'Search engine visibility', 'usces' ) . ' : ' . ( ( $environment['blog_public'] ) ? '' : __( 'Discourage search engines from indexing this site', 'usces' ) ) . "\r\n";
5319 + $data .= __( 'Thumbnail size', 'usces' ) . ' : ' . __( 'Width', 'usces' ) . ' ' . esc_html( $environment['thumbnail_size']['width'] ) . ' ' . __( 'Height', 'usces' ) . ' ' . esc_html( $environment['thumbnail_size']['height'] ) . "\r\n";
5320 + $data .= __( 'Image medium size', 'usces' ) . ' : ' . __( 'Width', 'usces' ) . ' ' . esc_html( $environment['medium_size']['width'] ) . ' ' . __( 'Height', 'usces' ) . ' ' . esc_html( $environment['medium_size']['height'] ) . "\r\n";
5321 + $data .= __( 'Image large size', 'usces' ) . ' : ' . __( 'Width', 'usces' ) . ' ' . esc_html( $environment['large_size']['width'] ) . ' ' . __( 'Height', 'usces' ) . ' ' . esc_html( $environment['large_size']['height'] ) . "\r\n";
5322 + $data .= __( 'Permalink Settings', 'usces' ) . ' : ' . esc_html( $environment['permalinks'] ) . "\r\n";
5323 + $data .= __( 'WordPress Multisite', 'usces' ) . ' : ' . ( ( $environment['wp_multisite'] ) ? __( 'ON', 'usces' ) : '' ) . "\r\n";
5324 + $data .= __( 'WordPress Memory Limit', 'usces' ) . ' : ' . esc_html( $environment['wp_memory_limit'] ) . "\r\n";
5325 + $data .= __( 'WordPress Debug Mode', 'usces' ) . ' : ' . ( ( $environment['wp_debug_mode'] ) ? __( 'ON', 'usces' ) : __( 'OFF', 'usces' ) ) . "\r\n";
5326 +
5327 + $data .= "\r\n" . '### ' . __( 'Theme', 'usces' ) . " ###\r\n\r\n";
5328 + $data .= __( 'Theme name', 'usces' ) . ' : ' . esc_html( $theme['name'] ) . "\r\n";
5329 + $data .= __( 'Theme version', 'usces' ) . ' : ' . esc_html( $theme['version'] ) . "\r\n";
5330 + $data .= __( 'Author URL', 'usces' ) . ' : ' . esc_html( $theme['author_url'] ) . "\r\n";
5331 + if ( isset( $theme['is_child_theme'] ) && $theme['is_child_theme'] ) {
5332 + $data .= __( 'Parent theme name', 'usces' ) . ' : ' . esc_html( $theme['parent_name'] ) . "\r\n";
5333 + $data .= __( 'Parent theme version', 'usces' ) . ' : ' . esc_html( $theme['parent_version'] ) . "\r\n";
5334 + $data .= __( 'Parent author URL', 'usces' ) . ' : ' . esc_html( $theme['parent_author_url'] ) . "\r\n";
5335 + }
5336 +
5337 + $data .= "\r\n" . '### ' . __( 'Active Plugins', 'usces' ) . " ###\r\n\r\n";
5338 + foreach ( $active_plugins as $plugin ) {
5339 + $data .= esc_html( $plugin['name'] ) . ' : ' . __( 'by', 'usces' ) . ' ' . esc_html( $plugin['author_name'] ) . ' - ' . esc_html( $plugin['version'] ) .
5340 + esc_html( ( $plugin['version'] != $plugin['version_latest'] ) ? sprintf( __( '( Update to version %1$s is available. )', 'usces' ), $plugin['version_latest'] ) : '' ) . "\r\n";
5341 + }
5342 +
5343 + $data .= "\r\n" . '### ' . __( 'Inactive Plugins', 'usces' ) . " ###\r\n\r\n";
5344 + foreach ( $inactive_plugins as $plugin ) {
5345 + $data .= esc_html( $plugin['name'] ) . ' : ' . __( 'by', 'usces' ) . ' ' . esc_html( $plugin['author_name'] ) . ' - ' . esc_html( $plugin['version'] ) .
5346 + esc_html( ( $plugin['version'] != $plugin['version_latest'] ) ? sprintf( __( '( Update to version %1$s is available. )', 'usces' ), $plugin['version_latest'] ) : '' ) . "\r\n";
5347 + }
5348 + $data .= "\r\n" . '### ' . __( 'General Setting', 'usces' ) . " ###\r\n\r\n";
5349 + $data .= __( 'Welcart Version', 'usces' ) . ' : ' . esc_html( $welcart_information['version'] ) . "\r\n";
5350 + $data .= __( 'number of item', 'usces' ) . ' : ' . esc_html( $welcart_information['total_items'] ) . "\r\n";
5351 + $data .= __( 'SKU total number', 'usces' ) . ' : ' . esc_html( $welcart_information['total_sku'] ) . "\r\n";
5352 + $data .= __( 'Display mode', 'usces' ) . ' : ' . ( ( $welcart_information['maintenance_mode'] ) ? __( 'Under Maintenance', 'usces' ) : __( 'Normal business', 'usces' ) ) . "\r\n";
5353 + $data .= __( 'Campaign Schedule', 'usces' ) . ' : ' . __( 'starting time', 'usces' ) . ': ';
5354 + foreach ( $welcart_information['campaign_schedule']['start'] as $key => $value ) {
5355 + $data .= esc_html( $value ) . ' ' . __( $key, 'usces' );
5356 + }
5357 + $data .= '. ' . __( 'date and time of termination', 'usces' ) . ': ';
5358 + foreach ( $welcart_information['campaign_schedule']['end'] as $key => $value ) {
5359 + $data .= esc_html( $value ) . ' ' . __( $key, 'usces' ) . ' ';
5360 + }
5361 + $data .= "\r\n";
5362 +
5363 + $data .= __( 'E-mail address for ordering', 'usces' ) . ' : ' . esc_html( $welcart_information['order_mail'] ) . "\r\n";
5364 + $data .= __( 'Sender\'s e-mail address', 'usces' ) . ' : ' . esc_html( $welcart_information['sender_mail'] ) . "\r\n";
5365 + $data .= __( 'Conditions for free shipping', 'usces' ) . ' : ' . ( ( ! empty( $welcart_information['postage_privilege'] ) ) ? esc_html( $welcart_information['postage_privilege'] ) . __( 'Above', 'usces' ) : '' ) . "\r\n";
5366 + $data .= __( 'default limitation number of purchase', 'usces' ) . ' : ' . ( ( ! empty( $welcart_information['purchase_limit'] ) ) ? esc_html( $welcart_information['purchase_limit'] ) . __( 'maximum amount', 'usces' ) : '' ) . "\r\n";
5367 + $data .= __( 'initial value of date of sending out.', 'usces' ) . ' : ' . ( ( isset( $welcart_information['shipping_rule_text'][ $welcart_information['shipping_rule'] ] ) ) ? esc_html( $welcart_information['shipping_rule_text'][ $welcart_information['shipping_rule'] ] ) : '' ) . "\r\n";
5368 + $data .= __( 'Tax treatment', 'usces' ) . ' : ' . ( ( $welcart_information['tax_mode'] == 'include' ) ? __( 'Included', 'usces' ) : __( 'Excluded', 'usces' ) ) . "\r\n";
5369 + $data .= __( 'Tax target', 'usces' ) . ' : ' . ( ( $welcart_information['tax_target'] == 'products' ) ? __( 'Only Products', 'usces' ) : __( 'All Amount', 'usces' ) ) . "\r\n";
5370 + $data .= __( 'Applicable tax rate', 'usces' ) . ' : ' . ( ( $welcart_information['applicable_taxrate'] == 'standard' ) ? __( 'Standard tax rate', 'usces' ) : __( 'Reduced tax rate', 'usces' ) ) . "\r\n";
5371 + $data .= __( 'Percentage of Consumption tax', 'usces' ) . ' : ' . esc_html( ucfirst( $welcart_information['tax_rate'] ) ) . ' %' . "\r\n";
5372 + $data .= __( 'Reduced tax rate', 'usces' ) . ' : ' . esc_html( $welcart_information['reduced_tax_rate'] ) . ' %' . "\r\n";
5373 + $data .= __( 'method of Calculation of the tax', 'usces' ) . ' : ';
5374 + switch ( $welcart_information['tax_method'] ) {
5375 + case 'cutting':
5376 + $data .= __( 'drop fractions', 'usces' ) . "\r\n";
5377 + break;
5378 + case 'bring':
5379 + $data .= __( 'raise to a unit', 'usces' ) . "\r\n";
5380 + break;
5381 + case 'rounding':
5382 + $data .= __( 'round up numbers of five and above and round down anything under', 'usces' ) . "\r\n";
5383 + break;
5384 + default:
5385 + break;
5386 + }
5387 +
5388 + $data .= __( 'Subject to fees', 'usces' ) . ' : ' . ( ( $welcart_information['fee_subject'] == 'products' ) ? __( 'Only Products', 'usces' ) : __( 'All Amount', 'usces' ) ) . "\r\n";
5389 + $data .= __( 'membership syetem', 'usces' ) . ' : ' . ( ( $welcart_information['membership_system'] == 'activate' ) ? __( 'to use', 'usces' ) : __( 'not to use', 'usces' ) ) . "\r\n";
5390 + $data .= __( 'membership points', 'usces' ) . ' : ' . ( ( $welcart_information['membership_point'] == 'activate' ) ? __( 'to grant', 'usces' ) : __( 'not to grant', 'usces' ) ) . "\r\n";
5391 + $data .= __( 'Areas of Point Redemption', 'usces' ) . ' : ' . ( ( $welcart_information['point_coverage'] ) ? __( 'Applicable to Total Merchandise Price and Handling Fee', 'usces' ) : __( 'Limited Only to Total Merchandise Price', 'usces' ) ) . "\r\n";
5392 + $data .= __( 'Timing point of grant', 'usces' ) . ' : ' . ( ( $welcart_information['point_assign'] ) ? __( 'Payment at the time', 'usces' ) : __( 'Immediately', 'usces' ) ) . "\r\n";
5393 +
5394 + $data .= "\r\n" . '### ' . __( 'payment method', 'usces' ) . " ###\r\n\r\n";
5395 + foreach ( $welcart_information['payment_methods'] as $payment ) {
5396 + $data .= esc_html( $payment['name'] ) . ' - ' . ( ( isset( $welcart_information['payment_structure'][ $payment['settlement'] ] ) ) ? ( esc_html( $welcart_information['payment_structure'][ $payment['settlement'] ] ) ) : '' ) . ' - ' . ( ( $payment['use'] == 'activate' ) ? __( 'Activate', 'usces' ) : __( 'Deactivate', 'usces' ) ) . "\r\n";
5397 + }
5398 +
5399 + $data .= "\r\n" . '### ' . __( 'Common Options', 'usces' ) . " ###\r\n\r\n";
5400 + foreach ( $welcart_information['common_options'] as $common_options ) {
5401 + $data .= __( 'option name', 'usces' ) . ' : ' . esc_html( $common_options['name'] ) . "\r\n";
5402 + $data .= __( 'selected amount', 'usces' ) . ' : ' . ( str_replace( "\n", ' ', $common_options['value'] ) ) . "\r\n";
5403 + $data .= __( 'Type of option', 'usces' ) . ' : ' . esc_html( ( isset( $welcart_information['common_options_type'][ $common_options['means'] ] ) ) ? ( esc_html( $welcart_information['common_options_type'][ $common_options['means'] ] ) ) : '' ) . "\r\n";
5404 + $data .= __( 'Required', 'usces' ) . ' : ' . ( ( 1 === (int) $common_options['essential'] ) ? __( 'Essential', 'usces' ) : '' ) . "\r\n\r\n";
5405 + }
5406 +
5407 + $data .= "\r\n" . '### ' . __( 'shipping option', 'usces' ) . " ###\r\n\r\n";
5408 + foreach ( $welcart_information['shipping_methods'] as $shipping ) {
5409 + $charge = '';
5410 + $delivery_day = '';
5411 + if ( -1 === $shipping['charge'] ) {
5412 + $charge = esc_html__( 'Not fixing shipping.', 'usces' );
5413 + } else {
5414 + foreach ( $welcart_information['shipping_charge'] as $shipping_charge ) {
5415 + if ( $shipping['charge'] == $shipping_charge['id'] ) {
5416 + $charge = $shipping_charge['name'];
5417 + break;
5418 + }
5419 + }
5420 + }
5421 + if ( -1 === $shipping['days'] ) {
5422 + $delivery_day = esc_html__( 'Delivery Date Not Specified', 'usces' );
5423 + } else {
5424 + foreach ( $welcart_information['delivery_days'] as $day ) {
5425 + if ( $shipping['days'] == $day['id'] ) {
5426 + $delivery_day = $day['name'];
5427 + break;
5428 + }
5429 + }
5430 + }
5431 + $data .= esc_html( $shipping['name'] ) . ' - ' . ( str_replace( "\n", ' ', $shipping['time'] ) ) . ' - ' . ( ( $shipping['intl'] ) ? __( 'International Shipment', 'usces' ) : __( 'Domestic Shipment', 'usces' ) ) . ' - ';
5432 + $data .= esc_html( $charge ) . ' - ' . esc_html( $delivery_day ) . ( ( $shipping['nocod'] ) ? ' - ' . __( 'No COD', 'usces' ) : '' ) . "\r\n";
5433 + }
5434 +
5435 + $data .= "\r\n" . '### ' . __( 'Shipping', 'usces' ) . " ###\r\n\r\n";
5436 + foreach ( $welcart_information['shipping_charge'] as $shipping_charge ) {
5437 + $data .= esc_html( $shipping_charge['name'] ) . "\r\n";
5438 + }
5439 +
5440 + $data .= "\r\n" . '### ' . __( 'Mail Options', 'usces' ) . " ###\r\n\r\n";
5441 + $data .= __( 'New sign-in completion email', 'usces' ) . ' : ' . ( ( $welcart_information['newmem_admin_mail'] ) ? __( 'Send', 'usces' ) : __( 'Don\'t send', 'usces' ) ) . "\r\n";
5442 + $data .= __( 'Member update completion email to admin', 'usces' ) . ' : ' . ( ( $welcart_information['updmem_admin_mail'] ) ? __( 'Send', 'usces' ) : __( 'Don\'t send', 'usces' ) ) . "\r\n";
5443 + $data .= __( 'Member update completion email to customer', 'usces' ) . ' : ' . ( ( $welcart_information['updmem_customer_mail'] ) ? __( 'Send', 'usces' ) : __( 'Don\'t send', 'usces' ) ) . "\r\n";
5444 + $data .= __( 'Member removal completion email to admin', 'usces' ) . ' : ' . ( ( $welcart_information['delmem_admin_mail'] ) ? __( 'Send', 'usces' ) : __( 'Don\'t send', 'usces' ) ) . "\r\n";
5445 + $data .= __( 'Member removal completion email to customer', 'usces' ) . ' : ' . ( ( $welcart_information['delmem_customer_mail'] ) ? __( 'Send', 'usces' ) : __( 'Don\'t send', 'usces' ) ) . "\r\n";
5446 + $data .= __( 'Customer name', 'usces' ) . ' : ' . ( ( $welcart_information['put_customer_name'] ) ? __( 'Indication', 'usces' ) : __( 'Non-indication', 'usces' ) ) . "\r\n";
5447 + $data .= __( 'Attachment file for administrator email', 'usces' ) . ' : ' . ( ( $welcart_information['email_attach_feature'] ) ? __( 'Use', 'usces' ) : __( 'Do not Use', 'usces' ) ) . "\r\n";
5448 + if ( $welcart_information['email_attach_feature'] ) {
5449 + $data .= __( 'Extensions of attachments', 'usces' ) . ' : ' . esc_html( $welcart_information['email_attach_file_extension'] ) . "\r\n";
5450 + $data .= __( 'Maximum size of email attachment', 'usces' ) . ' : ' . esc_html( $welcart_information['email_attach_file_size'] ) . " Mb\r\n";
5451 + }
5452 + $data .= __( 'HTML mail format', 'usces' ) . ' : ' . ( ( $welcart_information['add_html_email_option'] ) ? __( 'Use', 'usces' ) : __( 'Do not Use', 'usces' ) ) . "\r\n";
5453 +
5454 + $data .= "\r\n" . '### ' . __( 'Rule of the column for a item name', 'usces' ) . " ###\r\n\r\n";
5455 + foreach ( $welcart_information['indi_item_name'] as $key => $value ) {
5456 + $data .= __( "Indication of {$welcart_information['indi_item_name_text'][ $key ]}", 'usces' ) . ' : ' . ( ( $value ) ? __( 'Show', 'usces' ) : '' ) . "\r\n";
5457 + $data .= __( "Position of {$welcart_information['indi_item_name_text'][ $key ]}", 'usces' ) . ' : ' . esc_html( $welcart_information['pos_item_name'][ $key ] ) . "\r\n";
5458 + }
5459 + $data .= "\r\n" . '### ' . __( 'System Setting', 'usces' ) . " ###\r\n\r\n";
5460 + $data .= __( 'Display Modes', 'usces' ) . ' : ' . ( ( $welcart_information['divide_item'] ) ? __( 'Not display an article in blog', 'usces' ) : '' ) . "\r\n";
5461 + $data .= __( 'rel attribute', 'usces' ) . ' : ' . ( ( $welcart_information['itemimg_anchor_rel'] ) ? $welcart_information['itemimg_anchor_rel'] : '' ) . "\r\n";
5462 + $data .= __( 'compound category sort item', 'usces' ) . ' : ' . ( ( 'name' == $welcart_information['fukugo_category_orderby'] ) ? __( 'category name', 'usces' ) : __( 'category ID', 'usces' ) ) . "\r\n";
5463 + $data .= __( 'compound category sort order', 'usces' ) . ' : ' . ( ( 'DESC' == $welcart_information['fukugo_category_order'] ) ? __( 'Descendin', 'usces' ) : __( 'Ascending', 'usces' ) ) . "\r\n";
5464 + $data .= __( 'Switching SSL', 'usces' ) . ' : ' . ( ( $welcart_information['use_ssl'] ) ? __( 'Switching', 'usces' ) : '' ) . "\r\n";
5465 + $data .= __( 'The page_id of the inquiry-form', 'usces' ) . ' : ' . esc_html( $welcart_information['inquiry_id'] ) . "\r\n";
5466 + $data .= __( 'To disable usces_cart.css', 'usces' ) . ' : ' . ( ( $welcart_information['no_cart_css'] ) ? __( 'To disable', 'usces' ) : '' ) . "\r\n";
5467 + $data .= __( 'Product sub-image rule', 'usces' ) . ' : ' . ( ( $welcart_information['subimage_rule'] ) ? __( 'Put two _ (underscores) between the product code and the sequential number', 'usces' ) : __( 'Product Code Forward Matching', 'usces' ) ) . "\r\n";
5468 + $data .= __( 'Described method of invoice', 'usces' ) . ' : ' . ( ( $welcart_information['pdf_delivery'] ) ? __( 'To address the shipping information', 'usces' ) : __( 'To address the purchaser information', 'usces' ) ) . "\r\n";
5469 + $data .= __( 'Character code in the CSV file', 'usces' ) . ' : ' . ( ( $welcart_information['csv_encode_type'] ) ? __( 'UTF-8', 'usces' ) : __( 'Shift_JIS', 'usces' ) ) . "\r\n";
5470 + $data .= __( "'Category' of CSV product data file", 'usces' ) . ' : ' . ( ( $welcart_information['csv_category_format'] ) ? __( 'slug (slug)', 'usces' ) : __( 'ID (tag_ID)', 'usces' ) ) . "\r\n";
5471 + $data .= __( 'Order data re-created from the settlement log', 'usces' ) . ' : ' . ( ( $welcart_information['settlement_backup'] ) ? __( 'Use', 'usces' ) : __( 'Do not Use', 'usces' ) ) . "\r\n";
5472 + $data .= __( 'Settlement error message', 'usces' ) . ' : ' . ( ( $welcart_information['settlement_notice'] ) ? __( 'Display', 'usces' ) : __( 'Do not display', 'usces' ) ) . "\r\n";
5473 + $data .= __( 'The language of the front-end', 'usces' ) . ' : ' . esc_html( $welcart_information['front_lang'] ) . "\r\n";
5474 + $data .= __( 'Currencies', 'usces' ) . ' : ' . ( ( isset( $welcart_information['country'][ $welcart_information['currency'] ] ) ) ? esc_html( $welcart_information['country'][ $welcart_information['currency'] ] ) : esc_html( $welcart_information['currency'] ) ) . "\r\n";
5475 + $data .= __( 'The name and address form', 'usces' ) . ' : ' . ( ( isset( $welcart_information['country'][ $welcart_information['addressform'] ] ) ) ? esc_html( $welcart_information['country'][ $welcart_information['addressform'] ] ) : esc_html( $welcart_information['currency'] ) ) . "\r\n";
5476 +
5477 + $target_market_country = array();
5478 + foreach ( $welcart_information['target_market'] as $key => $value ) {
5479 + if ( isset( $welcart_information['country'][ $value ] ) ) {
5480 + $target_market_country[] = $welcart_information['country'][ $value ];
5481 + }
5482 + }
5483 + $data .= __( 'Target Market', 'usces' ) . ' : ' . esc_html( implode( ', ', $target_market_country ) ) . "\r\n";
5484 +
5485 + $data .= "\r\n" . '### ' . __( 'System extension', 'usces' ) . " ###\r\n\r\n";
5486 + $data .= __( 'Ganbare Tencho', 'usces' ) . ' : ' . ( ( $welcart_information['ganbare_activate_flag'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5487 + $data .= __( 'Linkage Order Upadate', 'usces' ) . ' : ' . ( ( $welcart_information['stocklink_orderedit_flag'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5488 + $data .= __( 'Linkage Order Collective Upadate', 'usces' ) . ' : ' . ( ( $welcart_information['stocklink_collective_flag'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5489 + $data .= __( '[New] Order List', 'usces' ) . ' : ' . ( ( $welcart_information['datalistup_orderlist_flag'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5490 + $data .= __( '[New] Member List', 'usces' ) . ' : ' . ( ( $welcart_information['datalistup_memberlist_flag'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5491 + $data .= __( 'Email verification for new registration', 'usces' ) . ' : ' . ( ( $welcart_information['verifyemail_switch_flag'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5492 + $data .= __( 'Email verification for editing information', 'usces' ) . ' : ' . ( ( $welcart_information['verifyemail_edit_flag'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5493 + $data .= __( 'Login Notification', 'usces' ) . ' : ' . ( ( $welcart_information['verifyemail_login_notify'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5494 + $data .= __( 'Google reCAPTCHA v3', 'usces' ) . ' : ' . ( ( $welcart_information['google_recaptcha_status'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5495 + $data .= __( 'Brute-force attack countermeasures', 'usces' ) . ' : ' . ( ( $welcart_information['brute_force_status'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5496 + $data .= __( 'Structured data measures', 'usces' ) . ' : ' . ( ( $welcart_information['structured_data_product_status'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5497 + $data .= __( 'New product image registration', 'usces' ) . ' : ' . ( ( $welcart_information['newproductimage_switch_flag'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5498 + $data .= __( 'Operation Log', 'usces' ) . ' : ' . ( ( $welcart_information['operation_log_switch_flag'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5499 + $data .= __( 'Credit Card Security Measures', 'usces' ) . ' : ' . ( ( $welcart_information['credit_security'] ) ? __( 'Enabled', 'usces' ) : __( 'Disabled', 'usces' ) ) . "\r\n";
5500 +
5501 + $data .= "\r\n" . '### ' . __( 'Settlement Setting', 'usces' ) . " ###\r\n\r\n";
5502 + $settlement_selected_text = array();
5503 + if ( is_array( $welcart_information['settlement_selected'] ) ) {
5504 + foreach ( $welcart_information['settlement_selected'] as $key => $value ) {
5505 + if ( isset( $welcart_information['available_settlement'][ $value ] ) ) {
5506 + $settlement_selected_text[] = esc_html__( $welcart_information['available_settlement'][ $value ], 'usces' );
5507 + }
5508 + }
5509 + }
5510 + $data .= __( 'Settlement modules in use', 'usces' ) . ' : ' . esc_html( implode( ', ', $settlement_selected_text ) ) . "\r\n";
5511 +
5512 + $data .= "\r\n" . '### ' . __( 'Management Information', 'usces' ) . " ###\r\n\r\n";
5513 + $data .= __( 'Number of orders', 'usces' ) . ' : ' . esc_html( $welcart_information['number_of_orders'] ) . "\r\n";
5514 + $data .= __( 'Number of members', 'usces' ) . ' : ' . esc_html( $welcart_information['number_of_members'] ) . "\r\n";
5515 +
5516 + $data .= "\r\n" . '### ' . __( 'Server environment', 'usces' ) . " ###\r\n\r\n";
5517 + $data .= __( 'Server', 'usces' ) . ' : ' . esc_html( $environment['server'] ) . "\r\n";
5518 + $data .= __( 'PHP version', 'usces' ) . ' : ' . esc_html( $environment['php_version'] ) . "\r\n";
5519 + $data .= __( 'PHP global memory', 'usces' ) . ' : ' . esc_html( $ini_confs['memory_limit']['global_value'] ) . "\r\n";
5520 + $data .= __( 'PHP locale memory', 'usces' ) . ' : ' . esc_html( $ini_confs['memory_limit']['local_value'] ) . "\r\n";
5521 + $data .= __( 'PHP post max size', 'usces' ) . ' : ' . esc_html( $environment['php_post_max_size'] ) . "\r\n";
5522 + $data .= __( 'PHP time limit', 'usces' ) . ' : ' . esc_html( $environment['php_max_execution_time'] ) . "\r\n";
5523 + $data .= __( 'PHP Max Input Vars', 'usces' ) . ' : ' . esc_html( $environment['php_max_input_vars'] ) . "\r\n";
5524 + $data .= __( 'cURL', 'usces' ) . ' : ' . ( in_array( 'curl', $loaded_extensions ) ? 'ON' : '-' ) . "\r\n";
5525 + $data .= __( 'cURL version', 'usces' ) . ' : ' . ( esc_html( $environment['curl_version']['version'] . ' ' . $environment['curl_version']['host'] ) ) . "\r\n";
5526 + $data .= __( 'MySQL version', 'usces' ) . ' : ' . esc_html( $environment['mysql_version'] ) . "\r\n";
5527 + $data .= __( 'Maximum upload size', 'usces' ) . ' : ' . esc_html( $environment['upload_max_filesize'] ) . "\r\n";
5528 + $data .= __( 'SimpleXML', 'usces' ) . ' : ' . ( in_array( 'SimpleXML', $loaded_extensions ) ? 'ON' : '-' ) . "\r\n";
5529 + $data .= __( 'gd', 'usces' ) . ' : ' . ( in_array( 'gd', $loaded_extensions ) ? 'ON' : '-' ) . "\r\n";
5530 + $data .= __( 'json', 'usces' ) . ' : ' . ( in_array( 'json', $loaded_extensions ) ? 'ON' : '-' ) . "\r\n";
5531 + $data .= __( 'mbstring', 'usces' ) . ' : ' . ( in_array( 'mbstring', $loaded_extensions ) ? 'ON' : '-' ) . "\r\n";
5532 + $data .= __( 'openssl', 'usces' ) . ' : ' . ( in_array( 'openssl', $loaded_extensions ) ? 'ON' : '-' ) . "\r\n";
5533 +
5534 + return $data;
5535 +}
5536 +
5537 +function usces_download_system_information() {
5538 +
5539 + check_ajax_referer( 'admin_system' );
5540 + if ( ! current_user_can( 'wel_manage_setting' ) ) {
5541 + wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
5542 + }
5543 +
5544 + $filename = 'welcart_information_' . date_i18n( 'YmdHis' ) . '.txt';
5545 + $wp_environment = usces_get_wp_environment();
5546 + $environment = $wp_environment['environment'];
5547 + $theme = $wp_environment['theme'];
5548 + $active_plugins = $wp_environment['active_plugins'];
5549 + $inactive_plugins = $wp_environment['inactive_plugins'];
5550 + $welcart_information = get_welcart_system_information();
5551 + $loaded_extensions = get_loaded_extensions();
5552 + $ini_confs = ini_get_all();
5553 + $data = usces_generate_system_information_text( $environment, $theme, $active_plugins, $inactive_plugins, $welcart_information, $loaded_extensions, $ini_confs );
5554 + $result = array(
5555 + 'status' => true,
5556 + 'data' => $data,
5557 + 'filename' => $filename,
5558 + );
5559 + echo json_encode( $result );
5560 + wp_die();
5561 +}
5562 +
5563 +/**
5564 + * List Download Authority.
5565 + *
5566 + * @return boolean
5567 + */
5568 +function usces_admin_user_can_download_list() {
5569 + $admin_user = array( 'administrator', 'wc_management' );
5570 + $custom_user = apply_filters( 'usces_filter_admin_user_can_download_list', array() );
5571 + if ( is_array( $custom_user ) && ! empty( $custom_user ) ) {
5572 + $admin_user = array_merge( $admin_user, $custom_user );
5573 + }
5574 + $can_dl = false;
5575 + foreach ( $admin_user as $user ) {
5576 + if ( current_user_can( $user ) ) {
5577 + $can_dl = true;
5578 + break;
5579 + }
5580 + }
5581 + return $can_dl;
5582 +}
5583 +
5584 +/**
5585 + * Filter content wp_editor preview.
5586 + */
5587 +function usces_filter_content_wp_editor_preview() {
5588 + global $usces;
5589 +
5590 + $_POST = $usces->stripslashes_deep_post( $_POST );
5591 +
5592 + if ( ! current_user_can( 'wel_manage_order' ) ) { // This preview is also used in order_edit_form.
5593 + wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
5594 + }
5595 +
5596 + $nonce = isset( $_POST['wc_nonce'] ) ? wp_unslash( $_POST['wc_nonce'] ) : '';
5597 + if ( ! wp_verify_nonce( $nonce, 'wc_preview_editor_nonce' ) ) {
5598 + $error_msg = array( 'message' => 'Your request is not valid.' );
5599 + wp_send_json_error( $error_msg, 403 );
5600 + }
5601 + $mode = $_POST['mode'];
5602 + $res = array(
5603 + 'status' => false,
5604 + );
5605 + switch ( $mode ) {
5606 + case 'preview_email':
5607 + $content_header = isset( $_POST['content_header'] ) ? $_POST['content_header'] : '';
5608 + $content_footer = isset( $_POST['content_footer'] ) ? $_POST['content_footer'] : '';
5609 + $res['status'] = true;
5610 + $res['content_header'] = wpautop( $content_header );
5611 + $res['content_footer'] = wpautop( $content_footer );
5612 + break;
5613 + case 'preview_email_order_detail':
5614 + $content = isset( $_POST['content'] ) ? $_POST['content'] : '';
5615 + $res['status'] = true;
5616 + $res['content'] = wpautop( wp_kses_post( $content ) );
5617 + break;
5618 + }
5619 + wp_send_json( $res );
5620 +}
5621 +
5622 +/**
5623 + * 手数料対象金額
5624 + * -'all' 送料を含む全額
5625 + * -'products' 商品代金のみ
5626 + *
5627 + * @return string
5628 + */
5629 +function usces_is_fee_subject() {
5630 + global $usces;
5631 + $fee_subject = ( ! empty( $usces->options['fee_subject'] ) ) ? $usces->options['fee_subject'] : 'all';
5632 + return $fee_subject;
5633 +}