<?php
session_start();

include "../config.php";
include "../header.php";
include "../style.php";

if( isset($_SESSION["ulogin"]) )
{  // members only stuff!

include("navigation.php");
include("../banners2.php");

echo "<font size=2 face='$fonttype' color='$fontcolour'><p><center>";


echo "<p><br><br><font size=6><img src=images/promotiontools&stats.png></font></p>";

echo "<p><b>You currently have ".$points." points. If you wish to purchase extra points,<br>please click on 'Advertising' in the navigation menu.</p></b>";

//current earnings.....
if ($commission>0) {
echo "<p><b>You are owed $".round($commission,2).".  Commissions are paid between the 15th and 30th of every month.<br>  You <font color='red'>MUST</font> send in a support request if you wish to be paid. <br>Make sure you have your PayPal email or other payment options filled out under 'Edit My Details'.</p></b>";
}

if($_POST['reset']) {
$hits_unique=0;
$hits_visitor=0;
mysql_query("UPDATE members SET hits_unique=0,hits_visitor=0 WHERE userid='$userid'");
}



echo "<p><b>Your referral url:</b><br><br>".$domain."/index.php?referid=".$_SESSION[uname]."<br><br><br><font face=verdana size=3><b>Hits:</b> ".$hits_visitor." &nbsp; <b>Unique Visitors:</b> ".$hits_unique."  <br><br><form method=post><input type=\"submit\" name=\"reset\" value=\"Reset\"></form></font></p></b>";

echo "<p><b>Splash Page 1:</b><br><br>".$domain."/splashpage.php?referid=".$_SESSION[uname]."<p></b><br>";

echo "<p><b>Splash Page 2:</b><br><br>".$domain."/splashpage1.php?referid=".$_SESSION[uname]."<p></b><br>";

echo "<p><b>Splash Page 3:</b><br><br>".$domain."/splashpage2.php?referid=".$_SESSION[uname]."<p></b><br>";

$query = "SELECT * FROM advertise";
$result = mysql_query ($query)
or die ("Query failed");

$num_rows = mysql_num_rows($result);

if ($num_rows>0) {
//only if there were banners to show.
echo "<br><br><b>Promo Tools:</b><br><br><br> ";
}

while ($line = mysql_fetch_array($result)) {
$bannerurl = $line["bannerurl"];
$bannimgsize = @getimagesize($bannerurl);
//print_r($bannimgsize);
if($bannimgsize[0] > 600){
echo "<img src=\"$bannerurl\" width=\"610\" border='0'>";
}else{
echo "<img src=\"$bannerurl\">";
}
?>
<br><br>
Banner Url: <br><? echo $bannerurl; ?><br><br>

<textarea rows=4 cols=65 name="text"><a href="<? echo $domain."/index.php?referid=".$_SESSION[uname]; ?>" target=_blank"><img src="<? echo $bannerurl; ?>" border=0></a></textarea><br>
<br>


<br><br>
<?
}

$query = "select * from email_promotion";
$result = mysql_query ($query)
or die ("Select failed");

if(@mysql_num_rows($result)) echo "Email copy for your own list, safelists or list building sites like ListSupreme.com
(for use on advertising websites or your own double opt-in subscribers only - do not send to purchased bulk email lists including \"blasters\")<br><br>";

while ($line = mysql_fetch_array($result)) {

?>
Subject 1: <input type="text" value="<? echo dbget($line['subject1']); ?>"><br>
Subject 2: <input type="text" value="<? echo dbget($line['subject2']); ?>"><br>
<textarea rows=10 cols=50 name="text"><? echo str_replace("%reflink%", $domain."/index.php?referid=".$_SESSION[uname], dbget($line["text"])); ?></textarea><br>
<br>
<?
}

$query = "SELECT * FROM members where referid='".$_SESSION[uname]."' and verified=1 ORDER BY joindate ASC";
$result = mysql_query ($query);

echo "<p><br>Members signed up from your referral url:<br></p>";
?><b> Please Note:<br>
PRO Upgrades purchased with points will reflect under your Referrals as PRO (Points),
<br>but there will be NO Cash Commissions Paid for PRO (Points) Upgrades.</b></p><br>
<table width=85% border=0 cellpadding=2 cellspacing=2>


<tr><td bgcolor="<? echo $contrastcolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"></font></center></td>
<td bgcolor="<? echo $contrastcolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>">Name</font></center></td>
<td bgcolor="<? echo $contrastcolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>">Userid</font></center></td>
<td bgcolor="<? echo $contrastcolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>">Membership Type</font></center></td>
<td bgcolor="<? echo $contrastcolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>">Came From</font></center></td>
</tr>
<?
$count = 0;
$nextreflevel = array();
while ($line = mysql_fetch_array($result)) {
$count++;
$name = $line["name"];
$userid = $line["userid"];
if($_SESSION[uname] != $userid) $nextreflevel[] = $line["userid"];
$memtype = $line["memtype"];

$referrer = $line["referrer"];

if(strlen($referrer) > 65) $referrer = substr($referrer,0,63)."..";
?>
<tr>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $count; ?></font></center></td>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $name; ?></font></center></td>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $userid; ?></font></center></td>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $memtype; ?><? if($line['upgrade_points']==1) echo " (Points)"; ?></font></center></td>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $referrer; ?></font></center></td>
<TR>
<?
}
//level 2
$levelref = $nextreflevel;
$nextreflevel = array();
$showlvlheader = true;
$count = 0;
if(count($levelref)>0){
foreach ($levelref as $refuser){
if(!empty($refuser)){

$query = "SELECT * FROM members where referid='".$refuser."' and verified=1 ORDER BY joindate ASC";
$result = mysql_query ($query);

while ($line = mysql_fetch_array($result)) {
if($showlvlheader){
echo "<tr><td bgcolor='$contrastcolour' colspan='5'><font size='2' face='$fonttype' color='$fontcolour'>Second Level Referrals</font></td></tr>";
$showlvlheader =false;
}
$count++;
$name = $line["name"];
$userid = $line["userid"];
if($_SESSION[uname] != $userid) $nextreflevel[] = $line["userid"];
$memtype = $line["memtype"];

$referrer = $line["referrer"];

if(strlen($referrer) > 65) $referrer = substr($referrer,0,63)."..";
?>
<tr>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $count; ?></font></center></td>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $name; ?></font></center></td>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $userid; ?></font></center></td>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $memtype; ?><? if($line['upgrade_points']==1) echo " (Points)"; ?></font></center></td>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $referrer; ?></font></center></td>
<TR>
<?
}
}
}
}
//level 2 end
//level 3
$levelref = $nextreflevel;
$nextreflevel = array();
$showlvlheader = true;
$count = 0;
if(count($levelref)>0){
foreach ($levelref as $refuser){
if(!empty($refuser)){

$query = "SELECT * FROM members where referid='".$refuser."' and verified=1 ORDER BY joindate ASC";
$result = mysql_query ($query);

while ($line = mysql_fetch_array($result)) {
if($showlvlheader){
echo "<tr><td bgcolor='$contrastcolour' colspan='5'><font size='2' face='$fonttype' color='$fontcolour'>Third Level Referrals</font></td></tr>";
$showlvlheader =false;
}
$count++;
$name = $line["name"];
$userid = $line["userid"];
if($_SESSION[uname] != $userid) $nextreflevel[] = $line["userid"];
$memtype = $line["memtype"];

$referrer = $line["referrer"];

if(strlen($referrer) > 65) $referrer = substr($referrer,0,63)."..";
?>
<tr>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $count; ?></font></center></td>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $name; ?></font></center></td>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $userid; ?></font></center></td>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $memtype; ?><? if($line['upgrade_points']==1) echo " (Points)"; ?></font></center></td>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $referrer; ?></font></center></td>
<TR>
<?
}
}
}
}
//level 3 end
//level 4
$levelref = $nextreflevel;
$nextreflevel = array();
$showlvlheader = true;
$count = 0;
if(count($levelref)>0){
foreach ($levelref as $refuser){
if(!empty($refuser)){

$query = "SELECT * FROM members where referid='".$refuser."' and verified=1 ORDER BY joindate ASC";
$result = mysql_query ($query);

while ($line = mysql_fetch_array($result)) {
if($showlvlheader){
echo "<tr><td bgcolor='$contrastcolour' colspan='5'><font size='2' face='$fonttype' color='$fontcolour'>Fourth Level Referrals</font></td></tr>";
$showlvlheader =false;
}
$count++;
$name = $line["name"];
$userid = $line["userid"];
$nextreflevel[] = $line["userid"];
$memtype = $line["memtype"];

$referrer = $line["referrer"];

if(strlen($referrer) > 65) $referrer = substr($referrer,0,63)."..";
?>
<tr>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $count; ?></font></center></td>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $name; ?></font></center></td>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $userid; ?></font></center></td>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $memtype; ?><? if($line['upgrade_points']==1) echo " (Points)"; ?></font></center></td>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $referrer; ?></font></center></td>
<TR>
<?
}
}
}
}
//level 4 end
//level 5
$levelref = $nextreflevel;
$nextreflevel = array();
$showlvlheader = true;
$count = 0;
if(count($levelref)>0){
foreach ($levelref as $refuser){
if(!empty($refuser)){

$query = "SELECT * FROM members where referid='".$refuser."' and verified=1 ORDER BY joindate ASC";
$result = mysql_query ($query);

while ($line = mysql_fetch_array($result)) {
if($showlvlheader){
echo "<tr><td bgcolor='$contrastcolour' colspan='5'><font size='2' face='$fonttype' color='$fontcolour'>Fifth Level Referrals</font></td></tr>";
$showlvlheader =false;
}
$count++;
$name = $line["name"];
$userid = $line["userid"];
$nextreflevel[] = $line["userid"];
$memtype = $line["memtype"];

$referrer = $line["referrer"];

if(strlen($referrer) > 65) $referrer = substr($referrer,0,63)."..";
?>
<tr>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $count; ?></font></center></td>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $name; ?></font></center></td>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $userid; ?></font></center></td>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $memtype; ?><? if($line['upgrade_points']==1) echo " (Points)"; ?></font></center></td>
<td bgcolor="<? echo $basecolour; ?>"><center><font size="2" face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $referrer; ?></font></center></td>
<TR>
<?
}
}
}
}
//level 5 end

?>
</table>


</center>
<?
echo "</font></td></tr></table></font><br><br><br><br>";
}

else
{ ?>

</p>

<font size=3 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><p><b><center>You must be logged in to access this site. Please <a href="../index.php">click here</a> to login.</p></b></font>

<? }

include "../footer.php";
mysql_close($dblink);
?>