<?php
session_start();
include '_connect.php';
if((isset($_REQUEST['user']) && $_REQUEST['user']!=null) && (isset($_REQUEST['pass']) && $_REQUEST['pass']!=null )){
$user=$_REQUEST['user'];
$pass=$_REQUEST['pass'];
// $user=mysql_real_escape_string($_REQUEST['user']);
// $pass=mysql_real_escape_string($_REQUEST['pass']);
  $query=$conn->prepare("SELECT * from [ehongdb].[dbo].[EMPLOYEE] where ((BARCODE='$user' OR US_NAME='$user') and US_PASSWD='$pass')"); // and (DP_ID=13 or DP_ID=15 or DP_ID=25)
$query->execute();
$numRows=$query->rowCount();
if ($numRows!=0) {
 $fetch = $query->fetch();
 $_SESSION['EMP_ID']=$fetch['EMP_ID'];
 $_SESSION['US_NAME']=$fetch['US_NAME'];
 $_SESSION['uid']=$fetch['US_NAME'];
 $_SESSION['DP_ID']=$fetch['DP_ID'];
 $_SESSION['PHONE']=$fetch['PHONE']; //เบอร์โทรศัพท์
 $_SESSION['BR_ID']=$fetch['BR_ID']; //สาขา
 $_SESSION['uname']=$fetch['TNAME'].$fetch['FNAME']."  ".$fetch['LNAME']; //ชื่อ-สกุล
 $_SESSION['user']=$_REQUEST['user'];
 echo "<script>alert('ยินดีต้อนรับครับ')</script>";
 header( "Refresh:0;url=index.php" );
}else echo "<script>alert('ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง'); window.location.href='../index.html';</script>";
}else echo "<script>alert('กรอกข้อมูลให้ครบ'); window.location.href='../index.html';</script>";
?>
