<?php
session_start();

date_default_timezone_set('Asia/Colombo');

define("HOST", $_SERVER['HTTP_HOST']);
define("SUBFOLDER", "");
define("FILE_ROOT", $_SERVER['DOCUMENT_ROOT'] . "/" . SUBFOLDER);
define("HOME", HOST . "/" . SUBFOLDER . "/");

// add files from helpers folder
foreach (glob(FILE_ROOT . "src/helpers/*.php") as $file) {
    require $file;
}

// PHP autoloader
spl_autoload_register(function ($className) {
    include FILE_ROOT . 'src/models/' . $className . '.php';
});

$dbcredentials = [
    "localhost" => [
        "host" => "localhost",
        "username" => "root",
        "password" => "",
        "database" => "dias"
    ],
    "csweb" => [
        "host" => "localhost",
        "username" => "virusinc_cswebusr9",
        "password" => "QE8tsej699xAt5P",
        "database" => "virusinc_csweb"
    ]
];

dbconnection::connect($dbcredentials["localhost"]);

// update current user lastseen value 
if (auth::user()) {
    users::update(auth::user_id(), ["lastseen" => timestamp()]);
} else {
    router::redirect("login");
}
