<html>

<?php


include("header.php");
$db = db_init ();

	if ($submit) {
	
		if($id) 
		{
			$result = db_query("SELECT * FROM translators WHERE id=\"$id\"",$db);    
			$pass=db_result($result,0,"password");
				if ( !(crypt($oldpassword,"$pass")=="$pass") )
				{  
					echo gettext("Passwords do not match.");
					exit;
				}
		}
		
// process form
		
		if($password==$password1 && $first && $last && $email)
		{  //quality check
			if($password)
			{
				$passworde = crypt("$password");
			}
			else
			{
				$passworde = $pass;	
			}
			
			if($id) 
			{
				$sql = "REPLACE INTO translators (id,first,last,email,password,biography) VALUES ('$id','$first','$last','$email','$passworde','$biography')";
				$result = db_query($sql);
				echo gettext("Information saved.")."\n";
			}
			else 
			{
				$sql = "INSERT INTO translators (first,last,email,password,biography) VALUES ('$first','$last','$email','$passworde','$biography')";
				$result = db_query($sql);
				$sql = "SELECT  LAST_INSERT_ID() AS id FROM translators WHERE id=LAST_INSERT_ID()";
				$result = db_query($sql);
				$id = db_result($result,0,"id");
				printf(gettext("Your ID is:  <b>%s</b> , remember it!!!")."<br>\n", $id);
				sprintf(gettext("The registration process has been completed. An mail containing information about your account has been sent to %s.\n"), $email);
				mail($email,"Registration at KDE-i18n-$team","Your account details:\nID:$id \n Password:$password\n\n Use your id to access team pages on the website.");
			}
//modificare in ID invece che filename
		
		$dest = sprintf("translators-foto/%s.png",$id);
			if(@exec("cp \"$file\" \"$dest\"")!=0) {
			sprintf(gettext("Unable to create %s - check permissions<br>\n"), $dest);
			exit;
			}
		echo $dest;
?>
<img width=50 src=<? echo $dest ?>>
<?
		} //if quality ok!
		else
		{
			echo  gettext("Error: Check if you have entered all the necessary entries");
		}
	else
	{
print (gettext("If you are an italain KDE translator please register now").":<br>")
?>

<form method="post" enctype="multipart/form-data" action="<?php echo $PHP_SELF?>">
	<table border=0>    
		<tr><td><?php gettext("Name") ?>(*)</td><td><input type="Text" name="first"></td></tr>
		<tr><td><?php gettext("Surname") ?>(*)</td><td><input type="Text" name="last"></td></tr>
		<tr><td><?php gettext("Email") ?>(*)</td><td><input type="Text" name="email"></td></tr>
		<tr><td><?php gettext("Password") ?>(*)</td><td><input type="Password" name="password"></td></tr>
		<tr><td><?php gettext("Verify Password") ?>(*)</td><td><input type="Password" name="password1"></td></tr>
		<tr><td><?php gettext("Photo") ?> <?php gettext("(PNG, max 40Kb)") ?></td><td><input type="file" name="file"></td></tr>
		<tr><td><?php gettext("Short biography") ?></td><td><textarea name="biography" cols="30" rows="6"></textarea></td></tr>
	</table>
<input type="hidden" name="MAX_FILE_SIZE" value="40000">
<input type="Submit" name="submit" value="<?php print (gettext("Enter information"))?>">
</form>
<?php

	} // end if
include("footer.php");
?>
</body>
</html>
