<?php require("check.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<title>Administratoriaus prisijungimas</title>
<link href="stilius.css" rel="stylesheet" type="text/css" />

<?php
	require("configas.php");
	global $dbhost, $dbuname, $dbpass, $dbname; 
	mysql_connect($dbhost, $dbuname, $dbpass); 

	mysql_query("SET NAMES utf8");
	@mysql_select_db($dbname) or die ("Unable to select database !"); 
?>
</head>
<body>
<?php
if(isset($_POST['Submit'])){
	$vardas=$_POST['vardas'];
	$email=$_POST['email'];
	$txt=$_POST['txt'];
	$id=$_POST['id'];
	
	$uzklausa = "UPDATE atsiliepimai SET vardas='$vardas', email='$email', txt='$txt' WHERE id='$id'";
	$rezultatas = mysql_query($uzklausa) or die(mysql_error());
	echo "<meta http-equiv='refresh' content='0; url=atsiliepimai.php'/>";
}
?>
<table id="pagr" align="center">
	<tr valign="top">
		<td class="meniu">
			<table class="meniu2" width="200px">
				<?php require("meniu.php"); ?>
			</table>			
		</td>
		<td class="turinys">
			<table border="0" class="turinys2">
				<tr>
					<td class="t1">Fan&#371; u&#382;klausos</td>
				</tr>
				<tr>
					<td class="t2" align="center">
					<?php
					$id=$_GET["id"];
					if ($id==NULL){
					rodyti();
					}else{
					$sql = "DELETE FROM fanai WHERE id='$id'";
					$rez = mysql_query($sql) or die(mysql_error());
					rodyti();
					}
					
					function rodyti(){
					$sql = "SELECT * FROM fanai ORDER BY id DESC";
					$rez = mysql_query($sql) or die(mysql_error());
					while ($row = mysql_fetch_array($rez)){
						echo "<table class='lentele' border='0'><tr><td class='ats'>";
						echo "<tr><td>".$row['vardas']."</td><td>".$row['pavarde']."</td></tr><tr><td>".$row['miestas']."</td><td>".$row['tel']."</td></tr><tr><td><a href='mailto:".$row['email']."'>".$row['email']."</a></td></tr><tr><td colspan='2'>".$row['comment']."</td></tr><tr><td><a href='fanai.php?id=".$row['id']."' class='busena'><img src='images/stop.png' border='0'/></a></td></tr>";
						
						}
					}				
					?>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>

</body>
</html>