<?php

require_once "process/xuly_dangnhap.php";
include_once "dataconfig/dataprovider.php";
$xx = new xuLyDangNhap();
if (isset($_POST['btnLogin'])) {
    //document.getElementById("result").innerHTML =''; // Variable To Store Error Message
    $xx->HandleError('');
    $id = $xx->CheckLoginInDB($_POST['txtUsername'], $_POST['txtPassword']);
    $sql = "select * from taikhoan where tk_TenDangNhap = '" . $_POST['txtUsername'] . "' and tk_MatKhau = '" . $_POST['txtPassword'] . "'";
    $result = DataProvider::GetOneRow($sql);
    if ($id > 0) {
        if (session_status() == PHP_SESSION_NONE) {
            session_start();
        }
        $_SESSION['UID'] = $id;
        $_SESSION["user_name"] = $_POST['txtUsername'];
        $_SESSION['DaDangNhap'] = 1;
        $_SESSION['LoaiNguoiDung'] = $result['tk_LoaiNguoiDung'];
        $xx->RedirectToURL("index.php");
    }
}
?>
  
<a id="thongbaoloi" class="show-top-notification-2 timer-notification" href="#"/>
<div class="top-notification-2 top-notification bg-red-dark timeout-notification">
    <h4>Thông báo</h4>
    <p>
        <?php 
echo $xx->GetErrorMessage();
?>
<?php

require_once "process/xuly_dangnhap.php";
$xx = new xuLyDangNhap();
if (!$xx->CheckLogin()) {
    $xx->RedirectToURL("dangnhap.php");
}