<?php
	include_once('../config.php');   
    
  
          
    if(!isset($_SESSION['userId']))
    { 
         header("Location: ../");
         die;
    }  
                
                if(isset($_POST['submittXNpIN']))
                {        
                    
                    $stmt=$conn->prepare("select txnpwd,phm  from  UI__Rgst   where cuurentId=:cuurentId ");    
                    $stmt->bindValue(':cuurentId', $_SESSION['userId'] , PDO::PARAM_STR); 
                    $stmt->execute();   
                    $FResult = $stmt->fetch(PDO::FETCH_OBJ);
                    
                    $iD = $_SESSION['userId'];    
                    $digits = 6; 
                    $PWWF =  rand(pow(10, $digits-1), pow(10, $digits)-1);      
                    $stmt=$conn->prepare("update UI__Rgst set txnpwd=:txnpwd where cuurentId=:cuurentId ");    
                    $stmt->bindValue(':txnpwd',   hash('sha256', $PWWF), PDO::PARAM_STR);   
                    $stmt->bindValue(':cuurentId',  $iD , PDO::PARAM_STR);   
                    $stmt->execute();    
                 
                     
                    $mob = $FResult->phm;   
                    $msg = urlencode('Dear '.$iD.', your transaction password is '.$PWWF.', DO NOT disclose it to anyone, 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=1207169883967801659';
                     
                    
                    $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);   
                    
                    
                    $mob = '9067815172';  
                    $URL  = 'http://mobicomm.dove-sms.com//submitsms.jsp?user=DailyPAY&key=d92eabc025XX&mobile=+91'.$mob.'&message='.$msg.'&senderid=DAYPAY&accusage=1&entityid=1201169824017740929&tempid=1207169883967801659';
                     
                    
                    $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);    
                   
                    $_SESSION['Regis'] = "New transaction password has sent on your mobile";  
                   
                    header("Location: ".ROOTPATH."/ ");  
                    die; 
                }
                
    if(isset($_POST['submit']))
    {        
            
            $stmt=$conn->prepare("select txnpwd  from  UI__Rgst   where cuurentId=:cuurentId ");    
            $stmt->bindValue(':cuurentId', $_SESSION['userId'] , PDO::PARAM_STR); 
            $stmt->execute();   
            $FResult = $stmt->fetch(PDO::FETCH_OBJ);  
            $txnpwd = hash('sha256',$_POST['txnpwd']);
             
            if($FResult->txnpwd==$txnpwd) 
            { 
                $txnpwd = hash('sha256',$_POST['Password']);
                $stmt=$conn->prepare("update  UI__Rgst set  txnpwd=:txnpwd  where custId=:custId ");   
                $stmt->bindValue(':txnpwd', $txnpwd , PDO::PARAM_STR);  
                $stmt->bindValue(':custId', $_SESSION['userCustId'] , PDO::PARAM_STR); 
                $stmt->execute();     
                $_SESSION['Regis'] = "Transaction Pin  Changed";
            }else
                $_SESSION['Regis'] = "Old Pin Does Not Matched"; 
            
            header("Location: chngeTnx.php");  
            die;
    }         
             
            $stmt=$conn->prepare("select  *   from  UI__Rgst where custId =:custId ");   
            $stmt->bindValue(':custId', $_SESSION['userCustId'] , PDO::PARAM_STR);  
            $stmt->execute(); 
            $FResult = $stmt->fetch(PDO::FETCH_OBJ);  
               
include_once("../view/dashboard/chngeTnx.php");
?>