<?php
session_start();
include("config/connection.php");
include("config/config-url.php");

	$nama = $_POST['nama'];
	$password = $_POST['password'];
	$sql ="select * from tb_operator where nama = '".$nama."' and password = '".$password."' and status = '1'";
	$hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
	$jumlah = mysql_num_rows($hasil);
	if ($jumlah!=1){ ?>
		<script>window.location = "<?php echo $base?>loginsistem.php"</script>
    <?php 
	} else{
		$row = mysql_fetch_row($hasil);
		$user_id = $row[0];
		$nama = $row[1];
		$akses = $row[3];
		$_SESSION["id"] = $user_id;
		$_SESSION["user"] = $nama;
        $_SESSION["pass"] = $password; 
		$_SESSION["akses"] = $akses; 
		
		$tanggal = date('Y-m-d');
		include("config/connection.php");
		$sql ="select Id_Jadwal from tb_jadwal where tanggal = '".$tanggal."'";
		$hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
		mysql_close($test);
		
		$row = mysql_fetch_object($hasil);
		$Id_Jadwal = $row->Id_Jadwal;
		if($Id_Jadwal == ''){


			include("config/connection.php");
			
			$Waktu = '10.30';
			$Id_Kapal = '2';
			$Id_Nahkoda = '1';
			$Kuota_Order = '200';
			$Dari = '7';
			$Tujuan = '2';
			$tanggal = date('Y-m-d');
		
			$sql="insert into tb_jadwal (Waktu, Id_Kapal, Id_Nahkoda, Kuota_Order, Sisa, Dari, Tujuan, Status, tanggal)  values ('".$Waktu."','".$Id_Kapal."','".$Id_Nahkoda."','".$Kuota_Order."', '".$Kuota_Order."', '".$Dari."', '".$Tujuan."', 1, '".$tanggal."')";
			if (!mysql_query($sql,$test)){
			die('Error: ' . mysql_error());
			}
		
	
	
			include("config/connection.php");
			
			$Waktu = '15.30';
			$Id_Kapal = '2';
			$Id_Nahkoda = '1';
			$Kuota_Order = '200';
			$Dari = '7';
			$Tujuan = '2';
			$tanggal = date('Y-m-d');
		
			$sql="insert into tb_jadwal (Waktu, Id_Kapal, Id_Nahkoda, Kuota_Order, Sisa, Dari, Tujuan, Status, tanggal)  values ('".$Waktu."','".$Id_Kapal."','".$Id_Nahkoda."','".$Kuota_Order."', '".$Kuota_Order."', '".$Dari."', '".$Tujuan."', 1, '".$tanggal."')";
			if (!mysql_query($sql,$test)){
			die('Error: ' . mysql_error());
			}
		
		}
		
			include("config/connection.php");
			$sql ="select Id_Jadwal from tb_jadwal where tanggal = '".$tanggal."' and Waktu = '10.30'";
			$hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
			mysql_close($test);
			
			$row = mysql_fetch_object($hasil);
			$Id_Jadwal = $row->Id_Jadwal;
			$_SESSION["jadwalpagi"] = $Id_Jadwal;
		
			include("config/connection.php");
			$sql ="select Id_Jadwal from tb_jadwal where tanggal = '".$tanggal."' and Waktu = '15.30'";
			$hasil = mysql_query($sql) or die("Kesalahan Pada SQL");
			mysql_close($test);
			
			$row = mysql_fetch_object($hasil);
			$Id_Jadwal = $row->Id_Jadwal;
			$_SESSION["jadwalsore"] = $Id_Jadwal;
		?>
        
        <script>window.location = "<?php echo $base?>index"</script>
    <?php 
	}
