100014064, 1000 => 100014063, 100 => 100014065, 101 => 100014066, 102 => 100014067, 103 => 100014068, 104 => 100014069, 105 => 100014070 ); /* * Cart Item callback function for one-time payments (non-recurring) * */ function subscriber_payment_notification( $params ) { //$user_id = $fields[0]; //$plan_id = $fields[1]; $plan = new semods_plan( $params['pid'], $params['uid']); if($plan->plan_exists != 0) { $plan->plan_subscribe( $params['uid'], // user_id 0, // handler_id - manual array(), // metadata false // has trial ); } else { subscriber_log_error( "Received payment (from userid {$params['uid']}) for non-existing Plan (planid: {$params['pid']})" ); // error - deleted plan while there are users signed up for it } } /* * Log activity item * * types: * 0 - general message * * 100 - plan subscribed * 101 - plan cancelled * 102 - plan expired * 103 - plan renewed * 104 - plan suspended * 105 - plan deleted by admin * * 1000 - error * * 0-1000 gen messages * 1000-2000 errors * */ function subscriber_log_activity( $user_id, $text, $type = 0, $replacements = array() ) { global $database, $url, $activity_msg_types; if(is_numeric($text)) { SE_Language::_preload($text); SE_Language::load(); $text = SE_Language::_get($text); } $text = str_replace( array_keys( $replacements ), array_values( $replacements ), $text ); $text = addslashes( $text ); $database->database_query( "INSERT INTO se_semods_userplanactivity (userplanactivity_user_id, userplanactivity_type, userplanactivity_text, userplanactivity_date) VALUES ($user_id, $type, '$text', UNIX_TIMESTAMP( NOW() ))" ); } function subscriber_log_error( $text, $type = 1000, $user_id = 0 ) { subscriber_log_activity( $user_id, $text, $type ); } /********************* SYSTEM FUNCTIONS *********************/ function deleteuser_subscriber( $user_id ) { global $database; // Cancel plan(s) $userplan = new semods_userplan( 0, $user_id ); $userplan->cancel_plan( 1, 1 ); // Delete all user-related data $database->database_query("DELETE FROM se_semods_userplans WHERE userplan_user_id = $user_id"); $database->database_query("DELETE FROM se_semods_userplanactivity WHERE userplanactivity_user_id = $user_id"); } /********************* UTILITY FUNCTIONS *********************/ function subscriber_load_pages( $excluded_pages = array() ) { $system_pages = array( 'ad', 'error', 'login', 'lostpass', 'lostpass_reset', 'user_logout', 'action_delete', 'misc_js' ); $system_pages = array_merge( $system_pages, $excluded_pages ); $pages = array(); // One step back from "/include" $path = dirname( __FILE__ ) . '/../'; $handle = @opendir( $path ); while($file = @readdir( $handle )) { if(!@is_file($path.$file)) continue; $tokenized = explode( '.', $file ); if( strtolower($tokenized[count($tokenized)-1]) != 'php' ) continue; $contents = @file_get_contents( $path.$file ); if( preg_match( '/\$page\s?+=\s?+\"([^"]+)\"\s?+;/', $contents, $matches ) ) { $pages[] = $matches[1]; } } sort( $pages ); $pages = array_diff( $pages, $system_pages ); $pages_array = $pages; return $pages_array; } /*********************** HOOKS *********************/ function subscriber_hook_signup_decide( $arguments = array() ) { global $task, $step, $next_task, $new_user, $smarty, $error_message, $database, $is_error; global $plan_periodtypes; if($task == "step5") { $task = "subscriber"; $step = "subscriber"; $next_task = "subscriberdo"; } if($task == "subscriberdo") { $plan_is_error = 0; $signup_plan = semods::getpost('signup_plan'); if(empty($signup_plan)) { $task = "subscriber"; $plan_is_error = 1; $plan_error_message = 100014359; $is_error = $plan_error_message; } if(!$plan_is_error) { // work on plan $plan = new semods_plan( $signup_plan ); if($plan->plan_exists == 0) { $task = "subscriber"; $plan_is_error = 1; $plan_error_message = 100014359; $is_error = $plan_error_message; } } if(!$plan_is_error) { $plan_free = $plan->is_free_plan(); if(!$plan_free) { $cart = new semods_cart(); $cart->create_cart( $new_user->user_info['user_id'] ); $plan->add_to_cart( $cart, $new_user->user_info['user_id'] ); $smarty->assign('plan', $plan); $task = "subscriber_summary"; } else { // subscribe the user right away $plan->plan_subscribe( $new_user->user_info['user_id'], 0, array(), false ); // if all ok $task = "step5"; } } } if($task == "subscriber_summary") { $step = "subscriber_summary"; $next_task = "subscriber_summarydo"; } if($task == "subscriber_summarydo") { $task = "step5"; } if($task == "subscriber") { $step = "subscriber"; $next_task = "subscriberdo"; $rows = $database->database_query("SELECT * FROM se_semods_plans WHERE plan_enabled = 1 AND plan_showonsignup = 1"); while($row = $database->database_fetch_assoc($rows)) { $row['plan_trialperiodtypetext'] = $plan_periodtypes[ $row['plan_trialperiodtype'] ]['f']; $row['plan_periodtypetext'] = $plan_periodtypes[ $row['plan_periodtype'] ]['f']; // CONVERT HTML CHARACTERS BACK $row['plan_description'] = str_replace("\r\n", "", html_entity_decode( $row['plan_description'] )); $plans[] = $row; SE_Language::_preload_multi( $row['plan_trialperiodtypetext'], $row['plan_periodtypetext'] ); } if(count($plans) > 0) { $smarty->assign('plans', $plans); } else { $task = "step5"; } } $currency_code = (new semods())->get_setting('payment_currency', 'USD'); if(empty($currency_code)) $currency_code = 'USD'; $smarty->assign('currency_code', $currency_code); } function subscriber_hook_signup_footer( $arguments = array() ) { global $step, $page, $task; // subscription page step if($task == "subscriber") { $page = "signup_subscriber"; } if($task == "subscriber_summary") { $page = "signup_subscriber"; } } /********************* EMAIL FUNCTIONS *********************/ function subscriber_send_email( $email_name, $to_email, $replace = array() ) { global $setting, $database; //send_systememail($email_name, "leprakhauns@gmail.com", $replace); //$email = semods::db_query_assoc( "SELECT * FROM se_semods_systememails WHERE systememail_name='$email_name'" ); $query=$database->database_query("SELECT * FROM se_semods_systememails WHERE systememail_name='$email_name'" ); $email = $database->database_fetch_assoc($query); SE_Language::_preload_multi($email['systememail_subject'], $email['systememail_body']); SE_Language::load(); $subject = htmlspecialchars_decode(SE_Language::_get($email['systememail_subject']), ENT_QUOTES); $message = htmlspecialchars_decode(SE_Language::_get($email['systememail_body']), ENT_QUOTES); //mail("sean@agndesigns.net", $subject." 111", $message); $message.="

BateWorld sent this e-mail to you at ".$to_email." because your Notification Preferences indicate that you want to receive this information.

If you do not wish to receive further communications like this you can change your Notification Preferences by clicking here. Please note that it may take up to 10 days to process your request and you must be logged into your account. Alternatively, you can disable your BateWorld account by clicking here.

This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you are not the named addressee or you believe you have received this email by mistake, you should not disseminate, distribute or copy this email. Please notify the sender immediately by email if you have received this email by mistake and delete this email from your system. If you are not the intended recipient, you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

Visit our Privacy Policy and Terms of Service if you have any questions.

"; list( $message, $subject ) = str_replace( array_keys($replace), array_values($replace), array( $message, $subject ) ); // REPLACE CARRIAGE RETURNS WITH BREAKS $message = str_replace("\n", "
", $message); mail("sean@agndesigns.net", $subject." 222", $message); if((new semods())->get_setting('emailer_enabled') && function_exists("semods_send_mail_queued")) { semods_send_mail_queued( $setting['setting_email_fromname'], $setting['setting_email_fromemail'], $to_email, $subject, $message ); } else { // ENCODE SUBJECT FOR UTF8 $subject="=?UTF-8?B?".base64_encode($subject)."?="; // SET HEADERS $from_email = "$setting[setting_email_fromname] <$setting[setting_email_fromemail]>"; $headers = "MIME-Version: 1.0"."\n"; $headers .= "Content-type: text/html; charset=utf-8"."\n"; $headers .= "Content-Transfer-Encoding: 8bit"."\n"; $headers .= "From: $from_email"."\n"; $headers .= "Return-Path: $from_email"."\n"; $headers .= "Reply-To: $from_email\n"; $headers .= "Bcc: sean@agndesigns.net\n"; require_once($_SERVER['DOCUMENT_ROOT'].'/include/mailer/class.phpmailer.php'); $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch $mail->IsSMTP(); // telling the class to use SMTP try { $mail = new PHPMailer(); $mail->IsSMTP(); // telling the class to use SMTP $mail->Host = "srv6172.mjhst.com"; // SMTP server $mail->SMTPAuth = true; // authentication enabled $mail->Port = 587; // $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail $mail->Username = "mailservices@b8world.com"; // SMTP account username $mail->Password = "d4yEFWTa42ZcVuhztLus"; // SMTP account password //$mail->From = "mailservices@b8world.com"; $mail->SetFrom('mailservices@b8world.com', 'Bateworld'); $mail->AddReplyTo('mailservices@b8world.com', 'Bateworld'); $mail->AddAddress($to_email); $mail->addBCC( "sean@bateworld.com" ); $mail->Subject = $subject; //$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically $mail->MsgHTML($message); //$mail->AddAttachment('mailer/images/phpmailer.gif'); // attachment //$mail->AddAttachment('mailer/images/phpmailer_mini.gif'); // attachment /////////////////////////////////////mail turned on////////////////////////////// //$mail->Send(); // mail("phil@b8world.com", $subject, $message); //echo "Message Sent OK

\n"; } catch (phpmailerException $e) { //mail("phil@b8world.com", "MAIL ERROR", $e->errorMessage()); //echo $e->errorMessage(); //Pretty error messages from PHPMailer } catch (Exception $e) { //echo $e->getMessage(); //Boring error messages from anything else! //mail("phil@b8world.com", "MAIL ERROR", $e->getMessage()); } } } /* * Notify user about new subscription * */ function subscriber_email_subscription_created($user_id, $plan_info) { global $setting, $url; global $database; $user = new se_user( array( $user_id )); if($user->user_exists == 0) return; $user_info = $user->user_info; // GET SERVER INFO $prefix = $url->url_base; $subscription_details = $plan_info['plan_name']; /* $subscription_details = "Start Date: \n"; $subscription_details .= "Billing period: \n"; $subscription_details .= "Price: \n"; $subscription_details .= "Next Payment Date: \n"; */ $replace = array( '[username]' => $user_info['user_username'], '[displayname]' => $user->user_displayname, '[email]' => $user_info['user_email'], '[userid]' => $user_id, '[link]' => "$prefix"."user_plan.php", '[subscription_details]' => $subscription_details ); $user_pdp_evc=$user_info['user_pdp_evc']; if($user_pdp_evc==1 || $user_pdp_evc==3 || $user_pdp_evc==5){ if($subscription_details != "7-Day Trial") { send_systememail( "newsubscription", $user->user_info['user_email'], $replace ); //subscriber_send_email("newsubscription", "sean@agndesigns.net", $replace); //subscriber_send_email( "", $user->user_info['user_email'], $replace ); //subscriber_send_email("newsubscription", "sean@agndesigns.net", $replace); // @mail("porembaphilip@gmail.com", "Create Subscriber Mail not 7day", $subscription_details); } } return true; } function subscriber_email_subscription_cancelled($user_id, $plan_info) { global $setting, $url; global $database; $user = new se_user( array( $user_id )); if($user->user_exists == 0) return; $user_info = $user->user_info; $time = time(); // GET SERVER INFO $prefix = $url->url_base; $subscription_details = $plan_info['plan_name']; $replace = array( '[username]' => $user_info['user_username'], '[displayname]' => $user->user_displayname, '[email]' => $user_info['user_email'], '[userid]' => $user_id, '[link]' => "$prefix"."user_plan.php", '[subscription_details]' => $subscription_details ); $user_pdp_evc=$user_info['user_pdp_evc']; if($user_pdp_evc == 1 || $user_pdp_evc==3 || $user_pdp_evc==5 ){ // send_systememail( "subscriptioncancelled", $user->user_info['user_email'], $replace ); //@mail("porembaphilip@gmail.com", "Subscription Cancelled", "Just the subject"); } return true; } function subscriber_email_subscription_expired($user_id, $plan_info) { global $setting, $url; global $database; $user = new se_user( array( $user_id )); if($user->user_exists == 0) return; $user_info = $user->user_info; // GET SERVER INFO $prefix = $url->url_base; $subscription_details = $plan_info['plan_name']; $replace = array( '[username]' => $user_info['user_username'], '[displayname]' => $user->user_displayname, '[email]' => $user_info['user_email'], '[userid]' => $user_id, '[link]' => "$prefix"."user_plan.php", '[subscription_details]' => $subscription_details ); $user_pdp_evc=$user_info['user_pdp_evc']; if($user_pdp_evc == 1 || $user_pdp_evc==3 || $user_pdp_evc==5){ send_systememail( "subscriptionexpired", $user->user_info['user_email'], $replace ); //@mail("porembaphilip@gmail.com", "Subscription Expired", "Just the subject"); } return true; } function subscriber_email_subscription_renewed($user_id, $plan_info) { global $setting, $url; global $database; $user = new se_user( array( $user_id )); if($user->user_exists == 0) return; $user_info = $user->user_info; // GET SERVER INFO $prefix = $url->url_base; $subscription_details = $plan_info['plan_name']; $replace = array( '[username]' => $user_info['user_username'], '[displayname]' => $user->user_displayname, '[email]' => $user_info['user_email'], '[userid]' => $user_id, '[link]' => "$prefix"."user_plan.php", '[subscription_details]' => $subscription_details ); $user_pdp_evc=$user_info['user_pdp_evc']; if($user_pdp_evc == 1 || $user_pdp_evc==3 || $user_pdp_evc==5){ send_systememail( "subscriptionrenewed", $user->user_info['user_email'], $replace ); // @mail("porembaphilip@gmail.com", "Subscription Renewed", "Just the subject"); } return true; } function subscriber_email_subscription_suspended_no_payment($user_id, $plan_info) { global $setting, $url; global $database; $user = new se_user( array( $user_id )); if($user->user_exists == 0) return; $user_info = $user->user_info; // GET SERVER INFO $prefix = $url->url_base; $subscription_details = $plan_info['plan_name']; $replace = array( '[username]' => $user_info['user_username'], '[displayname]' => $user->user_displayname, '[email]' => $user_info['user_email'], '[userid]' => $user_id, '[link]' => "$prefix"."user_plan.php", '[subscription_details]' => $subscription_details ); $user_pdp_evc=$user_info['user_pdp_evc']; if($user_pdp_evc == 1 || $user_pdp_evc==3 || $user_pdp_evc==5){ send_systememail( "subscriptionpaymentfailed", $user->user_info['user_email'], $replace ); //@mail("porembaphilip@gmail.com", "Subscription Payment Failed", "Just the subject"); } return true; } function subscriber_email_subscription_soon_expires($user_info, $plan_info) { global $setting, $url; global $database; $user = new se_user( array( $user_id )); if($user->user_exists == 0) return; $user_info = $user->user_info; // GET SERVER INFO $prefix = $url->url_base; $subscription_details = $plan_info['plan_name']; $replace = array( '[username]' => $user_info['user_username'], '[displayname]' => $user->user_displayname, '[email]' => $user_info['user_email'], '[userid]' => $user_id, '[link]' => "$prefix"."user_plan.php", '[subscription_details]' => $subscription_details ); $user_pdp_evc=$user_info['user_pdp_evc']; if($user_pdp_evc == 1 || $user_pdp_evc==3 || $user_pdp_evc==5){ if($plan_info['plan_recurring']!=1){ send_systememail( "subscriptionexpiration", $user->user_info['user_email'], $replace ); } //@mail("porembaphilip@gmail.com", "Subscription about to expire", $subscription_details); } return true; } //function subscriber_email_subscription_refunded($user_info, $plan_info) { // //} /********************* BACKGROUND JOBS *********************/ function subscriber_scheduler_tasks() { global $database; // PROCESS ALL QUEUED TASKS $processed_tasks = array(); for(;;) { $task = semods::db_query_assoc('SELECT * FROM se_semods_plantasks ORDER BY plantask_id ASC LIMIT 1'); // No more tasks if($task === false) break; $task_processed = false; switch($task['plantask_type']) { case 'cancel_subscription': if($task['plantask_paymentgw'] != 0) { $paymentgw = semods_paymengtw_factory( $task['plantask_paymentgw'] ); // Log Error if(!$paymentgw) { subscriber_log_error( "Error cancelling plan - Failed instantiating Payment Handler (id={$task['plantask_paymentgw']})", 1000 ); } else { $result = $paymentgw->cancel_subscription( array( 'fast' => 0, 'metadata' => $task['plantask_metadata'] ) ); // Log Error if(!$result) { subscriber_log_error( "Error cancelling plan - (id={$task['plantask_paymentgw']})", 1001 ); // TODO // email_notify_admin(error cancelling ? requeue task? ); } } } if($result) { // email_notify(plan_cancelled); } else { // email_notify_admin(error cancelling plan id XX); } $task_processed = true; break; } if($task_processed) { $database->database_query("DELETE FROM se_semods_plantasks WHERE plantask_id = {$task['plantask_id']}"); } } } function subscriber_scheduler_daily() { global $database; $x=0; // PROCESS ALL PLANS EXPIRATION // Possible state changes: // active -> expired, cancelled -> expired, active -> suspended_paymentfailed, suspended_paymentfailed -> expired // safety of 1 day $safety_delta = 86400; // period of no payment to cancel - 0 days $suspend_to_cancel_period = 0; // take plans with state Active, Cancelled, Suspended, Suspended - payment failed and not Free for life (0 expiration date) $sql = 'SELECT * FROM se_semods_userplans WHERE (userplan_state = 0 OR userplan_state = 3 OR userplan_state = 4 OR userplan_state = 7 OR userplan_state = 1) AND userplan_expiredate != 0'; $rows = $database->database_query($sql); if ($rows === false) { //mail("sean@agndesigns.net", "DB ERROR", 'Database Error - could not query the database.' . ' MySQL Error: ' . $database->database_error()); echo "RRR";exit; scheduler_log_error( 'Database Error - could not query the database.' . ' MySQL Error: ' ); return false; } if($database->database_num_rows($rows) > 0) { $now = time(); if($x==1){mail("sean@agndesigns.net", "More than one", 'expiring');} // TODO: make date in sql query // loop through records while ($row = $database->database_fetch_assoc($rows)) { $x++; if($_SERVER["REMOTE_ADDR"]=="76.111.155.21") { //echo $row["userplan_user_id"]."
"; } if($row['userplan_plan_id'] != 1&&$row['userplan_plan_id'] != 10&&$row['userplan_plan_id'] != 9){ // userplan is not recurring // if plan suspended - failed payment & waitin period is over -> cancel & expire plan if($now > intval($row['userplan_expiredate']) + $suspend_to_cancel_period ) { //if($row['userplan_state'] == 7) { // if plan period expired -> downgrade & change state to "suspended_payment_failed" $userplan = new semods_userplan( $row['userplan_id'] ); $userplan->expire_plan(); //} } elseif($now > intval($row['userplan_expiredate']) + $safety_delta) { // if plan period expired -> downgrade & change state to "suspended_payment_failed" $userplan = new semods_userplan( $row['userplan_id'] ); $userplan->suspend_plan_failed_payment(); } } } } } function subscriber_scheduler_daily_new() { global $database; $x=0; // PROCESS ALL PLANS EXPIRATION // Possible state changes: // active -> expired, cancelled -> expired, active -> suspended_paymentfailed, suspended_paymentfailed -> expired // safety of 1 day $safety_delta = 86400; // period of no payment to cancel - 0 days $suspend_to_cancel_period = 0; // take plans with state Active, Cancelled, Suspended, Suspended - payment failed and not Free for life (0 expiration date) /* $sql = 'SELECT * FROM se_semods_userplans WHERE (userplan_state = 0 OR userplan_state = 3 OR userplan_state = 4 OR userplan_state = 7) AND userplan_expiredate != 0'; $rows = $database->database_query($sql); if ($rows === false) { //mail("sean@agndesigns.net", "DB ERROR", 'Database Error - could not query the database.' . ' MySQL Error: ' . $database->database_error()); echo "RRR";exit; scheduler_log_error( 'Database Error - could not query the database.' . ' MySQL Error: ' ); return false; } if($database->database_num_rows($rows) > 0) { $now = time(); if($x==1){mail("sean@agndesigns.net", "More than one", 'expiring');} // TODO: make date in sql query // loop through records while ($row = $database->database_fetch_assoc($rows)) { break; $x++; if($_SERVER["REMOTE_ADDR"]=="76.111.155.21") { //echo $row["userplan_user_id"]."
"; } if($row['userplan_plan_id'] != 1&&$row['userplan_plan_id'] != 10&&$row['userplan_plan_id'] != 9){ // userplan is not recurring // if plan suspended - failed payment & waitin period is over -> cancel & expire plan if($now > intval($row['userplan_expiredate']) + $suspend_to_cancel_period ) { //if($row['userplan_state'] == 7) { // if plan period expired -> downgrade & change state to "suspended_payment_failed" $userplan = new semods_userplan( $row['userplan_id'] ); // $userplan->expire_plan(); //} } elseif($now > intval($row['userplan_expiredate']) + $safety_delta) { // if plan period expired -> downgrade & change state to "suspended_payment_failed" $userplan = new semods_userplan( $row['userplan_id'] ); // $userplan->suspend_plan_failed_payment(); } } } }*/ $sql = 'SELECT * FROM se_semods_userplans WHERE (userplan_plan_id=4) AND userplan_expiredate<'.time().' AND userplan_expiredate != 0 AND userplan_state=1'; //echo $sql; $rows = $database->database_query($sql); if ($rows === false) { //mail("sean@agndesigns.net", "DB ERROR", 'Database Error - could not query the database.' . ' MySQL Error: ' . $database->database_error()); echo "RRR";exit; scheduler_log_error( 'Database Error - could not query the database.' . ' MySQL Error: ' ); return false; } if($database->database_num_rows($rows) > 0) { $now = time(); if($x==1){mail("sean@agndesigns.net", "More than one", 'expiring');} // TODO: make date in sql query // loop through records while ($row = $database->database_fetch_assoc($rows)) { echo $row["userplan_user_id"]."
"; $x++; if($_SERVER["REMOTE_ADDR"]=="76.111.155.21") { //echo $row["userplan_user_id"]."
"; } if($row['userplan_plan_id'] != 1&&$row['userplan_plan_id'] != 10&&$row['userplan_plan_id'] != 9){ // userplan is not recurring // if plan suspended - failed payment & waitin period is over -> cancel & expire plan if($now > intval($row['userplan_expiredate']) + $suspend_to_cancel_period ) { //if($row['userplan_state'] == 7) { // if plan period expired -> downgrade & change state to "suspended_payment_failed" $userplan = new semods_userplan( $row['userplan_id'] ); $userplan->expire_plan(); //} } elseif($now > intval($row['userplan_expiredate']) + $safety_delta) { // if plan period expired -> downgrade & change state to "suspended_payment_failed" $userplan = new semods_userplan( $row['userplan_id'] ); $userplan->suspend_plan_failed_payment(); } } } } } ?>