<?php

include "../config.php";
$today = date('Y-m-d',strtotime("now"));

//downgrade members if subscription is expire
$onemonthonedayago = date('Y-m-d',strtotime("-1 month -1 day"));
$oneyearonedayago = date('Y-m-d',strtotime("-1 year -1 day"));
$query = "select * from members ORDER BY memtype";
$result = mysql_query($query);
while ($line = mysql_fetch_array($result)) {
	$subscribed = $line["subscribed"];
	$userid = $line["userid"];
	$id = $line["id"];
	$memtype = $line["memtype"];
	$referid = $line["referid"];
	if ($subscribed == $onemonthonedayago) {
		if($memtype == 'PRO'){
			$query4 = "update members set points=points+".$propointsmonthly." where userid='".$userid."'";
			$result4 = mysql_query ($query4)
			or die ("Query 4 failed");
			echo $userid." has had ".$propointsmonthly." points added to their account.<br>";
//Bonus packs starts
			$query5 = "insert into solos (userid) values('$userid')";

			$count = 0;
			$quantity = $prosolosmonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query5);
			}
			echo $userid." has had ".$prosolosmonthly." solos added to their account.<br>";

			$query6 = "insert into cashsolos (userid) values('$userid')";

			$count = 0;
			$quantity = $procsolosmonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query6);
			}
			echo $userid." has had ".$procsolosmonthly." cash solos added to their account.<br>";

			$query7 = "insert into tlinks (userid,paid) values('$userid','$protrafficviewmonthly')";

			$count = 0;
			$quantity = $protrafficmonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query7);
			}
			echo $userid." has had ".$protrafficmonthly." traffic links with ".$protrafficviewmonthly." views added to their account.<br>";

			$query8 = "insert into ptcads (userid,paid) values('$userid','$proptcviewmonthly')";

			$count = 0;
			$quantity = $proptcmonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query8);
			}
			echo $userid." has had ".$protrafficmonthly." PTC links with ".$proptcviewmonthly." views added to their account.<br>";

			$query9 = "insert into banners (userid,max) values('$userid','$probannerviewmonthly')";

			$count = 0;
			$quantity = $probannermonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query9);
			}
			echo $userid." has had ".$probannermonthly." banners with ".$probannerviewmonthly." impressions added to their account.<br>";

			$query10 = "insert into buttons (userid,max) values('$userid','$probtnbannerviewmonthly')";

			$count = 0;
			$quantity = $probtnbannermonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query10);
			}
			echo $userid." has had ".$probtnbannermonthly." button banners with ".$probtnbannerviewmonthly." impressions added to their account.<br>";

			$query11 = "insert into hotlinks (userid,max,purchase) values('$userid','$prohotlinkviewmonthly','".time()."')";

			$count = 0;
			$quantity = $prohotlinkmonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query11);
			}
			echo $userid." has had ".$prohotlinkmonthly." hotlinks with ".$prohotlinkviewmonthly." views added to their account.<br>";

			$query12 = "insert into loginads (userid,max) values('$userid','$prologinviewmonthly')";

			$count = 0;
			$quantity = $prologinmonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query12);
			}
			echo $userid." has had ".$prologinmonthly." login ads with ".$prologinviewmonthly." views added to their account.<br>";
//bonus packs ends			
			
			$queryref="select * from members where userid='$referid'";
			$resultref = mysql_query ($queryref)
			or die ("Query 1 failed");
			$lineref = mysql_fetch_array($resultref);
			if ($memtype=="PRO") {
				$commission=$procommission;
			}elseif ($memtype=="JV Member") {
				$commission=$jvcommission;
			} elseif ($memtype=="SUPER JV") {
				$commission=$superjvcommissions;
			}
			if ($prointerval=="Yearly") {
				if ($subscribed==$oneyearonedayago) {
					$resultup="";
					$queryup="";
					$queryup="update members set memtype='PRO', subscribed='0000-00-00'"; // cancel subscription and set the subscription date to zero
					$resultup=mysql_query($queryup);
				}
			}elseif ($prointerval=="Monthly") {
				if ($subscribed==$onemonthonedayago) {
					$resultup="";
					$queryup="";
					$queryup="update members set memtype='PRO', subscribed='0000-00-00'";
					$resultup=mysql_query($queryup);
				}
			}
		}elseif($memtype == 'JV Member'){
			$query4 = "update members set points=points+".$jvpointsmonthly." where userid='".$userid."'";
			$result4 = mysql_query ($query4)
			or die ("Query 4 failed");
			echo $userid." has had ".$jvpointsmonthly." points added to their account.<br>";
//Bonus packs starts
			$query5 = "insert into solos (userid) values('$userid')";

			$count = 0;
			$quantity = $jvsolosmonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query5);
			}
			echo $userid." has had ".$jvsolosmonthly." solos added to their account.<br>";

			$query6 = "insert into cashsolos (userid) values('$userid')";

			$count = 0;
			$quantity = $jvcsolosmonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query6);
			}
			echo $userid." has had ".$jvcsolosmonthly." cash solos added to their account.<br>";

			$query7 = "insert into tlinks (userid,paid) values('$userid','$jvtrafficviewmonthly')";

			$count = 0;
			$quantity = $jvtrafficmonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query7);
			}
			echo $userid." has had ".$jvtrafficmonthly." traffic links with ".$jvtrafficviewmonthly." views added to their account.<br>";

			$query8 = "insert into ptcads (userid,paid) values('$userid','$jvptcviewmonthly')";

			$count = 0;
			$quantity = $jvptcmonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query8);
			}
			echo $userid." has had ".$jvtrafficmonthly." PTC links with ".$jvptcviewmonthly." views added to their account.<br>";

			$query9 = "insert into banners (userid,max) values('$userid','$jvbannerviewmonthly')";

			$count = 0;
			$quantity = $jvbannermonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query9);
			}
			echo $userid." has had ".$jvbannermonthly." banners with ".$jvbannerviewmonthly." impressions added to their account.<br>";

			$query10 = "insert into buttons (userid,max) values('$userid','$jvbtnbannerviewmonthly')";

			$count = 0;
			$quantity = $jvbtnbannermonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query10);
			}
			echo $userid." has had ".$jvbtnbannermonthly." button banners with ".$jvbtnbannerviewmonthly." impressions added to their account.<br>";

			$query11 = "insert into hotlinks (userid,max,purchase) values('$userid','$jvhotlinkviewmonthly','".time()."')";

			$count = 0;
			$quantity = $jvhotlinkmonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query11);
			}
			echo $userid." has had ".$jvhotlinkmonthly." hotlinks with ".$jvhotlinkviewmonthly." views added to their account.<br>";

			$query12 = "insert into loginads (userid,max) values('$userid','$jvloginviewmonthly')";

			$count = 0;
			$quantity = $jvloginmonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query12);
			}
			echo $userid." has had ".$jvloginmonthly." login ads with ".$jvloginviewmonthly." views added to their account.<br>";
//bonus packs ends			

			$queryref="select * from members where userid='$referid'";
			$resultref = mysql_query ($queryref)
			or die ("Query 1 failed");
			$lineref = mysql_fetch_array($resultref);
			if ($memtype=="PRO") {
				$commission=$projvcom;
			}elseif ($memtype=="JV Member") {
				$commission=$jvjvcom;
			} elseif ($memtype=="SUPER JV") {
				$commission=$superjvjvcom;
			}
			if ($jvinterval=="Yearly") {
				if ($subscribed==$oneyearonedayago) {
					$resultup="";
					$queryup="";
					$queryup="update members set memtype='PRO', subscribed='0000-00-00'"; // cancel sub.,set the sub. date to 0
					$resultup=mysql_query($queryup);
				}
			}elseif ($jvinterval=="Monthly") {
				if ($subscribed==$onemonthonedayago) {
					$resultup="";
					$queryup="";
					$queryup="update members set memtype='PRO', subscribed='0000-00-00'";
					$resultup=mysql_query($queryup);
				}
			}
		}elseif($memtype == 'SUPER JV'){
			$query4 = "update members set points=points+".$superjvpointsmonthly." where userid='".$userid."'";
			$result4 = mysql_query ($query4)
			or die ("Query 4 failed");
			echo $userid." has had ".$superjvpointsmonthly." points added to their account.<br>";
//Bonus packs starts
			$query5 = "insert into solos (userid) values('$userid')";

			$count = 0;
			$quantity = $superjvsolosmonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query5);
			}
			echo $userid." has had ".$superjvsolosmonthly." solos added to their account.<br>";

			$query6 = "insert into cashsolos (userid) values('$userid')";

			$count = 0;
			$quantity = $superjvcsolosmonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query6);
			}
			echo $userid." has had ".$superjvcsolosmonthly." cash solos added to their account.<br>";

			$query7 = "insert into tlinks (userid,paid) values('$userid','$superjvtrafficviewmonthly')";

			$count = 0;
			$quantity = $superjvtrafficmonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query7);
			}
			echo $userid." has had ".$superjvtrafficmonthly." traffic links with ".$superjvtrafficviewmonthly." views added to their account.<br>";

			$query8 = "insert into ptcads (userid,paid) values('$userid','$superjvptcviewmonthly')";

			$count = 0;
			$quantity = $superjvptcmonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query8);
			}
			echo $userid." has had ".$superjvtrafficmonthly." PTC links with ".$superjvptcviewmonthly." views added to their account.<br>";

			$query9 = "insert into banners (userid,max) values('$userid','$superjvbannerviewmonthly')";

			$count = 0;
			$quantity = $superjvbannermonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query9);
			}
			echo $userid." has had ".$superjvbannermonthly." banners with ".$superjvbannerviewmonthly." impressions added to their account.<br>";

			$query10 = "insert into buttons (userid,max) values('$userid','$superjvbtnbannerviewmonthly')";

			$count = 0;
			$quantity = $superjvbtnbannermonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query10);
			}
			echo $userid." has had ".$superjvbtnbannermonthly." button banners with ".$superjvbtnbannerviewmonthly." impressions added to their account.<br>";

			$query11 = "insert into hotlinks (userid,max,purchase) values('$userid','$superjvhotlinkviewmonthly','".time()."')";

			$count = 0;
			$quantity = $superjvhotlinkmonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query11);
			}
			echo $userid." has had ".$superjvhotlinkmonthly." hotlinks with ".$superjvhotlinkviewmonthly." views added to their account.<br>";

			$query12 = "insert into loginads (userid,max) values('$userid','$superjvloginviewmonthly')";

			$count = 0;
			$quantity = $superjvloginmonthly;
			while($quantity > $count) {
				$count++;
				mysql_query ($query12);
			}
			echo $userid." has had ".$superjvloginmonthly." login ads with ".$superjvloginviewmonthly." views added to their account.<br>";
//bonus packs ends			

			$queryref="select * from members where userid='$referid'";
			$resultref = mysql_query ($queryref)
			or die ("Query 1 failed");
			$lineref = mysql_fetch_array($resultref);
			if ($memtype=="PRO") {
				$commission=$prosupercom;
			}elseif ($memtype=="JV Member") {
				$commission=$jvsupercom;
			} elseif ($memtype=="SUPER JV") {
				$commission=$superjv2supercom;
			}
			if ($superjvinterval=="Yearly") {
				if ($subscribed==$oneyearonedayago) {
					$resultup="";
					$queryup="";
					$queryup="update members set memtype='PRO', subscribed='0000-00-00'"; // cancel sub and set the sub date to zero
					$resultup=mysql_query($queryup);
				}
			}elseif ($superjvinterval=="Monthly") {
				if ($subscribed==$onemonthonedayago) {
					$resultup="";
					$queryup="";
					$queryup="update members set memtype='PRO', subscribed='0000-00-00'";
					$resultup=mysql_query($queryup);
				}
			}
		}
	}
}





/*
$onemonthago = date('Y-m-d',strtotime("-1 month"));

$query = "select * from members where memtype='PRO'";
$result = mysql_query ($query)
or die ("Query 1 failed");
while ($line = mysql_fetch_array($result)) {
$subscribed = $line["subscribed"];
$userid = $line["userid"];
$id = $line["id"];
$memtype = $line["memtype"];
$referid = $line["referid"];

if ($subscribed == $onemonthago) {

$query4 = "update members set points=points+".$propointsmonthly." where userid='".$userid."'";
$result4 = mysql_query ($query4)
or die ("Query 4 failed");
echo $userid." has had ".$propointsmonthly." points added to their account.<br>";

$queryref="select * from members where userid='$referid'";
$resultref = mysql_query ($queryref)
or die ("Query 1 failed");
$lineref = mysql_fetch_array($resultref);
$memtype = $line["memtype"];
if ($memtype=="PRO") {
$commission=$procommission;
}
elseif ($memtype=="JV Member") {
$commission=$jvcommission;
} elseif ($memtype=="SUPER JV") {
$commission=$superjvcommissions;
}

if ($prointerval=="Yearly") {
$oneyearago== date('Y-m-d',strtotime("-1 year"));
if ($subscribed==$oneyearago) {
$resultup="";
$queryup="";
$queryup="update members set commission=commission+".$commission." where userid='$referid'";
$resultup=mysql_query($queryup);
echo "$".$commission." commission added to ".$referid;
}
}
elseif ($prointerval=="Monthly") {
$resultup="";
$queryup="";
$queryup="update members set commission=commission+".$commission." where userid='$referid'";
$resultup=mysql_query($queryup);
echo "$".$commission." commission added to ".$referid;
}

}
}

$query = "select * from members where memtype='JV Member'";
$result = mysql_query ($query)
or die ("Query 1 failed");
while ($line = mysql_fetch_array($result)) {
$subscribed = $line["subscribed"];
$userid = $line["userid"];
$id = $line["id"];
$memtype = $line["memtype"];
$referid = $line["referid"];

if ($subscribed == $onemonthago) {

$query4 = "update members set points=points+".$jvpointsmonthly." where userid='".$userid."'";
$result4 = mysql_query ($query4)
or die ("Query 4 failed");
echo $userid." has had ".$jvpointsmonthly." points added to their account.<br>";

$queryref="select * from members where userid='$referid'";
$resultref = mysql_query ($queryref)
or die ("Query 1 failed");
$lineref = mysql_fetch_array($resultref);
$memtype = $line["memtype"];
if ($memtype=="PRO") {
$commission=$projvcom;
}
elseif ($memtype=="JV Member") {
$commission=$jvjvcom;
} elseif ($memtype=="SUPER JV") {
$commission=$superjvjvcom;
}

if ($jvinterval=="Yearly") {
$oneyearago== date('Y-m-d',strtotime("-1 year"));
if ($subscribed==$oneyearago) {
$resultup="";
$queryup="";
$queryup="update members set commission=commission+".$commission." where userid='$referid'";
$resultup=mysql_query($queryup);
echo "$".$commission." commission added to ".$referid;
}
}
elseif ($jvinterval=="Monthly") {
$resultup="";
$queryup="";
$queryup="update members set commission=commission+".$commission." where userid='$referid'";
$resultup=mysql_query($queryup);
echo "$".$commission." commission added to ".$referid;
}

}
}


$query = "select * from members where memtype='SUPER JV'";
$result = mysql_query ($query)
or die ("Query 1 failed");
while ($line = mysql_fetch_array($result)) {
$subscribed = $line["subscribed"];
$userid = $line["userid"];
$id = $line["id"];
$memtype = $line["memtype"];
$referid = $line["referid"];

if ($subscribed == $onemonthago) {

$query4 = "update members set points=points+".$superjvpointsmonthly." where userid='".$userid."'";
$result4 = mysql_query ($query4)
or die ("Query 4 failed");
echo $userid." has had ".$superjvpointsmonthly." points added to their account.<br>";

$queryref="select * from members where userid='$referid'";
$resultref = mysql_query ($queryref)
or die ("Query 1 failed");
$lineref = mysql_fetch_array($resultref);
$memtype = $line["memtype"];

if ($memtype=="PRO") {
$commission=$prosupercom;
}
elseif ($memtype=="JV Member") {
$commission=$jvsupercom;
} elseif ($memtype=="SUPER JV") {
$commission=$superjv2supercom;
}


if ($superjvinterval=="Yearly") {
$oneyearago== date('Y-m-d',strtotime("-1 year"));
if ($subscribed==$oneyearago) {
$resultup="";
$queryup="";
$queryup="update members set commission=commission+".$commission." where userid='$referid'";
$resultup=mysql_query($queryup);
echo "$".$commission." commission added to ".$referid;
}
}
elseif ($superjvinterval=="Monthly") {
$resultup="";
$queryup="";
$queryup="update members set commission=commission+".$commission." where userid='$referid'";
$resultup=mysql_query($queryup);
echo "$".$commission." commission added to ".$referid;
}

}
}
*/

//Prune
$sql = mysql_query("SELECT * FROM `members` WHERE `verified` = 0 AND `joindate` < '".date('Y-m-d',time()-24*60*60)."'");

while($each = mysql_fetch_array($sql)) {

	delete_account($each['userid']);

}

//Delete expired credit emails
 $sql = mysql_query("SELECT * FROM membermail WHERE sent=1 AND timestamp<='".(time()-30*24*60*60)."'");
 
 while($each = mysql_fetch_array($sql)) {
 
     $query2 = "delete from membermail_process where id='".$each['id']."'";
 	$result2 = mysql_query ($query2);
 	
 	$query2 = "delete from membermail_viewed where id='".$each['id']."'";
 	$result2 = mysql_query ($query2);
 
     $query3 = "delete from membermail where id='".$each['id']."'";
 	$result3 = mysql_query ($query3);
 
 }		

//Delete expired solos
$sql = mysql_query("SELECT * FROM solos WHERE added=1 AND sent=1 AND date<='".(time()-21*24*60*60)."'");

while($each = mysql_fetch_array($sql)) {

	$query2 = "delete from clicks where adid='".$each['id']."'";
	$result2 = mysql_query ($query2);

	$query3 = "delete from solos where id='".$each['id']."'";
	$result3 = mysql_query ($query3);

}

//Delete expired cash solos
$sql = mysql_query("SELECT * FROM cashsolos WHERE added=1 AND sent=1 AND date<='".(time()-21*24*60*60)."'");

while($each = mysql_fetch_array($sql)) {

	$query2 = "delete from cashclicks where adid='".$each['id']."'";
	$result2 = mysql_query ($query2);

	$query2 = "delete from cashlinks where adid='".$each['id']."'";
	$result2 = mysql_query ($query2);

	$query3 = "delete from cashsolos where id='".$each['id']."'";
	$result3 = mysql_query ($query3);

}

//Delete expired hp solos
$sql = mysql_query("SELECT * FROM hpsolos WHERE added=1 AND sent=1 AND date<='".(time()-21*24*60*60)."'");

while($each = mysql_fetch_array($sql)) {

	$query2 = "delete from hpclicks where adid='".$each['id']."'";
	$result2 = mysql_query ($query2);

	$query3 = "delete from hpsolos where id='".$each['id']."'";
	$result3 = mysql_query ($query3);

}

//Delete expired hpc solos
$sql = mysql_query("SELECT * FROM hpcsolos WHERE added=1 AND sent=1 AND date<='".(time()-21*24*60*60)."'");

while($each = mysql_fetch_array($sql)) {

	$query2 = "delete from hpcclicks where adid='".$each['id']."'";
	$result2 = mysql_query ($query2);

	$query2 = "delete from hpclinks where adid='".$each['id']."'";
	$result2 = mysql_query ($query2);

	$query3 = "delete from hpcsolos where id='".$each['id']."'";
	$result3 = mysql_query ($query3);

}


//Autoresponder
$sql = mysql_query("SELECT * FROM autoresponder WHERE message != '' AND subject != ''");
while($auto = mysql_fetch_array($sql)) {

	if($auto['memtype'] == "Free") $sql2 = mysql_query("SELECT * FROM members WHERE confirmed = '".date('Y-m-d',time()-$auto['days']*24*60*60-60*60)."' AND memtype='FREE'");
	elseif($auto['memtype'] == "Pro") $sql2 = mysql_query("SELECT * FROM members WHERE confirmed = '".date('Y-m-d',time()-$auto['days']*24*60*60-60*60)."' AND memtype='PRO'");
	else $sql2 = mysql_query("SELECT * FROM members WHERE confirmed = '".date('Y-m-d',time()-$auto['days']*24*60*60-60*60)."'");

	$Subjectold = $auto['subject'];
	$Messageold = $auto['message'];

	while ($line = mysql_fetch_array($sql2)) {
		$name = $line["name"];
		$userid = $line['userid'];
		$password = $line['pword'];
		$contactemail = $line["contact_email"];

		//reset values.
		$headers = "";
		$Subject = $Subjectold;
		$Message = $Messageold;

		//replace the merge fields.
		$Subject = stripslashes($Subject);
		$Subject = str_replace("~userid~",$userid,$Subject);
		$Subject = str_replace("~name~",$name,$Subject);
		$Subject = str_replace("~password~",$password,$Subject);

		$Message = stripslashes($Message);
		$Message = str_replace("~userid~",$userid,$Message);
		$Message = str_replace("~name~",$name,$Message);
		$Message = str_replace("~password~",$password,$Message);
		$Message = str_replace("~email~",$contactemail,$Message);

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

		$Message = str_replace("~fname~",$firstname,$Message);
		$Subject = str_replace("~fname~",$firstname,$Subject);

		$Message = "*********************\nAs a valued member of $sitename you have agreed to receive\ncontact from us. If you no longer want our messages, follow the instructions at the bottom.\n*********************\n\n".$Message."\n\n*********************\nYou are receiving this as you are a member of $sitename. You can opt out of receiving emails only by deleting your account, click here to delete your account.\n\n$domain/delete.php?userid=$userid&code=".md5($password)."\n\n$sitename\n$adminaddress";

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

		echo "Emailed $userid";

		mail($contactemail, $Subject, $Message,$headers);
	}

}




if($drawing == 1 AND date('w') == 0) {

	$sql = mysql_query("SELECT * FROM drawing ORDER BY rand()");
	$winner = mysql_fetch_array($sql);
	$count = mysql_num_rows($sql);


	mysql_query("update settings set setting='".$winner['userid']."' where name='drawwinner'");

	echo "Drawing Winner: ".$winner['userid']." \n";

	$sql = mysql_query("SELECT * FROM members WHERE userid='".$winner['userid']."'");
	while($winner2 = mysql_fetch_array($sql)) {



	}


}

mysql_query("DELETE FROM drawing WHERE 1");

mysql_query("UPDATE members SET textad1_clicks=textad1_clicks+textad_clicks, solo1_clicks=solo1_clicks+solo_clicks, banner1_clicks=banner1_clicks+banner_clicks, button1_clicks=button1_clicks+button_clicks, hotlink1_clicks=hotlink1_clicks+hotlink_clicks, htmlad1_clicks=htmlad1_clicks+htmlad_clicks, traffic1_clicks=traffic1_clicks+traffic_clicks, ptc1_clicks=ptc1_clicks+ptc_clicks, navtop1_clicks=navtop1_clicks+navtop_clicks, navbot1_clicks=navbot1_clicks+navbot_clicks, surf1_clicks=surf1_clicks+surf_clicks  WHERE 1");
echo "\n\n";


mysql_query("UPDATE members SET textad_clicks=0, banner_clicks=0, button_clicks=0, hotlink_clicks=0, htmlad_clicks=0, cashsolo_clicks=0, solo_clicks=0, traffic_clicks=0, ptc_clicks=0, navtop_clicks=0, navbot_clicks=0, surf_clicks=0 WHERE 1");
echo "\n\n";

$sql = mysql_query("SELECT * FROM prizes_won");
while($each = mysql_fetch_array($sql)) {
	echo $each['userid']." won ".$each['won']."\n";
}
mysql_query("DELETE FROM prizes_won WHERE 1");


mysql_query("UPDATE members SET bonus_viewed=0 WHERE 1");

if ($mpool=="1" OR $ppool=="1" AND date('w') == 0) {



	$sql = mysql_query("SELECT * FROM members WHERE memtype='PRO'");
	while($each = mysql_fetch_array($sql)) {
		$i = $proentry;
		while($i > 0) {
			mysql_query("INSERT INTO poolentry VALUES('".$each['userid']."')");
			$i--;
		}
	}



	$sql = mysql_query("SELECT * FROM members WHERE memtype='JV Member'");
	while($each = mysql_fetch_array($sql)) {
		$i = $jventry;
		while($i > 0) {
			mysql_query("INSERT INTO poolentry VALUES('".$each['userid']."')");
			$i--;
		}
	}
	$sql = mysql_query("SELECT * FROM members WHERE memtype='SUPER JV'");
	while($each = mysql_fetch_array($sql)) {
		$i = $superjventry;
		while($i > 0) {
			mysql_query("INSERT INTO poolentry VALUES('".$each['userid']."')");
			$i--;
		}
	}


}

if(date('l')=="Friday") $sql = mysql_query("SELECT * FROM snfsolos WHERE approved=1 AND solos_left>0 AND (type='".date('l')."' OR type='Mon/Wed/Fri')");
elseif(date('l')=="Tuesday") $sql = mysql_query("SELECT * FROM snfsolos WHERE approved=1 AND solos_left>0 AND (type='".date('l')."' OR type='Tues/Thurs/Sat')");
elseif(date('l')=="Thursday" OR date('l')=="Saturday") $sql = mysql_query("SELECT * FROM snfsolos WHERE approved=1 AND solos_left>0 AND (type='".date('l')."' OR type='Tues/Thurs/Sat')");
elseif(date('l')=="Monday" OR date('l')=="Wednesday") $sql = mysql_query("SELECT * FROM snfsolos WHERE approved=1 AND solos_left>0 AND (type='".date('l')."' OR type='Mon/Wed/Fri')");
else $sql = mysql_query("SELECT * FROM snfsolos WHERE approved=1 AND solos_left>0 AND type='".date('l')."'");

if(@mysql_num_rows($sql)) {
	while($each = mysql_fetch_array($sql)) {
		mysql_query("UPDATE snfsolos SET solos_left=solos_left-1 WHERE id='".$each['id']."'");
		mysql_query("INSERT INTO solos SET userid='".$each['userid']."', added=1, approved=1, date='".time()."', subject='".str_replace("'","\'", $each['subject'])."', adbody='".str_replace("'","\'", $each['adbody'])."', url='".str_replace("'","\'", $each['url'])."', scheduled=1");
	}
}
mysql_query("DELETE FROM snfsolos WHERE solos_left=0");

if(date('l')=="Friday") $sql = mysql_query("SELECT * FROM snfcsolos WHERE approved=1 AND cashsolos_left>0 AND (type='".date('l')."' OR type='Mon/Wed/Fri')");
elseif(date('l')=="Tuesday") $sql = mysql_query("SELECT * FROM snfcsolos WHERE approved=1 AND cashsolos_left>0 AND (type='".date('l')."' OR type='Tues/Thurs/Sat')");
elseif(date('l')=="Thursday" OR date('l')=="Saturday") $sql = mysql_query("SELECT * FROM snfcsolos WHERE approved=1 AND cashsolos_left>0 AND (type='".date('l')."' OR type='Tues/Thurs/Sat')");
elseif(date('l')=="Monday" OR date('l')=="Wednesday") $sql = mysql_query("SELECT * FROM snfcsolos WHERE approved=1 AND cashsolos_left>0 AND (type='".date('l')."' OR type='Mon/Wed/Fri')");
else $sql = mysql_query("SELECT * FROM snfcsolos WHERE approved=1 AND cashsolos_left>0 AND type='".date('l')."'");

if(@mysql_num_rows($sql)) {
	while($each = mysql_fetch_array($sql)) {
		mysql_query("UPDATE snfcsolos SET cashsolos_left=cashsolos_left-1 WHERE id='".$each['id']."'");
		mysql_query("INSERT INTO cashsolos SET userid='".$each['userid']."', added=1, approved=1, date='".time()."', subject='".str_replace("'","\'", $each['subject'])."', adbody='".str_replace("'","\'", $each['adbody'])."', url='".str_replace("'","\'", $each['url'])."', scheduled=1");
	}
}
mysql_query("DELETE FROM snfcsolos WHERE cashsolos_left=0");

mysql_close($dblink);

 ?>