<?php
	session_name('library');
	session_start();
	
	include("functions.php");

	head('Remove Book - Management Section');
?>

<body>
<div id="main">

	<?php
		include("header.php");
		include("menu.php");
	?>

<div id="entire_panel">
		<h1>Zmaž publikáciu</h1>
		
<?php
if ($_SESSION['admin'] == 1) {			 
	if(isset($_POST['submit'])) {
	
		$link = connect_db();
		
		$sql = "DELETE FROM users WHERE uid='" . $_SESSION['user_deleted'] . "'";
		$result = mysql_query($sql) or die(mysql_error());
		
		echo '<p id="bold">The user was deleted successfully.</p>';
	 
	} else {
	
		$link = connect_db();
		
		$user_id = $_GET['id'];
		protect($user_id);
		$_SESSION['user_deleted'] = $user_id;
		
		$sql = "SELECT * FROM users WHERE uid='" . $user_id . "'";
		$result = mysql_query($sql, $link) or die(mysql_error());
		$row = mysql_fetch_assoc($result);
		
		if((!$user_id) || (!is_numeric($user_id))) {
			echo 'Mazanie používateľa nebola zadávané korektným spôsobom.';
		}
	
		if(empty($msg)){
			echo '<h4>Praješ si skutočne vymazať nasledovného používateľa? </h4>';
			echo '<table border="1" class="center_page">';
			echo '<tr><th>USERNAME</th><td id="bold">' . $row['name'] . '</td></tr>';
			echo '<tr><th>MENO A PRIEZVISKO</th><td id="bold">' . $row['name'] . ' ' . $row['surname'] . '</td></tr>';
			echo '<tr><th>EMAIL</th><td id="bold">' . $row['email'] . '</td></tr>';
			echo '<tr><th>DÁTUM REGISTRÁCIE</th><td id="bold">' . $row['date_registered'] . '</td></tr>';
			echo '<tr><th colspan=2 class="button">'; 
			?>
			
			<form name=register method=post action="remove_order.php">
				<input name="submit" type="submit" id="submit" value="Zmaž">
			</form>
			
			<?php
			echo '</th></tr>';
			echo '</table>';
			
			
			$msg="";
		} else {
			echo '<p id="red">' . $msg . '</p>';
		}
		
		mysql_free_result($result);
		
		mysql_close($link);
		
	}
	
} else {
	echo '<p id="red">Na modifikáciu používateľov nemáte dostatočné právomoci.</p>';
}   
		?>				
</div>

	<?php include("footer.php"); ?>

</div>
</body>
</html>



