<?php 
    # $Id: benchmarkFile_DOWNLOAD.php,v 1.2 2007/01/08 12:51:13 jarda Exp $

    /* Checks correctness of the login information and logs the user if it is correct
    */
    
    require_once('simplePage.inc.php');	   # load database library

    if ($_POST["OK"])
    {

        $db = connect();

        $query = "SELECT * from bDBUser " .
                 "WHERE login = '$_POST[login]' " .
                 "AND password = '$_POST[password]'";

        $recordSet = $db->Execute($query);

        $row = $recordSet->FetchRow();

        if ($row) {
            session_name('benchmark');
            session_start();
            session_regenerate_id();

            # remove old records from session user table {{{
            $date = date("Y-m-d H:i:s", strtotime('-2 days'));

            $db->Execute("DELETE FROM sessionUser WHERE createdTime < '$date'");
            # }}}

            # add a new a new record to user session table {{{
            $date = date("Y-m-d H:i:s");

            $sessionId = session_id();

            $query = "INSERT INTO sessionUser (sessionId, userId, createdTime) " .
                     "VALUES ('$sessionId', $row[id], '$date')";

            $db->Execute($query);
            # }}}
            
        }
    }

    header("Location: index.php"); /* Redirect browser */ 

    # vim:enc=iso8859-2:fenc=iso8859-2:
?>
