<?php 

include('php/config.php');
include('php/functions.php');

if (preg_match('|^/([^/]+)/|', $_SERVER['PATH_INFO'], $matches)) {
    if ($MySQL->select_one("SELECT COUNT(*) FROM news WHERE id='".$matches[1]."'") == 1) {
    	$id = $matches[1];
    } 
	else {
		print $matches[1]."<br>\n";
		// die ("case not found in database: ".$_SERVER['SCRIPT_NAME'].$_SERVER['PATH_INFO']);
		header('Location: /errors/notfound.php');
	}
} 
else {
	//die ("case not found (no match): ".$_SERVER['SCRIPT_NAME'].$_SERVER['PATH_INFO']);
	header('Location: /errors/notfound.php');
}
$vars = $MySQL->select_row("SELECT * FROM news WHERE id='$id'");
	if (strlen($vars['title'])>0) {
    	define('PAGE_TITLE', $vars['title']);
        }
        else {
        define('PAGE_TITLE', DEFAULT_PAGE_TITLE);
        }
	if (strlen($vars['meta_description'])>0) {
		define('PAGE_DESCRIPTION', $vars['meta_description']);
	} 
    else {
		define('PAGE_DESCRIPTION', DEFAULT_PAGE_DESCRIPTION);
	}
	if (strlen($vars['meta_keywords'])>0) {
		define('PAGE_KEYWORDS', $vars['meta_keywords']);
	} 
    else {
		define('PAGE_KEYWORDS', DEFAULT_PAGE_KEYWORDS);
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html class="wf-kulturistaweb1kulturistaweb2-n6-active wf-kulturistaweb1kulturistaweb2-n7-active wf-active" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <head>
        <?php include("modules/page_head.php"); ?>
        <script type="text/javascript" src="/js/floating_nav.js"></script>
    </head>

    <body>
        
		<?php include("modules/header.php"); ?>
        
    	<div id="body_container" class="content_column">
            <div id="content_wrapper">                
                <div id="content_left">
                	<a href="/news-events.php"><h2>Latest News and Events</h2></a>                    
                    <?php include("modules/quote_request_dropdown.php"); ?>
                	<div id="floating_nav">
                	   <?php print_news_nav(); ?>
                    </div>
                </div><!-- content_left -->
                
                <div id="content_center">
					<a href="/news-events.php">Back to all news</a>
					<?php print_news_post_page($id); ?>
                </div><!-- content_center -->
            
            </div><!-- content_wrapper -->
        </div><!-- body_container -->
    	
        <div id="clearfix"></div>
        
        <?php 
			include("modules/footer.php"); 
		?>
        
    </body>
</html>