<?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')");
//-------------
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//ID" "http://www.w3.org/TR/html4/frameset.dtd">
<html lang="id">
<head>
	<title>LACAK PASIEN</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;
		}	
		
    </style>	
</head>

<body>

<?php 
$cari ='';
if(isset($_GET['cari'])){
	$cari = $_GET['cari'];
}
?>

<table width="100%" cellpadding="5">
	<tr class="dua">
		<td colspan="5" style="padding-top : 15px;">
			<form action="index.php" method="get">
				<input type="text" name="cari" size="15" maxlength="15">
				<input type="submit" value="Search">
				<label style = "color:#601500;"></br><?php echo "<b>Keyword : ".$cari."</b>" ?></label>
			</form>
		</td>
		<td colspan="2"><a href="biodata-new.php" title="Masukkan data pasien baru ke database"><button style="padding : 10px; width:100%"> INPUT PASIEN BARU </button></a></td>
		<td colspan="3"><a href="visit-monthly.php?tanggal=<?php echo date("Y-m-d");?>" title="Lihat Pasien Bulan ini"><button style="padding : 10px; width:100%">PASIEN BULAN INI</button></a></td>
		<td colspan="3"><a href="visit-daily.php?tanggal=<?php echo date("Y-m-d")?>" title="Lihat Pasien Hari ini"><button style="padding : 10px; width:100%"> PASIEN HARI INI </button></a></td>
	</tr>
	<tr class="head">
		<th width="44">MR</th>
		<th width="150">Nama</th>
		<th width="30">F20</th>
		<th width="100">Phone 1</th>
		<th width="100">Phone 2</th>
		<th>Alamat</th>
		<th width="110">Kelurahan</th>
		<th width="110">Kecamatan</th>
		<th width="110">Kota</th>
		<th width="110">Propinsi</th>
		<th width="110">Zip</th>
		<th width="75">Datang</th>
		<th width="75">Birthday</th>
		<th width="44">View</th>
		<th width="44">Edit</th>
	</tr>

<?php 
$no = 1;
$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 mr DESC LIMIT 0, 100";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
		$no++;
		$y = 2;
		$result1 = fmod($no,$y);
		if ( $result1 == 0 ) $sty = "dua";
		if ( $result1 == 1 ) $sty = "satu";
		
		//Script Umur
			$sa = date("Y");
			$si = $row["birthday"];
			$dti = new DateTime($si);
			$currdate_ = $dti->format('Y');
			$umur = $sa-$currdate_;
			if ($umur > 150) $umur1 = "";
			if ($umur < 150) $umur1 =  " (".$umur.")";
		//--------
		
		?>
		<tr class=<?php echo $sty; ?>>
			<td width="44" align="center"><a href="biodata.php?id=<?php echo $row["id"];?>" title="Lihat detail pasien"><?php echo $row["mr"]; ?></a></td>
			<td width="150"><a href="biodata.php?id=<?php echo $row["id"];?>" title="Lihat detail pasien"><?php echo $row["name"].$umur1; ?></a></td>
			<td width="30" align="center"><a  href="biodata.php?id=<?php echo $row["id"];?>" title="Lihat detail pasien"><?php echo $row["freq"]; ?></a></td>
			<td width="100"><a href="https://wa.me/<?php echo $row["phone_wa"]; ?>"><?php echo $row["phone_wa"]; ?></a></td>
			<td width="100"><a href="biodata.php?id=<?php echo $row["id"];?>" title="Lihat detail pasien"><?php echo $row["phone_home"]; ?></a></td>
			<td><a href="biodata.php?id=<?php echo $row["id"];?>" title="Lihat detail pasien"><?php echo $row["street_address"]; ?></a></td>
			<td width="110"><a href="biodata.php?id=<?php echo $row["id"];?>" title="Lihat detail pasien"><?php echo $row["kelurahan"]; ?></a></td>
			<td width="110"><a href="biodata.php?id=<?php echo $row["id"];?>" title="Lihat detail pasien"><?php echo $row["kecamatan"]; ?></a></td>
			<td width="110"><a href="biodata.php?id=<?php echo $row["id"];?>" title="Lihat detail pasien"><?php echo $row["city"]; ?></a></td>
			<td width="110"><a href="biodata.php?id=<?php echo $row["id"];?>" title="Lihat detail pasien"><?php echo $row["state"]; ?></a></td>
			<td width="110"><a href="biodata.php?id=<?php echo $row["id"];?>" title="Lihat detail pasien"><?php echo $row["kode_pos"]; ?></a></td>
			<td width="75"><a href="biodata.php?id=<?php echo $row["id"];?>" title="Lihat detail pasien"><?php echo $row["firstcome"]; ?></a></td>
			<td width="75"><a href="biodata.php?id=<?php echo $row["id"];?>" title="Lihat detail pasien"><?php echo $row["birthday"]; ?></a></td>
			<td width="44"><a href="biodata.php?id=<?php echo $row["id"];?>" title="Lihat detail pasien"><button>View</button></a></td>
			<td width="44"><a href="biodata_edit.php?id=<?php echo $row["id"];?>" title="Lihat detail pasien"><button>Edit</button></a></td>
		</tr>
		<?php
    }
} else {
    echo "0 results";
}
?>
</body>
</html>
