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

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