<?php
include_once('../config.php');   
include_once(ABS_PATH.'/custom_function/default.php'); 
 
if(!isset($_SESSION['userId']))
{ 
header("Location: ../");
die;
} 
                
                
                            
                                
                            
                     

                    
                           
    if(isset($_POST['submit'])) 
    {              
        
				$_POST['amount'] = 10000;	
				$_POST['pinno'] = "787980";
				$PAYWAllet =  GetBalance();  
                 
                       
				 
				    
				 
                    $stmt=$conn->prepare("select *   from    UI__TpDys");     
                    $stmt->execute();   
                    $dateOfra = $stmt->fetch(PDO::FETCH_OBJ); 
                                        
					$stmt =  $conn->prepare("insert into UI__Atw (custId,Tdate,Amt,dys,status) values(:custId,:Tdate,:Amt,:dys,1)");             
					$stmt->bindValue(':Tdate', date("d-M-Y H:i"), PDO::PARAM_STR);
					$stmt->bindValue(':custId', $_SESSION['userId'], PDO::PARAM_STR);
					$stmt->bindValue(':Amt', $_POST['amount'], PDO::PARAM_INT);
					$stmt->bindValue(':dys', $dateOfra->ATWdys, PDO::PARAM_INT);
				  	$stmt->execute();
						   
						   
					$stmt=$conn->prepare("insert into UI__WithDraw(userid,Tdate,amt,status,accept) values(:userid,:Tdate,:amt,:status,:accept)"); 
					$stmt->bindValue(':userid',   $_SESSION['userId']  , PDO::PARAM_STR);   
					$stmt->bindValue(':Tdate',  date("d-M-Y H:i") , PDO::PARAM_STR);   
					$stmt->bindValue(':amt', $_POST['amount'] , PDO::PARAM_STR);  
					$stmt->bindValue(':status', "AWT Transfered" , PDO::PARAM_STR); 
					$stmt->bindValue(':accept', 1 , PDO::PARAM_STR);     
					$stmt->execute();
    
    
               
				 
					LvBal($_SESSION['userId'],$_POST['amount'],2,"AWT Transfered",$_SESSION['userId']); 

					$stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
					$stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_STR);  
					$stmt->execute();
					$UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);  


					$stmt=$conn->prepare("insert into UI__Receipt(type,bank,mobile,email,amountPaid,Tid,status,Tdate,custId,cdId,Topay,TopayName) values(:type,:bank,:mobile,:email,:amountPaid,:Tid,:status,:Tdate,:custId,:cdId,:Topay,:TopayName)"); 
					$stmt->bindValue(':type',   17 , PDO::PARAM_STR);   
					$stmt->bindValue(':bank',  "Wallet" , PDO::PARAM_STR);   
					$stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
					$stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
					$stmt->bindValue(':amountPaid', $_POST['amount']  , PDO::PARAM_STR); 
					$stmt->bindValue(':Tid', mt_rand(1234552,23555), PDO::PARAM_STR); 
					$stmt->bindValue(':status', 1 , PDO::PARAM_STR); 
					$stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);      
					$stmt->bindValue(':custId', $_SESSION['userId']  , PDO::PARAM_STR);  
					$stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
					$stmt->bindValue(':Topay',  $_SESSION['userId']   , PDO::PARAM_STR); 
					$stmt->bindValue(':TopayName',  $_SESSION['userId']  , PDO::PARAM_STR);     
					$stmt->execute();     
					$LastIntId= $_SESSION['LastIntId'];
					unset($_SESSION['LastIntId']);      
					
					
					 
					     
					$_SESSION['Regis'] = "Transaction successful";
					$_SESSION['topSuc'] = 1;  
						
					$subject = "AWT Transfer  On ".$SITE_NAME;  
					$template_type = 1;
					$attachment = '';
					$name = $beneficiary_name;
					$Amt = $_POST['amount'];
					
					$message="
					<tr>
					<td align='left' valign='top'>
					<h4 style='font-weight:bold; padding:2px 2px; margin:3px; text-align:left; color:#002368;'>Dear user,</h4>
					<h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'>Thanks for Money Transfer with us. Your Details are as follows </h5> 
					<h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'> To: $name , Amount Rs : $Amt </h5>
					
					</td>
					</tr>"; 
					
					SendMail($EMAIL->eml,$subject,$message,$template_type,$attachment);   
					$mob = $UI__Rgst->phm; 
					$iD = $_SESSION['userId'];
					$am = $_POST['amount'];
					$msg = urlencode('Dear '.$iD.', Congratulations, your TOPUP amount Rs. '.$am.' has been successfully done, DailyPay team.'); 
                    $URL  = 'http://mobicomm.dove-sms.com//submitsms.jsp?user=DailyPAY&key=d92eabc025XX&mobile=+91'.$mob.'&message='.$msg.'&senderid=DAYPAY&accusage=1&entityid=1201169824017740929&tempid=1207169907140786246';
                
					
					$crl = curl_init();
					curl_setopt($crl, CURLOPT_URL, $URL);
					curl_setopt($crl, CURLOPT_FRESH_CONNECT, true);
					curl_setopt($crl, CURLOPT_RETURNTRANSFER, true); 
					$response = curl_exec($crl);
					
					$stmt =  $conn->prepare("insert into UI__Tlimits (custId,Tdate,amt,type) values(:custId,:Tdate,:amt,2)  ");   
					$stmt->bindValue(':custId', $_SESSION['userId'], PDO::PARAM_STR);
					$stmt->bindValue(':Tdate', date("d-M-Y"), PDO::PARAM_STR);
					$stmt->bindValue(':amt', $_POST['amount'], PDO::PARAM_STR);
					$stmt->execute();  
					
					echo $LastIntId; 
					die;   
            }  
	
	                        
                            
        include_once("../view/dashboard/atw2.php");
?>