<?php
require_once("../includes/config.inc.php");
require_once("../includes/PageDataAccess.inc.php");

$pda = new PageDataAccess(getDBLink());
$activePages = $pda->getPageList();
$pageTitle = "Blogs";
$pageDescription = "The blog is all about web development, and other interesting topics.";
//$sideBar = "hobbies-sidebar.inc.php";

require("../includes/header.inc.php");
?>
		<main>

			<div class="content-frame">
				
				<h3>Blogs</h3>
				
				<table>
					<?php echo(createBlogList($activePages));?>
				</table
			</div>
			
		</main>
	</div>
<?php
if(!empty($sideBar)){
	require("../includes/" . $sideBar);
}

// wraps the blog pages in an unordered list
function createBlogList($pages){

	$html = "<ul class=\"blog-list\">";
	foreach ($pages as $p) {
		$html .= "<li>";
		$html .= 	"<a href=\"blog-post.php?pageId=" . $p['pageId'] . "\">";
		$html .= 		$p['title'];
		$html .= 	"</a>";
		$html .= "</li>";
		
	}
	$html .= "</ul>";
	return $html;
}	

require("../includes/footer.inc.php");
?>
