<?php
	$empty = empty($_POST['username']);
	
	$filename = "stock.txt";
		$file = fopen($filename,"r");
			$readed = fread($file,filesize($filename));
			fclose($file);
		$rearray = explode("\r\n",$readed);

		$stock = $rearray[0];
	
	if ($empty == false) {
		$username = $_POST['username'];
		
		$filename1 = "../../userDB/" . $username . ".txt";
		$file1 = fopen($filename1,"r");
			$readed1 = fread($file1,filesize($filename1));
			fclose($file1);
		$rearray1 = explode("\r\n",$readed1);

		$a0 = $rearray[0];
		
		$money = $rearray1[1];
	}
	else {
		$username = "<b>PLEASE LOGIN</b>";
		$money = "<b>PLEASE LOGIN</b>";
	}
?>


<!DOCTYPE HTML>
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>CShop - Anak Cerdas 22 Bundle</title>
	</head>
	<body>
		<style>
			.p-name {
				font-family: Arial;
				font-size: 18px;
			}
			.homef {
				width: 75%;
			}
			.diss {
				width: 73%;
			}
			.comment {
				background: #e6e7ed;
			}
			.red {
				color: red;
			}
			.bad-cmt {
				color: gray;
			}
		</style>
	
		<!-- User Desc -->
	
		<img src="../../pictureDB/buku-kokbisa.jpg" width="200px">
		<p>
			<span class="p-name"><b>Anak cerdas 22 + Buku Kog bisa</b></span><br>
			Stok: <?php echo $stock ?><br>
			harga: MBC. 400000<br>
			<br>
			Deskripsi:<br>
			<br>
			Dengan paket bundle ini maka si cerdas 22 anda akan menjadi lebih semangat dalam<br>
			memberikan benefit sebanyak banyaknya, dapatkan benefitnya sekarang juga dengan melakukan pembelian item ini!<br>
			<br>
			<span class="red"><b>Cantumkan No Telepon di kolom "Home adress"</b></span>
		</p>
		
		<!-- user purchase dialog -->
		
		<p>
			Halo <?php echo $username ?> ! Sisa saldo anda: MBC. <?php echo $money ?><br>
			Apakah anda yakin ingin melakukan pembelian produk ini?
		</p>
		
		<form action="buy.php" method="POST">
			<input type="hidden" name="username" value="<?php echo $username ?>">
			
			<label for="userHome">Your home adress: </label>
			<input type="text" name="userHome" id="userHome" placeholder="Indonesia/JawaBarat/Bandung/" class="homef"><br>
			
			<label for="userRequest">Request message: </label>
			<input type="text" name="userRequest" id="userRequest" placeholder="Yang warna merah yaa..." class="diss"><br>
			
			<label for="userPW">Input Password:</label>
			<input type="password" name="userPW" id="userPW">
			<input type="submit" value="Yes, Purchase it">
		</form>
		
		<p><b>User Discussion:</b></p>
			<form method="POST" action="discuss.php">
				<input type="hidden" name="username" value="<?php echo $username ?>">
				<input type="text" name="discuss" placeholder="Your message here..." class="diss" autocomplete="off">
				
				<input type="Submit" value="Send!">
			</form>
		
		<p class="comment">
			<?php
				$filename = fopen("discussion.txt", "r") or die("Unable to open file!");

				// Output one line until end-of-file
				while(!feof($filename)) {
				  echo fgets($filename) . "<br>";
				}
				fclose($filename);
			?>
		</p>
		
		<script>
			
		</script>
	</body>
</html>