<?php 
	session_start();
	include ('../config.php');
	include ('secureadmin.php');
	
	$metatitle = "Edit Author - Admin Control Panel";
	include ('includes/document_head.php');
	
	$authorid = $_GET['id'];
	
	
	$query = "select * from authors where id = ".$authorid.";"; 
	$result = mysql_query($query,$connection) or die(mysql_error());
	$info = mysql_fetch_assoc($result);
	// get this category's information
	$name = $info['fname'];
	$status = $info['status'];
	$email = $info['email'];
	$username = $info['username'];
	$displayname = $info['displayname'];
	$bio = $info['bio'];	
	$url = $info['url'];	
	$avatar = $info['gravatar'];	
	
	if($status == 0) {
		$status = "Active";
		$action = "Ban";
	} else {
		$status = "Banned";
		$action = "Restore";
	}

		
?>
		<div id="wrapper">
			<?php include 'includes/topbar.php'?>		
			<?php include 'includes/sidebar.php'?>
			<div class="main_container container_16 clearfix">
				
					
			<div class="flat_area grid_16">
			
			
		
	<div class="box grid_8 round_all">
		<div class="block">
			<h2>Profile Settings for <?php echo $name; ?></h2>
					
	

	
	<div style="float:left; padding: 7px;"><img src="<?php echo $avatar; ?>" /></div>
	
	<b>Pen Name:</b> <?php echo $displayname; ?><br/><br/>
	
	<b>Homepage:</b> <a href="<?php echo $url; ?>"><?php echo $url; ?></a><br/><br/>
	<div style="clear: both;"></div>
	<b>Bio:</b> <br/><div style="width: 300px;"><?php echo $bio; ?></div><br/>
	
			</div>
		</div>



			<div class="box grid_8 round_all">
			<div class="block">
	<h2>Account Settings for <?php echo $name; ?></h2>
					
	<b>Name:</b> <?php echo $name; ?><br/><br/>
		
	<b>Username:</b> <?php echo $username; ?><br/><br/>
	
	<b>Status:</b> <?php echo $status; ?><br/><br/>
	
	<b>Email:</b> <?php echo $email; ?><br/><br/>
	
			<a href="authors.php?status=<?php echo $info['status']; ?>&id=<?php echo $authorid; ?>"><button  class="skin_colour round_all"><img width="24" height="24" src="images/icons/small/white/Create Write.png"><span><?php echo $action; ?> User</span></button></a>


	<br/><br/><br/>
	
			</div>
		</div>
		

	</div>
	
	<br/><br/>
	<h2>All Articles by <?php echo $name; ?></h2>
				<div class="box grid_16 round_all">
				<table class="display table"> 
					<thead> 
						<tr> 
							<th>ID</th> 
							<th>Date</th>
							<th>Author</th> 
							<th>Title</th> 
							<th>Views</th>
							<th>Status</th>
						</tr> 
					</thead> 
					<tbody> 
					
					
<?php // Populates the Dropdown list with all categories and subcats
	$query = "select * from articles where authorid=".$authorid; 
	$result = mysql_query($query,$connection) or die(mysql_error());
	$num_results = mysql_num_rows($result);
		
	
	for ($i=0; $i <$num_results; $i++) { 
		$row = mysql_fetch_assoc($result);
		
		$date = strtotime($row['date']);
		$artdate = date('m/d/y', $date);
		
		
		// Get Author Display Name
		$authquery = "select * from authors where id=".$row['authorid']; 
		$authresult = mysql_query($authquery,$connection) or die(mysql_error());
		$authinfo = mysql_fetch_assoc($authresult);
		
		// Get Views
		$viewquery = "select * from articleviews where articleid=".$row['id']; 
		$viewresult = mysql_query($viewquery,$connection) or die(mysql_error());
		$viewinfo = mysql_fetch_assoc($viewresult);
		$views = $viewinfo['views'];
		if (!$views) $views = "-";

		if($row['status'] == 0) {
			$status = "Active";
		} elseif($row['status'] == 1) {
			$status = "In Review";
		} else {
			$status = "Problem";
		}
		
		echo "<tr> <td>".$row['id']."</td> 
			 <td>".$artdate."</td> 
			 <td>".$authinfo['displayname']."</td>
			 <td><a href=\"articleview.php?id=".$row['id']."\">".$row['title']."</a></td>
			 <td>".$views."</td>
			 <td>".$status."</td></tr>";
		}
?>

					</tbody> 
				</table>
			</div>

		
			
		</div>	
<?php include 'includes/closing_items.php'?>