<html>

<script type="text/javascript">
    
	function show(id){
	
		window.location.href = "http://127.0.0.1/booking/booklist.php?id=" + id;
	}
	function newuser(){
	
		window.location.href = "http://127.0.0.1/booking/booklist.php";
	}
	
	function del(id){
	
		window.location.href = "http://127.0.0.1/booking/del_booklist.php?id=" + id;
	}
	
</script>
<form action='manage_booklist.php' method="post">
<?
	$conn = new mysqli('localhost', 'root', 'tester123','book_store');
	if ($conn->connect_error) {
		die("Connection failed: " . $conn->connect_error);
	}else{
		//echo "ok";
	}
	$sql = "select * from booklist";	
	$result = $conn->query($sql);		
	
	$cmd = $_GET['cmd'];
	$id = $_GET['id'];
	
	$txt_barcode='';
	$s_name='';
	$f_name='';
	$l_name='';
	
	
	if($id != ''){
		$sql_edit = "select * from booklist where barcode='".$id."'";	
		$resultedit = $conn->query($sql_edit);
		if ($result->num_rows > 0) {
			while($rowedit = $resultedit->fetch_assoc()) {
				$barcode= $rowedit['barcode'];
				$callno=$rowedit['callno'];
				$title=$rowedit['title'];
				$status=$rowedit['status'];
				$author=$rowedit['author'];
				$count=$rowedit['count'];

			}
		}
	}
		
?>

<h3>Manage Patrons Page</h3>
<table width ='60%' align='center' >
	<tr>
		<td width='20%' >Barcode</td>
		<td>
		<input type='text' name='txt_barcode' id='txt_barcode' value='<?=$barcode?>'disabled>
		<input type='hidden' name='h_barcode' id='h_barcode' value='<?=$barcode?>'>
		
		</td>
	</tr>
	<tr>
		<td>callno</td>
		<td><input type='text' name='callno' id='callno' value='<?=$callno?>'required></td>
	</tr>
	<tr>
		<td>author</td>
		<td><input type='text' name='title' id='title' value='<?=$title?>'required></td>
	</tr>
	<tr>
		<td>status</td>
		<td><input type='text' name='status' id='status' value='<?=$status?>'required></td>
	</tr><tr>
		<td>count</td>
		<td><input type='text' name='count' id='count' value='<?=$count?>'required></td>
	</tr>
	<tr>
	<td></td>
		<td>
			<input type='submit'>
			<input type='button' value='New' onclick="newuser();">
		</td>
		
	</tr>
</table>
<br/>
<br/>
<br/>


<table width ='80%' border='1'  align='center'>
<tr>
	<td>Barcode</td>
	<td>callno</td>
	<td>title</td>
	<td>author</td>
	<td>status</td>
	<td>count</td>
</tr>


<?
if ($result->num_rows > 0) {
		while($row = $result->fetch_assoc()) {
			$txt_p_barcode = $row['barcode'];
			echo "<tr><td>".$row['barcode']."</td>";
			echo "<td>".$row['title']."</td>";
			echo "<td>".$row['author']."</td>";
			echo "<td>".$row['status']."</td>";
			echo "<td>".$row['status']."</td>
			
			<td>";
			
			?>
				<input type='button' value='ลบ' onclick="del('<?=$txt_p_barcode;?>');">
				
				<input type="button" value="แก้ไข" onclick="show('<?=$txt_p_barcode;?>');">	
				<?
				
			echo "</td>
		<tr>";
		}	
	}


?>
	
	
</tr>
</table>


</form>



</html>