<?php

require_once "config.php";
?>
 
<?php 
if (isset($_POST["txtUsername"]) && isset($_POST["txtPassword"])) {
    $dataclass = new Dataclass();
    $result = $dataclass->check_Login($_POST["txtUsername"], sha1($_POST["txtPassword"]));
    $valid = false;
    $userID = 0;
    while ($row = $result->fetch()) {
        //Login ok
        $userID = $row["idtbladmin"];
        $_SESSION["UserId"] = $userID;
        $_SESSION["Username"] = $row["username"];
        $valid = true;
    }
    //
    if (isset($_POST["chkRemember"])) {
        setcookie("Username", $_POST["txtUsername"], EXPIRE);
        setcookie("Password", $_POST["txtPassword"], EXPIRE);
    }
    if (isset($_POST["chkKeepSignedIn"])) {
        setcookie("SignedIn", "true", EXPIRE);
        setcookie("UserId", $userID, EXPIRE);
        setcookie("Username", $_POST["txtUsername"], EXPIRE);
    }
}
if (isset($_SESSION["Username"])) {
    header("location:index.php");