<?php 
if(isset($_SESSION))
{
	session_destroy();
}
include('include/settings.php');
$message="";
$msg='';
if(isset($_POST["btnSignIn"]))
{
	if(trim($_POST["txtUserName"])!=null && trim($_POST["txtPassword"])!=null)
	{
		$my_user_email=strtolower($_POST["txtUserName"]);
		$sql=$mysqli->prepare("select user_id,user_email_id,user_password,user_type,user_creationdate from cdi_usermaster where user_status=1 and user_email_id=? and user_type='sales'");
		$sql->bind_param("s",$my_user_email);
		$sql->execute();
		$sql->bind_result($user_id,$user_email_id,$user_password,$user_type,$user_creationdate);
		if($sql->fetch()>0)
		{
			if(md5('cybeRintelligencE'.$_POST["txtPassword"].$user_creationdate)==$user_password)
			{
				$sql->close();
				$_SESSION["userId"]=$user_id;
				$_SESSION["userEmail"]=$user_email_id;
				$_SESSION["userType"]=$user_type;
				
				header("location:./index.php");
			}
			else
			{
				$msg="Please enter correct credentials.";
			}
		}
		else
		{
			$msg="Please enter correct credentials.";
		}
	}
	else
	{
		$msg="All fields are required.";
	}
}	
?>
<!DOCTYPE html>
<html lang="en">
<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="">
    <meta name="author" content="">
    <link rel="icon" href="https://crm-admin-dashboard-template.multipurposethemes.com/images/favicon.ico">

    <title> Log in </title>
  
	<!-- Vendors Style-->
	<link rel="stylesheet" href="../src/css/vendors_css.css">
	  
	<!-- Style-->  
	<link rel="stylesheet" href="../src/css/style.css">
	<link rel="stylesheet" href="../src/css/skin_color.css">	

</head>
	
<body class="hold-transition theme-primary bg-img" style="background-image: url(../../../images/auth-bg/bg-1.jpg)">
	
	<div class="container h-p100">
		<div class="row align-items-center justify-content-md-center h-p100">
		    	
			<p class="errormessage" id="errormessage"><?php echo $msg ?></p>
			<img src="https://rishtasite.in/lead-crm/assets/images/fav.png" alt="Rishta" style="height:50px; width:250px;">
			<div class="col-12">
			    
				<div class="row justify-content-center g-0">
					<div class="col-lg-5 col-md-5 col-12">
						<div class="bg-white rounded10 shadow-lg">
							<div class="content-top-agile p-20 pb-0">
								<h2 class="text-primary">Let's Get Started</h2>
								<p class="mb-0">Sign in to continue</p>							
							</div>
							<div class="p-40">
								<form action="#" method="post">
									<div class="form-group">
										<div class="input-group mb-3">
											<span class="input-group-text bg-transparent"><i class="ti-user"></i></span>
											<input autocomplete="off" type="text" id="txtUserName" name="txtUserName" class="form-control ps-15 bg-transparent" placeholder="Username">
									
				
										</div>
									</div>
									<div class="form-group">
										<div class="input-group mb-3">
											<span class="input-group-text  bg-transparent"><i class="ti-lock"></i></span>
											<input autocomplete="off" type="password" id="txtPassword" name="txtPassword" class="form-control ps-15 bg-transparent" placeholder="Password">
				
										</div>
									</div>
									  <div class="row">
										<div class="col-6">
										  <div class="checkbox">
											<input type="checkbox" id="basic_checkbox_1" >
											<label for="basic_checkbox_1">Remember Me</label>
										  </div>
										</div>
										<!-- /.col -->
										<!--div class="col-6">
										 <div class="fog-pwd text-end">
											<a href="javascript:void(0)" class="hover-warning"><i class="ion ion-locked"></i> Forgot pwd?</a><br>
										  </div>
										</div-->
										<!-- /.col -->
										<div class="col-12 text-center">
										  <button type="submit" id="btnSignIn" name="btnSignIn" class="btn btn-danger mt-10 btnCustom" onclick="return validate()">SIGN IN</button>
										  
										</div>
										<!-- /.col -->
									  </div>
								</form>	
								<!--div class="text-center">
									<p class="mt-15 mb-0">Don't have an account? <a href="auth_register.html" class="text-warning ms-5">Sign Up</a></p>
								</div-->	
							</div>						
						</div>
						<!--div class="text-center">
						  <p class="mt-20 text-white">- Sign With -</p>
						  <p class="gap-items-2 mb-20">
							  <a class="btn btn-social-icon btn-round btn-facebook" href="#"><i class="fa fa-facebook"></i></a>
							  <a class="btn btn-social-icon btn-round btn-twitter" href="#"><i class="fa fa-twitter"></i></a>
							  <a class="btn btn-social-icon btn-round btn-instagram" href="#"><i class="fa fa-instagram"></i></a>
							</p>	
						</div-->
					</div>
				</div>
			</div>
		</div>
	</div>


	<!-- Vendor JS -->
	<script src="../src/js/vendors.min.js"></script>
	<script src="../src/js/pages/chat-popup.js"></script>
    <script src="../../../assets/icons/feather-icons/feather.min.js"></script>	

</body>
</html>

<script type="text/javascript">
	function validate()
	{
		if($.trim($('#txtUserName').val())=="")
		{
			alert('Please enter your username.');
			return false;
		}
		else if($.trim($('#txtPassword').val())=="")
		{
			alert('Please enter your password.');
			return false;
		}
		else
		{
			var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
			if(emailReg.test($('#txtUserName').val()) == false)
			{
				 alert('Please enter correct email id.');
				return false;
			}
			return true;
		}
	}
	
        $(document).ready(function () {
            $('#fp').hide();
            $('a.fp').click(function () {
                $('#login').hide();
                $('#fp').show();
            });
            $('#btnCancel').click(function () {
                $('#fp').hide();
                $('#login').show();
            });
			
			$('#btnSubmit').click(function () {
				var email=$('#txtFpEmail').val();
				if($.trim(email).length==0)
				{
					$('#errorforgotmessage').text('Please Enter Correct Email Id.');
				}
				else
				{
					var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
					if(emailReg.test(email) == false)
					{
						$('#errorforgotmessage').text('Please Enter Correct Email Id.');
						return false;
					}
					else
					{
						$.ajax({
								url: 'check-for-password.php',
								type: 'post',
								data:  {"email":email},
								datatype: 'html',
								success: function(rsp)
								{
									if(rsp==1)
									{
										$('#errorforgotmessage').text('Please reset password by clicking on the link we sent you in email.');
										$('#txtFpEmail').val('');
									}
									else
									{
										$('#errorforgotmessage').text('Sorry, User Doesnot exists with this email id.');
									}
								}
							});
					}
				}
            });
			
			
			
        });
    </script>
