<?php

//include ("dbset.php");

$username = $_GET['username'];
//$password = $_POST['password_text'];

// Include database connection settings
//include("db_connect.php");

$con = mysql_connect("localhost","web15u2","sHK3od6a");
if (!$con)
  {
  die('Could not connect to database: ' . mysql_error());
  }
   
mysql_select_db("web15db2", $con);

function execsql($qry){
	$result = mysql_query($qry);
	return $result;
}



$login_query = "SELECT username FROM users WHERE username = '" . $username . "' ";
echo $login_query;
$login_result = mySQL_query($login_query);

$num = mysql_num_rows($login_result);
//echo "num:".$num;
// Check username and password match
if ($num == 1) {
// Inialize session
session_start();	
// Set username session variable

$access = "SELECT userlevel FROM users WHERE (username = '" .$username. "') ";
//echo $access;
$accessResult = mySQL_query($access);
$_SESSION['userlevel'] = mysql_result($accessResult, 0, "userlevel");

//$_SESSION['username'] = $_GET['user_name_text'];
//echo "home:".$home_page;
date_default_timezone_set('Africa/Khartoum');
$entry_date = date("Y-m-d H:i:s",time()-3600); 

$active_query = "INSERT INTO active_users (username) VALUES ('".$username."' ) ";
//echo $active_query;
execsql($active_query);

//$table_name = "tlh_tracking_log_in";
//$action_query = "INSERT INTO $table_name (entry_date, user, action) VALUES ('".$entry_date."' ,'".$_SESSION['username']."','log in' )";
//execsql($action_query);

//if ($home_page=="hr") {$location = "hr_module/hr_main.php?date="; }
//if ($home_page=="production") {$location = "production/production_main.php?period=day"; }
//if ($home_page=="stores") {$location = "store/store_main.php?period=day"; }
//if ($home_page=="sales") {$location = "sales/sales_main.php?period=day"; }
//if ($home_page=="admin") {$location = "admin_module/user_list.php";  }
//if ($home_page=="") {$location = "../mainmenu.php"; }
//$_SESSION['location'] = $location;

// Jump to secured page
  header('Location: ../HR/employeeMenu.php?type=week' );
}
else {
//Jump to login page
    header('Location: ../mainmenu.php');
}

?>