<?php

ob_start();

error_reporting(0);

include("connect.php");

session_start(); 

?>

<!DOCTYPE html>

<html dir="ltr">



<head>

  <title>BTCOVER | Admin Dashboard</title><meta charset="UTF-8" />
	<meta name="google-site-verification" content="bE43faWcX8yFkqZ8OdbPUO_2J1CEnx8xX3VZyjPRlfI" />

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <!-- Tell the browser to be responsive to screen width -->

    <meta name="viewport" content="width=device-width, initial-scale=1">

    <meta name="description" content="">

    <meta name="author" content="">

    <!-- Favicon icon -->

    <link rel="icon" type="image/png" sizes="16x16" href="assets/images/favicon.png">

    <!-- Custom CSS -->

    <link href="dist/css/style.min.css" rel="stylesheet">



</head>



<body>

    <div class="main-wrapper">

        <!-- ============================================================== -->

        <!-- Preloader - style you can find in spinners.css -->

        <!-- ============================================================== -->

        

        <!-- ============================================================== -->

        <!-- Preloader - style you can find in spinners.css -->

        <!-- ============================================================== -->

        <!-- ============================================================== -->

        <!-- Login box.scss -->

        <!-- ============================================================== -->

        <div class="auth-wrapper d-flex no-block justify-content-center align-items-center bg-dark">

            <div class="auth-box bg-dark border-top border-secondary">

                <div id="loginform">

                    <div class="text-center p-t-20 p-b-20" style="padding-bottom:0px;padding-top:0px;">

                        <span class="db"><img src="assets/images/logo.png" alt="logo" /></span>

                    </div>

                    <!-- Form -->

                  <form class="form-horizontal m-t-20" id="loginform" method="post" action="">

                        <div class="row p-b-30">

                            <div class="col-12">

                                <div class="input-group mb-3">

                                    <div class="input-group-prepend">

                                        <span class="input-group-text bg-success text-white" id="basic-addon1"><i class="ti-user"></i></span>

                                    </div>

                                    <input  type="email" class="form-control form-control-lg" name="emailid" placeholder="User Email" required>

                                </div>

                                <div class="input-group mb-3">

                                    <div class="input-group-prepend">

                                        <span class="input-group-text bg-warning text-white" id="basic-addon2"><i class="ti-pencil"></i></span>

                                    </div>

                                     <input type="password" class="form-control form-control-lg" name="password" placeholder="Password" required >

                                </div>

                            </div>

                        </div>

                        <div class="row border-top border-secondary">

                            <div class="col-12">

                                <div class="form-group">

                                    <div class="p-t-20">

                                       <!-- <button class="btn btn-info" id="to-recover" type="button"><i class="fa fa-lock m-r-5"></i> Lost password?</button>-->

                                        <button class="btn btn-success float-right" name="sublogin" type="submit" style="width:200px;">Login</button>

                                    </div>

                                </div>

                            </div>

                        </div>

                    </form>
					 <div class="text-center" style="margin-top:15%;">

                        <span class="text-white">©2019 BTCOVER All Rights Reserved.<br> Developed By  &nbsp;&nbsp;<a href="https://www.belltechnology.in/" target='_blank'> Bell Technology </a> &nbsp; | &nbsp;<a href="http://www.btcover.appexperts.net/privacy_policy.html"> Privacy Policy </a></span>

                    </div>

                </div>

                <div id="recoverform">

					  <div class="text-center p-t-20 p-b-20">

                        <span class="db"><img src="assets/images/logo.png" alt="logo" /></span>

                    </div>

                    <div class="text-center">

                        <span class="text-white">Enter your e-mail address below and we will send you password on your mail address.</span>

                    </div>

                    <div class="row m-t-20">

                        <!-- Form -->

                        <form class="col-12" action="index.html">

                            <!-- email -->

                            <div class="input-group mb-3">

                                <div class="input-group-prepend">

                                    <span class="input-group-text bg-danger text-white" id="basic-addon1"><i class="ti-email"></i></span>

                                </div>

                                 <input type="email" class="form-control form-control-lg" placeholder="Email Address" name="email" required>

                            </div>

                            <!-- pwd -->

                            <div class="row m-t-20 p-t-20 border-top border-secondary">

                                <div class="col-12">

                                     <a class="btn btn-success" href="#" id="to-login" name="action">Back To Login</a>

                                    <button class="btn btn-info float-right" type="submit" name="recover">Recover</button>

                                </div>

                            </div>

                        </form>

                    </div>

                </div>

            </div>

        </div>

       <?php

	#Get value from  login form

	

	if(isset($_POST['sublogin']))

	{

		 $fname = $_POST['emailid'];

		 $pass = $_POST['password'];

		 $flag_temp=0;

		 $r_temp=session_id();

		$temp_time=time();

		 

		 

		$res_search = mysqli_query($con,"select * from tbl_manager where status='Active' and manager_email='$fname' && password='$pass'");

		$row_search  = mysqli_num_rows($res_search);

		$a21=mysqli_fetch_array($res_search);

		if($row_search>0)

		{

			$ver=$a21['manager_id'];

			$check_dis_id=$a21['admin_id'];

			if($a21['session_id']=="")

			{

				$uq1=mysqli_query($con,"UPDATE tbl_manager SET login_datetime='$temp_time',session_id='$r_temp',activity_time='$temp_time' where manager_id='$ver'");

				#store all fetch data in session.

				$_SESSION['admin_id']=$a21['admin_id'];

				$_SESSION['manager_id']=$ver;

				$_SESSION['user_type']=$a21['manage_type'];

				$_SESSION['user_session']=$r_temp;

				header("location:dashboard.php"); 

			}

			else

			{

				$last_action=(int)$a21['activity_time'];

				if (time() - $last_action > 480) 

				{

					// last request was more than 8 minutes ago

					$uq1=mysqli_query($con,"UPDATE tbl_manager SET login_datetime='$temp_time',session_id='$r_temp',activity_time='$temp_time' where manager_id='$ver'");

					// destroy session data in storage

					$_SESSION['admin_id']=$a21['admin_id'];

					$_SESSION['manager_id']=$ver;

					$_SESSION['user_type']=$a21['manage_type'];

					$_SESSION['user_session']=$r_temp;

					header("location:dashboard.php");

				}

				else

				{

					$res_search_dis = mysqli_query($con,"select * from tbl_manager where admin_id='$check_dis_id' and session_id='$r_temp'");

					if(mysqli_num_rows($res_search_dis)>0)

					{

						?>

						<script> alert("You are already logged in same browser.Please logout and then try again!"); </script>

						<?php

					}

					else

					{

						header("location:login-confirmation.php?logid=".base64_encode($ver));

					}

				}

			}



		} else {

		?>

			<script> alert("Email and password does not match!");</script>

		<?php }} ?>      

    </div>

    <!-- ============================================================== -->

    <!-- All Required js -->

    <!-- ============================================================== -->

    <script src="assets/libs/jquery/dist/jquery.min.js"></script>

    <!-- Bootstrap tether Core JavaScript -->

    <script src="assets/libs/popper.js/dist/umd/popper.min.js"></script>

    <script src="assets/libs/bootstrap/dist/js/bootstrap.min.js"></script>

    <!-- ============================================================== -->

    <!-- This page plugin js -->

    <!-- ============================================================== -->

    <script>



    $('[data-toggle="tooltip"]').tooltip();

    $(".preloader").fadeOut();

    // ============================================================== 

    // Login and Recover Password 

    // ============================================================== 

    $('#to-recover').on("click", function() {

        $("#loginform").slideUp();

        $("#recoverform").fadeIn();

    });

    $('#to-login').click(function(){

        

        $("#recoverform").hide();

        $("#loginform").fadeIn();

    });

    </script>



</body>



</html>