han_paysubscriptions.php
来自「sabreipb 2.1.6 utf-8中文版本!」· PHP 代码 · 共 1,216 行 · 第 1/4 页
PHP
1,216 行
$this->update['subtrans_member_id'] = $this->member['id']; $this->update['subtrans_old_group'] = $this->member['mgroup']; $this->update['subtrans_start_date'] = time(); //-------------------------------------- // Deal with lifetime subs //-------------------------------------- if ( $this->new_sub['sub_unit'] == 'x' ) { $this->update['subtrans_end_date'] = 9999999999; } else { $this->update['subtrans_end_date'] = time() + ( $this->new_sub['sub_length'] * $this->day_to_seconds[ $this->new_sub['sub_unit'] ] ); } //-------------------------------------- // Just updating a subscription //-------------------------------------- if ( $this->results['current_package_id'] ) { $subid = $this->ipsclass->DB->build_and_exec_query( array( 'select' => '*', 'from' => 'subscription_trans', 'where' => "subtrans_subscrid='".addslashes($this->update['subtrans_subscrid'])."'" ) ); if ( $subid['subtrans_id'] ) { //-------------------------------------- // Okay, existing subscription we're updating, so... //-------------------------------------- unset($this->update['subtrans_start_date']); unset($this->update['subtrans_end_date']); unset($this->update['subtrans_old_group']); unset($this->update['subtrans_cumulative']); $this->ipsclass->DB->do_update( 'subscription_trans', $this->update, "subtrans_subscrid='".addslashes($this->update['subtrans_subscrid'])."'" ); } } else { $this->ipsclass->DB->do_insert( 'subscription_trans', $this->update ); $newid = $this->ipsclass->DB->get_insert_id(); //-------------------------------------- // Mark all old subs as dead //-------------------------------------- $this->ipsclass->DB->do_update( 'subscription_trans', array( 'subtrans_state' => 'dead' ), "subtrans_state='paid' AND subtrans_member_id={$this->member['id']} AND subtrans_id != $newid" ); } //-------------------------------------- // UPDATE MEMBERS //-------------------------------------- if ( $this->update['subtrans_state'] == 'paid' ) { $this->do_paid_member($this->new_sub, $this->member, $subid['subtrans_id']); $this->do_log("{$this->class_gateway->i_am}: Subscription started. Set trans_id {$this->cur_details['subtrans_id']} to {$this->update['subtrans_state']}, paid {$this->update['subtrans_paid']}"); } else { $this->do_failed_member($this->new_sub, $this->member, $subid['subtrans_id']); $this->do_log("{$this->class_gateway->i_am}: Subscription FAILED. Set trans_id {$this->cur_details['subtrans_id']} to {$this->update['subtrans_state']}, paid {$this->update['subtrans_paid']}"); } } /*-------------------------------------------------------------------------*/ // PAID MEMBER UPGRADE YEAH BABY /*-------------------------------------------------------------------------*/ function do_paid_member($new_sub, $member, $cur_trx_id="") { //-------------------------------------- // INIT //-------------------------------------- $end_date = 0; $email_end_date = 0; //-------------------------------------- // Make sure we have enough member info //-------------------------------------- if ( ! $member['email'] ) { $member = $this->ipsclass->DB->build_and_exec_query( array( 'select' => '*', 'from' => 'members', 'where' => 'id='.intval($member['id']) ) ); } define( 'IPB_CALLED', 1 ); //-------------------------------------- // Lifetime... //-------------------------------------- if ( $new_sub['sub_unit'] == 'x' ) { $end_date = 9999999999; $email_end_date = $this->ipsclass->lang['no_expire']; } else { if ( $cur_trx_id ) { //-------------------------------------- // Upgrading... //-------------------------------------- $end_date = 'sub_end'; $email_end_date = $this->ipsclass->get_date( $member['sub_end'], 'DATE' ); } else { //-------------------------------------- // New... //-------------------------------------- $end_date = time() + ( $new_sub['sub_length'] * $this->class_gateway->day_to_seconds[ $new_sub['sub_unit'] ] ); $email_end_date = $this->ipsclass->get_date( $end_date, 'DATE' ); } } $query = "UPDATE ibf_members SET sub_end=$end_date"; if ( $new_sub['sub_new_group'] ) { $query .= ", mgroup={$new_sub['sub_new_group']}"; } $query .= " WHERE id={$member['id']}"; $this->ipsclass->DB->query($query); //-------------------------------------- // Running Custom code? //-------------------------------------- $name = preg_replace( "/[^a-zA-Z0-9\-\_]/", "" , $new_sub['sub_run_module'] ); if ( $name != "" ) { if ( @file_exists( ROOT_PATH . 'sources/classes/paymentgateways/custom/cus_'.$name.'.php' ) ) { require_once( ROOT_PATH . 'sources/classes/paymentgateways/custom/cus_'.$name.'.php' ); $this->customsubs = new customsubs(); $this->customsubs->subs_paid($new_sub, $member, $cur_trx_id); } } //-------------------------------------- // Running IPB custom code? //-------------------------------------- if ( USE_MODULES == 1 ) { require ROOT_PATH."modules/ipb_member_sync.php"; $this->modules = new ipb_member_sync(); $this->modules->register_class($this); $this->modules->on_group_change($member['id'], $new_sub['sub_new_group']); } //-------------------------------------- // Send an email? //-------------------------------------- require_once( ROOT_PATH."sources/classes/class_email.php" ); $this->email = new emailer(); $this->email->ipsclass =& $this->ipsclass; $this->email->email_init(); $this->email->get_template("new_subscription"); $this->email->build_message( array( 'PACKAGE' => $new_sub['sub_title'], 'EXPIRES' => $email_end_date, 'LINK' => $this->ipsclass->vars['board_url'].'/index.'.$this->ipsclass->vars['php_ext'].'?act=paysubs&CODE=index', ) ); $this->email->to = trim( $member['email'] ); $this->email->send_mail(); } /*-------------------------------------------------------------------------*/ // FAILED MEMBER UPGRADE YEAH BABY /*-------------------------------------------------------------------------*/ function do_failed_member($new_sub, $member, $cur_trx_id="") { define( 'IPB_CALLED', 1 ); $query = "UPDATE ibf_members SET sub_end=0"; if ( $cur_trx_id ) { $this->ipsclass->DB->cache_add_query( 'mod_failed_member', array( 'cur_trx_id' => $cur_trx_id ), 'sql_subsm_queries' ); $this->ipsclass->DB->cache_exec_query(); $r = $this->ipsclass->DB->fetch_row(); $mgroup = $r['g_id'] ? $r['g_id'] : $this->ipsclass->vars['member_group']; $query .= ", mgroup={$mgroup}"; } $query .= " WHERE id={$member['id']}"; $this->ipsclass->DB->query($query); //-------------------------------------- // Running Custom code? //-------------------------------------- $name = preg_replace( "/[^a-zA-Z0-9\-\_]/", "" , $new_sub['sub_run_module'] ); if ( $name != "" ) { if ( @file_exists( ROOT_PATH . 'sources/classes/paymentgateways/custom/cus_'.$name.'.php' ) ) { require_once( ROOT_PATH . 'sources/classes/paymentgateways/custom/cus_'.$name.'.php' ); $this->customsubs = new customsubs(); $this->customsubs->subs_failed($new_sub, $member, $cur_trx_id); } } //-------------------------------------- // Running IPB custom code? //-------------------------------------- if ( USE_MODULES == 1 ) { require ROOT_PATH."modules/ipb_member_sync.php"; $this->modules = new ipb_member_sync(); $this->modules->register_class($this); $this->modules->on_group_change($member['id'], $mgroup); } } /*-------------------------------------------------------------------------*/ // Captains log: Unix date: 1002343439 /*-------------------------------------------------------------------------*/ function do_log($msg) { $extra = ""; foreach( $_POST as $k => $v ) { if ( $k == 'ccnum' ) { $v = 'xxxx xxxx xxxx xxxx'; } else if ( $k == 'ccid' ) { $v = 'xxx'; } $extra .= "\n$k = $v;"; } if ( is_array( $_GET ) ) { foreach( $_GET as $k => $v ) { if ( $k == 'ccnum' ) { $v = 'xxxx xxxx xxxx xxxx'; } else if ( $k == 'ccid' ) { $v = 'xxx'; } $extra .= "\n$k = $v;"; } } //-------------------------------------- // Add to DB //-------------------------------------- $this->ipsclass->DB->do_insert( 'subscription_logs', array( 'sublog_date' => time(), 'sublog_data' => $msg, 'sublog_ipaddress' => $this->ip_address, 'sublog_postdata' => $extra ) ); //-------------------------------------- // Debug? //-------------------------------------- $this->class_gateway->_write_debug_message( "MSG:\n$msg\nPost contents\n$extra\n" ); } }?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?