<?
//
// H-Tracker v0.2
// http://h-tracker.org
// Based on TorrentTrader (http://www.torrenttrader.org)
//
//
require_once("backend/functions.php");
require_once("backend/phpbb2Bridge.php");
dbconn(true);
$id = 0 + $_GET["id"];
$md5 = $_GET["secret"];
$email = $_GET["email"];
if (!$id || !$md5 || !$email)
show_error_msg("Couldn't change the email", "Error retrieving ID, KEY or Email.",1);
$res = mysql_query("SELECT editsecret, username FROM users WHERE id = $id");
$row = mysql_fetch_array($res);
if (!$row)
show_error_msg("Couldn't change the email", "No user found wanting to change the email.",1);
$sec = hash_pad($row["editsecret"]);
if (preg_match('/^ *$/s', $sec))
show_error_msg("Couldn't change the email", "No match found.",1);
if ($md5 != md5($sec . $email . $sec))
show_error_msg("Couldn't change the email", "No md5.",1);
mysql_query("UPDATE users SET editsecret='', email=" . sqlesc($email) . " WHERE id=$id AND editsecret=" . sqlesc($row["editsecret"]));
if (!mysql_affected_rows())
show_error_msg("Couldn't change the email", "No affected rows.",1);
update_phpBB2userEmail($row["username"],$email);
header("Refresh: 0; url=$SITEURL/account.php");
?>