<?php 
$total = $z->select("SELECT COUNT(ID) as total FROM albums WHERE status=?", array("yes"), "s")->row->total; 
$start = 0; $limit = 50;
if(isset($_GET['start'])){ 
	$ostart = $_GET['start'];
	$start = $limit * $ostart - $limit;	
}
$list = $z->select("SELECT * FROM albums WHERE status=? ORDER BY ID DESC LIMIT ?,?", array("yes",$start,$limit), "sss");
$pageLabel = isset($_GET['start']) && $_GET['start'] > 1 ? ' &ndash; Page '.$_GET['start'] : '';
?>
<ul class="ibl dashnav size18 fontl">
	<li><a href="<?php echo baseurl; ?>admin/dashboard" class="noul noulh">Dashboard</a></li>
	<li class="ibl aro">&rsaquo;</li>
	<li>Albums</li>
</ul>
<h2 class="size24 fontl cfff titleb">Albums <span class="que-count">(<?php echo number_format($total); ?>)</span><?php echo $pageLabel; ?></h2>
<button class="size14 fontn cfff abs anim bnp-new create-new-album"><div class="ibl icon-plus ico"></div>Create Album</button>

<?php if($list->count > 0 && $list->result=="ok"){
	echo '<ol class="albumList ibl">';
	for($n = 0; $n < count($list->fetch); $n++):
		$s = $list->fetch[$n]->tracks > 1 ? 's' : '';
		$cover = baseurl.'photo/album/'.$z->encode($list->fetch[$n]->photo).'/default.jpg';
		echo '<li class="rel album'.$hash->encode($list->fetch[$n]->ID).'">'
		. '<div class="poster rel"><img src="'.$cover.'" class="bl"></div>'
		. '<h2 class="size14 fontb wordwrap ttl cfff">'.stripslashes($list->fetch[$n]->title).'</h2>'
		. '<h2 class="size13 fontn ctr c999">'.number_format($list->fetch[$n]->tracks).' Track'.$s.'</h2>'
		. '<button class="editBtn bl size13 fontn anim" data-cover="'.$cover.'" data-title="'.stripslashes($list->fetch[$n]->title).'" data-id="'.$hash->encode($list->fetch[$n]->ID).'">Edit</button>';
		if($list->fetch[$n]->locked=='no'){ echo '<a href="javascript:;" class="size11 noul noulh rmAlbum" data-id="'.$hash->encode($list->fetch[$n]->ID).'">Delete</a>'; }
		echo '</li>';
	endfor;
	echo '</ol>';
	$pagin = '<ol class="pages ibl">';
	$fresh_start = isset($_GET['start']) ? $_GET['start'] : 1;	
	$next = $fresh_start+1;
	$prev = $fresh_start-1;
	$prevlink = baseurl.'admin/albums/p'.$prev;
	$link_first = baseurl.'admin/albums';
	$nextlink = baseurl.'admin/albums/p'.$next;
	$link_last = baseurl.'admin/albums/p'.ceil($total/$limit); 
	$link_i = baseurl.'admin/albums/p';
	$pagin .= $z->pagination($total, $limit, $start, $fresh_start, $link_first, $prevlink, $prev, $next, $nextlink, $link_last, $link_i, '');		
	$pagin .= '</ol>';
	echo $pagin;
}else{ 
	echo '<div class="emptyTracks rel size40 cfff fontl"><div class="icon-puzzle ico"></div>You haven\'t created any album yet..</div>';
} ?>