
<?php  
session_start();//session starts here 
  
?>  
<!DOCTYPE html>
<html lang="en" class="h-100">

<head>
    <meta charset="utf-8">
	<meta name="robots" content="index, follow">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	
	<!-- PAGE TITLE HERE -->
	<title>ورودی سیستم</title>

	<!-- FAVICONS ICON -->
    <link rel="shortcut icon" type="image/png" href="images/favicon.png">
    <link href="css/style.css" rel="stylesheet">
    <link rel="stylesheet" href="dist/sweetalert.css"> 
<!-- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> -->
    <script>
        function ValidateEmail() {
        var email = document.getElementById("user").value;
        var lblErroremail = document.getElementById("lblErroremail");
        lblErroremail.innerHTML = "";
        var expr = /^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+\.[a-zA-z]{2,3}$/;
        if (!expr.test(email)) {
            lblErroremail.innerHTML = "Warning   "+"Invalid email address";
        }
    }
    </script>

</head>

<body class="vh-100">
    <div class="authincation h-100">
        <div class="container h-100">
            <div class="row justify-content-center h-100 align-items-center">
                <div class="col-md-6">
                    <div class="authincation-content">
                        <div class="row no-gutters">
                            <div class="col-xl-12">
                                <div class="auth-form">
									<div class="text-center mb-3">
                                  <a href="index.html"><img src="images/logo1.png" height="80" alt=""></a>
									</div>
                                    
                                    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" dir="rtl">
                                    <div class="mb-3">
                                            <label class="mb-1"><strong>نوعیت کاربر</strong></label>
                                            <select name="user_type" id="user_type" class="form-control">
                                                <option value="">انتخاب</option>
                                                <option value="admin">ریس</option>
                                                <option value="staff">کارمند</option>
                                            </select>
                                        </div> 
                                        <div class="mb-3">
                                            <label class="mb-1"><strong>ایمیل آدرس</strong></label>
                                            <input type="email" name="email" id="user" class="form-control" placeholder="ایمیل" onkeyup="ValidateEmail();"><span id="lblErroremail" style="color:red"></span>
                                        </div>
                                        <div class="mb-3">
                                            <label class="mb-1"><strong>رمز</strong></label>
                                            <input type="password" name="pass" class="form-control" placeholder="رمز">
                                        </div>
                                        <div class="row d-flex justify-content-between mt-4 mb-2">
                                       
                                         
                                        </div>
                                        <div class="text-center">
                                            <button type="submit" id="form_submit" name="login" class="btn btn-primary btn-block">ورود به سیستم</button>
                                        </div>
                                    </form>
                                   
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <!--**********************************
        Scripts
    ***********************************-->
    <!-- Required vendors -->
    <script src="vendor/global/global.min.js"></script>
    <script src="js/custom.min.js"></script>
    <script src="js/dlabnav-init.js"></script>
	<script src="js/styleSwitcher.js"></script>
    <script src="dist/sweetalert.min.js"></script>
</body>
</html>
<?php  
  
include("dbconnection.php");  
if($_SERVER['REQUEST_METHOD'] == "POST")
{
    

    $user_email = $_POST['email'];
    $user_pass = $_POST['pass'];
    $user_name = $_POST['emp_name'];
    $user_type = $_POST['user_type'];
    $user_pass = md5($user_pass);
  
    $check_user="SELECT * FROM employee WHERE emp_email='$user_email' AND emp_password ='$user_pass' AND emp_type = '$user_type'";  
  
    $run=mysqli_query($con,$check_user);  
  
    if(mysqli_num_rows($run) > 0)  
    {  

		  while($row = mysqli_fetch_assoc($run)) {
            $_SESSION['emp_id'] = $row['emp_id'];
		    $_SESSION['emp_name'] = $row['emp_name'];
            $_SESSION['emp_type'] = $row['emp_type'];
           
		  }
  
        $_SESSION['emp_email']=$user_email; //here session is used and value of $user_email store in $_SESSION.
        $_SESSION['emp_type']=$user_type;
        

        
        echo "<script>swal('به سیستم اطلاعات و مدیریت مرکز آموزشی نعیم آریا خوش آمدید','','success')
                            window.setTimeout(function(){ 
                            window.open('index.php','_self')
                            } ,500);</script>";
        
  
  
    }  
    else  
    {  
      echo "<script>
       sweetAlert('Warning','معلومات شما درست نیست','error');  
      </script>";  
	}
}  
?>