<%@include file="include/lib.jsp"%>
<%
response.setDateHeader("Expires", -1);
response.setHeader("Pragma","no-cache");
response.setHeader("Cache-Control","no-cache");
%>
<%
// Create data access object.
AdminLoginDao dao = new AdminLoginDao(request);

// Action.
String actionFlag = paramString("actionFlag");
if(actionFlag.equals("logout")){
	dao.logout();
}
if(actionFlag.equals("login")){
	if(dao.login(paramString("uname"), paramString("passwd"))){
		// Start page for admin.
		response.sendRedirect("dashboard.jsp");
		return;
	}
	else{
		jsAlert("Login failed!");
	}
}

// Report Manager.
String reportPw = paramString("rpw");
if(isNotEmpty(reportPw)){
	AdminDao adminDao = new AdminDao();
	AdminData adminData = adminDao.selectOne();

	if(isNotEmpty(adminData.reportPw) && reportPw.equals(adminData.reportPw)){
		adminLoginDao.createReportSession();
		response.sendRedirect("report,daily.jsp");
		return;
	}
}
%>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Expires" content="-1"> 
<meta http-equiv="Pragma" content="no-cache"> 
<meta http-equiv="Cache-Control" content="no-cache"> 
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<title><%= getNxName()%> v<%= getNxVersion()%></title>
<style type="text/css">
/* ######################################################################################### */
table{
	font-family: arial;
	font-size: 10pt;
	color: #000000;
}

input{
	font-family: arial;
	font-size: 10pt;
	background: #FFFFFF;
	color: #000000;
	border: #919191 1px solid;
}

input:hover{
	border: #3C7FB1 1px solid;
}

input:focus{
	border: #3C7FB1 1px solid;
}

input[type=button]{
	background: #333333;
	color: #ECECEC;
	font-size: 8pt;
	border: 0px;
	padding: 3;
	padding-left: 10;
	padding-right: 10;
}

input[type=button]:hover{
	background: #262626;
	color: #FFFFFF;
}

div.login-page {
	max-width: 320px;
	margin: 200px auto;
}


span.info{
	background-color: #4CAF50;
	color: #FFFFFF;
	padding: 2px;
}

span.alert{
	background-color: #D73811;
	color: #FFFFFF;
	padding: 2px;
}

span.warning{
	background-color: #FF7518;
	color: #FFFFFF;
	padding: 2px;
}
</style>
</head>
<body style="background: #111111">

<div class="login-page">
<form method="post" action="<%= getPageName()%>">
<input type="hidden" name="actionFlag" value="login">

<table cellspacing="0" cellpadding="4" bgcolor="#FFFFFF" width="320">

	<tr height="25">
		<td colspan="2" style="background-color: #1B9BFF; color: #FFFFFF; font-size: 9pt;">ADMIN LOGIN</td>
	</tr>

	<tr height="5">
		<td colspan="2"></td>
	</tr>

	<tr>
		<td width="100">&nbsp;Username</td>
		<td><input type="text" name="uname"></td>
	</tr>

	<tr>
		<td>&nbsp;Password</td>
		<td><input type="password" name="passwd" onkeypress="javascript:if(event.keyCode == 13){this.form.submit(); return;}"></td>
	</tr>

<%if(dao.isFirstLogin()){%>
	<tr>
		<td colspan="2">
			&nbsp;&nbsp;<span class="warning">Initial username and password : admin/admin</span>
		</td>
	</tr>
<%}%>

	<tr>
		<td></td>
		<td>
			<input type="button" value="SUBMIT" onclick="javascript:this.form.submit();">
			<input type="button" value="RESET" onclick="javascript:this.form.reset();">
		</td>
	</tr>

	<tr height="5">
		<td colspan="2"></td>
	</tr>

</div>

</body>
</html>
