<?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 Rants');
adminmenu();
?>
<h2>Manage Rants</h2>

<?php

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

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

$total = ceil( $mtdb->getOne("SELECT count(DISTINCT id) FROM rant") / $perpage );
$rants = $mtdb->getAll("SELECT r.id,UNIX_TIMESTAMP(r.published) AS published,c.name,r.title,r.body, r.status FROM rant r,contributor c WHERE c.id=r.author GROUP BY id ORDER BY id DESC LIMIT $start,$perpage");

pagination( $page, $total );

?>

<table class="widefat">
	<thead>
	<tr>
	<th scope="col" style="text-align: center;">Rant&nbsp;#</th>
	<th scope="col">Author</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( $rants as $r ) {
		$alternate=!$alternate;
		?>
		<tr id="rant-<?php echo $r->id; ?>" <?php if($alternate) echo 'class="alternate"'; ?>>
		 <th scope="row" style="text-align: center;"><?php echo $r->id; ?></th>
		 <td><?php echo $r->name; ?></td>
		 <td><?php echo $r->title; ?></td>
		 <td><?php echo $r->status; ?></td>
		 <td><?php echo htmlentities( date( 'Y-m-d H:i:s', $r->published)); ?></td>
		 <td><?php echo Excerpt($r->body,185); ?></td>
		 <td><?php echo '<a href="' . SITE_HOST.SITE_PATH.'/rant/' . $r->id . '">View</a>'; ?></td>
		 <td style="text-align: center;"><a href="edit-rant.php?rant_id=<?php echo $r->id; ?>">Edit</a></td>
		 <td style="text-align: center;"><a class="delete" href="delete-rant.php?rant_id=<?php echo $r->id; ?>">Delete</a></td>
		</tr>
		<?php
	}
	?>
	</tbody>
</table>

<?php
adminfooter();
?>
