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