
<?php
include("../include/session.php");

	
	$d = date("d");
	$m = date("m");
	$y = date("Y");
	
	$user_id = $_SESSION['username'];
	date_default_timezone_set('Africa/Gaborone');
	$entry_date = date("Y-m-d H:i:s", time());
	
	$warning_string= $_SESSION['warning_text'];			
	$warning_string = str_replace("'", "-", $warning_string);
	
	$notes_string= $_SESSION['additional_text'];			
	$notes_string = str_replace("'", "-", $notes_string);
	
	
	 
	$table_name = $_SESSION['db_prefix']."_warnings";
	$warning_query = "INSERT INTO $table_name (
											  warning,
											  offence,
											  emp_id,
											  warning_date,
											  exp_date,
											  issued_by,
											  warning_text,
											  additional_notes) 
	                    VALUES (
								'".$_SESSION['warning']."' ,
     							'".$_SESSION['offence']."' ,
	 							'".$_SESSION['emp_id']."' ,
	 							'".$_SESSION['warning_date']."' ,
								'".$_SESSION['exp_date']."' ,
								'".$_SESSION['issued_by']."' ,
	 							'".$warning_string."',
								'".$notes_string."' )";
								
	execsql($warning_query);
	
	$table_name = $_SESSION['db_prefix']."_warnings";
    $warning_query = "SELECT warning_id  FROM $table_name ORDER BY warning_id DESC LIMIT 1  ";
    $warning_result = mySQL_query($warning_query);
    $warning_id = mysql_result($warning_result, 0, "warning_id");
	
		
	$table_name = $_SESSION['db_prefix']."_tracking_hr";
   $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$_SESSION['username']."', '23', '".$_SESSION['emp_id']."' ,'".$_SESSION['issued_by']."','".$_SESSION['offence']."','".$warning_id."' )";
   $trackingResult = mySQL_query($trackingQuery);
 
 
if ($_SESSION['warning']=='Final warning') {   
include('../include/warning_alert.php');
}
	
	if (isset($_GET['new_button']) )
	   {
		 $action='warningWiz0.php';
	   }
		 
	if (isset($_GET['finish_button']) )
	  {
		 $action='warning_details.php?warning_id='.$warning_id ;
	  }
	
	 
     $_SESSION['warning']="";
	 $_SESSION['offence']="";
	 $_SESSION['emp_id']="";
     $_SESSION['employee_name'] ="";
	 $_SESSION['warning_date'] = date('Y-m-d');
	 $_SESSION['warning_text'] = "";
	 $_SESSION['additional_text']="";  

	 
?>

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



