PluginProbe
Welcart e-Commerce / 1.3.17
Welcart e-Commerce v1.3.17
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.17, at functions/function.php

4,443 lines 168.7 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 $name3 = ( isset( $_POST['member']['name3'] ) ) ? $_POST['member']['name3'] : '';
1382 $name4 = ( isset( $_POST['member']['name4'] ) ) ? $_POST['member']['name4'] : '';
1383
1384 //$wpdb->show_errors();
1385 $query = $wpdb->prepare(
1386 "UPDATE $member_table_name SET
1387 `mem_email`=%s, `mem_status`=%s, `mem_point`=%d, `mem_name1`=%s, `mem_name2`=%s,
1388 `mem_name3`=%s, `mem_name4`=%s, `mem_zip`=%s, `mem_pref`=%s, `mem_address1`=%s,
1389 `mem_address2`=%s, `mem_address3`=%s, `mem_tel`=%s, `mem_fax`=%s
1390 WHERE ID = %d",
1391 $_POST['member']['email'],
1392 $_POST['member']['status'],
1393 $_POST['member']['point'],
1394 $_POST['member']['name1'],
1395 $_POST['member']['name2'],
1396 $name3,
1397 $name4,
1398 $_POST['member']['zipcode'],
1399 $_POST['member']['pref'],
1400 $_POST['member']['address1'],
1401 $_POST['member']['address2'],
1402 $_POST['member']['address3'],
1403 $_POST['member']['tel'],
1404 $_POST['member']['fax'],
1405 $ID
1406 );
1407
1408 do_action('usces_action_pre_update_memberdata', $ID);
1409 //20100818ysk start
1410 //$res = $wpdb->query( $query );
1411 $res[0] = $wpdb->query( $query );
1412
1413 do_action( 'usces_action_post_update_memberdata', $ID, $res[0]);
1414
1415 if(false === $res[0])
1416 return false;
1417
1418 $usces->set_member_meta_value('customer_country', $_POST['member']['country'], $ID);
1419 //20130524ysk start 0000712
1420 $csmb_meta = usces_has_custom_field_meta( 'member' );
1421 if( is_array($csmb_meta) ) {
1422 foreach( $csmb_meta as $key => $entry ) {
1423 if( '4' == $entry['means'] ) {
1424 $usces->del_member_meta( 'csmb_'.$key, $ID );
1425 }
1426 }
1427 }
1428 //20130524ysk end
1429 $i = 1;
1430 if( !empty($_POST['custom_member']) ) {
1431 foreach( $_POST['custom_member'] as $key => $value ) {
1432 $csmb_key = 'csmb_'.$key;
1433 if( is_array($value) )
1434 $value = serialize($value);
1435 $res[$i] = $usces->set_member_meta_value($csmb_key, $value, $ID);
1436 if(false === $res[$i])
1437 return false;
1438 $i++;
1439 }
1440 }
1441
1442
1443 $meta_keys = apply_filters( 'usces_filter_delete_member_pcid', "'zeus_pcid', 'remise_pcid', 'digitalcheck_ip_user_id'" );
1444 $query = $wpdb->prepare("DELETE FROM $member_table_meta_name WHERE member_id = %d AND meta_key IN( $meta_keys )",
1445 $_POST['member_id']
1446 );
1447 $res[$i] = $wpdb->query( $query );
1448
1449 $result = ( 0 < array_sum($res) ) ? 1 : 0;
1450 //return $res;
1451 return $result;
1452 //20100818ysk end
1453 }
1454
1455 function usces_delete_orderdata() {
1456 global $wpdb, $usces;
1457 if(!isset($_REQUEST['order_id']) || WCUtils::is_blank($_REQUEST['order_id']) ) return 0;
1458 $order_table = $wpdb->prefix . "usces_order";
1459 $order_meta_table = $wpdb->prefix . "usces_order_meta";
1460 $ID = $_REQUEST['order_id'];
1461
1462 $del = usces_delete_order_check( $ID );
1463 if( $del ) {
1464
1465 $query = $wpdb->prepare("SELECT * FROM $order_table WHERE ID = %d", $ID);
1466 $order_data = $wpdb->get_row( $query, OBJECT );
1467 //20130625ysk start 0000721
1468 //20120306ysk start 0000324
1469 //$order_res = $wpdb->get_row( $query, ARRAY_A );
1470 //$restore_point = false;
1471 $point = 0;
1472 if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] && !empty($order_data->mem_id) && !$usces->is_status('cancel', $order_data->order_status) ) {
1473 if( 0 < $order_data->order_getpoint ) {
1474 //if( $usces->is_status('completion', $order_data->order_status) ) {
1475 // //$restore_point = true;
1476 // $point += $order_data->order_getpoint;
1477 //} else {
1478 if( usces_is_complete_settlement( $order_data->order_payment_name, $order_data->order_status ) || $usces->is_status('receipted', $order_data->order_status) ) {
1479 //$restore_point = true;
1480 $point += $order_data->order_getpoint;
1481 }
1482 //}
1483 }
1484 if( 0 < $order_data->order_usedpoint ) {
1485 $point -= $order_data->order_usedpoint;
1486 }
1487 }
1488 //20120306ysk end
1489
1490 $query = $wpdb->prepare("DELETE FROM $order_table WHERE ID = %d", $ID);
1491 $res = $wpdb->query( $query );
1492
1493 $args = compact( 'ID', 'point', 'res' );
1494
1495 if($res){
1496
1497 do_action('usces_action_del_orderdata', $order_data, $args);
1498
1499 $query = $wpdb->prepare("DELETE FROM $order_meta_table WHERE order_id = %d", $ID);
1500 $wpdb->query( $query );
1501
1502 //20120306ysk start 0000324
1503 //if( $restore_point ) usces_restore_point( $order_res['mem_id'], $order_res['order_getpoint'] );
1504 if( 0 != $point ) usces_restore_point( $order_data->mem_id, $point );
1505 //20120306ysk end
1506 //20130625ysk end
1507 }
1508
1509 } else {
1510 $res = true;
1511 }
1512
1513 return $res;
1514 }
1515
1516 function usces_update_ordercart() {
1517 global $wpdb, $usces;
1518 if(!isset($_REQUEST['order_id']) || WCUtils::is_blank($_REQUEST['order_id']) ) return 0;
1519 $order_table_name = $wpdb->prefix . "usces_order";
1520 $ID = $_REQUEST['order_id'];
1521 $usces->cart->crear_cart();
1522 $usces->cart->upCart();
1523 $cart = $usces->cart->get_cart();
1524 //20120613ysk start 0000500
1525 $idx = count($cart)-1;
1526 $post_id = $cart[$idx]['post_id'];
1527 $sku = $cart[$idx]['sku'];
1528 $sku_code = esc_attr(urldecode($sku));
1529 $cartItemName = $usces->getCartItemName($post_id, $sku_code);
1530 $skuPrice = $cart[$idx]['price'];
1531 //20120613ysk end
1532
1533 $query = $wpdb->prepare("UPDATE $order_table_name SET `order_cart`=%s WHERE ID = %d", serialize($cart), $ID);
1534 $res = $wpdb->query( $query );
1535
1536 $usces->cart->crear_cart();
1537 //20120613ysk start 0000500
1538 if( $res === false ) {
1539 $res = "-1#usces#";
1540 } else {
1541 $res = $skuPrice."#usces#".$cartItemName;
1542 }
1543 //20120613ysk end
1544 return $res;
1545 }
1546
1547 function usces_update_ordercheck() {
1548 global $wpdb, $usces;
1549
1550 $tableName = $wpdb->prefix . "usces_order";
1551 $order_id = $_POST['order_id'];
1552 $checked = $_POST['checked'];
1553
1554 $query = $wpdb->prepare("SELECT `order_check` FROM $tableName WHERE ID = %d", $order_id);
1555 $res = $wpdb->get_var( $query );
1556
1557 $checkfield = unserialize($res);
1558 if( !isset($checkfield[$checked]) ) $checkfield[$checked] = $checked;
1559 //$checkfield = 'OK';
1560 $query = $wpdb->prepare("UPDATE $tableName SET `order_check`=%s WHERE ID = %d", serialize($checkfield), $order_id);
1561 $res = $wpdb->query( $query );
1562
1563 if($res)
1564 return $checked;
1565 else
1566 return 'error';
1567 }
1568 function usces_update_orderdata() {
1569 global $wpdb, $usces;
1570 $_POST = $usces->stripslashes_deep_post($_POST);
1571
1572 $order_table_name = $wpdb->prefix . "usces_order";
1573 $order_table_meta_name = $wpdb->prefix . "usces_order_meta";
1574 $member_table_name = $wpdb->prefix . "usces_member";
1575
1576 $ID = $_REQUEST['order_id'];
1577
1578 $query = $wpdb->prepare("SELECT * FROM $order_table_name WHERE ID = %d", $ID);
1579 $old_orderdata = $wpdb->get_row( $query );
1580 $old_status = $old_orderdata->order_status;
1581
1582 $usces->cart->crear_cart();
1583 $usces->cart->upCart();
1584 if(isset($_POST['delButton'])) {
1585 $usces->cart->del_row();
1586 $indexs = array_keys($_POST['delButton']);
1587 $index = $indexs[0];
1588 do_action('usces_admin_delete_orderrow', $ID, $index );
1589 }
1590 $cart = $usces->cart->get_cart();
1591 $usces->cart->entry();
1592 $entry = $usces->cart->get_entry();
1593
1594 $item_total_price = $usces->get_total_price( $cart );
1595 //$set = $usces->getPayments( $entry['order']['payment_name'] );
1596 $taio = isset($entry['order']['taio']) ? $entry['order']['taio'] : '';
1597 $receipt = isset($entry['order']['receipt']) ? $entry['order']['receipt'] : '';
1598 $admin = isset($entry['order']['admin']) ? $entry['order']['admin'] : '';
1599 $status = $usces->make_status( $taio, $receipt, $admin );
1600 if( $taio == 'completion' || $taio == 'continuation' ){
1601 if( 'update' == $_POST['up_modified'] ){
1602 $order_modified = substr(get_date_from_gmt(gmdate('Y-m-d H:i:s', time())), 0, 10);
1603 }else{
1604 $order_modified = $_POST['modified'];
1605 }
1606 }else{
1607 $order_modified = '';
1608 }
1609 $ordercheck = isset($_POST['check']) ? serialize($_POST['check']) : '';
1610 $member_id = isset($_POST['member_id']) ? $_POST['member_id'] : 0;
1611 //$member_id = $usces->get_memberid_by_email($_POST['customer']['mailaddress']);
1612
1613 if( 'cancel' == $taio ){
1614 $query = $wpdb->prepare(
1615 "UPDATE $order_table_name SET `order_modified`=%s, `order_status`=%s WHERE ID = %d",
1616 $order_modified, $status, $ID
1617 );
1618 $res[0] = $wpdb->query( $query );
1619
1620 $query = $wpdb->prepare("SELECT * FROM $order_table_name WHERE ID = %d", $ID);
1621 $new_orderdata = $wpdb->get_row( $query );
1622
1623 //20131101ysk start 0000751
1624 if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] && !empty($member_id) && !$usces->is_status('cancel', $old_status) ) {
1625 $point = 0;
1626 if( 0 < $old_orderdata->order_getpoint ) {
1627 if( usces_is_complete_settlement( $old_orderdata->order_payment_name, $old_orderdata->order_status ) || $usces->is_status('receipted', $old_orderdata->order_status) ) {
1628 $point += $old_orderdata->order_getpoint;
1629 }
1630 }
1631 if( 0 < $old_orderdata->order_usedpoint ) {
1632 $point -= $old_orderdata->order_usedpoint;
1633 }
1634 if( 0 != $point ) usces_restore_point( $member_id, $point );
1635 }
1636 //20131101ysk end
1637
1638 do_action('usces_action_update_orderdata', $new_orderdata, $old_status, $old_orderdata);
1639 $usces->cart->crear_cart();
1640
1641 return 1;
1642 }
1643
1644 //$wpdb->show_errors();
1645 //20101208ysk start
1646 $query = $wpdb->prepare(
1647 "UPDATE $order_table_name SET
1648 `mem_id`=%d, `order_email`=%s, `order_name1`=%s, `order_name2`=%s, `order_name3`=%s, `order_name4`=%s,
1649 `order_zip`=%s, `order_pref`=%s, `order_address1`=%s, `order_address2`=%s, `order_address3`=%s,
1650 `order_tel`=%s, `order_fax`=%s, `order_delivery`=%s, `order_cart`=%s, `order_note`=%s,
1651 `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,
1652 `order_discount`=%f, `order_shipping_charge`=%f, `order_cod_fee`=%f, `order_tax`=%f, `order_modified`=%s,
1653 `order_status`=%s, `order_delidue_date`=%s, `order_check`=%s
1654 WHERE ID = %d",
1655 $member_id,
1656 $_POST['customer']['mailaddress'],
1657 $_POST['customer']['name1'],
1658 $_POST['customer']['name2'],
1659 $_POST['customer']['name3'],
1660 $_POST['customer']['name4'],
1661 $_POST['customer']['zipcode'],
1662 $_POST['customer']['pref'],
1663 $_POST['customer']['address1'],
1664 $_POST['customer']['address2'],
1665 $_POST['customer']['address3'],
1666 $_POST['customer']['tel'],
1667 $_POST['customer']['fax'],
1668 serialize($_POST['delivery']),
1669 serialize($cart),
1670 $_POST['offer']['note'],
1671 $_POST['offer']['delivery_method'],
1672 $_POST['offer']['delivery_date'],
1673 $_POST['offer']['delivery_time'],
1674 $_POST['offer']['payment_name'],
1675 $item_total_price,
1676 $_POST['offer']['getpoint'],
1677 $_POST['offer']['usedpoint'],
1678 $_POST['offer']['discount'],
1679 $_POST['offer']['shipping_charge'],
1680 $_POST['offer']['cod_fee'],
1681 $_POST['offer']['tax'],
1682 $order_modified,
1683 $status,
1684 $_POST['offer']['delidue_date'],
1685 $ordercheck,
1686 $ID
1687 );
1688 //20101208ysk end
1689
1690 //20100818ysk start
1691 //$res = $wpdb->query( $query );
1692 $res[0] = $wpdb->query( $query );
1693 if(false === $res[0])
1694 return false;
1695
1696 $usces->set_order_meta_value('customer_country', $_POST['customer']['country'], $ID);
1697 //20130524ysk start 0000712
1698 $csod_meta = usces_has_custom_field_meta( 'order' );
1699 if( is_array($csod_meta) ) {
1700 foreach( $csod_meta as $key => $entry ) {
1701 if( '4' == $entry['means'] ) {
1702 $usces->del_order_meta( 'csod_'.$key, $ID );
1703 }
1704 }
1705 }
1706 $cscs_meta = usces_has_custom_field_meta( 'customer' );
1707 if( is_array($cscs_meta) ) {
1708 foreach( $cscs_meta as $key => $entry ) {
1709 if( '4' == $entry['means'] ) {
1710 $usces->del_order_meta( 'cscs_'.$key, $ID );
1711 }
1712 }
1713 }
1714 $csde_meta = usces_has_custom_field_meta( 'delivery' );
1715 if( is_array($csde_meta) ) {
1716 foreach( $csde_meta as $key => $entry ) {
1717 if( '4' == $entry['means'] ) {
1718 $usces->del_order_meta( 'csde_'.$key, $ID );
1719 }
1720 }
1721 }
1722 //20130524ysk end
1723 $i = 1;
1724 if( !empty($_POST['custom_order']) ) {
1725 foreach( $_POST['custom_order'] as $key => $value ) {
1726 $csod_key = 'csod_'.$key;
1727 if( is_array($value) )
1728 $value = serialize($value);
1729 $res[$i] = $usces->set_order_meta_value($csod_key, $value, $ID);
1730 if(false === $res[$i])
1731 return false;
1732 $i++;
1733 }
1734 }
1735 if( !empty($_POST['custom_customer']) ) {
1736 foreach( $_POST['custom_customer'] as $key => $value ) {
1737 $cscs_key = 'cscs_'.$key;
1738 if( is_array($value) )
1739 $value = serialize($value);
1740 $res[$i] = $usces->set_order_meta_value($cscs_key, $value, $ID);
1741 if(false === $res[$i])
1742 return false;
1743 $i++;
1744 }
1745 }
1746 if( !empty($_POST['custom_delivery']) ) {
1747 foreach( $_POST['custom_delivery'] as $key => $value ) {
1748 $csde_key = 'csde_'.$key;
1749 if( is_array($value) )
1750 $value = serialize($value);
1751 $res[$i] = $usces->set_order_meta_value($csde_key, $value, $ID);
1752 if(false === $res[$i])
1753 return false;
1754 $i++;
1755 }
1756 }
1757 $value = get_date_from_gmt(gmdate('Y-m-d H:i:s', time()));
1758 if ( !preg_match('/pending|noreceipt/', $old_status) && preg_match('/pending|noreceipt/', $status) ) {
1759 $rquery = $wpdb->prepare("DELETE FROM $order_table_meta_name WHERE order_id = %d AND meta_key = %s", $ID, 'receipted_date');
1760 $wpdb->query( $rquery );
1761 }else if ( !preg_match('/pending|noreceipt/', $old_status) && !preg_match('/pending|noreceipt/', $status) ) {
1762 $query = $wpdb->prepare("SELECT order_id FROM $order_table_meta_name WHERE order_id = %d AND meta_key = %s", $ID, 'receipted_date');
1763 $varres = $wpdb->get_var( $query );
1764 if( empty($varres) ){
1765 $usces->set_order_meta_value('receipted_date', $value, $ID);
1766 }
1767 }else if ( preg_match('/pending|noreceipt/', $old_status) && !preg_match('/pending|noreceipt/', $status) ) {
1768 $usces->set_order_meta_value('receipted_date', $value, $ID);
1769 }
1770
1771 //20131101ysk start 0000751
1772 //if( !usces_is_complete_settlement( $_POST['offer']['payment_name'] ) ) {
1773 // if( !preg_match('/pending|noreceipt/', $old_status) && preg_match('/pending|noreceipt/', $status) ) {//�
1774 �金→未�
1775 �金
1776 // usces_action_acting_getpoint( $ID, false );//ポイント取消
1777 // } else if( preg_match('/pending|noreceipt/', $old_status) && !preg_match('/pending|noreceipt/', $status) ) {//未�
1778 �金→�
1779 �金
1780 // usces_action_acting_getpoint( $ID );//ポイント追加
1781 // }
1782 //}
1783 if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] && !empty($member_id) ) {
1784 $point = 0;
1785 $getpoint = $_POST['offer']['getpoint'];
1786 $usedpoint = $_POST['offer']['usedpoint'];
1787 if( $usces->is_status('cancel', $old_status) && !$usces->is_status('cancel', $status) ) {//キャンセル→新規受付・取り寄せ中・発送済み
1788 if( 0 < $getpoint ) {
1789 if( usces_is_complete_settlement( $_POST['offer']['payment_name'], $status ) || $usces->is_status('receipted', $status) ) {
1790 $point -= $getpoint;
1791 }
1792 }
1793 if( 0 < $usedpoint ) {
1794 $point += $usedpoint;
1795 }
1796 } else {
1797 if( !usces_is_complete_settlement( $_POST['offer']['payment_name'] ) ) {
1798 if( !preg_match('/pending|noreceipt/', $old_status) && preg_match('/pending|noreceipt/', $status) ) {//�
1799 �金→未�
1800 �金
1801 $point += $getpoint;//ポイント取消
1802 } else if( preg_match('/pending|noreceipt/', $old_status) && !preg_match('/pending|noreceipt/', $status) ) {//未�
1803 �金→�
1804 �金
1805 $point -= $getpoint;//ポイント追加
1806 } else {
1807 if( $old_orderdata->order_getpoint != $getpoint ) {
1808 $point += $old_orderdata->order_getpoint - $getpoint;
1809 }
1810 }
1811 } else {
1812 if( $old_orderdata->order_getpoint != $getpoint ) {
1813 $point += $old_orderdata->order_getpoint - $getpoint;
1814 }
1815 }
1816 if( $old_orderdata->order_usedpoint != $usedpoint ) {
1817 $point -= $old_orderdata->order_usedpoint - $usedpoint;
1818 }
1819 }
1820 if( 0 != $point ) usces_restore_point( $member_id, $point );
1821 }
1822 //20131101ysk end
1823
1824 $result = ( 0 < array_sum($res) ) ? 1 : 0;
1825 //20100818ysk end
1826
1827 $query = $wpdb->prepare("SELECT * FROM $order_table_name WHERE ID = %d", $ID);
1828 $new_orderdata = $wpdb->get_row( $query );
1829 //20120612ysk start 0000501
1830 //do_action('usces_action_update_orderdata', $new_orderdata);
1831 do_action('usces_action_update_orderdata', $new_orderdata, $old_status, $old_orderdata);
1832 //20120612ysk end
1833 $usces->cart->crear_cart();
1834
1835 return $result;
1836
1837 // else :
1838 //
1839 // if ( $member['ID'] ) {
1840 //
1841 // $mquery = $wpdb->prepare(
1842 // "UPDATE $member_table_name SET mem_point = (mem_point + %d - %d) WHERE ID = %d",
1843 // $entry['order']['getpoint'], $entry['order']['usedpoint'], $member['ID']);
1844 //
1845 // $wpdb->query( $mquery );
1846 // $mquery = $wpdb->prepare("SELECT mem_point FROM $member_table_name WHERE ID = %d", $member['ID']);
1847 // $point = $wpdb->get_var( $mquery );
1848 // $_SESSION['usces_member']['point'] = $point;
1849 // }
1850 //
1851 // if ( !empty($entry['reserve']) ) {
1852 // foreach ( $entry['reserve'] as $key => $value ) {
1853 // if ( is_array($value) )
1854 // $value = serialize($value);
1855 // $mquery = $wpdb->prepare("INSERT INTO $order_table_meta_name ( order_id, meta_key, meta_value )
1856 // VALUES (%d, %s, %s, %s)", $order_id, $key, $value);
1857 // $wpdb->query( $mquery );
1858 // }
1859 // }
1860 //
1861 // endif;
1862 //
1863 // //zaiko
1864 // foreach($cart as $cartrow){
1865 // $zaikonum = $usces->getItemZaikoNum( $cartrow['post_id'], $cartrow['sku'] );
1866 // if($zaikonum == '') continue;
1867 // $zaikonum = $zaikonum - $cartrow['quantity'];
1868 // $usces->updateItemZaikoNum( $cartrow['post_id'], $cartrow['sku'], $zaikonum );
1869 // if($zaikonum <= 0) $usces->updateItemZaiko( $cartrow['post_id'], $cartrow['sku'], 2 );
1870 // }
1871 //
1872 // return $order_id;
1873
1874 }
1875
1876
1877
1878 function usces_export_xml() {
1879 $options = get_option('usces');
1880 echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '"?' . ">\n";
1881 ?>
1882 <usces><?php echo serialize($options); ?></usces>
1883 <usces_management_status><?php echo serialize(get_option('usces_management_status')); ?></usces_management_status>
1884 <usces_zaiko_status><?php echo serialize(get_option('usces_zaiko_status')); ?></usces_zaiko_status>
1885 <usces_customer_status><?php echo serialize(get_option('usces_customer_status')); ?></usces_customer_status>
1886 <usces_payment_structure><?php echo serialize(get_option('usces_payment_structure')); ?></usces_payment_structure>
1887 <usces_display_mode><?php echo serialize(get_option('usces_display_mode')); ?></usces_display_mode>
1888 <!--20110331ysk start-->
1889 <!-- <usces_pref><?php //echo serialize(get_option('usces_pref')); ?></usces_pref>-->
1890 <!--20110331ysk end-->
1891 <usces_shipping_rule><?php echo serialize(get_option('usces_shipping_rule')); ?></usces_shipping_rule>
1892
1893 <?php
1894 }
1895
1896 function usces_all_change_zaiko(&$obj) {
1897 global $wpdb, $usces;
1898
1899 $ids = $_POST['listcheck'];
1900 $status = true;
1901 foreach ( (array)$ids as $post_id ){
1902 $skus = $usces->get_skus($post_id);
1903 foreach ( (array)$skus as $sku ){
1904 $res = usces_update_sku( $post_id, $sku['code'], 'stock', (int)$_POST['change']['word']['zaiko'] );
1905 if( !$res ){
1906 $status = false;
1907 }
1908 }
1909 }
1910 if ( true === $status ) {
1911 $obj->set_action_status('success', __('I completed collective operation.','usces'));
1912 } elseif ( false === $status ) {
1913 $obj->set_action_status('error', __('ERROR: I was not able to complete collective operation','usces'));
1914 } else {
1915 $obj->set_action_status('none', '');
1916 }
1917 }
1918
1919 function usces_all_change_itemdisplay(&$obj){
1920 global $wpdb;
1921
1922 $ids = $_POST['listcheck'];
1923 $post_status = $_POST['change']['word']['display_status'];
1924 $status = true;
1925 foreach ( (array)$ids as $post_id ):
1926 // $query = $wpdb->prepare("UPDATE $wpdb->posts SET post_status = %s WHERE ID = %d", $post_status, $post_id);
1927 // $res = $wpdb->query( $query );
1928 $post_data = array('ID'=>$post_id, 'post_status'=>$post_status);
1929 $res = wp_update_post( $post_data );
1930
1931 if( $res == 0 ) {
1932 $status = false;
1933 }
1934 endforeach;
1935 if ( true === $status ) {
1936 $obj->set_action_status('success', __('I completed collective operation.','usces'));
1937 } elseif ( false === $status ) {
1938 $obj->set_action_status('error', __('ERROR: I was not able to complete collective operation','usces'));
1939 } else {
1940 $obj->set_action_status('none', '');
1941 }
1942 }
1943
1944 function usces_all_change_order_reciept(&$obj){
1945 global $wpdb, $usces;
1946
1947 $tableName = $wpdb->prefix . "usces_order";
1948 $ids = $_POST['listcheck'];
1949 $status = true;
1950 foreach ( (array)$ids as $id ):
1951 //20120306ysk start 0000324
1952 //$query = $wpdb->prepare("SELECT order_status FROM $tableName WHERE ID = %d", $id);
1953 //$statusstr = $wpdb->get_var( $query );
1954 $query = $wpdb->prepare("SELECT order_status, mem_id, order_getpoint FROM $tableName WHERE ID = %d", $id);
1955 $order_res = $wpdb->get_row( $query, ARRAY_A );
1956 $statusstr = $order_res['order_status'];
1957 $restore_point = false;
1958 $getpoint = $order_res['order_getpoint'];
1959 if( strpos($statusstr, 'cancel') !== false ) continue;//20131101ysk 0000751
1960 //20120306ysk end
1961 if(strpos($statusstr, 'noreceipt') === false && strpos($statusstr, 'receipted') === false) continue;
1962 $old_status = $statusstr;//20120612ysk 0000501
1963 if($_REQUEST['change']['word']['order_reciept'] == 'receipted') {
1964 //20120306ysk start 0000324
1965 //if(strpos($statusstr, 'noreceipt') !== false)
1966 if(strpos($statusstr, 'noreceipt') !== false) {
1967 $statusstr = str_replace('noreceipt', 'receipted', $statusstr);
1968 //if( !$usces->is_status('completion', $order_res['order_status']) ) {
1969 $restore_point = true;
1970 $getpoint = $getpoint * -1;//add point
1971 //}
1972 }
1973 //20120306ysk end
1974 }elseif($_REQUEST['change']['word']['order_reciept'] == 'noreceipt') {
1975 //20120306ysk start 0000324
1976 //if(strpos($statusstr, 'receipted') !== false)
1977 if(strpos($statusstr, 'receipted') !== false) {
1978 $statusstr = str_replace('receipted', 'noreceipt', $statusstr);
1979 //if( !$usces->is_status('completion', $order_res['order_status']) )
1980 $restore_point = true;
1981 }
1982 //20120306ysk end
1983 }
1984 $query = $wpdb->prepare("UPDATE $tableName SET order_status = %s WHERE ID = %d", $statusstr, $id);
1985 $res = $wpdb->query( $query );
1986 if( $res === false ) {
1987 $status = false;
1988 }
1989 //20120306ysk start 0000324
1990 if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] ) {
1991 if( !empty($order_res['mem_id']) && 0 < $order_res['order_getpoint'] ) {
1992 if( $res && $restore_point ) usces_restore_point( $order_res['mem_id'], $getpoint );
1993 }
1994 }
1995 //20120306ysk end
1996 if( $status ) {
1997 do_action( 'usces_action_collective_order_reciept_each', $id, $statusstr, $old_status );
1998 }
1999 endforeach;
2000 if ( true === $status ) {
2001 $obj->set_action_status('success', __('I completed collective operation.','usces'));
2002 } elseif ( false === $status ) {
2003 $obj->set_action_status('error', __('ERROR: I was not able to complete collective operation','usces'));
2004 } else {
2005 $obj->set_action_status('none', '');
2006 }
2007 do_action('usces_action_collective_order_reciept', array(&$obj));
2008 }
2009
2010 function usces_all_change_order_status(&$obj){
2011 global $wpdb, $usces;
2012
2013 $tableName = $wpdb->prefix . "usces_order";
2014 $ids = $_POST['listcheck'];
2015 foreach ( (array)$ids as $id ):
2016 $status = true;
2017 //20120306ysk start 0000324
2018 //$query = $wpdb->prepare("SELECT order_status FROM $tableName WHERE ID = %d", $id);
2019 //$statusstr = $wpdb->get_var( $query );
2020 $query = $wpdb->prepare("SELECT order_status, mem_id, order_getpoint, order_usedpoint, order_payment_name FROM $tableName WHERE ID = %d", $id);
2021 $order_res = $wpdb->get_row( $query, ARRAY_A );
2022 $statusstr = $order_res['order_status'];
2023 $restore_point = false;
2024 $getpoint = $order_res['order_getpoint'];
2025 $usedpoint = $order_res['order_usedpoint'];
2026 //20120306ysk end
2027 $old_status = $statusstr;//20120612ysk 0000501
2028 switch ($_REQUEST['change']['word']['order_status']) {
2029 case 'estimate':
2030 if(strpos($statusstr, 'adminorder') !== false) {
2031 $statusstr = str_replace('adminorder', 'estimate', $statusstr);
2032 }else if(strpos($statusstr, 'estimate') === false) {
2033 $statusstr .= 'estimate,';
2034 }
2035 break;
2036 case 'adminorder':
2037 if(strpos($statusstr, 'estimate') !== false) {
2038 $statusstr = str_replace('estimate', 'adminorder', $statusstr);
2039 }else if(strpos($statusstr, 'adminorder') === false) {
2040 $statusstr .= 'adminorder,';
2041 }
2042 break;
2043 case 'duringorder':
2044 if(strpos($statusstr, 'cancel') !== false) {
2045 $statusstr = str_replace('cancel', 'duringorder', $statusstr);
2046 //20120919ysk start 0000573
2047 if( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
2048 $restore_point = true;
2049 $getpoint = $getpoint * -1;//add point
2050 } elseif( $usces->is_status('receipted', $order_res['order_status']) ) {
2051 $restore_point = true;
2052 $getpoint = $getpoint * -1;//add point
2053 }
2054 //20120919ysk end
2055 }else if(strpos($statusstr, 'completion') !== false) {
2056 $statusstr = str_replace('completion', 'duringorder', $statusstr);
2057 //20120306ysk start 0000324
2058 //if( !usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) && !$usces->is_status('receipted', $order_res['order_status']) )
2059 // $restore_point = true;
2060 //20120306ysk end
2061 }else if(strpos($statusstr, 'new') !== false) {
2062 $statusstr = str_replace('new', 'duringorder', $statusstr);
2063 }else if(strpos($statusstr, 'duringorder') === false) {
2064 $statusstr .= 'duringorder,';
2065 }
2066 break;
2067 case 'cancel':
2068 if(strpos($statusstr, 'completion') !== false) {
2069 $statusstr = str_replace('completion', 'cancel', $statusstr);
2070 //20120306ysk start 0000324
2071 //if( !usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) && !$usces->is_status('receipted', $order_res['order_status']) )
2072 // $restore_point = true;
2073 //20120306ysk end
2074 }else if(strpos($statusstr, 'new') !== false) {
2075 $statusstr = str_replace('new', 'cancel', $statusstr);
2076 }else if(strpos($statusstr, 'duringorder') !== false) {
2077 $statusstr = str_replace('duringorder', 'cancel', $statusstr);
2078 }else if(strpos($statusstr, 'cancel') === false) {
2079 $statusstr .= 'cancel,';
2080 }
2081 //20120919ysk start 0000573
2082 if( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
2083 $restore_point = true;
2084 $usedpoint = $usedpoint * -1;//add point
2085 } elseif( $usces->is_status('receipted', $order_res['order_status']) ) {
2086 $restore_point = true;
2087 $usedpoint = $usedpoint * -1;//add point
2088 }
2089 //20120919ysk end
2090 break;
2091 case 'completion':
2092 if(strpos($statusstr, 'new') !== false) {
2093 $statusstr = str_replace('new', 'completion', $statusstr);
2094 }else if(strpos($statusstr, 'duringorder') !== false) {
2095 $statusstr = str_replace('duringorder', 'completion', $statusstr);
2096 }else if(strpos($statusstr, 'cancel') !== false) {
2097 $statusstr = str_replace('cancel', 'completion', $statusstr);
2098 //20120919ysk start 0000573
2099 if( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
2100 $restore_point = true;
2101 $getpoint = $getpoint * -1;//add point
2102 } elseif( $usces->is_status('receipted', $order_res['order_status']) ) {
2103 $restore_point = true;
2104 $getpoint = $getpoint * -1;//add point
2105 }
2106 //20120919ysk end
2107 }else if(strpos($statusstr, 'completion') === false) {
2108 $statusstr .= 'completion,';
2109 }
2110 //20120306ysk start 0000324
2111 //if( !usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) && !$usces->is_status('receipted', $order_res['order_status']) ) {
2112 // $restore_point = true;
2113 // $getpoint = $getpoint * -1;//add point
2114 //}
2115 //20120306ysk end
2116 break;
2117 case 'new':
2118 if(strpos($statusstr, 'duringorder') !== false) {
2119 $statusstr = str_replace('duringorder,', '', $statusstr);
2120 }else if(strpos($statusstr, 'completion') !== false) {
2121 $statusstr = str_replace('completion,', '', $statusstr);
2122 //20120306ysk start 0000324
2123 //if( !usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) && !$usces->is_status('receipted', $order_res['order_status']) )
2124 // $restore_point = true;
2125 //20120306ysk end
2126 }else if(strpos($statusstr, 'cancel') !== false) {
2127 $statusstr = str_replace('cancel,', '', $statusstr);
2128 //20120919ysk start 0000573
2129 if( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) ) {
2130 $restore_point = true;
2131 $getpoint = $getpoint * -1;//add point
2132 } elseif( $usces->is_status('receipted', $order_res['order_status']) ) {
2133 $restore_point = true;
2134 $getpoint = $getpoint * -1;//add point
2135 }
2136 //20120919ysk end
2137 }
2138 break;
2139 }
2140 $query = $wpdb->prepare("UPDATE $tableName SET order_status = %s WHERE ID = %d", $statusstr, $id);
2141 $res = $wpdb->query( $query );
2142 if( $res === false ) {
2143 $status = false;
2144 }
2145 //20120306ysk start 0000324
2146 if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] ) {
2147 if( !empty($order_res['mem_id']) && ( 0 < $order_res['order_getpoint'] || 0 < $order_res['order_usedpoint'] ) ) {
2148 if( $res && $restore_point ) usces_restore_point( $order_res['mem_id'], $getpoint + $usedpoint );
2149 }
2150 }
2151 //20120306ysk end
2152 //20120612ysk 0000501 start
2153 if( $status ) {
2154 do_action('usces_action_collective_order_status_each', $id, $statusstr, $old_status);
2155 }
2156 //20120612ysk end
2157 endforeach;
2158 if ( true === $status ) {
2159 $obj->set_action_status('success', __('I completed collective operation.','usces'));
2160 } elseif ( false === $status ) {
2161 $obj->set_action_status('error', __('ERROR: I was not able to complete collective operation','usces'));
2162 } else {
2163 $obj->set_action_status('none', '');
2164 }
2165 do_action('usces_action_collective_order_status', array(&$obj));
2166 }
2167
2168 function usces_all_delete_order_data(&$obj){
2169 global $wpdb, $usces;
2170
2171 $tableName = $wpdb->prefix . "usces_order";
2172 $tableMetaName = $wpdb->prefix . "usces_order_meta";
2173 $ids = $_POST['listcheck'];
2174 $status = true;
2175 foreach ( (array)$ids as $id ):
2176 $del = usces_delete_order_check( $id );
2177 if( $del === false ) continue;
2178 //20130625ysk start 0000721
2179 //20120306ysk start 0000324
2180 //$restore_point = false;
2181 $point = 0;
2182 $query = $wpdb->prepare("SELECT * FROM $tableName WHERE ID = %d", $id);
2183 $order_res = $wpdb->get_row( $query, ARRAY_A );
2184 if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] && !empty($order_res['mem_id']) && !$usces->is_status('cancel', $order_res['order_status']) ) {
2185 //$query = $wpdb->prepare("SELECT * FROM $tableName WHERE ID = %d", $id);
2186 //$order_res = $wpdb->get_row( $query, ARRAY_A );
2187 if( 0 < $order_res['order_getpoint'] ) {
2188 //if( $usces->is_status('completion', $order_res['order_status']) ) {
2189 // $restore_point = true;
2190 //} else {
2191 if( usces_is_complete_settlement( $order_res['order_payment_name'], $order_res['order_status'] ) || $usces->is_status('receipted', $order_res['order_status']) )
2192 //$restore_point = true;
2193 $point += $order_res['order_getpoint'];
2194 //}
2195 }
2196 if( 0 < $order_res['order_usedpoint'] ) {
2197 $point -= $order_res['order_usedpoint'];
2198 }
2199 }
2200 //20120306ysk end
2201 $query = $wpdb->prepare("DELETE FROM $tableName WHERE ID = %d", $id);
2202 $res = $wpdb->query( $query );
2203 if( $res === false ) {
2204 $status = false;
2205 }else{
2206
2207 if( 0 != $point ) usces_restore_point( $order_res['mem_id'], $point );
2208
2209 do_action('usces_action_collective_order_delete_each', $id, $order_res);
2210
2211 $metaquery = $wpdb->prepare("DELETE FROM $tableMetaName WHERE order_id = %d", $id);//0000427
2212 $metares = $wpdb->query( $metaquery );
2213 }
2214 endforeach;
2215 if ( true === $status ) {
2216 $obj->set_action_status('success', __('I completed collective operation.','usces'));
2217 } elseif ( false === $status ) {
2218 $obj->set_action_status('error', __('ERROR: I was not able to complete collective operation','usces'));
2219 } else {
2220 $obj->set_action_status('none', '');
2221 }
2222 do_action('usces_action_collective_order_delete', array(&$obj));
2223 }
2224
2225 function usces_check_acting_return() {
2226 global $usces;
2227 $entry = $usces->cart->get_entry();
2228
2229 $acting = $_GET['acting'];
2230 $results = array();
2231 switch ( $acting ) {
2232 case 'epsilon':
2233 if(isset($_GET['duplicate']) && $_GET['duplicate'] == 1){
2234 $results[0] = 'duplicate';
2235 }else if(isset($_GET['result'])){
2236 $results[0] = (int)$_GET['result'];
2237 $results['reg_order'] = true;
2238 }else{
2239 $str = explode('?', $_GET['acting_return']);
2240 if(!isset($str[1])) {
2241 $results[0] = 0;
2242 }else{
2243 $para = parse_str($str[1]);
2244 $results[0] = isset($para['result']) ? (int)$para['result'] : 0;
2245 foreach($para as $key => $value){
2246 $results[$key] = $value;
2247 }
2248 }
2249
2250 }
2251 $results['reg_order'] = true;
2252 break;
2253
2254 case 'paypal':
2255 usces_log('paypal in ', 'acting_transaction.log');
2256 require_once($usces->options['settlement_path'] . "paypal.php");
2257 $results = paypal_check($usces_paypal_url);
2258 remove_action( 'wp_footer', array(&$usces, 'lastprocessing'));
2259 $results['reg_order'] = true;
2260 break;
2261
2262 case 'zeus_card':
2263 $results = $_REQUEST;
2264 if( $_REQUEST['acting_return'] && isset($_REQUEST['wctid']) && usces_is_trusted_acting_data($_REQUEST['wctid']) ){
2265 $results[0] = 1;
2266 }else{
2267 $results[0] = 0;
2268 }
2269 $results['reg_order'] = true;
2270 break;
2271
2272 case 'zeus_conv':
2273 $results = $_GET;
2274 if( $_REQUEST['acting_return'] ){
2275 $results[0] = 1;
2276 }else{
2277 $results[0] = 0;
2278 }
2279 $results['reg_order'] = false;
2280 break;
2281
2282 case 'remise_card':
2283 $results = $_POST;
2284 if( $_REQUEST['acting_return'] && ( isset($_REQUEST['X-ERRCODE']) && ' ' === $_REQUEST['X-ERRCODE'] ) ){
2285 usces_log('remise card entry data : '.print_r($entry, true), 'acting_transaction.log');
2286 $results[0] = 1;
2287 }else{
2288 $results[0] = 0;
2289 }
2290 if( isset($_REQUEST['dlseller_update']) ){
2291 $results['reg_order'] = false;
2292 }else{
2293 $results['reg_order'] = true;
2294 }
2295 break;
2296
2297 case 'remise_conv':
2298 $results = $_GET;
2299 if( $_REQUEST['acting_return'] && isset($_REQUEST['X-JOB_ID']) && '0:0000' === $_REQUEST['X-R_CODE']){
2300 //usces_log('remise conv entry data : '.print_r($entry, true), 'acting_transaction.log');
2301 $results[0] = 1;
2302 }else{
2303 $results[0] = 0;
2304 }
2305 $results['reg_order'] = true;
2306 break;
2307
2308 //20101018ysk start
2309 case 'jpayment_card':
2310 $results = $_GET;
2311 if($_GET['rst'] == 2) {
2312 usces_log('jpayment card error : '.print_r($entry, true), 'acting_transaction.log');
2313 }
2314 $results[0] = ($_GET['rst'] == 1) ? 1 : 0;
2315 $results['reg_order'] = true;
2316 break;
2317
2318 case 'jpayment_conv':
2319 $results = $_GET;
2320 if($_GET['rst'] == 2) {
2321 usces_log('jpayment conv error : '.print_r($entry, true), 'acting_transaction.log');
2322 }
2323 $results[0] = ($_GET['rst'] == 1 and $_GET['ap'] == 'CPL_PRE') ? 1 : 0;
2324 $results['reg_order'] = true;
2325 break;
2326
2327 case 'jpayment_bank':
2328 $results = $_GET;
2329 if($_GET['rst'] == 2) {
2330 usces_log('jpayment bank error : '.print_r($entry, true), 'acting_transaction.log');
2331 }
2332 $results[0] = ($_GET['rst'] == 1) ? 1 : 0;
2333 $results['reg_order'] = true;
2334 break;
2335 //20101018ysk end
2336 //20110208ysk start
2337 case 'paypal_ec':
2338 $results = $_GET;
2339
2340 //Build a second API request to PayPal, using the token as the ID to get the details on the payment authorization
2341 $req_token = isset($_REQUEST['token']) ? $_REQUEST['token'] : '0';
2342 $nvpstr = "&TOKEN=".urlencode($req_token);
2343
2344 $usces->paypal->setMethod('GetExpressCheckoutDetails');
2345 $usces->paypal->setData($nvpstr);
2346 $res = $usces->paypal->doExpressCheckout();
2347 $resArray = $usces->paypal->getResponse();
2348 $ack = strtoupper($resArray["ACK"]);
2349 if($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
2350 //20121009ysk start 0000587
2351 //20121225ysk start 000634
2352 $cart = $usces->cart->get_cart();
2353 $charging_type = $usces->getItemChargingType($cart[0]['post_id'], $cart);
2354 if( 'continue' == $charging_type ) {
2355 $results[0] = 1;
2356 } else {
2357 //20121225ysk end
2358 if( (float)$resArray["AMT"] != (float)$entry['order']['total_full_price'] ) {
2359 usces_log('PayPal : AMT Error. AMT='.$resArray["AMT"].', total_full_price='.$entry['order']['total_full_price'], 'acting_transaction.log');
2360 $results[0] = 0;
2361 } else {
2362 $results[0] = 1;
2363 }
2364 }
2365 //20121009ysk end
2366
2367 } else {
2368 //Display a user friendly Error on the page using any of the following error information returned by PayPal
2369 $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
2370 $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
2371 $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
2372 $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
2373 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');
2374 $results[0] = 0;
2375 }
2376 $results['reg_order'] = true;
2377 break;
2378 //20110208ysk end
2379 //20120413ysk start
2380 case 'sbps_card':
2381 case 'sbps_wallet':
2382 case 'sbps_mobile':
2383 /* if( isset($_REQUEST['cancel']) ) {
2384 $results[0] = 0;
2385 $results['reg_order'] = false;
2386
2387 } else {
2388 if( isset($_REQUEST['res_result']) and 'OK' == $_REQUEST['res_result'] ) {
2389 usces_log($acting.' entry data : '.print_r($entry, true), 'acting_transaction.log');
2390 $results[0] = 1;
2391 } else {
2392 usces_log($acting.' error : '.print_r($_REQUEST,true), 'acting_transaction.log');
2393 $results[0] = 0;
2394 }
2395 $results['reg_order'] = true;
2396 }
2397 break;*/
2398 case 'sbps_conv':
2399 case 'sbps_payeasy':
2400 if( isset($_REQUEST['cancel']) ) {
2401 $results[0] = 0;
2402 $results['reg_order'] = false;
2403
2404 } else {
2405 if( isset($_REQUEST['res_result']) and 'OK' == $_REQUEST['res_result'] ) {
2406 $results[0] = 1;
2407 } else {
2408 //usces_log($acting.' error : '.print_r($_REQUEST,true), 'acting_transaction.log');
2409 $results[0] = 0;
2410 }
2411 $results['reg_order'] = false;
2412 }
2413 break;
2414 //20120413ysk end
2415 //20120618ysk start
2416 case 'telecom_card':
2417 $results = $_GET;
2418 if( $_REQUEST['result'] ){
2419 usces_log($acting.' entry data : '.print_r($entry, true), 'acting_transaction.log');
2420 $results[0] = 1;
2421 }else{
2422 usces_log($acting.' error : '.print_r($_REQUEST,true), 'acting_transaction.log');
2423 $results[0] = 0;
2424 }
2425 $results['reg_order'] = true;
2426 break;
2427 //20120618ysk end
2428 //20121206ysk start
2429 case 'digitalcheck_card':
2430 $results = $_REQUEST;
2431 if( isset($_REQUEST['SID']) ) {
2432 $results[0] = 1;
2433 } else {
2434 $results[0] = 0;
2435 }
2436 $results['reg_order'] = true;
2437 break;
2438 case 'digitalcheck_conv':
2439 $results = $_REQUEST;
2440 //if( isset($_REQUEST['SID']) ) {
2441 $results[0] = 1;
2442 //} else {
2443 // $results[0] = 0;
2444 //}
2445 $results['reg_order'] = false;
2446 break;
2447 //20121206ysk end
2448 //20130225ysk start
2449 case 'mizuho_card':
2450 case 'mizuho_conv':
2451 $results = $_GET;
2452 if( isset($_GET['rsltcd']) ) {
2453 if( '000' == substr($_GET['rsltcd'], 0, 3) ) {
2454 $results[0] = 1;
2455 $results['reg_order'] = true;
2456 } else {
2457 $results[0] = 0;
2458 $results['reg_order'] = false;
2459 }
2460 } else {
2461 $results[0] = 0;
2462 $results['reg_order'] = false;
2463 }
2464 break;
2465 //20130225ysk end
2466 //20131220ysk start
2467 case 'anotherlane_card':
2468 $results[0] = 1;
2469 $results['reg_order'] = false;
2470 break;
2471 //20131220ysk end
2472 //20140206ysk start
2473 case 'veritrans_card':
2474 case 'veritrans_conv':
2475 $results[0] = ( isset($_GET['result']) ) ? $_GET['result'] : 0;
2476 $results['reg_order'] = false;
2477 break;
2478 //20140206ysk end
2479
2480 default:
2481 do_action( 'usces_action_check_acting_return_default' );
2482 $results = $_REQUEST;//20140227ysk
2483 if( isset($_REQUEST['result']) and true == $_REQUEST['result'] ) {
2484 usces_log($acting.' entry data : '.print_r($entry, true), 'acting_transaction.log');
2485 $results[0] = 1;
2486 }else{
2487 usces_log($acting.' error : '.print_r($_REQUEST, true), 'acting_transaction.log');
2488 $results[0] = 0;
2489 }
2490 //20110310ysk start
2491 //$results['reg_order'] = false;
2492 $results['reg_order'] = true;
2493 //20110310ysk end
2494 $results = apply_filters( 'usces_filter_check_acting_return_results', $results );//20140227ysk
2495 break;
2496 }
2497
2498 return $results;
2499 }
2500 //20110203ysk start
2501 function usces_check_acting_return_duplicate( $results = array() ) {
2502 global $wpdb;
2503 $acting = isset($_GET['acting']) ? $_GET['acting'] : '';
2504 // usces_log('$_REQUEST : '.print_r($_REQUEST,true), 'acting_transaction.log');
2505 // usces_log('$results : '.print_r($results,true), 'acting_transaction.log');
2506
2507 switch($acting) {
2508 case 'epsilon':
2509 $trans_id = isset($_REQUEST['trans_code']) ? $_REQUEST['trans_code'] : '';
2510 break;
2511 //20110208ysk start
2512 case 'paypal':
2513 $trans_id = isset($results['txn_id']) ? $results['txn_id'] : '';
2514 break;
2515 //20110208ysk end
2516 case 'paypal_ipn':
2517 $trans_id = isset($_REQUEST['txn_id']) ? $_REQUEST['txn_id'] : '';
2518 break;
2519 //20110208ysk start
2520 case 'paypal_ec':
2521 $trans_id = isset($_REQUEST['token']) ? $_REQUEST['token'] : '';
2522 break;
2523 //20110208ysk end
2524 case 'zeus_card':
2525 $trans_id = isset($_REQUEST['ordd']) ? $_REQUEST['ordd'] : '';
2526 break;
2527 case 'zeus_conv':
2528 case 'zeus_bank':
2529 $trans_id = isset($_REQUEST['order_no']) ? $_REQUEST['order_no'] : '';
2530 break;
2531 case 'remise_card':
2532 $trans_id = isset($_REQUEST['X-TRANID']) ? $_REQUEST['X-TRANID'] : '';
2533 break;
2534 case 'remise_conv':
2535 $trans_id = isset($_REQUEST['X-JOB_ID']) ? $_REQUEST['X-JOB_ID'] : '';
2536 break;
2537 case 'jpayment_card':
2538 case 'jpayment_conv':
2539 case 'jpayment_bank':
2540 $trans_id = isset($_REQUEST['gid']) ? $_REQUEST['gid'] : '';
2541 break;
2542 //20120413ysk start
2543 case 'sbps_card':
2544 case 'sbps_conv':
2545 case 'sbps_payeasy':
2546 case 'sbps_wallet':
2547 case 'sbps_mobile':
2548 $trans_id = isset($_REQUEST['order_id']) ? $_REQUEST['order_id'] : '';
2549 break;
2550 //20120413ysk end
2551 //20120618ysk start
2552 case 'telecom_card':
2553 $trans_id = isset($_REQUEST['sendid']) ? $_REQUEST['sendid'] : '';
2554 break;
2555 //20120618ysk end
2556 //20121206ysk start
2557 case 'digitalcheck_card':
2558 case 'digitalcheck_conv':
2559 $trans_id = isset($_REQUEST['SID']) ? $_REQUEST['SID'] : '';
2560 break;
2561 //20121206ysk end
2562 //20130225ysk start
2563 case 'mizuho_card':
2564 case 'mizuho_conv':
2565 $trans_id = isset($_REQUEST['stran']) ? $_REQUEST['stran'] : '';
2566 break;
2567 //20130225ysk end
2568 default:
2569 $trans_id = '';
2570 }
2571 $table_meta_name = $wpdb->prefix.'usces_order_meta';
2572 $query = $wpdb->prepare("SELECT order_id FROM $table_meta_name WHERE meta_key = %s AND meta_value = %s", 'trans_id', $trans_id);
2573 $order_id = $wpdb->get_var($query);
2574 return $order_id;
2575 }
2576 //20110203ysk end
2577
2578 //20111111ysk start
2579 function usces_dates_interconv( $date_str ) {
2580 $base_struc = preg_split('[/.-]', 'd/m/Y' );
2581 $date_str_parts = preg_split('[/.-]', $date_str );
2582 $date_elements = array();
2583
2584 $p_keys = array_keys( $base_struc );
2585 foreach( $p_keys as $p_key ) {
2586 if( !empty( $date_str_parts[$p_key] )) {
2587 $date_elements[$base_struc[$p_key]] = $date_str_parts[$p_key];
2588 } else {
2589 return false;
2590 }
2591 }
2592 $dummy_ts = mktime( 0,0,0, $date_elements['m'],$date_elements['d'],$date_elements['Y']);
2593 return date( 'Y-m-d', $dummy_ts );
2594 }
2595 //20101111ysk end
2596
2597 function usces_register_action($handle, $type, $key, $value, $function){
2598 global $usces_action;
2599 $usces_action[$handle] = array('type'=>$type, 'key'=>$key, 'value'=>$value, 'function'=>$function);
2600 }
2601
2602 function usces_deregister_action($handle){
2603 global $usces_action;
2604 unset($usces_action[$handle]);
2605 }
2606
2607 function usces_get_wcexp($post_id, $name=''){
2608 $wcexp = get_post_meta($post_id, '_wcexp', true);
2609 if( empty($name) ){
2610 $value = ( $wcexp !== false ) ? $wcexp : '';
2611 }else{
2612 $value = ($wcexp !== false && isset($wcexp[$name])) ? $wcexp[$name] : '';
2613 }
2614 return $value;
2615 }
2616
2617 function usces_update_check_admin($result){
2618 $result = true;
2619 return $result;
2620 }
2621
2622 function usces_setup_cod_ajax(){
2623 global $usces;
2624 $usces->options = get_option('usces');
2625 $message = '';
2626 $_POST = $usces->stripslashes_deep_post($_POST);
2627
2628 $usces->options['cod_type'] = isset($_POST['cod_type']) ? $_POST['cod_type'] : 'fix';
2629 if( isset($_POST['cod_fee']) )
2630 $usces->options['cod_fee'] = (int)$_POST['cod_fee'];
2631
2632 if( 'fix' == $usces->options['cod_type'] ){
2633 if( isset($_POST['cod_limit_amount']) ){
2634 $usces->options['cod_limit_amount'] = (int)$_POST['cod_limit_amount'];
2635 if( !WCUtils::is_blank($_POST['cod_limit_amount']) && 0 === (int)$_POST['cod_limit_amount'] )
2636 $message = __('There is the item where a value is dirty.', 'usces');
2637 }
2638
2639 }elseif( 'change' == $usces->options['cod_type'] ){
2640 if( isset($_POST['cod_first_amount']) ){
2641 $usces->options['cod_first_amount'] = (int)$_POST['cod_first_amount'];
2642 if( 0 === (int)$_POST['cod_first_amount'] )
2643 $message = __('There is the item where a value is dirty.', 'usces');
2644 }
2645 if( isset($_POST['cod_limit_amount']) ){
2646 $usces->options['cod_limit_amount'] = (int)$_POST['cod_limit_amount'];
2647 if( !WCUtils::is_blank($_POST['cod_limit_amount']) && 0 === (int)$_POST['cod_limit_amount'] )
2648 $message = __('There is the item where a value is dirty.', 'usces');
2649 }
2650 if( isset($_POST['cod_first_fee']) ){
2651 $usces->options['cod_first_fee'] = (int)$_POST['cod_first_fee'];
2652 if( 0 === (int)$_POST['cod_first_fee'] && '0' !== $_POST['cod_first_fee'])
2653 $message = __('There is the item where a value is dirty.', 'usces');
2654 }
2655 if( isset($_POST['cod_end_fee']) ){
2656 $usces->options['cod_end_fee'] = (int)$_POST['cod_end_fee'];
2657 if( 0 === (int)$_POST['cod_end_fee'] && '0' !== $_POST['cod_end_fee'] )
2658 $message = __('There is the item where a value is dirty.', 'usces');
2659 }
2660
2661 unset($usces->options['cod_amounts'], $usces->options['cod_fees']);
2662 if( isset($_POST['cod_amounts']) ){
2663 for($i=0; $i<count((array)$_POST['cod_amounts']); $i++){
2664 $usces->options['cod_amounts'][$i] = (int)$_POST['cod_amounts'][$i];
2665 $usces->options['cod_fees'][$i] = (int)$_POST['cod_fees'][$i];
2666 if( 0 === (int)$_POST['cod_amounts'][$i] || (0 === (int)$_POST['cod_fees'][$i] && '0' !== $_POST['cod_fees'][$i]) )
2667 $message = __('There is the item where a value is dirty.', 'usces');
2668 }
2669 }
2670 }
2671
2672
2673 if( '' == $message ){
2674 $r = 'success';
2675 update_option('usces', $usces->options);
2676 }else{
2677 $r = '<span style="color:red;">' . $message . '</span>';
2678 }
2679 die( $r );
2680 }
2681
2682 function usces_get_order_acting_data($rand){
2683 global $wpdb;
2684
2685 $table_name = $wpdb->prefix . "usces_access";
2686 $query = $wpdb->prepare("SELECT acc_str1 AS sesid, acc_value AS order_data FROM $table_name WHERE acc_key = %s", $rand);
2687 $res = $wpdb->get_row($query, ARRAY_A);
2688 if($res == NULL){
2689 return false;
2690 }else{
2691 return $res;
2692 }
2693 }
2694
2695 function usces_auth_order_acting_data($rand){
2696 global $usces, $wpdb;
2697 $datas = usces_get_order_acting_data($rand);
2698 $data = unserialize($datas['order_data']);
2699 usces_log('usces_auth_order_acting_data', 'acting_transaction.log');
2700 $data['propriety'] = 1;
2701
2702 $data = serialize($data);
2703 $table_name = $wpdb->prefix . "usces_access";
2704 $query = $wpdb->prepare("UPDATE $table_name SET acc_value = %s WHERE acc_type = %s AND acc_key = %s",
2705 $data,
2706 'acting_data',
2707 $rand
2708 );
2709 $res = $wpdb->query($query);
2710 }
2711
2712 function usces_ordered_acting_data($rand){
2713 global $usces, $wpdb;
2714 $datas = usces_get_order_acting_data($rand);
2715 $data = unserialize($datas['order_data']);
2716 usces_log('usces_ordered_acting_data', 'acting_transaction.log');
2717 $data['order_received'] = 1;
2718
2719 $data = serialize($data);
2720 $table_name = $wpdb->prefix . "usces_access";
2721 $query = $wpdb->prepare("UPDATE $table_name SET acc_value = %s WHERE acc_type = %s AND acc_key = %s",
2722 $data,
2723 'acting_data',
2724 $rand
2725 );
2726 $res = $wpdb->query($query);
2727 }
2728
2729 function usces_is_trusted_acting_data($rand){
2730 global $usces, $wpdb;
2731 $datas = usces_get_order_acting_data($rand);
2732 $data = unserialize($datas['order_data']);
2733 usces_log('usces_is_trusted_acting_data', 'acting_transaction.log');
2734 if( isset($data['propriety']) && $data['propriety'] && !isset($data['order_received']) )
2735 return true;
2736 else
2737 return false;
2738 }
2739
2740 function usces_get_filename( $path ){
2741 $res = array();
2742 if ( $handle = opendir($path) ) {
2743 while (false !== ($file = readdir($handle))) {
2744 if( '.' != $file && '..' != $file )
2745 $res[] = $file;
2746 }
2747 closedir($handle);
2748 }
2749 return $res;
2750 }
2751
2752 function usces_locales(){
2753 $res = array();
2754 if ( $handle = opendir(USCES_PLUGIN_DIR.'/languages/') ) {
2755 while (false !== ($file = readdir($handle))) {
2756 if( '.' != $file && '..' != $file && preg_match('/^usces-(.+)\.mo$/', $file, $matches) ){
2757 $res[] = $matches[1];
2758 }
2759 }
2760 closedir($handle);
2761 }
2762 return $res;
2763 }
2764
2765 function usces_get_local_language(){
2766 $locale = get_locale();
2767 switch( $locale ){
2768 case '':
2769 case 'en':
2770 case 'en_US':
2771 $front_lang = 'en';
2772 break;
2773 case 'ja':
2774 case 'ja_JP':
2775 $front_lang = 'ja';
2776 break;
2777 default:
2778 $front_lang = 'others';
2779 }
2780 return $front_lang;
2781 }
2782
2783 function usces_get_base_country(){
2784 global $usces_settings;
2785 // $locale = get_locale();
2786 $wplang = defined('WPLANG') ? WPLANG : '';
2787 $locale = empty( $wplang ) ? 'en' : $wplang;
2788 if( array_key_exists($locale, $usces_settings['lungage2country']) )
2789 return $usces_settings['lungage2country'][$locale];
2790 else
2791 return 'US';
2792 }
2793
2794 function usces_get_local_addressform(){
2795 global $usces_settings;
2796 $base = usces_get_base_country();
2797 if( array_key_exists($base, $usces_settings['addressform']) )
2798 return $usces_settings['addressform'][$base];
2799 else
2800 return 'US';
2801 }
2802
2803 function usces_get_local_target_market(){
2804 $base = usces_get_base_country();
2805 return (array)$base;
2806 }
2807
2808 function usces_get_apply_addressform($country){
2809 global $usces_settings;
2810 return $usces_settings['addressform'][$country];
2811 }
2812
2813 function usces_remove_filter(){
2814 global $usces, $post;
2815
2816 if( is_single() && 'item' == $post->post_mime_type ) {
2817 remove_filter('the_content', array(&$usces, 'filter_itemPage'));
2818
2819 }else if( $usces->is_cart_page($_SERVER['REQUEST_URI']) || $usces->is_inquiry_page($_SERVER['REQUEST_URI']) ){
2820 remove_action('the_post', array(&$usces, 'action_cartFilter'));
2821 remove_filter('the_title', array(&$usces, 'filter_cartTitle'),20);
2822 remove_filter('the_content', array(&$usces, 'filter_cartContent'),20);
2823
2824 }else if( $usces->is_member_page($_SERVER['REQUEST_URI']) ){
2825 remove_action('the_post', array(&$usces, 'action_memberFilter'));
2826 remove_filter('the_title', array(&$usces, 'filter_memberTitle'),20);
2827 remove_filter('the_content', array(&$usces, 'filter_memberContent'),20);
2828
2829 }else{
2830 remove_action('the_post', array(&$usces, 'goDefaultPage'));
2831 }
2832 }
2833
2834 function usces_reset_filter(){
2835 global $usces, $post;
2836
2837 if( is_single() && 'item' == $post->post_mime_type ) {
2838 add_filter('the_content', array(&$usces, 'filter_itemPage'));
2839
2840 }else if( $usces->is_cart_page($_SERVER['REQUEST_URI']) || $usces->is_inquiry_page($_SERVER['REQUEST_URI']) ){
2841 add_action('the_post', array(&$usces, 'action_cartFilter'));
2842 add_filter('the_title', array(&$usces, 'filter_cartTitle'),20);
2843 add_filter('the_content', array(&$usces, 'filter_cartContent'),20);
2844
2845 }else if( $usces->is_member_page($_SERVER['REQUEST_URI']) ){
2846 add_action('the_post', array(&$usces, 'action_memberFilter'));
2847 add_filter('the_title', array(&$usces, 'filter_memberTitle'),20);
2848 add_filter('the_content', array(&$usces, 'filter_memberContent'),20);
2849
2850 }else{
2851 add_action('the_post', array(&$usces, 'goDefaultPage'));
2852 }
2853 }
2854
2855
2856 function usces_get_wcex(){
2857 $wcex = array();
2858 if( defined('WCEX_DLSELLER_VERSION'))
2859 $wcex['DLSELLER'] = array('name'=>'Dl Seller', 'version'=>WCEX_DLSELLER_VERSION);
2860 if( defined('WCEX_ITEM_LIST_LAYOUT_VERSION'))
2861 $wcex['ITEM_LIST_LAYOUT'] = array('name'=>'Item List Layout', 'version'=>WCEX_ITEM_LIST_LAYOUT_VERSION);
2862 if( defined('WCEX_MOBILE_VERSION'))
2863 $wcex['MOBILE'] = array('name'=>'Mobile', 'version'=>WCEX_MOBILE_VERSION);
2864 if( defined('WCEX_MULTIPRICE_VERSION'))
2865 $wcex['MULTIPRICE'] = array('name'=>'Multi Price', 'version'=>WCEX_MULTIPRICE_VERSION);
2866 if( defined('WCEX_SLIDE_SHOWCASE_VERSION'))
2867 $wcex['SLIDE_SHOWCASE'] = array('name'=>'Slide Showcase', 'version'=>WCEX_SLIDE_SHOWCASE_VERSION);
2868 if( defined('WCEX_WIDGET_CART_VERSION'))
2869 $wcex['WIDGET_CART'] = array('name'=>'Widget Cart', 'version'=>WCEX_WIDGET_CART_VERSION);
2870
2871 return $wcex;
2872 }
2873
2874 function usces_trackPageview_cart($push){
2875 $push = array();
2876 if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2877 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_cart'";
2878 }else{
2879 $push[] = "'_trackPageview','/wc_cart'";
2880 }
2881 return $push;
2882 }
2883
2884 function usces_trackPageview_customer($push){
2885 $push = array();
2886 if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2887 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_customer'";
2888 }else{
2889 $push[] = "'_trackPageview','/wc_customer'";
2890 }
2891 return $push;
2892 }
2893
2894 function usces_trackPageview_delivery($push){
2895 $push = array();
2896 if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2897 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_delivery'";
2898 }else{
2899 $push[] = "'_trackPageview','/wc_delivery'";
2900 }
2901 return $push;
2902 }
2903
2904 function usces_trackPageview_confirm($push){
2905 $push = array();
2906 if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2907 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_confirm'";
2908 }else{
2909 $push[] = "'_trackPageview','/wc_confirm'";
2910 }
2911 return $push;
2912 }
2913
2914 function usces_trackPageview_ordercompletion($push){
2915 global $usces;
2916 $sesdata = $usces->cart->get_entry();
2917 $order_id = $sesdata['order']['ID'];
2918 $data = $usces->get_order_data($order_id, 'direct');
2919 $cart = unserialize($data['order_cart']);
2920 $total_price = $usces->get_total_price( $cart ) + $data['order_discount'] - $data['order_usedpoint'];
2921
2922 if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2923 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_ordercompletion'";
2924 }else{
2925 $push[] = "'_trackPageview','/wc_ordercompletion'";
2926 }
2927 $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() . "'";
2928 for($i=0; $i<count($cart); $i++) {
2929 $cart_row = $cart[$i];
2930 $post_id = $cart_row['post_id'];
2931 $sku = urldecode($cart_row['sku']);
2932 $quantity = $cart_row['quantity'];
2933 // $options = $cart_row['options'];
2934 // $advance = $usces->cart->wc_serialize($cart_row['advance']);
2935 // $itemCode = $usces->getItemCode($post_id);
2936 $itemName = $usces->getItemName($post_id);
2937 // $cartItemName = $usces->getCartItemName($post_id, $sku);
2938 $skuPrice = $cart_row['price'];
2939 $cats = $usces->get_item_cat_genre_ids( $post_id );
2940 if( is_array($cats) )
2941 sort($cats);
2942 $category = get_cat_name( $cats[0] );
2943 $push[] = "'_addItem', '" . $order_id . "', '" . $sku . "', '" . $itemName . "', '" . $category . "', '" . $skuPrice . "', '" . $quantity . "'";
2944 }
2945 $push[] = "'_trackTrans'";
2946
2947 return $push;
2948 }
2949
2950 function usces_trackPageview_error($push){
2951 if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2952 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_error'";
2953 }else{
2954 $push[] = "'_trackPageview','/wc_error'";
2955 }
2956 return $push;
2957 }
2958
2959 function usces_trackPageview_member($push){
2960 if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2961 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_member'";
2962 }else{
2963 $push[] = "'_trackPageview','/wc_member'";
2964 }
2965 return $push;
2966 }
2967
2968 function usces_trackPageview_login($push){
2969 if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2970 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_login'";
2971 }else{
2972 $push[] = "'_trackPageview','/wc_login'";
2973 }
2974 return $push;
2975 }
2976
2977 function usces_trackPageview_editmemberform($push){
2978 if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2979 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_editmemberform'";
2980 }else{
2981 $push[] = "'_trackPageview','/wc_editmemberform'";
2982 }
2983 return $push;
2984 }
2985
2986 function usces_trackPageview_newcompletion($push){
2987 if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2988 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_newcompletion'";
2989 }else{
2990 $push[] = "'_trackPageview','/wc_newcompletion'";
2991 }
2992 return $push;
2993 }
2994
2995 function usces_trackPageview_newmemberform($push){
2996 if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
2997 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_newmemberform'";
2998 }else{
2999 $push[] = "'_trackPageview','/wc_newmemberform'";
3000 }
3001 return $push;
3002 }
3003
3004 function usces_trackPageview_deletemember($push){
3005 if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
3006 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_deletemember'";
3007 }else{
3008 $push[] = "'_trackPageview','/wc_deletemember'";
3009 }
3010 return $push;
3011 }
3012
3013 function usces_trackPageview_search_item($push){
3014 if(defined('USCES_KEY') && defined('USCES_MULTI') && true == USCES_MULTI){
3015 $push[] = "'_trackPageview','/" . USCES_KEY . "wc_search_item'";
3016 }else{
3017 $push[] = "'_trackPageview','/wc_search_item'";
3018 }
3019 return $push;
3020 }
3021
3022 function usces_get_essential_mark( $fielde, $data = NULL ){
3023 global $usces_essential_mark;
3024 do_action('usces_action_essential_mark', $data, $fielde);
3025 return $usces_essential_mark[$fielde];
3026 }
3027
3028 function uesces_get_admin_addressform( $type, $data, $customdata, $out = 'return' ){
3029 global $usces, $usces_settings;
3030 $options = get_option('usces');
3031 $applyform = usces_get_apply_addressform($options['system']['addressform']);
3032 $formtag = '';
3033 switch( $type ){
3034 case 'member':
3035 $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']);
3036 $country = $usces->get_member_meta_value('customer_country', $data['ID']);
3037 $values['country'] = !empty($country) ? $country : usces_get_local_addressform();
3038 break;
3039 case 'customer':
3040 $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']);
3041 $country = $usces->get_order_meta_value('customer_country', $data['ID']);
3042 $values['country'] = !empty($country) ? $country : usces_get_local_addressform();
3043 break;
3044 case 'delivery':
3045 $values = $data;
3046 break;
3047 }
3048
3049 switch ($applyform){
3050
3051 case 'JP':
3052 //20100818ysk start
3053 $formtag .= usces_admin_custom_field_input($customdata, $type, 'name_pre', 'return');
3054 //20100818ysk end
3055 $formtag .= '
3056 <tr>
3057 <td class="label">' . __('name', 'usces') . '</td>
3058 <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>
3059 </tr>
3060 <tr>
3061 <td class="label">' . __('furigana', 'usces') . '</td>
3062 <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>
3063 </tr>';
3064 //20100818ysk start
3065 $formtag .= usces_admin_custom_field_input($customdata, $type, 'name_after', 'return');
3066 //20100818ysk end
3067 $formtag .= '
3068 <tr>
3069 <td class="label">' . __('Zip/Postal Code', 'usces') . '</td>
3070 <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>
3071 </tr>
3072 <tr>
3073 <td class="label">' . __('Country', 'usces') . '</td>
3074 <td class="col2">' . uesces_get_target_market_form( $type, $values['country'] ) . '</td>
3075 </tr>
3076 <tr>
3077 <td class="label">' . __('Province', 'usces') . '</td>
3078 <td class="col2">';
3079
3080 $formtag .= usces_pref_select( $type, $values );
3081
3082 $formtag .= '</td>
3083 </tr>';
3084 $formtag .= '
3085 <tr>
3086 <td class="label">' . __('city', 'usces') . '</td>
3087 <td class="col2"><input name="' . $type . '[address1]" type="text" class="text long" value="' . esc_attr($values['address1']) . '" /></td>
3088 </tr>
3089 <tr>
3090 <td class="label">' . __('numbers', 'usces') . '</td>
3091 <td class="col2"><input name="' . $type . '[address2]" type="text" class="text long" value="' . esc_attr($values['address2']) . '" /></td>
3092 </tr>
3093 <tr>
3094 <td class="label">' . __('building name', 'usces') . '</td>
3095 <td class="col2"><input name="' . $type . '[address3]" type="text" class="text long" value="' . esc_attr($values['address3']) . '" /></td>
3096 </tr>
3097 <tr>
3098 <td class="label">' . __('Phone number', 'usces') . '</td>
3099 <td class="col2"><input name="' . $type . '[tel]" type="text" class="text long" value="' . esc_attr($values['tel']) . '" /></td>
3100 </tr>
3101 <tr>
3102 <td class="label">' . __('FAX number', 'usces') . '</td>
3103 <td class="col2"><input name="' . $type . '[fax]" type="text" class="text long" value="' . esc_attr($values['fax']) . '" /></td>
3104 </tr>';
3105 //20100818ysk start
3106 $formtag .= usces_admin_custom_field_input($customdata, $type, 'fax_after', 'return');
3107 //20100818ysk end
3108 break;
3109
3110 case 'CN':
3111 $formtag .= usces_admin_custom_field_input($customdata, $type, 'name_pre', 'return');
3112 $formtag .= '
3113 <tr>
3114 <td class="label">' . __('name', 'usces') . '</td>
3115 <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>
3116 </tr>';
3117 $formtag .= usces_admin_custom_field_input($customdata, $type, 'name_after', 'return');
3118 $formtag .= '
3119 <tr>
3120 <td class="label">' . __('Country', 'usces') . '</td>
3121 <td class="col2">' . uesces_get_target_market_form( $type, $values['country'] ) . '</td>
3122 </tr>
3123 <tr>
3124 <td class="label">' . __('State', 'usces') . '</td>
3125 <td class="col2">';
3126
3127 $formtag .= usces_pref_select( $type, $values );
3128
3129 $formtag .= '</td>
3130 </tr>';
3131 $formtag .= '<tr>
3132 <td class="label">' . __('city', 'usces') . '</td>
3133 <td class="col2"><input name="' . $type . '[address1]" type="text" class="text long" value="' . esc_attr($values['address1']) . '" /></td>
3134 </tr>
3135 <tr>
3136 <td class="label">' . __('Address Line1', 'usces') . '</td>
3137 <td class="col2"><input name="' . $type . '[address2]" type="text" class="text long" value="' . esc_attr($values['address2']) . '" /></td>
3138 </tr>
3139 <tr>
3140 <td class="label">' . __('Address Line2', 'usces') . '</td>
3141 <td class="col2"><input name="' . $type . '[address3]" type="text" class="text long" value="' . esc_attr($values['address3']) . '" /></td>
3142 </tr>
3143 <tr>
3144 <td class="label">' . __('Zip', 'usces') . '</td>
3145 <td class="col2"><input name="' . $type . '[zipcode]" type="text" class="text short" value="' . esc_attr($values['zipcode']) . '" /></td>
3146 </tr>
3147 <tr>
3148 <td class="label">' . __('Phone number', 'usces') . '</td>
3149 <td class="col2"><input name="' . $type . '[tel]" type="text" class="text long" value="' . esc_attr($values['tel']) . '" /></td>
3150 </tr>
3151 <tr>
3152 <td class="label">' . __('FAX number', 'usces') . '</td>
3153 <td class="col2"><input name="' . $type . '[fax]" type="text" class="text long" value="' . esc_attr($values['fax']) . '" /></td>
3154 </tr>';
3155 $formtag .= usces_admin_custom_field_input($customdata, $type, 'fax_after', 'return');
3156 break;
3157
3158 case 'US':
3159 default:
3160 //20100818ysk start
3161 $formtag .= usces_admin_custom_field_input($customdata, $type, 'name_pre', 'return');
3162 //20100818ysk end
3163 $formtag .= '
3164 <tr>
3165 <td class="label">' . __('name', 'usces') . '</td>
3166 <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>
3167 </tr>';
3168 //20100818ysk start
3169 $formtag .= usces_admin_custom_field_input($customdata, $type, 'name_after', 'return');
3170 //20100818ysk end
3171 $formtag .= '
3172 <tr>
3173 <td class="label">' . __('Address Line1', 'usces') . '</td>
3174 <td class="col2"><input name="' . $type . '[address2]" type="text" class="text long" value="' . esc_attr($values['address2']) . '" /></td>
3175 </tr>
3176 <tr>
3177 <td class="label">' . __('Address Line2', 'usces') . '</td>
3178 <td class="col2"><input name="' . $type . '[address3]" type="text" class="text long" value="' . esc_attr($values['address3']) . '" /></td>
3179 </tr>
3180 <tr>
3181 <td class="label">' . __('city', 'usces') . '</td>
3182 <td class="col2"><input name="' . $type . '[address1]" type="text" class="text long" value="' . esc_attr($values['address1']) . '" /></td>
3183 </tr>
3184 <tr>
3185 <td class="label">' . __('State', 'usces') . '</td>
3186 <td class="col2">';
3187
3188 $formtag .= usces_pref_select( $type, $values );
3189
3190 $formtag .= '</td>
3191 </tr>';
3192 $formtag .= '
3193 <tr>
3194 <td class="label">' . __('Country', 'usces') . '</td>
3195 <td class="col2">' . uesces_get_target_market_form( $type, $values['country'] ) . '</td>
3196 </tr>
3197 <tr>
3198 <td class="label">' . __('Zip', 'usces') . '</td>
3199 <td class="col2"><input name="' . $type . '[zipcode]" type="text" class="text short" value="' . esc_attr($values['zipcode']) . '" /></td>
3200 </tr>
3201 <tr>
3202 <td class="label">' . __('Phone number', 'usces') . '</td>
3203 <td class="col2"><input name="' . $type . '[tel]" type="text" class="text long" value="' . esc_attr($values['tel']) . '" /></td>
3204 </tr>
3205 <tr>
3206 <td class="label">' . __('FAX number', 'usces') . '</td>
3207 <td class="col2"><input name="' . $type . '[fax]" type="text" class="text long" value="' . esc_attr($values['fax']) . '" /></td>
3208 </tr>';
3209 //20100818ysk start
3210 $formtag .= usces_admin_custom_field_input($customdata, $type, 'fax_after', 'return');
3211 //20100818ysk end
3212 break;
3213 }
3214 $res = apply_filters('usces_filter_apply_admin_addressform', $formtag, $type, $data, $customdata);
3215
3216
3217 if($out == 'return') {
3218 return $res;
3219 } else {
3220 echo $res;
3221 }
3222 }
3223
3224 function uesces_get_mail_addressform( $type, $data, $order_id, $out = 'return' ){
3225 global $wpdb, $usces, $usces_settings;
3226 $options = get_option('usces');
3227 $applyform = usces_get_apply_addressform($options['system']['addressform']);
3228 $formtag = '';
3229 switch( $type ){
3230 case 'admin_mail_customer':
3231 $values = $data;
3232 $values['country'] = !empty($values['country']) ? $values['country'] : usces_get_local_addressform();
3233 $mode = 'customer';
3234 $name_label = __('Buyer','usces');
3235 break;
3236 case 'admin_mail':
3237 $values = $data;
3238 $values['country'] = !empty($values['country']) ? $values['country'] : usces_get_local_addressform();
3239 $mode = 'delivery';
3240 $name_label = __('A destination name','usces');
3241 break;
3242 case 'order_mail_customer':
3243 $values = $data['customer'];
3244 $values['country'] = !empty($values['country']) ? $values['country'] : usces_get_local_addressform();
3245 $mode = 'customer';
3246 $name_label = __('Buyer','usces');
3247 break;
3248 case 'order_mail':
3249 $values = $data['delivery'];
3250 $values['country'] = !empty($values['country']) ? $values['country'] : usces_get_local_addressform();
3251 $mode = 'delivery';
3252 $name_label = __('A destination name','usces');
3253 break;
3254 }
3255
3256 switch ($applyform){
3257
3258 case 'JP':
3259 //20110118ysk start
3260 $formtag .= usces_mail_custom_field_info( $mode, 'name_pre', $order_id );
3261 //20110118ysk end
3262 //20131129_kitamu_start
3263 if( $type == 'order_mail_customer' or $type == 'admin_mail_customer' ){
3264 $usces_order_table = $wpdb->prefix . "usces_order";
3265 $order_data = $wpdb->get_results( $wpdb->prepare("SELECT mem_id,order_email FROM $usces_order_table WHERE ID = %d LIMIT 1", $order_id ) );
3266 $mem_id = $order_data[0]->mem_id;
3267 $order_email = $order_data[0]->order_email;
3268
3269 $formtag .= ( !empty( $mem_id ) ) ? __( 'membership number', 'usces' ) . "\t\t: " . $mem_id . "\r\n" : '';
3270 $formtag .= ( !empty( $order_email ) ) ? __( 'e-mail adress', 'usces' ) . "\t\t: " . $order_email . "\r\n" : '';
3271 }
3272 //20131129_kitamu_end
3273 $formtag .= $name_label . "\t\t: " . sprintf(__('Mr/Mrs %s', 'usces'), ($values['name1'] . ' ' . $values['name2'])) . " \r\n";
3274 if( !empty($values['name3']) || !empty($values['name4']) ) {
3275 $formtag .= __('furigana','usces') . "\t\t: " . $values['name3'] . ' ' . $values['name4'] . " \r\n";
3276 }
3277 //20110118ysk start
3278 $formtag .= usces_mail_custom_field_info( $mode, 'name_after', $order_id );
3279 //20110118ysk end
3280 //20131213_kitamu_start
3281 if( count( $options['system']['target_market'] ) != 1 ){
3282 $formtag .= __('Country','usces') . "\t\t\t: " . $usces_settings['country'][$values['country']] . "\r\n";
3283 }
3284 //20131213_kitamu_end
3285 $formtag .= __('Zip/Postal Code','usces') . "\t\t: " . $values['zipcode'] . "\r\n";
3286 $formtag .= __('Address','usces') . "\t\t\t: " . $values['pref'] . $values['address1'] . $values['address2'] . " " . $values['address3'] . "\r\n";
3287 $formtag .= __('Phone number','usces') . "\t\t: " . $values['tel'] . "\r\n";
3288 $formtag .= __('FAX number','usces') . "\t\t: " . $values['fax'] . "\r\n";
3289 //20110118ysk start
3290 $formtag .= usces_mail_custom_field_info( $mode, 'fax_after', $order_id );
3291 //20110118ysk end
3292 break;
3293
3294 case 'CN':
3295 //20110118ysk start
3296 $formtag .= usces_mail_custom_field_info( $mode, 'name_pre', $order_id );
3297 //20110118ysk end
3298 //20131129_kitamu_start
3299 if( $type == 'order_mail_customer' or $type == 'admin_mail_customer' ){
3300 $usces_order_table = $wpdb->prefix . "usces_order";
3301 $order_data = $wpdb->get_results( $wpdb->prepare("SELECT mem_id,order_email FROM $usces_order_table WHERE ID = %d LIMIT 1", $order_id ) );
3302 $mem_id = $order_data[0]->mem_id;
3303 $order_email = $order_data[0]->order_email;
3304
3305 $formtag .= ( !empty( $mem_id ) ) ? __( 'membership number', 'usces' ) . "\t\t: " . $mem_id . "\r\n" : '';
3306 $formtag .= ( !empty( $order_email ) ) ? __( 'e-mail adress', 'usces' ) . "\t\t: " . $order_email . "\r\n" : '';
3307 }
3308 //20131129_kitamu_end
3309 $formtag .= $name_label . "\t\t: " . sprintf(__('Mr/Mrs %s', 'usces'), ($values['name1'] . ' ' . $values['name2'])) . " \r\n";
3310 //20110118ysk start
3311 $formtag .= usces_mail_custom_field_info( $mode, 'name_after', $order_id );
3312 //20110118ysk end
3313 //20131213_kitamu_start
3314 if( count( $options['system']['target_market'] ) != 1 ){
3315 $formtag .= __('Country','usces') . " : " . $usces_settings['country'][$values['country']] . "\r\n";
3316 }
3317 //20131213_kitamu_end
3318 $formtag .= __('State','usces') . " : " . $values['pref'] . "\r\n";
3319 $formtag .= __('City','usces') . " : " . $values['address1'] . "\r\n";
3320 $formtag .= __('Address','usces') . " : " . $values['address2'] . " " . $values['address3'] . "\r\n";
3321 $formtag .= __('Zip/Postal Code','usces') . " : " . $values['zipcode'] . "\r\n";
3322 $formtag .= __('Phone number','usces') . " : " . $values['tel'] . "\r\n";
3323 $formtag .= __('FAX number','usces') . " : " . $values['fax'] . "\r\n";
3324 //20110118ysk start
3325 $formtag .= usces_mail_custom_field_info( $mode, 'fax_after', $order_id );
3326 //20110118ysk end
3327 break;
3328
3329 case 'US':
3330 default:
3331 //20110118ysk start
3332 $formtag .= usces_mail_custom_field_info( $mode, 'name_pre', $order_id );
3333 //20110118ysk end
3334 //20131129_kitamu_start
3335 if( $type == 'order_mail_customer' or $type == 'admin_mail_customer' ){
3336 $usces_order_table = $wpdb->prefix . "usces_order";
3337 $order_data = $wpdb->get_results( $wpdb->prepare("SELECT mem_id,order_email FROM $usces_order_table WHERE ID = %d LIMIT 1", $order_id ) );
3338 $mem_id = $order_data[0]->mem_id;
3339 $order_email = $order_data[0]->order_email;
3340
3341 $formtag .= ( !empty( $mem_id ) ) ? __( 'membership number', 'usces' ) . "\t\t: " . $mem_id . "\r\n" : '';
3342 $formtag .= ( !empty( $order_email ) ) ? __( 'e-mail adress', 'usces' ) . "\t\t: " . $order_email . "\r\n" : '';
3343 }
3344 //20131129_kitamu_end
3345 $formtag .= $name_label . " : " . sprintf(__('Mr/Mrs %s', 'usces'), ($values['name2'] . ' ' . $values['name1'])) . " \r\n";
3346 //20110118ysk start
3347 $formtag .= usces_mail_custom_field_info( $mode, 'name_after', $order_id );
3348 //20110118ysk end
3349 $formtag .= __('Address','usces') . " : " . $values['address2'] . " " . $values['address3'] . "\r\n";
3350 $formtag .= __('City','usces') . " : " . $values['address1'] . "\r\n";
3351 $formtag .= __('State','usces') . " : " . $values['pref'] . "\r\n";
3352
3353 //20131213_kitamu_start
3354 if( count( $options['system']['target_market'] ) != 1 ){
3355 $formtag .= __('Country','usces') . " : " . $usces_settings['country'][$values['country']] . "\r\n";
3356 }
3357 //20131213_kitamu_end
3358 $formtag .= __('Zip/Postal Code','usces') . " : " . $values['zipcode'] . "\r\n";
3359 $formtag .= __('Phone number','usces') . " : " . $values['tel'] . "\r\n";
3360 $formtag .= __('FAX number','usces') . " : " . $values['fax'] . "\r\n";
3361 //20110118ysk start
3362 $formtag .= usces_mail_custom_field_info( $mode, 'fax_after', $order_id );
3363 //20110118ysk end
3364 break;
3365 }
3366 $res = apply_filters('usces_filter_apply_mail_addressform', $formtag, $type, $data, $order_id);
3367
3368
3369 if($out == 'return') {
3370 return $res;
3371 } else {
3372 echo $res;
3373 }
3374 }
3375
3376 function uesces_get_target_market_form( $type, $selected, $out = 'return' ){
3377 global $usces_settings;
3378 $options = get_option('usces');
3379 $res = '<select name="' . $type . '[country]" id="' . $type . '_country">'."\n";
3380 foreach ( $usces_settings['country'] as $key => $value ){
3381 if( in_array($key, $options['system']['target_market']) )
3382 $res .= '<option value="' . $key . '"' . ($selected == $key ? ' selected="selected"' : '') . '>' . $value . "</option>\n";
3383 }
3384 $res .= '</select>'."\n";
3385
3386 if($out == 'return') {
3387 return $res;
3388 } else {
3389 echo $res;
3390 }
3391 }
3392
3393 function usces_pref_select( $type, $values, $out = 'return' ){
3394 global $usces, $usces_states;
3395
3396 //20110513ysk start
3397 //$country = empty($values['country']) ? usces_get_local_addressform() : $values['country'];
3398 $country = empty($values['country']) ? usces_get_base_country() : $values['country'];
3399 $options = get_option('usces');
3400 if( !in_array($country, $options['system']['target_market']) )
3401 $country = $options['system']['target_market'][0];
3402 //20110513ysk end
3403 //20110331ysk start
3404 //$prefs = $usces_states[$country];
3405 $prefs = get_usces_states($country);
3406 //20110331ysk end
3407 $html = '<select name="' . esc_attr($type . '[pref]') . '" id="' . esc_attr($type) . '_pref" class="pref">';
3408 //20120123ysk start 0000386
3409 //foreach((array)$prefs as $pref)
3410 // $html .= "\t".'<option value="' . esc_attr($pref) . '"' . ($pref == $values['pref'] ? ' selected="selected"' : '') . '>' . esc_html($pref) . "</option>\n";
3411 $prefs_count = count($prefs);
3412 if($prefs_count > 0) {
3413 $select = __('-- Select --', 'usces');
3414 $html .= "\t".'<option value="' . esc_attr($select) . '">' . esc_html($select) . "</option>\n";
3415 for($i = 1; $i < $prefs_count; $i++)
3416 $html .= "\t".'<option value="' . esc_attr($prefs[$i]) . '"' . ($prefs[$i] == $values['pref'] ? ' selected="selected"' : '') . '>' . esc_html($prefs[$i]) . "</option>\n";
3417 }
3418 //20120123ysk end
3419 $html .= "</select>\n";
3420
3421 if( $out == 'return' ){
3422 return $html;
3423 }else{
3424 echo $html;
3425 }
3426 }
3427
3428 function usces_is_member_system(){
3429 global $usces;
3430 if($usces->options['membersystem_state'] == 'activate')
3431 return true;
3432 else
3433 return false;
3434 }
3435
3436 function usces_is_member_system_point(){
3437 global $usces;
3438 if($usces->options['membersystem_point'] == 'activate')
3439 return true;
3440 else
3441 return false;
3442 }
3443
3444 function usces_shipping_country_option( $selected, $out = '' ){
3445 global $usces_settings;
3446 $options = get_option('usces');
3447 $res = '';
3448 foreach ( $usces_settings['country'] as $key => $value ){
3449 if( in_array($key, $options['system']['target_market']) )
3450 $res .= '<option value="' . $key . '"' . ($selected == $key ? ' selected="selected"' : '') . '>' . $value . "</option>\n";
3451 }
3452 //20110317ysk start
3453 //$res .= '<option value="world_wide"' . ($selected == $key ? ' selected="selected"' : '') . '>World Wide' . "</option>\n";
3454 //20110317ysk end
3455 echo $res;
3456 }
3457
3458 function usces_get_cart_button( $out = '' ) {
3459 global $usces;
3460 $res = '';
3461
3462 if($usces->use_js){
3463 $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;';
3464 if( usces_is_cart() ) {
3465 $res .= '<input name="customerinfo" type="submit" class="to_customerinfo_button" value="' . __(' Next ','usces') . '"' . apply_filters('usces_filter_cart_nextbutton', ' onclick="return uscesCart.cartNext();"') . ' />';
3466 }
3467 }else{
3468 $res .= '<a href="' . get_home_url() . '" class="continue_shopping_button">' . __('continue shopping','usces') . '</a>&nbsp;&nbsp;';
3469 if( usces_is_cart() ) {
3470 $res .= '<input name="customerinfo" type="submit" class="to_customerinfo_button" value="' . __(' Next ','usces') . '"' . apply_filters('usces_filter_cart_nextbutton', NULL) . ' />';
3471 }
3472 }
3473 $res = apply_filters('usces_filter_get_cart_button', $res);
3474
3475 if($out == 'return'){
3476 return $res;
3477 }else{
3478 echo $res;
3479 }
3480 }
3481
3482 function usces_get_customer_button( $out = '' ) {
3483 global $usces, $member_regmode;
3484 $res = '';
3485
3486 $res = '<input name="backCart" type="submit" class="back_cart_button" value="'.__('Back', 'usces').'" />&nbsp;&nbsp;';
3487
3488 $button = '<input name="deliveryinfo" type="submit" class="to_deliveryinfo_button" value="'.__(' Next ', 'usces').'" />&nbsp;&nbsp;';
3489 $res .= apply_filters('usces_filter_customer_button', $button);
3490
3491 if(usces_is_membersystem_state() && $member_regmode != 'editmemberfromcart' && usces_is_login() == false ){
3492 $res .= '<input name="reganddeliveryinfo" type="submit" class="to_reganddeliveryinfo_button" value="'.__('To the next while enrolling', 'usces').'"' . apply_filters('usces_filter_customerinfo_prebutton', NULL) . ' />';
3493 }elseif(usces_is_membersystem_state() && $member_regmode == 'editmemberfromcart' ){
3494 $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) . ' />';
3495 }
3496
3497 $res = apply_filters('usces_filter_get_customer_button', $res);
3498
3499 if($out == 'return'){
3500 return $res;
3501 }else{
3502 echo $res;
3503 }
3504 }
3505
3506 function usces_delivery_secure_form( $out = '' ) {
3507 global $usces, $usces_entries, $usces_carts;
3508 $html = '';
3509 include( USCES_PLUGIN_DIR . "/includes/delivery_secure_form.php");
3510
3511 if($out == 'return'){
3512 return $html;
3513 }else{
3514 echo $html;
3515 }
3516 }
3517
3518 function usces_delivery_info_script( $out ='' ){
3519 global $usces, $usces_entries, $usces_carts;
3520 $html = '';
3521 include( USCES_PLUGIN_DIR . "/includes/delivery_info_script.php");
3522
3523 if($out == 'return'){
3524 return $html;
3525 }else{
3526 echo $html;
3527 }
3528 }
3529
3530 function usces_get_entries(){
3531 global $usces, $usces_entries;
3532 $usces_entries = $usces->cart->get_entry();
3533 }
3534
3535 function usces_get_carts(){
3536 global $usces, $usces_carts;
3537 $usces_carts = $usces->cart->get_cart();
3538 }
3539
3540 function usces_get_members(){
3541 global $usces, $usces_members;
3542 $usces_members = $usces->get_member();
3543 }
3544
3545 function usces_error_message( $out = ''){
3546 global $usces;
3547
3548 if($out == 'return'){
3549 return $usces->error_message;
3550 }else{
3551 echo $usces->error_message;
3552 }
3553 }
3554
3555 function usces_url( $type, $out = ''){
3556 global $usces;
3557
3558 switch ( $type ){
3559 case 'cart':
3560 $url = USCES_CART_URL;
3561 break;
3562 case 'login':
3563 $url = USCES_LOGIN_URL;
3564 break;
3565 case 'member':
3566 $url = USCES_MEMBER_URL;
3567 break;
3568 case 'newmember':
3569 $url = USCES_NEWMEMBER_URL;
3570 break;
3571 case 'lostmemberpassword':
3572 $url = USCES_LOSTMEMBERPASSWORD_URL;
3573 break;
3574 case 'cartnonsession':
3575 $url = USCES_CART_NONSESSION_URL;
3576 break;
3577 }
3578
3579 if($out == 'return'){
3580 return $url;
3581 }else{
3582 echo $url;
3583 }
3584 }
3585
3586 function usces_total_price( $out = ''){
3587 global $usces;
3588
3589 if($out == 'return'){
3590 return $usces->get_total_price();
3591 }else{
3592 echo $usces->get_total_price();
3593 }
3594 }
3595
3596 function usces_completion_settlement( $out ='' ){
3597 global $usces, $usces_entries;
3598 $html = '';
3599
3600 $template = apply_filters( 'usces_filter_completion_settlement', USCES_PLUGIN_DIR . "/includes/completion_settlement.php", $usces_entries );
3601 require( $template );
3602
3603 if($out == 'return'){
3604 return $html;
3605 }else{
3606 echo $html;
3607 }
3608 }
3609
3610 function usces_purchase_button( $out ='' ){
3611 global $usces, $usces_entries;
3612 $html = '';
3613 include( USCES_PLUGIN_DIR . "/includes/purchase_button.php");
3614
3615 if($out == 'return'){
3616 return $html;
3617 }else{
3618 echo $html;
3619 }
3620 }
3621
3622 function usces_get_member_regmode(){
3623 global $member_regmode;
3624 $member_regmode = isset( $_SESSION['usces_entry']['member_regmode'] ) ? $_SESSION['usces_entry']['member_regmode'] : 'none';
3625 }
3626
3627 function uesces_get_error_settlement( $out = '' ) {
3628 $res = '';
3629 if( isset($_REQUEST['acting']) && ('zeus_conv' == $_REQUEST['acting'] || 'zeus_card' == $_REQUEST['acting'] || 'zeus_bank' == $_REQUEST['acting'] ) ){ //ZEUS
3630 $res .= '<div class="support_box">';
3631 if( isset($_GET['code']) ){
3632 $res .= ' <br />エラーコード:' . esc_html($_GET['code']);
3633 if( in_array($_GET['code'], array('02130514', '02130517', '02130619', '02130620', '02130621', '02130640')) ){
3634 $res .= '<br />カード番号が正しくないようです。';
3635 }elseif( in_array($_GET['code'], array('02130714', '02130717', '02130725', '02130814', '02130817', '02130825')) ){
3636 $res .= '<br />カードの有効期限が正しくないようです。';
3637 }elseif( in_array($_GET['code'], array('02130922')) ){
3638 $res .= '<br />カードの有効期限が切れているようです。';
3639 }elseif( in_array($_GET['code'], array('02131117', '02131123', '02131124')) ){
3640 $res .= '<br />カードの名義が正しくないようです。';
3641 }elseif( in_array($_GET['code'], array('02131414', '02131417', '02131437')) ){
3642 $res .= '<br />お客様�
3643 報の電話番号が正しくないようです。';
3644 }elseif( in_array($_GET['code'], array('02131527', '02131528', '02131529', '02131537')) ){
3645 $res .= '<br />お客様�
3646 報のEメールアドレスが正しくないようです。';
3647 }
3648 $res .= ' <br />
3649  <br />
3650 <a href="' . USCES_CUSTOMER_URL . '">もう一度決済を行う>></a><br />';
3651 }else{
3652 $res .= ' <br />エラーコード:' . esc_html($_GET['err_code']);
3653 $res .= ' <br />
3654 カード番号を再�
3655 �力する場合はこちらをクリックしてください。<br />
3656  <br />
3657 <a href="' . USCES_CUSTOMER_URL . '&re-enter=1">カード番号の再�
3658 �力>></a><br />';
3659 }
3660 $res .= ' <br />
3661 ゼウス・カスタマーサポート(24時間365日)<br />
3662 電話番号:0570-02-3939(つながらないときは 03-4334-0500)<br />
3663 E-mail:support@cardservice.co.jp
3664 </div>'."\n";
3665 }
3666 $res = apply_filters( 'usces_filter_get_error_settlement', $res );
3667
3668 if($out == 'return'){
3669 return $res;
3670 }else{
3671 echo $res;
3672 }
3673 }
3674
3675 function usces_page_name( $out = '') {
3676 global $usces;
3677 $page = '';
3678
3679 if( empty($usces->page) ){
3680 if( $usces->is_cart_page($_SERVER['REQUEST_URI']) ){
3681 $page = 'cart';
3682 }elseif( $usces->is_member_page($_SERVER['REQUEST_URI']) ){
3683 $page = 'member';
3684 }
3685 }else{
3686 $page = $usces->page;
3687 }
3688
3689 if($out == 'return'){
3690 return $page;
3691 }else{
3692 echo $page;
3693 }
3694 }
3695
3696 function usces_post_reg_orderdata($order_id, $results){
3697 global $usces, $wpdb;
3698 $acting = isset($_GET['acting']) ? $_GET['acting'] : '';
3699 $data = array();
3700
3701 if( $order_id ){
3702
3703 switch ( $acting ) {
3704 case 'epsilon':
3705 $trans_id = isset($_REQUEST['trans_code']) ? $_REQUEST['trans_code'] : '';
3706 break;
3707 case 'paypal_ipn':
3708 $trans_id = isset($_REQUEST['txn_id']) ? $_REQUEST['txn_id'] : '';
3709 break;
3710 case 'paypal':
3711 $trans_id = isset($results['txn_id']) ? $results['txn_id'] : '';
3712 break;
3713 //20110208ysk start
3714 case 'paypal_ec':
3715 $trans_id = isset($_REQUEST['token']) ? $_REQUEST['token'] : '';
3716 //20110621ysk start 0000184
3717 if(isset($results['settlement_id']))
3718 $usces->set_order_meta_value('settlement_id', $results['settlement_id'], $order_id);
3719 if(isset($results['profile_id']))
3720 $usces->set_order_meta_value('profile_id', $results['profile_id'], $order_id);
3721 //20110621ysk end
3722 break;
3723 //20110208ysk end
3724 case 'zeus_card':
3725 $acting_opts = $usces->options['acting_settings']['zeus'];
3726 if( isset($_GET['zeussuffix']) ){
3727 $entry = $usces->cart->get_entry();//20110621ysk 0000184
3728 $data['acting'] = 'zeus_card Secure API';
3729 $data['order_number'] = $_GET['zeusordd'];
3730 $data['howpay'] = $entry['order']['howpay'];
3731
3732 $usces->set_order_meta_value('acting_'.$acting, serialize($data), $order_id);
3733 if( $usces->is_member_logged_in() ){
3734 //if( 2 == $acting_opts['security'] && 'on' == $acting_opts['quickcharge']){
3735 if( 'on' == $acting_opts['quickcharge']){
3736 $usces->set_member_meta_value('zeus_pcid', '8888888888888888');
3737 }
3738 $usces->set_member_meta_value('zeus_partofcard', $_GET['zeussuffix']);
3739 $usces->set_member_meta_value('zeus_limitofcard', ($_GET['zeusyear'].'/'.$_GET['zeusmonth']));
3740 }
3741 }else{
3742 $trans_id = isset($_REQUEST['ordd']) ? $_REQUEST['ordd'] : '';
3743 //foreach($_GET as $key => $value) {
3744 // $data[$key] = esc_sql($value);
3745 //}
3746 //$usces->set_order_meta_value('acting_'.$acting, serialize($data), $order_id);
3747 if( !empty($_REQUEST['order_number']) ) {
3748 $usces->set_order_meta_value( 'order_number', $_REQUEST['order_number'], $order_id );
3749 }
3750 if( $usces->is_member_logged_in() ) {
3751 if( 'on' == $acting_opts['quickcharge'] ) {
3752 $usces->set_member_meta_value('zeus_pcid', '8888888888888888');
3753 }
3754 }
3755 }
3756 if(empty($usces)){
3757 usces_log('zeus card transaction : No Session', 'acting_transaction.log');
3758 }else{
3759 usces_log('zeus card transaction : OK', 'acting_transaction.log');
3760 }
3761 break;
3762 case 'zeus_conv':
3763 $trans_id = isset($_REQUEST['order_no']) ? $_REQUEST['sendpoint'] : '';
3764 $zeus_convs = array(
3765 'acting' => 'zeus_conv',
3766 'pay_cvs' => isset($_REQUEST['pay_cvs']) ? $_REQUEST['pay_cvs'] : '',
3767 'order_no' => isset($_REQUEST['order_no']) ? $_REQUEST['order_no'] : '',
3768 'money' => isset($_REQUEST['money']) ? $_REQUEST['money'] : '',
3769 'pay_no1' => isset($_REQUEST['pay_no1']) ? $_REQUEST['pay_no1'] : '',
3770 'pay_no2' => isset($_REQUEST['pay_no2']) ? $_REQUEST['pay_no2'] : '',
3771 'pay_limit' => isset($_REQUEST['pay_limit']) ? $_REQUEST['pay_limit'] : '',
3772 'status' => isset($_REQUEST['status']) ? $_REQUEST['status'] : '',
3773 'error_code' => isset($_REQUEST['error_code']) ? $_REQUEST['error_code'] : ''
3774 );
3775 $usces->set_order_meta_value('acting_'.(isset($_REQUEST['sendpoint']) ? $_REQUEST['sendpoint'] : ''), serialize($zeus_convs), $order_id);
3776 break;
3777 case 'zeus_bank':
3778 $trans_id = isset($_REQUEST['order_no']) ? $_REQUEST['order_no'] : '';
3779 break;
3780 case 'remise_card':
3781 $trans_id = isset($_REQUEST['X-TRANID']) ? $_REQUEST['X-TRANID'] : '';
3782 break;
3783 case 'remise_conv':
3784 $trans_id = isset($_REQUEST['X-JOB_ID']) ? $_REQUEST['X-JOB_ID'] : '';
3785 break;
3786 case 'jpayment_card':
3787 case 'jpayment_conv':
3788 case 'jpayment_bank':
3789 $trans_id = isset($_REQUEST['gid']) ? $_REQUEST['gid'] : '';
3790 break;
3791 //20120413ysk start
3792 case 'sbps_card':
3793 case 'sbps_conv':
3794 case 'sbps_payeasy':
3795 case 'sbps_wallet':
3796 case 'sbps_mobile':
3797 $trans_id = isset($_REQUEST['order_id']) ? $_REQUEST['order_id'] : '';
3798 break;
3799 //20120413ysk end
3800 //20120618ysk start
3801 case 'telecom_card':
3802 $trans_id = isset($_REQUEST['sendid']) ? $_REQUEST['sendid'] : '';
3803 break;
3804 //20120618ysk end
3805 //20121206ysk start
3806 case 'digitalcheck_card':
3807 case 'digitalcheck_conv':
3808 $trans_id = isset($_REQUEST['SID']) ? $_REQUEST['SID'] : '';
3809 break;
3810 //20121206ysk end
3811 //20130225ysk start
3812 case 'mizuho_card':
3813 case 'mizuho_conv':
3814 $trans_id = isset($_REQUEST['stran']) ? $_REQUEST['stran'] : '';
3815 break;
3816 //20130225ysk end
3817 default:
3818 if( isset($_REQUEST['FUKA']) && strstr($_REQUEST['FUKA'], "digitalcheck_card") ) {
3819 $trans_id = isset($_REQUEST['SID']) ? $_REQUEST['SID'] : '';
3820 } else {
3821 $trans_id = '';
3822 }
3823 }
3824
3825 if(!empty($trans_id)) {
3826 $usces->set_order_meta_value('trans_id', $trans_id, $order_id);
3827 }
3828 }
3829
3830 }
3831
3832 //20110621ysk start 0000184
3833 function usces_paypal_doecp( &$results ) {
3834 global $usces;
3835 $entry = $usces->cart->get_entry();
3836 $cart = $usces->cart->get_cart();
3837
3838 $post_id = $cart[0]['post_id'];
3839 $charging_type = $usces->getItemChargingType( $post_id );
3840 if( 'continue' != $charging_type ) {
3841 //通常購�
3842
3843 //Format the other parameters that were stored in the session from the previous calls
3844 $paymentAmount = usces_crform($entry['order']['total_full_price'], false, false, 'return', false);
3845 $token = urlencode($_REQUEST['token']);
3846 $paymentType = urlencode("Sale");
3847 $currencyCodeType = urlencode($usces->get_currency_code());
3848 $payerID = urlencode($_REQUEST['PayerID']);
3849 $serverName = urlencode($_SERVER['SERVER_NAME']);
3850
3851 $nvpstr = '&TOKEN='.$token.'&PAYERID='.$payerID.'&PAYMENTACTION='.$paymentType.'&AMT='.$paymentAmount.'&CURRENCYCODE='.$currencyCodeType.'&IPADDRESS='.$serverName;
3852 $nvpstr = apply_filters( 'usces_filter_usces_paypal_doecp', $nvpstr, $charging_type );
3853 //20131121ysk start 0000771
3854 if( 'shipped' == $usces->getItemDivision( $post_id ) ) {
3855 $country = ( !empty($entry['delivery']['country']) ) ? $entry['delivery']['country'] : usces_get_base_country();
3856 if( 'US' != $country and 'CA' != $country ) {//20140207ysk 0000771
3857 $nvpstr .= '&SHIPTONAME='.$entry['delivery']['name2'].' '.$entry['delivery']['name1'].
3858 '&SHIPTOSTREET='.$entry['delivery']['address2'].
3859 '&SHIPTOSTREET2='.$entry['delivery']['address3'].
3860 '&SHIPTOCITY='.$entry['delivery']['address1'].
3861 '&SHIPTOSTATE='.$entry['delivery']['pref'].
3862 '&SHIPTOZIP='.$entry['delivery']['zipcode'].
3863 '&SHIPTOCOUNTRYCODE='.$country.
3864 '&SHIPTOPHONENUM='.ltrim( str_replace( '-', '', $entry['delivery']['tel'] ), '0' );
3865 }
3866 }
3867 //20131121ysk end
3868 $usces->paypal->setMethod('DoExpressCheckoutPayment');
3869 $usces->paypal->setData($nvpstr);
3870 $res = $usces->paypal->doExpressCheckout();
3871 $resArray = $usces->paypal->getResponse();
3872 $ack = strtoupper($resArray["ACK"]);
3873 if( $ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING" ) {
3874 $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.
3875 //$usces->set_order_meta_value('settlement_id', $transactionId, $order_id);
3876 $results['settlement_id'] = $transactionId;
3877 $results['payment_status'] = isset( $resArray["PAYMENTSTATUS"] ) ? $resArray["PAYMENTSTATUS"] : '';
3878 $results['pending_reason'] = isset( $resArray["PENDINGREASON"] ) ? $resArray["PENDINGREASON"] : '';
3879
3880 } else {
3881 //Display a user friendly Error on the page using any of the following error information returned by PayPal
3882 $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
3883 $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
3884 $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
3885 $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
3886 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');
3887 return false;
3888 }
3889
3890 } else {
3891 if( !apply_filters( 'usces_pre_create_recurring_payments_profile', true ) ) return false;
3892
3893 //定期支払い
3894 $paymentAmount = usces_crform($entry['order']['total_full_price'], false, false, 'return', false);//20111129ysk 0000320
3895 $token = urlencode($_REQUEST['token']);
3896 $currencyCodeType = urlencode($usces->get_currency_code());
3897 //$nextdate = get_date_from_gmt(gmdate('Y-m-d H:i:s', time()));
3898 //$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';
3899 $profileStartDate = date('Y-m-d', dlseller_first_charging($post_id, 'time')).'T01:01:01Z';
3900 $billingPeriod = "Month";// or "Day", "Week", "SemiMonth", "Year"
3901 $billingFreq = $usces->getItemFrequency($post_id);
3902 $desc = urlencode(usces_make_agreement_description($cart, $entry['order']['total_full_price']));//20111125ysk 0000320
3903 $totalBillingCycles = (empty($dlitem['dlseller_interval'])) ? '' : '&TOTALBILLINGCYCLES='.urlencode($dlitem['dlseller_interval']);
3904 //$totalBillingCycles = ( dlseller_auto_stop() ) ? '&TOTALBILLINGCYCLES='.dlseller_cycles( $post_id ) : '';
3905
3906 //$nvpstr = '&TOKEN='.$token.'&AMT='.$paymentAmount.'&CURRENCYCODE='.$currencyCodeType.'&PROFILESTARTDATE='.$profileStartDate.'&BILLINGPERIOD='.$billingPeriod.'&BILLINGFREQUENCY='.$billingFreq.'&DESC='.$desc;
3907 $nvpstr = '&TOKEN='.$token.'&AMT='.$paymentAmount.'&CURRENCYCODE='.$currencyCodeType.'&PROFILESTARTDATE='.$profileStartDate.'&BILLINGPERIOD='.$billingPeriod.'&BILLINGFREQUENCY='.$billingFreq.'&DESC='.$desc.$totalBillingCycles;
3908 $nvpstr = apply_filters( 'usces_filter_usces_paypal_doecp', $nvpstr, $charging_type );
3909
3910 $usces->paypal->setMethod('CreateRecurringPaymentsProfile');
3911 $usces->paypal->setData($nvpstr);
3912 $res = $usces->paypal->doExpressCheckout();
3913 $resArray = $usces->paypal->getResponse();
3914 $ack = strtoupper($resArray["ACK"]);
3915 if( $ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING" ) {
3916 $profileid = $resArray["PROFILEID"];
3917 //$usces->set_order_meta_value('profile_id', $profileid, $order_id);
3918 $results['settlement_id'] = $profileid;
3919 $results['profile_id'] = $profileid;
3920 $results['profile_status'] = isset( $resArray["PROFILESTATUS"] ) ? $resArray["PROFILESTATUS"] : '';
3921
3922 } else {
3923 //Display a user friendly Error on the page using any of the following error information returned by PayPal
3924 $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
3925 $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
3926 $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
3927 $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
3928 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');
3929 return false;
3930 }
3931 }
3932
3933 return true;
3934 }
3935 //20110621ysk end
3936 //20110421ysk start
3937 function usces_make_agreement_description($cart, $amt) {
3938 global $usces;
3939
3940 $cart_row = $cart[0];
3941 $quantity = $cart_row['quantity'];
3942 $itemName = $usces->getItemName($cart_row['post_id']);
3943 //if(1 < count($cart)) $itemName .= ','.__('Others', 'usces');
3944 if(50 < mb_strlen($itemName)) $itemName = mb_substr($itemName, 0, 50).'...';
3945 $amt = usces_crform($amt, true, false, 'return', true);
3946 $desc = $itemName.' '.__('Quantity','usces').':'.$quantity.' '.$amt;
3947 return($desc);
3948 }
3949 //20110421ysk end
3950
3951 function usces_get_send_out_date(){
3952 global $usces;
3953
3954 $bus_day_arr = (isset($usces->options['business_days'])) ? $usces->options['business_days'] : false;
3955 list( $today_year, $today_month, $today_day, $hour, $minute, $second ) = preg_split( '([^0-9])', current_time('mysql') );
3956 if( !is_array($bus_day_arr) ){
3957 $today_bus_flag = 1;
3958 }else{
3959 $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;
3960 }
3961 // get the time limit addition
3962 $limit_hour = (!empty($usces->options['delivery_time_limit']['hour'])) ? $usces->options['delivery_time_limit']['hour'] : false;
3963 $limit_min = (!empty($usces->options['delivery_time_limit']['min'])) ? $usces->options['delivery_time_limit']['min'] : false;
3964
3965 if( false === $hour || false === $minute ){
3966 $time_limit_addition = false;
3967 }elseif( ($hour.':'.$minute.':'.$second) > ($limit_hour.':'.$limit_min.':00') ){
3968 $time_limit_addition = 1;
3969 }else{
3970 $time_limit_addition = 0;
3971 }
3972 // get the shipping indication in cart
3973 $cart = $usces->cart->get_cart();
3974 $shipping_indication = apply_filters('usces_filter_shipping_indication', $usces->options['usces_shipping_indication']);
3975 $shipping = 0;
3976 $indication_flag = true;
3977 for($i = 0; $i < count($cart); $i++) {
3978 $cart_row = $cart[$i];
3979 $post_id = $cart_row['post_id'];
3980 $itemShipping = (int)$usces->getItemShipping($post_id);
3981 if($itemShipping === 0 or $itemShipping === 9) {
3982 $indication_flag = false;
3983 break;
3984 }
3985 if($shipping < $itemShipping) $shipping = $itemShipping;
3986 }
3987 $indication_incart = ( $indication_flag ) ? $shipping_indication[$shipping] : false;
3988 // get the send out date
3989 $sendout_num = 0;
3990 if( $today_bus_flag ){
3991 if( $time_limit_addition ){
3992 $sendout_num += 1;
3993 }
3994 if( false !== $indication_incart ){
3995 $sendout_num += $indication_incart;
3996 }
3997 }else{
3998 if( false !== $indication_incart ){
3999 $sendout_num += $indication_incart;
4000 }
4001 }
4002 $holiday = 0;
4003 for( $i=0; $i<=$sendout_num; $i++ ){
4004 list($yyyy, $mm, $dd) = explode('-', date('Y-m-d', mktime(0,0,0,(int)$today_month,($today_day + $i),(int)$today_year)));
4005 if( isset($bus_day_arr[(int)$yyyy][(int)$mm][(int)$dd]) && !$bus_day_arr[(int)$yyyy][(int)$mm][(int)$dd] ){
4006 $holiday++;
4007 $sendout_num++;
4008 }
4009 if( 100 < $sendout_num ) break;
4010 }
4011 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)));
4012
4013 $res = array(
4014 'today_bus_flag' => $today_bus_flag,
4015 'time_limit_addition'=> $time_limit_addition,
4016 'indication_incart' => $indication_incart,
4017 'holiday' => $holiday,
4018 'sendout_num' => $sendout_num,
4019 'sendout_date' => array('year' => $send_y, 'month' => $send_m, 'day' => $send_d)
4020 );
4021 return $res;
4022 }
4023
4024 function usces_action_footer_comment(){
4025 echo "<!-- Welcart version : v".USCES_VERSION." -->\n";
4026 }
4027
4028 function usces_set_acting_notification_time( $key ){
4029 global $wpdb;
4030 $tableName = $wpdb->prefix . "usces_access";
4031 $query = $wpdb->prepare("SELECT ID FROM $tableName WHERE acc_type = %s AND acc_key = %s", 'notification_time', $key);
4032 $res = $wpdb->get_var( $query );
4033 if( $res )
4034 return;
4035
4036 $query = $wpdb->prepare("INSERT INTO $tableName (acc_key, acc_type, acc_num1) VALUES (%s, %s, %d)",
4037 $key, 'notification_time', time());
4038 $res = $wpdb->query( $query );
4039 }
4040
4041 function usces_check_notification_time( $key, $time ){
4042 global $wpdb;
4043 $tableName = $wpdb->prefix . "usces_access";
4044 $query = $wpdb->prepare("SELECT acc_num1 FROM $tableName WHERE acc_type = %s AND acc_key = %s", 'notification_time', $key);
4045 $res = $wpdb->get_var( $query );
4046 if( !$res )
4047 return false;
4048
4049 $past = time() - $res;
4050 if( $time > $past )
4051 return true;
4052 else
4053 return false;
4054 }
4055
4056 function usces_is_same_itemcode( $post_id, $item_code ){
4057 global $wpdb, $usces;
4058
4059 $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);
4060 $ids = $wpdb->get_col( $query );
4061 // usces_log('ids : '.print_r($query,true), 'acting_transaction.log');
4062 // usces_log('ids : '.print_r($ids,true), 'acting_transaction.log');
4063 if( !$ids ){
4064 return false;
4065 }
4066 $id_str = implode(',', $ids);
4067 $query = "SELECT ID FROM $wpdb->posts WHERE ID IN({$id_str}) AND post_status = 'publish'";
4068 $res = $wpdb->get_col( $query );
4069 // usces_log('res : '.print_r($res,true), 'acting_transaction.log');
4070 // usces_log('res : '.print_r($query,true), 'acting_transaction.log');
4071 if( !$res ){
4072 return false;
4073 }
4074
4075 return $res;
4076 }
4077
4078 function usces_update_sku( $post_id, $skucode, $fieldname, $value ){
4079 global $wpdb;
4080 $metas = usces_get_post_meta($post_id, '_isku_');
4081 if( ! $metas )
4082 return false;
4083
4084 $meta_id = '';
4085 foreach( $metas as $meta ){
4086 $sku = unserialize($meta['meta_value']);
4087 if( $skucode == $sku['code'] ){
4088 $meta_id = $meta['meta_id'];
4089 $sku[$fieldname] = $value;
4090 break;
4091 }
4092 }
4093 $serialized_values = serialize($sku);
4094 if( !empty($meta_id) ) $res = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = %s WHERE meta_id = %d", $serialized_values, $meta_id) );
4095 if( !$res ){
4096 return false;
4097 }else{
4098 return true;
4099 }
4100 }
4101
4102 function usces_get_items_skus() {
4103 global $wpdb, $usces;
4104 $res = array();
4105 $item_codes = array();
4106 $item_names = array();
4107 $status = array();
4108
4109 $query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts}
4110 WHERE post_mime_type = %s AND post_status = %s", 'item', 'publish');
4111 $IDs = $wpdb->get_col($query);
4112 if( !$IDs )
4113 return $res;
4114
4115 //wp_cache_set( 'item_ids', $IDs );
4116
4117 $key = 0;
4118 foreach((array)$IDs as $post_id){
4119 $item_codes[$post_id] = $usces->getItemCode($post_id);
4120 $item_names[$post_id] = $usces->getItemName($post_id);
4121
4122 //$skus = $usces->get_skus($post_id);
4123 $metas = usces_get_post_meta($post_id, '_isku_');
4124 foreach( (array)$metas as $mkey => $rows ){
4125 $metas[$mkey]['meta_value'] = unserialize($rows['meta_value']);
4126 $allmetas[] = $metas;
4127 // $sku_post_id[] = $post_id;
4128 // $sku_code[] = $values['code'];
4129 // $sku_stocknum[] = $values['stocknum'];
4130 $status[] = $metas[$mkey]['meta_value']['stock'];
4131 $key++;
4132 }
4133 //usces_log('implode : '.strlen(explode(',', $res)), 'acting_transaction.log');
4134 }
4135 // wp_cache_set( 'item_ids', $IDs );
4136 // wp_cache_set( 'item_codes', $item_codes );
4137 // wp_cache_set( 'item_names', $item_names );
4138 // wp_cache_set( 'sku_data', $res );
4139 // wp_cache_set( 'stock_ct', array_count_values($status) );
4140
4141 }
4142 function usces_get_non_zerostoc_items() {
4143 global $wpdb, $usces;
4144
4145 $query = $wpdb->prepare("SELECT ID, code.meta_value AS code, name.meta_value AS name FROM {$wpdb->posts}
4146 LEFT JOIN {$wpdb->postmeta} AS code ON ID = code.post_id AND '_itemCode' = code.meta_key
4147 LEFT JOIN {$wpdb->postmeta} AS name ON ID = name.post_id AND '_itemName' = name.meta_key
4148 LEFT JOIN {$wpdb->postmeta} AS sku ON ID = sku.post_id AND '_isku_' = sku.meta_key
4149 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)
4150 GROUP BY ID",
4151 'item', 'post', 'trush', '%"stocknum";i:0%', '%"stocknum";s:1:"0"%');
4152 $res = $wpdb->get_results($query, ARRAY_A);
4153
4154 return $res;
4155
4156 // $key = 0;
4157 // foreach((array)$items as $item){
4158 //// $ItemCode = $usces->getItemCode($item['ID']);
4159 //// $ItemName = $usces->getItemName($item['ID']);
4160 //
4161 // //$skus = $usces->get_skus($post_id);
4162 // $metas = usces_get_post_meta($item['ID'], '_isku_');
4163 // foreach( (array)$metas as $rows ){
4164 // $meta_value = unserialize($rows['meta_value']);
4165 // if( "" != $meta_value['stocknum'] && 0 === (int)$meta_value['stocknum'] ){
4166 // $res[$key]['ID'] = $item['ID'];
4167 // $res[$key]['code'] = $item['code'];
4168 // $res[$key]['name'] = $item['name'];
4169 // $res[$key]['sku'] = $meta_value['code'];
4170 // }
4171 // $key++;
4172 // }
4173 // }
4174 // return $res;
4175 }
4176 function usces_get_stocs() {
4177 global $wpdb, $usces;
4178 $status = array();
4179
4180 $query = $wpdb->prepare("SELECT m.meta_value FROM {$wpdb->posts} AS p
4181 LEFT JOIN {$wpdb->postmeta} AS m ON p.ID = m.post_id AND m.meta_key = %s
4182 WHERE post_mime_type = %s AND post_type = %s AND post_status <> %s"
4183 , '_isku_', 'item', 'post', 'trush');
4184 $values = $wpdb->get_col($query);
4185 if( !$values )
4186 return $status;
4187
4188 foreach((array)$values as $value){
4189 $meta_value = unserialize($value);
4190 $status[] = (string)$meta_value['stock'];
4191 }
4192 return array_count_values($status);
4193 }
4194
4195 function usces_get_deco_order_id( $order_id ) {
4196 global $usces;
4197
4198 $dec_order_id = $usces->get_order_meta_value( 'dec_order_id', $order_id);
4199 if( !$dec_order_id ){
4200 $dec_order_id = str_pad($order_id, $usces->options['system']['dec_orderID_digit'], "0", STR_PAD_LEFT);
4201 }
4202 return $dec_order_id;
4203 }
4204
4205 function usces_mail_line( $type, $email = '' ) {
4206 $line = '';
4207
4208 switch( $type ) {
4209 case 1:
4210 $line = "******************************************************************";
4211 break;
4212 case 2:
4213 $line = "------------------------------------------------------------------";
4214 break;
4215 case 3:
4216 $line = "==================================================================";
4217 break;
4218 }
4219
4220 $line = apply_filters( 'usces_filter_mail_line', $line, $type, $email );
4221
4222 return $line."\r\n";
4223 }
4224
4225 function usces_get_gp_price($post_id, $p, $quant){
4226 global $usces;
4227 $GpN1 = $usces->getItemGpNum1($post_id);
4228 $GpN2 = $usces->getItemGpNum2($post_id);
4229 $GpN3 = $usces->getItemGpNum3($post_id);
4230 $GpD1 = $usces->getItemGpDis1($post_id);
4231 $GpD2 = $usces->getItemGpDis2($post_id);
4232 $GpD3 = $usces->getItemGpDis3($post_id);
4233
4234 if( empty($GpN1) || empty($GpD1) ) {
4235
4236 $realprice = $p;
4237
4238 }else if( (!empty($GpN1) && !empty($GpD1)) && (empty($GpN2) || empty($GpD2)) ) {
4239
4240 if( $quant >= $GpN1 ) {
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 >= $GpN2 ) {
4249 $realprice = round($p * (100 - $GpD2) / 100);
4250 }else if( $quant >= $GpN1 && $quant < $GpN2 ) {
4251 $realprice = round($p * (100 - $GpD1) / 100);
4252 }else{
4253 $realprice = $p;
4254 }
4255
4256 }else if( (!empty($GpN1) && !empty($GpD1)) && (!empty($GpN2) && !empty($GpD2)) && (!empty($GpN3) && !empty($GpD3)) ) {
4257
4258 if( $quant >= $GpN3 ) {
4259 $realprice = round($p * (100 - $GpD3) / 100);
4260 }else if( $quant >= $GpN2 && $quant < $GpN3 ) {
4261 $realprice = round($p * (100 - $GpD2) / 100);
4262 }else if( $quant >= $GpN1 && $quant < $GpN2 ) {
4263 $realprice = round($p * (100 - $GpD1) / 100);
4264 }else{
4265 $realprice = $p;
4266 }
4267
4268 }else{
4269 $realprice = $p;
4270 }
4271
4272 $realprice = apply_filters('usces_filter_get_gp_price', $realprice, $post_id, $p, $quant);
4273 return $realprice;
4274 }
4275 //20120306ysk start 0000324
4276 function usces_is_complete_settlement( $payment_name, $status = '' ) {
4277 $complete = false;
4278 //20120919ysk start 0000573
4279 $options = get_option('usces');
4280 if( $options['point_assign'] == 0 ) {
4281 $complete = true;
4282 //20120919ysk end
4283 } else {
4284 $payments = usces_get_system_option( 'usces_payment_method', 'name' );
4285 if( isset($payments[$payment_name]['settlement']) ) {
4286 switch( $payments[$payment_name]['settlement'] ) {
4287 case 'acting':
4288 if( false !== strpos( $status, 'pending' ) ) break;
4289 case 'acting_zeus_card':
4290 case 'acting_remise_card':
4291 case 'acting_jpayment_card':
4292 case 'acting_paypal_ec':
4293 case 'acting_sbps_card':
4294 case 'acting_telecom_card':
4295 case 'acting_digitalcheck_card':
4296 case 'acting_mizuho_card':
4297 case 'acting_anotherlane_card':
4298 case 'acting_veritrans_card':
4299 case 'COD':
4300 $complete = true;
4301 }
4302 }
4303 }
4304 $complete = apply_filters( 'usces_filter_is_complete_settlement', $complete, $payment_name, $status );
4305 return $complete;
4306 }
4307
4308 function usces_action_acting_getpoint( $order_id, $add = true ) {
4309 global $usces, $wpdb;
4310
4311 if( !apply_filters( 'usces_action_acting_getpoint_switch', true, $order_id, $add) )
4312 return;
4313
4314 //20120919ysk start 0000573
4315 $options = get_option('usces');
4316 if( $options['point_assign'] != 0 ) {
4317 //20120919ysk end
4318 if( 'activate' == $usces->options['membersystem_state'] && 'activate' == $usces->options['membersystem_point'] ) {
4319 $table_name = $wpdb->prefix . "usces_order";
4320 $mquery = $wpdb->prepare("SELECT mem_id, order_getpoint FROM $table_name WHERE ID = %d", $order_id);
4321 $values = $wpdb->get_row( $mquery, ARRAY_A );
4322 $mem_id = $values['mem_id'];
4323 $getpoint = $values['order_getpoint'];
4324
4325 if( !empty($mem_id) && 0 < $getpoint ) {
4326 $calc = ($add) ? '+' : '-';
4327 $member_table_name = $wpdb->prefix . "usces_member";
4328 $mquery = $wpdb->prepare("UPDATE $member_table_name SET mem_point = (mem_point ".$calc." %d) WHERE ID = %d", $getpoint, $mem_id);
4329 $wpdb->query( $mquery );
4330
4331 if( !empty($_SESSION['usces_member']['point']) ) {
4332 $mquery = $wpdb->prepare("SELECT mem_point FROM $member_table_name WHERE ID = %d", $mem_id);
4333 $point = $wpdb->get_var( $mquery );
4334 $_SESSION['usces_member']['point'] = $point;
4335 }
4336 }
4337 }
4338 }
4339 do_action( 'usces_action_acting_getpoint', $order_id, $add );
4340 }
4341
4342 function usces_restore_point( $mem_id, $point ) {
4343 global $wpdb;
4344
4345 if( !apply_filters( 'usces_action_restore_point_switch', true, $mem_id, $point) )
4346 return;
4347
4348 $member_table_name = $wpdb->prefix . "usces_member";
4349 $query = $wpdb->prepare( "UPDATE $member_table_name SET mem_point = (mem_point - %d) WHERE ID = %d", $point, $mem_id );
4350 $wpdb->query( $query );
4351 }
4352 //20120306ysk end
4353 //20120413ysk start
4354 function usces_set_free_csv( $customer ){
4355 $free_csv = "";
4356 if( !WCUtils::is_blank($customer['name1']) ) {
4357 $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'];
4358 $free_csv = base64_encode( $free_csv );
4359 }
4360 return $free_csv;
4361 }
4362 //20120413ysk end
4363
4364 function usces_get_itemopt_filed($post_id, $sku, $opt){
4365 global $usces;
4366 $sku = urlencode($sku);
4367 $optcode = urlencode($opt['name']);
4368 $name = $opt['name'];
4369 $means = (int)$opt['means'];
4370 $essential = (int)$opt['essential'];
4371 $session_value = isset( $_SESSION['usces_singleitem']['itemOption'][$post_id][$sku][$optcode] ) ? $_SESSION['usces_singleitem']['itemOption'][$post_id][$sku][$optcode] : NULL;
4372
4373 $html = '';
4374 switch($means) {
4375 case 0://Single-select
4376 case 1://Multi-select
4377 $selects = explode("\n", $opt['value']);
4378 $multiple = ($means === 0) ? '' : ' multiple';
4379 $multiple_array = ($means == 0) ? '' : '[]';
4380 $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";
4381 if($essential == 1){
4382 if( '#NONE#' == $session_value || NULL == $session_value )
4383 $selected = ' selected="selected"';
4384 else
4385 $selected = '';
4386 $html .= "\t<option value='#NONE#'{$selected}>" . __('Choose','usces') . "</option>\n";
4387 }
4388 $i=0;
4389 foreach($selects as $v) {
4390 if( ($i == 0 && $essential == 0 && NULL == $session_value) || esc_attr($v) == $session_value )
4391 $selected = ' selected="selected"';
4392 else
4393 $selected = '';
4394 $html .= "\t<option value='" . esc_attr($v) . "'{$selected}>" . esc_html($v) . "</option>\n";
4395 $i++;
4396 }
4397 $html .= "</select>\n";
4398 break;
4399 case 2://Text
4400 $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";
4401 break;
4402 case 5://Text-area
4403 $html .= "\n<textarea name='itemOption[{$post_id}][{$sku}][{$optcode}]' id='itemOption[{$post_id}][{$sku}][{$optcode}]' class='iopt_textarea'>" . esc_attr($session_value) . "</textarea>\n";
4404 break;
4405 }
4406
4407 $html = apply_filters('usces_get_itemopt_filed', $html, $post_id, $sku, $opt);
4408
4409 return $html;
4410 }
4411
4412 function usces_delete_order_check( $order_id ) {
4413 $res = apply_filters( 'usces_filter_delete_order_check', true, $order_id );
4414 return $res;
4415 }
4416
4417 function usces_itempage_admin_bar() {
4418 global $wp_admin_bar, $post;
4419 if( is_single() && usces_is_item() ){
4420 $wp_admin_bar->remove_menu('edit');
4421 $ref = urlencode(site_url() . '/wp-admin/admin.php?page=usces_itemedit');
4422 $wp_admin_bar->add_menu( array(
4423 'id' => 'edit',
4424 'title' => __('Edit item', 'usces'),
4425 'href' => site_url() . '/wp-admin/admin.php?page=usces_itemedit&action=edit&post=' . $post->ID . '&usces_referer=' . $ref
4426 ) );
4427 }
4428 }
4429
4430 function usces_rand( $digit = 10 ) {
4431 $num = str_repeat( "9", $digit );
4432 $rand = apply_filters( 'usces_filter_rand_value', sprintf( '%0'.$digit.'d', mt_rand( 1, (int)$num ) ), $num );
4433 return $rand;
4434 }
4435
4436 function usces_get_cr_symbol() {
4437 global $usces, $usces_settings;
4438 $cr = $usces->options['system']['currency'];
4439 list( $code, $decimal, $point, $seperator, $symbol ) = $usces_settings['currency'][$cr];
4440 return $symbol;
4441 }
4442
4443 ?>