0)) { $plan = new semods_plan( $plan_id ); if($plan->plan_exists == 0) { semods::redirect("admin_subscriber_plans.php"); } $plan_info = $plan->plan_info; $plan_managed_users = $plan->total_managed_users(); } else { // Defaults $plan_info['plan_enabled'] = 1; $plan_info['plan_level_id'] = 1; // default level $plan_info['plan_downgrade_level_id'] = 1; // default level $plan_info['plan_period'] = 1; // 1 $plan_info['plan_periodtype'] = 0; // days $plan_info['plan_trialperiod'] = 0; // 0 $plan_info['plan_trialperiodtype'] = 1; // days $plan_info['plan_price'] = 0; $plan_info['plan_onetime_price'] = 0; $plan_info['plan_showonsignup'] = 1; $plan_info['plan_recurring'] = 1; $plan_info['plan_recurring_cycles'] = 0; $plan_info['plan_levels'] = ''; // all levels $plan_info['plan_upgrade_from'] = ''; // upgrade from any } // CREATE / EDIT if($task == "editplan") { $plan_info['plan_name'] = semods::post('plan_name', ''); $plan_info['plan_description'] = semods::post('plan_description', ''); $plan_info['plan_enabled'] = semods::post('plan_enabled', 0); $plan_info['plan_level_id'] = semods::post('plan_level_id', 1); $plan_info['plan_downgrade_level_id'] = semods::post('plan_downgrade_level_id', 1); $plan_info['plan_period'] = semods::post('plan_period', 1); $plan_info['plan_periodtype'] = semods::post('plan_periodtype', ''); $plan_info['plan_trialperiod'] = semods::post('plan_trialperiod', 0); $plan_info['plan_trialperiodtype'] = semods::post('plan_trialperiodtype', 0); $plan_info['plan_price'] = floatval(semods::post('plan_price', 0)); $plan_info['plan_onetime_price'] = floatval(semods::post('plan_onetime_price', 0)); $plan_info['plan_showonsignup'] = semods::post('plan_showonsignup', 1); $plan_info['plan_recurring'] = semods::post('plan_recurring', 1); $plan_info['plan_recurring_cycles'] = intval(semods::post('plan_recurring_cycles', 0)); $plan_info['plan_levels_all'] = semods::post('plan_levels_all',0); $plan_info['plan_levels'] = $plan_info['plan_levels_all'] ? array() : semods::post('plan_levels',array()); $plan_info['plan_plans_all'] = semods::post('plan_plans_all',0); $plan_info['plan_upgrade_from'] = $plan_info['plan_plans_all'] ? array() : semods::post('plan_plans',array()); $plan_has_managed_users = semods::post('plan_has_managed_users', 0); $plan_info['plan_levels'] = implode( ',', $plan_info['plan_levels'] ); $plan_info['plan_upgrade_from'] = implode( ',', $plan_info['plan_upgrade_from'] ); //$plan_description_encoded = $plan_description; // lifetime subscription, clear other values if($plan_info['plan_periodtype'] == 4) { $plan_info['plan_period'] = 1; $plan_info['plan_trialperiod'] = 0; $plan_info['plan_trialperiodtype'] = 1; $plan_info['plan_onetime_price'] = 0; $plan_info['plan_recurring'] = 0; $plan_info['plan_recurring_cycles'] = 0; } for(;;) { if(empty($plan_info['plan_name'])) { $is_error = 1; $error_message = 100014154; break; } if($plan_has_managed_users) { // stop verifying if managed break; } // if not lifetime - must have recurring price if(($plan_info['plan_periodtype'] != 4) && ($plan_info['plan_price'] == 0) && ($plan_info['plan_onetime_price'] != 0)) { $is_error = 1; $error_message = 100014164; break; } // LOAD ACTIVE GATEWAYS AND CHECK THE PLAN PARAMETERS ARE OK WITH THEM $sql = "SELECT paymentgateway_id FROM se_semods_paymentgateways WHERE paymentgateway_enabled = 1 AND paymentgateway_handle_recurringpayments = 1"; $paymentgateways_errors = array(); // Load up payment gateways $paymentgateways = array(); $rows = $database->database_query( $sql ); while($row = $database->database_fetch_assoc($rows)) { $gateway = semods_paymengtw_factory( $row['paymentgateway_id'] ); if($gateway) { if(!$gateway->verify_plan_parameters($plan_info)) { $is_error = 1; $paymentgateways_errors[] = array( 'name' => $gateway->name, 'error_message' => $gateway->error_message ); } } } break; } if($is_error == 0) { if($plan_id == 0) { $fields = array('plan_name', 'plan_description', 'plan_level_id', 'plan_downgrade_level_id', 'plan_period', 'plan_periodtype', 'plan_trialperiod', 'plan_trialperiodtype', 'plan_price', 'plan_onetime_price', 'plan_enabled', 'plan_showonsignup', 'plan_recurring', 'plan_recurring_cycles', 'plan_levels', 'plan_upgrade_from' ); foreach($fields as $field) { $values[] = "'" . $plan_info[$field] . "'"; } semods::db_query( "INSERT INTO se_semods_plans(" . implode(',', $fields) . ") VALUES (" . implode(',', $values) . ")" ); $plan_id = $database->database_insert_id(); } else if($plan_has_managed_users) { // only updated allowed stuff $fields = array('plan_name', 'plan_description', 'plan_level_id', 'plan_downgrade_level_id', 'plan_showonsignup', 'plan_levels', 'plan_upgrade_from', 'plan_enabled' ); foreach($fields as $field) { $values[] = "$field = '" . $plan_info[$field] . "'"; } semods::db_query( "UPDATE se_semods_plans SET " . implode(',', $values) . " WHERE plan_id = $plan_id" ); } else { $fields = array('plan_name', 'plan_description', 'plan_level_id', 'plan_downgrade_level_id', 'plan_period', 'plan_periodtype', 'plan_trialperiod', 'plan_trialperiodtype', 'plan_price', 'plan_onetime_price', 'plan_enabled', 'plan_showonsignup', 'plan_recurring', 'plan_recurring_cycles', 'plan_levels', 'plan_upgrade_from' ); foreach($fields as $field) { $values[] = "$field = '" . $plan_info[$field] . "'"; } semods::db_query( "UPDATE se_semods_plans SET " . implode(',', $values) . " WHERE plan_id = $plan_id" ); } // non-fatal errors, but stil need to be shown if(count($paymentgateways_errors) == 0) { semods::redirect("admin_subscriber_plans.php"); } } // CONVERT HTML CHARACTERS BACK $plan_info['plan_description'] = str_replace("\r\n", "", html_entity_decode( $plan_info['plan_description'] )); } // No-action "level" $levels[] = array( 'level_id' => 0, 'level_name' => semods::get_language_text( 100014153 ), 'level_default' => 0 ); // LOOP OVER USER LEVELS $rows = $database->database_query("SELECT level_id, level_name, level_default FROM se_levels ORDER BY level_id"); while($row = $database->database_fetch_assoc($rows)) { $levels[] = $row; } $plan_levels = empty($plan_info['plan_levels']) ? array() : explode(",", $plan_info['plan_levels']); // LOOP OVER USER LEVELS, TAKE SELECTED $rows = $database->database_query("SELECT level_id, level_name, level_default FROM se_levels ORDER BY level_id"); while($row = $database->database_fetch_assoc($rows)) { $row['level_selected'] = in_array($row['level_id'], $plan_levels) || $plan_id == 0 || empty($plan_levels) ? 1 : 0; $level_array[] = $row; } $plan_plans = empty($plan_info['plan_upgrade_from']) ? array() : explode(",", $plan_info['plan_upgrade_from']); // LOOP OVER PLANS, TAKE SELECTED $rows = $database->database_query("SELECT * FROM se_semods_plans"); while($row = $database->database_fetch_assoc($rows)) { $row['plan_selected'] = in_array($row['plan_id'], $plan_plans) || $plan_id == 0 || empty($plan_plans) ? 1 : 0; $plan_array[] = $row; } // PRELOAD LANG foreach($plan_periodtypes as $plan_periodtype_preload) { SE_Language::_preload( $plan_periodtype_preload['f'] ); } if(is_numeric($error_message)) { SE_Language::_preload( $error_message ); SE_Language::load(); $error_message = SE_Language::_get($error_message); } $currency_code = semods::get_setting('payment_currency_code'); // ASSIGN VARIABLES AND SHOW ADMIN ADD USER LEVEL PAGE $smarty->assign('result', $result); $smarty->assign('is_error', $is_error); $smarty->assign('error_message', $error_message); $smarty->assign('levelsx', $level_array); $smarty->assign('levels_all', empty($level_array) ? 1 : 0); $smarty->assign('plans', $plan_array); $smarty->assign('plans_all', empty($plan_array) ? 1 : 0); $smarty->assign('levels', $levels); $smarty->assign('plan_periodtypes', $plan_periodtypes); $smarty->assign('plan_info', $plan_info); $smarty->assign('plan_id', $plan_id); //$smarty->assign('plan_name', $plan_name); //$smarty->assign('plan_description', $plan_description); //$smarty->assign('plan_level_id', $plan_level_id); //$smarty->assign('plan_downgrade_level_id', $plan_downgrade_level_id); //$smarty->assign('plan_period', $plan_period); //$smarty->assign('plan_periodtype', $plan_periodtype); //$smarty->assign('plan_trialperiod', $plan_trialperiod); //$smarty->assign('plan_trialperiodtype', $plan_trialperiodtype); //$smarty->assign('plan_price', $plan_price); //$smarty->assign('plan_onetime_price', $plan_onetime_price); //$smarty->assign('plan_enabled', $plan_enabled); //$smarty->assign('plan_showonsignup', $plan_showonsignup); //$smarty->assign('plan_recurring', $plan_recurring); //$smarty->assign('plan_recurring_cycles', $plan_recurring_cycles); $smarty->assign('plan_managed_users', $plan_managed_users); $smarty->assign('plan_has_managed_users', $plan_managed_users > 0 ); $smarty->assign('paymentgateways_errors', $paymentgateways_errors ); $smarty->assign('currency_code', $currency_code ); include "admin_footer.php"; ?>