<?php
if (!defined("root")) {
	define("root", $_SERVER['DOCUMENT_ROOT']);
}
require(root."/___simple_config.php");
session_start();
$pageName = "login";
$pageTitle = "Login Dashboard";
$coutSpecs = array('nl'=>"n");
require(root."/".adminFolder."/_common.php");
require(root."/".adminFolder."/_lib/db.php");
require(root."/".adminFolder."/_lib/main.php");
if (isset($_SESSION["user"])) {
	header("Location: /".adminFolder."/");
	exit;
}
$sending = cekpost(cleanQuery($_POST["sending"]), "");
$sm = "/".adminFolder."/";
if (isset($sending) && $sending!="") {
	$inputUsername = cekpost(cleanQuery($_POST["inputUsername"]), "");
	$inputPassword = cekpost(cleanQuery($_POST["inputPassword"]), "");
	$err = "";
	if ($inputUsername=="" || $inputPassword=="") {
		if ($inputUsername=="") { $err .= ($err!=""?'<br />':'')."Username must be filled!"; }
		if ($inputPassword=="") { $err .= ($err!=""?'<br />':'')."Password must be filled!"; }
	} else {
		$saltPass = saltEncoding($inputPassword);
		$rsc=array();$qc="SELECT * FROM _users WHERE username='$inputUsername' AND pass='$saltPass'";
		callRS($rsc, $qc);
		if (count($rsc)<=0) {
			$err .= ($err!=""?'<br />':'')."Username or Password did not match any within the database! Please check again the typing or contact your administrator";
		} else {
			session_destroy();
			session_start();
			if (isset($_SESSION["user"])) { unset($_SESSION["user"]); }
			$_SESSION["user"] = array(
				"kduser" => $rsc[0]["kduser"],
				"username" => $rsc[0]["username"],
				"inisial" => $rsc[0]["inisial"],
				"session_id" => session_id(),
				"login_time" => time(),
				"last_click" => time()
			);
			#print_r($_SESSION["user"]);
			echo '<script>window.location="'.$sm.'"</script>';
		}
	}
}
require(root."/".adminFolder."/_tpl/tag_html_a.php");
cout('<link href="'.absDom.'/'.adminFolder.'/css/css_login.css" rel="stylesheet">');
cout('
<style type="text/css">
	
</style>
');
require(root."/".adminFolder."/_tpl/openbody.php");
require(root."/".adminFolder."/_tpl/header.php");

#cout('<div class="container theme-showcase" role="main">');
	#cout('<!-- Main jumbotron for a primary marketing message or call to action -->');
	#cout('<div class="jumbotron">');
	#	cout('<h1>Theme example</h1>');
	#	cout('<p>This is a template showcasing the optional theme stylesheet included in Bootstrap. Use it as a starting point to create something more unique by building on or modifying it.</p>');
	#cout('</div>');
	#cout('<div class="page-header">');
	#	cout('<h1>'.$pageTitle.'</h1>');
	#cout('</div>');
	#cout('<div>');
	#	cout('<ul class="nav nav-pills" role="tablist">');
	#		cout('<li role="presentation" class="active"><a href="#">Main</a></li>');
	#		cout('<li role="presentation"><a href="#">Add</a></li>');
	#	cout('</ul>');
	#cout('</div>');
	cout('<form class="form-signin" method="post" action="">');
		cout('<input type="hidden" name="sending" value="1" />');
		cout('<h2 class="form-signin-heading">Please log in</h2>');
		cout('<label for="inputUsername" class="sr-only">Email address</label>');
		cout('<input type="text" id="inputUsername" name="inputUsername" class="form-control" placeholder="Username" required autofocus>');
		cout('<label for="inputPassword" class="sr-only">Password</label>');
		cout('<input type="password" id="inputPassword" name="inputPassword" class="form-control" placeholder="Password" required>');
		#cout('<div class="checkbox">');
		#	cout('<label>');
		#		cout('<input type="checkbox" value="remember-me"> Remember me');
		#	cout('</label>');
		#cout('</div>');
		cout('<button class="btn btn-lg btn-primary btn-block" type="submit">Log in</button>');
	cout('</form>');
#cout('</div>');
/*
cout('<div class="container">');
	cout('<div style="margin:10px;border-radius:5px;">');
		cout('<form method="post" action="" class="loginForm">');
			cout('<input type="hidden" name="sending" value="1" />');
			cout('<fieldset>');
				cout('<legend>Please login with your username and password</legend>');
				cout('<table class="tdata" style="width:90%;margin:0 auto;">');
					cout('<tr class="judul"><td><label for="username">Username</label></td></tr>');
					cout('<tr class="rodd"><td style="text-align:center;"><input type="text" name="username" id="username" size="30" /></td></tr>');
					cout('<tr class="judul"><td><label for="depass">Password</label></td></tr>');
					cout('<tr class="rodd"><td style="text-align:center;"><input type="password" name="depass" id="depass" /></td></tr>');
					cout('<tr><td style="text-align:center;"><input class="formButton" type="submit" value="Login" /></td></tr>');
					if ($err!="") {
						cout('<tr><td class="err">'.$err.'</td></tr>');
					}
				cout('</table>');
			cout('</fieldset>');
		cout('</form>');
	cout('</div>');
cout('</div>');
*/
require(root."/".adminFolder."/_tpl/footer.php");
require(root."/".adminFolder."/_tpl/tag_html_b.php");
?>