<?php 
	include('../config.php'); 
	include(ABS_PATH.'/custom_function/default.php'); 
         
    if(isset($_SESSION['userId']))
    {      
        header("Location: ../mob/dashboard/");
        die;
    } 
  
      
      
      
            if(isset($_POST['SubmitRef']))
            {         
                    $set=0;      
                    $stmt=$conn->prepare("select id from UI__Rgst where tokenGen=:tokenGen ");    
                    $stmt->bindValue(':tokenGen',  $_POST['tokenGen'] , PDO::PARAM_STR);   
                    $stmt->execute();  
                  
                      
                    if($stmt->rowCount() < 1)
                    {
                        
                        
                        $stmt=$conn->prepare("select * from UI__Rgst where cuurentId=:cuurentId ");    
                        $stmt->bindValue(':cuurentId',  $_POST['login_id'] , PDO::PARAM_STR);   
                        $stmt->execute(); 
                   
                        if($stmt->rowCount() > 0 )
                        {
                        

                        $Result = $stmt->fetch(PDO::FETCH_OBJ);   
                        $digits = 6; 
                        
                        $PWWF = rand(pow(10, $digits-1), pow(10, $digits)-1);      
                        $stmt=$conn->prepare("update UI__Rgst set pwd=:pwd,tokenGen=:tokenGen where cuurentId=:cuurentId ");    
                        $stmt->bindValue(':pwd',   hash('sha256', $PWWF), PDO::PARAM_STR);  
                        $stmt->bindValue(':tokenGen',  $_POST['tokenGen'], PDO::PARAM_STR);    
                        $stmt->bindValue(':cuurentId',  $_POST['login_id'] , PDO::PARAM_STR);   
                        $stmt->execute();    
                         
                        $subject = "Your New Password On ".$SITE_NAME;  
                        $template_type = 1;
                        $attachment = ''; 
                        $name = $Result->nm;
                        $Password = $PWWF;
                        $cuurentId = $_POST['login_id'];  
                        $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;'>Your Details are as follows </h5> 
                        <h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'> Name: $name , Your ID : $cuurentId , Password : $Password</h5>
                        
                        </td>
                        </tr>";   
                        SendMail($Result->eml,$subject,$message,$template_type,$attachment);
                        SendMail('dailypay2024@gmail.com',$subject,$message,$template_type,$attachment);    
                      
                               
                        $mob = $Result->phm; 
                        $iD = $_SESSION['userId'];
                        $msg = urlencode('Dear '.$iD.', your 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=1207169883887775866';
                          
                        $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";
                        $iD = $_SESSION['userId'];
                        $msg = urlencode('Dear '.$iD.', your 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=1207169883887775866';
                          
                        $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['LoginSuccess']  ="Password has been sent successfully on your email id Please check Spam folder if not get";
                        }else
                            $_SESSION['LoginSuccess']  ="Please enter correct userid";
                    }else
                            $_SESSION['LoginSuccess']  ="Something Went Wrong";
                            
                    header("Location: forgetPassword.php");
                    die;
                        
            }
          
               
	$filename = basename(__FILE__); 
	include_once("../view/".$filename); 
?>