Location: PHPKode > scripts > AmaroK Web Frontend > obsidianmusic-2.3.0/pages/all.php
<?php

//
//  ObsidianMusic
//   a.k.a. amaroK Web Frontend 2.0
//
//  Created 12/26/05
//   Copyright (C) Ryan Loebs (ObsidianX) 2005/2006
//   See LICENSE for GPL
//
//  all.php - Browse page
//
///////////////////////////////////////

if(eregi("all.php", $_SERVER['PHP_SELF'])){
	die("Cannot access directly.");
}

// Grab all the songs
if(!isset($_GET['per_page']) || !(int)$_GET['per_page']) {
	$_GET['per_page'] = 50;
}
if(!isset($_GET['page']) || !(int)$_GET['page']) {
	$_GET['page'] = 1;
}

$params[':limit'] = (int)$_GET['per_page'];
$params[':offset'] = $_GET['per_page']*($_GET['page']-1);
$q = query(getquery('all', 'song', $params));
// FIXME: optimize this
$total = array_pop(fetch_assoc(query(getquery('count'))));
$rows = getSongArray($q);

$tpl->addVar("root", "title", _PG_ALL);
$tpl->addVar("songs", "page", _PG_ALL);

$totalPages = ceil($total/$_GET['per_page']);

// make pagination
for($i=1 ; $i <= 5; ++$i) {
	$pages[$i] = array('page'=>$i, 'class'=>'');
}
for($i= $_GET['page']-5; $i < $_GET['page']+5; ++$i) {
	if($i < 1) {
		continue;
	}
	$pages[$i] = array('page'=>$i, 'class'=>'');
}

for($i = $totalPages-5; $i <= $totalPages; ++$i) {
	$pages[$i] = array('page'=>$i, 'class'=>'');
}

$pages[$_GET['page']] = array('page'=>$_GET['page'], 'class'=>'active');
$pages = array_values($pages);


$tpl->addGlobalVar("pageact", "all");
$tpl->loadTemplate("pagelist");
$tpl->setAttribute("pagelist", "visibility", "visible");
$tpl->addRows("pages", $pages);

$tpl->addRows("row", $rows);
Return current item: AmaroK Web Frontend