<?php

session_start();

include "../config.php";

if( isset($_SESSION["ulogin"]) )
   	{  // members only stuff!
        
		$tickets = $userrecord['tickets'];
		
		
		if($tickets) {
		
			mysql_query("UPDATE members SET tickets=tickets-1 WHERE userid='$userid'");
			$tickets--;
			
			$number = rand(0,10000);
			if($number <= 7700) {
			
		//		echo "Try Again";
			$castigator=0;
			
			} elseif($number <=8000) {
				mysql_query("INSERT INTO game_winners SET userid='$userid', date='".time()."', won='1 Traffic Link w/50 views'");
				mysql_query("insert into tlinks (userid,paid) values('$userid','50')");
					
				$castigator=4;	
			//	echo "You just won 1 Traffic Link w/50 views";
			
			
			} elseif($number>=10007) {
				mysql_query("INSERT INTO game_winners SET userid='$userid', date='".time()."', won='1 Solo'");
				mysql_query("INSERT INTO `solos` (`id` ,`userid` ,`approved` ,`subject` ,`adbody` ,`sent` ,`added`) VALUES (NULL , '".$userid."', '0', '', '', '0', '0')");
					
			$castigator=1;		
			//	echo "You just won 1 Solo";	
				
			} elseif($number<=8100) {
				mysql_query("INSERT INTO game_winners SET userid='$userid', date='".time()."', won='5,000 Points'");
				mysql_query("UPDATE members SET points=points+5000 WHERE userid='$userid'");
					
					$castigator=8;
			//	echo "You just won 5,000 Points";
				
			} elseif($number<=8700) {
				mysql_query("INSERT INTO game_winners SET userid='$userid', date='".time()."', won='10,000 Points'");
				mysql_query("UPDATE members SET points=points+10000 WHERE userid='$userid'");
					
				$castigator=9;	
			//	echo "You just won 10,000 Points";
				
			} elseif($number>=10003) {
				mysql_query("INSERT INTO game_winners SET userid='$userid', date='".time()."', won='25,000 Points'");
				mysql_query("UPDATE members SET points=points+25000 WHERE userid='$userid'");
					
			$castigator=10;		
			//	echo "You just won 25,000 Points";
				
			} elseif($number>=10006) {
				mysql_query("INSERT INTO game_winners SET userid='$userid', date='".time()."', won='50,000 Points'");
				mysql_query("UPDATE members SET points=points+50000 WHERE userid='$userid'");
					
				$castigator=11;	
			//	echo "You just won 50,000 Points";
				
			} elseif($number>=10005) {
				mysql_query("INSERT INTO game_winners SET userid='$userid', date='".time()."', won='100,000 Points'");
				mysql_query("UPDATE members SET points=points+100000 WHERE userid='$userid'");
				$castigator=12;
			//	echo "You just won 100,000 Points";
				
				
			} elseif($number<=9000) {
				mysql_query("INSERT INTO game_winners SET userid='$userid', date='".time()."', won='1 PTC w/50 views'");
				mysql_query("insert into ptcads (userid,paid) values('$userid','50')");
					
				$castigator=3;	
			//	echo "You just won 1 PTC w/50 views";	
				
			} elseif($number<=8200) {
				mysql_query("INSERT INTO game_winners SET userid='$userid', date='".time()."', won='1 Login Ad'");
				mysql_query("insert into loginads (userid,max) values('$userid','1000')");
					
				$castigator=5;	
			//	echo "You just won 1 Login Ad";	
				
			} elseif($number<=7900) {
				mysql_query("INSERT INTO game_winners SET userid='$userid', date='".time()."', won='1 Banner Ad'");
				mysql_query("insert into banners (userid,max) values('$userid','1000')");
					
				$castigator=6;	
			//	echo "You just won 1 Banner Ad";	
				
			} elseif($number<=8600) {
				mysql_query("INSERT INTO game_winners SET userid='$userid', date='".time()."', won='1 Button Banner'");
				mysql_query("insert into buttons (userid,max) values('$userid','1000')");
					
				$castigator=7;	
			//	echo "You just won 1 Button Banner";	
				
			} elseif($number>=10004) {
				mysql_query("INSERT INTO game_winners SET userid='$userid', date='".time()."', won='1 Cash Solo'");
				mysql_query("insert into cashsolos (userid) values('$userid')");
					
				$castigator=2;	
			//	echo "You just won 1 Cash Solo";	
				

			} elseif($number<=8000) {
			
				mysql_query("INSERT INTO game_winners SET userid='$userid', date='".time()."', won='\$0.10'");
				mysql_query("UPDATE members SET commission=commission+0.10 WHERE userid='$userid'");
					
				$castigator=13;	
			//	echo "You just won \$0.10";					

			} elseif($number<=8400) {
				mysql_query("INSERT INTO game_winners SET userid='$userid', date='".time()."', won='\$0.25'");
				mysql_query("UPDATE members SET commission=commission+0.25 WHERE userid='$userid'");
					
					$castigator=14;
			//	echo "You just won \$0.25";		

			} elseif($number<=8800) {
				mysql_query("INSERT INTO game_winners SET userid='$userid', date='".time()."', won='\$0.50'");
				mysql_query("UPDATE members SET commission=commission+0.50 WHERE userid='$userid'");
					
				$castigator=15;	
			//	echo "You just won \$0.50";	
				
			} elseif($number<=9200) {
				mysql_query("INSERT INTO game_winners SET userid='$userid', date='".time()."', won='\$0.75'");
				mysql_query("UPDATE members SET commission=commission+0.75 WHERE userid='$userid'");
					
				$castigator=16;	
			//	echo "You just won \$0.75";	
				
			} elseif($number>=10009) {
				mysql_query("INSERT INTO game_winners SET userid='$userid', date='".time()."', won='\$1.00'");
				mysql_query("UPDATE members SET commission=commission+1.00 WHERE userid='$userid'");
					
				$castigator=17;	
			//	echo "You just won \$1.00";		
				
				
			} elseif($number>=10008) {
				mysql_query("INSERT INTO game_winners SET userid='$userid', date='".time()."', won='\$2.50'");
				mysql_query("UPDATE members SET commission=commission+2.50 WHERE userid='$userid'");
					
				$castigator=18;	
			//	echo "You just won \$2.50";	

				
			} elseif($number>=10002) {
				mysql_query("INSERT INTO game_winners SET userid='$userid', date='".time()."', won='\$5.00'");
				mysql_query("UPDATE members SET commission=commission+5.00 WHERE userid='$userid'");
					
			$castigator=19;		
			//	echo "You just won \$5.00";		

				
			} elseif($number>=10001) {
				mysql_query("INSERT INTO game_winners SET userid='$userid', date='".time()."', won='\$10.00'");
				mysql_query("UPDATE members SET commission=commission+10.00 WHERE userid='$userid'");
					
				$castigator=20;	
			//	echo "You just won \$10.00";						
				
				
			}
			
         //$start=intval(rand(0,20));
		 $start = 1;
       echo("&start=1&castigator=".$castigator."&nbTickets=".$tickets);

	}
    
    }

else
  {  echo("&start=1&castigator=0&nbTickets=".$tickets); }

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