<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

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

$reverse=$_GET['reverse'];
if ($reverse=='yes') {
	   $job_no=$_GET['job_no_text'];
	   

$table_name = $_SESSION['db_prefix']."_";
$_query = "INSERT INTO $table_name ( ) VALUES ( ) ";
execsql($_query);


$table_name = $_SESSION['db_prefix']."_captured_timber";
$table_name2 = $_SESSION['db_prefix']."_captured_timber_done";	   
$A_query = "INSERT INTO $table_name SELECT * FROM $table_name2 WHERE cap_job = '".$job_no."' ";
execsql($A_query);
echo '<br>*****A '.$A_query;

$table_name2 = $_SESSION['db_prefix']."_captured_timber_done";
$delete_query = "DELETE FROM $table_name2 WHERE cap_job = '".$job_no."' ";
execsql($delete_query);
echo '<br>*****'.$delete_query;



$table_name = $_SESSION['db_prefix']."_authorised_timber";
$table_name2 = $_SESSION['db_prefix']."_authorised_timber_done";
$B_query = "INSERT INTO $table_name SELECT * FROM $table_name2 WHERE job_no = '".$job_no."' ";
execsql($B_query);
echo '<br>*****B '.$B_query;

$table_name2 = $_SESSION['db_prefix']."_authorised_timber_done";
$delete_query = "DELETE FROM $table_name2 WHERE job_no = '".$job_no."' ";
execsql($delete_query);
echo '<br>*****'.$delete_query;


$table_name = $_SESSION['db_prefix']."_captured_mitek";
$table_name2 = $_SESSION['db_prefix']."_captured_mitek_done";	
$C_query = "INSERT INTO $table_name SELECT * FROM $table_name2 WHERE cap_job = '".$job_no."' ";
execsql($C_query);
echo '<br>*****C '.$C_query;

$table_name2 = $_SESSION['db_prefix']."_captured_mitek_done";
$delete_query = "DELETE FROM $table_name2 WHERE cap_job = '".$job_no."' ";
execsql($delete_query);
echo '<br>*****'.$delete_query;


$table_name = $_SESSION['db_prefix']."_captured_sundries";
$table_name2 = $_SESSION['db_prefix']."_captured_sundries_done";
$D_query = "INSERT INTO $table_name SELECT * FROM $table_name2 WHERE cap_job = '".$job_no."' ";
execsql($D_query);
echo '<br>*****'.$D_query;

$table_name2 = $_SESSION['db_prefix']."_captured_sundries_done";
$delete_query = "DELETE FROM $table_name WHERE cap_job = '".$job_no."' ";
execsql($delete_query);
echo '<br>*****D '.$delete_query;



$table_name2 = $_SESSION['db_prefix']."_captured_jobs";
$update_query = "UPDATE $table_name2 SET delivered = 'no' WHERE job_no = '".$job_no."' ";
execsql($update_query);

echo '<br><br>Reversal of job no '.$job_no.' completed';
}
?>

</head>

<body>
<?php
if ($reverse=='') { 
?>
<form action="reverse_completed_job.php" method="get">
<input name="job_no_text" type="text" />
<input name="reverse" type="hidden" value="yes" />
<input name="reverse_job" type="submit" value="reverse completed job" />
</form>
<?php
}
else {
echo '<br><br>Reversal of job no '.$job_no.' completed';
}
?>


</body>
</html>