<?
/**
 * @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_lode.php');
		//get data
		$file_host='config/kqxs.txt';
		if(!file_exists($file_host)){fopen($file_host, "w+");}
		$Hour=date("H");
		$Minute=date("i");
		$date_now=date("Y/m/d");
		$fp_host = file($file_host);
		$dulieu=explode('<vweb>',trim($fp_host[0]));
		$time_host = $dulieu[0];
	
		if ((time() > strtotime(date('Y/m/d',strtotime($time_host)+86400)." $Hour_Update:$Minute_Update:00") && $date_now != $time_host) || empty($fp_host[0]))
		{

		$getcontent_url = $server_url . "/sv_relax.php";
        $getcontent_data = array(
            'pagesv'	=>	'sv_relax_kq',
            '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 {
				$info = explode('<vweb>',$reponse);
				if ($info[0] != $time_host || empty($fp_host[0])) {
					//write file
					$fp = fopen($file_host, "w+");  
					fputs ($fp, $reponse);
					fclose($fp);
					//End write file
				}
				else $error = $reponse;
			}
		}
		
		//xu ly va hien thi ra cho nguoi dung xem
		$fp_host = file($file_host);
		$dulieu=explode('<vweb>',$fp_host[0]);
		$time_host = $dulieu[0];
	
		$xoso_info = explode('|', $dulieu[1]);
		$Get_GiaiDacBiet=$xoso_info[0];
		$Get_GiaiNhat=$xoso_info[1];
		$Get_GiaiNhi=explode("-",$xoso_info[2]);
		$Get_GiaiBa=explode("-",$xoso_info[3]);
		$Get_GiaiTu=explode("-",$xoso_info[4]);
		$Get_GiaiNam=explode("-",$xoso_info[5]);
		$Get_GiaiSau=explode("-",$xoso_info[6]);
		$Get_GiaiBay=explode("-",$xoso_info[7]);
		
		$lode_xuly = array
		(
			substr($Get_GiaiDacBiet,-2),
			substr($Get_GiaiNhat,-2),
			substr($Get_GiaiNhi[0],-2),
			substr($Get_GiaiNhi[1],-2),
			substr($Get_GiaiBa[0],-2),
			substr($Get_GiaiBa[1],-2),
			substr($Get_GiaiBa[2],-2),
			substr($Get_GiaiBa[3],-2),
			substr($Get_GiaiBa[4],-2),
			substr($Get_GiaiBa[5],-2),
			substr($Get_GiaiTu[0],-2),
			substr($Get_GiaiTu[1],-2),
			substr($Get_GiaiTu[2],-2),
			substr($Get_GiaiTu[3],-2),
			substr($Get_GiaiNam[0],-2),
			substr($Get_GiaiNam[1],-2),
			substr($Get_GiaiNam[2],-2),
			substr($Get_GiaiNam[3],-2),
			substr($Get_GiaiNam[4],-2),
			substr($Get_GiaiNam[5],-2),
			substr($Get_GiaiSau[0],-2),
			substr($Get_GiaiSau[1],-2),	
			substr($Get_GiaiSau[2],-2),
			$Get_GiaiBay[0],	
			$Get_GiaiBay[1],
			$Get_GiaiBay[2],
			$Get_GiaiBay[3]
		);
		
		if(!isset($_GET['date_bet'])){$date_bet=date("Y/m/d");}
		else{$date_bet=$_GET['date_bet'];}
		$getcontent_url = $server_url . "/sv_relax.php";
        $getcontent_data = array(
			'date_bet'	=>	strtotime($date_bet),
			'login'	=>	$_SESSION['mu_username'],
            'pagesv'	=>	'sv_relax_getinfo',
            '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 {
				$dulieu = explode('<vweb>',$reponse);
				$leng_data=count($dulieu);

				for($i=0;$i<$leng_data-1;$i++){
					$bet_info=explode("||",$dulieu[$i]);
					$hit_trung=0;
						switch($bet_info[5])
						{
							case 'de':
								$bet_info[5]="Đề";
								if($bet_info[0]==$lode_xuly[0]){$nut="Nhận thưởng"; $hit_trung=1;}
								break;
							case 'lo':
								$bet_info[5]="Bao Lô";
								$ketqua_lo=xuly_ketqua_loxien($bet_info[0],$bet_info[1],$bet_info[2],$bet_info[3],1,8,$lode_xuly);
								if($ketqua_lo>0){$nut="Trúng $ketqua_lo nháy"; $hit_trung=1;}
								break;
							case 'loxien2':
								$bet_info[5]="Lô xiên 2";
								$ketqua_lo=xuly_ketqua_loxien($bet_info[0],$bet_info[1],$bet_info[2],$bet_info[3],2,1,$lode_xuly);
								if($ketqua_lo==2){$nut="Nhận thưởng"; $hit_trung=1;}
								break;
							case 'loxien3':
								$bet_info[5]="Lô xiên 3";
								$ketqua_lo=xuly_ketqua_loxien($bet_info[0],$bet_info[1],$bet_info[2],$bet_info[3],3,1,$lode_xuly);
								if($ketqua_lo==3){$nut="Nhận thưởng"; $hit_trung=1;}
								break;
							case 'loxien4':
								$bet_info[5]="Lô xiên 4";
								$ketqua_lo=xuly_ketqua_loxien($bet_info[0],$bet_info[1],$bet_info[2],$bet_info[3],4,1,$lode_xuly);
								if($ketqua_lo==4){$nut="Nhận thưởng"; $hit_trung=1;}
								break;				
						}
				
					if($bet_info[8]==1){$bet_info[8]='disabled'; $nut="Đã nhận giải";}
					elseif(strtotime($bet_info[7])>strtotime($time_host)){$bet_info[8]='disabled'; $nut="Chờ kết quả";}
					elseif(strtotime($bet_info[7])<strtotime($time_host)){$bet_info[8]='disabled'; $nut="Quá hạn";}	
					elseif($hit_trung==0){$bet_info[8]='disabled'; $nut="Trượt";}
					
					$num_bet="";
					for($u=0;$u<4;$u++)
					{
						if(strlen($bet_info[$u])>1)
						{
							$num_bet.="$bet_info[$u]   ";
						}
					}
					$num_bet=substr($num_bet,0,-3);
					
					$info_bet[] = array (
						'num_bet'	=> $num_bet,
						'num_point'	=> $bet_info[4],
						'type_play'	=> $bet_info[5],
						'Money_Bet'	=> $bet_info[6],
						'Date_Bet'	=> $bet_info[7],
						'Bet_Status' => $bet_info[8],
						'ID' => $bet_info[9],
						'Button'	=> $nut,
						'Hit_Trung' => $hit_trung
					);
				}
				
				$date_info=explode(",",$dulieu[$leng_data-1]);
				
			}

		$page_template = "templates/relax/ketqua.tpl";
?>