<?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>";

if ($action=="send") {

$querysend="select * from post_html where id='$postid'";
$resultsend= mysql_query($querysend);
$numrows = @ mysql_num_rows($resultsend);
if ($numrows>0) {
$linesend = mysql_fetch_array($resultsend);
}
$headers .= "From: $sitename<$adminemail>\n";
$headers .= "Reply-To: <$adminemail>\n";
$headers .= "X-Sender: <$adminemail>\n";
$headers .= "X-Mailer: PHP4\n";
$headers .= "X-Priority: 3\n";
$headers .= "Return-Path: <$adminemail>\n";
$adbody = "".dbget($linesend["adbody"])."<a href=\"".dbget($linesend["url"])."\" target=\"_blank\">Click Here To Visit The Site</a>";


$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$adbody .= "<br><hr>";
$adbody .= "<p>This is an ad you have requested to be forwarded to you from ".$sitename.". You are receivng this because you are a member of ".$sitename.".</p>";
$adbody .= "<p>Login: ".$domain."<br>";
$adbody .= "Your Userid: ".$userid."<br>";
$adbody .= "Your Password: ".$password."</p>";
$adbody .= "$adminname, $sitename, $adminaddress\n";

@mail($contact_email, dbget($linesend["subject"]), $adbody,$headers);

?><form method="GET" action="browseads_html.php">
<input type="hidden" name="nextid" value=1>
<input type="submit" value="Next Ad"><br>
</form> <?
echo "<p><center>Ad sent to '$contact_email'</center></p>";
echo "</center></font></td></tr></table>";
include "../footer.php";
exit;



//first clear the database of expired ads.
$onedayago = strtotime("-1 day");
$querys="select * from post_html where posted < '".$onedayago."'";
$results=mysql_query($querys);
//now build the query.....

while ($lines = mysql_fetch_array($results)) {
$postid = $lines["postid"];

if ($counter==0) {
$queryv.= "delete from viewed_html where id=".$postid." ";
}
else {
$queryv.= " and id=".$postid." ";
}
$counter=$counter+1;
}
if ($query<>"") {
$resultv=mysql_query($queryv);
}

$queryd="delete from post_html where posted < '".$onedayago."'";
$resultd=mysql_query($queryd);

//then delete ads of users with no credits
$querynil="select * from members where points<=0";
$resultnil=mysql_query($querynil);
$numrows = @ mysql_num_rows($resultnil);
if ($numrows>0) {
//go on and delete these ads.
while ($linenil = mysql_fetch_array($resultnil)) {
$nilposter = $linenil["userid"];
$querydelnil="delete from post_html where userid='".$nilposter."'";
$resultdelnil=mysql_query($querydelnil);
}
}

?><center>
<font size=6><br><img src='images/ti-browhtml.png'></font>
<br>
<?

}

// begin Builder

//Get recommended links
$selected = getrecommended($referid);
//Show recommmended link, if any
if($selected) {

if($selected['bold']) $winner = "<a target=\"_blank\" href=\"".$selected['url']."\"><b><font style=\"font-size: 12pt\" color=\"".$selected['color']."\">".$selected['title']."</font></b></a>";
else $winner = "<a target=\"_blank\" href=\"".$selected['url']."\"><font style=\"font-size: 12pt\" color=\"".$selected['color']."\">".$selected['title']."</font></a>";

echo '<br><table style="text-align: left; width: 500px" border="0"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td
style="background-color: rgb(255, 255, 0); height: 60px; width: 500px;"><center><font style="font-size: 12pt">Recommended Link: <br>'.$winner.'</font></td>
</tr>
</tbody>
</table>


<br><br>';
}
// End Builder


if ($memtype=="PRO") {
echo	"<p><font size='3' color='blue'><b><u>You will get ".$prohtmlearn." points for every website viewed.</b></u></font></p>";
}
elseif ($memtype=="JV Member"){
echo	"<p><font size='3' color='blue'><b><u>You will get ".$jvhtmlearn." points for every website viewed.</b></u></font></p>";
}
elseif ($memtype=="SUPER JV"){
echo	"<p><font size='3' color='blue'><b><u>You will get ".$superjvhtmlearn." points for every website viewed.</b></u></font></p>";
}

$queryviewed="select * from viewed_html where userid='".$userid."'";
$resultviewed = mysql_query($queryviewed);

$queryexclude="select * from post_html where";
while ($lineviewed = mysql_fetch_array($resultviewed)) {
$postid = $lineviewed["postid"];
if ($counter==0) {
$queryexclude.= " id<>".$postid." and";
}
else {
$queryexclude.= " id<>".$postid." and";
}
$counter=$counter+1;
}
$queryexclude.= " userid<>'".$userid."' ORDER BY rand() LIMIT 1";
$resultexclude=mysql_query($queryexclude);
$numrows = @mysql_num_rows($resultexclude);
if ($numrows==0) {
echo "<center><p><b>No more ads to view.</b></center></p>";
$noads="TRUE";
}
else {

$name = trim($name);
$firstname = substr($name , 0, strpos($name, " "));

?>
<center>
<table width=600>
<tr>
<td align="center">

<div style="width: 600px; overflow: hidden;">

<?			
while($linevad= mysql_fetch_array($resultexclude)) {


$adbody = str_replace("~fname~", $firstname, dbget($linevad["adbody"]));
$poster = $linevad["userid"];
$postid = $linevad["id"];

if($linevad['saved_id']) mysql_query("UPDATE saved_html SET hits=hits+1 WHERE id='".$linevad['saved_id']."'"); 


?> 

<?
echo "".$adbody."<br><br><a href=\"adframe_html.php?id=".$postid."\" target=\"_blank\">Click Here To Visit The Site</a><br>";
?>

<br>
<form method="GET">
<input type="hidden" name="action" value="send">
<input type="hidden" name="postid" value="<? echo $postid; ?>">
<input type="hidden" name="nextid" value=1>
<input type="submit" value="Email me this ad"></form><br>

<?


//add this ad to viewers list
$queryadtolist="insert into viewed_html (userid, postid) values ('$userid','$postid')";
$resultadtolist=mysql_query($queryadtolist);				


}
?>




<form id="nextad" method="POST">
<input type="submit" value="Next Ads"><br>
</form>


<span id="plzwait">Please wait <b>5</b> seconds...</span>
<script type="text/javascript">
counter = 6;
function countdown() {
if ((0 <= 100) || (0 > 0)) {
counter--;
if(counter == 0) {
document.getElementById("nextad").style.display = 'block';
document.getElementById("plzwait").style.display = 'none';
}
if(counter > 0) {
document.getElementById("plzwait").innerHTML = 'Please wait <b>'+counter+'<\/b> seconds...';
document.getElementById("nextad").style.display = 'none';
setTimeout('countdown()',1000);
}
}
}
countdown();
</script>

</div>

<br>
</td>
</tr>
</table>
<center>
<?
}

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

else
{ 
?>

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

<? 
    
}

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