<?
$SelLanguage   = $HTTP_POST_VARS["SelLanguage"];  
$loginid       = $HTTP_POST_VARS["loginid"];      //--Login名稱
$pwd           = $HTTP_POST_VARS["pwd"];          //--Loginpwd
if (empty($SelLanguage)) $SelLanguage = "Traditional_chinese";
require_once("config/".$SelLanguage);
require_once("_ConnectString.php");
require_once("_image.php");
require_once("_read_source/_operateusers.php");
require_once("Display/com_name.php");

$size_page="20";
$path="./config/";
$sessPath = "../php/session/";

function fn_Language($SelLanguage){
	global $path;
	$LanguageList = "";
	$handle = opendir($path);
	while ($strfile = readdir($handle)){
		if ((strlen($strfile)>2) && ($strfile!="Config.php")){
			$LanguageList = ($strfile == $SelLanguage) ? $LanguageList."<option value=\"$strfile\" selected>".$strfile."</option>" : $LanguageList."<option value=\"$strfile\">".$strfile."</option>";
		}
	}
	closedir($handle); 
	return $LanguageList;
}

//--輸入帳號和pwd後的處理動作
if(isset($loginid) && isset($pwd)){
	$pwdmd5 = "D".md5(trim($pwd));		//--將密碼轉成md5,以便查詢
	$strSQL = "Select * from ".$DB_OPERATEUSERS." where ".$DB_OPERATEUSERS_LOGINID."='".$loginid."' and ".$DB_OPERATEUSERS_PWD."='".$pwdmd5."'";
	$intSQL = mysql_query($strSQL);

	$login_ip = (!getenv(HTTP_X_FORWARDED_FOR))?( getenv(REMOTE_ADDR)):(getenv(HTTP_X_FORWARDED_FOR)); 
	$login_time = date("Y-m-d H:i:s");

	//--login success
	if ((mysql_num_rows($intSQL)) == 1){
		$row=mysql_fetch_array($intSQL);

		$status = "Login Success";
        $memo = $SelLanguage;

        $LoginID_Sess		= $loginid; 
		$OperateRole_Sess	= $row["operaterole"];
		$GroupNo_Sess		= $row["groupno"];
		$Sess_time			= $login_time;

        //--login 成功時,產生所要的session變數
		session_save_path($sessPath); 
		session_start();
		session_register("SelLanguage");
		session_register("size_page");
		session_register("LoginID_Sess"); 
		session_register("OperateRole_Sess"); 
        session_register("GroupNo_Sess"); 
		header("location: ./frame/main.php");
	}
	else{
		$status = "Login Fail";
        $memo = $SelLanguage;

     	$SQL="insert into LOGINLOG (loginid,pwd,login_ip,login_time,status,memo) values ('$loginid','$pwd','$login_ip','$login_time','$status','$memo')"; 
        mysql_query($SQL); 

		print "<html><title></title><head>";
		print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=unicode\">";
		print "<center><b><font size=\"10\" color=\"red\">".$L_BREAK."</font></b></center>";
		print "</head></html>";
		exit();
	} 
} 
?> 
<html><head>
<title><?echo $INDEX_TITLE?></title>
<meta http-equiv="Content-Type" content="text/html" charset="UTF-8">
<link href="Display/display.css" type="text/css" rel="stylesheet">
<SCRIPT language=JavaScript src="../inc/fun.js"></SCRIPT>
</head>
<?
include("Display/login.php");
?>
</html>