<?php 	include_once('../../config.php'); 
		 
          
			if(isset($_POST['submit']))
			{ 
			        if($_POST['WalletAmount'] >0)
			        {
                    $stmt=$conn->prepare("select  cust_id from   pw__usr  where ph_no=:ph_no");  
                    $stmt->bindValue(':ph_no', $_POST['PhNo'] , PDO::PARAM_STR);
                    $stmt->execute();  
                    $starlineR = $stmt->fetch(PDO::FETCH_OBJ);  
			        
                    $stmt=$conn->prepare("insert into  pw__admTxn   (admId,amt,tDate,custId,type) values(:admId,:amt,:tDate,:custId,:type) ");  
                    $stmt->bindValue(':admId', $_SESSION['adminId'] , PDO::PARAM_STR);
                    $stmt->bindValue(':amt', $_POST['WalletAmount'] , PDO::PARAM_STR);
                    $stmt->bindValue(':tDate', date("d-M-Y H:i:s") , PDO::PARAM_STR);
                    $stmt->bindValue(':custId', $starlineR->cust_id , PDO::PARAM_STR); 
                    $stmt->bindValue(':type', 1, PDO::PARAM_STR);  
                    $stmt->execute();  
                    
                    $stmt=$conn->prepare("select  amt from  pw__normal  where custId=:custId");  
                    $stmt->bindValue(':custId',  $starlineR->cust_id  , PDO::PARAM_STR);
                    $stmt->execute();  
                    $dtm = $stmt->fetch(PDO::FETCH_OBJ);     
                    
                    $decrypted = openssl_decrypt(hex2bin($dtm->amt),'AES-128-CBC',$Pwdkey);  
                    $encrypted_pwd = bin2hex(openssl_encrypt(($decrypted-$_POST['WalletAmount']),'AES-128-CBC', $Pwdkey));    
                      
                    $stmt=$conn->prepare("update  pw__normal set amt=:amt where custId=:custId ");   
                    $stmt->bindValue(':amt', ($encrypted_pwd), PDO::PARAM_STR);   
                    $stmt->bindValue(':custId', $starlineR->cust_id , PDO::PARAM_STR); 
                    $stmt->execute();    
                    
              
                        
                    $_SESSION['WltMsg'] = "Wallet updated";
                    header("Location: subwallet.php");  
                    die;
			        }
			}   
		 
?>  
<?php  include ABS_PATH.'/admin/header.php';	?>  


 <script>
 
var URL  = '<?php echo ROOTPATH;?>';  
	$(function() {
		$( "#datepicker" ).datepicker(); 
	}); 
  
	$(document).ready(function()
	{   

	
	$("#product_frm").validate({
		
		errorElement:'div',
		rules:{ 
			city:{
				required:true				 
			} 
			
			
			
		},
		messages:{				
			 
			 city:{
				required:"Enter city name"				 
			} 
		}
	});


	});
 
function Verify()
{
    
    $.ajax({	
    type: "POST",
    url: URL+"/admin/ajax/default.php",
    data: {Verify:1,phoneNo:$("#PhNo").val()},	
    beforeSend: function(){ 
    
    },
    success: function(val)
        {      
           var dm = jQuery.parseJSON(val); 
           if(dm['found']==1) 
                $("#Verydata").html(dm['name']+",<BR> "+dm['cust_id']);
           else
                $("#Verydata").html("Please check phone no");
            
        }
    });  
}


</script>
 
		 <div class="col-md-10">

	  			<div class="row">
	  				<div class="col-md-12">
	  					<div class="content-box-large">
							<div class="panel-heading">
								<div class="panel-title"> <h3> Sutract  Wallet </h3> <span style="color:green;"> <?php echo  $_SESSION['WltMsg'];?></span></div>    
								
								<div class="panel-options"> 

								   <input type="button"  class="btn btn-warning" name="btnback" id="btnback" value=" Back " onClick="javascript:location.href='../users/registered_users.php';" />
								  
								</div>
							  
								 
							</div>
							
							
			  				<div class="panel-body">    
			  					<form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" id="product_frm" autocomplete="off"> 
								
							 
								 
								 <div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">Phone</label>
								    <div class="col-sm-3">
								      <input name="PhNo" id="PhNo" class="form-control"   placeholder="Phone No"   required>
								      <a href="javascript:void(0);" onclick="Verify();">Verify: </a> <BR>
								      <span id="Verydata"></span>
								    </div>
								 </div>
								 <hr>
								  <div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">Wallet Amount</label>
								    <div class="col-sm-3">
								      <input name="WalletAmount" class="form-control"   placeholder="Wallet Amount"   required>
								    </div>
								 </div>
								 <hr>
								   
								  
								  <div class="form-group">
										<label for="inputEmail3" class="col-sm-2 control-label">Sutract User</label>
										<div class="col-sm-10">
										  <input type="submit"    class="btn btn-primary"  name="submit" value="Sutract Wallet">
										</div>
								  </div>   
								</form>
								
								
							
			  				</div>
			  			</div>
	  				</div>
	  				 
	  			</div>

	  			 


	  		<!--  Page content -->
		  </div>
		</div>
    </div>

<?php  include ABS_PATH.'/admin/footer.php'; unset($_SESSION['WltMsg']);	?>    