<?php
include('../include/session.php');
date_default_timezone_set('Africa/Gaborone');
$entryDate = date("Y-m-d H:i:s"); 


$job_card_no = $_GET['job_card_no_text'];
$start_date = $_GET['start_date'];
$end_date = $_GET['end_date'];

$table_name = $_SESSION['db_prefix']."_compiled_jobs";
$job_date_query = "SELECT del_date, end_date FROM $table_name WHERE job_card_no = '".$job_card_no."' ";
$job_date_result = mySQL_query($job_date_query);
$saved_start_date = mysql_result($job_date_result, 0, "del_date");
$saved_end_date = mysql_result($job_date_result, 0, "end_date");


$table_name = $_SESSION['db_prefix']."_mworks_jobs";
$update_query = "UPDATE $table_name SET del_date = '".$start_date."', end_date = '".$end_date."' WHERE job_card_no = '".$job_card_no."' ";
execsql($update_query);



$table_name = $_SESSION['db_prefix']."_tracking_production";

if ($saved_start_date!=$start_date) {
	    $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '96', '".$job_card_no."' ,'".$saved_start_date."','".$start_date."','Start date' )";
		//echo '<br>id_number'.$trackingQuery;
			$trackingResult = mySQL_query($trackingQuery);
}

if ($saved_end_date!=$end_date) {
	    $trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entryDate."' ,'".$_SESSION['username']."', '96', '".$job_card_no."' ,'".$saved_end_date."','".$end_date."','End date' )";
		//echo '<br>id_number'.$trackingQuery;
			$trackingResult = mySQL_query($trackingQuery);
}


?>

       <script>
	          window.location="production_planner.php"
	   </script>
       
