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

	
	$user_id = $_SESSION['username'];
	date_default_timezone_set('Africa/Gaborone');
	$entry_date = date("Y-m-d H:i:s", time()); 
	$rec_date = date("Y-m-d");
	$year = date('Y');
		
	 
	$table_name = $_SESSION['db_prefix']."_machinery";
	$machine_query = "INSERT INTO $table_name (`in_service`,`machine_name`,  `make`, `model`, `department`, `serial_no`, `clock`, `service_interval`, `notes`) VALUES (trim('". $_SESSION['in_service']."'),  trim('". $_SESSION['machine_name']."'), trim('".$_SESSION['make']."'),  trim('".$_SESSION['model']."'), trim('".$_SESSION['department']."'), trim('".$_SESSION['serial_no']."'), trim('".$_SESSION['clock']."'), trim('".$_SESSION['service_interval']."'), trim('".$_SESSION['notes']."'))";
	execsql($machine_query);
	
$table_name = $_SESSION['db_prefix']."_machinery";
$id_query = "SELECT machine_id FROM $table_name ORDER BY machine_id DESC LIMIT 1 ";
$id_result = mySQL_query($id_query);
$machine_id = mysql_result($id_result, 0, "machine_id");	

		
	$table_name = $_SESSION['db_prefix']."_tracking_store";
   $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$_SESSION['username']."', '38', '' ,'". $_SESSION['machine_name']."','".$_SESSION['make']."','".$_SESSION['model']."' )";
   $trackingResult = mySQL_query($trackingQuery);


if (isset($_GET['new_button']) )
	   {
		$action='machineryWiz0.php';
	   }
		 
	if (isset($_GET['finish_button']) )
	  {
		$action='machine_details.php?machine_id='.$machine_id ;
	  }	
	 
     $today = date("Y-m-d");
	 $_SESSION['machine_name'] = "";
	 $_SESSION['vehicle_no'] = "";
     $_SESSION['make'] = "";
	 $_SESSION['model'] = "";
	 $_SESSION['fuel'] = "";
	 $_SESSION['department'] = "";
	 
	 
	 $_SESSION['service_interval'] = "";
	 $_SESSION['clock_reading'] = "";
	 $_SESSION['serial_no'] = "";
	 $_SESSION['engine_no'] = "";
	 $_SESSION['machine_name'] = "";
	 $_SESSION['license'] = "";
	 $_SESSION['ba_license'] = "";
	 
	 $_SESSION['notes'] ="";	
	
	 
?>

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



