<?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	
{ 		
		$lob		=	$_POST['lob'];
		$lob		= 	str_replace("/", "-", $lob);
		$hdes_name	=	base64_decode(base64_decode(base64_decode(base64_decode($_POST['hdes_name']))));
		$st_tim		=	$_POST['st_tim'];
		
		$kdm_wgt = $_POST['kdm_wgt'];
		$lop = 1;
		
		$INST_KDM = "INSERT INTO sol_loading_kdm(emp_det_id, loading_date,loading_time, kdm_loading_weight, post_dt)VALUES('$hdes_name','$lob','$st_tim','$kdm_wgt','$cur_time')";
		$QURY_KDM = mysqli_query($connect,$INST_KDM);
		
		
		$SLCT_KDM = "SELECT MAX(sol_loading_kdm_id) AS max_sol_id FROM sol_loading_kdm";
		$EXEC_KDM = mysqli_query($connect,$SLCT_KDM);
		$FTCH_KDM = mysqli_fetch_object($EXEC_KDM);
		
		foreach($_POST['category'] as $cat_id)
		{					
			$sol_wt = $_POST['sol_wt'][$cat_id];
			
			$INSRT_d	= "INSERT INTO soldering_loading(`sol_loading_kdm_id`, `emp_det_id`,`design_det_id`, `loading_date`, `loading_time`,`solder_weight`,`post_dt`) VALUES('$FTCH_KDM->max_sol_id', '$hdes_name', '$cat_id', '$lob', '$st_tim', '$sol_wt', '$cur_time')";		
			//echo $INSRT_d;
			$QURY_d		= mysqli_query($connect,$INSRT_d);
			
			//THI IS FOR UPDATING THE DESIGN STATUS
			$UPDATE = "UPDATE design_det SET design_status = 'In Soldering Loading',update_dt = '$cur_time' WHERE design_det_id = '$cat_id'";
			$QRY    = mysqli_query($connect,$UPDATE); 
			
			$SLCT_CAS  =  "SELECT * FROM casting_finishing WHERE design_det_id = '$cat_id'";
			$QURY_CAS  =  mysqli_query($connect,$SLCT_CAS);
			if(mysqli_num_rows($QURY_CAS)>0)
			{
				//THI IS FOR UPDATING THE CAD LOADING STATUS
				$UPDATE_cd = "UPDATE casting_finishing SET cas_fin_status = 'yes',update_dt = '$cur_time' WHERE design_det_id = '$cat_id'";
				$QRY_cd    = mysqli_query($connect,$UPDATE_cd); 		
			}
			else
			{
				//THI IS FOR UPDATING THE SILVER FINISH STATUS
				$UPDATE_cd = "UPDATE silver_finishing SET to_solder_load = 'yes',update_dt = '$cur_time' WHERE design_det_id = '$cat_id'";
				$QRY_cd    = mysqli_query($connect,$UPDATE_cd); 	
			}
			
			$lop++;	
		}
		
?>
		<script type="text/javascript">
            //alert("Data inserted successfully");
            //history.back();
            window.location='../sol_loading_list.php';
        </script>
<?php
}
?>
	
