<?php include('config.php');
session_start();
session_regenerate_id();
$dateqe = new DateTime("now", new DateTimeZone('Asia/Dhaka')); 
date_default_timezone_set('Asia/Dhaka'); 
$datetime = date("Y-m-d H:i:s", $dateqe->format('U'));

	if(isset($_POST['username']) && isset($_POST['password']))
	{
		$username = mysqli_real_escape_string($conn,$_POST['username']);
		$password = mysqli_real_escape_string($conn,$_POST['password']);

		$stmt =mysqli_query($conn,"SELECT uid,password,us_coid,us_bid,us_brid,us_language,us_ugid,bid_per,brid_per,route_per,us_em_id,co_permission,business_permission,branch_permission,group_permission,company.balance,company.expiry_date,company.currency,company.co_f_year_start,company.decimaltk,company.decimalitem,branch.branch_email,branch.printer_set,user_g.default_set FROM user 
		LEFT JOIN company ON (user.us_coid=company.coid)
		LEFT JOIN business ON (user.us_bid=business.bid AND user.us_coid=business.coid)
		LEFT JOIN branch ON (user.us_brid=branch.brid AND user.us_coid=branch.coid)
	    LEFT JOIN user_g ON (user.us_ugid=user_g.ugid AND user.us_coid=user_g.coid)
	    WHERE username='$username' AND password='$password' AND us_status=1 AND user_g.status=1 AND business.active=1 AND branch.active=1 LIMIT 1")or die(mysqli_error($conn));

	    $row=mysqli_fetch_assoc($stmt);

	    if (mysqli_num_rows($stmt)>0 && @$row['uid']) {

	      foreach($row as $name => $value) {
	    	$_SESSION['USER'][$name] = $value;
	      }

	      $sid = session_id();
          mysqli_query($conn,"UPDATE user SET us_sid='$sid' WHERE uid =".$row['uid']." LIMIT 1");
          echo "Bangladesh";
	    } else {

				echo "Email Or Password Dose Not Match";
		}
    }
?>