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

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

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