<?php
include('include/autoloader.php');
$smarty->assign('is_category',1);
$id = intval(make_safe(xss_clean($_GET['id'])));
$slug = make_safe(xss_clean($_GET['slug']));
$category = $general->category($id);
foreach ($category AS $key=>$value) {
	$smarty->assign('category_'.$key,$value);
}
$ur = explode('?',curPageURL());
if (count($ur) != 0) {
if (isset($ur[1])) {
parse_str($ur[1],$q);	
}
}
if ($options['theme_pagination_load'] == 'normal') {
$page = 1;
if (isset($options['theme_category_media_number'])) {
	$size = $options['theme_category_media_number'];
} else {
	$size = 24;
}
if (isset($q['page'])){ $page = (int) $q['page']; }
$sqls = "SELECT * FROM media WHERE published='1' AND deleted='0' AND category_id='$id' ORDER BY id DESC";
$query = $mysqli->query($sqls);
$total_records = $query->num_rows;
$smarty->assign('total_records',$total_records);
if ($total_records > 0) {
$pagination = new Pagination();
$pagination->setLink("./category/$id/$slug?page=%s");
$pagination->setPage($page);
$pagination->setSize($size);
$pagination->setTotalRecords($total_records);
$get = "SELECT * FROM media WHERE published='1' AND deleted='0' AND category_id='$id' ORDER BY id DESC ".$pagination->getLimitSql();
$q = $mysqli->query($get);
while ($row = $q->fetch_assoc()) {
	$media[] = $row;
}
$smarty->assign('media',$media);
$smarty->assign('pagi',$pagination->create_links());
}
}
$smarty->assign('seo_title',htmlspecialchars_decode($category['category'],ENT_QUOTES).' - '.$options['general_seo_title']);
$smarty->assign('seo_keywords',$category['seo_keywords']);
$smarty->assign('seo_description',$category['seo_description']);
$smarty->display('category.html');	
?>