
<?php include("header.php"); ?>

<h2>Publications, Presentations, and Posters</h2>

<div id="pubs">
	<ul>

<?php

$pubfilename = "publist";
$pubfile = fopen($pubfilename, 'r');

$perpage = 25;
$title = ""; $authors = ""; $place = ""; $when = ""; $notes = ""; $link = "";
$page = 0; $count = 0;

if (isset($_GET['p']))
	$page = $_GET['p'];

while ($line = fgets($pubfile))
{
	if (preg_match('/^###/', $line))
	{
		$count++;
		if ($count < $perpage * $page + 1)
		{
			$title = ""; $authors = ""; $place = ""; $when = ""; $notes = ""; $link = ""; 
			continue;
		}

		print '<li>';
		print '<span class="title">';
		if ($link)
		{
			if (substr($link, 0, 4) === 'http')
				print "<a href=\"$link\">";
			else
				print "<a href=\"docs/$link\">";
		}
		print $title.'.  ';
		if ($link)
			print '</a>';
		print "</span>\n";
		print "<span class=\"authors\">$authors</span>, \n";
		print "<span class=\"place\">$place</span>, \n";
		print "<span class=\"place\">$when</span>.\n";
		if ($notes)
			print "($notes)\n";
		print '</li>';

		$title = ""; $authors = ""; $place = ""; $when = ""; $notes = ""; $link = ""; 
	}
	
	if ($count >= $perpage * ($page + 1))
		break;

	else if (preg_match('/^TITLE\s*=\s*(.*)/', $line, $matches))
		$title = $matches[1];
	else if (preg_match('/^AUTHORS\s*=\s*(.*)/', $line, $matches))
		$authors = $matches[1];
	else if (preg_match('/^PLACE\s*=\s*(.*)/', $line, $matches))
		$place = $matches[1];
	else if (preg_match('/^WHEN\s*=\s*(.*)/', $line, $matches))
		$when = $matches[1];
	else if (preg_match('/^NOTES\s*=\s*(.*)/', $line, $matches))
		$notes = $matches[1];
	else if (preg_match('/^LINK\s*=\s*(.*)/', $line, $matches))
		$link = $matches[1];
	else 
		continue;
}
?>
</ul>

<?php
if ($page != 0)
{
	$prevpage = $page - 1;
	print "<span id=\"newer\"><a href=\"publications.php?p=$prevpage\">Newer...</a></span>";
}
else
{
	print "<span id=\"newer\"><a href=\"index.php\">Home</a></span>";
}
if ($count >= $perpage * ($page + 1))
{
	$nextpage = $page + 1;
	print "<span id=\"older\"><a href=\"publications.php?p=$nextpage\">Older...</a></span>";
}
?>
</div>

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


