FREE Online Affiliate Program
www.WebpageAffiliates.com
Copyright © - updated by www.WebpagePublicity.com
Signup | Affiliate Training Videos | Login
#!/usr/bin/perl
##############################################################
# #
# Ultimate Affiliate #
# ***********SQL EDITION********** #
# By Steve Miles #
# http://www.groundbreak.com #
# #
# Copyright 1998-present #
# #
# Selling or distributing this software or #
# modifications of this software without #
# permission is expressly forbidden. Permission #
# to modify the script for personal use is granted. #
# In all cases this header and copyright #
# must remain intact. All violators will be #
# PROSECUTED to the full extent. #
# #
##############################################################
use Time::Local;
use File::Find;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw (:standard);
$q = new CGI;
@stuff = $q->param;
foreach $stuff (@stuff) {${$stuff} = $q->param($stuff); ${$stuff} =~ s/\;//ig;}
$|++;
require "config.cgi";
require "common.cgi";
&Create_DB_Connection;
$time = time();
&headers_footers;
@daysinmonth = (30,28,31,30,31,30,31,31,30,30,30,31);
@monthnames = ("January","February","March","April","May","June","July","August","September","October","November","December");
@hournames = ("12am-1am","1am-2am","2am-3am","3am-4am","4am-5am","5am-6am","6am-7am","7am-8am","8am-9am","9am-10am","10am-11am","11am-12pm","12pm-1pm","1pm-2pm","2pm-3pm","3pm-4pm","4pm-5pm","5pm-6pm","6pm-7pm","7pm-8pm","8pm-9pm","9pm-10pm","10pm-11pm","11pm-12am");
@daynames = ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
@fields = (Year,Month,Day,Sponsor,Status,Tier,Username,Password,Email,Name,Address1,Address2,City,State,Zip,Country,Company,Sitename,Siteurl,Terms,Checkname,Phone,Fax,SSNumber);
if($action =~ /Get Lost Password/i){&emailpassword;exit;}
if($action =~ /Did you lose your password\?/i){&lostpasswordform;exit;}
if ($pass) { $pass = crypt($pass, "rocksalt"); }
if (!$user) { $user = $q->cookie('statsuser'); }
if (!$pass) { $pass = $q->cookie('statspass'); }
if (!$user && !$pass) {&loginpage;}
if ($bypass) {&to_login;}
$SQL = "SELECT * FROM users WHERE Username = '$user'"; &Do_SQL;
$row = $sth->fetchrow_hashref; $crypt_password = crypt($row->{'Password'}, "rocksalt");
if ($row->{'Status'} =~ /PENDING/ig || $row->{'Status'} =~ /VALIDATED/ig) {&print_default("This affiliate is still awaiting approval.");exit;}
elsif ($pass ne $crypt_password || $user ne $row->{'Username'}) { &to_login; }
sub to_login {
$cookie1 = $q->cookie(-name=>statsuser, -value=>'', -path=>'/');
$cookie2 = $q->cookie(-name=>statspass, -value=>'', -path=>'/');
print $q->header(-cookie=>[$cookie1,$cookie2]);
print<
ERROR
Login info incorrect... Usernames and Passwords are case sensitive, you
can have your login info sent to your email address if you've forgotten what they are.
You will be forwarded to the main stats page in 5 seconds.
Click Here if nothing happens.
EOF
exit;
}
$Tier = $row->{'Tier'};
$cookie1 = $q->cookie(-name=>statsuser, -value=>$user, -path=>'/');
$cookie2 = $q->cookie(-name=>statspass, -value=>$crypt_password, -path=>'/');
foreach $field (@fields) {
${$field} = $row->{"$field"};
}
$url_to_clickthru =~ s//$user/g;
if ($what_type_of_commission eq "flatfee") { @temporary_tiers = @flatfee_tiers; }
else { @temporary_tiers = @percentage_tiers; }
foreach $item (@temporary_tiers) {
$t++;
if ($item > 0) { $final_level = $t;}
}
(@user_tiers) = split (/\,/, $Tier);
foreach $item (@user_tiers) {
$i++;
if ($item > 0) { $user_final_level = $i;}
}
$t = 0; $i = 0;
if ($user_final_level) { $grand_level = $user_final_level; }
else { $grand_level = $final_level; }
if($action eq "Update Your Info"){&changeinfoform;exit;}
if($action eq "Top 100 Referral Sites"){&create_month_hash;&getreferrers;exit;}
if($action eq "Update User Info"){&updateuser;exit;}
if($action eq "Yes" || $action eq "Delete Account") { &deleteuser;exit;}
if($action eq "Get Link Code" || $action eq "bannercode"){&bannercode;exit;}
if($action eq "Year to date" || $action eq "View this year"){&create_month_hash;&year_stats;exit;}
if($action eq "In-depth Commissions" || $action eq "View Commissions"){&create_month_hash;&viewtransactions;exit;}
if($action eq "pyramid"){&pyramid;exit;}
if($action eq "logout"){&logout;exit;}
if($action eq "emaildownline") { &emaildownline; exit; }
if($action eq "send") {&send; exit; }
&create_month_hash;
&create_month_stats;
&statspage;exit;
######################################################################
# SEND DOWNLINE EMAILS
######################################################################
sub send {
#$found = $q->cookie('sentemail');
if ($found) {
print $q->header;
print<
Error
You can only send email once an hour...
Click Here
EOF
exit;
}
#$SQL = "SELECT * FROM users WHERE Username = '$user'"; &Do_SQL;
#$temp = $sth->fetchrow_hashref; $user_email = $temp->{'Email'};
$emailheader =~ s/\%\%Name\%\%/$row->{'Name'}/ig;
$emailheader =~ s/\%\%Email\%\%/$row->{'Email'}/ig;
if ($test) { @emails = ($user_email); } else {
$SQL="SELECT * FROM users"; &Do_SQL;
while ($row = $sth->fetchrow_hashref){
$info{$row->{'Username'}} = [$row->{'Email'},$row->{'OptOut'}];
push @{ $kids{$row->{'Sponsor'}} }, $row->{'Username'};
}
$kid = "$user";
if (!$kids{$kid}) {
print $q->header;
print<There are currently no members in your downline
EOF
exit;
} else {
&crunch1(1);
}
$o++;
sub crunch1 {
foreach $kid (@{ $kids{$kid} }) {
$newlevel++;
if ($limit_levels) { if ($grand_level > $newlevel) { $showitnow++; }} else { $showitnow = 1; }
if ($showitnow) {
$temp = $newlevel + 1;
$payouts{$temp}++;
$levels{$temp}++; $total_downline++;
if ($to eq "direct" && $temp eq 2) {
if (!$info{$kid}[1]) { push (@emails, $info{$kid}[0]); }
} else {
if (!$info{$kid}[1]) { push (@emails, $info{$kid}[0]); }
}
&crunch1($newlevel);
$showitnow = 0;}
$newlevel--;
delete($info{$kid});
}}
}
if ($test) {
$temp2 = "Test Email Successful ";
&emaildownline;
} else {
$cookies = $q->cookie(-name=>sentemail, -value=>1, -expires=>'+1h', -path=>'/');
print $q->header(-cookie=>$cookies);
print<
Emailing Successful
The emailing has been successful...
You will be forwarded to the main stats page in 5 seconds.
Click Here if nothing happens.
EOF
}
foreach $email (@emails) {
if ($email =~ /^[\w\-\.]+\@[\w\-]+\.[\w\-\.]+\w$/) {
if ($smtphost) {
$smtp = Net::SMTP->new($smtphost);
$smtp->mail($user_email);
$smtp->to($email);
$smtp->data();
$smtp->datasend("From: $user_email\n");
$smtp->datasend("Return-Path: $user_email\n");
$smtp->datasend("To: $email\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("\n");
$smtp->datasend("$emailheader\n\n$message\n\n");
$smtp->dataend();
$smtp->quit();
} else {
open (MAIL, "|$mailprog -oi -t") || die "Can't open $mailprog!\n";
print MAIL <<"EOF";
From: $user_email
Return-Path: $user_email
To: $email
Subject: $subject
$emailheader
$message
EOF
close (MAIL);
}}}
exit;
}
######################################################################
# EMAIL AFFILIATES FORM
######################################################################
sub emaildownline {
$SQL = "SELECT * FROM users WHERE Username = '$user'"; &Do_SQL;
$row = $sth->fetchrow_hashref; $user_email = $row->{'Email'};
if ($to eq "direct") { $temp = "selected"; }
print $q->header;
print<$temp2
EOF
}
######################################################################
# Prepare and show tree of affiliates
######################################################################
sub pyramid {
($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime(time());
$month = $mon;
$year = $year + 1900;
print $q->header;
$SQL = "SELECT * FROM users WHERE Username = '$user'"; &Do_SQL;
$row = $sth->fetchrow_hashref;
print<Downline for $user
Downline for $user as of $monthnames[$month], $year
[return to main page]
EOF
if ($affiliate_downline_email && !$row->{'SuspendEmail'}) {
print<Click here to email your downline
EOF
}
$report = "1: $user \n";
$payouts{1} = 1;
$levels{1} = 1;
$SQL="SELECT * FROM users"; &Do_SQL;
while ($row = $sth->fetchrow_hashref){
$info{$row->{'Username'}} = [$row->{'Email'},$row->{'Name'},$row->{'Month'},$row->{'Day'},$row->{'Year'},$row->{'OptOut'}];
push @{ $kids{$row->{'Sponsor'}} }, $row->{'Username'};
}
$kid = "$user";
if (!$kids{$kid}) {
print<There are currently no members in your downline
EOF
} else {
&crunch(1);
}
$o++;
sub crunch {
foreach $kid (@{ $kids{$kid} }) {
$newlevel++;
if ($limit_levels) { if ($grand_level > $newlevel) { $showitnow++; }} else { $showitnow = 1; }
if ($showitnow) {
$temp = $newlevel + 1;
$payouts{$temp}++;
$levels{$temp}++; $total_downline++;
while ($b < $newlevel) { $report .= " "; $b++; } $b=0;
if ($affiliate_downline_show) {
$report .= "$temp: $kid $info{$kid}[0], $info{$kid}[1], $info{$kid}[2]/$info{$kid}[3]/$info{$kid}[4]\n";
} else {
$report .= "$temp: $kid \n";
} $showitnow = 0;}
&crunch($newlevel);
$newlevel--;
delete($info{$kid});
}
}
if (!$total_downline) { $total_downline = "0"; }
print<
$report
Total in downline: $total_downline
EOF
while (!$found_some) { $i++;
if ($levels{$i}) {
print<Level $i: $levels{$i}
EOF
} else { $found_some = 1; }
}
print<
EOF
}
######################################################################
# Top Referring Sites for that user
######################################################################
sub getreferrers {
print $q->header;
&date;
&header;
print<
Identify your high-traffic links
$footer
EOF
$time = time();
$temp = $time - (60 * 60 * 24 * 30);
$SQL = "DELETE FROM ua_referers WHERE Date < '$temp'"; &Do_SQL;
exit;
}
######################################################################
# View User Info
######################################################################
sub changeinfoform {
@fields = (Year,Month,Day,Sponsor,Username,Password,Email,Name,Address1,Address2,City,State,Zip,Country,Company,Sitename,Siteurl,Terms,Checkname,Phone,Fax,SSNumber,OptOut,Field1,Field2,Field3,Field4,Field5);
$SQL = "SELECT * FROM users WHERE Username LIKE '$user'";
&Do_SQL;
while ($pointer = $sth->fetchrow_hashref){
foreach $field (@fields) {
${$field} = $pointer->{"$field"};
}
}
$sth->finish;
$dbh->disconnect;
$Sponsor =~ s/\_/ /ig;
if ($OptOut) { $optedout = "checked"; }
print $q->header;
&header;
print<
Update your account information
$footer
EOF
}
######################################################################
# Update User
######################################################################
sub updateuser {
if ($new_Email =~ /^[\w\-\.]+\@[\w\-]+\.[\w\-\.]+\w$/) {}
else {&print_default("Not a valid email format!"); exit;}
$SQL = "SELECT Username FROM users WHERE Username = '$new_Username'"; &Do_SQL;
while ($row = $sth->fetchrow_hashref) {
if ($row->{'Username'} ne $old_user) { &print_default("This username is already in use");}
}
@reserved = split (/,/, $reserved);
foreach $item (@reserved) {
if ($item eq $new_Username) { &print_default(" That username is reserved"); }
}
if (!$new_Username || $new_Username !~ /^[A-Za-z0-9]+$/) { &print_default(" Username must consist of numbers and letters only");}
if (!$new_Password || $new_Password !~ /^[A-Za-z0-9]+$/) { &print_default(" Passwords do not match");}
$count++ while $new_Username =~ /[A-Za-z0-9]/g;
if (4 > $count) { &print_default(" You need more than 3 and less than 21 characters in your username");}
$count = 0;
$count++ while $new_Password =~ /[A-Za-z0-9]/g;
if (4 > $count) { &print_default(" You need more than 3 and less than 21 characters in your password");}
foreach $stuff (@stuff) {${$stuff} =~ s/\'/\\\'/g;${$stuff} =~ s/\"/\\\"/g;}
$Sponsor =~ s/ /_/ig;
if ($new_OptOut ne "on") { $new_OptOut = ""; } else { $new_OptOut = 1; }
$SQL="UPDATE users SET
Username = '$new_Username',
Password = '$new_Password',
Email = '$new_Email',
Name = '$new_Name',
Address1 = '$new_Address1',
Address2 = '$new_Address2',
City = '$new_City',
State = '$new_State',
Zip = '$new_Zip',
Country = '$new_Country',
Company = '$new_Company',
Sitename = '$new_Sitename',
Siteurl = '$new_Siteurl',
Checkname = '$new_Checkname',
Phone = '$new_Phone',
Fax = '$new_Fax',
SSNumber = '$new_SSNumber',
OptOut = '$new_OptOut',
Field1 = '$new_Field1',
Field2 = '$new_Field2',
Field3 = '$new_Field3',
Field4 = '$new_Field4',
Field5 = '$new_Field5'
WHERE
Username = '$old_user'
";
&Do_SQL;
$SQL = "UPDATE ua_primary_hits SET Id = '$new_Username' WHERE Id = '$old_user'"; &Do_SQL;
$SQL = "UPDATE users SET Sponsor = '$new_Username' WHERE Sponsor = '$old_user'"; &Do_SQL;
$SQL = "UPDATE commissions SET Id = '$new_Username' WHERE Id = '$old_user'"; &Do_SQL;
$SQL = "UPDATE ua_campaigns SET Id = '$new_Username' WHERE Id = '$old_user'"; &Do_SQL;
$SQL = "UPDATE ua_referers SET Id = '$new_Username' WHERE Id = '$old_user'"; &Do_SQL;
$SQL = "UPDATE ua_hits SET Id = '$new_Username' WHERE Id = '$old_user'"; &Do_SQL;
$sth->finish;
$dbh->disconnect;
if ($user ne $new_Username) {
if ($replicator_on eq 1 && $user =~ /^[A-Za-z0-9]+$/ && $path_to_replicated_pages) {
$deletedir = "$path_to_replicated_pages/$user";
*name = *File::Find::name;
finddepth \&zap, $deletedir;
sub zap {
if (!-l && -d _) {
rmdir($name);
} else {
unlink($name);
}
}}
}
$Username = $new_Username;
@temp = (Field1,Field2,Field3,Field4,Field5);
foreach $item (@temp) {
push (@signupfields, $item);
}
foreach $field (@signupfields) {
$temp = "new_$field";
${$field} = ${$temp};
}
&replicate;
print $q->header;
print<
SUCCESSFUL SIGNUP!
Your account has been updated...
You will be forwarded to the main stats page in 5 seconds.
Click Here if nothing happens.
EOF
exit;
}
######################################################################
# Create Stats hashes for this month
######################################################################
sub create_month_stats {
$SQL = "SELECT SUM(Month_Total),SUM(Month_Unique) FROM ua_primary_hits WHERE Id = '$user'";
&Do_SQL;
$row = $sth->fetchrow_arrayref;
$total_month_hits = ${$row}[0];
$unique_month_hits = ${$row}[1];
if (!$total_month_hits) { $total_month_hits = 0; }
if (!$unique_month_hits) { $unique_month_hits = 0; }
$SQL = "SELECT * FROM ua_primary_hits WHERE Month = '$month' && Year = '$real_year' && Id = '$user'";
&Do_SQL;
$row = $sth->fetchrow_hashref;
$SQL="SELECT * FROM commissions WHERE Id like '$user'";
&Do_SQL;
while ($pointer = $sth->fetchrow_hashref){
$i++;
$log_month = $pointer->{'Month'};
$log_year = $pointer->{'Year'};
$log_day = $pointer->{'Day'};
$log_payout = $pointer->{'Commission'};
$log_tier = $pointer->{'Level'};
$log_status = $pointer->{'Status'};
if ($log_year eq $real_year && $log_month eq $month) {
if ($log_status ne "PENDING") {
$tier = "tier$log_day";
${$tier}{$i} = $status;
$tierA = "tier$log_day\A";
${$tierA} = ${$tierA} + $log_payout;
$total = "total$log_day";
${$total} = ${$total} + $log_payout;
if ($log_status ne "NOTPAID") {$paid_total = $paid_total + $log_payout;}
$whole_month_total = $whole_month_total + $log_payout;
$sale_number++;
}}
if ($log_status ne "PENDING") {
if ($log_status ne "NOTPAID") {$paid_program_total = $paid_program_total + $log_payout;}
$whole_program_total = $whole_program_total + $log_payout;
$total_program_commissions++;
}
}
$sth->finish;
$i = 0;
$mon_max = 0;
while ($i < 32) {
$temp = "$i\day";
if ($row->{$temp} > $mon_max) {
$mon_max = $row->{$temp};
}
$i++;
}
$whole_month_total = (int ($whole_month_total * 100)) / 100;
$i = 1;
while ($i < 32) {
$tier = "tier$i"; $t1 = keys %{$tier};
$big_total = $t1;
if ($sales_max < $big_total) {$sales_max = $big_total;}
$i++;
}
if (!$total_program_commissions) { $cpstotal = "n/a"; } else { $cpstotal = int ($unique_month_hits / $total_program_commissions); }
if (!$sale_number) { $cps = "n/a"; } else { $cps = int ($row->{'Month_Unique'} / $sale_number); }
if (!$cps) { $cps = "0"; } if (!$cpstotal) { $cpstotal = "0"; }
if ($paid_program_total > 0 || $paid_program_total < 0) {} else { $paid_program_total = 0; }
if ($whole_program_total > 0 || $whole_program_total < 0) {} else { $whole_program_total = 0; }
if ($sale_number) {} else { $sale_number = 0; }
if ($total_program_commissions) {} else { $total_program_commissions = 0; }
if ($whole_month_total > 0 || $whole_month_total < 0) {} else {$whole_month_total=0;}
if ($paid_total > 0 || $paid_total < 0) {} else {$paid_total=0;}
$days_in_the_month = @days_of_the_month;
}
######################################################################
# Delete User
######################################################################
sub deleteuser {
if ($action eq "Delete Account") {
print $q->header;
print<
Are you sure you want to delete your account?
EOF
exit;
}
$temp = "NO_SPONSOR";
$SQL = "SELECT * FROM users WHERE Username like '$user'";
&Do_SQL;
while ($pointer = $sth->fetchrow_hashref) {
$temp = $pointer->{'Sponsor'};
}
$SQL="DELETE FROM users WHERE Username like '$user'";
&Do_SQL;
$SQL="DELETE FROM hits WHERE Id like '$user'";
&Do_SQL;
$SQL="DELETE FROM commissions WHERE Id like '$user'";
&Do_SQL;
$SQL="DELETE FROM ua_primary_hits WHERE Id like '$user'";
&Do_SQL;
$SQL="UPDATE users SET
Sponsor = '$temp'
WHERE
Sponsor = '$user'";
&Do_SQL;
$sth->finish;
if ($replicator_on eq 1 && $user =~ /^[A-Za-z0-9]+$/ && $path_to_replicated_pages) {
$deletedir = "$path_to_replicated_pages/$user";
*name = *File::Find::name;
finddepth \&zap, $deletedir;
sub zap {
if (!-l && -d _) {
rmdir($name);
} else {
unlink($name);
}
}}
print $q->header;
print<
DELETE SUCCESSFUL
Your Account has been deleted
You will be forwarded to our main page in 5 seconds.
Click Here if nothing happens.
EOF
exit;
}
######################################################################
# Banner Code Page
######################################################################
sub bannercode {
print $q->header;
$num_sites = @extra_sites;
&header;
print<
EOF
if ($type) {} else {
print<
Click Here
To return to the main affiliate stats page.
Click Here
To get banner and text link code to advertise our website.
EOF
if ($grand_level > 1) {
print<
Click Here
To get banner and text link code to advertise our affiliate program and earn commissions on sales generated by new affiliates you sign up.
EOF
}
if ($clickthru_as_a_dir ne 1 && $replicator_on ne 1) {
print<
Click Here
To learn how you can track different ad campaigns by including a special variable in your link code.
EOF
}
if ($use_page eq 1 && $replicator_on ne 1) {
print<
Click Here
To view instructions on how to send clicks through your affiliate url to different pages on our website.
EOF
}
print<
$footer
EOF
exit;
}
if ($type eq "products" && $num_sites && $show ne "YES" && $use_page) {
print<