<?php 	
    include_once('../../config.php');   	
    include_once(ABS_PATH.'/admin/login_check.php');     
    
        
        
                   
                
              
			 
		    function Refcall($ref)
            {
                global $conn;
                $stmt=$conn->prepare("select cuurentId   from UI__Rgst where refId =:cuurentId ");   
                $stmt->bindValue(':cuurentId', $ref , PDO::PARAM_INT);  
                $stmt->execute(); 
                $Result = $stmt->fetchAll(PDO::FETCH_OBJ);   
                return $Result;
            }
            
             
            $stmt=$conn->prepare("select cuurentId from UI__Rgst where cuurentId =:cuurentId ");   
            $stmt->bindValue(':cuurentId', $_REQUEST['UserId']  , PDO::PARAM_STR);  
            $stmt->execute(); 
            $Result = $stmt->fetch(PDO::FETCH_OBJ);  
            $myRefId = $Result->cuurentId;
              
            $stmt=$conn->prepare("select cuurentId   from UI__Rgst where refId =:cuurentId ");   
            $stmt->bindValue(':cuurentId', $Result->cuurentId  , PDO::PARAM_INT);  
            $stmt->execute(); 
            
           
            
            $myTT = 0;
            if($stmt->rowCount()>0)
            { 
                $Result = $stmt->fetchAll(PDO::FETCH_OBJ);     
                foreach($Result as $dtm) 
                    $stepCt['step1']['id'][] = $dtm->cuurentId;
                    
                    
                $myTT +=count($stepCt['step1']['id']);       
                foreach($Result as $dtm) 
                    $stepCt['step2']['id'][] =  Refcall($dtm->cuurentId); 
                
            } 
              
              
            for($i=0;$i<count($stepCt['step2']['id']);$i++)
            {
                 
                if(count($stepCt['step2']['id'][$i])>0)
                {
                       $myTT +=count($stepCt['step2']['id'][$i]);     
                       
                   foreach($stepCt['step2']['id'][$i] as $dtm)
                     $stepCt['step3']['id'][] =  Refcall($dtm->cuurentId);  
                }
                
            } 
             
             
             
            
            
            for($i=0;$i<count($stepCt['step3']['id']);$i++)
            {
                 
                if(count($stepCt['step3']['id'][$i])>0)
                {
                     $myTT +=count($stepCt['step3']['id'][$i]);     
                     
                   foreach($stepCt['step3']['id'][$i] as $dtm)
                     $stepCt['step4']['id'][] =  Refcall($dtm->cuurentId);  
                }
            } 
            
            
            for($i=0;$i<count($stepCt['step4']['id']);$i++)
            {
                 
                if(count($stepCt['step4']['id'][$i])>0)
                {
                    
                   $myTT +=count($stepCt['step4']['id'][$i]);   
                   
                   foreach($stepCt['step4']['id'][$i] as $dtm)
                     $stepCt['step5']['id'][] =  Refcall($dtm->cuurentId);  
                }
            } 
            
            
            for($i=0;$i<count($stepCt['step5']['id']);$i++)
            {
                 
                if(count($stepCt['step5']['id'][$i])>0)
                {
                    $myTT +=count($stepCt['step5']['id'][$i]);   
                      
                   foreach($stepCt['step5']['id'][$i] as $dtm)
                     $stepCt['step6']['id'][] =  Refcall($dtm->cuurentId);  
                }
            } 
            
            
            for($i=0;$i<count($stepCt['step6']['id']);$i++)
            {
                 
                if(count($stepCt['step6']['id'][$i])>0)
                {
                    $myTT +=count($stepCt['step6']['id'][$i]);   
                      
                   foreach($stepCt['step6']['id'][$i] as $dtm)
                     $stepCt['step7']['id'][] =  Refcall($dtm->cuurentId);  
                }
            } 
            
            for($i=0;$i<count($stepCt['step7']['id']);$i++)
            {
                 
                if(count($stepCt['step7']['id'][$i])>0)
                {
                    $myTT +=count($stepCt['step7']['id'][$i]);   
                      
                   foreach($stepCt['step7']['id'][$i] as $dtm)
                     $stepCt['step8']['id'][] =  Refcall($dtm->cuurentId);  
                }
            }
            
            
            for($i=0;$i<count($stepCt['step8']['id']);$i++)
            {
                 
                if(count($stepCt['step8']['id'][$i])>0)
                {
                    $myTT +=count($stepCt['step8']['id'][$i]);   
                      
                   foreach($stepCt['step8']['id'][$i] as $dtm)
                     $stepCt['step9']['id'][] =  Refcall($dtm->cuurentId);  
                }
            }
            
            
            for($i=0;$i<count($stepCt['step9']['id']);$i++)
            {
                 
                if(count($stepCt['step9']['id'][$i])>0)
                {
                    $myTT +=count($stepCt['step9']['id'][$i]);   
                      
                   foreach($stepCt['step9']['id'][$i] as $dtm)
                     $stepCt['step10']['id'][] =  Refcall($dtm->cuurentId);  
                }
            }   
            
            for($i=0;$i<count($stepCt['step10']['id']);$i++)
            {
                 
                if(count($stepCt['step10']['id'][$i])>0)
                {
                    $myTT +=count($stepCt['step10']['id'][$i]);   
                      
                   foreach($stepCt['step10']['id'][$i] as $dtm)
                     $stepCt['step11']['id'][] =  Refcall($dtm->cuurentId);  
                }
            }   
            
            
            for($i=0;$i<count($stepCt['step11']['id']);$i++)
            {
                 
                if(count($stepCt['step11']['id'][$i])>0)
                {
                    $myTT +=count($stepCt['step11']['id'][$i]);   
                      
                   foreach($stepCt['step11']['id'][$i] as $dtm)
                     $stepCt['step12']['id'][] =  Refcall($dtm->cuurentId);  
                }
            }   
            
            
            for($i=0;$i<count($stepCt['step12']['id']);$i++)
            {
                 
                if(count($stepCt['step12']['id'][$i])>0)
                {
                    $myTT +=count($stepCt['step12']['id'][$i]);   
                      
                   foreach($stepCt['step12']['id'][$i] as $dtm)
                     $stepCt['step13']['id'][] =  Refcall($dtm->cuurentId);  
                }
            }   
            
            for($i=0;$i<count($stepCt['step13']['id']);$i++)
            {
                 
                if(count($stepCt['step13']['id'][$i])>0)
                {
                    $myTT +=count($stepCt['step13']['id'][$i]);   
                      
                   foreach($stepCt['step13']['id'][$i] as $dtm)
                     $stepCt['step14']['id'][] =  Refcall($dtm->cuurentId);  
                }
            }   
            
            for($i=0;$i<count($stepCt['step14']['id']);$i++)
            {
                 
                if(count($stepCt['step14']['id'][$i])>0)
                {
                    $myTT +=count($stepCt['step14']['id'][$i]);   
                      
                   foreach($stepCt['step14']['id'][$i] as $dtm)
                     $stepCt['step15']['id'][] =  Refcall($dtm->cuurentId);  
                }
            } 
            
                
              
            
            $stmt=$conn->prepare("select  nm from  UI__Rgst where  cuurentId=:cuurentId");  
            $stmt->bindValue(':cuurentId', $_REQUEST['UserId'] , PDO::PARAM_STR);
            $stmt->execute(); 
            $UserId = $stmt->fetch(PDO::FETCH_OBJ);
          
                
include ABS_PATH.'/admin/header.php';	        
?>  
        

<script>
            
            function GetBalance(sr,Id)
            {
                
                    $.ajax({
                    type: 'POST',
                    url: "../../config.php",
                    //async: false,			 
                    data: {gtMybal:1,Id:Id,bYadmin:1},	  
                    success: function(ajaxresult)
                    {	      
                        $("#MyBal"+sr).html(ajaxresult);     
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) 
                    { 
                    
                            alert('Error');
                            
                    }
                    });
            
            }
	
function del_record(val)
{

	var r = confirm("Do you really want to delete record !");
	if (r == true) {    
	$.ajax({
	type: 'POST',
	url: "../ajax/default.php",
	//async: false,			 
	data: {del_city_names:1,val:val},	  
	success: function(ajaxresult){	     
		location.reload();	 	
	},
	error: function(XMLHttpRequest, textStatus, errorThrown) { 
	alert('Error');
	}
	});
	
	}	  
	
}



$( document ).ready(function() 
{  
   
     
     
});

var fruits = [];  
function ckkl(i)
    {
        
     
         $('#Chxk'+i).prop('checked', true); 
         fruits.push(i); 
         var  text = fruits.toString();    
         $("#idS").val(text);   
    }  
</script>
		 
		<div class="col-md-10">  
  			<div class="content-box-large">
  			    <form method="post" autocomplete="off"> 
  				<div class="panel-heading">
					<div class="panel-title"><h3>  <?php echo $UserId->nm;?>: Downline Level <?php echo $_REQUEST['level'];?> </h3></div>
					
			        <div align="right">  
					    <input type="submit"    class="btn btn-warning"  value="download Excel" name="dnExc"/>
					    <!--a href="javascript:void(0);" class="btn btn-warning" id="checkAll"> Test  </a-->
					</div>
					
				</div>
				
  				<div class="panel-body">
  					<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
						<thead>
							<tr>
								<th>Sr</th>
								<th>Name</th>  	  
								<th>UserID</th>   
								<th>Login Pin</th>   
								<th>Topup Amount</th>   
							</tr>
						</thead>
						<tbody>
							<?php
                                    
                                  $sr = 1; 
								  foreach($stepCt['step'.$_REQUEST['level']]  as $dtm)
								  {         
                                            
                                         
                                            foreach($dtm  as $mmt)
                                            {
                                            
                                                $stmt=$conn->prepare("select *  from UI__Rgst where cuurentId=:cuurentId ");   
                                                $stmt->bindValue(':cuurentId', $mmt , PDO::PARAM_STR);  
                                                $stmt->execute(); 
                                                $Result = $stmt->fetch(PDO::FETCH_OBJ); 
                                                
                                                $stmt=$conn->prepare("select  id,amt from   UI__DChstr where Rid=:sId  and typ=1");  
                                                $stmt->bindValue(':sId', $mmt  , PDO::PARAM_STR);
                                                $stmt->execute();   
                                                $UI__DChstr = $stmt->fetchAll(PDO::FETCH_OBJ); 
                                                
                                                $topM = 0;
                                                foreach($UI__DChstr  as $mp)
                                                    $topM +=$mp->amt; 

							?>
							<tr class="odd gradeX">
								<td><?php echo $sr++;?> </td>
								<td><?php echo $Result->nm;?></td>
								<td><?php echo $mmt;?></td> 
								<td><?php echo $Result->UserPin;?></td> 
								<td><?php echo $topM;?></td> 
								
							</tr>  
							<?php 
                                                    
                                            }
								  
							    }
							?>
						</tbody>
					</table>
  				</div>
  				
  				<input name="idS"   id="idS" type="hidden" /> 
  				</form>
  			</div>  
		  </div>
		  
		</div>
    </div>

<?php  include ABS_PATH.'/admin/footer.php';	?>    