<?php
/*
   +----------------------------------------------------------------------+
   | Rolls Page                                                           |
   | Author: Adam Goldberg                                                |
   +----------------------------------------------------------------------+
   | Copyright (c) 2008-2009 Adam J Goldberg                              |
   | This file is part of Lifebox.                                        |
   |                                                                      |
   | Lifebox is free software: you can redistribute it and/or modify      |
   | it under the terms of the GNU General Public License as published by |
   | the Free Software Foundation, either version 3 of the License, or    |
   | (at your option) any later version.                                  |
   |                                                                      |
   | Lifebox is distributed in the hope that it will be useful,           |
   | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
   | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
   | GNU General Public License for more details.                         |
   |                                                                      |
   | You should have received a copy of the GNU General Public License    |
   | along with Lifebox.  If not, see <http://www.gnu.org/licenses/>.     |
   +----------------------------------------------------------------------+
   | Display a browseable list of rolls                                   |
   +----------------------------------------------------------------------+
*/

require_once 'config/global.inc.php';
require_once 'Album.inc.php';
require_once 'Pagination.inc.php';

if (empty($_GET['offset'])){
        $offset = 0;
} else {
        $offset = $_GET['offset'];
}

if (empty($_GET['all'])) {
        $limit = $CONFIG['perpage_rolls'];
} else {
        $limit = '10000';
}

if (isset($_GET['sort'])) {
	$sort = $_GET['sort'];
} else {
	$sort = '';
}

$all_url = '/'.$a.'/?all=true&sort='.$sort;
$smarty->assign('all_url',$all_url);

#If SORT Post
if (isset($_POST['sort']) AND $_POST['sort']) {
	header('Location: /rolls/?offset='.$offset.'&sort='.$_POST['sort']);
	exit(0);
}

#Get Latest Albums
$album_list = Album::getAlbumList(1,$limit,$offset,$sort);
$smarty->assign('album_list',$album_list);

$total_rows = Album::getAlbumList(1,true);

#Create Pagination URL
$get_string = '';
foreach ($_GET as $key=>$value){
        if ($key !== 'offset'){
                $value = urlencode($value);
                $key = urlencode($key);
                $get_string .= "$key=$value&";
        }
}
$get_string = substr($get_string,0,-1);

$p = new Pagination($total_rows,$limit,$offset);
$p->setURL("/rolls/?$get_string");
$pagination = $p->getNavigation();


$smarty->assign('pagination',$pagination);
$smarty->assign('total_pages',$p->getTotalPages());
$smarty->assign('total_items',$p->getTotalItems());
$smarty->assign('current_page',$p->getCurrentPage());
$smarty->assign('first_result',$p->getFirstResult());
$smarty->assign('last_result',$p->getLastResult());

$smarty->display($CONFIG['smarty_templates'].'/rolls.tpl');

?>
