<?php 	
    include_once('../../config.php');   	
    include_once(ABS_PATH.'/admin/login_check.php');     
    
        
        
                    if(isset($_POST['dnExc']))
                    {          
                            
                            header('Content-type: text/csv');
                            $date = "Customer-".date("d-M-Y")." Report";
                            header('Content-Disposition: attachment; filename=""'.$date.'".csv"'); 
                            // do not cache the file
                            header('Pragma: no-cache');
                            header('Expires: 0');
                              
                              
                            $file = fopen('php://output', 'w'); 
                            // send the column headers
                            fputcsv($file, array('UserId','Name','Phone'));   
                            $AllUsers = explode(",",$_POST['idS']);
                            
                            foreach ($AllUsers as $dt)
                            {        
                                    $stmt=$conn->prepare("select cuurentId,nm,phm  from   UI__Rgst where cuurentId=:cuurentId ");  
                                    $stmt->bindValue(':cuurentId', trim($dt) , PDO::PARAM_STR);
                                    $stmt->execute();  
                                    $Mnnnt = $stmt->fetch(PDO::FETCH_OBJ); 
                                    
                                    $Disk = null;
                                    $Disk['cuurentId'] = $Mnnnt->cuurentId;    
                                    $Disk['nm'] = $Mnnnt->nm;    
                                    $Disk['phm'] = $Mnnnt->phm;    
                                    fputcsv($file, $Disk);    
                            
                            } 
                        fclose($fp);     
                        die;
                         
                }
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');
	}
	});
	
	}	  
	
}


function AutoPay(cuurentId,key)
{   
    
    window.location.href = "WithaddAccount.php?amount="+$("#amt"+key).val()+"&cuurentId="+cuurentId;  
    
}


$( 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>Auto  Users Withdrawls List </h3></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>Phone</th>   
								<th>Wallet</th>  
								<th>TopUp</th>  
								<th>Amout</th>  
								<th>Action</th>  
							</tr>
						</thead>
						<tbody>
							<?php
                                    $stmt=$conn->prepare("select  * from  UI__Rgst where is_active = 1  and (autoWithdrawls) order by id");  
                                    //$stmt->bindValue(':Ttime', $InTime , PDO::PARAM_STR);
                                    $stmt->execute(); 
                                    $AllUsers = $stmt->fetchAll(PDO::FETCH_OBJ); 
                                    $sr = 1;
								  foreach($AllUsers as $ky=>$users)
								  {    
							          
							        $stmt=$conn->prepare("select  id,amt from   UI__DChstr where Rid=:sId  and typ=1");  
                                    $stmt->bindValue(':sId', $users->cuurentId , PDO::PARAM_STR);
                                    $stmt->execute();  
                                    $count = $stmt->rowCount();
                                    $AllTp = $stmt->fetchAll(PDO::FETCH_OBJ);   
                                    
                                    $Mtp = 0;
                                    foreach($AllTp as $mppp)
                                        $Mtp +=$mppp->amt; 
                                     
							?>
							<tr class="odd gradeX">
								<td><?php echo $sr++;?> </td>
								<td><a href="topuptlist.php?cuurentId=<?php echo $users->cuurentId;?>"><?php echo $users->nm;?></a></td>
								<td><?php echo $users->cuurentId;?></td>
								 
								<td><?php    echo $users->phm;?>  </td>  
								 
								 
								<td>
								        <span id="MyBal<?php echo $sr;?>"><a href="javascript:void(0);" onclick="GetBalance(<?php echo $sr;?>,'<?php echo $users->cuurentId;?>')">View</a></span>
								        <?php // if($users->cuurentId!='DP112233') echo  GetBalance($users->cuurentId);?> 
							    </td>   
								<td> <?php echo $Mtp;//if($count > 0) echo "Active"; ?>  </td>      
								<td>  <input type="number"  name="amt<?php echo $ky?>"  id="amt<?php echo $ky?>" >   </td>      
								<td> 
								             <a class="btn btn-warning" href="javascript:void(0);" onclick="AutoPay('<?php echo $users->cuurentId;?>',<?php echo $ky?>)" >Pay</a> 
								             /
								             <a href="editAutoListUsers.php?id=<?php echo $users->id;?>"> Edit </a>
								</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';	?>    