<?php



if (!isset($_SESSION)) {
    session_start();
}

require_once('lib/dbclass.php');




$email = $_POST['email'];
$pwd   = $_POST['password'];
$pwd   = encrypt($pwd);





$user = findQuery("select * from tbl_user where username='$email' and password='$pwd' and status=0 ");

$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) {
        // $message     = 'Software Expired';
        // $longMessage = 'Software Expired';
        // Encode the values for inclusion in the URL

        // $encodedMessage = urlencode($message);


        // Construct the URL with query parameters
        //$url = "../login.php?message={$encodedMessage}";

        // Redirect to the new URL
        //echo "<script>window.location.href='{$url}';</script>";
    }
}



if ($user[0]['id']) {
    $_SESSION['userid'] = $user[0]['id'];
    //print_r($user[0]['name']);
    header('Location:ChallengeReport/challengereport.php');
    exit;
} else {
    $message     = 'Invalid username or password';
    $longMessage = 'Invalid username';


    // Encode the values for inclusion in the URL

    $encodedMessage = urlencode($message);


    // Construct the URL with query parameters
    $url = "../login.php?message={$encodedMessage}";

    // Redirect to the new URL
    echo "<script>window.location.href='{$url}';</script>";
}
