<?php
session_start();

require_once("../web.config.php");
require_once("include/Function.Manage.Config.php");


//$tip="";
if( isset($_POST["name"],$_POST["password"],$_POST["checkCode"] ) )
{
	$adminName=$_POST["name"];
	$adminPassword=md5($_POST["password"]);
	$checkCode=$_POST["checkCode"];
	if( strtolower($_SESSION["checkCode"])== strtolower($checkCode ) ){

		$sql="select * from deep_Admin where fuserName='$adminName' and fpassword='$adminPassword' ";
		$stmt = $conn->query($sql)or die("SQL语句执行错误！"); 
		if( $row = $stmt->fetch() )
		{
			$tip="登陆提交成功！！！";
			// 用户合法
			$ip=$_SERVER['REMOTE_ADDR'];
			//date_default_timezone_set("PRC");//GMT格林尼治标准时间
			$now=date('Y-m-d H:i:s');

			$conn->exec("update deep_Admin set flastLoginIP='$ip',flastLoginTime='$now',floginTimes=floginTimes+1 where id=".$row["id"]);
			
			setcookie("thisLoginTime",$now);
			setcookie("lastLoginTime",$row["flastLoginTime"]);
			setcookie("lastLoginIP",$row["flastLoginIP"]);
			setcookie("loginTimes",$row["floginTimes"]+1);
			
			$_SESSION["adminName"]=$adminName;// 设置用户姓名到session范围
			header("location:manage.php"); 
			//exit();
			//echo "<script language='javascript'>window.location.href='manage.php';</ script>";
		}else{
			$tip="用户名或密码错误！！！请重新输入";
		}

	}else{
		$tip="验证码输入错误！！！请重新输入";
	}	
}

$page_title="系统后台登陆界面";
$login_title="管理员登录";

require_once("themes/".$themes_Path."/Login.master.php") ;

// ------------------------------------------------------------------
function LoginForm()
{
?>
<form id="formLogin" name="admininfo" method="post" action="" onSubmit="return checkSubmit()">
  <table>
    <tr>
      <td><div align="center">用户名：</div></td>
      <td><input type="text" name="name" /></td>
    </tr>
    <tr>
      <td><div align="center">密  码：</div></td>
      <td><input type="password" name="password" /></td>
    </tr>
    <tr>
      <td><div align="center">验证码：</div></td>
      <td><input type="text" name="checkCode" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><img src="../Deep_library/Deep.util.validatorCode.php" width="85" height="20" onClick="this.src+='?rand='+Math.random();" title="看不清？单击此处刷新" style="cursor:pointer;"/></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><div align="center">
          <input type="submit" name="Submit" value="登 录"  />
          &nbsp;
          <input type="reset" name="Reset" value="清 除" />
        </div></td>
    </tr>
  </table>
</form>
<script type="text/javascript">
    function checkSubmit()
    {
      if(document.admininfo.name.value=="") {
        document.admininfo.name.focus();
        alert("管理员用户名不能为空！");
        return false;
      }
      if(document.admininfo.password.value=="") {
        document.admininfo.password.focus();
        alert("密码不能为空！");
        return false;
      }
        if(document.admininfo.checkCode.value=="") {
        document.admininfo.checkCode.focus();
        alert("验证码不能为空！");
        return false;
      }
    
    }
    </script>

<?php
}
?>


