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