<?php
include_once($setting['sitepath'].'/includes/pagination.class.php');
$pic_settings = array('w'=>80,'h'=>80);
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$cache = RayCache::getInstance($cat_data['name'].$page, null, array('prefix' => 'slim-blue_', 'path' => 'cache/', 'expire' => $setting['cachelife']));
$data = $cache->read('home');
if ($data) {
	echo $data;
} else {
	$cache->start_caching();
?>
<div id="left">
	<?php
	$runOnce = false;
	function echoOnce()	{
    	global $runOnce;
    	if(!$runOnce) {
        	$runOnce = true;
        	return "<b>Sub categories:</b><br><div id='catpages'>";
    	}
	}
	echo '<h1>'.$cat_data['name'].'</h1>
          <div id="category_wrap">';
	$query = yasDB_select("SELECT * FROM categories WHERE active='yes' AND parent='no' ORDER BY `order` desc") or die(mysql_error());
	while($row = $query->fetch_array(MYSQLI_ASSOC)) {
		if ($id = $row['pid']) {
			echo echoOnce();
			if ($setting['seo']=='yes') {
				echo '<a href="' . $setting['siteurl'] . 'category/' . $row['id'] .'/1.html">' . $row['name'] . '</a>&nbsp;|&nbsp;';
			}
			else {
				echo '<a href="' . $setting['siteurl'] . 'index.php?act=cat&id=' . $row['id'] .'">' . $row['name'] . '</a>&nbsp;|&nbsp;';
			}
		}  
	}
	$count = yasDB_select("SELECT count(id) AS count FROM `games` where category = " . yasDB_clean($_GET['id']));
	$total = $count->fetch_array(MYSQLI_ASSOC);
	if($total['count'] < 1) {
		echo '<br/><center><span style="font-size:200%;">There are no games in this category yet.</span></center>';
		echo '<div id="main_wrap"><br style="clear: both"/><div id="catpages"></div>';
	}
	else {
		$pageurl = new pagination($total['count'], $setting['seo'], '', 1, 3);
		$query = yasDB_select("SELECT * FROM `games` where category = " . yasDB_clean($_GET['id']) . " order by `id` desc LIMIT " . $pageurl->start . ", " . $pageurl->limit);
		while($games = $query->fetch_array(MYSQLI_ASSOC)) {
			$gameurl = $games['title'];
			$gameurl = str_replace(" ", "-", $gameurl);
			$gameurl = str_replace("'", "_", $gameurl);
			$gameurl = str_replace('"', "_", $gameurl);
			$gameurl = str_replace('/', "_", $gameurl);
			$gameurl = str_replace("\\", "_", $gameurl);
			$gameurl = rawurlencode($gameurl);
			$games['description'] = stripslashes($games['description']);
			if (!file_exists($games['thumbnail'])) {
				$games['thumbnail'] = 'img/nopic.jpg';
			}
			if(strlen($games['description']) > 75){
				$games['description'] = substr($games['description'], 0, 75)."...";
			}
			if ($setting['seo']=='yes') {
				$gurl = $setting['siteurl'] . 'game/' . $games['id'] . '/' . $gameurl . '.html';
			}
			else {
				$gurl = $setting['siteurl'] . 'index.php?act=game&id=' . $games['id'];
			}
			echo '<div class="category_box"><div class="gamepic">
				<a href="' . $gurl . '">
				<img align="absmiddle" src="' . resize($setting['siteurl'].$games['thumbnail'], $pic_settings) . '"  alt="' . $games['title'] . '" width="80" height="80"" /></div><div class="game_text"><strong>' .
				$games['title'] . '</strong></a> <div>' . $games['description'] . '</div></div>
               	<div class="game_stats"><strong>Plays:</strong>' . $games['plays'] . '</div><br style="clear: both"/></div>'; 
		}	 
		echo '<br /><br /><div id="main_wrap"><br style="clear: both"/><div class="catpages"><br/>';
		echo $pageurl->showPagination();
		echo '</div>';
	}
?>
<div class="clear"></div>
</div></div>
<?php
$cache->write($cat_data['name'].$page);
$cache->stop_caching();
echo $cache->read($cat_data['name'].$page);
}
?>