PluginProbe
Welcart e-Commerce / 1.3.16
Welcart e-Commerce v1.3.16
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.16, at functions/function.php

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