<?php
	include("inside/config.php");
	session_start();
	$user=$_SESSION['username'];
	if(empty($user))
	{
		echo "<script>window.location='login.php'</script>";
	}
	$currentpage = "index";
	$id=$_REQUEST['id'];
	$sql=mysql_query("select * from `articles` where `article_id`='$id'");
	$row=mysql_fetch_array($sql);
	
	if($_REQUEST['action']=="delete")
	{
		$id=$_REQUEST['id'];
		$sqlDel=mysql_query("delete from `articles` where `article_id`='$id'");
		$type = "ok";
		$msg = "Article Deletion Successful! ";
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
	<title>Admin Panel : Frontier Public High School</title>
	<link rel="stylesheet" href="css/style.css" type="text/css" media="all" />
<?php include('inside/jsfunctions.php'); ?>
</head>
<body>
<?php include('inside/header.php'); ?>
<!-- Container -->
<div id="container">
	<div class="shell">
		
		<!-- Small Nav -->
		<div class="small-nav">
			<a href="#">Dashboard</a>
			<span>&gt;</span>
			Current Articles
		</div>
		<!-- End Small Nav -->
		
		<!-- Message OK -->		
		<?php if($type=="ok"){ ?>
        <div class="msg msg-ok" id="msgok">
			<p><strong><?php echo $msg; ?></strong></p>
			<a href="#" class="close" onclick="removeOk()">close</a>
		</div>
		<!-- End Message OK -->		
		<?php } ?>
		<!-- Message Error -->
		<?php if($type=="error"){ ?>
		<div class="msg msg-error" id="error">
			<p><strong><?php echo $msg; ?></strong></p>
			<a href="#" class="close" onclick="removeError()">close</a>
		</div>
        <?php } ?>
		<!-- End Message Error -->
		<br />
		<!-- Main -->
		<div id="main">
			<div class="cl">&nbsp;</div>
			
			<!-- Content -->
			<div id="content">
				
				<!-- Box -->
				<div class="box">
					<!-- Box Head -->
					<div class="box-head">
						<h2 class="left">Current Articles					</h2>
					</div>
					<!-- End Box Head -->	

					<!-- Table -->
					<div class="table">
					  <table width="100%" border="0" cellspacing="0" cellpadding="0">
					    <tr>
					      <th>Title</th>
					      <th>Page Name</th>
					      <th>Initial Contents</th>
					      <th width="110" class="ac">Content Control</th>
				        </tr>
					   
<?php
					  		$sql2=mysql_query("select * from `articles`");
					  		while($row2=mysql_fetch_array($sql2))
					  		{
					  		$content=$row2['article_content'];
					  		$detail=substr($content,0,25);
					  		$content=$detail.".";
					  		?>                        <tr>
  <td class="odd"><h3><a href="article-detail.php?id=<?php echo $row2['article_id'];?>"><?php echo $row2['article_heading']; ?></a></h3></td>
					      <td><?php echo $row2['page_name']; ?></td>
					      <td><?php echo $content; ?></td>
					      <td><a  class="ico del" href="index.php?action=delete&id=<?php echo $row2['article_id'];?>" onclick="return confirm('Are you sure you want to delete?')">Delete</a>
                          	  <a  class="ico edit" href="edit-article.php?id=<?php echo $row2['article_id']; ?>">Edit</a></td>
				        </tr>
                        <?php
					  		}
					  		?>
				      </table>
					  <!-- Pagging --><!-- End Pagging -->
						
					</div>
					<!-- Table -->
					
				</div>
				<!-- End Box -->
				
				<!-- Box --><!-- End Box -->

			</div>
			<!-- End Content -->
			
			<!-- Sidebar -->
			<div id="sidebar">
				
				<!-- Box -->
				<div class="box">
					
					<!-- Box Head -->
					<div class="box-head">
						<h2>Management</h2>
					</div>
					<!-- End Box Head-->
					
					<div class="box-content">
						<a href="new-article.php" class="add-button"><span>Add new Article</span></a>
						<div class="cl">&nbsp;</div>

						<!-- Sort --><!-- End Sort -->
						
					</div>
				</div>
				<!-- End Box -->
			</div>
			<!-- End Sidebar -->
			
			<div class="cl">&nbsp;</div>			
		</div>
		<!-- Main -->
	</div>
</div>
<!-- End Container -->
<?php include("inside/footer.php"); ?>
</body>
</html>