<?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">Lankytoj&#371; atsiliepimai</td>
				</tr>
				<tr>
					<td class="t2" align="center">
					<?php
					$id=$_GET["id"];
					$funk=$_GET["funk"];
					if ($id==NULL){
					rodyti();
					}else if ($id!=NULL && $funk==1){
					$sql = "DELETE FROM atsiliepimai WHERE id='$id'";
					$rez = mysql_query($sql) or die(mysql_error());
					rodyti();
					}else if ($id!=NULL && $funk==2){
					redaguoti($id);
					}
					
					function rodyti(){
					$sql = "SELECT * FROM atsiliepimai 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 $row['vardas']."</td><td class='ats'>".$row['email']."</td><td></td><td rowspan='2' valign='top' class='ats3'><a href='atsiliepimai.php?id=".$row['id']."&funk=1' class='busena'><img src='images/stop.png' border='0'/></a></td></tr>";
						echo "<tr><td colspan='4' class='ats2'><a href='atsiliepimai.php?id=".$row['id']."&funk=2 '>".$row['txt']."</a>";
						echo "</td></tr></table>";
						}
					}	

					function redaguoti($id){
							$uzklausa = "SELECT * FROM atsiliepimai where id='$id'";
							$rezultatas = mysql_query($uzklausa) or die(mysql_error());
							$eilute = mysql_fetch_array($rezultatas); 
							?>
							
							<form  action="<?php echo $php_self ?>" method="post" enctype="multipart/form-data">
							<?php
							echo "<table border='0' cellspacing='0' cellpadding='0' class='lentele'><tr><td width='70' align='right'>Vardas:</td><td colspan='3'>";
							echo "<input type='hidden' name='id' value='".$eilute['id']."'/><input name='vardas' type='text' style='width: 300px' maxlength='12' value='".$eilute['vardas']."'/></td></tr><td align='right'>El. pa&scaron;tas:</td><td colspan='3'>";
							echo "<input name='email' type='text' style='width: 300px' maxlength='28' value='".$eilute['email']."'/></td></tr><tr><td>&nbsp;</td><td colspan='3'>";
							echo "<textarea name='txt' rows='10' cols='35' maxlength='200'>".$eilute['txt']."</textarea></td></tr><tr><td>&nbsp;</td><td width='100px'>&nbsp;</td>";
							echo "<td align='right'><input name='Submit' type='submit' class='button' value='Si&#371;sti' /></td></tr></table></form>";

						}					
					?>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>

</body>
</html>