<?php

/* This page displays a list of comics, 15 per page. */

require_once('include/admin.inc.php');

auth_redirect(); // Require logged in user to access this page.

adminhead('Manage Pages');
adminmenu();
?>
<h2>Manage Pages</h2>

<?php

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

$perpage = 15;
$start = ($page - 1) * $perpage;

$total = ceil( $dbConnection->fetchColumn('SELECT COUNT(url_name) FROM static_page') / $perpage );
$pages = $dbConnection->fetchAll('SELECT url_name, pubdate, status, title, body FROM static_page ORDER BY url_name ASC LIMIT ?, ?', array($start, $perpage));

pagination( $page, $total );

?>

<table class="widefat">
	<thead>
	<tr>
	<th scope="col" style="text-align: center;">Page&nbsp;Name</th>
	<th scope="col">Title</th>
	<th scope="col">Status</th>
	<th scope="col">Published&nbsp;On</th>
	<th scope="col">Excerpt</th>
	<th scope="col"></th>
	<th scope="col"></th>
	<th scope="col"></th>
	</tr>
	</thead>

	<tbody id="the-list">
	<?php
	$alternate=false;
	foreach( $pages as $p ) {
		$alternate=!$alternate;
		?>
		<tr id="page-<?php echo $p->url_name; ?>" <?php if($alternate) echo 'class="alternate"'; ?>>
		 <th scope="row" style="text-align: center;"><?php echo $p->url_name ?></th>
		 <td><?php echo $p->title; ?></td>
		 <td><?php echo $p->status; ?></td>
		 <td><?php echo $p->pubdate; ?></td>
		 <td><?php echo Excerpt($p->body,185); ?></td>
		 <td><?php echo '<a href="' . SITE_HOST.SITE_PATH.'/' . $p->url_name . '">View</a>'; ?></td>
		 <td style="text-align: center;"><a href="edit-page.php?page_name=<?php echo $p->url_name; ?>">Edit</a></td>
		 <td style="text-align: center;"><a class="delete" href="delete-page.php?page_name=<?php echo $p->url_name; ?>">Delete</a></td>
		</tr>
		<?php
	}
	?>
	</tbody>
</table>

<?php
adminfooter();
?>
