<?
//*********************************************************************************************
//* columns.inc
//* copyright © 2007 Indigocafe.com 
//* created by J. Brissett 
//*********************************************************************************************

//*********************************************************************************************
//*********************************************************************************************
//*** DEFINES
//*********************************************************************************************
//*********************************************************************************************
define(STATUS_LIVE, 0);
define(STATUS_DRAFT, 1);
define(STATUS_FLAGGED, 2);
define(STATUS_REMOVED, 3);

define(ARTICLE_STATUS_LIVE, "Posted");
define(ARTICLE_STATUS_DRAFT, "Draft");
define(ARTICLE_STATUS_FLAGGED, "Flagged");
define(ARTICLE_STATUS_REMOVED, "Removed");

define(COMMENT_PAGE, "http://www.indigocafe.com/comments/post.php");

//*********************************************************************************************
//*********************************************************************************************
//*** COMMON ARTICLE CODE
//*********************************************************************************************
//*********************************************************************************************

// ==============================================================
// return the status of the article
// ==============================================================
function getStatusName($status)
{
	if ($status == STATUS_LIVE) { $statusName = ARTICLE_STATUS_LIVE; }
	if ($status == STATUS_DRAFT) { $statusName = ARTICLE_STATUS_DRAFT; }
	if ($status == STATUS_FLAGGED) { $statusName = ARTICLE_STATUS_FLAGGED; }
	if ($status == STATUS_REMOVED) { $statusName = ARTICLE_STATUS_REMOVED; }

return $statusName;
}

//*********************************************************************************************
//*********************************************************************************************
//*** DISPLAY CODE
//*********************************************************************************************
//*********************************************************************************************

// ==============================================================
// ENTRY POINT: display the article
// ==============================================================
function displayArticle($column_id, $id, $connection)
{
	$column = getColumnInfo($column_id, $connection);

	if ($column["doctype"] == DOCTYPE_REVIEW) { displayReview($column_id, $id, $connection); } 
	if ($column["doctype"] == DOCTYPE_COLUMN) { displayColumn($column_id, $id, $connection); }

	echo "<div style=\"padding-left: 20; padding-bottom: 10;\">";
	echo "
	<!-- AddThis Bookmark Button BEGIN -->
	<script type=\"text/javascript\">
		addthis_url    = location.href;   
		addthis_title  = document.title;  
		addthis_pub    = 'booksellergirl';     
	</script><script type=\"text/javascript\" src=\"http://s7.addthis.com/js/addthis_widget.php?v=12\" ></script>
	<!-- AddThis Bookmark Button END -->
	";
	echo "</div>";

	echo "<div style=\"padding-left: 20; padding-bottom: 2;\">";
	displayBottomNav($column_id, $id, $connection);
	echo "</div>";

}

// ==============================================================
// display the book (1 book is the to be reviewed)
// param:
//		title_codes = title codes for book
//		begin = where to begin looking at the TC list
// ==============================================================
function displayAssocBookInfo($title_codes, $begin, $connection)
{
		$TC = split(",",  $title_codes);

		echo "<table width=115 border=0 align=right cellspacing=2 class=footer>";

		$i = $begin;
		while($TC[$i])
		{
			$title = trim($TC[$i]);
			$validNumber = "^[0-9]{1,4}$";                  
			if (($title) && (ereg($validNumber, $title)))  
			{
				$book = getBookInfo($title, $connection);

				echo "<tr><td align=center>";
				echo $book["reg_image"];
				echo "</td></tr>";
				echo "<tr><td align=center>";
				echo $book["title"]."<br>";
				echo "by ".$book["author"]."<br>";
				echo "</td></tr>";
				echo "<tr><td height=1></td></tr>";
			}
			$i++;
		}
		echo "</table>";
}

// ==============================================================
//
// ==============================================================
function displayBottomNav($column_id, $bag_id, $connection)
{
		$column = getColumnInfo($column_id, $connection);

		// is the person viewing is user?
		$poster_id = $column["author"]; // the poster
		$current_id = getCustID($bag_id, $connection); // the veiwer
		if ($poster_id == $current_id ) { $logged_in = 1; } else { $logged_in = 0; }

		$author = getMemberName($poster_id, $connection);
		$name = getUserName($author);
		$user_id = getPublicID($poster_id, $connection);

		echo "\n\n<table class=commentsFooter><tr>";
		echo "<td>posted by: <a href=".DIR_PROFILE_PAGE."?u=$user_id>$name</a>";
		echo " | <a href=".COLUMNS_ROOT."?u=$user_id>more from this member</a> ";
		if ($logged_in) { echo "&nbsp;&nbsp;[ <a href=".POST_ENTRY_PAGE."?c=$column_id>Edit Post</a> ]"; }
		echo "</td><td align=right>";
    echo "<a href=article.php?t=".$column["doctype"]."&c=".$column_id."&printer=1>Print Article</a>&nbsp;"; 
    echo "<a href=article.php?t=".$column["doctype"]."&c=".$column_id."&printer=1><img src=\"/img/printer.gif\" border=0></a>";
		echo "<td>";
		echo "</tr></table>";

		displayArticleComments($column_id, $bag_id, $connection);

}


//*********************************************************************************************
//*********************************************************************************************
?>