<?php
	//Connects to your Database
	include "../db_connection/db_connection.php";
	include "../config/config.php";		
	$page_id	=	base64_decode(base64_decode(base64_decode($_GET['page_id']))); //THIS IS PAGE ID  
	                  
	//cat_name,d_no,hdes_name,imgInp
	if($page_id==1) //this is for basic details add page	
	{ 	
		//$hdes_name	=	base64_decode(base64_decode(base64_decode(base64_decode($_POST['hdes_name']))));	
		$lob		=	$_POST['lob']; 
		$lob		= 	str_replace("/", "-", $lob);
		$question1	=	$_POST['question1']; 
		
		$i=1;
		//$lop_val=$_POST['jsval'];
		foreach($_POST['category'] as $cat_loop_id)
		{
			$design_det_id=explode(",",$cat_loop_id);
			$cat_id=$design_det_id[0];
			$cat_loop_id=$design_det_id[1];
			$no_pice=$design_det_id[2];
			$cad_tm = $_POST['cad_tm'][$cat_loop_id];
						
			if($question1=="rtv")
			{
				//THI IS FOR INSERTING THE DESIGN TO DIRECT RTV LOADING 
				$INSRT_d	= "INSERT INTO cam_finishing(`design_det_id` , `finishing_date`,`to_rtv_load`, `post_dt`) VALUES('$cat_id','$lob','yes','$cur_time')";		
				$QURY_d		= mysqli_query($connect,$INSRT_d);
				
				$UPDATE_cc = "UPDATE cad_finishing_des SET no_of_pice='$no_pice', to_rtv_load = 'yes',`cad_fin_status` = 'yes',update_dt = '$cur_time' WHERE design_det_id = '$cat_id'";
				$QRY_cc    = mysqli_query($connect,$UPDATE_cc); 
				
			}			
			else if($question1=="silver")
			{
				//THI IS FOR INSERTING THE DESIGN TO DIRECT SILVER LOADING 
				$INSRT_d	= "INSERT INTO silver_pending(`design_det_id` , `finishing_date`, `post_dt`) VALUES('$cat_id','$lob','$cur_time')";		
				$QURY_d		= mysqli_query($connect,$INSRT_d);
				
				$UPDATE_cc = "UPDATE cad_finishing_des SET no_of_pice='$no_pice', to_silver_load = 'yes',`cad_fin_status` = 'yes',update_dt = '$cur_time' WHERE design_det_id = '$cat_id'";
				$QRY_cc    = mysqli_query($connect,$UPDATE_cc); 
				
			}
			else if($question1=="cam")
			{
				$UPDATE_cc = "UPDATE cad_finishing_des SET no_of_pice='$no_pice', `cad_fin_status` = 'yes',update_dt = '$cur_time' WHERE design_det_id = '$cat_id'";
				$QRY_cc    = mysqli_query($connect,$UPDATE_cc); 
				//echo $UPDATE_cc."<br>";
			}			
			$UPDATE_des = "UPDATE design_det SET `no_of_pieces` = '$no_pice' WHERE design_det_id = '$cat_id'";
			$QRY_des    = mysqli_query($connect,$UPDATE_des);
			$i++;		
		}
		
?>
		<script type="text/javascript">
            //alert("Data inserted successfully");
            //history.back();
            window.location='../cad_finishing_list.php';
        </script>
<?php
}
?>
	
