level_info['level_subscriber_allow'] == 0) { semods::redirect('home.php'); } $task = semods::getpost('task', "main"); $from_plan = intval( semods::getpost('from_plan') ); if(!empty($from_plan)) { $userplan = new semods_userplan( $from_plan, $user->user_info['user_id'] ); } if($userplan->userplan_exists == 0) { // Now - only one plan // Later - multiple plans => display list to choose from $userplan = new semods_userplan( 0, $user->user_info['user_id'] ); } // Decide if trials are allowed if( ($userplan->userplan_exists == 0) || (($userplan->userplan_exists == 1) && (semods::get_setting('subscriber_allow_multiple_trials') == 1)) ) { $allow_trial = true; } else { $allow_trial = false; } // TBD: also show "self", i.e. "from_plan" plan if userplan is expired .. or it's renew task only ? if($task == 'upgrade') { $signup_plan = intval(semods::getpost('signup_plan')); for(;;) { if(empty($signup_plan)) { $error_message = 100014336; break; } // Can't upgrade to self - it's renew? - only if expired / cancelled if(($userplan->userplan_exists != 0) && ($signup_plan == $userplan->userplan_info['plan_id']) && (!in_array( intval($userplan->userplan_info['userplan_state']), array(2,3) )) ){ $error_message = 100014336; break; } // Validate this plan can be upgraded to $sql = "SELECT COUNT(*) FROM se_semods_plans WHERE plan_enabled = 1 AND (FIND_IN_SET({$user->user_info['user_level_id']},plan_levels) OR plan_levels='')"; if($userplan->userplan_exists != 0) { $sql .= " AND (FIND_IN_SET({$userplan->userplan_info['plan_id']},plan_upgrade_from) OR plan_upgrade_from='')"; } $sql .= " AND plan_id = $signup_plan"; // Can't upgrade to self - it's renew? - only if expired / cancelled if(($userplan->userplan_exists != 0) && ($signup_plan == $userplan->userplan_info['plan_id']) && (!in_array( intval($userplan->userplan_info['userplan_state']), array(2,3) )) ){ $sql .= " AND plan_id != {$userplan->userplan_info['plan_id']}"; } if(semods::db_query_count( $sql ) == 0) { $error_message = 100014336; break; } // CREATE CART & REDIRECT // TODO: pro-rate $plan = new semods_plan( $signup_plan ); $plan_free = $plan->is_free_plan(); if(!$plan_free) { $cart = new semods_cart(); $cart->create_cart( $user->user_info['user_id'] ); $plan->add_to_cart( $cart, $user->user_info['user_id'], $allow_trial ); // GO TO PAYMENT PROCESSOR header("Location: payment.php"); exit; } else { // act on free plan // subscribe a user for free plan right away ... $plan->plan_subscribe( $user->user_info['user_id'], 0, array(), false ); // redirect somewhere with msg? // GO TO PLANS HOME header("Location: user_plan.php?upgradesuccess"); exit; } break; } } //if($task == 'main') { // Find out which plans can be upgraded to $sql = "SELECT * FROM se_semods_plans WHERE plan_enabled = 1 AND (FIND_IN_SET({$user->user_info['user_level_id']},plan_levels) OR plan_levels='')"; if($userplan->userplan_exists != 0) { $sql .= " AND (FIND_IN_SET({$userplan->userplan_info['plan_id']},plan_upgrade_from) OR plan_upgrade_from='')"; } // Can't upgrade to self - it's renew? - only if expired / cancelled if(($userplan->userplan_exists != 0) && (!in_array( intval($userplan->userplan_info['userplan_state']), array(2,3) )) ){ $sql .= " AND plan_id != {$userplan->userplan_info['plan_id']}"; } $rows = $database->database_query( $sql ); $plans = array(); 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'] ); } //} // ASSIGN VARIABLES AND INCLUDE FOOTER $currency_code = semods::get_setting('payment_currency'); if(empty($currency_code)) $currency_code = 'USD'; $smarty->assign('require', isset($_REQUEST['require']) ); $smarty->assign('currency_code', $currency_code); $smarty->assign('allow_trial', $allow_trial); $smarty->assign('result', $result); $smarty->assign('is_error', empty($error_message) ? 0 : 1); $smarty->assign('error_message', $error_message); $smarty->assign('plans', $plans); $smarty->assign('from_plan', $from_plan); include "footer.php"; ?>