<?
/**
 * @Project GoldMU.Net
 * @copyright 03/03/2022
 * @Email: goldmu.net@gmail.com
 * @Zalo: 0923 117 898
*/
 
	if (!defined('GoldWebMU')) die("Ban khong co quyen truy cap he thong");
include('config/config_reset.php');
include('config/config_relife.php');
include('config/config_resetvip.php');
include('config/config_gioihanrs.php');
include('config/config_resetvip_over.php');

if (isset($_POST['action']))
{
	$action = $_POST['action'];
	if ($action == 'resetvipover')
	{
		$character = $_POST['character'];
		
		if( $sendsv === false ) { $error = "Tốc độ xử lý của bạn quá nhanh, vui lòng chờ vài giây rồi tiếp tục thực hiện."; }
		elseif (empty($character))
		{
			$error = "Chưa chọn nhân vật cần Reset";
		}
		elseif (preg_match("/[^a-zA-Z0-9_$]/", $character))
			{
				$error = "Dữ liệu lỗi - Nhân vật chỉ được sử dụng kí tự a-z, A-Z, số (1-9) và dấu _.";
			}
		else {
			
			$getcontent_url = $server_url . "/sv_char.php";
            $getcontent_data = array(
                'login'    =>  $_SESSION['mu_username'],
                'name'    =>  $_SESSION['mu_nvchon'],
                'resetnow'    =>  $_SESSION['nv_reset'],
                
                'pagesv'	=>	'sv_char_reset_vip_over',
                'string_login'    =>  $_SESSION['checklogin'],
                'passtransfer'    =>  $passtransfer
            ); 
            
            $reponse = _getContent($getcontent_url, $getcontent_data, $getcontent_method, $getcontent_curl);
			
			if ( empty($reponse) ) $error = "Server bảo trì.";
			elseif($reponse == "login_other") {
				$error = "<font size='3' color='red'>Tài khoản đã được đăng nhập trên trình duyệt khác hoặc máy tính khác.</font>";
				session_destroy();
			}
			else {
				if ( read_TagName($reponse, 'info', 1) == 'OK' ) {
					$notice = read_TagName($reponse, 'messenge', 1);

					$_SESSION['acc_gcoin'] = read_TagName($reponse, 'gcoin', 1);
					$_SESSION['acc_gcoin_km'] = read_TagName($reponse, 'gcoin_km', 1);
					$_SESSION['acc_vpoint'] = read_TagName($reponse, 'vpoint', 1);
					
					$_SESSION['nv_reset'] = $_SESSION['nv_reset']+1;
					$_SESSION['nv_level'] = 1;
					$_SESSION['nv_point'] = read_TagName($reponse, 'resetpoint', 1);
					$_SESSION['nv_pointdutru'] = read_TagName($reponse, 'pointdutru', 1);
					$_SESSION['nv_resetday'] = $_SESSION['nv_resetday']+1;
					$_SESSION['nv_resetmonth'] = $_SESSION['nv_resetmonth']+1;
				}
				else $error = $reponse;
			}
		}
	}
}

$thehe_choise = $_SESSION['acc_thehe'];

if ( ($_SESSION['nv_reset'] >= $reset_cap_0) AND ($_SESSION['nv_reset'] < $reset_cap_1) )
{
	$level = $level_cap_1_vip;
	$gcoin_reset_vip = $gcoin_cap_1_vip;
}
elseif ( ($_SESSION['nv_reset'] >= $reset_cap_1) AND ($_SESSION['nv_reset'] < $reset_cap_2) )
{
	$level = $level_cap_2_vip;
	$gcoin_reset_vip = $gcoin_cap_2_vip;
}
elseif ( ($_SESSION['nv_reset'] >= $reset_cap_2) AND ($_SESSION['nv_reset'] < $reset_cap_3) )
{
	$level = $level_cap_3_vip;
	$gcoin_reset_vip = $gcoin_cap_3_vip;
}
elseif ( ($_SESSION['nv_reset'] >= $reset_cap_3) AND ($_SESSION['nv_reset'] < $reset_cap_4) )
{
	$level = $level_cap_4_vip;
	$gcoin_reset_vip = $gcoin_cap_4_vip;
}
elseif ( ($_SESSION['nv_reset'] >= $reset_cap_4) AND ($_SESSION['nv_reset'] < $reset_cap_5) )
{
	$level = $level_cap_5_vip;
	$gcoin_reset_vip = $gcoin_cap_5_vip;
}
elseif ( ($_SESSION['nv_reset'] >= $reset_cap_5) AND ($_SESSION['nv_reset'] < $reset_cap_6) )
{
	$level = $level_cap_6_vip;
	$gcoin_reset_vip = $gcoin_cap_6_vip;
}
elseif ( ($_SESSION['nv_reset'] >= $reset_cap_6) AND ($_SESSION['nv_reset'] < $reset_cap_7) )
{
	$level = $level_cap_7_vip;
	$gcoin_reset_vip = $gcoin_cap_7_vip;
}
elseif ( ($_SESSION['nv_reset'] >= $reset_cap_7) AND ($_SESSION['nv_reset'] < $reset_cap_8) )
{
	$level = $level_cap_8_vip;
	$gcoin_reset_vip = $gcoin_cap_8_vip;
}
elseif ( ($_SESSION['nv_reset'] >= $reset_cap_8) AND ($_SESSION['nv_reset'] < $reset_cap_9) )
{
	$level = $level_cap_9_vip;
	$gcoin_reset_vip = $gcoin_cap_9_vip;
}
elseif ( ($_SESSION['nv_reset'] >= $reset_cap_9) AND ($_SESSION['nv_reset'] < $reset_cap_10) )
{
	$level = $level_cap_10_vip;
	$gcoin_reset_vip = $gcoin_cap_10_vip;
}
elseif ( ($_SESSION['nv_reset'] >= $reset_cap_10) AND ($_SESSION['nv_reset'] < $reset_cap_11) )
{
	$level = $level_cap_11_vip;
	$gcoin_reset_vip = $gcoin_cap_11_vip;
}
elseif ( ($_SESSION['nv_reset'] >= $reset_cap_11) AND ($_SESSION['nv_reset'] < $reset_cap_12) )
{
	$level = $level_cap_12_vip;
	$gcoin_reset_vip = $gcoin_cap_12_vip;
}
elseif ( ($_SESSION['nv_reset'] >= $reset_cap_12) AND ($_SESSION['nv_reset'] < $reset_cap_13) )
{
	$level = $level_cap_13_vip;
	$gcoin_reset_vip = $gcoin_cap_13_vip;
}
elseif ( ($_SESSION['nv_reset'] >= $reset_cap_13) AND ($_SESSION['nv_reset'] < $reset_cap_14) )
{
	$level = $level_cap_14_vip;
	$gcoin_reset_vip = $gcoin_cap_14_vip;
}
elseif ( ($_SESSION['nv_reset'] >= $reset_cap_14) AND ($_SESSION['nv_reset'] < $reset_cap_15) )
{
	$level = $level_cap_15_vip;
	$gcoin_reset_vip = $gcoin_cap_15_vip;
}
elseif ( ($_SESSION['nv_reset'] >= $reset_cap_15) AND ($_SESSION['nv_reset'] < $reset_cap_16) )
{
	$level = $level_cap_16_vip;
	$gcoin_reset_vip = $gcoin_cap_16_vip;
}
elseif ( ($_SESSION['nv_reset'] >= $reset_cap_16) AND ($_SESSION['nv_reset'] < $reset_cap_17) )
{
	$level = $level_cap_17_vip;
	$gcoin_reset_vip = $gcoin_cap_17_vip;
}
elseif ( ($_SESSION['nv_reset'] >= $reset_cap_17) AND ($_SESSION['nv_reset'] < $reset_cap_18) )
{
	$level = $level_cap_18_vip;
	$gcoin_reset_vip = $gcoin_cap_18_vip;
}
elseif ( ($_SESSION['nv_reset'] >= $reset_cap_18) AND ($_SESSION['nv_reset'] < $reset_cap_19) )
{
	$level = $level_cap_19_vip;
	$gcoin_reset_vip = $gcoin_cap_19_vip;
}
elseif ( ($_SESSION['nv_reset'] >= $reset_cap_19) AND ($_SESSION['nv_reset'] < $reset_cap_20) )
{
	$level = $level_cap_20_vip;
	$gcoin_reset_vip = $gcoin_cap_20_vip;
}
	

$chenhlech_level = $_SESSION['nv_level'] - $level;
$chenhlech_gcoin = ($_SESSION['acc_gcoin'] + $_SESSION['acc_gcoin_km']) - $gcoin_reset_vip;

$font_thieu_begin = "<font color='red'><b>";
$font_thieu_end = "</b></font>";
$font_du_begin = "<font color='green'><b>";
$font_du_end = "</b></font>";

$accept = 1;

$check_reset = $_SESSION['nv_reset'];
$check_relife = $_SESSION['nv_relife'];
$resetday = $_SESSION['nv_resetday'];

$Top1_TotalRS = $_SESSION['top1_rs'];
$SUM_Top1_TotalRS = $_SESSION['sum_top1_rs'];

$char_sumrs = ResetTotal($check_reset, $check_relife);

$timestamp = time();
if($use_gioihanrs[$thehe_choise] == 1 && $char_sumrs >= $rsgh[$thehe_choise]) {
if($ghrs_open[$thehe_choise] > 0 && (strtotime($ghrs_open_begin[$thehe_choise]) < $timestamp) && (strtotime($ghrs_open_end[$thehe_choise]) + 24*60*60 > $timestamp))
{
	$gioihanrs = $ghrs_open[$thehe_choise];
}else{
	require_once('modules/char_manager/ghrs.php');
}
}
if($use_overrs[$thehe_choise] == 0) {
    $overrs_rs[$thehe_choise] = 0;
}
if( $_SESSION['nv_resetday'] < ($gioihanrs + $overrs_rs[$thehe_choise]) ) 
{
	$accept = 0;
    $notice_vuotmuc = '<br /><i>Cần phải hết số lần reset ngày và hết số lần reset vượt mức mới có thể Reset OVER</i>';
    if($_SESSION['nv_resetday'] >= $gioihanrs) $notice_vuotmuc = "<br /><i>Cần phải Reset đủ <strong>". $overrs_rs[$thehe_choise] ."</strong> lần vượt mức bên Reset VIP mới có thể Reset OVER </i>";
	$notice_resetday = "$font_thieu_begin $_SESSION[nv_resetday] / $gioihanrs + ". $overrs_rs[$thehe_choise] ." $font_thieu_end $notice_vuotmuc";
} else $notice_resetday = "$font_du_begin $_SESSION[nv_resetday] / $gioihanrs + ". $overrs_rs[$thehe_choise] ." $font_du_end";

if ($chenhlech_level < 0) { $notice_level = "$font_thieu_begin Thiếu ". ABS($chenhlech_level) ." level $font_thieu_end"; } else { $notice_level = "$font_du_begin Đủ Level Reset $font_du_end"; }
if ($chenhlech_gcoin < 0) { $notice_gcoin = "$font_thieu_begin Thiếu ". ABS($chenhlech_gcoin) ." Gcoin $font_thieu_end"; } else { $notice_gcoin = "$font_du_begin Đủ Gcoin Reset $font_du_end"; }

if ( $_SESSION['nv_online'] == 1 || $chenhlech_level < 0 || $chenhlech_gcoin < 0 || $use_gioihanrs[$thehe_choise] == 0 ) { $accept = 0; }	

$page_template = "templates/char_manager/resetvipover.tpl";
?>