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

function.php in Welcart e-Commerce 1.3.9, at functions/function.php

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