<?php
	header("Content-Security-Policy: script-src 'none'; img-src *");
	require("./includes/header.php");
?>
<p id="profileArea">Изберете профил<br /><br />
<?php
	$link = @mysqli_connect("localhost", "mainuser", "gfdagfda", "osup2020");
	if(!$link){
		echo 'Има проблем с базата от данни. Пробвайте по-късно.';
		require("./includes/footer.php");
		exit;
	}
	$sql = "SELECT user FROM users ORDER BY user";
	$result = @mysqli_query($link, $sql);
	$i = 0;
	while($row = @mysqli_fetch_assoc($result)){
		echo '<a href="profile.php?num='.$i.'" class="profile">'.$row['user'].'</a><br />';
		$i++;
	}
?></p>
<script>
	var currentSearch = document.location.search;
	var searchParams = new URLSearchParams(currentSearch);
	var profiles = document.getElementsByClassName('profile');
	var index = searchParams.get('num').toString();
	
	var user;
	eval("user=profiles["+index+"]");
	
	if(user != null){
		document.getElementById('profileArea').innerHTML = 'Профилът на '+user.innerHTML+'!';
	}
	

</script>
<?php
	require("./includes/footer.php");
?>