<?php
# Name: PHP版程氏音乐CMS管理系统 v3.0
# Author: 程氏<web@chshcms.com> [QQ:848769359]
# Homepage:http://www.chshcms.cn/

include "../lib/cs_conn.php";
include "../lib/cs_common.php";
$action=CS_Request("a");
$CS_Name=CS_Request("adminname");
$CS_Pass=md5(CS_Request("password"));
$CS_Code=CS_Request("code");
if($action=="logout"){
	setcookie("CS_AdminUP","",time()-1,'/');
	setcookie("CS_AdminID","",time()-1);
	setcookie("CS_AdminUserName","",time()-1);
	setcookie("CS_AdminPassWord","",time()-1);
	setcookie("CS_Qianx","",time()-1);
	setcookie("CS_Login","",time()-1);
	die("<script>window.parent.window.location.href='login.php'</script>");
}
if($CS_Name and $CS_Pass and $CS_Code){
	$logtime=date('Y-m-d H:i:s');
	if(!empty($_SERVER["HTTP_CLIENT_IP"]))
	   $UIP = $_SERVER["HTTP_CLIENT_IP"];
	else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))
	   $UIP = $_SERVER["HTTP_X_FORWARDED_FOR"];
	else if(!empty($_SERVER["REMOTE_ADDR"]))
	   $UIP = $_SERVER["REMOTE_ADDR"];
	else
 	  $UIP = "无法获取！";

	if($CS_Code!=CS_AdminCode){
		die(Admin_Error('抱歉，认证码错误！','login.php'));
	}
	$sql= "Select CS_ID from ".Getdbname('admin')." where CS_AdminName='".$CS_Name."' and CS_AdminPass='".$CS_Pass."'";
        $CS_ID= $db->Getone($sql);//从数据库中返回1
	if($CS_ID){
		 $db->query("update ".Getdbname('admin')." set CS_LoginNum =CS_LoginNum +1,CS_LoginIP='".$UIP."',CS_LoginTime ='".$logtime."' where CS_ID='".$CS_ID."'");
		 $row=$db ->Getrow("Select * from ".Getdbname('admin')." where CS_ID='".$CS_ID."' ");
		 setcookie("CS_AdminUP",$row['CS_ID'],time()+360000,'/');
		 setcookie("CS_AdminID",$row['CS_ID']);
		 setcookie("CS_AdminUserName",$row['CS_AdminName']);
		 setcookie("CS_AdminPassWord",md5($row['CS_AdminPass']));
		 setcookie("CS_Quanx",$row['CS_Quanx']);
		 setcookie("CS_Login",md5($row['CS_ID'].$row['CS_AdminName'].md5($row['CS_AdminPass']).$row['CS_Quanx']));
	         header("Location:index.php");
	}else{
		die(Admin_Error('用户非法！','login.php'));
	}	
}
?>
<!doctype html>
<html>
	<head>
		<meta charset=utf-8 />
		<title>csdjcms management</title>
		<link href="res/css/admin_login.css" rel="stylesheet" />
		<script>
			if (window.parent !== window.self) {
					document.write = '';
					window.parent.location.href = window.self.location.href;
					setTimeout(function () {
							document.body.innerHTML = '';
					}, 0);
			}
		</script>

	</head>
<body>
	<div class="wrap">
		<h1><a href="../">phpwind 后台管理中心</a></h1>
		<form method="post" name="login" action="" autoComplete="off">
			<div class="login">
				<ul>
					<li>
						<input class="input" id="admin_name" required="required" name="adminname" type="text" placeholder="帐号名" title="帐号名" />
					</li>
					<li>
						<input class="input" id="admin_pwd" type="password" required="required" name="password" placeholder="密码" title="密码" />
					</li>
					<li>
						<input class="input" id="admin_code" type="password" required="required" name="code" placeholder="认证码" title="认证码" />
					</li>
				</ul>
				<button type="submit" name="submit" class="btn">登录</button>
			</div>
		</form>
	</div>
<script src="res/js/jquery.js"></script>
<script> 
	//不支持placeholder浏览器下对placeholder进行处理
	if(document.createElement('input').placeholder !== '') {
		$('[placeholder]').focus(function() {
			var input = $(this);
			if(input.val() == input.attr('placeholder')) {
				input.val('');
				input.removeClass('placeholder');
			}
		}).blur(function() {
			var input = $(this);
			if(input.val() == '' || input.val() == input.attr('placeholder')) {
				input.addClass('placeholder');
				input.val(input.attr('placeholder'));
			}
		}).blur().parents('form').submit(function() {
			$(this).find('[placeholder]').each(function() {
				var input = $(this);
				if(input.val() == input.attr('placeholder')) {
					input.val('');
				}
			});
		});
	}
</script>
</body>
</html>

