<?php
include "koneksi.php";
if (isset($_POST['kendaraan'])) {
    $kendaraan = $_POST["kendaraan"];
    $kendaraan2 = $kendaraan;
    $sql = "select * from isi_daily_report where id != $kendaraan";
	
	if (isset($_SESSION["UserID"]))
			{
				$level=$_SESSION["Level"];
				$q="SELECT * FROM user WHERE id='". $_SESSION["UserID"] ."'";
				$res=mysqli_query($conn,$q);
				$dataUser=mysqli_fetch_assoc($res);
				
				//echo " ".$dataUser["nik_data_karyawan"];
				$nik = $dataUser["nik_data_karyawan"];
				$nama = $dataUser["nama"];
				$tanggal = date('m-d-Y');
			}
	$query1 = "INSERT INTO daily_report (nik,nama,tanggal_upload,id_daily_report_isi1,id_daily_report_isi2,id_daily_report_isi3) VALUES ('$nik','$nama','$tanggal','$kendaraan', '0', '0')";
	$result = mysqli_query($conn, $query1);
	
    $hasil = mysqli_query($conn, $sql);
    $no = 0;
    while ($data = mysqli_fetch_array($hasil)) {
        ?>
        <option value="<?php echo  $data['id']; ?>"><?php echo $data['daily']; ?></option>
        <?php
    }
}
if (isset($_POST['merk'])) {
    $merk = $_POST["merk"];
	
	$query = "SELECT * FROM daily_report ORDER BY id DESC LIMIT 1";
	$res=mysqli_query($conn,$query);
	$dataUser=mysqli_fetch_assoc($res);
	$id_daily_report_isi1 = $dataUser["id_daily_report_isi1"];
	$id_daily = $dataUser["id"];
			
    $sql = "select * from isi_daily_report where id != $merk AND id != $id_daily_report_isi1";

	if (isset($_SESSION["UserID"]))
			{
				$level=$_SESSION["Level"];
				$q="SELECT * FROM user WHERE id='". $_SESSION["UserID"] ."'";
				$res=mysqli_query($conn,$q);
				$dataUser=mysqli_fetch_assoc($res);
				
				//echo " ".$dataUser["nik_data_karyawan"];
				$nik = $dataUser["nik_data_karyawan"];
				$nama = $dataUser["nama"];
				$tanggal = date('m-d-Y');
			}
	$q="UPDATE daily_report SET id_daily_report_isi2='$merk' WHERE id='$id_daily'";
	$result = mysqli_query($conn, $q);
	
    $hasil = mysqli_query($conn, $sql);
    $no = 0;
    while ($data = mysqli_fetch_array($hasil)) {
        ?>
		<option value="<?php echo  $data['id']; ?>"><?php echo $data['daily']; ?></option>
		
        <?php
    }
}
if (isset($_POST['tipe'])) 
{
	$tipe = $_POST["tipe"];
	$query = "SELECT * FROM daily_report ORDER BY id DESC LIMIT 1";
	$res=mysqli_query($conn,$query);
	$dataUser=mysqli_fetch_assoc($res);
	$id_daily_report_isi1 = $dataUser["id_daily_report_isi1"];
	$id_daily = $dataUser["id"];
    
	
	$q="UPDATE daily_report SET id_daily_report_isi3='$tipe' WHERE id='$id_daily'";
	$result = mysqli_query($conn, $q);
	
  
}

?>