<?
include "../config.inc";

// Check if all fields were filled in...
if (($user=="") || ($password=="") || ($firstname=="") || ($lastname=="")
|| ($email=="") || ($address=="") || ($zip=="") || ($city=="") ||
($phone=="") || ($url=="")) {
    header("Location:error1.html");
    exit;
}

// Open database...
$db = mysql_connect("localhost", "$databaseuser", "$databasepasswd");
mysql_select_db("$databasename",$db);


// Check and store affiliate data...
$sql="SELECT user,email FROM affiliate WHERE email='$email' OR user='$user'";
$result = mysql_query("$sql",$db);
if (mysql_num_rows($result) != 0) {
  header("Location:error2.html");
  exit;
}
$sql = "INSERT INTO affiliate (user, password, firstname, lastname,
email, address, zip, city, phone, url, affiliateid) VALUES ('$user', '$password', '$firstname', '$lastname', '$email', '$address', '$zip', '$city', '$phone', '$url', 0)";
$result = mysql_query("$sql",$db);
$affiliateid = mysql_insert_id();
$sql = "INSERT INTO affiliatestats (clicks, orders, affiliateid) VALUES (0, 0, '$affiliateid')";
$result = mysql_query("$sql",$db);


// Close database...

mysql_close($db);


// Send message to inform webmaster about the new affiliate...

$message="$user подписался на участие в партнерской программе, проверьте его/ее вебсайт: $url";
$subject="Зарегистрировался новый партнер";
mail("$affiliaterecipient","$subject","$message","From: $epost \nContent-Type: text/plain; charset=windows-1251\nContent-Transfer-Encoding: 8bit");


// Show thank you message...

header("Location:thankyou.html");
?>
