<?php
	include "koneksi.php";
	
	$mhb_id=mysqli_real_escape_string($conn,$_GET["id"]);
    echo "ini mhb id :".$mhb_id."<br>";	
    $tanggal_periksa_kelengkapan_cylinder = date('d / M / y');
    $cuci=$_POST['cuci'];
	$tanggal = date('d / M / y');
	echo "tanggal".$tanggal;
    echo "<br>".$cuci;
	
	
  
	if ($cuci == 1)//sudah dicuci
	{
		if (isset($_POST["kirim"])) {
			$jumlah = count($_FILES['gambar']['name']);
			//$jumlah2 = count($_FILES['gambar2']['name']);
			if ($jumlah > 0) 
			{
				$gambar = array();
				for ($i=0; $i < $jumlah; $i++) { 
					$file_name = $_FILES['gambar']['name'][$i];
					$tmp_name = $_FILES['gambar']['tmp_name'][$i];				
					move_uploaded_file($tmp_name, "fotoFormMHB-FR-PRO-D001-01/".$file_name);
					$gambar[$i] = $file_name;				
				}
				//mysqli_query($conn,"INSERT INTO fom_dissasembly_checklist VALUES('','$mhb_id','1','$tanggal_periksa_kelengkapan_cylinder',
														   
					//									   '$gambar[1]','$gambar[1]','$gambar[2]','$gambar[3]','$gambar[4]',
						//								   '$gambar[5]','$gambar[6]','$gambar[7]','$gambar[8]','$gambar[9]',
							//							   '$gambar[10]','$gambar[11]','$gambar[12]','$gambar[13]','$gambar[14]',
								//						   '$gambar[15]','$gambar[16]','$gambar[17]','$gambar[18]','$gambar[19]',
														   
									//					   '','','','','','','','','','',
										//				   '','','','','','','','','','',
														   
											//			   '','','','','','','','',
												//		   '')");
	//echo "<br>"."gambar 1 ".$gambar[0];
	//echo "<br>"."gambar 2 ".$gambar[1];
	//echo "<br>"."gambar 3 ".$gambar[2];
	//echo "<br>"."gambar 4 ".$gambar[3];
	//echo "<br>"."gambar 5 ".$gambar[4];
	//echo "<br>"."gambar 6 ".$gambar[5];
	//echo "<br>"."gambar 7 ".$gambar[6];
	//echo "<br>"."gambar 8 ".$gambar[7];
	//echo "<br>"."gambar 9 ".$gambar[8];
	//echo "<br>"."gambar 10 ".$gambar[9];
	
	//echo "<br>"."gambar 11 ".$gambar[10];
	//echo "<br>"."gambar 12 ".$gambar[11];
	//echo "<br>"."gambar 13 ".$gambar[12];
	//echo "<br>"."gambar 14 ".$gambar[13];
	//echo "<br>"."gambar 15 ".$gambar[14];
	//echo "<br>"."gambar 16 ".$gambar[15];
	//echo "<br>"."gambar 17 ".$gambar[16];
	//echo "<br>"."gambar 18 ".$gambar[17];
	//echo "<br>"."gambar 19 ".$gambar[18];
	//echo "<br>"."gambar 20 ".$gambar[19];										   
				
                $sql = "INSERT INTO fom_dissasembly_checklist (no_mhb_barang_job, status_cuti, tanggal_periksa_kelengkapan_cylinder,
				                                               gambarChylinder1,gambarChylinder2,gambarChylinder3,gambarChylinder4,gambarChylinder5,
															   gambarChylinder6,gambarChylinder7,gambarChylinder8,gambarChylinder9,gambarChylinder10,
															   gambarChylinder11,gambarChylinder12,gambarChylinder13,gambarChylinder14,gambarChylinder15,
															   gambarChylinder16,gambarChylinder17,gambarChylinder18,gambarChylinder19,gambarChylinder20)
															   
                               VALUES                         ('$mhb_id','$cuci','$tanggal',
							                                   '$gambar[0]','$gambar[1]','$gambar[2]','$gambar[3]','$gambar[4]',
							                                   '$gambar[5]','$gambar[6]','$gambar[7]','$gambar[8]','$gambar[9]',
															   '$gambar[10]','$gambar[11]','$gambar[12]','$gambar[13]','$gambar[14]',
															   '$gambar[15]','$gambar[16]','$gambar[17]','$gambar[18]','$gambar[19]')";				
				
													   
			
                //header("location:cleaningAndDaT3.php?p=1&d=$mhb_id");			
                $result = mysqli_query($conn, $sql);
				if($result)
				{
					echo "<br>"."query ".$sql."<br>";	
					echo "Data berhasil masuk";
					echo "Berhasil Upload 1";
					header("location:cleaningAndDaT3.php?p=1&d=$mhb_id");
				}
				else
				{
					header("location:cleaningAndDaT2.php?p=2&d=$mhb_id");
					//die("Error");
				}							

			}
			else
			{
				echo "Gambar tidak ada";
			}
		}
	}
    else if ($cuci == 2)
	{
		//kembali ke cleaning and dat tanpa proses
		header("location:cleaningAndDaT.php?p=6");
	}	
    
?>