<?php  session_start(); error_reporting(0); ?>
<?php if(!isset($_SESSION['j_admin'])){ 
    $url = urlencode("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"); //header('location:../login/?url='.$url.'');  
} ?>
<!doctype html>
<html lang="en"> 
<head>
	<?php
    require_once("../j_conn/url.php");
    require_once("../j_conn/dbc.php");
    require_once("../j_incs/functions.php");
    $page_name="$p1_name";
    $page_desc="$p1_motto";
    $page_img="".$dir."j_files/j_img/logo/logo-meta.png";
    $page_author="$company";
    $page_keywords="".$company.", $page_name, $page_desc, ".$company_motto.", $company_desc";
    $page_url="".$dir."spcs/";
    require_once("../j_incs/metas.php");
    require_once("../j_incs/scripts-top.php");
    ?>
</head>
<body>
    
    <div class="app">
        <div class="layout">
            <?php 
            require_once("../j_incs/header.php");
            require_once("../j_incs/nav.php");
            ?>
            <!-- Page Container START -->
            <div class="page-container">
                

                <!-- Content Wrapper START -->
                <div class="main-content">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-md-1"></div>
                            <div class="col-md-10">
                                <div class="page-header">
									<div class="header-sub-title">
										<nav class="breadcrumb breadcrumb-dash">
											<a href="<?php echo $dir; ?>" class="breadcrumb-item"><i class="anticon anticon-dashboard m-r-5"></i>Dashboard</a>
											<!--<a class="breadcrumb-item" href="#"> </a>-->
											<span class="breadcrumb-item active"><?php echo $page_name; ?></span>
										</nav>
									</div>
								</div>
                            </div>
                        </div>
                    </div>
                     
                     <?php //require('../j_incs/balance.php'); ?>
                    
                    <div class="container-fluid">
                    <div class="row">
						<div class="col-md-1"></div>
                        <div class="col-md-10">
							<div class="tab-content m-t-15">
								<div class="tab-pane fade show active" id="tab-account">
								
										
									<div class="card">
										
										<div class="card-header">
											<h4><?php echo $page_name; ?></h4>
											<h6 class="">
												 <?php echo $page_desc; ?>
											</h6>
										</div>
										<div class="card-body">
										
											<?php if(!isset($_SESSION['j_admin'])){ ?>
											<p align="center">
												<img src="<?php echo $dir; ?>j_files/j_img/icons/empty-1.svg"/><br/>
												Not logged in!
											</p>

											<p class="text-center">
												Please login to your account or create an account for free to access <?php echo $p1_name; ?>
												<br/><br/>
												<a href="<?php echo $dir; ?>login/?url=<?php echo $url; ?>" class="app_btn">Login to your account</a>
												&nbsp; &nbsp; &nbsp;
												<a href="<?php echo $dir; ?>register/?url=<?php echo $url; ?>" class="app_btn bg-danger">Create Account</a>
											</p>
											<br/>
											<?php }  ?>
											
											<?php 
											$sql4="SELECT * from j_pays WHERE j_user_id='".$id."' AND j_kind='TRADING' AND j_deleted < 1 order by j_id desc"; //check 
											$result4 = runSQL($sql4);
											$inv_count = mysqli_num_rows($result4);
											?>
											
											<?php if(isset($_SESSION['j_admin']) && $inv_count < 1){ ?>
											<p align="center">
												<img src="<?php echo $dir; ?>j_files/j_img/icons/empty-1.svg"/><br/>
												Not Yet Invested!
											</p>

											<p class="text-center">
												Please invest with <?php echo $company; ?> to access <?php echo $p1_name; ?>
												<br/><br/>
												<a href="<?php echo $dir; ?>invest-now/?url=<?php echo $url; ?>" class="app_btn">Invest Now</a>
											</p>
											<br/>
											<?php }  ?>
											
											<?php if(isset($_SESSION['j_admin']) && $inv_count > 0){ 
											//check if i've invested
											$sql4="SELECT DISTINCT(j_user_id) from j_pays WHERE j_referrer_id='".$id."' AND j_kind='TRADING' AND j_deleted < 1 order by j_id desc"; //check 
											$result4 = runSQL($sql4);
											$total_ref = mysqli_num_rows($result4);
											//$total_ref = 60;
											$total_ref_main = $total_ref;
											//credit user here
											if($total_ref_main>=10 && $total_ref_main<30){  //level 1
												require_once("pay-1.php");
											}elseif($total_ref_main>=30 && $total_ref_main<60){ //level 2
												require_once("pay-2.php");
											}elseif($total_ref_main>=60 && $total_ref_main<100){ //level 3
												require_once("pay-3.php");
											}elseif($total_ref_main>=100 && $total_ref_main<150){ //level 4
												require_once("pay-4.php");
											}elseif($total_ref_main>=150){ //level 5
												require_once("pay-5.php");
											}
											?>
											<div id="loader"><h4 align='center' style='font-size:60px;'><i class='anticon anticon-loading' style='color:orange !important;'></i> </h4> <h6 align='center'>Loading SPCS, please wait...</h6></div>
											<div id="content" style="display:none;">
												<h6 class="">
													Use your 
													<a href="<?php echo $dir; ?>referral-link/">Referral Link</a> 
													to refer more and earn more on <?php echo $p1_name; ?>. 
													<a href="<?php echo $dir; ?>referrals/">View My Referrals</a> 
												</h6>
												<div class="table-responsive">
													<table class="table table-bordered">
														<thead>
															<tr>
																<th scope="col">Level</th>
																<th scope="col">Referrals</th>
																<th scope="col">Earning</th>
																<th scope="col">Status</th>
															</tr>
														</thead>
														<tbody>
															<?php $level_1_ref = 10; ?>
															<tr>
																<th scope="row">
																	Level 1 partner
																	<?php if($total_ref>=$level_1_ref){ echo '<i class="far fa-check-circle text-success"></i>';} ?>
																</th>
																<td><?php echo $level_1_ref; ?></td>
																<td><?php echo $currency_code_in_use; ?>200 dollar, 10% referral bonus</td>
																<td>
																	<?php if($total_ref>=$level_1_ref){ echo "$level_1_ref of $level_1_ref";}else{ echo "$total_ref of $level_1_ref"; } ?>
																</td>
															</tr>
															
															
															<?php 
															$level_2_ref = 20; 
															$total_ref=$total_ref_main-$level_1_ref; if($total_ref<=0){ $total_ref=0; }
															?>
															<tr>
																<th scope="row">
																	Level 2 partner
																	<?php if($total_ref>=$level_2_ref){ echo '<i class="far fa-check-circle text-success"></i>';} ?>
																</th>
																<td><?php echo $level_2_ref; ?></td>
																<td><?php echo $currency_code_in_use; ?>400 dollar, 15% referral bonus</td>
																<td>
																	<?php if($total_ref>=$level_2_ref){ echo "$level_2_ref of $level_2_ref";}else{ echo "$total_ref of $level_2_ref"; } ?>
																</td>
															</tr>
															
															
															<?php 
															$level_3_ref = 30; 
															$sub_total = $level_1_ref+$level_2_ref;
															$total_ref=$total_ref_main-$sub_total; if($total_ref<=0){ $total_ref=0; }
															?>
															<tr>
																<th scope="row">
																	Level 3 partner
																	<?php if($total_ref>=$level_3_ref){ echo '<i class="far fa-check-circle text-success"></i>';} ?>
																</th>
																<td><?php echo $level_3_ref; ?></td>
																<td><?php echo $currency_code_in_use; ?>600, 20% referral bonus</td>
																<td>
																	<?php if($total_ref>=$level_3_ref){ echo "$level_3_ref of $level_3_ref";}else{ echo "$total_ref of $level_3_ref"; } ?>
																</td>
															</tr>
															
															
															
															<?php 
															$level_4_ref = 40; 
															$sub_total = $level_1_ref+$level_2_ref+$level_3_ref;
															$total_ref=$total_ref_main-$sub_total; if($total_ref<=0){ $total_ref=0; }
															?>
															<tr>
																<th scope="row">
																	Level 4 partner
																	<?php if($total_ref>=$level_4_ref){ echo '<i class="far fa-check-circle text-success"></i>';} ?>
																</th>
																<td><?php echo $level_4_ref; ?></td>
																<td><?php echo $currency_code_in_use; ?>800, 25% referral bonus</td>
																<td>
																	<?php if($total_ref>=$level_4_ref){ echo "$level_4_ref of $level_4_ref";}else{ echo "$total_ref of $level_4_ref"; } ?>
																</td>
															</tr>
															
															
															<?php 
															$level_5_ref = 50; 
															$sub_total = $level_1_ref+$level_2_ref+$level_3_ref+$level_4_ref;
															$total_ref=$total_ref_main-$sub_total; if($total_ref<=0){ $total_ref=0; }
															?>
															<tr>
																<th scope="row">
																	Level 5 partner
																	<?php if($total_ref>=$level_5_ref){ echo '<i class="far fa-check-circle text-success"></i>';} ?>
																</th>
																<td><?php echo $level_5_ref; ?></td>
																<td><?php echo $currency_code_in_use; ?>1,000, 30% referral bonus</td>
																<td>
																	<?php if($total_ref>=$level_5_ref){ echo "$level_5_ref of $level_5_ref";}else{ echo "$total_ref of $level_5_ref"; } ?>
																</td>
															</tr>
															
															
															
														</tbody>
													</table>
												</div>
											</div>


											<?php } ?>
										</div>
									</div>
								 
								</div>
								
							</div>
                        </div>
                </div>
                <!-- Content Wrapper END -->

                <?php
                require_once("../j_incs/footer.php");
                ?>

            </div>
            <!-- Page Container END -->
        </div>
    </div>
    
    
    <?php
    require_once("../j_incs/scripts-bottom.php");
    ?>
    <script>
		$(document).ready(function(){
			$("#loader").hide();
			$("#content").show();
		});
		 $("[name=amount_usd]").keyup(function(){
            var a = $("[name=amount_usd]").val();
            var d = $("[name=duration]").val();
            var c = $("[name=wallet_type]").val();
            if(a!=="" && d!=="" && c!==""){
              $.ajax({
                url: '<?php echo $dir;  ?>invest-now/calculator.php?a='+a+'&d='+d+'&c='+c+'',
                method: 'post',
                success: function (data) {
                     $("#lt").html(data);
                 }
              });
            }
          });
			
		
        $("[name=duration]").change(function(){
            var a = $("[name=amount_usd]").val();
            var d = $("[name=duration]").val();
            var c = $("[name=wallet_type]").val();
            if(a!=="" && d!=="" && c!==""){
              $.ajax({
                url: '<?php echo $dir;  ?>invest-now/calculator.php?a='+a+'&d='+d+'&c='+c+'',
                method: 'post',
                success: function (data) {
                     $("#lt").html(data);
                 }
              });
            }
          });
		  
		$("[name=wallet_type]").change(function () {
			$("[name=amount]").val('');
			$("[name=amount_usd]").val('');
			var  wallet_type_id = $("[name=wallet_type]");
			var  addressInfo_id = $(".addressInfo");
			var wallet_type_val = wallet_type_id.val();
			if(wallet_type_val !==''){
				addressInfo_id.html(wallet_type_val);
			}
		});
		$("[name=amount_usd]").keyup(function () {
			var  amount_crypto = $("[name=amount]");
			var  amount_usd = $("[name=amount_usd]");
			var  currency = $("[name=wallet_type]").val();
			var  amount_crypto_val = amount_crypto.val();
			var  amount_usd_val = amount_usd.val();
			var  rateResult = $("[name=amount]");
			if(currency !=='' && amount_usd !==''){
				amount_crypto.val('***');
				amount_crypto.attr('disabled','');
				$.post('<?php echo $dir; ?>wallet-topup/rate-usd.php', 
				{
					currency:currency,
					amount_crypto_val:amount_crypto_val,
					amount_usd_val:amount_usd_val,
				},function(data){
					if(data){
						rateResult.html(data);
						//amount_crypto.removeAttr('disabled'); 
					}else{
						amount_crypto.val('');
						//amount_crypto.removeAttr('disabled'); 
					}
				});
			}
		});
		
		
		
		$("[name=amount]").keyup(function () {
			var  amount_crypto = $("[name=amount]");
			var  amount_usd = $("[name=amount_usd]");
			var  currency = $("[name=wallet_type]").val();
			var  amount_crypto_val = amount_crypto.val();
			var  amount_usd_val = amount_usd.val();
			var  rateResult = $("[name=amount]");
			if(currency !=='' && amount_crypto !==''){
				amount_usd.val('***');
				amount_usd.attr('disabled','');
				$.post('<?php echo $dir; ?>wallet-topup/rate-crypto.php', 
				{
					currency:currency,
					amount_crypto_val:amount_crypto_val,
					amount_usd_val:amount_usd_val,
				},function(data){
					if(data){
					   rateResult.html(data);
						amount_usd.removeAttr('disabled'); 
					}else{
						amount_usd.val('');
						amount_usd.removeAttr('disabled'); 
					}
				});
			}
		});
		
		
       
        
        
        var form = "#form";
        var button = "#submit";
        var button_val = $(button).html();
        var result = "#formresult";
        $(form).on('submit',(function(e) {
        e.preventDefault();
        $(button).attr('disabled', '');
        $(button).html("<i class='anticon anticon-loading'></i> Processing");
        $(result).html("<div class='alert alert-warning'> Taking too long? <a href=''>Reload </a></div>");
         $.ajax({
        url: "save.php",
        type: "POST",
        data: new FormData(this),
        contentType: false,
        cache: false,
        processData:false,
        success: function(data)
        {
        if(data){
         $(button).removeAttr('disabled');
        $(button).html(button_val);
        $(result).html(data);
        }else{
        $(result).html("Error occurred.");
        $(button).removeAttr('disabled');
        $(button).html(button_val);
        }
        }
        });
        }));
        </script>
   
</body>
</html>