<?php 
	session_start();
	include ('../config.php');
	include ('secureadmin.php');
	
	if(isset($_GET['deleteid'])) { 
	
	$deleteid = $_GET['deleteid'];
	
		$sql = "DELETE from `articles` WHERE `id`=".$deleteid.";";
			$query = mysql_query($sql);
			header('Location: articleactive.php');
			exit();	
}

	$metatitle = "Active Articles - Admin Control Panel";	
	include ('includes/document_head.php');

?>
		<div id="wrapper">
			<?php include 'includes/topbar.php'?>		
			<?php include 'includes/sidebar.php'?>
			<div class="main_container container_16 clearfix">
				
<!-- CONFIRM DELETE -->
<script type="text/javascript">
function confirmDelete(delUrl) {
  if (confirm("Are you sure you want to delete this article? It will be removed immediately.")) {
    document.location = delUrl;
  }
}
</script>

			<div class="flat_area grid_16">
			
				<h2>Active Articles</h2>
				<p>These articles have been approved and are currently live across your directory.</p><br/>
			</div>
			<div class="box grid_16 round_all">
				<table class="display table"> 
					<thead> 
						<tr> 
							<th width="5%">ID</th> 
							<th width="8%">Date</th>
							<th width="52%">Title</th> 
							<th width="15%">Author</th> 
							<th width="25%">Actions</th>
						</tr> 
					</thead> 
					<tbody> 
					
					
<?php // Populates the Dropdown list with all categories and subcats
	$query = "select * from articles where status=0"; 
	$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><a href=\"articleedit.php?id=".$row['id']."\">".$row['title']."</a></td>
			 <td><a href=\"authoredit.php?id=".$authinfo['id']."\">".$authinfo['displayname']."</a></td>
			 <td> <a href=\"markproblem.php?id=".$row['id']."\">Mark Problem</a> | <a href=\"javascript:confirmDelete('articleactive.php?deleteid=".$row['id']."')\">Delete</a></td></tr>";
		}
?>

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


				</div>				
			
			
			


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