<?
	$query = "SELECT * FROM page WHERE name='".$_SESSION['page']."'";
	$mysqldb1->query($query);
	$page = $mysqldb1->fetchArray();
	
	// FIXES Z-INDEX ISSUES
	if ($page['external'] !=  '') { 
		$page['external'] = str_replace('></embed></object>', 'wmode="opaque"></embed></object>', html_entity_decode($page['external']));
	}
	
	$content = str_replace('#VIDEO#', $page['external'], html_entity_decode($page['content']));
	$content = str_replace('../..', 'http://'.$domain, $content);
	
?>
<div id="page_frame">
<div id="page_header"><? print $page['heading']; ?></div>
<div id="page_content">
<? print $content; ?>
<?
// PAGE SPLITS
$page_size = 50;
$record_start = $_GET['record_start'];
if (strlen($record_start) == 0) {
	$record_start = 0;
}

$variables = "&page=newsletter";

$query = "
SELECT 
	count(t1.id) AS rows
FROM 
	newsletter AS t1 
WHERE 
	status='enabled'";

//fb($query);
$mysqldb1->query($query);
$table = $mysqldb1->fetchObject();
$rows = $table->rows;

// PREV
if ($record_start > 0) {
	$prev = $record_start - $page_size;
	$url = $_SERVER['PHP_SELF'].'?record_start='.$prev.$variables;
	$prev_link = '<a href="'.$url.'" target="_self"><<< prev</a>';
} else {
	$prev_link = '';
}

// NEXT
if ($rows > ($record_start + $page_size)) {
	$next = $record_start + $page_size;
	$url = $_SERVER['PHP_SELF'].'?record_start='.$next.$variables;
	$next_link = '<a href="'.$url.'" target="_self">next >>></a>';
} else {
	$next_link = '';
}

$total_pages = ceil($rows / $page_size);
$current_page = ($record_start / $page_size) + 1;

if ($rows > $page_size) {
	$page_links = cssPageLinks($total_pages, $current_page, $page_size, 'record_start', $variables);
}
// --PAGE SPLITS
?>
<div class="page_links"><? print $page_links; //$prev_link.' '.$page_links.' '.$next_link; ?></div>
<?
$query = "
SELECT 
	t1.* 
FROM 
	newsletter AS t1 
WHERE 
	t1.status='enabled'
ORDER BY 
	t1.id DESC 
LIMIT 
	".$record_start.", ".$page_size;
?>
<table width="100%" border="0" cellpadding="0" cellspacing="5">
	<tr>
	<?
    //fb($query);
	$columns = 1;
    $counter = 0;
    $mysqldb1->query($query);
    while ($listing = $mysqldb1->fetchArray()) {
		
		$href = '/newsletter/'.$listing['link_name'];
		$class = '';
		$rel = '';
		$listing_heading = '<a href="'.$href.'" target="_self">'.$listing['heading'].'</a>';
		
        $counter++;
        if ($counter % 2 != 0) { $bgcolour = ''; } else { $bgcolour = ''; }
    ?>
        <td align="left" valign="top" class="listing" style="background-color:<? print $bgcolor; ?>;">
        	
            <table width="100%" border="0" cellpadding="5" cellspacing="0">
                <tr>
                    <td width="80%" align="left" valign="middle"><div class="listing_heading"><? print $listing_heading; ?></div></td>
                    <td width="20%" align="right" valign="middle"><a href="<? print $href; ?>" target="_self"><img src="/website/styles/default/view_small.png" alt="view" width="60" height="20" border="0" /></a></td>
                </tr>
            </table>
            
        </td>
        
        <? if ($counter % $columns == 0) { ?>
        </tr></tr>
		<? } ?>
    <?
    }
    ?>
    <? if ($mysqldb1->affectedRows() < 1) { ?>
    <td>
    There are currently no newsletters.
    </td>
    <? } ?>
	</tr>
</table>
<div class="page_links"><? print $page_links; //$prev_link.' '.$page_links.' '.$next_link; ?></div>
</div>
<div id="page_footer"></div>
</div>