<?php
    include('loginsession.php');
    error_reporting(E_ALL);
    $filename = __FILE__;  //---Nama file saat ini
    if (strlen(__FILE__) > 48) {$filename = substr(__FILE__, 48);}
    $save = mysqli_query($conn, "INSERT INTO novia_abc_user_logs (userid,filename) VALUES ('$userini_id','$filename')");
//-------------

$mr=  $_POST['mr']; 
$password = $_POST['password'];
$insert=1;
$today = date("Y-m-d");
$today1 = date("Y-m-d H:i:s");
if ( $userini_id == "3"){
    $password = 000;
}


$sql = "SELECT date_, mr FROM novia_abc_visit";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
		$s = $row["date_"];
        $dt = new DateTime($s);
        $currdate = $dt->format('Y-m-d');
		$tgl =  date("Y-m-d");
		if ( $currdate == $tgl){
			if ($mr == $row["mr"]){ $insert = 2;}
		}
	}
}

if ( $password != 000 ) { echo "<script>alert('Password Anda Salah');document.location='daftar-sekarang.php?id=$mr'</script>"; }
else if ( $insert == 2 ) { echo "<script>alert('Pasien sudah mendaftar hari ini');document.location='daftar-sekarang.php?id=$mr'</script>"; }
else { $save = mysqli_query($conn, "INSERT INTO novia_abc_visit (mr, date_ ) VALUES ('$mr', '$today1')");
	if($save){ echo "<script>document.location='visit-daily.php?tanggal=$today'</script>";} 
	else { echo "<script>alert('Proses simpan gagal, coba kembali');document.location='daftar-sekarang.php?id=$mr'</script>"; }
}
?>
