<?php 	include_once('../../config.php');   	
		include_once(ABS_PATH.'/admin/login_check.php');   
		
		   if(isset($_POST['SubmitVal']))
		   {  
		           
		        $TransferSeledct = explode(",",$_POST['search']);  
                $stmt=$conn->prepare("select custId from UI__Rgst where cuurentId=:cuurentId");   
                $stmt->bindValue(':cuurentId', trim($TransferSeledct[0]) , PDO::PARAM_STR);  
                $stmt->execute();   
                $result = $stmt->fetch();
                 
		         
		       foreach($_POST['chckVal'] as $dmt)
		       {      
		           
                    $id = $_POST['chckValId'][$dmt];    
                    $stmt=$conn->prepare("update UI__PnMX set Transfered=:Transfered where id=:id");   
                    $stmt->bindValue(':Transfered', $result['custId'] , PDO::PARAM_STR);
                    $stmt->bindValue(':id', $id , PDO::PARAM_STR);  
                    $stmt->execute();   
                    
                    $stmt=$conn->prepare("insert into UI__PinHistr (PinId,trasferTo,TranferBy,Tdate) values(:PinId,:trasferTo,:TranferBy,:Tdate) ");   
                    $stmt->bindValue(':PinId', $id , PDO::PARAM_STR);
                    $stmt->bindValue(':trasferTo', $result['custId'] , PDO::PARAM_STR);
                    $stmt->bindValue(':TranferBy', 'Admin' , PDO::PARAM_STR);
                    $stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR); 
                    $stmt->execute();       
		       }
		       
		       header("Location: ".ROOTPATH."/admin/wallet/subwallet.php");
		       die;
		   }     
		     
?>  
<?php  include ABS_PATH.'/admin/header.php';	?>  

<script>
var URL  = '<?php echo ROOTPATH;?>';  

 

function del_record(val)
{

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


$(document).ready(function () 
{    
     
    var Ctm = $("#CheckCount").val();     
    $("#checkAll").click(function()
    {        
        for(var i=0;i<=Ctm;i++)
        {
            $('#checkCheck'+i).prop('checked', true);    
        } 
    });
       
        


  // Send Search Text to the server
  $("#search").keyup(function () {
    let searchText = $(this).val();
    if (searchText != "") {
      $.ajax({
        url: "action.php",
        method: "post",
        data: {
          query: searchText,
        },
        success: function (response) {
          $("#show-list").html(response);
        },
      });
    } else {
      $("#show-list").html("");
    }
  });
  // Set searched text in input field on click of search button
  $(document).on("click", "a", function () {
    $("#search").val($(this).text());
    $("#show-list").html("");
  });
  
});

</script>
		 
		<div class="col-md-10">  
  			<div class="content-box-large">
  				<div class="panel-heading">
					<div class="panel-title"><h3>Pin List </h3></div>
					
					<div align="right"> 
								    <a  class="btn btn-warning"  href="subwallet.php" > Back </a>
								    <span id="checkAll" class="btn btn-primary"  >Check All</span>
			         </div>  
			
				</div>
				
  				<div class="panel-body">
  				    <form method="post" autocomplete="off" >
  					<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
						<thead>
							<tr>
								<th>Sr</th>  
								<th>Pin Value</th> 
								<th>Pin Status</th> 
								<th>Plan</th>  
								<th>Transfered </th>     
								<th>Created Date</th> 
								<th>Action</th> 
							</tr>
						</thead>
						<tbody>
					
							<?php
                                    $stmt=$conn->prepare("select  * from  UI__PnMX  where PhNo=:PhNo ");  
                                    $stmt->bindValue(':PhNo', $_REQUEST['Rd'] , PDO::PARAM_STR);
                                    $stmt->execute(); 
                                    $AllUsers = $stmt->fetchAll(PDO::FETCH_OBJ); 
                                    $sr = 1;
								  foreach($AllUsers as $ky=>$users)
								  {    
							                     
                                     if($users->AMMT==1)
                                        $plan = "1000";    
                                        
                                    $stmt=$conn->prepare("select   nm from   UI__Rgst  where custId=:custId ");    
                                    $stmt->bindValue(':custId', $users->Transfered, PDO::PARAM_STR);
                                    $stmt->execute(); 
                                    $custId = $stmt->fetch(PDO::FETCH_OBJ); 
                            
							?>
							<tr class="odd gradeX">
								<td><?php echo $sr++;?> </td>
								<td><?php echo $users->MPin;?></td>
								<td><?php  if($users->exp==1) echo "Used"; else echo "Active";?>  </td> 
								<td><?php echo $plan;?>  </td>  
								<td><?php echo $custId->nm;;?>  </td>   
								<td><?php echo $users->createdOn;?>  </td>        								 
								<td> 
								         <input type="checkbox" name="chckVal[<?php echo $ky;?>]" id="checkCheck<?php echo $ky;?>" value="<?php echo $ky;?>">
								         <input type="hidden" name="chckValId[<?php echo $ky;?>]" value="<?php echo $users->id;?>">
								</td> 
							</tr>  
							<?php } ?>
							<input type="hidden" value="<?php  echo $ky; ?>" id="CheckCount" /> 
						</tbody>
						
					</table>
					
					
					<?php 
                            $stmt=$conn->prepare("select   nm,custId from   UI__Rgst  where master=0  ");    
                            //$stmt->bindValue(':PhNo', $_REQUEST['Rd'] , PDO::PARAM_STR);
                            $stmt->execute(); 
                            $AllUsers = $stmt->fetchAll(PDO::FETCH_OBJ); 
                             
				    ?>  
    				 <div class="form-group"> 
    				    <div class="col-sm-3">   
            					  <input type="text" name="search" id="search" class="form-control " placeholder="Search...">
            					  <div class="list-group" id="show-list"></div>
          
    				    </div> 
    				    <!--div class="col-sm-3">   
                					<select name="TransferSeledct" id="TransferSeledct" class="form-control" >
                					    <?php 
                					        foreach($AllUsers as $dmt) 
                					        {
                					    ?>
                					        <option value="<?php echo $dmt->custId;?>"><?php echo $dmt->nm;?></option>   
                					    <?php } ?>
                					</select>  
    				    </div-->      
    				 </div>  
    				 
    				 <div class="form-group"> 
    				    <div class="col-sm-3">  
    				    
                		        <input type="submit" name="SubmitVal" value="Transfer Now" class="btn btn-warning" />			
    				    </div> 
    				 </div>   
    				 
					</form>
  				</div>
  			</div>



		  </div>
		</div>
    </div>

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