<?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="Content-Type" content="text/html; charset=utf-8" />
<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_select_db($dbname) or die ("Unable to select database !"); 
mysql_query("SET NAMES utf8"); 
?>
<script language="JavaScript" type="text/javascript" src="wy/scripts/wysiwyg.js"></script>
<script language="JavaScript" type="text/javascript" src="wy/scripts/wysiwyg-settings.js"></script>	

<script language="javascript1.2">
   // attach the editor to all textareas of your page.
   WYSIWYG.attach('all');

</script>
</head>
<body>
<?php
if(isset($_POST['redaguoti'])){
	$kalba=$_POST['kalba'];
	$tema=$_POST['tema'];
	$textas=$_POST['tekstas'];
	$id=$_GET["id"];
			
	$sql = "UPDATE news2 SET kalba='$kalba', tema='$tema', txt='$textas'  WHERE id='$id'";
	$rez = mysql_query($sql) or die(mysql_error());
	echo "<META HTTP-EQUIV=Refresh CONTENT='0; url=news.php?id=".$id."'>";
}
?>
<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 class="turinys2">
				<tr>
					<td class="t1">Naujien&#371; s&#261;ra&#353;as</td>
				</tr>
				<tr>
					<td class="t2" align="center">
						<table id="news"  class="lentele">
						<?php
						$id=$_GET["id"];
						$busena=$_GET["b"];
						if ($id==NULL && $busena==NULL){
						rodyti();
						}else if ($id!=NULL && $busena==NULL){
						redaguoti($id);
						}else if ($id!=NULL && $busena!=NULL){
							$sql = "UPDATE news2 SET busena='$busena' WHERE id='$id'";
							$rez = mysql_query($sql) or die(mysql_error());
							rodyti();
						}						
							function redaguoti($id){
							$uzklausa = "SELECT * FROM news2 where id='$id'";
							$rezultatas = mysql_query($uzklausa) or die(mysql_error());
							$eilute = mysql_fetch_array($rezultatas);
							?>
							<form  action="<? echo $php_self ?>" method="post" enctype="multipart/form-data">
							<?php
							echo "<tr><td><input type='text' name='tema' style='width: 432px' value='".$eilute['tema']."'/></td>";
							if($eilute['kalba']==1){
							echo "<td><input type='radio' name=kalba value='1' checked><img src='images/LT.png'/><input type='radio' name=kalba value='2'><img src='images/EN.png'/></td></tr>";
							}else{
							echo "<td><input type='radio' name=kalba value='1'><img src='images/LT.png'/><input type='radio' name=kalba value='2' checked><img src='images/EN.png'/></td></tr>";
							}
							echo "<tr><td colspan='2'><textarea cols='70' rows='20' name='tekstas' id='text'>".$eilute['txt']."</textarea></td></tr>";
							echo "<tr><td colspan='2' align='right'><input type='submit' name='redaguoti' value='Redaguoti'/></td></tr></form>";
							}
							function rodyti(){
								$uzklausa = "SELECT * FROM news2 WHERE kalba=1 ORDER BY id DESC";
								$rezultatas = mysql_query($uzklausa) or die(mysql_error());
									echo "<tr class='antraste'><td>Naujienos</td><td>B&#363;sena</td></tr>";
								while ($eilute = mysql_fetch_array($rezultatas)){
									echo "<tr><td class='news1'><a href='news.php?id=".$eilute['id']."' class='tema'>".$eilute['tema']."</a></td>";
									if($eilute['busena']==1){
										echo "<td class='news2'><a href='news.php?id=".$eilute['id']."&b=2' class='busena'><img src='images/ok.png' border='0'/></a></td></tr>";
									}else{
										echo "<td class='news2'><a href='news.php?id=".$eilute['id']."&b=1' class='busena'><img src='images/stop.png' border='0'/></a></td></tr>";
									}
								}
							}
						?>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>

</body>
</html>