<script language="JavaScript" src="login_include/go_to_url.js"  type="text/javascript"></script> 

<?php

include ("login_include/dbset.php");
$today = date("Y-m-d");
$username = $_POST['user_name_text'];
$_SESSION['username'] = $username;
$c = $_POST['c'];
$a = $_POST['a'];
$r = $_POST['r'];

@session_start();

$password = $_POST['password_text'];

$con = @mysql_connect("localhost",$dbu,$dbp);
if (!$con)
  {
  die('Could not connect to database again: ' . mysql_error());
  }
   
mysql_select_db($dbs, $con);

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


$login_query = "SELECT username FROM system_users WHERE username = '" . $username . "' AND  password = '".md5($password)."' ";
$login_result = mySQL_query($login_query);
$num = mysql_num_rows($login_result);
$user_name = mysql_result($login_result, 0, "username");
echo '<br>*****num: '.$num;
if ($num == 1) {
	
$access = "SELECT access_id FROM system_users WHERE username = '" .$username. "' ";
$accessResult = mySQL_query($access);
$_SESSION['access_id'] = mysql_result($accessResult, 0, "access_id");
$_SESSION['username'] = $_POST['user_name_text'];

date_default_timezone_set('Africa/Gaborone');
$entry_date = date("Y-m-d H:i:s", time());  

$active_query = "INSERT INTO active_users (username, log_in, last_active, logged_into) VALUES ('".$_SESSION['username']."', '".$entry_date."', '".$entry_date."', 'Radstone Gaborone' ) ";
execsql($active_query);

//Radstone direct entry
if ($c=='rad') {
$report_reference = $_POST['r']; 	
$table_name = "rds_tracking_log_in";
$action_query = "INSERT INTO $table_name (entry_date, user, action) VALUES ('".$entry_date."' ,'".$_SESSION['username']."','log in' )";
execsql($action_query);

//begin order_quantity alert
if ($a=='order') { $location = "Radstone/store/order.php?order_reference=".$r; }
//end order_quantity alert

//begin 3x late alert
if ($a=='late') { $location = "Radstone/hr_module/hr_main.php?date="; }
//end 3x late alert

//begin warning
if ($a=='warning') { $location = "Radstone/hr_module/warning_details.php?warning_id=".$r; }
//end warning alert

//begin product margin
if ($a=='prod_margin') { $location = "Radstone/production/production_plan_report.php?production_no=".$r; }
//end product_margin

//begin min stock
if ($a=='min_stock') { $location = "Radstone/store/store_items_list_complete.php?subCat=Complete"; }
//end min stock

//begin stock take
if ($a=='stock_take') { $location = "Radstone/store/select_stock_report.php"; }
//end stock

//begin fuel usage
if ($a=='fuel_consumption') { $location = "Radstone/store/vehicle_fuel_list.php?date=&vehicle_id=".$r; }
//end fuel usage

//begin wet approve
if ($a=='wet_request') { $location = "Radstone/quality/wet_tile_inspection_sheet.php?report_no=".$r."&approve="; }
//end wet approve

//begin dry approve
if ($a=='dryt_request') { $location = "Radstone/quality/dry_tile_inspection_sheet.php?report_no=".$r."&approve="; }
//end dry approve



}

//Radstone Namibia direct entry
if ($c=='nmb') {
$report_reference = $_POST['r']; 	
$table_name = "nmb_tracking_log_in";
$action_query = "INSERT INTO $table_name (entry_date, user, action) VALUES ('".$entry_date."' ,'".$_SESSION['username']."','log in' )";
execsql($action_query);

//begin order_quantity alert
if ($a=='order') { $location = "Radstone_Nmb/store/order.php?order_reference=".$r; }
//end order_quantity alert

//begin 3x late alert
if ($a=='late') { $location = "Radstone_Nmb/hr_module/hr_main.php?date="; }
//end 3x late alert

//begin warning
if ($a=='warning') { $location = "Radstone_Nmb/hr_module/warning_details.php?warning_id=".$r; }
//end warning alert

//begin min stock
if ($a=='min_stock') { $location = "Radstone_Nmb/store/store_items_list_complete.php?subCat=Complete"; }
//end min stock

//begin stock take
if ($a=='stock_take') { $location = "Radstone_Nmb/store/select_stock_report.php"; }
//end stock

//begin wet approve
if ($a=='wet_request') { $location = "Radstone_Nmb/quality/wet_tile_inspection_sheet.php?report_no=".$r."&approve="; }
//end stock take

}

//Tlhomeso direct entry
if ($c=='tlh') {
$report_reference = $_POST['r']; 	
$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);

//begin 3x late alert
if ($a=='late') { $location = "Tlhomeso/hr_module/hr_main.php?date="; }
//end 3x late alert

//begin warning
if ($a=='warning') { $location = "Tlhomeso/hr_module/warning_details.php?warning_id=".$r; }
//end warning alert

//begin stock take
if ($a=='stock_take') { $location = "Tlhomeso/store/select_stock_report.php"; }
//end stock


if ($a=='qr') { $location = "Tlhomeso/sales/quotations_list.php?date=0"; }




}

//Tlhomeso FTW direct entry
if ($c=='ftw') {
$report_reference = $_POST['r']; 	
$table_name = "ftw_tracking_log_in";
$action_query = "INSERT INTO $table_name (entry_date, user, action) VALUES ('".$entry_date."' ,'".$_SESSION['username']."','log in' )";
execsql($action_query);

//begin 3x late alert
if ($a=='late') { $location = "Tlhomeso_FTW/hr_module/hr_main.php?date="; }
//end 3x late alert

//begin warning
if ($a=='warning') { $location = "Tlhomeso_FTW/hr_module/warning_details.php?warning_id=".$r; }
//end warning alert

//begin stock take
if ($a=='stock_take') { $location = "Tlhomeso_FTW/store/select_stock_report.php"; }
//end stock
}



//header('Location: '.$location );

}
else {

$location = "http://costing.tocotex.com/main.php?e=1"; 

  ?>
  <script language="javascript" type="text/javascript">
        window.location="<?php $location ?>";
</script>
<?php
}

?>