<?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 Comics');
adminmenu();
?>
<h2>Edit Comic</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 strip") / $perpage );
$strips = $mtdb->getAll("SELECT id, UNIX_TIMESTAMP(published) as published, type, media, title, book, page FROM strip GROUP BY id ORDER BY id DESC LIMIT $start,$perpage");
$types_db = $mtdb->getAll("SELECT id,description FROM strip_t");

$type = array();
foreach( $types_db as $k ) $type[$k->id]=$k->description;


pagination( $page, $total );

?>

<table class="widefat">
	<thead>
	<tr>
	<th scope="col" style="text-align: center;">Strip #</th>
	<th scope="col">Title</th>
	<th scope="col">Published On</th>
	<th scope="col">Type</th>
	<th scope="col">Book Page #</th>
	<th scope="col"></th>
	<th scope="col"></th>
	<th scope="col"></th>
	</tr>
	</thead>

	<tbody id="the-list">
	<?php
	$alternate=false;
	foreach( $strips as $s ) {
		$alternate=!$alternate;
		?>
		<tr id="comic-<?php echo $s->id; ?>" <?php if($alternate) echo 'class="alternate"'; ?>>
		 <th scope="row" style="text-align: center;"><?php echo $s->id; ?></th>
		 <td><?php echo $s->title;	 ?></td>
		 <td><?php echo htmlentities( date( 'Y-m-d H:i:s', $s->published)); ?></td>
		 <td><?php echo $type[$s->type]; ?></td>
		 <td><?php echo $s->book; ?> - <?php echo $s->page; ?></td>
		 <td style="text-align: center;"><a href="<?php echo SITE_HOST . SITE_PATH; ?>/strip/<?php echo $s->id; ?>">View</a></td>
		 <td style="text-align: center;"><a href="edit-comic.php?strip_id=<?php echo $s->id; ?>">Edit</a></td>
		 <td style="text-align: center;"><a class="delete" href="delete-comic.php?strip_id=<?php echo $s->id; ?>">Delete</a></td>
		</tr>
		<?php
	}
	?>
	</tbody>
</table>



<?php
adminfooter();
?>
