<?php

if (!defined('IN_HK') || !IN_HK)
{
	exit;
}

if (HK_LOGGED_IN)
{
	exit;
}

if (isset($_POST['usr']) && isset($_POST['pwd']))
{
	$username = filter($_POST['usr']);
	$password = $core->uberHash($_POST['pwd']);

	if ($users->validateUser($username, $password))
	{		
		$hkId = $users->name2id($username);
		
		if ($users->GetUserVar($hkId, 'rank') > 4)
		{	
			session_destroy();
			session_start();
		
			$_SESSION['UBER_USER_N'] = $users->getUserVar($hkId, 'username');
			$_SESSION['UBER_USER_H'] = $password;
			$_SESSION['UBER_HK_USER_N'] = $_SESSION['UBER_USER_N'];
			$_SESSION['UBER_HK_USER_H'] = $_SESSION['UBER_USER_H'];
			
			header("Location: " . HK_WWW . "/index.php?_cmd=main");
			
			exit;
		}
		else
		{
			$_SESSION['HK_LOGIN_ERROR'] = "<p>Du hast keine Rechte um auf das Housekeeping zuzugreifen!</p>";
		}
	}		
	else
	{
		$_SESSION['HK_LOGIN_ERROR'] = '<p>Fehlerhafte Angaben</p>';
	}
}

?>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<title>Funlight › Anmelden</title>
<link rel="stylesheet" id="login-css" href="/manage/css/login.css?ver=20110610" type="text/css" media="all">
<link rel="stylesheet" id="colors-fresh-css" href="/manage/css/colors-fresh.css?ver=20110703" type="text/css" media="all">
<meta name="robots" content="noindex,nofollow">
</head>

<body class="login">
<div id="login"><h1><a href="http://wordpress.org/" style="background: url(<?php echo WWW;  ?>/images/ultimate_logo.png) no-repeat top center; width:381px;" title="UltimateCMS Housekeeping">Funlight</a></h1>
<?php if(isset($_SESSION['HK_LOGIN_ERROR'])) { ?>
<div id="login_error"><?php echo $_SESSION['HK_LOGIN_ERROR']; ?></div>
<?php } ?>
	<form method="post" id="loginform">
         <h3>Username
		<input type="text" name="usr" class="input" id="user_login" value="<?php if (LOGGED_IN) { echo USER_NAME; } ?>"><br />
		<br />
		Password
		<br />
		<input type="password" name="pwd" class="input" value=""><br />
		<br />
		<input type="submit" class="input" value="Login">
		<input type="button" onClick="document.location = '/';" class="input" value="Back to site"><br>
	</form>

<script type="text/javascript">
function wp_attempt_focus(){
setTimeout( function(){ try{
d = document.getElementById('user_login');
d.focus();
d.select();
} catch(e){}
}, 200);
}

wp_attempt_focus();
if(typeof wpOnload=='function')wpOnload();
</script>
</div>


<script type="text/javascript">
function wp_attempt_focus() {
setTimeout( function() {
try {
d = document.getElementById('user_login');
d.value = '';
d.focus();
} catch(e){}
}, 200 );
}
wp_attempt_focus();
if(typeof wpOnload=='function')wpOnload()
</script>
<script type="text/javascript" src="http://cdn.jquerytools.org/1.2.5/all/jquery.tools.min.js?ver=3.2.1"></script>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-16106315-4']);
  _gaq.push(['_setDomainName', '.funpic.de']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript';
ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' :
'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
  })();

</script>
</body>