<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="cui" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<%
String autologin=request.getParameter("autologin");
String forwardUrl=request.getParameter("forwardUrl");
com.cesgroup.cesmonitor.service.LoginUser user=com.cesgroup.cesmonitor.common.Util.getLoginUser();
if(user!=null){
    if(autologin==null){
%>
<script type="text/javascript">
document.getElementById("browser").style.display="none"; 
window.location.href="${ctx}/formview/index";
</script>

<% 
       return;
    }else{
        if(forwardUrl!=null){
            response.sendRedirect(forwardUrl);
            return;
        }
    }
}
%>

<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="shortcut icon" type="images/x-icon"
	href="login/css/images/logoNew.ico">
<title>智能监控平台</title>
<link href="//at.alicdn.com/t/font_9wwm5jywp8yf1or.css" rel="stylesheet">
<link href="login/css/login.css" rel="stylesheet">
<script src="login/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	document.getElementById("browser").style.display="none"; 
});
</script>
<script type="text/javascript">
window.onload=function (){
	var browser=navigator.appName
	var b_version=navigator.appVersion
	var version=parseFloat(b_version)

	document.getElementById("browser").style.display="none"; 
	//alert("2");
	if ((browser=="Netscape"||browser=="Microsoft Internet Explorer") && (version>=5)){
		//alert("3");
		$("body").show();
		document.getElementById("browser").style.display="";
	 }else{	
		// alert("4");
			document.getElementById("browser").style.display="none"; 
		 	var browser="<a target='_blank' href='https://support.microsoft.com/zh-cn/help/17621/internet-explorer-downloads'>IE9</a>"
			var error = "当前浏览器版本过低，至少需要";
			var error2="及以上版本，请先升级！强烈建议您选择并安装新版本浏览器。";
			var str2 = "<h2 style='font-weight:900;padding:10px 0;'><a href='https://www.google.cn/intl/zh-CN/chrome' target='_blank'>Google Chrome</a>,"
			        + "<a href='http://www.firefox.com.cn' target='_blank' >Firefox</a>,"
					+ "<a href='https://support.microsoft.com/zh-cn/help/17621/internet-explorer-downloads' target='_blank' >IE</a></h2>"; 

		 document.writeln("<pre style='font-size:25px;color:black;text-align:center;'>" +
			               "<h2 style='padding-top:200px;margin:0'><strong>" + error+browser+error2+"<br/></strong></h2><h2>" +
			               str2 + "</h2></pre>");  
	      }
	}

</script>
</head>
<body id="browser">
<script type="text/javascript">	
document.getElementById("browser").style.display="none"; 
//alert("8");
</script>

	<% 
   
	String username=request.getParameter("username");
    String password=request.getParameter("password");
    if(autologin!=null && username!=null && password!=null){
        if(forwardUrl==null){
            forwardUrl="${ctx}/php/zabbix.php?action=dashboard.view";
        }
    %>
	<script type="text/javascript">
        //http://localhost/cesmonitor/login?autologin=1&username=Admin&password=zabbix
        function autoLogin(loginUrl,usernameValue,passwordValue,forwardUrlValue){
        //	alert(loginUrl+username+password);
    	    var form = document.createElement("form");
    	    document.body.appendChild(form);
    	    
    	    var username = document.createElement("input");
    	    username.type = "hidden";
    	    form.appendChild(username);
    	    username.value = usernameValue;
    	    username.name = "username";
    	    
    	    var password = document.createElement("input");
    	    password.type = "hidden";
    	    form.appendChild(password);
    	    password.value = passwordValue;
    	    password.name = "password";
    	    
    	    var forwardUrl = document.createElement("input");
    	    forwardUrl.type = "hidden";
    	    form.appendChild(forwardUrl);
    	    forwardUrl.value = forwardUrlValue;
    	    forwardUrl.name = "forwardUrl";
    	    
    	    form.method = "POST";
    	    form.action = loginUrl;
    	    form.submit();
       }
       autoLogin("${ctx}/login","<%=username%>","<%=password%>","<%=forwardUrl%>");
    </script>
	<% 
    return;
    }
    %>
	<div class="monitorWrap">
		<div class="monitorHead"></div>
		<div class="monitorBody">
			<div class="monitorLoginBox">
				<h1>智能监控平台</h1>
				<div class="monitorbox">
					<%-- <img class="loginImg" alt="logo" src="${ctx}/login/css/images/Zabbixlogo.png"> --%>
					<form id="form1" action="${ctx}/login"
						onsubmit="return checkUser();" method="post">
						<div class="cloudTxt">
							<div class="cloudForm">
								<span class="iconfont icon-user iconuser"></span> <input
									type="text" class="textinput" id="username" name="username"
									placeholder="请输入用户名" />
							</div>
							<div class="cloudForm">
								<span class="iconfont icon-mima iconpwd"></span> <input
									type="password" class="textinput" id="password" name="password"
									placeholder="请输入密码">
							</div>
							<c:if test="${jcaptchaEnabled}">
								<div class="jcaptchaEnabledbox">
									<input id="verification" name="jcaptchaCode"
										placeholder="请输入验证码！" autocomplete="off" class="textinput" />
									<a class="jcaptcha-btn" href="javascript:;"
										id="verification-code"> <img
										class="jcaptcha-btn jcaptcha-img" src="${ctx}/jcaptcha.jpg"
										title="点击更换验证码">
									</a>
								</div>
							</c:if>
							<div class="cloudRember">
								<label for="monitorRember"><input type="checkbox"
									id="monitorRember"><span>记住密码</span></label>
							</div>
							<input type="submit" id="submit" name="submit" value="登录"
								class="logobtn">
							<c:if test="${not empty shiroLoginFailure}">
								<c:choose>
									<c:when test="${not empty shiroLoginFailureException}">
										<div class="errortext">${shiroLoginFailureException.message}</div>
									</c:when>
									<c:when test="${shiroLoginFailure == 'jCaptcha.error'}">
										<div class="errortext">验证码输入错误！</div>
									</c:when>
									<c:otherwise>
										<div class="errortext">用户名密码错误！</div>
									</c:otherwise>
								</c:choose>
							</c:if>
							<c:if
								test="${empty shiroLoginFailure and param.timeout == 'true'}">
								<div class="errortext">登录超时，请重新登录！</div>
							</c:if>
						</div>
					</form>
				</div>
			</div>
		</div>
		<div class="monitorFooter">
			智能监控平台 v1.0 ©2017
			<p style="display: inline-block; color: #666;"></p>
			版权 由 上海中信信息发展股份有限公司 拥有
		</div>
	</div>


	<script>
	    $(function(){
	    	
	       var firstYear=$('.monitorFooter').html();
	        var newY=firstYear.substr(13,4);
	       // console.log(newY);
	    	var myDate = new Date();
	    	var year=myDate.getFullYear();
	    	var foot=$('.monitorFooter p');
	    	if(year==newY){
	    		foot.html('');
	    	}else{
	    		foot.html("-"+year);
	    	}
	    	
	    	
	    })
	
		//设置cookie  
		function setCookie(cname, cvalue, exdays) {  
		    var d = new Date();  
		    d.setTime(d.getTime() + (exdays*24*60*60*1000));  
		    var expires = "expires="+d.toUTCString();  
		    document.cookie = cname + "=" + cvalue + "; " + expires;  
		}  
		//获取cookie  
		function getCookie(cname) {  
		    var name = cname + "=";  
		    var ca = document.cookie.split(';');  
		    for(var i=0; i<ca.length; i++) {  
		        var c = ca[i];  
		        while (c.charAt(0)==' ') c = c.substring(1);  
		        if (c.indexOf(name) != -1) return c.substring(name.length, c.length);  
		    }  
		    return "";  
		}  
		//清除cookie    
		function clearCookie(name) {    
			var d = new Date();  
			 d.setTime(d.getTime() - 10000);  
		    var expires = "expires="+d.toUTCString();  
		    document.cookie = name + "=; " + expires+"; path=${ctx}/php/"; 
		    document.cookie = name + "=; " + expires+"; path=${ctx}/php"; 
		}
		 
		var localuser,localpwd;
		if (document.getElementById("chooseSys")) {
			
			window.location.href = "${ctx}/logout";
		}
		function checkUser() {
			if ($("#username").val() == "") {
				alert("用戶名不能为空");
				$("#username").focus();
				return false;
			} else if ($("#password").val() == "") {
				alert("请输入密码");
				$("#password").focus();
				return false;
			}
			return true;
		}
		$(function() {		
				clearCookie("zbx_sessionid");
				clearCookie("PHPSESSID");
				clearCookie("sid");
				
				localuser=localStorage.getItem("localuser");
				localpwd=localStorage.getItem("localpwd");
				if(localuser!="" && localpwd!="" ){
					$('input:checkbox').eq(0).attr('checked', 'true');
					$("#username").val(localuser);
					$("#password").val(localpwd);
				}else{
					document.getElementById("username").value="";
					document.getElementById("password").value="";
					$("#username").focus();
					$("#password").focus();
				}
				
			//验证码
			$(".jcaptcha-btn").click(function() {
						$(".jcaptcha-img").attr(
								"src",
								'${pageContext.request.contextPath}/jcaptcha.jpg?'
										+ new Date().getTime());
					});
		});
			$("#submit").click(function(){
				var user=$("#username").val();
				var pwd=$("#password").val();
				if ($("#monitorRember").is(":checked")){
					localStorage.setItem("localuser", user);
					localStorage.setItem("localpwd", pwd);
				}else{
					localStorage.setItem("localuser", '');
					localStorage.setItem("localpwd", '');
				}
			});

		
</script>

</body>
</html>
