<?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($drawing == 1) {
		
        
		$query = "SELECT * FROM pages where name='Cycler'";
		$result = mysql_query ($query)
			or die ("Query failed");
		while ($line = mysql_fetch_array($result)) {
			$htmlcode = $line["htmlcode"];
			echo dbget($htmlcode);
        }		
		
		echo "<br>";
		
			$tickets = intval($_POST['tickets']);
			if($tickets) {
			
				if($points < $tickets*$drawprice) {
				
				echo "<font color=red></font>";
				
				}
				else {
				
				
					mysql_query("UPDATE members SET points=points-".($tickets*$drawprice)." WHERE userid = '".$userid."'");
					
					mysql_query("INSERT INTO transactions VALUES ('id','".$userid."','$tickets Draw tickets','".time()."','-".($tickets*$drawprice)." points')");
					
					
					$added = $tickets;
					while($tickets > 0) {
						mysql_query("INSERT INTO drawing VALUES('".$userid."')");
						$tickets--;
					}
					
					echo "<br><br>";
				
				}
					
			}

			
			$scount = mysql_query("SELECT COUNT(*) FROM drawing  WHERE userid = '".$userid."'");
			$count = intval(mysql_result($scount, 0));
			
			if($drawwinner != "") $drawwinner = '';

	  echo "";
	  ?>
		
	  

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


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

else
  { ?>

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

  <? }

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