<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>
<?php 
include('../include/session.php');
$job_no = $_GET['job_no'];



$sub_category=$_GET['sub_category'];

if ($sub_category=='Mitek') {
$cap_item_id = $_GET['store_item_select'];
		$auth_quantity = $_GET['quantity_text'];	
		$table_name = $_SESSION['db_prefix']."_captured_mitek";
		$table_name2 = $_SESSION['db_prefix']."_captured_mitek_edit_temp";
		
		$check_query = "SELECT cap_item_id FROM $table_name WHERE cap_item_id = '".$cap_item_id."' AND cap_job = '".$job_no."' UNION ALL SELECT cap_item_id FROM $table_name2 WHERE cap_item_id = '".$cap_item_id."' AND cap_job = '".$job_no."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
				
		if ($check_num==0) {	
		$mitek_query = "INSERT INTO $table_name2 (cap_job, cap_item_id, cap_quantity, auth_quantity, user ) VALUES ('".$job_no."', '".$cap_item_id."', '0', '".$auth_quantity."', '".$_SESSION['username']."'  ) ";
		execsql($mitek_query);
		
	   }	
		else {
			?>
            <script>
			alert('This item is already in the list and will not be added to the list.\r\n\r\nIf you require additional quantity, you should edit the quantity in the list. ');
			</script>
            <?php 
		}
}

if ($sub_category=='Sundries') {
$cap_item_id = $_GET['store_item_select'];
		$auth_quantity = $_GET['quantity_text'];	
		$table_name = $_SESSION['db_prefix']."_captured_sundries";
		$table_name2 = $_SESSION['db_prefix']."_captured_sundries_edit_temp";
		
		$check_query = "SELECT cap_item_id FROM $table_name WHERE cap_item_id = '".$cap_item_id."' AND cap_job = '".$job_no."' UNION ALL SELECT cap_item_id FROM $table_name WHERE cap_item_id = '".$cap_item_id."' AND cap_job = '".$job_no."'  ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		
		if ($check_num==0) {	
		$sundries_query = "INSERT INTO $table_name2 (cap_job, cap_item_id, cap_quantity, auth_quantity, user ) VALUES ('".$job_no."', '".$cap_item_id."', '0', '".$auth_quantity."', '".$_SESSION['username']."'  ) ";
		execsql($sundries_query);
		
	   }	
		else {
			?>
            <script>
			alert('This item is already in the list and will not be added to the list.\r\n\r\nIf you require additional quantity, you should edit the quantity in the list. ');
			</script>
            <?php 
		}
}
		
		
		   ?>
		   <script language="javascript" type="text/javascript">
          window.location="../production/authorisation_edit.php?job_no=<?php echo $job_no ?>&screen=0&edit=1&sub_category=<?php if ($sub_category=='Mitek') { echo '#mitek'; } else { echo '#sundries';}?>";
</script>

