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

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