<?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 "<br><H2><center><img src=images/cash&pointsjackpot.png></H2><center><img src=images/jackpot.gif></center>";
       
        if ($mpool=="1" OR $ppool=="1") {
		
		
	$query1 = "SELECT * FROM pages WHERE name='Pool'";
    $result1 = mysql_query ($query1);

    $line1 = mysql_fetch_array($result1);
         $htmlcode = $line1["htmlcode"];

    echo dbget($htmlcode)."<br><br>";
		
		
		
			$tickets = intval($_POST['tickets']);
			if($tickets) {
			
				if($points < $tickets*$poolentryprice) {
				
				echo "<font color=red>You don't have enough points.</font>";
				
				}
				else {
				
				
					mysql_query("UPDATE members SET points=points-".($tickets*$poolentryprice)." WHERE userid = '".$userid."'");
					
					mysql_query("INSERT INTO transactions VALUES ('id','".$userid."','$tickets Jackot Tickets','".time()."','-".($tickets*$poolentryprice)." points')");
										
					$added = $tickets;
					while($tickets > 0) {
						mysql_query("INSERT INTO poolentry VALUES('".$userid."')");
						$tickets--;
					}
					
					echo "You have successfully purchased $added Jackpot entry tickets.<br><br>";
				
				}
					
			}

			
			$scount = mysql_query("SELECT COUNT(*) FROM poolentry  WHERE userid = '".$userid."'");
			$count = intval(mysql_result($scount, 0));
			
			
	  echo "You currently have $points points and $count chance(s) to win.";
	  ?>
	  <form action="poolentry.php" method="post">
	  <input type="text" name="tickets" value="1"> x <? echo $poolentryprice; ?> points<br>
	  <input type="submit" value="Buy">
	  </form>
	  </center>	
<?

if ($mpool=="1") {	

    	echo "<font size=2 face='$fonttype' color='$fontcolour'><p><b><center>";
        echo "<H2><font color=green>Cash Jackpot Winners List</font></H2><br>Last 10 Winners";
        $query = "select * from moneywinner ORDER BY id DESC LIMIT 10";
		$result = mysql_query ($query)
	     	or die ("Query failed");
        $numrows = @ mysql_num_rows($result);
        if ($numrows == 0) {
        	echo "<p><center>No winners yet.</p></center>";

        }
        ?>
            <table width=70% border=0 cellpadding=2 cellspacing=2>
        	<tr>
 <td bgcolor="<? echo $contrastcolour; ?>"><center><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>">Date</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; ?>">Amount</font></center></td>
            	        </tr>
        <?
    	while ($line = mysql_fetch_array($result)) {
			$id = $line["id"];
            $userid = $line["userid"];
            $amount = $line["amount"];
            $date = $line["paiddate"];


        ?><tr>
<td bgcolor="<? echo $basecolour; ?>"><center><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $date; ?></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 $amount; ?></font></center></td>
          </tr> <?
        }
        echo "</table></center><br><br>" ;
       } //endifmpool

       if ($ppool=="1") {

echo "<font size=2 face='$fonttype' color='$fontcolour'><p><b><center>";
        echo "<H2><font color=green>Points Jackpot Winners List</font></H2><br>Last 10 Winners";
        $query = "select * from pointswinner ORDER BY id DESC LIMIT 10";
		$result = mysql_query ($query)
	     	or die ("Query failed");
        $numrows = @ mysql_num_rows($result);
        if ($numrows == 0) {
        	echo "<p><center>No winners yet.</p></center>";

        }
        ?>
            <table width=70% border=0 cellpadding=2 cellspacing=2>
        	<tr>
 <td bgcolor="<? echo $contrastcolour; ?>"><center><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>">Date</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; ?>">Amount</font></center></td>
            	        </tr>
        <?
    	while ($line = mysql_fetch_array($result)) {
			$id = $line["id"];
            $userid = $line["userid"];
            $amount = $line["amount"];
            $date = $line["paiddate"];

        ?><tr>
<td bgcolor="<? echo $basecolour; ?>"><center><font size=2 face="<? echo $fonttype; ?>" color="<? echo $fontcolour; ?>"><? echo $date; ?></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 $amount; ?> Points</font></center></td>
          </tr> <?
        }
        echo "</table></center><br><br>" ;
       

} //endifppool
?>
	

		
		<?
		} else echo "The weekly pool drawing is disabled.";
		
		

	echo "<br><br><br></td></tr></table>";
  

 }

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