<?php
@session_start();
@ob_start();
$conn = mysql_connect('localhost', 'akhilagya', 'abhinay@2018AB') or die ("connection not found");
	mysql_select_db('laabh') or die ("connection not found");
//include "header.php"; 
//$objIms->loginpage_alter();
	unset($_SESSION["uname"]);
	unset($_SESSION["pwd"]);
	
	if(isset($_POST["Save"])){
	
	//echo "SELECT * FROM system_login where emailid = '".$_POST["uname"]."' AND password = '".md5($_POST["pwd"])."'";
	 $query = mysql_query("SELECT * FROM system_login where emailid = '".$_POST["uname"]."' AND password = '".md5($_POST["pwd"])."'");
	
	if(mysql_num_rows($query)>0)
	
	{ $row = mysql_fetch_array($query) ;
	$sqlsc="select * from tbl_state where id in (select state from registration where id ='".$row["reg_id"]."' )";
							
							$res_sc=mysql_query($sqlsc);
							
						$row_sc=mysql_fetch_array($res_sc);
						
						$sqlname="select * from registration where id ='".$row["reg_id"]."'";
							
							$res_name=mysql_query($sqlname);
							
						$row_name=mysql_fetch_array($res_name);
		//die('hello');
		$_SESSION["uname"] = $row["emailid"];
		$_SESSION["pwd"] = $row["password"];
		$_SESSION["state_code"] = $row_sc["state_code"];
		$_SESSION["state"] = $row_sc["name"];
		
		$_SESSION["db"] = 'inventory_'.$row["emailid"];
		$_SESSION["name"] = $row_name["name"];
		$_SESSION["org_name"] = $row_name["org_name"];
		$_SESSION["address"]  = $row_name["address"];
		$_SESSION["org_logo"] = $row_name["org_logo"];
		$_SESSION["gstin"] = $row_name["gstin"];
		$_SESSION["city"] = $row_name["city"];
		$_SESSION["pin"] = $row_name["pin"];
		$_SESSION["phone"] = $row_name["phone"];
		$_SESSION["reg_id"] = $row["reg_id"];
		
		
		$id=$row["id"];
		$_SESSION["id"]=$id;
		$_SESSION['login_id']=$row["id"];
		
		  $ip=$_SERVER['REMOTE_ADDR'];
		 //die($ip);
		  $lastlogin_date=date("d-m-Y");
		  date_default_timezone_set("Asia/Kolkata");
		  $last_time=date("H:i:s");
	mysql_query("update  system_login set lastlogin_date='".$lastlogin_date."',last_time='".$last_time."',ipaddress='".$ip."' where id=$id ");
			header("location:admin/index.php");
	
	}
	else
	{	
		
		echo "<span style='color:#fff'>Wrong ID or Password</span>";
		
	}		
}	
?>
<!DOCTYPE HTML>
<html>

<head>
	<title>Laabh</title>
	<!-- Meta-Tags -->
	<link rel="shortcut icon" href="images/icon.png" />
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta charset="utf-8">
	
	<script>
		addEventListener("load", function () {
			setTimeout(hideURLbar, 0);
		}, false);

		function hideURLbar() {
			window.scrollTo(0, 1);
		}
	</script>
	<!-- //Meta-Tags -->
	<!-- Stylesheets -->
	<link href="log_css/font-awesome.css" rel="stylesheet">
	<link href="log_css/style.css" rel='stylesheet' type='text/css' />
	<!--// Stylesheets -->
	<!--fonts-->
	<!-- title -->
	<link href="//fonts.googleapis.com/css?family=Josefin+Slab:100,300,400,600,700" rel="stylesheet">
	<link href="//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800" rel="stylesheet">
	<!--//fonts-->
	<style>
	body {
  /*background: linear-gradient(to right, #123C58, #67A9D3);*/
  /*background: radial-gradient(circle, #67A9D3, #123C58, #67A9D3);*/
}
.w3ls-login form{ border-radius:20px;}
.header h2 {
    font-size: 52px;
    color: #fff ;
    font-family: 'Josefin Slab', sans-serif;
    font-weight: 700;
    text-transform: capitalize;
    letter-spacing: 2px;
    text-shadow: 2px 2px 3px #212121;
}
	</style>
</head>
<!--<body style="background:url(images/blur.jpg);  background-repeat: no-repeat;
    background-size:100%;">-->
<body style=" ">
<div class="container" style="">
<div class="header" style="background:">

			<h2 align="left" style="margin-left:20px; margin-top:10px;">
				<a href="index.php" style="color:#FFFFFF">
					<span style="color:#06d56c">L</span>aabh</a>
			</h2>
			
		</div>
</div>

	<h1 style="color:#FFFFFF;">Login </h1>
	<div class="w3ls-login box box--big" style="margin-top:-20px;">
		<!-- form starts here -->
		<form  method="post" style="background:#FFFFFF">
			<img src="images/icon.png" style="height:90px; width:90px;" alt="" />
			<div class="agile-field-txt">
				<label>
					<i class="fa fa-user" aria-hidden="true"></i> Username</label>
				<input type="text" name="uname" id="uname" placeholder=" " onBlur="chk()" required="" />
			</div>
			<div class="agile-field-txt">
				<label>
					<i class="fa fa-lock" aria-hidden="true"></i> password</label>
				<input type="password" name="pwd" placeholder=" " required="" id="pwd" />
				<div class="agile_label">
					<input id="check3" name="check3" type="checkbox" value="show password" onClick="myFunction()">
					<label class="check" for="check3">Show password</label>
				</div>
				<div class="agile-right">
					<a href="">forgot password?</a>
				<br>
					<a href="register.php" style="color:#000">Register Here.</a>
				</div>
			</div>
			
			<h3 style="color:#FF0000" id="alert_text"></h3>
			<!-- script for show password -->
			<script>
				function myFunction() {
					var x = document.getElementById("myInput");
					if (x.type === "password") {
						x.type = "text";
					} else {
						x.type = "password";
					}
				}
			</script>
			<!-- //end script -->
			<div class="w3ls-bot">
				<div class="switch-agileits">
					
					
				</div>
				<input type="submit" name="Save" value="LOGIN">
			</div>
		</form>
	</div>
	<!-- //form ends here -->
	<!--copyright-->
	<div class="copy-wthree">
		
		
	</div>
	<script src="js/lib/jquery/jquery.min.js"></script>
	
	
	<script>
	function chk(){
	
	var uname = $('#uname').val();
	
			$.ajax({
		type: "POST",
		url: "check_user.php",
		data: "uname="+uname+"&type=log",
		 dataType: 'json', 
		cache: false,
		success: function(data)
			{
				var res = data[0];
				if(res==1){
				$('#uname').val('');
				$('#pwd').val('');
				$('#uname').focus();
				$('#alert_text').html('Sorry your Plan Has Expired Please Upgrade To A Plan or Contact Us.');
				
				}else{
				$('#alert_text').html('');
				}
								
				
				
			}
			});
   
			
			
	}
	</script>
	
	
	<script type="text/javascript">
$(document).ready(function () {

    //Disable full page
    $("body").on("contextmenu",function(e){
        return false;
    });
    
    
});
</script>

	<!--//copyright-->
</body>
</html>
