<?php 
ob_start(); 
error_reporting(0);
include("connect.php");
session_start(); 
?>
<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="utf-8" />
        <title>Tarkashcorp | Admin Dashboard</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta content="width=device-width, initial-scale=1" name="viewport" />
        <meta content="Preview page of Metronic Admin Theme #6 for " name="description" />
        <meta content="" name="author" />
        <!-- BEGIN GLOBAL MANDATORY STYLES -->
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css" />
        <link href="assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
        <link href="assets/global/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css" />
        <link href="assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
        <link href="assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css" rel="stylesheet" type="text/css" />
        <!-- END GLOBAL MANDATORY STYLES -->
        <!-- BEGIN PAGE LEVEL PLUGINS -->
        <link href="assets/global/plugins/select2/css/select2.min.css" rel="stylesheet" type="text/css" />
        <link href="assets/global/plugins/select2/css/select2-bootstrap.min.css" rel="stylesheet" type="text/css" />
        <!-- END PAGE LEVEL PLUGINS -->
        <!-- BEGIN THEME GLOBAL STYLES -->
        <link href="assets/global/css/components.min.css" rel="stylesheet" id="style_components" type="text/css" />
        <link href="assets/global/css/plugins.min.css" rel="stylesheet" type="text/css" />
        <!-- END THEME GLOBAL STYLES -->
        <!-- BEGIN PAGE LEVEL STYLES -->
        <link href="assets/pages/css/login.min.css" rel="stylesheet" type="text/css" />
        <!-- END PAGE LEVEL STYLES -->
        <!-- BEGIN THEME LAYOUT STYLES -->
        <!-- END THEME LAYOUT STYLES -->
        <link rel="shortcut icon" href="favicon.ico" />
		
		<style>
		::-webkit-scrollbar {
			display: none;
			overflow: hidden;
		}
		</style>
		<script>
		window.onscroll = function () {
		window.scrollTo(0,0);
		}
		</script>
		</head>
    <!-- END HEAD -->

    <body class=" login">
        <!-- BEGIN LOGO -->
        <div class="logo">
            <a href="index.php">
                <img src="assets/pages/img/app_logo2.png" height="70px" width="200px" alt="" /> </a>
        </div>
        <!-- END LOGO -->
        <!-- BEGIN LOGIN -->
        <div class="content" style="margin-top:5px;">
            <!-- BEGIN LOGIN FORM -->
            <form class="login-form" method="post">
                <h3 class="form-title font-green">Sign In</h3>
                <div class="alert alert-danger display-hide">
                    <button class="close" data-close="alert"></button>
                    <span> Enter user name and password. </span>
                </div>
                <div class="form-group">
                    <!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
                    <label class="control-label visible-ie8 visible-ie9">User name</label>
                    <input class="form-control form-control-solid placeholder-no-fix" type="text" autocomplete="off" placeholder="Username" name="distributor_email" /> </div>
                <div class="form-group">
                    <label class="control-label visible-ie8 visible-ie9">Password</label>
                    <input class="form-control form-control-solid placeholder-no-fix" type="password" autocomplete="off" placeholder="Password" name="password" /> </div>
                <div class="form-actions">
				<input id="submit" type="submit" name="sub" class="btn green uppercase"  value="Log In"/>
        <!--        <label class="rememberme check mt-checkbox mt-checkbox-outline">
                        <input type="checkbox" name="remember" value="1" />Remember
                        <span></span>
                    </label>
                    <a href="javascript:;" id="forget-password" class="forget-password">Forgot Password?</a> -->
                </div>
        <!--    <div class="login-options">
                    <h4>Or login with</h4>
                    <ul class="social-icons">
                        <li>
                            <a class="social-icon-color facebook" data-original-title="facebook" href="javascript:;"></a>
                        </li>
                        <li>
                            <a class="social-icon-color twitter" data-original-title="Twitter" href="javascript:;"></a>
                        </li>
                        <li>
                            <a class="social-icon-color googleplus" data-original-title="Goole Plus" href="javascript:;"></a>
                        </li>
                        <li>
                            <a class="social-icon-color linkedin" data-original-title="Linkedin" href="javascript:;"></a>
                        </li>
                    </ul>
                </div> -->
				<!--
                <div class="create-account">
                    <p>
                        <a href="javascript:;" id="register-btn" class="uppercase">Create an account</a>
                    </p>
                </div>
				-->
            </form>
            <!-- END LOGIN FORM -->
            <!-- BEGIN FORGOT PASSWORD FORM -->
            
            <!-- END REGISTRATION FORM -->
        </div>
		
<?php
if(isset($_POST['sub'])){
		
		 $fname = $_POST['distributor_email'];
		 $pass = $_POST['password'];
		 $flag_temp=0;
		 $r_temp=session_id();
		 $temp_time=time();
		 
		$res_search = mysqli_query($con,"select * from tbl_distributor_users where status='Active' and distributor_email='$fname' && password='$pass'");
		$row_search  = mysqli_num_rows($res_search);
		$a21=mysqli_fetch_array($res_search);
		if($row_search>0)
		{
			$ver=$a21['distributor_user_id'];
			if($a21['session_id']=="")
			{
				$check_dis_id=$a21['distributor_id'];
				$res_search_dis = mysqli_query($con,"select * from tbl_distributor_users where distributor_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
				{
					$uq1=mysqli_query($con,"UPDATE tbl_distributor_users SET login_datetime='$temp_time',session_id='$r_temp',activity_time='$temp_time' where distributor_user_id='$ver'");
				
					$_SESSION['user_id']=$a21['distributor_id'];
					$_SESSION['dis_user_id']=$ver;
					$res11 = mysqli_query($con,"Select * from tbl_distributor where distributor_id='$check_dis_id'");
					/* while($row11=mysqli_fetch_array($res11))
					{
						$distributor_category=$row11['distributor_category'];
						if (strpos($distributor_category, 'Serial No') !== false)
							$_SESSION['serialno_sale']="Yes";
						else
							$_SESSION['serialno_sale']="No";
						$flag_temp=1;
					}*/
					$_SESSION['user_role']=$a21['user_role'];
					$_SESSION['user_session']=$r_temp;
					if($res11>0){ 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_distributor_users SET login_datetime='$temp_time',session_id='$r_temp',activity_time='$temp_time' where distributor_user_id='$ver'");	
					// destroy session data in storage
					$_SESSION['user_id']=$a21['distributor_id'];
					$_SESSION['dis_user_id']=$ver;
					$res11 = mysqli_query($con,"Select * from tbl_distributor where distributor_id='$check_dis_id'");
					while($row11=mysqli_fetch_assoc($res11))
					{
						$_SESSION['serialno_sale']=$row11['serialno_sale'];
						$flag_temp=1;
					}
					$_SESSION['user_role']=$a21['user_role'];
					$_SESSION['user_session']=$r_temp;
					if($flag_temp==1)
					header("location:dashboard.php");
				}
				else
				{
					header("location:login-confirmation.php?logid=".base64_encode($ver));
				}
			}*/

		} 
		else {
		?>
			<script> alert("Email and password does not match!");</script>
		<?php
		}
		}
		?>       
         
        <div class="copyright"> 2018 &copy; <a target="_blank" href="http://www.belltechnology.in">Bell Technology</a></div>

        <!-- BEGIN CORE PLUGINS -->
        <script src="assets/global/plugins/jquery.min.js" type="text/javascript"></script>
        <script src="assets/global/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
        <script src="assets/global/plugins/js.cookie.min.js" type="text/javascript"></script>
        <script src="assets/global/plugins/jquery-slimscroll/jquery.slimscroll.min.js" type="text/javascript"></script>
        <script src="assets/global/plugins/jquery.blockui.min.js" type="text/javascript"></script>
        <script src="assets/global/plugins/bootstrap-switch/js/bootstrap-switch.min.js" type="text/javascript"></script>
        <!-- END CORE PLUGINS -->
        <!-- BEGIN PAGE LEVEL PLUGINS -->
        <script src="assets/global/plugins/jquery-validation/js/jquery.validate.min.js" type="text/javascript"></script>
        <script src="assets/global/plugins/jquery-validation/js/additional-methods.min.js" type="text/javascript"></script>
        <script src="assets/global/plugins/select2/js/select2.full.min.js" type="text/javascript"></script>
        <!-- END PAGE LEVEL PLUGINS -->
        <!-- BEGIN THEME GLOBAL SCRIPTS -->
        <script src="assets/global/scripts/app.min.js" type="text/javascript"></script>
        <!-- END THEME GLOBAL SCRIPTS -->
        <!-- BEGIN PAGE LEVEL SCRIPTS -->
        <script src="assets/pages/scripts/login.min.js" type="text/javascript"></script>
        <!-- END PAGE LEVEL SCRIPTS -->
        <!-- BEGIN THEME LAYOUT SCRIPTS -->
        <!-- END THEME LAYOUT SCRIPTS -->
        <script>
            $(document).ready(function()
            {
                $('#clickmewow').click(function()
                {
                    $('#radio1003').attr('checked', 'checked');
                });
            })
        </script>
    </body>

</html>