<?php

/*
	[SupeSite/X-Space] (C)2001-2006 Comsenz Inc.
	¦Cªí­¶­±

	$RCSfile: category.php,v $
	$Revision: 1.15 $
	$Date: 2006/09/26 09:30:11 $
*/

if(!defined('IN_SUPESITE')) {
	exit('Access Denied');
}

$catid = intval($_SGET['catid']);
if($catid) {
	dbconnect();
	$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('categories')." WHERE catid='$catid'");
	$thecat = $_SGLOBAL['db']->fetch_array($query);
}
if(empty($thecat)) messagebox('error', 'not_found', S_URL);

if(!empty($thecat['url'])) {
	header('location: '.$thecat['url']);
	exit;
}

if(!empty($_SCONFIG['htmlcategory'])) {
	$_SHTML['action'] = 'category';
	$_SHTML['catid'] = $thecat['catid'];
	if(!empty($_SGET['page'])) $_SHTML['page'] = intval($_SGET['page']);
	if(!empty($_SGET['mode'])) $_SHTML['mode'] = 'bbs';
	$_SGLOBAL['htmlfile'] = gethtmlfile($_SHTML);
	ehtml('get', $_SCONFIG['htmlcategorytime']);
	$_SCONFIG['debug'] = 0;
}

include_once(S_ROOT.'./include/common.inc.php');

if(!empty($thecat['upid'])) {
	$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('categories')." WHERE catid='$thecat[upid]'");
	$upcat = $_SGLOBAL['db']->fetch_array($query);
}

$_SGET['page'] = empty($_SGET['page'])?1:intval($_SGET['page']);

$title = $thecat['name'].'_'.$lang[$thecat['type']].'_'.$_SCONFIG['sitename'];
$keywords = $thecat['name'].','.$lang[$thecat['type']];
$description = $thecat['name'].','.$lang[$thecat['type']];

$guidearr = array();
$guidearr[] = array('url' => geturl('action/'.(($thecat['type']=='space')?'spaces':$thecat['type'])),'name' => $lang[$thecat['type']]);
if(!empty($upcat)) $guidearr[] = array('url' => geturl('action/category/catid/'.$upcat['catid']), 'name' => $upcat['name']);
$guidearr[] = array('url' => geturl('action/category/catid/'.$thecat['catid']), 'name' => $thecat['name']);

if(!empty($thecat['tpl']) && file_exists(S_ROOT.'./templates/'.$_SCONFIG['template'].'/'.$thecat['tpl'].'.html.php')) {
	$tplname = $thecat['tpl'];
} else {
	$tplname = (($thecat['type']=='space')?'spaces':$thecat['type']).'_category';
}

include template($tplname);

if(!empty($_SCONFIG['htmlcategory'])) {
	ehtml('make');
} else {
	maketplblocknames($tplname);
	maketplblockvalue('cache');
}

?>