PluginProbe
Welcart e-Commerce / 1.3.4
Welcart e-Commerce v1.3.4
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 / classes / usceshop.class.php

usceshop.class.php in Welcart e-Commerce 1.3.4, at classes/usceshop.class.php

7,993 lines 310.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 class usc_e_shop
3 {
4
5 var $page; //page action
6 var $cart; //cart object
7 var $use_ssl; //ssl flag
8 var $action, $action_status, $error_status;
9 var $action_message, $error_message;
10 var $itemskus, $itemsku, $itemopts, $itemopt, $item;
11 var $zaiko_status, $payment_structure, $display_mode, $shipping_rule;
12 var $member_status;
13 var $options, $mail_para;
14 var $login_mail, $current_member, $member_form;
15 var $payment_results, $log_flg, $delim, $use_js;
16
17 function usc_e_shop()
18 {
19 //20110331ysk start
20 //global $post, $usces_settings;
21 global $post, $usces_settings, $usces_states;
22 //20110331ysk end
23 do_action('usces_construct');
24 add_action('after_setup_theme', array(&$this, 'usces_session_start'));
25
26 if ( is_admin() ){
27 clean_term_cache( get_option('usces_item_cat_parent_id'), 'category' );
28 }
29
30 $locales = usces_locales();
31 foreach($locales as $l){
32 $usces_settings['language'][$l] = $l;
33 }
34 $usces_settings['language']['others'] = __('Follow config.php', 'usces');
35
36 $this->options = get_option('usces');
37 if(!isset($this->options['smtp_hostname']) || empty($this->options['smtp_hostname'])){ $this->options['smtp_hostname'] = 'localhost';}
38 if(!isset($this->options['delivery_method']) || !is_array($this->options['delivery_method'])) $this->options['delivery_method'] = array();
39 if(!isset($this->options['shipping_charge']) || !is_array($this->options['shipping_charge'])) $this->options['shipping_charge'] = array();
40 if(!isset($this->options['membersystem_state'])) $this->options['membersystem_state'] = 'activate';
41 if(!isset($this->options['membersystem_point'])) $this->options['membersystem_point'] = 'activate';
42 if(!isset($this->options['use_ssl'])) $this->options['use_ssl'] = 0;
43 if(!isset($this->options['point_coverage'])) $this->options['point_coverage'] = 0;
44 if(!isset($this->options['use_javascript'])) $this->options['use_javascript'] = 1;
45 if(!isset($this->options['privilege_discount'])) $this->options['privilege_discount'] = '';
46 if(!isset($this->options['privilege_point'])) $this->options['privilege_point'] = '';
47 if(!isset($this->options['campaign_privilege'])) $this->options['campaign_privilege'] = '';
48 if(!isset($this->options['campaign_category'])) $this->options['campaign_category'] = 0;
49 if(!isset($this->options['campaign_schedule']['start'])) $this->options['campaign_schedule']['start'] = array();
50 if(!isset($this->options['campaign_schedule']['end'])) $this->options['campaign_schedule']['end'] = array();
51 if(!isset($this->options['acting_settings']['paypal']['ec_activate'])) $this->options['acting_settings']['paypal']['ec_activate'] = '';
52 if(!isset($this->options['purchase_limit'])) $this->options['purchase_limit'] = '';
53 if(!isset($this->options['point_rate'])) $this->options['point_rate'] = '';
54 if(!isset($this->options['shipping_rule'])) $this->options['shipping_rule'] = '';
55 if(!isset($this->options['company_name'])) $this->options['company_name'] = '';
56 if(!isset($this->options['address1'])) $this->options['address1'] = '';
57 if(!isset($this->options['address2'])) $this->options['address2'] = '';
58 if(!isset($this->options['zip_code'])) $this->options['zip_code'] = '';
59 if(!isset($this->options['tel_number'])) $this->options['tel_number'] = '';
60 if(!isset($this->options['fax_number'])) $this->options['fax_number'] = '';
61 if(!isset($this->options['order_mail'])) $this->options['order_mail'] = '';
62 if(!isset($this->options['inquiry_mail'])) $this->options['inquiry_mail'] = '';
63 if(!isset($this->options['sender_mail'])) $this->options['sender_mail'] = '';
64 if(!isset($this->options['error_mail'])) $this->options['error_mail'] = '';
65 if(!isset($this->options['copyright'])) $this->options['copyright'] = '';
66 if(!isset($this->options['postage_privilege'])) $this->options['postage_privilege'] = '';
67 if(!isset($this->options['shipping_rule'])) $this->options['shipping_rule'] = '';
68 if(!isset($this->options['tax_rate'])) $this->options['tax_rate'] = '';
69 if(!isset($this->options['tax_method'])) $this->options['tax_method'] = 'cutting';
70 if(!isset($this->options['transferee'])) $this->options['transferee'] = '';
71 if(!isset($this->options['membersystem_state'])) $this->options['membersystem_state'] = 'activate';
72 if(!isset($this->options['membersystem_point'])) $this->options['membersystem_point'] = '';
73 if(!isset($this->options['point_rate'])) $this->options['point_rate'] = '';
74 if(!isset($this->options['start_point'])) $this->options['start_point'] = '';
75 if(!isset($this->options['point_coverage'])) $this->options['point_coverage'] = 1;
76 if(!isset($this->options['point_assign'])) $this->options['point_assign'] = 1;//20120919ysk 0000573
77 if(!isset($this->options['cod_type'])) $this->options['cod_type'] = 'fix';
78 if(!isset($this->options['newmem_admin_mail'])) $this->options['newmem_admin_mail'] = 0;
79 if(!isset($this->options['delmem_admin_mail'])) $this->options['delmem_admin_mail'] = 1;
80 if(!isset($this->options['delmem_customer_mail'])) $this->options['delmem_customer_mail'] = 1;
81 if(!isset($this->options['mail_data']['title'])) $this->options['mail_data']['title'] = array('thankyou'=>'','order'=>'','inquiry'=>'','returninq'=>'','membercomp'=>'','completionmail'=>'', 'ordermail'=>'','changemail'=>'','receiptmail'=>'','mitumorimail'=>'','cancelmail'=>'','othermail'=>'');
82 if(!isset($this->options['mail_data']['header'])) $this->options['mail_data']['header'] = array('thankyou'=>'','order'=>'','inquiry'=>'','returninq'=>'','membercomp'=>'','completionmail'=>'', 'ordermail'=>'','changemail'=>'','receiptmail'=>'','mitumorimail'=>'','cancelmail'=>'','othermail'=>'');
83 if(!isset($this->options['mail_data']['footer'])) $this->options['mail_data']['footer'] = array('thankyou'=>'','order'=>'','inquiry'=>'','returninq'=>'','membercomp'=>'','completionmail'=>'', 'ordermail'=>'','changemail'=>'','receiptmail'=>'','mitumorimail'=>'','cancelmail'=>'','othermail'=>'');
84 if(!isset($this->options['cart_page_data']['header'])) $this->options['cart_page_data']['header'] = array('cart'=>'','customer'=>'','delivery'=>'','confirm'=>'','completion'=>'');
85 if(!isset($this->options['cart_page_data']['footer'])) $this->options['cart_page_data']['footer'] = array('cart'=>'','customer'=>'','delivery'=>'','confirm'=>'','completion'=>'');
86 if(!isset($this->options['member_page_data']['header'])) $this->options['member_page_data']['header'] = array('login'=>'','newmember'=>'','newpass'=>'','changepass'=>'','memberinfo'=>'','completion'=>'');
87 if(!isset($this->options['member_page_data']['footer'])) $this->options['member_page_data']['footer'] = array('login'=>'','newmember'=>'','newpass'=>'','changepass'=>'','memberinfo'=>'','completion'=>'');
88
89 if(!isset($this->options['shortest_delivery_time'])) $this->options['shortest_delivery_time'] = '0';
90 if(!isset($this->options['delivery_after_days'])) $this->options['delivery_after_days'] = 15;
91 if(!isset($this->options['delivery_days'])) $this->options['delivery_days'] = array();
92 if(!isset($this->options['delivery_time_limit']['hour'])) $this->options['delivery_time_limit']['hour'] = '00';
93 if(!isset($this->options['delivery_time_limit']['min'])) $this->options['delivery_time_limit']['min'] = '00';
94
95 if(!isset($this->options['divide_item'])) $this->options['divide_item'] = 0;
96 if(!isset($this->options['itemimg_anchor_rel'])) $this->options['itemimg_anchor_rel'] = '';
97 if(!isset($this->options['fukugo_category_orderby'])) $this->options['fukugo_category_orderby'] = 'ID';
98 if(!isset($this->options['fukugo_category_order'])) $this->options['fukugo_category_order'] = 'ASC';
99 if(!isset($this->options['settlement_path'])) $this->options['settlement_path'] = USCES_PLUGIN_DIR . '/settlement/';
100 if(!isset($this->options['use_ssl'])) $this->options['use_ssl'] = 0;
101 if(!isset($this->options['ssl_url'])) $this->options['ssl_url'] = '';
102 if(!isset($this->options['ssl_url_admin'])) $this->options['ssl_url_admin'] = '';
103 if(!isset($this->options['inquiry_id'])) $this->options['inquiry_id'] = '';
104 if(!isset($this->options['system']['orderby_itemsku'])) $this->options['system']['orderby_itemsku'] = 0;
105 if(!isset($this->options['system']['orderby_itemopt'])) $this->options['system']['orderby_itemopt'] = 0;
106 if(!isset($this->options['system']['front_lang'])) $this->options['system']['front_lang'] = usces_get_local_language();
107 if(!isset($this->options['system']['currency'])) $this->options['system']['currency'] = usces_get_base_country();
108 if(!isset($this->options['system']['addressform'])) $this->options['system']['addressform'] = usces_get_local_addressform();
109 if(!isset($this->options['system']['target_market'])) $this->options['system']['target_market'] = usces_get_local_target_market();
110 if(!isset($this->options['system']['no_cart_css'])) $this->options['system']['no_cart_css'] = 0;
111 if(!isset($this->options['system']['dec_orderID_flag'])) $this->options['system']['dec_orderID_flag'] = 0;
112 if(!isset($this->options['system']['dec_orderID_prefix'])) $this->options['system']['dec_orderID_prefix'] = '';
113 if(!isset($this->options['system']['dec_orderID_digit'])) $this->options['system']['dec_orderID_digit'] = 6;
114 if(!isset($this->options['system']['subimage_rule'])) $this->options['system']['subimage_rule'] = 0;
115
116 if(!isset($this->options['acting_settings']['zeus'])) $this->options['acting_settings']['zeus'] = array('activate'=>'','card_activate'=>'','clientip'=>'','authkey'=>'','connection'=>'','3dsecure'=>'','security'=>'','quickcharge'=>'', 'howpay'=>'','bank_activate'=>'','clientip_bank'=>'','testid_bank'=>'','conv_activate'=>'','clientip_conv'=>'','testid_conv'=>'','test_type_conv'=>'');
117 if(!isset($this->options['acting_settings']['zeus']['connection'])) $this->options['acting_settings']['zeus']['connection'] = '1';
118 if(!isset($this->options['acting_settings']['zeus']['3dsecur'])) $this->options['acting_settings']['zeus']['3dsecur'] = '2';
119 if(!isset($this->options['acting_settings']['zeus']['security'])) $this->options['acting_settings']['zeus']['security'] = '2';
120 if(!isset($this->options['acting_settings']['remise'])) $this->options['acting_settings']['remise'] = array('activate'=>'','plan'=>'','SHOPCO'=>'','HOSTID'=>'','card_activate'=>'','card_jb'=>'', 'payquick'=>'','howpay'=>'','continuation'=>'','card_pc_ope'=>'','send_url_pc'=>'','conv_activate'=>'','S_PAYDATE'=>'','conv_pc_ope'=>'','send_url_cvs_pc'=>'');
121 if(!isset($this->options['acting_settings']['jpayment'])) $this->options['acting_settings']['jpayment'] = array('activate'=>'','aid'=>'','card_activate'=>'','card_jb'=>'','conv_activate'=>'','webm_activate'=>'', 'bitc_activate'=>'','suica_activate'=>'','bank_activate'=>'');
122 if(!isset($this->options['acting_settings']['paypal'])) $this->options['acting_settings']['paypal'] = array('activate'=>'','ec_activate'=>'','sandbox'=>'','user'=>'','pwd'=>'','signature'=>'', 'continuation'=>'');
123
124 //20010420ysk start
125 //if(!isset($this->options['system']['base_country'])) $this->options['system']['base_country'] = usces_get_base_country();
126 $this->options['system']['base_country'] = usces_get_base_country();
127 //20010420ysk end
128 //20110331ysk start
129 if(!isset($this->options['province'])) $this->options['province'][$this->options['system']['base_country']] = $usces_states[$this->options['system']['base_country']];
130 //20110331ysk end
131 if(!isset($this->options['system']['pointreduction'])) $this->options['system']['pointreduction'] = usces_get_pointreduction($this->options['system']['currency']);
132 if(!isset($this->options['indi_item_name'])){
133 $this->options['indi_item_name']['item_name'] = 1;
134 $this->options['indi_item_name']['item_code'] = 1;
135 $this->options['indi_item_name']['sku_name'] = 1;
136 $this->options['indi_item_name']['sku_code'] = 1;
137 $this->options['pos_item_name']['item_name'] = 1;
138 $this->options['pos_item_name']['item_code'] = 2;
139 $this->options['pos_item_name']['sku_name'] = 3;
140 $this->options['pos_item_name']['sku_code'] = 4;
141 }
142 update_option('usces', $this->options);
143
144 $this->check_display_mode();
145 $this->error_message = '';
146 $this->login_mail = '';
147 $this->get_current_member();
148 $this->page = '';
149 $this->payment_results = array();
150 $this->use_js = $this->options['use_javascript'];
151
152 //admin_ssl options
153 // $this->use_ssl = get_option("admin_ssl_use_ssl") === "1" ? true : false;
154 // $use_shared = get_option("admin_ssl_use_shared") === "1" && $this->use_ssl ? true : false;
155 // $shared_url = get_option("admin_ssl_shared_url");
156
157 $this->use_ssl = $this->options['use_ssl'];
158 // if ( $use_shared ) {
159 // $ssl_url = str_replace('/wp-admin/', '', $shared_url);
160 // } else {
161 // $ssl_url = str_replace('http://', 'https://', get_option('home'));
162 // }
163 define('USCES_CART_NUMBER', get_option('usces_cart_number'));
164 define('USCES_MEMBER_NUMBER', get_option('usces_member_number'));
165
166 if ( $this->use_ssl ) {
167 $ssl_url = $this->options['ssl_url'];
168 $ssl_url_admin = $this->options['ssl_url_admin'];
169 if( $this->is_cart_or_member_page($_SERVER['REQUEST_URI']) || $this->is_inquiry_page($_SERVER['REQUEST_URI']) ){
170 define('USCES_FRONT_PLUGIN_URL', $ssl_url_admin . '/wp-content/plugins/' . USCES_PLUGIN_FOLDER);
171 define('USCES_COOKIEPATH', preg_replace('|https?://[^/]+|i', '', $ssl_url . '/' ) );
172 }else{
173 define('USCES_FRONT_PLUGIN_URL', USCES_WP_CONTENT_URL . '/plugins/' . USCES_PLUGIN_FOLDER);
174 define('USCES_COOKIEPATH', COOKIEPATH);
175 }
176 define('USCES_SSL_URL', $ssl_url);
177 define('USCES_SSL_URL_ADMIN', $ssl_url_admin);
178 }else{
179 define('USCES_FRONT_PLUGIN_URL', USCES_WP_CONTENT_URL . '/plugins/' . USCES_PLUGIN_FOLDER);
180 define('USCES_SSL_URL', get_option('home'));
181 define('USCES_SSL_URL_ADMIN', get_option('siteurl'));
182 define('USCES_COOKIEPATH', COOKIEPATH);
183 }
184 // if($this->use_ssl) {
185 // define('USCES_CART_URL', $ssl_url . '/?page_id=' . USCES_CART_NUMBER . '&usces=' . $this->get_uscesid());
186 // define('USCES_MEMBER_URL', $ssl_url . '/?page_id=' . USCES_MEMBER_NUMBER . '&usces=' . $this->get_uscesid());
187 // define('USCES_INQUIRY_URL', $ssl_url . '/?page_id=' . $this->options['inquiry_id'] . '&usces=' . $this->get_uscesid());
188 // add_filter('home_url', array($this, 'usces_ssl_page_link'));
189 // add_filter('wp_get_attachment_url', array($this, 'usces_ssl_attachment_link'));
190 // add_filter('stylesheet_directory_uri', array($this, 'usces_ssl_contents_link'));
191 // add_filter('template_directory_uri', array($this, 'usces_ssl_contents_link'));
192 // add_filter('script_loader_src', array($this, 'usces_ssl_script_link'));
193 // add_filter('style_loader_src', array($this, 'usces_ssl_script_link'));
194 // } else {
195 // define('USCES_CART_URL', get_option('home') . '/?page_id=' . USCES_CART_NUMBER);
196 // define('USCES_MEMBER_URL', get_option('home') . '/?page_id=' . USCES_MEMBER_NUMBER);
197 // define('USCES_INQUIRY_URL', get_option('home') . '/?page_id=' . $this->options['inquiry_id']);
198 // }
199 define('USCES_ITEM_CAT_PARENT_ID', get_option('usces_item_cat_parent_id'));
200
201 $this->zaiko_status = get_option('usces_zaiko_status');
202 $this->member_status = get_option('usces_customer_status');
203 $this->payment_structure = get_option('usces_payment_structure');
204 $this->display_mode = get_option('usces_display_mode');
205 define('USCES_MYSQL_VERSION', (int)substr(mysql_get_server_info(), 0, 1));
206 define('USCES_JP', ('ja' === get_locale() ? true : false));
207
208 }
209
210 function get_default_post_to_edit30( $post_type = 'post', $create_in_db = false ) {
211 global $wpdb;
212
213 $post_title = '';
214 if ( !empty( $_REQUEST['post_title'] ) )
215 $post_title = esc_html( stripslashes( $_REQUEST['post_title'] ));
216
217 $post_content = '';
218 if ( !empty( $_REQUEST['content'] ) )
219 $post_content = esc_html( stripslashes( $_REQUEST['content'] ));
220
221 $post_excerpt = '';
222 if ( !empty( $_REQUEST['excerpt'] ) )
223 $post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ));
224
225 if ( $create_in_db ) {
226 // Cleanup old auto-drafts more than 7 days old
227 $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" );
228 foreach ( (array) $old_posts as $delete )
229 wp_delete_post( $delete, true ); // Force delete
230 $post = get_post( wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) ) );
231 } else {
232 $post->ID = 0;
233 $post->post_author = '';
234 $post->post_date = '';
235 $post->post_date_gmt = '';
236 $post->post_password = '';
237 $post->post_type = $post_type;
238 $post->post_status = 'draft';
239 $post->to_ping = '';
240 $post->pinged = '';
241 $post->comment_status = get_option( 'default_comment_status' );
242 $post->ping_status = get_option( 'default_ping_status' );
243 $post->post_pingback = get_option( 'default_pingback_flag' );
244 $post->post_category = get_option( 'default_category' );
245 $post->page_template = 'default';
246 $post->post_parent = 0;
247 $post->menu_order = 0;
248 }
249
250 $post->post_content = apply_filters( 'default_content', $post_content, $post );
251 $post->post_title = apply_filters( 'default_title', $post_title, $post );
252 $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt, $post );
253 $post->post_name = '';
254
255 return $post;
256 }
257
258 function get_default_post_to_edit() {
259 global $post;
260
261 $post_title = '';
262 if ( !empty( $_REQUEST['post_title'] ) )
263 $post_title = esc_html( stripslashes( $_REQUEST['post_title'] ));
264
265 $post_content = '';
266 if ( !empty( $_REQUEST['content'] ) )
267 $post_content = esc_html( stripslashes( $_REQUEST['content'] ));
268
269 $post_excerpt = '';
270 if ( !empty( $_REQUEST['excerpt'] ) )
271 $post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ));
272
273 $post->ID = 0;
274 $post->post_name = '';
275 $post->post_author = '';
276 $post->post_date = '';
277 $post->post_date_gmt = '';
278 $post->post_password = '';
279 $post->post_status = 'draft';
280 $post->post_type = 'post';
281 $post->to_ping = '';
282 $post->pinged = '';
283 $post->comment_status = get_option( 'default_comment_status' );
284 $post->ping_status = get_option( 'default_ping_status' );
285 $post->post_pingback = get_option( 'default_pingback_flag' );
286 $post->post_category = get_option( 'default_category' );
287 $post->post_content = apply_filters( 'default_content', $post_content);
288 $post->post_title = apply_filters( 'default_title', $post_title );
289 $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt);
290 $post->page_template = 'default';
291 $post->post_parent = 0;
292 $post->menu_order = 0;
293
294 return $post;
295 }
296 function is_cart_or_member_page($link)
297 {
298 $search = array(('page_id='.USCES_CART_NUMBER), '/usces-cart', ('page_id='.USCES_MEMBER_NUMBER), '/usces-member');
299 $flag = false;
300 foreach($search as $value){
301 $parts = array();
302 if( false !== strpos($link, $value) ){
303 if( $value == ('page_id='.USCES_CART_NUMBER) || $value == ('page_id='.USCES_MEMBER_NUMBER) ){
304 $parts = parse_url($link);
305 parse_str($parts['query'], $query);
306 if( $query['page_id'] == USCES_CART_NUMBER || $query['page_id'] == USCES_MEMBER_NUMBER ){
307 $flag = true;
308 }
309 }else{
310 $flag = true;
311 }
312 }
313 }
314 return $flag;
315 }
316
317 function is_cart_page($link)
318 {
319 $search = array(('page_id='.USCES_CART_NUMBER), '/usces-cart' );
320 $flag = false;
321 foreach($search as $value){
322 if( false !== strpos($link, $value) ){
323 if( $value == ('page_id='.USCES_CART_NUMBER) ){
324 $parts = parse_url($link);
325 parse_str($parts['query'], $query);
326 if( $query['page_id'] == USCES_CART_NUMBER ){
327 $flag = true;
328 }
329 }else{
330 $flag = true;
331 }
332 }
333 }
334 return $flag;
335 }
336
337 function is_member_page($link)
338 {
339 $search = array(('page_id='.USCES_MEMBER_NUMBER), '/usces-member' );
340 $flag = false;
341 foreach($search as $value){
342 if( false !== strpos($link, $value) ){
343 if( $value == ('page_id='.USCES_MEMBER_NUMBER) ){
344 $parts = parse_url($link);
345 parse_str($parts['query'], $query);
346 if( $query['page_id'] == USCES_MEMBER_NUMBER ){
347 $flag = true;
348 }
349 }else{
350 $flag = true;
351 }
352 }
353 }
354 return $flag;
355 }
356
357 function is_inquiry_page($link)
358 {
359 if( empty($this->options['inquiry_id']) )
360 return false;
361
362 $search = array(('page_id='.$this->options['inquiry_id']), '/usces-inquiry' );
363 $flag = false;
364 foreach($search as $value){
365 if( false !== strpos($link, $value) ){
366 if( $value == ('page_id='.$this->options['inquiry_id']) ){
367 $parts = parse_url($link);
368 parse_str($parts['query'], $query);
369 if( $query['page_id'] == $this->options['inquiry_id'] ){
370 $flag = true;
371 }
372 }else{
373 $flag = true;
374 }
375 }
376 }
377 return $flag;
378 }
379
380 function usces_ssl_page_link($link)
381 {
382 $parts = parse_url($link);
383
384 if( isset($parts['query']) ){
385 parse_str($parts['query'], $query);
386 }
387
388 if( false !== strpos($link, '/usces-cart') || (isset( $query['page_id']) && $query['page_id'] == USCES_CART_NUMBER) ){
389 $link = USCES_CART_URL;
390
391 }elseif( false !== strpos($link, '/usces-member') || (isset( $query['page_id']) && $query['page_id'] == USCES_MEMBER_NUMBER) ){
392 $link = USCES_MEMBER_URL;
393
394 }elseif( !empty($this->options['inquiry_id']) && (false !== strpos($link, '/usces-inquiry') || (isset( $query['page_id']) && $query['page_id'] == $this->options['inquiry_id'])) ){
395 $link = USCES_INQUIRY_URL;
396
397 }else{
398 $link = str_replace('https://', 'http://', $link);
399 $link = apply_filters('usces_ssl_page_link', $link);
400 }
401
402 return $link;
403 }
404 function usces_ssl_contents_link($link)
405 {
406 if( $this->is_cart_or_member_page($_SERVER['REQUEST_URI']) || $this->is_inquiry_page($_SERVER['REQUEST_URI'])){
407 $req = explode('/wp-content/',$link);
408 $link = USCES_SSL_URL_ADMIN . '/wp-content/' . $req[1];
409 }else{
410 $link = apply_filters('usces_ssl_contents_link', $link);
411 }
412 return $link;
413 }
414
415 function ssl_admin_ajax_url(){
416 $path = '/wp-admin/admin-ajax.php';
417 if( $this->use_ssl && ($this->is_cart_or_member_page($_SERVER['REQUEST_URI']) || $this->is_inquiry_page($_SERVER['REQUEST_URI'])) ){
418 $link = USCES_SSL_URL_ADMIN . '/wp-admin/admin-ajax.php';
419 }else{
420 $link = site_url( $path );
421 }
422 $link = apply_filters('ssl_admin_ajax_url', $link);
423 return $link;
424 }
425
426 function usces_ssl_attachment_link($link)
427 {
428 if( $this->is_cart_or_member_page($_SERVER['REQUEST_URI']) || $this->is_inquiry_page($_SERVER['REQUEST_URI']) ){
429 $link = str_replace(get_option('siteurl'), USCES_SSL_URL_ADMIN, $link);
430 }else{
431 $link = apply_filters('usces_ssl_attachment_link', $link);
432 }
433 return $link;
434 }
435
436 function usces_ssl_icon_dir_uri($uri)
437 {
438 if( $this->is_cart_or_member_page($_SERVER['REQUEST_URI']) || $this->is_inquiry_page($_SERVER['REQUEST_URI']) ){
439 $uri = USCES_SSL_URL_ADMIN. '/' . WPINC . '/images/crystal';
440 }else{
441 $link = apply_filters('usces_ssl_icon_dir_uri', $uri);
442 }
443 return $uri;
444 }
445
446 function usces_ssl_script_link($link)
447 {
448 if( $this->is_cart_or_member_page($_SERVER['REQUEST_URI']) || $this->is_inquiry_page($_SERVER['REQUEST_URI']) ){
449 if(strpos($link, '/wp-content/') !== false){
450 $req = explode('/wp-content/',$link, 2);
451 $link = USCES_SSL_URL_ADMIN . '/wp-content/' . $req[1];
452 }else if(strpos($link, '/wp-includes/') !== false){
453 $req = explode('/wp-includes/',$link, 2);
454 $link = USCES_SSL_URL_ADMIN . '/wp-includes/' . $req[1];
455 }else if(strpos($link, '/wp-admin/') !== false){
456 $req = explode('/wp-admin/',$link, 2);
457 $link = USCES_SSL_URL_ADMIN . '/wp-admin/' . $req[1];
458 }
459 }else{
460 $link = apply_filters('usces_ssl_script_link', $link);
461 }
462 return $link;
463 }
464
465 function set_action_status($status, $message)
466 {
467 $this->action_status = $status;
468 $this->action_message = $message;
469 }
470
471
472 /******************************************************************************/
473 function add_pages() {
474
475
476 add_object_page('Welcart Shop', 'Welcart Shop', 'level_6', USCES_PLUGIN_BASENAME, array($this, 'admin_top_page'));
477 add_submenu_page(USCES_PLUGIN_BASENAME, __('Home','usces'), __('Home','usces'), 'level_6', USCES_PLUGIN_BASENAME, array($this, 'admin_top_page'));
478 add_submenu_page(USCES_PLUGIN_BASENAME, __('Master Items','usces'), __('Master Items','usces'), 'level_6', 'usces_itemedit', array($this, 'item_master_page'));
479 add_submenu_page(USCES_PLUGIN_BASENAME, __('Add New Item','usces'), __('Add New Item','usces'), 'level_6', 'usces_itemnew', array($this, 'item_master_page'));
480 add_submenu_page(USCES_PLUGIN_BASENAME, __('General Setting','usces'), __('General Setting','usces'), 'level_6', 'usces_initial', array($this, 'admin_setup_page'));
481 add_submenu_page(USCES_PLUGIN_BASENAME, __('Business Days Setting','usces'), __('Business Days Setting','usces'), 'level_6', 'usces_schedule', array($this, 'admin_schedule_page'));
482 add_submenu_page(USCES_PLUGIN_BASENAME, __('Shipping Setting','usces'), __('Shipping Setting','usces'), 'level_6', 'usces_delivery', array($this, 'admin_delivery_page'));
483 add_submenu_page(USCES_PLUGIN_BASENAME, __('E-mail Setting','usces'), __('E-mail Setting','usces'), 'level_6', 'usces_mail', array($this, 'admin_mail_page'));
484 add_submenu_page(USCES_PLUGIN_BASENAME, __('Cart Page Setting','usces'), __('Cart Page Setting','usces'), 'level_6', 'usces_cart', array($this, 'admin_cart_page'));
485 add_submenu_page(USCES_PLUGIN_BASENAME, __('Member Page Setting','usces'), __('Member Page Setting','usces'), 'level_6', 'usces_member', array($this, 'admin_member_page'));
486 add_submenu_page(USCES_PLUGIN_BASENAME, __('System Setting','usces'), __('System Setting','usces'), 'administrator', 'usces_system', array($this, 'admin_system_page'));
487 add_submenu_page(USCES_PLUGIN_BASENAME, __('Settlement Setting','usces'), __('Settlement Setting','usces'), 'administrator', 'usces_settlement', array($this, 'admin_settlement_page'));
488 //add_submenu_page(USCES_PLUGIN_BASENAME, __('Backup','usces'), __('Backup','usces'), 'level_6', 'usces_backup', array($this, 'admin_backup_page'));
489 do_action('usces_action_shop_admin_menue');
490
491 add_object_page('Welcart Management', 'Welcart Management', 'level_6', 'usces_orderlist', array($this, 'order_list_page'));
492 add_submenu_page('usces_orderlist', __('Order List','usces'), __('Order List','usces'), 'level_6', 'usces_orderlist', array($this, 'order_list_page'));
493 add_submenu_page('usces_orderlist', __('New Order or Estimate','usces'), __('New Order or Estimate','usces'), 'level_6', 'usces_ordernew', array($this, 'order_list_page'));
494 add_submenu_page('usces_orderlist', __('List of Members','usces'), __('List of Members','usces'), 'level_6', 'usces_memberlist', array($this, 'member_list_page'));
495 //add_submenu_page('usces_orderlist', __('New Member','usces'), __('New Member','usces'), 'level_6', 'usces_membernew', array($this, 'member_list_page'));
496 do_action('usces_action_management_admin_menue');
497 }
498
499
500 /* Item Master Page */
501 function item_master_page() {
502 global $wpdb, $wp_locale;
503 global $wp_query;
504
505 if(empty($this->action_message) || WCUtils::is_blank($this->action_message) ) {
506 $this->action_status = 'none';
507 $this->action_message = '';
508 }
509
510 if($_REQUEST['page'] == 'usces_itemnew'){
511 $action = 'new';
512 }else{
513 $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
514 }
515 do_action( 'usces_action_item_master_page', $action );
516 switch ( $action ) {
517 case 'dlitemlist':
518 usces_download_item_list();
519 break;
520 case 'upload_register':
521 require_once(USCES_PLUGIN_DIR . '/includes/usces_item_master_upload_register.php');
522 break;
523 case 'delete':
524 case 'new':
525 case 'editpost':
526 case 'edit':
527 global $current_user;
528 require_once(USCES_PLUGIN_DIR . '/includes/usces_item_master_edit.php');
529 break;
530 default:
531 require_once(USCES_PLUGIN_DIR . '/includes/usces_item_master_list.php');
532 break;
533 }
534 }
535
536 /* order list page */
537 function order_list_page() {
538 $order_edit_form = apply_filters( 'usces_admin_order_edit_form', USCES_PLUGIN_DIR . '/includes/order_edit_form.php' );
539 $order_list = apply_filters( 'usces_admin_order_list', USCES_PLUGIN_DIR . '/includes/order_list.php' );
540
541 if(empty($this->action_message) || WCUtils::is_blank($this->action_message) ) {
542 $this->action_status = 'none';
543 $this->action_message = '';
544 }
545 if($_REQUEST['page'] == 'usces_ordernew'){
546 $order_action = 'new';
547 }else{
548 $order_action = isset($_REQUEST['order_action']) ? $_REQUEST['order_action'] : '';
549 }
550 do_action('usces_action_order_list_page', $order_action);
551 switch ($order_action) {
552 //20100908ysk start
553 case 'dlproductlist':
554 usces_download_product_list();
555 break;
556 case 'dlorderlist':
557 usces_download_order_list();
558 break;
559 //20100908ysk end
560 // case 'printpdf':
561 // require_once(USCES_PLUGIN_DIR . '/includes/order_print.php');
562 // break;
563 case 'editpost':
564 do_action('usces_pre_update_orderdata', $_REQUEST['order_id']);
565 $res = usces_update_orderdata();
566 if ( 1 === $res ) {
567 $this->set_action_status('success', __('order date is updated','usces').' <a href="'.stripslashes( $_POST['usces_referer'] ).'">'.__('back to the summary','usces').'</a>');
568 } elseif ( 0 === $res ) {
569 $this->set_action_status('none', '');
570 } else {
571 $this->set_action_status('error', 'ERROR : '.__('failure in update','usces'));
572 }
573 do_action('usces_after_update_orderdata', $_REQUEST['order_id'], $res);
574 require_once($order_edit_form);
575 break;
576 case 'newpost':
577 do_action('usces_pre_new_orderdata');
578 $res = usces_new_orderdata();
579 if ( 1 === $res ) {
580 $this->set_action_status('success', __('New date is add','usces'));
581 } elseif ( 0 === $res ) {
582 $this->set_action_status('none', '');
583 } else {
584 $this->set_action_status('error', 'ERROR : '.__('failure in addition','usces'));
585 }
586 do_action('usces_after_new_orderdata', $res);
587 $_REQUEST['order_action'] = 'edit';
588 $order_action = $_REQUEST['order_action'];
589 require_once($order_edit_form);
590 break;
591 case 'new':
592 case 'edit':
593 require_once($order_edit_form);
594 break;
595 case 'delete':
596 do_action('usces_pre_delete_orderdata', $_REQUEST['order_id']);
597 $res = usces_delete_orderdata();
598 if ( 1 === $res ) {
599 $this->set_action_status('success', __('the order date is deleted','usces'));
600 } elseif ( 0 === $res ) {
601 $this->set_action_status('none', '');
602 } else {
603 $this->set_action_status('error', 'ERROR : '.__('failure in delete','usces'));
604 }
605 do_action('usces_after_delete_orderdata', $_REQUEST['order_id'], $res);
606 default:
607 require_once($order_list);
608 }
609 }
610
611 /* member list page */
612 function member_list_page() {
613
614 if(empty($this->action_message) || WCUtils::is_blank($this->action_message) ) {
615 $this->action_status = 'none';
616 $this->action_message = '';
617 }
618 $member_action = isset($_REQUEST['member_action']) ? $_REQUEST['member_action'] : '';
619 switch ($member_action) {
620 //20100908ysk start
621 case 'dlmemberlist':
622 usces_download_member_list();
623 break;
624 //20100908ysk end
625 case 'editpost':
626 $this->error_message = $this->admin_member_check();
627 if( WCUtils::is_blank($this->error_message) ){
628 $res = usces_update_memberdata();
629 if ( 1 === $res ) {
630 $this->set_action_status('success', __('Membership information is updated','usces'));
631 } elseif ( 0 === $res ) {
632 $this->set_action_status('none', '');
633 } else {
634 $this->set_action_status('error', 'ERROR : '.__('failure in update','usces'));
635 }
636 }
637 require_once(USCES_PLUGIN_DIR . '/includes/member_edit_form.php');
638 break;
639 case 'new':
640 case 'edit':
641 require_once(USCES_PLUGIN_DIR . '/includes/member_edit_form.php');
642 break;
643 case 'delete':
644 $res = usces_delete_memberdata();
645 if ( 1 === $res ) {
646 $this->set_action_status('success', __('The member data is deleted','usces'));
647 } elseif ( 0 === $res ) {
648 $this->set_action_status('none', '');
649 } else {
650 $this->set_action_status('error', 'ERROR : '.__('failure in delete','usces'));
651 }
652 default:
653 require_once(USCES_PLUGIN_DIR . '/includes/member_list.php');
654 }
655
656 }
657
658 /* admin backup page */
659 function admin_backup_page() {
660
661 if(empty($this->action_message) || WCUtils::is_blank($this->action_message) ) {
662 $this->action_status = 'none';
663 $this->action_message = '';
664 }
665 require_once(USCES_PLUGIN_DIR . '/includes/admin_backup.php');
666
667 }
668
669 /* Shop Top Page */
670 function admin_top_page() {
671
672 require_once(USCES_PLUGIN_DIR . '/includes/admin_top.php');
673
674 }
675
676 /* Shop Setup Page */
677 function admin_setup_page() {
678 $this->options = get_option('usces');
679 //$this->options = array();
680
681
682 if(isset($_POST['usces_option_update'])) {
683
684 $_POST = $this->stripslashes_deep_post($_POST);
685 $this->options['display_mode'] = isset($_POST['display_mode']) ? trim($_POST['display_mode']) : '';
686 $this->options['campaign_category'] = empty($_POST['cat']) ? USCES_ITEM_CAT_PARENT_ID : $_POST['cat'];
687 $this->options['campaign_privilege'] = isset($_POST['cat_privilege']) ? trim($_POST['cat_privilege']) : '';
688 $this->options['privilege_point'] = isset($_POST['point_num']) ? (int)$_POST['point_num'] : '';
689 $this->options['privilege_discount'] = isset($_POST['discount_num']) ? (int)$_POST['discount_num'] : '';
690 $this->options['company_name'] = isset($_POST['company_name']) ? trim($_POST['company_name']) : '';
691 $this->options['zip_code'] = isset($_POST['zip_code']) ? trim($_POST['zip_code']) : '';
692 $this->options['address1'] = isset($_POST['address1']) ? trim($_POST['address1']) : '';
693 $this->options['address2'] = isset($_POST['address2']) ? trim($_POST['address2']) : '';
694 $this->options['tel_number'] = isset($_POST['tel_number']) ? trim($_POST['tel_number']) : '';
695 $this->options['fax_number'] = isset($_POST['fax_number']) ? trim($_POST['fax_number']) : '';
696 $this->options['order_mail'] = isset($_POST['order_mail']) ? trim($_POST['order_mail']) : '';
697 $this->options['inquiry_mail'] = isset($_POST['inquiry_mail']) ? trim($_POST['inquiry_mail']) : '';
698 $this->options['sender_mail'] = isset($_POST['sender_mail']) ? trim($_POST['sender_mail']) : '';
699 $this->options['error_mail'] = isset($_POST['error_mail']) ? trim($_POST['error_mail']) : '';
700 $this->options['postage_privilege'] = isset($_POST['postage_privilege']) ? trim($_POST['postage_privilege']) : '';
701 $this->options['purchase_limit'] = isset($_POST['purchase_limit']) ? trim($_POST['purchase_limit']) : '';
702 $this->options['point_rate'] = isset($_POST['point_rate']) ? (int)$_POST['point_rate'] : '';
703 $this->options['start_point'] = isset($_POST['start_point']) ? (int)$_POST['start_point'] : '';
704 $this->options['shipping_rule'] = isset($_POST['shipping_rule']) ? trim($_POST['shipping_rule']) : '';
705 $this->options['tax_rate'] = isset($_POST['tax_rate']) ? (int)$_POST['tax_rate'] : '';
706 $this->options['tax_method'] = isset($_POST['tax_method']) ? trim($_POST['tax_method']) : '';
707 $this->options['cod_type'] = isset($this->options['cod_type']) ? $this->options['cod_type'] : 'fix';
708 $this->options['transferee'] = isset($_POST['transferee']) ? trim($_POST['transferee']) : '';
709 $this->options['copyright'] = isset($_POST['copyright']) ? trim($_POST['copyright']) : '';
710 $this->options['membersystem_state'] = isset($_POST['membersystem_state']) ? trim($_POST['membersystem_state']) : '';
711 $this->options['membersystem_point'] = isset($_POST['membersystem_point']) ? trim($_POST['membersystem_point']) : '';
712 $this->options['point_coverage'] = isset($_POST['point_coverage']) ? (int)$_POST['point_coverage'] : 0;
713 $this->options['point_assign'] = isset($_POST['point_assign']) ? (int)$_POST['point_assign'] : 1;//20120919ysk 0000573
714
715 $this->options = apply_filters( 'usces_filter_admin_setup_options', $this->options );
716
717 update_option('usces', $this->options);
718
719 $this->action_status = 'success';
720 $this->action_message = __('options are updated','usces');
721
722 } else {
723 $this->action_status = 'none';
724 $this->action_message = '';
725 }
726
727 require_once(USCES_PLUGIN_DIR . '/includes/admin_setup.php');
728
729 }
730
731 /* Shop Schedule Page */
732 function admin_schedule_page() {
733
734 $this->options = get_option('usces');
735
736 if(isset($_POST['usces_option_update'])) {
737 $_POST = $this->stripslashes_deep_post($_POST);
738
739 $this->options['campaign_schedule'] = isset($_POST['campaign_schedule']) ? $_POST['campaign_schedule'] : '0';
740 if(isset($_POST['business_days']))
741 $this->options['business_days'] = $_POST['business_days'];
742
743 update_option('usces', $this->options);
744
745 do_action( 'usces_action_admin_schedule_update' );
746
747 $this->action_status = 'success';
748 $this->action_message = __('options are updated','usces');
749 } else {
750 $this->action_status = 'none';
751 $this->action_message = '';
752 }
753
754 require_once(USCES_PLUGIN_DIR . '/includes/admin_schedule.php');
755
756 }
757
758 /* Shop Delivery Page */
759 function admin_delivery_page() {
760
761 $this->options = get_option('usces');
762
763 if(isset($_POST['usces_option_update'])) {
764 $_POST = $this->stripslashes_deep_post($_POST);
765
766 //20101208ysk start
767 if(isset($_POST['delivery_time_limit'])) $this->options['delivery_time_limit'] = $_POST['delivery_time_limit'];
768 if(isset($_POST['shortest_delivery_time'])) $this->options['shortest_delivery_time'] = $_POST['shortest_delivery_time'];
769 if(isset($_POST['delivery_after_days'])) $this->options['delivery_after_days'] = $_POST['delivery_after_days'];
770 //20101208ysk end
771
772 update_option('usces', $this->options);
773
774 $this->action_status = 'success';
775 $this->action_message = __('options are updated','usces');
776 } else {
777 $this->action_status = 'none';
778 $this->action_message = '';
779 }
780
781 require_once(USCES_PLUGIN_DIR . '/includes/admin_delivery.php');
782
783 }
784
785 /* Shop Mail Page */
786 function admin_mail_page() {
787 global $allowedposttags;
788
789 $this->options = get_option('usces');
790
791 if(isset($_POST['usces_option_update'])) {
792 $_POST = $this->stripslashes_deep_post($_POST);
793
794 $this->options['smtp_hostname'] = trim($_POST['smtp_hostname']);
795 $this->options['newmem_admin_mail'] = (int)$_POST['newmem_admin_mail'];
796 $this->options['delmem_admin_mail'] = (int)$_POST['delmem_admin_mail'];
797 $this->options['delmem_customer_mail'] = (int)$_POST['delmem_customer_mail'];
798
799 foreach ( $_POST['title'] as $key => $value ) {
800 if( WCUtils::is_blank($value) ) {
801 $this->options['mail_data']['title'][$key] = $this->options['mail_default']['title'][$key];
802 }else{
803 $this->options['mail_data']['title'][$key] = trim($value);
804 }
805 }
806 foreach ( $_POST['header'] as $key => $value ) {
807 if( WCUtils::is_blank($value) ) {
808 $this->options['mail_data']['header'][$key] = $this->options['mail_default']['header'][$key];
809 }else{
810 $this->options['mail_data']['header'][$key] = $value;
811 }
812 }
813 foreach ( $_POST['footer'] as $key => $value ) {
814 if( WCUtils::is_blank($value) ) {
815 $this->options['mail_data']['footer'][$key] = $this->options['mail_default']['footer'][$key];
816 }else{
817 $this->options['mail_data']['footer'][$key] = $value;
818 }
819 }
820
821
822 $this->action_status = 'success';
823 $this->action_message = __('options are updated','usces');
824
825 } else {
826
827 foreach ( (array)$this->options['mail_data']['title'] as $key => $value ) {
828 if( WCUtils::is_blank($value) ) {
829 $this->options['mail_data']['title'][$key] = $this->options['mail_default']['title'][$key];
830 }
831 }
832 foreach ( (array)$this->options['mail_data']['header'] as $key => $value ) {
833 if( WCUtils::is_blank($value) ) {
834 $this->options['mail_data']['header'][$key] = $this->options['mail_default']['header'][$key];
835 }
836 }
837 foreach ( (array)$this->options['mail_data']['footer'] as $key => $value ) {
838 if( WCUtils::is_blank($value) ) {
839 $this->options['mail_data']['footer'][$key] = $this->options['mail_default']['footer'][$key];
840 }
841 }
842
843 $this->action_status = 'none';
844 $this->action_message = '';
845
846 }
847
848 update_option('usces', $this->options);
849 do_action( 'usces_action_admin_mail_page' );
850
851 require_once(USCES_PLUGIN_DIR . '/includes/admin_mail.php');
852
853 }
854
855 /* Admin Cart Page */
856 function admin_cart_page() {
857 global $allowedposttags;
858 $this->options = get_option('usces');
859
860 if(isset($_POST['usces_option_update'])) {
861 $_POST = $this->stripslashes_deep_post($_POST);
862
863 foreach ( $this->options['indi_item_name'] as $key => $value ) {
864 $this->options['indi_item_name'][$key] = isset($_POST['indication'][$key]) ? 1 : 0;
865 }
866 foreach ( $_POST['position'] as $key => $value ) {
867 $this->options['pos_item_name'][$key] = $value;
868 }
869 foreach ( $_POST['header'] as $key => $value ) {
870 $this->options['cart_page_data']['header'][$key] = addslashes(wp_kses($value, $allowedposttags));
871 }
872 foreach ( $_POST['footer'] as $key => $value ) {
873 $this->options['cart_page_data']['footer'][$key] = addslashes(wp_kses($value, $allowedposttags));
874 }
875
876 update_option('usces', $this->options);
877
878 $this->action_status = 'success';
879 $this->action_message = __('options are updated','usces');
880 } else {
881
882 $this->action_status = 'none';
883 $this->action_message = '';
884 }
885
886
887
888 require_once(USCES_PLUGIN_DIR . '/includes/admin_cart.php');
889
890 }
891
892 /* Admin Member Page */
893 function admin_member_page() {
894
895 $this->options = get_option('usces');
896
897 if(isset($_POST['usces_option_update'])) {
898 $_POST = $this->stripslashes_deep_post($_POST);
899
900 foreach ( $_POST['header'] as $key => $value ) {
901 $this->options['member_page_data']['header'][$key] = $value;
902 }
903 foreach ( $_POST['footer'] as $key => $value ) {
904 $this->options['member_page_data']['footer'][$key] = $value;
905 }
906
907 update_option('usces', $this->options);
908
909 $this->action_status = 'success';
910 $this->action_message = __('options are updated','usces');
911 } else {
912
913 $this->action_status = 'none';
914 $this->action_message = '';
915 }
916
917
918
919 require_once(USCES_PLUGIN_DIR . '/includes/admin_member.php');
920
921 }
922
923
924 /* Admin System Page */
925 function admin_system_page() {
926 //20110331ysk start
927 global $usces_states;
928 //20110331ysk end
929 $action_status = '';//20120511ysk 0000470
930
931 $this->options = get_option('usces');
932
933 if(isset($_POST['usces_option_update'])) {
934 $_POST = $this->stripslashes_deep_post($_POST);
935
936 //20110331ysk start
937 /* if($_POST['province'] != ''){
938 $temp_pref = explode("\n", $_POST['province']);
939 for($i=-1; $i<count($temp_pref); $i++){
940 if($i == -1){
941 $usces_pref[] = __('-- Select --','usces');
942 }else{
943 $usces_pref[] = trim($temp_pref[$i]);
944 }
945 }
946 }else{
947 $usces_pref = get_option('usces_pref');
948 }
949
950 $this->options['province'] = $usces_pref;*/
951 //20110331ysk end
952 $this->options['divide_item'] = isset($_POST['divide_item']) ? 1 : 0;
953 $this->options['itemimg_anchor_rel'] = isset($_POST['itemimg_anchor_rel']) ? trim($_POST['itemimg_anchor_rel']) : '';
954 $this->options['fukugo_category_orderby'] = isset($_POST['fukugo_category_orderby']) ? $_POST['fukugo_category_orderby'] : '';
955 $this->options['fukugo_category_order'] = isset($_POST['fukugo_category_order']) ? $_POST['fukugo_category_order'] : '';
956 $this->options['settlement_path'] = isset($_POST['settlement_path']) ? $_POST['settlement_path'] : '';
957 if( WCUtils::is_blank($this->options['settlement_path']) ) $this->options['settlement_path'] = USCES_PLUGIN_DIR . '/settlement/';
958 $sl = substr($this->options['settlement_path'], -1);
959 if($sl != '/' && $sl != '\\') $this->options['settlement_path'] .= '/';
960 $this->options['use_ssl'] = isset($_POST['use_ssl']) ? 1 : 0;
961 $this->options['ssl_url'] = isset($_POST['ssl_url']) ? rtrim($_POST['ssl_url'], '/') : '';
962 $this->options['ssl_url_admin'] = isset($_POST['ssl_url_admin']) ? rtrim($_POST['ssl_url_admin'], '/') : '';
963 if( WCUtils::is_blank($this->options['ssl_url']) || WCUtils::is_blank($this->options['ssl_url_admin']) ) $this->options['use_ssl'] = 0;
964 $this->options['inquiry_id'] = isset($_POST['inquiry_id']) ? esc_html(rtrim($_POST['inquiry_id'])) : '';
965 $this->options['use_javascript'] = isset($_POST['use_javascript']) ? (int)$_POST['use_javascript'] : 1;
966 $this->options['system']['front_lang'] = (isset($_POST['front_lang']) && 'others' != $_POST['front_lang']) ? $_POST['front_lang'] : usces_get_local_language();
967 $this->options['system']['currency'] = (isset($_POST['currency']) && 'others' != $_POST['currency']) ? $_POST['currency'] : usces_get_base_country();
968 $this->options['system']['addressform'] = (isset($_POST['addressform']) ) ? $_POST['addressform'] : usces_get_local_addressform();
969 $this->options['system']['target_market'] = (isset($_POST['target_market']) ) ? $_POST['target_market'] : usces_get_local_target_market();
970 $this->options['system']['no_cart_css'] = isset($_POST['no_cart_css']) ? 1 : 0;
971 $this->options['system']['dec_orderID_flag'] = isset($_POST['dec_orderID_flag']) ? (int)$_POST['dec_orderID_flag'] : 0;
972 $this->options['system']['dec_orderID_prefix'] = isset($_POST['dec_orderID_prefix']) ? esc_html(rtrim($_POST['dec_orderID_prefix'])) : '';
973 if( isset($_POST['dec_orderID_digit']) ){
974 $dec_orderID_digit = (int)rtrim($_POST['dec_orderID_digit']);
975 if( 6 > $dec_orderID_digit ){
976 $this->options['system']['dec_orderID_digit'] = 6;
977 }else{
978 $this->options['system']['dec_orderID_digit'] = $dec_orderID_digit;
979 }
980 }else{
981 $this->options['system']['dec_orderID_digit'] = 6;
982 }
983 $this->options['system']['subimage_rule'] = isset($_POST['subimage_rule']) ? (int)$_POST['subimage_rule'] : 0;
984 //20110331ysk start
985 unset($this->options['province']);
986 //$action_status = '';//20120511ysk 0000470
987 foreach((array)$this->options['system']['target_market'] as $target_market) {
988 $province = array();
989 if(!empty($_POST['province_'.$target_market])) {
990 $temp_pref = explode("\n", $_POST['province_'.$target_market]);
991 //20120123ysk start 0000386
992 //$province[] = __('-- Select --', 'usces');
993 $province[] = '-- Select --';
994 //20120123ysk end
995 //20120725ysk start 0000537
996 //for($i = 0; $i < count($temp_pref); $i++) {
997 //$province[] = trim($temp_pref[$i]);
998 foreach( $temp_pref as $pref ) {
999 if( !WCUtils::is_blank($pref) )
1000 $province[] = trim($pref);
1001 }
1002 if( 1 == count($province) )
1003 $action_status = 'error';
1004 //20120725ysk end
1005 } else {
1006 if(isset($usces_states[$target_market]) && is_array($usces_states[$target_market])) {
1007 $province = $usces_states[$target_market];
1008 } else {
1009 $action_status = 'error';
1010 }
1011 }
1012 $this->options['province'][$target_market] = $province;
1013 }
1014
1015 if($action_status != '') {
1016 $this->action_status = 'error';
1017 $this->action_message = __('Data have deficiency.','usces');
1018 } else {
1019 $this->action_status = 'success';
1020 $this->action_message = __('options are updated','usces');
1021 }
1022 //20110331ysk end
1023 } else {
1024
1025 if( !isset($this->options['province']) || empty($this->options['province']) ){
1026 //20110331ysk start
1027 //$this->options['province'] = get_option('usces_pref');
1028 $this->options['province'][$this->options['system']['base_country']] = $usces_states[$this->options['system']['base_country']];
1029 //20110331ysk end
1030 }
1031 $this->action_status = 'none';
1032 $this->action_message = '';
1033 }
1034
1035 if($action_status != 'error') //20120511ysk 0000470
1036 update_option('usces', $this->options);
1037
1038 require_once(USCES_PLUGIN_DIR . '/includes/admin_system.php');
1039
1040 }
1041
1042 /* Settlement Setting Page */
1043 function admin_settlement_page() {
1044
1045 $this->action_status = 'none';
1046 $this->action_message = '';
1047
1048 $options = get_option('usces');
1049
1050
1051 if( isset($_POST['usces_option_update']) ) {
1052 $_POST = $this->stripslashes_deep_post($_POST);
1053 $mes = '';
1054
1055 switch( $_POST['acting'] ){
1056 case 'zeus':
1057 unset( $options['acting_settings']['zeus'] );
1058 $options['acting_settings']['zeus']['card_url'] = isset($_POST['card_url']) ? $_POST['card_url'] : '';
1059 $options['acting_settings']['zeus']['card_secureurl'] = isset($_POST['card_secureurl']) ? $_POST['card_secureurl'] : '';
1060 $options['acting_settings']['zeus']['ipaddrs'] = isset($_POST['ipaddrs']) ? $_POST['ipaddrs'] : '';
1061 $options['acting_settings']['zeus']['pay_cvs'] = isset($_POST['pay_cvs']) ? $_POST['pay_cvs'] : '';
1062 $options['acting_settings']['zeus']['card_activate'] = isset($_POST['card_activate']) ? $_POST['card_activate'] : '';
1063 $options['acting_settings']['zeus']['connection'] = isset($_POST['connection']) ? $_POST['connection'] : 1;
1064 $options['acting_settings']['zeus']['3dsecur'] = isset($_POST['3dsecur']) ? $_POST['3dsecur'] : 2;
1065 $options['acting_settings']['zeus']['security'] = isset($_POST['security']) ? $_POST['security'] : 2;
1066 if( isset($_POST['authkey']) ){
1067 $options['acting_settings']['zeus']['authkey'] = $_POST['authkey'];
1068 }
1069 // if( 1 == $options['acting_settings']['zeus']['security'] ){
1070 // $options['acting_settings']['zeus']['quickcharge'] = '2';
1071 // }else{
1072 $options['acting_settings']['zeus']['quickcharge'] = isset($_POST['quickcharge']) ? $_POST['quickcharge'] : '';
1073 // }
1074 $options['acting_settings']['zeus']['batch'] = isset($_POST['batch']) ? $_POST['batch'] : '';
1075 $options['acting_settings']['zeus']['clientip'] = isset($_POST['clientip']) ? trim($_POST['clientip']) : '';
1076 $options['acting_settings']['zeus']['howpay'] = isset($_POST['howpay']) ? $_POST['howpay'] : '';
1077 $options['acting_settings']['zeus']['bank_activate'] = isset($_POST['bank_activate']) ? $_POST['bank_activate'] : '';
1078 $options['acting_settings']['zeus']['clientip_bank'] = isset($_POST['clientip_bank']) ? trim($_POST['clientip_bank']) : '';
1079 $options['acting_settings']['zeus']['testid_bank'] = isset($_POST['testid_bank']) ? trim($_POST['testid_bank']) : '';
1080 $options['acting_settings']['zeus']['bank_url'] = isset($_POST['bank_url']) ? $_POST['bank_url'] : '';
1081 $options['acting_settings']['zeus']['conv_activate'] = isset($_POST['conv_activate']) ? $_POST['conv_activate'] : '';
1082 $options['acting_settings']['zeus']['clientip_conv'] = isset($_POST['clientip_conv']) ? trim($_POST['clientip_conv']) : '';
1083 $options['acting_settings']['zeus']['testid_conv'] = isset($_POST['testid_conv']) ? trim($_POST['testid_conv']) : '';
1084 $options['acting_settings']['zeus']['test_type_conv'] = ( (isset($_POST['testid_conv']) && WCUtils::is_blank($_POST['testid_conv'])) || !isset($_POST['test_type']) ) ? 0 : $_POST['test_type'];
1085 $options['acting_settings']['zeus']['conv_url'] = isset($_POST['conv_url']) ? $_POST['conv_url'] : '';
1086
1087 if( WCUtils::is_blank($_POST['clientip']) && isset($_POST['card_activate']) && 'on' == $_POST['card_activate'])
1088 $mes .= '※カード決済IPコードを�
1089 �力して下さい<br />';
1090 if( isset($_POST['authkey']) && WCUtils::is_blank($_POST['authkey']) && isset($_POST['security']) && 3 == $_POST['security'])
1091 $mes .= '※認証キーを�
1092 �力して下さい<br />';
1093 if( WCUtils::is_blank($_POST['clientip_bank']) && isset($_POST['bank_activate']) && 'on' == $_POST['bank_activate'] )
1094 $mes .= '※�
1095 �金お任せIPコードを�
1096 �力して下さい<br />';
1097 if( WCUtils::is_blank($_POST['clientip_conv']) && isset($_POST['conv_activate']) && 'on' == $_POST['conv_activate'] )
1098 $mes .= '※コンビニ決済IPコードを�
1099 �力して下さい<br />';
1100 if( isset($_POST['batch']) && 'on' == $_POST['batch'] ) {
1101 if( isset($_POST['quickcharge']) && 'on' == $_POST['quickcharge'] ) {
1102 } else {
1103 $mes .= '※バッチ処理を利用する場合は、クイックチャージを利用するにして下さい<br />';
1104 }
1105 }
1106 if( !isset($_POST['card_url']) || empty($_POST['card_url']) || !isset($_POST['ipaddrs']) || empty($_POST['ipaddrs']) || !isset($_POST['bank_url']) || empty($_POST['bank_url']) || !isset($_POST['conv_url']) || empty($_POST['conv_url']) )
1107 $mes .= '※設定が不正です!<br />';
1108
1109 if( WCUtils::is_blank($mes) ){
1110 $this->action_status = 'success';
1111 $this->action_message = __('options are updated','usces');
1112 $options['acting_settings']['zeus']['activate'] = 'on';
1113 if( 'on' == $options['acting_settings']['zeus']['card_activate'] ){
1114 $this->payment_structure['acting_zeus_card'] = 'カード決済(ZEUS)';
1115 }else{
1116 unset($this->payment_structure['acting_zeus_card']);
1117 }
1118 if( 'on' == $options['acting_settings']['zeus']['bank_activate'] ){
1119 $this->payment_structure['acting_zeus_bank'] = '�
1120 �金お任せ(ZEUS)';
1121 }else{
1122 unset($this->payment_structure['acting_zeus_bank']);
1123 }
1124 if( 'on' == $options['acting_settings']['zeus']['conv_activate'] ){
1125 $this->payment_structure['acting_zeus_conv'] = 'コンビニ決済(ZEUS)';
1126 }else{
1127 unset($this->payment_structure['acting_zeus_conv']);
1128 }
1129 }else{
1130 $this->action_status = 'error';
1131 $this->action_message = __('データに不備が有ります','usces');
1132 $options['acting_settings']['zeus']['activate'] = 'off';
1133 unset($this->payment_structure['acting_zeus_card'], $this->payment_structure['acting_zeus_bank'], $this->payment_structure['acting_zeus_conv']);
1134 }
1135 ksort($this->payment_structure);
1136 update_option('usces_payment_structure',$this->payment_structure);
1137 $options['acting_settings']['zeus']['vercheck'] = '115';
1138 if( update_option('usces', $options) ){
1139 usces_clear_quickcharge();
1140 }
1141 break;
1142
1143 case 'remise':
1144 unset( $options['acting_settings']['remise'] );
1145 $options['acting_settings']['remise']['plan'] = isset($_POST['plan']) ? $_POST['plan'] : '';
1146 $options['acting_settings']['remise']['SHOPCO'] = isset($_POST['SHOPCO']) ? $_POST['SHOPCO'] : '';
1147 $options['acting_settings']['remise']['HOSTID'] = isset($_POST['HOSTID']) ? $_POST['HOSTID'] : '';
1148 $options['acting_settings']['remise']['card_activate'] = isset($_POST['card_activate']) ? $_POST['card_activate'] : '';
1149 $options['acting_settings']['remise']['card_jb'] = isset($_POST['card_jb']) ? $_POST['card_jb'] : '';
1150 $options['acting_settings']['remise']['card_pc_ope'] = isset($_POST['card_pc_ope']) ? $_POST['card_pc_ope'] : '';
1151 $options['acting_settings']['remise']['payquick'] = isset($_POST['payquick']) ? $_POST['payquick'] : '';
1152 $options['acting_settings']['remise']['howpay'] = isset($_POST['howpay']) ? $_POST['howpay'] : '';
1153 $options['acting_settings']['remise']['continuation'] = isset($_POST['continuation']) ? $_POST['continuation'] : '';
1154 $options['acting_settings']['remise']['conv_activate'] = isset($_POST['conv_activate']) ? $_POST['conv_activate'] : '';
1155 $options['acting_settings']['remise']['conv_pc_ope'] = isset($_POST['conv_pc_ope']) ? $_POST['conv_pc_ope'] : '';
1156 $options['acting_settings']['remise']['S_PAYDATE'] = isset($_POST['S_PAYDATE']) ? $_POST['S_PAYDATE'] : '';
1157 $options['acting_settings']['remise']['send_url_mbl'] = isset($_POST['send_url_mbl']) ? $_POST['send_url_mbl'] : '';
1158 $options['acting_settings']['remise']['send_url_pc'] = isset($_POST['send_url_pc']) ? $_POST['send_url_pc'] : '';
1159 $options['acting_settings']['remise']['send_url_cvs_mbl'] = isset($_POST['send_url_cvs_mbl']) ? $_POST['send_url_cvs_mbl'] : '';
1160 $options['acting_settings']['remise']['send_url_cvs_pc'] = isset($_POST['send_url_cvs_pc']) ? $_POST['send_url_cvs_pc'] : '';
1161 $options['acting_settings']['remise']['send_url_mbl_test'] = isset($_POST['send_url_mbl_test']) ? $_POST['send_url_mbl_test'] : '';
1162 $options['acting_settings']['remise']['send_url_pc_test'] = isset($_POST['send_url_pc_test']) ? $_POST['send_url_pc_test'] : '';
1163 $options['acting_settings']['remise']['send_url_cvs_mbl_test'] = isset($_POST['send_url_cvs_mbl_test']) ? $_POST['send_url_cvs_mbl_test'] : '';
1164 $options['acting_settings']['remise']['send_url_cvs_pc_test'] = isset($_POST['send_url_cvs_pc_test']) ? $_POST['send_url_cvs_pc_test'] : '';
1165 $options['acting_settings']['remise']['REMARKS3'] = isset($_POST['REMARKS3']) ? $_POST['REMARKS3'] : '';
1166
1167 if( isset($_POST['plan_remise']) && WCUtils::is_zero($_POST['plan_remise']) )
1168 $mes .= '※サービスプランを選択してください<br />';
1169 if( WCUtils::is_blank($_POST['SHOPCO']) )
1170 $mes .= '※加盟店コードを�
1171 �力して下さい<br />';
1172 if( WCUtils::is_blank($_POST['HOSTID']) )
1173 $mes .= '※ホスト番号を�
1174 �力して下さい<br />';
1175 if( isset($_POST['conv_activate']) && 'on' == $_POST['conv_activate'] && empty($_POST['S_PAYDATE']) )
1176 $mes .= '※支払期限を�
1177 �力して下さい<br />';
1178 if( isset($_POST['card_pc_ope']) && 'public' == $_POST['card_pc_ope'] && empty($_POST['send_url_pc']) )
1179 $mes .= '※クレジットカード決済の本番URLを�
1180 �力して下さい<br />';
1181 if( isset($_POST['conv_pc_ope']) && 'public' == $_POST['conv_pc_ope'] && empty($_POST['send_url_cvs_pc']) )
1182 $mes .= '※コンビニ・電子マネー決済の本番URLを�
1183 �力して下さい<br />';
1184 if( !isset($_POST['REMARKS3']) || empty($_POST['REMARKS3']) )
1185 $mes .= '※設定が不正です!<br />';
1186
1187 if( WCUtils::is_blank($mes) ){
1188 //$this->zaction_status = 'success';
1189 $this->action_status = 'success';
1190 $this->action_message = __('options are updated','usces');
1191 $options['acting_settings']['remise']['activate'] = 'on';
1192 if( 'on' == $options['acting_settings']['remise']['card_activate'] ){
1193 $this->payment_structure['acting_remise_card'] = 'カード決済(ルミーズ)';
1194 }else{
1195 unset($this->payment_structure['acting_remise_card']);
1196 }
1197 if( 'on' == $options['acting_settings']['remise']['conv_activate'] ){
1198 $this->payment_structure['acting_remise_conv'] = 'コンビニ決済(ルミーズ)';
1199 }else{
1200 unset($this->payment_structure['acting_remise_conv']);
1201 }
1202
1203 }else{
1204 $this->action_status = 'error';
1205 $this->action_message = __('データに不備が有ります','usces');
1206 $options['acting_settings']['remise']['activate'] = 'off';
1207 unset($this->payment_structure['acting_remise_card']);
1208 unset($this->payment_structure['acting_remise_conv']);
1209 }
1210 ksort($this->payment_structure);
1211 update_option('usces_payment_structure',$this->payment_structure);
1212 update_option('usces', $options);
1213 break;
1214 //20101018ysk start
1215 case 'jpayment':
1216 unset( $options['acting_settings']['jpayment'] );
1217 $options['acting_settings']['jpayment']['aid'] = isset($_POST['aid']) ? $_POST['aid'] : '';
1218 $options['acting_settings']['jpayment']['card_activate'] = isset($_POST['card_activate']) ? $_POST['card_activate'] : '';
1219 $options['acting_settings']['jpayment']['card_jb'] = isset($_POST['card_jb']) ? $_POST['card_jb'] : '';
1220 $options['acting_settings']['jpayment']['conv_activate'] = isset($_POST['conv_activate']) ? $_POST['conv_activate'] : '';
1221 //$options['acting_settings']['jpayment']['webm_activate'] = isset($_POST['webm_activate']) ? $_POST['webm_activate'] : '';
1222 //$options['acting_settings']['jpayment']['bitc_activate'] = isset($_POST['bitc_activate']) ? $_POST['bitc_activate'] : '';
1223 //$options['acting_settings']['jpayment']['suica_activate'] = isset($_POST['suica_activate']) ? $_POST['suica_activate'] : '';
1224 $options['acting_settings']['jpayment']['bank_activate'] = isset($_POST['bank_activate']) ? $_POST['bank_activate'] : '';
1225 $options['acting_settings']['jpayment']['send_url'] = isset($_POST['send_url']) ? $_POST['send_url'] : '';
1226
1227 if( WCUtils::is_blank($_POST['aid']) )
1228 $mes .= '※店舗IDコードを�
1229 �力して下さい<br />';
1230 if( isset($_POST['card_activate']) && 'on' == $_POST['card_activate'] && empty($_POST['card_jb']) )
1231 $mes .= '※ジョブタイプを指定して下さい<br />';
1232
1233 if( WCUtils::is_blank($mes) ){
1234 $this->action_status = 'success';
1235 $this->action_message = __('options are updated','usces');
1236 $options['acting_settings']['jpayment']['activate'] = 'on';
1237 if( 'on' == $options['acting_settings']['jpayment']['card_activate'] ){
1238 $this->payment_structure['acting_jpayment_card'] = 'カード決済(J-Payment)';
1239 }else{
1240 unset($this->payment_structure['acting_jpayment_card']);
1241 }
1242 if( 'on' == $options['acting_settings']['jpayment']['conv_activate'] ){
1243 $this->payment_structure['acting_jpayment_conv'] = 'コンビニ決済(J-Payment)';
1244 }else{
1245 unset($this->payment_structure['acting_jpayment_conv']);
1246 }
1247 //if( 'on' == $options['acting_settings']['jpayment']['webm_activate'] ){
1248 // $this->payment_structure['acting_jpayment_webm'] = 'WebMoney決済(J-Payment)';
1249 //}else{
1250 // unset($this->payment_structure['acting_jpayment_webm']);
1251 //}
1252 //if( 'on' == $options['acting_settings']['jpayment']['bitc_activate'] ){
1253 // $this->payment_structure['acting_jpayment_bitc'] = 'BitCash決済(J-Payment)';
1254 //}else{
1255 // unset($this->payment_structure['acting_jpayment_bitc']);
1256 //}
1257 //if( 'on' == $options['acting_settings']['jpayment']['suica_activate'] ){
1258 // $this->payment_structure['acting_jpayment_suica'] = 'モバイルSuica決済(J-Payment)';
1259 //}else{
1260 // unset($this->payment_structure['acting_jpayment_suica']);
1261 //}
1262 if( 'on' == $options['acting_settings']['jpayment']['bank_activate'] ){
1263 $this->payment_structure['acting_jpayment_bank'] = 'バンクチェック決済(J-Payment)';
1264 }else{
1265 unset($this->payment_structure['acting_jpayment_bank']);
1266 }
1267
1268 }else{
1269 $this->action_status = 'error';
1270 $this->action_message = __('データに不備が有ります', 'usces');
1271 $options['acting_settings']['jpayment']['activate'] = 'off';
1272 unset($this->payment_structure['acting_jpayment_card']);
1273 unset($this->payment_structure['acting_jpayment_conv']);
1274 //unset($this->payment_structure['acting_jpayment_webm']);
1275 //unset($this->payment_structure['acting_jpayment_bitc']);
1276 //unset($this->payment_structure['acting_jpayment_suica']);
1277 unset($this->payment_structure['acting_jpayment_bank']);
1278 }
1279 ksort($this->payment_structure);
1280 update_option('usces_payment_structure', $this->payment_structure);
1281 update_option('usces', $options);
1282 break;
1283 //20101018ysk end
1284 //20110208ysk start
1285 case 'paypal':
1286 unset( $options['acting_settings']['paypal'] );
1287 $options['acting_settings']['paypal']['ec_activate'] = isset($_POST['ec_activate']) ? $_POST['ec_activate'] : '';
1288 $options['acting_settings']['paypal']['sandbox'] = isset($_POST['sandbox']) ? $_POST['sandbox'] : '';
1289 $options['acting_settings']['paypal']['user'] = isset($_POST['user']) ? $_POST['user'] : '';
1290 $options['acting_settings']['paypal']['pwd'] = isset($_POST['pwd']) ? $_POST['pwd'] : '';
1291 $options['acting_settings']['paypal']['signature'] = isset($_POST['signature']) ? $_POST['signature'] : '';
1292 //20110412ysk start
1293 $options['acting_settings']['paypal']['continuation'] = isset($_POST['continuation']) ? $_POST['continuation'] : '';
1294 //20110412ysk end
1295
1296 if( !isset($_POST['sandbox']) || empty($_POST['sandbox']) )
1297 $mes .= '※PayPalサーバーが不正です<br />';
1298 if( WCUtils::is_blank($_POST['user']) )
1299 $mes .= '※APIユーザー名を�
1300 �力して下さい<br />';
1301 if( WCUtils::is_blank($_POST['pwd']) )
1302 $mes .= '※APIパスワードを�
1303 �力して下さい<br />';
1304 if( WCUtils::is_blank($_POST['signature']) )
1305 $mes .= '※署名を�
1306 �力して下さい<br />';
1307
1308 if( WCUtils::is_blank($mes) ){
1309 $this->action_status = 'success';
1310 $this->action_message = __('options are updated','usces');
1311 if($options['acting_settings']['paypal']['sandbox'] == 1) {
1312 $options['acting_settings']['paypal']['api_host'] = 'api-3t.sandbox.paypal.com';
1313 $options['acting_settings']['paypal']['api_endpoint'] = 'https://api-3t.sandbox.paypal.com/nvp';
1314 $options['acting_settings']['paypal']['paypal_url'] = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
1315 } else {
1316 $options['acting_settings']['paypal']['api_host'] = 'api-3t.paypal.com';
1317 $options['acting_settings']['paypal']['api_endpoint'] = 'https://api-3t.paypal.com/nvp';
1318 $options['acting_settings']['paypal']['paypal_url'] = 'https://www.paypal.com/cgi-bin/webscr';
1319 }
1320 $options['acting_settings']['paypal']['activate'] = 'on';
1321 if( 'on' == $options['acting_settings']['paypal']['ec_activate'] ){
1322 $this->payment_structure['acting_paypal_ec'] = 'PayPal決済';
1323 }else{
1324 unset($this->payment_structure['acting_paypal_ec']);
1325 }
1326
1327 }else{
1328 $this->action_status = 'error';
1329 $this->action_message = __('データに不備が有ります', 'usces');
1330 $options['acting_settings']['paypal']['activate'] = 'off';
1331 unset($this->payment_structure['acting_paypal_ec']);
1332 }
1333 ksort($this->payment_structure);
1334 update_option('usces_payment_structure', $this->payment_structure);
1335 update_option('usces', $options);
1336 break;
1337 //20110208ysk end
1338 //20120413ysk start
1339 case 'sbps':
1340 unset( $options['acting_settings']['sbps'] );
1341 $options['acting_settings']['sbps']['merchant_id'] = isset($_POST['merchant_id']) ? $_POST['merchant_id'] : '';
1342 $options['acting_settings']['sbps']['service_id'] = isset($_POST['service_id']) ? $_POST['service_id'] : '';
1343 $options['acting_settings']['sbps']['hash_key'] = isset($_POST['hash_key']) ? $_POST['hash_key'] : '';
1344 $options['acting_settings']['sbps']['ope'] = isset($_POST['ope']) ? $_POST['ope'] : '';
1345 $options['acting_settings']['sbps']['send_url'] = isset($_POST['send_url']) ? $_POST['send_url'] : '';
1346 $options['acting_settings']['sbps']['send_url_check'] = isset($_POST['send_url_check']) ? $_POST['send_url_check'] : '';
1347 $options['acting_settings']['sbps']['send_url_test'] = isset($_POST['send_url_test']) ? $_POST['send_url_test'] : '';
1348 $options['acting_settings']['sbps']['card_activate'] = isset($_POST['card_activate']) ? $_POST['card_activate'] : '';
1349 $options['acting_settings']['sbps']['3d_secure'] = isset($_POST['3d_secure']) ? $_POST['3d_secure'] : '';
1350 $options['acting_settings']['sbps']['cust'] = isset($_POST['cust']) ? $_POST['cust'] : '';
1351 $options['acting_settings']['sbps']['continuation'] = isset($_POST['continuation']) ? $_POST['continuation'] : '';
1352 $options['acting_settings']['sbps']['conv_activate'] = isset($_POST['conv_activate']) ? $_POST['conv_activate'] : '';
1353 $options['acting_settings']['sbps']['payeasy_activate'] = isset($_POST['payeasy_activate']) ? $_POST['payeasy_activate'] : '';
1354 $options['acting_settings']['sbps']['wallet_yahoowallet'] = isset($_POST['wallet_yahoowallet']) ? $_POST['wallet_yahoowallet'] : '';
1355 $options['acting_settings']['sbps']['wallet_rakuten'] = isset($_POST['wallet_rakuten']) ? $_POST['wallet_rakuten'] : '';
1356 $options['acting_settings']['sbps']['wallet_paypal'] = isset($_POST['wallet_paypal']) ? $_POST['wallet_paypal'] : '';
1357 $options['acting_settings']['sbps']['wallet_netmile'] = isset($_POST['wallet_netmile']) ? $_POST['wallet_netmile'] : '';
1358 $options['acting_settings']['sbps']['wallet_alipay'] = isset($_POST['wallet_alipay']) ? $_POST['wallet_alipay'] : '';
1359 $options['acting_settings']['sbps']['mobile_docomo'] = isset($_POST['mobile_docomo']) ? $_POST['mobile_docomo'] : '';
1360 $options['acting_settings']['sbps']['mobile_softbank'] = isset($_POST['mobile_softbank']) ? $_POST['mobile_softbank'] : '';
1361 $options['acting_settings']['sbps']['mobile_auone'] = isset($_POST['mobile_auone']) ? $_POST['mobile_auone'] : '';
1362 $options['acting_settings']['sbps']['mobile_mysoftbank'] = isset($_POST['mobile_mysoftbank']) ? $_POST['mobile_mysoftbank'] : '';
1363
1364 if( WCUtils::is_blank($_POST['merchant_id']) )
1365 $mes .= '※マーチャントIDを�
1366 �力して下さい<br />';
1367 if( WCUtils::is_blank($_POST['service_id']) )
1368 $mes .= '※サービスIDを�
1369 �力して下さい<br />';
1370 if( WCUtils::is_blank($_POST['hash_key']) )
1371 $mes .= '※Hash KEYを�
1372 �力して下さい<br />';
1373 if( isset($_POST['ope']) && 'public' == $_POST['ope'] && empty($_POST['send_url']) )
1374 $mes .= '※本番URLを�
1375 �力して下さい<br />';
1376
1377 if( WCUtils::is_blank($mes) ){
1378 $this->action_status = 'success';
1379 $this->action_message = __('options are updated','usces');
1380 $options['acting_settings']['sbps']['activate'] = 'on';
1381 if( 'on' == $options['acting_settings']['sbps']['card_activate'] ){
1382 $this->payment_structure['acting_sbps_card'] = 'カード決済(ソフトバンク・ペイメント)';
1383 }else{
1384 unset($this->payment_structure['acting_sbps_card']);
1385 }
1386 if( 'on' == $options['acting_settings']['sbps']['conv_activate'] ){
1387 $this->payment_structure['acting_sbps_conv'] = 'コンビニ決済(ソフトバンク・ペイメント)';
1388 }else{
1389 unset($this->payment_structure['acting_sbps_conv']);
1390 }
1391 if( 'on' == $options['acting_settings']['sbps']['payeasy_activate'] ){
1392 $this->payment_structure['acting_sbps_payeasy'] = 'ペイジー決済(ソフトバンク・ペイメント)';
1393 }else{
1394 unset($this->payment_structure['acting_sbps_payeasy']);
1395 }
1396 if( ( 'on' == $options['acting_settings']['sbps']['wallet_yahoowallet'] ) ||
1397 ( 'on' == $options['acting_settings']['sbps']['wallet_rakuten'] ) ||
1398 ( 'on' == $options['acting_settings']['sbps']['wallet_paypal'] ) ||
1399 ( 'on' == $options['acting_settings']['sbps']['wallet_netmile'] ) ||
1400 ( 'on' == $options['acting_settings']['sbps']['wallet_alipay'] ) ) {
1401 $options['acting_settings']['sbps']['wallet_activate'] = 'on';
1402 } else {
1403 $options['acting_settings']['sbps']['wallet_activate'] = 'off';
1404 }
1405 if( 'on' == $options['acting_settings']['sbps']['wallet_activate'] ){
1406 $this->payment_structure['acting_sbps_wallet'] = 'ウォレット決済(ソフトバンク・ペイメント)';
1407 }else{
1408 unset($this->payment_structure['acting_sbps_wallet']);
1409 }
1410 if( ( 'on' == $options['acting_settings']['sbps']['mobile_docomo'] ) ||
1411 ( 'on' == $options['acting_settings']['sbps']['mobile_softbank'] ) ||
1412 ( 'on' == $options['acting_settings']['sbps']['mobile_auone'] ) ||
1413 ( 'on' == $options['acting_settings']['sbps']['mobile_mysoftbank'] ) ) {
1414 $options['acting_settings']['sbps']['mobile_activate'] = 'on';
1415 } else {
1416 $options['acting_settings']['sbps']['mobile_activate'] = 'off';
1417 }
1418 if( 'on' == $options['acting_settings']['sbps']['mobile_activate'] ){
1419 $this->payment_structure['acting_sbps_mobile'] = '携帯キャリア決済(ソフトバンク・ペイメント)';
1420 }else{
1421 unset($this->payment_structure['acting_sbps_mobile']);
1422 }
1423
1424 }else{
1425 $this->action_status = 'error';
1426 $this->action_message = __('データに不備が有ります','usces');
1427 $options['acting_settings']['sbps']['activate'] = 'off';
1428 unset($this->payment_structure['acting_sbps_card']);
1429 unset($this->payment_structure['acting_sbps_conv']);
1430 unset($this->payment_structure['acting_sbps_payeasy']);
1431 unset($this->payment_structure['acting_sbps_wallet']);
1432 unset($this->payment_structure['acting_sbps_mobile']);
1433 }
1434 ksort($this->payment_structure);
1435 update_option('usces_payment_structure', $this->payment_structure);
1436 update_option('usces', $options);
1437 break;
1438 //20120413ysk end
1439 //20120618ysk start
1440 case 'telecom':
1441 unset( $options['acting_settings']['telecom'] );
1442 $options['acting_settings']['telecom']['clientip'] = isset($_POST['clientip']) ? $_POST['clientip'] : '';
1443 $options['acting_settings']['telecom']['stype'] = isset($_POST['stype']) ? $_POST['stype'] : '';
1444 $options['acting_settings']['telecom']['card_activate'] = isset($_POST['card_activate']) ? $_POST['card_activate'] : '';
1445 $options['acting_settings']['telecom']['edy_activate'] = isset($_POST['edy_activate']) ? $_POST['edy_activate'] : '';
1446
1447 if( WCUtils::is_blank($_POST['clientip']) )
1448 $mes .= '※クライアントIPを�
1449 �力して下さい<br />';
1450 if( WCUtils::is_blank($_POST['stype']) )
1451 $mes .= '※決済タイプを�
1452 �力して下さい<br />';
1453
1454 if( WCUtils::is_blank($mes) ){
1455 $this->action_status = 'success';
1456 $this->action_message = __('options are updated','usces');
1457 $options['acting_settings']['telecom']['activate'] = 'on';
1458 if( 'on' == $options['acting_settings']['telecom']['card_activate'] ){
1459 if( 'E' == $options['acting_settings']['telecom']['stype'][0] ) {
1460 $options['acting_settings']['telecom']['send_url'] = "https://www.credit-cgiserver.com/inetcredit/secure/order.pl";
1461 } else {
1462 $options['acting_settings']['telecom']['send_url'] = "https://secure.telecomcredit.co.jp/inetcredit/secure/order.pl";
1463 }
1464 $this->payment_structure['acting_telecom_card'] = 'カード決済(テレコムクレジット)';
1465 }else{
1466 unset($this->payment_structure['acting_telecom_card']);
1467 }
1468 if( 'on' == $options['acting_settings']['telecom']['edy_activate'] ){
1469 $options['acting_settings']['telecom']['send_url_edy'] = "https://secure.telecomcredit.co.jp/payment/edy/order.pl";
1470 $this->payment_structure['acting_telecom_edy'] = 'Edy決済(テレコムクレジット)';
1471 }else{
1472 unset($this->payment_structure['acting_telecom_edy']);
1473 }
1474 }else{
1475 $this->action_status = 'error';
1476 $this->action_message = __('データに不備が有ります','usces');
1477 $options['acting_settings']['telecom']['activate'] = 'off';
1478 unset($this->payment_structure['acting_telecom_card']);
1479 unset($this->payment_structure['acting_telecom_edy']);
1480 }
1481 ksort($this->payment_structure);
1482 update_option('usces_payment_structure', $this->payment_structure);
1483 update_option('usces', $options);
1484 break;
1485 //20120618ysk end
1486 //20121206ysk start
1487 case 'digitalcheck':
1488 unset( $options['acting_settings']['digitalcheck'] );
1489 $options['acting_settings']['digitalcheck']['card_activate'] = isset($_POST['card_activate']) ? $_POST['card_activate'] : '';
1490 $options['acting_settings']['digitalcheck']['card_ip'] = isset($_POST['card_ip']) ? $_POST['card_ip'] : '';
1491 $options['acting_settings']['digitalcheck']['card_pass'] = isset($_POST['card_pass']) ? $_POST['card_pass'] : '';
1492 $options['acting_settings']['digitalcheck']['card_kakutei'] = isset($_POST['card_kakutei']) ? $_POST['card_kakutei'] : '';
1493 $options['acting_settings']['digitalcheck']['card_user_id'] = isset($_POST['card_user_id']) ? $_POST['card_user_id'] : '';
1494 $options['acting_settings']['digitalcheck']['conv_activate'] = isset($_POST['conv_activate']) ? $_POST['conv_activate'] : '';
1495 $options['acting_settings']['digitalcheck']['conv_ip'] = isset($_POST['conv_ip']) ? $_POST['conv_ip'] : '';
1496 $options['acting_settings']['digitalcheck']['conv_store'] = isset($_POST['conv_store']) ? $_POST['conv_store'] : array();
1497 $options['acting_settings']['digitalcheck']['conv_kigen'] = isset($_POST['conv_kigen']) ? $_POST['conv_kigen'] : '14';
1498
1499 if( 'on' == $options['acting_settings']['digitalcheck']['card_activate'] ) {
1500 if( '' == trim($_POST['card_ip']) )
1501 $mes .= '※加盟店コードを�
1502 �力して下さい<br />';
1503 if( 'on' == $options['acting_settings']['digitalcheck']['card_user_id'] ) {
1504 if( '' == trim($_POST['card_pass']) )
1505 $mes .= '※加盟店パスワードを�
1506 �力して下さい<br />';
1507 }
1508 }
1509 if( 'on' == $options['acting_settings']['digitalcheck']['conv_activate'] ) {
1510 if( '' == trim($_POST['conv_ip']) )
1511 $mes .= '※加盟店コードを�
1512 �力して下さい<br />';
1513 if( empty($_POST['conv_store']) )
1514 $mes .= '※利用コンビニを選択して下さい<br />';
1515 }
1516
1517 if( '' == $mes ){
1518 $this->action_status = 'success';
1519 $this->action_message = __('options are updated','usces');
1520 $options['acting_settings']['digitalcheck']['activate'] = 'on';
1521 if( 'on' == $options['acting_settings']['digitalcheck']['card_activate'] ){
1522 $options['acting_settings']['digitalcheck']['send_url_card'] = "https://www.digitalcheck.jp/settle/settle3/bp3.dll";
1523 if( 'on' == $options['acting_settings']['digitalcheck']['card_user_id'] ) {
1524 $options['acting_settings']['digitalcheck']['send_url_user_id'] = "https://www.digitalcheck.jp/settle/settlex/credit2.dll";
1525 } else {
1526 $options['acting_settings']['digitalcheck']['send_url_user_id'] = "";
1527 }
1528 $this->payment_structure['acting_digitalcheck_card'] = 'カード決済(デジタルチェック)';
1529 }else{
1530 unset($this->payment_structure['acting_digitalcheck_card']);
1531 }
1532 if( 'on' == $options['acting_settings']['digitalcheck']['conv_activate'] ){
1533 //$options['acting_settings']['digitalcheck']['send_url_conv'] = "https://www.digitalcheck.jp/settle/settle2/ubp3.dll";
1534 $options['acting_settings']['digitalcheck']['send_url_conv'] = "https://www.digitalcheck.jp/settle/settle3/bp3.dll";
1535 $this->payment_structure['acting_digitalcheck_conv'] = 'コンビニ決済(デジタルチェック)';
1536 }else{
1537 unset($this->payment_structure['acting_digitalcheck_conv']);
1538 }
1539 }else{
1540 $this->action_status = 'error';
1541 $this->action_message = __('データに不備が有ります','usces');
1542 $options['acting_settings']['digitalcheck']['activate'] = 'off';
1543 unset($this->payment_structure['acting_digitalcheck_card']);
1544 unset($this->payment_structure['acting_digitalcheck_conv']);
1545 }
1546 ksort($this->payment_structure);
1547 update_option('usces_payment_structure', $this->payment_structure);
1548 update_option('usces', $options);
1549 break;
1550 //20121206ysk end
1551 //20130225ysk start
1552 case 'mizuho':
1553 unset( $options['acting_settings']['mizuho'] );
1554 $options['acting_settings']['mizuho']['shopid'] = isset($_POST['shopid']) ? $_POST['shopid'] : '';
1555 $options['acting_settings']['mizuho']['cshopid'] = isset($_POST['cshopid']) ? $_POST['cshopid'] : '';
1556 $options['acting_settings']['mizuho']['hash_pass'] = isset($_POST['hash_pass']) ? $_POST['hash_pass'] : '';
1557 $options['acting_settings']['mizuho']['ope'] = isset($_POST['ope']) ? $_POST['ope'] : '';
1558 $options['acting_settings']['mizuho']['send_url'] = isset($_POST['send_url']) ? $_POST['send_url'] : '';
1559 $options['acting_settings']['mizuho']['send_url_mbl'] = isset($_POST['send_url_mbl']) ? $_POST['send_url_mbl'] : '';
1560 $options['acting_settings']['mizuho']['card_activate'] = isset($_POST['card_activate']) ? $_POST['card_activate'] : '';
1561 $options['acting_settings']['mizuho']['conv1_activate'] = isset($_POST['conv1_activate']) ? $_POST['conv1_activate'] : '';
1562 $options['acting_settings']['mizuho']['conv2_activate'] = isset($_POST['conv2_activate']) ? $_POST['conv2_activate'] : '';
1563
1564 //if( 'on' == $options['acting_settings']['mizuho']['card_activate'] or 'on' == $options['acting_settings']['mizuho']['conv_activate'] ) {
1565 if( '' == trim($_POST['shopid']) )
1566 $mes .= '※加盟店コードを�
1567 �力して下さい<br />';
1568 if( '' == trim($_POST['cshopid']) )
1569 $mes .= '※加盟店サブコードを�
1570 �力して下さい<br />';
1571 if( '' == trim($_POST['hash_pass']) )
1572 $mes .= '※ハッシュ用パスワードを�
1573 �力して下さい<br />';
1574 //}
1575 if( isset($_POST['ope']) && 'public' == $_POST['ope'] && empty($_POST['send_url']) )
1576 $mes .= '※本番URLを�
1577 �力して下さい<br />';
1578 if( defined('WCEX_MOBILE') and isset($_POST['ope']) && 'public' == $_POST['ope'] && empty($_POST['send_url_mbl']) )
1579 $mes .= '※本番URL(携帯)を�
1580 �力して下さい<br />';
1581
1582 if( '' == $mes ) {
1583 $this->action_status = 'success';
1584 $this->action_message = __('options are updated','usces');
1585 $options['acting_settings']['mizuho']['activate'] = 'on';
1586 $options['acting_settings']['mizuho']['send_url_test'] = "https://210.161.141.207/mltbank/MBWebFrontPayment";
1587 if( defined('WCEX_MOBILE') ) $options['acting_settings']['mizuho']['send_url_mbl_test'] = "https://210.161.141.207/mltbank/iMBWebFrontPayment";
1588 if( 'on' == $options['acting_settings']['mizuho']['card_activate'] ) {
1589 $this->payment_structure['acting_mizuho_card'] = 'カード決済(みずほファクター)';
1590 } else {
1591 unset($this->payment_structure['acting_mizuho_card']);
1592 }
1593 if( 'on' == $options['acting_settings']['mizuho']['conv1_activate'] ) {
1594 $this->payment_structure['acting_mizuho_conv1'] = 'コンビニ・ウェルネット決済(みずほファクター)';
1595 } else {
1596 unset($this->payment_structure['acting_mizuho_conv1']);
1597 }
1598 if( 'on' == $options['acting_settings']['mizuho']['conv2_activate'] ) {
1599 $this->payment_structure['acting_mizuho_conv2'] = 'コンビニ・セブンイレブン決済(みずほファクター)';
1600 } else {
1601 unset($this->payment_structure['acting_mizuho_conv2']);
1602 }
1603 } else {
1604 $this->action_status = 'error';
1605 $this->action_message = __('データに不備が有ります','usces');
1606 $options['acting_settings']['mizuho']['activate'] = 'off';
1607 unset($this->payment_structure['acting_mizuho_card']);
1608 unset($this->payment_structure['acting_mizuho_conv1']);
1609 unset($this->payment_structure['acting_mizuho_conv2']);
1610 }
1611 ksort($this->payment_structure);
1612 update_option('usces_payment_structure', $this->payment_structure);
1613 update_option('usces', $options);
1614 break;
1615 //20130225ysk end
1616 }
1617
1618
1619 }
1620
1621
1622 $this->options = get_option('usces');
1623
1624 require_once(USCES_PLUGIN_DIR . '/includes/admin_settlement.php');
1625 }
1626
1627 /********************************************************************************/
1628 function selected( $selected, $current) {
1629 if ( $selected == $current)
1630 echo ' selected="selected"';
1631 }
1632 /********************************************************************************/
1633
1634 function usces_session_start() {
1635 $options = get_option('usces');
1636 if( !isset($options['usces_key']) || empty($options['usces_key']) ){
1637 $options['usces_key'] = uniqid('uk');
1638 update_option('usces', $options);
1639 }
1640
1641 if(defined( 'USCES_KEY' )){
1642 if( is_admin() || preg_match('/\/wp-login\.php/', $_SERVER['REQUEST_URI']) ){
1643 session_name( 'adm'.USCES_KEY );
1644 }else{
1645 session_name( USCES_KEY );
1646 }
1647 }else{
1648 if( is_admin() || preg_match('/\/wp-login\.php/', $_SERVER['REQUEST_URI']) ){
1649 session_name( 'adm'.$options['usces_key'] );
1650 }else{
1651 session_name( $options['usces_key'] );
1652 }
1653 }
1654 if(isset($_GET['uscesid']) && !WCUtils::is_blank($_GET['uscesid'])) {
1655 $sessid = $_GET['uscesid'];
1656 $sessid = $this->uscesdc($sessid);
1657 session_id($sessid);
1658 }
1659
1660 @session_start();
1661
1662 //20111222ysk start 0000367
1663 //if ( !isset($_SESSION['usces_member']) ){
1664 if ( !isset($_SESSION['usces_member']) || $options['membersystem_state'] != 'activate' ){
1665 //20111222ysk end
1666 $_SESSION['usces_member'] = array();
1667 }
1668
1669 if(!isset($_SESSION['usces_checked_business_days']))
1670 $this->update_business_days();
1671 }
1672
1673 function usces_cookie() {
1674 if(is_admin()) return;
1675
1676 $actionflag = false;
1677 $sess = NULL;
1678 $addr = NULL;
1679 $rckid = NULL;
1680 $none = NULL;
1681 $cookie = $this->get_cookie();
1682
1683 if( isset($_GET['uscesid']) && !WCUtils::is_blank($_GET['uscesid']) ){
1684 $sessid = base64_decode(urldecode($_GET['uscesid']));
1685 list($sess, $addr, $rckid, $none) = explode('_', $sessid, 4);
1686 }
1687 if('acting' == $addr) return;
1688
1689 if( apply_filters( 'usces_filter_cookie', false) ) return;
1690
1691 //There is a need to consider.
1692 return;
1693
1694 if( $this->use_ssl && ($this->is_cart_or_member_page($_SERVER['REQUEST_URI']) || $this->is_inquiry_page($_SERVER['REQUEST_URI']))){
1695
1696 $refer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL;
1697 $sslid = isset($cookie['sslid']) ? $cookie['sslid'] : NULL;
1698 $option = get_option('usces');
1699 $parsed = parse_url(get_option('home'));
1700 $home = $parsed['host'] . (isset($parsed['path']) ? $parsed['path'] : '');
1701 $parsed = parse_url($option['ssl_url']);
1702 $sslhome = $parsed['host'] . (isset($parsed['path']) ? $parsed['path'] : '');
1703
1704 //usces_log('refer : '.$refer, 'acting_transaction.log');
1705 // usces_log('sslid : '.$sslid, 'acting_transaction.log');
1706 // usces_log('rckid : '.$rckid, 'acting_transaction.log');
1707 // usces_log('usces_cookieid : '.$_SESSION['usces_cookieid'], 'acting_transaction.log');
1708 // usces_log('request : '.print_r($_SERVER['REQUEST_URI'],true), 'acting_transaction.log');
1709
1710 if( empty($refer) || (false === strpos($refer, $home) && false === strpos($refer, $sslhome)) ){
1711 if( !empty($sslid) && !empty($rckid) && $sslid === $rckid ){
1712 $actionflag = true;
1713 }else{
1714 $actionflag = false;
1715 }
1716 }else{
1717 if( !empty($sslid) && $sslid !== $rckid ){
1718 $actionflag = false;
1719 }else{
1720 $actionflag = true;
1721 }
1722 }
1723
1724
1725 if( $actionflag ){
1726 $values = array(
1727 'id' => $rckid,
1728 'sslid' => $rckid,
1729 'name' => '',
1730 'rme' => ''
1731 );
1732 if( 'acting' !== $rckid ){
1733 $this->set_cookie($values);
1734 }
1735 }else{
1736 if( 'acting' !== $rckid ){
1737 unset($_SESSION['usces_member'], $_SESSION['usces_cart'], $_SESSION['usces_entry'] );
1738 wp_redirect( 'http://'.$home );
1739 }
1740 }
1741 }else{
1742 if( !isset($cookie['id']) || WCUtils::is_blank($cookie['id']) ) {
1743 $values = array(
1744 'id' => md5(uniqid(rand(), true)),
1745 'name' => '',
1746 'rme' => ''
1747 );
1748 $this->set_cookie($values);
1749 $_SESSION['usces_cookieid'] = $values['id'];
1750 } else {
1751 if( !isset($_SESSION['usces_cookieid']) || $_SESSION['usces_cookieid'] != $cookie['id'])
1752 $_SESSION['usces_cookieid'] = $cookie['id'];
1753 }
1754
1755 $actionflag = true;
1756 }
1757
1758 }
1759
1760 function set_cookie($values){
1761 $value = serialize($values);
1762 $timeout = time()+7*86400;
1763 $domain = $_SERVER['SERVER_NAME'];
1764 $res = setcookie('usces_cookie', $value, $timeout, USCES_COOKIEPATH, $domain);
1765 }
1766
1767 function get_cookie() {
1768 $values = isset($_COOKIE['usces_cookie']) ? unserialize(stripslashes($_COOKIE['usces_cookie'])) : NULL;
1769 return $values;
1770 }
1771
1772 function get_access( $key, $type, $date ) {
1773 global $wpdb;
1774 $table_name = $wpdb->prefix . "usces_access";
1775
1776 $query = $wpdb->prepare("SELECT acc_value FROM $table_name WHERE acc_key = %s AND acc_type = %s AND acc_date = %s", $key, $type, $date);
1777 $value = $wpdb->get_var( $query );
1778 if( !$value ){
1779 $res = NULL;
1780 }else{
1781 $res = unserialize($value);
1782 }
1783
1784 return $res;
1785 }
1786
1787 function get_access_piriod( $key, $type, $startday, $endday ) {
1788 global $wpdb;
1789 $table_name = $wpdb->prefix . "usces_access";
1790 //$wpdb->show_errors();
1791 $query = $wpdb->prepare("SELECT acc_type, acc_value, acc_date FROM $table_name WHERE acc_key = %s AND acc_type = %s AND (acc_date >= %s AND acc_date <= %s)", $key, $type, $startday, $endday);
1792 $res = $wpdb->get_results( $query, ARRAY_A );
1793
1794 return $res;
1795 }
1796
1797 function update_access( $array ) {
1798 global $wpdb;
1799 $table_name = $wpdb->prefix . "usces_access";
1800
1801 $query = $wpdb->prepare("SELECT ID FROM $table_name WHERE acc_key = %s AND acc_type = %s AND acc_date = %s", $array['acc_key'], $array['acc_type'], $array['acc_date']);
1802 $res = $wpdb->get_var( $query );
1803 //$wpdb->show_errors();
1804 if(empty($res)){
1805 $query = $wpdb->prepare("INSERT INTO $table_name (acc_key, acc_type, acc_value, acc_date) VALUES(%s, %s, %s, %s)", $array['acc_key'], $array['acc_type'], serialize($array['acc_value']), $array['acc_date']);
1806 $wpdb->query( $query );
1807 }else{
1808 $query = $wpdb->prepare("UPDATE $table_name SET acc_value = %s WHERE acc_key = %s AND acc_type = %s AND acc_date = %s", serialize($array['acc_value']), $array['acc_key'], $array['acc_type'], $array['acc_date']);
1809 $wpdb->query( $query );
1810 }
1811 }
1812
1813 function get_uscesid( $flag = true) {
1814
1815 $sessname = session_name();
1816 $sessid = session_id();
1817 $sessid = $this->uscescv($sessid, $flag);
1818 return $sessid;
1819 }
1820
1821 function shop_head() {
1822 global $post;
1823 $this->item = $post;
1824 $no_cart_css = isset($this->options['system']['no_cart_css']) ? $this->options['system']['no_cart_css'] : 0;
1825
1826 if( $this->is_cart_or_member_page($_SERVER['REQUEST_URI']) || $this->is_inquiry_page($_SERVER['REQUEST_URI']) ){
1827 $css_url = USCES_FRONT_PLUGIN_URL . '/css/usces_cart.css';
1828 }else{
1829 $css_url = USCES_WP_CONTENT_URL . '/plugins/' . USCES_PLUGIN_FOLDER . '/css/usces_cart.css';
1830 }
1831 if( $this->is_cart_or_member_page($_SERVER['REQUEST_URI']) ){
1832 echo " <meta name='robots' content='noindex,nofollow' />\n";
1833 wp_print_scripts( array( 'sack' ));
1834 }
1835 if( !$no_cart_css ){
1836 echo '<link href="' . $css_url . '" rel="stylesheet" type="text/css" />';
1837 }
1838 if( file_exists(get_stylesheet_directory() . '/usces_cart.css') ){
1839 echo '<link href="' . get_stylesheet_directory_uri() . '/usces_cart.css" rel="stylesheet" type="text/css" />';
1840 }
1841 }
1842
1843 function shop_foot() {
1844 global $current_user;
1845 $item = $this->item;
1846 if( empty($item) ){
1847 $item->ID = 0;
1848 $item->post_mime_type = '';
1849 }
1850 get_currentuserinfo();
1851 if( $this->is_cart_or_member_page($_SERVER['REQUEST_URI']) || $this->is_inquiry_page($_SERVER['REQUEST_URI']) ){
1852 $javascript_url = USCES_FRONT_PLUGIN_URL . '/js/usces_cart.js';
1853 }else{
1854 $javascript_url = USCES_WP_CONTENT_URL . '/plugins/' . USCES_PLUGIN_FOLDER . '/js/usces_cart.js';
1855 }
1856 $this->member_name = ( is_user_logged_in() ) ? esc_js(get_user_meta($current_user->ID,'first_name').get_user_meta($current_user->ID,'last_name')) : '';
1857 $this->previous_url = isset($_SESSION['usces_previous_url']) ? $_SESSION['usces_previous_url'] : get_home_url();
1858
1859 // usces_log('post_type : '.$item->post_mime_type, 'test.log');
1860 // usces_log('is_single : '.(is_single() ? 'true' : 'false'), 'test.log');
1861
1862 if( $this->use_js && empty($this->item) && !is_admin() ) :
1863 ?>
1864 <script type='text/javascript'>
1865 /* <![CDATA[ */
1866 uscesL10n = {
1867 <?php echo apply_filters('usces_filter_uscesL10n', NULL, $item->ID); ?>
1868 'ajaxurl': "<?php echo $this->ssl_admin_ajax_url(); ?>"
1869 }
1870 /* ]]> */
1871 </script>
1872 <?php elseif( $this->use_js && !empty($this->item) ) :
1873
1874 $ioptkeys = $this->get_itemOptionKey( $item->ID );
1875 $mes_opts_str = "";
1876 $key_opts_str = "";
1877 $opt_means = "";
1878 $opt_esse = "";
1879 if($ioptkeys){
1880 foreach($ioptkeys as $key => $value){
1881 $optValues = $this->get_itemOptions( $value, $item->ID );
1882 if($optValues['means'] < 2){
1883 $mes_opts_str .= "'" . sprintf(__("Chose the %s", 'usces'), esc_js($value)) . "',";
1884 }else{
1885 $mes_opts_str .= "'" . sprintf(__("Input the %s", 'usces'), esc_js($value)) . "',";
1886 }
1887 $key_opts_str .= "'" . urlencode(esc_js($value)) . "',";
1888 $opt_means .= "'" . esc_js($optValues['means']) . "',";
1889 $opt_esse .= "'" . esc_js($optValues['essential']) . "',";
1890 }
1891 $mes_opts_str = rtrim($mes_opts_str, ',');
1892 $key_opts_str = rtrim($key_opts_str, ',');
1893 $opt_means = rtrim($opt_means, ',');
1894 $opt_esse = rtrim($opt_esse, ',');
1895 }
1896 //$itemRestriction = get_post_custom_values('_itemRestriction', $item->ID);
1897 $itemRestriction = get_post_meta($item->ID, '_itemRestriction', true);
1898
1899 ?>
1900 <script type='text/javascript'>
1901 /* <![CDATA[ */
1902 uscesL10n = {
1903 <?php echo apply_filters('usces_filter_uscesL10n', NULL, $item->ID); ?>
1904 'ajaxurl': "<?php echo $this->ssl_admin_ajax_url(); ?>",
1905 'post_id': "<?php echo $item->ID; ?>",
1906 'cart_number': "<?php echo get_option('usces_cart_number'); ?>",
1907 'is_cart_row': <?php echo ( (0 < $this->cart->num_row()) ? 'true' : 'false'); ?>,
1908 'opt_esse': new Array( <?php echo $opt_esse; ?> ),
1909 'opt_means': new Array( <?php echo $opt_means; ?> ),
1910 'mes_opts': new Array( <?php echo $mes_opts_str; ?> ),
1911 'key_opts': new Array( <?php echo $key_opts_str; ?> ),
1912 'previous_url': "<?php echo $this->previous_url; ?>",
1913 'itemRestriction': "<?php echo $itemRestriction; ?>"
1914 }
1915 /* ]]> */
1916 </script>
1917 <script type='text/javascript' src='<?php echo $javascript_url; ?>'></script>
1918 <?php endif; ?>
1919 <?php //if( !is_home() && !is_front_page() && $this->use_js && (is_page(USCES_CART_NUMBER) || $this->is_cart_page($_SERVER['REQUEST_URI']) || ('item' == $item->post_mime_type)) ) : ?>
1920 <?php if( $this->use_js && (is_page(USCES_CART_NUMBER) || $this->is_cart_page($_SERVER['REQUEST_URI']) || (is_singular() && 'item' == $item->post_mime_type)) ) : ?>
1921 <script type='text/javascript'>
1922 (function($) {
1923 uscesCart = {
1924 intoCart : function (post_id, sku) {
1925
1926 var zaikonum = document.getElementById("zaikonum["+post_id+"]["+sku+"]").value;
1927 var zaiko = document.getElementById("zaiko["+post_id+"]["+sku+"]").value;
1928 if( (zaiko != '0' && zaiko != '1') || parseInt(zaikonum) == 0 ){
1929 alert('<?php _e('temporaly out of stock now', 'usces'); ?>');
1930 return false;
1931 }
1932
1933 var mes = '';
1934 if(document.getElementById("quant["+post_id+"]["+sku+"]")){
1935 var quant = document.getElementById("quant["+post_id+"]["+sku+"]").value;
1936 if( quant == '0' || quant == '' || !(uscesCart.isNum(quant))){
1937 mes += "<?php _e('enter the correct amount', 'usces'); ?>\n";
1938 }
1939 var checknum = '';
1940 var checkmode = '';
1941 if( parseInt(uscesL10n.itemRestriction) <= parseInt(zaikonum) && uscesL10n.itemRestriction != '' && uscesL10n.itemRestriction != '0' && zaikonum != '' ) {
1942 checknum = uscesL10n.itemRestriction;
1943 checkmode ='rest';
1944 } else if( parseInt(uscesL10n.itemRestriction) > parseInt(zaikonum) && uscesL10n.itemRestriction != '' && uscesL10n.itemRestriction != '0' && zaikonum != '' ) {
1945 checknum = zaikonum;
1946 checkmode ='zaiko';
1947 } else if( (uscesL10n.itemRestriction == '' || uscesL10n.itemRestriction == '0') && zaikonum != '' ) {
1948 checknum = zaikonum;
1949 checkmode ='zaiko';
1950 } else if( uscesL10n.itemRestriction != '' && uscesL10n.itemRestriction != '0' && zaikonum == '' ) {
1951 checknum = uscesL10n.itemRestriction;
1952 checkmode ='rest';
1953 }
1954
1955
1956 if( parseInt(quant) > parseInt(checknum) && checknum != '' ){
1957 if(checkmode == 'rest'){
1958 mes += <?php _e("'This article is limited by '+checknum+' at a time.'", 'usces'); ?>+"\n";
1959 }else{
1960 mes += <?php _e("'Stock is remainder '+checknum+'.'", 'usces'); ?>+"\n";
1961 }
1962 }
1963 }
1964 for(i=0; i<uscesL10n.key_opts.length; i++){
1965 var skuob = document.getElementById("itemOption["+post_id+"]["+sku+"]["+uscesL10n.key_opts[i]+"]");
1966 if( uscesL10n.opt_esse[i] == '1' ){
1967
1968 if( uscesL10n.opt_means[i] < 2 && skuob.value == '#NONE#' ){
1969 mes += uscesL10n.mes_opts[i]+"\n";
1970 }else if( uscesL10n.opt_means[i] >= 2 && skuob.value == '' ){
1971 mes += uscesL10n.mes_opts[i]+"\n";
1972 }
1973 }
1974 }
1975
1976 <?php apply_filters( 'usces_filter_inCart_js_check', $item->ID ); //Unavailable ?>
1977 <?php do_action( 'usces_action_inCart_js_check', $item->ID ); ?>
1978
1979 if( mes != '' ){
1980 alert( mes );
1981 return false;
1982 }else{
1983 <?php echo apply_filters('usces_filter_js_intoCart', "return true;\n", $item->ID, NULL); ?>
1984 }
1985 },
1986
1987 upCart : function () {
1988
1989 var zaikoob = $("input[name*='zaikonum']");
1990 var quantob = $("input[name*='quant']");
1991 var postidob = $("input[name*='itempostid']");
1992 var skuob = $("input[name*='itemsku']");
1993
1994 var zaikonum = '';
1995 var zaiko = '';
1996 var quant = '';
1997 var mes = '';
1998 var checknum = '';
1999 var post_id = '';
2000 var sku = '';
2001 var itemRestriction = '';
2002
2003 var ct = zaikoob.length;
2004 for(var i=0; i< ct; i++){
2005 post_id = postidob[i].value;
2006 sku = skuob[i].value;
2007 itemRestriction = $("input[name='itemRestriction\[" + i + "\]']").val();
2008 zaikonum = $("input[name='zaikonum\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").val();
2009
2010 quant = $("input[name='quant\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").val();
2011 if( $("input[name='quant\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']") ){
2012 if( quant == '0' || quant == '' || !(uscesCart.isNum(quant))){
2013 mes += <?php _e("'enter the correct amount for the No.' + (i+1) + ' item'", 'usces'); ?>+"\n";
2014 }
2015 var checknum = '';
2016 var checkmode = '';
2017 if( parseInt(itemRestriction) <= parseInt(zaikonum) && itemRestriction != '' && itemRestriction != '0' && zaikonum != '' ) {
2018 checknum = itemRestriction;
2019 checkmode ='rest';
2020 } else if( parseInt(itemRestriction) > parseInt(zaikonum) && itemRestriction != '' && itemRestriction != '0' && zaikonum != '' ) {
2021 checknum = zaikonum;
2022 checkmode ='zaiko';
2023 } else if( (itemRestriction == '' || itemRestriction == '0') && zaikonum != '' ) {
2024 checknum = zaikonum;
2025 checkmode ='zaiko';
2026 } else if( itemRestriction != '' && itemRestriction != '0' && zaikonum == '' ) {
2027 checknum = itemRestriction;
2028 checkmode ='rest';
2029 }
2030 if( parseInt(quant) > parseInt(checknum) && checknum != '' ){
2031 if(checkmode == 'rest'){
2032 mes += <?php _e("'This article is limited by '+checknum+' at a time for the No.' + (i+1) + ' item.'", 'usces'); ?>+"\n";
2033 }else{
2034 mes += <?php _e("'Stock of No.' + (i+1) + ' item is remainder '+checknum+'.'", 'usces'); ?>+"\n";
2035 }
2036 }
2037 }
2038 }
2039
2040 <?php apply_filters( 'usces_filter_upCart_js_check', $item->ID ); //Unavailable ?>
2041 <?php do_action( 'usces_action_upCart_js_check', $item->ID ); ?>
2042
2043 if( mes != '' ){
2044 alert( mes );
2045 return false;
2046 }else{
2047 <?php echo apply_filters('usces_filter_js_upCart', "return true;\n", $item->ID, NULL); ?>
2048 }
2049 },
2050
2051 cartNext : function () {
2052
2053 var zaikoob = $("input[name*='zaikonum']");
2054 var quantob = $("input[name*='quant']");
2055 var postidob = $("input[name*='itempostid']");
2056 var skuob = $("input[name*='itemsku']");
2057
2058 var zaikonum = '';
2059 var zaiko = '';
2060 var quant = '';
2061 var mes = '';
2062 var checknum = '';
2063 var post_id = '';
2064 var sku = '';
2065 var itemRestriction = '';
2066
2067 var ct = zaikoob.length;
2068 for(var i=0; i< ct; i++){
2069 post_id = postidob[i].value;
2070 sku = skuob[i].value;
2071 itemRestriction = $("input[name='itemRestriction\[" + i + "\]']").val();
2072 zaikonum = $("input[name='zaikonum\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").val();
2073
2074 quant = $("input[name='quant\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']").val();
2075 if( $("input[name='quant\[" + i + "\]\[" + post_id + "\]\[" + sku + "\]']") ){
2076 if( quant == '0' || quant == '' || !(uscesCart.isNum(quant))){
2077 mes += <?php _e("'enter the correct amount for the No.' + (i+1) + ' item'", 'usces'); ?>+"\n";
2078 }
2079 var checknum = '';
2080 var checkmode = '';
2081 if( parseInt(itemRestriction) <= parseInt(zaikonum) && itemRestriction != '' && itemRestriction != '0' && zaikonum != '' ) {
2082 checknum = itemRestriction;
2083 checkmode ='rest';
2084 } else if( parseInt(itemRestriction) > parseInt(zaikonum) && itemRestriction != '' && itemRestriction != '0' && zaikonum != '' ) {
2085 checknum = zaikonum;
2086 checkmode ='zaiko';
2087 } else if( (itemRestriction == '' || itemRestriction == '0') && zaikonum != '' ) {
2088 checknum = zaikonum;
2089 checkmode ='zaiko';
2090 } else if( itemRestriction != '' && itemRestriction != '0' && zaikonum == '' ) {
2091 checknum = itemRestriction;
2092 checkmode ='rest';
2093 }
2094
2095 if( parseInt(quant) > parseInt(checknum) && checknum != '' ){
2096 if(checkmode == 'rest'){
2097 mes += <?php _e("'This article is limited by '+checknum+' at a time for the No.' + (i+1) + ' item.'", 'usces'); ?>+"\n";
2098 }else{
2099 mes += <?php _e("'Stock of No.' + (i+1) + ' item is remainder '+checknum+'.'", 'usces'); ?>+"\n";
2100 }
2101 }
2102 }
2103 }
2104 if( mes != '' ){
2105 alert( mes );
2106 return false;
2107 }else{
2108 return true;
2109 }
2110 },
2111
2112 previousCart : function () {
2113 location.href = uscesL10n.previous_url;
2114 },
2115
2116 settings: {
2117 url: uscesL10n.ajaxurl,
2118 type: 'POST',
2119 cache: false,
2120 success: function(data, dataType){
2121 //$("tbody#item-opt-list").html( data );
2122 },
2123 error: function(msg){
2124 //$("#ajax-response").html(msg);
2125 }
2126 },
2127
2128 changeStates : function( country ) {
2129 var s = this.settings;
2130 s.data = "action=change_states_ajax&country=" + country;
2131 s.success = function(data, dataType){
2132 if( 'error' == data ){
2133 alert('error');
2134 }else{
2135 $("select#pref").html( data );
2136 }
2137 };
2138 s.error = function(msg){
2139 alert("error");
2140 };
2141 $.ajax( s );
2142 return false;
2143 },
2144
2145 isNum : function (num) {
2146 if (num.match(/[^0-9]/g)) {
2147 return false;
2148 }
2149 return true;
2150 },
2151 purchase : 0
2152 };
2153 $("#country").change(function () {
2154 var country = $("#country option:selected").val();
2155 $("#newcharging_type option:selected").val()
2156 uscesCart.changeStates( country );
2157 });
2158 $("#purchase_form").submit(function () {
2159 if( 0 == uscesCart.purchase ){
2160 uscesCart.purchase = 1;
2161 return true;
2162 }else{
2163 $("#purchase_button").attr("disabled", "disabled");
2164 $("#back_button").attr("disabled", "disabled");
2165 return false;
2166 }
2167 });
2168
2169 })(jQuery);
2170 </script>
2171 <?php endif; ?>
2172 <?php
2173 usces_states_form_js();
2174 }
2175
2176 function admin_head() {
2177 global $wp_version;
2178 $payments_str = '';
2179 $payments = usces_get_system_option( 'usces_payment_method', 'sort' );
2180 foreach ( (array)$payments as $id => $array ) {
2181 $payments_str .= "'" . esc_js($array['name']) . "': '" . esc_js($array['settlement']) . "', ";
2182 }
2183 $payments_str .= "'" . __('Transfer (prepayment)', 'usces') . "': 'transferAdvance', ";
2184 $payments_str .= "'" . __('Transfer (postpay)', 'usces') . "': 'transferDeferred', ";
2185 $payments_str .= "'" . __('COD', 'usces') . "': 'COD', ";
2186 $payments_str = rtrim($payments_str, ', ');
2187 $wcex_str = '';
2188 $wcex = usces_get_wcex();
2189 foreach ( (array)$wcex as $key => $values ) {
2190 $wcex_str .= "'" . esc_js($key) . "-" . esc_js($values['version']) . "', ";
2191 }
2192 $wcex_str = rtrim($wcex_str, ', ');
2193 if ( version_compare($wp_version, '3.4', '>=') ){
2194 $theme_ob = wp_get_theme();
2195 $theme['Name'] = esc_js($theme_ob->get('Name'));
2196 $theme['Version'] = esc_js($theme_ob->get('Version'));
2197 }else{
2198 $theme = get_theme_data( get_stylesheet_directory().'/style.css' );//20120618ysk
2199 }
2200 ?>
2201
2202 <link href="<?php echo USCES_PLUGIN_URL; ?>/css/admin_style.css" rel="stylesheet" type="text/css" media="all" />
2203 <script type='text/javascript'>
2204 /* <![CDATA[ */
2205 uscesL10n = {
2206 'requestFile': "<?php echo site_url(); ?>/wp-admin/admin-ajax.php",
2207 'USCES_PLUGIN_URL': "<?php echo USCES_PLUGIN_URL; ?>",
2208 'version': "<?php echo USCES_VERSION; ?>",
2209 'wcid': "<?php echo get_option('usces_wcid'); ?>",
2210 'locale': '<?php echo get_locale(); ?>',
2211 'cart_number': "<?php echo get_option('usces_cart_number'); ?>",
2212 'purchase_limit': "<?php echo $this->options['purchase_limit']; ?>",
2213 'point_rate': "<?php echo $this->options['point_rate']; ?>",
2214 'shipping_rule': "<?php echo $this->options['shipping_rule']; ?>",
2215 'theme': "<?php echo $theme['Name'] . '-' . $theme['Version']; ?>",
2216 'wcex': new Array( <?php echo $wcex_str; ?> ),
2217 'now_loading': "<?php _e('now loading', 'usces'); ?>"
2218 };
2219 uscesPayments = {<?php echo $payments_str; ?>};
2220 /* ]]> */
2221 </script>
2222 <script type='text/javascript' src='<?php echo USCES_PLUGIN_URL; ?>/js/usces_admin.js'></script>
2223 <?php
2224 if($this->action_status == 'edit' || $this->action_status == 'editpost'){
2225 ?>
2226 <link rel='stylesheet' href='<?php echo get_option('siteurl'); ?>/wp-includes/js/thickbox/thickbox.css' type='text/css' media='all' />
2227 <?php
2228 }
2229 if( isset($_REQUEST['page']) ){
2230 switch( $_REQUEST['page'] ){
2231 case 'usces_initial':
2232 ?>
2233 <script type='text/javascript'>
2234 /* <![CDATA[ */
2235 usces_ini = {
2236 'cod_type': "<?php if( 'change' == $this->options['cod_type'] ) {echo 'change';}else{echo 'fix';} ?>",
2237 'cod_type_fix': "<?php echo esc_js(__('Fixation C.O.D.', 'usces')); ?>",
2238 'cod_type_change': "<?php echo esc_js(__('Variable C.O.D.', 'usces')); ?>",
2239 'cod_unit': "<?php echo esc_js(__('dollars', 'usces')); ?>",
2240 'cod_failure': "<?php echo esc_js(__('failure in update', 'usces')); ?>",
2241 'cod_updated': "<?php echo esc_js(__('options are updated', 'usces')); ?>",
2242 'cod_limit': "<?php echo esc_js(__('A value of the amount of upper limit is dirty.', 'usces')); ?>"
2243 };
2244 /* ]]> */
2245 </script>
2246 <?php
2247 break;
2248 case 'usces_itemnew':
2249 case 'usces_itemedit':
2250 ?>
2251 <style type="text/css">
2252 <!--
2253 #usces_mess {
2254 color: #FF0000;
2255 font-weight: bold;
2256 }
2257 -->
2258 </style>
2259 <?php
2260 break;
2261 }
2262 }
2263 ?>
2264 <?php
2265 if( is_admin() && ( (isset($_GET['order_action']) && 'newpost' == $_GET['order_action'])
2266 || (isset($_GET['page']) && 'usces_ordernew' == $_GET['page'])
2267 || (isset($_GET['order_action']) && 'edit' == $_GET['order_action'])
2268 || (isset($_GET['order_action']) && 'editpost' == $_GET['order_action'])
2269 || (isset($_GET['member_action']) && 'edit' == $_GET['member_action'])
2270 || (isset($_GET['member_action']) && 'editpost' == $_GET['member_action'])) ) :
2271 switch( $_GET['page'] ){
2272 case 'usces_ordernew':
2273 case 'usces_orderlist':
2274 $admin_page = 'order';
2275 break;
2276 case 'usces_memberlist':
2277 $admin_page = 'member';
2278 break;
2279 }
2280 ?>
2281 <script type='text/javascript'>
2282 jQuery(function($) {
2283 uscesForm = {
2284 settings: {
2285 url: uscesL10n.requestFile,
2286 type: 'POST',
2287 cache: false,
2288 success: function(data, dataType){
2289 //$("tbody#item-opt-list").html( data );
2290 },
2291 error: function(msg){
2292 //$("#ajax-response").html(msg);
2293 }
2294 },
2295
2296 changeStates : function( country, type ) {
2297 var s = this.settings;
2298 s.data = "action=change_states_ajax&country=" + country;
2299 s.success = function(data, dataType){
2300 if( 'error' == data ){
2301 alert('error');
2302 }else{
2303 $("select#" + type + "_pref").html( data );
2304 if( customercountry == country && 'customer' == type ){
2305 $("#" + type + "_pref").attr({selectedIndex:customerstate});
2306 }else if( deliverycountry == country && 'delivery' == type ){
2307 $("#" + type + "_pref").attr({selectedIndex:deliverystate});
2308 }else if( customercountry == country && 'member' == type ){
2309 $("#" + type + "_pref").attr({selectedIndex:customerstate});
2310 }
2311 }
2312 };
2313 s.error = function(msg){
2314 alert("error");
2315 };
2316 $.ajax( s );
2317 return false;
2318 },
2319
2320 isNum : function (num) {
2321 if (num.match(/[^0-9]/g)) {
2322 return false;
2323 }
2324 return true;
2325 }
2326 };
2327 <?php
2328 if( 'order' == $admin_page ){
2329 ?>
2330 if( undefined != $("#customer_pref").get(0) && undefined != $("#delivery_country").get(0) ) {
2331 var customerstate = $("#customer_pref").get(0).selectedIndex;
2332 var customercountry = $("#customer_country").val();
2333 var deliverystate = $("#delivery_pref").get(0).selectedIndex;
2334 var deliverycountry = $("#delivery_country").val();
2335
2336 $("#customer_country").change(function () {
2337 var country = $("#customer_country option:selected").val();
2338 uscesForm.changeStates( country, 'customer' );
2339 });
2340 $("#delivery_country").change(function () {
2341 var country = $("#delivery_country option:selected").val();
2342 uscesForm.changeStates( country, 'delivery' );
2343 });
2344 }
2345 <?php
2346 }else if( 'member' == $admin_page ){
2347 ?>
2348 if( undefined != $("#member_pref").get(0) ) {
2349 var customerstate = $("#member_pref").get(0).selectedIndex;
2350 var customercountry = $("#member_country").val();
2351 var deliverystate = '';
2352 var deliverycountry = '';
2353
2354 $("#member_country").change(function () {
2355 var country = $("#member_country option:selected").val();
2356 uscesForm.changeStates( country, 'member' );
2357 });
2358 }
2359 <?php
2360 }
2361 ?>
2362 });
2363 </script>
2364 <?php
2365 endif;
2366 }
2367
2368 function main() {
2369 global $wpdb, $wp_locale, $wp_version, $post_ID;
2370 global $wp_query, $usces_action, $post, $action, $editing;
2371
2372 update_option('usces_shipping_rule', apply_filters('usces_filter_shipping_rule', get_option('usces_shipping_rule')));
2373 $this->shipping_rule = get_option('usces_shipping_rule');
2374
2375 // $_wp_http_referer = isset($_POST['_wp_http_referer']) ? $_POST['_wp_http_referer'] : 'a';
2376 // if( isset($_POST) && 1 !== preg_match('/(?:plugin|theme)-editor\.php/', $_wp_http_referer) ){
2377 // $_POST = $this->stripslashes_deep_post($_POST);
2378 // }
2379
2380 if( !is_admin() ){
2381 $this->usces_cookie();
2382 }
2383 $this->make_url();
2384
2385 //usces_log('HTTP_REFERER : '.$_SERVER['HTTP_REFERER'], 'acting_transaction.log');
2386 //usces_log('REQUEST_URI : '.$_SERVER['REQUEST_URI'], 'acting_transaction.log');
2387
2388 do_action('usces_main');
2389 $this->update_table();
2390
2391
2392 // if( 'customer' == $this->page ){
2393 // header("Pragma: private");
2394 // header("Cache-Control: private");
2395 // }else{
2396 // header("Pragma: no-cache");
2397 // header("Cache-Control: no-cache");
2398 // }
2399
2400
2401 //var_dump($_REQUEST);
2402 require_once(USCES_PLUGIN_DIR . '/classes/cart.class.php');
2403 $this->cart = new usces_cart();
2404
2405 do_action('usces_after_cart_instant');
2406
2407 if( isset($_REQUEST['page']) && $_REQUEST['page'] == 'usces_itemedit' && isset($_REQUEST['action']) && $_REQUEST['action'] == 'duplicate' ){
2408 $post_id = (int)$_GET['post'];
2409 $new_id = usces_item_dupricate($post_id);
2410 $ref = isset($_REQUEST['usces_referer']) ? urlencode($_REQUEST['usces_referer']) : '';
2411 $url = USCES_ADMIN_URL . '?page=usces_itemedit&action=edit&post=' . $new_id . '&usces_referer=' . $ref;
2412 wp_redirect($url);
2413 exit;
2414 }else if( isset($_REQUEST['page']) && $_REQUEST['page'] == 'usces_itemedit' && isset($_REQUEST['action']) && $_REQUEST['action'] == 'itemcsv' ){
2415 $filename = usces_item_uploadcsv();
2416 $url = USCES_ADMIN_URL . '?page=usces_itemedit&usces_status=none&usces_message=&action=upload_register&regfile='.$filename;
2417 wp_redirect($url);
2418 exit;
2419 }
2420 //20110208ysk start
2421 if('on' == $this->options['acting_settings']['paypal']['ec_activate']) {
2422 require_once(USCES_PLUGIN_DIR . '/classes/paymentPaypal.class.php');
2423 $this->paypal = new usces_paypal();
2424 }
2425 //20110208ysk end
2426
2427 $this->ad_controller();
2428 //$this->controller();
2429
2430
2431
2432 if( isset($_GET['page']) && $_GET['page'] == 'usces_itemnew'){
2433 $itemnew = 'new';
2434 }else{
2435 $itemnew = '';
2436 }
2437
2438 wp_enqueue_script('jquery');
2439
2440 if( is_admin() && isset($_REQUEST['page']) && ((isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit') || $itemnew == 'new' || (isset($_REQUEST['action']) && $_REQUEST['action'] == 'editpost'))) {
2441
2442 if(isset($_REQUEST['action']) && $_REQUEST['action'] != 'editpost' && $itemnew == 'new'){
2443 if ( version_compare($wp_version, '3.0-beta', '>') ){
2444 if ( !isset($_GET['post_type']) )
2445 $post_type = 'post';
2446 elseif ( in_array( $_GET['post_type'], get_post_types( array('public' => true ) ) ) )
2447 $post_type = $_GET['post_type'];
2448 else
2449 wp_die( __('Invalid post type') );
2450 $post_type_object = get_post_type_object($post_type);
2451 $editing = true;
2452 // if ( current_user_can($post_type_object->edit_type_cap) ) {
2453 $post = $this->get_default_post_to_edit30( $post_type, true );
2454 $post_ID = $post->ID;
2455 // }
2456
2457 }else{
2458 $post = $this->get_default_post_to_edit();
2459 }
2460 }else{
2461 if ( version_compare($wp_version, '3.0-beta', '>') ){
2462 if ( isset($_GET['post']) )
2463 $post_id = (int) $_GET['post'];
2464 elseif ( isset($_POST['post_ID']) )
2465 $post_id = (int) $_POST['post_ID'];
2466 else
2467 $post_id = 0;
2468 $post_ID = $post_id;
2469 $post = null;
2470 $post_type_object = null;
2471 $post_type = null;
2472 if ( $post_id ) {
2473 $post = get_post($post_id);
2474 if ( $post ) {
2475 $post_type_object = get_post_type_object($post->post_type);
2476 if ( $post_type_object ) {
2477 $post_type = $post->post_type;
2478 $current_screen->post_type = $post->post_type;
2479 $current_screen->id = $current_screen->post_type;
2480 }
2481 }
2482 } elseif ( isset($_POST['post_type']) ) {
2483 $post_type_object = get_post_type_object($_POST['post_type']);
2484 if ( $post_type_object ) {
2485 $post_type = $post_type_object->name;
2486 $current_screen->post_type = $post_type;
2487 $current_screen->id = $current_screen->post_type;
2488 }
2489 }
2490
2491
2492 // $post = get_post( $post_id, OBJECT, 'edit' );
2493 // if ( $post->post_type == 'page' )
2494 // $post->page_template = get_post_meta( $id, '_wp_page_template', true );
2495
2496 }else{
2497 if(isset($_GET['post'])){
2498 $post_ID = (int) $_GET['post'];
2499 $post = get_post($post_ID);
2500 }else{
2501 $post_ID = isset($_REQUEST['post_ID']) ? (int) $_REQUEST['post_ID'] : 0;
2502 if(!empty($post_ID))
2503 $post = get_post($post_ID);
2504 }
2505 }
2506 // global $wp_query, $usces_action, $post;
2507
2508 }
2509 $editing = true;
2510 wp_enqueue_script('autosave');
2511 wp_enqueue_script('post');
2512 //if ( user_can_richedit() )
2513 //wp_enqueue_script('editor');
2514 add_thickbox();
2515 wp_enqueue_script('media-upload');
2516 wp_enqueue_script('word-count');
2517 wp_enqueue_script( 'admin-comments' );
2518
2519 if ( version_compare($wp_version, '3.3', '<') )
2520 add_action( 'admin_print_footer_scripts', 'wp_tiny_mce', 25 );
2521 wp_enqueue_script('quicktags');
2522
2523 }
2524
2525
2526 if( is_admin() && isset($_REQUEST['page']) ){
2527
2528 wp_enqueue_script('jquery-color');
2529
2530 switch( $_REQUEST['page'] ){
2531
2532 case 'usces_initial':
2533 $js = USCES_FRONT_PLUGIN_URL.'/js/usces_initial.js';
2534 wp_enqueue_script('usces_initial.js', $js, array('jquery-ui-dialog', 'jquery-ui-sortable'));
2535 //wp_enqueue_script('jquery-ui-sortable');
2536 break;
2537
2538 case 'usces_settlement':
2539 wp_enqueue_script('jquery-ui-tabs', array('jquery-ui-core'));
2540 $jquery_cookieUrl = USCES_FRONT_PLUGIN_URL.'/js/jquery.cookie.js';
2541 wp_enqueue_script('jquery-cookie', $jquery_cookieUrl, array('jquery'), '1.0' );
2542 // $item_list_layoutUrl = USCES_FRONT_PLUGIN_URL.'/js/usces_dumy.js';
2543 // wp_enqueue_script('usces_dumy', $item_list_layoutUrl, array('jquery-ui-tabs'), '1.0' );
2544 break;
2545 //20100809ysk start
2546 case 'usces_cart':
2547 wp_enqueue_script('jquery-ui-tabs', array('jquery-ui-core'));
2548 $jquery_cookieUrl = USCES_FRONT_PLUGIN_URL.'/js/jquery.cookie.js';
2549 wp_enqueue_script('jquery-cookie', $jquery_cookieUrl, array('jquery'), '1.0');
2550 break;
2551 //20100809ysk end
2552 //20100818ysk start
2553 case 'usces_member':
2554 wp_enqueue_script('jquery-ui-tabs', array('jquery-ui-core'));
2555 $jquery_cookieUrl = USCES_FRONT_PLUGIN_URL.'/js/jquery.cookie.js';
2556 wp_enqueue_script('jquery-cookie', $jquery_cookieUrl, array('jquery'), '1.0');
2557 break;
2558 //20100818ysk end
2559 //20100908ysk start
2560 case 'usces_orderlist':
2561 case 'usces_ordernew':
2562 wp_enqueue_script('jquery-ui-dialog');
2563 break;
2564 case 'usces_memberlist':
2565 wp_enqueue_script('jquery-ui-dialog');
2566 break;
2567 //20100908ysk end
2568 //20101111ysk start
2569 case 'usces_itemnew':
2570 wp_enqueue_script('jquery-ui-sortable');
2571 break;
2572 case 'usces_itemedit':
2573 if( isset($_REQUEST['action']) && 'upload_register' == $_REQUEST['action'] ){
2574 @ob_end_clean();
2575 ob_start();
2576 }else{
2577 wp_enqueue_script('jquery-ui-sortable');
2578 wp_enqueue_script('jquery-ui-dialog');
2579 }
2580 break;
2581 //20101111ysk end
2582 //20101208ysk start
2583 case 'usces_delivery':
2584 wp_enqueue_script('jquery-ui-tabs', array('jquery-ui-core'));
2585 $jquery_cookieUrl = USCES_FRONT_PLUGIN_URL.'/js/jquery.cookie.js';
2586 wp_enqueue_script('jquery-cookie', $jquery_cookieUrl, array('jquery'), '1.0');
2587 break;
2588 //20101208ysk end
2589 //20110331ysk start
2590 case 'usces_system':
2591 wp_enqueue_script('jquery-ui-tabs', array('jquery-ui-core'));
2592 $jquery_cookieUrl = USCES_FRONT_PLUGIN_URL.'/js/jquery.cookie.js';
2593 wp_enqueue_script('jquery-cookie', $jquery_cookieUrl, array('jquery'), '1.0');
2594 break;
2595 //20110331ysk end
2596 }
2597 }
2598
2599 if( isset($_REQUEST['order_action']) && $_REQUEST['order_action'] == 'pdfout' ){
2600 $this->get_current_member();
2601 $mid = $this->current_member['id'];
2602 $oid = $_GET['order_id'];
2603 if( !is_user_logged_in() && !$this->is_order($mid, $oid) )
2604 die('No permission');
2605 require_once( apply_filters('usces_filter_orderpdf_path', USCES_PLUGIN_DIR . '/includes/order_print.php') );
2606 }
2607
2608 do_action( 'usces_after_main' );
2609 }
2610
2611 function stripslashes_deep_post( $array ){
2612 $res = array();
2613 foreach( $array as $key => $value ){
2614 $key = stripslashes($key);
2615 if( is_array($value) ){
2616 $value = $this->stripslashes_deep_post( $value );
2617 }else{
2618 $value = stripslashes($value);
2619 }
2620 $res[$key] = $value;
2621 }
2622 return $res;
2623 }
2624
2625 function make_url(){
2626
2627 $permalink_structure = get_option('permalink_structure');
2628 //usces_log('use_ssl : '.$this->use_ssl, 'acting_transaction.log');
2629 if($this->use_ssl) {
2630 if( $permalink_structure ){
2631 $this->delim = '&';
2632 $home_perse = parse_url(get_option('home'));
2633 $home_perse_path = isset($home_perse['path']) ? $home_perse['path'] : '';
2634 $home_path = $home_perse['host'].$home_perse_path;
2635 $ssl_perse = parse_url($this->options['ssl_url']);
2636 $ssl_perse_path = isset($ssl_perse['path']) ? $ssl_perse['path'] : '';
2637 $ssl_path = $ssl_perse['host'].$ssl_perse_path;
2638 if( $home_perse_path != $ssl_perse_path ){
2639 if( ! defined('USCES_CUSTOMER_URL') )
2640 define('USCES_CUSTOMER_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_CART_NUMBER . '&customerinfo=1&uscesid=' . $this->get_uscesid());
2641 if( ! defined('USCES_CART_URL') )
2642 define('USCES_CART_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_CART_NUMBER . '&uscesid=' . $this->get_uscesid());
2643 if( ! defined('USCES_LOSTMEMBERPASSWORD_URL') )
2644 define('USCES_LOSTMEMBERPASSWORD_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_MEMBER_NUMBER . '&uscesid=' . $this->get_uscesid() . '&page=lostmemberpassword');
2645 if( ! defined('USCES_NEWMEMBER_URL') )
2646 define('USCES_NEWMEMBER_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_MEMBER_NUMBER . '&uscesid=' . $this->get_uscesid() . '&page=newmember');
2647 if( ! defined('USCES_LOGIN_URL') )
2648 define('USCES_LOGIN_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_MEMBER_NUMBER . '&uscesid=' . $this->get_uscesid() . '&page=login');
2649 if( ! defined('USCES_LOGOUT_URL') )
2650 define('USCES_LOGOUT_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_MEMBER_NUMBER . '&uscesid=' . $this->get_uscesid() . '&page=logout');
2651 if( ! defined('USCES_MEMBER_URL') )
2652 define('USCES_MEMBER_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_MEMBER_NUMBER . '&uscesid=' . $this->get_uscesid());
2653 $inquiry_url = empty( $this->options['inquiry_id'] ) ? '' : $this->options['ssl_url'] . '/index.php?page_id=' . $this->options['inquiry_id'] . '&uscesid=' . $this->get_uscesid();
2654 if( ! defined('USCES_INQUIRY_URL') )
2655 define('USCES_INQUIRY_URL', $inquiry_url);
2656 if( ! defined('USCES_CART_NONSESSION_URL') )
2657 define('USCES_CART_NONSESSION_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_CART_NUMBER);
2658 //20110208ysk start
2659 //define('USCES_PAYPAL_NOTIFY_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_CART_NUMBER . '&acting_return=paypal_ipn&uscesid=' . $this->get_uscesid(false));
2660 if( ! defined('USCES_PAYPAL_NOTIFY_URL') )
2661 define('USCES_PAYPAL_NOTIFY_URL', $this->options['ssl_url'] . '/index.php?page_id=' . USCES_CART_NUMBER . '&acting=paypal_ipn&uscesid=' . $this->get_uscesid(false));
2662 //20110208ysk end
2663 }else{
2664 $ssl_plink_cart = str_replace('http://','https://', str_replace( $home_path, $ssl_path, get_page_link(USCES_CART_NUMBER) ));
2665 $ssl_plink_member = str_replace('http://','https://', str_replace( $home_path, $ssl_path, get_page_link(USCES_MEMBER_NUMBER) ));
2666 if( ! defined('USCES_CUSTOMER_URL') )
2667 define('USCES_CUSTOMER_URL', $ssl_plink_cart . '?uscesid=' . $this->get_uscesid() . '&customerinfo=1');
2668 if( ! defined('USCES_CART_URL') )
2669 define('USCES_CART_URL', $ssl_plink_cart . '?uscesid=' . $this->get_uscesid());
2670 if( ! defined('USCES_LOSTMEMBERPASSWORD_URL') )
2671 define('USCES_LOSTMEMBERPASSWORD_URL', $ssl_plink_member . '?uscesid=' . $this->get_uscesid() . '&page=lostmemberpassword');
2672 if( ! defined('USCES_NEWMEMBER_URL') )
2673 define('USCES_NEWMEMBER_URL', $ssl_plink_member . '?uscesid=' . $this->get_uscesid(). '&page=newmember');
2674 if( ! defined('USCES_LOGIN_URL') )
2675 define('USCES_LOGIN_URL', $ssl_plink_member . '?uscesid=' . $this->get_uscesid() . '&page=login');
2676 if( ! defined('USCES_LOGOUT_URL') )
2677 define('USCES_LOGOUT_URL', $ssl_plink_member . '?uscesid=' . $this->get_uscesid() . '&page=logout');
2678 if( ! defined('USCES_MEMBER_URL') )
2679 define('USCES_MEMBER_URL', $ssl_plink_member . '?uscesid=' . $this->get_uscesid());
2680 if( !isset($this->options['inquiry_id']) || !( (int)$this->options['inquiry_id'] ) ){
2681 $inquiry_url = get_home_url();
2682 }else{
2683 $ssl_plink_inquiry = str_replace('http://','https://', str_replace( $home_path, $ssl_path, get_page_link($this->options['inquiry_id']) ));
2684 $inquiry_url = empty( $this->options['inquiry_id'] ) ? '' : $ssl_plink_inquiry . '?uscesid=' . $this->get_uscesid();
2685 }
2686 if( ! defined('USCES_INQUIRY_URL') )
2687 define('USCES_INQUIRY_URL', $inquiry_url);
2688 if( ! defined('USCES_CART_NONSESSION_URL') )
2689 define('USCES_CART_NONSESSION_URL', $ssl_plink_cart);
2690 //20110208ysk start
2691 //define('USCES_PAYPAL_NOTIFY_URL', $ssl_plink_cart . '?acting_return=paypal_ipn&uscesid=' . $this->get_uscesid(false));
2692 if( ! defined('USCES_PAYPAL_NOTIFY_URL') )
2693 define('USCES_PAYPAL_NOTIFY_URL', $ssl_plink_cart . '?acting=paypal_ipn&uscesid=' . $this->get_uscesid(false));
2694 //20110208ysk end
2695 }
2696 }else{
2697 $this->delim = '&';
2698 if( ! defined('USCES_CUSTOMER_URL') )
2699 define('USCES_CUSTOMER_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_CART_NUMBER . '&customerinfo=1&uscesid=' . $this->get_uscesid());
2700 if( ! defined('USCES_CART_URL') )
2701 define('USCES_CART_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_CART_NUMBER . '&uscesid=' . $this->get_uscesid());
2702 if( ! defined('USCES_LOSTMEMBERPASSWORD_URL') )
2703 define('USCES_LOSTMEMBERPASSWORD_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_MEMBER_NUMBER . '&uscesid=' . $this->get_uscesid() . '&page=lostmemberpassword');
2704 if( ! defined('USCES_NEWMEMBER_URL') )
2705 define('USCES_NEWMEMBER_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_MEMBER_NUMBER . '&uscesid=' . $this->get_uscesid() . '&page=newmember');
2706 if( ! defined('USCES_LOGIN_URL') )
2707 define('USCES_LOGIN_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_MEMBER_NUMBER . '&uscesid=' . $this->get_uscesid() . '&page=login');
2708 if( ! defined('USCES_LOGOUT_URL') )
2709 define('USCES_LOGOUT_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_MEMBER_NUMBER . '&uscesid=' . $this->get_uscesid() . '&page=logout');
2710 if( ! defined('USCES_MEMBER_URL') )
2711 define('USCES_MEMBER_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_MEMBER_NUMBER . '&uscesid=' . $this->get_uscesid());
2712 $inquiry_url = empty( $this->options['inquiry_id'] ) ? '' : $this->options['ssl_url'] . '/?page_id=' . $this->options['inquiry_id'] . '&uscesid=' . $this->get_uscesid();
2713 if( ! defined('USCES_INQUIRY_URL') )
2714 define('USCES_INQUIRY_URL', $inquiry_url);
2715 if( ! defined('USCES_CART_NONSESSION_URL') )
2716 define('USCES_CART_NONSESSION_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_CART_NUMBER);
2717 //20110208ysk start
2718 //define('USCES_PAYPAL_NOTIFY_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_CART_NUMBER . '&acting_return=paypal_ipn&uscesid=' . $this->get_uscesid(false));
2719 if( ! defined('USCES_PAYPAL_NOTIFY_URL') )
2720 define('USCES_PAYPAL_NOTIFY_URL', $this->options['ssl_url'] . '/?page_id=' . USCES_CART_NUMBER . '&acting=paypal_ipn&uscesid=' . $this->get_uscesid(false));
2721 //20110208ysk end
2722 }
2723 if( !is_admin() ){
2724 add_filter('home_url', array($this, 'usces_ssl_page_link'));
2725 add_filter('wp_get_attachment_url', array($this, 'usces_ssl_attachment_link'));
2726 add_filter('icon_dir_uri', array($this, 'usces_ssl_icon_dir_uri'));
2727 add_filter('stylesheet_directory_uri', array($this, 'usces_ssl_contents_link'));
2728 add_filter('template_directory_uri', array($this, 'usces_ssl_contents_link'));
2729 add_filter('script_loader_src', array($this, 'usces_ssl_script_link'));
2730 add_filter('style_loader_src', array($this, 'usces_ssl_script_link'));
2731 }
2732 } else {
2733 if( $permalink_structure ){
2734 $this->delim = '?';
2735 if( ! defined('USCES_CUSTOMER_URL') )
2736 define('USCES_CUSTOMER_URL', get_page_link(USCES_CART_NUMBER) . '?customerinfo=1');
2737 if( ! defined('USCES_CART_URL') )
2738 define('USCES_CART_URL', get_page_link(USCES_CART_NUMBER));
2739 if( ! defined('USCES_LOSTMEMBERPASSWORD_URL') )
2740 define('USCES_LOSTMEMBERPASSWORD_URL', get_page_link(USCES_MEMBER_NUMBER) . '?page=lostmemberpassword');
2741 if( ! defined('USCES_NEWMEMBER_URL') )
2742 define('USCES_NEWMEMBER_URL', get_page_link(USCES_MEMBER_NUMBER) . '?page=newmember');
2743 if( ! defined('USCES_LOGIN_URL') )
2744 define('USCES_LOGIN_URL', get_page_link(USCES_MEMBER_NUMBER) . '?page=login');
2745 if( ! defined('USCES_LOGOUT_URL') )
2746 define('USCES_LOGOUT_URL', get_page_link(USCES_MEMBER_NUMBER) . '?page=logout');
2747 if( ! defined('USCES_MEMBER_URL') )
2748 define('USCES_MEMBER_URL', get_page_link(USCES_MEMBER_NUMBER));
2749 $inquiry_url = ( !isset( $this->options['inquiry_id'] ) || !( (int)$this->options['inquiry_id'] )) ? get_home_url() : get_page_link($this->options['inquiry_id']);
2750 if( ! defined('USCES_INQUIRY_URL') )
2751 define('USCES_INQUIRY_URL', $inquiry_url);
2752 if( ! defined('USCES_CART_NONSESSION_URL') )
2753 define('USCES_CART_NONSESSION_URL', get_page_link(USCES_CART_NUMBER));
2754 //20110208ysk start
2755 //define('USCES_PAYPAL_NOTIFY_URL', get_page_link(USCES_CART_NUMBER) . '?acting_return=paypal_ipn&uscesid=' . $this->get_uscesid(false));
2756 if( ! defined('USCES_PAYPAL_NOTIFY_URL') )
2757 define('USCES_PAYPAL_NOTIFY_URL', get_page_link(USCES_CART_NUMBER) . '?acting=paypal_ipn&uscesid=' . $this->get_uscesid(false));
2758 //20110208ysk end
2759 }else{
2760 $this->delim = '&';
2761 if( ! defined('USCES_CUSTOMER_URL') )
2762 define('USCES_CUSTOMER_URL', get_option('home') . '/?page_id=' . USCES_CART_NUMBER . '&customerinfo=1');
2763 if( ! defined('USCES_CART_URL') )
2764 define('USCES_CART_URL', get_option('home') . '/?page_id=' . USCES_CART_NUMBER);
2765 if( ! defined('USCES_LOSTMEMBERPASSWORD_URL') )
2766 define('USCES_LOSTMEMBERPASSWORD_URL', get_option('home') . '/?page_id=' . USCES_MEMBER_NUMBER . '&page=lostmemberpassword');
2767 if( ! defined('USCES_NEWMEMBER_URL') )
2768 define('USCES_NEWMEMBER_URL', get_option('home') . '/?page_id=' . USCES_MEMBER_NUMBER . '&page=newmember');
2769 if( ! defined('USCES_LOGIN_URL') )
2770 define('USCES_LOGIN_URL', get_option('home') . '/?page_id=' . USCES_MEMBER_NUMBER . '&page=login');
2771 if( ! defined('USCES_LOGOUT_URL') )
2772 define('USCES_LOGOUT_URL', get_option('home') . '/?page_id=' . USCES_MEMBER_NUMBER . '&page=logout');
2773 if( ! defined('USCES_CART_NONSESSION_URL') )
2774 define('USCES_CART_NONSESSION_URL', get_option('home') . '/?page_id=' . USCES_MEMBER_NUMBER . '&page=logout');
2775 if( ! defined('USCES_MEMBER_URL') )
2776 define('USCES_MEMBER_URL', get_option('home') . '/?page_id=' . USCES_MEMBER_NUMBER);
2777 $inquiry_url = empty( $this->options['inquiry_id'] ) ? '' : get_option('home') . '/?page_id=' . $this->options['inquiry_id'];
2778 if( ! defined('USCES_INQUIRY_URL') )
2779 define('USCES_INQUIRY_URL', $inquiry_url);
2780 if( ! defined('USCES_CART_NONSESSION_URL') )
2781 define('USCES_CART_NONSESSION_URL', get_option('home') . '/?page_id=' . USCES_CART_NUMBER);
2782 //20110208ysk start
2783 //define('USCES_PAYPAL_NOTIFY_URL', get_option('home') . '/?page_id=' . USCES_CART_NUMBER . '&acting_return=paypal_ipn&uscesid=' . $this->get_uscesid(false));
2784 if( ! defined('USCES_PAYPAL_NOTIFY_URL') )
2785 define('USCES_PAYPAL_NOTIFY_URL', get_option('home') . '/?page_id=' . USCES_CART_NUMBER . '&acting=paypal_ipn&uscesid=' . $this->get_uscesid(false));
2786 //20110208ysk end
2787 }
2788 }
2789 }
2790
2791 function regist_action(){
2792 usces_register_action('inCart', 'post', 'inCart', NULL, 'inCart');
2793 usces_register_action('upButton', 'post', 'upButton', NULL, 'upButton');
2794 usces_register_action('delButton', 'post', 'delButton', NULL, 'delButton');
2795 usces_register_action('backCart', 'post', 'backCart', NULL, 'backCart');
2796 usces_register_action('customerinfo', 'request', 'customerinfo', NULL, 'customerinfo');
2797 usces_register_action('backCustomer', 'post', 'backCustomer', NULL, 'backCustomer');
2798 usces_register_action('customerlogin', 'post', 'customerlogin', NULL, 'customerlogin');
2799 usces_register_action('reganddeliveryinfo', 'post', 'reganddeliveryinfo', NULL, 'reganddeliveryinfo');
2800 usces_register_action('deliveryinfo', 'post', 'deliveryinfo', NULL, 'deliveryinfo');
2801 usces_register_action('backDelivery', 'post', 'backDelivery', NULL, 'backDelivery');
2802 usces_register_action('confirm', 'request', 'confirm', NULL, 'confirm');
2803 usces_register_action('use_point', 'post', 'use_point', NULL, 'use_point');
2804 usces_register_action('backConfirm', 'post', 'backConfirm', NULL, 'backConfirm');
2805 usces_register_action('purchase', 'request', 'purchase', NULL, 'purchase');
2806 usces_register_action('acting_return', 'request', 'acting_return', NULL, 'acting_return');
2807 usces_register_action('settlement_epsilon', 'request', 'settlement', 'epsilon', 'settlement_epsilon');
2808 usces_register_action('inquiry_button', 'post', 'inquiry_button', NULL, 'inquiry_button');
2809 usces_register_action('member_login', 'request', 'member_login', NULL, 'member_login_page');
2810 usces_register_action('regmember', 'request', 'regmember', NULL, 'regmember');
2811 usces_register_action('editmember', 'request', 'editmember', NULL, 'editmember');
2812 usces_register_action('deletemember', 'request', 'deletemember', NULL, 'deletemember');
2813 usces_register_action('page_login', 'get', 'page', 'login', 'member_login_page');
2814 usces_register_action('page_logout', 'get', 'page', 'logout', 'page_logout');
2815 usces_register_action('page_lostmemberpassword', 'get', 'page', 'lostmemberpassword', 'page_lostmemberpassword');
2816 usces_register_action('lostpassword', 'request', 'lostpassword', NULL, 'lostpassword');
2817 usces_register_action('uscesmode_changepassword', 'request', 'uscesmode', 'changepassword', 'uscesmode_changepassword');
2818 usces_register_action('changepassword', 'request', 'changepassword', NULL, 'changepassword_page');
2819 usces_register_action('page_newmember', 'get', 'page', 'newmember', 'page_newmember');
2820 usces_register_action('usces_export', 'post', 'usces_export', NULL, 'usces_export');
2821 usces_register_action('usces_import', 'post', 'usces_import', NULL, 'usces_import');
2822 usces_register_action('page_search_item', 'get', 'page', 'search_item', 'page_search_item');
2823 usces_register_action('front_ajax', 'post', 'usces_ajax_action', NULL, 'front_ajax');
2824 }
2825
2826 function ad_controller(){
2827 global $usces_action;
2828 ksort($usces_action);
2829 //if($this->is_maintenance()){
2830 if($this->is_maintenance() and !is_user_logged_in()){//0000651
2831 $this->maintenance();
2832 }else{
2833 $action_array = array('inCart', 'upButton', 'delButton', 'backCart', 'customerinfo', 'backCustomer',
2834 'customerlogin', 'reganddeliveryinfo', 'deliveryinfo', 'backDelivery', 'confirm', 'use_point',
2835 'backConfirm', 'purchase', 'acting_return', 'settlement_epsilon', 'inquiry_button', 'member_login',
2836 'regmember', 'editmember', 'deletemember', 'page_login', 'page_logout', 'page_lostmemberpassword', 'lostpassword',
2837 'uscesmode_changepassword', 'changepassword', 'page_newmember', 'usces_export', 'usces_import',
2838 'page_search_item', 'front_ajax');
2839 $flg = 0;
2840 $res = true;
2841 foreach( $usces_action as $handle => $action ){
2842 extract($action);
2843 switch($type){
2844 case 'post':
2845 if( empty($value) ){
2846 if( isset($_POST[$key]) ){
2847 if(in_array($handle, $action_array)){
2848 $res = call_user_func(array($this, $function));
2849 }else{
2850 $res = call_user_func($function);
2851 }
2852 $flg = 1;
2853 }
2854 }else{
2855 if( isset($_POST[$key]) && $_POST[$key] == $value ){
2856 if(in_array($handle, $action_array)){
2857 $res = call_user_func(array($this, $function));
2858 }else{
2859 $res = call_user_func($function);
2860 }
2861 $flg = 1;
2862 }
2863 }
2864 break;
2865 case 'get':
2866 if( empty($value) ){
2867 if( isset($_GET[$key]) ){
2868 if(in_array($handle, $action_array)){
2869 $res = call_user_func(array($this, $function));
2870 }else{
2871 $res = call_user_func($function);
2872 }
2873 $flg = 1;
2874 }
2875 }else{
2876 if( isset($_GET[$key]) && $_GET[$key] == $value ){
2877 if(in_array($handle, $action_array)){
2878 $res = call_user_func(array($this, $function));
2879 }else{
2880 $res = call_user_func($function);
2881 }
2882 $flg = 1;
2883 }
2884 }
2885 break;
2886 case 'request':
2887 if( empty($value) ){
2888 if( isset($_REQUEST[$key]) ){
2889 if(in_array($handle, $action_array)){
2890 $res = call_user_func(array($this, $function));
2891 }else{
2892 $res = call_user_func($function);
2893 }
2894 $flg = 1;
2895 }
2896 }else{
2897 if( isset($_REQUEST[$key]) && $_REQUEST[$key] == $value ){
2898 if(in_array($handle, $action_array)){
2899 $res = call_user_func(array($this, $function));
2900 }else{
2901 $res = call_user_func($function);
2902 }
2903 $flg = 1;
2904 }
2905 }
2906 break;
2907 }
2908 if( ! $res ) break;
2909 }
2910 if( !$flg ) $this->default_page();
2911 }
2912 }
2913
2914 //action function------------------------------------------------------------
2915 function front_ajax(){
2916 switch ($_POST['usces_ajax_action']){
2917 case 'change_states':
2918 change_states_ajax();
2919 break;
2920 }
2921 do_action('usces_front_ajax');
2922 }
2923
2924 function maintenance(){
2925 $this->page = 'maintenance';
2926 add_action('the_post', array($this, 'action_cartFilter'));
2927 }
2928
2929 function inCart(){
2930 global $wp_query;
2931 $this->page = 'cart';
2932 $this->incart_check();
2933 $this->cart->inCart();
2934 add_action('the_post', array($this, 'action_cartFilter'));
2935 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_cart');
2936 add_action('template_redirect', array($this, 'template_redirect'));
2937 }
2938
2939 function upButton(){
2940 global $wp_query;
2941 $this->page = 'cart';
2942 $this->cart->upCart();
2943 $this->error_message = $this->zaiko_check();
2944 add_action('the_post', array($this, 'action_cartFilter'));
2945 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_cart');
2946 add_action('template_redirect', array($this, 'template_redirect'));
2947 }
2948
2949 function delButton(){
2950 global $wp_query;
2951 $this->page = 'cart';
2952 $this->cart->del_row();
2953 add_action('the_post', array($this, 'action_cartFilter'));
2954 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_cart');
2955 add_action('template_redirect', array($this, 'template_redirect'));
2956 }
2957
2958 function backCart(){
2959 global $wp_query;
2960 $this->page = 'cart';
2961 add_action('the_post', array($this, 'action_cartFilter'));
2962 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_cart');
2963 add_action('template_redirect', array($this, 'template_redirect'));
2964 }
2965
2966 function customerinfo(){
2967 global $wp_query;
2968 if( false === $this->cart->num_row() ){
2969 header('location: ' . get_option('home'));
2970 exit;
2971 }
2972 $this->cart->entry();
2973 $this->error_message = $this->zaiko_check();
2974 $this->error_message = apply_filters( 'usces_filter_cart_check', $this->error_message );
2975 if( WCUtils::is_blank($this->error_message) ){
2976 if($this->is_member_logged_in()){
2977 //20100818ysk start
2978 //$this->page = 'delivery';
2979 $this->error_message = has_custom_customer_field_essential();
2980 $this->page = ( WCUtils::is_blank($this->error_message) ) ? 'delivery' : 'customer';
2981 //20100818ysk end
2982 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_delivery');
2983 }else{
2984 $this->page = 'customer';
2985 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_customer');
2986 }
2987 }else{
2988 $this->page = 'cart';
2989 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_cart');
2990 }
2991 if ( !$this->cart->is_order_condition() ) {
2992 $order_conditions = $this->get_condition();
2993 $this->cart->set_order_condition($order_conditions);
2994 }
2995 add_action('the_post', array($this, 'action_cartFilter'));
2996 add_action('template_redirect', array($this, 'template_redirect'));
2997 }
2998
2999 function backCustomer(){
3000 global $wp_query;
3001 if( false === $this->cart->num_row() ){
3002 header('location: ' . get_option('home'));
3003 exit;
3004 }
3005 $this->page = apply_filters( 'usces_filter_backCustomer_page', 'customer' );
3006 add_action('the_post', array($this, 'action_cartFilter'));
3007 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_customer');
3008 add_action('template_redirect', array($this, 'template_redirect'));
3009 // $this->cart->entry();
3010 // $this->error_message = $this->delivery_check();
3011 // $this->page = ($this->error_message == '') ? 'customer' : 'delivery';
3012 }
3013
3014 function customerlogin(){
3015 global $wp_query;
3016 if( false === $this->cart->num_row() ){
3017 header('location: ' . get_option('home'));
3018 exit;
3019 }
3020 //20100818ysk start
3021 //$this->cart->entry();
3022 //$this->page = ($this->member_login() == 'member') ? 'delivery' : 'customer';
3023 if($this->member_login() == 'member') {
3024 $this->cart->entry();
3025 $this->error_message = has_custom_customer_field_essential();
3026 if( WCUtils::is_blank($this->error_message) ){
3027 $this->page = 'delivery';
3028 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_delivery');
3029 }else{
3030 $this->page = 'customer';
3031 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_customer');
3032 }
3033 } else {
3034 $this->cart->entry();
3035 $this->page = 'customer';
3036 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_customer');
3037 }
3038 //20100818ysk end
3039 add_action('the_post', array($this, 'action_cartFilter'));
3040 add_action('template_redirect', array($this, 'template_redirect'));
3041 }
3042
3043 function reganddeliveryinfo(){
3044 global $wp_query;
3045 if( false === $this->cart->num_row() ){
3046 header('location: ' . get_option('home'));
3047 exit;
3048 }
3049 $this->cart->entry();
3050 //20110715ysk start 0000203
3051 //$_POST['member_regmode'] = 'newmemberfromcart';
3052 if(empty($_POST['member_regmode']) or $_POST['member_regmode'] != 'editmemberfromcart') $_POST['member_regmode'] = 'newmemberfromcart';
3053 //20110715ysk end
3054
3055 if( $this->regist_member() == 'newcompletion' ){
3056 $this->page = 'delivery';
3057 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_delivery');
3058 }else{
3059 $this->page = 'customer';
3060 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_customer');
3061 }
3062 add_action('the_post', array($this, 'action_cartFilter'));
3063 add_action('template_redirect', array($this, 'template_redirect'));
3064 }
3065
3066 function deliveryinfo(){
3067 global $wp_query;
3068 if( false === $this->cart->num_row() ){
3069 header('location: ' . get_option('home'));
3070 exit;
3071 }
3072 $this->cart->entry();
3073 $this->error_message = $this->customer_check();
3074
3075 if( WCUtils::is_blank($this->error_message) ){
3076 $this->page = 'delivery';
3077 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_delivery');
3078 }else{
3079 $this->page = 'customer';
3080 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_customer');
3081 }
3082 add_action('the_post', array($this, 'action_cartFilter'));
3083 add_action('template_redirect', array($this, 'template_redirect'));
3084 }
3085
3086 function backDelivery(){
3087 global $wp_query;
3088 if( false === $this->cart->num_row() ){
3089 header('location: ' . get_option('home'));
3090 exit;
3091 }
3092 $this->page = 'delivery';
3093 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_delivery');
3094 add_action('the_post', array($this, 'action_cartFilter'));
3095 add_action('template_redirect', array($this, 'template_redirect'));
3096 }
3097
3098 function confirm(){
3099 global $wpdb, $wp_query;
3100 if( false === $this->cart->num_row() ){
3101 header('location: ' . get_option('home'));
3102 exit;
3103 }
3104
3105 $this->cart->entry();
3106 $this->error_message = $this->zaiko_check();
3107 if( $this->error_message != '' ){
3108 $this->page = 'cart';
3109 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_cart');
3110 add_action('the_post', array($this, 'action_cartFilter'));
3111 add_action('template_redirect', array($this, 'template_redirect'));
3112 return;
3113 }
3114
3115 $this->set_reserve_pre_order_id();
3116 if(isset($_POST['confirm'])){
3117 $this->error_message = $this->delivery_check();
3118 }
3119 $this->page = ( WCUtils::is_blank($this->error_message) ) ? 'confirm' : 'delivery';
3120 if( WCUtils::is_blank($this->error_message) ){
3121 //20120919ysk start 0000573
3122 if( usces_is_member_system() && usces_is_member_system_point() && $this->is_member_logged_in() ) {
3123 unset( $_SESSION['usces_entry']['order']['usedpoint'] );//20120914ysk 0000566
3124 $member_table = $wpdb->prefix."usces_member";
3125 $query = $wpdb->prepare("SELECT mem_point FROM $member_table WHERE ID = %d", $_SESSION['usces_member']['ID']);
3126 $mem_point = $wpdb->get_var( $query );
3127 $_SESSION['usces_member']['point'] = $mem_point;
3128 }
3129 //20120919ysk end
3130 $this->page = 'confirm';
3131 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_confirm');
3132 }else{
3133 $this->page = 'delivery';
3134 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_delivery');
3135 }
3136 add_action('the_post', array($this, 'action_cartFilter'));
3137 add_action('template_redirect', array($this, 'template_redirect'));
3138 }
3139
3140 function use_point(){
3141 global $wp_query;
3142 $this->cart->entry();
3143 $this->error_message = $this->point_check( $this->cart->get_entry() );
3144 $this->page = 'confirm';
3145 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_confirm');
3146 add_action('the_post', array($this, 'action_cartFilter'));
3147 add_action('template_redirect', array($this, 'template_redirect'));
3148 }
3149
3150 function backConfirm(){
3151 global $wp_query;
3152 if( false === $this->cart->num_row() ){
3153 header('location: ' . get_option('home'));
3154 exit;
3155 }
3156 $this->page = 'confirm';
3157 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_confirm');
3158 add_action('the_post', array($this, 'action_cartFilter'));
3159 add_action('template_redirect', array($this, 'template_redirect'));
3160 }
3161
3162 function purchase(){
3163 global $wp_query;
3164 if( false === $this->cart->num_row() ){
3165 header('location: ' . get_option('home'));
3166 exit;
3167 }
3168
3169 if( !apply_filters('usces_purchase_check', true) ) return;
3170
3171 do_action('usces_purchase_validate');
3172 $entry = $this->cart->get_entry();
3173 $this->error_message = $this->zaiko_check();
3174 if( WCUtils::is_blank($this->error_message) && 0 < $this->cart->num_row()){
3175 $actinc_status = '';
3176 $payments = $this->getPayments( $entry['order']['payment_name'] );
3177 if( substr($payments['settlement'], 0, 6) == 'acting' && $entry['order']['total_full_price'] > 0 ){
3178 $acting_flg = ( 'acting' == $payments['settlement'] ) ? $payments['module'] : $payments['settlement'];
3179 $query = '';
3180 foreach($_POST as $key => $value){
3181 if($key != 'purchase')
3182 $query .= '&' . $key . '=' . urlencode(maybe_serialize($value));
3183 }
3184 $actinc_status = $this->acting_processing($acting_flg, $query);
3185 }
3186
3187 if($actinc_status == 'error'){
3188 $this->page = 'error';
3189 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_error');
3190 }else{
3191 $res = $this->order_processing();
3192 if( 'ordercompletion' == $res ){
3193 $this->page = 'ordercompletion';
3194 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_ordercompletion');
3195 }else{
3196 $this->page = 'error';
3197 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_error');
3198 }
3199 }
3200 }else{
3201 $this->page = 'cart';
3202 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_cart');
3203 }
3204 add_action('the_post', array($this, 'action_cartFilter'));
3205 add_action('template_redirect', array($this, 'template_redirect'));
3206 }
3207
3208 function acting_return(){
3209 global $wp_query;
3210 $entry = $this->cart->get_entry();
3211
3212 //20110208ysk start
3213 /* if( 'paypal_ipn' == $_REQUEST['acting_return'] ){
3214 usces_log('paypal_ipn in ', 'acting_transaction.log');
3215 require_once($this->options['settlement_path'] . 'paypal.php');
3216 $ipn_res = paypal_ipn_check($usces_paypal_url);
3217 if( $ipn_res[0] === true ){
3218 $res = $this->order_processing( $ipn_res );
3219 if( 'ordercompletion' == $res ){
3220 $this->cart->crear_cart();
3221 }else{
3222 usces_log('paypal_ipn regorder error (acting_return) : '.print_r($entry, true), 'acting_transaction.log');
3223 }
3224 }
3225 exit;
3226 }*/
3227 //20110208ysk end
3228 if( false === $this->cart->num_row() && ('paypal' != $_GET['acting'] && 1 !== (int)$_GET['acting_return']) ){
3229 header('location: ' . get_option('home'));
3230 exit;
3231 }
3232
3233 $this->payment_results = usces_check_acting_return();
3234
3235 if( isset($this->payment_results[0]) && $this->payment_results[0] === 'duplicate' ){
3236
3237 header('location: ' . get_option('home'));
3238 exit;
3239
3240 }else if( isset($this->payment_results[0]) && $this->payment_results[0] ){//result OK
3241
3242 if( ! $this->payment_results['reg_order'] ){//without Registration Order
3243 $this->page = 'ordercompletion';
3244 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_ordercompletion');
3245
3246 }else{
3247 $res = $this->order_processing( $this->payment_results );
3248
3249 if( 'ordercompletion' == $res ){
3250 $this->page = 'ordercompletion';
3251 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_ordercompletion');
3252 }else{
3253 $this->page = 'error';
3254 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_error');
3255 }
3256 }
3257
3258 }else{//result NG
3259 $this->page = 'error';
3260 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_error');
3261 }
3262
3263 add_action('the_post', array($this, 'action_cartFilter'));
3264 add_action('template_redirect', array($this, 'template_redirect'));
3265 }
3266
3267 function settlement_epsilon(){
3268 global $wp_query;
3269 require_once($this->options['settlement_path'] . 'epsilon.php');
3270 }
3271
3272 function inquiry_button(){
3273 if( isset($_POST['inq_name']) && !WCUtils::is_blank($_POST['inq_name']) && isset($_POST['inq_mailaddress']) && is_email( trim($_POST['inq_mailaddress']) ) && !WCUtils::is_blank($_POST['inq_contents']) ){
3274 $res = $this->inquiry_processing();
3275 }else{
3276 $res = 'deficiency';
3277 }
3278
3279 $this->page = $res;
3280 }
3281
3282 function member_login_page(){
3283 global $wp_query;
3284 $res = $this->member_login();
3285 if( 'member' == $res ){
3286 $this->page = 'member';
3287 do_action('usces_action_member_logined');
3288 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_member');
3289 }elseif( 'login' == $res ){
3290 $this->page = 'login';
3291 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_login');
3292 }
3293 add_action('the_post', array($this, 'action_memberFilter'));
3294 add_action('template_redirect', array($this, 'template_redirect'));
3295 }
3296
3297 function regmember(){
3298 global $wp_query;
3299 $res = $this->regist_member();
3300 if( 'editmemberform' == $res ){
3301 $this->page = 'editmemberform';
3302 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_editmemberform');
3303 }elseif( 'newcompletion' == $res ){
3304 $this->page = 'newcompletion';
3305 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_newcompletion');
3306 }else{
3307 $this->page = $res;
3308 }
3309 add_action('the_post', array($this, 'action_memberFilter'));
3310 add_action('template_redirect', array($this, 'template_redirect'));
3311 }
3312
3313 function editmember(){
3314 global $wp_query;
3315 $res = $this->regist_member();
3316 if( 'editmemberform' == $res ){
3317 $this->page = 'editmemberform';
3318 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_editmemberform');
3319 }elseif( 'newcompletion' == $res ){
3320 $this->page = 'newcompletion';
3321 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_newcompletion');
3322 }else{
3323 $this->page = $res;
3324 }
3325 add_action('the_post', array($this, 'action_memberFilter'));
3326 add_action('template_redirect', array($this, 'template_redirect'));
3327 }
3328
3329 function deletemember(){
3330 $res = $this->delete_member();
3331 if( $res ){
3332 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_deletemember');
3333 $this->member_logout();
3334 }else{
3335 $this->page = 'editmemberform';
3336 add_action('the_post', array($this, 'action_memberFilter'));
3337 }
3338 add_action('template_redirect', array($this, 'template_redirect'));
3339 }
3340
3341 function page_logout(){
3342 global $wp_query;
3343 $this->member_logout();
3344 add_action('the_post', array($this, 'action_memberFilter'));
3345 add_action('template_redirect', array($this, 'template_redirect'));
3346 }
3347
3348 function page_lostmemberpassword(){
3349 global $wp_query;
3350 $this->page = 'lostmemberpassword';
3351 add_action('the_post', array($this, 'action_memberFilter'));
3352 add_action('template_redirect', array($this, 'template_redirect'));
3353 }
3354
3355 function lostpassword(){
3356 global $wp_query;
3357 $this->error_message = $this->lostpass_mailaddcheck();
3358 if ( $this->error_message != '' ) {
3359 $this->page = 'lostmemberpassword';
3360 } else {
3361 $res = $this->lostmail();
3362 $this->page = $res;//'lostcompletion';
3363 }
3364 add_action('the_post', array($this, 'action_memberFilter'));
3365 add_action('template_redirect', array($this, 'template_redirect'));
3366 }
3367
3368 function uscesmode_changepassword(){
3369 global $wp_query;
3370 $this->page = 'changepassword';
3371 add_action('the_post', array($this, 'action_memberFilter'));
3372 add_action('template_redirect', array($this, 'template_redirect'));
3373 }
3374
3375 function changepassword_page(){
3376 global $wp_query;
3377 $this->error_message = $this->changepass_check();
3378 if ( $this->error_message != '' ) {
3379 $this->page = 'changepassword';
3380 } else {
3381 $res = $this->changepassword();
3382 $this->page = $res;//'changepasscompletion';
3383 }
3384 add_action('the_post', array($this, 'action_memberFilter'));
3385 add_action('template_redirect', array($this, 'template_redirect'));
3386 }
3387
3388 function page_newmember(){
3389
3390 global $wp_query;
3391 $this->page = 'newmemberform';
3392 add_filter('yoast-ga-push-after-pageview', 'usces_trackPageview_newmemberform');
3393 add_action('the_post', array($this, 'action_memberFilter'));
3394 add_action('template_redirect', array($this, 'template_redirect'));
3395 }
3396
3397 function usces_export(){
3398 $this->export();
3399 }
3400
3401 function usces_import(){
3402 $this->import();
3403 }
3404
3405 function page_search_item(){
3406 global $wp_query;
3407 $this->page = 'search_item';
3408 //add_action('template_redirect', array($this, 'action_search_item'));
3409 add_action('the_post', array($this, 'action_cartFilter'));
3410 add_action('template_redirect', array($this, 'template_redirect'));
3411 }
3412
3413 function default_page(){
3414 global $wp_query;
3415 add_action('the_post', array($this, 'goDefaultPage'));
3416 add_action('template_redirect', array($this, 'template_redirect'));
3417 }
3418 //--------------------------------------------------------------------------------------
3419
3420
3421 function goDefaultPage(){
3422 global $post;
3423
3424 if( $post->ID == USCES_CART_NUMBER ) {
3425
3426 $this->page = 'cart';
3427 add_filter('the_content', array($this, 'filter_cartContent'),20);
3428
3429 }else if( $post->ID == USCES_MEMBER_NUMBER ) {
3430
3431 $this->page = 'member';
3432 add_filter('the_content', array($this, 'filter_memberContent'),20);
3433
3434 }else if( !is_singular() ) {
3435 $this->page = 'wp_search';
3436 add_filter('the_excerpt', array($this, 'filter_cartContent'),20);
3437 add_filter('the_content', array($this, 'filter_cartContent'),20);
3438
3439 }else{
3440 add_filter('the_content', array(&$this, 'filter_itemPage'));
3441
3442 }
3443 }
3444
3445 function template_redirect () {
3446 global $post, $usces_entries, $usces_carts, $usces_members, $usces_gp, $member_regmode;
3447
3448 if( apply_filters('usces_action_template_redirect', false) ) return;//Deprecated
3449 if( apply_filters('usces_filter_template_redirect', false) ) return;
3450
3451 if( is_single() && 'item' == $post->post_mime_type ) {
3452 if( file_exists(get_stylesheet_directory() . '/wc_templates/wc_item_single.php') ){
3453 if( !post_password_required($post) ){
3454 include(get_stylesheet_directory() . '/wc_templates/wc_item_single.php');
3455 exit;
3456 }
3457 }
3458 }elseif( isset($_REQUEST['page']) && ('search_item' == $_REQUEST['page'] || 'usces_search' == $_REQUEST['page']) && $this->is_cart_page($_SERVER['REQUEST_URI']) ){
3459 if( file_exists(get_stylesheet_directory() . '/wc_templates/wc_search_page.php') ){
3460 include(get_stylesheet_directory() . '/wc_templates/wc_search_page.php');
3461 exit;
3462 }
3463
3464 }else if( $this->is_cart_page($_SERVER['REQUEST_URI']) ){
3465 switch( $this->page ){
3466 case 'customer':
3467 if( file_exists(get_stylesheet_directory() . '/wc_templates/cart/wc_customer_page.php') ){
3468 usces_get_entries();
3469 usces_get_member_regmode();
3470 include(get_stylesheet_directory() . '/wc_templates/cart/wc_customer_page.php');
3471 exit;
3472 }
3473 break;
3474 case 'delivery':
3475 if( file_exists(get_stylesheet_directory() . '/wc_templates/cart/wc_delivery_page.php') ){
3476 usces_get_entries();
3477 usces_get_carts();
3478 include(get_stylesheet_directory() . '/wc_templates/cart/wc_delivery_page.php');
3479 exit;
3480 }
3481 break;
3482 case 'confirm':
3483 if( file_exists(get_stylesheet_directory() . '/wc_templates/cart/wc_confirm_page.php') ){
3484 usces_get_entries();
3485 usces_get_carts();
3486 usces_get_members();
3487 include(get_stylesheet_directory() . '/wc_templates/cart/wc_confirm_page.php');
3488 exit;
3489 }
3490 break;
3491 case 'ordercompletion':
3492 if( file_exists(get_stylesheet_directory() . '/wc_templates/cart/wc_completion_page.php') ){
3493 usces_get_entries();
3494 usces_get_carts();
3495 include(get_stylesheet_directory() . '/wc_templates/cart/wc_completion_page.php');
3496 exit;
3497 }
3498 break;
3499 case 'error':
3500 if( file_exists(get_stylesheet_directory() . '/wc_templates/cart/wc_cart_error_page.php') ){
3501 include(get_stylesheet_directory() . '/wc_templates/cart/wc_cart_error_page.php');
3502 exit;
3503 }
3504 break;
3505 case 'cart':
3506 default:
3507 if( file_exists(get_stylesheet_directory() . '/wc_templates/cart/wc_cart_page.php') ){
3508 include(get_stylesheet_directory() . '/wc_templates/cart/wc_cart_page.php');
3509 exit;
3510 }
3511
3512 }
3513 }else if($this->is_inquiry_page($_SERVER['REQUEST_URI']) ){
3514
3515 }else if( $this->is_member_page($_SERVER['REQUEST_URI']) ){
3516 if($this->options['membersystem_state'] != 'activate') return;
3517
3518 if( $this->is_member_logged_in() ) {
3519 $member_regmode = 'editmemberform';
3520 if( file_exists(get_stylesheet_directory() . '/wc_templates/member/wc_member_page.php') ){
3521 include(get_stylesheet_directory() . '/wc_templates/member/wc_member_page.php');
3522 exit;
3523 }
3524
3525 } else {
3526
3527 switch( $this->page ){
3528 case 'login':
3529 if( file_exists(get_stylesheet_directory() . '/wc_templates/member/wc_login_page.php') ){
3530 include(get_stylesheet_directory() . '/wc_templates/member/wc_login_page.php');
3531 exit;
3532 }
3533 break;
3534 case 'newmemberform':
3535 if( file_exists(get_stylesheet_directory() . '/wc_templates/member/wc_new_member_page.php') ){
3536 $member_regmode = 'newmemberform';
3537 include(get_stylesheet_directory() . '/wc_templates/member/wc_new_member_page.php');
3538 exit;
3539 }
3540 break;
3541 case 'lostmemberpassword':
3542 if( file_exists(get_stylesheet_directory() . '/wc_templates/member/wc_lostpassword_page.php') ){
3543 include(get_stylesheet_directory() . '/wc_templates/member/wc_lostpassword_page.php');
3544 exit;
3545 }
3546 break;
3547 case 'changepassword':
3548 if( file_exists(get_stylesheet_directory() . '/wc_templates/member/wc_changepassword_page.php') ){
3549 include(get_stylesheet_directory() . '/wc_templates/member/wc_changepassword_page.php');
3550 exit;
3551 }
3552 break;
3553 case 'newcompletion':
3554 case 'editcompletion':
3555 case 'lostcompletion':
3556 case 'changepasscompletion':
3557 if( file_exists(get_stylesheet_directory() . '/wc_templates/member/wc_member_completion_page.php') ){
3558 include(get_stylesheet_directory() . '/wc_templates/member/wc_member_completion_page.php');
3559 exit;
3560 }
3561 break;
3562 default:
3563 if( file_exists(get_stylesheet_directory() . '/wc_templates/member/wc_login_page.php') ){
3564 include(get_stylesheet_directory() . '/wc_templates/member/wc_login_page.php');
3565 exit;
3566 }
3567 }
3568 }
3569
3570 }else{
3571 // remove_action('the_post', array(&$this, 'goDefaultPage'));
3572 }
3573 }
3574
3575 function import() {
3576 $res = usces_import_xml();
3577 if ( $res === false ) :
3578 $this->action_status = 'error';
3579 //$this->action_message = __('Import was not completed.', 'usces');
3580 else :
3581 $this->action_status = 'success';
3582 $this->action_message = __('Import is cmpleted', 'usces');
3583 endif;
3584
3585 // require_once(USCES_PLUGIN_DIR . '/includes/admin_backup.php');
3586 }
3587
3588 function export() {
3589 $filename = 'usces.' . substr(get_date_from_gmt(gmdate('Y-m-d H:i:s', time())), 0, 10) . '.xml';
3590
3591 header('Content-Description: File Transfer');
3592 header("Content-Disposition: attachment; filename=$filename");
3593 header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
3594
3595 usces_export_xml();
3596 die();
3597
3598 }
3599
3600
3601 function changepassword() {
3602 global $wpdb;
3603
3604 if ( !isset($_SESSION['usces_lostmail']) ) :
3605 $this->error_message = __('Failed in update due to time-out', 'usces');
3606 return 'login';
3607 else :
3608
3609 $member_table = $wpdb->prefix . "usces_member";
3610
3611 $query = $wpdb->prepare("UPDATE $member_table SET mem_pass = %s WHERE mem_email = %s",
3612 md5(trim($_POST['loginpass1'])), $_SESSION['usces_lostmail']);
3613 $res = $wpdb->query( $query );
3614 //$res = $wpdb->last_results;
3615
3616 if ( $res === false ) :
3617 $this->error_message = __('Error: failure in updating password', 'usces');
3618 return 'login';
3619 else :
3620 return 'changepasscompletion';
3621 endif;
3622
3623 endif;
3624 }
3625
3626 function lostmail() {
3627 $delim = apply_filters( 'usces_filter_delim', $this->delim );
3628
3629 $_SESSION['usces_lostmail'] = trim($_POST['loginmail']);
3630 $id = session_id();
3631 $uri = USCES_MEMBER_URL . $delim . 'uscesmode=changepassword';
3632 $res = usces_lostmail($uri);
3633 return $res;
3634
3635 }
3636
3637 function regist_member() {
3638 global $wpdb;
3639 $_POST = $this->stripslashes_deep_post($_POST);
3640
3641 $member = $this->get_member();
3642 $mode = $_POST['member_regmode'];
3643 $member_table = $wpdb->prefix . "usces_member";
3644 $member_meta_table = $wpdb->prefix . "usces_member_meta";
3645
3646 //20110715ysk start 0000203
3647 //$error_mes = ( $_POST['member_regmode'] == 'newmemberfromcart' ) ? $this->member_check_fromcart() : $this->member_check();
3648 $error_mes = ( $_POST['member_regmode'] == 'newmemberfromcart' or $_POST['member_regmode'] == 'editmemberfromcart' ) ? $this->member_check_fromcart() : $this->member_check();
3649 //20110715ysk end
3650
3651 if ( $error_mes != '' ) {
3652
3653 $this->error_message = $error_mes;
3654 return $mode;
3655
3656 } elseif ( $_POST['member_regmode'] == 'editmemberform' ) {
3657
3658 do_action('usces_action_pre_edit_memberdata', $_POST['member'], $_POST['member_id']);
3659
3660 //20130802ysk start 0000741
3661 $query = $wpdb->prepare("SELECT ID FROM $member_table WHERE mem_email = %s", trim($_POST['member']['mailaddress1']));
3662 $id = $wpdb->get_var( $query );
3663 if ( !empty($id) and $id != $_POST['member_id'] ) {
3664 $this->error_message = __('This e-mail address has been already registered.', 'usces');
3665 return $mode;
3666 }
3667 //20130802ysk end
3668
3669 $query = $wpdb->prepare("SELECT mem_pass FROM $member_table WHERE ID = %d", $_POST['member_id']);
3670 $pass = $wpdb->get_var( $query );
3671
3672 $password = ( !empty($_POST['member']['password1']) && trim($_POST['member']['password1']) == trim($_POST['member']['password2']) ) ? md5(trim($_POST['member']['password1'])) : $pass;
3673 $query = $wpdb->prepare("UPDATE $member_table SET
3674 mem_pass = %s, mem_name1 = %s, mem_name2 = %s, mem_name3 = %s, mem_name4 = %s,
3675 mem_zip = %s, mem_pref = %s, mem_address1 = %s, mem_address2 = %s,
3676 mem_address3 = %s, mem_tel = %s, mem_fax = %s, mem_email = %s WHERE ID = %d",
3677 $password,
3678 trim($_POST['member']['name1']),
3679 trim($_POST['member']['name2']),
3680 trim($_POST['member']['name3']),
3681 trim($_POST['member']['name4']),
3682 trim($_POST['member']['zipcode']),
3683 trim($_POST['member']['pref']),
3684 trim($_POST['member']['address1']),
3685 trim($_POST['member']['address2']),
3686 trim($_POST['member']['address3']),
3687 trim($_POST['member']['tel']),
3688 trim($_POST['member']['fax']),
3689 trim($_POST['member']['mailaddress1']),
3690 $_POST['member_id']
3691 );
3692 $res = $wpdb->query( $query );
3693
3694 if( $res !== false ){
3695 $this->set_member_meta_value('customer_country', $_POST['member']['country'], $_POST['member_id']);
3696 //20100818ysk start
3697 $res = $this->reg_custom_member($_POST['member_id']);
3698 //20100818ysk end
3699 do_action('usces_action_edit_memberdata', $_POST['member'], $_POST['member_id']);
3700 $meta_keys = apply_filters( 'usces_filter_delete_member_pcid', "'zeus_pcid', 'remise_pcid', 'digitalcheck_ip_user_id'" );
3701 $query = $wpdb->prepare("DELETE FROM $member_meta_table WHERE member_id = %d AND meta_key IN( $meta_keys )",
3702 $_POST['member_id']
3703 );
3704 $res = $wpdb->query( $query );
3705
3706 $this->get_current_member();
3707 return 'editmemberform';
3708
3709 } else {
3710 $this->error_message = __('Error:failure in update', 'usces');
3711 return $mode;
3712 }
3713
3714 } elseif ( $_POST['member_regmode'] == 'newmemberform' ) {
3715
3716 $query = $wpdb->prepare("SELECT ID FROM $member_table WHERE mem_email = %s", trim($_POST['member']['mailaddress1']));
3717 $id = $wpdb->get_var( $query );
3718 if ( !empty($id) ) {
3719 $this->error_message = __('This e-mail address has been already registered.', 'usces');
3720 return $mode;
3721 } else {
3722
3723 $point = $this->options['start_point'];
3724 $pass = md5(trim($_POST['member']['password1']));
3725 $query = $wpdb->prepare("INSERT INTO $member_table
3726 (mem_email, mem_pass, mem_status, mem_cookie, mem_point,
3727 mem_name1, mem_name2, mem_name3, mem_name4, mem_zip, mem_pref,
3728 mem_address1, mem_address2, mem_address3, mem_tel, mem_fax,
3729 mem_delivery_flag, mem_delivery, mem_registered, mem_nicename)
3730 VALUES (%s, %s, %d, %s, %d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s)",
3731 trim($_POST['member']['mailaddress1']),
3732 $pass,
3733 0,
3734 "",
3735 $point,
3736 trim($_POST['member']['name1']),
3737 trim($_POST['member']['name2']),
3738 trim($_POST['member']['name3']),
3739 trim($_POST['member']['name4']),
3740 trim($_POST['member']['zipcode']),
3741 trim($_POST['member']['pref']),
3742 trim($_POST['member']['address1']),
3743 trim($_POST['member']['address2']),
3744 trim($_POST['member']['address3']),
3745 trim($_POST['member']['tel']),
3746 trim($_POST['member']['fax']),
3747 '',
3748 '',
3749 get_date_from_gmt(gmdate('Y-m-d H:i:s', time())),
3750 '');
3751 $res = $wpdb->query( $query );
3752
3753 //$_SESSION['usces_member']['ID'] = $wpdb->insert_id;
3754 //$this->get_current_member();
3755 if($res !== false) {
3756 $user = $_POST['member'];
3757 $user['ID'] = $wpdb->insert_id;
3758 $this->set_member_meta_value('customer_country', $_POST['member']['country'], $user['ID']);
3759 //20110714ysk start 0000207
3760 //20100818ysk start
3761 //$res = $this->reg_custom_member($wpdb->insert_id);
3762 $res = $this->reg_custom_member($user['ID']);
3763 //20100818ysk end
3764 //20110714ysk end
3765 $mser = usces_send_regmembermail($user);
3766
3767 do_action('usces_action_member_registered', $_POST['member'], $user['ID']);
3768
3769 return 'newcompletion';
3770
3771 } else {
3772 $this->error_message = __('Error:failure in update', 'usces');
3773 return $mode;
3774 }
3775 }
3776
3777 } elseif ( $_POST['member_regmode'] == 'newmemberfromcart' ) {
3778
3779 $query = $wpdb->prepare("SELECT ID FROM $member_table WHERE mem_email = %s", trim($_POST['customer']['mailaddress1']));
3780 $id = $wpdb->get_var( $query );
3781 if ( !empty($id) ) {
3782 $this->error_message = __('This e-mail address has been already registered.', 'usces');
3783 return $mode;
3784 } else {
3785
3786 $point = $this->options['start_point'];
3787 $pass = md5(trim($_POST['customer']['password1']));
3788 $query = $wpdb->prepare("INSERT INTO $member_table
3789 (mem_email, mem_pass, mem_status, mem_cookie, mem_point,
3790 mem_name1, mem_name2, mem_name3, mem_name4, mem_zip, mem_pref,
3791 mem_address1, mem_address2, mem_address3, mem_tel, mem_fax,
3792 mem_delivery_flag, mem_delivery, mem_registered, mem_nicename)
3793 VALUES (%s, %s, %d, %s, %d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s)",
3794 trim($_POST['customer']['mailaddress1']),
3795 $pass,
3796 0,
3797 "",
3798 $point,
3799 trim($_POST['customer']['name1']),
3800 trim($_POST['customer']['name2']),
3801 trim($_POST['customer']['name3']),
3802 trim($_POST['customer']['name4']),
3803 trim($_POST['customer']['zipcode']),
3804 trim($_POST['customer']['pref']),
3805 trim($_POST['customer']['address1']),
3806 trim($_POST['customer']['address2']),
3807 trim($_POST['customer']['address3']),
3808 trim($_POST['customer']['tel']),
3809 trim($_POST['customer']['fax']),
3810 '',
3811 '',
3812 get_date_from_gmt(gmdate('Y-m-d H:i:s', time())),
3813 '');
3814 $res = $wpdb->query( $query );
3815
3816 //$_SESSION['usces_member']['ID'] = $wpdb->insert_id;
3817 //$this->get_current_member();
3818 if($res !== false) {
3819 //20110714ysk start 0000207
3820 $member_id = $wpdb->insert_id;
3821 //$this->set_member_meta_value('customer_country', $_POST['member']['country'], $wpdb->insert_id);
3822 $this->set_member_meta_value('customer_country', $_POST['customer']['country'], $member_id);
3823 //20100818ysk start
3824 //$res = $this->reg_custom_member($wpdb->insert_id);
3825 $res = $this->reg_custom_member($member_id);
3826 //20100818ysk end
3827 //20110714ysk end
3828 //usces_send_regmembermail();
3829 do_action('usces_action_member_registered', $_POST['customer'], $member_id);
3830 $user = $_POST['customer'];
3831 $user['ID'] = $member_id;
3832 $mser = usces_send_regmembermail($user);
3833 $_POST['loginmail'] = trim($_POST['customer']['mailaddress1']);
3834 $_POST['loginpass'] = trim($_POST['customer']['password1']);
3835 if( $this->member_login() == 'member' ){
3836 $_SESSION['usces_entry']['member_regmode'] = 'editmemberfromcart';
3837 return 'newcompletion';
3838 }
3839
3840 } else {
3841 $this->error_message = __('Error:failure in update', 'usces');
3842 return $mode;
3843 }
3844 }
3845
3846 //20110715ysk start 0000203
3847 } elseif ( $_POST['member_regmode'] == 'editmemberfromcart' ) {
3848
3849 do_action('usces_action_pre_edit_memberdata', $_POST['customer'], $_POST['member_id']);
3850
3851 $query = $wpdb->prepare("SELECT mem_pass FROM $member_table WHERE ID = %d", $_POST['member_id']);
3852 $pass = $wpdb->get_var( $query );
3853
3854 $password = ( !empty($_POST['customer']['password1']) && trim($_POST['customer']['password1']) == trim($_POST['customer']['password2']) ) ? md5(trim($_POST['customer']['password1'])) : $pass;
3855 $query = $wpdb->prepare("UPDATE $member_table SET
3856 mem_pass = %s, mem_name1 = %s, mem_name2 = %s, mem_name3 = %s, mem_name4 = %s,
3857 mem_zip = %s, mem_pref = %s, mem_address1 = %s, mem_address2 = %s,
3858 mem_address3 = %s, mem_tel = %s, mem_fax = %s, mem_email = %s WHERE ID = %d",
3859 $password,
3860 trim($_POST['customer']['name1']),
3861 trim($_POST['customer']['name2']),
3862 trim($_POST['customer']['name3']),
3863 trim($_POST['customer']['name4']),
3864 trim($_POST['customer']['zipcode']),
3865 trim($_POST['customer']['pref']),
3866 trim($_POST['customer']['address1']),
3867 trim($_POST['customer']['address2']),
3868 trim($_POST['customer']['address3']),
3869 trim($_POST['customer']['tel']),
3870 trim($_POST['customer']['fax']),
3871 trim($_POST['customer']['mailaddress1']),
3872 $_POST['member_id']
3873 );
3874 $res = $wpdb->query( $query );
3875 if( $res !== false ){
3876 $this->set_member_meta_value('customer_country', $_POST['customer']['country'], $_POST['member_id']);
3877 $res = $this->reg_custom_member($_POST['member_id']);
3878 do_action('usces_action_edit_memberdata', $_POST['customer'], $_POST['member_id']);
3879 unset($_SESSION['usces_member']);
3880 $this->member_just_login(trim($_POST['customer']['mailaddress1']), trim($_POST['customer']['password1']));
3881 return 'newcompletion';
3882
3883 } else {
3884 $this->error_message = __('Error:failure in update', 'usces');
3885 return $mode;
3886 }
3887 //20110715ysk end
3888 }
3889 }
3890
3891 function delete_member() {
3892 if( ! $this->is_member_logged_in() )
3893 return false;
3894 $mem = $this->get_member();
3895 if( ! $mem['ID'] )
3896 return false;
3897
3898 $res = usces_delete_memberdata( $mem['ID'] );
3899 if( $res ) {
3900 usces_send_delmembermail( $mem );
3901 }
3902
3903 return $res;
3904 }
3905
3906 function is_member_logged_in( $id = false ) {
3907 if( $id === false ){
3908 if( !empty($_SESSION['usces_member']['ID']) )
3909 return true;
3910 else
3911 return false;
3912 }else{
3913 if( !empty($_SESSION['usces_member']['ID']) && $_SESSION['usces_member']['ID'] == $id )
3914 return true;
3915 else
3916 return false;
3917 }
3918 }
3919
3920 function is_member($email) {
3921 global $wpdb;
3922
3923 $member_table = $wpdb->prefix . "usces_member";
3924 $query = $wpdb->prepare("SELECT mem_email FROM $member_table WHERE mem_email = %s", $email);
3925 $member = $wpdb->get_row( $query, ARRAY_A );
3926 if ( empty($member) ) {
3927 return false;
3928 }else{
3929 return true;
3930 }
3931 }
3932
3933 function member_login() {
3934 global $wpdb;
3935 $_POST = $this->stripslashes_deep_post($_POST);
3936
3937 $cookie = $this->get_cookie();
3938
3939
3940 if ( isset($cookie['rme']) && $cookie['rme'] == 'forever' && !isset($_POST['rememberme']) && !isset($_POST['loginmail'])) {
3941 $email = $cookie['name'];
3942 $member_table = $wpdb->prefix . "usces_member";
3943
3944 $query = $wpdb->prepare("SELECT ID FROM $member_table WHERE mem_email = %s", $email);
3945 $id = $wpdb->get_var( $query );
3946
3947 if ( !$id ) {
3948 $this->current_member['email'] = htmlspecialchars($email);
3949 $this->error_message = __('<b>Error:</b> E-mail address is not correct.', 'usces');
3950 return 'login';
3951 } else {
3952 $query = $wpdb->prepare("SELECT * FROM $member_table WHERE mem_email = %s", $email);
3953 $member = $wpdb->get_row( $query, ARRAY_A );
3954 if ( empty($member) ) {
3955 $this->current_member['email'] = htmlspecialchars($email);
3956 $this->error_message = __('<b>Error:</b> Password is not correct.', 'usces');
3957 return 'login';
3958 } else {
3959 $_SESSION['usces_member']['ID'] = $member['ID'];
3960 $_SESSION['usces_member']['mailaddress1'] = $member['mem_email'];
3961 $_SESSION['usces_member']['mailaddress2'] = $member['mem_email'];
3962 $_SESSION['usces_member']['point'] = $member['mem_point'];
3963 $_SESSION['usces_member']['name1'] = $member['mem_name1'];
3964 $_SESSION['usces_member']['name2'] = $member['mem_name2'];
3965 $_SESSION['usces_member']['name3'] = $member['mem_name3'];
3966 $_SESSION['usces_member']['name4'] = $member['mem_name4'];
3967 $_SESSION['usces_member']['zipcode'] = $member['mem_zip'];
3968 $_SESSION['usces_member']['pref'] = $member['mem_pref'];
3969 $_SESSION['usces_member']['address1'] = $member['mem_address1'];
3970 $_SESSION['usces_member']['address2'] = $member['mem_address2'];
3971 $_SESSION['usces_member']['address3'] = $member['mem_address3'];
3972 $_SESSION['usces_member']['tel'] = $member['mem_tel'];
3973 $_SESSION['usces_member']['fax'] = $member['mem_fax'];
3974 $_SESSION['usces_member']['delivery_flag'] = $member['mem_delivery_flag'];
3975 $_SESSION['usces_member']['delivery'] = !empty($member['mem_delivery']) ? unserialize($member['mem_delivery']) : '';
3976 $_SESSION['usces_member']['registered'] = $member['mem_registered'];
3977 $_SESSION['usces_member']['nicename'] = $member['mem_nicename'];
3978 $_SESSION['usces_member']['country'] = $this->get_member_meta_value('customer_country', $member['ID']);
3979 $_SESSION['usces_member']['status'] = $member['mem_status'];
3980 //20100818ysk start
3981 $this->set_session_custom_member($member['ID']);
3982 //20100818ysk end
3983 $this->get_current_member();
3984
3985 do_action( 'usces_action_after_login' );
3986 return apply_filters( 'usces_filter_member_login', 'member', $member );
3987 }
3988 }
3989 } else if ( isset($_POST['loginmail']) && WCUtils::is_blank($_POST['loginmail']) && isset($_POST['loginpass']) && WCUtils::is_blank($_POST['loginpass']) && isset($cookie['rme']) && $cookie['rme'] != 'forever' ) {
3990 return 'login';
3991 } else if ( isset($_POST['loginmail']) && WCUtils::is_blank($_POST['loginpass']) && isset($cookie['rme']) && $cookie['rme'] != 'forever' ) {
3992 $this->current_member['email'] = trim($_POST['loginmail']);
3993 $this->error_message = __('<b>Error:</b> Enter the password.', 'usces');
3994 return 'login';
3995 } else if ( !isset($_POST['loginmail']) ){
3996 return 'login';
3997 } else {
3998 $email = isset($_POST['loginmail']) ? trim($_POST['loginmail']) : '';
3999 $pass = isset($_POST['loginpass']) ? md5(trim($_POST['loginpass'])) : '';
4000 $member_table = $wpdb->prefix . "usces_member";
4001
4002 $query = $wpdb->prepare("SELECT ID FROM $member_table WHERE mem_email = %s", $email);
4003 $id = $wpdb->get_var( $query );
4004
4005 if ( !$id ) {
4006 $this->current_member['email'] = htmlspecialchars($email);
4007 $this->error_message = __('<b>Error:</b> E-mail address is not correct.', 'usces');
4008 return 'login';
4009 } else {
4010 $query = $wpdb->prepare("SELECT * FROM $member_table WHERE mem_email = %s AND mem_pass = %s", $email, $pass);
4011 $member = $wpdb->get_row( $query, ARRAY_A );
4012 if ( empty($member) ) {
4013 $this->current_member['email'] = htmlspecialchars($email);
4014 $this->error_message = __('<b>Error:</b> Password is not correct.', 'usces');
4015 return 'login';
4016 } else {
4017 $_SESSION['usces_member']['ID'] = $member['ID'];
4018 $_SESSION['usces_member']['mailaddress1'] = $member['mem_email'];
4019 $_SESSION['usces_member']['mailaddress2'] = $member['mem_email'];
4020 $_SESSION['usces_member']['point'] = $member['mem_point'];
4021 $_SESSION['usces_member']['name1'] = $member['mem_name1'];
4022 $_SESSION['usces_member']['name2'] = $member['mem_name2'];
4023 $_SESSION['usces_member']['name3'] = $member['mem_name3'];
4024 $_SESSION['usces_member']['name4'] = $member['mem_name4'];
4025 $_SESSION['usces_member']['zipcode'] = $member['mem_zip'];
4026 $_SESSION['usces_member']['pref'] = $member['mem_pref'];
4027 $_SESSION['usces_member']['address1'] = $member['mem_address1'];
4028 $_SESSION['usces_member']['address2'] = $member['mem_address2'];
4029 $_SESSION['usces_member']['address3'] = $member['mem_address3'];
4030 $_SESSION['usces_member']['tel'] = $member['mem_tel'];
4031 $_SESSION['usces_member']['fax'] = $member['mem_fax'];
4032 $_SESSION['usces_member']['delivery_flag'] = $member['mem_delivery_flag'];
4033 $_SESSION['usces_member']['delivery'] = !empty($member['mem_delivery']) ? unserialize($member['mem_delivery']) : '';
4034 $_SESSION['usces_member']['registered'] = $member['mem_registered'];
4035 $_SESSION['usces_member']['nicename'] = $member['mem_nicename'];
4036 $_SESSION['usces_member']['country'] = $this->get_member_meta_value('customer_country', $member['ID']);
4037 $_SESSION['usces_member']['status'] = $member['mem_status'];
4038 //20100818ysk start
4039 $this->set_session_custom_member($member['ID']);
4040 //20100818ysk end
4041 $this->get_current_member();
4042
4043 if( isset($_POST['rememberme']) ){
4044 $cookie['name'] = $email;
4045 $cookie['rme'] = 'forever';
4046 $this->set_cookie($cookie);
4047 }else{
4048 $cookie['name'] = '';
4049 $cookie['rme'] = '';
4050 $this->set_cookie($cookie);
4051 }
4052
4053 do_action( 'usces_action_after_login' );
4054 return apply_filters( 'usces_filter_member_login', 'member', $member );
4055 }
4056 }
4057 }
4058 }
4059
4060 function member_just_login($email, $pass) {
4061 global $wpdb;
4062 $pass = md5($pass);
4063 $member_table = $wpdb->prefix . "usces_member";
4064
4065 $query = $wpdb->prepare("SELECT * FROM $member_table WHERE mem_email = %s AND mem_pass = %s", $email, $pass);
4066 $member = $wpdb->get_row( $query, ARRAY_A );
4067 if ( empty($member) ) {
4068 $this->current_member['email'] = htmlspecialchars($email);
4069 $this->error_message = __('<b>Error:</b> Password is not correct.', 'usces');
4070 return 'login';
4071 } else {
4072 $_SESSION['usces_member']['ID'] = $member['ID'];
4073 $_SESSION['usces_member']['mailaddress1'] = $member['mem_email'];
4074 $_SESSION['usces_member']['mailaddress2'] = $member['mem_email'];
4075 $_SESSION['usces_member']['point'] = $member['mem_point'];
4076 $_SESSION['usces_member']['name1'] = $member['mem_name1'];
4077 $_SESSION['usces_member']['name2'] = $member['mem_name2'];
4078 $_SESSION['usces_member']['name3'] = $member['mem_name3'];
4079 $_SESSION['usces_member']['name4'] = $member['mem_name4'];
4080 $_SESSION['usces_member']['zipcode'] = $member['mem_zip'];
4081 $_SESSION['usces_member']['pref'] = $member['mem_pref'];
4082 $_SESSION['usces_member']['address1'] = $member['mem_address1'];
4083 $_SESSION['usces_member']['address2'] = $member['mem_address2'];
4084 $_SESSION['usces_member']['address3'] = $member['mem_address3'];
4085 $_SESSION['usces_member']['tel'] = $member['mem_tel'];
4086 $_SESSION['usces_member']['fax'] = $member['mem_fax'];
4087 $_SESSION['usces_member']['delivery_flag'] = $member['mem_delivery_flag'];
4088 $_SESSION['usces_member']['delivery'] = !empty($member['mem_delivery']) ? unserialize($member['mem_delivery']) : '';
4089 $_SESSION['usces_member']['registered'] = $member['mem_registered'];
4090 $_SESSION['usces_member']['nicename'] = $member['mem_nicename'];
4091 $_SESSION['usces_member']['country'] = $this->get_member_meta_value('customer_country', $member['ID']);
4092 $_SESSION['usces_member']['status'] = $member['mem_status'];
4093 //20100818ysk start
4094 $this->set_session_custom_member($member['ID']);
4095 //20100818ysk end
4096 $this->get_current_member();
4097
4098 // $cookie = $this->get_cookie();
4099 // if(isset($_POST['rememberme']) && $cookie){
4100 // $cookie['name'] = $email;
4101 // $cookie['pass'] = trim($_POST['loginpass']);
4102 // $this->set_cookie($cookie);
4103 // }else{
4104 // $cookie['name'] = '';
4105 // $cookie['pass'] = '';
4106 // $this->set_cookie($cookie);
4107 // }
4108
4109 do_action( 'usces_action_after_login' );
4110 return apply_filters( 'usces_filter_member_login', 'member', $member );
4111 }
4112 }
4113
4114 function member_logout() {
4115 unset($_SESSION['usces_member'], $_SESSION['usces_entry']);
4116 do_action('usces_action_member_logout');
4117 wp_redirect(get_option('home'));
4118 exit;
4119 }
4120
4121 function get_current_member() {
4122
4123 if ( isset($_SESSION['usces_member']['ID']) ) {
4124 $this->current_member['id'] = $_SESSION['usces_member']['ID'];
4125 $this->current_member['name'] = usces_localized_name( $_SESSION['usces_member']['name1'], $_SESSION['usces_member']['name2'], 'return');
4126 } else {
4127 $this->current_member['id'] = 0;
4128 $this->current_member['name'] = __('guest', 'usces');
4129 }
4130 }
4131
4132 function get_member() {
4133 $res = array(
4134 'ID' => '',
4135 'registered' => '',
4136 'mailaddress1' => '',
4137 'mailaddress2' => '',
4138 'password1' => '',
4139 'password2' => '',
4140 'point' => '',
4141 'name1' => '',
4142 'name2' => '',
4143 'name3' => '',
4144 'name4' => '',
4145 'zipcode' => '',
4146 'address1' => '',
4147 'address2' => '',
4148 'address3' => '',
4149 'tel' => '',
4150 'fax' => '',
4151 'country' => '',
4152 'pref' => '',
4153 'status' => ''
4154 );
4155 if(!empty($_SESSION['usces_member'])) {
4156 foreach ( $_SESSION['usces_member'] as $key => $value ) {
4157 //20100818ysk start
4158 if(is_array($_SESSION['usces_member'][$key]))
4159 $res[$key] = stripslashes_deep($value);
4160 else
4161 //20100818ysk end
4162 $res[$key] = stripslashes($value);
4163 }
4164 }
4165 return $res;
4166 }
4167
4168 function get_member_info( $mid ) {
4169 global $wpdb;
4170 $infos = array();
4171
4172 //if( !current_user_can('activate_plugins') ) return array();
4173
4174 $table = $wpdb->prefix . "usces_member";
4175 $query = $wpdb->prepare("SELECT * FROM $table WHERE ID = %d", $mid);
4176 $datas = $wpdb->get_results( $query, ARRAY_A );
4177 if( $datas ) {
4178 $infos = $datas[0];
4179
4180 $table = $wpdb->prefix . "usces_member_meta";
4181 $query = $wpdb->prepare("SELECT meta_key, meta_value FROM $table WHERE member_id = %d", $mid);
4182 $metas = $wpdb->get_results( $query, ARRAY_A );
4183
4184 foreach( $metas as $meta ){
4185 $infos[$meta['meta_key']] = maybe_unserialize($meta['meta_value']);
4186 }
4187 }
4188 return $infos;
4189 }
4190
4191 function is_order($mid, $oid) {
4192 global $wpdb;
4193
4194 $table = $wpdb->prefix . "usces_order";
4195 $query = $wpdb->prepare("SELECT ID FROM $table WHERE ID = %d AND mem_id = %d", $oid, $mid);
4196 $mem_id = $wpdb->get_var( $query );
4197 if ( empty($mem_id) ) {
4198 return false;
4199 }else{
4200 return true;
4201 }
4202 }
4203
4204 function is_purchased_item($mid, $post_id, $sku = NULL) {
4205 global $wpdb;
4206 $res = false;
4207
4208 $history = $this->get_member_history($mid);
4209 foreach ( $history as $umhs ) {
4210 $cart = $umhs['cart'];
4211 $status = $umhs['order_status'];
4212 for($i=0; $i<count($cart); $i++) {
4213 $cart_row = $cart[$i];
4214 $sku_code = urldecode($cart_row['sku']);
4215 if( empty($sku) ){
4216 if( $cart_row['post_id'] == $post_id && (false === strpos($status, 'noreceipt') && false === strpos($status, 'pending')) ){
4217 $res = true;
4218 break 2;
4219 }elseif( $cart_row['post_id'] == $post_id && (false !== strpos($status, 'noreceipt') || false !== strpos($status, 'pending')) ){
4220 $res = 'noreceipt';
4221 break 2;
4222 }
4223 }else{
4224 if( $cart_row['post_id'] == $post_id && $sku_code == $sku && (false === strpos($status, 'noreceipt') && false === strpos($status, 'pending')) ){
4225 $res = true;
4226 break 2;
4227 }elseif( $cart_row['post_id'] == $post_id && $sku_code == $sku && (false !== strpos($status, 'noreceipt') || false !== strpos($status, 'pending')) ){
4228 $res = 'noreceipt';
4229 break 2;
4230 }
4231 }
4232 }
4233
4234 }
4235 return $res;
4236 }
4237
4238 function get_order_data($order_id, $mode = '' ) {
4239 global $wpdb, $usces;
4240 $order_table = $wpdb->prefix . "usces_order";
4241
4242 $query = $wpdb->prepare("SELECT * FROM $order_table WHERE ID = %d", $order_id);
4243
4244 if( 'direct' == $mode ){
4245 $value = $wpdb->get_row( $query, ARRAY_A );
4246 return $value;
4247 }
4248
4249 $value = $wpdb->get_row( $query );
4250
4251 if( $value == NULL ) {
4252 return false;
4253 }else{
4254 $res =array();
4255 }
4256 if(strpos($value->order_status, 'cancel') !== false || strpos($value->order_status, 'estimate') !== false){
4257 return false;
4258 }
4259
4260 $res = array(
4261 'ID' => $value->ID,
4262 'mem_id' => $value->mem_id,
4263 'cart' => unserialize($value->order_cart),
4264 'condition' => unserialize($value->order_condition),
4265 'getpoint' => $value->order_getpoint,
4266 'usedpoint' => $value->order_usedpoint,
4267 'discount' => $value->order_discount,
4268 'payment_name' => $value->order_payment_name,
4269 'shipping_charge' => $value->order_shipping_charge,
4270 'cod_fee' => $value->order_cod_fee,
4271 'tax' => $value->order_tax,
4272 'end_price' => $value->order_item_total_price - ($value->order_getpoint*$usces->options['system']['pointreduction']) + $value->order_discount + $value->order_shipping_charge + $value->order_cod_fee + $value->order_tax,
4273 'status' => $value->order_status,
4274 'date' => mysql2date(__('Y/m/d'), $value->order_date),
4275 'modified' => mysql2date(__('Y/m/d'), $value->order_modified)
4276 );
4277
4278 return $res;
4279 }
4280
4281 function get_orderIDs_by_postID($mem_id, $post_id) {
4282 global $wpdb;
4283 $order_table = $wpdb->prefix . "usces_order";
4284
4285 $query = $wpdb->prepare("SELECT ID, order_cart, order_status FROM $order_table WHERE mem_id = %d ORDER BY order_modified DESC, order_date DESC", $mem_id);
4286 $rows = $wpdb->get_query( $query, ARRAY_A );
4287
4288 if( $value == NULL ) {
4289 return false;
4290 }else{
4291 foreach($rows as $row){
4292 if(strpos($row['order_status'], 'cancel') !== false || strpos($row['order_status'], 'estimate') !== false){
4293 continue;
4294 }else{
4295 $carts = unserialize($row['order_cart']);
4296 foreach($carts as $cart){
4297 if( $post_id == $cart['post_id'] ){
4298 $res[] = $row['ID'];
4299 break;
4300 }
4301 }
4302 }
4303 }
4304 }
4305 return $res;
4306 }
4307
4308 function incart_check() {
4309 //$_POST = $this->stripslashes_deep_post($_POST);
4310 $mes = array();
4311
4312 $ids = array_keys($_POST['inCart']);
4313 $post_id = $ids[0];
4314 $skus = array_keys($_POST['inCart'][$post_id]);
4315 $sku = $skus[0];
4316 $quant = isset($_POST['quant'][$post_id][$sku]) ? (int)$_POST['quant'][$post_id][$sku] : 1;
4317 $stock = $this->getItemZaikoNum($post_id, $sku);
4318 $zaiko_id = (int)$this->getItemZaikoStatusId($post_id, $sku);
4319 $itemRestriction = get_post_meta($post_id, '_itemRestriction',true );
4320
4321 if( 1 > $quant ){
4322 $mes[$post_id][$sku] = __('enter the correct amount', 'usces') . "<br />";
4323 }else if( $quant > (int)$itemRestriction && !WCUtils::is_blank($itemRestriction) && !WCUtils::is_zero($itemRestriction) ){
4324 $mes[$post_id][$sku] = sprintf(__("This article is limited by %d at a time.", 'usces'), $itemRestriction) . "<br />";
4325 }else if( $quant > (int)$stock && !WCUtils::is_blank($stock) ){
4326 $mes[$post_id][$sku] = __('Sorry, stock is insufficient.', 'usces') . ' ' . __('Current stock', 'usces') . $stock . "<br />";
4327 }else if( 1 < $zaiko_id ){
4328 $mes[$post_id][$sku] = __('Sorry, this item is sold out.', 'usces') . "<br />";
4329 }
4330
4331 $ioptkeys = $this->get_itemOptionKey( $post_id, true );
4332 if($ioptkeys){
4333 foreach($ioptkeys as $key => $value){
4334 $optValues = $this->get_itemOptions( urldecode($value), $post_id );
4335 if( 0 == $optValues['means'] ){ //case of select
4336 if( $optValues['essential'] && '#NONE#' == $_POST['itemOption'][$post_id][$sku][$value] ){
4337 $mes[$post_id][$sku] .= sprintf(__("Chose the %s", 'usces'), urldecode($value)) . "<br />";
4338 }
4339 }elseif( 1 == $optValues['means'] ){ //case of multiselect
4340 if( $optValues['essential'] ){
4341 $mselect = 0;
4342 foreach((array)$_POST['itemOption'][$post_id][$sku][$value] as $mvalue){
4343 if(!empty($mvalue) and '#NONE#' != $mvalue) $mselect++;
4344 }
4345 if( $mselect == 0 ){
4346 $mes[$post_id][$sku] .= sprintf(__("Chose the %s", 'usces'), urldecode($value)) . "<br />";
4347 }
4348 }
4349 }else{ //case of text
4350 if( $optValues['essential'] && WCUtils::is_blank($_POST['itemOption'][$post_id][$sku][$value]) ){
4351 $mes[$post_id][$sku] .= sprintf(__("Input the %s", 'usces'), urldecode($value)) . "<br />";
4352 }
4353 }
4354 }
4355 }
4356
4357 $mes = apply_filters('usces_filter_incart_check', $mes, $post_id, $sku);
4358
4359 if( isset($mes[$post_id]) && is_array($mes[$post_id]) ){
4360 foreach( $mes[$post_id] as $skukey => $skuvalue ){
4361 $mes[$post_id][$skukey] = rtrim($skuvalue, "<br />");
4362 }
4363 }
4364
4365 if( !empty($mes) ){
4366 $_SESSION['usces_singleitem']['itemOption'] = $_POST['itemOption'];
4367 $_SESSION['usces_singleitem']['quant'] = $_POST['quant'];
4368 $_SESSION['usces_singleitem']['error_message'] = $mes;
4369 if( false === strpos($_POST['usces_referer'], 'http') ){
4370 $parse_url = parse_url(get_home_url());
4371 header('location: ' . $parse_url['scheme'] . '://' . $parse_url['host'] . $_POST['usces_referer'] . '#cart_button');
4372 }else{
4373 header('location: ' . $_POST['usces_referer'] . '#cart_button');
4374 }
4375 exit;
4376 }
4377
4378 do_action('usces_action_incart_checked', $mes, $post_id, $sku);
4379 }
4380
4381 function zaiko_check() {
4382 $mes = '';
4383 $cart = $this->cart->get_cart();
4384 $stocks = array();
4385
4386 for($i=0; $i<count($cart); $i++) {
4387 $cart_row = $cart[$i];
4388 $post_id = $cart_row['post_id'];
4389 $sku = $cart_row['sku'];
4390 $sku_code = urldecode($cart_row['sku']);
4391
4392 $quant = ( isset($_POST['quant']) ) ? trim($_POST['quant'][$i][$post_id][$sku]) : $cart_row['quantity'];
4393 //$zaiko_status = $this->getItemZaiko($post_id, $sku);
4394 $zaiko_id = (int)$this->getItemZaikoStatusId($post_id, $sku_code);
4395 $stock = $this->getItemZaikoNum($post_id, $sku_code);
4396 if( !isset($stocks[$post_id][$sku]) ){
4397 if( !WCUtils::is_blank($stock) ){
4398 $stocks[$post_id][$sku] = $stock;
4399 }else{
4400 $stocks[$post_id][$sku] = NULL;
4401 }
4402 }
4403 $checkstock = $stocks[$post_id][$sku];
4404 $stocks[$post_id][$sku] = $stocks[$post_id][$sku] - $quant;
4405 $itemRestriction = get_post_meta($post_id, '_itemRestriction', true);
4406
4407 //$red = (in_array($zaiko_status, array(__('Sold Out', 'usces'), __('Out Of Stock', 'usces'), __('Out of print', 'usces')))) ? 'red' : '';
4408
4409 if( 1 > (int)$quant ){
4410 $mes .= sprintf(__("Enter the correct amount for the No.%d item.", 'usces'), ($i+1)) . "<br />";
4411 }else if( 1 < $zaiko_id || WCUtils::is_zero($stock) ){
4412 $mes .= sprintf(__('Sorry, No.%d item is sold out.', 'usces'), ($i+1)) . "<br />";
4413 }else if( $quant > (int)$itemRestriction && !WCUtils::is_blank($itemRestriction) && !WCUtils::is_zero($itemRestriction) ){
4414 $mes .= sprintf(__('This article is limited by %1$d at a time for the No.%2$d item.', 'usces'), $itemRestriction, ($i+1)) . "<br />";
4415 }else if( 0 > $stocks[$post_id][$sku] && !WCUtils::is_blank($stock) ){
4416 $mes .= sprintf(__('Stock of No.%1$d item is remainder %2$d.', 'usces'), ($i+1), $checkstock) . "<br />";
4417 }
4418 }
4419 $mes = apply_filters('usces_filter_zaiko_check', $mes, $cart);
4420 return $mes;
4421 }
4422
4423 function member_check() {
4424 $mes = '';
4425 foreach ( $_POST['member'] as $key => $vlue ) {
4426 $_SESSION['usces_member'][$key] = trim($vlue);
4427 }
4428 if ( $_POST['member_regmode'] == 'editmemberform' ) {
4429 if ( (!WCUtils::is_blank($_POST['member']['password1']) || !WCUtils::is_blank($_POST['member']['password2']) ) && trim($_POST['member']['password1']) != trim($_POST['member']['password2']) )
4430 $mes .= __('Password is not correct.', 'usces') . "<br />";
4431 if ( !is_email($_POST['member']['mailaddress1']) || WCUtils::is_blank($_POST['member']['mailaddress1']) )
4432 $mes .= __('e-mail address is not correct', 'usces') . "<br />";
4433
4434 } else {
4435 if ( WCUtils::is_blank($_POST['member']['password1']) || WCUtils::is_blank($_POST['member']['password2']) || trim($_POST['member']['password1']) != trim($_POST['member']['password2']) )
4436 $mes .= __('Password is not correct.', 'usces') . "<br />";
4437 if ( !is_email($_POST['member']['mailaddress1']) || WCUtils::is_blank($_POST['member']['mailaddress1']) || WCUtils::is_blank($_POST['member']['mailaddress2']) || trim($_POST['member']['mailaddress1']) != trim($_POST['member']['mailaddress2']) )
4438 $mes .= __('e-mail address is not correct', 'usces') . "<br />";
4439
4440 }
4441 if ( WCUtils::is_blank($_POST["member"]["name1"]) )
4442 $mes .= __('Name is not correct', 'usces') . "<br />";//20111116ysk 0000299
4443 // if ( trim($_POST["member"]["name3"]) == "" && USCES_JP )
4444 // $mes .= __('Invalid CANNAT pretend.', 'usces') . "<br />";
4445 if ( WCUtils::is_blank($_POST["member"]["zipcode"]) )
4446 $mes .= __('postal code is not correct', 'usces') . "<br />";
4447 if ( $_POST["member"]["pref"] == __('-- Select --', 'usces') )
4448 $mes .= __('enter the prefecture', 'usces') . "<br />";
4449 if ( WCUtils::is_blank($_POST["member"]["address1"]) )
4450 $mes .= __('enter the city name', 'usces') . "<br />";
4451 if ( WCUtils::is_blank($_POST["member"]["address2"]) )
4452 $mes .= __('enter house numbers', 'usces') . "<br />";
4453 if ( WCUtils::is_blank($_POST["member"]["tel"]) )
4454 $mes .= __('enter phone numbers', 'usces') . "<br />";
4455 if( !WCUtils::is_blank($_POST['member']["tel"]) && preg_match("/[^\d-]/", trim($_POST["member"]["tel"])) )
4456 $mes .= __('Please input a phone number with a half size number.', 'usces') . "<br />";
4457
4458 $mes = apply_filters('usces_filter_member_check', $mes);
4459
4460 return $mes;
4461 }
4462
4463 function member_check_fromcart() {
4464 $mes = '';
4465 if ( WCUtils::is_blank($_POST['customer']['password1']) || WCUtils::is_blank($_POST['customer']['password2']) || trim($_POST['customer']['password1']) != trim($_POST['customer']['password2']) )
4466 $mes .= __('Password is not correct.', 'usces') . "<br />";
4467 if ( !is_email($_POST['customer']['mailaddress1']) || WCUtils::is_blank($_POST['customer']['mailaddress1']) || WCUtils::is_blank($_POST['customer']['mailaddress2']) || trim($_POST['customer']['mailaddress1']) != trim($_POST['customer']['mailaddress2']) )
4468 $mes .= __('e-mail address is not correct', 'usces') . "<br />";
4469 if ( WCUtils::is_blank($_POST["customer"]["name1"]) )
4470 $mes .= __('Name is not correct', 'usces') . "<br />";//20111116ysk 0000299
4471 // if ( trim($_POST["customer"]["name3"]) == "" && USCES_JP )
4472 // $mes .= __('Invalid CANNAT pretend.', 'usces') . "<br />";
4473 if ( WCUtils::is_blank($_POST["customer"]["zipcode"]) )
4474 $mes .= __('postal code is not correct', 'usces') . "<br />";
4475 if ( $_POST["customer"]["pref"] == __('-- Select --', 'usces') )
4476 $mes .= __('enter the prefecture', 'usces') . "<br />";
4477 if ( WCUtils::is_blank($_POST["customer"]["address1"]) )
4478 $mes .= __('enter the city name', 'usces') . "<br />";
4479 if ( WCUtils::is_blank($_POST["customer"]["address2"]) )
4480 $mes .= __('enter house numbers', 'usces') . "<br />";
4481 if ( WCUtils::is_blank($_POST["customer"]["tel"]) )
4482 $mes .= __('enter phone numbers', 'usces') . "<br />";
4483 if( !WCUtils::is_blank($_POST['customer']["tel"]) && preg_match("/[^\d-]/", trim($_POST["customer"]["tel"])) )
4484 $mes .= __('Please input a phone number with a half size number.', 'usces') . "<br />";
4485
4486 $mes = apply_filters('usces_filter_member_check_fromcart', $mes);
4487
4488 return $mes;
4489 }
4490
4491 function admin_member_check() {
4492 global $wpdb;
4493 $mes = '';
4494 if ( !is_email( trim($_POST['member']["email"]) ) ){
4495 $mes .= __('e-mail address is not correct', 'usces') . "<br />";
4496 }else{
4497 $member_table = $wpdb->prefix . "usces_member";
4498 $mem_email = $wpdb->get_var( $wpdb->prepare("SELECT mem_email FROM $member_table WHERE ID = %d LIMIT 1", trim($_POST['member_id'])) );
4499 if( trim($_POST['member']["email"]) != $mem_email ){
4500 $mem_ID = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $member_table WHERE mem_email = %s LIMIT 1", trim($_POST['member']["email"])) );
4501 if( !empty($mem_ID) )
4502 $mes .= __('This e-mail address has been already registered.', 'usces') . "<br />";
4503 }
4504 }
4505 if ( WCUtils::is_blank($_POST['member']["name1"]) )
4506 $mes .= __('Name is not correct', 'usces') . "<br />";
4507 // if ( trim($_POST["mem_name3"]) == "" && USCES_JP )
4508 // $mes .= __('Invalid CANNAT pretend.', 'usces') . "<br />";
4509 // if ( trim($_POST['member']["zipcode"]) == "" )
4510 // $mes .= __('postal code is not correct', 'usces') . "<br />";
4511 // if ( $_POST['member']["pref"] == __('-- Select --', 'usces') )
4512 // $mes .= __('enter the prefecture', 'usces') . "<br />";
4513 // if ( trim($_POST['member']["address1"]) == "" )
4514 // $mes .= __('enter the city name', 'usces') . "<br />";
4515 // if ( trim($_POST['member']["address2"]) == "" )
4516 // $mes .= __('enter house numbers', 'usces') . "<br />";
4517 // if ( trim($_POST['member']["tel"]) == "" )
4518 // $mes .= __('enter phone numbers', 'usces') . "<br />";
4519 if( !WCUtils::is_blank($_POST['member']["tel"]) && preg_match("/[^\d-]/", trim($_POST["member"]["tel"])) )
4520 $mes .= __('Please input a phone number with a half size number.', 'usces') . "<br />";
4521
4522 $mes = apply_filters('usces_filter_admin_member_check', $mes);
4523
4524 return $mes;
4525 }
4526
4527 function customer_check() {
4528 $mes = '';
4529 if ( !is_email($_POST['customer']['mailaddress1']) || WCUtils::is_blank($_POST['customer']['mailaddress1']) || WCUtils::is_blank($_POST['customer']['mailaddress2']) || trim($_POST['customer']['mailaddress1']) != trim($_POST['customer']['mailaddress2']) )
4530 $mes .= __('e-mail address is not correct', 'usces') . "<br />";
4531 if ( WCUtils::is_blank($_POST["customer"]["name1"]) )
4532 $mes .= __('Name is not correct', 'usces') . "<br />";//20111116ysk 0000299
4533 // if ( trim($_POST["customer"]["name3"]) == "" && USCES_JP )
4534 // $mes .= __('Invalid CANNAT pretend.', 'usces') . "<br />";
4535 if ( WCUtils::is_blank($_POST["customer"]["zipcode"]) )
4536 $mes .= __('postal code is not correct', 'usces') . "<br />";
4537 if ( $_POST["customer"]["pref"] == __('-- Select --', 'usces') )
4538 $mes .= __('enter the prefecture', 'usces') . "<br />";
4539 if ( WCUtils::is_blank($_POST["customer"]["address1"]) )
4540 $mes .= __('enter the city name', 'usces') . "<br />";
4541 if ( WCUtils::is_blank($_POST["customer"]["address2"]) )
4542 $mes .= __('enter house numbers', 'usces') . "<br />";
4543 if ( WCUtils::is_blank($_POST["customer"]["tel"]) )
4544 $mes .= __('enter phone numbers', 'usces') . "<br />";
4545 if( !WCUtils::is_blank($_POST['customer']["tel"]) && preg_match("/[^\d-]/", trim($_POST["customer"]["tel"])) )
4546 $mes .= __('Please input a phone number with a half size number.', 'usces') . "<br />";
4547
4548 $mes = apply_filters('usces_filter_customer_check', $mes);
4549
4550 return $mes;
4551 }
4552
4553 function delivery_check() {
4554 $mes = '';
4555 if ( isset($_POST['delivery']['delivery_flag']) && $_POST['delivery']['delivery_flag'] == 1 ) {
4556 if ( WCUtils::is_blank($_POST["delivery"]["name1"]) )
4557 $mes .= __('Name is not correct', 'usces') . "<br />";//20111116ysk 0000299
4558 // if ( trim($_POST["delivery"]["name3"]) == "" && USCES_JP )
4559 // $mes .= __('Invalid CANNAT pretend.', 'usces') . "<br />";
4560 if ( WCUtils::is_blank($_POST["delivery"]["zipcode"]) )
4561 $mes .= __('postal code is not correct', 'usces') . "<br />";
4562 if ( $_POST["delivery"]["pref"] == __('-- Select --', 'usces') )
4563 $mes .= __('enter the prefecture', 'usces') . "<br />";
4564 if ( WCUtils::is_blank($_POST["delivery"]["address1"]) )
4565 $mes .= __('enter the city name', 'usces') . "<br />";
4566 if ( WCUtils::is_blank($_POST["delivery"]["address2"]) )
4567 $mes .= __('enter house numbers', 'usces') . "<br />";
4568 if ( WCUtils::is_blank($_POST["delivery"]["tel"]) )
4569 $mes .= __('enter phone numbers', 'usces') . "<br />";
4570 }
4571 if ( !isset($_POST['offer']['delivery_method']) || (empty($_POST['offer']['delivery_method']) && !WCUtils::is_zero($_POST['offer']['delivery_method'])) )
4572 $mes .= __('chose one from delivery method.', 'usces') . "<br />";
4573 if ( !isset($_POST['offer']['payment_name']) ){
4574 $mes .= __('chose one from payment options.', 'usces') . "<br />";
4575 }else{
4576 $payments = $this->getPayments($_POST['offer']['payment_name']);
4577 if('COD' == $payments['settlement']){
4578 $total_items_price = $this->get_total_price();
4579 $tax = $this->getTax( $total_items_price );
4580 $total_items_price = $total_items_price + $tax;
4581 $cod_limit_amount = ( isset($this->options['cod_limit_amount']) && 0 < (int)$this->options['cod_limit_amount'] ) ? $this->options['cod_limit_amount'] : 0;
4582 if( 0 < $cod_limit_amount && $total_items_price > $cod_limit_amount )
4583 $mes .= sprintf(__('A total products amount of money surpasses the upper limit(%s) that I can purchase in C.O.D.', 'usces'), usces_crform($this->options['cod_limit_amount'], true, false, 'return')) . "<br />";
4584 }
4585
4586 }
4587 //20101119ysk start
4588 if(isset($_POST['offer']['delivery_method']) and isset($_POST['offer']['payment_name'])) {
4589 $d_method_index = $this->get_delivery_method_index((int)$_POST['offer']['delivery_method']);
4590 if($this->options['delivery_method'][$d_method_index]['nocod'] == 1) {
4591 $payments = $this->getPayments($_POST['offer']['payment_name']);
4592 if('COD' == $payments['settlement'])
4593 $mes .= __('COD is not available.', 'usces') . "<br />";
4594 }
4595 }
4596 //20101119ysk end
4597 //20110317ysk start
4598 if(isset($_POST['offer']['delivery_method'])) {
4599 $d_method_index = $this->get_delivery_method_index((int)$_POST['offer']['delivery_method']);
4600 $country = $_SESSION['usces_entry']["delivery"]["country"];
4601 $local_country = usces_get_base_country();
4602 if($country == $local_country) {
4603 if($this->options['delivery_method'][$d_method_index]['intl'] == 1) {
4604 $mes .= __('�
4605 �送方法が誤っています。国際便は指定できません。', 'usces') . "<br />";
4606 }
4607 } else {
4608 if( WCUtils::is_zero($this->options['delivery_method'][$d_method_index]['intl']) ) {
4609 $mes .= __('�
4610 �送方法が誤っています。国際便を指定してください。', 'usces') . "<br />";
4611 }
4612 }
4613 }
4614 //20110317ysk end
4615
4616 $mes = apply_filters('usces_filter_delivery_check', $mes);
4617
4618 return $mes;
4619 }
4620
4621 function point_check( $entries ) {
4622 $member = $this->get_member();
4623 $this->set_cart_fees( $member, $entries );
4624 $mes = '';
4625 if( isset($_POST['offer']["usedpoint"]) ) {
4626 if ( WCUtils::is_blank($_POST['offer']["usedpoint"]) || !preg_match("/^[0-9]+$/", $_POST['offer']["usedpoint"]) || (int)$_POST['offer']["usedpoint"] < 0 ) {
4627 $mes .= __('Invalid value. Please enter in the numbers.', 'usces') . "<br />";
4628 } else {
4629 /* if ( trim($_POST['offer']["usedpoint"]) > $member['point'] ){
4630 $mes .= __('You have exceeded the maximum available.', 'usces') . "max".$member['point']."pt<br />";
4631 $_POST['offer']["usedpoint"] = 0;
4632 $array = array(
4633 'usedpoint' => 0
4634 );
4635 $this->cart->set_order_entry( $array );
4636 }elseif($this->options['point_coverage'] && trim($_POST['offer']["usedpoint"]) > ($entries['order']['total_items_price'] + $entries['order']['discount'] + $entries['order']['shipping_charge'] + $entries['order']['cod_fee'])){
4637 $mes .= __('You have exceeded the maximum available.', 'usces') . "max".($entries['order']['total_items_price'] + $entries['order']['discount'] + $entries['order']['shipping_charge'] + $entries['order']['cod_fee'])."pt<br />";
4638 $_POST['offer']["usedpoint"] = 0;
4639 $array = array(
4640 'usedpoint' => 0
4641 );
4642 $this->cart->set_order_entry( $array );
4643 }elseif(!$this->options['point_coverage'] && trim($_POST['offer']["usedpoint"]) > ($entries['order']['total_items_price'] + $entries['order']['discount'])){
4644 $mes .= __('You have exceeded the maximum available.', 'usces') . "max".($entries['order']['total_items_price'] + $entries['order']['discount'])."pt<br />";
4645 $_POST['offer']["usedpoint"] = 0;
4646 $array = array(
4647 'usedpoint' => 0
4648 );
4649 $this->cart->set_order_entry( $array );
4650 }
4651 */ if( trim($_POST['offer']["usedpoint"]) > $member['point'] ) {
4652 $mes .= __('You have exceeded the maximum available.', 'usces')."max".$member['point']."pt<br />";
4653 } elseif( $this->options['point_coverage'] && trim($_POST['offer']["usedpoint"]) > ($entries['order']['total_items_price'] + $entries['order']['discount'] + $entries['order']['shipping_charge'] + $entries['order']['cod_fee']) ) {
4654 $mes .= __('You have exceeded the maximum available.', 'usces')."max".($entries['order']['total_items_price'] + $entries['order']['discount'] + $entries['order']['shipping_charge'] + $entries['order']['cod_fee'])."pt<br />";
4655 } elseif( !$this->options['point_coverage'] && trim($_POST['offer']["usedpoint"]) > ($entries['order']['total_items_price'] + $entries['order']['discount']) ) {
4656 $mes .= __('You have exceeded the maximum available.', 'usces')."max".($entries['order']['total_items_price'] + $entries['order']['discount'])."pt<br />";
4657 }
4658 $mes = apply_filters( 'usces_filter_point_check', $mes );
4659 if( '' != $mes ) {
4660 $_POST['offer']["usedpoint"] = 0;
4661 $array = array(
4662 'usedpoint' => 0
4663 );
4664 $this->cart->set_order_entry( $array );
4665 }
4666 }
4667 }
4668 return $mes;
4669 }
4670
4671 function lostpass_mailaddcheck() {
4672 $mes = '';
4673 if ( !is_email($_POST['loginmail']) || WCUtils::is_blank($_POST['loginmail']) ) {
4674 $mes .= __('e-mail address is not correct', 'usces') . "<br />";
4675 }elseif( !$this->is_member($_POST['loginmail']) ){
4676 $mes .= __('It is the e-mail address that there is not.', 'usces') . "<br />";
4677 }
4678
4679 return $mes;
4680 }
4681
4682 function changepass_check() {
4683 $mes = '';
4684 if ( WCUtils::is_blank($_POST['loginpass1']) || WCUtils::is_blank($_POST['loginpass2']) || (trim($_POST['loginpass1']) != trim($_POST['loginpass2'])))
4685 $mes .= __('Password is not correct.', 'usces') . "<br />";
4686
4687 return $mes;
4688 }
4689
4690 function get_page() {
4691 return $this->page;
4692 }
4693
4694 function check_display_mode() {
4695 $options = get_option('usces');
4696 if( isset($options['display_mode']) && $options['display_mode'] == 'Maintenancemode' ) return;
4697
4698 $start['hour'] = empty($options['campaign_schedule']['start']['hour']) ? 0 : $options['campaign_schedule']['start']['hour'];
4699 $start['min'] = empty($options['campaign_schedule']['start']['min']) ? 0 : $options['campaign_schedule']['start']['min'];
4700 $start['month'] = empty($options['campaign_schedule']['start']['month']) ? 0 : $options['campaign_schedule']['start']['month'];
4701 $start['day'] = empty($options['campaign_schedule']['start']['day']) ? 0 : $options['campaign_schedule']['start']['day'];
4702 $start['year'] = empty($options['campaign_schedule']['start']['year']) ? 0 : $options['campaign_schedule']['start']['year'];
4703 $end['hour'] = empty($options['campaign_schedule']['end']['hour']) ? 0 : $options['campaign_schedule']['end']['hour'];
4704 $end['min'] = empty($options['campaign_schedule']['end']['min']) ? 0 : $options['campaign_schedule']['end']['min'];
4705 $end['month'] = empty($options['campaign_schedule']['end']['month']) ? 0 : $options['campaign_schedule']['end']['month'];
4706 $end['day'] = empty($options['campaign_schedule']['end']['day']) ? 0 : $options['campaign_schedule']['end']['day'];
4707 $end['year'] = empty($options['campaign_schedule']['end']['year']) ? 0 : $options['campaign_schedule']['end']['year'];
4708 $starttime = mktime($start['hour'], $start['min'], 0, $start['month'], $start['day'], $start['year']);
4709 $endtime = mktime($end['hour'], $end['min'], 0, $end['month'], $end['day'], $end['year']);
4710 $current_time = current_time('timestamp');
4711
4712 if( ($current_time >= $starttime) && ($current_time <= $endtime) )
4713 $options['display_mode'] = 'Promotionsale';
4714 else
4715 $options['display_mode'] = 'Usualsale';
4716
4717 update_option('usces', $options);
4718
4719 }
4720
4721 function update_business_days() {
4722 $options = get_option('usces');
4723 $datetimestr = get_date_from_gmt(gmdate('Y-m-d H:i:s', time()));
4724 $dhour = (int)substr($datetimestr, 11, 2);
4725 $dminute = (int)substr($datetimestr, 14, 2);
4726 $dsecond = (int)substr($datetimestr, 17, 2);
4727 $dmonth = (int)substr($datetimestr, 5, 2);
4728 $dday = (int)substr($datetimestr, 8, 2);
4729 $dyear = (int)substr($datetimestr, 0, 4);
4730 $dtimestamp = mktime($dhour, $dminute, $dsecond, $dmonth, $dday, $dyear);
4731 $datenow = getdate($dtimestamp);
4732 //list($year, $mon, $mday) = getBeforeMonth($datenow['year'], $datenow['mon'], $datenow['mday'], 1);
4733 list($year, $mon, $mday) = getBeforeMonth($datenow['year'], $datenow['mon'], 1, 1);
4734
4735 if(isset($options['business_days'][$year][$mon][1]))
4736 unset($options['business_days'][$year][$mon]);
4737
4738 for($i=0; $i<3; $i++){
4739 //list($year, $mon, $mday) = getAfterMonth($datenow['year'], $datenow['mon'], $datenow['mday'], $i);
4740 list($year, $mon, $mday) = getAfterMonth($datenow['year'], $datenow['mon'], 1, $i);
4741 $last = getLastDay($year, $mon);
4742 for($j=1; $j<=$last; $j++){
4743 if(!isset($options['business_days'][$year][$mon][$j]))
4744 $options['business_days'][$year][$mon][$j] = 1;
4745 }
4746 }
4747
4748 update_option('usces', $options);
4749
4750 $_SESSION['usces_checked_business_days'] = '';
4751 }
4752
4753 function display_cart() {
4754 if($this->cart->num_row() > 0) {
4755 include (USCES_PLUGIN_DIR . '/includes/cart_table.php');
4756 } else {
4757 echo "<div class='no_cart'>" . __('There are no items in your cart.', 'usces') . "</div>\n";
4758 }
4759 }
4760
4761 function display_cart_confirm() {
4762 if($this->cart->num_row() > 0) {
4763 include (USCES_PLUGIN_DIR . '/includes/cart_confirm.php');
4764 } else {
4765 echo "<div class='no_cart'>" . __('There are no items in your cart.', 'usces') . "</div>\n";
4766 }
4767 }
4768
4769 function set_initial() {
4770
4771 usces_log('set_initial : OK', 'database_error.log');
4772 $rets07 = usces_upgrade_07();
4773 $rets11 = usces_upgrade_11();
4774 usces_log('rets11 : ' . print_r($rets11,true), 'database_error.log');
4775 $this->set_default_theme();
4776 $this->set_default_page();
4777 $this->set_default_categories();
4778 $this->create_table();
4779 $this->update_table();
4780 $this->update_options();//20120710ysk 0000472
4781 }
4782
4783 function create_table() {
4784 global $wpdb;
4785
4786 if ( ! empty($wpdb->charset) )
4787 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
4788 if ( ! empty($wpdb->collate) )
4789 $charset_collate .= " COLLATE $wpdb->collate";
4790
4791 $access_table = $wpdb->prefix . "usces_access";
4792 $member_table = $wpdb->prefix . "usces_member";
4793 $member_meta_table = $wpdb->prefix . "usces_member_meta";
4794 $order_table = $wpdb->prefix . "usces_order";
4795 $order_meta_table = $wpdb->prefix . "usces_order_meta";
4796
4797 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
4798
4799 if($wpdb->get_var("show tables like '$member_table'") != $member_table) {
4800
4801 $sql = "CREATE TABLE " . $access_table . " (
4802 ID BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
4803 acc_key VARCHAR( 50 ) NOT NULL ,
4804 acc_type VARCHAR( 50 ) NULL ,
4805 acc_value LONGTEXT NULL ,
4806 acc_date DATE NOT NULL DEFAULT '0000-00-00',
4807 acc_num1 INT( 11 ) NOT NULL DEFAULT 0,
4808 acc_num2 INT( 11 ) NOT NULL DEFAULT 0,
4809 acc_str1 VARCHAR( 200 ) NULL ,
4810 acc_str2 VARCHAR( 200 ) NULL ,
4811 KEY acc_key ( acc_key ),
4812 KEY acc_type ( acc_type ),
4813 KEY acc_date ( acc_date ),
4814 KEY acc_num1 ( acc_num1 ),
4815 KEY acc_num2 ( acc_num2 )
4816 ) ENGINE = MYISAM AUTO_INCREMENT=0 $charset_collate;";
4817
4818 dbDelta($sql);
4819 add_option("usces_db_access", USCES_DB_ACCESS);
4820 }
4821 if($wpdb->get_var("show tables like '$member_table'") != $member_table) {
4822
4823 $sql = "CREATE TABLE " . $member_table . " (
4824 ID BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
4825 mem_email VARCHAR( 100 ) NOT NULL ,
4826 mem_pass VARCHAR( 64 ) NOT NULL ,
4827 mem_status INT( 11 ) NOT NULL DEFAULT '0',
4828 mem_cookie VARCHAR( 13 ) NULL ,
4829 mem_point INT( 11 ) NOT NULL DEFAULT '0',
4830 mem_name1 VARCHAR( 100 ) NOT NULL ,
4831 mem_name2 VARCHAR( 100 ) NULL ,
4832 mem_name3 VARCHAR( 100 ) NULL ,
4833 mem_name4 VARCHAR( 100 ) NULL ,
4834 mem_zip VARCHAR( 50 ) NULL ,
4835 mem_pref VARCHAR( 100 ) NOT NULL ,
4836 mem_address1 VARCHAR( 100 ) NOT NULL ,
4837 mem_address2 VARCHAR( 100 ) NULL ,
4838 mem_address3 VARCHAR( 100 ) NULL ,
4839 mem_tel VARCHAR( 100 ) NOT NULL ,
4840 mem_fax VARCHAR( 100 ) NULL ,
4841 mem_delivery_flag TINYINT ( 1 ) NULL ,
4842 mem_delivery LONGTEXT,
4843 mem_registered DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
4844 mem_nicename VARCHAR( 50 ) NULL ,
4845 KEY mem_email ( mem_email ) ,
4846 KEY mem_pass ( mem_pass )
4847 ) ENGINE = MYISAM AUTO_INCREMENT=1000 $charset_collate;";
4848
4849 dbDelta($sql);
4850 add_option("usces_db_member", USCES_DB_MEMBER);
4851 }
4852 if($wpdb->get_var("show tables like '$member_meta_table'") != $member_meta_table) {
4853
4854 $sql = "CREATE TABLE " . $member_meta_table . " (
4855 mmeta_id bigint(20) NOT NULL auto_increment,
4856 member_id bigint(20) NOT NULL default '0',
4857 meta_key varchar(255) default NULL,
4858 meta_value longtext,
4859 PRIMARY KEY (mmeta_id),
4860 KEY order_id (member_id),
4861 KEY meta_key (meta_key)
4862 ) ENGINE = MYISAM $charset_collate;";
4863
4864 dbDelta($sql);
4865 add_option("usces_db_member_meta", USCES_DB_MEMBER_META);
4866 }
4867 if($wpdb->get_var("show tables like '$order_table'") != $order_table) {
4868
4869 $sql = "CREATE TABLE " . $order_table . " (
4870 ID BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
4871 mem_id BIGINT( 20 ) UNSIGNED NULL ,
4872 order_email VARCHAR( 100 ) NOT NULL ,
4873 order_name1 VARCHAR( 100 ) NOT NULL ,
4874 order_name2 VARCHAR( 100 ) NULL ,
4875 order_name3 VARCHAR( 100 ) NULL ,
4876 order_name4 VARCHAR( 100 ) NULL ,
4877 order_zip VARCHAR( 50 ) NULL ,
4878 order_pref VARCHAR( 100 ) NOT NULL ,
4879 order_address1 VARCHAR( 100 ) NOT NULL ,
4880 order_address2 VARCHAR( 100 ) NULL ,
4881 order_address3 VARCHAR( 100 ) NULL ,
4882 order_tel VARCHAR( 100 ) NOT NULL ,
4883 order_fax VARCHAR( 100 ) NULL ,
4884 order_delivery LONGTEXT,
4885 order_cart LONGTEXT,
4886 order_note TEXT,
4887 order_delivery_time VARCHAR( 100 ) NOT NULL ,
4888 order_payment_name VARCHAR( 100 ) NOT NULL ,
4889 order_condition TEXT,
4890 order_item_total_price DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
4891 order_getpoint INT( 10 ) NOT NULL DEFAULT '0',
4892 order_usedpoint INT( 10 ) NOT NULL DEFAULT '0',
4893 order_discount DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
4894 order_shipping_charge DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
4895 order_cod_fee DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
4896 order_tax DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
4897 order_date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
4898 order_modified VARCHAR( 20 ) NULL ,
4899 order_status VARCHAR( 255 ) NULL ,
4900 order_check VARCHAR( 255 ) NULL ,
4901 order_delidue_date VARCHAR( 30 ) NULL ,
4902 order_delivery_method INT( 10 ) NOT NULL DEFAULT -1,
4903 order_delivery_date VARCHAR( 100 ) NULL,
4904 KEY order_email ( order_email ) ,
4905 KEY order_name1 ( order_name1 ) ,
4906 KEY order_name2 ( order_name2 ) ,
4907 KEY order_pref ( order_pref ) ,
4908 KEY order_address1 ( order_address1 ) ,
4909 KEY order_tel ( order_tel ) ,
4910 KEY order_date ( order_date )
4911 ) ENGINE = MYISAM AUTO_INCREMENT=1000 $charset_collate;";
4912
4913 dbDelta($sql);
4914 add_option("usces_db_order", USCES_DB_ORDER);
4915 }
4916 if($wpdb->get_var("show tables like '$order_meta_table'") != $order_meta_table) {
4917
4918 $sql = "CREATE TABLE " . $order_meta_table . " (
4919 ometa_id bigint(20) NOT NULL auto_increment,
4920 order_id bigint(20) NOT NULL default '0',
4921 meta_key varchar(255) default NULL,
4922 meta_value longtext,
4923 PRIMARY KEY (ometa_id),
4924 KEY order_id (order_id),
4925 KEY meta_key (meta_key)
4926 ) ENGINE = MYISAM $charset_collate;";
4927
4928 dbDelta($sql);
4929 add_option("usces_db_order_meta", USCES_DB_ORDER_META);
4930 }
4931
4932 }
4933
4934 function update_table()
4935 {
4936 global $wpdb;
4937 $access_table = $wpdb->prefix . "usces_access";
4938 $member_table = $wpdb->prefix . "usces_member";
4939 $member_meta_table = $wpdb->prefix . "usces_member_meta";
4940 $order_table = $wpdb->prefix . "usces_order";
4941 $order_meta_table = $wpdb->prefix . "usces_order_meta";
4942
4943 $access_ver = get_option( "usces_db_access" );
4944 $member_ver = get_option( "usces_db_member" );
4945 $member_meta_ver = get_option( "usces_db_member_meta" );
4946 $order_ver = get_option( "usces_db_order" );
4947 $order_meta_ver = get_option( "usces_db_order_meta" );
4948
4949 if( $access_ver != USCES_DB_ACCESS ) {
4950 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
4951 $sql = "CREATE TABLE " . $access_table . " (
4952 ID BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
4953 acc_key VARCHAR( 50 ) NOT NULL ,
4954 acc_type VARCHAR( 50 ) NULL ,
4955 acc_value LONGTEXT NULL ,
4956 acc_date DATE NOT NULL DEFAULT '0000-00-00',
4957 acc_num1 INT( 11 ) NOT NULL DEFAULT 0,
4958 acc_num2 INT( 11 ) NOT NULL DEFAULT 0,
4959 acc_str1 VARCHAR( 200 ) NULL ,
4960 acc_str2 VARCHAR( 200 ) NULL ,
4961 KEY acc_key ( acc_key ),
4962 KEY acc_type ( acc_type ),
4963 KEY acc_date ( acc_date ),
4964 KEY acc_num1 ( acc_num1 ),
4965 KEY acc_num2 ( acc_num2 )
4966 ) ENGINE = MYISAM;";
4967
4968 dbDelta($sql);
4969 update_option( "usces_db_access", USCES_DB_ACCESS );
4970 }
4971 if( $member_ver != USCES_DB_MEMBER ) {
4972 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
4973 $sql = "CREATE TABLE " . $member_table . " (
4974 ID BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
4975 mem_email VARCHAR( 100 ) NOT NULL ,
4976 mem_pass VARCHAR( 64 ) NOT NULL ,
4977 mem_status INT( 11 ) NOT NULL DEFAULT '0',
4978 mem_cookie VARCHAR( 13 ) NULL ,
4979 mem_point INT( 11 ) NOT NULL DEFAULT '0',
4980 mem_name1 VARCHAR( 100 ) NOT NULL ,
4981 mem_name2 VARCHAR( 100 ) NULL ,
4982 mem_name3 VARCHAR( 100 ) NULL ,
4983 mem_name4 VARCHAR( 100 ) NULL ,
4984 mem_zip VARCHAR( 50 ) NULL ,
4985 mem_pref VARCHAR( 100 ) NOT NULL ,
4986 mem_address1 VARCHAR( 100 ) NOT NULL ,
4987 mem_address2 VARCHAR( 100 ) NULL ,
4988 mem_address3 VARCHAR( 100 ) NULL ,
4989 mem_tel VARCHAR( 100 ) NOT NULL ,
4990 mem_fax VARCHAR( 100 ) NULL ,
4991 mem_delivery_flag TINYINT ( 1 ) NULL ,
4992 mem_delivery LONGTEXT,
4993 mem_registered DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
4994 mem_nicename VARCHAR( 50 ) NULL ,
4995 KEY mem_email ( mem_email ) ,
4996 KEY mem_pass ( mem_pass )
4997 ) ENGINE = MYISAM;";
4998
4999 dbDelta($sql);
5000 update_option( "usces_db_member", USCES_DB_MEMBER );
5001 }
5002 if( $member_meta_ver != USCES_DB_MEMBER_META ) {
5003 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
5004 $sql = "CREATE TABLE " . $member_meta_table . " (
5005 mmeta_id bigint(20) NOT NULL auto_increment,
5006 member_id bigint(20) NOT NULL default '0',
5007 meta_key varchar(255) default NULL,
5008 meta_value longtext,
5009 PRIMARY KEY (mmeta_id),
5010 KEY order_id (member_id),
5011 KEY meta_key (meta_key)
5012 ) ENGINE = MYISAM;";
5013
5014 dbDelta($sql);
5015 update_option("usces_db_member_meta", USCES_DB_MEMBER_META);
5016 }
5017 if( $order_ver != USCES_DB_ORDER ) {
5018 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
5019 $sql = "CREATE TABLE " . $order_table . " (
5020 ID BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
5021 mem_id BIGINT( 20 ) UNSIGNED NULL ,
5022 order_email VARCHAR( 100 ) NOT NULL ,
5023 order_name1 VARCHAR( 100 ) NOT NULL ,
5024 order_name2 VARCHAR( 100 ) NULL ,
5025 order_name3 VARCHAR( 100 ) NULL ,
5026 order_name4 VARCHAR( 100 ) NULL ,
5027 order_zip VARCHAR( 50 ) NULL ,
5028 order_pref VARCHAR( 100 ) NOT NULL ,
5029 order_address1 VARCHAR( 100 ) NOT NULL ,
5030 order_address2 VARCHAR( 100 ) NULL ,
5031 order_address3 VARCHAR( 100 ) NULL ,
5032 order_tel VARCHAR( 100 ) NOT NULL ,
5033 order_fax VARCHAR( 100 ) NULL ,
5034 order_delivery LONGTEXT,
5035 order_cart LONGTEXT,
5036 order_note TEXT,
5037 order_delivery_time VARCHAR( 100 ) NOT NULL ,
5038 order_payment_name VARCHAR( 100 ) NOT NULL ,
5039 order_condition TEXT,
5040 order_item_total_price DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
5041 order_getpoint INT( 10 ) NOT NULL DEFAULT '0',
5042 order_usedpoint INT( 10 ) NOT NULL DEFAULT '0',
5043 order_discount DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
5044 order_shipping_charge DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
5045 order_cod_fee DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
5046 order_tax DECIMAL( 10, 2 ) NOT NULL DEFAULT '0.00',
5047 order_date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
5048 order_modified VARCHAR( 20 ) NULL ,
5049 order_status VARCHAR( 255 ) NULL ,
5050 order_check VARCHAR( 255 ) NULL ,
5051 order_delidue_date VARCHAR( 30 ) NULL ,
5052 order_delivery_method INT( 10 ) NOT NULL DEFAULT -1,
5053 order_delivery_date VARCHAR( 100 ) NULL,
5054 KEY order_email ( order_email ) ,
5055 KEY order_name1 ( order_name1 ) ,
5056 KEY order_name2 ( order_name2 ) ,
5057 KEY order_pref ( order_pref ) ,
5058 KEY order_address1 ( order_address1 ) ,
5059 KEY order_tel ( order_tel ) ,
5060 KEY order_date ( order_date )
5061 ) ENGINE = MYISAM;";
5062
5063 dbDelta($sql);
5064 update_option("usces_db_order", USCES_DB_ORDER);
5065 }
5066 if( $order_meta_ver != USCES_DB_ORDER_META ) {
5067 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
5068 $sql = "CREATE TABLE " . $order_meta_table . " (
5069 ometa_id bigint(20) NOT NULL auto_increment,
5070 order_id bigint(20) NOT NULL default '0',
5071 meta_key varchar(255) default NULL,
5072 meta_value longtext,
5073 PRIMARY KEY (ometa_id),
5074 KEY order_id (order_id),
5075 KEY meta_key (meta_key)
5076 ) ENGINE = MYISAM;";
5077
5078 dbDelta($sql);
5079 update_option("usces_db_order_meta", USCES_DB_ORDER_META);
5080 }
5081 }
5082
5083 function set_default_theme()
5084 {
5085 $themepath = USCES_WP_CONTENT_DIR.'/themes/welcart_default';
5086 $resourcepath = USCES_WP_CONTENT_DIR.'/plugins/usc-e-shop/theme/welcart_default';
5087 if( file_exists($themepath) ) return false;
5088 if(!file_exists($resourcepath) ) return false;
5089
5090 mkdir($themepath, 0775);
5091 $this->dir_copy($resourcepath, $themepath);
5092
5093 }
5094
5095 function dir_copy($source, $dest){
5096 if ($res = opendir($source)) {
5097 while (($file = readdir($res)) !== false) {
5098 $sorce_path = $source . '/' . $file;
5099 $dest_path = $dest . '/' . $file;
5100 $filetype = @filetype($sorce_path);
5101 if( $filetype == 'file' ) {
5102 copy($sorce_path, $dest_path);
5103 }elseif( $filetype == 'dir' && $file != '..' && $file != '.' ){
5104 mkdir($dest_path);
5105 $this->dir_copy($sorce_path, $dest_path);
5106 }
5107 }
5108 closedir($res);
5109 }
5110 }
5111
5112 function set_default_page()
5113 {
5114 global $wpdb;
5115 $datetime = get_date_from_gmt(gmdate('Y-m-d H:i:s', time()));
5116 $datetime_gmt = gmdate('Y-m-d H:i:s', time());
5117
5118 //cart_page
5119 $query = $wpdb->prepare("SELECT ID from $wpdb->posts where post_name = %s", USCES_CART_FOLDER);
5120 $cart_number = $wpdb->get_var( $query );
5121 if( $cart_number === NULL ) {
5122 $query = $wpdb->prepare("INSERT INTO $wpdb->posts
5123 (post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status,
5124 comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt,
5125 post_content_filtered, post_parent, guid, menu_order, post_type, post_mime_type, comment_count)
5126 VALUES (%d, %s, %s, %s, %s, %s, %s,
5127 %s, %s, %s, %s, %s, %s, %s, %s,
5128 %s, %d, %s, %d, %s, %s, %d)",
5129 1, $datetime, $datetime_gmt, '', __('Cart', 'usces'), '', 'publish',
5130 'closed', 'closed', '', USCES_CART_FOLDER, '', '', $datetime, $datetime_gmt,
5131 '', 0, '', 0, 'page', '', 0);
5132 $wpdb->query($query);
5133 $cart_number = $wpdb->insert_id;
5134 if( $cart_number !== NULL ) {
5135 $query = $wpdb->prepare("INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) VALUES (%d, %s, %s)",
5136 $cart_number, '_wp_page_template', 'uscescart.php');
5137 $wpdb->query($query);
5138 }
5139 }
5140 update_option('usces_cart_number', $cart_number);
5141
5142 //member_page
5143 $query = $wpdb->prepare("SELECT ID from $wpdb->posts where post_name = %s", USCES_MEMBER_FOLDER);
5144 $member_number = $wpdb->get_var( $query );
5145 if( $member_number === NULL ) {
5146 $query = $wpdb->prepare("INSERT INTO $wpdb->posts
5147 (post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status,
5148 comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt,
5149 post_content_filtered, post_parent, guid, menu_order, post_type, post_mime_type, comment_count)
5150 VALUES (%d, %s, %s, %s, %s, %s, %s,
5151 %s, %s, %s, %s, %s, %s, %s, %s,
5152 %s, %d, %s, %d, %s, %s, %d)",
5153 1, $datetime, $datetime_gmt, '', __('Membership', 'usces'), '', 'publish',
5154 'closed', 'closed', '', USCES_MEMBER_FOLDER, '', '', $datetime, $datetime_gmt,
5155 '', 0, '', 0, 'page', '', 0);
5156 $wpdb->query($query);
5157 $member_number = $wpdb->insert_id;
5158 if( $member_number !== NULL ) {
5159 $query = $wpdb->prepare("INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) VALUES (%d, %s, %s)",
5160 $member_number, '_wp_page_template', 'uscesmember.php');
5161 $wpdb->query($query);
5162 }
5163 }
5164 update_option('usces_member_number', $member_number);
5165
5166 }
5167
5168 function set_default_categories()
5169 {
5170 global $wpdb;
5171
5172 $idObj = get_category_by_slug('item');
5173 if( empty($idObj) ) {
5174 $item_cat = array('cat_name' => __('Items', 'usces'), 'category_description' => '', 'category_nicename' => 'item', 'category_parent' => 0);
5175 $item_cat_id = wp_insert_category($item_cat);
5176 update_option('usces_item_cat_parent_id', $item_cat_id);
5177 }
5178
5179 $idObj = get_category_by_slug('itemreco');
5180 if( empty($idObj) && isset($item_cat_id) ) {
5181 $itemreco_cat = array('cat_name' => __('Items recommended', 'usces'), 'category_description' => '', 'category_nicename' => 'itemreco', 'category_parent' => $item_cat_id);
5182 $itemreco_cat_id = wp_insert_category($itemreco_cat);
5183 }
5184
5185 $idObj = get_category_by_slug('itemnew');
5186 if( empty($idObj) && isset($item_cat_id) ) {
5187 $itemnew_cat = array('cat_name' => __('New items', 'usces'), 'category_description' => '', 'category_nicename' => 'itemnew', 'category_parent' => $item_cat_id);
5188 $itemnew_cat_id = wp_insert_category($itemnew_cat);
5189 }
5190
5191 $idObj = get_category_by_slug('itemgenre');
5192 if( empty($idObj) && isset($item_cat_id) ) {
5193 $itemgenre_cat = array('cat_name' => __('Item genre', 'usces'), 'category_description' => '', 'category_nicename' => 'itemgenre', 'category_parent' => $item_cat_id);
5194 $itemgenre_cat_id = wp_insert_category($itemgenre_cat);
5195 }
5196 }
5197 //20120710ysk start 0000472
5198 function update_options() {
5199 $target_market = $this->options['system']['target_market'];
5200
5201 $update_shipping_charge = false;
5202 $shipping_charge = isset($this->options['shipping_charge']) ? $this->options['shipping_charge'] : array();
5203 foreach( (array)$target_market as $tm ) {
5204 for( $i = 0; $i < count($shipping_charge); $i++ ) {
5205 if( isset($shipping_charge[$i]['country']) and $shipping_charge[$i]['country'] == $tm ) {
5206 foreach( $shipping_charge[$i]['value'] as $pref => $value ) {
5207 $shipping_charge[$i][$tm][$pref] = $value;
5208 }
5209 unset($shipping_charge[$i]['country']);
5210 unset($shipping_charge[$i]['value']);
5211 $update_shipping_charge = true;
5212 }
5213 }
5214 }
5215 if( $update_shipping_charge ) $this->options['shipping_charge'] = $shipping_charge;
5216
5217 $update_delivery_days = false;
5218 $delivery_days = isset($this->options['delivery_days']) ? $this->options['delivery_days'] : array();
5219 foreach( (array)$target_market as $tm ) {
5220 for( $i = 0; $i < count($delivery_days); $i++ ) {
5221 if( isset($delivery_days[$i]['country']) and $delivery_days[$i]['country'] == $tm ) {
5222 foreach( $delivery_days[$i]['value'] as $pref => $value ) {
5223 $delivery_days[$i][$tm][$pref] = $value;
5224 }
5225 unset($delivery_days[$i]['country']);
5226 unset($delivery_days[$i]['value']);
5227 $update_delivery_days = true;
5228 }
5229 }
5230 }
5231 if( $update_delivery_days ) $this->options['delivery_days'] = $delivery_days;
5232
5233 if( $update_shipping_charge or $update_delivery_days )
5234 update_option('usces', $this->options);
5235 }
5236 //20120710ysk end
5237 function get_item_cat_ids(){
5238 $args = array('child_of' => USCES_ITEM_CAT_PARENT_ID, 'hide_empty' => 0, 'hierarchical' => 0);
5239 $categories = get_categories( $args );
5240 foreach($categories as $category){
5241 $ids[] = $category->term_id;
5242 }
5243 return $ids;
5244 }
5245
5246 function get_item_post_ids(){
5247 global $wpdb;
5248 $query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_mime_type = %s", 'item');
5249 $ids = $wpdb->get_col( $query );
5250
5251 return $ids;
5252 }
5253
5254 function get_item_cat_genre_ids( $post_id ){
5255 $ids = array();
5256 $all_ids = array();
5257 $genre = get_category_by_slug( 'itemgenre' );
5258 $genre_id = $genre->term_id;
5259 $args = array('child_of' => $genre_id, 'hide_empty' => 0, 'hierarchical' => 0);
5260 $categories = get_categories( $args );
5261 foreach($categories as $category){
5262 $ids[] = $category->term_id;
5263 }
5264 $allcats = get_the_category( $post_id );
5265 foreach($allcats as $cat){
5266 $all_ids[] = $cat->term_id;
5267 }
5268 //$all_ids =
5269 $results = array_intersect($ids, $all_ids);
5270
5271 return $results;
5272 }
5273
5274 function set_item_mime($post_id, $str)
5275 {
5276 global $wpdb;
5277 if( WCUtils::is_blank($str) ) return;
5278
5279 $query = $wpdb->prepare("UPDATE $wpdb->posts SET post_mime_type = %s WHERE ID = %s", $str, $post_id);
5280 $results = $wpdb->query( $query );
5281 return $results;
5282 }
5283
5284 function isAdnminSSL()
5285 {
5286 $plugins = get_option('active_plugins');
5287 foreach($plugins as $plugin) {
5288 if( false !== strpos($plugin, USCES_ADMIN_SSL_BASE_NAME) )
5289 return true;
5290 }
5291 return false;
5292 }
5293
5294 function getGuidTax() {
5295 $tax_rate = (int)$this->options['tax_rate'];
5296 if ( 0 < $tax_rate )
5297 $str = '<em class="tax">'.__('(Excl. Tax)', 'usces').'</em>';
5298 else
5299 $str = '<em class="tax">'.__('(Incl. Tax)', 'usces').'</em>';
5300
5301 return apply_filters('usces_filter_tax_guid', $str, $tax_rate);
5302 }
5303
5304 function getItemCode($post_id) {
5305 $str = get_post_meta($post_id, '_itemCode', true);
5306 return $str;
5307 }
5308
5309 function getItemName($post_id) {
5310 $str = get_post_meta($post_id, '_itemName', true);
5311 return $str;
5312 }
5313
5314 function getItemRestriction($post_id) {
5315 $str = get_post_meta($post_id, '_itemRestriction', true);
5316 return $str;
5317 }
5318
5319 function getItemPointrate($post_id) {
5320 $str = get_post_meta($post_id, '_itemPointrate', true);
5321 return $str;
5322 }
5323
5324 function getItemShipping($post_id) {
5325 $str = get_post_meta($post_id, '_itemShipping', true);
5326 return $str;
5327 }
5328
5329 function getItemShippingCharge($post_id) {
5330 $str = get_post_meta($post_id, '_itemShippingCharge', true);
5331 return (float)$str;
5332 }
5333
5334 function getItemDeliveryMethod($post_id) {
5335 $str = get_post_meta($post_id, '_itemDeliveryMethod', true);
5336 if( empty($str) )
5337 return array();
5338 else
5339 return $str;
5340 }
5341
5342 function getItemIndividualSCharge($post_id) {
5343 $str = get_post_meta($post_id, '_itemIndividualSCharge', true);
5344 return $str;
5345 }
5346
5347 function getItemGpNum1($post_id) {
5348 $str = get_post_meta($post_id, '_itemGpNum1', true);
5349 return $str;
5350 }
5351
5352 function getItemGpNum2($post_id) {
5353 $str = get_post_meta($post_id, '_itemGpNum2', true);
5354 return $str;
5355 }
5356
5357 function getItemGpNum3($post_id) {
5358 $str = get_post_meta($post_id, '_itemGpNum3', true);
5359 return $str;
5360 }
5361
5362 function getItemGpDis1($post_id) {
5363 $str = get_post_meta($post_id, '_itemGpDis1', true);
5364 return $str;
5365 }
5366
5367 function getItemGpDis2($post_id) {
5368 $str = get_post_meta($post_id, '_itemGpDis2', true);
5369 return $str;
5370 }
5371
5372 function getItemGpDis3($post_id) {
5373 $str = get_post_meta($post_id, '_itemGpDis3', true);
5374 return $str;
5375 }
5376
5377 function getItemSku($post_id, $index = '') {
5378 $array = array();
5379 $skus = $this->get_skus($post_id, 'sort');
5380 foreach((array)$skus as $sku){
5381 $array[] = $sku['code'];
5382 }
5383 if(!$array) return false;
5384 if($index == ''){
5385 return $array;
5386 }else if(isset($array[$index])){
5387 return $array[$index];
5388 }else{
5389 return false;
5390 }
5391 }
5392
5393 function getItemPrice($post_id, $skukey = '') {
5394 $array = array();
5395 $skus = $this->get_skus($post_id, 'code');
5396 foreach((array)$skus as $key => $sku){
5397 $array[$key] = (float)str_replace('.', '', $sku['price']);
5398 }
5399 if(!$array) return false;
5400 if($skukey == ''){
5401 return $array;
5402 }else if(isset($array[$skukey])){
5403 return $array[$skukey];
5404 }else{
5405 return false;
5406 }
5407 }
5408
5409 function getItemDiscount($post_id, $skukey = '') {
5410 $display_mode = $this->options['display_mode'];
5411 $array = array();
5412 $skus = $this->get_skus($post_id, 'code');
5413 foreach((array)$skus as $key => $sku){
5414 $price = (float)str_replace(',', '', $sku['price']);
5415 if ( $display_mode == 'Promotionsale' ) {
5416 if ( $this->options['campaign_privilege'] == 'discount' ){
5417 if( 0 === (int)$this->options['campaign_category'] || in_category((int)$this->options['campaign_category'], $post_id) ){
5418 $discount = $price * $this->options['privilege_discount'] / 100;
5419 }else{
5420 $discount = 0;
5421 }
5422 }else if ( $this->options['campaign_privilege'] == 'point' ){
5423 $discount = 0;
5424 }
5425 }
5426
5427 $discount = ceil($discount);
5428 $array[$key] = $discount;
5429 }
5430 if(!$array) return false;
5431 if($skukey == ''){
5432 return $array;
5433 }else if(isset($array[$skukey])){
5434 return $array[$skukey];
5435 }else{
5436 return false;
5437 }
5438 }
5439
5440 function getItemZaiko($post_id, $skukey = '') {
5441 $array = array();
5442 $skus = $this->get_skus($post_id, 'code');
5443 foreach((array)$skus as $key => $sku){
5444 $num = $sku['stock'];
5445 $array[$key] = $this->zaiko_status[$num];
5446 }
5447 if(!$array) return false;
5448 if($skukey == ''){
5449 return $array;
5450 }else if(isset($array[$skukey])){
5451 return $array[$skukey];
5452 }else{
5453 return false;
5454 }
5455 }
5456
5457 function getItemZaikoStatusId($post_id, $skukey = '') {
5458 $array = array();
5459 $skus = $this->get_skus($post_id, 'code');
5460 foreach((array)$skus as $key => $sku){
5461 $num = $sku['stock'];
5462 $array[$key] = $num;
5463 }
5464 if(!$array) return false;
5465 if($skukey == ''){
5466 return $array;
5467 }else if(isset($array[$skukey])){
5468 return $array[$skukey];
5469 }else{
5470 return false;
5471 }
5472 }
5473
5474 function updateItemZaiko($post_id, $skucode, $value) {
5475 $res = usces_update_sku( $post_id, $skucode, 'stock', $value );
5476 if( !$res ){
5477 return false;
5478 }else{
5479 return true;
5480 }
5481 }
5482
5483 function getItemZaikoNum($post_id, $skukey = '') {
5484 $array = array();
5485 $skus = $this->get_skus($post_id, 'code');
5486 foreach((array)$skus as $key => $sku){
5487 $array[$key] = $sku['stocknum'];
5488 }
5489 if(!$array) return false;
5490 if($skukey == ''){
5491 return $array;
5492 }else if(isset($array[$skukey])){
5493 return $array[$skukey];
5494 }else{
5495 return false;
5496 }
5497 }
5498
5499 function updateItemZaikoNum($post_id, $skucode, $value) {
5500 $res = usces_update_sku( $post_id, $skucode, 'stocknum', $value );
5501 if( !$res ){
5502 return false;
5503 }else{
5504 return true;
5505 }
5506 }
5507 //20120629ysk start 0000520
5508 function getItemDivision( $post_id ){
5509 if( usces_is_item($post_id) ){
5510 $item_division = get_post_meta($post_id, '_item_division', true);
5511 $division = empty($item_division) ? 'shipped' : $item_division;
5512 }else{
5513 $division = NULL;
5514 }
5515 return $division;
5516 }
5517 //20120629ysk end
5518 function getItemChargingType( $post_id, $cart = array() ){
5519 if( usces_is_item($post_id) ){
5520 $charging = get_post_meta($post_id, '_item_charging_type', true);
5521 //if( !defined('WCEX_DLSELLER') )
5522 if( !defined('WCEX_DLSELLER') and !defined('WCEX_AUTO_DELIVERY') )
5523 $charging = NULL;
5524 }else{
5525 $charging = NULL;
5526 }
5527 switch( $charging ){
5528 case 0:
5529 $type = 'once';
5530 break;
5531 case 1:
5532 $type = 'continue';
5533 break;
5534 case 2:
5535 $type = 'regular';
5536 if( !empty($cart) ) {
5537 if( empty($cart['advance']) ) {
5538 $type = 'once';
5539 } else {
5540 $advance = $this->cart->wc_unserialize( $cart['advance'] );
5541 $sku = urldecode( $cart['sku'] );
5542 $regular = $advance[$post_id][$sku]['regular'];
5543 $unit = isset( $regular['unit'] ) ? $regular['unit'] : '';
5544 $interval = isset( $regular['interval'] ) ? (int)$regular['interval'] : 0;
5545 if( empty($unit) or 1 > $interval ) //通常課金扱い
5546 $type = 'once';
5547 }
5548 }
5549 break;
5550 default:
5551 $type = NULL;
5552 }
5553 return $type;
5554 }
5555
5556 function getItemFrequency( $post_id ){
5557 $frequency = get_post_meta($post_id, '_item_frequency',true );
5558 return $frequency;
5559 }
5560
5561 function getItemChargingDay( $post_id ){
5562 $array = get_post_meta($post_id, '_item_chargingday',true );
5563 $day = (int)$array;
5564 $chargingday = empty($day) ? 1 : $day;
5565 return $chargingday;
5566 }
5567
5568 function getItemSkuDisp($post_id, $skukey = '') {
5569 $array = array();
5570 $skus = $this->get_skus($post_id, 'code');
5571 foreach((array)$skus as $key => $sku){
5572 $array[$key] = $sku['name'];
5573 }
5574 if(!$array) return false;
5575 if($skukey == ''){
5576 return $array;
5577 }else if(isset($array[$skukey])){
5578 return $array[$skukey];
5579 }else{
5580 return false;
5581 }
5582 }
5583
5584 // function getItemSkuChargingType($post_id, $skukey = '') {
5585 // $fields = get_post_custom($post_id);
5586 // $skus = array();
5587 // foreach((array)$fields as $key => $value){
5588 // if( preg_match('/^_isku_/', $key, $match) ){
5589 // $key = substr($key, 6);
5590 // $values = maybe_unserialize($value[0]);
5591 // if( isset($values['charging_type']) && "undefined" != $values['charging_type'] && !empty($values['charging_type']) ){
5592 // $skus[$key] = $values['charging_type'];
5593 // }else{
5594 // continue;
5595 // }
5596 // }
5597 // }
5598 // if( empty($skus) ) return false;
5599 // if($skukey == ''){
5600 // return $skus;
5601 // }elseif( isset($skus[$skukey]) ){
5602 // return $skus[$skukey];
5603 // }else{
5604 // return false;
5605 // }
5606 // }
5607
5608 function getItemSkuUnit($post_id, $skukey = '') {
5609 $array = array();
5610 $skus = $this->get_skus($post_id, 'code');
5611 foreach((array)$skus as $key => $sku){
5612 $array[$key] = $sku['unit'];
5613 }
5614 if(!$array) return false;
5615 if($skukey == ''){
5616 return $array;
5617 }else if(isset($array[$skukey])){
5618 return $array[$skukey];
5619 }else{
5620 return false;
5621 }
5622 }
5623
5624 function get_item( $post_id ) {
5625 $usces_item['post_id'] = $post_id;
5626 $usces_item['itemCode'] = $this->getItemCode($post_id);
5627 $usces_item['itemName'] = $this->getItemName($post_id);
5628
5629 $skus = $this->get_skus($post_id, 'code');
5630 foreach((array)$skus as $key => $sku){
5631 $usces_item['skuCodes'][] = $key;
5632 $usces_item['skuValues'][] = $sku;
5633 }
5634
5635 $usces_item = apply_filters('usces_filter_get_item', $usces_item, $post_id);
5636
5637 return $usces_item;
5638 }
5639
5640 function get_itemOptionKey( $post_id, $enc = false ) {
5641 $opts = usces_get_opts( $post_id );
5642 if(empty($opts)) return;
5643
5644 $res = array();
5645 foreach ( (array)$opts as $opt ) {
5646 if( $enc )
5647 $res[] = urlencode($opt['name']);
5648 else
5649 $res[] = $opt['name'];
5650 }
5651 return $res;
5652 }
5653
5654 function get_itemOptions( $key, $post_id ) {
5655 $opts = usces_get_opts( $post_id, 'name' );
5656 if(empty($opts[$key]))
5657 return;
5658 else
5659 return $opts[$key];
5660 }
5661
5662 function get_postIDbyCode( $itemcode ) {
5663 global $wpdb;
5664
5665 $query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_itemCode', $itemcode);
5666 $res = $wpdb->get_var( $query );
5667 return $res;
5668 }
5669
5670 function get_pictids($item_code) {
5671 global $wpdb, $usces;
5672
5673 if( empty($item_code) )
5674 return false;
5675
5676 if( !$usces->options['system']['subimage_rule'] ){
5677 $codestr = $item_code.'%';
5678 $query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title LIKE %s AND post_title <> %s AND post_type = 'attachment' ORDER BY post_title", $codestr, $item_code);
5679 }else{
5680 $codestr = $item_code.'--%';
5681 $query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title LIKE %s AND post_type = 'attachment' ORDER BY post_title", $codestr);
5682 }
5683 $results = $wpdb->get_col( $query );
5684 return $results;
5685 }
5686
5687 function get_mainpictid($item_code) {
5688 global $wpdb;
5689 $query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type = 'attachment' LIMIT 1", $item_code);
5690 $id = $wpdb->get_var( $query );
5691 $id = apply_filters( 'usces_filter_get_mainpictid', $id, $item_code );
5692 return $id;
5693 }
5694
5695 function get_skus( $post_id, $keyflag = 'sort' ) {
5696 if( !$post_id )
5697 return array();
5698
5699 $skus = array();
5700 $metas = usces_get_post_meta($post_id, '_isku_');
5701 if( empty($metas) ) return $skus;
5702
5703 foreach( $metas as $rows ){
5704 $values = unserialize($rows['meta_value']);
5705 $key = isset($values[$keyflag]) ? $values[$keyflag] : $values['sort'];
5706 $skus[$key] = array(
5707 'meta_id' => $rows['meta_id'],
5708 'code' => $values['code'],
5709 'name' => $values['name'],
5710 'cprice' => $values['cprice'],
5711 'price' => $values['price'],
5712 'unit' => $values['unit'],
5713 'stocknum' => $values['stocknum'],
5714 'stock' => $values['stock'],
5715 'gp' => $values['gp'],
5716 'sort' => $values['sort'],
5717 'advance' => isset($values['advance']) ? $values['advance'] : ''
5718 );
5719 }
5720 $skus = apply_filters( 'usces_filter_get_skus', $skus, $post_id, $keyflag );
5721 ksort($skus);
5722
5723 return $skus;
5724 }
5725
5726 function is_item( $post ) {
5727
5728 if( $post->post_mime_type == 'item' )
5729 return true;
5730 else
5731 return false;
5732 }
5733
5734 function getItemIds( $end_type ) {
5735 global $wpdb;
5736 if( 'front' == $end_type )
5737 $query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_status = %s AND post_mime_type = %s", 'publish', 'item');
5738 if( 'back' == $end_type )
5739 $query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_mime_type = %s", 'item');
5740 $ids = $wpdb->get_col( $query );
5741 if( empty($ids) ) $ids = array();
5742 return $ids;
5743 }
5744
5745 function getNotItemIds() {
5746 global $wpdb;
5747 $query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_status = %s AND post_mime_type <> %s", 'publish', 'item');
5748 $ids = $wpdb->get_col( $query );
5749 if( empty($ids) ) $ids = array();
5750 return $ids;
5751 }
5752
5753 function getPaymentMethod( $name ) {
5754 $res = array();
5755 $payments = $this->options['payment_method'];
5756 foreach ( (array)$payments as $payment ) {
5757 if($name = $payment['name']) {
5758 $res = $payment;
5759 break;
5760 }
5761 }
5762 return $res;
5763 }
5764
5765 function order_processing( $results = array() ) {
5766 do_action('usces_pre_reg_orderdata');
5767 //db(function.php)
5768 //20110203ysk start
5769 $res = usces_check_acting_return_duplicate( $results );
5770 if($res != NULL) {
5771 usces_log('order processing duplicate : acting='.$_REQUEST['acting'].', order_id='.$res, 'acting_transaction.log');
5772 return 'ordercompletion';
5773 }
5774 if(isset($_REQUEST['acting']) && ('jpayment_card' == $_REQUEST['acting'] || 'jpayment_conv' == $_REQUEST['acting'] || 'jpayment_bank' == $_REQUEST['acting'])) {
5775 usces_log($_REQUEST['acting'].' transaction : '.$_REQUEST['gid'], 'acting_transaction.log');//OK
5776 }
5777 //20110203ysk end
5778 //20110621ysk start 0000184
5779 if(isset($_REQUEST['acting']) && ('paypal_ec' == $_REQUEST['acting'])) {
5780 if( !usces_paypal_doecp( $results ) )
5781 return 'error';
5782 }
5783 //20110621ysk end
5784 $order_id = usces_reg_orderdata( $results );
5785 do_action('usces_post_reg_orderdata', $order_id, $results);
5786
5787 if ( $order_id ) {
5788 //mail(function.php)
5789 $mail_res = usces_send_ordermail( $order_id );
5790 return 'ordercompletion';
5791
5792 } else {
5793 return 'error';
5794 }
5795
5796 }
5797
5798 function acting_processing($acting_flg, $query) {
5799 global $wpdb;
5800 $entry = $this->cart->get_entry();
5801 $delim = apply_filters( 'usces_filter_delim', $this->delim );
5802 $acting_flg = trim($acting_flg);
5803 //$usces_entries = $this->cart->get_entry();
5804
5805 if( empty($acting_flg) ) return 'error';
5806
5807
5808 //include(USCES_PLUGIN_DIR . '/settlement/' . $acting_flg);
5809 if($acting_flg == 'paypal.php'){
5810 // if( !file_exists($this->options['settlement_path'] . $acting_flg) )
5811 // return 'error';
5812 //
5813 // require_once($this->options['settlement_path'] . "paypal.php");
5814 // paypal_submit();
5815
5816 }else if($acting_flg == 'epsilon.php'){
5817 if( !file_exists($this->options['settlement_path'] . $acting_flg) )
5818 return 'error';
5819
5820 if ( $this->use_ssl ) {
5821 $redirect = str_replace('http://', 'https://', USCES_CART_URL);
5822 }else{
5823 $redirect = USCES_CART_URL;
5824 }
5825 usces_log('epsilon card entry data (acting_processing) : '.print_r($entry, true), 'acting_transaction.log');
5826 $query .= '&settlement=epsilon&redirect_url=' . urlencode($redirect);
5827 $query = $delim . ltrim($query, '&');
5828 header("location: " . $redirect . $query);
5829 exit;
5830
5831 }else if($acting_flg == 'acting_zeus_card' && 2 == $this->options['acting_settings']['zeus']['connection'] ){
5832 if( 1 == $this->options['acting_settings']['zeus']['3dsecur'] ){
5833 if( !isset($_REQUEST['PaRes'])){
5834
5835 usces_log('zeus card entry data2 (acting_processing) : '.print_r($entry, true), 'acting_transaction.log');
5836 usces_zeus_3dsecure_enrol();
5837
5838 }else if( 1 == $this->options['acting_settings']['zeus']['3dsecur'] && isset($_REQUEST['PaRes'])){
5839
5840 usces_zeus_3dsecure_auth();
5841 }
5842 }else{
5843 $res = usces_zeus_secure_payreq();
5844 return $res;
5845 }
5846 }else if($acting_flg == 'acting_zeus_card' && 1 == $this->options['acting_settings']['zeus']['connection'] ){
5847
5848 $acting_opts = $this->options['acting_settings']['zeus'];
5849 $interface = parse_url($acting_opts['card_url']);
5850
5851 //usces_log('zeus card ***** : '.print_r($entry, true), 'acting_transaction.log');
5852
5853 $vars = 'send=mall';
5854 $vars .= '&clientip=' . $acting_opts['clientip'];
5855 $vars .= '&cardnumber=' . $_POST['cardnumber'];
5856 if( 1 == $this->options['acting_settings']['zeus']['security'] ){
5857 $vars .= '&seccode=' . $_POST['securecode'];
5858 }
5859 $vars .= '&expyy=' . substr($_POST['expyy'], 2);
5860 $vars .= '&expmm=' . $_POST['expmm'];
5861 $vars .= '&telno=' . str_replace('-', '', $_POST['telno']);
5862 $vars .= '&email=' . $_POST['email'];
5863 $vars .= '&sendid=' . $_POST['sendid'];
5864 $vars .= '&username=' . $_POST['username'];
5865 $vars .= '&money=' . $_POST['money'];
5866 $vars .= '&sendpoint=' . $_POST['sendpoint'];
5867 $vars .= '&printord=' . $_POST['printord'];
5868 if( isset($_POST['howpay']) && WCUtils::is_zero($_POST['howpay']) ){
5869 $vars .= '&div=' . $_POST['div'];
5870 }
5871
5872 //usces_log('zeus card *****vars : '.print_r($vars, true), 'acting_transaction.log');
5873
5874 $header = "POST " . $interface['path'] . " HTTP/1.1\r\n";
5875 $header .= "Host: " . $_SERVER['HTTP_HOST'] . "\r\n";
5876 //$header .= "Host: usctest.securesites.com\r\n";
5877 $header .= "User-Agent: PHP Script\r\n";
5878 $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
5879 $header .= "Content-Length: " . strlen($vars) . "\r\n";
5880 $header .= "Connection: close\r\n\r\n";
5881 $header .= $vars;
5882 $fp = fsockopen('ssl://'.$interface['host'],443,$errno,$errstr,30);
5883
5884 if ($fp){
5885 fwrite($fp, $header);
5886 while ( !feof($fp) ) {
5887 $scr = fgets($fp, 1024);
5888 $page .= $scr;
5889 }
5890 fclose($fp);
5891
5892 //usces_log('zeus card *****2 : '.print_r($page, true), 'acting_transaction.log');
5893 if( false !== strpos( $page, 'Success_order') ){
5894 usces_log('zeus card entry data1 (acting_processing) : '.print_r($entry, true), 'acting_transaction.log');
5895 $ordd = usces_get_order_number( $page );
5896 //20120904ysk start 0000541
5897 if ( !isset($_POST['cbrand']) || (isset($_POST['howpay']) && 1 == $_POST['howpay']) ) {
5898 $args = '';
5899 } else {
5900 $div = 'div_'.$_POST['cbrand'];
5901 $args = '&cbrand='.$_POST['cbrand'].'&howpay='.$_POST['howpay'].'&'.$div.'='.$_POST[$div];
5902 }
5903 $args .= '&order_number='.$ordd;
5904 header("Location: " . USCES_CART_URL . $delim . 'acting=zeus_card&acting_return=1'.$args);
5905 //20120904ysk end
5906 exit;
5907 }else{
5908 usces_log('zeus card : Certification Error', 'acting_transaction.log');
5909 header("Location: " . USCES_CART_URL . $delim . 'acting=zeus_card&acting_return=0');
5910 exit;
5911 }
5912 }else{
5913 usces_log('zeus card : Socket Error', 'acting_transaction.log');
5914 header("Location: " . USCES_CART_URL . $delim . 'acting=zeus_card&acting_return=0');
5915 }
5916 exit;
5917
5918 }else if($acting_flg == 'acting_zeus_conv'){
5919
5920 $acting_opts = $this->options['acting_settings']['zeus'];
5921 $interface = parse_url($acting_opts['conv_url']);
5922
5923
5924 $vars .= 'clientip=' . $acting_opts['clientip_conv'];
5925 $vars .= '&act=' . $_POST['act'];
5926 $vars .= '&money=' . $_POST['money'];
5927 $vars .= '&username=' . mb_convert_encoding($_POST['username'], 'SJIS', 'UTF-8');
5928 $vars .= '&telno=' . str_replace('-', '', $_POST['telno']);
5929 $vars .= '&email=' . $_POST['email'];
5930 $vars .= '&pay_cvs=' . $_POST['pay_cvs'];
5931 $vars .= '&sendid=' . $_POST['sendid'];
5932 $vars .= '&sendpoint=' . $_POST['sendpoint'];
5933 if( !WCUtils::is_blank($acting_opts['testid_conv']) ){
5934 $vars .= '&testid=' . $acting_opts['testid_conv'];
5935 $vars .= '&test_type=' . $acting_opts['test_type_conv'];
5936 }
5937
5938
5939 $header = "POST " . $interface['path'] . " HTTP/1.1\r\n";
5940 $header .= "Host: " . $_SERVER['HTTP_HOST'] . "\r\n";
5941 $header .= "User-Agent: PHP Script\r\n";
5942 $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
5943 $header .= "Content-Length: " . strlen($vars) . "\r\n";
5944 $header .= "Connection: close\r\n\r\n";
5945 $header .= $vars;
5946 $fp = fsockopen('ssl://'.$interface['host'],443,$errno,$errstr,30);
5947
5948 if ($fp){
5949 fwrite($fp, $header);
5950 while ( !feof($fp) ) {
5951 $scr = fgets($fp, 1024);
5952 $page .= $scr;
5953 if( false !== strpos( $scr, 'order_no') )
5954 $qstr .= trim($scr) . '&';
5955 if( false !== strpos( $scr, 'pay_no1') )
5956 $qstr .= trim($scr) . '&';
5957 if( false !== strpos( $scr, 'pay_no2') )
5958 $qstr .= trim($scr) . '&';
5959 if( false !== strpos( $scr, 'pay_limit') )
5960 $qstr .= trim($scr) . '&';
5961 if( false !== strpos( $scr, 'pay_url') )
5962 $qstr .= trim($scr) . '&';
5963 if( false !== strpos( $scr, 'error_code') )
5964 $qstr .= trim($scr) . '&';
5965 if( false !== strpos( $scr, 'sendpoint') )
5966 $qstr .= trim($scr) . '&';
5967 }
5968 $qstr .= 'pay_cvs=' . $_POST['pay_cvs'];
5969 fclose($fp);
5970 //usces_log('zeus page : '.$page, 'acting_transaction.log');
5971
5972 if( false !== strpos( $page, 'Success_order') ){
5973 usces_log('zeus conv entry data (acting_processing) : '.print_r($entry, true), 'acting_transaction.log');
5974 header("Location: " . USCES_CART_URL . $delim . 'acting=zeus_conv&acting_return=1&' . $qstr);
5975 exit;
5976 }else{
5977 usces_log('zeus data NG : '.$page, 'acting_transaction.log');
5978 header("Location: " . USCES_CART_URL . $delim . 'acting=zeus_conv&acting_return=0');
5979 exit;
5980 }
5981 }else{
5982 usces_log('zeus : sockopen NG', 'acting_transaction.log');
5983 header("Location: " . USCES_CART_URL . $delim . 'acting=zeus_conv&acting_return=0');
5984 }
5985 exit;
5986
5987 //20110208ysk start
5988 }else if($acting_flg == 'acting_paypal_ec') {
5989 $acting_opts = $this->options['acting_settings']['paypal'];
5990
5991 $nvpstr = $query;
5992 $nvpstr .= '&CURRENCYCODE='.$this->get_currency_code();
5993 //$nvpstr .= '&ADDROVERRIDE=1';
5994 $nvpstr .= '&PAYMENTACTION=' . apply_filters('usces_filter_paypal_ec_paymentaction', 'Sale');
5995
5996 //The returnURL is the location where buyers return to when a payment has been succesfully authorized.
5997 $nvpstr .= '&RETURNURL='.urlencode(USCES_CART_URL.$delim.'acting=paypal_ec&acting_return=1');
5998
5999 //The cancelURL is the location buyers are sent to when they hit the cancel button during authorization of payment during the PayPal flow
6000 $nvpstr .= '&CANCELURL='.urlencode(USCES_CART_URL.$delim.'confirm=1');
6001
6002 $nvpstr .= '&NOTIFYURL='.urlencode(USCES_PAYPAL_NOTIFY_URL);
6003
6004 $this->paypal->setMethod('SetExpressCheckout');
6005 $this->paypal->setData($nvpstr);
6006 $res = $this->paypal->doExpressCheckout();
6007 $resArray = $this->paypal->getResponse();
6008 $ack = strtoupper($resArray["ACK"]);
6009 if($ack == "SUCCESS" || $ack == "SUCCESSWITHWARNING") {
6010 $token = urldecode($resArray["TOKEN"]);
6011 $payPalURL = $acting_opts['paypal_url'].'?cmd=_express-checkout&token='.$token.'&useraction=commit';
6012 header("Location: ".$payPalURL);
6013
6014 } else {
6015 //Display a user friendly Error on the page using any of the following error information returned by PayPal
6016 $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
6017 $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
6018 $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
6019 $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
6020 usces_log('PayPal : SetExpressCheckout API call failed. Error Code:['.$ErrorCode.'] Error Severity Code:['.$ErrorSeverityCode.'] Short Error Message:'.$ErrorShortMsg.' Detailed Error Message:'.$ErrorLongMsg, 'acting_transaction.log');
6021 header("Location: ".USCES_CART_URL.$delim.'acting=paypal_ec&acting_return=0');
6022 }
6023 exit;
6024 //20110208ysk end
6025 //20121030ysk start
6026 } elseif( $acting_flg == 'acting_telecom_edy' ) {
6027 $table_meta_name = $wpdb->prefix."usces_order_meta";
6028 $value = array();
6029 $value['usces_cart'] = $_SESSION['usces_cart'];
6030 $value['usces_entry'] = $_SESSION['usces_entry'];
6031 $value['usces_member'] = $_SESSION['usces_member'];
6032 $mvalue = serialize( $value );
6033 $mquery = $wpdb->prepare( "INSERT INTO $table_meta_name (order_id, meta_key, meta_value) VALUES (%d, %s, %s)", $_POST['option'], $_POST['option'], $mvalue );
6034 $res = $wpdb->query( $mquery );
6035
6036 unset( $_SESSION['usces_cart'] );
6037 unset( $_SESSION['usces_entry'] );
6038
6039 $acting_opts = $this->options['acting_settings']['telecom'];
6040 header( "location: ".$acting_opts['send_url_edy'].'?acting=telecom_edy'.$query );
6041 exit;
6042 //20121030ysk end
6043 //20121206ysk start
6044 } else if( $acting_flg == 'acting_digitalcheck_card' ) {
6045 $acting_opts = $this->options['acting_settings']['digitalcheck'];
6046 $interface = parse_url($acting_opts['send_url_user_id']);
6047 $kakutei = ( empty($acting_opts['card_kakutei']) ) ? '0' : $acting_opts['card_kakutei'];
6048
6049 $vars = 'IP='.$acting_opts['card_ip'];
6050 $vars .= '&PASS='.$acting_opts['card_pass'];
6051 $vars .= '&IP_USER_ID='.$_POST['IP_USER_ID'];
6052 $vars .= '&SID='.$_POST['SID'];
6053 $vars .= '&STORE=51';
6054 $vars .= '&N1='.$_POST['N1'];
6055 $vars .= '&K1='.$_POST['K1'];
6056 $vars .= '&KAKUTEI='.$kakutei;
6057 $vars .= '&FUKA='.$acting_flg;
6058
6059 $header = "POST ".$interface['path']." HTTP/1.1\r\n";
6060 $header .= "Host: ".$_SERVER['HTTP_HOST']."\r\n";
6061 $header .= "User-Agent: PHP Script\r\n";
6062 $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
6063 $header .= "Content-Length: ".strlen($vars)."\r\n";
6064 $header .= "Connection: close\r\n\r\n";
6065 $header .= $vars;
6066 $fp = fsockopen('ssl://'.$interface['host'],443,$errno,$errstr,30);
6067
6068 if( $fp ) {
6069 fwrite( $fp, $header );
6070 $page = '';
6071 while( !feof($fp) ) {
6072 $line = fgets( $fp, 1024 );
6073 if( strcmp($line, "\r\n") == 0 ) {
6074 $headerdone = true;
6075 } elseif( $headerdone ) {
6076 $page .= $line;
6077 }
6078 }
6079 fclose($fp);
6080 $lines = explode("\n", $page);
6081 if( false !== strpos( $lines[0], 'OK') ) {
6082 usces_log('digitalcheck card entry data (acting_processing) : '.print_r($entry, true), 'acting_transaction.log');
6083 //$args = '&SID='.$lines[1];
6084 $args = '&SID='.$_POST['SID'].'&FUKA='.$acting_flg;
6085 header( "location: ".USCES_CART_URL.$delim.'acting=digitalcheck_card&acting_return=1'.$args );
6086 } else {
6087 usces_log('digitalcheck card : Certification Error : '.$page, 'acting_transaction.log');
6088 header( "location: ".USCES_CART_URL.$delim.'acting=digitalcheck_card&acting_return=0' );
6089 }
6090 } else {
6091 usces_log('digitalcheck card : Socket Error', 'acting_transaction.log');
6092 header( "location: ".USCES_CART_URL.$delim.'acting=digitalcheck_card&acting_return=0' );
6093 }
6094 exit;
6095 } else if( $acting_flg == 'acting_digitalcheck_conv' ) {
6096 if( isset($_REQUEST['STORE']) and '99' != $_REQUEST['STORE'] ) {
6097 $res = $this->order_processing();
6098 if( 'ordercompletion' == $res ) {
6099 $table_meta_name = $wpdb->prefix."usces_order_meta";
6100 $mquery = $wpdb->prepare("SELECT order_id FROM $table_meta_name WHERE meta_key = %s AND meta_value = %s", 'SID', $_REQUEST['SID'] );
6101 $order_id = $wpdb->get_var($mquery);
6102 if( $order_id ) {
6103 $data = array( "settltment_status" => "未決済", "settltment_errmsg" => "決済が完了していません" );
6104 $this->set_order_meta_value( 'acting_digitalcheck_conv', serialize( $data ), $order_id );
6105 }
6106 $this->cart->crear_cart();
6107 $acting_opts = $this->options['acting_settings']['digitalcheck'];
6108 header( "location: ".$acting_opts['send_url_conv'].'?acting=digitalcheck_conv'.$query );
6109 exit;
6110 } else {
6111 usces_log('digitalcheck conv : order processing error', 'acting_transaction.log');
6112 header( "location: ".USCES_CART_URL.$delim.'acting=digitalcheck_conv&acting_return=0' );
6113 }
6114 } else {
6115 $acting_opts = $this->options['acting_settings']['digitalcheck'];
6116 header( "location: ".$acting_opts['send_url_conv'].'?acting=digitalcheck_conv'.$query );
6117 exit;
6118 }
6119 //20121206ysk end
6120 }
6121 do_action('usces_action_acting_processing', $acting_flg, $query);
6122 }
6123
6124 function inquiry_processing() {
6125
6126 $mail_res = usces_send_inquirymail();
6127
6128 if ( $mail_res )
6129 return 'inquiry_comp';
6130 else
6131 return 'inquiry_error';
6132 }
6133
6134 function lastprocessing() {
6135
6136 if ( $this->page == 'ordercompletion' )
6137 $this->cart->crear_cart();
6138
6139 unset($_SESSION['usces_singleitem']);
6140
6141 }
6142
6143 function is_item_zaiko( $post_id, $sku ){
6144 $status_num = (int)$this->getItemZaikoStatusId($post_id, $sku);
6145 $zaiko_num = trim($this->getItemZaikoNum($post_id, $sku));
6146
6147 if( false !== $zaiko_num
6148 && ( 0 < (int)$zaiko_num || WCUtils::is_blank($zaiko_num) )
6149 && false !== $status_num
6150 && 2 > $status_num
6151 ){
6152 return true;
6153 }else{
6154 return false;
6155 }
6156 }
6157
6158 // function for the cart ***********************************************************
6159 function get_total_price( $cart = array() ) {
6160 if( empty($cart) )
6161 $cart = $this->cart->get_cart();
6162
6163 $total_price = 0;
6164
6165 if( !empty($cart) ) {
6166 for($i=0; $i<count($cart); $i++) {
6167 $quantity = $cart[$i]['quantity'];
6168 $skuPrice = $cart[$i]['price'];
6169
6170 $total_price += ($skuPrice * $quantity);
6171 }
6172 }
6173 return apply_filters( 'usces_filter_get_total_price', $total_price, $cart);
6174 }
6175
6176 function get_total_quantity( $cart = array() ) {
6177 if( empty($cart) )
6178 $cart = $this->cart->get_cart();
6179
6180 $total_quantity = 0;
6181
6182 if( !empty($cart) ) {
6183 for($i=0; $i<count($cart); $i++) {
6184 $total_quantity += $cart[$i]['quantity'];
6185 }
6186 }
6187 return $total_quantity;
6188 }
6189
6190 function get_order_point( $mem_id = '', $display_mode = '', $cart = array() ) {
6191 if( $mem_id == '' || $this->options['membersystem_state'] == 'deactivate' || $this->options['membersystem_point'] == 'deactivate') return 0;
6192
6193 if ( empty($cart) )
6194 $cart = $this->cart->get_cart();
6195
6196 if ( empty($display_mode) )
6197 $display_mode = $this->options['display_mode'];
6198
6199 $point = 0;
6200 $total = $this->get_total_price( $cart );
6201 if ( $display_mode == 'Promotionsale' ) {
6202 if ( $this->options['campaign_privilege'] == 'discount' ) {
6203 foreach ( $cart as $rows ) {
6204 $cats = $this->get_post_term_ids($rows['post_id'], 'category');
6205 if ( !in_array($this->options['campaign_category'], $cats) ){
6206 $rate = get_post_meta($rows['post_id'], '_itemPointrate', true);
6207 $price = $rows['price'] * $rows['quantity'];
6208 $point += $price * $rate / 100;
6209 }
6210 }
6211 } elseif ( $this->options['campaign_privilege'] == 'point' ) {
6212 foreach ( $cart as $rows ) {
6213 $rate = get_post_meta($rows['post_id'], '_itemPointrate', true);
6214 //$price = $this->getItemPrice($rows['post_id'], $rows['sku']) * $rows['quantity'];
6215 $price = $rows['price'] * $rows['quantity'];
6216 $cats = $this->get_post_term_ids($rows['post_id'], 'category');
6217 if ( in_array($this->options['campaign_category'], $cats) )
6218 $point += $price * $rate / 100 * $this->options['privilege_point'];
6219 else
6220 $point += $price * $rate / 100;
6221 }
6222 }
6223 } else {
6224 foreach ( $cart as $rows ) {
6225 $rate = get_post_meta($rows['post_id'], '_itemPointrate', true);
6226 //$price = $this->getItemPrice($rows['post_id'], $rows['sku']) * $rows['quantity'];
6227 $price = $rows['price'] * $rows['quantity'];
6228 $point += $price * $rate / 100;
6229 }
6230 }
6231
6232 //20130425ysk start 0000699
6233 if( 0 < $point ) ceil( $point );
6234
6235 $entry = $this->cart->get_entry();
6236 $use_point = isset( $entry['order']['usedpoint'] ) ? (int)$entry['order']['usedpoint'] : 0;
6237 if( 0 < $use_point ) {
6238 $point = ceil( $point - ( $point * $use_point / $total ) );
6239 if( 0 > $point )
6240 $point = 0;
6241 }
6242
6243 return apply_filters( 'usces_filter_get_order_point', $point );
6244 //20130425ysk end
6245 }
6246
6247 function get_order_discount( $display_mode = '', $cart = array() ) {
6248 if ( empty($cart) )
6249 $cart = $this->cart->get_cart();
6250
6251 if ( empty($display_mode) )
6252 $display_mode = $this->options['display_mode'];
6253
6254 $discount = 0;
6255 $total = $this->get_total_price( $cart );
6256 if ( $display_mode == 'Promotionsale' ) {
6257 if ( $this->options['campaign_privilege'] == 'discount' ){
6258 if( 0 === (int)$this->options['campaign_category'] ){
6259 $discount = $total * $this->options['privilege_discount'] / 100;
6260 }else{
6261 foreach($cart as $cart_row){
6262 if( in_category((int)$this->options['campaign_category'], $cart_row['post_id']) ){
6263 $discount += $cart_row['price'] * $cart_row['quantity'] * $this->options['privilege_discount'] / 100;
6264 }
6265 }
6266 }
6267 }else if ( $this->options['campaign_privilege'] == 'point' ){
6268 $discount = 0;
6269 }
6270 }
6271
6272 $discount = ceil($discount * -1);
6273 $discount = apply_filters('usces_order_discount', $discount, $cart);
6274 return $discount;
6275 }
6276
6277 function getShippingCharge( $pref, $cart = array(), $entry = array() ) {
6278 if( empty($cart) )
6279 $cart = $this->cart->get_cart();
6280 if( empty($entry) )
6281 $entry = $this->cart->get_entry();
6282
6283 //�
6284 �送方法ID
6285 $d_method_id = $entry['order']['delivery_method'];
6286 //�
6287 �送方法index
6288 $d_method_index = $this->get_delivery_method_index($d_method_id);
6289 //送料ID
6290 $fixed_charge_id = ( isset($this->options['delivery_method'][$d_method_index]['charge']) ) ? $this->options['delivery_method'][$d_method_index]['charge'] : -1;
6291 $individual_quant = 0;
6292 $total_quant = 0;
6293 $charges = array();
6294 $individual_charges = array();
6295 $country = (isset($entry['delivery']['country']) && !empty($entry['delivery']['country'])) ? $entry['delivery']['country'] : $entry['customer']['country'];//20120710ysk 0000472
6296
6297 foreach ( $cart as $rows ) {
6298
6299 if( -1 == $fixed_charge_id ){
6300 //商品送料ID
6301 $s_charge_id = $this->getItemShippingCharge($rows['post_id']);
6302 //商品送料index
6303 $s_charge_index = $this->get_shipping_charge_index($s_charge_id);
6304 //20120710ysk start 0000472
6305 //$charge = isset($this->options['shipping_charge'][$s_charge_index]['value'][$pref]) ? $this->options['shipping_charge'][$s_charge_index]['value'][$pref] : 0;
6306 $charge = isset($this->options['shipping_charge'][$s_charge_index][$country][$pref]) ? $this->options['shipping_charge'][$s_charge_index][$country][$pref] : 0;
6307 //20120710ysk end
6308 }else{
6309
6310 $s_charge_index = $this->get_shipping_charge_index($fixed_charge_id);
6311 //20120710ysk start 0000472
6312 //$charge = isset($this->options['shipping_charge'][$s_charge_index]['value'][$pref]) ? $this->options['shipping_charge'][$s_charge_index]['value'][$pref] : 0;
6313 $charge = isset($this->options['shipping_charge'][$s_charge_index][$country][$pref]) ? $this->options['shipping_charge'][$s_charge_index][$country][$pref] : 0;
6314 //20120710ysk end
6315 }
6316
6317 if($this->getItemIndividualSCharge($rows['post_id'])){
6318 $individual_quant += $rows['quantity'];
6319 $individual_charges[] = $rows['quantity'] * $charge;
6320 }else{
6321 $charges[] = $charge;
6322 }
6323 $total_quant += $rows['quantity'];
6324 }
6325
6326 if( count($charges) > 0 ){
6327 rsort($charges);
6328 $max_charge = $charges[0];
6329 $charge = $max_charge + array_sum($individual_charges);
6330 }else{
6331 $charge = array_sum($individual_charges);
6332 }
6333
6334 $charge = apply_filters('usces_filter_getShippingCharge', $charge, $cart, $entry);
6335
6336 return $charge;
6337 }
6338
6339 function getCODFee($payment_name, $amount_by_cod) {
6340 $payments = $this->getPayments($payment_name);
6341 if( 'COD' != $payments['settlement'] ){
6342 $fee = 0;
6343
6344 }else if( 'change' != $this->options['cod_type'] ){
6345 //$fee = isset($this->options['cod_fee']) ? $this->options['cod_fee'] : '';
6346 $fee = isset($this->options['cod_fee']) ? $this->options['cod_fee'] : 0;
6347
6348 }else{
6349 $price = $amount_by_cod + $this->getTax( $amount_by_cod );
6350 if( $price <= $this->options['cod_first_amount'] ){
6351 $fee = $this->options['cod_first_fee'];
6352
6353 }else if( isset($this->options['cod_amounts']) ){
6354 $last = count( $this->options['cod_amounts'] ) - 1;
6355 if( $price > $this->options['cod_amounts'][$last] ){
6356 $fee = $this->options['cod_end_fee'];
6357
6358 }else{
6359 $fee = 0;
6360 foreach( $this->options['cod_amounts'] as $key => $value ){
6361 if( $price <= $value ){
6362 $fee = $this->options['cod_fees'][$key];
6363 break;
6364 }
6365 }
6366 }
6367 }else{
6368 $fee = $this->options['cod_end_fee'];
6369 }
6370 }
6371 $fee = apply_filters('usces_filter_getCODFee', $fee, $payment_name, $amount_by_cod);
6372 return $fee;
6373 }
6374
6375 function getTax( $total ) {
6376 if( empty($this->options['tax_rate']) )
6377 return 0;
6378
6379 if( $this->options['tax_method'] == 'cutting' )
6380 $tax = floor($total * $this->options['tax_rate'] / 100);
6381 elseif($this->options['tax_method'] == 'bring')
6382 $tax = ceil($total * $this->options['tax_rate'] / 100);
6383 elseif($this->options['tax_method'] == 'rounding')
6384 $tax = round($total * $this->options['tax_rate'] / 100);
6385
6386 return $tax;
6387 }
6388
6389 function set_cart_fees( $member, &$entries ) {
6390 $carts = $this->cart->get_cart();
6391 $total_items_price = $this->get_total_price();
6392 if ( empty($this->options['postage_privilege']) || $total_items_price < $this->options['postage_privilege'] ) {
6393 $shipping_charge = $this->getShippingCharge( $entries['delivery']['pref'] );
6394 } else {
6395 $shipping_charge = 0;
6396 }
6397 $shipping_charge = apply_filters('usces_filter_set_cart_fees_shipping_charge', $shipping_charge, $carts, $entries);
6398 $payments = $this->getPayments( $entries['order']['payment_name'] );
6399 $discount = $this->get_order_discount();
6400 $use_point = $entries['order']['usedpoint'];
6401 $amount_by_cod = $total_items_price - $use_point + $discount + $shipping_charge;
6402 $amount_by_cod = apply_filters('usces_filter_set_cart_fees_amount_by_cod', $amount_by_cod, $entries, $total_items_price, $use_point, $discount, $shipping_charge);
6403 $cod_fee = $this->getCODFee($entries['order']['payment_name'], $amount_by_cod);
6404 $cod_fee = apply_filters('usces_filter_set_cart_fees_cod', $cod_fee, $entries, $total_items_price, $use_point, $discount, $shipping_charge);
6405 $total_price = $total_items_price - $use_point + $discount + $shipping_charge + $cod_fee;
6406 $total_price = apply_filters('usces_filter_set_cart_fees_total_price', $total_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee);
6407 $tax = $this->getTax( $total_price );
6408 $total_full_price = $total_price + $tax;
6409 $total_full_price = apply_filters('usces_filter_set_cart_fees_total_full_price', $total_full_price, $total_items_price, $use_point, $discount, $shipping_charge, $cod_fee);
6410 $get_point = $this->get_order_point( $member['ID'] );
6411 //20130425ysk start 0000699
6412 //if(0 < (int)$use_point){
6413 // $get_point = ceil( $get_point - ($get_point * $use_point / $total_items_price) );
6414 // if(0 > $get_point)
6415 // $get_point = 0;
6416 //}
6417 //20130425ysk end
6418
6419 $array = array(
6420 'total_items_price' => $total_items_price,
6421 'total_price' => $total_price,
6422 'total_full_price' => $total_full_price,
6423 'getpoint' => $get_point,
6424 'usedpoint' => $use_point,
6425 'discount' => $discount,
6426 'shipping_charge' => $shipping_charge,
6427 'cod_fee' => $cod_fee,
6428 'tax' => $tax
6429 );
6430 $this->cart->set_order_entry( $array );
6431 //$entries = $this->cart->get_entry();
6432 //var_dump($entries);
6433 }
6434
6435 function getPayments( $payment_name ) {
6436 if( '#none#' == $payment_name )
6437 return NULL;
6438
6439 $payments = usces_get_system_option( 'usces_payment_method', 'name' );
6440 if( isset($payments[$payment_name]) )
6441 return $payments[$payment_name];
6442 return NULL;
6443 }
6444
6445 function is_maintenance() {
6446 if ( $this->options['display_mode'] == 'Maintenancemode' )
6447 return true;
6448 else
6449 return false;
6450 }
6451
6452 // function maintenance_mode() {
6453 // if ( $this->is_maintenance() && !is_user_logged_in() && (!strstr($_SERVER['REQUEST_URI'], 'wp-admin') || !strstr($_SERVER['REQUEST_URI'], 'wp-login') ) ) {
6454 // include ( TEMPLATEPATH . '/maintenance.php ');
6455 // exit;
6456 // } elseif ( isset($_GET['uscesmode']) && $_GET['uscesmode'] == 'lostpassword' ) {
6457 // $error = isset($_GET['error']) ? '?error='.$_GET['error'] : '';
6458 // include ( TEMPLATEPATH . '/member/changepassword.php ');
6459 // exit;
6460 // }
6461 // }
6462
6463 function get_member_history($mem_id) {
6464 global $wpdb;
6465 $order_table = $wpdb->prefix . "usces_order";
6466
6467 $query = $wpdb->prepare("SELECT * FROM $order_table WHERE mem_id = %d ORDER BY order_date DESC", $mem_id);
6468 // $query = $wpdb->prepare("SELECT ID, order_cart, order_condition, order_date, order_usedpoint, order_getpoint,
6469 // order_discount, order_shipping_charge, order_cod_fee, order_tax, order_status
6470 // FROM $order_table WHERE mem_id = %d ORDER BY order_date DESC", $mem_id);
6471 $results = $wpdb->get_results( $query );
6472
6473 $i=0;
6474 $res = array();
6475 foreach ( $results as $value ) {
6476 if(strpos($value->order_status, 'cancel') === false && strpos($value->order_status, 'estimate') === false){
6477
6478 $res[] = array(
6479 'ID' => $value->ID,
6480 'cart' => unserialize($value->order_cart),
6481 'condition' => unserialize($value->order_condition),
6482 'getpoint' => $value->order_getpoint,
6483 'usedpoint' => $value->order_usedpoint,
6484 'discount' => $value->order_discount,
6485 'shipping_charge' => $value->order_shipping_charge,
6486 'payment_name' => $value->order_payment_name,
6487 'cod_fee' => $value->order_cod_fee,
6488 'tax' => $value->order_tax,
6489 'order_status' => $value->order_status,
6490 'date' => mysql2date(__('Y/m/d'), $value->order_date),
6491 'order_date' => $value->order_date
6492 );
6493 $i++;
6494
6495 }
6496 }
6497
6498 return $res;
6499
6500 }
6501
6502 function get_post_term_ids( $post_id, $taxonomy ){
6503 global $wpdb;
6504 $query = $wpdb->prepare("SELECT tt.term_id FROM $wpdb->term_relationships AS tr
6505 INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
6506 WHERE tt.taxonomy = %s AND tr.object_id = %d", $taxonomy, $post_id);
6507 $ids = $wpdb->get_col( $query );
6508
6509 return $ids;
6510
6511 }
6512
6513 function get_tag_names($post_id) {
6514 global $wpdb;
6515 $tag = 'post_tag';
6516 $query = $wpdb->prepare("SELECT t.name FROM $wpdb->term_relationships AS tr
6517 INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
6518 INNER JOIN $wpdb->terms AS t ON t.term_id = tt.term_id
6519 WHERE tt.taxonomy = %s AND tr.object_id = %d", $tag, $post_id);
6520 $names = $wpdb->get_col( $query );
6521
6522 return apply_filters('usces_filter_get_tag_names', $names, $post_id);
6523
6524 }
6525
6526 function get_ID_byItemName($itemname, $status = 'publish') {
6527 global $wpdb;
6528 $meta_key = '_itemCode';
6529 $query = $wpdb->prepare("SELECT p.ID FROM $wpdb->posts AS p
6530 INNER JOIN $wpdb->postmeta AS pm ON p.ID = pm.post_id
6531 WHERE p.post_status = %s AND pm.meta_key = %s AND meta_value = %s ", $status, $meta_key, $itemname);
6532 $id = $wpdb->get_var( $query );
6533
6534 // $wpdb->show_errors();
6535 // $wpdb->print_error();
6536
6537 return $id;
6538
6539 }
6540
6541 function uscescv( $sessid, $flag ) {
6542
6543 $chars = '';
6544 $i=0;
6545 $h=0;
6546 $usces_cookie = $this->get_cookie();
6547 if( isset($usces_cookie['id']) && !empty($usces_cookie['id']) ){
6548 $cid = $usces_cookie['id'];
6549 }elseif( isset($_SESSION['usces_cookieid']) && !empty($_SESSION['usces_cookieid']) ){
6550 $cid = $_SESSION['usces_cookieid'];
6551 }else{
6552 $cid = 0;
6553 }
6554 while($h<strlen($sessid)){
6555 if(0 == $i % 3){
6556 $chars .= substr($i, -1);
6557 }else{
6558 $chars .= substr($sessid, $h, 1);
6559 $h++;
6560 }
6561 $i++;
6562 }
6563 if( $flag ){
6564 $postfix = ( isset($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['REMOTE_ADDR']) ) ? $_SERVER['REMOTE_ADDR'] : 'REMOTE_ADDR';
6565 $postfix = apply_filters('usces_sessid_force', $postfix);
6566 $sessid = $chars . '_' . $postfix . '_' . $cid . '_A';
6567 }else{
6568 $sessid = $chars . '_' . apply_filters('usces_sessid_flag', 'acting') . '_' . $cid . '_A';
6569 }
6570 $sessid = urlencode(base64_encode($sessid));
6571 //usces_log('sessid2 : '.$sessid, 'acting_transaction.log');
6572
6573 return $sessid;
6574 }
6575
6576 function uscesdc( $sessid ) {
6577 // $usces_cookie = $this->get_cookie();
6578 // if( $this->use_ssl && ($this->is_cart_or_member_page($_SERVER['REQUEST_URI']) || $this->is_inquiry_page($_SERVER['REQUEST_URI']))){
6579 // if( isset($usces_cookie['sslid']) && !empty($usces_cookie['sslid']) ){
6580 // $cid = $usces_cookie['sslid'];
6581 // }else{
6582 // $cid = 0;
6583 // }
6584 // }else{
6585 // if( isset($usces_cookie['id']) && !empty($usces_cookie['id']) ){
6586 // $cid = $usces_cookie['id'];
6587 // }else{
6588 // $cid = 0;
6589 // }
6590 // }
6591 $sessid = base64_decode(urldecode($sessid));
6592 list($sess, $addr, $cookieid, $none) = explode('_', $sessid, 4);
6593 $postfix = ( isset($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['REMOTE_ADDR']) ) ? $_SERVER['REMOTE_ADDR'] : 'REMOTE_ADDR';
6594 $postfix = apply_filters('usces_sessid_force', $postfix);
6595 //usces_log('cid : '.$cid, 'acting_transaction.log');
6596 //usces_log('cookieid : '.$cookieid, 'acting_transaction.log');
6597 //usces_log('postfix : '.$postfix, 'acting_transaction.log');
6598 //usces_log('addr : '.$addr, 'acting_transaction.log');
6599 if( 'acting' !== $addr && 'mobile' !== $addr && $postfix !== $addr ) {
6600 $sessid = '';
6601 return NULL;
6602 }
6603 $chars = '';
6604 $h=0;
6605 while($h<strlen($sess)){
6606 if(0 != $h % 3){
6607 $chars .= substr($sess, $h, 1);
6608 }
6609 $h++;
6610 }
6611 $sessid = $chars;
6612
6613 return $sessid;
6614
6615 }
6616
6617 function get_visiter( $period ) {
6618 global $wpdb;
6619 $datestr = substr(get_date_from_gmt(gmdate('Y-m-d H:i:s', time())), 0, 10);
6620 $yearstr = substr($datestr, 0, 4);
6621 $monthstr = substr($datestr, 5, 2);
6622 $daystr = substr($datestr, 8, 2);
6623 if($period == 'today') {
6624 $date = $datestr;
6625 $today = $datestr;
6626 }else if($period == 'thismonth') {
6627 $date = date('Y-m-01');
6628 $today = $datestr;
6629 }else if($period == 'lastyear') {
6630 $date = date('Y-m-01', mktime(0, 0, 0, (int)$monthstr, 1, (int)$yearstr-1));
6631 $today = date('Y-m-01', mktime(0, 0, 0, (int)$monthstr, (int)$daystr, (int)$yearstr-1));
6632 }
6633 $table_name = $wpdb->prefix . 'usces_access';
6634
6635 $query = $wpdb->prepare("SELECT SUM(acc_num1) AS ct1, SUM(acc_num2) AS ct2 FROM $table_name WHERE acc_date >= %s AND acc_date <= %s", $date, $today);
6636 $res = $wpdb->get_row($query, ARRAY_A);
6637
6638 if( $res == NULL )
6639 return 0;
6640 else
6641 return $res['ct1']+$res['ct2'];
6642 }
6643
6644 function get_fvisiter( $period ) {
6645 global $wpdb;
6646 $datestr = substr(get_date_from_gmt(gmdate('Y-m-d H:i:s', time())), 0, 10);
6647 $yearstr = substr($datestr, 0, 4);
6648 $monthstr = substr($datestr, 5, 2);
6649 $daystr = substr($datestr, 8, 2);
6650 if($period == 'today') {
6651 $date = $datestr;
6652 $today = $datestr;
6653 }else if($period == 'thismonth') {
6654 $date = date('Y-m-01');
6655 $today = $datestr;
6656 }else if($period == 'lastyear') {
6657 $date = date('Y-m-01', mktime(0, 0, 0, (int)$monthstr, 1, (int)$yearstr-1));
6658 $today = date('Y-m-01', mktime(0, 0, 0, (int)$monthstr, (int)$daystr, (int)$yearstr-1));
6659 }
6660 $table_name = $wpdb->prefix . 'usces_access';
6661
6662 $query = $wpdb->prepare("SELECT SUM(acc_num2) AS ct FROM $table_name WHERE acc_date >= %s AND acc_date <= %s", $date, $today);
6663 $res = $wpdb->get_var($query);
6664
6665 if( $res == NULL )
6666 return 0;
6667 else
6668 return $res;
6669 }
6670
6671 function get_order_num( $period ) {
6672 global $wpdb;
6673 $datestr = substr(get_date_from_gmt(gmdate('Y-m-d H:i:s', time())), 0, 10);
6674 $yearstr = substr($datestr, 0, 4);
6675 $monthstr = substr($datestr, 5, 2);
6676 $daystr = substr($datestr, 8, 2);
6677 if($period == 'today') {
6678 $date = date('Y-m-d 00:00:00', current_time('timestamp'));
6679 $today = date('Y-m-d 23:59:59', current_time('timestamp'));
6680 }else if($period == 'thismonth') {
6681 $date = date('Y-m-01 00:00:00', current_time('timestamp'));
6682 $today = date('Y-m-d 23:59:59', current_time('timestamp'));
6683 }else if($period == 'lastyear') {
6684 $date = date('Y-m-01 00:00:00', mktime(0, 0, 0, (int)$monthstr, 1, (int)$yearstr-1));
6685 $today = date('Y-m-d 23:59:59', mktime(0, 0, 0, (int)$monthstr+1, 0, (int)$yearstr-1));
6686 }
6687 $table_name = $wpdb->prefix . 'usces_order';
6688
6689 $query = $wpdb->prepare("SELECT COUNT(ID) AS ct FROM $table_name WHERE order_date >= %s AND order_date <= %s AND 0 = LOCATE(%s, order_status) AND 0 = LOCATE(%s, order_status)", $date, $today, 'cancel', 'estimate');
6690 $res = $wpdb->get_var($query);
6691
6692 if( $res == NULL )
6693 return 0;
6694 else
6695 return $res;
6696 }
6697
6698 function get_order_amount( $period ) {
6699 global $wpdb;
6700 $datestr = substr(get_date_from_gmt(gmdate('Y-m-d H:i:s', time())), 0, 10);
6701 $yearstr = substr($datestr, 0, 4);
6702 $monthstr = substr($datestr, 5, 2);
6703 $daystr = substr($datestr, 8, 2);
6704 if($period == 'today') {
6705 $date = date('Y-m-d 00:00:00', current_time('timestamp'));
6706 $today = date('Y-m-d 23:59:59', current_time('timestamp'));
6707 }else if($period == 'thismonth') {
6708 $date = date('Y-m-01 00:00:00', current_time('timestamp'));
6709 $today = date('Y-m-d 23:59:59', current_time('timestamp'));
6710 }else if($period == 'lastyear') {
6711 $date = date('Y-m-01 00:00:00', mktime(0, 0, 0, (int)$monthstr, 1, (int)$yearstr-1));
6712 $today = date('Y-m-d 23:59:59', mktime(0, 0, 0, (int)$monthstr+1, 0, (int)$yearstr-1));
6713 }
6714 $table_name = $wpdb->prefix . 'usces_order';
6715
6716 $query = $wpdb->prepare("SELECT
6717 SUM(order_item_total_price) AS price,
6718 SUM(order_usedpoint) AS point,
6719 SUM(order_discount) AS discount,
6720 SUM(order_shipping_charge) AS shipping,
6721 SUM(order_cod_fee) AS cod,
6722 SUM(order_tax) AS tax
6723 FROM $table_name WHERE order_date >= %s AND order_date <= %s AND 0 = LOCATE(%s, order_status) AND 0 = LOCATE(%s, order_status)", $date, $today, 'cancel', 'estimate');
6724 $res = $wpdb->get_row($query, ARRAY_A);
6725
6726 if( $res == NULL )
6727 return 0;
6728 else
6729 return $res['price'] - $res['point'] + $res['discount'] + $res['shipping'] + $res['cod'] + $res['tax'];
6730 }
6731
6732 function is_status($need, $str){
6733 $array = explode(',', $str);
6734 return in_array($need, $array);
6735 }
6736
6737 function make_status( $taio='', $receipt='', $admin='' ){
6738 $str = '';
6739 if($taio != '' && $taio != '#none#')
6740 $str .= $taio . ',';
6741 if($receipt != '' && $receipt != '#none#')
6742 $str .= $receipt . ',';
6743 if($admin != '' && $admin != '#none#')
6744 $str .= $admin . ',';
6745 return $str;
6746 }
6747
6748 function get_memberid_by_email($email){
6749 global $wpdb;
6750 $table_name = $wpdb->prefix . "usces_member";
6751 $query = $wpdb->prepare("SELECT ID FROM $table_name WHERE mem_email = %s", $email);
6752 $res = $wpdb->get_var($query);
6753 return $res;
6754 }
6755
6756 function get_condition(){
6757 //20120807ysk start 0000544
6758 $order_conditions = array(
6759 'display_mode' => $this->options['display_mode'],
6760 'campaign_privilege' => $this->options['campaign_privilege'],
6761 'campaign_category' => $this->options['campaign_category'],
6762 'privilege_point' => $this->options['privilege_point'],
6763 'privilege_discount' => $this->options['privilege_discount']);
6764 return $order_conditions;
6765 //20120807ysk end
6766 }
6767
6768 function get_bestseller_ids( $days = "" ){
6769 global $wpdb;
6770 $datestr = substr(get_date_from_gmt(gmdate('Y-m-d H:i:s', time())), 0, 10);
6771 $yearstr = substr($datestr, 0, 4);
6772 $monthstr = substr($datestr, 5, 2);
6773 $daystr = substr($datestr, 8, 2);
6774 $res = array();
6775 $order_table_name = $wpdb->prefix . "usces_order";
6776 $where = "";
6777 if($days != ''){
6778 $order_date = date('Y-m-d H:i:s', mktime(0, 0, 0, (int)$monthstr, ((int)$daystr-$days), (int)$yearstr));
6779 $where = " WHERE order_date >= '{$order_date}'";
6780 }
6781 $query = "SELECT order_cart FROM {$order_table_name}" . $where;
6782 $dbres = $wpdb->get_col($query);
6783 if(!$dbres) return false;
6784
6785 foreach((array)$dbres as $carts){
6786 $rows = unserialize($carts);
6787 foreach((array)$rows as $carts){
6788 if( 'publish' != get_post_status($carts['post_id']) )
6789 continue;
6790
6791 $id = $carts['post_id'];
6792 $qu = $carts['quantity'];
6793 if(array_key_exists($id, $res)){
6794 $res[$id] = $res[$id] + $qu;
6795 }else{
6796 $res[$id] = $qu;
6797 }
6798 }
6799 }
6800 arsort($res);
6801 $results = array_keys($res);
6802 return $results;
6803 }
6804
6805 function get_items_num(){
6806 global $wpdb;
6807 $query = $wpdb->prepare("SELECT COUNT(ID) AS ct FROM {$wpdb->posts}
6808 WHERE post_mime_type = %s AND post_type = %s AND post_status <> %s",
6809 'item', 'post', 'trush');
6810 $res = $wpdb->get_var($query);
6811
6812 return $res;
6813 }
6814
6815 function is_gptekiyo( $post_id, $sku, $quant ) {
6816 $skus = $this->get_skus( $post_id, 'code' );
6817 if( !isset($skus[$sku]['gp']) || !$skus[$sku]['gp'] ) return false;
6818
6819 $GpN1 = $this->getItemGpNum1($post_id);
6820 $GpN2 = $this->getItemGpNum2($post_id);
6821 $GpN3 = $this->getItemGpNum3($post_id);
6822
6823 if( empty($GpN1) ) {
6824
6825 return false;
6826
6827 }else if( !empty($GpN1) && empty($GpN2) ) {
6828
6829 if( $quant >= $GpN1 ) {
6830 return true;
6831 }else{
6832 return false;
6833 }
6834
6835 }else if( !empty($GpN1) && !empty($GpN2) && empty($GpN3) ) {
6836
6837 if( $quant >= $GpN2 ) {
6838 return true;
6839 }else if( $quant >= $GpN1 && $quant < $GpN2 ) {
6840 return true;
6841 }else{
6842 return false;
6843 }
6844
6845 }else if( !empty($GpN1) && !empty($GpN2) && !empty($GpN3) ) {
6846
6847 if( $quant >= $GpN3 ) {
6848 return true;
6849 }else if( $quant >= $GpN2 && $quant < $GpN3 ) {
6850 return true;
6851 }else if( $quant >= $GpN1 && $quant < $GpN2 ) {
6852 return true;
6853 }else{
6854 return false;
6855 }
6856 }
6857 }
6858
6859 function get_available_delivery_method() {
6860 if($this->cart->num_row() > 0) {
6861 $cart = $this->cart->get_cart();
6862 $before_deli = array();
6863 $intersect = array();
6864 $integration = array();
6865 $temp = array();
6866 $in = 0;
6867 foreach($cart as $key => $row){
6868 $deli = $this->getItemDeliveryMethod($row['post_id']);
6869 //usces_p($deli);
6870 if( empty($deli))
6871 continue;
6872
6873 //usces_log('deli : '.print_r($deli, true), 'acting_transaction.log');
6874 if( 0 === $in ){
6875 $intersect = $deli;
6876 }
6877 $intersect = array_intersect($deli, $intersect);
6878 $before_deli = $deli;
6879 foreach($deli as $value){
6880 $integration[] = $value;
6881 }
6882 $in++;
6883 }
6884 $integration = array_unique($integration);
6885 foreach($integration as $id){
6886 $index = $this->get_delivery_method_index($id);
6887 $temp[$index] = $id;
6888 }
6889 ksort($temp);
6890 //20120820ysk start 0000546
6891 //$force = array($temp[0]);
6892 $force = array(array_shift($temp));
6893 //20120820ysk end
6894
6895 if( empty($intersect) ){
6896 return $force;
6897 }else{
6898 return $intersect;
6899 }
6900 }
6901 return array();
6902 }
6903
6904 function get_delivery_method_index($id) {
6905 $index = false;
6906 for($i=0; $i<count($this->options['delivery_method']); $i++){
6907 if( $this->options['delivery_method'][$i]['id'] === (int)$id ){
6908 $index = $i;
6909 }
6910 }
6911 if($index === false)
6912 return -1;
6913 else
6914 return $index;
6915 }
6916
6917 function get_shipping_charge_index($id) {
6918 $index = false;
6919 for($i=0; $i<count($this->options['shipping_charge']); $i++){
6920 //20120710ysk start 0000472
6921 //if( $this->options['shipping_charge'][$i]['id'] === $id ){
6922 if( (int)$this->options['shipping_charge'][$i]['id'] == (int)$id ){
6923 //20120710ysk end
6924 $index = $i;
6925 }
6926 }
6927 if($index === false)
6928 return -1;
6929 else
6930 return $index;
6931 }
6932
6933 function get_initial_data($xml){
6934 $buf = file_get_contents($xml);
6935 preg_match_all('@<page>.*?<post_title>(.*?)</post_title>.*?<post_status>(.*?)</post_status>.*?<post_name>(.*?)</post_name>.*?<post_content>(.*?)</post_content>.*?</page>@s', $buf, $match, PREG_SET_ORDER);
6936 return $match;
6937 }
6938
6939 function getCurrencySymbol(){
6940 global $usces_settings;
6941 $cr = $this->options['system']['currency'];
6942 list($code, $decimal, $point, $seperator, $symbol) = $usces_settings['currency'][$cr];
6943 return $symbol;
6944 }
6945
6946 function getCartItemName($post_id, $sku){
6947 $name_arr = array();
6948 $name_str = '';
6949
6950 foreach($this->options['indi_item_name'] as $key => $value){
6951 if($value){
6952 $pos = (int)$this->options['pos_item_name'][$key];
6953 $ind = ($pos === 0) ? 'A' : $pos;
6954 switch($key){
6955 case 'item_name':
6956 $name_arr[$ind][$key] = $this->getItemName($post_id);
6957 break;
6958 case 'item_code':
6959 $name_arr[$ind][$key] = $this->getItemCode($post_id);
6960 break;
6961 case 'sku_name':
6962 $name_arr[$ind][$key] = $this->getItemSkuDisp($post_id, $sku);
6963 break;
6964 case 'sku_code':
6965 $name_arr[$ind][$key] = $sku;
6966 break;
6967 }
6968 }
6969
6970 }
6971 ksort($name_arr);
6972 foreach($name_arr as $vals){
6973 foreach($vals as $key => $value){
6974
6975 $name_str .= $value . ' ';
6976 }
6977 }
6978
6979 $name_str = apply_filters('usces_admin_order_item_name_filter', $name_str);
6980
6981 return trim($name_str);
6982 }
6983
6984 function set_reserve_pre_order_id(){
6985 $entry = $this->cart->get_entry();
6986 $id = ( isset($entry['reserve']['pre_order_id']) && !empty($entry['reserve']['pre_order_id']) ) ? $entry['reserve']['pre_order_id'] : uniqid('');
6987 $this->cart->set_pre_order_id($id);
6988 }
6989
6990 function get_current_pre_order_id(){
6991 $entry = $this->cart->get_entry();
6992 $id = ( isset($entry['reserve']['pre_order_id']) && !empty($entry['reserve']['pre_order_id']) ) ? $entry['reserve']['pre_order_id'] : NULL;
6993 return $id;
6994 }
6995
6996 function get_reserve($order_id, $key){
6997 global $wpdb;
6998 $order_meta_table_name = $wpdb->prefix . "usces_order_meta";
6999 $query = $wpdb->prepare("SELECT meta_value FROM $order_meta_table_name WHERE order_id = %d AND meta_key = %s",
7000 $order_id, $key);
7001 $res = $wpdb->get_var($query);
7002 return $res;
7003 }
7004
7005 //20100818ysk start
7006 //20100816ysk start
7007 //function get_order_meta($order_id, $key) {
7008 function get_order_meta_value($key, $order_id) {
7009 global $wpdb;
7010 $order_meta_table_name = $wpdb->prefix . "usces_order_meta";
7011 $query = $wpdb->prepare("SELECT meta_value FROM $order_meta_table_name WHERE order_id = %d AND meta_key = %s",
7012 $order_id, $key);
7013 $res = $wpdb->get_var($query);
7014 return $res;
7015 }
7016 //20100816ysk end
7017 function set_order_meta_value($key, $meta_value, $order_id) {
7018 global $wpdb;
7019
7020 //if( empty($meta_value) ) return;
7021 if( empty($order_id) ) return;
7022
7023 $table_name = $wpdb->prefix . "usces_order_meta";
7024 $query = $wpdb->prepare("SELECT count(*) FROM $table_name WHERE order_id = %d AND meta_key = %s",
7025 $order_id, $key);
7026 $res = $wpdb->get_var($query);
7027 if(0 < $res) {
7028 $query = $wpdb->prepare("UPDATE $table_name SET meta_value = %s WHERE order_id = %d AND meta_key = %s",
7029 $meta_value,
7030 $order_id,
7031 $key
7032 );
7033 $res2 = $wpdb->query($query);
7034 } else {
7035 $query = $wpdb->prepare("INSERT INTO $table_name (order_id, meta_key, meta_value)
7036 VALUES(%d, %s, %s)",
7037 $order_id,
7038 $key,
7039 $meta_value
7040 );
7041 $res2 = $wpdb->query($query);
7042 }
7043 return $res2;
7044 }
7045 //20130524ysk start
7046 function del_order_meta( $key, $order_id ) {
7047 global $wpdb;
7048 $table_name = $wpdb->prefix."usces_order_meta";
7049 $query = $wpdb->prepare( "DELETE FROM $table_name WHERE order_id = %d AND meta_key = %s", $order_id, $key );
7050 $res = $wpdb->query( $query );
7051 return $res;
7052 }
7053 //20130524ysk end
7054 function set_session_custom_member($member_id) {
7055 unset($_SESSION['usces_member']['custom_member']);
7056 $meta = usces_has_custom_field_meta('member');
7057 if(is_array($meta)) {
7058 $keys = array_keys($meta);
7059 foreach($keys as $key) {
7060 $csmb_key = 'csmb_'.$key;
7061 $_SESSION['usces_member']['custom_member'][$key] = maybe_unserialize($this->get_member_meta_value($csmb_key, $member_id));
7062 }
7063 }
7064 }
7065
7066 function reg_custom_member($member_id) {
7067 //20130524ysk start 0000712
7068 $csmb_meta = usces_has_custom_field_meta( 'member' );
7069 if( is_array($csmb_meta) ) {
7070 foreach( $csmb_meta as $key => $entry ) {
7071 if( '4' == $entry['means'] ) {
7072 $this->del_member_meta( 'csmb_'.$key, $member_id );
7073 }
7074 }
7075 }
7076 //20130524ysk end
7077 if( !empty($_POST['custom_member']) ) {
7078 foreach( $_POST['custom_member'] as $key => $value ) {
7079 $csmb_key = 'csmb_'.$key;
7080 if( is_array($value) )
7081 $value = serialize($value);
7082 $res = $this->set_member_meta_value($csmb_key, $value, $member_id);
7083 if(false === $res)
7084 return false;
7085 }
7086 }elseif( isset($_POST['custom_customer']) ){
7087 foreach( $_POST['custom_customer'] as $key => $value ) {
7088 $csmb_key = 'csmb_'.$key;
7089 if( is_array($value) )
7090 $value = serialize($value);
7091 $res = $this->set_member_meta_value($csmb_key, $value, $member_id);
7092 if(false === $res)
7093 return false;
7094 }
7095 }
7096 }
7097 //20100818ysk end
7098
7099 function save_order_acting_data($rand){
7100 global $wpdb;
7101 $data = serialize(array( 'cart' => $this->cart->get_cart(), 'entry' => $this->cart->get_entry() ));
7102 $table_name = $wpdb->prefix . "usces_access";
7103 $query = $wpdb->prepare("INSERT INTO $table_name (acc_type, acc_str1, acc_date, acc_key, acc_value)
7104 VALUES(%s, %s, now(), %s, %s)",
7105 'acting_data',
7106 $this->get_uscesid(false),
7107 $rand,
7108 $data
7109 );
7110 $res = $wpdb->query($query);
7111 return $res;
7112 }
7113
7114 //20100818ysk start
7115 function set_member_meta_value($key, $meta_value, $member_id = ''){
7116 global $wpdb;
7117
7118 //if( empty($meta_value) ) return;
7119 if( WCUtils::is_blank($member_id) ) {
7120 if( !$this->is_member_logged_in() ) return;
7121 $member = $this->get_member();
7122 $member_id = $member['ID'];
7123 }
7124
7125 $table_name = $wpdb->prefix . "usces_member_meta";
7126 //$query = $wpdb->prepare("SELECT meta_value FROM $table_name WHERE member_id = %d AND meta_key = %s",
7127 $query = $wpdb->prepare("SELECT count(*) FROM $table_name WHERE member_id = %d AND meta_key = %s",
7128 $member_id, $key);
7129 $res = $wpdb->get_var($query);
7130 //if($res != NULL){
7131 if(0 < $res){
7132 $query = $wpdb->prepare("UPDATE $table_name SET meta_value = %s WHERE member_id = %d AND meta_key = %s",
7133 $meta_value,
7134 $member_id,
7135 $key
7136 );
7137 $res2 = $wpdb->query($query);
7138 }else{
7139 $query = $wpdb->prepare("INSERT INTO $table_name (member_id, meta_key, meta_value)
7140 VALUES(%d, %s, %s)",
7141 $member_id,
7142 $key,
7143 $meta_value
7144 );
7145 $res2 = $wpdb->query($query);
7146 }
7147 return $res2;
7148 }
7149 //20100818ysk end
7150
7151 function get_member_meta_value($key, $member_id){
7152 global $wpdb;
7153 $table_name = $wpdb->prefix . "usces_member_meta";
7154 $query = $wpdb->prepare("SELECT meta_value FROM $table_name WHERE member_id = %d AND meta_key = %s",
7155 $member_id, $key);
7156 $res = $wpdb->get_var($query);
7157 return $res;
7158 }
7159
7160 function del_member_meta($key, $member_id){
7161 global $wpdb;
7162 $table_name = $wpdb->prefix . "usces_member_meta";
7163 $query = $wpdb->prepare("DELETE FROM $table_name WHERE member_id = %d AND meta_key = %s",
7164 $member_id, $key);
7165 $res = $wpdb->query($query);
7166 return $res;
7167 }
7168
7169 function get_member_meta($member_id){
7170 global $wpdb;
7171 $table_name = $wpdb->prefix . "usces_member_meta";
7172 $query = $wpdb->prepare("SELECT * FROM $table_name WHERE member_id = %d AND meta_key <> 'customer_country' AND meta_key NOT LIKE %s", $member_id, 'csmb_%');
7173 $res = $wpdb->get_results($query, ARRAY_A);
7174 return $res;
7175 }
7176
7177 function get_settle_info_field( $order_id ){
7178 global $wpdb;
7179 $fields = array();
7180 $table_name = $wpdb->prefix . "usces_order_meta";
7181 $query = $wpdb->prepare("SELECT meta_key, meta_value FROM $table_name WHERE order_id = %d AND (meta_key LIKE %s OR meta_key = %s OR meta_key = %s OR meta_key = %s)",
7182 $order_id, 'acting_%', 'settlement_id', 'order_number', 'res_tracking_id', 'SID');
7183 $res = $wpdb->get_results($query, ARRAY_A);
7184 if( !$res )
7185 return $fields;
7186
7187 foreach( $res as $value ){
7188 if( 'settlement_id' == $value['meta_key'] ){
7189 $meta_values = maybe_unserialize($value['meta_value']);
7190 if( is_array($meta_values) ){
7191 foreach( $meta_values as $key => $meta_value ){
7192 $fields[$key] = $meta_value;
7193 }
7194 }else{
7195 $fields['settlement_id'] = $meta_values;
7196 }
7197 }elseif( 'order_number' == $value['meta_key'] ){
7198 $fields['order_number'] = $value['meta_value'];
7199 }elseif( 'res_tracking_id' == $value['meta_key'] ){
7200 $fields['res_tracking_id'] = $value['meta_value'];
7201 }elseif( 'SID' == $value['meta_key'] ){
7202 $fields['SID'] = $value['meta_value'];
7203 }elseif( 'acting_' == substr($value['meta_key'], 0, 7) ){
7204 $meta_values = unserialize($value['meta_value']);
7205 if(is_array($meta_values)){
7206 foreach( $meta_values as $key => $meta_value ){
7207 $fields[$key] = $meta_value;
7208 }
7209 }
7210 }
7211 }
7212 return $fields;
7213 }
7214
7215 function get_post_custom($post_id, $orderby='meta_id', $order='ASC'){
7216 global $wpdb;
7217 $table = $wpdb->prefix . "postmeta";
7218 $meta_list = $wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value FROM $table WHERE post_id = %d ORDER BY $orderby $order",
7219 $post_id), ARRAY_A );
7220
7221 if ( !empty($meta_list) ) {
7222 foreach ( $meta_list as $metarow) {
7223 $mkey = $metarow['meta_key'];
7224 $mval = $metarow['meta_value'];
7225 $res[$mkey][] = $mval;
7226 }
7227 }
7228 return $res;
7229 }
7230
7231 function get_post_user_custom($post_id, $orderby='meta_id', $order='ASC'){
7232 global $wpdb;
7233 $res = array();
7234 $table = $wpdb->prefix . "postmeta";
7235 $meta_list = $wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value FROM $table WHERE post_id = %d ORDER BY $orderby $order",
7236 $post_id), ARRAY_A );
7237
7238 if ( !empty($meta_list) ) {
7239 foreach ( $meta_list as $metarow) {
7240 if( 0 === strpos($metarow['meta_key'], '_') )
7241 continue;
7242
7243 $mkey = $metarow['meta_key'];
7244 $mval = $metarow['meta_value'];
7245 if( array_key_exists($mkey, $res) ){
7246 $cval = $res[$mkey];
7247 $cval = (array)$cval;
7248 $cval[] = $mval;
7249 $res[$mkey] = $cval;
7250 }else{
7251 $res[$mkey] = $mval;
7252 }
7253 }
7254 }
7255 return $res;
7256 }
7257
7258 function get_currency($amount, $symbol_pre = false, $symbol_post = false, $seperator_flag = true ){
7259 global $usces_settings;
7260 $cr = $this->options['system']['currency'];
7261 list($code, $decimal, $point, $seperator, $symbol) = $usces_settings['currency'][$cr];
7262 if( !$seperator_flag ){
7263 $seperator = '';
7264 }
7265 $price = number_format((double)$amount, $decimal, $point, $seperator);//0000652
7266
7267 if( $symbol_pre )
7268 $price = ( usces_is_entity($symbol) ? mb_convert_encoding($symbol, 'UTF-8', 'HTML-ENTITIES') : $symbol ) . $price;
7269
7270 if( $symbol_post )
7271 $price = $price . __($code, 'usces');
7272
7273 return $price;
7274 }
7275
7276 function get_currency_code(){
7277 global $usces_settings;
7278 $cr = $this->options['system']['currency'];
7279 list($code, $decimal, $point, $seperator, $symbol) = $usces_settings['currency'][$cr];
7280 return $code;
7281 }
7282
7283 //shortcode-----------------------------------------------------------------------------
7284 function sc_company_name() {
7285 return htmlspecialchars($this->options['company_name']);
7286 }
7287 function sc_zip_code() {
7288 return htmlspecialchars($this->options['zip_code']);
7289 }
7290 function sc_address1() {
7291 return htmlspecialchars($this->options['address1']);
7292 }
7293 function sc_address2() {
7294 return htmlspecialchars($this->options['address2']);
7295 }
7296 function sc_tel_number() {
7297 return htmlspecialchars($this->options['tel_number']);
7298 }
7299 function sc_fax_number() {
7300 return htmlspecialchars($this->options['fax_number']);
7301 }
7302 function sc_inquiry_mail() {
7303 return htmlspecialchars($this->options['inquiry_mail']);
7304 }
7305 function sc_payment() {
7306 $payments = usces_get_system_option( 'usces_payment_method', 'sort' );
7307 $htm = "<ul>\n";
7308 foreach ( (array)$payments as $payment ) {
7309 $htm .= "<li>" . htmlspecialchars($payment['name']) . "<br />\n";
7310 $htm .= nl2br(htmlspecialchars($payment['explanation'])) . "</li>\n";
7311 }
7312 $htm .= "</ul>\n";
7313 return $htm;
7314 }
7315 function sc_payment_title() {
7316 $payments = $this->options['payment_method'];
7317 $htm = "<ul>\n";
7318 foreach ( (array)$payments as $payment ) {
7319 $htm .= "<li>" . esc_html($payment['name']) . "</li>\n";
7320 }
7321 $htm .= "</ul>\n";
7322 return $htm;
7323 }
7324 function sc_cod_fee() {
7325 return number_format($this->options['cod_fee']);
7326 }
7327 function sc_start_point() {
7328 return number_format($this->options['start_point']);
7329 }
7330 function sc_postage_privilege() {
7331 if(empty($this->options['postage_privilege']))
7332 return;
7333 return number_format($this->options['postage_privilege']);
7334 }
7335 function sc_shipping_charge() {
7336 //20120710ysk start 0000472
7337 $entry = $this->cart->get_entry();
7338 $country = (isset($entry['delivery']['country']) && !empty($entry['delivery']['country'])) ? $entry['delivery']['country'] : $entry['customer']['country'];//20120710ysk 0000472
7339 //20120710ysk end
7340 $arr = array();
7341 foreach ( (array)$this->options['shipping_charge'] as $charges ) {
7342 //20120710ysk start 0000472
7343 //foreach ( (array)$charges['value'] as $value ) {
7344 foreach ( (array)$charges[$country] as $value ) {
7345 //20120710ysk end
7346 $arr[] = $value;
7347 }
7348 }
7349 sort($arr);
7350 $min = $arr[0];
7351 rsort($arr);
7352 $max = $arr[0];
7353 if($min == $max){
7354 $res = number_format($min);
7355 }else{
7356 $res = number_format($min) . __(' - ', 'usces') . number_format($max);
7357 }
7358 return $res;
7359 }
7360 function sc_site_url() {
7361 return get_option('home');
7362 }
7363 function sc_button_to_cart($atts) {
7364 extract(shortcode_atts(array(
7365 'item' => '',
7366 'sku' => '',
7367 'value' => __('to the cart', 'usces'),
7368 'force' => 0,
7369 'quant' => 0,
7370 'opt' => 1,
7371 ), $atts));
7372
7373 $post_id = $this->get_ID_byItemName($item);
7374 $datas = $this->get_skus( $post_id, 'code' );
7375 $zaikonum = $datas[$sku]['stocknum'];
7376 $zaiko = $datas[$sku]['stock'];
7377 $gptekiyo = $datas[$sku]['gp'];
7378 $skuPrice = $datas[$sku]['price'];
7379 $sku_enc = urlencode($sku);
7380 $mats = compact('item','sku','value','force','quant','post_id','datas','zaikonum','zaiko','gptekiyo','skuPrice','sku_enc');
7381 if( ! $this->is_item_zaiko( $post_id, $sku ) ){
7382 return '<div class="button_status">' . esc_html($this->zaiko_status[$zaiko]) . '</div>';
7383 }
7384
7385 $html = "<form action=\"" . USCES_CART_URL . "\" method=\"post\">\n";
7386 $html .= "<input name=\"zaikonum[{$post_id}][{$sku_enc}]\" type=\"hidden\" id=\"zaikonum[{$post_id}][{$sku_enc}]\" value=\"{$zaikonum}\" />\n";
7387 $html .= "<input name=\"zaiko[{$post_id}][{$sku_enc}]\" type=\"hidden\" id=\"zaiko[{$post_id}][{$sku_enc}]\" value=\"{$zaiko}\" />\n";
7388 $html .= "<input name=\"gptekiyo[{$post_id}][{$sku_enc}]\" type=\"hidden\" id=\"gptekiyo[{$post_id}][{$sku_enc}]\" value=\"{$gptekiyo}\" />\n";
7389 $html .= "<input name=\"skuPrice[{$post_id}][{$sku_enc}]\" type=\"hidden\" id=\"skuPrice[{$post_id}][{$sku_enc}]\" value=\"{$skuPrice}\" />\n";
7390 if( 1 == $opt ){
7391 $html .= usces_item_option_fileds( $post_id, $sku, 1, 'return' );
7392 }elseif( 2 == $opt ){
7393 $html .= usces_item_option_fileds( $post_id, $sku, 0, 'return' );
7394 }
7395 if( $quant ){
7396 $quant_field = "<input name=\"quant[{$post_id}][" . $sku_enc . "]\" type=\"text\" id=\"quant[{$post_id}][" . $sku_enc . "]\" class=\"skuquantity\" value=\"\" onKeyDown=\"if (event.keyCode == 13) {return false;}\" />";
7397 $html .= apply_filters('usces_filter_sc_itemQuant', $quant_field, $mats);
7398 }
7399 $html .= "<input name=\"inCart[{$post_id}][{$sku_enc}]\" type=\"submit\" id=\"inCart[{$post_id}][{$sku_enc}]\" class=\"skubutton\" value=\"{$value}\" " . apply_filters('usces_filter_direct_intocart_button', NULL, $post_id, $sku, $force, $options) . " />";
7400 $html .= "<input name=\"usces_referer\" type=\"hidden\" value=\"" . $_SERVER['REQUEST_URI'] . "\" />\n";
7401 if( $force )
7402 $html .= "<input name=\"usces_force\" type=\"hidden\" value=\"incart\" />\n";
7403 $html = apply_filters('usces_filter_single_item_inform', $html);
7404 $html .= "</form>";
7405 $html .= '<div class="error_message">' . usces_singleitem_error_message($post_id, $sku, 'return') . '</div>'."\n";
7406
7407 return $html;
7408 }
7409
7410 function filter_itemPage($content){
7411 global $post;
7412 $html = '';
7413
7414 if( ($post->post_mime_type != 'item' || !is_single()) ) return $content;
7415 if( post_password_required($post) ) return $content;
7416
7417 $temp_path = apply_filters('usces_template_path_single_item', USCES_PLUGIN_DIR . '/templates/single_item.php');
7418 include( $temp_path );
7419
7420 $content = apply_filters('usces_filter_itemPage', $html, $post->ID);
7421
7422 return $content;
7423 }
7424
7425 function filter_cartContent($content) {
7426 global $post;
7427 $html = '';
7428
7429 switch($this->page){
7430 case 'cart':
7431 $temp_path = apply_filters('usces_template_path_cart', USCES_PLUGIN_DIR . '/templates/cart/cart.php');
7432 include( $temp_path );
7433 break;
7434 case 'customer':
7435 $temp_path = apply_filters('usces_template_path_customer', USCES_PLUGIN_DIR . '/templates/cart/customer_info.php');
7436 include( $temp_path );
7437 break;
7438 case 'delivery':
7439 $temp_path = apply_filters('usces_template_path_delivery', USCES_PLUGIN_DIR . '/templates/cart/delivery_info.php');
7440 include( $temp_path );
7441 break;
7442 case 'confirm':
7443 $temp_path = apply_filters('usces_template_path_confirm', USCES_PLUGIN_DIR . '/templates/cart/confirm.php');
7444 include( $temp_path );
7445 break;
7446 case 'ordercompletion':
7447 $temp_path = apply_filters('usces_template_path_ordercompletion', USCES_PLUGIN_DIR . '/templates/cart/completion.php');
7448 include( $temp_path );
7449 break;
7450 case 'error':
7451 $temp_path = apply_filters('usces_template_path_carterror', USCES_PLUGIN_DIR . '/templates/cart/error.php');
7452 include( $temp_path );
7453 break;
7454 case 'maintenance':
7455 $temp_path = apply_filters('usces_template_path_maintenance', USCES_PLUGIN_DIR . '/templates/cart/maintenance.php');
7456 include( $temp_path );
7457 break;
7458 case 'search_item':
7459 $temp_path = apply_filters('usces_template_path_search_item', USCES_PLUGIN_DIR . '/templates/search_item.php');
7460 include( $temp_path );
7461 break;
7462 case 'wp_search':
7463 if($post->post_mime_type == 'item'){
7464 $temp_path = apply_filters('usces_template_path_wp_search', USCES_PLUGIN_DIR . '/templates/wp_search_item.php');
7465 include( $temp_path );
7466 }else{
7467 $html = $content;
7468 }
7469 break;
7470 default:
7471 $html = $content;
7472 }
7473
7474 if( $this->use_ssl && ($this->is_cart_or_member_page($_SERVER['REQUEST_URI']) || $this->is_inquiry_page($_SERVER['REQUEST_URI'])) )
7475 $html = str_replace('src="'.get_option('siteurl'), 'src="'.USCES_SSL_URL_ADMIN, $html);
7476
7477 $html = apply_filters('usces_filter_cartContent', $html);
7478
7479 $content = $html;
7480
7481 remove_filter('the_title', array($this, 'filter_cartTitle'));
7482
7483 return $content;
7484 }
7485
7486 function filter_cartTitle($title) {
7487
7488 if( $title == 'Cart' || $title == __('Cart', 'usces') ){
7489 switch($this->page){
7490 case 'cart':
7491 $newtitle = apply_filters('usces_filter_title_cart', __('In the cart', 'usces'));
7492 break;
7493 case 'customer':
7494 $newtitle = apply_filters('usces_filter_title_customer', __('Customer Information', 'usces'));
7495 break;
7496 case 'delivery':
7497 $newtitle = apply_filters('usces_filter_title_delivery', __('Shipping / Payment options', 'usces'));
7498 break;
7499 case 'confirm':
7500 $newtitle = apply_filters('usces_filter_title_confirm', __('Confirmation', 'usces'));
7501 break;
7502 case 'ordercompletion':
7503 $newtitle = apply_filters('usces_filter_title_ordercompletion', __('Completion', 'usces'));
7504 break;
7505 case 'error':
7506 $newtitle = apply_filters('usces_filter_title_carterror', __('Error', 'usces'));
7507 break;
7508 case 'search_item':
7509 $newtitle = apply_filters('usces_filter_title_search_item', __("'AND' search by categories", 'usces'));
7510 break;
7511 case 'maintenance':
7512 $newtitle = apply_filters('usces_filter_title_maintenance', __('Under Maintenance', 'usces'));
7513 break;
7514 case 'login':
7515 $newtitle = apply_filters('usces_filter_title_login', __('Log-in for members', 'usces'));
7516 break;
7517 default:
7518 $newtitle = apply_filters('usces_filter_title_cart_default', $title);
7519 }
7520 }else{
7521 $newtitle = $title;
7522 }
7523
7524 $newtitle = apply_filters('usces_filter_cartTitle', $newtitle);
7525 return $newtitle;
7526 }
7527
7528 function action_cartFilter(){
7529 add_filter('the_title', array($this, 'filter_cartTitle'),20);
7530 add_filter('the_content', array($this, 'filter_cartContent'),20);
7531 }
7532
7533 function action_search_item(){
7534 include(TEMPLATEPATH . '/page.php');
7535 exit;
7536 }
7537
7538 function filter_memberContent($content) {
7539 global $post;
7540 $html = '';
7541
7542 if($this->options['membersystem_state'] == 'activate'){
7543
7544 if( $this->is_member_logged_in() ) {
7545
7546 $member_regmode = 'editmemberform';
7547 $temp_path = apply_filters('usces_template_path_member', USCES_PLUGIN_DIR . '/templates/member/member.php');
7548 include( $temp_path );
7549
7550 } else {
7551
7552 switch($this->page){
7553 case 'login':
7554 $temp_path = apply_filters('usces_template_path_login', USCES_PLUGIN_DIR . '/templates/member/login.php');
7555 include( $temp_path );
7556 break;
7557 case 'lostmemberpassword':
7558 $temp_path = apply_filters('usces_template_path_lostpassword', USCES_PLUGIN_DIR . '/templates/member/lostpassword.php');
7559 include( $temp_path );
7560 break;
7561 case 'changepassword':
7562 $temp_path = apply_filters('usces_template_path_changepassword', USCES_PLUGIN_DIR . '/templates/member/changepassword.php');
7563 include( $temp_path );
7564 break;
7565 case 'newcompletion':
7566 case 'editcompletion':
7567 case 'lostcompletion':
7568 case 'changepasscompletion':
7569 $temp_path = apply_filters('usces_template_path_membercompletion', USCES_PLUGIN_DIR . '/templates/member/completion.php');
7570 include( $temp_path );
7571 break;
7572 case 'newmemberform':
7573 $member_form_title = apply_filters('usces_filter_title_newmemberform', __('New enrollment form', 'usces'));
7574 $member_regmode = 'newmemberform';
7575 $temp_path = apply_filters('usces_template_path_member_form', USCES_PLUGIN_DIR . '/templates/member/member_form.php');
7576 include( $temp_path );
7577 break;
7578 default:
7579 $temp_path = apply_filters('usces_template_path_login', USCES_PLUGIN_DIR . '/templates/member/login.php');
7580 include( $temp_path );
7581 }
7582
7583 }
7584 }else{
7585 $html .= "<p>只今会員サービスは提供いたしておりません。</p>";
7586 }
7587
7588 $content = $html;
7589
7590 remove_filter('the_title', array($this, 'filter_memberTitle'));
7591
7592 return $content;
7593 }
7594
7595 function filter_memberTitle($title) {
7596
7597 if( $this->options['membersystem_state'] == 'activate' && ($title == 'Member' || $title == __('Membership', 'usces')) ){
7598 switch($this->page){
7599 case 'login':
7600 $newtitle = apply_filters('usces_filter_title_login', __('Log-in for members', 'usces'));
7601 break;
7602 case 'newmemberform':
7603 $newtitle = apply_filters('usces_filter_title_newmemberform', __('New enrollment form', 'usces'));
7604 break;
7605 case 'lostmemberpassword':
7606 $newtitle = apply_filters('usces_filter_title_lostmemberpassword', __('The new password acquisition', 'usces'));
7607 break;
7608 case 'changepassword':
7609 $newtitle = apply_filters('usces_filter_title_changepassword', __('Change password', 'usces'));
7610 break;
7611 case 'newcompletion':
7612 case 'editcompletion':
7613 case 'lostcompletion':
7614 case 'changepasscompletion':
7615 $newtitle = apply_filters('usces_filter_title_changepasscompletion', __('Completion', 'usces'));
7616 break;
7617 case 'error':
7618 $newtitle = apply_filters('usces_filter_title_membererror', __('Error', 'usces'));
7619 break;
7620 default:
7621 $newtitle = apply_filters('usces_filter_title_member_default', $title);
7622 }
7623 }else{
7624 $newtitle = $title;
7625 }
7626
7627 $newtitle = apply_filters('usces_filter_memberTitle', $newtitle);
7628 return $newtitle;
7629 }
7630
7631 function action_memberFilter(){
7632 add_filter('the_title', array($this, 'filter_memberTitle'),20);
7633 add_filter('the_content', array($this, 'filter_memberContent'),20);
7634 }
7635
7636 function filter_usces_cart_css(){
7637 $path = get_stylesheet_directory_uri() . '/usces_cart.css';
7638 return $path;
7639 }
7640
7641 function filter_divide_item(){
7642 global $wp_query;
7643
7644
7645 if( ($this->options['divide_item'] && !is_category() && !is_search() && !is_singular() && !is_admin()) ){
7646 $ids = $this->getItemIds( 'front' );
7647 $wp_query->query_vars['post__not_in'] = $ids;
7648
7649 }
7650 if( is_admin() ){
7651 $ids = $this->getItemIds( 'back' );
7652 //$wp_query->query_vars['category__not_in'] = array(USCES_ITEM_CAT_PARENT_ID);
7653 $wp_query->query_vars['post__not_in'] = $ids;
7654 }
7655 do_action( 'usces_action_divide_item');
7656 }
7657
7658 function load_upload_template(){
7659 $post_id = $_POST['post_id'];
7660 $file = 'upload_template01.php';
7661 include(TEMPLATEPATH . '/' . $file);
7662 exit;
7663 }
7664
7665 function filter_itemimg_anchor_rel($html){
7666
7667 if( is_single() ){
7668 $str = ' rel="' . $this->options['itemimg_anchor_rel'] . '"';
7669 }else{
7670 $str = '';
7671 }
7672 return $html . $str;
7673 }
7674
7675 function filter_permalink( $link ) {
7676
7677 if(false !== strpos('?page_id=4', $link) || false !== strpos('?page_id=3', $link) || false !== strpos('usces-cart', $link) || false !== strpos('usces-member', $link) )
7678 $link = str_replace('http://', 'https://', $link);
7679
7680 return $link;
7681 }
7682
7683 function filter_cart_page_header($html){
7684 if( !empty($this->options['cart_page_data']['header']['cart']) ){
7685 $html = $this->options['cart_page_data']['header']['cart'];
7686 }
7687 return do_shortcode( stripslashes(nl2br($html)) );
7688 }
7689
7690 function filter_cart_page_footer($html){
7691 if( !empty($this->options['cart_page_data']['footer']['cart']) ){
7692 $html = $this->options['cart_page_data']['footer']['cart'];
7693 }
7694 return do_shortcode( stripslashes(nl2br($html)) );
7695 }
7696
7697 function filter_customer_page_header($html){
7698 if( !empty($this->options['cart_page_data']['header']['customer']) ){
7699 $html = $this->options['cart_page_data']['header']['customer'];
7700 }
7701 return do_shortcode( stripslashes(nl2br($html)) );
7702 }
7703
7704 function filter_customer_page_footer($html){
7705 if( !empty($this->options['cart_page_data']['footer']['customer']) ){
7706 $html = $this->options['cart_page_data']['footer']['customer'];
7707 }
7708 return do_shortcode( stripslashes(nl2br($html)) );
7709 }
7710
7711 function filter_delivery_page_header($html){
7712 if( !empty($this->options['cart_page_data']['header']['delivery']) ){
7713 $html = $this->options['cart_page_data']['header']['delivery'];
7714 }
7715 return do_shortcode( stripslashes(nl2br($html)) );
7716 }
7717
7718 function filter_delivery_page_footer($html){
7719 if( !empty($this->options['cart_page_data']['footer']['delivery']) ){
7720 $html = $this->options['cart_page_data']['footer']['delivery'];
7721 }
7722 return do_shortcode( stripslashes(nl2br($html)) );
7723 }
7724
7725 function filter_confirm_page_header($html){
7726 if( !empty($this->options['cart_page_data']['header']['confirm']) ){
7727 $html = $this->options['cart_page_data']['header']['confirm'];
7728 }
7729 return do_shortcode( stripslashes(nl2br($html)) );
7730 }
7731
7732 function filter_confirm_page_footer($html){
7733 if( !empty($this->options['cart_page_data']['footer']['confirm']) ){
7734 $html = $this->options['cart_page_data']['footer']['confirm'];
7735 }
7736 return do_shortcode( stripslashes(nl2br($html)) );
7737 }
7738
7739 function filter_cartcompletion_page_header($html){
7740 if( !empty($this->options['cart_page_data']['header']['completion']) ){
7741 $html = $this->options['cart_page_data']['header']['completion'];
7742 }
7743 return do_shortcode( stripslashes(nl2br($html)) );
7744 }
7745
7746 function filter_cartcompletion_page_footer($html){
7747 if( !empty($this->options['cart_page_data']['footer']['completion']) ){
7748 $html = $this->options['cart_page_data']['footer']['completion'];
7749 }
7750 return do_shortcode( stripslashes(nl2br($html)) );
7751 }
7752
7753 function filter_login_page_header($html){
7754 if( !empty($this->options['member_page_data']['header']['login']) ){
7755 $html = $this->options['member_page_data']['header']['login'];
7756 }
7757 return do_shortcode( stripslashes(nl2br($html)) );
7758 }
7759
7760 function filter_login_page_footer($html){
7761 if( !empty($this->options['member_page_data']['footer']['login']) ){
7762 $html = $this->options['member_page_data']['footer']['login'];
7763 }
7764 return do_shortcode( stripslashes(nl2br($html)) );
7765 }
7766
7767 function filter_newmember_page_header($html){
7768 if( !empty($this->options['member_page_data']['header']['newmember']) ){
7769 $html = $this->options['member_page_data']['header']['newmember'];
7770 }
7771 return do_shortcode( stripslashes(nl2br($html)) );
7772 }
7773
7774 function filter_newmember_page_footer($html){
7775 if( !empty($this->options['member_page_data']['footer']['newmember']) ){
7776 $html = $this->options['member_page_data']['footer']['newmember'];
7777 }
7778 return do_shortcode( stripslashes(nl2br($html)) );
7779 }
7780
7781 function filter_newpass_page_header($html){
7782 if( !empty($this->options['member_page_data']['header']['newpass']) ){
7783 $html = $this->options['member_page_data']['header']['newpass'];
7784 }
7785 return do_shortcode( stripslashes(nl2br($html)) );
7786 }
7787
7788 function filter_newpass_page_footer($html){
7789 if( !empty($this->options['member_page_data']['footer']['newpass']) ){
7790 $html = $this->options['member_page_data']['footer']['newpass'];
7791 }
7792 return do_shortcode( stripslashes(nl2br($html)) );
7793 }
7794
7795 function filter_changepass_page_header($html){
7796 if( !empty($this->options['member_page_data']['header']['changepass']) ){
7797 $html = $this->options['member_page_data']['header']['changepass'];
7798 }
7799 return do_shortcode( stripslashes(nl2br($html)) );
7800 }
7801
7802 function filter_changepass_page_footer($html){
7803 if( !empty($this->options['member_page_data']['footer']['changepass']) ){
7804 $html = $this->options['member_page_data']['footer']['changepass'];
7805 }
7806 return do_shortcode( stripslashes(nl2br($html)) );
7807 }
7808
7809 function filter_memberinfo_page_header($html){
7810 if( !empty($this->options['member_page_data']['header']['memberinfo']) ){
7811 $html = $this->options['member_page_data']['header']['memberinfo'];
7812 }
7813 return do_shortcode( stripslashes(nl2br($html)) );
7814 }
7815
7816 function filter_memberinfo_page_footer($html){
7817 if( !empty($this->options['member_page_data']['footer']['memberinfo']) ){
7818 $html = $this->options['member_page_data']['footer']['memberinfo'];
7819 }
7820 return do_shortcode( stripslashes(nl2br($html)) );
7821 }
7822
7823 function filter_membercompletion_page_header($html){
7824 if( !empty($this->options['member_page_data']['header']['completion']) ){
7825 $html = $this->options['member_page_data']['header']['completion'];
7826 }
7827 return do_shortcode( stripslashes(nl2br($html)) );
7828 }
7829
7830 function filter_membercompletion_page_footer($html){
7831 if( !empty($this->options['member_page_data']['footer']['completion']) ){
7832 $html = $this->options['member_page_data']['footer']['completion'];
7833 }
7834 return do_shortcode( stripslashes(nl2br($html)) );
7835 }
7836
7837 function action_cart_page_header(){
7838 if( !empty($this->options['cart_page_data']['header']['cart']) ){
7839 $html = $this->options['cart_page_data']['header']['cart'];
7840 echo do_shortcode( stripslashes(nl2br($html)) );
7841 }
7842 }
7843
7844 function action_cart_page_footer(){
7845 if( !empty($this->options['cart_page_data']['footer']['cart']) ){
7846 $html = $this->options['cart_page_data']['footer']['cart'];
7847 echo do_shortcode( stripslashes(nl2br($html)) );
7848 }
7849 }
7850
7851 function action_customer_page_header(){
7852 if( !empty($this->options['cart_page_data']['header']['customer']) ){
7853 $html = $this->options['cart_page_data']['header']['customer'];
7854 echo do_shortcode( stripslashes(nl2br($html)) );
7855 }
7856 }
7857
7858 function action_customer_page_footer(){
7859 if( !empty($this->options['cart_page_data']['footer']['customer']) ){
7860 $html = $this->options['cart_page_data']['footer']['customer'];
7861 echo do_shortcode( stripslashes(nl2br($html)) );
7862 }
7863 }
7864
7865 function action_delivery_page_header(){
7866 if( !empty($this->options['cart_page_data']['header']['delivery']) ){
7867 $html = $this->options['cart_page_data']['header']['delivery'];
7868 echo do_shortcode( stripslashes(nl2br($html)) );
7869 }
7870 }
7871
7872 function action_delivery_page_footer(){
7873 if( !empty($this->options['cart_page_data']['footer']['delivery']) ){
7874 $html = $this->options['cart_page_data']['footer']['delivery'];
7875 echo do_shortcode( stripslashes(nl2br($html)) );
7876 }
7877 }
7878
7879 function action_confirm_page_header(){
7880 if( !empty($this->options['cart_page_data']['header']['confirm']) ){
7881 $html = $this->options['cart_page_data']['header']['confirm'];
7882 echo do_shortcode( stripslashes(nl2br($html)) );
7883 }
7884 }
7885
7886 function action_confirm_page_footer(){
7887 if( !empty($this->options['cart_page_data']['footer']['confirm']) ){
7888 $html = $this->options['cart_page_data']['footer']['confirm'];
7889 echo do_shortcode( stripslashes(nl2br($html)) );
7890 }
7891 }
7892
7893 function action_cartcompletion_page_header(){
7894 if( !empty($this->options['cart_page_data']['header']['completion']) ){
7895 $html = $this->options['cart_page_data']['header']['completion'];
7896 echo do_shortcode( stripslashes(nl2br($html)) );
7897 }
7898 }
7899
7900 function action_cartcompletion_page_footer(){
7901 if( !empty($this->options['cart_page_data']['footer']['completion']) ){
7902 $html = $this->options['cart_page_data']['footer']['completion'];
7903 echo do_shortcode( stripslashes(nl2br($html)) );
7904 }
7905 }
7906
7907 function action_login_page_header(){
7908 if( !empty($this->options['member_page_data']['header']['login']) ){
7909 $html = $this->options['member_page_data']['header']['login'];
7910 echo do_shortcode( stripslashes(nl2br($html)) );
7911 }
7912 }
7913
7914 function action_login_page_footer(){
7915 if( !empty($this->options['member_page_data']['footer']['login']) ){
7916 $html = $this->options['member_page_data']['footer']['login'];
7917 echo do_shortcode( stripslashes(nl2br($html)) );
7918 }
7919 }
7920
7921 function action_newmember_page_header(){
7922 if( !empty($this->options['member_page_data']['header']['newmember']) ){
7923 $html = $this->options['member_page_data']['header']['newmember'];
7924 echo do_shortcode( stripslashes(nl2br($html)) );
7925 }
7926 }
7927
7928 function action_newmember_page_footer(){
7929 if( !empty($this->options['member_page_data']['footer']['newmember']) ){
7930 $html = $this->options['member_page_data']['footer']['newmember'];
7931 echo do_shortcode( stripslashes(nl2br($html)) );
7932 }
7933 }
7934
7935 function action_newpass_page_header(){
7936 if( !empty($this->options['member_page_data']['header']['newpass']) ){
7937 $html = $this->options['member_page_data']['header']['newpass'];
7938 echo do_shortcode( stripslashes(nl2br($html)) );
7939 }
7940 }
7941
7942 function action_newpass_page_footer(){
7943 if( !empty($this->options['member_page_data']['footer']['newpass']) ){
7944 $html = $this->options['member_page_data']['footer']['newpass'];
7945 echo do_shortcode( stripslashes(nl2br($html)) );
7946 }
7947 }
7948
7949 function action_changepass_page_header(){
7950 if( !empty($this->options['member_page_data']['header']['changepass']) ){
7951 $html = $this->options['member_page_data']['header']['changepass'];
7952 echo do_shortcode( stripslashes(nl2br($html)) );
7953 }
7954 }
7955
7956 function action_changepass_page_footer(){
7957 if( !empty($this->options['member_page_data']['footer']['changepass']) ){
7958 $html = $this->options['member_page_data']['footer']['changepass'];
7959 echo do_shortcode( stripslashes(nl2br($html)) );
7960 }
7961 }
7962
7963 function action_memberinfo_page_header(){
7964 if( !empty($this->options['member_page_data']['header']['memberinfo']) ){
7965 $html = $this->options['member_page_data']['header']['memberinfo'];
7966 echo do_shortcode( stripslashes(nl2br($html)) );
7967 }
7968 }
7969
7970 function action_memberinfo_page_footer(){
7971 if( !empty($this->options['member_page_data']['footer']['memberinfo']) ){
7972 $html = $this->options['member_page_data']['footer']['memberinfo'];
7973 echo do_shortcode( stripslashes(nl2br($html)) );
7974 }
7975 }
7976
7977 function action_membercompletion_page_header(){
7978 if( !empty($this->options['member_page_data']['header']['completion']) ){
7979 $html = $this->options['member_page_data']['header']['completion'];
7980 echo do_shortcode( stripslashes(nl2br($html)) );
7981 }
7982 }
7983
7984 function action_membercompletion_page_footer(){
7985 if( !empty($this->options['member_page_data']['footer']['completion']) ){
7986 $html = $this->options['member_page_data']['footer']['completion'];
7987 echo do_shortcode( stripslashes(nl2br($html)) );
7988 }
7989 }
7990
7991 }
7992 ?>
7993