<?php session_start();
include('includes/dbcon.php');

if(isset($_POST['login']))
{
  // echo "dd";
$user_unsafe=$_POST['username'];
$pass_unsafe=$_POST['password'];
//$branch_id=$_POST['$branch'];

//echo $user_unsafe;
$user = mysqli_real_escape_string($con,$user_unsafe);
$pass1 = mysqli_real_escape_string($con,$pass_unsafe);


//echo "aa";

$salt="a1Bz20ydqelm8m1wql";
$pass=$pass1;


date_default_timezone_set('Asia/Manila');

$date = date("Y-m-d H:i:s");

//echo $pass;

$sqlquery="SELECT users_master.*,users_master.userid AS uid ,authority_levels.Authority_Des FROM users_master  
 LEFT JOIN authority_levels ON users_master.al=authority_levels.Authority_Level  where users_master.username='$user' and password='$pass' ";


//echo $sqlquery;
$query=mysqli_query($con,$sqlquery)or die(mysqli_error($con));
  $row=mysqli_fetch_array($query);
  $counter=mysqli_num_rows($query);
       // echo $counter;   
                 
    if ($counter == 0) 
    { 
 

    //  echo $sqlquery;
  // echo "<script type='text/javascript'>alert('Invalid Username or Password!')";
  
   // echo "<script type='text/javascript'>document.location='index.php'</script>";
    } 
    elseif ($counter > 0)
    {
           
             // echo "ll";
            $rm_id=$row['uid'];
           $rm_name=$row['username'];
           $rm_al=$row['al'];   
           $rm_Authority_Des=$row['Authority_Des'];           
           $rm_emp_id=$row['emp_id']; 
         
    
   
    $_SESSION['rm_id']=$rm_id;  
    $_SESSION['rm_name']=$rm_name;
    $_SESSION['rm_al']=$rm_al;  
    $_SESSION['rm_Authority_Des']=$rm_Authority_Des;    
    $_SESSION['rm_emp_id']=$rm_emp_id;

//echo "kk:";
//echo $hrm_emp_id;
//echo $hrm_id;
     echo "<script type='text/javascript'>document.location='pages/home.php'</script>";
      
    }
}  
?>

  
