<?php
ob_start();
session_start();
include "./koneksi.php";
if (isset($_POST['login'])) {
    $password = $_POST['password'];
    $username = $_POST['username'];
    $sql = mysqli_query($openinmut, "SELECT * FROM tb_perawat WHERE `username` ='$username' AND `password`='$password'");
    if (mysqli_num_rows($sql) == 1) { //jika berhasil akan bernilai 1
        echo json_encode(array("statusCode" => 200));
        $qry = mysqli_fetch_array($sql);
        $_SESSION['username']     = $qry['username'];
        $_SESSION['nama_perawat'] = $qry['nama_perawat'];
        $_SESSION['auth']         = $qry['auth'];
        $_SESSION['id_perawat']   = $qry['id_perawat'];
        $_SESSION['last_login']     = $qry['last_login'];

        if ($qry['auth'] == "user") {
            header('location: ' . $uri .  '/ena_pro/dist/index.html');
        }
    } else {
        echo json_encode(array("statusCode" => 201));
        unset($_SESSION['username']);
        unset($_SESSION['auth']);
        header("location:/ena_pro/login.html");
    }
}
if (empty($_SESSION['auth'])) {
    echo "Logout";
} else {
    echo "<p style='font-size:12px;'>" . $_SESSION['nama_perawat'] . "</p>";
    echo "<p style='font-size:12px;'>Last session:<br>" . date('d-m-Y H:i:s', strtotime($_SESSION['last_login'])) . "</p>";
}
