<?php
	require("./includes/header.php");
	require("./includes/htmLawed.php");
	$config = array('safe'=>1);
?>
<p><form action="chat_post_message.php" method="POST">
	<input type="text" name="message" />
	<input type="hidden" name="xsrftoken_mixed" value="<?=$xsrftoken_mixed?>" />
	<input type="hidden" name="xsrftoken_dynamic" value="<?=$xsrftoken_dynamic?>" />
	<input type="submit" name="submit" value="Изпрати" />
</form></p>
<p>
<?php
	$link = @mysqli_connect("localhost", "mainuser", "gfdagfda", "osup2020");
	if(!$link){
		echo 'Има проблем с базата от данни. Пробвайте по-късно.';
		require("./includes/footer.php");
		exit;
	}
	
	$sql = "SELECT users.user, chatmessages.message
			FROM users
			JOIN chatmessages ON users.id = chatmessages.uid
			ORDER BY chatmessages.dt DESC
			LIMIT 100";
	
	$result = @mysqli_query($link, $sql);
	if(!$result){
		echo 'Има проблем с базата от данни. Пробвайте по-късно.';
		require("./includes/footer.php");
		exit;
	}
	
	while($row = @mysqli_fetch_assoc($result)){
		echo $row['user'].": ".htmLawed($row['message'], $config)."<br />";
	}
	
?>
</p>
<?php
	require("./includes/footer.php");
?>