<?php
    include('../SecurityChecked/StringAuthenticationStrict.php');
    StrictSecurityChecked();
	include('../config.php');      
     
	$stmt=$conn->prepare("SELECT * FROM users WHERE valid_id=:valid_id");  
    $stmt->execute(array(':valid_id'=>$_REQUEST['valid_id']));
	$rows=$stmt->fetch();	
	$affected_rows  = $stmt->rowCount();  	 
     
	if($affected_rows > 0)
	{ 
		if($rows['email_varify'] > 0)
		{
			$msg="<span style='color:green;'>Email Already Verified !!!</span>";
        }			
		else 
		{ 
    		$stmt=$conn->prepare("update users set email_varify=1,valid_id='' where id=:id");   
    		$stmt->execute(array(':id'=>$rows['id']));   
    		$cust_id=$rows['cust_id'];

            $stmt= $conn->prepare("select id,email_verify,cust_id from job_applied where cust_id=:cust_id and email_verify=0");  
            $stmt->bindValue(':cust_id', $cust_id, PDO::PARAM_STR); 
            $stmt->execute();		
            $applied_affected_rows = $stmt->rowCount();
            if($applied_affected_rows > 0)		
            {
            	$rw = $stmt->fetchAll(PDO::FETCH_OBJ);    
            	foreach($rw as $dt)
            	{
            	   $stmt =  $conn->prepare("update job_applied set email_verify=1 where cust_id=:cust_id");
            	   $stmt->bindValue(':cust_id', $dt->cust_id, PDO::PARAM_STR);
            	   $stmt->execute();
            	}
            }
    		$msg1="<span style='color:green;'>Email Verified Successfully!!!</span>";
		    //echo '<script>alert("Email Validation Successfully!!!")</script>';		
		}
	}  
	else
		$msg2="<span style='color:red;'>Link Expired / Already Updated!!!</span>"; //'<script>alert("Email Validation Not Done!!!")</script>';  
	
	
	$filename = basename(__FILE__); 
	include_once("../view/login/".$filename); 
?>