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

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