<?php
require_once("../includes/user_data.php");

if(isset($user_data)){
	if($user_data['admin_flag']==1){
	
	if(isset($_GET['action'])){
		if($_GET['action'] == "delete"){
			if((int)$_GET['user_ID']>0){
				mysql_query("DELETE FROM Users WHERE ID = ".(int)$_GET['user_ID']." LIMIT 1");
			}
			elseif((int)$_GET['event_ID']>0){
				mysql_query("DELETE FROM Events WHERE ID = ".(int)$_GET['event_ID']." LIMIT 1");
			}
			elseif((int)$_GET['comment_ID']>0){
				mysql_query("DELETE FROM Comments WHERE ID = ".(int)$_GET['comment_ID']." LIMIT 1");
			}
			elseif((int)$_GET['forum_topic_ID']>0){
				mysql_query("DELETE FROM Forum_Topics WHERE ID = ".(int)$_GET['forum_topic_ID']." LIMIT 1");
			}			
		}
	}
	?>
	<h1>Moderation Control Panel (You Are Logged In)</h1>
	
		<p>Direct DB access is probably the best method at this point, but you can delete users/comments/posts/events here.</p>
		
		<p>
			There is no undo available. Delete carefully.
		</p>
	
		<h3>Last 100 Users</h3>
		
		<ul>
		<?php
		$result = mysql_query("SELECT * FROM Users LIMIT 100");
		while($row = mysql_fetch_assoc($result)){
		?>
			<li>
				<a href="controlpanel.php?user_ID=<?=$row['ID'];?>&action=delete">Delete User</a> - 
				
				<?=$row['first_name']." ".$row['last_name'];?>
				in 
				<?=$row['city'].", ".$row['state'];?>
				- Email: <?=$row['email'];?>
			
			</li>
		<?php
		}
		?>
		</ul>
		
		<h3>Last 100 Events</h3>
		<ul>
		<?php
		$result = mysql_query("SELECT * FROM Events LIMIT 100");
		while($row = mysql_fetch_assoc($result)){
			$number_attendees = (int)mysql_num_rows(mysql_query("SELECT ID FROM Events_RSVP WHERE event_ID = ".(int)$row['ID']));

			?>
			
			<li>
				<a href="controlpanel.php?event_ID=<?=$row['ID'];?>&action=delete">Delete Event</a> - 
				"<?=stripslashes($row['title']);?>" being held in <?=$row['city'].",".$row['state'];?> -
				<?=$number_attendees;?> people attending.
			</li>
			
			<?php
			
		}
		?>
		</ul>

		<h3>Last 100 Forum Topics</h3>
		<ul>
			<?php
			$result= mysql_query("SELECT * FROM Forum_Topics");
			while($row = mysql_fetch_assoc($result)){
				?>
				
					<li>
						<a href="controlpanel.php?forum_topic_ID=<?=$row['ID'];?>&action=delete">Delete Topic</a> - 
						<?=$row['topic'];?> posted <?=$row['TS'];?>
					</li>
				
				<?php
			}
			?>
		</ul>

		<h3>Last 300 Forum Posts/Comments</h3>
		<ul>
		<?php
			$result = mysql_query("SELECT * FROM Comments");
			while($row = mysql_fetch_assoc($result)){
			?>
				<li>
					<a href="controlpanel.php?comment_ID=<?=$row['ID'];?>&action=delete">Delete Post</a><br>
					<textarea rows="4" cols="100"><?=$row['body'];?></textarea> <br>Posted <?=$row['TS'];?>
					
					<hr>
				</li>
			<?php
			}
		?>
		</ul>
		
	
	<?php
	}
	else
		print "You are not an administrator.";
}
else
	header("Location:http://".$_SERVER['SERVER_NAME']."/user_login.php?validation=You are not logged in.");
?>

