<?php
	include "koneksi.php";
	$id = mysqli_real_escape_string($conn, $_GET["id"]);
    $q = "SELECT * FROM data_karyawan WHERE id='$id'";

	$no_mhb_barang_job=mysqli_real_escape_string($conn,$_GET["id"]);
	
	$form=$_POST["form"];
	
	$ukuranSurfaceID=$_POST["ukuranSurfaceID"];
	$sizeSurviceID=$_POST["sizeSurviceID"];
	$upperSurviceID=$_POST["upperSurviceID"];
	$lowerSurviceID=$_POST["lowerSurviceID"];
	$x1SurviceID=$_POST["x1SurviceID"];
	$y1SurviceID=$_POST["y1SurviceID"];
	$z1SurviceID=$_POST["z1SurviceID"];
	
	$x2SurviceID=$_POST["x2SurviceID"];
	$y2SurviceID=$_POST["y2SurviceID"];
	$z2SurviceID=$_POST["z2SurviceID"];
	
	$x3SurviceID=$_POST["x3SurviceID"];
	$y3SurviceID=$_POST["y3SurviceID"];
	$z3SurviceID=$_POST["z3SurviceID"];
	
	$x4SurviceID=$_POST["x4SurviceID"];
	$y4SurviceID=$_POST["y4SurviceID"];
	$z4SurviceID=$_POST["z4SurviceID"];
	
	$x5SurviceID=$_POST["x5SurviceID"];
	$y5SurviceID=$_POST["y5SurviceID"];
	$z5SurviceID=$_POST["z5SurviceID"];
	
	$x6SurviceID=$_POST["x6SurviceID"];
	$y6SurviceID=$_POST["y6SurviceID"];
	$z6SurviceID=$_POST["z6SurviceID"];
	
	$x7SurviceID=$_POST["x7SurviceID"];
	$y7SurviceID=$_POST["y7SurviceID"];
	$z7SurviceID=$_POST["z7SurviceID"];
	
	$x8SurviceID=$_POST["x8SurviceID"];
	$y8SurviceID=$_POST["y8SurviceID"];
	$z8SurviceID=$_POST["z8SurviceID"];
	
	//survace id condition
	$conditionSurviceID=$_POST["conditionSurviceID"];
	
	//thickness min 50
	$aChromeCoatingSurviceID=$_POST["aChromeCoatingSurviceID"];
	$bChromeCoatingSurviceID=$_POST["bChromeCoatingSurviceID"];
	$cChromeCoatingSurviceID=$_POST["cChromeCoatingSurviceID"];
	$dChromeCoatingSurviceID=$_POST["dChromeCoatingSurviceID"];
	$eChromeCoatingSurviceID=$_POST["eChromeCoatingSurviceID"];
	
	//roughness (ra) in
	$roughnessSurfaceID1=$_POST["roughnessSurfaceID1"];
	$roughnessSurfaceID2=$_POST["roughnessSurfaceID2"];
	$roughnessSurfaceID3=$_POST["roughnessSurfaceID3"];
	
	//welding joint
	$roughnessSurfaceID1=$_POST["roughnessSurfaceID1"];
	
	//spec inside run out tube
	$aSpecInsideRunSurfaceID=$_POST["aSpecInsideRunSurfaceID"];
	$bSpecInsideRunSurfaceID=$_POST["bSpecInsideRunSurfaceID"];
	
	//spec inside concentricity between tube and head end
	$cSpecInsideConcentricitySurfaceID=$_POST["cSpecInsideConcentricitySurfaceID"];
	$dSpecInsideConcentricitySurfaceID=$_POST["dSpecInsideConcentricitySurfaceID"];
	$eSpecInsideConcentricitySurfaceID=$_POST["eSpecInsideConcentricitySurfaceID"];
	
	//long hone
	$lengthHoneSurfaceID=$_POST["lengthHoneSurfaceID"];
	//hardness mat'l 
	$roughnessSurfaceID1=$_POST["roughnessSurfaceID1"];
	$lengthHoneHardnessMatSurfaceID1=$_POST["lengthHoneHardnessMatSurfaceID1"];
	$lengthHoneHardnessMatSurfaceID2=$_POST["lengthHoneHardnessMatSurfaceID2"];
	$lengthHoneHardnessMatSurfaceID3=$_POST["lengthHoneHardnessMatSurfaceID3"];
	
	//total length
	$totalLengthSurfaceID=$_POST["totalLengthSurfaceID"];
	//hardness mat'l 
	$totalLengthHardnessSurvaceID1=$_POST["totalLengthHardnessSurvaceID1"];
	$totalLengthHardnessSurvaceID2=$_POST["totalLengthHardnessSurvaceID2"];
	$totalLengthHardnessSurvaceID3=$_POST["totalLengthHardnessSurvaceID3"];	
	
	
	//diameterOdTube
	$diameterOdTube=$_POST["diameterOdTube"];
	
	// recomendation repar
	$recommendationRepairSurfaceID=$_POST["recommendationRepairSurfaceID"];
	
	//surface id head end (h8/oem)
	$xSurviceIDHeadEnd1=$_POST["xSurviceIDHeadEnd1"];
	$ySurviceIDHeadEnd1=$_POST["ySurviceIDHeadEnd1"];
	$zSurviceIDHeadEnd1=$_POST["zSurviceIDHeadEnd1"];
	$xSurviceIDHeadEnd2=$_POST["xSurviceIDHeadEnd2"];
	$ySurviceIDHeadEnd2=$_POST["ySurviceIDHeadEnd2"];
	$zSurviceIDHeadEnd2=$_POST["zSurviceIDHeadEnd2"];
	$xSurviceIDHeadEnd3=$_POST["xSurviceIDHeadEnd3"];
	$ySurviceIDHeadEnd3=$_POST["ySurviceIDHeadEnd3"];
	$zSurviceIDHeadEnd3=$_POST["zSurviceIDHeadEnd3"];
	$xSurviceIDHeadEnd4=$_POST["xSurviceIDHeadEnd4"];
	$ySurviceIDHeadEnd4=$_POST["ySurviceIDHeadEnd4"];
	$zSurviceIDHeadEnd4=$_POST["zSurviceIDHeadEnd4"];
	$xSurviceIDHeadEnd5=$_POST["xSurviceIDHeadEnd5"];
	$ySurviceIDHeadEnd5=$_POST["ySurviceIDHeadEnd5"];
	$zSurviceIDHeadEnd5=$_POST["zSurviceIDHeadEnd5"];
	
	//condition 
	$ConditionSurfaceIdHeadEnd=$_POST["ConditionSurfaceIdHeadEnd"];	
	//recomendation repair
	$recommendationRepairSurfaceIHeadEnd=$_POST["recommendationRepairSurfaceIHeadEnd"];
	
	//face bottom condition
	$faceButtomConditionSurfaceIHeadEnd=$_POST["faceButtomConditionSurfaceIHeadEnd"];
	//recomendation repair
	$recommendationRepairFaceBottomSurfaceIHeadEnd=$_POST["recommendationRepairFaceBottomSurfaceIHeadEnd"];
	
	//hole thread or thread on head end
	$holeThreadSurfaceID=$_POST["holeThreadSurfaceID"];
	//recomendation repair
	$RecommendationHoleThreadSurfaceID=$_POST["RecommendationHoleThreadSurfaceID"];
	
	//bracket condition
	$brackketConditionSurfaceID=$_POST["brackketConditionSurfaceID"];
	//recomendation repair
	$recommendationRepairBrackketConditionSurfaceID=$_POST["recommendationRepairBrackketConditionSurfaceID"];
	
	//oil port 
	$oilPortSurfaceID=$_POST["oilPortSurfaceID"];
    //recomendation repair	
	$recommendationRepairOilPortSurfaceID=$_POST["recommendationRepairOilPortSurfaceID"];
	
	//foto
	$nama_file = $_FILES['gambar']['name'];
    $ukuran_file = $_FILES['gambar']['size'];
    $tipe_file = $_FILES['gambar']['type'];
    $tmp_file = $_FILES['gambar']['tmp_name'];
	
	//mengambil isi dari database form_qc_001_surfaceid_condition
	$db = "SELECT * form_qc_001_surfaceid_condition WHERE id_dipilih = '1'";

							$res = mysqli_query($conn, $db);
							while ($row = mysqli_fetch_assoc($res)) 
							{
							?>
								<tr>
									<td>
									     <?php
										$c="SELECT * FROM form_qc_001_surfaceid_condition WHERE nik=".$b;
										$resb=mysqli_query($conn,$c);
										$datb=mysqli_fetch_assoc($resb);
										$departement = $datb["departement"];
								        echo "tess = ".$departement;
									     ?>
								    </td>
								<tr>
							<?php
							}
	
	
	/////////////////////////////////////////////////Assy / Parsial dan Single Non Testing//////////////////////////////////////////////////////
	
	echo "form = ".$form."<br>";
	
	echo "ukuranSurfaceID = ".$ukuranSurfaceID."<br>";
	echo "sizeSurviceID = ".$sizeSurviceID."<br>";
	echo "upperSurviceID = ".$upperSurviceID."<br>";
	echo "lowerSurviceID = ".$lowerSurviceID."<br>";
	
	echo "x1SurviceID = ".$x1SurviceID."<br>";
	echo "y1SurviceID = ".$y1SurviceID."<br>";
	echo "z1SurviceID = ".$z1SurviceID."<br>";
	
	echo "x2SurviceID = ".$x2SurviceID."<br>";
	echo "y2SurviceID = ".$y2SurviceID."<br>";
	echo "z2SurviceID = ".$z2SurviceID."<br>";
	
	echo "x3SurviceID = ".$x3SurviceID."<br>";
	echo "y3SurviceID = ".$y3SurviceID."<br>";
	echo "z3SurviceID = ".$z3SurviceID."<br>";
	
	echo "x4SurviceID = ".$x4SurviceID."<br>";
	echo "y4SurviceID = ".$y4SurviceID."<br>";
	echo "z4SurviceID = ".$z4SurviceID."<br>";
	
	echo "x5SurviceID = ".$x5SurviceID."<br>";
	echo "y5SurviceID = ".$y5SurviceID."<br>";
	echo "z5SurviceID = ".$z5SurviceID."<br>";
	
	echo "x6SurviceID = ".$x6SurviceID."<br>";
	echo "y6SurviceID = ".$y6SurviceID."<br>";
	echo "z6SurviceID = ".$z6SurviceID."<br>";
	
	echo "x7SurviceID = ".$x7SurviceID."<br>";
	echo "y7SurviceID = ".$y7SurviceID."<br>";
	echo "z7SurviceID = ".$z7SurviceID."<br>";
	
	echo "x8SurviceID = ".$x8SurviceID."<br>";
	echo "y8SurviceID = ".$y8SurviceID."<br>";
	echo "z8SurviceID = ".$z8SurviceID."<br>";
	
	echo "conditionSurviceID = ".$conditionSurviceID."<br>";
	
	echo "aChromeCoatingSurviceID = ".$aChromeCoatingSurviceID."<br>";
	echo "bChromeCoatingSurviceID = ".$bChromeCoatingSurviceID."<br>";
	echo "cChromeCoatingSurviceID = ".$cChromeCoatingSurviceID."<br>";
	echo "cChromeCoatingSurviceID = ".$dChromeCoatingSurviceID."<br>";
	echo "eChromeCoatingSurviceID = ".$eChromeCoatingSurviceID."<br>";
	
	echo "roughnessSurfaceID1 = ".$roughnessSurfaceID1."<br>";
	echo "roughnessSurfaceID2 = ".$roughnessSurfaceID2."<br>";
	echo "roughnessSurfaceID3 = ".$roughnessSurfaceID3."<br>";
	
	echo "aSpecInsideRunSurfaceID = ".$aSpecInsideRunSurfaceID."<br>";
	echo "bSpecInsideRunSurfaceID = ".$bSpecInsideRunSurfaceID."<br>";
	
	echo "cSpecInsideConcentricitySurfaceID = ".$cSpecInsideConcentricitySurfaceID."<br>";
	echo "dSpecInsideConcentricitySurfaceID = ".$dSpecInsideConcentricitySurfaceID."<br>";
	echo "eSpecInsideConcentricitySurfaceID = ".$eSpecInsideConcentricitySurfaceID."<br>";
	
	echo "lengthHoneSurfaceID = ".$lengthHoneSurfaceID."<br>";
	
	echo "lengthHoneHardnessMatSurfaceID1 = ".$lengthHoneHardnessMatSurfaceID1."<br>";
	echo "lengthHoneHardnessMatSurfaceID2 = ".$lengthHoneHardnessMatSurfaceID2."<br>";
	echo "lengthHoneHardnessMatSurfaceID3 = ".$lengthHoneHardnessMatSurfaceID3."<br>";
	
	echo "totalLengthSurfaceID = ".$totalLengthSurfaceID."<br>";
	
	echo "totalLengthHardnessSurvaceID1 = ".$totalLengthHardnessSurvaceID1."<br>";
	echo "totalLengthHardnessSurvaceID2 = ".$totalLengthHardnessSurvaceID2."<br>";
	echo "totalLengthHardnessSurvaceID3 = ".$totalLengthHardnessSurvaceID3."<br>";
	
	echo "diameterOdTube = ".$diameterOdTube."<br>";
	
	echo "recommendationRepairSurfaceID = ".$recommendationRepairSurfaceID."<br>";
	
	echo "xSurviceIDHeadEnd1 = ".$xSurviceIDHeadEnd1."<br>";
	echo "ySurviceIDHeadEnd1 = ".$ySurviceIDHeadEnd1."<br>";
	echo "zSurviceIDHeadEnd1 = ".$zSurviceIDHeadEnd1."<br>";
	
	echo "xSurviceIDHeadEnd2 = ".$xSurviceIDHeadEnd2."<br>";
	echo "ySurviceIDHeadEnd2 = ".$ySurviceIDHeadEnd2."<br>";
	echo "zSurviceIDHeadEnd2 = ".$zSurviceIDHeadEnd2."<br>";
	
	echo "xSurviceIDHeadEnd3 = ".$xSurviceIDHeadEnd3."<br>";
	echo "ySurviceIDHeadEnd3 = ".$ySurviceIDHeadEnd3."<br>";
	echo "zSurviceIDHeadEnd3 = ".$zSurviceIDHeadEnd3."<br>";
	
	echo "xSurviceIDHeadEnd4 = ".$xSurviceIDHeadEnd4."<br>";
	echo "ySurviceIDHeadEnd4 = ".$ySurviceIDHeadEnd4."<br>";
	echo "zSurviceIDHeadEnd4 = ".$zSurviceIDHeadEnd4."<br>";
	
	echo "xSurviceIDHeadEnd5 = ".$xSurviceIDHeadEnd5."<br>";
	echo "ySurviceIDHeadEnd5 = ".$ySurviceIDHeadEnd5."<br>";
	echo "zSurviceIDHeadEnd5 = ".$zSurviceIDHeadEnd5."<br>";
	
	echo "ConditionSurfaceIdHeadEnd = ".$ConditionSurfaceIdHeadEnd."<br>";
	echo "recommendationRepairSurfaceIHeadEnd = ".$recommendationRepairSurfaceIHeadEnd."<br>";
	echo "faceButtomConditionSurfaceIHeadEnd = ".$faceButtomConditionSurfaceIHeadEnd."<br>";
	echo "recommendationRepairFaceBottomSurfaceIHeadEnd = ".$recommendationRepairFaceBottomSurfaceIHeadEnd."<br>";
	echo "holeThreadSurfaceID = ".$holeThreadSurfaceID."<br>";
	echo "RecommendationHoleThreadSurfaceID = ".$RecommendationHoleThreadSurfaceID."<br>";
	echo "brackketConditionSurfaceID = ".$brackketConditionSurfaceID."<br>";
	echo "recommendationRepairBrackketConditionSurfaceID = ".$recommendationRepairBrackketConditionSurfaceID."<br>";
	echo "oilPortSurfaceID = ".$oilPortSurfaceID."<br>";
	echo "recommendationRepairOilPortSurfaceID = ".$recommendationRepairOilPortSurfaceID."<br>";
	
	echo "foto : = ".$nama_file."<br>";
	$tanggal = date('m-d-Y');
	if ($nama_file == NULL) //foto kosong
	{
								$dent=0;
								$crack=0;
								$score=0;
								$pitted=0;
								$wave=0;
								$oversize=0;
								$wearstep=0;
								$oval=0;
								$corrosion=0;
								$scratches=0;
								$deepscratches=0;
		$q = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id_dipilih='1'";
							$res = mysqli_query($conn, $q);
							while ($row = mysqli_fetch_assoc($res)) 
							{
								echo "ini id yg terpilih = ".$row['id'];
							}
							
								
		
		echo "Foto kosong";
		$query = "INSERT INTO form_mhb_fr_qc_001_01 (
										no_mhb_barang_job,
										 tanggal_periksa_form,
										 form,
										 ukuranSurfaceID,
										 sizeSurviceID,
										 upperSurviceID,
										 lowerSurviceID,
										 x1SurviceID,
										 y1SurviceID,
										 z1SurviceID,
										 x2SurviceID,
										 y2SurviceID,
										 z2SurviceID,
										 x3SurviceID,
										 y3SurviceID,
										 z3SurviceID,
										 x4SurviceID,
										 y4SurviceID,
										 z4SurviceID,
										 x5SurviceID,
										 y5SurviceID,
										 z5SurviceID,
										 x6SurviceID,
										 y6SurviceID,
										 z6SurviceID,
										 x7SurviceID,
										 y7SurviceID,
										 z7SurviceID,
										 x8SurviceID,
										 y8SurviceID,
										 z8SurviceID,
										 aChromeCoatingSurviceID,
										 bChromeCoatingSurviceID,
										 cChromeCoatingSurviceID,
										 dChromeCoatingSurviceID,
										 eChromeCoatingSurviceID,
										 roughnessSurfaceID1,
										 roughnessSurfaceID2,
										 roughnessSurfaceID3,
										 aSpecInsideRunSurfaceID,
										 bSpecInsideRunSurfaceID,
										 cSpecInsideConcentricitySurfaceID,
										 dSpecInsideConcentricitySurfaceID,
										 eSpecInsideConcentricitySurfaceID,
										 lengthHoneSurfaceID,
										 lengthHoneHardnessMatSurfaceID1,
										 lengthHoneHardnessMatSurfaceID2,
										 lengthHoneHardnessMatSurfaceID3,
										 totalLengthSurfaceID,
										 totalLengthHardnessSurvaceID1,
										 totalLengthHardnessSurvaceID2,
										 totalLengthHardnessSurvaceID3,
										 diameterOdTube,
										 recommendationRepairSurfaceID,
										 xSurviceIDHeadEnd1,
										 ySurviceIDHeadEnd1,
										 zSurviceIDHeadEnd1,
										 xSurviceIDHeadEnd2,
										 ySurviceIDHeadEnd2,
										 zSurviceIDHeadEnd2,
										 xSurviceIDHeadEnd3,
										 ySurviceIDHeadEnd3,
										 zSurviceIDHeadEnd3,
										 xSurviceIDHeadEnd4,
										 ySurviceIDHeadEnd4,
										 zSurviceIDHeadEnd4,
										 xSurviceIDHeadEnd5,
										 ySurviceIDHeadEnd5,
										 zSurviceIDHeadEnd5,
										 ConditionSurfaceIdHeadEnd,
										 recommendationRepairSurfaceIHeadEnd,
										 faceButtomConditionSurfaceIHeadEnd,
										 recommendationRepairFaceBottomSurfaceIHeadEnd,
										 holeThreadSurfaceID,
										 RecommendationHoleThreadSurfaceID,
										 brackketConditionSurfaceID,
										 recommendationRepairBrackketConditionSurfaceID,
										 oilPortSurfaceID,
										 recommendationRepairOilPortSurfaceID)
							
							       VALUE
							             ('$no_mhb_barang_job',
										 '$tanggal',
										 '$form',
										 '$ukuranSurfaceID',
										 '$sizeSurviceID',
										 '$upperSurviceID',
										 '$lowerSurviceID',
										 '$x1SurviceID',
										 '$y1SurviceID',
										 '$z1SurviceID',
										 '$x2SurviceID',
										 '$y2SurviceID',
										 '$z2SurviceID',
										 '$x3SurviceID',
										 '$y3SurviceID',
										 '$z3SurviceID',
										 '$x4SurviceID',
										 '$y4SurviceID',
										 '$z4SurviceID',
										 '$x5SurviceID',
										 '$y5SurviceID',
										 '$z5SurviceID',
										 '$x6SurviceID',
										 '$y6SurviceID',
										 '$z6SurviceID',
										 '$x7SurviceID',
										 '$y7SurviceID',
										 '$z7SurviceID',
										 '$x8SurviceID',
										 '$y8SurviceID',
										 '$z8SurviceID',
										 '$aChromeCoatingSurviceID',
										 '$bChromeCoatingSurviceID',
										 '$cChromeCoatingSurviceID',
										 '$dChromeCoatingSurviceID',
										 '$eChromeCoatingSurviceID',
										 '$roughnessSurfaceID1',
										 '$roughnessSurfaceID2',
										 '$roughnessSurfaceID3',
										 '$aSpecInsideRunSurfaceID',
										 '$bSpecInsideRunSurfaceID',
										 '$cSpecInsideConcentricitySurfaceID',
										 '$dSpecInsideConcentricitySurfaceID',
										 '$eSpecInsideConcentricitySurfaceID',
										 '$lengthHoneSurfaceID',
										 '$lengthHoneHardnessMatSurfaceID1',
										 '$lengthHoneHardnessMatSurfaceID2',
										 '$lengthHoneHardnessMatSurfaceID3',
										 '$totalLengthSurfaceID',
										 '$totalLengthHardnessSurvaceID1',
										 '$totalLengthHardnessSurvaceID2',
										 '$totalLengthHardnessSurvaceID3',
										 '$diameterOdTube',
										 '$recommendationRepairSurfaceID',
										 '$xSurviceIDHeadEnd1',
										 '$ySurviceIDHeadEnd1',
										 '$zSurviceIDHeadEnd1',
										 '$xSurviceIDHeadEnd2',
										 '$ySurviceIDHeadEnd2',
										 '$zSurviceIDHeadEnd2',
										 '$xSurviceIDHeadEnd3',
										 '$ySurviceIDHeadEnd3',
										 '$zSurviceIDHeadEnd3',
										 '$xSurviceIDHeadEnd4',
										 '$ySurviceIDHeadEnd4',
										 '$zSurviceIDHeadEnd4',
										 '$xSurviceIDHeadEnd5',
										 '$ySurviceIDHeadEnd5',
										 '$zSurviceIDHeadEnd5',
										 '$ConditionSurfaceIdHeadEnd',
										 '$recommendationRepairSurfaceIHeadEnd',
										 '$faceButtomConditionSurfaceIHeadEnd',
										 '$recommendationRepairFaceBottomSurfaceIHeadEnd',
										 '$holeThreadSurfaceID',
										 '$RecommendationHoleThreadSurfaceID',
										 '$brackketConditionSurfaceID',
										 '$recommendationRepairBrackketConditionSurfaceID',
										 '$oilPortSurfaceID',
										 '$recommendationRepairOilPortSurfaceID')";
										 
							
		
		
			$resultInsert = mysqli_query($conn, $query);
			if($resultInsert)
			{
				echo "Data periode berhasil masuk tanpa foto";
				//header("location:inputFormMhbFrQc00102.php?p=$no_mhb_barang_job");
				header("location:inputToleransi2.php?mhb_id=$no_mhb_barang_job");
				
				//update surfaceid_condition ke db form_mhb_fr_qc_001_01 sesuai surfaceid yg dipilih dengan cara mengupdate form_mhb_fr_qc_001_01 yang paling baru
				
				$select_terbaru = "SELECT * FROM form_mhb_fr_qc_001_01 ORDER BY id DESC LIMIT 1";
				$select_terbaru1 = mysqli_query($conn, $select_terbaru);
				$aa=mysqli_fetch_assoc($select_terbaru1);
				$id_terbaru = $aa["id"];
				echo "<br>"."ini id terbaru = ".$id_terbaru;
				
				//dent
				$selecta = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '1'";
				$select1 = mysqli_query($conn, $selecta);
				$a=mysqli_fetch_assoc($select1);
				$id_dipilih1 = $a["id_dipilih"];
				if($id_dipilih1 == 1)
				{
					//dent
					echo "<br>"."ini dent";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDdent = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no dent
					echo "<br>"."ini no dent";
				}
				
				//crack
				$selectb = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '2'";
				$select2 = mysqli_query($conn, $selectb);
				$b=mysqli_fetch_assoc($select2);
				$id_dipilih2 = $b["id_dipilih"];
				if($id_dipilih2 == 1)
				{
					//crack
					echo "<br>"."ini crack";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDcrack = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no crack
					echo "<br>"."ini no crack";
				}
				
				//score
				$selectc = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '3'";
				$select3 = mysqli_query($conn, $selectc);
				$c=mysqli_fetch_assoc($select3);
				$id_dipilih3 = $c["id_dipilih"];
				if($id_dipilih3 == 1)
				{
					//score
					echo "<br>"."ini score";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDscore = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no score
					echo "<br>"."ini no score";
				}
				
				//pitted
				$selectd = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '4'";
				$select4 = mysqli_query($conn, $selectd);
				$d=mysqli_fetch_assoc($select4);
				$id_dipilih4 = $d["id_dipilih"];
				if($id_dipilih4 == 1)
				{
					//pitted
					echo "<br>"."ini pitted";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDpitted = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no pitted
					echo "<br>"."ini no pitted";
				}
				
				//wave
				$selecte = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '5'";
				$select5 = mysqli_query($conn, $selecte);
				$e=mysqli_fetch_assoc($select5);
				$id_dipilih5 = $e["id_dipilih"];
				if($id_dipilih5 == 1)
				{
					//wave
					echo "<br>"."ini wave";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDwave = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no wave
					echo "<br>"."ini no wave";
				}
				
				//oversize
				$selectf = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '6'";
				$select6 = mysqli_query($conn, $selectf);
				$f=mysqli_fetch_assoc($select6);
				$id_dipilih6 = $f["id_dipilih"];
				if($id_dipilih6 == 1)
				{
					//oversize
					echo "<br>"."ini oversize";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDoversize = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no oversize
					echo "<br>"."ini no oversize";
				}
				
				//wearstep
				$selectg = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '7'";
				$select7 = mysqli_query($conn, $selectg);
				$g=mysqli_fetch_assoc($select7);
				$id_dipilih7 = $g["id_dipilih"];
				if($id_dipilih7 == 1)
				{
					//wearstep
					echo "<br>"."ini wearstep";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDwearStep = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no wearstep
					echo "<br>"."ini no wearstep";
				}
				
				//oval
				$selecth = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '8'";
				$select8 = mysqli_query($conn, $selecth);
				$h=mysqli_fetch_assoc($select8);
				$id_dipilih8 = $h["id_dipilih"];
				if($id_dipilih8 == 1)
				{
					//oval
					echo "<br>"."ini oval";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDoval = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no oval
					echo "<br>"."ini no oval";
				}
				
				//corrosion
				$selecti = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '9'";
				$select9 = mysqli_query($conn, $selecti);
				$i=mysqli_fetch_assoc($select9);
				$id_dipilih9 = $i["id_dipilih"];
				if($id_dipilih9 == 1)
				{
					//corrosion
					echo "<br>"."ini corrosion";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDcorrosion = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no corrosion
					echo "<br>"."ini no corrosion";
				}
				
				//scratches
				$selectj = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '10'";
				$select10 = mysqli_query($conn, $selectj);
				$j=mysqli_fetch_assoc($select10);
				$id_dipilih10 = $j["id_dipilih"];
				if($id_dipilih10 == 1)
				{
					//scratches
					echo "<br>"."ini scratches";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDscratches = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no scratches
					echo "<br>"."ini no scratches";
				}
				
				//deepscratches
				$selectk = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '11'";
				$select11 = mysqli_query($conn, $selectk);
				$k=mysqli_fetch_assoc($select11);
				$id_dipilih11 = $k["id_dipilih"];
				if($id_dipilih11 == 1)
				{
					//deepscratches
					echo "<br>"."ini deepscratches";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDdeepScratc = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no deepscratches
					echo "<br>"."ini no deepscratches";
				}
					
			$update = "UPDATE form_qc_001_surfaceid_condition SET id_dipilih = 0 WHERE id_dipilih = 1";
				$updatesql = mysqli_query($conn, $update);
			}
			else
			{
				header("location:printInspectionReportAssyParsialSingle.php?p=3");
				
				echo "error";
			}
	}
	// dengan foto
	else
	{
		// Set path folder tempat menyimpan gambarnya
		$path = "fotoFormMHB-FR-QC-001-01/".$nama_file;
		if($tipe_file == "image/jpeg" || $tipe_file == "image/png")
		{ // Cek apakah tipe file yang diupload adalah JPG / JPEG / PNG
		  // Jika tipe file yang diupload JPG / JPEG / PNG, lakukan :
		  if($ukuran_file <= 1000000){ // Cek apakah ukuran file yang diupload kurang dari sama dengan 1MB
			// Jika ukuran file kurang dari sama dengan 1MB, lakukan :
			// Proses upload
			if(move_uploaded_file($tmp_file, $path)){ // Cek apakah gambar berhasil diupload atau tidak
			  // Jika gambar berhasil diupload, Lakukan :  
			  // Proses simpan ke Database
			  if (isset($_SESSION["UserID"]))
			{
		echo "Foto terisi";
		$query = "INSERT INTO form_mhb_fr_qc_001_01 (
										no_mhb_barang_job,
										 tanggal_periksa_form,
										 form,
										 ukuranSurfaceID,
										 sizeSurviceID,
										 upperSurviceID,
										 lowerSurviceID,
										 x1SurviceID,
										 y1SurviceID,
										 z1SurviceID,
										 x2SurviceID,
										 y2SurviceID,
										 z2SurviceID,
										 x3SurviceID,
										 y3SurviceID,
										 z3SurviceID,
										 x4SurviceID,
										 y4SurviceID,
										 z4SurviceID,
										 x5SurviceID,
										 y5SurviceID,
										 z5SurviceID,
										 x6SurviceID,
										 y6SurviceID,
										 z6SurviceID,
										 x7SurviceID,
										 y7SurviceID,
										 z7SurviceID,
										 x8SurviceID,
										 y8SurviceID,
										 z8SurviceID,
										 aChromeCoatingSurviceID,
										 bChromeCoatingSurviceID,
										 cChromeCoatingSurviceID,
										 dChromeCoatingSurviceID,
										 eChromeCoatingSurviceID,
										 roughnessSurfaceID1,
										 roughnessSurfaceID2,
										 roughnessSurfaceID3,
										 aSpecInsideRunSurfaceID,
										 bSpecInsideRunSurfaceID,
										 cSpecInsideConcentricitySurfaceID,
										 dSpecInsideConcentricitySurfaceID,
										 eSpecInsideConcentricitySurfaceID,
										 lengthHoneSurfaceID,
										 lengthHoneHardnessMatSurfaceID1,
										 lengthHoneHardnessMatSurfaceID2,
										 lengthHoneHardnessMatSurfaceID3,
										 totalLengthSurfaceID,
										 totalLengthHardnessSurvaceID1,
										 totalLengthHardnessSurvaceID2,
										 totalLengthHardnessSurvaceID3,
										 diameterOdTube,
										 recommendationRepairSurfaceID,
										 xSurviceIDHeadEnd1,
										 ySurviceIDHeadEnd1,
										 zSurviceIDHeadEnd1,
										 xSurviceIDHeadEnd2,
										 ySurviceIDHeadEnd2,
										 zSurviceIDHeadEnd2,
										 xSurviceIDHeadEnd3,
										 ySurviceIDHeadEnd3,
										 zSurviceIDHeadEnd3,
										 xSurviceIDHeadEnd4,
										 ySurviceIDHeadEnd4,
										 zSurviceIDHeadEnd4,
										 xSurviceIDHeadEnd5,
										 ySurviceIDHeadEnd5,
										 zSurviceIDHeadEnd5,
										 ConditionSurfaceIdHeadEnd,
										 recommendationRepairSurfaceIHeadEnd,
										 faceButtomConditionSurfaceIHeadEnd,
										 recommendationRepairFaceBottomSurfaceIHeadEnd,
										 holeThreadSurfaceID,
										 RecommendationHoleThreadSurfaceID,
										 brackketConditionSurfaceID,
										 recommendationRepairBrackketConditionSurfaceID,
										 oilPortSurfaceID,
										 recommendationRepairOilPortSurfaceID,
										 foto_dokumen)
							
							       VALUE
							             ('$no_mhb_barang_job',
										 '$tanggal',
										 '$form',
										 '$ukuranSurfaceID',
										 '$sizeSurviceID',
										 '$upperSurviceID',
										 '$lowerSurviceID',
										 '$x1SurviceID',
										 '$y1SurviceID',
										 '$z1SurviceID',
										 '$x2SurviceID',
										 '$y2SurviceID',
										 '$z2SurviceID',
										 '$x3SurviceID',
										 '$y3SurviceID',
										 '$z3SurviceID',
										 '$x4SurviceID',
										 '$y4SurviceID',
										 '$z4SurviceID',
										 '$x5SurviceID',
										 '$y5SurviceID',
										 '$z5SurviceID',
										 '$x6SurviceID',
										 '$y6SurviceID',
										 '$z6SurviceID',
										 '$x7SurviceID',
										 '$y7SurviceID',
										 '$z7SurviceID',
										 '$x8SurviceID',
										 '$y8SurviceID',
										 '$z8SurviceID',
										 '$aChromeCoatingSurviceID',
										 '$bChromeCoatingSurviceID',
										 '$cChromeCoatingSurviceID',
										 '$dChromeCoatingSurviceID',
										 '$eChromeCoatingSurviceID',
										 '$roughnessSurfaceID1',
										 '$roughnessSurfaceID2',
										 '$roughnessSurfaceID3',
										 '$aSpecInsideRunSurfaceID',
										 '$bSpecInsideRunSurfaceID',
										 '$cSpecInsideConcentricitySurfaceID',
										 '$dSpecInsideConcentricitySurfaceID',
										 '$eSpecInsideConcentricitySurfaceID',
										 '$lengthHoneSurfaceID',
										 '$lengthHoneHardnessMatSurfaceID1',
										 '$lengthHoneHardnessMatSurfaceID2',
										 '$lengthHoneHardnessMatSurfaceID3',
										 '$totalLengthSurfaceID',
										 '$totalLengthHardnessSurvaceID1',
										 '$totalLengthHardnessSurvaceID2',
										 '$totalLengthHardnessSurvaceID3',
										 '$diameterOdTube',
										 '$recommendationRepairSurfaceID',
										 '$xSurviceIDHeadEnd1',
										 '$ySurviceIDHeadEnd1',
										 '$zSurviceIDHeadEnd1',
										 '$xSurviceIDHeadEnd2',
										 '$ySurviceIDHeadEnd2',
										 '$zSurviceIDHeadEnd2',
										 '$xSurviceIDHeadEnd3',
										 '$ySurviceIDHeadEnd3',
										 '$zSurviceIDHeadEnd3',
										 '$xSurviceIDHeadEnd4',
										 '$ySurviceIDHeadEnd4',
										 '$zSurviceIDHeadEnd4',
										 '$xSurviceIDHeadEnd5',
										 '$ySurviceIDHeadEnd5',
										 '$zSurviceIDHeadEnd5',
										 '$ConditionSurfaceIdHeadEnd',
										 '$recommendationRepairSurfaceIHeadEnd',
										 '$faceButtomConditionSurfaceIHeadEnd',
										 '$recommendationRepairFaceBottomSurfaceIHeadEnd',
										 '$holeThreadSurfaceID',
										 '$RecommendationHoleThreadSurfaceID',
										 '$brackketConditionSurfaceID',
										 '$recommendationRepairBrackketConditionSurfaceID',
										 '$oilPortSurfaceID',
										 '$recommendationRepairOilPortSurfaceID',
										 '$nama_file')";
										 
										 
			$resultInsert = mysqli_query($conn, $query);
			if($resultInsert)
			{
				echo "Data periode berhasil masuk";
				
				//header("location:inputFormMhbFrQc00102.php?p=$no_mhb_barang_job");
					
				header("location:inputToleransi2.php?mhb_id=$no_mhb_barang_job");
				
				//update surfaceid_condition ke db form_mhb_fr_qc_001_01 sesuai surfaceid yg dipilih dengan cara mengupdate form_mhb_fr_qc_001_01 yang paling baru
				
				$select_terbaru = "SELECT * FROM form_mhb_fr_qc_001_01 ORDER BY id DESC LIMIT 1";
				$select_terbaru1 = mysqli_query($conn, $select_terbaru);
				$aa=mysqli_fetch_assoc($select_terbaru1);
				$id_terbaru = $aa["id"];
				echo "<br>"."ini id terbaru = ".$id_terbaru;
				
				//dent
				$selecta = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '1'";
				$select1 = mysqli_query($conn, $selecta);
				$a=mysqli_fetch_assoc($select1);
				$id_dipilih1 = $a["id_dipilih"];
				if($id_dipilih1 == 1)
				{
					//dent
					echo "<br>"."ini dent";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDdent = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no dent
					echo "<br>"."ini no dent";
				}
				
				//crack
				$selectb = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '2'";
				$select2 = mysqli_query($conn, $selectb);
				$b=mysqli_fetch_assoc($select2);
				$id_dipilih2 = $b["id_dipilih"];
				if($id_dipilih2 == 1)
				{
					//crack
					echo "<br>"."ini crack";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDcrack = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no crack
					echo "<br>"."ini no crack";
				}
				
				//score
				$selectc = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '3'";
				$select3 = mysqli_query($conn, $selectc);
				$c=mysqli_fetch_assoc($select3);
				$id_dipilih3 = $c["id_dipilih"];
				if($id_dipilih3 == 1)
				{
					//score
					echo "<br>"."ini score";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDscore = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no score
					echo "<br>"."ini no score";
				}
				
				//pitted
				$selectd = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '4'";
				$select4 = mysqli_query($conn, $selectd);
				$d=mysqli_fetch_assoc($select4);
				$id_dipilih4 = $d["id_dipilih"];
				if($id_dipilih4 == 1)
				{
					//pitted
					echo "<br>"."ini pitted";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDpitted = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no pitted
					echo "<br>"."ini no pitted";
				}
				
				//wave
				$selecte = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '5'";
				$select5 = mysqli_query($conn, $selecte);
				$e=mysqli_fetch_assoc($select5);
				$id_dipilih5 = $e["id_dipilih"];
				if($id_dipilih5 == 1)
				{
					//wave
					echo "<br>"."ini wave";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDwave = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no wave
					echo "<br>"."ini no wave";
				}
				
				//oversize
				$selectf = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '6'";
				$select6 = mysqli_query($conn, $selectf);
				$f=mysqli_fetch_assoc($select6);
				$id_dipilih6 = $f["id_dipilih"];
				if($id_dipilih6 == 1)
				{
					//oversize
					echo "<br>"."ini oversize";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDoversize = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no oversize
					echo "<br>"."ini no oversize";
				}
				
				//wearstep
				$selectg = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '7'";
				$select7 = mysqli_query($conn, $selectg);
				$g=mysqli_fetch_assoc($select7);
				$id_dipilih7 = $g["id_dipilih"];
				if($id_dipilih7 == 1)
				{
					//wearstep
					echo "<br>"."ini wearstep";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDwearStep = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no wearstep
					echo "<br>"."ini no wearstep";
				}
				
				//oval
				$selecth = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '8'";
				$select8 = mysqli_query($conn, $selecth);
				$h=mysqli_fetch_assoc($select8);
				$id_dipilih8 = $h["id_dipilih"];
				if($id_dipilih8 == 1)
				{
					//oval
					echo "<br>"."ini oval";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDoval = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no oval
					echo "<br>"."ini no oval";
				}
				
				//corrosion
				$selecti = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '9'";
				$select9 = mysqli_query($conn, $selecti);
				$i=mysqli_fetch_assoc($select9);
				$id_dipilih9 = $i["id_dipilih"];
				if($id_dipilih9 == 1)
				{
					//corrosion
					echo "<br>"."ini corrosion";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDcorrosion = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no corrosion
					echo "<br>"."ini no corrosion";
				}
				
				//scratches
				$selectj = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '10'";
				$select10 = mysqli_query($conn, $selectj);
				$j=mysqli_fetch_assoc($select10);
				$id_dipilih10 = $j["id_dipilih"];
				if($id_dipilih10 == 1)
				{
					//scratches
					echo "<br>"."ini scratches";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDscratches = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no scratches
					echo "<br>"."ini no scratches";
				}
				
				//deepscratches
				$selectk = "SELECT * FROM form_qc_001_surfaceid_condition WHERE id = '11'";
				$select11 = mysqli_query($conn, $selectk);
				$k=mysqli_fetch_assoc($select11);
				$id_dipilih11 = $k["id_dipilih"];
				if($id_dipilih11 == 1)
				{
					//deepscratches
					echo "<br>"."ini deepscratches";
					$updatea = "UPDATE form_mhb_fr_qc_001_01 SET conditionSurviceIDdeepScratc = 1 WHERE id = $id_terbaru";
					$update1 = mysqli_query($conn, $updatea);
				}
				else
				{
					//no deepscratches
					echo "<br>"."ini no deepscratches";
				}
					
			$update = "UPDATE form_qc_001_surfaceid_condition SET id_dipilih = 0 WHERE id_dipilih = 1";
				$updatesql = mysqli_query($conn, $update);
			}
			else
			{
				header("location:printInspectionReportAssyParsialSingle.php?p=2");
			
				echo "error";
			}
			}
			else{
			  // Jika gambar gagal diupload, Lakukan :
		  
			  header("location:printInspectionReportAssyParsialSingle.php?p=3");
			}
		  }else{
			// Jika ukuran file lebih dari 1MB, lakukan :
		   
			header("location:printInspectionReportAssyParsialSingle.php?p=4");
			echo "<d>".$query;
		  }
		}
		else
		{
		  // Jika tipe file yang diupload bukan JPG / JPEG / PNG, lakukan :

		  header("location:tambahDailyReprintInspectionReportAssyParsialSingleport.php?p=5");
		  echo "<d>".$query;
		}
		}

	}
?>