<html>
<head>
    <meta charset="utf-8"/>
    <title>PRAYATNA - User Login</title>
	<link rel="stylesheet" href="user_style.css">
	<link href="https://fonts.googleapis.com/css2?family=Asap+Condensed&display=swap" rel="stylesheet">
</head>
<body>
<?php
    require('db.php');
    session_start();
    // When form submitted, check and create user session.
    if (isset($_POST['mobile'])) {
        $mobile = stripslashes($_REQUEST['mobile']);    // removes backslashes
        $mobile = mysqli_real_escape_string($con, $mobile);
        $password = stripslashes($_REQUEST['password']);
        $password = mysqli_real_escape_string($con, $password);
        // Check user is exist in the database
        //$query    = "SELECT * FROM `user` WHERE mobile='$mobile' AND password='" . md5($password) . "' AND accept=1;" ;
		$query    = "SELECT * FROM `user` WHERE mobile='$mobile'
                     AND password='" . md5($password) . "'" ;
        $result = mysqli_query($con, $query) or die(mysql_error());
        $rows = mysqli_num_rows($result);
        if ($rows == 1) {
			$record = $result->fetch_assoc();
			if($record["accept"]== 1){
            $_SESSION['mobile'] = $record["mobile"]; //$mobile;
			//$record = $result->fetch_assoc();
			$_SESSION['uname'] = $record["uname"];
            // Redirect to user dashboard page
            header("Location: user_add_event.php");
			}
			else {
            echo '<div class="user_login_form">
                  <h3>Admin not yet approved your User Registeration; Please wait.</h3><br/>';
			}
        } else {
            echo '<div class="user_login_form">
                  <h3>Incorrect Username/password or your are not yet registered.</h3><br/>';
        }
	?>
	<a href="user_login.php"> <input type = "button" value = "LOGIN" class="user_login_button"></a></div>
<?php
    }
	else {
?>
    <div id="login">
    <form class="user_login_form" method="post" name="login">
        <h1 class="login-title">USER LOGIN</h1>
        <input type="tel" class="login-input" id="mobile" name="mobile" placeholder="Mobile Number" pattern="[0-9]{10}" required>
		<br><br><br>
        <input type="password" class="login-input" id="password" name="password" placeholder="Password"/>
		<br><br>
        <input type="submit" value="LOGIN" name="submit" class="user_login_button"/>
		<br>
		<p>New to PRAYATNA'23?</p>
		 <a href="user_registration.php"> <input type = "button" value = "REGISTER NOW" class="user_login_button"></a>
		 
		<p>Forgot password?</p>
		 <a href="user_forgot_pwd.php"> <input type = "button" value = "RESET PASSWORD" class="user_login_button"></
		<p></p>
		 <a href="index.html"> <input type = "button" value = "HOME" class="user_login_button"></a>
    </form>
    </div>
<?php
    }
?>
</body>
</html>