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

<?php

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

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

$total = ceil( $dbConnection->fetchColumn('SELECT COUNT(*) FROM admin_log') / $perpage );
$entries = $dbConnection->fetchAll('SELECT UNIX_TIMESTAMP(l.logdate) AS logstamp, l.logdate AS logdate, c.name AS cname, s.name AS section, action, level, message ' .
	'FROM admin_log l JOIN admin_section s ON l.section = s.id JOIN contributor c ON l.contributor = c.id ORDER BY l.logdate DESC LIMIT ?, ?', array($start, $perpage), array(PDO::PARAM_INT, PDO::PARAM_INT));

pagination( $page, $total );

?>

<table class="widefat">
	<thead>
	<tr>
	<th scope="col" style="text-align: center;">Date</th>
	<th scope="col">Contributor</th>
	<th scope="col">Section</th>
	<th scope="col">Action</th>
	<th scope="col">Level</th>
	<th scope="col">Message</th>
	</tr>
	</thead>

	<tbody id="the-list">
	<?php
	$alternate=false;
	foreach( $entries as $e ) {
		$alternate=!$alternate;
		?>
		<tr id="log-<?php echo $e->logstamp; ?>" <?php if($alternate) echo 'class="alternate"'; ?>>
		 <th scope="row" style="text-align: center;"><?php echo $e->logdate; ?></th>
		 <td><?php echo $e->cname;  ?></td>
		 <td><?php echo $e->section; ?></td>
		 <td><?php echo $e->action; ?></td>
		 <td><?php echo $e->level ?></td>
		 <td><?php echo $e->message; ?></td>
		</tr>
		<?php
	}
	?>
	</tbody>
</table>



<?php
adminfooter();
?>
