<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Web management</title>
<link rel="stylesheet" href="styles.css" type="text/css">
<?php include 'codes.php';?>
</head>
<body>
<?php 
$id = mysql_real_escape_string(stripslashes($_REQUEST['id']));
$language = mysql_real_escape_string(stripslashes($_REQUEST['language']));
$dir = mysql_real_escape_string(stripslashes($_REQUEST['dir']));
$active = mysql_real_escape_string(stripslashes($_REQUEST['active']));
$main = mysql_real_escape_string(stripslashes($_REQUEST['main']));
			
if  (isset($_POST['submit'])) {
			$sql1 = "SELECT * FROM lang WHERE dir='$dir' AND id!='$id'";
			$result1= mysql_query($sql1);
			$nu_row = mysql_num_rows($result1);
?>
  <?php 
	if  ($nu_row==0) {
	?>
<?php 
			$sql = "UPDATE lang SET language='$language', dir='$dir', active='$active', main='$main' WHERE id='$id'";
			$result = mysql_query($sql);
			if  ($main==1) {
			$sql2 = "UPDATE lang SET main=0 WHERE id!='$id'";
			$result2 = mysql_query($sql2);
			}
			$sql3 = "UPDATE lang SET active=1 WHERE main=1";
			$result3 = mysql_query($sql3);
?>
<meta http-equiv="refresh" content="0;URL=all-lang.php">
<?php } else {?>
<div align="center"> Αυτό  υπάρχει ήδη στην λίστα. </div><?php } ?>
<?php
} else {	
			$result = mysql_query("SELECT * FROM lang WHERE id='$id'",$dbh);
			$myrow=mysql_fetch_array($result); 
			$id=$myrow['id'];
			$language=$myrow['language'];
			$dir=$myrow['dir'];
			$active=$myrow['active'];
			$main=$myrow['main'];
?>

<table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><div><img src="img/frame-edit.png" width="180" height="37" alt=""></div>
<div class="frame">

<form name="forma" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" enctype="multipart/form-data">
  <input type="hidden" name="id" value="<?php echo $id ?>">
  <table width="100%" border="0" cellspacing="0" cellpadding="4">
    <tr>
      <td width="20">&nbsp;</td>
      <td>Γλώσσα*</td> 
      <td><input type="text" name="language" maxlength="30" size="40" value="<?php echo $language ?>" class="forms"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>Directory*</td> 
      <td><input type="text" name="dir" class="forms" size="12" value="<?php echo $dir ?>" maxlength="6"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>Active</td>
      <td>
      <select name="active" class="forms">
<option value="0">0 no</option>
<option value="1">1 yes</option>
<option value="<?php echo $active ?>" selected><?php echo $active ?></option>
</select>
      </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>Default</td>
      <td>
      <select name="main" class="forms">
<option value="0">0 no</option>
<option value="1">1 yes</option>
<option value="<?php echo $main ?>" selected><?php echo $main ?></option>
</select>
      </td>
    </tr>
    </table>

  <div align="center" style="padding:5px">
   <input type="submit" name="submit" value="Καταχώρηση" class="button">
        <input type="reset" name="reset" value="Επαναφορά" class="button">  </div>
</form>  
</div>
<div align="right"><a href="all-lang.php" class="links">μεταφορά στην Λίστα</a></div></td>
  </tr>
</table><?php include 'menudown.php';?>
<?php } ?>
</body>
</html>
