<?php
/***********************************************************      
 程序说明：         
	功能说明：用户登入系统
	调用关系：调用: header.inc     
              被调用:      
	变量说明：
	返回值：无
	作者：CuiTicun    
      
修改注释：      
NO.1      
姓名：            
时间：      
修改说明：      
*********************************************************/  
session_start();
if(strlen($selectedLanguage)  < 1){
	$selectedLanguage = 'eng';
}
if($selectedLanguage != $userInfo[language]){
	$userInfo[language]=$selectedLanguage;
}
require("../../inc/header.inc");
$userIP =  getenv("HTTP_X_FORWARDED_FOR"); 
if( $userIP == "" ){ 
	$userIP = getenv("REMOTE_ADDR"); 
}
$DEBUG = 0;
$pubDb='OMC_PUB';
$userTable='sysUser';
if($DEBUG) echo "<br>selectedLanguage=$selectedLanguage";
if($DEBUG) echo "<br>selectedOmcPath=$selectedOmcPath";

if(strlen($login) > 0){
	if($DEBUG) echo "<br>selectedLanguage=$selectedLanguage";
	if($DEBUG) echo "<br>userName=$userName";
	if($DEBUG) echo "<br>userPwd=$userPwd";
	$isChkPass = 0;
	//检查用户是否存在，密码是否正确
	$chkSQL="SELECT privilege 
			FROM $userTable 
			WHERE userName='$userName' AND password=password('$userPwd')
			"; 
	if($DEBUG) echo "<br>chkSQL=$chkSQL";
	$chkResult = mysqli_query($pubConn,$chkSQL); 
	echo mysqli_error($pubConn);
	$row = mysqli_fetch_array($chkResult); 
	if(mysqli_num_rows($chkResult) > 0){
		$isChkPass = 1;
	}
	//通过检查
	if($isChkPass == 1){
		//将用户资料导入session
		session_register("userInfo");  //保存用户帐号信息
		$userInfo = array(ID,privilege,IP,language); 
		$userInfo[ID]		=$userName; 
		$userInfo[privilege]=$row[privilege]; 
		$userInfo[IP]		=$userIP; 
		$userInfo[language]	=$selectedLanguage; 
		$userInfo[refresh_time]	=time(); 
		insertLog("Log in");
		if($DEBUG) echo "<br>userInfo[ID]=$userInfo[ID]";
		if($DEBUG) echo "<br>userInfo[privilege]=$userInfo[privilege]";
		if($DEBUG) echo "<br>userInfo[IP]=$userInfo[IP]";
		if($DEBUG) echo "<br>userInfo[language]=$userInfo[language]";
		?>
		<SCRIPT LANGUAGE="JAVASCRIPT">
		<!--
		var URL='../../index.php';
		var d,windowName;
		var windowName;
		var msgWindow;

		var baseSetting='toolbar=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,left=0,top=0';
		var size800=',width=790,height=560';
		var size1024=',width=1010,height=710';

		d = new Date();
		windowName = d.getTime();

		if (window.screen.width==800 && window.screen.height==600){
			pageSetting = baseSetting + size800;
		}else{
			pageSetting = baseSetting + size1024;
		}
		msgWindow = window.open(URL,windowName,pageSetting);
		-->
		</script>
		<?php
	}else{
		//没有通过用户检查
		//写入日志
		insertLog("Login Error:IP=$userIP,User name=$userName");
		//报错
		?>
		<SCRIPT LANGUAGE="JAVASCRIPT">
		<!--
			alert("User ID or Password Error!");
		//-->
		</script>
		<?php
	}
}
?>
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
function loadset(){
	document.loginForm.userName.value='';
	document.loginForm.userPwd.value='';
	<?php
	if(!isset($login)){
		echo "document.loginForm.userName.focus();";
	}
	?>

}

function Check(theform){
	var username=theform.userName.value;
	var password=theform.userPwd.value;
	if (username.length < 1){  
		alert("User ID error!");
		theform.userName.focus();
		return (false);
	}
	if (password.length < 6){
		alert("password length must >= 6");
		theform.userPwd.focus();
		theform.userPwd.select();
		return (false);
	}
	return (true);
}

function selectEng(){
	window.location.href="<?php echo"$PHP_SELF?selectedLanguage=eng";?>";
}

function selectChn(){
	window.location.href="<?php echo"$PHP_SELF?selectedLanguage=chn";?>";
}

//-->
</script>

<body bgcolor="#FFFFFF"  onload="loadset()">
<br><br><br><br><br><br>
<form method="POST" name=loginForm action="<?php echo "$PHP_SELF?selectedLanguage=$selectedLanguage"?>" onsubmit="return Check(this)" >
<table border="0" width="100%" height="75%" valign="center">
<tr>
<td width="100%" align="center" height="25%" valign="bottom">
	<img border="0" src="../../images/alto_logo_80.gif"> 
	<br><br><br>
</td>  
</tr>  
<tr> 
<td width="100%" align="center" height="10"> 
	<table border="1" width="280" bordercolordark="#FFFFFF" bordercolor="#808080" cellspacing="0" height="120">
	<tr>
	<td width="100%" colspan="2" bgcolor="#E6E6E6" height="20" align="center">
		<b><font size="2">
		<?php echo "$loginTitle"; ?>
		</font></b>
	</td>  
	</tr>  
	<tr>  
	<td>     
		<?php
			echo "<img border=\"0\" src=\"../../images/loginUser.gif\" > $strUserName";
		?>
	</td>
	<td align="center">     
		<input type="text" name="userName" size="20" class="text"> 
	</td>     
	</tr>  
	<tr>  
	<td>
		<?php
			echo "<img border=\"0\" src=\"../../images/loginPwd.gif\" >  $strPassword";
		?>
	</td>     
	<td align="center">     
		<input type="password" name="userPwd" size="20" class="text">       
	</td>    
	</tr> 
	<tr> 
	<td colspan="2" align="center">  
		<?php
			echo "<input type=\"submit\" value=\"$strLogin\" name=\"login\" class=\"button\">";
			echo "&nbsp;&nbsp;&nbsp;";
			echo "<input type=\"reset\" value=\"$strCancel\" class=\"button\">";
		?>
	</td>     
	</tr>
	</table> 
</td>  
</tr>
<tr><td align="center">
		<?php
			if($selectedLanguage == 'chn'){
				echo "<a style=\"Cursor:hand\" onclick=\"javascript:selectEng()\"><image src=\"../../images/english.gif\">"; 
			}else{
				echo "<a style=\"Cursor:hand\" onclick=\"javascript:selectChn()\"><image src=\"../../images/chinese.gif\">";
			}
		?>
</td></tr>
<tr><td align="center"><b><font size=6>R9.2(V9.02.00.015)</font></b></td></tr>
</table>
</form>
</body> 

