<?php
if($_COOKIE['User']!='')
{
	?>
<script>window.location.href='welcome.php'</script>
<?php
}
?>
<?php
include('db_connection.php');
$Mainclass=new DB_Controller();



	if(isset($_REQUEST['login']))

	{

		$Username=$_REQUEST['username'];

		$Password=$_REQUEST['pass'];

		$Condition=" Binary User_Name='".$Username."' and Binary Password='".$Password."'";

		$Login_Check=$Mainclass->num_check('dealer_login_master','*',$Condition);

		if($Login_Check>0)

		{

			$Get_Login_Details=$Mainclass->Fetch_individual_data('dealer_login_master','*',$Condition);
			if($Get_Login_Details['Active']=='Yes')
			{
				/*if($Get_Login_Details['User_Type']!='Admin' || $Get_Login_Details['User_Type']!='Warehouse' || $Get_Login_Details['User_Type']!='Supervisor')
				{*/
					
					$Get_Zone=$Mainclass->Fetch_individual_data('dealer_master',"Dealer_Zone,Dealer_Type","Order_Code='".$Get_Login_Details['Dealer_Code']."'");
					
					
					$User_Name=$Get_Login_Details['User_Name'];
					$Emp_Name=$Get_Login_Details['Employee_Name'];
					$Emp_Type=$Get_Login_Details['User_Type'];
					$Dealer_Code=$Get_Login_Details['Dealer_Code'];
					$Zone=$Get_Zone['Dealer_Zone'];
					$Deal_Type=$Get_Zone['Dealer_Type'];
					$User_SLN=$Get_Login_Details['SLN'];
					
					
					$Mainclass->cookies('User_Id',$User_SLN);
					$Mainclass->cookies('User_Name',$User_Name);
					$Mainclass->cookies('O_Code',$Dealer_Code);
					$Mainclass->cookies('Type',$Emp_Type);
					$Mainclass->cookies('Dlr_Type',$Deal_Type);
					$Mainclass->cookies('Emp_Name',$Emp_Name);
					$Mainclass->cookies('Zone',$Zone);
					
				/*}
				else
				{
					$User_SLN=$Get_Login_Details['SLN'];
					$User_Name=$Get_Login_Details['User_Name'];
					$Emp_Name=$Get_Login_Details['Employee_Name'];
					$Emp_Type=$Get_Login_Details['User_Type'];
					
					//$Mainclass->cookies('User',$User_Name);
					//$Mainclass->cookies('GType',$Emp_Type);
					$Mainclass->cookies('User_Id',$User_SLN);
					$Mainclass->cookies('Emp_Name',$Emp_Name);
					$Mainclass->cookies('Type',$Emp_Type);
					$Mainclass->cookies('User_Name',$User_Name);
				}*/
			
				$Values="'".$Get_Login_Details['SLN']."','".$_SERVER['REMOTE_ADDR']."','".date('Y-m-d H:i:s')."'";
$Tracking=$Mainclass->Insert_Data('login_tracking_details',"User_SLN,Login_Ip,Last_Login",$Values);
$FieldValue=" Last_Login_Date_Time='".date('Y-m-d H:i:s')."',Last_Login_IP='".$_SERVER['REMOTE_ADDR']."'";
$Condition=" SLN='".$Get_Login_Details['SLN']."'";
$Update_Login_Det=$Mainclass->Update_Data('dealer_login_master',$FieldValue,$Condition);
			
			
			?>

	<script>window.location.href='welcome.php';</script>

	<?php
			}
			else
			{
				$Err="User Deactivated";
			}

			

		}

		else

		{

		$Err="Invalid Credential";	

		}

	}

	?>

<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="utf-8">

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

  <title>Chandrani Pearls Gold Billing</title>

<link rel="icon" type="image/jpg" href="dist/img/favicon.png?v=1">

  <!-- Google Font: Source Sans Pro -->

  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">

  <!-- Font Awesome -->

  <!--<link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css">-->
	
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css" />

  <!-- icheck bootstrap -->

  <link rel="stylesheet" href="plugins/icheck-bootstrap/icheck-bootstrap.min.css">

  <!-- Theme style -->

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

  <link rel="stylesheet" href="dist/css/custom.css?v=1">

  <style type="text/css">

  

  html { 

background: url(dist/img/gold_background.webp?v=3) no-repeat center center fixed;

-webkit-background-size: cover;

-moz-background-size: cover;

-o-background-size: cover;

background-size: cover;

min-height: 100%;

}

  </style>

 <script>
    function show_pass()
    {
      $('#showdiv').hide();
      $('#hidediv').show();
      var passInput=$("#passInput").attr('type','text');
    }
    function hide_pass()
    {
      $('#showdiv').show();
      $('#hidediv').hide();
      var passInput=$("#passInput").attr('type','password');
    }
    </script> 

  

</head>

	

<body class="hold-transition login-page" style="background-color:transparent;">

<div class="login-box" style="background-color:transparent;">

  <!-- /.login-logo -->

  <div class="card card-outline card-primary">

    <div class="card-header text-center">

     <img src="dist/img/logo-web.png" width="210">

    </div>

    <div class="card-body">

		

      <p class="login-box-msg" style="color:#FF0000; font-weight:600;"><?php if($Err!=''){echo $Err;}?></p>

      <form action="#" method="post">

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

          <input type="text" name="username" class="form-control" placeholder="User Name">

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

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

              <span class="fas fa-user"></span>

            </div>

          </div>

        </div>

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

          <input type="password" name="pass" id="passInput" class="form-control" placeholder="Password">

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

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

              <span id="showdiv" class="fa-solid fa-eye" style="cursor: pointer;" onclick="show_pass()" title="Show Password"></span>

              <span id="hidediv" class="fa-solid fa-eye-slash" style="cursor: pointer; display:none;" onclick="hide_pass()" title="Hide Password"></span>

            </div>

          </div>

        </div>

        <div class="row">

          

          <!-- /.col -->

          <div class="col-12">

            <button type="submit" name="login" class="btn btn-custom btn-block" style="border:0px;">Log In</button>

          </div>

          <!-- /.col -->

        </div>

      </form>

      

      <!-- /.social-auth-links -->

      <!--<p class="mb-1">

        <a href="forgot-password.php"> Forgot Password?</a>

      </p>-->

      

    </div>

    <!-- /.card-body -->

  </div>

  <!-- /.card -->

</div>

<!-- /.login-box -->

<!-- jQuery -->

<script src="plugins/jquery/jquery.min.js"></script>

<!-- Bootstrap 4 -->

<script src="plugins/bootstrap/js/bootstrap.bundle.min.js"></script>

<!-- AdminLTE App -->

<script src="dist/js/adminlte.min.js"></script>

</body>

</html>