<?php 

session_start(); 
include "../config.php";
include "../header.php";
include "../style.php";
if( isset($_SESSION["alogin"]) ) {

?><table> 

<tr> 

<td width="15%" valign=top><br> 

<? include("adminnavigation.php"); ?> 

</td> 

<td valign="top" align="center"><br><br> 




<?php 


$query = "SELECT * FROM poolentry ORDER BY RAND() LIMIT 1"; 
$result = mysql_query ($query); 

$line = mysql_fetch_array($result); 
$userid = $line["userid"]; 


$query = "select * from pool where name='points'"; 
$result = mysql_query ($query) 
or die ("Query failed"); 

$line = mysql_fetch_array($result); 
$amount= $line["amount"]; 


$today = date("Y-m-d"); 

mysql_query("update members set points=points+round(".$amount.") where userid='".$userid."'"); 
echo "<b>".round($amount)."</b> <font color=BLUE>points has been added to ".$userid."'s account.</font><br>"; 

echo "-<b>".round($amount)."</b> <font color=BLUE>points have been removed from the points pool.</font><br>"; 

mysql_query("update pool set amount=amount-".$amount." +2500 where name='points'"); 

echo "<b>2500</b> <font color=BLUE>points have added to the points pool.</font><br>"; 


$won=round($amount); 
$query = "insert into pointswinner (userid,amount,paiddate) VALUES ('$userid','$won','$today')"; 
$result = mysql_query ($query) 
or die ("Insert failed"); 

echo "<b>".$userid."</b> <font color=BLUE>has been added to the winners table.</font><br>"; 

mysql_query("INSERT INTO transactions VALUES ('".$userid."',' Points Pool Winner ','".time()."','$won points added to their account')");


//get all members details....
$query4 = "select * from members where status=1 and verified=1 and vacation=0";
$result4 = mysql_query ($query4)
or die ("Query failed");
while ($line4 = mysql_fetch_array($result4)) {

$from_address = "";
$email = $line4["subscribed_email"];
$memtypeq = $line4["memtype"];
$useridq = $line4["userid"];
$nameq = $line4["name"];
$passwordq = $line4["pword"];
$wonq = $line4["won"];

//now we've got all we need, so blast the ad out!

$Subject = "POINTS JACKPOT WINNER NOTICE ".$subject;
$Message = "A winner has been randomly chosen for the Points Jackpot and ".$won." points have been added to the winner's account.\nLogin and see who the winner is. It could be you!";
$Message .= "\n\n--------------------------------------------------------------\n\n";
$Message .= "".$domain."\n";
$Message .= "--------------------------------------------------------------\n\n";
$Message .= "This is not SP@M. You are receiving this because you are a member of '$sitename' and agreed to receive solo ads as part of our Terms & Conditions\n\n";
$Message .= "If You wish to BE REMOVED from Future Messages, Please Login and Delete your Membership or Click the Delete Link below this Message.\n\n$domain/delete.php?userid=$useridq&code=".md5($passwordq).".\n\n";
$Message .= "$sitename\n$adminname\n$adminaddress\n";

$headers = "From: $sitename<$adminemail>\n";
$headers .= "Reply-To: <$adminemail>\n";
$headers .= "X-Sender: <$adminemail>\n";
$headers .= "X-Mailer: PHP4\n";
$headers .= "X-Priority: 1\n";
$headers .= "Return-Path: <$adminemail>\n";



$nameq = trim($nameq);
$firstnameq = substr($nameq , 0, strpos($nameq, " "));


$Message = str_replace("~won~",$wonq,$Message);
$Message = str_replace("~fname~",$firstnameq,$Message);
$Subject = str_replace("~userid~",$useridq,$Subject);
$Subject = str_replace("~fname~",$firstnameq,$Subject);

mail($email, $Subject, wordwrap(stripslashes($Message)),$headers);

$counter=$counter+1;

} // end while ($line4 = mysql_fetch_array($result))





?> 





<center><table><tr><td> 


</td></tr></table></center> 




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

else 

echo "Unauthorised Access!"; 



include "../footer.php"; 



?> 