<?php
    session_start();
    include('../config.php');
    date_default_timezone_set('Europe/London');
    if(isset($_SESSION['email'])){
        $email = $_SESSION['email'];
        $qv = $conn->query("SELECT * FROM `main_reg` WHERE `email`='$email'");
            $r = mysqli_fetch_array($qv);
            $active = $r['active'];
            $fname = $r['first_name'];
            $code = $r['hash_p'];
            $btc2 = $r['btc'];
            $email = $r['email'];
    		$litcoin_c = $r['litcoin'];
    		$eth_c = $r['eth'];
    		$btccash = $r['btccash'];
    		$payeer_c = $r['payeer'];
            $mref = $r['ref'];
            $cd = $r['cd'];
            
            
            $lname = $r['last_name'];
            $country = $r['country'];
            $state = $r['state'];
            $city = $r['city'];
            $dob = $r['zip'];
            $ref = $r['ref'];
            $dateob = $r['dateob'];
            $phone = $r['perfect'];
            $status = $r['status'];
            
            //$comand = $conn->query("UPDATE `main_reg` SET `status`='0' WHERE `hash_p` = '$code';");
            $q_t = $conn->query("SELECT * FROM `btc_address` WHERE `status`='1'");
		$rowp = mysqli_fetch_array($q_t);
		$address = $rowp['address'];
    }else{
        echo '<script> window.location = "/"</script>';
    }
    
    $mmm = $conn->query("SELECT * FROM `wdraw` WHERE `user_code`='$code'");
    $rv = mysqli_num_rows($mmm);
    
    if(mysqli_num_rows($mmm) >= 1){
        $sql_por3 = $conn->query("SELECT SUM(`amount`) AS `amt` FROM `wdraw` WHERE `user_code`='$code'");
        $r_s3 = mysqli_fetch_array($sql_por3);
        $amt_pr3 = (int)$r_s3['amt'];
    }else{
        $amt_pr3 = 0;
    }
    
    
    $mmmb = $conn->query("SELECT * FROM `wdraw` WHERE `user_code`='$code' AND `status`='1'");
    $rvb = mysqli_num_rows($mmmb);
    
    if(mysqli_num_rows($mmmb) >= 1){
        $sql_por3b = $conn->query("SELECT SUM(`amount`) AS `amt` FROM `wdraw` WHERE `user_code`='$code' AND `status`='1'");
        $r_s3b = mysqli_fetch_array($sql_por3b);
        $approved_wdw = (int)$r_s3b['amt'];
    }else{
        $approved_wdw = 0;
    }
    
    //echo $username;$pend
    
    function get_client_ip() {
        $ipaddress = '';
        if (getenv('HTTP_CLIENT_IP'))
            $ipaddress = getenv('HTTP_CLIENT_IP');
        else if(getenv('HTTP_X_FORWARDED_FOR'))
            $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
        else if(getenv('HTTP_X_FORWARDED'))
            $ipaddress = getenv('HTTP_X_FORWARDED');
        else if(getenv('HTTP_FORWARDED_FOR'))
            $ipaddress = getenv('HTTP_FORWARDED_FOR');
        else if(getenv('HTTP_FORWARDED'))
           $ipaddress = getenv('HTTP_FORWARDED');
        else if(getenv('REMOTE_ADDR'))
            $ipaddress = getenv('REMOTE_ADDR');
        else
            $ipaddress = 'UNKNOWN';
        return $ipaddress;
    }
    
    $jb = $conn->query("SELECT * FROM `balance` WHERE `code`='$code'");

    
    if(mysqli_num_rows($jb) >= 1){
        $rj = mysqli_fetch_array($jb);
        $av_bal = (int)$rj['amount'];
    }else{
        $av_bal = 0;
    }
    
    
    $sql_por = $conn->query("SELECT SUM(`amount`) AS `amt` FROM `deposite` WHERE `code` = '$code' AND `status` = '1'");
    $r_s = mysqli_fetch_array($sql_por);
    $amt_pr = $r_s['amt'];
    if($amt_pr != ''){
        
        $amt_pro = $amt_pr;
    }else{
        $amt_pro = 0;
    }
    
    
    $sql_porc = $conn->query("SELECT SUM(`amount`) AS `amt` FROM `deposite` WHERE `code` = '$code' AND `status` = '1' AND `matured`='0'");
    $r_sc = mysqli_fetch_array($sql_porc);
    $amt_prc = $r_sc['amt'];
    if($amt_prc != ''){
        
        $amt_proc = $amt_prc.' USD';
    }else{
        $amt_proc = 'N/A';
    }
    
    
    
    $sql_porv = $conn->query("SELECT * FROM `investment` WHERE `code` = '$code' AND `status` = '1'");
    $r_sv = mysqli_fetch_array($sql_porv);
    $amt_prv = $r_sv['amount'];
    if($amt_prv != ''){
        
        $amt_prov = $amt_prv.'.00 USD';
    }else{
        $amt_prov = 'N/A';
    }
    
    
    
    $sql_porw = $conn->query("SELECT * FROM `wdraw` WHERE `user_code` = '$code' ORDER BY `id` DESC;");
    $r_sw = mysqli_fetch_array($sql_porw);
    $amt_prw = $r_sw['amount'];
    if($amt_prw != ''){
        
        $amt_prow = $amt_prw.'.00';
    }else{
        $amt_prow = 'N/A';
    }
    
    $earn = $conn->query("SELECT * FROM `profit` WHERE `code`='$code'");
    $rve = mysqli_num_rows($earn);
    
    if(mysqli_num_rows($earn) >= 1){
        $sql_pore = $conn->query("SELECT SUM(`profit`) AS `amt` FROM `profit` WHERE `code`='$code'");
        $r_se = mysqli_fetch_array($sql_pore);
        $earns = (int)$r_se['amt'];
    }else{
        $earns = 0;
    }
    
    
    
    
    
    
    
    $tcontract = $conn->query("SELECT * FROM `investment` WHERE `code`='$code' AND `status`='1'");
    $c_rvc = mysqli_num_rows($tcontract);
    
    if(mysqli_num_rows($tcontract) >= 1){
        $sql_porc = $conn->query("SELECT SUM(`amount`) AS `amt` FROM `investment` WHERE `code`='$code' AND `status`='1'");
        $r_sc = mysqli_fetch_array($sql_porc);
        $tcontract = (int)$r_sc['amt'];
    }else{
        $tcontract = 0;
    }
    
    
   
    
    
    $sps = $conn->query("SELECT * FROM `active_deposit` WHERE `code`='$code'");
    if(mysqli_num_rows($sps) >= 1){
        $zoo = mysqli_fetch_array($sps);
        $amountz = $zoo['amount'];
        $amt_proc = $amt_proc + $amountz;
    }else{
        $amt_proc = $amt_proc;
    }
    
    $qdb = $conn->query("SELECT * FROM `account` WHERE `code`='$code'");
    $rdb = mysqli_fetch_array($qdb);
    $cntry = $rdb['country'];
    $bname = $rdb['bname'];
    $anumber = $rdb['anumber'];
    $aname = $rdb['aname'];
    
    
    
    $av_bal_ref = $conn->query("SELECT * FROM `referral` WHERE `code`='$code'");
    $c_rvc = mysqli_num_rows($av_bal_ref);
    
    if(mysqli_num_rows($av_bal_ref) >= 1){
        $sql_porc = $conn->query("SELECT SUM(`amount`) AS `amt` FROM `referral` WHERE `code`='$code'");
        $r_sc = mysqli_fetch_array($sql_porc);
        $av_bal_ref = (int)$r_sc['amt'];
    }else{
        $av_bal_ref = 0;
    }
    
    
    
    
    
    $av_history_ref = $conn->query("SELECT * FROM `ref_history` WHERE `refcode`='$code'");
    $c_history = mysqli_num_rows($av_history_ref);
    
    if(mysqli_num_rows($av_history_ref) >= 1){
        $sql_porc = $conn->query("SELECT SUM(`amount`) AS `amt` FROM `ref_history` WHERE `refcode`='$code'");
        $r_sc = mysqli_fetch_array($sql_porc);
        $av_history_ref = (int)$r_sc['amt'];
    }else{
        $av_history_ref = 0;
    }
    
    
    
    $qdb_top = $conn->query("SELECT * FROM `top_account_bal` WHERE `code`='$code'");
    $rdb_top = mysqli_fetch_array($qdb_top);
    $top_up = $rdb_top['amount'];
    
    $rf = $conn->query("SELECT * FROM `main_reg` WHERE `ref`='$cd'");
    $ref_num = mysqli_num_rows($rf);
    
    
    $qvx = $conn->query("SELECT * FROM `main_reg` WHERE `ref`='$cd' AND `active`='3' AND `status`='3'");
    $active_ref = mysqli_num_rows($qvx);
    
    $qvp = $conn->query("SELECT * FROM `main_reg` WHERE `ref`='$cd' AND `status`='0'");
    $pending_ref = mysqli_num_rows($qvp);
    $pending_ref = $pending_ref * 3000;
    
    $sql_porwp = $conn->query("SELECT * FROM `wdraw` WHERE `user_code` = '$code' ORDER BY `id` DESC LIMIT 1");
    $r_swp = mysqli_fetch_array($sql_porwp);
    $amt_prow_lastp = $r_swp['amount'];
    if($amt_prow_lastp != ''){
        
        $amt_prow_last = $amt_prow_lastp.'.00';
    }else{
        $amt_prow_last = 'N/A';
    }
    
    
    
    
    
    
    $sels = $conn->query("SELECT * FROM `bank_details` WHERE `code`='$code'");
    $row_sels = mysqli_fetch_array($sels);
    $bank_names = $row_sels['bank_name'];
    $act_names = $row_sels['ac_name'];
    $ac_numbers = $row_sels['acct_num'];
    $bank_code = $row_sels['bank_code'];
    
    
    
    
?>