<?php 
include('config.php');
	
	$article = $_GET['id'];
	
		$sitequery = 'select * from settings;';
	$siteresult = mysql_query($sitequery,$connection) or die(mysql_error());
	
	//Create site settings variables		
	$siteinfo = mysql_fetch_array($siteresult);
	$sitetitle = $siteinfo['title'];
	$siteurl = $siteinfo['url'];


	$query = "select * from articles where status=0 and id = ".$article;
	
	$articleresults = mysql_query($query,$connection) or die(mysql_error());
	$num_results = mysql_num_rows($articleresults);
	$articleinfo = mysql_fetch_array($articleresults);
	
	if (!$num_results) {
		header('Location: '.$siteurl);
	}
	
//Get article info	
	$id = $$articleinfo['id'];
	$authorid = $articleinfo['authorid'];
	$date = strtotime($articleinfo['date']);
	$artdate = date('m/d/y', $date);
	$categoryid = $articleinfo['categoryid'];
	$title = stripslashes($articleinfo['title']);
	$body = stripslashes($articleinfo['body']);
	$resource = $articleinfo['resource'];
	
	
//Meta Info
$cathead = 0;
$metatitle = $title." - ";
$descbody = filter_var( $body, FILTER_SANITIZE_STRING );
$metadesc = '<META NAME="Description" CONTENT="'.substr($descbody, 0, 150).'...">';
include('header.php'); 
include('sidebar.php'); 

	if ($seourls == 1) { $scrubtitle = generate_seo_link($title); }
//get author info
	$authorquery = "select * from authors where id=".$authorid;
	$authorresult = mysql_query($authorquery,$connection) or die(mysql_error());
	$authorinfo = mysql_fetch_array($authorresult);
	$authorname = $authorinfo['displayname'];
	$authorbio = $authorinfo['bio'];
	$gravatar = $authorinfo['gravatar'];
	if ($seourls == 1) { $scrubauthor = generate_seo_link($authorname); }
	
//get category info
	$catquery = "select * from categories where id=".$categoryid;
	$catresult = mysql_query($catquery,$connection) or die(mysql_error());
	$catinfo = mysql_fetch_array($catresult);
	$categoryname = $catinfo['name'];
	$catparent = $catinfo['parentid'];
	if ($seourls == 1) { $scrubcatname = generate_seo_link($categoryname); }
	
	if ($catparent == NULL) {
			if ($seourls == 1) { // With SEO URLS
				$displaycat = "<a href=\"".$siteurl."/category/".$categoryid."/".$scrubcatname."/\"><b>".$categoryname."</b></a>";
			} else {
				$displaycat = "<a href=\"".$siteurl."/category.php?id=".$categoryid."\"><b>".$categoryname."</b></a>";
			}
	
	} else {
//get category info
	$query = "select * from categories where id=".$catparent;
	$result = mysql_query($query,$connection) or die(mysql_error());
	$info = mysql_fetch_array($result);
	$parentname = $info['name'];
	if ($seourls == 1) { $scrubparent = generate_seo_link($parentname); }
	
	if ($seourls == 1) { // With SEO URLS
		$displaycat = "<a href=\"".$siteurl."/category/".$catparent."/".$scrubparent."/\"><b>".$parentname."</b></a> > 
				   <a href=\"".$siteurl."/category/".$categoryid."/".$scrubcatname."/\"><b>".$categoryname."</b></a>";
	} else {
		$displaycat = "<a href=\"".$siteurl."/category.php?id=".$catparent."\"><b>".$parentname."</b></a> > 
				   <a href=\"".$siteurl."/category.php?id=".$categoryid."\"><b>".$categoryname."</b></a>";
	}
	}
	
	
	//Add a view to this article
	$query = "select * from articleviews where articleid = ".$article;
	$results = mysql_query($query,$connection) or die(mysql_error());
	$viewinfo = mysql_fetch_array($results);
	if ($viewinfo == NULL) {
		$sql = "INSERT INTO articleviews VALUES (".$article.", 1)";
		$query = mysql_query($sql);
	} else {
		$totalviews = $viewinfo['views'];
		$totalviews++;
	
		$sql = "UPDATE articleviews SET views=".$totalviews." WHERE `articleid`=".$article."";
		$query = mysql_query($sql);
	}

	if ($seourls == 1) { // With SEO URLS
		$authorlink = "<a href=\"".$siteurl."/profile/".$authorid."/".$scrubauthor."/\"><b>".$authorname."</b></a>";
	} else {
		$authorlink = "<a href=\"".$siteurl."/profile.php?a=".$authorid."\"><b>".$authorname."</b></a>";
	}
 
?>

<!-- CONTENT AREA -->
<div id="content-full">	


	<h1><?php echo $title; ?></h1>
	<div class="article-meta"><?php echo $displaycat; ?> | By: <?php echo $authorlink; ?> (<?php echo $artdate; ?>) <span style="float:right;">Views: <?php echo $totalviews; ?></span></div>
	
<div id="content-body">
<div style="float:right; padding: 5px;">	<?php // PRINT OUT THE 250 x 300 code
	$query = "select * from adboxes where id=1;"; 
	$result = mysql_query($query,$connection) or die(mysql_error());
	$info = mysql_fetch_assoc($result);

	echo stripslashes($info['adcode']); 
	?>
</div>

<?php echo $body; ?>
<br/>

<!-- Social Buttons -->
<center><span class="st_email_large" displayText="Email"></span><span class="st_twitter_large" displayText="Tweet"></span><span class="st_facebook_large" displayText="Facebook"></span><span class="st_stumbleupon_large" displayText="Stumble"></span><span class="st_digg_large" displayText="Digg"></span><span class="st_delicious_large" displayText="Del.icio.us"></span><span class="st_ybuzz_large" displayText="Yahoo! Buzz"></span><span class="st_gbuzz_large" displayText="Google Buzz"></span><span class="st_reddit_large" displayText="Reddit"></span><span class="st_sharethis_large" displayText="ShareThis"></span></center>

<h2>About the Author</h2>
<table><tr><td><img alt="" src="<?php echo $gravatar; ?>" style="padding: 5px 5px 5px 0;" /></td>
<td><b><?php echo $authorname; ?> </b><br/><?php echo $resource; ?></td></tr></table>
	
</div>
</div>

<div class="clear"></div>


<?php include('footer.php'); ?>
