session_start();
include "../sa_config.php";
include "./lang/$language";
include "./countries.php";
$errorMsg = '';
if($_POST['step'] == 'register'){
// form was sent
$conn = sa_db_connect();
if(!$conn){
echo "Database connection error. Please try again later.";
echo mysql_error();
}
if($_POST['ausername'] == '')
$errorMsg .= AFF_SI_UNAMEMISSING.'
';
// check if user doesnt exist already
$userid = preg_replace('/[^a-zA-Z0-9_]/', '', $_POST['ausername']); // protect against sql injection
$chk_user = mysql_query("SELECT Username FROM Affiliates where Username='$userid'");
if(mysql_num_rows($chk_user) > 0)
{
$errorMsg .= AFF_SI_USEREXISTS.'
';
$_POST['ausername'] = '';
}
if($_POST['apassword'] == '')
$errorMsg .= AFF_SI_PWDMISSING.'
';
if($_POST['aemail'] == '')
$errorMsg .= AFF_SI_EMAILMISSING.'
';
$email = $_POST['aemail'];
if(!sa_valid_email($_POST['aemail']))
$errorMsg .= AFF_SI_EMAILINVALID.'
';
if($_POST['termsAgree'] == "no")
$errorMsg .= AFF_SI_TERMSNO.'
';
if($errorMsg == '' && (preg_match ("/".str_replace("www.", "", $_SERVER["SERVER_NAME"])."/i", $_SERVER["HTTP_REFERER"]))){
// save and send notification email
$aemailbody = "Dear ".$_POST['afirstname'].",\n\nThank you for signing up to our affiliate program.\nYour account details are below:\n\n"
."Username: ".$_POST['ausername']."\nPassword: ".$_POST['apassword']."\n\n"
."You can log into your account and view your 'real-time' statistics by going to:\n"
."http://".$domain."/".$folder."/user/index.php\n\n"
."Thank you once again, and we wish you luck with your profit making!\n\n\n"
."Affiliate Program Manager\n"
.$adminEmail."\n\n\n\n";
$date_now = date("U");
$password = md5($_POST['apassword']);
$q1 = mysql_query("INSERT INTO Affiliates (Username, Password, FirstName, LastName, Company, Street,
Street2, City, State, Zip, Country, Phone, Email, Website, PayTo, Title, PaymentPreferenceID, StartEffectiveDate, EndEffectiveDate) VALUES
('".$_POST['ausername']."', '".$password."', '".$_POST['afirstname']."', '".$_POST['alastname']."',
'".$_POST['acompany']."', '".$_POST['astreet']."', '".$_POST['astreet2']."', '".$_POST['acity']."',
'".$_POST['astate']."', '".$_POST['azip']."', '".$_POST['acountry']."', '".$_POST['aphone']."',
'".$_POST['aemail']."', '".$_POST['awebsite']."', '".$_POST['acheckname']."', '".$_POST['atitle']."',
'".$_POST['payPreference']."', '".$date_now."', '2145945600')")
or die(mysql_error());
include "thankyou.php";
if(!mail($_POST['aemail'], "Welcome New Affiliate!", $aemailbody, "From:".$adminEmail."\nReply-To:".$adminEmail."\n")){
echo "
if($errorMsg != '') echo "
$errorMsg
"; ?>