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 -4281 1.3.92.12.4 View file →
@@ -1,4281 +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 - }
97 -
98 - $meisai = __('Items','usces') . " : \r\n";
99 - foreach ( (array)$cart as $cart_row ) {
100 - $post_id = $cart_row['post_id'];
101 - $sku = urldecode($cart_row['sku']);
102 - $quantity = $cart_row['quantity'];
103 - $options = $cart_row['options'];
104 - $itemCode = $usces->getItemCode($post_id);
105 - $itemName = $usces->getItemName($post_id);
106 - $cartItemName = $usces->getCartItemName($post_id, $sku);
107 - $skuPrice = $cart_row['price'];
108 -// $pictids = $usces->get_pictids($itemCode);
109 - if (!empty($options)) {
110 -// $optstr = implode(',', $options);
111 - } else {
112 - $optstr = '';
113 - $options = array();
114 - }
115 -
116 - $meisai .= usces_mail_line( 2, $data['order_email'] );//--------------------
117 - $meisai .= "$cartItemName \r\n";
118 - if( is_array($options) && count($options) > 0 ){
119 - $optstr = '';
120 - foreach($options as $key => $value){
121 -//20110629ysk start 0000190
122 - //if( !empty($key) )
123 - // $meisai .= $key . ' : ' . urldecode($value) . "\r\n";
124 - if( !empty($key) ) {
125 - $key = urldecode($key);
126 - if(is_array($value)) {
127 - $c = '';
128 - $optstr .= $key . ' : ';
129 - foreach($value as $v) {
130 - $optstr .= $c.urldecode($v);
131 - $c = ', ';
132 - }
133 - $optstr .= "\r\n";
134 - } else {
135 - $optstr .= $key . ' : ' . urldecode($value) . "\r\n";
136 - }
137 - }
138 -//20110629ysk end
139 - }
140 - $meisai .= apply_filters( 'usces_filter_option_adminmail', $optstr, $options);
141 - }
142 - $meisai .= __('Unit price','usces') . " ".usces_crform( $skuPrice, true, false, 'return' ) . __(' * ','usces') . $cart_row['quantity'] . "\r\n";
143 - }
144 -
145 - $meisai .= usces_mail_line( 3, $data['order_email'] );//====================
146 - $meisai .= __('total items','usces') . " : " . usces_crform( $data['order_item_total_price'], true, false, 'return' ) . "\r\n";
147 -
148 - if ( $data['order_usedpoint'] != 0 )
149 - $meisai .= __('use of points','usces') . " : " . number_format($data['order_usedpoint']) . __('Points','usces') . "\r\n";
150 - if ( $data['order_discount'] != 0 )
151 - $meisai .= apply_filters('usces_confirm_discount_label', __('Campaign disnount', 'usces'), $order_id) . " : " . usces_crform( $data['order_discount'], true, false, 'return' ) . "\r\n";
152 - $meisai .= __('Shipping','usces') . " : " . usces_crform( $data['order_shipping_charge'], true, false, 'return' ) . "\r\n";
153 - if ( $payment['settlement'] == 'COD' )
154 - $meisai .= apply_filters('usces_filter_cod_label', __('COD fee', 'usces')) . " : " . usces_crform( $data['order_cod_fee'], true, false, 'return' ) . "\r\n";
155 - if ( !empty($usces->options['tax_rate']) )
156 - $meisai .= __('consumption tax','usces') . " : " . usces_crform( $data['order_tax'], true, false, 'return' ) . "\r\n";
157 - $meisai .= usces_mail_line( 2, $data['order_email'] );//--------------------
158 - $meisai .= __('Payment amount','usces') . " : " . usces_crform( $total_full_price, true, false, 'return' ) . "\r\n";
159 - $meisai .= usces_mail_line( 2, $data['order_email'] );//--------------------
160 - $meisai .= "(" . __('Currency', 'usces') . ' : ' . __(usces_crcode( 'return' ), 'usces') . ")\r\n\r\n";
161 -
162 - $msg_body .= apply_filters('usces_filter_order_confirm_mail_meisai', $meisai, $data, $cart);
163 -
164 -
165 -
166 - $msg_shipping = __('** A shipping address **','usces') . "\r\n";
167 - $msg_shipping .= usces_mail_line( 1, $data['order_email'] );//********************
168 -
169 - $msg_shipping .= uesces_get_mail_addressform( 'admin_mail', $deli, $order_id );
170 -
171 -//20101208ysk start
172 - //$msg_shipping .= __('Delivery Time','usces') . " : " . $data['order_delivery_time'] . "\r\n";
173 - if ( $data['order_delidue_date'] == NULL || $data['order_delidue_date'] == '#none#' ) {
174 - $msg_shipping .= "\r\n";
175 - }else{
176 - $msg_shipping .= __('Shipping date', 'usces') . " : " . $data['order_delidue_date'] . "\r\n";
177 - $msg_shipping .= __("* A shipment due date is a day to ship an article, and it's not the arrival day.", 'usces') . "\r\n";
178 - $msg_shipping .= "\r\n";
179 - }
180 - $deli_meth = (int)$data['order_delivery_method'];
181 - if( 0 <= $deli_meth ){
182 - $deli_index = $usces->get_delivery_method_index($deli_meth);
183 - if( 0 <= $deli_index ) $msg_shipping .= __('Delivery Method','usces') . " : " . $usces->options['delivery_method'][$deli_index]['name'] . "\r\n";
184 - }
185 - $msg_shipping .= __('Delivery date','usces') . " : " . $data['order_delivery_date'] . "\r\n";
186 - $msg_shipping .= __('Delivery Time','usces') . " : " . $data['order_delivery_time'] . "\r\n";
187 -//20101208ysk end
188 - $msg_shipping .= "\r\n";
189 - $msg_body .= apply_filters('usces_filter_order_confirm_mail_shipping', $msg_shipping, $data);
190 -
191 -// $msg_body .= __('** For some region, to deliver the items in the morning is not possible.','usces') . "\r\n";
192 -// $msg_body .= __('** WE may not always be able to deliver the items on time which you desire.','usces') . " \r\n";
193 -// $msg_body .= usces_mail_line( 2, $data['order_email'] )."\r\n";
194 -
195 - $msg_payment = __('** Payment method **','usces') . "\r\n";
196 - $msg_payment .= usces_mail_line( 1, $data['order_email'] );//********************
197 - $msg_payment .= $payment['name']. "\r\n\r\n";
198 - if( 'orderConfirmMail' == $_POST['mode'] || 'changeConfirmMail' == $_POST['mode'] || 'mitumoriConfirmMail' == $_POST['mode'] || 'otherConfirmMail' == $_POST['mode'] ) {//20130514ysk start 0000524
199 - if ( $payment['settlement'] == 'transferAdvance' || $payment['settlement'] == 'transferDeferred' ) {
200 - $transferee = __('Transfer','usces') . " : \r\n";
201 - $transferee .= $usces->options['transferee'] . "\r\n";
202 - $msg_payment .= apply_filters('usces_filter_mail_transferee', $transferee, $payment);
203 - $msg_payment .= "\r\n".usces_mail_line( 2, $data['order_email'] )."\r\n";//--------------------
204 -//20101018ysk start
205 - } elseif($payment['settlement'] == 'acting_jpayment_conv') {
206 - $args = maybe_unserialize($usces->get_order_meta_value($payment['settlement'], $order_id));
207 - $msg_payment .= __('決済番号', 'usces').' : '.$args['gid']."\r\n";
208 - $msg_payment .= __('決済金額', 'usces').' : '.number_format($args['ta']).__('dollars','usces')."\r\n";
209 - $msg_payment .= __('お支払先', 'usces').' : '.usces_get_conv_name($args['cv'])."\r\n";
210 - $msg_payment .= __('コンビニ受付番号','usces').' : '.$args['no']."\r\n";
211 - if($args['cv'] != '030') {//ファミリーマート以外
212 - $msg_payment .= __('コンビニ受付番号情報URL', 'usces').' : '.$args['cu']."\r\n";
213 - }
214 - $msg_payment .= "\r\n".usces_mail_line( 2, $data['order_email'] )."\r\n";//--------------------
215 - } elseif($payment['settlement'] == 'acting_jpayment_bank') {
216 - $args = maybe_unserialize($usces->get_order_meta_value($payment['settlement'], $order_id));
217 - $msg_payment .= __('決済番号', 'usces').' : '.$args['gid']."\r\n";
218 - $msg_payment .= __('決済金額', 'usces').' : '.number_format($args['ta']).__('dollars','usces')."\r\n";
219 - $bank = explode('.', $args['bank']);
220 - $msg_payment .= __('銀行コード','usces').' : '.$bank[0]."\r\n";
221 - $msg_payment .= __('銀行名','usces').' : '.$bank[1]."\r\n";
222 - $msg_payment .= __('支店コード','usces').' : '.$bank[2]."\r\n";
223 - $msg_payment .= __('支店名','usces').' : '.$bank[3]."\r\n";
224 - $msg_payment .= __('口座種別','usces').' : '.$bank[4]."\r\n";
225 - $msg_payment .= __('口座番号','usces').' : '.$bank[5]."\r\n";
226 - $msg_payment .= __('口座名義','usces').' : '.$bank[6]."\r\n";
227 - $msg_payment .= __('支払期限','usces').' : '.substr($args['exp'], 0, 4).'年'.substr($args['exp'], 4, 2).'月'.substr($args['exp'], 6, 2)."日\r\n";
228 - $msg_payment .= "\r\n".usces_mail_line( 2, $data['order_email'] )."\r\n";//--------------------
229 -//20101018ysk end
230 - }
231 - }//20130514ysk end
232 -
233 - $msg_body .= apply_filters('usces_filter_order_confirm_mail_payment', $msg_payment, $order_id, $payment, $cart, $data);
234 -
235 -//20100818ysk start
236 - $msg_body .= usces_mail_custom_field_info( 'order', '', $order_id, $data['order_email'] );
237 -//20100818ysk end
238 -
239 - $msg_body .= "\r\n";
240 - $msg_body .= __('** Others / a demand **','usces') . "\r\n";
241 - $msg_body .= usces_mail_line( 1, $data['order_email'] );//********************
242 - $msg_body .= $data['order_note'] . "\r\n\r\n";
243 -// $msg_body .= usces_mail_line( 2, $data['order_email'] )."\r\n";//--------------------
244 -// $msg_body .= "\r\n";
245 -
246 -// $msg_body .= __('Please inform it of any questions from [an inquiry].','usces') . "\r\n";
247 -// $msg_body .= usces_mail_line( 2, $data['order_email'] )."\r\n";//--------------------
248 -
249 - $msg_body .= apply_filters('usces_filter_order_confirm_mail_body', NULL, $data);
250 - $msg_body = apply_filters('usces_filter_order_confirm_mail_bodyall', $msg_body, $data);
251 -
252 - switch ( $_POST['mode'] ) {
253 - case 'completionMail':
254 - $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']);
255 - break;
256 - case 'orderConfirmMail':
257 - $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']);
258 - break;
259 - case 'changeConfirmMail':
260 - $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']);
261 - break;
262 - case 'receiptConfirmMail':
263 - $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']);
264 - break;
265 - case 'mitumoriConfirmMail':
266 - $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']);
267 - break;
268 - case 'cancelConfirmMail':
269 - $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']);
270 - break;
271 - case 'otherConfirmMail':
272 - $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']);
273 - break;
274 - default:
275 - $message = apply_filters( 'usces_filter_order_confirm_mail_body_after', $msg_body, $data );
276 - }
277 - return apply_filters('usces_filter_order_confirm_mail_message', $message, $data);
278 -
279 -}
280 -
281 -function usces_send_ordermail($order_id) {
282 - global $usces, $wpdb;
283 -
284 - $tableName = $wpdb->prefix . "usces_order";
285 - $query = $wpdb->prepare("SELECT * FROM $tableName WHERE ID = %d", $order_id);
286 - $data = $wpdb->get_row( $query, ARRAY_A );
287 -
288 - $cart = $usces->cart->get_cart();
289 - $entry = $usces->cart->get_entry();
290 - $mail_data = $usces->options['mail_data'];
291 - $payment = $usces->getPayments( $entry['order']['payment_name'] );
292 - $res = false;
293 -
294 - $msg_body = "\r\n\r\n\r\n" . __('** content of ordered items **','usces') . "\r\n";
295 - $msg_body .= usces_mail_line( 1, $entry['customer']['mailaddress1'] );//********************
296 - $msg_body .= apply_filters('usces_filter_send_order_mail_first', NULL, $data);
297 -//20110118ysk start
298 - //$msg_body .= usces_mail_custom_field_info( 'customer', 'name_pre', $order_id );
299 -//20110118ysk end
300 - //$msg_body .= __('Buyer','usces') . " : " . sprintf(__('Mr/Mrs %s', 'usces'), usces_localized_name( $entry['customer']['name1'], $entry['customer']['name2'], 'return' )) . "\r\n";
301 - $msg_body .= uesces_get_mail_addressform( 'order_mail_customer', $entry, $order_id );
302 -//20110118ysk start
303 - //$msg_body .= usces_mail_custom_field_info( 'customer', 'name_after', $order_id );
304 -//20110118ysk end
305 - $msg_body .= __('Order number','usces') . " : " . usces_get_deco_order_id( $order_id ) . "\r\n";
306 -
307 - $meisai = __('Items','usces') . " : \r\n";
308 - foreach ( $cart as $cart_row ) {
309 - $post_id = $cart_row['post_id'];
310 - $sku = urldecode($cart_row['sku']);
311 - $quantity = $cart_row['quantity'];
312 - $options = $cart_row['options'];
313 - $itemCode = $usces->getItemCode($post_id);
314 - $itemName = $usces->getItemName($post_id);
315 - $cartItemName = $usces->getCartItemName($post_id, $sku);
316 - $skuPrice = $cart_row['price'];
317 -// $pictids = $usces->get_pictids($itemCode);
318 - if (!empty($options)) {
319 -// $optstr = implode(',', $options);
320 - } else {
321 - $optstr = '';
322 - $options = array();
323 - }
324 -
325 - $meisai .= usces_mail_line( 2, $entry['customer']['mailaddress1'] );//--------------------
326 - $meisai .= "$cartItemName \r\n";
327 - if( is_array($options) && count($options) > 0 ){
328 - $optstr = '';
329 - foreach($options as $key => $value){
330 -//20110629ysk start 0000190
331 - //if( !empty($key) )
332 - // $meisai .= $key . ' : ' . urldecode($value) . "\r\n";
333 - if( !empty($key) ) {
334 - $key = urldecode($key);
335 - if(is_array($value)) {
336 - $c = '';
337 - $optstr .= $key. ' : ';
338 - foreach($value as $v) {
339 - $optstr .= $c.urldecode($v);
340 - $c = ', ';
341 - }
342 - $optstr .= "\r\n";
343 - } else {
344 - $optstr .= $key . ' : ' . urldecode($value) . "\r\n";
345 - }
346 - }
347 -//20110629ysk end
348 - }
349 - $meisai .= apply_filters( 'usces_filter_option_ordermail', $optstr, $options);
350 - }
351 - $meisai .= __('Unit price','usces') . " ".usces_crform( $skuPrice, true, false, 'return' ) . __(' * ','usces') . $cart_row['quantity'] . "\r\n";
352 - }
353 - $meisai .= usces_mail_line( 3, $entry['customer']['mailaddress1'] );//====================
354 - $meisai .= __('total items','usces') . " : " . usces_crform( $entry['order']['total_items_price'], true, false, 'return' ) . "\r\n";
355 -
356 - if ( $entry['order']['usedpoint'] != 0 )
357 - $meisai .= __('use of points','usces') . " : " . number_format($entry['order']['usedpoint']) . __('Points','usces') . "\r\n";
358 -//20120308ysk start 0000433
359 - //if ( $data['order_discount'] != 0 )
360 - if ( $entry['order']['discount'] != 0 )
361 -//20120308ysk end
362 - $meisai .= apply_filters('usces_confirm_discount_label', __('Campaign disnount', 'usces'), $order_id) . " : " . usces_crform( $entry['order']['discount'], true, false, 'return' ) . "\r\n";
363 - $meisai .= __('Shipping','usces') . " : " . usces_crform( $entry['order']['shipping_charge'], true, false, 'return' ) . "\r\n";
364 - if ( $payment['settlement'] == 'COD' )
365 - $meisai .= apply_filters('usces_filter_cod_label', __('COD fee', 'usces')) . " : " . usces_crform( $entry['order']['cod_fee'], true, false, 'return' ) . "\r\n";
366 - if ( !empty($usces->options['tax_rate']) )
367 - $meisai .= __('consumption tax','usces') . " : " . usces_crform( $entry['order']['tax'], true, false, 'return' ) . "\r\n";
368 - $meisai .= usces_mail_line( 2, $entry['customer']['mailaddress1'] );//--------------------
369 - $meisai .= __('Payment amount','usces') . " : " . usces_crform( $entry['order']['total_full_price'], true, false, 'return' ) . "\r\n";
370 - $meisai .= usces_mail_line( 2, $entry['customer']['mailaddress1'] );//--------------------
371 - $meisai .= "(" . __('Currency', 'usces') . ' : ' . __(usces_crcode( 'return' ), 'usces') . ")\r\n\r\n";
372 -
373 -//20120308ysk start 0000433
374 - //$msg_body .= apply_filters('usces_filter_send_order_mail_meisai', $meisai, $data);
375 - $msg_body .= apply_filters('usces_filter_send_order_mail_meisai', $meisai, $data, $cart, $entry);
376 -//20120308ysk end
377 -
378 -
379 - $msg_shipping = __('** A shipping address **','usces') . "\r\n";
380 - $msg_shipping .= usces_mail_line( 1, $entry['customer']['mailaddress1'] );//********************
381 -
382 - $msg_shipping .= uesces_get_mail_addressform( 'order_mail', $entry, $order_id );
383 -
384 -//20101208ysk start
385 - //$msg_shipping .= __('Delivery Time','usces') . " : " . $entry['order']['delivery_time'] . "\r\n";
386 - $deli_meth = (int)$entry['order']['delivery_method'];
387 - if( 0 <= $deli_meth ){
388 - $deli_index = $usces->get_delivery_method_index($deli_meth);
389 - if( 0 <= $deli_index ) $msg_shipping .= __('Delivery Method','usces') . " : " . $usces->options['delivery_method'][$deli_index]['name'] . "\r\n";
390 - }
391 - $msg_shipping .= __('Delivery date','usces') . " : " . $entry['order']['delivery_date'] . "\r\n";
392 - $msg_shipping .= __('Delivery Time','usces') . " : " . $entry['order']['delivery_time'] . "\r\n";
393 -//20101208ysk end
394 -// $msg_body .= usces_mail_line( 2, $entry['customer']['mailaddress1'] );//--------------------
395 -// $msg_body .= __('** For some region, to deliver the items in the morning is not possible.','usces') . "\r\n";
396 -// $msg_body .= " " . __('** WE may not always be able to deliver the items on time which you desire.','usces') . "\r\n";
397 -// $msg_body .= usces_mail_line( 2, $entry['customer']['mailaddress1'] )."\r\n";//--------------------
398 - $msg_shipping .= "\r\n";
399 - $msg_body .= apply_filters('usces_filter_send_order_mail_shipping', $msg_shipping, $data);
400 -
401 - $msg_payment = __('** Payment method **','usces') . "\r\n";
402 - $msg_payment .= usces_mail_line( 1, $entry['customer']['mailaddress1'] );//********************
403 - $msg_payment .= $payment['name'] . usces_payment_detail($entry) . "\r\n\r\n";
404 - if ( $payment['settlement'] == 'transferAdvance' || $payment['settlement'] == 'transferDeferred' ) {
405 - $transferee = __('Transfer','usces') . " : \r\n";
406 - $transferee .= $usces->options['transferee'] . "\r\n";
407 - $msg_payment .= apply_filters('usces_filter_mail_transferee', $transferee, $payment);
408 - $msg_payment .= "\r\n".usces_mail_line( 2, $entry['customer']['mailaddress1'] )."\r\n";//--------------------
409 -//20101018ysk start
410 - } elseif($payment['settlement'] == 'acting_jpayment_conv') {
411 - $args = maybe_unserialize($usces->get_order_meta_value($payment['settlement'], $order_id));
412 - $msg_payment .= __('決済番号', 'usces').' : '.$args['gid']."\r\n";
413 - $msg_payment .= __('決済金額', 'usces').' : '.number_format($args['ta']).__('dollars','usces')."\r\n";
414 - $msg_payment .= __('お支払先', 'usces').' : '.usces_get_conv_name($args['cv'])."\r\n";
415 - $msg_payment .= __('コンビニ受付番号','usces').' : '.$args['no']."\r\n";
416 - if($args['cv'] != '030') {//ファミリーマート以外
417 - $msg_payment .= __('コンビニ受付番号情報URL', 'usces').' : '.$args['cu']."\r\n";
418 - }
419 - $msg_payment .= "\r\n".usces_mail_line( 2, $entry['customer']['mailaddress1'] )."\r\n";//--------------------
420 - } elseif($payment['settlement'] == 'acting_jpayment_bank') {
421 - $args = maybe_unserialize($usces->get_order_meta_value($payment['settlement'], $order_id));
422 - $msg_payment .= __('決済番号', 'usces').' : '.$args['gid']."\r\n";
423 - $msg_payment .= __('決済金額', 'usces').' : '.number_format($args['ta']).__('dollars','usces')."\r\n";
424 - $bank = explode('.', $args['bank']);
425 - $msg_payment .= __('銀行コード','usces').' : '.$bank[0]."\r\n";
426 - $msg_payment .= __('銀行名','usces').' : '.$bank[1]."\r\n";
427 - $msg_payment .= __('支店コード','usces').' : '.$bank[2]."\r\n";
428 - $msg_payment .= __('支店名','usces').' : '.$bank[3]."\r\n";
429 - $msg_payment .= __('口座種別','usces').' : '.$bank[4]."\r\n";
430 - $msg_payment .= __('口座番号','usces').' : '.$bank[5]."\r\n";
431 - $msg_payment .= __('口座名義','usces').' : '.$bank[6]."\r\n";
432 - $msg_payment .= __('支払期限','usces').' : '.substr($args['exp'], 0, 4).'年'.substr($args['exp'], 4, 2).'月'.substr($args['exp'], 6, 2)."日\r\n";
433 - $msg_payment .= "\r\n".usces_mail_line( 2, $entry['customer']['mailaddress1'] )."\r\n";//--------------------
434 -//20101018ysk end
435 - }
436 -
437 - $msg_body .= apply_filters('usces_filter_send_order_mail_payment', $msg_payment, $order_id, $payment, $cart, $entry, $data);
438 -
439 -//20100818ysk start
440 - $msg_body .= usces_mail_custom_field_info( 'order', '', $order_id );
441 -//20100818ysk end
442 -
443 - $msg_body .= "\r\n";
444 - $msg_body .= __('** Others / a demand **','usces') . "\r\n";
445 - $msg_body .= usces_mail_line( 1, $entry['customer']['mailaddress1'] );//********************
446 - $msg_body .= $entry['order']['note'] . "\r\n\r\n";
447 -// $msg_body .= usces_mail_line( 2, $entry['customer']['mailaddress1'] )."\r\n";//--------------------
448 -// $msg_body .= "\r\n";
449 -
450 -// $msg_body .= __('I will inform it of shipment completion by an email.','usces') . "\r\n";
451 -// $msg_body .= __('Please inform it of any questions from [an inquiry].','usces') . "\r\n";
452 -// $msg_body .= usces_mail_line( 2, $entry['customer']['mailaddress1'] )."\r\n";//--------------------
453 -
454 - $msg_body .= apply_filters('usces_filter_send_order_mail_body', NULL, $data);
455 - $msg_body = apply_filters('usces_filter_send_order_mail_bodyall', $msg_body, $data);
456 -
457 - $subject = apply_filters('usces_filter_send_order_mail_subject_thankyou', $mail_data['title']['thankyou'], $data);
458 - $message = do_shortcode($mail_data['header']['thankyou']) . $msg_body . do_shortcode($mail_data['footer']['thankyou']);
459 -//var_dump($msg_body);exit;
460 - $confirm_para = array(
461 - 'to_name' => sprintf(__('Mr/Mrs %s', 'usces'), ($entry["customer"]["name1"] . ' ' . $entry["customer"]["name2"])),
462 - 'to_address' => $entry['customer']['mailaddress1'],
463 - 'from_name' => get_option('blogname'),
464 - 'from_address' => $usces->options['sender_mail'],
465 - 'return_path' => $usces->options['sender_mail'],
466 - 'subject' => $subject,
467 - 'message' => $message
468 - );
469 - $confirm_para = apply_filters( 'usces_send_ordermail_para_to_customer', $confirm_para, $entry, $data);
470 -
471 - //if ( usces_send_mail( $confirm_para ) ) {
472 - usces_send_mail( $confirm_para );
473 -
474 - $subject = apply_filters('usces_filter_send_order_mail_subject_order', $mail_data['title']['order'], $data);
475 - $message = do_shortcode($mail_data['header']['order']) . $msg_body
476 - . $mail_data['footer']['order']
477 - . "\n----------------------------------------------------\n"
478 - . "REMOTE_ADDR : " . $_SERVER['REMOTE_ADDR']
479 - . "\n----------------------------------------------------\n";
480 -
481 - $order_para = array(
482 - 'to_name' => __('An order email','usces'),
483 - 'to_address' => $usces->options['order_mail'],
484 - 'from_name' => sprintf(__('Mr/Mrs %s', 'usces'), ($entry["customer"]["name1"] . ' ' . $entry["customer"]["name2"])),
485 - 'from_address' => $entry['customer']['mailaddress1'],
486 - 'return_path' => $usces->options['error_mail'],
487 - 'subject' => $subject,
488 - 'message' => $message
489 - );
490 -
491 - $order_para = apply_filters( 'usces_send_ordermail_para_to_manager', $order_para, $entry, $data);
492 - $res = usces_send_mail( $order_para );
493 -
494 -// }
495 -
496 - return $res;
497 -
498 -}
499 -
500 -
501 -function usces_send_inquirymail() {
502 - global $usces;
503 - $_POST = $usces->stripslashes_deep_post($_POST);
504 - $res = false;
505 - $mail_data = $usces->options['mail_data'];
506 - $inq_name = trim($_POST["inq_name"]);
507 - $inq_contents = trim($_POST["inq_contents"]);
508 - $inq_mailaddress = trim($_POST["inq_mailaddress"]);
509 - $reserve = '';
510 - if(isset($_POST['reserve'])){
511 - foreach($_POST['reserve'] as $key => $value){
512 - $reserve .= $key . " : " . $value . "\r\n";
513 - }
514 - }
515 - $mats = compact('inq_name','inq_contents','inq_mailaddress','reserve','mail_data');
516 - $subject = apply_filters( 'usces_filter_inquiry_subject_to_customer', $mail_data['title']['inquiry'],$mats);
517 - $message = apply_filters( 'usces_filter_inquiry_header', $mail_data['header']['inquiry'], $inq_name, $inq_mailaddress ) . "\r\n\r\n";
518 - $message .= apply_filters( 'usces_filter_inquiry_reserve', $reserve, $inq_name, $inq_mailaddress );
519 - $message .= apply_filters( 'usces_filter_inq_contents', $inq_contents, $inq_name, $inq_mailaddress ) . "\r\n\r\n";
520 - $message .= apply_filters( 'usces_filter_inq_footer', $mail_data['footer']['inquiry'], $inq_name, $inq_mailaddress );
521 - do_action( 'usces_action_presend_inquiry_mail', $message, $inq_name, $inq_mailaddress );
522 -
523 - $para1 = array(
524 - 'to_name' => sprintf(__('Mr/Mrs %s', 'usces'), $inq_name),
525 - 'to_address' => $inq_mailaddress,
526 - 'from_name' => get_option('blogname'),
527 - 'from_address' => $usces->options['sender_mail'],
528 - 'return_path' => $usces->options['sender_mail'],
529 - 'subject' => $subject,
530 - 'message' => do_shortcode($message),
531 - );
532 -
533 - $res0 = usces_send_mail( $para1 );
534 - if ( $res0 ) {
535 -
536 - $subject = apply_filters( 'usces_filter_inquiry_subject_to_manager', __('** An inquiry **','usces').'('.$inq_name.')',$mats);
537 - $message = $reserve . $_POST['inq_contents'] . "\r\n"
538 - . "\n----------------------------------------------------\n"
539 - . "REMOTE_ADDR : " . $_SERVER['REMOTE_ADDR']
540 - . "\n----------------------------------------------------\n";
541 -
542 - $para2 = array(
543 - 'to_name' => __('An inquiry email','usces'),
544 - 'to_address' => $usces->options['inquiry_mail'],
545 - 'from_name' => sprintf(__('Mr/Mrs %s', 'usces'), $inq_name),
546 - 'from_address' => $inq_mailaddress,
547 - 'return_path' => $usces->options['error_mail'],
548 - 'subject' => $subject,
549 - 'message' => do_shortcode($message),
550 - );
551 - sleep(1);
552 - $res = usces_send_mail( $para2 );
553 -
554 - }
555 -
556 - return $res;
557 -
558 -}
559 -
560 -function usces_send_regmembermail($user) {
561 - global $usces;
562 - $res = false;
563 - $mail_data = $usces->options['mail_data'];
564 - $newmem_admin_mail = $usces->options['newmem_admin_mail'];
565 - $name = usces_localized_name(trim($user['name1']), trim($user['name2']), 'return');
566 - $mailaddress1 = trim($user['mailaddress1']);
567 -
568 - $subject = $mail_data['title']['membercomp'];
569 - $message = $mail_data['header']['membercomp'];
570 - $message .= __('Registration contents', 'usces')."\r\n";
571 - $message .= '--------------------------------'."\r\n";
572 - $message .= __('Member ID', 'usces') . ' : ' . $user['ID'] . "\r\n";
573 - $message .= __('Name', 'usces') . ' : ' . sprintf(__('Mr/Mrs %s', 'usces'), $name) . "\r\n";
574 - $message .= __('e-mail adress', 'usces') . ' : ' . $mailaddress1."\r\n";
575 - $message .= '--------------------------------'."\r\n\r\n";
576 - $message .= $mail_data['footer']['membercomp'];
577 - $message = apply_filters('usces_filter_send_regmembermail_message', $message, $user);
578 -
579 - $para1 = array(
580 - 'to_name' => sprintf(__('Mr/Mrs %s', 'usces'), $name),
581 - 'to_address' => $mailaddress1,
582 - 'from_name' => get_option('blogname'),
583 - 'from_address' => $usces->options['sender_mail'],
584 - 'return_path' => $usces->options['sender_mail'],
585 - 'subject' => $subject,
586 - 'message' => do_shortcode($message),
587 - );
588 - $para1 = apply_filters( 'usces_filter_send_regmembermail_para1', $para1 );
589 - $res = usces_send_mail( $para1 );
590 -
591 - if($newmem_admin_mail){
592 -
593 - $subject = __('New sign-in processing was completed.', 'usces');
594 - $message = __('New sign-in processing was completed.', 'usces') . "\r\n\r\n";
595 - $message .= __('Registration contents', 'usces')."\r\n";
596 - $message .= '--------------------------------'."\r\n";
597 - $message .= __('Member ID', 'usces') . ' : ' . $user['ID'] . "\r\n";
598 - $message .= __('Name', 'usces') . ' : ' . sprintf(__('Mr/Mrs %s', 'usces'), $name) . "\r\n";
599 - $message .= __('e-mail adress', 'usces') . ' : ' . $mailaddress1."\r\n";
600 - $message .= '--------------------------------'."\r\n\r\n";
601 - $message = apply_filters('usces_filter_send_regmembermail_notice', $message, $user);
602 -
603 - $para2 = array(
604 - 'to_name' => __('Notice of new sign-in', 'usces'),
605 - 'to_address' => $usces->options['order_mail'],
606 - 'from_name' => get_option('blogname'),
607 - 'from_address' => $usces->options['sender_mail'],
608 - 'return_path' => $usces->options['sender_mail'],
609 - 'subject' => $subject,
610 - 'message' => do_shortcode($message),
611 - );
612 - $para2 = apply_filters( 'usces_filter_send_regmembermail_para2', $para2 );
613 - usces_send_mail( $para2 );
614 - }
615 -
616 - return $res;
617 -
618 -}
619 -
620 -function usces_send_delmembermail( $user ) {
621 - global $usces;
622 - $res = true;
623 - $mail_data = $usces->options['mail_data'];
624 - $delmem_admin_mail = $usces->options['delmem_admin_mail'];
625 - $delmem_customer_mail = $usces->options['delmem_customer_mail'];
626 - $name = usces_localized_name(trim($user['name1']), trim($user['name2']), 'return');
627 - $mailaddress1 = trim($user['mailaddress1']);
628 - $subject = apply_filters( 'usces_filter_send_delmembermail_subject', __('Member removal processing was completed.', 'usces'), $user );
629 -
630 - if( $delmem_customer_mail ) {
631 - $message = $subject."\r\n\r\n";
632 - $message .= __('Registration contents', 'usces')."\r\n";
633 - $message .= '--------------------------------'."\r\n";
634 - $message .= __('Member ID', 'usces').' : '.$user['ID']."\r\n";
635 - $message .= __('Name', 'usces').' : '.sprintf(__('Mr/Mrs %s', 'usces'), $name)."\r\n";
636 - $message .= __('e-mail adress', 'usces').' : '.$mailaddress1."\r\n";
637 - $message .= '--------------------------------'."\r\n\r\n";
638 - $message .= $mail_data['footer']['membercomp'];
639 - $message = apply_filters( 'usces_filter_send_delmembermail_message', $message, $user );
640 -
641 - $para1 = array(
642 - 'to_name' => sprintf(__('Mr/Mrs %s', 'usces'), $name),
643 - 'to_address' => $mailaddress1,
644 - 'from_name' => get_option('blogname'),
645 - 'from_address' => $usces->options['sender_mail'],
646 - 'return_path' => $usces->options['sender_mail'],
647 - 'subject' => $subject,
648 - 'message' => do_shortcode($message),
649 - );
650 - $para1 = apply_filters( 'usces_filter_send_delmembermail_para1', $para1 );
651 - $res = usces_send_mail( $para1 );
652 - }
653 -
654 - if( $delmem_admin_mail ) {
655 - $message = $subject."\r\n\r\n";
656 - $message .= __('Registration contents', 'usces')."\r\n";
657 - $message .= '--------------------------------'."\r\n";
658 - $message .= __('Member ID', 'usces').' : '.$user['ID']."\r\n";
659 - $message .= __('Name', 'usces').' : '.sprintf(__('Mr/Mrs %s', 'usces'), $name)."\r\n";
660 - $message .= __('e-mail adress', 'usces') . ' : '.$mailaddress1."\r\n";
661 - $message .= '--------------------------------'."\r\n\r\n";
662 - $message = apply_filters( 'usces_filter_send_delmembermail_notice', $message, $user );
663 -
664 - $para2 = array(
665 - 'to_name' => __('Notice of new sign-in', 'usces'),
666 - 'to_address' => $usces->options['order_mail'],
667 - 'from_name' => get_option('blogname'),
668 - 'from_address' => $usces->options['sender_mail'],
669 - 'return_path' => $usces->options['sender_mail'],
670 - 'subject' => $subject,
671 - 'message' => do_shortcode($message),
672 - );
673 - $para2 = apply_filters( 'usces_filter_send_delmembermail_para2', $para2 );
674 - $res = usces_send_mail( $para2 );
675 - }
676 - return $res;
677 -}
678 -
679 -function usces_lostmail($url) {
680 - global $usces;
681 - $res = false;
682 -
683 - $mail_data = $usces->options['mail_data'];
684 - $subject = apply_filters( 'usces_filter_lostmail_subject', __('Change password','usces') );
685 - $message = __('Please, click the following URL, and please change a password.','usces') . "\n\r\n\r\n\r"
686 - . $url . "\n\r\n\r\n\r"
687 - . "-----------------------------------------------------\n\r"
688 - . __('If you have not requested this email please kindly ignore and delete it.','usces') . "\n\r"
689 - . "-----------------------------------------------------\n\r\n\r\n\r";
690 - $message = apply_filters( 'usces_filter_lostmail_message', $message, $url );
691 - $message .= apply_filters( 'usces_filter_lostmail_footer', $mail_data['footer']['othermail'] );
692 -
693 -
694 - $para1 = array(
695 - 'to_name' => sprintf(__('Mr/Mrs %s', 'usces'), $_SESSION["usces_lostmail"]),
696 - 'to_address' => $_SESSION["usces_lostmail"],
697 - 'from_name' => get_option('blogname'),
698 - 'from_address' => $usces->options['sender_mail'],
699 - 'return_path' => $usces->options['sender_mail'],
700 - 'subject' => $subject,
701 - 'message' => do_shortcode($message),
702 - );
703 -
704 - $para1 = apply_filters( 'usces_filter_send_lostmail_para1', $para1 );
705 - $res = usces_send_mail( $para1 );
706 -
707 - if($res === false) {
708 - $usces->error_message = __('Error: I was not able to transmit an email.','usces');
709 - $page = 'lostmemberpassword';
710 - } else {
711 - $page = 'lostcompletion';
712 - }
713 -
714 - return $page;
715 -
716 -}
717 -
718 -//20100818ysk start
719 -//function usces_mail_custom_field_info( $custom_field, $position, $id ) {
720 -function usces_mail_custom_field_info( $custom_field, $position, $id, $mailaddress = '' ) {
721 - global $usces;
722 -
723 - $msg_body = '';
724 - switch($custom_field) {
725 - case 'order':
726 - $field = 'usces_custom_order_field';
727 - $cs = 'csod_';
728 - break;
729 - case 'customer':
730 - $field = 'usces_custom_customer_field';
731 - $cs = 'cscs_';
732 - break;
733 - case 'delivery':
734 - $field = 'usces_custom_delivery_field';
735 - $cs = 'csde_';
736 - break;
737 - case 'member':
738 - $field = 'usces_custom_member_field';
739 - $cs = 'csmb_';
740 - break;
741 - default:
742 - return $msg_body;
743 - }
744 -
745 - $meta = usces_has_custom_field_meta($custom_field);
746 -
747 - if(!empty($meta) and is_array($meta)) {
748 - $keys = array_keys($meta);
749 - switch($custom_field) {
750 - case 'order':
751 - $msg_body .= "\r\n";
752 - $msg_body .= usces_mail_line( 1, $mailaddress );
753 - foreach($keys as $key) {
754 - $value = maybe_unserialize($usces->get_order_meta_value($cs.$key, $id));
755 - if(is_array($value)) {
756 - $concatval = '';
757 - $c = '';
758 - foreach($value as $v) {
759 - $concatval .= $c.$v;
760 - $c = ', ';
761 - }
762 - $value = $concatval;
763 - }
764 - $msg_body .= $meta[$key]['name']." : ".$value."\r\n";
765 - }
766 - $msg_body .= usces_mail_line( 1, $mailaddress );
767 - break;
768 -
769 - case 'customer':
770 - case 'delivery':
771 - foreach($keys as $key) {
772 - if($meta[$key]['position'] == $position) {
773 - $value = maybe_unserialize($usces->get_order_meta_value($cs.$key, $id));
774 - if(is_array($value)) {
775 - $concatval = '';
776 - $c = '';
777 - foreach($value as $v) {
778 - $concatval .= $c.$v;
779 - $c = ', ';
780 - }
781 - $value = $concatval;
782 - }
783 - $msg_body .= $meta[$key]['name']." : ".$value."\r\n";
784 - }
785 - }
786 - break;
787 -
788 - case 'member':
789 - foreach($keys as $key) {
790 - if($meta[$key]['position'] == $position) {
791 - $value = maybe_unserialize($usces->get_member_meta_value($cs.$key, $id));
792 - if(is_array($value)) {
793 - $concatval = '';
794 - $c = '';
795 - foreach($value as $v) {
796 - $concatval .= $c.$v;
797 - $c = ', ';
798 - }
799 - $value = $concatval;
800 - }
801 - $msg_body .= $meta[$key]['name']." : ".$value."\r\n";
802 - }
803 - }
804 - break;
805 - }
806 - }
807 - $msg_body = apply_filters('usces_filter_mail_custom_field_info', $msg_body, $custom_field, $position, $id, $mailaddress);
808 - return $msg_body;
809 -}
810 -//20100818ysk end
811 -
812 -//function usces_send_receipted_mail( $order_id, $acting ) {
813 -// global $usces;
814 -// $res = false;
815 -//
816 -// $subject = __('Change password','usces');
817 -// $message = __('Please, click the following URL, and please change a password.','usces') . "\n\r\n\r\n\r"
818 -// . $url . "\n\r\n\r\n\r"
819 -// . "-----------------------------------------------------\n\r"
820 -// . __('I seem to have you cancel it when the body does not have memorizing to this email.','usces') . "\n\r"
821 -// . "-----------------------------------------------------\n\r\n\r\n\r"
822 -// . $usces->options['mail_data']['footer']['footerlogo'];
823 -//
824 -// $para1 = array(
825 -// 'to_name' => sprintf(__('Mr/Mrs %s', 'usces'), $_SESSION["usces_lostmail"]),
826 -// 'to_address' => $_SESSION["usces_lostmail"],
827 -// 'from_name' => get_bloginfo('name'),
828 -// 'from_address' => $usces->options['sender_mail'],
829 -// 'return_path' => $usces->options['error_mail'],
830 -// 'subject' => $subject,
831 -// 'message' => $message
832 -// );
833 -//
834 -// $res = usces_send_mail( $para1 );
835 -//
836 -// if($res === false) {
837 -// $usces->error_message = __('Error: I was not able to transmit an email.','usces');
838 -// $page = 'lostmemberpassword';
839 -// } else {
840 -// $page = 'lostcompletion';
841 -// }
842 -//
843 -// return $page;
844 -//
845 -//}
846 -
847 -function usces_send_mail( $para ) {
848 - global $usces;
849 -
850 - $from_name = $para['from_name'];
851 - $from_address = $para['from_address'];
852 - if (strpos($para['from_address'], '..') !== false || strpos($para['from_address'], '.@') !== false) {
853 - $fname = str_replace(strstr($para['from_address'], '@'), '', $para['from_address']);
854 - if( '"' != substr($fname, 0, 1) && '"' != substr($fname, -1) ){
855 - $para['from_address'] = str_replace($fname, '"RFC_violation"', $para['from_address']);
856 - $from_name = $para['from_name'] . '(' . $from_address . ')';
857 - }
858 - }
859 - $from = htmlspecialchars(html_entity_decode($from_name, ENT_QUOTES)) . " <{$para['from_address']}>";
860 - $header = "From: " . apply_filters('usces_filter_send_mail_from', $from, $para) . "\r\n";
861 - $header .= "Return-Path: {$para['return_path']}\r\n";
862 -
863 - $subject = html_entity_decode($para['subject'], ENT_QUOTES);
864 - $message = $para['message'];
865 -
866 - ini_set( "SMTP", "{$usces->options['smtp_hostname']}" );
867 - if( !ini_get( "smtp_port" ) ){
868 - ini_set( "smtp_port", apply_filters('usces_filter_send_mail_port', 25, $para) );
869 - }
870 - ini_set( "sendmail_from", "" );
871 -
872 - $mails = explode( ',', $para['to_address'] );
873 - $to_mailes = array();
874 - foreach( $mails as $mail ){
875 - if (strpos($mail, '..') !== false || strpos($mail, '.@') !== false) {
876 - $name = str_replace(strstr($mail, '@'), '', $mail);
877 - if( '"' != substr($name, 0, 1) && '"' != substr($name, -1) ){
878 - $to_mailes[] = str_replace($name, '"'.$name.'"', $mail);
879 - }else{
880 - $to_mailes[] = $mail;
881 - }
882 - }elseif( is_email( trim($mail) ) ){
883 - $to_mailes[] = $mail;
884 - }else{
885 - $to_mailes[] = NULL;
886 - }
887 - }
888 -
889 - if( !empty( $to_mailes ) ){
890 - $res = @wp_mail( $to_mailes , $subject , $message, $header );
891 - }else{
892 - $res = false;
893 - }
894 -
895 - return $res;
896 -
897 -}
898 -
899 -function usces_send_mail2( $para ) {
900 - global $usces;
901 -
902 - $usces->mail_para = $para;
903 - add_action('phpmailer_init','usces_send_mail_init', 11);
904 -
905 -// $from = htmlspecialchars(html_entity_decode($para['from_name'], ENT_QUOTES)) . " <{$para['from_address']}>";
906 -// $header = "From: " . apply_filters('usces_filter_send_mail_from', $from, $para) . "\r\n";
907 -// $header .= "Return-Path: {$para['return_path']}\r\n";
908 -
909 - $subject = html_entity_decode($para['subject'], ENT_QUOTES);
910 - $message = $para['message'];
911 -
912 -// ini_set( "SMTP", "{$usces->options['smtp_hostname']}" );
913 -// if( !ini_get( "smtp_port" ) ){
914 -// ini_set( "smtp_port", apply_filters('usces_filter_send_mail_port', 25, $para) );
915 -// }
916 -// ini_set( "sendmail_from", "" );
917 -
918 - $mails = explode( ',', $para['to_address'] );
919 - $to_mailes = array();
920 - foreach( $mails as $mail ){
921 - if( is_email( trim($mail) ) ){
922 - $to_mailes[] = $mail;
923 - }
924 - }
925 - if( !empty( $to_mailes ) ){
926 - $res = @wp_mail( $to_mailes , $subject , $message );
927 - }else{
928 - $res = false;
929 - }
930 -//usces_log('mail : '.print_r($res, true), 'acting_transaction.log');
931 -
932 - remove_action('phpmailer_init','usces_send_mail_init', 11);
933 - $usces->mail_para = array();
934 - return $res;
935 -
936 -}
937 -
938 -function usces_send_mail_init($phpmailer){
939 - global $usces;
940 -
941 - $phpmailer->Mailer = 'mail';
942 - $phpmailer->From = $usces->mail_para['from_address'];
943 - $phpmailer->FromName = apply_filters('usces_filter_send_mail_from', $usces->mail_para['from_name'], $usces->mail_para);
944 - $phpmailer->Sender = $usces->mail_para['from_address'];
945 -
946 -// $phpmailer->Mailer = 'smtp';
947 -// $phpmailer->SMTPSecure = '';
948 -// $phpmailer->Host = 'sample.com';
949 -// $phpmailer->Port = 25;
950 -// $phpmailer->SMTPAuth = true;
951 -// $phpmailer->Username = 'sample@sample.com';
952 -// $phpmailer->Password = 'password';
953 -
954 - do_action('usces_filter_phpmailer_init', array( &$phpmailer ));
955 -}
956 -
957 -function usces_reg_orderdata( $results = array() ) {
958 - global $wpdb, $usces;
959 -// $wpdb->show_errors();
960 -
961 - $options = get_option('usces');
962 - $cart = $usces->cart->get_cart();
963 - $entry = $usces->cart->get_entry();
964 - if( empty($cart) ){
965 - usces_log('reg_orderdata : Session is empty.', 'database_error.log');
966 - return 0;
967 - }
968 -
969 - $charging_type = $usces->getItemChargingType($cart[0]['post_id']);
970 -
971 - $item_total_price = $usces->get_total_price( $cart );
972 - $member = $usces->get_member();
973 - $order_table_name = $wpdb->prefix . "usces_order";
974 - $order_table_meta_name = $wpdb->prefix . "usces_order_meta";
975 - $member_table_name = $wpdb->prefix . "usces_member";
976 - $set = $usces->getPayments( $entry['order']['payment_name'] );
977 - $status = '';
978 - if( 'continue' == $charging_type ){
979 - $order_modified = substr(get_date_from_gmt(gmdate('Y-m-d H:i:s', time())), 0, 10);
980 - }else{
981 - $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' : '';
982 - $order_modified = NULL;
983 - }
984 - $payments = $usces->getPayments($entry['order']['payment_name']);
985 - if( isset($results['payment_status']) && $results['payment_status'] != 'Completed' && $payments['module'] == 'paypal.php') $status = 'pending';
986 -
987 - if( (empty($entry['customer']['name1']) && empty($entry['customer']['name2'])) || empty($entry['customer']['mailaddress1']) || empty($entry) || empty($cart) ) return '1';
988 - $status = apply_filters('usces_filter_reg_orderdata_status', $status);
989 - $delidue_date = ( isset($entry['order']['delidue_date']) ) ? $entry['order']['delidue_date'] : NULL;
990 -//20101208ysk start
991 - $query = $wpdb->prepare(
992 - "INSERT INTO $order_table_name (
993 - `mem_id`, `order_email`, `order_name1`, `order_name2`, `order_name3`, `order_name4`,
994 - `order_zip`, `order_pref`, `order_address1`, `order_address2`, `order_address3`,
995 - `order_tel`, `order_fax`, `order_delivery`, `order_cart`, `order_note`, `order_delivery_method`, `order_delivery_date`, `order_delivery_time`,
996 - `order_payment_name`, `order_condition`, `order_item_total_price`, `order_getpoint`, `order_usedpoint`, `order_discount`,
997 - `order_shipping_charge`, `order_cod_fee`, `order_tax`, `order_date`, `order_modified`, `order_status`, `order_delidue_date` )
998 - 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)",
999 - $member['ID'],
1000 - $entry['customer']['mailaddress1'],
1001 - $entry['customer']['name1'],
1002 - $entry['customer']['name2'],
1003 - $entry['customer']['name3'],
1004 - $entry['customer']['name4'],
1005 - $entry['customer']['zipcode'],
1006 - $entry['customer']['pref'],
1007 - $entry['customer']['address1'],
1008 - $entry['customer']['address2'],
1009 - $entry['customer']['address3'],
1010 - $entry['customer']['tel'],
1011 - $entry['customer']['fax'],
1012 - serialize($entry['delivery']),
1013 - serialize($cart),
1014 - $entry['order']['note'],
1015 - $entry['order']['delivery_method'],
1016 - $entry['order']['delivery_date'],
1017 - $entry['order']['delivery_time'],
1018 - $entry['order']['payment_name'],
1019 - serialize($entry['condition']),
1020 - $item_total_price,
1021 - $entry['order']['getpoint'],
1022 - $entry['order']['usedpoint'],
1023 - $entry['order']['discount'],
1024 - $entry['order']['shipping_charge'],
1025 - $entry['order']['cod_fee'],
1026 - $entry['order']['tax'],
1027 - get_date_from_gmt(gmdate('Y-m-d H:i:s', time())),
1028 - $order_modified,
1029 - $status,
1030 - $delidue_date
1031 - );
1032 -//20101208ysk end
1033 -
1034 - $res = $wpdb->query( $query );
1035 - usces_log('reg_orderdata : ' . $wpdb->last_error, 'database_error.log');
1036 -
1037 - if( $res === false){
1038 - $order_id = false;
1039 - }else{
1040 - $order_id = $wpdb->insert_id;
1041 - }
1042 -
1043 - if ( !$order_id ) :
1044 -
1045 - usces_log('reg_error_entry : '.print_r($entry, true), 'acting_transaction.log');
1046 - return false;
1047 -
1048 - else :
1049 -
1050 - $usces->cart->set_order_entry( array('ID' => $order_id) );
1051 - $usces->set_order_meta_value('customer_country', $entry['customer']['country'], $order_id);
1052 -
1053 - if ( $member['ID'] && 'activate' == $options['membersystem_state'] && 'activate' == $options['membersystem_point'] ) {
1054 -
1055 - $mquery = '';
1056 - if( usces_is_complete_settlement( $entry['order']['payment_name'], $status ) ) {//20120306ysk 0000324
1057 - if( apply_filters( 'usces_action_acting_getpoint_switch', true, $order_id, true) ){
1058 - $mquery = $wpdb->prepare(
1059 - "UPDATE $member_table_name SET mem_point = (mem_point + %d - %d) WHERE ID = %d",
1060 - $entry['order']['getpoint'], $entry['order']['usedpoint'], $member['ID']);
1061 - }else{
1062 - $mquery = $wpdb->prepare(
1063 - "UPDATE $member_table_name SET mem_point = (mem_point - %d) WHERE ID = %d",
1064 - $entry['order']['usedpoint'], $member['ID']);
1065 - }
1066 - } elseif( 0 < $entry['order']['usedpoint'] ) {
1067 - $mquery = $wpdb->prepare(
1068 - "UPDATE $member_table_name SET mem_point = (mem_point - %d) WHERE ID = %d",
1069 - $entry['order']['usedpoint'], $member['ID']);
1070 - }
1071 - if( $mquery ) {
1072 - $wpdb->query( $mquery );
1073 - $mquery = $wpdb->prepare("SELECT mem_point FROM $member_table_name WHERE ID = %d", $member['ID']);
1074 - $point = $wpdb->get_var( $mquery );
1075 - $_SESSION['usces_member']['point'] = $point;
1076 - }
1077 -
1078 - }
1079 -
1080 - if ( !empty($entry['reserve']) ) {
1081 - foreach ( $entry['reserve'] as $key => $value ) {
1082 - if ( is_array($value) )
1083 - $value = serialize($value);
1084 - $usces->set_order_meta_value($key, $value, $order_id);
1085 - }
1086 - }
1087 -
1088 - if ( !preg_match('/pending|noreceipt/', $status) ) {
1089 - $value = get_date_from_gmt(gmdate('Y-m-d H:i:s', time()));
1090 - $usces->set_order_meta_value('receipted_date', $value, $order_id);
1091 - }
1092 -
1093 -//20100818ysk start
1094 - if( !empty($entry['custom_order']) ) {
1095 - foreach( $entry['custom_order'] as $key => $value ) {
1096 - $csod_key = 'csod_'.$key;
1097 - if( is_array($value) )
1098 - $value = serialize($value);
1099 - $usces->set_order_meta_value($csod_key, $value, $order_id);
1100 - }
1101 - }
1102 - if( !empty($entry['custom_customer']) ) {
1103 - foreach( $entry['custom_customer'] as $key => $value ) {
1104 - $cscs_key = 'cscs_'.$key;
1105 - if( is_array($value) )
1106 - $value = serialize($value);
1107 - $usces->set_order_meta_value($cscs_key, $value, $order_id);
1108 - }
1109 - }
1110 - if( !empty($entry['custom_delivery']) ) {
1111 - foreach( $entry['custom_delivery'] as $key => $value ) {
1112 - $csde_key = 'csde_'.$key;
1113 - if( is_array($value) )
1114 - $value = serialize($value);
1115 - $usces->set_order_meta_value($csde_key, $value, $order_id);
1116 - }
1117 - }
1118 -//20100818ysk end
1119 -
1120 - if ( isset($_REQUEST['X-S_TORIHIKI_NO']) ) {
1121 - $usces->set_order_meta_value('settlement_id', $_REQUEST['X-S_TORIHIKI_NO'], $order_id);
1122 - if ( isset($_REQUEST['X-AC_MEMBERID']) ) {
1123 - $usces->set_order_meta_value($_REQUEST['X-AC_MEMBERID'], 'continuation', $order_id);
1124 - //$usces->set_member_meta_value('continue_memberid', $_REQUEST['X-AC_MEMBERID']);
1125 - $usces->set_member_meta_value('continue_memberid_'.$order_id, $_REQUEST['X-AC_MEMBERID']);
1126 - }
1127 - }
1128 -
1129 - if(isset($_REQUEST['acting']) && ('jpayment_card' == $_REQUEST['acting'] || 'jpayment_conv' == $_REQUEST['acting'] || 'jpayment_bank' == $_REQUEST['acting'])) {
1130 - $usces->set_order_meta_value('settlement_id', $_GET['cod'], $order_id);
1131 - foreach($_GET as $key => $value) {
1132 - if( 'purchase_jpayment' != $key)
1133 - $data[$key] = mysql_real_escape_string($value);
1134 - }
1135 - $usces->set_order_meta_value('acting_'.$_REQUEST['acting'], serialize($data), $order_id);
1136 - }
1137 - if( isset($_REQUEST['acting']) && isset($_REQUEST['acting_return']) && isset($_REQUEST['trans_code']) && 'epsilon' == $_REQUEST['acting'] ) {
1138 - //$usces->set_order_meta_value('settlement_id', $_GET['trans_code'], $order_id);//20130523ysk 0000711
1139 - $usces->set_order_meta_value('settlement_id', $_GET['order_number'], $order_id);
1140 - }
1141 - if( isset($_REQUEST['res_tracking_id']) ) {
1142 - $usces->set_order_meta_value('res_tracking_id', $_REQUEST['res_tracking_id'], $order_id);
1143 - }
1144 -//20121206ysk start
1145 - if( isset($_REQUEST['SID']) && isset($_REQUEST['FUKA']) ) {
1146 - if( substr($_REQUEST['FUKA'], 0, 24) == 'acting_digitalcheck_card' ) {
1147 - $data['SID'] = mysql_real_escape_string($_REQUEST['SID']);
1148 - $usces->set_order_meta_value( $_REQUEST['FUKA'], serialize($data), $order_id );
1149 - }
1150 - $usces->set_order_meta_value( 'SID', $_REQUEST['SID'], $order_id );
1151 - }
1152 -//20121206ysk end
1153 -//20130225ysk start
1154 - if( isset($_REQUEST['acting']) && 'mizuho_card' == $_REQUEST['acting'] ) {
1155 - $data['stran'] = mysql_real_escape_string($_REQUEST['stran']);
1156 - $data['mbtran'] = mysql_real_escape_string($_REQUEST['mbtran']);
1157 - $usces->set_order_meta_value( 'acting_'.$_REQUEST['acting'], serialize($data), $order_id );
1158 - } elseif( isset($_REQUEST['acting']) && 'mizuho_conv' == $_REQUEST['acting'] ) {
1159 - $data['stran'] = mysql_real_escape_string($_REQUEST['stran']);
1160 - $data['mbtran'] = mysql_real_escape_string($_REQUEST['mbtran']);
1161 - $data['bktrans'] = mysql_real_escape_string($_REQUEST['bktrans']);
1162 - $data['tranid'] = mysql_real_escape_string($_REQUEST['tranid']);
1163 - $usces->set_order_meta_value( 'stran', $data['stran'], $order_id );
1164 - $usces->set_order_meta_value( 'acting_'.$_REQUEST['acting'], serialize($data), $order_id );
1165 - }
1166 -//20130225ysk end
1167 -
1168 - $args = array('cart'=>$cart, 'entry'=>$entry, 'order_id'=>$order_id, 'member_id'=>$member['ID'], 'payments'=>$payments, 'charging_type'=>$charging_type);
1169 - do_action('usces_action_reg_orderdata', $args);
1170 -
1171 - endif;
1172 -
1173 - return $order_id;
1174 -
1175 -}
1176 -
1177 -function usces_new_orderdata() {
1178 - global $wpdb, $usces;
1179 - $_POST = $usces->stripslashes_deep_post($_POST);
1180 -
1181 - $usces->cart->crear_cart();
1182 - $cart = $usces->cart->get_cart();
1183 - $item_total_price = $usces->get_total_price( $cart );
1184 - $entry = $usces->cart->get_entry();
1185 - $member_id = $usces->get_memberid_by_email($_POST['customer']['mailaddress']);
1186 - $order_table_name = $wpdb->prefix . "usces_order";
1187 - $order_table_meta_name = $wpdb->prefix . "usces_order_meta";
1188 - $member_table_name = $wpdb->prefix . "usces_member";
1189 - $set = $usces->getPayments( $_POST['offer']['payment_name'] );
1190 - if( isset($_POST['offer']['receipt']) ) {
1191 - $status = $_POST['offer']['receipt'].',';
1192 - } else {
1193 - $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' : '';
1194 - }
1195 - $status .= ( !WCUtils::is_blank($_POST['offer']['taio']) && $_POST['offer']['taio'] != '#none#' ) ? $_POST['offer']['taio'].',' : '';
1196 - $status .= $_POST['offer']['admin'];
1197 - $status = apply_filters('usces_filter_new_orderdata_status', $status);
1198 - $order_conditions = $usces->get_condition();
1199 -
1200 -//20101208ysk start
1201 - $query = $wpdb->prepare(
1202 - "INSERT INTO $order_table_name (
1203 - `mem_id`, `order_email`, `order_name1`, `order_name2`, `order_name3`, `order_name4`,
1204 - `order_zip`, `order_pref`, `order_address1`, `order_address2`, `order_address3`,
1205 - `order_tel`, `order_fax`, `order_delivery`, `order_cart`, `order_note`, `order_delivery_method`, `order_delivery_date`, `order_delivery_time`,
1206 - `order_payment_name`, `order_condition`, `order_item_total_price`, `order_getpoint`, `order_usedpoint`, `order_discount`,
1207 - `order_shipping_charge`, `order_cod_fee`, `order_tax`, `order_date`, `order_modified`, `order_status`, `order_delidue_date` )
1208 - 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)",
1209 - $member_id,
1210 - $_POST['customer']['mailaddress'],
1211 - $_POST['customer']['name1'],
1212 - $_POST['customer']['name2'],
1213 - $_POST['customer']['name3'],
1214 - $_POST['customer']['name4'],
1215 - $_POST['customer']['zipcode'],
1216 - $_POST['customer']['pref'],
1217 - $_POST['customer']['address1'],
1218 - $_POST['customer']['address2'],
1219 - $_POST['customer']['address3'],
1220 - $_POST['customer']['tel'],
1221 - $_POST['customer']['fax'],
1222 - serialize($_POST['delivery']),
1223 - serialize($cart),
1224 - $_POST['offer']['note'],
1225 - $_POST['offer']['delivery_method'],
1226 - $_POST['offer']['delivery_date'],
1227 - $_POST['offer']['delivery_time'],
1228 - $_POST['offer']['payment_name'],
1229 - serialize($order_conditions),
1230 - $item_total_price,
1231 - $_POST['offer']['getpoint'],
1232 - $_POST['offer']['usedpoint'],
1233 - $_POST['offer']['discount'],
1234 - $_POST['offer']['shipping_charge'],
1235 - $_POST['offer']['cod_fee'],
1236 - $_POST['offer']['tax'],
1237 - get_date_from_gmt(gmdate('Y-m-d H:i:s', time())),
1238 - null,
1239 - $status,
1240 - $_POST['offer']['delidue_date']
1241 - );
1242 -//20101208ysk end
1243 -
1244 - $res = $wpdb->query( $query );
1245 -// $wpdb->print_error();
1246 -// echo $query;
1247 -// exit;
1248 - $order_id = $wpdb->insert_id;
1249 - $_REQUEST['order_id'] = $wpdb->insert_id;
1250 -
1251 -//20100818ysk start
1252 - if( !$order_id ) :
1253 -
1254 - return false;
1255 -
1256 - else :
1257 - $usces->set_order_meta_value('customer_country', $_POST['customer']['country'], $order_id);
1258 -
1259 - if( !empty($_POST['custom_order']) ) {
1260 - foreach( $_POST['custom_order'] as $key => $value ) {
1261 - $csod_key = 'csod_'.$key;
1262 - if( is_array($value) )
1263 - $value = serialize($value);
1264 - $usces->set_order_meta_value($csod_key, $value, $order_id);
1265 - }
1266 - }
1267 - if( !empty($_POST['custom_customer']) ) {
1268 - foreach( $_POST['custom_customer'] as $key => $value ) {
1269 - $cscs_key = 'cscs_'.$key;
1270 - if( is_array($value) )
1271 - $value = serialize($value);
1272 - $usces->set_order_meta_value($cscs_key, $value, $order_id);
1273 - }
1274 - }
1275 - if( !empty($_POST['custom_delivery']) ) {
1276 - foreach( $_POST['custom_delivery'] as $key => $value ) {
1277 - $csde_key = 'csde_'.$key;
1278 - if( is_array($value) )
1279 - $value = serialize($value);
1280 - $usces->set_order_meta_value($csde_key, $value, $order_id);
1281 - }
1282 - }
1283 - if ( !preg_match('/pending|noreceipt/', $status) ) {
1284 - $value = get_date_from_gmt(gmdate('Y-m-d H:i:s', time()));
1285 - $usces->set_order_meta_value('receipted_date', $value, $order_id);
1286 - }
1287 -//20120314ysk start 0000435
1288 - $args = array('cart'=>$cart, 'entry'=>$entry, 'order_id'=>$order_id, 'member_id'=>$member_id);
1289 - do_action('usces_action_reg_orderdata', $args);
1290 -//20120314ysk end
1291 - endif;
1292 -//20100818ysk end
1293 -
1294 - $usces->cart->crear_cart();
1295 - return $res;
1296 -
1297 -}
1298 -
1299 -function usces_delete_memberdata( $ID = 0 ) {
1300 - global $wpdb, $usces;
1301 -
1302 - if( 0 === $ID ){
1303 - if(!isset($_REQUEST['member_id']) || WCUtils::is_blank($_REQUEST['member_id']) )
1304 - return 0;
1305 - $ID = $_REQUEST['member_id'];
1306 - }
1307 - do_action('usces_action_pre_delete_memberdata', $ID);
1308 -
1309 - $member_table_name = $wpdb->prefix . "usces_member";
1310 -//20100818ysk start
1311 - $member_table_meta_name = $wpdb->prefix . "usces_member_meta";
1312 -//20100818ysk end
1313 -
1314 - $query = $wpdb->prepare("DELETE FROM $member_table_name WHERE ID = %d", $ID);
1315 - $res = $wpdb->query( $query );
1316 -//20100818ysk start
1317 - if($res) {
1318 - $query = $wpdb->prepare("DELETE FROM $member_table_meta_name WHERE member_id = %d", $ID);
1319 - $wpdb->query( $query );
1320 - }
1321 -//20100818ysk end
1322 - do_action('usces_action_post_delete_memberdata', $res, $ID);
1323 -
1324 - return $res;
1325 -}
1326 -
1327 -function usces_update_memberdata() {
1328 - global $wpdb, $usces;
1329 - $_POST = $usces->stripslashes_deep_post($_POST);
1330 -
1331 - $member_table_name = $wpdb->prefix . "usces_member";
1332 -//20100818ysk start
1333 - $member_table_meta_name = $wpdb->prefix . "usces_member_meta";
1334 -//20100818ysk end
1335 -
1336 - $ID = (int)$_REQUEST['member_id'];
1337 -
1338 -//$wpdb->show_errors();
1339 - $query = $wpdb->prepare(
1340 - "UPDATE $member_table_name SET
1341 - `mem_email`=%s, `mem_status`=%s, `mem_point`=%d, `mem_name1`=%s, `mem_name2`=%s,
1342 - `mem_name3`=%s, `mem_name4`=%s, `mem_zip`=%s, `mem_pref`=%s, `mem_address1`=%s,
1343 - `mem_address2`=%s, `mem_address3`=%s, `mem_tel`=%s, `mem_fax`=%s
1344 - WHERE ID = %d",
1345 - $_POST['member']['email'],
1346 - $_POST['member']['status'],
1347 - $_POST['member']['point'],
1348 - $_POST['member']['name1'],
1349 - $_POST['member']['name2'],
1350 - $_POST['member']['name3'],
1351 - $_POST['member']['name4'],
1352 - $_POST['member']['zipcode'],
1353 - $_POST['member']['pref'],
1354 - $_POST['member']['address1'],
1355 - $_POST['member']['address2'],
1356 - $_POST['member']['address3'],
1357 - $_POST['member']['tel'],
1358 - $_POST['member']['fax'],
1359 - $ID
1360 - );
1361 -
1362 - do_action('usces_action_pre_update_memberdata', $ID);
1363 -//20100818ysk start
1364 - //$res = $wpdb->query( $query );
1365 - $res[0] = $wpdb->query( $query );
1366 -
1367 - do_action( 'usces_action_post_update_memberdata', $ID, $res[0]);
1368 -
1369 - if(false === $res[0])
1370 - return false;
1371 -
1372 - $usces->set_member_meta_value('customer_country', $_POST['member']['country'], $ID);
1373 -//20130524ysk start 0000712
1374 - $csmb_meta = usces_has_custom_field_meta( 'member' );
1375 - if( is_array($csmb_meta) ) {
1376 - foreach( $csmb_meta as $key => $entry ) {
1377 - if( '4' == $entry['means'] ) {
1378 - $usces->del_member_meta( 'csmb_'.$key, $ID );
1379 - }
1380 - }
1381 - }
1382 -//20130524ysk end
1383 - $i = 1;
1384 - if( !empty($_POST['custom_member']) ) {
1385 - foreach( $_POST['custom_member'] as $key => $value ) {
1386 - $csmb_key = 'csmb_'.$key;
1387 - if( is_array($value) )
1388 - $value = serialize($value);
1389 - $res[$i] = $usces->set_member_meta_value($csmb_key, $value, $ID);
1390 - if(false === $res[$i])
1391 - return false;
1392 - $i++;
1393 - }
1394 - }
1395 -
1396 -
1397 - //$meta_keys = apply_filters( 'usces_filter_delete_member_pcid', "'zeus_pcid', 'remise_pcid', 'digitalcheck_ip_user_id'" );
1398 - $meta_keys = apply_filters( 'usces_filter_delete_member_pcid', "'remise_pcid', 'digitalcheck_ip_user_id'" );
1399 - $query = $wpdb->prepare("DELETE FROM $member_table_meta_name WHERE member_id = %d AND meta_key IN( $meta_keys )",
1400 - $_POST['member_id']
1401 - );
1402 - $res[$i] = $wpdb->query( $query );
1403 -
1404 - $result = ( 0 < array_sum($res) ) ? 1 : 0;
1405 - //return $res;
1406 - return $result;
1407 -//20100818ysk end
1408 -}
1409 -
1410 -function usces_delete_orderdata() {
1411 - global $wpdb, $usces;
1412 - if(!isset($_REQUEST['order_id']) || WCUtils::is_blank($_REQUEST['order_id']) ) return 0;
1413 - $order_table = $wpdb->prefix . "usces_order";
1414 - $order_meta_table = $wpdb->prefix . "usces_order_meta";
1415 - $ID = $_REQUEST['order_id'];
1416 -
1417 - $del = usces_delete_order_check( $ID );
1418 - if( $del ) {
1419 -
1420 - $query = $wpdb->prepare("SELECT * FROM $order_table WHERE ID = %d", $ID);
1421 - $order_data = $wpdb->get_row( $query, OBJECT );
1422 -//20130625ysk start 0000721
1423 -//20120306ysk start 0000324
1424 - //$order_res = $wpdb->get_row( $query, ARRAY_A );
1425 - //$restore_point = false;
1426 - $point = 0;
1427 - if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] && !empty($order_data->mem_id) && !$usces->is_status('cancel', $order_data->order_status) ) {
1428 - if( 0 < $order_data->order_getpoint ) {
1429 - //if( $usces->is_status('completion', $order_data->order_status) ) {
1430 - // //$restore_point = true;
1431 - // $point += $order_data->order_getpoint;
1432 - //} else {
1433 - if( usces_is_complete_settlement( $order_data->order_payment_name, $order_data->order_status ) || $usces->is_status('receipted', $order_data->order_status) ) {
1434 - //$restore_point = true;
1435 - $point += $order_data->order_getpoint;
1436 - }
1437 - //}
1438 - }
1439 - if( 0 < $order_data->order_usedpoint ) {
1440 - $point -= $order_data->order_usedpoint;
1441 - }
1442 - }
1443 -//20120306ysk end
1444 -
1445 - $query = $wpdb->prepare("DELETE FROM $order_table WHERE ID = %d", $ID);
1446 - $res = $wpdb->query( $query );
1447 -
1448 - $args = compact( 'ID', 'point', 'res' );
1449 -
1450 - if($res){
1451 - $query = $wpdb->prepare("DELETE FROM $order_meta_table WHERE order_id = %d", $ID);
1452 - $wpdb->query( $query );
1453 -
1454 - do_action('usces_action_del_orderdata', $order_data, $args);
1455 -//20120306ysk start 0000324
1456 - //if( $restore_point ) usces_restore_point( $order_res['mem_id'], $order_res['order_getpoint'] );
1457 - if( 0 != $point ) usces_restore_point( $order_data->mem_id, $point );
1458 -//20120306ysk end
1459 -//20130625ysk end
1460 - }
1461 -
1462 - } else {
1463 - $res = true;
1464 - }
1465 -
1466 - return $res;
1467 -}
1468 -
1469 -function usces_update_ordercart() {
1470 - global $wpdb, $usces;
1471 - if(!isset($_REQUEST['order_id']) || WCUtils::is_blank($_REQUEST['order_id']) ) return 0;
1472 - $order_table_name = $wpdb->prefix . "usces_order";
1473 - $ID = $_REQUEST['order_id'];
1474 - $usces->cart->crear_cart();
1475 - $usces->cart->upCart();
1476 - $cart = $usces->cart->get_cart();
1477 -//20120613ysk start 0000500
1478 - $idx = count($cart)-1;
1479 - $post_id = $cart[$idx]['post_id'];
1480 - $sku = $cart[$idx]['sku'];
1481 - $sku_code = esc_attr(urldecode($sku));
1482 - $cartItemName = $usces->getCartItemName($post_id, $sku_code);
1483 - $skuPrice = $cart[$idx]['price'];
1484 -//20120613ysk end
1485 -
1486 - $query = $wpdb->prepare("UPDATE $order_table_name SET `order_cart`=%s WHERE ID = %d", serialize($cart), $ID);
1487 - $res = $wpdb->query( $query );
1488 -
1489 - $usces->cart->crear_cart();
1490 -//20120613ysk start 0000500
1491 - if( $res === false ) {
1492 - $res = "-1#usces#";
1493 - } else {
1494 - $res = $skuPrice."#usces#".$cartItemName;
1495 - }
1496 -//20120613ysk end
1497 - return $res;
1498 -}
1499 -
1500 -function usces_update_ordercheck() {
1501 - global $wpdb, $usces;
1502 -
1503 - $tableName = $wpdb->prefix . "usces_order";
1504 - $order_id = $_POST['order_id'];
1505 - $checked = $_POST['checked'];
1506 -
1507 - $query = $wpdb->prepare("SELECT `order_check` FROM $tableName WHERE ID = %d", $order_id);
1508 - $res = $wpdb->get_var( $query );
1509 -
1510 - $checkfield = unserialize($res);
1511 - if( !isset($checkfield[$checked]) ) $checkfield[$checked] = $checked;
1512 - //$checkfield = 'OK';
1513 - $query = $wpdb->prepare("UPDATE $tableName SET `order_check`=%s WHERE ID = %d", serialize($checkfield), $order_id);
1514 - $res = $wpdb->query( $query );
1515 -
1516 - if($res)
1517 - return $checked;
1518 - else
1519 - return 'error';
1520 -}
1521 -function usces_update_orderdata() {
1522 - global $wpdb, $usces;
1523 - $_POST = $usces->stripslashes_deep_post($_POST);
1524 -
1525 - $order_table_name = $wpdb->prefix . "usces_order";
1526 - $order_table_meta_name = $wpdb->prefix . "usces_order_meta";
1527 - $member_table_name = $wpdb->prefix . "usces_member";
1528 -
1529 - $ID = $_REQUEST['order_id'];
1530 -
1531 - $query = $wpdb->prepare("SELECT * FROM $order_table_name WHERE ID = %d", $ID);
1532 - $old_orderdata = $wpdb->get_row( $query );
1533 - $old_status = $old_orderdata->order_status;
1534 -
1535 - $usces->cart->crear_cart();
1536 - $usces->cart->upCart();
1537 - if(isset($_POST['delButton'])) {
1538 - $usces->cart->del_row();
1539 - $indexs = array_keys($_POST['delButton']);
1540 - $index = $indexs[0];
1541 - do_action('usces_admin_delete_orderrow', $ID, $index );
1542 - }
1543 - $cart = $usces->cart->get_cart();
1544 - $usces->cart->entry();
1545 - $entry = $usces->cart->get_entry();
1546 -
1547 - $item_total_price = $usces->get_total_price( $cart );
1548 - $set = $usces->getPayments( $entry['order']['payment_name'] );
1549 - $taio = isset($entry['order']['taio']) ? $entry['order']['taio'] : '';
1550 - $receipt = isset($entry['order']['receipt']) ? $entry['order']['receipt'] : '';
1551 - $admin = isset($entry['order']['admin']) ? $entry['order']['admin'] : '';
1552 - $status = $usces->make_status( $taio, $receipt, $admin );
1553 - if( $taio == 'completion' || $taio == 'continuation' ){
1554 - if( 'update' == $_POST['up_modified'] ){
1555 - $order_modified = substr(get_date_from_gmt(gmdate('Y-m-d H:i:s', time())), 0, 10);
1556 - }else{
1557 - $order_modified = $_POST['modified'];
1558 - }
1559 - }else{
1560 - $order_modified = '';
1561 - }
1562 - $ordercheck = isset($_POST['check']) ? serialize($_POST['check']) : '';
1563 - $member_id = isset($_POST['member_id']) ? $_POST['member_id'] : 0;
1564 - //$member_id = $usces->get_memberid_by_email($_POST['customer']['mailaddress']);
1565 -
1566 - if( 'cancel' == $taio ){
1567 - $query = $wpdb->prepare(
1568 - "UPDATE $order_table_name SET `order_modified`=%s, `order_status`=%s WHERE ID = %d",
1569 - $order_modified, $status, $ID
1570 - );
1571 - $res[0] = $wpdb->query( $query );
1572 -
1573 - $query = $wpdb->prepare("SELECT * FROM $order_table_name WHERE ID = %d", $ID);
1574 - $new_orderdata = $wpdb->get_row( $query );
1575 -
1576 -//20131101ysk start 0000751
1577 - if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] && !empty($member_id) && !$usces->is_status('cancel', $old_status) ) {
1578 - $point = 0;
1579 - if( 0 < $old_orderdata->order_getpoint ) {
1580 - if( usces_is_complete_settlement( $old_orderdata->order_payment_name, $old_orderdata->order_status ) || $usces->is_status('receipted', $old_orderdata->order_status) ) {
1581 - $point += $old_orderdata->order_getpoint;
1582 - }
1583 - }
1584 - if( 0 < $old_orderdata->order_usedpoint ) {
1585 - $point -= $old_orderdata->order_usedpoint;
1586 - }
1587 - if( 0 != $point ) usces_restore_point( $member_id, $point );
1588 - }
1589 -//20131101ysk end
1590 -
1591 - do_action('usces_action_update_orderdata', $new_orderdata, $old_status, $old_orderdata);
1592 - $usces->cart->crear_cart();
1593 -
1594 - return 1;
1595 - }
1596 -
1597 -//$wpdb->show_errors();
1598 -//20101208ysk start
1599 - $query = $wpdb->prepare(
1600 - "UPDATE $order_table_name SET
1601 - `mem_id`=%d, `order_email`=%s, `order_name1`=%s, `order_name2`=%s, `order_name3`=%s, `order_name4`=%s,
1602 - `order_zip`=%s, `order_pref`=%s, `order_address1`=%s, `order_address2`=%s, `order_address3`=%s,
1603 - `order_tel`=%s, `order_fax`=%s, `order_delivery`=%s, `order_cart`=%s, `order_note`=%s,
1604 - `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,
1605 - `order_discount`=%f, `order_shipping_charge`=%f, `order_cod_fee`=%f, `order_tax`=%f, `order_modified`=%s,
1606 - `order_status`=%s, `order_delidue_date`=%s, `order_check`=%s
1607 - WHERE ID = %d",
1608 - $member_id,
1609 - $_POST['customer']['mailaddress'],
1610 - $_POST['customer']['name1'],
1611 - $_POST['customer']['name2'],
1612 - $_POST['customer']['name3'],
1613 - $_POST['customer']['name4'],
1614 - $_POST['customer']['zipcode'],
1615 - $_POST['customer']['pref'],
1616 - $_POST['customer']['address1'],
1617 - $_POST['customer']['address2'],
1618 - $_POST['customer']['address3'],
1619 - $_POST['customer']['tel'],
1620 - $_POST['customer']['fax'],
1621 - serialize($_POST['delivery']),
1622 - serialize($cart),
1623 - $_POST['offer']['note'],
1624 - $_POST['offer']['delivery_method'],
1625 - $_POST['offer']['delivery_date'],
1626 - $_POST['offer']['delivery_time'],
1627 - $_POST['offer']['payment_name'],
1628 - $item_total_price,
1629 - $_POST['offer']['getpoint'],
1630 - $_POST['offer']['usedpoint'],
1631 - $_POST['offer']['discount'],
1632 - $_POST['offer']['shipping_charge'],
1633 - $_POST['offer']['cod_fee'],
1634 - $_POST['offer']['tax'],
1635 - $order_modified,
1636 - $status,
1637 - $_POST['offer']['delidue_date'],
1638 - $ordercheck,
1639 - $ID
1640 - );
1641 -//20101208ysk end
1642 -
1643 -//20100818ysk start
1644 - //$res = $wpdb->query( $query );
1645 - $res[0] = $wpdb->query( $query );
1646 - if(false === $res[0])
1647 - return false;
1648 -
1649 - $usces->set_order_meta_value('customer_country', $_POST['customer']['country'], $ID);
1650 -//20130524ysk start 0000712
1651 - $csod_meta = usces_has_custom_field_meta( 'order' );
1652 - if( is_array($csod_meta) ) {
1653 - foreach( $csod_meta as $key => $entry ) {
1654 - if( '4' == $entry['means'] ) {
1655 - $usces->del_order_meta( 'csod_'.$key, $ID );
1656 - }
1657 - }
1658 - }
1659 - $cscs_meta = usces_has_custom_field_meta( 'customer' );
1660 - if( is_array($cscs_meta) ) {
1661 - foreach( $cscs_meta as $key => $entry ) {
1662 - if( '4' == $entry['means'] ) {
1663 - $usces->del_order_meta( 'cscs_'.$key, $ID );
1664 - }
1665 - }
1666 - }
1667 - $csde_meta = usces_has_custom_field_meta( 'delivery' );
1668 - if( is_array($csde_meta) ) {
1669 - foreach( $csde_meta as $key => $entry ) {
1670 - if( '4' == $entry['means'] ) {
1671 - $usces->del_order_meta( 'csde_'.$key, $ID );
1672 - }
1673 - }
1674 - }
1675 -//20130524ysk end
1676 - $i = 1;
1677 - if( !empty($_POST['custom_order']) ) {
1678 - foreach( $_POST['custom_order'] as $key => $value ) {
1679 - $csod_key = 'csod_'.$key;
1680 - if( is_array($value) )
1681 - $value = serialize($value);
1682 - $res[$i] = $usces->set_order_meta_value($csod_key, $value, $ID);
1683 - if(false === $res[$i])
1684 - return false;
1685 - $i++;
1686 - }
1687 - }
1688 - if( !empty($_POST['custom_customer']) ) {
1689 - foreach( $_POST['custom_customer'] as $key => $value ) {
1690 - $cscs_key = 'cscs_'.$key;
1691 - if( is_array($value) )
1692 - $value = serialize($value);
1693 - $res[$i] = $usces->set_order_meta_value($cscs_key, $value, $ID);
1694 - if(false === $res[$i])
1695 - return false;
1696 - $i++;
1697 - }
1698 - }
1699 - if( !empty($_POST['custom_delivery']) ) {
1700 - foreach( $_POST['custom_delivery'] as $key => $value ) {
1701 - $csde_key = 'csde_'.$key;
1702 - if( is_array($value) )
1703 - $value = serialize($value);
1704 - $res[$i] = $usces->set_order_meta_value($csde_key, $value, $ID);
1705 - if(false === $res[$i])
1706 - return false;
1707 - $i++;
1708 - }
1709 - }
1710 - $value = get_date_from_gmt(gmdate('Y-m-d H:i:s', time()));
1711 - if ( !preg_match('/pending|noreceipt/', $old_status) && preg_match('/pending|noreceipt/', $status) ) {
1712 - $rquery = $wpdb->prepare("DELETE FROM $order_table_meta_name WHERE order_id = %d AND meta_key = %s", $ID, 'receipted_date');
1713 - $wpdb->query( $rquery );
1714 - }else if ( !preg_match('/pending|noreceipt/', $old_status) && !preg_match('/pending|noreceipt/', $status) ) {
1715 - $query = $wpdb->prepare("SELECT order_id FROM $order_table_meta_name WHERE order_id = %d AND meta_key = %s", $ID, 'receipted_date');
1716 - $varres = $wpdb->get_var( $query );
1717 - if( empty($varres) ){
1718 - $usces->set_order_meta_value('receipted_date', $value, $ID);
1719 - }
1720 - }else if ( preg_match('/pending|noreceipt/', $old_status) && !preg_match('/pending|noreceipt/', $status) ) {
1721 - $usces->set_order_meta_value('receipted_date', $value, $ID);
1722 - }
1723 -
1724 -//20131101ysk start 0000751
1725 - //if( !usces_is_complete_settlement( $_POST['offer']['payment_name'] ) ) {
1726 - // if( !preg_match('/pending|noreceipt/', $old_status) && preg_match('/pending|noreceipt/', $status) ) {//入金→未入金
1727 - // usces_action_acting_getpoint( $ID, false );//ポイント取消
1728 - // } else if( preg_match('/pending|noreceipt/', $old_status) && !preg_match('/pending|noreceipt/', $status) ) {//未入金→入金
1729 - // usces_action_acting_getpoint( $ID );//ポイント追加
1730 - // }
1731 - //}
1732 - if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] && !empty($member_id) ) {
1733 - $point = 0;
1734 - $getpoint = $_POST['offer']['getpoint'];
1735 - $usedpoint = $_POST['offer']['usedpoint'];
1736 - if( $usces->is_status('cancel', $old_status) && !$usces->is_status('cancel', $status) ) {//キャンセル→新規受付・取り寄せ中・発送済み
1737 - if( 0 < $getpoint ) {
1738 - if( usces_is_complete_settlement( $_POST['offer']['payment_name'], $status ) || $usces->is_status('receipted', $status) ) {
1739 - $point -= $getpoint;
1740 - }
1741 - }
1742 - if( 0 < $usedpoint ) {
1743 - $point += $usedpoint;
1744 - }
1745 - } else {
1746 - if( !usces_is_complete_settlement( $_POST['offer']['payment_name'] ) ) {
1747 - if( !preg_match('/pending|noreceipt/', $old_status) && preg_match('/pending|noreceipt/', $status) ) {//入金→未入金
1748 - $point += $getpoint;//ポイント取消
1749 - } else if( preg_match('/pending|noreceipt/', $old_status) && !preg_match('/pending|noreceipt/', $status) ) {//未入金→入金
1750 - $point -= $getpoint;//ポイント追加
1751 - } else {
1752 - if( $old_orderdata->order_getpoint != $getpoint ) {
1753 - $point += $old_orderdata->order_getpoint - $getpoint;
1754 - }
1755 - }
1756 - } else {
1757 - if( $old_orderdata->order_getpoint != $getpoint ) {
1758 - $point += $old_orderdata->order_getpoint - $getpoint;
1759 - }
1760 - }
1761 - if( $old_orderdata->order_usedpoint != $usedpoint ) {
1762 - $point -= $old_orderdata->order_usedpoint - $usedpoint;
1763 - }
1764 - }
1765 - if( 0 != $point ) usces_restore_point( $member_id, $point );
1766 - }
1767 -//20131101ysk end
1768 -
1769 - $result = ( 0 < array_sum($res) ) ? 1 : 0;
1770 -//20100818ysk end
1771 -
1772 - $query = $wpdb->prepare("SELECT * FROM $order_table_name WHERE ID = %d", $ID);
1773 - $new_orderdata = $wpdb->get_row( $query );
1774 -//20120612ysk start 0000501
1775 - //do_action('usces_action_update_orderdata', $new_orderdata);
1776 - do_action('usces_action_update_orderdata', $new_orderdata, $old_status, $old_orderdata);
1777 -//20120612ysk end
1778 - $usces->cart->crear_cart();
1779 -
1780 -return $result;
1781 -
1782 -// else :
1783 -//
1784 -// if ( $member['ID'] ) {
1785 -//
1786 -// $mquery = $wpdb->prepare(
1787 -// "UPDATE $member_table_name SET mem_point = (mem_point + %d - %d) WHERE ID = %d",
1788 -// $entry['order']['getpoint'], $entry['order']['usedpoint'], $member['ID']);
1789 -//
1790 -// $wpdb->query( $mquery );
1791 -// $mquery = $wpdb->prepare("SELECT mem_point FROM $member_table_name WHERE ID = %d", $member['ID']);
1792 -// $point = $wpdb->get_var( $mquery );
1793 -// $_SESSION['usces_member']['point'] = $point;
1794 -// }
1795 -//
1796 -// if ( !empty($entry['reserve']) ) {
1797 -// foreach ( $entry['reserve'] as $key => $value ) {
1798 -// if ( is_array($value) )
1799 -// $value = serialize($value);
1800 -// $mquery = $wpdb->prepare("INSERT INTO $order_table_meta_name ( order_id, meta_key, meta_value )
1801 -// VALUES (%d, %s, %s, %s)", $order_id, $key, $value);
1802 -// $wpdb->query( $mquery );
1803 -// }
1804 -// }
1805 -//
1806 -// endif;
1807 -//
1808 -// //zaiko
1809 -// foreach($cart as $cartrow){
1810 -// $zaikonum = $usces->getItemZaikoNum( $cartrow['post_id'], $cartrow['sku'] );
1811 -// if($zaikonum == '') continue;
1812 -// $zaikonum = $zaikonum - $cartrow['quantity'];
1813 -// $usces->updateItemZaikoNum( $cartrow['post_id'], $cartrow['sku'], $zaikonum );
1814 -// if($zaikonum <= 0) $usces->updateItemZaiko( $cartrow['post_id'], $cartrow['sku'], 2 );
1815 -// }
1816 -//
1817 -// return $order_id;
1818 -
1819 -}
1820 -
1821 -
1822 -
1823 -function usces_export_xml() {
1824 - $options = get_option('usces');
1825 - echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '"?' . ">\n";
1826 -?>
1827 - <usces><?php echo serialize($options); ?></usces>
1828 - <usces_management_status><?php echo serialize(get_option('usces_management_status')); ?></usces_management_status>
1829 - <usces_zaiko_status><?php echo serialize(get_option('usces_zaiko_status')); ?></usces_zaiko_status>
1830 - <usces_customer_status><?php echo serialize(get_option('usces_customer_status')); ?></usces_customer_status>
1831 - <usces_payment_structure><?php echo serialize(get_option('usces_payment_structure')); ?></usces_payment_structure>
1832 - <usces_display_mode><?php echo serialize(get_option('usces_display_mode')); ?></usces_display_mode>
1833 -<!--20110331ysk start-->
1834 -<!-- <usces_pref><?php //echo serialize(get_option('usces_pref')); ?></usces_pref>-->
1835 -<!--20110331ysk end-->
1836 - <usces_shipping_rule><?php echo serialize(get_option('usces_shipping_rule')); ?></usces_shipping_rule>
1837 -
1838 -<?php
1839 -}
1840 -
1841 -function usces_all_change_zaiko(&$obj) {
1842 - global $wpdb, $usces;
1843 -
1844 - $ids = $_POST['listcheck'];
1845 - $status = true;
1846 - foreach ( (array)$ids as $post_id ){
1847 - $skus = $usces->get_skus($post_id);
1848 - foreach ( (array)$skus as $sku ){
1849 - $res = usces_update_sku( $post_id, $sku['code'], 'stock', (int)$_POST['change']['word']['zaiko'] );
1850 - if( !$res ){
1851 - $status = false;
1852 - }
1853 - }
1854 - }
1855 - if ( true === $status ) {
1856 - $obj->set_action_status('success', __('I completed collective operation.','usces'));
1857 - } elseif ( false === $status ) {
1858 - $obj->set_action_status('error', __('ERROR: I was not able to complete collective operation','usces'));
1859 - } else {
1860 - $obj->set_action_status('none', '');
1861 - }
1862 -}
1863 -
1864 -function usces_all_change_itemdisplay(&$obj){
1865 - global $wpdb;
1866 -
1867 - $ids = $_POST['listcheck'];
1868 - $post_status = $_POST['change']['word']['display_status'];
1869 - $status = true;
1870 - foreach ( (array)$ids as $post_id ):
1871 -// $query = $wpdb->prepare("UPDATE $wpdb->posts SET post_status = %s WHERE ID = %d", $post_status, $post_id);
1872 -// $res = $wpdb->query( $query );
1873 - $post_data = array('ID'=>$post_id, 'post_status'=>$post_status);
1874 - $res = wp_update_post( $post_data );
1875 -
1876 - if( $res == 0 ) {
1877 - $status = false;
1878 - }
1879 - endforeach;
1880 - if ( true === $status ) {
1881 - $obj->set_action_status('success', __('I completed collective operation.','usces'));
1882 - } elseif ( false === $status ) {
1883 - $obj->set_action_status('error', __('ERROR: I was not able to complete collective operation','usces'));
1884 - } else {
1885 - $obj->set_action_status('none', '');
1886 - }
1887 -}
1888 -
1889 -function usces_all_change_order_reciept(&$obj){
1890 - global $wpdb, $usces;
1891 -
1892 - $tableName = $wpdb->prefix . "usces_order";
1893 - $ids = $_POST['listcheck'];
1894 - $status = true;
1895 - foreach ( (array)$ids as $id ):
1896 -//20120306ysk start 0000324
1897 - //$query = $wpdb->prepare("SELECT order_status FROM $tableName WHERE ID = %d", $id);
1898 - //$statusstr = $wpdb->get_var( $query );
1899 - $query = $wpdb->prepare("SELECT order_status, mem_id, order_getpoint FROM $tableName WHERE ID = %d", $id);
1900 - $order_res = $wpdb->get_row( $query, ARRAY_A );
1901 - $statusstr = $order_res['order_status'];
1902 - $restore_point = false;
1903 - $getpoint = $order_res['order_getpoint'];
1904 - if( strpos($statusstr, 'cancel') !== false ) continue;//20131101ysk 0000751
1905 -//20120306ysk end
1906 - if(strpos($statusstr, 'noreceipt') === false && strpos($statusstr, 'receipted') === false) continue;
1907 - $old_status = $statusstr;//20120612ysk 0000501
1908 - if($_REQUEST['change']['word']['order_reciept'] == 'receipted') {
1909 -//20120306ysk start 0000324
1910 - //if(strpos($statusstr, 'noreceipt') !== false)
1911 - if(strpos($statusstr, 'noreceipt') !== false) {
1912 - $statusstr = str_replace('noreceipt', 'receipted', $statusstr);
1913 - //if( !$usces->is_status('completion', $order_res['order_status']) ) {
1914 - $restore_point = true;
1915 - $getpoint = $getpoint * -1;//add point
1916 - //}
1917 - }
1918 -//20120306ysk end
1919 - }elseif($_REQUEST['change']['word']['order_reciept'] == 'noreceipt') {
1920 -//20120306ysk start 0000324
1921 - //if(strpos($statusstr, 'receipted') !== false)
1922 - if(strpos($statusstr, 'receipted') !== false) {
1923 - $statusstr = str_replace('receipted', 'noreceipt', $statusstr);
1924 - //if( !$usces->is_status('completion', $order_res['order_status']) )
1925 - $restore_point = true;
1926 - }
1927 -//20120306ysk end
1928 - }
1929 - $query = $wpdb->prepare("UPDATE $tableName SET order_status = %s WHERE ID = %d", $statusstr, $id);
1930 - $res = $wpdb->query( $query );
1931 - if( $res === false ) {
1932 - $status = false;
1933 - }
1934 -//20120306ysk start 0000324
1935 - if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] ) {
1936 - if( !empty($order_res['mem_id']) && 0 < $order_res['order_getpoint'] ) {
1937 - if( $res && $restore_point ) usces_restore_point( $order_res['mem_id'], $getpoint );
1938 - }
1939 - }
1940 -//20120306ysk end
1941 - if( $status ) {
1942 - do_action( 'usces_action_collective_order_reciept_each', $id, $statusstr, $old_status );
1943 - }
1944 - endforeach;
1945 - if ( true === $status ) {
1946 - $obj->set_action_status('success', __('I completed collective operation.','usces'));
1947 - } elseif ( false === $status ) {
1948 - $obj->set_action_status('error', __('ERROR: I was not able to complete collective operation','usces'));
1949 - } else {
1950 - $obj->set_action_status('none', '');
1951 - }
1952 - do_action('usces_action_collective_order_reciept', array(&$obj));
1953 -}
1954 -
1955 -function usces_all_change_order_status(&$obj){
1956 - global $wpdb, $usces;
1957 -
1958 - $tableName = $wpdb->prefix . "usces_order";
1959 - $ids = $_POST['listcheck'];
1960 - foreach ( (array)$ids as $id ):
1961 - $status = true;
1962 -//20120306ysk start 0000324
1963 - //$query = $wpdb->prepare("SELECT order_status FROM $tableName WHERE ID = %d", $id);
1964 - //$statusstr = $wpdb->get_var( $query );
1965 - $query = $wpdb->prepare("SELECT order_status, mem_id, order_getpoint, order_usedpoint, order_payment_name FROM $tableName WHERE ID = %d", $id);
1966 - $order_res = $wpdb->get_row( $query, ARRAY_A );
1967 - $statusstr = $order_res['order_status'];
1968 - $restore_point = false;
1969 - $getpoint = $order_res['order_getpoint'];
1970 - $usedpoint = $order_res['order_usedpoint'];
1971 -//20120306ysk end
1972 - $old_status = $statusstr;//20120612ysk 0000501
1973 - switch ($_REQUEST['change']['word']['order_status']) {
1974 - case 'estimate':
1975 - if(strpos($statusstr, 'adminorder') !== false) {
1976 - $statusstr = str_replace('adminorder', 'estimate', $statusstr);
1977 - }else if(strpos($statusstr, 'estimate') === false) {
1978 - $statusstr .= 'estimate,';
1979 - }
1980 - break;
1981 - case 'adminorder':
1982 - if(strpos($statusstr, 'estimate') !== false) {
1983 - $statusstr = str_replace('estimate', 'adminorder', $statusstr);
1984 - }else if(strpos($statusstr, 'adminorder') === false) {
1985 - $statusstr .= 'adminorder,';
1986 - }
1987 - break;
1988 - case 'duringorder':
1989 - if(strpos($statusstr, 'cancel') !== false) {
1990 - $statusstr = str_replace('cancel', 'duringorder', $statusstr);
1991 -//20120919ysk start 0000573
1992 - if( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
1993 - $restore_point = true;
1994 - $getpoint = $getpoint * -1;//add point
1995 - } elseif( $usces->is_status('receipted', $order_res['order_status']) ) {
1996 - $restore_point = true;
1997 - $getpoint = $getpoint * -1;//add point
1998 - }
1999 -//20120919ysk end
2000 - }else if(strpos($statusstr, 'completion') !== false) {
2001 - $statusstr = str_replace('completion', 'duringorder', $statusstr);
2002 -//20120306ysk start 0000324
2003 - //if( !usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) && !$usces->is_status('receipted', $order_res['order_status']) )
2004 - // $restore_point = true;
2005 -//20120306ysk end
2006 - }else if(strpos($statusstr, 'new') !== false) {
2007 - $statusstr = str_replace('new', 'duringorder', $statusstr);
2008 - }else if(strpos($statusstr, 'duringorder') === false) {
2009 - $statusstr .= 'duringorder,';
2010 - }
2011 - break;
2012 - case 'cancel':
2013 - if(strpos($statusstr, 'completion') !== false) {
2014 - $statusstr = str_replace('completion', 'cancel', $statusstr);
2015 -//20120306ysk start 0000324
2016 - //if( !usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) && !$usces->is_status('receipted', $order_res['order_status']) )
2017 - // $restore_point = true;
2018 -//20120306ysk end
2019 - }else if(strpos($statusstr, 'new') !== false) {
2020 - $statusstr = str_replace('new', 'cancel', $statusstr);
2021 - }else if(strpos($statusstr, 'duringorder') !== false) {
2022 - $statusstr = str_replace('duringorder', 'cancel', $statusstr);
2023 - }else if(strpos($statusstr, 'cancel') === false) {
2024 - $statusstr .= 'cancel,';
2025 - }
2026 -//20120919ysk start 0000573
2027 - if( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
2028 - $restore_point = true;
2029 - $usedpoint = $usedpoint * -1;//add point
2030 - } elseif( $usces->is_status('receipted', $order_res['order_status']) ) {
2031 - $restore_point = true;
2032 - $usedpoint = $usedpoint * -1;//add point
2033 - }
2034 -//20120919ysk end
2035 - break;
2036 - case 'completion':
2037 - if(strpos($statusstr, 'new') !== false) {
2038 - $statusstr = str_replace('new', 'completion', $statusstr);
2039 - }else if(strpos($statusstr, 'duringorder') !== false) {
2040 - $statusstr = str_replace('duringorder', 'completion', $statusstr);
2041 - }else if(strpos($statusstr, 'cancel') !== false) {
2042 - $statusstr = str_replace('cancel', 'completion', $statusstr);
2043 -//20120919ysk start 0000573
2044 - if( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
2045 - $restore_point = true;
2046 - $getpoint = $getpoint * -1;//add point
2047 - } elseif( $usces->is_status('receipted', $order_res['order_status']) ) {
2048 - $restore_point = true;
2049 - $getpoint = $getpoint * -1;//add point
2050 - }
2051 -//20120919ysk end
2052 - }else if(strpos($statusstr, 'completion') === false) {
2053 - $statusstr .= 'completion,';
2054 - }
2055 -//20120306ysk start 0000324
2056 - //if( !usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) && !$usces->is_status('receipted', $order_res['order_status']) ) {
2057 - // $restore_point = true;
2058 - // $getpoint = $getpoint * -1;//add point
2059 - //}
2060 -//20120306ysk end
2061 - break;
2062 - case 'new':
2063 - if(strpos($statusstr, 'duringorder') !== false) {
2064 - $statusstr = str_replace('duringorder,', '', $statusstr);
2065 - }else if(strpos($statusstr, 'completion') !== false) {
2066 - $statusstr = str_replace('completion,', '', $statusstr);
2067 -//20120306ysk start 0000324
2068 - //if( !usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) && !$usces->is_status('receipted', $order_res['order_status']) )
2069 - // $restore_point = true;
2070 -//20120306ysk end
2071 - }else if(strpos($statusstr, 'cancel') !== false) {
2072 - $statusstr = str_replace('cancel,', '', $statusstr);
2073 -//20120919ysk start 0000573
2074 - if( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
2075 - $restore_point = true;
2076 - $getpoint = $getpoint * -1;//add point
2077 - } elseif( $usces->is_status('receipted', $order_res['order_status']) ) {
2078 - $restore_point = true;
2079 - $getpoint = $getpoint * -1;//add point
2080 - }
2081 -//20120919ysk end
2082 - }
2083 - break;
2084 - }
2085 - $query = $wpdb->prepare("UPDATE $tableName SET order_status = %s WHERE ID = %d", $statusstr, $id);
2086 - $res = $wpdb->query( $query );
2087 - if( $res === false ) {
2088 - $status = false;
2089 - }
2090 -//20120306ysk start 0000324
2091 - if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] ) {
2092 - if( !empty($order_res['mem_id']) && ( 0 < $order_res['order_getpoint'] || 0 < $order_res['order_usedpoint'] ) ) {
2093 - if( $res && $restore_point ) usces_restore_point( $order_res['mem_id'], $getpoint + $usedpoint );
2094 - }
2095 - }
2096 -//20120306ysk end
2097 -//20120612ysk 0000501 start
2098 - if( $status ) {
2099 - do_action('usces_action_collective_order_status_each', $id, $statusstr, $old_status);
2100 - }
2101 -//20120612ysk end
2102 - endforeach;
2103 - if ( true === $status ) {
2104 - $obj->set_action_status('success', __('I completed collective operation.','usces'));
2105 - } elseif ( false === $status ) {
2106 - $obj->set_action_status('error', __('ERROR: I was not able to complete collective operation','usces'));
2107 - } else {
2108 - $obj->set_action_status('none', '');
2109 - }
2110 - do_action('usces_action_collective_order_status', array(&$obj));
2111 -}
2112 -
2113 -function usces_all_delete_order_data(&$obj){
2114 - global $wpdb, $usces;
2115 -
2116 - $tableName = $wpdb->prefix . "usces_order";
2117 - $tableMetaName = $wpdb->prefix . "usces_order_meta";
2118 - $ids = $_POST['listcheck'];
2119 - $status = true;
2120 - foreach ( (array)$ids as $id ):
2121 - $del = usces_delete_order_check( $id );
2122 - if( $del === false ) continue;
2123 -//20130625ysk start 0000721
2124 -//20120306ysk start 0000324
2125 - //$restore_point = false;
2126 - $point = 0;
2127 - if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] && !empty($order_res['mem_id']) && !$usces->is_status('cancel', $order_res['order_status']) ) {
2128 - $query = $wpdb->prepare("SELECT * FROM $tableName WHERE ID = %d", $id);
2129 - $order_res = $wpdb->get_row( $query, ARRAY_A );
2130 - if( 0 < $order_res['order_getpoint'] ) {
2131 - //if( $usces->is_status('completion', $order_res['order_status']) ) {
2132 - // $restore_point = true;
2133 - //} else {
2134 - if( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) || $usces->is_status('receipted', $order_res['order_status']) )
2135 - //$restore_point = true;
2136 - $point += $order_res['order_getpoint'];
2137 - //}
2138 - }
2139 - if( 0 < $order_res['order_usedpoint'] ) {
2140 - $point -= $order_res['order_usedpoint'];
2141 - }
2142 - }
2143 -//20120306ysk end
2144 - $query = $wpdb->prepare("DELETE FROM $tableName WHERE ID = %d", $id);
2145 - $res = $wpdb->query( $query );
2146 - if( $res === false ) {
2147 - $status = false;
2148 - }else{
2149 - $metaquery = $wpdb->prepare("DELETE FROM $tableMetaName WHERE order_id = %d", $id);//0000427
2150 - $metares = $wpdb->query( $metaquery );
2151 -//20120306ysk start 0000324
2152 - //if( $restore_point ) usces_restore_point( $order_res['mem_id'], $order_res['order_getpoint'] );
2153 - if( 0 != $point ) usces_restore_point( $order_res['mem_id'], $point );
2154 -//20120306ysk end
2155 -//20120612ysk start 0000501
2156 -//20130419ysk
2157 - do_action('usces_action_collective_order_delete_each', $id, $order_res);
2158 -//20120612ysk end
2159 - }
2160 - endforeach;
2161 - if ( true === $status ) {
2162 - $obj->set_action_status('success', __('I completed collective operation.','usces'));
2163 - } elseif ( false === $status ) {
2164 - $obj->set_action_status('error', __('ERROR: I was not able to complete collective operation','usces'));
2165 - } else {
2166 - $obj->set_action_status('none', '');
2167 - }
2168 - do_action('usces_action_collective_order_delete', array(&$obj));
2169 -}
2170 -
2171 -function usces_check_acting_return() {
2172 - global $usces;
2173 - $entry = $usces->cart->get_entry();
2174 -
2175 - $acting = $_GET['acting'];
2176 - $results = array();
2177 - switch ( $acting ) {
2178 - case 'epsilon':
2179 - if(isset($_GET['duplicate']) && $_GET['duplicate'] == 1){
2180 - $results[0] = 'duplicate';
2181 - }else if(isset($_GET['result'])){
2182 - $results[0] = (int)$_GET['result'];
2183 - $results['reg_order'] = true;
2184 - }else{
2185 - $str = explode('?', $_GET['acting_return']);
2186 - if(!isset($str[1])) {
2187 - $results[0] = 0;
2188 - }else{
2189 - $para = parse_str($str[1]);
2190 - $results[0] = isset($para['result']) ? (int)$para['result'] : 0;
2191 - foreach($para as $key => $value){
2192 - $results[$key] = $value;
2193 - }
2194 - }
2195 -
2196 - }
2197 - $results['reg_order'] = true;
2198 - break;
2199 -
2200 - case 'paypal':
2201 - usces_log('paypal in ', 'acting_transaction.log');
2202 - require_once($usces->options['settlement_path'] . "paypal.php");
2203 - $results = paypal_check($usces_paypal_url);
2204 - remove_action( 'wp_footer', array(&$usces, 'lastprocessing'));
2205 - $results['reg_order'] = true;
2206 - break;
2207 -
2208 - case 'zeus_card':
2209 - $results = $_REQUEST;
2210 - if( $_REQUEST['acting_return'] && isset($_REQUEST['wctid']) && usces_is_trusted_acting_data($_REQUEST['wctid']) ){
2211 - $results[0] = 1;
2212 - }else{
2213 - $results[0] = 0;
2214 - }
2215 - $results['reg_order'] = true;
2216 - break;
2217 -
2218 - case 'zeus_conv':
2219 - $results = $_GET;
2220 - if( $_REQUEST['acting_return'] ){
2221 - $results[0] = 1;
2222 - }else{
2223 - $results[0] = 0;
2224 - }
2225 - $results['reg_order'] = false;
2226 - break;
2227 -
2228 - case 'remise_card':
2229 - $results = $_POST;
2230 - if( $_REQUEST['acting_return'] && ( isset($_REQUEST['X-ERRCODE']) && ' ' === $_REQUEST['X-ERRCODE'] ) ){
2231 - usces_log('remise card entry data : '.print_r($entry, true), 'acting_transaction.log');
2232 - $results[0] = 1;
2233 - }else{
2234 - $results[0] = 0;
2235 - }
2236 - if( isset($_REQUEST['dlseller_update']) ){
2237 - $results['reg_order'] = false;
2238 - }else{
2239 - $results['reg_order'] = true;
2240 - }
2241 - break;
2242 -
2243 - case 'remise_conv':
2244 - $results = $_GET;
2245 - if( $_REQUEST['acting_return'] && isset($_REQUEST['X-JOB_ID']) && '0:0000' === $_REQUEST['X-R_CODE']){
2246 - //usces_log('remise conv entry data : '.print_r($entry, true), 'acting_transaction.log');
2247 - $results[0] = 1;
2248 - }else{
2249 - $results[0] = 0;
2250 - }
2251 - $results['reg_order'] = true;
2252 - break;
2253 -
2254 -//20101018ysk start
2255 - case 'jpayment_card':
2256 - $results = $_GET;
2257 - if($_GET['rst'] == 2) {
2258 - usces_log('jpayment card error : '.print_r($entry, true), 'acting_transaction.log');
2259 - }
2260 - $results[0] = ($_GET['rst'] == 1) ? 1 : 0;
2261 - $results['reg_order'] = true;
2262 - break;
2263 -
2264 - case 'jpayment_conv':
2265 - $results = $_GET;
2266 - if($_GET['rst'] == 2) {
2267 - usces_log('jpayment conv error : '.print_r($entry, true), 'acting_transaction.log');
2268 - }
2269 - $results[0] = ($_GET['rst'] == 1 and $_GET['ap'] == 'CPL_PRE') ? 1 : 0;
2270 - $results['reg_order'] = true;
2271 - break;
2272 -
2273 - case 'jpayment_bank':
2274 - $results = $_GET;
2275 - if($_GET['rst'] == 2) {
2276 - usces_log('jpayment bank error : '.print_r($entry, true), 'acting_transaction.log');
2277 - }
2278 - $results[0] = ($_GET['rst'] == 1) ? 1 : 0;
2279 - $results['reg_order'] = true;
2280 - break;
2281 -//20101018ysk end
2282 -//20110208ysk start
2283 - case 'paypal_ec':
2284 - $results = $_GET;
2285 -
2286 - //Build a second API request to PayPal, using the token as the ID to get the details on the payment authorization
2287 - $nvpstr = "&TOKEN=".urlencode($_REQUEST['token']);
2288 -
2289 - $usces->paypal->setMethod('GetExpressCheckoutDetails');
2290 - $usces->paypal->setData($nvpstr);
2291 - $res = $usces->paypal->doExpressCheckout();
2292 - $resArray = $usces->paypal->getResponse();
2293 - $ack = strtoupper($resArray["ACK"]);
2294 - if($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
2295 -//20121009ysk start 0000587
2296 -//20121225ysk start 000634
2297 - $cart = $usces->cart->get_cart();
2298 - $charging_type = $usces->getItemChargingType($cart[0]['post_id'], $cart);
2299 - if( 'continue' == $charging_type ) {
2300 - $results[0] = 1;
2301 - } else {
2302 -//20121225ysk end
2303 - if( (float)$resArray["AMT"] != (float)$entry['order']['total_full_price'] ) {
2304 - usces_log('PayPal : AMT Error. AMT='.$resArray["AMT"].', total_full_price='.$entry['order']['total_full_price'], 'acting_transaction.log');
2305 - $results[0] = 0;
2306 - } else {
2307 - $results[0] = 1;
2308 - }
2309 - }
2310 -//20121009ysk end
2311 -
2312 - } else {
2313 - //Display a user friendly Error on the page using any of the following error information returned by PayPal
2314 - $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
2315 - $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
2316 - $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
2317 - $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
2318 - 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');
2319 - $results[0] = 0;
2320 - }
2321 - $results['reg_order'] = true;
2322 - break;
2323 -//20110208ysk end
2324 -//20120413ysk start
2325 - case 'sbps_card':
2326 - case 'sbps_wallet':
2327 - case 'sbps_mobile':
2328 -/* if( isset($_REQUEST['cancel']) ) {
2329 - $results[0] = 0;
2330 - $results['reg_order'] = false;
2331 -
2332 - } else {
2333 - if( isset($_REQUEST['res_result']) and 'OK' == $_REQUEST['res_result'] ) {
2334 - usces_log($acting.' entry data : '.print_r($entry, true), 'acting_transaction.log');
2335 - $results[0] = 1;
2336 - } else {
2337 - usces_log($acting.' error : '.print_r($_REQUEST,true), 'acting_transaction.log');
2338 - $results[0] = 0;
2339 - }
2340 - $results['reg_order'] = true;
2341 - }
2342 - break;*/
2343 - case 'sbps_conv':
2344 - case 'sbps_payeasy':
2345 - if( isset($_REQUEST['cancel']) ) {
2346 - $results[0] = 0;
2347 - $results['reg_order'] = false;
2348 -
2349 - } else {
2350 - if( isset($_REQUEST['res_result']) and 'OK' == $_REQUEST['res_result'] ) {
2351 - $results[0] = 1;
2352 - } else {
2353 - //usces_log($acting.' error : '.print_r($_REQUEST,true), 'acting_transaction.log');
2354 - $results[0] = 0;
2355 - }
2356 - $results['reg_order'] = false;
2357 - }
2358 - break;
2359 -//20120413ysk end
2360 -//20120618ysk start
2361 - case 'telecom_card':
2362 - $results = $_GET;
2363 - if( $_REQUEST['result'] ){
2364 - usces_log($acting.' entry data : '.print_r($entry, true), 'acting_transaction.log');
2365 - $results[0] = 1;
2366 - }else{
2367 - usces_log($acting.' error : '.print_r($_REQUEST,true), 'acting_transaction.log');
2368 - $results[0] = 0;
2369 - }
2370 - $results['reg_order'] = true;
2371 - break;
2372 -//20120618ysk end
2373 -//20121206ysk start
2374 - case 'digitalcheck_card':
2375 - $results = $_REQUEST;
2376 - if( isset($_REQUEST['SID']) ) {
2377 - $results[0] = 1;
2378 - } else {
2379 - $results[0] = 0;
2380 - }
2381 - $results['reg_order'] = true;
2382 - break;
2383 - case 'digitalcheck_conv':
2384 - $results = $_REQUEST;
2385 - //if( isset($_REQUEST['SID']) ) {
2386 - $results[0] = 1;
2387 - //} else {
2388 - // $results[0] = 0;
2389 - //}
2390 - $results['reg_order'] = false;
2391 - break;
2392 -//20121206ysk end
2393 -//20130225ysk start
2394 - case 'mizuho_card':
2395 - case 'mizuho_conv':
2396 - $results = $_GET;
2397 - if( isset($_GET['rsltcd']) ) {
2398 - if( '000' == substr($_GET['rsltcd'], 0, 3) ) {
2399 - $results[0] = 1;
2400 - $results['reg_order'] = true;
2401 - } else {
2402 - $results[0] = 0;
2403 - $results['reg_order'] = false;
2404 - }
2405 - } else {
2406 - $results[0] = 0;
2407 - $results['reg_order'] = false;
2408 - }
2409 - break;
2410 -//20130225ysk end
2411 -
2412 - default:
2413 - do_action( 'usces_action_check_acting_return_default' );
2414 - $results = $_GET;
2415 - if( $_REQUEST['result'] ){
2416 - usces_log($acting.' entry data : '.print_r($entry, true), 'acting_transaction.log');
2417 - $results[0] = 1;
2418 - }else{
2419 - usces_log($acting.' error : '.print_r($_REQUEST,true), 'acting_transaction.log');
2420 - $results[0] = 0;
2421 - }
2422 -//20110310ysk start
2423 - //$results['reg_order'] = false;
2424 - $results['reg_order'] = true;
2425 -//20110310ysk end
2426 - break;
2427 - }
2428 -
2429 - return $results;
2430 -}
2431 -//20110203ysk start
2432 -function usces_check_acting_return_duplicate( $results = array() ) {
2433 - global $wpdb;
2434 - $acting = isset($_GET['acting']) ? $_GET['acting'] : '';
2435 -// usces_log('$_REQUEST : '.print_r($_REQUEST,true), 'acting_transaction.log');
2436 -// usces_log('$results : '.print_r($results,true), 'acting_transaction.log');
2437 -
2438 - switch($acting) {
2439 - case 'epsilon':
2440 - $trans_id = isset($_REQUEST['trans_code']) ? $_REQUEST['trans_code'] : '';
2441 - break;
2442 -//20110208ysk start
2443 - case 'paypal':
2444 - $trans_id = isset($results['txn_id']) ? $results['txn_id'] : '';
2445 - break;
2446 -//20110208ysk end
2447 - case 'paypal_ipn':
2448 - $trans_id = isset($_REQUEST['txn_id']) ? $_REQUEST['txn_id'] : '';
2449 - break;
2450 -//20110208ysk start
2451 - case 'paypal_ec':
2452 - $trans_id = isset($_REQUEST['token']) ? $_REQUEST['token'] : '';
2453 - break;
2454 -//20110208ysk end
2455 - case 'zeus_card':
2456 - $trans_id = isset($_REQUEST['ordd']) ? $_REQUEST['ordd'] : '';
2457 - break;
2458 - case 'zeus_conv':
2459 - case 'zeus_bank':
2460 - $trans_id = isset($_REQUEST['order_no']) ? $_REQUEST['order_no'] : '';
2461 - break;
2462 - case 'remise_card':
2463 - $trans_id = isset($_REQUEST['X-TRANID']) ? $_REQUEST['X-TRANID'] : '';
2464 - break;
2465 - case 'remise_conv':
2466 - $trans_id = isset($_REQUEST['X-JOB_ID']) ? $_REQUEST['X-JOB_ID'] : '';
2467 - break;
2468 - case 'jpayment_card':
2469 - case 'jpayment_conv':
2470 - case 'jpayment_bank':
2471 - $trans_id = isset($_REQUEST['gid']) ? $_REQUEST['gid'] : '';
2472 - break;
2473 -//20120413ysk start
2474 - case 'sbps_card':
2475 - case 'sbps_conv':
2476 - case 'sbps_payeasy':
2477 - case 'sbps_wallet':
2478 - case 'sbps_mobile':
2479 - $trans_id = isset($_REQUEST['order_id']) ? $_REQUEST['order_id'] : '';
2480 - break;
2481 -//20120413ysk end
2482 -//20120618ysk start
2483 - case 'telecom_card':
2484 - $trans_id = isset($_REQUEST['sendid']) ? $_REQUEST['sendid'] : '';
2485 - break;
2486 -//20120618ysk end
2487 -//20121206ysk start
2488 - case 'digitalcheck_card':
2489 - case 'digitalcheck_conv':
2490 - $trans_id = isset($_REQUEST['SID']) ? $_REQUEST['SID'] : '';
2491 - break;
2492 -//20121206ysk end
2493 -//20130225ysk start
2494 - case 'mizuho_card':
2495 - case 'mizuho_conv':
2496 - $trans_id = isset($_REQUEST['stran']) ? $_REQUEST['stran'] : '';
2497 - break;
2498 -//20130225ysk end
2499 - default:
2500 - $trans_id = '';
2501 - }
2502 - $table_meta_name = $wpdb->prefix.'usces_order_meta';
2503 - $query = $wpdb->prepare("SELECT order_id FROM $table_meta_name WHERE meta_key = %s AND meta_value = %s", 'trans_id', $trans_id);
2504 - $order_id = $wpdb->get_var($query);
2505 - return $order_id;
2506 -}
2507 -//20110203ysk end
2508 -
2509 -//20111111ysk start
2510 -function usces_dates_interconv( $date_str ) {
2511 - $base_struc = preg_split('[/.-]', 'd/m/Y' );
2512 - $date_str_parts = preg_split('[/.-]', $date_str );
2513 - $date_elements = array();
2514 -
2515 - $p_keys = array_keys( $base_struc );
2516 - foreach( $p_keys as $p_key ) {
2517 - if( !empty( $date_str_parts[$p_key] )) {
2518 - $date_elements[$base_struc[$p_key]] = $date_str_parts[$p_key];
2519 - } else {
2520 - return false;
2521 - }
2522 - }
2523 - $dummy_ts = mktime( 0,0,0, $date_elements['m'],$date_elements['d'],$date_elements['Y']);
2524 - return date( 'Y-m-d', $dummy_ts );
2525 -}
2526 -//20101111ysk end
2527 -
2528 -function usces_register_action($handle, $type, $key, $value, $function){
2529 - global $usces_action;
2530 - $usces_action[$handle] = array('type'=>$type, 'key'=>$key, 'value'=>$value, 'function'=>$function);
2531 -}
2532 -
2533 -function usces_deregister_action($handle){
2534 - global $usces_action;
2535 - unset($usces_action[$handle]);
2536 -}
2537 -
2538 -function usces_get_wcexp($post_id, $name=''){
2539 - $wcexp = get_post_meta($post_id, '_wcexp', true);
2540 - if( empty($name) ){
2541 - $value = ( $wcexp !== false ) ? $wcexp : '';
2542 - }else{
2543 - $value = ($wcexp !== false && isset($wcexp[$name])) ? $wcexp[$name] : '';
2544 - }
2545 - return $value;
2546 -}
2547 -
2548 -function usces_update_check_admin($result){
2549 - $result = true;
2550 - return $result;
2551 -}
2552 -
2553 -function usces_setup_cod_ajax(){
2554 - global $usces;
2555 - $usces->options = get_option('usces');
2556 - $message = '';
2557 - $_POST = $usces->stripslashes_deep_post($_POST);
2558 -
2559 - $usces->options['cod_type'] = isset($_POST['cod_type']) ? $_POST['cod_type'] : 'fix';
2560 - if( isset($_POST['cod_fee']) )
2561 - $usces->options['cod_fee'] = (int)$_POST['cod_fee'];
2562 -
2563 - if( 'fix' == $usces->options['cod_type'] ){
2564 - if( isset($_POST['cod_limit_amount']) ){
2565 - $usces->options['cod_limit_amount'] = (int)$_POST['cod_limit_amount'];
2566 - if( !WCUtils::is_blank($_POST['cod_limit_amount']) && 0 === (int)$_POST['cod_limit_amount'] )
2567 - $message = __('There is the item where a value is dirty.', 'usces');
2568 - }
2569 -
2570 - }elseif( 'change' == $usces->options['cod_type'] ){
2571 - if( isset($_POST['cod_first_amount']) ){
2572 - $usces->options['cod_first_amount'] = (int)$_POST['cod_first_amount'];
2573 - if( 0 === (int)$_POST['cod_first_amount'] )
2574 - $message = __('There is the item where a value is dirty.', 'usces');
2575 - }
2576 - if( isset($_POST['cod_limit_amount']) ){
2577 - $usces->options['cod_limit_amount'] = (int)$_POST['cod_limit_amount'];
2578 - if( !WCUtils::is_blank($_POST['cod_limit_amount']) && 0 === (int)$_POST['cod_limit_amount'] )
2579 - $message = __('There is the item where a value is dirty.', 'usces');
2580 - }
2581 - if( isset($_POST['cod_first_fee']) ){
2582 - $usces->options['cod_first_fee'] = (int)$_POST['cod_first_fee'];
2583 - if( 0 === (int)$_POST['cod_first_fee'] && '0' !== $_POST['cod_first_fee'])
2584 - $message = __('There is the item where a value is dirty.', 'usces');
2585 - }
2586 - if( isset($_POST['cod_end_fee']) ){
2587 - $usces->options['cod_end_fee'] = (int)$_POST['cod_end_fee'];
2588 - if( 0 === (int)$_POST['cod_end_fee'] && '0' !== $_POST['cod_end_fee'] )
2589 - $message = __('There is the item where a value is dirty.', 'usces');
2590 - }
2591 -
2592 - unset($usces->options['cod_amounts'], $usces->options['cod_fees']);
2593 - if( isset($_POST['cod_amounts']) ){
2594 - for($i=0; $i<count((array)$_POST['cod_amounts']); $i++){
2595 - $usces->options['cod_amounts'][$i] = (int)$_POST['cod_amounts'][$i];
2596 - $usces->options['cod_fees'][$i] = (int)$_POST['cod_fees'][$i];
2597 - if( 0 === (int)$_POST['cod_amounts'][$i] || (0 === (int)$_POST['cod_fees'][$i] && '0' !== $_POST['cod_fees'][$i]) )
2598 - $message = __('There is the item where a value is dirty.', 'usces');
2599 - }
2600 - }
2601 - }
2602 -
2603 -
2604 - if( '' == $message ){
2605 - $r = 'success';
2606 - update_option('usces', $usces->options);
2607 - }else{
2608 - $r = '<span style="color:red;">' . $message . '</span>';
2609 - }
2610 - die( $r );
2611 -}
2612 -
2613 -function usces_get_order_acting_data($rand){
2614 - global $wpdb;
2615 -
2616 - $table_name = $wpdb->prefix . "usces_access";
2617 - $query = $wpdb->prepare("SELECT acc_str1 AS sesid, acc_value AS order_data FROM $table_name WHERE acc_key = %s", $rand);
2618 - $res = $wpdb->get_row($query, ARRAY_A);
2619 - if($res == NULL){
2620 - return false;
2621 - }else{
2622 - return $res;
2623 - }
2624 -}
2625 -
2626 -function usces_auth_order_acting_data($rand){
2627 - global $usces, $wpdb;
2628 - $datas = usces_get_order_acting_data($rand);
2629 - $data = unserialize($datas['order_data']);
2630 - usces_log('usces_auth_order_acting_data', 'acting_transaction.log');
2631 - $data['propriety'] = 1;
2632 -
2633 - $data = serialize($data);
2634 - $table_name = $wpdb->prefix . "usces_access";
2635 - $query = $wpdb->prepare("UPDATE $table_name SET acc_value = %s WHERE acc_type = %s AND acc_key = %s",
2636 - $data,
2637 - 'acting_data',
2638 - $rand
2639 - );
2640 - $res = $wpdb->query($query);
2641 -}
2642 -
2643 -function usces_ordered_acting_data($rand){
2644 - global $usces, $wpdb;
2645 - $datas = usces_get_order_acting_data($rand);
2646 - $data = unserialize($datas['order_data']);
2647 - usces_log('usces_ordered_acting_data', 'acting_transaction.log');
2648 - $data['order_received'] = 1;
2649 -
2650 - $data = serialize($data);
2651 - $table_name = $wpdb->prefix . "usces_access";
2652 - $query = $wpdb->prepare("UPDATE $table_name SET acc_value = %s WHERE acc_type = %s AND acc_key = %s",
2653 - $data,
2654 - 'acting_data',
2655 - $rand
2656 - );
2657 - $res = $wpdb->query($query);
2658 -}
2659 -
2660 -function usces_is_trusted_acting_data($rand){
2661 - global $usces, $wpdb;
2662 - $datas = usces_get_order_acting_data($rand);
2663 - $data = unserialize($datas['order_data']);
2664 - usces_log('usces_is_trusted_acting_data', 'acting_transaction.log');
2665 - if( isset($data['propriety']) && $data['propriety'] && !isset($data['order_received']) )
2666 - return true;
2667 - else
2668 - return false;
2669 -}
2670 -
2671 -function usces_get_filename( $path ){
2672 - $res = array();
2673 - if ( $handle = opendir($path) ) {
2674 - while (false !== ($file = readdir($handle))) {
2675 - if( '.' != $file && '..' != $file )
2676 - $res[] = $file;
2677 - }
2678 - closedir($handle);
2679 - }
2680 - return $res;
2681 -}
2682 -
2683 -function usces_locales(){
2684 - $res = array();
2685 - if ( $handle = opendir(USCES_PLUGIN_DIR.'/languages/') ) {
2686 - while (false !== ($file = readdir($handle))) {
2687 - if( '.' != $file && '..' != $file && preg_match('/^usces-(.+)\.mo$/', $file, $matches) ){
2688 - $res[] = $matches[1];
2689 - }
2690 - }
2691 - closedir($handle);
2692 - }
2693 - return $res;
2694 -}
2695 -
2696 -function usces_get_local_language(){
2697 - $locale = get_locale();
2698 - switch( $locale ){
2699 - case '':
2700 - case 'en':
2701 - case 'en_US':
2702 - $front_lang = 'en';
2703 - break;
2704 - case 'ja':
2705 - case 'ja_JP':
2706 - $front_lang = 'ja';
2707 - break;
2708 - default:
2709 - $front_lang = 'others';
2710 - }
2711 - return $front_lang;
2712 -}
2713 -
2714 -function usces_get_base_country(){
2715 - global $usces_settings;
2716 -// $locale = get_locale();
2717 - $wplang = defined('WPLANG') ? WPLANG : '';
2718 - $locale = empty( $wplang ) ? 'en' : $wplang;
2719 - if( array_key_exists($locale, $usces_settings['lungage2country']) )
2720 - return $usces_settings['lungage2country'][$locale];
2721 - else
2722 - return 'US';
2723 -}
2724 -
2725 -function usces_get_local_addressform(){
2726 - global $usces_settings;
2727 - $base = usces_get_base_country();
2728 - if( array_key_exists($base, $usces_settings['addressform']) )
2729 - return $usces_settings['addressform'][$base];
2730 - else
2731 - return 'US';
2732 -}
2733 -
2734 -function usces_get_local_target_market(){
2735 - $base = usces_get_base_country();
2736 - return (array)$base;
2737 -}
2738 -
2739 -function usces_get_apply_addressform($country){
2740 - global $usces_settings;
2741 - return $usces_settings['addressform'][$country];
2742 -}
2743 -
2744 -function usces_remove_filter(){
2745 - global $usces, $post;
2746 -
2747 - if( is_single() && 'item' == $post->post_mime_type ) {
2748 - remove_filter('the_content', array(&$usces, 'filter_itemPage'));
2749 -
2750 - }else if( $usces->is_cart_page($_SERVER['REQUEST_URI']) || $usces->is_inquiry_page($_SERVER['REQUEST_URI']) ){
2751 - remove_action('the_post', array(&$usces, 'action_cartFilter'));
2752 - remove_filter('the_title', array(&$usces, 'filter_cartTitle'),20);
2753 - remove_filter('the_content', array(&$usces, 'filter_cartContent'),20);
2754 -
2755 - }else if( $usces->is_member_page($_SERVER['REQUEST_URI']) ){
2756 - remove_action('the_post', array(&$usces, 'action_memberFilter'));
2757 - remove_filter('the_title', array(&$usces, 'filter_memberTitle'),20);
2758 - remove_filter('the_content', array(&$usces, 'filter_memberContent'),20);
2759 -
2760 - }else{
2761 - remove_action('the_post', array(&$usces, 'goDefaultPage'));
2762 - }
2763 -}
2764 -
2765 -function usces_reset_filter(){
2766 - global $usces, $post;
2767 -
2768 - if( is_single() && 'item' == $post->post_mime_type ) {
2769 - add_filter('the_content', array(&$usces, 'filter_itemPage'));
2770 -
2771 - }else if( $usces->is_cart_page($_SERVER['REQUEST_URI']) || $usces->is_inquiry_page($_SERVER['REQUEST_URI']) ){
2772 - add_action('the_post', array(&$usces, 'action_cartFilter'));
2773 - add_filter('the_title', array(&$usces, 'filter_cartTitle'),20);
2774 - add_filter('the_content', array(&$usces, 'filter_cartContent'),20);
2775 -
2776 - }else if( $usces->is_member_page($_SERVER['REQUEST_URI']) ){
2777 - add_action('the_post', array(&$usces, 'action_memberFilter'));
2778 - add_filter('the_title', array(&$usces, 'filter_memberTitle'),20);
2779 - add_filter('the_content', array(&$usces, 'filter_memberContent'),20);
2780 -
2781 - }else{
2782 - add_action('the_post', array(&$usces, 'goDefaultPage'));
2783 - }
2784 -}
2785 -
2786 -
2787 -function usces_get_wcex(){
2788 - $wcex = array();
2789 - if( defined('WCEX_DLSELLER_VERSION'))
2790 - $wcex['DLSELLER'] = array('name'=>'Dl Seller', 'version'=>WCEX_DLSELLER_VERSION);
2791 - if( defined('WCEX_ITEM_LIST_LAYOUT_VERSION'))
2792 - $wcex['ITEM_LIST_LAYOUT'] = array('name'=>'Item List Layout', 'version'=>WCEX_ITEM_LIST_LAYOUT_VERSION);
2793 - if( defined('WCEX_MOBILE_VERSION'))
2794 - $wcex['MOBILE'] = array('name'=>'Mobile', 'version'=>WCEX_MOBILE_VERSION);
2795 - if( defined('WCEX_MULTIPRICE_VERSION'))
2796 - $wcex['MULTIPRICE'] = array('name'=>'Multi Price', 'version'=>WCEX_MULTIPRICE_VERSION);
2797 - if( defined('WCEX_SLIDE_SHOWCASE_VERSION'))
2798 - $wcex['SLIDE_SHOWCASE'] = array('name'=>'Slide Showcase', 'version'=>WCEX_SLIDE_SHOWCASE_VERSION);
2799 - if( defined('WCEX_WIDGET_CART_VERSION'))
2800 - $wcex['WIDGET_CART'] = array('name'=>'Widget Cart', 'version'=>WCEX_WIDGET_CART_VERSION);
2801 -
2802 - return $wcex;
2803 -}
2804 -
2805 -function usces_trackPageview_cart($push){
2806 - $push = array();
2807 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2808 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_cart'";
2809 - }else{
2810 - $push[] = "'_trackPageview','/wc_cart'";
2811 - }
2812 - return $push;
2813 -}
2814 -
2815 -function usces_trackPageview_customer($push){
2816 - $push = array();
2817 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2818 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_customer'";
2819 - }else{
2820 - $push[] = "'_trackPageview','/wc_customer'";
2821 - }
2822 - return $push;
2823 -}
2824 -
2825 -function usces_trackPageview_delivery($push){
2826 - $push = array();
2827 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2828 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_delivery'";
2829 - }else{
2830 - $push[] = "'_trackPageview','/wc_delivery'";
2831 - }
2832 - return $push;
2833 -}
2834 -
2835 -function usces_trackPageview_confirm($push){
2836 - $push = array();
2837 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2838 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_confirm'";
2839 - }else{
2840 - $push[] = "'_trackPageview','/wc_confirm'";
2841 - }
2842 - return $push;
2843 -}
2844 -
2845 -function usces_trackPageview_ordercompletion($push){
2846 - global $usces;
2847 - $sesdata = $usces->cart->get_entry();
2848 - $order_id = $sesdata['order']['ID'];
2849 - $data = $usces->get_order_data($order_id, 'direct');
2850 - $cart = unserialize($data['order_cart']);
2851 - $total_price = $usces->get_total_price( $cart ) - $data['order_discount'];
2852 -
2853 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2854 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_ordercompletion'";
2855 - }else{
2856 - $push[] = "'_trackPageview','/wc_ordercompletion'";
2857 - }
2858 - $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() . "'";
2859 - for($i=0; $i<count($cart); $i++) {
2860 - $cart_row = $cart[$i];
2861 - $post_id = $cart_row['post_id'];
2862 - $sku = urldecode($cart_row['sku']);
2863 - $quantity = $cart_row['quantity'];
2864 -// $options = $cart_row['options'];
2865 -// $advance = $usces->cart->wc_serialize($cart_row['advance']);
2866 -// $itemCode = $usces->getItemCode($post_id);
2867 - $itemName = $usces->getItemName($post_id);
2868 -// $cartItemName = $usces->getCartItemName($post_id, $sku);
2869 - $skuPrice = $cart_row['price'];
2870 - $cats = $usces->get_item_cat_genre_ids( $post_id );
2871 - if( is_array($cats) )
2872 - sort($cats);
2873 - $category = get_cat_name( $cats[0] );
2874 - $push[] = "'_addItem', '" . $order_id . "', '" . $sku . "', '" . $itemName . "', '" . $category . "', '" . $skuPrice . "', '" . $quantity . "'";
2875 - }
2876 - $push[] = "'_trackTrans'";
2877 -
2878 - return $push;
2879 -}
2880 -
2881 -function usces_trackPageview_error($push){
2882 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2883 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_error'";
2884 - }else{
2885 - $push[] = "'_trackPageview','/wc_error'";
2886 - }
2887 - return $push;
2888 -}
2889 -
2890 -function usces_trackPageview_member($push){
2891 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2892 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_member'";
2893 - }else{
2894 - $push[] = "'_trackPageview','/wc_member'";
2895 - }
2896 - return $push;
2897 -}
2898 -
2899 -function usces_trackPageview_login($push){
2900 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2901 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_login'";
2902 - }else{
2903 - $push[] = "'_trackPageview','/wc_login'";
2904 - }
2905 - return $push;
2906 -}
2907 -
2908 -function usces_trackPageview_editmemberform($push){
2909 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2910 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_editmemberform'";
2911 - }else{
2912 - $push[] = "'_trackPageview','/wc_editmemberform'";
2913 - }
2914 - return $push;
2915 -}
2916 -
2917 -function usces_trackPageview_newcompletion($push){
2918 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2919 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_newcompletion'";
2920 - }else{
2921 - $push[] = "'_trackPageview','/wc_newcompletion'";
2922 - }
2923 - return $push;
2924 -}
2925 -
2926 -function usces_trackPageview_newmemberform($push){
2927 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2928 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_newmemberform'";
2929 - }else{
2930 - $push[] = "'_trackPageview','/wc_newmemberform'";
2931 - }
2932 - return $push;
2933 -}
2934 -
2935 -function usces_trackPageview_deletemember($push){
2936 - if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2937 - $push[] = "'_trackPageview','/" . USCES_KEY . "wc_deletemember'";
2938 - }else{
2939 - $push[] = "'_trackPageview','/wc_deletemember'";
2940 - }
2941 - return $push;
2942 -}
2943 -
2944 -function usces_get_essential_mark( $fielde, $data = NULL ){
2945 - global $usces_essential_mark;
2946 - do_action('usces_action_essential_mark', $data, $fielde);
2947 - return $usces_essential_mark[$fielde];
2948 -}
2949 -
2950 -function uesces_get_admin_addressform( $type, $data, $customdata, $out = 'return' ){
2951 - global $usces, $usces_settings;
2952 - $options = get_option('usces');
2953 - $applyform = usces_get_apply_addressform($options['system']['addressform']);
2954 - $formtag = '';
2955 - switch( $type ){
2956 - case 'member':
2957 - $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']);
2958 - $country = $usces->get_member_meta_value('customer_country', $data['ID']);
2959 - $values['country'] = !empty($country) ? $country : usces_get_local_addressform();
2960 - break;
2961 - case 'customer':
2962 - $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']);
2963 - $country = $usces->get_order_meta_value('customer_country', $data['ID']);
2964 - $values['country'] = !empty($country) ? $country : usces_get_local_addressform();
2965 - break;
2966 - case 'delivery':
2967 - $values = $data;
2968 - break;
2969 - }
2970 -
2971 - switch ($applyform){
2972 -
2973 - case 'JP':
2974 - //20100818ysk start
2975 - $formtag .= usces_admin_custom_field_input($customdata, $type, 'name_pre', 'return');
2976 - //20100818ysk end
2977 - $formtag .= '
2978 - <tr>
2979 - <td class="label">' . __('name', 'usces') . '</td>
2980 - <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>
2981 - </tr>
2982 - <tr>
2983 - <td class="label">' . __('furigana', 'usces') . '</td>
2984 - <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>
2985 - </tr>';
2986 - //20100818ysk start
2987 - $formtag .= usces_admin_custom_field_input($customdata, $type, 'name_after', 'return');
2988 - //20100818ysk end
2989 - $formtag .= '
2990 - <tr>
2991 - <td class="label">' . __('Zip/Postal Code', 'usces') . '</td>
2992 - <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>
2993 - </tr>
2994 - <tr>
2995 - <td class="label">' . __('Country', 'usces') . '</td>
2996 - <td class="col2">' . uesces_get_target_market_form( $type, $values['country'] ) . '</td>
2997 - </tr>
2998 - <tr>
2999 - <td class="label">' . __('Province', 'usces') . '</td>
3000 - <td class="col2">';
3001 -
3002 - $formtag .= usces_pref_select( $type, $values );
3003 -
3004 - $formtag .= '</td>
3005 - </tr>';
3006 - $formtag .= '
3007 - <tr>
3008 - <td class="label">' . __('city', 'usces') . '</td>
3009 - <td class="col2"><input name="' . $type . '[address1]" type="text" class="text long" value="' . esc_attr($values['address1']) . '" /></td>
3010 - </tr>
3011 - <tr>
3012 - <td class="label">' . __('numbers', 'usces') . '</td>
3013 - <td class="col2"><input name="' . $type . '[address2]" type="text" class="text long" value="' . esc_attr($values['address2']) . '" /></td>
3014 - </tr>
3015 - <tr>
3016 - <td class="label">' . __('building name', 'usces') . '</td>
3017 - <td class="col2"><input name="' . $type . '[address3]" type="text" class="text long" value="' . esc_attr($values['address3']) . '" /></td>
3018 - </tr>
3019 - <tr>
3020 - <td class="label">' . __('Phone number', 'usces') . '</td>
3021 - <td class="col2"><input name="' . $type . '[tel]" type="text" class="text long" value="' . esc_attr($values['tel']) . '" /></td>
3022 - </tr>
3023 - <tr>
3024 - <td class="label">' . __('FAX number', 'usces') . '</td>
3025 - <td class="col2"><input name="' . $type . '[fax]" type="text" class="text long" value="' . esc_attr($values['fax']) . '" /></td>
3026 - </tr>';
3027 - //20100818ysk start
3028 - $formtag .= usces_admin_custom_field_input($customdata, $type, 'fax_after', 'return');
3029 - //20100818ysk end
3030 - break;
3031 -
3032 - case 'CN':
3033 - $formtag .= usces_admin_custom_field_input($customdata, $type, 'name_pre', 'return');
3034 - $formtag .= '
3035 - <tr>
3036 - <td class="label">' . __('name', 'usces') . '</td>
3037 - <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>
3038 - </tr>';
3039 - $formtag .= usces_admin_custom_field_input($customdata, $type, 'name_after', 'return');
3040 - $formtag .= '
3041 - <tr>
3042 - <td class="label">' . __('Country', 'usces') . '</td>
3043 - <td class="col2">' . uesces_get_target_market_form( $type, $values['country'] ) . '</td>
3044 - </tr>
3045 - <tr>
3046 - <td class="label">' . __('State', 'usces') . '</td>
3047 - <td class="col2">';
3048 -
3049 - $formtag .= usces_pref_select( $type, $values );
3050 -
3051 - $formtag .= '</td>
3052 - </tr>';
3053 - $formtag .= '<tr>
3054 - <td class="label">' . __('city', 'usces') . '</td>
3055 - <td class="col2"><input name="' . $type . '[address1]" type="text" class="text long" value="' . esc_attr($values['address1']) . '" /></td>
3056 - </tr>
3057 - <tr>
3058 - <td class="label">' . __('Address Line1', 'usces') . '</td>
3059 - <td class="col2"><input name="' . $type . '[address2]" type="text" class="text long" value="' . esc_attr($values['address2']) . '" /></td>
3060 - </tr>
3061 - <tr>
3062 - <td class="label">' . __('Address Line2', 'usces') . '</td>
3063 - <td class="col2"><input name="' . $type . '[address3]" type="text" class="text long" value="' . esc_attr($values['address3']) . '" /></td>
3064 - </tr>
3065 - <tr>
3066 - <td class="label">' . __('Zip', 'usces') . '</td>
3067 - <td class="col2"><input name="' . $type . '[zipcode]" type="text" class="text short" value="' . esc_attr($values['zipcode']) . '" /></td>
3068 - </tr>
3069 - <tr>
3070 - <td class="label">' . __('Phone number', 'usces') . '</td>
3071 - <td class="col2"><input name="' . $type . '[tel]" type="text" class="text long" value="' . esc_attr($values['tel']) . '" /></td>
3072 - </tr>
3073 - <tr>
3074 - <td class="label">' . __('FAX number', 'usces') . '</td>
3075 - <td class="col2"><input name="' . $type . '[fax]" type="text" class="text long" value="' . esc_attr($values['fax']) . '" /></td>
3076 - </tr>';
3077 - $formtag .= usces_admin_custom_field_input($customdata, $type, 'fax_after', 'return');
3078 - break;
3079 -
3080 - case 'US':
3081 - default:
3082 - //20100818ysk start
3083 - $formtag .= usces_admin_custom_field_input($customdata, $type, 'name_pre', 'return');
3084 - //20100818ysk end
3085 - $formtag .= '
3086 - <tr>
3087 - <td class="label">' . __('name', 'usces') . '</td>
3088 - <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>
3089 - </tr>';
3090 - //20100818ysk start
3091 - $formtag .= usces_admin_custom_field_input($customdata, $type, 'name_after', 'return');
3092 - //20100818ysk end
3093 - $formtag .= '
3094 - <tr>
3095 - <td class="label">' . __('Address Line1', 'usces') . '</td>
3096 - <td class="col2"><input name="' . $type . '[address2]" type="text" class="text long" value="' . esc_attr($values['address2']) . '" /></td>
3097 - </tr>
3098 - <tr>
3099 - <td class="label">' . __('Address Line2', 'usces') . '</td>
3100 - <td class="col2"><input name="' . $type . '[address3]" type="text" class="text long" value="' . esc_attr($values['address3']) . '" /></td>
3101 - </tr>
3102 - <tr>
3103 - <td class="label">' . __('city', 'usces') . '</td>
3104 - <td class="col2"><input name="' . $type . '[address1]" type="text" class="text long" value="' . esc_attr($values['address1']) . '" /></td>
3105 - </tr>
3106 - <tr>
3107 - <td class="label">' . __('State', 'usces') . '</td>
3108 - <td class="col2">';
3109 -
3110 - $formtag .= usces_pref_select( $type, $values );
3111 -
3112 - $formtag .= '</td>
3113 - </tr>';
3114 - $formtag .= '
3115 - <tr>
3116 - <td class="label">' . __('Country', 'usces') . '</td>
3117 - <td class="col2">' . uesces_get_target_market_form( $type, $values['country'] ) . '</td>
3118 - </tr>
3119 - <tr>
3120 - <td class="label">' . __('Zip', 'usces') . '</td>
3121 - <td class="col2"><input name="' . $type . '[zipcode]" type="text" class="text short" value="' . esc_attr($values['zipcode']) . '" /></td>
3122 - </tr>
3123 - <tr>
3124 - <td class="label">' . __('Phone number', 'usces') . '</td>
3125 - <td class="col2"><input name="' . $type . '[tel]" type="text" class="text long" value="' . esc_attr($values['tel']) . '" /></td>
3126 - </tr>
3127 - <tr>
3128 - <td class="label">' . __('FAX number', 'usces') . '</td>
3129 - <td class="col2"><input name="' . $type . '[fax]" type="text" class="text long" value="' . esc_attr($values['fax']) . '" /></td>
3130 - </tr>';
3131 - //20100818ysk start
3132 - $formtag .= usces_admin_custom_field_input($customdata, $type, 'fax_after', 'return');
3133 - //20100818ysk end
3134 - break;
3135 - }
3136 - $res = apply_filters('usces_filter_apply_admin_addressform', $formtag, $type, $data, $customdata);
3137 -
3138 -
3139 - if($out == 'return') {
3140 - return $res;
3141 - } else {
3142 - echo $res;
3143 - }
3144 -}
3145 -
3146 -function uesces_get_mail_addressform( $type, $data, $order_id, $out = 'return' ){
3147 - global $usces, $usces_settings;
3148 - $options = get_option('usces');
3149 - $applyform = usces_get_apply_addressform($options['system']['addressform']);
3150 - $formtag = '';
3151 - switch( $type ){
3152 - case 'admin_mail_customer':
3153 - $values = $data;
3154 - $values['country'] = !empty($values['country']) ? $values['country'] : usces_get_local_addressform();
3155 - $mode = 'customer';
3156 - $name_label = __('Buyer','usces');
3157 - break;
3158 - case 'admin_mail':
3159 - $values = $data;
3160 - $values['country'] = !empty($values['country']) ? $values['country'] : usces_get_local_addressform();
3161 - $mode = 'delivery';
3162 - $name_label = __('A destination name','usces');
3163 - break;
3164 - case 'order_mail_customer':
3165 - $values = $data['customer'];
3166 - $values['country'] = !empty($values['country']) ? $values['country'] : usces_get_local_addressform();
3167 - $mode = 'customer';
3168 - $name_label = __('Buyer','usces');
3169 - break;
3170 - case 'order_mail':
3171 - $values = $data['delivery'];
3172 - $values['country'] = !empty($values['country']) ? $values['country'] : usces_get_local_addressform();
3173 - $mode = 'delivery';
3174 - $name_label = __('A destination name','usces');
3175 - break;
3176 - }
3177 -
3178 - switch ($applyform){
3179 -
3180 - case 'JP':
3181 - //20110118ysk start
3182 - $formtag .= usces_mail_custom_field_info( $mode, 'name_pre', $order_id );
3183 - //20110118ysk end
3184 - $formtag .= $name_label . "\t\t: " . sprintf(__('Mr/Mrs %s', 'usces'), ($values['name1'] . ' ' . $values['name2'])) . " \r\n";
3185 - if( !empty($values['name3']) || !empty($values['name4']) ) {
3186 - $formtag .= __('furigana','usces') . "\t\t: " . $values['name3'] . ' ' . $values['name4'] . " \r\n";
3187 - }
3188 - //20110118ysk start
3189 - $formtag .= usces_mail_custom_field_info( $mode, 'name_after', $order_id );
3190 - //20110118ysk end
3191 - $formtag .= __('Country','usces') . "\t\t\t: " . $usces_settings['country'][$values['country']] . "\r\n";
3192 - $formtag .= __('Zip/Postal Code','usces') . "\t\t: " . $values['zipcode'] . "\r\n";
3193 - $formtag .= __('Address','usces') . "\t\t\t: " . $values['pref'] . $values['address1'] . $values['address2'] . " " . $values['address3'] . "\r\n";
3194 - $formtag .= __('Phone number','usces') . "\t\t: " . $values['tel'] . "\r\n";
3195 - $formtag .= __('FAX number','usces') . "\t\t: " . $values['fax'] . "\r\n";
3196 - //20110118ysk start
3197 - $formtag .= usces_mail_custom_field_info( $mode, 'fax_after', $order_id );
3198 - //20110118ysk end
3199 - break;
3200 -
3201 - case 'CN':
3202 - //20110118ysk start
3203 - $formtag .= usces_mail_custom_field_info( $mode, 'name_pre', $order_id );
3204 - //20110118ysk end
3205 - $formtag .= $name_label . "\t\t: " . sprintf(__('Mr/Mrs %s', 'usces'), ($values['name1'] . ' ' . $values['name2'])) . " \r\n";
3206 - //20110118ysk start
3207 - $formtag .= usces_mail_custom_field_info( $mode, 'name_after', $order_id );
3208 - //20110118ysk end
3209 - $formtag .= __('Country','usces') . " : " . $usces_settings['country'][$values['country']] . "\r\n";
3210 - $formtag .= __('State','usces') . " : " . $values['pref'] . "\r\n";
3211 - $formtag .= __('City','usces') . " : " . $values['address1'] . "\r\n";
3212 - $formtag .= __('Address','usces') . " : " . $values['address2'] . " " . $values['address3'] . "\r\n";
3213 - $formtag .= __('Zip/Postal Code','usces') . " : " . $values['zipcode'] . "\r\n";
3214 - $formtag .= __('Phone number','usces') . " : " . $values['tel'] . "\r\n";
3215 - $formtag .= __('FAX number','usces') . " : " . $values['fax'] . "\r\n";
3216 - //20110118ysk start
3217 - $formtag .= usces_mail_custom_field_info( $mode, 'fax_after', $order_id );
3218 - //20110118ysk end
3219 - break;
3220 -
3221 - case 'US':
3222 - default:
3223 - //20110118ysk start
3224 - $formtag .= usces_mail_custom_field_info( $mode, 'name_pre', $order_id );
3225 - //20110118ysk end
3226 - $formtag .= $name_label . " : " . sprintf(__('Mr/Mrs %s', 'usces'), ($values['name2'] . ' ' . $values['name1'])) . " \r\n";
3227 - //20110118ysk start
3228 - $formtag .= usces_mail_custom_field_info( $mode, 'name_after', $order_id );
3229 - //20110118ysk end
3230 - $formtag .= __('Address','usces') . " : " . $values['address2'] . " " . $values['address3'] . "\r\n";
3231 - $formtag .= __('City','usces') . " : " . $values['address1'] . "\r\n";
3232 - $formtag .= __('State','usces') . " : " . $values['pref'] . "\r\n";
3233 - $formtag .= __('Country','usces') . " : " . $usces_settings['country'][$values['country']] . "\r\n";
3234 - $formtag .= __('Zip/Postal Code','usces') . " : " . $values['zipcode'] . "\r\n";
3235 - $formtag .= __('Phone number','usces') . " : " . $values['tel'] . "\r\n";
3236 - $formtag .= __('FAX number','usces') . " : " . $values['fax'] . "\r\n";
3237 - //20110118ysk start
3238 - $formtag .= usces_mail_custom_field_info( $mode, 'fax_after', $order_id );
3239 - //20110118ysk end
3240 - break;
3241 - }
3242 - $res = apply_filters('usces_filter_apply_mail_addressform', $formtag, $type, $data, $order_id);
3243 -
3244 -
3245 - if($out == 'return') {
3246 - return $res;
3247 - } else {
3248 - echo $res;
3249 - }
3250 -}
3251 -
3252 -function uesces_get_target_market_form( $type, $selected, $out = 'return' ){
3253 - global $usces_settings;
3254 - $options = get_option('usces');
3255 - $res = '<select name="' . $type . '[country]" id="' . $type . '_country">'."\n";
3256 - foreach ( $usces_settings['country'] as $key => $value ){
3257 - if( in_array($key, $options['system']['target_market']) )
3258 - $res .= '<option value="' . $key . '"' . ($selected == $key ? ' selected="selected"' : '') . '>' . $value . "</option>\n";
3259 - }
3260 - $res .= '</select>'."\n";
3261 -
3262 - if($out == 'return') {
3263 - return $res;
3264 - } else {
3265 - echo $res;
3266 - }
3267 -}
3268 -
3269 -function usces_pref_select( $type, $values, $out = 'return' ){
3270 - global $usces, $usces_states;
3271 -
3272 -//20110513ysk start
3273 - //$country = empty($values['country']) ? usces_get_local_addressform() : $values['country'];
3274 - $country = empty($values['country']) ? usces_get_base_country() : $values['country'];
3275 - $options = get_option('usces');
3276 - if( !in_array($country, $options['system']['target_market']) )
3277 - $country = $options['system']['target_market'][0];
3278 -//20110513ysk end
3279 -//20110331ysk start
3280 - //$prefs = $usces_states[$country];
3281 - $prefs = get_usces_states($country);
3282 -//20110331ysk end
3283 - $html = '<select name="' . esc_attr($type . '[pref]') . '" id="' . esc_attr($type) . '_pref" class="pref">';
3284 -//20120123ysk start 0000386
3285 - //foreach((array)$prefs as $pref)
3286 - // $html .= "\t".'<option value="' . esc_attr($pref) . '"' . ($pref == $values['pref'] ? ' selected="selected"' : '') . '>' . esc_html($pref) . "</option>\n";
3287 - $prefs_count = count($prefs);
3288 - if($prefs_count > 0) {
3289 - $select = __('-- Select --', 'usces');
3290 - $html .= "\t".'<option value="' . esc_attr($select) . '">' . esc_html($select) . "</option>\n";
3291 - for($i = 1; $i < $prefs_count; $i++)
3292 - $html .= "\t".'<option value="' . esc_attr($prefs[$i]) . '"' . ($prefs[$i] == $values['pref'] ? ' selected="selected"' : '') . '>' . esc_html($prefs[$i]) . "</option>\n";
3293 - }
3294 -//20120123ysk end
3295 - $html .= "</select>\n";
3296 -
3297 - if( $out == 'return' ){
3298 - return $html;
3299 - }else{
3300 - echo $html;
3301 - }
3302 -}
3303 -
3304 -function usces_is_member_system(){
3305 - global $usces;
3306 - if($usces->options['membersystem_state'] == 'activate')
3307 - return true;
3308 - else
3309 - return false;
3310 -}
3311 -
3312 -function usces_is_member_system_point(){
3313 - global $usces;
3314 - if($usces->options['membersystem_point'] == 'activate')
3315 - return true;
3316 - else
3317 - return false;
3318 -}
3319 -
3320 -function usces_shipping_country_option( $selected, $out = '' ){
3321 - global $usces_settings;
3322 - $options = get_option('usces');
3323 - $res = '';
3324 - foreach ( $usces_settings['country'] as $key => $value ){
3325 - if( in_array($key, $options['system']['target_market']) )
3326 - $res .= '<option value="' . $key . '"' . ($selected == $key ? ' selected="selected"' : '') . '>' . $value . "</option>\n";
3327 - }
3328 -//20110317ysk start
3329 - //$res .= '<option value="world_wide"' . ($selected == $key ? ' selected="selected"' : '') . '>World Wide' . "</option>\n";
3330 -//20110317ysk end
3331 - echo $res;
3332 -}
3333 -
3334 -function usces_get_cart_button( $out = '' ) {
3335 - global $usces;
3336 - $res = '';
3337 -
3338 - if($usces->use_js){
3339 - $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;';
3340 - if( usces_is_cart() ) {
3341 - $res .= '<input name="customerinfo" type="submit" class="to_customerinfo_button" value="' . __(' Next ','usces') . '"' . apply_filters('usces_filter_cart_nextbutton', ' onclick="return uscesCart.cartNext();"') . ' />';
3342 - }
3343 - }else{
3344 - $res .= '<a href="' . get_home_url() . '" class="continue_shopping_button">' . __('continue shopping','usces') . '</a>&nbsp;&nbsp;';
3345 - if( usces_is_cart() ) {
3346 - $res .= '<input name="customerinfo" type="submit" class="to_customerinfo_button" value="' . __(' Next ','usces') . '"' . apply_filters('usces_filter_cart_nextbutton', NULL) . ' />';
3347 - }
3348 - }
3349 - $res = apply_filters('usces_filter_get_cart_button', $res);
3350 -
3351 - if($out == 'return'){
3352 - return $res;
3353 - }else{
3354 - echo $res;
3355 - }
3356 -}
3357 -
3358 -function usces_get_customer_button( $out = '' ) {
3359 - global $usces, $member_regmode;
3360 - $res = '';
3361 -
3362 - $res = '<input name="backCart" type="submit" class="back_cart_button" value="'.__('Back', 'usces').'" />&nbsp;&nbsp;';
3363 -
3364 - $button = '<input name="deliveryinfo" type="submit" class="to_deliveryinfo_button" value="'.__(' Next ', 'usces').'" />&nbsp;&nbsp;';
3365 - $res .= apply_filters('usces_filter_customer_button', $button);
3366 -
3367 - if(usces_is_membersystem_state() && $member_regmode != 'editmemberfromcart' && usces_is_login() == false ){
3368 - $res .= '<input name="reganddeliveryinfo" type="submit" class="to_reganddeliveryinfo_button" value="'.__('To the next while enrolling', 'usces').'"' . apply_filters('usces_filter_customerinfo_prebutton', NULL) . ' />';
3369 - }elseif(usces_is_membersystem_state() && $member_regmode == 'editmemberfromcart' ){
3370 - $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) . ' />';
3371 - }
3372 -
3373 - $res = apply_filters('usces_filter_get_customer_button', $res);
3374 -
3375 - if($out == 'return'){
3376 - return $res;
3377 - }else{
3378 - echo $res;
3379 - }
3380 -}
3381 -
3382 -function usces_delivery_secure_form( $out = '' ) {
3383 - global $usces, $usces_entries, $usces_carts;
3384 - $html = '';
3385 - include( USCES_PLUGIN_DIR . "/includes/delivery_secure_form.php");
3386 -
3387 - if($out == 'return'){
3388 - return $html;
3389 - }else{
3390 - echo $html;
3391 - }
3392 -}
3393 -
3394 -function usces_delivery_info_script( $out ='' ){
3395 - global $usces, $usces_entries, $usces_carts;
3396 - $html = '';
3397 - include( USCES_PLUGIN_DIR . "/includes/delivery_info_script.php");
3398 -
3399 - if($out == 'return'){
3400 - return $html;
3401 - }else{
3402 - echo $html;
3403 - }
3404 -}
3405 -
3406 -function usces_get_entries(){
3407 - global $usces, $usces_entries;
3408 - $usces_entries = $usces->cart->get_entry();
3409 -}
3410 -
3411 -function usces_get_carts(){
3412 - global $usces, $usces_carts;
3413 - $usces_carts = $usces->cart->get_cart();
3414 -}
3415 -
3416 -function usces_get_members(){
3417 - global $usces, $usces_members;
3418 - $usces_members = $usces->get_member();
3419 -}
3420 -
3421 -function usces_error_message( $out = ''){
3422 - global $usces;
3423 -
3424 - if($out == 'return'){
3425 - return $usces->error_message;
3426 - }else{
3427 - echo $usces->error_message;
3428 - }
3429 -}
3430 -
3431 -function usces_url( $type, $out = ''){
3432 - global $usces;
3433 -
3434 - switch ( $type ){
3435 - case 'cart':
3436 - $url = USCES_CART_URL;
3437 - break;
3438 - case 'login':
3439 - $url = USCES_LOGIN_URL;
3440 - break;
3441 - case 'member':
3442 - $url = USCES_MEMBER_URL;
3443 - break;
3444 - case 'newmember':
3445 - $url = USCES_NEWMEMBER_URL;
3446 - break;
3447 - case 'lostmemberpassword':
3448 - $url = USCES_LOSTMEMBERPASSWORD_URL;
3449 - break;
3450 - case 'cartnonsession':
3451 - $url = USCES_CART_NONSESSION_URL;
3452 - break;
3453 - }
3454 -
3455 - if($out == 'return'){
3456 - return $url;
3457 - }else{
3458 - echo $url;
3459 - }
3460 -}
3461 -
3462 -function usces_total_price( $out = ''){
3463 - global $usces;
3464 -
3465 - if($out == 'return'){
3466 - return $usces->get_total_price();
3467 - }else{
3468 - echo $usces->get_total_price();
3469 - }
3470 -}
3471 -
3472 -function usces_completion_settlement( $out ='' ){
3473 - global $usces, $usces_entries;
3474 - $html = '';
3475 -
3476 - $template = apply_filters( 'usces_filter_completion_settlement', USCES_PLUGIN_DIR . "/includes/completion_settlement.php", $usces_entries );
3477 - require( $template );
3478 -
3479 - if($out == 'return'){
3480 - return $html;
3481 - }else{
3482 - echo $html;
3483 - }
3484 -}
3485 -
3486 -function usces_purchase_button( $out ='' ){
3487 - global $usces, $usces_entries;
3488 - $html = '';
3489 - include( USCES_PLUGIN_DIR . "/includes/purchase_button.php");
3490 -
3491 - if($out == 'return'){
3492 - return $html;
3493 - }else{
3494 - echo $html;
3495 - }
3496 -}
3497 -
3498 -function usces_get_member_regmode(){
3499 - global $member_regmode;
3500 - $member_regmode = isset( $_SESSION['usces_entry']['member_regmode'] ) ? $_SESSION['usces_entry']['member_regmode'] : 'none';
3501 -}
3502 -
3503 -function uesces_get_error_settlement( $out = '' ) {
3504 - $res = '';
3505 - if( isset($_REQUEST['acting']) && ('zeus_conv' == $_REQUEST['acting'] || 'zeus_card' == $_REQUEST['acting'] || 'zeus_bank' == $_REQUEST['acting'] ) ){ //ZEUS
3506 - $res .= '<div class="support_box">';
3507 - if( isset($_GET['code']) ){
3508 - $res .= ' <br />エラーコード:' . esc_html($_GET['code']);
3509 - if( in_array($_GET['code'], array('02130514', '02130517', '02130619', '02130620', '02130621', '02130640')) ){
3510 - $res .= '<br />カード番号が正しくないようです。';
3511 - }elseif( in_array($_GET['code'], array('02130714', '02130717', '02130725', '02130814', '02130817', '02130825')) ){
3512 - $res .= '<br />カードの有効期限が正しくないようです。';
3513 - }elseif( in_array($_GET['code'], array('02130922')) ){
3514 - $res .= '<br />カードの有効期限が切れているようです。';
3515 - }elseif( in_array($_GET['code'], array('02131117', '02131123', '02131124')) ){
3516 - $res .= '<br />カードの名義が正しくないようです。';
3517 - }elseif( in_array($_GET['code'], array('02131414', '02131417', '02131437')) ){
3518 - $res .= '<br />お客様情報の電話番号が正しくないようです。';
3519 - }elseif( in_array($_GET['code'], array('02131527', '02131528', '02131529', '02131537')) ){
3520 - $res .= '<br />お客様情報のEメールアドレスが正しくないようです。';
3521 - }
3522 - $res .= ' <br />
3523 -  <br />
3524 - <a href="' . USCES_CUSTOMER_URL . '">もう一度決済を行う>></a><br />';
3525 - }else{
3526 - $res .= ' <br />エラーコード:' . esc_html($_GET['err_code']);
3527 - $res .= ' <br />
3528 - カード番号を再入力する場合はこちらをクリックしてください。<br />
3529 -  <br />
3530 - <a href="' . USCES_CUSTOMER_URL . '&re-enter=1">カード番号の再入力>></a><br />';
3531 - }
3532 - $res .= ' <br />
3533 - ゼウス・カスタマーサポート(24時間365日)<br />
3534 - 電話番号:0570-02-3939(つながらないときは 03-4334-0500)<br />
3535 - E-mail:support@cardservice.co.jp
3536 - </div>'."\n";
3537 - }
3538 - $res = apply_filters( 'usces_filter_get_error_settlement', $res );
3539 -
3540 - if($out == 'return'){
3541 - return $res;
3542 - }else{
3543 - echo $res;
3544 - }
3545 -}
3546 -
3547 -function usces_page_name( $out = '') {
3548 - global $usces;
3549 - $page = '';
3550 -
3551 - if( empty($usces->page) ){
3552 - if( $usces->is_cart_page($_SERVER['REQUEST_URI']) ){
3553 - $page = 'cart';
3554 - }elseif( $usces->is_member_page($_SERVER['REQUEST_URI']) ){
3555 - $page = 'member';
3556 - }
3557 - }else{
3558 - $page = $usces->page;
3559 - }
3560 -
3561 - if($out == 'return'){
3562 - return $page;
3563 - }else{
3564 - echo $page;
3565 - }
3566 -}
3567 -
3568 -function usces_post_reg_orderdata($order_id, $results){
3569 - global $usces, $wpdb;
3570 - //$entry = $usces->cart->get_entry();//20110621ysk 0000184
3571 - $acting = isset($_GET['acting']) ? $_GET['acting'] : '';
3572 - $data = array();
3573 -
3574 - if( $order_id ){
3575 -
3576 - switch ( $acting ) {
3577 - case 'epsilon':
3578 - $trans_id = isset($_REQUEST['trans_code']) ? $_REQUEST['trans_code'] : '';
3579 - break;
3580 - case 'paypal_ipn':
3581 - $trans_id = isset($_REQUEST['txn_id']) ? $_REQUEST['txn_id'] : '';
3582 - break;
3583 - case 'paypal':
3584 - $trans_id = isset($results['txn_id']) ? $results['txn_id'] : '';
3585 - break;
3586 -//20110208ysk start
3587 - case 'paypal_ec':
3588 - $trans_id = isset($_REQUEST['token']) ? $_REQUEST['token'] : '';
3589 -//20110621ysk start 0000184
3590 - if(isset($results['settlement_id']))
3591 - $usces->set_order_meta_value('settlement_id', $results['settlement_id'], $order_id);
3592 - if(isset($results['profile_id']))
3593 - $usces->set_order_meta_value('profile_id', $results['profile_id'], $order_id);
3594 -//20110621ysk end
3595 - break;
3596 -//20110208ysk end
3597 - case 'zeus_card':
3598 - $acting_opts = $usces->options['acting_settings']['zeus'];
3599 - if( isset($_GET['zeussuffix']) ){
3600 - $data['acting'] = 'zeus_card Secure API';
3601 - $data['order_number'] = $_GET['zeusordd'];
3602 -
3603 - $usces->set_order_meta_value('acting_'.$acting, serialize($data), $order_id);
3604 - if( $usces->is_member_logged_in() ){
3605 - //if( 2 == $acting_opts['security'] && 'on' == $acting_opts['quickcharge']){
3606 - if( 'on' == $acting_opts['quickcharge']){
3607 - $usces->set_member_meta_value('zeus_pcid', '8888888888888888');
3608 - }
3609 - $usces->set_member_meta_value('zeus_partofcard', $_GET['zeussuffix']);
3610 - $usces->set_member_meta_value('zeus_limitofcard', ($_GET['zeusyear'].'/'.$_GET['zeusmonth']));
3611 - }
3612 - }else{
3613 - $trans_id = isset($_REQUEST['ordd']) ? $_REQUEST['ordd'] : '';
3614 - //foreach($_GET as $key => $value) {
3615 - // $data[$key] = mysql_real_escape_string($value);
3616 - //}
3617 - //$usces->set_order_meta_value('acting_'.$acting, serialize($data), $order_id);
3618 - if( !empty($_REQUEST['order_number']) ) {
3619 - $usces->set_order_meta_value( 'order_number', $_REQUEST['order_number'], $order_id );
3620 - }
3621 - if( $usces->is_member_logged_in() ) {
3622 - if( 'on' == $acting_opts['quickcharge'] ) {
3623 - $usces->set_member_meta_value('zeus_pcid', '8888888888888888');
3624 - }
3625 - }
3626 - }
3627 - if(empty($usces)){
3628 - usces_log('zeus card transaction : No Session', 'acting_transaction.log');
3629 - }else{
3630 - usces_log('zeus card transaction : OK', 'acting_transaction.log');
3631 - }
3632 - break;
3633 - case 'zeus_conv':
3634 - $trans_id = isset($_REQUEST['order_no']) ? $_REQUEST['sendpoint'] : '';
3635 - $zeus_convs = array(
3636 - 'acting' => 'zeus_conv',
3637 - 'pay_cvs' => isset($_REQUEST['pay_cvs']) ? $_REQUEST['pay_cvs'] : '',
3638 - 'order_no' => isset($_REQUEST['order_no']) ? $_REQUEST['order_no'] : '',
3639 - 'money' => isset($_REQUEST['money']) ? $_REQUEST['money'] : '',
3640 - 'pay_no1' => isset($_REQUEST['pay_no1']) ? $_REQUEST['pay_no1'] : '',
3641 - 'pay_no2' => isset($_REQUEST['pay_no2']) ? $_REQUEST['pay_no2'] : '',
3642 - 'pay_limit' => isset($_REQUEST['pay_limit']) ? $_REQUEST['pay_limit'] : '',
3643 - 'status' => isset($_REQUEST['status']) ? $_REQUEST['status'] : '',
3644 - 'error_code' => isset($_REQUEST['error_code']) ? $_REQUEST['error_code'] : ''
3645 - );
3646 - $usces->set_order_meta_value('acting_'.(isset($_REQUEST['sendpoint']) ? $_REQUEST['sendpoint'] : ''), serialize($zeus_convs), $order_id);
3647 - break;
3648 - case 'zeus_bank':
3649 - $trans_id = isset($_REQUEST['order_no']) ? $_REQUEST['order_no'] : '';
3650 - break;
3651 - case 'remise_card':
3652 - $trans_id = isset($_REQUEST['X-TRANID']) ? $_REQUEST['X-TRANID'] : '';
3653 - break;
3654 - case 'remise_conv':
3655 - $trans_id = isset($_REQUEST['X-JOB_ID']) ? $_REQUEST['X-JOB_ID'] : '';
3656 - break;
3657 - case 'jpayment_card':
3658 - case 'jpayment_conv':
3659 - case 'jpayment_bank':
3660 - $trans_id = isset($_REQUEST['gid']) ? $_REQUEST['gid'] : '';
3661 - break;
3662 -//20120413ysk start
3663 - case 'sbps_card':
3664 - case 'sbps_conv':
3665 - case 'sbps_payeasy':
3666 - case 'sbps_wallet':
3667 - case 'sbps_mobile':
3668 - $trans_id = isset($_REQUEST['order_id']) ? $_REQUEST['order_id'] : '';
3669 - break;
3670 -//20120413ysk end
3671 -//20120618ysk start
3672 - case 'telecom_card':
3673 - $trans_id = isset($_REQUEST['sendid']) ? $_REQUEST['sendid'] : '';
3674 - break;
3675 -//20120618ysk end
3676 -//20121206ysk start
3677 - case 'digitalcheck_card':
3678 - case 'digitalcheck_conv':
3679 - $trans_id = isset($_REQUEST['SID']) ? $_REQUEST['SID'] : '';
3680 - break;
3681 -//20121206ysk end
3682 -//20130225ysk start
3683 - case 'mizuho_card':
3684 - case 'mizuho_conv':
3685 - $trans_id = isset($_REQUEST['stran']) ? $_REQUEST['stran'] : '';
3686 - break;
3687 -//20130225ysk end
3688 - default:
3689 - if( isset($_REQUEST['FUKA']) && strstr($_REQUEST['FUKA'], "digitalcheck_card") ) {
3690 - $trans_id = isset($_REQUEST['SID']) ? $_REQUEST['SID'] : '';
3691 - } else {
3692 - $trans_id = '';
3693 - }
3694 - }
3695 -
3696 - if(!empty($trans_id)) {
3697 - $usces->set_order_meta_value('trans_id', $trans_id, $order_id);
3698 - }
3699 - }
3700 -
3701 -}
3702 -
3703 -//20110621ysk start 0000184
3704 -function usces_paypal_doecp( &$results ) {
3705 - global $usces;
3706 - $entry = $usces->cart->get_entry();
3707 - $cart = $usces->cart->get_cart();
3708 -
3709 - $post_id = $cart[0]['post_id'];
3710 - $charging_type = $usces->getItemChargingType( $post_id );
3711 - if( 'continue' != $charging_type ) {
3712 - //通常購入
3713 - //Format the other parameters that were stored in the session from the previous calls
3714 - $paymentAmount = usces_crform($entry['order']['total_full_price'], false, false, 'return', false);
3715 - $token = urlencode($_REQUEST['token']);
3716 - $paymentType = urlencode("Sale");
3717 - $currencyCodeType = urlencode($usces->get_currency_code());
3718 - $payerID = urlencode($_REQUEST['PayerID']);
3719 - $serverName = urlencode($_SERVER['SERVER_NAME']);
3720 -
3721 - $nvpstr = '&TOKEN='.$token.'&PAYERID='.$payerID.'&PAYMENTACTION='.$paymentType.'&AMT='.$paymentAmount.'&CURRENCYCODE='.$currencyCodeType.'&IPADDRESS='.$serverName;
3722 - $nvpstr = apply_filters( 'usces_filter_usces_paypal_doecp', $nvpstr, $charging_type );
3723 -
3724 - $usces->paypal->setMethod('DoExpressCheckoutPayment');
3725 - $usces->paypal->setData($nvpstr);
3726 - $res = $usces->paypal->doExpressCheckout();
3727 - $resArray = $usces->paypal->getResponse();
3728 - $ack = strtoupper($resArray["ACK"]);
3729 - if($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
3730 - $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.
3731 - //$usces->set_order_meta_value('settlement_id', $transactionId, $order_id);
3732 - $results['settlement_id'] = $transactionId;
3733 -
3734 - } else {
3735 - //Display a user friendly Error on the page using any of the following error information returned by PayPal
3736 - $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
3737 - $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
3738 - $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
3739 - $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
3740 - 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');
3741 - return false;
3742 - }
3743 -
3744 - } else {
3745 - //定期支払い
3746 - //$paymentAmount = usces_crform($entry['order']['total_items_price'], false, false, 'return', false);
3747 - $paymentAmount = usces_crform($entry['order']['total_full_price'], false, false, 'return', false);//20111129ysk 0000320
3748 - $token = urlencode($_REQUEST['token']);
3749 - $currencyCodeType = urlencode($usces->get_currency_code());
3750 - //$nextdate = get_date_from_gmt(gmdate('Y-m-d H:i:s', time()));
3751 - //$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';
3752 - $profileStartDate = date('Y-m-d', dlseller_first_charging($post_id, 'time')).'T01:01:01Z';
3753 - $billingPeriod = "Month";// or "Day", "Week", "SemiMonth", "Year"
3754 - $billingFreq = $usces->getItemFrequency($post_id);
3755 - //$desc = urlencode(usces_make_agreement_description($cart, $entry['order']['total_items_price']));
3756 - $desc = urlencode(usces_make_agreement_description($cart, $entry['order']['total_full_price']));//20111125ysk 0000320
3757 - $totalBillingCycles = (empty($dlitem['dlseller_interval'])) ? '' : '&TOTALBILLINGCYCLES='.urlencode($dlitem['dlseller_interval']);
3758 - //$totalBillingCycles = ( dlseller_auto_stop() ) ? '&TOTALBILLINGCYCLES='.dlseller_cycles( $post_id ) : '';
3759 -
3760 - //$nvpstr = '&TOKEN='.$token.'&AMT='.$paymentAmount.'&CURRENCYCODE='.$currencyCodeType.'&PROFILESTARTDATE='.$profileStartDate.'&BILLINGPERIOD='.$billingPeriod.'&BILLINGFREQUENCY='.$billingFreq.'&DESC='.$desc;
3761 - $nvpstr = '&TOKEN='.$token.'&AMT='.$paymentAmount.'&CURRENCYCODE='.$currencyCodeType.'&PROFILESTARTDATE='.$profileStartDate.'&BILLINGPERIOD='.$billingPeriod.'&BILLINGFREQUENCY='.$billingFreq.'&DESC='.$desc.$totalBillingCycles;
3762 - $nvpstr = apply_filters( 'usces_filter_usces_paypal_doecp', $nvpstr, $charging_type );
3763 -
3764 - $usces->paypal->setMethod('CreateRecurringPaymentsProfile');
3765 - $usces->paypal->setData($nvpstr);
3766 - $res = $usces->paypal->doExpressCheckout();
3767 - $resArray = $usces->paypal->getResponse();
3768 - $ack = strtoupper($resArray["ACK"]);
3769 - if($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
3770 - $profileid = $resArray["PROFILEID"];
3771 - //$usces->set_order_meta_value('profile_id', $profileid, $order_id);
3772 - $results['settlement_id'] = $profileid;
3773 - $results['profile_id'] = $profileid;
3774 -
3775 - } else {
3776 - //Display a user friendly Error on the page using any of the following error information returned by PayPal
3777 - $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
3778 - $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
3779 - $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
3780 - $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
3781 - 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');
3782 - return false;
3783 - }
3784 - }
3785 -
3786 - return true;
3787 -}
3788 -//20110621ysk end
3789 -//20110421ysk start
3790 -function usces_make_agreement_description($cart, $amt) {
3791 - global $usces;
3792 -
3793 - $cart_row = $cart[0];
3794 - $quantity = $cart_row['quantity'];
3795 - $itemName = $usces->getItemName($cart_row['post_id']);
3796 - //if(1 < count($cart)) $itemName .= ','.__('Others', 'usces');
3797 - if(50 < mb_strlen($itemName)) $itemName = mb_substr($itemName, 0, 50).'...';
3798 - $amt = usces_crform($amt, true, false, 'return', true);
3799 - $desc = $itemName.' '.__('Quantity','usces').':'.$quantity.' '.$amt;
3800 - return($desc);
3801 -}
3802 -//20110421ysk end
3803 -
3804 -function usces_get_send_out_date(){
3805 - global $usces;
3806 -
3807 - $bus_day_arr = (isset($usces->options['business_days'])) ? $usces->options['business_days'] : false;
3808 - list( $today_year, $today_month, $today_day, $hour, $minute, $second ) = preg_split( '([^0-9])', current_time('mysql') );
3809 - if( !is_array($bus_day_arr) ){
3810 - $today_bus_flag = 1;
3811 - }else{
3812 - $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;
3813 - }
3814 - // get the time limit addition
3815 - $limit_hour = (!empty($usces->options['delivery_time_limit']['hour'])) ? $usces->options['delivery_time_limit']['hour'] : false;
3816 - $limit_min = (!empty($usces->options['delivery_time_limit']['min'])) ? $usces->options['delivery_time_limit']['min'] : false;
3817 -
3818 - if( false === $hour || false === $minute ){
3819 - $time_limit_addition = false;
3820 - }elseif( ($hour.':'.$minute.':'.$second) > ($limit_hour.':'.$limit_min.':00') ){
3821 - $time_limit_addition = 1;
3822 - }else{
3823 - $time_limit_addition = 0;
3824 - }
3825 - // get the shipping indication in cart
3826 - $cart = $usces->cart->get_cart();
3827 - $shipping_indication = apply_filters('usces_filter_shipping_indication', $usces->options['usces_shipping_indication']);
3828 - $shipping = 0;
3829 - $indication_flag = true;
3830 - for($i = 0; $i < count($cart); $i++) {
3831 - $cart_row = $cart[$i];
3832 - $post_id = $cart_row['post_id'];
3833 - $itemShipping = (int)$usces->getItemShipping($post_id);
3834 - if($itemShipping === 0 or $itemShipping === 9) {
3835 - $indication_flag = false;
3836 - break;
3837 - }
3838 - if($shipping < $itemShipping) $shipping = $itemShipping;
3839 - }
3840 - $indication_incart = ( $indication_flag ) ? $shipping_indication[$shipping] : false;
3841 - // get the send out date
3842 - $sendout_num = 0;
3843 - if( $today_bus_flag ){
3844 - if( $time_limit_addition ){
3845 - $sendout_num += 1;
3846 - }
3847 - if( false !== $indication_incart ){
3848 - $sendout_num += $indication_incart;
3849 - }
3850 - }else{
3851 - if( false !== $indication_incart ){
3852 - $sendout_num += $indication_incart;
3853 - }
3854 - }
3855 - $holiday = 0;
3856 - for( $i=0; $i<=$sendout_num; $i++ ){
3857 - list($yyyy, $mm, $dd) = explode('-', date('Y-m-d', mktime(0,0,0,(int)$today_month,($today_day + $i),(int)$today_year)));
3858 - if( isset($bus_day_arr[(int)$yyyy][(int)$mm][(int)$dd]) && !$bus_day_arr[(int)$yyyy][(int)$mm][(int)$dd] ){
3859 - $holiday++;
3860 - $sendout_num++;
3861 - }
3862 - if( 100 < $sendout_num ) break;
3863 - }
3864 - 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)));
3865 -
3866 - $res = array(
3867 - 'today_bus_flag' => $today_bus_flag,
3868 - 'time_limit_addition'=> $time_limit_addition,
3869 - 'indication_incart' => $indication_incart,
3870 - 'holiday' => $holiday,
3871 - 'sendout_num' => $sendout_num,
3872 - 'sendout_date' => array('year' => $send_y, 'month' => $send_m, 'day' => $send_d)
3873 - );
3874 - return $res;
3875 -}
3876 -
3877 -function usces_action_footer_comment(){
3878 - echo "<!-- Welcart version : v".USCES_VERSION." -->\n";
3879 -}
3880 -
3881 -function usces_set_acting_notification_time( $key ){
3882 - global $wpdb;
3883 - $tableName = $wpdb->prefix . "usces_access";
3884 - $query = $wpdb->prepare("SELECT ID FROM $tableName WHERE acc_type = %s AND acc_key = %s", 'notification_time', $key);
3885 - $res = $wpdb->get_var( $query );
3886 - if( $res )
3887 - return;
3888 -
3889 - $query = $wpdb->prepare("INSERT INTO $tableName (acc_key, acc_type, acc_num1) VALUES (%s, %s, %d)",
3890 - $key, 'notification_time', time());
3891 - $res = $wpdb->query( $query );
3892 -}
3893 -
3894 -function usces_check_notification_time( $key, $time ){
3895 - global $wpdb;
3896 - $tableName = $wpdb->prefix . "usces_access";
3897 - $query = $wpdb->prepare("SELECT acc_num1 FROM $tableName WHERE acc_type = %s AND acc_key = %s", 'notification_time', $key);
3898 - $res = $wpdb->get_var( $query );
3899 - if( !$res )
3900 - return false;
3901 -
3902 - $past = time() - $res;
3903 - if( $time > $past )
3904 - return true;
3905 - else
3906 - return false;
3907 -}
3908 -
3909 -function usces_is_same_itemcode( $post_id, $item_code ){
3910 - global $wpdb, $usces;
3911 -
3912 - $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);
3913 - $ids = $wpdb->get_col( $query );
3914 -// usces_log('ids : '.print_r($query,true), 'acting_transaction.log');
3915 -// usces_log('ids : '.print_r($ids,true), 'acting_transaction.log');
3916 - if( !$ids ){
3917 - return false;
3918 - }
3919 - $id_str = implode(',', $ids);
3920 - $query = "SELECT ID FROM $wpdb->posts WHERE ID IN({$id_str}) AND post_status = 'publish'";
3921 - $res = $wpdb->get_col( $query );
3922 -// usces_log('res : '.print_r($res,true), 'acting_transaction.log');
3923 -// usces_log('res : '.print_r($query,true), 'acting_transaction.log');
3924 - if( !$res ){
3925 - return false;
3926 - }
3927 -
3928 - return $res;
3929 -}
3930 -
3931 -function usces_update_sku( $post_id, $skucode, $fieldname, $value ){
3932 - global $wpdb;
3933 - $metas = usces_get_post_meta($post_id, '_isku_');
3934 - if( ! $metas )
3935 - return false;
3936 -
3937 - $meta_id = '';
3938 - foreach( $metas as $meta ){
3939 - $sku = unserialize($meta['meta_value']);
3940 - if( $skucode == $sku['code'] ){
3941 - $meta_id = $meta['meta_id'];
3942 - $sku[$fieldname] = $value;
3943 - break;
3944 - }
3945 - }
3946 - $serialized_values = serialize($sku);
3947 - if( !empty($meta_id) ) $res = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $serialized_values, $meta_id) );
3948 - if( !$res ){
3949 - return false;
3950 - }else{
3951 - return true;
3952 - }
3953 -}
3954 -
3955 -function usces_get_items_skus() {
3956 - global $wpdb, $usces;
3957 - $res = array();
3958 - $item_codes = array();
3959 - $item_names = array();
3960 - $status = array();
3961 -
3962 - $query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts}
3963 - WHERE post_mime_type = %s AND post_status = %s", 'item', 'publish');
3964 - $IDs = $wpdb->get_col($query);
3965 - if( !$IDs )
3966 - return $res;
3967 -
3968 - //wp_cache_set( 'item_ids', $IDs );
3969 -
3970 - $key = 0;
3971 - foreach((array)$IDs as $post_id){
3972 - $item_codes[$post_id] = $usces->getItemCode($post_id);
3973 - $item_names[$post_id] = $usces->getItemName($post_id);
3974 -
3975 - //$skus = $usces->get_skus($post_id);
3976 - $metas = usces_get_post_meta($post_id, '_isku_');
3977 - foreach( (array)$metas as $mkey => $rows ){
3978 - $metas[$mkey]['meta_value'] = unserialize($rows['meta_value']);
3979 - $allmetas[] = $metas;
3980 -// $sku_post_id[] = $post_id;
3981 -// $sku_code[] = $values['code'];
3982 -// $sku_stocknum[] = $values['stocknum'];
3983 - $status[] = $metas[$mkey]['meta_value']['stock'];
3984 - $key++;
3985 - }
3986 - //usces_log('implode : '.strlen(explode(',', $res)), 'acting_transaction.log');
3987 - }
3988 -// wp_cache_set( 'item_ids', $IDs );
3989 -// wp_cache_set( 'item_codes', $item_codes );
3990 -// wp_cache_set( 'item_names', $item_names );
3991 -// wp_cache_set( 'sku_data', $res );
3992 -// wp_cache_set( 'stock_ct', array_count_values($status) );
3993 -
3994 -}
3995 -function usces_get_non_zerostoc_items() {
3996 - global $wpdb, $usces;
3997 -
3998 - $query = $wpdb->prepare("SELECT ID, code.meta_value AS code, name.meta_value AS name FROM {$wpdb->posts}
3999 - LEFT JOIN {$wpdb->postmeta} AS code ON ID = code.post_id AND '_itemCode' = code.meta_key
4000 - LEFT JOIN {$wpdb->postmeta} AS name ON ID = name.post_id AND '_itemName' = name.meta_key
4001 - LEFT JOIN {$wpdb->postmeta} AS sku ON ID = sku.post_id AND '_isku_' = sku.meta_key
4002 - 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)
4003 - GROUP BY ID",
4004 - 'item', 'post', 'trush', '%"stocknum";i:0%', '%"stocknum";s:1:"0"%');
4005 - $res = $wpdb->get_results($query, ARRAY_A);
4006 -
4007 - return $res;
4008 -
4009 -// $key = 0;
4010 -// foreach((array)$items as $item){
4011 -//// $ItemCode = $usces->getItemCode($item['ID']);
4012 -//// $ItemName = $usces->getItemName($item['ID']);
4013 -//
4014 -// //$skus = $usces->get_skus($post_id);
4015 -// $metas = usces_get_post_meta($item['ID'], '_isku_');
4016 -// foreach( (array)$metas as $rows ){
4017 -// $meta_value = unserialize($rows['meta_value']);
4018 -// if( "" != $meta_value['stocknum'] && 0 === (int)$meta_value['stocknum'] ){
4019 -// $res[$key]['ID'] = $item['ID'];
4020 -// $res[$key]['code'] = $item['code'];
4021 -// $res[$key]['name'] = $item['name'];
4022 -// $res[$key]['sku'] = $meta_value['code'];
4023 -// }
4024 -// $key++;
4025 -// }
4026 -// }
4027 -// return $res;
4028 -}
4029 -function usces_get_stocs() {
4030 - global $wpdb, $usces;
4031 - $status = array();
4032 -
4033 - $query = $wpdb->prepare("SELECT m.meta_value FROM {$wpdb->posts} AS p
4034 - LEFT JOIN {$wpdb->postmeta} AS m ON p.ID = m.post_id AND m.meta_key = %s
4035 - WHERE post_mime_type = %s AND post_type = %s AND post_status <> %s"
4036 - , '_isku_', 'item', 'post', 'trush');
4037 - $values = $wpdb->get_col($query);
4038 - if( !$values )
4039 - return $status;
4040 -
4041 - foreach((array)$values as $value){
4042 - $meta_value = unserialize($value);
4043 - $status[] = (string)$meta_value['stock'];
4044 - }
4045 - return array_count_values($status);
4046 -}
4047 -
4048 -function usces_get_deco_order_id( $order_id ) {
4049 - global $usces;
4050 -
4051 - $dec_order_id = $usces->get_order_meta_value( 'dec_order_id', $order_id);
4052 - if( !$dec_order_id ){
4053 - $dec_order_id = str_pad($order_id, $usces->options['system']['dec_orderID_digit'], "0", STR_PAD_LEFT);
4054 - }
4055 - return $dec_order_id;
4056 -}
4057 -
4058 -function usces_mail_line( $type, $email = '' ) {
4059 - $line = '';
4060 -
4061 - switch( $type ) {
4062 - case 1:
4063 - $line = "******************************************************************";
4064 - break;
4065 - case 2:
4066 - $line = "------------------------------------------------------------------";
4067 - break;
4068 - case 3:
4069 - $line = "==================================================================";
4070 - break;
4071 - }
4072 -
4073 - $line = apply_filters( 'usces_filter_mail_line', $line, $type, $email );
4074 -
4075 - return $line."\r\n";
4076 -}
4077 -
4078 -function usces_get_gp_price($post_id, $p, $quant){
4079 - global $usces;
4080 - $GpN1 = $usces->getItemGpNum1($post_id);
4081 - $GpN2 = $usces->getItemGpNum2($post_id);
4082 - $GpN3 = $usces->getItemGpNum3($post_id);
4083 - $GpD1 = $usces->getItemGpDis1($post_id);
4084 - $GpD2 = $usces->getItemGpDis2($post_id);
4085 - $GpD3 = $usces->getItemGpDis3($post_id);
4086 -
4087 - if( empty($GpN1) || empty($GpD1) ) {
4088 -
4089 - $realprice = $p;
4090 -
4091 - }else if( (!empty($GpN1) && !empty($GpD1)) && (empty($GpN2) || empty($GpD2)) ) {
4092 -
4093 - if( $quant >= $GpN1 ) {
4094 - $realprice = round($p * (100 - $GpD1) / 100);
4095 - }else{
4096 - $realprice = $p;
4097 - }
4098 -
4099 - }else if( (!empty($GpN1) && !empty($GpD1)) && (!empty($GpN2) && !empty($GpD2)) && (empty($GpN3) || empty($GpD3)) ) {
4100 -
4101 - if( $quant >= $GpN2 ) {
4102 - $realprice = round($p * (100 - $GpD2) / 100);
4103 - }else if( $quant >= $GpN1 && $quant < $GpN2 ) {
4104 - $realprice = round($p * (100 - $GpD1) / 100);
4105 - }else{
4106 - $realprice = $p;
4107 - }
4108 -
4109 - }else if( (!empty($GpN1) && !empty($GpD1)) && (!empty($GpN2) && !empty($GpD2)) && (!empty($GpN3) && !empty($GpD3)) ) {
4110 -
4111 - if( $quant >= $GpN3 ) {
4112 - $realprice = round($p * (100 - $GpD3) / 100);
4113 - }else if( $quant >= $GpN2 && $quant < $GpN3 ) {
4114 - $realprice = round($p * (100 - $GpD2) / 100);
4115 - }else if( $quant >= $GpN1 && $quant < $GpN2 ) {
4116 - $realprice = round($p * (100 - $GpD1) / 100);
4117 - }else{
4118 - $realprice = $p;
4119 - }
4120 -
4121 - }else{
4122 - $realprice = $p;
4123 - }
4124 -
4125 - $realprice = apply_filters('usces_filter_get_gp_price', $realprice, $post_id, $p, $quant);
4126 - return $realprice;
4127 -}
4128 -//20120306ysk start 0000324
4129 -function usces_is_complete_settlement( $payment_name, $status = '' ) {
4130 - $complete = false;
4131 -//20120919ysk start 0000573
4132 - $options = get_option('usces');
4133 - if( $options['point_assign'] == 0 ) {
4134 - $complete = true;
4135 -//20120919ysk end
4136 - } else {
4137 - $payments = usces_get_system_option( 'usces_payment_method', 'name' );
4138 - if( isset($payments[$payment_name]['settlement']) ) {
4139 - switch( $payments[$payment_name]['settlement'] ) {
4140 - case 'acting':
4141 - if( false !== strpos( $status, 'pending' ) ) break;
4142 - case 'acting_zeus_card':
4143 - case 'acting_remise_card':
4144 - case 'acting_jpayment_card':
4145 - case 'acting_paypal_ec':
4146 - case 'acting_sbps_card':
4147 - case 'acting_telecom_card':
4148 - case 'acting_digitalcheck_card':
4149 - case 'acting_mizuho_card':
4150 - case 'COD':
4151 - $complete = true;
4152 - }
4153 - }
4154 - }
4155 - $complete = apply_filters( 'usces_filter_is_complete_settlement', $complete, $payment_name, $status );
4156 - return $complete;
4157 -}
4158 -
4159 -function usces_action_acting_getpoint( $order_id, $add = true ) {
4160 - global $usces, $wpdb;
4161 -
4162 - if( !apply_filters( 'usces_action_acting_getpoint_switch', true, $order_id, $add) )
4163 - return;
4164 -
4165 -//20120919ysk start 0000573
4166 - $options = get_option('usces');
4167 - if( $options['point_assign'] != 0 ) {
4168 -//20120919ysk end
4169 - if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] ) {
4170 - $table_name = $wpdb->prefix . "usces_order";
4171 - $mquery = $wpdb->prepare("SELECT mem_id, order_getpoint FROM $table_name WHERE ID = %d", $order_id);
4172 - $values = $wpdb->get_row( $mquery, ARRAY_A );
4173 - $mem_id = $values['mem_id'];
4174 - $getpoint = $values['order_getpoint'];
4175 -
4176 - if( !empty($mem_id) && 0 < $getpoint ) {
4177 - $calc = ($add) ? '+' : '-';
4178 - $member_table_name = $wpdb->prefix . "usces_member";
4179 - $mquery = $wpdb->prepare("UPDATE $member_table_name SET mem_point = (mem_point ".$calc." %d) WHERE ID = %d", $getpoint, $mem_id);
4180 - $wpdb->query( $mquery );
4181 -
4182 - if( !empty($_SESSION['usces_member']['point']) ) {
4183 - $mquery = $wpdb->prepare("SELECT mem_point FROM $member_table_name WHERE ID = %d", $mem_id);
4184 - $point = $wpdb->get_var( $mquery );
4185 - $_SESSION['usces_member']['point'] = $point;
4186 - }
4187 - }
4188 - }
4189 - }
4190 - do_action( 'usces_action_acting_getpoint', $order_id, $add );
4191 -}
4192 -
4193 -function usces_restore_point( $mem_id, $point ) {
4194 - global $wpdb;
4195 -
4196 - if( !apply_filters( 'usces_action_restore_point_switch', true, $mem_id, $point) )
4197 - return;
4198 -
4199 - $member_table_name = $wpdb->prefix . "usces_member";
4200 - $query = $wpdb->prepare( "UPDATE $member_table_name SET mem_point = (mem_point - %d) WHERE ID = %d", $point, $mem_id );
4201 - $wpdb->query( $query );
4202 -}
4203 -//20120306ysk end
4204 -//20120413ysk start
4205 -function usces_set_free_csv( $customer ){
4206 - $free_csv = "";
4207 - if( !WCUtils::is_blank($customer['name1']) ) {
4208 - $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'];
4209 - $free_csv = base64_encode( $free_csv );
4210 - }
4211 - return $free_csv;
4212 -}
4213 -//20120413ysk end
4214 -
4215 -function usces_get_itemopt_filed($post_id, $sku, $opt){
4216 - global $usces;
4217 - $sku = urlencode($sku);
4218 - $optcode = urlencode($opt['name']);
4219 - $name = $opt['name'];
4220 - $means = (int)$opt['means'];
4221 - $essential = (int)$opt['essential'];
4222 - $session_value = isset( $_SESSION['usces_singleitem']['itemOption'][$post_id][$sku][$optcode] ) ? $_SESSION['usces_singleitem']['itemOption'][$post_id][$sku][$optcode] : NULL;
4223 -
4224 - $html = '';
4225 - switch($means) {
4226 - case 0://Single-select
4227 - case 1://Multi-select
4228 - $selects = explode("\n", $opt['value']);
4229 - $multiple = ($means === 0) ? '' : ' multiple';
4230 - $multiple_array = ($means == 0) ? '' : '[]';
4231 - $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";
4232 - if($essential == 1){
4233 - if( '#NONE#' == $session_value || NULL == $session_value )
4234 - $selected = ' selected="selected"';
4235 - else
4236 - $selected = '';
4237 - $html .= "\t<option value='#NONE#'{$selected}>" . __('Choose','usces') . "</option>\n";
4238 - }
4239 - $i=0;
4240 - foreach($selects as $v) {
4241 - if( ($i == 0 && $essential == 0 && NULL == $session_value) || esc_attr($v) == $session_value )
4242 - $selected = ' selected="selected"';
4243 - else
4244 - $selected = '';
4245 - $html .= "\t<option value='" . esc_attr($v) . "'{$selected}>" . esc_html($v) . "</option>\n";
4246 - $i++;
4247 - }
4248 - $html .= "</select>\n";
4249 - break;
4250 - case 2://Text
4251 - $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";
4252 - break;
4253 - case 5://Text-area
4254 - $html .= "\n<textarea name='itemOption[{$post_id}][{$sku}][{$optcode}]' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_textarea'>" . esc_attr($session_value) . "</textarea>\n";
4255 - break;
4256 - }
4257 -
4258 - $html = apply_filters('usces_get_itemopt_filed', $html, $post_id, $sku, $opt);
4259 -
4260 - return $html;
4261 -}
4262 -
4263 -function usces_delete_order_check( $order_id ) {
4264 - $res = apply_filters( 'usces_filter_delete_order_check', true, $order_id );
4265 - return $res;
4266 -}
4267 -
4268 -function usces_itempage_admin_bar() {
4269 - global $wp_admin_bar, $post;
4270 - if( is_single() && usces_is_item() ){
4271 - $wp_admin_bar->remove_menu('edit');
4272 - $ref = urlencode(site_url() . '/wp-admin/admin.php?page=usces_itemedit');
4273 - $wp_admin_bar->add_menu( array(
4274 - 'id' => 'edit',
4275 - 'title' => __('Edit item', 'usces'),
4276 - 'href' => site_url() . '/wp-admin/admin.php?page=usces_itemedit&action=edit&post=' . $post->ID . '&usces_referer=' . $ref
4277 - ) );
4278 - }
4279 -}
4280 -
4281 -?>
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 +}