<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
	<title>moto</title>
	<style type="text/css">.star {color: red; font-weight: bold;}</style>
</head>
<body>	

	<?php echo $today = date("g:i a, j. F Y"); ?>
	<br /><br />

	<FORM METHOD="POST" ACTION="ldap.php"> 
		<h3>LDAP</h3>
		Zadejte údaje:<BR>
		<!-- <INPUT TYPE="hidden" NAME="server">
		  type in the search base: 
		  <INPUT TYPE="text" NAME="login">
		  <INPUT TYPE="password" NAME="heslo">
		   type in part of their surname:-->
		  <table border=0>
		  <tr><td>Login:</td><td><INPUT TYPE="text" NAME="login"> </td></tr>
		  <tr><td>Heslo:</td><td><INPUT TYPE="password" NAME="heslo"> </td></tr>
		  <tr><td></td><td><INPUT TYPE="submit" VALUE="Hledat"> </td></tr>
		  
		  </table>
	</FORM>	
	
	<?php

		$navigace = $_GET['nav'];
		switch ($navigace) {
		  case "":
	?>
	
	
	
	<?php
	  break;
	  case "edit":
		include("./mysql.php");
		$what = $_GET["what"];
		$vyber = mysql_query("SELECT * FROM ".$tabulka." WHERE ID = ".$what);
		$pole = mysql_fetch_array($vyber);
		mysql_close($spojeni);
	?>
		
	<form action="index.php?nav=replace" method="post">
		<p><b>ZNAČKA<span class="star">*</span></b></p>
			<input type="hidden" name="ID" value="<? echo($pole["ID"])?>" />		
			<input type="text" name="ZNACKA" value="<? echo($pole["ZNACKA"])?>" />
				
		<p><b>TYP<span class="star">*</span></b></p>
			<input type="text" name="TYP" value="<? echo($pole["TYP"])?>" />
					
		<p><b>ROK VÝROBY<span class="star">*</span></b></p>
			<input type="text" name="ROK_VYROBY" value="<? echo($pole["ROK_VYROBY"])?>" />

		<p><b>CENA<span class="star">*</span></b></p>
			<input type="text" name="CENA" value="<? echo($pole["CENA"])?>"  />
		
		<br />
		<br />
			<input type="submit" value="Odeslat"/>
				
	</form>


	<?php  
	  break;
	  case "show":
		include("./mysql.php");
		$vyber=mysql_query("SELECT * FROM ".$tabulka);
	?>  
	
	<script>
	var newrec = "<a href=\"index2.php\">vložit nový záznam</a>";
	document.write(newrec);
	</script>
	
	<table align="center", width="800", border="3">
		 <tr bgcolor="#800000"><font color="white"><th>ID</th><th>ZNAČKA</th><th>TYP</th><th>ROK VÝROBY</th><th>CENA</th></font></tr>
	
	<?php  
		while ($pole=mysql_fetch_array($vyber)) {
	?>  
	
	<tr><td><? echo($pole["ID"]); ?></td><td><? echo($pole["ZNACKA"]); ?></td><td><? echo($pole["TYP"]); ?></td><td><? echo($pole["ROK_VYROBY"]); ?></td><td><? echo($pole["CENA"]); ?></td>
		<td><a href="./index.php?nav=edit&what=<?php echo($pole["ID"]); ?>"><img src="obr/edit.png" alt="upravit"></a></td>
		<td><a href="./index.php?nav=rem&what=<?php echo($pole["ID"]); ?>"><img src="obr/delete.png" alt="delete"></a></td>
	</tr>
	 
	<?php  }
		mysql_close($spojeni);
	  break;
	  case "add":
		include("./mysql.php");
		$chyba = "Chyba formuláře:<br />";
		$err = false;
		$ZNACKA =  $_POST['ZNACKA'];
		if ($ZNACKA == "") {$chyba .= "ZNAČKA \n";
		  $err = true;}
		$TYP = $_POST['TYP'];
		if ($TYP == "") {$chyba .= "TYP \n";
		  $err = true;}
		$ROK_VYROBY = $_POST['ROK_VYROBY'];
		if ($ROK_VYROBY == "") {$chyba .= "ROK VÝROBY \n";
		  $err = true;}
		$CENA = $_POST['CENA'];
		if ($CENA == "") {$chyba .= "CENA \n";
		  $err = true;}
		else {mysql_query("INSERT INTO ".$tabulka." (ZNACKA, TYP, ROK_VYROBY, CENA) VALUES ('".$ZNACKA."', '".$TYP."', '".$ROK_VYROBY."', '".$CENA."')") or die("Chyba SQL ".mysql_error());}
		mysql_close($spojeni);
		
		if ($err == true) 
	
		{ 
	?>
	
	</table>
	
	  <form action="index.php?nav=add" method="post">
		<h3><font color="red">Doplňte prosím chybějící údaje!</font></h3>
		<p><b>ZNAČKA<span class="star">*</span></b></p><input type="text" name="ZNACKA" value="<? echo($ZNACKA)?>" />
		<p><b>TYP<span class="star">*</span></b></p><input type="text" name="TYP" value="<? echo($TYP)?>" />
		<p><b>ROK VÝROBY<span class="star">*</span></b></p><input type="text" name="ROK_VYROBY" value="<? echo($ROK_VYROBY)?>" />
		<p><b>CENA<span class="star">*</span></b></p><input type="text" name="CENA" value="<? echo($CENA)?>" />
		<br />
		<br />
		<input type="submit" value="Odeslat" />
	  </form>
	  
	<?php 	} 
		elseif ($err == false) {
	?>
		<h3><font color="red">Záznam byl úspěšně vložen!</font></h3>         
		<p><b>ZNAČKA:    </b><?php echo($_POST['ZNACKA'])?></p>
		<p><b>TYP:    </b><?php echo($_POST['TYP']);?></p>
		<p><b>ROK VÝROBY:    </b><?php echo($_POST['ROK_VYROBY']);?></p>
		<p><b>CENA:    </b><?php echo($_POST['CENA']); ?></p>
		
	<p><a href="./index.php?nav=show">zobrazit všechny záznamy</a></p>
	
	<script>
	var newrec = "<a href=\"index2.php\">vložit nový záznam</a>";
	document.write(newrec);
	</script>	
	
	<?php }
	  break;
	  case "replace":
		include("./mysql.php");
		$chyba = "Chyba formuláře:<br />";
		$err = false;
		$ID = $_POST['ID'];
		if ($ID == "") {$chyba .= "jednoznačný identifikátor \n";
		  $err = true;}
		$ZNACKA =  $_POST['ZNACKA'];
		if ($ZNACKA == "") {$chyba .= "ZNAČKA \n";
		  $err = true;}
		$TYP = $_POST['TYP'];
		if ($TYP == "") {$chyba .= "TYP \n";
		  $err = true;}
		$ROK_VYROBY = $_POST['ROK_VYROBY'];
		if ($ROK_VYROBY == "") {$chyba .= "ROK VÝROBY \n";
		  $err = true;}
		$CENA = $_POST['CENA'];
		if ($CENA == "") {$chyba .= "CENA \n";
		  $err = true;}
	
		else {mysql_query("UPDATE ".$tabulka." SET ZNACKA = '".$ZNACKA."', TYP = '".$TYP."', ROK_VYROBY = '".$ROK_VYROBY."', CENA = '".$CENA."' WHERE ID = '".$ID."' LIMIT 1") or die("Chyba SQL ".mysql_error());}
		
		mysql_close($spojeni);
		if ($err == true) { ?>
	  <form action="index.php?nav=replace" method="post">
		<h3><font color="red">Doplňte prosím chybějící údaje!</font></h3><input type="hidden" name="ID" value="<? echo($ID)?>" />
		<p><b>ZNAČKA<span class="star">*</span></b></p><input type="text" name="ZNACKA" value="<? echo($ZNACKA)?>" />
		<p><b>TYP<span class="star">*</span></b></p><input type="text" name="TYP" value="<? echo($TYP)?>" />
		<p><b>ROK VÝROBY<span class="star">*</span></b></p><input type="text" name="ROK_VYROBY" value="<? echo($ROK_VYROBY)?>" />
		<p><b>CENA<span class="star">*</span></b></p><input type="text" name="CENA" value="<? echo($CENA)?>" />
		<br />
		<br />
		<input type="submit" value="Odeslat" />
	  </form>
	  
	<?php } elseif ($err == false) {
	?>
	
	  <h3><font color="red">Upravený záznam!</font></h3>               
		<p><b>ZNAČKA:    </b><?php echo($_POST['ZNACKA'])?></p>
		<p><b>TYP:    </b><?php echo($_POST['TYP'])?></p>
		<p><b>ROK VÝROBY:    </b><?php echo($_POST['ROK_VYROBY'])?></p>
		<p><b>CENA:    </b><?php echo($_POST['CENA'])?></p>
		<input type="button" onClick="parent.location='index.php?nav=show'" value='Zpět' />
	<?php }
	  break;
	  case "rem":
		$confirm = $_POST["confirm"];
		$ID = $_GET['what'];
		if ($confirm == "") {
		  include("./mysql.php");
		  $vyber = mysql_query("SELECT * FROM ".$tabulka." WHERE ID = ".$ID);
		  $pole = mysql_fetch_array($vyber);
		  mysql_close($spojeni);
	?>  
	
		<form action="index.php?nav=rem&what=<? echo($ID)?>" method="post">
		<h3><font color="red">Opravdu si přejete odstranit následující záznam?</font></h3>
		<p><b>ZNAČKA:    </b><?php echo($pole['ZNACKA'])?></p>
		<p><b>TYP:    </b><?php echo($pole['TYP'])?></p>
		<p><b>ROK VÝROBY:    </b><?php echo($pole['ROK_VYROBY'])?></p>
		<p><b>CENA:    </b><?php echo($pole['CENA'])?></p>
			<input type="hidden" name="confirm" value="remove" />
			<input type="submit" value="Ano" />
			<input type="button" onClick="parent.location='index.php?nav=show'" value='Ne' />
		</form>  

	<?php  }
		elseif ($confirm == "remove") {
		  include("./mysql.php");
		  $chyba = "Chyba:<br />";
		  $err = false;
		  if ($ID == "") {$chyba .= "jednoznačný identifikátor \n";
			$err = true;}
		  if ($err == true) echo($chyba." nebyl předán.");
		  else {mysql_query("DELETE FROM ".$tabulka." WHERE ID = '".$ID."' LIMIT 1") or die("Chyba SQL ".mysql_error());}
		  mysql_close($spojeni); ?>
		  <h3><font color="red">Úspěšně smazáno!</font></h3>
		<input type="button" onClick="parent.location='index.php?nav=show'" value='Zpět' />
	
	<?php  }
	  break;
	}
	?>

</body>
</html>