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

                    
              
                if(isset($_REQUEST['clearAll'])) 
                {
                    unset($_SESSION['TaccountNo']);
                    unset($_SESSION['Tifsc']);
                    unset($_SESSION['Tname']);
                    unset($_SESSION['OtpLogin']); 
                    unset($_SESSION['OtpLoginEror']);  
                    header("Location: AddMAccount.php");
                    die; 
                }
                          
                if(isset($_POST['AddOtp'])) 
                { 
                    if($_POST['enterOtp']==$_SESSION['OtpLogin'])
                    {    
                        $stmt =  $conn->prepare("insert into UI__AddAccount (custId,accno,ifsc,Tdate,accName) values(:custId,:accno,:ifsc,:Tdate,:accName)");            
                        $stmt->bindValue(':custId', $_SESSION['userId'] , PDO::PARAM_STR);
                        $stmt->bindValue(':accno', $_SESSION['TaccountNo'], PDO::PARAM_STR);
                        $stmt->bindValue(':ifsc', $_SESSION['Tifsc'], PDO::PARAM_STR);
                        $stmt->bindValue(':Tdate',date("d-M-Y"), PDO::PARAM_STR); 
                        $stmt->bindValue(':accName',$_SESSION['Tname'], PDO::PARAM_STR); 
                        $stmt->execute();     
                        unset($_SESSION['TaccountNo']);
                        unset($_SESSION['Tifsc']);
                        unset($_SESSION['Tname']);
                        unset($_SESSION['OtpLogin']); 
                        unset($_SESSION['OtpLoginEror']);  
                        $_SESSION['Regis'] = "Account submited successfully will be approved shortly"; 
                    }else
                        $_SESSION['OtpLoginEror']    = "Enter Correct OTP";
                    
                    header("Location: AddMAccount.php");
                    die;   
                }
                          
                          
        if(isset($_POST['submit'])) 
        {     
                $stmt=$conn->prepare("SELECT * FROM UI__BankVefy WHERE accno=:accno and ifsc=:ifsc");  
                $stmt->bindValue(':accno', $_POST['accountNo'] , PDO::PARAM_STR);
                $stmt->bindValue(':ifsc', $_POST['ifsc'] , PDO::PARAM_STR);
                $stmt->execute(); 
                $affected_rows = $stmt->rowCount(); 
                 
                
                if($affected_rows>0) 
                {
                        $Result = $stmt->fetch(PDO::FETCH_OBJ); 
                        $_SESSION['TaccountNo']  = $_POST['accountNo'];
                        $_SESSION['Tifsc']  = $_POST['ifsc'];
                        $_SESSION['Tname'] = $Result->name;
                        
                        $stmt=$conn->prepare("SELECT * FROM UI__AddAccount WHERE accno=:accno and ifsc=:ifsc and custId=:custId ");  
                        $stmt->bindValue(':accno', $Result->accno , PDO::PARAM_STR);
                        $stmt->bindValue(':ifsc', $Result->ifsc , PDO::PARAM_STR);
                        $stmt->bindValue(':custId', $_SESSION['userId']  , PDO::PARAM_STR);
                        $stmt->execute(); 
                        if( $stmt->rowCount() < 1)  
                        {
                            $stmt=$conn->prepare("SELECT phm FROM UI__Rgst WHERE   cuurentId=:cuurentId ");   
                            $stmt->bindValue(':cuurentId', $_SESSION['userId']  , PDO::PARAM_STR);
                            $stmt->execute(); 
                            $CustData = $stmt->fetch(PDO::FETCH_OBJ); 
                            
                            $_SESSION['OtpLogin'] =  rand(11234,23344);
                            $CMB = $_SESSION['OtpLogin'];
                            $mob = $CustData->phm;
                            $msg = urlencode(''.$CMB.' is your mobile verification one time password to proceed on DAILYPAY. It is valid for 5 minitus.'); 
                            $URL  = 'http://mobicomm.dove-sms.com//submitsms.jsp?user=DailyPAY&key=d92eabc025XX&mobile=+91'.$mob.'&message='.$msg.'&senderid=DAYPAY&accusage=1&entityid=1201169824017740929&tempid=1207169907610629409';
                            
                            $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'] = "Otp has been sent on your resgitered mobile no";
                        }
                        else
                            $_SESSION['Regis'] = "Account already added"; 
                        
                }else
                    $_SESSION['Regis'] = "Please verify account first";  
                    
                header("Location: AddMAccount.php");
                die; 
        }  
        
        
            $stmt=$conn->prepare("select * from  UI__Rgst where cuurentId=:cuurentId");    
            $stmt->bindValue(':cuurentId',  $_SESSION['userId'], PDO::PARAM_STR);     
            $stmt->execute(); 
            $Result = $stmt->fetch(PDO::FETCH_OBJ);   

         
include_once("../view/dashboard/AddMAccount.php");
?>