<?php
	include "koneksi.php";
	
	$id=mysqli_real_escape_string($conn,$_GET["id"]);
    echo "ini".$id."<br>";	
	
	$tanggal_receiving = date('d-m-Y');

    //1. Ambil Data yang Dikirim dari Form
    $nama_file1 = $_FILES['MHB-FR-QC-001-01']['name'];
    $ukuran_file1 = $_FILES['MHB-FR-QC-001-01']['size'];
    $tipe_file1 = $_FILES['MHB-FR-QC-001-01']['type'];
    $tmp_file1 = $_FILES['MHB-FR-QC-001-01']['tmp_name'];
	
	//2. Ambil Data yang Dikirim dari Form
    $nama_file2 = $_FILES['MHB-FR-QC-001-02']['name'];
    $ukuran_file2 = $_FILES['MHB-FR-QC-001-02']['size'];
    $tipe_file2 = $_FILES['MHB-FR-QC-001-02']['type'];
    $tmp_file2 = $_FILES['MHB-FR-QC-001-02']['tmp_name'];
	
	//3. Ambil Data yang Dikirim dari Form
    $nama_file3 = $_FILES['MHB-FR-QC-001-03']['name'];
    $ukuran_file3 = $_FILES['MHB-FR-QC-001-03']['size'];
    $tipe_file3 = $_FILES['MHB-FR-QC-001-03']['type'];
    $tmp_file3 = $_FILES['MHB-FR-QC-001-03']['tmp_name'];
	
	//4. Ambil Data yang Dikirim dari Form
    $nama_file4 = $_FILES['MHB-FR-QC-001-04']['name'];
    $ukuran_file4 = $_FILES['MHB-FR-QC-001-04']['size'];
    $tipe_file4 = $_FILES['MHB-FR-QC-001-04']['type'];
    $tmp_file4 = $_FILES['MHB-FR-QC-001-04']['tmp_name'];
	
	//5. Ambil Data yang Dikirim dari Form
    $nama_file5 = $_FILES['MHB-FR-QC-001-05']['name'];
    $ukuran_file5 = $_FILES['MHB-FR-QC-001-05']['size'];
    $tipe_file5 = $_FILES['MHB-FR-QC-001-05']['type'];
    $tmp_file5 = $_FILES['MHB-FR-QC-001-05']['tmp_name'];
	
	//6. Ambil Data yang Dikirim dari Form
    $nama_file6 = $_FILES['MHB-FR-PROD-001-01']['name'];
    $ukuran_file6 = $_FILES['MHB-FR-PROD-001-01']['size'];
    $tipe_file6 = $_FILES['MHB-FR-PROD-001-01']['type'];
    $tmp_file6 = $_FILES['MHB-FR-PROD-001-01']['tmp_name'];
	
	//7. Ambil Data yang Dikirim dari Form
    $nama_file7 = $_FILES['MHB-FR-QC-001-10']['name'];
    $ukuran_file7 = $_FILES['MHB-FR-QC-001-10']['size'];
    $tipe_file7 = $_FILES['MHB-FR-QC-001-10']['type'];
    $tmp_file7 = $_FILES['MHB-FR-QC-001-10']['tmp_name'];
	
	
// Set path folder tempat menyimpan gambarnya
$path1 = "Dokumen/".$nama_file1;
$path2 = "Dokumen/".$nama_file2;
$path3 = "Dokumen/".$nama_file3;
$path4 = "Dokumen/".$nama_file4;
$path5 = "Dokumen/".$nama_file5;
$path6 = "Dokumen/".$nama_file6;
$path7 = "Dokumen/".$nama_file7;


if($tipe_file1 == "image/jpeg" || $tipe_file1 == "image/png"){ // Cek apakah tipe file yang diupload adalah JPG / JPEG / PNG
  // Jika tipe file yang diupload JPG / JPEG / PNG, lakukan :
  if($ukuran_file1 <= 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_file1, $path1))
	{ // Cek apakah gambar berhasil diupload atau tidak
      // Jika gambar berhasil diupload, Lakukan :  
      // Proses simpan ke Database
	  if(move_uploaded_file($tmp_file2, $path2))
	  {
		  if(move_uploaded_file($tmp_file3, $path3))
	      {
			  if(move_uploaded_file($tmp_file4, $path4))
	          {
				  if(move_uploaded_file($tmp_file5, $path5))
	              {
					  if(move_uploaded_file($tmp_file6, $path6))
	                  {
						  if(move_uploaded_file($tmp_file7, $path7))
	                      {
	  
									  $query = "INSERT INTO print_inspection_report (id_barang_job, mhb_fr_qc_001_01, mhb_fr_qc_001_02, mhb_fr_qc_001_03, mhb_fr_qc_001_04, mhb_fr_qc_001_05 , mhb_fr_prod_001_01 , mhb_fr_qc_001_10)
														VALUE
																	  ('$id','$nama_file1','$nama_file2','$nama_file3','$nama_file4','$nama_file5','$nama_file6','$nama_file7')";
									$sql = mysqli_query($conn, $query); // Eksekusi/ Jalankan query dari variabel $query
									  
									$query1 = "UPDATE barang_job SET status = '4' WHERE no_mhb_id='$id'"; //seudah sampai print inspection report
	                                $result = mysqli_query($conn, $query1);
									  
									  if($sql & $result)
									  { // Cek jika proses simpan ke database sukses atau tidak
										// Jika Sukses, Lakukan :
										//header("location: index.php"); // Redirectke halaman index.php
										header("location:printInspectionReport.php?p=1");
										echo "1:";
									  }
									  else
									  {
										// Jika Gagal, Lakukan :
									 
										header("location:printInspectionReport.php?p=2");
										echo "2"."<br>";
										echo $query;
										echo "ono = ".$id;
									  }
						  }
				      }
				  }
			  }
		  }
	   }
    }
	
	
	
	
	else{
      // Jika gambar gagal diupload, Lakukan :
  
	  header("location:printInspectionReport.php?p=3");
	  echo "3";
    }
  }else{
    // Jika ukuran file lebih dari 1MB, lakukan :
   
	header("location:printInspectionReport.php?p=4");
	echo "4";
  }
}else{
  // Jika tipe file yang diupload bukan JPG / JPEG / PNG, lakukan :

  header("location:printInspectionReport.php?p=5");
  echo "5";
}

?>
