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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//ID" "http://www.w3.org/TR/html4/frameset.dtd">
<html lang="id">
<head>
	<title>KUNJUNGAN TERBARU</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="css/style.css">
	<link href="images/balance.ico" rel="icon" type="image/icon" />

	<style>
		a { text-decoration: none; color:inherit;}
		a:hover {color:#FF00FF;}   /* Mouse over link */
		input[type=text],input[type=password]
		{
		width:60%;
		padding:8px;
		margin-top:8px;
		margin-bottom:8px;
		border:1px solid #ccc;
		padding-left:5px;
		font-size:18px;
		}

		input[type=submit]
		{
		width:35%;
		background-color:#8baca4;
		color:#FFFFFF;
		border:2px solid #8baca4;
		padding:6px;
		font-size:18px;
		cursor:pointer;
		border-radius:5px;
		}	
		img {
            width: 100%;
            max-width: 500px;
            height: auto;
        }
    </style>	
</head>

<body>


    <table width="100%" cellpadding="5">
		<tr class="dua">
		    <td Height=66px align="center"; style="background-color:#355CA9; text-shadow:1px 1px 0px #aaa;"><a style="font-size:20px; font-family: Times New Roman; color:#222;">KUNJUNGAN TERBARU<a>
		        <a style = "font-size:16px;"><br>Urutan Kunjungan Terbaru<a></td>
		</tr>
	</table>
    <table width="100%" cellpadding="5">
		<tr class="dua">
		    <td width="75%"><a href="administrasi.php" title=""><button style="padding : 10px; width:100%; background-color:#A6B7C1;"> NAVIGASI </button></a></td>
		    <td width="25%"><a href="index.php" title="Halaman Awal"><button style="padding : 10px; width:100%; background-color:#A6B7C1;"> HOME </button></a></td>
		</tr>
	</table>

	<table width="100%" cellpadding="5">
		<tr class="dua">
		<td><a href="biodata-new.php" title="Masukkan data pasien baru ke database"><button style="padding : 10px; width:100%; background-color:#1baca4;"> DAFTAR BARU </button></a></td>
		<td><a href="visit-yearly.php?tanggal=<?php echo date("Y-m-d");?>" title="Lihat Pasien Tahun ini"><button style="padding : 10px; width:100%; background-color:#8baca4;">PASIEN TAHUN INI</button></a></td>
		<td><a href="visit-monthly.php?tanggal=<?php echo date("Y-m-d");?>" title="Lihat Pasien Bulan ini"><button style="padding : 10px; width:100%; background-color:#8baca4;">PASIEN BULAN INI</button></a></td>
		<td><a href="visit-daily.php?tanggal=<?php echo date("Y-m-d");?>" title="Lihat Pasien Hari ini"><button style="padding : 10px; width:100%; background-color:#8baca4;"> PASIEN HARI INI </button></a></td>
		</tr>
	</table>

	<table width="100%" cellpadding="5">
		<tr class="dua">
			<td colspan="4" style="padding-top : 10px;">
				<form action="index.php" method="get" align="center">
					<input type="text" name="cari" size="15" maxlength="33" placeholder=<?php echo $cari ?>>
					<input type="submit" value="Lacak Pasien">
				</form>
			</td>
		</tr>
	</table>

<table width="100%" cellpadding="5">

	<tr class="head">
	    <th width="10%">No</th>
		<th width="10%">MR</th>
		<th width="45%">Nama</th>
		<th width="10%">H</th>
		<th width="20%">Terakhir</th>
		<th width="100%">F</th>

		
	</tr>

<?php 
$no = 0;
$sty = 1;
$sql = "SELECT *  FROM novia_abc_biodata WHERE name LIKE '%$cari%' OR mr LIKE '%$cari%' OR phone_wa LIKE '%$cari%' OR phone_home LIKE '%$cari%' ORDER BY lastcome DESC LIMIT 0, 1000";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
		
		//Script Umur
		    $yer = new DateTime();
		    $yar = $row["birthday"];
		    $yur = new DateTime($yar);
		    $yor = $yer->diff($yur);
		    $mer = $yor->y;
		    $mur = " (".$mer.")";
			if ($mer > 150) $mur = "";			
			
			
		//Script Selisih Hari
		    $lost = new DateTime();
		    $last = $row["lastcome"];
		    $lest = new DateTime($last);
		    $lust = $lost->diff($lest);
		    $jumlahHari = $lust->days;
			//if ($jumlahHari > 1000) $jumlahHari = "";

		if ($jumlahHari < 1000){
    		$no++;
    		$y = 2;
    		$result1 = fmod($no,$y);
    		if ( $result1 == 0 ) $sty = "dua";
    		if ( $result1 == 1 ) $sty = "satu";
    		?>
    		<tr class=<?php echo $sty; ?>>
    		    <td width="10%" align="center"><a title="Lihat detail pasien"><?php echo $no; ?></a></td>
    			<td width="10%" align="center"><a href="biodata.php?id=<?php echo $row["id"];?>" title="Lihat detail pasien"><?php echo $row["mr"]; ?></a></td>
    			<td width="45%"><a href="biodata.php?id=<?php echo $row["id"];?>" title="Lihat detail pasien"><?php echo $row["name"].$mur; ?></a></td>
    			<td width="10%" align="center"><a href="https://wa.me/<?php echo $row["phone_wa"]; ?>"><?php echo $jumlahHari; ?></a></td>
    			<td width="20%" align="center"><a href="biodata.php?id=<?php echo $row["id"];?>" title="Lihat detail pasien"><?php echo $row["lastcome"]; ?></a></td>
    			<td width="100%" align="center"><a  href="biodata.php?id=<?php echo $row["id"];?>" title="Lihat detail pasien"><?php echo $row["freq"]; ?></a></td>
    		</tr>
    		<?php
        }
    }
} else {
    echo "0 results";
}
?>
		</table>
</body>
</html>
