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

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

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