<?php

if (!isset($_SESSION)) {
    session_start();
}
require_once('lib/dbclass.php');
$checking = findQuery('SELECT * FROM `settings`');



if ($checking) {
    $expiry  = date('Y-m-d', strtotime($checking[0]['enddate']));
    $today   = date('Y-m-d');
    $expired = 0;



    if ($expiry < $today) {
        session_destroy();
        echo "<script src='sweetalert.js'></script>";
        echo "<script>
        document.addEventListener('DOMContentLoaded', function() {
            swal({
                icon: 'error',
                title: 'Software Expired!',
                text: 'Software Expired.',
                Button: false,   // Hides the OK button
                timer: 3000                // Set timer in milliseconds (3000ms = 3 seconds)
            }).then(function() {
                window.location = 'login.php';  // Redirect after the timer expires
            });
        });
      </script>";
    } else {
        $username = $_POST['username'];
        $password = $_POST['password'];

        if ($username != 'admin' || $password != 'admin123$$') {
            session_destroy();
            echo "<script src='sweetalert.js'></script>";
            echo "<script>
        document.addEventListener('DOMContentLoaded', function() {
            swal({
                icon: 'error',
                title: 'Invalid Credentials!',
                text: 'Invalid username or password.',
                Button: false,   // Hides the OK button
                timer: 3000                // Set timer in milliseconds (3000ms = 3 seconds)
            }).then(function() {
                window.location = 'login.php';  // Redirect after the timer expires
            });
        });
      </script>";
        } else {
            $_SESSION['neetuser'] = 1;
            echo "<script > window.location = 'viewdata.php';</script>";
        }
    }
}
