<?php 
	require_once 'conn.php';
	$website_link = "https://speedbitplus.com";
	$website_name = "Speedbit-Plus";
 $_SESSION['website_name'] = $website_name;	
 $_SESSION['website_link'] = $website_link;	
 
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
 
 // Always set content-type when sending HTML email
$mail_headers = "MIME-Version: 1.0" . "\r\n";
$mail_headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers

 
	if(function_exists('alert')){
		// echo "<script> alert('function exists'); </script>"; 	
	}else{
		function alert($x){
				echo "<script> alert('$x'); </script>"; 	
		}
	}

	function note_msg($m,$l='./',$t=1){
		$_SESSION['notice_msg']=$m;
		$_SESSION['notice_type']=$t;
		if($l == './'){
		$req = $_SERVER['REQUEST_URI'];
		$req_list = explode('/',$req);
		$req_list_length = count($req_list);
		if($req_list[$req_list_length-1] == ''){ $req_list[$req_list_length-1]='./'; }
		$l = $req_list[$req_list_length-1];
		// alert($req_list[$req_list_length-1]." $req_list_length 
		}
	header("location:$l");	
	}

$mail="";
	if(isset($_SESSION['user_id'])){
		$q="select email from info where 1";	
		$r =mysqli_query($conn,$q);
		while($qy =mysqli_fetch_assoc($r)){
		if(strtolower(md5($qy['email']) == $_SESSION['user_id'])){
			$mail = $qy['email'];
			break;
		}
	}
	}else{
		header('location:/');
	}
	
// $mail="num6375names@yahoo.com";	
	$sql = "SELECT * FROM info WHERE email=? ORDER BY id DESC"; // SQL with parameters
$select_stmt = $conn->prepare($sql); 
$select_stmt->bind_param("s", $mail);
$select_stmt->execute();
$result = $select_stmt->get_result(); // get the mysqli result
$infos = $result->fetch_assoc(); // fetch data

// alert($infos['bal']." ".$infos['email']);

function getPrice($pair){
		$url = "https://api.binance.com/api/v3/ticker/price";
		$data = json_decode(@file_get_contents($url));
		$pair = str_replace("/", "",$pair);

		if ($data) {
				for ($i=0; $i < count($data); $i++) {
				$price = 0.00; 
				if ($data[$i]->symbol == $pair) {
					$price = $data[$i]->price;
					break;
				}
			}
			if ($price <= 0) {
			 	return 'invalid_pair';
			 }else{
			 	return $price;
			 }
		}else{
			$tell =  0;
			
			if($tell < 3){
				return getPrice($pair);
			}else{
				return 'No network found';
			}
		}		

	}
	
	function get_Price($price,$amt){
		return $amt/$price;
	}
	
	$settings_id="1";	
	$sql = "SELECT * FROM settings WHERE id=?"; // SQL with parameters
$select_stmt = $conn->prepare($sql); 
$select_stmt->bind_param("i", $settings_id);
$select_stmt->execute();
$result = $select_stmt->get_result(); // get the mysqli result
$settings = $result->fetch_assoc(); // fetch data
// $settings=[];


// $settings=$wallet = ["btc"=>'',"eth"=>'',"usdt"=>'',"usdt_erc20"=>'',"usdt_bep2"=>'',"usdt_trc20"=>'',"bnb"=>'',"bnb2"=>''];
	
	

	$q="select  count(amount) from trans where email='$mail' order by id desc";
	$r = mysqli_query($conn,$q);
	$total_trans = mysqli_R($r,0);

	$q="select  sum(amount) from trans where email='$mail' and type='deposit' and status='success' order by id desc";
	$r = mysqli_query($conn,$q);
	$total_deposit_sum = mysqli_R($r,0);

	$q="select  sum(amount) from trans where email='$mail' and type='investment' and status='success' order by id desc";
	$r = mysqli_query($conn,$q);
	$total_invest_sum = mysqli_R($r,0);

	$q="select  sum(amount) from trans where email='$mail' and type='intrest' and status='success' order by id desc";
	$r = mysqli_query($conn,$q);
	$total_intrest_sum = mysqli_R($r,0);

	$q="select  amount from trans where email='$mail' and type='deposit' and status='success' order by id desc LIMIT 1";
	$r = mysqli_query($conn,$q);
	$last_deposit = mysqli_R($r,0);

	$q="select  amount from trans where email='$mail' and type='withdraw' and status='success' order by id desc LIMIT 1";
	$r = mysqli_query($conn,$q);
	$last_withdraw = mysqli_R($r,0);

	$q="select  sum(amount) from trans where email='$mail' and type='withdraw' and status='success' order by id desc";
	$r = mysqli_query($conn,$q);
	$total_withdraw_sum = mysqli_R($r,0);
	
	if($infos['lock_account'] == 1){
	    header('location:/logout');
	}


    
    $q2="select * from coins where 1";   
$r = mysqli_query($conn,$q2);
$data = [];
while($c = mysqli_fetch_assoc($r)){
     array_push($data,$c);
}

  $coins2 = $data;
function getAmt($a,$n){
    global $coins2;
    $n = strtolower($n);
    if($n == 'btc'){
        return ($a/$coins2[0]['price']);
    }
   if($n == 'eth'){
        return ($a/$coins2[1]['price']);
    }
  if($n == 'bnb'){
        return ($a/$coins2[3]['price']);
    }
    if($n == 'ltc'){
        return ($a/$coins2[3]['price']);
    } 
    if($n == 'xrp'){
        return ($a/$coins2[4]['price']);
    } 
    if($n == 'ada'){
        return ($a/$coins2[5]['price']);
    } 
   if($n == 'sol'){
        return $a/$coins2[6]['price'];
    } 
       if($n == 'doge'){
        return $a/$coins2[8]['price'];
    } 
   if($n == 'ltc'){
        return ($a/$coins2[9]['price']);
    } 
       if($n == 'bch'){
        return ($a/$coins2[10]['price']);
    } 
    
}


?>