<?php     include 'config.php'; ?>
<?php
// login.php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
   	$email=  htmlentities($_POST['email']);
	$password= md5($_POST['password']);


		// checking if field is empty
		if($email == "")
		{
			$extra="index.php";
			$host  = $_SERVER['HTTP_HOST'];
			$uri  = rtrim(dirname($_SERVER['PHP_SELF']),'/\\');
			echo "<script type='text/javascript'> document.location = 'https://$host$uri/$extra'; </script>";
				

			$_SESSION['errmsg']="Your username field is empty";
				exit();
		}


		if($password == "")
		{
			$extra="index.php";
			$host  = $_SERVER['HTTP_HOST'];
			$uri  = rtrim(dirname($_SERVER['PHP_SELF']),'/\\');
			echo "<script type='text/javascript'> document.location = 'https://$host$uri/$extra'; </script>";
			
	

			$_SESSION['errmsg']="Your password field is empty";
			
				exit();
				
		}








$query=mysqli_query($conn,"SELECT * FROM teachers WHERE email='$email' and password='$password'");
$num=mysqli_fetch_array($query);




    if($num>0) {

        
        $extra="profile.php";
		$_SESSION['login']=$num['email'];
		$_SESSION['id']=$num['id'];
		$_SESSION['username']=$num['name'];
		$uip=$_SERVER['REMOTE_ADDR'];
		$status=1;
		// $log=mysqli_query($con,"insert into userlog(userEmail,userip,status) values('".$_SESSION['login']."','$uip','$status')");
		$host=$_SERVER['HTTP_HOST'];
		$uri=rtrim(dirname($_SERVER['PHP_SELF']),'/\\');
		echo "<script type='text/javascript'> document.location = 'https://$host$uri/$extra'; </script>";
	
		exit();
        
        
        
    //       header("Location: ../Dash.php");
    //   $_SESSION['mess'] = 'Login was successful';
    } else {
        //$_SESSION['errmsg'] = "Invalid email or password.";
        
		echo "<script type='text/javascript'> document.location = 'index.php'; </script>";
	
		$_SESSION['errmsg']="Invalid email id or Password";
		exit();
    }

    $stmt->close();
    $conn->close();
}
?>
<!doctype html>
<html lang="en">


<!-- Mirrored from codervent.com/rocker/demo/vertical/authentication-signin.html by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 26 Aug 2022 06:47:23 GMT -->
<head>
	<!-- Required meta tags -->
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<!--favicon-->
	<link rel="icon" href="assets/images/favicon-32x32.png" type="image/png" />
	<!--plugins-->
	<link href="assets/plugins/simplebar/css/simplebar.css" rel="stylesheet" />
	<link href="assets/plugins/perfect-scrollbar/css/perfect-scrollbar.css" rel="stylesheet" />
	<link href="assets/plugins/metismenu/css/metisMenu.min.css" rel="stylesheet" />
	<!-- loader-->
	<link href="assets/css/pace.min.css" rel="stylesheet" />
	<script src="assets/js/pace.min.js"></script>
	<!-- Bootstrap CSS -->
	<link href="assets/css/bootstrap.min.css" rel="stylesheet">
	<link href="assets/css/bootstrap-extended.css" rel="stylesheet">
	<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&amp;display=swap" rel="stylesheet">
	<link href="assets/css/app.css" rel="stylesheet">
	<link href="assets/css/icons.css" rel="stylesheet">
	<title>   school Portal</title>
</head>

<body class="bg-login" style="padding: 2%;">
	<!--wrapper-->
	<div class="wrapper" >
		<div class="section-authentication-signin d-flex align-items-center justify-content-center my-5 my-lg-0">
			<div class="container-fluid">
				<div class="row row-cols-1 row-cols-lg-2 row-cols-xl-3">
					<div class="col mx-auto">
						<div class="mb-4 text-center">
							<a href="index.php"  > <img src="assets/images/logo-img.png" width="180" alt="" /> </a>
						</div>
						<div class="card">
							<div class="card-body">
								<div class="border p-4 rounded">
								<div class="col-md-12 col-sm-12">
                              <div class="section-title wow fadeInUp" data-wow-delay="0.1s" style="padding-top: 10px; text-align: center;">
                                  
                                   <span style="color:red;font-size: 20px;" >
                                      <?php if($_SESSION['errmsg']){
                                    echo htmlentities($_SESSION['errmsg']);
                                    ?>
                                    <?php
                                    echo htmlentities($_SESSION['errmsg']="");
									  }?>
                                    </span>

                                    <span style="color:green;font-size: 20px;" >
                                      <?php if($_SESSION['mess']){
                                    echo htmlentities($_SESSION['mess']);
                                    ?>
                                    <?php
                                    echo htmlentities($_SESSION['mess']="");
									  }?>
                                    </span>
                              </div>
                         </div>
									<div class="text-center">
										<h3 class="">Sign in</h3>
										<!--<p>Don't have an account yet? <a href="register.php">Sign up here</a>-->
										<!--</p>-->
									</div>
									
									
									<div class="form-body">
										<form class="row g-3" action="" method="post">
											<div class="col-12">
												<label for="inputEmailAddress" class="form-label">Email Address</label>
												<input type="email" name="email" class="form-control" id="inputEmailAddress" placeholder="Email Address">
											</div>
											<div class="col-12">
												<label for="inputChoosePassword" class="form-label">Enter Password</label>
												<div class="input-group" id="show_hide_password">
													<input type="password" class="form-control border-end-0" id="inputChoosePassword" value="" name="password" placeholder="Enter Password"> <a href="javascript:;" class="input-group-text bg-transparent"><i class='bx bx-hide'></i></a>
												</div>
											</div>
											<div class="col-md-6">
												<div class="form-check form-switch">
													<input class="form-check-input" type="checkbox" id="flexSwitchCheckChecked" checked>
													<label class="form-check-label" for="flexSwitchCheckChecked">Remember Me</label>
												</div>
											</div>
											<!--<div class="col-md-6 text-end">	<a href="forget_password.php">Forgot Password ?</a>-->
											<!--</div>-->
											<div class="col-12">
												<div class="d-grid">
													<button type="submit" class="btn btn-primary"><i class="bx bxs-lock-open"></i>Sign in</button>
												</div>
											</div>
										</form>
								 
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<!--end row-->
			</div>
		</div>
	</div>
	<!--end wrapper-->
	<!-- Bootstrap JS -->
	<script src="assets/js/bootstrap.bundle.min.js"></script>
	<!--plugins-->
	<script src="assets/js/jquery.min.js"></script>
	<script src="assets/plugins/simplebar/js/simplebar.min.js"></script>
	<script src="assets/plugins/metismenu/js/metisMenu.min.js"></script>
	<script src="assets/plugins/perfect-scrollbar/js/perfect-scrollbar.js"></script>
	<!--Password show & hide js -->
	<script>
		$(document).ready(function () {
			$("#show_hide_password a").on('click', function (event) {
				event.preventDefault();
				if ($('#show_hide_password input').attr("type") == "text") {
					$('#show_hide_password input').attr('type', 'password');
					$('#show_hide_password i').addClass("bx-hide");
					$('#show_hide_password i').removeClass("bx-show");
				} else if ($('#show_hide_password input').attr("type") == "password") {
					$('#show_hide_password input').attr('type', 'text');
					$('#show_hide_password i').removeClass("bx-hide");
					$('#show_hide_password i').addClass("bx-show");
				}
			});
		});
	</script>
	<!--app JS-->
	<script src="assets/js/app.js"></script>
</body>


<!-- Mirrored from codervent.com/rocker/demo/vertical/authentication-signin.html by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 26 Aug 2022 06:47:31 GMT -->
</html>