<?php	
	require_once("config.php");	
	session_start();
	if(isset($_SESSION['sys_id'])) header("Location: index.php");
if (isset($_POST['login'])){	
	$username = mysql_real_escape_string(stripslashes($_POST['username']));
	$password = mysql_real_escape_string(stripslashes($_POST['password']));	
	$passmd5 = md5($password);
	$sql = "select * FROM v_user WHERE username='$username' and password='$passmd5'" or die(mysql_error());
	$result = mysql_query($sql);
	@$row = mysql_fetch_array($result, MYSQL_ASSOC);
	if (mysql_num_rows($result) != 0){
		$_SESSION['sys_id'] = $row["sysuserid"];
		$_SESSION['sys_type'] = $row["sys_type"];
		$_SESSION['role_id'] = $row["role_id"];
		$_SESSION['orgunitid_t'] = $row["orgunitid"];
		$_SESSION['orgunitid_r'] = $row["orgunitid_r"];
		$_SESSION['parentunit'] = $row["parentunit"];
		$_SESSION['orgunitname'] = $row["orgunitname"];
		$_SESSION['unittypeid'] = $row['unittypeid'];
		$_SESSION['first_name_s'] = $row["first_name"];	
		
		/*=========== session to pop new document in ==, commment by kongxiong==============*/
		if(!isset($_SESSION['tmp_doc_pop'])) $_SESSION['tmp_doc_pop'] = "ON";
		if(isset($_SESSION['temp_url'])){
			$download = $_SESSION['temp_url'];
			unset($_SESSION['temp_url']);
			header("Location: $download");
		}else{
			header("Location: index.php");
		}
		// header("Location: index.php");
		exit();
	} else{
		$message = "&#3722;&#3767;&#3784;&#3740;&#3769;&#3785;&#3779;&#3722;&#3785; &#3755;&#3749;&#3767; &#3749;&#3760;&#3755;&#3761;&#3732;&#3740;&#3784;&#3762;&#3737;&#3738;&#3789;&#3784;&#3734;&#3767;&#3713;&#3733;&#3785;&#3757;&#3719;";
	}
}
	require_once("loginpage.php");