<?php

session_start();
include_once('../../../controllers/mailer/phpmail2.php');

require_once "../../../controllers/routing/default_values.php";
require_once "../../../controllers/config/db_con_live_static.php";



$server_address=$_SERVER['HTTP_HOST'];


if(isset($_POST['ibssignin']))
{

 $otp = $_POST['new_otp'];

 $sqlc = 'select count(id) as total_id from otp_block where email="'.$_SESSION['pass_changer_email'].'" and expire>"'.date('Y-m-d H:i:s').'"';

$lockQry = $conn->query($sqlc);
$block = $lockQry->fetch_assoc();
if($block['total_id']>0){
$_SESSION['mmsg'] = '<span style="color:red; font-weight:bold; font-size:20px;">You Are Blocked For 15 Minutes!</span>';
echo '<script>window.location.href="index.php"</script>';

}else{

 $sql = 'select otp,user_id,email from forgot_pass_email_otp where  status="PENDING" and email="'.$_SESSION['pass_changer_email'].'" and expire_date>"'.date('Y-m-d H:i:s').'" order by id desc LIMIT 1';
$check = $conn->query($sql);
$check_mail = $check->fetch_assoc();
if($check_mail['otp']==$otp){
 $Upsql = 'update forgot_pass_email_otp set status="VERIFIED" where otp="'.$check_mail['otp'].'" and user_id="'.$check_mail['user_id'].'" and email="'.$check_mail['email'].'"';
 $update = $conn->query($Upsql);
  // die();
 $new_plain_pass = $_SESSION['pass_changer_email'].'_2';
 if($check_mail['user_id']>0){
// echo "xxxxxxxxxxxxxxxxxxxxx";
//  die();
//  $update = $conn->query('update user_activity_management set password="'.$encode_pass.'",pass_change="NO" where user_id="'.$_SESSION['pass_changer_user_id'].'" 
//  and email="'.$_SESSION['pass_changer_email'].'"');
 
//mail

$_SESSION['login_otp_verified_vendor']='1';
       $_SESSION["user_type"] = "suplier";
        $_SESSION['mhafuz'] = 'Active';





 echo '<script>window.location.href="../../../views/vendor_mod/eProc_vendor/vendor_entry.php"</script>';
 }
 
 
}else{
$invalid_sql = 'insert into invalid_opt_try set otp="'.$otp.'",session_id="'.session_id().'",email="'.$_SESSION['pass_changer_email'].'"';
$conn->query($invalid_sql);

$sqlc = 'select count(id) as total_id from invalid_opt_try where session_id="'.session_id().'"';
$lockQry = $conn->query($sqlc);
$block = $lockQry->fetch_assoc();
if($block['total_id']>2){
$newTime = date('Y-m-d H:i:s', strtotime('+15 minutes'));

$invalid_sql2 = 'insert into otp_block set expire="'.$newTime.'",session_id="'.session_id().'",email="'.$_SESSION['pass_changer_email'].'"';
$conn->query($invalid_sql2);
}

$_SESSION['mmsg'] = '<span style="color:red; font-weight:bold; font-size:20px;">Invalid OTP</span>';
echo '<script>window.location.href="otp_check_step.php"</script>';
}
}
}


?>