include './resources/init.php';
if (isset($_POST['type'])) {
    if ($_POST['type'] == "logout") {
        fAuthorization::destroyUserInfo();
    } else {
        if ($_POST['type'] == "login") {
            try {
                $user = new User($_POST['username']);
            } catch (fException $e) {
                fURL::redirect(URL_ROOT . "authentication.php");
            }
            if (sha1($_POST['password']) == $user->getPassword()) {
                fAuthorization::setUserAuthLevel($user->getLevel());
                fAuthorization::setUserToken($_POST['username']);
                fURL::redirect(fAuthorization::getRequestedUrl(true, URL_ROOT . "inventory.php"));
            } else {
                fURL::redirect(URL_ROOT . "authentication.php");
            }
        }
    }
} else {
    if (isset($_GET['type']) == "logout") {
        fAuthorization::destroyUserInfo();
    }
}
$tmpl->place('header');
$tmpl->place('menu');
?>
<div class="span-24 last">
	<span id="statusbar"></span>