<?php 
ob_start();
session_start();
include_once("include/functions.php");

if(!empty($_POST['loginEmail']))
$loginEmail = $_POST['loginEmail'];
elseif(!empty($_GET['loginEmail']))
$loginEmail = $_GET['loginEmail'];
else
$loginEmail ="";




if(!empty($_POST['otp']))
$otp = $_POST['otp'];
elseif(!empty($_GET['otp']))
$otp = $_GET['otp'];
else
$otp =rand(10000,99999);



if(isset($_POST['save'])){
 recovery_email_check();
}


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

redirect("forgotpassword.php?loginEmail=".$_POST['loginEmail']."&otp=".$_POST['otp']);
}


?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="Instructor login page for LMS platform.">
  <title>Recovery Account</title>

  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
  <link href="css/bootstrap.min.css" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet">
  <link href="css/main.css" rel="stylesheet">
  <link href="css/login.css" rel="stylesheet">
 
  <style>
    .err{
	
	color:#DC3545;
	}
  
  </style>
</head>
<body class="instructor-login-page">
  <div class="login-shell container-fluid">
    <div class="row g-0 login-card">
      <div class="col-lg-6 login-form-pane">
        <a href="index.php" class="login-brand">
           <span class="auth-brand__icon"><img src="images/logo.jpg" style="width: 240px;border-radius: 20px;" ></span>
        </a>

        <div class="login-form-wrap">
            <p class="login-eyebrow">Account Recovery</p>
        <h1>Recover Your Account</h1>
        <p class="login-lead">
        Enter your registered email address to receive a One-Time Password (OTP) and reset your account access.
        </p>

         <!-- <form id="instructorLoginForm" class="needs-validation" novalidate>-->
         <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>" id="instructorLoginForm" class="needs-validation" novalidate enctype="multipart/form-data">
            <div id="formFeedback" class="alert d-none mb-3" role="alert"></div>
            
            <?php
			  if(!empty($_GET['fail']))
			  {
			 ?>
				<div class="alert alert-danger" role="alert"> <center> <strong style="color:black"> Invalid Credentials.... </strong> </center> </div>
			<?php
				}
			?> 

            <div class="row g-3">
                 <div class="col-12">
                  <label for="email" class="form-label">Email</label>
                  <input type="email" class="form-control" name="loginEmail" value="<?php echo $loginEmail;?>" id="loginEmail" required>
                  <div class="invalid-feedback" id="emailError">Enter Email Id.</div>
             </div>
				
           
                <?php if($loginEmail !="") { ?>
             <div class="form-floating mb-3">
              <input type="text" class="form-control" name="otp" id="otp" value="<?php echo $otp; ?>" required>
              <label for="loginEmail">OTP</label>
              <div class="invalid-feedback"></div>
            </div>
            <?php } ?> 

              <div class="col-12 login-meta">
             <!--   <div class="form-check">
                  <input class="form-check-input" type="checkbox" id="rememberMe" >
                  <label class="form-check-label" for="rememberMe">Remember me</label>
                  <div class="invalid-feedback">You Must Confirm Before Login.</div>
                </div>-->
                <a href="recoveryAccount.php" class="forgot-link">Forgot password?</a>
              </div>

              <div class="col-12 d-grid mt-1">
               	  <?php if($loginEmail =="") { ?>
            <button type="submit" name="save" class="btn btn-primary w-100 btn-auth">Submit</button>
            <?php }else { ?>
            <button type="submit" name="next" class="btn btn-success w-100 btn-auth">Next</button>
            <?php } ?>
              </div>
            </div>
          </form>

          <p class="login-footnote">
            New instructor?
            <a href="register.php">Create an account</a>
          </p>
        </div>
      </div>

      <div class="col-lg-6 login-media-pane">
        <div class="login-media-content">
        <h2>Recover Your Account</h2>
        <p>Securely regain access to your instructor portal. Enter your registered email, receive an OTP, and reset your account quickly.</p>
        <div class="feature-pill">
          <i class="bi bi-shield-lock me-2"></i>Secure OTP verification
        </div>
        </div>
        <div class="login-media-image-wrap">
          <img
            src="images/instructorwithrobot.jpg?auto=format&fit=crop&w=1200&q=80"
            alt="Instructor interacting with robotics learning setup"
            class="login-media-image"
          >
        </div>
      </div>
    </div>
  </div>
<div id="welcomePopup" class="welcome-popup" style="display:none;">
<div class="popup-box">

<h4>ðŸŽ‰ Successfully Registered! Login to continue.</h4>

<a href="dashboard.php"> <button>Continue</button> </a>

</div>
</div>
  <script src="js/jquery.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
  <script src="js/main.js"></script>
  <script language="javascript">
  $(function () {
    initWelcomePopup();
  });
  </script>
</body>
</html>
