<?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>
<title>Administratoriaus prisijungimas</title>
<link href="stilius.css" rel="stylesheet" type="text/css" />
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<?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"); 
?>
</head>
<body>
<?php
if(isset($_POST['submit'])){
	$metai=$_POST['metai'];
	$menuo=$_POST['menuo'];
	$diena=$_POST['diena'];
	$koncertas=$_POST['koncertas'];
	
	$uzklausa = "INSERT INTO koncertai (busena, kalba, metai, menuo, diena, koncertas) VALUES ('1', '2', '$metai', '$menuo', '$diena', '$koncertas')";
	$rezultatas = mysql_query($uzklausa) or die(mysql_error());
	echo "<meta http-equiv='refresh' content='0; url=koncertai-en.php'/>";
}
if(isset($_POST['redaguoti'])){
	$metai=$_POST['metai2'];
	$menuo=$_POST['menuo2'];
	$diena=$_POST['diena2'];
	$koncertas=$_POST['koncertas2'];
	$id=$_POST['id2'];
	
	$uzklausa = "UPDATE koncertai SET metai='$metai', menuo='$menuo', diena='$diena', koncertas='$koncertas' WHERE id='$id'";
	$rezultatas = mysql_query($uzklausa) or die(mysql_error());
	echo "<meta http-equiv='refresh' content='0; url=koncertai-en.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">Koncert&#371; s&#261;ra&#353;as angli&#353;kai</td>
				</tr>
								<tr>
					<td>
						<form  action="<? echo $php_self ?>" method="post" enctype="multipart/form-data">
						<table class="lentele">
						<?php
						echo "<tr><td colspan='5'>&#303;terpti nauj&#261; koncert&#261;:</td></tr><tr><td>";
						echo "<select name='metai' style='width:70px;'><option value='2011'>2011</option><option value='2012'>2012</option><option value='2013'>2013</option><option value='2014'>2014</option><option value='2015'>2015</option><option value='2016'>2016</option><option value='2017'>2017</option><option value='2018'>2018</option><option value='2019'>2019</option><option value='2020'>2020</option></select>";
						echo "</td><td><select name='menuo' style='width:50px;'><option value='01'>01</option><option value='02'>02</option><option value='03'>03</option><option value='04'>04</option><option value='05'>05</option><option value='06'>06</option><option value='07'>07</option><option value='08'>08</option><option value='09'>09</option><option value='10'>10</option><option value='11'>11</option><option value='12'>12</option></select>";
						echo "</td><td><select name='diena' style='width:50px;'><option value='01'>01</option><option value='02'>02</option><option value='03'>03</option><option value='04'>04</option><option value='05'>05</option><option value='06'>06</option><option value='07'>07</option><option value='08'>08</option><option value='09'>09</option><option value='10'>10</option><option value='11'>11</option><option value='12'>12</option><option value='13'>13</option><option value='14'>14</option><option value='15'>15</option><option value='16'>16</option><option value='17'>17</option><option value='18'>18</option><option value='19'>19</option><option value='20'>20</option><option value='21'>21</option><option value='22'>22</option><option value='23'>23</option><option value='24'>24</option><option value='25'>25</option><option value='26'>26</option><option value='27'>27</option><option value='28'>28</option><option value='29'>29</option><option value='30'>30</option><option value='31'>31</option></select></td><td><input style='width: 500px' type='text' name='koncertas' />";
						echo "</td><td><input type='Submit' name='submit' value='&#303;terpti' style='width:100px;' /></td></tr>";
						?>
							
						</table>
						</form>
					</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){
						busena ($busena, $id);

						
						}
						
						function busena ($busena, $id){
							$sql = "UPDATE koncertai SET busena='$busena' WHERE id='$id'";
							$rez = mysql_query($sql) or die(mysql_error());
							rodyti();
						}
						function redaguoti($id){
							$uzklausa = "SELECT * FROM koncertai 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 colspan='5'>Redaguoti koncert&#261;:</tr></td>";
							echo "<tr><td><input type='hidden' name='id2' value='".$eilute['id']."'/><input type='text' name='metai2' style='width: 70px' value='".$eilute['metai']."'/></td>";
							echo "<td><input type='text' name='menuo2' style='width: 50px' value='".$eilute['menuo']."'/></td>";
							echo "<td><input type='text' name='diena2' style='width: 50px' value='".$eilute['diena']."'/></td>";
							echo "<td><input type='text' name='koncertas2' style='width: 500px' value='".$eilute['koncertas']."'/></td>";
							echo "<td><input type='Submit' name='redaguoti' value='Redaguoti' style='width:100px;' /></td></tr>";

						}

							function rodyti(){
								$uzklausa = "SELECT * FROM koncertai WHERE kalba=2 ORDER BY metai DESC, menuo DESC, diena DESC";
								$rezultatas = mysql_query($uzklausa) or die(mysql_error());
									echo "<tr class='antraste'><td width='100px'>Data</td><td>Koncertai</td><td>B&#363;sena</td></tr>";
								while ($eilute = mysql_fetch_array($rezultatas)){
									echo "<tr><td>".$eilute['metai']."-".$eilute['menuo']."-".$eilute['diena']."</td><td class='news1'><a href='koncertai.php?id=".$eilute['id']."'>".$eilute['koncertas']."</a></td>";
									if($eilute['busena']==1){
										echo "<td class='news2'><a href='koncertai.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='koncertai.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>