Location: PHPKode > scripts > Impleo Music Collection Script > impleo/index.php
<?php
/* ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * <hide@address.com> wrote this file. As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy me a beer in return Christoffer Kjeldgaard Petersen
 * ----------------------------------------------------------------------------
 */

header("content-type:text/html;charset=utf-8");

require_once(dirname(__FILE__) . '/classes/Factory.class.php');
require_once(dirname(__FILE__) . '/classes/Paging.class.php');
require_once(dirname(__FILE__) . '/classes/ImpleoTemplate.class.php');

$tpl = new ImpleoTemplate("index.tpl");
$factory = Factory::getInstance();

$arrDetails = $factory->getDetailInfo();
$arrGeneralSettings = $factory->getGeneralSettings();

if ($arrGeneralSettings['records_per_page'] > 0)
    $LIMIT = $arrGeneralSettings['records_per_page'];
else
    $LIMIT = $factory->getNumberOfItems();
    
    // Search
    $isSearch = false;
    if (isset($_REQUEST['q']) && isset($_REQUEST['term']))
    {
        $q = htmlspecialchars(stripslashes($_REQUEST['q']));
        $t = htmlspecialchars(stripslashes($_REQUEST['term']));
        $arrItems = $factory->searchMusic($_REQUEST['q'], $_REQUEST['term']);
        $isSearch = true;
        $tpl->assign('query', $q);
        $tpl->assign('selectedTerm', $t);
        $tpl->assign('searchUrl', "&q={$_REQUEST['q']}&term={$_REQUEST['term']}");
        $intNumRecords = count($arrItems);
    }
    else
    {
        $arrItems = $factory->getMusicItems();
        $intNumRecords =  $factory->getNumberOfItems();
    }
    $tpl->assign('isSearch', $isSearch);
        

// Sorting
$arrOrder = array("artist" => "asc", "title" => "asc", "year" => "asc");
foreach($arrDetails as $arrOrderDetail)
{
	$arrOrder[$arrOrderDetail['key']] = "asc";
}
if (isset($_GET['sort']))
{
	if (isset($_GET['order']))
	{
		if ($_GET['order'] == "asc") {
			$order = true;
			$arrOrder[$_GET['sort']] = "desc";
		}
		else {
			$order = false;
			$arrOrder[$_GET['sort']] = "asc";
		}
	}
	else
		$order = true;
	MusicItem::sortMusic($arrItems, $_GET['sort'], $order);
}

/* Page-control */
if (is_numeric($_GET['page']))
{
	$display = $_GET['page'];
	$start = $display*$LIMIT-$LIMIT;
}
else
{
	$display = 1;
	$start = 0;
}

if ($intNumRecords > $LIMIT)
{
	$arrPaging = Paging::createPagingList($intNumRecords, $LIMIT, $display, $_SERVER['QUERY_STRING']);
	$showPaging = true;
}
else
	$showPaging = false;

$arrMusic = array();
for($i = $start; $i < $start+$LIMIT; $i++)
{
	if (array_key_exists($i, $arrItems))
	{
		$arrMusic[] = $arrItems[$i];
	}
}

// Links in table?
if ($arrGeneralSettings['link'] == '1')
    $link = true;
else
    $link = false;

$tpl->assign('collectionName', $arrGeneralSettings['name']);
$tpl->assign('link', $link);
$tpl->assign('sortorder', $arrOrder);
$tpl->assign('musiclist', $arrMusic);
$tpl->assign('details', $arrDetails);
$tpl->assign('numRecords', $intNumRecords);
$tpl->assign('numArtists', $factory->getAttributeCount("artist"));
$tpl->assign('showPaging', $showPaging);
$tpl->assign('paging', $arrPaging);
$tpl->assign('uri', $_SERVER['REQUEST_URI']);

$tpl->displayTemplate();

?>
Return current item: Impleo Music Collection Script