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

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