<?php
session_start();
?>

<!DOCTYPE html>
<html lang="en">


<?php
include("../include/config.php");
error_reporting(E_ALL);
ini_set('display_errors', 1);

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

    $username = $_POST['username'];
    $password = $_POST['password'];


    $sql_query = "select * from  tbl_users where username='" . $username . "' ";

    $result = mysqli_query($db, $sql_query);

    $count = mysqli_num_rows($result);

    $flag = 0;

    $userId = 0;
    if ($count >= 1) {

        $pass = "";

        if ($row = mysqli_fetch_array($result)) {
            $userId = $row["id"];
        }


        $pass = $row["password"];



        if (password_verify($password, $pass)) {
            $flag = 1;
        }


        if ($flag > 0) {
            session_start();

            $_SESSION['username'] = $username;
            $_SESSION['userId'] = $userId;

            $_SESSION['success'] = "You are now logged in";
            //  header("Location: /admin/index.php");
            header("Location: admin/index.php");

        } else {
            echo "Invalid username and password2";
        }



    } else {
        echo "Invalid username and password";

    }


}


?>

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Mouldifi - A fully responsive, HTML5 based admin theme">
<meta name="keywords" content="Responsive, HTML5, admin theme, business, professional, Mouldifi, web design, CSS3">
<title>ورود به بیمه توانا</title>
<!-- Site favicon -->
<link rel='shortcut icon' type='image/x-icon' href='admin/images/favicon.ico' />
<!-- /site favicon -->

<!-- Entypo font stylesheet -->
<link href="admin/css/entypo.css" rel="stylesheet">
<!-- /entypo font stylesheet -->

<!-- Font awesome stylesheet -->
<link href="admin/css/font-awesome.min.css" rel="stylesheet">
<!-- /font awesome stylesheet -->

<!-- CSS3 Animate It Plugin Stylesheet -->
<link href="admin/css/plugins/css3-animate-it-plugin/animations.css" rel="stylesheet">
<!-- /css3 animate it plugin stylesheet -->

<!-- Bootstrap stylesheet min version -->
<link href="admin/css/bootstrap.min.css" rel="stylesheet">
<!-- /bootstrap stylesheet min version -->

<!-- Mouldifi core stylesheet -->
<link href="admin/css/mouldifi-core.css" rel="stylesheet">
<!-- /mouldifi core stylesheet -->

<link href="admin/css/mouldifi-forms.css" rel="stylesheet">

<!-- Bootstrap RTL stylesheet min version -->
<link href="admin/css/bootstrap-rtl.min.css" rel="stylesheet">
<!-- /bootstrap rtl stylesheet min version -->

<!-- Mouldifi RTL core stylesheet -->
<link href="admin/css/mouldifi-rtl-core.css" rel="stylesheet">
<!-- /mouldifi rtl core stylesheet -->

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
      <script src="admin/js/html5shiv.min.js"></script>
      <script src="admin/js/respond.min.js"></script>
<![endif]-->


</head>
<body class="login-page">
	<div class="login-pag-inner">
		<div class="animatedParent animateOnce z-index-50">
			<div class="login-container animated growIn slower">
				<div class="login-branding">
					<a href="admin/index.php"><img src="admin/images/logo.png" alt="Mouldifi" title="Mouldifi"></a>
				</div>
				<div class="login-content">
					<h2><strong>خوش آمدید</strong>, ورود به پنل مدیریت</h2>
					<form method="POST" action="" enctype="multipart/form-data">
						<div class="form-group">
							<input type="text" name="username" id="username" placeholder="نام کاربری" class="form-control">
						</div>                        
						<div class="form-group">
							<input type="password" id="password" name="password" placeholder="رمز عبور" class="form-control">
						</div>
						<div class="form-group">
							 <div class="checkbox checkbox-replace">
								<input type="checkbox" id="remeber">
								<label for="remeber">ذخیره کردن</label>
							  </div>
						 </div>
						<div class="form-group">
							<button type="submit" id="but_submit" name="but_submit" class="btn btn-primary btn-block"> ورود</button>
						</div>
						<p class="text-center"><a href="forgot-password.html">رمز عبور خود را فراموش کردید؟</a></p>
					</form>
				</div>
			</div>
		</div>
	</div>
<!--Load JQuery-->
<script src="admin/js/jquery.min.js"></script>
<!-- Load CSS3 Animate It Plugin JS -->
<script src="admin/js/plugins/css3-animate-it-plugin/css3-animate-it.js"></script>
<script src="admin/js/bootstrap.min.js"></script>
</body>
</html>
