<?
/*
	[SupeSite/X-Space] (C)2001-2006 Comsenz Inc.
	¤½§i­¶­±

	$RCSfile: announcement.php,v $
	$Revision: 1.12 $
	$Date: 2006/09/27 02:17:05 $
*/

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

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

$perpage = 10;
$id = empty($_SGET['id'])?0:intval($_SGET['id']);

$listvalue = array();
if(empty($id)) {

	$page = empty($_SGET['page'])?1:intval($_SGET['page']);
	($page<1)?$page=1:'';
	$start = ($page-1)*$perpage;

	$query = $_SGLOBAL['db']->query('SELECT COUNT(*) FROM '.tname('announcements').' WHERE starttime <= '.$_SGLOBAL['timestamp'].' AND (endtime >= '.$_SGLOBAL['timestamp'].' OR endtime = 0)');
	$listcount = $_SGLOBAL['db']->result($query, 0);
	$multipage = '';
	
	if($listcount) {
		$query = $_SGLOBAL['db']->query('SELECT * FROM '.tname('announcements').' WHERE starttime <= '.$_SGLOBAL['timestamp'].' AND (endtime >= '.$_SGLOBAL['timestamp'].' OR endtime = 0) ORDER BY displayorder DESC, starttime DESC LIMIT '.$start.','.$perpage);
		while($item = $_SGLOBAL['db']->fetch_array($query)) {
			$item['starttime'] = $item['starttime'] ? sgmdate($item['starttime']) : '-';
			$item['endtime'] = $item['endtime'] ? sgmdate($item['endtime']) : '-';
			$item['url'] = geturl('action/announcement/id/'.$item['id']);
			$listvalue[] = $item;
		}
		$urlarr = array('action'=>'announcement');
		$multipage = multi($listcount, $perpage, $page, $urlarr, 0);
	}
	
} else {

	$query = $_SGLOBAL['db']->query('SELECT * FROM '.tname('announcements').' WHERE id=\''.$id.'\'');
	if($announce = $_SGLOBAL['db']->fetch_array($query)) {
		$announce['starttime'] = $announce['starttime'] ? sgmdate($announce['starttime']) : '-';
		$announce['endtime'] = $announce['endtime'] ? sgmdate($announce['endtime']) : '-';
		$announce['url'] = geturl('action/announcement/id/'.$id);
		$listvalue[] = $announce;
		$multipage = '<a href="'.geturl('action/announcement').'">MORE</a>';
	} else {
		messagebox('error', 'not_found', S_URL);
	}

}

$title = $lang['announcement'];

include template('site_announcement');

?>